| 1 | #include "MLons.hxx"
|
|---|
| 2 |
|
|---|
| 3 | MLons::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 |
|
|---|
| 22 | MLons::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 |
|
|---|
| 41 | void 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 |
|
|---|
| 59 | Float_t MLons::GetAmplTrig ()
|
|---|
| 60 | {
|
|---|
| 61 | return fAmplTrig ;
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | void MLons::SetAmplTrig (Float_t in )
|
|---|
| 65 | {
|
|---|
| 66 | fAmplTrig = in ;
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | Float_t MLons::GetFwhmTrig ()
|
|---|
| 70 | {
|
|---|
| 71 | return fFwhmTrig ;
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | void MLons::SetFwhmTrig (Float_t in )
|
|---|
| 75 | {
|
|---|
| 76 | fFwhmTrig = in ;
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 | Float_t MLons::GetAmplFadc ()
|
|---|
| 81 | {
|
|---|
| 82 | return fAmplFadc ;
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | void MLons::SetAmplFadc (Float_t in )
|
|---|
| 86 | {
|
|---|
| 87 | fAmplFadc = in ;
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | Float_t MLons::GetFwhmFadc ()
|
|---|
| 91 | {
|
|---|
| 92 | return fFwhmFadc ;
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | void MLons::SetFwhmFadc (Float_t in )
|
|---|
| 96 | {
|
|---|
| 97 | fFwhmFadc = in ;
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | void MLons::SetPath (Char_t in[])
|
|---|
| 101 | {
|
|---|
| 102 | strcpy(path, & in[0]);
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | void MLons::ReadBinaryMStarLight(char *filename){
|
|---|
| 106 |
|
|---|
| 107 | MSLStored.ReadBinary(filename);
|
|---|
| 108 |
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | Int_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 |
|
|---|
| 124 | Int_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 |
|
|---|
| 137 | Int_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[10];
|
|---|
| 146 | Char_t cstoredbright[10];
|
|---|
| 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 | if(in_br<1.0){
|
|---|
| 165 | sprintf(cbright,"%4.2f",in_br);
|
|---|
| 166 | sprintf(cstoredbright,"%4.2f",MSLStored.GetBrightness());
|
|---|
| 167 | }
|
|---|
| 168 | else{
|
|---|
| 169 | sprintf(cbright,"%3.1f",in_br);
|
|---|
| 170 | sprintf(cstoredbright,"%3.1f",MSLStored.GetBrightness());
|
|---|
| 171 | }
|
|---|
| 172 | if (strcmp(cbright, cstoredbright)){
|
|---|
| 173 |
|
|---|
| 174 | // Building the filename
|
|---|
| 175 | // Note: it would be nice to get an algorithm that gets the name of
|
|---|
| 176 | // files it needs to get brightness as a function of precison(in_pre),
|
|---|
| 177 | // brightnes (in_br) and the Star_files that are in the "Path" directory.
|
|---|
| 178 |
|
|---|
| 179 | strcpy(filename_slt, & path[0]);
|
|---|
| 180 | strcat(filename_slt, "Brightness");
|
|---|
| 181 | strcat(filename_slt, & cbright[0]);
|
|---|
| 182 |
|
|---|
| 183 | strcat(filename_slt, ".slt");
|
|---|
| 184 |
|
|---|
| 185 | // If brightness is different it check if the new file has the
|
|---|
| 186 | // required parameters.
|
|---|
| 187 | // Note: I could be faster to store the whole trigger and fadc
|
|---|
| 188 | // response and use it while brightness does not change. Then the
|
|---|
| 189 | // root file should be open and close here.
|
|---|
| 190 |
|
|---|
| 191 | ReadBinaryMStarLight( & filename_slt[0]);
|
|---|
| 192 |
|
|---|
| 193 | if (!(CheckTrig() && CheckFADC())) {
|
|---|
| 194 | 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;
|
|---|
| 195 | return 0;
|
|---|
| 196 | }
|
|---|
| 197 | MSLStored.SetBrightness(in_br);
|
|---|
| 198 |
|
|---|
| 199 | }
|
|---|
| 200 |
|
|---|
| 201 | // Random number that decides the set of bins that the program will get
|
|---|
| 202 | start_bin=RandomNumber->Uniform(1.0e4);
|
|---|
| 203 |
|
|---|
| 204 | // Filling trigger response
|
|---|
| 205 |
|
|---|
| 206 | bin=(Int_t)(start_bin*4);
|
|---|
| 207 |
|
|---|
| 208 | for (i=0;i<TRIGGER_TIME_SLICES;i++){
|
|---|
| 209 |
|
|---|
| 210 | time=((float)i)/SLICES_PER_NSEC;
|
|---|
| 211 |
|
|---|
| 212 | if (time>(bin-start_bin*4.0)/4.0) bin++;
|
|---|
| 213 |
|
|---|
| 214 | if (bin>=TRIGBINS) bin=bin-TRIGBINS;
|
|---|
| 215 |
|
|---|
| 216 | out_tr[i]=MSLStored.GetTrig(bin);
|
|---|
| 217 | }
|
|---|
| 218 |
|
|---|
| 219 | // Filling fadc response
|
|---|
| 220 |
|
|---|
| 221 | bin=(Int_t) (start_bin*0.3);
|
|---|
| 222 |
|
|---|
| 223 | for (i=0;i<(Int_t) SLICES_MFADC;i++){
|
|---|
| 224 |
|
|---|
| 225 | time=((float)i)*WIDTH_FADC_TIMESLICE;
|
|---|
| 226 |
|
|---|
| 227 | if (time>(bin-start_bin*0.3)/0.3) bin++;
|
|---|
| 228 |
|
|---|
| 229 | if (bin>=FADCBINS) bin=bin-FADCBINS;
|
|---|
| 230 |
|
|---|
| 231 | out_Fr[i]=MSLStored.GetFadc(bin);
|
|---|
| 232 | }
|
|---|
| 233 |
|
|---|
| 234 | return 1;
|
|---|
| 235 | }
|
|---|