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

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