]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TOF/AliTOFSDigitizer.cxx
Moving to the new VMC naming convention
[u/mrichter/AliRoot.git] / TOF / AliTOFSDigitizer.cxx
index b33fc4f4cdf5daec50965d4515b412a5be4ee76b..ae0f922c2d3be513cbcdf852a251fd274a56c10d 100644 (file)
@@ -13,6 +13,8 @@
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
+/* $Id$ */
+
 //_________________________________________________________________________
 // This is a TTask that constructs SDigits out of Hits
 // A Summable Digits is the "sum" of all hits in a pad
 // Use case: see AliTOFhits2sdigits.C macro in the CVS
 //////////////////////////////////////////////////////////////////////////////
 
-#include "TBenchmark.h"
-#include "TTask.h"
-#include "TTree.h"
-#include "TSystem.h"
-#include "TParticle.h"
-#include "TH1.h"
-#include "TFile.h"
-#include "TROOT.h"
-#include "TFolder.h"
-#include <TF1.h>
+
+#include <Riostream.h>
 #include <stdlib.h>
-#include <iostream.h>
-#include <fstream.h>
 
+#include <TBenchmark.h>
+#include <TF1.h>
+#include <TFile.h>
+#include <TFolder.h>
+#include <TH1.h>
+#include <TParticle.h>
+#include <TROOT.h>
+#include <TSystem.h>
+#include <TTask.h>
+#include <TTree.h>
+
+#include "AliDetector.h"
+#include "AliLoader.h"
+#include "AliRun.h"
+#include "AliRunLoader.h"
+#include "AliTOF.h"
+#include "AliTOFConstants.h"
 #include "AliTOFHitMap.h"
 #include "AliTOFSDigit.h"
-#include "AliTOFConstants.h"
+#include "AliTOFSDigitizer.h"
 #include "AliTOFhit.h"
-#include "AliTOF.h"
+#include "AliTOFhitT0.h"
 #include "AliTOFv1.h"
 #include "AliTOFv2.h"
 #include "AliTOFv3.h"
 #include "AliTOFv4.h"
-#include "AliTOFSDigitizer.h"
-#include "AliRun.h"
-#include "AliDetector.h"
-#include "AliMC.h"
-
 
 ClassImp(AliTOFSDigitizer)
 
@@ -58,6 +62,9 @@ ClassImp(AliTOFSDigitizer)
   AliTOFSDigitizer::AliTOFSDigitizer():TTask("AliTOFSDigitizer","") 
 {
   // ctor
+
+  fRunLoader     = 0 ;
+
   fEvent1=0;
   fEvent2=0;
   ftail    = 0;
@@ -88,8 +95,19 @@ ClassImp(AliTOFSDigitizer)
   InitParameters();
 
   // add Task to //root/Tasks folder
-  TTask * roottasks = (TTask*)gROOT->GetRootFolder()->FindObject("Tasks") ; 
-  roottasks->Add(this) ; 
+  fRunLoader = AliRunLoader::Open(HeaderFile);//open session and mount on default event folder
+  if (fRunLoader == 0x0)
+   {
+     Fatal("AliTOFSDigitizer","Event is not loaded. Exiting");
+     return;
+   }
+  AliLoader* gime = fRunLoader->GetLoader("TOFLoader");
+  if (gime == 0x0)
+   {
+     Fatal("AliTOFSDigitizer","Can not find TOF loader in event. Exiting.");
+     return;
+   }
+  gime->PostSDigitizer(this);
 }
 
 //____________________________________________________________________________ 
@@ -158,10 +176,18 @@ Double_t TimeWithTail(Double_t* x, Double_t* par)
 //____________________________________________________________________________
 void AliTOFSDigitizer::Exec(Option_t *verboseOption, Option_t *allEvents) { 
 
+  fRunLoader->LoadgAlice();
+  fRunLoader->LoadHeader();
+  fRunLoader->LoadKinematics();
+  gAlice = fRunLoader->GetAliRun();
+  
+  AliLoader* gime = fRunLoader->GetLoader("TOFLoader");
+  gime->LoadHits("read");
+  gime->LoadSDigits("recreate");
   if(strstr(verboseOption,"tim") || strstr(verboseOption,"all"))
     gBenchmark->Start("TOFSDigitizer");
 
-  AliTOF *TOF = (AliTOF *) gAlice->GetDetector ("TOF");
+  AliTOF *TOF = (AliTOF *) gAlice->GetDetector("TOF");
 
   if (!TOF) {
     Error("AliTOFSDigitizer","TOF not found");
@@ -178,6 +204,7 @@ void AliTOFSDigitizer::Exec(Option_t *verboseOption, Option_t *allEvents) {
     TOF->RecreateSDigitsArray();
   }
 
+  Int_t version=TOF->IsVersion();
 
   if (fEdgeTails) ftail = new TF1("tail",TimeWithTail,-2,2,3);
 
@@ -207,40 +234,43 @@ void AliTOFSDigitizer::Exec(Option_t *verboseOption, Option_t *allEvents) {
     Int_t nnoisesdigitsinEv=0;
     Int_t nsignalsdigitsinEv=0;
 
-    gAlice->GetEvent(ievent);
-    TTree *TH = gAlice->TreeH ();
+    fRunLoader->GetEvent(ievent);
+    TOF->SetTreeAddress();
+    TTree *TH = gime->TreeH ();
     if (!TH)
       return;
-    if (gAlice->TreeS () == 0)
-      gAlice->MakeTree ("S");
+    if (gime->TreeS () == 0)
+      gime->MakeTree ("S");
 
       
     //Make branches
     char branchname[20];
     sprintf (branchname, "%s", TOF->GetName ());
     //Make branch for digits
-    TOF->MakeBranch ("S");
+    TOF->MakeBranch("S");
     
     //Now made SDigits from hits
 
-    Int_t    vol[5];       // location for a digit
-    Float_t  digit[2];     // TOF digit variables
+
     TParticle *particle;
-    AliTOFhit *tofHit;
+    //AliTOFhit *tofHit;
     TClonesArray *TOFhits = TOF->Hits();
 
     // create hit map
     AliTOFHitMap *hitMap = new AliTOFHitMap(TOF->SDigits());
 
     // increase performances in terms of CPU time
-    TH->SetBranchStatus("*",0); // switch off all branches
-    TH->SetBranchStatus("TOF*",1); // switch on only TOF
+    //PH     TH->SetBranchStatus("*",0); // switch off all branches
+    //PH     TH->SetBranchStatus("TOF*",1); // switch on only TOF
+
+    TBranch * tofHitsBranch = TH->GetBranch("TOF");
 
     Int_t ntracks = static_cast<Int_t>(TH->GetEntries());
     for (Int_t track = 0; track < ntracks; track++)
     {
       gAlice->ResetHits();
-      TH->GetEvent(track);
+      //PH      TH->GetEvent(track);
+      tofHitsBranch->GetEvent(track);
       particle = gAlice->Particle(track);
       Int_t nhits = TOFhits->GetEntriesFast();
       // cleaning all hits of the same track in the same pad volume
@@ -255,17 +285,43 @@ void AliTOFSDigitizer::Exec(Option_t *verboseOption, Option_t *allEvents) {
 
       for (Int_t hit = 0; hit < nhits; hit++)
       {
-       tofHit = (AliTOFhit *) TOFhits->UncheckedAt(hit);
-       Int_t tracknum = tofHit->GetTrack();
-       vol[0] = tofHit->GetSector();
-       vol[1] = tofHit->GetPlate();
-
-       // selection case for sdigitizing only hits in a given plate of a given sector
-       if(thereIsNotASelection || (vol[0]==fSelectedSector && vol[1]==fSelectedPlate)){
-         
+       Int_t    vol[5];       // location for a digit
+       Float_t  digit[2];     // TOF digit variables
+       Int_t tracknum;
+       Float_t Xpad;
+       Float_t Zpad;
+       Float_t geantTime;
+
+       // fp: really sorry for this, it is a temporary trick to have
+       // track length too
+       if(version!=6){
+         AliTOFhit *tofHit = (AliTOFhit *) TOFhits->UncheckedAt(hit);
+         tracknum = tofHit->GetTrack();
+         vol[0] = tofHit->GetSector();
+         vol[1] = tofHit->GetPlate();
+         vol[2] = tofHit->GetStrip();
+         vol[3] = tofHit->GetPadx();
+         vol[4] = tofHit->GetPadz();
+         Xpad = tofHit->GetDx();
+         Zpad = tofHit->GetDz();
+         geantTime = tofHit->GetTof(); // unit [s]
+       } else {
+         AliTOFhitT0 *tofHit = (AliTOFhitT0 *) TOFhits->UncheckedAt(hit);
+         tracknum = tofHit->GetTrack();
+         vol[0] = tofHit->GetSector();
+         vol[1] = tofHit->GetPlate();
          vol[2] = tofHit->GetStrip();
          vol[3] = tofHit->GetPadx();
          vol[4] = tofHit->GetPadz();
+         Xpad = tofHit->GetDx();
+         Zpad = tofHit->GetDz();
+         geantTime = tofHit->GetTof(); // unit [s]
+       }
+
+       geantTime *= 1.e+09;  // conversion from [s] to [ns]
+           
+       // selection case for sdigitizing only hits in a given plate of a given sector
+       if(thereIsNotASelection || (vol[0]==fSelectedSector && vol[1]==fSelectedPlate)){
          
          Bool_t dummy=((tracknum==previousTrack) && (vol[0]==previousSector) && (vol[1]==previousPlate) && (vol[2]==previousStrip));
          
@@ -289,13 +345,9 @@ void AliTOFSDigitizer::Exec(Option_t *verboseOption, Option_t *allEvents) {
              nHitsFromPrim++;
            } // counts hits due to primary particles
            
-           Float_t Xpad = tofHit->GetDx();
-           Float_t Zpad = tofHit->GetDz();
            Float_t xStrip=AliTOFConstants::fgkXPad*(vol[3]-0.5-0.5*AliTOFConstants::fgkNpadX)+Xpad;
            Float_t zStrip=AliTOFConstants::fgkZPad*(vol[4]-0.5-0.5*AliTOFConstants::fgkNpadZ)+Zpad;
-           Float_t geantTime = tofHit->GetTof(); // unit [s]
-           geantTime *= 1.e+09;  // conversion from [s] to [ns]
-           
+
            //cout << "geantTime " << geantTime << " [ns]" << endl;
            Int_t nActivatedPads = 0, nFiredPads = 0;
            Bool_t isFired[4] = {kFALSE, kFALSE, kFALSE, kFALSE};
@@ -356,10 +408,10 @@ void AliTOFSDigitizer::Exec(Option_t *verboseOption, Option_t *allEvents) {
     
     delete hitMap;
       
-    gAlice->TreeS()->Reset();
-    gAlice->TreeS()->Fill();
+    gime->TreeS()->Reset();
+    gime->TreeS()->Fill();
     //gAlice->TreeS()->Write(0,TObject::kOverwrite) ;
-    gAlice->TreeS()->AutoSave();
+    gime->WriteSDigits("OVERWRITE");
 
     if(strstr(verboseOption,"all")){
       cout << "----------------------------------------" << endl;