Bug Summary

File:plugins/monitoring/ST_online_Tresolution/JEventProcessor_ST_online_Tresolution.cc
Location:line 105, column 28
Description:Called C++ object pointer is null

Annotated Source Code

1// $Id$
2//
3// File: JEventProcessor_ST_online_Tresolution.cc
4// Created: Fri Jan 8 09:07:34 EST 2016
5// Creator: mkamel (on Linux ifarm1401 2.6.32-431.el6.x86_64 x86_64)
6//
7
8#include "JEventProcessor_ST_online_Tresolution.h"
9#include "TRIGGER/DTrigger.h"
10using namespace jana;
11
12
13// Routine used to create our JEventProcessor
14#include <JANA/JApplication.h>
15#include <JANA/JFactory.h>
16
17#include "RF/DRFTime.h"
18
19extern "C"{
20void InitPlugin(JApplication *app){
21 InitJANAPlugin(app);
22 app->AddProcessor(new JEventProcessor_ST_online_Tresolution());
23}
24} // "C"
25
26
27//------------------
28// JEventProcessor_ST_online_Tresolution (Constructor)
29//------------------
30JEventProcessor_ST_online_Tresolution::JEventProcessor_ST_online_Tresolution()
31{
32
33}
34
35//------------------
36// ~JEventProcessor_ST_online_Tresolution (Destructor)
37//------------------
38JEventProcessor_ST_online_Tresolution::~JEventProcessor_ST_online_Tresolution()
39{
40
41}
42
43//------------------
44// init
45//------------------
46jerror_t JEventProcessor_ST_online_Tresolution::init(void)
47{
48 // This is called once at program startup. If you are creating
49 // and filling historgrams in this plugin, you should lock the
50 // ROOT mutex like this:
51 //
52 // japp->RootWriteLock();
53 // ... fill historgrams or trees ...
54 // japp->RootUnLock();
55 //
56 // **************** define histograms *************************
57
58 TDirectory *main = gDirectory(TDirectory::CurrentDirectory());
59 gDirectory(TDirectory::CurrentDirectory())->mkdir("st_Tresolution")->cd();
60 h2_CorrectedTime_z = new TH2I*[NCHANNELS];
61
62 // All my Calculations in 2015 were using the binning below
63 NoBins_time = 80;
64 NoBins_z = 1300;
65 time_lower_limit = -4.0;
66 time_upper_limit = 4.0;
67 z_lower_limit = 35.0;
68 z_upper_limit = 100.0;
69 for (Int_t i = 0; i < NCHANNELS; i++)
70 {
71 h2_CorrectedTime_z[i] = new TH2I(Form("h2_CorrectedTime_z_%i", i+1), "Corrected Time vs. Z; Z (cm); Propagation Time (ns)", NoBins_z,z_lower_limit,z_upper_limit, NoBins_time, time_lower_limit, time_upper_limit);
72 }
73
74 gDirectory(TDirectory::CurrentDirectory())->cd("../");
75 main->cd();
76
77 return NOERROR;
78}
79
80//------------------
81// brun
82//------------------
83jerror_t JEventProcessor_ST_online_Tresolution::brun(JEventLoop *eventLoop, int32_t runnumber)
84{
85 // This is called whenever the run number changes
86
87 //RF Period
88 vector<double> locRFPeriodVector;
89 eventLoop->GetCalib("PHOTON_BEAM/RF/rf_period", locRFPeriodVector);
90 dRFBunchPeriod = locRFPeriodVector[0];
91
92 // Obtain the target center along z;
93 map<string,double> target_params;
94 if (eventLoop->GetCalib("/TARGET/target_parms", target_params))
1
Taking true branch
95 jout << "Error loading /TARGET/target_parms/ !" << endl;
96 if (target_params.find("TARGET_Z_POSITION") != target_params.end())
2
Taking false branch
97 z_target_center = target_params["TARGET_Z_POSITION"];
98 else
99 jerr << "Unable to get TARGET_Z_POSITION from /TARGET/target_parms !" << endl;
100
101 // Obtain the Start Counter geometry
102 DApplication* dapp = dynamic_cast<DApplication*>(eventLoop->GetJApplication());
3
Calling 'JEventLoop::GetJApplication'
4
Returning from 'JEventLoop::GetJApplication'
5
'dapp' initialized here
103 if(!dapp)
6
Assuming 'dapp' is null
7
Taking true branch
104 _DBG_std::cerr<<"plugins/monitoring/ST_online_Tresolution/JEventProcessor_ST_online_Tresolution.cc"
<<":"<<104<<" "
<<"Cannot get DApplication from JEventLoop! (are you using a JApplication based program?)"<<endl;
105 DGeometry* locGeometry = dapp->GetDGeometry(eventLoop->GetJEvent().GetRunNumber());
8
Called C++ object pointer is null
106 locGeometry->GetStartCounterGeom(sc_pos, sc_norm);
107 // Propagation Time constant
108 if(eventLoop->GetCalib("START_COUNTER/propagation_time_corr", propagation_time_corr))
109 jout << "Error loading /START_COUNTER/propagation_time_corr !" << endl;
110 return NOERROR;
111}
112
113//------------------
114// evnt
115//------------------
116jerror_t JEventProcessor_ST_online_Tresolution::evnt(JEventLoop *loop, uint64_t eventnumber)
117{
118 // This is called for every event. Use of common resources like writing
119 // to a file or filling a histogram should be mutex protected. Using
120 // loop->Get(...) to get reconstructed objects (and thereby activating the
121 // reconstruction algorithm) should be done outside of any mutex lock
122 // since multiple threads may call this method at the same time.
123 // Here's an example:
124 //
125 // vector<const MyDataClass*> mydataclasses;
126 // loop->Get(mydataclasses);
127 //
128 // japp->RootWriteLock();
129 // ... fill historgrams or trees ...
130 // japp->RootUnLock();
131 double speed_light = 29.9792458;
132
133 const DTrigger* locTrigger = NULL__null;
134 loop->GetSingle(locTrigger);
135 if(locTrigger->Get_L1FrontPanelTriggerBits() != 0)
136 return NOERROR;
137
138 // Get the particleID object for each run
139 // Be sure that DRFTime_factory::init() and brun() are called
140 vector<const DParticleID *> locParticleID_algos;
141 loop->Get(locParticleID_algos);
142 if(locParticleID_algos.size() < 1)
143 {
144 _DBG_std::cerr<<"plugins/monitoring/ST_online_Tresolution/JEventProcessor_ST_online_Tresolution.cc"
<<":"<<144<<" "
<<"Unable to get a DParticleID object! NO PID will be done!"<<endl;
145 return RESOURCE_UNAVAILABLE;
146 }
147 auto locParticleID = locParticleID_algos[0];
148
149 // We want to be use some of the tools available in the RFTime factory
150 // Specifically stepping the RF back to a chosen time
151 vector<const DRFTime *> locRFTimes;
152 loop->Get(locRFTimes); // make sure brun() gets called for this factory!
153 auto locRFTimeFactory = static_cast<DRFTime_factory*>(loop->GetFactory("DRFTime"));
154
155
156 // SC hits
157 vector<const DSCHit *> scHitVector;
158 loop->Get(scHitVector);
159
160 // RF time object
161 const DRFTime* thisRFTime = NULL__null;
162 vector <const DRFTime*> RFTimeVector;
163 loop->Get(RFTimeVector);
164 if (RFTimeVector.size() != 0)
165 thisRFTime = RFTimeVector[0];
166
167 // Grab charged tracks
168 vector<const DChargedTrack *> chargedTrackVector;
169 loop->Get(chargedTrackVector);
170
171 // Grab the associated detector matches object
172 const DDetectorMatches* locDetectorMatches = NULL__null;
173 loop->GetSingle(locDetectorMatches);
174
175 // Grab the associated RF bunch object
176 const DEventRFBunch *thisRFBunch = NULL__null;
177 loop->GetSingle(thisRFBunch, "Calibrations");
178
179 // FILL HISTOGRAMS
180 // Since we are filling histograms local to this plugin, it will not interfere with other ROOT operations: can use plugin-wide ROOT fill lock
181 japp->RootFillLock(this); //ACQUIRE ROOT FILL LOCK
182
183 for (uint32_t i = 0; i < chargedTrackVector.size(); i++)
184 {
185 // Grab the charged track and declare time based track object
186 const DChargedTrack *thisChargedTrack = chargedTrackVector[i];
187 // Grab associated time based track object by selecting charged track with best FOM
188 const DTrackTimeBased *timeBasedTrack = thisChargedTrack->Get_BestTrackingFOM()->Get_TrackTimeBased();
189 // Implement quality cuts for the time based tracks
190 trackingFOMCut = 0.0027; // 3 sigma cut
191 //trackingFOMCut = 0.0001; // 5 sigma cut
192 if(timeBasedTrack->FOM < trackingFOMCut) continue;
193
194 // Grab the ST hit match params object and cut on only tracks matched to the ST
195 shared_ptr<const DSCHitMatchParams> locBestSCHitMatchParams;
196 foundSC = locParticleID->Get_BestSCMatchParams(timeBasedTrack, locDetectorMatches, locBestSCHitMatchParams);
197 if (!foundSC) continue;
198
199 // Define vertex vector and cut on target/scattering chamber geometry
200 vertex = timeBasedTrack->position();
201 z_v = vertex.z();
202 r_v = vertex.Perp();
203
204 z_vertex_cut = fabs(z_target_center - z_v) <= 15.0;
205 r_vertex_cut = r_v < 0.5;
206 // Apply vertex cut
207 if (!z_vertex_cut) continue;
208 if (!r_vertex_cut) continue;
209 bool st_match = locDetectorMatches->Get_SCMatchParams(timeBasedTrack, st_params);
210 // If st_match = true, there is a match between this track and the ST
211 if (!st_match) continue;
212
213 DVector3 IntersectionPoint, IntersectionMomentum;
214 shared_ptr<DSCHitMatchParams> locSCHitMatchParams;
215 vector<DTrackFitter::Extrapolation_t>extrapolations=timeBasedTrack->extrapolations.at(SYS_START);
216 bool sc_match_pid = locParticleID->Cut_MatchDistance(extrapolations, st_params[0]->dSCHit, st_params[0]->dSCHit->t, locSCHitMatchParams, true, &IntersectionPoint, &IntersectionMomentum);
217
218 if(!sc_match_pid) continue;
219 // Cut on the number of particle votes to find the best RF time
220 if (thisRFBunch->dNumParticleVotes < 2) continue;
221 // Calculate the TOF estimate of the target time
222
223 // Calculate the RF estimate of the target time
224 locCenteredRFTime = thisRFTime->dTime;
225 // RF time at center of target
226 locCenterToVertexRFTime = (timeBasedTrack->z() - z_target_center)*(1.0/speed_light); // Time correction for photon from target center to vertex of track
227 locVertexRFTime = locCenteredRFTime + locCenterToVertexRFTime;
228 sc_index= locSCHitMatchParams->dSCHit->sector - 1;
229 // Start Counter geometry in hall coordinates
230 sc_pos_soss = sc_pos[sc_index][0].z(); // Start of straight section
231 sc_pos_eoss = sc_pos[sc_index][1].z(); // End of straight section
232 sc_pos_eobs = sc_pos[sc_index][11].z(); // End of bend section
233 sc_pos_eons = sc_pos[sc_index][12].z(); // End of nose section
234 //Get the ST time walk corrected time
235 st_time = st_params[0]->dSCHit->t;
236 // Get the Flight time
237 FlightTime = locSCHitMatchParams->dFlightTime;
238 //St time corrected for the flight time
239 st_corr_FlightTime = st_time - FlightTime;
240 // SC_RFShiftedTime = locRFTimeFactory->Step_TimeToNearInputTime(locVertexRFTime, st_corr_FlightTime);
241 // Z intersection of charged track and SC
242 locSCzIntersection = IntersectionPoint.z();
243 ////////////////////////////////////////////////////////////////////
244 /// Fill the sc time histograms corrected for walk and propagation//
245 ////////////////////////////////////////////////////////////////////
246 // Read the constants from CCDB
247 double incpt_ss = propagation_time_corr[sc_index][0];
248 double slope_ss = propagation_time_corr[sc_index][1];
249 double incpt_bs = propagation_time_corr[sc_index][2];
250 double slope_bs = propagation_time_corr[sc_index][3];
251 double incpt_ns = propagation_time_corr[sc_index][4];
252 double slope_ns = propagation_time_corr[sc_index][5];
253 // Straight Sections
254 if (locSCzIntersection > sc_pos_soss && locSCzIntersection <= sc_pos_eoss)
255 {
256 Corr_Time_ss = st_corr_FlightTime - (incpt_ss + (slope_ss * locSCzIntersection));
257 SC_RFShiftedTime = locRFTimeFactory->Step_TimeToNearInputTime(locVertexRFTime, Corr_Time_ss);
258 h2_CorrectedTime_z[sc_index]->Fill(locSCzIntersection,Corr_Time_ss -SC_RFShiftedTime);
259 }
260 // Bend Sections
261 if(locSCzIntersection > sc_pos_eoss && locSCzIntersection <= sc_pos_eobs)
262 {
263 Corr_Time_bs = st_corr_FlightTime - (incpt_bs + (slope_bs * locSCzIntersection));
264 SC_RFShiftedTime = locRFTimeFactory->Step_TimeToNearInputTime(locVertexRFTime, Corr_Time_bs);
265 h2_CorrectedTime_z[sc_index]->Fill(locSCzIntersection,Corr_Time_bs - SC_RFShiftedTime);
266 }
267 // Nose Sections
268 if(locSCzIntersection > sc_pos_eobs && locSCzIntersection <= sc_pos_eons)
269 {
270 Corr_Time_ns = st_corr_FlightTime - (incpt_ns + (slope_ns * locSCzIntersection));
271 SC_RFShiftedTime = locRFTimeFactory->Step_TimeToNearInputTime(locVertexRFTime, Corr_Time_ns);
272 h2_CorrectedTime_z[sc_index]->Fill(locSCzIntersection,Corr_Time_ns - SC_RFShiftedTime);
273 }
274 } // sc charged tracks
275
276 japp->RootFillUnLock(this); //RELEASE ROOT FILL LOCK
277
278 return NOERROR;
279}
280
281//------------------
282// erun
283//------------------
284jerror_t JEventProcessor_ST_online_Tresolution::erun(void)
285{
286 // This is called whenever the run number changes, before it is
287 // changed to give you a chance to clean up before processing
288 // events from the next run number.
289 return NOERROR;
290}
291
292//------------------
293// fini
294//------------------
295jerror_t JEventProcessor_ST_online_Tresolution::fini(void)
296{
297 // Called before program exit after event processing is finished.
298 return NOERROR;
299}
300