HighLAND
numuBkgInAntiNuModeCCSelection.cxx
1 #include "numuBkgInAntiNuModeCCSelection.hxx"
2 #include "baseSelection.hxx"
3 #include "numuCCSelection.hxx"
4 #include "CutUtils.hxx"
5 #include "SubDetId.hxx"
6 #include "VersioningUtils.hxx"
7 #include "trackerSelectionUtils.hxx"
8 #include "EventBoxId.hxx"
9 #include "SystId.hxx"
10 
11 //********************************************************************
12 numuBkgInAntiNuModeCCSelection::numuBkgInAntiNuModeCCSelection(bool forceBreak): SelectionBase(forceBreak,EventBoxId::kEventBoxTracker) {
13 //********************************************************************
14 
15  // Initialize the numuCCSelection, which is used
16  _numuCCSelection.Initialize();
17 }
18 
19 //********************************************************************
21 //********************************************************************
22 
23  // Cuts must be added in the right order
24  // last "true" means the step sequence is broken if cut is not passed (default is "false")
25  AddStep(StepBase::kCut, "event quality", new EventQualityCut(), true);
26  AddStep(StepBase::kCut, "> 0 tracks ", new TotalMultiplicityCut(), true);
27  AddStep(StepBase::kAction, "find leading tracks",new FindLeadingTracksAction());
28  AddStep(StepBase::kAction, "find vertex", new FindVertexAction());
29  AddStep(StepBase::kAction, "fill summary", new FillSummaryAction_numuBkg());
30  AddStep(StepBase::kCut, "quality+fiducial", new TrackQualityFiducialCut(), true);
31  AddStep(StepBase::kCut, "neg_mult", new NegativeMultiplicityCut());
32  AddStep(StepBase::kAction, "find veto track", new FindVetoTrackAction());
33  AddStep(StepBase::kCut, "veto", new ExternalVetoCut());
34  AddStep(StepBase::kAction, "find oofv track", new FindOOFVTrackAction());
35  AddStep(StepBase::kCut, "External FGD1", new ExternalFGD1lastlayersCut());
36  AddStep(StepBase::kCut, "Muon PID", new NumuBkgMuonPIDCut());
37 
38  SetBranchAlias(0,"trunk");
39 
40  // By default the preselection correspond to cuts 0-2
41  SetPreSelectionAccumLevel(2);
42 
43  // Step and Cut numbers needed by CheckRedoSelection
44  _MuonPIDCutIndex = GetCutNumber("Muon PID");
45  _MuonPIDStepIndex = GetStepNumber("Muon PID");
46  _FindLeadingTracksStepIndex = GetStepNumber("find leading tracks");
47  _TotalMultiplicityCutIndex = GetCutNumber("> 0 tracks ");
48 }
49 
50 //********************************************************************
52 //********************************************************************
53 
54  // The detector in which the selection is applied
55  SetDetectorFV(SubDetId::kFGD1);
56 
57  // Set the detector field into the selection beaing used
58  _numuCCSelection.SetDetectorFV(SubDetId::kFGD1);
59 }
60 
61 //********************************************************************
62 bool numuBkgInAntiNuModeCCSelection::FillEventSummary(AnaEventC& event, Int_t allCutsPassed[]){
63 //********************************************************************
64 
65  // The event sample corresponding to this selection
66  if(allCutsPassed[0]) static_cast<AnaEventSummaryB*>(event.Summary)->EventSample = SampleId::kFGD1NuMuBkgInAntiNuModeCC;
67 
68  return (static_cast<AnaEventSummaryB*>(event.Summary)->EventSample != SampleId::kUnassigned);
69 }
70 
71 //********************************************************************
73 //********************************************************************
74 
75  // Cast the ToyBox to the appropriate type
76  ToyBoxTracker& box = *static_cast<ToyBoxTracker*>(&boxB);
77 
78  if(!box.HMNtrack) return true;
79 
80  static_cast<AnaEventSummaryB*>(event.Summary)->LeptonCandidate[SampleId::kFGD1NuMuBkgInAntiNuModeCC] = box.HMNtrack;
81  for(int i = 0; i < 4; ++i){
82  static_cast<AnaEventSummaryB*>(event.Summary)->VertexPosition[SampleId::kFGD1NuMuBkgInAntiNuModeCC][i] = box.HMNtrack->PositionStart[i];
83  }
84  if(box.HMNtrack->GetTrueParticle()) static_cast<AnaEventSummaryB*>(event.Summary)->TrueVertex[SampleId::kFGD1NuMuBkgInAntiNuModeCC] = box.HMNtrack->GetTrueParticle()->TrueVertex;
85  return true;
86 }
87 
88 //**************************************************
90 //**************************************************
91 
92  (void)event;
93 
94  // Cast the ToyBox to the appropriate type
95  ToyBoxTracker& box = *static_cast<ToyBoxTracker*>(&boxB);
96 
97  return (box.HMNtrack==box.HMtrack);
98 }
99 
100 //**************************************************
101 bool NumuBkgMuonPIDCut::Apply(AnaEventC& event, ToyBoxB& boxB) const{
102 //**************************************************
103 
104  (void)event;
105 
106  // Cast the ToyBox to the appropriate type
107  ToyBoxTracker& box = *static_cast<ToyBoxTracker*>(&boxB);
108 
109  if (!box.HMNtrack) return false;
110  if(box.HMNtrack->Momentum < 0.) return false;
111  return cutUtils::NumuBkgMuonPIDCut(*(box.HMNtrack));
112 }
113 
114 //**************************************************
115 bool numuBkgInAntiNuModeCCSelection::IsRelevantRecObjectForSystematic(const AnaEventC& event, AnaRecObjectC* track, SystId_h systId, Int_t branch) const{
116 //**************************************************
117 
118  return _numuCCSelection.IsRelevantRecObjectForSystematic(event,track,systId,branch);
119 }
120 
121 //**************************************************
122 bool numuBkgInAntiNuModeCCSelection::IsRelevantTrueObjectForSystematic(const AnaEventC& event, AnaTrueObjectC* trueTrack, SystId_h systId, Int_t branch) const{
123 //**************************************************
124 
125  return _numuCCSelection.IsRelevantTrueObjectForSystematic(event,trueTrack,systId,branch);
126 }
127 
128 //**************************************************
129 bool numuBkgInAntiNuModeCCSelection::IsRelevantSystematic(const AnaEventC& event, const ToyBoxB& box, SystId_h systId, Int_t branch) const{
130 //**************************************************
131 
132  // Same as for numuCC but preffer to write is explicitely
133 
134  (void)event;
135  (void)branch;
136  (void)box;
137 
138  if (systId==SystId::kFgdTrackEff) // No FGD track eff
139  return false;
140  else if (systId==SystId::kFgdHybridTrackEff) // No FGD hybrid track eff
141  return false;
142  else if (systId==SystId::kMichelEleEff) // No michel electron Systematic
143  return false;
144  else if (systId==SystId::kSIPion) // No Pion SI systematic
145  return false;
146  else if (systId==SystId::kSIProton) // No Proton SI systematic
147  return false;
148  return true;
149 }
150 
151 //**************************************************
153 //**************************************************
154 
155  _numuCCSelection.InitializeEvent(event);
156 }
157 
158 //********************************************************************
159 bool numuBkgInAntiNuModeCCSelection::CheckRedoSelection(const AnaEventC& event, const ToyBoxB& PreviousToyBoxB, Int_t& redoFromStep){
160 //********************************************************************
161 
162  (void)event;
163  // redoFromStep=0;
164  // return true;
165  // Relevant properties of the previous toy are saved in the PreviousToyBox that is passed as parameter
166  // - i.e PreviousToyBox->HMNtrack is the HMNtrack of the previous toy
167  // - i.e PreviousToyBox->AccumLevel[i] is the accum level of the previous toy
168  // for branch i in this selection
169 
170  // Only redo the selection when the HMN track changes identity or the PID cut has a different effect:
171 
172  // Cast the ToyBox to the appropriate type
173  const ToyBoxTracker& PreviousToyBox = *static_cast<const ToyBoxTracker*>(&PreviousToyBoxB);
174 
175  // nothing to do if there is no HMN track
176  if (!PreviousToyBox.HMNtrack) return false;
177 
178  if (PreviousToyBox.MaxAccumLevel > _TotalMultiplicityCutIndex){
179  ToyBoxTracker box;
180  trackerSelUtils::FindLeadingTracks(event, box);
181 
182  // Redo the selection if any of the leading tracks changes identity
183  if (PreviousToyBox.SHMNtrack!=box.SHMNtrack ||
184  PreviousToyBox.SHMPtrack!=box.SHMPtrack ||
185  PreviousToyBox.HMNtrack !=box.HMNtrack ||
186  PreviousToyBox.HMPtrack !=box.HMPtrack ||
187  PreviousToyBox.SHMtrack !=box.SHMtrack ||
188  PreviousToyBox.HMtrack !=box.HMtrack){
189 
190  redoFromStep = _FindLeadingTracksStepIndex;
191  return true;
192  }
193  }
194 
195  // When the leading tracks do not change identity, Redo the selection if the effect of the PID cut is different.
196  // We have previously saved in the EventBox the AccumLevel of the previous toy for each branch.
197  // PreviousToyBox->AccumLevel[0]>_MuonPIDCutIndex means that the PID cut was passed, so we check whether the cut
198  // was passed in the previous toy and not in the current one, or the opposit, it was not passed before
199  // and it is passed now.
200 
201  if (PreviousToyBox.MaxAccumLevel >= _MuonPIDCutIndex){
202  bool pidCut = cutUtils::NumuBkgMuonPIDCut(*(PreviousToyBox.HMNtrack));
203  if (( pidCut && (PreviousToyBox.AccumLevel[0] == _MuonPIDCutIndex)) ||
204  (!pidCut && (PreviousToyBox.AccumLevel[0] > _MuonPIDCutIndex))){
205  // We should redo the selection starting from the MuonPIDCut step
206  redoFromStep = _MuonPIDStepIndex;
207  return true;
208  }
209  }
210 
211  return false;
212 }
213 
214 
215 
AnaTrackB * SHMtrack
For storing the second highest momentum track.
bool CheckRedoSelection(const AnaEventC &event, const ToyBoxB &PreviousToyBox, Int_t &redoFromStep)
AnaTrueVertexB * TrueVertex
Pointer to the AnaTrueVertexB of the interaction that created this AnaTrueParticleB.
Float_t PositionStart[4]
The reconstructed start position of the particle.
bool Apply(AnaEventC &event, ToyBoxB &box) const
Int_t MaxAccumLevel
Definition: ToyBoxB.hxx:39
void DefineDetectorFV()
Define the detector Fiducial Volume in which this selection is applied.
AnaTrackB * HMPtrack
For storing the highest momentum positive track.
bool Apply(AnaEventC &event, ToyBoxB &box) const
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.
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 IsRelevantSystematic(const AnaEventC &event, const ToyBoxB &box, SystId_h systId, Int_t branch) const
Is this systematic relevant for this selection.
AnaTrackB * HMNtrack
For storing the highest momentum negative track.
void InitializeEvent(AnaEventC &event)
Fill the EventBox with the objects needed by this selection.
AnaTrackB * SHMPtrack
For storing the second highest momentum positive track.
AnaTrackB * HMtrack
For storing the highest momentum track.
AnaEventSummaryC * Summary
A summary of the event with high level quantities.
AnaTrackB * SHMNtrack
For storing the second highest momentum negative track.
void DefineSteps()
Define all steps in the selection.
Int_t * AccumLevel
Accum level for each branch in this toy in the selection this ToyBox belongs to.
Definition: ToyBoxB.hxx:35
Find the Vertex. For the moment it&#39;s just the Star position of the HM track.
AnaTrueParticleB * GetTrueParticle() const
Return a casted version of the AnaTrueObject associated.
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...
A cut on event quality. Requires good beam and ND280 data quality flags.
void Initialize()
Initialize this selection: defines the steps and the detectorFV.