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