HighLAND
MichelElectronEffSystematics.cxx
1 #include "MichelElectronEffSystematics.hxx"
2 #include "ND280AnalysisUtils.hxx"
3 #include "EventBoxTracker.hxx"
4 #include "ToyBoxTracker.hxx"
5 #include "SubDetId.hxx"
6 #include "SystId.hxx"
7 #include "EventBoxId.hxx"
8 #include "SystematicUtils.hxx"
9 #include "Parameters.hxx"
10 #include "VersioningUtils.hxx"
11 
12 //********************************************************************
14 //********************************************************************
15  _computecounters=comp;
16  // Get the michel electron efficiency values
17  Int_t baseindex=0;
18  _fgd1eff = new BinnedParams("FGD1MichelElectronEff", BinnedParams::k1D_EFF_SYMMETRIC, versionUtils::Extension());
19  baseindex+=_fgd1eff->GetNBins();
20  _fgd1pur = new BinnedParams("FGD1MichelElectronPur", BinnedParams::k1D_EFF_SYMMETRIC, versionUtils::Extension());
21  baseindex+=_fgd1pur->GetNBins();
22  if(versionUtils::prod6_systematics){
23  _fgd2eff = new BinnedParams("FGD2MichelElectronEff", BinnedParams::k1D_EFF_SYMMETRIC, versionUtils::Extension());
24  baseindex+=_fgd2eff->GetNBins();
25  _fgd2pur = new BinnedParams("FGD2MichelElectronPur", BinnedParams::k1D_EFF_SYMMETRIC, versionUtils::Extension());
26  baseindex+=_fgd2pur->GetNBins();
27  }
28 
29  if(_computecounters){
30  _fgd1pur->InitializeEfficiencyCounter();
31  _fgd1eff->InitializeEfficiencyCounter();
32  if(versionUtils::prod6_systematics){
33  _fgd2pur->InitializeEfficiencyCounter();
34  _fgd2eff->InitializeEfficiencyCounter();
35  }
36  }
37 
38  SetNParameters(2*baseindex);
39 
40  _prod5Cut = ND::params().GetParameterI("psycheSystematics.Prod5Cuts");
41 
42 }
43 
44 //********************************************************************
46 //********************************************************************
47 
48  const AnaEventB& event = *static_cast<const AnaEventB*>(&eventBB);
49 
50  // Cast the ToyBox to the appropriate type
51  const ToyBoxTracker& box = *static_cast<const ToyBoxTracker*>(&boxB);
52 
53  if(_computecounters){
54  _fgd1pur->InitializeEfficiencyCounter();
55  _fgd1eff->InitializeEfficiencyCounter();
56  if(versionUtils::prod6_systematics){
57  _fgd2pur->InitializeEfficiencyCounter();
58  _fgd2eff->InitializeEfficiencyCounter();
59  }
60  }
61 
62  Weight_h eventWeight=1;
63 
64  // Vertex and True vertex should exist
65  if (!box.Vertex->TrueVertex) return eventWeight;
66 
67  Int_t runPeriod = anaUtils::GetRunPeriod(event.EventInfo.Run);
68  // Get the number of true michel electrons
69  Int_t trueNME = anaUtils::GetNMichelElectrons(*(box.Vertex->TrueVertex), static_cast<SubDetId::SubDetEnum>(box.DetectorFV));
70  if (trueNME<0 ) trueNME=0;
71 
72  // Must cast to EventBoxTracker since MichelElectrons are not in EventBoxB
73  EventBoxTracker* EventBox = static_cast<EventBoxTracker*>(event.EventBoxes[EventBoxId::kEventBoxTracker]);
74 
75  // Get the number of reconstructed michel electrons
76  UInt_t NME=EventBox->nFGDMichelElectrons[box.DetectorFV];
77  // Get the number of reconstructed michel electrons
78  BinnedParamsParams effparams,purparams;
79  Int_t effindex,purindex;
80  bool doeff= false;
81  bool dopur= false; _fgd1pur->GetBinValues((float)runPeriod, purparams, purindex);
82  if(box.DetectorFV == SubDetId::kFGD1){
83  doeff= _fgd1eff->GetBinValues((float)runPeriod, effparams, effindex);
84  dopur= _fgd1pur->GetBinValues((float)runPeriod, purparams, purindex);
85  purindex+=_fgd1eff->GetNBins();
86  }
87  else if(box.DetectorFV == SubDetId::kFGD2){
88  if(versionUtils::prod6_systematics){
89  doeff= _fgd2eff->GetBinValues((float)runPeriod, effparams, effindex);
90  dopur= _fgd2pur->GetBinValues((float)runPeriod, purparams, purindex);
91  purindex+=_fgd2eff->GetNBins();
92  }
93  }
94 
95  if (trueNME>0){
96  bool found= ( NME>0 );
97 
98  if (doeff)
99  eventWeight *= systUtils::ComputeEffLikeWeight(found, toy, GetIndex(), 0, effparams);
100 
101  if(_computecounters){
102  if(box.DetectorFV == SubDetId::kFGD1)
103  _fgd1eff->UpdateEfficiencyCounter(effindex,found);
104  else if(box.DetectorFV == SubDetId::kFGD2 && versionUtils::prod6_systematics)
105  _fgd2eff->UpdateEfficiencyCounter(effindex,found);
106 
107  }
108  }
109  if(NME>0){
110  //we don't want to apply the same variation as the efficiency
111  bool found = (trueNME>0);
112 
113  if (dopur)
114  eventWeight *= systUtils::ComputeEffLikeWeight(found, toy, GetIndex(), purindex, purparams);
115 
116  if(_computecounters){
117  if(box.DetectorFV == SubDetId::kFGD1)
118  _fgd1pur->UpdateEfficiencyCounter(purindex-_fgd1eff->GetNBins(),found);
119  else if(box.DetectorFV == SubDetId::kFGD2 && versionUtils::prod6_systematics)
120  _fgd2pur->UpdateEfficiencyCounter(purindex-_fgd2eff->GetNBins(),found);
121  }
122  }
123 
124  return eventWeight;
125 }
126 
AnaTrueVertexB * TrueVertex
Int_t GetIndex() const
Return the index of this systematic.
int GetParameterI(std::string)
Get parameter. Value is returned as integer.
Definition: Parameters.cxx:217
Int_t GetNMichelElectrons(const AnaTrueVertexB &trueVertex, SubDetId::SubDetEnum det=SubDetId::kFGD1)
Get the number of true michel electrons.
Definition: TruthUtils.cxx:6
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.
bool GetBinValues(Float_t value, Float_t &mean, Float_t &sigma)
Gets the bin values for a 1D source.
bool UpdateEfficiencyCounter(Int_t index, bool correct)
Update the efficiency variables _ncorrect and _nwrong.
AnaVertexB * Vertex
For storing the reconstructed vertex.
int GetRunPeriod(int run, int subrun=-1)
Returns the run period (sequentially: 0,1,2,3,4,5 ...)
MichelElectronEffSystematics(bool computecounters=false)
void InitializeEfficiencyCounter()
Initialize counters.
Weight_h ComputeWeight(const ToyExperiment &toy, const AnaEventC &event, const ToyBoxB &box)
Int_t GetNBins()
Get the number of bins.