Bug Summary

File:plugins/monitoring/ST_online_efficiency/JEventProcessor_ST_online_efficiency.cc
Location:line 111, 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 japp->RootWriteLock(); //ACQUIRE ROOT LOCK!!
56 // Create root folder for ST and cd to it, store main dir
57 TDirectory *main = gDirectory(TDirectory::CurrentDirectory());
58 gDirectory(TDirectory::CurrentDirectory())->mkdir("st_efficiency")->cd();
59 //eff histos
60 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);
61 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);
62
63 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);
64 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);
65
66 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);
67 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);
68
69 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);
70 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);
71
72 h_ST_Eff_All= new TH1D("h_ST_Eff_All", " Efficiency; Sector; N_{RECD}/N_{TRCK}", 31, -0.5, 30.5);
73 h_ST_Eff_ss = new TH1D("h_ST_Eff_ss", " SS Efficiency; Sector; N_{RECD}/N_{TRCK}", 31, -0.5, 30.5);
74 h_ST_Eff_bs = new TH1D("h_ST_Eff_bs", " BS Efficiency; Sector; N_{RECD}/N_{TRCK}", 31, -0.5, 30.5);
75 h_ST_Eff_ns = new TH1D("h_ST_Eff_ns", " NS Efficiency; Sector; N_{RECD}/N_{TRCK}", 31, -0.5, 30.5);
76
77 gDirectory(TDirectory::CurrentDirectory())->cd("../");
78 main->cd();
79 japp->RootUnLock(); //RELEASE ROOT LOCK!!
80 // Initialize counters
81 memset(N_trck_prd_All, 0, sizeof(N_trck_prd_All));
82 memset(N_recd_hit_All, 0, sizeof(N_recd_hit_All));
83 memset(N_trck_prd_ss, 0, sizeof(N_trck_prd_ss));
84 memset(N_recd_hit_ss, 0, sizeof(N_recd_hit_ss));
85 memset(N_trck_prd_bs, 0, sizeof(N_trck_prd_bs));
86 memset(N_recd_hit_bs, 0, sizeof(N_recd_hit_bs));
87 memset(N_trck_prd_ns, 0, sizeof(N_trck_prd_ns));
88 memset(N_recd_hit_ns, 0, sizeof(N_recd_hit_ns));
89
90 return NOERROR;
91}
92
93//------------------
94// brun
95//------------------
96jerror_t JEventProcessor_ST_online_efficiency::brun(JEventLoop *eventLoop, int32_t runnumber)
97{
98 // This is called whenever the run number changes
99 // Obtain the target center along z;
100 map<string,double> target_params;
101 if (eventLoop->GetCalib("/TARGET/target_parms", target_params))
1
Taking true branch
102 jout << "Error loading /TARGET/target_parms/ !" << endl;
103 if (target_params.find("TARGET_Z_POSITION") != target_params.end())
2
Taking true branch
104 z_target_center = target_params["TARGET_Z_POSITION"];
105 else
106 jerr << "Unable to get TARGET_Z_POSITION from /TARGET/target_parms !" << endl;
107 // Obtain the Start Counter geometry
108 DApplication* dapp = dynamic_cast<DApplication*>(eventLoop->GetJApplication());
3
Calling 'JEventLoop::GetJApplication'
4
Returning from 'JEventLoop::GetJApplication'
5
'dapp' initialized here
109 if(!dapp)
6
Assuming 'dapp' is null
7
Taking true branch
110 _DBG_std::cerr<<"plugins/monitoring/ST_online_efficiency/JEventProcessor_ST_online_efficiency.cc"
<<":"<<110<<" "
<<"Cannot get DApplication from JEventLoop! (are you using a JApplication based program?)"<<endl;
111 DGeometry* locGeometry = dapp->GetDGeometry(eventLoop->GetJEvent().GetRunNumber());
8
Called C++ object pointer is null
112 locGeometry->GetStartCounterGeom(sc_pos, sc_norm);
113 return NOERROR;
114}
115
116//------------------
117// evnt
118//------------------
119jerror_t JEventProcessor_ST_online_efficiency::evnt(JEventLoop *eventLoop, uint64_t eventnumber)
120{
121 // This is called for every event. Use of common resources like writing
122 // to a file or filling a histogram should be mutex protected. Using
123 // loop->Get(...) to get reconstructed objects (and thereby activating the
124 // reconstruction algorithm) should be done outside of any mutex lock
125 // since multiple threads may call this method at the same time.
126 // Here's an example:
127 //
128 // vector<const MyDataClass*> mydataclasses;
129 // loop->Get(mydataclasses);
130 //
131 // japp->RootWriteLock();
132 // ... fill historgrams or trees ...
133 // japp->RootUnLock();
134 vector<const DSCDigiHit*> st_adc_digi_hits;
135 vector<const DParticleID*> pid_algorithm;
136 vector<const DSCHit*> st_hits;
137 vector<const DChargedTrack*> chargedTrackVector;
138 eventLoop->Get(st_adc_digi_hits);
139 eventLoop->Get(pid_algorithm);
140 eventLoop->Get(st_hits);
141 eventLoop->Get(chargedTrackVector);
142 // Grab the associated detector matches object
143 const DDetectorMatches* locDetectorMatches = NULL__null;
144 eventLoop->GetSingle(locDetectorMatches);
145
146 // Lock ROOT mutex so other threads won't interfere
147 japp->RootWriteLock();
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 japp->RootUnLock();
265 return NOERROR;
266}
267
268//------------------
269// erun
270//------------------
271jerror_t JEventProcessor_ST_online_efficiency::erun(void)
272{
273 // This is called whenever the run number changes, before it is
274 // changed to give you a chance to clean up before processing
275 // events from the next run number.
276 return NOERROR;
277}
278
279//------------------
280// fini
281//------------------
282jerror_t JEventProcessor_ST_online_efficiency::fini(void)
283{
284 // Called before program exit after event processing is finished.
285 for (uint32_t i = 0; i < NCHANNELS; i++)
286 {
287 //hit object
288 h_N_trck_prd_All->Fill(i+1,double(N_trck_prd_All[i]));
289 h_N_recd_hit_All->Fill(i+1,double(N_recd_hit_All[i]));
290 h_N_trck_prd_ss->Fill(i+1,double(N_trck_prd_ss[i]));
291 h_N_recd_hit_ss->Fill(i+1,double(N_recd_hit_ss[i]));
292 h_N_trck_prd_bs->Fill(i+1,double(N_trck_prd_bs[i]));
293 h_N_recd_hit_bs->Fill(i+1,double(N_recd_hit_bs[i]));
294 h_N_trck_prd_ns->Fill(i+1,double(N_trck_prd_ns[i]));
295 h_N_recd_hit_ns->Fill(i+1,double(N_recd_hit_ns[i]));
296 }
297 return NOERROR;
298}
299