]>
Commit | Line | Data |
---|---|---|
5a5a1232 | 1 | // $Header$ |
2 | ||
3 | #include "VSDCreator.h" | |
4 | ||
84aff7a4 | 5 | #include <TEveTreeTools.h> |
5a5a1232 | 6 | |
7 | #include <AliStack.h> | |
8 | #include <AliITSLoader.h> | |
9 | #include <AliTPCTrackHitsV2.h> | |
10 | #include <AliPDG.h> | |
11 | #include <AliHit.h> | |
12 | #include <AliSimDigits.h> | |
13 | #include <AliKalmanTrack.h> | |
22aefef8 | 14 | #include <AliESDEvent.h> |
d6a49f20 | 15 | #include <AliESDv0.h> |
5a5a1232 | 16 | #include <AliTPCclusterMI.h> |
17 | #include <AliTPCClustersRow.h> | |
18 | #include <AliITS.h> | |
19 | #include <AliITSclusterV2.h> | |
20 | #include <AliTrackReference.h> | |
21 | #include <AliESDkink.h> | |
82e1eece | 22 | #include <AliESDtrack.h> |
5a5a1232 | 23 | |
24 | #include <AliRun.h> | |
25 | #include <AliTPCParam.h> | |
26 | ||
27 | #include <TSystem.h> | |
28 | #include <TFile.h> | |
84aff7a4 | 29 | #include <TError.h> |
5a5a1232 | 30 | |
5a5a1232 | 31 | using namespace Alieve; |
32 | ||
33 | using namespace std; | |
34 | ||
35 | //______________________________________________________________________ | |
36 | // VSDCreator | |
37 | // | |
38 | ||
39 | ClassImp(VSDCreator) | |
40 | ||
265ecb21 | 41 | VSDCreator::VSDCreator(const Text_t* name, const Text_t* title) : |
84aff7a4 | 42 | TEveVSD(name, title), |
265ecb21 | 43 | |
44 | mKineType (KT_Standard), | |
45 | mDataDir ("."), | |
46 | mEvent (0), | |
5a5a1232 | 47 | |
265ecb21 | 48 | mTPCHitRes (2), |
49 | mTRDHitRes (2), | |
5a5a1232 | 50 | |
265ecb21 | 51 | mDebugLevel (0), |
52 | mGenInfoMap (), | |
5a5a1232 | 53 | |
265ecb21 | 54 | pRunLoader (0) |
55 | { | |
5a5a1232 | 56 | // Particles not in ROOT's PDG database occuring in ALICE |
57 | AliPDG::AddParticlesToPdgDataBase(); | |
58 | { | |
59 | TDatabasePDG *pdgDB = TDatabasePDG::Instance(); | |
60 | // const Int_t kspe=50000000; | |
61 | const Int_t kion=10000000; | |
62 | ||
63 | const Double_t kAu2Gev=0.9314943228; | |
64 | const Double_t khSlash = 1.0545726663e-27; | |
65 | const Double_t kErg2Gev = 1/1.6021773349e-3; | |
66 | const Double_t khShGev = khSlash*kErg2Gev; | |
67 | const Double_t kYear2Sec = 3600*24*365.25; | |
68 | ||
69 | pdgDB->AddParticle("Deuteron","Deuteron",2*kAu2Gev+8.071e-3,kTRUE, | |
70 | 0,1,"Ion",kion+10020); | |
71 | pdgDB->AddParticle("Triton","Triton",3*kAu2Gev+14.931e-3,kFALSE, | |
72 | khShGev/(12.33*kYear2Sec),1,"Ion",kion+10030); | |
73 | pdgDB->AddParticle("Alpha","Alpha",4*kAu2Gev+2.424e-3,kTRUE, | |
74 | khShGev/(12.33*kYear2Sec),2,"Ion",kion+20040); | |
75 | pdgDB->AddParticle("HE3","HE3",3*kAu2Gev+14.931e-3,kFALSE, | |
76 | 0,2,"Ion",kion+20030); | |
77 | } | |
78 | ||
79 | // AliKalmanTrack::SetConvConst(1); | |
80 | } | |
81 | ||
5a5a1232 | 82 | /**************************************************************************/ |
83 | ||
84 | void VSDCreator::CreateVSD(const Text_t* data_dir, Int_t event, | |
85 | const Text_t* vsd_file) | |
86 | { | |
84aff7a4 | 87 | static const TEveException eH("VSDCreator::CreateVSD "); |
5a5a1232 | 88 | |
89 | mDataDir = data_dir; | |
90 | mEvent = event; | |
91 | ||
92 | string galice_file (Form("%s/galice.root", mDataDir.Data())); | |
93 | ||
94 | if(mDebugLevel > 0) | |
95 | printf("%s opening %s \n", eH.Data(), galice_file.c_str()); | |
96 | ||
97 | if(gSystem->AccessPathName(galice_file.c_str(), kReadPermission)) { | |
98 | throw(eH + "Can not read file '" + galice_file + "'."); | |
99 | } | |
100 | pRunLoader = AliRunLoader::Open(galice_file.c_str()); | |
101 | if(pRunLoader == 0) | |
102 | throw(eH + "AliRunLoader::Open failed."); | |
103 | ||
104 | pRunLoader->LoadgAlice(); | |
105 | Int_t status = pRunLoader->GetEvent(mEvent); | |
106 | if(status) | |
107 | throw(eH + Form("GetEvent(%d) failed, exit code %s.", mEvent, status)); | |
108 | ||
109 | if(mDebugLevel > 0) | |
110 | printf("%s open seems ok. Now loading sim data.\n", eH.Data()); | |
111 | ||
112 | pRunLoader->LoadHeader(); | |
113 | pRunLoader->LoadKinematics(); | |
114 | pRunLoader->LoadTrackRefs(); | |
115 | pRunLoader->LoadHits(); | |
116 | ||
117 | // GledNS::PushFD(); | |
118 | ||
119 | if(mDebugLevel > 0) | |
84aff7a4 | 120 | printf("%s opening output TEveVSD.\n", eH.Data()); |
5a5a1232 | 121 | |
122 | TFile* file = TFile::Open(vsd_file, "RECREATE", "ALICE VisualizationDataSummary"); | |
84aff7a4 | 123 | fDirectory = new TDirectoryFile("Event0", ""); |
5a5a1232 | 124 | |
125 | if(mDebugLevel > 0) | |
126 | printf("%s creating trees now ...\n", eH.Data()); | |
127 | ||
128 | CreateTrees(); | |
129 | ||
130 | if(mDebugLevel > 0) | |
131 | printf("%s trees created, closing files.\n", eH.Data()); | |
132 | ||
c1d0d915 | 133 | file->Write(); |
5a5a1232 | 134 | file->Close(); |
135 | delete file; | |
84aff7a4 | 136 | fDirectory =0; |
5a5a1232 | 137 | |
138 | //GledNS::PopFD(); | |
139 | ||
84aff7a4 | 140 | // clean after the TEveVSD data was sucessfuly written |
141 | fTreeK = 0; | |
142 | fTreeH = 0; | |
143 | //fTreeTR = 0; | |
144 | fTreeC = 0; | |
145 | fTreeV0 = 0; | |
146 | fTreeKK = 0; | |
147 | fTreeR = 0; | |
148 | fTreeGI = 0; | |
5a5a1232 | 149 | |
150 | pRunLoader->UnloadAll(); | |
151 | delete pRunLoader; | |
152 | if(gAlice) { | |
153 | delete gAlice; gAlice = 0; | |
154 | } | |
155 | pRunLoader = 0; | |
156 | ||
157 | if(mDebugLevel > 0) | |
158 | printf("%s all done.\n", eH.Data()); | |
159 | } | |
160 | ||
161 | void VSDCreator::CreateTrees() | |
162 | { | |
84aff7a4 | 163 | static const TEveException eH("VSDCreator::CreateTrees "); |
5a5a1232 | 164 | |
84aff7a4 | 165 | if(fDirectory == 0) |
5a5a1232 | 166 | throw(eH + "output directory not set."); |
167 | ||
168 | try { | |
169 | if(mDebugLevel > 1) | |
7816f7cf | 170 | printf("%sConvertKinematics.\n", eH.Data()); |
5a5a1232 | 171 | ConvertKinematics(); |
84aff7a4 | 172 | } catch(TEveException& exc) { Warning(eH, exc); } |
5a5a1232 | 173 | |
174 | try { | |
175 | if(mDebugLevel > 1) | |
7816f7cf | 176 | printf("%sConvertHits.\n", eH.Data()); |
5a5a1232 | 177 | ConvertHits(); |
84aff7a4 | 178 | } catch(TEveException& exc) { Warning(eH, exc); } |
5a5a1232 | 179 | |
180 | try { | |
181 | if(mDebugLevel > 1) | |
7816f7cf | 182 | printf("%sConvertClusters.\n", eH.Data()); |
5a5a1232 | 183 | ConvertClusters(); |
84aff7a4 | 184 | } catch(TEveException& exc) { Warning(eH, exc); } |
5a5a1232 | 185 | |
5a5a1232 | 186 | try { |
187 | if(mDebugLevel > 1) | |
7816f7cf | 188 | printf("%sConvertRecTracks.\n", eH.Data()); |
5a5a1232 | 189 | ConvertRecTracks(); |
84aff7a4 | 190 | } catch(TEveException& exc) { |
191 | Warning(exc, "skipping V0 extraction."); | |
5a5a1232 | 192 | goto end_esd_processing; |
193 | } | |
194 | ||
195 | try { | |
196 | if(mDebugLevel > 1) | |
7816f7cf | 197 | printf("%sConvertV0.\n", eH.Data()); |
5a5a1232 | 198 | ConvertV0(); |
84aff7a4 | 199 | } catch(TEveException& exc) { Warning(eH, exc); } |
5a5a1232 | 200 | |
201 | try { | |
202 | if(mDebugLevel > 1) | |
7816f7cf | 203 | printf("%sConvertKinks.\n", eH.Data()); |
5a5a1232 | 204 | ConvertKinks(); |
84aff7a4 | 205 | } catch(TEveException& exc) { Warning(eH, exc); } |
5a5a1232 | 206 | |
207 | end_esd_processing: | |
208 | ||
209 | try { | |
210 | if(mDebugLevel > 1) | |
7816f7cf | 211 | printf("%sConvertGenInfo.\n", eH.Data()); |
5a5a1232 | 212 | ConvertGenInfo(); |
84aff7a4 | 213 | } catch(TEveException& exc) { Warning(eH, exc); } |
5a5a1232 | 214 | |
5a5a1232 | 215 | return; |
216 | } | |
217 | ||
218 | /**************************************************************************/ | |
219 | // Kinematics | |
220 | /**************************************************************************/ | |
221 | ||
222 | void VSDCreator::ConvertKinematics() | |
223 | { | |
84aff7a4 | 224 | static const TEveException eH("VSDCreator::ConvertKinematics "); |
5a5a1232 | 225 | |
84aff7a4 | 226 | if(fTreeK != 0) |
5a5a1232 | 227 | throw (eH + "kinematics already converted"); |
228 | ||
229 | AliStack* stack = pRunLoader->Stack(); | |
230 | if(stack == 0) | |
231 | throw(eH + "stack is null."); | |
232 | ||
84aff7a4 | 233 | fDirectory->cd(); |
234 | fTreeK = new TTree("Kinematics", "TParticles sorted by Label"); | |
5a5a1232 | 235 | |
236 | Int_t nentries = stack->GetNtrack(); | |
84aff7a4 | 237 | vector<TEveMCTrack> vmc(nentries); |
5a5a1232 | 238 | for (Int_t idx=0; idx<nentries; idx++) { |
239 | TParticle* tp = stack->Particle(idx); | |
84aff7a4 | 240 | vmc[idx] = *tp; |
241 | vmc[idx].fLabel = idx; | |
5a5a1232 | 242 | } |
243 | ||
84aff7a4 | 244 | // read track refrences |
245 | // functionality now in KineTools. | |
246 | /* | |
247 | TTree* fTreeTR = pRunLoader->TreeTR(); | |
5a5a1232 | 248 | |
84aff7a4 | 249 | if(fTreeTR == 0) { |
250 | Warning(eH, "no TrackRefs; some data will not be available."); | |
5a5a1232 | 251 | } else { |
252 | TClonesArray* RunArrayTR = 0; | |
84aff7a4 | 253 | fTreeTR->SetBranchAddress("AliRun", &RunArrayTR); |
5a5a1232 | 254 | |
84aff7a4 | 255 | Int_t nPrimaries = (Int_t) fTreeTR->GetEntries(); |
5a5a1232 | 256 | for (Int_t iPrimPart = 0; iPrimPart<nPrimaries; iPrimPart++) { |
84aff7a4 | 257 | // printf("T0 fTreeTR->GetEntry(%d) \n",iPrimPart); |
258 | fTreeTR->GetEntry(iPrimPart); | |
259 | // printf("END fTreeTR->GetEntry(%d) \n",iPrimPart); | |
5a5a1232 | 260 | |
261 | for (Int_t iTrackRef = 0; iTrackRef < RunArrayTR->GetEntriesFast(); iTrackRef++) { | |
262 | AliTrackReference *trackRef = (AliTrackReference*)RunArrayTR->At(iTrackRef); | |
263 | Int_t track = trackRef->GetTrack(); | |
264 | if(track < nentries && track > 0){ | |
84aff7a4 | 265 | TEveMCTrack& mct = vmc[track]; |
5a5a1232 | 266 | if(trackRef->TestBit(kNotDeleted)) { |
267 | mct.decayed = true; | |
268 | mct.t_decay = trackRef->GetTime(); | |
269 | mct.V_decay.x = trackRef->X(); | |
270 | mct.V_decay.y = trackRef->Y(); | |
271 | mct.V_decay.z = trackRef->Z(); | |
272 | mct.P_decay.x = trackRef->Px(); | |
273 | mct.P_decay.y = trackRef->Py(); | |
274 | mct.P_decay.z = trackRef->Pz(); | |
275 | if(TMath::Abs(mct.GetPdgCode()) == 11) | |
276 | mct.decayed = false; // a bug in TreeTR | |
277 | } | |
278 | } | |
279 | } | |
280 | } | |
281 | } | |
84aff7a4 | 282 | */ |
5a5a1232 | 283 | |
84aff7a4 | 284 | fTreeK->Branch("K", "TEveMCTrack", &fpK, fBuffSize); |
5a5a1232 | 285 | |
286 | printf("sizeofvmc = %d\n", vmc.size()); | |
84aff7a4 | 287 | for(vector<TEveMCTrack>::iterator k=vmc.begin(); k!=vmc.end(); ++k) { |
288 | TEveMCTrack& mct = *k; | |
289 | fK = mct; | |
5a5a1232 | 290 | |
291 | TParticle* m = &mct; | |
84aff7a4 | 292 | Int_t mi = mct.fLabel; |
5a5a1232 | 293 | int cnt = 0; |
294 | while(m->GetMother(0) != -1) { | |
295 | if(cnt > 100) { | |
296 | printf("cnt %d mi=%d, mo=%d\n", cnt, mi, m->GetMother(0)); | |
297 | } | |
298 | mi = m->GetMother(0); | |
299 | m = &vmc[mi]; | |
300 | ++cnt; | |
301 | } | |
84aff7a4 | 302 | fK.fEvaLabel = mi; |
5a5a1232 | 303 | |
84aff7a4 | 304 | fTreeK->Fill(); |
5a5a1232 | 305 | } |
306 | ||
84aff7a4 | 307 | fTreeK->BuildIndex("label"); |
5a5a1232 | 308 | } |
309 | ||
310 | /**************************************************************************/ | |
311 | // Hits | |
312 | /**************************************************************************/ | |
313 | ||
314 | namespace { | |
315 | ||
316 | struct Detector | |
317 | { | |
318 | const char* name; | |
319 | const char* hitbranch; | |
320 | unsigned char detidx; | |
321 | }; | |
322 | ||
323 | Detector detects[] = { | |
324 | { "ITS", "AliITShit", 0 }, | |
325 | { "TPC", "AliTPCTrackHitsV2", 1 }, | |
326 | { "TRD", "AliTRDhit", 2 }, | |
327 | { "TOF", "AliTOFhit", 3 } | |
f4b3bbb7 | 328 | // { "HMPID", "AliHMPIDhit", 4 }, |
5a5a1232 | 329 | }; |
330 | ||
331 | } | |
332 | ||
333 | /**************************************************************************/ | |
334 | ||
335 | void VSDCreator::ConvertHits() | |
336 | { | |
84aff7a4 | 337 | static const TEveException eH("VSDCreator::ConvertHits "); |
5a5a1232 | 338 | |
84aff7a4 | 339 | if(fTreeH != 0) |
5a5a1232 | 340 | throw(eH + "hits already converted."); |
341 | ||
84aff7a4 | 342 | fDirectory->cd(); |
343 | fTreeH = new TTree("Hits", "Combined detector hits."); | |
344 | fTreeH->Branch("H", "TEveHit", &fpH, fBuffSize); | |
5a5a1232 | 345 | |
346 | map<Int_t, Int_t> hmap; | |
347 | // parameters for ITS, TPC hits filtering | |
348 | Float_t x,y,z, x1,y1,z1; | |
349 | Float_t tpc_sqr_res = mTPCHitRes*mTPCHitRes; | |
350 | Float_t trd_sqr_res = mTRDHitRes*mTRDHitRes; | |
351 | ||
352 | int l=0; | |
353 | // load hits from the rest of detectors | |
354 | while(detects[l].name != 0) { | |
355 | Detector& det = detects[l++]; | |
356 | ||
357 | switch(det.detidx) { | |
358 | case 1: { | |
359 | Int_t count = 0; | |
360 | TTree* treeh = pRunLoader->GetTreeH(det.name, false); | |
361 | if(treeh == 0) { | |
84aff7a4 | 362 | Warning(eH, Form("no hits for %s.", det.name)); |
5a5a1232 | 363 | continue; |
364 | } | |
365 | AliTPCTrackHitsV2 hv2, *_hv2=&hv2; | |
366 | treeh->SetBranchAddress("TPC2", &_hv2); | |
367 | Int_t np = treeh->GetEntries(); | |
368 | for(Int_t i=0; i<np; i++){ | |
369 | treeh->GetEntry(i); | |
370 | Int_t eva_idx = np -i -1; | |
371 | if (hv2.First() == 0) continue; | |
372 | x = y = z = 0; | |
373 | do { | |
374 | AliHit* ah = hv2.GetHit(); | |
84aff7a4 | 375 | x1 = ah->X(); y1 = ah->Y(); z1 = ah->Z(); |
376 | if ((x-x1)*(x-x1) + (y-y1)*(y-y1) + (z-z1)*(z-z1) > tpc_sqr_res) | |
377 | { | |
378 | fH.fDetId = det.detidx; | |
379 | fH.fSubdetId = 0; | |
380 | fH.fLabel = ah->Track(); | |
381 | fH.fEvaLabel = eva_idx; | |
382 | fH.fV.fX = x1; fH.fV.fY = y1; fH.fV.fZ = z1; | |
383 | fTreeH->Fill(); | |
384 | hmap[fH.fLabel]++; | |
5a5a1232 | 385 | x = x1; y = y1; z = z1; |
386 | count++; | |
387 | } | |
388 | } while (hv2.Next()); | |
389 | } | |
390 | // printf("%d entries in TPChits \n",count); | |
391 | break; | |
392 | } | |
393 | default: { | |
394 | TTree* treeh = pRunLoader->GetTreeH(det.name, false); | |
395 | if(treeh == 0) { | |
84aff7a4 | 396 | Warning(eH, Form("no hits for %s.", det.name)); |
5a5a1232 | 397 | continue; |
398 | } | |
399 | TClonesArray *arr = new TClonesArray(det.hitbranch); | |
400 | treeh->SetBranchAddress(det.name, &arr); | |
401 | Int_t np = treeh->GetEntries(); | |
402 | // in TreeH files hits are grouped in clones arrays | |
403 | // each eva particle has its own clone array | |
404 | for (Int_t i=0; i<np; i++) { | |
405 | treeh->GetEntry(i); | |
406 | Int_t eva_idx = np -i -1; | |
407 | Int_t nh=arr->GetEntriesFast(); | |
408 | x = y = z = 0; | |
409 | // printf("%d entry %d hits for primary %d \n", i, nh, eva_idx); | |
410 | for (Int_t j=0; j<nh; j++) { | |
411 | AliHit* ali_hit = (AliHit*)arr->UncheckedAt(j); | |
84aff7a4 | 412 | fH.fDetId = det.detidx; |
413 | fH.fSubdetId = 0; | |
414 | fH.fLabel = ali_hit->GetTrack(); | |
415 | fH.fEvaLabel = eva_idx; | |
416 | fH.fV.Set(ali_hit->X(), ali_hit->Y(), ali_hit->Z()); | |
5a5a1232 | 417 | if(det.detidx == 2) { |
418 | x1=ali_hit->X();y1=ali_hit->Y();z1=ali_hit->Z(); | |
419 | if((x-x1)*(x-x1)+(y-y1)*(y-y1)+(z-z1)*(z-z1) < trd_sqr_res) continue; | |
420 | x=x1; y=y1; z=z1; | |
421 | } | |
84aff7a4 | 422 | hmap[fH.fLabel]++; |
423 | fTreeH->Fill(); | |
5a5a1232 | 424 | } |
425 | } | |
426 | delete arr; | |
427 | break; | |
428 | } // end default | |
429 | } // end switch | |
430 | } // end while | |
431 | ||
432 | ||
433 | //set geninfo | |
434 | for(map<Int_t, Int_t>::iterator j=hmap.begin(); j!=hmap.end(); ++j) { | |
84aff7a4 | 435 | GetGeninfo(j->first)->fNHits += j->second; |
5a5a1232 | 436 | } |
5a5a1232 | 437 | } |
438 | ||
439 | /**************************************************************************/ | |
440 | // Clusters | |
441 | /**************************************************************************/ | |
442 | ||
443 | void VSDCreator::ConvertClusters() | |
444 | { | |
84aff7a4 | 445 | static const TEveException eH("VSDCreator::ConvertClusters "); |
5a5a1232 | 446 | |
84aff7a4 | 447 | if(fTreeC != 0) |
5a5a1232 | 448 | throw(eH + "clusters already converted."); |
449 | ||
84aff7a4 | 450 | fDirectory->cd(); |
451 | fTreeC = new TTree("Clusters", "rec clusters"); | |
452 | fTreeC->Branch("C", "TEveCluster", &fpC, fBuffSize); | |
5a5a1232 | 453 | |
454 | try { | |
455 | ConvertITSClusters(); | |
84aff7a4 | 456 | } catch(TEveException& exc) { Warning(eH, exc); } |
5a5a1232 | 457 | |
458 | try { | |
459 | ConvertTPCClusters(); | |
84aff7a4 | 460 | } catch(TEveException& exc) { Warning(eH, exc); } |
5a5a1232 | 461 | } |
462 | ||
463 | /**************************************************************************/ | |
464 | ||
465 | void VSDCreator::ConvertTPCClusters() | |
466 | { | |
84aff7a4 | 467 | static const TEveException eH("VSDCreator::ConvertTPCClusters "); |
5a5a1232 | 468 | |
469 | auto_ptr<TFile> f | |
470 | ( TFile::Open(Form("%s/TPC.RecPoints.root", mDataDir.Data())) ); | |
471 | if(!f.get()) | |
472 | throw(eH + "can not open 'TPC.RecPoints.root' file."); | |
473 | ||
474 | auto_ptr<TDirectory> d | |
475 | ( (TDirectory*) f->Get(Form("Event%d", mEvent)) ); | |
476 | if(!d.get()) | |
477 | throw(eH + Form("event directory '%d' not found.", 0)); | |
478 | ||
479 | auto_ptr<TTree> tree( (TTree*) d->Get("TreeR") ); | |
480 | if(!tree.get()) | |
481 | throw(eH + "'TreeR' not found."); | |
482 | ||
483 | auto_ptr<AliTPCParam> par( GetTpcParam(eH) ); | |
484 | ||
485 | AliTPCClustersRow clrow, *_clrow=&clrow; | |
486 | AliTPCclusterMI *cl; | |
487 | _clrow->SetClass("AliTPCclusterMI"); | |
488 | tree->SetBranchAddress("Segment", &_clrow); | |
489 | ||
490 | // count clusters | |
491 | Int_t nClusters = 0; | |
492 | Int_t n_ent = tree->GetEntries(); | |
493 | for (Int_t n=0; n<n_ent; n++) { | |
494 | tree->GetEntry(n); | |
495 | nClusters += _clrow->GetArray()->GetEntriesFast(); | |
496 | } | |
497 | ||
498 | // calculate xyz for a cluster and add it to container | |
499 | Double_t x,y,z; | |
500 | Float_t cs, sn, tmp; | |
501 | map<Int_t, Int_t> cmap; | |
502 | ||
503 | for (Int_t n=0; n<tree->GetEntries(); n++) { | |
504 | tree->GetEntry(n); | |
505 | Int_t ncl = _clrow->GetArray()->GetEntriesFast(); | |
506 | if(ncl > 0) { | |
507 | Int_t sec,row; | |
508 | par->AdjustSectorRow(_clrow->GetID(),sec,row); | |
509 | while (ncl--) { | |
510 | if(_clrow->GetArray()) { | |
511 | // cl = new AliTPCclusterMI(*(AliTPCclusterMI*)_clrow->GetArray()->UncheckedAt(ncl)); | |
512 | cl = (AliTPCclusterMI*)_clrow->GetArray()->UncheckedAt(ncl); | |
84aff7a4 | 513 | if(cl->GetLabel(0) >= 0) |
514 | { | |
5a5a1232 | 515 | x = par->GetPadRowRadii(sec,row); y = cl->GetY(); z = cl->GetZ(); |
516 | par->AdjustCosSin(sec,cs,sn); | |
517 | tmp = x*cs-y*sn; y= x*sn+y*cs; x=tmp; | |
518 | ||
84aff7a4 | 519 | fC.fDetId = 1; |
520 | fC.fSubdetId = 0; | |
521 | fC.fLabel[0] = cl->GetLabel(0); | |
522 | fC.fLabel[1] = cl->GetLabel(1); | |
523 | fC.fLabel[2] = cl->GetLabel(2); | |
524 | fC.fV.Set(x, y, z); | |
525 | ||
526 | fTreeC->Fill(); | |
527 | { | |
528 | int i = 0; | |
529 | while(i < 3 && fC.fLabel[i]) | |
530 | cmap[fC.fLabel[i++]]++; | |
5a5a1232 | 531 | } |
532 | } | |
533 | } | |
534 | } | |
535 | } | |
536 | } | |
537 | //set geninfo | |
538 | for(map<Int_t, Int_t>::iterator j=cmap.begin(); j!=cmap.end(); ++j) { | |
84aff7a4 | 539 | GetGeninfo(j->first)->fNClus += j->second; |
5a5a1232 | 540 | } |
541 | } | |
542 | ||
543 | /**************************************************************************/ | |
544 | ||
545 | void VSDCreator::ConvertITSClusters() | |
546 | { | |
84aff7a4 | 547 | static const TEveException eH("VSDCreator::ConvertITSClusters "); |
5a5a1232 | 548 | |
549 | auto_ptr<TFile> f | |
550 | ( TFile::Open(Form("%s/ITS.RecPoints.root", mDataDir.Data())) ); | |
551 | if(!f.get()) | |
552 | throw(eH + "can not open 'ITS.RecPoints.root' file."); | |
553 | ||
554 | auto_ptr<TDirectory> d | |
555 | ( (TDirectory*) f->Get(Form("Event%d", mEvent)) ); | |
556 | if(!d.get()) | |
557 | throw(eH + Form("event directory '%d' not found.", 0)); | |
558 | ||
559 | auto_ptr<TTree> tree( (TTree*) d->Get("TreeR") ); | |
560 | if(!tree.get()) | |
561 | throw(eH + "'TreeR' not found."); | |
562 | ||
563 | AliITSLoader* ITSld = (AliITSLoader*) pRunLoader->GetLoader("ITSLoader"); | |
564 | //AliITS* pITS = ITSld->GetITS(); | |
565 | AliITSgeom* geom = ITSld->GetITSgeom(); | |
566 | //AliITSgeom* geom = new AliITSgeom(); | |
567 | //geom->ReadNewFile("/home/aljam/ITSgeometry.det"); | |
568 | ||
569 | //printf("alice ITS geom %p \n",geom ); | |
570 | ||
571 | if(!geom) | |
572 | throw(eH + "can not find ITS geometry"); | |
573 | ||
574 | TClonesArray *arr = new TClonesArray("AliITSclusterV2"); | |
575 | tree->SetBranchAddress("Clusters", &arr); | |
576 | Int_t nmods = tree->GetEntries(); | |
577 | Float_t gc[3]; | |
578 | map<Int_t, Int_t> cmap; | |
579 | ||
580 | for (Int_t mod=0; mod<nmods; mod++) { | |
581 | tree->GetEntry(mod); | |
582 | Int_t nc=arr->GetEntriesFast(); | |
583 | for (Int_t j=0; j<nc; j++) { | |
584 | AliITSclusterV2* recp = (AliITSclusterV2*)arr->UncheckedAt(j); | |
585 | ||
586 | Double_t rot[9]; | |
587 | geom->GetRotMatrix(mod,rot); | |
588 | Int_t lay,lad,det; | |
589 | geom->GetModuleId(mod,lay,lad,det); | |
590 | Float_t tx,ty,tz; | |
591 | geom->GetTrans(lay,lad,det,tx,ty,tz); | |
592 | ||
593 | Double_t alpha=TMath::ATan2(rot[1],rot[0])+TMath::Pi(); | |
594 | Double_t phi1=TMath::Pi()/2+alpha; | |
595 | if(lay==1) phi1+=TMath::Pi(); | |
596 | ||
597 | Float_t cp=TMath::Cos(phi1), sp=TMath::Sin(phi1); | |
598 | Float_t r=tx*cp+ty*sp; | |
84aff7a4 | 599 | gc[0] = r*cp - recp->GetY()*sp; |
600 | gc[1] = r*sp + recp->GetY()*cp; | |
601 | gc[2] = recp->GetZ(); | |
602 | ||
603 | fC.fDetId = 0; | |
604 | fC.fSubdetId = 0; | |
605 | fC.fLabel[0] = recp->GetLabel(0); | |
606 | fC.fLabel[1] = recp->GetLabel(1); | |
607 | fC.fLabel[2] = recp->GetLabel(2); | |
608 | fC.fV.fX = r*cp - recp->GetY()*sp; | |
609 | fC.fV.fY = r*sp + recp->GetY()*cp; | |
610 | fC.fV.fZ = recp->GetZ(); | |
611 | fTreeC->Fill(); | |
5a5a1232 | 612 | { int i = 0; |
84aff7a4 | 613 | while(i < 3 && fC.fLabel[i]) |
614 | cmap[fC.fLabel[i++]]++; | |
5a5a1232 | 615 | } |
616 | } | |
617 | ||
618 | for(map<Int_t, Int_t>::iterator j=cmap.begin(); j!=cmap.end(); ++j) { | |
84aff7a4 | 619 | GetGeninfo(j->first)->fNClus += j->second; |
5a5a1232 | 620 | } |
621 | } | |
622 | delete arr; | |
623 | } | |
624 | ||
625 | /**************************************************************************/ | |
626 | // ESD | |
627 | /**************************************************************************/ | |
628 | ||
629 | void VSDCreator::ConvertRecTracks() | |
630 | { | |
84aff7a4 | 631 | static const TEveException eH("VSDCreator::ConvertRecTracks "); |
5a5a1232 | 632 | |
84aff7a4 | 633 | if(fTreeR != 0) |
5a5a1232 | 634 | throw(eH + "tracks already converted."); |
635 | ||
84aff7a4 | 636 | fDirectory->cd(); |
637 | fTreeR = new TTree("RecTracks", "rec tracks"); | |
5a5a1232 | 638 | |
84aff7a4 | 639 | fTreeR->Branch("R", "TEveRecTrack", &fpR, 512*1024,1); |
5a5a1232 | 640 | |
641 | TFile f(Form("%s/AliESDs.root", mDataDir.Data())); | |
642 | if(!f.IsOpen()) | |
643 | throw(eH + "no AliESDs.root file."); | |
644 | ||
645 | TTree* tree = (TTree*) f.Get("esdTree"); | |
646 | if (tree == 0) | |
647 | throw(eH + "no esdTree."); | |
648 | ||
649 | ||
22aefef8 | 650 | AliESDEvent *fEvent= new AliESDEvent(); |
651 | fEvent->ReadFromTree(tree); | |
5a5a1232 | 652 | tree->GetEntry(mEvent); |
22aefef8 | 653 | if(fEvent->GetAliESDOld())fEvent->CopyFromOldESD(); |
5a5a1232 | 654 | |
655 | ||
656 | // reconstructed tracks | |
657 | AliESDtrack* esd_t; | |
658 | Double_t dbuf[3]; | |
659 | for (Int_t n=0; n<fEvent->GetNumberOfTracks(); n++) { | |
660 | esd_t = fEvent->GetTrack(n); | |
661 | ||
84aff7a4 | 662 | fR.fLabel = esd_t->GetLabel(); |
663 | fR.fStatus = (Int_t) esd_t->GetStatus(); | |
664 | fR.fSign = (Int_t) esd_t->GetSign(); | |
665 | esd_t->GetXYZ(dbuf); fR.fV.Set(dbuf); | |
666 | esd_t->GetPxPyPz(dbuf); fR.fP.Set(dbuf); | |
5a5a1232 | 667 | Double_t ep = esd_t->GetP(); |
84aff7a4 | 668 | fR.fBeta = ep/TMath::Sqrt(ep*ep + TMath::C()*TMath::C()*esd_t->GetMass()*esd_t->GetMass()); |
669 | fTreeR->Fill(); | |
5a5a1232 | 670 | } |
84aff7a4 | 671 | fTreeR->BuildIndex("label"); |
22aefef8 | 672 | delete fEvent; |
5a5a1232 | 673 | } |
674 | ||
675 | /**************************************************************************/ | |
676 | ||
677 | void VSDCreator::ConvertV0() | |
678 | { | |
84aff7a4 | 679 | static const TEveException eH("VSDCreator::ConvertV0 "); |
5a5a1232 | 680 | |
84aff7a4 | 681 | if(fTreeV0 != 0) |
5a5a1232 | 682 | throw(eH + "V0 already converted."); |
683 | ||
84aff7a4 | 684 | fDirectory->cd(); |
685 | fTreeV0 = new TTree("V0", "V0 points"); | |
5a5a1232 | 686 | |
84aff7a4 | 687 | fTreeV0->Branch("V0", "TEveRecV0", &fpV0, 512*1024,1); |
5a5a1232 | 688 | |
689 | TFile f(Form("%s/AliESDs.root", mDataDir.Data())); | |
690 | if(!f.IsOpen()){ | |
691 | throw(eH + "no AliESDs.root file."); | |
692 | } | |
693 | ||
694 | TTree* tree = (TTree*) f.Get("esdTree"); | |
695 | if (tree == 0) | |
696 | throw(eH + "no esdTree."); | |
697 | ||
22aefef8 | 698 | AliESDEvent *fEvent= new AliESDEvent(); |
699 | fEvent->ReadFromTree(tree); | |
5a5a1232 | 700 | tree->GetEntry(mEvent); |
22aefef8 | 701 | if(fEvent->GetAliESDOld())fEvent->CopyFromOldESD(); |
5a5a1232 | 702 | |
982f2494 | 703 | for (Int_t n =0; n< fEvent->GetNumberOfV0s(); n++) |
704 | { | |
705 | AliESDv0 *av = fEvent->GetV0(n); | |
706 | AliESDtrack *trackN = fEvent->GetTrack(av->GetNindex()); // negative daughter | |
707 | AliESDtrack *trackP = fEvent->GetTrack(av->GetPindex()); // positive daughter | |
708 | ||
5a5a1232 | 709 | Double_t pos[3]; |
710 | ||
84aff7a4 | 711 | fV0.fStatus = av->GetStatus(); |
5a5a1232 | 712 | // Point of closest approach |
b75d63a7 | 713 | av->GetXYZ(pos[0],pos[1],pos[2]); |
84aff7a4 | 714 | fV0.fVCa.fX = pos[0]; |
715 | fV0.fVCa.fY = pos[1]; | |
716 | fV0.fVCa.fZ = pos[2]; | |
5a5a1232 | 717 | // set birth vertex of neutral particle |
b75d63a7 | 718 | av->GetXYZ(pos[0], pos[1], pos[2]); |
84aff7a4 | 719 | fV0.fV0Birth.Set(pos); |
5a5a1232 | 720 | |
721 | // momentum and position of negative particle | |
b75d63a7 | 722 | av->GetParamN()->GetPxPyPz(pos); |
84aff7a4 | 723 | fV0.fPNeg.Set(pos); |
b75d63a7 | 724 | av->GetParamN()->GetXYZ(pos); |
84aff7a4 | 725 | fV0.fVNeg.Set(pos); |
5a5a1232 | 726 | |
727 | // momentum and position of positive particle | |
b75d63a7 | 728 | av->GetParamP()->GetPxPyPz(pos); |
84aff7a4 | 729 | fV0.fPPos.Set(pos); |
5a5a1232 | 730 | av->GetParamP()->GetXYZ(pos); |
84aff7a4 | 731 | fV0.fVPos.Set(pos); |
5a5a1232 | 732 | |
84aff7a4 | 733 | fV0.fLabel = 0; // !!!! mother label unknown |
734 | fV0.fPdg = av->GetPdgCode(); | |
982f2494 | 735 | |
5a5a1232 | 736 | // daughter indices |
84aff7a4 | 737 | fV0.fDLabel[0] = TMath::Abs(trackN->GetLabel()); |
738 | fV0.fDLabel[1] = TMath::Abs(trackP->GetLabel()); | |
5a5a1232 | 739 | |
740 | // printf("V0 convert labels(%d,%d) index(%d,%d)\n", | |
84aff7a4 | 741 | // fV0.d_label[0], fV0.d_label[1], |
982f2494 | 742 | // av->GetNIndex(), av->GetPIndex()); |
5a5a1232 | 743 | |
84aff7a4 | 744 | fTreeV0->Fill(); |
5a5a1232 | 745 | } |
84aff7a4 | 746 | // if(fEvent->GetNumberOfV0s()) fTreeV0->BuildIndex("label"); |
22aefef8 | 747 | delete fEvent; |
5a5a1232 | 748 | } |
749 | ||
750 | /**************************************************************************/ | |
751 | ||
752 | void VSDCreator::ConvertKinks() | |
753 | { | |
84aff7a4 | 754 | static const TEveException eH("VSDCreator::ConvertKinks "); |
5a5a1232 | 755 | |
84aff7a4 | 756 | if(fTreeKK != 0) |
5a5a1232 | 757 | throw(eH + "Kinks already converted."); |
758 | ||
84aff7a4 | 759 | fDirectory->cd(); |
760 | fTreeKK = new TTree("Kinks", "ESD Kinks"); | |
5a5a1232 | 761 | |
84aff7a4 | 762 | fTreeKK->Branch("KK", "TEveRecKink", &fpKK, fBuffSize); |
5a5a1232 | 763 | |
764 | TFile f(Form("%s/AliESDs.root", mDataDir.Data())); | |
765 | if(!f.IsOpen()){ | |
766 | throw(eH + "no AliESDs.root file."); | |
767 | } | |
768 | ||
769 | TTree* tree = (TTree*) f.Get("esdTree"); | |
770 | if (tree == 0) | |
771 | throw(eH + "no esdTree."); | |
772 | ||
22aefef8 | 773 | |
774 | AliESDEvent *fEvent= new AliESDEvent(); | |
775 | fEvent->ReadFromTree(tree); | |
5a5a1232 | 776 | tree->GetEntry(mEvent); |
22aefef8 | 777 | if(fEvent->GetAliESDOld())fEvent->CopyFromOldESD(); |
778 | ||
5a5a1232 | 779 | |
780 | // printf("CONVERT KINK Read %d entries in tree kinks \n", fEvent->GetNumberOfKinks()); | |
781 | for (Int_t n =0; n< fEvent->GetNumberOfKinks(); n++) { | |
782 | AliESDkink* kk = fEvent->GetKink(n); | |
783 | ||
784 | Double_t pos[3]; | |
785 | ||
84aff7a4 | 786 | fKK.fLabel = kk->GetLabel(0); |
787 | fKK.fStatus = Int_t(kk->GetStatus(1) << 8 + kk->GetStatus(2)); | |
5a5a1232 | 788 | |
789 | // reconstructed kink position | |
84aff7a4 | 790 | fKK.fLabelSec = kk->GetLabel(1); |
791 | fKK.fVKink.Set(kk->GetPosition()); | |
5a5a1232 | 792 | |
793 | const AliExternalTrackParam& tp_mother = kk->RefParamMother(); | |
794 | // momentum and position of mother | |
795 | tp_mother.GetPxPyPz(pos); | |
84aff7a4 | 796 | fKK.fP.Set(pos); |
5a5a1232 | 797 | tp_mother.GetXYZ(pos); |
84aff7a4 | 798 | fKK.fV.Set(pos); |
5a5a1232 | 799 | const Double_t* par = tp_mother.GetParameter(); |
800 | // printf("KINK Pt %f, %f \n",1/tp_mother.Pt(),par[4] ); | |
84aff7a4 | 801 | fKK.fSign = (par[4] < 0) ? -1 : 1; |
5a5a1232 | 802 | |
803 | const AliExternalTrackParam& tp_daughter = kk->RefParamDaughter(); | |
804 | // momentum and position of daughter | |
805 | tp_daughter.GetPxPyPz(pos); | |
84aff7a4 | 806 | fKK.fPSec.Set(pos); |
5a5a1232 | 807 | tp_daughter.GetXYZ(pos); |
84aff7a4 | 808 | fKK.fVEnd.Set(pos); |
5a5a1232 | 809 | |
84aff7a4 | 810 | fTreeKK->Fill(); |
5a5a1232 | 811 | } |
84aff7a4 | 812 | if(fEvent->GetNumberOfKinks()) fTreeKK->BuildIndex("label"); |
22aefef8 | 813 | delete fEvent; |
5a5a1232 | 814 | } |
815 | /**************************************************************************/ | |
84aff7a4 | 816 | // TEveMCRecCrossRef |
5a5a1232 | 817 | /**************************************************************************/ |
818 | ||
819 | void VSDCreator::ConvertGenInfo() | |
820 | { | |
84aff7a4 | 821 | static const TEveException eH("VSDCreator::ConvertGenInfo "); |
5a5a1232 | 822 | |
84aff7a4 | 823 | if(fTreeGI != 0) |
5a5a1232 | 824 | throw(eH + "GI already converted."); |
825 | ||
84aff7a4 | 826 | fDirectory->cd(); |
827 | fTreeGI = new TTree("TEveMCRecCrossRef", "Objects prepared for cross querry"); | |
5a5a1232 | 828 | |
84aff7a4 | 829 | TEveMCRecCrossRef::Class()->IgnoreTObjectStreamer(true); |
830 | fTreeGI->Branch("GI", "TEveMCRecCrossRef", &fpGI, fBuffSize); | |
831 | fTreeGI->Branch("K.", "TEveMCTrack", &fpK); | |
832 | fTreeGI->Branch("R.", "TEveRecTrack", &fpR); | |
5a5a1232 | 833 | |
84aff7a4 | 834 | for (map<Int_t, TEveMCRecCrossRef*>::iterator j=mGenInfoMap.begin(); j!=mGenInfoMap.end(); ++j) { |
835 | fGI = *(j->second); | |
836 | fGI.fLabel = j->first; | |
837 | fTreeK->GetEntry(j->first); | |
5a5a1232 | 838 | |
84aff7a4 | 839 | if (fTreeR) { |
840 | Int_t re = fTreeR->GetEntryNumberWithIndex(j->first); | |
5a5a1232 | 841 | if(re != -1) |
84aff7a4 | 842 | fGI.fIsRec = true; |
5a5a1232 | 843 | } |
84aff7a4 | 844 | // Int_t has_v0 = fTreeV0->GetEntryNumberWithIndex(j->first); |
5a5a1232 | 845 | //if (has_v0 != -1) |
84aff7a4 | 846 | // fGI.has_V0 = true; |
847 | if (fTreeKK) { | |
848 | Int_t has_kk = fTreeKK->GetEntryNumberWithIndex(j->first); | |
5a5a1232 | 849 | if (has_kk != -1) |
84aff7a4 | 850 | fGI.fHasKink = true; |
5a5a1232 | 851 | } |
84aff7a4 | 852 | fTreeGI->Fill(); |
5a5a1232 | 853 | } |
854 | mGenInfoMap.clear(); | |
855 | } | |
856 | ||
857 | /**************************************************************************/ | |
858 | /**************************************************************************/ | |
859 | // Protected methods | |
860 | /**************************************************************************/ | |
861 | /**************************************************************************/ | |
862 | ||
84aff7a4 | 863 | AliTPCParam* VSDCreator::GetTpcParam(const TEveException& eh) |
5a5a1232 | 864 | { |
865 | auto_ptr<TFile> fp( TFile::Open(Form("%s/galice.root", mDataDir.Data())) ); | |
866 | if(!fp.get()) | |
867 | throw(eh + "can not open 'galice.root' file."); | |
868 | AliTPCParam* par = (AliTPCParam *) fp->Get("75x40_100x60_150x60"); | |
869 | if(!par) | |
870 | throw(eh + "TPC data not found."); | |
871 | return par; | |
872 | } | |
873 | ||
874 | ||
875 | ||
84aff7a4 | 876 | TEveMCRecCrossRef* VSDCreator::GetGeninfo(Int_t label) |
5a5a1232 | 877 | { |
878 | // printf("get_geninfo %d\n", label); | |
84aff7a4 | 879 | TEveMCRecCrossRef* gi; |
880 | map<Int_t, TEveMCRecCrossRef*>::iterator i = mGenInfoMap.find(label); | |
5a5a1232 | 881 | if(i == mGenInfoMap.end()) { |
84aff7a4 | 882 | gi = new TEveMCRecCrossRef(); |
5a5a1232 | 883 | mGenInfoMap[label] = gi; |
884 | } else { | |
885 | gi = i->second; | |
886 | } | |
887 | return gi; | |
888 | } |