]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HMPID/Hdisp.C
HTA revisited algorithm.
[u/mrichter/AliRoot.git] / HMPID / Hdisp.C
1 #if !defined(__CINT__) || defined(__MAKECINT__)
2
3 #include <TSystem.h>
4 #include <TFile.h>
5 #include <TVirtualX.h>
6 #include <TTree.h>
7 #include <TButton.h>
8 #include <TCanvas.h>
9 #include <TCanvasImp.h>
10 #include <TStyle.h>
11 #include <TString.h>
12 #include <TClonesArray.h>
13 #include <TParticle.h>
14 #include <TRandom.h>
15 #include <TLatex.h>
16 #include <TPDGCode.h>
17 #include <TLegend.h>
18 #include <TPolyMarker.h>
19 #include <TBox.h>
20 #include <AliESDEvent.h>
21 #include <AliCDBManager.h>
22 #include <AliCDBEntry.h>
23 #include "AliHMPIDHit.h"
24 #include "AliHMPIDv2.h"
25 #include "AliHMPIDReconstructor.h"
26 #include "AliHMPIDRecon.h"
27 #include "AliHMPIDParam.h"
28 #include "AliHMPIDCluster.h"
29 #include "AliTracker.h"
30 #include "AliStack.h"
31
32 #endif
33
34 AliHMPIDParam *fParam;
35 TDatabasePDG *fPdg;
36
37 TCanvas *fCanvas=0; Int_t fType=1; Int_t fEvt=-1; Int_t fNevt=0;                      
38 TCanvasImp *fCanvasImp;
39 TFile *fHitFile; TTree *fHitTree; TClonesArray *fHitLst; TPolyMarker *fRenMip[7]; TPolyMarker *fRenCko[7]; TPolyMarker *fRenFee[7];
40                                   TClonesArray *fSdiLst; 
41 TFile *fDigFile; TTree *fDigTree; TObjArray    *fDigLst; TBox *fRenDig[7][160*144]; TBox *fBox[7][160*144];   
42 TFile *fCluFile; TTree *fCluTree; TObjArray    *fCluLst; TPolyMarker *fRenClu[7];
43 TFile *fEsdFile; TTree *fEsdTree; AliESDEvent  *fEsd;    TPolyMarker *fRenTxC[7]; TPolyMarker *fRenRin[7];  
44 TFile *fCosFile; TTree *fCosTree;
45
46 TButton *fHitMipBok,*fHitCkoBok,*fHitFeeBok,*fDigBok,*fCluBok,*fEsdBok;
47
48 TString fStHitMip = "ON";
49 TString fStHitCko = "ON";
50 TString fStHitFee = "ON";
51 TString fStDig    = "ON";
52 TString fStClu    = "ON";
53 TString fStEsd    = "ON";
54
55 Int_t fTimeArrow = 1;
56
57 Int_t fMaxCharge = 200;  //maximum charge to saturate color to red
58
59 Int_t fChamN[9]={6,5,-1,4,3,2,-1,1,0};
60
61 Int_t fTotPads[7],fTotClus[7];
62
63 Int_t qSigmaCut=0;
64
65 Int_t trigType=0;
66
67 AliRunLoader *gAL=0; 
68 AliLoader *gDL=0; // detector loader (needed to get Digits and Clusters) 
69
70 Int_t nDigs[7];
71
72 enum EObjectType {kHitMip=kOpenTriangleUp,kHitCko=kOpenCircle,kHitFee=kOpenDiamond,kCluster=kStar,kTrack=kPlus,kRing=kFullDotSmall};
73   //  kOpenTriangleUp  Hit Mip
74   //  kOpenCircle      Hit Ckov
75   //  kOpenDiamond     Hit Feedback
76   //  kStar            Cluster 
77   //  kPlus            Track
78   //  kFullDotSmall    Ring
79   
80 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
81 void CreateContainers()
82 {//to create all containers
83   fHitLst=new TClonesArray("AliHMPIDHit");
84   fSdiLst=new TClonesArray("AliHMPIDDigit");
85   fDigLst=new TObjArray(7); for(Int_t i=0;i<7;i++) fDigLst->AddAt(new TClonesArray("AliHMPIDDigit"),i);       fDigLst->SetOwner(kTRUE);
86   fCluLst=new TObjArray(7); for(Int_t i=0;i<7;i++) fCluLst->AddAt(new TClonesArray("AliHMPIDCluster"),i);     fCluLst->SetOwner(kTRUE); 
87   fEsd   =new AliESDEvent;
88 }
89 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
90 void CreateRenders()
91 {
92   for(Int_t ch=0;ch<7;ch++){
93     fRenMip[ch]=new TPolyMarker; fRenMip[ch]->SetMarkerStyle(kOpenTriangleUp);fRenMip[ch]->SetMarkerColor(kBlack)  ;
94     fRenCko[ch]=new TPolyMarker; fRenCko[ch]->SetMarkerStyle(kOpenCircle);    fRenCko[ch]->SetMarkerColor(kBlack)  ;
95     fRenFee[ch]=new TPolyMarker; fRenFee[ch]->SetMarkerStyle(kOpenDiamond);   fRenFee[ch]->SetMarkerColor(kBlack)  ;
96     fRenClu[ch]=new TPolyMarker; fRenClu[ch]->SetMarkerStyle(kStar);          fRenClu[ch]->SetMarkerColor(kMagenta);
97     fRenTxC[ch]=new TPolyMarker; fRenTxC[ch]->SetMarkerStyle(kPlus);          fRenTxC[ch]->SetMarkerColor(kRed)    ;
98                                  fRenTxC[ch]->SetMarkerSize(3);
99     fRenRin[ch]=new TPolyMarker; fRenRin[ch]->SetMarkerStyle(kFullDotSmall);  fRenRin[ch]->SetMarkerColor(kMagenta);
100
101     for(Int_t iDig=0;iDig<160*144;iDig++) {
102       fRenDig[ch][iDig] = new TBox;
103       fRenDig[ch][iDig]->SetFillStyle(1);
104       fBox[ch][iDig] = new TBox;
105       fBox[ch][iDig]->SetFillStyle(0);
106     }
107   }
108 }//CreateRenders()
109 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
110 void ClearRenders()
111 {
112   for(Int_t ch=0;ch<7;ch++){
113     fRenTxC[ch]->SetPolyMarker(0); 
114     fRenRin[ch]->SetPolyMarker(0); 
115     fRenMip[ch]->SetPolyMarker(0); 
116     fRenCko[ch]->SetPolyMarker(0); 
117     fRenFee[ch]->SetPolyMarker(0); 
118     nDigs[ch] = 0;
119     fRenClu[ch]->SetPolyMarker(0); 
120   }
121 }//ClearRenders()
122 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
123 void PrintHits()
124 {
125 //Prints a list of HMPID hits for a given event. Default is event number 0.
126   if(!fHitTree) return;
127   Printf("List of HMPID hits for event %i",fEvt);
128   Int_t iTot=0;
129   for(Int_t iEnt=0;iEnt<fHitTree->GetEntries();iEnt++){//entries loop
130     fHitTree->GetEntry(iEnt);      
131     fHitLst->Print();
132     iTot+=fHitLst->GetEntries();
133   }
134   Printf("totally %i hits for event %i",iTot,fEvt);
135 }//PrintHits();
136 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
137 void PrintSdis()
138 {//prints a list of HMPID sdigits  for a given event
139   Printf("List of HMPID sdigits for event %i",fEvt);
140   fSdiLst->Print();
141   Printf("totally %i sdigits for event %i",fSdiLst->GetEntries(),fEvt);
142 }//PrintSdis()
143 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
144 void PrintDigs()
145 {//prints a list of HMPID digits
146   Printf("List of HMPID digits for event %i",fEvt);  
147   fDigLst->Print();
148   Int_t iTot=0;  for(Int_t i=0;i<7;i++) {iTot+=((TClonesArray*)fDigLst->At(i))->GetEntries();}
149   Printf("totally %i digits for event %i",iTot,fEvt);
150 }
151 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
152 void PrintClus()
153 {//prints a list of HMPID clusters  for a given event
154   Printf("List of HMPID clusters for event %i",fEvt);
155   
156   fCluLst->Print();
157   Int_t iTot=0; for(Int_t iCh=0;iCh<7;iCh++) iTot+=((TClonesArray*)fCluLst->At(iCh))->GetEntries();
158   
159   Printf("totally %i clusters for event %i",iTot,fEvt);
160 }
161 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
162 void PrintEsd()
163 {//prints a list of HMPID Esd  for a given event
164   Printf("List of HMPID ESD summary for event %i",fEvt);
165   for(Int_t iTrk=0;iTrk<fEsd->GetNumberOfTracks();iTrk++){
166     AliESDtrack *pTrk = fEsd->GetTrack(iTrk);
167     
168     Double_t xout[3],pout[3];
169     
170     pTrk->GetOuterPxPyPz(pout);
171     Double_t pMomOut = TMath::Sqrt(pout[0]*pout[0]+pout[1]*pout[1]+pout[2]*pout[2]);
172     
173     Float_t x,y;Int_t q,nacc;   pTrk->GetHMPIDmip(x,y,q,nacc);
174     Float_t xra,yra,th,ph; pTrk->GetHMPIDtrk(xra,yra,th,ph);
175 //    Printf("xra %f yra %f th %f phi %f",xra,yra,th,ph);
176     Int_t ch,idx,size;
177     Int_t word = pTrk->GetHMPIDcluIdx();
178     ch = word/1000000;
179     word = word%1000000;
180     size = word/1000;
181     idx = word%1000;
182     Double_t rout[3]; pTrk->GetOuterXYZ(rout);
183     vol = gGeoManager->FindNode(rout[0],rout[1],rout[2]);
184     Printf("Track %02i Ch. %2i with pOuter %7.2f with ThetaCer %7.3f with %3i photons with MIP Q %4i size %2i (idx %3i) in vol. %s",iTrk,ch,pMomOut,
185         pTrk->GetHMPIDsignal(),nacc,q,size,idx,vol->GetName());
186   }  
187 }//PrintEsd()
188 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
189 void DrawChamber(Int_t iCh) 
190 {//used by Draw() to Draw() chamber structure
191   gPad->Range(-10,-10,AliHMPIDParam::SizeAllX()+5,AliHMPIDParam::SizeAllY()+5);
192   if(iCh>=0){TLatex txt; txt.SetTextSize(0.06); txt.DrawLatex(55,-9,Form("RICH %i",iCh));}
193   
194   for(Int_t iPc=AliHMPIDParam::kMinPc;iPc<=AliHMPIDParam::kMaxPc;iPc++){
195     TBox *pBox=new TBox(AliHMPIDParam::MinPcX(iPc),AliHMPIDParam::MinPcY(iPc),
196                         AliHMPIDParam::MaxPcX(iPc),AliHMPIDParam::MaxPcY(iPc));
197     pBox->SetFillStyle(0);  pBox->Draw();
198   }//PC loop      
199 }//DrawChamber()
200 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
201 void DrawLegend()
202 {//used by Draw() to draw legend
203   Int_t nTxC=0,nMip=0,nCko=0,nFee=0,nDig=0,nClu=0;
204   for(Int_t ch=0;ch<7;ch++){
205     nTxC+=fRenTxC[ch]->Size();
206     nMip+=fRenMip[ch]->Size();
207     nCko+=fRenCko[ch]->Size();
208     nFee+=fRenFee[ch]->Size();
209     nClu+=fRenClu[ch]->Size();
210     nDig+=nDigs[ch];
211   }
212   TLegend *pLeg=new TLegend(0.15,0.3,0.85,0.98);
213   pLeg->SetHeader(Form("Event %i Total %i",fEvt,fNevt));
214   pLeg->AddEntry(fRenTxC[0],   Form("TRKxPC %i"  ,nTxC),"p");
215   pLeg->AddEntry(fRenMip[0],   Form("Mip hits %i"  ,nMip),"p");    
216   pLeg->AddEntry(fRenCko[0],   Form("Ckov hits %i"  ,nCko),"p");    
217   pLeg->AddEntry(fRenFee[0],   Form("Feed hits %i"  ,nFee),"p");    
218   pLeg->AddEntry(fRenDig[0][0],Form("Digs %i"  ,nDig),"p");    
219   pLeg->AddEntry(fRenClu[0],   Form("Clus %i"  ,nClu),"p");    
220   pLeg->Draw();
221  
222 /*  TLegend *pLeg2 = new TLegend(0.4,0.087,0.8,0.97);
223   pLeg2->SetHeader("");
224   pLeg2->AddEntry(fRenMip[0],Form("Mip hits %i"   ,nMip),"p");
225   pLeg2->Draw();*/
226
227  TBox *pBox = new TBox(0.012,0.01,0.97,0.28);
228  pBox->Draw("l");
229
230  TText *pText = new TText(0.35,0.21, "ddl = (0....13)");
231  pText->SetTextSize(0.06);
232  pText->Draw();
233
234  TText *pText2 = new TText(0.09,0.15,"RICH n ---> ddl 2n (left) & 2n+1 (right)");
235  pText2->SetTextSize(0.06);
236  pText2->Draw();
237
238  TText *pText3 = new TText(0.1,0.09, "phcat (0,2,4) left,   phcat (1,3,5) right");
239  pText3->SetTextSize(0.06);
240  pText3->Draw();
241
242  TText *pText4 = new TText(0.35,0.03, Form("sigma cut = %i",qSigmaCut));
243  pText4->SetTextSize(0.06);
244  pText4->Draw();
245
246 }//DrawLegend()
247 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
248 void Draw()
249 {//draws all the objects of current event in given canvas
250   Int_t iPadN[7]={9,8,6,5,4,2,1};
251   Int_t sampleCol = fMaxCharge/gStyle->GetNumberOfColors();
252   for(Int_t iCh=0;iCh<7;iCh++){//chambers loop    
253     fCanvas->cd(iPadN[iCh]);
254     gPad->SetEditable(kTRUE); gPad->Clear(); DrawChamber(iCh);
255     
256     if(fDigFile){
257       if(fStDig   =="ON") {
258         for(Int_t iDig=0;iDig<nDigs[iCh];iDig++) {
259           Int_t charge = fRenDig[iCh][iDig]->GetUniqueID();
260           Int_t color = charge/sampleCol;if(color>=gStyle->GetNumberOfColors()) color = gStyle->GetNumberOfColors()-1;
261           fRenDig[iCh][iDig]->SetFillColor(gStyle->GetColorPalette(color));
262           fRenDig[iCh][iDig]->Draw();
263           fBox[iCh][iDig]->Draw();
264         }
265       }
266     }
267     
268     if(fEsdFile){if(fStEsd   =="ON") fRenTxC[iCh]->Draw();}
269     
270     if(fHitFile){
271       if(fStHitMip=="ON") fRenMip[iCh]->Draw();
272       if(fStHitFee=="ON") fRenFee[iCh]->Draw();
273       if(fStHitCko=="ON") fRenCko[iCh]->Draw();
274     }
275     
276     if(fEsdFile){if(fStEsd   =="ON") fRenRin[iCh]->Draw();}
277     if(fCluFile){if(fStClu   =="ON") fRenClu[iCh]->Draw();}
278     gPad->SetEditable(kFALSE);
279   }//chambers loop
280   
281   fCanvas->cd(3);  gPad->Clear(); DrawLegend();
282   
283   fCanvas->cd(7);
284   
285   if(fHitFile){
286     fHitMipBok->SetTitle(Form("Mips  %s",fStHitMip.Data())); fHitMipBok->Modified();
287     fHitCkoBok->SetTitle(Form("Ckov  %s",fStHitCko.Data())); fHitCkoBok->Modified();
288     fHitFeeBok->SetTitle(Form("Fdbk  %s",fStHitFee.Data())); fHitFeeBok->Modified();
289   }
290   if(fDigFile){fDigBok->SetTitle(fStDig); fDigBok->Modified();}  
291   if(fCluFile){fCluBok->SetTitle(fStClu); fCluBok->Modified();} 
292   if(fEsdFile){fEsdBok->SetTitle(fStEsd); fEsdBok->Modified();}
293   
294 }//Draw()
295 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
296 void RenderHit(TClonesArray *pHitLst)
297 {//used by ReadEvent() to render hits to polymarker structures, one per chamber
298   for(Int_t iHit=0;iHit<pHitLst->GetEntries();iHit++){       //hits loop
299     AliHMPIDHit *pHit = (AliHMPIDHit*)pHitLst->At(iHit); Int_t ch=pHit->Ch(); Float_t x=pHit->LorsX(); Float_t y=pHit->LorsY();    //get current hit        
300     switch(pHit->Pid()){
301       case 50000050: fRenCko[ch]->SetNextPoint(x,y);break; 
302       case 50000051: fRenFee[ch]->SetNextPoint(x,y);break;
303       default:       fRenMip[ch]->SetNextPoint(x,y);break;
304     }//switch hit PID      
305 //    Printf("----------ihit %i ch %i chhit %i MIP %i CKO %i FEE %i",iHit,ch,pHit->Pid());
306   }//hits loop for this entry
307 }//RenderHits()
308 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
309 void RenderDig(TObjArray *pDigLst)
310 {//used by ReadEvent() to render digs to Tbox structures, one per chamber
311
312   for(Int_t iCh=0;iCh<=6;iCh++){                                    //chambers loop   
313     TClonesArray *pDigCham=(TClonesArray*)pDigLst->At(iCh);         //get digs list for this chamber
314     nDigs[iCh] = 0;
315     fTotPads[iCh] = pDigCham->GetEntries();
316     Int_t iDigEff=0;
317     for(Int_t iDig=0;iDig<pDigCham->GetEntries();iDig++){            //digs loop
318       AliHMPIDDigit *pDig = (AliHMPIDDigit*)pDigCham->At(iDig); Float_t x=pDig->LorsX(); Float_t y=pDig->LorsY();    //get current hit        
319       if((Int_t)pDig->Q()<=qSigmaCut) continue;
320       fRenDig[iCh][iDigEff]->SetX1(x-0.5*AliHMPIDParam::SizePadX());
321       fRenDig[iCh][iDigEff]->SetX2(x+0.5*AliHMPIDParam::SizePadX());
322       fRenDig[iCh][iDigEff]->SetY1(y-0.5*AliHMPIDParam::SizePadY());
323       fRenDig[iCh][iDigEff]->SetY2(y+0.5*AliHMPIDParam::SizePadY());
324       fRenDig[iCh][iDigEff]->SetUniqueID((Int_t)pDig->Q());
325       fBox[iCh][iDigEff]->SetX1(x-0.5*AliHMPIDParam::SizePadX());
326       fBox[iCh][iDigEff]->SetX2(x+0.5*AliHMPIDParam::SizePadX());
327       fBox[iCh][iDigEff]->SetY1(y-0.5*AliHMPIDParam::SizePadY());
328       fBox[iCh][iDigEff]->SetY2(y+0.5*AliHMPIDParam::SizePadY());
329       iDigEff++;
330       nDigs[iCh]++;
331     }//Digit loop
332   }//hits loop for this entry
333 }//RenderHits()
334 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
335 void RenderClu(TObjArray *pClus)
336 {//used by ReadEvent() to render clusters to polymarker structures, one per chamber
337   for(Int_t iCh=0;iCh<=6;iCh++){                                     //chambers loop   
338     TClonesArray *pClusCham=(TClonesArray*)pClus->At(iCh);           //get clusters list for this chamber
339     fTotClus[iCh] = pClusCham->GetEntries();
340     for(Int_t iClu=0;iClu<pClusCham->GetEntries();iClu++){           //clusters loop
341       AliHMPIDCluster *pClu = (AliHMPIDCluster*)pClusCham->At(iClu); //get current cluster        
342       fRenClu[iCh]->SetNextPoint(pClu->X(),pClu->Y());
343 //      Printf("RenderClu: ch %i x %f y %f",iCh,pClu->X(),pClu->Y());
344     }//cluster loop
345   }//chamber loop for this entry
346 }//RenderClus()
347 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
348 void RenderEsd(AliESDEvent *pEsd)
349 {//used by ReadEvent() to render ESD to polymarker structures for rings and intersections one per chamber
350   AliHMPIDRecon rec;
351   for(Int_t iTrk=0;iTrk<pEsd->GetNumberOfTracks();iTrk++){//tracks loop to collect cerenkov rings and intersection points
352     AliESDtrack *pTrk=pEsd->GetTrack(iTrk);    Int_t ch=pTrk->GetHMPIDcluIdx(); //get track and chamber intersected by it
353     ch/=1000000;
354     Float_t xPc,yPc,xRa,yRa,thRa,phRa; 
355     pTrk->GetHMPIDtrk(xRa,yRa,thRa,phRa);;
356     if(ch<AliHMPIDParam::AliHMPIDParam::kMinCh||ch>AliHMPIDParam::kMaxCh) continue;//this track does not intersect any chamber
357     Int_t npTrk = fRenTxC[ch]->SetNextPoint(xRa,yRa);                           //add this intersection point
358     Float_t ckov=pTrk->GetHMPIDsignal();                                        //get ckov angle stored for this track  
359     if(ckov>0){
360       rec.SetTrack(xRa,yRa,thRa,phRa);
361       fRenRin[ch]->SetUniqueID(npTrk);
362       for(Int_t j=0;j<500;j++){
363         TVector2 pos; pos=rec.TracePhot(ckov,j*6.28/500.);
364        if(!AliHMPIDParam::IsInDead(pos.X(),pos.Y())) fRenRin[ch]->SetNextPoint(pos.X(),pos.Y());
365       }      
366     }//if ckov is valid
367   }//tracks loop  
368 }//RenEsd()
369 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
370 TString Stack(Int_t evt,Int_t tid)
371 {
372 // Prints some useful info from stack
373 // Arguments: evt - event number. if not -1 print info only for that event
374 //            tid - track id. if not -1 then print it and all it's mothers if any   
375 //   Returns: mother tid of the given tid if any
376   if(gAL->LoadHeader()) return -1;
377   if(gAL->LoadKinematics()) return -1;
378   
379   gAL->GetEvent(evt);    
380   AliStack *pStack=gAL->Stack();  
381   TParticle *pTrack=pStack->Particle(tid);
382 //  Int_t mtid=pTrack->GetFirstMother();
383   TString str;
384   str.Append(Form("with P = %7.4f (%7.4f,%7.4f,%7.4f) GeV/c ",pTrack->P(),pTrack->Px(),pTrack->Py(),pTrack->Pz()));
385   gAL->UnloadHeader();  gAL->UnloadKinematics();
386   return str;
387 }
388 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
389 void DispTB(TString t0,TString t1,TString t2,TString t3)
390 {
391   fCanvasImp->SetStatusText(t0,0);
392   fCanvasImp->SetStatusText(t1,1);
393   fCanvasImp->SetStatusText(t2,2);
394   fCanvasImp->SetStatusText(t3,3);
395 }
396 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
397 Bool_t FindPos(TVector3 xyz,Int_t &cham,Int_t &sect,Int_t &gap,Int_t &padX,Int_t &padY)
398 {
399 // It finds the chamber parameters for a given point 
400 // Arguments:  xyz  coordinates of a given point in MARS
401 //   Returns:  cham   chamber ID ( 0-6 )
402 //             sect   sector  ID ( 0-5 )
403 //             padX   X (integer) of the pad in X in the given sector (1-80)
404 //             padY   Y (integer) of the pad in Y in the given sector (1-48)
405   cham = -1;
406   TGeoNode *node = gGeoManager->FindNode(xyz.X(),xyz.Y(),xyz.Z());
407   if(!node) return kFALSE;
408   TGeoVolume *vol = node->GetVolume();
409   if(!vol) return kFALSE;
410   TGeoManager *geo = vol->GetGeoManager();
411   if(!geo) return kFALSE;
412   Int_t i=0;
413   while(geo->GetMother(i)) {
414     TString s = geo->GetMother(i)->GetName();
415 //    if(s.Contains("Hcel_")) padX=(Int_t)(s.Remove(0,5)).Atof();
416 //    if(s.Contains("Hrow_")) padY=(Int_t)(s.Remove(0,5)).Atof();
417 //    if(s.Contains("Hsec_")) sect=(Int_t)(s.Remove(0,5)).Atof();
418 //    if(s.Contains("Hmp_"))  cham=(Int_t)(s.Remove(0,4)).Atof();
419     if(s.Contains("Hcel_")) padX=geo->GetMother(i)->GetNumber();
420     if(s.Contains("Hrow_")) padY=geo->GetMother(i)->GetNumber();
421     if(s.Contains("Hsec_")) sect=geo->GetMother(i)->GetNumber();
422     if(s.Contains("Hmp_"))  cham=geo->GetMother(i)->GetNumber();
423     i++; 
424   }
425   return (cham==-1) ? kFALSE : kTRUE;
426 }
427 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
428 void DisplayInfo(Int_t evt,Int_t px, Int_t py)
429 {
430   if(!gPad) return;
431   TVirtualPad *pPad=gPad->GetSelectedPad();
432   Int_t padN = pPad->GetNumber()-1;
433   if(padN<0 || padN>8) return;
434   Int_t ch,pc,padX,padY;
435   ch = fChamN[padN];
436   if(ch<0) return;
437   TString text0,text1,text2,text3;
438   
439   Float_t x=pPad->AbsPixeltoX(px); Float_t y=pPad->AbsPixeltoY(py); 
440   fParam->Lors2Pad(x,y,pc,padX,padY);
441   TVector3 xyz=fParam->Lors2Mars(ch,x,y);
442   
443   if(padX>=0&&padY>=0) {
444     text0.Append(Form("Pad(%i,%i)-LORS(%6.2f,%6.2f)-MARS(%7.2f,%7.2f,%7.2f) A(%6.2f,%6.2f)",padX,padY,x,y,xyz.X(),xyz.Y(),xyz.Z(),
445                                                                                                  xyz.Theta()*TMath::RadToDeg(),xyz.Phi()*TMath::RadToDeg()));
446     text1.Append(Form("Module %i Sector %i",ch,pc));
447     text2="";
448     text3.Append(Form("Pads = %i - Clusters = %i - Occupancy %5.2f%%",fTotPads[ch],fTotClus[ch],100.*fTotPads[ch]/(144.*160.)));
449   }
450   
451   TObject *obj = fCanvas->GetSelected();
452   TString name = obj->GetName();
453   
454 // Find object DIGIT
455
456   if(name=="") {DispTB(text0,text1,text2,text3);return;} // TLatex not interesting
457     
458   if(name.Contains("TBox")) {
459     TBox *box = (TBox*)obj;
460     if(box->GetUniqueID()==0) return; // just black frame hit!
461     text2.Append(Form("charge = %i ADC",box->GetUniqueID()));
462     DispTB(text0,text1,text2,text3);
463     return;
464   }
465 //
466 // Find object HITs CLUSTER TRACK and RING (based on TPolyMarker and symbol)
467 //
468   TPolyMarker *b = (TPolyMarker*)obj;
469
470   const Int_t big = 9999;
471
472   // check if point is near one of the points
473   Int_t distance = big;
474   Int_t index=0;
475
476   Double_t *xPol = b->GetX();
477   Double_t *yPol = b->GetY();
478
479   for(Int_t i=0;i<b->Size();i++) {
480     Int_t pxp = pPad->XtoAbsPixel(pPad->XtoPad(xPol[i]));
481     Int_t pyp = pPad->YtoAbsPixel(pPad->YtoPad(yPol[i]));
482     Int_t d   = TMath::Abs(pxp-px) + TMath::Abs(pyp-py);
483     if (d < distance) {distance = d; index=i;}
484   }
485
486   Int_t symbol = b->GetMarkerStyle();
487
488   //  kOpenTriangleUp  Hit Mip
489   //  kOpenCircle      Hit Ckov
490   //  kOpenDiamond     Hit Feedback
491   //  kStar            Cluster 
492   //  kPlus            Track
493   //  kFullDotSmall    Ring
494   
495   // Case Hit Mip of Hit Ckov or Hit Feedback
496   if(symbol==kHitMip || symbol==kHitCko || symbol==kHitFee) {
497     if(evt!=kButton1Down) return;
498     TString nameHit;
499     Int_t iCko[7]={0,0,0,0,0,0,0};
500     Int_t iFee[7]={0,0,0,0,0,0,0};
501     Int_t iMip[7]={0,0,0,0,0,0,0};
502     Int_t iHit;
503     Int_t chHit;
504     Int_t indHit=0;
505     
506     Int_t indTrk = b->GetUniqueID(); // track index
507     for(Int_t iEnt=0;iEnt<fHitTree->GetEntries();iEnt++){//entries loop
508       fHitTree->GetEntry(iEnt);                              
509       for(iHit=0;iHit<fHitLst->GetEntries();iHit++) {       //hits loop
510         AliHMPIDHit *pHit = (AliHMPIDHit*)fHitLst->At(iHit);
511         chHit = pHit->Ch();
512         Int_t pid = pHit->Pid();
513         if(pid==50000050) iCko[chHit]++;
514         else if(pid==50000051) iFee[chHit]++;
515         else iMip[chHit]++;
516
517         if(symbol==kHitMip && ch==chHit && index==iMip[chHit]-1) {indTrk=iEnt;indHit = iHit;break;}
518         if(symbol==kHitCko && ch==chHit && index==iCko[chHit]-1) {indTrk=iEnt;indHit = iHit;break;}
519         if(symbol==kHitFee && ch==chHit && index==iFee[chHit]-1) {indTrk=iEnt;indHit = iHit;break;}
520       }
521     }
522     fHitTree->GetEntry(indTrk);
523     AliHMPIDHit *pHit = (AliHMPIDHit*)fHitLst->At(indHit);
524
525     Int_t tid = pHit->Tid();
526     
527     TString str = Stack(fEvt,tid);
528      
529     Float_t x=pHit->LorsX(); 
530     Float_t y=pHit->LorsY();
531     Float_t charge = pHit->Q();
532     
533     TVector3 v = fParam->Lors2Mars(pHit->Ch(),pHit->LorsX(),pHit->LorsY());
534     Int_t cham,sect,gap,padX,padY;
535     FindPos(v,cham,sect,gap,padX,padY);
536     
537     if(pHit->Pid()==50000050) {nameHit = " Cherenkov Photon ";}
538     else if(pHit->Pid()==50000051) {nameHit = " Feedback Photon ";}
539     else if(fPdg->GetParticle(pHit->Pid())) nameHit = fPdg->GetParticle(pHit->Pid())->GetName();
540     nameHit.Append(Form(" (tid %i)",tid));
541     text0="";text0.Append(Form("Hit(%5.2f,%6.2f) LORS - Pad Volume(%i,%i) - hit %i/%i",x,y,padX,padY,indHit+1,fHitLst->GetEntries()));
542     text2="";text2.Append(Form("Q = %7.2f ADC",charge));
543     text3="";text3="Particle: "+ nameHit +" "+ str;
544   } // Hit  
545   else if (symbol==kCluster) {
546     TClonesArray *pClusCham=(TClonesArray*)fCluLst->At(ch);         //get clusters list for this chamber
547     AliHMPIDCluster *pClu = (AliHMPIDCluster*)pClusCham->At(index); //get current cluster
548     text0="";text0.Append(Form("CLUSTER: x %6.2f y %6.2f",pClu->X(),pClu->Y()));
549     text2="";text2.Append(Form("charge = %i ADC",(Int_t)pClu->Q()));
550     }
551   else if (symbol==kTrack || symbol==kRing) {
552     if(symbol==kRing) index = b->GetUniqueID();
553     AliESDtrack *pTrk=fEsd->GetTrack(index);
554     Float_t xPc,yPc,thRa,phRa,xRa,yRa;
555     Int_t ch = AliHMPIDTracker::IntTrkCha(pTrk,xPc,yPc,xRa,yRa,thRa,phRa);
556     text0="";text0.Append(Form("TRACK n.%d: x %6.2f y %6.2f at PC plane in chamber %i",index,xPc,yPc,ch));
557     text2="";text2.Append(Form("p = %7.2f GeV/c",pTrk->GetP()));
558     Float_t ckov=pTrk->GetHMPIDsignal();                             
559     Double_t prob[5];
560     pTrk->GetHMPIDpid(prob);
561     if(ckov>0){
562       Float_t x,y;Int_t q,nacc;   pTrk->GetHMPIDmip(x,y,q,nacc);
563       text3="";text3.Append(Form("Theta Cherenkov %5.3f with %i photons |  e %5.1f%% | u %5.1f%% | pi %5.1f%% | K %5.1f%% | p %5.1f%%",
564           pTrk->GetHMPIDsignal(),nacc,prob[0]*100,prob[1]*100,prob[2]*100,prob[3]*100,prob[4]*100));
565     }      
566   }
567 //Update toolbar status  
568
569   DispTB(text0,text1,text2,text3);  
570 }
571 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
572 void CloseInfo()
573 {
574 }
575 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
576 void DoZoom(Int_t evt, Int_t px, Int_t py, TObject *)
577 {
578 //  Printf(" px %i py%i event %i",px,py,evt);
579   
580   if(evt== 1) evt = 5;  //for laptop with touchpad: zoom in with left button
581   if(evt== 2) evt = 6;  //for laptop with touchpad: zoom out with both buttons
582   
583   if(evt==kMouseMotion||evt==kButton1Down) DisplayInfo(evt,px,py);
584 //  if(evt==11)  CloseInfo();
585   if(evt!=5 && evt!=6) return; //5- zoom in 6-zoom out
586   const Int_t minZoom=64;
587   const Int_t maxZoom=2;
588   static Int_t zoom[7]={64,64,64,64,64,64,64}; //zoom level
589   
590  // if(!obj->IsA()->InheritsFrom("TPad")) return;  //current object is not pad
591   TVirtualPad *pPad=gPad->GetSelectedPad();
592   Int_t padN = pPad->GetNumber()-1;
593   if(padN<0 || padN>8) return;
594   
595   Int_t iCh = fChamN[padN];
596   if(iCh < 0) return;
597   
598   if(evt==5&&zoom[iCh]==maxZoom) return; 
599   if(evt==6&&zoom[iCh]==minZoom) return; 
600     
601   Float_t x=pPad->AbsPixeltoX(px); Float_t y=pPad->AbsPixeltoY(py); 
602  
603   if(evt==5){ zoom[iCh]=zoom[iCh]/2;     pPad->Range(x-zoom[iCh]*2,y-zoom[iCh]*2,x+zoom[iCh]*2,y+zoom[iCh]*2);} //zoom in
604   if(evt==6){ zoom[iCh]=zoom[iCh]*2;     pPad->Range(x-zoom[iCh]*2,y-zoom[iCh]*2,x+zoom[iCh]*2,y+zoom[iCh]*2);} //zoom out 
605   if(zoom[iCh]==minZoom) pPad->Range(-10,-10,AliHMPIDParam::SizeAllX()+5,AliHMPIDParam::SizeAllY()+5);
606   ((TCanvas *)gTQSender)->SetTitle(Form("zoom x%i",minZoom/zoom[iCh]));
607   pPad->Modified();
608   pPad->Update();                                              
609 }
610 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
611 void CheckStatus()
612 {
613   if(fHitFile){
614     if(fStHitMip=="OFF") {fHitMipBok->SetFillColor(kRed);} else {fHitMipBok->SetFillColor(18);}
615     if(fStHitCko=="OFF") {fHitCkoBok->SetFillColor(kRed);} else {fHitCkoBok->SetFillColor(18);}
616     if(fStHitFee=="OFF") {fHitFeeBok->SetFillColor(kRed);} else {fHitFeeBok->SetFillColor(18);}
617   }
618   if(fDigFile){if(fStDig   =="OFF") {fDigBok->SetFillColor(kRed);} else {fDigBok->SetFillColor(18);}}
619   if(fCluFile){if(fStClu   =="OFF") {fCluBok->SetFillColor(kRed);} else {fCluBok->SetFillColor(18);}}
620   if(fEsdFile){if(fStEsd   =="OFF") {fEsdBok->SetFillColor(kRed);} else {fEsdBok->SetFillColor(18);}}
621 }
622 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
623 void GetEvent()
624 {
625   ClearRenders();
626   
627   ReadEvent();
628   
629   while(!Trigger()) {
630   Printf(" trigger %i for event %i",Trigger(),fEvt);
631     fEvt+=fTimeArrow;
632     ClearRenders();
633     ReadEvent();
634   }
635   
636   CheckStatus();
637   Draw();
638 }
639 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
640 void NextEvent()
641 {
642   fTimeArrow = 1;
643   fEvt+=fTimeArrow;
644   GetEvent();
645 }
646 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
647 void PrevEvent()
648 {
649   fTimeArrow = -1;
650   fEvt+=fTimeArrow;
651   GetEvent();
652 }
653 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
654 void End()
655 {
656   gSystem->Exit(0);
657 }
658 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
659 void Hdisp()                                  
660 {//display events from files if any in current directory or simulated events
661   
662   fParam=AliHMPIDParam::Instance();                          // first invocation of AliHMPIDParam to initialize geometry...
663   fPdg = TDatabasePDG::Instance();                           // first invocation of TDatabasePDG to retrieve particle infos...
664   
665   CreateContainers();
666   CreateRenders();
667   
668   TString title="Session with";
669
670   LoadRunLoader();
671   
672   if(gSystem->IsFileInIncludePath("HMPID.Hits.root")){// tries to open hits
673     fHitFile=TFile::Open("HMPID.Hits.root");       fNevt=fHitFile->GetNkeys(); fType=1; title+=Form(" HITS-%i ",fNevt);
674   }
675   
676   if(gSystem->IsFileInIncludePath("HMPID.Digits.root")){// tries to open clusters
677      fDigFile=TFile::Open("HMPID.Digits.root");  fNevt=fDigFile->GetNkeys(); fType=1;  title+=Form(" DIGITS-%i ",fNevt);
678    }
679   
680   if(gSystem->IsFileInIncludePath("HMPID.RecPoints.root")){// tries to open clusters
681     fCluFile=TFile::Open("HMPID.RecPoints.root");  fNevt=fCluFile->GetNkeys(); fType=1;  title+=Form(" CLUSTERS-%i ",fNevt);
682    }
683
684   if(gSystem->IsFileInIncludePath("cosmic.root")){                          //clm: Check if cosmic file is in the folder
685     fCosFile=TFile::Open("cosmic.root");  fCosTree=(TTree*)fCosFile->Get("cosmic");  fNevt=fCosTree->GetEntries();  fType=2;
686     fCosTree->SetBranchAddress("Digs",&fDigLst);   fCosTree->SetBranchAddress("Clus",&fCluLst); 
687   }            
688
689   if(gSystem->IsFileInIncludePath("AliESDs.root")){     
690     fEsdFile=TFile::Open("AliESDs.root");
691     if(fEsdFile) { 
692       fEsdTree=(TTree*)fEsdFile->Get("esdTree"); 
693       fEsd->ReadFromTree(fEsdTree); fEsd->GetStdContent();                       //clm: new ESD schema: see Task Force meeting 20th June, 2007
694       if(fEsdTree) {
695         fNevt=fEsdTree->GetEntries(); fType=1;  title+=Form(" ESD-%i ",fNevt); 
696       } else {delete fEsdFile;fEsdFile=0x0;}
697     } else {delete fEsdFile; delete fEsdTree;}
698   }
699   
700   fCanvas=new TCanvas("all","",-1024,768);fCanvas->SetWindowSize(1024,768);
701   fCanvasImp = fCanvas->GetCanvasImp();
702   fCanvasImp->ShowStatusBar();
703   fCanvas->Divide(3,3,0,0);//  pAll->ToggleEditor();
704   fCanvas->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)",0,0,"DoZoom(Int_t,Int_t,Int_t,TObject*)");
705   fCanvas->cd(7); 
706   gStyle->SetPalette(1,0);
707   switch(fType){
708     case 1: fCanvas->SetTitle(title.Data());                      
709                          TButton *pNxtBtn = new TButton("Next"      ,"NextEvent()"   ,0.0,0.0,0.3,0.1); pNxtBtn->Draw(); 
710                          TButton *pPrvBtn = new TButton("Previous"  ,"PrevEvent()"   ,0.3,0.0,0.6,0.1); pPrvBtn->Draw(); 
711             if(fHitFile){TButton *pHitBtn = new TButton("Print hits","PrintHits()"   ,0.0,0.2,0.3,0.3); pHitBtn->Draw();}  
712             if(fDigFile){TButton *pDigBtn = new TButton("Print digs","PrintDigs()"   ,0.0,0.4,0.3,0.5); pDigBtn->Draw();}  
713             if(fCluFile){TButton *pCluBtn = new TButton("Print clus","PrintClus()"   ,0.0,0.6,0.3,0.7); pCluBtn->Draw();} 
714             if(fEsdFile){TButton *pEsdBtn = new TButton("Print ESD ","PrintEsd()"    ,0.0,0.8,0.3,0.9); pEsdBtn->Draw();}
715             if(fHitFile){      fHitMipBok = new TButton(Form("Mip  %s",fStHitMip.Data()),"SwitchHitMip()",0.3,0.16,0.6,0.22); fHitMipBok->Draw();}
716             if(fHitFile){      fHitCkoBok = new TButton(Form("Ckov %s",fStHitCko.Data()),"SwitchHitCko()",0.3,0.22,0.6,0.28); fHitCkoBok->Draw();}  
717             if(fHitFile){      fHitFeeBok = new TButton(Form("Fdbk %s",fStHitFee.Data()),"SwitchHitFee()",0.3,0.28,0.6,0.34); fHitFeeBok->Draw();}  
718             if(fDigFile){         fDigBok = new TButton(fStDig      ,"SwitchDigs()"  ,0.3,0.4,0.6,0.5); fDigBok->Draw();}  
719             if(fCluFile){         fCluBok = new TButton(fStClu      ,"SwitchClus()"  ,0.3,0.6,0.6,0.7); fCluBok->Draw();} 
720             if(fEsdFile){         fEsdBok = new TButton(fStEsd      ,"SwitchEsd()"   ,0.3,0.8,0.6,0.9); fEsdBok->Draw();}
721
722             if(fHitFile){TButton *fHitMipOnly = new TButton(" Only ","OnlyHitMip()",0.6,0.16,0.9,0.22); fHitMipOnly->Draw();}  
723             if(fHitFile){TButton *fHitCkoOnly = new TButton(" Only ","OnlyHitCko()",0.6,0.22,0.9,0.28); fHitCkoOnly->Draw();}  
724             if(fHitFile){TButton *fHitFeeOnly = new TButton(" Only ","OnlyHitFee()",0.6,0.28,0.9,0.34); fHitFeeOnly->Draw();}  
725             if(fDigFile){TButton *fDigOnly    = new TButton(" Only ","OnlyDigs()"  ,0.6,0.40,0.9,0.50); fDigOnly->Draw();}  
726             if(fCluFile){TButton *fCluOnly    = new TButton(" Only ","OnlyClus()"  ,0.6,0.60,0.9,0.70); fCluOnly->Draw();} 
727             if(fEsdFile){TButton *fEsdOnly    = new TButton(" Only ","OnlyEsd()"   ,0.6,0.80,0.9,0.90); fEsdOnly->Draw();}
728                          TButton *pAll        = new TButton(" ALL  ","All()"       ,0.5,0.90,0.7,1.00); pAll->Draw();
729             
730                                      TButton *pEnd    = new TButton("Quit"      ,"End()"         ,0.6,0.0,0.9,0.1); pEnd->Draw();
731     break;
732     case 2: fCanvas->SetTitle("COSMIC");
733                          TButton *pCosBtn = new TButton("Next"      ,"NextEvent()",0.0,0.0,0.3,0.1); pCosBtn->Draw(); 
734              
735     break;
736     case 3: fCanvas->SetTitle("SIMULATION"); 
737             TButton *pSimBtn = new TButton("Simulate"  ,"NextEvent()",0.0,0.0,0.3,0.1); pSimBtn->Draw(); 
738             TButton *pHitBtn = new TButton("Print hits","PrintHits()",0.0,0.2,0.3,0.3); pHitBtn->Draw();  
739             TButton *pDigBtn = new TButton("Print digs","PrintDigs()",0.0,0.4,0.3,0.5); pDigBtn->Draw();
740             TButton *pCluBtn = new TButton("Print clus","PrintClus()",0.0,0.6,0.3,0.7); pCluBtn->Draw(); 
741             TButton *pEsdBtn = new TButton("Print ESD" ,"PrintEsd()" ,0.0,0.8,0.3,0.9); pEsdBtn->Draw();
742             if(fHitFile){      fHitMipBok = new TButton(Form("Mips %s",fStHitMip.Data()),"SwitchHitMip()",0.3,0.16,0.6,0.22); fHitMipBok->Draw();}  
743             if(fHitFile){      fHitCkoBok = new TButton(Form("Ckov %s",fStHitCko.Data()),"SwitchHitCko()",0.3,0.22,0.6,0.28); fHitCkoBok->Draw();}  
744             if(fHitFile){      fHitFeeBok = new TButton(Form("Fdbk %s",fStHitFee.Data()),"SwitchHitFee()",0.3,0.28,0.6,0.34); fHitFeeBok->Draw();}  
745             if(fDigFile){         fDigBok = new TButton(fStDig      ,"SwitchDigs()"  ,0.3,0.4,0.6,0.5); fDigBok->Draw();}  
746             if(fCluFile){         fCluBok = new TButton(fStClu      ,"SwitchClus()"  ,0.3,0.6,0.6,0.7); fCluBok->Draw();} 
747             if(fEsdFile){         fEsdBok = new TButton(fStEsd      ,"SwitchEsd()"   ,0.3,0.8,0.6,0.9); fEsdBok->Draw();}
748             
749             if(fHitFile){TButton *fHitMipOnly = new TButton(" Only ","OnlyHitMip()",0.6,0.16,0.9,0.22); fHitMipOnly->Draw();}  
750             if(fHitFile){TButton *fHitCkoOnly = new TButton(" Only ","OnlyHitCko()",0.6,0.22,0.9,0.28); fHitCkoOnly->Draw();}  
751             if(fHitFile){TButton *fHitFeeOnly = new TButton(" Only ","OnlyHitFee()",0.6,0.28,0.9,0.34); fHitFeeOnly->Draw();}  
752             if(fDigFile){TButton *fDigOnly    = new TButton(" Only ","OnlyDigs()"  ,0.6,0.40,0.9,0.50); fDigOnly->Draw();}  
753             if(fCluFile){TButton *fCluOnly    = new TButton(" Only ","OnlyClus()"  ,0.6,0.60,0.9,0.70); fCluOnly->Draw();} 
754             if(fEsdFile){TButton *fEsdOnly    = new TButton(" Only ","OnlyEsd()"   ,0.6,0.80,0.9,0.90); fEsdOnly->Draw();}
755                          TButton *pSimAll     = new TButton(" ALL  ","All()"       ,0.5,0.90,0.7,1.00); pSimAll->Draw();
756     break;
757   }
758     
759   NextEvent();           
760       
761 }//Hdisp()
762 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
763 void SwitchHitMip()
764 {
765   fStHitMip=(fStHitMip=="OFF")? "ON":"OFF";
766   GetEvent();
767 }
768 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
769 void SwitchHitCko()
770 {
771   fStHitCko=(fStHitCko=="OFF")? "ON":"OFF";
772   GetEvent();
773 }
774 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
775 void SwitchHitFee()
776 {
777   fStHitFee=(fStHitFee=="OFF")? "ON":"OFF";
778   GetEvent();
779 }
780 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
781 void SwitchDigs()
782 {
783   fStDig=(fStDig=="OFF")? "ON":"OFF";
784   GetEvent();
785 }
786 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
787 void SwitchClus()
788 {
789   fStClu=(fStClu=="OFF")? "ON":"OFF";
790   GetEvent();
791 }
792 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
793 void SwitchEsd()
794 {
795   fStEsd=(fStEsd=="OFF")? "ON":"OFF";
796    GetEvent();
797 }
798 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
799 void AllNo()
800 {
801   if(fHitFile) {
802     fStHitMip = "OFF";
803     fStHitCko = "OFF";
804     fStHitFee = "OFF";
805   }
806   if(fDigFile) fStDig    = "OFF";
807   if(fCluFile) fStClu    = "OFF";
808   if(fEsdFile) fStEsd    = "OFF";
809 }
810 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
811 void AllYes()
812 {
813   if(fHitFile) {
814     fStHitMip = "ON";
815     fStHitCko = "ON";
816     fStHitFee = "ON";
817   }
818   if(fDigFile) fStDig    = "ON";
819   if(fCluFile) fStClu    = "ON";
820   if(fEsdFile) fStEsd    = "ON";
821 }
822 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
823 void All()
824 {
825   AllYes();
826   GetEvent();
827 }
828 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
829 void OnlyHitMip()
830 {
831   AllNo();
832   fStHitMip = "ON";
833   GetEvent();
834 }
835 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
836 void OnlyHitCko()
837 {
838   AllNo();
839   fStHitCko = "ON";
840   GetEvent();
841 }
842 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
843 void OnlyHitFee()
844 {
845   AllNo();
846   fStHitFee = "ON";
847   GetEvent();
848 }
849 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
850 void OnlyDigs()
851 {
852   AllNo();
853   fStDig    = "ON";
854   GetEvent();
855 }
856 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
857 void OnlyClus()
858 {
859   AllNo();
860   fStClu    = "ON";
861   GetEvent();
862 }
863 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
864 void OnlyEsd()
865 {
866   AllNo();
867   fStEsd    = "ON";
868   GetEvent();
869 }
870 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
871 void LoadRunLoader(){
872   if(!gSystem->IsFileInIncludePath("galice.root")) {
873   Printf("\n\n galice.root not in path: please check! \n\n");
874   return;
875   }
876   if(gAlice) gAlice=0x0;                       
877   gAL=AliRunLoader::Open(); 
878   gAL->LoadHeader();
879   gAL->LoadHits("HMPID");
880   gAL->LoadDigits("HMPID");
881   gAL->LoadRecPoints("HMPID");
882   gDL = gAL->GetDetectorLoader("HMPID"); 
883   if(!gDL){
884    Printf("\n\n no AliLoader present: please check! \n\n");
885   return;
886   }
887   fNevt= gAL->GetNumberOfEvents(); 
888 }
889 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
890 void ReadEvent(){
891 //used by NextEvent()  to read curent event and construct all render elements
892   if(fNevt && fEvt>=fNevt) fEvt=0; //loop over max event
893   if(fNevt && fEvt<0) fEvt=fNevt-1; //loop over max event
894   
895 //  Printf("getting event %i out of %i",fEvt,fNevt);
896   
897   if(gDL) {
898   
899     gAL->GetEvent(fEvt);
900     
901 //-------- HITS
902
903     fHitTree=gDL->TreeH();
904
905     if(fHitTree) {    
906     
907       fHitTree->SetBranchAddress("HMPID",&fHitLst);
908       
909       for(Int_t iEnt=0;iEnt<fHitTree->GetEntries();iEnt++){    
910         fHitTree->GetEntry(iEnt);
911         RenderHit(fHitLst);   
912       }//prim loop
913     }//if hits tree
914
915 //-------- DIGITS
916
917     fDigTree=gDL->TreeD();
918     
919     if(fDigTree){ 
920       for(Int_t iCh=AliHMPIDParam::kMinCh;iCh<=AliHMPIDParam::kMaxCh;iCh++) fDigTree->SetBranchAddress(Form("HMPID%i",iCh),&(*fDigLst)[iCh]); 
921 //      fDigTree->GetEvent(fEvt);
922       fDigTree->GetEntry(0);                       
923       RenderDig(fDigLst);
924       //cout << "pointer to the dig list " << fDigLst << endl;
925      }
926
927 //-------- CLUSTERS
928
929      fCluTree= gDL->TreeR();
930      
931      if(fCluTree) {
932      for(Int_t iCh=AliHMPIDParam::kMinCh;iCh<=AliHMPIDParam::kMaxCh;iCh++) fCluTree->SetBranchAddress(Form("HMPID%i",iCh),&(*fCluLst)[iCh]); 
933      fCluTree->GetEntry(0);
934      RenderClu(fCluLst);   
935     }
936   }
937   
938 //-------- ESD
939   
940   if(fEsdFile){//if ESD file open
941     fEsdTree->GetEntry(fEvt);  
942     RenderEsd(fEsd);
943   }//if ESD file 
944
945 }
946 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
947 void SetEvent(Int_t ev)
948 {
949   fEvt=ev;
950   GetEvent();
951 }
952 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
953 void SetSigmaCut(Int_t sig=0)
954 {
955   qSigmaCut = sig;
956 }
957 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
958 void SetField()
959 {
960   gROOT->LoadMacro("Field.C");
961  
962   AliMagF * b = Field();
963
964 AliHMPIDTracker::SetFieldMap(b,kTRUE);
965 }
966 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
967 void SetTrigger(Int_t type=0)
968 {
969   trigType = type;
970   if(type==1) Printf(" Trigger 1 selected: at least ONE track in HMPID.");
971 }
972 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
973 Bool_t Trigger()
974 {
975   if(trigType==0) return kTRUE;
976   if(trigType==1) {
977     if(fEsd->GetNumberOfTracks()>0) {
978     PrintEsd();
979     return kTRUE;
980     } else return kFALSE;
981   }
982   return kTRUE;
983 }