Belle II Software  release-06-01-15
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 
31 //C++/C standard lib elements.
32 #include <string>
33 //#include <queue>
34 #include <limits>
35 
36 namespace Belle2 {
53  class CDCDigitizerModule : public Module {
54 
55  public:
58 
60  void initialize() override;
61 
66  void event() override;
67 
69  void terminate() override
70  {
72  // if (m_eDepToADCConversionsFromDB) delete m_eDepToADCConversionsFromDB;
73  if (m_runGainFromDB) delete m_runGainFromDB;
74  if (m_gain0FromDB) delete m_gain0FromDB;
76  if (m_xTalkFromDB) delete m_xTalkFromDB;
77  };
78 
79  private:
86  double smearDriftLength(double driftLength, double dDdt);
87 
88 
98  double getdDdt(double driftLength);
99 
100 
112  double getDriftTime(double driftLength, bool addTof, bool addDelay);
113 
114 
127  void makeSignalsAfterShapers(const WireID& wid, double edep, double dx, double costh, unsigned short& adcCount,
128  double& convFactorForThreshold);
129 
131  double getPositiveT0(const WireID&);
132 
134  void setFEElectronics();
135 
140  double Polya(double xmax = 10);
141 
143  void setSemiTotalGain();
144 
146 
151  double getSemiTotalGain(int clayer, int cell) const
152  {
153  return m_semiTotalGain[clayer][cell];
154  }
155 
157 
161  double getSemiTotalGain(const WireID& wireID) const
162  {
163  return m_semiTotalGain[wireID.getICLayer()][wireID.getIWire()];
164  }
165 
167  void addXTalk();
168 
170  // void setEDepToADCConversions();
171 
177  std::string m_inputCDCSimHitsName;
178  std::string m_outputCDCHitsName;
185  //--- Paramters for simple digitization -------------------------------------------------------------------------------------
186  double m_fraction;
187  double m_mean1;
188  double m_resolution1;
189  double m_mean2;
190  double m_resolution2;
195  double m_tMin;
196  double m_tMaxOuter;
197  double m_tMaxInner;
198  // unsigned short m_tdcOffset; /**< Offset of TDC count (in ns)*/
205  unsigned short m_posFlag;
206  unsigned short m_boardID = 0;
207  TVector3 m_posWire;
208  TVector3 m_posTrack;
209  TVector3 m_momentum;
210  double m_driftLength;
211  double m_flightTime;
212  double m_globalTime;
214  double m_tdcBinWidth;
216  double m_tdcResol;
217  double m_driftV;
218  double m_driftVInv;
219  double m_propSpeedInv;
222  double m_analogGain;
223  double m_digitalGain;
224  double m_adcBinWidth;
227  double m_totalFudgeFactor = 1.;
229  bool m_gasGainSmearing = false;
230  double m_effWForGasGainSmearing = 0.0266;
231  double m_thetaOfPolya = 0.5;
232  bool m_extraADCSmearing = false;
233  // double m_sigmaForExtraADCSmearing = 0.3; /**< Gaussian sigma for extra ADC smearing */
234  double m_runGain = 1.;
235  float m_semiTotalGain[MAX_N_SLAYERS][MAX_N_SCELLS] = {{}};
236  double m_overallGainFactor = 1.;
238  //--- Universal digitization parameters -------------------------------------------------------------------------------------
247  bool m_align;
250 // float m_eventTime; /**< It is a timing of event, which includes a time jitter due to the trigger system */
251 
252  bool m_useDB4FEE;
254  float m_lowEdgeOfTimeWindow[nBoards] = {0};
255  float m_uprEdgeOfTimeWindow[nBoards] = {0};
256  float m_tdcThresh [nBoards] = {0};
257  float m_adcThresh [nBoards] = {0};
258  unsigned short m_widthOfTimeWindowInCount [nBoards] = {0};
267  // DBObjPtr<CDCEDepToADCConversions>* m_eDepToADCConversionsFromDB = nullptr; /*!< Pointer to edep-to-ADC conv. params. from DB. */
268  // float m_eDepToADCParams[MAX_N_SLAYERS][4]; /*!< edep-to-ADC conv. params. */
269 
270  bool m_addXTalk;
278  bool m_synchronization = true;
279  bool m_randomization = true;
280  int m_tSimMode = 0;
284  unsigned short m_trgDelayInCount[nBoards] = {0};
287  struct SignalInfo {
289  SignalInfo(int simHitIndex = 0, float driftTime = 0, float charge = 0, float maxDriftL = 0, float minDriftL = 0,
290  int simHitIndex2 = -1,
291  float driftTime2 = std::numeric_limits<float>::max(), int simHitIndex3 = -1, float driftTime3 = std::numeric_limits<float>::max()) :
292  m_simHitIndex(simHitIndex), m_driftTime(driftTime), m_charge(charge), m_maxDriftL(maxDriftL), m_minDriftL(minDriftL),
293  m_simHitIndex2(simHitIndex2), m_driftTime2(driftTime2),
294  m_simHitIndex3(simHitIndex3), m_driftTime3(driftTime3) {}
296  float m_driftTime;
297  float m_charge;
298  float m_maxDriftL;
299  float m_minDriftL;
301  float m_driftTime2;
303  float m_driftTime3;
304  };
305 
307  struct XTalkInfo {
309  XTalkInfo(unsigned short tdc, unsigned short adc, unsigned short tot, unsigned short status) :
310  m_tdc(tdc), m_adc(adc), m_tot(tot), m_status(status) {}
311  unsigned short m_tdc;
312  unsigned short m_adc;
313  unsigned short m_tot;
314  unsigned short m_status;
315  };
316  };
317 
319 } // 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.
bool m_extraADCSmearing
Swtich for extra ADC smearing.
bool m_includeEarlyXTalks
Flag to switch on/off xtalks earlier than the hit.
TVector3 m_momentum
3-momentum of this 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)
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.
TVector3 m_posTrack
track position of this hit
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.
float m_lowEdgeOfTimeWindow[nBoards]
Lower edge of time-window.
double m_digitalGain
digital gain (V/pC)
double m_totalFudgeFactor
total fudge factor for space resol.
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.
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.
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.
float m_uprEdgeOfTimeWindow[nBoards]
Upper edge of time-window.
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
float m_tdcThresh[nBoards]
Threshold for timing-signal.
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_spaceChargeEffect
Space charge effect.
double m_driftVInv
m_driftV^-1 (in ns/cm)
StoreArray< CDCSimHit > m_simHits
CDCSimHit array.
unsigned short m_widthOfTimeWindowInCount[nBoards]
Width of time window.
StoreArray< CDCHit > m_cdcHits4Trg
CDCHit4trg array.
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.
unsigned short m_trgDelayInCount[nBoards]
Trigger delay in frontend electronics in count.
TVector3 m_posWire
wire position of this hit
double m_mean1
Mean value of the first Gassian used to smear drift length.
bool m_synchronization
Flag to switch on/off timing synchronization.
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.
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.
float m_adcThresh[nBoards]
Threshold for FADC.
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)
float m_semiTotalGain[MAX_N_SLAYERS][MAX_N_SCELLS]
total gain per wire
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
Example Detector.
Definition: CDCSimHit.h:22
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:95
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.