-- SebastianKupny - 28 Sep 2012

Using this macro you will be able to unpack and read data from root trees from simulations files. The other way (more recommended) is create for this purpose a tasks.

The macro


#include <fstream>
#include <iostream>
#include <string>

using namespace std;

void Kratta_get_interested_0903 ( TString A_sim_file ) {
  TString dir = getenv("VMCWORKDIR");
  TString r3bdir = dir + "/macros";

  TString r3b_geomdir = dir + "/geometry";
  gSystem->Setenv("GEOMPATH",r3b_geomdir.Data());

  TString r3b_confdir = dir + "gconfig";
  gSystem->Setenv("CONFIG_DIR",r3b_confdir.Data());

// Output files
  //TString OutFile = "r3bsim.root";
  TString InFile = A_sim_file;
  
  Int_t verbose = 10;

  // In general, the following parts need not be touched
  // ========================================================================

  // ----    Debug option   -------------------------------------------------
  gDebug = 0;
  // ------------------------------------------------------------------------

  // -----   Timer   --------------------------------------------------------
  TStopwatch timer;
  timer.Start();
  // ------------------------------------------------------------------------

  // ----  Load libraries   -------------------------------------------------
  gROOT->LoadMacro("$VMCWORKDIR/gconfig/basiclibs.C");
  basiclibs();

  gSystem->Load("libGenVector");

  gSystem->Load("libGeoBase");
  gSystem->Load("libParBase");
  gSystem->Load("libBase");
  gSystem->Load("libMCStack");
  gSystem->Load("libField");
  gSystem->Load("libGen");

  //----  Load R3B specific libraries ---------------------------------------
  gSystem->Load("libR3Bbase");
  gSystem->Load("libR3BGen");
  gSystem->Load("libR3BPassive");
  gSystem->Load("libR3BData");
  gSystem->Load("libR3BCal");
  gSystem->Load("libR3BCalo");
  gSystem->Load("libR3BDch");
  gSystem->Load("libR3BGfi");
  gSystem->Load("libR3BLand");
  gSystem->Load("libR3BmTof");
  gSystem->Load("libR3BTof");
  gSystem->Load("libR3BATof");
  gSystem->Load("libR3BTra");
  gSystem->Load("libR3BChimera");
  gSystem->Load("libELILuMon");
  gSystem->Load("libData");
  gSystem->Load("libKrakowArray"); 
  
  
  string stlInFile(A_sim_file);
  
  Double_t fEkin = 400;
  Double_t fMom = 1772;


  TFile *f = new TFile(  InFile );
  TTree *t4 = (TTree*)f->Get("cbmsim");
  
  Int_t nevent = t4->GetEntries();
  cout << nevent << endl;

  TClonesArray * pp;
  t4->SetBranchAddress( "KrakowPoint", &pp);

  TH2F * hist1 = new TH2F("hist1", "Kratta deltaE-E", 1000, -0.02, 1.1, 1000, -0.05, 0.5);

  hist1->SetXTitle("E [GeV]");
  hist1->SetYTitle("deltaE [GeV]");
  Double_t fDeltaE;
  Double_t fE;
  
  Int_t fDetId;
  Int_t fTrackID;
  
  for (Int_t i=0; i<nevent; i++) {
    
    t4-> GetEntry(i);  

    //pp->Print();
    Int_t nPoints = pp-> GetEntries();
    
    fDeltaE = 0;
    fE = 0;
    for (Int_t pi = 0; pi < nPoints; pi++ )
    {
      //KrakowArrayPoint *krattaPt = (KrakowArrayPoint*) pp->ConstructedAt(pi);
      KrakowArrayPoint *krattaPt = (KrakowArrayPoint*) (*pp)[pi];
      ///Printing:

      fDetId = krattaPt->GetDetectorID();
      fTrackID = krattaPt->GetTrackID();
      if (verbose > 0 )
      {
        krattaPt->Print();
        cout << "   Event "<< i << ", point= " << pi << ", Eloss= " <<  krattaPt->GetEnergyLoss();
        cout << ", DetectorID = " << krattaPt->GetDetectorID()  << endl;
        cout << "   TrackID=" << fTrackID << endl;
      }
      if ( fTrackID == 0 ){ ///Only primary particle
      if ( fDetId == 6 ) fDeltaE =  krattaPt->GetEnergyLoss();
      if ( fDetId == 7 ) fE = krattaPt->GetEnergyLoss();
      }
      }
    
    if (verbose > 1 )
    {
     cout << "   SELECTED: Pair (" << fE << "," << fDeltaE << ")" << endl;
     cout << "   SELECTED: Total energy: " << fE + fDeltaE << endl;
    }
  }
}

Topic revision: r1 - 2012-09-28, SebastianKupny
 
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding GSI Wiki? Send feedback
Imprint (in German)
Privacy Policy (in German)