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 <NtpWriter.h>

Public Member Functions

 NtpWriter (NtpMCFormat_t fmt=kNFGHEP, Long_t runnu=0, Long_t runseed=-1)
 
 ~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...
 
Long_t fRunSeed
 run seed 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 <constantinos.andreopoulos cern.ch> University of Liverpool & STFC Rutherford Appleton Laboratory

October 1, 2004

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

Definition at line 39 of file NtpWriter.h.

Constructor & Destructor Documentation

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

Definition at line 35 of file NtpWriter.cxx.

35  :
36 fNtpFormat(fmt),
37 fRunNu(runnu),
38 fRunSeed(seed),
39 fOutFile(0),
40 fOutTree(0),
41 fEventBranch(0),
44 {
45  LOG("Ntp", pNOTICE) << "Run number: " << runnu;
46  LOG("Ntp", pNOTICE)
47  << "Requested G/ROOT tree format: " << NtpMCFormat::AsString(fNtpFormat);
48 
49  this->SetDefaultFilename();
50 }
void SetDefaultFilename(string filename_prefix="gntp")
Definition: NtpWriter.cxx:138
NtpMCFormat_t fNtpFormat
enumeration of event formats
Definition: NtpWriter.h:71
TFile * fOutFile
output file
Definition: NtpWriter.h:75
NtpMCTreeHeader * fNtpMCTreeHeader
Definition: NtpWriter.h:79
TBranch * fEventBranch
the generated event branch
Definition: NtpWriter.h:77
Long_t fRunSeed
run seed
Definition: NtpWriter.h:73
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
static const char * AsString(NtpMCFormat_t fmt)
Definition: NtpMCFormat.h:36
TTree * fOutTree
output tree
Definition: NtpWriter.h:76
#define pNOTICE
Definition: Messenger.h:61
Long_t fRunNu
run nu
Definition: NtpWriter.h:72
NtpMCEventRecord * fNtpMCEventRecord
Definition: NtpWriter.h:78
NtpWriter::~NtpWriter ( )

initialize the ntuple writer

Definition at line 52 of file NtpWriter.cxx.

53 {
54 
55 }

Member Function Documentation

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

save the event tree

Definition at line 57 of file NtpWriter.cxx.

58 {
59  LOG("Ntp", pINFO) << "Adding event " << ievent << " to output tree";
60 
61  if(!ev_rec) {
62  LOG("Ntp", pERROR) << "NULL input EventRecord!";
63  return;
64  }
65  if(!fOutTree) {
66  LOG("Ntp", pERROR) << "No open output TTree to add the input EventRecord!";
67  return;
68  }
69 
70  switch (fNtpFormat) {
71  case kNFGHEP:
73  fNtpMCEventRecord->Fill(ievent, ev_rec);
74  fOutTree->Fill();
75  delete fNtpMCEventRecord;
77  break;
78  default:
79  break;
80  }
81 }
#define pERROR
Definition: Messenger.h:59
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:71
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
#define pINFO
Definition: Messenger.h:62
TTree * fOutTree
output tree
Definition: NtpWriter.h:76
NtpMCEventRecord * fNtpMCEventRecord
Definition: NtpWriter.h:78
void NtpWriter::CreateEventBranch ( void  )
private

Definition at line 175 of file NtpWriter.cxx.

176 {
177  switch (fNtpFormat) {
178  case kNFGHEP:
179  this->CreateGHEPEventBranch();
180  break;
181  default:
182  LOG("Ntp", pERROR)
183  << "Unknown TTree format. Can not create TBranches";
184  break;
185  }
186  assert(fEventBranch);
187  fEventBranch->SetAutoDelete(kFALSE);
188 }
#define pERROR
Definition: Messenger.h:59
void CreateGHEPEventBranch(void)
Definition: NtpWriter.cxx:190
NtpMCFormat_t fNtpFormat
enumeration of event formats
Definition: NtpWriter.h:71
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:96
void NtpWriter::CreateGHEPEventBranch ( void  )
private

Definition at line 190 of file NtpWriter.cxx.

191 {
192  LOG("Ntp", pINFO) << "Creating a NtpMCEventRecord TBranch";
193 
194  fNtpMCEventRecord = 0;
195  TTree::SetBranchStyle(1);
196 
197 #if ROOT_VERSION_CODE >= ROOT_VERSION(6,0,0)
198  int split = 0;
199 #else
200  int split = 1;
201 #endif
202 
203  fEventBranch = fOutTree->Branch("gmcrec",
204  "genie::NtpMCEventRecord", &fNtpMCEventRecord, 32000, split);
205  // was split=1 ... but, at least w/ ROOT 6.06/04, this generates
206  // Warning in <TTree::Bronch>: genie::NtpMCEventRecord cannot be split, resetting splitlevel to 0
207  // which the art framework turns into a fatal error
208 }
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:96
#define pINFO
Definition: Messenger.h:62
TTree * fOutTree
output tree
Definition: NtpWriter.h:76
void split(std::string const &s, char c, OutIter dest)
Definition: split.h:35
NtpMCEventRecord * fNtpMCEventRecord
Definition: NtpWriter.h:78
void NtpWriter::CreateTree ( void  )
private

Definition at line 161 of file NtpWriter.cxx.

162 {
163  if(fOutTree) delete fOutTree;
164 
165  LOG("Ntp", pINFO) << "Creating the output GENIE/ROOT tree";
166 
167  ostringstream title;
168  title << "GENIE MC Truth TTree"
169  << ", Format: " << NtpMCFormat::AsString(fNtpFormat);
170 
171  fOutTree = new TTree("gtree",title.str().c_str());
172  fOutTree->SetAutoSave(200000000); // autosave when 0.2 Gbyte written
173 }
NtpMCFormat_t fNtpFormat
enumeration of event formats
Definition: NtpWriter.h:71
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
#define pINFO
Definition: Messenger.h:62
static const char * AsString(NtpMCFormat_t fmt)
Definition: NtpMCFormat.h:36
TTree * fOutTree
output tree
Definition: NtpWriter.h:76
void NtpWriter::CreateTreeHeader ( void  )
private

Definition at line 210 of file NtpWriter.cxx.

211 {
212  LOG("Ntp", pINFO) << "Creating the NtpMCTreeHeader";
213 
215 
217 
221 
222  LOG("Ntp", pINFO) << *fNtpMCTreeHeader;
223 }
NtpMCFormat_t fNtpFormat
enumeration of event formats
Definition: NtpWriter.h:71
NtpMCTreeHeader * fNtpMCTreeHeader
Definition: NtpWriter.h:79
Long_t fRunSeed
run seed
Definition: NtpWriter.h:73
#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.
#define pINFO
Definition: Messenger.h:62
Long_t runnu
MC Job run number.
NtpMCFormat_t format
Event Record format (GENIE support multiple formats)
Long_t runseed
Random seed used in the MC run.
Long_t fRunNu
run nu
Definition: NtpWriter.h:72
void NtpWriter::CustomizeFilename ( string  filename)

Definition at line 128 of file NtpWriter.cxx.

129 {
131 }
string fOutFilename
output filename
Definition: NtpWriter.h:74
string filename
Definition: train.py:213
void NtpWriter::CustomizeFilenamePrefix ( string  prefix)

Definition at line 133 of file NtpWriter.cxx.

134 {
135  this->SetDefaultFilename(prefix);
136 }
void SetDefaultFilename(string filename_prefix="gntp")
Definition: NtpWriter.cxx:138
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 55 of file NtpWriter.h.

void NtpWriter::Initialize ( void  )

add event

Definition at line 83 of file NtpWriter.cxx.

84 {
85  LOG("Ntp",pINFO) << "Initializing GENIE output MC tree";
86 
87  this->OpenFile(fOutFilename); // open ROOT file
88  this->CreateTree(); // create output tree
89 
90  //-- create the event branch
91  this->CreateEventBranch();
92 
93  //-- create the tree header
94  this->CreateTreeHeader();
95  //-- update the tune name (and associated directories) from RunOpt
96  // (keep header from RunOpt entanglement)
97  string tunename("unknown");
98  string tuneDir("unknown");
99  string customDirs("");
100  TuneId* tuneId = RunOpt::Instance()->Tune();
101  if ( ! tuneId ) {
102  LOG("Ntp", pERROR)
103  << "No TuneId is available from RunOpt";
104  } else {
105  tunename = tuneId->Name();
106  tuneDir = tuneId->TuneDirectory();
107  if ( tuneId->IsCustom() ) {
108  tunename += "*"; // flag it as possibly modified
109  customDirs = tuneId->CustomSource();
110  }
111  }
112  fNtpMCTreeHeader->tune.SetString(tunename.c_str());
113  fNtpMCTreeHeader->tuneDir.SetString(tuneDir.c_str());
114  fNtpMCTreeHeader->customDirs.SetString(customDirs.c_str());
115 
116  //-- write the tree header
117  fNtpMCTreeHeader->Write();
118 
119  //-- save GENIE configuration for this MC Job
120  NtpMCJobConfig configuration;
121  configuration.Load()->Write();
122 
123  //-- take a snapshot of the user's environment
124  NtpMCJobEnv environment;
125  environment.TakeSnapshot()->Write();
126 }
Stores the GENIE configuration in ROOT TFolders along with the output event tree. ...
TuneId * Tune(void) const
Definition: RunOpt.h:44
string Name(void) const
Definition: TuneId.h:46
void OpenFile(string filename)
Definition: NtpWriter.cxx:149
void CreateTree(void)
Definition: NtpWriter.cxx:161
#define pERROR
Definition: Messenger.h:59
Stores a snapshot of your environment in ROOT TFolder along with the output event tree...
Definition: NtpMCJobEnv.h:26
TObjString tune
GENIE Tune Name.
bool IsCustom(void) const
Definition: TuneId.h:62
string fOutFilename
output filename
Definition: NtpWriter.h:74
NtpMCTreeHeader * fNtpMCTreeHeader
Definition: NtpWriter.h:79
TObjString tuneDir
directory from when tune config came
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
string TuneDirectory(void) const
Definition: TuneId.cxx:116
void CreateEventBranch(void)
Definition: NtpWriter.cxx:175
string CustomSource(void) const
Definition: TuneId.h:77
#define pINFO
Definition: Messenger.h:62
void CreateTreeHeader(void)
Definition: NtpWriter.cxx:210
TObjString customDirs
any custom directories
static RunOpt * Instance(void)
Definition: RunOpt.cxx:54
TFolder * Load(void)
GENIE tune ID.
Definition: TuneId.h:37
TFolder * TakeSnapshot(void)
Definition: NtpMCJobEnv.cxx:41
void NtpWriter::OpenFile ( string  filename)
private

Definition at line 149 of file NtpWriter.cxx.

150 {
151  if(fOutFile) delete fOutFile;
152 
153  LOG("Ntp", pINFO)
154  << "Opening the output ROOT file: " << filename;
155 
156  // use "TFile::Open()" instead of "new TFile()" so that it can handle
157  // alternative URLs (e.g. xrootd, etc)
158  fOutFile = TFile::Open(filename.c_str(),"RECREATE");
159 }
TFile * fOutFile
output file
Definition: NtpWriter.h:75
string filename
Definition: train.py:213
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
#define pINFO
Definition: Messenger.h:62
void NtpWriter::Save ( void  )

get the even tree

Definition at line 225 of file NtpWriter.cxx.

226 {
227  LOG("Ntp", pINFO) << "Saving the output tree";
228 
229  if(fOutFile) {
230 
231  fOutFile->Write();
232  fOutFile->Close();
233  delete fOutFile;
234  fOutFile = 0;
235 
236  } else {
237  LOG("Ntp", pERROR) << "No open ROOT file was found";
238  }
239 }
#define pERROR
Definition: Messenger.h:59
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:96
#define pINFO
Definition: Messenger.h:62
void NtpWriter::SetDefaultFilename ( string  filename_prefix = "gntp")
private

Definition at line 138 of file NtpWriter.cxx.

139 {
140  ostringstream fnstr;
141  fnstr << filename_prefix << "."
142  << fRunNu << "."
144  << ".root";
145 
146  fOutFilename = fnstr.str();
147 }
NtpMCFormat_t fNtpFormat
enumeration of event formats
Definition: NtpWriter.h:71
string fOutFilename
output filename
Definition: NtpWriter.h:74
static const char * FilenameTag(NtpMCFormat_t fmt)
Definition: NtpMCFormat.h:50
Long_t fRunNu
run nu
Definition: NtpWriter.h:72

Member Data Documentation

TBranch* genie::NtpWriter::fEventBranch
private

the generated event branch

Definition at line 77 of file NtpWriter.h.

NtpMCFormat_t genie::NtpWriter::fNtpFormat
private

enumeration of event formats

Definition at line 71 of file NtpWriter.h.

NtpMCEventRecord* genie::NtpWriter::fNtpMCEventRecord
private

Definition at line 78 of file NtpWriter.h.

NtpMCTreeHeader* genie::NtpWriter::fNtpMCTreeHeader
private

Definition at line 79 of file NtpWriter.h.

TFile* genie::NtpWriter::fOutFile
private

output file

Definition at line 75 of file NtpWriter.h.

string genie::NtpWriter::fOutFilename
private

output filename

Definition at line 74 of file NtpWriter.h.

TTree* genie::NtpWriter::fOutTree
private

output tree

Definition at line 76 of file NtpWriter.h.

Long_t genie::NtpWriter::fRunNu
private

run nu

Definition at line 72 of file NtpWriter.h.

Long_t genie::NtpWriter::fRunSeed
private

run seed

Definition at line 73 of file NtpWriter.h.


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