]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TOF/AliTOFcalib.cxx
adding AliHLTGlobalHistoComponent (ID GlobalHisto) for histogramming of global ESDEve...
[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//_____________________________________________________________________________
a6e0ebfe 910AliTOFRecoParam * AliTOFcalib::ReadRecParFromCDB(const Char_t *sel, Int_t nrun)
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
7037bd93 926 AliTOFRecoParam *param=(AliTOFRecoParam*)entry->GetObject();
927 return param;
928}
0a749fa5 929//-----------------------------------------------------------------------------
930// Calibration methods
931//-----------------------------------------------------------------------------
932void AliTOFcalib::CreateTreeFromCDB(Int_t minrun, Int_t maxrun){
933
934 // creating the chain with the trees for calibration
935 // collecting them from reference data
936 // from minrun to maxrun
937
938 Float_t p[CHENTRIESSMALL];
939 Int_t nentries;
940 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
941 fTree->Branch("nentries",&nentries,"nentries/I");
942 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
943 AliCDBManager *man = AliCDBManager::Instance();
162637e4 944 AliCDBStorage *aStorage = man->GetStorage("local://$ALICE_ROOT/OCDB");
0a749fa5 945 for (Int_t irun = minrun;irun<=maxrun;irun++){
946 AliCDBEntry *entry = aStorage->Get("TOF/RefData/TreeForCalib",irun);
947 if (!entry){
948 AliInfo(Form("No entry found for run %i",irun));
949 }
950 else{
af6e05be 951 TTree *tree = (TTree*)entry->GetObject();
0a749fa5 952 tree->SetBranchAddress("nentries",&nentries);
953 tree->SetBranchAddress("TOFentries",p);
954 fTree->CopyEntries(tree);
0a749fa5 955 fNruns++;
956 }
957 }
958 AliInfo(Form("Number of runs being analyzed %i",fNruns));
959}
960//-----------------------------------------------------------------------------
961void AliTOFcalib::CreateTreeFromGrid(Int_t minrun, Int_t maxrun){
962
963 // creating the chain with the trees for calibration
964 // collecting them from the Grid
965 // from minrun to maxrun
966
967 Float_t p[CHENTRIESSMALL];
968 Int_t nentries;
969 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
970 fTree->SetDirectory(0);
971 fTree->Branch("nentries",&nentries,"nentries/I");
972 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
973 AliInfo("connected to alien");
974 TGrid::Connect("alien://");
975
955f2093 976 TString filename;
0a749fa5 977 for (Int_t irun = minrun;irun<=maxrun;irun++){
955f2093 978 filename = Form("alien:///alice/cern.ch/user/c/czampolli/TOFCalibReference_%i.root",irun);
979 TFile *filegrid = TFile::Open(filename.Data(),"READ");
0a749fa5 980 TTree *tree = (TTree*)filegrid->Get("T");
981 tree->SetBranchAddress("nentries",&nentries);
982 tree->SetBranchAddress("TOFentries",p);
983 fTree->CopyEntries(tree);
984 delete tree;
985 fNruns++;
986 }
987
988 AliInfo(Form("Number of runs being analyzed %i",fNruns));
989}
990//-----------------------------------------------------------------------------
991void AliTOFcalib::CreateTreeFromFile(Int_t minrun, Int_t maxrun){
992
993 // creating the tree with the trees for calibration
994 // collecting them from reference data (from file)
995 // from minrun to maxrun
996
997 Float_t p[CHENTRIESSMALL];
998 Int_t nentries;
999 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
1000 fTree->SetDirectory(0);
1001 fTree->Branch("nentries",&nentries,"nentries/I");
1002 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
955f2093 1003 TString filename;
0a749fa5 1004 for (Int_t irun = minrun;irun<=maxrun;irun++){
955f2093 1005 filename = Form("$ALICE_ROOT/TOF/RefData/TreeForCalib/fileout_%i.root",irun);
1006 TFile *file = new TFile(filename.Data(),"READ");
0a749fa5 1007 TTree *tree = (TTree*)file->Get("T");
1008 tree->SetBranchAddress("nentries",&nentries);
1009 tree->SetBranchAddress("TOFentries",p);
1010 fTree->CopyEntries(tree);
1011 delete tree;
1012 delete file;
1013 file = 0x0;
1014 fNruns++;
1015 }
1016
1017 AliInfo(Form("Number of runs being analyzed %i",fNruns));
1018}
1019//-----------------------------------------------------------------------------
296591ad 1020void AliTOFcalib::CreateChainFromGrid(Int_t minrun, Int_t maxrun){
1021
1022 // creating the chain with the trees for calibration
1023 // collecting them from the Grid
1024 // from minrun to maxrun
1025
1026 fChain = new TChain("T");
1027 AliInfo("connected to alien");
1028 TGrid::Connect("alien://");
1029
955f2093 1030 TString filename;
296591ad 1031 for (Int_t irun = minrun;irun<=maxrun;irun++){
955f2093 1032 filename = Form("alien:///alice/cern.ch/user/c/czampolli/TOFCalibReference_%i.root",irun);
1033 fChain->Add(filename.Data());
296591ad 1034 fNruns++;
1035 }
1036
1037 AliInfo(Form("Number of runs being analyzed %i",fNruns));
1038}
1039//-----------------------------------------------------------------------------
0a749fa5 1040Int_t AliTOFcalib::Calibrate(Int_t ichmin, Int_t ichmax, Option_t *optionSave, Option_t *optionFit){
7037bd93 1041
0a749fa5 1042 // calibrating summing more than one channels
1043 // computing calibration parameters
1044 // Returning codes:
1045 // 0 -> everything was ok
1046 // 1 -> no tree for calibration found
1047 // 2 -> not enough statistics to perform calibration
1048 // 3 -> problems with arrays
1049
1050 TH1::AddDirectory(0);
1051
1052 AliInfo(Form("*** Calibrating Histograms %s, summing more channels, from channel %i, to channel %i, storing Calib Pars in channel %i", GetName(),ichmin,ichmax,ichmin)) ;
1053 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1054 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1055
1056 Float_t p[CHENTRIESSMALL];
1057 Int_t nentries;
296591ad 1058 //fTree->SetBranchAddress("nentries",&nentries);
1059 //fTree->SetBranchAddress("TOFentries",p);
1060 fChain->SetBranchAddress("nentries",&nentries);
1061 fChain->SetBranchAddress("TOFentries",p);
0a749fa5 1062
1063 Float_t ntracksTotalmean =0;
1064 for (Int_t i=ichmin; i<ichmax; i++){
1065 Int_t ientry = -1;
1066 for (Int_t irun=0;irun<fNruns;irun++){
1067 ientry = i+irun*fNChannels;
296591ad 1068 //fTree->GetEntry(ientry);
1069 fChain->GetEntry(ientry);
0a749fa5 1070 Int_t ntracksRun=nentries/3;
1071 ntracksTotalmean+=ntracksRun;
1072 }
1073 }
1074
1075 if (ntracksTotalmean < MEANENTRIES) {
1076 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
1077 return 2;
1078 }
1079
1080 //filling ToT and Time arrays
1081
1082 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
1083 Float_t minToT = 0; // ns
1084 Float_t maxToT = 4.88; // ns
1085
1086 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1087 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1088 Int_t ntracksTotal = 0;
1089 Int_t ntracksRun = 0;
1090 Double_t binsProfile[101]; // sized larger than necessary, the correct
1091 // dim being set in the booking of the profile
1092 Int_t nusefulbins=0;
1093 Float_t meantime=0;
1094 for (Int_t i = ichmin;i<ichmax;i++){
1095 Int_t ientry = -1;
1096 for (Int_t irun=0;irun<fNruns;irun++){
1097 ientry = i+irun*fNChannels;
296591ad 1098 //fTree->GetEntry(ientry);
1099 fChain->GetEntry(ientry);
0a749fa5 1100 ntracksTotal+=nentries/3;
1101 ntracksRun=nentries/3;
1102 AliDebug(2,Form("run %i, channel %i, nentries = %i, ntracks = %i",irun,i,nentries, ntracksRun));
1103 for (Int_t j=0;j<ntracksRun;j++){
1104 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1105 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1106 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1107 Float_t tot = p[idxexToT];
1108 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1109 meantime+=p[idxexTime]-p[idxexExTime];
1110 hToT->Fill(tot);
1111 }
1112 }
1113 }
1114 nusefulbins = FindBins(hToT,&binsProfile[0]);
1115 meantime/=ntracksTotal;
1116 AliDebug(2, Form("meantime = %f",meantime));
1117
1118 for (Int_t j=1;j<=nusefulbins;j++) {
1119 AliDebug(2,Form(" summing channels from %i to %i, nusefulbins = %i, bin %i = %f",ichmin,ichmax,nusefulbins,j,binsProfile[j]));
1120 }
1121
1122 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1123 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1124
1125 for (Int_t irun=0;irun<fNruns;irun++){
1126 Int_t ientry = -1;
1127 for (Int_t i=ichmin; i<ichmax; i++){
1128 ientry = i+irun*fNChannels;
296591ad 1129 //fTree->GetEntry(ientry);
1130 fChain->GetEntry(ientry);
0a749fa5 1131 ntracksRun=nentries/3;
1132 for (Int_t j=0;j<ntracksRun;j++){
1133 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1134 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1135 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1136 Float_t tot = p[idxexToT];
1137 Float_t time = p[idxexTime]-p[idxexExTime];
1138 AliDebug (2, Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1139 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1140 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1141 }
1142 }
1143 }
1144
1145 hSlewingProf->Fit("pol5",optionFit,"",0,4);
1146 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1147 Float_t par[6];
1148 for(Int_t kk=0;kk<6;kk++){
1149 par[kk]=calibfunc->GetParameter(kk);
1150 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1151 }
1152
1153 if(strstr(optionSave,"save")){
1154 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
1155 fileProf->cd();
1156 TString profName=Form("Profile%06i_%06i",ichmin,ichmax);
1157 TString timeTotName=Form("TimeTot%06i_%06i",ichmin,ichmax);
1158 TString totName=Form("Tot%06i_%06i",ichmin,ichmax);
1159 TString deltaName=Form("Delta%06i_%06i",ichmin,ichmax);
1160 hSlewingProf->Write(profName);
1161 htimetot->Write(timeTotName);
1162 hToT->Write(totName);
1163 hdeltaTime->Write(deltaName);
1164 fileProf->Close();
1165 delete fileProf;
1166 fileProf=0x0;
1167 }
1168
1169 delete hToT;
1170 hToT=0x0;
1171 delete hSlewingProf;
1172 hSlewingProf=0x0;
1173 delete htimetot;
1174 htimetot=0x0;
1175 delete hdeltaTime;
1176 hdeltaTime=0x0;
1177
1178 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ichmin);
1179 calChannel->SetSlewPar(par);
0cb9d099 1180 WriteParOfflineOnCDB("TOF/Calib","valid");
0a749fa5 1181 return 0;
1182}
1183//----------------------------------------------------------------------------
1184Int_t AliTOFcalib::Calibrate(Int_t i, Option_t *optionSave, Option_t *optionFit){
1185
1186 // computing calibration parameters for channel i
1187 // Returning codes:
1188 // 0 -> everything was ok
1189 // 1 -> no tree for calibration found
1190 // 2 -> not enough statistics to perform calibration
1191 // 3 -> problems with arrays
1192
1193 TH1::AddDirectory(0);
1194
1195 AliInfo(Form("*** Calibrating Histograms (one channel) %s", GetName())) ;
1196 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1197 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1198
1199 Float_t p[MAXCHENTRIESSMALL];
1200 Int_t nentries;
296591ad 1201 //fTree->SetBranchAddress("nentries",&nentries);
1202 //fTree->SetBranchAddress("TOFentries",p);
1203 fChain->SetBranchAddress("nentries",&nentries);
1204 fChain->SetBranchAddress("TOFentries",p);
0a749fa5 1205
1206 Float_t ntracksTotal =0;
1207 for (Int_t irun=0;irun<fNruns;irun++){
1208 Int_t ientry = -1;
1209 ientry = i+irun*fNChannels;
296591ad 1210 //fTree->GetEntry(ientry);
1211 fChain->GetEntry(ientry);
0a749fa5 1212 ntracksTotal+=nentries/3;
1213 }
1214
1215 if (ntracksTotal < MEANENTRIES) {
1216 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotal));
1217 return 2;
1218 }
1219
1220 //filling ToT and Time arrays
1221
1222 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
1223 Float_t minToT = 0; // ns
1224 Float_t maxToT = 4.88; // ns
1225
1226 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1227 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1228 Int_t ntracksRun = 0;
1229 Double_t binsProfile[101]; // sized larger than necessary, the correct
1230 // dim being set in the booking of the profile
1231 Int_t nusefulbins=0;
1232 Float_t meantime=0;
1233 for (Int_t irun=0;irun<fNruns;irun++){
1234 Int_t ientry = -1;
1235 ientry = i+irun*fNChannels;
296591ad 1236 //fTree->GetEntry(ientry);
1237 fChain->GetEntry(ientry);
0a749fa5 1238 ntracksRun=nentries/3;
1239 AliDebug(2,Form("run %i, channel %i, nentries = %i, ntracksRun = %i",irun, i ,nentries, ntracksRun));
1240 for (Int_t j=0;j<ntracksRun;j++){
1241 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1242 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1243 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1244 Float_t tot = p[idxexToT];
1245 meantime+=p[idxexTime]-p[idxexExTime];
1246 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1247 hToT->Fill(tot);
1248 }
1249 }
1250
1251 nusefulbins = FindBins(hToT,&binsProfile[0]);
1252 meantime/=ntracksTotal;
1253 AliDebug(2,Form("meantime = %f",meantime));
1254
1255 for (Int_t j=1;j<=nusefulbins;j++) {
1256 AliDebug(2,Form(" channel %i, nusefulbins = %i, bin %i = %f",i,nusefulbins,j,binsProfile[j]));
1257 }
1258
1259 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1260 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1261 for (Int_t irun=0;irun<fNruns;irun++){
1262 Int_t ientry = -1;
1263 ientry = i+irun*fNChannels;
296591ad 1264 //fTree->GetEntry(ientry);
1265 fChain->GetEntry(ientry);
0a749fa5 1266 ntracksRun=nentries/3;
1267 for (Int_t j=0;j<ntracksRun;j++){
1268 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1269 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1270 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1271 Float_t tot = p[idxexToT];
1272 Float_t time = p[idxexTime]-p[idxexExTime];
1273 AliDebug (2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1274 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1275 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1276 }
1277 }
1278
1279 hSlewingProf->Fit("pol5",optionFit,"",0,4);
1280 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1281 Float_t par[6];
1282 for(Int_t kk=0;kk<6;kk++){
1283 par[kk]=calibfunc->GetParameter(kk);
1284 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1285 }
1286
1287
1288 if(strstr(optionSave,"save")){
1289 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
1290 fileProf->cd();
1291 TString profName=Form("Profile%06i",i);
1292 TString timeTotName=Form("TimeTot%06i",i);
1293 TString totName=Form("Tot%06i",i);
1294 TString deltaName=Form("Delta%06i",i);
1295 hSlewingProf->Write(profName);
1296 htimetot->Write(timeTotName);
1297 hToT->Write(totName);
1298 hdeltaTime->Write(deltaName);
1299 fileProf->Close();
1300 delete fileProf;
1301 fileProf=0x0;
1302 }
1303
1304 delete hToT;
1305 hToT=0x0;
1306 delete hSlewingProf;
1307 hSlewingProf=0x0;
1308 delete htimetot;
1309 htimetot=0x0;
1310 delete hdeltaTime;
1311 hdeltaTime=0x0;
1312
1313 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(i);
1314 calChannel->SetSlewPar(par);
0cb9d099 1315 WriteParOfflineOnCDB("TOF/Calib","valid");
0a749fa5 1316 return 0;
1317}
1318//----------------------------------------------------------------------------
1319Int_t AliTOFcalib::Calibrate(Int_t nch, Int_t *ch, Option_t *optionSave, Option_t *optionFit){
1320
1321 // calibrating an array of channels
1322 // computing calibration parameters
1323 // Returning codes:
1324 // 0 -> everything was ok
1325 // 1 -> no tree for calibration found
1326 // 2 -> not enough statistics to perform calibration
1327 // 3 -> problems with arrays
1328
1329 TH1::AddDirectory(0);
1330
1331 AliInfo(Form("*** Calibrating Histograms %s, number of channels = %i", GetName(),nch)) ;
1332 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1333 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1334 for (Int_t ich=0; ich<nch; ich++){
1335 Int_t i = ch[ich];
1336 AliInfo(Form("Calibrating channel = %i",i )) ;
1337 }
1338 Float_t p[MAXCHENTRIESSMALL];
1339 Int_t nentries;
296591ad 1340 //fTree->SetBranchAddress("nentries",&nentries);
1341 //fTree->SetBranchAddress("TOFentries",p);
1342 fChain->SetBranchAddress("nentries",&nentries);
1343 fChain->SetBranchAddress("TOFentries",p);
0a749fa5 1344
1345 Float_t ntracksTotalmean =0;
1346 for (Int_t ich=0; ich<nch; ich++){
1347 Int_t ientry = -1;
1348 Int_t i = ch[ich];
1349 for (Int_t irun=0;irun<fNruns;irun++){
1350 ientry = i+irun*fNChannels;
296591ad 1351 //fTree->GetEntry(ientry);
1352 fChain->GetEntry(ientry);
0a749fa5 1353 ntracksTotalmean+=nentries/3;
1354 }
1355 }
1356
1357 ntracksTotalmean/=nch;
1358 if (ntracksTotalmean < MEANENTRIES) {
1359 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
1360 return 2;
1361 }
1362
1363 //filling ToT and Time arrays
1364
1365 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
1366 Float_t minToT = 0; // ns
1367 Float_t maxToT = 4.88; // ns
1368 TFile * fileProf=0x0;
1369 if(strstr(optionSave,"save")){
1370 fileProf = new TFile("TOFCalibSave.root","recreate");
1371 }
1372 for (Int_t ich=0; ich<nch; ich++) {
1373 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1374 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1375 Double_t binsProfile[101]; // sized larger than necessary, the correct
1376 // dim being set in the booking of the profile
1377 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1378 Int_t ntracksTotal = 0;
1379 Int_t ntracksRun = 0;
1380 Int_t nusefulbins=0;
1381 Float_t meantime=0;
1382 Int_t i=-1;
1383 for (Int_t irun=0;irun<fNruns;irun++){
1384 i = ch[ich]+irun*fNChannels;
1385 AliDebug(2,Form("Calibrating channel %i",i));
296591ad 1386 //fTree->GetEntry(i);
1387 fChain->GetEntry(i);
0a749fa5 1388 ntracksTotal+=nentries/3;
1389 }
1390 if (ntracksTotal < MEANENTRIES) {
4682c56e 1391 AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %d), not calibrating channel and continuing.....",i,ntracksTotal));
0a749fa5 1392 continue;
1393 }
1394
1395 for (Int_t irun=0;irun<fNruns;irun++){
3c609b5c 1396 i = ch[ich]+irun*fNChannels;
296591ad 1397 //fTree->GetEntry(i);
1398 fChain->GetEntry(i);
0a749fa5 1399 ntracksRun=nentries/3;
1400 for (Int_t j=0;j<ntracksRun;j++){
1401 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1402 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1403 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1404 Float_t tot = p[idxexToT];
1405 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1406 meantime+=p[idxexTime]-p[idxexExTime];
1407 hToT->Fill(tot);
1408 }
1409 }
1410
1411 nusefulbins = FindBins(hToT,&binsProfile[0]);
1412 meantime/=ntracksTotal;
1413 for (Int_t j=1;j<=nusefulbins;j++) {
1414 AliDebug(2,Form(" channel %i, nusefulbins = %i, bin %i = %f",i,nusefulbins,j,binsProfile[j]));
1415 }
1416
1417 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1418 for (Int_t irun=0;irun<fNruns;irun++){
3c609b5c 1419 i = ch[ich]+irun*fNChannels;
296591ad 1420 //fTree->GetEntry(i);
1421 fChain->GetEntry(i);
0a749fa5 1422 ntracksRun=nentries/3;
1423 for (Int_t j=0;j<ntracksRun;j++){
1424 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1425 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1426 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1427 Float_t tot = p[idxexToT];
1428 Float_t time = p[idxexTime]-p[idxexExTime];
1429 AliDebug(2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1430 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1431 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1432 }
1433 }
1434
1435 hSlewingProf->Fit("pol5",optionFit,"",1,4);
1436 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1437 Float_t par[6];
1438 for(Int_t kk=0;kk<6;kk++){
1439 par[kk]=calibfunc->GetParameter(kk);
1440 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1441 }
1442
1443 if(strstr(optionSave,"save") && fileProf){
1444 TString profName=Form("Profile%06i",i);
1445 TString timeTotName=Form("TimeTot%06i",i);
1446 TString totName=Form("Tot%06i",i);
1447 TString deltaName=Form("Delta%06i",i);
1448 fileProf->cd();
1449 hSlewingProf->Write(profName);
1450 htimetot->Write(timeTotName);
1451 hToT->Write(totName);
1452 hdeltaTime->Write(deltaName);
1453 }
1454
1455 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(i);
1456 calChannel->SetSlewPar(par);
1457 delete hToT;
1458 hToT=0x0;
1459 delete hSlewingProf;
1460 hSlewingProf=0x0;
1461 delete htimetot;
1462 htimetot=0x0;
1463 delete hdeltaTime;
1464 hdeltaTime=0x0;
1465 }
1466
1467 if(strstr(optionSave,"save") && fileProf){
1468 fileProf->Close();
1469 delete fileProf;
1470 fileProf=0x0;
1471 }
0cb9d099 1472 WriteParOfflineOnCDB("TOF/Calib","valid");
0a749fa5 1473
1474 return 0;
1475}
1476//----------------------------------------------------------------------------
1477Int_t AliTOFcalib::CalibrateFromProfile(Int_t ich, Option_t *optionSave, Option_t *optionFit){
1478
1479 // computing calibration parameters using the old profiling algo
1480 // Returning codes:
1481 // 0 -> everything was ok
1482 // 1 -> no tree for calibration found
1483 // 2 -> not enough statistics to perform calibration
1484 // 3 -> problems with arrays
1485
1486 TH1::AddDirectory(0);
1487
1488 AliInfo(Form("*** Calibrating Histograms From Profile %s", GetName())) ;
1489 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1490 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1491 Float_t p[MAXCHENTRIESSMALL];
1492 Int_t nentries;
1493 Int_t ntracksTotal=0;
296591ad 1494 //fTree->SetBranchAddress("nentries",&nentries);
1495 //fTree->SetBranchAddress("TOFentries",p);
1496 fChain->SetBranchAddress("nentries",&nentries);
1497 fChain->SetBranchAddress("TOFentries",p);
0a749fa5 1498
1499 for (Int_t irun=0;irun<fNruns;irun++){
1500 Int_t i = ich+irun*fNChannels;
296591ad 1501 //fTree->GetEntry(i);
1502 fChain->GetEntry(i);
0a749fa5 1503 ntracksTotal+=nentries/3;
1504 }
1505
1506 if (ntracksTotal < MEANENTRIES) {
4682c56e 1507 AliInfo(Form(" Too small mean number of entires per channel (mean number = %d) not calibrating and exiting.....",ntracksTotal));
0a749fa5 1508 return 2;
1509 }
1510
af6e05be 1511 TH1F * hProf = Profile(ich);
0a749fa5 1512 hProf->Fit("pol5",optionFit,"",0,4);
1513 TF1 * calibfunc = (TF1*)hProf->GetFunction("pol5");
1514 Float_t par[6];
1515 for(Int_t kk=0;kk<6;kk++){
1516 par[kk]=calibfunc->GetParameter(kk);
1517 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1518 }
1519
1520 if(strstr(optionSave,"save")){
1521 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
1522 fileProf->cd();
1523 TString profName=Form("Profile%06i",ich);
1524 hProf->Write(profName);
1525 fileProf->Close();
1526 delete fileProf;
1527 fileProf=0x0;
1528 }
1529
1530 delete hProf;
1531 hProf=0x0;
1532 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ich);
1533 calChannel->SetSlewPar(par);
0cb9d099 1534 WriteParOfflineOnCDB("TOF/Calib","valid");
0a749fa5 1535 return 0;
1536}
1537//----------------------------------------------------------------------------
1538Int_t AliTOFcalib::Calibrate(Option_t *optionSave, Option_t *optionFit){
1539
1540 // calibrating the whole TOF
1541 // computing calibration parameters
1542 // Returning codes:
1543 // 0 -> everything was ok
1544 // 1 -> no tree for calibration found
1545 // 2 -> not enough statistics to perform calibration
1546 // 3 -> problems with arrays
1547
1548 TH1::AddDirectory(0);
1549
1550 AliInfo(Form("*** Calibrating Histograms %s, all channels", GetName())) ;
1551 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1552 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1553
1554 TFile * fileProf=0x0;
1555 if(strstr(optionSave,"save")){
1556 fileProf = new TFile("TOFCalibSave.root","recreate");
1557 }
1558
1559 Float_t p[MAXCHENTRIESSMALL];
1560 Int_t nentries;
296591ad 1561 //fTree->SetBranchAddress("nentries",&nentries);
1562 //fTree->SetBranchAddress("TOFentries",p);
1563 fChain->SetBranchAddress("nentries",&nentries);
1564 fChain->SetBranchAddress("TOFentries",p);
0a749fa5 1565
1566 Float_t ntracksTotalmean =0;
1567 for (Int_t ii=0; ii<fNChannels; ii++){
1568 for (Int_t irun=0;irun<fNruns;irun++){
1569 Int_t i = ii+irun*fNChannels;
296591ad 1570 //fTree->GetEntry(i);
1571 fChain->GetEntry(i);
0a749fa5 1572 ntracksTotalmean+=nentries/3;
1573 }
1574 }
1575
1576 ntracksTotalmean/=fNChannels;
1577 if (ntracksTotalmean < MEANENTRIES) {
1578 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
1579 return 2;
1580 }
1581
1582 //filling ToT and Time arrays
1583
1584 Int_t nbinToT = 100; // ToT bin width in Profile = 50.0 ps
1585 Float_t minToT = 0; // ns
1586 Float_t maxToT = 4.88;// ns
1587 for (Int_t ii=0; ii<fNChannels; ii++) {
1588 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1589 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1590 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1591 if (ii%1000 == 0) AliDebug(1,Form("Calibrating channel %i ",ii));
1592 //Int_t i = 3;
1593 Int_t nusefulbins=0;
1594 Double_t binsProfile[101]; // sized larger than necessary, the correct
1595 // dim being set in the booking of the profile
1596 Int_t ntracksRun = 0;
1597 Int_t ntracksTotal = 0;
1598 for (Int_t irun=0;irun<fNruns;irun++){
1599 Int_t i = ii+irun*fNChannels;
296591ad 1600 //fTree->GetEntry(i);
1601 fChain->GetEntry(i);
0a749fa5 1602 ntracksTotal+=nentries/3;
1603 }
1604 if (ntracksTotal < MEANENTRIES) {
4682c56e 1605 AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %d), not calibrating channel and continuing.....",ii,ntracksTotal));
0a749fa5 1606 continue;
1607 }
1608 Float_t meantime=0;
1609 for (Int_t irun=0;irun<fNruns;irun++){
1610 Int_t i = ii+irun*fNChannels;
296591ad 1611 //fTree->GetEntry(i);
1612 fChain->GetEntry(i);
0a749fa5 1613 ntracksRun=nentries/3;
1614 for (Int_t j=0;j<ntracksRun;j++){
1615 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1616 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1617 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1618 Float_t tot = p[idxexToT];
1619 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1620 meantime+=p[idxexTime]-p[idxexExTime];
1621 hToT->Fill(tot);
1622 }
1623 }
1624 nusefulbins = FindBins(hToT,&binsProfile[0]);
1625 meantime/=ntracksTotal;
1626 for (Int_t j=0;j<nusefulbins;j++) {
1627 AliDebug(2,Form(" channel %i, usefulbin = %i, low edge = %f",ii,j,binsProfile[j]));
1628 }
1629 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1630 for (Int_t irun=0;irun<fNruns;irun++){
1631 Int_t i = ii+irun*fNChannels;
296591ad 1632 //fTree->GetEntry(i);
1633 fChain->GetEntry(i);
0a749fa5 1634 ntracksRun=nentries/3;
1635 for (Int_t j=0;j<ntracksRun;j++){
1636 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1637 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1638 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1639 Float_t tot = p[idxexToT];
1640 Float_t time = p[idxexTime]-p[idxexExTime];
1641 AliDebug (2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1642 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1643 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1644 }
1645 }
1646 hSlewingProf->Fit("pol5",optionFit,"",1,4);
1647 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1648 Float_t par[6];
1649 for(Int_t kk=0;kk<6;kk++){
1650 par[kk]=calibfunc->GetParameter(kk);
1651 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1652 }
1653
1654 if(strstr(optionSave,"save") && fileProf){
1655 TString profName=Form("Profile%06i",ii);
1656 TString timeTotName=Form("TimeTot%06i",ii);
1657 TString totName=Form("Tot%06i",ii);
1658 TString deltaName=Form("Delta%06i",ii);
1659 fileProf->cd();
1660 hSlewingProf->Write(profName);
1661 htimetot->Write(timeTotName);
1662 hToT->Write(totName);
1663 hdeltaTime->Write(deltaName);
1664 }
1665 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ii);
1666 calChannel->SetSlewPar(par);
1667
1668 delete hToT;
1669 hToT=0x0;
1670 delete hSlewingProf;
1671 hSlewingProf=0x0;
1672 delete htimetot;
1673 htimetot=0x0;
1674 delete hdeltaTime;
1675 hdeltaTime=0x0;
1676 }
1677
1678 if(strstr(optionSave,"save")){
1679 fileProf->Close();
1680 delete fileProf;
1681 fileProf=0x0;
1682 }
0cb9d099 1683 WriteParOfflineOnCDB("TOF/Calib","valid");
0a749fa5 1684 return 0;
1685}
1686
1687//-----------------------------------------------------------------------
1688TH1F* AliTOFcalib::Profile(Int_t ich)
340693af 1689{
0a749fa5 1690 // profiling algo
1691
1692 Float_t p[MAXCHENTRIESSMALL];
1693 Int_t nentries;
296591ad 1694 //fTree->SetBranchAddress("nentries",&nentries);
1695 //fTree->SetBranchAddress("TOFentries",p);
1696 fChain->SetBranchAddress("nentries",&nentries);
1697 fChain->SetBranchAddress("TOFentries",p);
0a749fa5 1698
1699 //Prepare histograms for Slewing Correction
1700 const Int_t knbinToT = 100;
1701 Int_t nbinTime = 200;
1702 Float_t minTime = -5.5; //ns
1703 Float_t maxTime = 5.5; //ns
1704 Float_t minToT = 0; //ns
1705 Float_t maxToT = 5.; //ns
1706 Float_t deltaToT = (maxToT-minToT)/knbinToT;
1707 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];
1708 Int_t n[knbinToT+1], nentrx[knbinToT+1];
1709 Double_t sigmaToT[knbinToT+1];
1710 for (Int_t i = 0; i < knbinToT+1 ; i++){
1711 mTime[i]=0;
1712 mToT[i]=0;
1713 n[i]=0;
1714 meanTime[i]=0;
1715 meanTime2[i]=0;
1716 vToT[i]=0;
1717 vToT2[i]=0;
1718 meanToT[i]=0;
1719 meanToT2[i]=0;
1720 vTime[i]=0;
1721 vTime2[i]=0;
1722 xlow[i]=0;
1723 sigmaTime[i]=0;
1724 sigmaToT[i]=0;
1725 n[i]=0;
1726 nentrx[i]=0;
1727 }
1728 TH2F* hSlewing = new TH2F("hSlewing", "hSlewing", knbinToT, minToT, maxToT, nbinTime, minTime, maxTime);
1729 Int_t ntracksRun = 0;
1730 TH1F *histo = new TH1F("histo", "1D Time vs ToT", knbinToT, minToT, maxToT);
1731 for (Int_t irun=0;irun<fNruns;irun++){
1732 Int_t i = ich+irun*fNChannels;
296591ad 1733 //fTree->GetEntry(i);
1734 fChain->GetEntry(i);
0a749fa5 1735 ntracksRun=nentries/3;
1736 for (Int_t j=0;j<ntracksRun;j++){
1737 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1738 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1739 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1740 Float_t tot = p[idxexToT];
1741 Float_t time = p[idxexTime]-p[idxexExTime];
1742 Int_t nx = (Int_t)((tot-minToT)/deltaToT)+1;
1743 if ((tot != 0) && ( time!= 0)){
1744 vTime[nx]+=time;
1745 vTime2[nx]+=time*time;
1746 vToT[nx]+=tot;
1747 vToT2[nx]+=tot*tot;
1748 nentrx[nx]++;
1749 hSlewing->Fill(tot,time);
1750 }
1751 }
1752 }
1753 Int_t nbinsToT=hSlewing->GetNbinsX();
1754 if (nbinsToT != knbinToT) {
1755 AliError("Profile :: incompatible numbers of bins");
1756 return 0x0;
1757 }
1758
1759 Int_t usefulBins=0;
1760 for (Int_t i=1;i<=nbinsToT;i++){
1761 if (nentrx[i]!=0){
1762 n[usefulBins]+=nentrx[i];
1763 if (n[usefulBins]==0 && i == nbinsToT) {
1764 break;
1765 }
1766 meanTime[usefulBins]+=vTime[i];
1767 meanTime2[usefulBins]+=vTime2[i];
1768 meanToT[usefulBins]+=vToT[i];
1769 meanToT2[usefulBins]+=vToT2[i];
1770 if (n[usefulBins]<10 && i!=nbinsToT) continue;
1771 mTime[usefulBins]=meanTime[usefulBins]/n[usefulBins];
1772 mToT[usefulBins]=meanToT[usefulBins]/n[usefulBins];
1773 sigmaTime[usefulBins]=TMath::Sqrt(1./n[usefulBins]/n[usefulBins]
1774 *(meanTime2[usefulBins]-meanTime[usefulBins]
1775 *meanTime[usefulBins]/n[usefulBins]));
1776 if ((1./n[usefulBins]/n[usefulBins]
1777 *(meanToT2[usefulBins]-meanToT[usefulBins]
1778 *meanToT[usefulBins]/n[usefulBins]))< 0) {
1779 AliError(" too small radical" );
1780 sigmaToT[usefulBins]=0;
1781 }
1782 else{
1783 sigmaToT[usefulBins]=TMath::Sqrt(1./n[usefulBins]/n[usefulBins]
1784 *(meanToT2[usefulBins]-meanToT[usefulBins]
1785 *meanToT[usefulBins]/n[usefulBins]));
1786 }
1787 usefulBins++;
1788 }
1789 }
1790 for (Int_t i=0;i<usefulBins;i++){
1791 Int_t binN = (Int_t)((mToT[i]-minToT)/deltaToT)+1;
1792 histo->Fill(mToT[i],mTime[i]);
1793 histo->SetBinError(binN,sigmaTime[i]);
1794 }
1795 delete hSlewing;
1796 hSlewing=0x0;
1797
1798 return histo;
6dc9348d 1799}
0a749fa5 1800//----------------------------------------------------------------------------
1801Int_t AliTOFcalib::FindBins(TH1F* h, Double_t *binsProfile) const{
6dc9348d 1802
0a749fa5 1803 // to determine the bins for ToT histo
1804
1805 Int_t cont = 0;
1806 Int_t startBin = 1;
1807 Int_t nbin = h->GetNbinsX();
1808 Int_t nentries = (Int_t)h->GetEntries();
1809 Float_t max = h->GetBinLowEdge(nbin);
1810 Int_t nusefulbins=0;
1811 Int_t maxcont=0;
1812 // setting maxvalue of entries per bin
1813 if (nentries <= 60) maxcont = 2;
1814 else if (nentries <= 100) maxcont = 5;
1815 else if (nentries <= 500) maxcont = 10;
1816 else maxcont = 20;
1817 for (Int_t j=1;j<=nbin;j++) {
1818 cont += (Int_t)h->GetBinContent(j);
1819 if (j<nbin){
1820 if (cont>=maxcont){
1821 nusefulbins++;
1822 binsProfile[nusefulbins-1]=h->GetBinLowEdge(startBin);
1823 cont=0;
1824 startBin=j+1;
1825 continue;
1826 }
1827 }
1828 else{
1829 if (cont>=maxcont){
1830 nusefulbins++;
1831 binsProfile[nusefulbins-1]=h->GetBinLowEdge(startBin);
1832 binsProfile[nusefulbins]=max;
1833 }
1834 else {
1835 binsProfile[nusefulbins]=h->GetBinLowEdge(startBin);
1836 }
1837 }
1838 }
1839 return nusefulbins;
1840}
2bf4d9d6 1841
1842
1843//----------------------------------------------------------------------------
1844
1845void
1846AliTOFcalib::CreateDeltaBCOffset()
1847{
1848 /*
1849 * create deltaBC offset
1850 */
1851
1852 if (fDeltaBCOffset) {
1853 AliWarning("DeltaBCOffset object already defined, cannot create a new one");
1854 return;
1855 }
1856 fDeltaBCOffset = new AliTOFDeltaBCOffset();
1857}
1858
1859//----------------------------------------------------------------------------
1860
1861void
1862AliTOFcalib::CreateCTPLatency()
1863{
1864 /*
1865 * create CTP latency
1866 */
1867
1868 if (fCTPLatency) {
1869 AliWarning("CTPLatency object already defined, cannot create a new one");
1870 return;
1871 }
1872 fCTPLatency = new AliTOFCTPLatency();
1873}
1874
1875//----------------------------------------------------------------------------
1876
1877void
1878AliTOFcalib::CreateT0Fill()
1879{
1880 /*
1881 * create event-time
1882 */
1883
1884 if (fT0Fill) {
1885 AliWarning("T0Fill object already defined, cannot create a new one");
1886 return;
1887 }
1888 fT0Fill = new AliTOFT0Fill();
1889}
1890
1891//----------------------------------------------------------------------------
1892
f04b3a69 1893void
1894AliTOFcalib::CreateRunParams()
1895{
1896 /*
1897 * create run params
1898 */
1899
1900 if (fRunParams) {
1901 AliWarning("RunParams object already defined, cannot create a new one");
1902 return;
1903 }
1904 fRunParams = new AliTOFRunParams();
1905}
1906
1907//----------------------------------------------------------------------------
1908
2bf4d9d6 1909void
1910AliTOFcalib::WriteDeltaBCOffsetOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
1911{
1912 /*
1913 * deltaBC offset on CDB
1914 */
1915
1916 if (!fDeltaBCOffset) return;
1917 AliCDBId id(Form("%s/DeltaBCOffset", sel), minrun, maxrun);
1918 AliCDBMetaData *md = new AliCDBMetaData();
1919 md->SetResponsible("Roberto Preghenella");
1920 AliCDBManager *man = AliCDBManager::Instance();
1921 man->Put(fDeltaBCOffset, id, md);
1922 AliDebug(2,Form("DeltaBCOffset written on CDB with run range [%i, %i] ",minrun ,maxrun));
1923 delete md;
1924}
1925
1926//----------------------------------------------------------------------------
1927
1928void
1929AliTOFcalib::WriteCTPLatencyOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
1930{
1931 /*
1932 * write CTP latency on CDB
1933 */
1934
1935 if (!fCTPLatency) return;
1936 AliCDBId id(Form("%s/CTPLatency", sel), minrun, maxrun);
1937 AliCDBMetaData *md = new AliCDBMetaData();
1938 md->SetResponsible("Roberto Preghenella");
1939 AliCDBManager *man = AliCDBManager::Instance();
1940 man->Put(fCTPLatency, id, md);
1941 AliDebug(2,Form("CTPLatency written on CDB with run range [%i, %i] ",minrun ,maxrun));
1942 delete md;
1943}
1944
1945//----------------------------------------------------------------------------
1946
1947void
1948AliTOFcalib::WriteT0FillOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
1949{
1950 /*
1951 * write event-time on CDB
1952 */
1953
1954 if (!fT0Fill) return;
1955 AliCDBId id(Form("%s/T0Fill", sel), minrun, maxrun);
1956 AliCDBMetaData *md = new AliCDBMetaData();
1957 md->SetResponsible("Roberto Preghenella");
1958 AliCDBManager *man = AliCDBManager::Instance();
1959 man->Put(fT0Fill, id, md);
1960 AliDebug(2,Form("T0Fill written on CDB with run range [%i, %i] ",minrun ,maxrun));
1961 delete md;
1962}
1963
1964//----------------------------------------------------------------------------
1965
f04b3a69 1966void
1967AliTOFcalib::WriteRunParamsOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
1968{
1969 /*
1970 * write run params on CDB
1971 */
1972
1973 if (!fRunParams) return;
1974 AliCDBId id(Form("%s/RunParams", sel), minrun, maxrun);
1975 AliCDBMetaData *md = new AliCDBMetaData();
1976 md->SetResponsible("Roberto Preghenella");
1977 AliCDBManager *man = AliCDBManager::Instance();
1978 man->Put(fRunParams, id, md);
1979 AliDebug(2,Form("RunParams written on CDB with run range [%i, %i] ",minrun ,maxrun));
1980 delete md;
1981}
1982
1983//----------------------------------------------------------------------------
1984
2bf4d9d6 1985Bool_t
1986AliTOFcalib::ReadDeltaBCOffsetFromCDB(const Char_t *sel , Int_t nrun)
1987{
1988 /*
1989 * read deltaBC offset from CDB
1990 */
1991
1992 AliCDBManager *man = AliCDBManager::Instance();
1993 AliCDBEntry *entry = man->Get(Form("%s/DeltaBCOffset", sel),nrun);
1994 if (!entry) {
1995 AliFatal("No DeltaBCOffset entry found in CDB");
1996 exit(0);
1997 }
1998 fDeltaBCOffset =(AliTOFDeltaBCOffset *)entry->GetObject();
1999 if(!fDeltaBCOffset){
2000 AliFatal("No DeltaBCOffset object found in CDB entry");
2001 exit(0);
2002 }
2003 return kTRUE;
2004}
2005
2006//----------------------------------------------------------------------------
2007
2008Bool_t
2009AliTOFcalib::ReadCTPLatencyFromCDB(const Char_t *sel , Int_t nrun)
2010{
2011 /*
2012 * read CTP latency from CDB
2013 */
2014
2015 AliCDBManager *man = AliCDBManager::Instance();
2016 AliCDBEntry *entry = man->Get(Form("%s/CTPLatency", sel),nrun);
2017 if (!entry) {
2018 AliFatal("No CTPLatency entry found in CDB");
2019 exit(0);
2020 }
2021 fCTPLatency =(AliTOFCTPLatency *)entry->GetObject();
2022 if(!fCTPLatency){
2023 AliFatal("No CTPLatency object found in CDB entry");
2024 exit(0);
2025 }
2026 return kTRUE;
2027}
2028
2029//----------------------------------------------------------------------------
2030
2031Bool_t
2032AliTOFcalib::ReadT0FillFromCDB(const Char_t *sel , Int_t nrun)
2033{
2034 /*
2035 * read event-time from CDB
2036 */
2037
2038 AliCDBManager *man = AliCDBManager::Instance();
2039 AliCDBEntry *entry = man->Get(Form("%s/T0Fill", sel),nrun);
2040 if (!entry) {
2041 AliFatal("No T0Fill entry found in CDB");
2042 exit(0);
2043 }
2044 fT0Fill =(AliTOFT0Fill *)entry->GetObject();
2045 if(!fT0Fill){
2046 AliFatal("No T0Fill object found in CDB entry");
2047 exit(0);
2048 }
2049 return kTRUE;
2050}
2051
f04b3a69 2052//----------------------------------------------------------------------------
2053
2054Bool_t
2055AliTOFcalib::ReadRunParamsFromCDB(const Char_t *sel , Int_t nrun)
2056{
2057 /*
2058 * read run params from CDB
2059 */
2060
2061 AliCDBManager *man = AliCDBManager::Instance();
2062 AliCDBEntry *entry = man->Get(Form("%s/RunParams", sel),nrun);
2063 if (!entry) {
2064 AliFatal("No RunParams entry found in CDB");
2065 exit(0);
2066 }
2067 fRunParams =(AliTOFRunParams *)entry->GetObject();
2068 if(!fRunParams){
2069 AliFatal("No RunParams object found in CDB entry");
2070 exit(0);
2071 }
2072 return kTRUE;
2073}
2074
5b4ed716 2075//----------------------------------------------------------------------------
2076
2077Bool_t
2078AliTOFcalib::Init(Int_t run)
2079{
2080 /*
2081 * init
2082 */
2083
2084 if (fInitFlag) {
2085 AliWarning("the class was already initialized, re-initialize it");
2086 fInitFlag = kFALSE;
2087 }
2088
2089 /* read channel status array */
2090 if (!ReadParOnlineStatusFromCDB("TOF/Calib", run)) {
2091 AliError("cannot get \"Status\" object from OCDB");
2092 return kFALSE;
2093 }
2094 /* get par offline array */
2095 if (!ReadParOfflineFromCDB("TOF/Calib", run)) {
2096 AliError("cannot get \"ParOffline\" object from OCDB");
2097 return kFALSE;
2098 }
2099 /* get deltaBC offset obj */
2100 if (!ReadDeltaBCOffsetFromCDB("TOF/Calib", run)) {
2101 AliError("cannot get \"DeltaBCOffset\" object from OCDB");
2102 return kFALSE;
2103 }
2104 /* get CTP latency obj */
2105 if (!ReadCTPLatencyFromCDB("TOF/Calib", run)) {
2106 AliError("cannot get \"CTPLatency\" object from OCDB");
2107 return kFALSE;
2108 }
2109 /* get run params obj */
2110 if (!ReadRunParamsFromCDB("TOF/Calib", run)) {
2111 AliError("cannot get \"RunParams\" object from OCDB");
2112 return kFALSE;
2113 }
2114 /* get response params */
2115 if (fCorrectTExp) {
2116 TFile *responseFile = TFile::Open("$ALICE_ROOT/TOF/data/AliTOFresponsePar.root");
2117 if (!responseFile || !responseFile->IsOpen()) {
2118 AliError("cannot open \"ResponseParams\" local file");
2119 return kFALSE;
2120 }
2121 fResponseParams = (AliTOFResponseParams *)responseFile->Get("ResponseParams");
2122 if (!fResponseParams) {
2123 AliError("cannot get \"ResponseParams\" object from local file");
2124 return kFALSE;
2125 }
2126 responseFile->Close();
2127 }
2128
2129 /* all done */
2130 fInitFlag = kTRUE;
2131 return kTRUE;
2132
2133}
2134
2135//----------------------------------------------------------------------------
2136
2137Double_t
2138AliTOFcalib::GetTimeCorrection(Int_t index, Double_t tot, Int_t deltaBC, Int_t l0l1, UInt_t timestamp)
2139{
2140 /*
2141 * get time correction
2142 */
2143
2144 if (!fInitFlag) {
2145 AliError("class not yet initialized. Initialize it before.");
2146 return 0.;
2147 }
2148
2149 /* get calibration params */
2150 AliTOFChannelOffline *parOffline = (AliTOFChannelOffline *)fTOFCalOffline->At(index);
2151 Int_t deltaBCOffset = fDeltaBCOffset->GetDeltaBCOffset();
2152 Float_t ctpLatency = fCTPLatency->GetCTPLatency();
2153 Float_t tdcLatencyWindow = fStatus->GetLatencyWindow(index) * 1.e3;
2154 Float_t timezero = fRunParams->EvalT0(timestamp);
2155 /* check whether to remove mean T0.
2156 * useful when one wants to compute mean T0 */
2157 if (!fRemoveMeanT0) timezero = 0.;
2158
2159 /* compute correction */
2160 Double_t corr = 0.;
2161 /* deltaBC correction */
2162 deltaBC = deltaBCOffset; /* inhibit deltaBC correction for the time being */
2163 corr += (deltaBC - deltaBCOffset) * AliTOFGeometry::BunchCrossingBinWidth();
2164 /* L0-L1 latency correction */
2165 corr -= l0l1 * AliTOFGeometry::BunchCrossingBinWidth();
2166 /* CTP latency correction */
2167 corr -= ctpLatency;
2168 /* TDC latency window correction */
2169 corr += tdcLatencyWindow;
2170 /* time-zero correction */
2171 corr += timezero;
2172 /* time calibration correction */
2173 if (tot < AliTOFGeometry::SlewTOTMin())
2174 tot = AliTOFGeometry::SlewTOTMin();
2175 if (tot > AliTOFGeometry::SlewTOTMax())
2176 tot = AliTOFGeometry::SlewTOTMax();
2177 for (Int_t islew = 0; islew < 6; islew++)
2178 corr += parOffline->GetSlewPar(islew) * TMath::Power(tot, islew) * 1.e3;
2179
2180 /* return correction */
2181 return corr;
2182}
2183
2184//----------------------------------------------------------------------------
2185
2186void
2187AliTOFcalib::CalibrateESD(AliESDEvent *event)
2188{
2189 /*
2190 * calibrate ESD
2191 */
2192
2193 if (!fInitFlag) {
2194 AliError("class not yet initialized. Initialize it before.");
2195 return;
2196 }
2197
2198 /* loop over tracks */
2199 AliESDtrack *track = NULL;
2200 Int_t index, l0l1, deltaBC;
2201 Double_t time, tot, corr, texp[AliPID::kSPECIES];
2202 UInt_t timestamp = event->GetTimeStamp();
2203 for (Int_t itrk = 0; itrk < event->GetNumberOfTracks(); itrk++) {
2204
2205 /* get track */
2206 track = event->GetTrack(itrk);
2207 if (!track || !(track->GetStatus() & AliESDtrack::kTOFout)) continue;
8bb89c94 2208
2209 /* calibrate TOF signal */
2210 if (fCalibrateTOFsignal) {
2211 /* get info */
2212 index = track->GetTOFCalChannel();
2213 time = track->GetTOFsignalRaw();
2214 tot = track->GetTOFsignalToT();
2215 l0l1 = track->GetTOFL0L1();
2216 deltaBC = track->GetTOFDeltaBC();
2217 /* get correction */
2218 corr = GetTimeCorrection(index, tot, deltaBC, l0l1, timestamp);
2219 /* apply correction */
2220 time -= corr;
2221 /* set new TOF signal */
2222 track->SetTOFsignal(time);
2223 }
5b4ed716 2224
2225 /* correct expected time */
2226 if (fCorrectTExp) {
2227 /* get integrated times */
2228 track->GetIntegratedTimes(texp);
2229 /* loop over particle types and correct expected time */
2230 for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++)
2231 texp[ipart] += fResponseParams->EvalTExpCorr(ipart, track->P());
2232 /* set integrated times */
2233 track->SetIntegratedTimes(texp);
2234 }
2235
2236 }
2237
2238}
2239
2240//----------------------------------------------------------------------------
2241
2242Bool_t
2243AliTOFcalib::IsChannelEnabled(Int_t index)
2244{
2245 /*
2246 * is channel enabled
2247 */
2248
2249 if (!fInitFlag) {
2250 AliError("class not yet initialized. Initialize it before.");
2251 return kTRUE;
2252 }
2253
2254 /* check bad status */
2255 if (fStatus->GetPulserStatus(index) == AliTOFChannelOnlineStatusArray::kTOFPulserBad) return kFALSE;
2256 if (fStatus->GetNoiseStatus(index) == AliTOFChannelOnlineStatusArray::kTOFNoiseBad) return kFALSE;
2257 if (fStatus->GetHWStatus(index) == AliTOFChannelOnlineStatusArray::kTOFHWBad) return kFALSE;
2258
2259 /* good status */
2260 return kTRUE;
2261
2262}