4 // Simple task to test the collision normalization. Can be called for
5 // both MC and data and shows how to fill the collision normalization
8 // Author: Michele Floris
12 #include "AliCollisionNormalizationTask.h"
19 #include <AliESDEvent.h>
20 #include <AliHeader.h>
22 #include "AliCollisionNormalization.h"
23 #include "AliAnalysisManager.h"
24 #include "AliInputEventHandler.h"
26 //#include "AliBackgroundSelection.h"
27 #include "AliMultiplicity.h"
28 #include "AliMCEvent.h"
30 ClassImp(AliCollisionNormalizationTask)
32 AliCollisionNormalizationTask::AliCollisionNormalizationTask() :
33 AliAnalysisTaskSE("AliCollisionNormalizationTask"),
36 fCollisionNormalization(0)
39 // Default event handler
42 // Define input and output slots here
43 DefineOutput(1, TList::Class());
47 AliCollisionNormalizationTask::AliCollisionNormalizationTask(const char* name) :
48 AliAnalysisTaskSE(name),
51 fCollisionNormalization(new AliCollisionNormalization())
54 // Constructor. Initialization of pointers
57 // Define input and output slots here
58 DefineOutput(1, TList::Class());
60 // AliLog::SetClassDebugLevel("AliCollisionNormalizationTask", AliLog::kWarning);
63 AliCollisionNormalizationTask::~AliCollisionNormalizationTask()
69 // histograms are in the output list and deleted when the output
70 // list is deleted by the TSelector dtor
78 void AliCollisionNormalizationTask::UserCreateOutputObjects()
80 // create result objects and add to output list
82 Printf("AliCollisionNormalizationTask::CreateOutputObjects");
87 if (!fCollisionNormalization)
88 fCollisionNormalization = new AliCollisionNormalization;
90 fOutput->Add(fCollisionNormalization);
91 // fOutput->Add(fCollisionNormalization->GetVzCorrZeroBin ());
92 // fOutput->Add(fCollisionNormalization->GetVzMCGen ());
93 // fOutput->Add(fCollisionNormalization->GetVzMCRec ());
94 // fOutput->Add(fCollisionNormalization->GetVzMCTrg ());
95 // fOutput->Add(fCollisionNormalization->GetVzData ());
96 // fOutput->Add(fCollisionNormalization->GetNEvents ());
97 // fOutput->Add(fCollisionNormalization->GetStatBin0 ());
101 void AliCollisionNormalizationTask::UserExec(Option_t*)
106 PostData(1, fOutput);
109 AliESDEvent * aESD = dynamic_cast<AliESDEvent*>(fInputEvent);
110 if (strcmp(aESD->ClassName(),"AliESDEvent")) {
111 AliFatal("Not processing ESDs");
113 // Get MC event, if needed
114 AliMCEvent* mcEvent = fIsMC ? MCEvent() : 0;
115 if (!mcEvent && fIsMC){
116 AliFatal("Running on MC but no MC handler available");
119 // Physics selection. At least in the case of MC we cannot use
120 // yourTask->SelectCollisionCandidates();, because we also need to
121 // fill the "generated" histogram
122 // NB never call IsEventSelected more than once per event
123 // (statistics histogram would be altered)
125 Bool_t isSelected = ((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected();
127 // Get the Multiplicity cut
128 const AliMultiplicity* mult = aESD->GetMultiplicity();
130 AliError("Can't get mult object");
134 // Check if the event is "reconstructed" according to some quality
135 // cuts. Tipically, we mean "it has a good-eonugh vertex"
137 Int_t ntracklet = mult->GetNumberOfTracklets();
138 const AliESDVertex * vtxESD = aESD->GetPrimaryVertexSPD();
139 if (IsEventInBinZero()) {
144 if (ntracklet > 0 && !vtxESD) {
145 AliError("No vertex but reconstructed tracklets?");
148 // assign vz. For MC we use generated vz
150 if (!fIsMC) vz = vtxESD ? vtxESD->GetZ() : 0; // FIXME : is zv used anywhere in Gen?
151 else vz = mcEvent->GetPrimaryVertex()->GetZ();
154 // Monte Carlo: we fill 3 histos
155 if (!isSelected || !vtxESD) ntracklet = 0; //If the event does not pass the physics selection or is not rec, it goes in the bin0
156 fCollisionNormalization->FillVzMCGen(vz, ntracklet, mcEvent);
157 // If triggered == passing the physics selection
159 fCollisionNormalization->FillVzMCTrg(vz, ntracklet, mcEvent);
160 // If reconstructer == good enough vertex
161 if (vtxESD) fCollisionNormalization->FillVzMCRec(vz, ntracklet, mcEvent);
165 // Passing the trigger
166 fCollisionNormalization->FillVzData(vz,ntracklet);
172 void AliCollisionNormalizationTask::Terminate(Option_t *)
174 // The Terminate() function is the last function to be called during
175 // a query. It always runs on the client, it can be used to present
176 // the results graphically or save the results to file.
178 fOutput = dynamic_cast<TList*> (GetOutputData(1));
180 Printf("ERROR: fOutput not available");
185 Bool_t AliCollisionNormalizationTask::IsEventInBinZero() {
187 // Returns true if an event is to be assigned to the zero bin
189 // You should have your own version of this method in the class: in
190 // general, the definition of "reconstructed" event is subjective.
192 Bool_t isZeroBin = kTRUE;
193 const AliESDEvent* esd= dynamic_cast<AliESDEvent*>(fInputEvent);
194 const AliMultiplicity* mult = esd->GetMultiplicity();
196 Printf("AliAnalysisTaskBGvsTime::IsBinZero: Can't get mult object");
199 Int_t ntracklet = mult->GetNumberOfTracklets();
200 const AliESDVertex * vtxESD = esd->GetPrimaryVertexSPD();
202 // If there is a vertex from vertexer z with delta phi > 0.02 we
203 // don't consider it rec (we keep the event in bin0). If quality
204 // is good eneough we check the number of tracklets
205 // if the vertex is more than 15 cm away, this is autamatically bin0
206 if( TMath::Abs(vtxESD->GetZ()) <= 15 ) {
207 if (vtxESD->IsFromVertexerZ()) {
208 if (vtxESD->GetDispersion()<=0.02 ) {
209 if(ntracklet>0) isZeroBin = kFALSE;
211 } else if(ntracklet>0) isZeroBin = kFALSE; // if the event is not from Vz we chek the n of tracklets