]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HMPID/HESDfromKin.C
minors
[u/mrichter/AliRoot.git] / HMPID / HESDfromKin.C
1 AliRunLoader *gAL=0; 
2 Int_t gEvt=0; Int_t gMaxEvt=0;
3 TObjArray *pNmean,*pQthre;
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   if(!OpenCalib()) {Printf("Problems in OpenCalib!Bye.");return;}
28     
29   TString ttl=name;
30   Bool_t htaCheck=ttl.Contains("HTA");
31 //  if(!htaCheck) SimEsd(pHL,pEsd); else SimEsdHidden(pHL,pEsd);
32   SimEsd(pHL,pEsd,htaCheck);
33   
34   pEsdFl->cd();
35   pEsdFl->Write();pEsdFl->Close();        
36 }
37 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
38 void SimEsd(AliLoader *pHL,AliESDEvent *pEsd,Bool_t htaCheck)
39 {
40   if(htaCheck) {
41     TFile *fout = new TFile("HTA.root","recreate");
42     TH1F *hdC   = new TH1F("dC"  ,";delta Cerenkov (rad)",100,-0.2,0.2);
43     TH1F *hCer  = new TH1F("Cer" ,"Theta Cerenkov (rad)",250,0.,0.75);
44     TH2F *htvsp = new TH2F("tvsp",";momentum (GeV/c);theta Cerenkov (rad)",100,0.,5.,1000,0.,0.75);
45     TH1F *hdth  = new TH1F("dth" ,";Delta theta Trk (mrad)",100,-250,250);
46     TH1F *hdph  = new TH1F("dph" ,";Delta phi Trk (mrad)",100,-500,500);
47     Double_t rd=TMath::RadToDeg();
48     Printf("----------------------------------------------");
49     Printf("| SimHTA:Utility to embed ESD from kinematics|");
50     Printf("|     with  Hidden Track Algorithm (HTA)     |");
51     Printf("----------------------------------------------");
52   } else {
53     Printf("-----------------------------------------------");
54     Printf("| SimESD: Utility to embed ESD from kinematics|");
55     Printf("-----------------------------------------------");
56 }
57   AliHMPIDTracker::SetFieldMap(gAL->GetAliRun()->Field(),kTRUE);
58   AliHMPIDTracker pTracker;
59   AliHMPID *pH=(AliHMPID*)gAL->GetAliRun()->GetDetector("HMPID");
60   Int_t iNevt=gAL->GetNumberOfEvents();
61   pEsd->SetMagneticField(AliHMPIDTracker::GetBz());
62   for(Int_t iEvt=0;iEvt<iNevt;iEvt++){//events loop
63     gAL->GetEvent(iEvt);    
64     pHL->TreeR()->GetEntry(0);
65     AliStack *pStack=gAL->Stack();
66     Int_t nTrkHMPID=0;
67     for(Int_t i=0;i<pStack->GetNtrack();i++){
68       if(!pStack->IsPhysicalPrimary(i)) continue;
69       TParticle *pTrack=pStack->Particle(i); 
70       if(pTrack->GetPDG()->Charge()==0) continue;
71       AliESDtrack trk(pTrack); 
72       Float_t xPc,yPc,xRa,yRa,thRa,phRa;
73       Int_t iCh=pTracker.IntTrkCha(&trk,xPc,yPc,xRa,yRa,thRa,phRa);         //get chamber intersected by this track 
74       if(iCh<0) {
75         trk.SetHMPIDtrk(0,0,0,0);                                                                //no intersection found
76         trk.SetHMPIDcluIdx   (99,99999);                                                         //chamber not found, mip not yet considered
77         trk.SetHMPIDsignal(AliHMPIDRecon::kNotPerformed);                                        //ring reconstruction not yet performed
78         continue;                                                           //no intersection at all, go after next track
79       }
80       nTrkHMPID++;
81       trk.SetHMPIDcluIdx   (iCh,99999);                                                          //chamber not found, mip not yet considered
82       
83       if(phRa<0) phRa += TMath::TwoPi(); // to be verified
84       
85       trk.SetHMPIDtrk(xRa,yRa,thRa,phRa);                                                        //store initial infos
86       pEsd->AddTrack(&trk);
87     
88   //    if(!(iEvt%50)) Printf("Number of events processed: %i with tracks %i in HMPID",iEvt,nTrkHMPID);
89       Printf("Number of events processed: %i with tracks %i in HMPID",iEvt,nTrkHMPID);
90
91       Int_t status;
92       if(!htaCheck) status = pTracker.Recon         (pEsd,pH->CluLst(),pNmean,pQthre);
93       else          status = pTracker.ReconHiddenTrk(pEsd,pH->CluLst(),pNmean,pQthre);
94
95       Printf("status %i",status);
96       if(status !=0) continue;
97
98     
99     }// track loop
100     gEsdTr->Fill();
101     pEsd->Reset();
102   }// event loop
103   Printf("Events processed %i",iEvt);
104   if(htaCheck) {
105     fout->Write();
106     fout->Close();
107     delete fout;
108   }
109   gAL->UnloadHeader();  gAL->UnloadKinematics();
110 }//SimEsd()
111 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
112 Bool_t OpenCalib()
113 {
114   AliCDBManager* pCDB = AliCDBManager::Instance();
115   pCDB->SetDefaultStorage("local://$HOME");
116   AliCDBEntry *pQthreEnt=pCDB->Get("HMPID/Calib/Qthre",0);
117   AliCDBEntry *pNmeanEnt=pCDB->Get("HMPID/Calib/Nmean",0);
118   
119   if(!pQthreEnt || !pNmeanEnt) return kFALSE;
120   
121   pNmean=(TObjArray*)pNmeanEnt->GetObject(); 
122   pQthre=(TObjArray*)pQthreEnt->GetObject(); 
123
124   if(!pQthre || !pNmean) return kFALSE;  
125   return kTRUE;
126 }
127 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++