Public Member Functions | Private Member Functions | Private Attributes | List of all members
genie::NtpWriter Class Reference

A utility class to facilitate creating the GENIE MC Ntuple from the output GENIE GHEP event records. More...

#include "/cvmfs/nova.opensciencegrid.org/externals/genie/v3_00_06_p01/Linux64bit+2.6-2.12-e17-debug/GENIE-Generator/src/Framework/Ntuple/NtpWriter.h"

Public Member Functions

 NtpWriter (NtpMCFormat_t fmt=kNFGHEP, Long_t runnu=0)
 
 ~NtpWriter ()
 initialize the ntuple writer More...
 
void Initialize (void)
 add event More...
 
void AddEventRecord (int ievent, const EventRecord *ev_rec)
 save the event tree More...
 
void Save (void)
 get the even tree More...
 
TTree * EventTree (void)
 
void CustomizeFilename (string filename)
 
void CustomizeFilenamePrefix (string prefix)
 

Private Member Functions

void SetDefaultFilename (string filename_prefix="gntp")
 
void OpenFile (string filename)
 
void CreateTree (void)
 
void CreateTreeHeader (void)
 
void CreateEventBranch (void)
 
void CreateGHEPEventBranch (void)
 

Private Attributes

NtpMCFormat_t fNtpFormat
 enumeration of event formats More...
 
Long_t fRunNu
 run nu More...
 
string fOutFilename
 output filename More...
 
TFile * fOutFile
 output file More...
 
TTree * fOutTree
 output tree More...
 
TBranch * fEventBranch
 the generated event branch More...
 
NtpMCEventRecordfNtpMCEventRecord
 
NtpMCTreeHeaderfNtpMCTreeHeader
 

Detailed Description

A utility class to facilitate creating the GENIE MC Ntuple from the output GENIE GHEP event records.

Author
Costas Andreopoulos <costas.andreopoulos stfc.ac.uk> University of Liverpool & STFC Rutherford Appleton Lab

October 1, 2004

Copyright (c) 2003-2019, The GENIE Collaboration For the full text of the license visit http://copyright.genie-mc.org or see $GENIE/LICENSE

Definition at line 40 of file NtpWriter.h.

Constructor & Destructor Documentation

NtpWriter::NtpWriter ( NtpMCFormat_t  fmt = kNFGHEP,
Long_t  runnu = 0 
)

Definition at line 48 of file NtpWriter.cxx.

References genie::NtpMCFormat::AsString(), fNtpFormat, LOG, pNOTICE, and SetDefaultFilename().

48  :
50 fRunNu(runnu),
51 fOutFile(0),
52 fOutTree(0),
53 fEventBranch(0),
56 {
57  LOG("Ntp", pNOTICE) << "Run number: " << runnu;
58  LOG("Ntp", pNOTICE)
59  << "Requested G/ROOT tree format: " << NtpMCFormat::AsString(fNtpFormat);
60 
61  this->SetDefaultFilename();
62 }
void SetDefaultFilename(string filename_prefix="gntp")
Definition: NtpWriter.cxx:128
NtpMCFormat_t fNtpFormat
enumeration of event formats
Definition: NtpWriter.h:72
TFile * fOutFile
output file
Definition: NtpWriter.h:75
NtpMCTreeHeader * fNtpMCTreeHeader
Definition: NtpWriter.h:79
TBranch * fEventBranch
the generated event branch
Definition: NtpWriter.h:77
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:97
static const char * AsString(NtpMCFormat_t fmt)
Definition: NtpMCFormat.h:37
TTree * fOutTree
output tree
Definition: NtpWriter.h:76
#define pNOTICE
Definition: Messenger.h:62
Long_t fRunNu
run nu
Definition: NtpWriter.h:73
NtpMCEventRecord * fNtpMCEventRecord
Definition: NtpWriter.h:78
NtpWriter::~NtpWriter ( )

initialize the ntuple writer

Definition at line 64 of file NtpWriter.cxx.

65 {
66 
67 }

Member Function Documentation

void NtpWriter::AddEventRecord ( int  ievent,
const EventRecord ev_rec 
)

save the event tree

Definition at line 69 of file NtpWriter.cxx.

References genie::NtpMCEventRecord::Fill(), fNtpFormat, fNtpMCEventRecord, fOutTree, genie::kNFGHEP, LOG, pERROR, and pINFO.

Referenced by ConvertToGHepMock(), GenerateEventsAtFixedInitState(), main(), and RunCherryPicker().

70 {
71  LOG("Ntp", pINFO) << "Adding event " << ievent << " to output tree";
72 
73  if(!ev_rec) {
74  LOG("Ntp", pERROR) << "NULL input EventRecord!";
75  return;
76  }
77  if(!fOutTree) {
78  LOG("Ntp", pERROR) << "No open output TTree to add the input EventRecord!";
79  return;
80  }
81 
82  switch (fNtpFormat) {
83  case kNFGHEP:
85  fNtpMCEventRecord->Fill(ievent, ev_rec);
86  fOutTree->Fill();
87  delete fNtpMCEventRecord;
89  break;
90  default:
91  break;
92  }
93 }
#define pERROR
Definition: Messenger.h:60
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 Fill(unsigned int ievent, const EventRecord *ev_rec)
NtpMCFormat_t fNtpFormat
enumeration of event formats
Definition: NtpWriter.h:72
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:97
#define pINFO
Definition: Messenger.h:63
TTree * fOutTree
output tree
Definition: NtpWriter.h:76
NtpMCEventRecord * fNtpMCEventRecord
Definition: NtpWriter.h:78
void NtpWriter::CreateEventBranch ( void  )
private

Definition at line 165 of file NtpWriter.cxx.

References ana::assert(), CreateGHEPEventBranch(), fEventBranch, fNtpFormat, genie::kNFGHEP, LOG, and pERROR.

Referenced by EventTree(), and Initialize().

166 {
167  switch (fNtpFormat) {
168  case kNFGHEP:
169  this->CreateGHEPEventBranch();
170  break;
171  default:
172  LOG("Ntp", pERROR)
173  << "Unknown TTree format. Can not create TBranches";
174  break;
175  }
177  fEventBranch->SetAutoDelete(kFALSE);
178 }
#define pERROR
Definition: Messenger.h:60
void CreateGHEPEventBranch(void)
Definition: NtpWriter.cxx:180
NtpMCFormat_t fNtpFormat
enumeration of event formats
Definition: NtpWriter.h:72
TBranch * fEventBranch
the generated event branch
Definition: NtpWriter.h:77
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:97
assert(nhit_max >=nhit_nbins)
void NtpWriter::CreateGHEPEventBranch ( void  )
private

Definition at line 180 of file NtpWriter.cxx.

References fEventBranch, fNtpMCEventRecord, fOutTree, LOG, pINFO, and split().

Referenced by CreateEventBranch(), and EventTree().

181 {
182  LOG("Ntp", pINFO) << "Creating a NtpMCEventRecord TBranch";
183 
184  fNtpMCEventRecord = 0;
185  TTree::SetBranchStyle(1);
186 
187 #if ROOT_VERSION_CODE >= ROOT_VERSION(6,0,0)
188  int split = 0;
189 #else
190  int split = 1;
191 #endif
192 
193  fEventBranch = fOutTree->Branch("gmcrec",
194  "genie::NtpMCEventRecord", &fNtpMCEventRecord, 32000, split);
195  // was split=1 ... but, at least w/ ROOT 6.06/04, this generates
196  // Warning in <TTree::Bronch>: genie::NtpMCEventRecord cannot be split, resetting splitlevel to 0
197  // which the art framework turns into a fatal error
198 }
void split(double tt, double *fr)
TBranch * fEventBranch
the generated event branch
Definition: NtpWriter.h:77
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:97
#define pINFO
Definition: Messenger.h:63
TTree * fOutTree
output tree
Definition: NtpWriter.h:76
NtpMCEventRecord * fNtpMCEventRecord
Definition: NtpWriter.h:78
void NtpWriter::CreateTree ( void  )
private

Definition at line 151 of file NtpWriter.cxx.

References genie::NtpMCFormat::AsString(), fNtpFormat, fOutTree, LOG, pINFO, and plotROC::title.

Referenced by EventTree(), and Initialize().

152 {
153  if(fOutTree) delete fOutTree;
154 
155  LOG("Ntp", pINFO) << "Creating the output GENIE/ROOT tree";
156 
157  ostringstream title;
158  title << "GENIE MC Truth TTree"
159  << ", Format: " << NtpMCFormat::AsString(fNtpFormat);
160 
161  fOutTree = new TTree("gtree",title.str().c_str());
162  fOutTree->SetAutoSave(200000000); // autosave when 0.2 Gbyte written
163 }
NtpMCFormat_t fNtpFormat
enumeration of event formats
Definition: NtpWriter.h:72
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:97
#define pINFO
Definition: Messenger.h:63
static const char * AsString(NtpMCFormat_t fmt)
Definition: NtpMCFormat.h:37
TTree * fOutTree
output tree
Definition: NtpWriter.h:76
void NtpWriter::CreateTreeHeader ( void  )
private

Definition at line 200 of file NtpWriter.cxx.

References fNtpFormat, fNtpMCTreeHeader, genie::NtpMCTreeHeader::format, fRunNu, LOG, pINFO, and genie::NtpMCTreeHeader::runnu.

Referenced by EventTree(), and Initialize().

201 {
202  LOG("Ntp", pINFO) << "Creating the NtpMCTreeHeader";
203 
205 
207 
210 
211  LOG("Ntp", pINFO) << *fNtpMCTreeHeader;
212 }
NtpMCFormat_t fNtpFormat
enumeration of event formats
Definition: NtpWriter.h:72
NtpMCTreeHeader * fNtpMCTreeHeader
Definition: NtpWriter.h:79
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:97
MINOS-style Ntuple Class to hold an output MC Tree Header.
#define pINFO
Definition: Messenger.h:63
Long_t runnu
MC Job run number.
NtpMCFormat_t format
Event Record format (GENIE support multiple formats)
Long_t fRunNu
run nu
Definition: NtpWriter.h:73
void NtpWriter::CustomizeFilename ( string  filename)

Definition at line 118 of file NtpWriter.cxx.

References shutoffs::filename, and fOutFilename.

Referenced by ConvertToGHepMock(), EventTree(), GenerateEventsAtFixedInitState(), and RunCherryPicker().

119 {
121 }
string filename
Definition: shutoffs.py:106
string fOutFilename
output filename
Definition: NtpWriter.h:74
void NtpWriter::CustomizeFilenamePrefix ( string  prefix)

Definition at line 123 of file NtpWriter.cxx.

References SetDefaultFilename().

Referenced by EventTree(), and main().

124 {
125  this->SetDefaultFilename(prefix);
126 }
void SetDefaultFilename(string filename_prefix="gntp")
Definition: NtpWriter.cxx:128
const XML_Char * prefix
Definition: expat.h:380
TTree* genie::NtpWriter::EventTree ( void  )
inline

use before Initialize() only if you wish to override the default filename, or the default filename prefix

Definition at line 56 of file NtpWriter.h.

References CreateEventBranch(), CreateGHEPEventBranch(), CreateTree(), CreateTreeHeader(), CustomizeFilename(), CustomizeFilenamePrefix(), shutoffs::filename, fOutTree, OpenFile(), and SetDefaultFilename().

Referenced by main(), and RunCherryPicker().

void NtpWriter::Initialize ( void  )

add event

Definition at line 95 of file NtpWriter.cxx.

References CreateEventBranch(), CreateTree(), CreateTreeHeader(), fNtpMCTreeHeader, fOutFilename, genie::NtpMCJobConfig::Load(), LOG, OpenFile(), pINFO, and genie::NtpMCJobEnv::TakeSnapshot().

Referenced by ConvertToGHepMock(), GenerateEventsAtFixedInitState(), main(), and RunCherryPicker().

96 {
97  LOG("Ntp",pINFO) << "Initializing GENIE output MC tree";
98 
99  this->OpenFile(fOutFilename); // open ROOT file
100  this->CreateTree(); // create output tree
101 
102  //-- create the event branch
103  this->CreateEventBranch();
104 
105  //-- create the tree header
106  this->CreateTreeHeader();
107  fNtpMCTreeHeader->Write();
108 
109  //-- save GENIE configuration for this MC Job
110  NtpMCJobConfig configuration;
111  configuration.Load()->Write();
112 
113  //-- take a snapshot of the user's environment
114  NtpMCJobEnv environment;
115  environment.TakeSnapshot()->Write();
116 }
Stores the GENIE configuration in ROOT TFolders along with the output event tree. ...
void OpenFile(string filename)
Definition: NtpWriter.cxx:139
void CreateTree(void)
Definition: NtpWriter.cxx:151
Stores a snapshot of your environment in ROOT TFolder along with the output event tree...
Definition: NtpMCJobEnv.h:27
string fOutFilename
output filename
Definition: NtpWriter.h:74
NtpMCTreeHeader * fNtpMCTreeHeader
Definition: NtpWriter.h:79
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:97
void CreateEventBranch(void)
Definition: NtpWriter.cxx:165
#define pINFO
Definition: Messenger.h:63
void CreateTreeHeader(void)
Definition: NtpWriter.cxx:200
TFolder * Load(void)
TFolder * TakeSnapshot(void)
Definition: NtpMCJobEnv.cxx:47
void NtpWriter::OpenFile ( string  filename)
private

Definition at line 139 of file NtpWriter.cxx.

References shutoffs::filename, fOutFile, LOG, and pINFO.

Referenced by EventTree(), and Initialize().

140 {
141  if(fOutFile) delete fOutFile;
142 
143  LOG("Ntp", pINFO)
144  << "Opening the output ROOT file: " << filename;
145 
146  // use "TFile::Open()" instead of "new TFile()" so that it can handle
147  // alternative URLs (e.g. xrootd, etc)
148  fOutFile = TFile::Open(filename.c_str(),"RECREATE");
149 }
string filename
Definition: shutoffs.py:106
TFile * fOutFile
output file
Definition: NtpWriter.h:75
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:97
#define pINFO
Definition: Messenger.h:63
void NtpWriter::Save ( void  )

get the even tree

Definition at line 214 of file NtpWriter.cxx.

References fOutFile, LOG, pERROR, and pINFO.

Referenced by ConvertToGHepMock(), GenerateEventsAtFixedInitState(), main(), and RunCherryPicker().

215 {
216  LOG("Ntp", pINFO) << "Saving the output tree";
217 
218  if(fOutFile) {
219 
220  fOutFile->Write();
221  fOutFile->Close();
222  delete fOutFile;
223  fOutFile = 0;
224 
225  } else {
226  LOG("Ntp", pERROR) << "No open ROOT file was found";
227  }
228 }
#define pERROR
Definition: Messenger.h:60
TFile * fOutFile
output file
Definition: NtpWriter.h:75
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:97
#define pINFO
Definition: Messenger.h:63
void NtpWriter::SetDefaultFilename ( string  filename_prefix = "gntp")
private

Definition at line 128 of file NtpWriter.cxx.

References genie::NtpMCFormat::FilenameTag(), fNtpFormat, fOutFilename, and fRunNu.

Referenced by CustomizeFilenamePrefix(), EventTree(), and NtpWriter().

129 {
130  ostringstream fnstr;
131  fnstr << filename_prefix << "."
132  << fRunNu << "."
134  << ".root";
135 
136  fOutFilename = fnstr.str();
137 }
NtpMCFormat_t fNtpFormat
enumeration of event formats
Definition: NtpWriter.h:72
string fOutFilename
output filename
Definition: NtpWriter.h:74
static const char * FilenameTag(NtpMCFormat_t fmt)
Definition: NtpMCFormat.h:51
Long_t fRunNu
run nu
Definition: NtpWriter.h:73

Member Data Documentation

TBranch* genie::NtpWriter::fEventBranch
private

the generated event branch

Definition at line 77 of file NtpWriter.h.

Referenced by CreateEventBranch(), and CreateGHEPEventBranch().

NtpMCFormat_t genie::NtpWriter::fNtpFormat
private

enumeration of event formats

Definition at line 72 of file NtpWriter.h.

Referenced by AddEventRecord(), CreateEventBranch(), CreateTree(), CreateTreeHeader(), NtpWriter(), and SetDefaultFilename().

NtpMCEventRecord* genie::NtpWriter::fNtpMCEventRecord
private

Definition at line 78 of file NtpWriter.h.

Referenced by AddEventRecord(), and CreateGHEPEventBranch().

NtpMCTreeHeader* genie::NtpWriter::fNtpMCTreeHeader
private

Definition at line 79 of file NtpWriter.h.

Referenced by CreateTreeHeader(), and Initialize().

TFile* genie::NtpWriter::fOutFile
private

output file

Definition at line 75 of file NtpWriter.h.

Referenced by OpenFile(), and Save().

string genie::NtpWriter::fOutFilename
private

output filename

Definition at line 74 of file NtpWriter.h.

Referenced by CustomizeFilename(), Initialize(), and SetDefaultFilename().

TTree* genie::NtpWriter::fOutTree
private

output tree

Definition at line 76 of file NtpWriter.h.

Referenced by AddEventRecord(), CreateGHEPEventBranch(), CreateTree(), and EventTree().

Long_t genie::NtpWriter::fRunNu
private

run nu

Definition at line 73 of file NtpWriter.h.

Referenced by CreateTreeHeader(), and SetDefaultFilename().


The documentation for this class was generated from the following files: