clean up warnings
[u/mrichter/AliRoot.git] / FMD / AliFMDReconstruction.cxx
index 49480abbf4dd816382798580f2546bc5760a5541..e34b88758636082882cd0d6e0d06e717844d7cea 100644 (file)
 #include "TFile.h"
 #include "TROOT.h"
 #include "TFolder.h"
-#include <Riostream.h>
+#include "TH2F.h"
 
 // --- Standard library ---
 #include <stdlib.h>
+#include <Riostream.h>
 
 // --- AliRoot header files ---
 
+#include "AliRunLoader.h"
+#include "AliLoader.h"
+
 #include "AliFMDdigit.h"
+#include "AliFMDhit.h"
 #include "AliFMDReconstParticles.h"
 #include "AliFMD.h"
 #include "AliFMDv1.h"
 #include "AliFMDReconstruction.h"
 #include "AliRun.h"
+#include "AliConfig.h"
+#include "AliHeader.h"
+#include "AliGenEventHeader.h"
+
 ClassImp(AliFMDReconstruction)
 
         
@@ -48,20 +57,31 @@ ClassImp(AliFMDReconstruction)
 AliFMDReconstruction::AliFMDReconstruction():TTask("AliFMDReconstruction","") 
 {
   fNevents = 0 ;  // Number of events to rreconnstraction, 0 means all events in current file
-  // add Task to //root/Tasks folder
-  TTask * roottasks = (TTask*)gROOT->GetRootFolder()->FindObject("Tasks") ; 
-  roottasks->Add(this) ; 
+  fRunLoader = 0x0;
+  
 }
 //____________________________________________________________________________ 
 
-AliFMDReconstruction::AliFMDReconstruction(char* HeaderFile, char *ReconstParticlesFile):TTask("AliFMDReconstruction","")
+AliFMDReconstruction::AliFMDReconstruction(AliRunLoader* rl):TTask("AliFMDReconstruction","")
 {
+
+  if (rl == 0x0)
+   {
+     Fatal("AliFMDReconstruction","Argument AliRunLoader* is null!");
+     return;
+   }
+   
   fNevents = 0 ;    // Number of events to rreconnstraction, 0 means all events in current file
-  fReconstParticlesFile=ReconstParticlesFile ;
-  fHeadersFile=HeaderFile ;
+
+  fRunLoader = rl;
+  AliLoader* gime = fRunLoader->GetLoader("FMDLoader");
+  if (gime == 0x0)
+   {
+     Fatal("AliFMDReconstruction","Can not find FMD (loader) in specified event");
+     return;//never reached
+   }
   //add Task to //root/Tasks folder
-  TTask * roottasks = (TTask*)gROOT->GetRootFolder()->FindObject("Tasks") ; 
-  roottasks->Add(this) ;     
+  gime->PostReconstructioner(this);
 }
 
 //____________________________________________________________________________ 
@@ -69,255 +89,214 @@ AliFMDReconstruction::AliFMDReconstruction(char* HeaderFile, char *ReconstPartic
 AliFMDReconstruction::~AliFMDReconstruction()
 {
 }
-//----------------------------------------------------------------------------
 
-void AliFMDReconstruction::Exec(Option_t *option) 
+//____________________________________________________________________________
+
+void AliFMDReconstruction::Exec() 
 { 
-  printf (" AliFMDReconstruction starting \n");
  //Collects all digits in the same active volume into number of particles
-  
-  Int_t const NumVolums=5;
-  Int_t const NumSectors=40;
-  Int_t const NumRings=768;
-  Int_t PadADC[10][50][800];
+  /*
+    Reconstruct number of particles 
+    in given group of pads for given FMDvolume
+    determine by numberOfVolume , 
+    numberOfMinSector,numberOfMaxSector,
+    numberOfMinRing, numberOgMaxRing
+    Reconstruction method choose dependence on number of empty pads  
+  */
+
+
+  cout<<"\nStart AliFMDReconstruction::Exec(...)"<<endl;
+  Int_t const knumVolumes=5;
+  Int_t padADC;
+  Float_t eta, etain,etaout,rad,theta;
   Int_t ivol, iSector, iRing;
-  Int_t Ne1; 
-  //Int_t NumberOfRings[5]=  {256,128,256,128,256};
-  Int_t NumberOfSectors[5]=  {20,40,20,40,20};
+  Float_t rin[5]={4.2,15.4,4.2,15.4,4.2};
+  Float_t rout[5]={17.4,28.4,17.4,28.4,17.4};
+  Float_t z[5]={-62.8, -75.2, 83.4, 75.2, 340.};
+  Int_t numberOfRings[5]={512,256,512,256,512};
+  Int_t numberOfSectors[5]=  {20,40,20,40,20};
+  Int_t numberOfEtaIntervals[5];
   // number of ring for boundary 0.1 eta
-   Int_t EtaIntervalInner []=
-      {0, 55, 110, 165, 221, 276, 331, 386, 442,
-       497, 552, 607, 663, 718, 767 };
-   /*
-     {0,  18, 36,   55,  73,
-      92, 110, 128, 147, 165,
-      184, 202, 221, 239, 255};*/
-   Int_t  EtaIntervalOuter []=  //{0, 21, 43, 65, 86, 108, 127};
-     {0, 65, 130, 195, 260, 325, 383};
- Int_t EtaInterval[20];
-  
 
-  Int_t size_EtaIntervalInner=sizeof (EtaIntervalInner)/sizeof(EtaIntervalInner[0]);
+  
+  if (fRunLoader == 0x0)
+   {
+    Error("Exec","Run Loader loader is NULL - Session not opened");
+    return;
+   }
+ AliLoader* gime = fRunLoader->GetLoader("FMDLoader");
+  if (gime == 0x0)
+   {
+     Fatal("AliFMDReconstruction","Can not find FMD (loader) in specified event");
+     return;//never reached
+   }
+   
+  fRunLoader->LoadgAlice();
+  fRunLoader->LoadHeader();
+  Int_t retval;
+  TDirectory* cwd = gDirectory;
+  gDirectory = 0x0;
+    Text_t buf1[20];
+  TH2F* hTotal[10];
+  for (Int_t j=1; j<=5; j++){
+    sprintf(buf1,"hTotal%d",j);
+    
+    hTotal[j] = new TH2F(buf1," Number of primary particles ",
+                        numberOfSectors[j-1],1,numberOfSectors[j-1],
+                        numberOfRings[j-1],1,numberOfRings[j-1]);
+  }   
+  gDirectory = cwd;
+       
+  if(fNevents == 0) fNevents=Int_t (fRunLoader->TreeE()->GetEntries()); 
+  cout<<" fNevents "<<fNevents<<endl;
+   for(Int_t ievent=0;ievent<fNevents;ievent++)
+    { 
+      fRunLoader->GetEvent(ievent) ;
 
-  Int_t size_EtaIntervalOuter=sizeof (EtaIntervalOuter)/sizeof(EtaIntervalOuter[0]);
+      cout<<" ievent "<<ievent<<endl;
+    for (Int_t i=0; i<5; i++)
+        hTotal[i+1]->Reset();
+      
+      retval = gime->LoadDigits("READ"); 
+      if (retval)
+       {
+         Error("Exec","Error occured while loading digits. Exiting.");
+         return;
+       }
+      
+      AliFMD * fFMD = (AliFMD *) gAlice->GetDetector("FMD");
+      TClonesArray *fReconParticles=fFMD->ReconParticles();
+      TClonesArray *fDigits=fFMD->Digits();
+      TTree* treeD = gime->TreeD();
+      if (treeD == 0x0)
+       {
+         Error("Exec","Can not get Tree with Digits. Nothing to reconstruct - Exiting");
+         return;
+       }
+      
+      TBranch *brDigits=0;
+           
+      brDigits=treeD->GetBranch("FMD");
+      cout<<" brDigits "<<brDigits<<endl;
+      if (brDigits) {
+       brDigits->SetAddress(&fDigits);
+       //        fFMD->SetHitsAddressBranch(brHits);
+      }else{
+       cerr<<"EXEC Branch FMD digits not found"<<endl;
+       return;
+      } 
+         
+      if(gime->TreeR()==0) gime->MakeTree("R");
 
-  AliFMD * FMD = (AliFMD *) gAlice->GetDetector("FMD");  
-  TClonesArray *fReconParticles=FMD->ReconParticles();
-  if(fNevents == 0) fNevents=(Int_t)gAlice->TreeE()->GetEntries(); 
-  for(Int_t ievent=0;ievent<fNevents;ievent++)
-    { 
-      for (Int_t i=0; i<NumVolums; i++)
-       for(Int_t j=0; j<NumSectors; j++)
-         for(Int_t ij=0; ij<NumRings; ij++)
-           PadADC[i][j][ij]=0;                    //zhachem ???
-      gAlice->GetEvent(ievent) ;
-      if(gAlice->TreeH()==0) return; 
-      if(gAlice->TreeR()==0) gAlice->MakeTree("R");
       //Make branches
-      AliFMDdigit  *fmdDigit;
-      FMD->MakeBranch("R");
-      
-      Int_t zeroADC=1;
-      // Int_t  threshold_array_size=30;
+      fFMD->MakeBranch("R");
 
-      // cout<<" AliFMDdigit "<<AliFMDdigit<<endl;
-      if (FMD)
+      
+      Int_t zeroADC=6;
+      AliFMDdigit  *fmdDigit;
+       if (fFMD)
        {
-         gAlice->TreeD()->GetEvent(0); 
-         TClonesArray *FMDdigits=FMD->Digits();
-         Int_t nDigits=FMDdigits->GetEntries();
-          Int_t RecParticles[6];
-          Int_t nRecPart=0 ;
-          Int_t ZeroPads=0;
-          Int_t NumberOfPads=0; //To avoid warning
+         gime->TreeD()->GetEvent(0); 
+                 
+         Int_t nDigits=fDigits->GetEntries();
+         cout<<" nDigits "<<nDigits<<endl;
+         Int_t recParticles[6];
+         Int_t nRecPart=0 ;
+          Int_t zeroPads=0;
+          Int_t numberOfPads=0; //To avoid warning
           Int_t pedestal;
           Float_t channelWidth=(22400*50)/1024;
           for (Int_t digit=0;digit<nDigits;digit++) 
             {
-              fmdDigit=(AliFMDdigit*)FMDdigits->UncheckedAt(digit);    
+              fmdDigit=(AliFMDdigit*)fDigits->UncheckedAt(digit);    
               ivol=fmdDigit->Volume();
               iSector=fmdDigit->NumberOfSector();
               iRing=fmdDigit->NumberOfRing();
               pedestal=Int_t(gRandom->Gaus(500,250));
-              PadADC[ivol-1][iSector-1][iRing-1]=
-                fmdDigit->ADCsignal()
+              padADC= fmdDigit->ADCsignal()
                 -Int_t(Float_t(pedestal)/channelWidth);
-              if (PadADC[ivol-1][iSector-1][iRing-1]<0) 
-                PadADC[ivol-1][iSector-1][iRing-1]=0;
-            } //digit loop
-          Int_t Rmin=0; Int_t Rmax=0; //To avoid warning
-          Int_t Smin=0; Int_t Smax=0; //To avoid warning
-                  
-          for (ivol=1; ivol<=NumVolums; ivol++)
+              if (padADC<0) padADC=0;
+              hTotal[ivol]->Fill(iSector,iRing,padADC);
+            } //digit loop
+          Int_t rmin=0; Int_t rmax=0; //To avoid warning
+          Int_t smin=0; Int_t smax=0; //To avoid warning
+          AliHeader *header = fRunLoader->GetHeader();
+          AliGenEventHeader* genHeader = header->GenEventHeader();
+          TArrayF *o = new TArrayF(3); 
+          genHeader->PrimaryVertex(*o);
+          Float_t zVertex=o->At(2);
+          for (ivol=0; ivol<knumVolumes; ivol++)
             {
-              if (ivol==1||ivol==3||ivol==5)
-                {
-                  Ne1=size_EtaIntervalInner;
-                  for(Int_t ieta=0; ieta<Ne1; ieta++)
-                    EtaInterval[ieta]=EtaIntervalInner[ieta];
-                }
-              if (ivol==2||ivol==4)
-                {
-                  Ne1=size_EtaIntervalOuter;
-                  for( Int_t ieta=0; ieta<Ne1; ieta++)
-                    EtaInterval[ieta]=EtaIntervalOuter[ieta];
-                }
-
-
-                  for (Int_t e1=0;e1<Ne1-1;e1++) // vol<=NumVolums
-                    {
-                      Rmin=EtaInterval[e1];
-                  Rmax=EtaInterval[e1+1];
-                  ZeroPads=0;
-                  Smin=0;
-                  Smax=NumberOfSectors[ivol-1]; 
-                  for (Int_t iring=Rmin; iring<Rmax; iring++) 
-                    {
-                      NumberOfPads=(Rmax-Rmin)*(Smax-Smin);
-                      for 
-                        (Int_t isector=1;
-                         isector<=NumberOfSectors[ivol-1]; 
-                         isector++) 
-                        if(PadADC[ivol-1][isector-1][iring-1]<zeroADC)
-                          ZeroPads++;
-                    } //ring
-                  /*
-                  cout<<"\nRmin="<<Rmin;
-                  cout<<"\nRmax="<<Rmax;
-                  cout<<"\nSmin="<<Smin;
-                  cout<<"\nSmax="<<Smax;
-              
-                  cout<<"\nvolume "<<ivol<<" zero "<<ZeroPads<<
-                    " NumberOfPads "<<NumberOfPads<<endl;
-                  */
-                  Float_t zerosRatio= 
-                    (Float_t)ZeroPads/(Float_t)NumberOfPads;
-                  //  cout<<"\nzerosRatio="<<zerosRatio;                     
-                  RecParticles[0]=ivol;
-                  RecParticles[1]=Smin;
-                  RecParticles[2]=Smax;
-                  RecParticles[3]=Rmin;
-                  RecParticles[4]=Rmax;
-                  if (zerosRatio>0.1 ||(ivol==2||ivol==4))
-                    RecParticles[5]=
-                      Determination_by_Poisson
-                      (PadADC,ivol,Rmin,Rmax,Smin,Smax);
-                  else
-                    RecParticles[5]=
-                      Determination_by_thresholds
-                      (PadADC,ivol,Rmin,Rmax,Smin,Smax);
-                  //  cout<<" nDeterm "<<RecParticles[5]<<endl;
-                  new((*fReconParticles)[nRecPart++]) 
-                AliFMDReconstParticles(RecParticles);                 
-       } // eta
-    } // volume
+               Float_t ring2number=Float_t (numberOfRings[ivol])/
+                 (rout[ivol]-rin[ivol]);
+               Float_t realZ=zVertex+z[ivol];
+               theta=TMath::ATan(rout[ivol]/TMath::Abs(realZ));
+               etain = - TMath::Log( TMath::Tan(theta/2.));
+               theta=TMath::ATan(rin[ivol]/TMath::Abs(realZ));
+               etaout=- TMath::Log( TMath::Tan(theta/2.));
+               numberOfEtaIntervals[ivol]=Int_t((etaout-etain)*10)-1;
+               eta=etain;
+               for (Int_t e1=0;e1<=numberOfEtaIntervals[ivol];e1++) 
+                 {
+                   theta = 2.*TMath::ATan (TMath::Exp (-eta));
+                   Float_t radmin = TMath::Abs(realZ) * (TMath::Tan (theta));
+                   rmax= Int_t ( (radmin-rin[ivol])*ring2number+0.5);
+                   cout<<ivol<<" "<<" eta "<<eta<<" radmin "<<radmin<<
+
+                     " Rmax "<<rmax<<" "<<endl;;
+                   eta=eta+0.1;
+                   theta = 2.*TMath::ATan (TMath::Exp (-eta));
+                   rad = TMath::Abs(realZ) * (TMath::Tan (theta));
+                   rmin=Int_t( (rad-rin[ivol])*ring2number+0.5);
+                   cout<<"eta "<<eta<<" rad "<<rad<<" Rmin "<<rmin<<endl;
+                   //      if(ivol==2&&e1==13) rmin=0;
+                   zeroPads=0;
+                   smin=0;
+                   smax=numberOfSectors[ivol]; 
+                   numberOfPads=(rmax-rmin)*(smax-smin);
+                   for (Int_t iring=rmin; iring<rmax; iring++) 
+                     {
+                       for 
+                         (Int_t isector=0;
+                          isector<numberOfSectors[ivol]; 
+                          isector++) 
+                         {
+                          if(hTotal[ivol+1]->GetBinContent(isector+1,iring+1)
+                            <zeroADC) zeroPads++;}
+
+                     } //ring
+                   Float_t numberOfPads=Float_t(smax-smin)*Float_t(rmax-rmin);
+
+                   cout<<" zero "<<zeroPads++<<" pads "<<numberOfPads;
+                   Double_t lambda=-TMath::Log(Double_t(zeroPads)/numberOfPads);
+                   Int_t fRecon=Int_t (lambda*numberOfPads+0.5);
+                   
+                   Float_t zerosRatio= 
+                     (Float_t)zeroPads/(Float_t)numberOfPads;
+                   cout<<" zerosRatio "<<zerosRatio<<" recon "<<fRecon<<endl;
+                   recParticles[0]=ivol+1;
+                   recParticles[1]=smin;
+                   recParticles[2]=smax;
+                   recParticles[3]=rmin;
+                   recParticles[4]=rmax;
+                   recParticles[5]= fRecon;
+                   new((*fReconParticles)[nRecPart++]) 
+                     AliFMDReconstParticles(recParticles);             
+
+
+                } // eta
+            } // volume
           
-          // if(zerosRatio<0.01) Determination_by_counting (ZeroPads) ;           
        }//if FMD
-      gAlice->TreeR()->Reset();
-      gAlice->TreeR()->Fill(); 
-      gAlice->TreeR()->Write(0,TObject::kOverwrite);
+       gime->TreeR()->Reset();
+       gime->TreeR()->Fill(); 
+       gime->WriteRecPoints("OVERWRITE");
     } //event loop
-  // cout<<"\nAliFMDReconstruction::Exec finished"<<endl;
-};
-
-//------------------------------------------------------------
-Int_t AliFMDReconstruction::Determination_by_thresholds
-(Int_t PadADC[][50][800],Int_t volume, Int_t Rmin, Int_t Rmax, 
- Int_t Smin, Int_t Smax)
-{
-  
-  Int_t thresholdInner[30]={
-    0,     14,  28,    42,   57,     
-    72,    89,  104,  124,  129, 
-    164,  174,  179,  208,  228, 
-    248,  268,   317,  337,  357, 
-    392,  407,  416,  426,  436, 
-    461,  468,  493,  506,  515}; 
-
-  Int_t thresholdOuter[30]={0, 18, 48, 77, 105,
-                           132, 165, 198, 231, 
-                           264, 286, 308, 334, 
-                           352, 374, 418, 440,
-                           462, 484, 506, 528,
-                           550, 572, 594, 616}; 
-  Int_t threshold[30];
-  for (Int_t it=0; it<30; it++) {
-    if(volume==1||volume==3||volume==5) threshold[it]=thresholdInner[it];
-    if(volume==2||volume==4) threshold[it]=thresholdOuter[it];
-  }
-  Int_t threshold_array_size = 30;     
-  Int_t NumPart=0;
-  //Inner Si
-  for (Int_t iring=Rmin; iring<Rmax; iring++) 
-    {
-      for (Int_t isector=Smin; isector<Smax; isector++) 
-       {
-         for (int i=0;i<threshold_array_size-1;i++)
-           {         
-             if(PadADC[volume-1][isector][iring]>threshold[i]
-                &&PadADC[volume-1][isector][iring]<=threshold[i+1])
-               {
-                 NumPart+=i;
-                 break;
-               }; // if in threshol interval
-           }; //threshold_array_size
-       }; //iring
-    }; //sector
-  // cout<<"\nEnd threshol method"<<endl;
-  return NumPart;
+  cout<<"\nAliFMDReconstruction::Exec finished"<<endl;
 }
-
-
- //__________________________________________________________________
-
-Int_t AliFMDReconstruction::Determination_by_Poisson (Int_t PadADC[][50][800],
-                                          Int_t vol, Int_t rmin, Int_t rmax, 
-                                          Int_t secmin, Int_t secmax)
-{
-  Int_t threshold_adc=1;   
-  Int_t zeropads=0;
-  for (Int_t i=rmin;i<rmax;i++)
-    {
-      for (Int_t j=secmin;j<secmax;j++)
-       {
-         if (PadADC[vol-1][j][i]<threshold_adc) zeropads++;
-       };
-    };
-  Float_t lambda=-TMath::Log(Float_t(zeropads)/
-                            ( Float_t(secmax-secmin)*
-                              Float_t(rmax-rmin))); //+1 zdes' ne nado
-  Int_t Recon=(Int_t)(lambda*(secmax-secmin)*(rmax-rmin)); //+1 zdes' ne nado
-  //  cout<<"\nEnd Poisson method"<<endl;
-  return Recon;
-};
-
-//------------------------------------------------------------------
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-