Functions | Variables
gtestEventLoop.cxx File Reference
#include <string>
#include <TSystem.h>
#include <TFile.h>
#include <TTree.h>
#include <TIterator.h>
#include "Framework/EventGen/EventRecord.h"
#include "Framework/GHEP/GHepParticle.h"
#include "Framework/Ntuple/NtpMCFormat.h"
#include "Framework/Ntuple/NtpMCTreeHeader.h"
#include "Framework/Ntuple/NtpMCEventRecord.h"
#include "Framework/Messenger/Messenger.h"
#include "Framework/ParticleData/PDGCodes.h"
#include "Framework/Utils/CmdLnArgParser.h"

Go to the source code of this file.

Functions

void GetCommandLineArgs (int argc, char **argv)
 
int main (int argc, char **argv)
 

Variables

int gOptNEvt
 
string gOptInpFilename
 

Function Documentation

void GetCommandLineArgs ( int  argc,
char **  argv 
)

Definition at line 132 of file gtestEventLoop.cxx.

133 {
134  LOG("myAnalysis", pINFO) << "Parsing commad line arguments";
135 
136  CmdLnArgParser parser(argc,argv);
137 
138  // get GENIE event sample
139  if( parser.OptionExists('f') ) {
140  LOG("myAnalysis", pINFO)
141  << "Reading event sample filename";
142  gOptInpFilename = parser.ArgAsString('f');
143  } else {
144  LOG("myAnalysis", pFATAL)
145  << "Unspecified input filename - Exiting";
146  exit(1);
147  }
148 
149  // number of events to analyse
150  if( parser.OptionExists('n') ) {
151  LOG("myAnalysis", pINFO)
152  << "Reading number of events to analyze";
153  gOptNEvt = parser.ArgAsInt('n');
154  } else {
155  LOG("myAnalysis", pINFO)
156  << "Unspecified number of events to analyze - Use all";
157  gOptNEvt = -1;
158  }
159 }
int gOptNEvt
#define pFATAL
Definition: Messenger.h:56
string gOptInpFilename
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
#define pINFO
Definition: Messenger.h:62
Command line argument parser.
int main ( int  argc,
char **  argv 
)

Definition at line 44 of file gtestEventLoop.cxx.

45 {
46  GetCommandLineArgs (argc, argv);
47 
48  //-- open the ROOT file and get the TTree & its header
49  TTree * tree = 0;
50  NtpMCTreeHeader * thdr = 0;
51 
52  TFile file(gOptInpFilename.c_str(),"READ");
53 
54  tree = dynamic_cast <TTree *> ( file.Get("gtree") );
55  thdr = dynamic_cast <NtpMCTreeHeader *> ( file.Get("header") );
56 
57  if(!tree) return 1;
58 
59  NtpMCEventRecord * mcrec = 0;
60  tree->SetBranchAddress("gmcrec", &mcrec);
61 
62  int nev = (gOptNEvt > 0) ?
63  TMath::Min(gOptNEvt, (int)tree->GetEntries()) :
64  (int) tree->GetEntries();
65 
66  //
67  // Loop over all events
68  //
69  for(int i = 0; i < nev; i++) {
70 
71  // get next tree entry
72  tree->GetEntry(i);
73 
74  // get the GENIE event
75  EventRecord & event = *(mcrec->event);
76 
77  LOG("myAnalysis", pNOTICE) << event;
78 
79  //
80  // Put your event analysis code here
81  //
82  // ... ... ... ... ...
83  // ... ... ... ... ...
84  //
85  //
86 
87 
88 
89  //
90  // Loop over all particles in this event
91  //
92 
93  GHepParticle * p = 0;
94  TIter event_iter(&event);
95 
96  while((p=dynamic_cast<GHepParticle *>(event_iter.Next())))
97  {
98  //
99  // Put your event analysis code here
100  //
101  // ... ... ... ... ...
102  // ... ... ... ... ...
103  //
104  //
105 
106  // EXAMPLE: Print out the energy of all final state pions.
107  if (p->Status() == kIStStableFinalState ) {
108  if (p->Pdg() == kPdgPi0 ||
109  p->Pdg() == kPdgPiP ||
110  p->Pdg() == kPdgPiM)
111  {
112  LOG("myAnalysis", pNOTICE)
113  << "Got a : " << p->Name() << " with E = " << p->E() << " GeV";
114  }
115  }
116 
117  }// end loop over particles
118 
119  // clear current mc event record
120  mcrec->Clear();
121 
122  }//end loop over events
123 
124  // close input GHEP event file
125  file.Close();
126 
127  LOG("myAnalysis", pNOTICE) << "Done!";
128 
129  return 0;
130 }
double E(void) const
Get energy.
Definition: GHepParticle.h:91
int gOptNEvt
MINOS-style ntuple record. Each such ntuple record holds a generated EventRecord object. Ntuples of this type are intended for feeding GENIE events into other applications (for example the GEANT4 based MC generation framework of an experiment) if no direct interface exists.
void GetCommandLineArgs(int argc, char **argv)
string gOptInpFilename
GHepStatus_t Status(void) const
Definition: GHepParticle.h:64
int Pdg(void) const
Definition: GHepParticle.h:63
string Name(void) const
Name that corresponds to the PDG code.
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
MINOS-style Ntuple Class to hold an output MC Tree Header.
p
Definition: test.py:223
const int kPdgPiP
Definition: PDGCodes.h:158
const int kPdgPi0
Definition: PDGCodes.h:160
Generated Event Record. It is a GHepRecord object that can accept / be visited by EventRecordVisitorI...
Definition: EventRecord.h:37
const int kPdgPiM
Definition: PDGCodes.h:159
#define pNOTICE
Definition: Messenger.h:61
void Clear(Option_t *opt="")
STDHEP-like event record entry that can fit a particle or a nucleus.
Definition: GHepParticle.h:39
EventRecord * event
event
Event finding and building.

Variable Documentation

string gOptInpFilename

Definition at line 41 of file gtestEventLoop.cxx.

int gOptNEvt

Definition at line 40 of file gtestEventLoop.cxx.