Belle II Software  release-08-01-10
CDCDigitizerModule.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 //basf2 framework headers
12 #include <framework/core/Module.h>
13 #include <framework/datastore/StoreArray.h>
14 
15 #include <simulation/dataobjects/SimClockState.h>
16 
17 //cdc package headers
18 #include <mdst/dataobjects/MCParticle.h>
19 #include <cdc/dataobjects/CDCSimHit.h>
20 #include <cdc/dataobjects/CDCHit.h>
21 #include <cdc/dataobjects/WireID.h>
22 #include <cdc/geometry/CDCGeometryPar.h>
23 #include <cdc/geometry/CDCGeoControlPar.h>
24 #include <cdc/dbobjects/CDCFEElectronics.h>
25 #include <reconstruction/dbobjects/CDCDedxRunGain.h>
26 #include <reconstruction/dbobjects/CDCDedxScaleFactor.h>
27 #include <reconstruction/dbobjects/CDCDedxWireGain.h>
28 //#include <cdc/dbobjects/CDCEDepToADCConversions.h>
29 #include <cdc/dbobjects/CDCCrossTalkLibrary.h>
30 #include <cdc/dbobjects/CDCCorrToThresholds.h>
31 
32 //C++/C standard lib elements.
33 #include <string>
34 //#include <queue>
35 #include <limits>
36 
37 namespace Belle2 {
54  class CDCDigitizerModule : public Module {
55 
56  public:
59 
61  void initialize() override;
62 
67  void event() override;
68 
70  void terminate() override
71  {
73  // if (m_eDepToADCConversionsFromDB) delete m_eDepToADCConversionsFromDB;
74  if (m_runGainFromDB) delete m_runGainFromDB;
75  if (m_gain0FromDB) delete m_gain0FromDB;
77  if (m_xTalkFromDB) delete m_xTalkFromDB;
79  };
80 
81  private:
88  double smearDriftLength(double driftLength, double dDdt);
89 
90 
100  double getdDdt(double driftLength);
101 
102 
114  double getDriftTime(double driftLength, bool addTof, bool addDelay);
115 
116 
129  void makeSignalsAfterShapers(const WireID& wid, double edep, double dx, double costh, unsigned short& adcCount,
130  double& convFactorForThreshold);
131 
133  double getPositiveT0(const WireID&);
134 
136  void setFEElectronics();
137 
142  double Polya(double xmax = 10);
143 
145  void setSemiTotalGain();
146 
148 
153  double getSemiTotalGain(int clayer, int cell) const
154  {
155  return m_semiTotalGain[clayer][cell];
156  }
157 
159 
163  double getSemiTotalGain(const WireID& wireID) const
164  {
165  return m_semiTotalGain[wireID.getICLayer()][wireID.getIWire()];
166  }
167 
169  void addXTalk();
170 
172  // void setEDepToADCConversions();
173 
179  std::string m_inputCDCSimHitsName;
180  std::string m_outputCDCHitsName;
190  //--- Paramters for simple digitization -------------------------------------------------------------------------------------
191  double m_fraction;
192  double m_mean1;
193  double m_resolution1;
194  double m_mean2;
195  double m_resolution2;
200  double m_tMin;
201  double m_tMaxOuter;
202  double m_tMaxInner;
203  // unsigned short m_tdcOffset; /**< Offset of TDC count (in ns)*/
210  unsigned short m_posFlag;
211  unsigned short m_boardID = 0;
215  double m_driftLength;
216  double m_flightTime;
217  double m_globalTime;
219  double m_tdcBinWidth;
221  double m_tdcResol;
222  double m_driftV;
223  double m_driftVInv;
224  double m_propSpeedInv;
227  double m_analogGain;
228  double m_digitalGain;
229  double m_adcBinWidth;
232  double m_totalFudgeFactor = 1.;
234  bool m_gasGainSmearing = true;
235  double m_effWForGasGainSmearing = 0.0266;
236  double m_thetaOfPolya = 0.5;
237  bool m_extraADCSmearing = false;
238  // double m_sigmaForExtraADCSmearing = 0.3; /**< Gaussian sigma for extra ADC smearing */
239  double m_runGain = 1.;
240  float m_semiTotalGain[c_maxNSenseLayers][c_maxNDriftCells] = {{}};
241  double m_overallGainFactor = 1.;
243  //--- Universal digitization parameters -------------------------------------------------------------------------------------
252  bool m_align;
257 // float m_eventTime; /**< It is a timing of event, which includes a time jitter due to the trigger system */
258 
259  bool m_useDB4FEE;
261  float m_lowEdgeOfTimeWindow[c_nBoards] = {0};
262  float m_uprEdgeOfTimeWindow[c_nBoards] = {0};
263  float m_tdcThresh [c_nBoards] = {0};
264  float m_adcThresh [c_nBoards] = {0};
265  unsigned short m_widthOfTimeWindowInCount [c_nBoards] = {0};
274  // DBObjPtr<CDCEDepToADCConversions>* m_eDepToADCConversionsFromDB = nullptr; /*!< Pointer to edep-to-ADC conv. params. from DB. */
275  // float m_eDepToADCParams[c_maxNSenseLayers][4]; /*!< edep-to-ADC conv. params. */
276 
277  bool m_addXTalk;
286  bool m_synchronization = true;
287  bool m_randomization = true;
288  int m_tSimMode = 0;
292  unsigned short m_trgDelayInCount[c_nBoards] = {0};
295  struct SignalInfo {
297  SignalInfo(int simHitIndex = 0, float driftTime = 0, float charge = 0, float maxDriftL = 0, float minDriftL = 0,
298  int simHitIndex2 = -1,
299  float driftTime2 = std::numeric_limits<float>::max(), int simHitIndex3 = -1, float driftTime3 = std::numeric_limits<float>::max()) :
300  m_simHitIndex(simHitIndex), m_driftTime(driftTime), m_charge(charge), m_maxDriftL(maxDriftL), m_minDriftL(minDriftL),
301  m_simHitIndex2(simHitIndex2), m_driftTime2(driftTime2),
302  m_simHitIndex3(simHitIndex3), m_driftTime3(driftTime3) {}
304  float m_driftTime;
305  float m_charge;
306  float m_maxDriftL;
307  float m_minDriftL;
309  float m_driftTime2;
311  float m_driftTime3;
312  };
313 
315  struct XTalkInfo {
317  XTalkInfo(unsigned short tdc, unsigned short adc, unsigned short tot, unsigned short status) :
318  m_tdc(tdc), m_adc(adc), m_tot(tot), m_status(status) {}
319  unsigned short m_tdc;
320  unsigned short m_adc;
321  unsigned short m_tot;
322  unsigned short m_status;
323  };
324  };
325 
327 } // end of Belle2 namespace
The Class for Detailed Digitization of CDC.
double m_tdcThreshold4Inner
TDC threshold for inner layers in unit of eV.
double m_driftV
Nominal drift velocity (in cm/ns)
double Polya(double xmax=10)
Generate randum number according to Polya distribution.
unsigned short m_boardID
FEE board ID.
int m_eDepInGasMode
Mode for extracting dE(gas) from dE(gas+wire)
double m_tMaxInner
Upper edge of time window in ns for the inner layers.
double getdDdt(double driftLength)
The method to get dD/dt.
bool m_outputNegativeDriftTime
A switch to output negative drift time to CDCHit.
unsigned short m_widthOfTimeWindowInCount[c_nBoards]
Width of time window.
bool m_extraADCSmearing
Swtich for extra ADC smearing.
bool m_includeEarlyXTalks
Flag to switch on/off xtalks earlier than the hit.
void makeSignalsAfterShapers(const WireID &wid, double edep, double dx, double costh, unsigned short &adcCount, double &convFactorForThreshold)
Function to make signals after shapers.
int m_trgTimingOffsetInCount
Trigger timing offset in unit of count.
bool m_addInWirePropagationDelay4Bg
A switch used to control adding propagation delay into the total drift time or not for beam bg.
double getSemiTotalGain(int clayer, int cell) const
Return semi-total gain of the specified wire.
bool m_useDB4RunGain
Fetch run gain from DB.
DBObjPtr< CDCCrossTalkLibrary > * m_xTalkFromDB
Pointer to cross-talk from DB.
double m_analogGain
analog gain (V/pC)
double m_tdcBinWidthInv
m_tdcBinWidth^-1 (in ns^-1)
float m_uprEdgeOfTimeWindow[c_nBoards]
Upper edge of time-window.
double m_tMin
Lower edge of time window in ns.
bool m_output2ndHit
A switch to output 2nd hit.
int m_adcThreshold
Threshold for ADC in unit of count.
double m_resolution2
Resolution of the second Gassian used to smear drift length.
bool m_addTimeOfFlight
A switch used to control adding time of flight into the total drift time or not.
double m_trigTimeJitter
Magnitude of trigger timing jitter (ns).
void initialize() override
Initialize variables, print info, and start CPU clock.
double smearDriftLength(double driftLength, double dDdt)
Method used to smear the drift length.
std::string m_MCParticlesToSimHitsName
Relation for origin of incoming SimHits.
double m_digitalGain
digital gain (V/pC)
double m_totalFudgeFactor
total fudge factor for space resol.
std::string m_OptionalAllMCParticlesToHitsName
Relation name for optional matching of all MCParticles.
bool m_addInWirePropagationDelay
A switch used to control adding propagation delay into the total drift time or not.
bool m_align
A switch to control alignment.
void event() override
Actual digitization of all hits in the CDC.
unsigned short m_trgDelayInCount[c_nBoards]
Trigger delay in frontend electronics in count.
double m_globalTime
global time of this hit
bool m_doSmearing
A switch to control drift length smearing.
std::string m_inputCDCSimHitsName
Input array name.
DBObjPtr< CDCDedxWireGain > * m_wireGainFromDB
Pointer to wire gain from DB.
B2Vector3D m_posWire
wire position of this hit
bool m_addTimeOfFlight4Bg
A switch used to control adding time of flight into the total drift time or not for beam bg.
bool m_addXTalk
Flag to switch on/off crosstalk.
bool m_addTimeWalk
A switch used to control adding time-walk delay into the total drift time or not.
bool m_treatNegT0WiresAsGood
A switch for negative-t0 wires.
void terminate() override
Terminate func.
double m_addFudgeFactorForSigma
additional fudge factor for space resol.
bool m_matchAllMCParticles
A switch to match all particles to a hit, regardless wether they produced a hit or not.
bool m_useDB4EDepToADC
Fetch edep-to-ADC conversion params.
std::string m_SimHitsTOCDCHitsName
Relation for outgoing CDCHits.
int m_offsetForTriggerBin
Input to getCDCTriggerBin(offset)
void setSemiTotalGain()
Set semi-total gain (from DB)
double m_driftLength
drift length of this hit
double m_tdcResol
TDC resolution (in ns)
int m_tSimMode
Timing simulation mode.
bool m_useDB4FEE
Fetch FEE params from DB.
double m_adcBinWidth
ADC bin width (mV)
double m_thetaOfPolya
theta of Polya function for gas gain smearing
bool m_matchFirstMCParticles
A switch to match first three MCParticles, not just the one with smallest drift time.
bool m_spaceChargeEffect
Space charge effect.
double m_driftVInv
m_driftV^-1 (in ns/cm)
StoreArray< CDCSimHit > m_simHits
CDCSimHit array.
DBObjPtr< CDCCorrToThresholds > * m_corrToThresholdFromDB
Pointer to threshold correction from DB.
std::string m_OptionalFirstMCParticlesToHitsName
Relation name for optional matching of up to first three MCParticles.
StoreArray< CDCHit > m_cdcHits4Trg
CDCHit4trg array.
float m_semiTotalGain[c_maxNSenseLayers][c_maxNDriftCells]
total gain per wire
DBObjPtr< CDCDedxRunGain > * m_runGainFromDB
Pointer to run gain from DB.
double m_degOfSPEOnThreshold
Degree of space charge effect on timing threshold.
bool m_randomization
Flag to switch on/off timing randmization.
CDCSimHit * m_aCDCSimHit
Pointer to CDCSimHit.
WireID m_wireID
WireID of this hit.
double getSemiTotalGain(const WireID &wireID) const
Return semi-total gain of the specified wire.
DBObjPtr< CDCDedxScaleFactor > * m_gain0FromDB
Pointer to overall gain factor from DB.
double m_effWForGasGainSmearing
Effective energy (keV) for one electron prod.
bool m_issue2ndHitWarning
Flag to switch on/off a warning on the 2nd TDC hit.
double getPositiveT0(const WireID &)
Modify t0 for negative-t0 case.
double m_tdcThreshold4Outer
TDC threshold for outer layers in unit of eV.
double m_tdcThresholdOffset
Offset for TDC(digital) threshold (mV)
double m_fraction
Fraction of the first Gaussian used to smear drift length.
int m_debugLevel4XTalk
Debug level for crosstalk.
int m_shiftOfTimeWindowIn32Count
Shift of time window for synchronization in 32count.
unsigned short m_posFlag
left or right flag of this hit
std::string m_outputCDCHitsName4Trg
Output array name for trigger.
StoreArray< CDCHit > m_cdcHits
CDCHit array.
double m_mean1
Mean value of the first Gassian used to smear drift length.
bool m_synchronization
Flag to switch on/off timing synchronization.
float m_lowEdgeOfTimeWindow[c_nBoards]
Lower edge of time-window.
double getDriftTime(double driftLength, bool addTof, bool addDelay)
The method to get drift time based on drift length.
std::string m_outputCDCHitsName
Output array name.
float m_tdcThresh[c_nBoards]
Threshold for timing-signal.
B2Vector3D m_momentum
3-momentum of this hit
StoreArray< MCParticle > m_mcParticles
Set edep-to-ADC conversion params.
bool m_gasGainSmearing
Swtich for gas gain smearing.
double m_tMaxOuter
Upper edge of time window in ns for the outer layers.
DBArray< CDCFEElectronics > * m_fEElectronicsFromDB
Pointer to FE electronics params.
double m_resolution1
Resolution of the first Gassian used to smear drift length.
B2Vector3D m_posTrack
track position of this hit
bool m_useSimpleDigitization
Use float Gaussian Smearing instead of proper digitization.
CDC::CDCGeometryPar * m_cdcgp
Cached Pointer to CDCGeometryPar.
double m_overallGainFactor
Overall gain factor.
void setFEElectronics()
Set FEE parameters (from DB)
double m_mean2
Mean value of the second Gassian used to smear drift length.
double m_tdcBinWidth
Width of a TDC bin (in ns)
CDC::CDCGeoControlPar * m_gcp
Cached pointer to CDCGeoControlPar.
bool m_correctForWireSag
A switch to control wire sag.
StoreObjPtr< SimClockState > m_simClockState
generated hardware clock state
double m_flightTime
flight time of this hit
float m_adcThresh[c_nBoards]
Threshold for FADC.
Example Detector.
Definition: CDCSimHit.h:21
The Class for CDC Geometry Control Parameters.
The Class for CDC Geometry Parameters.
Class for accessing arrays of objects in the database.
Definition: DBArray.h:26
Class for accessing objects in the database.
Definition: DBObjPtr.h:21
Base class for Modules.
Definition: Module.h:72
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
Class to identify a wire inside the CDC.
Definition: WireID.h:34
unsigned short getICLayer() const
Getter for continuous layer numbering.
Definition: WireID.cc:24
unsigned short getIWire() const
Getter for wire within the layer.
Definition: WireID.h:145
Abstract base class for different kinds of events.
Structure for saving the signal information.
float m_driftTime2
2nd-shortest drift time in the cell.
int m_simHitIndex2
SimHit index for 2nd drift time.
int m_simHitIndex3
SimHit index for 3rd drift time.
float m_charge
Sum of charge for all SimHits in the cell.
float m_driftTime
Shortest drift time of any SimHit in the cell.
float m_driftTime3
3rd-shortest drift time in the cell.
SignalInfo(int simHitIndex=0, float driftTime=0, float charge=0, float maxDriftL=0, float minDriftL=0, int simHitIndex2=-1, float driftTime2=std::numeric_limits< float >::max(), int simHitIndex3=-1, float driftTime3=std::numeric_limits< float >::max())
Constructor that initializes all members.
Structure for saving the x-talk information.
XTalkInfo(unsigned short tdc, unsigned short adc, unsigned short tot, unsigned short status)
Constructor that initializes all members.