]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PHOS/AliPHOSClusterizerv1.cxx
Cleaning includes
[u/mrichter/AliRoot.git] / PHOS / AliPHOSClusterizerv1.cxx
index 058321d548211f3c2b5ffa8c2edd61be44305213..42311dbfee006462af558be798eff836095ca8f8 100644 (file)
 
 // --- Standard library ---
 
-#include <iostream.h>
-#include <iomanip.h>
-
 // --- AliRoot header files ---
-
+#include "AliPHOSCalibrationDB.h"
 #include "AliPHOSClusterizerv1.h"
 #include "AliPHOSCpvRecPoint.h"
 #include "AliPHOSDigit.h"
@@ -100,7 +97,6 @@ AliPHOSClusterizerv1::AliPHOSClusterizerv1(const char* headerFile,const char* na
   // ctor with the indication of the file where header Tree and digits Tree are stored
   
   InitParameters() ;
-  
   Init() ;
   fDefaultInit = kFALSE ; 
 
@@ -110,26 +106,8 @@ AliPHOSClusterizerv1::AliPHOSClusterizerv1(const char* headerFile,const char* na
   AliPHOSClusterizerv1::~AliPHOSClusterizerv1()
 {
   // dtor
+  fSplitFile = 0 ; 
 
-//   if (!fDefaultInit) {
-//     AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ; 
-    
-//   // remove the task from the folder list
-//     gime->RemoveTask("C",GetName()) ;
-    
-//     // remove the data from the folder list
-//     TString name(GetName()) ; 
-//     name.Remove(name.Index(":")) ; 
-//     gime->RemoveObjects("D", name) ;  //  Digits
-//     gime->RemoveObjects("RE", name) ; // EMCARecPoints
-//     gime->RemoveObjects("RC", name) ; // CPVRecPoints
-    
-//     // Delete gAlice
-//     gime->CloseFile() ; 
-    
-    fSplitFile = 0 ; 
-//  }
 }
 
 //____________________________________________________________________________
@@ -143,11 +121,16 @@ const TString AliPHOSClusterizerv1::BranchName() const
 //____________________________________________________________________________
 Float_t  AliPHOSClusterizerv1::Calibrate(Int_t amp, Int_t absId) const
 { //To be replased later by the method, reading individual parameters from the database
-  if(absId <= fEmcCrystals) //calibrate as EMC 
-    return fADCpedestalEmc + amp*fADCchanelEmc ;       
-  else //Digitize as CPV
-    return fADCpedestalCpv+ amp*fADCchanelCpv ;       
+  if(fCalibrationDB)
+    return fCalibrationDB->Calibrate(amp,absId) ;
+  else{ //simulation
+    if(absId <= fEmcCrystals) //calibrate as EMC 
+      return fADCpedestalEmc + amp*fADCchanelEmc ;        
+    else //calibrate as CPV
+      return fADCpedestalCpv+ amp*fADCchanelCpv ;       
+  }
 }
+
 //____________________________________________________________________________
 void AliPHOSClusterizerv1::Exec(Option_t * option)
 {
@@ -162,36 +145,6 @@ void AliPHOSClusterizerv1::Exec(Option_t * option)
   if(strstr(option,"print"))
     Print("") ; 
 
-//    gAlice->GetEvent(0) ;
-  
-//  //check, if the branch with name of this" already exits?
-//   if(gAlice->TreeR()) { 
-//     TObjArray * lob = (TObjArray*)gAlice->TreeR()->GetListOfBranches() ;
-//     TIter next(lob) ; 
-//     TBranch * branch = 0 ;  
-//     Bool_t phosemcfound = kFALSE, phoscpvfound = kFALSE, clusterizerfound = kFALSE ; 
-    
-//     TString branchname = GetName() ;
-//     branchname.Remove(branchname.Index(Version())-1) ;
-    
-//     while ( (branch = (TBranch*)next()) && (!phosemcfound || !phoscpvfound || !clusterizerfound) ) {
-//       if ( (strcmp(branch->GetName(), "PHOSEmcRP")==0) && (strcmp(branch->GetTitle(), branchname.Data())==0) ) 
-//     phosemcfound = kTRUE ;
-      
-//       else if ( (strcmp(branch->GetName(), "PHOSCpvRP")==0) && (strcmp(branch->GetTitle(), branchname.Data())==0) ) 
-//     phoscpvfound = kTRUE ;
-      
-//       else if ((strcmp(branch->GetName(), "AliPHOSClusterizer")==0) && (strcmp(branch->GetTitle(), GetName())==0) ) 
-//     clusterizerfound = kTRUE ; 
-//     }
-    
-//     if ( phoscpvfound || phosemcfound || clusterizerfound ) {
-//       cerr << "WARNING: AliPHOSClusterizer::Exec -> Emc(Cpv)RecPoints and/or Clusterizer branch with name " 
-//        << branchname.Data() << " already exits" << endl ;
-//       return ; 
-//     }       
-//   }
-  
   AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
   if(gime->BranchExists("RecPoints"))
     return ;
@@ -205,12 +158,8 @@ void AliPHOSClusterizerv1::Exec(Option_t * option)
     if(ievent == 0)
       GetCalibrationParameters() ;
     
-    fNumberOfEmcClusters  = 0 ;
-    fNumberOfCpvClusters  = 0 ;
-    
-    
-    //    if(!ReadDigits(ievent))   continue;  //reads digits for event ievent
-    
+    fNumberOfEmcClusters  = fNumberOfCpvClusters  = 0 ;
+            
     MakeClusters() ;
     
     if(fToUnfold)             
@@ -228,12 +177,10 @@ void AliPHOSClusterizerv1::Exec(Option_t * option)
   
   if(strstr(option,"tim")){
     gBenchmark->Stop("PHOSClusterizer");
-    cout << "AliPHOSClusterizer:" << endl ;
-    cout << "  took " << gBenchmark->GetCpuTime("PHOSClusterizer") << " seconds for Clusterizing " 
-        <<  gBenchmark->GetCpuTime("PHOSClusterizer")/nevents << " seconds per event " << endl ;
-    cout << endl ;
+    Info("Exec", "  took %f seconds for Clusterizing %f seconds per event \n",
+        gBenchmark->GetCpuTime("PHOSClusterizer"), 
+        gBenchmark->GetCpuTime("PHOSClusterizer")/nevents ) ; 
   }
-  
 }
 
 //____________________________________________________________________________
@@ -284,19 +231,19 @@ Bool_t AliPHOSClusterizerv1::FindFit(AliPHOSEmcRecPoint * emcRP, AliPHOSDigit **
     gMinuit->mnparm(index, "x",  x, 0.1, 0, 0, ierflg) ;
     index++ ;   
     if(ierflg != 0){ 
-      cout << "PHOS Unfolding>  Unable to set initial value for fit procedure : x = " << x << endl ;
+      Warning("FindFit", "PHOS Unfolding unable to set initial value for fit procedure : x = %f\n", x ) ;
       return kFALSE;
     }
     gMinuit->mnparm(index, "z",  z, 0.1, 0, 0, ierflg) ;
     index++ ;   
     if(ierflg != 0){
-      cout << "PHOS Unfolding>  Unable to set initial value for fit procedure : z = " << z << endl ;
+       Warning("FindFit", "PHOS Unfolding unable to set initial value for fit procedure : z =%f\n", z ) ;
       return kFALSE;
     }
     gMinuit->mnparm(index, "Energy",  energy , 0.05*energy, 0., 4.*energy, ierflg) ;
     index++ ;   
     if(ierflg != 0){
-      cout << "PHOS Unfolding>  Unable to set initial value for fit procedure : energy = " << energy << endl ;      
+      Warning("FindFit", "PHOS Unfolding unable to set initial value for fit procedure : energy = %f\n", energy ) ;      
       return kFALSE;
     }
   }
@@ -314,7 +261,7 @@ Bool_t AliPHOSClusterizerv1::FindFit(AliPHOSEmcRecPoint * emcRP, AliPHOSDigit **
   gMinuit->mnexcm("MIGRAD", &p0, 0, ierflg) ;    // minimize 
 
   if(ierflg == 4){  // Minimum not found   
-    cout << "PHOS Unfolding>  Fit not converged, cluster abandoned "<< endl ;      
+    Warning("FindFit", "PHOS Unfolding fit not converged, cluster abandoned\n" );      
     return kFALSE ;
   }            
   for(index = 0; index < nPar; index++){
@@ -333,15 +280,22 @@ Bool_t AliPHOSClusterizerv1::FindFit(AliPHOSEmcRecPoint * emcRP, AliPHOSDigit **
 void AliPHOSClusterizerv1::GetCalibrationParameters() 
 {
   AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
-  const AliPHOSDigitizer * dig = gime->Digitizer(BranchName()) ;
 
-  fADCchanelEmc   = dig->GetEMCchannel() ;
-  fADCpedestalEmc = dig->GetEMCpedestal();
-  
-  fADCchanelCpv   = dig->GetCPVchannel() ;
-  fADCpedestalCpv = dig->GetCPVpedestal() ; 
-  
+  const TTask * task = gime->Digitizer(BranchName()) ;
+  if(strcmp(task->IsA()->GetName(),"AliPHOSDigitizer")==0){
+    const AliPHOSDigitizer * dig = static_cast<const AliPHOSDigitizer *>(task) ;
+
+    fADCchanelEmc   = dig->GetEMCchannel() ;
+    fADCpedestalEmc = dig->GetEMCpedestal();
+    
+    fADCchanelCpv   = dig->GetCPVchannel() ;
+    fADCpedestalCpv = dig->GetCPVpedestal() ; 
+  }
+  else{
+    fCalibrationDB = gime->CalibrationDB();
+  }
 }
+
 //____________________________________________________________________________
 void AliPHOSClusterizerv1::Init()
 {
@@ -356,7 +310,7 @@ void AliPHOSClusterizerv1::Init()
 
   AliPHOSGetter * gime = AliPHOSGetter::GetInstance(GetTitle(),branchname.Data(), fToSplit ) ; 
   if ( gime == 0 ) {
-    cerr << "ERROR: AliPHOSClusterizerv1::Init -> Could not obtain the Getter object !" << endl ; 
+    Error("Init", "Could not obtain the Getter object !") ;  
     return ;
   } 
 
@@ -393,9 +347,6 @@ void AliPHOSClusterizerv1::Init()
 
   gime->PostClusterizer(this) ;
   gime->PostRecPoints(branchname) ;
-
-  //  gime->PostDigits() ;
-  //  gime->PostDigitizer() ;
   
 }
 
@@ -418,10 +369,7 @@ void AliPHOSClusterizerv1::InitParameters()
   fEmcTimeGate             = 1.e-8 ; 
   
   fToUnfold                = kTRUE ;
-  
-  //  fHeaderFileName          = GetTitle() ; 
-  //  fDigitsBranchTitle       = GetName() ;
-   
+    
   TString clusterizerName( GetName()) ;
   if (clusterizerName.IsNull() ) 
     clusterizerName = "Default" ; 
@@ -429,6 +377,8 @@ void AliPHOSClusterizerv1::InitParameters()
   clusterizerName.Append(Version()) ; 
   SetName(clusterizerName) ;
   fRecPointsInRun          = 0 ;
+  fCalibrationDB = 0 ;
+
 
 }
 
@@ -534,7 +484,10 @@ void AliPHOSClusterizerv1::WriteRecPoints(Int_t event)
   }
   
   if(!treeR){
-    gAlice->MakeTree("R", fSplitFile);
+    if(fSplitFile)
+      gAlice->MakeTree("R", fSplitFile);
+    else
+      gAlice->MakeTree("R", gROOT->GetFile(GetTitle()));
     treeR = gAlice->TreeR() ;
   }
 
@@ -581,7 +534,7 @@ void AliPHOSClusterizerv1::WriteRecPoints(Int_t event)
   cpvBranch        ->Fill() ;
   clusterizerBranch->Fill() ;
 
-  treeR->AutoSave() ; //Write(0,kOverwrite) ;  
+  treeR->AutoSave() ; 
   if(gAlice->TreeR()!=treeR)
     treeR->Delete();
 }
@@ -601,9 +554,7 @@ void AliPHOSClusterizerv1::MakeClusters()
   
   TClonesArray * digits = gime->Digits() ; 
    if ( !digits ) {
-    cerr << "ERROR:  AliPHOSClusterizerv1::MakeClusters -> Digits with name " 
-        << GetName() << " not found ! " << endl ; 
-    abort() ; 
+   Fatal("MakeClusters", "Digits with name %s not found !", BranchName().Data() ) ;  
   } 
   TClonesArray * digitsC =  (TClonesArray*)digits->Clone() ;
   
@@ -622,7 +573,6 @@ void AliPHOSClusterizerv1::MakeClusters()
 
     if (( IsInEmc (digit) && Calibrate(digit->GetAmp(),digit->GetId()) > fEmcClusteringThreshold  ) || 
         ( IsInCpv (digit) && Calibrate(digit->GetAmp(),digit->GetId()) > fCpvClusteringThreshold  ) ) {
-         
       Int_t iDigitInCluster = 0 ; 
       
       if  ( IsInEmc(digit) ) {   
@@ -1017,35 +967,45 @@ void AliPHOSClusterizerv1::Print(Option_t * option)const
 {
   // Print clusterizer parameters
 
-  if( strcmp(GetName(), "") !=0 ){
-    
+  TString message ; 
+  TString taskName(GetName()) ; 
+  taskName.ReplaceAll(Version(), "") ;
+  
+  if( strcmp(GetName(), "") !=0 ) {  
     // Print parameters
-    TString taskName(GetName()) ; 
-    taskName.ReplaceAll(Version(), "") ;
-
-    cout << "---------------"<< taskName.Data() << " " << GetTitle()<< "-----------" << endl 
-        << "Clusterizing digits from the file: " << taskName.Data() << endl 
-        << "                           Branch: " << GetName() << endl 
-        << endl 
-        << "                       EMC Clustering threshold = " << fEmcClusteringThreshold << endl
-        << "                       EMC Local Maximum cut    = " << fEmcLocMaxCut << endl
-        << "                       EMC Logarothmic weight   = " << fW0 << endl
-        << endl
-        << "                       CPV Clustering threshold = " << fCpvClusteringThreshold << endl
-        << "                       CPV Local Maximum cut    = " << fCpvLocMaxCut << endl
-       << "                       CPV Logarothmic weight   = " << fW0CPV << endl
-        << endl ;
+    message  = "\n--------------- %s %s -----------\n" ; 
+    message += "Clusterizing digits from the file: %s\n" ;
+    message += "                           Branch: %s\n" ; 
+    message += "                       EMC Clustering threshold = %f\n" ; 
+    message += "                       EMC Local Maximum cut    = %f\n" ; 
+    message += "                       EMC Logarothmic weight   = %f\n" ;
+    message += "                       CPV Clustering threshold = %f\n" ;
+    message += "                       CPV Local Maximum cut    = %f\n" ;
+    message += "                       CPV Logarothmic weight   = %f\n" ;
     if(fToUnfold)
-      cout << " Unfolding on " << endl ;
+      message += " Unfolding on\n" ;
     else
-      cout << " Unfolding off " << endl ;
+      message += " Unfolding off\n" ;
     
-    cout << "------------------------------------------------------------------" <<endl ;
+    message += "------------------------------------------------------------------" ;
   }
-  else
-    cout << " AliPHOSClusterizerv1 not initialized " << endl ;
+  else 
+    message = " AliPHOSClusterizerv1 not initialized " ;
+  
+  Info("Print", message.Data(),  
+       taskName.Data(), 
+       GetTitle(),
+       taskName.Data(), 
+       GetName(), 
+       fEmcClusteringThreshold, 
+       fEmcLocMaxCut, 
+       fW0, 
+       fCpvClusteringThreshold, 
+       fCpvLocMaxCut, 
+       fW0CPV ) ; 
 }
+
+
 //____________________________________________________________________________
 void AliPHOSClusterizerv1::PrintRecPoints(Option_t * option)
 {
@@ -1054,17 +1014,23 @@ void AliPHOSClusterizerv1::PrintRecPoints(Option_t * option)
   TObjArray * emcRecPoints = AliPHOSGetter::GetInstance()->EmcRecPoints(BranchName()) ; 
   TObjArray * cpvRecPoints = AliPHOSGetter::GetInstance()->CpvRecPoints(BranchName()) ; 
 
-  cout << "AliPHOSClusterizerv1: : event "<<gAlice->GetEvNumber() << endl ;
-  cout << "       Found "<< emcRecPoints->GetEntriesFast() << " EMC Rec Points and " 
-          << cpvRecPoints->GetEntriesFast() << " CPV RecPoints" << endl ;
-
+  TString message ; 
+  message  = "\nevent " ;
+  message += gAlice->GetEvNumber() ; 
+  message += "\n       Found " ; 
+  message += emcRecPoints->GetEntriesFast() ; 
+  message += "EMC RecPoints and " ;
+  message += cpvRecPoints->GetEntriesFast() ; 
+  message += " CPV RecPoints \n" ; 
   fRecPointsInRun +=  emcRecPoints->GetEntriesFast() ; 
   fRecPointsInRun +=  cpvRecPoints->GetEntriesFast() ; 
-
+  
+  char * tempo = new char[8192]; 
+  
   if(strstr(option,"all")) {
-    cout << "EMC clusters " << endl ;
-    cout << " Index  Ene(MeV)   Multi  Module     X      Y      Z    Lambda 1   Lambda 2  # of prim  Primaries list "      <<  endl;      
-    
+    message += "\nEMC clusters\n" ;
+    message += "Index    Ene(MeV) Multi Module     X     Y   Z  Lambda 1 Lambda 2  # of prim  Primaries list\n" ;      
     Int_t index ;
     for (index = 0 ; index < emcRecPoints->GetEntries() ; index++) {
       AliPHOSEmcRecPoint * rp = (AliPHOSEmcRecPoint * )emcRecPoints->At(index) ; 
@@ -1075,57 +1041,40 @@ void AliPHOSClusterizerv1::PrintRecPoints(Option_t * option)
       Int_t * primaries; 
       Int_t nprimaries;
       primaries = rp->GetPrimaries(nprimaries);
-
-      cout << setw(4) << rp->GetIndexInList() << "   " 
-          << setw(7) << setprecision(3) << rp->GetEnergy() << "           " 
-          << setw(3) <<         rp->GetMultiplicity() << "  " 
-          << setw(1) <<              rp->GetPHOSMod() << "  " 
-          << setw(6) << setprecision(2) << locpos.X() << "  " 
-          << setw(6) << setprecision(2) << locpos.Y() << "  " 
-          << setw(6) << setprecision(2) << locpos.Z() << "  "
-          << setw(4) << setprecision(2) << lambda[0]  << "  "
-          << setw(4) << setprecision(2) << lambda[1]  << "  "
-          << setw(2) << nprimaries << "  " ;
-     
-      for (Int_t iprimary=0; iprimary<nprimaries; iprimary++)
-       cout << setw(4) <<   primaries[iprimary] << "  "  ;
-      cout << endl ;    
-    }
-
-    //Now plot CPV recPoints
-    cout << "EMC clusters " << endl ;
-    cout << "  Index    " 
-        << "  Multi    "
-        << "  Module   "  
-        << "    X      "
-        << "    Y      "
-        << "    Z      "
-        << " # of prim "
-        << " Primaries list "      <<  endl;      
-    
-    for (index = 0 ; index < cpvRecPoints->GetEntries() ; index++) {
-      AliPHOSRecPoint * rp = (AliPHOSRecPoint * )cpvRecPoints->At(index) ; 
-      cout << setw(6) << rp->GetIndexInList() << "     ";
-      cout << setw(6) << rp->GetPHOSMod()     << "        CPV     ";
+      sprintf(tempo, "\n%6d  %8.2f  %3d     %2d     %4.1f    %4.1f %4.1f %4f  %4f    %2d     : ", 
+             rp->GetIndexInList(), rp->GetEnergy(), rp->GetMultiplicity(), rp->GetPHOSMod(), 
+             locpos.X(), locpos.Y(), locpos.Z(), lambda[0], lambda[1], nprimaries) ; 
+      message += tempo ; 
       
-      TVector3  locpos;  
-      rp->GetLocalPosition(locpos);
-      cout << setw(6) <<  locpos.X()          << "     ";
-      cout << setw(6) <<  locpos.Y()          << "     ";
-      cout << setw(6) <<  locpos.Z()          << "     ";
+      for (Int_t iprimary=0; iprimary<nprimaries; iprimary++) {
+       sprintf(tempo, "%d ", primaries[iprimary] ) ; 
+       message += tempo ;
+      }
       
-      Int_t * primaries; 
-      Int_t nprimaries ; 
-      primaries = rp->GetPrimaries(nprimaries);
-      cout << setw(6) <<    nprimaries         << "     ";
-
-      for (Int_t iprimary=0; iprimary<nprimaries; iprimary++)
-       cout << setw(4)  <<  primaries[iprimary] << " ";
-      cout << endl;     
+      //Now plot CPV recPoints
+      message += "Index    Ene(MeV) Module     X     Y   Z  # of prim  Primaries list\n" ;      
+      for (index = 0 ; index < cpvRecPoints->GetEntries() ; index++) {
+       AliPHOSRecPoint * rp = (AliPHOSRecPoint * )cpvRecPoints->At(index) ; 
+       
+       TVector3  locpos;  
+       rp->GetLocalPosition(locpos);
+       
+       Int_t * primaries; 
+       Int_t nprimaries ; 
+       primaries = rp->GetPrimaries(nprimaries);
+       sprintf(tempo, "\n%6d  %8.2f  %2d     %4.1f    %4.1f %4.1f %2d     : ", 
+               rp->GetIndexInList(), rp->GetEnergy(), rp->GetPHOSMod(), 
+               locpos.X(), locpos.Y(), locpos.Z(), nprimaries) ; 
+       message += tempo ; 
+       primaries = rp->GetPrimaries(nprimaries);
+       for (Int_t iprimary=0; iprimary<nprimaries; iprimary++) {
+         sprintf(tempo, "%d ", primaries[iprimary] ) ; 
+         message += tempo ;
+       }
+      }
     }
-
-
-    cout << "-----------------------------------------------------------------------"<<endl ;
   }
+  delete tempo ; 
+  Info("Print", message.Data() ) ; 
 }