Bug Summary

File:libraries/TOF/DTOFHit_factory.cc
Location:line 186, column 20
Description:Dereference of null pointer

Annotated Source Code

1// $Id: DTOFHit_factory.cc 7442 2011-02-17 14:10:59Z zihlmann $
2//
3// File: DTOFHit_factory.cc
4// Created: Thu Jun 9 10:05:21 EDT 2005
5// Creator: davidl (on Darwin wire129.jlab.org 7.8.0 powerpc)
6//
7#include <iostream>
8using namespace std;
9
10#include "DTOFHit_factory.h"
11#include "DTOFRawHit.h"
12#include "DTOFRawHitMC.h"
13#include "DTOFHit.h"
14#include <math.h>
15
16//#define NaN std::numeric_limits<double>::quiet_NaN()
17#define NaN__builtin_nan("") __builtin_nan("")
18
19//------------------
20// brun
21//------------------
22jerror_t DTOFHit_factory::brun(JEventLoop *loop, int runnumber)
23{
24
25 map<string, double> tofparms;
26
27 if ( !loop->GetCalib("TOF/tof_parms", tofparms)){
28 cout<<"DTOFHit_factory: loading values from TOF data base"<<endl;
29 } else {
30 cout << "DTOFHit_factory: Error loading values from TOF data base" <<endl;
31
32 C_EFFECTIVE = 15.; // set to some reasonable value
33 HALFPADDLE = 126; // set to some reasonable value
34 E_THRESHOLD = 0.0005; // energy threshold in GeV
35 ATTEN_LENGTH = 400.; // 400cm attenuation length
36 return NOERROR;
37 }
38
39 C_EFFECTIVE = tofparms["TOF_C_EFFECTIVE"];
40 HALFPADDLE = tofparms["TOF_HALFPADDLE"];
41 E_THRESHOLD = tofparms["TOF_E_THRESHOLD"];
42 ATTEN_LENGTH = tofparms["TOF_ATTEN_LENGTH"];
43 return NOERROR;
44
45}
46
47//------------------
48// evnt
49//------------------
50jerror_t DTOFHit_factory::evnt(JEventLoop *loop, int eventnumber)
51{
52
53 vector<const DTOFRawHit*> hits;
54 loop->Get(hits,TOF_POINT_TAG.c_str());
55
56 vector<const DTOFRawHit*> P1hitsL;
57 vector<const DTOFRawHit*> P1hitsR;
58 vector<const DTOFRawHit*> P2hitsL;
59 vector<const DTOFRawHit*> P2hitsR;
60
61 int P1L[100];
62 int P1R[100];
63 int P2L[100];
64 int P2R[100];
65
66 int c1l = 0;
67 int c1r = 0;
68 int c2l = 0;
69 int c2r = 0;
70
71 // sort the tof hits into left and right PMTs for both planes
72
73 for (unsigned int i = 0; i < hits.size(); i++){
1
Loop condition is false. Execution continues on line 94
74 const DTOFRawHit *hit = hits[i];
75 if (hit->plane){
76 if (hit->lr){
77 P2hitsR.push_back(hit);
78 P2R[c2r++] = i;
79 } else {
80 P2hitsL.push_back(hit);
81 P2L[c2l++] = i;
82 }
83 } else {
84 if (hit->lr){
85 P1hitsR.push_back(hit);
86 P1R[c1r++] = i;
87 } else {
88 P1hitsL.push_back(hit);
89 P1L[c1l++] = i;
90 }
91 }
92 }
93
94 for (unsigned int i=0; i<P1hitsL.size(); i++){
2
Loop condition is false. Execution continues on line 124
95 int bar = P1hitsL[i]->bar;
96 if (bar>40){ // this is a half paddle
97 DTOFHit *hit = new DTOFHit;
98 hit->bar = bar;
99 hit->orientation = P1hitsL[i]->plane;
100 hit->E_north = P1hitsL[i]->dE;
101 hit->E_south = 0.0;
102 hit->t_north = P1hitsL[i]->t;
103 hit->t_south = 0.0;
104 _data.push_back(hit);
105 hit->AddAssociatedObject(P1hitsL[i]);
106
107 } else {
108 for (unsigned int j=0; j<P1hitsR.size(); j++){
109 if (bar==P1hitsR[j]->bar){
110 DTOFHit *hit = new DTOFHit;
111 hit->bar = bar;
112 hit->orientation = P1hitsL[i]->plane;
113 hit->E_north = P1hitsL[i]->dE;
114 hit->E_south = P1hitsR[j]->dE;
115 hit->t_north = P1hitsL[i]->t;
116 hit->t_south = P1hitsR[j]->t;
117 _data.push_back(hit);
118 hit->AddAssociatedObject(P1hitsL[i]);
119 hit->AddAssociatedObject(P1hitsR[j]);
120 }
121 }
122 }
123 }
124 for (unsigned int j=0; j<P1hitsR.size(); j++){
3
Loop condition is false. Execution continues on line 140
125 int bar = P1hitsR[j]->bar;
126 if (bar>40){ // this is a half paddle
127 DTOFHit *hit = new DTOFHit;
128 hit->bar = bar;
129 hit->orientation = P1hitsR[j]->plane;
130 hit->E_north = 0.0;
131 hit->E_south = P1hitsR[j]->dE;
132 hit->t_north = 0.0;
133 hit->t_south = P1hitsR[j]->t;
134 _data.push_back(hit);
135 hit->AddAssociatedObject(P1hitsR[j]);
136 }
137 }
138
139
140 for (unsigned int i=0; i<P2hitsL.size(); i++){
4
Loop condition is false. Execution continues on line 169
141 int bar = P2hitsL[i]->bar;
142 if (bar>40){
143 DTOFHit *hit = new DTOFHit;
144 hit->bar = bar;
145 hit->orientation = P2hitsL[i]->plane;
146 hit->E_north = P2hitsL[i]->dE;
147 hit->E_south = 0.0;
148 hit->t_north = P2hitsL[i]->t;
149 hit->t_south = 0.0;
150 _data.push_back(hit);
151 hit->AddAssociatedObject(P2hitsL[i]);
152 } else {
153 for (unsigned int j=0; j<P2hitsR.size(); j++){
154 if (bar==P2hitsR[j]->bar){
155 DTOFHit *hit = new DTOFHit;
156 hit->bar = bar;
157 hit->orientation = P2hitsL[i]->plane;
158 hit->E_north = P2hitsL[i]->dE;
159 hit->E_south = P2hitsR[j]->dE;
160 hit->t_north = P2hitsL[i]->t;
161 hit->t_south = P2hitsR[j]->t;
162 _data.push_back(hit);
163 hit->AddAssociatedObject(P2hitsL[i]);
164 hit->AddAssociatedObject(P2hitsR[j]);
165 }
166 }
167 }
168 }
169 for (unsigned int j=0; j<P2hitsR.size(); j++){
5
Loop condition is true. Entering loop body
7
Loop condition is true. Entering loop body
9
Loop condition is true. Entering loop body
11
Loop condition is false. Execution continues on line 184
170 int bar = P2hitsR[j]->bar;
171 if (bar>40){ // this is a half paddle
6
Taking false branch
8
Taking false branch
10
Taking true branch
172 DTOFHit *hit = new DTOFHit;
173 hit->bar = bar;
174 hit->orientation = P2hitsR[j]->plane;
175 hit->E_north = 0.0;
176 hit->E_south = P2hitsR[j]->dE;
177 hit->t_north = 0.0;
178 hit->t_south = P2hitsR[j]->t;
179 _data.push_back(hit);
180 hit->AddAssociatedObject(P2hitsR[j]);
181 }
182 }
183
184 for (int i=0;i<(int)_data.size(); i++) {
12
Loop condition is true. Entering loop body
185
186 DTOFHit *hit = _data[i];
13
Dereference of null pointer
187
188 int check = -1;
189 if (hit->E_north > E_THRESHOLD) {
190 check++;
191 }
192 if (hit->E_south > E_THRESHOLD) {
193 check++;
194 }
195
196 if (check > 0 ) {
197 hit->meantime = (hit->t_north+hit->t_south)/2. - HALFPADDLE/C_EFFECTIVE;
198 hit->timediff = (hit->t_south - hit->t_north)/2.;
199 float pos = hit->timediff * C_EFFECTIVE;
200 hit->pos = pos;
201 hit->dpos = 2.; // manually/artificially set to 2cm.
202
203 // mean energy deposition at the location of the hit position
204 // devide by two to be comparable with single PMT hits
205 float en = hit->E_north * exp((HALFPADDLE-pos)/ATTEN_LENGTH) ;
206 float es = hit->E_south * exp((HALFPADDLE+pos)/ATTEN_LENGTH) ;
207 float emean = (en+es)/2.;
208 hit->dE = emean;
209
210 } else {
211 hit->meantime = NaN__builtin_nan("");
212 hit->timediff = NaN__builtin_nan("");
213 hit->pos = NaN__builtin_nan("");
214 hit->dpos = NaN__builtin_nan("");
215 hit->dE = NaN__builtin_nan("");
216 }
217
218 }
219
220 return NOERROR;
221}
222