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