File indexing completed on 2025-01-30 10:29:38
0001
0002
0003
0004
0005 #include "TutorialProcessor.h"
0006 #include "Hit.h"
0007 #include <JANA/JLogger.h>
0008
0009 TutorialProcessor::TutorialProcessor() {
0010 SetTypeName(NAME_OF_THIS);
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
0028
0029 auto hits = event->Get<Hit>();
0030
0031
0032 std::lock_guard<std::mutex>lock(m_mutex);
0033
0034
0035
0036 for (const Hit* hit : hits) {
0037 m_heatmap[hit->x][hit->y] += hit->E;
0038
0039 }
0040 }
0041
0042 void TutorialProcessor::Finish() {
0043
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