Belle II Software  release-06-01-15
TrackingHLTDQMModule.cc
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 #include <tracking/modules/trackingDQM/TrackingHLTDQMModule.h>
10 #include <tracking/modules/trackingDQM/TrackDQMEventProcessor.h>
11 #include <tracking/dqmUtils/HistogramFactory.h>
12 
13 #include <TDirectory.h>
14 
15 using namespace Belle2;
16 using namespace Belle2::HistogramFactory;
17 using namespace std;
18 using boost::format;
19 
20 //-----------------------------------------------------------------
21 // Register the Module
22 //-----------------------------------------------------------------
23 
24 REG_MODULE(TrackingHLTDQM)
25 
26 //-----------------------------------------------------------------
27 // Implementation
28 //-----------------------------------------------------------------
29 
31 {
32  setPropertyFlags(c_ParallelProcessingCertified);
33  setDescription("Data Quality Monitoring of the tracking run on HLT. "
34  );
35 }
36 
37 //------------------------------------------------------------------
38 // Function to define histograms
39 //-----------------------------------------------------------------
40 
42 {
44 
45  // eventLevelTrackingInfo is currently only set by VXDTF2, if VXDTF2 is not in path the StoreObject is not there
46  m_eventLevelTrackingInfo.isOptional();
47 
48  m_rawTTD.isOptional();
49 }
50 
52 {
55 
56  if (VXD::GeoCache::getInstance().getGeoTools()->getNumberOfLayers() == 0)
57  B2FATAL("Missing geometry for VXD.");
58 
59  // Create a separate histogram directories and cd into it.
60  TDirectory* originalDirectory = gDirectory;
61 
62  // There might be problems with nullptr if the directory with the same name already exists (but I am not sure because there isn't anything like that in AlignmentDQM)
63  TDirectory* TracksDQM = originalDirectory->GetDirectory("TrackingHLTDQM");
64  if (!TracksDQM)
65  TracksDQM = originalDirectory->mkdir("TrackingHLTDQM");
66 
67  TracksDQM->cd();
68  DefineTracks();
69  DefineHits();
70  DefineMomentumAngles();
71  DefineMomentumCoordinates();
72  DefineHelixParametersAndCorrelations();
73  DefineTrackFitStatus();
74 
75  DefineAbortFlagsHistograms();
76 
77  originalDirectory->cd();
78 
79  for (auto change : m_histogramParameterChanges)
80  ProcessHistogramParameterChange(get<0>(change), get<1>(change), get<2>(change));
81 }
82 
84 {
86  if (!histogramsDefined)
87  return;
88 
89  bool runningOnHLT = true;
90 
91  TrackDQMEventProcessor eventProcessor = TrackDQMEventProcessor(this, m_recoTracksStoreArrayName, m_tracksStoreArrayName,
92  runningOnHLT);
93 
94  eventProcessor.Run();
95 
96  if (m_eventLevelTrackingInfo.isValid()) {
97  m_trackingErrorFlags->Fill((double)m_eventLevelTrackingInfo->hasAnErrorFlag());
98 
99  if (m_rawTTD.isValid()) {
100 
101  for (auto& it : m_rawTTD) {
102 
103  // get last injection time
104  auto difference = it.GetTimeSinceLastInjection(0);
105  // check time overflow, too long ago
106  if (difference != 0x7FFFFFFF) {
107 
108  double timeSinceInj = it.GetTimeSinceLastInjection(0) / c_globalClock;
109  double timeInCycle = timeSinceInj - (int)(timeSinceInj / c_revolutionTime) * c_revolutionTime;
110 
111  if (it.GetIsHER(0))
112  m_allVStimeHER->Fill(timeSinceInj, timeInCycle);
113  else
114  m_allVStimeLER->Fill(timeSinceInj, timeInCycle);
115 
116  if (m_eventLevelTrackingInfo->hasAnErrorFlag()) {
117  if (it.GetIsHER(0))
118  m_abortVStimeHER->Fill(timeSinceInj, timeInCycle);
119  else
120  m_abortVStimeLER->Fill(timeSinceInj, timeInCycle);
121  } //has error flag
122  } //time overflow
123  }// loop on RawFTSW
124  } //RawFTSW is valid
125  } else
126  m_trackingErrorFlags->Fill(0.0);
127 
128 }
129 
131 {
132  // only monitor if any flag was set so only 2 bins needed
133  const char* flagTitle =
134  "Tracking error summary. Mean = errors/event (should be 0 or very close to 0); Error occured yes or no; Number of events";
135 
136  m_trackingErrorFlags = Create("NumberTrackingErrorFlags", flagTitle, 2, -0.5, 1.5, "", "");
137 
138  m_trackingErrorFlags->GetXaxis()->SetBinLabel(1, "No Error");
139  m_trackingErrorFlags->GetXaxis()->SetBinLabel(2, "Error occured");
140 
141  //tracking abort VS time after HER/LER injection and time within a beam cycle
142  m_abortVStimeHER = new TH2F(
143  "TrkAbortVsTimeHER",
144  "Tracking Abort vs HER Injection;Time since last injection [#mus];Time in beam cycle [#mus];Events / bin",
145  100, 0, c_noInjectionTime, 50, 0, c_revolutionTime);
146 
147  m_abortVStimeLER = new TH2F(
148  "TrkAbortVsTimeLER",
149  "Tracking Abort vs LER Injection;Time since last injection [#mus];Time in beam cycle [#mus];Events / bin",
150  100, 0, c_noInjectionTime, 50, 0, c_revolutionTime);
151 
152  //tracking all VS time after HER/LER injection and time within a beam cycle
153  m_allVStimeHER = new TH2F(
154  "allEvtsVsTimeHER",
155  "Number Of Events vs HER Injection;Time since last injection [#mus];Time in beam cycle [#mus];Events / bin",
156  100, 0, c_noInjectionTime, 50, 0, c_revolutionTime);
157 
158  m_allVStimeLER = new TH2F(
159  "allEvtsVsTimeLER",
160  "Number of Events vs LER Injection;Time since last injection [#mus];Time in beam cycle [#mus];Events / bin",
161  100, 0, c_noInjectionTime, 50, 0, c_revolutionTime);
162 
163 }
virtual void Run()
Call this to start processing the event data and filling histograms.
This class serves as a base for the TrackDQMModule and AlignDQMModule (and possibly other DQM histogr...
virtual void initialize() override
Initializer.
virtual void event() override
This method is called for each event.
void runningOnHLT()
function called when the module is run on HLT
virtual void defineHisto() override
Histogram definitions such as TH1(), TH2(), TNtuple(), TTree()....
The purpose of this class is to process one event() in TrackDQMModule.
void initialize() override
Module functions.
void event() override
fill of the histograms happens here
virtual void DefineAbortFlagsHistograms()
All the following Define- functions should be used in the defineHisto() function to define histograms...
virtual void defineHisto() override
Histogram definitions such as TH1(), TH2(), TNtuple(), TTree()....
static GeoCache & getInstance()
Return a reference to the singleton instance.
Definition: GeoCache.cc:213
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.