Belle II Software  release-06-01-15
CDCDedxDQM.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 <reconstruction/modules/CDCDedxDQM/CDCDedxDQM.h>
10 #include <TDirectory.h>
11 
12 using namespace Belle2;
13 
14 REG_MODULE(CDCDedxDQM)
15 
16 //---------------------------------
18 {
19  setPropertyFlags(c_ParallelProcessingCertified); // parallel processing
20  setDescription("CDC dE/dx DQM plots with bhabha/hadron events.");
21  addParam("mmode", mmode, "default monitoring mode is basic", std::string("basic"));
22 }
23 
24 //---------------------------------
26 {
27 
28 }
29 
30 //---------------------------------
32 {
33 
34  TDirectory* oldDir = gDirectory;
35  oldDir->mkdir("CDCDedx");
36  oldDir->cd("CDCDedx");
37 
38  if (m_MetaDataPtr) {
39  m_exp = int(m_MetaDataPtr->getExperiment());
40  m_run = int(m_MetaDataPtr->getRun());
41  if (m_DBRunGain)m_rungain = m_DBRunGain->getRunGain();
42  }
43 
44  hMeta = new TH1D("hMeta", "hMeta", 3, 0.5, 3.5);
45  hMeta->GetXaxis()->SetTitle("Quantity");
46  hMeta->GetYaxis()->SetTitle("Values");
47  hMeta->SetTitle(Form("(Exp:%d, Run:%d, RG:%0.03f)", m_exp, m_run, m_rungain));
48  hMeta->GetXaxis()->SetBinLabel(1, "nevt");
49  hMeta->GetXaxis()->SetBinLabel(2, "nbhabha");
50  hMeta->GetXaxis()->SetBinLabel(3, "nhadron");
51 
52  hdEdx = new TH1D("hdEdx", ";CDC dE/dx;Entries", 250, 0., 2.5);
53  hdEdxvsP = new TH2D("hdEdxVsP", ";#it{p}_{CDC} (GeV/c);CDC dE/dx", 400, 0.050, 4.50, 800, 0.35, 20.35);
54  hdEdxvsEvt = new TH2D("hdEdxvsEvt", ";Events(M);CDC dE/dx", 300, 0, 300, 200, 0.00, 2.5);
55  hdEdxvsCosth = new TH2D("hdEdxvsCosth", ";cos#theta (e^{-}e^{+} tracks);CDC dE/dx", 100, -1.00, 1.00, 250, 0.00, 2.5);
56  hdEdxvsPhi = new TH2D("hdEdxvsPhi", ";#phi (e^{-}e^{+} tracks);CDC dE/dx", 100, -3.20, 3.20, 250, 0.00, 2.5);
57  if (mmode != "basic") {
58  hWires = new TH2F("hWires", "All Wires;", 2400, -1.2, 1.2, 2400, -1.2, 1.2);
59  hWires->GetXaxis()->SetTitle("CDC-wire map: counter-clockwise and start from +x");
60  hWireStatus = new TH2F("hWireStatus", "Wire Status", 2400, -1.2, 1.2, 2400, -1.2, 1.2);
61  hWireStatus->GetXaxis()->SetTitle("CDC-wire map: counter-clockwise and start from +x");
62  }
63  oldDir->cd();
64 
65 }
66 
67 
68 //---------------------------------
70 {
71 
72  if (!m_cdcDedxTracks.isOptional()) {
73  B2WARNING("Missing CDCDedxTracks array, CDCDedxDQM is skipped.");
74  return;
75  }
76 
77  m_TrgResult.isOptional();
78  m_cdcDedxTracks.isRequired();
79  REG_HISTOGRAM
80 
81 }
82 
83 //-------------------------------
85 {
86 
87  if (!m_cdcDedxTracks.isOptional()) {
88  B2WARNING("Missing CDCDedxTracks array, CDCDedxDQM is skipped.");
89  return;
90  }
91 
92  hMeta->Reset();
93  hdEdx->Reset();
94  hdEdxvsP->Reset();
95  hdEdxvsCosth->Reset();
96  hdEdxvsPhi->Reset();
97  hdEdxvsEvt->Reset();
98  if (mmode != "basic") {
99  hWires->Reset();
100  hWireStatus->Reset();
101  }
102 }
103 
104 
105 //----------------------------
107 {
108 
109  if (!m_cdcDedxTracks.isOptional()) return;
110 
111  if (!m_TrgResult.isValid()) {
112  B2WARNING("Required SoftwareTriggerResult object not available: CDCDedxDQM is skipped");
113  return;
114  }
115 
116  const std::map<std::string, int>& fresults = m_TrgResult->getResults();
117  if (fresults.find("software_trigger_cut&skim&accept_bhabha") == fresults.end()
118  and fresults.find("software_trigger_cut&skim&accept_hadron") == fresults.end())return;
119 
120  const bool IsBhabhaEvt = (m_TrgResult->getResult("software_trigger_cut&skim&accept_bhabha") ==
122  const bool IsHadronEvt = (m_TrgResult->getResult("software_trigger_cut&skim&accept_hadron") ==
124 
125  m_nEvt += 1;
126  if (!IsBhabhaEvt and !IsHadronEvt)return;
127  if (IsBhabhaEvt)m_nBEvt += 1;
128  if (IsHadronEvt)m_nHEvt += 1;
129 
130  //Get current evt number
131  if (m_MetaDataPtr)m_event = int(m_MetaDataPtr->getEvent());
132 
133  for (Int_t idedx = 0; idedx < m_cdcDedxTracks.getEntries(); idedx++) {
134 
135  CDCDedxTrack* dedxTrack = m_cdcDedxTracks[idedx];
136  if (!dedxTrack || dedxTrack->size() == 0)continue;
137 
138  const Track* track = dedxTrack->getRelatedFrom<Track>();
139  if (!track)continue;
140 
141  const TrackFitResult* fitResult = track->getTrackFitResultWithClosestMass(Const::pion);
142  if (!fitResult)continue;
143 
144  UncertainHelix helix = fitResult->getUncertainHelix();
145  static DBObjPtr<BeamSpot> beamSpotDB;
146  helix.passiveMoveBy(beamSpotDB->getIPPosition());
147  const auto& frame = ReferenceFrame::GetCurrent();
148  double dr = frame.getVertex(helix.getPerigee()).Perp();
149  double dz = frame.getVertex(helix.getPerigee()).Z();
150  if (dr >= 1.0 || fabs(dz) >= 1.0)continue;
151 
152  //CDC acceptance as well
153  double costh = dedxTrack->getCosTheta();
154  if (costh < TMath::Cos(150.0 * TMath::DegToRad()))continue;
155  if (costh > TMath::Cos(17.0 * TMath::DegToRad())) continue;
156 
157  //clean tracks with relaxed nhit cut
158  double nhits = dedxTrack->getNLayerHits();
159  if (costh > -0.55 && costh < 0.820) {
160  if (nhits < 20)continue;
161  } else {
162  if (costh <= -0.62 || costh >= 0.880) {
163  if (nhits < 8)continue;
164  if (costh > 0 && nhits < 10)continue;
165  } else {
166  if (nhits < 15)continue;
167  }
168  }
169 
170  double dedxnosat = dedxTrack->getDedxNoSat();
171  if (dedxnosat < 0)continue;
172 
173  double dedx = dedxTrack->getDedx();
174  if (dedx < 0)continue;
175 
176  double pCDC = dedxTrack->getMomentum();
177  if (pCDC <= 0) continue;
178 
179  double pTrk = fitResult->getMomentum().Mag();
180  if (pTrk <= 0) continue;
181 
182  if (IsBhabhaEvt) {
183  const ECLCluster* eclCluster = track->getRelated<ECLCluster>();
184  if (eclCluster and eclCluster->hasHypothesis(ECLCluster::EHypothesisBit::c_nPhotons)) {
185  double TrkEoverP = eclCluster->getEnergy(ECLCluster::EHypothesisBit::c_nPhotons) / pTrk;
186  if (TrkEoverP > 0) {
187  if (abs(TrkEoverP - 1.0) > 0.25)continue;
188  }
189  }
190 
191  hdEdx->Fill(dedxnosat);
192  double phi = fitResult->getMomentum().Phi();
193  if (hdEdxvsCosth->Integral() <= 80000)hdEdxvsCosth->Fill(costh, dedxnosat);
194  if (hdEdxvsPhi->Integral() <= 80000)hdEdxvsPhi->Fill(phi, dedxnosat);
195 
196  if (m_event >= 150e6)m_event = 150e6 - 100;
197  m_event = int(m_event / 5e5);
198  hdEdxvsEvt->Fill(m_event, dedxnosat);
199 
200  }
201 
202  if (IsHadronEvt && hdEdxvsP->Integral() <= 80000)hdEdxvsP->Fill(pCDC, dedx);
203 
204  if (mmode != "basic") {
205  for (int ihit = 0; ihit < dedxTrack->size(); ++ihit) {
206  int iwire = dedxTrack->getWire(ihit);
207  double iadc = dedxTrack->getADCCount(ihit);
208  if (m_adc[iwire].size() < 50)m_adc[iwire].push_back(iadc); //just contiung dead
209  }
210  }
211  }
212 
213 }
214 
215 //---------------------------------
217 {
218 
219  hMeta->SetBinContent(1, m_nEvt);
220  hMeta->SetBinContent(2, m_nBEvt);
221  hMeta->SetBinContent(3, m_nHEvt);
222 
223  if (hdEdx->GetEntries() > 0) {
224  hdEdx->GetXaxis()->SetRange(hdEdx->FindFirstBinAbove(0, 1), hdEdx->FindLastBinAbove(0, 1));
225  }
226 
227  if (hdEdxvsEvt->GetEntries() > 0) {
228  hdEdxvsEvt->GetXaxis()->SetRange(hdEdxvsEvt->FindFirstBinAbove(0, 1), hdEdxvsEvt->FindLastBinAbove(0, 1));
229  }
230 
231  //get dead wire pattern
232  if (mmode != "basic") {
233  Int_t nbadwires = 0;
234  for (int iwire = 0; iwire < 14336; ++iwire) {
235  int nwire = getIndexVal(iwire, "nwirelayer");
236  int twire = getIndexVal(iwire, "twire");
237  double radius = getIndexVal(iwire, "rwire");
238  int wire = iwire - twire ;
239  double phi = 2.*TMath::Pi() * (float(wire) / float(nwire));
240  double x = radius * cos(phi);
241  double y = radius * sin(phi);
242  hWires->Fill(x, y);
243  if (m_adc[iwire].size() > 0)continue;
244  nbadwires++;
245  hWireStatus->Fill(x, y);
246  }
247  hWireStatus->SetTitle(Form("%d", nbadwires));
248  }
249 
250 }
251 
252 
253 //---------------------------------
255 {
256 
257 }
258 
259 //-----------------------------------------------------------
260 double CDCDedxDQMModule::getIndexVal(int iWire, TString what)
261 {
262  //few hardcoded number
263  //radius of each CDC layer
264  double r[56] = {
265  16.80, 17.80, 18.80, 19.80, 20.80, 21.80, 22.80, 23.80,
266  25.70, 27.52, 29.34, 31.16, 32.98, 34.80,
267  36.52, 38.34, 40.16, 41.98, 43.80, 45.57,
268  47.69, 49.46, 51.28, 53.10, 54.92, 56.69,
269  58.41, 60.18, 62.00, 63.82, 65.64, 67.41,
270  69.53, 71.30, 73.12, 74.94, 76.76, 78.53,
271  80.25, 82.02, 83.84, 85.66, 87.48, 89.25,
272  91.37, 93.14, 94.96, 96.78, 98.60, 100.37,
273  102.09, 103.86, 105.68, 107.50, 109.32, 111.14
274  };
275 
276  Int_t totalWireiLayer = 0 ;
277  double myreturn = 0;
278  for (Int_t iLayer = 0; iLayer < 56; iLayer++) {
279  int iSuperLayer = (iLayer - 2) / 6;
280  if (iSuperLayer <= 0)iSuperLayer = 1;
281  int nWireiLayer = 160 + (iSuperLayer - 1) * 32;
282  totalWireiLayer += nWireiLayer;
283 
284  if (iWire < totalWireiLayer) {
285  if (what == "layer")myreturn = iLayer;
286  else if (what == "nwirelayer") myreturn = nWireiLayer;
287  else if (what == "twire") myreturn = totalWireiLayer - nWireiLayer;
288  else if (what == "rwire") myreturn = r[iLayer] / 100.;
289  else std::cout << "Invalid return :0 " << std::endl;
290  break;
291  }
292  }
293  return myreturn;
294 }
This module to design collect CDC dEdx monitoring for DQM and only minimal information are stored.
Definition: CDCDedxDQM.h:47
Int_t m_exp
exp number
Definition: CDCDedxDQM.h:88
Int_t m_nBEvt
bhabha events
Definition: CDCDedxDQM.h:93
TH2F * hWireStatus
dead wire status
Definition: CDCDedxDQM.h:107
DBObjPtr< CDCDedxRunGain > m_DBRunGain
Run gain DB object.
Definition: CDCDedxDQM.h:82
TH2D * hdEdxvsCosth
dedx vs costh
Definition: CDCDedxDQM.h:105
virtual void initialize() override
Initialize the module.
Definition: CDCDedxDQM.cc:69
TH2D * hdEdxvsP
dedx vs p
Definition: CDCDedxDQM.h:103
TH2F * hWires
all wire mapping
Definition: CDCDedxDQM.h:108
Int_t m_event
number of event
Definition: CDCDedxDQM.h:90
virtual void event() override
This method is called for each event.
Definition: CDCDedxDQM.cc:106
Int_t m_nHEvt
hadron events
Definition: CDCDedxDQM.h:94
virtual void endRun() override
This method is called at the end of each run.
Definition: CDCDedxDQM.cc:216
virtual void terminate() override
End of the event processing.
Definition: CDCDedxDQM.cc:254
Int_t m_nEvt
accepted events
Definition: CDCDedxDQM.h:92
TH1D * hMeta
metadata
Definition: CDCDedxDQM.h:101
Int_t m_run
run number
Definition: CDCDedxDQM.h:89
StoreObjPtr< EventMetaData > m_MetaDataPtr
Store array for metadata info.
Definition: CDCDedxDQM.h:84
virtual void beginRun() override
This method is called for each run.
Definition: CDCDedxDQM.cc:84
StoreArray< CDCDedxTrack > m_cdcDedxTracks
Store array for CDCDedxTrack.
Definition: CDCDedxDQM.h:86
virtual ~CDCDedxDQMModule()
Destructor.
Definition: CDCDedxDQM.cc:25
Double_t m_rungain
previous rungain
Definition: CDCDedxDQM.h:96
TH2D * hdEdxvsPhi
dedx vs phi
Definition: CDCDedxDQM.h:104
double getIndexVal(int iWire, TString what)
get index val of cdc wire/layer/parameters
Definition: CDCDedxDQM.cc:260
TH2D * hdEdxvsEvt
dedx vs event
Definition: CDCDedxDQM.h:106
std::string mmode
monitoring mode all/basic
Definition: CDCDedxDQM.h:99
StoreObjPtr< SoftwareTriggerResult > m_TrgResult
Store array for Trigger selection.
Definition: CDCDedxDQM.h:85
virtual void defineHisto() override
Defination of histograms.
Definition: CDCDedxDQM.cc:31
std::vector< double > m_adc[14336]
adc per wire for wire status
Definition: CDCDedxDQM.h:97
Debug output for CDCDedxPID module.
Definition: CDCDedxTrack.h:25
int getADCCount(int i) const
Return the adcCount for this hit.
Definition: CDCDedxTrack.h:203
double getDedx() const
Get dE/dx truncated mean for this track.
Definition: CDCDedxTrack.h:103
int getNLayerHits() const
Return the number of layer hits for this track.
Definition: CDCDedxTrack.h:159
double getCosTheta() const
Return cos(theta) for this track.
Definition: CDCDedxTrack.h:121
int getWire(int i) const
Return the sensor ID for this hit: wire number for CDC (0-14336)
Definition: CDCDedxTrack.h:191
double getDedxNoSat() const
Get dE/dx truncated mean without the saturation correction for this track.
Definition: CDCDedxTrack.h:106
int size() const
Return the number of hits for this track.
Definition: CDCDedxTrack.h:185
double getMomentum() const
Return the track momentum valid in the CDC.
Definition: CDCDedxTrack.h:118
static const ChargedStable pion
charged pion particle
Definition: Const.h:542
Class for accessing objects in the database.
Definition: DBObjPtr.h:21
ECL cluster data.
Definition: ECLCluster.h:27
bool hasHypothesis(EHypothesisBit bitmask) const
Return if specific hypothesis bit is set.
Definition: ECLCluster.h:348
double getEnergy(EHypothesisBit hypothesis) const
Return Energy (GeV).
Definition: ECLCluster.cc:19
@ c_nPhotons
CR is split into n photons (N1)
HistoModule.h is supposed to be used instead of Module.h for the modules with histogram definitions t...
Definition: HistoModule.h:29
static const ReferenceFrame & GetCurrent()
Get current rest frame.
FROM * getRelatedFrom(const std::string &name="", const std::string &namedRelation="") const
Get the object from which this object has a relation.
Values of the result of a track fit with a given particle hypothesis.
TVector3 getMomentum() const
Getter for vector of momentum at closest approach of track in r/phi projection.
UncertainHelix getUncertainHelix() const
Conversion to framework Uncertain Helix (i.e., with covariance).
Class that bundles various TrackFitResults.
Definition: Track.h:25
This class represents an ideal helix in perigee parameterization including the covariance matrix of t...
double passiveMoveBy(const TVector3 &by)
Moves origin of the coordinate system (passive transformation) by the given vector.
#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.