Index: trunk/MagicSoft/Simulation/Detector/StarResponse/MStarLight.cxx
===================================================================
--- trunk/MagicSoft/Simulation/Detector/StarResponse/MStarLight.cxx	(revision 5104)
+++ trunk/MagicSoft/Simulation/Detector/StarResponse/MStarLight.cxx	(revision 5248)
@@ -3,153 +3,173 @@
 using namespace std;
 
-MStarLight::MStarLight() {
+MStarLight::MStarLight(Float_t fadc_slices_per_ns, Int_t response_slices_fadc) {
   //
   //   default constructor
   //
 
+  fBrightness  = 0.; 
+  fTimeRange   = TIMERANGE; 
+
+  fFadcSlicesPerNanosec = fadc_slices_per_ns; // "real" number of FADC slices per ns
+
+  fResponseSlicesFadc = response_slices_fadc; 
+  // total number of bins in the histogram containing the response of the FADC to a
+  // single photoelectron. The bins are narrower than the true FADC slices by a factor
+  // equal to SUBBINS (see MFadcDefine.h)
+
+
+  fBinsTrig = (Int_t)(TRIG_SLICES_PER_NSEC*TIMERANGE);   // Default value 4*10000=40000
+  fTrigShape   = 0; 
+  fAmplTrig    = 0.; 
+  fFwhmTrig    = 0.; 
+
+  fBinsFadc    = (Int_t)(fFadcSlicesPerNanosec*TIMERANGE);  // Default value 0.3*10000=3000
+  fFadcShape   = 0; 
+  fIntegFadc   = 0.; 
+  fFwhmFadc    = 0.; 
+
+
+  fTrig     = new Float_t[fBinsTrig];
+  fTrigResp = new Float_t[RESPONSE_SLICES_TRIG];
+  fFadc     = new Float_t[fBinsFadc];
+  fFadcResp = new Float_t[fResponseSlicesFadc]; 
+  
+  for (Int_t i= 0; i< fBinsTrig ; i++) 
+    fTrig[i] = 0. ; 
+
+  for (Int_t i= 0; i < fBinsFadc; i++) 
+    fFadc[i] = 0.; 
+  
+  for (Int_t i = 0; i < RESPONSE_SLICES_TRIG; i++) 
+    fTrigResp[i] = 0.; 
+
+  for (Int_t i = 0; i < fResponseSlicesFadc; i++) 
+    fFadcResp[i] = 0.; 
+}
+
+void MStarLight::Reset() {
+
+  
   fBrightness  = 0. ; 
-  fTimeRange   = TIMERANGE  ; 
-
-  fBinsTrig    = TRIGBINS   ; 
-  fTrigShape   = 0. ; 
-  fAmplTrig    = 0. ; 
-  fFwhmTrig    = 0. ; 
-
-  fBinsFadc    = FADCBINS   ; 
-  fFadcShape   = 0. ; 
-  fIntegFadc    = 0. ; 
-  fFwhmFadc    = 0. ; 
-
-  
-  for (Int_t i= 0; i< TRIGBINS ; i++) 
-    fTrig[i] = 0. ; 
-
-  for (Int_t i= 0; i<FADCBINS; i++) 
-    fFadc[i] = 0. ; 
-  
-  for (Int_t i= 0; i<40; i++) 
-    fTrigResp[i] = 0. ; 
-
-  for (Int_t i= 0; i<45; i++) 
-    fFadcResp[i] = 0. ; 
-}
-
-void MStarLight::Reset() {
-
-  
-  fBrightness  = 0. ; 
-  fTimeRange   = TIMERANGE  ; 
-
-  fBinsTrig    = TRIGBINS   ; 
-  fTrigShape   = 0. ; 
-  fAmplTrig    = 0. ; 
-  fFwhmTrig    = 0. ; 
-
-  fBinsFadc    = FADCBINS   ; 
-  fFadcShape   = 0. ; 
-  fIntegFadc    = 0. ; 
-  fFwhmFadc    = 0. ; 
-
-  
-  for (Int_t i= 0; i< TRIGBINS ; i++) 
-    fTrig[i] = 0. ; 
-
-  for (Int_t i= 0; i<FADCBINS; i++) 
-    fFadc[i] = 0. ; 
-  
-  for (Int_t i= 0; i<40; i++) 
-    fTrigResp[i] = 0. ; 
-
-  for (Int_t i= 0; i<45; i++) 
-    fFadcResp[i] = 0. ; 
-}
-
-
+  fTimeRange   = TIMERANGE; 
+
+  fTrigShape   = 0; 
+  fAmplTrig    = 0.; 
+  fFwhmTrig    = 0.; 
+
+  fFadcShape   = 0; 
+  fIntegFadc   = 0.; 
+  fFwhmFadc    = 0.; 
+
+  
+  for (Int_t i= 0; i < fBinsTrig ; i++) 
+    fTrig[i] = 0.; 
+
+  for (Int_t i= 0; i < fBinsFadc; i++) 
+    fFadc[i] = 0.; 
+  
+  for (Int_t i = 0; i < RESPONSE_SLICES_TRIG; i++) 
+    fTrigResp[i] = 0.; 
+
+  for (Int_t i = 0; i < fResponseSlicesFadc; i++) 
+    fFadcResp[i] = 0.; 
+}
 
 Float_t MStarLight::GetBrightness () 
 {
-  return fBrightness  ; 
+  return fBrightness; 
 }
 
 void MStarLight::SetBrightness (Float_t in ) 
 {
-  fBrightness = in ; 
+  fBrightness = in; 
 }
 
 Float_t MStarLight::GetAmplTrig () 
 {
-  return fAmplTrig  ; 
+  return fAmplTrig ; 
 }
 
 void MStarLight::SetAmplTrig (Float_t in ) 
 {
-  fAmplTrig = in ; 
+  fAmplTrig = in; 
 }
 
 Float_t  MStarLight::GetFwhmTrig () 
 {
-  return fFwhmTrig  ; 
+  return fFwhmTrig; 
 }
 
 void MStarLight::SetFwhmTrig (Float_t in ) 
 {
-  fFwhmTrig = in ; 
-}
-
+  fFwhmTrig = in; 
+}
+
+void MStarLight::SetFadcSlicesPerNanosec (Float_t in)
+{
+  fFadcSlicesPerNanosec = in;
+  fBinsFadc    = (Int_t)(fFadcSlicesPerNanosec*TIMERANGE);
+
+  if (fFadc)
+    delete [] fFadc;
+
+  fFadc = new Float_t[fBinsFadc];
+
+  for (Int_t i= 0; i < fBinsFadc; i++) 
+    fFadc[i] = 0.;  
+}
 
 Float_t MStarLight::GetIntegFadc () 
 {
-  return fIntegFadc  ; 
+  return fIntegFadc; 
 }
 
 void MStarLight::SetIntegFadc (Float_t in ) 
 {
-  fIntegFadc = in ; 
+  fIntegFadc = in; 
 }
 
 Float_t  MStarLight::GetFwhmFadc () 
 {
-  return fFwhmFadc  ; 
+  return fFwhmFadc; 
 }
 
 void MStarLight::SetFwhmFadc (Float_t in ) 
 {
-  fFwhmFadc = in ; 
-}
-
-
-void MStarLight::SetTrigResponse( Float_t *in ) {
-  
-  for (Int_t i= 0; i<40; i++) 
-    fTrigResp[i] = in[i] ; 
-  
-}
-
-void MStarLight::SetFadcResponse( Float_t *in ) {
-
-  for (Int_t i= 0; i<45; i++)
-    fFadcResp[i] = in[i] ; 
-}
-
-void MStarLight::FillResponse( Float_t ampl, Float_t time ) {
-
-  //     fill the trigger response
-  
-  Int_t startbin = (Int_t) (time * 4)  ; 
-  
-  Int_t icount = 0 ;
-  Int_t idata      ; 
-  
-  for ( Int_t i=startbin ; i<startbin+40 ; i++) {
-    //
-    if ( i < TRIGBINS ) 
-      idata = i ; 
-    else if ( i >= TRIGBINS ) 
-      idata = i - TRIGBINS ; 
-
-    fTrig[idata] = fTrig[idata] + ampl * fTrigResp[icount] ; 
-    
-    icount++ ; 
-  }
+  fFwhmFadc = in; 
+}
+
+
+void MStarLight::SetTrigResponse( Float_t *in )
+{
+  for (Int_t i = 0; i < RESPONSE_SLICES_TRIG; i++) 
+    fTrigResp[i] = in[i]; 
+}
+
+void MStarLight::SetFadcResponse( Float_t *in )
+{
+  for (Int_t i = 0; i < fResponseSlicesFadc; i++)
+    fFadcResp[i] = in[i]; 
+}
+
+void MStarLight::FillResponse( Float_t ampl, Float_t time )
+{
+  //  fill the trigger response
+  
+  Int_t startbin = (Int_t) (time * ((Float_t)fBinsTrig/TIMERANGE));
+
+  Int_t icount = 0;
+  Int_t idata; 
+  
+  for ( Int_t i = startbin ; i < startbin+RESPONSE_SLICES_TRIG ; i++)
+    {
+      if ( i < fBinsTrig ) 
+	idata = i; 
+      else if ( i >= fBinsTrig ) 
+	idata = i - fBinsTrig; 
+
+      fTrig[idata] = fTrig[idata] + ampl * fTrigResp[icount];
+      icount++ ; 
+    }
 
   //
@@ -157,11 +177,11 @@
   //
 
-  startbin = (Int_t) ( time / 0.6666666666 );
-  
+  startbin = (Int_t) ( time * ((Float_t)(fBinsFadc*SUBBINS)/TIMERANGE));
+
   Int_t ichanfadc = 0 ; 
   
   //
   //   putting the response slices in the right sig slices.
-  //   Be carefull, because both slices have different widths. 
+  //   Be careful, because both slices have different widths. 
   //
 
@@ -170,22 +190,21 @@
   // the signal within each FADC slice, but measures just the signal height
   // at one point, like the real FADC does. By default, each FADC slice 
-  // contains 5 bins of the response histogram(fFadcResp[45]). Warning:
-  // do not change this unless you do the corresponding modifications also
-  // in MFadc.cxx, or the signal and the noise photoelectrons will be treated 
-  // differently!!
-  //
-
-  for ( Int_t i = 0 ; i < 45; i += 5 ) {
-    ichanfadc = (Int_t) ((startbin+i)/5) ; 
-    
-    if ( (ichanfadc) < FADCBINS ) 
-      idata = ichanfadc ; 
-    else if ( ichanfadc >=FADCBINS ) 
-      idata = ichanfadc-FADCBINS ; 
-    
-    fFadc[idata] += (ampl * fFadcResp[i] )  ; 
-    
-  }
-
+  // contains SUBBINS bins of the response histogram
+  // (fFadcResp). Warning: do not change this unless you do the corresponding 
+  // modifications also in MFadc.cxx, or the signal and the noise photoelectrons 
+  // will be treated differently!!
+  //
+
+  for ( Int_t i = 0 ; i < fResponseSlicesFadc; i += SUBBINS )
+    {
+      ichanfadc = (Int_t) ((startbin+i)/(Float_t)SUBBINS); 
+
+      if ( ichanfadc < fBinsFadc ) 
+	idata = ichanfadc; 
+      else if ( ichanfadc >= fBinsFadc ) 
+	idata = ichanfadc-fBinsFadc; 
+
+      fFadc[idata] += (ampl * fFadcResp[i]); 
+    }
 }
 
@@ -197,121 +216,108 @@
   TRandom2 wuerfel( (UInt_t) (noiseTrig*100) ) ; 
  
-  for (Int_t i=0; i< TRIGBINS ; i++ ) {
-    fTrig[i] += wuerfel.Gaus(0., noiseTrig ) ; 
-  }
-
-  for (Int_t i=0; i< FADCBINS ; i++ ) {
-    fFadc[i] += wuerfel.Gaus(0., noiseFadc ) ; 
-  }
-  
-  
-}
-
-Float_t MStarLight::GetTrig( Int_t i){
+  for (Int_t i=0; i< fBinsTrig ; i++ )
+    fTrig[i] += wuerfel.Gaus(0., noiseTrig );
+
+  for (Int_t i=0; i< fBinsFadc ; i++ )
+    fFadc[i] += wuerfel.Gaus(0., noiseFadc );
+  
+}
+
+Float_t MStarLight::GetTrig( Int_t i)
+{
   //------------------------------------------------------------------
   //
-  //  It gets the value of the simualted trigger in the i bin
+  //  It gets the value of the simulated trigger in the i bin
   //
   return fTrig[i];
 }
 
-Float_t MStarLight::GetFadc( Int_t i){
+Float_t MStarLight::GetFadc( Int_t i)
+{
   //------------------------------------------------------------------
   //
-  //  It gets the value of the simualted FADC signal in the i bin
+  //  It gets the value of the simulated FADC signal in the i bin
   //
   return fFadc[i];
 }
 
-void MStarLight::StoreHisto( char *filename) {
-  
-  Float_t baseline = 0. ; 
-
-
-  //    first the histogramms for trigger
+void MStarLight::StoreHisto( char *filename)
+{
+
+  Float_t baseline = 0.; 
+
+  //    first the histograms for trigger
   //
   //    the calculated trigger signal before baseline
   // 
 
-  TH1F  trigresp ("trigresp", "Trigger Response", TRIGBINS, 0., TIMERANGE) ; 
-
-  for (Int_t i=0; i< TRIGBINS ; i++ ) {
-    
-    trigresp.SetBinContent(i, fTrig[i]) ; 
-
-    baseline = baseline + fTrig[i]  ; 
-  }
-
-  baseline = baseline / TRIGBINS ; 
+  TH1F  trigresp ("trigresp", "Trigger Response", fBinsTrig, 0., TIMERANGE);
+
+  for (Int_t i=0; i< fBinsTrig ; i++ )
+    {
+      trigresp.SetBinContent(i+1, fTrig[i]);
+      baseline += fTrig[i];
+    }
+
+  baseline /= fBinsTrig;
   
   TH1F  trigbase ("trigbase", "Response after Baseline shift", 
-		  TRIGBINS, 0., TIMERANGE) ; 
-  for (Int_t i=0; i< TRIGBINS ; i++ ) {
-    
-    trigbase.SetBinContent(i, fTrig[i]-baseline ) ; 
-    
-  }
+		  fBinsTrig, 0., TIMERANGE) ; 
+
+  for (Int_t i = 0; i < fBinsTrig ; i++)
+    trigbase.SetBinContent(i+1, fTrig[i]-baseline );
   
   TH1F  trigdist ("trigdist", "Noise on the baseline", 
-		  1000, -25., 25. ) ; 
-
-  for (Int_t i=0; i< TRIGBINS ; i++ ) {
-    
-    trigdist.Fill( (Float_t) trigbase.GetBinContent(i) ) ; 
-  }
+		  1000, -25., 25. );
+
+  for (Int_t i = 0; i < fBinsTrig ; i++)
+    trigdist.Fill( (Float_t) trigbase.GetBinContent(i+1) );
 
 
   // 
-  //     second the histograms for the fadc
-  //
-  
-  
-  TH1F  fadcresp ("fadcresp", "Fadc Response", FADCBINS, 0., TIMERANGE) ; 
-
-  for (Int_t i=0; i< FADCBINS ; i++ ) {
-    
-    fadcresp.SetBinContent(i, fFadc[i]) ; 
-
-    baseline = baseline + fFadc[i]  ; 
-  }
-
-  baseline = baseline / FADCBINS ; 
+  // Now the histograms for the fadc
+  //
+
+  TH1F  fadcresp ("fadcresp", "Fadc Response", fBinsFadc, 0., TIMERANGE); 
+
+  baseline = 0.;
+  for (Int_t i=0; i < fBinsFadc; i++)
+    {
+      fadcresp.SetBinContent(i+1, fFadc[i]); 
+      baseline += fFadc[i]; 
+    }
+
+  baseline /= fBinsFadc; 
   
   TH1F  fadcbase ("fadcbase", "Fadc after Baseline shift", 
-		  FADCBINS, 0., TIMERANGE) ; 
-  for (Int_t i=0; i< FADCBINS ; i++ ) {
-    
-    fadcbase.SetBinContent(i, fFadc[i]-baseline ) ; 
-    
-  }
-  
+		  fBinsFadc, 0., TIMERANGE) ; 
+
+  for (Int_t i=0; i< fBinsFadc ; i++ )
+    fadcbase.SetBinContent(i+1, fFadc[i]-baseline ); 
+
   TH1F  fadcdist ("fadcdist", "Noise on fadc", 
 		  1000, -100., 100. ) ; 
 
-  for (Int_t i=0; i< FADCBINS ; i++ ) {
-    
-    fadcdist.Fill( (Float_t) fadcbase.GetBinContent(i) ) ; 
-  }
-
-
-
-  
-  TFile outfile( filename, "UPDATE" ) ; 
-  
-  trigresp.Write() ; 
-  trigbase.Write() ; 
-  trigdist.Write() ; 
-
-  fadcresp.Write() ; 
-  fadcbase.Write() ; 
-  fadcdist.Write() ; 
-  
-  
-  outfile.Close() ; 
-}
-
-void MStarLight::WriteBinary( char *filename) {
-  //
-  //  write the things to the binary file
+  for (Int_t i=0; i< fBinsFadc ; i++ )
+    fadcdist.Fill( (Float_t) fadcbase.GetBinContent(i+1) ); 
+
+  TFile outfile( filename, "RECREATE");
+  
+  trigresp.Write(); 
+  trigbase.Write(); 
+  trigdist.Write(); 
+
+  fadcresp.Write(); 
+  fadcbase.Write(); 
+  fadcdist.Write(); 
+  
+  
+  outfile.Close(); 
+}
+
+void MStarLight::WriteBinary( char *filename)
+{
+  //
+  //  write the information to the binary file
 
   FILE *datei ; 
@@ -319,9 +325,9 @@
   datei = fopen ( filename, "w" ) ; 
   
-  if ( ! datei ) {
-    cout << " ERROR: Can't open the file " << filename 
-	 << endl ; 
-    exit (230) ; 
-  }
+  if ( ! datei )
+    {
+      cout << " ERROR: Can't open the file " << filename << endl;
+      exit (230);
+    }
 
   Float_t version = VERSIONSR;
@@ -329,19 +335,20 @@
   //   write them out 
 
-  fwrite ( &version, sizeof(Float_t), 1, datei ) ; 
-  fwrite ( &fBrightness, sizeof(Float_t), 1, datei ) ; 
-  fwrite ( &fTimeRange , sizeof(Float_t), 1, datei ) ; 
-
-  fwrite ( &fBinsTrig  , sizeof(Float_t), 1, datei ) ; 
-  fwrite ( &fTrigShape , sizeof(Float_t), 1, datei ) ; 
-  fwrite ( &fAmplTrig  , sizeof(Float_t), 1, datei ) ; 
-  fwrite ( &fFwhmTrig  , sizeof(Float_t), 1, datei ) ; 
-
-  fwrite ( &fBinsFadc  , sizeof(Float_t), 1, datei ) ; 
-  fwrite ( &fFadcShape , sizeof(Float_t), 1, datei ) ; 
-  fwrite ( &fIntegFadc , sizeof(Float_t), 1, datei ) ; 
-  fwrite ( &fFwhmFadc  , sizeof(Float_t), 1, datei ) ; 
-
-  fwrite ( &fTrig      , sizeof(Float_t), TRIGBINS, datei ) ; 
+  fwrite ( &version,               sizeof(Float_t), 1, datei ); 
+  fwrite ( &fBrightness,           sizeof(Float_t), 1, datei ); 
+  fwrite ( &fTimeRange,            sizeof(Float_t), 1, datei ); 
+  fwrite ( &fFadcSlicesPerNanosec, sizeof(Float_t), 1, datei ); 
+
+  fwrite ( &fBinsTrig  , sizeof(Int_t),   1, datei ); 
+  fwrite ( &fTrigShape , sizeof(Int_t),   1, datei ); 
+  fwrite ( &fAmplTrig  , sizeof(Float_t), 1, datei ); 
+  fwrite ( &fFwhmTrig  , sizeof(Float_t), 1, datei ); 
+
+  fwrite ( &fBinsFadc  , sizeof(Int_t),   1, datei ); 
+  fwrite ( &fFadcShape , sizeof(Int_t),   1, datei ); 
+  fwrite ( &fIntegFadc , sizeof(Float_t), 1, datei ); 
+  fwrite ( &fFwhmFadc  , sizeof(Float_t), 1, datei ); 
+
+  fwrite (fTrig, sizeof(Float_t), fBinsTrig, datei); 
 
   //    We want to store the FADC signal taking into account the AC
@@ -351,23 +358,21 @@
   // 
 
-  Float_t baseline = 0. ; 
-
-  for (Int_t i=0; i< FADCBINS ; i++ ) {
-    
-    baseline = baseline + fFadc[i]  ; 
-  }
-
-  baseline = baseline / FADCBINS ; 
-  
-  for (Int_t i=0; i< FADCBINS ; i++ ) {
-    
-      fFadc[i]=fFadc[i]-baseline;
-    
-  }
-  
-  fwrite ( &fFadc      , sizeof(Float_t), FADCBINS, datei ) ; 
-
-
-  fclose ( datei ) ; 
+  Float_t baseline = 0.; 
+
+  for (Int_t i=0; i< fBinsFadc ; i++ )
+    baseline += fFadc[i]; 
+
+  baseline /= fBinsFadc; 
+
+  Float_t *temp = new Float_t[fBinsFadc];
+
+  for (Int_t i=0; i < fBinsFadc; i++ )
+    temp[i] = fFadc[i]-baseline;
+  
+  fwrite (temp, sizeof(Float_t), fBinsFadc, datei); 
+
+  delete [] temp;
+
+  fclose ( datei ); 
   
 }
@@ -393,14 +398,14 @@
 
   Float_t read_version;
-  Float_t current_version=VERSIONSR;
-
-  // Check taht we read the right version of the Database
+  Float_t current_version = VERSIONSR;
+
+  // Check that we read the right version of the Database
   fread ( &read_version, sizeof(Float_t), 1, datei ) ; 
 
   if(Int_t(read_version)!=Int_t(current_version)){
     cout<<" ERROR: You are trying to read database VERSION "<<
-      read_version<<endl;
+      read_version << endl;
     cout<<"        You must generate a database for the current VERSION "<<
-      current_version<<endl;
+      current_version << endl;
     cout<<"        See the NSB database section in the Camera How to Use note."
 	<<endl;
@@ -408,28 +413,30 @@
   }
 
-  fread ( &fBrightness, sizeof(Float_t), 1, datei ) ; 
-  fread ( &fTimeRange , sizeof(Float_t), 1, datei ) ; 
-
-
-  fread ( &fBinsTrig  , sizeof(Float_t), 1, datei ) ; 
-  fread ( &fTrigShape , sizeof(Float_t), 1, datei ) ; 
-  fread ( &fAmplTrig  , sizeof(Float_t), 1, datei ) ; 
-  fread ( &fFwhmTrig  , sizeof(Float_t), 1, datei ) ; 
-
-  fread ( &fBinsFadc  , sizeof(Float_t), 1, datei ) ; 
-  fread ( &fFadcShape , sizeof(Float_t), 1, datei ) ; 
-  fread ( &fIntegFadc , sizeof(Float_t), 1, datei ) ; 
-  fread ( &fFwhmFadc  , sizeof(Float_t), 1, datei ) ; 
-
-  fread ( &fTrig      , sizeof(Float_t), TRIGBINS, datei ) ; 
-
-  fread ( &fFadc      , sizeof(Float_t), FADCBINS, datei ) ; 
-
-  
+  fread ( &fBrightness, sizeof(Float_t), 1, datei ); 
+  fread ( &fTimeRange , sizeof(Float_t), 1, datei ); 
+  fread ( &fFadcSlicesPerNanosec, sizeof(Float_t), 1, datei ); 
+
+  fread ( &fBinsTrig  , sizeof(Int_t),   1, datei ); 
+  fread ( &fTrigShape , sizeof(Int_t),   1, datei ); 
+  fread ( &fAmplTrig  , sizeof(Float_t), 1, datei ); 
+  fread ( &fFwhmTrig  , sizeof(Float_t), 1, datei ); 
+
+  fread ( &fBinsFadc  , sizeof(Int_t),   1, datei ); 
+  fread ( &fFadcShape , sizeof(Int_t),   1, datei ); 
+  fread ( &fIntegFadc , sizeof(Float_t), 1, datei ); 
+  fread ( &fFwhmFadc  , sizeof(Float_t), 1, datei ); 
+
+  if (fTrig)
+    delete [] fTrig;
+
+  if (fFadc)
+    delete [] fFadc;
+
+  fTrig = new Float_t[fBinsTrig];
+  fFadc = new Float_t[fBinsFadc];
+
+  fread (fTrig, sizeof(Float_t), fBinsTrig, datei); 
+  fread (fFadc, sizeof(Float_t), fBinsFadc, datei); 
 
   fclose ( datei ) ; 
 }
-
-
-
-
Index: trunk/MagicSoft/Simulation/Detector/StarResponse/MStarLight.hxx
===================================================================
--- trunk/MagicSoft/Simulation/Detector/StarResponse/MStarLight.hxx	(revision 5104)
+++ trunk/MagicSoft/Simulation/Detector/StarResponse/MStarLight.hxx	(revision 5248)
@@ -1,2 +1,5 @@
+#include "MFadcDefine.h"
+#include "MTriggerDefine.h"
+
 #ifndef __MStarLight__ 
 #define __MStarLight__ 
@@ -13,8 +16,6 @@
 #include "TRandom2.h" 
 
-#define VERSIONSR   1002.0
-#define TIMERANGE   10000. 
-#define TRIGBINS    40000
-#define FADCBINS     3000 
+#define VERSIONSR   1003.0
+#define TIMERANGE   10000  // ns
 
 class MStarLight {
@@ -22,68 +23,80 @@
  private: 
   
-  Float_t  fBrightness  ;   // the brightness of the star in phe/nsec
+  Float_t  fBrightness;  // the brightness of the star in phe/nsec
   
-  Float_t  fTimeRange   ;   // the time range of the trigger response
+  Float_t  fTimeRange;   // the time range of the trigger response
   
-  Float_t  fBinsTrig    ;   // Number of Bins in the trigger 
-  Float_t  fTrigShape   ;   // a number that indicate the shape type of 
-                            // the signal   
-                            // = 0 --> a gaussian  
-  Float_t  fAmplTrig    ;   // the amplitude of the trigger in mV
-  Float_t  fFwhmTrig    ;   // the width of the signal in nsec
+  Int_t    fBinsTrig;    // Number of Bins in the trigger database
+  Int_t    fTrigShape;   // a number that indicate the shape type of 
+                         // the signal   
+                         // = 0 --> a gaussian  
+  Float_t  fAmplTrig;    // the amplitude of the trigger in mV
+  Float_t  fFwhmTrig;    // the width of the signal in nsec
 
-  Float_t  fBinsFadc    ;   // Number of Bins in the trigger 
-  Float_t  fFadcShape   ;   // a number that indicate the shape type of 
-                            // the signal   
-                            // = 0 --> a gaussian  
-  Float_t  fIntegFadc    ;  // the integral of the single phe response
-                            // in the FADC (in FADC counts) 
-  Float_t  fFwhmFadc    ;   // the width of the signal in nsec
+  Int_t    fBinsFadc;    // Number of Bins in the FADC database 
+  Int_t    fFadcShape;   // a number that indicate the shape type of 
+                         // the signal   
+                         // = 0 --> a gaussian  
+  Float_t  fIntegFadc;   // the integral of the single phe response
+                         // in the FADC (in FADC counts) 
+  Float_t  fFwhmFadc;    // the width of the signal in nsec
   
-  Float_t  fTrig[TRIGBINS] ;   // 4.0 bins per nsec for 10000 nanoseconds
-  Float_t  fFadc[FADCBINS]  ;   // 0.3 bins per nsec for 10000 nanoseconds
-  
-  Float_t  fTrigResp [ 40 ] ;   // the shape of the response for trigger
-  Float_t  fFadcResp [ 45 ] ;   // the shape of the response for FADC
+  Float_t  *fTrig;       // Trigger branch "history" for 10000 nanoseconds
+  Float_t  *fTrigResp;   // the shape of the response for trigger
+  Float_t  *fFadc;       // FADC "history" for 10000 nanoseconds
+  Float_t  *fFadcResp;   // the shape of the response for FADC
+
+  Float_t  fFadcSlicesPerNanosec; // Number of FADC slices per ns 
+                                  // (may be < 1 if FADC is faster than 1 GHz)
+
+  Int_t    fResponseSlicesFadc;
 
  public:
-  
-  MStarLight() ; 
 
-  void Reset() ; 
+  MStarLight(Float_t fadc_slices_per_ns = 0., 
+	     Int_t response_slices_fadc = 0);
 
-  void SetBrightness( Float_t in ) ; 
-  void SetAmplTrig( Float_t in ) ; 
-  void SetFwhmTrig( Float_t in ) ; 
-  void SetShapeFadc( Float_t in ) { fFadcShape=in;}
-  void SetIntegFadc( Float_t in ) ; 
-  void SetFwhmFadc( Float_t in ) ; 
+  void Reset(); 
 
-  Float_t GetBrightness() ; 
-  Float_t GetAmplTrig() ; 
-  Float_t GetFwhmTrig() ; 
-  Float_t GetShapeFadc() {return fFadcShape;}
-  Float_t GetIntegFadc() ; 
-  Float_t GetFwhmFadc() ; 
+  void SetBrightness(Float_t in); 
+  void SetAmplTrig(Float_t in); 
+  void SetFwhmTrig(Float_t in); 
+  void SetShapeFadc(Int_t in)              {fFadcShape=in;}
+  void SetIntegFadc(Float_t in); 
+  void SetFwhmFadc(Float_t in); 
+  void SetFadcSlicesPerNanosec(Float_t in);
 
-  void SetTrigResponse(Float_t *in) ; 
 
-  void SetFadcResponse(Float_t *in) ; 
+  Float_t GetBrightness(); 
+  Float_t GetAmplTrig(); 
+  Float_t GetFwhmTrig(); 
+  Int_t   GetShapeFadc()            {return fFadcShape;}
+  Float_t GetIntegFadc(); 
+  Float_t GetFwhmFadc(); 
+  Int_t   GetBinsTrig()             {return fBinsTrig;} 
+  Int_t   GetBinsFadc()             {return fBinsFadc;} 
+  Float_t GetTimeRange()            {return fTimeRange;}
+  Float_t GetFadcSlicesPerNanosec() {return fFadcSlicesPerNanosec;}
 
-  void FillResponse(Float_t ampl, Float_t time) ; 
+  void SetTrigResponse(Float_t *in); 
+  void SetFadcResponse(Float_t *in); 
 
-  void ElecNoise ( Float_t noiseTrig =  0.3 , Float_t noiseFadc = .5 ) ; 
+  void FillResponse(Float_t ampl, Float_t time); 
+
+  void ElecNoise ( Float_t noiseTrig =  0.3 , Float_t noiseFadc = .5 ); 
 
   Float_t GetTrig (Int_t i);
-
   Float_t GetFadc (Int_t i);
 
-  void StoreHisto  (char *filename ) ;
+  Float_t* GetTrigPointer (Int_t i) { return &(fTrig[i]); }
+  Float_t* GetFadcPointer (Int_t i) { return &(fFadc[i]); }
 
-  void WriteBinary (char *filename ) ;
+  void StoreHisto  (char *filename );
 
-  void ReadBinary (char *filename ) ;
+  void WriteBinary (char *filename );
 
-} ; 
+  void ReadBinary (char *filename );
+
+}; 
 
 #endif 
Index: trunk/MagicSoft/Simulation/Detector/StarResponse/srreadparam.cxx
===================================================================
--- trunk/MagicSoft/Simulation/Detector/StarResponse/srreadparam.cxx	(revision 5104)
+++ trunk/MagicSoft/Simulation/Detector/StarResponse/srreadparam.cxx	(revision 5248)
@@ -19,7 +19,7 @@
 //=
 //= $RCSfile: srreadparam.cxx,v $
-//= $Revision: 1.5 $
+//= $Revision: 1.6 $
 //= $Author: moralejo $ 
-//= $Date: 2004-09-17 13:51:02 $
+//= $Date: 2004-10-12 13:41:09 $
 //=
 //=//////////////////////////////////////////////////////////////////////
@@ -75,10 +75,11 @@
 static float Simulated_Phe_p = 0.1;          //@< precision for phe loop
 static int   FADC_Shape=0;
-static float FADC_Integ=MFADC_RESPONSE_INTEGRAL;
-static float FADC_FWHM=MFADC_RESPONSE_FWHM;
-static int   Trig_Shape=0;
-static float Trig_Ampl=1.0;
-static float Trig_FWHM=2.0;
-static int   Write_Root=0;
+static float FADC_Integ = MFADC_RESPONSE_INTEGRAL;
+static float FADC_FWHM = MFADC_RESPONSE_FWHM;
+static float FADC_slices_per_ns = FADC_SLICES_PER_NSEC;
+static int   Trig_Shape = 0;
+static float Trig_Ampl = 1.0;
+static float Trig_FWHM = 2.0;
+static int   Write_Root = 0;
 //!@}
 
@@ -169,4 +170,10 @@
       break;
 
+    case fadc_GHz:  //  Get FADC sampling frequency in GHz
+
+      sscanf(line, "%s %f", token, &FADC_slices_per_ns);
+
+      break;
+
     case write_root:          //@< Write histogram
 
@@ -273,9 +280,10 @@
 //!@{
 void
-get_fadc_properties(int *shape, float *integ, float *fwhm)
+get_fadc_properties(int *shape, float *integ, float *fwhm, float *fadc_spns)
 {
   *shape =  FADC_Shape;
   *integ =  FADC_Integ;
-  *fwhm =  FADC_FWHM;
+  *fwhm  =  FADC_FWHM;
+  *fadc_spns = FADC_slices_per_ns;
 }
 //!@}
@@ -306,4 +314,9 @@
 //
 // $Log: not supported by cvs2svn $
+// Revision 1.5  2004/09/17 13:51:02  moralejo
+//
+// Adapted headers to current c++ style, removed -Wno-deprecated from
+// compilation options.
+//
 // Revision 1.4  2004/09/16 16:20:13  moralejo
 // *** empty log message ***
Index: trunk/MagicSoft/Simulation/Detector/StarResponse/srreadparam.h
===================================================================
--- trunk/MagicSoft/Simulation/Detector/StarResponse/srreadparam.h	(revision 5104)
+++ trunk/MagicSoft/Simulation/Detector/StarResponse/srreadparam.h	(revision 5248)
@@ -19,7 +19,7 @@
 //=
 //= $RCSfile: srreadparam.h,v $
-//= $Revision: 1.4 $
+//= $Revision: 1.5 $
 //= $Author: moralejo $ 
-//= $Date: 2004-09-17 13:51:02 $
+//= $Date: 2004-10-12 13:41:09 $
 //=
 //=//////////////////////////////////////////////////////////////////////
@@ -91,4 +91,5 @@
 T(trig_properties), /* shape for the single phe trigger response */  \
 T(fadc_properties), /* shape for the single phe fadc response */ \
+T(fadc_GHz),        /* FADC sampling frequency in GHz */ \
 T(write_root),      /* write root file with some histograms */ \
 T(end_file)         /* end of the parameters file */
@@ -128,5 +129,5 @@
 void get_simulated_phe(float *lphe, float *uphe, float *pphe);
 void get_trig_properties(int *shape, float *ampl, float *fwhm);
-void get_fadc_properties(int *shape, float *ampl, float *fwhm);
+void get_fadc_properties(int *shape, float *ampl, float *fwhm, float *slicesperns);
 int get_write_root();
 //!@}
@@ -145,4 +146,9 @@
 /*
  * $Log: not supported by cvs2svn $
+ * Revision 1.4  2004/09/17 13:51:02  moralejo
+ *
+ * Adapted headers to current c++ style, removed -Wno-deprecated from
+ * compilation options.
+ *
  * Revision 1.3  2004/09/16 16:20:13  moralejo
  * *** empty log message ***
Index: trunk/MagicSoft/Simulation/Detector/StarResponse/starresponse.cxx
===================================================================
--- trunk/MagicSoft/Simulation/Detector/StarResponse/starresponse.cxx	(revision 5104)
+++ trunk/MagicSoft/Simulation/Detector/StarResponse/starresponse.cxx	(revision 5248)
@@ -23,5 +23,6 @@
   TRandom2 Zufall( (UInt_t) brightness * 100)  ;      // a random generator
 
-  MStarLight  data  ;    // create  instance of the MStarLight 
+  MStarLight  data(fadc->GetFadcSlicesPerNanosec(), fadc->GetResponseSlicesFadc());
+  // create  instance of the MStarLight 
 
   //  Shall I write the root file???
@@ -31,39 +32,36 @@
   write_root= get_write_root();
   
+  Float_t   trigresp[RESPONSE_SLICES_TRIG];
+
   //  Get information from Trigger instance!!!
-   
-  cout << sizeof (trigger) << endl ; 
+  trigger->GetResponse(trigresp); 
+  data.SetTrigResponse(trigresp); 
+  
+  data.SetAmplTrig ( trigger->GetAmplitude() ); 
+  data.SetFwhmTrig ( trigger->GetFwhm() ); 
+  
+  Float_t  *fadcresp = new Float_t[fadc->GetResponseSlicesFadc()]; 
 
-  Float_t   trigresp[40] ; 
-  trigger->GetResponse ( trigresp ) ; 
-  data.SetTrigResponse( trigresp ) ; 
-  
-  data.SetAmplTrig ( trigger->GetAmplitude() ) ; 
-  data.SetFwhmTrig ( trigger->GetFwhm() ) ; 
-  
   //  Get information from FADC instance !!!!!
+  fadc->GetResponse(fadcresp); 
+  data.SetFadcResponse(fadcresp); 
 
-  Float_t   fadcresp[45] ; 
-  fadc->GetResponse (fadcresp ) ;   
-  data.SetFadcResponse( fadcresp ) ; 
-
-  data.SetShapeFadc ( fadc->GetShape() ) ; 
-  data.SetIntegFadc ( fadc->GetIntegral() ) ; 
-  data.SetFwhmFadc ( fadc->GetFwhm() ) ; 
+  data.SetShapeFadc ( fadc->GetShape() ); 
+  data.SetIntegFadc ( fadc->GetIntegral() ); 
+  data.SetFwhmFadc ( fadc->GetFwhm() ); 
  
   //  start with the loop over random events
   // 
   
-  Float_t a     = 0. ;   // the amplitude of the signal 
-  Float_t time  = 0. ;   // the time of the phe
+  Float_t a     = 0.;   // the amplitude of the signal 
+  Float_t time  = 0.;   // the time of the phe
 
-  for (Int_t i = 0 ; i< (Int_t ) (brightness * TIMERANGE) ; i++) {
-    
-    a = trigger->FillStar( 500, 10.) ;   // random the amplitude 
-    time=Zufall.Rndm() * TIMERANGE ;     // random the time
+  for (Int_t i = 0; i < (Int_t) (brightness * TIMERANGE) ; i++)
+    {
+      a = trigger->FillStar( 500, 10.) ;   // random the amplitude 
+      time=Zufall.Rndm() * TIMERANGE ;     // random the time
 
-    data.FillResponse(a, time ) ;        // fill the response function 
-    
-  }
+      data.FillResponse(a, time ) ;        // fill the response function     
+    }
 
   if(brightness<=1.0)
@@ -71,23 +69,22 @@
   else
     sprintf(filename, "%sBrightness%.1f.slt", path, brightness) ; 
-  data.WriteBinary( filename ) ;
 
-  data.Reset() ; 
+  data.WriteBinary( filename );
 
-  if(write_root){
-    data.ReadBinary( filename ) ;
-    
-    if(brightness<1.0)
-      sprintf(filename, "%sBrightness%.2f.root", path, brightness) ; 
-    else
-      sprintf(filename, "%sBrightness%.1f.root", path, brightness) ; 
-    sprintf(filename, "%sBrightness%.2f.root", path, brightness) ; 
-    cout << " the file will be written in " << filename
-	 << endl ; 
+  if(write_root)
+    {
+      if(brightness<=1.0)
+	sprintf(filename, "%sBrightness%.2f.root", path, brightness);
+      else
+	sprintf(filename, "%sBrightness%.1f.root", path, brightness);
 
-    data.StoreHisto( filename ) ; 
-  }
+      cout << " the file will be written in " << filename << endl;
 
-  return  (0) ; 
+      data.StoreHisto( filename );
+    }
+
+  data.Reset(); 
+
+  return(0); 
 
 }
@@ -112,5 +109,6 @@
   float trig_fwhm,trig_ampl;
   float fadc_fwhm,fadc_integral;
-  int fadc_shape, trig_shape;
+  float fadc_slices_per_ns;
+  Int_t fadc_shape, trig_shape;
 
   // 
@@ -120,6 +118,7 @@
 
   //  Instance of MFadc and MTrigger needed inside BuildStarLight
-  MTrigger *trigger;//= new MTrigger(1); 
-  MFadc *fadc;//= new MFadc;
+
+  MTrigger *trigger;
+  MFadc *fadc;
 
   if(argc == 1){
@@ -142,11 +141,23 @@
   trigger = new MTrigger(1,0.,0.,trig_ampl,trig_fwhm);
 
-  get_fadc_properties(&fadc_shape, &fadc_integral, &fadc_fwhm);
-  fadc = new MFadc(1,fadc_shape,fadc_integral,fadc_fwhm,fadc_shape,fadc_integral,fadc_fwhm);
+  get_fadc_properties(&fadc_shape, &fadc_integral, &fadc_fwhm, &fadc_slices_per_ns);
 
-  for (Float_t b=nphe_min; b<=nphe_max; b=b+nphe_pre )  //  loop over Brightness
-    {
-      BuildStarLight (b, path, trigger, fadc ) ;  
-    }
+  fadc = new MFadc(1, fadc_shape, fadc_integral, fadc_fwhm,
+		   fadc_shape, fadc_integral, fadc_fwhm, 0., fadc_slices_per_ns);
+
+  // loop over Brightness
+
+  // Limit precision (for speed reasons). Below 1 phe/ns/pixel we build the database
+  // files in steps of 0.01 (minimum). Above 1 phe/ns/pixel the steps are of 0.1 at least. 
+  // These values can be made larger through the input card of starresponse
+
+  nphe_pre = nphe_pre < 0.01? 0.01 : nphe_pre;
+  for (Float_t b = nphe_min; b <= 1.0; b += nphe_pre )
+    BuildStarLight (b, path, trigger, fadc);  
+
+  nphe_pre = nphe_pre < 0.1? 0.1 : nphe_pre;
+  for (Float_t b = 1.0+nphe_pre; b <= nphe_max; b += nphe_pre )
+    BuildStarLight (b, path, trigger, fadc);  
+
   delete(trigger);
   delete(fadc);
