HighLAND
nueOOFVSystematics.cxx
1 #include "nueOOFVSystematics.hxx"
2 #include "ND280AnalysisUtils.hxx"
3 #include "ToyBoxTracker.hxx"
4 #include "BasicUtils.hxx"
5 #include "SubDetId.hxx"
6 #include "FiducialVolumeDefinition.hxx"
7 #include "VersioningUtils.hxx"
8 
9 //********************************************************************
10 nueOOFVSystematics::nueOOFVSystematics():EventWeightBase(1){
11 //********************************************************************
12 
13  int npars=0;
14 
15  _fgd1 = new BinnedParams("OOFV_reco_fgd1_p6B",BinnedParams::k1D_SYMMETRIC);
16  npars=_fgd1->GetNBins();
17  _fgd2 = new BinnedParams("OOFV_reco_fgd2_p6B",BinnedParams::k1D_SYMMETRIC);
18  npars+=_fgd2->GetNBins();
19  _rate = new BinnedParams("nueOOFV_rate" ,BinnedParams::k1D_SYMMETRIC);
20  npars+=_rate->GetNBins();
21 
22  SetNParameters(npars);
23 
24  for (int i=0;i<9;i++){
25  if (!_fgd1->GetBinValues(i, _reco_corr[0][i], _reco_error[0][i],_reco_index[0][i])) _reco_index[0][i]=-1;
26  if (!_fgd2->GetBinValues(i, _reco_corr[1][i], _reco_error[1][i],_reco_index[1][i])) _reco_index[1][i]=-1;
27 
28  if (_reco_index[0][i]>=0) _reco_index[0][i] += _rate->GetNBins();
29  if (_reco_index[1][i]>=0) _reco_index[1][i] += _rate->GetNBins();
30  }
31 
32 }
33 
34 //********************************************************************
35 Int_t nueOOFVSystematics::GetDetNumber(SubDetId::SubDetEnum det){
36 //********************************************************************
37 
39  return 0;
40  else if(SubDetId::IsECALDetector(det))
41  return 1;
42  else if(SubDetId::IsTECALDetector(det))
43  return 1;
44  else if(SubDetId::IsPECALDetector(det))
45  return 1;
46  else if(SubDetId::IsSMRDDetector(det))
47  return 2;
48  else if(SubDetId::IsTPCDetector(det))
49  return 3;
50  else if(SubDetId::IsFGDDetector(det))
51  return -1;
52  else
53  return 4;
54 }
55 
56 //********************************************************************
58 //********************************************************************
59 
60  const AnaEventB& event = *static_cast<const AnaEventB*>(&eventBB);
61 
62  // Cast the ToyBox to the appropriate type
63  const ToyBoxTracker& box = *static_cast<const ToyBoxTracker*>(&boxB);
64 
65  (void)event;
66 
67  Weight_h eventWeight=1;
68  if (!box.MainTrack) return eventWeight; // HMN track should exist
69  if (!box.MainTrack->TrueObject) return eventWeight; // True track associated to HMN track should exist
70  if (!box.MainTrack->GetTrueParticle()->TrueVertex) return eventWeight; // True vertex associated to HMN track should exist
71 
72  // Get the true vertex position
73  Float_t* tvertex = box.MainTrack->GetTrueParticle()->TrueVertex->Position;
74 
75  // if the true vertex is inside the FGD FV this is not OOFV (RETURN EVENTWEIGHT=1)
76  if(anaUtils::InFiducialVolume(static_cast<SubDetId::SubDetEnum>(box.DetectorFV), tvertex)) return eventWeight;
77 
78  // Get the true track direction and position
79  Float_t* tdir = box.MainTrack->GetTrueParticle()->Direction;
80  Float_t* pos = box.MainTrack->GetTrueParticle()->Position;
81 
82  Float_t* fgd_det_min;
83  Float_t* fgd_det_max;
84  double Zmin_lastmodule,zup,zdown;
85  bool lastmodule;
86  Int_t fgd;
87  if(box.DetectorFV == SubDetId::kFGD1){
88  fgd=0;
89 
90  fgd_det_min = DetDef::fgd1min;
91  fgd_det_max = DetDef::fgd1max;
92  Zmin_lastmodule = fgd_det_max[2]-DetDef::fgdXYModuleWidth; //427;
93  zup =-60;
94  zdown = 623;
95  }
96  else if(box.DetectorFV == SubDetId::kFGD2){
97  fgd=1;
98 
99  fgd_det_min = DetDef::fgd2min;
100  fgd_det_max = DetDef::fgd2max;
101  Zmin_lastmodule = 1780;
102  zup = 1298;
103  zdown = 1983.095;
104  }
105  else return eventWeight;
106 
107  lastmodule=( pos[2] >Zmin_lastmodule && pos[2] < fgd_det_max[2]);
108 
109  Int_t categ =-1;
110  //inFGD1scint. Put z condition first to be faster
111  if ((tvertex[2] > fgd_det_min[2] && tvertex[2] < fgd_det_max[2]) &&
112  (tvertex[0] > fgd_det_min[0] && tvertex[0] < fgd_det_max[0]) &&
113  (tvertex[1] > fgd_det_min[1] && tvertex[1] < fgd_det_max[1]))
114  categ=0;
115  //upstreamFGD1scint
116  else if ((tvertex[2] > zup && tvertex[2] < fgd_det_min[2]) &&
117  (tvertex[0] > -1335 && tvertex[0] < 1335) &&
118  (tvertex[1] > -1280.5 && tvertex[1] < 1280.5))
119  categ=1;
120  //downstreamFGD1scint
121  else if((tvertex[2] > fgd_det_max[2] && tvertex[2] < zdown) &&
122  (tvertex[0] > -1335 && tvertex[0] < 1335) &&
123  (tvertex[1] > -1280.5 && tvertex[1] < 1280.5))
124  categ=2;
125  //neutralparent
126  else if( box.MainTrack->GetTrueParticle()->ParentPDG == 2112 || box.MainTrack->GetTrueParticle()->ParentPDG == 22 ||
127  box.MainTrack->GetTrueParticle()->GParentPDG == 2112 || box.MainTrack->GetTrueParticle()->GParentPDG == 22)
128  categ=3;
129  //backwards
130  else if(tdir[2]<=-0.5)
131  categ=4;
132  //highangle
133  else if(tdir[2]>-0.5 && tdir[2]<0.5)
134  categ=5;
135  //veryforward
136  else if(fabs(tdir[0]/tdir[2])<0.07 || fabs(tdir[1]/tdir[2])<0.07)
137  categ=6;
138  //lastmodule
139  else if ( lastmodule && anaUtils::InDetVolume(static_cast<SubDetId::SubDetEnum>(box.DetectorFV), box.MainTrack->PositionStart))
140  categ=7;
141  else
142  categ=8;
143 
144  // Note that this is wrong for layer28-29, veryhighangle and veryforward,
145  // for those one matching reco should be rerun to understand how reco is changed, by now it is applied as a rate uncertainty... but....
146  if(categ>=0 ){
148 
149  if (!_rate->GetBinValues(GetDetNumber(detector), _rate_corr[0][0], _rate_error[0][0],_rate_index[0][0])) _rate_index[0][0]=-1;
150 
151  if (_reco_index[fgd][categ]>=0){
152  eventWeight.Systematic *= (1+ _reco_corr[fgd][categ] + _reco_error[fgd][categ] * toy.GetToyVariations(_index)->Variations[_reco_index[fgd][categ]]);
153  eventWeight.Correction *= (1+ _reco_corr[fgd][categ]);
154  }
155  if (_rate_index[0][0]>=0){
156  eventWeight.Systematic *= (1+ _rate_corr[0][0] + _rate_error[0][0] * toy.GetToyVariations(_index)->Variations[_rate_index[0][0]]);
157  eventWeight.Correction *= (1+ _rate_corr[0][0]);
158  }
159  }
160 
161  if (eventWeight.Systematic < 0) eventWeight.Systematic = 0;
162 
163  return eventWeight;
164 }
165 
Int_t _index
The index of this systematic (needed by SystematicsManager);.
AnaTrueVertexB * TrueVertex
Pointer to the AnaTrueVertexB of the interaction that created this AnaTrueParticleB.
Float_t PositionStart[4]
The reconstructed start position of the particle.
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)
Apply the systematic.
static bool IsFGDDetector(SubDetId::SubDetEnum det)
Check if a detector enumeration refers to a FGD or not.
Definition: SubDetId.cxx:126
static bool IsP0DDetector(SubDetId::SubDetEnum det)
Check if a detector enumeration refers to a SMRDP0D or not.
Definition: SubDetId.cxx:146
SubDetId_h DetectorFV
Indicate the FV we are interested in.
Definition: ToyBoxB.hxx:52
Int_t GParentPDG
The PDG code of this particle&#39;s grandparent, or 0 if there is no grandparent.
AnaTrackB * MainTrack
For storing the Main Track (The lepton candidate in geranal: HMN or HMP track)
void SetNParameters(int N)
Set the number of systematic parameters associated to this systematic.
AnaTrueObjectC * TrueObject
The link to the true oject that most likely generated this reconstructed object.
SubDetId::SubDetEnum GetDetector(const Float_t *pos)
Return the detector in which the position is.
static bool IsPECALDetector(SubDetId::SubDetEnum det)
Check if a detector enumeration refers to a P0D ECAL or not.
Definition: SubDetId.cxx:138
bool GetBinValues(Float_t value, Float_t &mean, Float_t &sigma)
Gets the bin values for a 1D source.
Float_t Position[4]
The position the true interaction happened at.
static bool IsTPCDetector(SubDetId::SubDetEnum det)
Check if a detector enumeration refers to a TPC or not.
Definition: SubDetId.cxx:122
static bool IsECALDetector(SubDetId::SubDetEnum det)
Check if a detector enumeration refers to a ECAL or not.
Definition: SubDetId.cxx:130
SubDetEnum
Enumeration of all detector systems and subdetectors.
Definition: SubDetId.hxx:25
Int_t ParentPDG
The PDG code of this particle&#39;s immediate parent, or 0 if there is no parent.
static bool IsTECALDetector(SubDetId::SubDetEnum det)
Check if a detector enumeration refers to a Tracker ECAL or not.
Definition: SubDetId.cxx:134
ToyVariations * GetToyVariations(UInt_t index) const
returns the variations for a given systematic (index)
bool InDetVolume(SubDetId::SubDetEnum det, const Float_t *pos)
Float_t Position[4]
The initial position of the true particle.
AnaTrueParticleB * GetTrueParticle() const
Return a casted version of the AnaTrueObject associated.
bool InFiducialVolume(SubDetId::SubDetEnum det, const Float_t *pos, const Float_t *FVdefmin, const Float_t *FVdefmax)
Float_t Direction[3]
The initial direction of the true particle.
Int_t GetNBins()
Get the number of bins.
static bool IsSMRDDetector(SubDetId::SubDetEnum det)
Check if a detector enumeration refers to a SMRD or not.
Definition: SubDetId.cxx:142