New on per RCU data containers
[u/mrichter/AliRoot.git] / HMPID / Hdisp.C
CommitLineData
8282f9d0 1TCanvas *pAll=0;
2AliRunLoader *gAL=0; AliLoader *gHL=0; AliESD *gEsd=0; TTree *gEsdTr=0; AliHMPID *gH=0;
3Int_t gEvt=0; Int_t gMaxEvt=0;
4//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5void Hdisp()
6{//display events from files if any in current directory or simulated events
6ed6a312 7 pAll=new TCanvas("all","",1000,900); pAll->Divide(3,3,0,0);pAll->ToggleEditor();
8282f9d0 8 pAll->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)",0,"","DoZoom(Int_t,Int_t,Int_t,TObject*)");
9
10 if(gSystem->IsFileInIncludePath("galice.root")){// tries to open session
11 if(gAlice) delete gAlice; //in case we execute this in aliroot delete default AliRun object
12 gAL=AliRunLoader::Open(); //try to open galice.root from current dir
13 gAL->LoadgAlice(); //take new AliRun object from galice.root
14 gHL=gAL->GetDetectorLoader("HMPID"); gH=(AliHMPID*)gAL->GetAliRun()->GetDetector("HMPID"); //get HMPID object from galice.root
15 gMaxEvt=gAL->GetNumberOfEvents()-1;
d73ece6a 16 gHL->LoadHits(); gHL->LoadSDigits(); gHL->LoadDigits(); gHL->LoadRecPoints();
8282f9d0 17
18 TFile *pEsdFl=TFile::Open("AliESDs.root"); gEsdTr=(TTree*) pEsdFl->Get("esdTree"); gEsdTr->SetBranchAddress("ESD", &gEsd);
19 pAll->cd(7); TButton *pBtn=new TButton("Next","ReadEvt()",0,0,0.2,0.1); pBtn->Draw();
d73ece6a 20 TButton *pHitBtn=new TButton("Print hits","PrintHits()",0,0.2,0.3,0.3); pHitBtn->Draw();
21 TButton *pSdiBtn=new TButton("Print sdis","PrintSdis()",0,0.4,0.3,0.5); pSdiBtn->Draw();
22 TButton *pDigBtn=new TButton("Print digs","PrintDigs()",0,0.6,0.3,0.7); pDigBtn->Draw();
23 TButton *pCluBtn=new TButton("Print clus","PrintClus()",0,0.8,0.3,0.9); pCluBtn->Draw();
8282f9d0 24 ReadEvt();
25 }else{
26 pAll->cd(7); TButton *pBtn=new TButton("Next","SimEvt()",0,0,0.2,0.1); pBtn->Draw();
27 SimEvt();
28 }
29}
30//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31void ReadEvt()
32{// Read curent event and display it assumes that session is alredy opened
33 TClonesArray hits("AliHMPIDHit");
34 if(gEvt>gMaxEvt) gEvt=0; if(gEvt<0) gEvt=gMaxEvt;
35
36 gEsdTr->GetEntry(gEvt); gAL->GetEvent(gEvt);
d73ece6a 37 ReadHits(&hits); gHL->TreeS()->GetEntry(0); gHL->TreeD()->GetEntry(0); gHL->TreeR()->GetEntry(0);
38
8282f9d0 39
8282f9d0 40 DrawEvt(&hits,gH->DigLst(),gH->CluLst(),gEsd);
41 gEvt++;
42}
43//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
44void SimEvt()
45{
46 TClonesArray hits("AliHMPIDHit");
47 TClonesArray sdig("AliHMPIDDigit");
48 TObjArray digs(7); for(Int_t i=0;i<7;i++) digs.AddAt(new TClonesArray("AliHMPIDDigit"),i);
49 TObjArray clus(7); for(Int_t i=0;i<7;i++) clus.AddAt(new TClonesArray("AliHMPIDCluster"),i);
50 AliESD esd;
51
52 SimEsd(&esd);
53 SimHits(&esd,&hits);
54 AliHMPIDv1::Hit2Sdi(&hits,&sdig);
55 AliHMPIDDigitizer::Sdi2Dig(&sdig,&digs);
56 AliHMPIDReconstructor::Dig2Clu(&digs,&clus);
57 AliHMPIDTracker::Recon(&esd,&clus);
58
59 pAll->cd(3); gPad->Clear(); TLatex txt;txt.DrawLatex(0.2,0.2,Form("Simulated event %i",gEvt));
60 DrawEvt(&hits,&digs,&clus,&esd);
61 gEvt++;
62}//SimEvt()
a1d55ff3 63//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
64void SimEsd(AliESD *pEsd)
65{
66 TParticle part; TLorentzVector mom;
67 for(Int_t iTrk=0;iTrk<25;iTrk++){//stack loop
68 part.SetPdgCode(kProton);
69 part.SetProductionVertex(0,0,0,0);
70 Double_t eta= -0.4+gRandom->Rndm()*0.8; //rapidity is random [-0.4,+0.4]
71 Double_t phi= gRandom->Rndm()*1.4; //phi is random [ 0 , 80 ] degrees
72 mom.SetPtEtaPhiM(2,eta,phi,part.GetMass());
73 part.SetMomentum(mom);
74 AliESDtrack trk(&part);
75 pEsd->AddTrack(&trk);
76 }//stack loop
77}//EsdFromStack()
78//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8282f9d0 79void SimHits(AliESD *pEsd, TClonesArray *pHits)
a1d55ff3 80{
f3bae3e2 81 const Int_t kCerenkov=AliHMPIDParam::CkovCode();
82 const Int_t kFeedback=AliHMPIDParam::FeedCode();
83
a1d55ff3 84 AliHMPIDRecon rec;
f3bae3e2 85
a1d55ff3 86 Int_t hc=0; TVector2 pos;
87 for(Int_t iTrk=0;iTrk<pEsd->GetNumberOfTracks();iTrk++){//tracks loop
88 AliESDtrack *pTrk=pEsd->GetTrack(iTrk);
89 Float_t xRa,yRa;
90 Int_t ch=AliHMPIDTracker::IntTrkCha(pTrk,xRa,yRa);
91 if(ch<0) continue; //this track does not hit HMPID
92 Float_t ckov=0.63;
93
94 Float_t th,ph,xPc,yPc,; pTrk->GetHMPIDtrk(xPc,yPc,th,ph); rec.SetTrack(xRa,yRa,th,ph);
95
8282f9d0 96 if(!AliHMPIDDigit::IsInDead(xPc,yPc)) new((*pHits)[hc++]) AliHMPIDHit(ch,200e-9,kProton ,iTrk,xPc,yPc); //mip hit
97 for(int i=0;i<4;i++) new((*pHits)[hc++]) AliHMPIDHit(ch,7.5e-9,kFeedback,iTrk,gRandom->Rndm()*130,gRandom->Rndm()*126); //bkg hits 4 per track
a1d55ff3 98 for(int i=0;i<16;i++){
99 rec.TracePhot(ckov,gRandom->Rndm()*TMath::TwoPi(),pos);
8282f9d0 100 new((*pHits)[hc++]) AliHMPIDHit(ch,7.5e-9,kCerenkov,iTrk,pos.X(),pos.Y());
a1d55ff3 101 } //photon hits
102 }//tracks loop
8282f9d0 103}//SimHits()
a1d55ff3 104//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8282f9d0 105void ReadHits(TClonesArray *pHitLst)
a1d55ff3 106{
8282f9d0 107 pHitLst->Delete(); Int_t cnt=0;
108 for(Int_t iEnt=0;iEnt<gHL->TreeH()->GetEntries();iEnt++){ //TreeH loop
109 gHL->TreeH()->GetEntry(iEnt); //get current entry (prim)
110 for(Int_t iHit=0;iHit<gH->Hits()->GetEntries();iHit++){ //hits loop
111 AliHMPIDHit *pHit = (AliHMPIDHit*)gH->Hits()->At(iHit); //get current hit
112 new((*pHitLst)[cnt++]) AliHMPIDHit(*pHit);
113 }//hits loop for this entry
114 }//tree entries loop
115
116}//ReadHits()
a1d55ff3 117//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8282f9d0 118void DrawCh(Int_t iCh)
a1d55ff3 119{
120 gPad->Range(-10,-10,AliHMPIDDigit::SizeAllX()+5,AliHMPIDDigit::SizeAllY()+5);
f3bae3e2 121 if(iCh>=0){TLatex txt; txt.SetTextSize(0.1); txt.DrawLatex(-5,-5,Form("%i",iCh));}
a1d55ff3 122
123 for(Int_t iPc=AliHMPIDDigit::kMinPc;iPc<=AliHMPIDDigit::kMaxPc;iPc++){
124 TBox *pBox=new TBox(AliHMPIDDigit::fMinPcX[iPc],AliHMPIDDigit::fMinPcY[iPc],
125 AliHMPIDDigit::fMaxPcX[iPc],AliHMPIDDigit::fMaxPcY[iPc]);
126
8282f9d0 127 pBox->SetFillStyle(0);
a1d55ff3 128 pBox->Draw();
129
a1d55ff3 130 }//PC loop
8282f9d0 131}//DrawCh()
a1d55ff3 132//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8282f9d0 133void DrawEvt(TClonesArray *pHitLst,TObjArray *pDigLst,TObjArray *pCluLst,AliESD *pEsd)
a1d55ff3 134{//draws all the objects of current event in given canvas
135
136 AliHMPIDRecon rec;
d73ece6a 137 TPolyMarker *pTxC[7], *pRin[7]; TMarker *pMip,*pCko,*pFee,*pDig,*pClu;
138 pMip=new TMarker; pMip->SetMarkerColor(kRed); pMip->SetMarkerStyle(kOpenTriangleUp);
139 pCko=new TMarker; pCko->SetMarkerColor(kRed); pCko->SetMarkerStyle(kOpenCircle);
140 pFee=new TMarker; pFee->SetMarkerColor(kRed); pFee->SetMarkerStyle(kOpenDiamond);
141 pDig=new TMarker; pDig->SetMarkerColor(kGreen);pDig->SetMarkerStyle(kOpenSquare);
142 pClu=new TMarker; pClu->SetMarkerColor(kBlue); pClu->SetMarkerStyle(kStar);
a1d55ff3 143 for(Int_t ch=0;ch<7;ch++){
144 pTxC[ch]=new TPolyMarker; pTxC[ch]->SetMarkerStyle(2); pTxC[ch]->SetMarkerColor(kRed); pTxC[ch]->SetMarkerSize(3);
145 pRin[ch]=new TPolyMarker; pRin[ch]->SetMarkerStyle(6); pRin[ch]->SetMarkerColor(kMagenta);
146 }
147
a1d55ff3 148 for(Int_t iTrk=0;iTrk<pEsd->GetNumberOfTracks();iTrk++){//tracks loop to collect cerenkov rings and intersection points
149 AliESDtrack *pTrk=pEsd->GetTrack(iTrk);
150 Int_t ch=pTrk->GetHMPIDcluIdx();
151 if(ch<0) continue; //this track does not hit HMPID
152 ch/=1000000;
153 Float_t th,ph,xPc,yPc; pTrk->GetHMPIDtrk(xPc,yPc,th,ph); //get info on current track
154 pTxC[ch]->SetNextPoint(xPc,yPc); //add new intersection point
155
156 Float_t ckov=pTrk->GetHMPIDsignal(); Float_t err=TMath::Sqrt(pTrk->GetHMPIDchi2());
a1d55ff3 157 if(ckov>0){
158 rec.SetTrack(xPc,yPc,th,ph);
159 TVector2 pos; for(int j=0;j<100;j++){rec.TracePhot(ckov,j*0.0628,pos); pRin[ch]->SetNextPoint(pos.X(),pos.Y());}
160 }
161 }//tracks loop
162
d73ece6a 163 Int_t totHit=pHitLst->GetEntriesFast(),totDig=0,totClu=0,totTxC=0;
a1d55ff3 164 for(Int_t iCh=0;iCh<7;iCh++){//chambers loop
d73ece6a 165 totTxC+=pTxC[iCh]->GetN();
166 totDig+=((TClonesArray*)pDigLst->At(iCh))->GetEntriesFast();
167 totClu+=((TClonesArray*)pCluLst->At(iCh))->GetEntriesFast();
168
a1d55ff3 169 switch(iCh){
8282f9d0 170 case 6: pAll->cd(1); break; case 5: pAll->cd(2); break;
171 case 4: pAll->cd(4); break; case 3: pAll->cd(5); break; case 2: pAll->cd(6); break;
172 case 1: pAll->cd(8); break; case 0: pAll->cd(9); break;
a1d55ff3 173 }
174 gPad->SetEditable(kTRUE); gPad->Clear();
8282f9d0 175 DrawCh(iCh);
d73ece6a 176
177 for(Int_t iHit=0;iHit<pHitLst->GetEntriesFast();iHit++){
a1d55ff3 178 AliHMPIDHit *pHit=(AliHMPIDHit*)pHitLst->At(iHit);
d73ece6a 179 if(pHit->Ch()==iCh) pHit->Draw();
180 }
181
a1d55ff3 182 ((TClonesArray*)pDigLst->At(iCh))->Draw(); //draw digits
183 ((TClonesArray*)pCluLst->At(iCh))->Draw(); //draw clusters
184 pTxC[iCh]->Draw(); //draw intersections
185 pRin[iCh]->Draw(); //draw rings
186 gPad->SetEditable(kFALSE);
187 }//chambers loop
d73ece6a 188
189 pAll->cd(3); gPad->Clear(); TLegend *pLeg=new TLegend(0.2,0.2,0.8,0.8);
190 pLeg->SetHeader(Form("Event %i Total %i",gEvt,gMaxEvt+1));
191 pLeg->AddEntry(pTxC[0],Form("TRKxPC %i" ,totTxC),"p");
192 pLeg->AddEntry(pMip ,Form("Mip hits %i" ,totHit),"p");
193 pLeg->AddEntry(pCko ,Form("Ckov hits %i" ,totHit),"p");
194 pLeg->AddEntry(pFee ,Form("Feed hits %i" ,totHit),"p");
195 pLeg->AddEntry(pDig ,Form("Digs %i" ,totDig),"p");
196 pLeg->AddEntry(pClu ,Form("Clus %i" ,totClu),"p");
197 pLeg->Draw();
a1d55ff3 198}//DrawEvt()
8282f9d0 199//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
200void DoZoom(Int_t evt, Int_t px, Int_t py, TObject *obj)
a1d55ff3 201{
8282f9d0 202 if(evt!=5 && evt!=6) return; //5- zoom in 6-zoom out
203 const Int_t minZoom=64;
204 const Int_t maxZoom=2;
205 static Int_t zoom=minZoom; //zoom level
206 if(evt==5&&zoom==maxZoom) return;
207 if(evt==6&&zoom==minZoom) return;
208
d73ece6a 209 // if(!obj->IsA()->InheritsFrom("TPad")) return; //current object is not pad
210 TVirtualPad *pPad=gROOT->GetSelectedPad();
8282f9d0 211 if(pPad->GetNumber()==3 || pPad->GetNumber()==7) return; //current pad is wrong
212
213 // Printf("evt=%i (%i,%i) %s",evt,px,py,obj->GetName());
214
215 Float_t x=pPad->AbsPixeltoX(px); Float_t y=pPad->AbsPixeltoY(py);
6ed6a312 216
217 if(evt==5){ zoom=zoom/2; pPad->Range(x-zoom*2,y-zoom*2,x+zoom*2,y+zoom*2);} //zoom in
218 else { zoom=zoom*2; pPad->Range(x-zoom*2,y-zoom*2,x+zoom*2,y+zoom*2);} //zoom out
219 if(zoom==minZoom) pPad->Range(-10,-10,AliHMPIDDigit::SizeAllX()+5,AliHMPIDDigit::SizeAllY()+5);
8282f9d0 220 ((TCanvas *)gTQSender)->SetTitle(Form("zoom x%i",minZoom/zoom));
221 pPad->Modified();
222 pPad->Update();
a1d55ff3 223}
8282f9d0 224//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
d73ece6a 225void PrintHits()
226{
227//Prints a list of HMPID hits for a given event. Default is event number 0.
228 Printf("List of HMPID hits for event %i",gEvt);
229
230 Int_t iTotHits=0;
231 for(Int_t iPrim=0;iPrim<gHL->TreeH()->GetEntries();iPrim++){//prims loop
232 gHL->TreeH()->GetEntry(iPrim);
233 gH->Hits()->Print();
234 iTotHits+=gH->Hits()->GetEntries();
235 }
236 Printf("totally %i hits for event %i",iTotHits,gEvt);
237}
238//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
239void PrintSdis()
240{
241//prints a list of HMPID sdigits for a given event
242 Printf("List of HMPID sdigits for event %i",gEvt);
243 gH->SdiLst()->Print();
244 Printf("totally %i sdigits for event %i",gH->SdiLst()->GetEntries(),gEvt);
245}
246//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
247void PrintDigs()
248{
249//prints a list of HMPID digits
250 Printf("List of HMPID digits for event %i",gEvt);
251 gH->DigLst()->Print();
252 Int_t totDigs=0; for(Int_t i=0;i<7;i++) {totDigs+=gH->DigLst(i)->GetEntries();}
253 Printf("totally %i digits for event %i",totDigs,gEvt);
254}
255//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
256void PrintClus()
257{//prints a list of HMPID clusters for a given event
258 Printf("List of HMPID clusters for event %i",gEvt);
259 gH->CluLst()->Print();
260
261 Int_t iCluCnt=0; for(Int_t iCh=0;iCh<7;iCh++) iCluCnt+=gH->CluLst(iCh)->GetEntries();
262
263 Printf("totally %i clusters for event %i",iCluCnt,gEvt);
264}