New features for the private event display
[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 <TStyle.h>
10 #include <TString.h>
11 #include <TClonesArray.h>
12 #include <TParticle.h>
13 #include <TRandom.h>
14 #include <TLatex.h>
15 #include <TPDGCode.h>
16 #include <TLegend.h>
17 #include <TPolyMarker.h>
18 #include <TBox.h>
19 #include <AliESDEvent.h>
20 #include <AliCDBManager.h>
21 #include <AliCDBEntry.h>
22 #include "AliHMPIDHit.h"
23 #include "AliHMPIDv2.h"
24 #include "AliHMPIDReconstructor.h"
25 #include "AliHMPIDRecon.h"
26 #include "AliHMPIDParam.h"
27 #include "AliHMPIDCluster.h"
28 #include "AliTracker.h"
29
30 #endif
31
32 TCanvas *fCanvas=0; Int_t fType=3; Int_t fEvt=-1; Int_t fNevt=0;                      
33 TFile *fHitFile; TTree *fHitTree; TClonesArray *fHitLst; TPolyMarker *fRenMip[7]; TPolyMarker *fRenCko[7]; TPolyMarker *fRenFee[7];
34                                   TClonesArray *fSdiLst; 
35 TFile *fDigFile; TTree *fDigTree; TObjArray    *fDigLst; TBox *fRenDig[7][160*144]; TBox *fBox[7][160*144];   
36 TFile *fCluFile; TTree *fCluTree; TObjArray    *fCluLst; TPolyMarker *fRenClu[7];    
37 TFile *fEsdFile; TTree *fEsdTree; AliESDEvent  *fEsd;    TPolyMarker *fRenTxC[7]; TPolyMarker *fRenRin[7];  
38 TFile *fCosFile; TTree *fCosTree;
39
40 TButton *fHitMipBok,*fHitCkoBok,*fHitFeeBok,*fDigBok,*fCluBok,*fEsdBok;
41
42 TString fStHitMip = "ON";
43 TString fStHitCko = "ON";
44 TString fStHitFee = "ON";
45 TString fStDig    = "ON";
46 TString fStClu    = "ON";
47 TString fStEsd    = "ON";
48
49 Int_t fTimeArrow = 1;
50
51 Int_t fMaxCharge = 200;  //maximum charge to saturate color to red
52
53 AliRunLoader *gAL=0; 
54
55 Int_t nDigs[7];
56 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
57 void CreateContainers()
58 {//to create all containers
59   fHitLst=new TClonesArray("AliHMPIDHit");
60   fSdiLst=new TClonesArray("AliHMPIDDigit");
61   fDigLst=new TObjArray(7); for(Int_t i=0;i<7;i++) fDigLst->AddAt(new TClonesArray("AliHMPIDDigit"),i);       fDigLst->SetOwner(kTRUE);
62   fCluLst=new TObjArray(7); for(Int_t i=0;i<7;i++) fCluLst->AddAt(new TClonesArray("AliHMPIDCluster"),i);     fCluLst->SetOwner(kTRUE); 
63   fEsd   =new AliESDEvent;
64 }
65 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
66 void CreateRenders()
67 {
68   for(Int_t ch=0;ch<7;ch++){
69     fRenMip[ch]=new TPolyMarker; fRenMip[ch]->SetMarkerStyle(kOpenTriangleUp);  fRenMip[ch]->SetMarkerColor(kBlack);
70     fRenCko[ch]=new TPolyMarker; fRenCko[ch]->SetMarkerStyle(kOpenCircle);      fRenCko[ch]->SetMarkerColor(kBlack);
71     fRenFee[ch]=new TPolyMarker; fRenFee[ch]->SetMarkerStyle(kOpenDiamond);     fRenFee[ch]->SetMarkerColor(kBlack);
72     fRenClu[ch]=new TPolyMarker; fRenClu[ch]->SetMarkerStyle(kStar);            fRenClu[ch]->SetMarkerColor(kMagenta);
73     fRenTxC[ch]=new TPolyMarker; fRenTxC[ch]->SetMarkerStyle(kPlus);            fRenTxC[ch]->SetMarkerColor(kRed);      fRenTxC[ch]->SetMarkerSize(3);
74     fRenRin[ch]=new TPolyMarker; fRenRin[ch]->SetMarkerStyle(kFullDotSmall);    fRenRin[ch]->SetMarkerColor(kMagenta);
75     for(Int_t iDig=0;iDig<160*144;iDig++) {
76       fRenDig[ch][iDig] = new TBox;
77       fRenDig[ch][iDig]->SetFillStyle(1);
78       fBox[ch][iDig] = new TBox;
79       fBox[ch][iDig]->SetFillStyle(0);
80     }
81   }
82 }//CreateRenders()
83 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
84 void ClearRenders()
85 {
86   for(Int_t ch=0;ch<7;ch++){
87     fRenTxC[ch]->SetPolyMarker(0); 
88     fRenRin[ch]->SetPolyMarker(0); 
89     fRenMip[ch]->SetPolyMarker(0); 
90     fRenCko[ch]->SetPolyMarker(0); 
91     fRenFee[ch]->SetPolyMarker(0); 
92     nDigs[ch] = 0;
93     fRenClu[ch]->SetPolyMarker(0); 
94   }
95 }//ClearRenders()
96 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
97 void PrintHits()
98 {
99 //Prints a list of HMPID hits for a given event. Default is event number 0.
100   if(!fHitTree) return;
101   Printf("List of HMPID hits for event %i",fEvt);
102   Int_t iTot=0;
103   for(Int_t iEnt=0;iEnt<fHitTree->GetEntries();iEnt++){//entries loop
104     fHitTree->GetEntry(iEnt);      
105     fHitLst->Print();
106     iTot+=fHitLst->GetEntries();
107   }
108   Printf("totally %i hits for event %i",iTot,fEvt);
109 }//PrintHits();
110 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
111 void PrintSdis()
112 {//prints a list of HMPID sdigits  for a given event
113   Printf("List of HMPID sdigits for event %i",fEvt);
114   fSdiLst->Print();
115   Printf("totally %i sdigits for event %i",fSdiLst->GetEntries(),fEvt);
116 }//PrintSdis()
117 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
118 void PrintDigs()
119 {//prints a list of HMPID digits
120   Printf("List of HMPID digits for event %i",fEvt);  
121   fDigLst->Print();
122   Int_t iTot=0;  for(Int_t i=0;i<7;i++) {iTot+=((TClonesArray*)fDigLst->At(i))->GetEntries();}
123   Printf("totally %i digits for event %i",iTot,fEvt);
124 }
125 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
126 void PrintClus()
127 {//prints a list of HMPID clusters  for a given event
128   Printf("List of HMPID clusters for event %i",fEvt);
129   
130   fCluLst->Print();
131   Int_t iTot=0; for(Int_t iCh=0;iCh<7;iCh++) iTot+=((TClonesArray*)fCluLst->At(iCh))->GetEntries();
132   
133   Printf("totally %i clusters for event %i",iTot,fEvt);
134 }
135 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
136 void PrintEsd()
137 {//prints a list of HMPID Esd  for a given event
138   Printf("List of HMPID ESD summary for event %i",fEvt);
139   for(Int_t iTrk=0;iTrk<fEsd->GetNumberOfTracks();iTrk++){
140     AliESDtrack *pTrk = fEsd->GetTrack(iTrk);
141     Float_t x,y;Int_t q,nacc;   pTrk->GetHMPIDmip(x,y,q,nacc);
142     Printf("Track %02i with p %7.2f with ThetaCer %5.3f with %i photons",iTrk,pTrk->GetP(),pTrk->GetHMPIDsignal(),nacc);
143   }  
144 }//PrintEsd()
145 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
146 void DrawChamber(Int_t iCh) 
147 {//used by Draw() to Draw() chamber structure
148   gPad->Range(-10,-10,AliHMPIDParam::SizeAllX()+5,AliHMPIDParam::SizeAllY()+5);
149   if(iCh>=0){TLatex txt; txt.SetTextSize(0.1); txt.DrawLatex(-5,-5,Form("%i",iCh));}
150   
151   for(Int_t iPc=AliHMPIDParam::kMinPc;iPc<=AliHMPIDParam::kMaxPc;iPc++){
152     TBox *pBox=new TBox(AliHMPIDParam::MinPcX(iPc),AliHMPIDParam::MinPcY(iPc),
153                         AliHMPIDParam::MaxPcX(iPc),AliHMPIDParam::MaxPcY(iPc));
154     pBox->SetFillStyle(0);  pBox->Draw();
155   }//PC loop      
156 }//DrawChamber()
157 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
158 void DrawLegend()
159 {//used by Draw() to draw legend
160   Int_t nTxC=0,nMip=0,nCko=0,nFee=0,nDig=0,nClu=0;
161   for(Int_t ch=0;ch<7;ch++){
162     nTxC+=fRenTxC[ch]->GetLastPoint()+1;
163     nMip+=fRenMip[ch]->GetLastPoint()+1;
164     nCko+=fRenCko[ch]->GetLastPoint()+1;
165     nFee+=fRenFee[ch]->GetLastPoint()+1;
166     nClu+=fRenClu[ch]->GetLastPoint()+1;
167     nDig+=nDigs[ch];
168   }
169   TLegend *pLeg=new TLegend(0.2,0.2,0.8,0.8);
170   pLeg->SetHeader(Form("Event %i Total %i",fEvt,fNevt));
171   pLeg->AddEntry(fRenTxC[0],   Form("TRKxPC %i"     ,nTxC),"p");
172   pLeg->AddEntry(fRenMip[0],   Form("Mip hits %i"   ,nMip),"p");    
173   pLeg->AddEntry(fRenCko[0],   Form("Ckov hits %i"  ,nCko),"p");    
174   pLeg->AddEntry(fRenFee[0],   Form("Feed hits %i"  ,nFee),"p");    
175   pLeg->AddEntry(fRenDig[0][0],Form("Digs %i"       ,nDig),"p");    
176   pLeg->AddEntry(fRenClu[0],   Form("Clus %i"       ,nClu),"p");    
177   pLeg->Draw();
178 }//DrawLegend()
179 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
180 void Draw()
181 {//draws all the objects of current event in given canvas
182   Int_t iPadN[7]={9,8,6,5,4,2,1};
183   Int_t sampleCol = fMaxCharge/gStyle->GetNumberOfColors();
184   for(Int_t iCh=0;iCh<7;iCh++){//chambers loop    
185     fCanvas->cd(iPadN[iCh]);
186     gPad->SetEditable(kTRUE); gPad->Clear(); DrawChamber(iCh);
187     
188     if(fStDig   =="ON") {
189       for(Int_t iDig=0;iDig<nDigs[iCh];iDig++) {
190         Int_t charge = fRenDig[iCh][iDig]->GetUniqueID();
191         Int_t color = charge/sampleCol;if(color>=fMaxCharge) color = gStyle->GetNumberOfColors()-1;
192         fRenDig[iCh][iDig]->SetFillColor(gStyle->GetColorPalette(color));
193         fRenDig[iCh][iDig]->Draw();
194         fBox[iCh][iDig]->Draw();
195       }
196     }
197     if(fStEsd   =="ON") fRenTxC[iCh]->Draw();
198     if(fStHitMip=="ON") fRenMip[iCh]->Draw();
199     if(fStHitFee=="ON") fRenFee[iCh]->Draw();
200     if(fStHitCko=="ON") fRenCko[iCh]->Draw();
201     if(fStEsd   =="ON") fRenRin[iCh]->Draw();
202     if(fStClu   =="ON") fRenClu[iCh]->Draw();
203     gPad->SetEditable(kFALSE);
204   }//chambers loop
205   fCanvas->cd(3);  gPad->Clear(); DrawLegend();
206   
207   fCanvas->cd(7);
208   
209   if(fHitFile){fHitMipBok->SetTitle(Form("Mips  %s",fStHitMip.Data())); fHitMipBok->Modified();}
210   if(fHitFile){fHitCkoBok->SetTitle(Form("Ckov  %s",fStHitCko.Data())); fHitCkoBok->Modified();}
211   if(fHitFile){fHitFeeBok->SetTitle(Form("Fdbk  %s",fStHitFee.Data())); fHitFeeBok->Modified();}
212   if(fDigFile){fDigBok->SetTitle(fStDig); fDigBok->Modified();}  
213   if(fCluFile){fCluBok->SetTitle(fStClu); fCluBok->Modified();} 
214   if(fEsdFile){fEsdBok->SetTitle(fStEsd); fEsdBok->Modified();}
215   
216 }//Draw()
217 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
218 void RenderHit(TClonesArray *pHitLst)
219 {//used by ReadEvent() and SimulateEvent() to render hits to polymarker structures, one per chamber
220   for(Int_t iHit=0;iHit<pHitLst->GetEntries();iHit++){       //hits loop
221     AliHMPIDHit *pHit = (AliHMPIDHit*)pHitLst->At(iHit); Int_t ch=pHit->Ch(); Float_t x=pHit->LorsX(); Float_t y=pHit->LorsY();    //get current hit        
222     switch(pHit->Pid()){
223       case 50000050: fRenCko[ch]->SetNextPoint(x,y);break; 
224       case 50000051: fRenFee[ch]->SetNextPoint(x,y);break;
225       default:       fRenMip[ch]->SetNextPoint(x,y);break;
226     }//switch hit PID      
227   }//hits loop for this entry
228 }//RenderHits()
229 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
230 void RenderDig(TObjArray *pDigLst)
231 {//used by ReadEvent() and SimulateEvent() to render digs to Tbox structures, one per chamber
232   for(Int_t iCh=0;iCh<=6;iCh++){                                    //chambers loop   
233     TClonesArray *pDigCham=(TClonesArray*)pDigLst->At(iCh);         //get digs list for this chamber
234     nDigs[iCh] = 0;
235     for(Int_t iDig=0;iDig<pDigCham->GetEntries();iDig++){            //digs loop
236       AliHMPIDDigit *pDig = (AliHMPIDDigit*)pDigCham->At(iDig); Float_t x=pDig->LorsX(); Float_t y=pDig->LorsY();    //get current hit        
237       fRenDig[iCh][iDig]->SetX1(x-0.5*AliHMPIDParam::SizePadX());
238       fRenDig[iCh][iDig]->SetX2(x+0.5*AliHMPIDParam::SizePadX());
239       fRenDig[iCh][iDig]->SetY1(y-0.5*AliHMPIDParam::SizePadY());
240       fRenDig[iCh][iDig]->SetY2(y+0.5*AliHMPIDParam::SizePadY());
241       fRenDig[iCh][iDig]->SetUniqueID((Int_t)pDig->Q());
242       fBox[iCh][iDig]->SetX1(x-0.5*AliHMPIDParam::SizePadX());
243       fBox[iCh][iDig]->SetX2(x+0.5*AliHMPIDParam::SizePadX());
244       fBox[iCh][iDig]->SetY1(y-0.5*AliHMPIDParam::SizePadY());
245       fBox[iCh][iDig]->SetY2(y+0.5*AliHMPIDParam::SizePadY());
246       nDigs[iCh]++;
247     }//Digit loop
248   }//hits loop for this entry
249 }//RenderHits()
250 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
251 void RenderClu(TObjArray *pClus)
252 {//used by ReadEvent() and SimulateEvent() to render clusters to polymarker structures, one per chamber
253   for(Int_t iCh=0;iCh<=6;iCh++){                                     //chambers loop   
254     TClonesArray *pClusCham=(TClonesArray*)pClus->At(iCh);           //get clusters list for this chamber
255     for(Int_t iClu=0;iClu<pClusCham->GetEntries();iClu++){           //clusters loop
256       AliHMPIDCluster *pClu = (AliHMPIDCluster*)pClusCham->At(iClu); //get current cluster        
257       fRenClu[iCh]->SetNextPoint(pClu->X(),pClu->Y()); 
258 //      Printf("RenderClu: ch %i x %f y %f",iCh,pClu->X(),pClu->Y());
259     }//cluster loop
260   }//chamber loop for this entry
261 }//RenderClus()
262 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
263 void RenderEsd(AliESDEvent *pEsd)
264 {//used by ReadEvent() or SimulateEvent() to render ESD to polymarker structures for rings and intersections one per chamber
265   AliHMPIDRecon rec;
266   for(Int_t iTrk=0;iTrk<pEsd->GetNumberOfTracks();iTrk++){//tracks loop to collect cerenkov rings and intersection points
267     AliESDtrack *pTrk=pEsd->GetTrack(iTrk);    Int_t ch=pTrk->GetHMPIDcluIdx(); //get track and chamber intersected by it
268     if(ch<0) continue;                                                          //this track does not intersect any chamber
269     Float_t thRa,phRa,xRa,yRa; pTrk->GetHMPIDtrk(xRa,yRa,thRa,phRa);            //get info on current track
270     ch/=1000000;                            
271     Float_t xPc=0,yPc=0; AliHMPIDTracker::IntTrkCha(pTrk,xPc,yPc);              //find again intersection of track with PC--> it is not stored in ESD!
272     fRenTxC[ch]->SetNextPoint(xPc,yPc);                                            //add this intersection point
273     Float_t ckov=pTrk->GetHMPIDsignal();                                        //get ckov angle stored for this track  
274     if(ckov>0){
275       rec.SetTrack(xRa,yRa,thRa,phRa);
276       for(Int_t j=0;j<500;j++){
277         TVector2 pos; pos=rec.TracePhot(ckov,j*6.28/500.);
278        if(!AliHMPIDParam::IsInDead(pos.X(),pos.Y())) fRenRin[ch]->SetNextPoint(pos.X(),pos.Y());
279       }      
280     }//if ckov is valid
281   }//tracks loop  
282 }//RenEsd()
283 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
284 void SimulateEsd(AliESDEvent *pEsd)
285 {
286   TParticle part; TLorentzVector mom;
287   for(Int_t iTrk=0;iTrk<100;iTrk++){//stack loop
288     Printf("SimulateEsd: kProton %i",kProton);
289     part.SetPdgCode(kProton);
290     part.SetProductionVertex(0,0,0,0);
291     Double_t eta= -0.2+gRandom->Rndm()*0.4; //rapidity is random [-0.2,+0.2]
292     Double_t phi= gRandom->Rndm()*60.*TMath::DegToRad();   //phi is random      [ 0  , 60 ] degrees    
293     mom.SetPtEtaPhiM(5,eta,phi,part.GetMass());
294     part.SetMomentum(mom);
295     AliESDtrack trk(&part);
296     pEsd->AddTrack(&trk);
297   }//stack loop  
298 }//EsdFromStack()
299 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
300 void SimulateHits(AliESDEvent *pEsd, TClonesArray *pHits)
301 {//used by SimulateEvent to simulate hits out from provided ESD
302   const Int_t kCerenkov=50000050;
303   const Int_t kFeedback=50000051;
304   
305   AliHMPIDRecon rec;
306   Float_t eMip=200e-9,ePho=7.5e-9; 
307   Int_t hc=0; 
308   for(Int_t iTrk=0;iTrk<pEsd->GetNumberOfTracks();iTrk++){//tracks loop
309     AliESDtrack *pTrk=pEsd->GetTrack(iTrk);
310     Float_t xRa,yRa;
311     Int_t ch=AliHMPIDTracker::IntTrkCha(pTrk,xRa,yRa);
312     if(ch<0) continue; //this track does not hit HMPID
313     Float_t beta = pTrk->GetP()/(TMath::Sqrt(pTrk->GetP()*pTrk->GetP()+0.938*0.938));
314     Float_t ckov=TMath::ACos(1./(beta*1.292));
315
316     Float_t theta,phi,xPc,yPc,; pTrk->GetHMPIDtrk(xPc,yPc,theta,phi); rec.SetTrack(xRa,yRa,theta,phi); 
317     
318     if(!AliHMPIDParam::IsInDead(xPc,yPc)) new((*pHits)[hc++]) AliHMPIDHit(ch,eMip,kProton  ,iTrk,xPc,yPc);                 //mip hit
319     Int_t nPhots = (Int_t)(20.*TMath::Power(TMath::Sin(ckov),2)/TMath::Power(TMath::Sin(TMath::ACos(1./1.292)),2));
320     for(int i=0;i<nPhots;i++){
321       TVector2 pos;
322       pos=rec.TracePhot(ckov,gRandom->Rndm()*TMath::TwoPi());
323       if(!AliHMPIDParam::IsInDead(pos.X(),pos.Y())) new((*pHits)[hc++]) AliHMPIDHit(ch,ePho,kCerenkov,iTrk,pos.X(),pos.Y());
324     }                      //photon hits  
325     for(int i=0;i<3;i++){//feedback photons
326       Float_t x=gRandom->Rndm()*160; Float_t y=gRandom->Rndm()*150;
327       if(!AliHMPIDParam::IsInDead(x,y)) new((*pHits)[hc++]) AliHMPIDHit(ch,ePho,kFeedback,iTrk,x,y);                 //feedback hits  
328     }//photon hits loop                      
329   }//tracks loop    
330 }//SimulateHits()
331 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
332 void DoZoom(Int_t evt, Int_t px, Int_t py, TObject *)
333 {
334   Int_t iChamN[9]={6,5,-1,4,3,2,-1,1,0};
335   if(evt!=5 && evt!=6) return; //5- zoom in 6-zoom out
336   const Int_t minZoom=64;
337   const Int_t maxZoom=2;
338   static Int_t zoom[7]={64,64,64,64,64,64,64}; //zoom level
339   
340  // if(!obj->IsA()->InheritsFrom("TPad")) return;  //current object is not pad
341   TVirtualPad *pPad=gPad->GetSelectedPad();
342   Int_t padN = pPad->GetNumber()-1;
343   if(padN<0 || padN>8) return;
344   
345   Int_t iCh = iChamN[padN];
346   if(iCh < 0) return;
347   
348   if(evt==5&&zoom[iCh]==maxZoom) return; 
349   if(evt==6&&zoom[iCh]==minZoom) return; 
350     
351   Float_t x=pPad->AbsPixeltoX(px); Float_t y=pPad->AbsPixeltoY(py); 
352  
353   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
354   else      { 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 
355   if(zoom[iCh]==minZoom) pPad->Range(-10,-10,AliHMPIDParam::SizeAllX()+5,AliHMPIDParam::SizeAllY()+5);
356   ((TCanvas *)gTQSender)->SetTitle(Form("zoom x%i",minZoom/zoom[iCh]));
357   pPad->Modified();
358   pPad->Update();                                              
359 }
360 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
361 void ReadEvent()
362 {//used by NextEvent()  to read curent event and construct all render elements
363   if(fNevt && fEvt>=fNevt) fEvt=0; //loop over max event
364   if(fNevt && fEvt<0) fEvt=fNevt-1; //loop over max event
365   
366   if(fHitFile){ 
367     if(fHitTree) delete fHitTree;   fHitTree=(TTree*)fHitFile->Get(Form("Event%i/TreeH",fEvt));
368     
369                           fHitTree->SetBranchAddress("HMPID",&fHitLst);
370     for(Int_t iEnt=0;iEnt<fHitTree->GetEntries();iEnt++){    
371                           fHitTree->GetEntry(iEnt);                              
372       RenderHit(fHitLst);   
373     }//prim loop
374   }//if hits file
375
376   if(fDigFile){ 
377     if(fDigTree) delete fDigTree;   fDigTree=(TTree*)fDigFile->Get(Form("Event%i/TreeD",fEvt));
378     for(Int_t iCh=AliHMPIDParam::kMinCh;iCh<=AliHMPIDParam::kMaxCh;iCh++) fDigTree->SetBranchAddress(Form("HMPID%i",iCh),&(*fDigLst)[iCh]);      
379     fDigTree->GetEntry(0);                              
380     RenderDig(fDigLst);   
381   }//if digs file
382     
383   if(fCluFile){ 
384     if(fCluTree) delete fCluTree; fCluTree=(TTree*)fCluFile->Get(Form("Event%i/TreeR",fEvt));
385     for(Int_t iCh=AliHMPIDParam::kMinCh;iCh<=AliHMPIDParam::kMaxCh;iCh++) fCluTree->SetBranchAddress(Form("HMPID%i",iCh),&(*fCluLst)[iCh]);      
386     fCluTree->GetEntry(0);
387     RenderClu(fCluLst);   
388   }//if clus file
389   
390   if(fEsdFile){//if ESD file open
391     fEsdTree->GetEntry(fEvt);  
392     RenderEsd(fEsd);
393   }//if ESD file 
394 }//ReadEvent()
395 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
396 void SimulateEvent()
397 {// used by NextEvent() to simulate all info
398   AliCDBManager* pCDB = AliCDBManager::Instance();  pCDB->SetDefaultStorage("local://$HOME"); pCDB->SetRun(0);
399   AliCDBEntry *pNmeanEnt=pCDB->Get("HMPID/Calib/Nmean");
400
401   SimulateEsd(fEsd);
402   SimulateHits(fEsd,fHitLst);
403                  AliHMPIDv2::Hit2Sdi(fHitLst,fSdiLst);                               
404           AliHMPIDDigitizer::Sdi2Dig(fSdiLst,fDigLst);     
405       AliHMPIDReconstructor::Dig2Clu(fDigLst,fCluLst);
406             AliHMPIDTracker::Recon(fEsd,fCluLst,(TObjArray*)pNmeanEnt->GetObject());
407             
408   RenderHit(fHitLst);
409   RenderClu(fCluLst);
410   RenderEsd(fEsd);            
411 }//SimulateEvent()
412 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
413 void GetEvent()
414 {
415   ClearRenders();
416   CheckStatus();
417   switch(fType){
418     case 1: ReadEvent();break;
419 //    case 2: ReadCosmic(); break;
420     case 3: SimulateEvent();     break;
421     default:                 return;
422   }  
423   Draw();
424 }
425 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
426 void NextEvent()
427 {
428   fTimeArrow = 1;
429   fEvt+=fTimeArrow;
430   GetEvent();
431 }
432 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
433 void PrevEvent()
434 {
435   fTimeArrow = -1;
436   fEvt+=fTimeArrow;
437   GetEvent();
438 }
439 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
440 void End()
441 {
442   gSystem->Exit(0);
443 }
444 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
445 void Hdisp()                                  
446 {//display events from files if any in current directory or simulated events
447   AliHMPIDParam::Instance();                          // first invocation of AliHMPIDParam to initialize geometry...
448   CreateContainers();
449   CreateRenders();
450   
451   TString title="Session with";
452   if(gSystem->IsFileInIncludePath("HMPID.Hits.root")){// tries to open hits
453     fHitFile=TFile::Open("HMPID.Hits.root");       fNevt=fHitFile->GetNkeys(); fType=1; title+=Form(" HITS-%i ",fNevt);
454   }
455   
456   if(gSystem->IsFileInIncludePath("HMPID.Digits.root")){// tries to open clusters
457      fDigFile=TFile::Open("HMPID.Digits.root");  fNevt=fDigFile->GetNkeys(); fType=1;  title+=Form(" DIGITS-%i ",fNevt);
458    }
459   
460   if(gSystem->IsFileInIncludePath("HMPID.RecPoints.root")){// tries to open clusters
461     fCluFile=TFile::Open("HMPID.RecPoints.root");  fNevt=fCluFile->GetNkeys(); fType=1;  title+=Form(" CLUSTERS-%i ",fNevt);
462    }
463   
464   if(gSystem->IsFileInIncludePath("AliESDs.root")){     
465     fEsdFile=TFile::Open("AliESDs.root"); 
466     fEsdTree=(TTree*)fEsdFile->Get("esdTree"); 
467     fEsd->ReadFromTree(fEsdTree); fEsd->GetStdContent();                       //clm: new ESD schema: see Task Force meeting 20th June, 2007
468     fNevt=fEsdTree->GetEntries(); fType=1;  title+=Form(" ESD-%i ",fNevt);
469     
470     //clm: we need to set the magnetic field  
471     if(gSystem->IsFileInIncludePath("galice.root")){
472     if(gAlice) delete gAlice;                       
473     gAL=AliRunLoader::Open();                       
474     gAL->LoadgAlice();           
475     AliHMPIDTracker::SetFieldMap(gAL->GetAliRun()->Field(),kTRUE);                         
476    }else{
477           Printf("=============== NO galice file! Magnetic field for ESD tracking is: %f ===============",AliTracker::GetBz());
478      }  
479       
480   }
481
482   if(gSystem->IsFileInIncludePath("cosmic.root")){                          //clm: Check if cosmic file is in the folder
483     fCosFile=TFile::Open("cosmic.root");  fCosTree=(TTree*)fCosFile->Get("cosmic");  fNevt=fCosTree->GetEntries();  fType=2;
484     fCosTree->SetBranchAddress("Digs",&fDigLst);   fCosTree->SetBranchAddress("Clus",&fCluLst); 
485   }            
486
487   fCanvas=new TCanvas("all","",1024,768);fCanvas->SetWindowSize(1024,768);
488   fCanvas->ToggleEventStatus();
489   fCanvas->Divide(3,3,0,0);//  pAll->ToggleEditor();
490   fCanvas->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)",0,0,"DoZoom(Int_t,Int_t,Int_t,TObject*)");
491   fCanvas->cd(7); 
492   gStyle->SetPalette(1,0);
493   switch(fType){
494     case 1: fCanvas->SetTitle(title.Data());                      
495                          TButton *pNxtBtn = new TButton("Next"      ,"NextEvent()"   ,0.0,0.0,0.3,0.1); pNxtBtn->Draw(); 
496                          TButton *pPrvBtn = new TButton("Previous"  ,"PrevEvent()"   ,0.3,0.0,0.6,0.1); pPrvBtn->Draw(); 
497             if(fHitFile){TButton *pHitBtn = new TButton("Print hits","PrintHits()"   ,0.0,0.2,0.3,0.3); pHitBtn->Draw();}  
498             if(fDigFile){TButton *pDigBtn = new TButton("Print digs","PrintDigs()"   ,0.0,0.4,0.3,0.5); pDigBtn->Draw();}  
499             if(fCluFile){TButton *pCluBtn = new TButton("Print clus","PrintClus()"   ,0.0,0.6,0.3,0.7); pCluBtn->Draw();} 
500             if(fEsdFile){TButton *pEsdBtn = new TButton("Print ESD ","PrintEsd()"    ,0.0,0.8,0.3,0.9); pEsdBtn->Draw();}
501             if(fHitFile){      fHitMipBok = new TButton(Form("Mip  %s",fStHitMip.Data()),"SwitchHitMip()",0.3,0.16,0.6,0.22); fHitMipBok->Draw();}
502             if(fHitFile){      fHitCkoBok = new TButton(Form("Ckov %s",fStHitCko.Data()),"SwitchHitCko()",0.3,0.22,0.6,0.28); fHitCkoBok->Draw();}  
503             if(fHitFile){      fHitFeeBok = new TButton(Form("Fdbk %s",fStHitFee.Data()),"SwitchHitFee()",0.3,0.28,0.6,0.34); fHitFeeBok->Draw();}  
504             if(fDigFile){         fDigBok = new TButton(fStDig      ,"SwitchDigs()"  ,0.3,0.4,0.6,0.5); fDigBok->Draw();}  
505             if(fCluFile){         fCluBok = new TButton(fStClu      ,"SwitchClus()"  ,0.3,0.6,0.6,0.7); fCluBok->Draw();} 
506             if(fEsdFile){         fEsdBok = new TButton(fStEsd      ,"SwitchEsd()"   ,0.3,0.8,0.6,0.9); fEsdBok->Draw();}
507
508             if(fHitFile){TButton *fHitMipOnly = new TButton(" Only ","OnlyHitMip()",0.6,0.16,0.9,0.22); fHitMipOnly->Draw();}  
509             if(fHitFile){TButton *fHitCkoOnly = new TButton(" Only ","OnlyHitCko()",0.6,0.22,0.9,0.28); fHitCkoOnly->Draw();}  
510             if(fHitFile){TButton *fHitFeeOnly = new TButton(" Only ","OnlyHitFee()",0.6,0.28,0.9,0.34); fHitFeeOnly->Draw();}  
511             if(fDigFile){TButton *fDigOnly    = new TButton(" Only ","OnlyDigs()"  ,0.6,0.40,0.9,0.50); fDigOnly->Draw();}  
512             if(fCluFile){TButton *fCluOnly    = new TButton(" Only ","OnlyClus()"  ,0.6,0.60,0.9,0.70); fCluOnly->Draw();} 
513             if(fEsdFile){TButton *fEsdOnly    = new TButton(" Only ","OnlyEsd()"   ,0.6,0.80,0.9,0.90); fEsdOnly->Draw();}
514                          TButton *fAll        = new TButton(" ALL  ","All()"       ,0.5,0.90,0.7,1.00); fAll->Draw();
515             
516                                      TButton *pEnd    = new TButton("Quit"      ,"End()"         ,0.6,0.0,0.9,0.1); pEnd->Draw();
517     break;
518     case 2: fCanvas->SetTitle("COSMIC");
519                          TButton *pCosBtn = new TButton("Next"      ,"NextEvent()",0.0,0.0,0.3,0.1); pCosBtn->Draw(); 
520              
521     break;
522     case 3: fCanvas->SetTitle("SIMULATION"); 
523             TButton *pSimBtn = new TButton("Simulate"  ,"NextEvent()",0.0,0.0,0.3,0.1); pSimBtn->Draw(); 
524             TButton *pHitBtn = new TButton("Print hits","PrintHits()",0.0,0.2,0.3,0.3); pHitBtn->Draw();  
525             TButton *pDigBtn = new TButton("Print digs","PrintDigs()",0.0,0.4,0.3,0.5); pDigBtn->Draw();
526             TButton *pCluBtn = new TButton("Print clus","PrintClus()",0.0,0.6,0.3,0.7); pCluBtn->Draw(); 
527             TButton *pEsdBtn = new TButton("Print ESD" ,"PrintEsd()" ,0.0,0.8,0.3,0.9); pEsdBtn->Draw();
528             if(fHitFile){      fHitMipBok = new TButton(Form("Mips %s",fStHitMip.Data()),"SwitchHitMip()",0.3,0.16,0.6,0.22); fHitMipBok->Draw();}  
529             if(fHitFile){      fHitCkoBok = new TButton(Form("Ckov %s",fStHitCko.Data()),"SwitchHitCko()",0.3,0.22,0.6,0.28); fHitCkoBok->Draw();}  
530             if(fHitFile){      fHitFeeBok = new TButton(Form("Fdbk %s",fStHitFee.Data()),"SwitchHitFee()",0.3,0.28,0.6,0.34); fHitFeeBok->Draw();}  
531             if(fDigFile){         fDigBok = new TButton(fStDig      ,"SwitchDigs()"  ,0.3,0.4,0.6,0.5); fDigBok->Draw();}  
532             if(fCluFile){         fCluBok = new TButton(fStClu      ,"SwitchClus()"  ,0.3,0.6,0.6,0.7); fCluBok->Draw();} 
533             if(fEsdFile){         fEsdBok = new TButton(fStEsd      ,"SwitchEsd()"   ,0.3,0.8,0.6,0.9); fEsdBok->Draw();}
534             
535             if(fHitFile){TButton *fHitMipOnly = new TButton(" Only ","OnlyHitMip()",0.6,0.16,0.9,0.22); fHitMipOnly->Draw();}  
536             if(fHitFile){TButton *fHitCkoOnly = new TButton(" Only ","OnlyHitCko()",0.6,0.22,0.9,0.28); fHitCkoOnly->Draw();}  
537             if(fHitFile){TButton *fHitFeeOnly = new TButton(" Only ","OnlyHitFee()",0.6,0.28,0.9,0.34); fHitFeeOnly->Draw();}  
538             if(fDigFile){TButton *fDigOnly    = new TButton(" Only ","OnlyDigs()"  ,0.6,0.40,0.9,0.50); fDigOnly->Draw();}  
539             if(fCluFile){TButton *fCluOnly    = new TButton(" Only ","OnlyClus()"  ,0.6,0.60,0.9,0.70); fCluOnly->Draw();} 
540             if(fEsdFile){TButton *fEsdOnly    = new TButton(" Only ","OnlyEsd()"   ,0.6,0.80,0.9,0.90); fEsdOnly->Draw();}
541     break;
542   }
543     
544   NextEvent();           
545       
546 }//Hdisp()
547 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
548 void SwitchHitMip()
549 {
550   fStHitMip=(fStHitMip=="OFF")? "ON":"OFF";
551   GetEvent();
552 }
553 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
554 void SwitchHitCko()
555 {
556   fStHitCko=(fStHitCko=="OFF")? "ON":"OFF";
557   GetEvent();
558 }
559 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
560 void SwitchHitFee()
561 {
562   fStHitFee=(fStHitFee=="OFF")? "ON":"OFF";
563   GetEvent();
564 }
565 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
566 void SwitchDigs()
567 {
568   fStDig=(fStDig=="OFF")? "ON":"OFF";
569   GetEvent();
570 }
571 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
572 void SwitchClus()
573 {
574   fStClu=(fStClu=="OFF")? "ON":"OFF";
575   GetEvent();
576 }
577 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
578 void SwitchEsd()
579 {
580   fStEsd=(fStEsd=="OFF")? "ON":"OFF";
581    GetEvent();
582 }
583 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
584 void AllNo()
585 {
586   fStHitMip = "OFF";
587   fStHitCko = "OFF";
588   fStHitFee = "OFF";
589   fStDig    = "OFF";
590   fStClu    = "OFF";
591   fStEsd    = "OFF";
592 }
593 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
594 void AllYes()
595 {
596   if(fHitFile) fStHitMip = "ON";
597   if(fHitFile) fStHitCko = "ON";
598   if(fHitFile) fStHitFee = "ON";
599   if(fDigFile) fStDig    = "ON";
600   if(fCluFile) fStClu    = "ON";
601   if(fEsdFile) fStEsd    = "ON";
602 }
603 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
604 void All()
605 {
606   AllYes();
607   GetEvent();
608 }
609 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
610 void OnlyHitMip()
611 {
612   AllNo();
613   fStHitMip = "ON";
614   GetEvent();
615 }
616 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
617 void OnlyHitCko()
618 {
619   AllNo();
620   fStHitCko = "ON";
621   GetEvent();
622 }
623 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
624 void OnlyHitFee()
625 {
626   AllNo();
627   fStHitFee = "ON";
628   GetEvent();
629 }
630 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
631 void OnlyDigs()
632 {
633   AllNo();
634   fStDig    = "ON";
635   GetEvent();
636 }
637 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
638 void OnlyClus()
639 {
640   AllNo();
641   fStClu    = "ON";
642   GetEvent();
643 }
644 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
645 void OnlyEsd()
646 {
647   AllNo();
648   fStEsd    = "ON";
649   GetEvent();
650 }
651 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
652 void CheckStatus()
653 {
654 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
655
656   if(fStHitMip=="OFF") {fHitMipBok->SetFillColor(kRed);} else {fHitMipBok->SetFillColor(18);}
657   if(fStHitCko=="OFF") {fHitCkoBok->SetFillColor(kRed);} else {fHitCkoBok->SetFillColor(18);}
658   if(fStHitFee=="OFF") {fHitFeeBok->SetFillColor(kRed);} else {fHitFeeBok->SetFillColor(18);}
659   if(fStDig   =="OFF") {fDigBok->SetFillColor(kRed);} else {fDigBok->SetFillColor(18);}
660   if(fStClu   =="OFF") {fCluBok->SetFillColor(kRed);} else {fCluBok->SetFillColor(18);}
661   if(fStEsd   =="OFF") {fEsdBok->SetFillColor(kRed);} else {fEsdBok->SetFillColor(18);}
662 }
663 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++