GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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"
Include dependency graph for gtestEventLoop.cxx:

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 
)
int main ( int  argc,
char **  argv 
)

Definition at line 44 of file gtestEventLoop.cxx.

References genie::NtpMCEventRecord::Clear(), genie::GHepParticle::E(), genie::NtpMCEventRecord::event, GetCommandLineArgs(), gOptInpFilename, gOptNEvt, genie::kIStStableFinalState, genie::kPdgPi0, genie::kPdgPiM, genie::kPdgPiP, LOG, genie::GHepParticle::Name(), genie::GHepParticle::Pdg(), pNOTICE, and genie::GHepParticle::Status().

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.
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.
const int kPdgPiP
Definition: PDGCodes.h:158
const int kPdgPi0
Definition: PDGCodes.h:160
string gOptInpFilename
Definition: gEvDump.cxx:76
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 GetCommandLineArgs(int argc, char **argv)
Definition: gAtmoEvGen.cxx:563
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

Variable Documentation

string gOptInpFilename

Definition at line 41 of file gtestEventLoop.cxx.

int gOptNEvt

Definition at line 40 of file gtestEventLoop.cxx.

Referenced by main().