AliPhysics  a0db429 (a0db429)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
AliAnalysisTaskEMCALTimeCalib.cxx
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  * *
4  * Author: The ALICE Off-line Project. *
5  * Contributors are mentioned in the code where appropriate. *
6  * *
7  * Permission to use, copy, modify and distribute this software and its *
8  * documentation strictly for non-commercial purposes hereby granted *
9  * without fee, provided that the above copyright notice appears in all *
10  * copies and that both the copyright notice and this permission notice *
11  * appear in the supporting documentation. The authors make no claims *
12  * about the suitability of this software for any purpose. It is *
13  * provided "as is" without express or implied warranty. *
14  **************************************************************************/
15 
16 #include <TChain.h>
17 #include <TTree.h>
18 #include <TFile.h>
19 #include <TH1F.h>
20 #include <TH1D.h>
21 #include <TH2D.h>
22 #include <TH2F.h>
23 #include <TList.h>
24 #include <TCanvas.h>
25 #include <TGeoManager.h>
26 #include <TRefArray.h>
27 
28 #include "AliLog.h"
29 #include "AliAnalysisTask.h"
30 #include "AliAnalysisManager.h"
31 #include "AliESDEvent.h"
32 #include "AliAODEvent.h"
33 #include "AliVEvent.h"
34 #include "AliESDInputHandler.h"
35 #include "AliAODInputHandler.h"
36 #include "AliESDpid.h"
37 #include "AliTOFcalib.h"
38 #include "AliCDBManager.h"
39 #include "AliRunTag.h"
40 
41 #include "AliTOFT0maker.h"
42 #include "AliVCluster.h"
43 #include "AliESDCaloCluster.h"
44 #include "AliVCaloCells.h"
45 #include "AliESDCaloCells.h"
46 #include "AliAODCaloCluster.h"
47 #include "AliAODCaloCells.h"
48 #include "AliEMCALGeometry.h"
49 
51 
55 
56 using std::cout;
57 using std::endl;
58 
59 //________________________________________________________________________
62 : AliAnalysisTaskSE(name),
63  fRunNumber(-1),
64  fTOFmaker(0),
65  fOutputList(0x0),
66  fgeom(0),
67  fGeometryName(),
68  fMinClusterEnergy(0),
69  fMaxClusterEnergy(0),
70  fMinNcells(0),
71  fMaxNcells(0),
72  fMinLambda0(0),
73  fMaxLambda0(0),
74  fMinLambda0LG(0),
75  fMaxLambda0LG(0),
76  fMaxRtrack(0),
77  fMinCellEnergy(0),
78  fReferenceFileName(),
79  fReferenceRunByRunFileName(),
80  fPileupFromSPD(kFALSE),
81  fMinTime(0),
82  fMaxTime(0),
83  fRawTimeNbins (0),
84  fRawTimeMin (0),
85  fRawTimeMax (0),
86  fPassTimeNbins(0),
87  fPassTimeMin (0),
88  fPassTimeMax (0),
89  fEnergyNbins (0),
90  fEnergyMin(0),
91  fEnergyMax(0),
92  fFineNbins(0),
93  fFineTmin(0),
94  fFineTmax(0),
95  fReferenceFile(0),
96  fhcalcEvtTime(0),
97  fhEvtTimeHeader(0),
98  fhEvtTimeDiff(0),
99  fhEventType(0),
100  fhTOFT0vsEventNumber(0),
101  fhTcellvsTOFT0(0),
102  fhTcellvsTOFT0HD(0),
103  fhTcellvsSM(0),
104  fhEneVsAbsIdHG(0),
105  fhEneVsAbsIdLG(0),
106  fhTimeVsBC(0),
107  fhTimeSumSq(),
108  fhTimeEnt(),
109  fhTimeSum(),
110  fhTimeLGSumSq(),
111  fhTimeLGEnt(),
112  fhTimeLGSum(),
113  fhAllAverageBC(),
114  fhAllAverageLGBC(),
115  fhRefRuns(0),
116  fhTimeDsup(),
117  fhTimeDsupBC(),
118  fhRawTimeVsIdBC(),
119  fhRawTimeSumBC(),
120  fhRawTimeEntriesBC(),
121  fhRawTimeSumSqBC(),
122  fhRawTimeVsIdLGBC(),
123  fhRawTimeSumLGBC(),
124  fhRawTimeEntriesLGBC(),
125  fhRawTimeSumSqLGBC()
126 
127 {
128  for(Int_t i = 0; i < kNBCmask; i++)
129  {
130  fhAllAverageBC[i]=0;
131  fhAllAverageLGBC[i]=0;
132 
133  fhTimeSumSq[i]=0;
134  fhTimeEnt[i]=0;
135  fhTimeSum[i]=0;
136 
137  fhTimeLGSumSq[i]=0;
138  fhTimeLGEnt[i]=0;
139  fhTimeLGSum[i]=0;
140 
141  fhRawTimeVsIdBC[i]=0;
142  fhRawTimeSumBC[i]=0;
143  fhRawTimeEntriesBC[i]=0;
144  fhRawTimeSumSqBC[i]=0;
145 
146  fhRawTimeVsIdLGBC[i]=0;
147  fhRawTimeSumLGBC[i]=0;
149  fhRawTimeSumSqLGBC[i]=0;
150  }
151 
152  //set default cuts for calibration and geometry name
153  SetDefaultCuts();
154 
155  //T0 TOF time
157 
158  // Define input and output slots here
159  // Input slot #0 works with a TChain
160  DefineInput(0, TChain::Class());
161 
162  // Output slot #0 id reserved by the base class for AOD
163  // Output slot #1 writes into a TH1 container
164  DefineOutput(1, TList::Class());
165 
166 } // End ctor
167 
168 //_____________________________________________________________________
174 //void AliAnalysisTaskEMCALTimeCalib::LocalInit()
175 //{
176 // AliDebug(1,"AliAnalysisTaskEMCALTimeCalib::LocalInit()");
177 //}
178 
180 //_____________________________________________________________________
182 {
183  if(fReferenceFileName.Length()!=0){
184  TFile *myFile = TFile::Open(fReferenceFileName.Data());
185  AliInfo(Form("Reference file: %s, pointer %p",fReferenceFileName.Data(),myFile));
186  if(myFile==0x0) {
187  AliFatal("*** NO REFERENCE FILE");
188  } else {
189  AliDebug(1,"*** OK TFILE");
190  // connect ref run here
191  for(Int_t i = 0; i < kNBCmask; i++)
192  {
193  fhAllAverageBC[i]=(TH1F*) myFile->Get(Form("hAllTimeAvBC%d",i));
194  if(fhAllAverageBC[i]==0x0) AliFatal(Form("Reference histogram for BC%d does not exist",i));
195  if(fhAllAverageBC[i]->GetEntries()==0)AliWarning(Form("fhAllAverageLGBC[%d]->GetEntries() = 0",i));
196  fhAllAverageLGBC[i]=(TH1F*) myFile->Get(Form("hAllTimeAvLGBC%d",i));
197  if(fhAllAverageLGBC[i]==0x0) AliFatal(Form("Reference LG histogram for BC%d does not exist",i));
198  if(fhAllAverageLGBC[i]->GetEntries()==0)AliFatal(Form("fhAllAverageLGBC[%d]->GetEntries() = 0",i));
199  }
200 
201  AliDebug(1,Form("hAllAverage entries BC0 %d", (Int_t)fhAllAverageBC[0]->GetEntries() ));
202  AliDebug(1,Form("hAllAverage entries BC2 %d",(Int_t)fhAllAverageBC[2]->GetEntries() ));
203  AliDebug(1,Form("hAllAverageLG entries BC0 %d", (Int_t)fhAllAverageLGBC[0]->GetEntries() ));
204  AliDebug(1,Form("hAllAverageLG entries BC2 %d",(Int_t)fhAllAverageLGBC[2]->GetEntries() ));
205 
206  }
207  } else { //end of reference file is provided
208  AliFatal("You require to load reference histos from file but FILENAME is not provided");
209  }
210 } // End of AliAnalysisTaskEMCALTimeCalib::LoadReferenceHistos()
211 
214 //_____________________________________________________________________
216 {
217  // connect ref run here
218 
219  if(fReferenceRunByRunFileName.Length()!=0){
220  TFile *fReferenceFile = TFile::Open(fReferenceRunByRunFileName.Data());
221  AliInfo(Form("Reference R-b-R file: %s, pointer %p",fReferenceRunByRunFileName.Data(),fReferenceFile));
222  if(fReferenceFile==0x0) {
223  AliFatal("*** NO REFERENCE R-B-R FILE");
224  } else {
225  AliDebug(1,"*** OK TFILE");
226 
227  //AliInfo(Form("runnumber in LoadReferenceRunByRunHistos() %d, %d, InputEvent %p",fRunNumber,InputEvent()->GetRunNumber(),InputEvent()));
228  AliInfo(Form("fReferenceFile in LoadReferenceRunByRunHistos() %p",fReferenceFile));
229  //fReferenceFile->ls();
230  fhRefRuns=(TH1C*) fReferenceFile->Get(Form("h%d",fRunNumber));
231  //AliInfo(Form("Pointer to reference histogram %p",fhRefRuns));
232  if(fhRefRuns==0x0) {
233  fhRefRuns=(TH1C*) fReferenceFile->Get("h0");//Default values
234  AliError(Form("Reference histogram for run %d does not exist. Use Default",fRunNumber));
235  //AliFatal(Form("Reference histogram for run %d does not exist",fRunNumber));
236  }
237  if(fhRefRuns==0x0) AliFatal(Form("Default reference histogram does not exist. Run %d.",fRunNumber));
238  if(fhRefRuns->GetEntries()==0)AliWarning("fhRefRuns->GetEntries() = 0");
239  AliDebug(1,Form("hRefRuns entries %d", (Int_t)fhRefRuns->GetEntries() ));
240  }
241  } else { //end of reference file is provided
242  AliFatal("You require to load reference run-by-run histos from file but FILENAME is not provided");
243  }
244 
245 
246 
247 } // End of AliAnalysisTaskEMCALTimeCalib::LoadReferenceRunByRunHistos()
248 
249 //_____________________________________________________________________
253 {
254  AliDebug(1,"AnalysisTaskEMCalTimeCalib::NotifyRun()");
255  AliDebug(2,Form("Notify(): EMCal geometry: fgeom = %p, fGeometryName=%s\n ",fgeom,fGeometryName.Data()));
256 
257  if (!InputEvent())
258  {
259  AliFatal("ERROR: InputEvent not set");
260  return;
261  }
262  else AliDebug(1,"Good, InputEvent set");
263 
264  // AliInfo(Form("NotifyRun, fCurrentRunnumber %d",fCurrentRunNumber));
265  fRunNumber = InputEvent()->GetRunNumber();
266  AliDebug(1,Form("RunNumber %d", fRunNumber));
267 
268  // Init EMCAL geometry
269  if (!fgeom) SetEMCalGeometry();
270  //Init EMCAL geometry done
271 
272  if(fReferenceRunByRunFileName.Length()!=0)
274 
275  return;
276 }
277 
278 //_____________________________________________________________________
281 {
282  AliDebug(1,"AliAnalysisTaskEMCALTimeCalib::SetEMCalGeometry()");
283  if(fGeometryName.Length()==0){
284  fgeom=AliEMCALGeometry::GetInstanceFromRunNumber(fRunNumber);
285  AliInfo(Form("Get EMCAL geometry name <%s> for run %d",fgeom->GetName(),fRunNumber));
286  } else {
287  fgeom = AliEMCALGeometry::GetInstance(fGeometryName.Data());
288  AliInfo(Form("Set EMCAL geometry name to <%s>",fGeometryName.Data()));
289  }
290 
291  if (!fgeom){
292  AliWarning("Make sure the EMCal geometry is set properly !");
293  } else {
294  AliDebug(1,Form("EMCal geometry properly set: fGeom = %p, fGeometryName=%s",fgeom,fGeometryName.Data()));
295  }
296 
297  return kTRUE;
298 }
299 
300 //_____________________________________________________________________
303 {
304  //method under development
305  AliInfo(Form("<D> -- Run # = %d", fRunNumber));
306  AliInfo("prepare TOFT0maker!!");
307  //cout<<"Run "<< fRunNumber<<" in TOFT0maker"<<endl;
308 
309 
310  AliCDBManager * cdb = AliCDBManager::Instance();
311  cdb->SetDefaultStorage("raw://");
312  cdb->SetRun(fRunNumber);
313 
314  AliESDpid *extPID=new AliESDpid();
315 
316  // Wonder if some have to be declared as private variables??
317  // AliESDpid *extPID = new AliESDpid();
318  // AliTOFcalib * tofCalib = new AliTOFcalib();
319  // tofCalib->SetCalibrateTOFsignal(kTRUE);
320  // tofCalib->Init();
321 
322  fTOFmaker = new AliTOFT0maker(extPID);
323  fTOFmaker->SetTimeResolution(115.0); // if you want set the TOF res
324  // fTOFmaker = new AliTOFT0maker(extPID,tofCalib);
325  // fTOFmaker->SetTimeResolution(130.0);
326 
327  //cout<<"extPID "<<extPID<<" fTOFmaker "<<fTOFmaker<<endl;
328 
329 }// End PrepareTOFT0maker
330 
331 //________________________________________________________________________
335 {
336  AliDebug(1,"AliAnalysisTaskEMCALTimeCalib::UserCreateOutputObjects()");
337 
338  const Int_t nChannels = 17664;
339  //book histograms
340  fhcalcEvtTime = new TH1F("fhcalcEvtTime","calculated event time from T0",fFineNbins, fFineNbins,fFineTmax);
341  fhcalcEvtTime->GetXaxis()->SetTitle("T ");
342  fhcalcEvtTime->GetYaxis()->SetTitle("Counts (a.u.)");
343 
344  fhEvtTimeHeader = new TH1F("fhEvtTimeHeader","event time from header",fFineNbins, fFineNbins,fFineTmax);
345  fhEvtTimeHeader->GetXaxis()->SetTitle("T ");
346  fhEvtTimeHeader->GetYaxis()->SetTitle("Counts (a.u.)");
347 
348  fhEvtTimeDiff = new TH1F("fhEvtTimeDiff","event time difference",fFineNbins, fFineNbins,fFineTmax);
349  fhEvtTimeDiff->GetXaxis()->SetTitle("#Delta T ");
350  fhEvtTimeDiff->GetYaxis()->SetTitle("Counts (a.u.)");
351 
352  fhEventType = new TH1F("fhEventType","event type",10, 0.,10.);
353  fhEventType ->GetXaxis()->SetTitle("Type ");
354  fhEventType ->GetYaxis()->SetTitle("Counts (a.u.)");
355  fhTcellvsTOFT0 = new TH2F("hTcellvsTOFT0", " T_cell vs TOFT0", 500,-600.0,+400.0,fRawTimeNbins,fRawTimeMin,fRawTimeMax);
356  fhTcellvsTOFT0HD = new TH2F("hTcellvsTOFT0HD", " T_cell vs TOFT0,HighEnergy", 500,-600.0,+400.0,4*fRawTimeNbins,fRawTimeMin,fRawTimeMax);
357  fhTcellvsSM = new TH2F("hTcellvsSM", " T_cell vs SM", (Int_t)kNSM,0,(Double_t)kNSM,(Int_t)(fRawTimeNbins/2),fRawTimeMin,fRawTimeMax);
358  fhEneVsAbsIdHG = new TH2F("fhEneVsAbsIdHG", "energy vs ID for HG",1000,0,18000,200,0,10);
359  fhEneVsAbsIdLG = new TH2F("fhEneVsAbsIdLG", "energy vs ID for LG",1000,0,18000,200,0,40);
360 
361  for (Int_t i = 0; i < kNBCmask ; i++)
362  {
363  //already after correction
364  //high gain
365  fhTimeSumSq[i] = new TH1F(Form("hTimeSumSq%d", i),
366  Form("cell Sum Square time HG, BC %d ", i),
367  nChannels,0.,(Double_t)nChannels);
368  fhTimeSumSq[i]->SetYTitle("Sum Sq Time ");
369  fhTimeSumSq[i]->SetXTitle("AbsId");
370 
371  fhTimeSum[i] = new TH1F(Form("hTimeSum%d", i),
372  Form("cell Sum time HG, BC %d ", i),
373  nChannels,0.,(Double_t)nChannels);
374  fhTimeSum[i]->SetYTitle("Sum Time ");
375  fhTimeSum[i]->SetXTitle("AbsId");
376 
377  fhTimeEnt[i] = new TH1F(Form("hTimeEnt%d", i),
378  Form("cell Entries HG, BC %d ", i),
379  nChannels,0.,(Double_t)nChannels);
380  fhTimeEnt[i]->SetYTitle("Entries for Time ");
381  fhTimeEnt[i]->SetXTitle("AbsId");
382 
383  //low gain
384  fhTimeLGSumSq[i] = new TH1F(Form("hTimeLGSumSq%d", i),
385  Form("cell Sum Square time LG, BC %d ", i),
386  nChannels,0.,(Double_t)nChannels);
387  fhTimeLGSumSq[i]->SetYTitle("Sum Sq Time ");
388  fhTimeLGSumSq[i]->SetXTitle("AbsId");
389 
390  fhTimeLGSum[i] = new TH1F(Form("hTimeLGSum%d", i),
391  Form("cell Sum time LG, BC %d ", i),
392  nChannels,0.,(Double_t)nChannels);
393  fhTimeLGSum[i]->SetYTitle("Sum Time ");
394  fhTimeLGSum[i]->SetXTitle("AbsId");
395 
396  fhTimeLGEnt[i] = new TH1F(Form("hTimeLGEnt%d", i),
397  Form("cell Entries LG, BC %d ", i),
398  nChannels,0.,(Double_t)nChannels);
399  fhTimeLGEnt[i]->SetYTitle("Entries for Time ");
400  fhTimeLGEnt[i]->SetXTitle("AbsId");
401 
402  //raw time histograms
403  //high gain
404  fhRawTimeVsIdBC[i] = new TH2F(Form("RawTimeVsIdBC%d", i),
405  Form("cell raw time vs ID for high gain BC %d ", i),
406  nChannels,0.,(Double_t)nChannels,fRawTimeNbins,fRawTimeMin,fRawTimeMax);
407  fhRawTimeVsIdBC[i]->SetXTitle("AbsId");
408  fhRawTimeVsIdBC[i]->SetYTitle("Time");
409 
410  fhRawTimeSumBC[i] = new TH1F(Form("RawTimeSumBC%d", i),
411  Form("sum of cell raw time for high gain BC %d ", i),
412  nChannels,0.,(Double_t)nChannels);
413  fhRawTimeSumBC[i]->SetXTitle("AbsId");
414  fhRawTimeSumBC[i]->SetYTitle("Sum Time");
415 
416  fhRawTimeEntriesBC[i] = new TH1F(Form("RawTimeEntriesBC%d", i),
417  Form("No. entries of cells raw time for high gain BC %d ", i),
418  nChannels,0.,(Double_t)nChannels);
419  fhRawTimeEntriesBC[i]->SetXTitle("AbsId");
420  fhRawTimeEntriesBC[i]->SetYTitle("Entries for Time ");
421 
422  fhRawTimeSumSqBC[i] = new TH1F(Form("RawTimeSumSqBC%d", i),
423  Form("sum of (cell raw time)^2 for high gain BC %d ", i),
424  nChannels,0.,(Double_t)nChannels);
425  fhRawTimeSumSqBC[i]->SetXTitle("AbsId");
426  fhRawTimeSumSqBC[i]->SetYTitle("Sum Sq Time");
427 
428  //low gain
429  fhRawTimeVsIdLGBC[i] = new TH2F(Form("RawTimeVsIdLGBC%d", i),
430  Form("cell raw time vs ID for low gain BC %d ", i),
431  nChannels,0.,(Double_t)nChannels,fRawTimeNbins,fRawTimeMin,fRawTimeMax);
432  fhRawTimeVsIdLGBC[i]->SetXTitle("AbsId");
433  fhRawTimeVsIdLGBC[i]->SetYTitle("Time");
434 
435  fhRawTimeSumLGBC[i] = new TH1F(Form("RawTimeSumLGBC%d", i),
436  Form("sum of cell raw time for low gain BC %d ", i),
437  nChannels,0.,(Double_t)nChannels);
438  fhRawTimeSumLGBC[i]->SetXTitle("AbsId");
439  fhRawTimeSumLGBC[i]->SetYTitle("Sum Time");
440 
441  fhRawTimeEntriesLGBC[i] = new TH1F(Form("RawTimeEntriesLGBC%d", i),
442  Form("No. entries of cells raw time for low gain BC %d ", i),
443  nChannels,0.,(Double_t)nChannels);
444  fhRawTimeEntriesLGBC[i]->SetXTitle("AbsId");
445  fhRawTimeEntriesLGBC[i]->SetYTitle("Entries for Time ");
446 
447  fhRawTimeSumSqLGBC[i] = new TH1F(Form("RawTimeSumSqLGBC%d", i),
448  Form("sum of (cell raw time)^2 for low gain BC %d ", i),
449  nChannels,0.,(Double_t)nChannels);
450  fhRawTimeSumSqLGBC[i]->SetXTitle("AbsId");
451  fhRawTimeSumSqLGBC[i]->SetYTitle("Sum Sq Time");
452 
453 
454  for (Int_t j = 0; j < kNSM ; j++)
455  {
456  //fhTimeDsupBC[j][i]= new TH2F(Form("SupMod%dBC%d",j,i), Form("SupMod %d time_vs_E BC %d",j,i),500,0.0,20.0,2200,-350.0,750.0);
457  fhTimeDsupBC[j][i]= new TH2F(Form("SupMod%dBC%d",j,i), Form("SupMod %d time_vs_E BC %d",j,i),fEnergyNbins,fEnergyMin,fEnergyMax,fPassTimeNbins,fPassTimeMin,fPassTimeMax);
458  fhTimeDsupBC[j][i]->SetYTitle(" Time (ns) ");
459  fhTimeDsupBC[j][i]->SetXTitle(" E (GeV) ");
460  }
461  }
462 
463  for (Int_t jj = 0; jj < kNSM ; jj++)
464  {
465  fhTimeDsup[jj] = new TH2F(Form("SupMod%d",jj), Form("SupMod %d time_vs_E ",jj),fEnergyNbins,fEnergyMin,fEnergyMax,fPassTimeNbins,fPassTimeMin,fPassTimeMax);
466  fhTimeDsup[jj]->SetYTitle(" Time (ns) ");
467  fhTimeDsup[jj]->SetXTitle(" E (GeV) ");
468  }
469 
470  fhTimeVsBC = new TH2F("TimeVsBC"," SupMod time_vs_BC ", 4001,-0.5,4000.5,(Int_t)(fRawTimeNbins/2.),fRawTimeMin,fRawTimeMax);
471 
472 
473  //add histos to list
474  fOutputList = new TList();
475 
479  fOutputList->Add(fhEventType);
482  fOutputList->Add(fhTcellvsSM);
485 
486  for (Int_t i = 0; i < kNBCmask ; i++)
487  {
488  fOutputList->Add(fhTimeSumSq[i]);
489  fOutputList->Add(fhTimeEnt[i]);
490  fOutputList->Add(fhTimeSum[i]);
491 
492  fOutputList->Add(fhTimeLGSumSq[i]);
493  fOutputList->Add(fhTimeLGEnt[i]);
494  fOutputList->Add(fhTimeLGSum[i]);
495 
496  fOutputList->Add(fhRawTimeVsIdBC[i]);
497  fOutputList->Add(fhRawTimeSumBC[i]);
499  fOutputList->Add(fhRawTimeSumSqBC[i]);
500 
502  fOutputList->Add(fhRawTimeSumLGBC[i]);
505 
506  for (Int_t j = 0; j < kNSM ; j++){
507  fOutputList->Add(fhTimeDsupBC[j][i]);
508  }
509  }
510 
511  for (Int_t j = 0; j < kNSM ; j++)
512  {
513  fOutputList->Add(fhTimeDsup[j]);
514  }
515 
516  fOutputList->Add(fhTimeVsBC);
517 
518  fOutputList->SetOwner(kTRUE);
519  PostData(1,fOutputList);
520 
521 
522 } // End of AliAnalysisTaskEMCALTimeCalib::UserCreateOuputObjects()
523 
524 //________________________________________________________________________
527 {
528  // Called for each event
529  AliDebug(2,Form("UserExec: EMCal geometry: fgeom = %p fGeometryName %s",fgeom,fGeometryName.Data()));
530  AliVEvent *event = InputEvent();
531  //cout<<"T0TOF "<<event->GetT0TOF()<<endl;//bad idea
532  //cout<< fEvent->GetTOFHeader()->GetDefaultEventTimeVal()<<endl;
533  AliDebug(2,Form("TOF time from header %f ps",event->GetTOFHeader()->GetDefaultEventTimeVal()));
534  fhEvtTimeHeader->Fill(event->GetTOFHeader()->GetDefaultEventTimeVal());
535 
536  //fEvent = dynamic_cast<AliESDEvent*>(event);
537  if (!event) {
538  AliError("ESD not available, exit");
539  fhEventType->Fill(0.5);
540  return;
541  }
542 
543  if(fPileupFromSPD==kTRUE){
544  if(event->IsPileupFromSPD(3,0.8,3.,2.,5.)){
545  AliDebug(1,"Event: PileUp skip.");
546  fhEventType->Fill(1.5);
547  return;
548  }
549  }
550 
551  TString triggerclasses = event->GetFiredTriggerClasses();
552  if(triggerclasses=="") {
553  fhEventType->Fill(2.5);
554  return;
555  }
556 
557  Int_t eventType = ((AliVHeader*)event->GetHeader())->GetEventType();
558  // physics events eventType=7, select only those
559  AliDebug(1,Form("Triggerclasses %s, eventType %d",triggerclasses.Data(),eventType));
560  if(eventType != 7) {
561  fhEventType->Fill(3.5);
562  return;
563  }
564 
565  // Check trigger
566  Bool_t bMB = kFALSE;
567  Bool_t bL0 = kFALSE;
568  Bool_t bL1G = kFALSE;
569  Bool_t bL1J = kFALSE;
570 
571  if(triggerclasses.Contains("CINT7-B-NOPF-ALLNOTRD") ||
572  triggerclasses.Contains("CINT7-I-NOPF-ALLNOTRD") ||
573  triggerclasses.Contains("CINT1-I-NOPF-ALLNOTRD") ||
574  triggerclasses.Contains("CINT1-B-NOPF-ALLNOTRD") ||
575  triggerclasses.Contains("CINT8") ||
576  triggerclasses.Contains("CINT7") ||
577  triggerclasses.Contains("CPBI2_B1-B-NOPF-ALLNOTRD") ) bMB = kTRUE;
578 
579  if(triggerclasses.Contains("CEMC7-B-NOPF-CENTNOTRD") ||
580  triggerclasses.Contains("CEMC1-B-NOPF-CENTNOTRD") ||
581  triggerclasses.Contains("CEMC7") ||
582  triggerclasses.Contains("CEMC8") ||
583  triggerclasses.Contains("CEMC8-B-NOPF-CENTNOTRD") ) bL0 = kTRUE;
584 
585  if(triggerclasses.Contains("CEMC7EG1-B-NOPF-CENTNOTRD") ||
586  triggerclasses.Contains("CEMC7EG2-B-NOPF-CENTNOTRD") ||
587  triggerclasses.Contains("CEMC8EG1-B-NOPF-CENTNOTRD") ||
588  triggerclasses.Contains("CEMC8EGA") ||
589  triggerclasses.Contains("CEMC7EGA") ||
590  triggerclasses.Contains("CPBI2EGA") ) bL1G = kTRUE;
591 
592 
593  if(triggerclasses.Contains("CEMC7EJ1-B-NOPF-CENTNOTRD") ||
594  triggerclasses.Contains("CEMC7EJ2-B-NOPF-CENTNOTRD") ||
595  triggerclasses.Contains("CEMC8EJ1-B-NOPF-CENTNOTRD") ||
596  triggerclasses.Contains("CEMC7EJE") ||
597  triggerclasses.Contains("CEMC8EJE") ||
598  triggerclasses.Contains("CPBI2EJE") ) bL1J = kTRUE;
599 
600  if( bL1G || bL1J || bL0 ){ fhEventType->Fill(4.5);}
601  if( bMB ){ fhEventType->Fill(5.5);}
602 
603 
604  // if(bL1G || bL1J || bL0){
605 
606 // Prepare TOFT0 maker at the beginning of a run
607 // if (event->GetRunNumber() != fRunNumber){
608 // AliInfo(Form("Runno per event %d",event->GetRunNumber()));
609 // fRunNumber = event->GetRunNumber();
610 // // PrepareTOFT0maker();
611 // // cout<<"tofT0maker per run"<<fRunNumber<<endl;
612 // }// fi Check if run number has changed
613 
614  // --- Use of AliTOFT0maker
615  Double_t calcolot0=0.0;
616  if(!AODEvent()){
617  Double_t* timeTOFtable;
618  timeTOFtable=fTOFmaker->ComputeT0TOF(dynamic_cast<AliESDEvent*>(event));
619  AliDebug(2,Form("TOF time %f ps, resolution %f ps, tracks at TOF %f/used %f",timeTOFtable[0],timeTOFtable[1],timeTOFtable[3],timeTOFtable[7]));
620  //cout<<"event time "<<timeTOFtable[0]<<" resolution "<<timeTOFtable[1]<<"ps av. ev. time "<<timeTOFtable[2]<<" trks at TOF "<<timeTOFtable[3]<<" calc evnt time "<<timeTOFtable[4]<<" resolution "<<timeTOFtable[5]<<" tracks used "<<timeTOFtable[7]<<endl;
621  calcolot0=timeTOFtable[0];
622  }
623 
624  if (!fhcalcEvtTime) {
625  AliWarning("<E> fhcalcEvtTime not available");
626  return;
627  }// fi no simple histo present
628 
629  fhcalcEvtTime->Fill(calcolot0);
630  if(calcolot0 != 0 && event->GetTOFHeader()->GetDefaultEventTimeVal() != 0 )
631  fhEvtTimeDiff->Fill(calcolot0-event->GetTOFHeader()->GetDefaultEventTimeVal());
632 
633  TRefArray* caloClusters = new TRefArray();
634  event->GetEMCALClusters(caloClusters);
635  // cout << " ###########Bunch Cross nb = " << event->GetBunchCrossNumber() << endl;
636 
637  Int_t BunchCrossNumber =event->GetBunchCrossNumber();
638 
639  Float_t offset=0.;
640  Float_t offsetPerSM=0.;
641  Int_t L1phase=0;
642 
643  Int_t nBC = 0;
644  nBC = BunchCrossNumber%4;
645  //Int_t nTriggerMask =event->GetTriggerMask();
646  // cout << " nBC " << nBC << " nTriggerMask " << nTriggerMask<< endl;
647  Float_t timeBCoffset = 0.; //manual offest
648  // if( nBC%4 ==0 || nBC%4==1) timeBCoffset = 100.; // correction was for LHC11 when BC was not corrected
649 
650  Int_t nclus = caloClusters->GetEntries();
651  AliDebug(1,Form("###########Bunch Cross nb = %d nclus = %d",nBC,nclus ));
652  //cout << " ###########Bunch Cross nb = " << nBC <<" nclus= "<< nclus<< endl;
653  //Int_t ntracks = event-> GetNumberOfTracks() ;
654 
655  AliVCaloCells &cells= *(event->GetEMCALCells());//it is cluster independent
656  //Variables used plenty in loops
657  Int_t nSupMod=-1, nModule=-1;
658  Int_t iphi=-1, ieta=-1, nIphi=-1, nIeta=-1;
659  Int_t absId=-1;
660  Float_t hkdtime=0.0;
661  Float_t amp=0.0;
662  Bool_t isHighGain=kTRUE;
663 
664  for (Int_t icl = 0; icl < nclus; icl++) {
665  //ESD and AOD CaloCells carries the same information
666  AliVCluster* clus = (AliVCluster*)caloClusters->At(icl);
667  if(!AcceptCluster(clus)) continue;
668 
669  //cout<<"nCells="<< clus->GetNCells();<<endl;
670 
671  UShort_t * index = clus->GetCellsAbsId() ;
672 
673  for(Int_t i = 0; i < clus->GetNCells() ; i++) {
674  absId = index[i]; // or clus->GetCellNumber(i) ;
675  hkdtime = cells.GetCellTime(absId) * 1.0e09; // to get ns
676  amp = cells.GetCellAmplitude(absId) ;
677  isHighGain = cells.GetCellHighGain(absId);
678  //cout<<"cell absID: "<<absId<<" cellTime: "<<hkdtime<<" cellaplit: "<< amp<<endl;
679 
680  //main histograms with raw time information
681  if(amp>fMinCellEnergy){
682  if(isHighGain){
683  fhRawTimeVsIdBC[nBC]->Fill(absId,hkdtime);
684  fhRawTimeSumBC[nBC]->Fill(absId,hkdtime);
685  fhRawTimeEntriesBC[nBC]->Fill(absId,1.);
686  fhRawTimeSumSqBC[nBC]->Fill(absId,hkdtime*hkdtime);
687  }else{
688  fhRawTimeVsIdLGBC[nBC]->Fill(absId,hkdtime);
689  fhRawTimeSumLGBC[nBC]->Fill(absId,hkdtime);
690  fhRawTimeEntriesLGBC[nBC]->Fill(absId,1.);
691  fhRawTimeSumSqLGBC[nBC]->Fill(absId,hkdtime*hkdtime);
692  }
693  }
694  //fgeom->PrintCellIndexes(absId);
695  //fgeom->PrintCellIndexes(absId,1);
696 
697  // GEOMETRY tranformations
698  fgeom->GetCellIndex(absId, nSupMod, nModule, nIphi, nIeta);
699  fgeom->GetCellPhiEtaIndexInSModule(nSupMod,nModule,nIphi,nIeta, iphi,ieta);
700 
701  // other histograms for cross-check
702  CheckCellRCU(nSupMod,ieta,iphi);//SM, column, row
703 
704  fhTcellvsSM->Fill(nSupMod,hkdtime);
705  if(isHighGain==kTRUE) {fhEneVsAbsIdHG->Fill(absId,amp);}
706  else {fhEneVsAbsIdLG->Fill(absId,amp);}
707 
708  fhTimeVsBC->Fill(1.*BunchCrossNumber,hkdtime-timeBCoffset);
709  //important remark: We use 'Underflow bin' for absid=0 in OADB for time calibration
710  if(isHighGain==kTRUE){
711  if(fhAllAverageBC[nBC]!=0) {//comming from file after the first iteration
712  offset = (Float_t)(fhAllAverageBC[nBC]->GetBinContent(absId));//channel absId=0 has histogram bin=0
713  } else if(fReferenceFileName.Length()!=0){//protection against missing reference histogram
714  AliFatal(Form("Reference histogram for BC%d not properly loaded",nBC));
715  }
716  } else {
717  if(fhAllAverageLGBC[nBC]!=0) {//comming from file after the first iteration
718  offset = (Float_t)(fhAllAverageLGBC[nBC]->GetBinContent(absId));//channel absId=0 has histogram bin=0
719  } else if(fReferenceFileName.Length()!=0){//protection against missing reference histogram
720  AliFatal(Form("Reference LG histogram for BC%d not properly loaded",nBC));
721  }
722  }
723  //if(offset==0)cout<<"offset 0 in SM "<<nSupMod<<endl;
724 
725  // Solution for 2015 data where L1 phase is not correct in data. We need to calibrate run by run.
726  // The shift is done per SM (0-19).
727  if(fhRefRuns!=0) {//comming from file after the first iteration
728  //offsetPerSM = (Float_t)(fhRefRuns->GetBinContent(nBC*kNSM+nSupMod));//BC0SM0 = bin0
729  L1phase = (Int_t)(fhRefRuns->GetBinContent(nSupMod));//SM0 = bin0
730  if(nBC >= L1phase)
731  offsetPerSM = (nBC - L1phase)*25;
732  else
733  offsetPerSM = (nBC - L1phase + 4)*25;
734  } else if(fReferenceRunByRunFileName.Length()!=0){//protection against missing reference histogram
735  AliFatal("Reference histogram run-by-run not properly loaded");
736  }
737  //end of load additional offset
738 
739  if(amp>0.5) {
740  fhTimeDsup[nSupMod]->Fill(amp,hkdtime-offset-offsetPerSM);
741  fhTimeDsupBC[nSupMod][nBC]->Fill(amp,hkdtime-offset-offsetPerSM);
742  }
743 
744  if(amp>0.9) {
745  fhTcellvsTOFT0HD->Fill(calcolot0, hkdtime);
746  }
747 
748  fhTcellvsTOFT0->Fill(calcolot0, hkdtime-offset-offsetPerSM);
749 
750  hkdtime = hkdtime-timeBCoffset;//time corrected by manual offset (default=0)
751  Float_t hkdtimecorr;
752  hkdtimecorr= hkdtime-offset-offsetPerSM;//time after first iteration
753 
754  //main histograms after the first itereation for calibration constants
755  //if(hkdtimecorr>=-20. && hkdtimecorr<=20. && amp>0.9 ) {
756  if(hkdtimecorr>=fMinTime && hkdtimecorr<=fMaxTime && amp>fMinCellEnergy ) {
757  // per cell
758 // Float_t entriesTime=fhTimeEnt[nBC]->GetBinContent(absId)+1;
759 // Float_t sumTimeSq=(fhTimeSumSq[nBC]->GetBinContent(absId)+(hkdtime*hkdtime));
760 // Float_t sumTime=(fhTimeSum[nBC]->GetBinContent(absId)+hkdtime);
761 //
762 // fhTimeEnt[nBC]->SetBinContent(absId,entriesTime);
763 // fhTimeSumSq[nBC]->SetBinContent(absId,sumTimeSq);
764 // fhTimeSum[nBC]->SetBinContent(absId,sumTime);
765 
766  //correction in 2015 for wrong phase
767  if(offsetPerSM!=0) hkdtime=hkdtime-offsetPerSM;
768 
769  if(isHighGain){
770  fhTimeEnt[nBC]->Fill(absId,1.);
771  fhTimeSumSq[nBC]->Fill(absId,hkdtime*hkdtime);
772  fhTimeSum[nBC]->Fill(absId,hkdtime);
773  }else{
774  fhTimeLGEnt[nBC]->Fill(absId,1.);
775  fhTimeLGSumSq[nBC]->Fill(absId,hkdtime*hkdtime);
776  fhTimeLGSum[nBC]->Fill(absId,hkdtime);
777  }
778 
779 
780  } // hkdtime:[-20;20]
781  } // end icell
782  } //end cluster
783 
784 
785  // Post output data.
786  //cout<<"Post data and delete caloClusters"<<endl;
787  caloClusters->Delete();
788  delete caloClusters;
789 // } // end if trigger type
790 
791  PostData(1, fOutputList);
792 } // End of AliAnalysisTaskEMCALTimeCalib::UserExec()
793 
794 //________________________________________________________________________
798 {
799  fOutputList = dynamic_cast<TList*> (GetOutputData(1));
800 
801  if(fTOFmaker) delete fTOFmaker;
802 
803 
804  if (!fOutputList)
805  {
806  AliDebug(1,"ERROR: Output list not available");
807  return;
808  }
809 } // End of AliAnalysisTaskEMCALTimeCalib::Terminate
810 
811 //________________________________________________________________________
814 {
815  //fix with noisy EMCAL fee card
816  Int_t nCells = clus->GetNCells();
817 
818  if(clus->IsEMCAL())
819  {
820  if ((clus->E() > fMaxClusterEnergy && nCells > fMaxNcells ) || nCells > fMaxNcells){
821  AliDebug(1,"very big cluster with enormous energy - cluster rejected");
822  return kFALSE;
823  }
824  }
825 
826  // remove other than photonlike
827  Double_t lambda0=clus->GetM02();
828  if (lambda0>fMaxLambda0LG || lambda0<fMinLambda0LG){
829  AliDebug(1,"lambda0 loose cut failed - cluster rejected");
830  return kFALSE;
831  }
832 
833  // remove matched clusters
834  Double_t Dx=clus->GetTrackDx();
835  Double_t Dz=clus->GetTrackDz();
836  Double_t Rtrack = TMath::Sqrt(Dx*Dx+Dz*Dz);
837  if (Rtrack <fMaxRtrack)
838  {
839  AliDebug(1,"track matched - cluster rejected");
840  return kFALSE;
841  }
842 
843  if (nCells<fMinNcells)
844  {
845  AliDebug(1,"single cell cluster - cluster rejected");
846  return kFALSE;
847  }
848 
849  if(clus->E()<fMinClusterEnergy)
850  {
851  AliDebug(1,"cluster energy < 1 GeV- cluster rejected");
852  return kFALSE;
853  }
854 
855 
856  if(!IsLowGainCellInCluster(clus)) {//no low gain cell in cluster
857  //apply more strict lambda0^2 cut
858  if (lambda0>fMaxLambda0 || lambda0<fMinLambda0){
859  AliDebug(1,"lambda0 strict cut failed - cluster rejected");
860  return kFALSE;
861  }
862  }
863 
864 
865 
866 
867  return kTRUE;
868 }//End AliAnalysisTaskEMCALTimeCalib::AcceptCluster
869 
870 //________________________________________________________________________
873  UShort_t * index = clus->GetCellsAbsId() ;
874  AliVCaloCells &cells= *(InputEvent()->GetEMCALCells());
875  for(Int_t i = 0; i < clus->GetNCells() ; i++) {
876  if(cells.GetCellHighGain(index[i])==kFALSE) return kTRUE;//low gain cell
877  }
878  return kFALSE;
879 
880 }
881 
882 //________________________________________________________________________
884 Bool_t AliAnalysisTaskEMCALTimeCalib::CheckCellRCU(Int_t nSupMod,Int_t icol,Int_t irow)
885 {
886  Int_t iRCU;
887  if(nSupMod < 10 || (nSupMod >= 12 && nSupMod <18) )
888  {
889  if (0<=irow&&irow<8) iRCU=0; // first cable row
890  else if (8<=irow&&irow<16 && 0<=icol&&icol<24) iRCU=0; // first half;
891  //second cable row
892  //RCU1
893  else if (8<=irow&&irow<16 && 24<=icol&&icol<48) iRCU=1; // second half;
894  //second cable row
895  else if (16<=irow&&irow<24) iRCU=1; // third cable row
896 
897  if (nSupMod%2==1) iRCU = 1 - iRCU; // swap for odd=C side, to allow us to cable both sides the same
898  }
899  else
900  {
901  // Last 2 SM have one single SRU, just assign RCU 0
902  iRCU = 0 ;
903  }
904 
905  //cout<<"RCU:"<<iRCU<<endl;
906  if (iRCU<0)
907  AliFatal(Form("Wrong EMCAL/DCAL RCU number = %d\n", iRCU));
908 
909  return kTRUE;
910 }//End AliAnalysisTaskEMCALTimeCalib::CheckCellRCU
911 
912 //________________________________________________________________________
915 {
916  fMinClusterEnergy=1.0;//0.5//0.7
917  fMaxClusterEnergy=500;
918  fMinNcells=2;
919  fMaxNcells=200;
920  fMinLambda0=0.1;
921  fMaxLambda0=0.4;
922  fMinLambda0LG=0.1;
923  fMaxLambda0LG=4.0;
924  fMaxRtrack=0.025;
925  fMinCellEnergy=0.4;//0.1//0.4
926  fReferenceFileName="";//Reference.root
928  fGeometryName="";//EMCAL_COMPLETE12SMV1_DCAL_8SM
929  fPileupFromSPD=kFALSE;
930  fMinTime=-20.;
931  fMaxTime=20.;
932  //histograms
933  fRawTimeNbins = 600; // Raw time settings should be like that all the time
934  fRawTimeMin = 300.; // importent in pass1
935  fRawTimeMax = 900.;
936  fPassTimeNbins = 1400; // in pass2 should be (600,300,900)
937  fPassTimeMin = -350.;// in pass3 should be (1400,-350,350)
938  fPassTimeMax = 350.;
939  fEnergyNbins = 500; // default settings
940  fEnergyMin = 0.;
941  fEnergyMax = 20.;
942  fFineNbins = 90; //was 4500 for T0 time studies
943  fFineTmin = -500;
944  fFineTmax = 400;
945 }
946 
947 //________________________________________________________________________
952 void AliAnalysisTaskEMCALTimeCalib::ProduceCalibConsts(TString inputFile,TString outputFile,Bool_t isFinal)
953 {
954  TFile *file =new TFile(inputFile.Data());
955  if(file==0x0) {
956  //AliWarning("Input file does not exist!");
957  return;
958  }
959 
960  TList *list=(TList*)file->Get("chistolist");
961  if(list==0x0)
962  {
963  //AliWarning("List chistolist does not exist in file!");
964  return;
965  }
966 
967  //high gain
968  TH1F *h1[4];
969  TH1F *h2[4];
970  TH1F *h3[4];
971  TH1F *hAllTimeAvBC[4];
972  TH1F *hAllTimeRMSBC[4];
973 
974  //low gain
975  TH1F *h4[4];
976  TH1F *h5[4];
977  TH1F *h6[4];
978  TH1F *hAllTimeAvLGBC[4];
979  TH1F *hAllTimeRMSLGBC[4];
980 
981  if(isFinal==kFALSE){//first itereation
982  for(Int_t i=0;i<4;i++){
983  h1[i]=(TH1F *)list->FindObject(Form("RawTimeSumBC%d",i));
984  h2[i]=(TH1F *)list->FindObject(Form("RawTimeEntriesBC%d",i));
985  h3[i]=(TH1F *)list->FindObject(Form("RawTimeSumSqBC%d",i));
986 
987  h4[i]=(TH1F *)list->FindObject(Form("RawTimeSumLGBC%d",i));
988  h5[i]=(TH1F *)list->FindObject(Form("RawTimeEntriesLGBC%d",i));
989  h6[i]=(TH1F *)list->FindObject(Form("RawTimeSumSqLGBC%d",i));
990  }
991  } else {//final iteration
992  for(Int_t i=0;i<4;i++){
993  h1[i]=(TH1F *)list->FindObject(Form("hTimeSum%d",i));
994  h2[i]=(TH1F *)list->FindObject(Form("hTimeEnt%d",i));
995  h3[i]=(TH1F *)list->FindObject(Form("hTimeSumSq%d",i));
996 
997  h4[i]=(TH1F *)list->FindObject(Form("hTimeLGSum%d",i));
998  h5[i]=(TH1F *)list->FindObject(Form("hTimeLGEnt%d",i));
999  h6[i]=(TH1F *)list->FindObject(Form("hTimeLGSumSq%d",i));
1000  }
1001  }
1002  //AliWarning("Input histograms read.");
1003 
1004  for(Int_t i=0;i<4;i++){
1005  hAllTimeAvBC[i]=new TH1F(Form("hAllTimeAvBC%d",i),Form("hAllTimeAvBC%d",i),h1[i]->GetNbinsX(),h1[i]->GetXaxis()->GetXmin(),h1[i]->GetXaxis()->GetXmax());
1006  hAllTimeRMSBC[i]=new TH1F(Form("hAllTimeRMSBC%d",i),Form("hAllTimeRMSBC%d",i),h3[i]->GetNbinsX(),h3[i]->GetXaxis()->GetXmin(),h3[i]->GetXaxis()->GetXmax());
1007 
1008  hAllTimeAvLGBC[i]=new TH1F(Form("hAllTimeAvLGBC%d",i),Form("hAllTimeAvLGBC%d",i),h4[i]->GetNbinsX(),h4[i]->GetXaxis()->GetXmin(),h4[i]->GetXaxis()->GetXmax());
1009  hAllTimeRMSLGBC[i]=new TH1F(Form("hAllTimeRMSLGBC%d",i),Form("hAllTimeRMSLGBC%d",i),h6[i]->GetNbinsX(),h6[i]->GetXaxis()->GetXmin(),h6[i]->GetXaxis()->GetXmax());
1010  }
1011 
1012  //AliWarning("New histograms booked.");
1013 
1014  //important remark: we use 'underflow bin' for absid=0 in OADB . That's why there is j-1 below.
1015  for(Int_t i=0;i<4;i++){
1016  for(Int_t j=1;j<=h1[i]->GetNbinsX();j++){
1017  //high gain
1018  if(h2[i]->GetBinContent(j)!=0){
1019  hAllTimeAvBC[i]->SetBinContent(j-1,h1[i]->GetBinContent(j)/h2[i]->GetBinContent(j));
1020  hAllTimeRMSBC[i]->SetBinContent(j-1,TMath::Sqrt(h3[i]->GetBinContent(j)/h2[i]->GetBinContent(j)) );
1021  } else {
1022  hAllTimeAvBC[i]->SetBinContent(j-1,0.);
1023  hAllTimeRMSBC[i]->SetBinContent(j-1,0.);
1024  }
1025  //low gain
1026  if(h5[i]->GetBinContent(j)!=0){
1027  hAllTimeAvLGBC[i]->SetBinContent(j-1,h4[i]->GetBinContent(j)/h5[i]->GetBinContent(j));
1028  hAllTimeRMSLGBC[i]->SetBinContent(j-1,TMath::Sqrt(h6[i]->GetBinContent(j)/h5[i]->GetBinContent(j)) );
1029  } else {
1030  hAllTimeAvLGBC[i]->SetBinContent(j-1,0.);
1031  hAllTimeRMSLGBC[i]->SetBinContent(j-1,0.);
1032  }
1033 
1034  }
1035  }
1036 
1037  //AliWarning("Average and rms calculated.");
1038  TFile *fileNew=new TFile(outputFile.Data(),"recreate");
1039  for(Int_t i=0;i<4;i++){
1040  hAllTimeAvBC[i]->Write();
1041  hAllTimeRMSBC[i]->Write();
1042  hAllTimeAvLGBC[i]->Write();
1043  hAllTimeRMSLGBC[i]->Write();
1044  }
1045 
1046  //AliWarning(Form("Histograms saved in %s file.",outputFile.Data()));
1047 
1048  fileNew->Close();
1049  delete fileNew;
1050 
1051  for(Int_t i=0;i<4;i++){
1052  delete hAllTimeAvBC[i];
1053  delete hAllTimeRMSBC[i];
1054  delete hAllTimeAvLGBC[i];
1055  delete hAllTimeRMSLGBC[i];
1056 
1057  delete h1[i];
1058  delete h2[i];
1059  delete h3[i];
1060  delete h4[i];
1061  delete h5[i];
1062  delete h6[i];
1063  }
1064 
1065  file->Close();
1066  delete file;
1067 
1068  //AliWarning("Pointers deleted. Memory cleaned.");
1069 }
1070 
1071 //________________________________________________________________________
1075 void AliAnalysisTaskEMCALTimeCalib::ProduceOffsetForSMsV2(Int_t runNumber,TString inputFile,TString outputFile){
1076 
1077 const Double_t lowerLimit[]={
1078  0,
1079  1152,
1080  2304,
1081  3456,
1082  4608,
1083  5760,
1084  6912,
1085  8064,
1086  9216,
1087  10368,
1088  11520,
1089  11904,
1090  12288,
1091  13056,
1092  13824,
1093  14592,
1094  15360,
1095  16128,
1096  16896,
1097  17280};
1098 
1099 const Double_t upperLimit[]={
1100  1151 ,
1101  2303 ,
1102  3455 ,
1103  4607 ,
1104  5759 ,
1105  6911 ,
1106  8063 ,
1107  9215 ,
1108  10367,
1109  11519,
1110  11903,
1111  12287,
1112  13055,
1113  13823,
1114  14591,
1115  15359,
1116  16127,
1117  16895,
1118  17279,
1119  17663};
1120 
1121  TFile *file =new TFile(inputFile.Data());
1122  if(file==0x0) return;
1123 
1124  TH1F *ccBC[4];
1125  for(Int_t i = 0; i < kNBCmask; i++){
1126  ccBC[i]=(TH1F*) file->Get(Form("hAllTimeAvBC%d",i));
1127  }
1128 
1129  TH1F *hRun=new TH1F(Form("h%d",runNumber),Form("h%d",runNumber),19,0,19);
1130  Int_t fitResult=0;
1131  Double_t minimumValue=10000;
1132  Int_t minimumIndex=-1;
1133  Double_t meanBC[4];
1134 
1135  Double_t fitParameter=0;
1136  TF1 *f1=new TF1("f1","pol0",0,17664);
1137  for(Int_t i=0;i<20;i++){
1138  minimumValue=10000;
1139  for(Int_t j=0;j<kNBCmask;j++){
1140  fitResult=ccBC[j]->Fit("f1","CQ","",lowerLimit[i],upperLimit[i]);
1141  if(fitResult<0){
1142  hRun->SetBinContent(i,0);
1143  continue;
1144  }
1145  fitParameter = f1->GetParameter(0);
1146  if(j==0 || j==1) {
1147  fitParameter+=100;
1148  }
1149  meanBC[j]=fitParameter;
1150 
1151  if(fitParameter<minimumValue){
1152  minimumValue = fitParameter;
1153  minimumIndex = j;
1154  }
1155  }
1156  hRun->SetBinContent(i,minimumIndex);
1157  }
1158  delete f1;
1159  TFile *fileNew=new TFile(outputFile.Data(),"update");
1160  hRun->Write();
1161  fileNew->Close();
1162  delete fileNew;
1163 
1164  file->Close();
1165  delete file;
1166 }
Bool_t SetEMCalGeometry()
Set the EMCal Geometry.
TH1F * fhRawTimeEntriesLGBC[kNBCmask]
! 4 BCmask LG
Double_t fPassTimeMax
upper range of histo with time in passX
TH2F * fhEneVsAbsIdHG
! energy of each cell for high gain cells with strange time
TH1F * fhRawTimeSumLGBC[kNBCmask]
! 4 BCmask LG
ClassImp(AliAnalysisTaskTriggerRates) AliAnalysisTaskTriggerRates
Bool_t AcceptCluster(AliVCluster *clus)
Selection criteria of good cluster are set here.
TH2F * fhRawTimeVsIdBC[kNBCmask]
! 4 BCmask HG
Int_t fFineNbins
number of bins of histo with T0 time
TH1F * fhRawTimeSumSqBC[kNBCmask]
! 4 BCmask HG
Double_t fMinLambda0
minimum cluster lambda0
TFile * fReferenceFile
file with reference for SM
TH1F * fhcalcEvtTime
! spectrum calcolot0[0]
Double_t fEnergyMin
lower range of histo with energy
TString fReferenceRunByRunFileName
! name of reference file (run-by-run)
Double_t fMinTime
minimum cluster time after correction
AliTOFT0maker * fTOFmaker
pointer to get T0 from TOF
TList * list
Double_t fFineTmax
upper range of histo with T0 time
void SetDefaultCuts()
Set default cuts for calibration.
Double_t fRawTimeMin
lower range of histo with raw time
TH1F * fhRawTimeSumSqLGBC[kNBCmask]
! 4 BCmask LG
Double_t fMaxRtrack
maximum cluster track distance
Double_t fMaxLambda0
maximum cluster lambda0
AliEMCALGeometry * fgeom
pointer to EMCal geometry
Double_t fRawTimeMax
upper range of histo with raw time
TH2F * fhTcellvsTOFT0HD
! time of cell vs TOF T0 time for higher energy threshold
Bool_t IsLowGainCellInCluster(AliVCluster *clus)
Check if low gain cell is in a cluster.
Double_t fMaxTime
maximum cluster time after correction
static void ProduceOffsetForSMsV2(Int_t runNumber, TString inputFile="Reference.root", TString outputFile="ReferenceSM.root")
Double_t fEnergyMax
upper range of histo with energy
Double_t fMinClusterEnergy
minimum cluster energy
Double_t fFineTmin
lower range of histo with T0 time
TString fReferenceFileName
! name of reference file (for one period)
Int_t fMaxNcells
maximum number of cells in cluster
virtual void UserExec(Option_t *option)
Main loop executed for each event.
virtual void PrepareTOFT0maker()
Get T0 time from TOF.
Bool_t fPileupFromSPD
flag to set PileupFromSPD
TH1F * fhRawTimeSumBC[kNBCmask]
! 4 BCmask HG
Double_t fMinCellEnergy
minimum cell energy
Int_t fMinNcells
minimum number of cells in cluster
Task to work on Time Calibration for EMCal/DCal.
Double_t fMinLambda0LG
minimum cluster lambda0 Low Gain
Double_t fMaxClusterEnergy
maximum cluster energy
TH1F * fhEvtTimeHeader
! spectrum time from header
TH1F * fhEvtTimeDiff
! spectrum time difference
TH2F * fhTcellvsTOFT0
! time of cell vs TOF T0 time
Double_t fPassTimeMin
lower range of histo with time in passX
Double_t fMaxLambda0LG
maximum cluster lambda0 Low Gain
static void ProduceCalibConsts(TString inputFile="time186319testWOL0.root", TString outputFile="Reference.root", Bool_t isFinal=kFALSE)
TH2F * fhEneVsAbsIdLG
! energy of each cell for low gain cells with strange time
Int_t fPassTimeNbins
number of bins of histo with time in passX
TList * fOutputList
pointer to output list
TH1F * fhRawTimeEntriesBC[kNBCmask]
! 4 BCmask HG
TFile * file
Bool_t CheckCellRCU(Int_t nSupMod, Int_t icol, Int_t irow)
Check RCU for cell given by Super Module, column index, row index.
TH2F * fhRawTimeVsIdLGBC[kNBCmask]
! 4 BCmask LG
void LoadReferenceHistos()
Load reference Histograms (for one period) from file.
TH1F * fhAllAverageLGBC[kNBCmask]
4 BCmask High gain
Int_t fEnergyNbins
number of bins of histo with energy
Int_t fRawTimeNbins
number of bins of histo with raw time
TH2F * fhTimeDsup[kNSM]
20 entries per run: nSM
TH2F * fhTimeDsupBC[kNSM][kNBCmask]
! 20 x 4