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
21 * autors: Roberto Preghenella (R+)
22 * concacts: preghenella@bo.infn.it
24 *************************************************************************/
26 #include "AliTOFcalibHisto.h"
30 #include "AliTOFRawStream.h"
31 #include "AliTOFCableLengthMap.h"
32 #include "AliESDtrack.h"
34 ClassImp(AliTOFcalibHisto)
36 //__________________________________________________________________________
38 TFile *AliTOFcalibHisto::fgCalibHistoFile = NULL;
39 TFile *AliTOFcalibHisto::fgCalibParFile = NULL;
41 //__________________________________________________________________________
43 TString AliTOFcalibHisto::fgCalibHistoFileName = "$ALICE_ROOT/TOF/data/AliTOFcalibHisto.root";
44 TString AliTOFcalibHisto::fgCalibParFileName = "$ALICE_ROOT/TOF/data/AliTOFcalibPar.root";
46 //__________________________________________________________________________
48 const TString AliTOFcalibHisto::fgkCalibConstName[kNcalibConsts] = {
55 //__________________________________________________________________________
57 const TString AliTOFcalibHisto::fgkCalibMapName[kNcalibMaps] = {
78 "InterfaceCardLength",
82 //__________________________________________________________________________
84 const TString AliTOFcalibHisto::fgkCalibParName[kNcalibPars] = {
94 //__________________________________________________________________________
96 /* LHC clock period [ns] */
97 const Float_t AliTOFcalibHisto::fgkLHCperiod = 25.; /* SET THE CORRECT VALUE !!! */
99 //__________________________________________________________________________
101 /* Amphenol cable delay [ns/cm] */
102 const Float_t AliTOFcalibHisto::fgkAmphenolCableDelay = 5.13e-2; /* from measurement */
104 //__________________________________________________________________________
106 /* flat cable delay [ns/cm] */
107 //const Float_t AliTOFcalibHisto::fgkFlatCableDelay = 5.3e-2; /* from Amphenol 132-2829 series data-sheet */
108 const Float_t AliTOFcalibHisto::fgkFlatCableDelay = 5.124e-2; /* from LHC08d calibration */
110 //__________________________________________________________________________
112 /* interface card delay [ns/cm] */
113 //const Float_t AliTOFcalibHisto::fgkInterfaceCardDelay = 6.9e-2; /* from HyperLinx simulation */
114 const Float_t AliTOFcalibHisto::fgkInterfaceCardDelay = 5.7898e-2; /* from LHC08d calibration */
116 //__________________________________________________________________________
118 /* number of readout channels (DO/EO) */
119 const Int_t AliTOFcalibHisto::fgkNchannels = 157248;
120 const Int_t AliTOFcalibHisto::fgkNchannelsEO = 172800;
122 //__________________________________________________________________________
124 /* DDL BC shifts due to TTC fibers [LHCperiod] */
125 const Int_t AliTOFcalibHisto::fgkDDLBCshift[72] = {
146 //__________________________________________________________________________
148 /* strip flat-cable length (preliminary) [cm] */
149 const Float_t AliTOFcalibHisto::fgkFlatCableLength[91] = {
150 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 17.,
151 21., 21., 21., 21., 21., 17., 17., 21., 21., 17., 21., 21., 21., 17., 21., 21., 17., 21., 23.,
152 17., 19., 17., 19., 17., 19., 17., 19., 17., 19., 17., 19., 17., 19., 17.,
153 23., 21., 17., 21., 21., 17., 21., 21., 21., 17., 21., 21., 17., 17., 21., 21., 21., 21., 21.,
154 17., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18.
157 //__________________________________________________________________________
159 /* interface card lenght (preliminary) [cm] */
160 const Float_t AliTOFcalibHisto::fgkInterfaceCardLength[48] = {
161 13.97, 12.57, 14.52, 13.10, 15.44, 13.60, 10.58, 9.14,
162 11.21, 9.76, 12.11, 10.76, 8.67, 7.58, 9.32, 8.09,
163 10.24, 8.4, 5.51, 4.31, 6.54, 5.23, 7.48, 6.28,
164 10.43, 8.76, 11.05, 9.43, 11.72, 10.14, 7.2, 5.69,
165 7.71, 6.26, 8.36, 7.19, 4.85, 4.09, 5.57, 4.35,
166 6.59, 5.12, 2.49, 2.96, 2.70, 2.76, 2.91, 2.55
169 //__________________________________________________________________________
171 Bool_t AliTOFcalibHisto::fgCableCorrectionFlag[kNcorrections] = {
172 kFALSE, // kDDLBCcorr
173 kTRUE, // kAmphenolCableCorr
174 kTRUE, // kFlatCableCorr
175 kTRUE, // kInterfaceCardCorr
176 kFALSE, // kDDLdelayCorr
177 kFALSE, // kHPTDCdelayCorr
178 kFALSE, // kFEAchDelayCorr
179 kFALSE, // kFEAdelayCorr
180 kFALSE, // kTRMdelayCorr
181 kFALSE, // kTimeSlewingCorr
184 //__________________________________________________________________________
186 Bool_t AliTOFcalibHisto::fgFullCorrectionFlag[kNcorrections] = {
187 kFALSE, // kDDLBCcorr
188 kTRUE, // kAmphenolCableCorr
189 kTRUE, // kFlatCableCorr
190 kTRUE, // kInterfaceCardCorr
191 kTRUE, // kDDLdelayCorr
192 kTRUE, // kHPTDCdelayCorr
193 kTRUE, // kFEAchDelayCorr
194 kTRUE, // kFEAdelayCorr
195 kTRUE, // kTRMdelayCorr
196 kFALSE, // kTimeSlewingCorr
199 //__________________________________________________________________________
201 AliTOFcalibHisto::AliTOFcalibHisto() :
207 /* default constructor */
210 //__________________________________________________________________________
212 AliTOFcalibHisto::~AliTOFcalibHisto()
214 /* default destructor */
217 //__________________________________________________________________________
220 AliTOFcalibHisto::LoadHisto(TFile* file, TH1F **histo, const Char_t *name)
223 *histo = (TH1F *)file->Get(name);
225 AliWarning(Form("error while getting %s histo", name));
228 //__________________________________________________________________________
231 AliTOFcalibHisto::CreateHisto(TH1F **histo, const Char_t *name, Int_t size)
234 *histo = new TH1F(name, Form(";index;%s", name), size, 0, size);
236 AliWarning(Form("error while creating %s histo", name));
239 //__________________________________________________________________________
242 AliTOFcalibHisto::WriteHisto(TFile *file, TH1F *histo)
245 if (!file || !file->IsOpen() || !histo)
251 //__________________________________________________________________________
254 AliTOFcalibHisto::SetHisto(TH1F *histo, Int_t index, Float_t value)
259 histo->SetBinContent(index + 1, value);
262 //__________________________________________________________________________
265 AliTOFcalibHisto::GetHisto(TH1F *histo, Int_t index)
269 AliWarning("cannot get histo");
272 return histo->GetBinContent(index + 1);
275 //__________________________________________________________________________
278 AliTOFcalibHisto::LoadCalibHisto()
280 /* load calib histo */
282 if (fgCalibHistoFile && fgCalibHistoFile->IsOpen())
283 AliWarning("calib histo file already open: reloading");
285 /* open input file */
286 TFile *fileIn = TFile::Open(GetCalibHistoFileName());
287 if (!fileIn || !fileIn->IsOpen())
288 AliFatal(Form("cannot open input file %s", GetCalibHistoFileName()));
290 /* set calib histo file */
291 fgCalibHistoFile = fileIn;
294 for (Int_t iConst = 0; iConst < kNcalibConsts; iConst++)
295 LoadHisto(fileIn, &fCalibConst[iConst], fgkCalibConstName[iConst].Data());
297 for (Int_t iMap = 0; iMap < kNcalibMaps; iMap++)
298 LoadHisto(fileIn, &fCalibMap[iMap], fgkCalibMapName[iMap].Data());
301 //__________________________________________________________________________
304 AliTOFcalibHisto::LoadCalibPar()
308 if (fgCalibParFile && fgCalibParFile->IsOpen())
309 AliWarning("calib par file already open: reloading");
311 /* load calib histo */
314 /* open input file */
315 TFile *fileIn = TFile::Open(GetCalibParFileName());
316 if (!fileIn || !fileIn->IsOpen())
317 AliError(Form("cannot open input file %s", GetCalibParFileName()));
319 /* set calib par file */
320 fgCalibParFile = fileIn;
323 for (Int_t i = 0; i < kNcalibPars; i++)
324 LoadHisto(fileIn, &fCalibPar[i], fgkCalibParName[i].Data());
328 //__________________________________________________________________________
331 AliTOFcalibHisto::WriteCalibHisto()
333 /* write calib histo */
335 /* open output file */
336 TFile *fileOut = TFile::Open(GetCalibHistoFileName(), "RECREATE");
337 if (!fileOut || !fileOut->IsOpen())
338 AliFatal(Form("cannot open output file %s", GetCalibHistoFileName()));
341 for (Int_t iConst = 0; iConst < kNcalibConsts; iConst++)
342 CreateHisto(&fCalibConst[iConst], fgkCalibConstName[iConst].Data(), 1);
344 for (Int_t iMap = 0; iMap < kNcalibMaps; iMap++)
346 CreateHisto(&fCalibMap[iMap], fgkCalibMapName[iMap].Data(), fgkNchannelsEO);
348 CreateHisto(&fCalibMap[iMap], fgkCalibMapName[iMap].Data(), fgkNchannels);
350 /*** SETUP CONSTS ***/
352 SetHisto(fCalibConst[kLHCperiod], 0, fgkLHCperiod);
353 SetHisto(fCalibConst[kAmphenolCableDelay], 0, fgkAmphenolCableDelay);
354 SetHisto(fCalibConst[kFlatCableDelay], 0, fgkFlatCableDelay);
355 SetHisto(fCalibConst[kInterfaceCardDelay], 0, fgkInterfaceCardDelay);
359 AliTOFRawStream rawStream;
360 Int_t indexEO, det[5], dummy, index, sector, plate, strip, sectorStrip, padz, padx, pad, icIndex;
362 /* temporarly disable warnings */
363 AliLog::EType_t logLevel = (AliLog::EType_t)AliLog::GetGlobalLogLevel();
364 AliLog::SetGlobalLogLevel(AliLog::kError);
366 /* loop over electronics oriented (EO) indices */
367 for (Int_t ddl = 0; ddl < 72; ddl++)
368 for (Int_t trm = 0; trm < 10; trm++)
369 for (Int_t chain = 0; chain < 2; chain++)
370 for (Int_t tdc = 0; tdc < 15; tdc++)
371 for (Int_t channel = 0; channel < 8; channel++) {
373 /* compute index EO */
374 indexEO = GetIndexEO(ddl, trm, chain, tdc, channel);
376 /* convert EO indices into detector oriented (DO) indices
377 (this call causes some warnings because the loop includes
378 EO indices which are not connected to physical channels) */
379 rawStream.EquipmentId2VolumeId(ddl, trm + 3, chain, tdc, channel, det);
381 /* swap det[3] and det[4] */
382 dummy = det[3]; det[3] = det[4]; det[4] = dummy;
384 /* check detector indices */
385 if (det[0] < 0 || det[0] > 71 ||
386 det[1] < 0 || det[1] > 4 ||
387 det[2] < 0 || det[2] > 18 ||
388 det[3] < 0 || det[3] > 1 ||
389 det[4] < 0 || det[4] > 47) {
390 SetHisto(fCalibMap[kIndex], indexEO, -1);
394 /* setup information */
395 index = AliTOFGeometry::GetIndex(det);
399 sectorStrip = plate < 3 ? plate * 19 + strip : plate * 19 - 4 + strip;
402 pad = padz + 2 * padx;
403 icIndex = pad < 48 ? pad : 95 - pad;
408 SetHisto(fCalibMap[kIndex], indexEO, index);
410 SetHisto(fCalibMap[kDDL], index, ddl);
411 SetHisto(fCalibMap[kTRM], index, trm);
412 SetHisto(fCalibMap[kChain], index, chain);
413 SetHisto(fCalibMap[kTDC], index, tdc);
414 SetHisto(fCalibMap[kChannel], index, channel);
416 SetHisto(fCalibMap[kSector], index, sector);
417 SetHisto(fCalibMap[kPlate], index, plate);
418 SetHisto(fCalibMap[kStrip], index, strip);
419 SetHisto(fCalibMap[kSectorStrip], index, sectorStrip);
420 SetHisto(fCalibMap[kPadZ], index, padz);
421 SetHisto(fCalibMap[kPadX], index, padx);
422 SetHisto(fCalibMap[kPad], index, pad);
423 SetHisto(fCalibMap[kInterfaceCardIndex], index, icIndex);
424 /* calib constants */
425 SetHisto(fCalibMap[kDDLBCshift], index, fgkDDLBCshift[ddl]);
426 SetHisto(fCalibMap[kFlatCableLength], index, fgkFlatCableLength[sectorStrip]);
427 SetHisto(fCalibMap[kInterfaceCardLength], index, fgkInterfaceCardLength[icIndex]);
428 SetHisto(fCalibMap[kAmphenolCableLength], index, AliTOFCableLengthMap::GetCableLength(ddl, trm + 3, chain, tdc));
430 } /* loop over electronics oriented (EO) indices */
432 /* re-enable warnings */
433 AliLog::SetGlobalLogLevel(logLevel);
436 for (Int_t iConst = 0; iConst < kNcalibConsts; iConst++)
437 WriteHisto(fileOut, fCalibConst[iConst]);
439 for (Int_t iMap = 0; iMap < kNcalibMaps; iMap++)
440 WriteHisto(fileOut, fCalibMap[iMap]);
442 /* close output file */
446 //__________________________________________________________________________
449 AliTOFcalibHisto::GetCorrection(Int_t corr, Int_t index, Float_t tot)
451 /* apply correction */
453 Int_t ddl, chain, tdc, channel, hptdc, pbCh, feaIndex, sector, plate, strip, padx, trm;
458 return -GetCalibConst(kLHCperiod) * GetCalibMap(kDDLBCshift, index);
459 case kAmphenolCableCorr:
460 return GetCalibConst(kAmphenolCableDelay) * GetCalibMap(kAmphenolCableLength, index);
462 return GetCalibConst(kFlatCableDelay) * GetCalibMap(kFlatCableLength, index);
463 case kInterfaceCardCorr:
464 return GetCalibConst(kInterfaceCardDelay) * GetCalibMap(kInterfaceCardLength, index);
466 ddl = (Int_t)GetCalibMap(kDDL, index);
467 return GetCalibPar(kDDLdelayPar, ddl);
468 case kHPTDCdelayCorr:
469 chain = (Int_t)GetCalibMap(kChain, index);
470 tdc = (Int_t)GetCalibMap(kTDC, index);
471 hptdc = tdc + 15 * chain;
472 return GetCalibPar(kHPTDCdelayPar, hptdc);
473 case kFEAchDelayCorr:
474 ddl = (Int_t)GetCalibMap(kDDL, index);
475 tdc = (Int_t)GetCalibMap(kTDC, index);
476 channel = (Int_t)GetCalibMap(kChannel, index);
477 pbCh = channel + 8 * (tdc % 3);
479 return GetCalibPar(kRightFEAchDelayPar, pbCh);
481 return GetCalibPar(kLeftFEAchDelayPar, pbCh);
483 sector = (Int_t)GetCalibMap(kSector, index);
484 plate = (Int_t)GetCalibMap(kPlate, index);
485 strip = (Int_t)GetCalibMap(kStrip, index);
486 padx = (Int_t)GetCalibMap(kPadX, index);
487 feaIndex = padx / 12 + 4 * strip + 4 * 19 * plate + 4 * 19 * 5 * sector;
488 return GetCalibPar(kFEAdelayPar, feaIndex);
490 trm = (Int_t)GetCalibMap(kTRM, index);
491 return GetCalibPar(kTRMdelayPar, trm);
492 case kTimeSlewingCorr:
494 for (Int_t i = 0; i < fCalibPar[kTimeSlewingPar]->GetNbinsX(); i++)
495 slewing += GetCalibPar(kTimeSlewingPar, i) * TMath::Power(tot, i);
498 AliWarning(Form("unknown correction flag (%d)", corr));
503 //__________________________________________________________________________
506 AliTOFcalibHisto::GetNominalCorrection(Int_t index)
508 /* get nominal correction */
510 for (Int_t iCorr = 0; iCorr < kNcorrections; iCorr++)
511 corr += GetCorrection(iCorr, index);
515 //__________________________________________________________________________
518 AliTOFcalibHisto::ApplyNominalCorrection(AliESDtrack *track)
520 /* apply nominal correction */
522 Double_t rawTime = track->GetTOFsignalRaw();
523 Int_t index = track->GetTOFCalChannel();
524 Double_t time = rawTime - 1.e3 * GetNominalCorrection(index);
525 track->SetTOFsignal(time);
528 //__________________________________________________________________________
531 AliTOFcalibHisto::GetCableCorrection(Int_t index)
533 /* get cable correction */
535 for (Int_t iCorr = 0; iCorr < kNcorrections; iCorr++)
536 if (fgCableCorrectionFlag[iCorr])
537 corr += GetCorrection(iCorr, index);
541 //__________________________________________________________________________
544 AliTOFcalibHisto::GetFullCorrection(Int_t index)
546 /* get full correction */
548 for (Int_t iCorr = 0; iCorr < kNcorrections; iCorr++)
549 if (fgFullCorrectionFlag[iCorr])
550 corr += GetCorrection(iCorr, index);