// $Id$ // // File: DCustomAction_NeutronCuts.cc // Created: Wed Dec 21 13:24:54 EST 2016 // Creator: jrsteven (on Linux ifarm1402.jlab.org 3.10.0-327.el7.x86_64 x86_64) // #include "DCustomAction_NeutronCuts.h" void DCustomAction_NeutronCuts::Initialize(JEventLoop* locEventLoop) { //Optional: Create histograms and/or modify member variables. //Create any histograms/trees/etc. within a ROOT lock. //This is so that when running multithreaded, only one thread is writing to the ROOT file at a time. //NEVER: Get anything from the JEventLoop while in a lock: May deadlock //CREATE THE HISTOGRAMS //Since we are creating histograms, the contents of gDirectory will be modified: must use JANA-wide ROOT lock japp->RootWriteLock(); //ACQUIRE ROOT LOCK!! { // Optional: Useful utility functions. locEventLoop->GetSingle(dAnalysisUtilities); //Required: Create a folder in the ROOT output file that will contain all of the output ROOT objects (if any) for this action. //If another thread has already created the folder, it just changes to it. CreateAndChangeTo_ActionDirectory(); dHist_DeltaPhi = GetOrCreate_Histogram("DeltaPhi", ";#Delta#phi (degrees)", 360, 0., 360.0); } japp->RootUnLock(); //RELEASE ROOT LOCK!! } bool DCustomAction_NeutronCuts::Perform_Action(JEventLoop* locEventLoop, const DParticleCombo* locParticleCombo) { //Write custom code to perform an action on the INPUT DParticleCombo (DParticleCombo) //NEVER: Grab DParticleCombo or DAnalysisResults objects (of any tag!) from the JEventLoop within this function //NEVER: Grab objects that are created post-kinfit (e.g. DKinFitResults, etc.) from the JEventLoop if Get_UseKinFitResultsFlag() == false: CAN CAUSE INFINITE DEPENDENCY LOOP //NEVER: Get anything from the JEventLoop while in a lock: May deadlock deque locParticles; locParticleCombo->Get_DetectedFinalParticles(locParticles); // Remove high angle pions since neutron won't be in BCAL if(locParticles[0]->lorentzMomentum().Theta()*180./TMath::Pi() > 30. || locParticles[0]->lorentzMomentum().P() < 2.0) return false; // Require BCAL shower DeltaPhi and cut extra showers bool locIsGoodBCAL = false; vector locUnusedNeutralShowers; dAnalysisUtilities->Get_UnusedNeutralShowers(locEventLoop, locParticleCombo, locUnusedNeutralShowers); for(size_t loc_i=0; loc_idDetectorSystem == SYS_BCAL) { double locDeltaPhi = (locParticles[0]->lorentzMomentum().Phi() - locUnusedNeutralShowers[loc_i]->dSpacetimeVertex.Phi())*180./TMath::Pi(); if(locDeltaPhi > 360.) locDeltaPhi -= 360.; if(locDeltaPhi < 0.) locDeltaPhi += 360.; Lock_Action(); //ACQUIRE ROOT LOCK!! { // Fill any histograms here dHist_DeltaPhi->Fill(locDeltaPhi); } Unlock_Action(); //RELEASE ROOT LOCK!! // Cut on deltaPhi angle if(fabs(locDeltaPhi - 180.) < dDeltaPhiCut) locIsGoodBCAL = true; } } if(!locIsGoodBCAL || locUnusedNeutralShowers.size() > 2) return false; return true; //return false if you want to use this action to apply a cut (and it fails the cut!) }