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 ClassImp(AliTOFcalibHisto)
37 //__________________________________________________________________________
39 TFile *AliTOFcalibHisto::fgCalibHistoFile = NULL;
40 TFile *AliTOFcalibHisto::fgCalibParFile = NULL;
42 //__________________________________________________________________________
44 TString AliTOFcalibHisto::fgCalibHistoFileName = "$ALICE_ROOT/TOF/data/AliTOFcalibHisto.root";
45 TString AliTOFcalibHisto::fgCalibParFileName = "$ALICE_ROOT/TOF/data/AliTOFcalibPar.root";
47 //__________________________________________________________________________
49 const TString AliTOFcalibHisto::fgkCalibConstName[kNcalibConsts] = {
56 //__________________________________________________________________________
58 const TString AliTOFcalibHisto::fgkCalibMapName[kNcalibMaps] = {
79 "InterfaceCardLength",
83 //__________________________________________________________________________
85 const TString AliTOFcalibHisto::fgkCalibParName[kNcalibPars] = {
95 //__________________________________________________________________________
97 /* LHC clock period [ns] */
98 const Float_t AliTOFcalibHisto::fgkLHCperiod = (24.4e-3 * 1024); /* ns */
100 //__________________________________________________________________________
102 /* Amphenol cable delay [ns/cm] */
103 const Float_t AliTOFcalibHisto::fgkAmphenolCableDelay = 5.13e-2; /* from measurement */
105 //__________________________________________________________________________
107 /* flat cable delay [ns/cm] */
108 //const Float_t AliTOFcalibHisto::fgkFlatCableDelay = 5.3e-2; /* from Amphenol 132-2829 series data-sheet */
109 const Float_t AliTOFcalibHisto::fgkFlatCableDelay = 5.124e-2; /* from LHC08d calibration */
111 //__________________________________________________________________________
113 /* interface card delay [ns/cm] */
114 //const Float_t AliTOFcalibHisto::fgkInterfaceCardDelay = 6.9e-2; /* from HyperLinx simulation */
115 const Float_t AliTOFcalibHisto::fgkInterfaceCardDelay = 5.7898e-2; /* from LHC08d calibration */
117 //__________________________________________________________________________
119 /* number of readout channels (DO/EO) */
120 const Int_t AliTOFcalibHisto::fgkNchannels = 157248;
121 const Int_t AliTOFcalibHisto::fgkNchannelsEO = 172800;
123 //__________________________________________________________________________
125 /* DDL BC shifts due to TTC fibers [LHCperiod] */
126 const Int_t AliTOFcalibHisto::fgkDDLBCshift[72] = {
147 //__________________________________________________________________________
149 /* strip flat-cable length (preliminary) [cm] */
150 const Float_t AliTOFcalibHisto::fgkFlatCableLength[91] = {
151 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 17.,
152 21., 21., 21., 21., 21., 17., 17., 21., 21., 17., 21., 21., 21., 17., 21., 21., 17., 21., 23.,
153 17., 19., 17., 19., 17., 19., 17., 19., 17., 19., 17., 19., 17., 19., 17.,
154 23., 21., 17., 21., 21., 17., 21., 21., 21., 17., 21., 21., 17., 17., 21., 21., 21., 21., 21.,
155 17., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18.
158 //__________________________________________________________________________
160 /* interface card lenght (preliminary) [cm] */
161 const Float_t AliTOFcalibHisto::fgkInterfaceCardLength[48] = {
162 13.97, 12.57, 14.52, 13.10, 15.44, 13.60, 10.58, 9.14,
163 11.21, 9.76, 12.11, 10.76, 8.67, 7.58, 9.32, 8.09,
164 10.24, 8.4, 5.51, 4.31, 6.54, 5.23, 7.48, 6.28,
165 10.43, 8.76, 11.05, 9.43, 11.72, 10.14, 7.2, 5.69,
166 7.71, 6.26, 8.36, 7.19, 4.85, 4.09, 5.57, 4.35,
167 6.59, 5.12, 2.49, 2.96, 2.70, 2.76, 2.91, 2.55
170 //__________________________________________________________________________
172 Bool_t AliTOFcalibHisto::fgCableCorrectionFlag[kNcorrections] = {
173 kFALSE, // kDDLBCcorr
174 kTRUE, // kAmphenolCableCorr
175 kTRUE, // kFlatCableCorr
176 kTRUE, // kInterfaceCardCorr
177 kFALSE, // kDDLdelayCorr
178 kFALSE, // kHPTDCdelayCorr
179 kFALSE, // kFEAchDelayCorr
180 kFALSE, // kFEAdelayCorr
181 kFALSE, // kTRMdelayCorr
182 kFALSE, // kTimeSlewingCorr
185 //__________________________________________________________________________
187 Bool_t AliTOFcalibHisto::fgFullCorrectionFlag[kNcorrections] = {
188 kFALSE, // kDDLBCcorr
189 kTRUE, // kAmphenolCableCorr
190 kTRUE, // kFlatCableCorr
191 kTRUE, // kInterfaceCardCorr
192 kTRUE, // kDDLdelayCorr
193 kTRUE, // kHPTDCdelayCorr
194 kTRUE, // kFEAchDelayCorr
195 kTRUE, // kFEAdelayCorr
196 kTRUE, // kTRMdelayCorr
197 kFALSE, // kTimeSlewingCorr
200 //__________________________________________________________________________
202 AliTOFcalibHisto::AliTOFcalibHisto() :
208 /* default constructor */
211 //__________________________________________________________________________
213 AliTOFcalibHisto::~AliTOFcalibHisto()
215 /* default destructor */
218 //__________________________________________________________________________
221 AliTOFcalibHisto::LoadHisto(TFile* file, TH1F **histo, const Char_t *name)
224 *histo = (TH1F *)file->Get(name);
226 AliWarning(Form("error while getting %s histo", name));
229 //__________________________________________________________________________
232 AliTOFcalibHisto::CreateHisto(TH1F **histo, const Char_t *name, Int_t size)
235 *histo = new TH1F(name, Form(";index;%s", name), size, 0, size);
237 AliWarning(Form("error while creating %s histo", name));
240 //__________________________________________________________________________
243 AliTOFcalibHisto::WriteHisto(TFile *file, TH1F *histo)
246 if (!file || !file->IsOpen() || !histo)
252 //__________________________________________________________________________
255 AliTOFcalibHisto::SetHisto(TH1F *histo, Int_t index, Float_t value)
260 histo->SetBinContent(index + 1, value);
263 //__________________________________________________________________________
266 AliTOFcalibHisto::GetHisto(TH1F *histo, Int_t index)
270 AliWarning("cannot get histo");
273 return histo->GetBinContent(index + 1);
276 //__________________________________________________________________________
279 AliTOFcalibHisto::LoadCalibHisto()
281 /* load calib histo */
283 if (fgCalibHistoFile && fgCalibHistoFile->IsOpen())
284 AliWarning("calib histo file already open: reloading");
286 /* open input file */
287 TFile *fileIn = TFile::Open(GetCalibHistoFileName());
288 if (!fileIn || !fileIn->IsOpen())
289 AliFatal(Form("cannot open input file %s", GetCalibHistoFileName()));
291 /* set calib histo file */
292 fgCalibHistoFile = fileIn;
295 for (Int_t iConst = 0; iConst < kNcalibConsts; iConst++)
296 LoadHisto(fileIn, &fCalibConst[iConst], fgkCalibConstName[iConst].Data());
298 for (Int_t iMap = 0; iMap < kNcalibMaps; iMap++)
299 LoadHisto(fileIn, &fCalibMap[iMap], fgkCalibMapName[iMap].Data());
302 //__________________________________________________________________________
305 AliTOFcalibHisto::LoadCalibPar()
309 if (fgCalibParFile && fgCalibParFile->IsOpen())
310 AliWarning("calib par file already open: reloading");
312 /* load calib histo */
315 /* open input file */
316 TFile *fileIn = TFile::Open(GetCalibParFileName());
317 if (!fileIn || !fileIn->IsOpen())
318 AliError(Form("cannot open input file %s", GetCalibParFileName()));
320 /* set calib par file */
321 fgCalibParFile = fileIn;
324 for (Int_t i = 0; i < kNcalibPars; i++)
325 LoadHisto(fileIn, &fCalibPar[i], fgkCalibParName[i].Data());
329 //__________________________________________________________________________
332 AliTOFcalibHisto::WriteCalibHisto()
334 /* write calib histo */
336 /* open output file */
337 TFile *fileOut = TFile::Open(GetCalibHistoFileName(), "RECREATE");
338 if (!fileOut || !fileOut->IsOpen())
339 AliFatal(Form("cannot open output file %s", GetCalibHistoFileName()));
342 for (Int_t iConst = 0; iConst < kNcalibConsts; iConst++)
343 CreateHisto(&fCalibConst[iConst], fgkCalibConstName[iConst].Data(), 1);
345 for (Int_t iMap = 0; iMap < kNcalibMaps; iMap++)
347 CreateHisto(&fCalibMap[iMap], fgkCalibMapName[iMap].Data(), fgkNchannelsEO);
349 CreateHisto(&fCalibMap[iMap], fgkCalibMapName[iMap].Data(), fgkNchannels);
351 /*** SETUP CONSTS ***/
353 SetHisto(fCalibConst[kLHCperiod], 0, fgkLHCperiod);
354 SetHisto(fCalibConst[kAmphenolCableDelay], 0, fgkAmphenolCableDelay);
355 SetHisto(fCalibConst[kFlatCableDelay], 0, fgkFlatCableDelay);
356 SetHisto(fCalibConst[kInterfaceCardDelay], 0, fgkInterfaceCardDelay);
360 AliTOFRawStream rawStream;
361 Int_t indexEO, det[5], dummy, index, sector, plate, strip, sectorStrip, padz, padx, pad, icIndex;
363 /* temporarly disable warnings */
364 AliLog::EType_t logLevel = (AliLog::EType_t)AliLog::GetGlobalLogLevel();
365 AliLog::SetGlobalLogLevel(AliLog::kError);
367 /* loop over electronics oriented (EO) indices */
368 for (Int_t ddl = 0; ddl < 72; ddl++)
369 for (Int_t trm = 0; trm < 10; trm++)
370 for (Int_t chain = 0; chain < 2; chain++)
371 for (Int_t tdc = 0; tdc < 15; tdc++)
372 for (Int_t channel = 0; channel < 8; channel++) {
374 /* compute index EO */
375 indexEO = GetIndexEO(ddl, trm, chain, tdc, channel);
377 /* convert EO indices into detector oriented (DO) indices
378 (this call causes some warnings because the loop includes
379 EO indices which are not connected to physical channels) */
380 rawStream.EquipmentId2VolumeId(ddl, trm + 3, chain, tdc, channel, det);
382 /* swap det[3] and det[4] */
383 dummy = det[3]; det[3] = det[4]; det[4] = dummy;
385 /* check detector indices */
386 if (det[0] < 0 || det[0] > 71 ||
387 det[1] < 0 || det[1] > 4 ||
388 det[2] < 0 || det[2] > 18 ||
389 det[3] < 0 || det[3] > 1 ||
390 det[4] < 0 || det[4] > 47) {
391 SetHisto(fCalibMap[kIndex], indexEO, -1);
395 /* setup information */
396 index = AliTOFGeometry::GetIndex(det);
400 sectorStrip = plate < 3 ? plate * 19 + strip : plate * 19 - 4 + strip;
403 pad = padz + 2 * padx;
404 icIndex = pad < 48 ? pad : 95 - pad;
409 SetHisto(fCalibMap[kIndex], indexEO, index);
411 SetHisto(fCalibMap[kDDL], index, ddl);
412 SetHisto(fCalibMap[kTRM], index, trm);
413 SetHisto(fCalibMap[kChain], index, chain);
414 SetHisto(fCalibMap[kTDC], index, tdc);
415 SetHisto(fCalibMap[kChannel], index, channel);
417 SetHisto(fCalibMap[kSector], index, sector);
418 SetHisto(fCalibMap[kPlate], index, plate);
419 SetHisto(fCalibMap[kStrip], index, strip);
420 SetHisto(fCalibMap[kSectorStrip], index, sectorStrip);
421 SetHisto(fCalibMap[kPadZ], index, padz);
422 SetHisto(fCalibMap[kPadX], index, padx);
423 SetHisto(fCalibMap[kPad], index, pad);
424 SetHisto(fCalibMap[kInterfaceCardIndex], index, icIndex);
425 /* calib constants */
426 SetHisto(fCalibMap[kDDLBCshift], index, fgkDDLBCshift[ddl]);
427 SetHisto(fCalibMap[kFlatCableLength], index, fgkFlatCableLength[sectorStrip]);
428 SetHisto(fCalibMap[kInterfaceCardLength], index, fgkInterfaceCardLength[icIndex]);
429 SetHisto(fCalibMap[kAmphenolCableLength], index, AliTOFCableLengthMap::GetCableLength(ddl, trm + 3, chain, tdc));
431 } /* loop over electronics oriented (EO) indices */
433 /* re-enable warnings */
434 AliLog::SetGlobalLogLevel(logLevel);
437 for (Int_t iConst = 0; iConst < kNcalibConsts; iConst++)
438 WriteHisto(fileOut, fCalibConst[iConst]);
440 for (Int_t iMap = 0; iMap < kNcalibMaps; iMap++)
441 WriteHisto(fileOut, fCalibMap[iMap]);
443 /* close output file */
447 //__________________________________________________________________________
450 AliTOFcalibHisto::GetCorrection(Int_t corr, Int_t index, Float_t tot)
452 /* apply correction */
454 Int_t ddl, chain, tdc, channel, hptdc, pbCh, feaIndex, sector, plate, strip, padx, trm;
459 return -GetCalibConst(kLHCperiod) * GetCalibMap(kDDLBCshift, index);
460 case kAmphenolCableCorr:
461 return GetCalibConst(kAmphenolCableDelay) * GetCalibMap(kAmphenolCableLength, index);
463 return GetCalibConst(kFlatCableDelay) * GetCalibMap(kFlatCableLength, index);
464 case kInterfaceCardCorr:
465 return GetCalibConst(kInterfaceCardDelay) * GetCalibMap(kInterfaceCardLength, index);
467 ddl = (Int_t)GetCalibMap(kDDL, index);
468 return GetCalibPar(kDDLdelayPar, ddl);
469 case kHPTDCdelayCorr:
470 chain = (Int_t)GetCalibMap(kChain, index);
471 tdc = (Int_t)GetCalibMap(kTDC, index);
472 hptdc = tdc + 15 * chain;
473 return GetCalibPar(kHPTDCdelayPar, hptdc);
474 case kFEAchDelayCorr:
475 ddl = (Int_t)GetCalibMap(kDDL, index);
476 tdc = (Int_t)GetCalibMap(kTDC, index);
477 channel = (Int_t)GetCalibMap(kChannel, index);
478 pbCh = channel + 8 * (tdc % 3);
480 return GetCalibPar(kRightFEAchDelayPar, pbCh);
482 return GetCalibPar(kLeftFEAchDelayPar, pbCh);
484 sector = (Int_t)GetCalibMap(kSector, index);
485 plate = (Int_t)GetCalibMap(kPlate, index);
486 strip = (Int_t)GetCalibMap(kStrip, index);
487 padx = (Int_t)GetCalibMap(kPadX, index);
488 feaIndex = padx / 12 + 4 * strip + 4 * 19 * plate + 4 * 19 * 5 * sector;
489 return GetCalibPar(kFEAdelayPar, feaIndex);
491 trm = (Int_t)GetCalibMap(kTRM, index);
492 return GetCalibPar(kTRMdelayPar, trm);
493 case kTimeSlewingCorr:
495 for (Int_t i = 0; i < fCalibPar[kTimeSlewingPar]->GetNbinsX(); i++)
496 slewing += GetCalibPar(kTimeSlewingPar, i) * TMath::Power(tot, i);
499 AliWarning(Form("unknown correction flag (%d)", corr));
504 //__________________________________________________________________________
507 AliTOFcalibHisto::GetNominalCorrection(Int_t index)
509 /* get nominal correction */
511 for (Int_t iCorr = 0; iCorr < kNcorrections; iCorr++)
512 corr += GetCorrection(iCorr, index);
516 //__________________________________________________________________________
519 AliTOFcalibHisto::ApplyNominalCorrection(AliESDtrack *track)
521 /* apply nominal correction */
523 Double_t rawTime = track->GetTOFsignalRaw();
524 Int_t index = track->GetTOFCalChannel();
525 Double_t time = rawTime - 1.e3 * GetNominalCorrection(index);
526 track->SetTOFsignal(time);
529 //__________________________________________________________________________
532 AliTOFcalibHisto::GetCableCorrection(Int_t index)
534 /* get cable correction */
536 for (Int_t iCorr = 0; iCorr < kNcorrections; iCorr++)
537 if (fgCableCorrectionFlag[iCorr])
538 corr += GetCorrection(iCorr, index);
542 //__________________________________________________________________________
545 AliTOFcalibHisto::GetFullCorrection(Int_t index)
547 /* get full correction */
549 for (Int_t iCorr = 0; iCorr < kNcorrections; iCorr++)
550 if (fgFullCorrectionFlag[iCorr])
551 corr += GetCorrection(iCorr, index);