3 #include "VSDCreator.h"
5 #include <Reve/TTreeTools.h>
8 #include <AliITSLoader.h>
9 #include <AliTPCTrackHitsV2.h>
12 #include <AliSimDigits.h>
13 #include <AliKalmanTrack.h>
15 #include <AliESDV0MI.h>
16 #include <AliTPCclusterMI.h>
17 #include <AliTPCClustersRow.h>
19 #include <AliITSclusterV2.h>
20 #include <AliTrackReference.h>
21 #include <AliESDkink.h>
24 #include <AliTPCParam.h>
30 using namespace Alieve;
34 //______________________________________________________________________
40 void VSDCreator::init()
42 mKineType = KT_Standard;
50 // Particles not in ROOT's PDG database occuring in ALICE
51 AliPDG::AddParticlesToPdgDataBase();
53 TDatabasePDG *pdgDB = TDatabasePDG::Instance();
54 // const Int_t kspe=50000000;
55 const Int_t kion=10000000;
57 const Double_t kAu2Gev=0.9314943228;
58 const Double_t khSlash = 1.0545726663e-27;
59 const Double_t kErg2Gev = 1/1.6021773349e-3;
60 const Double_t khShGev = khSlash*kErg2Gev;
61 const Double_t kYear2Sec = 3600*24*365.25;
63 pdgDB->AddParticle("Deuteron","Deuteron",2*kAu2Gev+8.071e-3,kTRUE,
64 0,1,"Ion",kion+10020);
65 pdgDB->AddParticle("Triton","Triton",3*kAu2Gev+14.931e-3,kFALSE,
66 khShGev/(12.33*kYear2Sec),1,"Ion",kion+10030);
67 pdgDB->AddParticle("Alpha","Alpha",4*kAu2Gev+2.424e-3,kTRUE,
68 khShGev/(12.33*kYear2Sec),2,"Ion",kion+20040);
69 pdgDB->AddParticle("HE3","HE3",3*kAu2Gev+14.931e-3,kFALSE,
70 0,2,"Ion",kion+20030);
73 // AliKalmanTrack::SetConvConst(1);
76 VSDCreator::VSDCreator()
81 VSDCreator::VSDCreator(const Text_t* name, const Text_t* title) :
87 /**************************************************************************/
89 void VSDCreator::CreateVSD(const Text_t* data_dir, Int_t event,
90 const Text_t* vsd_file)
92 static const Exc_t eH("VSDCreator::CreateVSD ");
97 string galice_file (Form("%s/galice.root", mDataDir.Data()));
100 printf("%s opening %s \n", eH.Data(), galice_file.c_str());
102 if(gSystem->AccessPathName(galice_file.c_str(), kReadPermission)) {
103 throw(eH + "Can not read file '" + galice_file + "'.");
105 pRunLoader = AliRunLoader::Open(galice_file.c_str());
107 throw(eH + "AliRunLoader::Open failed.");
109 pRunLoader->LoadgAlice();
110 Int_t status = pRunLoader->GetEvent(mEvent);
112 throw(eH + Form("GetEvent(%d) failed, exit code %s.", mEvent, status));
115 printf("%s open seems ok. Now loading sim data.\n", eH.Data());
117 pRunLoader->LoadHeader();
118 pRunLoader->LoadKinematics();
119 pRunLoader->LoadTrackRefs();
120 pRunLoader->LoadHits();
125 printf("%s opening output VSD.\n", eH.Data());
127 TFile* file = TFile::Open(vsd_file, "RECREATE", "ALICE VisualizationDataSummary");
128 mDirectory = new TDirectory("Event0", "");
131 printf("%s creating trees now ...\n", eH.Data());
136 printf("%s trees created, closing files.\n", eH.Data());
145 // clean after the VSD data was sucessfuly written
155 pRunLoader->UnloadAll();
158 delete gAlice; gAlice = 0;
163 printf("%s all done.\n", eH.Data());
166 void VSDCreator::CreateTrees()
168 static const Exc_t eH("VSDCreator::CreateTrees ");
171 throw(eH + "output directory not set.");
175 printf("%s ConvertKinematics.\n", eH.Data());
177 } catch(Exc_t& exc) { WarnCaller(exc); }
181 printf("%s ConvertHits.\n", eH.Data());
183 } catch(Exc_t& exc) { WarnCaller(exc); }
187 printf("%s ConvertClusters.\n", eH.Data());
189 } catch(Exc_t& exc) { WarnCaller(exc); }
192 printf("############# EXITING, had incompatible ESDTrack class #####\n");
193 goto end_geninfo_processing;
198 printf("%s ConvertRecTracks.\n", eH.Data());
200 } catch(Exc_t& exc) {
201 WarnCaller(exc + " Skipping V0 extraction.");
202 goto end_esd_processing;
207 printf("%s ConvertV0.\n", eH.Data());
209 } catch(Exc_t& exc) { WarnCaller(exc); }
213 printf("%s ConvertKinks.\n", eH.Data());
215 } catch(Exc_t& exc) { WarnCaller(exc); }
221 printf("%s ConvertGenInfo.\n", eH.Data());
223 } catch(Exc_t& exc) { WarnCaller(exc); }
225 end_geninfo_processing:
229 /**************************************************************************/
231 /**************************************************************************/
233 void VSDCreator::ConvertKinematics()
235 static const Exc_t eH("VSDCreator::ConvertKinematics ");
238 throw (eH + "kinematics already converted");
240 AliStack* stack = pRunLoader->Stack();
242 throw(eH + "stack is null.");
245 mTreeK = new TTree("Kinematics", "TParticles sorted by Label");
247 Int_t nentries = stack->GetNtrack();
248 vector<MCTrack> vmc(nentries);
249 for (Int_t idx=0; idx<nentries; idx++) {
250 TParticle* tp = stack->Particle(idx);
252 vmc[idx].label = idx;
255 // read track refrences
256 TTree* mTreeTR = pRunLoader->TreeTR();
259 WarnCaller(eH + "no TrackRefs; some data will not be available.");
261 TClonesArray* RunArrayTR = 0;
262 mTreeTR->SetBranchAddress("AliRun", &RunArrayTR);
264 Int_t nPrimaries = (Int_t) mTreeTR->GetEntries();
265 for (Int_t iPrimPart = 0; iPrimPart<nPrimaries; iPrimPart++) {
266 // printf("START mTreeTR->GetEntry(%d) \n",iPrimPart);
267 mTreeTR->GetEntry(iPrimPart);
268 // printf("END mTreeTR->GetEntry(%d) \n",iPrimPart);
270 for (Int_t iTrackRef = 0; iTrackRef < RunArrayTR->GetEntriesFast(); iTrackRef++) {
271 AliTrackReference *trackRef = (AliTrackReference*)RunArrayTR->At(iTrackRef);
272 Int_t track = trackRef->GetTrack();
273 if(track < nentries && track > 0){
274 MCTrack& mct = vmc[track];
275 if(trackRef->TestBit(kNotDeleted)) {
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
292 mTreeK->Branch("K", "Reve::MCTrack", &mpK, fBuffSize);
294 printf("sizeofvmc = %d\n", vmc.size());
295 for(vector<MCTrack>::iterator k=vmc.begin(); k!=vmc.end(); ++k) {
300 Int_t mi = mct.label;
302 while(m->GetMother(0) != -1) {
304 printf("cnt %d mi=%d, mo=%d\n", cnt, mi, m->GetMother(0));
306 mi = m->GetMother(0);
315 mTreeK->BuildIndex("label");
318 /**************************************************************************/
320 /**************************************************************************/
327 const char* hitbranch;
328 unsigned char detidx;
331 Detector detects[] = {
332 { "ITS", "AliITShit", 0 },
333 { "TPC", "AliTPCTrackHitsV2", 1 },
334 { "TRD", "AliTRDhit", 2 },
335 { "TOF", "AliTOFhit", 3 }
336 // { "RICH", "AliRICHhit", 4 },
341 /**************************************************************************/
343 void VSDCreator::ConvertHits()
345 static const Exc_t eH("VSDCreator::ConvertHits ");
348 throw(eH + "hits already converted.");
351 mTreeH = new TTree("Hits", "Combined detector hits.");
352 mTreeH->Branch("H", "Reve::Hit", &mpH, fBuffSize);
354 map<Int_t, Int_t> hmap;
355 // parameters for ITS, TPC hits filtering
356 Float_t x,y,z, x1,y1,z1;
357 Float_t tpc_sqr_res = mTPCHitRes*mTPCHitRes;
358 Float_t trd_sqr_res = mTRDHitRes*mTRDHitRes;
361 // load hits from the rest of detectors
362 while(detects[l].name != 0) {
363 Detector& det = detects[l++];
368 TTree* treeh = pRunLoader->GetTreeH(det.name, false);
370 WarnCaller(eH + "no hits for "+ det.name +".");
373 AliTPCTrackHitsV2 hv2, *_hv2=&hv2;
374 treeh->SetBranchAddress("TPC2", &_hv2);
375 Int_t np = treeh->GetEntries();
376 for(Int_t i=0; i<np; i++){
378 Int_t eva_idx = np -i -1;
379 if (hv2.First() == 0) continue;
382 AliHit* ah = hv2.GetHit();
383 x1=ah->X();y1=ah->Y();z1=ah->Z();
384 if((x-x1)*(x-x1)+(y-y1)*(y-y1)+(z-z1)*(z-z1) > tpc_sqr_res) {
385 mH.det_id = det.detidx;
387 mH.label = ah->Track();
388 mH.eva_label = eva_idx;
389 mH.V.x = x1; mH.V.y = y1; mH.V.z = z1;
392 x = x1; y = y1; z = z1;
395 } while (hv2.Next());
397 // printf("%d entries in TPChits \n",count);
401 TTree* treeh = pRunLoader->GetTreeH(det.name, false);
403 WarnCaller(eH + "no hits for "+ det.name +".");
406 TClonesArray *arr = new TClonesArray(det.hitbranch);
407 treeh->SetBranchAddress(det.name, &arr);
408 Int_t np = treeh->GetEntries();
409 // in TreeH files hits are grouped in clones arrays
410 // each eva particle has its own clone array
411 for (Int_t i=0; i<np; i++) {
413 Int_t eva_idx = np -i -1;
414 Int_t nh=arr->GetEntriesFast();
416 // printf("%d entry %d hits for primary %d \n", i, nh, eva_idx);
417 for (Int_t j=0; j<nh; j++) {
418 AliHit* ali_hit = (AliHit*)arr->UncheckedAt(j);
419 mH.det_id = det.detidx;
421 mH.label = ali_hit->GetTrack();
422 mH.eva_label = eva_idx;
423 mH.V.Set(ali_hit->X(), ali_hit->Y(), ali_hit->Z());
424 if(det.detidx == 2) {
425 x1=ali_hit->X();y1=ali_hit->Y();z1=ali_hit->Z();
426 if((x-x1)*(x-x1)+(y-y1)*(y-y1)+(z-z1)*(z-z1) < trd_sqr_res) continue;
441 for(map<Int_t, Int_t>::iterator j=hmap.begin(); j!=hmap.end(); ++j) {
442 GetGeninfo(j->first)->n_hits += j->second;
447 /**************************************************************************/
449 /**************************************************************************/
451 void VSDCreator::ConvertClusters()
453 static const Exc_t eH("VSDCreator::ConvertClusters ");
456 throw(eH + "clusters already converted.");
459 mTreeC = new TTree("Clusters", "rec clusters");
460 mTreeC->Branch("C", "Reve::Cluster", &mpC, fBuffSize);
463 ConvertITSClusters();
464 } catch(Exc_t& exc) { WarnCaller(exc); }
467 ConvertTPCClusters();
468 } catch(Exc_t& exc) { WarnCaller(exc); }
471 /**************************************************************************/
473 void VSDCreator::ConvertTPCClusters()
475 static const Exc_t eH("VSDCreator::ConvertTPCClusters ");
478 ( TFile::Open(Form("%s/TPC.RecPoints.root", mDataDir.Data())) );
480 throw(eH + "can not open 'TPC.RecPoints.root' file.");
482 auto_ptr<TDirectory> d
483 ( (TDirectory*) f->Get(Form("Event%d", mEvent)) );
485 throw(eH + Form("event directory '%d' not found.", 0));
487 auto_ptr<TTree> tree( (TTree*) d->Get("TreeR") );
489 throw(eH + "'TreeR' not found.");
491 auto_ptr<AliTPCParam> par( GetTpcParam(eH) );
493 AliTPCClustersRow clrow, *_clrow=&clrow;
495 _clrow->SetClass("AliTPCclusterMI");
496 tree->SetBranchAddress("Segment", &_clrow);
500 Int_t n_ent = tree->GetEntries();
501 for (Int_t n=0; n<n_ent; n++) {
503 nClusters += _clrow->GetArray()->GetEntriesFast();
506 // calculate xyz for a cluster and add it to container
509 map<Int_t, Int_t> cmap;
511 for (Int_t n=0; n<tree->GetEntries(); n++) {
513 Int_t ncl = _clrow->GetArray()->GetEntriesFast();
516 par->AdjustSectorRow(_clrow->GetID(),sec,row);
518 if(_clrow->GetArray()) {
519 // cl = new AliTPCclusterMI(*(AliTPCclusterMI*)_clrow->GetArray()->UncheckedAt(ncl));
520 cl = (AliTPCclusterMI*)_clrow->GetArray()->UncheckedAt(ncl);
521 if(cl->GetLabel(0) >= 0){
522 x = par->GetPadRowRadii(sec,row); y = cl->GetY(); z = cl->GetZ();
523 par->AdjustCosSin(sec,cs,sn);
524 tmp = x*cs-y*sn; y= x*sn+y*cs; x=tmp;
528 mC.label[0] = cl->GetLabel(0);
529 mC.label[1] = cl->GetLabel(1);
530 mC.label[2] = cl->GetLabel(2);
535 while(i < 3 && mC.label[i])
536 cmap[mC.label[i++]]++;
544 for(map<Int_t, Int_t>::iterator j=cmap.begin(); j!=cmap.end(); ++j) {
545 GetGeninfo(j->first)->n_clus += j->second;
549 /**************************************************************************/
551 void VSDCreator::ConvertITSClusters()
553 static const Exc_t eH("VSDCreator::ConvertITSClusters ");
556 ( TFile::Open(Form("%s/ITS.RecPoints.root", mDataDir.Data())) );
558 throw(eH + "can not open 'ITS.RecPoints.root' file.");
560 auto_ptr<TDirectory> d
561 ( (TDirectory*) f->Get(Form("Event%d", mEvent)) );
563 throw(eH + Form("event directory '%d' not found.", 0));
565 auto_ptr<TTree> tree( (TTree*) d->Get("TreeR") );
567 throw(eH + "'TreeR' not found.");
569 AliITSLoader* ITSld = (AliITSLoader*) pRunLoader->GetLoader("ITSLoader");
570 //AliITS* pITS = ITSld->GetITS();
571 AliITSgeom* geom = ITSld->GetITSgeom();
572 //AliITSgeom* geom = new AliITSgeom();
573 //geom->ReadNewFile("/home/aljam/ITSgeometry.det");
575 //printf("alice ITS geom %p \n",geom );
578 throw(eH + "can not find ITS geometry");
580 TClonesArray *arr = new TClonesArray("AliITSclusterV2");
581 tree->SetBranchAddress("Clusters", &arr);
582 Int_t nmods = tree->GetEntries();
584 map<Int_t, Int_t> cmap;
586 for (Int_t mod=0; mod<nmods; mod++) {
588 Int_t nc=arr->GetEntriesFast();
589 for (Int_t j=0; j<nc; j++) {
590 AliITSclusterV2* recp = (AliITSclusterV2*)arr->UncheckedAt(j);
593 geom->GetRotMatrix(mod,rot);
595 geom->GetModuleId(mod,lay,lad,det);
597 geom->GetTrans(lay,lad,det,tx,ty,tz);
599 Double_t alpha=TMath::ATan2(rot[1],rot[0])+TMath::Pi();
600 Double_t phi1=TMath::Pi()/2+alpha;
601 if(lay==1) phi1+=TMath::Pi();
603 Float_t cp=TMath::Cos(phi1), sp=TMath::Sin(phi1);
604 Float_t r=tx*cp+ty*sp;
605 gc[0]= r*cp - recp->GetY()*sp;
606 gc[1]= r*sp + recp->GetY()*cp;
611 mC.label[0] = recp->GetLabel(0);
612 mC.label[1] = recp->GetLabel(1);
613 mC.label[2] = recp->GetLabel(2);
614 mC.V.x = r*cp - recp->GetY()*sp;
615 mC.V.y = r*sp + recp->GetY()*cp;
616 mC.V.z = recp->GetZ();
619 while(i < 3 && mC.label[i])
620 cmap[mC.label[i++]]++;
624 for(map<Int_t, Int_t>::iterator j=cmap.begin(); j!=cmap.end(); ++j) {
625 GetGeninfo(j->first)->n_clus += j->second;
631 /**************************************************************************/
633 /**************************************************************************/
635 void VSDCreator::ConvertRecTracks()
637 static const Exc_t eH("VSDCreator::ConvertRecTracks ");
640 throw(eH + "tracks already converted.");
643 mTreeR = new TTree("RecTracks", "rec tracks");
645 mTreeR->Branch("R", "Reve::RecTrack", &mpR, 512*1024,1);
647 TFile f(Form("%s/AliESDs.root", mDataDir.Data()));
649 throw(eH + "no AliESDs.root file.");
651 TTree* tree = (TTree*) f.Get("esdTree");
653 throw(eH + "no esdTree.");
657 tree->SetBranchAddress("ESD", &fEvent);
658 tree->GetEntry(mEvent);
661 // reconstructed tracks
664 for (Int_t n=0; n<fEvent->GetNumberOfTracks(); n++) {
665 esd_t = fEvent->GetTrack(n);
667 mR.label = esd_t->GetLabel();
668 mR.status = (Int_t) esd_t->GetStatus();
669 mR.sign = (Int_t) esd_t->GetSign();
670 esd_t->GetXYZ(dbuf); mR.V.Set(dbuf);
671 esd_t->GetPxPyPz(dbuf); mR.P.Set(dbuf);
672 Double_t ep = esd_t->GetP();
673 mR.beta = ep/TMath::Sqrt(ep*ep + TMath::C()*TMath::C()*esd_t->GetMass()*esd_t->GetMass());
676 mTreeR->BuildIndex("label");
679 /**************************************************************************/
681 void VSDCreator::ConvertV0()
683 static const Exc_t eH("VSDCreator::ConvertV0 ");
686 throw(eH + "V0 already converted.");
689 mTreeV0 = new TTree("V0", "V0 points");
691 mTreeV0->Branch("V0", "Reve::RecV0", &mpV0, 512*1024,1);
693 TFile f(Form("%s/AliESDs.root", mDataDir.Data()));
695 throw(eH + "no AliESDs.root file.");
698 TTree* tree = (TTree*) f.Get("esdTree");
700 throw(eH + "no esdTree.");
703 tree->SetBranchAddress("ESD", &fEvent);
704 tree->GetEntry(mEvent);
706 for (Int_t n =0; n< fEvent->GetNumberOfV0MIs(); n++) {
707 AliESDV0MI* av = fEvent->GetV0MI(n);
710 mV0.status = av->GetStatus();
711 // Point of closest approach
712 mV0.V_ca.x = av->GetXr(0);
713 mV0.V_ca.y = av->GetXr(1);
714 mV0.V_ca.z = av->GetXr(2);
715 // set birth vertex of neutral particle
717 av->GetXYZ(p[0], p[1], p[2]);
721 // momentum and position of negative particle
722 mV0.P_neg.Set(av->GetPMp());
723 av->GetParamM()->GetXYZ(pos);
726 // momentum and position of positive particle
727 mV0.P_pos.Set(av->GetPPp());
728 av->GetParamP()->GetXYZ(pos);
731 mV0.label = 0; // !!!! mother label unknown
732 mV0.pdg = av->GetPdgCode();
734 mV0.d_label[0] = av->GetLab(0);
735 mV0.d_label[1] = av->GetLab(1);
737 // printf("V0 convert labels(%d,%d) index(%d,%d)\n",
738 // av->GetLab(0), av->GetLab(1),
739 // av->GetIndex(0), av->GetIndex(1));
743 // if(fEvent->GetNumberOfV0MIs()) mTreeV0->BuildIndex("label");
746 /**************************************************************************/
748 void VSDCreator::ConvertKinks()
750 static const Exc_t eH("VSDCreator::ConvertKinks ");
753 throw(eH + "Kinks already converted.");
756 mTreeKK = new TTree("Kinks", "ESD Kinks");
758 mTreeKK->Branch("KK", "Reve::RecKink", &mpKK, fBuffSize);
760 TFile f(Form("%s/AliESDs.root", mDataDir.Data()));
762 throw(eH + "no AliESDs.root file.");
765 TTree* tree = (TTree*) f.Get("esdTree");
767 throw(eH + "no esdTree.");
770 tree->SetBranchAddress("ESD", &fEvent);
771 tree->GetEntry(mEvent);
773 // printf("CONVERT KINK Read %d entries in tree kinks \n", fEvent->GetNumberOfKinks());
774 for (Int_t n =0; n< fEvent->GetNumberOfKinks(); n++) {
775 AliESDkink* kk = fEvent->GetKink(n);
780 mKK.label = kk->GetLabel(0);
781 mKK.status = Int_t(kk->GetStatus(1) << 8 + kk->GetStatus(2));
783 // reconstructed kink position
784 mKK.label_sec = kk->GetLabel(1);
785 mKK.V_kink.Set(kk->GetPosition());
787 const AliExternalTrackParam& tp_mother = kk->RefParamMother();
788 // momentum and position of mother
789 tp_mother.GetPxPyPz(pos);
791 tp_mother.GetXYZ(pos);
793 const Double_t* par = tp_mother.GetParameter();
794 // printf("KINK Pt %f, %f \n",1/tp_mother.Pt(),par[4] );
795 mKK.sign = (par[4] < 0) ? -1 : 1;
797 const AliExternalTrackParam& tp_daughter = kk->RefParamDaughter();
798 // momentum and position of daughter
799 tp_daughter.GetPxPyPz(pos);
801 tp_daughter.GetXYZ(pos);
806 if(fEvent->GetNumberOfKinks()) mTreeKK->BuildIndex("label");
808 /**************************************************************************/
810 /**************************************************************************/
812 void VSDCreator::ConvertGenInfo()
814 static const Exc_t eH("VSDCreator::ConvertGenInfo ");
817 throw(eH + "GI already converted.");
820 mTreeGI = new TTree("GenInfo", "Objects prepared for cross querry");
822 GenInfo::Class()->IgnoreTObjectStreamer(true);
823 mTreeGI->Branch("GI", "Reve::GenInfo", &mpGI, fBuffSize);
824 mTreeGI->Branch("K.", "Reve::MCTrack", &mpK);
825 mTreeGI->Branch("R.", "Reve::RecTrack", &mpR);
827 for(map<Int_t, GenInfo*>::iterator j=mGenInfoMap.begin(); j!=mGenInfoMap.end(); ++j) {
829 mGI.label = j->first;
830 mTreeK->GetEntry(j->first);
833 Int_t re = mTreeR->GetEntryNumberWithIndex(j->first);
837 // Int_t has_v0 = mTreeV0->GetEntryNumberWithIndex(j->first);
839 // mGI.has_V0 = true;
841 Int_t has_kk = mTreeKK->GetEntryNumberWithIndex(j->first);
850 /**************************************************************************/
851 /**************************************************************************/
853 /**************************************************************************/
854 /**************************************************************************/
856 AliTPCParam* VSDCreator::GetTpcParam(const Exc_t& eh)
858 auto_ptr<TFile> fp( TFile::Open(Form("%s/galice.root", mDataDir.Data())) );
860 throw(eh + "can not open 'galice.root' file.");
861 AliTPCParam* par = (AliTPCParam *) fp->Get("75x40_100x60_150x60");
863 throw(eh + "TPC data not found.");
869 GenInfo* VSDCreator::GetGeninfo(Int_t label)
871 // printf("get_geninfo %d\n", label);
873 map<Int_t, GenInfo*>::iterator i = mGenInfoMap.find(label);
874 if(i == mGenInfoMap.end()) {
876 mGenInfoMap[label] = gi;