]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG4/macros/AddTaskPi0.C
Add access to event plane class to the frame, add reaction plane bins in AliAnaPi0...
[u/mrichter/AliRoot.git] / PWG4 / macros / AddTaskPi0.C
1 AliAnalysisTaskParticleCorrelation *AddTaskPi0(TString data, TString calorimeter, Bool_t kPrintSettings = kFALSE,Bool_t kSimulation = kFALSE, 
2                                                Bool_t outputAOD=kFALSE, TString outputfile = "", Int_t year = 2010,TString col = "pp",
3                                                Bool_t withQA = kFALSE)
4 {
5   // Creates a PartCorr task, configures it and adds it to the analysis manager.
6   
7   // Get the pointer to the existing analysis manager via the static access method.
8   //==============================================================================
9   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
10   if (!mgr) {
11     ::Error("AddTaskPi0", "No analysis manager to connect to.");
12     return NULL;
13   }  
14   
15   // Check the analysis type using the event handlers connected to the analysis manager.
16   //==============================================================================
17   if (!mgr->GetInputEventHandler()) {
18     ::Error("AddTaskPi0", "This task requires an input event handler");
19     return NULL;
20   }
21   TString inputDataType = "AOD";
22   if(!data.Contains("delta"))
23     inputDataType = mgr->GetInputEventHandler()->GetDataType(); // can be "ESD" or "AOD"
24   //cout<<"DATA TYPE :: "<<inputDataType<<endl;
25   // inputDataType: data managed by the input handler
26   // data: can be same as one managed by input handler, or the output AOD created by the filter. By default use AOD
27   
28   Bool_t kUseKinematics = kFALSE; 
29   if(kSimulation) { 
30     kUseKinematics = (mgr->GetMCtruthEventHandler())?kTRUE:kFALSE; 
31     if (!kUseKinematics && data=="AOD" && inputDataType != "ESD") kUseKinematics = kTRUE; //AOD primary should be available ... 
32   } 
33   
34   cout<<"********* ACCESS KINE? "<<kUseKinematics<<endl;
35   
36   // Configure analysis
37   //===========================================================================
38   
39   // *** Reader ***
40   AliCaloTrackReader * reader = ;
41   if(data.Contains("AOD")) reader = new AliCaloTrackAODReader();
42   else if(data=="ESD") reader = new AliCaloTrackESDReader();
43   else if(data=="MC" && inputDataType == "ESD") reader = new AliCaloTrackMCReader();
44   reader->SetDebug(-1);//10 for lots of messages
45   reader->SwitchOnCTS();
46   //reader->SetDeltaAODFileName("");
47   //if(!kSimulation) reader->SetFiredTriggerClassName("CINT1B-ABCE-NOPF-ALL");
48   if(calorimeter == "EMCAL") {
49     reader->SwitchOnEMCALCells();  
50     reader->SwitchOnEMCAL();
51   }
52   if(calorimeter == "PHOS") { 
53     reader->SwitchOnPHOSCells();  
54     reader->SwitchOnPHOS();
55   }
56   
57   // for case data="deltaAOD", no need to fill the EMCAL/PHOS cluster lists
58   if(data.Contains("delta")){
59     reader->SwitchOffEMCAL();
60     reader->SwitchOffPHOS();
61     reader->SwitchOffEMCALCells(); 
62     reader->SwitchOffPHOSCells(); 
63   }
64   
65   if(kUseKinematics){
66     if(inputDataType == "ESD"){
67       reader->SwitchOnStack();          
68       reader->SwitchOffAODMCParticles(); 
69     }
70     else if(inputDataType == "AOD"){
71       reader->SwitchOffStack();          
72       reader->SwitchOnAODMCParticles(); 
73     }
74   }
75
76   //In case of AODs created only for calorimeters, and track information filtered
77   //CTS is off when calling this method
78   //reader->SwitchOnCaloFilterPatch();
79   //Event selection
80   if     (col=="pp"  ) {
81     reader->SwitchOnEventSelection(); //remove pileup by default
82     reader->SwitchOffV0ANDSelection() ; // and besides v0 AND
83     reader->SwitchOffPrimaryVertexSelection(); // and besides primary vertex
84   }
85   else if(col=="PbPb") {
86     reader->SwitchOffEventSelection(); //remove pileup by default
87     reader->SwitchOffV0ANDSelection() ; // and besides v0 AND
88     reader->SwitchOffPrimaryVertexSelection(); // and besides primary vertex
89   }
90   
91   if     (col=="pp"  )   reader->SetZvertexCut(50.);  //Open cut
92   else if(col=="PbPb")   reader->SetZvertexCut(10.);  //Centrality defined in this range.
93   
94   //Min particle pT
95   reader->SetEMCALPtMin(0.5); 
96   reader->SetEMCALPtMax(30); 
97   reader->SetPHOSPtMin(0.);
98   reader->SetCTSPtMin(0.);
99   if(outputAOD)  reader->SwitchOnWriteDeltaAOD()  ;
100   if(kPrintSettings) reader->Print("");
101   
102   // *** Calorimeters Utils     ***
103   AliCalorimeterUtils *cu = new AliCalorimeterUtils;
104   if(year==2010) cu->SetEMCALGeometryName("EMCAL_FIRSTYEARV1");
105   else           cu->SetEMCALGeometryName("EMCAL_COMPLETEV1");
106   // Remove clusters close to borders, at least max energy cell is 1 cell away 
107   cu->SetNumberOfCellsFromEMCALBorder(1);
108   cu->SetNumberOfCellsFromPHOSBorder(2);
109   
110   if     (col=="pp"  ) {
111     cu->SwitchOnCorrectClusterLinearity();
112     AliEMCALRecoUtils * reco = cu->GetEMCALRecoUtils();
113     reco->SetNonLinearityFunction(AliEMCALRecoUtils::kBeamTestCorrected);
114     reco->SwitchOnRejectExoticCluster();
115   }
116   
117   // Remove EMCAL hottest channels for first LHC10 periods      
118   //  cu->SwitchOnBadChannelsRemoval();
119   //  cu->SwitchOnDistToBadChannelRecalculation();
120
121 //   TFile * fbad = new TFile("BadChannels.root","read");
122 //   TH2I * hbad0 = (TH2I*)fbad->Get("EMCALBadChannelMap_Mod0");
123 //   TH2I * hbad1 = (TH2I*)fbad->Get("EMCALBadChannelMap_Mod1");
124 //   TH2I * hbad2 = (TH2I*)fbad->Get("EMCALBadChannelMap_Mod2");
125 //   TH2I * hbad3 = (TH2I*)fbad->Get("EMCALBadChannelMap_Mod3");
126 //   cu->SetEMCALChannelStatusMap(0,hbad0);
127 //   cu->SetEMCALChannelStatusMap(1,hbad1);
128 //   cu->SetEMCALChannelStatusMap(2,hbad2);
129 //   cu->SetEMCALChannelStatusMap(3,hbad3);
130   
131   
132   //Recalibration
133   //cu->SwitchOnRecalibration();
134   //TFile * f = new TFile("RecalibrationFactors.root","read");
135   //cu->SetEMCALChannelRecalibrationFactors(0,(TH2F*)f->Get("EMCALRecalFactors_SM0"));
136   //cu->SetEMCALChannelRecalibrationFactors(1,(TH2F*)f->Get("EMCALRecalFactors_SM1"));
137   //cu->SetEMCALChannelRecalibrationFactors(2,(TH2F*)f->Get("EMCALRecalFactors_SM2"));
138   //cu->SetEMCALChannelRecalibrationFactors(3,(TH2F*)f->Get("EMCALRecalFactors_SM3"));
139   //f->Close(); 
140   
141   cu->SetDebug(-1);
142   if(kPrintSettings) cu->Print("");
143   
144   
145   // ##### Analysis algorithm settings ####
146   
147   // -------------------------------------------------
148   // --- Photon/Pi0/Omega/Electron Analysis ---
149   // -------------------------------------------------
150   
151   AliAnaPhoton *anaphoton = new AliAnaPhoton();
152   anaphoton->SetDebug(-1); //10 for lots of messages
153   if(calorimeter == "PHOS"){
154     anaphoton->SetNCellCut(2);// At least 2 cells
155     anaphoton->SetMinPt(3.);
156     anaphoton->SetMinDistanceToBadChannel(2, 4, 5);
157   }
158   else {//EMCAL
159     anaphoton->SetNCellCut(1);// At least 2 cells
160     anaphoton->SetMinPt(0.5); // no effect minium EMCAL cut.
161     anaphoton->SetMaxPt(30); 
162     //if(!kUseKinematics) anaphoton->SetTimeCut(400,900);// Time window of [400-900] ns
163     //anaphoton->SetMinDistanceToBadChannel(6, 12, 18);//For officially produced ESDs/AODs
164     anaphoton->SetMinDistanceToBadChannel(1, 2, 3);//For filtered AODs, new releases.
165   }
166   anaphoton->SetCalorimeter(calorimeter);
167   if(kUseKinematics) anaphoton->SwitchOnDataMC() ;//Access MC stack and fill more histograms
168   else  anaphoton->SwitchOffDataMC() ;
169   anaphoton->SwitchOffCaloPID();
170   anaphoton->SwitchOffFiducialCut();
171   if(kSimulation){
172     anaphoton->SwitchOnFiducialCut();
173     AliFiducialCut * fidCut1stYear = anaphoton->GetFiducialCut();
174     fidCut1stYear->DoCTSFiducialCut(kFALSE) ;
175     fidCut1stYear->DoEMCALFiducialCut(kTRUE) ;
176     fidCut1stYear->DoPHOSFiducialCut(kTRUE) ;
177     fidCut1stYear->SetSimpleEMCALFiducialCut(0.7,80.,120.);
178     fidCut1stYear->SetSimplePHOSFiducialCut(0.12,260.,320.);
179   }
180   
181   if(!data.Contains("delta")) {
182     anaphoton->SetOutputAODName(Form("Photons%s",calorimeter.Data()));
183     anaphoton->SetOutputAODClassName("AliAODPWG4ParticleCorrelation");
184   }
185   else anaphoton->SetInputAODName(Form("Photons%s",calorimeter.Data()));
186   anaphoton->AddToHistogramsName("AnaPhotonCorr_");
187   //Set Histograms bins and ranges
188   anaphoton->SetHistoPtRangeAndNBins(0, 30, 150) ;
189   if(year==2010)anaphoton->SetHistoPhiRangeAndNBins(78*TMath::DegToRad(), 122*TMath::DegToRad(), 78) ;
190   else          anaphoton->SetHistoPhiRangeAndNBins(78*TMath::DegToRad(), 182*TMath::DegToRad(), 108) ;
191   anaphoton->SetHistoEtaRangeAndNBins(-0.72, 0.72, 144) ;
192   if(kPrintSettings) anaphoton->Print("");
193   
194   // -----------------------------------
195   // --- Pi0 Invariant Mass Analysis ---
196   // -----------------------------------
197   
198   AliAnaPi0 *anapi0 = new AliAnaPi0();
199   anapi0->SetDebug(-1);//10 for lots of messages
200   anapi0->SetInputAODName(Form("Photons%s",calorimeter.Data()));
201   anapi0->SetCalorimeter(calorimeter);
202   anapi0->SwitchOffMultipleCutAnalysis(); 
203   //anapi0->SetNPtCuts(2);
204   //anapi0->SetNAsymCuts(2);
205   //anapi0->SetNNCellCuts(2);
206   //anapi0->SetNPIDBits(1);
207   
208   //anapi0->SetPtCutsAt(0,0.3); anapi0->SetPtCutsAt(1,0.5);
209   //anapi0->SetAsymCutsAt(0,0.1);anapi0->SetAsymCutsAt(1,0.5);
210   //anapi0->SetNCellCutsAt(0,1); anapi0->SetNCellCutsAt(1,2);
211   //anapi0->SetPIDBitsAt(0,0); //No Cut
212   //anapi0->SetPIDBitsAt(1,2); //Dispersion Cut
213
214   
215   if(kSimulation){
216     anapi0->SwitchOnFiducialCut();
217     AliFiducialCut * fidCut1stYear = anapi0->GetFiducialCut();
218     fidCut1stYear->DoCTSFiducialCut(kFALSE) ;
219     fidCut1stYear->DoEMCALFiducialCut(kTRUE) ;
220     fidCut1stYear->DoPHOSFiducialCut(kTRUE) ;
221     fidCut1stYear->SetSimpleEMCALFiducialCut(0.7,80.,120.);
222     fidCut1stYear->SetSimplePHOSFiducialCut(0.12,260.,320.);
223   }  
224         
225   //settings for pp collision mixing
226   anapi0->SwitchOnOwnMix(); //Off when mixing done with general mixing frame
227   if     (col=="pp"  ) {
228     anapi0->SetNCentrBin(1);
229     anapi0->SetNZvertBin(10);
230     anapi0->SetNRPBin(1);
231     anapi0->SetNMaxEvMix(100);    
232     anapi0->SwitchOnSMCombinations();
233   }
234   else if(col=="PbPb") {
235     anapi0->SetNCentrBin(10);
236     anapi0->SetNZvertBin(10);
237     anapi0->SetNRPBin(4);
238     anapi0->SetNMaxEvMix(10);
239     anapi0->SwitchOffSMCombinations();
240   }
241
242   
243   if(kUseKinematics)anapi0->SwitchOnDataMC() ;//Access MC stack and fill more histograms
244   else              anapi0->SwitchOffDataMC() ;
245   if(calorimeter=="PHOS") anapi0->SetNumberOfModules(3); //PHOS first year
246   else {                   
247      if(year==2010) anapi0->SetNumberOfModules(4); //EMCAL first year
248     else            anapi0->SetNumberOfModules(10);
249   }
250   anapi0->SetHistoPtRangeAndNBins(0, 30, 150) ;    
251   anapi0->SetHistoEtaRangeAndNBins(-0.72, 0.72, 144) ;
252   if(year==2010)anaphoton->SetHistoPhiRangeAndNBins(78*TMath::DegToRad(), 122*TMath::DegToRad(), 78) ;
253   else          anaphoton->SetHistoPhiRangeAndNBins(78*TMath::DegToRad(), 182*TMath::DegToRad(), 108) ;
254
255   anapi0->SetHistoMassRangeAndNBins(0., 1., 200) ;
256   anapi0->SetHistoAsymmetryRangeAndNBins(0., 1. , 100) ;
257   anapi0->SetHistoTrackMultiplicityRangeAndNBins(0, 200, 20); 
258
259   if(kPrintSettings) anapi0->Print("");
260
261   //QA
262   if (withQA) {
263     AliAnaCalorimeterQA *emcalQA = new AliAnaCalorimeterQA();
264     //emcalQA->SetDebug(10); //10 for lots of messages
265     emcalQA->SetCalorimeter("EMCAL");
266     if(kUseKinematics) emcalQA->SwitchOnDataMC() ;//Access MC stack and fill more histograms, AOD MC not implemented yet.
267     else  emcalQA->SwitchOffDataMC() ;
268     emcalQA->AddToHistogramsName("QA_"); //Begining of histograms name
269     //emcalQA->SetFiducialCut(fidCut);
270     emcalQA->SwitchOffFiducialCut();
271     emcalQA->SwitchOffPlotsMaking();
272     emcalQA->SwitchOffCorrelation();
273     //  if(!kUseKinematics)emcalQA->SetTimeCut(400,850);//Open for the moment
274     //Set Histrograms bins and ranges
275     emcalQA->SetHistoPtRangeAndNBins(0, 50, 200) ;
276     emcalQA->SetHistoFinePtRangeAndNBins(0, 10, 200) ; // bining for fhAmpId
277     emcalQA->SetHistoEtaRangeAndNBins(-0.71, 0.71, 142) ;
278     
279     if(year==2010){  
280       emcalQA->SetNumberOfModules(4); 
281       emcalQA->SetHistoPhiRangeAndNBins(78*TMath::DegToRad(), 122*TMath::DegToRad(), 78) ;
282       emcalQA->SetHistoXRangeAndNBins(-230,90,60);
283       emcalQA->SetHistoYRangeAndNBins(370,450,20);
284     }
285     else{            
286       emcalQA->SetNumberOfModules(10); 
287       emcalQA->SetHistoPhiRangeAndNBins(78*TMath::DegToRad(), 182*TMath::DegToRad(), 108) ;
288       emcalQA->SetHistoXRangeAndNBins(-600,90,100);
289       emcalQA->SetHistoYRangeAndNBins(100,450,50);
290     }
291     
292     emcalQA->SwitchOffFillAllPi0Histogram();
293     emcalQA->SwitchOffFillAllTrackMatchingHistogram();
294     emcalQA->SwitchOffFillAllTH3Histogram();
295     emcalQA->SwitchOffFillAllPositionHistogram2();
296     
297     emcalQA->SetHistoMassRangeAndNBins(0., 1, 100) ;
298     emcalQA->SetHistoAsymmetryRangeAndNBins(0., 1. , 10 );
299     emcalQA->SetHistoPOverERangeAndNBins(0,10.,50);
300     emcalQA->SetHistodEdxRangeAndNBins(0.,200.,50);
301     emcalQA->SetHistodRRangeAndNBins(0.,TMath::Pi(),75);
302     emcalQA->SetHistoTimeRangeAndNBins(300.,900,150);
303     emcalQA->SetHistoRatioRangeAndNBins(0.,2.,100);
304     emcalQA->SetHistoVertexDistRangeAndNBins(0.,100.,100);
305     emcalQA->SetHistoNClusterCellRangeAndNBins(0,500,500);
306     emcalQA->SetHistoZRangeAndNBins(-400,400,100);
307     emcalQA->SetHistoRRangeAndNBins(400,450,25);
308     emcalQA->SetHistoV0SignalRangeAndNBins(0,5000,100);
309     emcalQA->SetHistoV0MultiplicityRangeAndNBins(0,5000,100);
310     emcalQA->SetHistoTrackMultiplicityRangeAndNBins(0,5000,100);
311   }//withQA
312   
313   // #### Configure Maker ####
314   AliAnaPartCorrMaker * maker = new AliAnaPartCorrMaker();
315   maker->SetReader(reader);//pointer to reader
316   maker->SetCaloUtils(cu); //pointer to calorimeter utils
317   Int_t n = 0;//Analysis number, order is important
318   // Particle selection analysis
319   maker->AddAnalysis(anaphoton,n++);
320   maker->AddAnalysis(anapi0,n++);
321   if(withQA)maker->AddAnalysis(emcalQA,n++);  
322   maker->SetAnaDebug(-1)  ;
323   maker->SwitchOnHistogramsMaker()  ;
324   if(data.Contains("delta")) maker->SwitchOffAODsMaker()  ;
325   else                       maker->SwitchOnAODsMaker()  ;
326         
327   if(kPrintSettings) maker->Print("");
328   
329   printf("======================== \n");
330   printf(" End Configuration of Pi0 analysis with detector %s \n",calorimeter.Data());
331   printf("======================== \n");
332   
333   // Create task
334   //===========================================================================
335   AliAnalysisTaskParticleCorrelation * task = new AliAnalysisTaskParticleCorrelation (Form("PartCorr%s",calorimeter.Data()));
336   task->SetConfigFileName(""); //Don't configure the analysis via configuration file.
337   //task->SetDebugLevel(-1);
338   task->SetBranches("ESD:AliESDRun.,AliESDHeader"); //just a trick to get Constantin's analysis to work
339   if(data=="ESD")task->SelectCollisionCandidates();
340   task->SetAnalysisMaker(maker);
341   //if(!kSimulation)task->SelectCollisionCandidates(); //AliPhysicsSelection has to be attached before.
342   mgr->AddTask(task);
343   
344   //Create containers
345   char name[128];
346   sprintf(name,"PartCorr_%s",calorimeter.Data());
347   cout<<"Name of task "<<name<<endl;
348   
349   if(outputfile.Length()==0)outputfile = AliAnalysisManager::GetCommonFileName(); 
350
351   AliAnalysisDataContainer *cout_pc   = mgr->CreateContainer(calorimeter.Data(), TList::Class(), 
352                                                               AliAnalysisManager::kOutputContainer, 
353                                                               Form("%s:Pi0",outputfile.Data()));
354         
355   AliAnalysisDataContainer *cout_cuts = mgr->CreateContainer(Form("%sCuts",calorimeter.Data()), TList::Class(), 
356                                                               AliAnalysisManager::kParamContainer, 
357                                                               Form("%s:Pi0Cuts",outputfile.Data()));
358   // Create ONLY the output containers for the data produced by the task.
359   // Get and connect other common input/output containers via the manager as below
360   //==============================================================================
361   mgr->ConnectInput  (task, 0, mgr->GetCommonInputContainer());
362   // AOD output slot will be used in a different way in future
363   if(!data.Contains("delta")   && outputAOD) mgr->ConnectOutput (task, 0, mgr->GetCommonOutputContainer());
364   mgr->ConnectOutput (task, 1, cout_pc);
365   mgr->ConnectOutput (task, 2, cout_cuts);
366   
367   return task;
368 }
369
370