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