eic-smear  1.0.3
A collection of ROOT classes for Monte Carlo events and a fast-smearing code simulating detector effects for the Electron-Ion Collider task force
Forester.h
Go to the documentation of this file.
1 
10 #ifndef INCLUDE_EICSMEAR_ERHIC_FORESTER_H_
11 #define INCLUDE_EICSMEAR_ERHIC_FORESTER_H_
12 
13 // C(++) headers
14 #include <cmath>
15 #include <ctime>
16 #include <fstream>
17 #include <iomanip>
18 #include <iostream>
19 #include <string>
20 
21 // ROOT headers
22 #include <Rtypes.h>
23 #include <TFile.h>
24 #include <TStopwatch.h>
25 #include <TTree.h>
26 
27 // Other headers
28 #include "eicsmear/erhic/EventMC.h"
29 
30 namespace erhic {
31 
32 class FileType;
33 class VirtualEventFactory;
34 
35 
40 class Forester : public TObject {
41  public:
45  Forester();
46 
50  virtual ~Forester();
51 
56  Long64_t Plant();
57 
61  void SetInputFileName(const std::string&);
62 
66  void SetOutputFileName(const std::string&);
67 
72  void SetTreeName(const std::string& = "EICTree");
73 
78  void SetBranchName(const std::string& = "event");
79 
83  std::string GetInputFileName() const;
84 
88  std::string GetOutputFileName() const;
89 
94  std::string GetTreeName() const;
95 
99  std::string GetBranchName() const;
100 
107  void SetMaxNEvents(Long64_t = 0);
108 
112  Long64_t GetMaxNEvents() const;
113 
118  void SetMessageInterval(Long64_t = 10000);
119 
123  void Print(std::ostream& stream) const;
124 
130  void Print(Option_t* = "not used") const;
131 
136  void SetBeVerbose(bool = false);
137 
141  bool BeVerbose() const;
142 
148  const erhic::FileType* GetFileType() const;
149 
154  class Status{
155  public:
156  Status();
157  virtual ~Status();
158  virtual std::ostream& Print(std::ostream& os = std::cout) const;
159 
160  protected:
161  virtual void StartTimer();
162  virtual void StopTimer();
163  virtual void ModifyEventCount(Long64_t count);
164  virtual void ModifyParticleCount(Long64_t count);
165 
166  time_t mStartTime;
167  time_t mEndTime;
168  Long64_t mNEvents;
169  Long64_t mNParticles;
170 
171  // The TStopwatch is mutable as "GetRealTime()" is non-const.
172  mutable TStopwatch mTimer;
173 
174  friend class Forester;
175 
176  ClassDef(Status, 1);
177  };
178 
179  protected:
184  const Status& GetGetStatus() const {
185  return mStatus;
186  }
187 
194  bool OpenInput();
195 
199  bool SetupOutput();
200 
204  void Finish();
205 
211  bool AllocateEvent();
212 
219  bool FindFirstEvent();
220 
222  void PrintStatus() const;
223 
230  bool MustQuit() const;
231 
233  void SetMustQuit(bool quit);
234 
235  // Member variables.
236  // Those with comment //! will be treated as transient members by ROOT
237  // and won't be written to a file.
238  // IMPORTANT: There MUST be a space after //!
239 
240  Bool_t mQuit;
241  Bool_t mVerbose;
242  TTree* mTree;
245  TFile* mRootFile;
246  Long64_t mMaxNEvents;
247  Long64_t mInterval;
248 
249  std::ifstream* mTextFile;
250  std::string mInputName;
251  std::string mOutputName;
252  std::string mTreeName;
253  std::string mBranchName;
254  std::string mLine;
257 
258  ClassDef(Forester, 3)
259 };
260 
261 inline void Forester::SetInputFileName(const std::string& name) {
262  mInputName = name;
263 }
264 
265 inline void Forester::SetOutputFileName(const std::string& name) {
266  mOutputName = name;
267 }
268 
269 inline void Forester::SetTreeName(const std::string& name) {
270  mTreeName = name;
271 }
272 
273 inline void Forester::SetBranchName(const std::string& name) {
274  mBranchName = name;
275 }
276 
277 inline std::string Forester::GetInputFileName() const {
278  return mInputName;
279 }
280 
281 inline std::string Forester::GetOutputFileName() const {
282  return mOutputName;
283 }
284 
285 inline std::string Forester::GetTreeName() const {
286  return mTreeName;
287 }
288 
289 inline std::string Forester::GetBranchName() const {
290  return mBranchName;
291 }
292 
293 inline void Forester::SetMaxNEvents(Long64_t number) {
294  mMaxNEvents = number;
295 }
296 
297 inline Long64_t Forester::GetMaxNEvents() const {
298  return mMaxNEvents;
299 }
300 
301 inline void Forester::SetMessageInterval(Long64_t number) {
302  mInterval = number;
303 }
304 
305 inline bool Forester::MustQuit() const {
306  return mQuit;
307 }
308 
309 inline void Forester::SetMustQuit(bool flag) {
310  mQuit = flag;
311 }
312 
313 inline void Forester::SetBeVerbose(bool flag) {
314  mVerbose = flag;
315 }
316 
317 inline bool Forester::BeVerbose() const {
318  return mVerbose;
319 }
320 
321 inline const FileType* Forester::GetFileType() const {
322  return mFile;
323 }
324 
325 } // namespace erhic
326 
327 #endif // INCLUDE_EICSMEAR_ERHIC_FORESTER_H_
erhic::Forester::mFile
const erhic::FileType * mFile
< Stores event branch address
Definition: Forester.h:244
erhic::Forester::Forester
Forester()
Default constructor.
Definition: Forester.cxx:25
erhic::Forester::Status::mEndTime
time_t mEndTime
Definition: Forester.h:167
erhic::Forester::Finish
void Finish()
Writes output and takes end-of-file actions.
Definition: Forester.cxx:191
erhic::Forester::BeVerbose
bool BeVerbose() const
Returns the verbosity i.e.
Definition: Forester.h:317
erhic
Definition: EventDis.cxx:14
erhic::Forester::mEvent
VirtualEvent * mEvent
< Output TTree, owned by mRootFile
Definition: Forester.h:243
erhic::Forester::mMaxNEvents
Long64_t mMaxNEvents
< Pointer to output ROOT file
Definition: Forester.h:246
erhic::Forester::Status::~Status
virtual ~Status()
Definition: Forester.cxx:266
erhic::Forester::Status::mNParticles
Long64_t mNParticles
Definition: Forester.h:169
erhic::Forester::mQuit
Bool_t mQuit
Quit status. Set to true once EoF or max events reached.
Definition: Forester.h:240
erhic::Forester::Status::StartTimer
virtual void StartTimer()
Definition: Forester.cxx:280
erhic::Forester::Status::ModifyParticleCount
virtual void ModifyParticleCount(Long64_t count)
Definition: Forester.cxx:294
erhic::Forester::GetInputFileName
std::string GetInputFileName() const
Returns the name of the input text file containing Monte Carlo data.
Definition: Forester.h:277
erhic::Forester::MustQuit
bool MustQuit() const
Prints the quit flag status.
Definition: Forester.h:305
erhic::Forester::Status::StopTimer
virtual void StopTimer()
Definition: Forester.cxx:285
erhic::Forester::mTextFile
std::ifstream * mTextFile
Definition: Forester.h:249
erhic::Forester::GetOutputFileName
std::string GetOutputFileName() const
Returns the name of the ROOT tree file to create.
Definition: Forester.h:281
erhic::Forester::FindFirstEvent
bool FindFirstEvent()
Aligns the input text file on the first line of the first event.
Definition: Forester.cxx:228
erhic::VirtualEvent
Abstract base class for a physics event.
Definition: VirtualEvent.h:25
erhic::Forester::mStatus
Status mStatus
Forester status information.
Definition: Forester.h:255
EventMC.h
erhic::Forester::Status::Status
Status()
Definition: Forester.cxx:256
erhic::Forester::mBranchName
std::string mBranchName
Name of the event TBranch.
Definition: Forester.h:253
erhic::Forester::SetMustQuit
void SetMustQuit(bool quit)
Set the quit flag.
Definition: Forester.h:309
erhic::Forester::GetGetStatus
const Status & GetGetStatus() const
Prints a summary of the last call to Plant() to the requested output stream.
Definition: Forester.h:184
erhic::Forester::Print
void Print(std::ostream &stream) const
Prints the current configuration to the requested output stream.
Definition: Forester.cxx:241
erhic::Forester::SetupOutput
bool SetupOutput()
Opens the output ROOT file and creates the TTree ready for filling.
Definition: Forester.cxx:158
erhic::Forester::Status::Print
virtual std::ostream & Print(std::ostream &os=std::cout) const
Definition: Forester.cxx:268
erhic::Forester::SetTreeName
void SetTreeName(const std::string &="EICTree")
Sets the name of the TTree to write to the file named by SetOutputFileName().
Definition: Forester.h:269
erhic::Forester::AllocateEvent
bool AllocateEvent()
Allocate an event buffer for the TTree based on the generator type.
Definition: Forester.cxx:213
erhic::Forester::PrintStatus
void PrintStatus() const
Prints the status of the current Plant() call to the standard output.
erhic::VirtualEventFactory
Abstract base class for event builders.
Definition: erhic/EventFactory.h:35
erhic::Forester::GetMaxNEvents
Long64_t GetMaxNEvents() const
Returns the maximum number of events to process.
Definition: Forester.h:297
erhic::Forester::SetMessageInterval
void SetMessageInterval(Long64_t=10000)
Sets the event count interval at which to print a status message.
Definition: Forester.h:301
erhic::Forester::SetOutputFileName
void SetOutputFileName(const std::string &)
Sets the name of the ROOT tree file to create.
Definition: Forester.h:265
erhic::Forester::SetBranchName
void SetBranchName(const std::string &="event")
Sets the name of the TBranch containing event objects.
Definition: Forester.h:273
erhic::Forester::mTree
TTree * mTree
Definition: Forester.h:242
erhic::Forester::Status::ClassDef
ClassDef(Status, 1)
erhic::Forester::mTreeName
std::string mTreeName
Name of the output TTree.
Definition: Forester.h:252
erhic::Forester::GetBranchName
std::string GetBranchName() const
Returns the name of the TBranch containing event objects.
Definition: Forester.h:289
erhic::Forester::mOutputName
std::string mOutputName
Name of the output ROOT file.
Definition: Forester.h:251
erhic::Forester::Plant
Long64_t Plant()
Processes a text file into a ROOT file.
Definition: Forester.cxx:67
erhic::Forester::Status::mStartTime
time_t mStartTime
Definition: Forester.h:166
erhic::Forester::mFactory
VirtualEventFactory * mFactory
Definition: Forester.h:256
erhic::Forester::mInterval
Long64_t mInterval
Event interval between printing status messages.
Definition: Forester.h:247
erhic::Forester::~Forester
virtual ~Forester()
Destructor.
Definition: Forester.cxx:42
erhic::Forester::OpenInput
bool OpenInput()
Opens the input file and checks that it was produced by a supported Monte Carlo generator.
Definition: Forester.cxx:130
erhic::Forester::Status
Stores summary information about the last call to Forester::Plant().
Definition: Forester.h:154
erhic::Forester::SetMaxNEvents
void SetMaxNEvents(Long64_t=0)
Sets the maximum number of events to process.
Definition: Forester.h:293
erhic::Forester::Status::mTimer
TStopwatch mTimer
Definition: Forester.h:172
erhic::Forester::mRootFile
TFile * mRootFile
< File type information
Definition: Forester.h:245
erhic::FileType
Abstract base class for Monte Carlo file types.
Definition: File.h:424
erhic::Forester::GetTreeName
std::string GetTreeName() const
Returns the name of the TTree to write to the file named by SetOutputFileName().
Definition: Forester.h:285
erhic::Forester::Status::mNEvents
Long64_t mNEvents
Definition: Forester.h:168
erhic::Forester::mInputName
std::string mInputName
< Input text file
Definition: Forester.h:250
erhic::Forester::SetBeVerbose
void SetBeVerbose(bool=false)
If set to true, prints messages during running.
Definition: Forester.h:313
erhic::Forester::GetFileType
const erhic::FileType * GetFileType() const
Returns the file type information for the last processed file.
Definition: Forester.h:321
erhic::Forester::mLine
std::string mLine
Stores the latest text line read from the input file.
Definition: Forester.h:254
erhic::Forester::mVerbose
Bool_t mVerbose
Verbosity flag.
Definition: Forester.h:241
erhic::Forester
Manages the creation of trees from plain-text Monte Carlo files.
Definition: Forester.h:40
erhic::Forester::SetInputFileName
void SetInputFileName(const std::string &)
Sets the name of the input text file containing Monte Carlo data.
Definition: Forester.h:261
erhic::Forester::Status::ModifyEventCount
virtual void ModifyEventCount(Long64_t count)
Definition: Forester.cxx:290