Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DEventProcessor_mcthrown_tree.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: DEventProcessor_mcthrown_tree.cc
4 // Created: Thu Sep 28 11:38:03 EDT 2011
5 // Creator: pmatt (on Darwin swire-b241.jlab.org 8.4.0 powerpc)
6 //
7 
9 
10 #include <TAGGER/DTAGHGeometry.h>
11 
12 // The executable should define the ROOTfile global variable. It will
13 // be automatically linked when dlopen is called.
14 extern TFile *ROOTfile;
15 
16 // Routine used to create our DEventProcessor
17 extern "C"
18 {
19  void InitPlugin(JApplication *app)
20  {
21  InitJANAPlugin(app);
22  app->AddProcessor(new DEventProcessor_mcthrown_tree());
23  }
24 } // "C"
25 
26 //------------------
27 // init
28 //------------------
30 {
31  // require tagger hit for MCGEN beam photon by default to write event to TTree
32  dTagCheck = true;
33  gPARMS->SetDefaultParameter("MCTHROWN:TAGCHECK", dTagCheck);
34 
35  return NOERROR;
36 }
37 
38 //------------------
39 // evnt
40 //------------------
41 jerror_t DEventProcessor_mcthrown_tree::evnt(JEventLoop *locEventLoop, uint64_t eventnumber)
42 {
43  const DEventWriterROOT* locEventWriterROOT = NULL;
44  locEventLoop->GetSingle(locEventWriterROOT);
45 
46  //This looks bad. Really bad. But relax, it's fine.
47  //This was previously in brun(), but brun() is ONLY CALLED BY ONE THREAD (no matter how many threads you run with!)
48  //So this meant that the event writer wasn't set up for other threads!!
49  //So, we call this here, every event, where every thread can see it.
50  //However, only the FIRST thread will actually create the tree
51  //And, only the FIRST CALL for each thread will setup the event writer
52  //Subsequent calls will auto-detect that everything is already done and bail early.
53  //Ugly, yes. But it works, and it's too late now to have each thread call brun().
54  locEventWriterROOT->Create_ThrownTree(locEventLoop, "tree_thrown.root");
55 
56  // only keep generated events which hit a tagger counter
57  vector<const DBeamPhoton*> locBeamPhotons;
58  locEventLoop->Get(locBeamPhotons, "TAGGEDMCGEN");
59 
60  // skip events where generated beam photon did not hit TAGM or TAGH counter
61  if(dTagCheck && locBeamPhotons.empty())
62  return NOERROR;
63 
64  locEventWriterROOT->Fill_ThrownTree(locEventLoop);
65 
66  return NOERROR;
67 }
68 
TFile * ROOTfile
jerror_t evnt(JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
jerror_t init(void)
Called once at program start.
InitPlugin_t InitPlugin
void Create_ThrownTree(JEventLoop *locEventLoop, string locOutputFileName) const
void Fill_ThrownTree(JEventLoop *locEventLoop) const