]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
o Minor code cleanup
authorwiechula <wiechula@f7af4fe6-9843-0410-8265-dc069ae4e863>
Sat, 8 Jun 2013 18:50:34 +0000 (18:50 +0000)
committerwiechula <wiechula@f7af4fe6-9843-0410-8265-dc069ae4e863>
Sat, 8 Jun 2013 18:50:34 +0000 (18:50 +0000)
o Add simple tree filling

TPC/Upgrade/AliToyMCEventGenerator.cxx
TPC/Upgrade/AliToyMCEventGenerator.h
TPC/Upgrade/AliToyMCEventGeneratorSimple.cxx
TPC/Upgrade/AliToyMCEventGeneratorSimple.h

index 4d85ffee59ba0b1a19923d7e178cd07cbad58586..6b40b35064131f83a0a6c1a58743a7ea3e0b6a88 100644 (file)
@@ -1,32 +1,46 @@
 #include <iostream>
-#include "AliToyMCEventGenerator.h"
-#include <AliTPCROC.h>
-#include <AliTrackPointArray.h>
+
 #include <TDatabasePDG.h>
 #include <TRandom.h>
 #include <TH2F.h>
+#include <TGeoGlobalMagField.h>
+
+#include <AliTPCROC.h>
+#include <AliTrackPointArray.h>
 #include <AliTrackerBase.h>
 #include <AliCDBManager.h>
 #include <AliTPCParam.h>
 #include <AliGeomManager.h>
 #include <AliTPCcalibDB.h>
-#include <TGeoGlobalMagField.h>
 #include <AliTPCclusterMI.h>
+#include <AliTPCSpaceCharge3D.h>
+
+#include "AliToyMCEvent.h"
+#include "AliToyMCTrack.h"
+
+#include "AliToyMCEventGenerator.h"
+
 ClassImp(AliToyMCEventGenerator);
 
 
 AliToyMCEventGenerator::AliToyMCEventGenerator()
   :TObject()
   ,fTPCParam(0x0)
+  ,fEvent(0x0)
+  ,fSpaceCharge(0x0)
+  ,fOutputFileName("toyMC.root")
+  ,fOutFile(0x0)
+  ,fOutTree(0x0)
 {
   //TODO: Add method to set custom space charge file
   fSpaceCharge = new AliTPCSpaceCharge3D();
-  fSpaceCharge->SetSCDataFileName("SC_NeCO2_eps5_50kHz.root");
+  fSpaceCharge->SetSCDataFileName("$ALICE_ROOT/TPC/Calib/maps/SC_NeCO2_eps5_50kHz.root");
   fSpaceCharge->SetOmegaTauT1T2(0.325,1,1); // Ne CO2
   //fSpaceCharge->SetOmegaTauT1T2(0.41,1,1.05); // Ar CO2
   fSpaceCharge->InitSpaceCharge3DDistortion();
   fSpaceCharge->CreateHistoSCinZR(0.,50,50)->Draw("surf1");
-  fSpaceCharge->CreateHistoDRPhiinZR(0,100,100)->Draw("colz"); 
+  fSpaceCharge->CreateHistoDRPhiinZR(0,100,100)->Draw("colz");
+  //!!! This should be handled by the CongiOCDB macro
   const char* ocdb="local://$ALICE_ROOT/OCDB/";
   AliCDBManager::Instance()->SetDefaultStorage(ocdb);
   AliCDBManager::Instance()->SetRun(0);   
@@ -38,7 +52,12 @@ AliToyMCEventGenerator::AliToyMCEventGenerator()
 //________________________________________________________________
 AliToyMCEventGenerator::AliToyMCEventGenerator(const AliToyMCEventGenerator &gen)
   :TObject(gen)
+  ,fTPCParam(gen.fTPCParam)
+  ,fEvent(0x0)
   ,fSpaceCharge(gen.fSpaceCharge)
+  ,fOutputFileName(gen.fOutputFileName)
+  ,fOutFile(0x0)
+  ,fOutTree(0x0)
 {
   //
 }
@@ -46,10 +65,18 @@ AliToyMCEventGenerator::AliToyMCEventGenerator(const AliToyMCEventGenerator &gen
 AliToyMCEventGenerator::~AliToyMCEventGenerator() 
 {
   delete fSpaceCharge;
+  //!!! Is fTPCParam not owned by the CDB manager?
   delete fTPCParam;
 }
 //________________________________________________________________
-Bool_t AliToyMCEventGenerator::DistortTrack(AliToyMCTrack &trackIn, Double_t t0) {
+Bool_t AliToyMCEventGenerator::DistortTrack(AliToyMCTrack &trackIn, Double_t t0)
+{
+  //
+  //
+  //
+
+  //!!! Should this complete function not be moved to AliToyMCTrack, and directly called from the constructor
+  //    or setter of the track parameters?
 
   if(!fTPCParam) {
     fTPCParam = AliTPCcalibDB::Instance()->GetParameters();
@@ -75,6 +102,7 @@ Bool_t AliToyMCEventGenerator::DistortTrack(AliToyMCTrack &trackIn, Double_t t0)
   AliTrackPointArray pointArray1(nMaxPoints);
   Double_t xyz[3];
 
+  //!!! when does the propagation not work, how often does it happen?
   if (!AliTrackerBase::PropagateTrackTo(&track,iFCRadius,kMass,5,kTRUE,kMaxSnp)) return 0;
 
   Int_t npoints=0;
@@ -140,10 +168,10 @@ Bool_t AliToyMCEventGenerator::DistortTrack(AliToyMCTrack &trackIn, Double_t t0)
     tempCl->SetY(yArr[iPoint]);
     tempCl->SetZ(zArr[iPoint]);
     
-    Float_t xyz[3] = {xArrDist[iPoint],yArrDist[iPoint],zArrDist[iPoint]};
+    Float_t xyz2[3] = {xArrDist[iPoint],yArrDist[iPoint],zArrDist[iPoint]};
     Int_t index[3] = {0};
 
-    Float_t padRow = fTPCParam->GetPadRow(xyz,index);
+    Float_t padRow = fTPCParam->GetPadRow(xyz2,index);
     Int_t sector = index[1];
 
     if(padRow < 0 || (sector < 36 && padRow>62) || (sector > 35 &&padRow > 95) ) continue; //outside sensitive area
@@ -189,3 +217,46 @@ Bool_t AliToyMCEventGenerator::DistortTrack(AliToyMCTrack &trackIn, Double_t t0)
   
   
 }
+//________________________________________________________________
+Bool_t AliToyMCEventGenerator::ConnectOutputFile()
+{
+  //
+  // Create the output file name and tree and connect the event
+  //
+
+  fOutFile = new TFile(fOutputFileName.Data(),"recreate");
+
+  if (!fOutFile || !fOutFile->IsOpen()){
+    delete fOutFile;
+    fOutFile=0x0;
+    return kFALSE;
+  }
+  
+  fOutTree = new TTree("toyMCtree","Tree with toyMC simulation");
+  fOutTree->Branch("event","AliToyMCEvent",&fEvent);
+
+  return kTRUE;
+}
+
+//________________________________________________________________
+Bool_t AliToyMCEventGenerator::CloseOutputFile()
+{
+  //
+  // close the output file
+  //
+  if (!fOutFile) return kFALSE;
+  fOutFile->Write();
+  fOutFile->Close();
+  delete fOutFile;
+  fOutFile=0x0;
+
+  return kTRUE;
+}
+
+//________________________________________________________________
+void AliToyMCEventGenerator::FillTree()
+{
+  // fill the tree
+  if (fOutTree) fOutTree->Fill();
+}
+
index 14b26e7cfc2b99b180aadb726fe2faa66564dc21..f31774d7af810ca877afb4c761c6d2a54a56750f 100644 (file)
@@ -1,11 +1,17 @@
 #ifndef AliToyMCEventGenerator_H
 #define AliToyMCEventGenerator_H
 
+#include <TString.h>
+
+class TFile;
+class TTree;
+
+class AliTPCParam;
+class AliTPCSpaceCharge3D;
+
+class AliToyMCTrack;
+class AliToyMCEvent;
 
-#include "AliToyMCEvent.h"
-#include "AliToyMCTrack.h"
-#include <AliTPCSpaceCharge3D.h>
-#include <AliTPCParam.h>
 class AliToyMCEventGenerator : public TObject {
  public:
   AliToyMCEventGenerator();
@@ -16,11 +22,24 @@ class AliToyMCEventGenerator : public TObject {
 
   Bool_t DistortTrack(AliToyMCTrack &trackIn, Double_t t0);
 
+  void SetOutputFileName(const char* file) { fOutputFileName=file; }
+  const char* GetOutputFileName()    const { return fOutputFileName.Data(); }
  protected:
   AliTPCParam *fTPCParam;
+  AliToyMCEvent *fEvent;
+  
+  Bool_t ConnectOutputFile();
+  Bool_t CloseOutputFile();
+  void FillTree();
   
  private:
+  AliToyMCEventGenerator& operator= (const AliToyMCEventGenerator& );
+   
   AliTPCSpaceCharge3D *fSpaceCharge;
+
+  TString fOutputFileName;
+  TFile   *fOutFile;
+  TTree   *fOutTree;
   
   ClassDef(AliToyMCEventGenerator, 1)
      
index ba0b5a28e1ca7dcb1bc7ec42f2f27649c6444c71..6db9843d6f74c8614795896938e63f0e30a92d5b 100644 (file)
@@ -1,10 +1,13 @@
 #include <iostream>
-#include "AliToyMCEventGeneratorSimple.h"
+
 #include <TDatabasePDG.h>
 #include <TRandom.h>
 #include <TF1.h>
+
 #include "AliToyMCEvent.h"
 
+#include "AliToyMCEventGeneratorSimple.h"
+
 ClassImp(AliToyMCEventGeneratorSimple);
 
 
@@ -85,4 +88,26 @@ AliToyMCEvent* AliToyMCEventGeneratorSimple::Generate(Double_t time) {
   return retEvent;
 }
 
+//________________________________________________________________
+void AliToyMCEventGeneratorSimple::RunSimulation(const Int_t nevents/*=10*/)
+{
+  //
+  // run simple simulation with equal event spacing
+  //
+
+  if (!ConnectOutputFile()) return;
+
+  Double_t eventTime=0.;
+  const Double_t eventSpacing=1./50e3; //50kHz equally spaced
+  
+  for (Int_t ievent=0; ievent<nevents; ++ievent){
+    fEvent = Generate(eventTime);
+    FillTree();
+    delete fEvent;
+    fEvent=0x0;
+    eventTime+=eventSpacing;
+  }
+
+  CloseOutputFile();
+}
 
index 3f9a79f294524eae9ec7d993c28b0e5ab1a018dc..b0bb0a3c39bee984258de8df640304d9a32de6bc 100644 (file)
@@ -2,9 +2,10 @@
 #define AliToyMCEventGeneratorSimple_H
 
 
-#include "AliToyMCEvent.h"
-#include "AliToyMCTrack.h"
 #include "AliToyMCEventGenerator.h"
+
+class AliToyMCEvent;
+
 class AliToyMCEventGeneratorSimple : public AliToyMCEventGenerator {
  public:
   AliToyMCEventGeneratorSimple();
@@ -14,6 +15,8 @@ class AliToyMCEventGeneratorSimple : public AliToyMCEventGenerator {
 
   AliToyMCEvent* Generate(Double_t time);
   void SetParameters(Double_t vertexMean, Double_t vertexSigma);
+
+  void RunSimulation(const Int_t nevents=10);
  private:
   
   Double_t fVertexMean;