]> git.uio.no Git - u/mrichter/AliRoot.git/blob - T0/AliT0Parameters.cxx
3f39f5b8976cdc402d603244edac5bbcee8cc7df
[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 <Riostream.h>
35
36 AliT0CalibData* AliT0Parameters::fgCalibData = 0;
37 AliT0CalibData* AliT0Parameters::fgLookUp = 0;
38 //====================================================================
39 ClassImp(AliT0Parameters)
40 #if 0
41   ; // This is here to keep Emacs for indenting the next line
42 #endif
43
44 //____________________________________________________________________
45 AliT0Parameters* AliT0Parameters::fgInstance = 0;
46 //____________________________________________________________________
47 AliT0Parameters* 
48 AliT0Parameters::Instance() 
49 {
50   // Get static instance 
51   if (!fgInstance) fgInstance = new AliT0Parameters;
52   return fgInstance;
53 }
54
55 //____________________________________________________________________
56 AliT0Parameters::AliT0Parameters()
57   :fIsInit(kFALSE),fPh2Mip(0),fmV2Mip(0),fChannelWidth(0),fmV2Channel(0),fQTmin(0),fQTmax(0),fFixedGain(0),fSlewingLED(),fSlewingRec(),fPMTeff(),fTimeDelayLED(0),fTimeDelayCFD(0),fTimeDelayTVD(0),fCalibentry() 
58 {
59   // Default constructor 
60
61   for (Int_t ipmt=0; ipmt<24; ipmt++)
62     {
63       SetTimeDelayCablesCFD(ipmt);
64       SetTimeDelayCablesLED(ipmt);
65       SetTimeDelayElectronicCFD(ipmt);
66       SetTimeDelayElectronicLED(ipmt);
67       SetTimeDelayPMT(ipmt);
68        SetVariableDelayLine(ipmt);
69       SetSlewingLED(ipmt);
70       SetSlewingRec(ipmt);
71       SetPh2Mip();      
72       SetmV2Mip();      
73       SetChannelWidth();
74       SetmV2channel();
75       SetGain();
76       SetQTmin();
77       SetQTmax();
78       SetPMTeff(ipmt);
79    }
80   SetTimeDelayTVD();
81   SetZposition();
82   
83 }
84
85 //__________________________________________________________________
86 void
87 AliT0Parameters::Init()
88 {
89   // Initialize the parameters manager.  We need to get stuff from the
90   // CDB here. 
91   //   if (fIsInit) return;
92   
93   // AliCDBManager* cdb      = AliCDBManager::Instance();
94   // fCalibentry  = cdb->Get("T0/Calib/Gain_TimeDelay_Slewing_Walk");
95  
96
97   AliCDBStorage *stor =AliCDBManager::Instance()->GetStorage("local://$ALICE_ROOT");
98   AliCDBEntry* fCalibentry  = stor->Get("T0/Calib/Gain_TimeDelay_Slewing_Walk",0);
99  if (fCalibentry){
100    fgCalibData  = (AliT0CalibData*)fCalibentry->GetObject();
101   }
102  // fLookUpentry  = cdb->Get("T0/Calib/LookUp_Table");
103   fLookUpentry  = stor->Get("T0/Calib/LookUp_Table",0);
104   if (fLookUpentry){
105     fgLookUp  = (AliT0CalibData*)fLookUpentry->GetObject();
106     //   fgLookUp->Dump();
107   }
108   else {
109     fgLookUp->ReadAsciiLookup("$ALICE_ROOT/T0/lookUpTable.txt");
110   }
111
112   fIsInit = kTRUE;
113 }
114
115
116 //__________________________________________________________________
117 Float_t
118 AliT0Parameters::GetGain(Int_t ipmt) const
119 {
120   // Returns the calibrated gain for each PMT 
121   // 
122
123   if (!fCalibentry) 
124     return fFixedGain;
125    
126   return fgCalibData->GetGain(ipmt);
127 }
128
129 //__________________________________________________________________
130 Float_t
131 AliT0Parameters::GetTimeDelayLED(Int_t ipmt) 
132 {
133   // return time delay for LED channel
134   // 
135   if (!fCalibentry) {
136     fTimeDelayLED = fTimeDelayCablesLED[ipmt] + fTimeDelayElectronicLED[ipmt] + fTimeDelayPMT[ipmt];
137     return  fTimeDelayLED;
138   } 
139   return fgCalibData ->GetTimeDelayLED(ipmt);
140 }
141 //__________________________________________________________________
142 Float_t
143 AliT0Parameters::GetTimeDelayCFD(Int_t ipmt) 
144 {
145   // return time delay for CFD channel
146    // 
147   if (!fCalibentry) 
148     {
149       fTimeDelayCFD = fTimeDelayCablesCFD[ipmt] + fTimeDelayElectronicCFD[ipmt] + fTimeDelayPMT[ipmt] + fVariableDelayLine[ipmt];
150       return fTimeDelayCFD+37;
151     }
152    
153   return fgCalibData->GetTimeDelayCFD(ipmt);
154 }
155
156 //__________________________________________________________________
157
158 void 
159 AliT0Parameters::SetSlewingLED(Int_t ipmt)
160 {
161   //  Set Slweing Correction for LED channel 
162      Float_t mv[23] = {25, 30,40,60, 80,100,150,200,250,300,
163                        400,500,600,800,1000,1500, 2000, 3000, 4000, 5500,
164                        6000, 7000,8000};
165       Float_t y[23] = {5044, 4719, 3835, 3224, 2847, 2691,2327, 2067, 1937, 1781,
166                        1560, 1456 ,1339, 1163.5, 1027, 819, 650, 520, 370.5, 234,
167                        156, 78, 0};
168       
169       TGraph* gr = new TGraph(23,mv,y);
170       fSlewingLED.AddAtAndExpand(gr,ipmt);
171   }
172 //__________________________________________________________________
173
174 Float_t AliT0Parameters::GetSlewingLED(Int_t ipmt, Float_t mv) const
175 {
176   if (!fCalibentry) {
177     return ((TGraph*)fSlewingLED.At(ipmt))->Eval(mv); 
178   } 
179   return fgCalibData->GetSlewingLED(ipmt, mv) ;
180 }
181
182
183 //__________________________________________________________________
184
185 TGraph *AliT0Parameters::GetSlew(Int_t ipmt) const
186 {
187   if (!fCalibentry) {
188     return  (TGraph*)fSlewingLED.At(ipmt); 
189   } 
190   return fgCalibData -> GetSlew(ipmt) ;
191 }
192
193 //__________________________________________________________________
194
195
196 void 
197 AliT0Parameters::SetSlewingRec(Int_t ipmt)
198 {
199   //  Set Slweing Correction for LED channel 
200       Float_t mv[23] = {25, 30, 40,60, 80,100,150,200,250,300,
201                         400,500,600,800,1000,1500, 2000, 3000, 4000, 5500,
202                         6000, 7000,8000};
203       Float_t y[23] = {5044, 4719, 3835, 3224, 2847, 2691,2327, 2067, 1937, 1781, 
204                        1560, 1456 ,1339, 1163.5, 1027, 819, 650, 520, 370.5, 234, 
205                        156, 78, 0};
206       Float_t y1[23], mv1[23];
207       for (Int_t i=0; i<23; i++){
208         y1[i] = y[22-i]; mv1[i] = mv[22-i];}
209
210       TGraph* gr = new TGraph(23,y1,mv1);
211       fSlewingRec.AddAtAndExpand(gr,ipmt);
212
213 }
214 //__________________________________________________________________
215
216 Float_t AliT0Parameters::GetSlewingRec(Int_t ipmt, Float_t mv) const
217 {
218   if (!fCalibentry) {
219     return ((TGraph*)fSlewingRec.At(ipmt))->Eval(mv); 
220   } 
221   return fgCalibData -> GetSlewingRec(ipmt, mv) ;
222 }
223
224 //__________________________________________________________________
225
226 TGraph *AliT0Parameters::GetSlewRec(Int_t ipmt) const
227 {
228   if (!fCalibentry) {
229     return  (TGraph*)fSlewingRec.At(ipmt); 
230   } 
231   return fgCalibData -> GetSlewRec(ipmt) ;
232 }
233
234 //__________________________________________________________________
235 void 
236 AliT0Parameters::SetPMTeff(Int_t ipmt)
237 {
238   Float_t lambda[50];
239   Float_t eff[50 ] = {0,        0,       0.23619,  0.202909, 0.177913, 
240                     0.175667, 0.17856, 0.190769, 0.206667, 0.230286,
241                     0.252276, 0.256267,0.26,     0.27125,  0.281818,
242                     0.288118, 0.294057,0.296222, 0.301622, 0.290421, 
243                     0.276615, 0.2666,  0.248,    0.23619,  0.227814, 
244                     0.219818, 0.206667,0.194087, 0.184681, 0.167917, 
245                     0.154367, 0.1364,  0.109412, 0.0834615,0.0725283, 
246                     0.0642963,0.05861, 0.0465,   0.0413333,0.032069, 
247                     0.0252203,0.02066, 0.016262, 0.012,    0.00590476,
248                     0.003875, 0.00190, 0,        0,        0          } ;
249   for (Int_t i=0; i<50; i++) lambda[i]=200+10*i; 
250
251   TGraph* gr = new TGraph(50,lambda,eff);
252   fPMTeff.AddAtAndExpand(gr,ipmt);
253 }
254 //________________________________________________________________
255
256 Int_t 
257 AliT0Parameters::GetChannel(Int_t trm,  Int_t tdc, Int_t chain, Int_t channel)
258 {
259
260   
261   AliT0LookUpKey * lookkey;  //= new AliT0LookUpKey();
262   AliT0LookUpValue * lookvalue= new AliT0LookUpValue(trm,tdc,chain,channel);
263     
264    lookkey = (AliT0LookUpKey*) fgLookUp->GetMapLookup()->GetValue((TObject*)lookvalue);
265   if (!lookkey ) {
266     cout<<" no such address "<<endl; return -1;
267   }
268   
269
270   //cout<<"AliT0Parameters:: key "<<lookkey->GetKey()<<endl;
271   return lookkey->GetKey();
272   
273
274 }