New class AliHMPIDPid added. Now HMPID could run PID even on ESD within the same...
[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=3; 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 AliRunLoader *gAL=0; 
64
65 Int_t nDigs[7];
66
67 enum EObjectType {kHitMip=kOpenTriangleUp,kHitCko=kOpenCircle,kHitFee=kOpenDiamond,kCluster=kStar,kTrack=kPlus,kRing=kFullDotSmall};
68   //  kOpenTriangleUp  Hit Mip
69   //  kOpenCircle      Hit Ckov
70   //  kOpenDiamond     Hit Feedback
71   //  kStar            Cluster 
72   //  kPlus            Track
73   //  kFullDotSmall    Ring
74   
75 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
76 void CreateContainers()
77 {//to create all containers
78   fHitLst=new TClonesArray("AliHMPIDHit");
79   fSdiLst=new TClonesArray("AliHMPIDDigit");
80   fDigLst=new TObjArray(7); for(Int_t i=0;i<7;i++) fDigLst->AddAt(new TClonesArray("AliHMPIDDigit"),i);       fDigLst->SetOwner(kTRUE);
81   fCluLst=new TObjArray(7); for(Int_t i=0;i<7;i++) fCluLst->AddAt(new TClonesArray("AliHMPIDCluster"),i);     fCluLst->SetOwner(kTRUE); 
82   fEsd   =new AliESDEvent;
83 }
84 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
85 void CreateRenders()
86 {
87   for(Int_t ch=0;ch<7;ch++){
88     fRenMip[ch]=new TPolyMarker; fRenMip[ch]->SetMarkerStyle(kOpenTriangleUp);fRenMip[ch]->SetMarkerColor(kBlack)  ;
89     fRenCko[ch]=new TPolyMarker; fRenCko[ch]->SetMarkerStyle(kOpenCircle);    fRenCko[ch]->SetMarkerColor(kBlack)  ;
90     fRenFee[ch]=new TPolyMarker; fRenFee[ch]->SetMarkerStyle(kOpenDiamond);   fRenFee[ch]->SetMarkerColor(kBlack)  ;
91     fRenClu[ch]=new TPolyMarker; fRenClu[ch]->SetMarkerStyle(kStar);          fRenClu[ch]->SetMarkerColor(kMagenta);
92     fRenTxC[ch]=new TPolyMarker; fRenTxC[ch]->SetMarkerStyle(kPlus);          fRenTxC[ch]->SetMarkerColor(kRed)    ;
93                                  fRenTxC[ch]->SetMarkerSize(3);
94     fRenRin[ch]=new TPolyMarker; fRenRin[ch]->SetMarkerStyle(kFullDotSmall);  fRenRin[ch]->SetMarkerColor(kMagenta);
95
96     for(Int_t iDig=0;iDig<160*144;iDig++) {
97       fRenDig[ch][iDig] = new TBox;
98       fRenDig[ch][iDig]->SetFillStyle(1);
99       fBox[ch][iDig] = new TBox;
100       fBox[ch][iDig]->SetFillStyle(0);
101     }
102   }
103 }//CreateRenders()
104 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
105 void ClearRenders()
106 {
107   for(Int_t ch=0;ch<7;ch++){
108     fRenTxC[ch]->SetPolyMarker(0); 
109     fRenRin[ch]->SetPolyMarker(0); 
110     fRenMip[ch]->SetPolyMarker(0); 
111     fRenCko[ch]->SetPolyMarker(0); 
112     fRenFee[ch]->SetPolyMarker(0); 
113     nDigs[ch] = 0;
114     fRenClu[ch]->SetPolyMarker(0); 
115   }
116 }//ClearRenders()
117 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
118 void PrintHits()
119 {
120 //Prints a list of HMPID hits for a given event. Default is event number 0.
121   if(!fHitTree) return;
122   Printf("List of HMPID hits for event %i",fEvt);
123   Int_t iTot=0;
124   for(Int_t iEnt=0;iEnt<fHitTree->GetEntries();iEnt++){//entries loop
125     fHitTree->GetEntry(iEnt);      
126     fHitLst->Print();
127     iTot+=fHitLst->GetEntries();
128   }
129   Printf("totally %i hits for event %i",iTot,fEvt);
130 }//PrintHits();
131 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
132 void PrintSdis()
133 {//prints a list of HMPID sdigits  for a given event
134   Printf("List of HMPID sdigits for event %i",fEvt);
135   fSdiLst->Print();
136   Printf("totally %i sdigits for event %i",fSdiLst->GetEntries(),fEvt);
137 }//PrintSdis()
138 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
139 void PrintDigs()
140 {//prints a list of HMPID digits
141   Printf("List of HMPID digits for event %i",fEvt);  
142   fDigLst->Print();
143   Int_t iTot=0;  for(Int_t i=0;i<7;i++) {iTot+=((TClonesArray*)fDigLst->At(i))->GetEntries();}
144   Printf("totally %i digits for event %i",iTot,fEvt);
145 }
146 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
147 void PrintClus()
148 {//prints a list of HMPID clusters  for a given event
149   Printf("List of HMPID clusters for event %i",fEvt);
150   
151   fCluLst->Print();
152   Int_t iTot=0; for(Int_t iCh=0;iCh<7;iCh++) iTot+=((TClonesArray*)fCluLst->At(iCh))->GetEntries();
153   
154   Printf("totally %i clusters for event %i",iTot,fEvt);
155 }
156 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
157 void PrintEsd()
158 {//prints a list of HMPID Esd  for a given event
159   Printf("List of HMPID ESD summary for event %i",fEvt);
160   for(Int_t iTrk=0;iTrk<fEsd->GetNumberOfTracks();iTrk++){
161     AliESDtrack *pTrk = fEsd->GetTrack(iTrk);
162     Float_t x,y;Int_t q,nacc;   pTrk->GetHMPIDmip(x,y,q,nacc);
163     Printf("Track %02i with p %7.2f with ThetaCer %5.3f with %i photons",iTrk,pTrk->GetP(),pTrk->GetHMPIDsignal(),nacc);
164   }  
165 }//PrintEsd()
166 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
167 void DrawChamber(Int_t iCh) 
168 {//used by Draw() to Draw() chamber structure
169   gPad->Range(-10,-10,AliHMPIDParam::SizeAllX()+5,AliHMPIDParam::SizeAllY()+5);
170   if(iCh>=0){TLatex txt; txt.SetTextSize(0.1); txt.DrawLatex(-5,-5,Form("%i",iCh));}
171   
172   for(Int_t iPc=AliHMPIDParam::kMinPc;iPc<=AliHMPIDParam::kMaxPc;iPc++){
173     TBox *pBox=new TBox(AliHMPIDParam::MinPcX(iPc),AliHMPIDParam::MinPcY(iPc),
174                         AliHMPIDParam::MaxPcX(iPc),AliHMPIDParam::MaxPcY(iPc));
175     pBox->SetFillStyle(0);  pBox->Draw();
176   }//PC loop      
177 }//DrawChamber()
178 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
179 void DrawLegend()
180 {//used by Draw() to draw legend
181   Int_t nTxC=0,nMip=0,nCko=0,nFee=0,nDig=0,nClu=0;
182   for(Int_t ch=0;ch<7;ch++){
183     nTxC+=fRenTxC[ch]->Size();
184     nMip+=fRenMip[ch]->Size();
185     nCko+=fRenCko[ch]->Size();
186     nFee+=fRenFee[ch]->Size();
187     nClu+=fRenClu[ch]->Size();
188     nDig+=nDigs[ch];
189   }
190   TLegend *pLeg=new TLegend(0.2,0.2,0.8,0.8);
191   pLeg->SetHeader(Form("Event %i Total %i",fEvt,fNevt));
192   pLeg->AddEntry(fRenTxC[0],   Form("TRKxPC %i"     ,nTxC),"p");
193   pLeg->AddEntry(fRenMip[0],   Form("Mip hits %i"   ,nMip),"p");    
194   pLeg->AddEntry(fRenCko[0],   Form("Ckov hits %i"  ,nCko),"p");    
195   pLeg->AddEntry(fRenFee[0],   Form("Feed hits %i"  ,nFee),"p");    
196   pLeg->AddEntry(fRenDig[0][0],Form("Digs %i"       ,nDig),"p");    
197   pLeg->AddEntry(fRenClu[0],   Form("Clus %i"       ,nClu),"p");    
198   pLeg->Draw();
199 }//DrawLegend()
200 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
201 void Draw()
202 {//draws all the objects of current event in given canvas
203   Int_t iPadN[7]={9,8,6,5,4,2,1};
204   Int_t sampleCol = fMaxCharge/gStyle->GetNumberOfColors();
205   for(Int_t iCh=0;iCh<7;iCh++){//chambers loop    
206     fCanvas->cd(iPadN[iCh]);
207     gPad->SetEditable(kTRUE); gPad->Clear(); DrawChamber(iCh);
208     
209     if(fDigFile){
210       if(fStDig   =="ON") {
211         for(Int_t iDig=0;iDig<nDigs[iCh];iDig++) {
212           Int_t charge = fRenDig[iCh][iDig]->GetUniqueID();
213           Int_t color = charge/sampleCol;if(color>=gStyle->GetNumberOfColors()) color = gStyle->GetNumberOfColors()-1;
214           fRenDig[iCh][iDig]->SetFillColor(gStyle->GetColorPalette(color));
215           fRenDig[iCh][iDig]->Draw();
216           fBox[iCh][iDig]->Draw();
217         }
218       }
219     }
220     
221     if(fEsdFile){if(fStEsd   =="ON") fRenTxC[iCh]->Draw();}
222     
223     if(fHitFile){
224       if(fStHitMip=="ON") fRenMip[iCh]->Draw();
225       if(fStHitFee=="ON") fRenFee[iCh]->Draw();
226       if(fStHitCko=="ON") fRenCko[iCh]->Draw();
227     }
228     
229     if(fEsdFile){if(fStEsd   =="ON") fRenRin[iCh]->Draw();}
230     if(fCluFile){if(fStClu   =="ON") fRenClu[iCh]->Draw();}
231     gPad->SetEditable(kFALSE);
232   }//chambers loop
233   
234   fCanvas->cd(3);  gPad->Clear(); DrawLegend();
235   
236   fCanvas->cd(7);
237   
238   if(fHitFile){
239     fHitMipBok->SetTitle(Form("Mips  %s",fStHitMip.Data())); fHitMipBok->Modified();
240     fHitCkoBok->SetTitle(Form("Ckov  %s",fStHitCko.Data())); fHitCkoBok->Modified();
241     fHitFeeBok->SetTitle(Form("Fdbk  %s",fStHitFee.Data())); fHitFeeBok->Modified();
242   }
243   if(fDigFile){fDigBok->SetTitle(fStDig); fDigBok->Modified();}  
244   if(fCluFile){fCluBok->SetTitle(fStClu); fCluBok->Modified();} 
245   if(fEsdFile){fEsdBok->SetTitle(fStEsd); fEsdBok->Modified();}
246   
247 }//Draw()
248 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
249 void RenderHit(TClonesArray *pHitLst)
250 {//used by ReadEvent() and SimulateEvent() to render hits to polymarker structures, one per chamber
251   for(Int_t iHit=0;iHit<pHitLst->GetEntries();iHit++){       //hits loop
252     AliHMPIDHit *pHit = (AliHMPIDHit*)pHitLst->At(iHit); Int_t ch=pHit->Ch(); Float_t x=pHit->LorsX(); Float_t y=pHit->LorsY();    //get current hit        
253     switch(pHit->Pid()){
254       case 50000050: fRenCko[ch]->SetNextPoint(x,y);break; 
255       case 50000051: fRenFee[ch]->SetNextPoint(x,y);break;
256       default:       fRenMip[ch]->SetNextPoint(x,y);break;
257     }//switch hit PID      
258 //    Printf("----------ihit %i ch %i chhit %i MIP %i CKO %i FEE %i",iHit,ch,pHit->Pid());
259   }//hits loop for this entry
260 }//RenderHits()
261 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
262 void RenderDig(TObjArray *pDigLst)
263 {//used by ReadEvent() and SimulateEvent() to render digs to Tbox structures, one per chamber
264   for(Int_t iCh=0;iCh<=6;iCh++){                                    //chambers loop   
265     TClonesArray *pDigCham=(TClonesArray*)pDigLst->At(iCh);         //get digs list for this chamber
266     nDigs[iCh] = 0;
267     fTotPads[iCh] = pDigCham->GetEntries();
268     for(Int_t iDig=0;iDig<pDigCham->GetEntries();iDig++){            //digs loop
269       AliHMPIDDigit *pDig = (AliHMPIDDigit*)pDigCham->At(iDig); Float_t x=pDig->LorsX(); Float_t y=pDig->LorsY();    //get current hit        
270       fRenDig[iCh][iDig]->SetX1(x-0.5*AliHMPIDParam::SizePadX());
271       fRenDig[iCh][iDig]->SetX2(x+0.5*AliHMPIDParam::SizePadX());
272       fRenDig[iCh][iDig]->SetY1(y-0.5*AliHMPIDParam::SizePadY());
273       fRenDig[iCh][iDig]->SetY2(y+0.5*AliHMPIDParam::SizePadY());
274       fRenDig[iCh][iDig]->SetUniqueID((Int_t)pDig->Q());
275       fBox[iCh][iDig]->SetX1(x-0.5*AliHMPIDParam::SizePadX());
276       fBox[iCh][iDig]->SetX2(x+0.5*AliHMPIDParam::SizePadX());
277       fBox[iCh][iDig]->SetY1(y-0.5*AliHMPIDParam::SizePadY());
278       fBox[iCh][iDig]->SetY2(y+0.5*AliHMPIDParam::SizePadY());
279       nDigs[iCh]++;
280     }//Digit loop
281   }//hits loop for this entry
282 }//RenderHits()
283 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
284 void RenderClu(TObjArray *pClus)
285 {//used by ReadEvent() and SimulateEvent() to render clusters to polymarker structures, one per chamber
286   for(Int_t iCh=0;iCh<=6;iCh++){                                     //chambers loop   
287     TClonesArray *pClusCham=(TClonesArray*)pClus->At(iCh);           //get clusters list for this chamber
288     fTotClus[iCh] = pClusCham->GetEntries();
289     for(Int_t iClu=0;iClu<pClusCham->GetEntries();iClu++){           //clusters loop
290       AliHMPIDCluster *pClu = (AliHMPIDCluster*)pClusCham->At(iClu); //get current cluster        
291       fRenClu[iCh]->SetNextPoint(pClu->X(),pClu->Y());
292 //      Printf("RenderClu: ch %i x %f y %f",iCh,pClu->X(),pClu->Y());
293     }//cluster loop
294   }//chamber loop for this entry
295 }//RenderClus()
296 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
297 void RenderEsd(AliESDEvent *pEsd)
298 {//used by ReadEvent() or SimulateEvent() to render ESD to polymarker structures for rings and intersections one per chamber
299   AliHMPIDRecon rec;
300   for(Int_t iTrk=0;iTrk<pEsd->GetNumberOfTracks();iTrk++){//tracks loop to collect cerenkov rings and intersection points
301     AliESDtrack *pTrk=pEsd->GetTrack(iTrk);    Int_t ch=pTrk->GetHMPIDcluIdx(); //get track and chamber intersected by it
302     if(ch<0) continue;                                                          //this track does not intersect any chamber
303     Float_t thRa,phRa,xRa,yRa; pTrk->GetHMPIDtrk(xRa,yRa,thRa,phRa);            //get info on current track
304     ch/=1000000;                            
305     Float_t xPc=0,yPc=0; AliHMPIDTracker::IntTrkCha(pTrk,xPc,yPc);              //find again intersection of track with PC--> it is not stored in ESD!
306     Int_t npTrk = fRenTxC[ch]->SetNextPoint(xPc,yPc);                           //add this intersection point
307     Float_t ckov=pTrk->GetHMPIDsignal();                                        //get ckov angle stored for this track  
308     if(ckov>0){
309       rec.SetTrack(xRa,yRa,thRa,phRa);
310       fRenRin[ch]->SetUniqueID(npTrk);
311       for(Int_t j=0;j<500;j++){
312         TVector2 pos; pos=rec.TracePhot(ckov,j*6.28/500.);
313        if(!AliHMPIDParam::IsInDead(pos.X(),pos.Y())) fRenRin[ch]->SetNextPoint(pos.X(),pos.Y());
314       }      
315     }//if ckov is valid
316   }//tracks loop  
317 }//RenEsd()
318 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
319 void SimulateEsd(AliESDEvent *pEsd)
320 {
321   TParticle part; TLorentzVector mom;
322   for(Int_t iTrk=0;iTrk<100;iTrk++){//stack loop
323     Printf("SimulateEsd: kProton %i",kProton);
324     part.SetPdgCode(kProton);
325     part.SetProductionVertex(0,0,0,0);
326     Double_t eta= -0.2+gRandom->Rndm()*0.4; //rapidity is random [-0.2,+0.2]
327     Double_t phi= gRandom->Rndm()*60.*TMath::DegToRad();   //phi is random      [ 0  , 60 ] degrees    
328     mom.SetPtEtaPhiM(5,eta,phi,part.GetMass());
329     part.SetMomentum(mom);
330     AliESDtrack trk(&part);
331     pEsd->AddTrack(&trk);
332   }//stack loop  
333 }//EsdFromStack()
334 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
335 void SimulateHits(AliESDEvent *pEsd, TClonesArray *pHits)
336 {//used by SimulateEvent to simulate hits out from provided ESD
337   const Int_t kCerenkov=50000050;
338   const Int_t kFeedback=50000051;
339   
340   AliHMPIDRecon rec;
341   Float_t eMip=200e-9,ePho=7.5e-9; 
342   Int_t hc=0; 
343   for(Int_t iTrk=0;iTrk<pEsd->GetNumberOfTracks();iTrk++){//tracks loop
344     AliESDtrack *pTrk=pEsd->GetTrack(iTrk);
345     Float_t xRa,yRa;
346     Int_t ch=AliHMPIDTracker::IntTrkCha(pTrk,xRa,yRa);
347     if(ch<0) continue; //this track does not hit HMPID
348     Float_t beta = pTrk->GetP()/(TMath::Sqrt(pTrk->GetP()*pTrk->GetP()+0.938*0.938));
349     Float_t ckov=TMath::ACos(1./(beta*1.292));
350
351     Float_t theta,phi,xPc,yPc,; pTrk->GetHMPIDtrk(xPc,yPc,theta,phi); rec.SetTrack(xRa,yRa,theta,phi); 
352     
353     if(!AliHMPIDParam::IsInDead(xPc,yPc)) new((*pHits)[hc++]) AliHMPIDHit(ch,eMip,kProton  ,iTrk,xPc,yPc);                 //mip hit
354     Int_t nPhots = (Int_t)(20.*TMath::Power(TMath::Sin(ckov),2)/TMath::Power(TMath::Sin(TMath::ACos(1./1.292)),2));
355     for(int i=0;i<nPhots;i++){
356       TVector2 pos;
357       pos=rec.TracePhot(ckov,gRandom->Rndm()*TMath::TwoPi());
358       if(!AliHMPIDParam::IsInDead(pos.X(),pos.Y())) new((*pHits)[hc++]) AliHMPIDHit(ch,ePho,kCerenkov,iTrk,pos.X(),pos.Y());
359     }                      //photon hits  
360     for(int i=0;i<3;i++){//feedback photons
361       Float_t x=gRandom->Rndm()*160; Float_t y=gRandom->Rndm()*150;
362       if(!AliHMPIDParam::IsInDead(x,y)) new((*pHits)[hc++]) AliHMPIDHit(ch,ePho,kFeedback,iTrk,x,y);                 //feedback hits  
363     }//photon hits loop                      
364   }//tracks loop    
365 }//SimulateHits()
366 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
367 TString Stack(Int_t evt,Int_t tid)
368 {
369 // Prints some useful info from stack
370 // Arguments: evt - event number. if not -1 print info only for that event
371 //            tid - track id. if not -1 then print it and all it's mothers if any   
372 //   Returns: mother tid of the given tid if any
373   if(gAL->LoadHeader()) return -1;
374   if(gAL->LoadKinematics()) return -1;
375   
376   gAL->GetEvent(evt);    
377   AliStack *pStack=gAL->Stack();  
378   TParticle *pTrack=pStack->Particle(tid);
379 //  Int_t mtid=pTrack->GetFirstMother();
380   TString str;
381   str.Append(Form("with P = %7.4f (%7.4f,%7.4f,%7.4f) GeV/c ",pTrack->P(),pTrack->Px(),pTrack->Py(),pTrack->Pz()));
382   gAL->UnloadHeader();  gAL->UnloadKinematics();
383   return str;
384 }
385 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
386 void DispTB(TString t0,TString t1,TString t2,TString t3)
387 {
388   fCanvasImp->SetStatusText(t0,0);
389   fCanvasImp->SetStatusText(t1,1);
390   fCanvasImp->SetStatusText(t2,2);
391   fCanvasImp->SetStatusText(t3,3);
392 }
393 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
394 Bool_t FindPos(TVector3 xyz,Int_t &cham,Int_t &sect,Int_t &gap,Int_t &padX,Int_t &padY)
395 {
396 // It finds the chamber parameters for a given point 
397 // Arguments:  xyz  coordinates of a given point in MARS
398 //   Returns:  cham   chamber ID ( 0-6 )
399 //             sect   sector  ID ( 0-5 )
400 //             padX   X (integer) of the pad in X in the given sector (1-80)
401 //             padY   Y (integer) of the pad in Y in the given sector (1-48)
402   cham = -1;
403   TGeoNode *node = gGeoManager->FindNode(xyz.X(),xyz.Y(),xyz.Z());
404   if(!node) return kFALSE;
405   TGeoVolume *vol = node->GetVolume();
406   if(!vol) return kFALSE;
407   TGeoManager *geo = vol->GetGeoManager();
408   if(!geo) return kFALSE;
409   Int_t i=0;
410   while(geo->GetMother(i)) {
411     TString s = geo->GetMother(i)->GetName();
412 //    if(s.Contains("Hcel_")) padX=(Int_t)(s.Remove(0,5)).Atof();
413 //    if(s.Contains("Hrow_")) padY=(Int_t)(s.Remove(0,5)).Atof();
414 //    if(s.Contains("Hsec_")) sect=(Int_t)(s.Remove(0,5)).Atof();
415 //    if(s.Contains("Hmp_"))  cham=(Int_t)(s.Remove(0,4)).Atof();
416     if(s.Contains("Hcel_")) padX=geo->GetMother(i)->GetNumber();
417     if(s.Contains("Hrow_")) padY=geo->GetMother(i)->GetNumber();
418     if(s.Contains("Hsec_")) sect=geo->GetMother(i)->GetNumber();
419     if(s.Contains("Hmp_"))  cham=geo->GetMother(i)->GetNumber();
420     i++; 
421   }
422   return (cham==-1) ? kFALSE : kTRUE;
423 }
424 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
425 void DisplayInfo(Int_t evt,Int_t px, Int_t py)
426 {
427   if(!gPad) return;
428   TVirtualPad *pPad=gPad->GetSelectedPad();
429   Int_t padN = pPad->GetNumber()-1;
430   if(padN<0 || padN>8) return;
431   Int_t ch,pc,padX,padY;
432   ch = fChamN[padN];
433   if(ch<0) return;
434   TString text0,text1,text2,text3;
435   
436   Float_t x=pPad->AbsPixeltoX(px); Float_t y=pPad->AbsPixeltoY(py); 
437   fParam->Lors2Pad(x,y,pc,padX,padY);
438   TVector3 xyz=fParam->Lors2Mars(ch,x,y);
439   
440   if(padX>=0&&padY>=0) {
441     text0.Append(Form("Pad(%i,%i)-LORS(%6.2f,%6.2f)-MARS(%7.2f,%7.2f,%7.2f)",padX,padY,x,y,xyz.X(),xyz.Y(),xyz.Z()));
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 thRa,phRa,xRa,yRa; pTrk->GetHMPIDtrk(xRa,yRa,thRa,phRa);
551     Float_t xPc,yPc; AliHMPIDTracker::IntTrkCha(pTrk,xPc,yPc);
552     text0="";text0.Append(Form("TRACK n.%d: x %6.2f y %6.2f at PC plane",index,xPc,yPc));
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%% | K %5.1f%% | pi %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   if(evt==kMouseMotion||evt==kButton1Down) DisplayInfo(evt,px,py);
576   if(evt==11)  CloseInfo();
577   if(evt!=5 && evt!=6) return; //5- zoom in 6-zoom out
578   const Int_t minZoom=64;
579   const Int_t maxZoom=2;
580   static Int_t zoom[7]={64,64,64,64,64,64,64}; //zoom level
581   
582  // if(!obj->IsA()->InheritsFrom("TPad")) return;  //current object is not pad
583   TVirtualPad *pPad=gPad->GetSelectedPad();
584   Int_t padN = pPad->GetNumber()-1;
585   if(padN<0 || padN>8) return;
586   
587   Int_t iCh = fChamN[padN];
588   if(iCh < 0) return;
589   
590   if(evt==5&&zoom[iCh]==maxZoom) return; 
591   if(evt==6&&zoom[iCh]==minZoom) return; 
592     
593   Float_t x=pPad->AbsPixeltoX(px); Float_t y=pPad->AbsPixeltoY(py); 
594  
595   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
596   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 
597   if(zoom[iCh]==minZoom) pPad->Range(-10,-10,AliHMPIDParam::SizeAllX()+5,AliHMPIDParam::SizeAllY()+5);
598   ((TCanvas *)gTQSender)->SetTitle(Form("zoom x%i",minZoom/zoom[iCh]));
599   pPad->Modified();
600   pPad->Update();                                              
601 }
602 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
603 void ReadEvent()
604 {//used by NextEvent()  to read curent event and construct all render elements
605   if(fNevt && fEvt>=fNevt) fEvt=0; //loop over max event
606   if(fNevt && fEvt<0) fEvt=fNevt-1; //loop over max event
607   
608   if(fHitFile){ 
609     if(fHitTree) delete fHitTree;   fHitTree=(TTree*)fHitFile->Get(Form("Event%i/TreeH",fEvt));
610     
611                           fHitTree->SetBranchAddress("HMPID",&fHitLst);
612     for(Int_t iEnt=0;iEnt<fHitTree->GetEntries();iEnt++){    
613                           fHitTree->GetEntry(iEnt);
614       RenderHit(fHitLst);   
615     }//prim loop
616   }//if hits file
617
618   if(fDigFile){ 
619     if(fDigTree) delete fDigTree;   fDigTree=(TTree*)fDigFile->Get(Form("Event%i/TreeD",fEvt));
620     for(Int_t iCh=AliHMPIDParam::kMinCh;iCh<=AliHMPIDParam::kMaxCh;iCh++) fDigTree->SetBranchAddress(Form("HMPID%i",iCh),&(*fDigLst)[iCh]);      
621     fDigTree->GetEntry(0);                              
622     RenderDig(fDigLst);   
623   }//if digs file
624     
625   if(fCluFile){ 
626     if(fCluTree) delete fCluTree; fCluTree=(TTree*)fCluFile->Get(Form("Event%i/TreeR",fEvt));
627     for(Int_t iCh=AliHMPIDParam::kMinCh;iCh<=AliHMPIDParam::kMaxCh;iCh++) fCluTree->SetBranchAddress(Form("HMPID%i",iCh),&(*fCluLst)[iCh]);      
628     fCluTree->GetEntry(0);
629     RenderClu(fCluLst);   
630   }//if clus file
631   
632   if(fEsdFile){//if ESD file open
633     fEsdTree->GetEntry(fEvt);  
634     RenderEsd(fEsd);
635   }//if ESD file 
636 }//ReadEvent()
637 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
638 void SimulateEvent()
639 {// used by NextEvent() to simulate all info
640   AliCDBManager* pCDB = AliCDBManager::Instance();  pCDB->SetDefaultStorage("local://$HOME"); pCDB->SetRun(0);
641   AliCDBEntry *pNmeanEnt=pCDB->Get("HMPID/Calib/Nmean");
642
643   SimulateEsd(fEsd);
644   SimulateHits(fEsd,fHitLst);
645                  AliHMPIDv2::Hit2Sdi(fHitLst,fSdiLst);                               
646           AliHMPIDDigitizer::Sdi2Dig(fSdiLst,fDigLst);     
647       AliHMPIDReconstructor::Dig2Clu(fDigLst,fCluLst);
648             AliHMPIDTracker::Recon(fEsd,fCluLst,(TObjArray*)pNmeanEnt->GetObject());
649             
650   RenderHit(fHitLst);
651   RenderClu(fCluLst);
652   RenderEsd(fEsd);            
653 }//SimulateEvent()
654 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
655 void CheckStatus()
656 {
657   if(fHitFile){
658     if(fStHitMip=="OFF") {fHitMipBok->SetFillColor(kRed);} else {fHitMipBok->SetFillColor(18);}
659     if(fStHitCko=="OFF") {fHitCkoBok->SetFillColor(kRed);} else {fHitCkoBok->SetFillColor(18);}
660     if(fStHitFee=="OFF") {fHitFeeBok->SetFillColor(kRed);} else {fHitFeeBok->SetFillColor(18);}
661   }
662   if(fDigFile){if(fStDig   =="OFF") {fDigBok->SetFillColor(kRed);} else {fDigBok->SetFillColor(18);}}
663   if(fCluFile){if(fStClu   =="OFF") {fCluBok->SetFillColor(kRed);} else {fCluBok->SetFillColor(18);}}
664   if(fEsdFile){if(fStEsd   =="OFF") {fEsdBok->SetFillColor(kRed);} else {fEsdBok->SetFillColor(18);}}
665 }
666 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
667 void GetEvent()
668 {
669   ClearRenders();
670   CheckStatus();
671   switch(fType){
672     case 1: ReadEvent();break;
673 //    case 2: ReadCosmic(); break;
674     case 3: SimulateEvent();     break;
675     default:                 return;
676   }  
677   Draw();
678 }
679 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
680 void NextEvent()
681 {
682   fTimeArrow = 1;
683   fEvt+=fTimeArrow;
684   GetEvent();
685 }
686 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
687 void PrevEvent()
688 {
689   fTimeArrow = -1;
690   fEvt+=fTimeArrow;
691   GetEvent();
692 }
693 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
694 void End()
695 {
696   gSystem->Exit(0);
697 }
698 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
699 void Hdisp()                                  
700 {//display events from files if any in current directory or simulated events
701   
702   fParam=AliHMPIDParam::Instance();                          // first invocation of AliHMPIDParam to initialize geometry...
703   fPdg = TDatabasePDG::Instance();                           // first invocation of TDatabasePDG to retrieve particle infos...
704   
705   CreateContainers();
706   CreateRenders();
707   
708   TString title="Session with";
709   if(gSystem->IsFileInIncludePath("HMPID.Hits.root")){// tries to open hits
710     fHitFile=TFile::Open("HMPID.Hits.root");       fNevt=fHitFile->GetNkeys(); fType=1; title+=Form(" HITS-%i ",fNevt);
711   }
712   
713   if(gSystem->IsFileInIncludePath("HMPID.Digits.root")){// tries to open clusters
714      fDigFile=TFile::Open("HMPID.Digits.root");  fNevt=fDigFile->GetNkeys(); fType=1;  title+=Form(" DIGITS-%i ",fNevt);
715    }
716   
717   if(gSystem->IsFileInIncludePath("HMPID.RecPoints.root")){// tries to open clusters
718     fCluFile=TFile::Open("HMPID.RecPoints.root");  fNevt=fCluFile->GetNkeys(); fType=1;  title+=Form(" CLUSTERS-%i ",fNevt);
719    }
720   
721   if(gSystem->IsFileInIncludePath("AliESDs.root")){     
722     fEsdFile=TFile::Open("AliESDs.root"); 
723     fEsdTree=(TTree*)fEsdFile->Get("esdTree"); 
724     fEsd->ReadFromTree(fEsdTree); fEsd->GetStdContent();                       //clm: new ESD schema: see Task Force meeting 20th June, 2007
725     fNevt=fEsdTree->GetEntries(); fType=1;  title+=Form(" ESD-%i ",fNevt);
726     
727     //clm: we need to set the magnetic field  
728     if(gSystem->IsFileInIncludePath("galice.root")){
729     if(gAlice) delete gAlice;                       
730     gAL=AliRunLoader::Open();                       
731     gAL->LoadgAlice();           
732     AliHMPIDTracker::SetFieldMap(gAL->GetAliRun()->Field(),kTRUE);                         
733    }else{
734           Printf("=============== NO galice file! Magnetic field for ESD tracking is: %f ===============",AliTracker::GetBz());
735      }  
736       
737   }
738
739   if(gSystem->IsFileInIncludePath("cosmic.root")){                          //clm: Check if cosmic file is in the folder
740     fCosFile=TFile::Open("cosmic.root");  fCosTree=(TTree*)fCosFile->Get("cosmic");  fNevt=fCosTree->GetEntries();  fType=2;
741     fCosTree->SetBranchAddress("Digs",&fDigLst);   fCosTree->SetBranchAddress("Clus",&fCluLst); 
742   }            
743
744   fCanvas=new TCanvas("all","",-1024,768);fCanvas->SetWindowSize(1024,768);
745   fCanvasImp = fCanvas->GetCanvasImp();
746   fCanvasImp->ShowStatusBar();
747   fCanvas->Divide(3,3,0,0);//  pAll->ToggleEditor();
748   fCanvas->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)",0,0,"DoZoom(Int_t,Int_t,Int_t,TObject*)");
749   fCanvas->cd(7); 
750   gStyle->SetPalette(1,0);
751   switch(fType){
752     case 1: fCanvas->SetTitle(title.Data());                      
753                          TButton *pNxtBtn = new TButton("Next"      ,"NextEvent()"   ,0.0,0.0,0.3,0.1); pNxtBtn->Draw(); 
754                          TButton *pPrvBtn = new TButton("Previous"  ,"PrevEvent()"   ,0.3,0.0,0.6,0.1); pPrvBtn->Draw(); 
755             if(fHitFile){TButton *pHitBtn = new TButton("Print hits","PrintHits()"   ,0.0,0.2,0.3,0.3); pHitBtn->Draw();}  
756             if(fDigFile){TButton *pDigBtn = new TButton("Print digs","PrintDigs()"   ,0.0,0.4,0.3,0.5); pDigBtn->Draw();}  
757             if(fCluFile){TButton *pCluBtn = new TButton("Print clus","PrintClus()"   ,0.0,0.6,0.3,0.7); pCluBtn->Draw();} 
758             if(fEsdFile){TButton *pEsdBtn = new TButton("Print ESD ","PrintEsd()"    ,0.0,0.8,0.3,0.9); pEsdBtn->Draw();}
759             if(fHitFile){      fHitMipBok = new TButton(Form("Mip  %s",fStHitMip.Data()),"SwitchHitMip()",0.3,0.16,0.6,0.22); fHitMipBok->Draw();}
760             if(fHitFile){      fHitCkoBok = new TButton(Form("Ckov %s",fStHitCko.Data()),"SwitchHitCko()",0.3,0.22,0.6,0.28); fHitCkoBok->Draw();}  
761             if(fHitFile){      fHitFeeBok = new TButton(Form("Fdbk %s",fStHitFee.Data()),"SwitchHitFee()",0.3,0.28,0.6,0.34); fHitFeeBok->Draw();}  
762             if(fDigFile){         fDigBok = new TButton(fStDig      ,"SwitchDigs()"  ,0.3,0.4,0.6,0.5); fDigBok->Draw();}  
763             if(fCluFile){         fCluBok = new TButton(fStClu      ,"SwitchClus()"  ,0.3,0.6,0.6,0.7); fCluBok->Draw();} 
764             if(fEsdFile){         fEsdBok = new TButton(fStEsd      ,"SwitchEsd()"   ,0.3,0.8,0.6,0.9); fEsdBok->Draw();}
765
766             if(fHitFile){TButton *fHitMipOnly = new TButton(" Only ","OnlyHitMip()",0.6,0.16,0.9,0.22); fHitMipOnly->Draw();}  
767             if(fHitFile){TButton *fHitCkoOnly = new TButton(" Only ","OnlyHitCko()",0.6,0.22,0.9,0.28); fHitCkoOnly->Draw();}  
768             if(fHitFile){TButton *fHitFeeOnly = new TButton(" Only ","OnlyHitFee()",0.6,0.28,0.9,0.34); fHitFeeOnly->Draw();}  
769             if(fDigFile){TButton *fDigOnly    = new TButton(" Only ","OnlyDigs()"  ,0.6,0.40,0.9,0.50); fDigOnly->Draw();}  
770             if(fCluFile){TButton *fCluOnly    = new TButton(" Only ","OnlyClus()"  ,0.6,0.60,0.9,0.70); fCluOnly->Draw();} 
771             if(fEsdFile){TButton *fEsdOnly    = new TButton(" Only ","OnlyEsd()"   ,0.6,0.80,0.9,0.90); fEsdOnly->Draw();}
772                          TButton *pAll        = new TButton(" ALL  ","All()"       ,0.5,0.90,0.7,1.00); pAll->Draw();
773             
774                                      TButton *pEnd    = new TButton("Quit"      ,"End()"         ,0.6,0.0,0.9,0.1); pEnd->Draw();
775     break;
776     case 2: fCanvas->SetTitle("COSMIC");
777                          TButton *pCosBtn = new TButton("Next"      ,"NextEvent()",0.0,0.0,0.3,0.1); pCosBtn->Draw(); 
778              
779     break;
780     case 3: fCanvas->SetTitle("SIMULATION"); 
781             TButton *pSimBtn = new TButton("Simulate"  ,"NextEvent()",0.0,0.0,0.3,0.1); pSimBtn->Draw(); 
782             TButton *pHitBtn = new TButton("Print hits","PrintHits()",0.0,0.2,0.3,0.3); pHitBtn->Draw();  
783             TButton *pDigBtn = new TButton("Print digs","PrintDigs()",0.0,0.4,0.3,0.5); pDigBtn->Draw();
784             TButton *pCluBtn = new TButton("Print clus","PrintClus()",0.0,0.6,0.3,0.7); pCluBtn->Draw(); 
785             TButton *pEsdBtn = new TButton("Print ESD" ,"PrintEsd()" ,0.0,0.8,0.3,0.9); pEsdBtn->Draw();
786             if(fHitFile){      fHitMipBok = new TButton(Form("Mips %s",fStHitMip.Data()),"SwitchHitMip()",0.3,0.16,0.6,0.22); fHitMipBok->Draw();}  
787             if(fHitFile){      fHitCkoBok = new TButton(Form("Ckov %s",fStHitCko.Data()),"SwitchHitCko()",0.3,0.22,0.6,0.28); fHitCkoBok->Draw();}  
788             if(fHitFile){      fHitFeeBok = new TButton(Form("Fdbk %s",fStHitFee.Data()),"SwitchHitFee()",0.3,0.28,0.6,0.34); fHitFeeBok->Draw();}  
789             if(fDigFile){         fDigBok = new TButton(fStDig      ,"SwitchDigs()"  ,0.3,0.4,0.6,0.5); fDigBok->Draw();}  
790             if(fCluFile){         fCluBok = new TButton(fStClu      ,"SwitchClus()"  ,0.3,0.6,0.6,0.7); fCluBok->Draw();} 
791             if(fEsdFile){         fEsdBok = new TButton(fStEsd      ,"SwitchEsd()"   ,0.3,0.8,0.6,0.9); fEsdBok->Draw();}
792             
793             if(fHitFile){TButton *fHitMipOnly = new TButton(" Only ","OnlyHitMip()",0.6,0.16,0.9,0.22); fHitMipOnly->Draw();}  
794             if(fHitFile){TButton *fHitCkoOnly = new TButton(" Only ","OnlyHitCko()",0.6,0.22,0.9,0.28); fHitCkoOnly->Draw();}  
795             if(fHitFile){TButton *fHitFeeOnly = new TButton(" Only ","OnlyHitFee()",0.6,0.28,0.9,0.34); fHitFeeOnly->Draw();}  
796             if(fDigFile){TButton *fDigOnly    = new TButton(" Only ","OnlyDigs()"  ,0.6,0.40,0.9,0.50); fDigOnly->Draw();}  
797             if(fCluFile){TButton *fCluOnly    = new TButton(" Only ","OnlyClus()"  ,0.6,0.60,0.9,0.70); fCluOnly->Draw();} 
798             if(fEsdFile){TButton *fEsdOnly    = new TButton(" Only ","OnlyEsd()"   ,0.6,0.80,0.9,0.90); fEsdOnly->Draw();}
799                          TButton *pSimAll     = new TButton(" ALL  ","All()"       ,0.5,0.90,0.7,1.00); pSimAll->Draw();
800     break;
801   }
802     
803   NextEvent();           
804       
805 }//Hdisp()
806 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
807 void SwitchHitMip()
808 {
809   fStHitMip=(fStHitMip=="OFF")? "ON":"OFF";
810   GetEvent();
811 }
812 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
813 void SwitchHitCko()
814 {
815   fStHitCko=(fStHitCko=="OFF")? "ON":"OFF";
816   GetEvent();
817 }
818 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
819 void SwitchHitFee()
820 {
821   fStHitFee=(fStHitFee=="OFF")? "ON":"OFF";
822   GetEvent();
823 }
824 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
825 void SwitchDigs()
826 {
827   fStDig=(fStDig=="OFF")? "ON":"OFF";
828   GetEvent();
829 }
830 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
831 void SwitchClus()
832 {
833   fStClu=(fStClu=="OFF")? "ON":"OFF";
834   GetEvent();
835 }
836 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
837 void SwitchEsd()
838 {
839   fStEsd=(fStEsd=="OFF")? "ON":"OFF";
840    GetEvent();
841 }
842 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
843 void AllNo()
844 {
845   if(fHitFile) {
846     fStHitMip = "OFF";
847     fStHitCko = "OFF";
848     fStHitFee = "OFF";
849   }
850   if(fDigFile) fStDig    = "OFF";
851   if(fCluFile) fStClu    = "OFF";
852   if(fEsdFile) fStEsd    = "OFF";
853 }
854 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
855 void AllYes()
856 {
857   if(fHitFile) {
858     fStHitMip = "ON";
859     fStHitCko = "ON";
860     fStHitFee = "ON";
861   }
862   if(fDigFile) fStDig    = "ON";
863   if(fCluFile) fStClu    = "ON";
864   if(fEsdFile) fStEsd    = "ON";
865 }
866 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
867 void All()
868 {
869   AllYes();
870   GetEvent();
871 }
872 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
873 void OnlyHitMip()
874 {
875   AllNo();
876   fStHitMip = "ON";
877   GetEvent();
878 }
879 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
880 void OnlyHitCko()
881 {
882   AllNo();
883   fStHitCko = "ON";
884   GetEvent();
885 }
886 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
887 void OnlyHitFee()
888 {
889   AllNo();
890   fStHitFee = "ON";
891   GetEvent();
892 }
893 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
894 void OnlyDigs()
895 {
896   AllNo();
897   fStDig    = "ON";
898   GetEvent();
899 }
900 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
901 void OnlyClus()
902 {
903   AllNo();
904   fStClu    = "ON";
905   GetEvent();
906 }
907 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
908 void OnlyEsd()
909 {
910   AllNo();
911   fStEsd    = "ON";
912   GetEvent();
913 }
914 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++