CMFSpectraMaker_module.cc
Go to the documentation of this file.
1 // Spectra making module
2 
3 #include <cmath>
4 #include <string>
5 #include <vector>
6 
7 #include "TFile.h"
8 #include "TTree.h"
9 #include "TH1.h"
10 
11 // Framework includes
17 #include "fhiclcpp/ParameterSet.h"
19 
20 // CMF includes
29 
30 namespace cmf {
32  public:
33  explicit CMFSpectraMaker(fhicl::ParameterSet const& pset);
34  ~CMFSpectraMaker() = default;
35 
36  // Required fucntions
37  void analyze(art::Event const& evt) override;
38  void beginJob() override;
39  void endJob() override;
40 
41  void reconfigure(fhicl::ParameterSet const& pset);
42 
43  private:
44 
45  void Initialize();
47  int sigmaVal,
48  cmf::EventListColl & eventLists,
49  cmf::ExposureMap & exposureMap);
50 
51  // Member data
52  fhicl::ParameterSet fManipulatorParameters; ///< event list manipulator parameters
53  fhicl::ParameterSet fSAWParameters; ///< shifter and weighter parameters
54 
56 
58  std::vector<std::string> fITypeStrings;
59  std::map<std::string, cmf::InteractionType_t> ITypes;
60  std::vector<int> fSigmaValues;
62  };
63 
64  //----------------------------------------------------------------//
66  : EDAnalyzer(pset)
67  {
68  this->reconfigure(pset);
69  }
70 
71  //----------------------------------------------------------------//
73  {
74  fManipulatorParameters = pset.get< fhicl::ParameterSet >("EventListManipulator" );
75  fSAWParameters = pset.get< fhicl::ParameterSet >("ShifterAndWeighterConfig");
76  fSigmaValues = pset.get< std::vector<int> >("SigmaValues", {0} );
77  fApplyExposureNorm = pset.get< bool >("ApplyExposureNorm", true );
78 
81  cmf::ParameterUtility::Instance() ->Initialize(pset.get< fhicl::ParameterSet >("ParametersToUse" ));
84 
86  fSAWParameters);
87 
88  fITypeStrings = pset.get< std::vector<std::string>> ("InteractionTypes");
89 
91  if (std::find(fITypeStrings.begin(), fITypeStrings.end(), "NuMuCC") != fITypeStrings.end())
93  if (std::find(fITypeStrings.begin(), fITypeStrings.end(), "NuMuBarCC") != fITypeStrings.end())
95  if (std::find(fITypeStrings.begin(), fITypeStrings.end(), "NuECC") != fITypeStrings.end())
97  if (std::find(fITypeStrings.begin(), fITypeStrings.end(), "NuEBarCC") != fITypeStrings.end())
99  if (std::find(fITypeStrings.begin(), fITypeStrings.end(), "NuTauCC") != fITypeStrings.end())
101  if (std::find(fITypeStrings.begin(), fITypeStrings.end(), "NuTauBarCC") != fITypeStrings.end())
103  if (std::find(fITypeStrings.begin(), fITypeStrings.end(), "NC") != fITypeStrings.end())
105  if (std::find(fITypeStrings.begin(), fITypeStrings.end(), "CosmicMuon") != fITypeStrings.end())
107  if (std::find(fITypeStrings.begin(), fITypeStrings.end(), "RockMuon") != fITypeStrings.end())
109 
110  }
111 
112  //----------------------------------------------------------------//
114  {
115  }
116 
117  //----------------------------------------------------------------//
119  {
120  }
121 
122  //----------------------------------------------------------------//
124  int sigmaValue,
125  cmf::EventListColl & eventLists,
126  cmf::ExposureMap & exposureMap)
127  {
128  for (auto& iType : ITypes){
129 
130  std::vector<float> spectrum;
131  std::vector<float> count;
132 
133  if (iType.second == cmf::kUnknownInteraction)
134  cmf::FillSpectrum(eventLists,
135  exposureMap,
136  spectrum,
137  count,
139  else
140  cmf::FillSpectrum(eventLists,
141  exposureMap,
142  spectrum,
143  count,
144  iType.second,
146 
147  std::map<long, TH1D*> energySpecMap;
148 
149  std::string preName = "";
150  if (sigmaValue != 0)
151  preName = std::to_string(sigmaValue)+"Sigma";
152 
154  count,
155  energySpecMap,
156  iType.first,
157  td,
158  preName);
159  }
160  }
161 
162  //----------------------------------------------------------------//
164  {
165  // get the lists of events from the TTree and put them into a map
166  // of event lists
168 
169  cmf::EventListColl eventLists;
170  manipulator.Deserialize(eventLists, cmf::kMC);
171 
172  cmf::ExposureMap exposureMap = manipulator.ExposureMap();
173 
174  // this allows us to get systematically spectra by setting
175  // the systematic sigma
176  auto parNames = cmf::ParameterUtility::Instance()->SysParNames();
177  if (parNames.size() > 0){
178  for (auto& parItr : parNames) {
179 
180  art::TFileDirectory td = fTFS->mkdir(parItr, parItr);
181 
182  for (size_t is = 0; is < fSigmaValues.size(); ++is){
183 
186 
189 
190  this->FillHistograms(td, fSigmaValues.at(is), eventLists, exposureMap);
191  }
192  }
193  }
194  else{
195  art::TFileDirectory td = fTFS->mkdir("nosyst", "Not systematically shifted");
196  this->FillHistograms(td, 0, eventLists, exposureMap);
197  }
198 
199  }
200 
201 }
202 
CMFSpectraMaker(fhicl::ParameterSet const &pset)
std::map< cmf::MetaData, cmf::SpillSummary > ExposureMap
Definition: Structs.h:215
std::vector< int > fSigmaValues
void MakeEnergySpectraFromBins(std::vector< float > const &binSpec, std::vector< float > const &binCount, std::map< long, TH1D * > &energySpecMap, std::string const &name, art::TFileDirectory &tfd, std::string const &uniqueID)
void Initialize(fhicl::ParameterSet const &pset)
TFileDirectory mkdir(std::string const &dir, std::string const &descr="")
fhicl::ParameterSet fManipulatorParameters
event list manipulator parameters
static SelectionUtility * Instance()
std::map< std::string, cmf::InteractionType_t > ITypes
DEFINE_ART_MODULE(TestTMapFile)
void analyze(art::Event const &evt) override
art::ServiceHandle< art::TFileService > fTFS
std::vector< std::string > SysParNames() const
void Deserialize(cmf::EventListColl &eventLists, cmf::DataMC_t dataMC=cmf::kBoth, std::set< cmf::DetType_t > const &detectors=std::set< cmf::DetType_t >({cmf::kNEARDET, cmf::kFARDET}))
const std::string cInteractionType_Strings[11]
Definition: Constants.h:149
static ParameterUtility * Instance()
~CMFSpectraMaker()=default
T get(std::string const &key) const
Definition: ParameterSet.h:231
int evt
std::vector< std::string > fITypeStrings
cmf::ExposureMap const & ExposureMap() const
void Initialize(fhicl::ParameterSet const &pset)
void FillSpectrum(cmf::EventListColl const &eventLists, cmf::ExposureMap const &exposureMap, std::vector< float > &spectrum, std::vector< float > &count, cmf::InteractionType_t intType, bool applyExposureNorm)
static ShifterAndWeighter * Instance()
EDAnalyzer(Table< Config > const &config)
Definition: EDAnalyzer.h:100
void Initialize(fhicl::ParameterSet const &plottingPars)
void reconfigure(fhicl::ParameterSet const &pset)
Module to combine a set of results into a single file currently only does one data product type at a ...
Definition: Event.cxx:24
std::vector< cmf::EventList > EventListColl
Definition: Event.h:147
void FillHistograms(art::TFileDirectory &td, int sigmaVal, cmf::EventListColl &eventLists, cmf::ExposureMap &exposureMap)
void InitShiftsAndWeightsToUse(cmf::Location const &loc, fhicl::ParameterSet const &parset)
static PlotUtilities * Instance()
cmf::Location ParametersAsLocation()
std::string to_string(ModuleType mt)
Definition: ModuleType.h:32
fhicl::ParameterSet fSAWParameters
shifter and weighter parameters
void Initialize(fhicl::ParameterSet const &pset)
void SetCurrentVals(cmf::Location const &loc)
void SetParameterValue(std::string const &parName, double const &value, cmf::DetType_t const &det)
Definition: Parameter.cxx:236
static CovarianceBinUtility * Instance()
enum BeamMode string