TestReponse with new params
[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 }//PrintGeo()
448 //__________________________________________________________________________________________________
449 void TestResponse()
450 {
451   TCanvas *pC=new TCanvas("c","Amplification test",900,800);
452   pC->Divide(1,2);
453   pC->cd(1);
454   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);
455   pF1->Draw();
456   
457   pC->cd(2);
458   
459   const Int_t nPoints=8;
460   THStack *pStack=new THStack("stack","photons");
461   TLegend *pLeg=new TLegend(0.6,0.2,0.9,0.5,"legend");    
462   TH1F *apH[nPoints];
463   
464   Double_t starty=AliRICHParam::DeadZone()/2;
465   Double_t deltay=AliRICHParam::SectorSizeY()/nPoints;
466   
467   for(int i=0;i<nPoints;i++){
468     apH[i]=new TH1F(Form("h%i",i),"Qdc for Photon;QDC;Counts",1000,0,1000); apH[i]->SetLineColor(i);
469     pStack->Add(apH[i]);                 
470     pLeg->AddEntry(apH[i],Form("@(0,%5.2f->%5.2f)",starty+i*deltay,starty+i*deltay-AliRICHParam::SectorSizeY()/2));
471   }
472         
473   
474   TVector3 x3(0,0,0);  
475   Int_t sector=10;
476 //  AliRICHParam::ResetWireSag();
477   for(Int_t i=0;i<10000;i++){//events loop
478     for(int j=0;j<nPoints;j++){
479       x3.SetY(starty-j*deltay);
480       apH[j]->Fill(AliRICHParam::Loc2TotQdc(x3,400e-9,500000,sector));
481     }
482   }
483   pStack->Draw("nostack");
484   pLeg->Draw();
485 }//TestResponse()
486 //__________________________________________________________________________________________________
487 void TestDigitsOLD()
488 {
489   Info("TestDigitsOLD","Creating test digits.");
490   rl->MakeTree("D");r->MakeBranch("D");
491
492
493   Int_t t[10];
494   Int_t c[10];
495   Int_t d[5];
496   t[0]=100;t[1]=200;t[2]=300;
497   c[0]=10;c[1]=20;c[2]=30;
498
499
500   d[0]=1;d[1]=1;d[2]=10;d[3]=3;d[4]=4;r->AddDigitOld(1,t,c,d);
501
502   d[0]=2;d[1]=2;d[2]=10;d[3]=3;d[4]=4;r->AddDigitOld(2,t,c,d);
503   d[0]=2;d[1]=3;d[2]=10;d[3]=3;d[4]=4;r->AddDigitOld(2,t,c,d);
504
505   d[0]=2;d[1]=2;d[2]=100;d[3]=3;d[4]=4;r->AddDigitOld(3,t,c,d);
506   d[0]=2;d[1]=3;d[2]= 50;d[3]=3;d[4]=4;r->AddDigitOld(3,t,c,d);
507   d[0]=2;d[1]=4;d[2]=200;d[3]=3;d[4]=4;r->AddDigitOld(3,t,c,d);
508
509   d[0]=2;d[1]=2;d[2]=100;d[3]=3;d[4]=4;r->AddDigitOld(6,t,c,d);
510   d[0]=2;d[1]=3;d[2]= 50;d[3]=3;d[4]=4;r->AddDigitOld(6,t,c,d);
511   d[0]=2;d[1]=4;d[2]=200;d[3]=3;d[4]=4;r->AddDigitOld(6,t,c,d);
512   d[0]=2;d[1]=5;d[2]= 50;d[3]=3;d[4]=4;r->AddDigitOld(6,t,c,d);
513   d[0]=2;d[1]=6;d[2]=300;d[3]=3;d[4]=4;r->AddDigitOld(6,t,c,d);
514   d[0]=2;d[1]=7;d[2]= 50;d[3]=3;d[4]=4;r->AddDigitOld(6,t,c,d);
515
516   rl->TreeD()->Fill();
517   rl->WriteDigits("OVERWRITE");
518   rl->UnloadDigits();
519   r->ResetDigitsOld();
520   Info("TestDigitsOLD","Stop.");
521 }//void TestDigits()
522 //__________________________________________________________________________________________________
523 void TestSD()
524 {
525   Info("TestSD","Creating test sdigits.");
526   rl->MakeTree("S");r->MakeBranch("S");
527   
528     for(Int_t iEventN=0;iEventN<a->GetEventsPerRun();iEventN++){//events loop
529     al->GetEvent(iEventN);
530   
531     if(!rl->TreeH()) rl->LoadHits();//from
532     if(!rl->TreeS()) rl->MakeTree("S");    r->MakeBranch("S");//to
533       
534     for(Int_t iPrimN=0;iPrimN<rl->TreeH()->GetEntries();iPrimN++){//prims loop
535       rl->TreeH()->GetEntry(iPrimN);
536       for(Int_t iHitN=0;iHitN<3;iHitN++){//hits loop  ???
537         AliRICHhit *pHit=r->Hits()->At(iHitN);        
538         TVector3 globX3(pHit->X(),pHit->Y(),pHit->Z());        
539         TVector3 locX3=r->C(pHit->C())->Glob2Loc(globX3);
540         
541         Int_t sector;
542         Int_t iTotQdc=r->Param()->Loc2TotQdc(locX3,pHit->Eloss(),pHit->Pid(),sector);
543         
544         Int_t iPadXmin,iPadXmax,iPadYmin,iPadYmax;
545         r->Param()->Loc2Area(locX3,iPadXmin,iPadYmin,iPadXmax,iPadYmax);
546         cout<<"left-down=("<<iPadXmin<<","<<iPadYmin<<") right-up=("<<iPadXmax<<','<<iPadYmax<<')'<<endl;
547         for(Int_t iPadY=iPadYmin;iPadY<=iPadYmax;iPadY++)
548           for(Int_t iPadX=iPadXmin;iPadX<=iPadXmax;iPadX++){
549             Float_t iPadQdc=iTotQdc*r->Param()->Loc2PadFrac(locX3,iPadX,iPadY);
550             Int_t padx,pady; r->Param()->Loc2Pad(locX3.X(),locX3.Y(),padx,pady);
551             cout<<"hit="<<iHitN<<" ("<<locX3.X()<<','<<locX3.Y()<<")("<<padx<<','<<pady<<") cur pad("<<iPadX<<","<<iPadY<<") qtot="<<iTotQdc<<" qfrac="<<r->Param()->Loc2PadFrac(locX3,iPadX,iPadY)<<endl;
552           }
553 //            r->AddSDigit(pHit->C(),padx,pady,r->Param()->Local2PadQdc(localX3,padx,pady),pHit->GetTrack());
554       }//hits loop
555     }//prims loop
556     rl->TreeS()->Fill();
557     rl->WriteSDigits("OVERWRITE");
558   }//events loop
559   
560   rl->UnloadHits();
561   rl->UnloadSDigits();  
562
563   rl->TreeS()->Fill();
564   rl->WriteSDigits("OVERWRITE");
565   rl->UnloadSDigits();
566   cout<<endl;r->Sdigits()->Print();
567   r->ResetSDigits();
568   Info("TestSdigits","Stop.");
569 }//void TestSdigits()
570 //__________________________________________________________________________________________________
571 void TestC()
572 {
573   Info("TestC","Creating test clusters.");
574   rl->MakeTree("R");r->MakeBranch("R");
575   
576   AliRICHcluster c;
577   c.AddDigit(new AliRICHdigit(1,20,21,200,1,2,3));
578   c.AddDigit(new AliRICHdigit(1,22,21,250,1,2,3));
579   c.CoG();
580   
581   r->AddCluster(c);  
582   
583   rl->TreeR()->Fill();
584   rl->WriteRecPoints("OVERWRITE");
585   rl->UnloadRecPoints();
586   r->ResetClusters();
587   
588   Info("TestC","Stop.");
589 }//TestC()
590 //__________________________________________________________________________________________________
591 void TestSeg()
592 {
593   AliRICHParam *p=r->Param();
594   Int_t padx,pady;
595   Double_t x,y;
596   Double_t dz=p->DeadZone();
597   Double_t sx=p->SectorSizeX(); Double_t sy=p->SectorSizeY();  Double_t px=p->PcSizeX(); Double_t py=p->PcSizeY();
598   cout<<endl;
599   Info("  1-  1","sec=%i padx=%3i pady=%3i",p->Loc2Pad(-px/2    , -py/2        ,padx,pady),padx,pady);
600   Info(" 48-  1","sec=%i padx=%3i pady=%3i",p->Loc2Pad(-sx/2-dz , -py/2        ,padx,pady),padx,pady);
601   Info(" 49-  1","sec=%i padx=%3i pady=%3i",p->Loc2Pad(-sx/2    , -py/2        ,padx,pady),padx,pady);
602   Info(" 96-  1","sec=%i padx=%3i pady=%3i",p->Loc2Pad( sx/2    , -py/2        ,padx,pady),padx,pady);
603   Info(" 97-  1","sec=%i padx=%3i pady=%3i",p->Loc2Pad( sx/2+dz , -py/2        ,padx,pady),padx,pady);
604   Info("144-  1","sec=%i padx=%3i pady=%3i",p->Loc2Pad( px/2    , -py/2        ,padx,pady),padx,pady);
605   cout<<endl;
606   Info("  1- 80","sec=%i padx=%3i pady=%3i",p->Loc2Pad(-px/2    , -dz/2        ,padx,pady),padx,pady);
607   Info(" 48- 80","sec=%i padx=%3i pady=%3i",p->Loc2Pad(-sx/2-dz , -dz/2        ,padx,pady),padx,pady);
608   Info(" 49- 80","sec=%i padx=%3i pady=%3i",p->Loc2Pad(-sx/2    , -dz/2        ,padx,pady),padx,pady);
609   Info(" 96- 80","sec=%i padx=%3i pady=%3i",p->Loc2Pad( sx/2    , -dz/2        ,padx,pady),padx,pady);
610   Info(" 97- 80","sec=%i padx=%3i pady=%3i",p->Loc2Pad( sx/2+dz , -dz/2        ,padx,pady),padx,pady);
611   Info("144- 80","sec=%i padx=%3i pady=%3i",p->Loc2Pad( px/2    , -dz/2        ,padx,pady),padx,pady);
612   cout<<endl;
613   Info("  1- 81","sec=%i padx=%3i pady=%3i",p->Loc2Pad(-px/2    ,  dz/2        ,padx,pady),padx,pady);
614   Info(" 48- 81","sec=%i padx=%3i pady=%3i",p->Loc2Pad(-sx/2-dz ,  dz/2        ,padx,pady),padx,pady);
615   Info(" 49- 81","sec=%i padx=%3i pady=%3i",p->Loc2Pad(-sx/2    ,  dz/2        ,padx,pady),padx,pady);
616   Info(" 96- 81","sec=%i padx=%3i pady=%3i",p->Loc2Pad( sx/2    ,  dz/2        ,padx,pady),padx,pady);
617   Info(" 97- 81","sec=%i padx=%3i pady=%3i",p->Loc2Pad( sx/2+dz ,  dz/2        ,padx,pady),padx,pady);
618   Info("144- 81","sec=%i padx=%3i pady=%3i",p->Loc2Pad( px/2    ,  dz/2        ,padx,pady),padx,pady);
619   cout<<endl;
620   Info("  1-160","sec=%i padx=%3i pady=%3i",p->Loc2Pad(-px/2    ,  py/2        ,padx,pady),padx,pady);
621   Info(" 48-160","sec=%i padx=%3i pady=%3i",p->Loc2Pad(-sx/2-dz ,  py/2        ,padx,pady),padx,pady);
622   Info(" 49-160","sec=%i padx=%3i pady=%3i",p->Loc2Pad(-sx/2    ,  py/2        ,padx,pady),padx,pady);
623   Info(" 96-160","sec=%i padx=%3i pady=%3i",p->Loc2Pad( sx/2    ,  py/2        ,padx,pady),padx,pady);
624   Info(" 97-160","sec=%i padx=%3i pady=%3i",p->Loc2Pad( sx/2+dz ,  py/2        ,padx,pady),padx,pady);
625   Info("144-160","sec=%i padx=%3i pady=%3i",p->Loc2Pad( px/2    ,  py/2        ,padx,pady),padx,pady);  
626   cout<<endl;
627   Info(" 73-160","sec=%i padx=%3i pady=%3i",p->Loc2Pad(    0    ,  py/2      ,padx,pady),padx,pady);    
628   Info(" 73- 81","sec=%i padx=%3i pady=%3i",p->Loc2Pad(    0    ,  dz/2      ,padx,pady),padx,pady);    
629   Info("0-0dead","sec=%i padx=%3i pady=%3i",p->Loc2Pad(    0    ,   0        ,padx,pady),padx,pady);    
630   Info(" 73- 80","sec=%i padx=%3i pady=%3i",p->Loc2Pad(    0    , -dz/2      ,padx,pady),padx,pady);    
631   Info(" 73-  1","sec=%i padx=%3i pady=%3i",p->Loc2Pad(    0    , -py/2      ,padx,pady),padx,pady);    
632   cout<<endl;
633   p->Pad2Loc(padx=  1,pady=1,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
634   p->Pad2Loc(padx= 48,pady=1,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
635   p->Pad2Loc(padx= 49,pady=1,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
636   p->Pad2Loc(padx= 96,pady=1,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
637   p->Pad2Loc(padx= 97,pady=1,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
638   p->Pad2Loc(padx=144,pady=1,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
639   cout<<endl;
640   p->Pad2Loc(padx=  1,pady=80,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
641   p->Pad2Loc(padx= 48,pady=80,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
642   p->Pad2Loc(padx= 49,pady=80,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
643   p->Pad2Loc(padx= 96,pady=80,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
644   p->Pad2Loc(padx= 97,pady=80,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
645   p->Pad2Loc(padx=144,pady=80,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
646   cout<<endl;
647   p->Pad2Loc(padx=  1,pady=81,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
648   p->Pad2Loc(padx= 48,pady=81,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
649   p->Pad2Loc(padx= 49,pady=81,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
650   p->Pad2Loc(padx= 96,pady=81,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
651   p->Pad2Loc(padx= 97,pady=81,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
652   p->Pad2Loc(padx=144,pady=81,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
653   cout<<endl;
654   p->Pad2Loc(padx=  1,pady=160,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
655   p->Pad2Loc(padx= 48,pady=160,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
656   p->Pad2Loc(padx= 49,pady=160,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
657   p->Pad2Loc(padx= 96,pady=160,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
658   p->Pad2Loc(padx= 97,pady=160,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
659   p->Pad2Loc(padx=144,pady=160,x,y);  cout<<"padx="<<padx<<" pady="<<pady<<" x="<<x<<" y="<<y<<endl;
660 }//void TestSeg()
661 //__________________________________________________________________________________________________
662 void TestMenu()
663 {
664   TControlBar *pMenu = new TControlBar("vertical","RICH test");
665   pMenu->AddButton("Test segmentation",  "TestSeg()",         "Test AliRICHParam segmentation methods");
666   pMenu->AddButton("Test transform",     "TestTransform()",   "Test ALiRICHChamber methods");
667   pMenu->AddButton("Test response",      "TestResponse()",    "Test AliRICHParam response methods");
668   pMenu->AddButton("Test sdigits",       "TestSD()",          "Create test set of sdigits");
669   pMenu->AddButton("Test digits OLD",    "TestDigitsOLD()",   "Create test set of OLD digits");
670   pMenu->AddButton("Test clusters",      "TestC()",           "Create test set of clusters");
671   pMenu->Show();  
672 }//TestMenu()
673 //__________________________________________________________________________________________________
674 void GeoMenu()
675 {
676   TControlBar *pMenu = new TControlBar("vertical","RICH draw");
677   pMenu->AddButton("RICH Isometry", "gMC->Gdraw(\"ALIC\", 60,40,0, 10,10, 0.008,0.008)","Draws ALIC volume in isometry");
678   pMenu->AddButton("RICH Front XY", "gMC->Gdraw(\"ALIC\", 0,0,0, 10,10, 0.01,0.01)","Draws ALIC volume in XY view");
679   pMenu->AddButton("RICH Side YZ",  "gMC->Gdraw(\"ALIC\",90,180, 0, 10,10, 0.01,0.01)","Draws ALIC volume in YZ view");
680   pMenu->AddButton("RICH Top XZ",   "gMC->Gdraw(\"ALIC\",90, 90, 0, 10,10, 0.01,0.01)","Draws ALIC volume in XZ view");
681   pMenu->AddButton("Module Isometry","gMC->Gdraw(\"SRIC\", 30,60,0, 10,10, 0.1,0.1)","Draws SRIC volume in isometry");
682   pMenu->AddButton("Module Front XY","gMC->Gdraw(\"SRIC\", 0,0,0, 10,10, 0.1,0.1)","Draws SRIC volume in XY view");
683   pMenu->AddButton("Module Top XZ", "gMC->Gdraw(\"SRIC\",90, 90, 0, 10,10, 0.1,0.1)","Draws SRIC volume in XZ view");
684   pMenu->AddButton("ALICE Tree", "((TGeant3*)gMC)->Gdtree(\"ALIC\")","Draws ALICE tree");      
685   pMenu->AddButton("RICH Tree",  "((TGeant3*)gMC)->Gdtree(\"RICH\")","Draws RICH tree");      
686   pMenu->AddButton("Geo test",  "GeoTest()",   "Draw RICH geo as a macro");
687   pMenu->AddButton("Print ref", "PrintGeo()",  "Print RICH chambers default position");
688   pMenu->AddButton("AliRICH::Print", "r->Print();", "Print RICH chambers default position");
689   pMenu->AddButton("Test transform","TestTransform()","Test L2G and G2L methods");
690   pMenu->Show();  
691 }//GeoMenu()
692 //__________________________________________________________________________________________________
693 void menu()
694
695   TControlBar *pMenu = new TControlBar("vertical","RICH main");
696        
697   if(ReadAlice()){//it's from file, reconstruct
698     pMenu->AddButton("hits->sdigits->digits","MainTrank()","Convert");
699     pMenu->AddButton("Debug ON",     "DebugON();",   "Switch debug on-off");   
700     pMenu->AddButton("Debug OFF",    "DebugOFF();",   "Switch debug on-off");   
701     
702     pMenu->AddButton("hits->sdigits",    "H_SD()",       "Perform first phase converstion");
703     pMenu->AddButton("sdigits->digits",  "SD_D()",       "Perform first phase converstion");
704     pMenu->AddButton("digits->clusters", "D_C()",        "Perform first phase converstion");
705
706     pMenu->AddButton("OLD Show","Show3()","Shows the structure of events in files");
707     pMenu->AddButton("OLD specials->sdigits",          "OLD_S_SD()",       "Perform first phase converstion");
708     pMenu->AddButton("OLD sdigits->digits",         "OLD_SD_D()","Perform second phase converstion");
709     pMenu->AddButton("OLD digits->clusters",     "OLD_D_C()",  "Perform second phase converstion");
710     
711   }else{//it's aliroot, simulate
712     pMenu->AddButton("Run",         "a->Run(1)",       "Process!");
713   }
714   pMenu->AddButton("Geo submenu",     "GeoMenu()",            "Shows geomentry submenu");
715   pMenu->AddButton("Geo GUI", "new G3GeometryGUI;","Create instance of G4GeometryGUI"); 
716   pMenu->AddButton("Test submenu",    "TestMenu()",            "Shows test submenu");
717   pMenu->AddButton("Browser",         "new TBrowser;",         "Start ROOT TBrowser");
718   pMenu->AddButton("Display Fast",    "DisplFast()",           "Display Fast");
719   pMenu->AddButton("Quit",            ".q",                    "Close session");
720   pMenu->Show();
721   a=gAlice;//for manual manipulation convinience
722 }//menu()
723 //__________________________________________________________________________________________________