PandaRoot
PndMdtParamDigi.h
Go to the documentation of this file.
1 //==================================================================
2 // description
3 // parameterized digitizaiton model from garfield simulation
4 // author, Jifeng Hu, hu@to.infn.it, Torino University
5 //
6 
7 #ifndef PNDMDTPARAMDIGI_H
8 #define PNDMDTPARAMDIGI_H 1
9 
10 #include "TVector3.h"
11 #include "TGraphErrors.h"
12 #include <vector>
13 #include "TF1.h"
14 #include "TH1F.h"
15 #include "TH2F.h"
16 #include "TRandom.h"
17 #include <math.h>
18 #include <map>
19 
20 // value and its error
21 typedef std::pair<Double_t, Double_t> ValueErrorType;
22 
23 namespace CLHEP {
24 class RandGeneral;
25 }
26 
27 class PndMdtParamDigi : public TNamed {
28 
29  public:
32 
34  ~PndMdtParamDigi();
35  void SetVerbose(Int_t v) { fVerbose = v; }
36  // call Init before invoking the other interfaces.
37  Bool_t Init();
38  // signal on Anode wire
39  //==========================================================================
40  // Int_t particleType: electron, muon, pion, kaon+-, proton, indiced as 0, 1, 2, 3, 4
41  // TVector3 iniP : initial 3-momentum of this charged particle
42  // TVector3 iniPos : initial position when entering into a tube
43  // TVector3 fnlPos : final position when exiting a tube
44  //==========================================================================
45  // by default, strip lenght 100 cm
46  // this inteface should be invoked first when parameters change
47  PndMdtParamDigi &SetParams(Int_t ptlType, TVector3 iniP, TVector3 iniPos, TVector3 finalPos, Double_t stripLen = 100.);
48 
49  void UseNoise(Bool_t swith) { fUseNoise = swith; }
50  void UseDetailedSim(Bool_t swith = kTRUE) { fDetailedSim = swith; }
51  void UsePlot(Bool_t swith = kTRUE) { fUsePlot = swith; }
52  void UseGaussianAmp(Bool_t swith) { fGaussianAmp = swith; }
53  void SetOptimization(Int_t val) { fNumofTruncation = val; }
54  void SetNoiseWidth(Double_t anode, Double_t strip)
55  {
56  fNoiseSigmaAnode = anode;
57  fNoiseSigmaStrip = strip;
58  }
59  //===============================================================
60  // readout interfaces
61  // only fired information is provided
62  // for wire, <-1, fired time>, for strips, <strip number from 0, fired time>
63  std::vector<std::pair<Int_t, Double_t>> GetFiredInfo();
64  // both anode and strip signals
65  void Compute(Bool_t useConvolution = kTRUE);
66  // access data of induced current
67  const std::vector<Double_t> &GetWireSignal() const { return fSignalDataAnode; }
68  const std::map<Int_t, std::vector<Double_t>> &GetStripSignals() const { return fSignalDataStripM; }
69  //===============================================================
70 
71  // plot a charged track and its produced signal
72  void Draw();
73 
74  private:
75  // anode signal only
76  void GetSignal(Bool_t useConvolution = kTRUE);
77  // get threshold-crossing time and amplitude
78  // if tube is fired, return kTRUE;
79  // in case of kTRUE, time and amplitude will be set.
80  Bool_t Digitize(Double_t &time, Double_t &amp); // anode
81  Bool_t Digitize(Int_t stripNo, Double_t &time, Double_t &amp); // strip
82  //
83  void GetRawSignalbySimAvalanche(Double_t fNoiseLevel = 1.);
84  void GetRawSignalbyWeightingAvalanche(Double_t fNoiseLevel = 1.);
85  void AddNoise(Double_t fNoiseLevel = 1., Int_t isAnode = 1);
86  void ApplyTransferFunction(Double_t *fSignalData, Int_t nSize = fSamplingSize);
87 
88  // by default, sampling rate is set to 100 MHz, 200 sampling points
89  static const Int_t fSamplingSize = 20;
90  Int_t fSamplingRate;
91  Int_t fSamplingInterval;
92  std::vector<Double_t> fSignalDataAnode;
93  std::map<Int_t, std::vector<Double_t>> fSignalDataStripM; // strip no, and its corresponding signal
94  TF1 *fTrF; // transfer function
95  Bool_t fUseNoise;
96  Bool_t fGaussianAmp; // amplication model
97  Double_t fNoiseSigmaAnode; // 0.01 mu Ampere
98  Double_t fNoiseSigmaStrip; // 0.01 mu Ampere
99  Int_t fNumofTruncation;
100 
101  private:
102  // drift time of primary ionized electrons to wire surface
103  inline Double_t GetElectronDriftTime(TVector2 iniPos)
104  {
105  const Double_t p0 = 5.35513e+03;
106  const Double_t p1 = 3.92749e+02;
107  const Double_t p2 = -5.41433e+03;
108  const Double_t p3 = -3.31810e+03;
109  Double_t x = iniPos.Mod() - cWIRERADIUS;
110  Double_t x1 = log(1. + x);
111  return (x * (p0 + p1 * pow(x, 0.25)) + x1 * (p2 + p3 * x1));
112  }
113  // drift time of secondary ions from wire surface to a given point
114  inline Double_t GetShiftTime(TVector2 fWireSurfacePos, TVector2 fProductionPos)
115  {
116  const Double_t p0 = 1.81940e-8; // unit: micro sencond
117  const Double_t p1 = 1.80248;
118  const Double_t p2 = 3.68652e+2;
119  const Double_t p3 = 1.67353e+3;
120  // const Double_t mean = 0; //[R.K. 01/2017] unused variable?
121  // const Double_t sigma = 2.73477e-3;//micro second //[R.K. 01/2017] unused variable?
122  Double_t dr = (fProductionPos - fWireSurfacePos).Mod();
123  return (((p3 * dr + p2) * dr + p1) * dr + p0 /*+ gRandom->Gaus(mean, sigma)*/) * 1.e3; // nano sencod
124  }
125 
126  private:
127  Int_t fParticleType; // electron 0, muon 1, pion 2,
128  TVector3 fParticleMomentum; // momentum of the incident charged particle
129  TVector3 fInitPostion;
130  TVector3 fExitPosition;
131  Bool_t fParamsChanged;
132  Double_t fStripLength;
133  Double_t fRestMass[5];
134 
135  void GetMPVofPrimaryIonization(Int_t particleType, const TVector3 &momentum, ValueErrorType &val) const;
136  Int_t GetAmplicationFactor(Int_t particleType, Double_t momentum) const;
137  // sampling position of secondary ion/electron for a given center
138  Bool_t fDetailedSim;
139  void SamplingPosition(TVector2 fDirection, TVector2 &fIonProductionPos);
140  // mean free path function as velocity
141  TGraphErrors *gFreePath[5]; //
142 
143  inline Double_t GetMeanFreePath(Int_t ptlType, Double_t mom) const
144  {
145  Double_t mMass = fRestMass[ptlType];
146  // Double_t mEnergy = sqrt(mom*mom + mMass*mMass);
147  Double_t mBeta = mom / mMass;
148  Double_t mPath = gFreePath[ptlType]->Eval(mBeta);
149  return gRandom->Exp(mPath);
150  }
151 
152  // avalanche size function
153  Bool_t fUseAvaHist;
154  TH1F *hAvaSize;
155  // TH1F* hAnodeI;
156  // TH1F* hCathodeIx;
157  // TH1F* hCathodeIy;
158  //
160  static const Int_t NRAD = 100; // radial bins, not changeable
161  static const Int_t NPHI = 100; // phi bins, not changeable
162  // geometry constant
163  Double_t cWIRERADIUS; // unit: cm
164  Double_t cCELLSIZE; // unit: cm
165  Double_t cSTRIPWIDTH; // unit: cm
166  Double_t cMAXRADIUS; // not changeable
167  Double_t cMAPFACTOR; // not changeable
168  Double_t cUNITLOGDR; //= TMath::Log(1. + cMAPFACTOR*(cMAXRADIUS - cWIRERADIUS))/NRAD;
169  Double_t cUNITPHI; //= TMath::Pi()*2./NPHI;
170  TH1F *hAnodeI1d[NRAD];
171  TH1F *hCathodeI2d[NRAD][NPHI];
172  Int_t fNr[NRAD];
173  Int_t fNrNphi[NRAD * NPHI];
174 
175  // cluster initialization
176  struct ClusInfo {
177  explicit ClusInfo(TVector3 _v = TVector3()) : fPosition(_v) {}
178  TVector3 fPosition;
179  Int_t fNumofPrimaryIonization;
180  Int_t fNumofIonsofThisCluster;
181  Double_t fStartTime;
182  };
183 
184  // histograms
185  Bool_t fUsePlot;
186  TH1F *hIndex;
187  TH2F *h2dIndex;
188  TH2F *hTrack;
189  TH1F *hIonNum;
190  TH2F *hAvaPos;
191  TH1F *hAvaNum;
192  TH1F *hAva1D;
193  TH2F *hAva2D;
194  //
195  TH1F *hExp1;
196  TH1F *hExp2;
197  TH1F *hGen;
198  TH1F *hLan;
199  Int_t fVerbose;
200  //
201  public:
202  struct AvaBinType {
203  AvaBinType(Int_t _i = 0, Double_t _v = 0.) : Index(_i), Probabilty(_v) {}
204  Int_t Index;
205  Double_t Probabilty;
206  }; // index, density
207  private:
208  std::vector<AvaBinType> fProbFunc1D;
209  std::vector<AvaBinType> fProbFunc2D;
210 
211  //
212  Double_t SPEEDOFLIGHT;
213  CLHEP::RandGeneral *fRandAva;
214 
215  ClassDef(PndMdtParamDigi, 1);
216 };
217 
218 #endif
std::pair< Double_t, Double_t > ValueErrorType
void UseGaussianAmp(Bool_t swith)
void SetNoiseWidth(Double_t anode, Double_t strip)
friend F32vec4 log(const F32vec4 &a)
Definition: P4_F32vec4.h:117
__m128 v
Definition: P4_F32vec4.h:3
const std::vector< Double_t > & GetWireSignal() const
void UsePlot(Bool_t swith=kTRUE)
const std::map< Int_t, std::vector< Double_t > > & GetStripSignals() const
AvaBinType(Int_t _i=0, Double_t _v=0.)
void UseDetailedSim(Bool_t swith=kTRUE)
void UseNoise(Bool_t swith)
void SetOptimization(Int_t val)
void SetVerbose(Int_t v)