Index: trunk/MagicSoft/Simulation/Detector/StarResponse/MStarLight.cxx
===================================================================
--- trunk/MagicSoft/Simulation/Detector/StarResponse/MStarLight.cxx	(revision 5247)
+++ 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 5247)
+++ 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 5247)
+++ 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 5247)
+++ 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 5247)
+++ 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);
Index: trunk/MagicSoft/Simulation/Detector/include-MFadc/MFadc.cxx
===================================================================
--- trunk/MagicSoft/Simulation/Detector/include-MFadc/MFadc.cxx	(revision 5247)
+++ trunk/MagicSoft/Simulation/Detector/include-MFadc/MFadc.cxx	(revision 5248)
@@ -20,5 +20,8 @@
 using namespace std;
 
-MFadc::MFadc(Int_t pix, Int_t shape, Float_t integral, Float_t fwhm, Int_t shapeout, Float_t integralout, Float_t fwhmout, Float_t trigger_delay) {
+MFadc::MFadc(Int_t pix, Int_t shape, Float_t integral, Float_t fwhm, 
+	     Int_t shapeout, Float_t integralout, Float_t fwhmout, 
+	     Float_t trigger_delay, Float_t fadc_slices_per_ns,
+	     Int_t fadc_slices_written) {
   //
   //  Constructor overloaded II 
@@ -45,9 +48,28 @@
   fwhm_resp_outer = fwhmout; 
   integ_resp_outer = integralout; 
-  shape_resp=shape;
-  shape_resp_outer=shapeout;
-
-    cout<< "[MFadc]  Setting up the MFadc with this values "<< endl ; 
-    cout<< "[MFadc]    - Inner pixels :  "<< endl ; 
+  shape_resp = shape;
+  shape_resp_outer = shapeout;
+  fFadcSlicesPerNanosec = fadc_slices_per_ns;
+  fFadcSlices = fadc_slices_written;
+
+  fSlices_mFadc = (Int_t)(TOTAL_TRIGGER_TIME*fFadcSlicesPerNanosec);
+
+  for (Int_t i = 0; i < CAMERA_PIXELS; i++)
+    sig[i] = new Float_t[fSlices_mFadc];
+
+  noise = new Float_t[fSlices_mFadc*1001];
+  noise_outer = new Float_t[fSlices_mFadc*1001];
+  digital_noise = new Float_t[fSlices_mFadc*1001];
+
+  for (Int_t i = 0; i < CAMERA_PIXELS; i++)
+    {
+      output[i] = new Float_t[fFadcSlices];
+      output_lowgain[i] = new Float_t[fFadcSlices];
+    }
+
+  cout<< "[MFadc]  Setting up the MFadc with this values "<< endl ; 
+  cout<< "[MFadc]  FADC sampling frequency: " << fFadcSlicesPerNanosec << " GHz" << endl ; 
+  cout<< "[MFadc]    - Inner pixels :  "<< endl ; 
+
   switch(shape_resp){
   case 0:
@@ -82,4 +104,21 @@
   //    set up the response shape
   // 
+
+  //
+  // First select number of bins for the histogram which will contain the single 
+  // photoelectron response of the FADC. The width of these bins is smaller than that 
+  // of the real FADC slices by a factor SUBBINS (see MFadcDefine.h):
+  //
+  if (shape_resp == 1)
+    fResponseSlicesFadc = (Int_t)(50.*fFadcSlicesPerNanosec*SUBBINS); 
+  // 50 ns range
+
+  else
+    fResponseSlicesFadc = (Int_t)(7*fwhm_resp/2.35*fFadcSlicesPerNanosec*SUBBINS); 
+  // 7 sigma range
+
+  sing_resp = new Float_t[fResponseSlicesFadc];
+  sing_resp_outer = new Float_t[fResponseSlicesFadc];
+
   Int_t  i ;
   
@@ -92,5 +131,5 @@
   response_sum_outer = 0.;
 
-  dX  = WIDTH_FADC_TIMESLICE / SUBBINS ;   // Units: ns
+  dX  = 1. / fFadcSlicesPerNanosec / SUBBINS ;   // Units: ns
   dX2 = dX/2. ; 
 
@@ -102,12 +141,12 @@
     fadc_time_offset = trigger_delay-x0; // ns
   
-    for (i=0; i< RESPONSE_SLICES_MFADC ; i++ ) {  
-
-      x = i * dX + dX2 ; 
+    for (i = 0; i < fResponseSlicesFadc ; i++ ) 
+      {  
+	x = i * dX + dX2 ; 
       
-      sing_resp[i] = expf(-0.5 * (x-x0)*(x-x0) / (sigma*sigma) ) ; 
-
-      response_sum_inner += sing_resp[i];
-    }
+	sing_resp[i] = (Float_t)(expf(-0.5*(x-x0)*(x-x0)/(sigma*sigma))); 
+
+	response_sum_inner += sing_resp[i];
+      }
 
     break;
@@ -121,5 +160,5 @@
     p1 = 2.066; 
     p2 = 1.568; 
-    p3 = 3; // This sets the peak of the pulse at x ~ 3 ADC slices
+    p3 = 3; // This will set the peak of the pulse at x ~ 3*3.3 = 10 ns
             // It is just a safe value so that the pulse is well contained.
     p4 = 0.00282; 
@@ -127,20 +166,34 @@
     p6 = 0.2411; 
     p7 = -0.009442;
-    // Define the time before trigger to read FADC signal when it
-    //  has to be written
-    fadc_time_offset = trigger_delay-p3*WIDTH_FADC_TIMESLICE; // ns
-
-    for (i=0; i< RESPONSE_SLICES_MFADC ; i++ ) {  
-      x = i * dX + dX2;
-
-      // x has to be converted from ns to units FADC slices:
-      zed_slices=x/WIDTH_FADC_TIMESLICE-p3;
-      d=(zed_slices>0)?0.5:-0.5;
-
-      sing_resp[i] =  (p1*exp(-p2*(exp(-p2*zed_slices)+zed_slices))+p4+
-		       p5*exp(-p2*(exp(-p2*zed_slices)+p6*zed_slices))+p7*d);
-
-      response_sum_inner += sing_resp[i];
-    }
+
+    // Now define the time before trigger to read FADC signal when it
+    // has to be written. Here FADC_SLICES_PER_NSEC (=0.3) is the value
+    // for the 300 MHz MAGIC FADCs and must NOT be changed, even if you
+    // use a faster sampling in the simulation (through the input card 
+    // command "fadc_GHz"), because this is just a conversion of units. The
+    // parameters of the "pulpo" pulse shape were obtained with the 300 MHz
+    // FADC and so we convert the time parameter to units of 3.3 ns slices 
+    // just to use the provided parametrization, and no matter what sampling 
+    // frequency we are simulating!
+
+    fadc_time_offset = trigger_delay - p3 / FADC_SLICES_PER_NSEC; // ns
+
+    for (i=0; i< fResponseSlicesFadc ; i++ )
+      {
+	x = i * dX + dX2;
+
+	// x has to be converted from ns to units FADC slices of the default 
+	// FADC of 300 MHz (these are just units, and must be these even if you
+	// are using another sampling frequency!):
+	//
+	zed_slices = x * FADC_SLICES_PER_NSEC - p3;
+	d=(zed_slices>0)?0.5:-0.5;
+
+	sing_resp[i] =  (Float_t) (p1*exp(-p2*(exp(-p2*zed_slices)+zed_slices))+
+				   p4+p5*exp(-p2*(exp(-p2*zed_slices)+
+						  p6*zed_slices))+p7*d);
+
+	response_sum_inner += sing_resp[i];
+      }
 
     break;
@@ -162,16 +215,17 @@
     fadc_time_offset = trigger_delay-x0; // ns
     
-    for (i=0; i< RESPONSE_SLICES_MFADC ; i++ ) {  
+    for (i = 0; i < fResponseSlicesFadc ; i++ ) 
+      {  
+	x = i * dX + dX2 ; 
       
-      x = i * dX + dX2 ; 
-      
-      //
-      //   the value 1/sqrt(2*Pi*sigma^2) was introduced to normalize 
-      //   the area at the input value After this, the integral
-      //   of the response will be integ_resp.
-      //
-      sing_resp_outer[i] = expf(-0.5 * (x-x0)*(x-x0) / (sigma*sigma) ) ; 
-      response_sum_outer += sing_resp_outer[i];
-    } 
+	//
+	//   the value 1/sqrt(2*Pi*sigma^2) was introduced to normalize 
+	//   the area at the input value After this, the integral
+	//   of the response will be integ_resp.
+	//
+	sing_resp_outer[i] = (Float_t) (expf(-0.5 * (x-x0)*(x-x0) / 
+					     (sigma*sigma)) ) ; 
+	response_sum_outer += sing_resp_outer[i];
+      } 
     break;
   case 1:
@@ -184,23 +238,39 @@
     p1 = 2.066; 
     p2 = 1.568; 
-    p3 = 3; // This sets the peak of the pulse at x ~ 3 ADC slices
-               // It is just a safe value so that the pulse is well contained.
+    p3 = 3; // This sets the peak of the pulse at x ~ 3*3.3 = 10 nanosec
+            // It is just a safe value so that the pulse is well contained.
     p4 = 0.00282; 
     p5 = 0.04093; 
     p6 = 0.2411; 
     p7 = -0.009442;
-    // Define the time before trigger to read FADC signal when it
-    //  has to be written
-    fadc_time_offset = trigger_delay-p3*WIDTH_FADC_TIMESLICE; // ns
-
-    for (i=0; i< RESPONSE_SLICES_MFADC ; i++ ) {  
-      x = i * dX + dX2;
-
-      zed_slices=x/WIDTH_FADC_TIMESLICE-p3;
-      d=(zed_slices>0)?0.5:-0.5;
-
-      sing_resp_outer[i] = (p1*exp(-p2*(exp(-p2*zed_slices)+zed_slices))+p4+
-			    p5*exp(-p2*(exp(-p2*zed_slices)+p6*zed_slices))+p7*d);
-      response_sum_outer += sing_resp_outer[i];
+
+    // Now define the time before trigger to read FADC signal when it
+    // has to be written. Here FADC_SLICES_PER_NSEC (=0.3) is the value
+    // for the 300 MHz MAGIC FADCs and must NOT be changed, even if you
+    // use a faster sampling in the simulation (through the input card 
+    // command "fadc_GHz"), because this is just a conversion of units. The
+    // parameters of the "pulpo" pulse shape were obtained with the 300 MHz
+    // FADC and so we convert the time parameter to units of 3.3 ns slices 
+    // just to use the provided parametrization, and no matter what sampling 
+    // frequency we are simulating!
+
+    fadc_time_offset = trigger_delay - p3 / FADC_SLICES_PER_NSEC; // ns
+
+    for (i=0; i< fResponseSlicesFadc ; i++ )
+      {
+	x = i * dX + dX2;
+
+	// x has to be converted from ns to units FADC slices of the default 
+	// FADC of 300 MHz (these are just units, and must be these even if you
+	// are using another sampling frequency!):
+	//
+	zed_slices = x * FADC_SLICES_PER_NSEC - p3;
+	d=(zed_slices>0)?0.5:-0.5;
+
+	sing_resp_outer[i] = (Float_t) (p1*exp(-p2*(exp(-p2*zed_slices)+
+						    zed_slices))+p4+
+					p5*exp(-p2*(exp(-p2*zed_slices)+
+						    p6*zed_slices))+p7*d);
+	response_sum_outer += sing_resp_outer[i];
       }
     break;
@@ -220,8 +290,9 @@
   //
 
-  for (i=0; i< RESPONSE_SLICES_MFADC ; i++ ) {  
+  for (i=0; i< fResponseSlicesFadc ; i++ )
+    {  
       sing_resp[i] *= integ_resp / response_sum_inner * SUBBINS;
       sing_resp_outer[i] *= integ_resp_outer / response_sum_outer * SUBBINS;
-  }
+    }
 
   //
@@ -250,10 +321,16 @@
     //
     memset(used, 0, CAMERA_PIXELS*sizeof(Bool_t));
-    memset(output, 0, CAMERA_PIXELS*FADC_SLICES*sizeof(Float_t));
-    memset(output_lowgain, 0, CAMERA_PIXELS*FADC_SLICES*sizeof(Float_t));
+
+    for (Int_t i = 0; i < CAMERA_PIXELS; i++)
+      {
+	memset(output[i], 0, fFadcSlices*sizeof(Float_t));
+	memset(output_lowgain[i], 0, fFadcSlices*sizeof(Float_t));
+      }
+
     // 
     // Added 15 01 2004, AM:
     //
-    memset(sig, 0, (Int_t)(CAMERA_PIXELS*SLICES_MFADC*sizeof(Float_t)));
+    for (Int_t i = 0; i < CAMERA_PIXELS; i++)
+      memset(sig[i], 0, (Int_t)(fSlices_mFadc*sizeof(Float_t)));
 }
 void MFadc::Fill( Int_t iPix, Float_t time, 
@@ -277,8 +354,12 @@
   // fills the information about one single Phe in the Trigger class
   //
-  // parameter is the number of the pixel and the time-difference to the
-  // first particle
-  //
-  //
+  // Parameters are the number of the pixel and the time-difference to the
+  // first photon.
+  //
+  //
+  // AM, Jan 2004: Replaced former FADC simulation (integration of signal)
+  // with a more realistic one (measuring signal height at discrete points).
+  //
+
 
   Int_t i, ichan, ichanfadc ; 
@@ -286,44 +367,43 @@
   //
   //   first we have to check if the pixel iPix is used or not until now
-  //   if this is the first use, reset all signal for that pixels
+  //   if this is the first use, reset all signal for that pixel
   // 
-  if ( iPix > numpix ) {
-    cout << " WARNING:  MFadc::Fill() :  iPix greater than Pixels in Camera = "
-	 << numpix
-	 << endl ;
-    exit(987) ; 
-  }
-
-  if ( used[iPix] == FALSE ) {
-    used [iPix] = TRUE ; 
+  if ( iPix > numpix ) 
+    {
+      cout << " WARNING: MFadc::Fill() : iPix greater than Pixels in Camera = "
+	   << numpix
+	   << endl;
+      exit(987); 
+    }
+
+  if ( used[iPix] == FALSE ) 
+    {
+      used [iPix] = TRUE; 
     
-    for (i=0; i < (Int_t) SLICES_MFADC; i++ ) {
-      sig[iPix][i] = 0. ; 
-    }
-  }
-
-  //
-  //   then select the time slice to use (ican) 
+      for (i=0; i < (Int_t) fSlices_mFadc; i++ ) 
+	sig[iPix][i] = 0.; 
+    }
+
+  //
+  //   then select the time slice to use (ichan) 
   // 
 
   if ( time < TOTAL_TRIGGER_TIME+fadc_time_offset ) { 
     //
-    //   determine the slices number assuming the WIDTH_RESPONSE_MFADC
-    //   ichan marks the start of the pulse, in number of bins of width  
-    //   WIDTH_RESPONSE_MFADC (2/3 of a ns), measured from the start of the 
-    //   FADC.
-    //
-
-    ichan = (Int_t) ( time / ((Float_t) WIDTH_RESPONSE_MFADC )); 
+    // Convert time into units of the width of the analog 
+    // signal histogram, sing_resp:
+    //
+    ichan = (Int_t) ( time * fFadcSlicesPerNanosec * SUBBINS); 
 
     //
     //   putting the response slices in the right sig slices.
-    //   Be carefull, because both slices have different widths. 
-    //
-
-    //
-    // AM, Jan 2004: Replaced former FADC simulation (integration of signal)
-    // with a more realistic one (measuring signal height at discrete points).
-    //
+    //   Be careful, because both slices have different widths. 
+    //
+
+    // We want to put the single phe response given by sing_resp into the
+    // array sig[][], but only one of each SUBBINS bins, since the binning 
+    // of sing_resp is finer than that of sig[][]. We want that the start of
+    // sing_resp coincides with the time "time" with respect to the begining
+    // of sig[][]
 
     // We take the pulse height in the middle of FADC slices, we start in the
@@ -332,26 +412,28 @@
 
     Int_t first_i =  Int_t(SUBBINS/2) - ichan%(Int_t)SUBBINS;
-    first_i = first_i < 0 ? (Int_t)SUBBINS+first_i : first_i;
-
-
-    for ( i = first_i ; i < (Int_t)RESPONSE_SLICES; i += (Int_t)SUBBINS) {	
-      ichanfadc = (Int_t) ((ichan+i)/SUBBINS) ; 
-      if ( ichanfadc < 0 )
+    first_i = first_i < 0 ? (Int_t)SUBBINS+first_i : first_i;    //
+    //
+    // first_i is the first bin of sing_resp which matches the center of one
+    // bin of sig[][]
+    //
+
+    for ( i = first_i ; i < (Int_t)fResponseSlicesFadc; i += (Int_t)SUBBINS)
+      {	
+	ichanfadc = (Int_t) ((ichan+i)/SUBBINS) ; 
+	if ( ichanfadc < 0 )
 	  continue;
 
-      //
-      // SLICES_MFADC is by default 48. sig[][] is not the true FADC, which
-      // is filled from sig[][] in MFadc::TriggeredFadc()
-      //
-      if ( (ichanfadc) < (Int_t)SLICES_MFADC ) {  
-	sig[iPix][ichanfadc] += (amplitude * sing_resp[i] )  ; 
-      } 
-    }
-
-  }
-  else {
+	//
+	// fSlices_mFadc is by default 48. sig[][] is not the true FADC, which
+	// is filled (from sig[][]) in MFadc::TriggeredFadc()
+	//
+	if ( (ichanfadc) < (Int_t) fSlices_mFadc )  
+	  sig[iPix][ichanfadc] += (amplitude * sing_resp[i] ); 
+      }
+
+  }
+  else
     cout << "  WARNING!  Fadc::Fill " << time << "  out of TriggerTimeRange " 
 	 << TOTAL_TRIGGER_TIME+fadc_time_offset << endl ; 
-  }
 
 }
@@ -363,68 +445,43 @@
   // for an outer pixel
   //
-  // parameter is the number of the pixel and the time-difference to the
-  // first particle
-  //
+  // See explanations of the code in function Fill() above 
   //
 
   Int_t i, ichan, ichanfadc ; 
   
-  //
-  //   first we have to check if the pixel iPix is used or not until now
-  //   if this is the first use, reset all signal for that pixels
-  // 
-  if ( iPix > numpix ) {
-    cout << " WARNING:  MFadc::FillOuter() :  iPix greater than CAMERA_PIXELS"
-	 << endl ;
-    exit(987) ; 
-  }
-
-  if ( used[iPix] == FALSE ) {
-    used [iPix] = TRUE ; 
+  if ( iPix > numpix ) 
+    {
+      cout << " WARNING: MFadc::FillOuter() : iPix greater than CAMERA_PIXELS"
+	   << endl ;
+      exit(987) ; 
+    }
+
+  if ( used[iPix] == FALSE ) 
+    {
+      used [iPix] = TRUE ; 
     
-    for (i=0; i < (Int_t) SLICES_MFADC; i++ ) {
-      sig[iPix][i] = 0. ; 
-    }
-  }
-
-  //
-  //   then select the time slice to use (ican) 
-  // 
+      for (i=0; i < (Int_t) fSlices_mFadc; i++)
+	sig[iPix][i] = 0.;
+    }
 
 
   if ( time < TOTAL_TRIGGER_TIME+fadc_time_offset ) { 
-    //
-    //   determine the slices number assuming the WIDTH_RESPONSE_MFADC
-    //
-    ichan = (Int_t) ( time / ((Float_t) WIDTH_RESPONSE_MFADC )); 
-
-    //
-    //   putting the response slices in the right sig slices.
-    //   Be carefull, because both slices have different widths. 
-    //
-
-    //
-    // AM, Jan 2004: Replaced former FADC simulation (integration of signal)
-    // with a more realistic one (measuring signal height at discrete points).
-    //
-
-    // We take the pulse height in the middle of FADC slices, we start in the
-    // first such point after the time "time" (=ichan in response bins). Each
-    // FADC slice corresponds to SUBBINS response bins (SUBBINS=5 by default).
+
+    ichan = (Int_t) ( time * fFadcSlicesPerNanosec * SUBBINS); 
 
     Int_t first_i =  Int_t(SUBBINS/2) - ichan%(Int_t)SUBBINS;
     first_i = first_i < 0 ? (Int_t)SUBBINS+first_i : first_i;
 
-    for ( i = first_i ; i < (Int_t)RESPONSE_SLICES; i += (Int_t)SUBBINS) {
-      ichanfadc = (Int_t) ((ichan+i)/SUBBINS) ; 
-
-      if ( ichanfadc < 0 )
+    for ( i = first_i ; i < (Int_t)fResponseSlicesFadc; i += (Int_t)SUBBINS)
+      {
+	ichanfadc = (Int_t) ((ichan+i)/SUBBINS); 
+
+	if ( ichanfadc < 0 )
 	  continue;
 
-      if ( (ichanfadc) < (Int_t)SLICES_MFADC ) {  
-	sig[iPix][ichanfadc] += (amplitude * sing_resp_outer[i] )  ; 
-      } 
-    }
-
+	if ( (ichanfadc) < (Int_t)fSlices_mFadc )
+	  sig[iPix][ichanfadc] += (amplitude * sing_resp_outer[i] ); 
+      }
+    
   }
   else {
@@ -432,8 +489,8 @@
 	 << TOTAL_TRIGGER_TIME+fadc_time_offset << endl ; 
   }
-
-}
-
-void MFadc::Set( Int_t iPix, Float_t resp[(Int_t) SLICES_MFADC]) { 
+  
+}
+
+void MFadc::Set( Int_t iPix, Float_t *resp) { 
   
   //
@@ -459,9 +516,9 @@
     used [iPix] = TRUE ; 
     
-    for (i=0; i < (Int_t)SLICES_MFADC; i++ ) {
+    for (i=0; i < (Int_t)fSlices_mFadc; i++ ) {
       sig[iPix][i] = 0. ; 
     }
   }
-  for ( i = 0 ; i<(Int_t)SLICES_MFADC; i++ ) {
+  for ( i = 0 ; i<(Int_t)fSlices_mFadc; i++ ) {
     sig[iPix][i] = resp[i] ; 
   }
@@ -469,5 +526,5 @@
 }
 
-void MFadc::AddSignal( Int_t iPix, Float_t resp[(Int_t) SLICES_MFADC]) { 
+void MFadc::AddSignal( Int_t iPix, Float_t *resp) { 
   
   //
@@ -493,9 +550,9 @@
     used [iPix] = TRUE ; 
     
-    for (i=0; i < (Int_t)SLICES_MFADC; i++ ) {
+    for (i=0; i < (Int_t)fSlices_mFadc; i++ ) {
       sig[iPix][i] = 0. ; 
     }
   }
-  for ( i = 0 ; i<(Int_t)SLICES_MFADC; i++ ) {
+  for ( i = 0 ; i<(Int_t)fSlices_mFadc; i++ ) {
     sig[iPix][i] += resp[i] ; 
   }
@@ -534,9 +591,9 @@
   for(j=0;j<numpix;j++){
     baseline=0.0;
-    for(i=0;i<(Int_t) SLICES_MFADC;i++){
+    for(i=0;i<(Int_t) fSlices_mFadc;i++){
       baseline+=sig[j][i];
     }
-    baseline=baseline/SLICES_MFADC;
-    for(i=0;i<(Int_t) SLICES_MFADC;i++){
+    baseline=baseline/fSlices_mFadc;
+    for(i=0;i<(Int_t) fSlices_mFadc;i++){
       sig[j][i]=-baseline;
     }
@@ -554,5 +611,5 @@
 
   for(i=0;i<numpix;i++)
-    for(j=0;j<(Int_t)SLICES_MFADC;j++)
+    for(j=0;j<(Int_t)fSlices_mFadc;j++)
         sig[i][j]+=pedestal[i];
   //
@@ -562,6 +619,4 @@
   // to do it for all pixels.
   //
-
-
 }
 
@@ -585,5 +640,5 @@
 	if (used[i]){
 	  fdum=(10*GenOff->Rndm());
-	  for(j=0;j<(Int_t) SLICES_MFADC;j++)
+	  for(j=0;j<(Int_t) fSlices_mFadc;j++)
 	    sig[i][j]+=fdum;
 	}
@@ -594,5 +649,5 @@
       if (used[pixel]){
 	fdum=(10*GenOff->Rndm());
-	for(j=0;j<(Int_t) SLICES_MFADC;j++)
+	for(j=0;j<(Int_t) fSlices_mFadc;j++)
 	  sig[pixel][j]+=fdum;
 	}
@@ -607,5 +662,5 @@
       for(i=0;i<numpix;i++){
 	if (used[i]){
-	  for(j=0;j<(Int_t) SLICES_MFADC;j++)
+	  for(j=0;j<(Int_t) fSlices_mFadc;j++)
 	    sig[i][j]+=offset;
 	}
@@ -615,5 +670,5 @@
 
       if (used[pixel]){
-	for(j=0;j<(Int_t) SLICES_MFADC;j++)
+	for(j=0;j<(Int_t) fSlices_mFadc;j++)
 	  sig[pixel][j]+=offset;
       }
@@ -632,5 +687,5 @@
       <<endl;
 
-  for (i=0;i<(UInt_t (SLICES_MFADC))*1001;i++){
+  for (i=0;i<(UInt_t (fSlices_mFadc))*1001;i++){
     noise[i]=GenElec->Gaus(0., value1 );
     noise_outer[i]=GenElec->Gaus(0., value2 );
@@ -656,5 +711,5 @@
     //
 
-    startslice=GenElec->Integer(((Int_t)SLICES_MFADC)*1000);
+    startslice=GenElec->Integer(((Int_t)fSlices_mFadc)*1000);
 
     if ( used[i] == FALSE )
@@ -664,9 +719,9 @@
 	    memcpy( (Float_t*)&sig[i][0],
 		    (Float_t*)&noise[startslice], 
-		    ((Int_t) SLICES_MFADC)*sizeof(Float_t));
+		    ((Int_t) fSlices_mFadc)*sizeof(Float_t));
 	else
 	    memcpy( (Float_t*)&sig[i][0],
 		    (Float_t*)&noise_outer[startslice], 
-		    ((Int_t) SLICES_MFADC)*sizeof(Float_t));
+		    ((Int_t) fSlices_mFadc)*sizeof(Float_t));
     }
 
@@ -677,8 +732,8 @@
     {
 	if (i < fInnerPixelsNum)
-	    for ( Int_t is=0 ; is< (Int_t)SLICES_MFADC ; is++ ) 
+	    for ( Int_t is=0 ; is< (Int_t)fSlices_mFadc ; is++ ) 
 		sig[i][is] += noise[startslice+is];
 	else
-	    for ( Int_t is=0 ; is< (Int_t)SLICES_MFADC ; is++ ) 
+	    for ( Int_t is=0 ; is< (Int_t)fSlices_mFadc ; is++ ) 
 		sig[i][is] += noise_outer[startslice+is];
     }
@@ -694,5 +749,5 @@
       <<endl;
 
-  for (i=0;i<UInt_t(SLICES_MFADC*1001);i++){
+  for (i=0;i<UInt_t(fSlices_mFadc*1001);i++){
     xrdm=GenElec->Gaus(0., value);
     digital_noise[i]=(xrdm>0?Int_t(xrdm+0.5):Int_t(xrdm-0.5));    
@@ -717,12 +772,12 @@
 	continue;
 
-      startslice=GenElec->Integer((Int_t) SLICES_MFADC*999);
+      startslice=GenElec->Integer((Int_t) fSlices_mFadc*999);
       //      
       //  Then the noise is introduced for each time slice
       //
-      for ( Int_t is=0 ; is< FADC_SLICES; is++ ) 
+      for ( Int_t is = 0 ; is < fFadcSlices; is++ ) 
 	{ 
 	  output[i][is] += digital_noise[startslice+is];
-	  output_lowgain[i][is] += digital_noise[startslice+FADC_SLICES+is];
+	  output_lowgain[i][is] += digital_noise[startslice+fFadcSlices+is];
 	}
     }
@@ -738,5 +793,5 @@
       printf ("Pid %3d",  ip ) ; 
 
-      for ( Int_t is=0 ; is < (Int_t)SLICES_MFADC; is++ ) {
+      for ( Int_t is=0 ; is < (Int_t)fSlices_mFadc; is++ ) {
 
 	if ( sig[ip][is] > 0. ) {
@@ -776,5 +831,5 @@
   Int_t  iFirstSlice ; 
 
-  iFirstSlice = (Int_t) ( t /  WIDTH_FADC_TIMESLICE ) ; 
+  iFirstSlice = (Int_t) ( t * fFadcSlicesPerNanosec ) ; 
 
   for ( Int_t ip=0; ip<numpix; ip++ ) {
@@ -799,8 +854,7 @@
   //    puts the standard response function into the array resp
   
-  for ( Int_t i=0; i< RESPONSE_SLICES; i++ ) {
-
-    resp[i] = sing_resp[i] ; 
-  }
+  for ( Int_t i=0; i< fResponseSlicesFadc; i++ )
+    resp[i] = sing_resp[i];
+
 }
 
@@ -841,5 +895,5 @@
   // Get at random a point in the FADC presimulated digital noise:
   //
-  startslice=GenElec->Integer((Int_t) SLICES_MFADC*999);
+  startslice=GenElec->Integer((Int_t) fSlices_mFadc*999);
 
   for ( Int_t is=0; is < n_slices ; is++ ) 
@@ -875,8 +929,7 @@
   // We had 0.5 for the correct rounding:
   //
-  iFirstSlice = (Int_t) ( 0.5 + time /  WIDTH_FADC_TIMESLICE ) ; 
-
-
-  for ( Int_t ip=0; ip<numpix; ip++ )
+  iFirstSlice = (Int_t) ( 0.5 + time * fFadcSlicesPerNanosec ) ; 
+
+  for ( Int_t ip = 0; ip < numpix; ip++ )
     {
 
@@ -887,5 +940,5 @@
 	// it anyway!
 	{
-	  for ( Int_t i=0 ; i < FADC_SLICES ; i++ ) 
+	  for ( Int_t i=0 ; i < fFadcSlices ; i++ ) 
 	    {
 	      output[ip][i]= pedestal[ip];
@@ -896,7 +949,7 @@
 
       i=0;
-      for ( Int_t is=iFirstSlice ; is < (iFirstSlice+FADC_SLICES) ; is++ ) 
+      for ( Int_t is = iFirstSlice; is < (iFirstSlice+fFadcSlices); is++ ) 
 	{
-	  if (is < (Int_t)SLICES_MFADC)
+	  if (is < (Int_t)fSlices_mFadc)
 	    {
 	      output[ip][i] = sig[ip][is];
@@ -948,12 +1001,12 @@
       sprintf (name, "fadc signal %d", i ) ; 
       
-      hist = new TH1F(dumm, name, (Int_t)SLICES_MFADC, fadc_time_offset, TOTAL_TRIGGER_TIME+fadc_time_offset); 
+      hist = new TH1F(dumm, name, (Int_t)fSlices_mFadc, fadc_time_offset, TOTAL_TRIGGER_TIME+fadc_time_offset); 
       //
       //  fill the histogram
       //
       
-      for (Int_t ibin=1; ibin <=(Int_t)SLICES_MFADC; ibin++) {
-	hist->SetBinContent (ibin, sig[i][ibin-1]) ;
-      }
+      for (Int_t ibin = 1; ibin <= (Int_t)fSlices_mFadc; ibin++)
+	hist->SetBinContent (ibin, sig[i][ibin-1]);
+
 
       //      hist->SetMaximum( 5.);
Index: trunk/MagicSoft/Simulation/Detector/include-MFadc/MFadc.hxx
===================================================================
--- trunk/MagicSoft/Simulation/Detector/include-MFadc/MFadc.hxx	(revision 5247)
+++ trunk/MagicSoft/Simulation/Detector/include-MFadc/MFadc.hxx	(revision 5248)
@@ -56,36 +56,56 @@
   Float_t  pedestal[CAMERA_PIXELS] ;  //  Pedestal of FADCs
 
-  Float_t  sig[CAMERA_PIXELS][(Int_t) SLICES_MFADC] ; //  the analog signal for pixels, in bins of width
-                                                      //  equal to the FADC slice: 50/15 ns, but with a
-                                                      //  total of SLICES_MFADC (=48 now) bins.
-  Float_t noise[((Int_t) SLICES_MFADC)*1001];
-  Float_t noise_outer[((Int_t) SLICES_MFADC)*1001];
-  Int_t digital_noise[((Int_t) SLICES_MFADC)*1001];
-
-  Float_t  output[CAMERA_PIXELS][FADC_SLICES];  //  the analog signal for pixels that is read after a trigger 
-                                                //  occurs (high gain). Only 15 (=FADC_SLICES) bins
-
-  Float_t  output_lowgain[CAMERA_PIXELS][FADC_SLICES]; //  analog signal, low gain.
+  Int_t    fSlices_mFadc;  // Number of simulated FADC slices. Larger than the actual number of slices
+                           // that will be written, since we have to account for possible delays in the 
+                           // trigger
+
+  Int_t fResponseSlicesFadc;
+
+  //
+  //  Float_t sig[CAMERA_PIXELS][] ; 
+  //  the analog signal for pixels, in bins of width
+  //  equal to the FADC slice: (default 50/15 ns), but with a
+  //  total of fSlices_mFadc bins (default 48).
+  //
+  Float_t *sig[CAMERA_PIXELS];
+
+  Float_t *noise;
+  Float_t *noise_outer;
+  Float_t *digital_noise;
+
+  Float_t  *output[CAMERA_PIXELS];  //  the analog signal for pixels that is read after a trigger 
+                                    //  occurs (high gain).
+
+  Float_t  *output_lowgain[CAMERA_PIXELS]; //  analog signal, low gain.
 
   Float_t high2low_gain;
+
   //
   //    first the data for the response function
   //
-  Int_t shape_resp ;                      // index shape of the phe_response function
-                                          // = 0 --> Gaussian
-                                          // = 1 --> Pulpo set-up
-  Float_t fwhm_resp ;                      // fwhm of the phe_response function (in ns)
-  Float_t integ_resp ;                      // area below curve of the phe_response function (in counts * ns)
-  Float_t sing_resp[ RESPONSE_SLICES_MFADC ] ;   // the shape of the phe_response function 
+  Int_t shape_resp;      // index shape of the phe_response function
+                         // = 0 --> Gaussian
+                         // = 1 --> Pulpo set-up
+  Float_t fwhm_resp;     // fwhm of the phe_response function (in ns)
+  Float_t integ_resp;    // area below curve of the phe_response function (in counts * ns)
+  Float_t *sing_resp;    // the shape of the phe_response function 
+
+  Float_t fFadcSlicesPerNanosec; // Number of FADC slices per nanosecond, that is, the
+                                 // sampling frequency of the FADC.
+
+  Int_t fFadcSlices;     // Number of FADC slices that will be written on the output 
+                         // file (same number for high and low gain)
 
   //
   //    We may end up with a different reponse for the outer pixels
   //
-  Int_t shape_resp_outer ;                      // index shape of the phe_response function
-                                          // = 0 --> Gaussian
-                                          // = 1 --> Pulpo set-up
-  Float_t fwhm_resp_outer ;                      // fwhm of the phe_response function (in ns)
-  Float_t integ_resp_outer ;                      // area below curve of the phe_response function (in counts * ns)
-  Float_t sing_resp_outer[ RESPONSE_SLICES_MFADC ] ;   // the shape of the phe_response function 
+  Int_t shape_resp_outer ;  // index shape of the phe_response function
+                            // = 0 --> Gaussian
+                            // = 1 --> Pulpo set-up
+  Float_t fwhm_resp_outer ; // fwhm of the phe_response function (in ns)
+  Float_t integ_resp_outer; // area below curve of the phe_response function (in counts * ns)
+  Float_t *sing_resp_outer; // the shape of the phe_response function 
+
+
   //
   //   RandomGenerator for the Electonic Noise
@@ -98,15 +118,16 @@
                             // in the trigger pixels.
 
-
 public:
 
-  MFadc(Int_t pix=577,
-	Int_t shape=0,
-	Float_t ampl=MFADC_RESPONSE_INTEGRAL, 
-	Float_t fwhm=MFADC_RESPONSE_FWHM,
-	Int_t shapeout=0,
-	Float_t amplout=MFADC_RESPONSE_INTEGRAL, 
-	Float_t fwhmout=MFADC_RESPONSE_FWHM,
-	Float_t trig_delay=0.) ;
+  MFadc(Int_t pix = 577,
+	Int_t shape = 0,
+	Float_t ampl = MFADC_RESPONSE_INTEGRAL, 
+	Float_t fwhm = MFADC_RESPONSE_FWHM,
+	Int_t shapeout = 0,
+	Float_t amplout = MFADC_RESPONSE_INTEGRAL, 
+	Float_t fwhmout = MFADC_RESPONSE_FWHM,
+	Float_t trig_delay = 0.,
+	Float_t fadc_slices_per_ns = FADC_SLICES_PER_NSEC,
+	Int_t   fadc_slices_written = FADC_SLICES);
   
   void SetSeed(UInt_t seed)  {GenElec->SetSeed(seed);}
@@ -120,7 +141,6 @@
   void FillOuter( Int_t, Float_t, Float_t  ) ;  
 
-  void Set( Int_t iPix, Float_t res[(Int_t) SLICES_MFADC]);
-
-  void AddSignal( Int_t iPix, Float_t res[(Int_t) SLICES_MFADC]);
+  void Set( Int_t iPix, Float_t *res);
+  void AddSignal( Int_t iPix, Float_t *res);
 
   void SetPedestals( Int_t ped);
@@ -185,5 +205,5 @@
   void SetHigh2LowGain(Float_t h2l) {high2low_gain=h2l;}
 
-  Float_t GetShape() {
+  Int_t GetShape() {
     return shape_resp;
   }
@@ -205,4 +225,12 @@
   }
 
+  Float_t GetFadcSlicesPerNanosec() {
+    return fFadcSlicesPerNanosec;
+  }
+
+  Int_t GetResponseSlicesFadc() {
+    return fResponseSlicesFadc;
+  }
+
   Bool_t IsPixelUsed(UInt_t p){
     return used[p];
Index: trunk/MagicSoft/Simulation/Detector/include-MLons/MLons.cxx
===================================================================
--- trunk/MagicSoft/Simulation/Detector/include-MLons/MLons.cxx	(revision 5247)
+++ trunk/MagicSoft/Simulation/Detector/include-MLons/MLons.cxx	(revision 5248)
@@ -3,5 +3,6 @@
 using namespace std;
 
-MLons::MLons(){
+MLons::MLons()
+{
   //-----------------------------------------------------------------
   //
@@ -9,19 +10,22 @@
   //
 
-  fTrigShape = 0.0;
+  fTrigShape = 0;
   fAmplTrig = 1.0;  
   fFwhmTrig = 2.0;
-
-  fFadcShape = 0.0;
+  fFadcSlicesPerNanosec = FADC_SLICES_PER_NSEC;
+
+  fFadcShape = 0;
   fIntegFadc = 1.0;
   fFwhmFadc = 2.0;
 
-  RandomNumber = new TRandom() ;
+  RandomNumber = new TRandom();
   RandomNumber -> SetSeed(0);
 
 }
 
-MLons::MLons(Float_t in_shapeT, Float_t in_amplT, Float_t in_FwhmT, 
-	     Float_t in_shapeF, Float_t in_integF, Float_t in_FwhmF){
+MLons::MLons(Int_t in_shapeT, Float_t in_amplT, Float_t in_FwhmT, 
+	     Int_t in_shapeF, Float_t in_integF, Float_t in_FwhmF,
+	     Float_t in_Fadc_Slices_per_ns)
+{
   //--------------------------------------------------------------------
   //
@@ -37,9 +41,14 @@
   fFwhmFadc = in_FwhmF;
 
+  fFadcSlicesPerNanosec = in_Fadc_Slices_per_ns;
+
+  MSLStored = new MStarLight;
+
   RandomNumber = new TRandom() ; 
   RandomNumber -> SetSeed(0);
 }
 
-void MLons::Reset() {
+void MLons::Reset() 
+{
   //-----------------------------------------------------------------
   //
@@ -47,13 +56,13 @@
   //
 
-  fTrigShape   = 0. ; 
-  fAmplTrig    = 0. ; 
-  fFwhmTrig    = 0. ; 
-
-  fFadcShape   = 0. ; 
-  fIntegFadc    = 0. ; 
-  fFwhmFadc    = 0. ; 
-
-  MSLStored.Reset();
+  fTrigShape   = 0; 
+  fAmplTrig    = 0.; 
+  fFwhmTrig    = 0.; 
+
+  fFadcShape   = 0; 
+  fIntegFadc   = 0.; 
+  fFwhmFadc    = 0.; 
+
+  MSLStored->Reset();
 
 }
@@ -110,11 +119,11 @@
 }
 
-void MLons::ReadBinaryMStarLight(char *filename){
-
-  MSLStored.ReadBinary(filename); 
-
-}
-
-Int_t MLons::CheckTrig(){
+void MLons::ReadBinaryMStarLight(char *filename)
+{
+  MSLStored->ReadBinary(filename); 
+}
+
+Int_t MLons::CheckTrig()
+{
   //--------------------------------------------------------------------
   //
@@ -122,12 +131,18 @@
   //
 
-  if (  fAmplTrig == MSLStored.GetAmplTrig() && 
-	fFwhmTrig == MSLStored.GetFwhmTrig())
+  if (  fAmplTrig == MSLStored->GetAmplTrig() && 
+	fFwhmTrig == MSLStored->GetFwhmTrig())
     return 1;
 
+  cout << "1 phe- pulse amplitudes for trigger (mV): " << fAmplTrig << "    "
+       << MSLStored->GetAmplTrig() << endl;
+  cout << "1 phe- pulse FWHM for trigger (ns):       " << fFwhmTrig << "    "
+       << MSLStored->GetFwhmTrig() << endl;
+
   return 0;
 }
 
-Int_t MLons::CheckFADC(){
+Int_t MLons::CheckFADC()
+{
   //--------------------------------------------------------------------
   //
@@ -135,14 +150,25 @@
   //
 
-  if (  fIntegFadc == MSLStored.GetIntegFadc() && 
-	fFwhmFadc == MSLStored.GetFwhmFadc() && 
-	fFadcShape == MSLStored.GetShapeFadc())
+  if (  fIntegFadc == MSLStored->GetIntegFadc() && 
+	fFwhmFadc == MSLStored->GetFwhmFadc() && 
+	fFadcShape == MSLStored->GetShapeFadc() &&
+	fFadcSlicesPerNanosec == MSLStored->GetFadcSlicesPerNanosec() )
     return 1;
 
+  cout << "1 phe- FADC pulse shape :             " << fFadcShape << "    " 
+       << MSLStored->GetShapeFadc() <<  endl;
+  cout << "1 phe- FADC pulse integral (counts) : " << fIntegFadc << "    " 
+       << MSLStored->GetIntegFadc() << endl;
+  cout << "1 phe- FADC pulse FWHM (ns) :         " << fFwhmFadc  << "    " 
+       << MSLStored->GetFwhmFadc() <<  endl;
+  cout << "FADC sampling frequencies (GHz) :     " << fFadcSlicesPerNanosec << "    "
+       << MSLStored->GetFadcSlicesPerNanosec() << endl;
+
   return 0;
 }
 
 Int_t MLons::GetResponse(Float_t in_br, Float_t in_pre,
-			 Float_t *out_tr, Float_t *out_Fr){
+			 Float_t *out_tr, Float_t *out_Fr)
+{
   //-------------------------------------------------------------------------
   //
@@ -154,89 +180,102 @@
   Char_t cstoredbright[10];
 
-  Int_t i;
   Int_t bin;
-  Float_t start_bin;
-  Float_t time;
-
+  Float_t start_time;
+
+
+  //
   // The following code line commented means that the simulation will crash if
   // some pixel ask for more lons than what we have in the database.
   // The following code line uncommented would mean that the simulation does
-  //  not crash if a pixel ask for more than it is simulated but would 
-  // assign to it lees lons.
-  if (in_br>49.9) in_br=49.9;  //  To avoid error for high required brightness
-                                 //  It has to be improved
+  // not crash if a pixel ask for more than it is simulated but would 
+  // assign to it less lons.
+  // I think this is unnecessary now. AM 5/10/2004
+  //  if (in_br>49.9) in_br=49.9;    //  To avoid error for high required brightness
+  //                                 //  It has to be improved
+  //
+
 
   //  Check if the the brightness is the same than the last time.
-  //  NOTE: Same means, the smae inside the required precision!!!
-
-  if(in_br<1.0){
+  //  NOTE: Same means, the same inside the required precision!!!
+
+  if(in_br<=1.0){
     sprintf(cbright,"%4.2f",in_br);
-    sprintf(cstoredbright,"%4.2f",MSLStored.GetBrightness());
+    sprintf(cstoredbright,"%4.2f",MSLStored->GetBrightness());
   }
   else{
     sprintf(cbright,"%3.1f",in_br);
-    sprintf(cstoredbright,"%3.1f",MSLStored.GetBrightness());
+    sprintf(cstoredbright,"%3.1f",MSLStored->GetBrightness());
   }
-  if (strcmp(cbright, cstoredbright)){
-    
-    // Building the filename
-    // Note: it would be nice to get an algorithm that gets the name of 
-    // files it needs to get brightness as a function of precison(in_pre),
-    // brightnes (in_br) and the Star_files that are in the "Path" directory.
-
-    strcpy(filename_slt, & path[0]);
-    strcat(filename_slt, "Brightness");
-    strcat(filename_slt, & cbright[0]);
+
+  if (strcmp(cbright, cstoredbright))
+    {
+      // Building the filename
+      // Note: it would be nice to get an algorithm that gets the name of 
+      // files it needs to get brightness as a function of precison(in_pre),
+      // brightnes (in_br) and the Star_files that are in the "Path" directory.
+
+      strcpy(filename_slt, & path[0]);
+      strcat(filename_slt, "Brightness");
+      strcat(filename_slt, & cbright[0]);
   
-    strcat(filename_slt, ".slt");
+      strcat(filename_slt, ".slt");
  
-    // If brightness is different it check if the new file has the
-    // required parameters.
-    // Note: I could be faster to store the whole trigger and fadc
-    // response and use it while brightness does not change. Then the
-    // root file should be open and close here.
-
-    ReadBinaryMStarLight( & filename_slt[0]);
-
-    if (!(CheckTrig() && CheckFADC())) {
-      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; 
-      return 0;
+      // If brightness is different it check if the new file has the
+      // required parameters.
+      // Note: I could be faster to store the whole trigger and fadc
+      // response and use it while brightness does not change. Then the
+      // root file should be open and close here.
+
+      MSLStored->ReadBinary(filename_slt); 
+
+      if (!(CheckTrig() && CheckFADC()))
+	{
+	  cout << "ERROR: The Database for light from Night Sky Background is wrong"<<endl;
+	  cout << "       Make sure that you generated the database with the same shape" << endl;
+	  cout << "       for Fadc and trigger that you are asking now."<<endl; 
+	  return 0;
+	}
+      MSLStored->SetBrightness(in_br);
+
     }
-    MSLStored.SetBrightness(in_br);
-
- }
 
   // Random number that decides the set of bins that the program will get
-  start_bin=RandomNumber->Uniform(1.0e4);
+  start_time = RandomNumber->Uniform(TIMERANGE);
 
   //  Filling trigger response
 
-  bin=(Int_t)(start_bin*4);
-
-  for (i=0;i<TRIGGER_TIME_SLICES;i++){
-
-    time=((float)i)/SLICES_PER_NSEC;
-    
-    if (time>(bin-start_bin*4.0)/4.0) bin++;
-
-    if (bin>=TRIGBINS) bin=bin-TRIGBINS;
-
-    out_tr[i]=MSLStored.GetTrig(bin);
-  }
+  bin = (Int_t)(start_time*TRIG_SLICES_PER_NSEC);
+
+
+  if (bin+TRIGGER_TIME_SLICES > MSLStored->GetBinsTrig())
+    {
+      memcpy (out_tr, MSLStored->GetTrigPointer(bin), 
+	      (UInt_t) (MSLStored->GetBinsTrig()-bin)*sizeof(Float_t));
+      memcpy (out_tr, MSLStored->GetTrigPointer(0),
+	      (UInt_t) (bin+TRIGGER_TIME_SLICES-MSLStored->GetBinsTrig())*sizeof(Float_t));
+    }
+  else
+    memcpy (out_tr, MSLStored->GetTrigPointer(bin), 
+	    (UInt_t) TRIGGER_TIME_SLICES*sizeof(Float_t));
+
 
   //  Filling fadc response
 
-  bin=(Int_t) (start_bin*0.3);
-
-  for (i=0;i<(Int_t) SLICES_MFADC;i++){
-
-    time=((float)i)*WIDTH_FADC_TIMESLICE;
-    
-    if (time>(bin-start_bin*0.3)/0.3) bin++;
-
-    if (bin>=FADCBINS) bin=bin-FADCBINS;
-
-    out_Fr[i]=MSLStored.GetFadc(bin);
-  }
+  // Start bin in the NSB database:
+  bin = (Int_t) (start_time*MSLStored->GetBinsFadc()/MSLStored->GetTimeRange()); 
+
+  // If we go over the end of the database, continue at the begining of it: 
+  if (bin + (Int_t)(TOTAL_TRIGGER_TIME*fFadcSlicesPerNanosec) > MSLStored->GetBinsFadc())
+    {
+      memcpy (out_Fr, MSLStored->GetFadcPointer(bin), 
+	      (Int_t)(MSLStored->GetBinsFadc()-bin)*sizeof(Float_t));
+
+      memcpy (out_Fr, MSLStored->GetFadcPointer(0),
+	      (Int_t)(bin + TOTAL_TRIGGER_TIME*fFadcSlicesPerNanosec - 
+		       MSLStored->GetBinsFadc())*sizeof(Float_t));
+    }
+  else
+    memcpy (out_Fr, MSLStored->GetFadcPointer(bin), 
+	    (Int_t)(TOTAL_TRIGGER_TIME*fFadcSlicesPerNanosec*sizeof(Float_t)));
 
   return 1;
Index: trunk/MagicSoft/Simulation/Detector/include-MLons/MLons.hxx
===================================================================
--- trunk/MagicSoft/Simulation/Detector/include-MLons/MLons.hxx	(revision 5247)
+++ trunk/MagicSoft/Simulation/Detector/include-MLons/MLons.hxx	(revision 5248)
@@ -33,26 +33,29 @@
 //
 
-class MLons {
+class MLons
+{
 
 private:
 
-  Char_t   path[256]    ;   // Location of StarLight files
+  Char_t   path[256];     // Location of StarLight files
 
-  MStarLight MSLStored  ;   // MStarLight in memmory
+  MStarLight *MSLStored;  // MStarLight in memory
 
-  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  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  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    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
 
-  TRandom  *RandomNumber;   // RandomGenerator 
+  Float_t  fFadcSlicesPerNanosec; // The sampling frequency (GHz) of the FADC
+
+  TRandom  *RandomNumber; // RandomGenerator 
 
 public:
@@ -60,6 +63,7 @@
   MLons() ;
 
-  MLons(Float_t in_shapeT, Float_t in_amplT, Float_t in_FwhmT,
-	Float_t in_shapeF, Float_t in_integF, Float_t in_FwhmF) ;
+  MLons(Int_t in_shapeT, Float_t in_amplT, Float_t in_FwhmT,
+	Int_t in_shapeF, Float_t in_integF, Float_t in_FwhmF,
+	Float_t in_Fadc_Slices_per_ns);
 
   void Reset() ;
@@ -78,4 +82,5 @@
   Float_t GetIntegFadc() ; 
   Float_t GetFwhmFadc() ; 
+  Float_t GetFadcSlicesPerNanosec() {return fFadcSlicesPerNanosec;}
 
   void GetPath(Char_t *out);
Index: trunk/MagicSoft/Simulation/Detector/include-MTrigger/MTrigger.cxx
===================================================================
--- trunk/MagicSoft/Simulation/Detector/include-MTrigger/MTrigger.cxx	(revision 5247)
+++ trunk/MagicSoft/Simulation/Detector/include-MTrigger/MTrigger.cxx	(revision 5248)
@@ -206,10 +206,10 @@
   x0 = 3*sigma ; 
   
-  for (i=0; i< RESPONSE_SLICES ; i++ ) {  
-
-    x = i * (1./((Float_t)SLICES_PER_NSEC)) 
-      + (1./( 2 * (Float_t)SLICES_PER_NSEC ))  ; 
+  for (i=0; i< RESPONSE_SLICES_TRIG ; i++ ) {  
+
+    x = i * (1./((Float_t)TRIG_SLICES_PER_NSEC)) 
+      + (1./( 2 * (Float_t)TRIG_SLICES_PER_NSEC ))  ; 
     
-    sing_resp[i] = 
+    sing_resp[i] = (Float_t)
       ampl_resp * expf(-0.5 * (x-x0)*(x-x0) / (sigma*sigma) ) ; 
   
@@ -224,5 +224,5 @@
   Int_t imax  = 0  ;
   Float_t max = 0. ; 
-  for (i=0; i< RESPONSE_SLICES ; i++ ) {  
+  for (i=0; i< RESPONSE_SLICES_TRIG ; i++ ) {  
     if ( sing_resp[i] > max ) {
       imax = i ; 
@@ -231,5 +231,5 @@
   }
  
-  peak_time = ( (Float_t) imax )  / ( (Float_t) SLICES_PER_NSEC ) ;
+  peak_time = ( (Float_t) imax )  / ( (Float_t) TRIG_SLICES_PER_NSEC ) ;
  
 
@@ -357,6 +357,6 @@
   
   for ( i = 0 ; i < 5 ; i++) {
-    SlicesFirst[i]  = -50 ; 
-    SlicesSecond[i] = -50 ;
+    SlicesFirst[i]  = 0; 
+    SlicesSecond[i] = 0;
     PixelsFirst[i]  = -1;
     PixelsSecond[i] = -1;
@@ -454,10 +454,10 @@
   x0 = 3*sigma ; 
   
-  for (i=0; i< RESPONSE_SLICES ; i++ ) {  
-
-    x = i * (1./((Float_t)SLICES_PER_NSEC)) 
-      + (1./( 2 * (Float_t)SLICES_PER_NSEC ))  ; 
+  for (i=0; i< RESPONSE_SLICES_TRIG ; i++ ) {  
+
+    x = i * (1./((Float_t)TRIG_SLICES_PER_NSEC)) 
+      + (1./( 2 * (Float_t)TRIG_SLICES_PER_NSEC ))  ; 
     
-    sing_resp[i] = 
+    sing_resp[i] = (Float_t)
       ampl_resp * expf(-0.5 * (x-x0)*(x-x0) / (sigma*sigma) ) ; 
   
@@ -472,5 +472,5 @@
   Int_t imax  = 0  ;
   Float_t max = 0. ; 
-  for (i=0; i< RESPONSE_SLICES ; i++ ) {  
+  for (i=0; i< RESPONSE_SLICES_TRIG ; i++ ) {  
     if ( sing_resp[i] > max ) {
       imax = i ; 
@@ -479,5 +479,5 @@
   }
  
-  peak_time = ( (Float_t) imax )  / ( (Float_t) SLICES_PER_NSEC ) ;
+  peak_time = ( (Float_t) imax )  / ( (Float_t) TRIG_SLICES_PER_NSEC ) ;
  
   //
@@ -588,6 +588,6 @@
   
   for ( i = 0 ; i < 5 ; i++) {
-    SlicesFirst[i]  = -50 ; 
-    SlicesSecond[i] = -50 ;
+    SlicesFirst[i]  = 0 ; 
+    SlicesSecond[i] = 0 ;
     PixelsFirst[i]  = -1;
     PixelsSecond[i] = -1;
@@ -683,10 +683,10 @@
   x0 = 3*sigma ; 
   
-  for (i=0; i< RESPONSE_SLICES ; i++ ) {  
-
-    x = i * (1./((Float_t)SLICES_PER_NSEC)) 
-      + (1./( 2 * (Float_t)SLICES_PER_NSEC ))  ; 
+  for (i=0; i< RESPONSE_SLICES_TRIG ; i++ ) {  
+
+    x = i * (1./((Float_t)TRIG_SLICES_PER_NSEC)) 
+      + (1./( 2 * (Float_t)TRIG_SLICES_PER_NSEC ))  ; 
     
-    sing_resp[i] = 
+    sing_resp[i] = (Float_t)
       ampl_resp * expf(-0.5 * (x-x0)*(x-x0) / (sigma*sigma) ) ; 
   
@@ -701,5 +701,5 @@
   Int_t imax  = 0  ;
   Float_t max = 0. ; 
-  for (i=0; i< RESPONSE_SLICES ; i++ ) {  
+  for (i=0; i< RESPONSE_SLICES_TRIG ; i++ ) {  
     if ( sing_resp[i] > max ) {
       imax = i ; 
@@ -708,5 +708,5 @@
   }
  
-  peak_time = ( (Float_t) imax )  / ( (Float_t) SLICES_PER_NSEC ) ;
+  peak_time = ( (Float_t) imax )  / ( (Float_t) TRIG_SLICES_PER_NSEC ) ;
  
   //
@@ -772,6 +772,6 @@
   
   for ( i = 0 ; i < 5 ; i++) {
-    SlicesFirst[i]  = -50 ; 
-    SlicesSecond[i] = -50 ;
+    SlicesFirst[i]  = 0 ; 
+    SlicesSecond[i] = 0 ;
     PixelsFirst[i]  = -1;
     PixelsSecond[i] = -1;
@@ -843,5 +843,5 @@
   
   for ( i = 0 ; i < 5 ; i++) {
-    SlicesFirst[i]  = -50 ; 
+    SlicesFirst[i]  = 0 ; 
     PixelsFirst[i]  = -1;
   }
@@ -872,5 +872,5 @@
   //
   //     Fills the information of one single Phe electron that 
-  //     comes from the shower 
+  //     comes from the NSB
   //
 
@@ -892,6 +892,5 @@
   //
   //     Fills the information of one single Phe electron that 
-  //     comes from the shower 
-  //
+  //     comes from a star
 
   //
@@ -969,5 +968,5 @@
     //
 
-    Int_t ichan = (Int_t) ( time * ((Float_t) SLICES_PER_NSEC) ) ; 
+    Int_t ichan = (Int_t) ( time * ((Float_t) TRIG_SLICES_PER_NSEC) ) ; 
 
     //
@@ -975,5 +974,5 @@
     //
 
-    for ( i = 0 ; i<RESPONSE_SLICES; i++ ) {
+    for ( i = 0 ; i<RESPONSE_SLICES_TRIG; i++ ) {
       
       if ( (ichan+i) >= 0  &&  
@@ -1132,10 +1131,10 @@
   x0 = 3*sigma ; 
   
-  for (i=0; i< RESPONSE_SLICES ; i++ ) {  
-
-    x = i * (1./((Float_t)SLICES_PER_NSEC)) 
-      + (1./( 2 * (Float_t)SLICES_PER_NSEC ))  ; 
+  for (i=0; i< RESPONSE_SLICES_TRIG ; i++ ) {  
+
+    x = i * (1./((Float_t)TRIG_SLICES_PER_NSEC)) 
+      + (1./( 2 * (Float_t)TRIG_SLICES_PER_NSEC ))  ; 
     
-    sing_resp[i] = 
+    sing_resp[i] = (Float_t)
       ampl_resp * expf(-0.5 * (x-x0)*(x-x0) / (sigma*sigma) ) ; 
   
@@ -1244,5 +1243,5 @@
   //    puts the standard response function into the array resp
 
-  for ( Int_t i=0; i< RESPONSE_SLICES; i++ ) {
+  for ( Int_t i=0; i< RESPONSE_SLICES_TRIG; i++ ) {
 
     resp[i] = sing_resp[i] ; 
@@ -1288,5 +1287,5 @@
 
 
-  Int_t  jmax = (Int_t) (gate_leng * SLICES_PER_NSEC )  ; 
+  Int_t  jmax = (Int_t) (gate_leng * TRIG_SLICES_PER_NSEC )  ; 
 
   //
@@ -1572,6 +1571,6 @@
       if (SlicesZero[iSli]){
 	//
-	//  Loop over trigger cells. It is topology analisy,
-	//  therefore it is keep here after multiplicity and 
+	//  Loop over trigger cells. It is topology analysis,
+	//  therefore it is kept here after multiplicity and 
 	//  threshold checks.
 	//
@@ -1645,5 +1644,5 @@
 		  SlicesFirst[nFirst++] = iSli ; // We save time when it triggers
 		  iReturn++ ;
-		  iSli+=(50*SLICES_PER_NSEC);  // We skip the following 50 ns (dead time)
+		  iSli+=(LEVEL1_DEAD_TIME*TRIG_SLICES_PER_NSEC);  // We skip the following 50 ns (dead time)
 		  iCell=TRIGGER_CELLS;         // We skip the remaining trigger cells 
 		  break ; 
@@ -1675,5 +1674,5 @@
 		  SlicesFirst[nFirst++] = iSli ; //  We save when it triggers
 		  iReturn++ ;
-		  iSli+=(50*SLICES_PER_NSEC);  // We skip the following 50 ns (dead time)
+		  iSli+=(LEVEL1_DEAD_TIME*TRIG_SLICES_PER_NSEC);  // We skip the following 50 ns (dead time)
 		  iCell=TRIGGER_CELLS;         // We skip the remaining trigger cells 
 		  break ; 
@@ -1768,5 +1767,5 @@
 		    SlicesFirst[nFirst++] = iSli ; //  We save time when it triggers
 		    iReturn++ ;
-		    iSli+=(50*SLICES_PER_NSEC);  // We skip the following 50 ns (dead time)
+		    iSli+=(LEVEL1_DEAD_TIME*TRIG_SLICES_PER_NSEC);  // We skip the following 50 ns (dead time)
 		    iCell=TRIGGER_CELLS;         // We skip the remaining trigger cells 
 		    break ; 
@@ -1863,5 +1862,5 @@
   //  It gives the time for the il trigger at first level
 
-  return((Float_t) ((Float_t) SlicesFirst[il]/((Float_t) SLICES_PER_NSEC)));
+  return((Float_t) ((Float_t) SlicesFirst[il]/((Float_t) TRIG_SLICES_PER_NSEC)));
 }
 
@@ -1885,5 +1884,5 @@
 
   // Translation from ns to slices
-  iNumSli=(int) (overlaping_time*SLICES_PER_NSEC);
+  iNumSli=(int) (overlaping_time*TRIG_SLICES_PER_NSEC);
   if (iNumSli<1) iNumSli=1;
 
@@ -1901,5 +1900,2 @@
 
 }
-
-
-
Index: trunk/MagicSoft/Simulation/Detector/include-MTrigger/MTrigger.hxx
===================================================================
--- trunk/MagicSoft/Simulation/Detector/include-MTrigger/MTrigger.hxx	(revision 5247)
+++ trunk/MagicSoft/Simulation/Detector/include-MTrigger/MTrigger.hxx	(revision 5248)
@@ -109,8 +109,9 @@
   //    first the data for the response function
   //
-  Float_t fwhm_resp ;                      // fwhm of the phe_response function 
-  Float_t ampl_resp ;                      // amplitude of the phe_response function (in mV)
-  Float_t sing_resp[ RESPONSE_SLICES ] ;   // the shape of the phe_response function 
-  Float_t peak_time  ;                      // the time from the start of the response function to the maximum peak 
+  Float_t fwhm_resp ;                       // fwhm of the phe_response function 
+  Float_t ampl_resp ;                       // amplitude of the phe_response function (in mV)
+  Float_t sing_resp[RESPONSE_SLICES_TRIG] ; // the shape of the phe_response function 
+  Float_t peak_time  ;                      // the time from the start of the response 
+                                            // function to the maximum peak 
 
   TH1F     *histPmt ; 
