]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TOF/AliTOFT0.cxx
Changed AliRunLoader::GetRunLoader() into AliRunLoader::Instance()
[u/mrichter/AliRoot.git] / TOF / AliTOFT0.cxx
index c87306faf63d012c2196b94126581742e4173a0b..641023bafed4e9b72dfc7670e4ea904e72ac6243 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
+/* $Id$ */
+
 //_________________________________________________________________________
+//
 // This is a TTask that made the calculation of the Time zero using TOF.
-// Description: The algorithm used to calculate the time zero of interaction
-// using TOF detector is the following.
-// We select in the MonteCarlo some primary particles - or tracks in the following - 
-// that strike the TOF detector (the larger part are pions, kaons or protons). 
-// We choose a set of 10 selected tracks, for each track You have the length
-// of the track when the TOF is reached (a standard TOF hit does not contain this
-// additional information, this is the reason why we implemented a new time zero 
-// dedicated TOF hit class AliTOFhitT0; in order to store this type of hit You 
-// have to use the AliTOFv4T0 as TOF class in Your Config.C. In AliTOFv4T0 the 
-// StepManager was modified in order to fill the TOF hit branch with this type 
-// of hits; in fact the AliTOF::AddT0Hit is called rather that the usual AliTOF::AddHit), 
-// the momentum at generation (from TreeK) and the time of flight
-// given by the TOF detector.
-// (Observe that the ctor of the AliTOF class, when the AliTOFv4T0 class is used, is called
-// with the "tzero" option: it is in order create the fHits TClonesArray filled with
-// AliTOFhitT0 objects, rather than with normal AliTOFhit)
-// Then Momentum and time of flight for each track are smeared according to 
-// known experimental resolution (all sources of error have been token into account).
-// Let consider now only one set of 10 tracks (the algorithm is the same for all sets).
-// Assuming the (mass) hypothesis that each track can be AUT a pion, AUT a kaon, AUT a proton,
-// we consider all the 3 at 10 possible cases. 
+// Description: The algorithm used to calculate the time zero of
+// interaction using TOF detector is the following.
+// We select in the MonteCarlo some primary particles - or tracks in
+// the following - that strike the TOF detector (the larger part are
+// pions, kaons or protons).
+// We choose a set of 10 selected tracks, for each track You have the
+// length of the track when the TOF is reached (a standard TOF hit
+// does not contain this additional information, this is the reason
+// why we implemented a new time zero dedicated TOF hit class
+// AliTOFhitT0; in order to store this type of hit You have to use the
+// AliTOFv4T0 as TOF class in Your Config.C. In AliTOFv4T0 the
+// StepManager was modified in order to fill the TOF hit branch with
+// this type of hits; in fact the AliTOF::AddT0Hit is called rather
+// that the usual AliTOF::AddHit), the momentum at generation (from
+// TreeK) and the time of flight given by the TOF detector.
+// (Observe that the ctor of the AliTOF class, when the AliTOFv4T0
+// class is used, is called with the "tzero" option: it is in order
+// create the fHits TClonesArray filled with AliTOFhitT0 objects,
+// rather than with normal AliTOFhit)
+// Then Momentum and time of flight for each track are smeared
+// according to known experimental resolution (all sources of error
+// have been token into account).
+// Let consider now only one set of 10 tracks (the algorithm is the
+// same for all sets).
+// Assuming the (mass) hypothesis that each track can be AUT a pion,
+// AUT a kaon, AUT a proton, we consider all the 3 at 10 possible
+// cases.
 // For each track in each (mass) configuration
-// (a configuration can be e.g. pion/pion/kaon/proton/pion/proton/kaon/kaon/pion/pion)
-// we calculate the time zero (we know in fact the velocity of the track after 
-// the assumption about its mass, the time of flight given by the TOF, and the 
-// corresponding path travelled till the TOF detector). Then for each mass configuration we have
-// 10 time zero and we can calculate the ChiSquare for the current configuration using the 
-// weighted mean over all 10 time zero.
-// We call the best assignment the mass configuration that gives the minimum value of the ChiSquare. 
-// We plot the weighted mean over all 10 time zero for the best assignment, 
-// the ChiSquare for the best assignment and the corresponding confidence level.
-// The strong assumption is the MC selection of primary particles. It will be introduced
-// in the future also some more realistic simulation about this point. 
+// (a configuration can be
+// e.g. pion/pion/kaon/proton/pion/proton/kaon/kaon/pion/pion)
+// we calculate the time zero (we know in fact the velocity of the
+// track after the assumption about its mass, the time of flight given
+// by the TOF, and the corresponding path travelled till the TOF
+// detector). Then for each mass configuration we have 10 time zero
+// and we can calculate the ChiSquare for the current configuration
+// using the weighted mean over all 10 time zero.
+// We call the best assignment the mass configuration that gives the
+// minimum value of the ChiSquare.
+// We plot the weighted mean over all 10 time zero for the best
+// assignment, the ChiSquare for the best assignment and the
+// corresponding confidence level.
+// The strong assumption is the MC selection of primary particles. It
+// will be introduced in the future also some more realistic
+// simulation about this point.
+//
 // Use case:
 // root [0] AliTOFT0 * tzero = new AliTOFT0("galice.root")
 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
 // root [2] tzero->ExecuteTask("tim")
 //             // available parameters:
 //             tim - print benchmarking information
-//             all - print usefull informations about the number of misidentified tracks 
-//                   and a comparison about the true configuration (known from MC) and the best
+//             all - print usefull informations about the number of
+//                   misidentified tracks and a comparison about the
+//                   true configuration (known from MC) and the best
 //                   assignment
+//
 //-- Author: F. Pierella
-//////////////////////////////////////////////////////////////////////////////
+//
+//_________________________________________________________________________
+
+#include <TCanvas.h>
+#include <TClonesArray.h>
+#include <TFile.h>
+//#include <TFolder.h>
+#include <TFrame.h>
+#include <TH1.h>
+#include <TParticle.h>
+#include <TBenchmark.h>
+#include <TTask.h>
+#include <TTree.h>
+#include <TRandom.h>
+#include <TROOT.h>
+
+#include "AliMC.h"
+#include "AliRun.h"
 
-#include "AliTOFT0.h"
 #include "AliTOFhitT0.h"
+#include "AliTOFT0.h"
 #include "AliTOF.h"
-#include "AliTOFv4T0.h"
-#include "AliRun.h"
-#include "AliDetector.h"
-#include "AliMC.h"
 
-#include "TH1.h"
-#include "TFile.h"
-#include "TTask.h"
-#include "TTree.h"
-#include "TSystem.h"
-#include "TCanvas.h"
-#include "TFrame.h"
-#include "TROOT.h"
-#include "TFolder.h"
-#include "TBenchmark.h"
-#include "TParticle.h"
-#include "TClonesArray.h"
-#include <stdlib.h>
-#include <iostream.h>
-#include <fstream.h>
-#include <iomanip.h>
+extern TROOT *gROOT;
+extern TRandom *gRandom;
+extern TBenchmark *gBenchmark;
+
+extern AliRun *gAlice;
 
 ClassImp(AliTOFT0)
 
 //____________________________________________________________________________ 
-  AliTOFT0::AliTOFT0():TTask("AliTOFT0","") 
+AliTOFT0::AliTOFT0():
+  TTask("AliTOFT0",""),
+  fNevents(0),
+  fTimeResolution(0),
+  fLowerMomBound(0),
+  fUpperMomBound(0),
+  fT0File(""),
+  fHeadersFile("")
 {
   // ctor
-  fNevents = 0 ;
 }
            
 //____________________________________________________________________________ 
-  AliTOFT0::AliTOFT0(char* headerFile, Int_t nEvents):TTask("AliTOFT0","") 
+AliTOFT0::AliTOFT0(char* headerFile, Int_t nEvents):
+  TTask("AliTOFT0",""), 
+  fNevents(nEvents),
+  fTimeResolution(1.2e-10),
+  fLowerMomBound(1.5),
+  fUpperMomBound(2.),
+  fT0File(""),
+  fHeadersFile(headerFile)
 {
-  fNevents=nEvents ; // Number of events for which calculate the T0, 
+  //
+  //
+  //
+
+  //fNevents=nEvents ; // Number of events for which calculate the T0, 
                      // default 0: it means all evens in current file
-  fLowerMomBound=1.5; // [GeV/c] default value
-  fUpperMomBound=2. ; // [GeV/c] default value
-  fTimeResolution   = 1.2e-10; // 120 ps by default    
-  fHeadersFile = headerFile ;
+  //fLowerMomBound=1.5; // [GeV/c] default value
+  //fUpperMomBound=2. ; // [GeV/c] default value
+  //fTimeResolution   = 1.2e-10; // 120 ps by default  
+  //fHeadersFile = headerFile ;
 
   TFile * file = (TFile*) gROOT->GetFile(fHeadersFile.Data() ) ;
 
@@ -121,6 +157,21 @@ ClassImp(AliTOFT0)
   roottasks->Add(this) ; 
 }
 
+//____________________________________________________________________________ 
+AliTOFT0::AliTOFT0(const AliTOFT0 & tzero):
+  TTask("AliTOFT0",""),
+  fNevents(0),
+  fTimeResolution(0),
+  fLowerMomBound(0),
+  fUpperMomBound(0),
+  fT0File(""),
+  fHeadersFile("")
+{
+  // copy ctr
+
+( (AliTOFT0 &)tzero ).Copy(*this);
+}
+
 //____________________________________________________________________________ 
   AliTOFT0::~AliTOFT0()
 {
@@ -209,53 +260,60 @@ void AliTOFT0::Exec(Option_t *option)
   Float_t chisquare=999.;
   Float_t tracktoflen[10]={0.,0.,0.,0.,0.,0.,0.,0.,0.,0.};
 
-  AliTOF *TOF = (AliTOF *) gAlice->GetDetector ("TOF");
+  AliTOF *detTOF = (AliTOF *) gAlice->GetDetector ("TOF");
 
-  if (!TOF) {
+  if (!detTOF) {
     Error("AliTOFT0","TOF not found");
     return;
   }
 
   if(strstr(option,"all")){
-    cout << "Selecting primary tracks with momentum between " << fLowerMomBound << " GeV/c and " << fUpperMomBound << " GeV/c" << endl;
-    cout << "Memorandum: 0 means PION | 1 means KAON | 2 means PROTON" << endl;
+    AliInfo(Form("Selecting primary tracks with momentum between %d GeV/c and %d GeV/c",  fLowerMomBound, fUpperMomBound));
+    AliInfo("Memorandum: 0 means PION | 1 means KAON | 2 means PROTON")
   }
 
-  if (fNevents == 0) fNevents = (Int_t) gAlice->TreeE()->GetEntries();
+  if (fNevents == 0) fNevents = (Int_t) AliRunLoader::Instance()->TreeE()->GetEntries();
 
   for (Int_t ievent = 0; ievent < fNevents; ievent++) {
     gAlice->GetEvent(ievent);
-    TTree *TH = gAlice->TreeH ();
-    if (!TH)
+    TTree *hitTree = detTOF->GetLoader()->TreeH ();
+    if (!hitTree)
       return;
     TParticle*    particle;
     AliTOFhitT0*  tofHit;
-    TClonesArray* TOFhits = TOF->Hits();
+    TClonesArray* tofHits = detTOF->Hits();
 
     Int_t lasttrack=-1;
     Int_t nset=0;
+
+    hitTree->SetBranchStatus("*",0); // switch off all branches
+    hitTree->SetBranchStatus("TOF*",1); // switch on only TOF
+
     // Start loop on primary tracks in the hits containers
 
-    Int_t ntracks = static_cast<Int_t>(TH->GetEntries());
+    Int_t ntracks = static_cast<Int_t>(hitTree->GetEntries());
     for (Int_t track = 0; track < ntracks; track++)
     {
       if(nset>=5) break; // check on the number of set analyzed
       
-      gAlice->ResetHits();
-      TH->GetEvent(track);
-      particle = gAlice->Particle(track);
-      Int_t nhits = TOFhits->GetEntriesFast();
+      gAlice->GetMCApp()->ResetHits();
+      hitTree->GetEvent(track);
+
+      AliMC *mcApplication = (AliMC*)gAlice->GetMCApp();
+
+      particle = mcApplication->Particle(track);
+      Int_t nhits = tofHits->GetEntriesFast();
 
       for (Int_t hit = 0; hit < nhits; hit++)
       {
-       tofHit = (AliTOFhitT0 *) TOFhits->UncheckedAt(hit);
+       tofHit = (AliTOFhitT0 *) tofHits->UncheckedAt(hit);
        ipart    = tofHit->GetTrack();
        // check to discard the case when the same particle is selected more than one
        // time 
 
        if (ipart != ipartold){
          
-         particle = (TParticle*)gAlice->Particle(ipart);
+         particle = (TParticle*)gAlice->GetMCApp()->Particle(ipart);
          
          Float_t idealtime=tofHit->GetTof();
          //       Float_t time=idealtime;
@@ -279,7 +337,7 @@ void AliTOFT0::Exec(Option_t *option)
            timeofflight[index]=time;
            tracktoflen[index]=toflen;
            momentum[index]=mom;
-           //      cout << timeofflight[index] << " " << tracktoflen[index] << " " << momentum[index] << endl;
+           //AliInfo(Form(" %d  %d  %d ", timeofflight[index], tracktoflen[index], momentum[index]));
            switch (abspdg) {
            case 211:
              truparticle[index]=0;
@@ -300,7 +358,7 @@ void AliTOFT0::Exec(Option_t *option)
            lasttrack=track;
            istop=0;
            selected=0;
-           //cout << "starting t0 calculation for current set" << endl;
+           //AliInfo("starting t0 calculation for current set");
            for (Int_t i1=0; i1<3;i1++) {
              beta[0]=momentum[0]/sqrt(massarray[i1]*massarray[i1]+momentum[0]*momentum[0]);
              for (Int_t i2=0; i2<3;i2++) { 
@@ -386,10 +444,10 @@ void AliTOFT0::Exec(Option_t *option)
            hchibestconflevel->Fill(confLevel);
            itimes++;
            if(strstr(option,"all")){
-             cout << "True Assignment " << truparticle[0] << truparticle[1] << truparticle[2] << truparticle[3] << truparticle[4] << truparticle[5] << truparticle[6] << truparticle[7] << truparticle[8] << truparticle[9] <<endl;
-             cout << "Best Assignment " << assparticle[0] << assparticle[1] << assparticle[2] << assparticle[3] << assparticle[4] << assparticle[5] << assparticle[6] << assparticle[7] << assparticle[8] << assparticle[9] << endl;
-             cout << "Minimum ChiSquare for current set    " << chisquare << endl;
-             cout << "Confidence Level (Minimum ChiSquare) " << confLevel << endl;
+             AliInfo(Form("True Assignment %d  %d  %d  %d  %d  %d  %d  %d  %d  %d", truparticle[0], truparticle[1], truparticle[2], truparticle[3], truparticle[4], truparticle[5], truparticle[6], truparticle[7], truparticle[8], truparticle[9]));
+             AliInfo(Form("Best Assignment %d  %d  %d  %d  %d  %d  %d  %d  %d  %d", assparticle[0], assparticle[1], assparticle[2], assparticle[3], assparticle[4], assparticle[5], assparticle[6], assparticle[7], assparticle[8], assparticle[9]));
+             AliInfo(Form("Minimum ChiSquare for current set   %d ", chisquare));
+             AliInfo(Form("Confidence Level (Minimum ChiSquare) %d", confLevel));
            }
            if (strstr(option,"visual") && itimes && (itimes%kUPDATE) == 0) {
              if (itimes == kUPDATE){
@@ -421,12 +479,12 @@ void AliTOFT0::Exec(Option_t *option)
   
   if(strstr(option,"all")){
     nmisidentified=(nmisidentified0+nmisidentified1+nmisidentified2+nmisidentified3+nmisidentified4+nmisidentified5+nmisidentified6+nmisidentified7+nmisidentified8+nmisidentified9);
-    cout << "total number of tracks token into account  " << 10*5*fNevents << endl;
+    AliInfo(Form("total number of tracks token into account  %i", 10*5*fNevents));
     Float_t badPercentage=100.*(Float_t)nmisidentified/(10*5*fNevents);
-    cout << "total misidentified                        " << nmisidentified << "("<< badPercentage << "%)" <<endl;
-    cout << "Total Number of set token into account     " << 5*fNevents << endl;
+    AliInfo(Form("total misidentified                       %i (%d %) ", nmisidentified, badPercentage));
+    AliInfo(Form("Total Number of set token into account     %i", 5*fNevents));
     Float_t goodSetPercentage=100.*(Float_t)ngood/(5*fNevents);
-    cout << "Number of set with no misidentified tracks " << ngood << "("<< goodSetPercentage << "%)" <<endl;
+    AliInfo(Form("Number of set with no misidentified tracks %i (%d %)", ngood, goodSetPercentage));
   }
 
   // free used memory for canvas
@@ -452,30 +510,43 @@ void AliTOFT0::Exec(Option_t *option)
   
   if(strstr(option,"tim") || strstr(option,"all")){
     gBenchmark->Stop("TOFT0");
-    cout << "AliTOFT0:" << endl ;
+    AliInfo("AliTOFT0:");
+    /*
     cout << "   took " << gBenchmark->GetCpuTime("TOFT0") << " seconds in order to calculate T0 " 
-        <<  gBenchmark->GetCpuTime("TOFT0")/fNevents << " seconds per event " << endl ;
-    cout << endl ;
+        << gBenchmark->GetCpuTime("TOFT0")/fNevents << " seconds per event " << endl ;
+    */
+    gBenchmark->Print("TOFT0");
   }
 }
  
 //__________________________________________________________________
-void AliTOFT0::SetTZeroFile(char * file ){
-  cout << "Destination file : " << file << endl ;
+void AliTOFT0::SetTZeroFile(char * file )
+{
+  //
+  //
+  //
+  printf("Destination file : %s \n", file) ;
   fT0File=file;
+
 }
+
 //__________________________________________________________________
-void AliTOFT0::Print(Option_t* option)const
+void AliTOFT0::Print(Option_t* /*option*/)const
 {
-  cout << "------------------- "<< GetName() << " -------------" << endl ;
+  //
+  //
+  //
+  printf("------------------- %s -------------\n", GetName()) ;
   if(!fT0File.IsNull())
-    cout << "  Writing T0 Distribution to file  " << (char*) fT0File.Data() << endl ;
+    printf("  Writing T0 Distribution to file  %s \n",(char*) fT0File.Data());
+
 }
 
 //__________________________________________________________________
 Bool_t AliTOFT0::operator==( AliTOFT0 const &tzero )const
 {
-  // Equal operator.
+  //
+  // Equal operator
   // 
 
   if( (fTimeResolution==tzero.fTimeResolution)&&(fLowerMomBound==tzero.fLowerMomBound)&&(fUpperMomBound==tzero.fUpperMomBound))
@@ -483,4 +554,3 @@ Bool_t AliTOFT0::operator==( AliTOFT0 const &tzero )const
   else
     return kFALSE ;
 }
-