]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PHOS/AliPHOSSDigitizer.cxx
New FMD parameters.
[u/mrichter/AliRoot.git] / PHOS / AliPHOSSDigitizer.cxx
index e2d13ead974347df3d9bac177f8de60389dae4fb..4f4c8c828a7a4d3eef0d4706d8ca2ff826be40e7 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 
@@ -33,9 +38,9 @@
 //             // Makes SDigitis for all events stored in galice.root
 //  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
 #include "TROOT.h"
 #include "TFolder.h"
 #include "TBenchmark.h"
+#include "TGeometry.h"
+
 // --- Standard library ---
 #include <iomanip.h>
 
 // --- AliRoot header files ---
 #include "AliRun.h"
+#include "AliHeader.h"
 #include "AliPHOSDigit.h"
+#include "AliPHOSGeometry.h"
+#include "AliPHOSGetter.h"
 #include "AliPHOSHit.h"
 #include "AliPHOSSDigitizer.h"
 
@@ -67,266 +77,296 @@ 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):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);
-
-  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 ;
+  InitParameters() ; 
+  Init();
+  fDefaultInit = kFALSE ; 
 }
 
 //____________________________________________________________________________ 
 AliPHOSSDigitizer::~AliPHOSSDigitizer()
 {
   // dtor
-  if(fSDigits)
-    delete fSDigits ;
-  if(fHits)
-    delete fHits ;
+  // fDefaultInit = kTRUE if SDigitizer created by default ctor (to get just the parameters)
+
+  
+  if (!fDefaultInit) {
+    AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ; 
+    
+    // remove the task from the folder list
+    gime->RemoveTask("S",GetName()) ;
+    
+    TString name(GetName()) ; 
+    if (! name.IsNull() ) 
+      name.Remove(name.Index(":")) ; 
+    
+    // remove the Hits from the folder list
+    gime->RemoveObjects("H",name) ;
+    
+    // remove the SDigits from the folder list
+    gime->RemoveObjects("S", name) ;
+    
+    // Delete gAlice
+    gime->CloseFile() ; 
+    
+  }
+  fSplitFile = 0 ; 
 }
+
 //____________________________________________________________________________ 
 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(!fIsInitialized){
+  AliPHOSGetter * gime = AliPHOSGetter::GetInstance(GetTitle(), GetName()) ;     
+  if ( gime == 0 ) {
+    cerr << "ERROR: AliPHOSSDigitizer::Init -> Could not obtain the Getter object !" << endl ; 
+    return ;
+  } 
+  
+  gime->PostSDigits( GetName(), GetTitle() ) ; 
 
-    if(fHeadersFile.IsNull())
-      fHeadersFile="galice.root" ;
+  TString sdname(GetName() );
+  sdname.Append(":") ;
+  sdname.Append(GetTitle() ) ;
+  SetName(sdname) ;
+  gime->PostSDigitizer(this) ;
+}
 
-    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") ;
-    }
-    
-    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 ;
-  }
+//____________________________________________________________________________ 
+void AliPHOSSDigitizer::InitParameters()
+{ 
+  fA             = 0;
+  fB             = 10000000.;
+  fPrimThreshold = 0.01 ;
+  fSDigitsInRun  = 0 ;
+  fSplitFile     = 0 ; 
 }
+
 //____________________________________________________________________________
 void AliPHOSSDigitizer::Exec(Option_t *option) 
 { 
   // Collects all hits in the same active volume into digit
-  
-  if(!fIsInitialized)
+  if( strcmp(GetName(), "") == 0 )
     Init() ;
+  
+  if (strstr(option, "print") ) {
+    Print("") ; 
+    return ; 
+  }
 
   if(strstr(option,"tim"))
     gBenchmark->Start("PHOSSDigitizer");
+
+  //Check, if this branch already exits
+  gAlice->GetEvent(0) ;
+
+  TString sdname(GetName()) ;
+  sdname.Remove(sdname.Index(GetTitle())-1) ;
   
-  fNevents = (Int_t) gAlice->TreeE()->GetEntries() ; 
-  
-  Int_t ievent ;
-  for(ievent = 0; ievent < fNevents; ievent++){
-    gAlice->GetEvent(ievent) ;
-    gAlice->SetEvent(ievent) ;
+  if(gAlice->TreeS() ) {
+    TObjArray * lob = static_cast<TObjArray*>(gAlice->TreeS()->GetListOfBranches()) ;
+    TIter next(lob) ; 
+    TBranch * branch = 0 ;  
+    Bool_t phosfound = kFALSE, sdigitizerfound = kFALSE ; 
     
-    if(gAlice->TreeH()==0){
-      cout << "AliPHOSSDigitizer: There is no Hit Tree" << endl;
-      return ;
+    while ( (branch = (static_cast<TBranch*>(next()))) && (!phosfound || !sdigitizerfound) ) {
+      TString thisName( GetName() ) ; 
+      TString branchName( branch->GetTitle() ) ; 
+      branchName.Append(":") ; 
+      if ( (strcmp(branch->GetName(), "PHOS")==0) && thisName.BeginsWith(branchName) )  
+       phosfound = kTRUE ;
+      else if ( (strcmp(branch->GetName(), "AliPHOSSDigitizer")==0) &&  thisName.BeginsWith(branchName) )
+       sdigitizerfound = kTRUE ; 
     }
     
-    //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();
+    if ( phosfound || sdigitizerfound ) {
+      cerr << "WARNING: AliPHOSSDigitizer::Exec -> SDigits and/or SDigitizer branch with name " << GetName() 
+          << " already exits" << endl ;
+      return ; 
+    }   
+  }  
+
+  AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ; 
+
+  Int_t nevents = (Int_t) gAlice->TreeE()->GetEntries() ; 
+  
+  Int_t ievent ;
+  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);
-      
-      Int_t i;
-      for ( i = 0 ; i < fHits->GetEntries() ; i++ ) {
-       AliPHOSHit * hit = (AliPHOSHit*)fHits->At(i) ;
+    //Now make SDigits from hits, for PHOS it is the same, so just copy    
 
+    Int_t Nprim =  (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 < 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() ) ) ;
-       
-       nSdigits++ ;  
+         new((*sdigits)[nSdigits]) AliPHOSDigit( -1              , hit->GetId(), 
+                                                  Digitize(hit->GetEnergy()), hit->GetTime()) ;
+       nSdigits++ ;    
        
-      } 
-      
-    } // loop over tracks
-    
-    fSDigits->Sort() ;
+      }
+
+    } // loop over iprim
     
-    nSdigits = fSDigits->GetEntriesFast() ;
-    fSDigits->Expand(nSdigits) ;
+    sdigits->Sort() ;
     
+    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;
-    
-    TObjArray * branches = gAlice->TreeS()->GetListOfBranches() ;
-    Int_t ibranch;
-    Bool_t phosNotFound = kTRUE ;
-    Bool_t sdigitizerNotFound = kTRUE ;
-    
-    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(!(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;
+      gAlice->MakeTree("S", fSplitFile);
     
     //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());
-      TBranch * subbr;
-      while ((subbr=(TBranch*)next())) {
-       subbr->SetFile(file);
-      }   
-      cwd->cd();
-    } 
+    TBranch * sdigitsBranch = gAlice->TreeS()->Branch("PHOS",&sdigits,bufferSize);
+    sdigitsBranch->SetTitle(sdname);
       
-    //second - SDigitizer
+    //Next - SDigitizer
     Int_t splitlevel = 0 ;
     AliPHOSSDigitizer * sd = this ;
-    sdigitizerBranch = gAlice->TreeS()->Branch("AliPHOSSDigitizer","AliPHOSSDigitizer",
+    TBranch * sdigitizerBranch = gAlice->TreeS()->Branch("AliPHOSSDigitizer","AliPHOSSDigitizer",
                                               &sd,bufferSize,splitlevel); 
-    sdigitizerBranch->SetTitle(fSDigitsTitle.Data());
-    if (file) {
-      sdigitizerBranch->SetFile(file);
-      TIter next( sdigitizerBranch->GetListOfBranches());
-      TBranch * subbr ;
-      while ((subbr=(TBranch*)next())) {
-       subbr->SetFile(file);
-      }   
-      cwd->cd();
-      delete file;
-    }
-
-    sdigitsBranch->Fill() ;
+    sdigitizerBranch->SetTitle(sdname);
+  
+    sdigitsBranch->Fill() ; 
     sdigitizerBranch->Fill() ;
-    gAlice->TreeS()->Write(0,TObject::kOverwrite) ;
+    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 ;
+        <<  gBenchmark->GetCpuTime("PHOSSDigitizer")/nevents << " seconds per event " << endl ;
     cout << endl ;
   }
   
   
 }
+
 //__________________________________________________________________
 void AliPHOSSDigitizer::SetSDigitsBranch(const char * title )
 {
   // Setting title to branch SDigits 
-  if(!fSDigitsTitle.IsNull())
-    cout << "AliPHOSSdigitizer: changing SDigits file from " <<fSDigitsTitle.Data() << " to " << title << endl ;
-  fSDigitsTitle=title ;
+
+  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 ){
+    cerr << "ERROR: AliPHOSSdigitizer::SetSDigitsBranch -> Cannot overwrite existing branch with title " << title << endl ;
+    return ;
+  }
+  
+  cout << "AliPHOSSdigitizer::SetSDigitsBranch -> Changing SDigits file from " << GetName() << " to " << title << endl ;
+
+  SetName(title) ; 
+    
+  // Post to the WhiteBoard
+  AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ; 
+  gime->PostSDigits( title, GetTitle()) ; 
 }
+
+//__________________________________________________________________
+void AliPHOSSDigitizer::SetSplitFile(const TString splitFileName) 
+{
+  // Diverts the SDigits in a file separate from the hits file
+  
+  TDirectory * cwd = gDirectory ;
+  
+  if ( !(gAlice->GetTreeSFileName() == splitFileName) ) {
+    if (gAlice->GetTreeSFile() ) 
+      gAlice->GetTreeSFile()->Close() ; 
+  }
+  
+  fSplitFile = gAlice->InitTreeFile("S",splitFileName.Data());
+  fSplitFile->cd() ; 
+  gAlice->Write(0, TObject::kOverwrite);
+  
+  TTree *treeE  = gAlice->TreeE();
+  if (!treeE) {
+    cerr << "ERROR: AliPHOSSDigitizer::SetSPlitFile -> No TreeE found "<<endl;
+    abort() ;
+  }      
+  
+  // copy TreeE
+    AliHeader *header = new AliHeader();
+    treeE->SetBranchAddress("Header", &header);
+    treeE->SetBranchStatus("*",1);
+    TTree *treeENew =  treeE->CloneTree();
+    treeENew->Write(0, TObject::kOverwrite);
+  
+
+  // copy AliceGeom
+    TGeometry *AliceGeom = static_cast<TGeometry*>(cwd->Get("AliceGeom"));
+    if (!AliceGeom) {
+      cerr << "ERROR: AliPHOSSDigitizer::SetSPlitFile -> AliceGeom was not found in the input file "<<endl;
+      abort() ;
+    }
+    AliceGeom->Write(0, TObject::kOverwrite);
+
+  gAlice->MakeTree("S",fSplitFile);
+  cwd->cd() ; 
+  cout << "INFO: AliPHOSSDigitizer::SetSPlitMode -> SDigits will be stored in " << splitFileName.Data() << endl ; 
+
+}
+
 //__________________________________________________________________
 void AliPHOSSDigitizer::Print(Option_t* option)const
 {
   // Prints parameters of SDigitizer
   cout << "------------------- "<< GetName() << " -------------" << endl ;
-  cout << "   Writing SDigitis to branch with title  " << fSDigitsTitle.Data() << endl ;
+  cout << "   Writing SDigits to branch with title  " << GetName() << endl ;
   cout << "   with digitization parameters  A = " << fA << endl ;
   cout << "                                 B = " << fB << endl ;
   cout << "   Threshold for Primary assignment= " << fPrimThreshold << endl ; 
@@ -336,38 +376,81 @@ void AliPHOSSDigitizer::Print(Option_t* option)const
 //__________________________________________________________________
 Bool_t AliPHOSSDigitizer::operator==( AliPHOSSDigitizer const &sd )const
 {
-  // SDigitizer are identical if the same threshold is in use
+  // 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 in the current pass of AliPHOSDigitizer
-  
-  cout << "AliPHOSSDigitizer: " << endl ;
-  cout << "       Number of entries in SDigits list  " << fSDigits->GetEntriesFast() << endl ;
+
+
+  AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ; 
+  TString sdname(GetName()) ;
+  sdname.Remove(sdname.Index(GetTitle())-1) ;
+  const TClonesArray * sdigits = gime->SDigits(sdname.Data()) ; 
+
+  cout << "AliPHOSSDigitiser: event " << gAlice->GetEvNumber() << endl ;
+  cout << "      Number of entries in SDigits list " << sdigits->GetEntriesFast() << endl ;
   cout << endl ;
-  
-  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;    
+    cout << "EMC sdigits " << endl ;
+    cout << "Digit Id    Amplitude     Index     Nprim  Primaries list " <<  endl;      
+    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()) && 
+        (((AliPHOSDigit * )  sdigits->At(index))->GetId() <= maxEmc) ; index++) {
+      digit = (AliPHOSDigit * )  sdigits->At(index) ;
+      if(digit->GetNprimary() == 0) continue;
+      cout << setw(6)  <<  digit->GetId() << "   "  <<         setw(10)  <<  digit->GetAmp() <<   "    "  
+          << setw(6)  <<  digit->GetIndexInList() << "    "   
+          << setw(5)  <<  digit->GetNprimary() <<"    ";
       
       Int_t iprimary;
       for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++)
-       cout << setw(5)  <<  digit->GetPrimary(iprimary+1) << "  ";
+       cout << setw(5)  <<  digit->GetPrimary(iprimary+1) << "    ";
       cout << endl;     
-    }
+    }    
+    cout << endl;
+  }
+
+  if(strstr(option,"all")||strstr(option,"CPV")){
     
+    //loop over CPV digits
+    AliPHOSDigit * digit;
+    cout << "CPV sdigits " << endl ;
+    cout << "Digit Id    Amplitude     Index     Nprim  Primaries list " <<  endl;      
+    Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ;
+    Int_t index ;
+    for (index = 0 ; index < sdigits->GetEntriesFast(); index++) {
+      digit = (AliPHOSDigit * )  sdigits->At(index) ;
+      if(digit->GetId() > maxEmc){
+       cout << setw(6)  <<  digit->GetId() << "   "  <<        setw(10)  <<  digit->GetAmp() <<   "    "  
+            << setw(6)  <<  digit->GetIndexInList() << "    "   
+            << setw(5)  <<  digit->GetNprimary() <<"    ";
+       
+       Int_t iprimary;
+       for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++)
+         cout << setw(5)  <<  digit->GetPrimary(iprimary+1) << "    ";
+       cout << endl;    
+      }    
+    }
   }
+
+}
+
+//____________________________________________________________________________ 
+void AliPHOSSDigitizer::UseHitsFrom(const char * filename)
+{
+  SetTitle(filename) ; 
+  Init() ; 
 }