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

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