Belle II Software  release-05-01-25
ECLBhabhaTCollectorModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2020 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: *
7  * Ewan Hill (ehill@mail.ubc.ca) *
8  * Mikhail Remnev *
9  * *
10  * This software is provided "as is" without any warranty. *
11  **************************************************************************/
12 
13 #include <ecl/modules/eclBhabhaTCollector/ECLBhabhaTCollectorModule.h>
14 #include <framework/dataobjects/EventMetaData.h>
15 #include <framework/gearbox/Const.h>
16 #include <ecl/dbobjects/ECLCrystalCalib.h>
17 #include <ecl/dataobjects/ECLDigit.h>
18 #include <ecl/dataobjects/ECLCalDigit.h>
19 #include <mdst/dataobjects/ECLCluster.h>
20 #include <mdst/dataobjects/Track.h>
21 #include <mdst/dataobjects/HitPatternCDC.h>
22 #include <tracking/dataobjects/RecoTrack.h>
23 #include <ecl/digitization/EclConfiguration.h>
24 #include <analysis/utility/PCmsLabTransform.h>
25 #include <analysis/ClusterUtility/ClusterUtils.h>
26 #include <boost/optional.hpp>
27 #include <ecl/geometry/ECLGeometryPar.h>
28 
29 #include <TH2F.h>
30 #include <TTree.h>
31 #include <TFile.h>
32 
33 using namespace Belle2;
34 using namespace ECL;
35 using namespace std;
36 
37 //-----------------------------------------------------------------
38 // Register the Module
39 //-----------------------------------------------------------------
40 REG_MODULE(ECLBhabhaTCollector)
41 
42 //-----------------------------------------------------------------
43 // Implementation
44 //-----------------------------------------------------------------
45 
47  m_ElectronicsDB("ECLCrystalElectronics"),
48  m_ElectronicsTimeDB("ECLCrystalElectronicsTime"),
49  m_FlightTimeDB("ECLCrystalFlightTime"),
50  m_PreviousCrystalTimeDB("ECLCrystalTimeOffset"),
51  m_CrateTimeDB("ECLCrateTimeOffset"),
52  m_dbgTree_electrons(0),
53  m_tree_evtNum(0)//,
54 {
55  setDescription("This module generates sum of all event times per crystal");
56 
57  addParam("timeAbsMax", m_timeAbsMax, // (Time in ADC units)
58  "Events with abs(getTimeFit) > m_timeAbsMax "
59  "are excluded", (short)80);
60 
61  addParam("minCrystal", m_minCrystal,
62  "First CellId to handle.", 1); // 1153 -- first crystal in barrel.
63  addParam("maxCrystal", m_maxCrystal,
64  "Last CellId to handle.", 8736);
65 
66  addParam("saveTree", m_saveTree,
67  "If true, TTree 'tree' with more detailed event info is saved in "
68  "the output file specified by HistoManager",
69  false);
70 
71  addParam("looseTrkZ0", m_looseTrkZ0, "max Z0 for loose tracks (cm)", 10.);
72  addParam("tightTrkZ0", m_tightTrkZ0, "max Z0 for tight tracks (cm)", 2.);
73  addParam("looseTrkD0", m_looseTrkD0, "max D0 for loose tracks (cm)", 2.);
74  addParam("tightTrkD0", m_tightTrkD0, "max D0 for tight tracks (cm)", 0.5); // beam pipe radius = 1cm in 2019
75 
76 
77  // specify this flag if you need parallel processing
78  setPropertyFlags(c_ParallelProcessingCertified);
79 }
80 
82 {
83 }
84 
86 {
87  //=== Prepare TTree for debug output
88  if (m_saveTree) { // /* >>>>>>>>>>>>>>>>>>>>>>>>>>>> if boolean true for saving debug trees >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
89  // Per electron
90  m_dbgTree_electrons = new TTree("tree_electrons", "Debug data for bhabha time calibration - one entry per electron");
91  m_dbgTree_electrons->Branch("EventNum", &m_tree_evtNum)->SetTitle("Event number");
92  m_dbgTree_electrons->Branch("CrystalCellID", &m_tree_cid)->SetTitle("Cell ID, 1..8736");
93  m_dbgTree_electrons->Branch("ADCamplitude", &m_tree_amp)->SetTitle("Amplitude, ADC units");
94  m_dbgTree_electrons->Branch("maxEcrystalEnergy", &m_tree_en)->SetTitle("Max Energy Crystal Energy, GeV");
95  m_dbgTree_electrons->Branch("maxEcrystalEnergyDIVclusterE",
96  &m_tree_E1Etot)->SetTitle("Max Energy Crystal Fraction Energy of Cluster");
97  m_dbgTree_electrons->Branch("E1divE2crystal",
98  &m_tree_E1E2)->SetTitle("Max Energy Crystal DIV second max energy crystal in cluster");
99  m_dbgTree_electrons->Branch("E1crystal_DIV_p", &m_tree_E1p)->SetTitle("Max Energy Crystal in cluster DIV track p");
100  m_dbgTree_electrons->Branch("timetsPreviousTimeCalibs",
101  &m_tree_timetsPreviousTimeCalibs)->SetTitle("Time t_psi after application of previous Ts, ns");
102  m_dbgTree_electrons->Branch("E_DIV_p", &m_E_DIV_p)->SetTitle("E DIV p");
103  m_dbgTree_electrons->Branch("timeF", &m_tree_timeF)->SetTitle("Time F, ns");
104  m_dbgTree_electrons->Branch("time_t_psi", &m_tree_time)->SetTitle("Time t_psi for Ts, ns");
105  m_dbgTree_electrons->Branch("quality", &m_tree_quality)->SetTitle("ECL FPGA fit quality, see Confluence article");
106  m_dbgTree_electrons->Branch("t0", &m_tree_t0)->SetTitle("T0, ns");
107  m_dbgTree_electrons->Branch("t0_unc", &m_tree_t0_unc)->SetTitle("T0 uncertainty, ns");
108  m_dbgTree_electrons->Branch("CrateID", &m_crystalCrate)->SetTitle("Crate id for crystal");
109  m_dbgTree_electrons->Branch("runNum", &m_runNum)->SetTitle("Run number");
110 
111  m_dbgTree_electrons->SetAutoSave(10);
112 
113 
114  // Per track
115  m_dbgTree_tracks = new TTree("tree_tracks", "Debug data for bhabha time calibration - one entry per track");
116  m_dbgTree_tracks->Branch("d0", &m_tree_d0)->SetTitle("d0, cm");
117  m_dbgTree_tracks->Branch("z0", &m_tree_z0)->SetTitle("z0, cm");
118  m_dbgTree_tracks->Branch("p", &m_tree_p)->SetTitle("track momentum, GeV");
119  m_dbgTree_tracks->Branch("charge", &m_charge)->SetTitle("track electric charge");
120  m_dbgTree_tracks->Branch("Num_CDC_hits", &m_tree_nCDChits)->SetTitle("Num CDC hits");
121 
122  m_dbgTree_tracks->SetAutoSave(10);
123 
124  // Per crystal
125  m_dbgTree_crystals = new TTree("tree_crystals",
126  "Debug data for bhabha time calibration - one entry per electron - one entry per crystal");
127  m_dbgTree_crystals->Branch("clustCrysE_DIV_maxEcrys",
128  &m_tree_clustCrysE_DIV_maxEcrys)->SetTitle("E of crystal i from cluster / E of max E crystal");
129  m_dbgTree_crystals->Branch("Crystal_E", &m_tree_clustCrysE) ->SetTitle("E of crystal i from cluster");
130  m_dbgTree_crystals->Branch("time_t_psi", &m_tree_time)->SetTitle("Time for Ts, ns");
131  m_dbgTree_crystals->Branch("Crystal_cell_ID", &m_tree_cid)->SetTitle("Cell ID, 1..8736");
132  m_dbgTree_crystals->Branch("quality", &m_tree_quality)->SetTitle("ECL FPGA fit quality, see Confluence article");
133 
134  m_dbgTree_crystals->SetAutoSave(10);
135 
136 
137  // Per event
138  m_dbgTree_event = new TTree("tree_event", "Debug data for bhabha time calibration - one entry per event");
139  m_dbgTree_event->Branch("massInvTracks", &m_massInvTracks)->SetTitle("Invariant mass of the two tracks");
140 
141  m_dbgTree_event->SetAutoSave(10);
142 
143 
144  m_dbgTree_evt_allCuts = new TTree("tree_evt_allCuts",
145  "Debug data for bhabha time calibration - one entry per event after all the cuts");
146  m_dbgTree_evt_allCuts->Branch("EclustPlus", &m_tree_enPlus)->SetTitle("Energy of cluster with +ve charge, GeV");
147  m_dbgTree_evt_allCuts->Branch("EclustNeg", &m_tree_enNeg)->SetTitle("Energy of cluster with -ve charge, GeV");
148  m_dbgTree_evt_allCuts->Branch("clustTimePos", &m_tree_tClustPos)->SetTitle("Cluster time of cluster with +ve charge, GeV");
149  m_dbgTree_evt_allCuts->Branch("clustTimeNeg", &m_tree_tClustNeg)->SetTitle("Cluster time of cluster with -ve charge, GeV");
150  m_dbgTree_evt_allCuts->Branch("maxEcrysTimePosClust",
151  &m_tree_maxEcrystPosClust)->SetTitle("Time of maximum energy crystal in cluster with +ve charge, GeV");
152  m_dbgTree_evt_allCuts->Branch("maxEcrysTimeNegClust",
153  &m_tree_maxEcrystNegClust)->SetTitle("Time of maximum energy crystal in cluster with -ve charge, GeV");
154  m_dbgTree_evt_allCuts->Branch("t0", &m_tree_t0)->SetTitle("T0, ns");
155  m_dbgTree_evt_allCuts->Branch("t0_ECL_closestCDC", &m_tree_t0_ECLclosestCDC)->SetTitle("T0 ECL closest to CDC t0, ns");
156  m_dbgTree_evt_allCuts->Branch("t0_ECL_minChi2", &m_tree_t0_ECL_minChi2)->SetTitle("T0 ECL with smallest chi squared, ns");
157 
158  m_dbgTree_evt_allCuts->SetAutoSave(10);
159 
160 
161  // Per crystal within each cluster, entry after all the cuts
162  m_dbgTree_crys_allCuts = new TTree("m_dbgTree_crys_allCuts",
163  "Debug data for bhabha time calibration - one entry per crystal per cluster entry after all cuts");
164 
165  m_dbgTree_crys_allCuts->Branch("runNum", &m_runNum)->SetTitle("Run number");
166  m_dbgTree_crys_allCuts->Branch("EventNum", &m_tree_evtNum)->SetTitle("Event number");
167  m_dbgTree_crys_allCuts->Branch("m_tree_ECLCalDigitTime",
168  &m_tree_ECLCalDigitTime)
169  ->SetTitle("Time of a crystal within the cluster after application of previous calibrations except t0, ns");
170  m_dbgTree_crys_allCuts->Branch("m_tree_ECLCalDigitE", &m_tree_ECLCalDigitE)->SetTitle("Energy of crystal, GeV");
171  m_dbgTree_crys_allCuts->Branch("m_tree_ECLDigitAmplitude",
172  &m_tree_ECLDigitAmplitude)->SetTitle("Amplitude of crystal signal pulse");
173  m_dbgTree_crys_allCuts->Branch("timetsPreviousTimeCalibs",
174  &m_tree_timetsPreviousTimeCalibs)->SetTitle("Time t_psi after application of previous Ts, ns");
175  m_dbgTree_crys_allCuts->Branch("t0", &m_tree_t0)->SetTitle("T0, ns");
176  m_dbgTree_crys_allCuts->Branch("t0_ECL_closestCDC", &m_tree_t0_ECLclosestCDC)->SetTitle("T0 ECL closest to CDC t0, ns");
177  m_dbgTree_crys_allCuts->Branch("t0_ECL_minChi2", &m_tree_t0_ECL_minChi2)->SetTitle("T0 ECL with smallest chi squared, ns");
178  m_dbgTree_crys_allCuts->Branch("CrystalCellID", &m_tree_cid)->SetTitle("Cell ID, 1..8736");
179 
180  m_dbgTree_crys_allCuts->SetAutoSave(10);
181 
182 
183  } // <<<<<<<<<<<<<<<<<<<<< if boolean true for saving debug trees <<<<<<<<<<<<<<<<<<<<<<<<<< */
184 
185 
186  // Per max E crystal entry after all the cuts
187  // this tree is always saved
188  m_dbgTree_allCuts = new TTree("tree_allCuts",
189  "Debug data for bhabha time calibration - one entry per max E crystal entry after cuts");
190 
191  m_dbgTree_allCuts->Branch("time_t_psi", &m_tree_time)->SetTitle("Time t_psi for Ts, ns");
192  m_dbgTree_allCuts->Branch("crateID", &m_crystalCrate)->SetTitle("Crate id for crystal");
193  m_dbgTree_allCuts->Branch("EventNum", &m_tree_evtNum)->SetTitle("Event number");
194  m_dbgTree_allCuts->Branch("runNum", &m_runNum)->SetTitle("Run number");
195  m_dbgTree_allCuts->Branch("CrystalCellID", &m_tree_cid)->SetTitle("Cell ID, 1..8736");
196  m_dbgTree_allCuts->Branch("maxEcrystalEnergy", &m_tree_en)->SetTitle("Max Energy Crystal Energy, GeV");
197  m_dbgTree_allCuts->Branch("maxEcrystalEnergyDIVclusterE",
198  &m_tree_E1Etot)->SetTitle("Max Energy Crystal Fraction Energy of Cluster");
199  m_dbgTree_allCuts->Branch("E1divE2crystal",
200  &m_tree_E1E2)->SetTitle("Max Energy Crystal DIV second max energy crystal in cluster");
201  m_dbgTree_allCuts->Branch("E1crystalDIVp", &m_tree_E1p)->SetTitle("Max Energy Crystal in cluster DIV track p");
202  m_dbgTree_allCuts->Branch("timetsPreviousTimeCalibs",
203  &m_tree_timetsPreviousTimeCalibs)->SetTitle("Time t_psi after application of previous Ts, ns");
204  m_dbgTree_allCuts->Branch("massInvTracks", &m_massInvTracks)->SetTitle("Invariant mass of the two tracks");
205  m_dbgTree_allCuts->Branch("t0", &m_tree_t0)->SetTitle("T0, ns");
206  m_dbgTree_allCuts->Branch("t0_ECL_closestCDC", &m_tree_t0_ECLclosestCDC)->SetTitle("T0 ECL closest to CDC t0, ns");
207  m_dbgTree_allCuts->Branch("t0_ECL_minChi2", &m_tree_t0_ECL_minChi2)->SetTitle("T0 ECL with smallest chi squared, ns");
208 
209  m_dbgTree_allCuts->Branch("clusterTime", &m_tree_tClust)->SetTitle("Cluster time of cluster with +ve charge, GeV");
210 
211  m_dbgTree_allCuts->SetAutoSave(10);
212 
213 }
214 
216 {
217  //=== MetaData
218  StoreObjPtr<EventMetaData> evtMetaData;
219 
220  B2INFO("ECLBhabhaTCollector: Experiment = " << evtMetaData->getExperiment() <<
221  " run = " << evtMetaData->getRun());
222 
223 
224  //=== Create histograms and register them in the data store
225 
226  int nbins = m_timeAbsMax * 8;
227  int max_t = m_timeAbsMax;
228  int min_t = -m_timeAbsMax;
229 
230 
231  auto TimevsCrysPrevCrateCalibPrevCrystCalib = new TH2F("TimevsCrysPrevCrateCalibPrevCrystCalib",
232  "Time t psi - ts - tcrate (previous calibs) vs crystal ID;crystal ID;Time t_psi with previous calib (ns)",
233  8736, 0, 8736, nbins, min_t, max_t);
234  registerObject<TH2F>("TimevsCrysPrevCrateCalibPrevCrystCalib", TimevsCrysPrevCrateCalibPrevCrystCalib);
235 
236  auto TimevsCratePrevCrateCalibPrevCrystCalib = new TH2F("TimevsCratePrevCrateCalibPrevCrystCalib",
237  "Time t psi - ts - tcrate (previous calibs) vs crate ID;crate ID;Time t_psi previous calib (ns)",
238  52, 1, 53, nbins, min_t, max_t);
239  registerObject<TH2F>("TimevsCratePrevCrateCalibPrevCrystCalib", TimevsCratePrevCrateCalibPrevCrystCalib);
240 
241  auto TimevsCrysNoCalibrations = new TH2F("TimevsCrysNoCalibrations",
242  "Time tpsi vs crystal ID;crystal ID;Time t_psi (ns)", 8736, 0, 8736, nbins, min_t, max_t);
243  registerObject<TH2F>("TimevsCrysNoCalibrations", TimevsCrysNoCalibrations);
244 
245  auto TimevsCrateNoCalibrations = new TH2F("TimevsCrateNoCalibrations",
246  "Time tpsi vs crate ID;crate ID;Time t_psi (ns)", 52, 1, 53, nbins, min_t, max_t);
247  registerObject<TH2F>("TimevsCrateNoCalibrations", TimevsCrateNoCalibrations);
248 
249  auto TimevsCrysPrevCrateCalibNoCrystCalib = new TH2F("TimevsCrysPrevCrateCalibNoCrystCalib",
250  "Time tpsi - tcrate (previous calib) vs crystal ID;crystal ID;Time t_psi including previous crate calib (ns)",
251  8736, 0, 8736, nbins, min_t, max_t);
252  registerObject<TH2F>("TimevsCrysPrevCrateCalibNoCrystCalib", TimevsCrysPrevCrateCalibNoCrystCalib);
253 
254  auto TimevsCrateNoCrateCalibPrevCrystCalib = new TH2F("TimevsCrateNoCrateCalibPrevCrystCalib",
255  "Time tpsi - ts (previous calib) vs crate ID;crate ID;Time t_psi including previous crystal calib (ns)",
256  52, 1, 53, nbins, min_t, max_t);
257  registerObject<TH2F>("TimevsCrateNoCrateCalibPrevCrystCalib", TimevsCrateNoCrateCalibPrevCrystCalib);
258 
259 
260  auto TsDatabase = new TH1F("TsDatabase", ";cell id;Ts from database", 8736, 0, 8736);
261  registerObject<TH1F>("TsDatabase", TsDatabase);
262 
263  auto TsDatabaseUnc = new TH1F("TsDatabaseUnc", ";cell id;Ts uncertainty from database", 8736, 0, 8736);
264  registerObject<TH1F>("TsDatabaseUnc", TsDatabaseUnc);
265 
266  auto TcrateDatabase = new TH1F("TcrateDatabase", ";cell id;Tcrate from database", 8736, 0, 8736);
267  registerObject<TH1F>("TcrateDatabase", TcrateDatabase);
268 
269  auto TcrateUncDatabase = new TH1F("TcrateUncDatabase", ";cell id;Tcrate uncertainty from database", 8736, 0, 8736);
270  registerObject<TH1F>("TcrateUncDatabase", TcrateUncDatabase);
271 
272 
273  auto tcrateDatabase_ns = new TH1F("tcrateDatabase_ns", ";crate id;tcrate derived from database", 52, 0, 52);
274  registerObject<TH1F>("tcrateDatabase_ns", tcrateDatabase_ns);
275 
276 
277  auto databaseCounter = new TH1F("databaseCounter",
278  ";A database was read in;Number of times database was saved to histogram", 1, 1, 2);
279  registerObject<TH1F>("databaseCounter", databaseCounter);
280 
281 
282  auto numCrystalEntriesPerEvent = new TH1F("numCrystalEntriesPerEvent",
283  ";Number crystal entries;Number of events", 15, 0, 15);
284  registerObject<TH1F>("numCrystalEntriesPerEvent", numCrystalEntriesPerEvent);
285 
286  auto cutflow = new TH1F("cutflow", ";Cut label number;Number of events passing cut", 20, 0, 20);
287  registerObject<TH1F>("cutflow", cutflow);
288 
289  auto numPhotonClustersPerTrack = new TH1F("numPhotonClustersPerTrack",
290  ";Number of photon clusters per track;Number", 20, 0, 20);
291  registerObject<TH1F>("numPhotonClustersPerTrack", numPhotonClustersPerTrack);
292 
293  auto maxEcrsytalEnergyFraction = new TH1F("maxEcrsytalEnergyFraction",
294  ";Maximum energy crystal energy / (sum) cluster energy;Number", 22, 0, 1.1);
295  registerObject<TH1F>("maxEcrsytalEnergyFraction", maxEcrsytalEnergyFraction);
296 
297 
298  auto numEntriesPerCrystal = new TH1F("numEntriesPerCrystal", ";cell id;Number", 8736, 0, 8736);
299  registerObject<TH1F>("numEntriesPerCrystal", numEntriesPerCrystal);
300 
301 
302  auto TimevsRunPrevCrateCalibPrevCrystCalibCID1338 = new TH2F("TimevsRunPrevCrateCalibPrevCrystCalibCID1338",
303  "Time t psi - ts - tcrate (previous calibs) vs run number cid 1338;Run number;Time t_psi with previous calib (ns)",
304  7000, 1, 7000, nbins, min_t, max_t);
305  registerObject<TH2F>("TimevsRunPrevCrateCalibPrevCrystCalibCID1338", TimevsRunPrevCrateCalibPrevCrystCalibCID1338);
306 
307  auto TimevsRunPrevCrateCalibPrevCrystCalibCrate8 = new TH2F("TimevsRunPrevCrateCalibPrevCrystCalibCrate8",
308  "Time t psi - ts - tcrate (previous calibs) vs run number crate 8;Run number;Time t_psi with previous calib (ns)",
309  7000, 1, 7000, nbins, min_t, max_t);
310  registerObject<TH2F>("TimevsRunPrevCrateCalibPrevCrystCalibCrate8", TimevsRunPrevCrateCalibPrevCrystCalibCrate8);
311 
312 
313 
314 
315  //=== Required data objects
316  m_eventT0.isRequired();
317  tracks.isRequired();
318  m_eclClusterArray.isRequired();
319  m_eclCalDigitArray.isRequired();
320  m_eclDigitArray.isRequired();
321 
322 }
323 
325 {
326  int cutIndexPassed = 0;
327  getObjectPtr<TH1F>("cutflow")->Fill(cutIndexPassed);
328  B2DEBUG(10, "Cutflow: no cuts: index = " << cutIndexPassed);
329 
330 
331  /* Use ECLChannelMapper to get other detector indices for the crystals */
332  /* For conversion from CellID to crate, shaper, and channel ids. */
333 
334  // Use smart pointer to avoid memory leak when the ECLChannelMapper object needs destroying at the end of the event.
335  shared_ptr< ECL::ECLChannelMapper > crystalMapper(new ECL::ECLChannelMapper());
336  crystalMapper->initFromDB();
337 
338  //== Get expected energies and calibration constants from DB. Need to call
339  // hasChanged() for later comparison
340  if (m_ElectronicsDB.hasChanged()) {
341  m_Electronics = m_ElectronicsDB->getCalibVector();
342  }
343  if (m_ElectronicsTimeDB.hasChanged()) {
344  m_ElectronicsTime = m_ElectronicsTimeDB->getCalibVector();
345  }
346  if (m_FlightTimeDB.hasChanged()) {
347  m_FlightTime = m_FlightTimeDB->getCalibVector();
348  }
349 
350  // Get the previous crystal time offset (the same thing that this calibration is meant to calculate).
351  // This can be used for testing purposes, and for the crate time offset.
352  if (m_PreviousCrystalTimeDB.hasChanged()) {
353  m_PreviousCrystalTime = m_PreviousCrystalTimeDB->getCalibVector();
354  m_PreviousCrystalTimeUnc = m_PreviousCrystalTimeDB->getCalibUncVector();
355  }
356 
357  B2DEBUG(35, "Finished checking if previous crystal time payload has changed");
358  if (m_CrateTimeDB.hasChanged()) {
359  m_CrateTime = m_CrateTimeDB->getCalibVector();
360  m_CrateTimeUnc = m_CrateTimeDB->getCalibUncVector();
361  }
362  B2DEBUG(35, "Finished checking if previous crate time payload has changed");
363  B2DEBUG(35, "m_CrateTime size = " << m_CrateTime.size());
364  B2DEBUG(29, "Crate time +- uncertainty [0]= " << m_CrateTime[0] << " +- " << m_CrateTimeUnc[0]);
365  B2DEBUG(29, "Crate time +- uncertainty [8735]= " << m_CrateTime[8735] << " +- " << m_CrateTimeUnc[8735]);
366 
367 
368  // Conversion coefficient from ADC ticks to nanoseconds
369  // TICKS_TO_NS ~ 0.4931 ns/clock tick
370  // 1/(4fRF) = 0.4913 ns/clock tick, where fRF is the accelerator RF frequency, fRF=508.889 MHz.
371  const double TICKS_TO_NS = 1.0 / (4.0 * EclConfiguration::m_rf) * 1e3;
372 
373 
374  vector<float> Crate_time_ns(52, 0.0);
376  // Make a crate time offset vector with an entry per crate (instead of per crystal) and convert from ADC counts to ns.
377  for (int crysID = 1; crysID <= 8736; crysID++) {
378  int crateID_temp = crystalMapper->getCrateID(crysID);
379  Crate_time_ns[crateID_temp - 1] = m_CrateTime[crysID] * TICKS_TO_NS;
380  }
381 
382 
384  if (m_storeCalib) {
385  for (int crysID = 0; crysID < 8736; crysID++) {
386  getObjectPtr<TH1F>("TsDatabase")->Fill(crysID + 0.001, m_PreviousCrystalTime[crysID]);
387  getObjectPtr<TH1F>("TsDatabaseUnc")->Fill(crysID + 0.001, m_PreviousCrystalTimeUnc[crysID]);
388  getObjectPtr<TH1F>("TcrateDatabase")->Fill(crysID + 0.001, m_CrateTime[crysID]);
389  getObjectPtr<TH1F>("TcrateUncDatabase")->Fill(crysID + 0.001, m_CrateTimeUnc[crysID]);
390 
391  B2INFO("cid = " << crysID + 1 << ", Ts previous = " << m_PreviousCrystalTime[crysID]);
392  }
393 
394  for (int crateID_temp = 1; crateID_temp <= 52; crateID_temp++) {
395  getObjectPtr<TH1F>("tcrateDatabase_ns")->Fill(crateID_temp + 0.001, Crate_time_ns[crateID_temp - 1]);
396  }
397 
398  // Use a histogram with only one bin as a counter to know the number of times the database histograms were filled.
399  // This is mostly useful for the talg when running over multiple runs and trying to read ts values.
400  getObjectPtr<TH1F>("databaseCounter")->Fill(1.001, 1);
401 
402  m_storeCalib = false;
403  }
404 
405 
406  /* Getting the event t0 using the full event t0 rather than from the CDC specifically */
407  double evt_t0 = -1;
408  double evt_t0_unc = -1;
409  double evt_t0_ECL_closestCDC = -1;
410  double evt_t0_ECL_minChi2 = -1;
411 
412  // Determine if there is an event t0 to use and then extract the information about it
413  if (!m_eventT0.isValid()) {
414  //cout << "event t0 not valid\n";
415  return;
416  } else if (!m_eventT0->hasTemporaryEventT0(Const::EDetector::CDC)) {
417  //cout << "no event t0\n";
418  return;
419  } else {
420  // Event has a t0 from CDC
421  cutIndexPassed++;
422  getObjectPtr<TH1F>("cutflow")->Fill(cutIndexPassed);
423  B2DEBUG(10, "Cutflow: Event t0 exists: index = " << cutIndexPassed);
424 
425 
426  // Get event t0 from CDC. We don't want event t0 from ECL as we are calibrating the ECL wrt the more accurately measured time measurements of the time. Start with the CDC since it has an event t0 but in the future we may switch to the TOP detector.
427  // Based on the information from Thomas Hauth <Thomas.Hauth@kit.edu> (leaving physics) we should take the last event t0 in the list of event t0's from the CDC as the later event t0 measurements are calculated in slower but more accurate ways.
428  vector<EventT0::EventT0Component> evt_t0_list = m_eventT0->getTemporaryEventT0s(Const::EDetector::CDC);
429  evt_t0 = evt_t0_list.back().eventT0; // time value
430  evt_t0_unc = evt_t0_list.back().eventT0Uncertainty; // uncertainty on event t0
431 
432 
433  // Get the ECL event t0 for comparison - validations
434  if (m_eventT0->hasTemporaryEventT0(Const::EDetector::ECL)) {
435  vector<EventT0::EventT0Component> evt_t0_list_ECL = m_eventT0->getTemporaryEventT0s(Const::EDetector::ECL);
436 
437 
438  double smallest_CDC_ECL_t0_diff = fabs(evt_t0_list_ECL[0].eventT0 - evt_t0);
439  int smallest_CDC_ECL_t0_diff_idx = 0;
440  for (long unsigned int ECLi = 0; ECLi < evt_t0_list_ECL.size(); ECLi++) {
441  double tempt_ECL_t0 = evt_t0_list_ECL[ECLi].eventT0;
442  if (fabs(tempt_ECL_t0 - evt_t0) < smallest_CDC_ECL_t0_diff) {
443  smallest_CDC_ECL_t0_diff = fabs(tempt_ECL_t0 - evt_t0);
444  smallest_CDC_ECL_t0_diff_idx = ECLi;
445  }
446  }
447 
448  evt_t0_ECL_closestCDC = evt_t0_list_ECL[smallest_CDC_ECL_t0_diff_idx].eventT0; // time value
449  B2DEBUG(30, "evt_t0_ECL_closestCDC = " << evt_t0_ECL_closestCDC);
450 
451 
452 
453  double smallest_ECL_t0_minChi2 = evt_t0_list_ECL[0].quality;
454  int smallest_ECL_t0_minChi2_idx = 0;
455 
456  B2DEBUG(30, "evt_t0_list_ECL[0].quality = " << evt_t0_list_ECL[0].quality
457  << ", with ECL event t0 = " << evt_t0_list_ECL[0].eventT0);
458 
459  for (long unsigned int ECLi = 0; ECLi < evt_t0_list_ECL.size(); ECLi++) {
460  B2DEBUG(30, "evt_t0_list_ECL[" << ECLi << "].quality = " << evt_t0_list_ECL[ECLi].quality
461  << ", with ECL event t0 = " <<
462  evt_t0_list_ECL[ECLi].eventT0);
463  if (evt_t0_list_ECL[ECLi].quality < smallest_ECL_t0_minChi2) {
464  smallest_ECL_t0_minChi2 = evt_t0_list_ECL[ECLi].quality;
465  smallest_ECL_t0_minChi2_idx = ECLi;
466  }
467  }
468 
469  evt_t0_ECL_minChi2 = evt_t0_list_ECL[smallest_ECL_t0_minChi2_idx].eventT0; // time value
470 
471  B2DEBUG(30, "evt_t0_ECL_minChi2 = " << evt_t0_ECL_minChi2);
472  B2DEBUG(30, "smallest_ECL_t0_minChi2_idx = " << smallest_ECL_t0_minChi2_idx);
473  }
474  }
475 
476 
477 
478  /* Determine the energies for each of the crystals since this isn't naturally connected to the cluster.
479  Also determine the indexing of the ecl cal digits and the ecl digits
480  Taken from Chris's ec/modules/eclGammaGammaECollector */
481 
482  // Resize vectors
483  m_EperCrys.resize(8736);
484  m_eclCalDigitID.resize(8736);
485  m_eclDigitID.resize(8736);
486 
487 
488  int idx = 0;
489  for (auto& eclCalDigit : m_eclCalDigitArray) {
490  int tempCrysID = eclCalDigit.getCellId() - 1;
491  m_EperCrys[tempCrysID] = eclCalDigit.getEnergy();
492  m_eclCalDigitID[tempCrysID] = idx;
493  idx++;
494  }
495 
496  idx = 0;
497  for (auto& eclDigit : m_eclDigitArray) {
498  int tempCrysID = eclDigit.getCellId() - 1;
499  m_eclDigitID[tempCrysID] = idx;
500  idx++;
501  }
502 
503 
504 
505 
506  //---------------------------------------------------------------------
507  //..Some utilities
508  ClusterUtils cUtil;
509  const TVector3 clustervertex = cUtil.GetIPPosition();
510  PCmsLabTransform boostrotate;
511 
512  //---------------------------------------------------------------------
513  //..Track properties, including 2 maxp tracks. Use pion (211) mass hypothesis,
514  // which is the only particle hypothesis currently available???
515  double maxp[2] = {0., 0.};
516  int maxiTrk[2] = { -1, -1};
517  int nTrkAll = tracks.getEntries();
518 
519  int nTrkLoose = 0;
520  int nTrkTight = 0;
522  /* Loop over all the tracks to define the tight and loose selection tracks.
523  We will select events with only 2 tight tracks and no additional loose tracks.
524  Tight tracks are a subset of looses tracks. */
525  for (int iTrk = 0; iTrk < nTrkAll; iTrk++) {
526  // Get track and assume it is a pion for now ... because it is the only particle we can assume?
527  const TrackFitResult* tempTrackFit = tracks[iTrk]->getTrackFitResult(Const::ChargedStable(211));
528  if (not tempTrackFit) {continue;}
529 
530  // Collect track info to be used for categorizing
531  short charge = tempTrackFit->getChargeSign();
532  double z0 = tempTrackFit->getZ0();
533  double d0 = tempTrackFit->getD0();
534  int nCDChits = tempTrackFit->getHitPatternCDC().getNHits();
535  double p = tempTrackFit->getMomentum().Mag();
536 
537  // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
538  //== Save debug TTree with detailed information if necessary.
539  m_tree_d0 = d0;
540  m_tree_z0 = z0;
541  m_tree_p = p;
542  m_charge = charge;
543  m_tree_nCDChits = nCDChits;
544 
545  if (m_saveTree) {
546  m_dbgTree_tracks->Fill();
547  }
548  //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
549 
550 
551  /* Test if loose track */
552 
553  // d0 and z0 cuts
554  if (abs(d0) > m_looseTrkD0) {
555  continue;
556  }
557  if (abs(z0) > m_looseTrkZ0) {
558  continue;
559  }
560  // Number of hits in the CDC
561  if (nCDChits < 1) {
562  continue;
563  }
564  nTrkLoose++;
565 
566 
567 
568  /* Test if the loose track is also a tight track */
569 
570  // Number of hits in the CDC
571  if (nCDChits < 20) {
572  continue;
573  }
574 
575 
576  // d0 and z0 cuts
577  if (abs(d0) > m_tightTrkD0) {
578  continue;
579  }
580  if (abs(z0) > m_tightTrkZ0) {
581  continue;
582  }
583  nTrkTight++;
584 
585  // Sorting of tight tracks. Not really required as we only want two tight tracks (at the moment) but okay.
586  //..Find the maximum p negative [0] and positive [1] tracks
587  int icharge = 0;
588  if (charge > 0) {icharge = 1;}
589  if (p > maxp[icharge]) {
590  maxp[icharge] = p;
591  maxiTrk[icharge] = iTrk;
592  }
593 
594  }
595  /* After that last section the numbers of loose and tight tracks are known as well as the
596  index of the loose tracks that have the highest p negatively charged and highest p positively
597  charged tracks as measured in the centre of mass frame */
598 
599 
600  if (nTrkTight != 2) {
601  return;
602  }
603  // There are exactly two tight tracks
604  cutIndexPassed++;
605  getObjectPtr<TH1F>("cutflow")->Fill(cutIndexPassed);
606  B2DEBUG(10, "Cutflow: Two tight tracks: index = " << cutIndexPassed);
607 
608 
609  if (nTrkLoose != 2) {
610  return;
611  }
612  // There are exactly two loose tracks as well, i.e. no additional loose tracks
613  cutIndexPassed++;
614  getObjectPtr<TH1F>("cutflow")->Fill(cutIndexPassed);
615  B2DEBUG(10, "Cutflow: No additional loose tracks: index = " << cutIndexPassed);
616 
617  /* Determine if the two tracks have the opposite electric charge.
618  We know this because the track indices stores the max pt track in [0] for negatively charged track
619  and [1] fo the positively charged track. If both are filled then both a negatively charged
620  and positively charged track were found. */
621  bool oppositelyChargedTracksPassed = maxiTrk[0] != -1 && maxiTrk[1] != -1;
622  if (!oppositelyChargedTracksPassed) {
623  return;
624  }
625  // The two tracks have the opposite electric charges.
626  cutIndexPassed++;
627  getObjectPtr<TH1F>("cutflow")->Fill(cutIndexPassed);
628  B2DEBUG(10, "Cutflow: Oppositely charged tracks: index = " << cutIndexPassed);
629 
630 
631 
632 
633  //---------------------------------------------------------------------
634  /* Determine associated energy clusters to each of the two tracks. Sum the energies of the
635  multiple clusters to each track and find the crystal with the maximum energy within all
636  the sets of clusters associated to the tracks*/
637  double trkEClustLab[2] = {0., 0.};
638  double trkEClustCOM[2] = {0., 0.};
639  double trkpLab[2];
640  double trkpCOM[2];
641  //double trkThetaLab[2];
642  TLorentzVector trkp4Lab[2];
643  TLorentzVector trkp4COM[2];
644 
645  // Index of the cluster and the crystal that has the highest energy crystal for the two tracks
646  int crysIDMax[2] = { -1, -1 };
647  double crysEMax[2] = { -1, -1 };
648  double crysE2Max[2] = { -1, -1 };
649  int numClustersPerTrack[2] = { 0, 0 };
650 
651  double clusterTime[2] = {0, 0};
652 
653  double E_DIV_p[2];
654 
655  vector<double> time_ECLCaldigits_bothClusters;
656  vector<int> cid_ECLCaldigits_bothClusters;
657  vector<double> E_ECLCaldigits_bothClusters;
658  vector<double> amp_ECLDigits_bothClusters;
659  vector<int> chargeID_ECLCaldigits_bothClusters;
660 
661  for (int icharge = 0; icharge < 2; icharge++) {
662  if (maxiTrk[icharge] > -1) {
663  B2DEBUG(10, "looping over the 2 max pt tracks");
664 
665  const TrackFitResult* tempTrackFit = tracks[maxiTrk[icharge]]->getTrackFitResult(Const::ChargedStable(211));
666  trkp4Lab[icharge] = tempTrackFit->get4Momentum();
667  trkp4COM[icharge] = boostrotate.rotateLabToCms() * trkp4Lab[icharge];
668  trkpLab[icharge] = trkp4Lab[icharge].Rho();
669  trkpCOM[icharge] = trkp4COM[icharge].Rho();
670 
671 
672  /* For each cluster associated to the current track, sum up the energies to get the total
673  energy of all clusters associated to the track and find which crystal has the highest
674  energy from all those clusters*/
675  auto eclClusterRelationsFromTracks = tracks[maxiTrk[icharge]]->getRelationsTo<ECLCluster>();
676  for (unsigned int clusterIdx = 0; clusterIdx < eclClusterRelationsFromTracks.size(); clusterIdx++) {
677 
678  B2DEBUG(10, "Looking at clusters. index = " << clusterIdx);
679  auto cluster = eclClusterRelationsFromTracks[clusterIdx];
680  bool goodClusterType = false;
681 
682  if (cluster->hasHypothesis(Belle2::ECLCluster::EHypothesisBit::c_nPhotons)) {
683  trkEClustLab[icharge] += cluster->getEnergy(Belle2::ECLCluster::EHypothesisBit::c_nPhotons);
684  goodClusterType = true;
685  numClustersPerTrack[icharge]++;
686  }
687 
688  if (goodClusterType) {
689 
690  clusterTime[icharge] = cluster->getTime();
691 
692  auto eclClusterRelations = cluster->getRelationsTo<ECLCalDigit>("ECLCalDigits");
693 
694  // Find the crystal that has the largest energy
695  for (unsigned int ir = 0; ir < eclClusterRelations.size(); ir++) {
696  const auto calDigit = eclClusterRelations.object(ir);
697  int tempCrysID = calDigit->getCellId() - 1;
698  double tempE = m_EperCrys[tempCrysID];
699 
700  int eclDigitIndex = m_eclDigitID[tempCrysID];
701  ECLDigit* ecl_dig = m_eclDigitArray[eclDigitIndex];
702 
703  // for the max E crystal
704  if (tempE > crysEMax[icharge]) {
705  // Set 2nd highest E crystal to the info from the highest E crystal
706  crysE2Max[icharge] = crysEMax[icharge];
707  // Set the highest E crystal to the current crystal
708  crysEMax[icharge] = tempE;
709  crysIDMax[icharge] = tempCrysID;
710  }
711  // for the 2nd highest E crystal
712  if (tempE > crysE2Max[icharge] && tempCrysID != crysIDMax[icharge]) {
713  crysE2Max[icharge] = tempE;
714  }
715 
716 
717  B2DEBUG(30, "calDigit(ir" << ir << ") time = " << calDigit->getTime() << "ns , with E = " << tempE << " GeV");
718  time_ECLCaldigits_bothClusters.push_back(calDigit->getTime());
719  cid_ECLCaldigits_bothClusters.push_back(tempCrysID);
720  E_ECLCaldigits_bothClusters.push_back(tempE);
721  amp_ECLDigits_bothClusters.push_back(ecl_dig->getAmp());
722  chargeID_ECLCaldigits_bothClusters.push_back(icharge);
723 
724  }
725  }
726  }
727  trkEClustCOM[icharge] = trkEClustLab[icharge] * trkpCOM[icharge] / trkpLab[icharge];
728 
729  // Send to the histogram the number of photon clusters associated to the track
730  getObjectPtr<TH1F>("numPhotonClustersPerTrack")->Fill(numClustersPerTrack[icharge]);
731 
732 
733  // Check both electrons to see if their cluster energy / track momentum is good.
734  // The Belle II physics book shows that this is the main way of separating electrons from other particles
735  // Done in the centre of mass reference frame although I believe E/p is invariant under a boost.
736  E_DIV_p[icharge] = trkEClustCOM[icharge] / trkpCOM[icharge];
737 
738  }
739  }
740  /* At the end of this section the 3-momenta magnitudes and the cluster energies are known
741  for the two saved track indices for both the lab and COM frames.
742  The crystal with the maximum energy, one associated to each track, is recorded*/
743 
744 
745 
746  //=== Check each crystal in the processed event and fill histogram.
747 
748  int cid;
749  double time;
750  int numCrystalsPassingCuts = 0;
751 
752  int crystalIDs[2] = { -1, -1};
753  int crateIDs[2] = { -1, -1};
754  double ts_prevCalib[2] = { -1, -1};
755  double tcrate_prevCalib[2] = { -1, -1};
756  double times_noPreviousCalibrations[2] = { -1, -1};
757  bool crystalCutsPassed[2] = {false, false};
758  double crystalEnergies[2] = { -1, -1};
759  double crystalEnergies2[2] = { -1, -1};
760 
761  for (int iCharge = 0; iCharge < 2; iCharge++) {
762  int crystal_idx = crysIDMax[iCharge];
763  int eclCalDigitIndex = m_eclCalDigitID[crystal_idx];
764  int eclDigitIndex = m_eclDigitID[crystal_idx];
765 
766  ECLDigit* ecl_dig = m_eclDigitArray[eclDigitIndex];
767  ECLCalDigit* ecl_cal = m_eclCalDigitArray[eclCalDigitIndex];
768 
769  //== Check whether specific ECLDigits should be excluded.
770 
771  auto en = ecl_cal->getEnergy();
772  auto amplitude = ecl_dig->getAmp();
773  crystalEnergies[iCharge] = en;
774 
775  cid = ecl_dig->getCellId();
776  time = ecl_dig->getTimeFit() * TICKS_TO_NS - evt_t0;
777 
778  // Offset time by electronics calibration and flight time calibration.
779  time -= m_ElectronicsTime[cid - 1] * TICKS_TO_NS;
780  time -= m_FlightTime[cid - 1];
781 
782 
783  // Apply the time walk correction: time shift as a function of the amplitude corrected by the electronics calibration.
784  // The electronics calibration also accounts for crystals that have a dead pre-amp and thus half the normal amplitude.
785  double energyTimeShift = m_ECLTimeUtil->energyDependentTimeOffsetElectronic(amplitude * m_Electronics[cid - 1]) * TICKS_TO_NS;
786 
787  B2DEBUG(35, "cellid = " << cid << ", amplitude = " << amplitude << ", time before t(E) shift = " << time <<
788  ", t(E) shift = " << energyTimeShift << " ns");
789  time -= energyTimeShift;
790 
791 
792  // Cell ID should be within specified range.
793  if (cid < m_minCrystal || cid > m_maxCrystal) continue;
794 
795  // Absolute time should be in specified range condition.
796  if (fabs(time) > m_timeAbsMax) continue;
797 
798  // Fit quality flag -- choose only events with best fit quality
799  if (ecl_dig->getQuality() != 0) continue;
800 
801  //== Save time and crystal information. Fill plot after both electrons are tested
802  crystalIDs[iCharge] = cid;
803  crateIDs[iCharge] = crystalMapper->getCrateID(ecl_cal->getCellId());
804 
805 
806  ts_prevCalib[iCharge] = m_PreviousCrystalTime[cid - 1] * TICKS_TO_NS;
807  tcrate_prevCalib[iCharge] = m_CrateTime[cid - 1] * TICKS_TO_NS;
808  times_noPreviousCalibrations[iCharge] = time;
809 
810 
811  B2DEBUG(30, "iCharge = " << iCharge);
812  B2DEBUG(30, "crateIDs[iCharge] = " << crateIDs[iCharge]);
813  B2DEBUG(30, "times_noPreviousCalibrations[iCharge] = " << times_noPreviousCalibrations[iCharge]);
814  B2DEBUG(30, "tcrate_prevCalib[iCharge] = " << tcrate_prevCalib[iCharge]);
815  B2DEBUG(30, "ts_prevCalib[iCharge] = " << ts_prevCalib[iCharge]);
816 
817 
818  crystalCutsPassed[iCharge] = true;
819 
820 
821  // For second most energetic energy crystal
822  crystalEnergies2[iCharge] = crysE2Max[iCharge];
823 
824 
825 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Tree saving
826  //== Save debug TTree with detailed information if necessary.
827  StoreObjPtr<EventMetaData> evtMetaData;
828 
829  m_tree_cid = ecl_dig->getCellId();
830  m_tree_amp = ecl_dig->getAmp();
831  m_tree_en = en;
832  m_tree_E1Etot = en / trkEClustLab[iCharge];
833  m_tree_E1E2 = en / crystalEnergies2[iCharge];
834  m_tree_E1p = en / trkpLab[iCharge];
835  m_tree_timetsPreviousTimeCalibs = time - ts_prevCalib[iCharge] - tcrate_prevCalib[iCharge];
836  m_tree_timeF = ecl_dig->getTimeFit() * TICKS_TO_NS;
837  m_tree_time = time;
838  m_tree_quality = ecl_dig->getQuality();
839  m_tree_t0 = evt_t0;
840  m_tree_t0_unc = evt_t0_unc;
841  m_E_DIV_p = E_DIV_p[iCharge];
842  m_tree_evtNum = evtMetaData->getEvent();
843  m_crystalCrate = crystalMapper->getCrateID(ecl_cal->getCellId());
844  m_runNum = evtMetaData->getRun();
845 
846  if (m_saveTree) {
847  m_dbgTree_electrons->Fill();
848  }
849 // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Tree saving
850 
851  // Fill histogram with information about maximum energy crystal energy fraction
852  getObjectPtr<TH1F>("maxEcrsytalEnergyFraction")->Fill(en / trkEClustLab[iCharge]);
853 
854 
855  }
856 
857 
858 
859  // Check both electrons to see if their cluster energy / track momentum is good.
860  // The Belle II physics book shows that this is the main way of separating electrons from other particles
861  // Done in the centre of mass reference frame although I believe E/p is invariant under a boost.
862  bool E_DIV_p_instance_passed[2] = {false, false};
863  double E_DIV_p_CUT = 0.7;
864  for (int icharge = 0; icharge < 2; icharge++) {
865  E_DIV_p_instance_passed[icharge] = E_DIV_p[icharge] > E_DIV_p_CUT;
866  }
867  if (!E_DIV_p_instance_passed[0] || !E_DIV_p_instance_passed[1]) {
868  return;
869  }
870  // E/p sufficiently large
871  cutIndexPassed++;
872  getObjectPtr<TH1F>("cutflow")->Fill(cutIndexPassed);
873  B2DEBUG(10, "Cutflow: E_i/p_i > " << E_DIV_p_CUT << ": index = " << cutIndexPassed);
874 
875 
876 
877 
878 
879 
880  // Now find energy clusters independently of the tracks
881  //------------------------------------------------------------------------
882 
883  vector<double> goodClusters_E;
884 
885 
886 
887 
888  double clusterE_minCut = 0.06; // GeV
889  int nclust = m_eclClusterArray.getEntries();
890  int nGoodClusts = 0;
891  vector<int> goodPhotonClusterIdxs;
892  vector<int> goodECLClusterIds;
893  for (int ic = 0; ic < nclust; ic++) {
894  if (m_eclClusterArray[ic]->hasHypothesis(Belle2::ECLCluster::EHypothesisBit::c_nPhotons)) {
895  double eClust = m_eclClusterArray[ic]->getEnergy(Belle2::ECLCluster::EHypothesisBit::c_nPhotons);
896  if (eClust > clusterE_minCut) {
897  goodPhotonClusterIdxs.push_back(ic);
898  goodECLClusterIds.push_back(m_eclClusterArray[ic]->getClusterId());
899  nGoodClusts++;
900  }
901  }
902  }
903 
904  int numTrackless = 0;
905  for (int clustId = 0; clustId < 2; clustId++) {
906  B2DEBUG(30, "m_eclClusterArray[goodPhotonClusterIdxs[clustId]]->isTrack() = " <<
907  m_eclClusterArray[goodPhotonClusterIdxs[clustId]]->isTrack());
908  if (!m_eclClusterArray[goodPhotonClusterIdxs[clustId]]->isTrack()) {
909  numTrackless++;
910  }
911  }
912  if (numTrackless != 0) {
913  B2DEBUG(20, "Number of trackless ECL clusters != 0");
914  }
915 
916  // There are exactly three energy clusters
917  cutIndexPassed++;
918  getObjectPtr<TH1F>("cutflow")->Fill(cutIndexPassed);
919  B2DEBUG(10, "Cutflow: ECL cluster associated to photon does not have a track associated to it: index = " << cutIndexPassed);
920  B2DEBUG(10, "Cutflow: NEW CUT TO BHABHA CODE FROM eegamma code");
921 
922 
923 
924 
925 
926  // Start of cuts on both the combined system of tracks and energy clusters
927 
928  double invMassTrk = (trkp4Lab[0] + trkp4Lab[1]).M();
929  double invMass_CUT = 0.9;
930  m_massInvTracks = invMassTrk; // invariant mass of the two tracks
931 
932 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Tree saving
933  if (m_saveTree) {
934  m_dbgTree_event->Fill();
935  }
936 // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Tree saving
937 
938  bool invMassCutsPassed = invMassTrk > (invMass_CUT * boostrotate.getCMSEnergy());
939  if (!invMassCutsPassed) {
940  return;
941  }
942  // Invariable mass of the two tracks are above the minimum
943  cutIndexPassed++;
944  getObjectPtr<TH1F>("cutflow")->Fill(cutIndexPassed);
945  B2DEBUG(10, "Cutflow: m(track 1+2) > " << invMass_CUT << "*E_COM = " << invMass_CUT << " * " << boostrotate.getCMSEnergy() <<
946  " : index = " << cutIndexPassed);
947 
948 
949 
950  //== Fill output histogram.
951  for (int iCharge = 0; iCharge < 2; iCharge++) {
952  if (crystalCutsPassed[iCharge]) {
953  getObjectPtr<TH2F>("TimevsCrysPrevCrateCalibPrevCrystCalib")->Fill((crystalIDs[iCharge] - 1) + 0.001,
954  times_noPreviousCalibrations[iCharge] - ts_prevCalib[iCharge] - tcrate_prevCalib[iCharge] , 1);
955  getObjectPtr<TH2F>("TimevsCratePrevCrateCalibPrevCrystCalib")->Fill((crateIDs[iCharge]) + 0.001,
956  times_noPreviousCalibrations[iCharge] - ts_prevCalib[iCharge] - tcrate_prevCalib[iCharge], 1);
957  getObjectPtr<TH2F>("TimevsCrysNoCalibrations")->Fill((crystalIDs[iCharge] - 1) + 0.001, times_noPreviousCalibrations[iCharge], 1);
958  getObjectPtr<TH2F>("TimevsCrateNoCalibrations")->Fill((crateIDs[iCharge]) + 0.001, times_noPreviousCalibrations[iCharge], 1);
959  getObjectPtr<TH2F>("TimevsCrysPrevCrateCalibNoCrystCalib")->Fill((crystalIDs[iCharge] - 1) + 0.001,
960  times_noPreviousCalibrations[iCharge] - tcrate_prevCalib[iCharge], 1);
961  getObjectPtr<TH2F>("TimevsCrateNoCrateCalibPrevCrystCalib")->Fill((crateIDs[iCharge]) + 0.001,
962  times_noPreviousCalibrations[iCharge] - ts_prevCalib[iCharge] , 1);
963 
964  getObjectPtr<TH1F>("numEntriesPerCrystal")->Fill((crystalIDs[iCharge] - 1) + 0.001);
965 
966  // Record number of crystals used from the event. Should be exactly two.
967  numCrystalsPassingCuts++;
968 
969 
970  /* Store information about one random specific crystal and one random specific crate for
971  studies of how they vary over time.*/
972  if (crystalIDs[iCharge] == 1338) {
973  getObjectPtr<TH2F>("TimevsRunPrevCrateCalibPrevCrystCalibCID1338")->Fill(m_runNum + 0.001,
974  times_noPreviousCalibrations[iCharge] - ts_prevCalib[iCharge] - tcrate_prevCalib[iCharge] , 1);
975  }
976  if (crateIDs[iCharge] == 8) {
977  getObjectPtr<TH2F>("TimevsRunPrevCrateCalibPrevCrystCalibCrate8")->Fill(m_runNum + 0.001,
978  times_noPreviousCalibrations[iCharge] - ts_prevCalib[iCharge] - tcrate_prevCalib[iCharge] , 1);
979  }
980 
981  }
982  }
983 
984 
985  // Change cutflow method for this bit ... don't call return because we used to call the hadron cluster stuff afterwards
986  //
987  if (crystalCutsPassed[0] || crystalCutsPassed[1]) {
988  // At least one ECL crystal time and quality cuts passed
989  cutIndexPassed++;
990  getObjectPtr<TH1F>("cutflow")->Fill(cutIndexPassed);
991  B2DEBUG(10, "Cutflow: At least one crystal time and quality cuts passed: index = " << cutIndexPassed);
992 
993  getObjectPtr<TH1F>("numCrystalEntriesPerEvent")->Fill(numCrystalsPassingCuts);
994  }
995 
996 
997  // Save final information to the tree after all cuts are applied
998  for (int iCharge = 0; iCharge < 2; iCharge++) {
999  if (crystalCutsPassed[iCharge]) {
1000  // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Tree saving
1001  StoreObjPtr<EventMetaData> evtMetaData;
1002  m_tree_evtNum = evtMetaData->getEvent();
1003  m_tree_cid = crystalIDs[iCharge];
1004  //m_tree_time = times[iCharge];
1005  m_tree_time = times_noPreviousCalibrations[iCharge];
1006  m_crystalCrate = crateIDs[iCharge];
1007  m_runNum = evtMetaData->getRun();
1008  m_tree_en = crystalEnergies[iCharge]; // for studies of ts as a function of energy
1009  m_tree_E1Etot = crystalEnergies[iCharge] / trkEClustLab[iCharge];
1010  m_tree_E1E2 = crystalEnergies[iCharge] / crystalEnergies2[iCharge];
1011  m_tree_E1p = crystalEnergies[iCharge] / trkpLab[iCharge];
1012  m_tree_timetsPreviousTimeCalibs = times_noPreviousCalibrations[iCharge] - ts_prevCalib[iCharge] - tcrate_prevCalib[iCharge];
1013  m_tree_t0 = evt_t0;
1014  m_tree_t0_ECLclosestCDC = evt_t0_ECL_closestCDC;
1015  m_tree_t0_ECL_minChi2 = evt_t0_ECL_minChi2;
1016  m_tree_tClust = clusterTime[iCharge];
1017 
1018  m_massInvTracks = invMassTrk; // This is probably already set but I'll set it again anyways just so that it is clear
1019 
1020  if (m_saveTree) {
1021  m_dbgTree_allCuts->Fill();
1022  }
1023  // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Tree saving
1024  }
1025  }
1026 
1027 
1028 
1029 
1030  if (crystalCutsPassed[0] && crystalCutsPassed[1] &&
1031  numClustersPerTrack[0] == 1 && numClustersPerTrack[1] == 1) {
1032  m_tree_enNeg = trkEClustLab[0];
1033  m_tree_enPlus = trkEClustLab[1];
1034  m_tree_tClustNeg = clusterTime[0];
1035  m_tree_tClustPos = clusterTime[1];
1036  m_tree_maxEcrystPosClust = times_noPreviousCalibrations[0] - ts_prevCalib[0] - tcrate_prevCalib[0];
1037  m_tree_maxEcrystNegClust = times_noPreviousCalibrations[1] - ts_prevCalib[1] - tcrate_prevCalib[1];
1038  m_tree_t0 = evt_t0;
1039  m_tree_t0_ECLclosestCDC = evt_t0_ECL_closestCDC;
1040  m_tree_t0_ECL_minChi2 = evt_t0_ECL_minChi2;
1041 
1042  // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Tree saving
1043  if (m_saveTree) {
1044  m_dbgTree_evt_allCuts->Fill();
1045  }
1046  // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Tree saving
1047  }
1048 
1049 
1050  B2DEBUG(30, "m_tree_maxEcrystPosClust + evt_t0 = " << m_tree_maxEcrystPosClust + evt_t0);
1051  B2DEBUG(30, "m_tree_maxEcrystNegClust + evt_t0 = " << m_tree_maxEcrystNegClust + evt_t0);
1052  B2DEBUG(30, "CDC evt_t0 = " << evt_t0);
1053  B2DEBUG(30, "ECL min chi2 even t0, m_tree_t0_ECL_minChi2 = " << m_tree_t0_ECL_minChi2);
1054 
1055 
1056 
1057  for (long unsigned int digit_i = 0; digit_i < time_ECLCaldigits_bothClusters.size(); digit_i++) {
1058  StoreObjPtr<EventMetaData> evtMetaData;
1059  m_runNum = evtMetaData->getRun();
1060  m_tree_evtNum = evtMetaData->getEvent();
1061  m_tree_ECLCalDigitTime = time_ECLCaldigits_bothClusters[digit_i];
1062  m_tree_ECLCalDigitE = E_ECLCaldigits_bothClusters[digit_i];
1063  m_tree_ECLDigitAmplitude = amp_ECLDigits_bothClusters[digit_i];
1064  m_tree_t0 = evt_t0;
1065  m_tree_t0_ECLclosestCDC = evt_t0_ECL_closestCDC;
1066  m_tree_t0_ECL_minChi2 = evt_t0_ECL_minChi2;
1067  m_tree_timetsPreviousTimeCalibs = times_noPreviousCalibrations[chargeID_ECLCaldigits_bothClusters[digit_i]] -
1068  ts_prevCalib[chargeID_ECLCaldigits_bothClusters[digit_i]] -
1069  tcrate_prevCalib[chargeID_ECLCaldigits_bothClusters[digit_i]];
1070  m_tree_cid = cid_ECLCaldigits_bothClusters[digit_i];
1071 
1072  // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Tree saving
1073  if (m_saveTree) {
1074  m_dbgTree_crys_allCuts->Fill();
1075  }
1076  // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Tree saving
1077 
1078  }
1079 
1080 
1081  B2DEBUG(30, "This was for event number = " << m_tree_evtNum);
1082 
1083 }
1084 
1085 
Belle2::CalibrationCollectorModule
Calibration collector module base class.
Definition: CalibrationCollectorModule.h:44
Belle2::ECLCalDigit::getEnergy
double getEnergy() const
Get Calibrated Energy.
Definition: ECLCalDigit.h:134
Belle2::TrackFitResult::get4Momentum
TLorentzVector get4Momentum() const
Getter for the 4Momentum at the closest approach of the track in the r/phi projection.
Definition: TrackFitResult.h:125
Belle2::ECLBhabhaTCollectorModule::inDefineHisto
void inDefineHisto()
Replacement for defineHisto() in CalibrationCollector modules.
Definition: ECLBhabhaTCollectorModule.cc:85
Belle2::ECLBhabhaTCollectorModule
This module generates time vs crystal 2D histograms to later (in eclBhabhaTAlgorithm) find time cryst...
Definition: ECLBhabhaTCollectorModule.h:45
Belle2::ECLBhabhaTCollectorModule::collect
void collect()
Select events and crystals and accumulate histograms.
Definition: ECLBhabhaTCollectorModule.cc:324
Belle2::ECLCalDigit
Class to store calibrated ECLDigits: ECLCalDigits.
Definition: ECLCalDigit.h:38
Belle2::ECLDigit::getQuality
int getQuality() const
Get Fitting Quality.
Definition: ECLDigit.h:90
Belle2::ECLCluster
ECL cluster data.
Definition: ECLCluster.h:39
Belle2::ECLCalDigit::getCellId
int getCellId() const
Get Cell ID.
Definition: ECLCalDigit.h:129
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::ECL::ECLChannelMapper::getCrateID
int getCrateID(int iCOPPERNode, int iFINESSE)
get crate number by given COPPER node number and FINESSE number
Definition: ECLChannelMapper.cc:211
Belle2::PCmsLabTransform::getCMSEnergy
double getCMSEnergy() const
Returns CMS energy of e+e- (aka.
Definition: PCmsLabTransform.h:57
Belle2::ECLCluster::EHypothesisBit::c_nPhotons
@ c_nPhotons
CR is split into n photons (N1)
Belle2::ECLBhabhaTCollectorModule::prepare
void prepare()
Define histograms and read payloads from DB.
Definition: ECLBhabhaTCollectorModule.cc:215
Belle2::TrackFitResult
Values of the result of a track fit with a given particle hypothesis.
Definition: TrackFitResult.h:59
Belle2::ClusterUtils::GetIPPosition
const TVector3 GetIPPosition()
Returns default IP position from beam parameters.
Definition: ClusterUtils.cc:182
Belle2::ECL::ECLChannelMapper
This class provides access to ECL channel map that is either a) Loaded from the database (see ecl/dbo...
Definition: ECLChannelMapper.h:36
Belle2::ClusterUtils
Class to provide momentum-related information from ECLClusters.
Definition: ClusterUtils.h:44
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::StoreObjPtr
Type-safe access to single objects in the data store.
Definition: ParticleList.h:33
Belle2::ECLDigit::getCellId
int getCellId() const
Get Cell ID.
Definition: ECLDigit.h:74
Belle2::ECL::EclConfiguration::m_rf
static constexpr double m_rf
accelerating RF, http://ptep.oxfordjournals.org/content/2013/3/03A006.full.pdf
Definition: EclConfiguration.h:45
Belle2::ECLDigit
Class to store ECL digitized hits (output of ECLDigi) relation to ECLHit filled in ecl/modules/eclDig...
Definition: ECLDigit.h:34
Belle2::ECLDigit::getTimeFit
int getTimeFit() const
Get Fitting Time.
Definition: ECLDigit.h:85
Belle2::PCmsLabTransform
Class to hold Lorentz transformations from/to CMS and boost vector.
Definition: PCmsLabTransform.h:37
Belle2::PCmsLabTransform::rotateLabToCms
const TLorentzRotation rotateLabToCms() const
Returns Lorentz transformation from Lab to CMS.
Definition: PCmsLabTransform.h:74
Belle2::Const::ChargedStable
Provides a type-safe way to pass members of the chargedStableSet set.
Definition: Const.h:465
Belle2::ECLDigit::getAmp
int getAmp() const
Get Fitting Amplitude.
Definition: ECLDigit.h:80
Belle2::ECL::ECLChannelMapper::initFromDB
bool initFromDB()
Initialize channel mapper from the conditions database.
Definition: ECLChannelMapper.cc:105
Belle2::ECLBhabhaTCollectorModule::~ECLBhabhaTCollectorModule
virtual ~ECLBhabhaTCollectorModule()
Module destructor.
Definition: ECLBhabhaTCollectorModule.cc:81