// $Id$ // // File: DCustomAction_DeltaPhi.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_DeltaPhi.h" void DCustomAction_DeltaPhi::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_DeltaPhi::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 auto locParticles = locParticleCombo->Get_FinalParticles_Measured(Get_Reaction(), d_AllCharges); double locDeltaPhi = (locParticles[0]->lorentzMomentum().Phi() - locParticles[1]->lorentzMomentum().Phi())*180./TMath::Pi(); if(locDeltaPhi > 360.) locDeltaPhi -= 360.; if(locDeltaPhi < 0.) locDeltaPhi += 360.; //Optional: FILL HISTOGRAMS //Since we are filling histograms local to this action, it will not interfere with other ROOT operations: can use action-wide ROOT lock //Note, the mutex is unique to this DReaction + action_string combo: actions of same class with different hists will have a different mutex 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) return false; // Cut on extra showers vector locUnusedNeutralShowers; dAnalysisUtilities->Get_UnusedNeutralShowers(locEventLoop, locParticleCombo, locUnusedNeutralShowers); if(locUnusedNeutralShowers.size() > 2) return false; // Remove low angle protons since these are too high in -t if(locParticles[1]->lorentzMomentum().Theta()*180./TMath::Pi() < 20.) return false; return true; //return false if you want to use this action to apply a cut (and it fails the cut!) }