HighLAND
tutorialWeightSystematics.cxx
1 #include "tutorialWeightSystematics.hxx"
2 #include "ND280AnalysisUtils.hxx"
3 #include "BasicUtils.hxx"
4 #include "ToyBoxTracker.hxx"
5 
6 //********************************************************************
7 /// Default constructor
9  //********************************************************************
10  Int_t baseindex=0;
11 
12  // With this instruction the BinnedParams class will read the file FGD1Mass_p5F or FGD1Mass_p6B (hence the versionUtils::Extension()), which has
13  // a format BinnedParams::k1D_SYMMETRIC (tells BinnedParams to interprete the parameters in those files)
14  _scintmass= new BinnedParams("FGD1Mass", BinnedParams::k1D_SYMMETRIC,versionUtils::Extension());
15 
16  // Get the number of parameters read from the file
17  baseindex+=_scintmass->GetNBins();
18 
19  // In the same way for the file FGD2MassWater.dat, with no production extension
20  _watermass = new BinnedParams("FGD2MassWater",BinnedParams::k1D_SYMMETRIC);
21 
22  // Increment the number of parameters
23  baseindex+=_watermass->GetNBins();
24 
25  // Set the total number of parameters
26  SetNParameters(baseindex);
27 
28  // For this particular example there is a single parameter in each of the files, get the numbers thers
29  // and save them in four simple float variables that we can use later
30  _scintmass->GetParametersForBin(0, _scintmass_corr, _scintmass_err);
31  _watermass->GetParametersForBin(0, _watermass_corr, _watermass_err);
32 }
33 
34 //********************************************************************
36 //********************************************************************
37 
38  const AnaEventB& event = *static_cast<const AnaEventB*>(&eventC);
39 
40  // Cast the ToyBox to the appropriate type
41  const ToyBoxTracker& box = *static_cast<const ToyBoxTracker*>(&boxB);
42 
43  // This is a class (WeightBase, in psycheCore) that holds to floats, a correction and a systematic (see below)
44  Weight_h eventWeight=1;
45 
46  // True vertex associated to the recon vertex should exist
47  if (!box.Vertex->TrueVertex) return eventWeight;
48 
49  // ----- Apply FGD mass systematic only when the true vertex is in FGD --------
50 
51  // Depending on FGD1 or FGD2
52  if( box.DetectorFV==SubDetId::kFGD1){ // Event selected in FGD1 FV
53  if (anaUtils::InDetVolume(SubDetId::kFGD1, box.Vertex->TrueVertex->Position)){ // TrueVertex in FGD1 FV
54  eventWeight.Systematic = 1 + _scintmass_corr + _scintmass_err * toy.GetToyVariations(_index)->Variations[0];
55  eventWeight.Correction = 1 + _scintmass_corr;
56  }
57  }
58  else if( box.DetectorFV==SubDetId::kFGD2){ // Event selected in FGD2 FV
59  if (anaUtils::InDetVolume(SubDetId::kFGD2, box.Vertex->TrueVertex->Position)){ // TrueVertex in FGD2 FV
60  // Check water of scintilator
61  if (anaUtils::GetFgdModuleTypeNoFV(event.GetIsMC(), box.Vertex->TrueVertex->Position,true) == 2){
62  // Use the numbers for water
63  eventWeight.Systematic = 1 + _watermass_corr + _watermass_err * toy.GetToyVariations(_index)->Variations[1];
64  eventWeight.Correction = 1 + _watermass_corr;
65  }
66  else{
67  // Use the numbers for scintillator
68  eventWeight.Systematic = 1 + _scintmass_corr + _scintmass_err * toy.GetToyVariations(_index)->Variations[0];
69  eventWeight.Correction = 1 + _scintmass_corr;
70  }
71  }
72  }
73  return eventWeight;
74 }
Int_t _index
The index of this systematic (needed by SystematicsManager);.
AnaTrueVertexB * TrueVertex
Float_t * Variations
the vector of Variations, one for each of the systematic parameters
Weight_h ComputeWeight(const ToyExperiment &toy, const AnaEventC &event, const ToyBoxB &box)
SubDetId_h DetectorFV
Indicate the FV we are interested in.
Definition: ToyBoxB.hxx:52
void SetNParameters(int N)
Set the number of systematic parameters associated to this systematic.
tutorialWeightSystematics()
Default constructor.
AnaVertexB * Vertex
For storing the reconstructed vertex.
Float_t Position[4]
The position the true interaction happened at.
Float_t _scintmass_corr
FGD mass correction and error.
ToyVariations * GetToyVariations(UInt_t index) const
returns the variations for a given systematic (index)
bool InDetVolume(SubDetId::SubDetEnum det, const Float_t *pos)
bool GetParametersForBin(Int_t index, Float_t &mean, Float_t &sigma)
Gets the bin values for a source provided the bin index.
Int_t GetNBins()
Get the number of bins.