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()
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 AliCDBManager* manager = AliCDBManager::Instance();
98 std::cout << "Failed to get instance of AliCDBManager." << std::endl;
102 fLocator = manager->GetStorage("local://$ALICE_ROOT");
104 for (Int_t i=0; i<kCDBCacheSize; ++i)
111 //_____________________________________________________________________________
112 AliTRDcalibDB::~AliTRDcalibDB()
121 //_____________________________________________________________________________
122 void AliTRDcalibDB::SetRun(Long64_t run)
125 // Sets current run number. Calibration data is read from the corresponding file.
126 // When the run number changes the caching is invalidated.
136 //_____________________________________________________________________________
137 void AliTRDcalibDB::Invalidate()
140 // Invalidates cache (when run number is changed).
143 for (Int_t i=0; i<kCDBCacheSize; ++i)
147 if (fCDBEntries[i]->IsOwner() != kFALSE && fCDBCache[i])
149 delete fCDBEntries[i];
156 //_____________________________________________________________________________
157 Bool_t AliTRDcalibDB::GetChamberPos(Int_t det, Float_t* xyz)
160 // Returns the deviation of the chamber position from the nominal position.
163 AliTRDCalChamber* chamber = dynamic_cast<AliTRDCalChamber*>(GetCachedCDBObject(kIDChamber));
167 const Float_t* kvalues = chamber->GetChamberPos(det);
178 //_____________________________________________________________________________
179 Bool_t AliTRDcalibDB::GetChamberRot(Int_t det, Float_t* xyz)
182 // Returns the rotation of the chamber from the nominal position.
185 AliTRDCalChamber* chamber = dynamic_cast<AliTRDCalChamber*>(GetCachedCDBObject(kIDChamber));
189 const Float_t* kvalues = chamber->GetChamberRot(det);
200 //_____________________________________________________________________________
201 Bool_t AliTRDcalibDB::GetStackPos(Int_t chamber, Int_t sector, Float_t* xyz)
204 // Returns the deviation of the stack position from the nominal position.
207 AliTRDCalStack* stack = dynamic_cast<AliTRDCalStack*>(GetCachedCDBObject(kIDStack));
211 const Float_t* kvalues = stack->GetStackPos(chamber, sector);
222 //_____________________________________________________________________________
223 Bool_t AliTRDcalibDB::GetStackRot(Int_t chamber, Int_t sector, Float_t* xyz)
226 // Returns the rotation of the stack from the nominal position.
229 AliTRDCalStack* stack = dynamic_cast<AliTRDCalStack*>(GetCachedCDBObject(kIDStack));
233 const Float_t* kvalues = stack->GetStackRot(chamber, sector);
244 //_____________________________________________________________________________
245 Float_t AliTRDcalibDB::GetVdrift(Int_t det, Int_t col, Int_t row)
248 // Returns the drift velocity for the given pad.
251 AliTRDCalPad* calPad = dynamic_cast<AliTRDCalPad*> (GetCachedCDBObject(kIDVdrift));
255 AliTRDCalROC* roc = calPad->GetCalROC(det);
259 return roc->GetValue(col, row);
262 //_____________________________________________________________________________
263 Float_t AliTRDcalibDB::GetT0(Int_t det, Int_t col, Int_t row)
266 // Returns t0 for the given pad.
269 AliTRDCalPad* calPad = dynamic_cast<AliTRDCalPad*> (GetCachedCDBObject(kIDT0));
273 AliTRDCalROC* roc = calPad->GetCalROC(det);
277 return roc->GetValue(col, row);
280 //_____________________________________________________________________________
281 Float_t AliTRDcalibDB::GetGainFactor(Int_t det, Int_t col, Int_t row)
284 // Returns the gain factor for the given pad.
287 AliTRDCalPad* calPad = dynamic_cast<AliTRDCalPad*> (GetCachedCDBObject(kIDGainFactor));
291 AliTRDCalROC* roc = calPad->GetCalROC(det);
295 return roc->GetValue(col, row);
298 //_____________________________________________________________________________
299 Float_t AliTRDcalibDB::GetSamplingFrequency()
302 // Returns the sampling frequency of the TRD read-out.
305 AliTRDCalGlobals* calGlobal = dynamic_cast<AliTRDCalGlobals*> (GetCachedCDBObject(kIDGlobals));
309 return calGlobal->GetSamplingFrequency();
312 //_____________________________________________________________________________
313 Int_t AliTRDcalibDB::GetNumberOfTimeBins()
316 // Returns the number of time bins which are read-out.
319 AliTRDCalGlobals* calGlobal = dynamic_cast<AliTRDCalGlobals*> (GetCachedCDBObject(kIDGlobals));
323 return calGlobal->GetNumberOfTimeBins();
326 //_____________________________________________________________________________
327 Float_t AliTRDcalibDB::GetOmegaTau(Float_t vdrift)
330 // Returns omega*tau (tan(Lorentz-angle)) for a given drift velocity <vd>
331 // and a B-field <b> for Xe/CO2 (15%).
332 // The values are according to a GARFIELD simulation.
334 // This function basically does not belong to the calibration class. It should be moved somewhere else.
335 // However, currently it is in use by simulation and reconstruction.
338 AliTRDCommonParam* commonParam = AliTRDCommonParam::Instance();
341 Float_t field = commonParam->GetField();
344 Float_t p0[kNb] = { 0.004810, 0.007412, 0.010252, 0.013409, 0.016888 };
345 Float_t p1[kNb] = { 0.054875, 0.081534, 0.107333, 0.131983, 0.155455 };
346 Float_t p2[kNb] = { -0.008682, -0.012896, -0.016987, -0.020880, -0.024623 };
347 Float_t p3[kNb] = { 0.000155, 0.000238, 0.000330, 0.000428, 0.000541 };
349 Int_t ib = ((Int_t) (10 * (field - 0.15)));
350 ib = TMath::Max( 0,ib);
351 ib = TMath::Min(kNb,ib);
353 Float_t alphaL = p0[ib]
355 + p2[ib] * vdrift*vdrift
356 + p3[ib] * vdrift*vdrift*vdrift;
358 return TMath::Tan(alphaL);