HighLAND
MomRangeResolSystematics.cxx
1 #include "MomRangeResolSystematics.hxx"
2 #include "ND280AnalysisUtils.hxx"
3 #include "EventBoxTracker.hxx"
4 #include "VersioningUtils.hxx"
5 
6 //#define DEBUG
7 
8 
9 //********************************************************************
11  //********************************************************************
12 
14 }
15 
16 //********************************************************************
18  //********************************************************************
19 
20  // Get the SystBox for this event
21  SystBoxB* box = GetSystBox(event);
22 
23 #ifdef DEBUG
24  std::cout << "MomRangeResolSystematics::ApplyVariation(): " << box->nRelevantRecObjects << std::endl;
25 #endif
26 
27  // Loop over relevant tracks for this systematic
28  for (Int_t itrk=0;itrk<box->nRelevantRecObjects;itrk++){
29 
30  AnaTrackB* track = static_cast<AnaTrackB*>(box->RelevantRecObjects[itrk]);
31 
32  if (!track) continue;
33 
34  if (!track->TrueObject) continue;
35 
36 #ifdef DEBUG
37  std::cout << itrk << std::endl;
38  track->Print();
39  std::cout<<"\n"<<std::endl;
40 #endif
41 
42  // Get the true momentum
43  Float_t p0_true = track->GetTrueParticle()->Momentum;
44 
45  // Get momentum from range for muon hypothesis
46  Float_t p0_range = track->RangeMomentumMuon;
47 
48 #ifdef DEBUG
49  std::cout << "track true momentum p0_true -- " << p0_true << std::endl;
50  std::cout << "track range momentum muon p0_range -- " << p0_range << std::endl;
51 #endif
52 
53  // Get the angle of a track wrt to beam axis: this is used to determine the systematic bins
54  Float_t costheta = fabs(track->DirectionStart[2]);
55 
56  // Get the detectors involved
57  // FGD
58  int bin_fgddet = GetFGDDet(track->Detector);
59  int bin_outerdet = 0;
60  SubDetId::SubDetEnum smrd_det = GetSMRDDet( track->Detector);
61  SubDetId::SubDetEnum tecal_det = GetTECalDet( track->Detector);
62  if(smrd_det!=SubDetId::kInvalid)
63  bin_outerdet = smrd_det;
64  else if(tecal_det!=SubDetId::kInvalid)
65  bin_outerdet = tecal_det;
66 
67 #ifdef DEBUG
68  std::cout << " bin values: bin_fgddet "<< bin_fgddet << " bin_outerdet " << bin_outerdet << " costheta " << costheta << "\n";
69 #endif
70 
71  // Get the extra resolution values: bins are defined by angle
72  Float_t sigma;
73  Int_t index;
74 
75  if (!GetBinSigmaValue(bin_fgddet, bin_outerdet, costheta, sigma, index)) continue;
76 
77 #ifdef DEBUG
78  std::cout << " bin values: sigma " << sigma << " index " << index << std::endl;
79 #endif
80 
81  // Apply the additional momentum resolution smearing with a sigma=x
82  Float_t prangev = (1 + sigma * toy.GetToyVariations(_index)->Variations[index]) * (p0_range - p0_true) + p0_true;
83 
84 #ifdef DEBUG
85  std::cout << "muon candidate p_range after tweak = "<< prangev << std::endl;
86 #endif
87 
88  // Apply the variation
89  track->RangeMomentumMuon = prangev;
90  }
91 
92 }
93 
94 //********************************************************************
96  //********************************************************************
97 
98  // Get the SystBox for this event
99  SystBoxB* box = GetSystBox(event);
100 
101  for (Int_t itrk=0;itrk<box->nRelevantRecObjects;itrk++){
102  AnaTrackB* track = static_cast<AnaTrackB*>(box->RelevantRecObjects[itrk]);
103  // Go back to the corrected momentum
105  }
106  // Don't reset the spill to corrected
107  return false;
108 }
109 
110 //********************************************************************
112 //********************************************************************
113  (void)(event);
114 
115  const AnaTrackB* track = static_cast<const AnaTrackB*>(&recObj);
116 
117  // do nothing if the momentum value is a default one (-999), and less than RP default 0.1
118  if (track->RangeMomentumMuon < 0.5) return false;
119 
120  //ignore tracks with more than one segment in SMRD or ECal
121  if (track->nECALSegments>1 || track->nSMRDSegments>1) return false;
122 
123  //want the candidate with no TPC
124  if(SubDetId::GetDetectorUsed(track->Detector, SubDetId::kTPC))
125  return false;
126 
127  return true;
128 }
129 
130 
131 //********************************************************************
133  //********************************************************************
134 
135  Int_t ngroups=0;
136  for (UInt_t b=0; b<sel.GetNBranches(); b++){
137  SubDetId_h det = sel.GetDetectorFV(b);
138  if (det == SubDetId::kFGD1 || det == SubDetId::kFGD){
139  IDs[ngroups++] = EventBoxTracker::kTracksWithFGD1AndNoTPC;
140  }
141  if (det == SubDetId::kFGD2 || det == SubDetId::kFGD){
142  IDs[ngroups++] = EventBoxTracker::kTracksWithFGD2AndNoTPC;
143  }
144  }
145 
146  return ngroups;
147 }
148 
149 //**************************************************
151  //**************************************************
152  SubDetId::SubDetEnum det = SubDetId::kInvalid;
153  if(SubDetId::GetDetectorUsed(Detector, SubDetId::kFGD1))
154  det = SubDetId::kFGD1;
155  else if(SubDetId::GetDetectorUsed(Detector, SubDetId::kFGD2))
156  det = SubDetId::kFGD2;
157 
158  return det;
159 }
160 
161 
162 
163 
164 //**************************************************
166  //**************************************************
167  SubDetId::SubDetEnum det = SubDetId::kInvalid;
168  if(SubDetId::GetDetectorUsed(Detector, SubDetId::kTopTECAL))
169  det = SubDetId::kTopTECAL;
170  else if(SubDetId::GetDetectorUsed(Detector, SubDetId::kLeftTECAL))
171  det = SubDetId::kLeftTECAL;
172  else if(SubDetId::GetDetectorUsed(Detector, SubDetId::kRightTECAL))
173  det = SubDetId::kRightTECAL;
174  else if(SubDetId::GetDetectorUsed(Detector, SubDetId::kBottomTECAL))
175  det = SubDetId::kBottomTECAL;
176 
177  return det;
178 }
179 
180 
181 
182 //**************************************************
184  //**************************************************
185  SubDetId::SubDetEnum det = SubDetId::kInvalid;
186  if(SubDetId::GetDetectorUsed(Detector, SubDetId::kTopSMRD))
187  det = SubDetId::kTopSMRD;
188  else if(SubDetId::GetDetectorUsed(Detector, SubDetId::kLeftSMRD))
189  det = SubDetId::kLeftSMRD;
190  else if(SubDetId::GetDetectorUsed(Detector, SubDetId::kRightSMRD))
191  det = SubDetId::kRightSMRD;
192  else if(SubDetId::GetDetectorUsed(Detector, SubDetId::kBottomSMRD))
193  det = SubDetId::kBottomSMRD;
194 
195  return det;
196 }
Int_t _index
The index of this systematic (needed by SystematicsManager);.
const AnaTrackB * GetOriginalTrack() const
Return a casted version of the original AnaParticleB associated.
unsigned long Detector
Float_t * Variations
the vector of Variations, one for each of the systematic parameters
int nECALSegments
How many ECAL tracks are associated with this track.
virtual bool IsRelevantRecObject(const AnaEventC &, const AnaRecObjectC &) const
Check whether a RecObject is relevant for this systematic or not.
SystBoxB * GetSystBox(const AnaEventC &event, Int_t isel=0, Int_t ibranch=0) const
Get the SystBox corresponding to a selection, branch and event.
virtual void Print() const
Dump the object to screen.
void SetNParameters(int N)
Set the number of systematic parameters associated to this systematic.
SubDetId::SubDetEnum GetSMRDDet(unsigned long Detector)
Get SMRD detector assuming only one can be present.
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 Momentum
The initial momentum of the true particle.
SubDetId::SubDetEnum GetTECalDet(unsigned long Detector)
Get TECal detector assuming only one can be present.
Float_t RangeMomentumMuon
Momentum by range calculated with muon hypothesis.
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...
int nSMRDSegments
How many SMRD tracks are associated with this track.
SubDetEnum
Enumeration of all detector systems and subdetectors.
Definition: SubDetId.hxx:25
Representation of a global track.
ToyVariations * GetToyVariations(UInt_t index) const
returns the variations for a given systematic (index)
Float_t DirectionStart[3]
The reconstructed start direction of the particle.
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
SubDetId::SubDetEnum GetFGDDet(unsigned long Detector)
Get FGD detector assuming only one can be present.
AnaTrueParticleB * GetTrueParticle() const
Return a casted version of the AnaTrueObject associated.
bool GetBinSigmaValue(Float_t value, Float_t &sigma)
Get only sigma.
Int_t GetRelevantRecObjectGroups(const SelectionBase &sel, Int_t *IDs) const
Get the TrackGroup IDs array for this systematic.
MomRangeResolSystematics()
Instantiate the momentum resolution systematic.
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.