3 #include "AlidNdEtaSystematicsSelector.h"
13 #include <TParticle.h>
18 #include <AliHeader.h>
19 #include <AliGenEventHeader.h>
20 #include <AliGenPythiaEventHeader.h>
21 #include <AliGenCocktailEventHeader.h>
24 #include "esdTrackCuts/AliESDtrackCuts.h"
25 #include "AliPWG0Helper.h"
26 #include "dNdEta/AlidNdEtaCorrection.h"
28 ClassImp(AlidNdEtaSystematicsSelector)
30 AlidNdEtaSystematicsSelector::AlidNdEtaSystematicsSelector() :
39 // Constructor. Initialization of pointers
42 for (Int_t i=0; i<4; ++i)
43 fdNdEtaCorrectionSpecies[i] = 0;
45 for (Int_t i=0; i<3; ++i) {
46 fdNdEtaCorrectionVertexReco[i] = 0;
47 fdNdEtaCorrectionTriggerBias[i] = 0;
51 AlidNdEtaSystematicsSelector::~AlidNdEtaSystematicsSelector()
58 void AlidNdEtaSystematicsSelector::Begin(TTree* tree)
62 AliSelectorRL::Begin(tree);
64 ReadUserObjects(tree);
67 void AlidNdEtaSystematicsSelector::ReadUserObjects(TTree* tree)
69 // read the user objects, called from slavebegin and begin
71 if (!fEsdTrackCuts && fInput)
72 fEsdTrackCuts = dynamic_cast<AliESDtrackCuts*> (fInput->FindObject("AliESDtrackCuts"));
74 if (!fEsdTrackCuts && tree)
75 fEsdTrackCuts = dynamic_cast<AliESDtrackCuts*> (tree->GetUserInfo()->FindObject("AliESDtrackCuts"));
78 AliDebug(AliLog::kError, "ERROR: Could not read EsdTrackCuts from input list.");
81 void AlidNdEtaSystematicsSelector::SlaveBegin(TTree* tree)
83 // The SlaveBegin() function is called after the Begin() function.
84 // When running with PROOF SlaveBegin() is called on each slave server.
85 // The tree argument is deprecated (on PROOF 0 is passed).
87 AliSelector::SlaveBegin(tree);
89 ReadUserObjects(tree);
91 TString option(GetOption());
93 printf("Running AlidNdEtaSystematicsSelector with options %s\n", option.Data());
95 if (option.Contains("secondaries"))
97 fSecondaries = new TH2F("fSecondaries", "fSecondaries;Case;N", 8, 0.5, 8.5, 2001, -0.5, 2000.5);
98 fSecondaries->GetXaxis()->SetBinLabel(1, "All Primaries");
99 fSecondaries->GetXaxis()->SetBinLabel(2, "All Secondaries");
100 fSecondaries->GetXaxis()->SetBinLabel(3, "Primaries pT > 0.3 GeV/c");
101 fSecondaries->GetXaxis()->SetBinLabel(4, "Secondaries pT > 0.3 GeV/c");
102 fSecondaries->GetXaxis()->SetBinLabel(5, "Tracks from Primaries");
103 fSecondaries->GetXaxis()->SetBinLabel(6, "Tracks from Secondaries");
104 fSecondaries->GetXaxis()->SetBinLabel(7, "Accepted Tracks from Primaries");
105 fSecondaries->GetXaxis()->SetBinLabel(8, "Accepted Tracks from Secondaries");
108 if (option.Contains("particle-composition"))
110 for (Int_t i=0; i<4; ++i)
113 name.Form("correction_%d", i);
114 fdNdEtaCorrectionSpecies[i] = new AlidNdEtaCorrection(name, name);
118 if (option.Contains("sigma-vertex"))
120 fSigmaVertex = new TH1F("fSigmaVertex", "fSigmaVertex;Nsigma2vertex;NacceptedTracks", 50, 0.05, 5.05);
121 printf("WARNING: sigma-vertex analysis enabled. This will produce weird results in the AliESDtrackCuts histograms\n");
124 if (option.Contains("vertexreco")) {
125 fdNdEtaCorrectionVertexReco[0] = new AlidNdEtaCorrection("vertexRecoND", "vertexRecoND");
126 fdNdEtaCorrectionVertexReco[1] = new AlidNdEtaCorrection("vertexRecoSD", "vertexRecoSD");
127 fdNdEtaCorrectionVertexReco[2] = new AlidNdEtaCorrection("vertexRecoDD", "vertexRecoDD");
130 if (option.Contains("triggerbias")) {
131 fdNdEtaCorrectionTriggerBias[0] = new AlidNdEtaCorrection("triggerBiasND", "triggerBiasND");
132 fdNdEtaCorrectionTriggerBias[1] = new AlidNdEtaCorrection("triggerBiasSD", "triggerBiasSD");
133 fdNdEtaCorrectionTriggerBias[2] = new AlidNdEtaCorrection("triggerBiasDD", "triggerBiasDD");
137 fPIDParticles = new TH1F("pid_particles", "PID of generated primary particles", 10001, -5000.5, 5000.5);
138 fPIDTracks = new TH1F("pid_tracks", "MC PID of reconstructed tracks", 10001, -5000.5, 5000.5);
141 Bool_t AlidNdEtaSystematicsSelector::Process(Long64_t entry)
143 // The Process() function is called for each entry in the tree (or possibly
144 // keyed object in the case of PROOF) to be processed. The entry argument
145 // specifies which entry in the currently loaded tree is to be processed.
146 // It can be passed to either TTree::GetEntry() or TBranch::GetEntry()
147 // to read either all or the required parts of the data. When processing
148 // keyed objects with PROOF, the object is already loaded and is available
149 // via the fObject pointer.
151 // This function should contain the "body" of the analysis. It can contain
152 // simple or elaborate selection criteria, run algorithms on the data
153 // of the event and typically fill histograms.
155 // WARNING when a selector is used with a TChain, you must use
156 // the pointer to the current TTree to call GetEntry(entry).
157 // The entry is always the local entry number in the current tree.
158 // Assuming that fTree is the pointer to the TChain being processed,
159 // use fTree->GetTree()->GetEntry(entry).
161 if (AliSelectorRL::Process(entry) == kFALSE)
164 // Check prerequisites
167 AliDebug(AliLog::kError, "ESD branch not available");
173 AliDebug(AliLog::kError, "fESDTrackCuts not available");
177 AliStack* stack = GetStack();
180 AliDebug(AliLog::kError, "Stack not available");
184 TObjArray* list = fEsdTrackCuts->GetAcceptedTracks(fESD);
186 if (fdNdEtaCorrectionSpecies[0])
187 FillCorrectionMaps(list);
195 // stuff for vertex reconstruction correction systematics
196 Bool_t vertexRecoStudy = kFALSE;
197 Bool_t triggerBiasStudy = kFALSE;
198 if (fdNdEtaCorrectionVertexReco[0]) vertexRecoStudy = kTRUE;
199 if (fdNdEtaCorrectionTriggerBias[0]) triggerBiasStudy = kTRUE;
201 if (vertexRecoStudy || triggerBiasStudy) {
202 AliHeader* header = GetHeader();
204 AliDebug(AliLog::kError, "Header not available");
208 // getting process information
209 Int_t processtype = AliPWG0Helper::GetPythiaEventProcessType(header);
211 AliDebug(AliLog::kInfo, Form("Pythia process type %d.",processtype));
213 // can only read pythia headers, either directly or from cocktalil header
214 AliGenEventHeader* genHeader = (AliGenEventHeader*)(header->GenEventHeader());
217 AliDebug(AliLog::kError, "Gen header not available");
223 genHeader->PrimaryVertex(vtxMC);
225 Int_t nGoodTracks = list->GetEntries();
227 Bool_t eventTriggered = AliPWG0Helper::IsEventTriggered(fESD);
228 Bool_t vertexReconstructed = AliPWG0Helper::IsVertexReconstructed(fESD);
231 if (processtype!=92 && processtype!=93 && processtype!=94) {
232 if (triggerBiasStudy) fdNdEtaCorrectionTriggerBias[0]->FillEventAll(vtxMC[2], nGoodTracks);
234 if (eventTriggered) {
235 if (triggerBiasStudy) fdNdEtaCorrectionTriggerBias[0]->FillEventWithTrigger(vtxMC[2], nGoodTracks);
236 if (vertexRecoStudy) fdNdEtaCorrectionVertexReco[0]->FillEventWithTrigger(vtxMC[2], nGoodTracks);
238 if (vertexReconstructed)
239 if (vertexRecoStudy) fdNdEtaCorrectionVertexReco[0]->FillEventWithTriggerWithReconstructedVertex(vtxMC[2], nGoodTracks);
243 // single diffractive
244 if (processtype==92 || processtype==93) {
245 if (triggerBiasStudy) fdNdEtaCorrectionTriggerBias[1]->FillEventAll(vtxMC[2], nGoodTracks);
247 if (eventTriggered) {
248 if (triggerBiasStudy) fdNdEtaCorrectionTriggerBias[1]->FillEventWithTrigger(vtxMC[2], nGoodTracks);
249 if (vertexRecoStudy) fdNdEtaCorrectionVertexReco[1]->FillEventWithTrigger(vtxMC[2], nGoodTracks);
251 if (vertexReconstructed)
252 if (vertexRecoStudy) fdNdEtaCorrectionVertexReco[1]->FillEventWithTriggerWithReconstructedVertex(vtxMC[2], nGoodTracks);
256 // double diffractive
257 if (processtype==94) {
258 if (triggerBiasStudy) fdNdEtaCorrectionTriggerBias[2]->FillEventAll(vtxMC[2], nGoodTracks);
260 if (eventTriggered) {
261 if (triggerBiasStudy) fdNdEtaCorrectionTriggerBias[2]->FillEventWithTrigger(vtxMC[2], nGoodTracks);
262 if (vertexRecoStudy) fdNdEtaCorrectionVertexReco[2]->FillEventWithTrigger(vtxMC[2], nGoodTracks);
264 if (vertexReconstructed)
265 if (vertexRecoStudy) fdNdEtaCorrectionVertexReco[2]->FillEventWithTriggerWithReconstructedVertex(vtxMC[2], nGoodTracks);
276 void AlidNdEtaSystematicsSelector::FillCorrectionMaps(TObjArray* listOfTracks)
278 // fills the correction maps for different particle species
280 AliStack* stack = GetStack();
281 AliHeader* header = GetHeader();
283 Bool_t vertexReconstructed = AliPWG0Helper::IsVertexReconstructed(fESD);
284 Bool_t eventTriggered = AliPWG0Helper::IsEventTriggered(fESD);
287 AliGenEventHeader* genHeader = header->GenEventHeader();
290 genHeader->PrimaryVertex(vtxMC);
292 // loop over mc particles
293 Int_t nPrim = stack->GetNprimary();
295 for (Int_t iMc = 0; iMc < nPrim; ++iMc)
297 TParticle* particle = stack->Particle(iMc);
301 AliDebug(AliLog::kError, Form("UNEXPECTED: particle with label %d not found in stack (mc loop).", iMc));
305 if (AliPWG0Helper::IsPrimaryCharged(particle, nPrim) == kFALSE)
308 Float_t eta = particle->Eta();
309 Float_t pt = particle->Pt();
312 switch (TMath::Abs(particle->GetPdgCode()))
314 case 211: id = 0; break;
315 case 321: id = 1; break;
316 case 2212: id = 2; break;
319 /*if (pt < 0.1 && particle->GetMother(0) > -1)
321 TParticle* mother = stack->Particle(particle->GetMother(0));
322 printf("Mother pdg code is %d\n", mother->GetPdgCode());
325 //if (particle->GetUniqueID() == 1)
327 //printf("Found illegal particle mc id = %d file = %s event = %d\n", iMc, fTree->GetCurrentFile()->GetName(), fTree->GetTree()->GetReadEntry());
329 default: id = 3; break;
332 if (vertexReconstructed)
334 fdNdEtaCorrectionSpecies[id]->FillParticle(vtxMC[2], eta, pt);
336 fPIDParticles->Fill(particle->GetPdgCode());
339 //fdNdEtaCorrectionSpecies[id]->FillParticleAllEvents(eta, pt);
340 //if (eventTriggered)
341 // fdNdEtaCorrectionSpecies[id]->FillParticleWhenEventTriggered(eta, pt);
342 }// end of mc particle
344 // loop over esd tracks
345 TIterator* iter = listOfTracks->MakeIterator();
347 while ((obj = iter->Next()) != 0)
349 AliESDtrack* esdTrack = dynamic_cast<AliESDtrack*> (obj);
353 // using the properties of the mc particle
354 Int_t label = TMath::Abs(esdTrack->GetLabel());
355 TParticle* particle = stack->Particle(label);
358 AliDebug(AliLog::kError, Form("UNEXPECTED: particle with label %d not found in stack (track loop).", label));
362 TParticle* mother = particle;
363 // find primary particle that created this particle
364 while (label >= nPrim)
366 //printf("Particle %d (pdg %d) is not a primary. Let's check its mother %d\n", label, mother->GetPdgCode(), mother->GetMother(0));
368 if (mother->GetMother(0) == -1)
370 AliDebug(AliLog::kError, Form("UNEXPECTED: Could not find mother of secondary particle %d.", label));
375 label = mother->GetMother(0);
377 mother = stack->Particle(label);
380 AliDebug(AliLog::kError, Form("UNEXPECTED: particle with label %d not found in stack (find mother loop).", label));
388 //printf("We continue with particle %d (pdg %d)\n", label, mother->GetPdgCode());
391 switch (TMath::Abs(mother->GetPdgCode()))
393 case 211: id = 0; break;
394 case 321: id = 1; break;
395 case 2212: id = 2; break;
396 default: id = 3; break;
399 if (vertexReconstructed)
401 fdNdEtaCorrectionSpecies[id]->FillParticleWhenMeasuredTrack(vtxMC[2], particle->Eta(), particle->Pt());
402 //if (particle->Pt() < 0.1)
403 fPIDTracks->Fill(particle->GetPdgCode());
405 } // end of track loop
407 Int_t nGoodTracks = listOfTracks->GetEntries();
409 for (Int_t i=0; i<4; ++i)
411 fdNdEtaCorrectionSpecies[i]->FillEventAll(vtxMC[2], nGoodTracks);
414 fdNdEtaCorrectionSpecies[i]->FillEventWithTrigger(vtxMC[2], nGoodTracks);
415 if (vertexReconstructed)
416 fdNdEtaCorrectionSpecies[i]->FillEventWithTriggerWithReconstructedVertex(vtxMC[2], nGoodTracks);
424 void AlidNdEtaSystematicsSelector::FillSecondaries()
426 // fills the secondary histograms
428 AliStack* stack = GetStack();
430 Int_t particlesPrimaries = 0;
431 Int_t particlesSecondaries = 0;
432 Int_t particlesPrimariesPtCut = 0;
433 Int_t particlesSecondariesPtCut = 0;
435 for (Int_t iParticle = 0; iParticle < stack->GetNtrack(); iParticle++)
437 TParticle* particle = stack->Particle(iParticle);
440 AliDebug(AliLog::kError, Form("UNEXPECTED: particle with label %d not found in stack (particle loop).", iParticle));
444 if (TMath::Abs(particle->Eta()) > 0.9)
447 Bool_t isPrimary = kFALSE;
448 if (iParticle < stack->GetNprimary())
450 if (AliPWG0Helper::IsPrimaryCharged(particle, stack->GetNprimary()) == kFALSE)
457 particlesPrimaries++;
459 particlesSecondaries++;
461 if (particle->Pt() < 0.3)
465 particlesPrimariesPtCut++;
467 particlesSecondariesPtCut++;
470 fSecondaries->Fill(1, particlesPrimaries);
471 fSecondaries->Fill(2, particlesSecondaries);
472 fSecondaries->Fill(3, particlesPrimariesPtCut);
473 fSecondaries->Fill(4, particlesSecondariesPtCut);
475 Int_t allTracksPrimaries = 0;
476 Int_t allTracksSecondaries = 0;
477 Int_t acceptedTracksPrimaries = 0;
478 Int_t acceptedTracksSecondaries = 0;
480 for (Int_t iTrack = 0; iTrack < fESD->GetNumberOfTracks(); iTrack++)
482 AliESDtrack* esdTrack = fESD->GetTrack(iTrack);
485 AliDebug(AliLog::kError, Form("UNEXPECTED: Could not get track %d.", iTrack));
489 Int_t label = TMath::Abs(esdTrack->GetLabel());
490 TParticle* particle = stack->Particle(label);
493 AliDebug(AliLog::kError, Form("UNEXPECTED: particle with label %d not found in stack (track loop).", label));
497 if (label < stack->GetNprimary())
498 allTracksPrimaries++;
500 allTracksSecondaries++;
502 if (!fEsdTrackCuts->AcceptTrack(esdTrack))
505 if (label < stack->GetNprimary())
506 acceptedTracksPrimaries++;
508 acceptedTracksSecondaries++;
511 fSecondaries->Fill(5, allTracksPrimaries);
512 fSecondaries->Fill(6, allTracksSecondaries);
513 fSecondaries->Fill(7, acceptedTracksPrimaries);
514 fSecondaries->Fill(8, acceptedTracksSecondaries);
516 //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);
519 void AlidNdEtaSystematicsSelector::FillSigmaVertex()
521 // fills the fSigmaVertex histogram
523 // save the old value
524 Float_t oldSigmaVertex = fEsdTrackCuts->GetMinNsigmaToVertex();
527 fEsdTrackCuts->SetMinNsigmaToVertex(5);
529 TObjArray* list = fEsdTrackCuts->GetAcceptedTracks(fESD);
531 TIterator* iter = list->MakeIterator();
533 while ((obj = iter->Next()) != 0)
535 AliESDtrack* esdTrack = dynamic_cast<AliESDtrack*> (obj);
539 Float_t sigma2Vertex = fEsdTrackCuts->GetSigmaToVertex(esdTrack);
541 for (Double_t nSigma = 0.1; nSigma < 5.05; nSigma += 0.1)
543 if (sigma2Vertex < nSigma)
544 fSigmaVertex->Fill(nSigma);
554 // set back the old value
555 fEsdTrackCuts->SetMinNsigmaToVertex(oldSigmaVertex);
558 void AlidNdEtaSystematicsSelector::SlaveTerminate()
560 // The SlaveTerminate() function is called after all entries or objects
561 // have been processed. When running with PROOF SlaveTerminate() is called
562 // on each slave server.
564 AliSelector::SlaveTerminate();
566 // Add the histograms to the output on each slave server
569 AliDebug(AliLog::kError, Form("ERROR: Output list not initialized."));
574 fOutput->Add(fSecondaries);
576 for (Int_t i=0; i<4; ++i)
577 if (fdNdEtaCorrectionSpecies[i])
578 fOutput->Add(fdNdEtaCorrectionSpecies[i]);
581 fOutput->Add(fSigmaVertex);
583 for (Int_t i=0; i<3; ++i) {
584 if (fdNdEtaCorrectionVertexReco[i])
585 fOutput->Add(fdNdEtaCorrectionVertexReco[i]);
587 if (fdNdEtaCorrectionTriggerBias[i])
588 fOutput->Add(fdNdEtaCorrectionTriggerBias[i]);
593 void AlidNdEtaSystematicsSelector::Terminate()
595 // The Terminate() function is the last function to be called during
596 // a query. It always runs on the client, it can be used to present
597 // the results graphically or save the results to file.
599 AliSelector::Terminate();
601 fSecondaries = dynamic_cast<TH2F*> (fOutput->FindObject("fSecondaries"));
602 for (Int_t i=0; i<4; ++i)
603 fdNdEtaCorrectionSpecies[i] = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject(Form("correction_%d", i)));
604 fSigmaVertex = dynamic_cast<TH1F*> (fOutput->FindObject("fSigmaVertex"));
608 TDatabasePDG* pdgDB = new TDatabasePDG;
610 for (Int_t i=0; i <= fPIDParticles->GetNbinsX()+1; ++i)
611 if (fPIDParticles->GetBinContent(i) > 0)
612 printf("PDG = %d (%s): generated: %d, reconstructed: %d, ratio: %f\n",
613 (Int_t) fPIDParticles->GetBinCenter(i),
614 pdgDB->GetParticle((Int_t) fPIDParticles->GetBinCenter(i))->GetName(),
615 (Int_t) fPIDParticles->GetBinContent(i),
616 (Int_t) fPIDTracks->GetBinContent(i),
617 ((fPIDTracks->GetBinContent(i) > 0) ? fPIDParticles->GetBinContent(i) / fPIDTracks->GetBinContent(i) : -1));
623 for (Int_t i=0; i<3; ++i) {
624 if (fdNdEtaCorrectionVertexReco[i])
625 fdNdEtaCorrectionVertexReco[i]->Finish();
627 if (fdNdEtaCorrectionTriggerBias[i])
628 fdNdEtaCorrectionTriggerBias[i]->Finish();
631 TFile* fout = TFile::Open("systematics.root", "RECREATE");
634 fEsdTrackCuts->SaveHistograms("esd_track_cuts");
637 fSecondaries->Write();
640 fSigmaVertex->Write();
642 for (Int_t i=0; i<4; ++i)
643 if (fdNdEtaCorrectionSpecies[i])
644 fdNdEtaCorrectionSpecies[i]->SaveHistograms();
646 for (Int_t i=0; i<3; ++i) {
647 if (fdNdEtaCorrectionVertexReco[i])
648 fdNdEtaCorrectionVertexReco[i]->SaveHistograms();
650 if (fdNdEtaCorrectionTriggerBias[i])
651 fdNdEtaCorrectionTriggerBias[i]->SaveHistograms();
660 fSecondaries->Draw("COLZ");
666 fSigmaVertex->Draw();