HighLAND
tutorialBranchesSelection.cxx
1 #include "tutorialBranchesSelection.hxx"
2 #include "tutorialSelection.hxx"
3 #include "baseSelection.hxx"
4 #include "CutUtils.hxx"
5 #include "Parameters.hxx"
6 #include "SubDetId.hxx"
7 #include "EventBoxUtils.hxx"
8 
9 //*******************************************************************************
10 tutorialBranchesSelection::tutorialBranchesSelection(bool forceBreak): SelectionBase(forceBreak,EventBoxId::kEventBoxTracker){
11 //*******************************************************************************
12  // Fill smth if needed
13 
14 }
15 
16 //*******************************************************************************
18 //*******************************************************************************
19 
20  // Set the detector Fiducial Volume in which the selection is applied. This is now a mandatory method
21  // If different branches use different FV you can specify the branch with SetDetectorFV(SubDetId::kFGD1, branch).
22  // Have a look at numuCCMultiTargetAnalysis for an example
23  SetDetectorFV(SubDetId::kFGD1);
24 }
25 
26 //*******************************************************************************
28 //*******************************************************************************
29 
30  // Copy all steps from the tutorialSelection
32  CopySteps(tut);
33 
34  // Add an action to the trunk
35  AddStep(StepBase::kAction, "find long tpc tracks", new FindLongTPCTracks());
36 
37  //Add a split to the trunk with 4 branches.
38  AddSplit(4);
39 
40  //First branch is for 1-track events. We add now a cut to branch 0
41  AddStep(0, StepBase::kCut, "1-track", new OneTPCTrackCut());
42 
43  //Second branch is for 2-track events. We add now a cut to branch 1
44  AddStep(1, StepBase::kCut, "2-tracks", new TwoTPCTracksCut());
45 
46  //Third branch is for >2 track events. We add now a cut to branch 2
47  AddStep(2, StepBase::kCut, ">2-tracks", new MoreThanTwoTPCTracksCut());
48 
49  //Forth branch is for >2 track events in which the two tracks have more than 65 nodes. We add now a cut to branch 3
50  AddStep(3, StepBase::kCut, ">2 long-tracks", new MoreThanTwoLongTPCTracksCut());
51 
52 
53  // Set the branch aliases to the three branches (this is mandatory)
54  // First integer is the branch number at each split. Since we have only one explit there is a single number (0, 1, 2)
55  // Second integer is the alias number (0, 1, 2) to be used in the DrawingTools when refering to a specific branch
56  SetBranchAlias(0,"1-track", 0);
57  SetBranchAlias(1,"2-tracks", 1);
58  SetBranchAlias(2,">2-tracks", 2);
59  SetBranchAlias(3,">2 long-tracks",3);
60 
61  // By default the preselection correspond to cuts 0-2.
62  // It means that if any of the three first cuts (0,1,2) is not passed
63  // the loop over toys will be broken ===> A single toy will be run
64  SetPreSelectionAccumLevel(2);
65 }
66 
67 //********************************************************************
68 bool tutorialBranchesSelection::FillEventSummary(AnaEventC& event, Int_t allCutsPassed[]){
69 //********************************************************************
70 
71  //CC0pi
72  if(allCutsPassed[0]){
73  static_cast<AnaEventSummaryB*>(event.Summary)->EventSample = SampleId::kFGD1NuMuCC0Pi;
74  }
75  //CC1pi
76  else if (allCutsPassed[1]){
77  static_cast<AnaEventSummaryB*>(event.Summary)->EventSample = SampleId::kFGD1NuMuCC1Pi;
78  }
79  //CCOther
80  else if (allCutsPassed[2]){
81  static_cast<AnaEventSummaryB*>(event.Summary)->EventSample = SampleId::kFGD1NuMuCCOther;
82  }
83 
84  // otherwise kUnassigned is used from the EventSummary constructor
85  return (static_cast<AnaEventSummaryB*>(event.Summary)->EventSample != SampleId::kUnassigned);
86 }
87 
88 
89 //*********************************************************************
91 //*********************************************************************
92 
93  // cast the box to the appropriate type
94  ToyBoxTutorial& box = *static_cast<ToyBoxTutorial*>(&boxB);
95 
96  if(!box.HMNtrack) return 1;
97 
98  static_cast<AnaEventSummaryB*>(event.Summary)->LeptonCandidate[SampleId::kFGD1NuMuCC0Pi] = box.HMNtrack;
99  static_cast<AnaEventSummaryB*>(event.Summary)->LeptonCandidate[SampleId::kFGD1NuMuCC1Pi] = box.HMNtrack;
100  static_cast<AnaEventSummaryB*>(event.Summary)->LeptonCandidate[SampleId::kFGD1NuMuCCOther] = box.HMNtrack;
101 
102  for(int i = 0; i < 4; ++i){
103  static_cast<AnaEventSummaryB*>(event.Summary)->VertexPosition[SampleId::kFGD1NuMuCC0Pi][i] = box.HMNtrack->PositionStart[i];
104  static_cast<AnaEventSummaryB*>(event.Summary)->VertexPosition[SampleId::kFGD1NuMuCC1Pi][i] = box.HMNtrack->PositionStart[i];
105  static_cast<AnaEventSummaryB*>(event.Summary)->VertexPosition[SampleId::kFGD1NuMuCCOther][i] = box.HMNtrack->PositionStart[i];
106  }
107  if(box.HMNtrack->GetTrueParticle()){
108  static_cast<AnaEventSummaryB*>(event.Summary)->TrueVertex[SampleId::kFGD1NuMuCC0Pi] = box.HMNtrack->GetTrueParticle()->TrueVertex;
109  static_cast<AnaEventSummaryB*>(event.Summary)->TrueVertex[SampleId::kFGD1NuMuCC1Pi] = box.HMNtrack->GetTrueParticle()->TrueVertex;
110  static_cast<AnaEventSummaryB*>(event.Summary)->TrueVertex[SampleId::kFGD1NuMuCCOther] = box.HMNtrack->GetTrueParticle()->TrueVertex;
111  }
112 
113  return 1;
114 }
115 
116 //*********************************************************************
117 bool OneTPCTrackCut::Apply(AnaEventC& event, ToyBoxB& boxB) const{
118 //*********************************************************************
119 
120  (void)event;
121 
122  // cast the box to the appropriate type
123  ToyBoxTutorial& box = *static_cast<ToyBoxTutorial*>(&boxB);
124 
125 
126  if (box.nNegativeTPCtracks+box.nPositiveTPCtracks==1)
127  return true;
128  else
129  return false;
130 }
131 
132 
133 //*********************************************************************
134 bool TwoTPCTracksCut::Apply(AnaEventC& event, ToyBoxB& boxB) const{
135 //*********************************************************************
136 
137  (void)event;
138 
139  // cast the box to the appropriate type
140  ToyBoxTutorial& box = *static_cast<ToyBoxTutorial*>(&boxB);
141 
142 
143  if (box.nNegativeTPCtracks+box.nPositiveTPCtracks==2)
144  return true;
145  else
146  return false;
147 }
148 
149 
150 //*********************************************************************
152 //*********************************************************************
153 
154  (void)event;
155 
156  // cast the box to the appropriate type
157  ToyBoxTutorial& box = *static_cast<ToyBoxTutorial*>(&boxB);
158 
159 
160  if (box.nNegativeTPCtracks+box.nPositiveTPCtracks>2)
161  return true;
162  else
163  return false;
164 }
165 
166 //*********************************************************************
168 //*********************************************************************
169 
170  (void)event;
171 
172  // Cast the box such that we can access nLongTPCTracks, not present in ToyBoxB
173  const ToyBoxTutorial* tutBox = static_cast<const ToyBoxTutorial*>(&box);
174 
175  if (tutBox->nLongTPCTracks>2)
176  return true;
177  else
178  return false;
179 }
180 
181 //*********************************************************************
183 //*********************************************************************
184 
185  AnaEventB& event = *static_cast<AnaEventB*>(&eventC);
186 
187  // Get all tracks using the TPC
188  AnaTrackB* selTracks[NMAXPARTICLES];
189  int nTPC = anaUtils::GetAllTracksUsingTPC(event, selTracks);
190 
191  // Cast the box such that we can access nLongTPCTracks, not present in ToyBoxB
192  ToyBoxTutorial* tutBox = static_cast<ToyBoxTutorial*>(&box);
193 
194  // reset to 0
195  tutBox->nLongTPCTracks=0;
196 
197  //loop over tpc tracks
198  for (Int_t i=0;i<nTPC; ++i){
199  AnaTrackB* track = selTracks[i];
200 
201  // Apply the fiducial cut
202  if (!cutUtils::FiducialCut(*track, SubDetId::kFGD1)){
203  continue;
204  }
205 
206  // Gets the longest segment in the closest TPC
208 
209  // Apply the nodes cut
210  if (TPCSegment->NNodes>65) tutBox->nLongTPCTracks++;
211  }
212 
213  return true;
214 }
215 
216 //**************************************************
218 //**************************************************
219 
220  AnaEventB& event = *static_cast<AnaEventB*>(&eventC);
221 
222  // Create the appropriate EventBox if it does not exist yet
223  if (!event.EventBoxes[EventBoxId::kEventBoxTracker])
224  event.EventBoxes[EventBoxId::kEventBoxTracker] = new EventBoxTracker();
225 
226  boxUtils::FillTracksWithTPC(event, static_cast<SubDetId::SubDetEnum>(GetDetectorFV()));
227  boxUtils::FillTracksWithFGD(event, static_cast<SubDetId::SubDetEnum>(GetDetectorFV()));
228  boxUtils::FillTrajsChargedInTPC(event);
229  boxUtils::FillTrajsChargedInFGDAndNoTPC(event, static_cast<SubDetId::SubDetEnum>(GetDetectorFV()));
230 }
231 
232 
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 GetAllTracksUsingTPC(const AnaEventB &event, AnaTrackB *selTracks[])
Int_t NNodes
The number of nodes in the reconstructed object.
bool Apply(AnaEventC &event, ToyBoxB &box) const
void InitializeEvent(AnaEventC &event)
Fill the EventBox with the objects needed by this selection.
virtual const ToyBoxTracker & box(Int_t isel=-1) const
Returns the ToyBoxTracker.
AnaTrackB * HMNtrack
For storing the highest momentum negative track.
Representation of a global track.
bool Apply(AnaEventC &event, ToyBoxB &box) const
AnaEventSummaryC * Summary
A summary of the event with high level quantities.
bool Apply(AnaEventC &event, ToyBoxB &box) const
AnaParticleB * GetSegmentWithMostNodesInClosestTpc(const AnaTrackB &track)
Combined function to address NuMu selection needs as efficiently as possible - gets the TPC segment w...
bool Apply(AnaEventC &event, ToyBoxB &box) const
bool FillEventSummary(AnaEventC &event, Int_t allCutsPassed[])
Fill the event summary information, which is needed by the fitters (BANFF, Mach3) ...
AnaTrueParticleB * GetTrueParticle() const
Return a casted version of the AnaTrueObject associated.
void DefineSteps()
========= These are mandatory functions ==================
Representation of a reconstructed particle (track or shower).
void DefineDetectorFV()
Set detector FV.
bool Apply(AnaEventC &event, ToyBoxB &box) const