Functions | Variables
gEvDump.cxx File Reference
#include <string>
#include <TFile.h>
#include <TTree.h>
#include <TLeaf.h>
#include "Framework/Conventions/GBuild.h"
#include "Framework/EventGen/EventRecord.h"
#include "Framework/Ntuple/NtpMCFormat.h"
#include "Framework/Ntuple/NtpMCTreeHeader.h"
#include "Framework/Ntuple/NtpMCEventRecord.h"
#include "Framework/Messenger/Messenger.h"
#include "Framework/ParticleData/PDGLibrary.h"
#include "Framework/Utils/CmdLnArgParser.h"
#include "Framework/Utils/RunOpt.h"

Go to the source code of this file.

Functions

void GetCommandLineArgs (int argc, char **argv)
 
void PrintSyntax (void)
 
void GetEventRange (Long64_t nev, Long64_t &n1, Long64_t &n2)
 
int main (int argc, char **argv)
 

Variables

Long64_t gOptNEvtL
 
Long64_t gOptNEvtH
 
string gOptInpFilename
 

Function Documentation

void GetCommandLineArgs ( int  argc,
char **  argv 
)

Definition at line 237 of file gEvDump.cxx.

238 {
239  LOG("gevdump", pINFO) << "*** Parsing command line arguments";
240 
241  // Common run options.
242  RunOpt::Instance()->ReadFromCommandLine(argc,argv);
243 
244  // Parse run options for this app
245 
246  CmdLnArgParser parser(argc,argv);
247 
248  // get GENIE event sample
249  if ( parser.OptionExists('f') ) {
250  LOG("gevdump", pINFO) << "Reading event sample filename";
251  gOptInpFilename = parser.ArgAsString('f');
252  } else {
253  LOG("gevdump", pFATAL)
254  << "Unspecified input filename - Exiting";
255  PrintSyntax();
256  gAbortingInErr = true;
257  exit(1);
258  }
259 
260  // number of events:
261  if ( parser.OptionExists('n') ) {
262  LOG("gevdump", pINFO) << "Reading number of events to analyze";
263  string nev = parser.ArgAsString('n');
264  if (nev.find(",") != string::npos) {
265  vector<long> vecn = parser.ArgAsLongTokens('n',",");
266  if(vecn.size()!=2) {
267  LOG("gevdump", pFATAL) << "Invalid syntax";
268  PrintSyntax();
269  gAbortingInErr = true;
270  exit(1);
271  }
272  // read a range of events
273  gOptNEvtL = vecn[0];
274  gOptNEvtH = vecn[1];
275  } else {
276  // read single event
277  gOptNEvtL = parser.ArgAsLong('n');
279  }
280  } else {
281  LOG("gevdump", pINFO)
282  << "Unspecified number of events to analyze - Use all";
283  gOptNEvtL = -1;
284  gOptNEvtH = -1;
285  }
286 
287 
288 }
void PrintSyntax(void)
Definition: gEvDump.cxx:290
#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
Long64_t gOptNEvtL
Definition: gEvDump.cxx:74
#define pINFO
Definition: Messenger.h:62
string gOptInpFilename
Definition: gEvDump.cxx:76
Long64_t gOptNEvtH
Definition: gEvDump.cxx:75
Command line argument parser.
bool gAbortingInErr
Definition: Messenger.cxx:34
void GetEventRange ( Long64_t  nev,
Long64_t &  n1,
Long64_t &  n2 
)

Definition at line 217 of file gEvDump.cxx.

218 {
219  if(gOptNEvtL == -1 && gOptNEvtH == -1) {
220  // read all events
221  n1=0;
222  n2=nev-1;
223  }
224  else {
225  // read a range of events
226  n1 = TMath::Max((Long64_t)0, gOptNEvtL);
227  n2 = TMath::Min(nev-1, gOptNEvtH);
228  if(n2-n1 <0) {
229  LOG("gevdump", pFATAL) << "Invalid event range";
230  PrintSyntax();
231  gAbortingInErr = true;
232  exit(1);
233  }
234  }
235 }
void PrintSyntax(void)
Definition: gEvDump.cxx:290
#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
Long64_t gOptNEvtL
Definition: gEvDump.cxx:74
Long64_t gOptNEvtH
Definition: gEvDump.cxx:75
bool gAbortingInErr
Definition: Messenger.cxx:34
int main ( int  argc,
char **  argv 
)

Definition at line 79 of file gEvDump.cxx.

80 {
81  GetCommandLineArgs (argc, argv);
82 
83  // set print level
84  GHepRecord::SetPrintLevel(RunOpt::Instance()->EventRecordPrintLevel());
85 
86  // Add a dummy value to Dark Matter to allow reading DarkMatter files
87  PDGLibrary::Instance()->AddDarkMatter( 1.0, 0.5 );
88 
89  //
90  // open the ROOT file and get the TTree & its header
91  //
92 
93  TFile file(gOptInpFilename.c_str(),"READ");
94 
95  TTree * ghep_tree =
96  dynamic_cast <TTree *> (file.Get("gtree"));
97  if(!ghep_tree) {
98  LOG("gevdump", pFATAL)
99  << "No GHEP event tree in input file: " << gOptInpFilename;
100  gAbortingInErr=true;
101  exit(1);
102  }
103  Long64_t nev = ghep_tree->GetEntries();
104  LOG("gevdump", pFATAL)
105  << "Input GHEP event tree has " << nev
106  << ((nev==1) ? " entry." : " entries.");
107 
108  NtpMCTreeHeader * thdr =
109  dynamic_cast <NtpMCTreeHeader *> ( file.Get("header") );
110  LOG("gevdump", pNOTICE)
111  << "Input tree header: " << *thdr;
112 
113  //
114  // set branch addresses
115  //
116 
117  // main event record branch, always present
118  NtpMCEventRecord * mcrec = 0;
119  ghep_tree->SetBranchAddress("gmcrec", &mcrec);
120 
121  // if the event file was created by GENIE's gevpick `cherry-picking' app
122  // (see $GENIE/src/stdapp/gEvPick.cxx) then there will be additional branches
123  // holding the original event filename and event number (in that file)
124  // for each `cherry-picked' event.
125  bool have_gevpick_branches = false;
126  TObjString* orig_filename = 0;
127  Long64_t orig_evtnum;
128  TBranch * brOrigFilename = ghep_tree->GetBranch("orig_filename");
129  TBranch * brOrigEvtNum = ghep_tree->GetBranch("orig_evtnum");
130  if(brOrigFilename!=0 && brOrigEvtNum!=0) {
131  have_gevpick_branches = true;
132  brOrigFilename->SetAddress(&orig_filename);
133  brOrigEvtNum ->SetAddress(&orig_evtnum);
134  }
135 
136  // if the event file was created by one of GENIE's specialized event generation
137  // then there may be additional branches holding flux pass-through
138  // info (flux neutrino parent info for each generated event).
139 #ifdef __GENIE_FLUX_DRIVERS_ENABLED__
140  flux::GJPARCNuFluxPassThroughInfo * jparc_flux_info = 0;
141  flux::GNuMIFluxPassThroughInfo * gnumi_flux_info = 0;
142  TBranch * brFluxInfo = ghep_tree->GetBranch("flux");
143  if(brFluxInfo) {
144  TObjArray * leafarr = brFluxInfo->GetListOfLeaves();
145  TIter iter(leafarr);
146  TLeaf * leaf = 0;
147  while((leaf = (TLeaf*)iter.Next())) {
148  string ltypename = leaf->GetTypeName();
149  if(ltypename == "genie::flux::GJPARCNuFluxPassThroughInfo") {
150  brFluxInfo->SetAddress(&jparc_flux_info);
151  LOG("gevdump", pNOTICE)
152  << "Found JPARC neutrino flux pass-though info";
153  }
154  else
155  if(ltypename == "genie::flux::GNuMIFluxPassThroughInfo") {
156  brFluxInfo->SetAddress(&gnumi_flux_info);
157  LOG("gevdump", pNOTICE)
158  << "Found NuMI neutrino flux pass-though info";
159  }
160  }//leaf
161  }//flux branch
162 #endif
163 
164 
165  //
166  // event loop
167  //
168 
169  Long64_t n1,n2;
170  GetEventRange(nev,n1,n2);
171  for(Long64_t i = n1; i <= n2; i++) {
172  ghep_tree->GetEntry(i);
173 
174  // retrieve GHEP event record abd print it out.
175  NtpMCRecHeader rec_header = mcrec->hdr;
176  EventRecord & event = *(mcrec->event);
177  LOG("gevdump", pNOTICE)
178  << " ** Event: " << rec_header.ievent
179  << event;
180 
181  // print info from additional tree branches that might be present
182  // if the event file was created by GENIE's gevpick app.
183  if(have_gevpick_branches) {
184  LOG("gevdump", pNOTICE)
185  << "\n Above event was originally event: " << orig_evtnum
186  << "\n in event file: " << orig_filename->GetString().Data()
187  << "\n\n";
188  }
189 
190  // print info from additional JPARC or NuMI flux pass-through branches
191  // that might be present of the event file was created by GENIE's
192  // specialized event generation applications for T2K or NuMI-expts.
193 #ifdef __GENIE_FLUX_DRIVERS_ENABLED__
194  if(jparc_flux_info) {
195  LOG("gevdump", pNOTICE)
196  << "Associated JPARC flux pass-through info for above event:"
197  << *jparc_flux_info;
198  }
199  if(gnumi_flux_info) {
200  LOG("gevdump", pNOTICE)
201  << "Associated NuMI flux pass-through info for above event:"
202  << *gnumi_flux_info;
203  }
204 #endif
205 
206  mcrec->Clear();
207  }
208 
209  // clean-up
210 
211  file.Close();
212 
213  LOG("gevdump", pNOTICE) << "Done!";
214  return 0;
215 }
NtpMCRecHeader hdr
record header
Definition: NtpMCRecordI.h:38
void GetCommandLineArgs(int argc, char **argv)
Definition: gEvDump.cxx:237
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.
#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
unsigned int ievent
Event number.
MINOS-style Ntuple Class to hold an output MC Tree Header.
void GetEventRange(Long64_t nev, Long64_t &n1, Long64_t &n2)
Definition: gEvDump.cxx:217
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
MINOS-style Ntuple Class to hold an MC Event Record Header.
#define pNOTICE
Definition: Messenger.h:61
void Clear(Option_t *opt="")
bool gAbortingInErr
Definition: Messenger.cxx:34
EventRecord * event
event
void PrintSyntax ( void  )

Definition at line 290 of file gEvDump.cxx.

291 {
292  LOG("gevdump", pNOTICE)
293  << "\n\n" << "Syntax:" << "\n"
294  << " gevdump -f sample.root [-n n1[,n2]] [--event-record-print-level]\n";
295 }
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
#define pNOTICE
Definition: Messenger.h:61

Variable Documentation

string gOptInpFilename

Definition at line 76 of file gEvDump.cxx.

Long64_t gOptNEvtH

Definition at line 75 of file gEvDump.cxx.

Long64_t gOptNEvtL

Definition at line 74 of file gEvDump.cxx.