]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TOF/AliTOF.cxx
Fixes for report #63583: High CPU time spent in TMath::Erf
[u/mrichter/AliRoot.git] / TOF / AliTOF.cxx
index 1612c6de088c90414cfb1a48d25693e9410b00ef..5e63e0a72948efc44fdee23b35d1320e74c7389c 100644 (file)
@@ -12,7 +12,6 @@
  * about the suitability of this software for any purpose. It is          *
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
-
 /* $Id$ */
 
 ///////////////////////////////////////////////////////////////////////////////
 */
 //End_Html
 
-#include "TFile.h"
-#include "TFolder.h"
-#include "TROOT.h"
-#include "TTask.h"
-#include "TTree.h"
-#include "TVirtualMC.h"
+#include <TClonesArray.h>
+#include <TFile.h>
+#include <TFolder.h>
+#include <TROOT.h>
+#include <TTask.h>
+#include <TTree.h>
+#include <TVirtualMC.h>
+#include <TStopwatch.h>
 
 #include "AliConst.h"
 #include "AliLoader.h"
 #include "AliLog.h"
 #include "AliMC.h"
 #include "AliRun.h"
+#include "AliDAQ.h"
+#include "AliRawReader.h"
 
-#include "AliTOFDDLRawData.h"
+//#include "AliTOFDDLRawData.h"
 #include "AliTOFDigitizer.h"
 #include "AliTOFdigit.h"
 #include "AliTOFhitT0.h"
@@ -61,6 +64,8 @@
 #include "AliTOFSDigitizer.h"
 #include "AliTOFSDigit.h"
 #include "AliTOF.h"
+#include "AliTOFrawData.h"
+#include "AliTOFRawStream.h"
 
 class AliTOFcluster;
 
@@ -70,31 +75,50 @@ extern TVirtualMC *gMC;
 
 extern AliRun *gAlice;
 
 ClassImp(AliTOF)
+
 //_____________________________________________________________________________
-AliTOF::AliTOF()
+AliTOF::AliTOF():
+  fFGeom(0x0),
+  fDTask(0x0),
+  fReTask(0x0),
+  fSDigits(0x0),
+  fNSDigits(0),
+  fReconParticles(0x0),
+  fIdSens(-1),
+  fTZero(kFALSE),
+  fTOFHoles(kTRUE),
+  fTOFGeometry(0x0),
+  fTOFRawWriter(AliTOFDDLRawData())
 {
   //
   // Default constructor
   //
-  fFGeom  = 0x0;
-  fDTask  = 0x0;
-  fReTask = 0x0;
+
+  //by default all sectors switched on
+  for (Int_t ii=0; ii<18; ii++) fTOFSectors[ii]=0;
+
+  fDigits = 0;
   fIshunt   = 0;
-  fSDigits  = 0 ;
-  fNSDigits = 0;
-  fDigits   = 0 ;
-  fReconParticles = 0x0;
-  fName="TOF";
-  fTZero  = kFALSE;
-  fTOFGeometry = 0;
+  fName = "TOF";
+
 }
  
 //_____________________________________________________________________________
 AliTOF::AliTOF(const char *name, const char *title, Option_t *option)
-       : AliDetector(name,title)
+       : 
+  AliDetector(name,title),
+  fFGeom(0x0),
+  fDTask(0x0),
+  fReTask(0x0),
+  fSDigits(0x0),
+  fNSDigits(0),
+  fReconParticles(0x0),
+  fIdSens(-1),
+  fTZero(kFALSE),
+  fTOFHoles(kTRUE),
+  fTOFGeometry(0x0),
+  fTOFRawWriter(AliTOFDDLRawData())
 {
   //
   // AliTOF standard constructor
@@ -104,16 +128,16 @@ AliTOF::AliTOF(const char *name, const char *title, Option_t *option)
 
   // Initialization of hits, sdigits and digits array
   // added option for time zero analysis
-  fFGeom  = 0x0; //skowron
-  fDTask  = 0x0;
-  fReTask = 0x0;
-  fReconParticles= 0x0;
+  //skowron
   fTOFGeometry = new AliTOFGeometry();
 
+  //by default all sectors switched on
+  for (Int_t ii=0; ii<18; ii++) fTOFSectors[ii]=0;
+
   if (strstr(option,"tzero")){
     fHits   = new TClonesArray("AliTOFhitT0",  1000);
     fTZero = kTRUE;
-    AliWarning("tzero option requires AliTOFv4T0/AliTOFv5T0 as TOF version (check Your Config.C)");
+    //    AliWarning("tzero option requires AliTOFv4T0/AliTOFv5T0 as TOF version (check Your Config.C)");
   }else{
     fHits   = new TClonesArray("AliTOFhit",  1000);
     fTZero = kFALSE;
@@ -131,21 +155,15 @@ AliTOF::AliTOF(const char *name, const char *title, Option_t *option)
   fIshunt  = 0;
   fSDigits = new TClonesArray("AliTOFSDigit", 1000);
   fDigits  = new TClonesArray("AliTOFdigit",  1000);
-  fNSDigits = 0;
-
-  fFGeom = 0x0;
-  fDTask = 0x0;
-  fReTask = 0x0;
-  fReconParticles = 0x0;
 
   //
   // Digitization parameters
   //
   // (Transfer Functions to be inserted here)
   //
-  SetMarkerColor(7);
-  SetMarkerStyle(2);
-  SetMarkerSize(0.4);
+  //PH  SetMarkerColor(7);
+  //PH  SetMarkerStyle(2);
+  //PH  SetMarkerSize(0.4);
 
 // Strip Parameters
   //fGapA    =   4.; //cm  Gap beetween tilted strip in A-type plate
@@ -157,28 +175,23 @@ AliTOF::AliTOF(const char *name, const char *title, Option_t *option)
 
 }
 
-//_____________________________________________________________________________
-AliTOF::AliTOF(const AliTOF &source)
-  :AliDetector()
+//____________________________________________________________________________
+void AliTOF::SetTOFSectors(Int_t * const sectors)
 {
-  // copy constructor
-
-  this->fReconParticles=source.fReconParticles;
-  this->fSDigits=source.fSDigits;
-  this->fTOFGeometry=source.fTOFGeometry;
+  // Setter for partial/full TOF configuration
 
+  for(Int_t isec=0;isec<18;isec++){
+    fTOFSectors[isec]=sectors[isec];
+  }
 }
-
-//_____________________________________________________________________________
-AliTOF& AliTOF::operator=(const AliTOF &source)
+//____________________________________________________________________________
+void AliTOF::GetTOFSectors(Int_t *sectors) const
 {
-  // ass. op.
-
-  this->fReconParticles=source.fReconParticles;
-  this->fSDigits=source.fSDigits;
-  this->fTOFGeometry=source.fTOFGeometry;
-  return *this;
+  // Getter for partial/full TOF configuration
 
+  for(Int_t isec=0;isec<18;isec++){
+    sectors[isec]=fTOFSectors[isec];
+  }
 }
 
 //_____________________________________________________________________________
@@ -288,7 +301,7 @@ void AliTOF::AddT0Hit(Int_t track, Int_t *vol, Float_t *hits)
 }
 
 //_____________________________________________________________________________
-void AliTOF::AddDigit(Int_t *tracks, Int_t *vol, Float_t *digits)
+void AliTOF::AddDigit(Int_t *tracks, Int_t *vol, Int_t *digits)
 {
   //
   // Add a TOF digit
@@ -299,7 +312,7 @@ void AliTOF::AddDigit(Int_t *tracks, Int_t *vol, Float_t *digits)
 }
 
 //_____________________________________________________________________________
-void AliTOF::AddSDigit(Int_t tracknum, Int_t *vol, Float_t *digits)
+void AliTOF::AddSDigit(Int_t tracknum, Int_t *vol, Int_t *digits)
 {
      
 //
@@ -373,7 +386,16 @@ void AliTOF::CreateGeometry()
 
   Float_t xTof, yTof;
 
-  if (IsVersion()==7) {
+  if (IsVersion()==8) {
+
+    xTof = 124.5;//fTOFGeometry->StripLength()+2.*(0.3+0.03); // cm,  x-dimension of FTOA volume
+    yTof = fTOFGeometry->Rmax()-fTOFGeometry->Rmin(); // cm,  y-dimension of FTOA volume
+    Float_t zTof = fTOFGeometry->ZlenA();             // cm,  z-dimension of FTOA volume
+    
+    //  TOF module internal definitions
+    TOFpc(xTof, yTof, zTof);
+
+  } else if (IsVersion()==7) {
 
     xTof = 124.5;//fTOFGeometry->StripLength()+2.*(0.3+0.03); // cm,  x-dimension of FTOA volume
     yTof = fTOFGeometry->Rmax()-fTOFGeometry->Rmin(); // cm,  y-dimension of FTOA volume
@@ -431,15 +453,6 @@ void AliTOF::DrawModule() const
   gMC->Gdopt("hide","off");
 }
 
-//_____________________________________________________________________________
-Int_t AliTOF::DistancetoPrimitive(Int_t , Int_t )
-{
-  //
-  // Returns distance from mouse pointer to detector, default version
-  //
-  return 9999;
-}
-
 //___________________________________________
 void AliTOF::ResetHits ()
 {
@@ -476,7 +489,7 @@ void AliTOF::Init()
   /*
   // Save the geometry
   TDirectory* saveDir = gDirectory;
-  gAlice->GetRunLoader()->CdGAFile();
+  AliRunLoader::Instance()->CdGAFile();
   fTOFGeometry->Write("TOFGeometry");
   saveDir->cd();
   */
@@ -565,10 +578,16 @@ void AliTOF::Hits2SDigits()
 //  AliInfo("Start...");
   
   AliRunLoader * rl = fLoader->GetRunLoader();
+  AliDebug(2,"Initialized runLoader");
   AliTOFSDigitizer sd((rl->GetFileName()).Data());
-  ToAliDebug(1, sd.Print(""));
+  AliDebug(2,"Initialized TOF sdigitizer");
+  //ToAliDebug(1, sd.Print(""));
+  //AliInfo("ToAliDebug");
 
-  sd.Exec("") ;
+  //sd.Exec("all") ;
+  sd.Exec("partial") ;
+
+  AliDebug(2,"I am sorting from AliTOF class");
 
 }
 
@@ -580,10 +599,9 @@ void AliTOF::Hits2SDigits(Int_t evNumber1, Int_t evNumber2)
 //
 
   if ((evNumber2-evNumber1)==1) 
-      AliDebug(1, Form("I am making sdigits for the %dth event", evNumber1))
-  else if ((evNumber2-evNumber1)>1)
-      AliDebug(1, Form("I am making sdigits for the events from the " 
-                      "%dth to the %dth", evNumber1, evNumber2-1));
+    AliDebug(1, Form("I am making sdigits for the %dth event", evNumber1));
+  if ((evNumber2-evNumber1)>1)
+    AliDebug(1, Form("I am making sdigits for the events from the %dth to the %dth", evNumber1, evNumber2-1));
  
   AliRunLoader * rl = fLoader->GetRunLoader();
   AliTOFSDigitizer sd((rl->GetFileName()).Data(),evNumber1,evNumber2) ;
@@ -596,11 +614,13 @@ void AliTOF::Hits2SDigits(Int_t evNumber1, Int_t evNumber2)
 //___________________________________________________________________________
 AliDigitizer* AliTOF::CreateDigitizer(AliRunDigitizer* manager) const
 {
+  AliDebug(2,"I am creating the TOF digitizer");
   return new AliTOFDigitizer(manager);
 }
 
 //___________________________________________________________________________
-Bool_t AliTOF::CheckOverlap(Int_t* vol, Float_t* digit,Int_t Track)
+Bool_t AliTOF::CheckOverlap(const Int_t * const vol,
+                           Int_t* digit,Int_t Track)
 {
 //
 // Checks if 2 or more hits belong to the same pad.
@@ -624,8 +644,8 @@ Bool_t AliTOF::CheckOverlap(Int_t* vol, Float_t* digit,Int_t Track)
       if (vol[i]!=vol2[i]) idem=kFALSE;}
 
     if (idem){  // same pad fired
-      Float_t tdc2 = digit[0];
-      Float_t tdc1 = currentDigit->GetTdc();
+      Int_t tdc2 = digit[0];
+      Int_t tdc1 = currentDigit->GetTdc();
 
       // we separate two digits on the same pad if
       // they are separated in time by at least 25 ns
@@ -645,7 +665,7 @@ Bool_t AliTOF::CheckOverlap(Int_t* vol, Float_t* digit,Int_t Track)
        overlap = kTRUE;
        return overlap;
       } else 
-               overlap= kFALSE;
+       overlap= kFALSE;
 
     } // close if (idem) -> two digits on the same TOF pad
 
@@ -660,6 +680,9 @@ void AliTOF::Digits2Raw()
 // Starting from the TOF digits, writes the Raw Data objects
 //
 
+  TStopwatch stopwatch;
+  stopwatch.Start();
+
   fLoader->LoadDigits();
 
   TTree* digits = fLoader->TreeD();
@@ -668,22 +691,24 @@ void AliTOF::Digits2Raw()
     return;
   }
   
-  //AliRunLoader *rl = AliRunLoader::Open("galice.root",AliConfig::GetDefaultEventFolderName(),"read");
-  fRunLoader->CdGAFile();
-  TFile *in=(TFile*)gFile;
-  in->cd();
-  AliTOFGeometry *geometry  = (AliTOFGeometry*)in->Get("TOFgeometry");
-
-  AliTOFDDLRawData rawWriter(geometry);
   //AliTOFDDLRawData rawWriter;
-  rawWriter.SetVerbose(0);
+  fTOFRawWriter.Clear();
+  fTOFRawWriter.SetVerbose(0);
+  if (fTOFRawWriter.GetPackedAcquisitionMode()) {
+    if(fTOFRawWriter.GetMatchingWindow()>8192)
+      AliWarning(Form("You are running in packing mode and the matching window is %.2f ns, i.e. greater than 199.8848 ns",
+                     fTOFRawWriter.GetMatchingWindow()*AliTOFGeometry::TdcBinWidth()*1.e-03));
+  }
   
-  AliInfo("Formatting raw data for TOF");
+  AliDebug(1,"Formatting raw data for TOF");
   digits->GetEvent(0);
-  rawWriter.RawDataTOF(digits->GetBranch("TOF"));  
+  fTOFRawWriter.RawDataTOF(digits->GetBranch("TOF"));  
 
   fLoader->UnloadDigits();
   
+  AliDebug(1, Form("Execution time to write TOF raw data : R:%.2fs C:%.2fs",
+                  stopwatch.RealTime(),stopwatch.CpuTime()));
+
 }
 
 //____________________________________________________________________________
@@ -692,8 +717,7 @@ void AliTOF::RecreateSDigitsArray() {
 // delete TClonesArray fSDigits and create it again
 //  needed for backward compatability with PPR test production
 //
-  delete fSDigits;
-  fSDigits       = new TClonesArray("AliTOFSDigit",  1000);
+  fSDigits->Clear();
 }
 //____________________________________________________________________________
 void AliTOF::CreateSDigitsArray() {
@@ -703,3 +727,58 @@ void AliTOF::CreateSDigitsArray() {
 //
   fSDigits       = new TClonesArray("AliTOFSDigit",  1000);
 }
+//____________________________________________________________________________
+Bool_t AliTOF::Raw2SDigits(AliRawReader* rawReader)
+{
+  //
+  // Converts raw data to sdigits for TOF
+  //
+
+  TStopwatch stopwatch;
+  stopwatch.Start();
+
+  if(!GetLoader()->TreeS()) {MakeTree("S");  MakeBranch("S");}
+  //TClonesArray &aSDigits = *fSDigits;
+
+  AliTOFRawStream tofRawStream = AliTOFRawStream();
+  tofRawStream.Raw2SDigits(rawReader, fSDigits);
+
+  GetLoader()->TreeS()->Fill(); GetLoader()->WriteSDigits("OVERWRITE");//write out sdigits
+  Int_t nSDigits = fSDigits->GetEntries();
+
+  ResetSDigits();
+
+  AliDebug(1, Form("Got %d TOF sdigits", nSDigits));
+  AliDebug(1, Form("Execution time to read TOF raw data and fill TOF sdigit tree : R:%.2fs C:%.2fs",
+                  stopwatch.RealTime(),stopwatch.CpuTime()));
+
+  return kTRUE;
+
+}
+
+//____________________________________________________________________________
+void AliTOF::Raw2Digits(AliRawReader* rawReader)
+{
+  //
+  // Converts raw data to digits for TOF
+  //
+
+  TStopwatch stopwatch;
+  stopwatch.Start();
+
+  if(!GetLoader()->TreeD()) {MakeTree("D");  MakeBranch("D");}
+  //TClonesArray &aDigits = *fDigits;
+
+  AliTOFRawStream tofRawStream = AliTOFRawStream();
+  tofRawStream.Raw2Digits(rawReader, fDigits);
+
+  GetLoader()->TreeD()->Fill(); GetLoader()->WriteDigits("OVERWRITE");//write out digits
+  Int_t nDigits = fDigits->GetEntries();
+
+  ResetDigits();
+
+  AliDebug(1, Form("Got %d TOF digits", nDigits));
+  AliDebug(1, Form("Execution time to read TOF raw data and fill TOF digit tree : R:%.2fs C:%.2fs",
+                  stopwatch.RealTime(),stopwatch.CpuTime()));
+
+}