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 **************************************************************************/
19 // task to perform TOF calibration
20 // optimized for pp runs
21 // expect a maximum of 100 entries per channel
22 // different ways to calibrate are implemented
39 #include "AliTOFCalibTask.h"
40 #include "AliTOFChannelTask.h"
41 #include "AliESDEvent.h"
42 #include "AliESDtrack.h"
44 //______________________________________________________________________________
45 AliTOFCalibTask::AliTOFCalibTask(const char *name) :
46 AliAnalysisTask(name,""),
78 // Input slot #0 works with an Ntuple
80 DefineInput(0, TChain::Class());
81 // Output slot #0 writes into a TH1 container
82 DefineOutput(0, TObjArray::Class()) ;
83 fdir = gDirectory->GetPath();
84 fbigarray = new Float_t*[TOFCHANNELS];
85 findexarray = new Int_t[TOFCHANNELS];
87 for (Int_t i =0;i<TOFCHANNELS;i++){
88 fbigarray[i] = new Float_t[CHENTRIES];
90 for (Int_t j =0;j<CHENTRIES;j++){
96 //______________________________________________________________________________
97 AliTOFCalibTask::AliTOFCalibTask(const AliTOFCalibTask &calibtask) :
98 AliAnalysisTask("AliTOFCalibTask",""),
131 fChain=calibtask.fChain;
133 fMinEntries=calibtask.fMinEntries;
136 fTime=calibtask.fTime;
137 fExpTimePi=calibtask.fExpTimePi;
138 fExpTimeKa=calibtask.fExpTimeKa;
139 fExpTimePr=calibtask.fExpTimePr;
140 ftree=calibtask.ftree;
141 fMinTime=calibtask.fMinTime;
142 fnESD=calibtask.fnESD;
143 fnESDselected=calibtask.fnESDselected;
144 fnESDkTOFout=calibtask.fnESDkTOFout;
145 fnESDkTIME=calibtask.fnESDkTIME;
146 fnESDassTOFcl=calibtask.fnESDassTOFcl;
147 fnESDTIMEcut=calibtask.fnESDTIMEcut;
148 fnESDTRDcut=calibtask.fnESDTRDcut;
149 fhToT=calibtask.fhToT;
150 fhTime=calibtask.fhTime;
151 fhExpTimePi=calibtask.fhExpTimePi;
152 fhExpTimeKa=calibtask.fhExpTimeKa;
153 fhExpTimePr=calibtask.fhExpTimePr;
154 fhPID=calibtask.fhPID;
156 fOutputContainer=calibtask.fOutputContainer;
158 fbigarray = new Float_t*[TOFCHANNELS];
159 findexarray = new Int_t[TOFCHANNELS];
161 for (Int_t i =0;i<TOFCHANNELS;i++){
162 fbigarray[i] = new Float_t[CHENTRIES];
163 findexarray[i]=calibtask.findexarray[i];
164 for (Int_t j =0;j<CHENTRIES;j++){
165 fbigarray[i][j]=calibtask.fbigarray[i][j];
170 //______________________________________________________________________________
171 AliTOFCalibTask:: ~AliTOFCalibTask()
175 AliInfo("TOF Calib Task: Deleting");
178 delete fOutputContainer;
187 //______________________________________________________________________________
188 AliTOFCalibTask& AliTOFCalibTask::operator=(const AliTOFCalibTask &calibtask)
190 //assignment operator
191 this->fdir=calibtask.fdir;
192 this->fChain=calibtask.fChain;
193 this->fESD=calibtask.fESD;
194 this->fMinEntries=calibtask.fMinEntries;
195 this->fIch=calibtask.fIch;
196 this->fToT=calibtask.fToT;
197 this->fTime=calibtask.fTime;
198 this->fExpTimePi=calibtask.fExpTimePi;
199 this->fExpTimeKa=calibtask.fExpTimeKa;
200 this->fExpTimePr=calibtask.fExpTimePr;
201 this->ftree=calibtask.ftree;
202 this->fMinTime=calibtask.fMinTime;
203 this->fnESD=calibtask.fnESD;
204 this->fnESDselected=calibtask.fnESDselected;
205 this->fnESDkTOFout=calibtask.fnESDkTOFout;
206 this->fnESDkTIME=calibtask.fnESDkTIME;
207 this->fnESDassTOFcl=calibtask.fnESDassTOFcl;
208 this->fnESDTIMEcut=calibtask.fnESDTIMEcut;
209 this->fnESDTRDcut=calibtask.fnESDTRDcut;
210 this->fhToT=calibtask.fhToT;
211 this->fhTime=calibtask.fhTime;
212 this->fhExpTimePi=calibtask.fhExpTimePi;
213 this->fhExpTimeKa=calibtask.fhExpTimeKa;
214 this->fhExpTimePr=calibtask.fhExpTimePr;
215 this->fOutputContainer=calibtask.fOutputContainer;
216 this->fhPID=calibtask.fhPID;
217 this->fhch=calibtask.fhch;
219 this->fbigarray = new Float_t*[TOFCHANNELS];
220 this->findexarray = new Int_t[TOFCHANNELS];
221 for (Int_t i =0;i<TOFCHANNELS;i++){
222 this->fbigarray[i] = new Float_t[CHENTRIES];
223 this->findexarray[i]=calibtask.findexarray[i];
224 for (Int_t j =0;j<CHENTRIES;j++){
225 this->fbigarray[i][j]=calibtask.fbigarray[i][j];
230 //--------------------------------------------------------------------------
231 void AliTOFCalibTask::BookHistos(){
235 AliInfo(Form("*** Booking Histograms %s", GetName())) ;
238 new TH1F("hToT", " ToT distribution (ns) ", 400, 0, 40);
240 new TH1F("hTime", " Time distribution (ns) ", 400, 0, 40);
242 new TH1F("hExpTimePi", " Exp Time distribution, Pi (ns) ", 400, 0, 40);
244 new TH1F("hExpTimeKa", " Exp Time distribution, Ka (ns) ", 400, 0, 40);
246 new TH1F("hExpTimePr", " Exp Time distribution, Pr (ns) ", 400, 0, 40);
248 new TH1I("hPID", " Combinatorial PID identity ", 3, 0, 3);
250 new TH1D("hch", " TOF channel ", TOFCHANNELS, 0, TOFCHANNELS);
252 //create the putput container
253 fOutputContainer = new TObjArray(7) ;
254 fOutputContainer->SetName(GetName()) ;
256 fOutputContainer->AddAt(fhToT, 0) ;
257 fOutputContainer->AddAt(fhTime, 1) ;
258 fOutputContainer->AddAt(fhExpTimePi, 2) ;
259 fOutputContainer->AddAt(fhExpTimeKa, 3) ;
260 fOutputContainer->AddAt(fhExpTimePr, 4) ;
261 fOutputContainer->AddAt(fhPID, 5) ;
262 fOutputContainer->AddAt(fhch, 6) ;
265 //----------------------------------------------------------------------------
266 void AliTOFCalibTask::DrawHistos(){
268 // drawing output histos
270 AliInfo(Form("*** Drawing Histograms %s", GetName())) ;
272 TCanvas * canvasToTTime = new TCanvas("canvasToTTime", " ToT and Time ",400, 30, 550, 630) ;
273 canvasToTTime->Divide(1,2);
274 canvasToTTime->cd(1);
275 fhToT->SetLineColor(4);
276 fhToT->GetXaxis()->SetTitle("ToT (ns)");
278 canvasToTTime->cd(2);
279 fhTime->SetLineColor(4);
280 fhTime->GetXaxis()->SetTitle("Time (ns)");
281 fhTime->Draw("hist");
282 canvasToTTime->Update();
283 canvasToTTime->Print("ToTTime.gif");
285 TCanvas * canvasExpTime = new TCanvas("canvasExpTime", " Expected Times ",400, 30, 550, 630) ;
286 canvasExpTime->Divide(1,3);
287 canvasExpTime->cd(1);
288 fhExpTimePi->SetLineColor(4);
289 fhExpTimePi->GetXaxis()->SetTitle("Exp Time (ns), #pi");
290 fhExpTimePi->Draw("hist");
291 canvasExpTime->cd(2);
292 fhExpTimeKa->SetLineColor(4);
293 fhExpTimeKa->GetXaxis()->SetTitle("Exp Time (ns), K");
294 fhExpTimeKa->Draw("hist");
295 canvasExpTime->cd(3);
296 fhExpTimePr->SetLineColor(4);
297 fhExpTimePr->GetXaxis()->SetTitle("Exp Time (ns), p");
298 fhExpTimePr->Draw("hist");
300 canvasExpTime->Print("ExpTime.gif");
302 TCanvas * canvasPID = new TCanvas("canvasPID", " Combinatorial PID ",400, 30, 550, 400);
303 fhPID->GetXaxis()->SetTitle("Comb PID");
304 fhPID->GetXaxis()->SetBinLabel(1,"#pi");
305 fhPID->GetXaxis()->SetBinLabel(2,"K");
306 fhPID->GetXaxis()->SetBinLabel(3,"p");
309 canvasPID->Print("PID.gif");
311 TCanvas * canvasrndch = new TCanvas("canvasrndch", " TOF channel ",400, 30, 550, 400);
312 fhch->GetXaxis()->SetTitle("TOF ch");
314 Float_t meanTOFch = 0;
315 for (Int_t ibin=0;ibin<TOFCHANNELS;ibin++){
316 meanTOFch+=(Float_t)fhch->GetBinContent(ibin+1);
319 meanTOFch/=TOFCHANNELS;
320 AliDebug(1,Form(" Mean number of tracks/channel = %f ",meanTOFch));
322 canvasrndch->Print("rndch.gif");
325 sprintf(line, ".!tar -zcvf %s.tar.gz *.gif", GetName()) ;
326 gROOT->ProcessLine(line);
327 sprintf(line, ".!rm -fR *.gif");
328 gROOT->ProcessLine(line);
329 AliInfo(Form("*** TOF Calib Task: plots saved in %s.tar.gz...\n", GetName())) ;
332 //______________________________________________________________________________
333 void AliTOFCalibTask::ConnectInputData(const Option_t*)
335 // Initialization of branch container and histograms
337 // AliLog::SetClassDebugLevel("AliTOFCalibTask",1);
338 AliInfo(Form("*** Initialization of %s", GetName())) ;
341 fChain = dynamic_cast<TChain *>(GetInputData(0)) ;
343 AliError(Form("Input 0 for %s not found\n", GetName()));
347 // One should first check if the branch address was taken by some other task
348 char ** address = (char **)GetBranchAddress(0, "ESD");
350 fESD = (AliESDEvent*)(*address);
352 fESD = new AliESDEvent();
354 // fESD = (AliESDEvent*)fChain->GetTree()->GetUserInfo()->FindObject("AliESDEvent");
355 fESD->ReadFromTree(fChain) ;
361 //-----------------------------------------------------------------------
362 Bool_t AliTOFCalibTask::Notify()
364 // Initialisation of branch container and histograms
366 AliInfo(Form("*** We are in %s::Notify()", GetName())) ;
369 fChain = dynamic_cast<TChain *>(GetInputData(0)) ;
371 AliError(Form("Input 0 for %s not found\n", GetName()));
375 // One should first check if the branch address was taken by some other task
376 char ** address = (char **)GetBranchAddress(0, "ESD") ;
378 fESD = (AliESDEvent *)(*address) ;
380 fESD = new AliESDEvent();
381 // fESD = (AliESDEvent*)fChain->GetTree()->GetUserInfo()->FindObject("AliESDEvent");
382 fESD->ReadFromTree(fChain) ;
383 //SetBranchAddress(0,"ESD",&fESD);
389 //________________________________________________________________________
390 void AliTOFCalibTask::CreateOutputObjects()
395 //______________________________________________________________________________
396 void AliTOFCalibTask::Exec(Option_t * opt)
401 AliInfo(Form("*** Executing %s", GetName())) ;
403 //******* The loop over events -----------------------------------------------
405 // Processing of one event
406 Long64_t entry = fChain->GetReadEntry() ;
408 AliError("fESD is not connected to the input!") ;
412 if ( !((entry-1)%100) )
413 AliDebug(1,Form("%s ----> Processing event # %lld", (dynamic_cast<TChain *>(fChain))->GetFile()->GetName(), entry)) ;
415 // ************************ TOF *************************************
417 fMinTime=22E3; //ns; not used
418 Int_t ntrk = fESD->GetNumberOfTracks() ;
424 AliESDtrack * t = fESD->GetTrack(ntrk) ;
425 //selecting only good quality tracks
426 if (!Select(t)) continue;
428 Int_t ich = Int_t(t->GetTOFCalChannel());
430 AliDebug(2,Form(" ESD in channel %i, filling array %i",t->GetTOFCalChannel(),ich));
431 Float_t tot = t->GetTOFsignalToT();
432 Float_t time = t->GetTOFsignalRaw();
433 AliDebug(2,Form(" track # %i in schannel %i, time = %f \n",ntrk,ich,time));
434 Double_t expTime[10];
435 t->GetIntegratedTimes(expTime);
436 Float_t expTimePi = expTime[2]*1.E-3;
437 Float_t expTimeKa = expTime[3]*1.E-3;
438 Float_t expTimePr = expTime[4]*1.E-3;
439 if (findexarray[ich]==(Int_t)(CHENTRIES/NIDX)) {
440 AliInfo(Form("too many tracks in channel %i, not storing any more...",ich));
444 AliDebug(2,Form("tracks in channel %i = %i, storing... ",ich, findexarray[ich] ));
445 Int_t ientry=(findexarray[ich]-1)*NIDX;
446 fbigarray[ich][ientry+DELTAIDXTOT]=tot; //in ns
447 fbigarray[ich][ientry+DELTAIDXTIME]=time*1E-3; // in ns
448 fbigarray[ich][ientry+DELTAIDXEXTIMEPI]=expTimePi;
449 fbigarray[ich][ientry+DELTAIDXEXTIMEKA]=expTimeKa;
450 fbigarray[ich][ientry+DELTAIDXEXTIMEPR]=expTimePr;
451 fhToT->Fill(fbigarray[ich][ientry+DELTAIDXTOT]);
452 fhTime->Fill(fbigarray[ich][ientry+DELTAIDXTIME]);
453 fhExpTimePi->Fill(fbigarray[ich][ientry+DELTAIDXEXTIMEPI]);
454 fhExpTimeKa->Fill(fbigarray[ich][ientry+DELTAIDXEXTIMEKA]);
455 fhExpTimePr->Fill(fbigarray[ich][ientry+DELTAIDXEXTIMEPR]);
456 AliDebug(2, Form("track = %i, tot = %f, time = %f, and Exp time in TOF: pi = %f, K = %f, p = %f",itr, fbigarray[ich][ientry+DELTAIDXTOT], fbigarray[ich][ientry+DELTAIDXTIME], expTimePi,expTimeKa,expTimePr));
458 fnESDselected+=nselected;
460 PostData(0, fOutputContainer);
463 //_____________________________________________________________________________
464 void AliTOFCalibTask::Terminate(Option_t *)
466 // Processing when the event loop is ended
470 TH1::AddDirectory(0);
471 AliInfo("TOF Calib Task: End of events loop");
472 AliInfo(Form(" Number of analyzed ESD tracks: %i\n",fnESD));
473 AliInfo(Form(" Number of selected ESD tracks: %i\n",fnESDselected));
474 AliInfo(Form(" Number of ESD tracks with kTOFout: %i\n",fnESDkTOFout));
475 AliInfo(Form(" Number of ESD tracks with kTIME: %i\n",fnESDkTIME));
476 AliInfo(Form(" Number of ESD tracks with TRDcut: %i\n",fnESDTRDcut));
477 AliInfo(Form(" Number of ESD tracks with TIMEcut: %i\n",fnESDTIMEcut));
478 AliInfo(Form(" Number of ESD tracks with assTOFcl: %i\n",fnESDassTOFcl));
480 for (Int_t i = 0;i<TOFCHANNELS;i++){
481 Int_t size=findexarray[i]*NIDX;
482 AliDebug(2, Form(" entries %i in channel %i ",findexarray[i],i));
483 if (findexarray[i]<6) {
484 AliDebug(1, Form(" not enough statistics for combined PID for channel %i, putting all the tracks as if they were pions",i));
487 if (!CombPID(&fbigarray[i][0], size)) AliError("ERROR!!!!ERROR!!!");
492 // saving data in a tree
494 TDirectory *dir = gDirectory;
497 Bool_t isThere=kFALSE;
498 const char *dirname = "./";
499 TString filename= "TOFCalib.root";
501 if((gSystem->FindFile(dirname,filename))!=NULL){
506 AliInfo("File with tree for Calibration not there, creating it");
507 outFile = new TFile( "TOFCalib.root","RECREATE");
509 tree = new TTree("T", "Tree for TOF calibration");
510 Float_t p[CHENTRIESSMALL];
512 tree->Branch("nentries",&nentries,"nentries/I");
513 tree->Branch("TOFentries",p,"TOFentries[nentries]/F");
514 for (Int_t i=0;i<TOFCHANNELS;i++){
515 nentries=findexarray[i]*(NIDXSMALL); // when filling small array,
516 // only first 3 floats taken
518 for (Int_t j=0; j<findexarray[i];j++){
519 for (Int_t k=0; k<NIDXSMALL;k++){
520 Int_t index1= j*NIDXSMALL+k; // index in small array
521 Int_t index2=j*NIDX+k; // index in big array
522 p[index1]=fbigarray[i][index2];
527 tree->Write("",TObject::kOverwrite);
535 AliInfo("File with tree for Calibration already there, updating it");
536 outFile = new TFile( "TOFCalib.root","READ");
538 tree=(TTree*)outFile->Get("T");
539 Float_t p[CHENTRIESSMALL];
540 Float_t ptemp[MAXCHENTRIESSMALL];
544 tree->SetBranchAddress("nentries",&nentries);
545 tree->SetBranchAddress("TOFentries",p);
546 TFile * outFile1 = new TFile( "TOFCalib.root","RECREATE");
548 TTree *treeTemp = new TTree("T","Tree for TOF calibration");
549 treeTemp->Branch("nentries",&nentriestemp,"nentries/I");
550 treeTemp->Branch("TOFentries",ptemp,"TOFentries[nentries]/F");
551 for (Int_t i=0;i<TOFCHANNELS;i++){
554 if (nentries+findexarray[i]*(NIDXSMALL) > MAXCHENTRIESSMALL){
555 AliDebug(2, Form("findexarray[%i] = %i, nentries = %i",i,findexarray[i],nentries));
556 AliInfo(Form("Too many entries in channel %i, stopping at %i entries, no storing any more...",i,MAXCHENTRIESSMALL/NIDXSMALL));
557 findexarray[i]=(MAXCHENTRIESSMALL-nentries)/NIDXSMALL;
559 for (Int_t kk = 0;kk<nentries;kk++){
562 nentries+=findexarray[i]*(NIDXSMALL); // when filling small array,
563 // only first 3 floats taken
565 nentriestemp=nentries;
566 for (Int_t j=0; j<findexarray[i];j++){
567 for (Int_t k=0; k<NIDXSMALL;k++){
568 Int_t index1= j*NIDXSMALL+k; // index in small array
569 Int_t index2=j*NIDX+k; // index in big array
570 ptemp[index1+nentries1]=fbigarray[i][index2];
575 treeTemp->SetName("T");
576 treeTemp->SetTitle("Tree for TOF calibration");
578 treeTemp->Write("",TObject::kOverwrite);
582 Int_t calibrationStatus = 0;
583 // Int_t ch[2]={3,1003};
584 // calibrationStatus = Calibrate(2,ch,"save");
585 //calibrationStatus = Calibrate(3,4,"save");
586 //calibrationStatus = CalibrateFromProfile(3,"save");
587 // calibrationStatus = Calibrate(3,"save");
588 calibrationStatus = Calibrate("");
589 AliInfo(Form("Calibration Status = %i, bye.... \n",calibrationStatus));
592 //----------------------------------------------------------------------------
593 Int_t AliTOFCalibTask::Calibrate(Int_t ichmin, Int_t ichmax, Option_t *optionSave, Option_t *optionFit){
595 // calibrating summing more than one channels
596 // computing calibration parameters
598 // 0 -> everything was ok
599 // 1 -> no tree for calibration found
600 // 2 -> not enough statistics to perform calibration
601 // 3 -> problems with arrays
603 TH1::AddDirectory(0);
605 AliInfo(Form("*** Calibrating Histograms %s, summing more channels, from channel %i, to channel %i, storing Calib Pars in channel %i", GetName(),ichmin,ichmax,ichmin)) ;
606 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
607 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
608 const char *dirname = "./";
609 TString filename= "TOFCalib.root";
611 if((gSystem->FindFile(dirname,filename))==NULL){
612 AliInfo("No file with tree for calibration found! exiting....");
616 TFile *file = new TFile("TOFCalib.root","READ");
617 TTree *tree = (TTree*)file->Get("T");
618 Float_t p[MAXCHENTRIESSMALL];
620 tree->SetBranchAddress("nentries",&nentries);
621 tree->SetBranchAddress("TOFentries",p);
623 Float_t nentriesmean =0;
624 for (Int_t i=ichmin; i<ichmax; i++){
626 Int_t ntracks=nentries/3;
627 nentriesmean+=ntracks;
630 // nentriesmean/=(ichmax-ichmin);
631 if (nentriesmean < MEANENTRIES) {
632 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",nentriesmean));
636 //filling ToT and Time arrays
638 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
639 Float_t minToT = 0; // ns
640 Float_t maxToT = 4.88; // ns
641 TObjArray * arrayCal = new TObjArray(TOFCHANNELS);
643 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
644 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
645 Int_t ntracksTot = 0;
647 Double_t binsProfile[101]; // sized larger than necessary, the correct
648 // dim being set in the booking of the profile
651 for (Int_t i = ichmin;i<ichmax;i++){
653 ntracksTot+=nentries/3;
655 AliDebug(2,Form("channel %i, nentries = %i, ntracks = %i",i,nentries, ntracks));
656 for (Int_t j=0;j<ntracks;j++){
657 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
658 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
659 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
660 Float_t tot = p[idxexToT];
661 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
662 meantime+=p[idxexTime]-p[idxexExTime];
666 nusefulbins = FindBins(hToT,&binsProfile[0]);
667 meantime/=ntracksTot;
668 AliDebug(2, Form("meantime = %f",meantime));
670 for (Int_t j=1;j<=nusefulbins;j++) {
671 AliDebug(2,Form(" summing channels from %i to %i, nusefulbins = %i, bin %i = %f",ichmin,ichmax,nusefulbins,j,binsProfile[j]));
674 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
675 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
676 for (Int_t i=ichmin; i<ichmax; i++){
679 for (Int_t j=0;j<ntracks;j++){
680 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
681 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
682 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
683 Float_t tot = p[idxexToT];
684 Float_t time = p[idxexTime]-p[idxexExTime];
685 AliDebug (2, Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
686 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
687 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
690 hSlewingProf->Fit("pol5",optionFit,"",0,4);
691 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
693 for(Int_t kk=0;kk<6;kk++){
694 par[kk]=calibfunc->GetParameter(kk);
695 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
698 if(strstr(optionSave,"save")){
699 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
701 TString profName=Form("Profile%06i_%06i",ichmin,ichmax);
702 TString timeTotName=Form("TimeTot%06i_%06i",ichmin,ichmax);
703 TString totName=Form("Tot%06i_%06i",ichmin,ichmax);
704 TString deltaName=Form("Delta%06i_%06i",ichmin,ichmax);
705 hSlewingProf->Write(profName);
706 htimetot->Write(timeTotName);
707 hToT->Write(totName);
708 hdeltaTime->Write(deltaName);
726 AliTOFChannelTask * calChannel = new AliTOFChannelTask();
727 calChannel->SetSlewPar(par);
728 // saving parameters in chmin
729 arrayCal->AddAt(calChannel,ichmin);
730 TFile *filecalib = new TFile("outCalArray.root","RECREATE");
731 arrayCal->Write("array",TObject::kSingleKey);
741 //----------------------------------------------------------------------------
742 Int_t AliTOFCalibTask::Calibrate(Int_t i, Option_t *optionSave, Option_t *optionFit){
744 // computing calibration parameters for channel i
746 // 0 -> everything was ok
747 // 1 -> no tree for calibration found
748 // 2 -> not enough statistics to perform calibration
749 // 3 -> problems with arrays
751 TH1::AddDirectory(0);
753 AliInfo(Form("*** Calibrating Histograms (one channel) %s", GetName())) ;
754 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
755 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
756 const char *dirname = "./";
757 TString filename= "TOFCalib.root";
759 if((gSystem->FindFile(dirname,filename))==NULL){
760 AliInfo("No file with tree for calibration found! exiting....");
764 TFile *file = new TFile("TOFCalib.root","READ");
765 TTree *tree = (TTree*)file->Get("T");
766 Float_t p[MAXCHENTRIESSMALL];
768 tree->SetBranchAddress("nentries",&nentries);
769 tree->SetBranchAddress("TOFentries",p);
772 Int_t nentriesmean=nentries/3;
774 if (nentriesmean < MEANENTRIES) {
775 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",nentriesmean));
779 //filling ToT and Time arrays
781 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
782 Float_t minToT = 0; // ns
783 Float_t maxToT = 4.88; // ns
784 TObjArray * arrayCal = new TObjArray(TOFCHANNELS);
786 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
787 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
789 Double_t binsProfile[101]; // sized larger than necessary, the correct
790 // dim being set in the booking of the profile
794 AliDebug(2,Form("channel %i, nentries = %i, ntracks = %i",i ,nentries, ntracks));
795 for (Int_t j=0;j<ntracks;j++){
796 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
797 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
798 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
799 Float_t tot = p[idxexToT];
800 meantime+=p[idxexTime]-p[idxexExTime];
801 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
805 nusefulbins = FindBins(hToT,&binsProfile[0]);
807 AliDebug(2,Form("meantime = %f",meantime));
809 for (Int_t j=1;j<=nusefulbins;j++) {
810 AliDebug(2,Form(" channel %i, nusefulbins = %i, bin %i = %f",i,nusefulbins,j,binsProfile[j]));
813 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
814 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
817 for (Int_t j=0;j<ntracks;j++){
818 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
819 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
820 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
821 Float_t tot = p[idxexToT];
822 Float_t time = p[idxexTime]-p[idxexExTime];
823 AliDebug (2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
824 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
825 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
827 hSlewingProf->Fit("pol5",optionFit,"",0,4);
828 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
830 for(Int_t kk=0;kk<6;kk++){
831 par[kk]=calibfunc->GetParameter(kk);
832 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
839 if(strstr(optionSave,"save")){
840 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
842 TString profName=Form("Profile%06i",i);
843 TString timeTotName=Form("TimeTot%06i",i);
844 TString totName=Form("Tot%06i",i);
845 TString deltaName=Form("Delta%06i",i);
846 hSlewingProf->Write(profName);
847 htimetot->Write(timeTotName);
848 hToT->Write(totName);
849 hdeltaTime->Write(deltaName);
864 AliTOFChannelTask * calChannel = new AliTOFChannelTask();
865 calChannel->SetSlewPar(par);
866 arrayCal->AddAt(calChannel,i);
867 TFile *filecalib = new TFile("outCalArray.root","RECREATE");
868 arrayCal->Write("array",TObject::kSingleKey);
879 //----------------------------------------------------------------------------
880 Int_t AliTOFCalibTask::Calibrate(Int_t nch, Int_t *ch, Option_t *optionSave, Option_t *optionFit){
882 // calibrating an array of channels
883 // computing calibration parameters
885 // 0 -> everything was ok
886 // 1 -> no tree for calibration found
887 // 2 -> not enough statistics to perform calibration
888 // 3 -> problems with arrays
890 TH1::AddDirectory(0);
892 AliInfo(Form("*** Calibrating Histograms %s, number of channels = %i", GetName(),nch)) ;
893 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
894 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
895 for (Int_t ich=0; ich<nch; ich++){
897 AliInfo(Form("Calibrating channel = %i",i )) ;
899 const char *dirname = "./";
900 TString filename= "TOFCalib.root";
902 if((gSystem->FindFile(dirname,filename))==NULL){
903 AliInfo("No file with tree for calibration found! exiting....");
907 TFile *file = new TFile("TOFCalib.root","READ");
908 TTree *tree = (TTree*)file->Get("T");
909 Float_t p[MAXCHENTRIESSMALL];
911 tree->SetBranchAddress("nentries",&nentries);
912 tree->SetBranchAddress("TOFentries",p);
914 Float_t nentriesmean =0;
915 for (Int_t ich=0; ich<nch; ich++){
918 Int_t ntracks=nentries/3;
919 nentriesmean+=ntracks;
923 if (nentriesmean < MEANENTRIES) {
924 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",nentriesmean));
928 //filling ToT and Time arrays
930 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
931 Float_t minToT = 0; // ns
932 Float_t maxToT = 4.88; // ns
933 TObjArray * arrayCal = new TObjArray(TOFCHANNELS);
934 arrayCal->SetOwner();
935 TFile * fileProf=0x0;
936 if(strstr(optionSave,"save")){
937 fileProf = new TFile("TOFCalibSave.root","recreate");
939 for (Int_t ich=0; ich<nch; ich++) {
940 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
941 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
942 Double_t binsProfile[101]; // sized larger than necessary, the correct
943 // dim being set in the booking of the profile
944 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
945 Int_t ntracksTot = 0;
950 AliDebug(2,Form("Calibrating channel %i",i));
952 ntracksTot+=nentries/3;
954 if (ntracks < MEANENTRIES) {
955 AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %f), not calibrating channel and continuing.....",i,ntracks));
958 for (Int_t j=0;j<ntracks;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 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
964 meantime+=p[idxexTime]-p[idxexExTime];
968 nusefulbins = FindBins(hToT,&binsProfile[0]);
969 meantime/=ntracksTot;
970 for (Int_t j=1;j<=nusefulbins;j++) {
971 AliDebug(2,Form(" channel %i, nusefulbins = %i, bin %i = %f",i,nusefulbins,j,binsProfile[j]));
974 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
977 for (Int_t j=0;j<ntracks;j++){
978 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
979 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
980 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
981 Float_t tot = p[idxexToT];
982 Float_t time = p[idxexTime]-p[idxexExTime];
983 AliDebug(2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
984 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
985 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
988 hSlewingProf->Fit("pol5",optionFit,"",1,4);
989 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
991 for(Int_t kk=0;kk<6;kk++){
992 par[kk]=calibfunc->GetParameter(kk);
993 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
996 if(strstr(optionSave,"save") && fileProf){
997 TString profName=Form("Profile%06i",i);
998 TString timeTotName=Form("TimeTot%06i",i);
999 TString totName=Form("Tot%06i",i);
1000 TString deltaName=Form("Delta%06i",i);
1002 hSlewingProf->Write(profName);
1003 htimetot->Write(timeTotName);
1004 hToT->Write(totName);
1005 hdeltaTime->Write(deltaName);
1008 AliTOFChannelTask * calChannel = new AliTOFChannelTask();
1009 calChannel->SetSlewPar(par);
1010 arrayCal->AddAt(calChannel,i);
1013 delete hSlewingProf;
1021 if(strstr(optionSave,"save") && fileProf){
1029 TFile *filecalib = new TFile("outCalArray.root","RECREATE");
1030 arrayCal->Write("array",TObject::kSingleKey);
1040 //----------------------------------------------------------------------------
1041 Int_t AliTOFCalibTask::CalibrateFromProfile(Int_t i, Option_t *optionSave, Option_t *optionFit){
1043 // computing calibration parameters using the old profiling algo
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
1050 TH1::AddDirectory(0);
1052 TObjArray * arrayCal = new TObjArray(TOFCHANNELS);
1053 AliInfo(Form("*** Calibrating Histograms From Profile %s", GetName())) ;
1054 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1055 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1056 const char *dirname = "./";
1057 TString filename= "TOFCalib.root";
1059 if((gSystem->FindFile(dirname,filename))==NULL){
1060 AliInfo("No file with tree for calibration found! exiting....");
1064 TFile *file = new TFile("TOFCalib.root","READ");
1065 TTree *tree = (TTree*)file->Get("T");
1066 Float_t p[MAXCHENTRIESSMALL];
1068 tree->SetBranchAddress("nentries",&nentries);
1069 tree->SetBranchAddress("TOFentries",p);
1072 Int_t ntracks=nentries/3;
1074 if (ntracks < MEANENTRIES) {
1075 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracks));
1079 TH1F * hProf = new TH1F();
1081 hProf->Fit("pol5",optionFit,"",0,4);
1082 TF1 * calibfunc = (TF1*)hProf->GetFunction("pol5");
1084 for(Int_t kk=0;kk<6;kk++){
1085 par[kk]=calibfunc->GetParameter(kk);
1086 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1089 if(strstr(optionSave,"save")){
1090 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
1092 TString profName=Form("Profile%06i",i);
1093 hProf->Write(profName);
1104 AliTOFChannelTask * calChannel = new AliTOFChannelTask();
1105 calChannel->SetSlewPar(par);
1106 arrayCal->AddAt(calChannel,i);
1107 TFile *filecalib = new TFile("outCalArray.root","RECREATE");
1108 arrayCal->Write("array",TObject::kSingleKey);
1116 //----------------------------------------------------------------------------
1117 Int_t AliTOFCalibTask::Calibrate(Option_t *optionSave, Option_t *optionFit){
1119 // calibrating the whole TOF
1120 // computing calibration parameters
1122 // 0 -> everything was ok
1123 // 1 -> no tree for calibration found
1124 // 2 -> not enough statistics to perform calibration
1125 // 3 -> problems with arrays
1127 TH1::AddDirectory(0);
1129 AliInfo(Form("*** Calibrating Histograms %s, all channels", GetName())) ;
1130 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1131 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1132 const char *dirname = "./";
1133 TString filename= "TOFCalib.root";
1135 if((gSystem->FindFile(dirname,filename))==NULL){
1136 AliInfo("No file with tree for calibration found! exiting....");
1140 TFile * fileProf=0x0;
1141 if(strstr(optionSave,"save")){
1142 fileProf = new TFile("TOFCalibSave.root","recreate");
1144 TFile *file = new TFile("TOFCalib.root","READ");
1145 TTree *tree = (TTree*)file->Get("T");
1146 Float_t p[MAXCHENTRIESSMALL];
1148 tree->SetBranchAddress("nentries",&nentries);
1149 tree->SetBranchAddress("TOFentries",p);
1151 Float_t nentriesmean =0;
1152 for (Int_t i=0; i<TOFCHANNELS; i++){
1154 Int_t ntracks=nentries/3;
1155 nentriesmean+=ntracks;
1158 nentriesmean/=TOFCHANNELS;
1159 if (nentriesmean < MEANENTRIES) {
1160 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",nentriesmean));
1164 //filling ToT and Time arrays
1166 Int_t nbinToT = 100; // ToT bin width in Profile = 50.0 ps
1167 Float_t minToT = 0; // ns
1168 Float_t maxToT = 4.88;// ns
1169 TObjArray * arrayCal = new TObjArray(TOFCHANNELS);
1170 arrayCal->SetOwner();
1171 for (Int_t ii=0; ii<TOFCHANNELS; ii++) {
1172 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1173 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1174 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1175 if (ii%1000 == 0) AliDebug(1,Form("Calibrating channel %i ",ii));
1177 Int_t nusefulbins=0;
1178 Double_t binsProfile[101]; // sized larger than necessary, the correct
1179 // dim being set in the booking of the profile
1181 Int_t ntracks=nentries/3;
1182 if (ntracks < MEANENTRIES) {
1183 AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %f), not calibrating channel and continuing.....",i,ntracks));
1187 for (Int_t j=0;j<ntracks;j++){
1188 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1189 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1190 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1191 Float_t tot = p[idxexToT];
1192 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1193 meantime+=p[idxexTime]-p[idxexExTime];
1196 nusefulbins = FindBins(hToT,&binsProfile[0]);
1198 for (Int_t j=0;j<nusefulbins;j++) {
1199 AliDebug(2,Form(" channel %i, usefulbin = %i, low edge = %f",i,j,binsProfile[j]));
1201 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1202 for (Int_t j=0;j<ntracks;j++){
1203 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1204 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1205 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1206 Float_t tot = p[idxexToT];
1207 Float_t time = p[idxexTime]-p[idxexExTime];
1208 AliDebug (2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1209 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1210 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1213 // hSlewingProf->Fit("pol5",optionFit,"",1,4);
1214 //TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1216 for(Int_t kk=0;kk<6;kk++){
1217 // par[kk]=calibfunc->GetParameter(kk);
1219 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1222 if(strstr(optionSave,"save") && fileProf){
1223 TString profName=Form("Profile%06i",ii);
1224 TString timeTotName=Form("TimeTot%06i",ii);
1225 TString totName=Form("Tot%06i",ii);
1226 TString deltaName=Form("Delta%06i",ii);
1228 hSlewingProf->Write(profName);
1229 htimetot->Write(timeTotName);
1230 hToT->Write(totName);
1231 hdeltaTime->Write(deltaName);
1233 AliTOFChannelTask * calChannel = new AliTOFChannelTask();
1234 calChannel->SetSlewPar(par);
1235 arrayCal->AddAt(calChannel,ii);
1239 delete hSlewingProf;
1247 if(strstr(optionSave,"save")){
1256 TFile *filecalib = new TFile("outCalArray.root","RECREATE");
1257 arrayCal->Write("array", TObject::kSingleKey);
1268 //_____________________________________________________________________________
1270 Bool_t AliTOFCalibTask::Select(AliESDtrack *t){
1272 // selecting good quality tracks
1273 //track selection: reconstrution to TOF:
1274 if ((t->GetStatus()&AliESDtrack::kTOFout)==0) {
1278 //IsStartedTimeIntegral
1279 if ((t->GetStatus()&AliESDtrack::kTIME)==0) {
1283 if (t->GetStatus() & AliESDtrack::kTRDbackup) {
1284 Float_t xout= t->GetOuterParam()->GetX();
1285 if (xout<364.25 && xout > 300.) return 0;
1288 Double_t time=t->GetTOFsignal();
1289 time*=1.E-3; // tof given in nanoseconds
1290 if(time >= fMinTime){
1295 Double_t mom=t->GetP();
1296 if (!(mom<=UPPERMOMBOUND && mom>=LOWERMOMBOUND)){
1297 // return 0; // skipping momentum cut
1300 UInt_t assignedTOFcluster=t->GetTOFcluster();//index of the assigned TOF cluster, >0 ?
1301 if(assignedTOFcluster==0){ // not matched
1307 //_____________________________________________________________________________
1309 Bool_t AliTOFCalibTask::CombPID(Float_t *smallarray, Int_t size){
1311 //track Combinatorial PID for calibration
1313 //cout << " In comb PID " << endl;
1315 const Int_t kntracksinset=6;
1316 if (kntracksinset != 6) {
1317 AliDebug(1,"Number of tracks in set smaller than expected one, identifying every particle as if it was a pion!");
1320 Float_t exptof[kntracksinset][3];
1321 Int_t assparticle[kntracksinset];
1322 Float_t timeofflight[kntracksinset];
1323 Float_t texp[kntracksinset];
1324 Float_t timezero[kntracksinset];
1325 Float_t weightedtimezero[kntracksinset];
1326 Float_t besttimezero[kntracksinset];
1327 Float_t bestchisquare[kntracksinset];
1328 Float_t bestweightedtimezero[kntracksinset];
1330 for (Int_t i=0;i<kntracksinset;i++){
1335 weightedtimezero[i]=0;
1338 bestweightedtimezero[i]=0;
1341 Int_t nset= (Int_t)(size/kntracksinset/NIDX);
1342 for (Int_t i=0; i< nset; i++) {
1343 for (Int_t j=0; j<kntracksinset; j++) {
1344 Int_t idxtime = ((kntracksinset*i+j)*NIDX)+DELTAIDXTIME;
1345 Int_t idxextimePi = ((kntracksinset*i+j)*NIDX)+DELTAIDXEXTIMEPI;
1346 Int_t idxextimeKa = ((kntracksinset*i+j)*NIDX)+DELTAIDXEXTIMEKA;
1347 Int_t idxextimePr = ((kntracksinset*i+j)*NIDX)+DELTAIDXEXTIMEPR;
1348 Double_t time=smallarray[idxtime]; // TOF time in ns
1349 timeofflight[j]=time+t0offset;
1350 exptof[j][0]=smallarray[idxextimePi];
1351 exptof[j][1]=smallarray[idxextimeKa];
1352 exptof[j][2]=smallarray[idxextimePr];
1353 AliDebug(2,Form("j = %i, Time = %f, and Exp time in PID: pi = %f, K = %f, p = %f",j,timeofflight[j],exptof[j][0],exptof[j][1],exptof[j][2]));
1355 Float_t t0best=999.;
1356 Float_t et0best=999.;
1357 Float_t chisquarebest=999.;
1358 for (Int_t i1=0; i1<3;i1++) {
1359 texp[0]=exptof[0][i1];
1360 for (Int_t i2=0; i2<3;i2++) {
1361 texp[1]=exptof[1][i2];
1362 for (Int_t i3=0; i3<3;i3++) {
1363 texp[2]=exptof[2][i3];
1364 for (Int_t i4=0; i4<3;i4++) {
1365 texp[3]=exptof[3][i4];
1366 for (Int_t i5=0; i5<3;i5++) {
1367 texp[4]=exptof[4][i5];
1368 for (Int_t i6=0; i6<3;i6++) {
1369 texp[5]=exptof[5][i6];
1371 Float_t sumAllweights=0.;
1372 Float_t meantzero=0.;
1373 Float_t emeantzero=0.;
1375 for (Int_t itz=0; itz<kntracksinset;itz++) {
1376 timezero[itz]=texp[itz]-timeofflight[itz];
1377 weightedtimezero[itz]=timezero[itz]/TRACKERROR;
1378 sumAllweights+=1./TRACKERROR;
1379 meantzero+=weightedtimezero[itz];
1381 } // end loop for (Int_t itz=0; itz<15;itz++)
1383 meantzero=meantzero/sumAllweights; // it is given in [ns]
1384 emeantzero=sqrt(1./sumAllweights); // it is given in [ns]
1386 // calculate chisquare
1388 Float_t chisquare=0.;
1389 for (Int_t icsq=0; icsq<kntracksinset;icsq++) {
1390 chisquare+=(timezero[icsq]-meantzero)*(timezero[icsq]-meantzero)/TRACKERROR;
1391 } // end loop for (Int_t icsq=0; icsq<15;icsq++)
1401 if(chisquare<=chisquarebest && ((Float_t) npion/ ((Float_t) kntracksinset)>0.3)){
1402 for(Int_t iqsq = 0; iqsq<kntracksinset; iqsq++) {
1403 besttimezero[iqsq]=timezero[iqsq];
1404 bestweightedtimezero[iqsq]=weightedtimezero[iqsq];
1405 bestchisquare[iqsq]=(timezero[iqsq]-meantzero)*(timezero[iqsq]-meantzero)/TRACKERROR;
1415 chisquarebest=chisquare;
1418 } // close if(dummychisquare<=chisquare)
1426 Float_t confLevel=999;
1427 if(chisquarebest<999.){
1428 Double_t dblechisquare=(Double_t)chisquarebest;
1429 confLevel=(Float_t)TMath::Prob(dblechisquare,kntracksinset-1);
1431 // assume they are all pions for fake sets
1432 if(confLevel<0.01 || confLevel==999. ){
1433 for (Int_t itrk=0; itrk<kntracksinset; itrk++)assparticle[itrk]=0;
1436 AliDebug(2,Form(" Best Assignment, selection %i %i %i %i %i %i ",assparticle[0],assparticle[1],assparticle[2],assparticle[3],assparticle[4],assparticle[5]));
1438 for (Int_t kk=0;kk<kntracksinset;kk++){
1439 Int_t idxextimePi = ((kntracksinset*i+kk)*NIDX)+DELTAIDXEXTIMEPI;
1440 Int_t idxextimeKa = ((kntracksinset*i+kk)*NIDX)+DELTAIDXEXTIMEKA;
1441 Int_t idxextimePr = ((kntracksinset*i+kk)*NIDX)+DELTAIDXEXTIMEPR;
1442 // storing in third slot of smallarray the assigned expected time
1443 fhPID->Fill(assparticle[kk]);
1444 // assparticle[kk]=0; //assuming all particles are pions
1445 if (assparticle[kk]==0){ //assigned to be a Pi
1446 smallarray[idxextimeKa]=-1;
1447 smallarray[idxextimePr]=-1;
1449 else if (assparticle[kk]==1){ //assigned to be a Ka
1450 smallarray[idxextimePi]=smallarray[idxextimeKa];
1451 smallarray[idxextimeKa]=-1;
1452 smallarray[idxextimePr]=-1;
1454 else if (assparticle[kk]==2){ //assigned to be a Pr
1455 smallarray[idxextimePi]=smallarray[idxextimePr];
1456 smallarray[idxextimeKa]=-1;
1457 smallarray[idxextimePr]=-1;
1463 //-----------------------------------------------------------------------
1464 TH1F* AliTOFCalibTask::Profile(Int_t ich)
1468 TFile *file = new TFile("TOFCalib.root","READ");
1469 TTree *tree = (TTree*)file->Get("T");
1470 Float_t p[MAXCHENTRIESSMALL];
1472 tree->SetBranchAddress("nentries",&nentries);
1473 tree->SetBranchAddress("TOFentries",p);
1475 //Prepare histograms for Slewing Correction
1476 const Int_t knbinToT = 100;
1477 Int_t nbinTime = 200;
1478 Float_t minTime = -5.5; //ns
1479 Float_t maxTime = 5.5; //ns
1480 Float_t minToT = 0; //ns
1481 Float_t maxToT = 5.; //ns
1482 Float_t deltaToT = (maxToT-minToT)/knbinToT;
1483 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];
1484 Int_t n[knbinToT+1], nentrx[knbinToT+1];
1485 Double_t sigmaToT[knbinToT+1];
1486 for (Int_t i = 0; i < knbinToT+1 ; i++){
1504 TH2F* hSlewing = new TH2F("hSlewing", "hSlewing", knbinToT, minToT, maxToT, nbinTime, minTime, maxTime);
1506 TH1F *histo = new TH1F("histo", "1D Time vs ToT", knbinToT, minToT, maxToT);
1507 tree->GetEntry(ich);
1509 for (Int_t j=0;j<ntracks;j++){
1510 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1511 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1512 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1513 Float_t tot = p[idxexToT];
1514 Float_t time = p[idxexTime]-p[idxexExTime];
1515 Int_t nx = (Int_t)((tot-minToT)/deltaToT)+1;
1516 if ((tot != 0) && ( time!= 0)){
1518 vTime2[nx]+=time*time;
1522 hSlewing->Fill(tot,time);
1525 Int_t nbinsToT=hSlewing->GetNbinsX();
1526 if (nbinsToT != knbinToT) {
1527 AliError("Profile :: incompatible numbers of bins");
1532 for (Int_t i=1;i<=nbinsToT;i++){
1534 n[usefulBins]+=nentrx[i];
1535 if (n[usefulBins]==0 && i == nbinsToT) {
1538 meanTime[usefulBins]+=vTime[i];
1539 meanTime2[usefulBins]+=vTime2[i];
1540 meanToT[usefulBins]+=vToT[i];
1541 meanToT2[usefulBins]+=vToT2[i];
1542 if (n[usefulBins]<10 && i!=nbinsToT) continue;
1543 mTime[usefulBins]=meanTime[usefulBins]/n[usefulBins];
1544 mToT[usefulBins]=meanToT[usefulBins]/n[usefulBins];
1545 sigmaTime[usefulBins]=TMath::Sqrt(1./n[usefulBins]/n[usefulBins]
1546 *(meanTime2[usefulBins]-meanTime[usefulBins]
1547 *meanTime[usefulBins]/n[usefulBins]));
1548 if ((1./n[usefulBins]/n[usefulBins]
1549 *(meanToT2[usefulBins]-meanToT[usefulBins]
1550 *meanToT[usefulBins]/n[usefulBins]))< 0) {
1551 AliError(" too small radical" );
1552 sigmaToT[usefulBins]=0;
1555 sigmaToT[usefulBins]=TMath::Sqrt(1./n[usefulBins]/n[usefulBins]
1556 *(meanToT2[usefulBins]-meanToT[usefulBins]
1557 *meanToT[usefulBins]/n[usefulBins]));
1562 for (Int_t i=0;i<usefulBins;i++){
1563 Int_t binN = (Int_t)((mToT[i]-minToT)/deltaToT)+1;
1564 histo->Fill(mToT[i],mTime[i]);
1565 histo->SetBinError(binN,sigmaTime[i]);
1574 //----------------------------------------------------------------------------
1575 Int_t AliTOFCalibTask::FindBins(TH1F* h, Double_t *binsProfile) const{
1577 // to determine the bins for ToT histo
1581 Int_t nbin = h->GetNbinsX();
1582 Int_t nentries = (Int_t)h->GetEntries();
1583 Float_t max = h->GetBinLowEdge(nbin);
1584 Int_t nusefulbins=0;
1586 // setting maxvalue of entries per bin
1587 if (nentries <= 60) maxcont = 2;
1588 else if (nentries <= 100) maxcont = 5;
1589 else if (nentries <= 500) maxcont = 10;
1591 for (Int_t j=1;j<=nbin;j++) {
1592 cont += (Int_t)h->GetBinContent(j);
1596 binsProfile[nusefulbins-1]=h->GetBinLowEdge(startBin);
1605 binsProfile[nusefulbins-1]=h->GetBinLowEdge(startBin);
1606 binsProfile[nusefulbins]=max;
1609 binsProfile[nusefulbins]=h->GetBinLowEdge(startBin);