HighLAND
BFieldDistortionSystematics.cxx
1 #include "BFieldDistortionSystematics.hxx"
2 #include "ND280AnalysisUtils.hxx"
3 #include "EventBoxTracker.hxx"
4 #include "VersioningUtils.hxx"
5 #include <math.h>
6 
7 //#define DEBUG
8 
9 //********************************************************************
11 //********************************************************************
12 
13  // Get the systematic source values
15 
16  // This systematic uses a Uniform random throw
17  _PDF = kUniform;
18 }
19 
20 //********************************************************************
22 //********************************************************************
23 
24  // Get the SystBox for this event
25  SystBoxB* box = GetSystBox(event);
26 
27 #ifdef DEBUG
28  std::cout << "BFieldDistortionSystematics::Apply(): " << box->nRelevantRecObjects << std::endl;
29 #endif
30 
31  // Loop over the relevant tracks for this systematic
32  for (Int_t itrk=0;itrk<box->nRelevantRecObjects;itrk++){
33 #ifdef DEBUG
34  std::cout << "itrk = " << itrk << std::endl;
35 #endif
36  AnaTrackB* track = static_cast<AnaTrackB*>(box->RelevantRecObjects[itrk]);
37 
38  Float_t delta = 0;
39  Float_t ntpcs = 0;
40  // There is no more than 2 TPC segments
41  // but we use the first one to correct.
42  // The TPC segment
43  // AnaTPCParticleB* tpcTrack = track->TPCSegments[0];
44 
45  // Use the TPC segment with more nodes in closest TPC to the start position of the track
47  if (!tpcTrack) continue;
48  Float_t gmom=track->Momentum;
49  Float_t mom = tpcTrack->Momentum;
50  Float_t refmom;
51 #ifdef DEBUG
52  std::cout<<" mom "<<mom<<std::endl;
53 #endif
54  //the sign represents the charge in the prod6 files!
55  if (versionUtils::prod6_systematics){
56  refmom = fabs(tpcTrack->RefitMomentum);
57  if (refmom == 99999 || !TMath::Finite(refmom)) continue;
58  }else{
59  refmom = tpcTrack->RefitMomentum;
60  if (refmom < 0 || !TMath::Finite(refmom)) continue;
61  }
62  // Make sure we have a valid momentum
63  if (mom < 0 || !TMath::Finite(mom)) continue;
64  // the tpc mom should always be smaller
65  // than the global momentum (gmom=tpcmom+fgdmom)
66  if (mom > gmom || refmom > gmom) continue;
67 
68  delta += (refmom-mom)*_mean_error*toy.GetToyVariations(_index)->Variations[0];
69  ntpcs += 1.0;
70 
71 #ifdef DEBUG
72  std::cout <<" p0 = " << track->Momentum << std::endl;
73 #endif
74 
75  // Apply the variation
76  if(ntpcs>0) track->Momentum += delta/(ntpcs);
77 
78 #ifdef DEBUG
79  std::cout << "p = " << track->Momentum << " delta "<<delta<<" ntpcs "<<ntpcs<<" var "<<toy.Variations[0]<< std::endl;
80 #endif
81  }
82 }
83 
84 //********************************************************************
86 //********************************************************************
87 
88  // Get the SystBox for this event
89  SystBoxB* box = GetSystBox(event);
90 
91  // Get the relevant tracks for this systematic
92  AnaRecObjectC** tracks = box->RelevantRecObjects;
93 
94  for (Int_t itrk=0;itrk<box->nRelevantRecObjects;itrk++){
95  AnaTrackB* track = static_cast<AnaTrackB*>(tracks[itrk]);
96  // Go back to the corrected momentum
97  track->Momentum = track->GetOriginalTrack()->Momentum;
98  }
99 
100  // Don't reset the spill to corrected
101  return false;
102 }
103 
104 //********************************************************************
106 //********************************************************************
107 
108  Int_t ngroups=0;
109  for (UInt_t b=0; b<sel.GetNBranches(); b++){
110  SubDetId_h det = sel.GetDetectorFV(b);
111  if (det == SubDetId::kFGD1 || det == SubDetId::kFGD){
112  IDs[ngroups++] = EventBoxTracker::kTracksWithTPCInFGD1FV;
113  }
114  if (det == SubDetId::kFGD2 || det == SubDetId::kFGD){
115  IDs[ngroups++] = EventBoxTracker::kTracksWithTPCInFGD2FV;
116  }
117  if (det == SubDetId::kP0D){
118  IDs[ngroups++] = EventBoxTracker::kTracksWithTPCInP0DFV;
119  }
120  }
121 
122  return ngroups;
123 }
Int_t _index
The index of this systematic (needed by SystematicsManager);.
const AnaTrackB * GetOriginalTrack() const
Return a casted version of the original AnaParticleB associated.
Int_t GetRelevantRecObjectGroups(const SelectionBase &sel, Int_t *IDs) const
Get the TrackGroup IDs array for this systematic.
Float_t * Variations
the vector of Variations, one for each of the systematic parameters
SystBoxB * GetSystBox(const AnaEventC &event, Int_t isel=0, Int_t ibranch=0) const
Get the SystBox corresponding to a selection, branch and event.
PDFEnum _PDF
The PDF use for the systematic parameter scan.
Float_t _mean_error
the mean error of the systematic source
Float_t Momentum
The reconstructed momentum of the particle, at the start position.
virtual void Apply(const ToyExperiment &toy, AnaEventC &event)
Apply the systematic.
virtual bool UndoSystematic(AnaEventC &event)
Undo the systematic variations done by ApplyVariation. This is faster tha reseting the full Spill...
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)
UInt_t GetNBranches() const
Return the number of branches.
Int_t nRelevantRecObjects
----—— Relevant rec objects and true objects for each systematic ------------—— ...
Definition: SystBoxB.hxx:20
AnaParticleB * GetSegmentWithMostNodesInClosestTpc(const AnaTrackB &track)
Combined function to address NuMu selection needs as efficiently as possible - gets the TPC segment w...
SubDetId_h GetDetectorFV(Int_t ibranch=0) const
Get the detector in which the Fiducial Volume is defined.
bool GetSigmaValueForBin(Int_t index, Float_t &sigma)
Get only mean or sigma.
Float_t RefitMomentum
Reconstructed momentum with the empirical distortion corrections.