Coverity fix
[u/mrichter/AliRoot.git] / EVE / EveBase / 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 *
51346b82 7 * full copyright notice. *
d810d0de 8 **************************************************************************/
9
b09247a2 10#include <memory>
d810d0de 11#include "AliEveVSDCreator.h"
5a5a1232 12
8cc1d3b4 13#include "AliEveEventManager.h"
14
5a5a1232 15#include <AliStack.h>
16#include <AliITSLoader.h>
17#include <AliTPCTrackHitsV2.h>
18#include <AliPDG.h>
19#include <AliHit.h>
22aefef8 20#include <AliESDEvent.h>
d6a49f20 21#include <AliESDv0.h>
5a5a1232 22#include <AliTPCclusterMI.h>
23#include <AliTPCClustersRow.h>
5a5a1232 24#include <AliITSclusterV2.h>
5a5a1232 25#include <AliESDkink.h>
82e1eece 26#include <AliESDtrack.h>
5a5a1232 27
28#include <AliRun.h>
a15e6d7d 29#include <AliRunLoader.h>
5a5a1232 30#include <AliTPCParam.h>
31
c180f65d 32#include <TDatabasePDG.h>
5a5a1232 33#include <TSystem.h>
34#include <TFile.h>
35
57ffa5fb 36//______________________________________________________________________________
5a5a1232 37//
73c1c0ec 38// Create VSD file from ALICE data.
5a5a1232 39
d810d0de 40ClassImp(AliEveVSDCreator)
5a5a1232 41
d810d0de 42AliEveVSDCreator::AliEveVSDCreator(const Text_t* name, const Text_t* title) :
84aff7a4 43 TEveVSD(name, title),
265ecb21 44
73c1c0ec 45 fTPCHitRes (2),
ba014dea 46 fTRDHitRes (1),
5a5a1232 47
73c1c0ec 48 fDebugLevel (0),
49 fRunLoader (0),
50 fGenInfoMap ()
265ecb21 51{
73c1c0ec 52 // Constructor.
53
5a5a1232 54 // Particles not in ROOT's PDG database occuring in ALICE
55 AliPDG::AddParticlesToPdgDataBase();
5a5a1232 56}
57
57ffa5fb 58/******************************************************************************/
5a5a1232 59
8cc1d3b4 60void AliEveVSDCreator::CreateVSD(const Text_t* vsdFile)
5a5a1232 61{
8cc1d3b4 62 // Create the VSD for current event in AliEveEventManager.
ba014dea 63 // Result is stored in directory "Event%04d".
73c1c0ec 64
a15e6d7d 65 static const TEveException kEH("AliEveVSDCreator::CreateVSD ");
5a5a1232 66
ba014dea 67 AliEveEventManager::AssertGeometry();
68
8cc1d3b4 69 fRunLoader = AliEveEventManager::AssertRunLoader();
5a5a1232 70
ba014dea 71 if (fDebugLevel > 0)
a15e6d7d 72 printf("%s open seems ok. Now loading sim data.\n", kEH.Data());
5a5a1232 73
73c1c0ec 74 fRunLoader->LoadHeader();
75 fRunLoader->LoadKinematics();
76 fRunLoader->LoadTrackRefs();
77 fRunLoader->LoadHits();
5a5a1232 78
ba014dea 79 if (fDebugLevel > 0)
a15e6d7d 80 printf("%s opening output TEveVSD.\n", kEH.Data());
5a5a1232 81
ba014dea 82 TFile* file = TFile::Open(vsdFile, "UPDATE", "ALICE Visualization Summary Data");
83
84 Int_t curEvent = AliEveEventManager::CurrentEventId();
85
86 TString eventDir; eventDir.Form("Event%04d", curEvent);
87
88 if (file->Get(eventDir))
89 {
90 Warning(kEH, "Event-dir '%s' existed -- replacing.", eventDir.Data());
91 file->Delete(eventDir + ";*");
92 }
93
94 fDirectory = new TDirectoryFile(eventDir, Form("Data for event %d", curEvent));
5a5a1232 95
ba014dea 96 if (fDebugLevel > 0)
a15e6d7d 97 printf("%s creating trees now ...\n", kEH.Data());
5a5a1232 98
99 CreateTrees();
100
ba014dea 101 if (fDebugLevel > 0)
a15e6d7d 102 printf("%s trees created, closing files.\n", kEH.Data());
5a5a1232 103
c1d0d915 104 file->Write();
5a5a1232 105 file->Close();
51346b82 106 delete file;
ba014dea 107 fDirectory = 0;
5a5a1232 108
84aff7a4 109 // clean after the TEveVSD data was sucessfuly written
110 fTreeK = 0;
111 fTreeH = 0;
112 //fTreeTR = 0;
113 fTreeC = 0;
114 fTreeV0 = 0;
115 fTreeKK = 0;
116 fTreeR = 0;
117 fTreeGI = 0;
5a5a1232 118
73c1c0ec 119 fRunLoader = 0;
5a5a1232 120
ba014dea 121 if (fDebugLevel > 0)
a15e6d7d 122 printf("%s all done.\n", kEH.Data());
5a5a1232 123}
124
d810d0de 125void AliEveVSDCreator::CreateTrees()
5a5a1232 126{
73c1c0ec 127 // Create and fill the output trees by calling all the
128 // ConvertXyzz() functions.
129 // Exceptions from individual functions are displayed as warnings.
130
a15e6d7d 131 static const TEveException kEH("AliEveVSDCreator::CreateTrees ");
5a5a1232 132
73c1c0ec 133 if (fDirectory == 0)
ba014dea 134 throw kEH + "output directory not set.";
5a5a1232 135
ba014dea 136 try
137 {
73c1c0ec 138 if (fDebugLevel > 1)
a15e6d7d 139 printf("%sConvertKinematics.\n", kEH.Data());
5a5a1232 140 ConvertKinematics();
ba014dea 141 }
142 catch(TEveException& exc)
143 {
144 Warning(kEH, exc);
145 }
8cc1d3b4 146
ba014dea 147 try
148 {
73c1c0ec 149 if (fDebugLevel > 1)
a15e6d7d 150 printf("%sConvertHits.\n", kEH.Data());
5a5a1232 151 ConvertHits();
ba014dea 152 }
153 catch(TEveException& exc)
154 {
155 Warning(kEH, exc);
156 }
5a5a1232 157
ba014dea 158 try
159 {
73c1c0ec 160 if (fDebugLevel > 1)
a15e6d7d 161 printf("%sConvertClusters.\n", kEH.Data());
5a5a1232 162 ConvertClusters();
ba014dea 163 }
164 catch(TEveException& exc)
165 {
166 Warning(kEH, exc);
167 }
5a5a1232 168
ba014dea 169 try
170 {
73c1c0ec 171 if (fDebugLevel > 1)
a15e6d7d 172 printf("%sConvertRecTracks.\n", kEH.Data());
5a5a1232 173 ConvertRecTracks();
ba014dea 174 }
175 catch(TEveException& exc)
176 {
d810d0de 177 Warning(exc, "skipping AliEveV0 extraction.");
5a5a1232 178 goto end_esd_processing;
179 }
180
ba014dea 181 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
182
183 Warning(kEH, "Explicitly abandoning further conversion.");
184 return;
185
186 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
4ae0321d 187/*
ba014dea 188 try
189 {
73c1c0ec 190 if (fDebugLevel > 1)
a15e6d7d 191 printf("%sConvertV0.\n", kEH.Data());
5a5a1232 192 ConvertV0();
ba014dea 193 }
194 catch(TEveException& exc)
195 {
196 Warning(kEH, exc);
197 }
5a5a1232 198
ba014dea 199 try
200 {
73c1c0ec 201 if (fDebugLevel > 1)
a15e6d7d 202 printf("%sConvertKinks.\n", kEH.Data());
5a5a1232 203 ConvertKinks();
ba014dea 204 }
205 catch(TEveException& exc)
206 {
207 Warning(kEH, exc);
208 }
4ae0321d 209*/
5a5a1232 210end_esd_processing:
211
ba014dea 212 try
213 {
73c1c0ec 214 if (fDebugLevel > 1)
a15e6d7d 215 printf("%sConvertGenInfo.\n", kEH.Data());
5a5a1232 216 ConvertGenInfo();
ba014dea 217 }
218 catch(TEveException& exc)
219 {
220 Warning(kEH, exc);
221 }
5a5a1232 222
5a5a1232 223 return;
224}
225
57ffa5fb 226/******************************************************************************/
5a5a1232 227// Kinematics
57ffa5fb 228/******************************************************************************/
5a5a1232 229
d810d0de 230void AliEveVSDCreator::ConvertKinematics()
5a5a1232 231{
73c1c0ec 232 // Convert kinematics.
233 // Track references are not stored, they should be.
234
a15e6d7d 235 static const TEveException kEH("AliEveVSDCreator::ConvertKinematics ");
5a5a1232 236
ba014dea 237 if (fTreeK != 0)
238 throw kEH + "kinematics already converted";
5a5a1232 239
73c1c0ec 240 AliStack* stack = fRunLoader->Stack();
ba014dea 241 if (stack == 0)
242 throw kEH + "stack is null.";
5a5a1232 243
84aff7a4 244 fDirectory->cd();
ba014dea 245 fTreeK = new TTree("Kinematics", "Particles created during simulation.");
51346b82 246
5a5a1232 247 Int_t nentries = stack->GetNtrack();
fd31e9de 248 std::vector<TEveMCTrack> vmc(nentries);
ba014dea 249 for (Int_t idx = 0; idx < nentries; ++idx)
250 {
73c1c0ec 251 TParticle* tp = stack->Particle(idx);
84aff7a4 252 vmc[idx] = *tp;
253 vmc[idx].fLabel = idx;
5a5a1232 254 }
255
84aff7a4 256 // read track refrences
d810d0de 257 // functionality now in AliEveKineTools.
84aff7a4 258 /*
73c1c0ec 259 TTree* fTreeTR = fRunLoader->TreeTR();
5a5a1232 260
84aff7a4 261 if(fTreeTR == 0) {
a15e6d7d 262 Warning(kEH, "no TrackRefs; some data will not be available.");
5a5a1232 263 } else {
264 TClonesArray* RunArrayTR = 0;
84aff7a4 265 fTreeTR->SetBranchAddress("AliRun", &RunArrayTR);
5a5a1232 266
84aff7a4 267 Int_t nPrimaries = (Int_t) fTreeTR->GetEntries();
5a5a1232 268 for (Int_t iPrimPart = 0; iPrimPart<nPrimaries; iPrimPart++) {
84aff7a4 269 // printf("T0 fTreeTR->GetEntry(%d) \n",iPrimPart);
270 fTreeTR->GetEntry(iPrimPart);
271 // printf("END fTreeTR->GetEntry(%d) \n",iPrimPart);
51346b82 272
5a5a1232 273 for (Int_t iTrackRef = 0; iTrackRef < RunArrayTR->GetEntriesFast(); iTrackRef++) {
51346b82 274 AliTrackReference *trackRef = (AliTrackReference*)RunArrayTR->At(iTrackRef);
5a5a1232 275 Int_t track = trackRef->GetTrack();
51346b82 276 if(track < nentries && track > 0){
277 TEveMCTrack& mct = vmc[track];
5a5a1232 278 if(trackRef->TestBit(kNotDeleted)) {
279 mct.decayed = true;
280 mct.t_decay = trackRef->GetTime();
281 mct.V_decay.x = trackRef->X();
282 mct.V_decay.y = trackRef->Y();
283 mct.V_decay.z = trackRef->Z();
284 mct.P_decay.x = trackRef->Px();
285 mct.P_decay.y = trackRef->Py();
286 mct.P_decay.z = trackRef->Pz();
287 if(TMath::Abs(mct.GetPdgCode()) == 11)
288 mct.decayed = false; // a bug in TreeTR
289 }
51346b82 290 }
5a5a1232 291 }
292 }
293 }
84aff7a4 294 */
5a5a1232 295
84aff7a4 296 fTreeK->Branch("K", "TEveMCTrack", &fpK, fBuffSize);
5a5a1232 297
6242b962 298 printf("sizeofvmc = %d\n", (Int_t) vmc.size());
ba014dea 299 for(std::vector<TEveMCTrack>::iterator k = vmc.begin(); k != vmc.end(); ++k)
300 {
84aff7a4 301 TEveMCTrack& mct = *k;
302 fK = mct;
5a5a1232 303
304 TParticle* m = &mct;
84aff7a4 305 Int_t mi = mct.fLabel;
5a5a1232 306 int cnt = 0;
ba014dea 307 while (m->GetMother(0) != -1)
308 {
309 if (cnt > 100)
5a5a1232 310 printf("cnt %d mi=%d, mo=%d\n", cnt, mi, m->GetMother(0));
ba014dea 311
5a5a1232 312 mi = m->GetMother(0);
313 m = &vmc[mi];
314 ++cnt;
315 }
84aff7a4 316 fK.fEvaLabel = mi;
5a5a1232 317
84aff7a4 318 fTreeK->Fill();
5a5a1232 319 }
320
8cc1d3b4 321 fTreeK->BuildIndex("fLabel");
5a5a1232 322}
323
5a5a1232 324
ba014dea 325//==============================================================================
326// Hits
327//==============================================================================
5a5a1232 328
d810d0de 329void AliEveVSDCreator::ConvertHits()
5a5a1232 330{
73c1c0ec 331 // Convert MC hits.
332 // TPC hits are handled specially as they are compressed - only mayor
333 // hits are stored
334
a15e6d7d 335 static const TEveException kEH("AliEveVSDCreator::ConvertHits ");
5a5a1232 336
73c1c0ec 337 if (fTreeH != 0)
ba014dea 338 throw kEH + "hits already converted.";
5a5a1232 339
84aff7a4 340 fDirectory->cd();
ba014dea 341 fTreeH = new TTree("Hits", "Simulated energy depositions in detector.");
84aff7a4 342 fTreeH->Branch("H", "TEveHit", &fpH, fBuffSize);
51346b82 343
ba014dea 344 try
345 {
346 ConvertAnyHits("ITS", "AliITShit", 0, 0);
347 ConvertTPCHits( 1, fTPCHitRes*fTPCHitRes);
348 ConvertAnyHits("TRD", "AliTRDhit", 2, fTRDHitRes*fTRDHitRes);
349 ConvertAnyHits("TOF", "AliTOFhit", 3, 0);
350
351 }
352 catch(TEveException& exc)
353 {
354 Warning(kEH, exc);
355 }
356}
357
358//------------------------------------------------------------------------------
359
360void AliEveVSDCreator::ConvertAnyHits(const TString& detector,
361 const TString& clones_class,
362 Int_t det_id, Float_t minDistSqr)
363{
364 // Convert hits for detector.
365
366 static const TEveException kEH("AliEveVSDCreator::ConvertAnyHits ");
367
5a5a1232 368 Float_t x,y,z, x1,y1,z1;
5a5a1232 369
ba014dea 370 TTree* treeh = fRunLoader->GetTreeH(detector, kFALSE);
371 if (treeh == 0)
73c1c0ec 372 {
ba014dea 373 Warning(kEH, Form("no hits for %s.", detector.Data()));
374 return;
375 }
5a5a1232 376
ba014dea 377 TClonesArray *arr = new TClonesArray(clones_class);
378 treeh->SetBranchAddress(detector, &arr);
379 Int_t np = treeh->GetEntries();
380
381 // In TreeH files hits are grouped in clones arrays
382 // each eva particle has its own clone array.
383
384 std::map<Int_t, Int_t> hmap;
385
386 for (Int_t i = 0; i < np; ++i)
387 {
388 treeh->GetEntry(i);
389 Int_t evaIdx = np - i - 1;
390 Int_t nh = arr->GetEntriesFast();
391 x = y = z = 0;
392 // printf("%d entry %d hits for primary %d \n", i, nh, evaIdx);
393 for (Int_t j = 0; j < nh; ++j)
73c1c0ec 394 {
ba014dea 395 AliHit* aliHit = (AliHit*)arr->UncheckedAt(j);
396
397 x1 = aliHit->X(); y1 = aliHit->Y(); z1 = aliHit->Z();
398 if (minDistSqr == 0 || (x-x1)*(x-x1) + (y-y1)*(y-y1) + (z-z1)*(z-z1) > minDistSqr)
73c1c0ec 399 {
ba014dea 400 fH.fDetId = det_id;
401 fH.fSubdetId = 0;
402 fH.fLabel = aliHit->GetTrack();
403 fH.fEvaLabel = evaIdx;
404 fH.fV.Set(aliHit->X(), aliHit->Y(), aliHit->Z());
405
406 fTreeH->Fill();
407
408 hmap[fH.fLabel]++;
409
410 x=x1; y=y1; z=z1;
5a5a1232 411 }
ba014dea 412 }
413 }
414 delete arr;
415
416 // Set geninfo.
417 for (std::map<Int_t, Int_t>::iterator j = hmap.begin(); j != hmap.end(); ++j)
418 {
419 GetGeninfo(j->first)->fNHits += j->second;
420 }
421}
422
423//------------------------------------------------------------------------------
424
425void AliEveVSDCreator::ConvertTPCHits(Int_t det_id, Float_t minDistSqr)
426{
427 // Convert hits for TPC.
428
429 static const TEveException kEH("AliEveVSDCreator::ConvertTPCHits ");
430
431 Float_t x,y,z, x1,y1,z1;
432
433 TTree* treeh = fRunLoader->GetTreeH("TPC", false);
434 if (treeh == 0)
435 {
436 Warning(kEH, Form("no hits for %s.", "TPC"));
437 return;
438 }
439
440 AliTPCTrackHitsV2 hv2, *hv2p = &hv2;
441 treeh->SetBranchAddress("TPC2", &hv2p);
442 Int_t np = treeh->GetEntries();
443
444 std::map<Int_t, Int_t> hmap;
445
446 for (Int_t i = 0; i < np; ++i)
447 {
448 treeh->GetEntry(i);
449 Int_t evaIdx = np -i -1;
450 if (hv2.First() == 0) continue;
451 x = y = z = 0;
452 do
453 {
454 AliHit* ah = hv2.GetHit();
455 x1 = ah->X(); y1 = ah->Y(); z1 = ah->Z();
456 if (minDistSqr == 0 || (x-x1)*(x-x1) + (y-y1)*(y-y1) + (z-z1)*(z-z1) > minDistSqr)
73c1c0ec 457 {
ba014dea 458 fH.fDetId = det_id;
459 fH.fSubdetId = 0;
460 fH.fLabel = ah->Track();
461 fH.fEvaLabel = evaIdx;
462 fH.fV.fX = x1; fH.fV.fY = y1; fH.fV.fZ = z1;
51346b82 463
ba014dea 464 fTreeH->Fill();
5a5a1232 465
ba014dea 466 hmap[fH.fLabel]++;
467
468 x = x1; y = y1; z = z1;
469 }
470 } while (hv2.Next());
471 }
472
473 // Set geninfo.
474 for (std::map<Int_t, Int_t>::iterator j = hmap.begin(); j != hmap.end(); ++j)
73c1c0ec 475 {
84aff7a4 476 GetGeninfo(j->first)->fNHits += j->second;
5a5a1232 477 }
5a5a1232 478}
479
ba014dea 480
481//==============================================================================
5a5a1232 482// Clusters
ba014dea 483//==============================================================================
5a5a1232 484
d810d0de 485void AliEveVSDCreator::ConvertClusters()
5a5a1232 486{
73c1c0ec 487 // Convert clusters.
488 //
489 // Only supported for ITS and TPC at the moment, see dedicated
490 // functions ConvertITSClusters() and ConvertTPCClusters().
491 //
492 // It should be possible now to do this in a general manner (with
493 // the alignment framework).
494
a15e6d7d 495 static const TEveException kEH("AliEveVSDCreator::ConvertClusters ");
5a5a1232 496
ba014dea 497 if (fTreeC != 0)
498 throw kEH + "clusters already converted.";
5a5a1232 499
84aff7a4 500 fDirectory->cd();
ba014dea 501 fTreeC = new TTree("Clusters", "Reconstructed points of particle passage.");
84aff7a4 502 fTreeC->Branch("C", "TEveCluster", &fpC, fBuffSize);
5a5a1232 503
ba014dea 504 try
505 {
506 ConvertAnyClusters("ITS", "ITSRecPoints", 0);
507 ConvertTPCClusters( 1);
508 ConvertAnyClusters("TRD", "TRDcluster", 2);
509 ConvertAnyClusters("TOF", "TOF", 3);
5a5a1232 510
ba014dea 511 }
512 catch(TEveException& exc)
513 {
514 Warning(kEH, exc);
515 }
5a5a1232 516}
517
ba014dea 518//------------------------------------------------------------------------------
5a5a1232 519
ba014dea 520void AliEveVSDCreator::ConvertAnyClusters(const TString& detector,
521 const TString& branch_name,
522 Int_t det_id)
5a5a1232 523{
ba014dea 524 // Convert clusters for detector and transform them to global coordinates.
73c1c0ec 525
ba014dea 526 static const TEveException kEH("AliEveVSDCreator::ConvertITSClusters ");
5a5a1232 527
ba014dea 528 fRunLoader->LoadRecPoints(detector);
529 TTree* tree = fRunLoader->GetTreeR(detector, false);
8cc1d3b4 530 if (!tree)
ba014dea 531 throw kEH + "'TreeR' not found.";
5a5a1232 532
ba014dea 533 TClonesArray *cl = 0;
534 TBranch *branch = tree->GetBranch(branch_name);
535 branch->SetAddress(&cl);
5a5a1232 536
ba014dea 537 Int_t nmods = branch->GetEntries();
5a5a1232 538
fd31e9de 539 std::map<Int_t, Int_t> cmap;
5a5a1232 540
ba014dea 541 for (Int_t mod = 0; mod < nmods; ++mod)
73c1c0ec 542 {
ba014dea 543 branch->GetEntry(mod);
544 Int_t nc = cl->GetEntriesFast();
545 for (Int_t j = 0; j < nc; ++j)
73c1c0ec 546 {
ba014dea 547 AliCluster *c = (AliCluster*) cl->UncheckedAt(j);
548
549 fC.fDetId = det_id;
550 fC.fSubdetId = mod;
551 fC.fLabel[0] = c->GetLabel(0);
552 fC.fLabel[1] = c->GetLabel(1);
553 fC.fLabel[2] = c->GetLabel(2);
554
555 c->GetGlobalXYZ(fC.fV.Arr());
556
557 fTreeC->Fill();
558
73c1c0ec 559 {
ba014dea 560 int i = 0;
561 while (i < 3 && fC.fLabel[i])
562 cmap[fC.fLabel[i++]]++;
5a5a1232 563 }
564 }
565 }
ba014dea 566 delete cl;
567
73c1c0ec 568 for (std::map<Int_t, Int_t>::iterator j=cmap.begin(); j!=cmap.end(); ++j)
569 {
84aff7a4 570 GetGeninfo(j->first)->fNClus += j->second;
5a5a1232 571 }
572}
573
ba014dea 574//------------------------------------------------------------------------------
5a5a1232 575
ba014dea 576void AliEveVSDCreator::ConvertTPCClusters(Int_t det_id)
5a5a1232 577{
ba014dea 578 // Convert TPC clusters and transform them to global coordinates.
73c1c0ec 579
ba014dea 580 static const TEveException kEH("AliEveVSDCreator::ConvertTPCClusters ");
5a5a1232 581
ba014dea 582 const Int_t kMaxCl = 100*160;
5a5a1232 583
ba014dea 584 fRunLoader->LoadRecPoints("TPC");
585 TTree* tree = fRunLoader->GetTreeR("TPC", false);
586 if (!tree)
587 throw kEH + "'TreeR' not found.";
5a5a1232 588
ba014dea 589 AliTPCClustersRow *clrow = new AliTPCClustersRow;
590 clrow->SetClass("AliTPCclusterMI");
591 clrow->SetArray(kMaxCl);
592 tree->SetBranchAddress("Segment", &clrow);
5a5a1232 593
ba014dea 594 Int_t nEnt = tree->GetEntries();
5a5a1232 595
fd31e9de 596 std::map<Int_t, Int_t> cmap;
5a5a1232 597
ba014dea 598 for (Int_t j = 0; j < nEnt; ++j)
73c1c0ec 599 {
ba014dea 600 if (!tree->GetEvent(j)) continue;
601
602 TClonesArray *cl = clrow->GetArray();
603 Int_t ncl = cl->GetEntriesFast();
604
605 while (ncl--)
73c1c0ec 606 {
ba014dea 607 AliCluster *c = (AliCluster*) cl->UncheckedAt(ncl);
608
609 fC.fDetId = det_id;
610 fC.fSubdetId = j;
611 fC.fLabel[0] = c->GetLabel(0);
612 fC.fLabel[1] = c->GetLabel(1);
613 fC.fLabel[2] = c->GetLabel(2);
614
615 c->GetGlobalXYZ(fC.fV.Arr());
616
84aff7a4 617 fTreeC->Fill();
ba014dea 618
619 {
620 int i = 0;
621 while (i < 3 && fC.fLabel[i])
84aff7a4 622 cmap[fC.fLabel[i++]]++;
5a5a1232 623 }
51346b82 624 }
5a5a1232 625
ba014dea 626 cl->Clear();
627 }
628 delete clrow;
629
630 //set geninfo
631 for (std::map<Int_t, Int_t>::iterator j=cmap.begin(); j!=cmap.end(); ++j)
632 {
633 GetGeninfo(j->first)->fNClus += j->second;
5a5a1232 634 }
5a5a1232 635}
636
ba014dea 637
57ffa5fb 638/******************************************************************************/
5a5a1232 639// ESD
57ffa5fb 640/******************************************************************************/
5a5a1232 641
d810d0de 642void AliEveVSDCreator::ConvertRecTracks()
5a5a1232 643{
73c1c0ec 644 // Convert reconstructed tracks.
645
a15e6d7d 646 static const TEveException kEH("AliEveVSDCreator::ConvertRecTracks ");
5a5a1232 647
73c1c0ec 648 if (fTreeR != 0)
ba014dea 649 throw kEH + "tracks already converted.";
5a5a1232 650
8cc1d3b4 651 AliESDEvent* esdEvent = AliEveEventManager::AssertESD();
652
84aff7a4 653 fDirectory->cd();
ba014dea 654 fTreeR = new TTree("RecTracks", "Reconstructed particle trajectories.");
655 fTreeR->Branch("R", "TEveRecTrack", &fpR, 512*1024);
51346b82 656
5a5a1232 657 // reconstructed tracks
a15e6d7d 658 AliESDtrack* esdTrack;
5a5a1232 659 Double_t dbuf[3];
73c1c0ec 660 for (Int_t n = 0; n < esdEvent->GetNumberOfTracks(); ++n)
661 {
a15e6d7d 662 esdTrack = esdEvent->GetTrack(n);
663
664 fR.fLabel = esdTrack->GetLabel();
665 fR.fStatus = (Int_t) esdTrack->GetStatus();
666 fR.fSign = (Int_t) esdTrack->GetSign();
667 esdTrack->GetXYZ(dbuf); fR.fV.Set(dbuf);
668 esdTrack->GetPxPyPz(dbuf); fR.fP.Set(dbuf);
669 Double_t ep = esdTrack->GetP();
670 fR.fBeta = ep/TMath::Sqrt(ep*ep + TMath::C()*TMath::C()*esdTrack->GetMass()*esdTrack->GetMass());
84aff7a4 671 fTreeR->Fill();
5a5a1232 672 }
ba014dea 673
674 fTreeR->BuildIndex("fLabel");
5a5a1232 675}
676
57ffa5fb 677/******************************************************************************/
5a5a1232 678
d810d0de 679void AliEveVSDCreator::ConvertV0()
5a5a1232 680{
73c1c0ec 681 // Convert reconstructed V0s.
682
a15e6d7d 683 static const TEveException kEH("AliEveVSDCreator::ConvertV0 ");
5a5a1232 684
ba014dea 685 if (fTreeV0 != 0)
686 throw kEH + "AliEveV0 already converted.";
5a5a1232 687
8cc1d3b4 688 AliESDEvent* esdEvent = AliEveEventManager::AssertESD();
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
73c1c0ec 695 for (Int_t n = 0; n < esdEvent->GetNumberOfV0s(); ++n)
982f2494 696 {
73c1c0ec 697 AliESDv0 *av = esdEvent->GetV0(n);
698 AliESDtrack *trackN = esdEvent->GetTrack(av->GetNindex()); // negative daughter
699 AliESDtrack *trackP = esdEvent->GetTrack(av->GetPindex()); // positive daughter
982f2494 700
5a5a1232 701 Double_t pos[3];
702
84aff7a4 703 fV0.fStatus = av->GetStatus();
5a5a1232 704 // Point of closest approach
b75d63a7 705 av->GetXYZ(pos[0],pos[1],pos[2]);
51346b82 706 fV0.fVCa.fX = pos[0];
84aff7a4 707 fV0.fVCa.fY = pos[1];
708 fV0.fVCa.fZ = pos[2];
51346b82 709 // set birth vertex of neutral particle
b75d63a7 710 av->GetXYZ(pos[0], pos[1], pos[2]);
84aff7a4 711 fV0.fV0Birth.Set(pos);
5a5a1232 712
713 // momentum and position of negative particle
b75d63a7 714 av->GetParamN()->GetPxPyPz(pos);
84aff7a4 715 fV0.fPNeg.Set(pos);
b75d63a7 716 av->GetParamN()->GetXYZ(pos);
84aff7a4 717 fV0.fVNeg.Set(pos);
5a5a1232 718
719 // momentum and position of positive particle
b75d63a7 720 av->GetParamP()->GetPxPyPz(pos);
84aff7a4 721 fV0.fPPos.Set(pos);
5a5a1232 722 av->GetParamP()->GetXYZ(pos);
84aff7a4 723 fV0.fVPos.Set(pos);
5a5a1232 724
84aff7a4 725 fV0.fLabel = 0; // !!!! mother label unknown
726 fV0.fPdg = av->GetPdgCode();
982f2494 727
5a5a1232 728 // daughter indices
84aff7a4 729 fV0.fDLabel[0] = TMath::Abs(trackN->GetLabel());
730 fV0.fDLabel[1] = TMath::Abs(trackP->GetLabel());
5a5a1232 731
51346b82 732 // printf("AliEveV0 convert labels(%d,%d) index(%d,%d)\n",
84aff7a4 733 // fV0.d_label[0], fV0.d_label[1],
982f2494 734 // av->GetNIndex(), av->GetPIndex());
5a5a1232 735
84aff7a4 736 fTreeV0->Fill();
5a5a1232 737 }
73c1c0ec 738 // if (esdEvent->GetNumberOfV0s()) fTreeV0->BuildIndex("label");
739 delete esdEvent;
5a5a1232 740}
741
57ffa5fb 742/******************************************************************************/
5a5a1232 743
d810d0de 744void AliEveVSDCreator::ConvertKinks()
5a5a1232 745{
73c1c0ec 746 // Convert reconstructed kinks.
747
a15e6d7d 748 static const TEveException kEH("AliEveVSDCreator::ConvertKinks ");
5a5a1232 749
73c1c0ec 750 if (fTreeKK != 0)
ba014dea 751 throw kEH + "Kinks already converted.";
5a5a1232 752
2626c85d 753 throw kEH + "Currently non-supported - TEveRecKink being updated.";
754
755 /*
8cc1d3b4 756 AliESDEvent* esdEvent = AliEveEventManager::AssertESD();
757
84aff7a4 758 fDirectory->cd();
759 fTreeKK = new TTree("Kinks", "ESD Kinks");
5a5a1232 760
84aff7a4 761 fTreeKK->Branch("KK", "TEveRecKink", &fpKK, fBuffSize);
5a5a1232 762
73c1c0ec 763 // printf("CONVERT KINK Read %d entries in tree kinks \n", esdEvent->GetNumberOfKinks());
764 for (Int_t n = 0; n < esdEvent->GetNumberOfKinks(); ++n)
765 {
766 AliESDkink* kk = esdEvent->GetKink(n);
5a5a1232 767
768 Double_t pos[3];
769
84aff7a4 770 fKK.fLabel = kk->GetLabel(0);
edaf814f 771 fKK.fStatus = 0; // status is Char_t[12] ... have no idea how/what to extract.
5a5a1232 772
773 // reconstructed kink position
84aff7a4 774 fKK.fLabelSec = kk->GetLabel(1);
775 fKK.fVKink.Set(kk->GetPosition());
5a5a1232 776
73c1c0ec 777 const AliExternalTrackParam& tpMother = kk->RefParamMother();
51346b82 778 // momentum and position of mother
73c1c0ec 779 tpMother.GetPxPyPz(pos);
84aff7a4 780 fKK.fP.Set(pos);
73c1c0ec 781 tpMother.GetXYZ(pos);
84aff7a4 782 fKK.fV.Set(pos);
73c1c0ec 783 const Double_t* par = tpMother.GetParameter();
784 // printf("KINK Pt %f, %f \n",1/tpMother.Pt(),par[4] );
84aff7a4 785 fKK.fSign = (par[4] < 0) ? -1 : 1;
51346b82 786
73c1c0ec 787 const AliExternalTrackParam& tpDaughter = kk->RefParamDaughter();
51346b82 788 // momentum and position of daughter
73c1c0ec 789 tpDaughter.GetPxPyPz(pos);
84aff7a4 790 fKK.fPSec.Set(pos);
73c1c0ec 791 tpDaughter.GetXYZ(pos);
84aff7a4 792 fKK.fVEnd.Set(pos);
5a5a1232 793
84aff7a4 794 fTreeKK->Fill();
5a5a1232 795 }
73c1c0ec 796 if (esdEvent->GetNumberOfKinks()) fTreeKK->BuildIndex("label");
797 delete esdEvent;
2626c85d 798 */
5a5a1232 799}
57ffa5fb 800/******************************************************************************/
84aff7a4 801// TEveMCRecCrossRef
57ffa5fb 802/******************************************************************************/
5a5a1232 803
d810d0de 804void AliEveVSDCreator::ConvertGenInfo()
5a5a1232 805{
73c1c0ec 806 // Build simulation-reconstruction cross-reference table.
807 // In a rather poor state at the moment.
808
a15e6d7d 809 static const TEveException kEH("AliEveVSDCreator::ConvertGenInfo ");
5a5a1232 810
ba014dea 811 if (fTreeGI != 0)
812 throw kEH + "GI already converted.";
5a5a1232 813
84aff7a4 814 fDirectory->cd();
815 fTreeGI = new TTree("TEveMCRecCrossRef", "Objects prepared for cross querry");
5a5a1232 816
84aff7a4 817 TEveMCRecCrossRef::Class()->IgnoreTObjectStreamer(true);
818 fTreeGI->Branch("GI", "TEveMCRecCrossRef", &fpGI, fBuffSize);
819 fTreeGI->Branch("K.", "TEveMCTrack", &fpK);
820 fTreeGI->Branch("R.", "TEveRecTrack", &fpR);
5a5a1232 821
ba014dea 822 for (std::map<Int_t, TEveMCRecCrossRef*>::iterator j=fGenInfoMap.begin(); j!=fGenInfoMap.end(); ++j)
823 {
84aff7a4 824 fGI = *(j->second);
825 fGI.fLabel = j->first;
826 fTreeK->GetEntry(j->first);
5a5a1232 827
84aff7a4 828 if (fTreeR) {
829 Int_t re = fTreeR->GetEntryNumberWithIndex(j->first);
51346b82 830 if(re != -1)
84aff7a4 831 fGI.fIsRec = true;
5a5a1232 832 }
73c1c0ec 833 // Int_t hasV0 = fTreeV0->GetEntryNumberWithIndex(j->first);
834 //if (hasV0 != -1)
d810d0de 835 // fGI.has_AliEveV0 = true;
ba014dea 836 if (fTreeKK)
837 {
73c1c0ec 838 Int_t hasKk = fTreeKK->GetEntryNumberWithIndex(j->first);
839 if (hasKk != -1)
84aff7a4 840 fGI.fHasKink = true;
5a5a1232 841 }
84aff7a4 842 fTreeGI->Fill();
5a5a1232 843 }
73c1c0ec 844 fGenInfoMap.clear();
5a5a1232 845}
846
57ffa5fb 847/******************************************************************************/
848/******************************************************************************/
5a5a1232 849// Protected methods
57ffa5fb 850/******************************************************************************/
851/******************************************************************************/
5a5a1232 852
d810d0de 853TEveMCRecCrossRef* AliEveVSDCreator::GetGeninfo(Int_t label)
5a5a1232 854{
73c1c0ec 855 // Return the cross-reference structure for given label.
856 // If the object does not exist it is created.
857
5a5a1232 858 // printf("get_geninfo %d\n", label);
84aff7a4 859 TEveMCRecCrossRef* gi;
73c1c0ec 860 std::map<Int_t, TEveMCRecCrossRef*>::iterator i = fGenInfoMap.find(label);
ba014dea 861 if (i == fGenInfoMap.end())
862 {
84aff7a4 863 gi = new TEveMCRecCrossRef();
73c1c0ec 864 fGenInfoMap[label] = gi;
ba014dea 865 }
866 else
867 {
5a5a1232 868 gi = i->second;
869 }
870 return gi;
871}