Fixes to calls for MeanMaterialBudget (now in AliTracker) (From Jouri Belikov)
[u/mrichter/AliRoot.git] / HMPID / HESDfromKin.C
1 AliRunLoader *gAL=0; 
2 Int_t gEvt=0; Int_t gMaxEvt=0;
3 TObjArray *pNmean;
4 TTree *gEsdTr;
5 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6 void HESDfromKin(const char *name="default")
7 {//simulate ESD from kinematics
8
9   if(gSystem->IsFileInIncludePath("galice.root")){// tries to open session
10     if(gAlice) delete gAlice;                                               //in case we execute this in aliroot delete default AliRun object 
11     gAL=AliRunLoader::Open();                                                                    //try to open galice.root from current dir 
12     gAL->LoadgAlice();                                                                           //take new AliRun object from galice.root   
13     if(gAL->LoadHeader()) return;
14     if(gAL->LoadKinematics()) return;
15
16     AliLoader *pHL=gAL->GetDetectorLoader("HMPID");
17     pHL->LoadRecPoints();
18     AliESDEvent *pEsd = new AliESDEvent();   
19     TFile *pEsdFl=TFile::Open("AliESDs.root","recreate"); 
20     gEsdTr=new TTree("esdTree","Sim ESD from kinematics"); 
21     pEsd->CreateStdContent();    pEsd->WriteToTree(gEsdTr);  //clm: new ESD write schema: see Task Force meeting 20th June, 2007
22     gEsdTr->GetUserInfo()->Add(pEsd);                        //clm: TList has to be created for ReadFromTree method -- this was not needed by the old ESD
23  
24        
25   }  else return;  
26
27   OpenCalib();
28     
29   TString ttl=name;
30   Bool_t htaCheck=ttl.Contains("HTA");
31   if(!htaCheck) SimEsd(pHL,pEsd); else SimEsdHidden(pHL,pEsd);
32   
33   pEsdFl->cd();
34   pEsdFl->Write();pEsdFl->Close();        
35 }
36 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
37 void SimEsd(AliLoader *pHL,AliESDEvent *pEsd)
38 {
39   Printf("-----------------------------------------------");
40   Printf("| SimESD: Utility to embed ESD from kinematics|");
41   Printf("-----------------------------------------------");
42   AliHMPIDTracker::SetFieldMap(gAL->GetAliRun()->Field(),kTRUE);
43   AliHMPID *pH=(AliHMPID*)gAL->GetAliRun()->GetDetector("HMPID");
44   Int_t mtid=-1;
45   Int_t iNevt=gAL->GetNumberOfEvents();
46   Printf("Number of events to process: %i",iNevt);
47   for(Int_t iEvt=0;iEvt<iNevt;iEvt++){//events loop
48     if(!(iEvt%50)) Printf("Events processed %i",iEvt);
49     gAL->GetEvent(iEvt);    
50     pHL->TreeR()->GetEntry(0);
51     AliStack *pStack=gAL->Stack();
52     for(Int_t i=0;i<pStack->GetNtrack();i++){
53       TParticle *pTrack=pStack->Particle(i); 
54       mtid=pTrack->GetFirstMother();
55       if(mtid>=0) continue; // only primaries
56       AliESDtrack trk(pTrack); 
57       pEsd->AddTrack(&trk);
58       AliHMPIDTracker::Recon(pEsd,pH->CluLst(),pNmean);
59     }// track loop
60     pEsd->SetMagneticField(AliHMPIDTracker::GetBz());
61     gEsdTr->Fill();
62     pEsd->Reset();
63   }// event loop
64   Printf("Events processed %i",iEvt);
65   gAL->UnloadHeader();  gAL->UnloadKinematics();
66 }//Esd()
67 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
68 void SimEsdHidden(AliLoader *pHL,AliESDEvent *pEsd)
69 {
70   Double_t rd=TMath::RadToDeg();
71   Printf("----------------------------------------------");
72   Printf("| SimHTA:Utility to embed ESD from kinematics|");
73   Printf("|     with  Hidden Track Algorithm (HTA)     |");
74   Printf("----------------------------------------------");
75   AliHMPIDTracker::SetFieldMap(gAL->GetAliRun()->Field(),kTRUE);
76   AliHMPID *pH=(AliHMPID*)gAL->GetAliRun()->GetDetector("HMPID");
77   Int_t mtid=-1;
78   Int_t iNevt=gAL->GetNumberOfEvents();
79   Printf("Number of events to process: %i",iNevt);
80   for(Int_t iEvt=0;iEvt<iNevt;iEvt++){//events loop
81     if(!(iEvt%50)) Printf("Events processed %i",iEvt);
82     gAL->GetEvent(iEvt);    
83     pHL->TreeR()->GetEntry(0);
84     AliStack *pStack=gAL->Stack();
85     for(Int_t i=0;i<pStack->GetNtrack();i++){
86       TParticle *pTrack=pStack->Particle(i); 
87       mtid=pTrack->GetFirstMother();
88       if(mtid>=0) continue; // only primaries
89       //find the chamber that intersects HMPID
90       AliESDtrack trk(pTrack);
91       Float_t xPc,yPc;
92       Int_t iCh=AliHMPIDTracker::IntTrkCha(&trk,xPc,yPc);                           //get chamber intersected by this track 
93       if(iCh<0) continue;                                                           //no intersection at all, go after next track
94       Float_t radX,radY,thetaTrk,phiTrk;
95       trk.GetHMPIDtrk(radX,radY,thetaTrk,phiTrk);
96       Printf("simulated track theta %f phi %f",thetaTrk*rd,phiTrk*rd);
97       TObjArray *pClus = pH->CluLst();
98       if(AliHMPIDTracker::ReconHiddenTrk(iCh,&trk,(TClonesArray *)pClus->At(iCh),pNmean)!=0) continue;
99       trk.GetHMPIDtrk(radX,radY,thetaTrk,phiTrk);
100       Printf("reconstr. track theta %f phi %f",thetaTrk*rd,phiTrk*rd);
101       pEsd->AddTrack(&trk);
102       Double_t thetaCerSim = TMath::ACos(pTrack->Energy()/(1.292*pTrack->P()));
103       Printf(" theta Cerenkov simulated     %f",thetaCerSim);
104       Printf(" theta Cerenkov reconstructed %f",trk.GetHMPIDsignal());
105     }// track loop
106     pEsd->SetMagneticField(AliHMPIDTracker::GetBz());
107     gEsdTr->Fill();
108     pEsd->Reset();
109   }// event loop
110   Printf("Events processed %i",iEvt);
111   gAL->UnloadHeader();  gAL->UnloadKinematics();
112 }//EsdHidden()
113 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
114 void OpenCalib()
115 {
116   AliCDBManager* pCDB = AliCDBManager::Instance();
117   pCDB->SetDefaultStorage("local://$HOME");
118   AliCDBEntry *pQthreEnt=pCDB->Get("HMPID/Calib/Qthre",0);
119   AliCDBEntry *pNmeanEnt=pCDB->Get("HMPID/Calib/Nmean",0);
120   
121   if(!pQthreEnt || ! pNmeanEnt) return;
122   
123   pNmean=(TObjArray*)pNmeanEnt->GetObject(); 
124 }
125 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++