File indexing completed on 2025-08-05 08:16:16
0001 #ifndef FUN4ALLRAW_SINGLEMICROMEGASPOOLINPUT_V2_H
0002 #define FUN4ALLRAW_SINGLEMICROMEGASPOOLINPUT_V2_H
0003
0004 #include "MicromegasBcoMatchingInformation_v2.h"
0005 #include "SingleStreamingInput.h"
0006
0007 #include <phool/PHTimer.h>
0008
0009 #include <array>
0010 #include <deque>
0011 #include <list>
0012 #include <map>
0013 #include <memory>
0014 #include <set>
0015 #include <string>
0016 #include <vector>
0017
0018 class MicromegasRawHit;
0019 class Packet;
0020
0021 class TFile;
0022 class TTree;
0023 class TH1;
0024
0025 class SingleMicromegasPoolInput_v2 : public SingleStreamingInput
0026 {
0027 public:
0028 explicit SingleMicromegasPoolInput_v2(const std::string &name = "SingleMicromegasPoolInput_v2");
0029 ~SingleMicromegasPoolInput_v2() override;
0030 void FillPool(const unsigned int nevents = 1) override;
0031
0032 void CleanupUsedPackets(const uint64_t bclk) override
0033 { CleanupUsedPackets(bclk,false); }
0034
0035
0036 void CleanupUsedPackets(const uint64_t , bool ) override;
0037
0038 void ClearCurrentEvent() override;
0039 bool GetSomeMoreEvents();
0040 void Print(const std::string &what = "ALL") const override;
0041 void CreateDSTNode(PHCompositeNode *topNode) override;
0042
0043 void SetBcoRange(const unsigned int value) { m_BcoRange = value; }
0044 void ConfigureStreamingInputManager() override;
0045 void SetNegativeBco(const unsigned int value) { m_NegativeBco = value; }
0046
0047
0048 void SetBcoPoolSize(const unsigned int value) { m_BcoPoolSize = value; }
0049
0050
0051 void FillBcoQA(uint64_t ) override;
0052
0053
0054 void createQAHistos() override;
0055
0056
0057 void set_do_evaluation( bool value ) { m_do_evaluation = value; }
0058
0059
0060 void set_evaluation_outputfile(const std::string& outputfile) { m_evaluation_filename = outputfile; }
0061
0062 private:
0063
0064
0065
0066
0067 static constexpr uint16_t MAX_FEECOUNT = 26;
0068
0069
0070 static constexpr size_t DAM_DMA_WORD_LENGTH = 16;
0071
0072
0073
0074 struct dma_word
0075 {
0076 uint16_t dma_header;
0077 uint16_t data[DAM_DMA_WORD_LENGTH - 1];
0078 };
0079
0080 void process_packet(Packet*);
0081 void decode_gtm_data(int , const dma_word&);
0082 void process_fee_data(int , unsigned int );
0083
0084
0085 std::vector<std::deque<uint16_t>> m_feeData{MAX_FEECOUNT};
0086
0087
0088 std::array<Packet *, 10> plist{};
0089
0090
0091 unsigned int m_NumSpecialEvents{0};
0092
0093
0094 unsigned int m_BcoRange{0};
0095
0096
0097 unsigned int m_NegativeBco{0};
0098
0099
0100 unsigned int m_BcoPoolSize{1};
0101
0102
0103
0104
0105
0106
0107
0108 std::map<uint64_t, std::set<int>> m_BeamClockPacket;
0109
0110
0111 std::map<uint64_t, std::set<int>> m_BeamClockFEE;
0112
0113
0114 std::map<uint64_t, std::vector<MicromegasRawHit *>> m_MicromegasRawHitMap;
0115
0116
0117
0118 std::map<int, uint64_t> m_FEEBclkMap;
0119
0120
0121
0122
0123
0124
0125
0126 std::set<uint64_t> m_BclkStack;
0127
0128
0129 using bco_matching_information_map_t = std::map<unsigned int, MicromegasBcoMatchingInformation_v2>;
0130 bco_matching_information_map_t m_bco_matching_information_map;
0131
0132 class counter_t
0133 {
0134 public:
0135
0136
0137 uint64_t total = 0;
0138
0139
0140 uint64_t dropped_bco = 0;
0141
0142
0143 uint64_t dropped_pool = 0;
0144
0145
0146 double dropped_fraction_bco() const { return double(dropped_bco)/total; }
0147
0148
0149 double dropped_fraction_pool() const { return double(dropped_pool)/total; }
0150
0151 };
0152
0153
0154 std::map<int,counter_t> m_fee_waveform_counters{};
0155
0156
0157 std::map<int,counter_t> m_waveform_counters{};
0158
0159
0160 std::map<int,counter_t> m_fee_heartbeat_counters{};
0161
0162
0163 std::map<int,counter_t> m_heartbeat_counters{};
0164
0165
0166 PHTimer m_timer{ "SingleMicromegasPoolInput_v2" };
0167
0168
0169
0170
0171
0172 TH1 *h_packet_stat{nullptr};
0173
0174
0175 TH1 *h_heartbeat_stat{nullptr};
0176
0177
0178 TH1 *h_packet{nullptr};
0179
0180
0181 TH1 *h_waveform{nullptr};
0182
0183
0184 TH1 *h_waveform_count_total{nullptr};
0185
0186
0187
0188 TH1 *h_waveform_count_dropped_bco{nullptr};
0189
0190
0191 TH1 *h_waveform_count_dropped_pool{nullptr};
0192
0193
0194 TH1 *h_fee_waveform_count_total{nullptr};
0195
0196
0197
0198 TH1 *h_fee_waveform_count_dropped_bco{nullptr};
0199
0200
0201 TH1 *h_fee_waveform_count_dropped_pool{nullptr};
0202
0203
0204
0205
0206
0207
0208
0209 bool m_do_evaluation = false;
0210
0211
0212 std::string m_evaluation_filename = "SingleMicromegasPoolInput.root";
0213 std::unique_ptr<TFile> m_evaluation_file;
0214
0215
0216
0217
0218
0219 class Waveform
0220 {
0221 public:
0222
0223
0224 unsigned int packet_id = 0;
0225
0226
0227 unsigned short fee_id = 0;
0228
0229
0230 unsigned short channel = 0;
0231
0232
0233 bool is_heartbeat = false;
0234
0235
0236 uint64_t gtm_bco_first = 0;
0237
0238
0239 uint64_t gtm_bco = 0;
0240
0241
0242 uint64_t gtm_bco_matched = 0;
0243
0244
0245 unsigned int fee_bco_first = 0;
0246
0247
0248 unsigned int fee_bco = 0;
0249
0250
0251 unsigned int fee_bco_predicted = 0;
0252
0253
0254 unsigned int fee_bco_predicted_matched = 0;
0255 };
0256
0257 Waveform m_waveform;
0258
0259
0260 TTree* m_evaluation_tree = nullptr;
0261
0262
0263
0264 };
0265
0266 #endif