Bug Summary

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