HighLAND
baseAnalysis.hxx
1 #ifndef baseAnalysis_h
2 #define baseAnalysis_h
3 
4 #include "HighlandAnalysisUtils.hxx"
5 #include "FluxWeighting.hxx"
6 #include "AnalysisAlgorithm.hxx"
7 
8 #include "Parameters.hxx"
9 #include "CutUtils.hxx"
10 #include "VersioningUtils.hxx"
11 #include "SystId.hxx"
12 #include "Versioning.hxx"
13 #include "CategoriesUtils.hxx"
14 #include "CategoryManager.hxx"
15 #include "ToyBoxTracker.hxx"
16 #include "RooTrackerVtxManager.hxx"
17 
18 
19 /// This class provides a base for user analyses. It handles many common
20 /// functions, and provides a structure so that users don't have to write too
21 /// much "boiler-plate" code.
22 ///
23 /// User analyses should inherit from this class.
25  public:
26  /// Constructor, which instantiates the necessary converters for converting
27  /// input files to the AnaSpill format.
29  virtual ~baseAnalysis(){}
30 
31 
32  virtual bool Initialize();
33  virtual bool InitializeSpill();
34  virtual bool FinalizeConfiguration();
35 
36  virtual void DefineProductions();
37  virtual void DefineInputConverters();
38 
39  virtual void DefineCorrections();
40  virtual void DefineSystematics();
41  virtual void DefineConfigurations();
42  virtual void DefineMicroTrees(bool addBase=true);
43  virtual void DefineTruthTree();
44 
45  virtual bool CheckFillTruthTree(const AnaTrueVertex& vtx) = 0;
46  virtual void FillTruthTree(const AnaTrueVertex& vtx) = 0;
47 
48  void FillMicroTreesBase(bool addBase=true);
49  void FillToyVarsInMicroTreesBase(bool addBase=true);
50  void FillTruthTree();
51  void FillTruthTreeBase(const AnaTrueVertex& vtx, const SubDetId::SubDetEnum det=SubDetId::kFGD1, bool IsAntinu = false);
52 
53  /// Get a casted AnaSpillC to AnaSpill from the InputManager
54  AnaSpill& GetSpill(){return *static_cast<AnaSpill*>(&input().GetSpill());}
55 
56  /// Get a casted AnaBunchBB to AnaBunch from the InputManager (TODO the protection)
58  if (_analysisPoint < AnalysisAlgorithm::kInitializeSpill || _analysisPoint> kFinalizeBunch){
59  std::cout << "baseAnalysis::GetBunch(). The Bunch is not available before InitializeBunch or after FinalizeBunch (see AnalysisAlgorithm.hxx) !!!" << std::endl;
60  exit(1);
61  }
62  return *static_cast<AnaBunch*>(&input().GetBunch());
63  }
64 
65  /// Get a casted AnaEventC to AnaEvent
67  if (_analysisPoint < AnalysisAlgorithm::kInitializeBunch || _analysisPoint> kFinalizeBunch){
68  std::cout << "baseAnalysis::GetEvent(). The Event is not available before InitializeBunch or after FinalizeBunch (see AnalysisAlgorithm.hxx) !!!" << std::endl;
69  exit(1);
70  }
71  return *static_cast<AnaEvent*>(_event);
72  }
73 
74  /// Create the appropriate event time from an Spill and a Bunch in that spill
75  virtual AnaEventC* MakeEvent(){
76  return new AnaEvent(GetSpill(),GetBunch());
77  }
78 
79  // Return the vertex from the ToyBox (some ToyBox derived classes could not have that member)
80  virtual AnaVertexB* GetVertex() const = 0;
81 
82  // Return the true vertex from the ToyBox (some ToyBox derived classes could not have that member)
83  virtual AnaTrueVertexB* GetTrueVertex() const = 0;
84 
85  /// Set whether to save the RooTrackerVtx tree or not
86  void SetSaveRooTracker(bool save){_saveRooTrackerVtxTree = save;}
87 
88  /// Set the RooTrackerVtxManager
90 
91  protected:
92 
93  /// the manager of the RooTrackerVtx
95 
96  /// Save RooTracker tree in output file
98 
99  /// Access to the flux weighting.
101 
102  /// Flag to enable/disable flux weight
104 
105  /// Flux file and option
106  std::string _fluxFile;
107  std::string _fluxTuning;
108 
109 
110  bool _enableSingleVariationSystConf;
111  bool _enableSingleWeightSystConf;
112  bool _enableAllSystConfig;
113 
114  /// Whether to use zero-variation configuration: no variation will be applied to systematics, i.e.
115  /// those relevant will work as correction
117 
118  Int_t _ntoys;
119  Int_t _randomSeed;
120 
121  void AddZeroVarConfiguration();
122 
123 public:
124 
125  enum enumStandardMicroTrees_baseAnalysis{
126  run = enumStandardMicroTreesLast_AnalysisAlgorithm+1,
127  subrun,
128  evt,
129  evt_time,
130  bunch,
131  NWEIGHTS,
132  weight,
133  TruthVertexID,
134  TruthVertexNB,
135  RooVtxIndex,
136  RooVtxEntry,
137  RooVtxEntry2,
138  RooVtxFile,
139  nu_pdg,
140  nu_trueE,
141  nu_truereac,
142  nu_truedir,
143  // truelepton_pdg, // is the same as the category particle
144  truelepton_mom,
145  truelepton_costheta,
146  truelepton_dir,
147  truevtx_pos,
148  // truevtx_det, // is the same as the category detector
149  selvtx_det,
150  selvtx_pos,
151  selvtx_truepos,
152  true_signal, // declared here, filled in each analysis package
153  weight_syst_total_noflux,
154  enumStandardMicroTreesLast_baseAnalysis
155  };
156 
157  enum enumConf_baseAnalysis{
158  sipion_syst=ConfigurationManager::enumConfLast_ConfigurationManager+1,
159  siproton_syst,
160  nuflux_syst,
161  antinuflux_syst,
162  all_syst,
163  zero_var,
164  enumConfLast_baseAnalysis
165  };
166 
167 };
168 
169 #define AddConfiguration(conf, name, ntoys, randomSeed,toyMaker) conf.AddConfiguration(name,#name,ntoys,randomSeed,toyMaker);
170 #define GetConfigurationIndex(name) conf().GetConfigurationIndex(#name)
171 
172 
173 
174 #endif
FluxWeighting * _flux
Access to the flux weighting.
Representation of a true Monte Carlo vertex.
virtual bool Initialize()
[AnalysisAlgorithm_mandatory]
bool _enableZeroVarConfig
AnaBunch & GetBunch()
Get a casted AnaBunchBB to AnaBunch from the InputManager (TODO the protection)
Representation of a true Monte Carlo vertex.
Definition: DataClasses.hxx:50
bool _applyFluxWeight
Flag to enable/disable flux weight.
RooTrackerVtxManager * _rooVtxManager
the manager of the RooTrackerVtx
AnaEventC * _event
The current event.
SubDetEnum
Enumeration of all detector systems and subdetectors.
Definition: SubDetId.hxx:25
AnaSpillC & GetSpill()
Get the current spill (to have corrections and systematics applied to it).
virtual AnaEventC * MakeEvent()
Create the appropriate event time from an Spill and a Bunch in that spill.
AnaEvent & GetEvent()
Get a casted AnaEventC to AnaEvent.
bool _saveRooTrackerVtxTree
Save RooTracker tree in output file.
AnaBunchC & GetBunch()
Get the current bunch (to have corrections and systematics applied to it).
Representation of a global vertex.
std::string _fluxFile
Flux file and option.
void SetSaveRooTracker(bool save)
Set whether to save the RooTrackerVtx tree or not.
AnaSpill & GetSpill()
Get a casted AnaSpillC to AnaSpill from the InputManager.
baseAnalysis(AnalysisAlgorithm *ana=NULL)
void SetRooVtxManager(RooTrackerVtxManager *man)
Set the RooTrackerVtxManager.