Belle II Software development
CDCTriggerNeuroDQMOnlineModule.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#pragma once
10
11#include <framework/core/HistoModule.h>
12
13#include <framework/datastore/StoreArray.h>
14#include <framework/datastore/StoreObjPtr.h>
15#include <trg/cdc/dataobjects/CDCTriggerTrack.h>
16#include <trg/cdc/dataobjects/CDCTriggerSegmentHit.h>
17#include <trg/cdc/dataobjects/CDCTriggerMLPInput.h>
18#include <tracking/dataobjects/RecoTrack.h>
19#include <framework/dataobjects/BinnedEventT0.h>
20
21#include "TH1F.h"
22
23using namespace Belle2;
25class CDCTriggerNeuroDQMOnlineModule : public HistoModule { // <- derived from HistoModule class
26
27public:
32
33
34private:
35
36 struct TSLine {
37 const CDCTriggerSegmentHit* hit;
38 std::string strline;
39 //vector<const CDCTriggerTrack*> relin2dtracks;
40 //vector<const CDCTriggerTrack*> relin2dtracks;
41 explicit TSLine(const CDCTriggerSegmentHit& h)
42 {
43 hit = &h;
44 }
45 };
46 typedef std::vector<TSLine> TSLines;
47
49 void initialize() override;
50 void beginRun() override;
51 void event() override;
52 void endRun() override;
53 void terminate() override;
54 void fillHWPlots();
55 void fillSimPlots();
56 void makeDebugOutput();
57 void fillRecoPlots();
58
63 void defineHisto() override;
65 void condFill(TH1F* histo, float value)
66 {
67 if (value != 0) {
68 histo->Fill(value);
69 }
70 }
72 unsigned getPattern(CDCTriggerTrack* track, std::string hitCollectionName)
73 {
74 unsigned pattern = 0;
75 for (const CDCTriggerSegmentHit& hit : track->getRelationsTo<CDCTriggerSegmentHit>(hitCollectionName)) {
76 unsigned sl = hit.getISuperLayer();
77 if (sl % 2 == 1) pattern |= (1 << ((sl - 1) / 2));
78 }
79 return pattern;
80 }
82 bool isValidPattern(unsigned pattern)
83 {
84 bool valid = false;
85 switch (pattern) {
86 case 7:
87 case 11:
88 case 13:
89 case 14:
90 case 15:
91 valid = true;
92 }
93 return valid;
94 }
95 std::string padto(std::string s, unsigned l)
96 {
97 if (s.size() < l) {
98 s.insert(s.begin(), l - s.size(), ' ');
99 }
100 return s;
101 }
102 std::string padright(std::string s, unsigned l)
103 {
104 if (s.size() < l) {
105 s.insert(s.end(), l - s.size(), ' ');
106 }
107 return s;
108 }
109 bool have_relation(const CDCTriggerTrack& track, const CDCTriggerSegmentHit& hit, std::string& arrayname)
110 {
111 bool related = false;
112 for (const CDCTriggerSegmentHit& ts : track.getRelationsTo<CDCTriggerSegmentHit>(arrayname)) {
113 if (&ts == &hit) {related = true;}
114 }
115 return related;
116 }
117 void sorted_insert(TSLines& lines, TSLine& line, std::string& arrayname, std::string& firstsortarray, std::string& secondsortarray)
118 {
119 bool inserted = false;
120 bool related = false;
121 TSLines::iterator it = lines.begin();
122 for (const CDCTriggerTrack& track : line.hit->getRelationsFrom<CDCTriggerTrack>(firstsortarray)) {
123 if (!inserted) {
124 for (TSLines::iterator i = lines.begin(); i < lines.end(); ++i) {
125 if (i->hit->getISuperLayer() % 2 != line.hit->getISuperLayer() % 2) {
126 continue;
127 }
128 if (have_relation(track, *(i->hit), arrayname)) {
129 it = i;
130 related = true;
131 if (i->hit->getSegmentID() > line.hit->getSegmentID()) {
132 inserted = true;
133 break;
134 }
135 }
136 }
137 } else { break; }
138 }
139 if (related) {
140 if (!inserted) {++it; }
141 lines.insert(it, line);
142 } else {
143 for (const CDCTriggerTrack& track : line.hit->getRelationsFrom<CDCTriggerTrack>(secondsortarray)) {
144 if (!inserted) {
145 for (TSLines::iterator i = it; i < lines.end(); ++i) {
146 if (i->hit->getISuperLayer() % 2 != line.hit->getISuperLayer() % 2) {
147 continue;
148 }
149 if (have_relation(track, *(i->hit), arrayname)) {
150 it = i;
151 related = true;
152 if (i->hit->getSegmentID() > line.hit->getSegmentID()) {
153 inserted = true;
154 break;
155 }
156 }
157 }
158 } else { break; }
159 }
160 if (related) {
161 if (!inserted) {++it; }
162 lines.insert(it, line);
163 } else {
164 lines.push_back(line);
165 }
166 }
167 }
170
188 std::string m_recoTracksName;
189
194
195 // store arrays for direct access
216
217
218
219
220 TH1F* m_neuroHWOutdzall = nullptr;
221 TH1F* m_neuroHWOutdz0 = nullptr;
222 TH1F* m_neuroHWOutdz1 = nullptr;
223 TH1F* m_neuroHWOutdz2 = nullptr;
224 TH1F* m_neuroHWOutdz3 = nullptr;
225 TH1F* m_neuroHWSimRecodZ = nullptr;
226
227 TH1F* m_neuroHWOutZ = nullptr;
228 TH1F* m_recoZ = nullptr;
229 TH1F* m_recoZ_related = nullptr;
230 TH1F* m_neuroHWOutSTTZ = nullptr;
231 TH1F* m_neuroHWOutCosTheta = nullptr;
232 TH1F* m_neuroHWOutPhi0 = nullptr;
233 TH1F* m_neuroHWOutPt = nullptr;
234 TH1F* m_neuroHWOutP = nullptr;
235 TH1F* m_neuroHWOutm_time = nullptr;
236 TH1F* m_neuroHWValTracksNumber = nullptr;
237 TH1F* m_neuroHWSector = nullptr;
238 TH1F* m_neuroHWInTSID = nullptr;
239 TH1F* m_neuroHWInTSIDSel = nullptr;
240 TH1F* m_neuroHWInCDCFE = nullptr;
241 TH1F* m_neuroHWInm_time = nullptr;
242 TH1F* m_neuroHWIn2DTracksNumber = nullptr;
243
244 TH1F* m_neuroHWOutHwSimdZ = nullptr;
245 TH1F* m_neuroHWSimZ = nullptr;
246 TH1F* m_neuroHWSimCosTheta = nullptr;
247 TH1F* m_neuroErrors = nullptr;
248 TH1F* m_neuroHWValTSCountAx = nullptr;
249 TH1F* m_neuroHWValTSCountSt = nullptr;
250
251 unsigned m_errcount = 0; // set later
252 std::vector<std::string> m_errdict{"Not All HWTrack ATS in 2DInTrack", "|HW-SW| > 1cm", "Delta Input IDs not all 0", "Delta Input Alphas not all 0", "Drifttime Overflow / Scaling Error", "TS only in HW", "TS only in SW", "Multiple ET per Track", "<4 related Axial TS", "<3 related Stereo TS", "Drift Time diff", "Eventcounter"};
253
254
255
256};
257
258
259
Combination of several CDCHits to a track segment hit for the trigger.
Track created by the CDC trigger.
HistoModule.h is supposed to be used instead of Module.h for the modules with histogram definitions t...
Definition: HistoModule.h:29
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
StoreArray< CDCTriggerMLPInput > m_simNeuroInputVector
StoreArray for neuro input vector from TSIM.
StoreArray< CDCTriggerTrack > m_unpackedNeuroInput2DTracks
StoreArray for neuro input 2dfinder tracks.
StoreArray< CDCTriggerTrack > m_unpackedNeuroTracks
StoreArray for neuro tracks from unpacker.
std::string m_unpackedNeuroInputSegmentHitsName
Name for neuro input Track segments.
void initialize() override
Module functions.
void condFill(TH1F *histo, float value)
Fill a histogram only with non-zero values.
void event() override
Function to process event record.
std::string m_unpacked2DTracksName
Name for 2D finder tracks from unpacker.
void endRun() override
Function to process end_run record.
bool m_useSimTracks
Switch to turn on use of hw sim tracks.
void terminate() override
Function to terminate module.
std::string m_unpackedNeuroInput2DTracksName
Name for neuro input 2d finder tracks.
StoreArray< CDCTriggerMLPInput > m_unpackedNeuroInputVector
StoreArray for neuro input vector from unpacker.
std::string m_unpackedNeuroInputAllSegmentHitsName
Name for TS hits from unpacker.
StoreArray< CDCTriggerTrack > m_simNeuroTracks
StoreArray for neuro tracks from TSIM.
std::string m_simNeuroInputVectorName
Name for simulated neuro input vector using HW TS, HW 2D.
void beginRun() override
Function to process begin_run record.
std::string m_histogramDirectoryName
Name of the histogram directory in ROOT file.
std::string m_recoTracksName
Name for the RecoTrack array name.
bool m_useRecoTracks
Switch to turn on use of recotracks.
std::string m_simNeuroTracksName
name of the storearray for hwsim tracks
unsigned getPattern(CDCTriggerTrack *track, std::string hitCollectionName)
get pattern of the track
std::string m_unpackedNeuroInputVectorName
Name for neuro input vector from unpacker.
bool isValidPattern(unsigned pattern)
Validity of the pattern.
StoreObjPtr< BinnedEventT0 > m_eventTime
storeobjpointer for event time
StoreArray< CDCTriggerSegmentHit > m_unpackedNeuroInputSegmentHits
StoreArray for neuro input Track segments.
StoreArray< CDCTriggerTrack > m_unpacked2DTracks
StoreArray for 2D finder tracks from unpacker.
std::string m_unpackedNeuroTracksName
Name for neuro tracks from unpacker.
StoreArray< RecoTrack > m_RecoTracks
StoreArray for RecoTracks.
StoreArray< CDCTriggerSegmentHit > m_unpackedNeuroInputAllSegmentHits
StoreArray for all TS hits from neuro unpacker.
void defineHisto() override
Histogram definitions such as TH1(), TH2(), TNtuple(), TTree()....
Abstract base class for different kinds of events.