| 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 | fIntegFadc = 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_integF, 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 | fIntegFadc = in_integF;
|
|---|
| 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 | fIntegFadc = 0. ;
|
|---|
| 53 | fFwhmFadc = 0. ;
|
|---|
| 54 |
|
|---|
| 55 | MSLStored.Reset();
|
|---|
| 56 |
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | void MLons::SetSeed(Int_t in)
|
|---|
| 60 | {
|
|---|
| 61 | RandomNumber -> SetSeed(in);
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | Float_t MLons::GetAmplTrig ()
|
|---|
| 65 | {
|
|---|
| 66 | return fAmplTrig ;
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | void MLons::SetAmplTrig (Float_t in )
|
|---|
| 70 | {
|
|---|
| 71 | fAmplTrig = in ;
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | Float_t MLons::GetFwhmTrig ()
|
|---|
| 75 | {
|
|---|
| 76 | return fFwhmTrig ;
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | void MLons::SetFwhmTrig (Float_t in )
|
|---|
| 80 | {
|
|---|
| 81 | fFwhmTrig = in ;
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 | Float_t MLons::GetIntegFadc ()
|
|---|
| 86 | {
|
|---|
| 87 | return fIntegFadc ;
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | void MLons::SetIntegFadc (Float_t in )
|
|---|
| 91 | {
|
|---|
| 92 | fIntegFadc = in ;
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | Float_t MLons::GetFwhmFadc ()
|
|---|
| 96 | {
|
|---|
| 97 | return fFwhmFadc ;
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | void MLons::SetFwhmFadc (Float_t in )
|
|---|
| 101 | {
|
|---|
| 102 | fFwhmFadc = in ;
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | void MLons::SetPath (Char_t in[])
|
|---|
| 106 | {
|
|---|
| 107 | strcpy(path, & in[0]);
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | void MLons::ReadBinaryMStarLight(char *filename){
|
|---|
| 111 |
|
|---|
| 112 | MSLStored.ReadBinary(filename);
|
|---|
| 113 |
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | Int_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 |
|
|---|
| 129 | Int_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 | return 1;
|
|---|
| 138 |
|
|---|
| 139 | return 0;
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 | Int_t MLons::GetResponse(Float_t in_br, Float_t in_pre,
|
|---|
| 143 | Float_t *out_tr, Float_t *out_Fr){
|
|---|
| 144 | //-------------------------------------------------------------------------
|
|---|
| 145 | //
|
|---|
| 146 | // It reads the response from the database and put it in out_tr
|
|---|
| 147 | //
|
|---|
| 148 |
|
|---|
| 149 | Char_t filename_slt[256];
|
|---|
| 150 | Char_t cbright[10];
|
|---|
| 151 | Char_t cstoredbright[10];
|
|---|
| 152 |
|
|---|
| 153 | Int_t i;
|
|---|
| 154 | Int_t bin;
|
|---|
| 155 | Float_t start_bin;
|
|---|
| 156 | Float_t time;
|
|---|
| 157 |
|
|---|
| 158 | // The following code line commented means that the simulation will crash if
|
|---|
| 159 | // some pixel ask for more lons than what we have in the database.
|
|---|
| 160 | // The following code line uncommented would mean that the simulation does
|
|---|
| 161 | // not crash if a pixel ask for more than it is simulated but would
|
|---|
| 162 | // assign to it lees lons.
|
|---|
| 163 | if (in_br>49.9) in_br=49.9; // To avoid error for high required brightness
|
|---|
| 164 | // It has to be improved
|
|---|
| 165 |
|
|---|
| 166 | // Check if the the brightness is the same than the last time.
|
|---|
| 167 | // NOTE: Same means, the smae inside the required precision!!!
|
|---|
| 168 |
|
|---|
| 169 | if(in_br<1.0){
|
|---|
| 170 | sprintf(cbright,"%4.2f",in_br);
|
|---|
| 171 | sprintf(cstoredbright,"%4.2f",MSLStored.GetBrightness());
|
|---|
| 172 | }
|
|---|
| 173 | else{
|
|---|
| 174 | sprintf(cbright,"%3.1f",in_br);
|
|---|
| 175 | sprintf(cstoredbright,"%3.1f",MSLStored.GetBrightness());
|
|---|
| 176 | }
|
|---|
| 177 | if (strcmp(cbright, cstoredbright)){
|
|---|
| 178 |
|
|---|
| 179 | // Building the filename
|
|---|
| 180 | // Note: it would be nice to get an algorithm that gets the name of
|
|---|
| 181 | // files it needs to get brightness as a function of precison(in_pre),
|
|---|
| 182 | // brightnes (in_br) and the Star_files that are in the "Path" directory.
|
|---|
| 183 |
|
|---|
| 184 | strcpy(filename_slt, & path[0]);
|
|---|
| 185 | strcat(filename_slt, "Brightness");
|
|---|
| 186 | strcat(filename_slt, & cbright[0]);
|
|---|
| 187 |
|
|---|
| 188 | strcat(filename_slt, ".slt");
|
|---|
| 189 |
|
|---|
| 190 | // If brightness is different it check if the new file has the
|
|---|
| 191 | // required parameters.
|
|---|
| 192 | // Note: I could be faster to store the whole trigger and fadc
|
|---|
| 193 | // response and use it while brightness does not change. Then the
|
|---|
| 194 | // root file should be open and close here.
|
|---|
| 195 |
|
|---|
| 196 | ReadBinaryMStarLight( & filename_slt[0]);
|
|---|
| 197 |
|
|---|
| 198 | if (!(CheckTrig() && CheckFADC())) {
|
|---|
| 199 | 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;
|
|---|
| 200 | return 0;
|
|---|
| 201 | }
|
|---|
| 202 | MSLStored.SetBrightness(in_br);
|
|---|
| 203 |
|
|---|
| 204 | }
|
|---|
| 205 |
|
|---|
| 206 | // Random number that decides the set of bins that the program will get
|
|---|
| 207 | start_bin=RandomNumber->Uniform(1.0e4);
|
|---|
| 208 |
|
|---|
| 209 | // Filling trigger response
|
|---|
| 210 |
|
|---|
| 211 | bin=(Int_t)(start_bin*4);
|
|---|
| 212 |
|
|---|
| 213 | for (i=0;i<TRIGGER_TIME_SLICES;i++){
|
|---|
| 214 |
|
|---|
| 215 | time=((float)i)/SLICES_PER_NSEC;
|
|---|
| 216 |
|
|---|
| 217 | if (time>(bin-start_bin*4.0)/4.0) bin++;
|
|---|
| 218 |
|
|---|
| 219 | if (bin>=TRIGBINS) bin=bin-TRIGBINS;
|
|---|
| 220 |
|
|---|
| 221 | out_tr[i]=MSLStored.GetTrig(bin);
|
|---|
| 222 | }
|
|---|
| 223 |
|
|---|
| 224 | // Filling fadc response
|
|---|
| 225 |
|
|---|
| 226 | bin=(Int_t) (start_bin*0.3);
|
|---|
| 227 |
|
|---|
| 228 | for (i=0;i<(Int_t) SLICES_MFADC;i++){
|
|---|
| 229 |
|
|---|
| 230 | time=((float)i)*WIDTH_FADC_TIMESLICE;
|
|---|
| 231 |
|
|---|
| 232 | if (time>(bin-start_bin*0.3)/0.3) bin++;
|
|---|
| 233 |
|
|---|
| 234 | if (bin>=FADCBINS) bin=bin-FADCBINS;
|
|---|
| 235 |
|
|---|
| 236 | out_Fr[i]=MSLStored.GetFadc(bin);
|
|---|
| 237 | }
|
|---|
| 238 |
|
|---|
| 239 | return 1;
|
|---|
| 240 | }
|
|---|