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