18 #include <TDirectoryFile.h>
19 #include <TLorentzVector.h>
23 #include <JANA/JApplication.h>
24 #include <JANA/JEventLoop.h>
29 #include <PID/DParticleSet.h>
30 #include <PID/DPhysicsEvent.h>
34 return a.
p.E()<b.
p.E();
51 pthread_mutex_init(&mutex, NULL);
68 TDirectory *
dir = (TDirectory*)gROOT->FindObject(
"PHYSICS");
69 if(!dir)dir =
new TDirectoryFile(
"PHYSICS",
"PHYSICS");
76 tree_thrwn =
new TTree(
"thrown",
"Thrown Event parameters");
77 tree_recon =
new TTree(
"recon",
"Reconstructed Event parameters");
80 evt_thrown =
new Event();
81 evt_recon =
new Event();
82 tree_thrwn->Branch(
"T",&evt_thrown);
83 tree_recon->Branch(
"R",&evt_recon);
86 TTree *evt =
new TTree(
"evt",
"Thrown and Reconstructed Event parameters");
87 evt->AddFriend(
"tree_thrwn");
88 evt->AddFriend(
"tree_recon");
110 vector<const DBeamPhoton*> beam_photons;
111 vector<const DMCThrown*> mcthrowns;
112 vector<const DPhysicsEvent*> physicsevents;
114 loop->Get(beam_photons);
115 loop->Get(mcthrowns);
116 loop->Get(physicsevents);
118 TVector3 VertexRec, VertexGen;
119 VertexGen = TVector3(mcthrowns[0]->position().
X(),mcthrowns[0]->position().Y(),mcthrowns[0]->position().Z());
121 TLorentzVector beam_photon(0.0, 0.0, 9.0, 9.0);
122 if(beam_photons.size()>0){
124 beam_photon.SetPxPyPzE(lv.Px(), lv.Py(), lv.Pz(), lv.E());
128 TLorentzVector target(0.0, 0.0, 0.0, 0.93827);
132 const DPhysicsEvent *physicsevent = NULL;
134 for(
unsigned int i=0; i<physicsevents.size(); i++){
135 if(physicsevents[i]->particle_sets.size()==0)
continue;
136 const DParticleSet *ps = physicsevents[i]->particle_sets[0];
137 int Nparts = ps->pip.size() + ps->pim.size()
138 + ps->photon.size() + ps->proton.size()
139 + ps->Kp.size() + ps->Km.size()
140 + ps->otherp.size() + ps->othern.size()
141 + ps->otherz.size() + ps->neutron.size();
142 if(Nparts>max_parts || physicsevents[i]==NULL){
143 physicsevent = physicsevents[i];
146 VertexRec.SetX(ps->vertex->dSpacetimeVertex.X());
147 VertexRec.SetY(ps->vertex->dSpacetimeVertex.Y());
148 VertexRec.SetZ(ps->vertex->dSpacetimeVertex.Z());
154 if (physicsevent!=NULL){
155 const DParticleSet *
particle_set=physicsevent->particle_sets[0];
156 for(
unsigned int j=0; j<particle_set->photon.size(); j++){
158 rec.
photons.push_back(MakeParticle(particle_set->photon[j]->dNeutralParticleHypotheses[0], 0.0));
160 for(
unsigned int j=0; j<particle_set->neutron.size(); j++){
162 rec.
neutrons.push_back(MakeParticle(particle_set->neutron[j]->dNeutralParticleHypotheses[0], 0.939565));
164 for(
unsigned int j=0; j<particle_set->pip.size(); j++){
166 rec.
piplus.push_back(MakeParticle(particle_set->pip[j]->dChargedTrackHypotheses[0], 0.13957));
168 for(
unsigned int j=0; j<particle_set->pim.size(); j++){
170 rec.
piminus.push_back(MakeParticle(particle_set->pim[j]->dChargedTrackHypotheses[0], 0.13957));
172 for(
unsigned int j=0; j<particle_set->proton.size(); j++){
174 rec.
protons.push_back(MakeParticle(particle_set->proton[j]->dChargedTrackHypotheses[0], 0.93827));
176 for(
unsigned int j=0; j<particle_set->Kp.size(); j++){
178 rec.
Kplus.push_back(MakeParticle(particle_set->Kp[j]->dChargedTrackHypotheses[0], 0.493677));
180 for(
unsigned int j=0; j<particle_set->Km.size(); j++){
182 rec.
Kminus.push_back(MakeParticle(particle_set->Km[j]->dChargedTrackHypotheses[0], 0.493677));
187 bool all_mesons_fiducial =
true;
188 bool all_photons_fiducial =
true;
189 bool all_neutrons_fiducial =
true;
190 bool all_protons_fiducial =
true;
192 for(
unsigned int k=0; k<mcthrowns.size(); k++){
193 switch(mcthrowns[k]->type){
195 all_photons_fiducial &= IsFiducial(mcthrowns[k]);
198 all_mesons_fiducial &= IsFiducial(mcthrowns[k]);
201 all_mesons_fiducial &= IsFiducial(mcthrowns[k]);
204 all_mesons_fiducial &= IsFiducial(mcthrowns[k]);
207 all_mesons_fiducial &= IsFiducial(mcthrowns[k]);
210 all_neutrons_fiducial &= IsFiducial(mcthrowns[k]);
213 all_protons_fiducial &= IsFiducial(mcthrowns[k]);
219 japp->RootWriteLock();
225 FillEvent(evt_recon, rec, thr);
226 FillEvent(evt_thrown, thr, rec);
229 bool all_fiducial = all_mesons_fiducial && all_photons_fiducial && all_protons_fiducial && all_neutrons_fiducial;
230 evt_recon->all_fiducial = all_fiducial;
231 evt_recon->all_mesons_fiducial = all_mesons_fiducial;
232 evt_recon->all_photons_fiducial = all_photons_fiducial;
233 evt_recon->all_neutrons_fiducial = all_neutrons_fiducial;
234 evt_recon->all_protons_fiducial = all_protons_fiducial;
235 evt_recon->vertex = VertexRec;
237 evt_thrown->all_fiducial = all_fiducial;
238 evt_thrown->all_mesons_fiducial = all_mesons_fiducial;
239 evt_thrown->all_photons_fiducial = all_photons_fiducial;
240 evt_thrown->all_neutrons_fiducial = all_neutrons_fiducial;
241 evt_thrown->all_protons_fiducial = all_protons_fiducial;
242 evt_thrown->vertex = VertexGen;
245 evt_recon->event = eventnumber;
246 evt_thrown->event = eventnumber;
269 double theta = kd->
momentum().Theta();
271 double px = p*
sin(theta)*cos(phi);
273 double pz = p*cos(theta);
274 double E =
sqrt(mass*mass + p*p);
280 part.
p.SetPxPyPzE(px,py,pz,E);
281 part.
x.SetXYZ(x, y, z);
299 part.
chisq = locChargedTrackHypothesis->dChiSq;
300 part.
Ndof = locChargedTrackHypothesis->dNDF;
301 part.
FOM_pid = locChargedTrackHypothesis->dFOM;
315 part.
chisq = locNeutralParticleHypothesis->dChiSq;
316 part.
Ndof = locNeutralParticleHypothesis->dNDF;
317 part.
FOM_pid = locNeutralParticleHypothesis->dFOM;
329 vector<Particle> &neutron = pset.
neutrons;
330 vector<Particle> &pip = pset.
piplus;
331 vector<Particle> &pim = pset.
piminus;
332 vector<Particle> &Kp = pset.
Kplus;
333 vector<Particle> &Km = pset.
Kminus;
334 vector<Particle> &proton = pset.
protons;
336 vector<Particle> &photon_match = pset_match.
photons;
337 vector<Particle> &neutron_match = pset_match.
neutrons;
338 vector<Particle> &pip_match = pset_match.
piplus;
339 vector<Particle> &pim_match = pset_match.
piminus;
340 vector<Particle> &Kp_match = pset_match.
Kplus;
341 vector<Particle> &Km_match = pset_match.
Kminus;
342 vector<Particle> &proton_match = pset_match.
protons;
354 for(
unsigned int i=0; i<photon.size(); i++){
357 *prt_match = FindBestMatch(photon[i], photon_match);
359 TClonesArray &prts = *(evt->
photon);
365 for(
unsigned int i=0; i<neutron.size(); i++){
368 *prt_match = FindBestMatch(neutron[i], neutron_match);
370 TClonesArray &prts = *(evt->
neutron);
376 for(
unsigned int i=0; i<pip.size(); i++){
377 TClonesArray &prts_match = *(evt->
pip_match);
379 *prt_match = FindBestMatch(pip[i], pip_match);
381 TClonesArray &prts = *(evt->
pip);
387 for(
unsigned int i=0; i<pim.size(); i++){
388 TClonesArray &prts_match = *(evt->
pim_match);
390 *prt_match = FindBestMatch(pim[i], pim_match);
392 TClonesArray &prts = *(evt->
pim);
398 for(
unsigned int i=0; i<Kp.size(); i++){
399 TClonesArray &prts_match = *(evt->
Kp_match);
401 *prt_match = FindBestMatch(Kp[i], Kp_match);
403 TClonesArray &prts = *(evt->
Kp);
409 for(
unsigned int i=0; i<Km.size(); i++){
410 TClonesArray &prts_match = *(evt->
Km_match);
412 *prt_match = FindBestMatch(Km[i], Km_match);
414 TClonesArray &prts = *(evt->
Km);
420 for(
unsigned int i=0; i<proton.size(); i++){
423 *prt_match = FindBestMatch(proton[i], proton_match);
425 TClonesArray &prts = *(evt->
proton);
431 for(
unsigned int i=0; i<photon.size(); i++)evt->
W += photon[i].p;
432 for(
unsigned int i=0; i<neutron.size(); i++)evt->
W += neutron[i].p;
433 for(
unsigned int i=0; i<pip.size(); i++)evt->
W += pip[i].p;
434 for(
unsigned int i=0; i<pim.size(); i++)evt->
W += pim[i].p;
435 for(
unsigned int i=0; i<Kp.size(); i++)evt->
W += Kp[i].p;
436 for(
unsigned int i=0; i<Km.size(); i++)evt->
W += Km[i].p;
447 double max_fom = 0.1;
449 best_match.
p.SetXYZT(0.0, 0.0, 0.0, 0.0);
450 for(
unsigned int i=0; i<secondaries.size(); i++){
451 double fom = GetFOM(primary, secondaries[i]);
454 best_match = secondaries[i];
480 double epsilon = 1.0E-6;
482 double curature_a = 1.0/a.
p.P();
483 double curature_b = 1.0/b.
p.P();
484 double curvature_diff = fabs(curature_a - curature_b);
485 double curvature_fom = 1.0/(curvature_diff + epsilon);
487 double theta_rel = fabs(a.
p.Angle(b.
p.Vect()));
488 double theta_fom = 1.0/(theta_rel + epsilon);
490 double fom = curvature_fom*theta_fom;
500 double theta_degrees = kd->
momentum().Theta()*TMath::RadToDeg();
505 if(theta_degrees<2.0 || theta_degrees>110.0)
return false;
506 if(p<0.100)
return false;
509 if(theta_degrees<1.0 || theta_degrees>120.0)
return false;
510 if(p<0.400)
return false;
TClonesArray * proton_match
Closest match proton (truth or recon, whatever is not in proton)
Particle MakeParticle(const DKinematicData *kd, double mass)
bool IsFiducial(const DKinematicData *kd)
jerror_t fini(void)
Called after last event of last event source has been processed.
vector< Particle > Kminus
const DVector3 & position(void) const
vector< Particle > photons
TClonesArray * Km_match
Closest match K- (truth or recon, whatever is not in Km)
Particle FindBestMatch(const Particle &primary, vector< Particle > &secondaries)
jerror_t evnt(JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
TLorentzVector DLorentzVector
TClonesArray * pip_match
Closest match pi+ (truth or recon, whatever is not in pip)
jerror_t brun(JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
vector< Particle > piminus
TClonesArray * pim_match
Closest match pi- (truth or recon, whatever is not in pim)
jerror_t init(void)
Called once at program start.
double charge(void) const
vector< Particle > protons
const DVector3 & momentum(void) const
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
DEventProcessor_phys_tree()
double GetFOM(const Particle &a, const Particle &b) const
TClonesArray * neutron_match
Closest match neutron (truth or recon, whatever is not in neutron)
vector< Particle > piplus
void FillEvent(Event *evt, particle_set &pset, particle_set &pset_match)
~DEventProcessor_phys_tree()
static bool CompareLorentzEnergy(const Particle &a, const Particle &b)
TClonesArray * Kp_match
Closest match K+ (truth or recon, whatever is not in Kp)
TClonesArray * photon_match
Closest match photon (truth or recon, whatever is not in photon)
vector< Particle > neutrons