]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TOF/AliTOFMerger.cxx
Correct log field
[u/mrichter/AliRoot.git] / TOF / AliTOFMerger.cxx
index 14f8c74230fdf5355d4af2ac86f7974a4202ec6d..9c8144efd2094ab67b1157ad02780aa871dc8a8d 100644 (file)
@@ -13,7 +13,6 @@
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-
 #include <TTree.h> 
 #include <TVector.h>
 #include <TObjArray.h>
@@ -39,22 +38,37 @@ ClassImp(AliTOFMerger)
 //___________________________________________
   AliTOFMerger::AliTOFMerger() 
 {
-// Default constructor    
+// Default ctor    
+    fNDigits = 0;
     fEvNrSig = 0;
     fEvNrBgr = 0;
     fMerge =kDigitize;
-    fFnBgr   = 0;
+    fDigits = 0;
+    fSDigits =0;
+    fFnBgr = 0;
+    fFnSig = 0;
+    fBgrFile = 0;
 }
 
 //------------------------------------------------------------------------
 AliTOFMerger::~AliTOFMerger()
 {
-// Destructor
+// Dtor
   if(fSDigits)  {
     fSDigits->Delete();
     delete fSDigits ;
     fSDigits = 0;
   }
+  delete fBgrFile;
+  fBgrFile = 0;
+  if(fFnBgr) {
+    delete[] fFnBgr;
+    fFnBgr = 0;
+  }
+  if(fFnSig) {
+    delete[] fFnSig;
+    fFnSig = 0;
+  }
 }
 
 
@@ -81,8 +95,103 @@ TFile* AliTOFMerger::InitBgr()
 //------------------------------------------------------------------------
 void AliTOFMerger::Digitise()
 {
+// as in FMD
+// keep galice.root for signal and name differently the file for 
+// background when add! otherwise the track info for signal will be lost !
+
+
 
 #ifdef DEBUG
   cout<<"ALiTOFMerger::>SDigits2Digits start...\n";
 #endif
+
+  AliTOF* TOF = (AliTOF *) gAlice->GetDetector("TOF") ;
+
+
+  TFile *f1 =0;
+  TTree *TK = gAlice->TreeK();
+  if (TK) f1 = TK->GetCurrentFile();
+
+  gAlice->GetEvent(fEvNrSig) ;
+  
+  if(gAlice->TreeD() == 0)     
+    gAlice->MakeTree("D") ;
+  gAlice->TreeD()->Reset();
+
+  // read and write digits for signal
+   ReadWriteDigit(fEvNrSig);
+
+   if(fMerge){ 
+     // bgr file
+    fBgrFile->cd();
+    // gAlice->TreeS()->Reset();
+    gAlice = (AliRun*)fBgrFile->Get("gAlice");
+    ReadWriteDigit(fEvNrBgr);
+   } //if merge
+
+
+  f1->cd();
+   
+  //Make branch for digits
+  TOF->MakeBranch("D");
+
+  gAlice->TreeD()->Reset();
+  gAlice->TreeD()->Fill();
+  
+  fDigits   = TOF->Digits();
+  
+  gAlice->TreeD()->Write(0,TObject::kOverwrite) ;
+  
+  gAlice->ResetDigits();
+
 }
+
+//---------------------------------------------------------------------
+
+void AliTOFMerger::ReadWriteDigit(Int_t iEvNum)
+{
+//
+// Read Sdigits from the current file and write them in the TreeD
+//
+  AliTOFdigit* tofsdigit;
+  
+  AliTOF * tofinfile = (AliTOF *) gAlice->GetDetector("TOF") ;
+  
+  gAlice->GetEvent(iEvNum) ;
+  if(gAlice->TreeS()==0) {
+    cout<<" TreeS==0 -> return"<<gAlice->TreeS()<<endl; 
+    return ;}
+  
+  Int_t ndig, k;
+  Int_t    tracks[3];    // track info
+  Int_t    vol[5];       // location for a digit
+  Float_t  digit[2];     // TOF digit variables
+
+  gAlice->ResetDigits();
+  gAlice->TreeS()->GetEvent(iEvNum);
+  TClonesArray * TOFdigits   = tofinfile->SDigits();
+  
+  ndig=TOFdigits->GetEntries();
+
+  for (k=0; k<ndig; k++) {
+    tofsdigit= (AliTOFdigit*) TOFdigits->UncheckedAt(k);
+
+       tracks[0] = tofsdigit->GetTrack(0);
+       tracks[1] = tofsdigit->GetTrack(1);
+       tracks[2] = tofsdigit->GetTrack(2);
+
+       vol[0] = tofsdigit->GetSector();
+       vol[1] = tofsdigit->GetPlate();
+       vol[2] = tofsdigit->GetStrip();
+       vol[3] = tofsdigit->GetPadx();
+       vol[4] = tofsdigit->GetPadz();
+
+       digit[0] = tofsdigit->GetTdc();
+       digit[1] = tofsdigit->GetAdc();
+
+       new ((*fDigits)[fNDigits++]) AliTOFdigit(tracks, vol, digit);
+  } // end loop on sdigits in the current file
+}
+
+
+