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