Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JEventProcessor_CDC_dedx.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: JEventProcessor_CDC_dedx.cc
4 // Created: Thu Aug 16 16:35:42 EDT 2018
5 // Creator: njarvis (on Linux egbert 2.6.32-696.23.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 #include <JANA/JFactory.h>
15 extern "C"{
16 void InitPlugin(JApplication *app){
17  InitJANAPlugin(app);
18  app->AddProcessor(new JEventProcessor_CDC_dedx());
19 }
20 } // "C"
21 
22 
23 //------------------
24 // JEventProcessor_CDC_dedx (Constructor)
25 //------------------
27 {
28 
29 }
30 
31 //------------------
32 // ~JEventProcessor_CDC_dedx (Destructor)
33 //------------------
35 {
36 
37 }
38 
39 //------------------
40 // init
41 //------------------
43 {
44  // This is called once at program startup.
45 
46  TDirectory *main = gDirectory;
47  gDirectory->mkdir("CDC_dedx")->cd();
48 
49  dedx_p = new TH2D("dedx_p","CDC dE/dx vs p, 4+ hits used;p (GeV/c);dE/dx (keV/cm)",250,0,10,400,0,25);
50 
51  dedx_p_pos = new TH2D("dedx_p_pos","CDC dE/dx vs p, q+, 4+ hits used;p (GeV/c);dE/dx (keV/cm)",250,0,10,400,0,25);
52 
53  dedx_p_neg = new TH2D("dedx_p_neg","CDC dE/dx vs p, q-, 4+ hits used;p (GeV/c);dE/dx (keV/cm)",250,0,10,400,0,25);
54 
55 
56  intdedx_p = new TH2D("intdedx_p","CDC dE/dx (from integral) vs p, 4+ hits used;p (GeV/c);dE/dx (keV/cm)",250,0,10,400,0,25);
57 
58  intdedx_p_pos = new TH2D("intdedx_p_pos","CDC dE/dx (from integral) vs p, q+, 4+ hits used;p (GeV/c);dE/dx (keV/cm)",250,0,10,400,0,25);
59 
60  intdedx_p_neg = new TH2D("intdedx_p_neg","CDC dE/dx (from integral) vs p, q-, 4+ hits used;p (GeV/c);dE/dx (keV/cm)",250,0,10,400,0,25);
61 
62 
63 
64  main->cd();
65 
66  return NOERROR;
67 }
68 
69 //------------------
70 // brun
71 //------------------
72 jerror_t JEventProcessor_CDC_dedx::brun(JEventLoop *eventLoop, int32_t runnumber)
73 {
74  // This is called whenever the run number changes
75  return NOERROR;
76 }
77 
78 //------------------
79 // evnt
80 //------------------
81 jerror_t JEventProcessor_CDC_dedx::evnt(JEventLoop *loop, uint64_t eventnumber)
82 {
83  // This is called for every event. Use of common resources like writing
84  // to a file or filling a histogram should be mutex protected. Using
85  // loop->Get(...) to get reconstructed objects (and thereby activating the
86  // reconstruction algorithm) should be done outside of any mutex lock
87  // since multiple threads may call this method at the same time.
88  // Here's an example:
89  //
90  // vector<const MyDataClass*> mydataclasses;
91  // loop->Get(mydataclasses);
92  //
93  // japp->RootFillLock(this);
94  // ... fill historgrams or trees ...
95  // japp->RootFillUnLock(this);
96 
97  // select events with physics events, i.e., not LED and other front panel triggers
98  const DTrigger* locTrigger = NULL;
99  loop->GetSingle(locTrigger);
100  if(locTrigger->Get_L1FrontPanelTriggerBits() != 0) return NOERROR;
101 
102 
103  const DVertex* locVertex = NULL;
104  loop->GetSingle(locVertex);
105  double vertexz = locVertex->dSpacetimeVertex.Z();
106  if ((vertexz < 52.0) || (vertexz > 78.0)) return NOERROR;
107 
108 
109  vector<const DTrackTimeBased*> tracks;
110  loop->Get(tracks);
111  if (tracks.size() ==0) return NOERROR;
112 
113 
114  for (uint32_t i=0; i<tracks.size(); i++) {
115 
116  int nhits = (int)tracks[i]->dNumHitsUsedFordEdx_CDC;
117  if (nhits < 4) continue;
118 
119  double charge = tracks[i]->charge();
120  DVector3 mom = tracks[i]->momentum();
121  double p = mom.Mag();
122 
123  double dedx = 1.0e6*tracks[i]->ddEdx_CDC_amp;
124 
125  if (dedx > 0) {
126 
127  japp->RootFillLock(this);
128 
129  dedx_p->Fill(p,dedx);
130 
131  if (charge > 0) {
132  dedx_p_pos->Fill(p,dedx);
133  } else {
134  dedx_p_neg->Fill(p,dedx);
135  }
136 
137  japp->RootFillUnLock(this);
138 
139  }
140 
141  // repeat for dedx from integral
142 
143  dedx = 1.0e6*tracks[i]->ddEdx_CDC;
144 
145  if (dedx > 0) {
146 
147  japp->RootFillLock(this);
148 
149  intdedx_p->Fill(p,dedx);
150 
151  if (charge > 0) {
152  intdedx_p_pos->Fill(p,dedx);
153  } else {
154  intdedx_p_neg->Fill(p,dedx);
155  }
156 
157  japp->RootFillUnLock(this);
158 
159  }
160 
161 
162 
163  }
164 
165  return NOERROR;
166 }
167 
168 //------------------
169 // erun
170 //------------------
172 {
173  // This is called whenever the run number changes, before it is
174  // changed to give you a chance to clean up before processing
175  // events from the next run number.
176  return NOERROR;
177 }
178 
179 //------------------
180 // fini
181 //------------------
183 {
184  // Called before program exit after event processing is finished.
185  return NOERROR;
186 }
187 
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
TVector3 DVector3
Definition: DVector3.h:14
jerror_t init(void)
Called once at program start.
uint32_t Get_L1FrontPanelTriggerBits(void) const
JApplication * japp
InitPlugin_t InitPlugin
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
DLorentzVector dSpacetimeVertex
Definition: DVertex.h:28
jerror_t fini(void)
Called after last event of last event source has been processed.
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
int main(int argc, char *argv[])
Definition: gendoc.cc:6