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