]> git.uio.no Git - u/mrichter/AliRoot.git/blob - T0/AliT0Parameters.cxx
DA find only coorect peak
[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 "AliT0.h"
28 #include "AliLog.h"               
29 #include "AliT0Parameters.h"      
30 #include "AliT0CalibData.h"   
31 #include "AliT0CalibWalk.h"   
32 #include "AliT0CalibTimeEq.h"   
33 #include "AliT0CalibLatency.h"   
34 #include "AliT0LookUpKey.h"
35 #include "AliT0LookUpValue.h"
36 #include <AliCDBManager.h>        
37 #include <AliCDBEntry.h>          
38 #include <AliCDBStorage.h>  
39 #include <TMath.h>
40 #include <TSystem.h>
41 //#include <Riostream.h>
42 #include <TGeoManager.h>
43 #include <TGeoPhysicalNode.h>
44 #include <TGeoMatrix.h>
45 #include <AliGeomManager.h>
46
47 AliT0CalibTimeEq* AliT0Parameters::fgCalibData = 0;
48 AliT0CalibData* AliT0Parameters::fgLookUp = 0;
49 AliT0CalibWalk* AliT0Parameters::fgSlewCorr =0;
50 AliT0CalibLatency *AliT0Parameters::fgLatency=0;
51 //====================================================================
52 ClassImp(AliT0Parameters)
53 #if 0
54   ; // This is here to keep Emacs for indenting the next line
55 #endif
56
57 //____________________________________________________________________
58 AliT0Parameters* AliT0Parameters::fgInstance = 0;
59 //____________________________________________________________________
60 AliT0Parameters* AliT0Parameters::Instance() 
61 {
62   // Get static instance 
63   if (!fgInstance) {
64     fgInstance = new AliT0Parameters;
65   }
66   return fgInstance;
67 }
68
69 //____________________________________________________________________
70 AliT0Parameters::AliT0Parameters()
71   :fIsInit(kFALSE),
72    fPh2Mip(0),fmV2Mip(0),
73    fChannelWidth(0),fmV2Channel(0),
74    fQTmin(0),fQTmax(0),
75    fAmpLEDRec(0), 
76    fPMTeff(),
77    fWalk(0),
78    fQTC(0),
79    fAmpLED(0),
80    fTimeDelayCFD(0), 
81  //  fTimeV0(0), 
82    fTimeDelayTVD(0),
83    fMeanT0(512),
84    fMeanVertex(0),
85    fLookUp(0),
86    fNumberOfTRMs(2),
87    fCalibentry(), fLookUpentry(),fSlewCorr()
88
89   
90 {
91   // Default constructor 
92   for (Int_t ipmt=0; ipmt<24; ipmt++)
93     {
94       SetPh2Mip();      
95       SetmV2Mip();      
96       SetChannelWidth();
97       SetmV2channel();
98       SetQTmin();
99       SetQTmax();
100       SetPMTeff(ipmt);
101     }
102   SetTimeDelayTVD();
103   SetZposition();
104     
105 }
106
107 //__________________________________________________________________
108 void
109 AliT0Parameters::Init()
110 {
111   // Initialize the parameters manager.  We need to get stuff from the
112   // CDB here. 
113    if (fIsInit) return;
114
115    AliCDBManager *stor =AliCDBManager::Instance();
116    //time equalizing
117    fCalibentry  = stor->Get("T0/Calib/TimeDelay");
118    if (fCalibentry)
119      fgCalibData  = (AliT0CalibTimeEq*)fCalibentry->GetObject();
120    else {
121          AliFatal(" ALARM !!!! No time delays in CDB "); 
122      fIsInit = kFALSE;
123      return;
124    }
125  //slewing correction
126   fSlewCorr  = stor->Get("T0/Calib/Slewing_Walk");
127   if (fSlewCorr){
128     fgSlewCorr  = (AliT0CalibWalk*)fSlewCorr->GetObject();
129   }
130   else {
131       AliFatal(" ALARM !!!! No slewing correction in CDB "); 
132     fIsInit = kFALSE;
133     return;
134   }
135   //lookup table
136   fLookUpentry  = stor->Get("T0/Calib/LookUp_Table");
137   if (fLookUpentry){
138     fgLookUp  = (AliT0CalibData*)fLookUpentry->GetObject();
139   }
140   else {
141      AliFatal(" ALARM !!!! No Lookup table  in CDB "); 
142     fIsInit = kFALSE;
143     return;
144   }
145   //latency
146   
147  fLatency  = stor->Get("T0/Calib/Latency");
148   if (fLatency){
149     fgLatency  = (AliT0CalibLatency*)fLatency->GetObject();
150   }
151   else {
152      AliWarning(" !!! no latency  in CDB "); 
153     return;
154   }
155   
156 fIsInit = kTRUE;
157 }
158
159
160 //__________________________________________________________________
161
162 void AliT0Parameters::InitIfOnline()
163 {
164 // should be used in online
165 // for switching to this one should write
166   // AliT0RawReader myrawreader(rawReader);
167 //      myrawreader.SetOnlineMode(kTRUE);
168
169   if (fIsInit) return;
170    //standart configuration (used for simulation)
171    //Int_t trm=0; Int_t tdc=0; Int_t chain=0; Int_t channel=0;
172   // configuration for test Jun07.
173    fgLookUp = new AliT0CalibData("T0");
174
175   fNumberOfTRMs = 1;
176  fgLookUp-> SetNumberOfTRMs(fNumberOfTRMs);
177   Int_t trm=7; Int_t tdc=0; Int_t chain=0; Int_t channel=0;
178   for (Int_t ik=0; ik<105; ik++)
179         {
180          AliT0LookUpKey * lookkey= new AliT0LookUpKey();
181          AliT0LookUpValue * lookvalue= new AliT0LookUpValue();
182
183
184           lookvalue->SetTRM(trm);
185           lookvalue->SetTDC(tdc);
186           lookvalue->SetChain(chain);
187           lookvalue->SetChannel(channel);
188           lookkey->SetKey(ik);
189           fgLookUp->GetMapLookup()->Add((TObject*)lookvalue,(TObject*)lookkey); 
190           if (channel<6) channel +=2;
191           else {channel = 0; tdc++;}
192           if(ik==56) { tdc=0; channel=0; chain = 1;}
193
194        }
195   
196   fIsInit=kTRUE;
197 }
198 //__________________________________________________________________
199 Float_t
200 AliT0Parameters::GetTimeDelayCFD(Int_t ipmt) 
201   {
202   // return time delay for CFD channel
203    // 
204   if (!fCalibentry) 
205     {
206       fTimeDelayCFD = 1000+ipmt*100;
207       return fTimeDelayCFD;
208     }
209    
210   return fgCalibData->GetTimeEq(ipmt);
211 }
212
213 //__________________________________________________________________
214 Float_t
215 AliT0Parameters::GetLatencyHPTDC() 
216   {
217   // return LatencyHPTDC for CFD channel
218   if (!fLatency) 
219     {
220       fLatencyHPTDC=9000.;
221       return fLatencyHPTDC;
222     }
223    
224   return fgLatency->GetLatencyHPTDC();
225 }
226 //__________________________________________________________________
227 Float_t
228 AliT0Parameters::GetLatencyL1() 
229   {
230   // return time delay for CFD channel
231    
232   return fgLatency->GetLatencyL1();
233 }
234
235 //__________________________________________________________________
236 Float_t
237 AliT0Parameters::GetLatencyL1A() 
238   {
239   // return time delay for CFD channel
240    
241   return fgLatency->GetLatencyL1A();
242 }
243
244 //__________________________________________________________________
245 Float_t
246 AliT0Parameters::GetLatencyL1C() 
247   {
248   // return time delay for CFD channel
249    
250   return fgLatency->GetLatencyL1C();
251 }
252 //__________________________________________________________________
253
254 Float_t
255 AliT0Parameters:: GetMeanVertex()
256
257   if (!fCalibentry) 
258     {
259       fMeanVertex=0;
260       return fMeanVertex;
261     }
262    
263   return fgCalibData->GetMeanVertex();
264 }
265 //__________________________________________________________________
266
267 TGraph *AliT0Parameters::GetAmpLEDRec(Int_t ipmt) const
268 {
269    if (!fSlewCorr) {
270      AliError("No slewing correction is available!");
271      return  (TGraph*)fAmpLEDRec.At(ipmt); 
272   } 
273   return fgSlewCorr -> GetAmpLEDRec(ipmt) ;
274 }
275
276 //__________________________________________________________________
277
278 TGraph *AliT0Parameters::GetWalk(Int_t ipmt) const
279 {
280   if (!fSlewCorr) {
281     AliError("No walk correction is available!");
282     return  (TGraph*)fWalk.At(ipmt); 
283   } 
284   return fgSlewCorr -> GetWalk(ipmt) ;
285 }
286
287 //__________________________________________________________________
288
289 TGraph *AliT0Parameters::GetQTC(Int_t ipmt) const
290 {
291   if (!fSlewCorr) {
292     AliError("No walk correction is available!");
293     //    return  (TGraph*)fQTC.At(ipmt); 
294    return  0; 
295   } 
296   return fgSlewCorr -> GetQTC(ipmt) ;
297 }
298
299 //__________________________________________________________________
300 TGraph *AliT0Parameters::GetAmpLED(Int_t ipmt) const
301 {
302   if (!fSlewCorr) {
303     AliError("No walk correction is available!");
304     //    return  (TGraph*)fQTC.At(ipmt); 
305    return  0; 
306   } 
307   return fgSlewCorr -> GetAmpLED(ipmt) ;
308 }
309
310 //__________________________________________________________________
311 void 
312 AliT0Parameters::SetPMTeff(Int_t ipmt)
313 {
314   Float_t lambda[50];
315   Float_t eff[50 ] = {0,        0,       0.23619,  0.202909, 0.177913, 
316                     0.175667, 0.17856, 0.190769, 0.206667, 0.230286,
317                     0.252276, 0.256267,0.26,     0.27125,  0.281818,
318                     0.288118, 0.294057,0.296222, 0.301622, 0.290421, 
319                     0.276615, 0.2666,  0.248,    0.23619,  0.227814, 
320                     0.219818, 0.206667,0.194087, 0.184681, 0.167917, 
321                     0.154367, 0.1364,  0.109412, 0.0834615,0.0725283, 
322                     0.0642963,0.05861, 0.0465,   0.0413333,0.032069, 
323                     0.0252203,0.02066, 0.016262, 0.012,    0.00590476,
324                     0.003875, 0.00190, 0,        0,        0          } ;
325   for (Int_t i=0; i<50; i++) lambda[i]=200+10*i; 
326
327   TGraph* gr = new TGraph(50,lambda,eff);
328   fPMTeff.AddAtAndExpand(gr,ipmt);
329 }
330 //________________________________________________________________
331
332 Int_t 
333 AliT0Parameters::GetChannel(Int_t trm,  Int_t tdc, Int_t chain, Int_t channel)
334 {
335
336   if (fgLookUp) {
337     AliT0LookUpValue key(trm,tdc,chain,channel);
338       AliT0LookUpKey *val = (AliT0LookUpKey*) fgLookUp->GetMapLookup()->GetValue((TObject*)&key);
339       // AliT0LookUpKey *val = (AliT0LookUpKey*) fLookUp.GetValue((TObject*)&key);
340     if (val )
341       return val->GetKey();
342     else {
343       AliWarning(Form("No such address (%d %d %d %d)!",trm,tdc,chain,channel));
344       return -1;
345     }
346   }
347   else {
348     AliError("No look up table has been loader!");
349     return -1;
350   }
351
352 }
353 //__________________________________________________________________
354 TMap *AliT0Parameters::GetMapLookup()
355 {
356   if (!fgLookUp){
357     cout<<" No look up table in OCDB";
358     return 0;
359   }
360   return   fgLookUp->GetMapLookup();
361 }
362 //__________________________________________________________________
363
364 Int_t
365 AliT0Parameters::GetNumberOfTRMs() 
366 {
367   // return number of trms
368   // 
369   if (!fgLookUp) {
370     //  fNumberOfTRMs = 2;
371     return  fNumberOfTRMs;
372   } 
373   return  fgLookUp ->GetNumberOfTRMs();
374 }
375 /*
376 //________________________________________________________________________________
377 Double_t AliT0Parameters::GetZPosition(const char* symname){
378 // Get the global z coordinate of the given T0 alignable volume
379 //
380   Double_t *tr = AliGeomManager::GetMatrix(symname)->GetTranslation();
381
382   return tr[2];
383 }
384 */
385 //________________________________________________________________________________
386 Double_t AliT0Parameters::GetZPosition(const char* symname){
387 // Get the global z coordinate of the given T0 alignable volume
388 //
389   Double_t *tr;
390   TGeoPNEntry *pne = gGeoManager->GetAlignableEntry(symname);
391   if (!pne) return 0;
392   
393
394   TGeoPhysicalNode *pnode = pne->GetPhysicalNode();
395   if(pnode){
396           TGeoHMatrix* hm = pnode->GetMatrix();
397            tr = hm->GetTranslation();
398   }else{
399           const char* path = pne->GetTitle();
400           if(!gGeoManager->cd(path)){
401                   AliErrorClass(Form("Volume path %s not valid!",path));
402                   return 0;
403           }
404          tr = gGeoManager->GetCurrentMatrix()->GetTranslation();
405   }
406   return tr[2];
407
408 }
409 //________________________________________________________________________________
410
411 Double_t AliT0Parameters::GetZPositionShift(const char* symname)
412 {
413 // Get the global z coordinate of the given T0 alignable volume
414 //
415   Double_t *tr = AliGeomManager::GetMatrix(symname)->GetTranslation();
416
417   TGeoHMatrix origmat;
418   AliGeomManager::GetOrigGlobalMatrix(symname,origmat);
419   Double_t *otr = origmat.GetTranslation();
420
421   return (tr[2]-otr[2]);
422 }
423