Public Member Functions | Protected Attributes | List of all members
fnex::Correlations Class Reference

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-12-03/FNEX/core/Correlations.h"

Public Member Functions

 Correlations (fhicl::ParameterSet const &pset)
 
 ~Correlations ()
 
void Reconfigure (fhicl::ParameterSet const &pset)
 
void ApplyCorrelations (InputPoint &pInputPoint)
 
void ApplyCorrelations (StringPointMap &pStringPointMap)
 
bool IsConfigured ()
 
const std::string ToString () const
 
void Print (std::ostream &outfile=std::cout) const
 

Protected Attributes

bool fIsConfigured
 
std::string fInstanceName
 
std::vector< fnex::simple_correlationfCorrelations
 

Detailed Description

Definition at line 36 of file Correlations.h.

Constructor & Destructor Documentation

fnex::Correlations::Correlations ( fhicl::ParameterSet const &  pset)
explicit

Definition at line 8 of file Correlations.cxx.

References Reconfigure().

9  : fIsConfigured(false)
10  {
11  this->Reconfigure(pset);
12 
13  }
void Reconfigure(fhicl::ParameterSet const &pset)
fnex::Correlations::~Correlations ( )
inline

Definition at line 42 of file Correlations.h.

References om::cout, outfile, Print(), string, and ToString().

42 {};

Member Function Documentation

void fnex::Correlations::ApplyCorrelations ( InputPoint pInputPoint)

Definition at line 50 of file Correlations.cxx.

References confusionMatrixTree::count, runNovaSAM::detectors, allTimeWatchdog::endl, fCorrelations, fnex::InputPoint::FixedParameters(), fnex::InputPoint::FixedSystematics(), update_sam_good_runs_metadata::good, novadaq::cnv::kFARDET, novadaq::cnv::kNEARDET, LOG_VERBATIM, make_pair(), fnex::InputPoint::ParameterSpaceLocation(), and fnex::InputPoint::SystematicPulls().

50  {
51 
52  // Loop through the correlations vector. Check that systematics
53  // (second osc. params) have one (and only one) match to each
54  // the ind. and dep. variables. Apply the correlations, and set
55  // Fixed: true for all dep. variables so that the fitter doesn't
56  // adjust them. Output a message if Fixed was not true ahead of time.
57  // Debug messages "DepVarShift = Corr*IndVarShift : INIT --> FINAL
58 
59  std::vector<novadaq::cnv::DetId> detectors;
60  detectors.push_back(novadaq::cnv::kNEARDET);
61  detectors.push_back(novadaq::cnv::kFARDET);
62 
63  auto parameterSpaceLocation = pInputPoint.ParameterSpaceLocation();
64  auto systematicPulls = pInputPoint.SystematicPulls();
65  auto fixedParameters = pInputPoint.FixedParameters();
66  auto fixedSystematics = pInputPoint.FixedSystematics();
67 
68  std::vector<bool> good (fCorrelations.size(), false);
69  std::vector<bool> tooMany(fCorrelations.size(), false);
70 
71  for(size_t icorr = 0; icorr < fCorrelations.size(); ++icorr){
72 
73  auto thiscorr = fCorrelations[icorr];
74 
75  // Define the parameter det maps
76  std::vector<ParameterDet> depParDet(2);
77  std::vector<ParameterDet> indParDet(2);
78 
79  // Set the parameter det maps
80  for(int idet = 0; idet < 2; ++idet){
81  depParDet[idet] = std::make_pair(thiscorr.depVar, detectors[idet]);
82  indParDet[idet] = std::make_pair(thiscorr.indVar, detectors[idet]);
83  }
84 
85  // Find the value of the independent variable
86  double indVal = 0.;
87  for(int idet = 0; idet < 2; ++idet){
88  if( parameterSpaceLocation.count(indParDet[idet]) > 0 ) indVal = parameterSpaceLocation[indParDet[idet]];
89  if( systematicPulls .count(indParDet[idet]) > 0 ) indVal = systematicPulls[indParDet[idet]];
90  }
91 
92  // Now find the dependent variable and set it
93  for(int idet = 0; idet < 2; ++idet){
94 
95  // First in the case that it is a parameterSpaceLocation
96  if( parameterSpaceLocation.count(depParDet[idet]) > 0 ){
97  LOG_VERBATIM("Correlations") << " Correlating: "
98  << thiscorr.depVar
99  << " = ( " << parameterSpaceLocation[depParDet[idet]] << " ) as "
100  << thiscorr.indVar
101  << " = ( " << indVal << " ) * "
102  << thiscorr.corr << " giving new val "
103  << indVal * thiscorr.corr
104  << std::endl;
105 
106  parameterSpaceLocation[depParDet[idet]] = indVal * thiscorr.corr;
107 
108  if(std::find(fixedParameters.begin(), fixedParameters.end(), depParDet[idet]) != fixedParameters.end()){
109  LOG_VERBATIM("Correlations") << thiscorr.depVar << " not fixed! Setting Fixed: true\n";
110  fixedParameters.push_back(depParDet[idet]);
111  }else{
112  LOG_VERBATIM("Correlations") << thiscorr.depVar << " already fixed. Good!\n";
113  }
114 
115  }//if( parameterSpaceLocation.count(depParDet[idet]) > 0 )
116 
117  // Then, if it is a systematicPull
118  if( systematicPulls.count(depParDet[idet]) > 0 ){
119  LOG_VERBATIM("Correlations") << " Correlating: "
120  << thiscorr.depVar
121  << " = ( " << systematicPulls[depParDet[idet]] << " ) as "
122  << thiscorr.indVar
123  << " = ( " << indVal << " ) * "
124  << thiscorr.corr << " giving new val "
125  << indVal * thiscorr.corr
126  << std::endl;
127 
128  systematicPulls[depParDet[idet]] = indVal * thiscorr.corr;
129 
130  if(std::find(fixedSystematics.begin(), fixedSystematics.end(), depParDet[idet]) != fixedSystematics.end()){
131  LOG_VERBATIM("Correlations") << thiscorr.depVar << " not fixed! Setting Fixed: true\n";
132  fixedSystematics.push_back(depParDet[idet]);
133  }else{
134  LOG_VERBATIM("Correlations") << thiscorr.depVar << " already fixed. Good!\n";
135  }
136 
137  }//if( systematicPulls.count(depParDet[idet]) > 0 )
138 
139  }//for(int idet=0; idet<2; idet++)
140 
141  }//(auto itr : fCorrelations)
142 
143  // Make the new input point and return it
144  pInputPoint = InputPoint( parameterSpaceLocation,
145  systematicPulls,
146  fixedParameters,
147  fixedSystematics );
148 
149  }// Correlations::ApplyCorrelations
std::pair< Spectrum *, CheatDecomp * > make_pair(SpectrumLoaderBase &loader_data, SpectrumLoaderBase &loader_mc, HistAxis *axis, Cut *cut, const SystShifts &shift, const Var &wei)
Definition: DataMCLoad.C:336
Far Detector at Ash River, MN.
Near Detector in the NuMI cavern.
std::vector< fnex::simple_correlation > fCorrelations
Definition: Correlations.h:71
#define LOG_VERBATIM(category)
void fnex::Correlations::ApplyCorrelations ( StringPointMap pStringPointMap)

Definition at line 154 of file Correlations.cxx.

References confusionMatrixTree::count, runNovaSAM::detectors, allTimeWatchdog::endl, HTMLTools::entry(), fCorrelations, update_sam_good_runs_metadata::good, novadaq::cnv::kFARDET, novadaq::cnv::kNEARDET, LOG_VERBATIM, and make_pair().

154  {
155 
156  // Loop through the correlations vector. Check that systematics
157  // (second osc. params) have one (and only one) match to each
158  // the ind. and dep. variables. Apply the correlations, and set
159  // Fixed: true for all dep. variables so that the fitter doesn't
160  // adjust them. Output a message if Fixed was not true ahead of time.
161  // Debug messages "DepVarShift = Corr*IndVarShift : INIT --> FINAL
162 
163  std::vector<novadaq::cnv::DetId> detectors;
164  detectors.push_back(novadaq::cnv::kNEARDET);
165  detectors.push_back(novadaq::cnv::kFARDET);
166 
167  std::vector<bool> good (fCorrelations.size(), false);
168  std::vector<bool> tooMany(fCorrelations.size(), false);
169 
170  // Make a new stringpointmap as a copy of the first
171  // This is the first part of a two part process to get around InputPoint
172  // objects being constant; we must construct new ones for each
173  // experiment being correlated
174  std::map<std::string, ParameterDetMap> parameterSpaceLocMap;
175  std::map<std::string, ParameterDetMap> systematicPullsMap;
176  std::map<std::string, std::vector<ParameterDet> > fixedParametersMap;
177  std::map<std::string, std::vector<ParameterDet> > fixedSystematicsMap;
178 
179  //std::cout << " Num points to correlate: " << pStringPointMap.size() << std::endl;
180  for(auto & point : pStringPointMap){
181  //std::cout << " IN APPLY CORR LOOKING AT INPUT POINT\n";
182  //std::cout << point.second;
183  parameterSpaceLocMap .emplace(point.first, point.second.ParameterSpaceLocation());
184  systematicPullsMap .emplace(point.first, point.second.SystematicPulls());
185  fixedParametersMap .emplace(point.first, point.second.FixedParameters());
186  fixedSystematicsMap .emplace(point.first, point.second.FixedSystematics());
187  }
188 
189  // Start looping through the set of all correlations
190  for(size_t icorr = 0; icorr < fCorrelations.size(); ++icorr){
191 
192  auto thiscorr = fCorrelations[icorr];
193 
194  // Check that each required experiment is present; else ignore
195  bool haveDepExp = (pStringPointMap.count(thiscorr.depExp)>0);
196  bool haveIndExp = (pStringPointMap.count(thiscorr.indExp)>0);
197 
198  if(!haveIndExp || !haveDepExp) continue;
199 
200  // Define and set the parameter det maps
201  std::vector<ParameterDet> depParDet(2);
202  std::vector<ParameterDet> indParDet(2);
203  for(int idet = 0; idet < 2; ++idet){
204  depParDet[idet] = std::make_pair(thiscorr.depVar, detectors[idet]);
205  indParDet[idet] = std::make_pair(thiscorr.indVar, detectors[idet]);
206  }
207 
208  // Grab the two sets of InputPoint contents
209  ParameterDetMap * depParameterSpaceLocation = &(parameterSpaceLocMap[thiscorr.depExp]);
210  ParameterDetMap * depSystematicPulls = &(systematicPullsMap[thiscorr.depExp]);
211  std::vector<ParameterDet> * depFixedParameters = &(fixedParametersMap[thiscorr.depExp]);
212  std::vector<ParameterDet> * depFixedSystematics = &(fixedSystematicsMap[thiscorr.depExp]);
213 
214  ParameterDetMap * indParameterSpaceLocation = &(parameterSpaceLocMap[thiscorr.indExp]);
215  ParameterDetMap * indSystematicPulls = &(systematicPullsMap[thiscorr.indExp]);
216 
217  // Check that the dep and indep variables are present
218  bool haveDepVar = false;
219  bool haveIndVar = false;
220  /*
221  std::vector<ParameterDet> * indFixedParameters = &(fixedParametersMap[thiscorr.indExp]);
222  std::vector<ParameterDet> * indFixedSystematics = &(fixedSystematicsMap[thiscorr.indExp]);
223  for(int idet=0; idet<2; idet++){
224  std::cout << " depParameterSpaceLocation->count( "
225  << thiscorr.depVar << " : "
226  << depParameterSpaceLocation->count(depParDet[idet]) << std::endl;
227  std::cout << " depSystematicPulls->count( "
228  << thiscorr.depVar << " : "
229  << depSystematicPulls->count(depParDet[idet]) << std::endl;
230  std::cout << " indParameterSpaceLocation->count( "
231  << thiscorr.depVar << " : "
232  << indParameterSpaceLocation->count(indParDet[idet]) << std::endl;
233  std::cout << " indSystematicPulls->count( "
234  << thiscorr.depVar << " : "
235  << indSystematicPulls->count(indParDet[idet]) << std::endl;
236  }*/
237 
238  for(int idet = 0; idet < 2; ++idet){
239  haveDepVar = (haveDepVar ||
240  depParameterSpaceLocation->count(depParDet[idet]) > 0 ||
241  depSystematicPulls->count(depParDet[idet]) > 0 );
242  haveIndVar = (haveIndVar ||
243  indParameterSpaceLocation->count(indParDet[idet]) > 0 ||
244  indSystematicPulls->count(indParDet[idet]) > 0 );
245  }
246 
247  if(!haveIndVar || !haveDepVar) continue;
248 
249  // Find the value of the independent variable
250  double indVal;
251  for(int idet = 0; idet < 2; ++idet){
252  if( indParameterSpaceLocation->count(indParDet[idet]) > 0 ) indVal = (*indParameterSpaceLocation)[indParDet[idet]];
253  if( indSystematicPulls ->count(indParDet[idet]) > 0 ) indVal = (*indSystematicPulls)[indParDet[idet]];
254  }
255 
256  // Now find the dependent variable and set it
257  for(int idet = 0; idet < 2; ++idet){
258 
259  // First in the case that it is a parameterSpaceLocation
260  if( depParameterSpaceLocation->count(depParDet[idet]) > 0 ){
261  LOG_VERBATIM("Correlations") << " Correlating: "
262  << std::setw(20) << thiscorr.depExp << ":"
263  << std::setw(20) << thiscorr.depVar
264  << " = ( " << (*depParameterSpaceLocation)[depParDet[idet]] << " )\n"
265  << " as "
266  << std::setw(20) << thiscorr.indExp << ":"
267  << std::setw(20) << thiscorr.indVar
268  << " = ( " << indVal << " ) * "
269  << std::setw(10) << thiscorr.corr << "\n"
270  << " giving new val "
271  << std::setw(10) << indVal * thiscorr.corr
272  << std::endl;
273 
274  (*depParameterSpaceLocation)[depParDet[idet]] = indVal * thiscorr.corr;
275 
276  if(std::find(depFixedParameters->begin(), depFixedParameters->end(), depParDet[idet]) != depFixedParameters->end()){
277  LOG_VERBATIM("Correlations") << thiscorr.depVar << " not fixed! Setting Fixed: true\n";
278  depFixedParameters->push_back(depParDet[idet]);
279  }else{
280  LOG_VERBATIM("Correlations") << thiscorr.depVar << " already fixed. Good!\n";
281  }
282 
283  }//if( deparameterSpaceLocation.count(depParDet[idet]) > 0 )
284 
285  // Then, if it is a systematicPull
286  if( depSystematicPulls->count(depParDet[idet]) > 0 ){
287  LOG_VERBATIM("Correlations") << " Correlating: "
288  << std::setw(20) << thiscorr.depExp << ":"
289  << std::setw(20) << thiscorr.depVar
290  << " = ( " << (*depSystematicPulls)[depParDet[idet]] << " )\n"
291  << " as "
292  << std::setw(20) << thiscorr.indExp << ":"
293  << std::setw(20) << thiscorr.indVar
294  << " = ( " << std::setw(10) << indVal << " ) * "
295  << std::setw(10) << thiscorr.corr << "\n"
296  << " giving new val "
297  << std::setw(10) << indVal * thiscorr.corr
298  << std::endl;
299 
300  (*depSystematicPulls)[depParDet[idet]] = indVal * thiscorr.corr;
301 
302  if(std::find(depFixedSystematics->begin(), depFixedSystematics->end(), depParDet[idet]) != depFixedSystematics->end()){
303  LOG_VERBATIM("Correlations") << thiscorr.depVar << " not fixed! Setting Fixed: true\n";
304  (*depFixedSystematics).push_back(depParDet[idet]);
305  }else{
306  LOG_VERBATIM("Correlations") << thiscorr.depVar << " already fixed. Good!\n";
307  }
308 
309  }//if( depSystematicPulls.count(depParDet[idet]) > 0 )
310 
311  }//for(int idet=0; idet<2; idet++)
312 
313  }//(auto itr : fCorrelations)
314 
315  // Now modify the StringPointMap to return
316  // This is the second part of a two part process to get around InputPoint
317  // objects being constant; we must construct new ones for each
318  // experiment being correlated
319  for( auto entry: pStringPointMap){
320  pStringPointMap[entry.first] = InputPoint(parameterSpaceLocMap[entry.first],
321  systematicPullsMap[entry.first],
322  fixedParametersMap[entry.first],
323  fixedSystematicsMap[entry.first] );
324  }
325 
326 
327  }// Correlations::ApplyCorrelations
std::pair< Spectrum *, CheatDecomp * > make_pair(SpectrumLoaderBase &loader_data, SpectrumLoaderBase &loader_mc, HistAxis *axis, Cut *cut, const SystShifts &shift, const Var &wei)
Definition: DataMCLoad.C:336
Far Detector at Ash River, MN.
Near Detector in the NuMI cavern.
std::unordered_map< ParameterDet, double, ParameterDetHasher > ParameterDetMap
Definition: Constants.h:63
std::vector< fnex::simple_correlation > fCorrelations
Definition: Correlations.h:71
#define LOG_VERBATIM(category)
def entry(str)
Definition: HTMLTools.py:26
bool fnex::Correlations::IsConfigured ( )

Definition at line 17 of file Correlations.cxx.

References fIsConfigured.

17  {
18  return fIsConfigured;
19  }
void fnex::Correlations::Print ( std::ostream &  outfile = std::cout) const

Definition at line 339 of file Correlations.cxx.

References allTimeWatchdog::endl, fCorrelations, ToString(), and w.

339  {
340  int w = 20;
341  int w2 = 30;
342  outfile << " Correlations Instance: " << this->ToString() << std::endl;
343  outfile << std::setw(w) << "DepExp" << std::setw(w2) << "DepVar"
344  << std::setw(w) << "IndExp" << std::setw(w2) << "IndVar"
345  << std::setw(w) << "Corr" << std::endl;
346  for(auto itr : fCorrelations){
347  outfile << std::setw(w) << itr.depExp << std::setw(w2) << itr.depVar
348  << std::setw(w) << itr.indExp << std::setw(w2) << itr.indVar
349  << std::setw(w) << itr.corr << std::endl;
350  }
351  return;
352  }
const std::string ToString() const
std::vector< fnex::simple_correlation > fCorrelations
Definition: Correlations.h:71
Float_t w
Definition: plot.C:20
FILE * outfile
Definition: dump_event.C:13
void fnex::Correlations::Reconfigure ( fhicl::ParameterSet const &  pset)

Definition at line 24 of file Correlations.cxx.

References fnex::simple_correlation::corr, fnex::simple_correlation::depExp, fnex::simple_correlation::depVar, fCorrelations, fInstanceName, fhicl::ParameterSet::get(), fnex::simple_correlation::indExp, fnex::simple_correlation::indVar, and string.

Referenced by Correlations().

24  {
25 
26  // Get name/type
27  fInstanceName = pset.get<std::string>("CorrelationsType","NoTypeProvided");
28 
29  // Get set of correlations
30  std::vector<fhicl::ParameterSet> corr_psets = pset.get<std::vector<fhicl::ParameterSet>>("Correlations");
31 
32  // Loop over these correlations
33  fCorrelations.resize(0);
34  for(auto itr : corr_psets){
35  fnex::simple_correlation thiscorr;
36  thiscorr.depExp = itr.get<std::string>("DepExp", "None");
37  thiscorr.indExp = itr.get<std::string>("IndepExp", "None");
38  thiscorr.depVar = itr.get<std::string>("DepVar" );
39  thiscorr.indVar = itr.get<std::string>("IndepVar" );
40  thiscorr.corr = itr.get<double >("Corr" );
41  fCorrelations.push_back(thiscorr);
42  }
43 
44  //this->Print();
45 
46  }
std::string fInstanceName
Definition: Correlations.h:68
std::vector< fnex::simple_correlation > fCorrelations
Definition: Correlations.h:71
enum BeamMode string
const std::string fnex::Correlations::ToString ( ) const

Definition at line 332 of file Correlations.cxx.

References fInstanceName, r(), and string.

Referenced by Print().

332  {
334  return r;
335  }
std::string fInstanceName
Definition: Correlations.h:68
TRandom3 r(0)
enum BeamMode string

Member Data Documentation

std::vector<fnex::simple_correlation> fnex::Correlations::fCorrelations
protected

Definition at line 71 of file Correlations.h.

Referenced by ApplyCorrelations(), Print(), and Reconfigure().

std::string fnex::Correlations::fInstanceName
protected

Definition at line 68 of file Correlations.h.

Referenced by Reconfigure(), and ToString().

bool fnex::Correlations::fIsConfigured
protected

Definition at line 65 of file Correlations.h.

Referenced by IsConfigured().


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