]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGGA/CaloTrackCorrelations/macros/AddTaskGammaJetCorrelation.C
Merge branch 'feature-movesplit'
[u/mrichter/AliRoot.git] / PWGGA / CaloTrackCorrelations / macros / AddTaskGammaJetCorrelation.C
1 // Configuration macro for analysis of photon-jet analysis
2 // Author: Adam Matyja
3 // based on AddTaskIsoPhoton by Gustavo Conesa & Marie Germain.
4
5 //new macro
6 TString kGammaJetCorrelationName          = "";
7
8 AliAnalysisTaskCaloTrackCorrelation *AddTaskGammaJetCorrelation(const Float_t  isoCone       = 0.4,
9                                                                 const Float_t  isoPth        = 0.5,
10                                                                 const Double_t maxLambda0Cut = 0.5,
11                                                                 const Int_t    maxNLMcut     = 2,
12                                                                 const Bool_t   timecut       = kFALSE,
13                                                                 const TString  calorimeter   = "EMCAL",
14                                                                 const Bool_t   simulation    = kFALSE,
15                                                                 const Bool_t   eventsel      = kFALSE,
16                                                                 const Bool_t   exotic        = kTRUE,
17                                                                 const Bool_t   nonlin        = kFALSE,
18                                                                 const TString  collision     = "pp",
19                                                                 const TString  trigger       = "MB",
20                                                                 const TString  firedTrigger  = "EG1",
21                                                                 const TString  clustersArray = "V1",
22                                                                 const Bool_t   mix           = kTRUE,
23                                                                 const Bool_t   tm            = kTRUE,
24                                                                 const Int_t    minCen        = -1,
25                                                                 const Int_t    maxCen        = -1,
26                                                                 const TString  jetBranchName = "clustersAOD_ANTIKT04_B0_Filter00272_Cut00150_Skip00",
27                                                                 const TString  jetBkgBranchName = "jeteventbackground_clustersAOD_KT04_B0_Filter00768_Cut00150_Skip00",
28                 const Float_t  jetMinPt      = 0,
29                 const Float_t  minDeltaPhi   = 1.5,
30                                                                 const Float_t  maxDeltaPhi   = 4.5,
31                                                                 const Float_t  minPtRatio    = 0,
32                                                                 const Float_t  maxPtRatio    = 5,   
33                                                                 const Int_t    debug         = -1,
34                                                                 const Bool_t   printSettings = kFALSE,
35                                                                 const Double_t scaleFactor   = -1
36                                                                 )
37 {
38   // Creates a CaloTrackCorr task, configures it and adds it to the analysis manager.
39
40   // Get the pointer to the existing analysis manager via the static access method.
41   
42   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
43   if (!mgr) 
44   {
45     ::Error("AddTask", "No analysis manager to connect to.");
46     return NULL;
47   }  
48   
49   // Check the analysis type using the event handlers connected to the analysis manager.
50   
51   if (!mgr->GetInputEventHandler()) 
52   {
53     ::Error("AddTask", "This task requires an input event handler");
54     return NULL;
55   }
56   
57   // Make sure the B field is enabled for track selection, some cuts need it
58   ((AliInputEventHandler*)mgr->GetInputEventHandler())->SetNeedField(kTRUE);
59
60 //  inputDataType = "AOD";
61 //  if(!kData.Contains("delta"))
62 //    inputDataType = mgr->GetInputEventHandler()->GetDataType(); // can be "ESD" or "AOD"
63   
64   //input jets
65   TString     deltaAODJetName   = "AliAOD.Jets.root"; //Jet input AOD name
66   if(deltaAODJetName.Length()!=0)
67     {
68       // External file with Jets
69      // aodHandler->AddFriend(deltaAODJetName.Data());
70       mgr->RegisterExtraFile(deltaAODJetName.Data());
71       cout<<"Jet file registered "<<endl;
72       cout<<"Extra files: "<<mgr->GetExtraFiles()<<endl;
73     }
74
75
76
77   Bool_t useKinematics = kFALSE;
78   useKinematics = (mgr->GetMCtruthEventHandler())?kTRUE:kFALSE;
79
80   // Name for containers
81   
82   //kGammaJetCorrelationName = Form("%s_Trig%s_Cl%s_TM%d_R%1.1f_Pt%1.1f",calorimeter.Data(), trigger.Data(),clustersArray.Data(),tm,cone,pth);
83   //  kGammaJetCorrelationName = Form("%s_Trig%s_Cl%s_TM%d",calorimeter.Data(), trigger.Data(),clustersArray.Data(),tm);
84   kGammaJetCorrelationName = Form("%s_Trig%s_Fired%s_Cl%s_TM%d_l02%1.2f",calorimeter.Data(), trigger.Data(),firedTrigger.Data(),clustersArray.Data(),tm,maxLambda0Cut);//<<<---changed here
85
86   
87   if(collision=="PbPb" && maxCen>=0) kGammaJetCorrelationName+=Form("Cen%d_%d",minCen,maxCen);
88     
89   printf("<<<< NAME: %s >>>>>\n",kGammaJetCorrelationName.Data());
90   
91   // #### Configure analysis ####
92     
93   AliAnaCaloTrackCorrMaker * maker = new AliAnaCaloTrackCorrMaker();
94   printf("SCALE FACTOR %e\n",scaleFactor);
95   maker->SetScaleFactor(scaleFactor); // for MC, negative (not scaled) by default
96   
97   // General frame setting and configuration
98   maker->SetReader   (ConfigureReader(mgr->GetInputEventHandler()->GetDataType(),calorimeter,useKinematics,simulation,eventsel,nonlin,timecut,collision,trigger,firedTrigger,clustersArray,jetBranchName,jetBkgBranchName,mix,minCen,maxCen,debug,printSettings)   ); 
99   maker->SetCaloUtils(ConfigureCaloUtils(clustersArray,collision,nonlin,exotic,simulation,timecut,debug,printSettings)); 
100   
101   // Analysis tasks setting and configuration
102   Int_t n = 0;//Analysis number, order is important
103
104   // Isolation settings
105   Int_t partInCone = AliIsolationCut::kNeutralAndCharged; // kOnlyCharged;
106   Int_t thresType  = AliIsolationCut::kPtThresIC;//  AliIsolationCut::kSumPtFracIC ; 
107   //Float_t isoCone = -1;
108   //Float_t isoPth  = -1;
109   
110   maker->AddAnalysis(ConfigurePhotonAnalysis(calorimeter,tm,simulation,maxLambda0Cut,maxNLMcut,debug,printSettings), n++); // Photon cluster selection
111   maker->AddAnalysis(ConfigureIsolationAnalysis(calorimeter,collision,"Photon", partInCone,thresType, isoCone, isoPth,tm,kFALSE,simulation,debug,printSettings), n++); // Photon isolation   
112   maker->AddAnalysis(ConfigurePhotonJetAnalysis(calorimeter,isoCone,jetMinPt,minDeltaPhi,maxDeltaPhi,minPtRatio,maxPtRatio,simulation,debug,printSettings), n++);// photon-jet correlation analysis
113
114   maker->SetAnaDebug(debug)  ;
115   maker->SwitchOnHistogramsMaker()  ;
116   //if(kData.Contains("delta")) maker->SwitchOffAODsMaker() ;
117   //else                        maker->SwitchOnAODsMaker()  ;
118   
119   if(printSettings) maker->Print("");
120   
121   printf("<< End Configuration of %d analysis for calorimeter %s >>\n",n, calorimeter.Data());
122   // Create task
123   
124   AliAnalysisTaskCaloTrackCorrelation * task = new AliAnalysisTaskCaloTrackCorrelation (Form("CaloTrackCorr%s",kGammaJetCorrelationName.Data()));
125   task->SetConfigFileName(""); //Don't configure the analysis via configuration file.
126   task->SetDebugLevel(debug);
127   task->SetBranches("ESD:AliESDRun.,AliESDHeader"); 
128   task->SetAnalysisMaker(maker);
129   mgr->AddTask(task);
130   
131   //Create containers
132   
133   //if(outputfile.Length()==0) outputfile = AliAnalysisManager::GetCommonFileName(); 
134   TString outputfile = AliAnalysisManager::GetCommonFileName();
135   
136   AliAnalysisDataContainer *cout_pc   = mgr->CreateContainer(kGammaJetCorrelationName, TList::Class(), 
137                                                              AliAnalysisManager::kOutputContainer, 
138                                                              Form("%s",outputfile.Data()));
139         
140   AliAnalysisDataContainer *cout_cuts = mgr->CreateContainer(Form("Param_%s",kGammaJetCorrelationName.Data()), TList::Class(), 
141                                                              AliAnalysisManager::kParamContainer, 
142                                                              "AnalysisParameters.root");
143   
144   // Create ONLY the output containers for the data produced by the task.
145   // Get and connect other common input/output containers via the manager as below
146   //==============================================================================
147   mgr->ConnectInput  (task, 0, mgr->GetCommonInputContainer());
148   // AOD output slot will be used in a different way in future
149   //if(!kData.Contains("delta")   && outputAOD) mgr->ConnectOutput (task, 0, mgr->GetCommonOutputContainer());
150   mgr->ConnectOutput (task, 1, cout_pc);
151   mgr->ConnectOutput (task, 2, cout_cuts);
152     
153   if(!mix)
154   {    
155     UInt_t mask =  SetTriggerMaskFromName(trigger);
156     task->SelectCollisionCandidates(mask);
157   } 
158   
159   return task;
160 }
161
162 //____________________________________
163 AliCaloTrackReader * ConfigureReader(TString inputDataType = "AOD",TString calorimeter = "EMCAL",Bool_t useKinematics = kFALSE,
164                                      Bool_t simulation = kFALSE,Bool_t   eventsel      = kFALSE,Bool_t nonlin = kTRUE, Bool_t timecut = kFALSE,
165                                      TString  collision     = "pp",TString trigger="MB",TString firedTrigger="EG1",
166                                      TString  clustersArray = "V1", TString  jetBranchName = "jets", TString  jetBkgBranchName = "jets",
167                                      Bool_t  mix           = kFALSE,
168                                      Float_t minCen = -1, Float_t maxCen = -1,
169                                      Int_t debug = -1,Bool_t printSettings = kFALSE)
170 {
171   
172   Bool_t useTender=kTRUE;
173
174   if(simulation)
175   {
176     if (!useKinematics && inputDataType=="AOD") useKinematics = kTRUE; //AOD primary should be available ...
177   }
178   
179   cout<<"********* ACCESS KINE? "<<useKinematics<< endl;
180
181
182
183   AliCaloTrackReader * reader = 0;
184   if     (inputDataType == "AOD") reader = new AliCaloTrackAODReader();
185   else if(inputDataType == "ESD") reader = new AliCaloTrackESDReader();
186   else printf("AliCaloTrackReader::ConfigureReader() - Data not known InputData=%s\n",inputDataType.Data());
187   
188   reader->SetDebug(debug);//10 for lots of messages
189
190   if(useTender){
191     reader->SwitchOffTriggerPatchMatching();
192     reader->SwitchOffBadTriggerEventsRemoval();
193   }
194
195   if(simulation)
196   {
197     // Event rejection cuts for jet-jet simulations, do not use in other
198     reader->SetPtHardAndJetPtComparison(kTRUE);
199     reader->SetPtHardAndJetPtFactor(4);
200     
201     reader->SetPtHardAndClusterPtComparison(kTRUE);
202     reader->SetPtHardAndClusterPtFactor(1.5);
203   }
204
205   //Delta AOD?
206   //reader->SetDeltaAODFileName("");
207   //if(kOutputAOD) reader->SwitchOnWriteDeltaAOD()  ;
208   
209   // MC settings
210   if(useKinematics){
211     if(inputDataType == "ESD"){
212       reader->SwitchOnStack();          
213       reader->SwitchOffAODMCParticles(); 
214     }
215     else if(inputDataType == "AOD"){
216       reader->SwitchOffStack();          
217       reader->SwitchOnAODMCParticles(); 
218     }
219   }  
220   
221   //------------------------
222   // Detector input filling
223   //------------------------
224   
225   //Min cluster/track E
226   reader->SetEMCALEMin(0.3); 
227   //reader->SetEMCALEMin(0.);// <<<----changed here 
228   reader->SetEMCALEMax(1000); 
229   reader->SetPHOSEMin(0.3);
230   reader->SetPHOSEMax(1000);
231   //  reader->SetCTSPtMin(0.2);
232   reader->SetCTSPtMin(0.15);// <<<----changed here 
233   reader->SetCTSPtMax(1000);
234
235   //-----------------------------------------------------------------
236   // Jet part
237   //-----------------------------------------------------------------
238   reader->SwitchOnNonStandardJets();
239   //reader->SetInputNonStandardJetBranchName("clustersAOD_ANTIKT04_B0_Filter00768_Cut00150_Skip00");
240   //reader->SetInputNonStandardJetBranchName("clustersAOD_ANTIKT04_B1_Filter00768_Cut00150_Skip00");//in PbPb
241   //reader->SetInputNonStandardJetBranchName("clustersAOD_ANTIKT04_B0_Filter00272_Cut00150_Skip00");//in pp 2.76 LHC11a,7 LHC11c
242   //reader->SetInputNonStandardJetBranchName("clustersAOD_ANTIKT04_B0_Filter00768_Cut00150_Skip02");//in pp 7 LHC13e4 MC
243   //reader->SetInputNonStandardJetBranchName("clustersAOD_ANTIKT04_B0_Filter00272_Cut00150_Skip00");//in pp 7 LHC12a15f MC
244   reader->SetInputNonStandardJetBranchName(jetBranchName.Data());
245   if(jetBkgBranchName.Length()!=0) {
246     reader->SwitchOnBackgroundJets();
247     reader->SetInputBackgroundJetBranchName(jetBkgBranchName.Data());
248   } else {
249     reader->SwitchOffBackgroundJets();
250   }
251   //reader->SetInputBackgroundJetBranchName("jeteventbackground_clustersAOD_KT04_B0_Filter00768_Cut00150_Skip00");//in pp 7 LHC13e4 MC
252
253
254   // Time cuts
255   if(simulation) 
256   {
257     reader->SwitchOffUseTrackTimeCut();
258     reader->SetEMCALTimeCut(-1e10,1e10); // Open time cut
259     reader->SwitchOffUseEMCALTimeCut() ;   
260     reader->SwitchOffUseParametrizedTimeCut();
261   }
262   else
263   {
264     reader->SwitchOffUseParametrizedTimeCut();
265     if(timecut)
266      {
267         printf("Set time cut \n");
268         reader->SwitchOnUseEMCALTimeCut();
269         //Absolute window
270         reader->SetEMCALTimeCut(-30.,30.); // default is -25ns-20ns
271       }
272     else
273       {
274         printf("Off time cuts time cut \n");
275         reader->SwitchOffUseEMCALTimeCut();
276         //Absolute window
277         reader->SetEMCALTimeCut(-1.e6,1.e6);
278       }
279
280     //if(kCalibT)
281     //{ 
282       //printf("Set time cut parameters for run %d\n",kRunNumber);
283       //reader->SetEMCALTimeCut(-20,20); 
284       //reader->SwitchOnUseParametrizedTimeCut();
285       //if     (kRunNumber >= 151636 && kRunNumber <= 155384 )
286       //{
287       //  printf("Set time parameters for LHC11c\n");
288       //  reader->SetEMCALParametrizedMinTimeCut(0,-5  ); reader->SetEMCALParametrizedMinTimeCut(1,-1 ); reader->SetEMCALParametrizedMinTimeCut(2, 1.87); reader->SetEMCALParametrizedMinTimeCut(3, 0.4);   
289       //  reader->SetEMCALParametrizedMaxTimeCut(0, 3.5); reader->SetEMCALParametrizedMaxTimeCut(1, 50); reader->SetEMCALParametrizedMaxTimeCut(2, 0.15); reader->SetEMCALParametrizedMaxTimeCut(3, 1.6);   
290       //}
291       //else if(kRunNumber >= 156447 && kRunNumber <= 159635 )
292       //{
293       //  printf("Set time parameters for LHC11d\n");
294       //  reader->SetEMCALParametrizedMinTimeCut(0,-5);  reader->SetEMCALParametrizedMinTimeCut(1,-1 );  reader->SetEMCALParametrizedMinTimeCut(2, 3.5 ); reader->SetEMCALParametrizedMinTimeCut(3, 1.  );   
295       //  reader->SetEMCALParametrizedMaxTimeCut(0, 5);  reader->SetEMCALParametrizedMaxTimeCut(1, 50);  reader->SetEMCALParametrizedMaxTimeCut(2, 0.45); reader->SetEMCALParametrizedMaxTimeCut(3, 1.25);   
296       //}
297       //else 
298       //{
299       //  printf("*** Fixed time cut 20 ns *** \n");
300       //  reader->SetEMCALTimeCut(-20,20);
301       //}
302 //      
303 //    }
304 //    else
305 //    {
306 //      reader->SwitchOffUseEMCALTimeCut();
307 //      reader->SetEMCALTimeCut(-1e10,1e10); // Open time cut
308 //      reader->SwitchOffUseParametrizedTimeCut(); 
309 //    }
310
311   }  
312   
313   reader->SwitchOnFiducialCut();
314   //reader->SwitchOffFiducialCut();// <<<----changed here 
315   //reader->GetFiducialCut()->SetSimpleCTSFiducialCut(0.8, 0, 360) ;
316   reader->GetFiducialCut()->SetSimpleCTSFiducialCut(0.9, 0, 360) ;// <<<--- changed here
317
318   // Tracks
319
320   //  reader->SwitchOffCTS();//here changed 0n->off
321   reader->SwitchOnCTS();//here changed 0n->off
322
323   reader->SwitchOffRecalculateVertexBC();
324   reader->SwitchOffVertexBCEventSelection();
325   
326   reader->SwitchOffUseTrackTimeCut();
327   reader->SetTrackTimeCut(0,50);
328
329   if(inputDataType=="ESD")
330   {
331     //Hybrids 2011
332     AliESDtrackCuts * esdTrackCuts  = CreateTrackCutsPWGJE(10001008);
333     reader->SetTrackCuts(esdTrackCuts);
334     AliESDtrackCuts * esdTrackCuts2 = CreateTrackCutsPWGJE(10011008);
335     reader->SetTrackComplementaryCuts(esdTrackCuts2);
336     
337     //Hybrids 2010
338     //AliESDtrackCuts * esdTrackCuts  = CreateTrackCutsPWGJE(10001006);
339     //reader->SetTrackCuts(esdTrackCuts);
340     //AliESDtrackCuts * esdTrackCuts2 = CreateTrackCutsPWGJE(10041006);
341     //reader->SetTrackComplementaryCuts(esdTrackCuts2);
342   }
343   else if(inputDataType=="AOD")
344   {
345     reader->SwitchOnAODHybridTrackSelection(); // Check that the AODs have Hybrids!!!!
346     reader->SetTrackStatus(AliVTrack::kITSrefit);    
347     //reader->SetTrackFilterMask(128);           // Filter bit, not mask, use if off hybrid
348   }
349   
350   // Calorimeter
351   
352   reader->SetEMCALClusterListName(clustersArray);
353   if(clustersArray == "" && !useTender)
354   {
355     printf("**************** Standard EMCAL clusters branch analysis **************** \n");
356     reader->SwitchOnClusterRecalculation();
357     // Check in ConfigureCaloUtils that the recalibration and bad map are ON 
358   }
359   else 
360   {
361     printf("**************** Input for analysis is Clusterizer %s **************** \n", clustersArray.Data());
362     reader->SwitchOffClusterRecalculation();
363   }  
364   
365   if(!nonlin) reader->SwitchOffClusterELinearityCorrection();
366   else        reader->SwitchOnClusterELinearityCorrection();
367
368   if(calorimeter == "EMCAL") {
369     reader->SwitchOnEMCALCells();  
370     reader->SwitchOnEMCAL();
371   }
372   if(calorimeter == "PHOS") { 
373     reader->SwitchOnPHOSCells();  
374     reader->SwitchOnPHOS();
375   }
376   
377   // for case data="deltaAOD", no need to fill the EMCAL/PHOS cluster lists
378   //if(kData.Contains("delta"))
379   //{
380   //  reader->SwitchOffEMCAL();
381   //  reader->SwitchOffPHOS();
382   //  reader->SwitchOffEMCALCells(); 
383   //  reader->SwitchOffPHOSCells(); 
384   //}
385   
386   //-----------------
387   // Event selection
388   //-----------------
389   
390   //if(!useKinematics) reader->SetFiredTriggerClassName("CEMC7EGA-B-NOPF-CENTNOTRD"); // L1 Gamma
391   if(!useKinematics) {
392     if(collision =="pPb" && trigger=="EMCEGA") {
393       reader->SetFiredTriggerClassName(firedTrigger);
394     }
395   }
396
397   // For mixing with AliAnaParticleHadronCorrelation switch it off
398   if(mix)
399   {
400     reader->SwitchOffEventTriggerAtSE();
401     UInt_t mask =  SetTriggerMaskFromName(trigger);
402     reader->SetEventTriggerMaks(mask); // Only for mixing and SwitchOffEventTriggerAtSE();
403     //reader->SetMixEventTriggerMaks(AliVEvent::kMB); // Careful, not all productions work with kMB, try kINT7, kINT1, kAnyINT
404     reader->SetMixEventTriggerMaks(AliVEvent::kAnyINT); // Careful, not all productions work with kMB, try kINT7, kINT1, kAnyINT
405
406     printf("---Trigger selection done in AliCaloTrackReader!!!\n");
407   }
408   else 
409     reader->SwitchOnEventTriggerAtSE();
410   
411   reader->SetZvertexCut(10.);                // Open cut
412   reader->SwitchOnPrimaryVertexSelection(); // and besides primary vertex
413   reader->SwitchOnRejectNoTrackEvents();//<<<--- changed here, new added
414
415   if(eventsel)
416   {
417     reader->SwitchOnPileUpEventRejection();   // remove pileup by default  
418     reader->SwitchOnV0ANDSelection() ;        // and besides v0 AND
419   }
420   else 
421   {
422     reader->SwitchOffPileUpEventRejection();  // remove pileup by default   
423     reader->SwitchOffV0ANDSelection() ;        // and besides v0 AND
424   }
425     
426   if(collision=="PbPb") 
427   {
428     // Centrality
429     reader->SetCentralityClass("V0M");
430     reader->SetCentralityOpt(10);  // 10 (c= 0-10, 10-20 ...), 20  (c= 0-5, 5-10 ...) or 100 (c= 1, 2, 3 ..)
431     reader->SetCentralityBin(minCen,maxCen); // Accept all events, if not select range
432     
433     // Event plane (only used in Maker and mixing for AliAnaPi0/AliAnaHadronCorrelation for the moment)
434     reader->SetEventPlaneMethod("V0");
435   }
436   
437   if(printSettings) reader->Print("");
438   
439   return reader;
440   
441 }
442
443 //_______________________________________
444 AliCalorimeterUtils* ConfigureCaloUtils( TString  clustersArray = "V1",TString  collision     = "pp",Bool_t nonlin = kTRUE,Bool_t exotic = kTRUE ,Bool_t simulation = kFALSE,Bool_t timecut = kFALSE,Int_t debug = -1,Bool_t printSettings = kFALSE)
445 {
446   
447   Bool_t useTender=kTRUE;
448
449   AliCalorimeterUtils *cu = new AliCalorimeterUtils;
450   cu->SetDebug(debug);
451   
452   // Remove clusters close to borders, at least max energy cell is 1 cell away 
453   //cu->SetNumberOfCellsFromEMCALBorder(0);// <<<----changed here 
454   cu->SetNumberOfCellsFromEMCALBorder(1);
455   cu->SetNumberOfCellsFromPHOSBorder(2);
456   
457   // Search of local maxima in cluster
458   if(collision=="pp" || collision=="pPb")
459   {
460     cu->SetLocalMaximaCutE(0.1);
461     cu->SetLocalMaximaCutEDiff(0.03);
462   }
463   else 
464   {
465     cu->SetLocalMaximaCutE(0.2);
466     cu->SetLocalMaximaCutEDiff(0.03);
467   }
468   
469   cu->SwitchOffClusterPlot();
470
471   //if(kRecalTM) cu->SwitchOnRecalculateClusterTrackMatching(); // Done in clusterization
472   //else         
473   cu->SwitchOffRecalculateClusterTrackMatching();
474   
475   if(useTender)
476     cu->SwitchOffBadChannelsRemoval() ;
477   else
478     cu->SwitchOnBadChannelsRemoval() ;
479
480   //EMCAL settings
481   if(!simulation)
482     cu->SwitchOnLoadOwnEMCALGeometryMatrices();
483
484   if(!useTender){  
485     AliEMCALRecoUtils * recou = cu->GetEMCALRecoUtils();
486     
487     if(!simulation)
488       {
489         cu->SwitchOnRecalibration(); // Check the reader if it is taken into account during filtering
490         //if(clustersArray == "" && !kTender) cu->SwitchOnRunDepCorrection(); 
491         if(clustersArray == "") cu->SwitchOnRunDepCorrection(); 
492       }
493     
494     cu->SwitchOnEMCALOADB();//FIX ME!!!
495
496     gROOT->LoadMacro("$ALICE_ROOT/PWGGA/EMCALTasks/macros/ConfigureEMCALRecoUtils.C");
497     ConfigureEMCALRecoUtils(recou,
498                             simulation,                             
499                             exotic,
500                             nonlin,
501                             kFALSE, // e calib
502                             kFALSE, // bad map
503                             kFALSE); // time calib
504     //kCalibE, 
505     //kBadMap,
506     //kCalibT);   
507     recou->SetExoticCellDiffTimeCut(1e10);
508     if(timecut) recou->SetExoticCellDiffTimeCut(50.);
509   }//end tender
510
511
512   if( nonlin ) 
513   { 
514 //    printf("ConfigureCaloUtils() - Apply non linearity to EMCAL\n");
515 //    //CAREFUL only for the latest simulation
516 //    recou->SetNonLinearityFunction(AliEMCALRecoUtils::kBeamTestCorrected);
517 //    recou->SetNonLinearityParam(0,9.81039e-01);
518 //    recou->SetNonLinearityParam(1,1.13508e-01);
519 //    recou->SetNonLinearityParam(2,1.00173e+00); 
520 //    recou->SetNonLinearityParam(3,9.67998e-02);
521 //    recou->SetNonLinearityParam(4,2.19381e+02);
522 //    recou->SetNonLinearityParam(5,6.31604e+01);
523 //    recou->SetNonLinearityParam(6,1);
524     printf("*** SET cluster non linearity correction ***\n");
525     cu->SwitchOnCorrectClusterLinearity();
526   }
527     
528   if(!useTender){
529     printf("ConfigureCaloUtils() - EMCAL Recalibration ON? %d %d\n",recou->IsRecalibrationOn(), cu->IsRecalibrationOn());
530     printf("ConfigureCaloUtils() - EMCAL BadMap        ON? %d %d\n",recou->IsBadChannelsRemovalSwitchedOn(), cu->IsBadChannelsRemovalSwitchedOn());
531   }
532
533   cu->SetNumberOfSuperModulesUsed(10);
534   // PHOS 
535   cu->SwitchOffLoadOwnPHOSGeometryMatrices();
536     
537   if(printSettings) cu->Print("");
538   
539   return cu;
540   
541 }
542
543 //_____________________________________
544 AliAnaPhoton* ConfigurePhotonAnalysis(TString calorimeter = "EMCAL",Bool_t tm = kFALSE,Bool_t simulation = kFALSE,Double_t maxLambda0Cut=0.5,Int_t maxNLMcut=2,Int_t debug = -1,Bool_t printSettings = kFALSE)
545 {
546   
547   AliAnaPhoton *ana = new AliAnaPhoton();
548   ana->SetDebug(debug); //10 for lots of messages
549   
550   // cluster selection cuts
551   
552   ana->SwitchOffFiducialCut();
553
554   ana->SetCalorimeter(calorimeter);
555   
556   if(calorimeter == "PHOS")
557   {
558     ana->SetNCellCut(2);// At least 3 cells
559     ana->SetMinPt(0.3);
560     ana->SetMinDistanceToBadChannel(2, 4, 5);
561     ana->SetTimeCut(-1e10,1e10); // open cut
562   }
563   else 
564   {//EMCAL
565     ana->SetNCellCut(1);// At least 2 cells
566     ana->SetMinEnergy(0.3); // avoid mip peak at E = 260 MeV
567     ana->SetMaxEnergy(1000); 
568     //ana->SetTimeCut(-1e10,1e10); // open cut, usual time window of [425-825] ns if time recalibration is off //<<<---modified here
569     // restrict to less than 100 ns when time calibration is on 
570     ana->SetMinDistanceToBadChannel(2, 4, 6); 
571     // Not useful if M02 cut is already strong
572     ana->SetNLMCut(1, maxNLMcut) ;//[1,2]
573     //ana->SetNLMCut(1, 10) ;//<<<----changed here 
574     //ana->SetNLMCut(1, 1) ;//<<<----changed here 
575   }
576   
577   if(tm)
578   {
579     ana->SwitchOnTrackMatchRejection() ;
580     ana->SwitchOffTMHistoFill() ;
581   }
582   else
583   {
584     ana->SwitchOffTrackMatchRejection() ;
585     ana->SwitchOnTMHistoFill() ;
586   }
587   
588   
589   //PID cuts (shower shape)
590   ana->SwitchOnCaloPID(); // do PID selection, unless specified in GetCaloPID, selection not based on bayesian
591   AliCaloPID* caloPID = ana->GetCaloPID();
592   //Not used in bayesian
593   
594   //EMCAL
595   caloPID->SetEMCALLambda0CutMax(maxLambda0Cut);//0.27 was before//0.50//<<<----changed here
596   caloPID->SetEMCALLambda0CutMin(0.10);
597   
598   caloPID->SetEMCALDEtaCut(0.025);
599   caloPID->SetEMCALDPhiCut(0.030);
600     
601   //PHOS
602   caloPID->SetPHOSDispersionCut(2.5);
603   caloPID->SetPHOSRCut(2.);
604   //if(kInputData=="AOD") caloPID->SetPHOSRCut(2000.); // Open cut since dX, dZ not stored
605       
606   ana->SwitchOnFillShowerShapeHistograms();  // Filled before photon shower shape selection <<<--- changed here
607   //ana->SwitchOffFillShowerShapeHistograms();  // Filled before photon shower shape selection
608   ana->SwitchOffFillPileUpHistograms();
609
610   // Input / output delta AOD settings
611   
612   //if(!kData.Contains("delta")) 
613   //{
614   ana->SetOutputAODName(Form("Photon%s",kGammaJetCorrelationName.Data()));
615   ana->SetOutputAODClassName("AliAODPWG4ParticleCorrelation");
616   //  //ana->SetOutputAODClassName("AliAODPWG4Particle"); // use if no correlation done
617   //}
618   //else 
619   ana->SetInputAODName(Form("Photon%s",kGammaJetCorrelationName.Data()));
620   
621   //Set Histograms name tag, bins and ranges
622   
623   ana->AddToHistogramsName(Form("AnaPhoton_TM%d_",tm));
624   SetHistoRangeAndNBins(ana->GetHistogramRanges(),calorimeter); // see method below
625   
626   // Number of particle type MC histograms
627   ana->FillNOriginHistograms(20);
628   ana->FillNPrimaryHistograms(20);
629   
630   ConfigureMC(ana,simulation);
631   
632   if(printSettings) ana->Print("");
633   
634   return ana;
635   
636 }
637
638 //____________________________________________________________________________________________________
639 AliAnaParticleIsolation* ConfigureIsolationAnalysis(TString calorimeter = "EMCAL",
640                                                     TString  collision     = "pp",
641                                                     TString particle="Photon", 
642                                                     Int_t  partInCone = AliIsolationCut::kOnlyCharged,
643                                                     Int_t  thresType  = AliIsolationCut::kSumPtFracIC,
644                                                     Float_t cone = 0.3,
645                                                     Float_t pth  = 0.3,
646                                                     Bool_t tm = kFALSE,
647                                                     Bool_t multi      = kFALSE,Bool_t simulation = kFALSE,
648                                                     Int_t debug = -1,
649                                                     Bool_t printSettings = kFALSE)
650 {
651   
652   AliAnaParticleIsolation *ana = new AliAnaParticleIsolation();
653   ana->SetDebug(debug);
654     
655   ana->SwitchOnFiducialCut();
656   //Avoid borders of EMCal
657   if(calorimeter=="EMCAL")
658     ana->GetFiducialCut()->SetSimpleEMCALFiducialCut(0.6, 86, 174) ;
659
660   // Same Eta as EMCal, cut in phi if EMCAL was triggering
661   if(particle=="Hadron"  || particle.Contains("CTS"))
662   {
663     //if(trigger.Contains("EMC"))
664     //  ana->GetFiducialCut()->SetSimpleCTSFiducialCut  (0.6, 260, 360) ;
665     //else
666       ana->GetFiducialCut()->SetSimpleCTSFiducialCut  (0.6, 0, 360) ;    
667   }
668   
669   ana->SetMinPt(10);//<<---changed here
670   
671   // Input / output delta AOD settings
672   
673   ana->SetInputAODName(Form("%s%s",particle.Data(),kGammaJetCorrelationName.Data()));
674   ana->SetAODObjArrayName(Form("IC%s_%s",particle.Data(),kGammaJetCorrelationName.Data())); 
675   
676   ana->SetCalorimeter(calorimeter);
677   
678   if(!tm)  ana->SwitchOnTMHistoFill();
679   else      ana->SwitchOffTMHistoFill();
680   
681   //if(particle=="Photon")ana->SwitchOnSSHistoFill();
682   //else                  ana->SwitchOffSSHistoFill();
683   
684   ana->SwitchOffSSHistoFill();
685   ana->SwitchOffFillPileUpHistograms();
686
687   //Do settings for main isolation cut class
688   AliIsolationCut * ic =  ana->GetIsolationCut();       
689   ic->SetDebug(debug);
690   
691   if(cone >0 && pth > 0)
692   {
693     ic->SetPtThreshold(pth);
694     ic->SetConeSize(cone);
695   }
696   else
697   {
698     if(collision=="pp") 
699     {
700       ic->SetPtThreshold(1.);//<<---changed here was 0.5,1
701       ic->SetConeSize(0.3);//<<---changed here was 0.4
702     }
703     if(collision=="pPb")
704       {
705         ic->SetPtThreshold(1.0);
706         ic->SetConeSize(0.3);
707       }
708
709     if(collision=="PbPb")
710     {
711       ic->SetPtThreshold(3.);
712       //ic->SetPtThreshold(1.);
713       ic->SetConeSize(0.3);
714     }
715   }
716   
717   ic->SetPtFraction(0.1);
718   ic->SetSumPtThreshold(1.0) ;
719   ic->SetParticleTypeInCone(partInCone);
720   ic->SetICMethod(thresType);
721   
722   //Do or not do isolation with previously produced AODs.
723   //No effect if use of SwitchOnSeveralIsolation()
724   ana->SwitchOffReIsolation();
725   
726   //Multiple IC
727   if(multi) 
728   {
729     ic->SetConeSize(1.);    // Take all for first iteration
730     ic->SetPtThreshold(100);// Take all for first iteration
731     ana->SwitchOnSeveralIsolation() ;
732     ana->SetAODObjArrayName(Form("MultiIC%sTM%d",particle.Data(),tm));
733      
734     ana->SetNCones(4);
735     ana->SetNPtThresFrac(4);
736     ana->SetConeSizes(0,0.3);       ana->SetConeSizes(1,0.4);
737     ana->SetConeSizes(2,0.5);       ana->SetConeSizes(3,0.6);
738     ana->SetPtThresholds(0, 0.5);   ana->SetPtThresholds(1, 1);     ana->SetPtThresholds(2, 2);
739     ana->SetPtFractions (0, 0.05) ; ana->SetPtFractions (1, 0.1);   ana->SetPtFractions (2, 0.2) ;  ana->SetPtFractions (3, 0.3) ;
740     ana->SetSumPtThresholds(0, 1) ; ana->SetSumPtThresholds(1, 3) ; ana->SetSumPtThresholds(2, 5);  ana->SetSumPtThresholds(3, 7)  ;
741     
742     ana->SwitchOffTMHistoFill();
743     ana->SwitchOffSSHistoFill();
744   }
745   else      
746     ana->SwitchOffSeveralIsolation() ;
747   
748   AliCaloPID* caloPID = ana->GetCaloPID();
749   caloPID->SetEMCALDEtaCut(0.025);
750   caloPID->SetEMCALDPhiCut(0.030);
751   
752   //Set Histograms name tag, bins and ranges
753   
754   if(!multi)ana->AddToHistogramsName(Form("AnaIsol%s_TM%d_",particle.Data(),tm));
755   else      ana->AddToHistogramsName(Form("AnaMultiIsol%s_TM%d_",particle.Data(),tm));
756
757   SetHistoRangeAndNBins(ana->GetHistogramRanges(),calorimeter); // see method below
758   
759   if(particle=="Hadron"  || particle.Contains("CTS"))
760   {
761     ana->GetHistogramRanges()->SetHistoPhiRangeAndNBins(0, TMath::TwoPi(), 200) ;
762     ana->GetHistogramRanges()->SetHistoEtaRangeAndNBins(-1.5, 1.5, 300) ;
763   }
764   
765   ConfigureMC(ana,simulation);
766   
767   if(printSettings) ic ->Print("");
768   if(printSettings) ana->Print("");
769   
770   return ana;
771   
772 }
773
774 //________________________________________________________
775 void ConfigureMC(AliAnaCaloTrackCorrBaseClass* ana,Bool_t simulation = kFALSE)
776 {
777   if(simulation) ana->SwitchOnDataMC() ;//Access MC stack and fill more histograms, AOD MC not implemented yet.
778   else            ana->SwitchOffDataMC() ;
779
780   //Set here generator name, default pythia
781   //ana->GetMCAnalysisUtils()->SetMCGenerator("");
782 }  
783
784 //________________________________________________________
785 void SetHistoRangeAndNBins (AliHistogramRanges* histoRanges,TString calorimeter = "EMCAL")
786 {
787   // Set common bins for all analysis and MC histograms filling
788     
789   histoRanges->SetHistoPtRangeAndNBins(-0.25, 99.75, 200) ; // Energy and pt histograms
790   
791   if(calorimeter=="EMCAL")
792   {
793     histoRanges->SetHistoPhiRangeAndNBins(78*TMath::DegToRad(), 182*TMath::DegToRad(), 108) ;
794     histoRanges->SetHistoXRangeAndNBins(-600,90,200); // QA
795     histoRanges->SetHistoYRangeAndNBins(100,450,100); // QA
796
797     histoRanges->SetHistoEtaRangeAndNBins(-0.72, 0.72, 144) ;
798   }
799   else
800   {
801     histoRanges->SetHistoPhiRangeAndNBins(260*TMath::DegToRad(), 320*TMath::DegToRad(), 60) ;
802     histoRanges->SetHistoEtaRangeAndNBins(-0.13, 0.13, 130) ;
803   }
804   
805   histoRanges->SetHistoShowerShapeRangeAndNBins(-0.1, 4.9, 500);
806   
807   // Invariant mass histoRangeslysis
808   histoRanges->SetHistoMassRangeAndNBins(0., 1., 200) ;
809   histoRanges->SetHistoAsymmetryRangeAndNBins(0., 1. , 100) ;
810   
811   // check if time calibration is on
812   //histoRanges->SetHistoTimeRangeAndNBins(-1000.,1000,1000);
813   histoRanges->SetHistoTimeRangeAndNBins(-400.,400,400);
814   histoRanges->SetHistoDiffTimeRangeAndNBins(-200, 200, 800);
815   
816   // track-cluster residuals
817   histoRanges->SetHistoTrackResidualEtaRangeAndNBins(-0.15,0.15,300);
818   histoRanges->SetHistoTrackResidualPhiRangeAndNBins(-0.15,0.15,300);
819   histoRanges->SetHistodRRangeAndNBins(0.,0.15,150);//QA
820
821   // QA, electron, charged
822   histoRanges->SetHistoPOverERangeAndNBins(0,10.,100);
823   histoRanges->SetHistodEdxRangeAndNBins(0.,200.,200);
824   
825   // QA
826   histoRanges->SetHistoFinePtRangeAndNBins(0, 10, 200) ; // bining for fhAmpId
827   histoRanges->SetHistoRatioRangeAndNBins(0.,2.,100);
828   histoRanges->SetHistoVertexDistRangeAndNBins(0.,500.,500);
829   histoRanges->SetHistoNClusterCellRangeAndNBins(0,500,500);
830   histoRanges->SetHistoZRangeAndNBins(-400,400,200);
831   histoRanges->SetHistoRRangeAndNBins(400,450,25);
832   histoRanges->SetHistoV0SignalRangeAndNBins(0,5000,500);
833   histoRanges->SetHistoV0MultiplicityRangeAndNBins(0,5000,500);
834   histoRanges->SetHistoTrackMultiplicityRangeAndNBins(0,5000,500);
835   
836   // Isolation
837   histoRanges->SetHistoPtInConeRangeAndNBins(0, 50 , 250);
838   histoRanges->SetHistoPtSumRangeAndNBins   (0, 100, 250);
839   
840 }
841
842 //_________________
843 UInt_t SetTriggerMaskFromName(TString trigger)
844 {
845   if(trigger=="EMC7")
846   {
847     printf("CaloTrackCorr trigger EMC7\n");
848     return AliVEvent::kEMC7;
849   }
850   else if (trigger=="INT7")
851   {
852     printf("CaloTrackCorr trigger INT7\n");
853     return AliVEvent::kINT7;
854   }
855   else if(trigger=="EMC1")
856   {
857     printf("CaloTrackCorr trigger EMC1\n");
858     return AliVEvent::kEMC1;
859   }
860   else if(trigger=="MB")
861   {
862     printf("CaloTrackCorr trigger MB\n");
863     return AliVEvent::kMB;
864   }  
865   else if(trigger=="PHOS")
866   {
867     printf("CaloTrackCorr trigger PHOS\n");
868     return AliVEvent::kPHI7;
869   }  
870   else if(trigger=="PHOSPb")
871   {
872     printf("CaloTrackCorr trigger PHOSPb\n");
873     return AliVEvent::kPHOSPb;
874   }
875   else if(trigger=="AnyINT")
876   {
877     printf("CaloTrackCorr trigger AnyINT\n");
878     return AliVEvent::kAnyINT;
879   }  
880   else if(trigger=="INT")
881   {
882     printf("CaloTrackCorr trigger AnyINT\n");
883     return AliVEvent::kAny;
884   }
885   else if(trigger=="EMCEGA")
886   {
887     printf("CaloTrackCorr trigger EMC Gamma\n");
888     return AliVEvent::kEMCEGA;
889   } 
890   else if(trigger=="EMCEJE")
891   {
892     printf("CaloTrackCorr trigger EMC Jet\n");
893     return AliVEvent::kEMCEJE;
894   }
895   else if(trigger=="Central")
896   {
897     printf("CaloTrackCorr trigger Central\n");
898     return AliVEvent::kCentral;
899   } 
900   else if(trigger=="CentralEGA")
901   {
902     printf("CaloTrackCorr trigger Central+EMCEGA\n");
903     return (AliVEvent::kCentral | AliVEvent::kEMCEGA);
904   } 
905   else if(trigger=="SemiCentral")
906   {
907     printf("CaloTrackCorr trigger SemiCentral\n");
908     return AliVEvent::kSemiCentral;
909   }
910   else if(trigger=="SemiOrCentral")
911   {
912     printf("CaloTrackCorr trigger SemiCentral Or Central\n");
913     return (AliVEvent::kSemiCentral | AliVEvent::kCentral);
914   }  
915   else if(trigger=="SemiOrCentralOrAnyINT")
916     {
917       printf("CaloTrackCorr trigger SemiCentral Or Central Or AnyINT\n");
918       return (AliVEvent::kSemiCentral | AliVEvent::kCentral | AliVEvent::kAnyINT);
919     }
920
921 }
922
923 AliAnaParticleJetFinderCorrelation* ConfigurePhotonJetAnalysis(TString calorimeter = "EMCAL",Float_t gammaConeSize = 0.3, Float_t  jetMinPt  = 0, 
924                                                                Float_t  minDeltaPhi   = 1.5,Float_t  maxDeltaPhi   = 4.5,
925                                                                Float_t  minPtRatio    = 0,Float_t  maxPtRatio    = 5,
926                                                                Bool_t simulation = kFALSE,Int_t debug = -1,Bool_t printSettings = kFALSE){
927
928   AliAnaParticleJetFinderCorrelation *ana = new AliAnaParticleJetFinderCorrelation();
929   ana->SetDebug(debug);
930   TString particle="Photon";
931   ana->SetInputAODName(Form("%s%s",particle.Data(),kGammaJetCorrelationName.Data()));
932
933   ana->SwitchOffFiducialCut();
934
935   ana->SetConeSize(0.4); //was 1 - cone to calculate FF
936   ana->SelectIsolated(kTRUE); // do correlation with isolated photons <<---changed here
937   ana->SetMakeCorrelationInHistoMaker(kFALSE);
938   ana->SetPtThresholdInCone(0.150);//<<---- change here
939   //ana->SetDeltaPhiCutRange(TMath::Pi()/2.,TMath::Pi()*3./2.);//Mostly Open Cuts 
940   ana->SetDeltaPhiCutRange(minDeltaPhi,maxDeltaPhi);  // Delta phi cut for correlation
941   ana->SetJetConeSize(0.4);//jet cone size / check the reco jet name
942   ana->SetJetMinPt(jetMinPt);//min jet pt
943   ana->SetJetAreaFraction(0.8);//min area fraction was 0.6
944   ana->SetMinPt(0.3);//min cluster pt repeated from reader
945   ana->SetGammaConeSize(gammaConeSize);//isolation cone repeated from isolation ana
946   //ana->SetRatioCutRange(0.01,5.); //Mostly Open Cuts //0.01-5//<<---- change here
947   ana->SetRatioCutRange(minPtRatio,maxPtRatio); // Delta pt cut for correlation
948
949   ana->UseJetRefTracks(kTRUE); //Working now
950   //Set Histograms bins and ranges
951   SetHistoRangeAndNBins(ana->GetHistogramRanges(),calorimeter); // see method below 0,100,200
952   //ana->SetHistoPtRangeAndNBins(0, 50, 200) ;
953   //      ana->SetHistoPhiRangeAndNBins(0, TMath::TwoPi(), 100) ;
954   //      ana->SetHistoEtaRangeAndNBins(-0.7, 0.7, 100) ;
955
956   //  ana->SwitchOnNonStandardJetFromReader();
957   ana->SwitchOnBackgroundJetFromReader();
958   //background subtraction for photons
959   //ana->SwitchOnBackgroundSubtractionGamma();
960   ana->SwitchOffBackgroundSubtractionGamma();
961
962   ana->SwitchOnSaveGJTree();
963   ana->SwitchOnMostOpposite();
964   //ana->SwitchOnMostEnergetic();
965
966
967   //if(useKinematics) ana->SwitchOnDataMC() ;//Access MC stack and fill more histograms
968   if(printSettings) 
969     ana->Print("");
970
971   return ana;
972
973 }