Ignore:
Timestamp:
10/12/04 14:43:18 (20 years ago)
Author:
moralejo
Message:
*** empty log message ***
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Simulation/Detector/include-MLons/MLons.cxx

    r5103 r5248  
    33using namespace std;
    44
    5 MLons::MLons(){
     5MLons::MLons()
     6{
    67  //-----------------------------------------------------------------
    78  //
     
    910  //
    1011
    11   fTrigShape = 0.0;
     12  fTrigShape = 0;
    1213  fAmplTrig = 1.0; 
    1314  fFwhmTrig = 2.0;
    14 
    15   fFadcShape = 0.0;
     15  fFadcSlicesPerNanosec = FADC_SLICES_PER_NSEC;
     16
     17  fFadcShape = 0;
    1618  fIntegFadc = 1.0;
    1719  fFwhmFadc = 2.0;
    1820
    19   RandomNumber = new TRandom() ;
     21  RandomNumber = new TRandom();
    2022  RandomNumber -> SetSeed(0);
    2123
    2224}
    2325
    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){
     26MLons::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{
    2630  //--------------------------------------------------------------------
    2731  //
     
    3741  fFwhmFadc = in_FwhmF;
    3842
     43  fFadcSlicesPerNanosec = in_Fadc_Slices_per_ns;
     44
     45  MSLStored = new MStarLight;
     46
    3947  RandomNumber = new TRandom() ;
    4048  RandomNumber -> SetSeed(0);
    4149}
    4250
    43 void MLons::Reset() {
     51void MLons::Reset()
     52{
    4453  //-----------------------------------------------------------------
    4554  //
     
    4756  //
    4857
    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();
    5867
    5968}
     
    110119}
    111120
    112 void MLons::ReadBinaryMStarLight(char *filename){
    113 
    114   MSLStored.ReadBinary(filename);
    115 
    116 }
    117 
    118 Int_t MLons::CheckTrig(){
     121void MLons::ReadBinaryMStarLight(char *filename)
     122{
     123  MSLStored->ReadBinary(filename);
     124}
     125
     126Int_t MLons::CheckTrig()
     127{
    119128  //--------------------------------------------------------------------
    120129  //
     
    122131  //
    123132
    124   if (  fAmplTrig == MSLStored.GetAmplTrig() &&
    125         fFwhmTrig == MSLStored.GetFwhmTrig())
     133  if (  fAmplTrig == MSLStored->GetAmplTrig() &&
     134        fFwhmTrig == MSLStored->GetFwhmTrig())
    126135    return 1;
    127136
     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
    128142  return 0;
    129143}
    130144
    131 Int_t MLons::CheckFADC(){
     145Int_t MLons::CheckFADC()
     146{
    132147  //--------------------------------------------------------------------
    133148  //
     
    135150  //
    136151
    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() )
    140156    return 1;
    141157
     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
    142167  return 0;
    143168}
    144169
    145170Int_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{
    147173  //-------------------------------------------------------------------------
    148174  //
     
    154180  Char_t cstoredbright[10];
    155181
    156   Int_t i;
    157182  Int_t bin;
    158   Float_t start_bin;
    159   Float_t time;
    160 
     183  Float_t start_time;
     184
     185
     186  //
    161187  // The following code line commented means that the simulation will crash if
    162188  // some pixel ask for more lons than what we have in the database.
    163189  // 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
    168197
    169198  //  Check if the the brightness is the same than the last time.
    170   //  NOTE: Same means, the smae 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){
    173202    sprintf(cbright,"%4.2f",in_br);
    174     sprintf(cstoredbright,"%4.2f",MSLStored.GetBrightness());
     203    sprintf(cstoredbright,"%4.2f",MSLStored->GetBrightness());
    175204  }
    176205  else{
    177206    sprintf(cbright,"%3.1f",in_br);
    178     sprintf(cstoredbright,"%3.1f",MSLStored.GetBrightness());
     207    sprintf(cstoredbright,"%3.1f",MSLStored->GetBrightness());
    179208  }
    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]);
    190220 
    191     strcat(filename_slt, ".slt");
     221      strcat(filename_slt, ".slt");
    192222 
    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
    204240    }
    205     MSLStored.SetBrightness(in_br);
    206 
    207  }
    208241
    209242  // 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);
    211244
    212245  //  Filling trigger response
    213246
    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
    226261
    227262  //  Filling fadc response
    228263
    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)));
    241280
    242281  return 1;
Note: See TracChangeset for help on using the changeset viewer.