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 **************************************************************************/
17 $Log: AliTOFcalib.cxx,v $
18 Revision 1.21 2007/11/02 15:41:49 hristov
19 Provide return value if the function is not void
21 Revision 1.20 2007/10/26 15:13:50 zampolli
22 Using a TChain instead of a TTree
24 Revision 1.19 2007/10/23 15:27:38 zampolli
25 Rearrangement of Calibration objects for simulation
27 Revision 1.16 2007/10/08 10:13:26 zampolli
28 First Run and Last Run members added, infinite validity of calib obj implemented.
30 Revision 1.15 2007/10/04 13:23:28 zampolli
31 Updates to handle functionalities in TOF online/offline calibration according to the latest schema
33 Revision 1.14 2007/06/06 16:26:30 arcelli
34 remove fall-back call to local CDB storage
36 Revision 1.13 2007/04/20 13:59:40 arcelli
37 make protections agains failed retrieval of the CDB object in a proper way
39 Revision 1.12 2007/03/23 11:31:16 arcelli
40 CDB Entry for TOF Reconstruction Parameters
42 Revision 1.11 2007/02/28 18:08:26 arcelli
43 Add protection against failed retrieval of the CDB cal object
45 Revision 1.10 2006/08/22 13:30:49 arcelli
46 removal of effective c++ warnings (C.Zampolli)
48 Revision 1.9 2006/04/20 22:30:50 hristov
49 Coding conventions (Annalisa)
51 Revision 1.8 2006/04/16 22:29:05 hristov
52 Coding conventions (Annalisa)
54 Revision 1.7 2006/04/16 20:12:46 hristov
55 Removing memory leak in case of cached CDB entries
57 Revision 1.6 2006/04/11 15:28:32 hristov
58 Checks on cache status before deleting calibration objects (A.Colla)
60 Revision 1.5 2006/04/05 08:35:38 hristov
61 Coding conventions (S.Arcelli, C.Zampolli)
63 Revision 1.4 2006/03/31 11:26:46 arcelli
64 changing CDB Ids according to standard convention
66 Revision 1.3 2006/03/28 14:57:02 arcelli
67 updates to handle new V5 geometry & some re-arrangements
69 Revision 1.2 2006/02/13 17:22:26 arcelli
72 Revision 1.1 2006/02/13 16:10:48 arcelli
73 Add classes for TOF Calibration (C.Zampolli)
75 author: Chiara Zampolli, zampolli@bo.infn.it
78 ///////////////////////////////////////////////////////////////////////////////
80 // class for TOF calibration //
82 ///////////////////////////////////////////////////////////////////////////////
99 #include "AliCDBEntry.h"
100 #include "AliCDBRunRange.h"
101 #include "AliCDBId.h"
102 #include "AliCDBManager.h"
103 #include "AliCDBStorage.h"
104 #include "AliCDBMetaData.h"
105 //#include "AliESDtrack.h"
106 //#include "AliESD.h"
109 #include "AliTOFcalib.h"
110 #include "AliTOFChannelOnlineArray.h"
111 #include "AliTOFChannelOnline.h"
112 #include "AliTOFChannelOnlineStatus.h"
113 #include "AliTOFChannelOnlineStatusArray.h"
114 #include "AliTOFChannelOffline.h"
115 #include "AliTOFGeometry.h"
116 #include "AliTOFRecoParam.h"
117 #include "AliTOFDeltaBCOffset.h"
118 #include "AliTOFCTPLatency.h"
119 #include "AliTOFT0Fill.h"
120 #include "AliTOFRunParams.h"
121 #include "AliLHCClockPhase.h"
122 #include "AliTOFResponseParams.h"
123 #include "AliESDEvent.h"
124 #include "AliESDtrack.h"
131 extern TStyle *gStyle;
133 ClassImp(AliTOFcalib)
135 //_______________________________________________________________________
136 AliTOFcalib::AliTOFcalib():
137 TTask("AliTOFcalib",""),
140 fTOFCalOnlinePulser(0x0),
141 fTOFCalOnlineNoise(0x0),
142 fTOFCalOnlineHW(0x0),
152 fLastRun(AliCDBRunRange::Infinity()),
153 fConfigMap(new TMap),
154 fDeltaBCOffset(NULL),
158 fLHCClockPhase(NULL),
159 fResponseParams(NULL),
160 fReadoutEfficiency(NULL),
163 fRemoveMeanT0(kTRUE),
164 fUseLHCClockPhase(kFALSE),
165 fCalibrateTOFsignal(kTRUE),
168 //TOF Calibration Class ctor
169 fNChannels = AliTOFGeometry::NSectors()*(2*(AliTOFGeometry::NStripC()+AliTOFGeometry::NStripB())+AliTOFGeometry::NStripA())*AliTOFGeometry::NpadZ()*AliTOFGeometry::NpadX();
171 gRandom->SetSeed(123456789);
173 //____________________________________________________________________________
175 AliTOFcalib::AliTOFcalib(const AliTOFcalib & calib):
177 fNChannels(calib.fNChannels),
179 fTOFCalOnlinePulser(0x0),
180 fTOFCalOnlineNoise(0x0),
181 fTOFCalOnlineHW(0x0),
184 fStatus(calib.fStatus),
185 fTOFSimToT(calib.fTOFSimToT),
186 fkValidity(calib.fkValidity),
188 fChain(calib.fChain),
189 fNruns(calib.fNruns),
190 fFirstRun(calib.fFirstRun),
191 fLastRun(calib.fLastRun),
192 fConfigMap(calib.fConfigMap),
193 fDeltaBCOffset(NULL),
197 fLHCClockPhase(NULL),
198 fResponseParams(NULL),
199 fReadoutEfficiency(NULL),
201 fInitFlag(calib.fInitFlag),
202 fRemoveMeanT0(calib.fRemoveMeanT0),
203 fUseLHCClockPhase(calib.fUseLHCClockPhase),
204 fCalibrateTOFsignal(calib.fCalibrateTOFsignal),
205 fCorrectTExp(calib.fCorrectTExp)
208 fTOFCalOnline = new TObjArray(fNChannels);
209 fTOFCalOnlinePulser = new TObjArray(fNChannels);
210 fTOFCalOnlineNoise = new TObjArray(fNChannels);
211 fTOFCalOnlineHW = new TObjArray(fNChannels);
212 fTOFCalOffline = new TObjArray(fNChannels);
213 fTOFCalOnline->SetOwner();
214 fTOFCalOnlinePulser->SetOwner();
215 fTOFCalOnlineNoise->SetOwner();
216 fTOFCalOnlineHW->SetOwner();
217 fTOFCalOffline->SetOwner();
219 //TOF Calibration Class copy ctor
220 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
221 AliTOFChannelOnline * calChOnline = (AliTOFChannelOnline*)calib.fTOFCalOnline->At(iarray);
222 AliTOFChannelOnlineStatus * calChOnlineStPulser = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlinePulser->At(iarray);
223 AliTOFChannelOnlineStatus * calChOnlineStNoise = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlineNoise->At(iarray);
224 AliTOFChannelOnlineStatus * calChOnlineStHW = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlineHW->At(iarray);
225 AliTOFChannelOffline * calChOffline = (AliTOFChannelOffline*)calib.fTOFCalOffline->At(iarray);
226 fTOFCalOnline->AddAt(calChOnline,iarray);
227 fTOFCalOnlinePulser->AddAt(calChOnlineStPulser,iarray);
228 fTOFCalOnlineNoise->AddAt(calChOnlineStNoise,iarray);
229 fTOFCalOnlineHW->AddAt(calChOnlineStHW,iarray);
230 fTOFCalOffline->AddAt(calChOffline,iarray);
233 if (calib.fDeltaBCOffset) fDeltaBCOffset = new AliTOFDeltaBCOffset(*calib.fDeltaBCOffset);
234 if (calib.fCTPLatency) fCTPLatency = new AliTOFCTPLatency(*calib.fCTPLatency);
235 if (calib.fT0Fill) fT0Fill = new AliTOFT0Fill(*calib.fT0Fill);
236 if (calib.fRunParams) fRunParams = new AliTOFRunParams(*calib.fRunParams);
237 if (calib.fResponseParams) fResponseParams = new AliTOFResponseParams(*calib.fResponseParams);
238 if (calib.fReadoutEfficiency) fReadoutEfficiency = new TH1F(*calib.fReadoutEfficiency);
239 if (calib.fProblematic) fProblematic = new TH1C(*calib.fProblematic);
241 gRandom->SetSeed(123456789);
244 //____________________________________________________________________________
246 AliTOFcalib& AliTOFcalib::operator=(const AliTOFcalib &calib)
248 //TOF Calibration Class assignment operator
253 TTask::operator=(calib);
254 fNChannels = calib.fNChannels;
256 fStatus = calib.fStatus;
257 fTOFSimToT = calib.fTOFSimToT;
258 fkValidity = calib.fkValidity;
260 fChain = calib.fChain;
261 fNruns = calib.fNruns;
262 fFirstRun = calib.fFirstRun;
263 fLastRun = calib.fLastRun;
264 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
265 AliTOFChannelOnline * calChOnline = (AliTOFChannelOnline*)calib.fTOFCalOnline->At(iarray);
266 AliTOFChannelOffline * calChOffline = (AliTOFChannelOffline*)calib.fTOFCalOffline->At(iarray);
267 AliTOFChannelOnlineStatus * calChOnlineStPulser = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlinePulser->At(iarray);
268 AliTOFChannelOnlineStatus * calChOnlineStNoise = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlineNoise->At(iarray);
269 AliTOFChannelOnlineStatus * calChOnlineStHW = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlineHW->At(iarray);
270 fTOFCalOnline->AddAt(calChOnline,iarray);
271 fTOFCalOnlinePulser->AddAt(calChOnlineStPulser,iarray);
272 fTOFCalOnlineNoise->AddAt(calChOnlineStNoise,iarray);
273 fTOFCalOnlineHW->AddAt(calChOnlineStHW,iarray);
274 fTOFCalOffline->AddAt(calChOffline,iarray);
277 if (calib.fDeltaBCOffset) {
278 if (fDeltaBCOffset) *fDeltaBCOffset = *calib.fDeltaBCOffset;
279 else fDeltaBCOffset = new AliTOFDeltaBCOffset(*calib.fDeltaBCOffset);
282 if (calib.fCTPLatency) {
283 if (fCTPLatency) *fCTPLatency = *calib.fCTPLatency;
284 else fCTPLatency = new AliTOFCTPLatency(*calib.fCTPLatency);
288 if (fT0Fill) *fT0Fill = *calib.fT0Fill;
289 else fT0Fill = new AliTOFT0Fill(*calib.fT0Fill);
291 if (calib.fRunParams) {
292 if (fRunParams) *fRunParams = *calib.fRunParams;
293 else fRunParams = new AliTOFRunParams(*calib.fRunParams);
295 if (calib.fResponseParams) {
296 if (fResponseParams) *fResponseParams = *calib.fResponseParams;
297 else fResponseParams = new AliTOFResponseParams(*calib.fResponseParams);
299 if (calib.fReadoutEfficiency) {
300 if (fReadoutEfficiency) *fReadoutEfficiency = *calib.fReadoutEfficiency;
301 else fReadoutEfficiency = new TH1F(*calib.fReadoutEfficiency);
303 if (calib.fProblematic) {
304 if (fProblematic) *fProblematic = *calib.fProblematic;
305 else fProblematic = new TH1C(*calib.fProblematic);
307 fInitFlag = calib.fInitFlag;
308 fRemoveMeanT0 = calib.fRemoveMeanT0;
309 fUseLHCClockPhase = calib.fUseLHCClockPhase;
310 fCalibrateTOFsignal = calib.fCalibrateTOFsignal;
311 fCorrectTExp = calib.fCorrectTExp;
316 //____________________________________________________________________________
318 AliTOFcalib::~AliTOFcalib()
320 //TOF Calibration Class dtor
321 if(!(AliCDBManager::Instance()->GetCacheFlag())){ // CDB objects must NOT be deleted if cache is active!
323 delete fTOFCalOnline;
325 if (fTOFCalOnlinePulser){
326 delete fTOFCalOnlinePulser;
328 if (fTOFCalOnlineNoise){
329 delete fTOFCalOnlineNoise;
331 if (fTOFCalOnlineHW){
332 delete fTOFCalOnlineHW;
335 delete fTOFCalOffline;
346 if (fDeltaBCOffset) delete fDeltaBCOffset;
347 if (fCTPLatency) delete fCTPLatency;
348 if (fT0Fill) delete fT0Fill;
349 if (fRunParams) delete fRunParams;
350 if (fResponseParams) delete fResponseParams;
351 if (fReadoutEfficiency) delete fReadoutEfficiency;
352 if (fProblematic) delete fProblematic;
354 if (fTree!=0x0) delete fTree;
355 if (fChain!=0x0) delete fChain;
358 //_____________________________________________________________________________
359 void AliTOFcalib::CreateCalArrays(){
361 // creating arrays for online/offline calibration objs
363 fTOFCalOnline = new TObjArray(fNChannels);
364 fTOFCalOnlinePulser = new TObjArray(fNChannels);
365 fTOFCalOnlineNoise = new TObjArray(fNChannels);
366 fTOFCalOnlineHW = new TObjArray(fNChannels);
367 fTOFCalOffline = new TObjArray(fNChannels);
368 fTOFCalOnline->SetOwner();
369 fTOFCalOnlinePulser->SetOwner();
370 fTOFCalOnlineNoise->SetOwner();
371 fTOFCalOnlineHW->SetOwner();
372 fTOFCalOffline->SetOwner();
373 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
374 AliTOFChannelOnline * calChOnline = new AliTOFChannelOnline();
375 AliTOFChannelOnlineStatus * calChOnlineStPulser = new AliTOFChannelOnlineStatus();
376 AliTOFChannelOnlineStatus * calChOnlineStNoise = new AliTOFChannelOnlineStatus();
377 AliTOFChannelOnlineStatus * calChOnlineStHW = new AliTOFChannelOnlineStatus();
378 AliTOFChannelOffline * calChOffline = new AliTOFChannelOffline();
379 fTOFCalOnline->AddAt(calChOnline,iarray);
380 fTOFCalOnlinePulser->AddAt(calChOnlineStPulser,iarray);
381 fTOFCalOnlineNoise->AddAt(calChOnlineStNoise,iarray);
382 fTOFCalOnlineHW->AddAt(calChOnlineStHW,iarray);
383 fTOFCalOffline->AddAt(calChOffline,iarray);
385 fCal = new AliTOFChannelOnlineArray(fNChannels);
386 fStatus = new AliTOFChannelOnlineStatusArray(fNChannels);
388 //_____________________________________________________________________________
389 void AliTOFcalib::CreateCalObjects(){
391 // creating arrays for online/offline calibration objs
393 fTOFCalOffline = new TObjArray(fNChannels);
394 fTOFCalOffline->SetOwner();
395 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
396 AliTOFChannelOffline * calChOffline = new AliTOFChannelOffline();
397 fTOFCalOffline->AddAt(calChOffline,iarray);
399 fCal = new AliTOFChannelOnlineArray(fNChannels);
400 fStatus = new AliTOFChannelOnlineStatusArray(fNChannels);
402 //_____________________________________________________________________________
403 void AliTOFcalib::WriteConfigMapOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
405 //Write calibration parameters to the CDB
408 AliCDBManager *man = AliCDBManager::Instance();
409 const Char_t *sel1 = "Config" ; // to be consistent with TOFPreprocessor
410 TString out(Form("%s/%s",sel,sel1));
411 AliDebug(2,Form("Writing TOF configuration map for online calib on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
412 AliCDBId id(out,fFirstRun,fLastRun);
413 AliCDBMetaData *md = new AliCDBMetaData();
414 md->SetResponsible("Chiara Zampolli");
418 man->Put(fConfigMap,id,md);
421 //_____________________________________________________________________________
423 void AliTOFcalib::WriteConfigMapOnCDB(const Char_t *sel)
425 //Write calibration parameters to the CDB with infinite validity
426 AliCDBManager *man = AliCDBManager::Instance();
427 const Char_t *sel1 = "Config" ; // to be consistent with TOFPreprocessor
428 TString out(Form("%s/%s",sel,sel1));
429 AliCDBRunRange runrange(fFirstRun,fLastRun);
430 AliDebug(2,Form("Writing TOF config map for online calib on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
431 AliCDBId id(out,runrange);
432 AliCDBMetaData *md = new AliCDBMetaData();
433 md->SetResponsible("Chiara Zampolli");
437 man->Put(fConfigMap,id,md);
440 //_____________________________________________________________________________
441 void AliTOFcalib::WriteParOnlineDelayOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
443 //Write calibration parameters to the CDB -------> new calib objs!!!!!
446 AliCDBManager *man = AliCDBManager::Instance();
447 const Char_t *sel1 = "ParOnlineDelay" ; // to be consistent with TOFPreprocessor
448 TString out(Form("%s/%s",sel,sel1));
449 AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
450 AliCDBId id(out,fFirstRun,fLastRun);
451 AliCDBMetaData *md = new AliCDBMetaData();
452 md->SetResponsible("Chiara Zampolli");
456 man->Put(fCal,id,md);
459 //_____________________________________________________________________________
460 void AliTOFcalib::WriteParOnlineStatusOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
462 //Write calibration parameters to the CDB -------> new calib objs!!!!!
465 AliCDBManager *man = AliCDBManager::Instance();
466 const Char_t *sel1 = "Status" ; // to be consistent with TOFPreprocessor
467 TString out(Form("%s/%s",sel,sel1));
468 AliDebug(2,Form("Writing TOF online status calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
469 AliCDBId id(out,fFirstRun,fLastRun);
470 AliCDBMetaData *md = new AliCDBMetaData();
471 md->SetResponsible("Chiara Zampolli");
475 man->Put(fStatus,id,md);
478 //_____________________________________________________________________________
480 void AliTOFcalib::WriteParOnlineDelayOnCDB(const Char_t *sel)
482 //Write calibration parameters to the CDB with infinite validity -------> new calib objs!!!!!
483 AliCDBManager *man = AliCDBManager::Instance();
484 const Char_t *sel1 = "ParOnlineDelay" ; // to be consistent with TOFPreprocessor
485 TString out(Form("%s/%s",sel,sel1));
486 AliCDBRunRange runrange(fFirstRun,fLastRun);
487 AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
488 AliCDBId id(out,runrange);
489 AliCDBMetaData *md = new AliCDBMetaData();
490 md->SetResponsible("Chiara Zampolli");
494 man->Put(fCal,id,md);
497 //_____________________________________________________________________________
499 void AliTOFcalib::WriteParOnlineStatusOnCDB(const Char_t *sel)
501 //Write calibration parameters to the CDB with infinite validity -------> new calib objs!!!!!
502 AliCDBManager *man = AliCDBManager::Instance();
503 const Char_t *sel1 = "Status" ; // to be consistent with TOFPreprocessor
504 TString out(Form("%s/%s",sel,sel1));
505 AliCDBRunRange runrange(fFirstRun,fLastRun);
506 AliDebug(2,Form("Writing TOF online status calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
507 AliCDBId id(out,runrange);
508 AliCDBMetaData *md = new AliCDBMetaData();
509 md->SetResponsible("Chiara Zampolli");
513 man->Put(fStatus,id,md);
516 //_____________________________________________________________________________
517 void AliTOFcalib::WriteParOnlineOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
519 //Write calibration parameters to the CDB
522 AliCDBManager *man = AliCDBManager::Instance();
523 const Char_t *sel1 = "ParOnline" ; // to be consistent with TOFPreprocessor
524 TString out(Form("%s/%s",sel,sel1));
525 AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
526 AliCDBId id(out,fFirstRun,fLastRun);
527 AliCDBMetaData *md = new AliCDBMetaData();
528 md->SetResponsible("Chiara Zampolli");
529 if (!fTOFCalOnline) {
532 man->Put(fTOFCalOnline,id,md);
535 //_____________________________________________________________________________
536 void AliTOFcalib::WriteParOnlinePulserOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
538 //Write calibration parameters from pulser to the CDB
541 AliCDBManager *man = AliCDBManager::Instance();
542 const Char_t *sel1 = "Pulser" ; // to be consistent with TOFPreprocessor
543 TString out(Form("%s/%s",sel,sel1));
544 AliDebug(2,Form("Writing TOF online calib obj from pulser on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
545 AliCDBId id(out,fFirstRun,fLastRun);
546 AliCDBMetaData *md = new AliCDBMetaData();
547 md->SetResponsible("Chiara Zampolli");
548 if (!fTOFCalOnlinePulser) {
551 man->Put(fTOFCalOnlinePulser,id,md);
554 //_____________________________________________________________________________
555 void AliTOFcalib::WriteParOnlineNoiseOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
557 //Write calibration parameters from noise to the CDB
560 AliCDBManager *man = AliCDBManager::Instance();
561 const Char_t *sel1 = "Noise" ; // to be consistent with TOFPreprocessor
562 TString out(Form("%s/%s",sel,sel1));
563 AliDebug(2,Form("Writing TOF online calib obj from noise on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
564 AliCDBId id(out,fFirstRun,fLastRun);
565 AliCDBMetaData *md = new AliCDBMetaData();
566 md->SetResponsible("Chiara Zampolli");
567 if (!fTOFCalOnlineNoise) {
570 man->Put(fTOFCalOnlineNoise,id,md);
573 //_____________________________________________________________________________
574 void AliTOFcalib::WriteParOnlineHWOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
576 //Write calibration parameters from hardware to the CDB
579 AliCDBManager *man = AliCDBManager::Instance();
580 const Char_t *sel1 = "HW" ; // to be consistent with TOFPreprocessor
581 TString out(Form("%s/%s",sel,sel1));
582 AliDebug(2,Form("Writing TOF online calib obj from hardware on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
583 AliCDBId id(out,fFirstRun,fLastRun);
584 AliCDBMetaData *md = new AliCDBMetaData();
585 md->SetResponsible("Chiara Zampolli");
586 if (!fTOFCalOnlineHW) {
589 man->Put(fTOFCalOnlineHW,id,md);
592 //_____________________________________________________________________________
594 void AliTOFcalib::WriteParOnlineOnCDB(const Char_t *sel)
596 //Write calibration parameters to the CDB with infinite validity
597 AliCDBManager *man = AliCDBManager::Instance();
598 const Char_t *sel1 = "ParOnline" ; // to be consistent with TOFPreprocessor
599 TString out(Form("%s/%s",sel,sel1));
600 AliCDBRunRange runrange(fFirstRun,fLastRun);
601 AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
602 AliCDBId id(out,runrange);
603 AliCDBMetaData *md = new AliCDBMetaData();
604 md->SetResponsible("Chiara Zampolli");
605 if (!fTOFCalOnline) {
608 man->Put(fTOFCalOnline,id,md);
611 //_____________________________________________________________________________
613 void AliTOFcalib::WriteParOnlinePulserOnCDB(const Char_t *sel)
615 //Write calibration parameters from pulser to the CDB with infinite validity
616 AliCDBManager *man = AliCDBManager::Instance();
617 const Char_t *sel1 = "Pulser" ; // to be consistent with TOFPreprocessor
618 TString out(Form("%s/%s",sel,sel1));
619 AliCDBRunRange runrange(fFirstRun,fLastRun);
620 AliDebug(2,Form("Writing TOF online calib obj from pulser on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
621 AliCDBId id(out,runrange);
622 AliCDBMetaData *md = new AliCDBMetaData();
623 md->SetResponsible("Chiara Zampolli");
624 if (!fTOFCalOnlinePulser) {
627 man->Put(fTOFCalOnlinePulser,id,md);
630 //_____________________________________________________________________________
632 void AliTOFcalib::WriteParOnlineNoiseOnCDB(const Char_t *sel)
634 //Write calibration parameters from noise to the CDB with infinite validity
635 AliCDBManager *man = AliCDBManager::Instance();
636 const Char_t *sel1 = "Noise" ; // to be consistent with TOFPreprocessor
637 TString out(Form("%s/%s",sel,sel1));
638 AliCDBRunRange runrange(fFirstRun,fLastRun);
639 AliDebug(2,Form("Writing TOF online calib obj from noise on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
640 AliCDBId id(out,runrange);
641 AliCDBMetaData *md = new AliCDBMetaData();
642 md->SetResponsible("Chiara Zampolli");
643 if (!fTOFCalOnlineNoise) {
646 man->Put(fTOFCalOnlineNoise,id,md);
649 //_____________________________________________________________________________
651 void AliTOFcalib::WriteParOnlineHWOnCDB(const Char_t *sel)
653 //Write calibration parameters from hardware to the CDB with infinite validity
654 AliCDBManager *man = AliCDBManager::Instance();
655 const Char_t *sel1 = "HW" ; // to be consistent with TOFPreprocessor
656 TString out(Form("%s/%s",sel,sel1));
657 AliCDBRunRange runrange(fFirstRun,fLastRun);
658 AliDebug(2,Form("Writing TOF online calib obj from harware on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
659 AliCDBId id(out,runrange);
660 AliCDBMetaData *md = new AliCDBMetaData();
661 md->SetResponsible("Chiara Zampolli");
662 if (!fTOFCalOnlineHW) {
665 man->Put(fTOFCalOnlineHW,id,md);
668 //_____________________________________________________________________________
670 void AliTOFcalib::WriteParOfflineOnCDB(const Char_t *sel, const Char_t *validity, Int_t minrun, Int_t maxrun)
672 //Write calibration parameters to the CDB
675 AliCDBManager *man = AliCDBManager::Instance();
676 const Char_t *sel1 = "ParOffline" ;
677 TString out(Form("%s/%s",sel,sel1));
678 AliDebug(2,Form("Writing TOF offline calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
679 AliCDBId id(out,fFirstRun,fLastRun);
680 AliCDBMetaData *md = new AliCDBMetaData();
681 md->SetResponsible("Chiara Zampolli");
682 md->SetComment(validity);
683 man->Put(fTOFCalOffline,id,md);
686 //_____________________________________________________________________________
688 void AliTOFcalib::WriteParOfflineOnCDB(const Char_t *sel, const Char_t *validity)
690 //Write calibration parameters to the CDB with infinite validity
691 AliCDBManager *man = AliCDBManager::Instance();
692 const Char_t *sel1 = "ParOffline" ;
693 TString out(Form("%s/%s",sel,sel1));
694 AliCDBRunRange runrange(fFirstRun,fLastRun);
695 AliDebug(2,Form("Writing TOF offline calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
696 AliCDBId id(out,runrange);
697 AliCDBMetaData *md = new AliCDBMetaData();
698 md->SetResponsible("Chiara Zampolli");
699 md->SetComment(validity);
700 man->Put(fTOFCalOffline,id,md);
703 //_____________________________________________________________________________
705 Bool_t AliTOFcalib::ReadConfigMapFromCDB(const Char_t *sel, Int_t nrun)
707 //Read calibration parameters from the CDB
708 AliCDBManager *man = AliCDBManager::Instance();
709 const Char_t *sel1 = "Config" ;
710 TString out(Form("%s/%s",sel,sel1));
711 AliCDBEntry *entry = man->Get(out,nrun);
713 AliFatal("Exiting, no CDB object (ConfigMap) found!!!");
716 if(!entry->GetObject()){
717 AliFatal("Exiting, no CDB object (ConfigMap) found!!!");
721 fConfigMap =(TMap*)entry->GetObject();
726 //_____________________________________________________________________________
728 Bool_t AliTOFcalib::ReadParOnlineDelayFromCDB(const Char_t *sel, Int_t nrun)
730 //Read calibration parameters from the CDB -------> new calib objs!!!!!
731 AliCDBManager *man = AliCDBManager::Instance();
732 const Char_t *sel1 = "ParOnlineDelay" ;
733 TString out(Form("%s/%s",sel,sel1));
734 AliCDBEntry *entry = man->Get(out,nrun);
736 AliFatal("Exiting, no CDB object (ParOnlineDelay) found!!!");
739 if(!entry->GetObject()){
740 AliFatal("Exiting, no CDB object (ParOnlineDelay) found!!!");
744 fCal =(AliTOFChannelOnlineArray*)entry->GetObject();
749 //_____________________________________________________________________________
751 Bool_t AliTOFcalib::ReadParOnlineStatusFromCDB(const Char_t *sel, Int_t nrun)
753 //Read calibration parameters from the CDB -------> new calib objs!!!!!
754 AliCDBManager *man = AliCDBManager::Instance();
755 const Char_t *sel1 = "Status" ;
756 TString out(Form("%s/%s",sel,sel1));
757 AliCDBEntry *entry = man->Get(out,nrun);
759 AliFatal("Exiting, no CDB object (Status) found!!!");
762 if(!entry->GetObject()){
763 AliFatal("Exiting, no CDB object (Status) found!!!");
767 fStatus =(AliTOFChannelOnlineStatusArray*)entry->GetObject();
772 //_____________________________________________________________________________
774 Bool_t AliTOFcalib::ReadParOnlineFromCDB(const Char_t *sel, Int_t nrun)
776 //Read calibration parameters from the CDB
777 AliCDBManager *man = AliCDBManager::Instance();
778 const Char_t *sel1 = "ParOnline" ;
779 TString out(Form("%s/%s",sel,sel1));
780 AliCDBEntry *entry = man->Get(out,nrun);
782 AliFatal("Exiting, no CDB object (ParOnline) found!!!");
785 if(!entry->GetObject()){
786 AliFatal("Exiting, no CDB object (ParOnline) found!!!");
790 fTOFCalOnline =(TObjArray*)entry->GetObject();
795 //_____________________________________________________________________________
797 Bool_t AliTOFcalib::ReadParOnlinePulserFromCDB(const Char_t *sel, Int_t nrun)
799 //Read calibration parameters from pulser from the CDB
800 AliCDBManager *man = AliCDBManager::Instance();
801 const Char_t *sel1 = "Pulser" ;
802 TString out(Form("%s/%s",sel,sel1));
803 AliCDBEntry *entry = man->Get(out,nrun);
805 AliFatal("Exiting, no CDB object (Pulser) found!!!");
808 if(!entry->GetObject()){
809 AliFatal("Exiting, no CDB object (Pulser) found!!!");
813 fTOFCalOnlinePulser =(TObjArray*)entry->GetObject();
818 //_____________________________________________________________________________
820 Bool_t AliTOFcalib::ReadParOnlineNoiseFromCDB(const Char_t *sel, Int_t nrun)
822 //Read calibration parameters from noise from the CDB
823 AliCDBManager *man = AliCDBManager::Instance();
824 const Char_t *sel1 = "Noise" ;
825 TString out(Form("%s/%s",sel,sel1));
826 AliCDBEntry *entry = man->Get(out,nrun);
828 AliFatal("Exiting, no CDB object (Noise) found!!!");
831 if(!entry->GetObject()){
832 AliFatal("Exiting, no CDB object (Noise) found!!!");
836 fTOFCalOnlineNoise =(TObjArray*)entry->GetObject();
841 //_____________________________________________________________________________
843 Bool_t AliTOFcalib::ReadParOnlineHWFromCDB(const Char_t *sel, Int_t nrun)
845 //Read calibration parameters from hardware from the CDB
846 AliCDBManager *man = AliCDBManager::Instance();
847 const Char_t *sel1 = "HW" ;
848 TString out(Form("%s/%s",sel,sel1));
849 AliCDBEntry *entry = man->Get(out,nrun);
851 AliFatal("Exiting, no CDB object (HW map) found!!!");
854 if(!entry->GetObject()){
855 AliFatal("Exiting, no CDB object (HW map) found!!!");
859 fTOFCalOnlineHW =(TObjArray*)entry->GetObject();
864 //_____________________________________________________________________________
866 Bool_t AliTOFcalib::ReadParOfflineFromCDB(const Char_t *sel, Int_t nrun)
868 //Read calibration parameters from the CDB
869 AliCDBManager *man = AliCDBManager::Instance();
870 const Char_t *sel1 = "ParOffline" ;
871 TString out(Form("%s/%s",sel,sel1));
872 AliCDBEntry *entry = man->Get(out,nrun);
874 AliFatal("Exiting, no CDB object (ParOffline) found!!!");
877 if(!entry->GetObject()){
878 AliFatal("Exiting, no CDB object (ParOffline) found!!!");
881 AliCDBMetaData * md = entry->GetMetaData();
882 fkValidity = md->GetComment();
883 fTOFCalOffline =(TObjArray*)entry->GetObject();
888 //_____________________________________________________________________________
889 void AliTOFcalib::WriteSimHistoOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun, TH1F *histo){
890 //Write Sim miscalibration parameters to the CDB
893 AliCDBManager *man = AliCDBManager::Instance();
894 const Char_t *sel1 = "SimHisto" ;
895 TString out(Form("%s/%s",sel,sel1));
896 AliCDBMetaData *mdhisto = new AliCDBMetaData();
897 mdhisto->SetResponsible("Chiara Zampolli");
898 AliCDBId id(out,minrun,maxrun);
899 man->Put(fTOFSimToT,id,mdhisto);
902 //_____________________________________________________________________________
903 Bool_t AliTOFcalib::ReadSimHistoFromCDB(const Char_t *sel, Int_t nrun)
905 //Read miscalibration parameters from the CDB
906 AliCDBManager *man = AliCDBManager::Instance();
910 const Char_t *sel1 = "SimHisto" ;
911 TString out(Form("%s/%s",sel,sel1));
912 AliCDBEntry *entry = man->Get(out,nrun);
914 AliFatal("Exiting, no CDB object (SimHisto) found!!!");
917 if(!entry->GetObject()){
918 AliFatal("Exiting, no CDB object (SimHisto) found!!!");
921 TH1F *histo =(TH1F*)entry->GetObject();
925 //_____________________________________________________________________________
926 void AliTOFcalib::WriteRecParOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun, AliTOFRecoParam *param){
927 //Write reconstruction parameters to the CDB
929 AliCDBManager *man = AliCDBManager::Instance();
930 AliCDBMetaData *md = new AliCDBMetaData();
931 md->SetResponsible("Silvia Arcelli");
932 const Char_t *sel1 = "RecoParam" ;
933 TString out(Form("%s/%s",sel,sel1));
934 AliCDBId id(out,minrun,maxrun);
936 TObjArray *arr=new TObjArray(1);
939 //man->Put(param,id,md);
942 //_____________________________________________________________________________
943 void AliTOFcalib::WriteRecParOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun, TObjArray *arr){
944 //Write reconstruction parameters to the CDB
946 AliCDBManager *man = AliCDBManager::Instance();
947 AliCDBMetaData *md = new AliCDBMetaData();
948 md->SetResponsible("Silvia Arcelli");
949 const Char_t *sel1 = "RecoParam" ;
950 TString out(Form("%s/%s",sel,sel1));
951 AliCDBId id(out,minrun,maxrun);
955 //_____________________________________________________________________________
956 AliTOFRecoParam * AliTOFcalib::ReadRecParFromCDB(const Char_t *sel, Int_t nrun, Int_t eventType)
958 //Read reconstruction parameters from the CDB
959 AliCDBManager *man = AliCDBManager::Instance();
960 const Char_t *sel1 = "RecoParam" ;
961 TString out(Form("%s/%s",sel,sel1));
962 AliCDBEntry *entry = man->Get(out,nrun);
964 AliFatal("Exiting, no CDB object (RecoParam) found!!!");
967 if(!entry->GetObject()){
968 AliFatal("Exiting, no CDB object (RecoParam) found!!!");
972 TObjArray *array = (TObjArray*)entry->GetObject();
973 AliTOFRecoParam *param=0x0;
974 if (eventType>=0 || eventType<array->GetEntries())
975 param=(AliTOFRecoParam*)array->At(eventType);
979 //-----------------------------------------------------------------------------
980 // Calibration methods
981 //-----------------------------------------------------------------------------
982 void AliTOFcalib::CreateTreeFromCDB(Int_t minrun, Int_t maxrun){
984 // creating the chain with the trees for calibration
985 // collecting them from reference data
986 // from minrun to maxrun
988 Float_t p[CHENTRIESSMALL];
990 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
991 fTree->Branch("nentries",&nentries,"nentries/I");
992 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
993 AliCDBManager *man = AliCDBManager::Instance();
994 AliCDBStorage *aStorage = man->GetStorage("local://$ALICE_ROOT/OCDB");
995 for (Int_t irun = minrun;irun<=maxrun;irun++){
996 AliCDBEntry *entry = aStorage->Get("TOF/RefData/TreeForCalib",irun);
998 AliInfo(Form("No entry found for run %i",irun));
1001 TTree *tree = (TTree*)entry->GetObject();
1002 tree->SetBranchAddress("nentries",&nentries);
1003 tree->SetBranchAddress("TOFentries",p);
1004 fTree->CopyEntries(tree);
1008 AliInfo(Form("Number of runs being analyzed %i",fNruns));
1010 //-----------------------------------------------------------------------------
1011 void AliTOFcalib::CreateTreeFromGrid(Int_t minrun, Int_t maxrun){
1013 // creating the chain with the trees for calibration
1014 // collecting them from the Grid
1015 // from minrun to maxrun
1017 Float_t p[CHENTRIESSMALL];
1019 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
1020 fTree->SetDirectory(0);
1021 fTree->Branch("nentries",&nentries,"nentries/I");
1022 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
1023 AliInfo("connected to alien");
1024 TGrid::Connect("alien://");
1027 for (Int_t irun = minrun;irun<=maxrun;irun++){
1028 filename = Form("alien:///alice/cern.ch/user/c/czampolli/TOFCalibReference_%i.root",irun);
1029 TFile *filegrid = TFile::Open(filename.Data(),"READ");
1030 TTree *tree = (TTree*)filegrid->Get("T");
1031 tree->SetBranchAddress("nentries",&nentries);
1032 tree->SetBranchAddress("TOFentries",p);
1033 fTree->CopyEntries(tree);
1038 AliInfo(Form("Number of runs being analyzed %i",fNruns));
1040 //-----------------------------------------------------------------------------
1041 void AliTOFcalib::CreateTreeFromFile(Int_t minrun, Int_t maxrun){
1043 // creating the tree with the trees for calibration
1044 // collecting them from reference data (from file)
1045 // from minrun to maxrun
1047 Float_t p[CHENTRIESSMALL];
1049 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
1050 fTree->SetDirectory(0);
1051 fTree->Branch("nentries",&nentries,"nentries/I");
1052 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
1054 for (Int_t irun = minrun;irun<=maxrun;irun++){
1055 filename = Form("$ALICE_ROOT/TOF/RefData/TreeForCalib/fileout_%i.root",irun);
1056 TFile *file = new TFile(filename.Data(),"READ");
1057 TTree *tree = (TTree*)file->Get("T");
1058 tree->SetBranchAddress("nentries",&nentries);
1059 tree->SetBranchAddress("TOFentries",p);
1060 fTree->CopyEntries(tree);
1067 AliInfo(Form("Number of runs being analyzed %i",fNruns));
1069 //-----------------------------------------------------------------------------
1070 void AliTOFcalib::CreateChainFromGrid(Int_t minrun, Int_t maxrun){
1072 // creating the chain with the trees for calibration
1073 // collecting them from the Grid
1074 // from minrun to maxrun
1076 fChain = new TChain("T");
1077 AliInfo("connected to alien");
1078 TGrid::Connect("alien://");
1081 for (Int_t irun = minrun;irun<=maxrun;irun++){
1082 filename = Form("alien:///alice/cern.ch/user/c/czampolli/TOFCalibReference_%i.root",irun);
1083 fChain->Add(filename.Data());
1087 AliInfo(Form("Number of runs being analyzed %i",fNruns));
1089 //-----------------------------------------------------------------------------
1090 Int_t AliTOFcalib::Calibrate(Int_t ichmin, Int_t ichmax, Option_t *optionSave, Option_t *optionFit){
1092 // calibrating summing more than one channels
1093 // computing calibration parameters
1095 // 0 -> everything was ok
1096 // 1 -> no tree for calibration found
1097 // 2 -> not enough statistics to perform calibration
1098 // 3 -> problems with arrays
1100 TH1::AddDirectory(0);
1102 AliInfo(Form("*** Calibrating Histograms %s, summing more channels, from channel %i, to channel %i, storing Calib Pars in channel %i", GetName(),ichmin,ichmax,ichmin)) ;
1103 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1104 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1106 Float_t p[CHENTRIESSMALL];
1108 //fTree->SetBranchAddress("nentries",&nentries);
1109 //fTree->SetBranchAddress("TOFentries",p);
1110 fChain->SetBranchAddress("nentries",&nentries);
1111 fChain->SetBranchAddress("TOFentries",p);
1113 Float_t ntracksTotalmean =0;
1114 for (Int_t i=ichmin; i<ichmax; i++){
1116 for (Int_t irun=0;irun<fNruns;irun++){
1117 ientry = i+irun*fNChannels;
1118 //fTree->GetEntry(ientry);
1119 fChain->GetEntry(ientry);
1120 Int_t ntracksRun=nentries/3;
1121 ntracksTotalmean+=ntracksRun;
1125 if (ntracksTotalmean < MEANENTRIES) {
1126 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
1130 //filling ToT and Time arrays
1132 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
1133 Float_t minToT = 0; // ns
1134 Float_t maxToT = 4.88; // ns
1136 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1137 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1138 Int_t ntracksTotal = 0;
1139 Int_t ntracksRun = 0;
1140 Double_t binsProfile[101]; // sized larger than necessary, the correct
1141 // dim being set in the booking of the profile
1142 Int_t nusefulbins=0;
1144 for (Int_t i = ichmin;i<ichmax;i++){
1146 for (Int_t irun=0;irun<fNruns;irun++){
1147 ientry = i+irun*fNChannels;
1148 //fTree->GetEntry(ientry);
1149 fChain->GetEntry(ientry);
1150 ntracksTotal+=nentries/3;
1151 ntracksRun=nentries/3;
1152 AliDebug(2,Form("run %i, channel %i, nentries = %i, ntracks = %i",irun,i,nentries, ntracksRun));
1153 for (Int_t j=0;j<ntracksRun;j++){
1154 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1155 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1156 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1157 Float_t tot = p[idxexToT];
1158 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1159 meantime+=p[idxexTime]-p[idxexExTime];
1164 nusefulbins = FindBins(hToT,&binsProfile[0]);
1165 if (ntracksTotal != 0){
1166 meantime/=ntracksTotal;
1168 AliDebug(2, Form("meantime = %f",meantime));
1170 for (Int_t j=1;j<=nusefulbins;j++) {
1171 AliDebug(2,Form(" summing channels from %i to %i, nusefulbins = %i, bin %i = %f",ichmin,ichmax,nusefulbins,j,binsProfile[j]));
1174 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1175 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1177 for (Int_t irun=0;irun<fNruns;irun++){
1179 for (Int_t i=ichmin; i<ichmax; i++){
1180 ientry = i+irun*fNChannels;
1181 //fTree->GetEntry(ientry);
1182 fChain->GetEntry(ientry);
1183 ntracksRun=nentries/3;
1184 for (Int_t j=0;j<ntracksRun;j++){
1185 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1186 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1187 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1188 Float_t tot = p[idxexToT];
1189 Float_t time = p[idxexTime]-p[idxexExTime];
1190 AliDebug (2, Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1191 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1192 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1197 hSlewingProf->Fit("pol5",optionFit,"",0,4);
1198 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1200 for(Int_t kk=0;kk<6;kk++){
1201 par[kk]=calibfunc->GetParameter(kk);
1202 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1205 if(strstr(optionSave,"save")){
1206 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
1208 TString profName=Form("Profile%06i_%06i",ichmin,ichmax);
1209 TString timeTotName=Form("TimeTot%06i_%06i",ichmin,ichmax);
1210 TString totName=Form("Tot%06i_%06i",ichmin,ichmax);
1211 TString deltaName=Form("Delta%06i_%06i",ichmin,ichmax);
1212 hSlewingProf->Write(profName);
1213 htimetot->Write(timeTotName);
1214 hToT->Write(totName);
1215 hdeltaTime->Write(deltaName);
1223 delete hSlewingProf;
1230 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ichmin);
1231 calChannel->SetSlewPar(par);
1232 WriteParOfflineOnCDB("TOF/Calib","valid");
1235 //----------------------------------------------------------------------------
1236 Int_t AliTOFcalib::Calibrate(Int_t i, Option_t *optionSave, Option_t *optionFit){
1238 // computing calibration parameters for channel i
1240 // 0 -> everything was ok
1241 // 1 -> no tree for calibration found
1242 // 2 -> not enough statistics to perform calibration
1243 // 3 -> problems with arrays
1245 TH1::AddDirectory(0);
1247 AliInfo(Form("*** Calibrating Histograms (one channel) %s", GetName())) ;
1248 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1249 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1251 Float_t p[MAXCHENTRIESSMALL];
1253 //fTree->SetBranchAddress("nentries",&nentries);
1254 //fTree->SetBranchAddress("TOFentries",p);
1255 fChain->SetBranchAddress("nentries",&nentries);
1256 fChain->SetBranchAddress("TOFentries",p);
1258 Float_t ntracksTotal =0;
1259 for (Int_t irun=0;irun<fNruns;irun++){
1261 ientry = i+irun*fNChannels;
1262 //fTree->GetEntry(ientry);
1263 fChain->GetEntry(ientry);
1264 ntracksTotal+=nentries/3;
1267 if (ntracksTotal < MEANENTRIES) {
1268 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotal));
1272 //filling ToT and Time arrays
1274 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
1275 Float_t minToT = 0; // ns
1276 Float_t maxToT = 4.88; // ns
1278 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1279 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1280 Int_t ntracksRun = 0;
1281 Double_t binsProfile[101]; // sized larger than necessary, the correct
1282 // dim being set in the booking of the profile
1283 Int_t nusefulbins=0;
1285 for (Int_t irun=0;irun<fNruns;irun++){
1287 ientry = i+irun*fNChannels;
1288 //fTree->GetEntry(ientry);
1289 fChain->GetEntry(ientry);
1290 ntracksRun=nentries/3;
1291 AliDebug(2,Form("run %i, channel %i, nentries = %i, ntracksRun = %i",irun, i ,nentries, ntracksRun));
1292 for (Int_t j=0;j<ntracksRun;j++){
1293 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1294 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1295 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1296 Float_t tot = p[idxexToT];
1297 meantime+=p[idxexTime]-p[idxexExTime];
1298 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1303 nusefulbins = FindBins(hToT,&binsProfile[0]);
1304 meantime/=ntracksTotal;
1305 AliDebug(2,Form("meantime = %f",meantime));
1307 for (Int_t j=1;j<=nusefulbins;j++) {
1308 AliDebug(2,Form(" channel %i, nusefulbins = %i, bin %i = %f",i,nusefulbins,j,binsProfile[j]));
1311 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1312 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1313 for (Int_t irun=0;irun<fNruns;irun++){
1315 ientry = i+irun*fNChannels;
1316 //fTree->GetEntry(ientry);
1317 fChain->GetEntry(ientry);
1318 ntracksRun=nentries/3;
1319 for (Int_t j=0;j<ntracksRun;j++){
1320 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1321 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1322 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1323 Float_t tot = p[idxexToT];
1324 Float_t time = p[idxexTime]-p[idxexExTime];
1325 AliDebug (2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1326 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1327 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1331 hSlewingProf->Fit("pol5",optionFit,"",0,4);
1332 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1334 for(Int_t kk=0;kk<6;kk++){
1335 par[kk]=calibfunc->GetParameter(kk);
1336 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1340 if(strstr(optionSave,"save")){
1341 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
1343 TString profName=Form("Profile%06i",i);
1344 TString timeTotName=Form("TimeTot%06i",i);
1345 TString totName=Form("Tot%06i",i);
1346 TString deltaName=Form("Delta%06i",i);
1347 hSlewingProf->Write(profName);
1348 htimetot->Write(timeTotName);
1349 hToT->Write(totName);
1350 hdeltaTime->Write(deltaName);
1358 delete hSlewingProf;
1365 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(i);
1366 calChannel->SetSlewPar(par);
1367 WriteParOfflineOnCDB("TOF/Calib","valid");
1370 //----------------------------------------------------------------------------
1371 Int_t AliTOFcalib::Calibrate(Int_t nch, Int_t *ch, Option_t *optionSave, Option_t *optionFit){
1373 // calibrating an array of channels
1374 // computing calibration parameters
1376 // 0 -> everything was ok
1377 // 1 -> no tree for calibration found
1378 // 2 -> not enough statistics to perform calibration
1379 // 3 -> problems with arrays
1381 TH1::AddDirectory(0);
1383 AliInfo(Form("*** Calibrating Histograms %s, number of channels = %i", GetName(),nch)) ;
1384 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1385 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1386 for (Int_t ich=0; ich<nch; ich++){
1388 AliInfo(Form("Calibrating channel = %i",i )) ;
1390 Float_t p[MAXCHENTRIESSMALL];
1392 //fTree->SetBranchAddress("nentries",&nentries);
1393 //fTree->SetBranchAddress("TOFentries",p);
1394 fChain->SetBranchAddress("nentries",&nentries);
1395 fChain->SetBranchAddress("TOFentries",p);
1397 Float_t ntracksTotalmean =0;
1398 for (Int_t ich=0; ich<nch; ich++){
1401 for (Int_t irun=0;irun<fNruns;irun++){
1402 ientry = i+irun*fNChannels;
1403 //fTree->GetEntry(ientry);
1404 fChain->GetEntry(ientry);
1405 ntracksTotalmean+=nentries/3;
1409 ntracksTotalmean/=nch;
1410 if (ntracksTotalmean < MEANENTRIES) {
1411 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
1415 //filling ToT and Time arrays
1417 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
1418 Float_t minToT = 0; // ns
1419 Float_t maxToT = 4.88; // ns
1420 TFile * fileProf=0x0;
1421 if(strstr(optionSave,"save")){
1422 fileProf = new TFile("TOFCalibSave.root","recreate");
1424 for (Int_t ich=0; ich<nch; ich++) {
1425 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1426 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1427 Double_t binsProfile[101]; // sized larger than necessary, the correct
1428 // dim being set in the booking of the profile
1429 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1430 Int_t ntracksTotal = 0;
1431 Int_t ntracksRun = 0;
1432 Int_t nusefulbins=0;
1435 for (Int_t irun=0;irun<fNruns;irun++){
1436 i = ch[ich]+irun*fNChannels;
1437 AliDebug(2,Form("Calibrating channel %i",i));
1438 //fTree->GetEntry(i);
1439 fChain->GetEntry(i);
1440 ntracksTotal+=nentries/3;
1442 if (ntracksTotal < MEANENTRIES) {
1443 AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %d), not calibrating channel and continuing.....",i,ntracksTotal));
1447 for (Int_t irun=0;irun<fNruns;irun++){
1448 i = ch[ich]+irun*fNChannels;
1449 //fTree->GetEntry(i);
1450 fChain->GetEntry(i);
1451 ntracksRun=nentries/3;
1452 for (Int_t j=0;j<ntracksRun;j++){
1453 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1454 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1455 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1456 Float_t tot = p[idxexToT];
1457 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1458 meantime+=p[idxexTime]-p[idxexExTime];
1463 nusefulbins = FindBins(hToT,&binsProfile[0]);
1464 meantime/=ntracksTotal;
1465 for (Int_t j=1;j<=nusefulbins;j++) {
1466 AliDebug(2,Form(" channel %i, nusefulbins = %i, bin %i = %f",i,nusefulbins,j,binsProfile[j]));
1469 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1470 for (Int_t irun=0;irun<fNruns;irun++){
1471 i = ch[ich]+irun*fNChannels;
1472 //fTree->GetEntry(i);
1473 fChain->GetEntry(i);
1474 ntracksRun=nentries/3;
1475 for (Int_t j=0;j<ntracksRun;j++){
1476 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1477 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1478 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1479 Float_t tot = p[idxexToT];
1480 Float_t time = p[idxexTime]-p[idxexExTime];
1481 AliDebug(2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1482 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1483 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1487 hSlewingProf->Fit("pol5",optionFit,"",1,4);
1488 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1490 for(Int_t kk=0;kk<6;kk++){
1491 par[kk]=calibfunc->GetParameter(kk);
1492 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1495 if(strstr(optionSave,"save") && fileProf){
1496 TString profName=Form("Profile%06i",i);
1497 TString timeTotName=Form("TimeTot%06i",i);
1498 TString totName=Form("Tot%06i",i);
1499 TString deltaName=Form("Delta%06i",i);
1501 hSlewingProf->Write(profName);
1502 htimetot->Write(timeTotName);
1503 hToT->Write(totName);
1504 hdeltaTime->Write(deltaName);
1507 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(i);
1508 calChannel->SetSlewPar(par);
1511 delete hSlewingProf;
1519 if(strstr(optionSave,"save") && fileProf){
1524 WriteParOfflineOnCDB("TOF/Calib","valid");
1528 //----------------------------------------------------------------------------
1529 Int_t AliTOFcalib::CalibrateFromProfile(Int_t ich, Option_t *optionSave, Option_t *optionFit){
1531 // computing calibration parameters using the old profiling algo
1533 // 0 -> everything was ok
1534 // 1 -> no tree for calibration found
1535 // 2 -> not enough statistics to perform calibration
1536 // 3 -> problems with arrays
1538 TH1::AddDirectory(0);
1540 AliInfo(Form("*** Calibrating Histograms From Profile %s", GetName())) ;
1541 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1542 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1543 Float_t p[MAXCHENTRIESSMALL];
1545 Int_t ntracksTotal=0;
1546 //fTree->SetBranchAddress("nentries",&nentries);
1547 //fTree->SetBranchAddress("TOFentries",p);
1548 fChain->SetBranchAddress("nentries",&nentries);
1549 fChain->SetBranchAddress("TOFentries",p);
1551 for (Int_t irun=0;irun<fNruns;irun++){
1552 Int_t i = ich+irun*fNChannels;
1553 //fTree->GetEntry(i);
1554 fChain->GetEntry(i);
1555 ntracksTotal+=nentries/3;
1558 if (ntracksTotal < MEANENTRIES) {
1559 AliInfo(Form(" Too small mean number of entires per channel (mean number = %d) not calibrating and exiting.....",ntracksTotal));
1563 TH1F * hProf = Profile(ich);
1564 hProf->Fit("pol5",optionFit,"",0,4);
1565 TF1 * calibfunc = (TF1*)hProf->GetFunction("pol5");
1567 for(Int_t kk=0;kk<6;kk++){
1568 par[kk]=calibfunc->GetParameter(kk);
1569 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1572 if(strstr(optionSave,"save")){
1573 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
1575 TString profName=Form("Profile%06i",ich);
1576 hProf->Write(profName);
1584 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ich);
1585 calChannel->SetSlewPar(par);
1586 WriteParOfflineOnCDB("TOF/Calib","valid");
1589 //----------------------------------------------------------------------------
1590 Int_t AliTOFcalib::Calibrate(Option_t *optionSave, Option_t *optionFit){
1592 // calibrating the whole TOF
1593 // computing calibration parameters
1595 // 0 -> everything was ok
1596 // 1 -> no tree for calibration found
1597 // 2 -> not enough statistics to perform calibration
1598 // 3 -> problems with arrays
1600 TH1::AddDirectory(0);
1602 AliInfo(Form("*** Calibrating Histograms %s, all channels", GetName())) ;
1603 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1604 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1606 TFile * fileProf=0x0;
1607 if(strstr(optionSave,"save")){
1608 fileProf = new TFile("TOFCalibSave.root","recreate");
1611 Float_t p[MAXCHENTRIESSMALL];
1613 //fTree->SetBranchAddress("nentries",&nentries);
1614 //fTree->SetBranchAddress("TOFentries",p);
1615 fChain->SetBranchAddress("nentries",&nentries);
1616 fChain->SetBranchAddress("TOFentries",p);
1618 Float_t ntracksTotalmean =0;
1619 for (Int_t ii=0; ii<fNChannels; ii++){
1620 for (Int_t irun=0;irun<fNruns;irun++){
1621 Int_t i = ii+irun*fNChannels;
1622 //fTree->GetEntry(i);
1623 fChain->GetEntry(i);
1624 ntracksTotalmean+=nentries/3;
1628 ntracksTotalmean/=fNChannels;
1629 if (ntracksTotalmean < MEANENTRIES) {
1630 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
1634 //filling ToT and Time arrays
1636 Int_t nbinToT = 100; // ToT bin width in Profile = 50.0 ps
1637 Float_t minToT = 0; // ns
1638 Float_t maxToT = 4.88;// ns
1639 for (Int_t ii=0; ii<fNChannels; ii++) {
1640 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1641 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1642 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1643 if (ii%1000 == 0) AliDebug(1,Form("Calibrating channel %i ",ii));
1645 Int_t nusefulbins=0;
1646 Double_t binsProfile[101]; // sized larger than necessary, the correct
1647 // dim being set in the booking of the profile
1648 Int_t ntracksRun = 0;
1649 Int_t ntracksTotal = 0;
1650 for (Int_t irun=0;irun<fNruns;irun++){
1651 Int_t i = ii+irun*fNChannels;
1652 //fTree->GetEntry(i);
1653 fChain->GetEntry(i);
1654 ntracksTotal+=nentries/3;
1656 if (ntracksTotal < MEANENTRIES) {
1657 AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %d), not calibrating channel and continuing.....",ii,ntracksTotal));
1661 for (Int_t irun=0;irun<fNruns;irun++){
1662 Int_t i = ii+irun*fNChannels;
1663 //fTree->GetEntry(i);
1664 fChain->GetEntry(i);
1665 ntracksRun=nentries/3;
1666 for (Int_t j=0;j<ntracksRun;j++){
1667 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1668 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1669 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1670 Float_t tot = p[idxexToT];
1671 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1672 meantime+=p[idxexTime]-p[idxexExTime];
1676 nusefulbins = FindBins(hToT,&binsProfile[0]);
1677 meantime/=ntracksTotal;
1678 for (Int_t j=0;j<nusefulbins;j++) {
1679 AliDebug(2,Form(" channel %i, usefulbin = %i, low edge = %f",ii,j,binsProfile[j]));
1681 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1682 for (Int_t irun=0;irun<fNruns;irun++){
1683 Int_t i = ii+irun*fNChannels;
1684 //fTree->GetEntry(i);
1685 fChain->GetEntry(i);
1686 ntracksRun=nentries/3;
1687 for (Int_t j=0;j<ntracksRun;j++){
1688 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1689 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1690 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1691 Float_t tot = p[idxexToT];
1692 Float_t time = p[idxexTime]-p[idxexExTime];
1693 AliDebug (2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1694 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1695 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1698 hSlewingProf->Fit("pol5",optionFit,"",1,4);
1699 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1701 for(Int_t kk=0;kk<6;kk++){
1702 par[kk]=calibfunc->GetParameter(kk);
1703 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1706 if(strstr(optionSave,"save") && fileProf){
1707 TString profName=Form("Profile%06i",ii);
1708 TString timeTotName=Form("TimeTot%06i",ii);
1709 TString totName=Form("Tot%06i",ii);
1710 TString deltaName=Form("Delta%06i",ii);
1712 hSlewingProf->Write(profName);
1713 htimetot->Write(timeTotName);
1714 hToT->Write(totName);
1715 hdeltaTime->Write(deltaName);
1717 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ii);
1718 calChannel->SetSlewPar(par);
1722 delete hSlewingProf;
1730 if(strstr(optionSave,"save")){
1735 WriteParOfflineOnCDB("TOF/Calib","valid");
1739 //-----------------------------------------------------------------------
1740 TH1F* AliTOFcalib::Profile(Int_t ich)
1744 Float_t p[MAXCHENTRIESSMALL];
1746 //fTree->SetBranchAddress("nentries",&nentries);
1747 //fTree->SetBranchAddress("TOFentries",p);
1748 fChain->SetBranchAddress("nentries",&nentries);
1749 fChain->SetBranchAddress("TOFentries",p);
1751 //Prepare histograms for Slewing Correction
1752 const Int_t knbinToT = 100;
1753 Int_t nbinTime = 200;
1754 Float_t minTime = -5.5; //ns
1755 Float_t maxTime = 5.5; //ns
1756 Float_t minToT = 0; //ns
1757 Float_t maxToT = 5.; //ns
1758 Float_t deltaToT = (maxToT-minToT)/knbinToT;
1759 Double_t mTime[knbinToT+1],mToT[knbinToT+1],meanTime[knbinToT+1], meanTime2[knbinToT+1],vToT[knbinToT+1], vToT2[knbinToT+1],meanToT[knbinToT+1],meanToT2[knbinToT+1],vTime[knbinToT+1],vTime2[knbinToT+1],xlow[knbinToT+1],sigmaTime[knbinToT+1];
1760 Int_t n[knbinToT+1], nentrx[knbinToT+1];
1761 Double_t sigmaToT[knbinToT+1];
1762 for (Int_t i = 0; i < knbinToT+1 ; i++){
1780 TH2F* hSlewing = new TH2F("hSlewing", "hSlewing", knbinToT, minToT, maxToT, nbinTime, minTime, maxTime);
1781 Int_t ntracksRun = 0;
1782 TH1F *histo = new TH1F("histo", "1D Time vs ToT", knbinToT, minToT, maxToT);
1783 for (Int_t irun=0;irun<fNruns;irun++){
1784 Int_t i = ich+irun*fNChannels;
1785 //fTree->GetEntry(i);
1786 fChain->GetEntry(i);
1787 ntracksRun=nentries/3;
1788 for (Int_t j=0;j<ntracksRun;j++){
1789 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1790 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1791 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1792 Float_t tot = p[idxexToT];
1793 Float_t time = p[idxexTime]-p[idxexExTime];
1794 Int_t nx = (Int_t)((tot-minToT)/deltaToT)+1;
1795 if ((tot != 0) && ( time!= 0)){
1797 vTime2[nx]+=time*time;
1801 hSlewing->Fill(tot,time);
1805 Int_t nbinsToT=hSlewing->GetNbinsX();
1806 if (nbinsToT != knbinToT) {
1807 AliError("Profile :: incompatible numbers of bins");
1812 for (Int_t i=1;i<=nbinsToT;i++){
1814 n[usefulBins]+=nentrx[i];
1815 if (n[usefulBins]==0 && i == nbinsToT) {
1818 meanTime[usefulBins]+=vTime[i];
1819 meanTime2[usefulBins]+=vTime2[i];
1820 meanToT[usefulBins]+=vToT[i];
1821 meanToT2[usefulBins]+=vToT2[i];
1822 if (n[usefulBins]<10 && i!=nbinsToT) continue;
1823 mTime[usefulBins]=meanTime[usefulBins]/n[usefulBins];
1824 mToT[usefulBins]=meanToT[usefulBins]/n[usefulBins];
1825 sigmaTime[usefulBins]=TMath::Sqrt(1./n[usefulBins]/n[usefulBins]
1826 *(meanTime2[usefulBins]-meanTime[usefulBins]
1827 *meanTime[usefulBins]/n[usefulBins]));
1828 if ((1./n[usefulBins]/n[usefulBins]
1829 *(meanToT2[usefulBins]-meanToT[usefulBins]
1830 *meanToT[usefulBins]/n[usefulBins]))< 0) {
1831 AliError(" too small radical" );
1832 sigmaToT[usefulBins]=0;
1835 sigmaToT[usefulBins]=TMath::Sqrt(1./n[usefulBins]/n[usefulBins]
1836 *(meanToT2[usefulBins]-meanToT[usefulBins]
1837 *meanToT[usefulBins]/n[usefulBins]));
1842 for (Int_t i=0;i<usefulBins;i++){
1843 Int_t binN = (Int_t)((mToT[i]-minToT)/deltaToT)+1;
1844 histo->Fill(mToT[i],mTime[i]);
1845 histo->SetBinError(binN,sigmaTime[i]);
1852 //----------------------------------------------------------------------------
1853 Int_t AliTOFcalib::FindBins(TH1F* h, Double_t *binsProfile) const{
1855 // to determine the bins for ToT histo
1859 Int_t nbin = h->GetNbinsX();
1860 Int_t nentries = (Int_t)h->GetEntries();
1861 Float_t max = h->GetBinLowEdge(nbin);
1862 Int_t nusefulbins=0;
1864 // setting maxvalue of entries per bin
1865 if (nentries <= 60) maxcont = 2;
1866 else if (nentries <= 100) maxcont = 5;
1867 else if (nentries <= 500) maxcont = 10;
1869 for (Int_t j=1;j<=nbin;j++) {
1870 cont += (Int_t)h->GetBinContent(j);
1874 binsProfile[nusefulbins-1]=h->GetBinLowEdge(startBin);
1883 binsProfile[nusefulbins-1]=h->GetBinLowEdge(startBin);
1884 binsProfile[nusefulbins]=max;
1887 binsProfile[nusefulbins]=h->GetBinLowEdge(startBin);
1895 //----------------------------------------------------------------------------
1898 AliTOFcalib::CreateDeltaBCOffset()
1901 * create deltaBC offset
1904 if (fDeltaBCOffset) {
1905 AliWarning("DeltaBCOffset object already defined, cannot create a new one");
1908 fDeltaBCOffset = new AliTOFDeltaBCOffset();
1911 //----------------------------------------------------------------------------
1914 AliTOFcalib::CreateCTPLatency()
1917 * create CTP latency
1921 AliWarning("CTPLatency object already defined, cannot create a new one");
1924 fCTPLatency = new AliTOFCTPLatency();
1927 //----------------------------------------------------------------------------
1930 AliTOFcalib::CreateT0Fill()
1937 AliWarning("T0Fill object already defined, cannot create a new one");
1940 fT0Fill = new AliTOFT0Fill();
1943 //----------------------------------------------------------------------------
1946 AliTOFcalib::CreateRunParams()
1953 AliWarning("RunParams object already defined, cannot create a new one");
1956 fRunParams = new AliTOFRunParams();
1959 //----------------------------------------------------------------------------
1962 AliTOFcalib::WriteDeltaBCOffsetOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
1965 * deltaBC offset on CDB
1968 if (!fDeltaBCOffset) return;
1969 AliCDBId id(Form("%s/DeltaBCOffset", sel), minrun, maxrun);
1970 AliCDBMetaData *md = new AliCDBMetaData();
1971 md->SetResponsible("Roberto Preghenella");
1972 AliCDBManager *man = AliCDBManager::Instance();
1973 man->Put(fDeltaBCOffset, id, md);
1974 AliDebug(2,Form("DeltaBCOffset written on CDB with run range [%i, %i] ",minrun ,maxrun));
1978 //----------------------------------------------------------------------------
1981 AliTOFcalib::WriteCTPLatencyOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
1984 * write CTP latency on CDB
1987 if (!fCTPLatency) return;
1988 AliCDBId id(Form("%s/CTPLatency", sel), minrun, maxrun);
1989 AliCDBMetaData *md = new AliCDBMetaData();
1990 md->SetResponsible("Roberto Preghenella");
1991 AliCDBManager *man = AliCDBManager::Instance();
1992 man->Put(fCTPLatency, id, md);
1993 AliDebug(2,Form("CTPLatency written on CDB with run range [%i, %i] ",minrun ,maxrun));
1997 //----------------------------------------------------------------------------
2000 AliTOFcalib::WriteT0FillOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
2003 * write event-time on CDB
2006 if (!fT0Fill) return;
2007 AliCDBId id(Form("%s/T0Fill", sel), minrun, maxrun);
2008 AliCDBMetaData *md = new AliCDBMetaData();
2009 md->SetResponsible("Roberto Preghenella");
2010 AliCDBManager *man = AliCDBManager::Instance();
2011 man->Put(fT0Fill, id, md);
2012 AliDebug(2,Form("T0Fill written on CDB with run range [%i, %i] ",minrun ,maxrun));
2016 //----------------------------------------------------------------------------
2019 AliTOFcalib::WriteRunParamsOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
2022 * write run params on CDB
2025 if (!fRunParams) return;
2026 AliCDBId id(Form("%s/RunParams", sel), minrun, maxrun);
2027 AliCDBMetaData *md = new AliCDBMetaData();
2028 md->SetResponsible("Roberto Preghenella");
2029 AliCDBManager *man = AliCDBManager::Instance();
2030 man->Put(fRunParams, id, md);
2031 AliDebug(2,Form("RunParams written on CDB with run range [%i, %i] ",minrun ,maxrun));
2035 //----------------------------------------------------------------------------
2038 AliTOFcalib::WriteReadoutEfficiencyOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
2041 * write readout efficiency on CDB
2044 if (!fReadoutEfficiency) return;
2045 AliCDBId id(Form("%s/ReadoutEfficiency", sel), minrun, maxrun);
2046 AliCDBMetaData *md = new AliCDBMetaData();
2047 md->SetResponsible("Roberto Preghenella");
2048 AliCDBManager *man = AliCDBManager::Instance();
2049 man->Put(fReadoutEfficiency, id, md);
2050 AliDebug(2,Form("ReadoutEfficiency written on CDB with run range [%i, %i] ",minrun ,maxrun));
2054 //----------------------------------------------------------------------------
2057 AliTOFcalib::WriteProblematicOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
2060 * write problematic on CDB
2063 if (!fProblematic) return;
2064 AliCDBId id(Form("%s/Problematic", sel), minrun, maxrun);
2065 AliCDBMetaData *md = new AliCDBMetaData();
2066 md->SetResponsible("Roberto Preghenella");
2067 AliCDBManager *man = AliCDBManager::Instance();
2068 man->Put(fProblematic, id, md);
2069 AliDebug(2,Form("Problematic written on CDB with run range [%i, %i] ",minrun ,maxrun));
2073 //----------------------------------------------------------------------------
2076 AliTOFcalib::ReadDeltaBCOffsetFromCDB(const Char_t *sel , Int_t nrun)
2079 * read deltaBC offset from CDB
2082 AliCDBManager *man = AliCDBManager::Instance();
2083 AliCDBEntry *entry = man->Get(Form("%s/DeltaBCOffset", sel),nrun);
2085 AliFatal("No DeltaBCOffset entry found in CDB");
2088 fDeltaBCOffset =(AliTOFDeltaBCOffset *)entry->GetObject();
2089 if(!fDeltaBCOffset){
2090 AliFatal("No DeltaBCOffset object found in CDB entry");
2096 //----------------------------------------------------------------------------
2099 AliTOFcalib::ReadCTPLatencyFromCDB(const Char_t *sel , Int_t nrun)
2102 * read CTP latency from CDB
2105 AliCDBManager *man = AliCDBManager::Instance();
2106 AliCDBEntry *entry = man->Get(Form("%s/CTPLatency", sel),nrun);
2108 AliFatal("No CTPLatency entry found in CDB");
2111 fCTPLatency =(AliTOFCTPLatency *)entry->GetObject();
2113 AliFatal("No CTPLatency object found in CDB entry");
2119 //----------------------------------------------------------------------------
2122 AliTOFcalib::ReadT0FillFromCDB(const Char_t *sel , Int_t nrun)
2125 * read event-time from CDB
2128 AliCDBManager *man = AliCDBManager::Instance();
2129 AliCDBEntry *entry = man->Get(Form("%s/T0Fill", sel),nrun);
2131 AliFatal("No T0Fill entry found in CDB");
2134 fT0Fill =(AliTOFT0Fill *)entry->GetObject();
2136 AliFatal("No T0Fill object found in CDB entry");
2142 //----------------------------------------------------------------------------
2145 AliTOFcalib::ReadRunParamsFromCDB(const Char_t *sel , Int_t nrun)
2148 * read run params from CDB
2151 AliCDBManager *man = AliCDBManager::Instance();
2152 AliCDBEntry *entry = man->Get(Form("%s/RunParams", sel),nrun);
2154 AliFatal("No RunParams entry found in CDB");
2157 fRunParams =(AliTOFRunParams *)entry->GetObject();
2159 AliFatal("No RunParams object found in CDB entry");
2165 //----------------------------------------------------------------------------
2168 AliTOFcalib::ReadLHCClockPhaseFromCDB(const Char_t *sel , Int_t nrun)
2171 * read LHC clock-phase from CDB
2174 AliCDBManager *man = AliCDBManager::Instance();
2175 AliCDBEntry *entry = man->Get(Form("%s/LHCClockPhase", sel),nrun);
2177 AliFatal("No LHCClockPhase entry found in CDB");
2180 fLHCClockPhase =(AliLHCClockPhase *)entry->GetObject();
2182 AliFatal("No LHCClockPhase object found in CDB entry");
2188 //----------------------------------------------------------------------------
2191 AliTOFcalib::ReadReadoutEfficiencyFromCDB(const Char_t *sel , Int_t nrun)
2194 * read readout efficiency from CDB
2197 AliCDBManager *man = AliCDBManager::Instance();
2198 AliCDBEntry *entry = man->Get(Form("%s/ReadoutEfficiency", sel),nrun);
2200 AliFatal("No ReadoutEfficiency entry found in CDB");
2203 fReadoutEfficiency = (TH1F *)entry->GetObject();
2204 if(!fReadoutEfficiency){
2205 AliFatal("No ReadoutEfficiency object found in CDB entry");
2211 //----------------------------------------------------------------------------
2214 AliTOFcalib::ReadProblematicFromCDB(const Char_t *sel , Int_t nrun)
2217 * read problematic from CDB
2220 AliCDBManager *man = AliCDBManager::Instance();
2221 AliCDBEntry *entry = man->Get(Form("%s/Problematic", sel),nrun);
2223 AliFatal("No Problematic entry found in CDB");
2226 fProblematic = (TH1C *)entry->GetObject();
2228 AliFatal("No Problematic object found in CDB entry");
2234 //----------------------------------------------------------------------------
2237 AliTOFcalib::Init(Int_t run)
2244 AliWarning("the class was already initialized, re-initialize it");
2248 /* read channel status array */
2249 if (!ReadParOnlineStatusFromCDB("TOF/Calib", run)) {
2250 AliError("cannot get \"Status\" object from OCDB");
2253 /* get par offline array */
2254 if (!ReadParOfflineFromCDB("TOF/Calib", run)) {
2255 AliError("cannot get \"ParOffline\" object from OCDB");
2258 /* get deltaBC offset obj */
2259 if (!ReadDeltaBCOffsetFromCDB("TOF/Calib", run)) {
2260 AliError("cannot get \"DeltaBCOffset\" object from OCDB");
2263 /* get CTP latency obj */
2264 if (!ReadCTPLatencyFromCDB("TOF/Calib", run)) {
2265 AliError("cannot get \"CTPLatency\" object from OCDB");
2268 /* get run params obj */
2269 if (!ReadRunParamsFromCDB("TOF/Calib", run)) {
2270 AliError("cannot get \"RunParams\" object from OCDB");
2273 /* get LHC clock-phase obj */
2274 if (!ReadLHCClockPhaseFromCDB("GRP/Calib", run)) {
2275 AliError("cannot get \"LHCClockPhase\" object from OCDB");
2278 /* get readout efficiency obj */
2279 if (!ReadReadoutEfficiencyFromCDB("TOF/Calib", run)) {
2280 AliError("cannot get \"ReadoutEfficiency\" object from OCDB");
2283 /* get readout efficiency obj */
2284 if (!ReadProblematicFromCDB("TOF/Calib", run)) {
2285 AliError("cannot get \"Problematic\" object from OCDB");
2288 /* get response params */
2289 TFile *responseFile = TFile::Open("$ALICE_ROOT/TOF/data/AliTOFresponsePar.root");
2290 if (!responseFile || !responseFile->IsOpen()) {
2291 AliError("cannot open \"ResponseParams\" local file");
2294 fResponseParams = (AliTOFResponseParams *)responseFile->Get("ResponseParams");
2295 if (!fResponseParams) {
2296 AliError("cannot get \"ResponseParams\" object from local file");
2299 responseFile->Close();
2301 /* check whether to use the clock phase */
2302 if (fRunParams->GetUseLHCClockPhase())
2303 fUseLHCClockPhase = kTRUE;
2305 if (fUseLHCClockPhase)
2306 AliInfo("calibration using BPTX LHC clock-phase");
2314 //----------------------------------------------------------------------------
2317 AliTOFcalib::GetTimeCorrection(Int_t index, Double_t tot, Int_t deltaBC, Int_t l0l1, UInt_t timestamp)
2320 * get time correction
2324 AliError("class not yet initialized. Initialize it before.");
2328 /* deal with L0-L1 orbit crossing (negative values) */
2329 if (l0l1 < 0) l0l1 += 3564;
2331 /* get calibration params */
2332 AliTOFChannelOffline *parOffline = (AliTOFChannelOffline *)fTOFCalOffline->At(index);
2333 Int_t deltaBCOffset = fDeltaBCOffset->GetDeltaBCOffset();
2334 Float_t ctpLatency = fCTPLatency->GetCTPLatency();
2335 Float_t tdcLatencyWindow = fStatus->GetLatencyWindow(index) * 1.e3;
2336 Float_t timezero = fRunParams->EvalT0(timestamp);
2337 Float_t clockphase = fLHCClockPhase->GetPhase(timestamp);
2338 /* check whether to remove mean T0.
2339 * useful when one wants to compute mean T0 */
2340 if (!fRemoveMeanT0) timezero = 0.;
2341 /* check whether to use the clock phase */
2342 if (fUseLHCClockPhase) timezero -= 1.e3 * clockphase;
2344 /* compute correction */
2346 /* deltaBC correction */
2347 deltaBC = deltaBCOffset; /* inhibit deltaBC correction for the time being */
2348 corr += (deltaBC - deltaBCOffset) * AliTOFGeometry::BunchCrossingBinWidth();
2349 /* L0-L1 latency correction */
2350 corr -= l0l1 * AliTOFGeometry::BunchCrossingBinWidth();
2351 /* CTP latency correction */
2353 /* TDC latency window correction */
2354 corr += tdcLatencyWindow;
2355 /* time-zero correction */
2357 /* time calibration correction */
2358 if (tot < AliTOFGeometry::SlewTOTMin())
2359 tot = AliTOFGeometry::SlewTOTMin();
2360 if (tot > AliTOFGeometry::SlewTOTMax())
2361 tot = AliTOFGeometry::SlewTOTMax();
2362 for (Int_t islew = 0; islew < 6; islew++)
2363 corr += parOffline->GetSlewPar(islew) * TMath::Power(tot, islew) * 1.e3;
2365 /* return correction */
2369 //----------------------------------------------------------------------------
2372 AliTOFcalib::CalibrateESD(AliESDEvent *event)
2379 AliError("class not yet initialized. Initialize it before.");
2383 /* loop over tracks */
2384 AliESDtrack *track = NULL;
2385 Int_t index, l0l1, deltaBC;
2386 Double_t time, tot, corr, texp[AliPID::kSPECIES];
2387 UInt_t timestamp = event->GetTimeStamp();
2388 for (Int_t itrk = 0; itrk < event->GetNumberOfTracks(); itrk++) {
2391 track = event->GetTrack(itrk);
2392 if (!track || !(track->GetStatus() & AliESDtrack::kTOFout)) continue;
2394 /* calibrate TOF signal */
2395 if (fCalibrateTOFsignal) {
2397 index = track->GetTOFCalChannel();
2398 time = track->GetTOFsignalRaw();
2399 tot = track->GetTOFsignalToT();
2400 l0l1 = track->GetTOFL0L1();
2401 deltaBC = track->GetTOFDeltaBC();
2402 /* get correction */
2403 corr = GetTimeCorrection(index, tot, deltaBC, l0l1, timestamp);
2404 /* apply correction */
2406 /* set new TOF signal */
2407 track->SetTOFsignal(time);
2410 /* correct expected time */
2412 /* get integrated times */
2413 track->GetIntegratedTimes(texp);
2414 /* loop over particle types and correct expected time */
2415 for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++)
2416 texp[ipart] += fResponseParams->EvalTExpCorr(ipart, track->P());
2417 /* set integrated times */
2418 track->SetIntegratedTimes(texp);
2425 //----------------------------------------------------------------------------
2428 AliTOFcalib::IsChannelEnabled(Int_t index, Bool_t checkEfficiency, Bool_t checkProblematic)
2431 * is channel enabled
2435 AliError("class not yet initialized. Initialize it before.");
2439 /* check bad status */
2440 if (fStatus->GetPulserStatus(index) == AliTOFChannelOnlineStatusArray::kTOFPulserBad) return kFALSE;
2441 if (fStatus->GetNoiseStatus(index) == AliTOFChannelOnlineStatusArray::kTOFNoiseBad) return kFALSE;
2442 if (fStatus->GetHWStatus(index) == AliTOFChannelOnlineStatusArray::kTOFHWBad) return kFALSE;
2443 if (checkEfficiency && !IsChannelEfficient(index)) return kFALSE;
2444 if (checkProblematic && IsChannelProblematic(index)) return kFALSE;
2451 //----------------------------------------------------------------------------
2454 AliTOFcalib::IsChannelEfficient(Int_t index)
2457 * is channel efficient
2461 AliError("class not yet initialized. Initialize it before.");
2465 /* check efficiency */
2466 if (fReadoutEfficiency->GetBinContent(index + 1) < 0.95) return kFALSE;
2471 //----------------------------------------------------------------------------
2474 AliTOFcalib::IsChannelProblematic(Int_t index)
2477 * is channel problematic
2481 AliError("class not yet initialized. Initialize it before.");
2485 /* check problematic */
2486 if (fProblematic->GetBinContent(index + 1) != 0) return kTRUE;
2491 //----------------------------------------------------------------------------
2494 AliTOFcalib::CalibrateTExp(AliESDEvent *event) const
2501 AliError("class not yet initialized. Initialize it before.");
2505 /* loop over tracks */
2506 AliESDtrack *track = NULL;
2507 Double_t texp[AliPID::kSPECIES];
2508 for (Int_t itrk = 0; itrk < event->GetNumberOfTracks(); itrk++) {
2511 track = event->GetTrack(itrk);
2512 if (!track || !(track->GetStatus() & AliESDtrack::kTOFout)) continue;
2514 /* get integrated times */
2515 track->GetIntegratedTimes(texp);
2516 /* loop over particle types and correct expected time */
2517 for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++)
2518 texp[ipart] += fResponseParams->EvalTExpCorr(ipart, track->P());
2519 /* set integrated times */
2520 track->SetIntegratedTimes(texp);
2526 //----------------------------------------------------------------------------
2529 AliTOFcalib::TuneForMC(AliESDEvent *event, Double_t resolution)
2535 /* get vertex spread and define T0-spread */
2536 Double_t diamond2 = TMath::Abs(event->GetSigma2DiamondZ());
2537 Double_t t0spread = TMath::Sqrt(diamond2) / 2.99792457999999984e-02;
2538 /* generate random startTime */
2539 Double_t startTime = gRandom->Gaus(0., t0spread);
2540 /* define extra smearing for resolution */
2541 Double_t defaultResolution = 80.;
2542 Double_t extraSmearing = 0.;
2543 if (resolution > defaultResolution)
2544 extraSmearing = TMath::Sqrt(resolution * resolution - defaultResolution * defaultResolution);
2546 /* loop over tracks */
2547 AliESDtrack *track = NULL;
2549 for (Int_t itrk = 0; itrk < event->GetNumberOfTracks(); itrk++) {
2551 track = event->GetTrack(itrk);
2552 if (!track) continue;
2553 /* check TOF match */
2554 if (!track->IsOn(AliESDtrack::kTOFout)) continue;
2555 /* check if channel is enabled */
2556 if (!IsChannelEnabled(track->GetTOFCalChannel())) {
2557 /* reset TOF status */
2558 track->ResetStatus(AliESDtrack::kTOFin);
2559 track->ResetStatus(AliESDtrack::kTOFout);
2560 track->ResetStatus(AliESDtrack::kTOFmismatch);
2561 track->ResetStatus(AliESDtrack::kTOFpid);
2563 /* get original time and manipulate it */
2564 time = track->GetTOFsignal();
2565 time += startTime; /* add start time */
2566 time += gRandom->Gaus(0., extraSmearing); /* extra smearing */
2567 time -= 25.; /* remove 25 ps to center the signal */
2568 track->SetTOFsignal(time);