NAGASH 0.9.8
Next Generation Analysis System
Loading...
Searching...
No Matches
Classes | Public Member Functions | Private Attributes | List of all members
NAGASH::SystTool Class Reference

Manage systematic variations. More...

#include "NAGASH/SystTool.h"

Inheritance diagram for NAGASH::SystTool:
NAGASH::Tool

Classes

struct  AuxVar
 
struct  VarWithSyst
 

Public Member Functions

 SystTool (std::shared_ptr< MSGTool > MSG)
 
template<typename T >
void BookVariation (const TString &name, const TString &systname, T *var)
 Book a systematic variation of a parameter.
 
const TString & CurrentVariation ()
 Get the name of the current systematic variation.
 
template<typename T >
Get (const TString &name)
 Get the value of the parameter with the current systematic variation.
 
const std::vector< TString > & GetListOfVariations ()
 get the list of all systematic variations.
 
std::vector< TString > GetListOfVariations (const TString &name)
 get the list of all systematic variations of given parameter.
 
int GetNVariations ()
 get the number of systematic variations.
 
int GetNVariations (const TString &name)
 get the number of systematic variations of given parameter.
 
double GetVariationCorrelation (const TString &name)
 Get the correlation factor of the given systematic variation.
 
void SetToVariation (const TString &name)
 set the current variation to the given one.
 
void SetVariationCorrelation (const TString &name, double correlation)
 Set the correlation factor of the given systematic variation.
 

Private Attributes

std::map< TString, double > CorrMap
 
TString currentvar
 
bool isSetVar = false
 
bool isSystListSorted = false
 
std::vector< TString > SystList
 
std::map< TString, std::vector< TString > > SystListMap
 
std::map< TString, std::vector< AuxVar > > SystMapFull
 
std::map< TString, VarWithSystVarMapFull
 

Additional Inherited Members

- Protected Member Functions inherited from NAGASH::Tool
 Tool ()=delete
 
 Tool (const Tool &tool)=delete
 
 Tool (std::shared_ptr< MSGTool > MSG)
 Constructor.
 
 Tool (Tool &&tool)=delete
 
virtual ~Tool ()=default
 
std::shared_ptr< MSGToolMSGUser ()
 return the MSGTool inside.
 
Tooloperator= (const Tool &tool)=delete
 
Tooloperator= (Tool &&tool)=delete
 

Detailed Description

Manage systematic variations.

Here is a demonstration of how to use the SystTool:

#include "NAGASH.h"
using namespace NAGASH;
int main()
{
auto msg = std::make_shared<MSGTool>();
auto config = std::make_shared<ConfigTool>();
ResultGroup MyResult(msg, config);
// prepare for data
auto MyEV = MyResult.BookResult<EventVector>("MyEV");
double Energy_Nominal;
double Energy_Resolution;
double Energy_ScaleUp;
double Energy_ScaleDown;
MyEV->BookVariable("Energy_Nominal", &Energy_Nominal);
MyEV->BookVariable("Energy_Resolution", &Energy_Resolution);
MyEV->BookVariable("Energy_ScaleUp", &Energy_ScaleUp);
MyEV->BookVariable("Energy_ScaleDown", &Energy_ScaleDown);
TRandom3 myrnd(12345);
for (int i = 0; i < 1e4; i++)
{
Energy_Nominal = myrnd.Gaus(10, 3);
Energy_Resolution = Energy_Nominal * myrnd.Gaus(1, 0.02);
Energy_ScaleUp = Energy_Nominal * 1.001;
Energy_ScaleDown = Energy_Nominal * 0.999;
MyEV->Fill();
}
// define variables
MyEV->SetVariableAddress("Energy_Nominal", &Energy_Nominal);
MyEV->SetVariableAddress("Energy_Resolution", &Energy_Resolution);
MyEV->SetVariableAddress("Energy_ScaleUp", &Energy_ScaleUp);
MyEV->SetVariableAddress("Energy_ScaleDown", &Energy_ScaleDown);
// set systematic variations
SystTool systtool(msg);
systtool.BookVariation<double>("E", "Nominal", &Energy_Nominal);
systtool.BookVariation<double>("E", "Resolution", &Energy_Resolution);
systtool.BookVariation<double>("E", "ScaleUp", &Energy_ScaleUp);
systtool.BookVariation<double>("E", "ScaleDown", &Energy_ScaleDown);
auto systlist = systtool.GetListOfVariations();
auto EnergyPlot = MyResult.BookResult<Plot1D>("EnergyPlot", "output.root", 20, 0, 20);
for (int i = 1; i < systlist.size(); i++) // start from index one since the first variation is always the nominal(need not to book)
EnergyPlot->BookSystematicVariation(systlist.at(i), 1); // the first argument is the name of variation
// the second is the correlation factor of this variation
for (int i = 0; i < 1e4; i++)
{
MyEV->GetEvent(i);
for (int j = 0; j < systlist.size(); j++)
{
systtool.SetToVariation(systlist[j]);
EnergyPlot->SetSystematicVariation(j); // the zeroth variation is nominal
// the order of variations in Plot1D is the order when booking them
// use index to save the time of switching between variations
EnergyPlot->Fill(systtool.Get<double>("E"));
}
}
EnergyPlot->WriteToFile();
return 1;
}
int main(int argc, char **argv)
Deprecated. It's better to use user defined event vector.
Definition EventVector.h:17
void BookVariable(const TString &name, int *value)
NAGASH interface for using ROOT histograms.
Definition NGHist.h:18
bool BookSystematicVariation(const TString &name, double corr_factor=0, SystPolicy policy=SystPolicy::Maximum) override
Book a systematic variation.
Definition NGHist.h:924
Used to manipulate a group of Result objects., especially inside NAGASH::Job.
Definition ResultGroup.h:20
Manage systematic variations.
Definition SystTool.h:14
std::shared_ptr< MSGTool > msg
Definition Tool.h:88

You can run the code and check the content of the output file output.root.

Definition at line 13 of file SystTool.h.

Constructor & Destructor Documentation

◆ SystTool()

NAGASH::SystTool::SystTool ( std::shared_ptr< MSGTool MSG)
inline

Definition at line 16 of file SystTool.h.

Member Function Documentation

◆ BookVariation()

template<typename T >
void NAGASH::SystTool::BookVariation ( const TString &  name,
const TString &  systname,
T *  var 
)

Book a systematic variation of a parameter.

Template Parameters
Tthe type of the parameter.
Parameters
namethe name of the parameter.
systnamethe name of the systematic variation.
varthe pointer to the variation.

Definition at line 60 of file SystTool.h.

◆ CurrentVariation()

const TString & SystTool::CurrentVariation ( )

Get the name of the current systematic variation.

Definition at line 85 of file SystTool.cxx.

◆ Get()

template<typename T >
T NAGASH::SystTool::Get ( const TString &  name)

Get the value of the parameter with the current systematic variation.

Template Parameters
Tthe type of the parameter.
Parameters
namethe name of the parameter.
Returns
current variation value of the parameter.

Definition at line 108 of file SystTool.h.

◆ GetListOfVariations() [1/2]

const std::vector< TString > & SystTool::GetListOfVariations ( )

get the list of all systematic variations.

Definition at line 136 of file SystTool.cxx.

◆ GetListOfVariations() [2/2]

std::vector< TString > SystTool::GetListOfVariations ( const TString &  name)

get the list of all systematic variations of given parameter.

Parameters
namethe name of the parameter.

Definition at line 160 of file SystTool.cxx.

◆ GetNVariations() [1/2]

int SystTool::GetNVariations ( )

get the number of systematic variations.

Definition at line 237 of file SystTool.cxx.

◆ GetNVariations() [2/2]

int SystTool::GetNVariations ( const TString &  name)

get the number of systematic variations of given parameter.

Parameters
namethe name of the parameter.

Definition at line 244 of file SystTool.cxx.

◆ GetVariationCorrelation()

double SystTool::GetVariationCorrelation ( const TString &  name)

Get the correlation factor of the given systematic variation.

Parameters
namethe name of the systematic variation.

Definition at line 119 of file SystTool.cxx.

◆ SetToVariation()

void SystTool::SetToVariation ( const TString &  name)

set the current variation to the given one.

Parameters
namethe name of the systematic variation.

Definition at line 178 of file SystTool.cxx.

◆ SetVariationCorrelation()

void SystTool::SetVariationCorrelation ( const TString &  name,
double  correlation 
)

Set the correlation factor of the given systematic variation.

Parameters
namethe name of the systematic variation.
correlationthe correlation factor of the systematic variation.

Definition at line 102 of file SystTool.cxx.

Member Data Documentation

◆ CorrMap

std::map<TString, double> NAGASH::SystTool::CorrMap
private

Definition at line 49 of file SystTool.h.

◆ currentvar

TString NAGASH::SystTool::currentvar
private

Definition at line 46 of file SystTool.h.

◆ isSetVar

bool NAGASH::SystTool::isSetVar = false
private

Definition at line 44 of file SystTool.h.

◆ isSystListSorted

bool NAGASH::SystTool::isSystListSorted = false
private

Definition at line 45 of file SystTool.h.

◆ SystList

std::vector<TString> NAGASH::SystTool::SystList
private

Definition at line 51 of file SystTool.h.

◆ SystListMap

std::map<TString, std::vector<TString> > NAGASH::SystTool::SystListMap
private

Definition at line 50 of file SystTool.h.

◆ SystMapFull

std::map<TString, std::vector<AuxVar> > NAGASH::SystTool::SystMapFull
private

Definition at line 48 of file SystTool.h.

◆ VarMapFull

std::map<TString, VarWithSyst> NAGASH::SystTool::VarMapFull
private

Definition at line 47 of file SystTool.h.


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