Write Calo QA output to a separate file
[u/mrichter/AliRoot.git] / PWG4 / macros / QA / AddTaskCalorimeterQA.C
1 //
2 // Wagon contacts: EMCAL Gustavo.Conesa.Balbastre@cern.ch
3 //                 PHOS  Yuri.Kharlov@cern.ch
4 //
5 AliAnalysisTaskParticleCorrelation *AddTaskCalorimeterQA(TString data, Bool_t kPrintSettings = kFALSE,Bool_t kSimulation = kFALSE,TString outputFile = "")
6 {
7   // Creates a PartCorr task for calorimeters performance studies, configures it and adds it to the analysis manager.
8   
9   // Get the pointer to the existing analysis manager via the static access method.
10   //==============================================================================
11   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
12   if (!mgr) {
13     ::Error("AddTaskPartCorr", "No analysis manager to connect to.");
14     return NULL;
15   }  
16   
17   // Check the analysis type using the event handlers connected to the analysis manager.
18   //==============================================================================
19   if (!mgr->GetInputEventHandler()) {
20     ::Error("AddTaskPartCorr", "This task requires an input event handler");
21     return NULL;
22   }
23    TString inputDataType = mgr->GetInputEventHandler()->GetDataType(); // can be "ESD" or "AOD"
24   
25   Bool_t kUseKinematics = (mgr->GetMCtruthEventHandler())?kTRUE:kFALSE;
26         
27   cout<<"********* ACCESS KINE? "<<kUseKinematics<<endl;
28         
29    // Configure analysis
30    //===========================================================================
31   
32   //Reader
33   //For this particular analysis few things done by the reader.
34   //Nothing else needs to be set.
35   AliCaloTrackReader * reader = 0x0;
36   if(data=="AOD")      reader = new AliCaloTrackAODReader();
37   else if(data=="ESD") reader = new AliCaloTrackESDReader();
38   //reader->SetDebug(10);//10 for lots of messages
39   reader->SwitchOffEMCAL();
40   reader->SwitchOffPHOS();
41   reader->SwitchOffCTS();
42         
43   if(kUseKinematics){
44                 if(inputDataType == "ESD"){
45                         reader->SwitchOnStack();          
46                         reader->SwitchOffAODMCParticles(); 
47                 }
48                 else if(inputDataType == "AOD"){
49                         reader->SwitchOffStack();          
50                         reader->SwitchOnAODMCParticles(); 
51                 }
52    }
53    //if(!kSimulation) reader->SetFiredTriggerClassName("CINT1B-ABCE-NOPF-ALL");
54    reader->SetDeltaAODFileName(""); //Do not create deltaAOD file, this analysis do not create branches.
55    if(kPrintSettings) reader->Print("");
56         
57   // *** Calorimeters Utils     ***
58   AliCalorimeterUtils *cu = new AliCalorimeterUtils;
59   // Remove clusters close to borders, at least max energy cell is 1 cell away 
60   cu->SetNumberOfCellsFromEMCALBorder(1);
61   cu->SetNumberOfCellsFromPHOSBorder(2);
62   cu->SwitchOnNoFiducialBorderInEMCALEta0();
63         
64   // Remove EMCAL hottest channels for first LHC10 periods      
65   cu->SwitchOnBadChannelsRemoval();
66   // SM0
67   cu->SetEMCALChannelStatus(0,3,13);  cu->SetEMCALChannelStatus(0,44,1); cu->SetEMCALChannelStatus(0,3,13); 
68   cu->SetEMCALChannelStatus(0,20,7);  cu->SetEMCALChannelStatus(0,38,2);   
69   // SM1
70   cu->SetEMCALChannelStatus(1,4,7);   cu->SetEMCALChannelStatus(1,4,13);  cu->SetEMCALChannelStatus(1,9,20); 
71   cu->SetEMCALChannelStatus(1,14,15); cu->SetEMCALChannelStatus(1,23,16); cu->SetEMCALChannelStatus(1,32,23); 
72   cu->SetEMCALChannelStatus(1,37,5);  cu->SetEMCALChannelStatus(1,40,1);  cu->SetEMCALChannelStatus(1,40,2);
73   cu->SetEMCALChannelStatus(1,40,5);  cu->SetEMCALChannelStatus(1,41,0);  cu->SetEMCALChannelStatus(1,41,1);
74   cu->SetEMCALChannelStatus(1,41,2);  cu->SetEMCALChannelStatus(1,41,4);
75   // SM2        
76   cu->SetEMCALChannelStatus(2,14,15); cu->SetEMCALChannelStatus(2,18,16); cu->SetEMCALChannelStatus(2,18,17); 
77   cu->SetEMCALChannelStatus(2,18,18); cu->SetEMCALChannelStatus(2,18,20); cu->SetEMCALChannelStatus(2,18,21); 
78   cu->SetEMCALChannelStatus(2,18,23); cu->SetEMCALChannelStatus(2,19,16); cu->SetEMCALChannelStatus(2,19,17); 
79   cu->SetEMCALChannelStatus(2,19,19); cu->SetEMCALChannelStatus(2,19,20); cu->SetEMCALChannelStatus(2,19,21); 
80   cu->SetEMCALChannelStatus(2,19,22);
81   //SM3
82   cu->SetEMCALChannelStatus(3,4,7);
83         
84   //Recalibration
85   //cu->SwitchOnRecalibration();
86   //TFile * f = new TFile("RecalibrationFactors.root","read");
87   //cu->SetEMCALChannelRecalibrationFactors(0,(TH2F*)f->Get("EMCALRecalFactors_SM0"));
88   //cu->SetEMCALChannelRecalibrationFactors(1,(TH2F*)f->Get("EMCALRecalFactors_SM1"));
89   //cu->SetEMCALChannelRecalibrationFactors(2,(TH2F*)f->Get("EMCALRecalFactors_SM2"));
90   //cu->SetEMCALChannelRecalibrationFactors(3,(TH2F*)f->Get("EMCALRecalFactors_SM3"));
91         
92   cu->SetDebug(-1);
93   if(kPrintSettings) cu->Print("");     
94         
95   // ##### Analysis algorithm settings ####
96   //AliFiducialCut * fidCut = new AliFiducialCut();
97   //fidCut->DoCTSFiducialCut(kFALSE) ;
98   //fidCut->DoEMCALFiducialCut(kTRUE) ;
99   //fidCut->DoPHOSFiducialCut(kTRUE) ;  
100         
101   AliAnaCalorimeterQA *emcalQA = new AliAnaCalorimeterQA();
102   //emcalQA->SetDebug(2); //10 for lots of messages
103   emcalQA->SetCalorimeter("EMCAL");
104   if(kUseKinematics) emcalQA->SwitchOnDataMC() ;//Access MC stack and fill more histograms, AOD MC not implemented yet.
105   else  emcalQA->SwitchOffDataMC() ;
106   emcalQA->AddToHistogramsName("EMCAL_"); //Begining of histograms name
107   //emcalQA->SetFiducialCut(fidCut);
108   emcalQA->SwitchOffFiducialCut();
109   emcalQA->SwitchOffPlotsMaking();
110   emcalQA->SwitchOnCalorimetersCorrelation();
111   emcalQA->SetTimeCut(420,825);//Open for the moment
112   //Set Histrograms bins and ranges
113   emcalQA->SetHistoPtRangeAndNBins(0, 10, 100) ;
114   emcalQA->SetHistoPhiRangeAndNBins(75*TMath::DegToRad(), 125*TMath::DegToRad(), 100) ;
115   emcalQA->SetHistoEtaRangeAndNBins(-0.8, 0.8, 80) ;
116   emcalQA->SetNumberOfModules(4); //EMCAL first year
117   emcalQA->SetHistoMassRangeAndNBins(0., 0.6, 200) ;
118   emcalQA->SetHistoAsymmetryRangeAndNBins(0., 1. , 10) ;
119   emcalQA->SetHistoPOverERangeAndNBins(0,10.,100);
120   emcalQA->SetHistodEdxRangeAndNBins(0.,400.,200);
121   emcalQA->SetHistodRRangeAndNBins(0.,TMath::Pi(),150);
122   emcalQA->SetHistoTimeRangeAndNBins(400.,800,200);
123   emcalQA->SetHistoRatioRangeAndNBins(0.,2.,100);
124   emcalQA->SetHistoVertexDistRangeAndNBins(0.,500.,100);
125   emcalQA->SetHistoNClusterCellRangeAndNBins(0,300,300);
126   emcalQA->SetHistoXRangeAndNBins(-230,90,160);
127   emcalQA->SetHistoYRangeAndNBins(370,450,35);
128   emcalQA->SetHistoZRangeAndNBins(-400,400,100);
129   emcalQA->SetHistoRRangeAndNBins(400,450,25);
130
131   //emcalQA->GetMCAnalysisUtils()->SetDebug(10);
132         
133   if(kPrintSettings) emcalQA->Print("");        
134
135    AliAnaCalorimeterQA *phosQA = new AliAnaCalorimeterQA();
136    //phosQA->SetDebug(2); //10 for lots of messages
137    phosQA->SetCalorimeter("PHOS");
138    if(kUseKinematics) phosQA->SwitchOnDataMC() ;//Access MC stack and fill more histograms, AOD MC not implemented yet.
139    else  phosQA->SwitchOffDataMC() ;  
140    phosQA->AddToHistogramsName("PHOS_");//Begining of histograms name
141    //phosQA->SetFiducialCut(fidCut);
142    phosQA->SwitchOffFiducialCut();
143    //phosQA->GetMCAnalysisUtils()->SetDebug(10);
144    phosQA->SwitchOffPlotsMaking();
145    //Set Histrograms bins and ranges
146    phosQA->SetHistoPtRangeAndNBins(0, 10, 100) ;
147    phosQA->SetHistoPhiRangeAndNBins(255*TMath::DegToRad(), 325*TMath::DegToRad(), 100) ;
148    phosQA->SetHistoEtaRangeAndNBins(-0.13, 0.13, 80) ;
149    phosQA->SetNumberOfModules(3); //PHOS first year
150    phosQA->SetHistoMassRangeAndNBins(0., 0.6, 200) ;
151    phosQA->SetHistoAsymmetryRangeAndNBins(0., 1. , 25) ;
152    phosQA->SetHistoPOverERangeAndNBins(0,10.,100);
153    phosQA->SetHistodEdxRangeAndNBins(0.,400.,200);
154    phosQA->SetHistodRRangeAndNBins(0.,TMath::Pi(),150);
155    phosQA->SetHistoTimeRangeAndNBins(0.,400,200);
156    phosQA->SetHistoRatioRangeAndNBins(0.,2.,100);
157    phosQA->SetHistoVertexDistRangeAndNBins(0.,500.,100);
158    phosQA->SetHistoNClusterCellRangeAndNBins(0,300,300);
159    phosQA->SetHistoXRangeAndNBins(-100,400,150);
160    phosQA->SetHistoYRangeAndNBins(-490,-290,100);
161    phosQA->SetHistoZRangeAndNBins(-80,80,80);
162    phosQA->SetHistoRRangeAndNBins(440,480,40);
163         
164   //if(kPrintSettings)phosQA->Print("");        
165         
166   // #### Configure Maker ####
167   AliAnaPartCorrMaker * maker = new AliAnaPartCorrMaker();
168   maker->SetReader(reader);//pointer to reader
169   maker->SetCaloUtils(cu); //pointer to calorimeter utils
170   maker->AddAnalysis(emcalQA,0);
171   maker->AddAnalysis(phosQA,1);
172   maker->SetAnaDebug(-1)  ; // 0 to at least print the event number
173   maker->SwitchOnHistogramsMaker()  ;
174   maker->SwitchOffAODsMaker()  ;
175   if(kPrintSettings) maker->Print("");
176  
177
178   printf("======================== \n");
179   printf(" End Configuration of Calorimeter QA \n");
180   printf("======================== \n");
181   
182    // Create task
183    //===========================================================================
184   AliAnalysisTaskParticleCorrelation * task = new AliAnalysisTaskParticleCorrelation ("CalorimeterPerformance");
185   task->SetConfigFileName(""); //Don't configure the analysis via configuration file.
186   //task->SetDebugLevel(-1);
187   task->SelectCollisionCandidates();
188   task->SetAnalysisMaker(maker);        
189   mgr->AddTask(task);
190   
191   //Create containers
192 //  AliAnalysisDataContainer *cout_pc = mgr->CreateContainer("Calo.Performance",TList::Class(),
193 //                                                         AliAnalysisManager::kOutputContainer, "Calo.Performance.root");
194         
195
196   if(outputFile.Length()==0)outputFile = AliAnalysisManager::GetCommonFileName(); 
197
198
199   AliAnalysisDataContainer *cout_pc   = mgr->CreateContainer("CaloQA", TList::Class(), 
200                                                                                                                          AliAnalysisManager::kOutputContainer, 
201                                                                                                                          Form("%s:CaloQA",outputFile.Data()));
202         
203   AliAnalysisDataContainer *cout_cuts = mgr->CreateContainer("CaloQACuts", TList::Class(), 
204                                                                                                                           AliAnalysisManager::kParamContainer, 
205                                                                                                                           Form("%s:CaloQACuts",outputFile.Data()));
206         //Form("%s:PartCorrCuts",outputfile.Data()));   
207   // Create ONLY the output containers for the data produced by the task.
208   // Get and connect other common input/output containers via the manager as below
209   //==============================================================================
210   mgr->ConnectInput  (task, 0, mgr->GetCommonInputContainer());
211   mgr->ConnectOutput (task, 1, cout_pc);
212   mgr->ConnectOutput (task, 2, cout_cuts);
213
214   return task;
215 }
216
217