FairRoot/PandaRoot
PndSdsFE.cxx
Go to the documentation of this file.
1 /*
2  * SdsFE.cpp
3  *
4  * Created on: Apr 4, 2011
5  * Author: esch
6  */
7 
8 #include "PndSdsFE.h"
9 #include <vector>
10 #include "Math/Interpolator.h"
11 #include "TGraph.h"
12 #include "TCanvas.h"
13 #include "TLegend.h"
14 #include "TFile.h"
15 
17  delete fFrontEndModel;
18  delete fFunction;
19 }
20 
21 
22 void PndSdsFE::SetParameter(TString parName, double parValue){
23  fFunction->SetParameter(parName.Data(), parValue);
24 }
25 
27 
28  fFunction->SetParameter("charge",Charge);
29  fMaximumAmplitude = fFunction->GetMaximumX();
30 
31  if (fFunction->GetParameter("constantcurrent") <= 0){
32  Error("PndSdsFE::GetTotFromCharge","const. current is less or equal zero -> now set to 60 e/ns");
33  fFunction->SetParameter("constantcurrent",60);
34  }
35 
36  if (fFunction->GetParameter("chargetime")<= 0){
37  Error("PndSdsFE::GetTotFromCharge","charge time is less than zero -> now set to 100 ns");
38  fFunction->SetParameter("chargetime",100);
39  }
40 
41  if (fThreshold < 0){
42  Error("PndSdsFE::GetTotFromCharge","Threshold is less than zero -> now set to 0 e");
43  fThreshold = 0;
44  }
45 
46  if (fFunction->GetParameter("charge")<= fThreshold){
47  Warning("PndSdsFE::GetTotFromCharge","charge is equal or less than threshold -> zero TOT");
48  return 0;
49  }
50 
51  double start_exakt=fFunction->GetX(fThreshold,0,fMaximumAmplitude );
52  double stop_exakt=fFunction->GetX(fThreshold,fMaximumAmplitude,fFunction->GetXmax());
53 
54  double start=DigitizeTime(start_exakt+fTimeOffSet);
55  double stop=DigitizeTime(stop_exakt+fTimeOffSet);
56 // printf("start exakt:%f \n",start_exakt);
57 // printf("start :%f \n",start);
58 // printf("stop exakt:%f \n",stop_exakt);
59 // printf("stop :%f \n",stop);
60 
61  return stop-start; // with digitization
62  //return stop_exakt - start_exakt; // without digitization
63 }
64 
65 double PndSdsFE::GetChargeFromTot(double tot){
66  return inter->Eval(tot);
67 }
68 
69 double PndSdsFE::GetTimeWalkFromTot(double tot){
70  fFunction->SetParameter("charge",GetChargeFromTot(tot));
71  fMaximumAmplitude = fFunction->GetMaximumX();
72  return fFunction->GetX(fThreshold,0,fMaximumAmplitude); //(xmin<x<xmax)
73 
74 }
75 
76 
77 double PndSdsFE::GetTimeWalkFromCharge(double Charge){
78  fFunction->SetParameter("charge",Charge);
79  fMaximumAmplitude = fFunction->GetMaximumX();
80  double result = fFunction->GetX(fThreshold,0,fMaximumAmplitude); //(xmin<x<xmax)
81  return result;
82 }
83 
84 double PndSdsFE::GetTimeBackToBaseline(double Charge){
85  fFunction->SetParameter("charge",Charge);
86  fMaximumAmplitude = fFunction->GetMaximumX();
87  return fFunction->GetX(fBaselineEpsilon,fMaximumAmplitude,fFunction->GetXmax());
88 }
89 
90 double PndSdsFE::DigitizeTime(double time){
91 
92  return TMath::Floor(( time / fTimeStep )) * fTimeStep + fTimeStep;
93 }
94 
95 double PndSdsFE::GetTimeStamp(double eventtime, double tof, double charge){
96  //GetChargeToTimeWalk(charge);
97  return DigitizeTime(GetTimeWalkFromCharge(charge)+eventtime+tof);
98 
99 }
101  fTimeOffSet = fRand.Uniform(fTimeStep);
102 }
103 
105 
106  fNumberOfSupportPoints = 2000;
107  fNumberOfMaxElectons = 630000;
109 
110  //printf("stepsize %f \n",stepsize);
111 
112  for( i=0; i < fNumberOfSupportPoints; i++){
113  if(i*stepsize<fThreshold){
114  continue;
115  }
116  else{
117 
118  fTot_list.push_back(i*stepsize);
119  fCharge_list.push_back(GetTotFromCharge(i*stepsize));
120 
121  //printf("x-value %f ,y-value %f \n",fCharge_list.back(),fTot_list.back());
122  //printf("x-value %f ,y-value %f \n",fCharge_list[],fTot_list.back());
123 
124  if(fTot_list.back()< fTot_list.back()-1) {
125  printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%d \n",i );
126  printf("x-value[i-3] %f ,x-value[i-2] %f \n",fTot_list.back()-3,fTot_list.back()-2);
127 
128  printf("x-value[i] %f ,x-value[i-1] %f \n",fTot_list.back(),fTot_list.back());
129  }
130  }
131  }
132 
134 }
135 
136 void PndSdsFE::SaveInterpolatorList(std::vector<double> charge, std::vector<double> tot){
137 
138  // To save an object to a root file it needs to inherit from TObject.
139  // std::vector does not inherit from TObject, but TVectorD does.
140  // so i convert the std::vector to a TVectorD and save them to a root file.
141 
142  int size_x = charge.size();
143  int size_y = tot.size();
144 
145  TVectorD charge_root(size_x);
146  TVectorD tot_root(size_y);
147 
148  for(int bx=0; bx < size_x;bx++)
149  {
150  charge_root[bx] = charge.at(bx);
151  }
152 
153  for(int by=0; by < size_x;by++)
154  {
155  tot_root[by] = tot.at(by);
156  }
157 
158  // in den namen der interpolatorliste sollte die threshold und das model hinein. sind diese beiden angaben identisch
159  // ist die interpolatorliste eindeutig.
160 
161  char s[20];
162 
163  sprintf(s,"interpolatorlist-modelnumber_%i-thr_%g.root",fFrontEndModel->GetModelNumber(),fThreshold);
164 
165  TFile f1(s,"RECREATE");
166 
167  TGraph* graph = new TGraph(charge.size(), &charge.at(0),&tot.at(0));
168  graph->Draw("AP");
169  graph->Write();
170 
171  charge_root.Write("charge");
172  tot_root.Write("tot");
173 }
174 
176  // is list available?
177 
178  char s[20];
179  sprintf(s,"interpolatorlist-modelnumber_%i-thr_%g.root",fFrontEndModel->GetModelNumber(),fThreshold);
180 
181  TFile *fInFile = new TFile(s,"read");
182 
183  if(fInFile->IsZombie()) {
184  std::cout << "No interpolator list to load, create one... " << std::endl;
187  return;
188  }
189  else
190  {
191  std::cout << "Loading Interpolator List " << std::endl;
193  return;
194  }
195 
196 }
197 
199 
200  char dd[20];
201  sprintf(dd,"interpolatorlist-modelnumber_%i-thr_%g.root",fFrontEndModel->GetModelNumber(),fThreshold);
202 
203  TFile *fInFile = new TFile(dd);
204 
205  if(fInFile->IsZombie()) {
206  std::cout << "PndSdsFE::LoadInterpolatorList(): error loading root file " << std::endl;
207 
208  return;
209  }
210  else
211  {
212  std::cout << "PndSdsFE::LoadInterpolatorList(): Loading list done " << std::endl;
213 
214  }
215 
216  TVectorD *charge = (TVectorD*)fInFile->Get("charge");
217  TVectorD *tot = (TVectorD*)fInFile->Get("tot");
218 
219  int size_charge = charge->GetNoElements();
220  int size_tot = tot->GetNoElements();
221 
222  fCharge_list.clear();
223  fCharge_list.clear();
224 
225  for(int bxx=0; bxx < size_charge;bxx++)
226  {
227  //fCharge_list.push_back(charge[bxx]);
228  fCharge_list.push_back((*charge)[bxx]);
229 
230  }
231 
232  for(int byy=0; byy < size_tot;byy++)
233  {
234  // fTot_list.push_back(tot);
235  fTot_list.push_back((*tot)[byy]);
236  }
237 
238  inter = new ROOT::Math::Interpolator(fCharge_list,fTot_list, ROOT::Math::Interpolation::kCSPLINE);
239 }
240 
242 
243 
void CreateInterpolatorList()
Definition: PndSdsFE.cxx:104
printf("RealTime=%f seconds, CpuTime=%f seconds\n", rtime, ctime)
virtual double GetTimeStamp(double eventtime, double tof, double charge)
Definition: PndSdsFE.cxx:95
double fBaselineEpsilon
Definition: PndSdsFE.h:107
virtual double GetChargeFromTot(double tot)
Definition: PndSdsFE.cxx:65
virtual double GetTotFromCharge(Double_t charge)
Definition: PndSdsFE.cxx:26
TF1 * f1
Definition: reco_analys2.C:50
virtual ~PndSdsFE()
Definition: PndSdsFE.cxx:16
TLorentzVector s
Definition: Pnd2DStar.C:50
virtual double GetTimeWalkFromCharge(double charge)
Definition: PndSdsFE.cxx:77
std::vector< double > fCharge_list
Definition: PndSdsFE.h:117
int i
Definition: PndSdsFE.h:114
virtual void SetParameter(TString parName, double parValue)
Definition: PndSdsFE.cxx:22
ROOT::Math::Interpolator * inter
Definition: PndSdsFE.h:119
virtual double GetTimeBackToBaseline(double charge)
Definition: PndSdsFE.cxx:84
void CalcTimeOffSet()
Definition: PndSdsFE.cxx:100
TF1 * fFunction
Definition: PndSdsFE.h:104
Double_t
void LoadInterpolatorList()
Definition: PndSdsFE.cxx:198
double fMaximumAmplitude
Definition: PndSdsFE.h:105
std::vector< double > fTot_list
Definition: PndSdsFE.h:118
void GetInterpolatorList()
Definition: PndSdsFE.cxx:175
void SaveInterpolatorList(std::vector< double > charge, std::vector< double > tot)
Definition: PndSdsFE.cxx:136
double fTimeStep
Definition: PndSdsFE.h:111
virtual double GetTimeWalkFromTot(double tot)
Definition: PndSdsFE.cxx:69
double DigitizeTime(double time)
Definition: PndSdsFE.cxx:90
int fNumberOfMaxElectons
Definition: PndSdsFE.h:102
double fTimeOffSet
Definition: PndSdsFE.h:110
TRandom2 fRand
Definition: PndSdsFE.h:113
PndSdsFEAmpModelSimple * fFrontEndModel
Definition: PndSdsFE.h:99
ClassImp(PndAnaContFact)
int fNumberOfSupportPoints
Definition: PndSdsFE.h:101
double fThreshold
Definition: PndSdsFE.h:106
double stepsize
Definition: PndSdsFE.h:115