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