Bug Summary

File:programs/Simulation/mcsmear/mcsmear.cc
Location:line 253, column 20
Description:Potential leak of memory pointed to by 'path_stripped'

Annotated Source Code

1// $Id: mcsmear.cc 19023 2015-07-14 20:23:27Z beattite $
2//
3// Created June 22, 2005 David Lawrence
4
5
6// The following flag can be used to switch from the classic mode where
7// the event loop is implemented in main() to a JANA based event-loop.
8// NOTE: for consistency, one should set the value of #define JANA_ENABLED
9// in smear.cc to the same value!
10#define USE_JANA1 1
11
12#include <iostream>
13#include <iomanip>
14using namespace std;
15
16#include <TF1.h>
17#include <TFile.h>
18#include <TH2.h>
19#include <TH1.h>
20
21#include <signal.h>
22#include <time.h>
23
24#if USE_JANA1
25#include <DANA/DApplication.h>
26#include "MyProcessor.h"
27#include "JFactoryGenerator_ThreadCancelHandler.h"
28
29#include <CDC/DCDCWire.h>
30//#include <FDC/DFDCWire.h>
31#include <HDGEOMETRY/DGeometry.h>
32
33#endif
34
35#include "units.h"
36#include "HDDM/hddm_s.hpp"
37
38void Smear(hddm_s::HDDM *record);
39void ParseCommandLineArguments(int narg, char* argv[]);
40void Usage(void);
41
42extern void SetSeeds(const char *vals);
43
44char *INFILENAME = NULL__null;
45char *OUTFILENAME = NULL__null;
46int QUIT = 0;
47
48bool ADD_NOISE = false;
49bool SMEAR_HITS = true;
50bool SMEAR_BCAL = true;
51bool FDC_ELOSS_OFF = false;
52bool IGNORE_SEEDS = false;
53
54// setup response parameters
55double BCAL_DARKRATE_GHZ = 0.;// 0.0176 (from calibDB BCAL/bcal_parms) for 4x4 array
56double BCAL_SIGMA_SIG_RELATIVE = 0.;// 0.105 (from calibDB BCAL/bcal_parms)
57double BCAL_SIGMA_PED_RELATIVE = 0.;// 0.139 (from calibDB BCAL/bcal_parms)
58double BCAL_SIPM_GAIN_VARIATION = 0.;// 0.04 (from calibDB BCAL/bcal_parms)
59double BCAL_XTALK_FRACT = 0.;// 0.157 (from calibDB BCAL/bcal_parms)
60double BCAL_INTWINDOW_NS = 0.;// 100 (from calibDB BCAL/bcal_parms)
61double BCAL_DEVICEPDE = 0.;// 0.21 (from calibDB BCAL/bcal_parms)
62double BCAL_SAMPLING_FRACT = 0.;// 0.095 (from calibDB BCAL/bcal_parms)
63double BCAL_PHOTONSPERSIDEPERMEV_INFIBER = 0.0;// 75 (from calibDB BCAL/bcal_parms)
64double BCAL_AVG_DARK_DIGI_VALS_PER_EVENT = 0.0; // 240 used to set thresholds
65double BCAL_SAMPLINGCOEFA = 0.0; // 0.042 (from calibDB BCAL/bcal_parms)
66double BCAL_SAMPLINGCOEFB = 0.0; // 0.013 (from calibDB BCAL/bcal_parms)
67double BCAL_TIMEDIFFCOEFA = 0.0; // 0.07 * sqrt( 2 ) (from calibDB BCAL/bcal_parms)
68double BCAL_TIMEDIFFCOEFB = 0.0; // 0.00 * sqrt( 2 ) (from calibDB BCAL/bcal_parms)
69double BCAL_TWO_HIT_RESOL = 0.0; // 50. (from calibDB BCAL/bcal_parms)
70double BCAL_mevPerPE = 0.31; // Energy corresponding to one pixel firing in MeV
71
72int BCAL_NUM_MODULES = 48;
73int BCAL_NUM_LAYERS = 4;
74int BCAL_NUM_SECTORS = 4;
75
76double BCAL_BASE_TIME_OFFSET = 0; // -100.0 (from calibDB BCAL/base_time_offset)
77double BCAL_TDC_BASE_TIME_OFFSET = 0; // -100.0 (from calibDB BCAL/base_time_offset)
78
79vector<vector<double> > attenuation_parameters; // Avg. of 525 (from calibDB BCAL/attenuation_parameters)
80vector<double> effective_velocities; // 16.75 (from calibDB BCAL/effective_velocities)
81
82double BCAL_ADC_THRESHOLD_MEV = 2.2; // MeV (To be updated/improved)
83double BCAL_FADC_TIME_RESOLUTION = 0.3; // ns (To be updated/improved)
84double BCAL_TDC_TIME_RESOLUTION = 0.3; // ns (To be updated/improved)
85double BCAL_MEV_PER_ADC_COUNT = 0.029; // MeV per integrated ADC count (based on Spring 2015 calibrations)
86double BCAL_NS_PER_ADC_COUNT = 0.0; // 0.0625 ns per ADC count (from calibDB BCAL/digi_scales)
87double BCAL_NS_PER_TDC_COUNT = 0.0; // 0.0559 ns per TDC count (from calibDB BCAL/digi_scales)
88
89// BCAL flags
90bool NO_T_SMEAR = false;
91bool NO_DARK_PULSES = false;
92bool NO_SAMPLING_FLUCTUATIONS = false;
93bool NO_SAMPLING_FLOOR_TERM = false;
94bool NO_POISSON_STATISTICS = false;
95
96double FTOF_BAR_THRESHOLD = 0.0;
97double STC_PADDLE_THRESHOLD = 0.0;
98double PSC_THRESHOLD = 0.0;
99double PS_THRESHOLD = 0.0;
100
101double TAGM_TSIGMA = 0.200; // ns
102double TAGH_TSIGMA = 0.350; // ns
103double TAGM_FADC_TSIGMA = 0.350; // ns
104double TAGH_FADC_TSIGMA = 0.450; // ns
105double TAGM_NPIX_PER_GEV = 1.e5;
106double TAGH_NPE_PER_GEV = 5.e5;
107
108// The following are place holders to be filled in with realistic numbers later
109double PS_SIGMA = 0.200; // ns
110double PSC_SIGMA = 0.200; //ns
111double PS_NPIX_PER_GEV = 1.e5;
112double PSC_PHOTONS_PERMEV = 5.e5;
113
114double FCAL_PHOT_STAT_COEF = 0.0; //0.035;
115double FCAL_BLOCK_THRESHOLD = 0.0; //20.0*k_MeV;
116
117double CDC_TDRIFT_SIGMA = 0.0; // 150.0/55.0*1E-9 seconds
118double CDC_TIME_WINDOW = 0.0; // 1000.0E-9 seconds
119double CDC_PEDESTAL_SIGMA = 0.0; // in fC
120double CDC_THRESHOLD_FACTOR = 0.0; // number of pedestal sigmas for determining sparcification threshold
121
122double FDC_TDRIFT_SIGMA = 0.0; // 200.0/55.0*1.0E-9 seconds
123double FDC_CATHODE_SIGMA = 0.0; // 150.0 microns
124double FDC_PED_NOISE = 0.0; // in pC calculated in SmearFDC
125double FDC_THRESHOLD_FACTOR = 0.0; // number of pedestal sigmas for determining sparcification threshold
126double FDC_HIT_DROP_FRACTION = 0.0; // 1000.0E-9
127double FDC_TIME_WINDOW = 0.0; // 1000.0E-9 in seconds
128double FDC_THRESH_KEV = 0.0; // fdc anode discriminator threshold
129
130double START_SIGMA = 0.0; // 300ps
131double START_PHOTONS_PERMEV = 0.0; // used to be 8000 should be more like 200
132
133// TOF parameters will be read from data base later
134double TOF_SIGMA = 100.*k_psec;
135double TOF_PHOTONS_PERMEV = 400.;
136
137double FMWPC_TSIGMA = 10.0; // ns
138double FMWPC_ASIGMA = 0.5E-6;
139double FMWPC_THRESHOLD = 0.0;
140
141double TRIGGER_LOOKBACK_TIME = -100; // ns
142
143bool DROP_TRUTH_HITS=false;
144
145// CDC geometry parameters (for noise)
146vector<unsigned int> NCDC_STRAWS;
147vector<double> CDC_RING_RADIUS;
148
149// FDC geometry and rate parameters (for noise)
150vector<double> FDC_LAYER_Z;
151double FDC_RATE_COEFFICIENT;
152
153using namespace jana;
154
155// histogram
156pthread_mutex_t root_mutex = PTHREAD_MUTEX_INITIALIZER{ { 0, 0, 0, 0, 0, 0, { 0, 0 } } };
157TH2F *fdc_drift_time_smear_hist = NULL__null;
158TH2F *fdc_drift_dist_smear_hist = NULL__null;
159TH2F *fdc_drift_time = NULL__null;
160TH1F *fdc_cathode_charge = NULL__null;
161TH2F *cdc_drift_time = NULL__null;
162TH1F *cdc_charge = NULL__null;
163TH1F *fdc_anode_mult = NULL__null;
164TH2F *cdc_drift_smear = NULL__null;
165
166//-----------
167// main
168//-----------
169int main(int narg,char* argv[])
170{
171 ParseCommandLineArguments(narg, argv);
172
173 // Create DApplication object
174 DApplication dapp(narg, argv);
175 dapp.AddFactoryGenerator(new JFactoryGenerator_ThreadCancelHandler());
176
177 TFile *hfile = new TFile("smear.root","RECREATE","smearing histograms");
178
179 MyProcessor myproc;
180 dapp.Run(&myproc);
181
182 hfile->Write();
183 hfile->Close();
184
185 return 0;
186}
187
188//-----------
189// ParseCommandLineArguments
190//-----------
191void ParseCommandLineArguments(int narg, char* argv[])
192{
193 bool warn_obsolete = false;
194
195 for (int i=1; i<narg; i++) {
1
Assuming 'i' is >= 'narg'
2
Loop condition is false. Execution continues on line 234
196 char *ptr = argv[i];
197
198 if (ptr[0] == '-') {
199 switch(ptr[1]) {
200 case 'h': Usage(); break;
201 case 'o': OUTFILENAME = strdup(&ptr[2]); break;
202 case 'n': warn_obsolete=true; break;
203 case 'N': ADD_NOISE=true; break;
204 case 's': SMEAR_HITS=false; break;
205 case 'i': IGNORE_SEEDS=true; break;
206 case 'r': SetSeeds(&ptr[2]); break;
207 case 'u': CDC_TDRIFT_SIGMA=atof(&ptr[2])*1.0E-9; break;
208 case 't': CDC_TIME_WINDOW=atof(&ptr[2])*1.0E-9; break;
209 case 'U': FDC_TDRIFT_SIGMA=atof(&ptr[2])*1.0E-9; break;
210 case 'C': FDC_CATHODE_SIGMA=atof(&ptr[2])*1.0E-6; break;
211 case 'T': FDC_TIME_WINDOW=atof(&ptr[2])*1.0E-9; break;
212 case 'e': FDC_ELOSS_OFF = true; break;
213 case 'E': CDC_PEDESTAL_SIGMA = atof(&ptr[2])*k_keV; break;
214 case 'd': DROP_TRUTH_HITS=true; break;
215 case 'p': FCAL_PHOT_STAT_COEF = atof(&ptr[2]); break;
216 case 'b': FCAL_BLOCK_THRESHOLD = atof(&ptr[2])*k_MeV; break;
217 case 'B': SMEAR_BCAL = false; break;
218 case 'V': BCAL_ADC_THRESHOLD_MEV = atof(&ptr[2]); break;
219 case 'X': BCAL_FADC_TIME_RESOLUTION = atof(&ptr[2]); break;
220 case 'G': NO_T_SMEAR = true; break;
221 case 'H': NO_DARK_PULSES = true; break;
222 case 'K': NO_SAMPLING_FLUCTUATIONS = true; break;
223 case 'L': NO_SAMPLING_FLOOR_TERM = true; break;
224 case 'M': NO_POISSON_STATISTICS = true; break;
225 case 'f': TOF_SIGMA= atof(&ptr[2])*k_psec; break;
226 case 'S': START_SIGMA= atof(&ptr[2])*k_psec; break;
227 }
228 }
229 else {
230 INFILENAME = argv[i];
231 }
232 }
233
234 if (!INFILENAME){
3
Assuming 'INFILENAME' is non-null
4
Taking false branch
235 cout << endl << "You must enter a filename!" << endl << endl;
236 Usage();
237 }
238
239 if (warn_obsolete) {
5
Taking false branch
240 cout << endl;
241 cout << "WARNING: Use of the \"-n\" option is obsolete. Random noise"
242 << endl;
243 cout << " hits are disabled by default now. To turn them back"
244 << endl;
245 cout << " on use the \"-N\" option." << endl;
246 cout << endl;
247 }
248
249 // Generate output filename based on input filename
250 if (OUTFILENAME == NULL__null) {
6
Taking true branch
251 char *ptr, *path_stripped;
252 path_stripped = ptr = strdup(INFILENAME);
7
Memory is allocated
253 while((ptr = strstr(ptr, "/")))path_stripped = ++ptr;
8
Loop condition is true. Entering loop body
9
Potential leak of memory pointed to by 'path_stripped'
254 ptr = strstr(path_stripped, ".hddm");
255 if(ptr)*ptr=0;
256 char str[256];
257 sprintf(str, "%s_%ssmeared.hddm", path_stripped, ADD_NOISE ? "n":"");
258 OUTFILENAME = strdup(str);
259 }
260
261 cout << "BCAL values will " << (SMEAR_BCAL ? "":"not") << " be smeared"
262
263 << endl;
264 cout << "BCAL values will " << (SMEAR_BCAL ? "":"not") << " be added"
265 << endl;
266}
267
268
269//-----------
270// Usage
271//-----------
272void Usage(void)
273{
274 cout << endl << "Usage:" << endl;
275 cout << " mcsmear [options] file.hddm" << endl;
276 cout << endl;
277 cout << " Read the given, Geant-produced HDDM file as input and smear" << endl;
278 cout << "the truth values for \"hit\" data before writing out to a" << endl;
279 cout << "separate file. The truth values for the thrown particles are" << endl;
280 cout << "not changed. Noise hits can also be added using the -n option." << endl;
281 cout << "Note that all smearing is done using Gaussians, with the " << endl;
282 cout << "sigmas configurable with the options below." << endl;
283 cout << endl;
284 cout << " options:" << endl;
285 cout << " -ofname Write output to a file named \"fname\" (default auto-generate name)" << endl;
286 cout << " -N Add random background hits to CDC and FDC (default is not to add)" << endl;
287 cout << " -s Don't smear real hits (see -B for BCAL, default is to smear)" << endl;
288 cout << " -i Ignore random number seeds found in input HDDM file" << endl;
289 cout << " -r\"s1 s2 s3\" Set initial random number seeds" << endl;
290 cout << " -u# Sigma CDC anode drift time in ns (def:" << CDC_TDRIFT_SIGMA*1.0E9 << "ns)" << endl;
291 cout << " (NOTE: this is only used if -y is also specified!)" << endl;
292 cout << " -y Do NOT apply drift distance dependence error to" << endl;
293 cout << " CDC (default is to apply)" << endl;
294 cout << " -Y Apply constant sigma smearing for FDC drift time. " << endl;
295 cout << " Default is to use a drift-distance dependent parameterization." << endl;
296 cout << " -t# CDC time window for background hits in ns (def:" << CDC_TIME_WINDOW*1.0E9 << "ns)" << endl;
297 cout << " -U# Sigma FDC anode drift time in ns (def:" << FDC_TDRIFT_SIGMA*1.0E9 << "ns)" << endl;
298 cout << " -C# Sigma FDC cathode strips in microns (def:" << FDC_TDRIFT_SIGMA << "ns)" << endl;
299 cout << " -T# FDC time window for background hits in ns (def:" << FDC_TIME_WINDOW*1.0E9 << "ns)" << endl;
300 cout << " -e hdgeant was run with LOSS=0 so scale the FDC cathode" << endl;
301 cout << " pedestal noise (def:false)" << endl;
302 cout << " -d Drop truth hits (default: keep truth hits)" << endl;
303 cout << " -p# FCAL photo-statistics smearing factor in GeV^3/2 (def:" << FCAL_PHOT_STAT_COEF << ")" << endl;
304 cout << " -b# FCAL single block threshold in MeV (def:" << FCAL_BLOCK_THRESHOLD/k_MeV << ")" << endl;
305 cout << " -B Don't process BCAL hits at all (def. process)" << endl;
306 cout << " -Vthresh BCAL ADC threshold (def. " << BCAL_ADC_THRESHOLD_MEV << " MeV)" << endl;
307 cout << " -Xsigma BCAL fADC time resolution (def. " << BCAL_FADC_TIME_RESOLUTION << " ns)" << endl;
308 cout << " -G Don't smear BCAL times (def. smear)" << endl;
309 cout << " -H Don't add BCAL dark hits (def. add)" << endl;
310 cout << " -K Don't apply BCAL sampling fluctuations (def. apply)" << endl;
311 cout << " -L Don't apply BCAL sampling floor term (def. apply)" << endl;
312 cout << " -M Don't apply BCAL Poisson statistics (def. apply)" << endl;
313 cout << " -f# TOF sigma in psec (def: " << TOF_SIGMA/k_psec << ")" << endl;
314 cout << " -h Print this usage statement." << endl;
315 cout << endl;
316 cout << " Example:" << endl;
317 cout << endl;
318 cout << " mcsmear -u3.5 -t500 hdgeant.hddm" << endl;
319 cout << endl;
320 cout << " This will produce a file named hdgeant_nsmeared.hddm that" << endl;
321 cout << " includes the hit information from the input file hdgeant.hddm" << endl;
322 cout << " but with the FDC and CDC hits smeared out. The CDC hits will" << endl;
323 cout << " have their drift times smeared via a gaussian with a 3.5ns width" << endl;
324 cout << " while the FDC will be smeared using the default values." << endl;
325 cout << " In addition, background hits will be added, the exact number of" << endl;
326 cout << " of which are determined by the time windows specified for the" << endl;
327 cout << " CDC and FDC. In this examplem the CDC time window was explicitly" << endl;
328 cout << " set to 500 ns." << endl;
329 cout << endl;
330
331 exit(0);
332}
333
334#if ! USE_JANA1
335//-----------------------------------------------------------------
336// ctrlCHandleMCSmear
337//-----------------------------------------------------------------
338void ctrlCHandleMCSmear(int x)
339{
340 QUIT++;
341 cerr << endl << "SIGINT received (" << QUIT << ")....." << endl;
342}
343#endif