HighLAND
p0dCCQEOOFVSystematics.cxx
1 #include "p0dCCQEOOFVSystematics.hxx"
2 #include "ND280AnalysisUtils.hxx"
3 #include "BasicUtils.hxx"
4 #include "SubDetId.hxx"
5 #include "FiducialVolumeDefinition.hxx"
6 #include "VersioningUtils.hxx"
7 #include "ToyBoxTracker.hxx"
8 
9 
10 const double p0d_fv_minz = -2969;
11 const double p0d_fv_maxz = -1264;
12 
13 //********************************************************************
14 p0dCCQEOOFVSystematics::p0dCCQEOOFVSystematics():EventWeightBase(1){
15 //********************************************************************
16 
17  _name = "P0DCCQEOOFV";
18 
19  char dirname[256];
20  sprintf(dirname,"%s/data",getenv("P0DNUMUCCQEANALYSISROOT"));
21 
22  _p0d = new BinnedParams();
23  _p0d->SetType(BinnedParams::k1D_SYMMETRIC);
24  _p0d->SetName("P0DCCQEOOFV_reco");
25  _p0d->Read(dirname);
26 
27  _rate = new BinnedParams();
28  _rate->SetType(BinnedParams::k2D_SYMMETRIC);
29  _rate->SetName("P0DCCQEOOFV_rate");
30  _rate->Read(dirname);
31  int npars = 0;
32  npars = _p0d->GetNBins();
33  npars += _rate->GetNBins();
34  SetNParameters(npars);
35  for (int i=0;i<9;i++){
36  if (!_p0d->GetBinValues(i, _reco_corr[i], _reco_error[i],_reco_index[i])) _reco_index[i]=-1;
37 
38  if (_reco_index[i]>=0) _reco_index[i] += _rate->GetNBins();
39  }
40 
41 
42 }
43 
44 //********************************************************************
45 Int_t p0dCCQEOOFVSystematics::GetBeamNumber(Int_t runperiod,AnaTrackB *maintrack){
46 //********************************************************************
47  if(runperiod==8){
48  if(maintrack->Charge<0)
49  return 1;
50  else
51  return 2;
52  }else
53  return 0;
54 }
55 
56 //********************************************************************
57 Int_t p0dCCQEOOFVSystematics::GetDetNumber(SubDetId::SubDetEnum det){
58 //********************************************************************
59 
61  return 0;
62  else if(SubDetId::IsFGDDetector(det))
63  return 1;
64  else if(SubDetId::IsECALDetector(det))
65  return 2;
66  else if(SubDetId::IsTECALDetector(det))
67  return 2;
68  else if(SubDetId::IsPECALDetector(det))
69  return 2;
70  else if(SubDetId::IsSMRDDetector(det))
71  return 3;
72  else if(SubDetId::IsTPCDetector(det))
73  return 4;
74 
75  else
76  return 5;
77 }
78 
79 //********************************************************************
81 //********************************************************************
82 
83  const AnaEventB& event = *static_cast<const AnaEventB*>(&eventC);
84 
85  // Cast the ToyBox to the appropriate type
86  const ToyBoxTracker& box = *static_cast<const ToyBoxTracker*>(&boxB);
87 
88  Weight_h eventWeight=1;
89  if (!box.MainTrack) return eventWeight; // HMN track should exist
90  if (!box.MainTrack->GetTrueParticle()) return eventWeight; // True track associated to HMN track should exist
91  if (!box.MainTrack->GetTrueParticle()->TrueVertex) return eventWeight; // True vertex associated to HMN track should exist
92 
93  // Get the true vertex position
94  Float_t* tvertex = box.MainTrack->GetTrueParticle()->TrueVertex->Position;
95 
96  // if the true vertex is inside the P0D FV this is not OOFV (RETURN EVENTWEIGHT=1)
97  if(anaUtils::InFiducialVolume(static_cast<SubDetId::SubDetEnum>(box.DetectorFV), tvertex)) return eventWeight;
98 
99  // Get the true track direction and position
100  //Float_t* tdir = box.MainTrack->GetTrueParticle()->Direction;
101  //Float_t* pos = box.MainTrack->GetTrueParticle()->Position;
102 
103  Float_t* p0d_det_min = DetDef::p0dmin;
104  Float_t* p0d_det_max = DetDef::p0dmax;
105 
106 
107  double Zmin_p0d_fv,Zmax_p0d_fv;
108  p0d_det_min = DetDef::p0dmin;
109  p0d_det_max = DetDef::p0dmax;
110  Zmin_p0d_fv = p0d_fv_minz;
111  Zmax_p0d_fv = p0d_fv_maxz;
112 
113  const SubDetId::SubDetEnum detector = static_cast<const SubDetId::SubDetEnum>(anaUtils::GetDetector(tvertex));
114 
115  Int_t categ =-1;
116  //In P0D CEcal.
117  if (SubDetId::IsP0DDetector(detector) && tvertex[2] > Zmax_p0d_fv)
118  categ = 0;
119  //In P0D US ECal
120  else if (SubDetId::IsP0DDetector(detector) && tvertex[2] < Zmin_p0d_fv)
121  categ = 1;
122  //In P0D WT
123  else if (SubDetId::IsP0DDetector(detector))
124  categ = 2;
125  else if (SubDetId::IsFGDDetector(detector))
126  categ = 3;
127  else if (SubDetId::IsECALDetector(detector))
128  categ = 4;
129  else if (SubDetId::IsPECALDetector(detector))
130  categ = 4;
131  else if (SubDetId::IsTECALDetector(detector))
132  categ = 4;
133  else if (SubDetId::IsSMRDDetector(detector))
134  categ = 5;
135  else if (SubDetId::IsTPCDetector(detector))
136  categ = 6;
137 
138  if(categ>=0 ){
140  Int_t runPeriod = anaUtils::GetRunPeriod(event.EventInfo.Run);
141 
142  if (!_rate->GetBinValues(GetBeamNumber(runPeriod,box.MainTrack), GetDetNumber(detector), _rate_corr, _rate_error,_rate_index)) _rate_index=-1;
143 
144  if (_reco_index[categ]>=0){
145  eventWeight.Systematic *= (1+ _reco_corr[categ] + _reco_error[categ]*toy.GetToyVariations(_index)->Variations[_reco_index[categ]]);
146  eventWeight.Correction *= (1+ _reco_corr[categ]);
147  }
148  if (_rate_index>=0){
149  eventWeight.Systematic *= (1+ _rate_corr + _rate_error*toy.GetToyVariations(_index)->Variations[_rate_index]);
150  eventWeight.Correction *= (1+ _rate_corr);
151  }
152 
153  }
154 
155 
156  if (eventWeight.Systematic < 0) eventWeight.Systematic = 0;
157 
158  return eventWeight;
159 }
160 
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 * Variations
the vector of Variations, one for each of the systematic parameters
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
void SetType(TypeEnum type)
Set the type.
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.
void SetName(const std::string &name)
Set the name.
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
Float_t Charge
The reconstructed charge of the particle.
Float_t _rate_corr
Mean of the rate correction.
bool GetBinValues(Float_t value, Float_t &mean, Float_t &sigma)
Gets the bin values for a 1D source.
Float_t _reco_corr[9]
Mean of the reco eff correction.
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
int GetRunPeriod(int run, int subrun=-1)
Returns the run period (sequentially: 0,1,2,3,4,5 ...)
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
void Read(const std::string &inputDirName, const std::string &extension="")
Read from a file the systematic source values.
Representation of a global track.
Weight_h ComputeWeight(const ToyExperiment &toy, const AnaEventC &event, const ToyBoxB &box)
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)
Float_t _rate_error
Uncertainty on the rate correction.
Float_t _reco_error[9]
Uncertainty on the reco eff correction.
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)
std::string _name
The name of this systematic.
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