Pass name correctly to base class.
[u/mrichter/AliRoot.git] / RICH / menu.C
1 void ControlPlots()
2 {  
3   Int_t iChamber=1;
4   
5   TH1F *pCqH1=new TH1F("clusq","Clusters Charge;q [QDC]",300,0,4000);
6   al->LoadHeader();  al->LoadKinematics();
7   
8   Bool_t isHits=!rl->LoadHits();  
9     Bool_t isSDigits=!rl->LoadSDigits();  
10       Bool_t isClusters=!rl->LoadRecPoints();
11         Bool_t isDigits=!rl->LoadDigits();
12   
13   for(Int_t iEventN=0;iEventN<a->GetEventsPerRun();iEventN++){//events loop
14     al->GetEvent(iEventN);    
15     if(isHits){
16       for(Int_t iPrimN=0;iPrimN<rl->TreeH()->GetEntries();iPrimN++){//prims loop
17         rl->TreeH()->GetEntry(iPrimN);      
18         Int_t iTotalHits=0,iTotalCerenkovs=0,iTotalSpecials=0;
19         iTotalHits+=r->Hits()->GetEntries();
20         iTotalCerenkovs+=r->Cerenkovs()->GetEntries();
21         iTotalSpecials+=r->Specials()->GetEntries();
22       }//prims loop
23     }//isHits
24     if(isSDigits){
25       rl->TreeS()->GetEntry(0);
26     }//isSdigits
27     if(isDigits){
28       rl->TreeD()->GetEntry(0);
29       for(int i=1;i<=7;i++);
30     }//isDigits
31     if(isClusters){
32       rl->TreeR()->GetEntry(0);
33       Int_t iTotalClusters=0;
34       for(int i=1;i<=7;i++) iTotalClusters+=r->Clusters(i)->GetEntries();    
35       for(Int_t iClusterN=0;iClusterN<r->Clusters(iChamber)->GetEntries();iClusterN++){
36         pCqH1->Fill(((AliRICHcluster*)r->Clusters(iChamber)->At(i))->Q());
37       }//clusters loop
38     }//isClusters
39   }//events loop 
40   if(isHits) rl->UnloadHits();  
41     if(isSDigits) rl->UnloadSDigits(); 
42       if(isDigits) rl->UnloadDigits(); 
43         if(isClusters) rl->UnloadRecPoints();
44   al->UnloadHeader();  al->UnloadKinematics();
45   pCqH1->Draw();
46 }//void ControlPlots()
47 //__________________________________________________________________________________________________
48 void MainTrank()
49 {
50   TStopwatch sw;TDatime time;
51   OLD_S_SD(); SD_D(); D_C();
52   cout<<"\nInfo in <MainTrank>: Start time: ";time.Print();
53   cout<<"Info in <MainTrank>: Stop  time: ";time.Set();  time.Print();
54   cout<<"Info in <MainTrank>: Time  used: ";sw.Print();
55 }
56 //__________________________________________________________________________________________________
57 void sh()
58 {
59   if(rl->LoadHits()) return;
60   
61   Int_t iTotalHits=0;
62   for(Int_t iPrimN=0;iPrimN<rl->TreeH()->GetEntries();iPrimN++){//prims loop
63     rl->TreeH()->GetEntry(iPrimN);      
64     r->Hits()->Print();
65     iTotalHits+=r->Hits()->GetEntries();
66   }
67   Info("sh","totally %i hits",iTotalHits);
68   rl->UnloadHits();
69 }
70 //__________________________________________________________________________________________________
71 void ssp()
72 {
73   if(rl->LoadHits()) return;
74   
75   Int_t iTotalSpecials=0;
76   for(Int_t iPrimN=0;iPrimN<rl->TreeH()->GetEntries();iPrimN++){//prims loop
77     rl->TreeH()->GetEntry(iPrimN);      
78     r->Specials()->Print();
79     iTotalSpecials+=r->Specials()->GetEntries();
80   }
81   Info("ssp","totally %i specials",iTotalSpecials);
82   rl->UnloadHits();
83 }
84 //__________________________________________________________________________________________________
85 void ss()
86 {
87   if(rl->LoadSDigits()) return;
88   rl->TreeS()->GetEntry(0);
89   r->SDigits()->Print();
90   Info("ss","totally %i sdigits",r->SDigits()->GetEntries());
91   rl->UnloadSDigits();
92 }
93 //__________________________________________________________________________________________________
94 void sd()
95 {
96   if(rl->LoadDigits()) return;
97   rl->TreeD()->GetEntry(0);
98   Int_t iTotalDigits=0;
99   for(int i=1;i<=7;i++){
100     r->Digits(i)->Print();
101     iTotalDigits+=r->Digits(i)->GetEntries();
102   }
103   Info("sd","totally %i digits",iTotalDigits);
104   rl->UnloadDigits();
105 }
106
107 void sc()
108 {
109   if(rl->LoadRecPoints()) return;
110   r->SetTreeAddress();
111   rl->TreeR()->GetEntry(0);
112   for(int i=1;i<=7;i++) r->Clusters(i)->Print();
113   rl->UnloadRecPoints();
114 }
115
116 Double_t r2d = TMath::RadToDeg();
117 Double_t d2r = TMath::DegToRad();
118
119 void DisplFast()
120 {
121   AliRICHDisplFast *d = new AliRICHDisplFast();
122   d->Exec();
123 }  
124
125
126 void Digits2Recos()
127 {
128   AliRICHRecon *detect = new AliRICHRecon("RICH patrec algorithm","Reconstruction");
129     
130
131   for (int nev=0; nev< a->GetEventsPerRun(); nev++) {    // Event Loop
132     al->GetEvent(nev);
133     cout <<endl<< "Processing event:" <<nev<<endl;
134     detect->StartProcessEvent();
135   } // event loop  
136   delete detect;
137 }  
138
139
140
141
142 void D_C()
143 {
144   AliRICHClusterFinder *z=new AliRICHClusterFinder(r);
145   z->Exec();  
146 }
147 //__________________________________________________________________________________________________
148 void OLD_S_SD()
149 {
150   Info("OLD_S_SD","Start.");
151   
152   rl->LoadHits(); 
153   
154   for(Int_t iEventN=0;iEventN<a->GetEventsPerRun();iEventN++){//events loop
155     al->GetEvent(iEventN);
156     
157     rl->MakeTree("S");  r->MakeBranch("S");
158     r->ResetSDigits();  r->ResetSpecialsOld();
159
160     for(Int_t iPrimN=0;iPrimN<rl->TreeH()->GetEntries();iPrimN++){//prims loop
161       rl->TreeH()->GetEntry(iPrimN);
162       for(Int_t i=0;i<r->Specials()->GetEntries();i++){//specials loop          
163         Int_t padx= ((AliRICHSDigit*)r->Specials()->At(i))->PadX()+r->Param()->NpadsX()/2;
164         Int_t pady= ((AliRICHSDigit*)r->Specials()->At(i))->PadY()+r->Param()->NpadsY()/2;
165         Double_t q=  ((AliRICHSDigit*)r->Specials()->At(i))->QPad();
166         Int_t hitN= ((AliRICHSDigit*)r->Specials()->At(i))->HitNumber()-1;//!!! important -1
167         Int_t chamber=((AliRICHhit*)r->Hits()->At(hitN))->C();
168         Int_t track=((AliRICHhit*)r->Hits()->At(hitN))->GetTrack();
169         if(padx<1 || padx>r->Param()->NpadsX() ||pady<1 || pady>r->Param()->NpadsY())
170           Error("OLD_S_SD","pad is out of valid range padx= %i pady=%i event %i",padx,pady,iEventN);
171         else
172           r->AddSDigit(chamber,padx,pady,q,track);
173       }//specials loop
174     }//prims loop
175     rl->TreeS()->Fill();
176     rl->WriteSDigits("OVERWRITE");
177   }//events loop  
178     rl->UnloadHits();     rl->UnloadSDigits();  
179   Info("OLD_S_SD","Stop.");    
180 }//OLD_S_SD()
181 //__________________________________________________________________________________________________
182 void H_SD()
183 {
184   Info("H_SD","Start.");
185   
186   for(Int_t iEventN=0;iEventN<a->GetEventsPerRun();iEventN++){//events loop
187     al->GetEvent(iEventN);
188   
189     if(!rl->TreeH()) rl->LoadHits();//from
190     if(!rl->TreeS()) rl->MakeTree("S");    r->MakeBranch("S");//to
191       
192     for(Int_t iPrimN=0;iPrimN<rl->TreeH()->GetEntries();iPrimN++){//prims loop
193       rl->TreeH()->GetEntry(iPrimN);
194       for(Int_t iHitN=0;iHitN<3;iHitN++){//hits loop  ???
195         AliRICHhit *pHit=r->Hits()->At(iHitN);        
196         TVector3 globX3(pHit->X(),pHit->Y(),pHit->Z());        
197         TVector3 locX3=r->C(pHit->C())->Glob2Loc(globX3);
198         
199         Int_t sector;
200         Int_t iTotQdc=r->Param()->Loc2TotQdc(locX3,pHit->Eloss(),pHit->Pid(),sector);
201         
202         Int_t iPadXmin,iPadXmax,iPadYmin,iPadYmax;
203         r->Param()->Loc2Area(locX3,iPadXmin,iPadYmin,iPadXmax,iPadYmax);
204         cout<<"left-down=("<<iPadXmin<<","<<iPadYmin<<") right-up=("<<iPadXmax<<','<<iPadYmax<<')'<<endl;
205         for(Int_t iPadY=iPadYmin;iPadY<=iPadYmax;iPadY++)
206           for(Int_t iPadX=iPadXmin;iPadX<=iPadXmax;iPadX++){
207             Double_t padQdc=iTotQdc*r->Param()->Loc2PadFrac(locX3,iPadX,iPadY);
208             if(padQdc>0.1)r->AddSDigit(pHit->C(),iPadX,iPadY,padQdc,pHit->GetTrack());
209           }            
210       }//hits loop
211     }//prims loop
212     rl->TreeS()->Fill();
213     rl->WriteSDigits("OVERWRITE");
214   }//events loop
215   
216   rl->UnloadHits();
217   rl->UnloadSDigits();  
218   Info("H_SD","Stop.");  
219 }//H_SD()
220 //__________________________________________________________________________________________________
221 void SD_D()
222 {
223   Info("SD_D","Start.");  
224
225   rl->LoadSDigits();
226   
227   for(Int_t iEventN=0;iEventN<a->GetEventsPerRun();iEventN++){//events loop
228     al->GetEvent(iEventN);
229     cout<<"Event "<<iEventN<<endl;  
230     rl->MakeTree("D");r->MakeBranch("D"); //create TreeD with RICH branches 
231     r->ResetSDigits();r->ResetDigits();//reset lists of sdigits and digits
232     rl->TreeS()->GetEntry(0);  
233     r->SDigits()->Sort();
234   
235     Int_t kBad=-101;
236     Int_t chamber,x,y,tr[3],id;
237     Double_t q=kBad;
238     chamber=x=y=tr[0]=tr[1]=tr[2]=id=kBad;
239     Int_t iNdigitsPerPad=kBad;//how many sdigits for a given pad
240         
241     for(Int_t i=0;i<r->SDigits()->GetEntries();i++){//sdigits loop (sorted)
242       AliRICHdigit *pSdig=(AliRICHdigit*)r->SDigits()->At(i);
243       if(pSdig->Id()==id){//still the same pad
244         iNdigitsPerPad++;
245         q+=pSdig->Q();
246         if(iNdigitsPerPad<=3)
247           tr[iNdigitsPerPad-1]=pSdig->T(0);
248 //        else
249 //          Info("","More then 3 sdigits for the given pad");
250       }else{//new pad, add the pevious one
251         if(id!=kBad) r->AddDigit(chamber,x,y,q,tr[0],tr[1],tr[2]);//ch-xpad-ypad-qdc-tr1-2-3
252         chamber=pSdig->C();x=pSdig->X();y=pSdig->Y();q=pSdig->Q();tr[0]=pSdig->T(0);id=pSdig->Id();
253         iNdigitsPerPad=1;tr[1]=tr[2]=kBad;
254       }
255     }//sdigits loop (sorted)
256   
257     if(r->SDigits()->GetEntries())r->AddDigit(chamber,x,y,q,tr[0],tr[1],tr[2]);//add the last digit
258         
259     rl->TreeD()->Fill();  
260     rl->WriteDigits("OVERWRITE");
261   }//events loop
262   rl->UnloadSDigits();     rl->UnloadDigits();  
263   r->ResetSDigits();r->ResetDigits();//reset lists of sdigits and digits
264   Info("SD_D","Stop.");  
265 }//SD_D()
266 //__________________________________________________________________________________________________
267 void Show()
268 {  
269   cout<<endl;
270   al->LoadHeader();  al->LoadKinematics();
271   
272   rl->LoadHits();  
273     Bool_t isSdigits=!rl->LoadSDigits();  
274       Bool_t isClusters=!rl->LoadRecPoints();
275         Bool_t isDigits=!rl->LoadDigits();//loaders
276   
277   cout<<endl;  cout<<endl;  
278   for(Int_t iEventN=0;iEventN<a->GetEventsPerRun();iEventN++){//events loop
279     Int_t iNparticles=a->GetEvent(iEventN);
280     Int_t iNprims=rl->TreeH()->GetEntries();
281     
282     Int_t iTotalHits=0,iTotalCerenkovs=0,iTotalSpecials=0;
283     for(Int_t iPrimN=0;iPrimN<iNprims;iPrimN++){//prims loop
284       rl->TreeH()->GetEntry(iPrimN);      
285       iTotalHits+=r->Hits()->GetEntries();
286       iTotalCerenkovs+=r->Cerenkovs()->GetEntries();
287       iTotalSpecials+=r->Specials()->GetEntries();
288       TParticle *pPrim=al->Stack()->Particle(iPrimN);
289       Info("Show","Evt %4i prim %4i has %4i hits %5i cerenkovs and %5i specials from %s (,%7.2f,%7.2f)",
290                            iEventN,
291                                     iPrimN,
292                                              r->Hits()->GetEntries(),
293                                                       r->Cerenkovs()->GetEntries(),
294                                                                         r->Specials()->GetEntries(),
295                                                                                          pPrim->GetName(),
296                                                                                  pPrim->Theta()*r2d,pPrim->Phi()*r2d);
297     }//prims loop
298     Info("Show-HITS","Evt %i total:  %i particles %i primaries %i hits %i cerenkovs %i specials",
299                         iEventN,   iNparticles, iNprims,     iTotalHits,iTotalCerenkovs,iTotalSpecials);
300     if(isSdigits){
301       rl->TreeS()->GetEntry(0);
302       Info("Show-SDIGITS","Evt %i contains %5i sdigits",iEventN,r->SDigits()->GetEntries());
303     }
304     if(isDigits){
305       rl->TreeD()->GetEntry(0);
306       for(int i=1;i<=7;i++)
307         Info("Show-DIGITS","Evt %i chamber %i contains %5i digits",
308                                  iEventN,   i,           r->Digits(i)->GetEntries());
309     }
310     if(isClusters){
311       rl->TreeR()->GetEntry(0);
312       for(int i=1;i<=7;i++)
313         Info("Show-CLUSTERS","Evt %i chamber %i contains %5i clusters",
314                                  iEventN,   i,           r->Clusters(i)->GetEntries());
315     }
316     cout<<endl;
317   }//events loop
318   rl->UnloadHits();  
319     if(isSdigits) rl->UnloadSDigits(); 
320       if(isDigits) rl->UnloadDigits(); 
321         if(isClusters) rl->UnloadRecPoints();
322   al->UnloadHeader();
323   al->UnloadKinematics();
324   cout<<endl;
325 }//void Show()
326 //__________________________________________________________________________________________________
327
328
329 AliRun *a;
330 AliRunLoader *al;
331 AliLoader *rl,*tl,*il;
332
333 AliRICH *r;
334
335 Bool_t ReadAlice()
336 {
337   Info("ReadAlice","Tring to read ALICE from SIMULATED FILE.");
338   AliLoader::SetDebug(0);
339   if(gAlice) delete gAlice;      
340   if(!(al=AliRunLoader::Open("galice.root","AlicE","update"))){
341     gSystem->Exec("rm -rf *.root *.dat");
342     Error("ReadAlice","galice.root broken, removing all this garbage then init new one");
343     new AliRun("gAlice","Alice experiment system");
344     gAlice->SetDebug(-1);
345     gAlice->Init("ConfigRich.C");
346     r=(AliRICH*)gAlice->GetDetector("RICH");
347     return kFALSE;
348   }
349   al->LoadgAlice();
350   if(!gAlice) Fatal("ReadAlice","No gAlice in file");
351   a=al->GetAliRun();
352   a->SetDebug(0);    
353 //RICH      
354   if(!(r=(AliRICH*)gAlice->GetDetector("RICH"))) Warning("RICH/menu.C::ReadAlice","No RICH in file");
355   r->SetDebug(0);
356   if(!(rl=al->GetLoader("RICHLoader")))          Warning("RICH/menu.C::ReadAlice","No RICH loader in file");        
357         
358   Info("ReadAlice","Run contains %i event(s)",gAlice->GetEventsPerRun());      
359   return kTRUE;
360 }
361 //__________________________________________________________________________________________________
362 void PrintGeo(Float_t rotDeg=0)
363 {
364   AliRICHParam *p=new AliRICHParam;  
365   Double_t r=p->Offset();
366   Double_t kP=p->AngleXY();
367   Double_t kT=p->AngleYZ();
368   Double_t kRot;
369   
370   if(rotDeg==0)
371     kRot=p->AngleRot();
372   else
373     kRot=rotDeg*deg;
374         
375   cout<<endl;
376   Double_t  phi=90*deg+kRot+kP,theta=90*deg+kT;
377   Info("   menu for          1","r=%8.3f theta=%5.1f phi=%5.1f x=%8.3f y=%8.3f z=%8.3f",
378                                  r,      theta*r2d,  phi*r2d,  
379                                                                r*sin(theta)*cos(phi),
380                                                                        r*sin(theta)*sin(phi),
381                                                                                r*cos(theta));
382   
383   phi=90*deg+kRot+kP,theta=90*deg;
384   Info("   menu for          2","r=%8.3f theta=%5.1f phi=%5.1f x=%8.3f y=%8.3f z=%8.3f",
385                                  r,      theta*r2d,  phi*r2d,  
386                                                                r*sin(theta)*cos(phi),
387                                                                        r*sin(theta)*sin(phi),
388                                                                                r*cos(theta));
389   
390   phi=90*deg+kRot,theta=90*deg-kT;    
391   Info("   menu for          3","r=%8.3f theta=%5.1f phi=%5.1f x=%8.3f y=%8.3f z=%8.3f",
392                                  r,      theta*r2d,  phi*r2d,  
393                                                                r*sin(theta)*cos(phi),
394                                                                        r*sin(theta)*sin(phi),
395                                                                                r*cos(theta));
396   
397   
398   phi=90*deg+kRot,theta=90*deg;
399   Info("   menu for          4","r=%8.3f theta=%5.1f phi=%5.1f x=%8.3f y=%8.3f z=%8.3f",
400                                  r,      theta*r2d,  phi*r2d,  
401                                                                r*sin(theta)*cos(phi),
402                                                                        r*sin(theta)*sin(phi),
403                                                                                r*cos(theta));
404
405   
406   phi=90*deg+kRot,theta=90*deg+kT;
407   Info("   menu for          5","r=%8.3f theta=%5.1f phi=%5.1f x=%8.3f y=%8.3f z=%8.3f",
408                                  r,      theta*r2d,  phi*r2d,  
409                                                                 r*sin(theta)*cos(phi),
410                                                                        r*sin(theta)*sin(phi),
411                                                                                r*cos(theta));
412   
413   
414   phi=90*deg+kRot-kP,theta=90*deg;
415   Info("   menu for          6","r=%8.3f theta=%5.1f phi=%5.1f x=%8.3f y=%8.3f z=%8.3f",
416                                  r,      theta*r2d,  phi*r2d,  
417                                                                r*sin(theta)*cos(phi),
418                                                                        r*sin(theta)*sin(phi),
419                                                                                r*cos(theta));
420   
421   phi=90*deg+kRot-kP,theta=90*deg+kT;
422   Info("   menu for          7","r=%8.3f theta=%5.1f phi=%5.1f x=%8.3f y=%8.3f z=%8.3f",
423                                  r,      theta*r2d,  phi*r2d,  
424                                                                r*sin(theta)*cos(phi),
425                                                                        r*sin(theta)*sin(phi),
426                                                                                r*cos(theta));
427
428   delete p;
429 }//PrintGeo()
430 //__________________________________________________________________________________________________
431 void TestResponse()
432 {
433   TCanvas *pC=new TCanvas("c","Amplification test",900,800);
434   pC->Divide(1,2);
435   pC->cd(1);
436   TF1 *pF1=new TF1("f1","9e-6*pow(x,4)+2e-7*pow(x,3)-0.0316*pow(x,2)-3e-4*x+25.367",-70,70);
437   pF1->Draw();
438   
439   pC->cd(2);
440   
441   const Int_t nPoints=8;
442   THStack *pStack=new THStack("stack","photons");
443   TLegend *pLeg=new TLegend(0.6,0.2,0.9,0.5,"legend");    
444   TH1F *apH[nPoints];
445   
446   Double_t starty=AliRICHParam::DeadZone()/2;
447   Double_t deltay=AliRICHParam::SectorSizeY()/nPoints;
448   
449   for(int i=0;i<nPoints;i++){
450     apH[i]=new TH1F(Form("h%i",i),"Qdc for Photon;QDC;Counts",1000,0,1000); apH[i]->SetLineColor(i);
451     pStack->Add(apH[i]);                 
452     pLeg->AddEntry(apH[i],Form("@(0,%5.2f->%5.2f)",starty+i*deltay,starty+i*deltay-AliRICHParam::SectorSizeY()/2));
453   }
454         
455   
456   TVector3 x3(0,0,0);  
457   Int_t sector=10;
458 //  AliRICHParam::ResetWireSag();
459   for(Int_t i=0;i<10000;i++){//events loop
460     for(int j=0;j<nPoints;j++){
461       x3.SetY(starty-j*deltay);
462       apH[j]->Fill(AliRICHParam::Loc2TotQdc(x3,400e-9,500000,sector));
463     }
464   }
465   pStack->Draw("nostack");
466   pLeg->Draw();
467 }//TestResponse()
468 //__________________________________________________________________________________________________
469 void TestSD()
470 {
471   Info("TestSD","Creating test sdigits.");
472   rl->MakeTree("S");r->MakeBranch("S");
473   
474     for(Int_t iEventN=0;iEventN<a->GetEventsPerRun();iEventN++){//events loop
475     al->GetEvent(iEventN);
476   
477     if(!rl->TreeH()) rl->LoadHits();//from
478     if(!rl->TreeS()) rl->MakeTree("S");    r->MakeBranch("S");//to
479       
480     for(Int_t iPrimN=0;iPrimN<rl->TreeH()->GetEntries();iPrimN++){//prims loop
481       rl->TreeH()->GetEntry(iPrimN);
482       for(Int_t iHitN=0;iHitN<3;iHitN++){//hits loop  ???
483         AliRICHhit *pHit=r->Hits()->At(iHitN);        
484         TVector3 globX3(pHit->X(),pHit->Y(),pHit->Z());        
485         TVector3 locX3=r->C(pHit->C())->Glob2Loc(globX3);
486         
487         Int_t sector;
488         Int_t iTotQdc=r->Param()->Loc2TotQdc(locX3,pHit->Eloss(),pHit->Pid(),sector);
489         
490         Int_t iPadXmin,iPadXmax,iPadYmin,iPadYmax;
491         r->Param()->Loc2Area(locX3,iPadXmin,iPadYmin,iPadXmax,iPadYmax);
492         cout<<"left-down=("<<iPadXmin<<","<<iPadYmin<<") right-up=("<<iPadXmax<<','<<iPadYmax<<')'<<endl;
493         for(Int_t iPadY=iPadYmin;iPadY<=iPadYmax;iPadY++)
494           for(Int_t iPadX=iPadXmin;iPadX<=iPadXmax;iPadX++){
495             Float_t iPadQdc=iTotQdc*r->Param()->Loc2PadFrac(locX3,iPadX,iPadY);
496             Int_t padx,pady; r->Param()->Loc2Pad(locX3.X(),locX3.Y(),padx,pady);
497             cout<<"hit="<<iHitN<<" ("<<locX3.X()<<','<<locX3.Y()<<")("<<padx<<','<<pady<<") cur pad("<<iPadX<<","<<iPadY<<") qtot="<<iTotQdc<<" qfrac="<<r->Param()->Loc2PadFrac(locX3,iPadX,iPadY)<<endl;
498           }
499 //            r->AddSDigit(pHit->C(),padx,pady,r->Param()->Local2PadQdc(localX3,padx,pady),pHit->GetTrack());
500       }//hits loop
501     }//prims loop
502     rl->TreeS()->Fill();
503     rl->WriteSDigits("OVERWRITE");
504   }//events loop
505   
506   rl->UnloadHits();
507   rl->UnloadSDigits();  
508
509   rl->TreeS()->Fill();
510   rl->WriteSDigits("OVERWRITE");
511   rl->UnloadSDigits();
512   cout<<endl;r->Sdigits()->Print();
513   r->ResetSDigits();
514   Info("TestSdigits","Stop.");
515 }//void TestSdigits()
516 //__________________________________________________________________________________________________
517 void TestC()
518 {
519   Info("TestC","Creating test clusters.");
520   rl->MakeTree("R");r->MakeBranch("R");
521   
522   AliRICHcluster c;
523   c.AddDigit(new AliRICHdigit(1,20,21,200,1,2,3));
524   c.AddDigit(new AliRICHdigit(1,22,21,250,1,2,3));
525   c.CoG();
526   
527   r->AddCluster(c);  
528   
529   rl->TreeR()->Fill();
530   rl->WriteRecPoints("OVERWRITE");
531   rl->UnloadRecPoints();
532   r->ResetClusters();
533   
534   Info("TestC","Stop.");
535 }//TestC()
536 //__________________________________________________________________________________________________
537 void TestSeg()
538 {
539   AliRICHParam *p=r->Param();
540   Int_t padx,pady;
541   Double_t x,y;
542   Double_t dz=p->DeadZone();
543   Double_t sx=p->SectorSizeX(); Double_t sy=p->SectorSizeY();  Double_t px=p->PcSizeX(); Double_t py=p->PcSizeY();
544   cout<<endl;
545   Info("  1-  1","sec=%i padx=%3i pady=%3i",p->Loc2Pad(-px/2    , -py/2        ,padx,pady),padx,pady);
546   Info(" 48-  1","sec=%i padx=%3i pady=%3i",p->Loc2Pad(-sx/2-dz , -py/2        ,padx,pady),padx,pady);
547   Info(" 49-  1","sec=%i padx=%3i pady=%3i",p->Loc2Pad(-sx/2    , -py/2        ,padx,pady),padx,pady);
548   Info(" 96-  1","sec=%i padx=%3i pady=%3i",p->Loc2Pad( sx/2    , -py/2        ,padx,pady),padx,pady);
549   Info(" 97-  1","sec=%i padx=%3i pady=%3i",p->Loc2Pad( sx/2+dz , -py/2        ,padx,pady),padx,pady);
550   Info("144-  1","sec=%i padx=%3i pady=%3i",p->Loc2Pad( px/2    , -py/2        ,padx,pady),padx,pady);
551   cout<<endl;
552   Info("  1- 80","sec=%i padx=%3i pady=%3i",p->Loc2Pad(-px/2    , -dz/2        ,padx,pady),padx,pady);
553   Info(" 48- 80","sec=%i padx=%3i pady=%3i",p->Loc2Pad(-sx/2-dz , -dz/2        ,padx,pady),padx,pady);
554   Info(" 49- 80","sec=%i padx=%3i pady=%3i",p->Loc2Pad(-sx/2    , -dz/2        ,padx,pady),padx,pady);
555   Info(" 96- 80","sec=%i padx=%3i pady=%3i",p->Loc2Pad( sx/2    , -dz/2        ,padx,pady),padx,pady);
556   Info(" 97- 80","sec=%i padx=%3i pady=%3i",p->Loc2Pad( sx/2+dz , -dz/2        ,padx,pady),padx,pady);
557   Info("144- 80","sec=%i padx=%3i pady=%3i",p->Loc2Pad( px/2    , -dz/2        ,padx,pady),padx,pady);
558   cout<<endl;
559   Info("  1- 81","sec=%i padx=%3i pady=%3i",p->Loc2Pad(-px/2    ,  dz/2        ,padx,pady),padx,pady);
560   Info(" 48- 81","sec=%i padx=%3i pady=%3i",p->Loc2Pad(-sx/2-dz ,  dz/2        ,padx,pady),padx,pady);
561   Info(" 49- 81","sec=%i padx=%3i pady=%3i",p->Loc2Pad(-sx/2    ,  dz/2        ,padx,pady),padx,pady);
562   Info(" 96- 81","sec=%i padx=%3i pady=%3i",p->Loc2Pad( sx/2    ,  dz/2        ,padx,pady),padx,pady);
563   Info(" 97- 81","sec=%i padx=%3i pady=%3i",p->Loc2Pad( sx/2+dz ,  dz/2        ,padx,pady),padx,pady);
564   Info("144- 81","sec=%i padx=%3i pady=%3i",p->Loc2Pad( px/2    ,  dz/2        ,padx,pady),padx,pady);
565   cout<<endl;
566   Info("  1-160","sec=%i padx=%3i pady=%3i",p->Loc2Pad(-px/2    ,  py/2        ,padx,pady),padx,pady);
567   Info(" 48-160","sec=%i padx=%3i pady=%3i",p->Loc2Pad(-sx/2-dz ,  py/2        ,padx,pady),padx,pady);
568   Info(" 49-160","sec=%i padx=%3i pady=%3i",p->Loc2Pad(-sx/2    ,  py/2        ,padx,pady),padx,pady);
569   Info(" 96-160","sec=%i padx=%3i pady=%3i",p->Loc2Pad( sx/2    ,  py/2        ,padx,pady),padx,pady);
570   Info(" 97-160","sec=%i padx=%3i pady=%3i",p->Loc2Pad( sx/2+dz ,  py/2        ,padx,pady),padx,pady);
571   Info("144-160","sec=%i padx=%3i pady=%3i",p->Loc2Pad( px/2    ,  py/2        ,padx,pady),padx,pady);  
572   cout<<endl;
573   Info(" 73-160","sec=%i padx=%3i pady=%3i",p->Loc2Pad(    0    ,  py/2      ,padx,pady),padx,pady);    
574   Info(" 73- 81","sec=%i padx=%3i pady=%3i",p->Loc2Pad(    0    ,  dz/2      ,padx,pady),padx,pady);    
575   Info("0-0dead","sec=%i padx=%3i pady=%3i",p->Loc2Pad(    0    ,   0        ,padx,pady),padx,pady);    
576   Info(" 73- 80","sec=%i padx=%3i pady=%3i",p->Loc2Pad(    0    , -dz/2      ,padx,pady),padx,pady);    
577   Info(" 73-  1","sec=%i padx=%3i pady=%3i",p->Loc2Pad(    0    , -py/2      ,padx,pady),padx,pady);    
578   cout<<endl;
579   p->Pad2Loc(padx=  1,pady=1,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
580   p->Pad2Loc(padx= 48,pady=1,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
581   p->Pad2Loc(padx= 49,pady=1,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
582   p->Pad2Loc(padx= 96,pady=1,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
583   p->Pad2Loc(padx= 97,pady=1,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
584   p->Pad2Loc(padx=144,pady=1,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
585   cout<<endl;
586   p->Pad2Loc(padx=  1,pady=80,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
587   p->Pad2Loc(padx= 48,pady=80,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
588   p->Pad2Loc(padx= 49,pady=80,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
589   p->Pad2Loc(padx= 96,pady=80,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
590   p->Pad2Loc(padx= 97,pady=80,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
591   p->Pad2Loc(padx=144,pady=80,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
592   cout<<endl;
593   p->Pad2Loc(padx=  1,pady=81,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
594   p->Pad2Loc(padx= 48,pady=81,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
595   p->Pad2Loc(padx= 49,pady=81,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
596   p->Pad2Loc(padx= 96,pady=81,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
597   p->Pad2Loc(padx= 97,pady=81,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
598   p->Pad2Loc(padx=144,pady=81,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
599   cout<<endl;
600   p->Pad2Loc(padx=  1,pady=160,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
601   p->Pad2Loc(padx= 48,pady=160,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
602   p->Pad2Loc(padx= 49,pady=160,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
603   p->Pad2Loc(padx= 96,pady=160,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
604   p->Pad2Loc(padx= 97,pady=160,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
605   p->Pad2Loc(padx=144,pady=160,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
606 }//void TestSeg()
607 //__________________________________________________________________________________________________
608 void TestMenu()
609 {
610   TControlBar *pMenu = new TControlBar("vertical","RICH test");
611   pMenu->AddButton("Test segmentation",  "TestSeg()",         "Test AliRICHParam segmentation methods");
612   pMenu->AddButton("Test transform",     "TestTransform()",   "Test ALiRICHChamber methods");
613   pMenu->AddButton("Test response",      "TestResponse()",    "Test AliRICHParam response methods");
614   pMenu->AddButton("Test sdigits",       "TestSD()",          "Create test set of sdigits");
615   pMenu->AddButton("Test digits OLD",    "TestDigitsOLD()",   "Create test set of OLD digits");
616   pMenu->AddButton("Test clusters",      "TestC()",           "Create test set of clusters");
617   pMenu->Show();  
618 }//TestMenu()
619 //__________________________________________________________________________________________________
620 void GeoMenu()
621 {
622   TControlBar *pMenu = new TControlBar("vertical","RICH draw");
623   pMenu->AddButton("RICH Isometry", "gMC->Gdraw(\"ALIC\", 60,40,0, 10,10, 0.008,0.008)","Draws ALIC volume in isometry");
624   pMenu->AddButton("RICH Front XY", "gMC->Gdraw(\"ALIC\", 0,0,0, 10,10, 0.01,0.01)","Draws ALIC volume in XY view");
625   pMenu->AddButton("RICH Side YZ",  "gMC->Gdraw(\"ALIC\",90,180, 0, 10,10, 0.01,0.01)","Draws ALIC volume in YZ view");
626   pMenu->AddButton("RICH Top XZ",   "gMC->Gdraw(\"ALIC\",90, 90, 0, 10,10, 0.01,0.01)","Draws ALIC volume in XZ view");
627   pMenu->AddButton("Module Isometry","gMC->Gdraw(\"SRIC\", 30,60,0, 10,10, 0.1,0.1)","Draws SRIC volume in isometry");
628   pMenu->AddButton("Module Front XY","gMC->Gdraw(\"SRIC\", 0,0,0, 10,10, 0.1,0.1)","Draws SRIC volume in XY view");
629   pMenu->AddButton("Module Top XZ", "gMC->Gdraw(\"SRIC\",90, 90, 0, 10,10, 0.1,0.1)","Draws SRIC volume in XZ view");
630   pMenu->AddButton("ALICE Tree", "((TGeant3*)gMC)->Gdtree(\"ALIC\")","Draws ALICE tree");      
631   pMenu->AddButton("RICH Tree",  "((TGeant3*)gMC)->Gdtree(\"RICH\")","Draws RICH tree");      
632   pMenu->AddButton("Geo test",  "GeoTest()",   "Draw RICH geo as a macro");
633   pMenu->AddButton("Print ref", "PrintGeo()",  "Print RICH chambers default position");
634   pMenu->AddButton("AliRICH::Print", "r->Print();", "Print RICH chambers default position");
635   pMenu->AddButton("Test transform","TestTransform()","Test L2G and G2L methods");
636   pMenu->Show();  
637 }//GeoMenu()
638 //__________________________________________________________________________________________________
639 void menu()
640
641   TControlBar *pMenu = new TControlBar("vertical","RICH main");
642        
643   if(ReadAlice()){//it's from file, reconstruct
644     pMenu->AddButton("hits->sdigits->digits->clusters","MainTrank()","Convert");
645     
646     pMenu->AddButton("hits->sdigits",    "H_SD()",       "Perform first phase converstion");
647     pMenu->AddButton("sdigits->digits",  "SD_D()",       "Perform first phase converstion");
648     pMenu->AddButton("digits->clusters", "D_C()",        "Perform first phase converstion");
649
650     pMenu->AddButton("Show","Show()","Shows the structure of events in files");
651     pMenu->AddButton("OLD specials->sdigits",          "OLD_S_SD()",       "Perform first phase converstion");
652     
653   }else{//it's aliroot, simulate
654     pMenu->AddButton("Run",         "a->Run(1)",       "Process!");
655   }
656   pMenu->AddButton("Geo submenu",     "GeoMenu()",            "Shows geomentry submenu");
657   pMenu->AddButton("Geo GUI", "new G3GeometryGUI;","Create instance of G4GeometryGUI"); 
658   pMenu->AddButton("Test submenu",    "TestMenu()",            "Shows test submenu");
659   pMenu->AddButton("Browser",         "new TBrowser;",         "Start ROOT TBrowser");
660   pMenu->AddButton("Display Fast",    "DisplFast()",           "Display Fast");
661   pMenu->AddButton("Control Plots",   "ControlPlots()",        "Display some control histograms");
662   pMenu->AddButton("Debug ON",     "DebugON();",   "Switch debug on-off");   
663   pMenu->AddButton("Debug OFF",    "DebugOFF();",   "Switch debug on-off");   
664   pMenu->AddButton("Quit",            ".q",                    "Close session");
665   pMenu->Show();
666   a=gAlice;//for manual manipulation convinience
667 }//menu()
668 //__________________________________________________________________________________________________
669 void DebugOFF(){  Info("DebugOFF","");  a->SetDebug(0);  r->SetDebug(0);  AliLoader::SetDebug(0);}
670 void DebugON() {  Info("DebugON","");   a->SetDebug(1);  r->SetDebug(1);  AliLoader::SetDebug(1);}