HighLAND
TPCPIDPullMCCorrection.cxx
1 #include <stdio.h>
2 #include "TPCPIDPullMCCorrection.hxx"
3 #include "HighlandAnalysisUtils.hxx"
4 #include "VersioningUtils.hxx"
5 
6 //#define DEBUG
7 
8 
9 //********************************************************************
10 TPCPIDPullMCCorrection::TPCPIDPullMCCorrection(){
11  //********************************************************************
12 
13 
14  // Read the systematic source parameters from the data files: a special case of sharing the data file with systematics
15  _sigma[TPCPIDVariation::kMuon] =
16  new BinnedParams(std::string(getenv("PSYCHESYSTEMATICSROOT")) + "/data", "TPCPIDMuonSigRatio", BinnedParams::k2D_SYMMETRIC, versionUtils::Extension());
17  _sigma[TPCPIDVariation::kElectron] =
18  new BinnedParams(std::string(getenv("PSYCHESYSTEMATICSROOT")) + "/data", "TPCPIDEleSigRatio", BinnedParams::k2D_SYMMETRIC, versionUtils::Extension());
19  _sigma[TPCPIDVariation::kProton] =
20  new BinnedParams(std::string(getenv("PSYCHESYSTEMATICSROOT")) + "/data", "TPCPIDProtonSigRatio", BinnedParams::k2D_SYMMETRIC, versionUtils::Extension());
21  _mean[TPCPIDVariation::kMuon] =
22  new BinnedParams(std::string(getenv("PSYCHESYSTEMATICSROOT")) + "/data", "TPCPIDMuonMeanDiff", BinnedParams::k2D_SYMMETRIC, versionUtils::Extension());
23  _mean[TPCPIDVariation::kElectron] =
24  new BinnedParams(std::string(getenv("PSYCHESYSTEMATICSROOT")) + "/data", "TPCPIDEleMeanDiff", BinnedParams::k2D_SYMMETRIC, versionUtils::Extension());
25  _mean[TPCPIDVariation::kProton] =
26  new BinnedParams(std::string(getenv("PSYCHESYSTEMATICSROOT")) + "/data", "TPCPIDProtonMeanDiff", BinnedParams::k2D_SYMMETRIC, versionUtils::Extension());
27 }
28 
29 //********************************************************************
31  //********************************************************************
32 
33  AnaSpill& spill = *static_cast<AnaSpill*>(&spillBB);
34 
35 #ifdef DEBUG
36  std::cout << " TPCPIDPullMCCorrection::Apply(): IsMC " << spill.GetIsMC() << std::endl;
37 #endif
38 
39 
40  // No correction for data
41  if (!spill.GetIsMC())
42  return;
43 
44  // Loop over all bunches
45  for (unsigned int i = 0; i < spill.Bunches.size(); i++) {
46 
47  AnaBunch* bunch = static_cast<AnaBunch*>(spill.Bunches[i]);
48  AnaTrackB* allTpcTracks[NMAXPARTICLES];
49 
50  // Get all the tracks in the TPC
51  int nTPC = anaUtils::GetAllTracksUsingDet(*bunch, SubDetId::kTPC, allTpcTracks);
52  for (Int_t j = 0; j < nTPC; j++)
53  ApplyVariation(allTpcTracks[j], _exp);
54  }
55 
56 
57 #ifdef DEBUG
58  std::cout << "TPCPIDPullMCCorrection::Apply() end " << std::endl;
59 #endif
60 
61 }
62 
63 
64 //********************************************************************
66  Float_t& mean_var, Float_t& sigma_var,
67  const AnaTrackB& track){
68  //********************************************************************
69 
70  // Get the TPC
71  int tpc = SubDetId::GetTPC(tpcTrack.Detector);
72 
73  // Need true particle
74  if (!track.GetTrueParticle()) return false;
75 
76  // Get the expected dEdx and error on the dEdx depending on the true particle of the
77  // (global) track
78 
79  Int_t PDG = abs(track.GetTrueParticle()->PDG);
80 
82 
83  switch (PDG){
84  case 13: // Muon
85  case 211:
86  part = TPCPIDVariation::kMuon;
87  break;
88  case 11: // Electron
89  part = TPCPIDVariation::kElectron;
90  break;
91  case 2212: // Proton
92  part = TPCPIDVariation::kProton;
93  break;
94  default:
95  return false;
96  break;
97  }
98 
99  if (!_mean[part] || !_sigma[part]) return false;
100 
101  // Need the correction part from the systematics
102  Float_t mean_err, sigma_err;
103 
104  // Note that the momentum changes if the mom resoltion, scale and bfield are also anabled.
105  if (!_mean[part]->GetBinValues(track.Momentum, (Float_t) tpc, mean_var, mean_err)) return false;
106  if (!_sigma[part]->GetBinValues(track.Momentum,(Float_t) tpc, sigma_var, sigma_err)) return false;
107 
108  return true;
109 }
110 
111 
unsigned long Detector
virtual void ApplyVariation(AnaTrackB *track, const ToyExperiment &exp)
Apply variation for a track, the most general case given a certain ToyExperiment. ...
std::vector< AnaBunchC * > Bunches
The reconstructed objects, split into timing bunches.
void Apply(AnaSpillC &spill)
Apply the correction to all the relevant objects: TPC constituent of an AnaTrack. ...
BinnedParams * _mean[kNPULLS]
bool GetVariation(const AnaTPCParticleB &tpcTrack, Float_t &mean_var, Float_t &sigma_var, const AnaTrackB &track)
Get the variation for a given TPC object.
HypEnum
Enum for particle hypothesis.
Float_t Momentum
The reconstructed momentum of the particle, at the start position.
Int_t PDG
The PDG code of this particle.
bool GetIsMC() const
Return whether this spill is from Monte Carlo or not.
Representation of a global track.
Representation of a TPC segment of a global track.
ToyExperiment _exp
Some default toy experiment, not used at the moment.
static int GetTPC(unsigned long BitField)
Definition: SubDetId.cxx:74
int GetAllTracksUsingDet(const AnaBunchB &bunch, SubDetId::SubDetEnum det, AnaTrackB *selTracks[])
AnaTrueParticleB * GetTrueParticle() const
Return a casted version of the AnaTrueObject associated.