Belle II Software  release-08-01-10
CDCDQMModule.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 // Own include
10 #include <cdc/modules/cdcDQM/CDCDQMModule.h>
11 
12 // Dataobject classes
13 #include <framework/database/DBObjPtr.h>
14 
15 #include <TF1.h>
16 #include <TVector3.h>
17 #include <TDirectory.h>
18 
19 #include <fstream>
20 #include <math.h>
21 
22 #include <cdc/dataobjects/WireID.h>
23 #include <cdc/geometry/CDCGeometryPar.h>
24 
25 using namespace std;
26 using namespace Belle2;
27 using namespace CDC;
28 
29 //-----------------------------------------------------------------
30 // Register module
31 //-----------------------------------------------------------------
32 
33 REG_MODULE(CDCDQM);
34 
35 CDCDQMModule::CDCDQMModule() : HistoModule()
36 {
37  // set module description (e.g. insert text)
38  setDescription("Make summary of data quality.");
39  addParam("MinHits", m_minHits, "Include only events with more than MinHits hits in CDC", 0);
41 }
42 
44 {
45 }
46 
48 {
49 
50  TDirectory* oldDir = gDirectory;
51  oldDir->mkdir("CDC");
52  oldDir->cd("CDC");
53  m_hNEvents = new TH1F("hNEvents", "hNEvents", 10, 0, 10);
54  m_hNEvents->GetXaxis()->SetBinLabel(1, "number of events");
55  m_hBit = new TH2F("hBit", "m_hBit", 7, 0, 7.0, 48, 0, 48.0);
56  m_hBit->SetTitle("CDC:Removed Data Bit;CDCRawIndex;Channell Index");
57  m_hOcc = new TH1F("hOcc", "hOccupancy", 150, 0, 1.5);
58  m_hADC = new TH2F("hADC", "hADC", 300, 0, 300, 200, 0, 1000);
59  m_hADC->SetTitle("ADC vs CDC-Boards;Board index;ADC");
60  m_hTDC = new TH2F("hTDC", "hTDC", 300, 0, 300, 1000, 4200, 5200);
61  m_hTDC->SetTitle("TDC vs CDC-Boards;Board index;TDC");
62  m_hHit = new TH2F("hHit", "hHit", 56, 0, 56, 400, 0, 400);
63  m_hHit->SetTitle("CDC-hits;layer index;nhits");
64  m_hPhi = new TH1F("hPhi", "", 360, -180.0, 180.0);
65  m_hPhi->SetTitle("CDC-track-#phi;cdctrack #phi (IP tracks + all events);entries");
66  m_hPhiIndex = new TH2F("hPhiIndex", "", 360, -180.0, 180.0, 8, 0, 8.0);
67  m_hPhiIndex->SetTitle("CDC-track-#phi;cdctrack #phi vs skims;selection-index");
68  m_hPhiEff = new TH2F("hPhiEff", "", 360, -180.0, 180.0, 100, 0, 100.0);
69  m_hPhiEff->SetTitle("CDC-track-#phi;cdctrack #phi vs cdchits;ncdchits");
70  m_hPhiHit = new TH2F("h2HitPhi", "h2HitPhi", 90, -180.0, 180.0, 56, 0, 56);
71  m_hPhiHit->SetTitle("CDC-hits-map (#phi vs layer);Track-#phi;Layer index");
72  oldDir->cd();
73 }
74 
76 {
77  REG_HISTOGRAM
78  m_cdcHits.isOptional();
79  m_cdcRawHits.isOptional();
80  m_trgSummary.isOptional();
81 
82  if (!m_Tracks.isOptional()) {
83  B2WARNING("Missing Tracks array");
84  return;
85  }
86 }
87 
89 {
90  if (!m_RecoTracks.isOptional()) {
91  B2DEBUG(22, "Missing recoTracks array in beginRun() ");
92  return;
93  }
94 
95  m_hNEvents->Reset();
96  m_hBit->Reset();
97  m_hOcc->Reset();
98  m_hADC->Reset();
99  m_hTDC->Reset();
100  m_hHit->Reset();
101  m_hPhi->Reset();
102  m_hPhiIndex->Reset();
103  m_hPhiEff->Reset();
104  m_hPhiHit->Reset();
105 }
106 
108 {
109  static CDCGeometryPar& cdcgeo = CDCGeometryPar::Instance();
110  const int nWires = 14336;
111  setReturnValue(1);
112  if (!m_trgSummary.isValid() || (m_trgSummary->getTimType() == Belle2::TRGSummary::TTYP_RAND)) {
113  setReturnValue(0);
114  return;
115  }
116 
117  if (!m_TrgResult.isValid()) {
118  B2WARNING("SoftwareTriggerResult object not available but require to select bhabha/mumu/hadron events skim");
119  return;
120  }
121 
122  const std::map<std::string, int>& fresults = m_TrgResult->getResults();
123  if ((fresults.find("software_trigger_cut&skim&accept_bhabha") == fresults.end()) ||
124  (fresults.find("software_trigger_cut&skim&accept_mumu_tight_or_highm") == fresults.end()) ||
125  (fresults.find("software_trigger_cut&skim&accept_hadron") == fresults.end())) {
126  B2WARNING("CDCDQMModule: Can't find required bhabha or mumu or hadron trigger identifier");
127  return;
128  }
129 
130  const bool IsBhabha = (m_TrgResult->getResult("software_trigger_cut&skim&accept_bhabha") ==
132  const bool IsHadron = (m_TrgResult->getResult("software_trigger_cut&skim&accept_hadron") ==
134  const bool IsMumu = (m_TrgResult->getResult("software_trigger_cut&skim&accept_mumu_tight_or_highm") ==
136 
137  if (m_cdcHits.getEntries() < m_minHits) {
138  setReturnValue(0);
139  return;
140  }
141 
142  m_nEvents += 1;
143  m_hOcc->Fill(static_cast<float>(m_cdcHits.getEntries()) / nWires);
144 
145  for (const auto& hit : m_cdcHits) {
146  int lay = hit.getICLayer();
147  int wire = hit.getIWire();
148  m_hHit->Fill(lay, wire);
149  }
150 
151  // to record removed databits
152  const int nEntries = m_rawCDCs.getEntries();
153  B2DEBUG(99, "nEntries of RawCDCs : " << nEntries);
154  for (int i = 0; i < nEntries; ++i) {
155  const int nEntriesRawCDC = m_rawCDCs[i]->GetNumEntries();
156  B2DEBUG(99, LogVar("nEntries of rawCDC[i]", nEntriesRawCDC));
157  for (int j = 0; j < nEntriesRawCDC; ++j) {
158  int MaxNumOfCh = m_rawCDCs[i]->GetMaxNumOfCh(j);
159  if (MaxNumOfCh != 4 && MaxNumOfCh != 48) {
160  B2ERROR("CDCDQM: Invalid value of GetMaxNumOfCh");
161  } else if (MaxNumOfCh == 48) {
162  for (int k = 0; k < MaxNumOfCh; ++k) {
163  if (m_rawCDCs[i]->CheckOnlineRemovedDataBit(j, k) == true)m_hBit->SetBinContent(i + 1, k + 1, -0.5);
164  else m_hBit->SetBinContent(i + 1, k + 1, 0.5);
165  }
166  }
167  }
168  }
169 
170  // ADC vs layer 2D histogram with only good track related hits
171  double iselect = -1.0;
172 
173  for (const auto& b2track : m_Tracks) {
174 
175  const Belle2::TrackFitResult* fitresult = b2track.getTrackFitResultWithClosestMass(Const::pion);
176  if (!fitresult) {
177  B2WARNING("No track fit result found.");
178  continue;
179  }
180 
181  Belle2::RecoTrack* track = b2track.getRelatedTo<Belle2::RecoTrack>(m_recoTrackArrayName);
182  if (!track) {
183  B2WARNING("Can not access RecoTrack of this Belle2::Track");
184  continue;
185  }
186 
187  const genfit::FitStatus* fs = track->getTrackFitStatus();
188  if (!fs) {
189  B2WARNING("Can not access FitStatus of this Track");
190  continue;
191  }
192  // require high NDF track
193  int ndf = fs->getNdf();
194  if (ndf < 20) continue;
195 
196  double phiDegree = fitresult->getPhi() / Unit::deg;
197 
198  if (fabs(fitresult->getD0()) > 1.0 || fabs(fitresult->getZ0()) > 1.0) {
199  //Off IP tracks
200  m_hPhiIndex->Fill(phiDegree, 0.5); //all skims
201  if (IsBhabha) iselect = 1.5;
202  if (IsHadron) iselect = 2.5;
203  if (IsMumu) iselect = 3.5;
204  m_hPhiIndex->Fill(phiDegree, iselect);
205  } else {
206  //IP tracks
207  m_hPhi->Fill(phiDegree);
208  m_hPhiIndex->Fill(phiDegree, 4.5); //all skims
209  if (IsBhabha) iselect = 5.5;
210  if (IsHadron) iselect = 6.5;
211  if (IsMumu) iselect = 7.5;
212  m_hPhiIndex->Fill(phiDegree, iselect);
213 
214  //for tracking efficiency part
215  double nsvdhits = fitresult->getHitPatternVXD().getNSVDHits();
216  double ncdchits = fitresult->getHitPatternCDC().getNHits();
217  if (nsvdhits > 6) {
218  if (ncdchits >= 100)ncdchits = 99.5; //push to last bin
219  m_hPhiEff->Fill(phiDegree, ncdchits);
220  }
221  }
222 
223  // Fill histograms of ADC/TDC if hits are associated with track
224  for (const RecoHitInformation::UsedCDCHit* hit : track->getCDCHitList()) {
225 
226  const genfit::TrackPoint* tp = track->getCreatedTrackPoint(track->getRecoHitInformation(hit));
227  if (!tp) {
228  B2WARNING("Can not access TrackPoint of this hit");
229  continue;
230  }
231 
232  UChar_t lay = hit->getICLayer();
233  UShort_t IWire = hit->getIWire();
234  UShort_t adc = hit->getADCCount();
235  unsigned short tdc = hit->getTDCCount();
236  WireID wireid(lay, IWire);
237  unsigned short bid = cdcgeo.getBoardID(wireid);
238 
239  m_hADC->Fill(bid, adc);
240  m_hTDC->Fill(bid, tdc);
241  m_hPhiHit->Fill(fitresult->getPhi() / Unit::deg, lay);
242 
243  }
244  }
245 }
246 
248 {
249  m_hNEvents->SetBinContent(1, m_nEvents);
250 }
251 
253 {
254 }
std::string m_recoTrackArrayName
Belle2::RecoTrack StoreArray name.
Definition: CDCDQMModule.h:103
StoreArray< RawCDC > m_rawCDCs
Input array for CDC Raw.
Definition: CDCDQMModule.h:99
TH2F * m_hBit
Histogram of online databit removed.
Definition: CDCDQMModule.h:113
void initialize() override
Initialize the Module.
Definition: CDCDQMModule.cc:75
int m_minHits
Minimum hits for processing.
Definition: CDCDQMModule.h:106
void event() override
Event processor.
StoreArray< CDCRawHit > m_cdcRawHits
CDC raw hits.
Definition: CDCDQMModule.h:98
void endRun() override
End-of-run action.
TH2F * m_hPhiIndex
Histogram of cdc phi of different IP + skims tracks.
Definition: CDCDQMModule.h:115
StoreObjPtr< TRGSummary > m_trgSummary
Trigger summary.
Definition: CDCDQMModule.h:100
void terminate() override
Termination action.
TH1F * m_hNEvents
Histogram of num.
Definition: CDCDQMModule.h:108
TH2F * m_hTDC
Histogram of TDC with track associated hits for all boards (0-299)
Definition: CDCDQMModule.h:111
TH2F * m_hPhiHit
Histogram of track associated hits in phi vs layer
Definition: CDCDQMModule.h:117
void beginRun() override
Called when entering a new run.
Definition: CDCDQMModule.cc:88
TH2F * m_hPhiEff
Histogram of cdc phi of tracking eff.
Definition: CDCDQMModule.h:116
TH1F * m_hPhi
Histogram of cdc phi of IP tracks.
Definition: CDCDQMModule.h:114
StoreArray< CDCHit > m_cdcHits
CDC hits.
Definition: CDCDQMModule.h:97
virtual ~CDCDQMModule()
Destructor.
Definition: CDCDQMModule.cc:43
TH2F * m_hADC
Histogram of ADC with track associated hits for all boards (0-299)
Definition: CDCDQMModule.h:110
TH1F * m_hOcc
Histogram of occupancy.
Definition: CDCDQMModule.h:109
StoreArray< RecoTrack > m_RecoTracks
RecoTracks.
Definition: CDCDQMModule.h:102
StoreArray< Track > m_Tracks
Tracks.
Definition: CDCDQMModule.h:101
StoreObjPtr< SoftwareTriggerResult > m_TrgResult
Store array for Trigger selection.
Definition: CDCDQMModule.h:104
TH2F * m_hHit
Histogram of Hits for all layers (0-55)
Definition: CDCDQMModule.h:112
void defineHisto() override
Histogram definitions.
Definition: CDCDQMModule.cc:47
Long64_t m_nEvents
Number of events processed.
Definition: CDCDQMModule.h:107
Class containing the result of the unpacker in raw data and the result of the digitizer in simulation...
Definition: CDCHit.h:40
The Class for CDC Geometry Parameters.
unsigned short getBoardID(const WireID &wID) const
Returns frontend board id. corresponding to the wire id.
static CDCGeometryPar & Instance(const CDCGeometry *=nullptr)
Static method to get a reference to the CDCGeometryPar instance.
static const ChargedStable pion
charged pion particle
Definition: Const.h:652
HistoModule.h is supposed to be used instead of Module.h for the modules with histogram definitions t...
Definition: HistoModule.h:29
unsigned short getNHits() const
Get the total Number of CDC hits in the fit.
unsigned short getNSVDHits() const
Get total number of hits in the SVD.
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
void setReturnValue(int value)
Sets the return value for this module as integer.
Definition: Module.cc:220
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:80
This is the Reconstruction Event-Data Model Track.
Definition: RecoTrack.h:79
bool isOptional(const std::string &name="")
Tell the DataStore about an optional input.
@ TTYP_RAND
random trigger events
Definition: TRGSummary.h:67
Values of the result of a track fit with a given particle hypothesis.
double getPhi() const
Getter for phi0 with CDF naming convention.
double getD0() const
Getter for d0.
double getZ0() const
Getter for z0.
HitPatternCDC getHitPatternCDC() const
Getter for the hit pattern in the CDC;.
HitPatternVXD getHitPatternVXD() const
Getter for the hit pattern in the VXD;.
static const double deg
degree to radians
Definition: Unit.h:109
Class to identify a wire inside the CDC.
Definition: WireID.h:34
Class to store variables with their name which were sent to the logging service.
Class where important numbers and properties of a fit can be stored.
Definition: FitStatus.h:80
double getNdf() const
Get the degrees of freedom of the fit.
Definition: FitStatus.h:122
Object containing AbsMeasurement and AbsFitterInfo objects.
Definition: TrackPoint.h:46
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
@ c_accept
Accept this event.
Abstract base class for different kinds of events.