]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TOF/AliTOFcalib.cxx
Fix for Savannah bug 74286
[u/mrichter/AliRoot.git] / TOF / AliTOFcalib.cxx
CommitLineData
6dc9348d 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
762446e0 16/*
7fffa85b 17$Log: AliTOFcalib.cxx,v $
18Revision 1.21 2007/11/02 15:41:49 hristov
19Provide return value if the function is not void
20
52be7fb0 21Revision 1.20 2007/10/26 15:13:50 zampolli
22Using a TChain instead of a TTree
23
296591ad 24Revision 1.19 2007/10/23 15:27:38 zampolli
25Rearrangement of Calibration objects for simulation
26
a7e9db2a 27Revision 1.16 2007/10/08 10:13:26 zampolli
28First Run and Last Run members added, infinite validity of calib obj implemented.
29
0cb9d099 30Revision 1.15 2007/10/04 13:23:28 zampolli
31Updates to handle functionalities in TOF online/offline calibration according to the latest schema
32
0a749fa5 33Revision 1.14 2007/06/06 16:26:30 arcelli
34remove fall-back call to local CDB storage
35
03705065 36Revision 1.13 2007/04/20 13:59:40 arcelli
37make protections agains failed retrieval of the CDB object in a proper way
38
7a4f634e 39Revision 1.12 2007/03/23 11:31:16 arcelli
40CDB Entry for TOF Reconstruction Parameters
41
7037bd93 42Revision 1.11 2007/02/28 18:08:26 arcelli
43Add protection against failed retrieval of the CDB cal object
44
1b20c168 45Revision 1.10 2006/08/22 13:30:49 arcelli
46removal of effective c++ warnings (C.Zampolli)
47
655e379f 48Revision 1.9 2006/04/20 22:30:50 hristov
49Coding conventions (Annalisa)
50
0e46b9ae 51Revision 1.8 2006/04/16 22:29:05 hristov
52Coding conventions (Annalisa)
53
7aeeaf38 54Revision 1.7 2006/04/16 20:12:46 hristov
55Removing memory leak in case of cached CDB entries
56
85fc78e3 57Revision 1.6 2006/04/11 15:28:32 hristov
58Checks on cache status before deleting calibration objects (A.Colla)
59
5eaae242 60Revision 1.5 2006/04/05 08:35:38 hristov
61Coding conventions (S.Arcelli, C.Zampolli)
62
340693af 63Revision 1.4 2006/03/31 11:26:46 arcelli
64 changing CDB Ids according to standard convention
65
28dd10b6 66Revision 1.3 2006/03/28 14:57:02 arcelli
67updates to handle new V5 geometry & some re-arrangements
68
d4ad0d6b 69Revision 1.2 2006/02/13 17:22:26 arcelli
70just Fixing Log info
71
762446e0 72Revision 1.1 2006/02/13 16:10:48 arcelli
73Add classes for TOF Calibration (C.Zampolli)
74
6dc9348d 75author: Chiara Zampolli, zampolli@bo.infn.it
762446e0 76*/
6dc9348d 77
78///////////////////////////////////////////////////////////////////////////////
79// //
80// class for TOF calibration //
81// //
82///////////////////////////////////////////////////////////////////////////////
83
6dc9348d 84#include "TF1.h"
0e46b9ae 85#include "TFile.h"
6dc9348d 86#include "TH1F.h"
87#include "TH2F.h"
5c7c93fa 88//#include "TList.h"
89//#include "TROOT.h"
90//#include "TStyle.h"
0a749fa5 91#include "TTree.h"
296591ad 92#include "TChain.h"
0a749fa5 93#include "TProfile.h"
94#include "TGrid.h"
5c7c93fa 95#include "TMath.h"
17149e6b 96#include "TMap.h"
0e46b9ae 97
98#include "AliCDBEntry.h"
0cb9d099 99#include "AliCDBRunRange.h"
0e46b9ae 100#include "AliCDBId.h"
6dc9348d 101#include "AliCDBManager.h"
0a749fa5 102#include "AliCDBStorage.h"
6dc9348d 103#include "AliCDBMetaData.h"
5c7c93fa 104//#include "AliESDtrack.h"
105//#include "AliESD.h"
0e46b9ae 106#include "AliLog.h"
107
0e46b9ae 108#include "AliTOFcalib.h"
17149e6b 109#include "AliTOFChannelOnlineArray.h"
0a749fa5 110#include "AliTOFChannelOnline.h"
7fffa85b 111#include "AliTOFChannelOnlineStatus.h"
17149e6b 112#include "AliTOFChannelOnlineStatusArray.h"
0a749fa5 113#include "AliTOFChannelOffline.h"
0e46b9ae 114#include "AliTOFGeometry.h"
7037bd93 115#include "AliTOFRecoParam.h"
2bf4d9d6 116#include "AliTOFDeltaBCOffset.h"
117#include "AliTOFCTPLatency.h"
118#include "AliTOFT0Fill.h"
f04b3a69 119#include "AliTOFRunParams.h"
5b4ed716 120#include "AliTOFResponseParams.h"
121#include "AliESDEvent.h"
122#include "AliESDtrack.h"
6dc9348d 123
5c7c93fa 124class TROOT;
125class TStyle;
126
6dc9348d 127extern TROOT *gROOT;
128extern TStyle *gStyle;
129
130ClassImp(AliTOFcalib)
131
6dc9348d 132//_______________________________________________________________________
655e379f 133AliTOFcalib::AliTOFcalib():
134 TTask("AliTOFcalib",""),
135 fNChannels(-1),
0a749fa5 136 fTOFCalOnline(0x0),
7fffa85b 137 fTOFCalOnlinePulser(0x0),
138 fTOFCalOnlineNoise(0x0),
139 fTOFCalOnlineHW(0x0),
0a749fa5 140 fTOFCalOffline(0x0),
17149e6b 141 fCal(0x0),
142 fStatus(0x0),
0a749fa5 143 fTOFSimToT(0x0),
144 fkValidity(0x0),
145 fTree(0x0),
296591ad 146 fChain(0x0),
0cb9d099 147 fNruns(0),
148 fFirstRun(0),
17149e6b 149 fLastRun(AliCDBRunRange::Infinity()),
2bf4d9d6 150 fConfigMap(new TMap),
151 fDeltaBCOffset(NULL),
152 fCTPLatency(NULL),
f04b3a69 153 fT0Fill(NULL),
5b4ed716 154 fRunParams(NULL),
155 fResponseParams(NULL),
156 fInitFlag(kFALSE),
157 fRemoveMeanT0(kTRUE),
8bb89c94 158 fCalibrateTOFsignal(kTRUE),
5b4ed716 159 fCorrectTExp(kFALSE)
655e379f 160{
340693af 161 //TOF Calibration Class ctor
0a749fa5 162 fNChannels = AliTOFGeometry::NSectors()*(2*(AliTOFGeometry::NStripC()+AliTOFGeometry::NStripB())+AliTOFGeometry::NStripA())*AliTOFGeometry::NpadZ()*AliTOFGeometry::NpadX();
6dc9348d 163}
164//____________________________________________________________________________
165
655e379f 166AliTOFcalib::AliTOFcalib(const AliTOFcalib & calib):
8a190ba2 167 TTask(calib),
0a749fa5 168 fNChannels(calib.fNChannels),
169 fTOFCalOnline(0x0),
7fffa85b 170 fTOFCalOnlinePulser(0x0),
171 fTOFCalOnlineNoise(0x0),
172 fTOFCalOnlineHW(0x0),
0a749fa5 173 fTOFCalOffline(0x0),
17149e6b 174 fCal(calib.fCal),
175 fStatus(calib.fStatus),
0a749fa5 176 fTOFSimToT(calib.fTOFSimToT),
177 fkValidity(calib.fkValidity),
178 fTree(calib.fTree),
296591ad 179 fChain(calib.fChain),
0cb9d099 180 fNruns(calib.fNruns),
181 fFirstRun(calib.fFirstRun),
17149e6b 182 fLastRun(calib.fLastRun),
2bf4d9d6 183 fConfigMap(calib.fConfigMap),
184 fDeltaBCOffset(NULL),
185 fCTPLatency(NULL),
f04b3a69 186 fT0Fill(NULL),
5b4ed716 187 fRunParams(NULL),
188 fResponseParams(NULL),
189 fInitFlag(calib.fInitFlag),
190 fRemoveMeanT0(calib.fRemoveMeanT0),
8bb89c94 191 fCalibrateTOFsignal(calib.fCalibrateTOFsignal),
5b4ed716 192 fCorrectTExp(calib.fCorrectTExp)
6dc9348d 193{
955f2093 194
195 fTOFCalOnline = new TObjArray(fNChannels);
196 fTOFCalOnlinePulser = new TObjArray(fNChannels);
197 fTOFCalOnlineNoise = new TObjArray(fNChannels);
198 fTOFCalOnlineHW = new TObjArray(fNChannels);
199 fTOFCalOffline = new TObjArray(fNChannels);
200 fTOFCalOnline->SetOwner();
201 fTOFCalOnlinePulser->SetOwner();
202 fTOFCalOnlineNoise->SetOwner();
203 fTOFCalOnlineHW->SetOwner();
204 fTOFCalOffline->SetOwner();
205
340693af 206 //TOF Calibration Class copy ctor
0a749fa5 207 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
208 AliTOFChannelOnline * calChOnline = (AliTOFChannelOnline*)calib.fTOFCalOnline->At(iarray);
7fffa85b 209 AliTOFChannelOnlineStatus * calChOnlineStPulser = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlinePulser->At(iarray);
210 AliTOFChannelOnlineStatus * calChOnlineStNoise = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlineNoise->At(iarray);
211 AliTOFChannelOnlineStatus * calChOnlineStHW = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlineHW->At(iarray);
0a749fa5 212 AliTOFChannelOffline * calChOffline = (AliTOFChannelOffline*)calib.fTOFCalOffline->At(iarray);
213 fTOFCalOnline->AddAt(calChOnline,iarray);
7fffa85b 214 fTOFCalOnlinePulser->AddAt(calChOnlineStPulser,iarray);
215 fTOFCalOnlineNoise->AddAt(calChOnlineStNoise,iarray);
216 fTOFCalOnlineHW->AddAt(calChOnlineStHW,iarray);
0a749fa5 217 fTOFCalOffline->AddAt(calChOffline,iarray);
0a749fa5 218 }
2bf4d9d6 219
220 if (calib.fDeltaBCOffset) fDeltaBCOffset = new AliTOFDeltaBCOffset(*calib.fDeltaBCOffset);
221 if (calib.fCTPLatency) fCTPLatency = new AliTOFCTPLatency(*calib.fCTPLatency);
222 if (calib.fT0Fill) fT0Fill = new AliTOFT0Fill(*calib.fT0Fill);
f04b3a69 223 if (calib.fRunParams) fRunParams = new AliTOFRunParams(*calib.fRunParams);
5b4ed716 224 if (calib.fResponseParams) fResponseParams = new AliTOFResponseParams(*calib.fResponseParams);
6dc9348d 225}
226
227//____________________________________________________________________________
7aeeaf38 228
229AliTOFcalib& AliTOFcalib::operator=(const AliTOFcalib &calib)
230{
231 //TOF Calibration Class assignment operator
8a190ba2 232
233 if (this == &calib)
234 return *this;
235
236 TTask::operator=(calib);
237 fNChannels = calib.fNChannels;
238 fCal = calib.fCal;
239 fStatus = calib.fStatus;
240 fTOFSimToT = calib.fTOFSimToT;
241 fkValidity = calib.fkValidity;
242 fTree = calib.fTree;
243 fChain = calib.fChain;
244 fNruns = calib.fNruns;
245 fFirstRun = calib.fFirstRun;
246 fLastRun = calib.fLastRun;
0a749fa5 247 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
248 AliTOFChannelOnline * calChOnline = (AliTOFChannelOnline*)calib.fTOFCalOnline->At(iarray);
249 AliTOFChannelOffline * calChOffline = (AliTOFChannelOffline*)calib.fTOFCalOffline->At(iarray);
7fffa85b 250 AliTOFChannelOnlineStatus * calChOnlineStPulser = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlinePulser->At(iarray);
251 AliTOFChannelOnlineStatus * calChOnlineStNoise = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlineNoise->At(iarray);
252 AliTOFChannelOnlineStatus * calChOnlineStHW = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlineHW->At(iarray);
8a190ba2 253 fTOFCalOnline->AddAt(calChOnline,iarray);
254 fTOFCalOnlinePulser->AddAt(calChOnlineStPulser,iarray);
255 fTOFCalOnlineNoise->AddAt(calChOnlineStNoise,iarray);
256 fTOFCalOnlineHW->AddAt(calChOnlineStHW,iarray);
257 fTOFCalOffline->AddAt(calChOffline,iarray);
0a749fa5 258 }
2bf4d9d6 259
260 if (calib.fDeltaBCOffset) {
261 if (fDeltaBCOffset) *fDeltaBCOffset = *calib.fDeltaBCOffset;
262 else fDeltaBCOffset = new AliTOFDeltaBCOffset(*calib.fDeltaBCOffset);
263 }
264
265 if (calib.fCTPLatency) {
266 if (fCTPLatency) *fCTPLatency = *calib.fCTPLatency;
267 else fCTPLatency = new AliTOFCTPLatency(*calib.fCTPLatency);
268 }
269
270 if (calib.fT0Fill) {
271 if (fT0Fill) *fT0Fill = *calib.fT0Fill;
272 else fT0Fill = new AliTOFT0Fill(*calib.fT0Fill);
273 }
f04b3a69 274 if (calib.fRunParams) {
275 if (fRunParams) *fRunParams = *calib.fRunParams;
276 else fRunParams = new AliTOFRunParams(*calib.fRunParams);
277 }
5b4ed716 278 if (calib.fResponseParams) {
279 if (fResponseParams) *fResponseParams = *calib.fResponseParams;
280 else fResponseParams = new AliTOFResponseParams(*calib.fResponseParams);
281 }
282 fInitFlag = calib.fInitFlag;
283 fRemoveMeanT0 = calib.fRemoveMeanT0;
8bb89c94 284 fCalibrateTOFsignal = calib.fCalibrateTOFsignal;
5b4ed716 285 fCorrectTExp = calib.fCorrectTExp;
2bf4d9d6 286
7aeeaf38 287 return *this;
288}
289
290//____________________________________________________________________________
6dc9348d 291
292AliTOFcalib::~AliTOFcalib()
293{
340693af 294 //TOF Calibration Class dtor
5eaae242 295 if(!(AliCDBManager::Instance()->GetCacheFlag())){ // CDB objects must NOT be deleted if cache is active!
0a749fa5 296 if (fTOFCalOnline){
0a749fa5 297 delete fTOFCalOnline;
6dc9348d 298 }
7fffa85b 299 if (fTOFCalOnlinePulser){
300 delete fTOFCalOnlinePulser;
301 }
302 if (fTOFCalOnlineNoise){
303 delete fTOFCalOnlineNoise;
304 }
305 if (fTOFCalOnlineHW){
306 delete fTOFCalOnlineHW;
307 }
0a749fa5 308 if (fTOFCalOffline){
0a749fa5 309 delete fTOFCalOffline;
6dc9348d 310 }
17149e6b 311 if (fCal){
312 delete fCal;
313 }
314 if (fStatus){
315 delete fStatus;
316 }
317 if (fConfigMap){
318 delete fConfigMap;
319 }
2bf4d9d6 320 if (fDeltaBCOffset) delete fDeltaBCOffset;
321 if (fCTPLatency) delete fCTPLatency;
322 if (fT0Fill) delete fT0Fill;
f04b3a69 323 if (fRunParams) delete fRunParams;
6dc9348d 324 }
0a749fa5 325 if (fTree!=0x0) delete fTree;
296591ad 326 if (fChain!=0x0) delete fChain;
2bf4d9d6 327
6dc9348d 328}
329//_____________________________________________________________________________
0a749fa5 330void AliTOFcalib::CreateCalArrays(){
6dc9348d 331
0a749fa5 332 // creating arrays for online/offline calibration objs
6dc9348d 333
0a749fa5 334 fTOFCalOnline = new TObjArray(fNChannels);
7fffa85b 335 fTOFCalOnlinePulser = new TObjArray(fNChannels);
336 fTOFCalOnlineNoise = new TObjArray(fNChannels);
337 fTOFCalOnlineHW = new TObjArray(fNChannels);
0a749fa5 338 fTOFCalOffline = new TObjArray(fNChannels);
339 fTOFCalOnline->SetOwner();
7fffa85b 340 fTOFCalOnlinePulser->SetOwner();
341 fTOFCalOnlineNoise->SetOwner();
342 fTOFCalOnlineHW->SetOwner();
0a749fa5 343 fTOFCalOffline->SetOwner();
344 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
345 AliTOFChannelOnline * calChOnline = new AliTOFChannelOnline();
7fffa85b 346 AliTOFChannelOnlineStatus * calChOnlineStPulser = new AliTOFChannelOnlineStatus();
347 AliTOFChannelOnlineStatus * calChOnlineStNoise = new AliTOFChannelOnlineStatus();
348 AliTOFChannelOnlineStatus * calChOnlineStHW = new AliTOFChannelOnlineStatus();
0a749fa5 349 AliTOFChannelOffline * calChOffline = new AliTOFChannelOffline();
350 fTOFCalOnline->AddAt(calChOnline,iarray);
7fffa85b 351 fTOFCalOnlinePulser->AddAt(calChOnlineStPulser,iarray);
352 fTOFCalOnlineNoise->AddAt(calChOnlineStNoise,iarray);
353 fTOFCalOnlineHW->AddAt(calChOnlineStHW,iarray);
0a749fa5 354 fTOFCalOffline->AddAt(calChOffline,iarray);
6dc9348d 355 }
17149e6b 356 fCal = new AliTOFChannelOnlineArray(fNChannels);
357 fStatus = new AliTOFChannelOnlineStatusArray(fNChannels);
358}
359//_____________________________________________________________________________
24d1e16e 360void AliTOFcalib::CreateCalObjects(){
361
362 // creating arrays for online/offline calibration objs
363
364 fTOFCalOffline = new TObjArray(fNChannels);
365 fTOFCalOffline->SetOwner();
366 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
367 AliTOFChannelOffline * calChOffline = new AliTOFChannelOffline();
368 fTOFCalOffline->AddAt(calChOffline,iarray);
369 }
370 fCal = new AliTOFChannelOnlineArray(fNChannels);
371 fStatus = new AliTOFChannelOnlineStatusArray(fNChannels);
372}
373//_____________________________________________________________________________
a6e0ebfe 374void AliTOFcalib::WriteConfigMapOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
17149e6b 375{
376 //Write calibration parameters to the CDB
377 SetFirstRun(minrun);
378 SetLastRun(maxrun);
379 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 380 const Char_t *sel1 = "Config" ; // to be consistent with TOFPreprocessor
955f2093 381 TString out(Form("%s/%s",sel,sel1));
17149e6b 382 AliDebug(2,Form("Writing TOF configuration map for online calib on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
383 AliCDBId id(out,fFirstRun,fLastRun);
384 AliCDBMetaData *md = new AliCDBMetaData();
385 md->SetResponsible("Chiara Zampolli");
386 if (!fConfigMap) {
387 // deve uscire!!
388 }
389 man->Put(fConfigMap,id,md);
390 delete md;
391}
392//_____________________________________________________________________________
393
a6e0ebfe 394void AliTOFcalib::WriteConfigMapOnCDB(const Char_t *sel)
17149e6b 395{
396 //Write calibration parameters to the CDB with infinite validity
397 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 398 const Char_t *sel1 = "Config" ; // to be consistent with TOFPreprocessor
955f2093 399 TString out(Form("%s/%s",sel,sel1));
17149e6b 400 AliCDBRunRange runrange(fFirstRun,fLastRun);
401 AliDebug(2,Form("Writing TOF config map for online calib on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
402 AliCDBId id(out,runrange);
403 AliCDBMetaData *md = new AliCDBMetaData();
404 md->SetResponsible("Chiara Zampolli");
405 if (!fConfigMap) {
406 // deve uscire!!
407 }
408 man->Put(fConfigMap,id,md);
409 delete md;
410}
411//_____________________________________________________________________________
a6e0ebfe 412void AliTOFcalib::WriteParOnlineDelayOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
17149e6b 413{
414 //Write calibration parameters to the CDB -------> new calib objs!!!!!
415 SetFirstRun(minrun);
416 SetLastRun(maxrun);
417 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 418 const Char_t *sel1 = "ParOnlineDelay" ; // to be consistent with TOFPreprocessor
955f2093 419 TString out(Form("%s/%s",sel,sel1));
17149e6b 420 AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
421 AliCDBId id(out,fFirstRun,fLastRun);
422 AliCDBMetaData *md = new AliCDBMetaData();
423 md->SetResponsible("Chiara Zampolli");
424 if (!fCal) {
425 // deve uscire!!
426 }
427 man->Put(fCal,id,md);
428 delete md;
429}
430//_____________________________________________________________________________
a6e0ebfe 431void AliTOFcalib::WriteParOnlineStatusOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
17149e6b 432{
433 //Write calibration parameters to the CDB -------> new calib objs!!!!!
434 SetFirstRun(minrun);
435 SetLastRun(maxrun);
436 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 437 const Char_t *sel1 = "Status" ; // to be consistent with TOFPreprocessor
955f2093 438 TString out(Form("%s/%s",sel,sel1));
17149e6b 439 AliDebug(2,Form("Writing TOF online status calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
440 AliCDBId id(out,fFirstRun,fLastRun);
441 AliCDBMetaData *md = new AliCDBMetaData();
442 md->SetResponsible("Chiara Zampolli");
443 if (!fStatus) {
444 // deve uscire!!
445 }
446 man->Put(fStatus,id,md);
447 delete md;
448}
449//_____________________________________________________________________________
450
a6e0ebfe 451void AliTOFcalib::WriteParOnlineDelayOnCDB(const Char_t *sel)
17149e6b 452{
453 //Write calibration parameters to the CDB with infinite validity -------> new calib objs!!!!!
454 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 455 const Char_t *sel1 = "ParOnlineDelay" ; // to be consistent with TOFPreprocessor
955f2093 456 TString out(Form("%s/%s",sel,sel1));
17149e6b 457 AliCDBRunRange runrange(fFirstRun,fLastRun);
458 AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
459 AliCDBId id(out,runrange);
460 AliCDBMetaData *md = new AliCDBMetaData();
461 md->SetResponsible("Chiara Zampolli");
462 if (!fCal) {
463 // deve uscire!!
464 }
465 man->Put(fCal,id,md);
466 delete md;
467}
468//_____________________________________________________________________________
469
a6e0ebfe 470void AliTOFcalib::WriteParOnlineStatusOnCDB(const Char_t *sel)
17149e6b 471{
472 //Write calibration parameters to the CDB with infinite validity -------> new calib objs!!!!!
473 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 474 const Char_t *sel1 = "Status" ; // to be consistent with TOFPreprocessor
955f2093 475 TString out(Form("%s/%s",sel,sel1));
17149e6b 476 AliCDBRunRange runrange(fFirstRun,fLastRun);
477 AliDebug(2,Form("Writing TOF online status calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
478 AliCDBId id(out,runrange);
479 AliCDBMetaData *md = new AliCDBMetaData();
480 md->SetResponsible("Chiara Zampolli");
481 if (!fStatus) {
482 // deve uscire!!
483 }
484 man->Put(fStatus,id,md);
485 delete md;
6dc9348d 486}
487//_____________________________________________________________________________
a6e0ebfe 488void AliTOFcalib::WriteParOnlineOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
340693af 489{
490 //Write calibration parameters to the CDB
0cb9d099 491 SetFirstRun(minrun);
492 SetLastRun(maxrun);
6dc9348d 493 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 494 const Char_t *sel1 = "ParOnline" ; // to be consistent with TOFPreprocessor
955f2093 495 TString out(Form("%s/%s",sel,sel1));
0cb9d099 496 AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
497 AliCDBId id(out,fFirstRun,fLastRun);
498 AliCDBMetaData *md = new AliCDBMetaData();
499 md->SetResponsible("Chiara Zampolli");
500 if (!fTOFCalOnline) {
501 // deve uscire!!
502 }
503 man->Put(fTOFCalOnline,id,md);
504 delete md;
505}
506//_____________________________________________________________________________
a6e0ebfe 507void AliTOFcalib::WriteParOnlinePulserOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
7fffa85b 508{
509 //Write calibration parameters from pulser to the CDB
510 SetFirstRun(minrun);
511 SetLastRun(maxrun);
512 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 513 const Char_t *sel1 = "Pulser" ; // to be consistent with TOFPreprocessor
955f2093 514 TString out(Form("%s/%s",sel,sel1));
7fffa85b 515 AliDebug(2,Form("Writing TOF online calib obj from pulser on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
516 AliCDBId id(out,fFirstRun,fLastRun);
517 AliCDBMetaData *md = new AliCDBMetaData();
518 md->SetResponsible("Chiara Zampolli");
519 if (!fTOFCalOnlinePulser) {
520 // deve uscire!!
521 }
522 man->Put(fTOFCalOnlinePulser,id,md);
523 delete md;
524}
525//_____________________________________________________________________________
a6e0ebfe 526void AliTOFcalib::WriteParOnlineNoiseOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
7fffa85b 527{
528 //Write calibration parameters from noise to the CDB
529 SetFirstRun(minrun);
530 SetLastRun(maxrun);
531 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 532 const Char_t *sel1 = "Noise" ; // to be consistent with TOFPreprocessor
955f2093 533 TString out(Form("%s/%s",sel,sel1));
7fffa85b 534 AliDebug(2,Form("Writing TOF online calib obj from noise on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
535 AliCDBId id(out,fFirstRun,fLastRun);
536 AliCDBMetaData *md = new AliCDBMetaData();
537 md->SetResponsible("Chiara Zampolli");
538 if (!fTOFCalOnlineNoise) {
539 // deve uscire!!
540 }
541 man->Put(fTOFCalOnlineNoise,id,md);
542 delete md;
543}
544//_____________________________________________________________________________
a6e0ebfe 545void AliTOFcalib::WriteParOnlineHWOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
7fffa85b 546{
547 //Write calibration parameters from hardware to the CDB
548 SetFirstRun(minrun);
549 SetLastRun(maxrun);
550 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 551 const Char_t *sel1 = "HW" ; // to be consistent with TOFPreprocessor
955f2093 552 TString out(Form("%s/%s",sel,sel1));
7fffa85b 553 AliDebug(2,Form("Writing TOF online calib obj from hardware on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
554 AliCDBId id(out,fFirstRun,fLastRun);
555 AliCDBMetaData *md = new AliCDBMetaData();
556 md->SetResponsible("Chiara Zampolli");
557 if (!fTOFCalOnlineHW) {
558 // deve uscire!!
559 }
560 man->Put(fTOFCalOnlineHW,id,md);
561 delete md;
562}
563//_____________________________________________________________________________
0cb9d099 564
a6e0ebfe 565void AliTOFcalib::WriteParOnlineOnCDB(const Char_t *sel)
0cb9d099 566{
567 //Write calibration parameters to the CDB with infinite validity
568 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 569 const Char_t *sel1 = "ParOnline" ; // to be consistent with TOFPreprocessor
955f2093 570 TString out(Form("%s/%s",sel,sel1));
0cb9d099 571 AliCDBRunRange runrange(fFirstRun,fLastRun);
572 AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
573 AliCDBId id(out,runrange);
6dc9348d 574 AliCDBMetaData *md = new AliCDBMetaData();
d4ad0d6b 575 md->SetResponsible("Chiara Zampolli");
0a749fa5 576 if (!fTOFCalOnline) {
577 // deve uscire!!
85fc78e3 578 }
0a749fa5 579 man->Put(fTOFCalOnline,id,md);
5eaae242 580 delete md;
6dc9348d 581}
582//_____________________________________________________________________________
583
a6e0ebfe 584void AliTOFcalib::WriteParOnlinePulserOnCDB(const Char_t *sel)
7fffa85b 585{
586 //Write calibration parameters from pulser to the CDB with infinite validity
587 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 588 const Char_t *sel1 = "Pulser" ; // to be consistent with TOFPreprocessor
955f2093 589 TString out(Form("%s/%s",sel,sel1));
7fffa85b 590 AliCDBRunRange runrange(fFirstRun,fLastRun);
591 AliDebug(2,Form("Writing TOF online calib obj from pulser on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
592 AliCDBId id(out,runrange);
593 AliCDBMetaData *md = new AliCDBMetaData();
594 md->SetResponsible("Chiara Zampolli");
595 if (!fTOFCalOnlinePulser) {
596 // deve uscire!!
597 }
598 man->Put(fTOFCalOnlinePulser,id,md);
599 delete md;
600}
601//_____________________________________________________________________________
602
a6e0ebfe 603void AliTOFcalib::WriteParOnlineNoiseOnCDB(const Char_t *sel)
7fffa85b 604{
605 //Write calibration parameters from noise to the CDB with infinite validity
606 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 607 const Char_t *sel1 = "Noise" ; // to be consistent with TOFPreprocessor
955f2093 608 TString out(Form("%s/%s",sel,sel1));
7fffa85b 609 AliCDBRunRange runrange(fFirstRun,fLastRun);
610 AliDebug(2,Form("Writing TOF online calib obj from noise on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
611 AliCDBId id(out,runrange);
612 AliCDBMetaData *md = new AliCDBMetaData();
613 md->SetResponsible("Chiara Zampolli");
614 if (!fTOFCalOnlineNoise) {
615 // deve uscire!!
616 }
617 man->Put(fTOFCalOnlineNoise,id,md);
618 delete md;
619}
620//_____________________________________________________________________________
621
a6e0ebfe 622void AliTOFcalib::WriteParOnlineHWOnCDB(const Char_t *sel)
7fffa85b 623{
624 //Write calibration parameters from hardware to the CDB with infinite validity
625 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 626 const Char_t *sel1 = "HW" ; // to be consistent with TOFPreprocessor
955f2093 627 TString out(Form("%s/%s",sel,sel1));
7fffa85b 628 AliCDBRunRange runrange(fFirstRun,fLastRun);
629 AliDebug(2,Form("Writing TOF online calib obj from harware on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
630 AliCDBId id(out,runrange);
631 AliCDBMetaData *md = new AliCDBMetaData();
632 md->SetResponsible("Chiara Zampolli");
633 if (!fTOFCalOnlineHW) {
634 // deve uscire!!
635 }
636 man->Put(fTOFCalOnlineHW,id,md);
637 delete md;
638}
639//_____________________________________________________________________________
640
a6e0ebfe 641void AliTOFcalib::WriteParOfflineOnCDB(const Char_t *sel, const Char_t *validity, Int_t minrun, Int_t maxrun)
0a749fa5 642{
340693af 643 //Write calibration parameters to the CDB
0cb9d099 644 SetFirstRun(minrun);
645 SetLastRun(maxrun);
6dc9348d 646 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 647 const Char_t *sel1 = "ParOffline" ;
955f2093 648 TString out(Form("%s/%s",sel,sel1));
0cb9d099 649 AliDebug(2,Form("Writing TOF offline calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
650 AliCDBId id(out,fFirstRun,fLastRun);
651 AliCDBMetaData *md = new AliCDBMetaData();
652 md->SetResponsible("Chiara Zampolli");
653 md->SetComment(validity);
654 man->Put(fTOFCalOffline,id,md);
655 delete md;
656}
657//_____________________________________________________________________________
658
a6e0ebfe 659void AliTOFcalib::WriteParOfflineOnCDB(const Char_t *sel, const Char_t *validity)
0cb9d099 660{
661 //Write calibration parameters to the CDB with infinite validity
662 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 663 const Char_t *sel1 = "ParOffline" ;
955f2093 664 TString out(Form("%s/%s",sel,sel1));
0cb9d099 665 AliCDBRunRange runrange(fFirstRun,fLastRun);
666 AliDebug(2,Form("Writing TOF offline calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
667 AliCDBId id(out,runrange);
d4ad0d6b 668 AliCDBMetaData *md = new AliCDBMetaData();
669 md->SetResponsible("Chiara Zampolli");
0a749fa5 670 md->SetComment(validity);
671 man->Put(fTOFCalOffline,id,md);
5eaae242 672 delete md;
d4ad0d6b 673}
674//_____________________________________________________________________________
675
a6e0ebfe 676Bool_t AliTOFcalib::ReadConfigMapFromCDB(const Char_t *sel, Int_t nrun)
17149e6b 677{
678 //Read calibration parameters from the CDB
679 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 680 const Char_t *sel1 = "Config" ;
955f2093 681 TString out(Form("%s/%s",sel,sel1));
17149e6b 682 AliCDBEntry *entry = man->Get(out,nrun);
683 if (!entry) {
684 AliFatal("Exiting, no CDB object (ConfigMap) found!!!");
685 exit(0);
686 }
687 if(!entry->GetObject()){
688 AliFatal("Exiting, no CDB object (ConfigMap) found!!!");
689 exit(0);
690 }
691
692 fConfigMap =(TMap*)entry->GetObject();
693
694 return kTRUE;
695
696}
697//_____________________________________________________________________________
698
a6e0ebfe 699Bool_t AliTOFcalib::ReadParOnlineDelayFromCDB(const Char_t *sel, Int_t nrun)
17149e6b 700{
701 //Read calibration parameters from the CDB -------> new calib objs!!!!!
702 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 703 const Char_t *sel1 = "ParOnlineDelay" ;
955f2093 704 TString out(Form("%s/%s",sel,sel1));
17149e6b 705 AliCDBEntry *entry = man->Get(out,nrun);
706 if (!entry) {
707 AliFatal("Exiting, no CDB object (ParOnlineDelay) found!!!");
708 exit(0);
709 }
710 if(!entry->GetObject()){
711 AliFatal("Exiting, no CDB object (ParOnlineDelay) found!!!");
712 exit(0);
713 }
714
715 fCal =(AliTOFChannelOnlineArray*)entry->GetObject();
716
717 return kTRUE;
718
719}
720//_____________________________________________________________________________
721
a6e0ebfe 722Bool_t AliTOFcalib::ReadParOnlineStatusFromCDB(const Char_t *sel, Int_t nrun)
17149e6b 723{
724 //Read calibration parameters from the CDB -------> new calib objs!!!!!
725 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 726 const Char_t *sel1 = "Status" ;
955f2093 727 TString out(Form("%s/%s",sel,sel1));
17149e6b 728 AliCDBEntry *entry = man->Get(out,nrun);
729 if (!entry) {
730 AliFatal("Exiting, no CDB object (Status) found!!!");
731 exit(0);
732 }
733 if(!entry->GetObject()){
734 AliFatal("Exiting, no CDB object (Status) found!!!");
735 exit(0);
736 }
737
738 fStatus =(AliTOFChannelOnlineStatusArray*)entry->GetObject();
739
740 return kTRUE;
741
742}
743//_____________________________________________________________________________
744
a6e0ebfe 745Bool_t AliTOFcalib::ReadParOnlineFromCDB(const Char_t *sel, Int_t nrun)
340693af 746{
747 //Read calibration parameters from the CDB
d4ad0d6b 748 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 749 const Char_t *sel1 = "ParOnline" ;
955f2093 750 TString out(Form("%s/%s",sel,sel1));
7a4f634e 751 AliCDBEntry *entry = man->Get(out,nrun);
c30c0a38 752 if (!entry) {
753 AliFatal("Exiting, no CDB object (ParOnline) found!!!");
754 exit(0);
755 }
7a4f634e 756 if(!entry->GetObject()){
c30c0a38 757 AliFatal("Exiting, no CDB object (ParOnline) found!!!");
758 exit(0);
7a4f634e 759 }
760
0a749fa5 761 fTOFCalOnline =(TObjArray*)entry->GetObject();
7fffa85b 762
763 return kTRUE;
764
765}
766//_____________________________________________________________________________
767
a6e0ebfe 768Bool_t AliTOFcalib::ReadParOnlinePulserFromCDB(const Char_t *sel, Int_t nrun)
7fffa85b 769{
770 //Read calibration parameters from pulser from the CDB
771 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 772 const Char_t *sel1 = "Pulser" ;
955f2093 773 TString out(Form("%s/%s",sel,sel1));
7fffa85b 774 AliCDBEntry *entry = man->Get(out,nrun);
c30c0a38 775 if (!entry) {
776 AliFatal("Exiting, no CDB object (Pulser) found!!!");
777 exit(0);
778 }
7fffa85b 779 if(!entry->GetObject()){
c30c0a38 780 AliFatal("Exiting, no CDB object (Pulser) found!!!");
781 exit(0);
7fffa85b 782 }
783
784 fTOFCalOnlinePulser =(TObjArray*)entry->GetObject();
785
786 return kTRUE;
787
788}
789//_____________________________________________________________________________
790
a6e0ebfe 791Bool_t AliTOFcalib::ReadParOnlineNoiseFromCDB(const Char_t *sel, Int_t nrun)
7fffa85b 792{
793 //Read calibration parameters from noise from the CDB
794 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 795 const Char_t *sel1 = "Noise" ;
955f2093 796 TString out(Form("%s/%s",sel,sel1));
7fffa85b 797 AliCDBEntry *entry = man->Get(out,nrun);
c30c0a38 798 if (!entry) {
799 AliFatal("Exiting, no CDB object (Noise) found!!!");
800 exit(0);
801 }
7fffa85b 802 if(!entry->GetObject()){
c30c0a38 803 AliFatal("Exiting, no CDB object (Noise) found!!!");
804 exit(0);
7fffa85b 805 }
806
807 fTOFCalOnlineNoise =(TObjArray*)entry->GetObject();
808
809 return kTRUE;
810
811}
812//_____________________________________________________________________________
813
a6e0ebfe 814Bool_t AliTOFcalib::ReadParOnlineHWFromCDB(const Char_t *sel, Int_t nrun)
7fffa85b 815{
816 //Read calibration parameters from hardware from the CDB
817 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 818 const Char_t *sel1 = "HW" ;
955f2093 819 TString out(Form("%s/%s",sel,sel1));
7fffa85b 820 AliCDBEntry *entry = man->Get(out,nrun);
c30c0a38 821 if (!entry) {
822 AliFatal("Exiting, no CDB object (HW map) found!!!");
823 exit(0);
824 }
7fffa85b 825 if(!entry->GetObject()){
c30c0a38 826 AliFatal("Exiting, no CDB object (HW map) found!!!");
827 exit(0);
7fffa85b 828 }
829
830 fTOFCalOnlineHW =(TObjArray*)entry->GetObject();
0a749fa5 831
1b20c168 832 return kTRUE;
7a4f634e 833
6dc9348d 834}
835//_____________________________________________________________________________
d4ad0d6b 836
a6e0ebfe 837Bool_t AliTOFcalib::ReadParOfflineFromCDB(const Char_t *sel, Int_t nrun)
0a749fa5 838{
839 //Read calibration parameters from the CDB
840 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 841 const Char_t *sel1 = "ParOffline" ;
955f2093 842 TString out(Form("%s/%s",sel,sel1));
0a749fa5 843 AliCDBEntry *entry = man->Get(out,nrun);
c30c0a38 844 if (!entry) {
845 AliFatal("Exiting, no CDB object (ParOffline) found!!!");
846 exit(0);
847 }
0a749fa5 848 if(!entry->GetObject()){
c30c0a38 849 AliFatal("Exiting, no CDB object (ParOffline) found!!!");
850 exit(0);
0a749fa5 851 }
852 AliCDBMetaData * md = entry->GetMetaData();
853 fkValidity = md->GetComment();
854 fTOFCalOffline =(TObjArray*)entry->GetObject();
d4ad0d6b 855
0a749fa5 856 return kTRUE;
857
858}
859//_____________________________________________________________________________
a6e0ebfe 860void AliTOFcalib::WriteSimHistoOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun, TH1F *histo){
340693af 861 //Write Sim miscalibration parameters to the CDB
d4ad0d6b 862
d4ad0d6b 863 fTOFSimToT=histo;
d4ad0d6b 864 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 865 const Char_t *sel1 = "SimHisto" ;
955f2093 866 TString out(Form("%s/%s",sel,sel1));
0a749fa5 867 AliCDBMetaData *mdhisto = new AliCDBMetaData();
868 mdhisto->SetResponsible("Chiara Zampolli");
40212801 869 AliCDBId id(out,minrun,maxrun);
870 man->Put(fTOFSimToT,id,mdhisto);
0a749fa5 871 delete mdhisto;
872}
873//_____________________________________________________________________________
a6e0ebfe 874Bool_t AliTOFcalib::ReadSimHistoFromCDB(const Char_t *sel, Int_t nrun)
0a749fa5 875{
876 //Read miscalibration parameters from the CDB
877 AliCDBManager *man = AliCDBManager::Instance();
878
40212801 879 // The Tot Histo
7a4f634e 880
a6e0ebfe 881 const Char_t *sel1 = "SimHisto" ;
955f2093 882 TString out(Form("%s/%s",sel,sel1));
c30c0a38 883 AliCDBEntry *entry = man->Get(out,nrun);
884 if (!entry) {
7a4f634e 885 AliFatal("Exiting, no CDB object (SimHisto) found!!!");
886 exit(0);
887 }
40212801 888 if(!entry->GetObject()){
7a4f634e 889 AliFatal("Exiting, no CDB object (SimHisto) found!!!");
890 exit(0);
891 }
40212801 892 TH1F *histo =(TH1F*)entry->GetObject();
d4ad0d6b 893 fTOFSimToT=histo;
52be7fb0 894 return kTRUE;
d4ad0d6b 895}
7037bd93 896//_____________________________________________________________________________
a6e0ebfe 897void AliTOFcalib::WriteRecParOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun, AliTOFRecoParam *param){
7037bd93 898 //Write reconstruction parameters to the CDB
899
900 AliCDBManager *man = AliCDBManager::Instance();
7037bd93 901 AliCDBMetaData *md = new AliCDBMetaData();
902 md->SetResponsible("Silvia Arcelli");
641168d2 903 const Char_t *sel1 = "RecoParam" ;
955f2093 904 TString out(Form("%s/%s",sel,sel1));
7037bd93 905 AliCDBId id(out,minrun,maxrun);
906 man->Put(param,id,md);
907 delete md;
908}
909//_____________________________________________________________________________
d6888ae2 910AliTOFRecoParam * AliTOFcalib::ReadRecParFromCDB(const Char_t *sel, Int_t nrun, Int_t eventType)
7037bd93 911{
912 //Read reconstruction parameters from the CDB
913 AliCDBManager *man = AliCDBManager::Instance();
641168d2 914 const Char_t *sel1 = "RecoParam" ;
955f2093 915 TString out(Form("%s/%s",sel,sel1));
c30c0a38 916 AliCDBEntry *entry = man->Get(out,nrun);
917 if (!entry) {
641168d2 918 AliFatal("Exiting, no CDB object (RecoParam) found!!!");
7a4f634e 919 exit(0);
920 }
7a4f634e 921 if(!entry->GetObject()){
641168d2 922 AliFatal("Exiting, no CDB object (RecoParam) found!!!");
7a4f634e 923 exit(0);
924 }
925
d6888ae2 926 TObjArray *array = (TObjArray*)entry->GetObject();
927 AliTOFRecoParam *param=0x0;
928 if (eventType>=0 || eventType<array->GetEntries())
929 param=(AliTOFRecoParam*)array->At(eventType);
7037bd93 930 return param;
d6888ae2 931
7037bd93 932}
0a749fa5 933//-----------------------------------------------------------------------------
934// Calibration methods
935//-----------------------------------------------------------------------------
936void AliTOFcalib::CreateTreeFromCDB(Int_t minrun, Int_t maxrun){
937
938 // creating the chain with the trees for calibration
939 // collecting them from reference data
940 // from minrun to maxrun
941
942 Float_t p[CHENTRIESSMALL];
943 Int_t nentries;
944 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
945 fTree->Branch("nentries",&nentries,"nentries/I");
946 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
947 AliCDBManager *man = AliCDBManager::Instance();
162637e4 948 AliCDBStorage *aStorage = man->GetStorage("local://$ALICE_ROOT/OCDB");
0a749fa5 949 for (Int_t irun = minrun;irun<=maxrun;irun++){
950 AliCDBEntry *entry = aStorage->Get("TOF/RefData/TreeForCalib",irun);
951 if (!entry){
952 AliInfo(Form("No entry found for run %i",irun));
953 }
954 else{
af6e05be 955 TTree *tree = (TTree*)entry->GetObject();
0a749fa5 956 tree->SetBranchAddress("nentries",&nentries);
957 tree->SetBranchAddress("TOFentries",p);
958 fTree->CopyEntries(tree);
0a749fa5 959 fNruns++;
960 }
961 }
962 AliInfo(Form("Number of runs being analyzed %i",fNruns));
963}
964//-----------------------------------------------------------------------------
965void AliTOFcalib::CreateTreeFromGrid(Int_t minrun, Int_t maxrun){
966
967 // creating the chain with the trees for calibration
968 // collecting them from the Grid
969 // from minrun to maxrun
970
971 Float_t p[CHENTRIESSMALL];
972 Int_t nentries;
973 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
974 fTree->SetDirectory(0);
975 fTree->Branch("nentries",&nentries,"nentries/I");
976 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
977 AliInfo("connected to alien");
978 TGrid::Connect("alien://");
979
955f2093 980 TString filename;
0a749fa5 981 for (Int_t irun = minrun;irun<=maxrun;irun++){
955f2093 982 filename = Form("alien:///alice/cern.ch/user/c/czampolli/TOFCalibReference_%i.root",irun);
983 TFile *filegrid = TFile::Open(filename.Data(),"READ");
0a749fa5 984 TTree *tree = (TTree*)filegrid->Get("T");
985 tree->SetBranchAddress("nentries",&nentries);
986 tree->SetBranchAddress("TOFentries",p);
987 fTree->CopyEntries(tree);
988 delete tree;
989 fNruns++;
990 }
991
992 AliInfo(Form("Number of runs being analyzed %i",fNruns));
993}
994//-----------------------------------------------------------------------------
995void AliTOFcalib::CreateTreeFromFile(Int_t minrun, Int_t maxrun){
996
997 // creating the tree with the trees for calibration
998 // collecting them from reference data (from file)
999 // from minrun to maxrun
1000
1001 Float_t p[CHENTRIESSMALL];
1002 Int_t nentries;
1003 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
1004 fTree->SetDirectory(0);
1005 fTree->Branch("nentries",&nentries,"nentries/I");
1006 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
955f2093 1007 TString filename;
0a749fa5 1008 for (Int_t irun = minrun;irun<=maxrun;irun++){
955f2093 1009 filename = Form("$ALICE_ROOT/TOF/RefData/TreeForCalib/fileout_%i.root",irun);
1010 TFile *file = new TFile(filename.Data(),"READ");
0a749fa5 1011 TTree *tree = (TTree*)file->Get("T");
1012 tree->SetBranchAddress("nentries",&nentries);
1013 tree->SetBranchAddress("TOFentries",p);
1014 fTree->CopyEntries(tree);
1015 delete tree;
1016 delete file;
1017 file = 0x0;
1018 fNruns++;
1019 }
1020
1021 AliInfo(Form("Number of runs being analyzed %i",fNruns));
1022}
1023//-----------------------------------------------------------------------------
296591ad 1024void AliTOFcalib::CreateChainFromGrid(Int_t minrun, Int_t maxrun){
1025
1026 // creating the chain with the trees for calibration
1027 // collecting them from the Grid
1028 // from minrun to maxrun
1029
1030 fChain = new TChain("T");
1031 AliInfo("connected to alien");
1032 TGrid::Connect("alien://");
1033
955f2093 1034 TString filename;
296591ad 1035 for (Int_t irun = minrun;irun<=maxrun;irun++){
955f2093 1036 filename = Form("alien:///alice/cern.ch/user/c/czampolli/TOFCalibReference_%i.root",irun);
1037 fChain->Add(filename.Data());
296591ad 1038 fNruns++;
1039 }
1040
1041 AliInfo(Form("Number of runs being analyzed %i",fNruns));
1042}
1043//-----------------------------------------------------------------------------
0a749fa5 1044Int_t AliTOFcalib::Calibrate(Int_t ichmin, Int_t ichmax, Option_t *optionSave, Option_t *optionFit){
7037bd93 1045
0a749fa5 1046 // calibrating summing more than one channels
1047 // computing calibration parameters
1048 // Returning codes:
1049 // 0 -> everything was ok
1050 // 1 -> no tree for calibration found
1051 // 2 -> not enough statistics to perform calibration
1052 // 3 -> problems with arrays
1053
1054 TH1::AddDirectory(0);
1055
1056 AliInfo(Form("*** Calibrating Histograms %s, summing more channels, from channel %i, to channel %i, storing Calib Pars in channel %i", GetName(),ichmin,ichmax,ichmin)) ;
1057 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1058 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1059
1060 Float_t p[CHENTRIESSMALL];
1061 Int_t nentries;
296591ad 1062 //fTree->SetBranchAddress("nentries",&nentries);
1063 //fTree->SetBranchAddress("TOFentries",p);
1064 fChain->SetBranchAddress("nentries",&nentries);
1065 fChain->SetBranchAddress("TOFentries",p);
0a749fa5 1066
1067 Float_t ntracksTotalmean =0;
1068 for (Int_t i=ichmin; i<ichmax; i++){
1069 Int_t ientry = -1;
1070 for (Int_t irun=0;irun<fNruns;irun++){
1071 ientry = i+irun*fNChannels;
296591ad 1072 //fTree->GetEntry(ientry);
1073 fChain->GetEntry(ientry);
0a749fa5 1074 Int_t ntracksRun=nentries/3;
1075 ntracksTotalmean+=ntracksRun;
1076 }
1077 }
1078
1079 if (ntracksTotalmean < MEANENTRIES) {
1080 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
1081 return 2;
1082 }
1083
1084 //filling ToT and Time arrays
1085
1086 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
1087 Float_t minToT = 0; // ns
1088 Float_t maxToT = 4.88; // ns
1089
1090 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1091 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1092 Int_t ntracksTotal = 0;
1093 Int_t ntracksRun = 0;
1094 Double_t binsProfile[101]; // sized larger than necessary, the correct
1095 // dim being set in the booking of the profile
1096 Int_t nusefulbins=0;
1097 Float_t meantime=0;
1098 for (Int_t i = ichmin;i<ichmax;i++){
1099 Int_t ientry = -1;
1100 for (Int_t irun=0;irun<fNruns;irun++){
1101 ientry = i+irun*fNChannels;
296591ad 1102 //fTree->GetEntry(ientry);
1103 fChain->GetEntry(ientry);
0a749fa5 1104 ntracksTotal+=nentries/3;
1105 ntracksRun=nentries/3;
1106 AliDebug(2,Form("run %i, channel %i, nentries = %i, ntracks = %i",irun,i,nentries, ntracksRun));
1107 for (Int_t j=0;j<ntracksRun;j++){
1108 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1109 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1110 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1111 Float_t tot = p[idxexToT];
1112 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1113 meantime+=p[idxexTime]-p[idxexExTime];
1114 hToT->Fill(tot);
1115 }
1116 }
1117 }
1118 nusefulbins = FindBins(hToT,&binsProfile[0]);
1119 meantime/=ntracksTotal;
1120 AliDebug(2, Form("meantime = %f",meantime));
1121
1122 for (Int_t j=1;j<=nusefulbins;j++) {
1123 AliDebug(2,Form(" summing channels from %i to %i, nusefulbins = %i, bin %i = %f",ichmin,ichmax,nusefulbins,j,binsProfile[j]));
1124 }
1125
1126 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1127 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1128
1129 for (Int_t irun=0;irun<fNruns;irun++){
1130 Int_t ientry = -1;
1131 for (Int_t i=ichmin; i<ichmax; i++){
1132 ientry = i+irun*fNChannels;
296591ad 1133 //fTree->GetEntry(ientry);
1134 fChain->GetEntry(ientry);
0a749fa5 1135 ntracksRun=nentries/3;
1136 for (Int_t j=0;j<ntracksRun;j++){
1137 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1138 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1139 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1140 Float_t tot = p[idxexToT];
1141 Float_t time = p[idxexTime]-p[idxexExTime];
1142 AliDebug (2, Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1143 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1144 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1145 }
1146 }
1147 }
1148
1149 hSlewingProf->Fit("pol5",optionFit,"",0,4);
1150 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1151 Float_t par[6];
1152 for(Int_t kk=0;kk<6;kk++){
1153 par[kk]=calibfunc->GetParameter(kk);
1154 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1155 }
1156
1157 if(strstr(optionSave,"save")){
1158 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
1159 fileProf->cd();
1160 TString profName=Form("Profile%06i_%06i",ichmin,ichmax);
1161 TString timeTotName=Form("TimeTot%06i_%06i",ichmin,ichmax);
1162 TString totName=Form("Tot%06i_%06i",ichmin,ichmax);
1163 TString deltaName=Form("Delta%06i_%06i",ichmin,ichmax);
1164 hSlewingProf->Write(profName);
1165 htimetot->Write(timeTotName);
1166 hToT->Write(totName);
1167 hdeltaTime->Write(deltaName);
1168 fileProf->Close();
1169 delete fileProf;
1170 fileProf=0x0;
1171 }
1172
1173 delete hToT;
1174 hToT=0x0;
1175 delete hSlewingProf;
1176 hSlewingProf=0x0;
1177 delete htimetot;
1178 htimetot=0x0;
1179 delete hdeltaTime;
1180 hdeltaTime=0x0;
1181
1182 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ichmin);
1183 calChannel->SetSlewPar(par);
0cb9d099 1184 WriteParOfflineOnCDB("TOF/Calib","valid");
0a749fa5 1185 return 0;
1186}
1187//----------------------------------------------------------------------------
1188Int_t AliTOFcalib::Calibrate(Int_t i, Option_t *optionSave, Option_t *optionFit){
1189
1190 // computing calibration parameters for channel i
1191 // Returning codes:
1192 // 0 -> everything was ok
1193 // 1 -> no tree for calibration found
1194 // 2 -> not enough statistics to perform calibration
1195 // 3 -> problems with arrays
1196
1197 TH1::AddDirectory(0);
1198
1199 AliInfo(Form("*** Calibrating Histograms (one channel) %s", GetName())) ;
1200 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1201 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1202
1203 Float_t p[MAXCHENTRIESSMALL];
1204 Int_t nentries;
296591ad 1205 //fTree->SetBranchAddress("nentries",&nentries);
1206 //fTree->SetBranchAddress("TOFentries",p);
1207 fChain->SetBranchAddress("nentries",&nentries);
1208 fChain->SetBranchAddress("TOFentries",p);
0a749fa5 1209
1210 Float_t ntracksTotal =0;
1211 for (Int_t irun=0;irun<fNruns;irun++){
1212 Int_t ientry = -1;
1213 ientry = i+irun*fNChannels;
296591ad 1214 //fTree->GetEntry(ientry);
1215 fChain->GetEntry(ientry);
0a749fa5 1216 ntracksTotal+=nentries/3;
1217 }
1218
1219 if (ntracksTotal < MEANENTRIES) {
1220 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotal));
1221 return 2;
1222 }
1223
1224 //filling ToT and Time arrays
1225
1226 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
1227 Float_t minToT = 0; // ns
1228 Float_t maxToT = 4.88; // ns
1229
1230 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1231 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1232 Int_t ntracksRun = 0;
1233 Double_t binsProfile[101]; // sized larger than necessary, the correct
1234 // dim being set in the booking of the profile
1235 Int_t nusefulbins=0;
1236 Float_t meantime=0;
1237 for (Int_t irun=0;irun<fNruns;irun++){
1238 Int_t ientry = -1;
1239 ientry = i+irun*fNChannels;
296591ad 1240 //fTree->GetEntry(ientry);
1241 fChain->GetEntry(ientry);
0a749fa5 1242 ntracksRun=nentries/3;
1243 AliDebug(2,Form("run %i, channel %i, nentries = %i, ntracksRun = %i",irun, i ,nentries, ntracksRun));
1244 for (Int_t j=0;j<ntracksRun;j++){
1245 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1246 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1247 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1248 Float_t tot = p[idxexToT];
1249 meantime+=p[idxexTime]-p[idxexExTime];
1250 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1251 hToT->Fill(tot);
1252 }
1253 }
1254
1255 nusefulbins = FindBins(hToT,&binsProfile[0]);
1256 meantime/=ntracksTotal;
1257 AliDebug(2,Form("meantime = %f",meantime));
1258
1259 for (Int_t j=1;j<=nusefulbins;j++) {
1260 AliDebug(2,Form(" channel %i, nusefulbins = %i, bin %i = %f",i,nusefulbins,j,binsProfile[j]));
1261 }
1262
1263 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1264 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1265 for (Int_t irun=0;irun<fNruns;irun++){
1266 Int_t ientry = -1;
1267 ientry = i+irun*fNChannels;
296591ad 1268 //fTree->GetEntry(ientry);
1269 fChain->GetEntry(ientry);
0a749fa5 1270 ntracksRun=nentries/3;
1271 for (Int_t j=0;j<ntracksRun;j++){
1272 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1273 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1274 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1275 Float_t tot = p[idxexToT];
1276 Float_t time = p[idxexTime]-p[idxexExTime];
1277 AliDebug (2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1278 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1279 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1280 }
1281 }
1282
1283 hSlewingProf->Fit("pol5",optionFit,"",0,4);
1284 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1285 Float_t par[6];
1286 for(Int_t kk=0;kk<6;kk++){
1287 par[kk]=calibfunc->GetParameter(kk);
1288 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1289 }
1290
1291
1292 if(strstr(optionSave,"save")){
1293 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
1294 fileProf->cd();
1295 TString profName=Form("Profile%06i",i);
1296 TString timeTotName=Form("TimeTot%06i",i);
1297 TString totName=Form("Tot%06i",i);
1298 TString deltaName=Form("Delta%06i",i);
1299 hSlewingProf->Write(profName);
1300 htimetot->Write(timeTotName);
1301 hToT->Write(totName);
1302 hdeltaTime->Write(deltaName);
1303 fileProf->Close();
1304 delete fileProf;
1305 fileProf=0x0;
1306 }
1307
1308 delete hToT;
1309 hToT=0x0;
1310 delete hSlewingProf;
1311 hSlewingProf=0x0;
1312 delete htimetot;
1313 htimetot=0x0;
1314 delete hdeltaTime;
1315 hdeltaTime=0x0;
1316
1317 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(i);
1318 calChannel->SetSlewPar(par);
0cb9d099 1319 WriteParOfflineOnCDB("TOF/Calib","valid");
0a749fa5 1320 return 0;
1321}
1322//----------------------------------------------------------------------------
1323Int_t AliTOFcalib::Calibrate(Int_t nch, Int_t *ch, Option_t *optionSave, Option_t *optionFit){
1324
1325 // calibrating an array of channels
1326 // computing calibration parameters
1327 // Returning codes:
1328 // 0 -> everything was ok
1329 // 1 -> no tree for calibration found
1330 // 2 -> not enough statistics to perform calibration
1331 // 3 -> problems with arrays
1332
1333 TH1::AddDirectory(0);
1334
1335 AliInfo(Form("*** Calibrating Histograms %s, number of channels = %i", GetName(),nch)) ;
1336 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1337 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1338 for (Int_t ich=0; ich<nch; ich++){
1339 Int_t i = ch[ich];
1340 AliInfo(Form("Calibrating channel = %i",i )) ;
1341 }
1342 Float_t p[MAXCHENTRIESSMALL];
1343 Int_t nentries;
296591ad 1344 //fTree->SetBranchAddress("nentries",&nentries);
1345 //fTree->SetBranchAddress("TOFentries",p);
1346 fChain->SetBranchAddress("nentries",&nentries);
1347 fChain->SetBranchAddress("TOFentries",p);
0a749fa5 1348
1349 Float_t ntracksTotalmean =0;
1350 for (Int_t ich=0; ich<nch; ich++){
1351 Int_t ientry = -1;
1352 Int_t i = ch[ich];
1353 for (Int_t irun=0;irun<fNruns;irun++){
1354 ientry = i+irun*fNChannels;
296591ad 1355 //fTree->GetEntry(ientry);
1356 fChain->GetEntry(ientry);
0a749fa5 1357 ntracksTotalmean+=nentries/3;
1358 }
1359 }
1360
1361 ntracksTotalmean/=nch;
1362 if (ntracksTotalmean < MEANENTRIES) {
1363 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
1364 return 2;
1365 }
1366
1367 //filling ToT and Time arrays
1368
1369 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
1370 Float_t minToT = 0; // ns
1371 Float_t maxToT = 4.88; // ns
1372 TFile * fileProf=0x0;
1373 if(strstr(optionSave,"save")){
1374 fileProf = new TFile("TOFCalibSave.root","recreate");
1375 }
1376 for (Int_t ich=0; ich<nch; ich++) {
1377 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1378 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1379 Double_t binsProfile[101]; // sized larger than necessary, the correct
1380 // dim being set in the booking of the profile
1381 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1382 Int_t ntracksTotal = 0;
1383 Int_t ntracksRun = 0;
1384 Int_t nusefulbins=0;
1385 Float_t meantime=0;
1386 Int_t i=-1;
1387 for (Int_t irun=0;irun<fNruns;irun++){
1388 i = ch[ich]+irun*fNChannels;
1389 AliDebug(2,Form("Calibrating channel %i",i));
296591ad 1390 //fTree->GetEntry(i);
1391 fChain->GetEntry(i);
0a749fa5 1392 ntracksTotal+=nentries/3;
1393 }
1394 if (ntracksTotal < MEANENTRIES) {
4682c56e 1395 AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %d), not calibrating channel and continuing.....",i,ntracksTotal));
0a749fa5 1396 continue;
1397 }
1398
1399 for (Int_t irun=0;irun<fNruns;irun++){
3c609b5c 1400 i = ch[ich]+irun*fNChannels;
296591ad 1401 //fTree->GetEntry(i);
1402 fChain->GetEntry(i);
0a749fa5 1403 ntracksRun=nentries/3;
1404 for (Int_t j=0;j<ntracksRun;j++){
1405 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1406 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1407 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1408 Float_t tot = p[idxexToT];
1409 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1410 meantime+=p[idxexTime]-p[idxexExTime];
1411 hToT->Fill(tot);
1412 }
1413 }
1414
1415 nusefulbins = FindBins(hToT,&binsProfile[0]);
1416 meantime/=ntracksTotal;
1417 for (Int_t j=1;j<=nusefulbins;j++) {
1418 AliDebug(2,Form(" channel %i, nusefulbins = %i, bin %i = %f",i,nusefulbins,j,binsProfile[j]));
1419 }
1420
1421 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1422 for (Int_t irun=0;irun<fNruns;irun++){
3c609b5c 1423 i = ch[ich]+irun*fNChannels;
296591ad 1424 //fTree->GetEntry(i);
1425 fChain->GetEntry(i);
0a749fa5 1426 ntracksRun=nentries/3;
1427 for (Int_t j=0;j<ntracksRun;j++){
1428 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1429 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1430 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1431 Float_t tot = p[idxexToT];
1432 Float_t time = p[idxexTime]-p[idxexExTime];
1433 AliDebug(2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1434 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1435 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1436 }
1437 }
1438
1439 hSlewingProf->Fit("pol5",optionFit,"",1,4);
1440 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1441 Float_t par[6];
1442 for(Int_t kk=0;kk<6;kk++){
1443 par[kk]=calibfunc->GetParameter(kk);
1444 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1445 }
1446
1447 if(strstr(optionSave,"save") && fileProf){
1448 TString profName=Form("Profile%06i",i);
1449 TString timeTotName=Form("TimeTot%06i",i);
1450 TString totName=Form("Tot%06i",i);
1451 TString deltaName=Form("Delta%06i",i);
1452 fileProf->cd();
1453 hSlewingProf->Write(profName);
1454 htimetot->Write(timeTotName);
1455 hToT->Write(totName);
1456 hdeltaTime->Write(deltaName);
1457 }
1458
1459 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(i);
1460 calChannel->SetSlewPar(par);
1461 delete hToT;
1462 hToT=0x0;
1463 delete hSlewingProf;
1464 hSlewingProf=0x0;
1465 delete htimetot;
1466 htimetot=0x0;
1467 delete hdeltaTime;
1468 hdeltaTime=0x0;
1469 }
1470
1471 if(strstr(optionSave,"save") && fileProf){
1472 fileProf->Close();
1473 delete fileProf;
1474 fileProf=0x0;
1475 }
0cb9d099 1476 WriteParOfflineOnCDB("TOF/Calib","valid");
0a749fa5 1477
1478 return 0;
1479}
1480//----------------------------------------------------------------------------
1481Int_t AliTOFcalib::CalibrateFromProfile(Int_t ich, Option_t *optionSave, Option_t *optionFit){
1482
1483 // computing calibration parameters using the old profiling algo
1484 // Returning codes:
1485 // 0 -> everything was ok
1486 // 1 -> no tree for calibration found
1487 // 2 -> not enough statistics to perform calibration
1488 // 3 -> problems with arrays
1489
1490 TH1::AddDirectory(0);
1491
1492 AliInfo(Form("*** Calibrating Histograms From Profile %s", GetName())) ;
1493 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1494 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1495 Float_t p[MAXCHENTRIESSMALL];
1496 Int_t nentries;
1497 Int_t ntracksTotal=0;
296591ad 1498 //fTree->SetBranchAddress("nentries",&nentries);
1499 //fTree->SetBranchAddress("TOFentries",p);
1500 fChain->SetBranchAddress("nentries",&nentries);
1501 fChain->SetBranchAddress("TOFentries",p);
0a749fa5 1502
1503 for (Int_t irun=0;irun<fNruns;irun++){
1504 Int_t i = ich+irun*fNChannels;
296591ad 1505 //fTree->GetEntry(i);
1506 fChain->GetEntry(i);
0a749fa5 1507 ntracksTotal+=nentries/3;
1508 }
1509
1510 if (ntracksTotal < MEANENTRIES) {
4682c56e 1511 AliInfo(Form(" Too small mean number of entires per channel (mean number = %d) not calibrating and exiting.....",ntracksTotal));
0a749fa5 1512 return 2;
1513 }
1514
af6e05be 1515 TH1F * hProf = Profile(ich);
0a749fa5 1516 hProf->Fit("pol5",optionFit,"",0,4);
1517 TF1 * calibfunc = (TF1*)hProf->GetFunction("pol5");
1518 Float_t par[6];
1519 for(Int_t kk=0;kk<6;kk++){
1520 par[kk]=calibfunc->GetParameter(kk);
1521 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1522 }
1523
1524 if(strstr(optionSave,"save")){
1525 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
1526 fileProf->cd();
1527 TString profName=Form("Profile%06i",ich);
1528 hProf->Write(profName);
1529 fileProf->Close();
1530 delete fileProf;
1531 fileProf=0x0;
1532 }
1533
1534 delete hProf;
1535 hProf=0x0;
1536 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ich);
1537 calChannel->SetSlewPar(par);
0cb9d099 1538 WriteParOfflineOnCDB("TOF/Calib","valid");
0a749fa5 1539 return 0;
1540}
1541//----------------------------------------------------------------------------
1542Int_t AliTOFcalib::Calibrate(Option_t *optionSave, Option_t *optionFit){
1543
1544 // calibrating the whole TOF
1545 // computing calibration parameters
1546 // Returning codes:
1547 // 0 -> everything was ok
1548 // 1 -> no tree for calibration found
1549 // 2 -> not enough statistics to perform calibration
1550 // 3 -> problems with arrays
1551
1552 TH1::AddDirectory(0);
1553
1554 AliInfo(Form("*** Calibrating Histograms %s, all channels", GetName())) ;
1555 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1556 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1557
1558 TFile * fileProf=0x0;
1559 if(strstr(optionSave,"save")){
1560 fileProf = new TFile("TOFCalibSave.root","recreate");
1561 }
1562
1563 Float_t p[MAXCHENTRIESSMALL];
1564 Int_t nentries;
296591ad 1565 //fTree->SetBranchAddress("nentries",&nentries);
1566 //fTree->SetBranchAddress("TOFentries",p);
1567 fChain->SetBranchAddress("nentries",&nentries);
1568 fChain->SetBranchAddress("TOFentries",p);
0a749fa5 1569
1570 Float_t ntracksTotalmean =0;
1571 for (Int_t ii=0; ii<fNChannels; ii++){
1572 for (Int_t irun=0;irun<fNruns;irun++){
1573 Int_t i = ii+irun*fNChannels;
296591ad 1574 //fTree->GetEntry(i);
1575 fChain->GetEntry(i);
0a749fa5 1576 ntracksTotalmean+=nentries/3;
1577 }
1578 }
1579
1580 ntracksTotalmean/=fNChannels;
1581 if (ntracksTotalmean < MEANENTRIES) {
1582 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
1583 return 2;
1584 }
1585
1586 //filling ToT and Time arrays
1587
1588 Int_t nbinToT = 100; // ToT bin width in Profile = 50.0 ps
1589 Float_t minToT = 0; // ns
1590 Float_t maxToT = 4.88;// ns
1591 for (Int_t ii=0; ii<fNChannels; ii++) {
1592 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1593 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1594 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1595 if (ii%1000 == 0) AliDebug(1,Form("Calibrating channel %i ",ii));
1596 //Int_t i = 3;
1597 Int_t nusefulbins=0;
1598 Double_t binsProfile[101]; // sized larger than necessary, the correct
1599 // dim being set in the booking of the profile
1600 Int_t ntracksRun = 0;
1601 Int_t ntracksTotal = 0;
1602 for (Int_t irun=0;irun<fNruns;irun++){
1603 Int_t i = ii+irun*fNChannels;
296591ad 1604 //fTree->GetEntry(i);
1605 fChain->GetEntry(i);
0a749fa5 1606 ntracksTotal+=nentries/3;
1607 }
1608 if (ntracksTotal < MEANENTRIES) {
4682c56e 1609 AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %d), not calibrating channel and continuing.....",ii,ntracksTotal));
0a749fa5 1610 continue;
1611 }
1612 Float_t meantime=0;
1613 for (Int_t irun=0;irun<fNruns;irun++){
1614 Int_t i = ii+irun*fNChannels;
296591ad 1615 //fTree->GetEntry(i);
1616 fChain->GetEntry(i);
0a749fa5 1617 ntracksRun=nentries/3;
1618 for (Int_t j=0;j<ntracksRun;j++){
1619 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1620 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1621 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1622 Float_t tot = p[idxexToT];
1623 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1624 meantime+=p[idxexTime]-p[idxexExTime];
1625 hToT->Fill(tot);
1626 }
1627 }
1628 nusefulbins = FindBins(hToT,&binsProfile[0]);
1629 meantime/=ntracksTotal;
1630 for (Int_t j=0;j<nusefulbins;j++) {
1631 AliDebug(2,Form(" channel %i, usefulbin = %i, low edge = %f",ii,j,binsProfile[j]));
1632 }
1633 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1634 for (Int_t irun=0;irun<fNruns;irun++){
1635 Int_t i = ii+irun*fNChannels;
296591ad 1636 //fTree->GetEntry(i);
1637 fChain->GetEntry(i);
0a749fa5 1638 ntracksRun=nentries/3;
1639 for (Int_t j=0;j<ntracksRun;j++){
1640 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1641 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1642 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1643 Float_t tot = p[idxexToT];
1644 Float_t time = p[idxexTime]-p[idxexExTime];
1645 AliDebug (2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1646 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1647 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1648 }
1649 }
1650 hSlewingProf->Fit("pol5",optionFit,"",1,4);
1651 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1652 Float_t par[6];
1653 for(Int_t kk=0;kk<6;kk++){
1654 par[kk]=calibfunc->GetParameter(kk);
1655 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1656 }
1657
1658 if(strstr(optionSave,"save") && fileProf){
1659 TString profName=Form("Profile%06i",ii);
1660 TString timeTotName=Form("TimeTot%06i",ii);
1661 TString totName=Form("Tot%06i",ii);
1662 TString deltaName=Form("Delta%06i",ii);
1663 fileProf->cd();
1664 hSlewingProf->Write(profName);
1665 htimetot->Write(timeTotName);
1666 hToT->Write(totName);
1667 hdeltaTime->Write(deltaName);
1668 }
1669 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ii);
1670 calChannel->SetSlewPar(par);
1671
1672 delete hToT;
1673 hToT=0x0;
1674 delete hSlewingProf;
1675 hSlewingProf=0x0;
1676 delete htimetot;
1677 htimetot=0x0;
1678 delete hdeltaTime;
1679 hdeltaTime=0x0;
1680 }
1681
1682 if(strstr(optionSave,"save")){
1683 fileProf->Close();
1684 delete fileProf;
1685 fileProf=0x0;
1686 }
0cb9d099 1687 WriteParOfflineOnCDB("TOF/Calib","valid");
0a749fa5 1688 return 0;
1689}
1690
1691//-----------------------------------------------------------------------
1692TH1F* AliTOFcalib::Profile(Int_t ich)
340693af 1693{
0a749fa5 1694 // profiling algo
1695
1696 Float_t p[MAXCHENTRIESSMALL];
1697 Int_t nentries;
296591ad 1698 //fTree->SetBranchAddress("nentries",&nentries);
1699 //fTree->SetBranchAddress("TOFentries",p);
1700 fChain->SetBranchAddress("nentries",&nentries);
1701 fChain->SetBranchAddress("TOFentries",p);
0a749fa5 1702
1703 //Prepare histograms for Slewing Correction
1704 const Int_t knbinToT = 100;
1705 Int_t nbinTime = 200;
1706 Float_t minTime = -5.5; //ns
1707 Float_t maxTime = 5.5; //ns
1708 Float_t minToT = 0; //ns
1709 Float_t maxToT = 5.; //ns
1710 Float_t deltaToT = (maxToT-minToT)/knbinToT;
1711 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];
1712 Int_t n[knbinToT+1], nentrx[knbinToT+1];
1713 Double_t sigmaToT[knbinToT+1];
1714 for (Int_t i = 0; i < knbinToT+1 ; i++){
1715 mTime[i]=0;
1716 mToT[i]=0;
1717 n[i]=0;
1718 meanTime[i]=0;
1719 meanTime2[i]=0;
1720 vToT[i]=0;
1721 vToT2[i]=0;
1722 meanToT[i]=0;
1723 meanToT2[i]=0;
1724 vTime[i]=0;
1725 vTime2[i]=0;
1726 xlow[i]=0;
1727 sigmaTime[i]=0;
1728 sigmaToT[i]=0;
1729 n[i]=0;
1730 nentrx[i]=0;
1731 }
1732 TH2F* hSlewing = new TH2F("hSlewing", "hSlewing", knbinToT, minToT, maxToT, nbinTime, minTime, maxTime);
1733 Int_t ntracksRun = 0;
1734 TH1F *histo = new TH1F("histo", "1D Time vs ToT", knbinToT, minToT, maxToT);
1735 for (Int_t irun=0;irun<fNruns;irun++){
1736 Int_t i = ich+irun*fNChannels;
296591ad 1737 //fTree->GetEntry(i);
1738 fChain->GetEntry(i);
0a749fa5 1739 ntracksRun=nentries/3;
1740 for (Int_t j=0;j<ntracksRun;j++){
1741 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1742 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1743 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1744 Float_t tot = p[idxexToT];
1745 Float_t time = p[idxexTime]-p[idxexExTime];
1746 Int_t nx = (Int_t)((tot-minToT)/deltaToT)+1;
1747 if ((tot != 0) && ( time!= 0)){
1748 vTime[nx]+=time;
1749 vTime2[nx]+=time*time;
1750 vToT[nx]+=tot;
1751 vToT2[nx]+=tot*tot;
1752 nentrx[nx]++;
1753 hSlewing->Fill(tot,time);
1754 }
1755 }
1756 }
1757 Int_t nbinsToT=hSlewing->GetNbinsX();
1758 if (nbinsToT != knbinToT) {
1759 AliError("Profile :: incompatible numbers of bins");
1760 return 0x0;
1761 }
1762
1763 Int_t usefulBins=0;
1764 for (Int_t i=1;i<=nbinsToT;i++){
1765 if (nentrx[i]!=0){
1766 n[usefulBins]+=nentrx[i];
1767 if (n[usefulBins]==0 && i == nbinsToT) {
1768 break;
1769 }
1770 meanTime[usefulBins]+=vTime[i];
1771 meanTime2[usefulBins]+=vTime2[i];
1772 meanToT[usefulBins]+=vToT[i];
1773 meanToT2[usefulBins]+=vToT2[i];
1774 if (n[usefulBins]<10 && i!=nbinsToT) continue;
1775 mTime[usefulBins]=meanTime[usefulBins]/n[usefulBins];
1776 mToT[usefulBins]=meanToT[usefulBins]/n[usefulBins];
1777 sigmaTime[usefulBins]=TMath::Sqrt(1./n[usefulBins]/n[usefulBins]
1778 *(meanTime2[usefulBins]-meanTime[usefulBins]
1779 *meanTime[usefulBins]/n[usefulBins]));
1780 if ((1./n[usefulBins]/n[usefulBins]
1781 *(meanToT2[usefulBins]-meanToT[usefulBins]
1782 *meanToT[usefulBins]/n[usefulBins]))< 0) {
1783 AliError(" too small radical" );
1784 sigmaToT[usefulBins]=0;
1785 }
1786 else{
1787 sigmaToT[usefulBins]=TMath::Sqrt(1./n[usefulBins]/n[usefulBins]
1788 *(meanToT2[usefulBins]-meanToT[usefulBins]
1789 *meanToT[usefulBins]/n[usefulBins]));
1790 }
1791 usefulBins++;
1792 }
1793 }
1794 for (Int_t i=0;i<usefulBins;i++){
1795 Int_t binN = (Int_t)((mToT[i]-minToT)/deltaToT)+1;
1796 histo->Fill(mToT[i],mTime[i]);
1797 histo->SetBinError(binN,sigmaTime[i]);
1798 }
1799 delete hSlewing;
1800 hSlewing=0x0;
1801
1802 return histo;
6dc9348d 1803}
0a749fa5 1804//----------------------------------------------------------------------------
1805Int_t AliTOFcalib::FindBins(TH1F* h, Double_t *binsProfile) const{
6dc9348d 1806
0a749fa5 1807 // to determine the bins for ToT histo
1808
1809 Int_t cont = 0;
1810 Int_t startBin = 1;
1811 Int_t nbin = h->GetNbinsX();
1812 Int_t nentries = (Int_t)h->GetEntries();
1813 Float_t max = h->GetBinLowEdge(nbin);
1814 Int_t nusefulbins=0;
1815 Int_t maxcont=0;
1816 // setting maxvalue of entries per bin
1817 if (nentries <= 60) maxcont = 2;
1818 else if (nentries <= 100) maxcont = 5;
1819 else if (nentries <= 500) maxcont = 10;
1820 else maxcont = 20;
1821 for (Int_t j=1;j<=nbin;j++) {
1822 cont += (Int_t)h->GetBinContent(j);
1823 if (j<nbin){
1824 if (cont>=maxcont){
1825 nusefulbins++;
1826 binsProfile[nusefulbins-1]=h->GetBinLowEdge(startBin);
1827 cont=0;
1828 startBin=j+1;
1829 continue;
1830 }
1831 }
1832 else{
1833 if (cont>=maxcont){
1834 nusefulbins++;
1835 binsProfile[nusefulbins-1]=h->GetBinLowEdge(startBin);
1836 binsProfile[nusefulbins]=max;
1837 }
1838 else {
1839 binsProfile[nusefulbins]=h->GetBinLowEdge(startBin);
1840 }
1841 }
1842 }
1843 return nusefulbins;
1844}
2bf4d9d6 1845
1846
1847//----------------------------------------------------------------------------
1848
1849void
1850AliTOFcalib::CreateDeltaBCOffset()
1851{
1852 /*
1853 * create deltaBC offset
1854 */
1855
1856 if (fDeltaBCOffset) {
1857 AliWarning("DeltaBCOffset object already defined, cannot create a new one");
1858 return;
1859 }
1860 fDeltaBCOffset = new AliTOFDeltaBCOffset();
1861}
1862
1863//----------------------------------------------------------------------------
1864
1865void
1866AliTOFcalib::CreateCTPLatency()
1867{
1868 /*
1869 * create CTP latency
1870 */
1871
1872 if (fCTPLatency) {
1873 AliWarning("CTPLatency object already defined, cannot create a new one");
1874 return;
1875 }
1876 fCTPLatency = new AliTOFCTPLatency();
1877}
1878
1879//----------------------------------------------------------------------------
1880
1881void
1882AliTOFcalib::CreateT0Fill()
1883{
1884 /*
1885 * create event-time
1886 */
1887
1888 if (fT0Fill) {
1889 AliWarning("T0Fill object already defined, cannot create a new one");
1890 return;
1891 }
1892 fT0Fill = new AliTOFT0Fill();
1893}
1894
1895//----------------------------------------------------------------------------
1896
f04b3a69 1897void
1898AliTOFcalib::CreateRunParams()
1899{
1900 /*
1901 * create run params
1902 */
1903
1904 if (fRunParams) {
1905 AliWarning("RunParams object already defined, cannot create a new one");
1906 return;
1907 }
1908 fRunParams = new AliTOFRunParams();
1909}
1910
1911//----------------------------------------------------------------------------
1912
2bf4d9d6 1913void
1914AliTOFcalib::WriteDeltaBCOffsetOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
1915{
1916 /*
1917 * deltaBC offset on CDB
1918 */
1919
1920 if (!fDeltaBCOffset) return;
1921 AliCDBId id(Form("%s/DeltaBCOffset", sel), minrun, maxrun);
1922 AliCDBMetaData *md = new AliCDBMetaData();
1923 md->SetResponsible("Roberto Preghenella");
1924 AliCDBManager *man = AliCDBManager::Instance();
1925 man->Put(fDeltaBCOffset, id, md);
1926 AliDebug(2,Form("DeltaBCOffset written on CDB with run range [%i, %i] ",minrun ,maxrun));
1927 delete md;
1928}
1929
1930//----------------------------------------------------------------------------
1931
1932void
1933AliTOFcalib::WriteCTPLatencyOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
1934{
1935 /*
1936 * write CTP latency on CDB
1937 */
1938
1939 if (!fCTPLatency) return;
1940 AliCDBId id(Form("%s/CTPLatency", sel), minrun, maxrun);
1941 AliCDBMetaData *md = new AliCDBMetaData();
1942 md->SetResponsible("Roberto Preghenella");
1943 AliCDBManager *man = AliCDBManager::Instance();
1944 man->Put(fCTPLatency, id, md);
1945 AliDebug(2,Form("CTPLatency written on CDB with run range [%i, %i] ",minrun ,maxrun));
1946 delete md;
1947}
1948
1949//----------------------------------------------------------------------------
1950
1951void
1952AliTOFcalib::WriteT0FillOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
1953{
1954 /*
1955 * write event-time on CDB
1956 */
1957
1958 if (!fT0Fill) return;
1959 AliCDBId id(Form("%s/T0Fill", sel), minrun, maxrun);
1960 AliCDBMetaData *md = new AliCDBMetaData();
1961 md->SetResponsible("Roberto Preghenella");
1962 AliCDBManager *man = AliCDBManager::Instance();
1963 man->Put(fT0Fill, id, md);
1964 AliDebug(2,Form("T0Fill written on CDB with run range [%i, %i] ",minrun ,maxrun));
1965 delete md;
1966}
1967
1968//----------------------------------------------------------------------------
1969
f04b3a69 1970void
1971AliTOFcalib::WriteRunParamsOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
1972{
1973 /*
1974 * write run params on CDB
1975 */
1976
1977 if (!fRunParams) return;
1978 AliCDBId id(Form("%s/RunParams", sel), minrun, maxrun);
1979 AliCDBMetaData *md = new AliCDBMetaData();
1980 md->SetResponsible("Roberto Preghenella");
1981 AliCDBManager *man = AliCDBManager::Instance();
1982 man->Put(fRunParams, id, md);
1983 AliDebug(2,Form("RunParams written on CDB with run range [%i, %i] ",minrun ,maxrun));
1984 delete md;
1985}
1986
1987//----------------------------------------------------------------------------
1988
2bf4d9d6 1989Bool_t
1990AliTOFcalib::ReadDeltaBCOffsetFromCDB(const Char_t *sel , Int_t nrun)
1991{
1992 /*
1993 * read deltaBC offset from CDB
1994 */
1995
1996 AliCDBManager *man = AliCDBManager::Instance();
1997 AliCDBEntry *entry = man->Get(Form("%s/DeltaBCOffset", sel),nrun);
1998 if (!entry) {
1999 AliFatal("No DeltaBCOffset entry found in CDB");
2000 exit(0);
2001 }
2002 fDeltaBCOffset =(AliTOFDeltaBCOffset *)entry->GetObject();
2003 if(!fDeltaBCOffset){
2004 AliFatal("No DeltaBCOffset object found in CDB entry");
2005 exit(0);
2006 }
2007 return kTRUE;
2008}
2009
2010//----------------------------------------------------------------------------
2011
2012Bool_t
2013AliTOFcalib::ReadCTPLatencyFromCDB(const Char_t *sel , Int_t nrun)
2014{
2015 /*
2016 * read CTP latency from CDB
2017 */
2018
2019 AliCDBManager *man = AliCDBManager::Instance();
2020 AliCDBEntry *entry = man->Get(Form("%s/CTPLatency", sel),nrun);
2021 if (!entry) {
2022 AliFatal("No CTPLatency entry found in CDB");
2023 exit(0);
2024 }
2025 fCTPLatency =(AliTOFCTPLatency *)entry->GetObject();
2026 if(!fCTPLatency){
2027 AliFatal("No CTPLatency object found in CDB entry");
2028 exit(0);
2029 }
2030 return kTRUE;
2031}
2032
2033//----------------------------------------------------------------------------
2034
2035Bool_t
2036AliTOFcalib::ReadT0FillFromCDB(const Char_t *sel , Int_t nrun)
2037{
2038 /*
2039 * read event-time from CDB
2040 */
2041
2042 AliCDBManager *man = AliCDBManager::Instance();
2043 AliCDBEntry *entry = man->Get(Form("%s/T0Fill", sel),nrun);
2044 if (!entry) {
2045 AliFatal("No T0Fill entry found in CDB");
2046 exit(0);
2047 }
2048 fT0Fill =(AliTOFT0Fill *)entry->GetObject();
2049 if(!fT0Fill){
2050 AliFatal("No T0Fill object found in CDB entry");
2051 exit(0);
2052 }
2053 return kTRUE;
2054}
2055
f04b3a69 2056//----------------------------------------------------------------------------
2057
2058Bool_t
2059AliTOFcalib::ReadRunParamsFromCDB(const Char_t *sel , Int_t nrun)
2060{
2061 /*
2062 * read run params from CDB
2063 */
2064
2065 AliCDBManager *man = AliCDBManager::Instance();
2066 AliCDBEntry *entry = man->Get(Form("%s/RunParams", sel),nrun);
2067 if (!entry) {
2068 AliFatal("No RunParams entry found in CDB");
2069 exit(0);
2070 }
2071 fRunParams =(AliTOFRunParams *)entry->GetObject();
2072 if(!fRunParams){
2073 AliFatal("No RunParams object found in CDB entry");
2074 exit(0);
2075 }
2076 return kTRUE;
2077}
2078
5b4ed716 2079//----------------------------------------------------------------------------
2080
2081Bool_t
2082AliTOFcalib::Init(Int_t run)
2083{
2084 /*
2085 * init
2086 */
2087
2088 if (fInitFlag) {
2089 AliWarning("the class was already initialized, re-initialize it");
2090 fInitFlag = kFALSE;
2091 }
2092
2093 /* read channel status array */
2094 if (!ReadParOnlineStatusFromCDB("TOF/Calib", run)) {
2095 AliError("cannot get \"Status\" object from OCDB");
2096 return kFALSE;
2097 }
2098 /* get par offline array */
2099 if (!ReadParOfflineFromCDB("TOF/Calib", run)) {
2100 AliError("cannot get \"ParOffline\" object from OCDB");
2101 return kFALSE;
2102 }
2103 /* get deltaBC offset obj */
2104 if (!ReadDeltaBCOffsetFromCDB("TOF/Calib", run)) {
2105 AliError("cannot get \"DeltaBCOffset\" object from OCDB");
2106 return kFALSE;
2107 }
2108 /* get CTP latency obj */
2109 if (!ReadCTPLatencyFromCDB("TOF/Calib", run)) {
2110 AliError("cannot get \"CTPLatency\" object from OCDB");
2111 return kFALSE;
2112 }
2113 /* get run params obj */
2114 if (!ReadRunParamsFromCDB("TOF/Calib", run)) {
2115 AliError("cannot get \"RunParams\" object from OCDB");
2116 return kFALSE;
2117 }
2118 /* get response params */
2119 if (fCorrectTExp) {
2120 TFile *responseFile = TFile::Open("$ALICE_ROOT/TOF/data/AliTOFresponsePar.root");
2121 if (!responseFile || !responseFile->IsOpen()) {
2122 AliError("cannot open \"ResponseParams\" local file");
2123 return kFALSE;
2124 }
2125 fResponseParams = (AliTOFResponseParams *)responseFile->Get("ResponseParams");
2126 if (!fResponseParams) {
2127 AliError("cannot get \"ResponseParams\" object from local file");
2128 return kFALSE;
2129 }
2130 responseFile->Close();
2131 }
2132
2133 /* all done */
2134 fInitFlag = kTRUE;
2135 return kTRUE;
2136
2137}
2138
2139//----------------------------------------------------------------------------
2140
2141Double_t
2142AliTOFcalib::GetTimeCorrection(Int_t index, Double_t tot, Int_t deltaBC, Int_t l0l1, UInt_t timestamp)
2143{
2144 /*
2145 * get time correction
2146 */
2147
2148 if (!fInitFlag) {
2149 AliError("class not yet initialized. Initialize it before.");
2150 return 0.;
2151 }
2152
2153 /* get calibration params */
2154 AliTOFChannelOffline *parOffline = (AliTOFChannelOffline *)fTOFCalOffline->At(index);
2155 Int_t deltaBCOffset = fDeltaBCOffset->GetDeltaBCOffset();
2156 Float_t ctpLatency = fCTPLatency->GetCTPLatency();
2157 Float_t tdcLatencyWindow = fStatus->GetLatencyWindow(index) * 1.e3;
2158 Float_t timezero = fRunParams->EvalT0(timestamp);
2159 /* check whether to remove mean T0.
2160 * useful when one wants to compute mean T0 */
2161 if (!fRemoveMeanT0) timezero = 0.;
2162
2163 /* compute correction */
2164 Double_t corr = 0.;
2165 /* deltaBC correction */
2166 deltaBC = deltaBCOffset; /* inhibit deltaBC correction for the time being */
2167 corr += (deltaBC - deltaBCOffset) * AliTOFGeometry::BunchCrossingBinWidth();
2168 /* L0-L1 latency correction */
2169 corr -= l0l1 * AliTOFGeometry::BunchCrossingBinWidth();
2170 /* CTP latency correction */
2171 corr -= ctpLatency;
2172 /* TDC latency window correction */
2173 corr += tdcLatencyWindow;
2174 /* time-zero correction */
2175 corr += timezero;
2176 /* time calibration correction */
2177 if (tot < AliTOFGeometry::SlewTOTMin())
2178 tot = AliTOFGeometry::SlewTOTMin();
2179 if (tot > AliTOFGeometry::SlewTOTMax())
2180 tot = AliTOFGeometry::SlewTOTMax();
2181 for (Int_t islew = 0; islew < 6; islew++)
2182 corr += parOffline->GetSlewPar(islew) * TMath::Power(tot, islew) * 1.e3;
2183
2184 /* return correction */
2185 return corr;
2186}
2187
2188//----------------------------------------------------------------------------
2189
2190void
2191AliTOFcalib::CalibrateESD(AliESDEvent *event)
2192{
2193 /*
2194 * calibrate ESD
2195 */
2196
2197 if (!fInitFlag) {
2198 AliError("class not yet initialized. Initialize it before.");
2199 return;
2200 }
2201
2202 /* loop over tracks */
2203 AliESDtrack *track = NULL;
2204 Int_t index, l0l1, deltaBC;
2205 Double_t time, tot, corr, texp[AliPID::kSPECIES];
2206 UInt_t timestamp = event->GetTimeStamp();
2207 for (Int_t itrk = 0; itrk < event->GetNumberOfTracks(); itrk++) {
2208
2209 /* get track */
2210 track = event->GetTrack(itrk);
2211 if (!track || !(track->GetStatus() & AliESDtrack::kTOFout)) continue;
8bb89c94 2212
2213 /* calibrate TOF signal */
2214 if (fCalibrateTOFsignal) {
2215 /* get info */
2216 index = track->GetTOFCalChannel();
2217 time = track->GetTOFsignalRaw();
2218 tot = track->GetTOFsignalToT();
2219 l0l1 = track->GetTOFL0L1();
2220 deltaBC = track->GetTOFDeltaBC();
2221 /* get correction */
2222 corr = GetTimeCorrection(index, tot, deltaBC, l0l1, timestamp);
2223 /* apply correction */
2224 time -= corr;
2225 /* set new TOF signal */
2226 track->SetTOFsignal(time);
2227 }
5b4ed716 2228
2229 /* correct expected time */
2230 if (fCorrectTExp) {
2231 /* get integrated times */
2232 track->GetIntegratedTimes(texp);
2233 /* loop over particle types and correct expected time */
2234 for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++)
2235 texp[ipart] += fResponseParams->EvalTExpCorr(ipart, track->P());
2236 /* set integrated times */
2237 track->SetIntegratedTimes(texp);
2238 }
2239
2240 }
2241
2242}
2243
2244//----------------------------------------------------------------------------
2245
2246Bool_t
2247AliTOFcalib::IsChannelEnabled(Int_t index)
2248{
2249 /*
2250 * is channel enabled
2251 */
2252
2253 if (!fInitFlag) {
2254 AliError("class not yet initialized. Initialize it before.");
2255 return kTRUE;
2256 }
2257
2258 /* check bad status */
2259 if (fStatus->GetPulserStatus(index) == AliTOFChannelOnlineStatusArray::kTOFPulserBad) return kFALSE;
2260 if (fStatus->GetNoiseStatus(index) == AliTOFChannelOnlineStatusArray::kTOFNoiseBad) return kFALSE;
2261 if (fStatus->GetHWStatus(index) == AliTOFChannelOnlineStatusArray::kTOFHWBad) return kFALSE;
2262
2263 /* good status */
2264 return kTRUE;
2265
2266}