Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:29:38

0001 
0002 // Copyright 2020, Jefferson Science Associates, LLC.
0003 // Subject to the terms in the LICENSE file found in the top-level directory.
0004 
0005 #include "TutorialProcessor.h"
0006 #include "Hit.h"
0007 #include <JANA/JLogger.h>
0008 
0009 TutorialProcessor::TutorialProcessor() {
0010     SetTypeName(NAME_OF_THIS); // Provide JANA with this class's name
0011     SetCallbackStyle(CallbackStyle::LegacyMode);
0012 }
0013 
0014 void TutorialProcessor::Init() {
0015     LOG << "QuickTutorialProcessor::Init: Initializing heatmap" << LOG_END;
0016 
0017     for (int i=0; i<100; ++i) {
0018         for (int j=0; j<100; ++j) {
0019             m_heatmap[i][j] = 0.0;
0020         }
0021     }
0022 }
0023 
0024 void TutorialProcessor::Process(const std::shared_ptr<const JEvent>& event) {
0025     LOG << "TutorialProcessor::Process, Event #" << event->GetEventNumber() << LOG_END;
0026     
0027     /// Do everything we can in parallel
0028     /// Warning: We are only allowed to use local variables and `event` here
0029     auto hits = event->Get<Hit>();
0030 
0031     /// Lock mutex
0032     std::lock_guard<std::mutex>lock(m_mutex);
0033 
0034     /// Do the rest sequentially
0035     /// Now we are free to access shared state such as m_heatmap
0036     for (const Hit* hit : hits) {
0037         m_heatmap[hit->x][hit->y] += hit->E;    // ADD ME
0038         /// Update shared state
0039     }
0040 }
0041 
0042 void TutorialProcessor::Finish() {
0043     // Close any resources
0044     LOG << "QuickTutorialProcessor::Finish: Displaying heatmap" << LOG_END;
0045 
0046     double min_value = m_heatmap[0][0];
0047     double max_value = m_heatmap[0][0];
0048 
0049     for (int i=0; i<100; ++i) {
0050         for (int j=0; j<100; ++j) {
0051             double value = m_heatmap[i][j];
0052             if (min_value > value) min_value = value;
0053             if (max_value < value) max_value = value;
0054         }
0055     }
0056     if (min_value != max_value) {
0057         char ramp[] = " .:-=+*#%@";
0058         for (int i=0; i<100; ++i) {
0059             for (int j=0; j<100; ++j) {
0060                 int shade = int((m_heatmap[i][j] - min_value)/(max_value - min_value) * 9);
0061                 std::cout << ramp[shade];
0062             }
0063             std::cout << std::endl;
0064         }
0065     }
0066 }
0067