Too wide range for charge.
[u/mrichter/AliRoot.git] / HMPID / HESDfromKin.C
CommitLineData
d8770a0f 1AliRunLoader *gAL=0;
2Int_t gEvt=0; Int_t gMaxEvt=0;
3df18479 3TObjArray *pNmean,*pQthre;
d8770a0f 4TTree *gEsdTr;
5//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
e4290ede 6void HESDfromKin(const char *name="default")
d8770a0f 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();
6e06db1d 18 AliESDEvent *pEsd = new AliESDEvent();
d8770a0f 19 TFile *pEsdFl=TFile::Open("AliESDs.root","recreate");
20 gEsdTr=new TTree("esdTree","Sim ESD from kinematics");
e4290ede 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
d8770a0f 25 } else return;
26
3df18479 27 if(!OpenCalib()) {Printf("Problems in OpenCalib!Bye.");return;}
d8770a0f 28
c0d7adf8 29 TString ttl=name;
30 Bool_t htaCheck=ttl.Contains("HTA");
31 if(!htaCheck) SimEsd(pHL,pEsd); else SimEsdHidden(pHL,pEsd);
e4290ede 32
33 pEsdFl->cd();
d8770a0f 34 pEsdFl->Write();pEsdFl->Close();
35}
36//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6e06db1d 37void SimEsd(AliLoader *pHL,AliESDEvent *pEsd)
d8770a0f 38{
c0d7adf8 39 Printf("-----------------------------------------------");
40 Printf("| SimESD: Utility to embed ESD from kinematics|");
41 Printf("-----------------------------------------------");
d8770a0f 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
e4290ede 56 AliESDtrack trk(pTrack);
d8770a0f 57 pEsd->AddTrack(&trk);
3df18479 58 AliHMPIDTracker::Recon(pEsd,pH->CluLst(),pNmean,pQthre);
d8770a0f 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();
3b49956b 66}//Esd()
d8770a0f 67//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6e06db1d 68void SimEsdHidden(AliLoader *pHL,AliESDEvent *pEsd)
3b49956b 69{
3df18479 70 TH1F *hdC = new TH1F("dC","dC",100,-0.2,0.2);
71 TH1F *hCer = new TH1F("Cer","Cer",250,0.,0.75);
72 TH2F *htvsp = new TH2F("tvsp","tvsp",100,0.,5.,1000,0.,0.75);
3b49956b 73 Double_t rd=TMath::RadToDeg();
c0d7adf8 74 Printf("----------------------------------------------");
75 Printf("| SimHTA:Utility to embed ESD from kinematics|");
76 Printf("| with Hidden Track Algorithm (HTA) |");
77 Printf("----------------------------------------------");
d8770a0f 78 AliHMPIDTracker::SetFieldMap(gAL->GetAliRun()->Field(),kTRUE);
79 AliHMPID *pH=(AliHMPID*)gAL->GetAliRun()->GetDetector("HMPID");
80 Int_t mtid=-1;
81 Int_t iNevt=gAL->GetNumberOfEvents();
82 Printf("Number of events to process: %i",iNevt);
83 for(Int_t iEvt=0;iEvt<iNevt;iEvt++){//events loop
84 if(!(iEvt%50)) Printf("Events processed %i",iEvt);
3b49956b 85 gAL->GetEvent(iEvt);
d8770a0f 86 pHL->TreeR()->GetEntry(0);
3b49956b 87 AliStack *pStack=gAL->Stack();
88 for(Int_t i=0;i<pStack->GetNtrack();i++){
89 TParticle *pTrack=pStack->Particle(i);
90 mtid=pTrack->GetFirstMother();
91 if(mtid>=0) continue; // only primaries
92 //find the chamber that intersects HMPID
93 AliESDtrack trk(pTrack);
94 Float_t xPc,yPc;
95 Int_t iCh=AliHMPIDTracker::IntTrkCha(&trk,xPc,yPc); //get chamber intersected by this track
96 if(iCh<0) continue; //no intersection at all, go after next track
97 Float_t radX,radY,thetaTrk,phiTrk;
98 trk.GetHMPIDtrk(radX,radY,thetaTrk,phiTrk);
3df18479 99// Printf("simulated track theta %f phi %f",thetaTrk*rd,phiTrk*rd);
3b49956b 100 TObjArray *pClus = pH->CluLst();
3df18479 101 if(AliHMPIDTracker::ReconHiddenTrk(iCh,&trk,(TClonesArray *)pClus->At(iCh),pNmean,pQthre)!=0) continue;
3b49956b 102 trk.GetHMPIDtrk(radX,radY,thetaTrk,phiTrk);
3df18479 103// Printf("reconstr. track theta %f phi %f",thetaTrk*rd,phiTrk*rd);
3b49956b 104 pEsd->AddTrack(&trk);
105 Double_t thetaCerSim = TMath::ACos(pTrack->Energy()/(1.292*pTrack->P()));
3df18479 106// Printf(" theta Cerenkov simulated %f",thetaCerSim);
107// Printf(" theta Cerenkov reconstructed %f",trk.GetHMPIDsignal());
108 hdC->Fill(trk.GetHMPIDsignal()-thetaCerSim);
109 hCer->Fill(trk.GetHMPIDsignal());
110 htvsp->Fill(pTrack->P(),trk.GetHMPIDsignal());
3b49956b 111 }// track loop
d8770a0f 112 pEsd->SetMagneticField(AliHMPIDTracker::GetBz());
113 gEsdTr->Fill();
114 pEsd->Reset();
115 }// event loop
116 Printf("Events processed %i",iEvt);
117 gAL->UnloadHeader(); gAL->UnloadKinematics();
3b49956b 118}//EsdHidden()
d8770a0f 119//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3df18479 120Bool_t OpenCalib()
d8770a0f 121{
122 AliCDBManager* pCDB = AliCDBManager::Instance();
123 pCDB->SetDefaultStorage("local://$HOME");
124 AliCDBEntry *pQthreEnt=pCDB->Get("HMPID/Calib/Qthre",0);
125 AliCDBEntry *pNmeanEnt=pCDB->Get("HMPID/Calib/Nmean",0);
126
3df18479 127 if(!pQthreEnt || !pNmeanEnt) return kFALSE;
d8770a0f 128
129 pNmean=(TObjArray*)pNmeanEnt->GetObject();
3df18479 130 pQthre=(TObjArray*)pQthreEnt->GetObject();
131
132 if(!pQthre || !pNmean) return kFALSE;
133 return kTRUE;
d8770a0f 134}
135//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++