GENIEGenerator
Loading...
Searching...
No Matches
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

◆ GetCommandLineArgs()

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}
#define pINFO
Definition Messenger.h:62
#define pFATAL
Definition Messenger.h:56
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE,...
Definition Messenger.h:96
Command line argument parser.
string gOptInpFilename
Definition gEvDump.cxx:76
int gOptNEvt

References genie::CmdLnArgParser::ArgAsInt(), genie::CmdLnArgParser::ArgAsString(), gOptInpFilename, gOptNEvt, LOG, genie::CmdLnArgParser::OptionExists(), pFATAL, and pINFO.

Referenced by main().

◆ main()

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}
#define pNOTICE
Definition Messenger.h:61
Generated Event Record. It is a GHepRecord object that can accept / be visited by EventRecordVisitorI...
Definition EventRecord.h:37
STDHEP-like event record entry that can fit a particle or a nucleus.
string Name(void) const
Name that corresponds to the PDG code.
int Pdg(void) const
double E(void) const
Get energy.
GHepStatus_t Status(void) const
MINOS-style ntuple record. Each such ntuple record holds a generated EventRecord object....
EventRecord * event
event
void Clear(Option_t *opt="")
MINOS-style Ntuple Class to hold an output MC Tree Header.
void GetCommandLineArgs(int argc, char **argv)
const int kPdgPiM
Definition PDGCodes.h:159
@ kIStStableFinalState
Definition GHepStatus.h:30
const int kPdgPi0
Definition PDGCodes.h:160
const int kPdgPiP
Definition PDGCodes.h:158

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().

Variable Documentation

◆ gOptInpFilename

string gOptInpFilename

Definition at line 41 of file gtestEventLoop.cxx.

◆ gOptNEvt

int gOptNEvt

Definition at line 40 of file gtestEventLoop.cxx.

Referenced by GetCommandLineArgs(), and main().