Index: trunk/MagicSoft/Simulation/Detector/include-MFadc/MFadc.cxx
===================================================================
--- trunk/MagicSoft/Simulation/Detector/include-MFadc/MFadc.cxx	(revision 2338)
+++ trunk/MagicSoft/Simulation/Detector/include-MFadc/MFadc.cxx	(revision 2339)
@@ -18,5 +18,5 @@
 #include "MGFadcSignal.hxx"
 
-MFadc::MFadc(Float_t ampl, Float_t fwhm, Float_t amplout, Float_t fwhmout) {
+MFadc::MFadc(Int_t pix, Float_t ampl, Float_t fwhm, Float_t amplout, Float_t fwhmout) {
   //
   //  Constructor overloaded II 
@@ -31,4 +31,5 @@
   //     this parameters of the trigger may be changed
   //  3. Then the all signals are set to zero
+  numpix=pix;
   
   fwhm_resp = fwhm; 
@@ -136,5 +137,5 @@
   //   if this is the first use, reset all signal for that pixels
   // 
-  if ( iPix > CAMERA_PIXELS ) {
+  if ( iPix > numpix ) {
     cout << " WARNING:  MFadc::Fill() :  iPix greater than CAMERA_PIXELS"
 	 << endl ;
@@ -201,5 +202,5 @@
   //   if this is the first use, reset all signal for that pixels
   // 
-  if ( iPix > CAMERA_PIXELS ) {
+  if ( iPix > numpix ) {
     cout << " WARNING:  MFadc::FillOuter() :  iPix greater than CAMERA_PIXELS"
 	 << endl ;
@@ -264,5 +265,5 @@
   //   if this is the first use, reset all signal for that pixels
   // 
-  if ( iPix > CAMERA_PIXELS ) {
+  if ( iPix > numpix ) {
     cout << " WARNING:  MFadc::Fill() :  iPix greater than CAMERA_PIXELS"
 	 << endl ;
@@ -298,5 +299,5 @@
   //   if this is the first use, reset all signal for that pixels
   // 
-  if ( iPix > CAMERA_PIXELS ) {
+  if ( iPix > numpix ) {
     cout << " WARNING:  MFadc::Fill() :  iPix greater than CAMERA_PIXELS"
 	 << endl ;
@@ -323,15 +324,15 @@
   Int_t i;
 
-  for(i=0;i<CAMERA_PIXELS;i++){
+  for(i=0;i<numpix;i++){
     pedestal[i]= (Float_t)(ped* GenElec->Rndm());
   }
 }
 
-void MFadc::SetPedestals(  Float_t ped[CAMERA_PIXELS]) { 
+void MFadc::SetPedestals(  Float_t *ped) { 
   //  It sets pedestal for each pixel from ped array
 
   Int_t i;
 
-  for(i=0;i<CAMERA_PIXELS;i++){
+  for(i=0;i<numpix;i++){
     pedestal[i]= ped[i];
   }
@@ -346,5 +347,5 @@
   Float_t baseline;
 
-  for(j=0;j<CAMERA_PIXELS;j++){
+  for(j=0;j<numpix;j++){
     baseline=0.0;
     for(i=0;i<(Int_t) SLICES_MFADC;i++){
@@ -367,5 +368,5 @@
   Int_t i, j;
 
-  for(i=0;i<CAMERA_PIXELS;i++)
+  for(i=0;i<numpix;i++)
     for(j=0;j<(Int_t)SLICES_MFADC;j++)
       sig[i][j]+=pedestal[i];
@@ -388,5 +389,5 @@
       // It does not exist, so all pixels will have the same offset
 
-      for(i=0;i<CAMERA_PIXELS;i++){
+      for(i=0;i<numpix;i++){
 	if (used[i]){
 	  fdum=(10*GenOff->Rndm());
@@ -411,5 +412,5 @@
       // It does not exist, so all pixels will have the same offset
 
-      for(i=0;i<CAMERA_PIXELS;i++){
+      for(i=0;i<numpix;i++){
 	if (used[i]){
 	  for(j=0;j<(Int_t) SLICES_MFADC;j++)
@@ -433,8 +434,8 @@
   UInt_t i;
  
-  cout<<"MFadc::SetElecNoise ... generating database for electroni noise."
+  cout<<"MFadc::SetElecNoise ... generating database for electronic noise."
       <<endl;
 
-  for (i=0;i<CAMERA_PIXELS*(Int_t) SLICES_MFADC*101;i++){
+  for (i=0;i<UInt_t(SLICES_MFADC*1001);i++){
     noise[i]=GenElec->Gaus(0., value  );
       }
@@ -452,18 +453,19 @@
   UInt_t startslice;
 
-  startslice=GenElec->Integer(CAMERA_PIXELS*(Int_t) SLICES_MFADC*100);
-
-    for ( Int_t i = 0 ; i < CAMERA_PIXELS; i++) {
+    for ( Int_t i = 0 ; i < numpix; i++) {
 	//
 	//  but at the beginning we must check if this pixel is
 	//  hitted the first time
 	//
+
+      startslice=GenElec->Integer((Int_t) SLICES_MFADC*1000);
+
 	if ( used[i] == FALSE ) {
 	    used [i] = TRUE ; 
 	    
-	    memcpy( (Float_t*)&sig[0][0],
-		    (Float_t*)&noise[startslice+i*(Int_t) SLICES_MFADC], 
+      	    memcpy( (Float_t*)&sig[i][0],
+		    (Float_t*)&noise[startslice], 
 		    (Int_t) SLICES_MFADC*sizeof(Float_t));
-    
+      
 	}
 	//      
@@ -473,8 +475,7 @@
 	  for ( Int_t is=0 ; is< (Int_t)SLICES_MFADC ; is++ ) {
 	    
-	    sig[i][is] += noise[startslice+i*(Int_t) SLICES_MFADC+is] ; 
+	    sig[i][is] += noise[startslice+is] ; 
 	    
 	  }
-	
     }
 }
@@ -485,5 +486,5 @@
   
 
-  for ( Int_t ip=0; ip<CAMERA_PIXELS; ip++ ) {
+  for ( Int_t ip=0; ip<numpix; ip++ ) {
     
     if ( used[ip] == kTRUE ) {
@@ -531,5 +532,5 @@
   iFirstSlice = (Int_t) ( t /  WIDTH_FADC_TIMESLICE ) ; 
 
-  for ( Int_t ip=0; ip<CAMERA_PIXELS; ip++ ) {
+  for ( Int_t ip=0; ip<numpix; ip++ ) {
     
     if ( used[ip] == kTRUE ) {
@@ -563,5 +564,5 @@
   //    puts the pedestal values into the array offset
   
-  for ( Int_t i=0; i< CAMERA_PIXELS; i++ ) {
+  for ( Int_t i=0; i< numpix; i++ ) {
 
     offset[i] = pedestal[i] ; 
@@ -593,5 +594,5 @@
   iFirstSlice = (Int_t) ( t /  WIDTH_FADC_TIMESLICE ) ; 
 
-  for ( Int_t ip=0; ip<CAMERA_PIXELS; ip++ ) {
+  for ( Int_t ip=0; ip<numpix; ip++ ) {
     
     if ( used[ip] == kTRUE ) { 
@@ -600,14 +601,21 @@
 	if (is< (Int_t)SLICES_MFADC && sig[ip][is]>0.0)
 	  {
-	  output[ip][i++]=(sig[ip][is] > 255. ? 255 :(UChar_t) (sig[ip][is]+0.5));
-	  output_lowgain[ip][i++]= 
-	    (Int_t)(pedestal[ip]+(sig[ip][is]-pedestal[ip])/HIGH2LOWGAIN) > 255. ? 255 :
-	    (UChar_t)(pedestal[ip]+(sig[ip][is]-pedestal[ip])/HIGH2LOWGAIN);
-	  
+	    output[ip][i]=(sig[ip][is] > 255. ? 255 :(UChar_t) (sig[ip][is]+0.5));
+	    output_lowgain[ip][i]= 
+	      (Int_t)(pedestal[ip]+(sig[ip][is]-pedestal[ip])/HIGH2LOWGAIN) > 255. ? 255 :
+	      (UChar_t)(pedestal[ip]+(sig[ip][is]-pedestal[ip])/HIGH2LOWGAIN);
+	    i++;
+	  }
+	else if(sig[ip][is]>0.0)
+	  {
+ 	    output[ip][i]= (UChar_t)(pedestal[ip]+0.5);
+ 	    output_lowgain[ip][i]= (UChar_t)(pedestal[ip]+0.5);
+	    i++;
 	  }
 	else 
  	  {
  	    output[ip][i]= 0;
- 	    output_lowgain[ip][i++]= 0;
+ 	    output_lowgain[ip][i]= 0;
+	    i++;
  	  }
       }
@@ -643,5 +651,5 @@
   
   Int_t ic = 0 ; 
-  for ( Int_t i=0 ; i < CAMERA_PIXELS; i++  ) {
+  for ( Int_t i=0 ; i < numpix; i++  ) {
     if ( used [i] == TRUE ) {
 
@@ -706,5 +714,2 @@
    return (output_lowgain[pixel][slice]);
 }
-
-
-
