Belle II Software  release-08-01-10
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 
23 using namespace Belle2;
28 class CDCTriggerNeuroDQMOnlineModule : public HistoModule { // <- derived from HistoModule class
29 
30 public:
35 
36 
37 private:
38 
39  struct TSLine {
40  const CDCTriggerSegmentHit* hit;
41  std::string strline;
42  //vector<const CDCTriggerTrack*> relin2dtracks;
43  //vector<const CDCTriggerTrack*> relin2dtracks;
44  explicit TSLine(const CDCTriggerSegmentHit& h)
45  {
46  hit = &h;
47  }
48  };
49  typedef std::vector<TSLine> TSLines;
50 
52  void initialize() override;
53  void beginRun() override;
54  void event() override;
55  void endRun() override;
56  void terminate() override;
57  void fillHWPlots();
58  void fillSimPlots();
59  void makeDebugOutput();
60  void fillRecoPlots();
61 
66  void defineHisto() override;
68  void condFill(TH1F* histo, float value)
69  {
70  if (value != 0) {
71  histo->Fill(value);
72  }
73  }
75  unsigned getPattern(CDCTriggerTrack* track, std::string hitCollectionName)
76  {
77  unsigned pattern = 0;
78  for (const CDCTriggerSegmentHit& hit : track->getRelationsTo<CDCTriggerSegmentHit>(hitCollectionName)) {
79  unsigned sl = hit.getISuperLayer();
80  if (sl % 2 == 1) pattern |= (1 << ((sl - 1) / 2));
81  }
82  return pattern;
83  }
85  bool isValidPattern(unsigned pattern)
86  {
87  bool valid = false;
88  switch (pattern) {
89  case 7:
90  case 11:
91  case 13:
92  case 14:
93  case 15:
94  valid = true;
95  }
96  return valid;
97  }
98  std::string padto(std::string s, unsigned l)
99  {
100  if (s.size() < l) {
101  s.insert(s.begin(), l - s.size(), ' ');
102  }
103  return s;
104  }
105  std::string padright(std::string s, unsigned l)
106  {
107  if (s.size() < l) {
108  s.insert(s.end(), l - s.size(), ' ');
109  }
110  return s;
111  }
112  bool have_relation(const CDCTriggerTrack& track, const CDCTriggerSegmentHit& hit, std::string& arrayname)
113  {
114  bool related = false;
115  for (const CDCTriggerSegmentHit& ts : track.getRelationsTo<CDCTriggerSegmentHit>(arrayname)) {
116  if (&ts == &hit) {related = true;}
117  }
118  return related;
119  }
120  void sorted_insert(TSLines& lines, TSLine& line, std::string& arrayname, std::string& firstsortarray, std::string& secondsortarray)
121  {
122  bool inserted = false;
123  bool related = false;
124  TSLines::iterator it = lines.begin();
125  for (const CDCTriggerTrack& track : line.hit->getRelationsFrom<CDCTriggerTrack>(firstsortarray)) {
126  if (!inserted) {
127  for (TSLines::iterator i = lines.begin(); i < lines.end(); ++i) {
128  if (i->hit->getISuperLayer() % 2 != line.hit->getISuperLayer() % 2) {
129  continue;
130  }
131  if (have_relation(track, *(i->hit), arrayname)) {
132  it = i;
133  related = true;
134  if (i->hit->getSegmentID() > line.hit->getSegmentID()) {
135  inserted = true;
136  break;
137  }
138  }
139  }
140  } else { break; }
141  }
142  if (related) {
143  if (!inserted) {++it; }
144  lines.insert(it, line);
145  } else {
146  for (const CDCTriggerTrack& track : line.hit->getRelationsFrom<CDCTriggerTrack>(secondsortarray)) {
147  if (!inserted) {
148  for (TSLines::iterator i = it; i < lines.end(); ++i) {
149  if (i->hit->getISuperLayer() % 2 != line.hit->getISuperLayer() % 2) {
150  continue;
151  }
152  if (have_relation(track, *(i->hit), arrayname)) {
153  it = i;
154  related = true;
155  if (i->hit->getSegmentID() > line.hit->getSegmentID()) {
156  inserted = true;
157  break;
158  }
159  }
160  }
161  } else { break; }
162  }
163  if (related) {
164  if (!inserted) {++it; }
165  lines.insert(it, line);
166  } else {
167  lines.push_back(line);
168  }
169  }
170  }
173 
187  std::string m_simNeuroTracksName;
191  std::string m_recoTracksName;
192 
197 
198  // store arrays for direct access
219 
220 
221 
222 
223  TH1F* m_neuroHWOutdzall = nullptr;
224  TH1F* m_neuroHWOutdz0 = nullptr;
225  TH1F* m_neuroHWOutdz1 = nullptr;
226  TH1F* m_neuroHWOutdz2 = nullptr;
227  TH1F* m_neuroHWOutdz3 = nullptr;
228  TH1F* m_neuroHWSimRecodZ = nullptr;
229 
230  TH1F* m_neuroHWOutZ = nullptr;
231  TH1F* m_recoZ = nullptr;
232  TH1F* m_recoZ_related = nullptr;
233  TH1F* m_neuroHWOutSTTZ = nullptr;
234  TH1F* m_neuroHWOutCosTheta = nullptr;
235  TH1F* m_neuroHWOutPhi0 = nullptr;
236  TH1F* m_neuroHWOutPt = nullptr;
237  TH1F* m_neuroHWOutP = nullptr;
238  TH1F* m_neuroHWOutm_time = nullptr;
239  TH1F* m_neuroHWValTracksNumber = nullptr;
240  TH1F* m_neuroHWSector = nullptr;
241  TH1F* m_neuroHWInTSID = nullptr;
242  TH1F* m_neuroHWInTSIDSel = nullptr;
243  TH1F* m_neuroHWInCDCFE = nullptr;
244  TH1F* m_neuroHWInm_time = nullptr;
245  TH1F* m_neuroHWIn2DTracksNumber = nullptr;
246 
247  TH1F* m_neuroHWOutHwSimdZ = nullptr;
248  TH1F* m_neuroHWSimZ = nullptr;
249  TH1F* m_neuroHWSimCosTheta = nullptr;
250  TH1F* m_neuroErrors = nullptr;
251  TH1F* m_neuroHWValTSCountAx = nullptr;
252  TH1F* m_neuroHWValTSCountSt = nullptr;
253 
254  unsigned m_errcount = 0; // set later
255  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"};
256 
257 
258 
259 };
260 
261 
262 
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
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 condFill(TH1F *histo, float value)
Fill a histogram only with non-zero values.
std::string m_unpacked2DTracksName
Name for 2D finder tracks from unpacker.
bool m_useSimTracks
Switch to turn on use of hw sim tracks.
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.
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.
Abstract base class for different kinds of events.