3 #include "AlidNdEtaCorrectionSelector.h"
9 #include <TParticlePDG.h>
13 #include <TSelector.h>
17 #include <AliGenEventHeader.h>
18 #include <AliTracker.h>
19 #include <AliHeader.h>
20 #include <AliESDVertex.h>
22 #include <AliESDtrack.h>
23 #include <AliRunLoader.h>
26 #include "esdTrackCuts/AliESDtrackCuts.h"
27 #include "dNdEta/AlidNdEtaCorrection.h"
28 #include "AliPWG0Helper.h"
30 ClassImp(AlidNdEtaCorrectionSelector)
32 AlidNdEtaCorrectionSelector::AlidNdEtaCorrectionSelector() :
45 // Constructor. Initialization of pointers
49 AlidNdEtaCorrectionSelector::~AlidNdEtaCorrectionSelector()
55 // histograms are in the output list and deleted when the output
56 // list is deleted by the TSelector dtor
59 Bool_t AlidNdEtaCorrectionSelector::SignOK(TParticlePDG* particle)
61 // returns if a particle with this sign should be counted
62 // this is determined by the value of fSignMode, which should have the same sign
64 // if fSignMode is 0 all particles are counted
71 printf("WARNING: not counting a particle that does not have a pdg particle\n");
75 Double_t charge = particle->Charge();
88 void AlidNdEtaCorrectionSelector::ReadUserObjects(TTree* tree)
90 // read the user objects, called from slavebegin and begin
92 if (!fEsdTrackCuts && fInput)
93 fEsdTrackCuts = dynamic_cast<AliESDtrackCuts*> (fInput->FindObject("AliESDtrackCuts"));
95 if (!fEsdTrackCuts && tree)
96 fEsdTrackCuts = dynamic_cast<AliESDtrackCuts*> (tree->GetUserInfo()->FindObject("AliESDtrackCuts"));
99 AliDebug(AliLog::kError, "ERROR: Could not read EsdTrackCuts from input list.");
102 void AlidNdEtaCorrectionSelector::Begin(TTree * tree)
104 // The Begin() function is called at the start of the query.
105 // When running with PROOF Begin() is only called on the client.
106 // The tree argument is deprecated (on PROOF 0 is passed).
108 AliSelectorRL::Begin(tree);
110 ReadUserObjects(tree);
112 TString option = GetOption();
113 AliInfo(Form("Called with option %s.", option.Data()));
115 if (option.Contains("only-positive"))
117 AliInfo("Processing only positive particles.");
120 else if (option.Contains("only-negative"))
122 AliInfo("Processing only negative particles.");
127 void AlidNdEtaCorrectionSelector::SlaveBegin(TTree * tree)
129 // The SlaveBegin() function is called after the Begin() function.
130 // When running with PROOF SlaveBegin() is called on each slave server.
131 // The tree argument is deprecated (on PROOF 0 is passed).
133 AliSelectorRL::SlaveBegin(tree);
135 ReadUserObjects(tree);
137 fdNdEtaCorrection = new AlidNdEtaCorrection("dndeta_correction", "dndeta_correction");
139 fPIDParticles = new TH1F("pid_particles", "PID of generated primary particles", 10001, -5000.5, 5000.5);
140 fPIDTracks = new TH1F("pid_tracks", "MC PID of reconstructed tracks", 10001, -5000.5, 5000.5);
142 fClustersITSPos = new TH1F("clusters_its_pos", "clusters_its_pos", 7, -0.5, 6.5);
143 fClustersTPCPos = new TH1F("clusters_tpc_pos", "clusters_tpc_pos", 160, -0.5, 159.5);
145 fClustersITSNeg = new TH1F("clusters_its_neg", "clusters_its_neg", 7, -0.5, 6.5);
146 fClustersTPCNeg = new TH1F("clusters_tpc_neg", "clusters_tpc_neg", 160, -0.5, 159.5);
149 Bool_t AlidNdEtaCorrectionSelector::Process(Long64_t entry)
151 // The Process() function is called for each entry in the tree (or possibly
152 // keyed object in the case of PROOF) to be processed. The entry argument
153 // specifies which entry in the currently loaded tree is to be processed.
154 // It can be passed to either TTree::GetEntry() or TBranch::GetEntry()
155 // to read either all or the required parts of the data. When processing
156 // keyed objects with PROOF, the object is already loaded and is available
157 // via the fObject pointer.
159 // This function should contain the "body" of the analysis. It can contain
160 // simple or elaborate selection criteria, run algorithms on the data
161 // of the event and typically fill histograms.
163 // WARNING when a selector is used with a TChain, you must use
164 // the pointer to the current TTree to call GetEntry(entry).
165 // The entry is always the local entry number in the current tree.
166 // Assuming that fTree is the pointer to the TChain being processed,
167 // use fTree->GetTree()->GetEntry(entry).
169 if (AliSelectorRL::Process(entry) == kFALSE)
172 // check prerequesites
175 AliDebug(AliLog::kError, "ESD branch not available");
179 AliHeader* header = GetHeader();
182 AliDebug(AliLog::kError, "Header not available");
186 AliStack* stack = GetStack();
189 AliDebug(AliLog::kError, "Stack not available");
195 AliDebug(AliLog::kError, "fESDTrackCuts not available");
199 Bool_t vertexReconstructed = AliPWG0Helper::IsVertexReconstructed(fESD);
201 Bool_t eventTriggered = AliPWG0Helper::IsEventTriggered(fESD);
204 AliGenEventHeader* genHeader = header->GenEventHeader();
207 genHeader->PrimaryVertex(vtxMC);
209 // loop over mc particles
210 Int_t nPrim = stack->GetNprimary();
212 for (Int_t iMc = 0; iMc < nPrim; ++iMc)
214 AliDebug(AliLog::kDebug+1, Form("MC Loop: Processing particle %d.", iMc));
216 TParticle* particle = stack->Particle(iMc);
220 AliDebug(AliLog::kError, Form("UNEXPECTED: particle with label %d not found in stack (mc loop).", iMc));
224 if (AliPWG0Helper::IsPrimaryCharged(particle, nPrim) == kFALSE)
227 if (SignOK(particle->GetPDG()) == kFALSE)
230 Float_t eta = particle->Eta();
231 Float_t pt = particle->Pt();
233 if (vertexReconstructed)
235 fdNdEtaCorrection->FillParticle(vtxMC[2], eta, pt);
236 if (pt > 0.1 && pt < 0.2)
237 fPIDParticles->Fill(particle->GetPdgCode());
240 fdNdEtaCorrection->FillParticleAllEvents(eta, pt);
242 fdNdEtaCorrection->FillParticleWhenEventTriggered(eta, pt);
243 }// end of mc particle
245 // ########################################################
246 // loop over esd tracks
247 Int_t nTracks = fESD->GetNumberOfTracks();
249 // count the number of "good" tracks as parameter for vertex reconstruction efficiency
250 Int_t nGoodTracks = 0;
251 for (Int_t t=0; t<nTracks; t++)
253 AliDebug(AliLog::kDebug+1, Form("ESD Loop: Processing track %d.", t));
255 AliESDtrack* esdTrack = fESD->GetTrack(t);
257 // cut the esd track?
258 if (!fEsdTrackCuts->AcceptTrack(esdTrack))
263 // using the properties of the mc particle
264 Int_t label = TMath::Abs(esdTrack->GetLabel());
267 AliDebug(AliLog::kWarning, Form("WARNING: cannot find corresponding mc part for track %d.", t));
271 TParticle* particle = stack->Particle(label);
274 AliDebug(AliLog::kError, Form("UNEXPECTED: particle with label %d not found in stack (track loop).", label));
278 if (SignOK(particle->GetPDG()) == kFALSE)
281 if (vertexReconstructed)
283 fdNdEtaCorrection->FillParticleWhenMeasuredTrack(vtxMC[2], particle->Eta(), particle->Pt());
284 if (particle->Pt() > 0.1 && particle->Pt() < 0.2)
286 fPIDTracks->Fill(particle->GetPdgCode());
287 if (particle->GetPDG()->Charge() > 0)
289 fClustersITSPos->Fill(esdTrack->GetITSclusters(0));
290 fClustersTPCPos->Fill(esdTrack->GetTPCclusters(0));
294 fClustersITSNeg->Fill(esdTrack->GetITSclusters(0));
295 fClustersTPCNeg->Fill(esdTrack->GetTPCclusters(0));
299 } // end of track loop
301 fdNdEtaCorrection->FillEvent(vtxMC[2], nGoodTracks);
304 fdNdEtaCorrection->FillEventWithTrigger(vtxMC[2], nGoodTracks);
305 if (vertexReconstructed)
306 fdNdEtaCorrection->FillEventWithTriggerWithReconstructedVertex(vtxMC[2], nGoodTracks);
312 void AlidNdEtaCorrectionSelector::SlaveTerminate()
314 // The SlaveTerminate() function is called after all entries or objects
315 // have been processed. When running with PROOF SlaveTerminate() is called
316 // on each slave server.
318 AliSelectorRL::SlaveTerminate();
320 // Add the histograms to the output on each slave server
323 AliDebug(AliLog::kError, "ERROR: Output list not initialized");
327 fOutput->Add(fdNdEtaCorrection);
330 void AlidNdEtaCorrectionSelector::Terminate()
332 // The Terminate() function is the last function to be called during
333 // a query. It always runs on the client, it can be used to present
334 // the results graphically or save the results to file.
336 AliSelectorRL::Terminate();
338 fdNdEtaCorrection = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject("dndeta_correction"));
339 if (!fdNdEtaCorrection)
341 AliDebug(AliLog::kError, "Could not read object from output list");
345 fdNdEtaCorrection->Finish();
347 TFile* fout = new TFile(Form("correction_map%s.root", GetOption()), "RECREATE");
350 fEsdTrackCuts->SaveHistograms("esd_track_cuts");
351 fdNdEtaCorrection->SaveHistograms();
356 fdNdEtaCorrection->DrawHistograms();
358 if (fPIDParticles && fPIDTracks)
360 new TCanvas("pidcanvas", "pidcanvas", 500, 500);
362 fPIDParticles->Draw();
363 fPIDTracks->SetLineColor(2);
364 fPIDTracks->Draw("SAME");
366 TDatabasePDG* pdgDB = new TDatabasePDG;
368 for (Int_t i=0; i <= fPIDParticles->GetNbinsX()+1; ++i)
369 if (fPIDParticles->GetBinContent(i) > 0)
370 printf("PDG = %d (%s): generated: %d, reconstructed: %d, ratio: %f\n", (Int_t) fPIDParticles->GetBinCenter(i), pdgDB->GetParticle((Int_t) fPIDParticles->GetBinCenter(i))->GetName(), (Int_t) fPIDParticles->GetBinContent(i), (Int_t) fPIDTracks->GetBinContent(i), ((fPIDTracks->GetBinContent(i) > 0) ? fPIDParticles->GetBinContent(i) / fPIDTracks->GetBinContent(i) : -1));
376 if (fClustersITSPos && fClustersITSNeg && fClustersTPCPos && fClustersTPCNeg)
378 TCanvas* canvas = new TCanvas("clusters", "clusters", 1000, 500);
379 canvas->Divide(2, 1);
382 fClustersITSPos->Draw();
383 fClustersITSNeg->SetLineColor(kRed);
384 fClustersITSNeg->Draw("SAME");
387 fClustersTPCPos->Draw();
388 fClustersTPCNeg->SetLineColor(kRed);
389 fClustersTPCNeg->Draw("SAME");