]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RICH/menu.C
Implementation of reconstructors (T.Kuhr)
[u/mrichter/AliRoot.git] / RICH / menu.C
index 0e17d466b8cbd615bcdd47ed9194da8dbe6e8282..c5f29dc00b8ababa8981985fd69cd7d52f86b6a1 100644 (file)
-void Spec2D()
+AliRICH * R() {return r;}
+
+void ControlPlots()
+{  
+  TH1F *pHxD,*pHyD,*pCqH1,*pCsH1,*pCqMipH1,*pCsMipH1,*pCqCerH1,*pCsCerH1,*pCqFeeH1,*pCsFeeH1,*pNumClusH1;  
+  TH2F *pCmH2,*pCmMipH2,*pCmCerH2,*pCmFeeH2;
+  
+  Bool_t isDig =!R()->GetLoader()->LoadDigits();
+  Bool_t isClus=!R()->GetLoader()->LoadRecPoints();
+
+  if(!isDig && !isClus){ Info("ControlPlots","No digits and clusters! Nothing to do.");return;}
+    
+  TFile *pFile = new TFile("$(HOME)/ControlPlots.root","RECREATE");   
+  
+  if(isDig){
+    cout<<"Digits available\n";
+    pHxD=new TH1F("HitDigitDiffX","Hit-Digits diff X all chambers;diff [cm]",100,-10,10); 
+    pHyD=new TH1F("HitDigitDiffY","Hit-Digits diff Y all chambers;diff [cm]",100,-10,10); 
+  }//isDig
+  
+  if(isClus){ 
+    cout<<"Clusters available\n";
+    pNumClusH1=new TH1F("NumClusPerEvent","Number of clusters per event;number",50,0,49);
+    pCqH1=new TH1F("ClusQ",   "Cluster Charge all chambers;q [QDC]",R()->P()->MaxQdc(),0,R()->P()->MaxQdc());
+    pCsH1=new TH1F("ClusSize","Cluster size all chambers;size [number of pads in cluster]",100,0,100);
+    pCmH2=new TH2F("ClusMap", "Cluster map;x [cm];y [cm]",1000,-R()->P()->PcSizeX()/2,R()->P()->PcSizeX()/2,
+                                                          1000,-R()->P()->PcSizeY()/2,R()->P()->PcSizeY()/2);
+  
+    pCqMipH1=new TH1F("MipClusQ",   "MIP Cluster Charge all chambers;q [QDC]",R()->P()->MaxQdc(),0,R()->P()->MaxQdc());
+    pCsMipH1=new TH1F("MipClusSize","MIP Cluster size all chambers;size [number of pads in cluster]",100,0,100);
+    pCmMipH2=new TH2F("MipClusMap", "MIP Cluster map;x [cm];y [cm]",1000,-R()->P()->PcSizeX()/2,R()->P()->PcSizeX()/2,
+                                                                    1000,-R()->P()->PcSizeY()/2,R()->P()->PcSizeY()/2);
+  
+    pCqCerH1=new TH1F("CerClusQ",   "Cerenkov Cluster Charge all chambers;q [QDC]",R()->P()->MaxQdc(),0,R()->P()->MaxQdc());
+    pCsCerH1=new TH1F("CerClusSize","Cernekov Cluster size all chambers;size [number of pads in cluster]",100,0,100);
+    pCmCerH2=new TH2F("CerClusMap", "Cerenkov Cluster map;x [cm];y [cm]",1000,-R()->P()->PcSizeX()/2,R()->P()->PcSizeX()/2,
+                                                                         1000,-R()->P()->PcSizeY()/2,R()->P()->PcSizeY()/2);
+    
+    pCqFeeH1=new TH1F("FeeClusQ",   "Feedback Cluster Charge all chambers;q [QDC]",R()->P()->MaxQdc(),0,R()->P()->MaxQdc());
+    pCsFeeH1=new TH1F("FeeClusSize","Feedback Cluster size all chambers;size [number of pads in cluster]",100,0,100);
+    pCmFeeH2=new TH2F("FeeClusMap", "Feedback Cluster map;x [cm];y [cm]",1000,-R()->P()->PcSizeX()/2,R()->P()->PcSizeX()/2,
+                                                                         1000,-R()->P()->PcSizeY()/2,R()->P()->PcSizeY()/2);
+  }//isClus
+  
+  for(Int_t iEvtN=0;iEvtN<R()->GetLoader()->GetRunLoader()->GetAliRun()->GetEventsPerRun();iEvtN++){//events loop
+    R()->GetLoader()->GetRunLoader()->GetEvent(iEvtN);    
+    if(isClus) R()->GetLoader()->TreeR()->GetEntry(0);
+    if(isDig)  R()->GetLoader()->TreeD()->GetEntry(0);  
+    
+    for(Int_t iChamN=1;iChamN<=7;iChamN++){//chambers loop
+      if(isClus){
+        Int_t iNclusCham=R()->Clusters(iChamN)->GetEntries();
+        if(iNclusCham) pNumClusH1->Fill(iNclusCham);//fill total number of clusters for a given event
+        for(Int_t iClusN=0;iClusN<iNclusCham;iClusN++){//clusters loop
+          AliRICHcluster *pClus=(AliRICHcluster*)R()->Clusters(iChamN)->At(iClusN);
+                                      pCqH1->Fill(pClus->Q());   pCsH1->Fill(pClus->Size());   pCmH2->Fill(pClus->X(),pClus->Y());    //common        
+           if(pClus->IsPureMip())     {pCqMipH1->Fill(pClus->Q());pCsMipH1->Fill(pClus->Size());pCmMipH2->Fill(pClus->X(),pClus->Y());}//Pure Mips
+           if(pClus->IsPureCerenkov()){pCqCerH1->Fill(pClus->Q());pCsCerH1->Fill(pClus->Size());pCmCerH2->Fill(pClus->X(),pClus->Y());}//Pure Photons
+           if(pClus->IsPureFeedback()){pCqFeeH1->Fill(pClus->Q());pCsFeeH1->Fill(pClus->Size());pCmFeeH2->Fill(pClus->X(),pClus->Y());}//Pure Feedbacks
+        }//clusters loop
+      }//isClus
+      if(isDig){
+        for(Int_t iDigN=0;iDigN<r->Digits(iChamN)->GetEntries();iDigN++){//digits loop
+          AliRICHdigit *pDig=(AliRICHdigit*)r->Digits(iChamN)->At(iDigN);
+          AliRICHhit   *pHit=hit(pDig->Tid(0));
+          TVector2 hitV2=R()->C(iChamN)->Glob2Loc(pHit->OutX3()); TVector2 digV2=R()->P()->Pad2Loc(pDig->X(),pDig->Y());
+          pHxD->Fill(hitV2.X()-digV2.X()); pHyD->Fill(hitV2.Y()-digV2.Y());
+        }//digits loop
+      }//isDig
+    }//chambers loop
+    Info("ControlPlots","Event %i processed.",iEvtN);
+  }//events loop 
+  
+  if(isDig)  R()->GetLoader()->UnloadDigits();
+  if(isClus) R()->GetLoader()->UnloadRecPoints();
+  
+  pFile->Write(); delete pFile;
+}//void ControlPlots()
+//__________________________________________________________________________________________________
+void MainTrank()
 {
-  Info("Spec2D","Start.");    
+  TStopwatch sw;TDatime time;
+  H_SD(); SD_D();   AliRICHClusterFinder *z=new AliRICHClusterFinder(r); z->Exec();//delete z;  
+  cout<<"\nInfo in <MainTrank>: Start time: ";time.Print();
+    cout<<"Info in <MainTrank>: Stop  time: ";time.Set();  time.Print();
+    cout<<"Info in <MainTrank>: Time  used: ";sw.Print();
+}
+//__________________________________________________________________________________________________
+void sh()
+{//prints list of hits for a given event
+  R()->GetLoader()->LoadHits();
+  
+  Int_t iTotalHits=0;
+  for(Int_t iPrimN=0;iPrimN<rl->TreeH()->GetEntries();iPrimN++){//prims loop
+    R()->GetLoader()->TreeH()->GetEntry(iPrimN);      
+    R()->Hits()->Print();
+    iTotalHits+=R()->Hits()->GetEntries();
+  }
+  Info("sh","totally %i hits",iTotalHits);
+  R()->GetLoader()->UnloadHits();
+}
+//__________________________________________________________________________________________________
+AliRICHhit* hit(Int_t tid)
+{//print hits for given tid
+  R()->GetLoader()->LoadHits();
+  for(Int_t iPrimN=0;iPrimN<R()->GetLoader()->TreeH()->GetEntries();iPrimN++){//prims loop      
+    R()->GetLoader()->TreeH()->GetEntry(iPrimN);
+    for(Int_t iHitN=0;iHitN<R()->Hits()->GetEntries();iHitN++){
+      AliRICHhit *pHit=(AliRICHhit*)R()->Hits()->At(iHitN);
+      if(tid==pHit->Track()) {R()->GetLoader()->UnloadHits();return pHit;}
+    }//hits
+  }//prims loop
+  R()->GetLoader()->UnloadHits();
+}
+//__________________________________________________________________________________________________
+void ss()
+{
+  if(rl->LoadSDigits()) return;
+  rl->TreeS()->GetEntry(0);
+  r->SDigits()->Print();
+  Info("ss","totally %i sdigits",r->SDigits()->GetEntries());
+  rl->UnloadSDigits();
+}
+//__________________________________________________________________________________________________
+void sd()
+{
+  if(rl->LoadDigits()) return;
+  rl->TreeD()->GetEntry(0);
+  Int_t iTotalDigits=0;
+  for(int i=1;i<=7;i++){
+    r->Digits(i)->Print();
+    iTotalDigits+=r->Digits(i)->GetEntries();
+  }
+  Info("sd","totally %i digits",iTotalDigits);
+  rl->UnloadDigits();
+}
+//__________________________________________________________________________________________________
+void sc(Int_t iEvtN=0)
+{
+  Info("sc","List of clusters for event %i",iEvtN);
+  R()->GetLoader()->GetRunLoader()->GetEvent(iEvtN);    
+  if(R()->GetLoader()->LoadRecPoints()) return;
+//  r->SetTreeAddress();
+  R()->GetLoader()->TreeR()->GetEntry(0);
+  Int_t iTotalClusters=0;
+  for(Int_t iChamber=1;iChamber<=7;iChamber++){
+    R()->Clusters(iChamber)->Print();
+    iTotalClusters+=R()->Clusters(iChamber)->GetEntries();
+  }
+  R()->GetLoader()->UnloadRecPoints();
+  Info("sc","totally %i clusters",iTotalClusters);
+}
+//__________________________________________________________________________________________________
+void sp(int tid)
+{
+  R()->GetLoader()->GetRunLoader()->LoadHeader();  R()->GetLoader()->GetRunLoader()->LoadKinematics();
   
-  delete gAlice;
+  if(tid<0||tid>=R()->GetLoader()->GetRunLoader()->Stack()->GetNtrack())
+    cout<<"Valid tid number is 0-"<<R()->GetLoader()->GetRunLoader()->Stack()->GetNtrack()-1<<" for this event.\n";
+  else
+    PrintParticleInfo(tid);
   
-  AliRunDigitizer *pManager = new AliRunDigitizer(1,1);
-  pManager->SetInputStream(0,"galice.root");
-  new AliRICHDigitizer(pManager);
-  pManager->Exec("deb");
-  Info("Spec2D","Stop.");
+  R()->GetLoader()->GetRunLoader()->UnloadKinematics();  R()->GetLoader()->GetRunLoader()->UnloadHeader();
 }
-
-void Spec2Sd()
+//__________________________________________________________________________________________________
+void PrintParticleInfo(int tid)
+{
+  TParticle *p=al->Stack()->Particle(tid);
+  cout<<p->GetName()<<"("<<tid<<")";
+  if(p->GetMother(0)!=-1){cout<<" from "; PrintParticleInfo(p->GetMother(0));}
+  else                   {cout<<endl;} 
+}    
+//__________________________________________________________________________________________________
+Int_t prim(Int_t tid)
 {
-  Info("Spec2Sd","Start.");
+  R()->GetLoader()->GetRunLoader()->LoadHeader();  R()->GetLoader()->GetRunLoader()->LoadKinematics();
   
-  rl->LoadHits(); rl->MakeTree("S");  r->MakeBranch("S");//from to
+  if(tid<0||tid>=R()->GetLoader()->GetRunLoader()->Stack()->GetNtrack())
+    cout<<"Valid tid number is 0-"<<R()->GetLoader()->GetRunLoader()->Stack()->GetNtrack()-1<<" for this event.\n";
+  else
+    while(1){
+      TParticle *p=R()->GetLoader()->GetRunLoader()->GetAliRun()->Stack()->Particle(tid);
+      if(p->GetMother(0)==-1) break;
+      tid=p->GetMother(0);
+    }
   
-  for(Int_t iEventN=0;iEventN<a->GetEventsPerRun();iEventN++){//events loop
-    al->GetEvent(iEventN);
-
-    
-    for(Int_t iPrimN=0;iPrimN<rl->TreeH()->GetEntries();iPrimN++){//prims loop
-      rl->TreeH()->GetEntry(iPrimN);
-      for(Int_t i=0;i<r->Specials()->GetEntries();i++){//specials loop          
-        Int_t padx= ((AliRICHSDigit*)r->Specials()->At(i))->PadX();
-        Int_t pady= ((AliRICHSDigit*)r->Specials()->At(i))->PadY();
-        Int_t qdc=  ((AliRICHSDigit*)r->Specials()->At(i))->QPad();
-        Int_t track=((AliRICHSDigit*)r->Specials()->At(i))->HitNumber();
-        r->AddSdigit(1,padx+r->Param()->NpadsX()/2,pady+r->Param()->NpadsY()/2,qdc,track);
-      }//specials loop
-    }//prims loop
-    rl->TreeS()->Fill();
-    rl->WriteSDigits("OVERWRITE");
-    r->ResetSdigits();    r->ResetSpecials();
-  }//events loop  
-    rl->UnloadHits();     rl->UnloadSDigits();  
-  Info("Spec2Sd","Stop.");    
+  R()->GetLoader()->GetRunLoader()->UnloadKinematics();  R()->GetLoader()->GetRunLoader()->UnloadHeader();
+  return tid;
 }
 
 
-void H2Sd()
+//__________________________________________________________________________________________________
+
+Double_t r2d = TMath::RadToDeg();
+Double_t d2r = TMath::DegToRad();
+
+void DisplFast(){ AliRICHDisplFast *d = new AliRICHDisplFast();  d->Exec();}  
+
+
+void C_R()
 {
-  Info("H2Sd","Start.");
-  
-  for(Int_t iEventN=0;iEventN<a->GetEventsPerRun();iEventN++){//events loop
-    al->GetEvent(iEventN);
-  
-    if(!rl->TreeH()) rl->LoadHits();//from
-    if(!rl->TreeS()) rl->MakeTree("S");    r->MakeBranch("S");//to
+  AliRICHRecon *detect = new AliRICHRecon("RICH patrec algorithm","Reconstruction");
     
 
-    for(Int_t iPrimN=0;iPrimN<rl->TreeH()->GetEntries();iPrimN++){//prims loop
-      rl->TreeH()->GetEntry(iPrimN);
-      for(Int_t iHitN=0;iHitN<r->Hits()->GetEntries();iHitN++){//hits loop  
-        AliRICHhit *pHit=r->Hits()->At(iHitN);
-        r->Param()->G2Px
-        r->AddSdigit(pHit->C(),padx+r->Param()->NpadsX()/2,pady+r->Param()->NpadsY()/2,qdc,track);
-      }
-    }
-    rl->TreeS()->Fill();
-    rl->WriteSDigits("OVERWRITE");
-  }//events loop
-  
-  rl->UnloadHits();
-  rl->UnloadSDigits();  
-  Info("H2Sd","Stop.");  
+  for (int nev=0; nev< a->GetEventsPerRun(); nev++) {    // Event Loop
+    al->GetEvent(nev);
+    cout <<endl<< "Processing event:" <<nev<<endl;
+    detect->StartProcessEvent();
+  } // event loop  
+  delete detect;
+}  
+//__________________________________________________________________________________________________
+void D_C()
+{
+  TStopwatch sw;TDatime time;
+
+   AliRICHClusterFinder *z=new AliRICHClusterFinder(r); z->Exec();
+
+   cout << endl;
+   cout << "Info in Digits->Clusters: Start time: ";time.Print();
+   cout << "Info in Digits->Clusters: Stop  time: ";time.Set();  time.Print();
+   cout << "Info in Digits->Clusters: Time  used: ";sw.Print();
 }
+//__________________________________________________________________________________________________
 
-void Sd2D()
+void SD_D()
 {
+  Info("SD_D","Start.");  
+  extern Int_t kBad; 
+  R()->P()->GenSigmaThMap();
   rl->LoadSDigits();
-  rl->MakeTree("D");r->MakeBranch("D");
   
-  rl->TreeS()->GetEntry(0);  
-  r->Sdigits()->Sort();
-  
-  Int_t chamber,x,y,qdc,tr[3],id;
-  Int_t kBad=-101;
-  chamber=x=y=qdc=tr[0]=tr[1]=tr[2]=id=kBad;
-  Int_t counter=kBad;//how many sdigits for a given pad
-  Int_t start=0,end=0;
-        
-  for(Int_t i=0;i<r->Sdigits()->GetEntries();i++){//sdigits loop (sorted)
-    AliRICHdigit *pSdig=(AliRICHdigit*)r->Sdigits()->At(i);
-    if(pSdig->Id()==id){//still the same pad
-      end++;
-    }else{//new pad, add the pevious one
-      if(id!=kBad) r->AddDigit(chamber,x,y,qdc,tr[0],tr[1],tr[2]);//ch-xpad-ypad-qdc-tr1-2-3
-      chamber=pSdig->C();x=pSdig->X();y=pSdig->Y();qdc=pSdig->Qdc();tr[0]=pSdig->T(0);id=pSdig->Id();
-      start=i;
-    }
-  }//sdigits loop (sorted)
+  for(Int_t iEventN=0;iEventN<a->GetEventsPerRun();iEventN++){//events loop
+    al->GetEvent(iEventN);    cout<<"Event "<<iEventN<<endl;  
+    rl->MakeTree("D");      R()->MakeBranch("D"); //create TreeD with RICH branches 
+    R()->ResetSDigits();    R()->ResetDigits();   //reset lists of sdigits and digits
+    rl->TreeS()->GetEntry(0);                        //get sdigits to memory container
+    R()->SDigits()->Sort();
+      
+    Int_t combiPid=0,chamber=0,x=0,y=0,tid[3],id=0; Double_t q=0;
+    Int_t iNdigitsPerPad;//how many sdigits for a given pad
+    const int kBad=-101;//??? to be removed in code    
+    for(Int_t i=0;i<R()->SDigits()->GetEntries();i++){//sdigits loop (sorted)
+      AliRICHdigit *pSdig=(AliRICHdigit*)R()->SDigits()->At(i);
+      if(pSdig->Id()==id){//still the same pad
+        iNdigitsPerPad++; q+=pSdig->Q();  combiPid+=pSdig->CombiPid();
+        if(iNdigitsPerPad<=3)
+          tid[iNdigitsPerPad-1]=pSdig->Tid(0);
+        else
+          Warning("SDigits2Digits","More then 3 sdigits for the given pad");
+      }else{//new pad, add the pevious one
+        if(id!=kBad&&R()->P()->IsOverTh(chamber,x,y,q)) {
+           R()->AddDigit(chamber,x,y,q,combiPid,tid);
+         }
+        combiPid=pSdig->CombiPid();chamber=pSdig->C();id=pSdig->Id();
+        x=pSdig->X();y=pSdig->Y();
+        q=pSdig->Q();
+        tid[0]=pSdig->Tid(0);
+        iNdigitsPerPad=1;tid[1]=tid[2]=kBad;
+      }
+    }//sdigits loop (sorted)
   
-  r->AddDigits(chamber,x,y,qdc,tr[0],tr[1],tr[2]);//add the last digit
+    if(R()->SDigits()->GetEntries() && R()->P()->IsOverTh(chamber,x,y,q))
+      R()->AddDigit(chamber,x,y,q,combiPid,tid);//add the last digit
         
-  rl->TreeD()->Fill();  
-  rl->WriteDigits("OVERWRITE");
-    
-  cout<<endl;
-  r->Digits(1)->Print();
-}
-
-void Show3()
+    rl->TreeD()->Fill();  
+    rl->WriteDigits("OVERWRITE");
+  }//events loop
+  rl->UnloadSDigits();     rl->UnloadDigits();  
+  R()->ResetSDigits(); R()->ResetDigits();//reset lists of sdigits and digits
+  Info("SD_D","Stop.");  
+}//SD_D()
+//__________________________________________________________________________________________________
+void Show()
 {  
   cout<<endl;
   al->LoadHeader();  al->LoadKinematics();
   
-  rl->LoadHits();  Bool_t isSdigits=!rl->LoadSDigits();  Bool_t isDigits=!rl->LoadDigits();//loaders
+  rl->LoadHits();  
+    Bool_t isSdigits=!rl->LoadSDigits();  
+      Bool_t isClusters=!rl->LoadRecPoints();
+        Bool_t isDigits=!rl->LoadDigits();//loaders
   
   cout<<endl;  cout<<endl;  
   for(Int_t iEventN=0;iEventN<a->GetEventsPerRun();iEventN++){//events loop
     Int_t iNparticles=a->GetEvent(iEventN);
     Int_t iNprims=rl->TreeH()->GetEntries();
     
-    Int_t iTotalHits=0,iTotalCerenkovs=0,iTotalSpecials=0;
+    Int_t iTotalHits=0;
     for(Int_t iPrimN=0;iPrimN<iNprims;iPrimN++){//prims loop
       rl->TreeH()->GetEntry(iPrimN);      
       iTotalHits+=r->Hits()->GetEntries();
-      iTotalCerenkovs+=r->Cerenkovs()->GetEntries();
-      iTotalSpecials+=r->Specials()->GetEntries();
       TParticle *pPrim=al->Stack()->Particle(iPrimN);
-      Info("Show","Event %4i prim %4i has %4i hits %5i cerenkovs and %5i specials from %s (,%7.2f,%7.2f)",
-                           iEventN,
-                                    iPrimN,
-                                             r->Hits()->GetEntries(),
-                                                      r->Cerenkovs()->GetEntries(),
-                                                                        r->Specials()->GetEntries(),
-                                                                                         pPrim->GetName(),
-                                                                                 pPrim->Theta()*r2d,pPrim->Phi()*r2d);
+      if(iPrimN<10) Info("Show","Evt %4i prim %4i has %4i hits from %s (,%7.2f,%7.2f)",
+                  iEventN,iPrimN, r->Hits()->GetEntries(), pPrim->GetName(), pPrim->Theta()*r2d,pPrim->Phi()*r2d);
     }//prims loop
-    Info("Show","Event %i total:  %i particles %i primaries %i hits %i cerenkovs %i specials",
-                        iEventN,   iNparticles, iNprims,     iTotalHits,iTotalCerenkovs,iTotalSpecials);
+    Info("Show-HIT","Evt %i total:  %i particles %i primaries %i hits",
+                        iEventN,   iNparticles, iNprims,     iTotalHits);
     if(isSdigits){
       rl->TreeS()->GetEntry(0);
-      Info("Show","Event %i contains %5i sdigits",iEventN,r->Sdigits()->GetEntries());
+      Info("Show-SDI","Evt %i contains %5i sdigits",iEventN,r->SDigits()->GetEntries());
     }
     if(isDigits){
       rl->TreeD()->GetEntry(0);
-      Info("Show","Event %i contains %5i digits",iEventN,r->Digits(1)->GetEntries());
+      for(int i=1;i<=7;i++)
+        Info("Show-DIG","Evt %i chamber %i contains %5i digits",
+                                 iEventN,   i,           r->Digits(i)->GetEntries());
+    }else
+        Info("Show-DIG","There is no digits for this event");
+    if(isClusters){
+      rl->TreeR()->GetEntry(0);
+      for(int i=1;i<=7;i++)
+        Info("Show-CLU","Evt %i chamber %i contains %5i clusters",
+                                 iEventN,   i,           r->Clusters(i)->GetEntries());
     }
     cout<<endl;
   }//events loop
-  rl->UnloadHits();  if(isSdigits) rl->UnloadSDigits(); if(isDigits) rl->UnloadDigits();
+  rl->UnloadHits();  
+    if(isSdigits) rl->UnloadSDigits(); 
+      if(isDigits) rl->UnloadDigits(); 
+        if(isClusters) rl->UnloadRecPoints();
   al->UnloadHeader();
   al->UnloadKinematics();
   cout<<endl;
 }//void Show()
-
-void menu()// How many events to generate.
-{ 
-   
-
-  TControlBar *pMenu = new TControlBar("vertical","RICH main");
-       
-  pMenu->AddButton("Debug ON",     "DebugON();",   "Switch debug on-off");   
-  pMenu->AddButton("Debug OFF",    "DebugOFF();",   "Switch debug on-off");   
-  if(CheckAlice()){//it's from file, reconstruct
-    pMenu->AddButton("Show","Show3()","Shows the structure of events in files");
-    pMenu->AddButton("Hits->Sdigits",    "H2Sd()",       "Perform first phase converstion");
-    pMenu->AddButton("Specials->Sdigits","Spec2Sd()",    "Perform first phase converstion");
-    pMenu->AddButton("Sdigits->Digits",  "Sd2D()",       "Perform first phase converstion");
-    pMenu->AddButton("Digits->Clusters", "D2C()",        "Perform first phase converstion");
-
-    pMenu->AddButton("OLD: Specials->Digits",     "Spec2D()","Perform first phase converstion");
-    pMenu->AddButton("OLD: Digits->RawClusters",  "D2Rc()",  "Perform second phase converstion");
-    
-    pMenu->AddButton("RingViewer","RingViewer()","Show rings with reconstructed info");
-  }else{//it's aliroot, simulate
-    pMenu->AddButton("Run",         "a->Run(1)",       "Process!");
-  }
-  pMenu->AddButton("Geo submenu",          "Geo()",            "Shows geomentry submenu");
-  pMenu->AddButton("Test submenu",    "TestMenu()",            "Shows test submenu");
-  pMenu->AddButton("Browser",      "new TBrowser;",         "Start ROOT TBrowser");
-  pMenu->AddButton("Quit",         ".q",                    "Close session");
-  pMenu->Show();
-  a=gAlice;//for manual manipulation convinience
-}//void menu(Int_t iNevents)
-
-
-void DebugOFF()
-{
-  Info("DebugOFF","");
-  a->SetDebug(0);
-  r->SetDebug(0);
-  AliLoader::SetDebug(0);
-}//void DebugOFF()
-
-void DebugON()
-{
-  Info("DebugON","");  
-  a->SetDebug(1);
-  r->SetDebug(1);
-  AliLoader::SetDebug(1);
-}//void DebugON()
+//__________________________________________________________________________________________________
 
 
 AliRun *a;
@@ -202,33 +332,19 @@ AliLoader *rl,*tl,*il;
 
 AliRICH *r;
 
-Bool_t CheckAlice()
-{
-  if(gAlice){//it's aliroot
-    if(gSystem->Exec("ls galice.root")){
-      Info("CheckAlice","It's AliRoot, and no galice.root: SIMULATION");
-      gAlice->SetDebug(-1);
-      gAlice->Init("AliceConfig.C");
-      r=(AliRICH*)gAlice->GetDetector("RICH");
-      return kFALSE;
-    }else{//galice.root is present we want to read alice from file
-      ReadAlice();
-      return kTRUE;
-    }
-  }else{//it's root with ALICE libs loaded
-    ReadAlice();
-    return kTRUE;
-  }       
-}//void CheckAlice()         
-
-void ReadAlice()
+Bool_t ReadAlice()
 {
-  Info("ReadAlice","Reading ALICE from SIMULATED FILE.");
+  Info("ReadAlice","Tring to read ALICE from SIMULATED FILE.");
   AliLoader::SetDebug(0);
   if(gAlice) delete gAlice;      
   if(!(al=AliRunLoader::Open("galice.root","AlicE","update"))){
     gSystem->Exec("rm -rf *.root *.dat");
-    Fatal("ReadAlice","galice.root broken, removing all this garbage");
+    Error("ReadAlice","galice.root broken, removing all this garbage then init new one");
+    new AliRun("gAlice","Alice experiment system");
+    gAlice->SetDebug(-1);
+    gAlice->Init("Config.C");
+    r=(AliRICH*)gAlice->GetDetector("RICH");
+    return kFALSE;
   }
   al->LoadgAlice();
   if(!gAlice) Fatal("ReadAlice","No gAlice in file");
@@ -240,324 +356,225 @@ void ReadAlice()
   if(!(rl=al->GetLoader("RICHLoader")))          Warning("RICH/menu.C::ReadAlice","No RICH loader in file");        
         
   Info("ReadAlice","Run contains %i event(s)",gAlice->GetEventsPerRun());      
+  return kTRUE;
 }
 //__________________________________________________________________________________________________
-void RingViewer()
-{
-  gStyle->SetPalette(1);
-  TCanvas *view=new TCanvas("Display","ALICE RICH Display",0,0,600,600);
-  
-  TH2F *pH2=new TH2F("pH2F","RICH DISPLAY",r->Param()->Nx(),0,r->Param()->Nx(),r->Param()->Ny(),0,r->Param()->Ny());
-  pH2->SetStats(0);
-  pH2->SetMaximum(100);
-
-  Int_t Nevents = gAlice->GetEventsPerRun();
-}
-//______________________________________________________________________________
-void Geo()
-{
-  TControlBar *pMenu = new TControlBar("vertical","RICH draw");
-  pMenu->AddButton("RICH Isometry", "gMC->Gdraw(\"ALIC\", 60,120,0, 10,10, 0.01,0.01)","Draws ALIC volume in isometry");
-  pMenu->AddButton("RICH Front XY", "gMC->Gdraw(\"ALIC\", 0,0,0, 10,10, 0.01,0.01)","Draws ALIC volume in XY view");
-  pMenu->AddButton("RICH Side YZ",  "gMC->Gdraw(\"ALIC\",90,180, 0, 10,10, 0.01,0.01)","Draws ALIC volume in YZ view");
-  pMenu->AddButton("RICH Top XZ",   "gMC->Gdraw(\"ALIC\",90, 90, 0, 10,10, 0.01,0.01)","Draws ALIC volume in XZ view");
-  pMenu->AddButton("Module Isometry","gMC->Gdraw(\"SRIC\", 30,60,0, 10,10, 0.1,0.1)","Draws SRIC volume in isometry");
-  pMenu->AddButton("Module Front XY","gMC->Gdraw(\"SRIC\", 0,0,0, 10,10, 0.1,0.1)","Draws SRIC volume in XY view");
-  pMenu->AddButton("Module Top XZ", "gMC->Gdraw(\"SRIC\",90, 90, 0, 10,10, 0.1,0.1)","Draws SRIC volume in XZ view");
-  pMenu->AddButton("ALICE Tree", "((TGeant3*)gMC)->Gdtree(\"ALIC\")","Draws ALICE tree");      
-  pMenu->AddButton("RICH Tree",  "((TGeant3*)gMC)->Gdtree(\"RICH\")","Draws RICH tree");      
-  pMenu->AddButton("Geo test",  "GeoTest()",   "Draw RICH geo as a macro");
-  pMenu->AddButton("Print ref", "PrintGeo()",  "Print RICH chambers default position");
-  pMenu->AddButton("AliRICH::Print", "r->Print();", "Print RICH chambers default position");
-  pMenu->AddButton("Test transform","TestTransform()","Test L2G and G2L methods");
-  pMenu->AddButton("Geo GUI", "new G3GeometryGUI;","Create instance of G4GeometryGUI"); 
-  pMenu->Show();  
-}//void Draw()
-//__________________________________________________________________________________________________
-void GeoTest()
-{
-
-  TBRIK *pAliceBRIK=new TBRIK("aliceBRIK","ALICE mother volume","void",500,500,500);
-  TBRIK *pArmBRIK=new TBRIK("armBRIK","RICH arm1","void",pRICH->GetSizeX(),pRICH->GetSizeY(),pRICH->GetSizeZ());
-   
-   TNode *pAliceNode=new TNode("aliceNode","Mother volume","aliceBRIK");
-   pAliceNode->cd();
-
-// ARM 1 LEFT      
-   TRotation rot1;
-   TVector3  v1(0,pRICH->GetOffset(),0);
-   
-         
-   rot1.RotateX(pRICH->GetYZAngle()*kDegrad);        v1.RotateX(pRICH->GetYZAngle()*kDegrad);
-   rot1.RotateZ(pRICH->GetXYAngle()*kDegrad);        v1.RotateZ(pRICH->GetXYAngle()*kDegrad);
-   rot1.RotateZ(pRICH->GetRotAngle()*kDegrad);       v1.RotateZ(pRICH->GetRotAngle()*kDegrad);
-         
-   TRotMatrix *pArm1RotMatrix=new TRotMatrix("rotArm1","rotArm1",rot1.ThetaX()*kRaddeg, rot1.PhiX()*kRaddeg,
-                                                                 rot1.ThetaY()*kRaddeg, rot1.PhiY()*kRaddeg,
-                                                                 rot1.ThetaZ()*kRaddeg, rot1.PhiZ()*kRaddeg);
-
-   TNode *pArm1Node=new TNode("arm1Node","Left arm","armBRIK",v1.X(),v1.Y(),v1.Z(),"rotArm1");
-   arm1Node->SetLineColor(kRed);
-   
-// ARM 2 LEFT      
-   TRotation rot2;
-   TVector3  v2(0,pRICH->GetOffset(),0);
-   
-         
-   rot2.RotateX( pRICH->YZAngle()*kDegrad);        v2.RotateX(pRICH->GetYZAngle()*kDegrad);
-   rot2.RotateZ(-pRICH->XYAngle()*kDegrad);        v2.RotateZ(-pRICH->GetXYAngle()*kDegrad);
-   rot2.RotateZ( pRICH->RotAngle()*kDegrad);        v2.RotateZ(pRICH->GetRotAngle()*kDegrad);
-         
-   TRotMatrix *pArm2RotMatrix=new TRotMatrix("rotArm2","rotArm2",rot2.ThetaX()*kRaddeg, rot2.PhiX()*kRaddeg,
-                                                                 rot2.ThetaY()*kRaddeg, rot2.PhiY()*kRaddeg,
-                                                                 rot2.ThetaZ()*kRaddeg, rot2.PhiZ()*kRaddeg);
-
-   TNode *pArm2Node=new TNode("arm2Node","Left arm","armBRIK",v2.X(),v2.Y(),v2.Z(),"rotArm2");
-   arm2Node->SetLineColor(kBlue);
-   
-   aliceNode->Draw();
-}//void GeoTest()
-//__________________________________________________________________________________________________
-void PrintGeo(Float_t rotDeg=0)
+void TestResponse()
 {
-  AliRICHParam *p=new AliRICHParam;  
-  Double_t r=p->Offset();
-  Double_t kP=p->AngleXY();
-  Double_t kT=p->AngleYZ();
-  Double_t kRot;
-  
-  if(rotDeg==0)
-    kRot=p->AngleRot();
-  else
-    kRot=rotDeg*deg;
+  TCanvas *pC=new TCanvas("c","Amplification test",900,800);
+  pC->Divide(1,2);
+  pC->cd(1);
+  TF1 *pF1=new TF1("f1",Gain,-70,70,1);  pF1->SetParameters(1,1);pF1->SetParNames("Sector");
+  TF1 *pF2=new TF1("f2",Gain,-70,70,1);  pF2->SetParameters(2,1);pF2->SetParNames("Sector");
+  pF1->Draw();pF2->Draw("same");
+  
+  pC->cd(2);
+  
+  const Int_t nPoints=8;
+  THStack *pStack=new THStack("stack","photons");
+  TLegend *pLeg=new TLegend(0.6,0.2,0.9,0.5,"legend");    
+  TH1F *apH[nPoints];
+  
+  Double_t starty=AliRICHParam::DeadZone()/2;
+  Double_t deltay=AliRICHParam::SectorSizeY()/nPoints;
+  
+  for(int i=0;i<nPoints;i++){
+    apH[i]=new TH1F(Form("h%i",i),"Qdc for Photon;QDC;Counts",500,0,500); apH[i]->SetLineColor(i);
+    pStack->Add(apH[i]);                 
+    pLeg->AddEntry(apH[i],Form("@(0,%5.2f->%5.2f)",starty+i*deltay,starty+i*deltay-AliRICHParam::SectorSizeY()/2));
+  }
         
-  cout<<endl;
-  Double_t  phi=90*deg+kRot+kP,theta=90*deg+kT;
-  Info("   menu for          1","r=%8.3f theta=%5.1f phi=%5.1f x=%8.3f y=%8.3f z=%8.3f",
-                                 r,      theta*r2d,  phi*r2d,  
-                                                               r*sin(theta)*cos(phi),
-                                                                       r*sin(theta)*sin(phi),
-                                                                               r*cos(theta));
-  
-  phi=90*deg+kRot+kP,theta=90*deg;
-  Info("   menu for          2","r=%8.3f theta=%5.1f phi=%5.1f x=%8.3f y=%8.3f z=%8.3f",
-                                 r,      theta*r2d,  phi*r2d,  
-                                                               r*sin(theta)*cos(phi),
-                                                                       r*sin(theta)*sin(phi),
-                                                                               r*cos(theta));
-  
-  phi=90*deg+kRot,theta=90*deg-kT;    
-  Info("   menu for          3","r=%8.3f theta=%5.1f phi=%5.1f x=%8.3f y=%8.3f z=%8.3f",
-                                 r,      theta*r2d,  phi*r2d,  
-                                                               r*sin(theta)*cos(phi),
-                                                                       r*sin(theta)*sin(phi),
-                                                                               r*cos(theta));
-  
-  
-  phi=90*deg+kRot,theta=90*deg;
-  Info("   menu for          4","r=%8.3f theta=%5.1f phi=%5.1f x=%8.3f y=%8.3f z=%8.3f",
-                                 r,      theta*r2d,  phi*r2d,  
-                                                               r*sin(theta)*cos(phi),
-                                                                       r*sin(theta)*sin(phi),
-                                                                               r*cos(theta));
-
   
-  phi=90*deg+kRot,theta=90*deg+kT;
-  Info("   menu for          5","r=%8.3f theta=%5.1f phi=%5.1f x=%8.3f y=%8.3f z=%8.3f",
-                                 r,      theta*r2d,  phi*r2d,  
-                                                                r*sin(theta)*cos(phi),
-                                                                       r*sin(theta)*sin(phi),
-                                                                               r*cos(theta));
-  
-  
-  phi=90*deg+kRot-kP,theta=90*deg;
-  Info("   menu for          6","r=%8.3f theta=%5.1f phi=%5.1f x=%8.3f y=%8.3f z=%8.3f",
-                                 r,      theta*r2d,  phi*r2d,  
-                                                               r*sin(theta)*cos(phi),
-                                                                       r*sin(theta)*sin(phi),
-                                                                               r*cos(theta));
-  
-  phi=90*deg+kRot-kP,theta=90*deg+kT;
-  Info("   menu for          7","r=%8.3f theta=%5.1f phi=%5.1f x=%8.3f y=%8.3f z=%8.3f",
-                                 r,      theta*r2d,  phi*r2d,  
-                                                               r*sin(theta)*cos(phi),
-                                                                       r*sin(theta)*sin(phi),
-                                                                               r*cos(theta));
-
-  delete p;
-}//void PrintGeo()
-
-
-
-void TestMenu()
-{
-  TControlBar *pMenu = new TControlBar("vertical","RICH test");
-  pMenu->AddButton("Test segmentation",  "TestSegmentation()","Test AliRICHParam::L2P() method");
-  pMenu->AddButton("Test transform",     "TestTransform()",   "Test ALiRICHChamber::L2G() and G2L methods");
-  pMenu->AddButton("Test gain",          "TestGain()",        "Test AliRICHParam::Gain() method");
-  pMenu->AddButton("Test MIP charge",    "TestMipCharge()",   "Test AliRICHParam::TotalCharge() method");
-  pMenu->AddButton("Test Sdigits",       "TestSdigits()",     "Create test set of sdigits");
-  pMenu->AddButton("Test Digits Old",    "TestDigitsOld()",      "Create test set of digits");
-  pMenu->Show();  
-}//void Draw()
-
-
-void TestGain()
-{
-  AliRICHParam *pParam=new AliRICHParam;
-  AliRICHResponseV0 *pRes=new AliRICHResponseV0;
-  
-  TLegend *pLegend=new TLegend(0.6,0.3,0.85,0.5);  
-  TH1F *pH0=new TH1F("pH1","Gain",100,0,600); 
-  TH1F *pH10=new TH1F("pH10","Gain",100,0,600);
-  TH1F *pH20=new TH1F("pH20","Gain",100,0,600);
-  TH1F *pH30=new TH1F("pH30","Gain",100,0,600);
-  TH1F *pHold=new TH1F("pHold","Mip Charge",100,0,2000);
-  for(int i=0;i<1000;i++){
-    pH0 ->Fill(pParam->Gain(0));
-    pH10->Fill(pParam->Gain(10));
-    pH20->Fill(pParam->Gain(20));
-    pH30->Fill(pParam->Gain(30));
-    pHold->Fill(pRes->IntPH(30));
+  TVector2 x2(0,0);  
+//  AliRICHParam::ResetWireSag();
+  for(Int_t i=0;i<10000;i++){//events loop
+    for(int j=0;j<nPoints;j++){
+      x2.Set(0,starty-j*deltay);
+      apH[j]->Fill(AliRICHParam::TotQdc(x2,0));
+    }
   }
-  pH0->Draw();
-  pH10->Draw("same");
-  pH20->Draw("same");
-  pH30->Draw("same");
-  pHold->Draw("same");
-  pLegend->AddEntry(pH0,"y=0");  
-  pLegend->AddEntry(pH10,"y=10");pH10->SetLineColor(kRed);
-  pLegend->AddEntry(pH20,"y=20");pH20->SetLineColor(kBlue);
-  pLegend->AddEntry(pH30,"y=30");pH30->SetLineColor(kGreen);
-  pLegend->AddEntry(pHold,"res");pHold->SetLineColor(kMagenta);
-  pLegend->Draw();
-}//void TestGain()
+  pStack->Draw("nostack");
+  pLeg->Draw();
+}//TestResponse()
 //__________________________________________________________________________________________________
-void TestMipCharge()
+void TestSD()
 {
-  AliRICHParam *pParam=new AliRICHParam;
-  AliRICHResponseV0 *pRes=new AliRICHResponseV0;
-  
-  TLegend *pLegend=new TLegend(0.6,0.3,0.85,0.5);  
-  TH1F *pH0= new TH1F("pH1", "Mip Charge",100,0,500); 
-  TH1F *pH10=new TH1F("pH10","Mip Charge",100,0,500);
-  TH1F *pH20=new TH1F("pH20","Mip Charge",100,0,500);
-  TH1F *pH30=new TH1F("pH30","Mip Charge",100,0,500);
-  TH1F *pHold=new TH1F("pHold","Mip Charge",100,0,500);
-  for(int i=0;i<1000;i++){
-    pH0 ->Fill(pParam->TotalCharge(kPiPlus,0.5e-9,0));
-    pH10->Fill(pParam->TotalCharge(kPiPlus,0.5e-9,10));
-    pH20->Fill(pParam->TotalCharge(kPiPlus,0.5e-9,20));
-    pH30->Fill(pParam->TotalCharge(kPiPlus,0.5e-9,30));
-    pHold->Fill(pRes->IntPH(0.5e-9,-30));
-  }
-  pH0->Draw();
-  pH10->Draw("same");
-  pH20->Draw("same");
-  pH30->Draw("same");
-  pHold->Draw("same");
-  pLegend->AddEntry(pH0,"y=0");  
-  pLegend->AddEntry(pH10,"y=10");pH10->SetLineColor(kRed);
-  pLegend->AddEntry(pH20,"y=20");pH20->SetLineColor(kBlue);
-  pLegend->AddEntry(pH30,"y=30");pH30->SetLineColor(kGreen);
-  pLegend->AddEntry(pHold,"res");pHold->SetLineColor(kMagenta);
-  pLegend->Draw();
-}//void TestGain()
+  Info("TestSD","Creating test sdigits.");
+  TVector3 hit(426.55,246.28,17.21);        
+  TVector2 x2=r->C(4)->Glob2Loc(hit);        
+  Int_t iTotQdc=r->P()->TotQdc(x2,624e-9);        
+  Int_t iPadXmin,iPadXmax,iPadYmin,iPadYmax;
+  Int_t padx,pady;
+  Int_t sec=r->P()->Loc2Pad(x2,padx,pady);
+  r->P()->Loc2Area(x2,iPadXmin,iPadYmin,iPadXmax,iPadYmax);
+  Info("TestSD","Initial hit (%7.2f,%7.2f,%7.2f)->(%7.2f,%7.2f)->(%4i,%4i,%4i) gives %i charge",
+                          hit.X(),hit.Y(),hit.Z(),x2.X(),x2.Y(),sec,padx,pady,iTotQdc);
+  
+  cout<<"left-down=("<<iPadXmin<<","<<iPadYmin<<") right-up=("<<iPadXmax<<','<<iPadYmax<<')'<<endl;
+  for(Int_t iPadY=iPadYmin;iPadY<=iPadYmax;iPadY++)
+    for(Int_t iPadX=iPadXmin;iPadX<=iPadXmax;iPadX++)
+       cout<<r->P()->FracQdc(x2,iPadX,iPadY)<<endl;
+  Info("TestSD","Stop.");
+}//void TestSdigits()
 //__________________________________________________________________________________________________
-void TestDigitsOld()
+void TestC()
 {
-  rl->MakeTree("D");r->MakeBranch("D");
+  Info("TestC","Creating test clusters.");
+  rl->MakeTree("R");r->MakeBranch("R");
   
+  AliRICHcluster c;
+  c.AddDigit(new AliRICHdigit(1,20,21,200,1,2,3));
+  c.AddDigit(new AliRICHdigit(1,22,21,250,1,2,3));
+  c.CoG();
   
-  Int_t t[10];
-  Int_t c[10];
-  Int_t d[5];
-  t[0]=100;t[1]=200;t[2]=300;
-  c[0]=10;c[1]=20;c[2]=30;
-  d[0]=0;d[1]=1;d[2]=2;d[3]=3;d[4]=4;
+  r->AddCluster(c);  
   
-  r->AddDigits(0,t,c,d);
-  r->AddDigits(6,t,c,d);
-    
-  rl->TreeD()->Fill();
-  rl->WriteDigits("OVERWRITE");
-  rl->UnloadDigits();
-  r->ResetDigits();
-}//void TestDigits()
+  rl->TreeR()->Fill();
+  rl->WriteRecPoints("OVERWRITE");
+  rl->UnloadRecPoints();
+  r->ResetClusters();
+  
+  Info("TestC","Stop.");
+}//TestC()
 //__________________________________________________________________________________________________
-void TestSdigits()
+void TestSeg()
 {
-  rl->MakeTree("S");r->MakeBranch("S");
-//totally 19 must be trasformd to 6 digits
-  r->AddSdigit(1,40,40,10,40); r->AddSdigit(1,40,40,10,41); r->AddSdigit(1,40,40,10,42); r->AddSdigit(1,40,40,10,43);
-  r->AddSdigit(1,45,45,10,45); r->AddSdigit(1,45,45,10,45); r->AddSdigit(1,45,45,10,45); r->AddSdigit(1,45,45,10,45);
-  
-  r->AddSdigit(1,20,20,10,20);  r->AddSdigit(1,20,20,10,21);
-  r->AddSdigit(1,25,25,10,25);  r->AddSdigit(1,25,25,10,25);
-  
-  r->AddSdigit(1,30,30,10,30); r->AddSdigit(1,30,30,10,31); r->AddSdigit(1,30,30,10,32);
-  r->AddSdigit(1,35,35,10,35); r->AddSdigit(1,35,35,10,35); r->AddSdigit(1,35,35,10,35);
-  
+  AliRICHParam *p=R()->P();
+  Int_t padx,pady,sec;
+  Double_t x,y;
+  Double_t eps=0.0000001;
+  Double_t x1=-0.5*p->PcSizeX()+eps; Double_t x2=-0.5*p->SectorSizeX()-p->DeadZone()-eps; Double_t x3=-0.5*p->SectorSizeX()+eps;
+  Double_t x6= 0.5*p->PcSizeX()-eps; Double_t x5= 0.5*p->SectorSizeX()+p->DeadZone()+eps; Double_t x4= 0.5*p->SectorSizeX()-eps;
+  Double_t y1=-0.5*p->PcSizeY()+eps; Double_t y2=-0.5*p->DeadZone()-eps;
+  Double_t y4= 0.5*p->PcSizeY()-eps; Double_t y3= 0.5*p->DeadZone()+eps;
+  TVector2 v2;
+  
+  AliRICHParam::Print();
+  
+  sec=p->Loc2Pad(TVector2(x= 0,y=y1),padx,pady); v2=p->Pad2Loc(padx,pady); Info(" 73-  1","(%7.2f,%7.2f)->(%5i,%5i,%5i) center=(%7.2f,%7.2f)",x,y,sec,padx,pady,v2.X(),v2.Y());
+  sec=p->Loc2Pad(TVector2(x= 0,y=y2),padx,pady); v2=p->Pad2Loc(padx,pady); Info(" 73- 80","(%7.2f,%7.2f)->(%5i,%5i,%5i) center=(%7.2f,%7.2f)",x,y,sec,padx,pady,v2.X(),v2.Y());
+  sec=p->Loc2Pad(TVector2(x= 0,y= 0),padx,pady); v2=p->Pad2Loc(padx,pady); Info(" dead  ","(%7.2f,%7.2f)->(%5i,%5i,%5i) center=(%7.2f,%7.2f)",x,y,sec,padx,pady,v2.X(),v2.Y());
+  sec=p->Loc2Pad(TVector2(x= 0,y=y3),padx,pady); v2=p->Pad2Loc(padx,pady); Info(" 73- 81","(%7.2f,%7.2f)->(%5i,%5i,%5i) center=(%7.2f,%7.2f)",x,y,sec,padx,pady,v2.X(),v2.Y());
+  sec=p->Loc2Pad(TVector2(x= 0,y=y4),padx,pady); v2=p->Pad2Loc(padx,pady); Info(" 73-160","(%7.2f,%7.2f)->(%5i,%5i,%5i) center=(%7.2f,%7.2f)\n",x,y,sec,padx,pady,v2.X(),v2.Y());
 
-  r->AddSdigit(1,10,10,10,10);
-  
-  
-  rl->TreeS()->Fill();
-  rl->WriteSDigits("OVERWRITE");
-  rl->UnloadSDigits();
-  cout<<endl;r->Sdigits()->Print();
-  r->ResetSDigits();
-}//void TestDigits()
+  sec=p->Loc2Pad(TVector2(x=x1,y=y4),padx,pady); v2=p->Pad2Loc(padx,pady); Info("  1-160","(%7.2f,%7.2f)->(%5i,%5i,%5i) center=(%7.2f,%7.2f)",x,y,sec,padx,pady,v2.X(),v2.Y());
+  sec=p->Loc2Pad(TVector2(x=x2,y=y4),padx,pady); v2=p->Pad2Loc(padx,pady); Info(" 48-160","(%7.2f,%7.2f)->(%5i,%5i,%5i) center=(%7.2f,%7.2f)",x,y,sec,padx,pady,v2.X(),v2.Y());
+  sec=p->Loc2Pad(TVector2(x=x3,y=y4),padx,pady); v2=p->Pad2Loc(padx,pady); Info(" 49-160","(%7.2f,%7.2f)->(%5i,%5i,%5i) center=(%7.2f,%7.2f)",x,y,sec,padx,pady,v2.X(),v2.Y());
+  sec=p->Loc2Pad(TVector2(x=x4,y=y4),padx,pady); v2=p->Pad2Loc(padx,pady); Info(" 96-160","(%7.2f,%7.2f)->(%5i,%5i,%5i) center=(%7.2f,%7.2f)",x,y,sec,padx,pady,v2.X(),v2.Y());
+  sec=p->Loc2Pad(TVector2(x=x5,y=y4),padx,pady); v2=p->Pad2Loc(padx,pady); Info(" 97-160","(%7.2f,%7.2f)->(%5i,%5i,%5i) center=(%7.2f,%7.2f)",x,y,sec,padx,pady,v2.X(),v2.Y());
+  sec=p->Loc2Pad(TVector2(x=x6,y=y4),padx,pady); v2=p->Pad2Loc(padx,pady); Info("144-160","(%7.2f,%7.2f)->(%5i,%5i,%5i) center=(%7.2f,%7.2f)\n",x,y,sec,padx,pady,v2.X(),v2.Y());
+  
+  sec=p->Loc2Pad(TVector2(x=x1,y=y3),padx,pady); v2=p->Pad2Loc(padx,pady); Info("  1- 81","(%7.2f,%7.2f)->(%5i,%5i,%5i) center=(%7.2f,%7.2f)",x,y,sec,padx,pady,v2.X(),v2.Y());
+  sec=p->Loc2Pad(TVector2(x=x2,y=y3),padx,pady); v2=p->Pad2Loc(padx,pady); Info(" 48- 81","(%7.2f,%7.2f)->(%5i,%5i,%5i) center=(%7.2f,%7.2f)",x,y,sec,padx,pady,v2.X(),v2.Y());
+  sec=p->Loc2Pad(TVector2(x=x3,y=y3),padx,pady); v2=p->Pad2Loc(padx,pady); Info(" 49- 81","(%7.2f,%7.2f)->(%5i,%5i,%5i) center=(%7.2f,%7.2f)",x,y,sec,padx,pady,v2.X(),v2.Y());
+  sec=p->Loc2Pad(TVector2(x=x4,y=y3),padx,pady); v2=p->Pad2Loc(padx,pady); Info(" 96- 81","(%7.2f,%7.2f)->(%5i,%5i,%5i) center=(%7.2f,%7.2f)",x,y,sec,padx,pady,v2.X(),v2.Y());
+  sec=p->Loc2Pad(TVector2(x=x5,y=y3),padx,pady); v2=p->Pad2Loc(padx,pady); Info(" 97- 81","(%7.2f,%7.2f)->(%5i,%5i,%5i) center=(%7.2f,%7.2f)",x,y,sec,padx,pady,v2.X(),v2.Y());
+  sec=p->Loc2Pad(TVector2(x=x6,y=y3),padx,pady); v2=p->Pad2Loc(padx,pady); Info("144- 81","(%7.2f,%7.2f)->(%5i,%5i,%5i) center=(%7.2f,%7.2f)\n",x,y,sec,padx,pady,v2.X(),v2.Y());
+  
+  sec=p->Loc2Pad(TVector2(x=x1,y=y2),padx,pady); v2=p->Pad2Loc(padx,pady); Info("  1- 80","(%7.2f,%7.2f)->(%5i,%5i,%5i) center=(%7.2f,%7.2f)",x,y,sec,padx,pady,v2.X(),v2.Y());
+  sec=p->Loc2Pad(TVector2(x=x2,y=y2),padx,pady); v2=p->Pad2Loc(padx,pady); Info(" 48- 80","(%7.2f,%7.2f)->(%5i,%5i,%5i) center=(%7.2f,%7.2f)",x,y,sec,padx,pady,v2.X(),v2.Y());
+  sec=p->Loc2Pad(TVector2(x=x3,y=y2),padx,pady); v2=p->Pad2Loc(padx,pady); Info(" 49- 80","(%7.2f,%7.2f)->(%5i,%5i,%5i) center=(%7.2f,%7.2f)",x,y,sec,padx,pady,v2.X(),v2.Y());
+  sec=p->Loc2Pad(TVector2(x=x4,y=y2),padx,pady); v2=p->Pad2Loc(padx,pady); Info(" 96- 80","(%7.2f,%7.2f)->(%5i,%5i,%5i) center=(%7.2f,%7.2f)",x,y,sec,padx,pady,v2.X(),v2.Y());
+  sec=p->Loc2Pad(TVector2(x=x5,y=y2),padx,pady); v2=p->Pad2Loc(padx,pady); Info(" 97- 80","(%7.2f,%7.2f)->(%5i,%5i,%5i) center=(%7.2f,%7.2f)",x,y,sec,padx,pady,v2.X(),v2.Y());
+  sec=p->Loc2Pad(TVector2(x=x6,y=y2),padx,pady); v2=p->Pad2Loc(padx,pady); Info("144- 80","(%7.2f,%7.2f)->(%5i,%5i,%5i) center=(%7.2f,%7.2f)\n",x,y,sec,padx,pady,v2.X(),v2.Y());
+  
+  sec=p->Loc2Pad(TVector2(x=x1,y=y1),padx,pady); v2=p->Pad2Loc(padx,pady); Info("  1-  1","(%7.2f,%7.2f)->(%5i,%5i,%5i) center=(%7.2f,%7.2f)",x,y,sec,padx,pady,v2.X(),v2.Y());
+  sec=p->Loc2Pad(TVector2(x=x2,y=y1),padx,pady); v2=p->Pad2Loc(padx,pady); Info(" 48-  1","(%7.2f,%7.2f)->(%5i,%5i,%5i) center=(%7.2f,%7.2f)",x,y,sec,padx,pady,v2.X(),v2.Y());
+  sec=p->Loc2Pad(TVector2(x=x3,y=y1),padx,pady); v2=p->Pad2Loc(padx,pady); Info(" 49-  1","(%7.2f,%7.2f)->(%5i,%5i,%5i) center=(%7.2f,%7.2f)",x,y,sec,padx,pady,v2.X(),v2.Y());
+  sec=p->Loc2Pad(TVector2(x=x4,y=y1),padx,pady); v2=p->Pad2Loc(padx,pady); Info(" 96-  1","(%7.2f,%7.2f)->(%5i,%5i,%5i) center=(%7.2f,%7.2f)",x,y,sec,padx,pady,v2.X(),v2.Y());
+  sec=p->Loc2Pad(TVector2(x=x5,y=y1),padx,pady); v2=p->Pad2Loc(padx,pady); Info(" 97-  1","(%7.2f,%7.2f)->(%5i,%5i,%5i) center=(%7.2f,%7.2f)",x,y,sec,padx,pady,v2.X(),v2.Y());
+  sec=p->Loc2Pad(TVector2(x=x6,y=y1),padx,pady); v2=p->Pad2Loc(padx,pady); Info("144-  1","(%7.2f,%7.2f)->(%5i,%5i,%5i) center=(%7.2f,%7.2f)\n",x,y,sec,padx,pady,v2.X(),v2.Y());
+   
+  new TCanvas("name","title");
+  gPad->Range(-80,-80,80,80);
+  AliRICHDisplFast::DrawSectors();
+  AliRICHParam *p=new AliRICHParam;
+  
+  Double_t eps=0.0001;
+  Double_t x1=-0.5*p->PcSizeX()+eps; Double_t x2=-0.5*p->SectorSizeX()-p->DeadZone()-eps; Double_t x3=-0.5*p->SectorSizeX()+eps;
+  Double_t x6= 0.5*p->PcSizeX()-eps; Double_t x5= 0.5*p->SectorSizeX()+p->DeadZone()+eps; Double_t x4= 0.5*p->SectorSizeX()-eps;
+  Double_t y1=-0.5*p->PcSizeY()+eps; Double_t y2=-0.5*p->DeadZone()-eps;
+  Double_t y4= 0.5*p->PcSizeY()-eps; Double_t y3= 0.5*p->DeadZone()+eps;
+  
+  TLatex t; t.SetTextSize(0.02);
+  
+  TVector2 v2;
+  v2=AliRICHParam::Pad2Loc( 1,140); t.DrawLatex(v2.X(),v2.Y(),"Sector 1");  
+  v2=AliRICHParam::Pad2Loc(49,140); t.DrawLatex(v2.X(),v2.Y(),"Sector 2");  
+  v2=AliRICHParam::Pad2Loc(97,140); t.DrawLatex(v2.X(),v2.Y(),"Sector 3");  
+  v2=AliRICHParam::Pad2Loc( 1, 60); t.DrawLatex(v2.X(),v2.Y(),"Sector 4");  
+  v2=AliRICHParam::Pad2Loc(49, 60); t.DrawLatex(v2.X(),v2.Y(),"Sector 5");  
+  v2=AliRICHParam::Pad2Loc(97, 60); t.DrawLatex(v2.X(),v2.Y(),"Sector 6");  
+  
+  t.SetTextColor(kRed);
+  t.DrawLatex(-63.08,-70,"-63.08"); t.DrawLatex(-28.00,-70,"-22.76"); t.DrawLatex(-20.16,-70,"-20.16"); //x position        
+  t.DrawLatex( 58.00,-70," 63.08"); t.DrawLatex( 22.76,-70," 22.76"); t.DrawLatex( 15.00,-70," 20.16");       
+  t.DrawLatex(-70,-64,"-65.30"); t.DrawLatex(-70,-5,"-1.30"); //y position 
+  t.DrawLatex(-70, 63," 65.30"); t.DrawLatex(-70, 2," 1.30");        
+  
+  t.SetTextColor(kBlue);  
+  t.DrawLatex(-63.08,-75,"1");  t.DrawLatex(-25.00,-75,"48");  t.DrawLatex(-20.00,-75,"49");       //x pads
+  t.DrawLatex( 18.00,-75,"96"); t.DrawLatex( 23.00,-75,"97");  t.DrawLatex( 60.00,-75,"144");
+  t.DrawLatex(-75,-64,"1");   t.DrawLatex(-75,-5,"80"); //y pads
+  t.DrawLatex(-75, 63,"160"); t.DrawLatex(-75, 2,"81");        
+}//void TestSeg()
 //__________________________________________________________________________________________________
-void TestSegmentation()
+void TestMenu()
 {
-  AliRICHParam *p=r->Param(); 
-  Float_t dz=p->DeadZone();
-  Float_t sx=p->SectorSizeX();Float_t sy=p->SectorSizeY();
-  Float_t px=p->PcSizeX();    Float_t py=p->PcSizeY();
-  Int_t padx,pady;
-  cout<<endl;
-  Info("  1-  1","sec=%i padx=%3i pady=%3i",p->L2P(-px/2    , -py/2        ,padx,pady),padx,pady);
-  Info(" 48-  1","sec=%i padx=%3i pady=%3i",p->L2P(-sx/2-dz , -py/2        ,padx,pady),padx,pady);
-  Info(" 49-  1","sec=%i padx=%3i pady=%3i",p->L2P(-sx/2    , -py/2        ,padx,pady),padx,pady);
-  Info(" 96-  1","sec=%i padx=%3i pady=%3i",p->L2P( sx/2    , -py/2        ,padx,pady),padx,pady);
-  Info(" 97-  1","sec=%i padx=%3i pady=%3i",p->L2P( sx/2+dz , -py/2        ,padx,pady),padx,pady);
-  Info("144-  1","sec=%i padx=%3i pady=%3i",p->L2P( px/2    , -py/2        ,padx,pady),padx,pady);
-  cout<<endl;
-  Info("  1- 80","sec=%i padx=%3i pady=%3i",p->L2P(-px/2    , -dz/2        ,padx,pady),padx,pady);
-  Info(" 48- 80","sec=%i padx=%3i pady=%3i",p->L2P(-sx/2-dz , -dz/2        ,padx,pady),padx,pady);
-  Info(" 49- 80","sec=%i padx=%3i pady=%3i",p->L2P(-sx/2    , -dz/2        ,padx,pady),padx,pady);
-  Info(" 96- 80","sec=%i padx=%3i pady=%3i",p->L2P( sx/2    , -dz/2        ,padx,pady),padx,pady);
-  Info(" 97- 80","sec=%i padx=%3i pady=%3i",p->L2P( sx/2+dz , -dz/2        ,padx,pady),padx,pady);
-  Info("144- 80","sec=%i padx=%3i pady=%3i",p->L2P( px/2    , -dz/2        ,padx,pady),padx,pady);
-  cout<<endl;
-  Info("  1- 81","sec=%i padx=%3i pady=%3i",p->L2P(-px/2    ,  dz/2        ,padx,pady),padx,pady);
-  Info(" 48- 81","sec=%i padx=%3i pady=%3i",p->L2P(-sx/2-dz ,  dz/2        ,padx,pady),padx,pady);
-  Info(" 49- 81","sec=%i padx=%3i pady=%3i",p->L2P(-sx/2    ,  dz/2        ,padx,pady),padx,pady);
-  Info(" 96- 81","sec=%i padx=%3i pady=%3i",p->L2P( sx/2    ,  dz/2        ,padx,pady),padx,pady);
-  Info(" 97- 81","sec=%i padx=%3i pady=%3i",p->L2P( sx/2+dz ,  dz/2        ,padx,pady),padx,pady);
-  Info("144- 81","sec=%i padx=%3i pady=%3i",p->L2P( px/2    ,  dz/2        ,padx,pady),padx,pady);
-  cout<<endl;
-  Info("  1-160","sec=%i padx=%3i pady=%3i",p->L2P(-px/2    ,  py/2        ,padx,pady),padx,pady);
-  Info(" 48-160","sec=%i padx=%3i pady=%3i",p->L2P(-sx/2-dz ,  py/2        ,padx,pady),padx,pady);
-  Info(" 49-160","sec=%i padx=%3i pady=%3i",p->L2P(-sx/2    ,  py/2        ,padx,pady),padx,pady);
-  Info(" 96-160","sec=%i padx=%3i pady=%3i",p->L2P( sx/2    ,  py/2        ,padx,pady),padx,pady);
-  Info(" 97-160","sec=%i padx=%3i pady=%3i",p->L2P( sx/2+dz ,  py/2        ,padx,pady),padx,pady);
-  Info("144-160","sec=%i padx=%3i pady=%3i",p->L2P( px/2    ,  py/2        ,padx,pady),padx,pady);  
-  cout<<endl;
-  Info(" 73-160","sec=%i padx=%3i pady=%3i",p->L2P(    0    ,  py/2      ,padx,pady),padx,pady);    
-  Info(" 73- 81","sec=%i padx=%3i pady=%3i",p->L2P(    0    ,  dz/2      ,padx,pady),padx,pady);    
-  Info(" 73- 80","sec=%i padx=%3i pady=%3i",p->L2P(    0    ,   0        ,padx,pady),padx,pady);    
-  Info("144- 81","sec=%i padx=%3i pady=%3i",p->L2P(    0    , -dz/2      ,padx,pady),padx,pady);    
-  Info("144- 81","sec=%i padx=%3i pady=%3i",p->L2P(    0    , -py/2      ,padx,pady),padx,pady);    
-}//void TestSegmentation()
+  TControlBar *pMenu = new TControlBar("vertical","RICH test");
+  pMenu->AddButton("Test segmentation",  "TestSeg()",         "Test AliRICHParam segmentation methods");
+  pMenu->AddButton("Test response",      "TestResponse()",    "Test AliRICHParam response methods");
+  pMenu->AddButton("Test sdigits",       "TestSD()",          "Create test set of sdigits");
+  pMenu->AddButton("Test clusters",      "TestC()",           "Create test set of clusters");
+  pMenu->AddButton("Test digits OLD",    "TestDigitsOLD()",   "Create test set of OLD digits");
+  pMenu->Show();  
+}//TestMenu()
 //__________________________________________________________________________________________________
-void TestClusters()
+void menu()
+{ 
+  TControlBar *pMenu = new TControlBar("vertical","RICH main");
+       
+  if(ReadAlice()){//it's from file, reconstruct
+    pMenu->AddButton("hits->sdigits->digits->clusters","MainTrank()","Convert");
+    
+    pMenu->AddButton("sdigits->digits"  ,"SD_D()" ,"AliRICHDigitizer");
+    pMenu->AddButton("digits->resolved clusters" ,"cf=new AliRICHClusterFinder(r);cf->Exec();delete cf;","AliRICHClusterFinder");
+    pMenu->AddButton("digits->raw clusters" ,     "AliRICHParam::SetDeclustering(kFALSE);cf=new AliRICHClusterFinder(r);cf->Exec();delete cf;","AliRICHClusterFinder");
+    pMenu->AddButton("clusters->recos"  ,"C_R()"  ,"AliRICHRecon");
+
+    pMenu->AddButton("Show",            "Show()","Shows the structure of events in files");
+    pMenu->AddButton("Display Fast",    "DisplFast()",           "Display Fast");
+    pMenu->AddButton("Control Plots",   "ControlPlots()",        "Display some control histograms");
+    
+  }else{//it's aliroot, simulate
+    pMenu->AddButton("Run",         "a->Run(1)",       "Process!");
+    pMenu->AddButton("Geo GUI", "new G3GeometryGUI;","Create instance of G4GeometryGUI"); 
+    pMenu->AddButton("Read RAW","ReadRaw()","Read a list of digits from test beam file"); 
+  }
+  pMenu->AddButton("Test submenu",    "TestMenu()",            "Shows test submenu");
+  pMenu->AddButton("Browser",         "new TBrowser;",         "Start ROOT TBrowser");
+  pMenu->AddButton("Debug ON",     "DebugON();",   "Switch debug on-off");   
+  pMenu->AddButton("Debug OFF",    "DebugOFF();",   "Switch debug on-off");   
+  pMenu->AddButton("Quit",            ".q",                    "Close session");
+  pMenu->Show();
+  a=gAlice;//for manual manipulation convinience
+}//menu()
+//__________________________________________________________________________________________________
+void DebugOFF(){  Info("DebugOFF","");  a->SetDebug(0);  r->SetDebug(0);  AliLoader::SetDebug(0);}
+void DebugON() {  Info("DebugON","");   a->SetDebug(1);  r->SetDebug(1);  AliLoader::SetDebug(1);}
+
+void ReadRaw()
 {
-  rl->MakeTree("R");r->MakeBranch("R");
-  r->AddCluster  
-  rl->TreeR()->Fill();
-  rl->WriteRecPoints("OVERWRITE");
-  rl->UnloadRecPoints();
-  r->ResetClusters();
-}//void TestClusters()
+  char *sRawFileName="beam/run1822_4sigma.dat";
+  FILE *pRawFile=fopen(sRawFileName,"r");
+  if(!pRawFile){Error("ReadRaw","Something wrong with raw data file %s",sRawFileName); return;}
+  
+  Int_t iNpads=0,q=0,x=0,y=0;
+  
+  while(fscanf(pRawFile,"%i",&iNpads)){
+    Info("ReadRaw","%i pads fired",iNpads);
+    for(Int_t i=0;i<iNpads;i++)
+      fscanf(pRawFile,"%i %i %i",&q,&x,&y);
+  }
+  fclose(pRawFile);
+}