Adapt the VZERO equalized signal Tender for AOD analyses
[u/mrichter/AliRoot.git] / ANALYSIS / TenderSupplies / AliAnalysisTaskVZEROEqFactorTask.cxx
CommitLineData
21c2a03e 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 is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
17//
18// AliAnalysisTaskVZEROEqFactorTask.cxx, February 12th 2014
19// --- David Dobrigkeit Chinellato
20//
21// This task is meant to set correct VZERO equalization factors in AliESDRun
22// so that AliCentrality makes use of the correct values. NB This task has to
23// be executed prior to AliCentrality for this to work properly! It is meant
24// to be used as a Tender.
25//
26// Comments, Suggestions, Bug reports: Please send them to:
27// --- daviddc@ifi.unicamp.br
28//
29// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
30
31class TTree;
32class TParticle;
33class TVector3;
34
35//class AliMCEventHandler;
36//class AliMCEvent;
37//class AliStack;
38
39class AliESDVertex;
40class AliAODVertex;
41class AliESDv0;
42class AliAODv0;
43
44#include <Riostream.h>
45#include "TList.h"
46#include "TH1.h"
47#include "TH2.h"
48#include "TH3.h"
49#include "TFile.h"
50#include "THnSparse.h"
51#include "TVector3.h"
52#include "TCanvas.h"
53#include "TMath.h"
54#include "TLegend.h"
55//#include "AliLog.h"
56
57#include "AliAnalysisTaskSE.h"
58#include "AliESDEvent.h"
59#include "AliAODEvent.h"
60#include "AliV0vertexer.h"
61#include "AliCascadeVertexer.h"
62#include "AliESDpid.h"
63#include "AliESDRun.h"
64#include "AliESDtrack.h"
65#include "AliESDtrackCuts.h"
66#include "AliInputEventHandler.h"
67#include "AliAnalysisManager.h"
68#include "AliMCEventHandler.h"
69#include "AliMCEvent.h"
70#include "AliStack.h"
71
72#include "AliCFContainer.h"
73#include "AliMultiplicity.h"
74#include "AliAODMCParticle.h"
75#include "AliESDcascade.h"
76#include "AliAODcascade.h"
77#include "AliESDUtils.h"
78#include "AliGenEventHeader.h"
79
80#include "AliAnalysisUtils.h"
81#include "AliAnalysisTaskVZEROEqFactorTask.h"
82#include "AliCDBManager.h"
83#include "AliCDBStorage.h"
84#include "AliCDBEntry.h"
85
86#include "AliVZEROCalibData.h"
87
88using std::cout;
89using std::endl;
90
91ClassImp(AliAnalysisTaskVZEROEqFactorTask)
92
93AliAnalysisTaskVZEROEqFactorTask::AliAnalysisTaskVZEROEqFactorTask()
ee3c3ebe 94: AliAnalysisTaskSE(), fListHist(0), fEqFactors(0), fCalibData(0), fRunNumber(0), fHistEventCounter(0), fisAOD(kFALSE)
21c2a03e 95//------------------------------------------------
96// Tree Variables
97{
98 // Dummy Constructor
99}
100
101AliAnalysisTaskVZEROEqFactorTask::AliAnalysisTaskVZEROEqFactorTask(const char *name)
ee3c3ebe 102 : AliAnalysisTaskSE(name), fListHist(0), fEqFactors(0), fCalibData(0), fRunNumber(0), fHistEventCounter(0), fisAOD(kFALSE)
21c2a03e 103{
104 // Constructor
105 DefineOutput(1, TList::Class());
106}
107
108
109AliAnalysisTaskVZEROEqFactorTask::~AliAnalysisTaskVZEROEqFactorTask()
110{
111//------------------------------------------------
112// DESTRUCTOR
113//------------------------------------------------
114
115 if (fListHist){
116 delete fListHist;
117 fListHist = 0x0;
118 }
119}
120
121//________________________________________________________________________
122void AliAnalysisTaskVZEROEqFactorTask::UserCreateOutputObjects()
123{
124//------------------------------------------------
125// Output: Empty at the moment
126//------------------------------------------------
127
128 fListHist = new TList();
129 fListHist->SetOwner(); // See http://root.cern.ch/root/html/TCollection.html#TCollection:SetOwner
130
131 if(! fHistEventCounter ) {
132 //Histogram Output: Event-by-Event
133 // --- Single "Events Processed" Counter at this stage
134 fHistEventCounter = new TH1D( "fHistEventCounter", ";Evt. Sel. Step;Count",4,0,4);
135 fHistEventCounter->GetXaxis()->SetBinLabel(1, "Processed");
136 fHistEventCounter->GetXaxis()->SetBinLabel(2, "Has ESD");
137 fHistEventCounter->GetXaxis()->SetBinLabel(3, "Has ESDRun");
138 fHistEventCounter->GetXaxis()->SetBinLabel(4, "Rewrote EqFactors");
139 fListHist->Add(fHistEventCounter);
140 }
141
142 //List of Histograms
143 PostData(1, fListHist);
144}// end UserCreateOutputObjects
145
146
147//________________________________________________________________________
148void AliAnalysisTaskVZEROEqFactorTask::UserExec(Option_t *)
149{
150 // Main loop
151 // Called for each event
152
153 AliESDEvent *lESDevent = 0x0;
ee3c3ebe 154 AliAODEvent *lAODevent = 0x0;
21c2a03e 155 // Connect to the InputEvent
156 // After these lines, we should have an ESD/AOD event + the number of V0s in it.
157
158 // Appropriate for ESD analysis!
159 //Count Processed Events
ee3c3ebe 160 fHistEventCounter->Fill(0.5);
161
162 if(fisAOD) {
163 lAODevent = dynamic_cast<AliAODEvent*>( InputEvent() );
164 if (!lAODevent) {
165 AliError("AOD event not available \n");
166 return;
167 }
168 } else {
169 lESDevent = dynamic_cast<AliESDEvent*>( InputEvent() );
170 if (!lESDevent) {
171 AliError("ESD event not available \n");
172 return;
173 }
21c2a03e 174 }
ee3c3ebe 175 fHistEventCounter->Fill(1.5);
21c2a03e 176
177
178 //Acquire ESDRun object - Will be needed to invoke AliESDEvent::SetVZEROEqFactors
ee3c3ebe 179 Int_t runNumber=-1;
180 // const AliESDRun *lESDRun;
181 if(fisAOD) {
182 runNumber = lAODevent->GetRunNumber();
183 } else {
184 // lESDRun = lESDevent->GetESDRun();
185 // if (!lESDRun) {
186 // AliError("ERROR: lESDRun not available, won't be able to write Equalization Factors! Exiting. \n");
187 // return;
188 // }
189 runNumber = lESDevent->GetRunNumber();
21c2a03e 190 }
ee3c3ebe 191 fHistEventCounter->Fill(2.5);
21c2a03e 192
193 //CDB Processing only necessary if Run Number changed! Check for change (no need to redo this every event)
ee3c3ebe 194 if( runNumber != fRunNumber ){
21c2a03e 195 AliWarning("Run Changed! Reloading CDB values!");
196 //Load CDB Entries - Mirroring AliVZEROReconstructor
ee3c3ebe 197 AliCDBManager *cdbmanager = AliCDBManager::Instance();
198 cdbmanager->SetDefaultStorage("raw://");
199 cdbmanager->SetRun(runNumber);
200 if(!cdbmanager) AliFatal("No CDB Manager !");
201 AliCDBEntry *entry7 = cdbmanager->Get("VZERO/Calib/EqualizationFactors");
202 if (!entry7) AliFatal("VZERO equalization factors are not found in OCDB !");
21c2a03e 203 fEqFactors = (TH1F*)entry7->GetObject();
204
205 //Load Calibration object fCalibData
206 fCalibData = GetCalibData(); // Mirror AliVZEROReconstructor Functionality
ee3c3ebe 207 fRunNumber = runNumber; //New Run
21c2a03e 208 }
ee3c3ebe 209 if(!fCalibData) AliFatal("No VZERO CalibData Object found!");
21c2a03e 210
211
212 Float_t factors[64];
213 Float_t factorSum = 0;
214 for(Int_t i = 0; i < 64; ++i) {
215 factors[i] = fEqFactors->GetBinContent(i+1)*fCalibData->GetMIPperADC(i);
216 factorSum += factors[i];
217 }
218 for(Int_t i = 0; i < 64; ++i) {
219 factors[i] *= (64./factorSum);
220 }
21c2a03e 221
ee3c3ebe 222 // Set the equalized factors
223 if(fisAOD) {
224 lAODevent->SetVZEROEqFactors(factors);
225 } else {
226 lESDevent->SetVZEROEqFactors(factors);
227 }
228 fHistEventCounter->Fill(3.5);
21c2a03e 229
230 // Post output data.
231 PostData(1, fListHist);
232}
233
234//________________________________________________________________________
235void AliAnalysisTaskVZEROEqFactorTask::Terminate(Option_t *)
236{
237 // Draw result to the screen
238 // Called once at the end of the query
239
240 TList *cRetrievedList = 0x0;
241 cRetrievedList = (TList*)GetOutputData(1);
242 if(!cRetrievedList){
243 Printf("ERROR - AliAnalysisTaskVZEROEqFactorTask : ouput data container list not available\n");
244 return;
245 }
246
247 fHistEventCounter = dynamic_cast<TH1D*> ( cRetrievedList->FindObject("fHistEventCounter") );
248 if (!fHistEventCounter) {
249 Printf("ERROR - AliAnalysisTaskVZEROEqFactorTask : fHistEventCounter not available");
250 return;
251 }
252
253 TCanvas *canCheck = new TCanvas("AliAnalysisTaskVZEROEqFactorTask","V0 Multiplicity",10,10,510,510);
254 canCheck->cd(1)->SetLogy();
255
256 fHistEventCounter->SetMarkerStyle(22);
257 fHistEventCounter->DrawCopy("E");
258}
259
260//_____________________________________________________________________________
261AliVZEROCalibData* AliAnalysisTaskVZEROEqFactorTask::GetCalibData() const
262{
263 // Gets calibration object for VZERO set
264
265 AliCDBManager *man = AliCDBManager::Instance();
266 AliCDBEntry *entry=0;
267 entry = man->Get("VZERO/Calib/Data");
268 AliVZEROCalibData *calibdata = 0;
269 if (entry) calibdata = (AliVZEROCalibData*) entry->GetObject();
270 if (!calibdata) AliFatal("No calibration data from calibration database !");
271 return calibdata;
272}