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