// $Id$ // // File: JEventProcessor_swimToTOF.cc // Created: Mon Jun 27 10:45:16 EDT 2016 // Creator: davidl (on Darwin harriet.jlab.org 15.5.0 i386) // #include #include using namespace std; #include "JEventProcessor_swimToTOF.h" using namespace jana; #include #include #include #include #include // Routine used to create our JEventProcessor #include #include extern "C"{ void InitPlugin(JApplication *app){ InitJANAPlugin(app); app->AddProcessor(new JEventProcessor_swimToTOF(), true); } } // "C" DApplication *dapp = NULL; DGeometry *geom = NULL; DMagneticFieldMap *bfield = NULL; double ZTOF = 0.0; mutex mtx; ofstream *ofs = NULL; //------------------ // JEventProcessor_swimToTOF (Constructor) //------------------ JEventProcessor_swimToTOF::JEventProcessor_swimToTOF() { ofs = new ofstream("proj_tof.dat"); } //------------------ // ~JEventProcessor_swimToTOF (Destructor) //------------------ JEventProcessor_swimToTOF::~JEventProcessor_swimToTOF() { if(ofs) delete ofs; } //------------------ // init //------------------ jerror_t JEventProcessor_swimToTOF::init(void) { // This is called once at program startup. return NOERROR; } //------------------ // brun //------------------ jerror_t JEventProcessor_swimToTOF::brun(JEventLoop *eventLoop, int32_t runnumber) { dapp = (DApplication*)japp; geom = dapp->GetDGeometry(runnumber); bfield = dapp->GetBfield(runnumber); vector z_tof; geom->GetTOFZ(z_tof); ZTOF = 0.0; for(auto z : z_tof) ZTOF += z/(double)z_tof.size(); cout << "ZTOF = " << ZTOF << endl; return NOERROR; } //------------------ // evnt //------------------ jerror_t JEventProcessor_swimToTOF::evnt(JEventLoop *loop, uint64_t eventnumber) { vector mcthrowns; loop->Get(mcthrowns); DReferenceTrajectory rt(bfield); rt.SetDGeometry(geom); double pipx = 0.0; double pipy = 0.0; double pimx = 0.0; double pimy = 0.0; for(auto thrown : mcthrowns){ DVector3 pos(thrown->position()); DVector3 mom(thrown->momentum()); double q = thrown->charge(); // pos.Print(); rt.Swim(pos, mom, q); DVector3 origin(0.0, 0.0, ZTOF); DVector3 norm(0.0, 0.0, -1.0); rt.GetIntersectionWithPlane(origin, norm, pos); if(q==+1.0){ pipx = pos.x(); pipy = pos.y(); }else{ pimx = pos.x(); pimy = pos.y(); } // pos.Print(); // _DBG__; } lock_guard lck(mtx); (*ofs) << pipx << " " << pipy << " " << pimx << " " << pimy << endl; // // japp->RootFillLock(this); // ... fill historgrams or trees ... // japp->RootFillUnLock(this); return NOERROR; } //------------------ // erun //------------------ jerror_t JEventProcessor_swimToTOF::erun(void) { // This is called whenever the run number changes, before it is // changed to give you a chance to clean up before processing // events from the next run number. return NOERROR; } //------------------ // fini //------------------ jerror_t JEventProcessor_swimToTOF::fini(void) { // Called before program exit after event processing is finished. return NOERROR; }