FairRoot/PandaRoot
PndSdsTotChargeConversion.cxx
Go to the documentation of this file.
2 #include "TMath.h"
3 
6 fthreshold(0.),
7 Qt(0.),
8 t1e(0.),
9 t2e(0.),
10 ftimestep(0.),
11 fstarttime(0.),
12 fstoptime(0.),
13 ftimeoffset(0.),
14 ftimewalk(0.),
15 fVerboseLevel(0),
16 fRand()
17 {
18  SetParameter("ftr", 100.); //todo take data from Database
19  SetParameter("fa", 60.);
20  SetParameter("fth", 3000.);
21  SetParameter("fclk", 156.);
22  ftimestep = 1. / GetParameter("fclk") * 1000.;
23  fVerboseLevel = VerboseLevel;
24  StartExecute();
25  Warning("constructor","default constructor used");
26  if (fVerboseLevel>0){
27  std::cout<<"Tot parameter "<<std::endl;
28  std::cout<<" charge time: "<<GetParameter("ftr")<<" ns"<<std::endl;
29  std::cout<<" const. current: "<<GetParameter("fa")<<" e/ns"<<std::endl;
30  std::cout<<" threshold: "<<GetParameter("fth")<<" e"<<std::endl;
31  std::cout<<" clock frequency: "<<GetParameter("fclk")<<" MHz"<<std::endl;
32  }
33 };
34 
37 fthreshold(0.),
38 Qt(0.),
39 t1e(0.),
40 t2e(0.),
41 ftimestep(0.),
42 fstarttime(0.),
43 fstoptime(0.),
44 ftimeoffset(0.),
45 ftimewalk(0.),
46 fVerboseLevel(0),
47 fRand()
48 {
49  SetParameter("ftr", tr); //charge time [ns]
50  SetParameter("fa", a); //const. curren [e/ns]
51  SetParameter("fth", threshold);
52  SetParameter("fclk", clockfrequency); //the frequency the readout chip works with
53  ftimestep = 1. / clockfrequency * 1000.;
54  fVerboseLevel = VerboseLevel;
55  if (fVerboseLevel>0){
56  std::cout<<"Tot parameter "<<std::endl;
57  std::cout<<" charge time: "<<GetParameter("ftr")<<" ns"<<std::endl;
58  std::cout<<" const. current: "<<GetParameter("fa")<<" e/ns"<<std::endl;
59  std::cout<<" threshold: "<<GetParameter("fth")<<" e"<<std::endl;
60  std::cout<<" clock frequency: "<<GetParameter("fclk")<<" MHz"<<std::endl;
61  }
62  StartExecute();
63 };
64 
66  if (GetParameter("fa") <= 0){
67  if (fVerboseLevel>0)
68  Error("ConvertChargeToDigiValue(Double_t charge)","const. current is less or equal zero -> now set to 60 e/ns");
69  SetParameter("fa",60.);
70  }
71 
72  Double_t Q = charge;
73  Qt = GetParameter("fth");
74  //Error handling: if there is a parameter leading to a division by zero Q=Qt=1 is set to prevent this
75 
76  if (Qt < 0){
77  if (fVerboseLevel>0)
78  Error("ConvertChargeToDigiValue(Double_t charge)","threshold is less than zero -> now set to 0 eV");
79  Qt = 0.;
80  }
81 
82  if ((Q <= Qt) or (Q <= 0)){
83  if (fVerboseLevel>0)
84  Warning("ConvertChargeToDigiValue(Double_t charge)","charge (%g) is equal or less than threshold (%g) -> zero TOT",Q,Qt);
85  Q = 1.;
86  Qt = 1.;
87  }
88 
89  t1e = (GetParameter("ftr")*Qt/Q+ftimeoffset); //exact time when signal is over threshold
90  t2e = (Q-Qt)/GetParameter("fa")+ftimeoffset+GetParameter("ftr"); //exact time when signal is again below threshold
91 
92  //return (t2e-t1e); //turn off clock
93  return GetTotWC();
94 }
95 
97 {
98  // formula from D.Pohl/FZJ his sources?
99  // dQ_rec a / (Q_t - a*t_c)/2 + (Q - Q_t)(t_c/Q - 1/a)*a/2 \.
100  // ------ = - * dt_max * | 1 + ---------------------------------------------------------------------- |
101  // Q_rec 2 \ sqrt{ [ (Q_t - a*t_c)/2 + (Q - Q_t)(t_c/Q - 1/a)*a/2 ]^2 + a*Q_t*t_c } /
102  //
103  // a 1 / 2Qt - Qt*Qc/Q - Q \.
104  // = - * ----- * | 1 + --------------------------------------- |
105  // 2 f_clk \ sqrt{ [2Qt - Qt*Qc/Q - Q]^2 + 4*Qc*Qt } /
106  //
107 
108  Double_t Q = Charge;
109  Qt = GetParameter("fth"); // threshold
110  Double_t a = GetParameter("fa"); // const current
111  Double_t tc = GetParameter("ftr");// time to load capacitor fully
112  Double_t Qc = a*tc; // storable capacitor charge
113  Double_t temp = 2.*Qt - Qt*Qc/Q - Q;
114  temp = temp/(sqrt(temp*temp + 4*Qc*Qt));
115  temp = 0.5*a*(1+temp)/GetParameter("fclk");
116  return temp;
117 }
118 
119 //Int_t PndSdsTotChargeConversion::GetTimeStamp(Double_t time)
120 //{
121 // Int_t temp = (Int_t)(time / ftimestep); // [clockcycles]
122 // time = temp*ftimestep + ftimestep; //[ns] to the following clock tick
123 // return (Int_t)TMath::Ceil(time); // [ns] with 1 ns number precision, casting cuts trailing digits, like floor()
124 //}
125 
127 {
128  ftimewalk=GetTimeWalk(Charge);
129 
130  Double_t totaltime = ftimewalk;
131  Double_t eventtime = MCEventTime;
132  Double_t flighttime = time;
133 
134  totaltime += flighttime; // [ns]
135  totaltime += eventtime; // [ns]
136 
137  Double_t digitizedtime = DigitizeTime(totaltime);
138 
139  if (fVerboseLevel>2){
140  std::cout<<" +++threshold: "<< Qt <<" "<<std::endl;
141  std::cout<<" charge: "<< Charge <<" "<<std::endl;
142  std::cout<<" time since event: "<< time <<" "<<std::endl;
143  std::cout<<" event time: "<< MCEventTime << std::endl;
144  std::cout<<" timewalk: "<< ftimewalk <<std::endl;
145  std::cout<<" total time: "<< totaltime <<std::endl;
146  std::cout<<" time step: "<< ftimestep<<std::endl;
147  std::cout<<" digitized total time:"<< digitizedtime << "+++"<<std::endl;
148  }
149  return digitizedtime ; //digitalisiert
150  // return totaltime; // nicht digitalisiert
151 }
152 
153 
155 {
156  Int_t temp = (Int_t)((time) / ftimestep);
157  time = temp *ftimestep + ftimestep;
158 
159  if (fVerboseLevel>2) std::cout << "temp " << temp << " time " << time << std::endl;
160 
161  return time;
162 }
163 
165  if (GetParameter("fa") <= 0){
166  if (fVerboseLevel>0)
167  Error("GetTimeWalk(Double_t charge)","const. current is less or equal zero -> now set to 60 e/ns");
168  SetParameter("fa",60.);
169  }
170 
171  Double_t Q = Charge;
172 
173  if (Qt < 0){
174  if (fVerboseLevel>0)
175  Error("GetTimeWalk(Double_t charge)","threshold is less than zero -> now set to 0 eV");
176  Qt = 0.;
177  }
178 
179  if ((Q <= Qt) or (Q <= 0)){
180  if (fVerboseLevel>0)
181  Warning("GetTimeWalk(Double_t charge)","charge is equal or less than threshold -> zero TOT -> infinity TimeWalk");
182  Q = 1.;
183  Qt = 100000.;
184  ftimewalk = GetParameter("ftr");
185  return ftimewalk;
186  }
187 
188 
189  Qt = GetParameter("fth");
190  ftimewalk = (GetParameter("ftr")*Qt/Q);
191 // ftimewalk += ftimestep;
192  return ftimewalk;
193 }
194 
195 Double_t PndSdsTotChargeConversion::GetTotWC(){ //calculates start time, stop time with a clock
196  fstarttime = (Int_t) ( t1e / ftimestep ) * ftimestep + ftimestep; //quantization of the start signal
197  fstoptime = (Int_t) ( t2e / ftimestep ) * ftimestep + ftimestep; //quantization of the stop signal
198  /*
199  std::cout<<" start point exact: "<<t1e<<std::endl;
200  std::cout<<" stop point exact: "<<t2e<<std::endl;
201  std::cout<<" time step is: "<<ftimestep<<" ns"<<std::endl;
202  std::cout<<" fclockfrequency is: "<<GetParameter("fclk")<<" MHz"<<std::endl;
203  std::cout<<" time offset is: "<<ftimeoffset<<" ns"<<std::endl;
204  std::cout<<" start point is: "<<fstarttime<<" ns"<<std::endl;
205  std::cout<<" stop point is: "<<fstoptime<<" ns"<<std::endl;
206  */
207  return (fstoptime-fstarttime);
208 }
209 
210 void PndSdsTotChargeConversion::StartExecute(){ //function called for different events to set different time offsets
211  ftimeoffset = fRand.Uniform(ftimestep);
212 }
213 
214 Double_t PndSdsTotChargeConversion::GetPileUpTime(Double_t fcharge){ //returns the time the detector is not sensitive for other events
215  return (GetParameter("ftr") + fcharge / GetParameter("fa"));
216 }
217 
218 Double_t PndSdsTotChargeConversion::DigiValueToCharge(Double_t digivalue){ //returns the charge for the given tot value
219  if (digivalue<0){
220  if (fVerboseLevel>0)
221  Error("ConvertDigiValueToELoss(Double_t digi)","charge digitization value not calculated properly");
222  return -1;
223  }
224  return (-GetParameter("fa")*GetParameter("ftr")+GetParameter("fth")+digivalue*GetParameter("fa"))/2.+sqrt( pow( (GetParameter("fa")*GetParameter("ftr")-GetParameter("fth")-digivalue*GetParameter("fa")),2) / 4. + GetParameter("fa")* GetParameter("fth") * GetParameter("ftr"));
225 }
226 
228 
virtual Double_t DigiValueToCharge(Double_t digivalue)
Converts a given digitized charge into charge in electrons.
PndSdsTotChargeConversion(Int_t VerboseLevel=0)
Default constructor.
TRandom3 fRand
Definition: full_core_ntp.C:28
friend F32vec4 sqrt(const F32vec4 &a)
Definition: P4_F32vec4.h:29
virtual Double_t GetTimeWalk(Double_t Charge)
Double_t DigitizeTime(Double_t time)
returns the time in [ns] but binned to clock units
virtual Double_t GetTimeStamp(Double_t tof, Double_t charge, Double_t MCEventTime)
absolute time stamp of a hit in ns (clock is taken into account)
Int_t a
Definition: anaLmdDigi.C:126
virtual Double_t ChargeToDigiValue(Double_t charge)
Converts a given charge in electrons into the electronics answer e.g. ToT [ns].
Double_t
Double_t GetParameter(TString param)
virtual Double_t GetRelativeError(Double_t Charge)
double threshold
ClassImp(PndAnaContFact)
virtual Double_t GetPileUpTime(Double_t charge)
returns the time the capacitor is loaded and therefore the time this MVD pixel/strip is blind for oth...
void SetParameter(TString param, Double_t value)