9 #include <TLorentzVector.h>
24 #include "JANA/JApplication.h"
25 #include "JANA/JFactory.h"
54 gPARMS->SetDefaultParameter(
"PI0BCALSKIM:WRITE_EVIO",
WRITE_EVIO );
55 gPARMS->SetDefaultParameter(
"PI0BCALSKIM:MIN_SH1_E" ,
MIN_SH1_E );
56 gPARMS->SetDefaultParameter(
"PI0BCALSKIM:MIN_SH2_E" ,
MIN_SH2_E );
104 vector< const DBCALShower* > locBCALShowers;
105 loop->Get(locBCALShowers);
106 vector< const DTrackTimeBased*> locTrackTimeBased;
107 loop->Get(locTrackTimeBased);
108 vector<const DVertex*> kinfitVertex;
109 loop->Get(kinfitVertex);
112 loop->GetSingle(locEventWriterEVIO);
114 vector< const JObject* > locObjectsToSave;
131 if(locBCALShowers.size() < 2 )
return NOERROR;
133 vector<const DTrackFitter*>fitters;
136 if(fitters.size()<1){
137 _DBG_<<
"Unable to get a DTrackFinder object!"<<endl;
138 return RESOURCE_UNAVAILABLE;
143 bool Candidate =
false;
144 double sh1_E, sh2_E, inv_mass, kinfitVertexZ=0.0, kinfitVertexX=0.0, kinfitVertexY=0.0;
145 vector <const DBCALShower *> matchedShowers;
147 for(
unsigned int i = 0 ; i < locTrackTimeBased.size() ; ++i)
149 vector<DTrackFitter::Extrapolation_t>extrapolations=locTrackTimeBased[i]->extrapolations.at(
SYS_BCAL);
150 if (extrapolations.size()>0){
151 for(
unsigned int j = 0 ; j < locBCALShowers.size() ; ++j)
153 double x = locBCALShowers[j]->x;
154 double y = locBCALShowers[j]->y;
155 double z = locBCALShowers[j]->z;
158 double R = pos_bcal.Perp();
166 double dPhi =mypos.Phi()-pos_bcal.Phi();
167 if (dPhi< -M_PI) dPhi+=2.*M_PI;
168 if (dPhi> M_PI) dPhi-=2.*M_PI;
169 double dZ = TMath::Abs(mypos.Z() - z);
170 if(dZ < 30.0 && fabs(dPhi) < 0.18) {
171 matchedShowers.push_back(locBCALShowers[j]);
181 vector<const DEventRFBunch*> locEventRFBunches;
182 loop->Get(locEventRFBunches);
183 if(locEventRFBunches.size() > 0) {
184 locObjectsToSave.push_back(static_cast<const JObject *>(locEventRFBunches[0]));
187 for (
unsigned int i = 0 ; i < kinfitVertex.size(); i++)
191 locObjectsToSave.push_back(static_cast<const JObject *>(kinfitVertex[0]));
193 kinfitVertexX = kinfitVertex[i]->dSpacetimeVertex.X();
194 kinfitVertexY = kinfitVertex[i]->dSpacetimeVertex.Y();
195 kinfitVertexZ = kinfitVertex[i]->dSpacetimeVertex.Z();
199 for(
unsigned int i=0; i<locBCALShowers.size() ; i++)
201 if (find(matchedShowers.begin(), matchedShowers.end(),locBCALShowers[i]) != matchedShowers.end())
continue;
202 sh1_E = locBCALShowers[i]->E_raw;
204 double sh1_x = s1->
x - kinfitVertexX ;
205 double sh1_y = s1->
y - kinfitVertexY ;
206 double sh1_z = s1->
z - kinfitVertexZ ;
207 double sh1_R =
sqrt(sh1_x*sh1_x+sh1_y*sh1_y+sh1_z*sh1_z);
208 TLorentzVector sh1_p(sh1_E*sh1_x/sh1_R,sh1_E*sh1_y/sh1_R,sh1_E*sh1_z/sh1_R,sh1_E);
209 for(
unsigned int j = i+1 ; j < locBCALShowers.size() ; j++)
211 if (find(matchedShowers.begin(), matchedShowers.end(),locBCALShowers[j]) != matchedShowers.end())
continue;
213 sh2_E = locBCALShowers[j]->E_raw;
214 double sh2_x = s2->
x - kinfitVertexX;
215 double sh2_y = s2->
y - kinfitVertexY;
216 double sh2_z = s2->
z - kinfitVertexZ;
217 double sh2_R =
sqrt(sh2_x*sh2_x + sh2_y*sh2_y + sh2_z*sh2_z);
218 TLorentzVector sh2_p(sh2_E*sh2_x/sh2_R,sh2_E*sh2_y/sh2_R,sh2_E*sh2_z/sh2_R,sh2_E);
219 TLorentzVector ptot = sh1_p+sh2_p;
221 Candidate |= ( (sh2_E>0.4) && (inv_mass<0.25) && (inv_mass>0.05));
222 if((sh2_E>0.4) && (inv_mass<0.25) && (inv_mass>0.05)) {
223 if(find(locObjectsToSave.begin(), locObjectsToSave.end(), locBCALShowers[i]) == locObjectsToSave.end())
224 locObjectsToSave.push_back(static_cast<const JObject *>(locBCALShowers[i]));
225 if(find(locObjectsToSave.begin(), locObjectsToSave.end(), locBCALShowers[j]) == locObjectsToSave.end())
226 locObjectsToSave.push_back(static_cast<const JObject *>(locBCALShowers[j]));
234 locEventWriterEVIO->
Write_EVIOEvent( loop,
"pi0bcalskim", locObjectsToSave );
jerror_t init(void)
Called once at program start.
bool ExtrapolateToRadius(double R, const vector< Extrapolation_t > &extraps, DVector3 &pos, DVector3 &mom, double &t, double &s) const
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
The DTrackFitter class is a base class for different charged track fitting algorithms. It does not actually fit the track itself, but provides the interface and some common support features most algorthims will need to implement.
JEventProcessor_pi0bcalskim()
jerror_t fini(void)
Called after last event of last event source has been processed.
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
~JEventProcessor_pi0bcalskim()
bool Write_EVIOEvent(JEventLoop *locEventLoop, string locOutputFileNameSubString) const
const DTrackFitter * fitter