3 #include "AlidNdEtaCorrectionSelector.h"
9 #include <TParticlePDG.h>
12 #include <AliGenEventHeader.h>
13 #include <AliTracker.h>
15 #include "esdTrackCuts/AliESDtrackCuts.h"
16 #include "dNdEtaCorrection.h"
18 ClassImp(AlidNdEtaCorrectionSelector)
20 AlidNdEtaCorrectionSelector::AlidNdEtaCorrectionSelector(TTree *) :
24 fdNdEtaCorrectionFinal(0)
27 // Constructor. Initialization of pointers
31 AlidNdEtaCorrectionSelector::~AlidNdEtaCorrectionSelector()
37 // histograms are in the output list and deleted when the output
38 // list is deleted by the TSelector dtor
41 void AlidNdEtaCorrectionSelector::Begin(TTree * tree)
43 // The Begin() function is called at the start of the query.
44 // When running with PROOF Begin() is only called on the client.
45 // The tree argument is deprecated (on PROOF 0 is passed).
47 AliSelector::Begin(tree);
50 void AlidNdEtaCorrectionSelector::SlaveBegin(TTree * tree)
52 // The SlaveBegin() function is called after the Begin() function.
53 // When running with PROOF SlaveBegin() is called on each slave server.
54 // The tree argument is deprecated (on PROOF 0 is passed).
56 AliSelector::SlaveBegin(tree);
58 fdNdEtaCorrection = new dNdEtaCorrection();
61 fEsdTrackCuts = dynamic_cast<AliESDtrackCuts*> (fChain->GetUserInfo()->FindObject("AliESDtrackCuts"));
64 AliDebug(AliLog::kError, "ERROR: Could not read EsdTrackCuts from user info");
67 Bool_t AlidNdEtaCorrectionSelector::Notify()
69 // The Notify() function is called when a new file is opened. This
70 // can be either for a new TTree in a TChain or when when a new TTree
71 // is started when using PROOF. Typically here the branch pointers
72 // will be retrieved. It is normaly not necessary to make changes
73 // to the generated code, but the routine can be extended by the
76 if (AliSelector::Notify() == kFALSE)
82 Bool_t AlidNdEtaCorrectionSelector::Process(Long64_t entry)
84 // The Process() function is called for each entry in the tree (or possibly
85 // keyed object in the case of PROOF) to be processed. The entry argument
86 // specifies which entry in the currently loaded tree is to be processed.
87 // It can be passed to either TTree::GetEntry() or TBranch::GetEntry()
88 // to read either all or the required parts of the data. When processing
89 // keyed objects with PROOF, the object is already loaded and is available
90 // via the fObject pointer.
92 // This function should contain the "body" of the analysis. It can contain
93 // simple or elaborate selection criteria, run algorithms on the data
94 // of the event and typically fill histograms.
96 // WARNING when a selector is used with a TChain, you must use
97 // the pointer to the current TTree to call GetEntry(entry).
98 // The entry is always the local entry number in the current tree.
99 // Assuming that fChain is the pointer to the TChain being processed,
100 // use fChain->GetTree()->GetEntry(entry).
102 if (AliSelector::Process(entry) == kFALSE)
105 // check prerequesites
108 AliDebug(AliLog::kError, "ESD branch not available");
112 AliHeader* header = GetHeader();
115 AliDebug(AliLog::kError, "Header not available");
121 AliDebug(AliLog::kError, "fESDTrackCuts not available");
125 // ########################################################
126 // get the EDS vertex
127 const AliESDVertex* vtxESD = fESD->GetVertex();
129 // the vertex should be reconstructed
130 if (strcmp(vtxESD->GetName(),"default")==0)
134 vtx_res[0] = vtxESD->GetXRes();
135 vtx_res[1] = vtxESD->GetYRes();
136 vtx_res[2] = vtxESD->GetZRes();
138 // the resolution should be reasonable???
139 if (vtx_res[2]==0 || vtx_res[2]>0.1)
142 // ########################################################
144 AliGenEventHeader* genHeader = header->GenEventHeader();
147 genHeader->PrimaryVertex(vtxMC);
149 // ########################################################
150 // loop over mc particles
151 TTree* particleTree = GetKinematics();
152 TParticle* particle = 0;
153 particleTree->SetBranchAddress("Particles", &particle);
155 Int_t nPrim = header->GetNprimary();
156 Int_t nTotal = header->GetNtrack();
158 for (Int_t i_mc = nTotal - nPrim; i_mc < nTotal; ++i_mc)
160 particleTree->GetEntry(i_mc);
165 if (IsPrimaryCharged(particle, nPrim) == kFALSE)
168 fdNdEtaCorrection->FillGene(vtxMC[2], particle->Eta());
169 }// end of mc particle
171 // ########################################################
172 // loop over esd tracks
173 Int_t nTracks = fESD->GetNumberOfTracks();
174 for (Int_t t=0; t<nTracks; t++)
176 AliESDtrack* esdTrack = fESD->GetTrack(t);
178 // cut the esd track?
179 if (!fEsdTrackCuts->AcceptTrack(esdTrack))
182 // using the eta of the mc particle
183 Int_t label = TMath::Abs(esdTrack->GetLabel());
186 AliDebug(AliLog::kWarning, Form("WARNING: cannot find corresponding mc part for track %d.", t));
189 particleTree->GetEntry(nTotal - nPrim + label);
191 fdNdEtaCorrection->FillMeas(vtxMC[2], particle->Eta());
193 } // end of track loop
198 void AlidNdEtaCorrectionSelector::SlaveTerminate()
200 // The SlaveTerminate() function is called after all entries or objects
201 // have been processed. When running with PROOF SlaveTerminate() is called
202 // on each slave server.
204 AliSelector::SlaveTerminate();
206 // Add the histograms to the output on each slave server
209 AliDebug(AliLog::kError, "ERROR: Output list not initialized");
213 fOutput->Add(fdNdEtaCorrection->GetGeneratedHistogram());
214 fOutput->Add(fdNdEtaCorrection->GetMeasuredHistogram());
217 void AlidNdEtaCorrectionSelector::Terminate()
219 // The Terminate() function is the last function to be called during
220 // a query. It always runs on the client, it can be used to present
221 // the results graphically or save the results to file.
223 AliSelector::Terminate();
225 fdNdEtaCorrectionFinal = new dNdEtaCorrection();
226 TH2F* measuredHistogram = dynamic_cast<TH2F*> (fOutput->FindObject("etaVsVtx_meas"));
227 TH2F* generatedHistogram = dynamic_cast<TH2F*> (fOutput->FindObject("etaVsVtx_gene"));
228 if (!measuredHistogram || !generatedHistogram)
230 AliDebug(AliLog::kError, Form("ERROR: Histograms not available %p %p", (void*) generatedHistogram, (void*) measuredHistogram));
233 fdNdEtaCorrectionFinal->SetGeneratedHistogram(generatedHistogram);
234 fdNdEtaCorrectionFinal->SetMeasuredHistogram(measuredHistogram);
236 fdNdEtaCorrectionFinal->Finish();
238 TFile* fout = new TFile("correction_map.root","RECREATE");
240 fEsdTrackCuts->SaveHistograms("esd_track_cuts");
241 fdNdEtaCorrectionFinal->SaveHistograms();
246 fdNdEtaCorrectionFinal->DrawHistograms();