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