- Timestamp:
- 10/12/04 14:43:18 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Simulation/Detector/include-MLons/MLons.cxx
r5103 r5248 3 3 using namespace std; 4 4 5 MLons::MLons(){ 5 MLons::MLons() 6 { 6 7 //----------------------------------------------------------------- 7 8 // … … 9 10 // 10 11 11 fTrigShape = 0 .0;12 fTrigShape = 0; 12 13 fAmplTrig = 1.0; 13 14 fFwhmTrig = 2.0; 14 15 fFadcShape = 0.0; 15 fFadcSlicesPerNanosec = FADC_SLICES_PER_NSEC; 16 17 fFadcShape = 0; 16 18 fIntegFadc = 1.0; 17 19 fFwhmFadc = 2.0; 18 20 19 RandomNumber = new TRandom() 21 RandomNumber = new TRandom(); 20 22 RandomNumber -> SetSeed(0); 21 23 22 24 } 23 25 24 MLons::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 MLons::MLons(Int_t in_shapeT, Float_t in_amplT, Float_t in_FwhmT, 27 Int_t in_shapeF, Float_t in_integF, Float_t in_FwhmF, 28 Float_t in_Fadc_Slices_per_ns) 29 { 26 30 //-------------------------------------------------------------------- 27 31 // … … 37 41 fFwhmFadc = in_FwhmF; 38 42 43 fFadcSlicesPerNanosec = in_Fadc_Slices_per_ns; 44 45 MSLStored = new MStarLight; 46 39 47 RandomNumber = new TRandom() ; 40 48 RandomNumber -> SetSeed(0); 41 49 } 42 50 43 void MLons::Reset() { 51 void MLons::Reset() 52 { 44 53 //----------------------------------------------------------------- 45 54 // … … 47 56 // 48 57 49 fTrigShape = 0 .;50 fAmplTrig = 0. 51 fFwhmTrig = 0. 52 53 fFadcShape = 0 .;54 fIntegFadc = 0.;55 fFwhmFadc = 0. 56 57 MSLStored .Reset();58 fTrigShape = 0; 59 fAmplTrig = 0.; 60 fFwhmTrig = 0.; 61 62 fFadcShape = 0; 63 fIntegFadc = 0.; 64 fFwhmFadc = 0.; 65 66 MSLStored->Reset(); 58 67 59 68 } … … 110 119 } 111 120 112 void MLons::ReadBinaryMStarLight(char *filename) {113 114 MSLStored .ReadBinary(filename);115 116 } 117 118 Int_t MLons::CheckTrig(){121 void MLons::ReadBinaryMStarLight(char *filename) 122 { 123 MSLStored->ReadBinary(filename); 124 } 125 126 Int_t MLons::CheckTrig() 127 { 119 128 //-------------------------------------------------------------------- 120 129 // … … 122 131 // 123 132 124 if ( fAmplTrig == MSLStored .GetAmplTrig() &&125 fFwhmTrig == MSLStored .GetFwhmTrig())133 if ( fAmplTrig == MSLStored->GetAmplTrig() && 134 fFwhmTrig == MSLStored->GetFwhmTrig()) 126 135 return 1; 127 136 137 cout << "1 phe- pulse amplitudes for trigger (mV): " << fAmplTrig << " " 138 << MSLStored->GetAmplTrig() << endl; 139 cout << "1 phe- pulse FWHM for trigger (ns): " << fFwhmTrig << " " 140 << MSLStored->GetFwhmTrig() << endl; 141 128 142 return 0; 129 143 } 130 144 131 Int_t MLons::CheckFADC(){ 145 Int_t MLons::CheckFADC() 146 { 132 147 //-------------------------------------------------------------------- 133 148 // … … 135 150 // 136 151 137 if ( fIntegFadc == MSLStored.GetIntegFadc() && 138 fFwhmFadc == MSLStored.GetFwhmFadc() && 139 fFadcShape == MSLStored.GetShapeFadc()) 152 if ( fIntegFadc == MSLStored->GetIntegFadc() && 153 fFwhmFadc == MSLStored->GetFwhmFadc() && 154 fFadcShape == MSLStored->GetShapeFadc() && 155 fFadcSlicesPerNanosec == MSLStored->GetFadcSlicesPerNanosec() ) 140 156 return 1; 141 157 158 cout << "1 phe- FADC pulse shape : " << fFadcShape << " " 159 << MSLStored->GetShapeFadc() << endl; 160 cout << "1 phe- FADC pulse integral (counts) : " << fIntegFadc << " " 161 << MSLStored->GetIntegFadc() << endl; 162 cout << "1 phe- FADC pulse FWHM (ns) : " << fFwhmFadc << " " 163 << MSLStored->GetFwhmFadc() << endl; 164 cout << "FADC sampling frequencies (GHz) : " << fFadcSlicesPerNanosec << " " 165 << MSLStored->GetFadcSlicesPerNanosec() << endl; 166 142 167 return 0; 143 168 } 144 169 145 170 Int_t MLons::GetResponse(Float_t in_br, Float_t in_pre, 146 Float_t *out_tr, Float_t *out_Fr){ 171 Float_t *out_tr, Float_t *out_Fr) 172 { 147 173 //------------------------------------------------------------------------- 148 174 // … … 154 180 Char_t cstoredbright[10]; 155 181 156 Int_t i;157 182 Int_t bin; 158 Float_t start_bin; 159 Float_t time; 160 183 Float_t start_time; 184 185 186 // 161 187 // The following code line commented means that the simulation will crash if 162 188 // some pixel ask for more lons than what we have in the database. 163 189 // 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 190 // not crash if a pixel ask for more than it is simulated but would 191 // assign to it less lons. 192 // I think this is unnecessary now. AM 5/10/2004 193 // if (in_br>49.9) in_br=49.9; // To avoid error for high required brightness 194 // // It has to be improved 195 // 196 168 197 169 198 // Check if the the brightness is the same than the last time. 170 // NOTE: Same means, the s mae inside the required precision!!!171 172 if(in_br< 1.0){199 // NOTE: Same means, the same inside the required precision!!! 200 201 if(in_br<=1.0){ 173 202 sprintf(cbright,"%4.2f",in_br); 174 sprintf(cstoredbright,"%4.2f",MSLStored .GetBrightness());203 sprintf(cstoredbright,"%4.2f",MSLStored->GetBrightness()); 175 204 } 176 205 else{ 177 206 sprintf(cbright,"%3.1f",in_br); 178 sprintf(cstoredbright,"%3.1f",MSLStored .GetBrightness());207 sprintf(cstoredbright,"%3.1f",MSLStored->GetBrightness()); 179 208 } 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]); 209 210 if (strcmp(cbright, cstoredbright)) 211 { 212 // Building the filename 213 // Note: it would be nice to get an algorithm that gets the name of 214 // files it needs to get brightness as a function of precison(in_pre), 215 // brightnes (in_br) and the Star_files that are in the "Path" directory. 216 217 strcpy(filename_slt, & path[0]); 218 strcat(filename_slt, "Brightness"); 219 strcat(filename_slt, & cbright[0]); 190 220 191 strcat(filename_slt, ".slt");221 strcat(filename_slt, ".slt"); 192 222 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; 223 // If brightness is different it check if the new file has the 224 // required parameters. 225 // Note: I could be faster to store the whole trigger and fadc 226 // response and use it while brightness does not change. Then the 227 // root file should be open and close here. 228 229 MSLStored->ReadBinary(filename_slt); 230 231 if (!(CheckTrig() && CheckFADC())) 232 { 233 cout << "ERROR: The Database for light from Night Sky Background is wrong"<<endl; 234 cout << " Make sure that you generated the database with the same shape" << endl; 235 cout << " for Fadc and trigger that you are asking now."<<endl; 236 return 0; 237 } 238 MSLStored->SetBrightness(in_br); 239 204 240 } 205 MSLStored.SetBrightness(in_br);206 207 }208 241 209 242 // Random number that decides the set of bins that the program will get 210 start_ bin=RandomNumber->Uniform(1.0e4);243 start_time = RandomNumber->Uniform(TIMERANGE); 211 244 212 245 // Filling trigger response 213 246 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 } 247 bin = (Int_t)(start_time*TRIG_SLICES_PER_NSEC); 248 249 250 if (bin+TRIGGER_TIME_SLICES > MSLStored->GetBinsTrig()) 251 { 252 memcpy (out_tr, MSLStored->GetTrigPointer(bin), 253 (UInt_t) (MSLStored->GetBinsTrig()-bin)*sizeof(Float_t)); 254 memcpy (out_tr, MSLStored->GetTrigPointer(0), 255 (UInt_t) (bin+TRIGGER_TIME_SLICES-MSLStored->GetBinsTrig())*sizeof(Float_t)); 256 } 257 else 258 memcpy (out_tr, MSLStored->GetTrigPointer(bin), 259 (UInt_t) TRIGGER_TIME_SLICES*sizeof(Float_t)); 260 226 261 227 262 // Filling fadc response 228 263 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 } 264 // Start bin in the NSB database: 265 bin = (Int_t) (start_time*MSLStored->GetBinsFadc()/MSLStored->GetTimeRange()); 266 267 // If we go over the end of the database, continue at the begining of it: 268 if (bin + (Int_t)(TOTAL_TRIGGER_TIME*fFadcSlicesPerNanosec) > MSLStored->GetBinsFadc()) 269 { 270 memcpy (out_Fr, MSLStored->GetFadcPointer(bin), 271 (Int_t)(MSLStored->GetBinsFadc()-bin)*sizeof(Float_t)); 272 273 memcpy (out_Fr, MSLStored->GetFadcPointer(0), 274 (Int_t)(bin + TOTAL_TRIGGER_TIME*fFadcSlicesPerNanosec - 275 MSLStored->GetBinsFadc())*sizeof(Float_t)); 276 } 277 else 278 memcpy (out_Fr, MSLStored->GetFadcPointer(bin), 279 (Int_t)(TOTAL_TRIGGER_TIME*fFadcSlicesPerNanosec*sizeof(Float_t))); 241 280 242 281 return 1;
Note:
See TracChangeset
for help on using the changeset viewer.