HighLAND
FGDPIDSystematics.cxx
1 #include "FGDPIDSystematics.hxx"
2 #include "ND280AnalysisUtils.hxx"
3 #include "EventBoxTracker.hxx"
4 #include "VersioningUtils.hxx"
5 
6 //#define DEBUG
7 
8 //********************************************************************
10 //********************************************************************
11 
12 
13  // Read the systematic source parameters from the data files
14  Int_t npar=0;
15  _fgd1mean = new BinnedParams("FGD1PIDMean", BinnedParams::k1D_EFF_SYMMETRIC, versionUtils::Extension());
16  _fgd1sigma = new BinnedParams("FGD1PIDSigRatio",BinnedParams::k1D_SYMMETRIC, versionUtils::Extension());
17  npar=_fgd1mean->GetNBins()+_fgd1sigma->GetNBins();
18  if( versionUtils::prod6_systematics){
19  _fgd2mean = new BinnedParams("FGD2PIDMean", BinnedParams::k1D_EFF_SYMMETRIC, versionUtils::Extension());
20  _fgd2sigma = new BinnedParams("FGD2PIDSigRatio",BinnedParams::k1D_SYMMETRIC, versionUtils::Extension());
21  npar+=_fgd2mean->GetNBins()+_fgd2sigma->GetNBins();
22  }
23 
24  //set the total number of parameters
25  SetNParameters(npar);
26 }
27 //********************************************************************
29 //********************************************************************
30 
31  // Get the SystBox for this event
32  SystBoxB* box = GetSystBox(event);
33 
34 #ifdef DEBUG
35  std::cout << "FGDPIDSystematics::Apply(): tracks size " << box->nRelevantRecObjects << std::endl;
36 #endif
37 
38  // Loop over relevant tracks for this systematic
39  for (Int_t itrk=0;itrk<box->nRelevantRecObjects;itrk++){
40  AnaTrackB* track = static_cast<AnaTrackB*>(box->RelevantRecObjects[itrk]);
41  if(!track->TrueObject) continue;
42  Int_t pdg;
43  if (abs(track->GetTrueParticle()->PDG) == 211 || abs(track->GetTrueParticle()->PDG) == 13)
44  pdg = 13;
45  else if (abs(track->GetTrueParticle()->PDG) == 2212)
46  pdg = 2212;
47  else
48  continue;
49 
50 
51  // Loop over FGD segments
52  for (int k = 0; k < track->nFGDSegments; k++) {
53  // The segment to be modified
54  AnaFGDParticleB* fgdTrack = track->FGDSegments[k];
55  if(!fgdTrack) continue;
56  // The original (corrected) FGD track
57  const AnaFGDParticleB* original = static_cast<const AnaFGDParticleB*>(fgdTrack->Original);
58  // The original should exist
59  if (!original) continue;
60 
61 #ifdef DEBUG
62  std::cout << pdg<<" FGDPIDSystematics::Apply(): nodes = " << fgdTrack->NNodes << std::endl;
63 #endif
64  // Get the systematic source values
65  Float_t sigR_value;
66  Float_t sigR_error;
67  Int_t mean_index;
68  Int_t sigR_index;
69  BinnedParamsParams params;
70 
71  bool inFGD1 = SubDetId::GetDetectorUsed(track->Detector, SubDetId::kFGD1);
72  bool inFGD2 = SubDetId::GetDetectorUsed(track->Detector, SubDetId::kFGD2);
73 
74  if(inFGD1){
75  if(!_fgd1mean->GetBinValues((Float_t)pdg,params, mean_index)) continue;
76  if(!_fgd1sigma->GetBinValues((Float_t)pdg,sigR_value, sigR_error, sigR_index)) continue;
77  sigR_index+=_fgd1mean->GetNBins();
78  }
79  if(inFGD2){
80  if( versionUtils::prod6_systematics){
81  if(!_fgd2mean->GetBinValues((Float_t)pdg,params, mean_index)) continue;
82  if(!_fgd2sigma->GetBinValues((Float_t)pdg,sigR_value, sigR_error, sigR_index)) continue;
83  sigR_index+=_fgd2mean->GetNBins();
84  }
85  }
86 
87 #ifdef DEBUG
88  std::cout << "FGDPIDSystematics::Apply(): meanmc, menadata, mean_index = " << params.meanMC << " " << params.meanDATA << " " << mean_index << std::endl;
89  std::cout << "FGDPIDSystematics::Apply(): sigR_value, sigR_error, sigR_index = " << sigR_value << " " << sigR_error << " " << sigR_index <<std::endl;
90 #endif
91  // Apply the variation
92 
93  // value = pull_mean
94  // Summing value to pullpi0 is effectively a correction, to center the pull at 0
95  // Summing error+x is the propagation of the systematic
96  Float_t diffdataMC=params.meanDATA-params.meanMC;
97  Float_t error=fabs(diffdataMC);
98 
99  if (pdg==13){
100  // systematic on pull mean
101  fgdTrack->Pullpi = fgdTrack->Pullpi+ diffdataMC + error * toy.GetToyVariations(_index)->Variations[mean_index];
102  fgdTrack->Pullmu = fgdTrack->Pullmu + diffdataMC + error * toy.GetToyVariations(_index)->Variations[mean_index];
103 
104  // systematic on pull sigma ratio
105  fgdTrack->Pullpi = params.meanMC + (fgdTrack->Pullpi-params.meanMC)*(sigR_value +
106  sigR_error * toy.GetToyVariations(_index)->Variations[sigR_index]);
107  fgdTrack->Pullmu = params.meanMC + (fgdTrack->Pullmu-params.meanMC)*(sigR_value +
108  sigR_error * toy.GetToyVariations(_index)->Variations[sigR_index]);
109  }
110  else if (pdg==2212){
111  // systematic on pull mean
112  fgdTrack->Pullp = fgdTrack->Pullp + diffdataMC + error * toy.GetToyVariations(_index)->Variations[mean_index];
113  // systematic on pull sigma ratio
114  fgdTrack->Pullp = params.meanMC + (fgdTrack->Pullp - params.meanMC)*(sigR_value + sigR_error *
115  toy.GetToyVariations(_index)->Variations[sigR_index]);
116  }
117 
118 #ifdef DEBUG
119 
120  // Get the original pulls
121  Float_t pullpi0 = original->Pullpi;
122  Float_t pullmu0 = original->Pullmu;
123  Float_t pullp0 = original->Pullp;
124  std::cout << "FGDPIDSystematics::Apply(): Results: " << std::endl;
125  std::cout << " " << track->GetTrueParticle()->PDG << " " << fgdTrack
126  << ", " << pullpi0 << " --> " << fgdTrack->Pullpi
127  << ", " << pullmu0 << " --> " << fgdTrack->Pullmu
128  << ", " << pullp0 << " --> " << fgdTrack->Pullp << std::endl;
129 #endif
130  }
131  }
132 }
133 
134 //********************************************************************
136 //********************************************************************
137 
138  // Get the SystBox for this event
139  SystBoxB* box = GetSystBox(event);
140 
141  for (int itrk=0;itrk<box->nRelevantRecObjects;itrk++){
142  for (int k = 0; k < static_cast<AnaTrackB*>(box->RelevantRecObjects[itrk])->nFGDSegments; k++) {
143  // The new FGD track
144  AnaFGDParticleB* fgdTrack = static_cast<AnaTrackB*>(box->RelevantRecObjects[itrk])->FGDSegments[k];
145  // The original (corrected) fgd track
146  const AnaFGDParticleB* original = static_cast<const AnaFGDParticleB*>(fgdTrack->Original);
147 
148  // revert to initial pulls
149  fgdTrack->Pullpi = original->Pullpi;
150  fgdTrack->Pullmu = original->Pullmu;
151  fgdTrack->Pullp = original->Pullp;
152  }
153  }
154 
155  // Don't reset the spill to corrected
156  return false;
157 }
158 
159 
160 //**************************************************
161 bool FGDPIDSystematics::IsRelevantRecObject(const AnaEventC& event, const AnaRecObjectC& recObj) const{
162 //**************************************************
163 
164  (void)event;
165 
166  // True track should always exist
167  if (!recObj.TrueObject) return false;
168 
169  const AnaTrueParticleB* truePart = static_cast<const AnaTrueParticleB*>(recObj.TrueObject);
170 
171  bool ok = false;
172  // only consider true protons, pions, muons and electrons
173  if (abs(truePart->PDG) == 211 ) ok = true;
174  else if (abs(truePart->PDG) == 2212) ok = true;
175  else if (abs(truePart->PDG) == 13) ok = true;
176 
177  return ok;
178 }
179 
180 //********************************************************************
182 //********************************************************************
183 
184  Int_t ngroups=0;
185  for (UInt_t b=0; b<sel.GetNBranches(); b++){
186  SubDetId_h det = sel.GetDetectorFV(b);
187  if (det == SubDetId::kFGD1 || det == SubDetId::kFGD){
188  IDs[ngroups++] = EventBoxTracker::kTracksWithFGD1AndNoTPC;
189  }
190  if (det == SubDetId::kFGD2 || det == SubDetId::kFGD){
191  IDs[ngroups++] = EventBoxTracker::kTracksWithFGD2AndNoTPC;
192  }
193  }
194 
195  return ngroups;
196 }
Int_t _index
The index of this systematic (needed by SystematicsManager);.
unsigned long Detector
Float_t * Variations
the vector of Variations, one for each of the systematic parameters
Float_t Pullp
Proton pull, according to FGD information.
Int_t NNodes
The number of nodes in the reconstructed object.
SystBoxB * GetSystBox(const AnaEventC &event, Int_t isel=0, Int_t ibranch=0) const
Get the SystBox corresponding to a selection, branch and event.
Float_t Pullpi
Pion pull, according to FGD information.
bool UndoSystematic(AnaEventC &event)
Undo the systematic variations done by ApplyVariation. This is faster tha reseting the full Spill...
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.
static bool GetDetectorUsed(unsigned long BitField, SubDetId::SubDetEnum det)
Method to see if a certain subdetector or subdetector system is used.
Definition: SubDetId.cxx:40
Float_t Pullmu
Muon pull, according to FGD information.
bool GetBinValues(Float_t value, Float_t &mean, Float_t &sigma)
Gets the bin values for a 1D source.
Float_t meanDATA
The mean value for each of the systematic parameters of the control sample.
Int_t GetRelevantRecObjectGroups(const SelectionBase &sel, Int_t *IDs) const
Get the TrackGroup IDs array for this systematic.
bool IsRelevantRecObject(const AnaEventC &event, const AnaRecObjectC &track) const
Is this track relevant for this systematic ?
Representation of a true Monte Carlo trajectory/particle.
const AnaParticleB * Original
Int_t PDG
The PDG code of this particle.
Float_t meanMC
The mean value for each of the systematic parameters of the control sample.
Representation of a global track.
ToyVariations * GetToyVariations(UInt_t index) const
returns the variations for a given systematic (index)
Representation of a FGD segment of a global track.
UInt_t GetNBranches() const
Return the number of branches.
int nFGDSegments
How many FGD tracks are associated with this track.
Int_t nRelevantRecObjects
----—— Relevant rec objects and true objects for each systematic ------------—— ...
Definition: SystBoxB.hxx:20
AnaTrueParticleB * GetTrueParticle() const
Return a casted version of the AnaTrueObject associated.
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.
AnaFGDParticleB * FGDSegments[NMAXFGDS]
The FGD segments that contributed to this global track.
void Apply(const ToyExperiment &toy, AnaEventC &event)
Apply the systematic.