1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 Revision 1.15 2007/10/04 13:23:28 zampolli
19 Updates to handle functionalities in TOF online/offline calibration according to the latest schema
21 Revision 1.14 2007/06/06 16:26:30 arcelli
22 remove fall-back call to local CDB storage
24 Revision 1.13 2007/04/20 13:59:40 arcelli
25 make protections agains failed retrieval of the CDB object in a proper way
27 Revision 1.12 2007/03/23 11:31:16 arcelli
28 CDB Entry for TOF Reconstruction Parameters
30 Revision 1.11 2007/02/28 18:08:26 arcelli
31 Add protection against failed retrieval of the CDB cal object
33 Revision 1.10 2006/08/22 13:30:49 arcelli
34 removal of effective c++ warnings (C.Zampolli)
36 Revision 1.9 2006/04/20 22:30:50 hristov
37 Coding conventions (Annalisa)
39 Revision 1.8 2006/04/16 22:29:05 hristov
40 Coding conventions (Annalisa)
42 Revision 1.7 2006/04/16 20:12:46 hristov
43 Removing memory leak in case of cached CDB entries
45 Revision 1.6 2006/04/11 15:28:32 hristov
46 Checks on cache status before deleting calibration objects (A.Colla)
48 Revision 1.5 2006/04/05 08:35:38 hristov
49 Coding conventions (S.Arcelli, C.Zampolli)
51 Revision 1.4 2006/03/31 11:26:46 arcelli
52 changing CDB Ids according to standard convention
54 Revision 1.3 2006/03/28 14:57:02 arcelli
55 updates to handle new V5 geometry & some re-arrangements
57 Revision 1.2 2006/02/13 17:22:26 arcelli
60 Revision 1.1 2006/02/13 16:10:48 arcelli
61 Add classes for TOF Calibration (C.Zampolli)
63 author: Chiara Zampolli, zampolli@bo.infn.it
66 ///////////////////////////////////////////////////////////////////////////////
68 // class for TOF calibration //
70 ///////////////////////////////////////////////////////////////////////////////
83 #include "AliCDBEntry.h"
84 #include "AliCDBRunRange.h"
86 #include "AliCDBManager.h"
87 #include "AliCDBStorage.h"
88 #include "AliCDBMetaData.h"
89 #include "AliESDtrack.h"
93 #include "AliTOFcalib.h"
94 #include "AliTOFChannelOnline.h"
95 #include "AliTOFChannelOffline.h"
96 #include "AliTOFGeometry.h"
97 #include "AliTOFRecoParam.h"
100 extern TStyle *gStyle;
102 ClassImp(AliTOFcalib)
104 //_______________________________________________________________________
105 AliTOFcalib::AliTOFcalib():
106 TTask("AliTOFcalib",""),
110 fTOFSimCalOnline(0x0),
111 fTOFSimCalOffline(0x0),
117 fLastRun(AliCDBRunRange::Infinity())
119 //TOF Calibration Class ctor
120 fNChannels = AliTOFGeometry::NSectors()*(2*(AliTOFGeometry::NStripC()+AliTOFGeometry::NStripB())+AliTOFGeometry::NStripA())*AliTOFGeometry::NpadZ()*AliTOFGeometry::NpadX();
122 //____________________________________________________________________________
124 AliTOFcalib::AliTOFcalib(const AliTOFcalib & calib):
125 TTask("AliTOFcalib",""),
126 fNChannels(calib.fNChannels),
129 fTOFSimCalOnline(0x0),
130 fTOFSimCalOffline(0x0),
131 fTOFSimToT(calib.fTOFSimToT),
132 fkValidity(calib.fkValidity),
134 fNruns(calib.fNruns),
135 fFirstRun(calib.fFirstRun),
136 fLastRun(calib.fLastRun)
138 //TOF Calibration Class copy ctor
139 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
140 AliTOFChannelOnline * calChOnline = (AliTOFChannelOnline*)calib.fTOFCalOnline->At(iarray);
141 AliTOFChannelOffline * calChOffline = (AliTOFChannelOffline*)calib.fTOFCalOffline->At(iarray);
142 fTOFCalOnline->AddAt(calChOnline,iarray);
143 fTOFCalOffline->AddAt(calChOffline,iarray);
145 AliTOFChannelOnline * simCalChOnline = (AliTOFChannelOnline*)calib.fTOFSimCalOnline->At(iarray);
146 AliTOFChannelOffline * simCalChOffline = (AliTOFChannelOffline*)calib.fTOFSimCalOffline->At(iarray);
147 fTOFSimCalOnline->AddAt(simCalChOnline,iarray);
148 fTOFSimCalOffline->AddAt(simCalChOffline,iarray);
152 //____________________________________________________________________________
154 AliTOFcalib& AliTOFcalib::operator=(const AliTOFcalib &calib)
156 //TOF Calibration Class assignment operator
157 this->fNChannels = calib.fNChannels;
158 this->fTOFSimToT = calib.fTOFSimToT;
159 this->fkValidity = calib.fkValidity;
160 this->fTree = calib.fTree;
161 this->fNruns = calib.fNruns;
162 this->fFirstRun = calib.fFirstRun;
163 this->fLastRun = calib.fLastRun;
164 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
165 AliTOFChannelOnline * calChOnline = (AliTOFChannelOnline*)calib.fTOFCalOnline->At(iarray);
166 AliTOFChannelOffline * calChOffline = (AliTOFChannelOffline*)calib.fTOFCalOffline->At(iarray);
167 this->fTOFCalOnline->AddAt(calChOnline,iarray);
168 this->fTOFCalOffline->AddAt(calChOffline,iarray);
169 AliTOFChannelOnline * simCalChOnline = (AliTOFChannelOnline*)calib.fTOFSimCalOnline->At(iarray);
170 AliTOFChannelOffline * simCalChOffline = (AliTOFChannelOffline*)calib.fTOFSimCalOffline->At(iarray);
171 this->fTOFSimCalOnline->AddAt(simCalChOnline,iarray);
172 this->fTOFSimCalOffline->AddAt(simCalChOffline,iarray);
177 //____________________________________________________________________________
179 AliTOFcalib::~AliTOFcalib()
181 //TOF Calibration Class dtor
182 if(!(AliCDBManager::Instance()->GetCacheFlag())){ // CDB objects must NOT be deleted if cache is active!
184 fTOFCalOnline->Clear();
185 delete fTOFCalOnline;
188 fTOFCalOffline->Clear();
189 delete fTOFCalOffline;
191 if (fTOFSimCalOnline){
192 fTOFSimCalOnline->Clear();
193 delete fTOFSimCalOnline;
195 if (fTOFSimCalOffline){
196 fTOFSimCalOffline->Clear();
197 delete fTOFSimCalOffline;
200 if (fTree!=0x0) delete fTree;
202 //_____________________________________________________________________________
203 void AliTOFcalib::CreateCalArrays(){
205 // creating arrays for online/offline calibration objs
207 fTOFCalOnline = new TObjArray(fNChannels);
208 fTOFCalOffline = new TObjArray(fNChannels);
209 fTOFCalOnline->SetOwner();
210 fTOFCalOffline->SetOwner();
211 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
212 AliTOFChannelOnline * calChOnline = new AliTOFChannelOnline();
213 AliTOFChannelOffline * calChOffline = new AliTOFChannelOffline();
214 fTOFCalOnline->AddAt(calChOnline,iarray);
215 fTOFCalOffline->AddAt(calChOffline,iarray);
218 //_____________________________________________________________________________
219 void AliTOFcalib::CreateSimCalArrays(){
221 // creating arrays for simulation online/offline calibration objs
223 fTOFSimCalOnline = new TObjArray(fNChannels);
224 fTOFSimCalOffline = new TObjArray(fNChannels);
225 fTOFSimCalOnline->SetOwner();
226 fTOFSimCalOffline->SetOwner();
227 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
228 AliTOFChannelOnline * simCalChOnline = new AliTOFChannelOnline();
229 AliTOFChannelOffline * simCalChOffline = new AliTOFChannelOffline();
230 fTOFSimCalOnline->AddAt(simCalChOnline,iarray);
231 fTOFSimCalOffline->AddAt(simCalChOffline,iarray);
234 //_____________________________________________________________________________
235 void AliTOFcalib::WriteParOnlineOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun)
237 //Write calibration parameters to the CDB
240 AliCDBManager *man = AliCDBManager::Instance();
241 Char_t *sel1 = "OnlineDelay" ; // to be consistent with TOFPreprocessor
243 sprintf(out,"%s/%s",sel,sel1);
244 AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
245 AliCDBId id(out,fFirstRun,fLastRun);
246 AliCDBMetaData *md = new AliCDBMetaData();
247 md->SetResponsible("Chiara Zampolli");
248 if (!fTOFCalOnline) {
251 man->Put(fTOFCalOnline,id,md);
254 //_____________________________________________________________________________
256 void AliTOFcalib::WriteParOnlineOnCDB(Char_t *sel)
258 //Write calibration parameters to the CDB with infinite validity
259 AliCDBManager *man = AliCDBManager::Instance();
260 Char_t *sel1 = "OnlineDelay" ; // to be consistent with TOFPreprocessor
262 sprintf(out,"%s/%s",sel,sel1);
263 AliCDBRunRange runrange(fFirstRun,fLastRun);
264 AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
265 AliCDBId id(out,runrange);
266 AliCDBMetaData *md = new AliCDBMetaData();
267 md->SetResponsible("Chiara Zampolli");
268 if (!fTOFCalOnline) {
271 man->Put(fTOFCalOnline,id,md);
274 //_____________________________________________________________________________
276 void AliTOFcalib::WriteParOfflineOnCDB(Char_t *sel, const Char_t *validity, Int_t minrun, Int_t maxrun)
278 //Write calibration parameters to the CDB
281 AliCDBManager *man = AliCDBManager::Instance();
282 Char_t *sel1 = "ParOffline" ;
284 sprintf(out,"%s/%s",sel,sel1);
285 AliDebug(2,Form("Writing TOF offline calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
286 AliCDBId id(out,fFirstRun,fLastRun);
287 AliCDBMetaData *md = new AliCDBMetaData();
288 md->SetResponsible("Chiara Zampolli");
289 md->SetComment(validity);
290 man->Put(fTOFCalOffline,id,md);
293 //_____________________________________________________________________________
295 void AliTOFcalib::WriteParOfflineOnCDB(Char_t *sel, const Char_t *validity)
297 //Write calibration parameters to the CDB with infinite validity
298 AliCDBManager *man = AliCDBManager::Instance();
299 Char_t *sel1 = "ParOffline" ;
301 sprintf(out,"%s/%s",sel,sel1);
302 AliCDBRunRange runrange(fFirstRun,fLastRun);
303 AliDebug(2,Form("Writing TOF offline calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
304 AliCDBId id(out,runrange);
305 AliCDBMetaData *md = new AliCDBMetaData();
306 md->SetResponsible("Chiara Zampolli");
307 md->SetComment(validity);
308 man->Put(fTOFCalOffline,id,md);
311 //_____________________________________________________________________________
313 Bool_t AliTOFcalib::ReadParOnlineFromCDB(Char_t *sel, Int_t nrun)
315 //Read calibration parameters from the CDB
316 AliCDBManager *man = AliCDBManager::Instance();
317 Char_t *sel1 = "OnlineDelay" ;
319 sprintf(out,"%s/%s",sel,sel1);
320 if (!man->Get(out,nrun)) {
323 AliCDBEntry *entry = man->Get(out,nrun);
324 if(!entry->GetObject()){
328 fTOFCalOnline =(TObjArray*)entry->GetObject();
333 //_____________________________________________________________________________
335 Bool_t AliTOFcalib::ReadParOfflineFromCDB(Char_t *sel, Int_t nrun)
337 //Read calibration parameters from the CDB
338 AliCDBManager *man = AliCDBManager::Instance();
339 Char_t *sel1 = "ParOffline" ;
341 sprintf(out,"%s/%s",sel,sel1);
342 if (!man->Get(out,nrun)) {
345 AliCDBEntry *entry = man->Get(out,nrun);
346 if(!entry->GetObject()){
349 AliCDBMetaData * md = entry->GetMetaData();
350 fkValidity = md->GetComment();
351 fTOFCalOffline =(TObjArray*)entry->GetObject();
356 //_____________________________________________________________________________
357 void AliTOFcalib::WriteSimParOnlineOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun, TObjArray *calOnline){
358 //Write Sim miscalibration parameters to the CDB
360 fTOFSimCalOnline=calOnline;
361 AliCDBManager *man = AliCDBManager::Instance();
362 AliCDBMetaData *md = new AliCDBMetaData();
363 md->SetResponsible("Chiara Zampolli");
364 Char_t *sel1 = "SimParOnline" ;
366 sprintf(out,"%s/%s",sel,sel1);
367 AliCDBId id1(out,minrun,maxrun);
368 man->Put(fTOFSimCalOnline,id1,md);
371 //_____________________________________________________________________________
372 void AliTOFcalib::WriteSimParOfflineOnCDB(Char_t *sel, const Char_t *validity, Int_t minrun, Int_t maxrun, TObjArray *calOffline, TH1F *histo){
373 //Write Sim miscalibration parameters to the CDB
376 fTOFSimCalOffline=calOffline;
377 AliCDBManager *man = AliCDBManager::Instance();
378 AliCDBMetaData *md = new AliCDBMetaData();
379 md->SetResponsible("Chiara Zampolli");
380 md->SetComment(validity);
381 Char_t *sel1 = "SimParOffline" ;
383 sprintf(out,"%s/%s",sel,sel1);
384 AliCDBId id1(out,minrun,maxrun);
385 man->Put(fTOFSimCalOffline,id1,md);
386 Char_t *sel2 = "SimHisto" ;
387 sprintf(out,"%s/%s",sel,sel2);
388 AliCDBMetaData *mdhisto = new AliCDBMetaData();
389 mdhisto->SetResponsible("Chiara Zampolli");
390 AliCDBId id2(out,minrun,maxrun);
391 man->Put(fTOFSimToT,id2,mdhisto);
395 //_____________________________________________________________________________
396 void AliTOFcalib::ReadSimParOnlineFromCDB(Char_t *sel, Int_t nrun)
398 //Read miscalibration parameters from the CDB
399 AliCDBManager *man = AliCDBManager::Instance();
403 Char_t *sel1 = "SimParOnline" ;
405 sprintf(out,"%s/%s",sel,sel1);
406 if (!man->Get(out,nrun)) {
407 AliFatal("Exiting, no CDB object (SimPar) found!!!");
410 AliCDBEntry *entry1 = man->Get(out,nrun);
411 if(!entry1->GetObject()){
412 AliFatal("Exiting, no CDB object (SimPar) found!!!");
415 TObjArray *cal =(TObjArray*)entry1->GetObject();
416 fTOFSimCalOnline=cal;
419 //_____________________________________________________________________________
420 void AliTOFcalib::ReadSimParOfflineFromCDB(Char_t *sel, Int_t nrun)
422 //Read miscalibration parameters from the CDB
423 AliCDBManager *man = AliCDBManager::Instance();
427 Char_t *sel1 = "SimParOffline" ;
429 sprintf(out,"%s/%s",sel,sel1);
430 if (!man->Get(out,nrun)) {
431 AliFatal("Exiting, no CDB object (SimPar) found!!!");
434 AliCDBEntry *entry1 = man->Get(out,nrun);
435 if(!entry1->GetObject()){
436 AliFatal("Exiting, no CDB object (SimPar) found!!!");
439 TObjArray *cal =(TObjArray*)entry1->GetObject();
440 AliCDBMetaData *md = (AliCDBMetaData*)entry1->GetMetaData();
441 fkValidity = md->GetComment();
442 fTOFSimCalOffline=cal;
446 Char_t *sel2 = "SimHisto" ;
447 sprintf(out,"%s/%s",sel,sel2);
448 if (!man->Get(out,nrun)) {
449 AliFatal("Exiting, no CDB object (SimHisto) found!!!");
452 AliCDBEntry *entry2 = man->Get(out,nrun);
453 if(!entry2->GetObject()){
454 AliFatal("Exiting, no CDB object (SimHisto) found!!!");
457 TH1F *histo =(TH1F*)entry2->GetObject();
460 //_____________________________________________________________________________
461 void AliTOFcalib::WriteRecParOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun, AliTOFRecoParam *param){
462 //Write reconstruction parameters to the CDB
464 AliCDBManager *man = AliCDBManager::Instance();
465 AliCDBMetaData *md = new AliCDBMetaData();
466 md->SetResponsible("Silvia Arcelli");
467 Char_t *sel1 = "RecPar" ;
469 sprintf(out,"%s/%s",sel,sel1);
470 AliCDBId id(out,minrun,maxrun);
471 man->Put(param,id,md);
474 //_____________________________________________________________________________
475 AliTOFRecoParam * AliTOFcalib::ReadRecParFromCDB(Char_t *sel, Int_t nrun)
477 //Read reconstruction parameters from the CDB
478 AliCDBManager *man = AliCDBManager::Instance();
479 Char_t *sel1 = "RecPar" ;
481 sprintf(out,"%s/%s",sel,sel1);
482 if (!man->Get(out,nrun)) {
483 AliFatal("Exiting, no CDB object (RecPar) found!!!");
486 AliCDBEntry *entry = man->Get(out,nrun);
487 if(!entry->GetObject()){
488 AliFatal("Exiting, no CDB object (RecPar) found!!!");
492 AliTOFRecoParam *param=(AliTOFRecoParam*)entry->GetObject();
495 //-----------------------------------------------------------------------------
496 // Calibration methods
497 //-----------------------------------------------------------------------------
498 void AliTOFcalib::CreateTreeFromCDB(Int_t minrun, Int_t maxrun){
500 // creating the chain with the trees for calibration
501 // collecting them from reference data
502 // from minrun to maxrun
504 Float_t p[CHENTRIESSMALL];
506 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
507 fTree->Branch("nentries",&nentries,"nentries/I");
508 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
509 AliCDBManager *man = AliCDBManager::Instance();
510 AliCDBStorage *aStorage = man->GetStorage("local://$ALICE_ROOT");
511 for (Int_t irun = minrun;irun<=maxrun;irun++){
512 AliCDBEntry *entry = aStorage->Get("TOF/RefData/TreeForCalib",irun);
514 AliInfo(Form("No entry found for run %i",irun));
517 TTree *tree = new TTree();
518 tree = (TTree*)entry->GetObject();
519 tree->SetBranchAddress("nentries",&nentries);
520 tree->SetBranchAddress("TOFentries",p);
521 fTree->CopyEntries(tree);
526 AliInfo(Form("Number of runs being analyzed %i",fNruns));
528 //-----------------------------------------------------------------------------
529 void AliTOFcalib::CreateTreeFromGrid(Int_t minrun, Int_t maxrun){
531 // creating the chain with the trees for calibration
532 // collecting them from the Grid
533 // from minrun to maxrun
535 Float_t p[CHENTRIESSMALL];
537 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
538 fTree->SetDirectory(0);
539 fTree->Branch("nentries",&nentries,"nentries/I");
540 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
541 AliInfo("connected to alien");
542 TGrid::Connect("alien://");
544 Char_t filename[100];
545 for (Int_t irun = minrun;irun<=maxrun;irun++){
546 sprintf(filename,"alien:///alice/cern.ch/user/c/czampolli/TOFCalibReference_%i.root",irun);
547 TFile *filegrid = TFile::Open(filename,"READ");
548 TTree *tree = (TTree*)filegrid->Get("T");
549 tree->SetBranchAddress("nentries",&nentries);
550 tree->SetBranchAddress("TOFentries",p);
551 fTree->CopyEntries(tree);
556 AliInfo(Form("Number of runs being analyzed %i",fNruns));
558 //-----------------------------------------------------------------------------
559 void AliTOFcalib::CreateTreeFromFile(Int_t minrun, Int_t maxrun){
561 // creating the tree with the trees for calibration
562 // collecting them from reference data (from file)
563 // from minrun to maxrun
565 Float_t p[CHENTRIESSMALL];
567 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
568 fTree->SetDirectory(0);
569 fTree->Branch("nentries",&nentries,"nentries/I");
570 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
571 Char_t filename[100];
572 for (Int_t irun = minrun;irun<=maxrun;irun++){
573 sprintf(filename,"$ALICE_ROOT/TOF/RefData/TreeForCalib/fileout_%i.root",irun);
574 TFile *file = new TFile(filename,"READ");
575 TTree *tree = (TTree*)file->Get("T");
576 tree->SetBranchAddress("nentries",&nentries);
577 tree->SetBranchAddress("TOFentries",p);
578 fTree->CopyEntries(tree);
585 AliInfo(Form("Number of runs being analyzed %i",fNruns));
587 //-----------------------------------------------------------------------------
588 Int_t AliTOFcalib::Calibrate(Int_t ichmin, Int_t ichmax, Option_t *optionSave, Option_t *optionFit){
590 // calibrating summing more than one channels
591 // computing calibration parameters
593 // 0 -> everything was ok
594 // 1 -> no tree for calibration found
595 // 2 -> not enough statistics to perform calibration
596 // 3 -> problems with arrays
598 TH1::AddDirectory(0);
600 AliInfo(Form("*** Calibrating Histograms %s, summing more channels, from channel %i, to channel %i, storing Calib Pars in channel %i", GetName(),ichmin,ichmax,ichmin)) ;
601 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
602 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
604 Float_t p[CHENTRIESSMALL];
606 fTree->SetBranchAddress("nentries",&nentries);
607 fTree->SetBranchAddress("TOFentries",p);
609 Float_t ntracksTotalmean =0;
610 for (Int_t i=ichmin; i<ichmax; i++){
612 for (Int_t irun=0;irun<fNruns;irun++){
613 ientry = i+irun*fNChannels;
614 fTree->GetEntry(ientry);
615 Int_t ntracksRun=nentries/3;
616 ntracksTotalmean+=ntracksRun;
620 if (ntracksTotalmean < MEANENTRIES) {
621 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
625 //filling ToT and Time arrays
627 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
628 Float_t minToT = 0; // ns
629 Float_t maxToT = 4.88; // ns
631 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
632 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
633 Int_t ntracksTotal = 0;
634 Int_t ntracksRun = 0;
635 Double_t binsProfile[101]; // sized larger than necessary, the correct
636 // dim being set in the booking of the profile
639 for (Int_t i = ichmin;i<ichmax;i++){
641 for (Int_t irun=0;irun<fNruns;irun++){
642 ientry = i+irun*fNChannels;
643 fTree->GetEntry(ientry);
644 ntracksTotal+=nentries/3;
645 ntracksRun=nentries/3;
646 AliDebug(2,Form("run %i, channel %i, nentries = %i, ntracks = %i",irun,i,nentries, ntracksRun));
647 for (Int_t j=0;j<ntracksRun;j++){
648 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
649 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
650 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
651 Float_t tot = p[idxexToT];
652 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
653 meantime+=p[idxexTime]-p[idxexExTime];
658 nusefulbins = FindBins(hToT,&binsProfile[0]);
659 meantime/=ntracksTotal;
660 AliDebug(2, Form("meantime = %f",meantime));
662 for (Int_t j=1;j<=nusefulbins;j++) {
663 AliDebug(2,Form(" summing channels from %i to %i, nusefulbins = %i, bin %i = %f",ichmin,ichmax,nusefulbins,j,binsProfile[j]));
666 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
667 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
669 for (Int_t irun=0;irun<fNruns;irun++){
671 for (Int_t i=ichmin; i<ichmax; i++){
672 ientry = i+irun*fNChannels;
673 fTree->GetEntry(ientry);
674 ntracksRun=nentries/3;
675 for (Int_t j=0;j<ntracksRun;j++){
676 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
677 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
678 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
679 Float_t tot = p[idxexToT];
680 Float_t time = p[idxexTime]-p[idxexExTime];
681 AliDebug (2, Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
682 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
683 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
688 hSlewingProf->Fit("pol5",optionFit,"",0,4);
689 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
691 for(Int_t kk=0;kk<6;kk++){
692 par[kk]=calibfunc->GetParameter(kk);
693 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
696 if(strstr(optionSave,"save")){
697 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
699 TString profName=Form("Profile%06i_%06i",ichmin,ichmax);
700 TString timeTotName=Form("TimeTot%06i_%06i",ichmin,ichmax);
701 TString totName=Form("Tot%06i_%06i",ichmin,ichmax);
702 TString deltaName=Form("Delta%06i_%06i",ichmin,ichmax);
703 hSlewingProf->Write(profName);
704 htimetot->Write(timeTotName);
705 hToT->Write(totName);
706 hdeltaTime->Write(deltaName);
721 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ichmin);
722 calChannel->SetSlewPar(par);
723 WriteParOfflineOnCDB("TOF/Calib","valid");
726 //----------------------------------------------------------------------------
727 Int_t AliTOFcalib::Calibrate(Int_t i, Option_t *optionSave, Option_t *optionFit){
729 // computing calibration parameters for channel i
731 // 0 -> everything was ok
732 // 1 -> no tree for calibration found
733 // 2 -> not enough statistics to perform calibration
734 // 3 -> problems with arrays
736 TH1::AddDirectory(0);
738 AliInfo(Form("*** Calibrating Histograms (one channel) %s", GetName())) ;
739 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
740 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
742 Float_t p[MAXCHENTRIESSMALL];
744 fTree->SetBranchAddress("nentries",&nentries);
745 fTree->SetBranchAddress("TOFentries",p);
747 Float_t ntracksTotal =0;
748 for (Int_t irun=0;irun<fNruns;irun++){
750 ientry = i+irun*fNChannels;
751 fTree->GetEntry(ientry);
752 ntracksTotal+=nentries/3;
755 if (ntracksTotal < MEANENTRIES) {
756 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotal));
760 //filling ToT and Time arrays
762 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
763 Float_t minToT = 0; // ns
764 Float_t maxToT = 4.88; // ns
766 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
767 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
768 Int_t ntracksRun = 0;
769 Double_t binsProfile[101]; // sized larger than necessary, the correct
770 // dim being set in the booking of the profile
773 for (Int_t irun=0;irun<fNruns;irun++){
775 ientry = i+irun*fNChannels;
776 fTree->GetEntry(ientry);
777 ntracksRun=nentries/3;
778 AliDebug(2,Form("run %i, channel %i, nentries = %i, ntracksRun = %i",irun, i ,nentries, ntracksRun));
779 for (Int_t j=0;j<ntracksRun;j++){
780 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
781 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
782 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
783 Float_t tot = p[idxexToT];
784 meantime+=p[idxexTime]-p[idxexExTime];
785 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
790 nusefulbins = FindBins(hToT,&binsProfile[0]);
791 meantime/=ntracksTotal;
792 AliDebug(2,Form("meantime = %f",meantime));
794 for (Int_t j=1;j<=nusefulbins;j++) {
795 AliDebug(2,Form(" channel %i, nusefulbins = %i, bin %i = %f",i,nusefulbins,j,binsProfile[j]));
798 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
799 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
800 for (Int_t irun=0;irun<fNruns;irun++){
802 ientry = i+irun*fNChannels;
803 fTree->GetEntry(ientry);
804 ntracksRun=nentries/3;
805 for (Int_t j=0;j<ntracksRun;j++){
806 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
807 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
808 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
809 Float_t tot = p[idxexToT];
810 Float_t time = p[idxexTime]-p[idxexExTime];
811 AliDebug (2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
812 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
813 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
817 hSlewingProf->Fit("pol5",optionFit,"",0,4);
818 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
820 for(Int_t kk=0;kk<6;kk++){
821 par[kk]=calibfunc->GetParameter(kk);
822 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
826 if(strstr(optionSave,"save")){
827 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
829 TString profName=Form("Profile%06i",i);
830 TString timeTotName=Form("TimeTot%06i",i);
831 TString totName=Form("Tot%06i",i);
832 TString deltaName=Form("Delta%06i",i);
833 hSlewingProf->Write(profName);
834 htimetot->Write(timeTotName);
835 hToT->Write(totName);
836 hdeltaTime->Write(deltaName);
851 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(i);
852 calChannel->SetSlewPar(par);
853 WriteParOfflineOnCDB("TOF/Calib","valid");
856 //----------------------------------------------------------------------------
857 Int_t AliTOFcalib::Calibrate(Int_t nch, Int_t *ch, Option_t *optionSave, Option_t *optionFit){
859 // calibrating an array of channels
860 // computing calibration parameters
862 // 0 -> everything was ok
863 // 1 -> no tree for calibration found
864 // 2 -> not enough statistics to perform calibration
865 // 3 -> problems with arrays
867 TH1::AddDirectory(0);
869 AliInfo(Form("*** Calibrating Histograms %s, number of channels = %i", GetName(),nch)) ;
870 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
871 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
872 for (Int_t ich=0; ich<nch; ich++){
874 AliInfo(Form("Calibrating channel = %i",i )) ;
876 Float_t p[MAXCHENTRIESSMALL];
878 fTree->SetBranchAddress("nentries",&nentries);
879 fTree->SetBranchAddress("TOFentries",p);
881 Float_t ntracksTotalmean =0;
882 for (Int_t ich=0; ich<nch; ich++){
885 for (Int_t irun=0;irun<fNruns;irun++){
886 ientry = i+irun*fNChannels;
887 fTree->GetEntry(ientry);
888 ntracksTotalmean+=nentries/3;
892 ntracksTotalmean/=nch;
893 if (ntracksTotalmean < MEANENTRIES) {
894 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
898 //filling ToT and Time arrays
900 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
901 Float_t minToT = 0; // ns
902 Float_t maxToT = 4.88; // ns
903 TFile * fileProf=0x0;
904 if(strstr(optionSave,"save")){
905 fileProf = new TFile("TOFCalibSave.root","recreate");
907 for (Int_t ich=0; ich<nch; ich++) {
908 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
909 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
910 Double_t binsProfile[101]; // sized larger than necessary, the correct
911 // dim being set in the booking of the profile
912 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
913 Int_t ntracksTotal = 0;
914 Int_t ntracksRun = 0;
918 for (Int_t irun=0;irun<fNruns;irun++){
919 i = ch[ich]+irun*fNChannels;
920 AliDebug(2,Form("Calibrating channel %i",i));
922 ntracksTotal+=nentries/3;
924 if (ntracksTotal < MEANENTRIES) {
925 AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %f), not calibrating channel and continuing.....",i,ntracksTotal));
929 for (Int_t irun=0;irun<fNruns;irun++){
930 Int_t i = ch[ich]+irun*fNChannels;
932 ntracksRun=nentries/3;
933 for (Int_t j=0;j<ntracksRun;j++){
934 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
935 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
936 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
937 Float_t tot = p[idxexToT];
938 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
939 meantime+=p[idxexTime]-p[idxexExTime];
944 nusefulbins = FindBins(hToT,&binsProfile[0]);
945 meantime/=ntracksTotal;
946 for (Int_t j=1;j<=nusefulbins;j++) {
947 AliDebug(2,Form(" channel %i, nusefulbins = %i, bin %i = %f",i,nusefulbins,j,binsProfile[j]));
950 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
951 for (Int_t irun=0;irun<fNruns;irun++){
952 Int_t i = ch[ich]+irun*fNChannels;
954 ntracksRun=nentries/3;
955 for (Int_t j=0;j<ntracksRun;j++){
956 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
957 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
958 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
959 Float_t tot = p[idxexToT];
960 Float_t time = p[idxexTime]-p[idxexExTime];
961 AliDebug(2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
962 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
963 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
967 hSlewingProf->Fit("pol5",optionFit,"",1,4);
968 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
970 for(Int_t kk=0;kk<6;kk++){
971 par[kk]=calibfunc->GetParameter(kk);
972 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
975 if(strstr(optionSave,"save") && fileProf){
976 TString profName=Form("Profile%06i",i);
977 TString timeTotName=Form("TimeTot%06i",i);
978 TString totName=Form("Tot%06i",i);
979 TString deltaName=Form("Delta%06i",i);
981 hSlewingProf->Write(profName);
982 htimetot->Write(timeTotName);
983 hToT->Write(totName);
984 hdeltaTime->Write(deltaName);
987 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(i);
988 calChannel->SetSlewPar(par);
999 if(strstr(optionSave,"save") && fileProf){
1004 WriteParOfflineOnCDB("TOF/Calib","valid");
1008 //----------------------------------------------------------------------------
1009 Int_t AliTOFcalib::CalibrateFromProfile(Int_t ich, Option_t *optionSave, Option_t *optionFit){
1011 // computing calibration parameters using the old profiling algo
1013 // 0 -> everything was ok
1014 // 1 -> no tree for calibration found
1015 // 2 -> not enough statistics to perform calibration
1016 // 3 -> problems with arrays
1018 TH1::AddDirectory(0);
1020 AliInfo(Form("*** Calibrating Histograms From Profile %s", GetName())) ;
1021 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1022 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1023 Float_t p[MAXCHENTRIESSMALL];
1025 Int_t ntracksTotal=0;
1026 fTree->SetBranchAddress("nentries",&nentries);
1027 fTree->SetBranchAddress("TOFentries",p);
1029 for (Int_t irun=0;irun<fNruns;irun++){
1030 Int_t i = ich+irun*fNChannels;
1032 ntracksTotal+=nentries/3;
1035 if (ntracksTotal < MEANENTRIES) {
1036 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotal));
1040 TH1F * hProf = new TH1F();
1041 hProf = Profile(ich);
1042 hProf->Fit("pol5",optionFit,"",0,4);
1043 TF1 * calibfunc = (TF1*)hProf->GetFunction("pol5");
1045 for(Int_t kk=0;kk<6;kk++){
1046 par[kk]=calibfunc->GetParameter(kk);
1047 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1050 if(strstr(optionSave,"save")){
1051 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
1053 TString profName=Form("Profile%06i",ich);
1054 hProf->Write(profName);
1062 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ich);
1063 calChannel->SetSlewPar(par);
1064 WriteParOfflineOnCDB("TOF/Calib","valid");
1067 //----------------------------------------------------------------------------
1068 Int_t AliTOFcalib::Calibrate(Option_t *optionSave, Option_t *optionFit){
1070 // calibrating the whole TOF
1071 // computing calibration parameters
1073 // 0 -> everything was ok
1074 // 1 -> no tree for calibration found
1075 // 2 -> not enough statistics to perform calibration
1076 // 3 -> problems with arrays
1078 TH1::AddDirectory(0);
1080 AliInfo(Form("*** Calibrating Histograms %s, all channels", GetName())) ;
1081 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1082 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1084 TFile * fileProf=0x0;
1085 if(strstr(optionSave,"save")){
1086 fileProf = new TFile("TOFCalibSave.root","recreate");
1089 Float_t p[MAXCHENTRIESSMALL];
1091 fTree->SetBranchAddress("nentries",&nentries);
1092 fTree->SetBranchAddress("TOFentries",p);
1094 Float_t ntracksTotalmean =0;
1095 for (Int_t ii=0; ii<fNChannels; ii++){
1096 for (Int_t irun=0;irun<fNruns;irun++){
1097 Int_t i = ii+irun*fNChannels;
1099 ntracksTotalmean+=nentries/3;
1103 ntracksTotalmean/=fNChannels;
1104 if (ntracksTotalmean < MEANENTRIES) {
1105 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
1109 //filling ToT and Time arrays
1111 Int_t nbinToT = 100; // ToT bin width in Profile = 50.0 ps
1112 Float_t minToT = 0; // ns
1113 Float_t maxToT = 4.88;// ns
1114 for (Int_t ii=0; ii<fNChannels; ii++) {
1115 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1116 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1117 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1118 if (ii%1000 == 0) AliDebug(1,Form("Calibrating channel %i ",ii));
1120 Int_t nusefulbins=0;
1121 Double_t binsProfile[101]; // sized larger than necessary, the correct
1122 // dim being set in the booking of the profile
1123 Int_t ntracksRun = 0;
1124 Int_t ntracksTotal = 0;
1125 for (Int_t irun=0;irun<fNruns;irun++){
1126 Int_t i = ii+irun*fNChannels;
1128 ntracksTotal+=nentries/3;
1130 if (ntracksTotal < MEANENTRIES) {
1131 AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %f), not calibrating channel and continuing.....",ii,ntracksTotal));
1135 for (Int_t irun=0;irun<fNruns;irun++){
1136 Int_t i = ii+irun*fNChannels;
1138 ntracksRun=nentries/3;
1139 for (Int_t j=0;j<ntracksRun;j++){
1140 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1141 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1142 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1143 Float_t tot = p[idxexToT];
1144 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1145 meantime+=p[idxexTime]-p[idxexExTime];
1149 nusefulbins = FindBins(hToT,&binsProfile[0]);
1150 meantime/=ntracksTotal;
1151 for (Int_t j=0;j<nusefulbins;j++) {
1152 AliDebug(2,Form(" channel %i, usefulbin = %i, low edge = %f",ii,j,binsProfile[j]));
1154 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1155 for (Int_t irun=0;irun<fNruns;irun++){
1156 Int_t i = ii+irun*fNChannels;
1158 ntracksRun=nentries/3;
1159 for (Int_t j=0;j<ntracksRun;j++){
1160 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1161 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1162 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1163 Float_t tot = p[idxexToT];
1164 Float_t time = p[idxexTime]-p[idxexExTime];
1165 AliDebug (2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1166 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1167 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1170 hSlewingProf->Fit("pol5",optionFit,"",1,4);
1171 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1173 for(Int_t kk=0;kk<6;kk++){
1174 par[kk]=calibfunc->GetParameter(kk);
1175 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1178 if(strstr(optionSave,"save") && fileProf){
1179 TString profName=Form("Profile%06i",ii);
1180 TString timeTotName=Form("TimeTot%06i",ii);
1181 TString totName=Form("Tot%06i",ii);
1182 TString deltaName=Form("Delta%06i",ii);
1184 hSlewingProf->Write(profName);
1185 htimetot->Write(timeTotName);
1186 hToT->Write(totName);
1187 hdeltaTime->Write(deltaName);
1189 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ii);
1190 calChannel->SetSlewPar(par);
1194 delete hSlewingProf;
1202 if(strstr(optionSave,"save")){
1207 WriteParOfflineOnCDB("TOF/Calib","valid");
1211 //-----------------------------------------------------------------------
1212 TH1F* AliTOFcalib::Profile(Int_t ich)
1216 Float_t p[MAXCHENTRIESSMALL];
1218 fTree->SetBranchAddress("nentries",&nentries);
1219 fTree->SetBranchAddress("TOFentries",p);
1221 //Prepare histograms for Slewing Correction
1222 const Int_t knbinToT = 100;
1223 Int_t nbinTime = 200;
1224 Float_t minTime = -5.5; //ns
1225 Float_t maxTime = 5.5; //ns
1226 Float_t minToT = 0; //ns
1227 Float_t maxToT = 5.; //ns
1228 Float_t deltaToT = (maxToT-minToT)/knbinToT;
1229 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];
1230 Int_t n[knbinToT+1], nentrx[knbinToT+1];
1231 Double_t sigmaToT[knbinToT+1];
1232 for (Int_t i = 0; i < knbinToT+1 ; i++){
1250 TH2F* hSlewing = new TH2F("hSlewing", "hSlewing", knbinToT, minToT, maxToT, nbinTime, minTime, maxTime);
1251 Int_t ntracksRun = 0;
1252 TH1F *histo = new TH1F("histo", "1D Time vs ToT", knbinToT, minToT, maxToT);
1253 for (Int_t irun=0;irun<fNruns;irun++){
1254 Int_t i = ich+irun*fNChannels;
1256 ntracksRun=nentries/3;
1257 for (Int_t j=0;j<ntracksRun;j++){
1258 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1259 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1260 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1261 Float_t tot = p[idxexToT];
1262 Float_t time = p[idxexTime]-p[idxexExTime];
1263 Int_t nx = (Int_t)((tot-minToT)/deltaToT)+1;
1264 if ((tot != 0) && ( time!= 0)){
1266 vTime2[nx]+=time*time;
1270 hSlewing->Fill(tot,time);
1274 Int_t nbinsToT=hSlewing->GetNbinsX();
1275 if (nbinsToT != knbinToT) {
1276 AliError("Profile :: incompatible numbers of bins");
1281 for (Int_t i=1;i<=nbinsToT;i++){
1283 n[usefulBins]+=nentrx[i];
1284 if (n[usefulBins]==0 && i == nbinsToT) {
1287 meanTime[usefulBins]+=vTime[i];
1288 meanTime2[usefulBins]+=vTime2[i];
1289 meanToT[usefulBins]+=vToT[i];
1290 meanToT2[usefulBins]+=vToT2[i];
1291 if (n[usefulBins]<10 && i!=nbinsToT) continue;
1292 mTime[usefulBins]=meanTime[usefulBins]/n[usefulBins];
1293 mToT[usefulBins]=meanToT[usefulBins]/n[usefulBins];
1294 sigmaTime[usefulBins]=TMath::Sqrt(1./n[usefulBins]/n[usefulBins]
1295 *(meanTime2[usefulBins]-meanTime[usefulBins]
1296 *meanTime[usefulBins]/n[usefulBins]));
1297 if ((1./n[usefulBins]/n[usefulBins]
1298 *(meanToT2[usefulBins]-meanToT[usefulBins]
1299 *meanToT[usefulBins]/n[usefulBins]))< 0) {
1300 AliError(" too small radical" );
1301 sigmaToT[usefulBins]=0;
1304 sigmaToT[usefulBins]=TMath::Sqrt(1./n[usefulBins]/n[usefulBins]
1305 *(meanToT2[usefulBins]-meanToT[usefulBins]
1306 *meanToT[usefulBins]/n[usefulBins]));
1311 for (Int_t i=0;i<usefulBins;i++){
1312 Int_t binN = (Int_t)((mToT[i]-minToT)/deltaToT)+1;
1313 histo->Fill(mToT[i],mTime[i]);
1314 histo->SetBinError(binN,sigmaTime[i]);
1321 //----------------------------------------------------------------------------
1322 Int_t AliTOFcalib::FindBins(TH1F* h, Double_t *binsProfile) const{
1324 // to determine the bins for ToT histo
1328 Int_t nbin = h->GetNbinsX();
1329 Int_t nentries = (Int_t)h->GetEntries();
1330 Float_t max = h->GetBinLowEdge(nbin);
1331 Int_t nusefulbins=0;
1333 // setting maxvalue of entries per bin
1334 if (nentries <= 60) maxcont = 2;
1335 else if (nentries <= 100) maxcont = 5;
1336 else if (nentries <= 500) maxcont = 10;
1338 for (Int_t j=1;j<=nbin;j++) {
1339 cont += (Int_t)h->GetBinContent(j);
1343 binsProfile[nusefulbins-1]=h->GetBinLowEdge(startBin);
1352 binsProfile[nusefulbins-1]=h->GetBinLowEdge(startBin);
1353 binsProfile[nusefulbins]=max;
1356 binsProfile[nusefulbins]=h->GetBinLowEdge(startBin);