Bug Summary

File:plugins/monitoring/ST_online_efficiency/JEventProcessor_ST_online_efficiency.cc
Location:line 110, column 28
Description:Called C++ object pointer is null

Annotated Source Code

1// $Id$
2//
3// File: JEventProcessor_ST_online_efficiency.cc
4// Created: Wed Jan 20 10:35:58 EST 2016
5// Creator: mkamel (on Linux ifarm1102 2.6.32-431.el6.x86_64 x86_64)
6//
7
8#include "JEventProcessor_ST_online_efficiency.h"
9using namespace jana;
10using namespace std;
11
12// Routine used to create our JEventProcessor
13#include <JANA/JApplication.h>
14#include <JANA/JFactory.h>
15extern "C"{
16void InitPlugin(JApplication *app){
17 InitJANAPlugin(app);
18 app->AddProcessor(new JEventProcessor_ST_online_efficiency());
19}
20} // "C"
21
22
23//------------------
24// JEventProcessor_ST_online_efficiency (Constructor)
25//------------------
26JEventProcessor_ST_online_efficiency::JEventProcessor_ST_online_efficiency()
27{
28
29}
30
31//------------------
32// ~JEventProcessor_ST_online_efficiency (Destructor)
33//------------------
34JEventProcessor_ST_online_efficiency::~JEventProcessor_ST_online_efficiency()
35{
36
37}
38
39//------------------
40// init
41//------------------
42jerror_t JEventProcessor_ST_online_efficiency::init(void)
43{
44 // This is called once at program startup. If you are creating
45 // and filling historgrams in this plugin, you should lock the
46 // ROOT mutex like this:
47 //
48 // japp->RootWriteLock();
49 // ... fill historgrams or trees ...
50 // japp->RootUnLock();
51 //
52 // USE_SC_TIME = 0 in order to Not reconstruct tracks with start counter time
53 gPARMS->SetParameter("TRKFIT:USE_SC_TIME",false);
54
55 // Create root folder for ST and cd to it, store main dir
56 TDirectory *main = gDirectory(TDirectory::CurrentDirectory());
57 gDirectory(TDirectory::CurrentDirectory())->mkdir("st_efficiency")->cd();
58 //eff histos
59 h_N_trck_prd_All = new TH1D("h_N_trck_prd_All", "h_N_trck_prd_All; Sector; Predicted Hit Counts", 31, -0.5, 30.5);
60 h_N_recd_hit_All = new TH1D("h_N_recd_hit_All", "h_N_recd_hit_All; Sector; Recorded Hit Counts", 31, -0.5, 30.5);
61
62 h_N_trck_prd_ss = new TH1D("h_N_trck_prd_ss", "h_N_trck_prd_ss; Sector; Predicted Hit Counts", 31, -0.5, 30.5);
63 h_N_recd_hit_ss = new TH1D("h_N_recd_hit_ss", "h_N_recd_hit_ss; Sector; Recorded Hit Counts", 31, -0.5, 30.5);
64
65 h_N_trck_prd_bs = new TH1D("h_N_trck_prd_bs", "h_N_trck_prd_bs; Sector; Predicted Hit Counts", 31, -0.5, 30.5);
66 h_N_recd_hit_bs = new TH1D("h_N_recd_hit_bs", "h_N_recd_hit_bs; Sector; Recorded Hit Counts", 31, -0.5, 30.5);
67
68 h_N_trck_prd_ns = new TH1D("h_N_trck_prd_ns", "h_N_trck_prd_ns; Sector; Predicted Hit Counts", 31, -0.5, 30.5);
69 h_N_recd_hit_ns = new TH1D("h_N_recd_hit_ns", "h_N_recd_hit_ns; Sector; Recorded Hit Counts", 31, -0.5, 30.5);
70
71 h_ST_Eff_All= new TH1D("h_ST_Eff_All", " Efficiency; Sector; N_{RECD}/N_{TRCK}", 31, -0.5, 30.5);
72 h_ST_Eff_ss = new TH1D("h_ST_Eff_ss", " SS Efficiency; Sector; N_{RECD}/N_{TRCK}", 31, -0.5, 30.5);
73 h_ST_Eff_bs = new TH1D("h_ST_Eff_bs", " BS Efficiency; Sector; N_{RECD}/N_{TRCK}", 31, -0.5, 30.5);
74 h_ST_Eff_ns = new TH1D("h_ST_Eff_ns", " NS Efficiency; Sector; N_{RECD}/N_{TRCK}", 31, -0.5, 30.5);
75
76 gDirectory(TDirectory::CurrentDirectory())->cd("../");
77 main->cd();
78
79 // Initialize counters
80 memset(N_trck_prd_All, 0, sizeof(N_trck_prd_All));
81 memset(N_recd_hit_All, 0, sizeof(N_recd_hit_All));
82 memset(N_trck_prd_ss, 0, sizeof(N_trck_prd_ss));
83 memset(N_recd_hit_ss, 0, sizeof(N_recd_hit_ss));
84 memset(N_trck_prd_bs, 0, sizeof(N_trck_prd_bs));
85 memset(N_recd_hit_bs, 0, sizeof(N_recd_hit_bs));
86 memset(N_trck_prd_ns, 0, sizeof(N_trck_prd_ns));
87 memset(N_recd_hit_ns, 0, sizeof(N_recd_hit_ns));
88
89 return NOERROR;
90}
91
92//------------------
93// brun
94//------------------
95jerror_t JEventProcessor_ST_online_efficiency::brun(JEventLoop *eventLoop, int32_t runnumber)
96{
97 // This is called whenever the run number changes
98 // Obtain the target center along z;
99 map<string,double> target_params;
100 if (eventLoop->GetCalib("/TARGET/target_parms", target_params))
1
Taking true branch
101 jout << "Error loading /TARGET/target_parms/ !" << endl;
102 if (target_params.find("TARGET_Z_POSITION") != target_params.end())
2
Taking true branch
103 z_target_center = target_params["TARGET_Z_POSITION"];
104 else
105 jerr << "Unable to get TARGET_Z_POSITION from /TARGET/target_parms !" << endl;
106 // Obtain the Start Counter geometry
107 DApplication* dapp = dynamic_cast<DApplication*>(eventLoop->GetJApplication());
3
Calling 'JEventLoop::GetJApplication'
4
Returning from 'JEventLoop::GetJApplication'
5
'dapp' initialized here
108 if(!dapp)
6
Assuming 'dapp' is null
7
Taking true branch
109 _DBG_std::cerr<<"plugins/monitoring/ST_online_efficiency/JEventProcessor_ST_online_efficiency.cc"
<<":"<<109<<" "
<<"Cannot get DApplication from JEventLoop! (are you using a JApplication based program?)"<<endl;
110 DGeometry* locGeometry = dapp->GetDGeometry(eventLoop->GetJEvent().GetRunNumber());
8
Called C++ object pointer is null
111 locGeometry->GetStartCounterGeom(sc_pos, sc_norm);
112 return NOERROR;
113}
114
115//------------------
116// evnt
117//------------------
118jerror_t JEventProcessor_ST_online_efficiency::evnt(JEventLoop *eventLoop, uint64_t eventnumber)
119{
120 // This is called for every event. Use of common resources like writing
121 // to a file or filling a histogram should be mutex protected. Using
122 // loop->Get(...) to get reconstructed objects (and thereby activating the
123 // reconstruction algorithm) should be done outside of any mutex lock
124 // since multiple threads may call this method at the same time.
125 // Here's an example:
126 //
127 // vector<const MyDataClass*> mydataclasses;
128 // loop->Get(mydataclasses);
129 //
130 // japp->RootWriteLock();
131 // ... fill historgrams or trees ...
132 // japp->RootUnLock();
133 vector<const DSCDigiHit*> st_adc_digi_hits;
134 vector<const DParticleID*> pid_algorithm;
135 vector<const DSCHit*> st_hits;
136 vector<const DChargedTrack*> chargedTrackVector;
137 eventLoop->Get(st_adc_digi_hits);
138 eventLoop->Get(pid_algorithm);
139 eventLoop->Get(st_hits);
140 eventLoop->Get(chargedTrackVector);
141 // Grab the associated detector matches object
142 const DDetectorMatches* locDetectorMatches = NULL__null;
143 eventLoop->GetSingle(locDetectorMatches);
144
145 // FILL HISTOGRAMS
146 // Since we are filling histograms local to this plugin, it will not interfere with other ROOT operations: can use plugin-wide ROOT fill lock
147 japp->RootFillLock(this); //ACQUIRE ROOT FILL LOCK
148
149 // Loop over charged tracks
150 for (uint32_t i = 0; i < chargedTrackVector.size(); i++)
151 {
152 // Grab the charged track
153 const DChargedTrack *thisChargedTrack = chargedTrackVector[i];
154 // Declare the time based track object
155 const DTrackTimeBased *timeBasedTrack;
156 // Grab associated time based track object by selecting charged track with best FOM
157 thisChargedTrack->Get_BestTrackingFOM()->GetSingle(timeBasedTrack);
158 float trackingFOMCut = 0.0027; // 3 sigma cut
159 if(timeBasedTrack->FOM < trackingFOMCut) continue;
160 // Define vertex vector
161 DVector3 vertex;
162 // Vertex info
163 vertex = timeBasedTrack->position();
164 // Cartesian Coordinates
165 double z_v = vertex.z();
166 double r_v = vertex.Perp();
167 bool z_vertex_cut = fabs(z_target_center - z_v) <= 15.0;
168 bool r_vertex_cut = r_v < 0.3;
169 // applied vertex cut
170 if (!z_vertex_cut) continue;
171 if (!r_vertex_cut) continue;
172 int st_pred_id = pid_algorithm[0]->PredictSCSector(timeBasedTrack->rt,0.05235,&locProjPos,&Barrel);
173 int st_pred_id_index = st_pred_id - 1;
174 // Z intersection of charged track and SC
175 locSCzIntersection = locProjPos.z();
176 locSCrIntersection = locProjPos.Perp();
177 // Get the direction of the track momentum
178 // Momentum of the track
179 DVector3 Momentum;
180 Momentum = timeBasedTrack->momentum();
181 if (st_pred_id != 0)
182 {
183 // Define sector array index
184 sc_index = st_pred_id_index;
185 // Start Counter geometry in hall coordinates
186 sc_pos_soss = sc_pos[sc_index][0].z(); // Start of straight section
187 sc_pos_eoss = sc_pos[sc_index][1].z(); // End of straight section
188 sc_pos_eobs = sc_pos[sc_index][11].z(); // End of bend section
189 sc_pos_eons = sc_pos[sc_index][12].z(); // End of nose section
190 ss_interval = (sc_pos_eoss - sc_pos_soss)/Nof_ss_intervals;
191 bs_interval = (sc_pos_eobs - sc_pos_eoss)/Nof_bs_intervals;
192 ns_interval = (sc_pos_eons - sc_pos_eobs)/Nof_ns_intervals;
193
194 //****************************
195 // Efficiency for the whole ST
196 //****************************
197 N_trck_prd_All[st_pred_id_index] += 1;
198 //loop over the Hit object and get the real sector hit at ST
199 for (uint32_t j = 0; j < st_hits.size(); j++)
200 {
201 int phi_sec_hit_sector = st_hits[j]->sector;
202 //********************************************************
203 //total efficiency of the ST
204 //********************************************************
205 if (st_pred_id == phi_sec_hit_sector){
206 N_recd_hit_All[st_pred_id_index] += 1;
207 break;
208 }
209 }
210 // ********************************
211 // Efficiency for Straight Section
212 // ********************************
213 if ( sc_pos_soss <= locSCzIntersection && locSCzIntersection <= sc_pos_eoss)
214 {
215 N_trck_prd_ss[st_pred_id_index] += 1;
216 //loop over the Hit object and get the real sector hit at ST
217 for (uint32_t j = 0; j < st_hits.size(); j++)
218 {
219 int phi_sec_hit_sector = st_hits[j]->sector;
220 if (st_pred_id == phi_sec_hit_sector)
221 {
222 N_recd_hit_ss[st_pred_id_index] += 1;
223 break;
224 }
225 }
226 }// end of straight section loop
227 //********************************
228 // Efficiency for Bend Section
229 //********************************
230 if ( sc_pos_eoss < locSCzIntersection && locSCzIntersection <= sc_pos_eobs)
231 {
232 N_trck_prd_bs[st_pred_id_index] += 1;
233 //loop over the Hit object and get the real sector hit at ST
234 for (uint32_t j = 0; j < st_hits.size(); j++)
235 {
236 int phi_sec_hit_sector = st_hits[j]->sector;
237 if (st_pred_id == phi_sec_hit_sector)
238 {
239 N_recd_hit_bs[st_pred_id_index] += 1;
240 break;
241 }
242 }
243 }// end of bend section loop
244 //********************************
245 // Efficiency for Nose Section
246 //********************************
247 if ( sc_pos_eobs < locSCzIntersection && locSCzIntersection <= sc_pos_eons)
248 {
249 N_trck_prd_ns[st_pred_id_index] += 1;
250
251 //loop over the Hit object and get the real sector hit at ST
252 for (uint32_t j = 0; j < st_hits.size(); j++)
253 {
254 int phi_sec_hit_sector = st_hits[j]->sector;
255 if (st_pred_id == phi_sec_hit_sector)
256 {
257 N_recd_hit_ns[st_pred_id_index] += 1;
258 break;
259 }
260 }
261 }// end of nose section loop
262 } // end if (st_pred_id != 0)
263 }// end of charged track loop
264
265 japp->RootFillUnLock(this); //RELEASE ROOT FILL LOCK
266
267 return NOERROR;
268}
269
270//------------------
271// erun
272//------------------
273jerror_t JEventProcessor_ST_online_efficiency::erun(void)
274{
275 // This is called whenever the run number changes, before it is
276 // changed to give you a chance to clean up before processing
277 // events from the next run number.
278 return NOERROR;
279}
280
281//------------------
282// fini
283//------------------
284jerror_t JEventProcessor_ST_online_efficiency::fini(void)
285{
286 // Called before program exit after event processing is finished.
287 for (uint32_t i = 0; i < NCHANNELS; i++)
288 {
289 //hit object
290 h_N_trck_prd_All->Fill(i+1,double(N_trck_prd_All[i]));
291 h_N_recd_hit_All->Fill(i+1,double(N_recd_hit_All[i]));
292 h_N_trck_prd_ss->Fill(i+1,double(N_trck_prd_ss[i]));
293 h_N_recd_hit_ss->Fill(i+1,double(N_recd_hit_ss[i]));
294 h_N_trck_prd_bs->Fill(i+1,double(N_trck_prd_bs[i]));
295 h_N_recd_hit_bs->Fill(i+1,double(N_recd_hit_bs[i]));
296 h_N_trck_prd_ns->Fill(i+1,double(N_trck_prd_ns[i]));
297 h_N_recd_hit_ns->Fill(i+1,double(N_recd_hit_ns[i]));
298 }
299 return NOERROR;
300}
301