HighLAND
p0dExampleSelection.cxx
1 #include "p0dExampleSelection.hxx"
2 #include "baseSelection.hxx"
3 #include "DataClasses.hxx"
4 #include "CutUtils.hxx"
5 #include "SubDetId.hxx"
6 #include "EventBoxUtils.hxx"
7 #include "P0DAnalysisUtils.hxx"
8 
9 
10 bool _debug=false;
11 bool _isUsingReconDirP0D=false;
12 bool _isUsingReconDirP0DNew=false;
13 
14 //**********************************************************************
15 p0dExampleSelection::p0dExampleSelection(bool forceBreak): SelectionBase(forceBreak,EventBoxId::kEventBoxP0D) {
16 //**********************************************************************
17 
18  // Minimum accum level to save event into the output Micro-trees
19  _debug = ND::params().GetParameterI("baseP0DAnalysis.Example.DebugSelection");
20 
21  // for whether or not P0D Recon directory variables are read
22  _isUsingReconDirP0D = ND::params().GetParameterI("highlandIO.FlatTree.UseReconDirP0D");
23 
24  // for whether or not P0D Recon directory variables are read
25  _isUsingReconDirP0DNew = ND::params().GetParameterI("highlandIO.P0DDataClasses.UseReconDirP0DNew");
26 
27 }
28 
29 //************************************************************************
31 //************************************************************************
32  SetDetectorFV(SubDetId::kP0D);
33 }
34 
35 //************************************************************************
37 //************************************************************************
38 
39  // Cuts must be added in the right order
40  // last "true" means the step sequence is broken if cut is not passed (default is "false")
41  AddStep(StepBase::kCut, "event quality", new EventQualityCut(), true); // from baseSelection in psycheSelections
42  AddStep(StepBase::kAction, "count showers/tracks",new CountTracksAndShowersAction());
43  AddStep(StepBase::kAction, "find true vertex", new FindTrueVertexAction());
44  AddStep(StepBase::kCut, "2 showers", new TwoShowersCut());
45  AddStep(StepBase::kCut, "0 tracks", new NoTracksCut());
46  AddStep(StepBase::kCut, "0 michel electrons", new NoMichelElectronsCut());
47 
48  // This is mandatory. An alias should be given to each of the branches
49  SetBranchAlias(0,"trunk");
50 }
51 
52 //************************************************************************
54 //************************************************************************
55 
56  //Create the appropriate EventBox if it does not exist yet
57 
58  // The code below is currently not needed !!!!
59 
60  AnaEventB& event = *static_cast<AnaEventB*>(&eventC);
61 
62  if(!event.EventBoxes[EventBoxId::kEventBoxP0D])
63  event.EventBoxes[EventBoxId::kEventBoxP0D] = new EventBoxP0D2();
64 
65  boxP0DUtils::FillVerticesFinal(event);
66  boxP0DUtils::FillP0DParticles(event);
67 }
68 
69 //***********************************************************************
71 //***********************************************************************
72 
73  // downcast the AnaEventC to AnaEventB
74  AnaEventB& event = *static_cast<AnaEventB*>(&eventC);
75 
76  // downcast the box to the appropriate type
77  ToyBoxP0D* p0dBox = static_cast<ToyBoxP0D*>(&box);
78 
79  if (_isUsingReconDirP0DNew){
80  // Get the relevant EventBox. No need to downcast since we only want things in the base class
81  EventBoxB* EventBox = event.EventBoxes[EventBoxId::kEventBoxP0D];
82 
83  p0dBox->nShowers = EventBox->nRecObjectsInGroup[EventBoxP0D2::kP0DShowers];
84  p0dBox->nTracks = EventBox->nRecObjectsInGroup[EventBoxP0D2::kP0DTracks];
85 
86  if (p0dBox->nShowers>0) p0dBox->Shower1 = static_cast<AnaP0DParticle*>(EventBox->RecObjectsInGroup[EventBoxP0D2::kP0DShowers][0]);
87  if (p0dBox->nShowers>1) p0dBox->Shower2 = static_cast<AnaP0DParticle*>(EventBox->RecObjectsInGroup[EventBoxP0D2::kP0DShowers][1]);
88  }
89  else if (_isUsingReconDirP0D){
90  AnaLocalReconEvent* localEvent = static_cast<AnaLocalReconEvent*>(&event);
91  for(std::vector<AnaP0DReconVertex*>::iterator it =localEvent->P0DReconVertices.begin(); it!= localEvent->P0DReconVertices.end(); ++it ){
92  if (_debug)
93  std::cout << "P0DReconVertices:AlgorithmName : " << (*it)->AlgorithmName << " Cycle: " << (*it)->Cycle
94  << " Bunch: " << (*it)->Bunch << std::endl;
95 
96  Int_t i=0;
97  for(std::vector<AnaP0DReconParticle*>::iterator it2 =(*it)->ParticlesP.begin(); it2!= (*it)->ParticlesP.end(); ++it2, i++ ){
98  if (_debug)
99  std::cout << " - " << i << ": P0DReconParticles:AlgorithmName : " << (*it2)->AlgorithmName << " Cycle: " << (*it2)->Cycle
100  << " Bunch: " << (*it2)->Bunch << " p = " << (*it2)->Momentum << " E = " << (*it2)->EDeposit << " l = " << (*it2)->Length
101  << " nShowers = " << (*it2)->Showers.size() << " nTracks = " << (*it2)->Tracks.size() << std::endl;
102 
103  if ((*it2)->AlgorithmName.find("Shower")!=std::string::npos){
104  p0dBox->nShowers++;
105  }
106  }
107  if (_debug)
108  std::cout << "NShowers = " << p0dBox->nShowers << std::endl;
109  }
110  }
111 
112  // Return value is ignored for actions
113  return true;
114 }
115 
116 //***********************************************************************
117 bool TwoShowersCut::Apply(AnaEventC& eventC, ToyBoxB& box) const {
118 //***********************************************************************
119 
120  (void) eventC;
121 
122  // downcast the box to the appropriate type
123  ToyBoxP0D* p0dBox = static_cast<ToyBoxP0D*>(&box);
124 
125  // Two showers
126  return (p0dBox->nShowers==2);
127 }
128 
129 //***********************************************************************
130 bool NoTracksCut::Apply(AnaEventC& eventC, ToyBoxB& box) const {
131 //***********************************************************************
132 
133  (void) eventC;
134 
135  // downcast the box to the appropriate type
136  ToyBoxP0D* p0dBox = static_cast<ToyBoxP0D*>(&box);
137 
138  // No Tracks
139  return (p0dBox->nTracks==0);
140 }
141 
142 //***********************************************************************
144 //***********************************************************************
145 
146  (void) box;
147 
148  // downcast the AnaEventC to AnaEventB
149  AnaEventB& event = *static_cast<AnaEventB*>(&eventC);
150 
151 
152  // No Tracks
153  return (static_cast<AnaEvent*>(&event)->nDelayedClusters==0);
154 }
155 
156 //***********************************************************************
158 //***********************************************************************
159 
160  (void) eventC;
161 
162  // downcast the box to the appropriate type
163  ToyBoxP0D* p0dBox = static_cast<ToyBoxP0D*>(&box);
164 
165  if (_isUsingReconDirP0DNew){
166  if (p0dBox->Shower1 && p0dBox->Shower1->GetTrueParticle())
167  p0dBox->TrueVertex = p0dBox->Shower1->GetTrueParticle()->TrueVertex;
168  }
169  /*
170  else if (_isUsingReconDirP0D){
171  AnaLocalReconEvent* localEvent = static_cast<AnaLocalReconEvent*>(&event);
172  if (localEvent->P0DReconVertices.size()>0)
173  box.TrueVertex = localEvent->P0DReconVertices[0]->TrueVertex
174 
175  }
176  */
177 
178  return true;
179 }
AnaTrueVertexB * TrueVertex
Pointer to the AnaTrueVertexB of the interaction that created this AnaTrueParticleB.
bool Apply(AnaEventC &event, ToyBoxB &box) const
int GetParameterI(std::string)
Get parameter. Value is returned as integer.
Definition: Parameters.cxx:217
void DefineSteps()
Define all steps in the selection.
bool Apply(AnaEventC &event, ToyBoxB &box) const
AnaTrueVertexB * TrueVertex
For storing the true vertex, for analyses with no reconstructed primary vertex.
Definition: ToyBoxND280.hxx:22
virtual const ToyBoxP0D & box(Int_t isel=-1) const
Returns the ToyBoxP0D.
Int_t nRecObjectsInGroup[NMAXRECOBJECTGROUPS]
----—— RecObjects and TrueRecObjects used in the selection and systematics ------------—— ...
bool Apply(AnaEventC &event, ToyBoxB &box) const
Int_t Bunch
The index of this bunch (0-7).
bool Apply(AnaEventC &event, ToyBoxB &box) const
void InitializeEvent(AnaEventC &event)
Fill the EventBox with the objects needed by this 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.
bool Apply(AnaEventC &event, ToyBoxB &box) const
void DefineDetectorFV()
Define the detector Fiducial Volume in which this selection is applied.