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

Last change on this file since 5095 was 5081, checked in by moralejo, 21 years ago
*** empty log message ***
File size: 5.3 KB
Line 
1#include "MLons.hxx"
2
3MLons::MLons(){
4 //-----------------------------------------------------------------
5 //
6 // Default constructor
7 //
8
9 fTrigShape = 0.0;
10 fAmplTrig = 1.0;
11 fFwhmTrig = 2.0;
12
13 fFadcShape = 0.0;
14 fIntegFadc = 1.0;
15 fFwhmFadc = 2.0;
16
17 RandomNumber = new TRandom() ;
18 RandomNumber -> SetSeed(0);
19
20}
21
22MLons::MLons(Float_t in_shapeT, Float_t in_amplT, Float_t in_FwhmT,
23 Float_t in_shapeF, Float_t in_integF, Float_t in_FwhmF){
24 //--------------------------------------------------------------------
25 //
26 // Constructor overloaded I
27 //
28
29 fTrigShape = in_shapeT;
30 fAmplTrig = in_amplT;
31 fFwhmTrig = in_FwhmT;
32
33 fFadcShape = in_shapeF;
34 fIntegFadc = in_integF;
35 fFwhmFadc = in_FwhmF;
36
37 RandomNumber = new TRandom() ;
38 RandomNumber -> SetSeed(0);
39}
40
41void MLons::Reset() {
42 //-----------------------------------------------------------------
43 //
44 // Reset the member variables
45 //
46
47 fTrigShape = 0. ;
48 fAmplTrig = 0. ;
49 fFwhmTrig = 0. ;
50
51 fFadcShape = 0. ;
52 fIntegFadc = 0. ;
53 fFwhmFadc = 0. ;
54
55 MSLStored.Reset();
56
57}
58
59void MLons::SetSeed(Int_t in)
60{
61 RandomNumber -> SetSeed(in);
62}
63
64Float_t MLons::GetAmplTrig ()
65{
66 return fAmplTrig ;
67}
68
69void MLons::SetAmplTrig (Float_t in )
70{
71 fAmplTrig = in ;
72}
73
74Float_t MLons::GetFwhmTrig ()
75{
76 return fFwhmTrig ;
77}
78
79void MLons::SetFwhmTrig (Float_t in )
80{
81 fFwhmTrig = in ;
82}
83
84
85Float_t MLons::GetIntegFadc ()
86{
87 return fIntegFadc ;
88}
89
90void MLons::SetIntegFadc (Float_t in )
91{
92 fIntegFadc = in ;
93}
94
95Float_t MLons::GetFwhmFadc ()
96{
97 return fFwhmFadc ;
98}
99
100void MLons::SetFwhmFadc (Float_t in )
101{
102 fFwhmFadc = in ;
103}
104
105void MLons::SetPath (Char_t in[])
106{
107 strcpy(path, & in[0]);
108}
109
110void MLons::ReadBinaryMStarLight(char *filename){
111
112 MSLStored.ReadBinary(filename);
113
114}
115
116Int_t MLons::CheckTrig(){
117 //--------------------------------------------------------------------
118 //
119 // Parameters of MSLStored should be the same than the required ones
120 //
121
122 if ( fAmplTrig == MSLStored.GetAmplTrig() &&
123 fFwhmTrig == MSLStored.GetFwhmTrig())
124 return 1;
125
126 return 0;
127}
128
129Int_t MLons::CheckFADC(){
130 //--------------------------------------------------------------------
131 //
132 // Parameters of MSLStored should be the same than the required ones
133 //
134
135 if ( fIntegFadc == MSLStored.GetIntegFadc() &&
136 fFwhmFadc == MSLStored.GetFwhmFadc() &&
137 fFadcShape == MSLStored.GetShapeFadc())
138 return 1;
139
140 return 0;
141}
142
143Int_t MLons::GetResponse(Float_t in_br, Float_t in_pre,
144 Float_t *out_tr, Float_t *out_Fr){
145 //-------------------------------------------------------------------------
146 //
147 // It reads the response from the database and put it in out_tr
148 //
149
150 Char_t filename_slt[256];
151 Char_t cbright[10];
152 Char_t cstoredbright[10];
153
154 Int_t i;
155 Int_t bin;
156 Float_t start_bin;
157 Float_t time;
158
159 // The following code line commented means that the simulation will crash if
160 // some pixel ask for more lons than what we have in the database.
161 // The following code line uncommented would mean that the simulation does
162 // not crash if a pixel ask for more than it is simulated but would
163 // assign to it lees lons.
164 if (in_br>49.9) in_br=49.9; // To avoid error for high required brightness
165 // It has to be improved
166
167 // Check if the the brightness is the same than the last time.
168 // NOTE: Same means, the smae inside the required precision!!!
169
170 if(in_br<1.0){
171 sprintf(cbright,"%4.2f",in_br);
172 sprintf(cstoredbright,"%4.2f",MSLStored.GetBrightness());
173 }
174 else{
175 sprintf(cbright,"%3.1f",in_br);
176 sprintf(cstoredbright,"%3.1f",MSLStored.GetBrightness());
177 }
178 if (strcmp(cbright, cstoredbright)){
179
180 // Building the filename
181 // Note: it would be nice to get an algorithm that gets the name of
182 // files it needs to get brightness as a function of precison(in_pre),
183 // brightnes (in_br) and the Star_files that are in the "Path" directory.
184
185 strcpy(filename_slt, & path[0]);
186 strcat(filename_slt, "Brightness");
187 strcat(filename_slt, & cbright[0]);
188
189 strcat(filename_slt, ".slt");
190
191 // If brightness is different it check if the new file has the
192 // required parameters.
193 // Note: I could be faster to store the whole trigger and fadc
194 // response and use it while brightness does not change. Then the
195 // root file should be open and close here.
196
197 ReadBinaryMStarLight( & filename_slt[0]);
198
199 if (!(CheckTrig() && CheckFADC())) {
200 cout<<"ERROR: The Database for light from Night Sky Background is wrong"<<endl<<" Make sure that you generated the database with the same shape for Fadc and trigger taht you are asking now."<<endl;
201 return 0;
202 }
203 MSLStored.SetBrightness(in_br);
204
205 }
206
207 // Random number that decides the set of bins that the program will get
208 start_bin=RandomNumber->Uniform(1.0e4);
209
210 // Filling trigger response
211
212 bin=(Int_t)(start_bin*4);
213
214 for (i=0;i<TRIGGER_TIME_SLICES;i++){
215
216 time=((float)i)/SLICES_PER_NSEC;
217
218 if (time>(bin-start_bin*4.0)/4.0) bin++;
219
220 if (bin>=TRIGBINS) bin=bin-TRIGBINS;
221
222 out_tr[i]=MSLStored.GetTrig(bin);
223 }
224
225 // Filling fadc response
226
227 bin=(Int_t) (start_bin*0.3);
228
229 for (i=0;i<(Int_t) SLICES_MFADC;i++){
230
231 time=((float)i)*WIDTH_FADC_TIMESLICE;
232
233 if (time>(bin-start_bin*0.3)/0.3) bin++;
234
235 if (bin>=FADCBINS) bin=bin-FADCBINS;
236
237 out_Fr[i]=MSLStored.GetFadc(bin);
238 }
239
240 return 1;
241}
Note: See TracBrowser for help on using the repository browser.