HighLAND
MomentumResolSystematics.cxx
1 #include "MomentumResolSystematics.hxx"
2 #include "ND280AnalysisUtils.hxx"
3 #include "EventBoxTracker.hxx"
4 #include "VersioningUtils.hxx"
5 #include "Parameters.hxx"
6 
7 //const bool debug = true;
8 //#define DEBUG true
9 
10 
11 /*
12 \\! [MomentumResolSystematics_info]
13 \htmlonly
14 This systematic is treated in detail in T2K-TN-222 \cite{TN-222}. The study has been performed using tracks that cross multiple TPCs,
15 whose redundancy allows building a fully reconstructed observable (no truth info needed) sensitive to the intrinsic TPC resolution.
16 The ultimate goal of this analysis is to compare the TPC and global momentum resolutions of data and MC, and in the case they differ, to find
17 the smearing factor that makes them similar. This smearing factor would be the systematic parameter to be propagated in any event selection.
18 
19 The use of tracks crossing at least two TPCs allows to compute the difference between the momentum reconstructed using the two TPC segments of the same global track.
20 Using the inverse of the transverse momentum to the magnetic field, \(1/p_t\), the distribution of its difference corrected by energy loss in the intermediate FGD \(\Delta 1/p_t\)
21 is approximately Gaussian and centered at zero, with a standard deviation having as main contribuitor the intrinsic resolution of the TPCs involved.
22 The resulting \(\Delta(1/p_t)\) distribution can be fitted to a Gaussian function in order to obtain the standard deviation, \(\sigma_{\Delta 1/p_t}\),
23 for different kinematic ranges (\(p_t\), angle, position, etc). \(\sigma_{\Delta 1/p_t}\) contains multiple contributions,
24 among which the one related to the momentum resolution should be extracted.
25 
26 
27 \endhtmlonly
28 \\! [MomentumResolSystematics_info]
29 */
30 
31 
32 //********************************************************************
34  //********************************************************************
35 
36  _params = new BinnedParams("MomentumResol",
37  BinnedParams::k1D_SYMMETRIC,
38  versionUtils::Extension());
39 
40  // Whether to use local TPC based smearing
41  _tpc_based_var = (bool)ND::params().GetParameterI("psycheSystematics.MomResol.UseTPCBased");
42  _useP0DFV = (bool) ND::params().GetParameterI("psycheSystematics.Tracker.UseP0DFV");
43 
45 
46  // Wether assume full correlation between syst bins
47  _full_correlations = ND::params().GetParameterI("psycheSystematics.Tracker.FullCorrelations");
48 }
49 
50 //********************************************************************
52  //********************************************************************
53 
54  // Get the SystBox for this event
55  SystBoxB* box = GetSystBox(event);
56 
57 #ifdef DEBUG
58  std::cout << "MomentumResolSystematics::ApplyVariation(): " << box->nRelevantRecObjects << std::endl;
59 #endif
60 
61  // Loop over relevant tracks for this systematic
62  for (Int_t itrk=0;itrk<box->nRelevantRecObjects;itrk++){
63 #ifdef DEBUG
64  std::cout << itrk << std::endl;
65 #endif
66  AnaTrackB* track = static_cast<AnaTrackB*>(box->RelevantRecObjects[itrk]);
67 
68  if (_tpc_based_var || _useP0DFV)
69  ApplyVariationTPCBased(track, toy);
70  else
71  ApplyVariation(track, toy);
72  }
73 }
74 
75 //********************************************************************
77  //********************************************************************
78 
79  // Get the SystBox for this event
80  SystBoxB* box = GetSystBox(event);
81 
82  for (Int_t itrk=0;itrk<box->nRelevantRecObjects;itrk++){
83  AnaTrackB* track = static_cast<AnaTrackB*>(box->RelevantRecObjects[itrk]);
84 
85  if (!track) continue;
86 
87  // Go back to the corrected momentum
88  if (!track->GetOriginalTrack()) continue;
89 
90  track->Momentum = track->GetOriginalTrack()->Momentum;
91 
92  track->MomentumFlip = track->GetOriginalTrack()->MomentumFlip;
93 
94  for (int iseg = 0; iseg < track->nTPCSegments; iseg++){
95  AnaTPCParticleB* tpcTrackorig = track->GetOriginalTrack()->TPCSegments[iseg];
96  AnaTPCParticleB* tpcTrack = track->TPCSegments[iseg];
97 
98  if (!tpcTrack || !tpcTrackorig) continue;
99 
100  tpcTrack->MomentumError = tpcTrackorig->MomentumError;
101  tpcTrack->Momentum = tpcTrackorig->Momentum;
102  }
103 
104  // Go back to the corrected charge
105  // static_cast<AnaTrackB*>(tracks[itrk])->Charge = track->GetOriginalTrack()->Charge;
106  }
107  // Don't reset the spill to corrected
108  return false;
109 }
110 
111 //********************************************************************
112 bool MomentumResolSystematics::GetVariation(AnaTrackB* track, Float_t& variation, const ToyExperiment& exp){
113  //********************************************************************
114  if (!track)
115  return false;
116 
117  if (!_params)
118  return false;
119 
120  variation = 0.;
121 
122  Float_t value1, value2;
123  Int_t index1, index2;
124 
125  if (versionUtils::prod6_systematics){
126 
127  // Complicated method for prod6
128  if (!GetXBinnedValues(track, value1, value2, index1, index2, MomentumResolVariation::kSyst)) return false;
129  }
130  else {
131  Float_t val1_tmp;
132  // P dependence for prod5
133  if (!_params->GetBinValues(track->Momentum, val1_tmp, value1, index1)) return false;
134 
135  value2 = value1;
136  index2 = index1;
137  }
138 
139  // Full correlation if requested
140  if (_full_correlations)
141  index1 = index2 = 0;
142 
143  variation = 0.5 * (value1 * exp.GetToyVariations(_index)->Variations[index1] +
144  value2 * exp.GetToyVariations(_index)->Variations[index2]);
145 
146  return true;
147 }
148 
149 //********************************************************************
150 bool MomentumResolSystematics::GetVariationTPC(AnaTPCParticleB* track, Float_t& variation, const ToyExperiment& exp){
151  //********************************************************************
152 
153  if (!track)
154  return false;
155 
156  if (!_params)
157  return false;
158 
159  variation = 0.;
160 
161  Float_t value1, value2;
162  Int_t index1, index2;
163 
164  if (versionUtils::prod6_systematics){
165 
166  // Complicated method for prod6
167  if (!GetXBinnedValues(track, value1, value2, index1, index2, MomentumResolVariation::kSyst)) return false;
168  }
169  else {
170  Float_t val1_tmp;
171  // P dependence for prod5
172  if (!_params->GetBinValues(track->Momentum, val1_tmp, value1, index1)) return false;
173 
174  value2 = value1;
175  index2 = index1;
176  }
177 
178  // Full correlation if requested
179  if (_full_correlations)
180  index1 = index2 = 0;
181 
182  variation = 0.5 * (value1 * exp.GetToyVariations(_index)->Variations[index1] +
183  value2 * exp.GetToyVariations(_index)->Variations[index2]);
184 
185  return true;
186 
187 
188 }
189 
190 
191 //********************************************************************
193  //********************************************************************
194 
195  Int_t ngroups=0;
196  for (UInt_t b=0; b<sel.GetNBranches(); b++){
197  SubDetId_h det = sel.GetDetectorFV(b);
198  if (det == SubDetId::kFGD1 || det == SubDetId::kFGD){
199  IDs[ngroups++] = EventBoxTracker::kTracksWithTPCInFGD1FV;
200  }
201  if (det == SubDetId::kFGD2 || det == SubDetId::kFGD){
202  IDs[ngroups++] = EventBoxTracker::kTracksWithTPCInFGD2FV;
203  }
204  if (det == SubDetId::kP0D){
205  IDs[ngroups++] = EventBoxTracker::kTracksWithTPCInP0DFV;
206  }
207  }
208 
209  return ngroups;
210 }
Int_t _index
The index of this systematic (needed by SystematicsManager);.
virtual void ApplyVariation(AnaTrackB *track, const ToyExperiment &exp)
const AnaTrackB * GetOriginalTrack() const
Return a casted version of the original AnaParticleB associated.
virtual bool UndoSystematic(AnaEventC &event)
Undo the systematic variations done by ApplyVariation. This is faster tha reseting the full Spill...
Float_t * Variations
the vector of Variations, one for each of the systematic parameters
int GetParameterI(std::string)
Get parameter. Value is returned as integer.
Definition: Parameters.cxx:217
SystBoxB * GetSystBox(const AnaEventC &event, Int_t isel=0, Int_t ibranch=0) const
Get the SystBox corresponding to a selection, branch and event.
AnaTPCParticleB * TPCSegments[NMAXTPCS]
The TPC segments that contributed to this global track.
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.
Float_t MomentumError
Error of the momentum at the start of the segment.
Float_t MomentumFlip
Momentum for the main PID hypothesis and reverse sense.
bool _tpc_based_var
Whether to do the smearing based on the local TPC mom.
Float_t Momentum
The reconstructed momentum of the particle, at the start position.
int nTPCSegments
How many TPC tracks are associated with this track.
virtual void ApplyVariationTPCBased(AnaTrackB *track, const ToyExperiment &exp)
virtual void Apply(const ToyExperiment &toy, AnaEventC &event)
Apply the systematic.
bool _full_correlations
Value of psycheSystematics.Tracker.FullCorrelations parameter.
bool GetVariationTPC(AnaTPCParticleB *track, Float_t &variation, const ToyExperiment &exp)
Get the variation given a track.
Representation of a global track.
Representation of a TPC segment of a global track.
ToyVariations * GetToyVariations(UInt_t index) const
returns the variations for a given systematic (index)
Int_t GetRelevantRecObjectGroups(const SelectionBase &sel, Int_t *IDs) const
Get the TrackGroup IDs array for this systematic.
UInt_t GetNBranches() const
Return the number of branches.
bool GetXBinnedValues(AnaTrackB *track, Float_t &value1, Float_t &value2, Int_t &index1, Int_t &index2, ModeEnum mode)
Get parameters for this global track assumed one uses X bins.
Int_t nRelevantRecObjects
----—— Relevant rec objects and true objects for each systematic ------------—— ...
Definition: SystBoxB.hxx:20
bool GetVariation(AnaTrackB *track, Float_t &variation, const ToyExperiment &exp)
Get the variation given a track.
Int_t GetNBins()
Get the number of bins.
SubDetId_h GetDetectorFV(Int_t ibranch=0) const
Get the detector in which the Fiducial Volume is defined.
BinnedParams * _params
Binned data to read the parameters.