HighLAND
antiNumuCCSelection.cxx
1 #include "antiNumuCCSelection.hxx"
2 #include "baseSelection.hxx"
3 #include "SystematicTuning.hxx"
4 #include "CutUtils.hxx"
5 #include "EventBoxUtils.hxx"
6 #include "SubDetId.hxx"
7 #include "SystId.hxx"
8 #include "VersioningUtils.hxx"
9 #include "SystematicUtils.hxx"
10 #include "trackerSelectionUtils.hxx"
11 
12 //********************************************************************
13 antiNumuCCSelection::antiNumuCCSelection(bool forceBreak): SelectionBase(forceBreak,EventBoxId::kEventBoxTracker) {
14 //********************************************************************
15 
16  // Initialize the numuCCSelection, which is used
17  _numuCCSelection.Initialize();
18 
19  // Initialize systematic tuning parameters
20  systTuning::Initialize();
21 }
22 
23 //********************************************************************
25 //********************************************************************
26 
27  // Cuts must be added in the right order
28  // last "true" means the step sequence is broken if cut is not passed (default is "false")
29  AddStep(StepBase::kCut, "event quality", new EventQualityCut(), true);
30  AddStep(StepBase::kCut, "> 0 tracks ", new TotalMultiplicityCut(), true);
31  AddStep(StepBase::kAction, "find leading tracks",new FindLeadingTracksAction_antinu());
32  AddStep(StepBase::kAction, "find vertex", new FindVertexAction());
33  AddStep(StepBase::kAction, "fill summary", new FillSummaryAction_antinu());
34  AddStep(StepBase::kCut, "quality+fiducial", new TrackQualityFiducialCut(), true);
35  AddStep(StepBase::kCut, "pos_mult", new PositiveMultiplicityCut());
36  AddStep(StepBase::kAction, "find veto track", new FindVetoTrackAction());
37  AddStep(StepBase::kCut, "veto", new ExternalVetoCut());
38  AddStep(StepBase::kAction, "find oofv track", new FindOOFVTrackAction());
39  AddStep(StepBase::kCut, "External FGD1", new ExternalFGD1lastlayersCut());
40  AddStep(StepBase::kCut, "Anti muon PID", new AntiMuonPIDCut());
41 
42  SetBranchAlias(0,"trunk");
43 
44  // By default the preselection correspond to cuts 0-2
45  SetPreSelectionAccumLevel(2);
46 
47  // Step and Cut numbers needed by CheckRedoSelection
48  _MuonPIDCutIndex = GetCutNumber("Anti muon PID");
49  _MuonPIDStepIndex = GetStepNumber("Anti muon PID");
50  _FindLeadingTracksStepIndex = GetStepNumber("find leading tracks");
51  _TotalMultiplicityCutIndex = GetCutNumber("> 0 tracks ");
52 }
53 
54 //********************************************************************
56 //********************************************************************
57 
58  // The detector in which the selection is applied
59  SetDetectorFV(SubDetId::kFGD1);
60 }
61 
62 //********************************************************************
63 bool antiNumuCCSelection::FillEventSummary(AnaEventC& event, Int_t allCutsPassed[]){
64 //********************************************************************
65 
66  // The event sample corresponding to this selection
67  if(allCutsPassed[0]) static_cast<AnaEventSummaryB*>(event.Summary)->EventSample = SampleId::kFGD1AntiNuMuCC;
68 
69  return (static_cast<AnaEventSummaryB*>(event.Summary)->EventSample != SampleId::kUnassigned);
70 }
71 
72 //********************************************************************
74 //********************************************************************
75 
76  // Cast the ToyBox to the appropriate type
77  ToyBoxTracker& box = *static_cast<ToyBoxTracker*>(&boxB);
78 
79  if(!box.HMPtrack) return 1;
80 
81  static_cast<AnaEventSummaryB*>(event.Summary)->LeptonCandidate[SampleId::kFGD1AntiNuMuCC] = box.HMPtrack;
82  for(int i = 0; i < 4; ++i){
83  static_cast<AnaEventSummaryB*>(event.Summary)->VertexPosition[SampleId::kFGD1AntiNuMuCC][i] = box.HMPtrack->PositionStart[i];
84  }
85  if(box.HMPtrack->GetTrueParticle()) static_cast<AnaEventSummaryB*>(event.Summary)->TrueVertex[SampleId::kFGD1AntiNuMuCC] = box.HMPtrack->GetTrueParticle()->TrueVertex;
86  return 1;
87 }
88 
89 //**************************************************
91 //**************************************************
92 
93  // Cast the ToyBox to the appropriate type
94  ToyBoxTracker& box = *static_cast<ToyBoxTracker*>(&boxB);
95 
96  // Find leading tracks with good quality and only in FGD FV
97  trackerSelUtils::FindLeadingTracks(event, box);
98 
99  // For this selection the main track is the HMP track
100  box.MainTrack = box.HMPtrack;
101  return true;
102 }
103 
104 //**************************************************
106 //**************************************************
107 
108  (void)event;
109 
110  // Cast the ToyBox to the appropriate type
111  ToyBoxTracker& box = *static_cast<ToyBoxTracker*>(&boxB);
112 
113  return (box.HMPtrack==box.HMtrack);
114 }
115 
116 //**************************************************
117 bool AntiMuonPIDCut::Apply(AnaEventC& event, ToyBoxB& boxB) const{
118 //**************************************************
119 
120  (void)event;
121  // Cast the ToyBox to the appropriate type
122  ToyBoxTracker& box = *static_cast<ToyBoxTracker*>(&boxB);
123 
124  if (!box.HMPtrack) return false;
125  if(box.HMPtrack->Momentum < 0.) return false;
126  return cutUtils::AntiMuonPIDCut(*(box.HMPtrack));
127 }
128 
129 //**************************************************
130 bool antiNumuCCSelection::IsRelevantRecObjectForSystematic(const AnaEventC& event, AnaRecObjectC* track, SystId_h systId, Int_t branch) const{
131 //**************************************************
132 
133  return _numuCCSelection.IsRelevantRecObjectForSystematic(event,track,systId,branch);
134 }
135 
136 //**************************************************
137 bool antiNumuCCSelection::IsRelevantTrueObjectForSystematic(const AnaEventC& event, AnaTrueObjectC* trueTrack, SystId_h systId, Int_t branch) const{
138 //**************************************************
139 
140  return _numuCCSelection.IsRelevantTrueObjectForSystematic(event,trueTrack,systId,branch);
141 }
142 
143 //**************************************************
144 bool antiNumuCCSelection::IsRelevantRecObjectForSystematicInToy(const AnaEventC& event, const ToyBoxB& box, AnaRecObjectC* track, SystId_h systId, Int_t branch) const{
145 //**************************************************
146 
147  return _numuCCSelection.IsRelevantRecObjectForSystematicInToy(event,box,track,systId,branch);
148 }
149 
150 //**************************************************
151 bool antiNumuCCSelection::IsRelevantTrueObjectForSystematicInToy(const AnaEventC& event, const ToyBoxB& boxB, AnaTrueObjectC* trueObj, SystId_h systId, Int_t branch) const{
152 //**************************************************
153 
154  // Apply to all objects, not fine-tuning
155  if (!systTuning::APPLY_SYST_FINE_TUNING) return true;
156 
157  // Cast the ToyBox to the appropriate type
158  const ToyBoxTracker& box = *static_cast<const ToyBoxTracker*>(&boxB);
159 
160 
161  AnaTrueParticleB* trueTrack = static_cast<AnaTrueParticleB*>(trueObj);
162 
163  // Main track "mode", will only consider certain true tracks of interest
164 
165  if(systId == SystId::kTpcTrackEff){
166  if (box.MainTrack->GetTrueParticle()){
167  // At first order the inclusive selection only depends on the tracking efficiency of the muon candidate.
168  if (trueTrack->ID == box.MainTrack->GetTrueParticle()->ID) return true;
169 
170  // Consider also the case in which the muon candidate is not a true anti-muon but this track it is
171  if (trueTrack->PDG == -13 && box.MainTrack->GetTrueParticle()->PDG!=-13) return true;
172 
173  return false;
174 
175  }
176  // Apply for anti-muon
177  else if (trueTrack->PDG == -13)
178  return true;
179 
180  return false;
181  }
182 
183  else if (systId == SystId::kSIProton){
184 
185  // If this trueTrack is NOT associated to the MainTrack, consider the posibility of this trueTrack to become the MainTrack
186  // This is to be tuned: e.g. may consider explicitely those not reconstructed in TPC
187  // also the ones that have the momentum ~closer to the Bethe-Bloch crossing point,
188  // i.e. when proton background starts to become non-negligible
189  if (trueTrack->PDG == 2212 && trueTrack->Momentum > box.MainTrack->Momentum
190  && trueTrack->Momentum > 1000.) return true;
191 
192  return false;
193  }
194 
195 
196  return _numuCCSelection.IsRelevantTrueObjectForSystematicInToy(event,boxB,trueObj,systId,branch);
197 
198 
199 }
200 
201 //**************************************************
202 bool antiNumuCCSelection::IsRelevantSystematic(const AnaEventC& event, const ToyBoxB& box, SystId_h systId, Int_t branch) const{
203 //**************************************************
204 
205  // Nu flux is not relevant
206  if (systId == SystId::kFluxWeightNu)
207  return false;
208 
209  // AntiNu flux is relevant
210  if (systId == SystId::kFluxWeightAntiNu)
211  return true;
212 
213  // For the rest trust numu
214  return _numuCCSelection.IsRelevantSystematic(event, box, systId, branch);
215 
216 }
217 
218 //**************************************************
220 //**************************************************
221 
222  _numuCCSelection.InitializeEvent(event);
223 }
224 
225 
226 //********************************************************************
227 bool antiNumuCCSelection::CheckRedoSelection(const AnaEventC& event, const ToyBoxB& PreviousToyBoxB, Int_t& redoFromStep){
228 //********************************************************************
229 
230  (void)event;
231 
232  // Cast the ToyBox to the appropriate type
233  const ToyBoxTracker& PreviousToyBox = *static_cast<const ToyBoxTracker*>(&PreviousToyBoxB);
234 
235  // Relevant properties of the previous toy are saved in the PreviousToyBox that is passed as parameter
236  // - i.e PreviousToyBox->HMPtrack is the HMPtrack of the previous toy
237  // - i.e PreviousToyBox->AccumLevel[i] is the accum level of the previous toy
238  // for branch i in this selection
239 
240  // Only redo the selection when the HMN track changes identity or the PID cut has a different effect:
241 
242  // nothing to do if there is no HMP track
243  if (!PreviousToyBox.HMPtrack) return false;
244 
245  if (PreviousToyBox.MaxAccumLevel > _TotalMultiplicityCutIndex){
246  ToyBoxTracker box;
247  trackerSelUtils::FindLeadingTracks(event, box);
248 
249  // Redo the selection if any of the leading tracks changes identity
250  if (PreviousToyBox.SHMNtrack!=box.SHMNtrack ||
251  PreviousToyBox.SHMPtrack!=box.SHMPtrack ||
252  PreviousToyBox.HMNtrack !=box.HMNtrack ||
253  PreviousToyBox.HMPtrack !=box.HMPtrack ||
254  PreviousToyBox.SHMtrack !=box.SHMtrack ||
255  PreviousToyBox.HMtrack !=box.HMtrack){
256 
257  redoFromStep = _FindLeadingTracksStepIndex;
258  return true;
259  }
260  }
261 
262  // When the HMN track does not change identity, Redo the selection if the effect of the PID cut is different.
263  // We have previously saved in the EventBox the AccumLevel of the previous toy for each branch.
264  // PreviousToyBox->AccumLevel[0]>_MuonPIDCutIndex means that the PID cut was passed, so we check whether the cut
265  // was passed in the previous toy and not in the current one, or the opposit, it was not passed before
266  // and it is passed now.
267 
268 
269  if (PreviousToyBox.MaxAccumLevel >= _MuonPIDCutIndex){
270  bool pidCut = cutUtils::AntiMuonPIDCut(*(PreviousToyBox.HMPtrack));
271  if (( pidCut && (PreviousToyBox.AccumLevel[0] == _MuonPIDCutIndex)) ||
272  (!pidCut && (PreviousToyBox.AccumLevel[0] > _MuonPIDCutIndex))){
273  redoFromStep = _MuonPIDStepIndex;
274  return true;
275  }
276  }
277 
278  return false;
279 }
AnaTrackB * SHMtrack
For storing the second highest momentum track.
AnaTrueVertexB * TrueVertex
Pointer to the AnaTrueVertexB of the interaction that created this AnaTrueParticleB.
Float_t PositionStart[4]
The reconstructed start position of the particle.
Int_t MaxAccumLevel
Definition: ToyBoxB.hxx:39
void InitializeEvent(AnaEventC &event)
Fill the EventBox with the objects needed by this selection.
bool IsRelevantTrueObjectForSystematic(const AnaEventC &event, AnaTrueObjectC *trueObj, SystId_h systId, Int_t branch) const
Is this true track relevant for a given systematic (prior to selection, call when initializing the ev...
bool IsRelevantTrueObjectForSystematicInToy(const AnaEventC &, const ToyBoxB &, AnaTrueObjectC *, SystId_h systId, Int_t branch=0) const
Is this true track relevant for a given systematic (after selection, called for each toy) ...
AnaTrackB * MainTrack
For storing the Main Track (The lepton candidate in geranal: HMN or HMP track)
Float_t Momentum
The initial momentum of the true particle.
AnaTrackB * HMPtrack
For storing the highest momentum positive track.
Int_t ID
The ID of the trueObj, which corresponds to the ID of the TTruthParticle that created it...
bool Apply(AnaEventC &event, ToyBoxB &box) const
Float_t Momentum
The reconstructed momentum of the particle, at the start position.
Leading tracks with good quality in FGD1.
Representation of a true Monte Carlo trajectory/particle.
bool CheckRedoSelection(const AnaEventC &event, const ToyBoxB &PreviousToyBox, Int_t &redoFromStep)
Int_t PDG
The PDG code of this particle.
AnaTrackB * HMNtrack
For storing the highest momentum negative track.
bool Apply(AnaEventC &event, ToyBoxB &box) const
AnaTrackB * SHMPtrack
For storing the second highest momentum positive track.
AnaTrackB * HMtrack
For storing the highest momentum track.
bool IsRelevantSystematic(const AnaEventC &event, const ToyBoxB &box, SystId_h systId, Int_t branch) const
Is this systematic relevant for this selection.
bool APPLY_SYST_FINE_TUNING
General tuning, the concept of apply the systematic for only the "relevant" objects.
AnaEventSummaryC * Summary
A summary of the event with high level quantities.
bool Apply(AnaEventC &event, ToyBoxB &box) const
AnaTrackB * SHMNtrack
For storing the second highest momentum negative track.
Int_t * AccumLevel
Accum level for each branch in this toy in the selection this ToyBox belongs to.
Definition: ToyBoxB.hxx:35
bool Apply(AnaEventC &event, ToyBoxB &box) const
void DefineDetectorFV()
Define the detector Fiducial Volume in which this selection is applied.
Find the Vertex. For the moment it&#39;s just the Star position of the HM track.
bool IsRelevantRecObjectForSystematic(const AnaEventC &event, AnaRecObjectC *recObj, SystId_h systId, Int_t branch) const
Is this track relevant for a given systematic (prior to selection, call when initializing the event...
bool IsRelevantRecObjectForSystematicInToy(const AnaEventC &, const ToyBoxB &, AnaRecObjectC *, SystId_h systId, Int_t branch=0) const
Is this track relevant for a given systematic (after selection, called for each toy) ...
void DefineSteps()
Define all steps in the selection.
AnaTrueParticleB * GetTrueParticle() const
Return a casted version of the AnaTrueObject associated.
A cut on event quality. Requires good beam and ND280 data quality flags.
void Initialize()
Initialize this selection: defines the steps and the detectorFV.