13 #include <TDirectoryFile.h>
14 #include <TLorentzVector.h>
16 #include <JANA/JApplication.h>
17 #include <JANA/JEventLoop.h>
22 #include <FCAL/DFCALPhoton.h>
23 #include <BCAL/DBCALPhoton.h>
25 #include <PID/DPhoton.h>
61 gPARMS->SetDefaultParameter(
"MAKE_HBOOK", make_hbook);
62 gPARMS->SetDefaultParameter(
"MAKE_ROOT", make_root);
68 tree =
new TTree(
"t",
"#eta Primakoff events");
69 tree->Branch(
"E",&evt);
80 string hbook_fname =
"eta_ntuple.hbook";
82 cout<<
"Opened "<<hbook_fname<<
" for writing..."<<endl;
88 ntp<<
",E_beam:R,px_beam,py_beam,pz_beam";
89 ntp<<
",E_proton_thrown,px_proton_thrown,py_proton_thrown,pz_proton_thrown";
90 ntp<<
",E_eta_thrown,px_eta_thrown,py_eta_thrown,pz_eta_thrown";
92 ntp<<
",prod_mech:I,decay_mode:I";
94 ntp<<
",E_fcal(Nfcal):R,px_fcal(Nfcal),py_fcal(Nfcal),pz_fcal(Nfcal)";
95 ntp<<
",x_fcal(Nfcal),y_fcal(Nfcal),z_fcal(Nfcal)";
96 ntp<<
",E_eta_best,px_eta_best,py_eta_best,pz_eta_best";
100 ntp<<
",phi_start(Nstart):R,phi_start_diff(Nstart)";
103 ntp<<
",E_bcal(Nbcal):R,phi_bcal(Nbcal),theta_bcal(Nbcal)";
105 hbname(10,
"ETANT", &evt_ntuple, ntp.str().c_str());
108 pthread_mutex_init(&mutex, NULL);
119 vector<const DBeamPhoton*> beam_photons;
120 vector<const DFCALPhoton*> fcalphotons;
121 vector<const DBCALPhoton*> bcalphotons;
122 vector<const DMCThrown*> mcthrowns;
123 vector<const DSCHit*> schits;
125 loop->Get(beam_photons);
126 loop->Get(fcalphotons);
127 loop->Get(bcalphotons);
128 loop->Get(mcthrowns);
132 TLorentzVector target(0.0, 0.0, 0.0, 0.93827);
135 vector<TLorentzVector> rec_photons;
136 vector<TVector3> rec_photons_pos;
137 for(
unsigned int i=0; i<fcalphotons.size(); i++){
138 rec_photons.push_back(fcalphotons[i]->getMom4());
139 rec_photons_pos.push_back(fcalphotons[i]->getPosition());
143 vector<TLorentzVector> rec_bcal_photons;
144 for(
unsigned int i=0; i<bcalphotons.size(); i++){
145 rec_bcal_photons.push_back(bcalphotons[i]->lorentzMomentum());
150 if(beam_photons.size()!=1){
151 cout<<
"Wrong number of DBeamPhoton objects for event "<<eventnumber<<
" ("<<beam_photons.size()<<
"). Skipping."<<endl;
154 TLorentzVector beam_photon = MakeTLorentz(beam_photons[0], 0.0);
159 bool found_eta=
false;
160 for(
unsigned int i=0; i<mcthrowns.size(); i++){
161 if(mcthrowns[i]->pdgtype == 221){
162 eta = MakeTLorentz(mcthrowns[i], 0.54745);
163 vertex = mcthrowns[i]->position();
169 cout<<
"No thrown eta particle found for event "<<eventnumber<<
". Skipping."<<endl;
174 japp->RootWriteLock();
177 evt->event = eventnumber;
178 evt->beam = beam_photon;
179 evt->eta_thrown = eta;
180 evt->proton_thrown = target+beam_photon-eta;
181 evt->vertex = vertex;
184 evt->t = -(beam_photon-eta).M2();
187 for(
unsigned int j=0; j<rec_photons.size(); j++){
188 evt->AddFCAL(rec_photons[j], rec_photons_pos[j]);
192 for(
unsigned int j=0; j<rec_bcal_photons.size(); j++){
193 evt->AddBCAL(rec_bcal_photons[j]);
197 for(
unsigned int j=0; j<rec_photons.size(); j++){
198 for(
unsigned int k=j+1; k<rec_photons.size(); k++){
200 TLorentzVector my_eta = rec_photons[j] + rec_photons[k];
201 if(fabs(evt->eta_best.M()-0.54745)>fabs(my_eta.M()-0.54745))
202 evt->eta_best = my_eta;
207 for(
unsigned int j=0; j<schits.size(); j++){
208 evt->AddSC(schits[j]->sector);
216 if(make_root)tree->Fill();
217 if(make_hbook)FillNtuple();
235 double theta = kd->
momentum().Theta();
237 double px = p*
sin(theta)*cos(phi);
239 double pz = p*cos(theta);
240 double E =
sqrt(mass*mass + p*p);
242 return TLorentzVector(px,py,pz,E);
252 evt_ntuple.event = evt->event;
253 evt_ntuple.E_beam = evt->beam.E();
254 evt_ntuple.px_beam = evt->beam.Px();
255 evt_ntuple.py_beam = evt->beam.Py();
256 evt_ntuple.pz_beam = evt->beam.Pz();
257 evt_ntuple.E_proton_thrown = evt->proton_thrown.E();
258 evt_ntuple.px_proton_thrown = evt->proton_thrown.Px();
259 evt_ntuple.py_proton_thrown = evt->proton_thrown.Py();
260 evt_ntuple.pz_proton_thrown = evt->proton_thrown.Pz();
261 evt_ntuple.E_eta_thrown = evt->eta_thrown.E();
262 evt_ntuple.px_eta_thrown = evt->eta_thrown.Px();
263 evt_ntuple.py_eta_thrown = evt->eta_thrown.Py();
264 evt_ntuple.pz_eta_thrown = evt->eta_thrown.Pz();
265 evt_ntuple.x = evt->vertex.X();
266 evt_ntuple.y = evt->vertex.Y();
267 evt_ntuple.z = evt->vertex.Z();
268 evt_ntuple.prod_mech = evt->prod_mech;
269 evt_ntuple.decay_mode = evt->decay_mode;
270 evt_ntuple.Nfcal = evt->Nfcal;
271 evt_ntuple.E_eta_best = evt->eta_best.E();
272 evt_ntuple.px_eta_best = evt->eta_best.Px();
273 evt_ntuple.py_eta_best = evt->eta_best.Py();
274 evt_ntuple.pz_eta_best = evt->eta_best.Pz();
275 evt_ntuple.M_eta_best = evt->eta_best.M();
276 evt_ntuple.t = evt->t;
277 evt_ntuple.Nstart = evt->Nstart;
278 evt_ntuple.E_bcal_tot = evt->E_bcal_tot;
279 evt_ntuple.Nfcal = evt->Nfcal;
283 for(UInt_t i=0; i<(UInt_t)evt_ntuple.Nfcal; i++){
286 _DBG_<<
"dynamic cast of TClonesArray element "<<i<<
" failed!!"<<endl;
290 evt_ntuple.E_fcal[i] = fcal->
p.E();
291 evt_ntuple.px_fcal[i] = fcal->
p.Px();
292 evt_ntuple.py_fcal[i] = fcal->
p.Py();
293 evt_ntuple.pz_fcal[i] = fcal->
p.Pz();
295 evt_ntuple.x_fcal[i] = fcal->
x.X();
296 evt_ntuple.y_fcal[i] = fcal->
x.Y();
297 evt_ntuple.z_fcal[i] = fcal->
x.Z();
302 for(UInt_t i=0; i<(UInt_t)evt_ntuple.Nstart; i++){
303 sc_t *sc =
dynamic_cast<sc_t*
>((*evt->sc)[i]);
305 _DBG_<<
"dynamic cast of TClonesArray element "<<i<<
" failed!!"<<endl;
310 evt_ntuple.phi_start_diff[i] = sc->
phi_diff;
315 for(UInt_t i=0; i<(UInt_t)evt_ntuple.Nbcal; i++){
318 _DBG_<<
"dynamic cast of TClonesArray element "<<i<<
" failed!!"<<endl;
322 evt_ntuple.E_bcal[i] = bcal->
p.E();
323 evt_ntuple.phi_bcal[i] = bcal->
p.Phi();
324 evt_ntuple.theta_bcal[i] = bcal->
p.Theta();
void hbname(int id, const char *CHBLOK, void *VAR, const char *CHFORM)
void hropen(int lun, char *name, char *filename, char *status, int stor, int istat)
TLorentzVector MakeTLorentz(const DKinematicData *track, double mass)
void hbnt(int id, char *CHTITL, char *CHOPT)
jerror_t evnt(JEventLoop *loop, uint64_t eventnumber)
Invoked via DEventProcessor virtual method.
jerror_t fini(void)
Invoked via DEventProcessor virtual method.
void hrout(int num, int icycle, char *opt)
void hrend(char *filename)
jerror_t erun(void)
Invoked via DEventProcessor virtual method.
jerror_t init(void)
Invoked via DEventProcessor virtual method.
const DVector3 & momentum(void) const