HighLAND
MomResolMCCorrection.cxx
1 #include <stdio.h>
2 #include "MomResolMCCorrection.hxx"
3 #include "HighlandAnalysisUtils.hxx"
4 #include "VersioningUtils.hxx"
5 #include "Parameters.hxx"
6 //#define DEBUG
7 
8 
9 //********************************************************************
10 MomResolMCCorrection::MomResolMCCorrection(){
11  //********************************************************************
12  _params = new BinnedParams(
13  std::string(getenv("PSYCHESYSTEMATICSROOT")) + "/data",
14  "MomentumResol",
15  BinnedParams::k1D_SYMMETRIC,
16  versionUtils::Extension()
17  );
18 
19  // This is to be consistent between the correction and systematic
20  _tpc_based_var = (bool)ND::params().GetParameterI("psycheSystematics.MomResol.UseTPCBased");
21 }
22 
23 //********************************************************************
25  //********************************************************************
26 #ifdef DEBUG
27  std::cout << " MomentumResolMCCorrection::Apply(): IsMC " << spill.GetIsMC() << std::endl;
28 #endif
29 
30  AnaSpill& spill = *static_cast<AnaSpill*>(&spillBB);
31 
32  // No correction for data
33  if (!spill.GetIsMC())
34  return;
35 
36  // Loop over all bunches
37  for (unsigned int i = 0; i < spill.Bunches.size(); i++) {
38  AnaBunch* bunch = static_cast<AnaBunch*>(spill.Bunches[i]);
39 
40  AnaTrackB* allTpcTracks[NMAXPARTICLES];
41 
42  // Get all the tracks in the TPC
43  int nTPC = anaUtils::GetAllTracksUsingDet(*bunch, SubDetId::kTPC, allTpcTracks);
44  for (Int_t j = 0; j < nTPC; j++){
45  if (_tpc_based_var)
46  ApplyVariationTPCBased(allTpcTracks[j], _exp);
47  else
48  ApplyVariation(allTpcTracks[j], _exp);
49  }
50  }
51 
52 
53 #ifdef DEBUG
54  std::cout << "MomentumResolMCCorrection::Apply() end " << std::endl;
55 #endif
56 
57 }
58 
59 
60 //********************************************************************
61 bool MomResolMCCorrection::GetVariation(AnaTrackB* track, Float_t& variation){
62  //********************************************************************
63  if (!track)
64  return false;
65 
66  if (!_params)
67  return false;
68 
69  variation = 0.;
70 
71  Float_t value1, value2;
72  Int_t index1, index2;
73 
74  if (versionUtils::prod6_systematics){
75 
76  // Complicated method for prod6
77  if (!GetXBinnedValues(track, value1, value2, index1, index2, MomentumResolVariation::kCorr)) return false;
78  }
79  else {
80  Float_t val1_tmp;
81  // P dependence for prod5
82  if (!_params->GetBinValues(track->Momentum, value1, val1_tmp)) return false;
83 
84  value2 = value1;
85  }
86 
87  variation = 0.5 * (value1 + value2);
88  return true;
89 }
90 
91 //********************************************************************
92 bool MomResolMCCorrection::GetVariationTPC(AnaTPCParticleB* track, Float_t& variation){
93  //********************************************************************
94  if (!track)
95  return false;
96 
97  if (!_params)
98  return false;
99 
100  variation = 0.;
101 
102  Float_t value1, value2;
103  Int_t index1, index2;
104 
105  if (versionUtils::prod6_systematics){
106 
107  // Complicated method for prod6
108  if (!GetXBinnedValues(track, value1, value2, index1, index2, MomentumResolVariation::kCorr)) return false;
109  }
110  else {
111  Float_t val1_tmp;
112  // P dependence for prod5
113  if (!_params->GetBinValues(track->Momentum, value1, val1_tmp)) return false;
114 
115  value2 = value1;
116  }
117 
118  variation = 0.5 * (value1 + value2);
119  return true;
120 }
121 
122 //********************************************************************
124  //********************************************************************
125 
126  if (!object) return false;
127 
128 
129  // Assuming the particles ToF reversing is already done can just run for the tracks that start in the FGDs
130  // ToDo
131  //
132  return true;
133 
134 }
ToyExperiment _exp
Some default toy experiment, not used at the moment.
virtual void ApplyVariation(AnaTrackB *track, const ToyExperiment &exp)
void Apply(AnaSpillC &spill)
Apply the momentum correction to all the relevant objects: AnaTrack and corresponding.
bool GetVariationTPC(AnaTPCParticleB *track, Float_t &variation)
Get the variation given a track.
std::vector< AnaBunchC * > Bunches
The reconstructed objects, split into timing bunches.
bool GetBinValues(Float_t value, Float_t &mean, Float_t &sigma)
Gets the bin values for a 1D source.
Float_t Momentum
The reconstructed momentum of the particle, at the start position.
virtual void ApplyVariationTPCBased(AnaTrackB *track, const ToyExperiment &exp)
bool GetIsMC() const
Return whether this spill is from Monte Carlo or not.
Representation of a global track.
bool GetVariation(AnaTrackB *track, Float_t &variation)
Get the variation given a track.
bool IsRelevantObject(const AnaRecObjectC *object)
Representation of a TPC segment of a global track.
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 GetAllTracksUsingDet(const AnaBunchB &bunch, SubDetId::SubDetEnum det, AnaTrackB *selTracks[])
BinnedParams * _params
Binned data to read the parameters.