3 #include "AlidNdEtaCorrectionSelector.h"
9 #include <TParticlePDG.h>
12 #include <TSelector.h>
16 #include <AliGenEventHeader.h>
17 #include <AliTracker.h>
18 #include <AliHeader.h>
19 #include <AliESDVertex.h>
21 #include <AliESDtrack.h>
22 #include <AliRunLoader.h>
25 #include "esdTrackCuts/AliESDtrackCuts.h"
26 #include "dNdEta/AlidNdEtaCorrection.h"
27 #include "AliPWG0Helper.h"
29 ClassImp(AlidNdEtaCorrectionSelector)
31 AlidNdEtaCorrectionSelector::AlidNdEtaCorrectionSelector() :
37 // Constructor. Initialization of pointers
41 AlidNdEtaCorrectionSelector::~AlidNdEtaCorrectionSelector()
47 // histograms are in the output list and deleted when the output
48 // list is deleted by the TSelector dtor
51 void AlidNdEtaCorrectionSelector::Begin(TTree * tree)
53 // The Begin() function is called at the start of the query.
54 // When running with PROOF Begin() is only called on the client.
55 // The tree argument is deprecated (on PROOF 0 is passed).
57 AliSelectorRL::Begin(tree);
60 void AlidNdEtaCorrectionSelector::SlaveBegin(TTree * tree)
62 // The SlaveBegin() function is called after the Begin() function.
63 // When running with PROOF SlaveBegin() is called on each slave server.
64 // The tree argument is deprecated (on PROOF 0 is passed).
66 AliSelectorRL::SlaveBegin(tree);
68 fdNdEtaCorrection = new AlidNdEtaCorrection();
71 fEsdTrackCuts = dynamic_cast<AliESDtrackCuts*> (fTree->GetUserInfo()->FindObject("AliESDtrackCuts"));
74 AliDebug(AliLog::kError, "ERROR: Could not read EsdTrackCuts from user info");
77 Bool_t AlidNdEtaCorrectionSelector::Process(Long64_t entry)
79 // The Process() function is called for each entry in the tree (or possibly
80 // keyed object in the case of PROOF) to be processed. The entry argument
81 // specifies which entry in the currently loaded tree is to be processed.
82 // It can be passed to either TTree::GetEntry() or TBranch::GetEntry()
83 // to read either all or the required parts of the data. When processing
84 // keyed objects with PROOF, the object is already loaded and is available
85 // via the fObject pointer.
87 // This function should contain the "body" of the analysis. It can contain
88 // simple or elaborate selection criteria, run algorithms on the data
89 // of the event and typically fill histograms.
91 // WARNING when a selector is used with a TChain, you must use
92 // the pointer to the current TTree to call GetEntry(entry).
93 // The entry is always the local entry number in the current tree.
94 // Assuming that fTree is the pointer to the TChain being processed,
95 // use fTree->GetTree()->GetEntry(entry).
97 if (AliSelectorRL::Process(entry) == kFALSE)
100 // check prerequesites
103 AliDebug(AliLog::kError, "ESD branch not available");
107 AliHeader* header = GetHeader();
110 AliDebug(AliLog::kError, "Header not available");
114 AliRunLoader* runLoader = GetRunLoader();
117 AliDebug(AliLog::kError, "RunLoader not available");
121 runLoader->LoadKinematics();
122 AliStack* stack = runLoader->Stack();
125 AliDebug(AliLog::kError, "Stack not available");
131 AliDebug(AliLog::kError, "fESDTrackCuts not available");
135 Bool_t vertexReconstructed = AliPWG0Helper::IsVertexReconstructed(fESD);
137 Bool_t eventTriggered = AliPWG0Helper::IsEventTriggered(fESD);
139 fdNdEtaCorrection->IncreaseEventCount();
141 fdNdEtaCorrection->IncreaseTriggeredEventCount();
144 AliGenEventHeader* genHeader = header->GenEventHeader();
147 genHeader->PrimaryVertex(vtxMC);
149 // loop over mc particles
150 Int_t nPrim = stack->GetNprimary();
152 for (Int_t iMc = 0; iMc < nPrim; ++iMc)
154 AliDebug(AliLog::kDebug+1, Form("MC Loop: Processing particle %d.", iMc));
156 TParticle* particle = stack->Particle(iMc);
160 AliDebug(AliLog::kError, Form("UNEXPECTED: particle with label %d not found in stack (mc loop).", iMc));
164 if (AliPWG0Helper::IsPrimaryCharged(particle, nPrim) == kFALSE)
167 Float_t eta = particle->Eta();
168 Float_t pt = particle->Pt();
170 if (vertexReconstructed)
171 fdNdEtaCorrection->FillParticle(vtxMC[2], eta, pt);
173 fdNdEtaCorrection->FillParticleAllEvents(eta, pt);
175 fdNdEtaCorrection->FillParticleWhenEventTriggered(eta, pt);
176 }// end of mc particle
178 // ########################################################
179 // loop over esd tracks
180 Int_t nTracks = fESD->GetNumberOfTracks();
182 // count the number of "good" tracks for vertex reconstruction efficiency
183 // TODO change to number of ITS clusters or similar
184 Int_t nGoodTracks = 0;
185 for (Int_t t=0; t<nTracks; t++)
187 AliDebug(AliLog::kDebug+1, Form("ESD Loop: Processing track %d.", t));
189 AliESDtrack* esdTrack = fESD->GetTrack(t);
191 // cut the esd track?
192 if (!fEsdTrackCuts->AcceptTrack(esdTrack))
197 // using the properties of the mc particle
198 Int_t label = TMath::Abs(esdTrack->GetLabel());
201 AliDebug(AliLog::kWarning, Form("WARNING: cannot find corresponding mc part for track %d.", t));
205 TParticle* particle = stack->Particle(label);
208 AliDebug(AliLog::kError, Form("UNEXPECTED: particle with label %d not found in stack (track loop).", label));
212 if (vertexReconstructed)
213 fdNdEtaCorrection->FillParticleWhenMeasuredTrack(vtxMC[2], particle->Eta(), particle->Pt());
214 } // end of track loop
219 fdNdEtaCorrection->FillEvent(vtxMC[2], nGoodTracks);
220 if (vertexReconstructed)
221 fdNdEtaCorrection->FillEventWithReconstructedVertex(vtxMC[2], nGoodTracks);
227 void AlidNdEtaCorrectionSelector::SlaveTerminate()
229 // The SlaveTerminate() function is called after all entries or objects
230 // have been processed. When running with PROOF SlaveTerminate() is called
231 // on each slave server.
233 AliSelectorRL::SlaveTerminate();
235 // Add the histograms to the output on each slave server
238 AliDebug(AliLog::kError, "ERROR: Output list not initialized");
242 fOutput->Add(fdNdEtaCorrection);
245 void AlidNdEtaCorrectionSelector::Terminate()
247 // The Terminate() function is the last function to be called during
248 // a query. It always runs on the client, it can be used to present
249 // the results graphically or save the results to file.
251 AliSelectorRL::Terminate();
253 fdNdEtaCorrection = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject("dndeta_correction"));
255 fdNdEtaCorrection->Finish();
257 TFile* fout = new TFile("correction_map.root","RECREATE");
259 fEsdTrackCuts->SaveHistograms("esd_track_cuts");
260 fdNdEtaCorrection->SaveHistograms();
265 fdNdEtaCorrection->DrawHistograms();