]> git.uio.no Git - u/mrichter/AliRoot.git/blame - T0/AliT0Parameters.cxx
DA find only coorect peak
[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//
6b7d32f7 27#include "AliT0.h"
dc7ca31d 28#include "AliLog.h"
29#include "AliT0Parameters.h"
30#include "AliT0CalibData.h"
82ee3b37 31#include "AliT0CalibWalk.h"
32#include "AliT0CalibTimeEq.h"
58bd3a16 33#include "AliT0CalibLatency.h"
2d3bfdf7 34#include "AliT0LookUpKey.h"
e0bba6cc 35#include "AliT0LookUpValue.h"
dc7ca31d 36#include <AliCDBManager.h>
37#include <AliCDBEntry.h>
0d82bd92 38#include <AliCDBStorage.h>
aae44346 39#include <TMath.h>
0d82bd92 40#include <TSystem.h>
700e6b36 41//#include <Riostream.h>
5325480c 42#include <TGeoManager.h>
43#include <TGeoPhysicalNode.h>
212239a1 44#include <TGeoMatrix.h>
0d82bd92 45#include <AliGeomManager.h>
dc7ca31d 46
82ee3b37 47AliT0CalibTimeEq* AliT0Parameters::fgCalibData = 0;
e0bba6cc 48AliT0CalibData* AliT0Parameters::fgLookUp = 0;
82ee3b37 49AliT0CalibWalk* AliT0Parameters::fgSlewCorr =0;
58bd3a16 50AliT0CalibLatency *AliT0Parameters::fgLatency=0;
dc7ca31d 51//====================================================================
52ClassImp(AliT0Parameters)
53#if 0
54 ; // This is here to keep Emacs for indenting the next line
55#endif
56
57//____________________________________________________________________
58AliT0Parameters* AliT0Parameters::fgInstance = 0;
59//____________________________________________________________________
3b7f37fd 60AliT0Parameters* AliT0Parameters::Instance()
dc7ca31d 61{
62 // Get static instance
76f3b07a 63 if (!fgInstance) {
64 fgInstance = new AliT0Parameters;
76f3b07a 65 }
dc7ca31d 66 return fgInstance;
67}
68
69//____________________________________________________________________
70AliT0Parameters::AliT0Parameters()
5325480c 71 :fIsInit(kFALSE),
72 fPh2Mip(0),fmV2Mip(0),
73 fChannelWidth(0),fmV2Channel(0),
74 fQTmin(0),fQTmax(0),
29d3e0eb 75 fAmpLEDRec(0),
5325480c 76 fPMTeff(),
29d3e0eb 77 fWalk(0),
c2337900 78 fQTC(0),
79 fAmpLED(0),
29d3e0eb 80 fTimeDelayCFD(0),
82ee3b37 81 // fTimeV0(0),
29d3e0eb 82 fTimeDelayTVD(0),
494f5042 83 fMeanT0(512),
4c809cd8 84 fMeanVertex(0),
29d3e0eb 85 fLookUp(0),
86 fNumberOfTRMs(2),
87 fCalibentry(), fLookUpentry(),fSlewCorr()
88
74adb36a 89
dc7ca31d 90{
91 // Default constructor
dc7ca31d 92 for (Int_t ipmt=0; ipmt<24; ipmt++)
93 {
dc7ca31d 94 SetPh2Mip();
95 SetmV2Mip();
96 SetChannelWidth();
97 SetmV2channel();
dc7ca31d 98 SetQTmin();
99 SetQTmax();
100 SetPMTeff(ipmt);
74adb36a 101 }
dc7ca31d 102 SetTimeDelayTVD();
103 SetZposition();
74adb36a 104
dc7ca31d 105}
106
107//__________________________________________________________________
108void
109AliT0Parameters::Init()
110{
111 // Initialize the parameters manager. We need to get stuff from the
112 // CDB here.
94c27e4f 113 if (fIsInit) return;
6ba20b30 114
74adb36a 115 AliCDBManager *stor =AliCDBManager::Instance();
74adb36a 116 //time equalizing
256d4943 117 fCalibentry = stor->Get("T0/Calib/TimeDelay");
118 if (fCalibentry)
82ee3b37 119 fgCalibData = (AliT0CalibTimeEq*)fCalibentry->GetObject();
256d4943 120 else {
121 AliFatal(" ALARM !!!! No time delays in CDB ");
122 fIsInit = kFALSE;
123 return;
124 }
c41ceaac 125 //slewing correction
74adb36a 126 fSlewCorr = stor->Get("T0/Calib/Slewing_Walk");
5325480c 127 if (fSlewCorr){
82ee3b37 128 fgSlewCorr = (AliT0CalibWalk*)fSlewCorr->GetObject();
c41ceaac 129 }
3b7f37fd 130 else {
256d4943 131 AliFatal(" ALARM !!!! No slewing correction in CDB ");
3b7f37fd 132 fIsInit = kFALSE;
133 return;
134 }
74adb36a 135 //lookup table
6eac39a1 136 fLookUpentry = stor->Get("T0/Calib/LookUp_Table");
e0bba6cc 137 if (fLookUpentry){
138 fgLookUp = (AliT0CalibData*)fLookUpentry->GetObject();
e0bba6cc 139 }
3b7f37fd 140 else {
256d4943 141 AliFatal(" ALARM !!!! No Lookup table in CDB ");
3b7f37fd 142 fIsInit = kFALSE;
143 return;
144 }
58bd3a16 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
156fIsInit = kTRUE;
dc7ca31d 157}
158
159
dc7ca31d 160//__________________________________________________________________
f8bea420 161
162void 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);
700e6b36 168
0d82bd92 169 if (fIsInit) return;
29d3e0eb 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.
d9cae8af 173 fgLookUp = new AliT0CalibData("T0");
dd9fd8d6 174
0d72dc5b 175 fNumberOfTRMs = 1;
d9cae8af 176 fgLookUp-> SetNumberOfTRMs(fNumberOfTRMs);
0d72dc5b 177 Int_t trm=7; Int_t tdc=0; Int_t chain=0; Int_t channel=0;
79e04c5f 178 for (Int_t ik=0; ik<105; ik++)
f8bea420 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);
0d82bd92 189 fgLookUp->GetMapLookup()->Add((TObject*)lookvalue,(TObject*)lookkey);
663b10cd 190 if (channel<6) channel +=2;
191 else {channel = 0; tdc++;}
0d82bd92 192 if(ik==56) { tdc=0; channel=0; chain = 1;}
dd9fd8d6 193
f8bea420 194 }
74adb36a 195
196 fIsInit=kTRUE;
f8bea420 197}
198//__________________________________________________________________
dc7ca31d 199Float_t
200AliT0Parameters::GetTimeDelayCFD(Int_t ipmt)
82ee3b37 201 {
dc7ca31d 202 // return time delay for CFD channel
203 //
204 if (!fCalibentry)
205 {
c41ceaac 206 fTimeDelayCFD = 1000+ipmt*100;
207 return fTimeDelayCFD;
dc7ca31d 208 }
209
82ee3b37 210 return fgCalibData->GetTimeEq(ipmt);
dc7ca31d 211}
58bd3a16 212
213//__________________________________________________________________
214Float_t
215AliT0Parameters::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//__________________________________________________________________
227Float_t
228AliT0Parameters::GetLatencyL1()
229 {
230 // return time delay for CFD channel
231
232 return fgLatency->GetLatencyL1();
233}
234
235//__________________________________________________________________
236Float_t
237AliT0Parameters::GetLatencyL1A()
238 {
239 // return time delay for CFD channel
240
241 return fgLatency->GetLatencyL1A();
242}
243
244//__________________________________________________________________
245Float_t
246AliT0Parameters::GetLatencyL1C()
247 {
248 // return time delay for CFD channel
249
250 return fgLatency->GetLatencyL1C();
251}
dc7ca31d 252//__________________________________________________________________
253
b95e8d87 254Float_t
255AliT0Parameters:: GetMeanVertex()
256{
257 if (!fCalibentry)
258 {
259 fMeanVertex=0;
260 return fMeanVertex;
261 }
262
263 return fgCalibData->GetMeanVertex();
264}
265//__________________________________________________________________
266
74adb36a 267TGraph *AliT0Parameters::GetAmpLEDRec(Int_t ipmt) const
dc7ca31d 268{
74adb36a 269 if (!fSlewCorr) {
29d3e0eb 270 AliError("No slewing correction is available!");
271 return (TGraph*)fAmpLEDRec.At(ipmt);
dc7ca31d 272 }
74adb36a 273 return fgSlewCorr -> GetAmpLEDRec(ipmt) ;
dc7ca31d 274}
275
276//__________________________________________________________________
277
c41ceaac 278TGraph *AliT0Parameters::GetWalk(Int_t ipmt) const
279{
74adb36a 280 if (!fSlewCorr) {
29d3e0eb 281 AliError("No walk correction is available!");
c41ceaac 282 return (TGraph*)fWalk.At(ipmt);
283 }
74adb36a 284 return fgSlewCorr -> GetWalk(ipmt) ;
c41ceaac 285}
286
287//__________________________________________________________________
288
c883fdf2 289TGraph *AliT0Parameters::GetQTC(Int_t ipmt) const
c41ceaac 290{
0d82bd92 291 if (!fSlewCorr) {
c883fdf2 292 AliError("No walk correction is available!");
293 // return (TGraph*)fQTC.At(ipmt);
294 return 0;
c41ceaac 295 }
c883fdf2 296 return fgSlewCorr -> GetQTC(ipmt) ;
c41ceaac 297}
298
c883fdf2 299//__________________________________________________________________
300TGraph *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}
c41ceaac 309
dc7ca31d 310//__________________________________________________________________
311void
312AliT0Parameters::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}
e0bba6cc 330//________________________________________________________________
331
332Int_t
333AliT0Parameters::GetChannel(Int_t trm, Int_t tdc, Int_t chain, Int_t channel)
334{
335
e30bc492 336 if (fgLookUp) {
337 AliT0LookUpValue key(trm,tdc,chain,channel);
3a06b1d2 338 AliT0LookUpKey *val = (AliT0LookUpKey*) fgLookUp->GetMapLookup()->GetValue((TObject*)&key);
339 // AliT0LookUpKey *val = (AliT0LookUpKey*) fLookUp.GetValue((TObject*)&key);
e30bc492 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!");
29d3e0eb 349 return -1;
e0bba6cc 350 }
e0bba6cc 351
352}
5325480c 353//__________________________________________________________________
29d3e0eb 354TMap *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
5325480c 364Int_t
365AliT0Parameters::GetNumberOfTRMs()
366{
367 // return number of trms
368 //
369 if (!fgLookUp) {
29d3e0eb 370 // fNumberOfTRMs = 2;
5325480c 371 return fNumberOfTRMs;
372 }
373 return fgLookUp ->GetNumberOfTRMs();
374}
256d4943 375/*
5325480c 376//________________________________________________________________________________
377Double_t AliT0Parameters::GetZPosition(const char* symname){
378// Get the global z coordinate of the given T0 alignable volume
379//
29d3e0eb 380 Double_t *tr = AliGeomManager::GetMatrix(symname)->GetTranslation();
5325480c 381
5325480c 382 return tr[2];
29d3e0eb 383}
256d4943 384*/
385//________________________________________________________________________________
386Double_t AliT0Parameters::GetZPosition(const char* symname){
387// Get the global z coordinate of the given T0 alignable volume
388//
389 Double_t *tr;
256d4943 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}
29d3e0eb 409//________________________________________________________________________________
410
411Double_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();
5325480c 420
29d3e0eb 421 return (tr[2]-otr[2]);
5325480c 422}
423