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