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