eventAnalysis  7.0-49-g0ac7482
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
TAnalysisModuleBase.hxx
Go to the documentation of this file.
1 #ifndef TAnalysisModuleBase_hxx_seen
2 #define TAnalysisModuleBase_hxx_seen
3 
4 #include <TGeoManager.h>
5 #include <TNamed.h>
6 #include <TTree.h>
7 #include <TND280Event.hxx>
8 #include <string>
9 
10 #include <EeventAnalysis.hxx>
11 
12 namespace ND {
13 class TAnalysisModuleBase;
14 OA_EXCEPTION(EAnalysisModuleBase, EeventAnalysis);
15 OA_EXCEPTION(EUndefinedTreeType, EAnalysisModuleBase);
16 OA_EXCEPTION(EAnalysisFailure, EAnalysisModuleBase);
17 };
18 
19 /// A base class for classes which specify how to set up an Analysis format
20 /// output tree, and fill it. These classes will be read in and run by the
21 /// eventAnalysis package software, namely by TAnalysisLoop. The classes must be
22 /// accompanied by tests to check that they work, and runtime tests to see if
23 /// they are appropriate for the input root files being used.
24 ///
25 /// A note on naming of data members in analysis modules classes and their
26 /// sub-classes:
27 ///
28 /// The names of members belonging to the modules themselves all
29 /// start with an 'f', to indicate that they are fields in the
30 /// classes. These names are used in coding up the modules, so it is
31 /// better that they follow the convention.
32 ///
33 /// The members of storages sub-classes to the modules, which get
34 /// saved in TTrees within TClonesArrays, DO NOT get an 'f' at the
35 /// beginning, because they represent names that get used directly
36 /// in analysis macros. This was always implemented consistently.
37 ///
38 /// The modules themselves get saved in the output files, including
39 /// their data members (except those with a comment with an
40 /// exclamation mark "//!" after them, which tells ROOT not to
41 /// save them). These can be accessed in the analysis macros,
42 /// but since they are explicitly members of the module
43 /// classes, it is consistent to have them start with 'f' too.
45  public:
47  virtual ~TAnalysisModuleBase();
48 
49  void SetNameTitle(char const *name, char const *title);
50  char const *GetName();
51  char const *GetTitle();
52 
53  protected:
55 
56  public:
57  /// Returns the type of tree, header, truth, or recon.
58  /// This is overridden in the derived base classes such as
59  /// TAnalysisReconModuleBase, so users do not need to override
60  /// it explicitly
61  virtual EType GetTreeType() const = 0;
62 
63  /// Returns the name of the directory which the output of a
64  /// particular module will be saved in.
65  std::string const GetDirectoryName() const;
66 
67  /// Sets whether the module is enabled. This only refer to modules
68  /// which have been included for consideration by being instantiated
69  /// in TAnalysisLoop.cxx or similar.
70  virtual void SetEnabled(Bool_t isenabled = true) { fIsEnabled = isenabled; }
71 
72  /// Disables the module. Is called when an exception is thrown inside
73  /// the module.
74  virtual void SetDisabled() { SetEnabled(false); }
75 
76  /// Sets whether the module should call IsFullEventWorthSaving() function
77  /// for each event, to decide if the full oaEvent info for that event should
78  /// be saved in the output
79  virtual void SetUsedForPreselection(Bool_t isused = true) {
80  fIsUsedForPreselection = isused;
81  }
82 
83  /// Whether the module is enable or not.
84  virtual Bool_t IsEnabled() const { return fIsEnabled; }
85 
86  /// Is the module is enabled by default. Default is to enable module. To
87  /// set to disable override this method in the derived module.
88  virtual Bool_t IsEnabledByDefault() const { return true; }
89 
90  /// Whether the module should call IsFullEventWorthSaving() function
91  /// for each event, to decide if the full oaEvent info for that event should
92  /// be saved in the output
93  virtual Bool_t IsUsedForPreselection() const {
95  }
96 
97  /// Prints a simple message describing the module. Should be overridden
98  /// for more detail
99  virtual void Print();
100 
101  /// Is called after the first event is loaded in.
102  /// This is a good time to save persistent quantities in the module's
103  /// data members, which will be retrievable from the eventAnalysis output
104  /// file.
105  /// Not intended for filling in the tree with the first event, as
106  /// Process() will also be called.
107  virtual Bool_t ProcessFirstEvent(ND::TND280Event &) = 0;
108 
109  void Initialize(TTree *tree);
110 
111  /// Gets the run and event IDs and calls FillTree with the
112  /// event, and then actually calls fOutputTree->Fill.
113  virtual bool Process(ND::TND280Event &event);
114 
115  /// Whether the module thinks it is worth saving the entire
116  /// oaEvent event tree entry for this event.
117  /// eventAnalysis can be used for event pre-selection in this way.
118  /// Activated with the --oaEvent-preselection=&lt;moduleclass&gt;> command-
119  /// line argument
120  virtual bool IsFullEventWorthSaving(ND::TND280Event &event);
121 
122  /// ROOT output parameters, usually no need to touch
123  Int_t GetBufferSize() { return fBufferSize; }
124 
125  /// ROOT output parameters, usually no need to touch
126  void SetBufferSize(Int_t buffersize) { fBufferSize = buffersize; }
127 
128  /// ROOT output parameters, usually no need to touch
129  Int_t GetSplitLevel() { return fSplitLevel; }
130 
131  /// ROOT output parameters, usually no need to touch
132  void SetSplitLevel(Int_t splitlevel) { fSplitLevel = splitlevel; }
133 
134  std::string const GetDescription() const { return fDescription; }
135  std::string const GetCVSTagName() const { return fCVSTagName; }
136  std::string const GetCVSID() const { return fCVSID; }
137 
138  /// The output tree
139  TTree const *GetOutputTree() const { return fOutputTree; }
140  void KillOutputTree() {
141  if (fOutputTree) {
142  fOutputTree->SetDirectory(NULL);
143  delete fOutputTree;
144  }
145  }
146 
147  /// A function that allows the module to be configured from an external
148  /// class without any dependencies.
149  /// Should be overridden with a function that responds to the string
150  /// option, and returns true if configuration succedded.
151  /// Used in TAnalysisLoop.cxx (and RunEventAnalysis.exe) for options of the
152  /// form: -O TTruthTrajectoriesModule=SaveAll
153  virtual Bool_t Configure(std::string &option);
154  ///\brief Subclasses should override this to let a user know what options
155  /// are available.
156  virtual void SayAvailableOpts(std::string indent = ""){};
157 
158  void SetInputDirectory(std::string dir) { fInputDirectory = dir; }
159 
160  virtual void FillConfigTree(TTree *);
161 
162  protected:
163  /// Initialize Module, override if necessary
164  virtual void InitializeModule(){};
165 
166  /// Initialize Branches. Don't do anything else in this function
167  virtual void InitializeBranches() = 0;
168 
169  /// Fill all the stuff that goes in the output tree. Return
170  /// true if everything went well. Otherwise, the module
171  /// may be disabled! (return definition changed Apr 2009!)
172  virtual bool FillTree(ND::TND280Event &) = 0;
173 
175 
176  Bool_t fIsEnabled;
177 
179 
180  TTree *fOutputTree;
181 
182  /// Buffer Size for TBranch. Has a default value that
183  /// can be changed per module.
184  Int_t fBufferSize; // Buffer Size for TBranch.
185 
186  Int_t fSplitLevel; ///< Split Level for TBranch.
187 
188  std::string fDescription; ///< A longish descrition of the analysis
189 
190  std::string fCVSTagName; ///< Defined if an official tagged version
191 
192  std::string fCVSID; ///< Defined if an official tagged version
193 
194  ///////////////////////////////////////////////////////////////////
195  // Default Tree Entries
196  Int_t fRunID;
197  Int_t fSubrunID;
198  Int_t fEventID;
200 
201  std::string fInputDirectory; ///< An input directory where analysis modules can search for extra files.
202 
203  std::string fName;
204  std::string fTitle;
205 
206  Bool_t fIsMC;
207 
208  private:
209 };
210 #endif
virtual void Print()
Prints a simple message describing the module.
virtual bool Process(ND::TND280Event &event)
Gets the run and event IDs and calls FillTree with the event, and then actually calls fOutputTree-&gt;Fi...
virtual Bool_t IsEnabled() const
Whether the module is enable or not.
virtual void SayAvailableOpts(std::string indent="")
Subclasses should override this to let a user know what options are available.
OA_EXCEPTION(EeventAnalysis, EoaCore)
Generate a base exception for the Analysis library.
std::string const GetDescription() const
std::string fDescription
A longish descrition of the analysis.
virtual Bool_t IsUsedForPreselection() const
Whether the module should call IsFullEventWorthSaving() function for each event, to decide if the ful...
A base class for classes which specify how to set up an Analysis format output tree, and fill it.
virtual void SetDisabled()
Disables the module.
std::string const GetCVSTagName() const
virtual bool IsFullEventWorthSaving(ND::TND280Event &event)
Whether the module thinks it is worth saving the entire oaEvent event tree entry for this event...
virtual Bool_t Configure(std::string &option)
A function that allows the module to be configured from an external class without any dependencies...
Int_t fBufferSize
Buffer Size for TBranch.
virtual Bool_t IsEnabledByDefault() const
Is the module is enabled by default.
std::string const GetDirectoryName() const
Returns the name of the directory which the output of a particular module will be saved in...
virtual void SetUsedForPreselection(Bool_t isused=true)
Sets whether the module should call IsFullEventWorthSaving() function for each event, to decide if the full oaEvent info for that event should be saved in the output.
std::string fCVSID
Defined if an official tagged version.
virtual void SetEnabled(Bool_t isenabled=true)
Sets whether the module is enabled.
void SetNameTitle(char const *name, char const *title)
Int_t GetSplitLevel()
ROOT output parameters, usually no need to touch.
virtual void InitializeBranches()=0
Initialize Branches. Don&#39;t do anything else in this function.
virtual Bool_t ProcessFirstEvent(ND::TND280Event &)=0
Is called after the first event is loaded in.
Int_t GetBufferSize()
ROOT output parameters, usually no need to touch.
virtual void InitializeModule()
Initialize Module, override if necessary.
Int_t fSplitLevel
Split Level for TBranch.
virtual EType GetTreeType() const =0
Returns the type of tree, header, truth, or recon.
TTree const * GetOutputTree() const
The output tree.
std::string const GetCVSID() const
std::string fCVSTagName
Defined if an official tagged version.
void SetBufferSize(Int_t buffersize)
ROOT output parameters, usually no need to touch.
std::string fInputDirectory
An input directory where analysis modules can search for extra files.
void SetSplitLevel(Int_t splitlevel)
ROOT output parameters, usually no need to touch.
void SetInputDirectory(std::string dir)
virtual bool FillTree(ND::TND280Event &)=0
Fill all the stuff that goes in the output tree.
virtual void FillConfigTree(TTree *)

Package Summary
Package Name: eventAnalysis
Package Version: 7.0-49-g0ac7482
Package Manager:

Generated on Mon Mar 25 2024 14:43:58 for eventAnalysis by doxygen 1.8.5