// $Id$ // // File: DCustomAction_indi_P4.cc // Created: Thu Jul 7 12:29:59 EDT 2016 // Creator: vbajaj (on Linux maria 2.6.32-573.3.1.el6.x86_64 x86_64) // #include "DCustomAction_indi_P4.h" void DCustomAction_indi_P4::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!! { //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(); // Optional: Create a ROOT subfolder. //If another thread has already created the folder, it just changes to it. // CreateAndChangeTo_Directory("MyDirName", "MyDirTitle"); //make sub-directory content here // gDirectory->cd(".."); //return to the action directory // (Optional) Example: Create a histogram. // This function will return the histogram if already created by another thread. If not pre-existing, it will create and return it. // Function arguments are identical to those used for the histogram constructors dMissE = GetOrCreate_Histogram("dMissE", "Missing E", 100, -1.,1.); dMissPx = GetOrCreate_Histogram("dMissPx", "Missing Px", 100, -1.,1.); dMissPy = GetOrCreate_Histogram("dMissPy", "Missing Py", 100, -1.,1.); dMissPz = GetOrCreate_Histogram("dMissPz", "Missing Pz", 100, -1.,1.); } japp->RootUnLock(); //RELEASE ROOT LOCK!! } bool DCustomAction_indi_P4::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 // Optional: Useful utility functions. const DAnalysisUtilities* locAnalysisUtilities; locEventLoop->GetSingle(locAnalysisUtilities); DLorentzVector locMissingP4 = locAnalysisUtilities->Calc_MissingP4(Get_Reaction(), locParticleCombo,false); double locMissE = locMissingP4.E(); double locMissPx = locMissingP4.Px(); double locMissPy = locMissingP4.Py(); double locMissPz = locMissingP4.Pz(); //Optional: check whether the user wanted to use the kinematic fit results when performing this action // bool locUseKinFitResultsFlag = Get_UseKinFitResultsFlag(); //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!! { dMissE->Fill(locMissE); dMissPx->Fill(locMissPx); dMissPy->Fill(locMissPy); dMissPz->Fill(locMissPz); } Unlock_Action(); //RELEASE ROOT LOCK!! /* if ((locMissE >.05 || locMissE <-.05) && (locMissPx >.05 || locMissPx <-.05 ) && (locMissPy >.05 || locMissPy <-.05) && (locMissPz >.05 || locMissPz <-.05)) { return false; } */ return true; //return false if you want to use this action to apply a cut (and it fails the cut!) }