]> git.uio.no Git - u/mrichter/AliRoot.git/blob - T0/AliT0Parameters.cxx
hardcoded LookUp table removed
[u/mrichter/AliRoot.git] / T0 / AliT0Parameters.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id:  */
17
18 //____________________________________________________________________
19 //                                                                          
20 // T0 - T0. 
21 //
22 // This class is a singleton that handles various parameters of
23 // the T0 detectors.  
24 // Eventually, this class will use the Conditions DB to get the
25 // various parameters, which code can then request from here.
26 //                                                       
27 #include "AliLog.h"               
28 #include "AliT0Parameters.h"      
29 #include "AliT0CalibData.h"   
30 #include "AliT0LookUpValue.h"
31 #include <AliCDBManager.h>        
32 #include <AliCDBEntry.h>          
33 #include <AliCDBStorage.h>  
34 #include <TMath.h>
35 #include <TSystem.h>
36 #include <Riostream.h>
37 #include <TGeoManager.h>
38 #include <TGeoPhysicalNode.h>
39
40 AliT0CalibData* AliT0Parameters::fgCalibData = 0;
41 AliT0CalibData* AliT0Parameters::fgLookUp = 0;
42 AliT0CalibData* AliT0Parameters::fgSlewCorr =0;
43 //====================================================================
44 ClassImp(AliT0Parameters)
45 #if 0
46   ; // This is here to keep Emacs for indenting the next line
47 #endif
48
49 //____________________________________________________________________
50 AliT0Parameters* AliT0Parameters::fgInstance = 0;
51 //____________________________________________________________________
52 AliT0Parameters* AliT0Parameters::Instance() 
53 {
54   // Get static instance 
55   if (!fgInstance) {
56     fgInstance = new AliT0Parameters;
57     //   fgInstance->Init();
58   }
59   return fgInstance;
60 }
61
62 //____________________________________________________________________
63 AliT0Parameters::AliT0Parameters()
64   :fIsInit(kFALSE),
65    fPh2Mip(0),fmV2Mip(0),
66    fChannelWidth(0),fmV2Channel(0),
67    fQTmin(0),fQTmax(0),
68    fSlewingLED(),fSlewingRec(),
69    fPMTeff(),
70    fTimeDelayDA(0),fTimeDelayCFD(0),fTimeDelayTVD(0),fMeanT0(499),
71    fCalibentry(), fLookUpentry(),fSlewCorr(),
72    fLookUp(0), fNumberOfTRMs(0)
73
74 {
75   // Default constructor 
76
77   for (Int_t ipmt=0; ipmt<24; ipmt++)
78     {
79       SetSlewingLED(ipmt);
80       SetSlewingRec(ipmt);
81       SetWalk(ipmt);
82       SetPh2Mip();      
83       SetmV2Mip();      
84       SetChannelWidth();
85       SetmV2channel();
86       SetQTmin();
87       SetQTmax();
88       SetPMTeff(ipmt);
89
90    }
91   SetTimeDelayTVD();
92   SetZposition();
93   SetNumberOfTRMs(2);
94   
95 }
96
97 //__________________________________________________________________
98 void
99 AliT0Parameters::Init()
100 {
101   // Initialize the parameters manager.  We need to get stuff from the
102   // CDB here. 
103  
104    if (fIsInit) return;
105
106   AliCDBManager *stor =AliCDBManager::Instance();
107   //time equalizing
108   AliCDBEntry* fCalibentry  = stor->Get("T0/Calib/TimeDelay");
109   if (fCalibentry)
110    fgCalibData  = (AliT0CalibData*)fCalibentry->GetObject();
111   else {
112     AliError(" ALARM !!!! No time delays in CDB "); 
113     fIsInit = kFALSE;
114     return;
115   }
116  //slewing correction
117   AliCDBEntry* fSlewCorr  = stor->Get("T0/Calib/Slewing_Walk");
118   if (fSlewCorr){
119     fgSlewCorr  = (AliT0CalibData*)fSlewCorr->GetObject();
120   }
121   else {
122     AliError(" ALARM !!!! No slewing correction in CDB "); 
123     fIsInit = kFALSE;
124     return;
125   }
126
127   fLookUpentry  = stor->Get("T0/Calib/LookUp_Table");
128   if (fLookUpentry){
129     fgLookUp  = (AliT0CalibData*)fLookUpentry->GetObject();
130   }
131   else {
132     AliError(" ALARM !!!! No Lookup table  in CDB "); 
133     fIsInit = kFALSE;
134     return;
135   }
136
137   /*
138   else {
139   const char * filename = gSystem->ExpandPathName("$ALICE_ROOT/T0/lookUpTable.txt");
140   ifstream inFile(filename);
141   fgLookUp->ReadAsciiLookup(filename);
142   }
143   */
144   fIsInit = kTRUE;
145 }
146
147
148 //__________________________________________________________________
149 Float_t
150 AliT0Parameters::GetTimeDelayDA(Int_t ipmt) 
151 {
152   // return time delay for LED channel
153   // 
154   if (!fCalibentry) {
155     fTimeDelayDA = 500;
156     return  fTimeDelayDA;
157   } 
158   return fgCalibData ->GetTimeDelayDA(ipmt);
159 }
160 //__________________________________________________________________
161 Float_t
162 AliT0Parameters::GetTimeDelayCFD(Int_t ipmt) 
163 {
164   // return time delay for CFD channel
165    // 
166   if (!fCalibentry) 
167     {
168       fTimeDelayCFD = 1000+ipmt*100;
169       return fTimeDelayCFD;
170     }
171    
172   return fgCalibData->GetTimeDelayCFD(ipmt);
173 }
174
175 //__________________________________________________________________
176 Int_t
177 AliT0Parameters::GetMeanT0() 
178 {
179   // return mean of T0 distrubution with vertex=0
180    // 
181   if (!fCalibentry) 
182     {
183       return fMeanT0;
184     }
185    
186   return fgCalibData->GetMeanT0();
187 }
188 //__________________________________________________________________
189
190 void 
191 AliT0Parameters::SetSlewingLED(Int_t ipmt)
192 {
193   //  Set Slweing Correction for LED channel 
194      Float_t mv[23] = {25, 30,40,60, 80,100,150,200,250,300,
195                        400,500,600,800,1000,1500, 2000, 3000, 4000, 5500,
196                        6000, 7000,8000};
197       Float_t y[23] = {5044, 4719, 3835, 3224, 2847, 2691,2327, 2067, 1937, 1781,
198                        1560, 1456 ,1339, 1163.5, 1027, 819, 650, 520, 370.5, 234,
199                        156, 78, 0};
200       
201       TGraph* gr = new TGraph(23,mv,y);
202       fSlewingLED.AddAtAndExpand(gr,ipmt);
203   }
204 //__________________________________________________________________
205
206 Float_t AliT0Parameters::GetSlewingLED(Int_t ipmt, Float_t mv) const
207 {
208   if (!fCalibentry) {
209     return ((TGraph*)fSlewingLED.At(ipmt))->Eval(mv); 
210   } 
211   return fgCalibData->GetSlewingLED(ipmt, mv) ;
212 }
213
214
215 //__________________________________________________________________
216
217 TGraph *AliT0Parameters::GetSlew(Int_t ipmt) const
218 {
219   if (!fCalibentry) {
220     return  (TGraph*)fSlewingLED.At(ipmt); 
221   } 
222   return fgCalibData -> GetSlew(ipmt) ;
223 }
224
225 //__________________________________________________________________
226
227
228 void 
229 AliT0Parameters::SetSlewingRec(Int_t ipmt)
230 {
231   //  Set Slweing Correction for LED channel 
232       Float_t mv[23] = {25, 30, 40,60, 80,100,150,200,250,300,
233                         400,500,600,800,1000,1500, 2000, 3000, 4000, 5500,
234                         6000, 7000,8000};
235       Float_t y[23] = {5044, 4719, 3835, 3224, 2847, 2691,2327, 2067, 1937, 1781, 
236                        1560, 1456 ,1339, 1163.5, 1027, 819, 650, 520, 370.5, 234, 
237                        156, 78, 0};
238       Float_t y1[23], mv1[23];
239       for (Int_t i=0; i<23; i++){
240         y1[i] = y[22-i]; mv1[i] = mv[22-i];}
241
242       TGraph* gr = new TGraph(23,y1,mv1);
243       fSlewingRec.AddAtAndExpand(gr,ipmt);
244
245 }
246 //__________________________________________________________________
247
248 Float_t AliT0Parameters::GetSlewingRec(Int_t ipmt, Float_t mv) const
249 {
250   if (!fCalibentry) {
251     return ((TGraph*)fSlewingRec.At(ipmt))->Eval(mv); 
252   } 
253   return fgCalibData -> GetSlewingRec(ipmt, mv) ;
254 }
255
256 //__________________________________________________________________
257
258 TGraph *AliT0Parameters::GetSlewRec(Int_t ipmt) const
259 {
260   if (!fCalibentry) {
261     return  (TGraph*)fSlewingRec.At(ipmt); 
262   } 
263   return fgCalibData -> GetSlewRec(ipmt) ;
264 }
265
266
267 //________________________________________________________________
268 void AliT0Parameters::SetWalk(Int_t ipmt)
269 {
270
271  Int_t mv, ps; 
272   Int_t x[70000], y[70000], index[70000];
273   Float_t time[10000],amplitude[10000];
274   string buffer;
275   Bool_t down=false;
276   
277   const char * filename = gSystem->ExpandPathName("$ALICE_ROOT/T0/data/CFD-Amp.txt");
278   ifstream inFile(filename);
279   //  if(!inFile) AliError(Form("Cannot open file %s !",filename));
280   
281   Int_t i=0;
282   while(getline(inFile,buffer)){
283     inFile >> ps >> mv;
284
285     x[i]=ps; y[i]=mv;
286     i++;
287   }
288   inFile.close();
289  
290   TMath::Sort(i, y, index,down);
291   Int_t amp=0, iin=0, isum=0, sum=0;
292   Int_t ind=0;
293   for (Int_t ii=0; ii<i; ii++)
294     {
295       ind=index[ii];
296       if(y[ind] == amp)
297         {
298           sum +=x[ind];
299           iin++;
300         }
301       else
302         {
303           if(iin>0)
304             time[isum] = Float_t (sum/(iin));
305           else
306             time[isum] =Float_t (x[ind]);
307           amplitude[isum] = Float_t (amp);
308           amp=y[ind];
309           //      cout<<ii<<" "<<ind<<" "<<y[ind]<<" "<<x[ind]<<" iin "<<iin<<" mean "<<time[isum]<<" amp "<< amplitude[isum]<<" "<<isum<<endl;
310           iin=0;
311           isum++;
312           sum=0;
313         }
314
315
316     }
317
318   inFile.close();
319
320    TGraph* gr = new TGraph(isum, amplitude, time);
321   fWalk.AddAtAndExpand(gr,ipmt);
322   
323   
324 }
325 //__________________________________________________________________
326
327 TGraph *AliT0Parameters::GetWalk(Int_t ipmt) const
328 {
329   if (!fCalibentry) {
330     return  (TGraph*)fWalk.At(ipmt); 
331   } 
332   return fgCalibData -> GetWalk(ipmt) ;
333 }
334
335 //__________________________________________________________________
336
337 Float_t AliT0Parameters::GetWalkVal(Int_t ipmt, Float_t mv) const
338 {
339   if (!fCalibentry) {
340     return ((TGraph*)fWalk.At(ipmt))->Eval(mv); 
341   } 
342   return fgCalibData -> GetWalkVal(ipmt, mv) ;
343 }
344
345
346 //__________________________________________________________________
347 void 
348 AliT0Parameters::SetPMTeff(Int_t ipmt)
349 {
350   Float_t lambda[50];
351   Float_t eff[50 ] = {0,        0,       0.23619,  0.202909, 0.177913, 
352                     0.175667, 0.17856, 0.190769, 0.206667, 0.230286,
353                     0.252276, 0.256267,0.26,     0.27125,  0.281818,
354                     0.288118, 0.294057,0.296222, 0.301622, 0.290421, 
355                     0.276615, 0.2666,  0.248,    0.23619,  0.227814, 
356                     0.219818, 0.206667,0.194087, 0.184681, 0.167917, 
357                     0.154367, 0.1364,  0.109412, 0.0834615,0.0725283, 
358                     0.0642963,0.05861, 0.0465,   0.0413333,0.032069, 
359                     0.0252203,0.02066, 0.016262, 0.012,    0.00590476,
360                     0.003875, 0.00190, 0,        0,        0          } ;
361   for (Int_t i=0; i<50; i++) lambda[i]=200+10*i; 
362
363   TGraph* gr = new TGraph(50,lambda,eff);
364   fPMTeff.AddAtAndExpand(gr,ipmt);
365 }
366 //________________________________________________________________
367
368 Int_t 
369 AliT0Parameters::GetChannel(Int_t trm,  Int_t tdc, Int_t chain, Int_t channel)
370 {
371
372   
373   AliT0LookUpKey * lookkey;  //= new AliT0LookUpKey();
374   AliT0LookUpValue * lookvalue= new AliT0LookUpValue(trm,tdc,chain,channel);
375     
376    lookkey = (AliT0LookUpKey*) fgLookUp->GetMapLookup()->GetValue((TObject*)lookvalue);
377   if (!lookkey ) {
378     cout<<" no such address "<<endl; return -1;
379   }
380   
381
382   //cout<<"AliT0Parameters:: key "<<lookkey->GetKey()<<endl;
383   return lookkey->GetKey();
384   
385
386 }
387 //__________________________________________________________________
388 Int_t
389 AliT0Parameters::GetNumberOfTRMs() 
390 {
391   // return number of trms
392   // 
393   if (!fgLookUp) {
394     fNumberOfTRMs = 2;
395     return  fNumberOfTRMs;
396   } 
397   return  fgLookUp ->GetNumberOfTRMs();
398 }
399 //________________________________________________________________________________
400 Double_t AliT0Parameters::GetZPosition(const char* symname){
401 // Get the global z coordinate of the given T0 alignable volume
402 //
403   Double_t *tr;
404   
405   cout<<symname<<endl;
406   TGeoPNEntry *pne = gGeoManager->GetAlignableEntry(symname);
407   if (!pne) return 0;
408   
409
410   TGeoPhysicalNode *pnode = pne->GetPhysicalNode();
411   if(pnode){
412           TGeoHMatrix* hm = pnode->GetMatrix();
413            tr = hm->GetTranslation();
414   }else{
415           const char* path = pne->GetTitle();
416           if(!gGeoManager->cd(path)){
417                   AliErrorClass(Form("Volume path %s not valid!",path));
418                   return 0;
419           }
420          tr = gGeoManager->GetCurrentMatrix()->GetTranslation();
421   }
422   return tr[2];
423
424 }
425