1 #include "AlidNdEtaCorrectionSelector.h"
7 #include <TParticlePDG.h>
10 #include <AliGenEventHeader.h>
11 #include <AliTracker.h>
13 #include "../esdTrackCuts/AliESDtrackCuts.h"
14 #include "dNdEtaCorrection.h"
16 ClassImp(AlidNdEtaCorrectionSelector)
18 AlidNdEtaCorrectionSelector::AlidNdEtaCorrectionSelector(TTree *) :
24 // Constructor. Initialization of pointers
28 AlidNdEtaCorrectionSelector::~AlidNdEtaCorrectionSelector()
34 // histograms are in the output list and deleted when the output
35 // list is deleted by the TSelector dtor
38 void AlidNdEtaCorrectionSelector::Begin(TTree * tree)
40 // The Begin() function is called at the start of the query.
41 // When running with PROOF Begin() is only called on the client.
42 // The tree argument is deprecated (on PROOF 0 is passed).
44 AliSelector::Begin(tree);
47 void AlidNdEtaCorrectionSelector::SlaveBegin(TTree * tree)
49 // The SlaveBegin() function is called after the Begin() function.
50 // When running with PROOF SlaveBegin() is called on each slave server.
51 // The tree argument is deprecated (on PROOF 0 is passed).
53 AliSelector::SlaveBegin(tree);
55 fdNdEtaCorrection = new dNdEtaCorrection();
58 fEsdTrackCuts = dynamic_cast<AliESDtrackCuts*> (fChain->GetUserInfo()->FindObject("AliESDtrackCuts"));
61 printf("ERROR: Could not read EsdTrackCuts from user info\n");
63 AliLog::SetClassDebugLevel("ESDtrackQualityCuts",1);
66 Bool_t AlidNdEtaCorrectionSelector::Notify()
68 // The Notify() function is called when a new file is opened. This
69 // can be either for a new TTree in a TChain or when when a new TTree
70 // is started when using PROOF. Typically here the branch pointers
71 // will be retrieved. It is normaly not necessary to make changes
72 // to the generated code, but the routine can be extended by the
75 if (AliSelector::Notify() == kFALSE)
81 Bool_t AlidNdEtaCorrectionSelector::IsPrimary(const TParticle* aParticle, Int_t aTotalPrimaries)
84 // Returns if the given particle is a primary particle
85 // This function or a equivalent should be available in some common place of AliRoot
88 // if the particle has a daughter primary, we do not want to count it
89 if (aParticle->GetFirstDaughter() != -1 && aParticle->GetFirstDaughter() < aTotalPrimaries)
92 Int_t pdgCode = TMath::Abs(aParticle->GetPdgCode());
94 // skip quarks and gluon
95 if (pdgCode > 10 && pdgCode != 21)
101 Bool_t AlidNdEtaCorrectionSelector::Process(Long64_t entry)
103 // The Process() function is called for each entry in the tree (or possibly
104 // keyed object in the case of PROOF) to be processed. The entry argument
105 // specifies which entry in the currently loaded tree is to be processed.
106 // It can be passed to either TTree::GetEntry() or TBranch::GetEntry()
107 // to read either all or the required parts of the data. When processing
108 // keyed objects with PROOF, the object is already loaded and is available
109 // via the fObject pointer.
111 // This function should contain the "body" of the analysis. It can contain
112 // simple or elaborate selection criteria, run algorithms on the data
113 // of the event and typically fill histograms.
115 // WARNING when a selector is used with a TChain, you must use
116 // the pointer to the current TTree to call GetEntry(entry).
117 // The entry is always the local entry number in the current tree.
118 // Assuming that fChain is the pointer to the TChain being processed,
119 // use fChain->GetTree()->GetEntry(entry).
121 if (AliSelector::Process(entry) == kFALSE)
124 if (!fESD || !fHeader)
127 // ########################################################
128 // get the EDS vertex
129 const AliESDVertex* vtxESD = fESD->GetVertex();
131 // the vertex should be reconstructed
132 if (strcmp(vtxESD->GetName(),"default")==0)
136 vtx_res[0] = vtxESD->GetXRes();
137 vtx_res[1] = vtxESD->GetYRes();
138 vtx_res[2] = vtxESD->GetZRes();
140 // the resolution should be reasonable???
141 if (vtx_res[2]==0 || vtx_res[2]>0.1)
144 // ########################################################
146 AliGenEventHeader* genHeader = fHeader->GenEventHeader();
149 genHeader->PrimaryVertex(vtxMC);
151 // ########################################################
152 // loop over mc particles
153 TTree* particleTree = GetKinematics();
154 TParticle* particle = 0;
155 particleTree->SetBranchAddress("Particles", &particle);
157 Int_t nPrim = fHeader->GetNprimary();
158 Int_t nTotal = fHeader->GetNtrack();
160 for (Int_t i_mc = nTotal - nPrim; i_mc < nTotal; ++i_mc)
162 particleTree->GetEntry(i_mc);
167 if (strcmp(particle->GetName(),"XXX") == 0)
169 printf("WARNING: There is a particle named XXX (%d).\n", i_mc);
173 TParticlePDG* pdgPart = particle->GetPDG();
175 if (strcmp(pdgPart->ParticleClass(),"Unknown") == 0)
177 printf("WARNING: There is a particle with an unknown particle class (%d pdg code %d).\n", i_mc, particle->GetPdgCode());
181 if (IsPrimary(particle, nPrim) == kFALSE)
184 if (pdgPart->Charge() == 0)
187 fdNdEtaCorrection->FillGene(vtxMC[2], particle->Eta());
189 }// end of mc particle
191 // ########################################################
192 // loop over esd tracks
193 Int_t nTracks = fESD->GetNumberOfTracks();
194 for (Int_t t=0; t<nTracks; t++)
196 AliESDtrack* esdTrack = fESD->GetTrack(t);
198 // cut the esd track?
199 if (!fEsdTrackCuts->AcceptTrack(esdTrack))
202 // using the eta of the mc particle
203 Int_t label = TMath::Abs(esdTrack->GetLabel());
206 printf("WARNING: cannot find corresponding mc part for track %d.", t);
209 particleTree->GetEntry(nTotal - nPrim + label);
211 fdNdEtaCorrection->FillMeas(vtxMC[2], particle->Eta());
213 } // end of track loop
218 void AlidNdEtaCorrectionSelector::SlaveTerminate()
220 // The SlaveTerminate() function is called after all entries or objects
221 // have been processed. When running with PROOF SlaveTerminate() is called
222 // on each slave server.
224 AliSelector::SlaveTerminate();
226 // Add the histograms to the output on each slave server
229 printf("ERROR: Output list not initialized\n");
233 fOutput->Add(fdNdEtaCorrection->GetGeneratedHistogram());
234 fOutput->Add(fdNdEtaCorrection->GetMeasuredHistogram());
237 void AlidNdEtaCorrectionSelector::Terminate()
239 // The Terminate() function is the last function to be called during
240 // a query. It always runs on the client, it can be used to present
241 // the results graphically or save the results to file.
243 AliSelector::Terminate();
245 fdNdEtaCorrectionFinal = new dNdEtaCorrection();
246 TH2F* measuredHistogram = dynamic_cast<TH2F*> (fOutput->FindObject("etaVsVtx_meas"));
247 TH2F* generatedHistogram = dynamic_cast<TH2F*> (fOutput->FindObject("etaVsVtx_gene"));
248 if (!measuredHistogram || !generatedHistogram)
250 printf("ERROR: Histograms not available %p %p\n", (void*) generatedHistogram, (void*) measuredHistogram);
253 fdNdEtaCorrectionFinal->SetGeneratedHistogram(generatedHistogram);
254 fdNdEtaCorrectionFinal->SetMeasuredHistogram(measuredHistogram);
256 fdNdEtaCorrectionFinal->Finish();
258 TFile* fout = new TFile("correction_map.root","RECREATE");
260 fEsdTrackCuts->SaveHistograms("esd_track_cuts");
261 fdNdEtaCorrectionFinal->SaveHistograms();
266 fdNdEtaCorrectionFinal->DrawHistograms();