Belle II Software  release-06-00-14
KLMTimeAlgorithm.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 /* KLM headers. */
12 #include <klm/bklm/geometry/GeometryPar.h>
13 #include <klm/dataobjects/KLMChannelIndex.h>
14 #include <klm/dataobjects/KLMElementNumbers.h>
15 #include <klm/dbobjects/KLMTimeCableDelay.h>
16 #include <klm/dbobjects/KLMTimeConstants.h>
17 #include <klm/eklm/geometry/GeometryData.h>
18 
19 /* Belle 2 headers. */
20 #include <calibration/CalibrationAlgorithm.h>
21 
22 /* ROOT headers. */
23 #include <Math/MinimizerOptions.h>
24 #include <TF1.h>
25 #include <TGraphErrors.h>
26 #include <TH1F.h>
27 #include <TH1I.h>
28 #include <TH2F.h>
29 #include <TProfile.h>
30 
31 namespace Belle2 {
41 
42  public:
43 
47  struct Event {
48 
50  double t0 = 0;
51 
53  double flyTime = 0;
54 
56  double recTime = 0;
57 
59  double dist = 0;
60 
62  double diffDistX = 0;
63 
65  double diffDistY = 0;
66 
68  double diffDistZ = 0;
69 
71  double eDep = 0;
72 
74  double nPE = 0;
75 
77  int channelId = 0;
78 
80  bool inRPC = 0;
81 
83  bool isFlipped = 0;
84 
88  double time()
89  {
90  return recTime - flyTime;
91  }
92 
93  };
94 
99 
100  /* Not enough data. */
101  c_NotEnoughData = 0,
102 
103  /* Failed fit. */
104  c_FailedFit = 1,
105 
106  /* Successful calibration. */
107  c_SuccessfulCalibration = 2,
108 
109  };
110 
115 
120 
124  void setDebug()
125  {
126  m_debug = true;
127  }
128 
134  void setMC(bool mc)
135  {
136  m_mc = mc;
137  }
138 
142  void useEvtT0()
143  {
144  m_useEventT0 = true;
145  }
146 
150  void setMinimalDigitNumber(int minimalDigitNumber)
151  {
152  m_MinimalDigitNumber = minimalDigitNumber;
153  }
154 
160  void setLowerLimit(int counts)
161  {
162  m_lower_limit_counts = counts;
163  }
164 
168  void saveHist();
169 
174  double esti_timeShift(const KLMChannelIndex& klmChannel);
175 
180  std::pair<int, double> tS_upperStrip(const KLMChannelIndex& klmChannel);
181 
186  std::pair<int, double> tS_lowerStrip(const KLMChannelIndex& klmChannel);
187 
188 
189  protected:
190 
194  virtual EResult calibrate() override;
195 
196  private:
197 
201  void setupDatabase();
202 
210 
214  void createHistograms();
215 
241  TProfile* profileRpcPhi, TProfile* profileRpcZ,
242  TProfile* profileBKLMScintillatorPhi, TProfile* profileBKLMScintillatorZ,
243  TProfile* profileEKLMScintillatorPlane1,
244  TProfile* profileEKLMScintillatorPlane2, bool fill2dHistograms);
245 
252  void timeDistance2dFit(
253  const std::vector< std::pair<KLMChannelNumber, unsigned int> >& channels,
254  double& delay, double& delayError);
255 
260  std::map<KLMChannelNumber, std::vector<struct Event> > m_evts;
261 
266  std::map<KLMChannelNumber, int> m_cFlag;
267 
269  std::map<KLMChannelNumber, double> m_timeShift;
270 
272  std::map<KLMChannelNumber, double> m_time_channel;
273 
275  std::map<KLMChannelNumber, double> m_etime_channel;
276 
278  double m_LowerTimeBoundaryRPC = -10.0;
279 
281  double m_UpperTimeBoundaryRPC = 10.0;
282 
285 
288 
291 
294 
297 
300 
303 
306 
309 
312 
314  double m_time_channelAvg_rpc = 0.0;
315 
318 
323 
329 
334 
340 
342  int m_MinimalDigitNumber = 100000000;
343 
346 
349 
352 
355 
358 
360  ROOT::Math::MinimizerOptions m_minimizerOptions;
361 
364 
370 
372  bool m_debug = false;
373 
375  bool m_mc = false;
376 
378  bool m_useEventT0 = true;
379 
381  TH1I* h_calibrated = nullptr;
382 
384  TH1F* h_diff = nullptr;
385 
386  /* Monitor graphs of peak value of time distribution for each channel. */
387 
389  TGraphErrors* gre_time_channel_rpc = nullptr;
390 
392  TGraphErrors* gre_time_channel_scint = nullptr;
393 
395  TGraphErrors* gre_time_channel_scint_end = nullptr;
396 
397  /* Monitor graphs of calibration constant value of each channel. */
398 
400  TGraph* gr_timeShift_channel_rpc = nullptr;
401 
403  TGraph* gr_timeShift_channel_scint = nullptr;
404 
407 
408  /* Profiles used for effective light speed estimation. */
409 
411  TProfile* m_ProfileRpcPhi = nullptr;
412 
414  TProfile* m_ProfileRpcZ = nullptr;
415 
417  TProfile* m_ProfileBKLMScintillatorPhi = nullptr;
418 
420  TProfile* m_ProfileBKLMScintillatorZ = nullptr;
421 
423  TProfile* m_ProfileEKLMScintillatorPlane1 = nullptr;
424 
426  TProfile* m_ProfileEKLMScintillatorPlane2 = nullptr;
427 
428  /* Profiles of time versus distance (after fit). */
429 
431  TProfile* m_Profile2RpcPhi = nullptr;
432 
434  TProfile* m_Profile2RpcZ = nullptr;
435 
437  TProfile* m_Profile2BKLMScintillatorPhi = nullptr;
438 
440  TProfile* m_Profile2BKLMScintillatorZ = nullptr;
441 
443  TProfile* m_Profile2EKLMScintillatorPlane1 = nullptr;
444 
446  TProfile* m_Profile2EKLMScintillatorPlane2 = nullptr;
447 
448  /*
449  * Histograms of global time distribution used for effective light speed
450  * estimation.
451  */
452 
454  TH1F* h_time_rpc_tc = nullptr;
455 
457  TH1F* h_time_scint_tc = nullptr;
458 
460  TH1F* h_time_scint_tc_end = nullptr;
461 
462  /* Histograms of global time distribution before calibration. */
463 
465  TH1F* h_time_rpc = nullptr;
466 
468  TH1F* h_time_scint = nullptr;
469 
471  TH1F* h_time_scint_end = nullptr;
472 
473  /* Histograms of global time distribution after calibration. */
474 
476  TH1F* hc_time_rpc = nullptr;
477 
479  TH1F* hc_time_scint = nullptr;
480 
482  TH1F* hc_time_scint_end = nullptr;
483 
484  /*
485  * Histograms of time distribution for forward (backward)
486  * before calibration.
487  */
488 
490  TH1F* h_timeF_rpc[2] = {nullptr};
491 
493  TH1F* h_timeF_scint[2] = {nullptr};
494 
496  TH1F* h_timeF_scint_end[2] = {nullptr};
497 
498  /*
499  * Histograms of time distribution for forward (backward)
500  * after calibration.
501  */
502 
504  TH1F* hc_timeF_rpc[2] = {nullptr};
505 
507  TH1F* hc_timeF_scint[2] = {nullptr};
508 
510  TH1F* hc_timeF_scint_end[2] = {nullptr};
511 
512  /*
513  * Histograms of time dependent on sector for forward (backward)
514  * before calibration.
515  */
516 
518  TH2F* h2_timeF_rpc[2] = {nullptr};
519 
521  TH2F* h2_timeF_scint[2] = {nullptr};
522 
524  TH2F* h2_timeF_scint_end[2] = {nullptr};
525 
526  /*
527  * Histograms of time dependent on sector for forward (backward)
528  * after calibration.
529  */
530 
532  TH2F* h2c_timeF_rpc[2] = {nullptr};
533 
535  TH2F* h2c_timeF_scint[2] = {nullptr};
536 
538  TH2F* h2c_timeF_scint_end[2] = {nullptr};
539 
540  /* Histograms of time distribution for sectors before calibration. */
541 
543  TH1F* h_timeFS_rpc[2][8] = {nullptr};
544 
546  TH1F* h_timeFS_scint[2][8] = {nullptr};
547 
549  TH1F* h_timeFS_scint_end[2][4] = {nullptr};
550 
551  /* Histograms of time distribution for sectors after calibration. */
552 
554  TH1F* hc_timeFS_rpc[2][8] = {nullptr};
555 
557  TH1F* hc_timeFS_scint[2][8] = {nullptr};
558 
560  TH1F* hc_timeFS_scint_end[2][4] = {nullptr};
561 
562  /*
563  * Histograms of time distribution dependent on layer of sectors
564  * before calibration.
565  */
566 
568  TH2F* h2_timeFS[2][8] = {nullptr};
569 
571  TH2F* h2_timeFS_end[2][4] = {nullptr};
572 
573  /*
574  * Histograms of time distribution dependent on layer of sectors
575  * after calibration.
576  */
577 
579  TH2F* h2c_timeFS[2][8] = {nullptr};
580 
582  TH2F* h2c_timeFS_end[2][4] = {nullptr};
583 
584  /* Histograms of time distribution of one layer before calibration. */
585 
587  TH1F* h_timeFSL[2][8][15] = {nullptr};
588 
590  TH1F* h_timeFSL_end[2][4][14] = {nullptr};
591 
592  /* Histograms of time distribution of one layer after calibration. */
593 
595  TH1F* hc_timeFSL[2][8][15] = {nullptr};
596 
598  TH1F* hc_timeFSL_end[2][4][14] = {nullptr};
599 
600  /* Histograms of time distribution of one plane before calibration. */
601 
603  TH1F* h_timeFSLP[2][8][15][2] = {nullptr};
604 
606  TH1F* h_timeFSLP_end[2][4][14][2] = {nullptr};
607 
608  /* Histograms of time distribution of one plane after calibration. */
609 
611  TH1F* hc_timeFSLP[2][8][15][2] = {nullptr};
612 
614  TH1F* hc_timeFSLP_end[2][4][14][2] = {nullptr};
615 
616  /*
617  * Histograms of time distribution dependent on channels
618  * before calibration.
619  */
620 
622  TH2F* h2_timeFSLP[2][8][15][2] = {nullptr};
623 
625  TH2F* h2_timeFSLP_end[2][4][14][2] = {nullptr};
626 
627  /*
628  * Histograms of time distribution dependent on channels
629  * after calibration.
630  */
631 
633  TH2F* h2c_timeFSLP[2][8][15][2] = {nullptr};
634 
636  TH2F* h2c_timeFSLP_end[2][4][14][2] = {nullptr};
637 
638  /* Histograms of time distribution of each channel before calibration. */
639 
641  TH1F* h_timeFSLPC_tc[2][8][15][2][54] = {nullptr};
642 
644  TH1F* h_timeFSLPC[2][8][15][2][54] = {nullptr};
645 
647  TH2F* m_HistTimeLengthBKLM[2][8][15][2][54] = {nullptr};
648 
650  TH1F* h_timeFSLPC_tc_end[2][4][14][2][75] = {nullptr};
651 
653  TH1F* h_timeFSLPC_end[2][4][14][2][75] = {nullptr};
654 
656  TH2F* m_HistTimeLengthEKLM[2][4][14][2][75] = {nullptr};
657 
658  /* Histograms of time distribution of each channel after calibration. */
659 
661  TH1F* hc_timeFSLPC[2][8][15][2][54] = {nullptr};
662 
664  TH1F* hc_timeFSLPC_end[2][4][14][2][75] = {nullptr};
665 
666  /* Formulas used for fitting. */
667 
669  TF1* fcn_pol1 = nullptr;
670 
672  TF1* fcn_const = nullptr;
673 
675  TF1* fcn_gaus = nullptr;
676 
678  TF1* fcn_land = nullptr;
679 
681  TFile* m_outFile = nullptr;
682 
683  };
684 
686 }
687 
Base class for calibration algorithms.
EResult
The result of calibration.
EKLM geometry data.
Definition: GeometryData.h:38
KLM channel index.
KLM element numbers.
KLM time calibration algorithm.
TProfile * m_Profile2EKLMScintillatorPlane2
For EKLM scintillator plane2.
TH2F * m_HistTimeLengthEKLM[2][4][14][2][75]
Two-dimensional distributions of time versus propagation length.
TH1F * h_timeFSLPC_tc[2][8][15][2][54]
BKLM part, used for effective light speed estimation.
TH2F * h2c_timeF_scint_end[2]
EKLM part.
TH1F * h_timeFSLPC_tc_end[2][4][14][2][75]
EKLM part, used for effective light speed estimation.
TH1F * h_time_scint_tc_end
EKLM part.
void createHistograms()
Create histograms.
TGraphErrors * gre_time_channel_scint
BKLM Scintillator.
double m_LowerTimeBoundaryCalibratedScintilltorsEKLM
Lower time boundary for EKLM scintillators (calibrated data).
double m_LowerTimeBoundaryScintilltorsEKLM
Lower time boundary for EKLM scintillators.
TH1F * h_timeFSL[2][8][15]
BKLM part.
TH1F * hc_timeFSLPC_end[2][4][14][2][75]
EKLM part.
TH1F * hc_timeFSL_end[2][4][14]
EKLM part.
TH1F * h_timeFSLP_end[2][4][14][2]
EKLM part.
TH1F * hc_timeFSLP_end[2][4][14][2]
EKLM part.
TH1F * h_timeFSLP[2][8][15][2]
BKLM part.
TH1F * hc_timeF_scint_end[2]
EKLM part.
std::map< KLMChannelNumber, double > m_timeShift
Shift values of ecah channel.
TH1F * h_time_scint
BKLM scintillator part.
double m_time_channelAvg_scint
Central value of the global time distribution (BKLM scintillator part).
TH1F * hc_timeFS_scint_end[2][4]
EKLM part.
double m_UpperTimeBoundaryCalibratedRPC
Upper time boundary for RPC (calibrated data).
KLMTimeConstants * m_timeConstants
DBObject of time cost on some parts of the detector.
void setupDatabase()
Setup the database.
double m_LowerTimeBoundaryCalibratedScintilltorsBKLM
Lower time boundary for BKLM scintillators (calibrated data).
void setMinimalDigitNumber(int minimalDigitNumber)
Set minimal digit number (total).
double m_UpperTimeBoundaryCalibratedScintilltorsBKLM
Upper time boundary for BKLM scintillators (calibrated data).
TH1F * hc_timeFS_scint[2][8]
BKLM scintillator part.
std::map< KLMChannelNumber, double > m_time_channel
Time distribution central value of each channel.
CalibrationAlgorithm::EResult readCalibrationData()
Read calibration data.
TGraph * gr_timeShift_channel_scint_end
EKLM.
TH1F * hc_timeF_scint[2]
BKLM scintillator part.
TH1F * h_timeFS_scint[2][8]
BKLM scintillator part.
const KLMElementNumbers * m_ElementNumbers
Element numbers.
TH1F * hc_timeF_rpc[2]
BKLM RPC part.
TH2F * h2c_timeFS_end[2][4]
EKLM part.
TH1F * h_timeFSLPC_end[2][4][14][2][75]
EKLM part.
const EKLM::GeometryData * m_EKLMGeometry
EKLM geometry data.
TProfile * m_Profile2BKLMScintillatorPhi
For BKLM scintillator phi plane.
TH1F * hc_time_scint_end
EKLM part.
TGraphErrors * gre_time_channel_scint_end
EKLM.
TH2F * h2_timeFSLP[2][8][15][2]
BKLM part.
TGraph * gr_timeShift_channel_scint
BKLM scintillator.
double m_time_channelAvg_scint_end
Central value of the global time distribution (EKLM scintillator part).
TProfile * m_Profile2EKLMScintillatorPlane1
For EKLM scintillator plane1.
TH1F * hc_timeFS_rpc[2][8]
BKLM RPC part.
void fillTimeDistanceProfiles(TProfile *profileRpcPhi, TProfile *profileRpcZ, TProfile *profileBKLMScintillatorPhi, TProfile *profileBKLMScintillatorZ, TProfile *profileEKLMScintillatorPlane1, TProfile *profileEKLMScintillatorPlane2, bool fill2dHistograms)
Fill profiles of time versus distance.
TFile * m_outFile
Output file.
double esti_timeShift(const KLMChannelIndex &klmChannel)
Estimate value of calibration constant for uncalibrated channels.
std::pair< int, double > tS_upperStrip(const KLMChannelIndex &klmChannel)
Tracing avaiable channels with increasing strip number.
TH1F * hc_timeFSLP[2][8][15][2]
BKLM part.
void saveHist()
Save histograms to file.
const bklm::GeometryPar * m_BKLMGeometry
BKLM geometry data.
TH2F * h2c_timeFSLP[2][8][15][2]
BKLM part.
TF1 * fcn_const
Const function.
TProfile * m_Profile2RpcZ
For BKLM RPC z plane.
TH1F * h_timeFSLPC[2][8][15][2][54]
BKLM part.
void setDebug()
Turn on debug mode (prints histograms and output running log).
TH2F * m_HistTimeLengthBKLM[2][8][15][2][54]
Two-dimensional distributions of time versus propagation length.
TH2F * h2_timeFSLP_end[2][4][14][2]
EKLM part.
void timeDistance2dFit(const std::vector< std::pair< KLMChannelNumber, unsigned int > > &channels, double &delay, double &delayError)
Two-dimensional fit for individual channels.
TH1I * h_calibrated
Calibration statistics for each channel.
TProfile * m_ProfileBKLMScintillatorZ
For BKLM scintillator z plane.
TH1F * h_time_rpc_tc
BKLM RPC part.
TH1F * h_time_scint_end
EKLM part.
TH2F * h2c_timeF_scint[2]
BKLM scintillator part.
TF1 * fcn_pol1
Pol1 function.
double m_etime_channelAvg_scint_end
Central value error of the global time distribution (EKLM scintillator part).
TH1F * hc_time_rpc
BKLM RPC part.
TH2F * h2c_timeFSLP_end[2][4][14][2]
EKLM part.
TH2F * h2_timeF_scint_end[2]
EKLM part.
void useEvtT0()
Use event T0 as the initial time point or not.
double m_UpperTimeBoundaryScintilltorsBKLM
Upper time boundary for BKLM scintillators.
TF1 * fcn_gaus
Gaussian function.
TH1F * h_timeF_rpc[2]
BKLM RPC part.
TProfile * m_ProfileBKLMScintillatorPhi
For BKLM scintillator phi plane.
TH1F * hc_time_scint
BKLM scintillator part.
TH2F * h2_timeFS[2][8]
BKLM part.
double m_etime_channelAvg_scint
Central value error of the global time distribution (BKLM scintillator part).
double m_UpperTimeBoundaryCalibratedScintilltorsEKLM
Upper time boundary for BKLM scintillators (calibrated data).
TH1F * h_timeF_scint_end[2]
EKLM part.
TProfile * m_ProfileRpcPhi
For BKLM RPC phi plane.
TProfile * m_ProfileEKLMScintillatorPlane2
For EKLM scintillator plane2.
TH1F * h_time_rpc
BKLM RPC part.
TH1F * h_timeFSL_end[2][4][14]
EKLM part.
TProfile * m_Profile2RpcPhi
For BKLM RPC phi plane.
TH1F * h_timeF_scint[2]
BKLM scintillator part.
TH1F * hc_timeFSL[2][8][15]
BKLM part.
TProfile * m_Profile2BKLMScintillatorZ
For BKLM scintillator z plane.
TH1F * h_timeFS_rpc[2][8]
BKLM RPC part.
KLMChannelIndex m_klmChannels
KLM ChannelIndex object.
TGraph * gr_timeShift_channel_rpc
BKLM RPC.
TH1F * h_diff
Distance between global and local position.
TH2F * h2_timeF_scint[2]
BKLM scintillator part.
TH1F * h_time_scint_tc
BKLM scintillator part.
double m_LowerTimeBoundaryRPC
Lower time boundary for RPC.
virtual EResult calibrate() override
Run algorithm on data.
double m_LowerTimeBoundaryCalibratedRPC
Lower time boundary for RPC (calibrated data).
bool m_useEventT0
Whether to use event T0 from CDC.
int m_MinimalDigitNumber
Minimal digit number (total).
void setLowerLimit(int counts)
Set the lower number of hits collected on one sigle strip.
ChannelCalibrationStatus
Channel calibration status.
TProfile * m_ProfileEKLMScintillatorPlane1
For EKLM scintillator plane1.
double m_UpperTimeBoundaryRPC
Upper time boundary for RPC.
TH2F * h2c_timeF_rpc[2]
BKLM RPC part.
TF1 * fcn_land
Landau function.
KLMTimeCableDelay * m_timeCableDelay
DBObject of the calibration constant of each channel due to cable decay.
std::pair< int, double > tS_lowerStrip(const KLMChannelIndex &klmChannel)
Tracing avaiable channels with decreasing strip number.
TProfile * m_ProfileRpcZ
For BKLM RPC z plane.
void setMC(bool mc)
Set flag indicating whether the input is MC sample.
double m_LowerTimeBoundaryScintilltorsBKLM
Lower time boundary for BKLM scintillators.
TH1F * hc_timeFSLPC[2][8][15][2][54]
BKLM part.
ROOT::Math::MinimizerOptions m_minimizerOptions
Minimization options.
std::map< KLMChannelNumber, int > m_cFlag
Calibration flag if the channel has enough hits collected and fitted OK.
TGraphErrors * gre_time_channel_rpc
BKLM RPC.
TH2F * h2_timeFS_end[2][4]
EKLM part.
TH2F * h2_timeF_rpc[2]
BKLM RPC part.
std::map< KLMChannelNumber, std::vector< struct Event > > m_evts
Container of hit information.
TH1F * h_timeFS_scint_end[2][4]
EKLM part.
double m_time_channelAvg_rpc
Central value of the global time distribution (BKLM RPC part).
TH2F * h2c_timeFS[2][8]
BKLM part.
double m_etime_channelAvg_rpc
Central value error of the global time distribution (BKLM RPC part).
std::map< KLMChannelNumber, double > m_etime_channel
Time distribution central value Error of each channel.
double m_UpperTimeBoundaryScintilltorsEKLM
Upper time boundary for BKLM scintillators.
int m_lower_limit_counts
Lower limit of hits collected for on single channel.
Class to store BKLM delay time coused by cable in the database.
Class to store KLM constants related to time.
Provides BKLM geometry parameters for simulation, reconstruction etc (from Gearbox or DataBase)
Definition: GeometryPar.h:38
Abstract base class for different kinds of events.
double flyTime
Particle flying time.
double diffDistX
Global position difference between klmHit2d and ExtHit (X).
double t0
EventT0 for the digit.
int channelId
Unique channel id Barral and endcap merged.
double time()
Get propagation time + cableDelay time.
bool inRPC
BKLM RPC flag, used for testing and not necessary.
double eDep
Collect energy eV.
double diffDistY
Global position difference between klmHit2d and ExtHit (Y).
double diffDistZ
Global position difference between klmHit2d and ExtHit (Z).
double dist
Propagation distance from hit to FEE.
double nPE
Number of photon electron.
double recTime
Recosntruction time respected to the trigger time.
bool isFlipped
If phi and z plane flipped, used for testing and not necessary.