3 #include "AlidNdEtaSystematicsSelector.h"
13 #include <TParticle.h>
17 #include <AliGenEventHeader.h>
19 #include <AliHeader.h>
21 #include "esdTrackCuts/AliESDtrackCuts.h"
22 #include "AliPWG0Helper.h"
23 #include "dNdEta/AlidNdEtaCorrection.h"
25 ClassImp(AlidNdEtaSystematicsSelector)
27 AlidNdEtaSystematicsSelector::AlidNdEtaSystematicsSelector() :
36 // Constructor. Initialization of pointers
39 for (Int_t i=0; i<4; ++i)
40 fdNdEtaCorrection[i] = 0;
43 AlidNdEtaSystematicsSelector::~AlidNdEtaSystematicsSelector()
50 void AlidNdEtaSystematicsSelector::Begin(TTree* tree)
54 AliSelectorRL::Begin(tree);
56 ReadUserObjects(tree);
59 void AlidNdEtaSystematicsSelector::ReadUserObjects(TTree* tree)
61 // read the user objects, called from slavebegin and begin
63 if (!fEsdTrackCuts && fInput)
64 fEsdTrackCuts = dynamic_cast<AliESDtrackCuts*> (fInput->FindObject("AliESDtrackCuts"));
66 if (!fEsdTrackCuts && tree)
67 fEsdTrackCuts = dynamic_cast<AliESDtrackCuts*> (tree->GetUserInfo()->FindObject("AliESDtrackCuts"));
70 AliDebug(AliLog::kError, "ERROR: Could not read EsdTrackCuts from input list.");
73 void AlidNdEtaSystematicsSelector::SlaveBegin(TTree* tree)
75 // The SlaveBegin() function is called after the Begin() function.
76 // When running with PROOF SlaveBegin() is called on each slave server.
77 // The tree argument is deprecated (on PROOF 0 is passed).
79 AliSelector::SlaveBegin(tree);
81 ReadUserObjects(tree);
83 TString option(GetOption());
85 printf("Running AlidNdEtaSystematicsSelector with options %s\n", option.Data());
87 if (option.Contains("secondaries"))
89 fSecondaries = new TH2F("fSecondaries", "fSecondaries;Case;N", 8, 0.5, 8.5, 2001, -0.5, 2000.5);
90 fSecondaries->GetXaxis()->SetBinLabel(1, "All Primaries");
91 fSecondaries->GetXaxis()->SetBinLabel(2, "All Secondaries");
92 fSecondaries->GetXaxis()->SetBinLabel(3, "Primaries pT > 0.3 GeV/c");
93 fSecondaries->GetXaxis()->SetBinLabel(4, "Secondaries pT > 0.3 GeV/c");
94 fSecondaries->GetXaxis()->SetBinLabel(5, "Tracks from Primaries");
95 fSecondaries->GetXaxis()->SetBinLabel(6, "Tracks from Secondaries");
96 fSecondaries->GetXaxis()->SetBinLabel(7, "Accepted Tracks from Primaries");
97 fSecondaries->GetXaxis()->SetBinLabel(8, "Accepted Tracks from Secondaries");
100 if (option.Contains("particle-composition"))
102 for (Int_t i=0; i<4; ++i)
105 name.Form("correction_%d", i);
106 fdNdEtaCorrection[i] = new AlidNdEtaCorrection(name, name);
110 if (option.Contains("sigma-vertex"))
112 fSigmaVertex = new TH1F("fSigmaVertex", "fSigmaVertex;Nsigma2vertex;NacceptedTracks", 10, 0.25, 5.25);
113 printf("WARNING: sigma-vertex analysis enabled. This will produce weird results in the AliESDtrackCuts histograms\n");
116 fPIDParticles = new TH1F("pid_particles", "PID of generated primary particles", 10001, -5000.5, 5000.5);
117 fPIDTracks = new TH1F("pid_tracks", "MC PID of reconstructed tracks", 10001, -5000.5, 5000.5);
120 Bool_t AlidNdEtaSystematicsSelector::Process(Long64_t entry)
122 // The Process() function is called for each entry in the tree (or possibly
123 // keyed object in the case of PROOF) to be processed. The entry argument
124 // specifies which entry in the currently loaded tree is to be processed.
125 // It can be passed to either TTree::GetEntry() or TBranch::GetEntry()
126 // to read either all or the required parts of the data. When processing
127 // keyed objects with PROOF, the object is already loaded and is available
128 // via the fObject pointer.
130 // This function should contain the "body" of the analysis. It can contain
131 // simple or elaborate selection criteria, run algorithms on the data
132 // of the event and typically fill histograms.
134 // WARNING when a selector is used with a TChain, you must use
135 // the pointer to the current TTree to call GetEntry(entry).
136 // The entry is always the local entry number in the current tree.
137 // Assuming that fTree is the pointer to the TChain being processed,
138 // use fTree->GetTree()->GetEntry(entry).
140 if (AliSelectorRL::Process(entry) == kFALSE)
143 // Check prerequisites
146 AliDebug(AliLog::kError, "ESD branch not available");
152 AliDebug(AliLog::kError, "fESDTrackCuts not available");
156 AliStack* stack = GetStack();
159 AliDebug(AliLog::kError, "Stack not available");
163 TObjArray* list = fEsdTrackCuts->GetAcceptedTracks(fESD);
165 if (fdNdEtaCorrection[0])
166 FillCorrectionMaps(list);
180 void AlidNdEtaSystematicsSelector::FillCorrectionMaps(TObjArray* listOfTracks)
182 // fills the correction maps for different particle species
184 AliStack* stack = GetStack();
185 AliHeader* header = GetHeader();
187 Bool_t vertexReconstructed = AliPWG0Helper::IsVertexReconstructed(fESD);
188 Bool_t eventTriggered = AliPWG0Helper::IsEventTriggered(fESD);
191 AliGenEventHeader* genHeader = header->GenEventHeader();
194 genHeader->PrimaryVertex(vtxMC);
196 // loop over mc particles
197 Int_t nPrim = stack->GetNprimary();
199 for (Int_t iMc = 0; iMc < nPrim; ++iMc)
201 TParticle* particle = stack->Particle(iMc);
205 AliDebug(AliLog::kError, Form("UNEXPECTED: particle with label %d not found in stack (mc loop).", iMc));
209 if (AliPWG0Helper::IsPrimaryCharged(particle, nPrim) == kFALSE)
212 Float_t eta = particle->Eta();
213 Float_t pt = particle->Pt();
216 switch (TMath::Abs(particle->GetPdgCode()))
218 case 211: id = 0; break;
219 case 321: id = 1; break;
220 case 2212: id = 2; break;
223 /*if (pt < 0.1 && particle->GetMother(0) > -1)
225 TParticle* mother = stack->Particle(particle->GetMother(0));
226 printf("Mother pdg code is %d\n", mother->GetPdgCode());
229 //if (particle->GetUniqueID() == 1)
231 //printf("Found illegal particle mc id = %d file = %s event = %d\n", iMc, fTree->GetCurrentFile()->GetName(), fTree->GetTree()->GetReadEntry());
233 default: id = 3; break;
236 if (vertexReconstructed)
238 fdNdEtaCorrection[id]->FillParticle(vtxMC[2], eta, pt);
240 fPIDParticles->Fill(particle->GetPdgCode());
243 fdNdEtaCorrection[id]->FillParticleAllEvents(eta, pt);
245 fdNdEtaCorrection[id]->FillParticleWhenEventTriggered(eta, pt);
246 }// end of mc particle
248 // loop over esd tracks
249 TIterator* iter = listOfTracks->MakeIterator();
251 while ((obj = iter->Next()) != 0)
253 AliESDtrack* esdTrack = dynamic_cast<AliESDtrack*> (obj);
257 // using the properties of the mc particle
258 Int_t label = TMath::Abs(esdTrack->GetLabel());
259 TParticle* particle = stack->Particle(label);
262 AliDebug(AliLog::kError, Form("UNEXPECTED: particle with label %d not found in stack (track loop).", label));
266 TParticle* mother = particle;
267 // find primary particle that created this particle
268 while (label >= nPrim)
270 //printf("Particle %d (pdg %d) is not a primary. Let's check its mother %d\n", label, mother->GetPdgCode(), mother->GetMother(0));
272 if (mother->GetMother(0) == -1)
274 AliDebug(AliLog::kError, Form("UNEXPECTED: Could not find mother of secondary particle %d.", label));
279 label = mother->GetMother(0);
281 mother = stack->Particle(label);
284 AliDebug(AliLog::kError, Form("UNEXPECTED: particle with label %d not found in stack (find mother loop).", label));
292 //printf("We continue with particle %d (pdg %d)\n", label, mother->GetPdgCode());
295 switch (TMath::Abs(mother->GetPdgCode()))
297 case 211: id = 0; break;
298 case 321: id = 1; break;
299 case 2212: id = 2; break;
300 default: id = 3; break;
303 if (vertexReconstructed)
305 fdNdEtaCorrection[id]->FillParticleWhenMeasuredTrack(vtxMC[2], particle->Eta(), particle->Pt());
306 //if (particle->Pt() < 0.1)
307 fPIDTracks->Fill(particle->GetPdgCode());
309 } // end of track loop
311 Int_t nGoodTracks = listOfTracks->GetEntries();
313 for (Int_t i=0; i<4; ++i)
315 fdNdEtaCorrection[i]->FillEvent(vtxMC[2], nGoodTracks);
318 fdNdEtaCorrection[i]->FillEventWithTrigger(vtxMC[2], nGoodTracks);
319 if (vertexReconstructed)
320 fdNdEtaCorrection[i]->FillEventWithTriggerWithReconstructedVertex(vtxMC[2], nGoodTracks);
328 void AlidNdEtaSystematicsSelector::FillSecondaries()
330 // fills the secondary histograms
332 AliStack* stack = GetStack();
334 Int_t particlesPrimaries = 0;
335 Int_t particlesSecondaries = 0;
336 Int_t particlesPrimariesPtCut = 0;
337 Int_t particlesSecondariesPtCut = 0;
339 for (Int_t iParticle = 0; iParticle < stack->GetNtrack(); iParticle++)
341 TParticle* particle = stack->Particle(iParticle);
344 AliDebug(AliLog::kError, Form("UNEXPECTED: particle with label %d not found in stack (particle loop).", iParticle));
348 if (TMath::Abs(particle->Eta()) > 0.9)
351 Bool_t isPrimary = kFALSE;
352 if (iParticle < stack->GetNprimary())
354 if (AliPWG0Helper::IsPrimaryCharged(particle, stack->GetNprimary()) == kFALSE)
361 particlesPrimaries++;
363 particlesSecondaries++;
365 if (particle->Pt() < 0.3)
369 particlesPrimariesPtCut++;
371 particlesSecondariesPtCut++;
374 fSecondaries->Fill(1, particlesPrimaries);
375 fSecondaries->Fill(2, particlesSecondaries);
376 fSecondaries->Fill(3, particlesPrimariesPtCut);
377 fSecondaries->Fill(4, particlesSecondariesPtCut);
379 Int_t allTracksPrimaries = 0;
380 Int_t allTracksSecondaries = 0;
381 Int_t acceptedTracksPrimaries = 0;
382 Int_t acceptedTracksSecondaries = 0;
384 for (Int_t iTrack = 0; iTrack < fESD->GetNumberOfTracks(); iTrack++)
386 AliESDtrack* esdTrack = fESD->GetTrack(iTrack);
389 AliDebug(AliLog::kError, Form("UNEXPECTED: Could not get track %d.", iTrack));
393 Int_t label = TMath::Abs(esdTrack->GetLabel());
394 TParticle* particle = stack->Particle(label);
397 AliDebug(AliLog::kError, Form("UNEXPECTED: particle with label %d not found in stack (track loop).", label));
401 if (label < stack->GetNprimary())
402 allTracksPrimaries++;
404 allTracksSecondaries++;
406 if (!fEsdTrackCuts->AcceptTrack(esdTrack))
409 if (label < stack->GetNprimary())
410 acceptedTracksPrimaries++;
412 acceptedTracksSecondaries++;
415 fSecondaries->Fill(5, allTracksPrimaries);
416 fSecondaries->Fill(6, allTracksSecondaries);
417 fSecondaries->Fill(7, acceptedTracksPrimaries);
418 fSecondaries->Fill(8, acceptedTracksSecondaries);
420 //printf("P = %d, S = %d, P_pt = %d, S_pt = %d, T_P = %d, T_S = %d, T_P_acc = %d, T_S_acc = %d\n", particlesPrimaries, particlesSecondaries, particlesPrimariesPtCut, particlesSecondariesPtCut, allTracksPrimaries, allTracksSecondaries, acceptedTracksPrimaries, acceptedTracksSecondaries);
423 void AlidNdEtaSystematicsSelector::FillSigmaVertex()
425 // fills the fSigmaVertex histogram
427 // save the old value
428 Float_t oldSigmaVertex = fEsdTrackCuts->GetMinNsigmaToVertex();
431 fEsdTrackCuts->SetMinNsigmaToVertex(5);
433 TObjArray* list = fEsdTrackCuts->GetAcceptedTracks(fESD);
435 TIterator* iter = list->MakeIterator();
437 while ((obj = iter->Next()) != 0)
439 AliESDtrack* esdTrack = dynamic_cast<AliESDtrack*> (obj);
443 Float_t sigma2Vertex = fEsdTrackCuts->GetSigmaToVertex(esdTrack);
445 for (Double_t nSigma = 0.5; nSigma < 5.1; nSigma += 0.5)
447 if (sigma2Vertex < nSigma)
448 fSigmaVertex->Fill(nSigma);
458 // set back the old value
459 fEsdTrackCuts->SetMinNsigmaToVertex(oldSigmaVertex);
462 void AlidNdEtaSystematicsSelector::SlaveTerminate()
464 // The SlaveTerminate() function is called after all entries or objects
465 // have been processed. When running with PROOF SlaveTerminate() is called
466 // on each slave server.
468 AliSelector::SlaveTerminate();
470 // Add the histograms to the output on each slave server
473 AliDebug(AliLog::kError, Form("ERROR: Output list not initialized."));
478 fOutput->Add(fSecondaries);
480 for (Int_t i=0; i<4; ++i)
481 if (fdNdEtaCorrection[i])
482 fOutput->Add(fdNdEtaCorrection[i]);
485 fOutput->Add(fSigmaVertex);
488 void AlidNdEtaSystematicsSelector::Terminate()
490 // The Terminate() function is the last function to be called during
491 // a query. It always runs on the client, it can be used to present
492 // the results graphically or save the results to file.
494 AliSelector::Terminate();
496 fSecondaries = dynamic_cast<TH2F*> (fOutput->FindObject("fSecondaries"));
497 for (Int_t i=0; i<4; ++i)
498 fdNdEtaCorrection[i] = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject(Form("correction_%d", i)));
499 fSigmaVertex = dynamic_cast<TH1F*> (fOutput->FindObject("fSigmaVertex"));
503 TDatabasePDG* pdgDB = new TDatabasePDG;
505 for (Int_t i=0; i <= fPIDParticles->GetNbinsX()+1; ++i)
506 if (fPIDParticles->GetBinContent(i) > 0)
507 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));
513 TFile* fout = TFile::Open("systematics.root", "RECREATE");
516 fEsdTrackCuts->SaveHistograms("esd_track_cuts");
519 fSecondaries->Write();
522 fSigmaVertex->Write();
524 for (Int_t i=0; i<4; ++i)
525 if (fdNdEtaCorrection[i])
526 fdNdEtaCorrection[i]->SaveHistograms();
534 fSecondaries->Draw("COLZ");
540 fSigmaVertex->Draw();