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

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 
)
void GetEventRange ( Long64_t  nev,
Long64_t &  n1,
Long64_t &  n2 
)

Definition at line 217 of file gEvDump.cxx.

References genie::gAbortingInErr, gOptNEvtH, gOptNEvtL, LOG, pFATAL, and PrintSyntax().

Referenced by main().

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

Definition at line 79 of file gEvDump.cxx.

References genie::PDGLibrary::AddDarkMatter(), genie::NtpMCEventRecord::Clear(), genie::NtpMCEventRecord::event, genie::gAbortingInErr, GetCommandLineArgs(), GetEventRange(), gOptInpFilename, genie::NtpMCRecordI::hdr, genie::NtpMCRecHeader::ievent, genie::RunOpt::Instance(), genie::PDGLibrary::Instance(), LOG, pFATAL, pNOTICE, and genie::GHepRecord::SetPrintLevel().

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
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 GetCommandLineArgs(int argc, char **argv)
Definition: gAtmoEvGen.cxx:563
void Clear(Option_t *opt="")
bool gAbortingInErr
Definition: Messenger.cxx:34
EventRecord * event
event
void PrintSyntax ( void  )

Variable Documentation

string gOptInpFilename

Definition at line 76 of file gEvDump.cxx.

Referenced by main().

Long64_t gOptNEvtH

Definition at line 75 of file gEvDump.cxx.

Referenced by GetEventRange(), and main().

Long64_t gOptNEvtL

Definition at line 74 of file gEvDump.cxx.

Referenced by GetEventRange(), and main().