]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PHOS/AliPHOSSDigitizer.cxx
fRefVolumeId for reference volume identification added.
[u/mrichter/AliRoot.git] / PHOS / AliPHOSSDigitizer.cxx
index f973f8e5c22076c399622023e368f82afb30857e..79caf80d7001942d13bd4520c4c25e26f18be816 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
+
 /* $Id$ */
 
 //_________________________________________________________________________
 // This is a TTask that makes SDigits out of Hits
+// The name of the TTask is also the title of the branch that will contain 
+// the created SDigits
+// The title of the TTAsk is the name of the file that contains the hits from
+// which the SDigits are created
 // A Summable Digits is the sum of all hits originating 
 // from one primary in one active cell
 // A threshold for assignment of the primary to SDigit is applied 
 // another set of SDigits with different parameters. Two versions
 // can be distunguished using titles of the branches.
 // User case:
-// root [0] AliPHOSSDigitizer * s = new AliPHOSSDigitizer("galice.root")
-// Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
-// root [1] s->ExecuteTask()
+//  root [0] AliPHOSSDigitizer * s = new AliPHOSSDigitizer("galice.root")
+//  Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
+//  root [1] s->ExecuteTask()
 //             // Makes SDigitis for all events stored in galice.root
-// root [2] s->SetPedestalParameter(0.001)
+//  root [2] s->SetPedestalParameter(0.001)
 //             // One can change parameters of digitization
-// root [3] s->SetSDigitsBranch("Redestal 0.001")
+// root [3] s->SetSDigitsBranch("Pedestal 0.001")
 //             // and write them into the new branch
-// root [4] s->ExeciteTask("deb all tim")
+// root [4] s->ExecuteTask("deb all tim")
 //             // available parameters:
 //             deb - print # of produced SDigitis
 //             deb all  - print # and list of produced SDigits
 
 // --- ROOT system ---
 #include "TFile.h"
-#include "TTask.h"
-#include "TTree.h"
-#include "TSystem.h"
 #include "TROOT.h"
-#include "TFolder.h"
 #include "TBenchmark.h"
+
 // --- Standard library ---
-#include <iomanip.h>
 
 // --- AliRoot header files ---
 #include "AliRun.h"
 #include "AliPHOSDigit.h"
+#include "AliPHOSGetter.h"
 #include "AliPHOSHit.h"
 #include "AliPHOSSDigitizer.h"
 
-
 ClassImp(AliPHOSSDigitizer)
 
            
 //____________________________________________________________________________ 
-  AliPHOSSDigitizer::AliPHOSSDigitizer():TTask("AliPHOSSDigitizer","") 
+  AliPHOSSDigitizer::AliPHOSSDigitizer():TTask("","") 
 {
   // ctor
-  fA = 0;
-  fB = 10000000. ;
-  fPrimThreshold = 0.01 ;
-  fNevents = 0 ;     
-  fSDigits = 0 ;
-  fHits = 0 ;
-  fIsInitialized = kFALSE ;
-
+  InitParameters() ;
+  fDefaultInit = kTRUE ; 
 }
 
 //____________________________________________________________________________ 
-AliPHOSSDigitizer::AliPHOSSDigitizer(const char* headerFile, const char *sDigitsTitle):TTask("AliPHOSSDigitizer","")
+AliPHOSSDigitizer::AliPHOSSDigitizer(const char * headerFile, const char * sDigitsTitle, const Bool_t toSplit):
+TTask(sDigitsTitle, headerFile)
 {
   // ctor
-  fA = 0;
-  fB = 10000000.;
-  fPrimThreshold = 0.01 ;
-  fNevents = 0 ;      
-  fSDigitsTitle = sDigitsTitle ;
-  fHeadersFile = headerFile ;
-  fSDigits = new TClonesArray("AliPHOSDigit",1000);
-  fHits    = new TClonesArray("AliPHOSHit",1000);
+  InitParameters() ; 
+  fToSplit = toSplit ;
+  Init();
+  fDefaultInit = kFALSE ; 
+}
 
-  TFile * file = (TFile*) gROOT->GetFile(fHeadersFile.Data() ) ;
-  
-  //File was not opened yet
-  if(file == 0){
-    if(fHeadersFile.Contains("rfio"))
-      file =   TFile::Open(fHeadersFile,"update") ;
-    else
-      file = new TFile(fHeadersFile.Data(),"update") ;
-    gAlice = (AliRun *) file->Get("gAlice") ;
-  }
-  
-  //add Task to //root/Tasks folder
-  TTask * roottasks = (TTask*)gROOT->GetRootFolder()->FindObject("Tasks") ; 
-  roottasks->Add(this) ; 
-  
-  fIsInitialized = kTRUE ;
+//____________________________________________________________________________ 
+AliPHOSSDigitizer::AliPHOSSDigitizer(const AliPHOSSDigitizer & sd) {
+  //cpy ctor 
+
+  fA             = sd.fA ;
+  fB             = sd.fB ;
+  fPrimThreshold = sd.fPrimThreshold ;
+  fSDigitsInRun  = sd.fSDigitsInRun ;
+  fSplitFile     = new TFile( (sd.fSplitFile)->GetName(), "new")  ; 
+  fToSplit       = sd.fToSplit ;
 }
 
 //____________________________________________________________________________ 
 AliPHOSSDigitizer::~AliPHOSSDigitizer()
 {
   // dtor
-  if(fSDigits)
-    delete fSDigits ;
-  if(fHits)
-    delete fHits ;
+  
+  fSplitFile = 0 ; 
 }
-//____________________________________________________________________________ 
-void AliPHOSSDigitizer::Init(){
-  //Initialization can not be done in the default constructor
 
-  if(!fIsInitialized){
+//____________________________________________________________________________ 
+void AliPHOSSDigitizer::Init()
+{
+  // Initialization: open root-file, allocate arrays for hits and sdigits,
+  // attach task SDigitizer to the list of PHOS tasks
+  // 
+  // Initialization can not be done in the default constructor
+  //============================================================= YS
+  //  The initialisation is now done by AliPHOSGetter
+  
+  if( strcmp(GetTitle(), "") == 0 )
+    SetTitle("galice.root") ;
 
-    if(fHeadersFile.IsNull())
-      fHeadersFile="galice.root" ;
+  AliPHOSGetter * gime = AliPHOSGetter::GetInstance(GetTitle(), GetName(),fToSplit) ;  
+  if ( gime == 0 ) {
+    Error("Init" ,"Could not obtain the Getter object !") ;  
+    return ;
+  } 
+  
+  gime->PostSDigits( GetName(), GetTitle() ) ; 
 
-    TFile * file = (TFile*) gROOT->GetFile(fHeadersFile.Data() ) ;
-    
-    //if file was not opened yet, read gAlice
-    if(file == 0){
-      file = new TFile(fHeadersFile.Data(),"update") ;
-      gAlice = (AliRun *) file->Get("gAlice") ;
+  fSplitFile = 0 ;
+  if(fToSplit){
+    // construct the name of the file as /path/PHOS.SDigits.root
+    // First - extract full path if necessary
+    TString sDigitsFileName(GetTitle()) ;
+    Ssiz_t islash = sDigitsFileName.Last('/') ;
+    if(islash<sDigitsFileName.Length())
+      sDigitsFileName.Remove(islash+1,sDigitsFileName.Length()) ;
+    else
+      sDigitsFileName="" ;
+    // Next - append the file name 
+    sDigitsFileName+="PHOS.SDigits." ;
+    if((strcmp(GetName(),"Default")!=0)&&(strcmp(GetName(),"")!=0)){
+      sDigitsFileName+=GetName() ;
+      sDigitsFileName+="." ;
     }
-    
-    fHits    = new TClonesArray("AliPHOSHit",1000);
-    fSDigits = new TClonesArray("AliPHOSDigit",1000);
-    
-    // add Task to //root/Tasks folder
-    TTask * roottasks = (TTask*)gROOT->GetRootFolder()->FindObject("Tasks") ; 
-    roottasks->Add(this) ; 
-    
-    fIsInitialized = kTRUE ;
+    sDigitsFileName+="root" ;
+    // Finally - check if the file already opened or open the file
+    fSplitFile = static_cast<TFile*>(gROOT->GetFile(sDigitsFileName.Data()));   
+    if(!fSplitFile)
+      fSplitFile =  TFile::Open(sDigitsFileName.Data(),"update") ;
   }
+
+  TString sdname(GetName() );
+  sdname.Append(":") ;
+  sdname.Append(GetTitle() ) ;
+  SetName(sdname) ;
+  gime->PostSDigitizer(this) ;
 }
+
+//____________________________________________________________________________ 
+void AliPHOSSDigitizer::InitParameters()
+{ 
+  // initializes the parameters for difitization
+  fA             = 0;
+  fB             = 10000000.;
+  fPrimThreshold = 0.01 ;
+  fSDigitsInRun  = 0 ;
+  fSplitFile     = 0 ; 
+  fToSplit       = kFALSE ;
+}
+
 //____________________________________________________________________________
-void AliPHOSSDigitizer::Exec(Option_t *option) { 
-  //Collects all hits in the same active volume into digit
-  
-  if(!fIsInitialized)
+void AliPHOSSDigitizer::Exec(Option_t *option) 
+{ 
+  // Collects all hits in the same active volume into digit
+
+  if( strcmp(GetName(), "") == 0 )
     Init() ;
+  
+  if (strstr(option, "print") ) {
+    Print("") ; 
+    return ; 
+  }
 
   if(strstr(option,"tim"))
     gBenchmark->Start("PHOSSDigitizer");
   
-  fNevents = (Int_t) gAlice->TreeE()->GetEntries() ; 
-  
+  //Check, if this branch already exits
+  AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
+  if(gime->BranchExists("SDigits") ) 
+    return;   
+
+  TString sdname(GetName()) ;
+  sdname.Remove(sdname.Index(GetTitle())-1) ;
+   
+  Int_t nevents = gime->MaxEvent() ; 
   Int_t ievent ;
-  for(ievent = 0; ievent < fNevents; ievent++){
-    gAlice->GetEvent(ievent) ;
-    gAlice->SetEvent(ievent) ;
-    
-    if(gAlice->TreeH()==0){
-      cout << "AliPHOSSDigitizer: There is no Hit Tree" << endl;
-      return ;
-    }
-    
-    //set address of the hits 
-    TBranch * branch = gAlice->TreeH()->GetBranch("PHOS");
-    if (branch) 
-      branch->SetAddress(&fHits);
-    else{
-      cout << "ERROR in AliPHOSSDigitizer: "<< endl ;
-      cout << "      no branch PHOS in TreeH"<< endl ;
-      cout << "      do nothing " << endl ;
-      return ;
-    }
-    
-    fSDigits->Clear();
+  for(ievent = 0; ievent < nevents; ievent++){
+    gime->Event(ievent,"H") ;
+    const TClonesArray * hits = gime->Hits() ;
+    TClonesArray * sdigits = gime->SDigits(sdname.Data()) ;
+    sdigits->Clear();
     Int_t nSdigits = 0 ;
     
-    
-    //Now made SDigits from hits, for PHOS it is the same, so just copy    
-    Int_t itrack ;
-    for (itrack=0; itrack < gAlice->GetNtrack(); itrack++){
-      
-      //=========== Get the PHOS branch from Hits Tree for the Primary track itrack
-      branch->GetEntry(itrack,0);
-      
+    //Now make SDigits from hits, for PHOS it is the same, so just copy    
+    Int_t nPrim =  static_cast<Int_t>((gAlice->TreeH())->GetEntries()) ; 
+    // Attention nPrim is the number of primaries tracked by Geant 
+    // and this number could be different to the number of Primaries in TreeK;
+    Int_t iprim ;
+    for (iprim = 0 ; iprim < nPrim ; iprim ++) { 
+      //=========== Get the PHOS branch from Hits Tree for the Primary iprim
+      gime->Track(iprim) ;
       Int_t i;
-      for ( i = 0 ; i < fHits->GetEntries() ; i++ ) {
-       AliPHOSHit * hit = (AliPHOSHit*)fHits->At(i) ;
-
+      for ( i = 0 ; i < hits->GetEntries() ; i++ ) {
+       AliPHOSHit * hit = dynamic_cast<AliPHOSHit *>(hits->At(i)) ;
        // Assign primary number only if contribution is significant
+       
        if( hit->GetEnergy() > fPrimThreshold)
-         new((*fSDigits)[nSdigits]) AliPHOSDigit( hit->GetPrimary(), hit->GetId(), Digitize( hit->GetEnergy() ) ) ;
+         new((*sdigits)[nSdigits]) AliPHOSDigit(hit->GetPrimary(),hit->GetId(),
+                                                Digitize(hit->GetEnergy()), hit->GetTime()) ;
        else
-         new((*fSDigits)[nSdigits]) AliPHOSDigit( -1               , hit->GetId(), Digitize( hit->GetEnergy() ) ) ;
+         new((*sdigits)[nSdigits]) AliPHOSDigit( -1              , hit->GetId(), 
+                                                 Digitize(hit->GetEnergy()), hit->GetTime()) ;
+       nSdigits++ ;    
        
-       nSdigits++ ;  
-       
-      } 
+      }
       
-    } // loop over tracks
+    } // loop over iprim
     
-    fSDigits->Sort() ;
+    sdigits->Sort() ;
     
-    nSdigits = fSDigits->GetEntriesFast() ;
-    fSDigits->Expand(nSdigits) ;
+    nSdigits = sdigits->GetEntriesFast() ;
+    fSDigitsInRun += nSdigits ;  
+    sdigits->Expand(nSdigits) ;
     
     Int_t i ;
     for (i = 0 ; i < nSdigits ; i++) { 
-      AliPHOSDigit * digit = (AliPHOSDigit *) fSDigits->At(i) ; 
+      AliPHOSDigit * digit = dynamic_cast<AliPHOSDigit *>(sdigits->At(i)) ; 
       digit->SetIndexInList(i) ;     
     }
 
-    if(gAlice->TreeS() == 0)
-      gAlice->MakeTree("S") ;
-    
-    //check, if this branch already exits?
-    TBranch * sdigitsBranch = 0;
-    TBranch * sdigitizerBranch = 0;
+    //Now write SDigits
     
-    TObjArray * branches = gAlice->TreeS()->GetListOfBranches() ;
-    Int_t ibranch;
-    Bool_t phosNotFound = kTRUE ;
-    Bool_t sdigitizerNotFound = kTRUE ;
+    if((gAlice->TreeS() == 0)|| (fSplitFile))  
+      gAlice->MakeTree("S", fSplitFile);
     
-    for(ibranch = 0;ibranch <branches->GetEntries();ibranch++){
-      
-      if(phosNotFound){
-       sdigitsBranch=(TBranch *) branches->At(ibranch) ;
-       if( (strcmp("PHOS",sdigitsBranch->GetName())==0 ) &&
-           (fSDigitsTitle.CompareTo(sdigitsBranch->GetTitle()) == 0) )
-         phosNotFound = kFALSE ;
-      }
-      if(sdigitizerNotFound){
-       sdigitizerBranch = (TBranch *) branches->At(ibranch) ;
-       if( (strcmp(sdigitizerBranch->GetName(),"AliPHOSSDigitizer") == 0)&&
-           (fSDigitsTitle.CompareTo(sdigitizerBranch->GetTitle()) == 0) )
-         sdigitizerNotFound = kFALSE ;
-      }
-    }
+    if(fSplitFile)
+      fSplitFile->cd() ;
 
-    if(!(sdigitizerNotFound && phosNotFound)){
-      cout << "AliPHOSSdigitizer error:" << endl ;
-      cout << "Can not overwrite existing branches: do not write" << endl ;
-      return ;
-    }
-    
-    //Make (if necessary) branches    
-    char * file =0;
-    if(gSystem->Getenv("CONFIG_SPLIT_FILE")){ //generating file name
-      file = new char[strlen(gAlice->GetBaseFile())+20] ;
-      sprintf(file,"%s/PHOS.SDigits.root",gAlice->GetBaseFile()) ;
-    }
-    
-    TDirectory *cwd = gDirectory;
-    
     //First list of sdigits
-    Int_t bufferSize = 32000 ;    
-    sdigitsBranch = gAlice->TreeS()->Branch("PHOS",&fSDigits,bufferSize);
-    sdigitsBranch->SetTitle(fSDigitsTitle.Data());
-    if (file) {
-      sdigitsBranch->SetFile(file);
-      TIter next( sdigitsBranch->GetListOfBranches());
-      while ((sdigitsBranch=(TBranch*)next())) {
-       sdigitsBranch->SetFile(file);
-      }   
-      cwd->cd();
-    } 
-      
-    //second - SDigitizer
+    Int_t bufferSize = 32000 ;
+    TBranch * sdigitsBranch = gAlice->TreeS()->Branch("PHOS",&sdigits,bufferSize);
+    sdigitsBranch->SetTitle(sdname);
+    
+    //Next - SDigitizer
     Int_t splitlevel = 0 ;
     AliPHOSSDigitizer * sd = this ;
-    sdigitizerBranch = gAlice->TreeS()->Branch("AliPHOSSDigitizer","AliPHOSSDigitizer",
-                                              &sd,bufferSize,splitlevel); 
-    sdigitizerBranch->SetTitle(fSDigitsTitle.Data());
-    if (file) {
-      sdigitizerBranch->SetFile(file);
-      TIter next( sdigitizerBranch->GetListOfBranches());
-      while ((sdigitizerBranch=(TBranch*)next())) {
-       sdigitizerBranch->SetFile(file);
-      }   
-      cwd->cd();
-      delete file;
-    }
-
-    gAlice->TreeS()->Fill() ;
-    gAlice->TreeS()->Write(0,TObject::kOverwrite) ;
+    TBranch * sdigitizerBranch = gAlice->TreeS()->Branch("AliPHOSSDigitizer","AliPHOSSDigitizer",
+                                                        &sd,bufferSize,splitlevel);
+    sdigitizerBranch->SetTitle(sdname);
     
+    sdigitsBranch->Fill() ;
+    sdigitizerBranch->Fill() ;
+
+    gAlice->TreeS()->AutoSave() ;
+        
     if(strstr(option,"deb"))
       PrintSDigits(option) ;
-    
   }
   
   if(strstr(option,"tim")){
     gBenchmark->Stop("PHOSSDigitizer");
-    cout << "AliPHOSSDigitizer:" << endl ;
-    cout << "   took " << gBenchmark->GetCpuTime("PHOSSDigitizer") << " seconds for SDigitizing " 
-        <<  gBenchmark->GetCpuTime("PHOSSDigitizer")/fNevents << " seconds per event " << endl ;
-    cout << endl ;
+    Info("Exec","   took %f seconds for SDigitizing  %f seconds per event",
+        gBenchmark->GetCpuTime("PHOSSDigitizer"), gBenchmark->GetCpuTime("PHOSSDigitizer")/nevents) ;
   }
-  
-  
 }
+
 //__________________________________________________________________
-void AliPHOSSDigitizer::SetSDigitsBranch(const char * title ){
-  //Seting title to branch SDigits 
-  if(!fSDigitsTitle.IsNull())
-    cout << "AliPHOSSdigitizer: changing SDigits file from " <<fSDigitsTitle.Data() << " to " << title << endl ;
-  fSDigitsTitle=title ;
+void AliPHOSSDigitizer::SetSDigitsBranch(const char * title )
+{
+  // Setting title to branch SDigits 
+
+  TString stitle(title) ;
+
+  // check if branch with title already exists
+  TBranch * sdigitsBranch    = 
+    static_cast<TBranch*>(gAlice->TreeS()->GetListOfBranches()->FindObject("PHOS")) ; 
+  TBranch * sdigitizerBranch =  
+    static_cast<TBranch*>(gAlice->TreeS()->GetListOfBranches()->FindObject("AliPHOSSDigitizer")) ;
+  const char * sdigitsTitle    = sdigitsBranch ->GetTitle() ;  
+  const char * sdigitizerTitle = sdigitizerBranch ->GetTitle() ;
+  if ( stitle.CompareTo(sdigitsTitle)==0 || stitle.CompareTo(sdigitizerTitle)==0 ){
+    Error("SetSDigitsBranch", "Cannot overwrite existing branch with title %s", title) ;
+    return ;
+  }
+  
+  Info("SetSDigitsBranch", "-> Changing SDigits file from %s to %s", GetName(), title) ;
+
+  SetName(title) ; 
+    
+  // Post to the WhiteBoard
+  AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ; 
+  gime->PostSDigits( title, GetTitle()) ; 
 }
+
+
 //__________________________________________________________________
-void AliPHOSSDigitizer::Print(Option_t* option)const{
-  cout << "------------------- "<< GetName() << " -------------" << endl ;
-  cout << "   Writing SDigitis to branch with title  " << fSDigitsTitle.Data() << endl ;
-  cout << "   with digitization parameters  A = " << fA << endl ;
-  cout << "                                 B = " << fB << endl ;
-  cout << "   Threshold for Primary assignment= " << fPrimThreshold << endl ; 
-  cout << "---------------------------------------------------"<<endl ;
+void AliPHOSSDigitizer::Print(Option_t* option)const
+{
+  // Prints parameters of SDigitizer
+  TString message ; 
+  message  = "\n------------------- %s -------------\n" ;  
+  message += "   Writing SDigits to branch with title  %s\n" ;
+  message += "   with digitization parameters  A = %f\n" ; 
+  message += "                                 B = %f\n" ;
+  message += "   Threshold for Primary assignment= %f\n" ; 
+  message += "---------------------------------------------------\n" ;
+  Info("Print", message.Data(),  GetName(),  GetName(), fA, fB, fPrimThreshold ) ;
   
 }
+
 //__________________________________________________________________
-Bool_t AliPHOSSDigitizer::operator==( AliPHOSSDigitizer const &sd )const{
+Bool_t AliPHOSSDigitizer::operator==( AliPHOSSDigitizer const &sd )const
+{
+  // Equal operator.
+  // SDititizers are equal if their pedestal, slope and threshold are equal
+
   if( (fA==sd.fA)&&(fB==sd.fB)&&(fPrimThreshold==sd.fPrimThreshold))
     return kTRUE ;
   else
     return kFALSE ;
 }
+
 //__________________________________________________________________
-void AliPHOSSDigitizer::PrintSDigits(Option_t * option){
-  //Prints list of digits produced at the current pass of AliPHOSDigitizer
-  
-  cout << "AliPHOSSDigitizer: " << endl ;
-  cout << "       Number of entries in SDigits list  " << fSDigits->GetEntriesFast() << endl ;
-  cout << endl ;
+void AliPHOSSDigitizer::PrintSDigits(Option_t * option)
+{
+  // Prints list of digits produced in the current pass of AliPHOSDigitizer
+
+
+  AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ; 
+  TString sdname(GetName()) ;
+  sdname.Remove(sdname.Index(GetTitle())-1) ;
+  const TClonesArray * sdigits = gime->SDigits(sdname.Data()) ;
+
+  TString message ; 
+  message  = "\nAliPHOSSDigitiser: event " ;
+  message += gAlice->GetEvNumber(); 
+  message += "\n      Number of entries in SDigits list " ;  
+  message += sdigits->GetEntriesFast() ; 
+  char * tempo = new char[8192]; 
   
-  if(strstr(option,"all")){// print all digits
+  if(strstr(option,"all")||strstr(option,"EMC")){
     
     //loop over digits
     AliPHOSDigit * digit;
-    cout << "SDigit Id " << " Amplitude " <<  " Index "  <<  " Nprim " << " Primaries list " <<  endl;    
+    message += "\nEMC sdigits\n" ;
+    message += "\n   Id  Amplitude    Time          Index Nprim: Primaries list \n" ;    
+    Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ;
     Int_t index ;
-    for (index = 0 ; index < fSDigits->GetEntries() ; index++) {
-      digit = (AliPHOSDigit * )  fSDigits->At(index) ;
-      cout << setw(8)  <<  digit->GetId() << " "  <<   setw(3)  <<  digit->GetAmp() <<   "  "  
-          << setw(6)  <<  digit->GetIndexInList() << "  "   
-          << setw(5)  <<  digit->GetNprimary() <<"  ";
-      
+    for (index = 0 ; (index < sdigits->GetEntriesFast()) && 
+        ((dynamic_cast<AliPHOSDigit *> (sdigits->At(index)))->GetId() <= maxEmc) ; index++) {
+      digit = dynamic_cast<AliPHOSDigit *>( sdigits->At(index) ) ;
+      if(digit->GetNprimary() == 0) 
+       continue;
+      sprintf(tempo, "\n%6d  %8d    %6.5e %4d      %2d :",
+             digit->GetId(), digit->GetAmp(), digit->GetTime(), digit->GetIndexInList(), digit->GetNprimary()) ;  
+      message += tempo ; 
       Int_t iprimary;
-      for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++)
-       cout << setw(5)  <<  digit->GetPrimary(iprimary+1) << "  ";
-      cout << endl;     
-    }
+      for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
+       sprintf(tempo, "%d ",digit->GetPrimary(iprimary+1) ) ; 
+       message += tempo ; 
+      }  
+    }    
+  }
+
+  if(strstr(option,"all")||strstr(option,"CPV")){
+    
+    //loop over CPV digits
+    AliPHOSDigit * digit;
     
+    message += "CPV sdigits\n" ;
+    message += "\n   Id  Amplitude    Index Nprim: Primaries list \n" ;    
+    Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ;
+    Int_t index ;
+    for (index = 0 ; index < sdigits->GetEntriesFast(); index++) {
+      digit = dynamic_cast<AliPHOSDigit *>( sdigits->At(index) ) ;
+      if(digit->GetId() > maxEmc){
+       sprintf(tempo, "\n%6d  %8d    %4d      %2d :",
+               digit->GetId(), digit->GetAmp(), digit->GetIndexInList(), digit->GetNprimary()) ;  
+       message += tempo ; 
+       Int_t iprimary;
+       for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
+         sprintf(tempo, "%d ",digit->GetPrimary(iprimary+1) ) ; 
+         message += tempo ; 
+       }
+      }    
+    }
   }
+  delete tempo ; 
+  Info("PrintSDigits", message.Data() ) ;
+}
+
+//____________________________________________________________________________ 
+void AliPHOSSDigitizer::UseHitsFrom(const char * filename)
+{
+  SetTitle(filename) ; 
+  Init() ; 
 }