79ab56b9 |
1 | #include "AlidNdEtaCorrectionSelector.h" |
539b6cb4 |
2 | |
3 | #include <TStyle.h> |
4 | #include <TSystem.h> |
5 | #include <TCanvas.h> |
6 | #include <TParticle.h> |
7 | #include <TParticlePDG.h> |
8 | |
9 | #include <AliLog.h> |
79ab56b9 |
10 | #include <AliGenEventHeader.h> |
539b6cb4 |
11 | #include <AliTracker.h> |
12 | |
79ab56b9 |
13 | #include "../esdTrackCuts/AliESDtrackCuts.h" |
14 | #include "dNdEtaCorrection.h" |
539b6cb4 |
15 | |
79ab56b9 |
16 | ClassImp(AlidNdEtaCorrectionSelector) |
539b6cb4 |
17 | |
79ab56b9 |
18 | AlidNdEtaCorrectionSelector::AlidNdEtaCorrectionSelector(TTree *) : |
539b6cb4 |
19 | AliSelector(), |
20 | fEsdTrackCuts(0), |
21 | fdNdEtaCorrection(0) |
22 | { |
79ab56b9 |
23 | // |
539b6cb4 |
24 | // Constructor. Initialization of pointers |
79ab56b9 |
25 | // |
539b6cb4 |
26 | } |
27 | |
79ab56b9 |
28 | AlidNdEtaCorrectionSelector::~AlidNdEtaCorrectionSelector() |
539b6cb4 |
29 | { |
79ab56b9 |
30 | // |
31 | // Destructor |
32 | // |
539b6cb4 |
33 | |
34 | // histograms are in the output list and deleted when the output |
35 | // list is deleted by the TSelector dtor |
36 | } |
37 | |
79ab56b9 |
38 | void AlidNdEtaCorrectionSelector::Begin(TTree * tree) |
539b6cb4 |
39 | { |
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). |
43 | |
44 | AliSelector::Begin(tree); |
539b6cb4 |
45 | } |
46 | |
79ab56b9 |
47 | void AlidNdEtaCorrectionSelector::SlaveBegin(TTree * tree) |
539b6cb4 |
48 | { |
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). |
52 | |
53 | AliSelector::SlaveBegin(tree); |
54 | |
79ab56b9 |
55 | fdNdEtaCorrection = new dNdEtaCorrection(); |
539b6cb4 |
56 | |
79ab56b9 |
57 | if (fChain) |
58 | fEsdTrackCuts = dynamic_cast<AliESDtrackCuts*> (fChain->GetUserInfo()->FindObject("AliESDtrackCuts")); |
539b6cb4 |
59 | |
79ab56b9 |
60 | if (!fEsdTrackCuts) |
61 | printf("ERROR: Could not read EsdTrackCuts from user info\n"); |
539b6cb4 |
62 | |
63 | AliLog::SetClassDebugLevel("ESDtrackQualityCuts",1); |
64 | } |
65 | |
79ab56b9 |
66 | Bool_t AlidNdEtaCorrectionSelector::Notify() |
539b6cb4 |
67 | { |
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 |
73 | // user if needed. |
74 | |
75 | if (AliSelector::Notify() == kFALSE) |
76 | return kFALSE; |
77 | |
539b6cb4 |
78 | return kTRUE; |
79 | } |
80 | |
79ab56b9 |
81 | Bool_t AlidNdEtaCorrectionSelector::IsPrimary(const TParticle* aParticle, Int_t aTotalPrimaries) |
539b6cb4 |
82 | { |
79ab56b9 |
83 | // |
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 |
86 | // |
87 | |
539b6cb4 |
88 | // if the particle has a daughter primary, we do not want to count it |
89 | if (aParticle->GetFirstDaughter() != -1 && aParticle->GetFirstDaughter() < aTotalPrimaries) |
90 | return kFALSE; |
91 | |
92 | Int_t pdgCode = TMath::Abs(aParticle->GetPdgCode()); |
93 | |
94 | // skip quarks and gluon |
95 | if (pdgCode > 10 && pdgCode != 21) |
96 | return kTRUE; |
97 | |
98 | return kFALSE; |
99 | } |
100 | |
79ab56b9 |
101 | Bool_t AlidNdEtaCorrectionSelector::Process(Long64_t entry) |
539b6cb4 |
102 | { |
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. |
110 | // |
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. |
114 | |
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). |
120 | |
121 | if (AliSelector::Process(entry) == kFALSE) |
122 | return kFALSE; |
123 | |
124 | if (!fESD || !fHeader) |
125 | return kFALSE; |
126 | |
127 | // ######################################################## |
128 | // get the EDS vertex |
129 | const AliESDVertex* vtxESD = fESD->GetVertex(); |
130 | |
79ab56b9 |
131 | // the vertex should be reconstructed |
132 | if (strcmp(vtxESD->GetName(),"default")==0) |
133 | return kTRUE; |
539b6cb4 |
134 | |
79ab56b9 |
135 | Double_t vtx_res[3]; |
539b6cb4 |
136 | vtx_res[0] = vtxESD->GetXRes(); |
137 | vtx_res[1] = vtxESD->GetYRes(); |
138 | vtx_res[2] = vtxESD->GetZRes(); |
139 | |
539b6cb4 |
140 | // the resolution should be reasonable??? |
141 | if (vtx_res[2]==0 || vtx_res[2]>0.1) |
142 | return kTRUE; |
143 | |
144 | // ######################################################## |
145 | // get the MC vertex |
79ab56b9 |
146 | AliGenEventHeader* genHeader = fHeader->GenEventHeader(); |
539b6cb4 |
147 | |
148 | TArrayF vtxMC(3); |
149 | genHeader->PrimaryVertex(vtxMC); |
539b6cb4 |
150 | |
151 | // ######################################################## |
152 | // loop over mc particles |
153 | TTree* particleTree = GetKinematics(); |
154 | TParticle* particle = 0; |
155 | particleTree->SetBranchAddress("Particles", &particle); |
156 | |
157 | Int_t nPrim = fHeader->GetNprimary(); |
158 | Int_t nTotal = fHeader->GetNtrack(); |
159 | |
160 | for (Int_t i_mc = nTotal - nPrim; i_mc < nTotal; ++i_mc) |
161 | { |
162 | particleTree->GetEntry(i_mc); |
163 | |
164 | if (!particle) |
165 | continue; |
166 | |
167 | if (strcmp(particle->GetName(),"XXX") == 0) |
168 | { |
169 | printf("WARNING: There is a particle named XXX (%d).\n", i_mc); |
170 | continue; |
171 | } |
172 | |
173 | TParticlePDG* pdgPart = particle->GetPDG(); |
174 | |
175 | if (strcmp(pdgPart->ParticleClass(),"Unknown") == 0) |
176 | { |
177 | printf("WARNING: There is a particle with an unknown particle class (%d pdg code %d).\n", i_mc, particle->GetPdgCode()); |
178 | continue; |
179 | } |
180 | |
181 | if (IsPrimary(particle, nPrim) == kFALSE) |
182 | continue; |
183 | |
184 | if (pdgPart->Charge() == 0) |
185 | continue; |
186 | |
79ab56b9 |
187 | fdNdEtaCorrection->FillGene(vtxMC[2], particle->Eta()); |
539b6cb4 |
188 | |
189 | }// end of mc particle |
190 | |
191 | // ######################################################## |
192 | // loop over esd tracks |
193 | Int_t nTracks = fESD->GetNumberOfTracks(); |
194 | for (Int_t t=0; t<nTracks; t++) |
195 | { |
196 | AliESDtrack* esdTrack = fESD->GetTrack(t); |
197 | |
198 | // cut the esd track? |
199 | if (!fEsdTrackCuts->AcceptTrack(esdTrack)) |
200 | continue; |
201 | |
539b6cb4 |
202 | // using the eta of the mc particle |
203 | Int_t label = TMath::Abs(esdTrack->GetLabel()); |
79ab56b9 |
204 | if (label == 0) |
539b6cb4 |
205 | { |
79ab56b9 |
206 | printf("WARNING: cannot find corresponding mc part for track %d.", t); |
539b6cb4 |
207 | continue; |
208 | } |
209 | particleTree->GetEntry(nTotal - nPrim + label); |
210 | |
79ab56b9 |
211 | fdNdEtaCorrection->FillMeas(vtxMC[2], particle->Eta()); |
539b6cb4 |
212 | |
213 | } // end of track loop |
214 | |
215 | return kTRUE; |
216 | } |
217 | |
79ab56b9 |
218 | void AlidNdEtaCorrectionSelector::SlaveTerminate() |
539b6cb4 |
219 | { |
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. |
223 | |
224 | AliSelector::SlaveTerminate(); |
225 | |
226 | // Add the histograms to the output on each slave server |
227 | if (!fOutput) |
228 | { |
229 | printf("ERROR: Output list not initialized\n"); |
230 | return; |
231 | } |
79ab56b9 |
232 | |
233 | fOutput->Add(fdNdEtaCorrection->GetGeneratedHistogram()); |
234 | fOutput->Add(fdNdEtaCorrection->GetMeasuredHistogram()); |
539b6cb4 |
235 | } |
236 | |
79ab56b9 |
237 | void AlidNdEtaCorrectionSelector::Terminate() |
539b6cb4 |
238 | { |
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. |
242 | |
243 | AliSelector::Terminate(); |
244 | |
79ab56b9 |
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) |
249 | { |
250 | printf("ERROR: Histograms not available %p %p\n", (void*) generatedHistogram, (void*) measuredHistogram); |
251 | return; |
252 | } |
253 | fdNdEtaCorrectionFinal->SetGeneratedHistogram(generatedHistogram); |
254 | fdNdEtaCorrectionFinal->SetMeasuredHistogram(measuredHistogram); |
255 | |
256 | fdNdEtaCorrectionFinal->Finish(); |
539b6cb4 |
257 | |
258 | TFile* fout = new TFile("correction_map.root","RECREATE"); |
259 | |
260 | fEsdTrackCuts->SaveHistograms("esd_track_cuts"); |
79ab56b9 |
261 | fdNdEtaCorrectionFinal->SaveHistograms(); |
539b6cb4 |
262 | |
263 | fout->Write(); |
264 | fout->Close(); |
265 | |
79ab56b9 |
266 | fdNdEtaCorrectionFinal->DrawHistograms(); |
539b6cb4 |
267 | } |