// $Id$ // // File: DPhysicsEvent_factory.cc // Created: Wed Aug 4 10:37:55 EDT 2010 // Creator: davidl (on Darwin eleanor.jlab.org 10.4.0 i386) // #include #include using namespace std; #include #include #include #include "DPhysicsEvent_factory.h" using namespace jana; //------------------ // init //------------------ jerror_t DPhysicsEvent_factory::init(void) { return NOERROR; } //------------------ // brun //------------------ jerror_t DPhysicsEvent_factory::brun(jana::JEventLoop *eventLoop, int runnumber) { // This is not a strict limit. Rather, it is the size the pool will be reduced // to if it has grown larger on the previous event and the current event does // not require this many. This prevents memory-leak-like behavior when running // many threads where each thread keeps allocating bigger and bigger pools as // it comes across slightly busier and busier events. MAX_PARTINFOS = 10; Nbinst = 600; tmin = -100.0; tmax = 500.0; Nbinsz = 50; zmin = 0.0; zmax = 100.0; MAKE_ROOT_HISTOS = false; gPARMS->SetDefaultParameter("PHYSICS:MAKE_ROOT_HISTOS", MAKE_ROOT_HISTOS); return NOERROR; } //------------------ // evnt //------------------ jerror_t DPhysicsEvent_factory::evnt(JEventLoop *loop, int eventnumber) { // Create a 2-D histogram of time vs. z-position for each particle // at the vertex position. All histos will be added and any maximum // found in the sum will be used to identify particles belonging // to the group. Remaining particles will have their histos added // and the process repeated until all groups are found. // Get reconstructed charged particles and photons vector chargedtracks; vector all_photons; loop->Get(chargedtracks); loop->Get(all_photons); // Keep only most probable hypothesis for charged tracks vector tracktimebaseds; for(unsigned int i=0; i &hypotheses = chargedtracks[i]->hypotheses; if(hypotheses.size()>0)tracktimebaseds.push_back(hypotheses[0]); } // Keep only photons not matched to charged tracks vector photons; for(unsigned int i=0; igetTag()!=DPhoton::kCharge)photons.push_back(all_photons[i]); } // To minimize memory usage and time in allocation, we maintain a // pool of partInfo_t objects. Make sure the pool is large enough to hold // all of the particles we have this event. unsigned int Nparticles_total = tracktimebaseds.size() + photons.size(); for(unsigned int i=partInfos_pool.size(); iSetLimits(tmin, tmax, zmin, zmax, Nbinst, Nbinsz); partInfos_pool.push_back(pi); } // Periodically delete some partInfo_t objects if the pool gets too large. // This prevents memory-leakage-like behavor. if((Nparticles_total < MAX_PARTINFOS) && (partInfos_pool.size()>MAX_PARTINFOS)){ for(unsigned int i=MAX_PARTINFOS; i parts; // Assign and fill partInfo_t objects for each charged track for(unsigned int i=0; i > groups; while(!AllInGroups(parts)){ // Make a list of all particles that have not been assigned // to a group vector unassigned; for(unsigned int i=0; iis_in_group)unassigned.push_back(parts[i]); } // Find the maximum t,z coordinate by adding all unassigned // particle's histos together DVector2 maxloc = DHoughFind::GetMaxBinLocation(unassigned); if(debug_level>0)_DBG_<<"Location of maximum: t="<is_in_group = true; // Add the new group to the list of groups groups.push_back(new_group); }; // OK, we've now grouped the particles together into groups. Create a new // DPhysicsEvent for each group for(unsigned int i=0; i &group = groups[i]; DPhysicsEvent *pe = new DPhysicsEvent; // Loop over particles in the group, pushing them onto the // appropriate vectors in the DPhysicsEvent for(unsigned int j=0; jphoton){ // photon pe->photon.push_back(pi->photon); }else if(pi->track){ // Determine type of charged track double mass = pi->track->mass(); double q = pi->track->charge(); if(fabs(mass-0.13957)<0.001){ if(q>0.0){ // pi+ pe->pip.push_back(pi->track); } else { // pi- pe->pim.push_back(pi->track); } } else if(fabs(mass-0.93827)<0.001){ // proton pe->proton.push_back(pi->track); } else if(fabs(mass-0.49368)<0.001){ if(q>0.0){ // K+ pe->Kp.push_back(pi->track); } else { // K- pe->Km.push_back(pi->track); } } else { if(q>0.0){ // other + pe->otherp.push_back(pi->track); } else { // other - pe->otherm.push_back(pi->track); } } }else{ _DBG_<<"Both photon and track points in partInfo_t are NULL. This should never happen. Compalin to davidl@jlab.org"< &parts) { for(unsigned int i=0; iis_in_group)return false; return true; } //------------------ // FillPartInfoChargedTrack //------------------ void DPhysicsEvent_factory::FillPartInfoChargedTrack(DPhysicsEvent_factory::partInfo_t *pi, const DTrackTimeBased *trk) { pi->Reset(); pi->track = trk; pi->t = trk->t0(); pi->sigmat = trk->t0_err(); pi->z = trk->z(); pi->sigmaz = 0.8/sin(trk->momentum().Theta()); // in cm. For now, use 3mm wide angle track resolution scaled by sin(theta) pi->Fill(pi->t, pi->sigmat, pi->z, pi->sigmaz); } //------------------ // FillPartInfoPhoton //------------------ void DPhysicsEvent_factory::FillPartInfoPhoton(DPhysicsEvent_factory::partInfo_t *pi, const DPhoton *photon) { pi->Reset(); pi->photon = photon; pi->t = photon->t0(); pi->sigmat = photon->t0_err(); pi->z = photon->z(); pi->sigmaz = 30.0/sqrt(12); // in cm. Use length of target for z-resolution of photons pi->Fill(pi->t, pi->sigmat, pi->z, pi->sigmaz); } //------------------ // MakeRootHists //------------------ void DPhysicsEvent_factory::MakeRootHists(int event, vector< vector > &groups) { /// This is meant for debugging ONLY. It will take the DHoughFind objects /// contained in the given "groups" container and convert them into /// ROOT histograms. This should be utilized using something like hd_root /// so that the histograms are saved to a file. /// /// A TDirectory will be made to hold the histograms for each event. /// Within that, a TDirectory will be created for each group and the /// group member's histos will be created there. // Save current directory so we can cd back to it before returing TDirectory *saveDir = gDirectory; // Create a TDirectory to hold the event char dirname[256]; sprintf(dirname, "event%03d", event); TDirectory *eventdir = saveDir->mkdir(dirname); // Container to keep pointer to all hists so we can make sum histo later vector root_hists; // Loop over groups for(unsigned int i=0; imkdir(dirname); groupdir->cd(); // Loop over members of group vector &group = groups[i]; for(unsigned int j=0; jMakeIntoRootHist(hname); h->SetDrawOption("surf4"); h->SetXTitle("time from L1 trigger (ns)"); h->SetYTitle("Z position of vertex (cm)"); h->SetStats(0); root_hists.push_back(h); } } // Create sum histo for all particles this event if(root_hists.size() > 0){ eventdir->cd(); TH2D *sum = (TH2D*)root_hists[0]->Clone("sum"); for(unsigned int i=1; iAdd(root_hists[i]); } } // Write eventdir and its contents to the file //eventdir->Write(); // cd back into TDirectory we were in upon entering this method saveDir->cd(); }