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 "AliTRDCalChamber.h"
39 #include "AliTRDCalStack.h"
40 #include "AliTRDCalPad.h"
41 #include "AliTRDCalDet.h"
42 #include "AliTRDCalGlobals.h"
44 ClassImp(AliTRDcalibDB)
46 AliTRDcalibDB* AliTRDcalibDB::fgInstance = 0;
47 Bool_t AliTRDcalibDB::fgTerminated = kFALSE;
49 //_ singleton implementation __________________________________________________
50 AliTRDcalibDB* AliTRDcalibDB::Instance()
53 // Singleton implementation
54 // Returns an instance of this class, it is created if neccessary
57 if (fgTerminated != kFALSE)
61 fgInstance = new AliTRDcalibDB();
66 void AliTRDcalibDB::Terminate()
69 // Singleton implementation
70 // Deletes the instance of this class and sets the terminated flag, instances cannot be requested anymore
71 // This function can be called several times.
83 //_____________________________________________________________________________
84 AliTRDcalibDB::AliTRDcalibDB()
90 // TODO Default runnumber is set to 0, this should be changed later to an invalid value (e.g. -1) to prevent
91 // TODO invalid calibration data to be used.
94 fPadResponse.fPRFbin = 0;
95 fPadResponse.fPRFlo = 0.0;
96 fPadResponse.fPRFhi = 0.0;
97 fPadResponse.fPRFwid = 0.0;
98 fPadResponse.fPRFpad = 0;
99 fPadResponse.fPRFsmp = 0;
101 AliCDBManager* manager = AliCDBManager::Instance();
104 std::cout << "AliTRDcalibDB: CRITICAL: Failed to get instance of AliCDBManager." << std::endl;
108 fLocator = manager->GetStorage("local://$ALICE_ROOT");
110 for (Int_t i=0; i<kCDBCacheSize; ++i)
116 // Create the sampled PRF
120 //_____________________________________________________________________________
121 AliTRDcalibDB::~AliTRDcalibDB()
127 if (fPadResponse.fPRFsmp) {
128 delete [] fPadResponse.fPRFsmp;
129 fPadResponse.fPRFsmp = 0;
135 //_____________________________________________________________________________
136 void AliTRDcalibDB::SetRun(Long64_t run)
139 // Sets current run number. Calibration data is read from the corresponding file.
140 // When the run number changes the caching is invalidated.
150 //_____________________________________________________________________________
151 void AliTRDcalibDB::Invalidate()
154 // Invalidates cache (when run number is changed).
157 for (Int_t i=0; i<kCDBCacheSize; ++i)
161 if (fCDBEntries[i]->IsOwner() == kFALSE && fCDBCache[i])
164 delete fCDBEntries[i];
171 //_____________________________________________________________________________
172 Bool_t AliTRDcalibDB::GetChamberPos(Int_t det, Float_t* xyz)
175 // Returns the deviation of the chamber position from the nominal position.
178 AliTRDCalChamber* chamber = dynamic_cast<AliTRDCalChamber*>(GetCachedCDBObject(kIDChamber));
182 const Float_t* kvalues = chamber->GetChamberPos(det);
193 //_____________________________________________________________________________
194 Bool_t AliTRDcalibDB::GetChamberRot(Int_t det, Float_t* xyz)
197 // Returns the rotation of the chamber from the nominal position.
200 AliTRDCalChamber* chamber = dynamic_cast<AliTRDCalChamber*>(GetCachedCDBObject(kIDChamber));
204 const Float_t* kvalues = chamber->GetChamberRot(det);
215 //_____________________________________________________________________________
216 Bool_t AliTRDcalibDB::GetStackPos(Int_t chamber, Int_t sector, Float_t* xyz)
219 // Returns the deviation of the stack position from the nominal position.
222 AliTRDCalStack* stack = dynamic_cast<AliTRDCalStack*>(GetCachedCDBObject(kIDStack));
226 const Float_t* kvalues = stack->GetStackPos(chamber, sector);
237 //_____________________________________________________________________________
238 Bool_t AliTRDcalibDB::GetStackRot(Int_t chamber, Int_t sector, Float_t* xyz)
241 // Returns the rotation of the stack from the nominal position.
244 AliTRDCalStack* stack = dynamic_cast<AliTRDCalStack*>(GetCachedCDBObject(kIDStack));
248 const Float_t* kvalues = stack->GetStackRot(chamber, sector);
259 //_____________________________________________________________________________
260 Float_t AliTRDcalibDB::GetVdrift(Int_t det, Int_t col, Int_t row)
263 // Returns the drift velocity for the given pad.
266 AliTRDCalPad* calPad = dynamic_cast<AliTRDCalPad*> (GetCachedCDBObject(kIDVdrift));
270 AliTRDCalROC* roc = calPad->GetCalROC(det);
274 return roc->GetValue(col, row);
277 //_____________________________________________________________________________
278 Float_t AliTRDcalibDB::GetT0(Int_t det, Int_t col, Int_t row)
281 // Returns t0 for the given pad.
284 AliTRDCalPad* calPad = dynamic_cast<AliTRDCalPad*> (GetCachedCDBObject(kIDT0));
288 AliTRDCalROC* roc = calPad->GetCalROC(det);
292 return roc->GetValue(col, row);
295 //_____________________________________________________________________________
296 Float_t AliTRDcalibDB::GetGainFactor(Int_t det, Int_t col, Int_t row)
299 // Returns the gain factor for the given pad.
302 AliTRDCalPad* calPad = dynamic_cast<AliTRDCalPad*> (GetCachedCDBObject(kIDGainFactor));
306 AliTRDCalROC* roc = calPad->GetCalROC(det);
310 return roc->GetValue(col, row);
313 //_____________________________________________________________________________
314 Float_t AliTRDcalibDB::GetPRFWidth(Int_t det, Int_t col, Int_t row)
317 // Returns the PRF width for the given pad.
320 AliTRDCalPad* calPad = dynamic_cast<AliTRDCalPad*> (GetCachedCDBObject(kIDPRFWidth));
324 AliTRDCalROC* roc = calPad->GetCalROC(det);
328 return roc->GetValue(col, row);
331 //_____________________________________________________________________________
332 Float_t AliTRDcalibDB::GetSamplingFrequency()
335 // Returns the sampling frequency of the TRD read-out.
338 AliTRDCalGlobals* calGlobal = dynamic_cast<AliTRDCalGlobals*> (GetCachedCDBObject(kIDGlobals));
342 return calGlobal->GetSamplingFrequency();
345 //_____________________________________________________________________________
346 Int_t AliTRDcalibDB::GetNumberOfTimeBins()
349 // Returns the number of time bins which are read-out.
352 AliTRDCalGlobals* calGlobal = dynamic_cast<AliTRDCalGlobals*> (GetCachedCDBObject(kIDGlobals));
356 return calGlobal->GetNumberOfTimeBins();
359 //_____________________________________________________________________________
360 Float_t AliTRDcalibDB::GetOmegaTau(Float_t vdrift)
363 // Returns omega*tau (tan(Lorentz-angle)) for a given drift velocity <vd>
364 // and a B-field <b> for Xe/CO2 (15%).
365 // The values are according to a GARFIELD simulation.
367 // This function basically does not belong to the calibration class. It should be moved somewhere else.
368 // However, currently it is in use by simulation and reconstruction.
371 AliTRDCommonParam* commonParam = AliTRDCommonParam::Instance();
374 Float_t field = commonParam->GetField();
377 Float_t p0[kNb] = { 0.004810, 0.007412, 0.010252, 0.013409, 0.016888 };
378 Float_t p1[kNb] = { 0.054875, 0.081534, 0.107333, 0.131983, 0.155455 };
379 Float_t p2[kNb] = { -0.008682, -0.012896, -0.016987, -0.020880, -0.024623 };
380 Float_t p3[kNb] = { 0.000155, 0.000238, 0.000330, 0.000428, 0.000541 };
382 Int_t ib = ((Int_t) (10 * (field - 0.15)));
383 ib = TMath::Max( 0,ib);
384 ib = TMath::Min(kNb,ib);
386 Float_t alphaL = p0[ib]
388 + p2[ib] * vdrift*vdrift
389 + p3[ib] * vdrift*vdrift*vdrift;
391 return TMath::Tan(alphaL);
394 //_____________________________________________________________________________
395 void AliTRDcalibDB::SamplePRF()
398 // Samples the pad response function
401 const Int_t kPRFbin = 61;
403 Float_t prf[kNplan][kPRFbin] = { {2.9037e-02, 3.3608e-02, 3.9020e-02, 4.5292e-02,
404 5.2694e-02, 6.1362e-02, 7.1461e-02, 8.3362e-02,
405 9.7063e-02, 1.1307e-01, 1.3140e-01, 1.5235e-01,
406 1.7623e-01, 2.0290e-01, 2.3294e-01, 2.6586e-01,
407 3.0177e-01, 3.4028e-01, 3.8077e-01, 4.2267e-01,
408 4.6493e-01, 5.0657e-01, 5.4655e-01, 5.8397e-01,
409 6.1767e-01, 6.4744e-01, 6.7212e-01, 6.9188e-01,
410 7.0627e-01, 7.1499e-01, 7.1851e-01, 7.1499e-01,
411 7.0627e-01, 6.9188e-01, 6.7212e-01, 6.4744e-01,
412 6.1767e-01, 5.8397e-01, 5.4655e-01, 5.0657e-01,
413 4.6493e-01, 4.2267e-01, 3.8077e-01, 3.4028e-01,
414 3.0177e-01, 2.6586e-01, 2.3294e-01, 2.0290e-01,
415 1.7623e-01, 1.5235e-01, 1.3140e-01, 1.1307e-01,
416 9.7063e-02, 8.3362e-02, 7.1461e-02, 6.1362e-02,
417 5.2694e-02, 4.5292e-02, 3.9020e-02, 3.3608e-02,
419 {2.5478e-02, 2.9695e-02, 3.4655e-02, 4.0454e-02,
420 4.7342e-02, 5.5487e-02, 6.5038e-02, 7.6378e-02,
421 8.9696e-02, 1.0516e-01, 1.2327e-01, 1.4415e-01,
422 1.6794e-01, 1.9516e-01, 2.2573e-01, 2.5959e-01,
423 2.9694e-01, 3.3719e-01, 3.7978e-01, 4.2407e-01,
424 4.6889e-01, 5.1322e-01, 5.5569e-01, 5.9535e-01,
425 6.3141e-01, 6.6259e-01, 6.8882e-01, 7.0983e-01,
426 7.2471e-01, 7.3398e-01, 7.3761e-01, 7.3398e-01,
427 7.2471e-01, 7.0983e-01, 6.8882e-01, 6.6259e-01,
428 6.3141e-01, 5.9535e-01, 5.5569e-01, 5.1322e-01,
429 4.6889e-01, 4.2407e-01, 3.7978e-01, 3.3719e-01,
430 2.9694e-01, 2.5959e-01, 2.2573e-01, 1.9516e-01,
431 1.6794e-01, 1.4415e-01, 1.2327e-01, 1.0516e-01,
432 8.9696e-02, 7.6378e-02, 6.5038e-02, 5.5487e-02,
433 4.7342e-02, 4.0454e-02, 3.4655e-02, 2.9695e-02,
435 {2.2363e-02, 2.6233e-02, 3.0782e-02, 3.6140e-02,
436 4.2535e-02, 5.0157e-02, 5.9197e-02, 6.9900e-02,
437 8.2707e-02, 9.7811e-02, 1.1548e-01, 1.3601e-01,
438 1.5998e-01, 1.8739e-01, 2.1840e-01, 2.5318e-01,
439 2.9182e-01, 3.3373e-01, 3.7837e-01, 4.2498e-01,
440 4.7235e-01, 5.1918e-01, 5.6426e-01, 6.0621e-01,
441 6.4399e-01, 6.7700e-01, 7.0472e-01, 7.2637e-01,
442 7.4206e-01, 7.5179e-01, 7.5551e-01, 7.5179e-01,
443 7.4206e-01, 7.2637e-01, 7.0472e-01, 6.7700e-01,
444 6.4399e-01, 6.0621e-01, 5.6426e-01, 5.1918e-01,
445 4.7235e-01, 4.2498e-01, 3.7837e-01, 3.3373e-01,
446 2.9182e-01, 2.5318e-01, 2.1840e-01, 1.8739e-01,
447 1.5998e-01, 1.3601e-01, 1.1548e-01, 9.7811e-02,
448 8.2707e-02, 6.9900e-02, 5.9197e-02, 5.0157e-02,
449 4.2535e-02, 3.6140e-02, 3.0782e-02, 2.6233e-02,
451 {1.9635e-02, 2.3167e-02, 2.7343e-02, 3.2293e-02,
452 3.8224e-02, 4.5335e-02, 5.3849e-02, 6.4039e-02,
453 7.6210e-02, 9.0739e-02, 1.0805e-01, 1.2841e-01,
454 1.5216e-01, 1.7960e-01, 2.1099e-01, 2.4671e-01,
455 2.8647e-01, 3.2996e-01, 3.7660e-01, 4.2547e-01,
456 4.7536e-01, 5.2473e-01, 5.7215e-01, 6.1632e-01,
457 6.5616e-01, 6.9075e-01, 7.1939e-01, 7.4199e-01,
458 7.5838e-01, 7.6848e-01, 7.7227e-01, 7.6848e-01,
459 7.5838e-01, 7.4199e-01, 7.1939e-01, 6.9075e-01,
460 6.5616e-01, 6.1632e-01, 5.7215e-01, 5.2473e-01,
461 4.7536e-01, 4.2547e-01, 3.7660e-01, 3.2996e-01,
462 2.8647e-01, 2.4671e-01, 2.1099e-01, 1.7960e-01,
463 1.5216e-01, 1.2841e-01, 1.0805e-01, 9.0739e-02,
464 7.6210e-02, 6.4039e-02, 5.3849e-02, 4.5335e-02,
465 3.8224e-02, 3.2293e-02, 2.7343e-02, 2.3167e-02,
467 {1.7224e-02, 2.0450e-02, 2.4286e-02, 2.8860e-02,
468 3.4357e-02, 4.0979e-02, 4.8966e-02, 5.8612e-02,
469 7.0253e-02, 8.4257e-02, 1.0102e-01, 1.2094e-01,
470 1.4442e-01, 1.7196e-01, 2.0381e-01, 2.4013e-01,
471 2.8093e-01, 3.2594e-01, 3.7450e-01, 4.2563e-01,
472 4.7796e-01, 5.2991e-01, 5.7974e-01, 6.2599e-01,
473 6.6750e-01, 7.0344e-01, 7.3329e-01, 7.5676e-01,
474 7.7371e-01, 7.8410e-01, 7.8793e-01, 7.8410e-01,
475 7.7371e-01, 7.5676e-01, 7.3329e-01, 7.0344e-01,
476 6.6750e-01, 6.2599e-01, 5.7974e-01, 5.2991e-01,
477 4.7796e-01, 4.2563e-01, 3.7450e-01, 3.2594e-01,
478 2.8093e-01, 2.4013e-01, 2.0381e-01, 1.7196e-01,
479 1.4442e-01, 1.2094e-01, 1.0102e-01, 8.4257e-02,
480 7.0253e-02, 5.8612e-02, 4.8966e-02, 4.0979e-02,
481 3.4357e-02, 2.8860e-02, 2.4286e-02, 2.0450e-02,
483 {1.5096e-02, 1.8041e-02, 2.1566e-02, 2.5793e-02,
484 3.0886e-02, 3.7044e-02, 4.4515e-02, 5.3604e-02,
485 6.4668e-02, 7.8109e-02, 9.4364e-02, 1.1389e-01,
486 1.3716e-01, 1.6461e-01, 1.9663e-01, 2.3350e-01,
487 2.7527e-01, 3.2170e-01, 3.7214e-01, 4.2549e-01,
488 4.8024e-01, 5.3460e-01, 5.8677e-01, 6.3512e-01,
489 6.7838e-01, 7.1569e-01, 7.4655e-01, 7.7071e-01,
490 7.8810e-01, 7.9871e-01, 8.0255e-01, 7.9871e-01,
491 7.8810e-01, 7.7071e-01, 7.4655e-01, 7.1569e-01,
492 6.7838e-01, 6.3512e-01, 5.8677e-01, 5.3460e-01,
493 4.8024e-01, 4.2549e-01, 3.7214e-01, 3.2170e-01,
494 2.7527e-01, 2.3350e-01, 1.9663e-01, 1.6461e-01,
495 1.3716e-01, 1.1389e-01, 9.4364e-02, 7.8109e-02,
496 6.4668e-02, 5.3604e-02, 4.4515e-02, 3.7044e-02,
497 3.0886e-02, 2.5793e-02, 2.1566e-02, 1.8041e-02,
500 // More sampling precision with linear interpolation
501 fPadResponse.fPRFlo = -1.5;
502 fPadResponse.fPRFhi = 1.5;
503 Float_t pad[kPRFbin];
504 Int_t sPRFbin = kPRFbin;
505 Float_t sPRFwid = (fPadResponse.fPRFhi - fPadResponse.fPRFlo) / ((Float_t) sPRFbin);
506 for (Int_t iPad = 0; iPad < sPRFbin; iPad++) {
507 pad[iPad] = ((Float_t) iPad + 0.5) * sPRFwid + fPadResponse.fPRFlo;
509 fPadResponse.fPRFbin = 500;
510 fPadResponse.fPRFwid = (fPadResponse.fPRFhi - fPadResponse.fPRFlo) / ((Float_t) fPadResponse.fPRFbin);
511 fPadResponse.fPRFpad = ((Int_t) (1.0 / fPadResponse.fPRFwid));
513 if (fPadResponse.fPRFsmp) delete [] fPadResponse.fPRFsmp;
514 fPadResponse.fPRFsmp = new Float_t[kNplan*fPadResponse.fPRFbin];
520 for (Int_t iPla = 0; iPla < kNplan; iPla++) {
522 for (Int_t iBin = 0; iBin < fPadResponse.fPRFbin; iBin++) {
524 Float_t bin = (((Float_t) iBin) + 0.5) * fPadResponse.fPRFwid + fPadResponse.fPRFlo;
528 diff = bin - pad[ipos2++];
529 } while ((diff > 0) && (ipos2 < kPRFbin));
530 if (ipos2 == kPRFbin) {
531 fPadResponse.fPRFsmp[iPla*fPadResponse.fPRFbin+iBin] = prf[iPla][ipos2-1];
533 else if (ipos2 == 1) {
534 fPadResponse.fPRFsmp[iPla*fPadResponse.fPRFbin+iBin] = prf[iPla][ipos2-1];
538 if (ipos2 >= kPRFbin) ipos2 = kPRFbin - 1;
540 fPadResponse.fPRFsmp[iPla*fPadResponse.fPRFbin+iBin] = prf[iPla][ipos2]
541 + diff * (prf[iPla][ipos2] - prf[iPla][ipos1])
550 //_____________________________________________________________________________
551 Int_t AliTRDcalibDB::PadResponse(Double_t signal, Double_t dist
552 , Int_t plane, Double_t *pad) const
555 // Applies the pad response
558 Int_t iBin = ((Int_t) (( - dist - fPadResponse.fPRFlo) / fPadResponse.fPRFwid));
559 Int_t iOff = plane * fPadResponse.fPRFbin;
561 Int_t iBin0 = iBin - fPadResponse.fPRFpad + iOff;
562 Int_t iBin1 = iBin + iOff;
563 Int_t iBin2 = iBin + fPadResponse.fPRFpad + iOff;
568 if ((iBin1 >= 0) && (iBin1 < (fPadResponse.fPRFbin*kNplan))) {
571 pad[0] = signal * fPadResponse.fPRFsmp[iBin0];
573 pad[1] = signal * fPadResponse.fPRFsmp[iBin1];
574 if (iBin2 < (fPadResponse.fPRFbin*kNplan)) {
575 pad[2] = signal * fPadResponse.fPRFsmp[iBin2];