source: trunk/MagicSoft/Simulation/Detector/include-MLons/MLons.cxx@ 18679

Last change on this file since 18679 was 5418, checked in by moralejo, 20 years ago
*** empty log message ***
File size: 8.4 KB
Line 
1#include "MLons.hxx"
2
3using namespace std;
4
5MLons::MLons()
6{
7 //-----------------------------------------------------------------
8 //
9 // Default constructor
10 //
11
12 fTrigShape = 0;
13 fAmplTrig = 1.0;
14 fFwhmTrig = 2.0;
15 fFadcSlicesPerNanosec = FADC_SLICES_PER_NSEC;
16
17 fFadcShape = 0;
18 fIntegFadc = 1.0;
19 fFwhmFadc = 2.0;
20
21 fGainFluctuations = 1;
22
23 RandomNumber = new TRandom();
24 RandomNumber -> SetSeed(0);
25
26}
27
28MLons::MLons(Int_t in_shapeT, Float_t in_amplT, Float_t in_FwhmT,
29 Int_t in_shapeF, Float_t in_integF, Float_t in_FwhmF,
30 Float_t in_Fadc_Slices_per_ns, Int_t in_Gain_Fluctuations)
31{
32 //--------------------------------------------------------------------
33 //
34 // Constructor overloaded I
35 //
36
37 fTrigShape = in_shapeT;
38 fAmplTrig = in_amplT;
39 fFwhmTrig = in_FwhmT;
40
41 fFadcShape = in_shapeF;
42 fIntegFadc = in_integF;
43 fFwhmFadc = in_FwhmF;
44
45 fFadcSlicesPerNanosec = in_Fadc_Slices_per_ns;
46
47 fGainFluctuations = in_Gain_Fluctuations;
48
49 MSLStored = new MStarLight;
50
51 RandomNumber = new TRandom() ;
52 RandomNumber -> SetSeed(0);
53}
54
55void MLons::Reset()
56{
57 //-----------------------------------------------------------------
58 //
59 // Reset the member variables
60 //
61
62 fTrigShape = 0;
63 fAmplTrig = 0.;
64 fFwhmTrig = 0.;
65
66 fFadcShape = 0;
67 fIntegFadc = 0.;
68 fFwhmFadc = 0.;
69
70 fGainFluctuations = 1;
71
72 MSLStored->Reset();
73
74}
75
76void MLons::SetSeed(UInt_t in)
77{
78 RandomNumber -> SetSeed(in);
79}
80
81Float_t MLons::GetAmplTrig ()
82{
83 return fAmplTrig ;
84}
85
86void MLons::SetAmplTrig (Float_t in )
87{
88 fAmplTrig = in ;
89}
90
91Float_t MLons::GetFwhmTrig ()
92{
93 return fFwhmTrig ;
94}
95
96void MLons::SetFwhmTrig (Float_t in )
97{
98 fFwhmTrig = in ;
99}
100
101
102Float_t MLons::GetIntegFadc ()
103{
104 return fIntegFadc ;
105}
106
107void MLons::SetIntegFadc (Float_t in )
108{
109 fIntegFadc = in ;
110}
111
112Float_t MLons::GetFwhmFadc ()
113{
114 return fFwhmFadc ;
115}
116
117void MLons::SetFwhmFadc (Float_t in )
118{
119 fFwhmFadc = in ;
120}
121
122void MLons::SetPath (Char_t in[])
123{
124 strcpy(path, & in[0]);
125}
126
127void MLons::ReadBinaryMStarLight(char *filename)
128{
129 MSLStored->ReadBinary(filename);
130}
131
132Int_t MLons::CheckTrig()
133{
134 //--------------------------------------------------------------------
135 //
136 // Parameters of MSLStored should be the same than the required ones
137 //
138
139 if ( fAmplTrig == MSLStored->GetAmplTrig() &&
140 fFwhmTrig == MSLStored->GetFwhmTrig())
141 return 1;
142
143 cout << "1 phe- pulse amplitudes for trigger (mV): " << fAmplTrig << " "
144 << MSLStored->GetAmplTrig() << endl;
145 cout << "1 phe- pulse FWHM for trigger (ns): " << fFwhmTrig << " "
146 << MSLStored->GetFwhmTrig() << endl;
147
148 return 0;
149}
150
151Int_t MLons::CheckFADC()
152{
153 //--------------------------------------------------------------------
154 //
155 // Parameters of MSLStored should be the same than the required ones
156 //
157
158 if ( fIntegFadc == MSLStored->GetIntegFadc() &&
159 fFwhmFadc == MSLStored->GetFwhmFadc() &&
160 fFadcShape == MSLStored->GetShapeFadc() &&
161 fFadcSlicesPerNanosec == MSLStored->GetFadcSlicesPerNanosec() )
162 return 1;
163
164 cout << "1 phe- FADC pulse shape : " << fFadcShape << " "
165 << MSLStored->GetShapeFadc() << endl;
166 cout << "1 phe- FADC pulse integral (counts) : " << fIntegFadc << " "
167 << MSLStored->GetIntegFadc() << endl;
168 cout << "1 phe- FADC pulse FWHM (ns) : " << fFwhmFadc << " "
169 << MSLStored->GetFwhmFadc() << endl;
170 cout << "FADC sampling frequencies (GHz) : " << fFadcSlicesPerNanosec << " "
171 << MSLStored->GetFadcSlicesPerNanosec() << endl;
172
173 return 0;
174}
175
176Int_t MLons::GetResponse(Float_t in_br, Float_t in_pre,
177 Float_t *out_tr, Float_t *out_Fr)
178{
179 //-------------------------------------------------------------------------
180 //
181 // It reads the response from the database and put it in out_tr
182 //
183
184 Char_t filename_slt[256];
185 Char_t cbright[10];
186 Char_t cstoredbright[10];
187
188 Int_t bin;
189 Float_t start_time;
190
191
192 //
193 // The following code line commented means that the simulation will crash if
194 // some pixel ask for more lons than what we have in the database.
195 // The following code line uncommented would mean that the simulation does
196 // not crash if a pixel ask for more than it is simulated but would
197 // assign to it less lons.
198 // I think this is unnecessary now. AM 5/10/2004
199 // if (in_br>49.9) in_br=49.9; // To avoid error for high required brightness
200 // // It has to be improved
201 //
202
203
204 // Check if the the brightness is the same than the last time.
205 // NOTE: Same means, the same inside the required precision!!!
206
207 if(in_br<=1.0){
208 sprintf(cbright,"%4.2f",in_br);
209 sprintf(cstoredbright,"%4.2f",MSLStored->GetBrightness());
210 }
211 else{
212 sprintf(cbright,"%3.1f",in_br);
213 sprintf(cstoredbright,"%3.1f",MSLStored->GetBrightness());
214 }
215
216 if (strcmp(cbright, cstoredbright))
217 {
218 // Building the filename
219 // Note: it would be nice to get an algorithm that gets the name of
220 // files it needs to get brightness as a function of precison(in_pre),
221 // brightnes (in_br) and the Star_files that are in the "Path" directory.
222
223 strcpy(filename_slt, & path[0]);
224 strcat(filename_slt, "Brightness");
225 strcat(filename_slt, & cbright[0]);
226
227 strcat(filename_slt, ".slt");
228
229 // If brightness is different it checks if the new file has the
230 // required parameters.
231 // Note: I could be faster to store the whole trigger and fadc
232 // response and use it while brightness does not change. Then the
233 // root file should be open and close here.
234
235 MSLStored->ReadBinary(filename_slt);
236
237 if (!(CheckTrig() && CheckFADC()))
238 {
239 cout << "ERROR: The Database for light from Night Sky Background is wrong"<<endl;
240 cout << " Make sure that you generated the database with the same shape" << endl;
241 cout << " for Fadc and trigger that you are asking now."<<endl;
242 return 0;
243 }
244
245 if ( !MSLStored->GetGainFluctuations() && fGainFluctuations)
246 {
247 cout << endl << "ERROR! The read NSB database in " << filename_slt << endl;
248 cout << "has been produced without PMT gain fluctuations. This is incompatible" << endl;
249 cout << "with the camera input card you are using. Please change the camera" << endl;
250 cout << "input card (adding the noise_gain_fluctuations_off command) or" << endl;
251 cout << "produce a new NSB database (using program StarResponse) without" << endl;
252 cout << "gain fluctuations. Exiting..." << endl << endl;
253 return 0;
254 }
255
256 else if ( MSLStored->GetGainFluctuations() && !fGainFluctuations)
257 {
258 cout << endl << "ERROR! The read NSB database in " << filename_slt << endl;
259 cout << "has been produced with PMT gain fluctuations. This is incompatible" << endl;
260 cout << "with the camera input card command noise_gain_fluctuations_off" << endl;
261 cout << "that you are using. Please change the camera input card or produce a" << endl;
262 cout << "new NSB database (using program StarResponse) without gain fluctuations." << endl;
263 cout << "Exiting..." << endl << endl;
264 return 0;
265 }
266
267 MSLStored->SetBrightness(in_br);
268
269 }
270
271 // Random number that decides the set of bins that the program will get
272 start_time = RandomNumber->Uniform(TIMERANGE);
273
274 // Filling trigger response
275
276 bin = (Int_t)(start_time*TRIG_SLICES_PER_NSEC);
277
278
279 if (bin+TRIGGER_TIME_SLICES > MSLStored->GetBinsTrig())
280 {
281 memcpy (out_tr, MSLStored->GetTrigPointer(bin),
282 (UInt_t) (MSLStored->GetBinsTrig()-bin)*sizeof(Float_t));
283 memcpy (out_tr, MSLStored->GetTrigPointer(0),
284 (UInt_t) (bin+TRIGGER_TIME_SLICES-MSLStored->GetBinsTrig())*sizeof(Float_t));
285 }
286 else
287 memcpy (out_tr, MSLStored->GetTrigPointer(bin),
288 (UInt_t) TRIGGER_TIME_SLICES*sizeof(Float_t));
289
290
291 // Filling fadc response
292
293 // Start bin in the NSB database:
294 bin = (Int_t) (start_time*MSLStored->GetBinsFadc()/MSLStored->GetTimeRange());
295
296 // If we go over the end of the database, continue at the begining of it:
297 if (bin + (Int_t)(TOTAL_TRIGGER_TIME*fFadcSlicesPerNanosec) > MSLStored->GetBinsFadc())
298 {
299 memcpy (out_Fr, MSLStored->GetFadcPointer(bin),
300 (Int_t)(MSLStored->GetBinsFadc()-bin)*sizeof(Float_t));
301
302 memcpy (out_Fr + MSLStored->GetBinsFadc() - bin,
303 MSLStored->GetFadcPointer(0),
304 (Int_t)(bin + TOTAL_TRIGGER_TIME*fFadcSlicesPerNanosec -
305 MSLStored->GetBinsFadc())*sizeof(Float_t));
306 }
307 else
308 memcpy (out_Fr, MSLStored->GetFadcPointer(bin),
309 (Int_t)(TOTAL_TRIGGER_TIME*fFadcSlicesPerNanosec*sizeof(Float_t)));
310
311 return 1;
312}
Note: See TracBrowser for help on using the repository browser.