1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | #define USE_JANA1 1
|
11 |
|
12 | #include <iostream>
|
13 | #include <iomanip>
|
14 | using 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 |
|
31 | #include <HDGEOMETRY/DGeometry.h>
|
32 |
|
33 | #endif
|
34 |
|
35 | #include "units.h"
|
36 | #include "HDDM/hddm_s.hpp"
|
37 |
|
38 | void Smear(hddm_s::HDDM *record);
|
39 | void ParseCommandLineArguments(int narg, char* argv[]);
|
40 | void Usage(void);
|
41 |
|
42 | extern void SetSeeds(const char *vals);
|
43 |
|
44 | char *INFILENAME = NULL__null;
|
45 | char *OUTFILENAME = NULL__null;
|
46 | int QUIT = 0;
|
47 |
|
48 | bool ADD_NOISE = false;
|
49 | bool SMEAR_HITS = true;
|
50 | bool SMEAR_BCAL = true;
|
51 | bool FDC_ELOSS_OFF = false;
|
52 | bool IGNORE_SEEDS = false;
|
53 |
|
54 |
|
55 | double BCAL_DARKRATE_GHZ = 0.;
|
56 | double BCAL_SIGMA_SIG_RELATIVE = 0.;
|
57 | double BCAL_SIGMA_PED_RELATIVE = 0.;
|
58 | double BCAL_SIPM_GAIN_VARIATION = 0.;
|
59 | double BCAL_XTALK_FRACT = 0.;
|
60 | double BCAL_INTWINDOW_NS = 0.;
|
61 | double BCAL_DEVICEPDE = 0.;
|
62 | double BCAL_SAMPLING_FRACT = 0.;
|
63 | double BCAL_PHOTONSPERSIDEPERMEV_INFIBER = 0.0;
|
64 | double BCAL_AVG_DARK_DIGI_VALS_PER_EVENT = 0.0;
|
65 | double BCAL_SAMPLINGCOEFA = 0.0;
|
66 | double BCAL_SAMPLINGCOEFB = 0.0;
|
67 | double BCAL_TIMEDIFFCOEFA = 0.0;
|
68 | double BCAL_TIMEDIFFCOEFB = 0.0;
|
69 | double BCAL_TWO_HIT_RESOL = 0.0;
|
70 | double BCAL_mevPerPE = 0.31;
|
71 |
|
72 | int BCAL_NUM_MODULES = 48;
|
73 | int BCAL_NUM_LAYERS = 4;
|
74 | int BCAL_NUM_SECTORS = 4;
|
75 |
|
76 | double BCAL_BASE_TIME_OFFSET = 0;
|
77 | double BCAL_TDC_BASE_TIME_OFFSET = 0;
|
78 |
|
79 | vector<vector<double> > attenuation_parameters;
|
80 | vector<double> effective_velocities;
|
81 |
|
82 | double BCAL_ADC_THRESHOLD_MEV = 2.2;
|
83 | double BCAL_FADC_TIME_RESOLUTION = 0.3;
|
84 | double BCAL_TDC_TIME_RESOLUTION = 0.3;
|
85 | double BCAL_MEV_PER_ADC_COUNT = 0.029;
|
86 | double BCAL_NS_PER_ADC_COUNT = 0.0;
|
87 | double BCAL_NS_PER_TDC_COUNT = 0.0;
|
88 |
|
89 |
|
90 | bool NO_T_SMEAR = false;
|
91 | bool NO_DARK_PULSES = false;
|
92 | bool NO_SAMPLING_FLUCTUATIONS = false;
|
93 | bool NO_SAMPLING_FLOOR_TERM = false;
|
94 | bool NO_POISSON_STATISTICS = false;
|
95 |
|
96 | double FTOF_BAR_THRESHOLD = 0.0;
|
97 | double STC_PADDLE_THRESHOLD = 0.0;
|
98 | double PSC_THRESHOLD = 0.0;
|
99 | double PS_THRESHOLD = 0.0;
|
100 |
|
101 | double TAGM_TSIGMA = 0.200;
|
102 | double TAGH_TSIGMA = 0.350;
|
103 | double TAGM_FADC_TSIGMA = 0.350;
|
104 | double TAGH_FADC_TSIGMA = 0.450;
|
105 | double TAGM_NPIX_PER_GEV = 1.e5;
|
106 | double TAGH_NPE_PER_GEV = 5.e5;
|
107 |
|
108 |
|
109 | double PS_SIGMA = 0.200;
|
110 | double PSC_SIGMA = 0.200;
|
111 | double PS_NPIX_PER_GEV = 1.e5;
|
112 | double PSC_PHOTONS_PERMEV = 5.e5;
|
113 |
|
114 | double FCAL_PHOT_STAT_COEF = 0.0;
|
115 | double FCAL_BLOCK_THRESHOLD = 0.0;
|
116 |
|
117 | double CDC_TDRIFT_SIGMA = 0.0;
|
118 | double CDC_TIME_WINDOW = 0.0;
|
119 | double CDC_PEDESTAL_SIGMA = 0.0;
|
120 | double CDC_THRESHOLD_FACTOR = 0.0;
|
121 |
|
122 | double FDC_TDRIFT_SIGMA = 0.0;
|
123 | double FDC_CATHODE_SIGMA = 0.0;
|
124 | double FDC_PED_NOISE = 0.0;
|
125 | double FDC_THRESHOLD_FACTOR = 0.0;
|
126 | double FDC_HIT_DROP_FRACTION = 0.0;
|
127 | double FDC_TIME_WINDOW = 0.0;
|
128 | double FDC_THRESH_KEV = 0.0;
|
129 |
|
130 | double START_SIGMA = 0.0;
|
131 | double START_PHOTONS_PERMEV = 0.0;
|
132 |
|
133 |
|
134 | double TOF_SIGMA = 100.*k_psec;
|
135 | double TOF_PHOTONS_PERMEV = 400.;
|
136 |
|
137 | double FMWPC_TSIGMA = 10.0;
|
138 | double FMWPC_ASIGMA = 0.5E-6;
|
139 | double FMWPC_THRESHOLD = 0.0;
|
140 |
|
141 | double TRIGGER_LOOKBACK_TIME = -100;
|
142 |
|
143 | bool DROP_TRUTH_HITS=false;
|
144 |
|
145 |
|
146 | vector<unsigned int> NCDC_STRAWS;
|
147 | vector<double> CDC_RING_RADIUS;
|
148 |
|
149 |
|
150 | vector<double> FDC_LAYER_Z;
|
151 | double FDC_RATE_COEFFICIENT;
|
152 |
|
153 | using namespace jana;
|
154 |
|
155 |
|
156 | pthread_mutex_t root_mutex = PTHREAD_MUTEX_INITIALIZER{ { 0, 0, 0, 0, 0, 0, { 0, 0 } } };
|
157 | TH2F *fdc_drift_time_smear_hist = NULL__null;
|
158 | TH2F *fdc_drift_dist_smear_hist = NULL__null;
|
159 | TH2F *fdc_drift_time = NULL__null;
|
160 | TH1F *fdc_cathode_charge = NULL__null;
|
161 | TH2F *cdc_drift_time = NULL__null;
|
162 | TH1F *cdc_charge = NULL__null;
|
163 | TH1F *fdc_anode_mult = NULL__null;
|
164 | TH2F *cdc_drift_smear = NULL__null;
|
165 |
|
166 |
|
167 |
|
168 |
|
169 | int main(int narg,char* argv[])
|
170 | {
|
171 | ParseCommandLineArguments(narg, argv);
|
172 |
|
173 |
|
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 |
|
190 |
|
191 | void 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 | |
|
| |
235 | cout << endl << "You must enter a filename!" << endl << endl;
|
236 | Usage();
|
237 | }
|
238 |
|
239 | if (warn_obsolete) {
|
| |
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 |
|
250 | if (OUTFILENAME == NULL__null) {
|
| |
251 | char *ptr, *path_stripped;
|
252 | path_stripped = ptr = strdup(INFILENAME);
|
| |
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 |
|
271 |
|
272 | void 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 |
|
337 |
|
338 | void ctrlCHandleMCSmear(int x)
|
339 | {
|
340 | QUIT++;
|
341 | cerr << endl << "SIGINT received (" << QUIT << ")....." << endl;
|
342 | }
|
343 | #endif
|