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