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.16 2007/10/08 10:13:26 zampolli
19 First Run and Last Run members added, infinite validity of calib obj implemented.
21 Revision 1.15 2007/10/04 13:23:28 zampolli
22 Updates to handle functionalities in TOF online/offline calibration according to the latest schema
24 Revision 1.14 2007/06/06 16:26:30 arcelli
25 remove fall-back call to local CDB storage
27 Revision 1.13 2007/04/20 13:59:40 arcelli
28 make protections agains failed retrieval of the CDB object in a proper way
30 Revision 1.12 2007/03/23 11:31:16 arcelli
31 CDB Entry for TOF Reconstruction Parameters
33 Revision 1.11 2007/02/28 18:08:26 arcelli
34 Add protection against failed retrieval of the CDB cal object
36 Revision 1.10 2006/08/22 13:30:49 arcelli
37 removal of effective c++ warnings (C.Zampolli)
39 Revision 1.9 2006/04/20 22:30:50 hristov
40 Coding conventions (Annalisa)
42 Revision 1.8 2006/04/16 22:29:05 hristov
43 Coding conventions (Annalisa)
45 Revision 1.7 2006/04/16 20:12:46 hristov
46 Removing memory leak in case of cached CDB entries
48 Revision 1.6 2006/04/11 15:28:32 hristov
49 Checks on cache status before deleting calibration objects (A.Colla)
51 Revision 1.5 2006/04/05 08:35:38 hristov
52 Coding conventions (S.Arcelli, C.Zampolli)
54 Revision 1.4 2006/03/31 11:26:46 arcelli
55 changing CDB Ids according to standard convention
57 Revision 1.3 2006/03/28 14:57:02 arcelli
58 updates to handle new V5 geometry & some re-arrangements
60 Revision 1.2 2006/02/13 17:22:26 arcelli
63 Revision 1.1 2006/02/13 16:10:48 arcelli
64 Add classes for TOF Calibration (C.Zampolli)
66 author: Chiara Zampolli, zampolli@bo.infn.it
69 ///////////////////////////////////////////////////////////////////////////////
71 // class for TOF calibration //
73 ///////////////////////////////////////////////////////////////////////////////
86 #include "AliCDBEntry.h"
87 #include "AliCDBRunRange.h"
89 #include "AliCDBManager.h"
90 #include "AliCDBStorage.h"
91 #include "AliCDBMetaData.h"
92 #include "AliESDtrack.h"
96 #include "AliTOFcalib.h"
97 #include "AliTOFChannelOnline.h"
98 #include "AliTOFChannelOffline.h"
99 #include "AliTOFGeometry.h"
100 #include "AliTOFRecoParam.h"
103 extern TStyle *gStyle;
105 ClassImp(AliTOFcalib)
107 //_______________________________________________________________________
108 AliTOFcalib::AliTOFcalib():
109 TTask("AliTOFcalib",""),
113 fTOFSimCalOnline(0x0),
114 fTOFSimCalOffline(0x0),
120 fLastRun(AliCDBRunRange::Infinity())
122 //TOF Calibration Class ctor
123 fNChannels = AliTOFGeometry::NSectors()*(2*(AliTOFGeometry::NStripC()+AliTOFGeometry::NStripB())+AliTOFGeometry::NStripA())*AliTOFGeometry::NpadZ()*AliTOFGeometry::NpadX();
125 //____________________________________________________________________________
127 AliTOFcalib::AliTOFcalib(const AliTOFcalib & calib):
128 TTask("AliTOFcalib",""),
129 fNChannels(calib.fNChannels),
132 fTOFSimCalOnline(0x0),
133 fTOFSimCalOffline(0x0),
134 fTOFSimToT(calib.fTOFSimToT),
135 fkValidity(calib.fkValidity),
137 fNruns(calib.fNruns),
138 fFirstRun(calib.fFirstRun),
139 fLastRun(calib.fLastRun)
141 //TOF Calibration Class copy ctor
142 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
143 AliTOFChannelOnline * calChOnline = (AliTOFChannelOnline*)calib.fTOFCalOnline->At(iarray);
144 AliTOFChannelOffline * calChOffline = (AliTOFChannelOffline*)calib.fTOFCalOffline->At(iarray);
145 fTOFCalOnline->AddAt(calChOnline,iarray);
146 fTOFCalOffline->AddAt(calChOffline,iarray);
148 AliTOFChannelOnline * simCalChOnline = (AliTOFChannelOnline*)calib.fTOFSimCalOnline->At(iarray);
149 AliTOFChannelOffline * simCalChOffline = (AliTOFChannelOffline*)calib.fTOFSimCalOffline->At(iarray);
150 fTOFSimCalOnline->AddAt(simCalChOnline,iarray);
151 fTOFSimCalOffline->AddAt(simCalChOffline,iarray);
155 //____________________________________________________________________________
157 AliTOFcalib& AliTOFcalib::operator=(const AliTOFcalib &calib)
159 //TOF Calibration Class assignment operator
160 this->fNChannels = calib.fNChannels;
161 this->fTOFSimToT = calib.fTOFSimToT;
162 this->fkValidity = calib.fkValidity;
163 this->fTree = calib.fTree;
164 this->fNruns = calib.fNruns;
165 this->fFirstRun = calib.fFirstRun;
166 this->fLastRun = calib.fLastRun;
167 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
168 AliTOFChannelOnline * calChOnline = (AliTOFChannelOnline*)calib.fTOFCalOnline->At(iarray);
169 AliTOFChannelOffline * calChOffline = (AliTOFChannelOffline*)calib.fTOFCalOffline->At(iarray);
170 this->fTOFCalOnline->AddAt(calChOnline,iarray);
171 this->fTOFCalOffline->AddAt(calChOffline,iarray);
172 AliTOFChannelOnline * simCalChOnline = (AliTOFChannelOnline*)calib.fTOFSimCalOnline->At(iarray);
173 AliTOFChannelOffline * simCalChOffline = (AliTOFChannelOffline*)calib.fTOFSimCalOffline->At(iarray);
174 this->fTOFSimCalOnline->AddAt(simCalChOnline,iarray);
175 this->fTOFSimCalOffline->AddAt(simCalChOffline,iarray);
180 //____________________________________________________________________________
182 AliTOFcalib::~AliTOFcalib()
184 //TOF Calibration Class dtor
185 if(!(AliCDBManager::Instance()->GetCacheFlag())){ // CDB objects must NOT be deleted if cache is active!
187 fTOFCalOnline->Clear();
188 delete fTOFCalOnline;
191 fTOFCalOffline->Clear();
192 delete fTOFCalOffline;
194 if (fTOFSimCalOnline){
195 fTOFSimCalOnline->Clear();
196 delete fTOFSimCalOnline;
198 if (fTOFSimCalOffline){
199 fTOFSimCalOffline->Clear();
200 delete fTOFSimCalOffline;
203 if (fTree!=0x0) delete fTree;
205 //_____________________________________________________________________________
206 void AliTOFcalib::CreateCalArrays(){
208 // creating arrays for online/offline calibration objs
210 fTOFCalOnline = new TObjArray(fNChannels);
211 fTOFCalOffline = new TObjArray(fNChannels);
212 fTOFCalOnline->SetOwner();
213 fTOFCalOffline->SetOwner();
214 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
215 AliTOFChannelOnline * calChOnline = new AliTOFChannelOnline();
216 AliTOFChannelOffline * calChOffline = new AliTOFChannelOffline();
217 fTOFCalOnline->AddAt(calChOnline,iarray);
218 fTOFCalOffline->AddAt(calChOffline,iarray);
221 //_____________________________________________________________________________
222 void AliTOFcalib::CreateSimCalArrays(){
224 // creating arrays for simulation online/offline calibration objs
226 fTOFSimCalOnline = new TObjArray(fNChannels);
227 fTOFSimCalOffline = new TObjArray(fNChannels);
228 fTOFSimCalOnline->SetOwner();
229 fTOFSimCalOffline->SetOwner();
230 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
231 AliTOFChannelOnline * simCalChOnline = new AliTOFChannelOnline();
232 AliTOFChannelOffline * simCalChOffline = new AliTOFChannelOffline();
233 fTOFSimCalOnline->AddAt(simCalChOnline,iarray);
234 fTOFSimCalOffline->AddAt(simCalChOffline,iarray);
237 //_____________________________________________________________________________
238 void AliTOFcalib::WriteParOnlineOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun)
240 //Write calibration parameters to the CDB
243 AliCDBManager *man = AliCDBManager::Instance();
244 Char_t *sel1 = "ParOnline" ; // to be consistent with TOFPreprocessor
246 sprintf(out,"%s/%s",sel,sel1);
247 AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
248 AliCDBId id(out,fFirstRun,fLastRun);
249 AliCDBMetaData *md = new AliCDBMetaData();
250 md->SetResponsible("Chiara Zampolli");
251 if (!fTOFCalOnline) {
254 man->Put(fTOFCalOnline,id,md);
257 //_____________________________________________________________________________
259 void AliTOFcalib::WriteParOnlineOnCDB(Char_t *sel)
261 //Write calibration parameters to the CDB with infinite validity
262 AliCDBManager *man = AliCDBManager::Instance();
263 Char_t *sel1 = "ParOnline" ; // to be consistent with TOFPreprocessor
265 sprintf(out,"%s/%s",sel,sel1);
266 AliCDBRunRange runrange(fFirstRun,fLastRun);
267 AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
268 AliCDBId id(out,runrange);
269 AliCDBMetaData *md = new AliCDBMetaData();
270 md->SetResponsible("Chiara Zampolli");
271 if (!fTOFCalOnline) {
274 man->Put(fTOFCalOnline,id,md);
277 //_____________________________________________________________________________
279 void AliTOFcalib::WriteParOfflineOnCDB(Char_t *sel, const Char_t *validity, Int_t minrun, Int_t maxrun)
281 //Write calibration parameters to the CDB
284 AliCDBManager *man = AliCDBManager::Instance();
285 Char_t *sel1 = "ParOffline" ;
287 sprintf(out,"%s/%s",sel,sel1);
288 AliDebug(2,Form("Writing TOF offline calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
289 AliCDBId id(out,fFirstRun,fLastRun);
290 AliCDBMetaData *md = new AliCDBMetaData();
291 md->SetResponsible("Chiara Zampolli");
292 md->SetComment(validity);
293 man->Put(fTOFCalOffline,id,md);
296 //_____________________________________________________________________________
298 void AliTOFcalib::WriteParOfflineOnCDB(Char_t *sel, const Char_t *validity)
300 //Write calibration parameters to the CDB with infinite validity
301 AliCDBManager *man = AliCDBManager::Instance();
302 Char_t *sel1 = "ParOffline" ;
304 sprintf(out,"%s/%s",sel,sel1);
305 AliCDBRunRange runrange(fFirstRun,fLastRun);
306 AliDebug(2,Form("Writing TOF offline calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
307 AliCDBId id(out,runrange);
308 AliCDBMetaData *md = new AliCDBMetaData();
309 md->SetResponsible("Chiara Zampolli");
310 md->SetComment(validity);
311 man->Put(fTOFCalOffline,id,md);
314 //_____________________________________________________________________________
316 Bool_t AliTOFcalib::ReadParOnlineFromCDB(Char_t *sel, Int_t nrun)
318 //Read calibration parameters from the CDB
319 AliCDBManager *man = AliCDBManager::Instance();
320 Char_t *sel1 = "ParOnline" ;
322 sprintf(out,"%s/%s",sel,sel1);
323 if (!man->Get(out,nrun)) {
326 AliCDBEntry *entry = man->Get(out,nrun);
327 if(!entry->GetObject()){
331 fTOFCalOnline =(TObjArray*)entry->GetObject();
336 //_____________________________________________________________________________
338 Bool_t AliTOFcalib::ReadParOfflineFromCDB(Char_t *sel, Int_t nrun)
340 //Read calibration parameters from the CDB
341 AliCDBManager *man = AliCDBManager::Instance();
342 Char_t *sel1 = "ParOffline" ;
344 sprintf(out,"%s/%s",sel,sel1);
345 if (!man->Get(out,nrun)) {
348 AliCDBEntry *entry = man->Get(out,nrun);
349 if(!entry->GetObject()){
352 AliCDBMetaData * md = entry->GetMetaData();
353 fkValidity = md->GetComment();
354 fTOFCalOffline =(TObjArray*)entry->GetObject();
359 //_____________________________________________________________________________
360 void AliTOFcalib::WriteSimParOnlineOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun, TObjArray *calOnline){
361 //Write Sim miscalibration parameters to the CDB
363 fTOFSimCalOnline=calOnline;
364 AliCDBManager *man = AliCDBManager::Instance();
365 AliCDBMetaData *md = new AliCDBMetaData();
366 md->SetResponsible("Chiara Zampolli");
367 Char_t *sel1 = "SimParOnline" ;
369 sprintf(out,"%s/%s",sel,sel1);
370 AliCDBId id1(out,minrun,maxrun);
371 man->Put(fTOFSimCalOnline,id1,md);
374 //_____________________________________________________________________________
375 void AliTOFcalib::WriteSimParOfflineOnCDB(Char_t *sel, const Char_t *validity, Int_t minrun, Int_t maxrun, TObjArray *calOffline, TH1F *histo){
376 //Write Sim miscalibration parameters to the CDB
379 fTOFSimCalOffline=calOffline;
380 AliCDBManager *man = AliCDBManager::Instance();
381 AliCDBMetaData *md = new AliCDBMetaData();
382 md->SetResponsible("Chiara Zampolli");
383 md->SetComment(validity);
384 Char_t *sel1 = "SimParOffline" ;
386 sprintf(out,"%s/%s",sel,sel1);
387 AliCDBId id1(out,minrun,maxrun);
388 man->Put(fTOFSimCalOffline,id1,md);
389 Char_t *sel2 = "SimHisto" ;
390 sprintf(out,"%s/%s",sel,sel2);
391 AliCDBMetaData *mdhisto = new AliCDBMetaData();
392 mdhisto->SetResponsible("Chiara Zampolli");
393 AliCDBId id2(out,minrun,maxrun);
394 man->Put(fTOFSimToT,id2,mdhisto);
398 //_____________________________________________________________________________
399 void AliTOFcalib::ReadSimParOnlineFromCDB(Char_t *sel, Int_t nrun)
401 //Read miscalibration parameters from the CDB
402 AliCDBManager *man = AliCDBManager::Instance();
406 Char_t *sel1 = "SimParOnline" ;
408 sprintf(out,"%s/%s",sel,sel1);
409 if (!man->Get(out,nrun)) {
410 AliFatal("Exiting, no CDB object (SimParOnline) found!!!");
413 AliCDBEntry *entry1 = man->Get(out,nrun);
414 if(!entry1->GetObject()){
415 AliFatal("Exiting, no CDB object (SimParOnline) found!!!");
418 TObjArray *cal =(TObjArray*)entry1->GetObject();
419 fTOFSimCalOnline=cal;
422 //_____________________________________________________________________________
423 void AliTOFcalib::ReadSimParOfflineFromCDB(Char_t *sel, Int_t nrun)
425 //Read miscalibration parameters from the CDB
426 AliCDBManager *man = AliCDBManager::Instance();
430 Char_t *sel1 = "SimParOffline" ;
432 sprintf(out,"%s/%s",sel,sel1);
433 if (!man->Get(out,nrun)) {
434 AliFatal("Exiting, no CDB object (SimParOffline) found!!!");
437 AliCDBEntry *entry1 = man->Get(out,nrun);
438 if(!entry1->GetObject()){
439 AliFatal("Exiting, no CDB object (SimParOffline) found!!!");
442 TObjArray *cal =(TObjArray*)entry1->GetObject();
443 AliCDBMetaData *md = (AliCDBMetaData*)entry1->GetMetaData();
444 fkValidity = md->GetComment();
445 fTOFSimCalOffline=cal;
449 Char_t *sel2 = "SimHisto" ;
450 sprintf(out,"%s/%s",sel,sel2);
451 if (!man->Get(out,nrun)) {
452 AliFatal("Exiting, no CDB object (SimHisto) found!!!");
455 AliCDBEntry *entry2 = man->Get(out,nrun);
456 if(!entry2->GetObject()){
457 AliFatal("Exiting, no CDB object (SimHisto) found!!!");
460 TH1F *histo =(TH1F*)entry2->GetObject();
463 //_____________________________________________________________________________
464 void AliTOFcalib::WriteRecParOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun, AliTOFRecoParam *param){
465 //Write reconstruction parameters to the CDB
467 AliCDBManager *man = AliCDBManager::Instance();
468 AliCDBMetaData *md = new AliCDBMetaData();
469 md->SetResponsible("Silvia Arcelli");
470 Char_t *sel1 = "RecPar" ;
472 sprintf(out,"%s/%s",sel,sel1);
473 AliCDBId id(out,minrun,maxrun);
474 man->Put(param,id,md);
477 //_____________________________________________________________________________
478 AliTOFRecoParam * AliTOFcalib::ReadRecParFromCDB(Char_t *sel, Int_t nrun)
480 //Read reconstruction parameters from the CDB
481 AliCDBManager *man = AliCDBManager::Instance();
482 Char_t *sel1 = "RecPar" ;
484 sprintf(out,"%s/%s",sel,sel1);
485 if (!man->Get(out,nrun)) {
486 AliFatal("Exiting, no CDB object (RecPar) found!!!");
489 AliCDBEntry *entry = man->Get(out,nrun);
490 if(!entry->GetObject()){
491 AliFatal("Exiting, no CDB object (RecPar) found!!!");
495 AliTOFRecoParam *param=(AliTOFRecoParam*)entry->GetObject();
498 //-----------------------------------------------------------------------------
499 // Calibration methods
500 //-----------------------------------------------------------------------------
501 void AliTOFcalib::CreateTreeFromCDB(Int_t minrun, Int_t maxrun){
503 // creating the chain with the trees for calibration
504 // collecting them from reference data
505 // from minrun to maxrun
507 Float_t p[CHENTRIESSMALL];
509 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
510 fTree->Branch("nentries",&nentries,"nentries/I");
511 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
512 AliCDBManager *man = AliCDBManager::Instance();
513 AliCDBStorage *aStorage = man->GetStorage("local://$ALICE_ROOT");
514 for (Int_t irun = minrun;irun<=maxrun;irun++){
515 AliCDBEntry *entry = aStorage->Get("TOF/RefData/TreeForCalib",irun);
517 AliInfo(Form("No entry found for run %i",irun));
520 TTree *tree = new TTree();
521 tree = (TTree*)entry->GetObject();
522 tree->SetBranchAddress("nentries",&nentries);
523 tree->SetBranchAddress("TOFentries",p);
524 fTree->CopyEntries(tree);
529 AliInfo(Form("Number of runs being analyzed %i",fNruns));
531 //-----------------------------------------------------------------------------
532 void AliTOFcalib::CreateTreeFromGrid(Int_t minrun, Int_t maxrun){
534 // creating the chain with the trees for calibration
535 // collecting them from the Grid
536 // from minrun to maxrun
538 Float_t p[CHENTRIESSMALL];
540 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
541 fTree->SetDirectory(0);
542 fTree->Branch("nentries",&nentries,"nentries/I");
543 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
544 AliInfo("connected to alien");
545 TGrid::Connect("alien://");
547 Char_t filename[100];
548 for (Int_t irun = minrun;irun<=maxrun;irun++){
549 sprintf(filename,"alien:///alice/cern.ch/user/c/czampolli/TOFCalibReference_%i.root",irun);
550 TFile *filegrid = TFile::Open(filename,"READ");
551 TTree *tree = (TTree*)filegrid->Get("T");
552 tree->SetBranchAddress("nentries",&nentries);
553 tree->SetBranchAddress("TOFentries",p);
554 fTree->CopyEntries(tree);
559 AliInfo(Form("Number of runs being analyzed %i",fNruns));
561 //-----------------------------------------------------------------------------
562 void AliTOFcalib::CreateTreeFromFile(Int_t minrun, Int_t maxrun){
564 // creating the tree with the trees for calibration
565 // collecting them from reference data (from file)
566 // from minrun to maxrun
568 Float_t p[CHENTRIESSMALL];
570 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
571 fTree->SetDirectory(0);
572 fTree->Branch("nentries",&nentries,"nentries/I");
573 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
574 Char_t filename[100];
575 for (Int_t irun = minrun;irun<=maxrun;irun++){
576 sprintf(filename,"$ALICE_ROOT/TOF/RefData/TreeForCalib/fileout_%i.root",irun);
577 TFile *file = new TFile(filename,"READ");
578 TTree *tree = (TTree*)file->Get("T");
579 tree->SetBranchAddress("nentries",&nentries);
580 tree->SetBranchAddress("TOFentries",p);
581 fTree->CopyEntries(tree);
588 AliInfo(Form("Number of runs being analyzed %i",fNruns));
590 //-----------------------------------------------------------------------------
591 Int_t AliTOFcalib::Calibrate(Int_t ichmin, Int_t ichmax, Option_t *optionSave, Option_t *optionFit){
593 // calibrating summing more than one channels
594 // computing calibration parameters
596 // 0 -> everything was ok
597 // 1 -> no tree for calibration found
598 // 2 -> not enough statistics to perform calibration
599 // 3 -> problems with arrays
601 TH1::AddDirectory(0);
603 AliInfo(Form("*** Calibrating Histograms %s, summing more channels, from channel %i, to channel %i, storing Calib Pars in channel %i", GetName(),ichmin,ichmax,ichmin)) ;
604 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
605 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
607 Float_t p[CHENTRIESSMALL];
609 fTree->SetBranchAddress("nentries",&nentries);
610 fTree->SetBranchAddress("TOFentries",p);
612 Float_t ntracksTotalmean =0;
613 for (Int_t i=ichmin; i<ichmax; i++){
615 for (Int_t irun=0;irun<fNruns;irun++){
616 ientry = i+irun*fNChannels;
617 fTree->GetEntry(ientry);
618 Int_t ntracksRun=nentries/3;
619 ntracksTotalmean+=ntracksRun;
623 if (ntracksTotalmean < MEANENTRIES) {
624 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
628 //filling ToT and Time arrays
630 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
631 Float_t minToT = 0; // ns
632 Float_t maxToT = 4.88; // ns
634 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
635 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
636 Int_t ntracksTotal = 0;
637 Int_t ntracksRun = 0;
638 Double_t binsProfile[101]; // sized larger than necessary, the correct
639 // dim being set in the booking of the profile
642 for (Int_t i = ichmin;i<ichmax;i++){
644 for (Int_t irun=0;irun<fNruns;irun++){
645 ientry = i+irun*fNChannels;
646 fTree->GetEntry(ientry);
647 ntracksTotal+=nentries/3;
648 ntracksRun=nentries/3;
649 AliDebug(2,Form("run %i, channel %i, nentries = %i, ntracks = %i",irun,i,nentries, ntracksRun));
650 for (Int_t j=0;j<ntracksRun;j++){
651 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
652 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
653 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
654 Float_t tot = p[idxexToT];
655 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
656 meantime+=p[idxexTime]-p[idxexExTime];
661 nusefulbins = FindBins(hToT,&binsProfile[0]);
662 meantime/=ntracksTotal;
663 AliDebug(2, Form("meantime = %f",meantime));
665 for (Int_t j=1;j<=nusefulbins;j++) {
666 AliDebug(2,Form(" summing channels from %i to %i, nusefulbins = %i, bin %i = %f",ichmin,ichmax,nusefulbins,j,binsProfile[j]));
669 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
670 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
672 for (Int_t irun=0;irun<fNruns;irun++){
674 for (Int_t i=ichmin; i<ichmax; i++){
675 ientry = i+irun*fNChannels;
676 fTree->GetEntry(ientry);
677 ntracksRun=nentries/3;
678 for (Int_t j=0;j<ntracksRun;j++){
679 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
680 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
681 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
682 Float_t tot = p[idxexToT];
683 Float_t time = p[idxexTime]-p[idxexExTime];
684 AliDebug (2, Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
685 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
686 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
691 hSlewingProf->Fit("pol5",optionFit,"",0,4);
692 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
694 for(Int_t kk=0;kk<6;kk++){
695 par[kk]=calibfunc->GetParameter(kk);
696 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
699 if(strstr(optionSave,"save")){
700 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
702 TString profName=Form("Profile%06i_%06i",ichmin,ichmax);
703 TString timeTotName=Form("TimeTot%06i_%06i",ichmin,ichmax);
704 TString totName=Form("Tot%06i_%06i",ichmin,ichmax);
705 TString deltaName=Form("Delta%06i_%06i",ichmin,ichmax);
706 hSlewingProf->Write(profName);
707 htimetot->Write(timeTotName);
708 hToT->Write(totName);
709 hdeltaTime->Write(deltaName);
724 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ichmin);
725 calChannel->SetSlewPar(par);
726 WriteParOfflineOnCDB("TOF/Calib","valid");
729 //----------------------------------------------------------------------------
730 Int_t AliTOFcalib::Calibrate(Int_t i, Option_t *optionSave, Option_t *optionFit){
732 // computing calibration parameters for channel i
734 // 0 -> everything was ok
735 // 1 -> no tree for calibration found
736 // 2 -> not enough statistics to perform calibration
737 // 3 -> problems with arrays
739 TH1::AddDirectory(0);
741 AliInfo(Form("*** Calibrating Histograms (one channel) %s", GetName())) ;
742 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
743 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
745 Float_t p[MAXCHENTRIESSMALL];
747 fTree->SetBranchAddress("nentries",&nentries);
748 fTree->SetBranchAddress("TOFentries",p);
750 Float_t ntracksTotal =0;
751 for (Int_t irun=0;irun<fNruns;irun++){
753 ientry = i+irun*fNChannels;
754 fTree->GetEntry(ientry);
755 ntracksTotal+=nentries/3;
758 if (ntracksTotal < MEANENTRIES) {
759 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotal));
763 //filling ToT and Time arrays
765 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
766 Float_t minToT = 0; // ns
767 Float_t maxToT = 4.88; // ns
769 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
770 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
771 Int_t ntracksRun = 0;
772 Double_t binsProfile[101]; // sized larger than necessary, the correct
773 // dim being set in the booking of the profile
776 for (Int_t irun=0;irun<fNruns;irun++){
778 ientry = i+irun*fNChannels;
779 fTree->GetEntry(ientry);
780 ntracksRun=nentries/3;
781 AliDebug(2,Form("run %i, channel %i, nentries = %i, ntracksRun = %i",irun, i ,nentries, ntracksRun));
782 for (Int_t j=0;j<ntracksRun;j++){
783 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
784 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
785 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
786 Float_t tot = p[idxexToT];
787 meantime+=p[idxexTime]-p[idxexExTime];
788 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
793 nusefulbins = FindBins(hToT,&binsProfile[0]);
794 meantime/=ntracksTotal;
795 AliDebug(2,Form("meantime = %f",meantime));
797 for (Int_t j=1;j<=nusefulbins;j++) {
798 AliDebug(2,Form(" channel %i, nusefulbins = %i, bin %i = %f",i,nusefulbins,j,binsProfile[j]));
801 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
802 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
803 for (Int_t irun=0;irun<fNruns;irun++){
805 ientry = i+irun*fNChannels;
806 fTree->GetEntry(ientry);
807 ntracksRun=nentries/3;
808 for (Int_t j=0;j<ntracksRun;j++){
809 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
810 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
811 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
812 Float_t tot = p[idxexToT];
813 Float_t time = p[idxexTime]-p[idxexExTime];
814 AliDebug (2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
815 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
816 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
820 hSlewingProf->Fit("pol5",optionFit,"",0,4);
821 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
823 for(Int_t kk=0;kk<6;kk++){
824 par[kk]=calibfunc->GetParameter(kk);
825 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
829 if(strstr(optionSave,"save")){
830 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
832 TString profName=Form("Profile%06i",i);
833 TString timeTotName=Form("TimeTot%06i",i);
834 TString totName=Form("Tot%06i",i);
835 TString deltaName=Form("Delta%06i",i);
836 hSlewingProf->Write(profName);
837 htimetot->Write(timeTotName);
838 hToT->Write(totName);
839 hdeltaTime->Write(deltaName);
854 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(i);
855 calChannel->SetSlewPar(par);
856 WriteParOfflineOnCDB("TOF/Calib","valid");
859 //----------------------------------------------------------------------------
860 Int_t AliTOFcalib::Calibrate(Int_t nch, Int_t *ch, Option_t *optionSave, Option_t *optionFit){
862 // calibrating an array of channels
863 // computing calibration parameters
865 // 0 -> everything was ok
866 // 1 -> no tree for calibration found
867 // 2 -> not enough statistics to perform calibration
868 // 3 -> problems with arrays
870 TH1::AddDirectory(0);
872 AliInfo(Form("*** Calibrating Histograms %s, number of channels = %i", GetName(),nch)) ;
873 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
874 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
875 for (Int_t ich=0; ich<nch; ich++){
877 AliInfo(Form("Calibrating channel = %i",i )) ;
879 Float_t p[MAXCHENTRIESSMALL];
881 fTree->SetBranchAddress("nentries",&nentries);
882 fTree->SetBranchAddress("TOFentries",p);
884 Float_t ntracksTotalmean =0;
885 for (Int_t ich=0; ich<nch; ich++){
888 for (Int_t irun=0;irun<fNruns;irun++){
889 ientry = i+irun*fNChannels;
890 fTree->GetEntry(ientry);
891 ntracksTotalmean+=nentries/3;
895 ntracksTotalmean/=nch;
896 if (ntracksTotalmean < MEANENTRIES) {
897 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
901 //filling ToT and Time arrays
903 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
904 Float_t minToT = 0; // ns
905 Float_t maxToT = 4.88; // ns
906 TFile * fileProf=0x0;
907 if(strstr(optionSave,"save")){
908 fileProf = new TFile("TOFCalibSave.root","recreate");
910 for (Int_t ich=0; ich<nch; ich++) {
911 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
912 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
913 Double_t binsProfile[101]; // sized larger than necessary, the correct
914 // dim being set in the booking of the profile
915 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
916 Int_t ntracksTotal = 0;
917 Int_t ntracksRun = 0;
921 for (Int_t irun=0;irun<fNruns;irun++){
922 i = ch[ich]+irun*fNChannels;
923 AliDebug(2,Form("Calibrating channel %i",i));
925 ntracksTotal+=nentries/3;
927 if (ntracksTotal < MEANENTRIES) {
928 AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %f), not calibrating channel and continuing.....",i,ntracksTotal));
932 for (Int_t irun=0;irun<fNruns;irun++){
933 Int_t i = ch[ich]+irun*fNChannels;
935 ntracksRun=nentries/3;
936 for (Int_t j=0;j<ntracksRun;j++){
937 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
938 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
939 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
940 Float_t tot = p[idxexToT];
941 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
942 meantime+=p[idxexTime]-p[idxexExTime];
947 nusefulbins = FindBins(hToT,&binsProfile[0]);
948 meantime/=ntracksTotal;
949 for (Int_t j=1;j<=nusefulbins;j++) {
950 AliDebug(2,Form(" channel %i, nusefulbins = %i, bin %i = %f",i,nusefulbins,j,binsProfile[j]));
953 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
954 for (Int_t irun=0;irun<fNruns;irun++){
955 Int_t i = ch[ich]+irun*fNChannels;
957 ntracksRun=nentries/3;
958 for (Int_t j=0;j<ntracksRun;j++){
959 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
960 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
961 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
962 Float_t tot = p[idxexToT];
963 Float_t time = p[idxexTime]-p[idxexExTime];
964 AliDebug(2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
965 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
966 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
970 hSlewingProf->Fit("pol5",optionFit,"",1,4);
971 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
973 for(Int_t kk=0;kk<6;kk++){
974 par[kk]=calibfunc->GetParameter(kk);
975 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
978 if(strstr(optionSave,"save") && fileProf){
979 TString profName=Form("Profile%06i",i);
980 TString timeTotName=Form("TimeTot%06i",i);
981 TString totName=Form("Tot%06i",i);
982 TString deltaName=Form("Delta%06i",i);
984 hSlewingProf->Write(profName);
985 htimetot->Write(timeTotName);
986 hToT->Write(totName);
987 hdeltaTime->Write(deltaName);
990 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(i);
991 calChannel->SetSlewPar(par);
1002 if(strstr(optionSave,"save") && fileProf){
1007 WriteParOfflineOnCDB("TOF/Calib","valid");
1011 //----------------------------------------------------------------------------
1012 Int_t AliTOFcalib::CalibrateFromProfile(Int_t ich, Option_t *optionSave, Option_t *optionFit){
1014 // computing calibration parameters using the old profiling algo
1016 // 0 -> everything was ok
1017 // 1 -> no tree for calibration found
1018 // 2 -> not enough statistics to perform calibration
1019 // 3 -> problems with arrays
1021 TH1::AddDirectory(0);
1023 AliInfo(Form("*** Calibrating Histograms From Profile %s", GetName())) ;
1024 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1025 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1026 Float_t p[MAXCHENTRIESSMALL];
1028 Int_t ntracksTotal=0;
1029 fTree->SetBranchAddress("nentries",&nentries);
1030 fTree->SetBranchAddress("TOFentries",p);
1032 for (Int_t irun=0;irun<fNruns;irun++){
1033 Int_t i = ich+irun*fNChannels;
1035 ntracksTotal+=nentries/3;
1038 if (ntracksTotal < MEANENTRIES) {
1039 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotal));
1043 TH1F * hProf = new TH1F();
1044 hProf = Profile(ich);
1045 hProf->Fit("pol5",optionFit,"",0,4);
1046 TF1 * calibfunc = (TF1*)hProf->GetFunction("pol5");
1048 for(Int_t kk=0;kk<6;kk++){
1049 par[kk]=calibfunc->GetParameter(kk);
1050 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1053 if(strstr(optionSave,"save")){
1054 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
1056 TString profName=Form("Profile%06i",ich);
1057 hProf->Write(profName);
1065 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ich);
1066 calChannel->SetSlewPar(par);
1067 WriteParOfflineOnCDB("TOF/Calib","valid");
1070 //----------------------------------------------------------------------------
1071 Int_t AliTOFcalib::Calibrate(Option_t *optionSave, Option_t *optionFit){
1073 // calibrating the whole TOF
1074 // computing calibration parameters
1076 // 0 -> everything was ok
1077 // 1 -> no tree for calibration found
1078 // 2 -> not enough statistics to perform calibration
1079 // 3 -> problems with arrays
1081 TH1::AddDirectory(0);
1083 AliInfo(Form("*** Calibrating Histograms %s, all channels", GetName())) ;
1084 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1085 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1087 TFile * fileProf=0x0;
1088 if(strstr(optionSave,"save")){
1089 fileProf = new TFile("TOFCalibSave.root","recreate");
1092 Float_t p[MAXCHENTRIESSMALL];
1094 fTree->SetBranchAddress("nentries",&nentries);
1095 fTree->SetBranchAddress("TOFentries",p);
1097 Float_t ntracksTotalmean =0;
1098 for (Int_t ii=0; ii<fNChannels; ii++){
1099 for (Int_t irun=0;irun<fNruns;irun++){
1100 Int_t i = ii+irun*fNChannels;
1102 ntracksTotalmean+=nentries/3;
1106 ntracksTotalmean/=fNChannels;
1107 if (ntracksTotalmean < MEANENTRIES) {
1108 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
1112 //filling ToT and Time arrays
1114 Int_t nbinToT = 100; // ToT bin width in Profile = 50.0 ps
1115 Float_t minToT = 0; // ns
1116 Float_t maxToT = 4.88;// ns
1117 for (Int_t ii=0; ii<fNChannels; ii++) {
1118 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1119 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1120 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1121 if (ii%1000 == 0) AliDebug(1,Form("Calibrating channel %i ",ii));
1123 Int_t nusefulbins=0;
1124 Double_t binsProfile[101]; // sized larger than necessary, the correct
1125 // dim being set in the booking of the profile
1126 Int_t ntracksRun = 0;
1127 Int_t ntracksTotal = 0;
1128 for (Int_t irun=0;irun<fNruns;irun++){
1129 Int_t i = ii+irun*fNChannels;
1131 ntracksTotal+=nentries/3;
1133 if (ntracksTotal < MEANENTRIES) {
1134 AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %f), not calibrating channel and continuing.....",ii,ntracksTotal));
1138 for (Int_t irun=0;irun<fNruns;irun++){
1139 Int_t i = ii+irun*fNChannels;
1141 ntracksRun=nentries/3;
1142 for (Int_t j=0;j<ntracksRun;j++){
1143 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1144 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1145 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1146 Float_t tot = p[idxexToT];
1147 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1148 meantime+=p[idxexTime]-p[idxexExTime];
1152 nusefulbins = FindBins(hToT,&binsProfile[0]);
1153 meantime/=ntracksTotal;
1154 for (Int_t j=0;j<nusefulbins;j++) {
1155 AliDebug(2,Form(" channel %i, usefulbin = %i, low edge = %f",ii,j,binsProfile[j]));
1157 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1158 for (Int_t irun=0;irun<fNruns;irun++){
1159 Int_t i = ii+irun*fNChannels;
1161 ntracksRun=nentries/3;
1162 for (Int_t j=0;j<ntracksRun;j++){
1163 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1164 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1165 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1166 Float_t tot = p[idxexToT];
1167 Float_t time = p[idxexTime]-p[idxexExTime];
1168 AliDebug (2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1169 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1170 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1173 hSlewingProf->Fit("pol5",optionFit,"",1,4);
1174 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1176 for(Int_t kk=0;kk<6;kk++){
1177 par[kk]=calibfunc->GetParameter(kk);
1178 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1181 if(strstr(optionSave,"save") && fileProf){
1182 TString profName=Form("Profile%06i",ii);
1183 TString timeTotName=Form("TimeTot%06i",ii);
1184 TString totName=Form("Tot%06i",ii);
1185 TString deltaName=Form("Delta%06i",ii);
1187 hSlewingProf->Write(profName);
1188 htimetot->Write(timeTotName);
1189 hToT->Write(totName);
1190 hdeltaTime->Write(deltaName);
1192 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ii);
1193 calChannel->SetSlewPar(par);
1197 delete hSlewingProf;
1205 if(strstr(optionSave,"save")){
1210 WriteParOfflineOnCDB("TOF/Calib","valid");
1214 //-----------------------------------------------------------------------
1215 TH1F* AliTOFcalib::Profile(Int_t ich)
1219 Float_t p[MAXCHENTRIESSMALL];
1221 fTree->SetBranchAddress("nentries",&nentries);
1222 fTree->SetBranchAddress("TOFentries",p);
1224 //Prepare histograms for Slewing Correction
1225 const Int_t knbinToT = 100;
1226 Int_t nbinTime = 200;
1227 Float_t minTime = -5.5; //ns
1228 Float_t maxTime = 5.5; //ns
1229 Float_t minToT = 0; //ns
1230 Float_t maxToT = 5.; //ns
1231 Float_t deltaToT = (maxToT-minToT)/knbinToT;
1232 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];
1233 Int_t n[knbinToT+1], nentrx[knbinToT+1];
1234 Double_t sigmaToT[knbinToT+1];
1235 for (Int_t i = 0; i < knbinToT+1 ; i++){
1253 TH2F* hSlewing = new TH2F("hSlewing", "hSlewing", knbinToT, minToT, maxToT, nbinTime, minTime, maxTime);
1254 Int_t ntracksRun = 0;
1255 TH1F *histo = new TH1F("histo", "1D Time vs ToT", knbinToT, minToT, maxToT);
1256 for (Int_t irun=0;irun<fNruns;irun++){
1257 Int_t i = ich+irun*fNChannels;
1259 ntracksRun=nentries/3;
1260 for (Int_t j=0;j<ntracksRun;j++){
1261 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1262 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1263 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1264 Float_t tot = p[idxexToT];
1265 Float_t time = p[idxexTime]-p[idxexExTime];
1266 Int_t nx = (Int_t)((tot-minToT)/deltaToT)+1;
1267 if ((tot != 0) && ( time!= 0)){
1269 vTime2[nx]+=time*time;
1273 hSlewing->Fill(tot,time);
1277 Int_t nbinsToT=hSlewing->GetNbinsX();
1278 if (nbinsToT != knbinToT) {
1279 AliError("Profile :: incompatible numbers of bins");
1284 for (Int_t i=1;i<=nbinsToT;i++){
1286 n[usefulBins]+=nentrx[i];
1287 if (n[usefulBins]==0 && i == nbinsToT) {
1290 meanTime[usefulBins]+=vTime[i];
1291 meanTime2[usefulBins]+=vTime2[i];
1292 meanToT[usefulBins]+=vToT[i];
1293 meanToT2[usefulBins]+=vToT2[i];
1294 if (n[usefulBins]<10 && i!=nbinsToT) continue;
1295 mTime[usefulBins]=meanTime[usefulBins]/n[usefulBins];
1296 mToT[usefulBins]=meanToT[usefulBins]/n[usefulBins];
1297 sigmaTime[usefulBins]=TMath::Sqrt(1./n[usefulBins]/n[usefulBins]
1298 *(meanTime2[usefulBins]-meanTime[usefulBins]
1299 *meanTime[usefulBins]/n[usefulBins]));
1300 if ((1./n[usefulBins]/n[usefulBins]
1301 *(meanToT2[usefulBins]-meanToT[usefulBins]
1302 *meanToT[usefulBins]/n[usefulBins]))< 0) {
1303 AliError(" too small radical" );
1304 sigmaToT[usefulBins]=0;
1307 sigmaToT[usefulBins]=TMath::Sqrt(1./n[usefulBins]/n[usefulBins]
1308 *(meanToT2[usefulBins]-meanToT[usefulBins]
1309 *meanToT[usefulBins]/n[usefulBins]));
1314 for (Int_t i=0;i<usefulBins;i++){
1315 Int_t binN = (Int_t)((mToT[i]-minToT)/deltaToT)+1;
1316 histo->Fill(mToT[i],mTime[i]);
1317 histo->SetBinError(binN,sigmaTime[i]);
1324 //----------------------------------------------------------------------------
1325 Int_t AliTOFcalib::FindBins(TH1F* h, Double_t *binsProfile) const{
1327 // to determine the bins for ToT histo
1331 Int_t nbin = h->GetNbinsX();
1332 Int_t nentries = (Int_t)h->GetEntries();
1333 Float_t max = h->GetBinLowEdge(nbin);
1334 Int_t nusefulbins=0;
1336 // setting maxvalue of entries per bin
1337 if (nentries <= 60) maxcont = 2;
1338 else if (nentries <= 100) maxcont = 5;
1339 else if (nentries <= 500) maxcont = 10;
1341 for (Int_t j=1;j<=nbin;j++) {
1342 cont += (Int_t)h->GetBinContent(j);
1346 binsProfile[nusefulbins-1]=h->GetBinLowEdge(startBin);
1355 binsProfile[nusefulbins-1]=h->GetBinLowEdge(startBin);
1356 binsProfile[nusefulbins]=max;
1359 binsProfile[nusefulbins]=h->GetBinLowEdge(startBin);