// $Id$ // // File: JEventProcessor_fmwpc_projection.cc // Created: Fri Jul 21 08:31:02 EDT 2017 // Creator: davidl (on Linux gluon112.jlab.org 2.6.32-642.3.1.el6.x86_64 x86_64) // #include "JEventProcessor_fmwpc_projection.h" using namespace jana; #include #include #include #include // Routine used to create our JEventProcessor #include #include extern "C"{ void InitPlugin(JApplication *app){ InitJANAPlugin(app); app->AddProcessor(new JEventProcessor_fmwpc_projection()); } } // "C" // This class is here merely so we can set the zmax_track_boundary // protected member of DReferenceTrajectory. class CPPReferenceTrajectory:public DReferenceTrajectory { public: CPPReferenceTrajectory(const DReferenceTrajectory& rt):DReferenceTrajectory(rt){} void SetZmax(double zmax){ zmax_track_boundary = zmax; } }; //------------------ // JEventProcessor_fmwpc_projection (Constructor) //------------------ JEventProcessor_fmwpc_projection::JEventProcessor_fmwpc_projection() { // These are the z coordinates of the FMWPC wire // planes in the lab frame. These will differ // depending on the Iron absorber thicknesses. // // The z_fmwpc_mother value is obtained from // $HDDS_HOME/cpp_HDDS.xml where the "ForwardMWPC" // volume is placed. // // The other values are relative to this and are // from the $HDDS_HOME/ForwardMWPC_HDDS.xml // where each of the CPPChamber volumes are placed. double z_fmwpc_mother = 925.406; z_fmwpc.push_back( z_fmwpc_mother + 9.96 ); z_fmwpc.push_back( z_fmwpc_mother + 23.13 ); z_fmwpc.push_back( z_fmwpc_mother + 36.3 ); z_fmwpc.push_back( z_fmwpc_mother + 50.82 ); z_fmwpc.push_back( z_fmwpc_mother + 67.84 ); z_fmwpc.push_back( z_fmwpc_mother + 91.46 ); z_fmwpc.push_back( z_fmwpc_mother + 189.53 ); z_fmwpc.push_back( z_fmwpc_mother + 197.15 ); } //------------------ // ~JEventProcessor_fmwpc_projection (Destructor) //------------------ JEventProcessor_fmwpc_projection::~JEventProcessor_fmwpc_projection() { } //------------------ // init //------------------ jerror_t JEventProcessor_fmwpc_projection::init(void) { // This is called once at program startup. return NOERROR; } //------------------ // brun //------------------ jerror_t JEventProcessor_fmwpc_projection::brun(JEventLoop *eventLoop, int32_t runnumber) { // This is called whenever the run number changes return NOERROR; } //------------------ // evnt //------------------ jerror_t JEventProcessor_fmwpc_projection::evnt(JEventLoop *loop, uint64_t eventnumber) { // This is called for every event. Use of common resources like writing // to a file or filling a histogram should be mutex protected. Using // loop->Get(...) to get reconstructed objects (and thereby activating the // reconstruction algorithm) should be done outside of any mutex lock // since multiple threads may call this method at the same time. // Here's an example: // // vector mydataclasses; // loop->Get(mydataclasses); // // japp->RootFillLock(this); // ... fill historgrams or trees ... // japp->RootFillUnLock(this); // The following 2 lines will cause the tracking reconstruction // to be done. The results will be a set of DTrackTimeBased // objects and the "tbts" container will have pointers to all // of them. vector tbts; loop->Get(tbts); // Loop over all reconstructed tracks for(auto tbt : tbts){ // The following selects only the charged pion hypothesis // tracks. When charged particle track reconstruction is // done, we don't know what type of particle made the track // so we fit the data with 4 different hypotheses (beta, pion, // Kaon, proton). For CPP, only pions and muons are of interest. // Because pions and muons are close enough in mass, the tracking // results won't differ significantly for muons so we just use // the pion hypothesis results for those. if( (tbt->PID()!=PiPlus) && (tbt->PID()!=PiMinus) ) continue; // A reconstructed track includes a DReferenceTrajectory object. // This is a long list of points along the trajectory of the // track. The DReferenceTrajectory object has methods that allow // us to ask things like "where does this trajectory cross // this plane". auto rt = tbt->rt; // Unfortunately, the default reconstruction has // a limit of z=670 to where it swims the trajctory to. We need // to swim it out to at least the last FMWPC plane which is // at about z=1130. Thus, we need to create our own // DReferenceTrajectory object and set a larger limit and then // re-swim. CPPReferenceTrajectory *myrt = new CPPReferenceTrajectory(*rt); myrt->SetZmax( 1130.0 ); myrt->Swim(rt->swim_steps[0].origin, rt->swim_steps[0].mom); // Loop over FMWPC wire planes and project track to each int layer =0; for( double z : z_fmwpc ){ layer++; // keep track of plane ("layer") number 1-8 // Define plane for this chamber. We define it by giving // a point on the plane and a unit vector normal to the // plane. (n.b. you could equally well define the "norm" // vector to be (0.0, 0.0, +1.0) ) DVector3 origin(0.0, 0.0, z); DVector3 norm(0.0, 0.0, -1.0); DVector3 pos; if( NOERROR == myrt->GetIntersectionWithPlane(origin, norm, pos)){ // At this point, layer will contain which FMWPC chamber // we projected to (1-8) and pos will contain the point // on that plane the track projects to. Here is where you // would put code to write this information out to a file // or do something else with it here. Most likely this // plugin would be merged with the cppmva plugin so you // could use this position to limit which hits get written // to the TTree used in the Multi-variate Analysis. // // For now, we just print to the screen. cout << eventnumber << " : layer " << layer << " : (x,y,z) = (" << pos.X() << ", " << pos.Y() << ", " << pos.Z() << ")" << endl; } } delete myrt; } return NOERROR; } //------------------ // erun //------------------ jerror_t JEventProcessor_fmwpc_projection::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_fmwpc_projection::fini(void) { // Called before program exit after event processing is finished. return NOERROR; }