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

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