AliTOFProb and AliTOFtestProb.C added
authorvicinanz <vicinanz@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 26 Jun 2002 18:03:43 +0000 (18:03 +0000)
committervicinanz <vicinanz@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 26 Jun 2002 18:03:43 +0000 (18:03 +0000)
TOF/AliTOFProb.cxx [new file with mode: 0644]
TOF/AliTOFProb.h [new file with mode: 0644]
TOF/AliTOFtestProb.C [new file with mode: 0644]
TOF/Makefile
TOF/TOFLinkDef.h
TOF/libTOF.pkg

diff --git a/TOF/AliTOFProb.cxx b/TOF/AliTOFProb.cxx
new file mode 100644 (file)
index 0000000..c0dfba6
--- /dev/null
@@ -0,0 +1,268 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+//_________________________________________________________________________
+// TTask class for TOF Probabilities (ALICE-Offline week June 2002).
+// Use case: start root and execute the following macro
+// ntuple.root is assumed to be the ntuple with the reconstructed
+// data
+/*
+{
+  // Dynamically link some shared libs
+  if (gClassTable->GetID("AliRun") < 0) {
+    gROOT->LoadMacro("loadlibs.C");
+    loadlibs();
+  }
+  // create an instance of the AliTOFProb class
+  // You have to pass the ntuple
+ AliTOFProb* tofprob=new AliTOFProb("ntuple.root");
+ tofprob->Exec("");
+}
+*/
+// 
+//-- Author: F. Pierella | pierella@bo.infn.it
+//////////////////////////////////////////////////////////////////////////////
+
+#include "TStyle.h"
+#include "TTask.h"
+#include "TTree.h"
+#include "TSystem.h"
+#include "TFile.h"
+#include "TH3.h"
+//#include "TH3.h"
+#include "TCanvas.h"
+#include "TFile.h"
+#include <TF1.h>
+#include <TF2.h>
+#include "TROOT.h"
+#include "TFolder.h"
+#include "TNtuple.h"
+#include "TLeaf.h"
+
+#include "AliConst.h"
+#include "AliTOFConstants.h"
+#include "AliTOFProb.h"
+
+#include <stdlib.h>
+#include <iostream.h>
+#include <fstream.h>
+
+ClassImp(AliTOFProb)
+
+//____________________________________________________________________________ 
+  AliTOFProb::AliTOFProb():TTask("AliTOFProb","") 
+{
+  // default ctor - set the pointer member vars to zero
+
+  fhfile    = 0;
+  fNtuple   = 0;
+  fgen      = 0;
+  foutfileName  = 0;
+}
+           
+//____________________________________________________________________________ 
+  AliTOFProb::AliTOFProb(char* headerFile):TTask("AliTOFProb","") 
+{
+
+  fhfile = TFile::Open(headerFile); // connect file with ntuple
+  foutfileName=headerFile;
+  fNtuple   = 0;
+  fgen      = 0;
+
+  Init();
+  // add Task to //root/Tasks folder
+  TTask * roottasks = (TTask*)gROOT->GetRootFolder()->FindObject("Tasks") ; 
+  roottasks->Add(this) ; 
+}
+//____________________________________________________________________________ 
+void AliTOFProb::Init()
+{
+
+  fNtuple= (TNtuple*)fhfile->Get("Ntuple"); // get ntuple from file
+  Int_t nvar = fNtuple->GetNvar(); cout <<"N of var.="<< nvar << endl;
+  fNtuple->GetEvent(0);
+
+}
+
+//____________________________________________________________________________ 
+  AliTOFProb::~AliTOFProb()
+{
+  //
+  // dtor (free used memory)
+  //
+
+  if (fhfile)
+    {
+      delete fhfile;
+      fhfile = 0;
+    }
+
+
+  if (fNtuple)
+    {
+      delete fNtuple;
+      fNtuple = 0;
+    }
+
+  if (fgen)
+    {
+      delete fgen;
+      fgen = 0;
+    }
+
+  if (foutfileName)
+    {
+      delete foutfileName;
+      foutfileName = 0;
+    }
+}
+
+
+//____________________________________________________________________________
+void AliTOFProb::Exec(const Option_t *dummyOpt) 
+{ 
+  //
+  // Performs Prob for TOF detector
+  // 
+  fTask=1;
+  fhfile->cd();
+  // create the histo
+  TH3* h3D=new TH3F("h3D", "", 100, 0., 1., 100, 0., 1., 100, 0., 1.);
+  TH3* h3Ddt=new TH3F("h3Ddt", "", 360, -120., 120., 360, -120., 120., 360, -120., 120.);
+
+  TH1* hpion  =new TH1F("hpion", "", 100, 0., 1.);
+  TH1* hkaon  =new TH1F("hkaon", "", 100, 0., 1.);
+  TH1* hproton=new TH1F("hproton", "", 100, 0., 1.);
+
+  TH1* hdtpion  =new TH1F("hdtpion", "", 600, -120., 120.);
+  TH1* hdtkaon  =new TH1F("hdtkaon", "", 600, -120., 120.);
+  TH1* hdtproton=new TH1F("hdtproton", "", 600, -120., 120.);
+
+  const Float_t timeResolution=0.12;
+
+  Int_t nparticles = (Int_t)fNtuple->GetEntries();
+  cout << " Number of nparticles =" << nparticles << endl;
+  if (nparticles <= 0) return;
+  
+  for (Int_t i=0; i < nparticles; i++) {
+    fNtuple->GetEvent(i);
+    //Int_t event=(Int_t)(fNtuple->GetLeaf("event")->GetValue());
+    Int_t pdgcode=(Int_t)(fNtuple->GetLeaf("ipart")->GetValue());
+    Float_t mass=fNtuple->GetLeaf("mext")->GetValue(0);
+    Int_t matc=(Int_t)(fNtuple->GetLeaf("matc")->GetValue(0));
+    Int_t imam=(Int_t)(fNtuple->GetLeaf("imam")->GetValue(0));
+    Float_t time=fNtuple->GetLeaf("text")->GetValue(0); // [ns]
+    // generate a gaussian around time with sigma timeresolution [ns]
+    Float_t lowTime=time-1000.*timeResolution;
+    Float_t upTime =time+1000.*timeResolution;
+    TF1* gauss=new TF1("tg","gaus",lowTime,upTime);
+
+    Double_t p1=time;
+    Double_t p2=timeResolution;
+    Float_t twopi=2*TMath::Pi();
+    Float_t sqrtwopi=TMath::Sqrt(twopi);
+    //Double_t p0=1./(p2*sqrtwopi);
+    Double_t p0=1.;
+    gauss->SetParameters(p0,p1,p2);
+
+    Float_t px=fNtuple->GetLeaf("pxvtx")->GetValue(0);
+    Float_t py=fNtuple->GetLeaf("pyvtx")->GetValue(0);
+    Float_t pz=fNtuple->GetLeaf("pzvtx")->GetValue(0);
+    // track length [cm]
+    Float_t toflen=fNtuple->GetLeaf("leng")->GetValue(0);
+
+    Float_t pvtx=TMath::Sqrt(px*px+py*py+pz*pz);
+    Float_t ptvtx=TMath::Sqrt(px*px+py*py);
+
+    Bool_t isSelected=(imam == 0 && pz !=0 && TMath::ATan(TMath::Abs(ptvtx/pz))>TMath::Pi()*45./180.);
+    Bool_t trackWithTime=(matc==2 || matc==3 || matc==4);
+
+    Int_t abspdgcode=TMath::Abs(pdgcode);
+    switch(abspdgcode){
+    case 321:
+      break;
+    case 2212:
+      break;
+    case 11:
+      break;
+    default:
+      break;
+    }
+
+    if (isSelected && trackWithTime && toflen>370.)
+      {//only primary +/-45  
+       Float_t beta[3]={0.,0.,0.};
+       Float_t timeth[3]={0.,0.,0.};
+       Float_t massarray[3]={0.13957,0.493677,0.9382723};
+       for (Int_t j=0; j < 3; j++) {
+         Float_t dummy=(pvtx/massarray[j])*(pvtx/massarray[j]);
+         beta[j]=TMath::Sqrt(dummy/(1.+dummy));
+         timeth[j]=toflen/(29.9792458*beta[j]);
+       }
+       Float_t pPion   =(Float_t)gauss->Eval(timeth[0],0.,0.);
+       Float_t pKaon   =(Float_t)gauss->Eval(timeth[1],0.,0.);
+       Float_t pProton =(Float_t)gauss->Eval(timeth[2],0.,0.);
+
+       Float_t dtpion=time-timeth[0];
+       Float_t dtkaon=time-timeth[1];
+       Float_t dtproton=time-timeth[2];
+       hdtpion->Fill(dtpion);
+       hdtkaon->Fill(dtkaon);
+       hdtproton->Fill(dtproton);
+
+       // normalizing probabilities
+       Float_t sumProb=pPion+pKaon+pProton;
+       pPion=pPion/sumProb;
+       pKaon=pKaon/sumProb;
+       pProton=pProton/sumProb;
+       hpion->Fill(pPion);
+       hkaon->Fill(pKaon);
+       hproton->Fill(pProton);
+       //cout << "pPion " << pPion << " pKaon " << pKaon << " pProton " << pProton << endl;
+       h3D->Fill(pPion,pKaon,pProton);
+       h3Ddt->Fill(dtpion,dtkaon,dtproton);
+       //cout << "pion " << timeth[0] << " kaon " << timeth[1] << " proton " << timeth[2] << endl;
+      }// End of cuts appling
+
+    delete gauss;
+
+  }// End of loop over particles
+
+  char outFileName[100];
+  strcpy(outFileName,"3DProbHisto.root");
+  TFile *houtfile = new TFile(outFileName,"recreate");
+  houtfile->cd();
+  h3D->Write(0,TObject::kOverwrite);
+  h3Ddt->Write(0,TObject::kOverwrite);
+  hpion->Write(0,TObject::kOverwrite);
+  hkaon->Write(0,TObject::kOverwrite);
+  hproton->Write(0,TObject::kOverwrite);
+  hdtpion->Write(0,TObject::kOverwrite);
+  hdtkaon->Write(0,TObject::kOverwrite);
+  hdtproton->Write(0,TObject::kOverwrite);
+
+  houtfile->Close();
+  houtfile->Write(0,TObject::kOverwrite);
+}
+
+
+//__________________________________________________________________
+Bool_t AliTOFProb::operator==( AliTOFProb const & tofrec)const
+{
+  // dummy version of Equal operator.
+  // requested by coding conventions
+  return kTRUE;
+
+}
diff --git a/TOF/AliTOFProb.h b/TOF/AliTOFProb.h
new file mode 100644 (file)
index 0000000..452925e
--- /dev/null
@@ -0,0 +1,49 @@
+#ifndef ALITOFPROB_H
+#define ALITOFPROB_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+
+//_________________________________________________________________________
+//  Task Class for Probabilities in TOF      
+//                  
+//-- Author: F. Pierella
+
+
+#include "TTask.h"
+#include "TCutG.h"
+#include "TString.h"
+#include <TF1.h>
+#include <TF2.h>
+#include <TH1.h>
+#include <TH2.h>
+#include <TNtuple.h>
+
+class AliTOFProb: public TTask {
+
+public:
+  AliTOFProb() ;          // ctor
+  AliTOFProb(char* headerFile) ; 
+  virtual ~AliTOFProb() ; // dtor   
+  virtual void  Exec(const Option_t *dummyOpt); // do the main work
+  void          Init();
+
+  TNtuple*      GetInputNtuple() const {return fNtuple;}
+
+  Bool_t   operator == (const AliTOFProb & tofprob) const ;
+
+private:
+
+  TNtuple *fNtuple; // pointer to ntuple 
+  TFile *fhfile;
+  TFile *fgen;
+  char* foutfileName; // destination file name for histos
+  Int_t fTask;
+
+ protected:
+
+  ClassDef(AliTOFProb,0)  // Task class for PID probabilities from TOF
+
+};
+
+#endif // AliTOFPROB_H
diff --git a/TOF/AliTOFtestProb.C b/TOF/AliTOFtestProb.C
new file mode 100644 (file)
index 0000000..4ce576e
--- /dev/null
@@ -0,0 +1,27 @@
+void AliTOFtestProb(TString fileNameMatch) 
+{
+  /////////////////////////////////////////////////////////////////////////
+  //
+  // Test macro for TOF Prob
+  // Author: F. Pierella
+  // Report problems to pierella@bo.infn.it
+  // input filenames:
+  // fileNameMatch -> file with the result of matching
+  //
+  // Use case:
+  // start root
+  // // load the macro
+  // root[0] .L AliTOFtestProb.C
+  // root[1] AliTOFtestProb("match-6KevPYTHIA-0.2T.root")
+  /////////////////////////////////////////////////////////////////////////
+
+  // Dynamically link some shared libs
+  if (gClassTable->GetID("AliRun") < 0) {
+    gROOT->LoadMacro("loadlibs.C");
+    loadlibs();
+    cout << "Loaded shared libraries" << endl;
+  }
+  
+  AliTOFProb* tofprob=new AliTOFProb(fileNameMatch.Data());
+  tofprob->Exec("");
+}
index ead7438..afb9637 100644 (file)
@@ -9,7 +9,7 @@ PACKAGE = TOF
 
 # C++ sources
 
-SRCS  = AliTOF.cxx  AliTOFv0.cxx  AliTOFv1.cxx  AliTOFv2.cxx  AliTOFv3.cxx  AliTOFv4.cxx AliTOFv4T0.cxx AliTOFhit.cxx AliTOFhitT0.cxx AliTOFdigit.cxx AliTOFRawSector.cxx  AliTOFRoc.cxx  AliTOFRawDigit.cxx AliTOFDigitizer.cxx AliTOFSDigitizer.cxx AliTOFMerger.cxx  AliTOFv2FHoles.cxx AliTOFSDigit.cxx AliTOFHitMap.cxx AliTOFConstants.cxx AliTOFT0.cxx AliTOFPID.cxx AliTOFPad.cxx AliTOFRecHit.cxx AliTOFTrack.cxx AliTOFReconstructioner.cxx
+SRCS  = AliTOF.cxx  AliTOFv0.cxx  AliTOFv1.cxx  AliTOFv2.cxx  AliTOFv3.cxx  AliTOFv4.cxx AliTOFv4T0.cxx AliTOFhit.cxx AliTOFhitT0.cxx AliTOFdigit.cxx AliTOFRawSector.cxx  AliTOFRoc.cxx  AliTOFRawDigit.cxx AliTOFDigitizer.cxx AliTOFSDigitizer.cxx AliTOFMerger.cxx  AliTOFv2FHoles.cxx AliTOFSDigit.cxx AliTOFHitMap.cxx AliTOFConstants.cxx AliTOFT0.cxx AliTOFPID.cxx AliTOFPad.cxx AliTOFRecHit.cxx AliTOFTrack.cxx AliTOFReconstructioner.cxx AliTOFProb.cxx
 
 # C++ Headers
 
index 83542f4..c266711 100644 (file)
@@ -11,6 +11,7 @@
 #pragma link C++ class  AliTOF+;
 #pragma link C++ class  AliTOFT0+;
 #pragma link C++ class  AliTOFPID+;
+#pragma link C++ class  AliTOFProb+;
 #pragma link C++ class  AliTOFv0+;
 #pragma link C++ class  AliTOFv1+;
 #pragma link C++ class  AliTOFv2+;
index 3b57d90..5c98e5a 100644 (file)
@@ -1,4 +1,4 @@
-SRCS  = AliTOF.cxx  AliTOFv0.cxx  AliTOFv1.cxx  AliTOFv2.cxx  AliTOFv3.cxx  AliTOFv4.cxx AliTOFv4T0.cxx AliTOFhit.cxx  AliTOFhitT0.cxx AliTOFPID.cxx AliTOFT0.cxx AliTOFdigit.cxx AliTOFRawSector.cxx  AliTOFRoc.cxx  AliTOFRawDigit.cxx AliTOFDigitizer.cxx AliTOFSDigitizer.cxx AliTOFMerger.cxx  AliTOFv2FHoles.cxx AliTOFSDigit.cxx AliTOFHitMap.cxx AliTOFConstants.cxx AliTOFPad.cxx AliTOFRecHit.cxx AliTOFTrack.cxx AliTOFReconstructioner.cxx
+SRCS  = AliTOF.cxx  AliTOFv0.cxx  AliTOFv1.cxx  AliTOFv2.cxx  AliTOFv3.cxx  AliTOFv4.cxx AliTOFv4T0.cxx AliTOFhit.cxx  AliTOFhitT0.cxx AliTOFPID.cxx AliTOFT0.cxx AliTOFdigit.cxx AliTOFRawSector.cxx  AliTOFRoc.cxx  AliTOFRawDigit.cxx AliTOFDigitizer.cxx AliTOFSDigitizer.cxx AliTOFMerger.cxx  AliTOFv2FHoles.cxx AliTOFSDigit.cxx AliTOFHitMap.cxx AliTOFConstants.cxx AliTOFPad.cxx AliTOFRecHit.cxx AliTOFTrack.cxx AliTOFReconstructioner.cxx AliTOFProb.cxx
 
 
 HDRS:= $(SRCS:.cxx=.h)