HESDfromKin adapted for HTA+minors
[u/mrichter/AliRoot.git] / HMPID / Hdisp.C
1 #if !defined(__CINT__) || defined(__MAKECINT__)
2
3 #include <TSystem.h>
4 #include <TFile.h>
5 #include <TTree.h>
6 #include <TButton.h>
7 #include <TCanvas.h>
8 #include <TClonesArray.h>
9 #include <TParticle.h>
10 #include <TRandom.h>
11 #include <TLatex.h>
12 #include <TLegend.h>
13 #include <TPolyMarker.h>
14 #include <TBox.h>
15 #include <AliESD.h>
16 #include <AliCDBManager.h>
17 #include <AliCDBEntry.h>
18 #include "AliHMPIDHit.h"
19 #include "AliHMPIDv2.h"
20 #include "AliHMPIDReconstructor.h"
21 #include "AliHMPIDRecon.h"
22 #include "AliHMPIDParam.h"
23 #include "AliHMPIDCluster.h"
24 #include <TChain.h>
25
26 #endif
27
28 TCanvas *fCanvas=0; Int_t fType=3; Int_t fEvt=0; Int_t fNevt=0;                      
29 TFile *fHitFile; TTree *fHitTree; TClonesArray *fHitLst; TPolyMarker *fRenMip[7]; TPolyMarker *fRenCko[7]; TPolyMarker *fRenFee[7];
30                                   TClonesArray *fSdiLst; 
31 TFile *fDigFile; TTree *fDigTree; TObjArray    *fDigLst; TPolyMarker *fRenDig[7];    
32 TFile *fCluFile; TTree *fCluTree; TObjArray    *fCluLst; TPolyMarker *fRenClu[7];    
33 TFile *fEsdFile; TTree *fEsdTree;  AliESD      *fEsd;    TPolyMarker *fRenTxC[7]; TPolyMarker *fRenRin[7];  
34 TFile *fCosFile; TTree *fCosTree;
35
36 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
37 void CreateContainers()
38 {//to create all containers
39   fHitLst=new TClonesArray("AliHMPIDHit");
40   fSdiLst=new TClonesArray("AliHMPIDDigit");
41   fDigLst=new TObjArray(7); for(Int_t i=0;i<7;i++) fDigLst->AddAt(new TClonesArray("AliHMPIDDigit"),i);       fDigLst->SetOwner(kTRUE);
42   fCluLst=new TObjArray(7); for(Int_t i=0;i<7;i++) fCluLst->AddAt(new TClonesArray("AliHMPIDCluster"),i);     fCluLst->SetOwner(kTRUE); 
43   fEsd   =new AliESD;
44 }
45 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
46 void CreateRenders()
47 {
48   for(Int_t ch=0;ch<7;ch++){
49     fRenMip[ch]=new TPolyMarker; fRenMip[ch]->SetMarkerStyle(kOpenTriangleUp);  fRenMip[ch]->SetMarkerColor(kRed);
50     fRenCko[ch]=new TPolyMarker; fRenCko[ch]->SetMarkerStyle(kOpenCircle);      fRenCko[ch]->SetMarkerColor(kRed);
51     fRenFee[ch]=new TPolyMarker; fRenFee[ch]->SetMarkerStyle(kOpenDiamond);     fRenFee[ch]->SetMarkerColor(kRed);
52     fRenDig[ch]=new TPolyMarker; fRenDig[ch]->SetMarkerStyle(kOpenSquare);      fRenDig[ch]->SetMarkerColor(kGreen);
53     fRenClu[ch]=new TPolyMarker; fRenClu[ch]->SetMarkerStyle(kStar);            fRenClu[ch]->SetMarkerColor(kBlue);
54     fRenTxC[ch]=new TPolyMarker; fRenTxC[ch]->SetMarkerStyle(kPlus);            fRenTxC[ch]->SetMarkerColor(kRed);      fRenTxC[ch]->SetMarkerSize(3);
55     fRenRin[ch]=new TPolyMarker; fRenRin[ch]->SetMarkerStyle(kFullDotSmall);    fRenRin[ch]->SetMarkerColor(kMagenta);
56   }
57 }//CreateRenders()
58 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
59 void ClearRenders()
60 {
61   for(Int_t ch=0;ch<7;ch++){
62     fRenTxC[ch]->SetPolyMarker(0); 
63     fRenRin[ch]->SetPolyMarker(0); 
64     fRenMip[ch]->SetPolyMarker(0); 
65     fRenCko[ch]->SetPolyMarker(0); 
66     fRenFee[ch]->SetPolyMarker(0); 
67     fRenDig[ch]->SetPolyMarker(0); 
68     fRenClu[ch]->SetPolyMarker(0); 
69   }
70 }//ClearRenders()
71 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
72 void PrintHits()
73 {
74 //Prints a list of HMPID hits for a given event. Default is event number 0.
75   if(!fHitTree) return;
76   Printf("List of HMPID hits for event %i",fEvt);
77   Int_t iTot=0;
78   for(Int_t iEnt=0;iEnt<fHitTree->GetEntries();iEnt++){//entries loop
79     fHitTree->GetEntry(iEnt);      
80     fHitLst->Print();
81     iTot+=fHitLst->GetEntries();
82   }
83   Printf("totally %i hits for event %i",iTot,fEvt);
84 }//PrintHits();
85 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
86 void PrintSdis()
87 {//prints a list of HMPID sdigits  for a given event
88   Printf("List of HMPID sdigits for event %i",fEvt);
89   fSdiLst->Print();
90   Printf("totally %i sdigits for event %i",fSdiLst->GetEntries(),fEvt);
91 }//PrintSdis()
92 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
93 void PrintDigs()
94 {//prints a list of HMPID digits
95   Printf("List of HMPID digits for event %i",fEvt);  
96   fDigLst->Print();
97   Int_t iTot=0;  for(Int_t i=0;i<7;i++) {iTot+=((TClonesArray*)fDigLst->At(i))->GetEntries();}
98   Printf("totally %i digits for event %i",iTot,fEvt);
99 }
100 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
101 void PrintClus()
102 {//prints a list of HMPID clusters  for a given event
103   Printf("List of HMPID clusters for event %i",fEvt);
104   
105   fCluLst->Print();
106   Int_t iTot=0; for(Int_t iCh=0;iCh<7;iCh++) iTot+=((TClonesArray*)fCluLst->At(iCh))->GetEntries();
107   
108   Printf("totally %i clusters for event %i",iTot,fEvt);
109 }
110 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
111 void PrintEsd()
112 {//prints a list of HMPID Esd  for a given event
113   Printf("List of HMPID ESD summary for event %i",fEvt);
114   for(Int_t iTrk=0;iTrk<fEsd->GetNumberOfTracks();iTrk++){
115     AliESDtrack *pTrk = fEsd->GetTrack(iTrk);
116     Float_t x,y;Int_t q,nacc;   pTrk->GetHMPIDmip(x,y,q,nacc);
117     Printf("Track %02i with p %7.2f with ThetaCer %5.3f with %i photons",iTrk,pTrk->GetP(),pTrk->GetHMPIDsignal(),nacc);
118   }  
119 }//PrintEsd()
120 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
121 void DrawChamber(Int_t iCh) 
122 {//used by Draw() to Draw() chamber structure
123   gPad->Range(-10,-10,AliHMPIDDigit::SizeAllX()+5,AliHMPIDDigit::SizeAllY()+5); 
124   if(iCh>=0){TLatex txt; txt.SetTextSize(0.1); txt.DrawLatex(-5,-5,Form("%i",iCh));}
125   
126   for(Int_t iPc=AliHMPIDDigit::kMinPc;iPc<=AliHMPIDDigit::kMaxPc;iPc++){
127     TBox *pBox=new TBox(AliHMPIDDigit::MinPcX(iPc),AliHMPIDDigit::MinPcY(iPc),
128                         AliHMPIDDigit::MaxPcX(iPc),AliHMPIDDigit::MaxPcY(iPc));
129     pBox->SetFillStyle(0);  pBox->Draw();
130   }//PC loop      
131 }//DrawChamber()
132 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
133 void DrawLegend()
134 {//used by Draw() to draw legend
135   Int_t nTxC=0,nMip=0,nCko=0,nFee=0,nDig=0,nClu=0;
136   for(Int_t ch=0;ch<7;ch++){
137     nTxC+=fRenTxC[ch]->GetN();
138     nMip+=fRenMip[ch]->GetN();
139     nCko+=fRenCko[ch]->GetN();
140     nFee+=fRenFee[ch]->GetN();
141     nDig+=fRenDig[ch]->GetN();
142     nClu+=fRenClu[ch]->GetN();
143   }
144   TLegend *pLeg=new TLegend(0.2,0.2,0.8,0.8);
145   pLeg->SetHeader(Form("Event %i Total %i",fEvt,fNevt));
146   pLeg->AddEntry(fRenTxC[0],Form("TRKxPC %i"     ,nTxC),"p");
147   pLeg->AddEntry(fRenMip[0],Form("Mip hits %i"   ,nMip),"p");    
148   pLeg->AddEntry(fRenCko[0],Form("Ckov hits %i"  ,nCko),"p");    
149   pLeg->AddEntry(fRenFee[0],Form("Feed hits %i"  ,nFee),"p");    
150   pLeg->AddEntry(fRenDig[0],Form("Digs %i"       ,nDig),"p");    
151   pLeg->AddEntry(fRenClu[0],Form("Clus %i"       ,nClu),"p");    
152   pLeg->Draw();
153 }//DrawLegend()
154 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
155 void Draw()
156 {//draws all the objects of current event in given canvas
157   for(Int_t iCh=0;iCh<7;iCh++){//chambers loop    
158     switch(iCh){
159       case 6: fCanvas->cd(1); break; case 5: fCanvas->cd(2); break;
160       case 4: fCanvas->cd(4); break; case 3: fCanvas->cd(5); break; case 2: fCanvas->cd(6); break;
161                                      case 1: fCanvas->cd(8); break; case 0: fCanvas->cd(9); break;
162     }
163     gPad->SetEditable(kTRUE); gPad->Clear(); DrawChamber(iCh);
164     fRenTxC[iCh]->Draw();        
165     fRenMip[iCh]->Draw();        
166     fRenFee[iCh]->Draw();        
167     fRenCko[iCh]->Draw();       
168     fRenRin[iCh]->Draw("CLP");   
169     fRenDig[iCh]->Draw();        
170     fRenClu[iCh]->Draw();        
171     gPad->SetEditable(kFALSE);
172   }//chambers loop
173   
174   fCanvas->cd(3);  gPad->Clear(); DrawLegend();
175 }//Draw()
176 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
177 void RenderHit(TClonesArray *pHitLst)
178 {//used by ReadEvent() and SimulateEvent() to render hits to polymarker structures, one per chamber
179   for(Int_t iHit=0;iHit<pHitLst->GetEntries();iHit++){       //hits loop
180     AliHMPIDHit *pHit = (AliHMPIDHit*)pHitLst->At(iHit); Int_t ch=pHit->Ch(); Float_t x=pHit->LorsX(); Float_t y=pHit->LorsY();    //get current hit        
181     switch(pHit->Pid()){
182       case 50000050: fRenCko[ch]->SetNextPoint(x,y);break; 
183       case 50000051: fRenFee[ch]->SetNextPoint(x,y);break;
184       default:       fRenMip[ch]->SetNextPoint(x,y);break;
185     }//switch hit PID      
186   }//hits loop for this entry
187 }//RenderHits()
188 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
189 void RenderClu(TObjArray *pClus,TPolyMarker **pMark)
190 {//used by ReadEvent() and SimulateEvent() to render clusters to polymarker structures, one per chamber
191   for(Int_t iCh=0;iCh<=6;iCh++){                                     //chambers loop   
192     TClonesArray *pClusCham=(TClonesArray*)pClus->At(iCh);           //get clusters list for this chamber
193     for(Int_t iClu=0;iClu<pClusCham->GetEntries();iClu++){           //clusters loop
194       AliHMPIDCluster *pClu = (AliHMPIDCluster*)pClusCham->At(iClu); //get current cluster        
195       pMark[iCh]->SetNextPoint(pClu->X(),pClu->Y()); 
196     }//switch hit PID      
197   }//hits loop for this entry
198 }//RenderClus()
199 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
200 void RenderEsd(AliESD *pEsd)
201 {//used by ReadEvent() or SimulateEvent() to render ESD to polymarker structures for rings and intersections one per chamber
202   AliHMPIDRecon rec;
203   for(Int_t iTrk=0;iTrk<pEsd->GetNumberOfTracks();iTrk++){//tracks loop to collect cerenkov rings and intersection points
204     AliESDtrack *pTrk=pEsd->GetTrack(iTrk);    Int_t ch=pTrk->GetHMPIDcluIdx(); //get track and chamber intersected by it
205     if(ch<0) continue;                                                          //this track does not intersect any chamber
206     Float_t thRa,phRa,xRa,yRa; pTrk->GetHMPIDtrk(xRa,yRa,thRa,phRa);            //get info on current track
207     ch/=1000000;                                                                //actual chamber number 
208     Float_t xPc=0,yPc=0; AliHMPIDTracker::IntTrkCha(pTrk,xPc,yPc);              //find again intersection of track with PC--> it is not stored in ESD!
209     fRenTxC[ch]->SetNextPoint(xPc,yPc);                                            //add this intersection point
210     Float_t ckov=pTrk->GetHMPIDsignal();                                        //get ckov angle stored for this track  
211     if(ckov>0){
212       rec.SetTrack(xRa,yRa,thRa,phRa);
213       for(Int_t j=0;j<100;j++){ 
214         TVector2 pos; pos=rec.TracePhot(ckov,j*0.0628);
215        if(!AliHMPIDDigit::IsInDead(pos.X(),pos.Y())) fRenRin[ch]->SetNextPoint(pos.X(),pos.Y());
216       }      
217     }//if ckov is valid
218   }//tracks loop  
219 }//RenEsd()
220 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
221 void SimulateEsd(AliESD *pEsd)
222 {
223   TParticle part; TLorentzVector mom;
224   for(Int_t iTrk=0;iTrk<100;iTrk++){//stack loop
225     part.SetPdgCode(kProton);
226     part.SetProductionVertex(0,0,0,0);
227     Double_t eta= -0.2+gRandom->Rndm()*0.4; //rapidity is random [-0.2,+0.2]
228     Double_t phi= gRandom->Rndm()*60.*TMath::DegToRad();   //phi is random      [ 0  , 60 ] degrees    
229     mom.SetPtEtaPhiM(5,eta,phi,part.GetMass());
230     part.SetMomentum(mom);
231     AliESDtrack trk(&part);
232     pEsd->AddTrack(&trk);
233   }//stack loop  
234 }//EsdFromStack()
235 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
236 void SimulateHits(AliESD *pEsd, TClonesArray *pHits)
237 {//used by SimulateEvent to simulate hits out from provided ESD
238   const Int_t kCerenkov=50000050;
239   const Int_t kFeedback=50000051;
240   
241   AliHMPIDRecon rec;
242   Float_t eMip=200e-9,ePho=7.5e-9; 
243   Int_t hc=0; 
244   for(Int_t iTrk=0;iTrk<pEsd->GetNumberOfTracks();iTrk++){//tracks loop
245     AliESDtrack *pTrk=pEsd->GetTrack(iTrk);
246     Float_t xRa,yRa;
247     Int_t ch=AliHMPIDTracker::IntTrkCha(pTrk,xRa,yRa);
248     if(ch<0) continue; //this track does not hit HMPID
249     Float_t beta = pTrk->GetP()/(TMath::Sqrt(pTrk->GetP()*pTrk->GetP()+0.938*0.938));
250     Float_t ckov=TMath::ACos(1./(beta*1.292));
251
252     Float_t theta,phi,xPc,yPc,; pTrk->GetHMPIDtrk(xPc,yPc,theta,phi); rec.SetTrack(xRa,yRa,theta,phi); 
253     
254     if(!AliHMPIDDigit::IsInDead(xPc,yPc)) new((*pHits)[hc++]) AliHMPIDHit(ch,eMip,kProton  ,iTrk,xPc,yPc);                 //mip hit
255     Int_t nPhots = (Int_t)(20.*TMath::Power(TMath::Sin(ckov),2)/TMath::Power(TMath::Sin(TMath::ACos(1./1.292)),2));
256     for(int i=0;i<nPhots;i++){
257       TVector2 pos;
258       pos=rec.TracePhot(ckov,gRandom->Rndm()*TMath::TwoPi());
259       if(!AliHMPIDDigit::IsInDead(pos.X(),pos.Y())) new((*pHits)[hc++]) AliHMPIDHit(ch,ePho,kCerenkov,iTrk,pos.X(),pos.Y());
260     }                      //photon hits  
261     for(int i=0;i<3;i++){//feedback photons
262       Float_t x=gRandom->Rndm()*160; Float_t y=gRandom->Rndm()*150;
263       if(!AliHMPIDDigit::IsInDead(x,y)) new((*pHits)[hc++]) AliHMPIDHit(ch,ePho,kFeedback,iTrk,x,y);                 //feedback hits  
264     }//photon hits loop                      
265   }//tracks loop    
266 }//SimulateHits()
267 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
268 void DoZoom(Int_t evt, Int_t px, Int_t py, TObject *)
269 {
270   if(evt!=5 && evt!=6) return; //5- zoom in 6-zoom out
271   const Int_t minZoom=64;
272   const Int_t maxZoom=2;
273   static Int_t zoom=minZoom; //zoom level
274   if(evt==5&&zoom==maxZoom) return; 
275   if(evt==6&&zoom==minZoom) return; 
276   
277  // if(!obj->IsA()->InheritsFrom("TPad")) return;  //current object is not pad
278   TVirtualPad *pPad=gPad->GetSelectedPad();
279   if(pPad->GetNumber()==3 || pPad->GetNumber()==7) return; //current pad is wrong
280
281  // Printf("evt=%i (%i,%i) %s",evt,px,py,obj->GetName());
282     
283   Float_t x=pPad->AbsPixeltoX(px); Float_t y=pPad->AbsPixeltoY(py); 
284  
285   if(evt==5){ zoom=zoom/2;     pPad->Range(x-zoom*2,y-zoom*2,x+zoom*2,y+zoom*2);} //zoom in
286   else      { zoom=zoom*2;     pPad->Range(x-zoom*2,y-zoom*2,x+zoom*2,y+zoom*2);} //zoom out 
287   if(zoom==minZoom) pPad->Range(-10,-10,AliHMPIDDigit::SizeAllX()+5,AliHMPIDDigit::SizeAllY()+5);
288   ((TCanvas *)gTQSender)->SetTitle(Form("zoom x%i",minZoom/zoom));
289   pPad->Modified();
290   pPad->Update();                                              
291 }
292 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
293 void ReadEvent()
294 {//used by NextEvent()  to read curent event and construct all render elements
295   if(fNevt && fEvt>=fNevt) fEvt=0; //loop over max event
296   
297   if(fHitFile){ 
298     if(fHitTree) delete fHitTree;   fHitTree=(TTree*)fHitFile->Get(Form("Event%i/TreeH",fEvt));
299     
300                           fHitTree->SetBranchAddress("HMPID",&fHitLst);
301     for(Int_t iEnt=0;iEnt<fHitTree->GetEntries();iEnt++){    
302                           fHitTree->GetEntry(iEnt);                              
303       RenderHit(fHitLst);   
304     }//prim loop
305   }//if hits file
306   
307   if(fCluFile){ 
308     if(fCluTree) delete fCluTree; fCluTree=(TTree*)fCluFile->Get(Form("Event%i/TreeR",fEvt));
309     for(Int_t iCh=AliHMPIDDigit::kMinCh;iCh<=AliHMPIDDigit::kMaxCh;iCh++) fCluTree->SetBranchAddress(Form("HMPID%i",iCh),&(*fCluLst)[iCh]);      
310     fCluTree->GetEntry(0);
311     RenderClu(fCluLst,fRenClu);   
312   }//if clus file
313   
314   if(fEsdFile){//if ESD file open
315     fEsdTree->GetEntry(fEvt);  
316     RenderEsd(fEsd);
317   }//if ESD file 
318 }//ReadEvent()
319 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
320 void SimulateEvent()
321 {// used by NextEvent() to simulate all info
322   AliCDBManager* pCDB = AliCDBManager::Instance();  pCDB->SetDefaultStorage("local://$HOME"); pCDB->SetRun(0);
323   AliCDBEntry *pNmeanEnt=pCDB->Get("HMPID/Calib/Nmean");
324
325   SimulateEsd(fEsd);
326   SimulateHits(fEsd,fHitLst);
327                  AliHMPIDv2::Hit2Sdi(fHitLst,fSdiLst);                               
328           AliHMPIDDigitizer::Sdi2Dig(fSdiLst,fDigLst);     
329       AliHMPIDReconstructor::Dig2Clu(fDigLst,fCluLst);
330             AliHMPIDTracker::Recon(fEsd,fCluLst,(TObjArray*)pNmeanEnt->GetObject());
331             
332   RenderHit(fHitLst);
333   RenderClu(fCluLst,fRenClu);
334   RenderEsd(fEsd);            
335 }//SimulateEvent()
336 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
337 void NextEvent()
338 {
339   fEvt++;
340   ClearRenders();
341   switch(fType){
342     case 1: ReadEvent();break;
343 //    case 2: ReadCosmic(); break;
344     case 3: SimulateEvent();     break;
345     default:                 return;
346   }  
347   Draw();
348 }
349 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
350 void Hdisp()                                  
351 {//display events from files if any in current directory or simulated events
352   CreateContainers();
353   CreateRenders();
354   
355   TString title="Session with";
356   if(gSystem->IsFileInIncludePath("HMPID.Hits.root")){// tries to open hits
357     fHitFile=TFile::Open("HMPID.Hits.root");       fNevt=fHitFile->GetNkeys(); fType=1; title+=Form(" HITS-%i ",fNevt);
358   }
359   
360   if(gSystem->IsFileInIncludePath("HMPID.Digits.root")){// tries to open clusters
361     fDigFile=TFile::Open("HMPID.Digits.root");  fNevt=fDigFile->GetNkeys(); fType=1;  title+=Form(" DIGITS-%i ",fNevt);
362   }
363   
364   if(gSystem->IsFileInIncludePath("HMPID.RecPoints.root")){// tries to open clusters
365     fCluFile=TFile::Open("HMPID.RecPoints.root");  fNevt=fCluFile->GetNkeys(); fType=1;  title+=Form(" CLUSTERS-%i ",fNevt);
366   }
367   
368   if(gSystem->IsFileInIncludePath("AliESDs.root")){     
369     fEsdFile=TFile::Open("AliESDs.root"); fEsdTree=(TTree*)fEsdFile->Get("esdTree");  fNevt=fEsdTree->GetEntries(); fType=1;  title+=Form(" ESD-%i ",fNevt);
370                                           fEsdTree->SetBranchAddress("ESD", &fEsd);    
371   }
372
373   if(gSystem->IsFileInIncludePath("cosmic.root")){                          //clm: Check if cosmic file is in the folder
374     fCosFile=TFile::Open("cosmic.root");  fCosTree=(TTree*)fCosFile->Get("cosmic");  fNevt=fCosTree->GetEntries();  fType=2;
375     fCosTree->SetBranchAddress("Digs",&fDigLst);   fCosTree->SetBranchAddress("Clus",&fCluLst); 
376   }            
377
378   fCanvas=new TCanvas("all","",600,400); fCanvas->Divide(3,3,0,0);//  pAll->ToggleEditor();
379   fCanvas->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)",0,0,"DoZoom(Int_t,Int_t,Int_t,TObject*)");
380   fCanvas->cd(7); 
381   switch(fType){
382     case 1: fCanvas->SetTitle(title.Data());                      
383                          TButton *pNxtBtn=new TButton("Next"      ,"NextEvent()",0.0,0.0,0.3,0.1); pNxtBtn->Draw(); 
384             if(fHitFile){TButton *pHitBtn=new TButton("Print hits","PrintHits()",0.0,0.2,0.3,0.3); pHitBtn->Draw();}  
385             if(fDigFile){TButton *pDigBtn=new TButton("Print digs","PrintDigs()",0.0,0.4,0.3,0.5); pDigBtn->Draw();}  
386             if(fCluFile){TButton *pCluBtn=new TButton("Print clus","PrintClus()",0.0,0.6,0.3,0.7); pCluBtn->Draw();} 
387             if(fEsdFile){TButton *pEsdBtn=new TButton("Print ESD" ,"PrintEsd()" ,0.0,0.8,0.3,0.9); pEsdBtn->Draw();}
388            
389     break;
390     case 2: fCanvas->SetTitle("COSMIC");
391                          TButton *pCosBtn=new TButton("Next"      ,"NextEvent()",0.0,0.0,0.3,0.1); pCosBtn->Draw(); 
392              
393     break;
394     case 3: fCanvas->SetTitle("SIMULATION"); 
395             TButton *pSimBtn=new TButton("Simulate"  ,"NextEvent()",0.0,0.0,0.3,0.1); pSimBtn->Draw(); 
396             TButton *pHitBtn=new TButton("Print hits","PrintHits()",0.0,0.2,0.3,0.3); pHitBtn->Draw();  
397             TButton *pDigBtn=new TButton("Print digs","PrintDigs()",0.0,0.4,0.3,0.5); pDigBtn->Draw();
398             TButton *pCluBtn=new TButton("Print clus","PrintClus()",0.0,0.6,0.3,0.7); pCluBtn->Draw(); 
399             TButton *pEsdBtn=new TButton("Print ESD" ,"PrintEsd()" ,0.0,0.8,0.3,0.9); pEsdBtn->Draw();
400     break;
401   }
402     
403       
404   NextEvent();           
405   
406       
407 }//Hdisp()
408 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++