]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PHOS/AliPHOSSDigitizer.cxx
New FMD parameters.
[u/mrichter/AliRoot.git] / PHOS / AliPHOSSDigitizer.cxx
index 8616449e2e356a37ade42ed5b55e882c801b5e41..4f4c8c828a7a4d3eef0d4706d8ca2ff826be40e7 100644 (file)
@@ -13,6 +13,7 @@
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
+
 /* $Id$ */
 
 //_________________________________________________________________________
@@ -76,26 +77,50 @@ ClassImp(AliPHOSSDigitizer)
 
            
 //____________________________________________________________________________ 
-  AliPHOSSDigitizer::AliPHOSSDigitizer():TTask("","") 
-{
+  AliPHOSSDigitizer::AliPHOSSDigitizer():TTask("","") {
   // ctor
-  fA             = 0;
-  fB             = 10000000.;
-  fPrimThreshold = 0.01 ;
-  fSDigitsInRun  = 0 ; 
+  InitParameters() ;
+  fDefaultInit = kTRUE ; 
 }
 
 //____________________________________________________________________________ 
 AliPHOSSDigitizer::AliPHOSSDigitizer(const char * headerFile, const char * sDigitsTitle):TTask(sDigitsTitle, headerFile)
 {
   // ctor
-  fA             = 0;
-  fB             = 10000000.;
-  fPrimThreshold = 0.01 ;
-  fSDigitsInRun  = 0 ;
+  InitParameters() ; 
   Init();
+  fDefaultInit = kFALSE ; 
 }
 
+//____________________________________________________________________________ 
+AliPHOSSDigitizer::~AliPHOSSDigitizer()
+{
+  // dtor
+  // 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()
@@ -109,7 +134,7 @@ void AliPHOSSDigitizer::Init()
   
   if( strcmp(GetTitle(), "") == 0 )
     SetTitle("galice.root") ;
-  
+
   AliPHOSGetter * gime = AliPHOSGetter::GetInstance(GetTitle(), GetName()) ;     
   if ( gime == 0 ) {
     cerr << "ERROR: AliPHOSSDigitizer::Init -> Could not obtain the Getter object !" << endl ; 
@@ -125,6 +150,16 @@ void AliPHOSSDigitizer::Init()
   gime->PostSDigitizer(this) ;
 }
 
+//____________________________________________________________________________ 
+void AliPHOSSDigitizer::InitParameters()
+{ 
+  fA             = 0;
+  fB             = 10000000.;
+  fPrimThreshold = 0.01 ;
+  fSDigitsInRun  = 0 ;
+  fSplitFile     = 0 ; 
+}
+
 //____________________________________________________________________________
 void AliPHOSSDigitizer::Exec(Option_t *option) 
 { 
@@ -153,10 +188,12 @@ void AliPHOSSDigitizer::Exec(Option_t *option)
     Bool_t phosfound = kFALSE, sdigitizerfound = kFALSE ; 
     
     while ( (branch = (static_cast<TBranch*>(next()))) && (!phosfound || !sdigitizerfound) ) {
-      if ( (strcmp(branch->GetName(), "PHOS")==0) && (strcmp(branch->GetTitle(), GetName())==0) ) 
+      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) && (strcmp(branch->GetTitle(), GetName())==0) ) 
+      else if ( (strcmp(branch->GetName(), "AliPHOSSDigitizer")==0) &&  thisName.BeginsWith(branchName) )
        sdigitizerfound = kTRUE ; 
     }
     
@@ -182,12 +219,12 @@ void AliPHOSSDigitizer::Exec(Option_t *option)
     
     //Now make SDigits from hits, for PHOS it is the same, so just copy    
 
-//******************** CHECK HERE
-//YS DOES NOT UNDERSTAND THE NEED FOR THE FOLLOWING LOOP
-//     Int_t itrack ;
-//     for (itrack=0; itrack < gAlice->GetNtrack(); itrack++){
-//       //=========== Get the PHOS branch from Hits Tree for the Primary track itrack
-//       gime->Track(itrack) ;
+    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)) ;
@@ -202,22 +239,24 @@ void AliPHOSSDigitizer::Exec(Option_t *option)
        nSdigits++ ;    
        
       }
-//    } // loop over tracks
+
+    } // loop over iprim
     
     sdigits->Sort() ;
     
     nSdigits = sdigits->GetEntriesFast() ;
     fSDigitsInRun += nSdigits ;  
     sdigits->Expand(nSdigits) ;
-//    Int_t i ;
+
+    Int_t i ;
     for (i = 0 ; i < nSdigits ; i++) { 
       AliPHOSDigit * digit = dynamic_cast<AliPHOSDigit *>(sdigits->At(i)) ; 
       digit->SetIndexInList(i) ;     
     }
-    
+
     if(gAlice->TreeS() == 0)
-       gAlice->MakeTree("S") ;
-        
+      gAlice->MakeTree("S", fSplitFile);
+    
     //First list of sdigits
     Int_t bufferSize = 32000 ;    
     TBranch * sdigitsBranch = gAlice->TreeS()->Branch("PHOS",&sdigits,bufferSize);
@@ -229,15 +268,16 @@ void AliPHOSSDigitizer::Exec(Option_t *option)
     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 ;
@@ -278,38 +318,47 @@ void AliPHOSSDigitizer::SetSDigitsBranch(const char * title )
 }
 
 //__________________________________________________________________
-void AliPHOSSDigitizer::SetSplitFile(const TString splitFileName) const
+void AliPHOSSDigitizer::SetSplitFile(const TString splitFileName) 
 {
   // Diverts the SDigits in a file separate from the hits file
   
   TDirectory * cwd = gDirectory ;
-  TFile * splitFile = gAlice->InitTreeFile("S",splitFileName.Data());
-  splitFile->cd() ; 
-  gAlice->Write();
+  
+  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<<"No TreeE found "<<endl;
+    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();
+    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<<"AliceGeom was not found in the input file "<<endl;
-    abort() ;
-  }
-  AliceGeom->Write();
+    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() ; 
-  gAlice->MakeTree("S",splitFile);
   cout << "INFO: AliPHOSSDigitizer::SetSPlitMode -> SDigits will be stored in " << splitFileName.Data() << endl ; 
+
 }
 
 //__________________________________________________________________