1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // Class providing the calibration parameters by accessing the CDB //
22 // Request an instance with AliTRDcalibDB::Instance() //
23 // If a new event is processed set the event number with SetRun //
24 // Then request the calibration data //
26 ///////////////////////////////////////////////////////////////////////////////
30 #include <AliCDBManager.h>
32 #include "AliTRDcalibDB.h"
33 #include "AliTRDgeometry.h"
34 #include "AliTRDpadPlane.h"
35 #include "AliTRDCommonParam.h"
37 #include "AliTRDCalROC.h"
38 #include "AliTRDCalChamberPos.h"
39 #include "AliTRDCalStackPos.h"
40 #include "AliTRDCalPad.h"
41 #include "AliTRDCalDet.h"
42 #include "AliTRDCalGlobals.h"
43 #include "AliTRDCalPIDLQ.h"
45 ClassImp(AliTRDcalibDB)
47 AliTRDcalibDB* AliTRDcalibDB::fgInstance = 0;
48 Bool_t AliTRDcalibDB::fgTerminated = kFALSE;
50 //_ singleton implementation __________________________________________________
51 AliTRDcalibDB* AliTRDcalibDB::Instance()
54 // Singleton implementation
55 // Returns an instance of this class, it is created if neccessary
58 if (fgTerminated != kFALSE)
62 fgInstance = new AliTRDcalibDB();
67 void AliTRDcalibDB::Terminate()
70 // Singleton implementation
71 // Deletes the instance of this class and sets the terminated flag, instances cannot be requested anymore
72 // This function can be called several times.
84 //_____________________________________________________________________________
85 AliTRDcalibDB::AliTRDcalibDB()
91 // TODO Default runnumber is set to 0, this should be changed later to an invalid value (e.g. -1) to prevent
92 // TODO invalid calibration data to be used.
95 fPadResponse.fPRFbin = 0;
96 fPadResponse.fPRFlo = 0.0;
97 fPadResponse.fPRFhi = 0.0;
98 fPadResponse.fPRFwid = 0.0;
99 fPadResponse.fPRFpad = 0;
100 fPadResponse.fPRFsmp = 0;
102 AliCDBManager* manager = AliCDBManager::Instance();
105 std::cout << "AliTRDcalibDB: CRITICAL: Failed to get instance of AliCDBManager." << std::endl;
109 fLocator = manager->GetStorage("local://$ALICE_ROOT");
111 for (Int_t i=0; i<kCDBCacheSize; ++i)
117 // Create the sampled PRF
121 //_____________________________________________________________________________
122 AliTRDcalibDB::~AliTRDcalibDB()
128 if (fPadResponse.fPRFsmp) {
129 delete [] fPadResponse.fPRFsmp;
130 fPadResponse.fPRFsmp = 0;
136 //_____________________________________________________________________________
137 void AliTRDcalibDB::SetRun(Long64_t run)
140 // Sets current run number. Calibration data is read from the corresponding file.
141 // When the run number changes the caching is invalidated.
151 //_____________________________________________________________________________
152 void AliTRDcalibDB::Invalidate()
155 // Invalidates cache (when run number is changed).
158 for (Int_t i=0; i<kCDBCacheSize; ++i)
162 if (fCDBEntries[i]->IsOwner() == kFALSE && fCDBCache[i])
165 delete fCDBEntries[i];
172 //_____________________________________________________________________________
173 Bool_t AliTRDcalibDB::GetChamberPos(Int_t det, Float_t* xyz)
176 // Returns the deviation of the chamber position from the nominal position.
179 AliTRDCalChamberPos* chamber = dynamic_cast<AliTRDCalChamberPos*>(GetCachedCDBObject(kIDChamber));
183 const Float_t* kvalues = chamber->GetChamberPos(det);
194 //_____________________________________________________________________________
195 Bool_t AliTRDcalibDB::GetChamberRot(Int_t det, Float_t* xyz)
198 // Returns the rotation of the chamber from the nominal position.
201 AliTRDCalChamberPos* chamber = dynamic_cast<AliTRDCalChamberPos*>(GetCachedCDBObject(kIDChamber));
205 const Float_t* kvalues = chamber->GetChamberRot(det);
216 //_____________________________________________________________________________
217 Bool_t AliTRDcalibDB::GetStackPos(Int_t chamber, Int_t sector, Float_t* xyz)
220 // Returns the deviation of the stack position from the nominal position.
223 AliTRDCalStackPos* stack = dynamic_cast<AliTRDCalStackPos*>(GetCachedCDBObject(kIDStack));
227 const Float_t* kvalues = stack->GetStackPos(chamber, sector);
238 //_____________________________________________________________________________
239 Bool_t AliTRDcalibDB::GetStackRot(Int_t chamber, Int_t sector, Float_t* xyz)
242 // Returns the rotation of the stack from the nominal position.
245 AliTRDCalStackPos* stack = dynamic_cast<AliTRDCalStackPos*>(GetCachedCDBObject(kIDStack));
249 const Float_t* kvalues = stack->GetStackRot(chamber, sector);
260 //_____________________________________________________________________________
261 Float_t AliTRDcalibDB::GetVdrift(Int_t det, Int_t col, Int_t row)
264 // Returns the drift velocity for the given pad.
267 AliTRDCalPad* calPad = dynamic_cast<AliTRDCalPad*> (GetCachedCDBObject(kIDVdrift));
271 AliTRDCalROC* roc = calPad->GetCalROC(det);
275 return roc->GetValue(col, row);
278 //_____________________________________________________________________________
279 Float_t AliTRDcalibDB::GetT0(Int_t det, Int_t col, Int_t row)
282 // Returns t0 for the given pad.
285 AliTRDCalPad* calPad = dynamic_cast<AliTRDCalPad*> (GetCachedCDBObject(kIDT0));
289 AliTRDCalROC* roc = calPad->GetCalROC(det);
293 return roc->GetValue(col, row);
296 //_____________________________________________________________________________
297 Float_t AliTRDcalibDB::GetGainFactor(Int_t det, Int_t col, Int_t row)
300 // Returns the gain factor for the given pad.
303 AliTRDCalPad* calPad = dynamic_cast<AliTRDCalPad*> (GetCachedCDBObject(kIDGainFactor));
307 AliTRDCalROC* roc = calPad->GetCalROC(det);
311 return roc->GetValue(col, row);
314 //_____________________________________________________________________________
315 Float_t AliTRDcalibDB::GetPRFWidth(Int_t det, Int_t col, Int_t row)
318 // Returns the PRF width for the given pad.
321 AliTRDCalPad* calPad = dynamic_cast<AliTRDCalPad*> (GetCachedCDBObject(kIDPRFWidth));
325 AliTRDCalROC* roc = calPad->GetCalROC(det);
329 return roc->GetValue(col, row);
332 //_____________________________________________________________________________
333 Float_t AliTRDcalibDB::GetSamplingFrequency()
336 // Returns the sampling frequency of the TRD read-out.
339 AliTRDCalGlobals* calGlobal = dynamic_cast<AliTRDCalGlobals*> (GetCachedCDBObject(kIDGlobals));
343 return calGlobal->GetSamplingFrequency();
346 //_____________________________________________________________________________
347 Int_t AliTRDcalibDB::GetNumberOfTimeBins()
350 // Returns the number of time bins which are read-out.
353 AliTRDCalGlobals* calGlobal = dynamic_cast<AliTRDCalGlobals*> (GetCachedCDBObject(kIDGlobals));
357 return calGlobal->GetNumberOfTimeBins();
360 //_____________________________________________________________________________
361 AliTRDCalPIDLQ* AliTRDcalibDB::GetPIDLQObject()
364 // Returns the object storing the distributions for PID with likelihood
368 /*AliTRDCalPIDLQ* pid = new AliTRDCalPIDLQ();
369 pid->ReadData("$ALICE_ROOT/TRD/TRDdEdxHistogramsV1.root");
372 // TODO due to a bug in the CDB this does not work yet
373 return dynamic_cast<AliTRDCalPIDLQ*> (GetCachedCDBObject(kIDPIDLQ));
376 //_____________________________________________________________________________
377 Float_t AliTRDcalibDB::GetOmegaTau(Float_t vdrift)
380 // Returns omega*tau (tan(Lorentz-angle)) for a given drift velocity <vd>
381 // and a B-field <b> for Xe/CO2 (15%).
382 // The values are according to a GARFIELD simulation.
384 // This function basically does not belong to the calibration class. It should be moved somewhere else.
385 // However, currently it is in use by simulation and reconstruction.
388 AliTRDCommonParam* commonParam = AliTRDCommonParam::Instance();
391 Float_t field = commonParam->GetField();
394 Float_t p0[kNb] = { 0.004810, 0.007412, 0.010252, 0.013409, 0.016888 };
395 Float_t p1[kNb] = { 0.054875, 0.081534, 0.107333, 0.131983, 0.155455 };
396 Float_t p2[kNb] = { -0.008682, -0.012896, -0.016987, -0.020880, -0.024623 };
397 Float_t p3[kNb] = { 0.000155, 0.000238, 0.000330, 0.000428, 0.000541 };
399 Int_t ib = ((Int_t) (10 * (field - 0.15)));
400 ib = TMath::Max( 0,ib);
401 ib = TMath::Min(kNb,ib);
403 Float_t alphaL = p0[ib]
405 + p2[ib] * vdrift*vdrift
406 + p3[ib] * vdrift*vdrift*vdrift;
408 return TMath::Tan(alphaL);
411 //_____________________________________________________________________________
412 void AliTRDcalibDB::SamplePRF()
415 // Samples the pad response function
418 const Int_t kPRFbin = 61;
420 Float_t prf[kNplan][kPRFbin] = { {2.9037e-02, 3.3608e-02, 3.9020e-02, 4.5292e-02,
421 5.2694e-02, 6.1362e-02, 7.1461e-02, 8.3362e-02,
422 9.7063e-02, 1.1307e-01, 1.3140e-01, 1.5235e-01,
423 1.7623e-01, 2.0290e-01, 2.3294e-01, 2.6586e-01,
424 3.0177e-01, 3.4028e-01, 3.8077e-01, 4.2267e-01,
425 4.6493e-01, 5.0657e-01, 5.4655e-01, 5.8397e-01,
426 6.1767e-01, 6.4744e-01, 6.7212e-01, 6.9188e-01,
427 7.0627e-01, 7.1499e-01, 7.1851e-01, 7.1499e-01,
428 7.0627e-01, 6.9188e-01, 6.7212e-01, 6.4744e-01,
429 6.1767e-01, 5.8397e-01, 5.4655e-01, 5.0657e-01,
430 4.6493e-01, 4.2267e-01, 3.8077e-01, 3.4028e-01,
431 3.0177e-01, 2.6586e-01, 2.3294e-01, 2.0290e-01,
432 1.7623e-01, 1.5235e-01, 1.3140e-01, 1.1307e-01,
433 9.7063e-02, 8.3362e-02, 7.1461e-02, 6.1362e-02,
434 5.2694e-02, 4.5292e-02, 3.9020e-02, 3.3608e-02,
436 {2.5478e-02, 2.9695e-02, 3.4655e-02, 4.0454e-02,
437 4.7342e-02, 5.5487e-02, 6.5038e-02, 7.6378e-02,
438 8.9696e-02, 1.0516e-01, 1.2327e-01, 1.4415e-01,
439 1.6794e-01, 1.9516e-01, 2.2573e-01, 2.5959e-01,
440 2.9694e-01, 3.3719e-01, 3.7978e-01, 4.2407e-01,
441 4.6889e-01, 5.1322e-01, 5.5569e-01, 5.9535e-01,
442 6.3141e-01, 6.6259e-01, 6.8882e-01, 7.0983e-01,
443 7.2471e-01, 7.3398e-01, 7.3761e-01, 7.3398e-01,
444 7.2471e-01, 7.0983e-01, 6.8882e-01, 6.6259e-01,
445 6.3141e-01, 5.9535e-01, 5.5569e-01, 5.1322e-01,
446 4.6889e-01, 4.2407e-01, 3.7978e-01, 3.3719e-01,
447 2.9694e-01, 2.5959e-01, 2.2573e-01, 1.9516e-01,
448 1.6794e-01, 1.4415e-01, 1.2327e-01, 1.0516e-01,
449 8.9696e-02, 7.6378e-02, 6.5038e-02, 5.5487e-02,
450 4.7342e-02, 4.0454e-02, 3.4655e-02, 2.9695e-02,
452 {2.2363e-02, 2.6233e-02, 3.0782e-02, 3.6140e-02,
453 4.2535e-02, 5.0157e-02, 5.9197e-02, 6.9900e-02,
454 8.2707e-02, 9.7811e-02, 1.1548e-01, 1.3601e-01,
455 1.5998e-01, 1.8739e-01, 2.1840e-01, 2.5318e-01,
456 2.9182e-01, 3.3373e-01, 3.7837e-01, 4.2498e-01,
457 4.7235e-01, 5.1918e-01, 5.6426e-01, 6.0621e-01,
458 6.4399e-01, 6.7700e-01, 7.0472e-01, 7.2637e-01,
459 7.4206e-01, 7.5179e-01, 7.5551e-01, 7.5179e-01,
460 7.4206e-01, 7.2637e-01, 7.0472e-01, 6.7700e-01,
461 6.4399e-01, 6.0621e-01, 5.6426e-01, 5.1918e-01,
462 4.7235e-01, 4.2498e-01, 3.7837e-01, 3.3373e-01,
463 2.9182e-01, 2.5318e-01, 2.1840e-01, 1.8739e-01,
464 1.5998e-01, 1.3601e-01, 1.1548e-01, 9.7811e-02,
465 8.2707e-02, 6.9900e-02, 5.9197e-02, 5.0157e-02,
466 4.2535e-02, 3.6140e-02, 3.0782e-02, 2.6233e-02,
468 {1.9635e-02, 2.3167e-02, 2.7343e-02, 3.2293e-02,
469 3.8224e-02, 4.5335e-02, 5.3849e-02, 6.4039e-02,
470 7.6210e-02, 9.0739e-02, 1.0805e-01, 1.2841e-01,
471 1.5216e-01, 1.7960e-01, 2.1099e-01, 2.4671e-01,
472 2.8647e-01, 3.2996e-01, 3.7660e-01, 4.2547e-01,
473 4.7536e-01, 5.2473e-01, 5.7215e-01, 6.1632e-01,
474 6.5616e-01, 6.9075e-01, 7.1939e-01, 7.4199e-01,
475 7.5838e-01, 7.6848e-01, 7.7227e-01, 7.6848e-01,
476 7.5838e-01, 7.4199e-01, 7.1939e-01, 6.9075e-01,
477 6.5616e-01, 6.1632e-01, 5.7215e-01, 5.2473e-01,
478 4.7536e-01, 4.2547e-01, 3.7660e-01, 3.2996e-01,
479 2.8647e-01, 2.4671e-01, 2.1099e-01, 1.7960e-01,
480 1.5216e-01, 1.2841e-01, 1.0805e-01, 9.0739e-02,
481 7.6210e-02, 6.4039e-02, 5.3849e-02, 4.5335e-02,
482 3.8224e-02, 3.2293e-02, 2.7343e-02, 2.3167e-02,
484 {1.7224e-02, 2.0450e-02, 2.4286e-02, 2.8860e-02,
485 3.4357e-02, 4.0979e-02, 4.8966e-02, 5.8612e-02,
486 7.0253e-02, 8.4257e-02, 1.0102e-01, 1.2094e-01,
487 1.4442e-01, 1.7196e-01, 2.0381e-01, 2.4013e-01,
488 2.8093e-01, 3.2594e-01, 3.7450e-01, 4.2563e-01,
489 4.7796e-01, 5.2991e-01, 5.7974e-01, 6.2599e-01,
490 6.6750e-01, 7.0344e-01, 7.3329e-01, 7.5676e-01,
491 7.7371e-01, 7.8410e-01, 7.8793e-01, 7.8410e-01,
492 7.7371e-01, 7.5676e-01, 7.3329e-01, 7.0344e-01,
493 6.6750e-01, 6.2599e-01, 5.7974e-01, 5.2991e-01,
494 4.7796e-01, 4.2563e-01, 3.7450e-01, 3.2594e-01,
495 2.8093e-01, 2.4013e-01, 2.0381e-01, 1.7196e-01,
496 1.4442e-01, 1.2094e-01, 1.0102e-01, 8.4257e-02,
497 7.0253e-02, 5.8612e-02, 4.8966e-02, 4.0979e-02,
498 3.4357e-02, 2.8860e-02, 2.4286e-02, 2.0450e-02,
500 {1.5096e-02, 1.8041e-02, 2.1566e-02, 2.5793e-02,
501 3.0886e-02, 3.7044e-02, 4.4515e-02, 5.3604e-02,
502 6.4668e-02, 7.8109e-02, 9.4364e-02, 1.1389e-01,
503 1.3716e-01, 1.6461e-01, 1.9663e-01, 2.3350e-01,
504 2.7527e-01, 3.2170e-01, 3.7214e-01, 4.2549e-01,
505 4.8024e-01, 5.3460e-01, 5.8677e-01, 6.3512e-01,
506 6.7838e-01, 7.1569e-01, 7.4655e-01, 7.7071e-01,
507 7.8810e-01, 7.9871e-01, 8.0255e-01, 7.9871e-01,
508 7.8810e-01, 7.7071e-01, 7.4655e-01, 7.1569e-01,
509 6.7838e-01, 6.3512e-01, 5.8677e-01, 5.3460e-01,
510 4.8024e-01, 4.2549e-01, 3.7214e-01, 3.2170e-01,
511 2.7527e-01, 2.3350e-01, 1.9663e-01, 1.6461e-01,
512 1.3716e-01, 1.1389e-01, 9.4364e-02, 7.8109e-02,
513 6.4668e-02, 5.3604e-02, 4.4515e-02, 3.7044e-02,
514 3.0886e-02, 2.5793e-02, 2.1566e-02, 1.8041e-02,
517 // More sampling precision with linear interpolation
518 fPadResponse.fPRFlo = -1.5;
519 fPadResponse.fPRFhi = 1.5;
520 Float_t pad[kPRFbin];
521 Int_t sPRFbin = kPRFbin;
522 Float_t sPRFwid = (fPadResponse.fPRFhi - fPadResponse.fPRFlo) / ((Float_t) sPRFbin);
523 for (Int_t iPad = 0; iPad < sPRFbin; iPad++) {
524 pad[iPad] = ((Float_t) iPad + 0.5) * sPRFwid + fPadResponse.fPRFlo;
526 fPadResponse.fPRFbin = 500;
527 fPadResponse.fPRFwid = (fPadResponse.fPRFhi - fPadResponse.fPRFlo) / ((Float_t) fPadResponse.fPRFbin);
528 fPadResponse.fPRFpad = ((Int_t) (1.0 / fPadResponse.fPRFwid));
530 if (fPadResponse.fPRFsmp) delete [] fPadResponse.fPRFsmp;
531 fPadResponse.fPRFsmp = new Float_t[kNplan*fPadResponse.fPRFbin];
537 for (Int_t iPla = 0; iPla < kNplan; iPla++) {
539 for (Int_t iBin = 0; iBin < fPadResponse.fPRFbin; iBin++) {
541 Float_t bin = (((Float_t) iBin) + 0.5) * fPadResponse.fPRFwid + fPadResponse.fPRFlo;
545 diff = bin - pad[ipos2++];
546 } while ((diff > 0) && (ipos2 < kPRFbin));
547 if (ipos2 == kPRFbin) {
548 fPadResponse.fPRFsmp[iPla*fPadResponse.fPRFbin+iBin] = prf[iPla][ipos2-1];
550 else if (ipos2 == 1) {
551 fPadResponse.fPRFsmp[iPla*fPadResponse.fPRFbin+iBin] = prf[iPla][ipos2-1];
555 if (ipos2 >= kPRFbin) ipos2 = kPRFbin - 1;
557 fPadResponse.fPRFsmp[iPla*fPadResponse.fPRFbin+iBin] = prf[iPla][ipos2]
558 + diff * (prf[iPla][ipos2] - prf[iPla][ipos1])
567 //_____________________________________________________________________________
568 Int_t AliTRDcalibDB::PadResponse(Double_t signal, Double_t dist
569 , Int_t plane, Double_t *pad) const
572 // Applies the pad response
575 Int_t iBin = ((Int_t) (( - dist - fPadResponse.fPRFlo) / fPadResponse.fPRFwid));
576 Int_t iOff = plane * fPadResponse.fPRFbin;
578 Int_t iBin0 = iBin - fPadResponse.fPRFpad + iOff;
579 Int_t iBin1 = iBin + iOff;
580 Int_t iBin2 = iBin + fPadResponse.fPRFpad + iOff;
585 if ((iBin1 >= 0) && (iBin1 < (fPadResponse.fPRFbin*kNplan))) {
588 pad[0] = signal * fPadResponse.fPRFsmp[iBin0];
590 pad[1] = signal * fPadResponse.fPRFsmp[iBin1];
591 if (iBin2 < (fPadResponse.fPRFbin*kNplan)) {
592 pad[2] = signal * fPadResponse.fPRFsmp[iBin2];