Difference between revisions of "Analysis JEventProcessor"

From GlueXWiki
Jump to: navigation, search
(Summary)
(DEventProcessor_b1pi_hists.cc)
Line 50: Line 50:
 
== DEventProcessor_b1pi_hists.cc ==
 
== DEventProcessor_b1pi_hists.cc ==
 
* This is from sim-recon/src/programs/Analysis/plugins/b1pi_hists/
 
* This is from sim-recon/src/programs/Analysis/plugins/b1pi_hists/
* Note the <span style="color:#008000">AddFactoryGenerator</span>() line in <span style="color:#008000">InitPlugin</span>(). 
 
 
<syntaxhighlight>
 
<syntaxhighlight>
 
#include "DEventProcessor_b1pi_hists.h"
 
#include "DEventProcessor_b1pi_hists.h"
 +
 +
// The executable should define the ROOTfile global variable. It will
 +
// be automatically linked when dlopen is called.
 +
extern TFile *ROOTfile;
  
 
// Routine used to create our DEventProcessor
 
// Routine used to create our DEventProcessor
Line 78: Line 81:
 
jerror_t DEventProcessor_b1pi_hists::brun(JEventLoop *locEventLoop, int runnumber)
 
jerror_t DEventProcessor_b1pi_hists::brun(JEventLoop *locEventLoop, int runnumber)
 
{
 
{
 +
  //Create Trees
 +
  const DEventWriterROOT* locEventWriterROOT = NULL;
 +
  locEventLoop->GetSingle(locEventWriterROOT);
 +
  locEventWriterROOT->Create_DataTrees(locEventLoop);
 +
  locEventWriterROOT->Create_ThrownTree("tree_b1pi_thrownmc.root");
 +
 +
  //Initialize Actions
 +
  dHistogramAction_TrackMultiplicity.Initialize(locEventLoop);
 +
  dHistogramAction_ThrownParticleKinematics.Initialize(locEventLoop);
 +
  dHistogramAction_DetectedParticleKinematics.Initialize(locEventLoop);
 +
  dHistogramAction_GenReconTrackComparison.Initialize(locEventLoop);
 +
 
   return NOERROR;
 
   return NOERROR;
 
}
 
}
Line 92: Line 107:
 
   dHistogramAction_GenReconTrackComparison(locEventLoop);
 
   dHistogramAction_GenReconTrackComparison(locEventLoop);
  
   //Perform the analysis for this event by requesting the results.
+
   //Triggers the analysis (is also automatically called by DEventWriterROOT::Fill_Trees())
    //For each DReaction in this plugin, this creates the DParticleCombo objects and performs the DAnalysisActions stored in the DReaction
+
 
   vector<const DAnalysisResults*> locAnalysisResultsVector;
 
   vector<const DAnalysisResults*> locAnalysisResultsVector;
 
   locEventLoop->Get(locAnalysisResultsVector);
 
   locEventLoop->Get(locAnalysisResultsVector);
  
   //Output TTree //saves the data from the surviving DParticleCombo's of all output-enabled DReaction's in this plugin to their respective TTree's
+
   //Output TTree
   vector<const DEventWriterROOT*> locEventWriterROOTVector;
+
   const DEventWriterROOT* locEventWriterROOT = NULL;
   locEventLoop->Get(locEventWriterROOTVector);
+
   locEventLoop->GetSingle(locEventWriterROOT);
   locEventWriterROOTVector[0]->Fill_Trees(locEventLoop);
+
  locEventWriterROOT->Fill_DataTrees(locEventLoop, "b1pi_hists");
 +
   locEventWriterROOT->Fill_ThrownTree(locEventLoop);
  
   //Mark that the event should be saved if at least one DParticleCombo survived all of the cuts
+
   //Do Miscellaneous Cuts (if any)
 
   bool locSaveEventFlag = false;
 
   bool locSaveEventFlag = false;
 
   for(size_t loc_i = 0; loc_i < locAnalysisResultsVector.size(); ++loc_i)
 
   for(size_t loc_i = 0; loc_i < locAnalysisResultsVector.size(); ++loc_i)
Line 111: Line 126:
 
     if(locAnalysisResults->Get_NumPassedParticleCombos() == 0)
 
     if(locAnalysisResults->Get_NumPassedParticleCombos() == 0)
 
       continue;
 
       continue;
 +
    //place cuts here
 
     locSaveEventFlag = true;
 
     locSaveEventFlag = true;
 
     break;
 
     break;
 
   }
 
   }
  
   //Save the event to dana_rest_b1pi.hddm
+
   //Output REST File
 
   if(locSaveEventFlag)
 
   if(locSaveEventFlag)
 
   {
 
   {

Revision as of 17:10, 2 July 2013

Summary

  • The DEventProcessor can be minimal in content.
  • The code below analyzes the b1pi DReaction, fills reaction-independent histograms, outputs the surviving DParticleCombo's to a TTree, and skims successful events into a new hddm file.
  • Code and documentation for the setting up the b1pi DReaction can be found at: DReaction

DEventProcessor_b1pi_hists.h

  • This is from sim-recon/src/programs/Analysis/plugins/b1pi_hists/
#ifndef _DEventProcessor_b1pi_hists_
#define _DEventProcessor_b1pi_hists_
 
#include "TFile.h"
#include "TROOT.h"
 
#include "JANA/JEventProcessor.h"
 
#include "DANA/DApplication.h"
#include "ANALYSIS/DAnalysisResults.h"
#include "HDDM/DEventWriterREST.h"
 
#include "DFactoryGenerator_b1pi_hists.h"
 
using namespace jana;
 
class DEventProcessor_b1pi_hists : public JEventProcessor
{
  public:
    DEventProcessor_b1pi_hists(){};
    ~DEventProcessor_b1pi_hists(){};
    const char* className(void){return "DEventProcessor_b1pi_hists";}
 
  private:
    jerror_t init(void);            ///< Called once at program start.
    jerror_t brun(JEventLoop *eventLoop, int runnumber);  ///< Called everytime a new run number is detected.
    jerror_t evnt(JEventLoop *eventLoop, int eventnumber);  ///< Called every event.
    jerror_t erun(void);            ///< Called everytime run number changes, provided brun has been called.
    jerror_t fini(void);            ///< Called after last event of last event source has been processed.
 
    // Create reaction-independent actions.
    DHistogramAction_TrackMultiplicity dHistogramAction_TrackMultiplicity;
    DHistogramAction_ThrownParticleKinematics dHistogramAction_ThrownParticleKinematics;
    DHistogramAction_DetectedParticleKinematics dHistogramAction_DetectedParticleKinematics;
    DHistogramAction_GenReconTrackComparison dHistogramAction_GenReconTrackComparison;
};
 
#endif // _DEventProcessor_b1pi_hists_

DEventProcessor_b1pi_hists.cc

  • This is from sim-recon/src/programs/Analysis/plugins/b1pi_hists/
#include "DEventProcessor_b1pi_hists.h"
 
// The executable should define the ROOTfile global variable. It will
// be automatically linked when dlopen is called.
extern TFile *ROOTfile;
 
// Routine used to create our DEventProcessor
extern "C"
{
  void InitPlugin(JApplication *app)
  {
    InitJANAPlugin(app);
    app->AddProcessor(new DEventProcessor_b1pi_hists());
    app->AddFactoryGenerator(new DFactoryGenerator_b1pi_hists());
  }
} // "C"
 
//------------------
// init
//------------------
jerror_t DEventProcessor_b1pi_hists::init(void)
{
  return NOERROR;
}
 
//------------------
// brun
//------------------
jerror_t DEventProcessor_b1pi_hists::brun(JEventLoop *locEventLoop, int runnumber)
{
  //Create Trees
  const DEventWriterROOT* locEventWriterROOT = NULL;
  locEventLoop->GetSingle(locEventWriterROOT);
  locEventWriterROOT->Create_DataTrees(locEventLoop);
  locEventWriterROOT->Create_ThrownTree("tree_b1pi_thrownmc.root");
 
  //Initialize Actions
  dHistogramAction_TrackMultiplicity.Initialize(locEventLoop);
  dHistogramAction_ThrownParticleKinematics.Initialize(locEventLoop);
  dHistogramAction_DetectedParticleKinematics.Initialize(locEventLoop);
  dHistogramAction_GenReconTrackComparison.Initialize(locEventLoop);
 
  return NOERROR;
}
 
//------------------
// evnt
//------------------
jerror_t DEventProcessor_b1pi_hists::evnt(JEventLoop *locEventLoop, int eventnumber)
{
  //Fill reaction-independent histograms.
  dHistogramAction_TrackMultiplicity(locEventLoop);
  dHistogramAction_ThrownParticleKinematics(locEventLoop);
  dHistogramAction_DetectedParticleKinematics(locEventLoop);
  dHistogramAction_GenReconTrackComparison(locEventLoop);
 
  //Triggers the analysis (is also automatically called by DEventWriterROOT::Fill_Trees())
  vector<const DAnalysisResults*> locAnalysisResultsVector;
  locEventLoop->Get(locAnalysisResultsVector);
 
  //Output TTree
  const DEventWriterROOT* locEventWriterROOT = NULL;
  locEventLoop->GetSingle(locEventWriterROOT);
  locEventWriterROOT->Fill_DataTrees(locEventLoop, "b1pi_hists");
  locEventWriterROOT->Fill_ThrownTree(locEventLoop);
 
  //Do Miscellaneous Cuts (if any)
  bool locSaveEventFlag = false;
  for(size_t loc_i = 0; loc_i < locAnalysisResultsVector.size(); ++loc_i)
  {
    const DAnalysisResults* locAnalysisResults = locAnalysisResultsVector[loc_i];
    if(locAnalysisResults->Get_Reaction()->Get_ReactionName() != "b1pi")
      continue;
    if(locAnalysisResults->Get_NumPassedParticleCombos() == 0)
      continue;
    //place cuts here
    locSaveEventFlag = true;
    break;
  }
 
  //Output REST File
  if(locSaveEventFlag)
  {
    vector<const DEventWriterREST*> locEventWriterRESTVector;
    locEventLoop->Get(locEventWriterRESTVector);
    locEventWriterRESTVector[0]->Write_RESTEvent(locEventLoop, "b1pi");
  }
 
  return NOERROR;
}
 
//------------------
// erun
//------------------
jerror_t DEventProcessor_b1pi_hists::erun(void)
{
  // Any final calculations on histograms (like dividing them)
  // should be done here. This may get called more than once.
  return NOERROR;
}
 
//------------------
// fini
//------------------
jerror_t DEventProcessor_b1pi_hists::fini(void)
{
  return NOERROR;
}