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 **************************************************************************/
16 /*************************************************************************
18 * AliTOFcalibHisto - class to handle TOF calibration histograms,
19 * map histograms and more
22 * autors: Roberto Preghenella (R+)
23 * concacts: preghenella@bo.infn.it
25 *************************************************************************/
27 #include "AliTOFcalibHisto.h"
31 #include "AliTOFRawStream.h"
32 #include "AliTOFCableLengthMap.h"
33 #include "AliESDtrack.h"
35 #define SLEW_TOTMIN 10.
36 #define SLEW_TOTMAX 16.
38 ClassImp(AliTOFcalibHisto)
40 //__________________________________________________________________________
42 TFile *AliTOFcalibHisto::fgCalibHistoFile = NULL;
43 TFile *AliTOFcalibHisto::fgCalibParFile = NULL;
45 //__________________________________________________________________________
47 TString AliTOFcalibHisto::fgCalibHistoFileName = "$ALICE_ROOT/TOF/data/AliTOFcalibHisto.root";
48 TString AliTOFcalibHisto::fgCalibParFileName = "$ALICE_ROOT/TOF/data/AliTOFcalibPar.root";
50 //__________________________________________________________________________
52 const TString AliTOFcalibHisto::fgkCalibConstName[kNcalibConsts] = {
59 //__________________________________________________________________________
61 const TString AliTOFcalibHisto::fgkCalibMapName[kNcalibMaps] = {
82 "InterfaceCardLength",
86 //__________________________________________________________________________
88 const TString AliTOFcalibHisto::fgkCalibParName[kNcalibPars] = {
101 //__________________________________________________________________________
103 /* LHC clock period [ns] */
104 const Double_t AliTOFcalibHisto::fgkLHCperiod = (24.4e-3 * 1024); /* ns */
106 //__________________________________________________________________________
108 /* Amphenol cable delay [ns/cm] */
109 const Double_t AliTOFcalibHisto::fgkAmphenolCableDelay = 5.13e-2; /* from measurement */
111 //__________________________________________________________________________
113 /* flat cable delay [ns/cm] */
114 //const Double_t AliTOFcalibHisto::fgkFlatCableDelay = 5.3e-2; /* from Amphenol 132-2829 series data-sheet */
115 const Double_t AliTOFcalibHisto::fgkFlatCableDelay = 5.124e-2; /* from LHC08d calibration */
117 //__________________________________________________________________________
119 /* interface card delay [ns/cm] */
120 //const Double_t AliTOFcalibHisto::fgkInterfaceCardDelay = 6.9e-2; /* from HyperLinx simulation */
121 //const Double_t AliTOFcalibHisto::fgkInterfaceCardDelay = 5.7898e-2; /* from LHC08d calibration */
122 const Double_t AliTOFcalibHisto::fgkInterfaceCardDelay = 6.31360207815420404e-02; /* from LHC09c calibration */
124 //__________________________________________________________________________
126 /* number of readout channels (DO/EO) */
127 const Int_t AliTOFcalibHisto::fgkNchannels = 157248;
128 const Int_t AliTOFcalibHisto::fgkNchannelsEO = 172800;
130 //__________________________________________________________________________
132 /* DDL BC shifts due to TTC fibers [LHCperiod] */
133 const Int_t AliTOFcalibHisto::fgkDDLBCshift[72] = {
154 //__________________________________________________________________________
156 /* strip flat-cable length (preliminary) [cm] */
157 const Double_t AliTOFcalibHisto::fgkFlatCableLength[91] = {
158 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 17.,
159 21., 21., 21., 21., 21., 17., 17., 21., 21., 17., 21., 21., 21., 17., 21., 21., 17., 21., 23.,
160 17., 19., 17., 19., 17., 19., 17., 19., 17., 19., 17., 19., 17., 19., 17.,
161 23., 21., 17., 21., 21., 17., 21., 21., 21., 17., 21., 21., 17., 17., 21., 21., 21., 21., 21.,
162 17., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18.
165 //__________________________________________________________________________
167 /* interface card lenght (preliminary) [cm] */
168 const Double_t AliTOFcalibHisto::fgkInterfaceCardLength[48] = {
169 13.97, 12.57, 14.52, 13.10, 15.44, 13.60, 10.58, 9.14,
170 11.21, 9.76, 12.11, 10.76, 8.67, 7.58, 9.32, 8.09,
171 10.24, 8.4, 5.51, 4.31, 6.54, 5.23, 7.48, 6.28,
172 10.43, 8.76, 11.05, 9.43, 11.72, 10.14, 7.2, 5.69,
173 7.71, 6.26, 8.36, 7.19, 4.85, 4.09, 5.57, 4.35,
174 6.59, 5.12, 2.49, 2.96, 2.70, 2.76, 2.91, 2.55
177 //__________________________________________________________________________
179 Bool_t AliTOFcalibHisto::fgCableCorrectionFlag[kNcorrections] = {
180 kFALSE, // kDDLBCcorr
181 kTRUE, // kAmphenolCableCorr
182 kTRUE, // kFlatCableCorr
183 kTRUE, // kInterfaceCardCorr
184 kFALSE, // kDDLdelayCorr
185 kFALSE, // kHPTDCdelayCorr
186 kFALSE, // kFEAchDelayCorr
187 kFALSE, // kFEAdelayCorr
188 kFALSE, // kTRMdelayCorr
189 kFALSE, // kICdelayCorr
190 kFALSE, // kStripDelayCorr
191 kFALSE, // kIndexDelayCorr
192 kFALSE, // kTimeSlewingCorr
195 //__________________________________________________________________________
197 Bool_t AliTOFcalibHisto::fgFullCorrectionFlag[kNcorrections] = {
198 kFALSE, // kDDLBCcorr
199 kTRUE, // kAmphenolCableCorr
200 kTRUE, // kFlatCableCorr
201 kTRUE, // kInterfaceCardCorr
202 kTRUE, // kDDLdelayCorr
203 kTRUE, // kHPTDCdelayCorr
204 kTRUE, // kFEAchDelayCorr
205 kTRUE, // kFEAdelayCorr
206 kTRUE, // kTRMdelayCorr
207 kFALSE, // kICdelayCorr
208 kTRUE, // kStripDelayCorr
209 kTRUE, // kIndexDelayCorr
210 kTRUE, // kTimeSlewingCorr
213 //__________________________________________________________________________
215 AliTOFcalibHisto::AliTOFcalibHisto() :
221 /* default constructor */
224 //__________________________________________________________________________
226 AliTOFcalibHisto::~AliTOFcalibHisto()
228 /* default destructor */
231 //__________________________________________________________________________
234 AliTOFcalibHisto::LoadHisto(TFile* file, TH1D **histo, const Char_t *name)
237 *histo = (TH1D *)file->Get(name);
239 AliWarning(Form("error while getting %s histo", name));
242 //__________________________________________________________________________
245 AliTOFcalibHisto::CreateHisto(TH1D **histo, const Char_t *name, Int_t size)
248 *histo = new TH1D(name, Form(";index;%s", name), size, 0, size);
250 AliWarning(Form("error while creating %s histo", name));
253 //__________________________________________________________________________
256 AliTOFcalibHisto::WriteHisto(TFile *file, TH1D *histo)
259 if (!file || !file->IsOpen() || !histo)
265 //__________________________________________________________________________
268 AliTOFcalibHisto::SetHisto(TH1D *histo, Int_t index, Double_t value)
273 histo->SetBinContent(index + 1, value);
276 //__________________________________________________________________________
279 AliTOFcalibHisto::GetHisto(TH1D *histo, Int_t index)
283 AliWarning("cannot get histo");
286 return histo->GetBinContent(index + 1);
289 //__________________________________________________________________________
292 AliTOFcalibHisto::LoadCalibHisto()
294 /* load calib histo */
296 if (fgCalibHistoFile && fgCalibHistoFile->IsOpen())
297 AliWarning("calib histo file already open: reloading");
299 /* open input file */
300 TFile *fileIn = TFile::Open(GetCalibHistoFileName());
301 if (!fileIn || !fileIn->IsOpen())
302 AliFatal(Form("cannot open input file %s", GetCalibHistoFileName()));
304 /* set calib histo file */
305 fgCalibHistoFile = fileIn;
308 for (Int_t iConst = 0; iConst < kNcalibConsts; iConst++)
309 LoadHisto(fileIn, &fCalibConst[iConst], fgkCalibConstName[iConst].Data());
311 for (Int_t iMap = 0; iMap < kNcalibMaps; iMap++)
312 LoadHisto(fileIn, &fCalibMap[iMap], fgkCalibMapName[iMap].Data());
315 //__________________________________________________________________________
318 AliTOFcalibHisto::LoadCalibPar()
322 if (fgCalibParFile && fgCalibParFile->IsOpen())
323 AliWarning("calib par file already open: reloading");
325 /* load calib histo */
328 /* open input file */
329 TFile *fileIn = TFile::Open(GetCalibParFileName());
330 if (!fileIn || !fileIn->IsOpen())
331 AliError(Form("cannot open input file %s", GetCalibParFileName()));
333 /* set calib par file */
334 fgCalibParFile = fileIn;
337 for (Int_t i = 0; i < kNcalibPars; i++)
338 LoadHisto(fileIn, &fCalibPar[i], fgkCalibParName[i].Data());
342 //__________________________________________________________________________
345 AliTOFcalibHisto::WriteCalibHisto()
347 /* write calib histo */
349 /* open output file */
350 TFile *fileOut = TFile::Open(GetCalibHistoFileName(), "RECREATE");
351 if (!fileOut || !fileOut->IsOpen())
352 AliFatal(Form("cannot open output file %s", GetCalibHistoFileName()));
355 for (Int_t iConst = 0; iConst < kNcalibConsts; iConst++)
356 CreateHisto(&fCalibConst[iConst], fgkCalibConstName[iConst].Data(), 1);
358 for (Int_t iMap = 0; iMap < kNcalibMaps; iMap++)
360 CreateHisto(&fCalibMap[iMap], fgkCalibMapName[iMap].Data(), fgkNchannelsEO);
362 CreateHisto(&fCalibMap[iMap], fgkCalibMapName[iMap].Data(), fgkNchannels);
364 /*** SETUP CONSTS ***/
366 SetHisto(fCalibConst[kLHCperiod], 0, fgkLHCperiod);
367 SetHisto(fCalibConst[kAmphenolCableDelay], 0, fgkAmphenolCableDelay);
368 SetHisto(fCalibConst[kFlatCableDelay], 0, fgkFlatCableDelay);
369 SetHisto(fCalibConst[kInterfaceCardDelay], 0, fgkInterfaceCardDelay);
373 AliTOFRawStream rawStream;
374 Int_t indexEO, det[5], dummy, index, sector, plate, strip, sectorStrip, padz, padx, pad, icIndex;
376 /* temporarly disable warnings */
377 AliLog::EType_t logLevel = (AliLog::EType_t)AliLog::GetGlobalLogLevel();
378 AliLog::SetGlobalLogLevel(AliLog::kError);
380 /* loop over electronics oriented (EO) indices */
381 for (Int_t ddl = 0; ddl < 72; ddl++)
382 for (Int_t trm = 0; trm < 10; trm++)
383 for (Int_t chain = 0; chain < 2; chain++)
384 for (Int_t tdc = 0; tdc < 15; tdc++)
385 for (Int_t channel = 0; channel < 8; channel++) {
387 /* compute index EO */
388 indexEO = GetIndexEO(ddl, trm, chain, tdc, channel);
390 /* convert EO indices into detector oriented (DO) indices
391 (this call causes some warnings because the loop includes
392 EO indices which are not connected to physical channels) */
393 rawStream.EquipmentId2VolumeId(ddl, trm + 3, chain, tdc, channel, det);
395 /* swap det[3] and det[4] */
396 dummy = det[3]; det[3] = det[4]; det[4] = dummy;
398 /* check detector indices */
399 if (det[0] < 0 || det[0] > 71 ||
400 det[1] < 0 || det[1] > 4 ||
401 det[2] < 0 || det[2] > 18 ||
402 det[3] < 0 || det[3] > 1 ||
403 det[4] < 0 || det[4] > 47) {
404 SetHisto(fCalibMap[kIndex], indexEO, -1);
408 /* setup information */
409 index = AliTOFGeometry::GetIndex(det);
413 sectorStrip = plate < 3 ? plate * 19 + strip : plate * 19 - 4 + strip;
416 pad = padz + 2 * padx;
417 icIndex = pad < 48 ? pad : 95 - pad;
422 SetHisto(fCalibMap[kIndex], indexEO, index);
424 SetHisto(fCalibMap[kDDL], index, ddl);
425 SetHisto(fCalibMap[kTRM], index, trm);
426 SetHisto(fCalibMap[kChain], index, chain);
427 SetHisto(fCalibMap[kTDC], index, tdc);
428 SetHisto(fCalibMap[kChannel], index, channel);
430 SetHisto(fCalibMap[kSector], index, sector);
431 SetHisto(fCalibMap[kPlate], index, plate);
432 SetHisto(fCalibMap[kStrip], index, strip);
433 SetHisto(fCalibMap[kSectorStrip], index, sectorStrip);
434 SetHisto(fCalibMap[kPadZ], index, padz);
435 SetHisto(fCalibMap[kPadX], index, padx);
436 SetHisto(fCalibMap[kPad], index, pad);
437 SetHisto(fCalibMap[kInterfaceCardIndex], index, icIndex);
438 /* calib constants */
439 SetHisto(fCalibMap[kDDLBCshift], index, fgkDDLBCshift[ddl]);
440 SetHisto(fCalibMap[kFlatCableLength], index, fgkFlatCableLength[sectorStrip]);
441 SetHisto(fCalibMap[kInterfaceCardLength], index, fgkInterfaceCardLength[icIndex]);
442 SetHisto(fCalibMap[kAmphenolCableLength], index, AliTOFCableLengthMap::GetCableLength(ddl, trm + 3, chain, tdc));
444 } /* loop over electronics oriented (EO) indices */
446 /* re-enable warnings */
447 AliLog::SetGlobalLogLevel(logLevel);
450 for (Int_t iConst = 0; iConst < kNcalibConsts; iConst++)
451 WriteHisto(fileOut, fCalibConst[iConst]);
453 for (Int_t iMap = 0; iMap < kNcalibMaps; iMap++)
454 WriteHisto(fileOut, fCalibMap[iMap]);
456 /* close output file */
460 //__________________________________________________________________________
463 AliTOFcalibHisto::GetCorrection(Int_t corr, Int_t index, Double_t tot)
465 /* apply correction */
467 Int_t ddl, chain, tdc, channel, hptdc, pbCh, feaIndex, sector, plate, padx, trm, icIndex, sectorStrip;
472 return -GetCalibConst(kLHCperiod) * GetCalibMap(kDDLBCshift, index);
473 case kAmphenolCableCorr:
474 return GetCalibConst(kAmphenolCableDelay) * GetCalibMap(kAmphenolCableLength, index);
476 return GetCalibConst(kFlatCableDelay) * GetCalibMap(kFlatCableLength, index);
477 case kInterfaceCardCorr:
478 return GetCalibConst(kInterfaceCardDelay) * GetCalibMap(kInterfaceCardLength, index);
480 ddl = (Int_t)GetCalibMap(kDDL, index);
481 return GetCalibPar(kDDLdelayPar, ddl);
482 case kHPTDCdelayCorr:
483 chain = (Int_t)GetCalibMap(kChain, index);
484 tdc = (Int_t)GetCalibMap(kTDC, index);
485 hptdc = tdc + 15 * chain;
486 return GetCalibPar(kHPTDCdelayPar, hptdc);
487 case kFEAchDelayCorr:
488 ddl = (Int_t)GetCalibMap(kDDL, index);
489 tdc = (Int_t)GetCalibMap(kTDC, index);
490 channel = (Int_t)GetCalibMap(kChannel, index);
491 pbCh = channel + 8 * (tdc % 3);
493 return GetCalibPar(kRightFEAchDelayPar, pbCh);
495 return GetCalibPar(kLeftFEAchDelayPar, pbCh);
497 sector = (Int_t)GetCalibMap(kSector, index);
498 plate = (Int_t)GetCalibMap(kPlate, index);
499 sectorStrip = (Int_t)GetCalibMap(kSectorStrip, index);
500 padx = (Int_t)GetCalibMap(kPadX, index);
501 feaIndex = padx / 12 + 4 * sectorStrip + 364 * sector;
502 return GetCalibPar(kFEAdelayPar, feaIndex);
504 ddl = (Int_t)GetCalibMap(kDDL, index);
505 trm = (Int_t)GetCalibMap(kTRM, index);
506 return GetCalibPar(kTRMdelayPar, trm + 10 * ddl);
508 icIndex = (Int_t)GetCalibMap(kInterfaceCardIndex, index);
509 return GetCalibPar(kICdelayPar, icIndex);
510 case kStripDelayCorr:
511 sector = (Int_t)GetCalibMap(kSector, index);
512 sectorStrip = (Int_t)GetCalibMap(kSectorStrip, index);
513 return GetCalibPar(kStripDelayPar, sectorStrip + 91 * sector);
514 case kIndexDelayCorr:
515 return GetCalibPar(kIndexDelayPar, index);
516 case kTimeSlewingCorr:
517 tot = tot < SLEW_TOTMIN ? SLEW_TOTMIN : tot;
518 tot = tot > SLEW_TOTMAX ? SLEW_TOTMAX : tot;
520 for (Int_t i = 0; i < fCalibPar[kTimeSlewingPar]->GetNbinsX(); i++)
521 slewing += GetCalibPar(kTimeSlewingPar, i) * TMath::Power(tot, i);
524 AliWarning(Form("unknown correction flag (%d)", corr));
529 //__________________________________________________________________________
532 AliTOFcalibHisto::GetNominalCorrection(Int_t index)
534 /* get nominal correction */
536 for (Int_t iCorr = 0; iCorr < kNcorrections; iCorr++)
537 corr += GetCorrection(iCorr, index);
541 //__________________________________________________________________________
544 AliTOFcalibHisto::ApplyNominalCorrection(AliESDtrack *track)
546 /* apply nominal correction */
548 Double_t rawTime = track->GetTOFsignalRaw();
549 Int_t index = track->GetTOFCalChannel();
550 Double_t time = rawTime - 1.e3 * GetNominalCorrection(index);
551 track->SetTOFsignal(time);
554 //__________________________________________________________________________
557 AliTOFcalibHisto::GetCableCorrection(Int_t index)
559 /* get cable correction */
561 for (Int_t iCorr = 0; iCorr < kNcorrections; iCorr++)
562 if (fgCableCorrectionFlag[iCorr])
563 corr += GetCorrection(iCorr, index);
567 //__________________________________________________________________________
570 AliTOFcalibHisto::GetFullCorrection(Int_t index, Double_t tot)
572 /* get full correction */
574 for (Int_t iCorr = 0; iCorr < kNcorrections; iCorr++)
575 if (fgFullCorrectionFlag[iCorr]) {
576 corr += GetCorrection(iCorr, index, tot);