]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TOF/AliTOFcalibHisto.cxx
Fixed problem when drawing DQM histograms (F.Bellini)
[u/mrichter/AliRoot.git] / TOF / AliTOFcalibHisto.cxx
CommitLineData
2cdf778a 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
ce469aed 16// *
17// *
18// * AliTOFcalibHisto - class to handle TOF calibration histograms,
19// * map histograms and more
20// *
21// *
22// * autors: Roberto Preghenella (R+)
23// * concacts: preghenella@bo.infn.it
24// *
25// *
2cdf778a 26
27#include "AliTOFcalibHisto.h"
28#include "AliLog.h"
97a29b32 29#include "TH1D.h"
2cdf778a 30#include "TFile.h"
31#include "AliTOFRawStream.h"
32#include "AliTOFCableLengthMap.h"
33#include "AliESDtrack.h"
34
97a29b32 35#define SLEW_TOTMIN 10.
36#define SLEW_TOTMAX 16.
37
2cdf778a 38ClassImp(AliTOFcalibHisto)
39
40//__________________________________________________________________________
41
42TFile *AliTOFcalibHisto::fgCalibHistoFile = NULL;
43TFile *AliTOFcalibHisto::fgCalibParFile = NULL;
27e86428 44TFile *AliTOFcalibHisto::fgCalibStatFile = NULL;
2cdf778a 45
46//__________________________________________________________________________
47
48TString AliTOFcalibHisto::fgCalibHistoFileName = "$ALICE_ROOT/TOF/data/AliTOFcalibHisto.root";
49TString AliTOFcalibHisto::fgCalibParFileName = "$ALICE_ROOT/TOF/data/AliTOFcalibPar.root";
27e86428 50TString AliTOFcalibHisto::fgCalibStatFileName = "$ALICE_ROOT/TOF/data/AliTOFcalibStat.root";
2cdf778a 51
52//__________________________________________________________________________
53
54const TString AliTOFcalibHisto::fgkCalibConstName[kNcalibConsts] = {
55 "LHCperiod",
56 "AmphenolCableDelay",
57 "FlatCableDelay",
58 "InterfaceCardDelay"
59};
60
61//__________________________________________________________________________
62
63const TString AliTOFcalibHisto::fgkCalibMapName[kNcalibMaps] = {
0e095c11 64 /* main index */
65 "Index",
2cdf778a 66 /* EO indices */
67 "DDL",
68 "TRM",
69 "Chain",
70 "TDC",
71 "Channel",
72 /* DO indices */
73 "Sector",
74 "Plate",
75 "Strip",
76 "SectorStrip",
77 "PadZ",
78 "PadX",
79 "Pad",
80 "InterfaceCardIndex",
81 /* calib constants */
82 "DDLBCshift",
83 "FlatCableLength",
84 "InterfaceCardLength",
85 "AmphenolCableLength"
86};
87
88//__________________________________________________________________________
89
90const TString AliTOFcalibHisto::fgkCalibParName[kNcalibPars] = {
91 "hDDLDelay",
92 "hHPTDCDelay",
93 "hLeftFEAchDelay",
94 "hRightFEAchDelay",
95 "hFEADelay",
97a29b32 96 "hICDelay",
2cdf778a 97 "hTRMDelay",
97a29b32 98 "hStripDelay",
99 "hIndexDelay",
100 "hSlewing"
2cdf778a 101};
102
103//__________________________________________________________________________
104
27e86428 105const TString AliTOFcalibHisto::fgkCalibStatName[kNcalibStats] = {
106 "hStripStat"
107};
108
109//__________________________________________________________________________
110
2cdf778a 111/* LHC clock period [ns] */
97a29b32 112const Double_t AliTOFcalibHisto::fgkLHCperiod = (24.4e-3 * 1024); /* ns */
2cdf778a 113
114//__________________________________________________________________________
115
116/* Amphenol cable delay [ns/cm] */
97a29b32 117const Double_t AliTOFcalibHisto::fgkAmphenolCableDelay = 5.13e-2; /* from measurement */
2cdf778a 118
119//__________________________________________________________________________
120
121/* flat cable delay [ns/cm] */
97a29b32 122//const Double_t AliTOFcalibHisto::fgkFlatCableDelay = 5.3e-2; /* from Amphenol 132-2829 series data-sheet */
123const Double_t AliTOFcalibHisto::fgkFlatCableDelay = 5.124e-2; /* from LHC08d calibration */
2cdf778a 124
125//__________________________________________________________________________
126
127/* interface card delay [ns/cm] */
97a29b32 128//const Double_t AliTOFcalibHisto::fgkInterfaceCardDelay = 6.9e-2; /* from HyperLinx simulation */
129//const Double_t AliTOFcalibHisto::fgkInterfaceCardDelay = 5.7898e-2; /* from LHC08d calibration */
130const Double_t AliTOFcalibHisto::fgkInterfaceCardDelay = 6.31360207815420404e-02; /* from LHC09c calibration */
2cdf778a 131
132//__________________________________________________________________________
133
0e095c11 134/* number of readout channels (DO/EO) */
2cdf778a 135const Int_t AliTOFcalibHisto::fgkNchannels = 157248;
0e095c11 136const Int_t AliTOFcalibHisto::fgkNchannelsEO = 172800;
2cdf778a 137
138//__________________________________________________________________________
139
140/* DDL BC shifts due to TTC fibers [LHCperiod] */
141const Int_t AliTOFcalibHisto::fgkDDLBCshift[72] = {
142 2, 2, -1, -1,
143 2, 2, 0, 0,
144 2, 2, 0, 0,
145 2, 2, 0, 0,
146 2, 2, 0, 0,
147 2, 2, 0, 0,
148 2, 2, 0, 0,
149 2, 2, 0, 0,
150 2, 2, 0, 0,
151 2, 2, 0, 0,
152 2, 2, -1, -1,
153 2, 2, -1, -1,
154 2, 2, -2, -2,
155 2, 2, -2, -2,
156 2, 2, -2, -2,
157 2, 2, -1, -1,
158 2, 2, -1, -1,
3aaf7a5f 159 2, 2, -1, -1
2cdf778a 160};
161
162//__________________________________________________________________________
163
164/* strip flat-cable length (preliminary) [cm] */
97a29b32 165const Double_t AliTOFcalibHisto::fgkFlatCableLength[91] = {
2cdf778a 166 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 17.,
167 21., 21., 21., 21., 21., 17., 17., 21., 21., 17., 21., 21., 21., 17., 21., 21., 17., 21., 23.,
168 17., 19., 17., 19., 17., 19., 17., 19., 17., 19., 17., 19., 17., 19., 17.,
169 23., 21., 17., 21., 21., 17., 21., 21., 21., 17., 21., 21., 17., 17., 21., 21., 21., 21., 21.,
170 17., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18.
171};
172
173//__________________________________________________________________________
174
175/* interface card lenght (preliminary) [cm] */
97a29b32 176const Double_t AliTOFcalibHisto::fgkInterfaceCardLength[48] = {
2cdf778a 177 13.97, 12.57, 14.52, 13.10, 15.44, 13.60, 10.58, 9.14,
178 11.21, 9.76, 12.11, 10.76, 8.67, 7.58, 9.32, 8.09,
179 10.24, 8.4, 5.51, 4.31, 6.54, 5.23, 7.48, 6.28,
180 10.43, 8.76, 11.05, 9.43, 11.72, 10.14, 7.2, 5.69,
181 7.71, 6.26, 8.36, 7.19, 4.85, 4.09, 5.57, 4.35,
182 6.59, 5.12, 2.49, 2.96, 2.70, 2.76, 2.91, 2.55
183};
184
185//__________________________________________________________________________
186
9155334b 187Bool_t AliTOFcalibHisto::fgCableCorrectionFlag[kNcorrections] = {
188 kFALSE, // kDDLBCcorr
189 kTRUE, // kAmphenolCableCorr
190 kTRUE, // kFlatCableCorr
191 kTRUE, // kInterfaceCardCorr
192 kFALSE, // kDDLdelayCorr
193 kFALSE, // kHPTDCdelayCorr
194 kFALSE, // kFEAchDelayCorr
195 kFALSE, // kFEAdelayCorr
196 kFALSE, // kTRMdelayCorr
97a29b32 197 kFALSE, // kICdelayCorr
198 kFALSE, // kStripDelayCorr
199 kFALSE, // kIndexDelayCorr
9155334b 200 kFALSE, // kTimeSlewingCorr
201};
202
203//__________________________________________________________________________
204
205Bool_t AliTOFcalibHisto::fgFullCorrectionFlag[kNcorrections] = {
206 kFALSE, // kDDLBCcorr
207 kTRUE, // kAmphenolCableCorr
208 kTRUE, // kFlatCableCorr
209 kTRUE, // kInterfaceCardCorr
210 kTRUE, // kDDLdelayCorr
211 kTRUE, // kHPTDCdelayCorr
212 kTRUE, // kFEAchDelayCorr
213 kTRUE, // kFEAdelayCorr
214 kTRUE, // kTRMdelayCorr
97a29b32 215 kFALSE, // kICdelayCorr
216 kTRUE, // kStripDelayCorr
217 kTRUE, // kIndexDelayCorr
218 kTRUE, // kTimeSlewingCorr
9155334b 219};
220
221//__________________________________________________________________________
222
27e86428 223const Int_t AliTOFcalibHisto::fgkStripStat[18][91] = {
224
225 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
226 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
227 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
228 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
229 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* S00 */
230
231 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
232 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
233 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
234 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
235 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* S01 */
236
237 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
238 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
239 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
240 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
241 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* S02 */
242
243 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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}, /* S16 */
326
327 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
b8006075 328 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1,
27e86428 329 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
330 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
331 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1} /* S17 */
332
333};
334
335//__________________________________________________________________________
336
2cdf778a 337AliTOFcalibHisto::AliTOFcalibHisto() :
338 TObject(),
339 fCalibConst(),
340 fCalibMap(),
27e86428 341 fCalibPar(),
342 fCalibStat()
2cdf778a 343{
344 /* default constructor */
345}
346
347//__________________________________________________________________________
348
349AliTOFcalibHisto::~AliTOFcalibHisto()
350{
351 /* default destructor */
352}
353
354//__________________________________________________________________________
355
356void
ce469aed 357AliTOFcalibHisto::LoadHisto(TFile * const file, TH1D **histo, const Char_t *name)
2cdf778a 358{
359 /* load histo */
97a29b32 360 *histo = (TH1D *)file->Get(name);
2cdf778a 361 if (!*histo)
362 AliWarning(Form("error while getting %s histo", name));
363}
364
365//__________________________________________________________________________
366
367void
97a29b32 368AliTOFcalibHisto::CreateHisto(TH1D **histo, const Char_t *name, Int_t size)
2cdf778a 369{
370 /* create histo */
97a29b32 371 *histo = new TH1D(name, Form(";index;%s", name), size, 0, size);
2cdf778a 372 if (!*histo)
373 AliWarning(Form("error while creating %s histo", name));
374}
375
376//__________________________________________________________________________
377
378void
97a29b32 379AliTOFcalibHisto::WriteHisto(TFile *file, TH1D *histo)
2cdf778a 380{
381 /* write histo */
382 if (!file || !file->IsOpen() || !histo)
383 return;
384 file->cd();
385 histo->Write();
386}
387
388//__________________________________________________________________________
389
390void
97a29b32 391AliTOFcalibHisto::SetHisto(TH1D *histo, Int_t index, Double_t value)
2cdf778a 392{
393 /* set histo */
394 if (!histo)
395 return;
396 histo->SetBinContent(index + 1, value);
397}
398
399//__________________________________________________________________________
400
97a29b32 401Double_t
402AliTOFcalibHisto::GetHisto(TH1D *histo, Int_t index)
2cdf778a 403{
404 /* get histo */
405 if (!histo) {
406 AliWarning("cannot get histo");
407 return 0.;
408 }
409 return histo->GetBinContent(index + 1);
410}
411
412//__________________________________________________________________________
413
414void
415AliTOFcalibHisto::LoadCalibHisto()
416{
417 /* load calib histo */
418
419 if (fgCalibHistoFile && fgCalibHistoFile->IsOpen())
420 AliWarning("calib histo file already open: reloading");
421
422 /* open input file */
423 TFile *fileIn = TFile::Open(GetCalibHistoFileName());
515ce574 424 if (!fileIn || !fileIn->IsOpen()) {
2cdf778a 425 AliFatal(Form("cannot open input file %s", GetCalibHistoFileName()));
515ce574 426 return;
427 }
2cdf778a 428
429 /* set calib histo file */
430 fgCalibHistoFile = fileIn;
431
432 /* load consts */
433 for (Int_t iConst = 0; iConst < kNcalibConsts; iConst++)
434 LoadHisto(fileIn, &fCalibConst[iConst], fgkCalibConstName[iConst].Data());
435 /* load maps */
436 for (Int_t iMap = 0; iMap < kNcalibMaps; iMap++)
437 LoadHisto(fileIn, &fCalibMap[iMap], fgkCalibMapName[iMap].Data());
438}
439
440//__________________________________________________________________________
441
442void
443AliTOFcalibHisto::LoadCalibPar()
444{
445 /* load calib par */
446
447 if (fgCalibParFile && fgCalibParFile->IsOpen())
448 AliWarning("calib par file already open: reloading");
449
450 /* load calib histo */
451 LoadCalibHisto();
452
453 /* open input file */
454 TFile *fileIn = TFile::Open(GetCalibParFileName());
515ce574 455 if (!fileIn || !fileIn->IsOpen()) {
2cdf778a 456 AliError(Form("cannot open input file %s", GetCalibParFileName()));
515ce574 457 return;
458 }
2cdf778a 459
460 /* set calib par file */
461 fgCalibParFile = fileIn;
462
463 /* load pars */
464 for (Int_t i = 0; i < kNcalibPars; i++)
465 LoadHisto(fileIn, &fCalibPar[i], fgkCalibParName[i].Data());
466
467}
468
469//__________________________________________________________________________
470
27e86428 471void
472AliTOFcalibHisto::LoadCalibStat()
473{
474 /* load calib stat */
475
476 if (fgCalibStatFile && fgCalibStatFile->IsOpen())
477 AliWarning("calib par file already open: reloading");
478
479 /* load calib histo */
480 LoadCalibHisto();
481
482 /* open input file */
483 TFile *fileIn = TFile::Open(GetCalibStatFileName());
484 if (!fileIn || !fileIn->IsOpen())
485 AliError(Form("cannot open input file %s", GetCalibStatFileName()));
486
487 /* set calib par file */
488 fgCalibStatFile = fileIn;
489
490 /* load pars */
491 for (Int_t i = 0; i < kNcalibStats; i++)
492 LoadHisto(fileIn, &fCalibStat[i], fgkCalibStatName[i].Data());
493
494}
495
496//__________________________________________________________________________
497
2cdf778a 498void
499AliTOFcalibHisto::WriteCalibHisto()
500{
501 /* write calib histo */
502
503 /* open output file */
504 TFile *fileOut = TFile::Open(GetCalibHistoFileName(), "RECREATE");
515ce574 505 if (!fileOut || !fileOut->IsOpen()) {
2cdf778a 506 AliFatal(Form("cannot open output file %s", GetCalibHistoFileName()));
515ce574 507 return;
508 }
2cdf778a 509
510 /* create consts */
511 for (Int_t iConst = 0; iConst < kNcalibConsts; iConst++)
512 CreateHisto(&fCalibConst[iConst], fgkCalibConstName[iConst].Data(), 1);
513 /* create maps */
514 for (Int_t iMap = 0; iMap < kNcalibMaps; iMap++)
0e095c11 515 if (iMap == kIndex)
516 CreateHisto(&fCalibMap[iMap], fgkCalibMapName[iMap].Data(), fgkNchannelsEO);
517 else
518 CreateHisto(&fCalibMap[iMap], fgkCalibMapName[iMap].Data(), fgkNchannels);
2cdf778a 519
520 /*** SETUP CONSTS ***/
521
522 SetHisto(fCalibConst[kLHCperiod], 0, fgkLHCperiod);
523 SetHisto(fCalibConst[kAmphenolCableDelay], 0, fgkAmphenolCableDelay);
524 SetHisto(fCalibConst[kFlatCableDelay], 0, fgkFlatCableDelay);
525 SetHisto(fCalibConst[kInterfaceCardDelay], 0, fgkInterfaceCardDelay);
526
527 /*** SETUP MAPS ***/
528
529 AliTOFRawStream rawStream;
0e095c11 530 Int_t indexEO, det[5], dummy, index, sector, plate, strip, sectorStrip, padz, padx, pad, icIndex;
2cdf778a 531
532 /* temporarly disable warnings */
533 AliLog::EType_t logLevel = (AliLog::EType_t)AliLog::GetGlobalLogLevel();
534 AliLog::SetGlobalLogLevel(AliLog::kError);
535
536 /* loop over electronics oriented (EO) indices */
537 for (Int_t ddl = 0; ddl < 72; ddl++)
538 for (Int_t trm = 0; trm < 10; trm++)
539 for (Int_t chain = 0; chain < 2; chain++)
540 for (Int_t tdc = 0; tdc < 15; tdc++)
541 for (Int_t channel = 0; channel < 8; channel++) {
542
99096b5f 543 /* compute index EO */
544 indexEO = GetIndexEO(ddl, trm, chain, tdc, channel);
545
2cdf778a 546 /* convert EO indices into detector oriented (DO) indices
547 (this call causes some warnings because the loop includes
548 EO indices which are not connected to physical channels) */
549 rawStream.EquipmentId2VolumeId(ddl, trm + 3, chain, tdc, channel, det);
550
551 /* swap det[3] and det[4] */
552 dummy = det[3]; det[3] = det[4]; det[4] = dummy;
553
554 /* check detector indices */
2dccfcae 555 if (det[0] < 0 || det[0] > 17 ||
2cdf778a 556 det[1] < 0 || det[1] > 4 ||
557 det[2] < 0 || det[2] > 18 ||
558 det[3] < 0 || det[3] > 1 ||
99096b5f 559 det[4] < 0 || det[4] > 47) {
560 SetHisto(fCalibMap[kIndex], indexEO, -1);
2cdf778a 561 continue;
99096b5f 562 }
2cdf778a 563
564 /* setup information */
565 index = AliTOFGeometry::GetIndex(det);
566 sector = det[0];
567 plate = det[1];
568 strip = det[2];
569 sectorStrip = plate < 3 ? plate * 19 + strip : plate * 19 - 4 + strip;
570 padz = det[3];
571 padx = det[4];
572 pad = padz + 2 * padx;
573 icIndex = pad < 48 ? pad : 95 - pad;
574
575 /* set maps */
576
0e095c11 577 /* main index */
578 SetHisto(fCalibMap[kIndex], indexEO, index);
2cdf778a 579 /* EO indices */
580 SetHisto(fCalibMap[kDDL], index, ddl);
581 SetHisto(fCalibMap[kTRM], index, trm);
582 SetHisto(fCalibMap[kChain], index, chain);
583 SetHisto(fCalibMap[kTDC], index, tdc);
584 SetHisto(fCalibMap[kChannel], index, channel);
585 /* DO indices */
586 SetHisto(fCalibMap[kSector], index, sector);
587 SetHisto(fCalibMap[kPlate], index, plate);
588 SetHisto(fCalibMap[kStrip], index, strip);
589 SetHisto(fCalibMap[kSectorStrip], index, sectorStrip);
590 SetHisto(fCalibMap[kPadZ], index, padz);
591 SetHisto(fCalibMap[kPadX], index, padx);
592 SetHisto(fCalibMap[kPad], index, pad);
593 SetHisto(fCalibMap[kInterfaceCardIndex], index, icIndex);
594 /* calib constants */
595 SetHisto(fCalibMap[kDDLBCshift], index, fgkDDLBCshift[ddl]);
596 SetHisto(fCalibMap[kFlatCableLength], index, fgkFlatCableLength[sectorStrip]);
597 SetHisto(fCalibMap[kInterfaceCardLength], index, fgkInterfaceCardLength[icIndex]);
598 SetHisto(fCalibMap[kAmphenolCableLength], index, AliTOFCableLengthMap::GetCableLength(ddl, trm + 3, chain, tdc));
599
600 } /* loop over electronics oriented (EO) indices */
601
602 /* re-enable warnings */
603 AliLog::SetGlobalLogLevel(logLevel);
604
605 /* write consts */
606 for (Int_t iConst = 0; iConst < kNcalibConsts; iConst++)
607 WriteHisto(fileOut, fCalibConst[iConst]);
608 /* write maps */
609 for (Int_t iMap = 0; iMap < kNcalibMaps; iMap++)
610 WriteHisto(fileOut, fCalibMap[iMap]);
611
612 /* close output file */
613 fileOut->Close();
614}
615
616//__________________________________________________________________________
617
27e86428 618void
619AliTOFcalibHisto::WriteCalibStat()
620{
621 /* write calib stat */
622
623 /* open output file */
624 TFile *fileOut = TFile::Open(GetCalibStatFileName(), "RECREATE");
515ce574 625 if (!fileOut || !fileOut->IsOpen()) {
27e86428 626 AliFatal(Form("cannot open output file %s", GetCalibStatFileName()));
515ce574 627 return;
628 }
27e86428 629
630 /* create stats */
631 for (Int_t iStat = 0; iStat < kNcalibStats; iStat++)
632 CreateHisto(&fCalibStat[iStat], fgkCalibStatName[iStat].Data(), fgkNchannels);
633
634 /*** SETUP STATS ***/
635
636 Int_t sector, sectorStrip;
637
638 /* load calib histo */
639 LoadCalibHisto();
640
641 /* loop over channels */
642 for (Int_t index = 0; index < fgkNchannels; index++) {
643 sector = (Int_t)GetCalibMap(kSector, index);
644 sectorStrip = (Int_t)GetCalibMap(kSectorStrip, index);
645 /* strip stat */
646 SetHisto(fCalibStat[kStripStat], index, (Double_t)fgkStripStat[sector][sectorStrip]);
647 } /* loop over channels */
648
649 /* write stats */
650 for (Int_t iStat = 0; iStat < kNcalibStats; iStat++)
651 WriteHisto(fileOut, fCalibStat[iStat]);
652
653 /* close output file */
654 fileOut->Close();
655}
656
657//__________________________________________________________________________
658
97a29b32 659Double_t
660AliTOFcalibHisto::GetCorrection(Int_t corr, Int_t index, Double_t tot)
2cdf778a 661{
662 /* apply correction */
663
01f1e64e 664 Int_t ddl, chain, tdc, channel, hptdc, pbCh, feaIndex, sector, plate, padx, trm, icIndex, sectorStrip;
97a29b32 665 Double_t slewing;
2cdf778a 666
667 switch (corr) {
668 case kDDLBCcorr:
669 return -GetCalibConst(kLHCperiod) * GetCalibMap(kDDLBCshift, index);
670 case kAmphenolCableCorr:
671 return GetCalibConst(kAmphenolCableDelay) * GetCalibMap(kAmphenolCableLength, index);
672 case kFlatCableCorr:
673 return GetCalibConst(kFlatCableDelay) * GetCalibMap(kFlatCableLength, index);
674 case kInterfaceCardCorr:
675 return GetCalibConst(kInterfaceCardDelay) * GetCalibMap(kInterfaceCardLength, index);
676 case kDDLdelayCorr:
677 ddl = (Int_t)GetCalibMap(kDDL, index);
678 return GetCalibPar(kDDLdelayPar, ddl);
679 case kHPTDCdelayCorr:
680 chain = (Int_t)GetCalibMap(kChain, index);
681 tdc = (Int_t)GetCalibMap(kTDC, index);
682 hptdc = tdc + 15 * chain;
683 return GetCalibPar(kHPTDCdelayPar, hptdc);
684 case kFEAchDelayCorr:
685 ddl = (Int_t)GetCalibMap(kDDL, index);
686 tdc = (Int_t)GetCalibMap(kTDC, index);
687 channel = (Int_t)GetCalibMap(kChannel, index);
688 pbCh = channel + 8 * (tdc % 3);
689 if (ddl % 2 == 0)
690 return GetCalibPar(kRightFEAchDelayPar, pbCh);
691 else
692 return GetCalibPar(kLeftFEAchDelayPar, pbCh);
693 case kFEAdelayCorr:
694 sector = (Int_t)GetCalibMap(kSector, index);
695 plate = (Int_t)GetCalibMap(kPlate, index);
97a29b32 696 sectorStrip = (Int_t)GetCalibMap(kSectorStrip, index);
2cdf778a 697 padx = (Int_t)GetCalibMap(kPadX, index);
97a29b32 698 feaIndex = padx / 12 + 4 * sectorStrip + 364 * sector;
2cdf778a 699 return GetCalibPar(kFEAdelayPar, feaIndex);
700 case kTRMdelayCorr:
97a29b32 701 ddl = (Int_t)GetCalibMap(kDDL, index);
2cdf778a 702 trm = (Int_t)GetCalibMap(kTRM, index);
97a29b32 703 return GetCalibPar(kTRMdelayPar, trm + 10 * ddl);
704 case kICdelayCorr:
705 icIndex = (Int_t)GetCalibMap(kInterfaceCardIndex, index);
706 return GetCalibPar(kICdelayPar, icIndex);
707 case kStripDelayCorr:
708 sector = (Int_t)GetCalibMap(kSector, index);
709 sectorStrip = (Int_t)GetCalibMap(kSectorStrip, index);
710 return GetCalibPar(kStripDelayPar, sectorStrip + 91 * sector);
711 case kIndexDelayCorr:
712 return GetCalibPar(kIndexDelayPar, index);
2cdf778a 713 case kTimeSlewingCorr:
97a29b32 714 tot = tot < SLEW_TOTMIN ? SLEW_TOTMIN : tot;
715 tot = tot > SLEW_TOTMAX ? SLEW_TOTMAX : tot;
2cdf778a 716 slewing = 0.;
717 for (Int_t i = 0; i < fCalibPar[kTimeSlewingPar]->GetNbinsX(); i++)
718 slewing += GetCalibPar(kTimeSlewingPar, i) * TMath::Power(tot, i);
719 return slewing;
720 default:
721 AliWarning(Form("unknown correction flag (%d)", corr));
722 return 0.;
723 }
724}
725
726//__________________________________________________________________________
727
97a29b32 728Double_t
2cdf778a 729AliTOFcalibHisto::GetNominalCorrection(Int_t index)
730{
731 /* get nominal correction */
97a29b32 732 Double_t corr = 0;
2cdf778a 733 for (Int_t iCorr = 0; iCorr < kNcorrections; iCorr++)
734 corr += GetCorrection(iCorr, index);
735 return corr;
736}
737
738//__________________________________________________________________________
739
740void
741AliTOFcalibHisto::ApplyNominalCorrection(AliESDtrack *track)
742{
743 /* apply nominal correction */
744
745 Double_t rawTime = track->GetTOFsignalRaw();
746 Int_t index = track->GetTOFCalChannel();
747 Double_t time = rawTime - 1.e3 * GetNominalCorrection(index);
748 track->SetTOFsignal(time);
749}
0e095c11 750
9155334b 751//__________________________________________________________________________
752
97a29b32 753Double_t
9155334b 754AliTOFcalibHisto::GetCableCorrection(Int_t index)
755{
756 /* get cable correction */
97a29b32 757 Double_t corr = 0;
9155334b 758 for (Int_t iCorr = 0; iCorr < kNcorrections; iCorr++)
759 if (fgCableCorrectionFlag[iCorr])
760 corr += GetCorrection(iCorr, index);
761 return corr;
762}
763
764//__________________________________________________________________________
765
97a29b32 766Double_t
767AliTOFcalibHisto::GetFullCorrection(Int_t index, Double_t tot)
9155334b 768{
769 /* get full correction */
97a29b32 770 Double_t corr = 0;
9155334b 771 for (Int_t iCorr = 0; iCorr < kNcorrections; iCorr++)
97a29b32 772 if (fgFullCorrectionFlag[iCorr]) {
773 corr += GetCorrection(iCorr, index, tot);
774 }
9155334b 775 return corr;
776}
777
27e86428 778//__________________________________________________________________________
779
780Bool_t
781AliTOFcalibHisto::GetStatus(Int_t index)
782{
783 /* get status */
784
785 Bool_t status = kTRUE;
786
787 for (Int_t iStat = 0; iStat < kNcalibStats; iStat++)
788 status &= GetCalibStat(iStat, index);
789
790 return status;
791}