source: trunk/MagicSoft/Simulation/Detector/StarResponse/srreadparam.cxx@ 6215

Last change on this file since 6215 was 5406, checked in by moralejo, 20 years ago
Added input card command gain_fluctuations_off to switch off PMT gain fluctuations in the noise generation. This is useful for certain tests.
File size: 8.8 KB
Line 
1//=//////////////////////////////////////////////////////////////////////
2//=
3//= srreadparam
4//=
5//= @file srreadparam.cxx
6//= @desc Reading of parameters file
7//= @author O Blanch Bigas
8//= @email blanch@ifae.es
9//= @date Wed Feb 21 17:43:07 CET 2001
10//=
11//=----------------------------------------------------------------------
12//=
13//= Created: Wed Feb 21 17:43:07 CET 2001
14//= Author: Oscar Blanch Bigas
15//= Purpose: Program for star response simulation
16//= Notes: See files README for details
17//=
18//=----------------------------------------------------------------------
19//=
20//= $RCSfile: srreadparam.cxx,v $
21//= $Revision: 1.7 $
22//= $Author: moralejo $
23//= $Date: 2004-11-16 11:09:11 $
24//=
25//=//////////////////////////////////////////////////////////////////////
26
27// @T \newpage
28
29//!@section Source code of |srreadparam.cxx|.
30
31/*!@"
32
33 This section describes briefly the source code for the file
34 |srreadparam.cxx|. This file is very closely related to the file
35 |readparams.cxx| from the |reflector| program. Actually, this later
36 file was the ancestror of the file you are looking at.
37
38 All the defines it uses are located in the file |srreadparam.h|. In
39 the first one we can see the definitions of the commands available
40 for the parameters file. We describe these commands in a later
41 section.
42
43 @"*/
44
45//!@subsection Includes and Global variables definition.
46
47/*!@"
48
49 All the defines are located in the file {\tt srreadparam.h}.
50
51 @"*/
52
53//!@{
54
55using namespace std;
56
57#include "srreadparam.h"
58
59//!@}
60
61//!@subsection Definition of global variables.
62
63/*!@"
64
65 Here we define the global variables where the values from the
66 parameters file are stored.
67
68 @"*/
69
70//!@{
71
72static char Database_path[PATH_MAX_LENGTH]; //@< path to store the database
73static float Simulated_Phe_l = 0.0; //@< lower limit for phe loop
74static float Simulated_Phe_u = 50.0; //@< higher limit for phe loop
75static float Simulated_Phe_p = 0.1; //@< precision for phe loop
76static int FADC_Shape=0;
77static float FADC_Integ = MFADC_RESPONSE_INTEGRAL;
78static float FADC_FWHM = MFADC_RESPONSE_FWHM;
79static float FADC_slices_per_ns = FADC_SLICES_PER_NSEC;
80static int Trig_Shape = 0;
81static float Trig_Ampl = 1.0;
82static float Trig_FWHM = 2.0;
83static int Write_Root = 0;
84static int gain_fluctuations = 1; // Is 0 if PMT gain fluctuations are disabled
85
86//!@}
87
88//!@subsection The function |readparam()|.
89
90//!-----------------------------------------------------------
91// @name srreadparam
92//
93// @desc read parameters from the stdin / parameters file
94//
95// @var *filename Name of the parameters file (NULL->STDIN)
96//
97// @date Wed Feb 21 17:43:07 CET 2001
98//------------------------------------------------------------
99// @function
100
101//!@{
102void
103readparam(char * filename)
104{
105 char line[LINE_MAX_LENGTH]; //@< line to get from the stdin
106 char token[ITEM_MAX_LENGTH]; //@< a single token
107 int i; //@< dummy counters
108 ifstream ifile;
109
110 ifile.open( filename );
111
112 // loop till the "end" directive is reached
113 int is_end = FALSE;
114 while (! is_end) {
115
116 // get line from file or stdin
117 if ( filename != NULL )
118 ifile.getline(line, LINE_MAX_LENGTH);
119 else
120 cin.getline(line, LINE_MAX_LENGTH);
121
122 // skip comments (start with '#')
123 if (line[0] == '#')
124 continue;
125
126 // show user comments (start with '>')
127 if (line[0] == '>') {
128 cout << line << endl << flush;
129 continue;
130 }
131
132 // look for each item at the beginning of the line
133 for (i=0; i<=end_file; i++)
134 if (strstr(line, ITEM_NAMES[i]) == line)
135 break;
136
137 // if it is not a valid line, just ignore it
138 if (i == end_file+1) {
139 cerr << "Skipping unknown token in [" << line << "]\n";
140 continue;
141 }
142
143 // case block for each directive
144 switch ( i ) {
145
146 case database_path: //@< name of the output path
147
148 // get the path for the outcoming database
149 sscanf(line, "%s %s", token, Database_path);
150
151 break;
152
153 case simulated_phe: //@< limits for the phe loop
154
155 sscanf(line, "%s %f %f %f", token, &Simulated_Phe_l, &Simulated_Phe_u,
156 &Simulated_Phe_p);
157
158 break;
159
160 case trig_properties: //@< shape of trigger response
161
162 sscanf(line, "%s %d %f %f", token, &Trig_Shape, &Trig_Ampl,
163 &Trig_FWHM);
164
165 break;
166
167 case fadc_properties: //@< shape of fadc response
168
169 sscanf(line, "%s %d %f %f", token, &FADC_Shape, &FADC_Integ,
170 &FADC_FWHM);
171
172 break;
173
174 case fadc_GHz: // Get FADC sampling frequency in GHz
175
176 sscanf(line, "%s %f", token, &FADC_slices_per_ns);
177
178 break;
179
180 case gain_fluctuations_off:
181
182 gain_fluctuations = 0; // Disable PMT gain fluctuations
183
184 break;
185
186 case write_root: //@< Write histogram
187
188 Write_Root = 1;
189
190 case end_file: //@< end of the parameters file
191
192 // show a short message
193 is_end = TRUE;
194
195 break;
196
197 } // switch ( i )
198
199 } // while (! is_end)
200
201 // after the loop is finished, return to the main function
202 return;
203}
204//!@}
205
206
207//!-----------------------------------------------------------
208// @name get_database_path
209//
210// @desc get name of the ouput path
211//
212// @return Name of the output path
213//
214// @date Wed Feb 21 17:57:19 CET 2001
215//------------------------------------------------------------
216// @function
217
218//!@{
219char *
220get_database_path(void)
221{
222 return (Database_path);
223}
224//!@}
225
226//!-----------------------------------------------------------
227// @name get_simulated_phe
228//
229// @desc return limits for the phe loop
230//
231// @var *lphe Lower limit in the phe loop
232// @var *uphe Higher limit in the phe loop
233// @var *pphe Precision in the phe loop
234// @return void
235//
236// @date Wed Feb 21 18:04:03 CET 2001
237//------------------------------------------------------------
238// @function
239
240//!@{
241void
242get_simulated_phe(float *lphe, float *uphe, float *pphe)
243{
244 *lphe = Simulated_Phe_l;
245 *uphe = Simulated_Phe_u;
246 *pphe = Simulated_Phe_p;
247}
248//!@}
249
250//!-----------------------------------------------------------
251// @name get_trig_properties
252//
253// @desc return shape of the single phe trigger response
254//
255// @var *shape number to indentify the shape (0 ->gaussian)
256// @var *ampl Amplitud of the gaussian response
257// @var *fwhm FWHM of the gaussian response
258// @return void
259//
260// @date Wed Feb 21 18:04:03 CET 2001
261//------------------------------------------------------------
262// @function
263
264//!@{
265void
266get_trig_properties(int *shape, float *ampl, float *fwhm)
267{
268 *shape = Trig_Shape;
269 *ampl = Trig_Ampl;
270 *fwhm = Trig_FWHM;
271}
272//!@}
273
274//!-----------------------------------------------------------
275// @name get_fadc_properties
276//
277// @desc return shape of the single phe FADC response
278//
279// @var *shape number to indentify the shape (0 ->gaussian)
280// @var *ampl Amplitud of the gaussian response
281// @var *fwhm FWHM of the gaussian response
282// @return void
283//
284// @date Wed Feb 21 18:04:03 CET 2001
285//------------------------------------------------------------
286// @function
287
288//!@{
289void
290get_fadc_properties(int *shape, float *integ, float *fwhm, float *fadc_spns)
291{
292 *shape = FADC_Shape;
293 *integ = FADC_Integ;
294 *fwhm = FADC_FWHM;
295 *fadc_spns = FADC_slices_per_ns;
296}
297//!@}
298
299//------------------------------------------------------------
300// Returns gain_fluctuations, which is 0 if the PMT gain fluctuations
301// have been disabled in the input card.
302//
303int apply_gain_fluctuations()
304{
305 return gain_fluctuations;
306}
307
308//!-----------------------------------------------------------
309// @name get_write_root
310//
311// @desc get boolean to write root files
312//
313// @return 0 (false) or 1 (true)
314//
315// @date Fri Mar 2 16:17:26 CET 2001
316//------------------------------------------------------------
317// @function
318
319//!@{
320int
321get_write_root(void)
322{
323 return (Write_Root);
324}
325//!@}
326
327//=------------------------------------------------------------
328//!@subsection Log of this file.
329
330//!@{
331//
332// $Log: not supported by cvs2svn $
333// Revision 1.6 2004/10/12 13:41:09 moralejo
334// *** empty log message ***
335//
336// Revision 1.5 2004/09/17 13:51:02 moralejo
337//
338// Adapted headers to current c++ style, removed -Wno-deprecated from
339// compilation options.
340//
341// Revision 1.4 2004/09/16 16:20:13 moralejo
342// *** empty log message ***
343//
344// Revision 1.3 2004/01/30 10:34:59 blanch
345// Change in variables name to clarify the meaning.
346//
347// Revision 1.2 2001/03/05 11:01:44 blanch
348// Commads to enter the FADC and trigger properties have been added.
349// There is also a new command that allows to writte the root files or not
350//
351// Revision 1.1 2001/02/23 10:13:44 magicsol
352// It read form an input card (defeult=starresponse.par) the parameters that
353// are needed for the starresponse program.
354//
355//!@}
356
357//=EOF
Note: See TracBrowser for help on using the repository browser.