Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JEventProcessor_dumpthrowns.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: JEventProcessor_dumpthrowns.cc
4 // Created: Tue Feb 4 09:29:35 EST 2014
5 // Creator: davidl (on Linux ifarm1102 2.6.32-220.7.1.el6.x86_64 x86_64)
6 //
7 
9 using namespace jana;
10 
11 
12 // Routine used to create our JEventProcessor
13 #include <JANA/JApplication.h>
14 
16 #include <TRACKING/DMCThrown.h>
17 
18 extern "C"{
19 void InitPlugin(JApplication *app){
20  InitJANAPlugin(app);
21  app->AddProcessor(new JEventProcessor_dumpthrowns());
22 }
23 } // "C"
24 
25 
26 //------------------
27 // JEventProcessor_dumpthrowns (Constructor)
28 //------------------
30 {
31  events_written = 0;
32  events_discarded = 0;
33 }
34 
35 //------------------
36 // ~JEventProcessor_dumpthrowns (Destructor)
37 //------------------
39 {
40 
41 }
42 
43 //------------------
44 // init
45 //------------------
47 {
48  //
49  MAX_CANDIDATE_FILTER = 1000;
50  gPARMS->SetDefaultParameter("MAX_CANDIDATE_FILTER", MAX_CANDIDATE_FILTER, "Maximum number of candidates allowed in event before any are written to file.");
51 
52 
53  // Open output file
54  ofs = new ofstream("gluex_throwns.txt");
55 
56  return NOERROR;
57 }
58 
59 //------------------
60 // brun
61 //------------------
62 jerror_t JEventProcessor_dumpthrowns::brun(JEventLoop *eventLoop, int32_t runnumber)
63 {
64  return NOERROR;
65 }
66 
67 //------------------
68 // evnt
69 //------------------
70 jerror_t JEventProcessor_dumpthrowns::evnt(JEventLoop *loop, uint64_t eventnumber)
71 {
72  // Get track candidates
73  vector<const DTrackCandidate*> candidates;
74  loop->Get(candidates);
75  if(candidates.size()==0 || candidates.size()>MAX_CANDIDATE_FILTER){
76  events_discarded++;
77  return NOERROR;
78  }
79 
80  // Get thrown particles
81  vector<const DMCThrown*> throwns;
82  loop->Get(throwns);
83 
84  // Write out thrown parameters
85  for(unsigned int i=0; i<throwns.size(); i++){
86  const DMCThrown *thrown = throwns[i];
87 
88  // Write thrown parameters to string
89  stringstream ss;
90  ss << thrown->charge();
91  ss << " " << thrown->x() << " " << thrown->y() << " " << thrown->z();
92  ss << " " << thrown->px() << " " << thrown->py() << " " << thrown->pz();
93 
94  // Write thrown parameters string to file
95  LockState();
96  (*ofs) << ss.str() << endl;
97  events_written++;
98  UnlockState();
99 
100  // Sometimes, generated particles are added to the thrown
101  // particles list. We want only the first MAX_CANDIDATE_FILTER
102  // particles which *may* correspond to the first candidates.
103  // (probably not, but at least it may work for the single particle
104  // case which is what we are interested in at the moment).
105  if((i+1) >= MAX_CANDIDATE_FILTER) break;
106  }
107 
108  return NOERROR;
109 }
110 
111 //------------------
112 // erun
113 //------------------
115 {
116  return NOERROR;
117 }
118 
119 //------------------
120 // fini
121 //------------------
123 {
124  if(ofs){
125  ofs->close();
126  delete ofs;
127  ofs =NULL;
128  }
129 
130  cout << endl;
131  cout << "Wrote " << events_written << " thrown events to output file (discarded " << events_discarded << ")" << endl;
132  cout << endl;
133 
134  return NOERROR;
135 }
136 
137 
138 
double px(void) const
double py(void) const
double z(void) const
double pz(void) const
double x(void) const
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
double y(void) const
InitPlugin_t InitPlugin
jerror_t init(void)
Called once at program start.
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
double charge(void) const
jerror_t fini(void)
Called after last event of last event source has been processed.
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.