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