Index: trunk/MagicSoft/Simulation/Detector/Camera/camera.cxx
===================================================================
--- trunk/MagicSoft/Simulation/Detector/Camera/camera.cxx	(revision 649)
+++ trunk/MagicSoft/Simulation/Detector/Camera/camera.cxx	(revision 671)
@@ -21,7 +21,7 @@
 //
 // $RCSfile: camera.cxx,v $
-// $Revision: 1.17 $
-// $Author: magicsol $ 
-// $Date: 2001-02-23 11:05:57 $
+// $Revision: 1.18 $
+// $Author: blanch $ 
+// $Date: 2001-03-05 10:36:52 $
 //
 ////////////////////////////////////////////////////////////////////////
@@ -209,4 +209,5 @@
 static int Write_McEvt  = TRUE;
 static int Write_McTrig = TRUE;
+static int Write_McFADC = TRUE;
 static int Write_RawEvt = FALSE;
 
@@ -234,4 +235,8 @@
 static float Trigger_response_fwhm = 2.0;
 static float Trigger_overlaping_time= 0.25;
+
+//@: Properties of the FADC
+static float FADC_response_ampl = MFADC_RESPONSE_AMPLITUDE;
+static float FADC_response_fwhm = MFADC_RESPONSE_FWHM;
 
 //@: Trigger conditions for a single trigger mode
@@ -422,7 +427,8 @@
 
   int simulateNSB;            //@< Will we simulate NSB?
+  int nphe2NSB;               //@< From how many ohe will we simulate NSB?
   float meanNSB;              //@< diffuse NSB mean value (phe per ns per central pixel)
-  float diffnsb_phepns[iMAXNUMPIX];  //@< diffuse NSB values for each pixel derived 
-                                     //@< from meanNSB
+  float diffnsb_phepns[iMAXNUMPIX];  //@< diffuse NSB values for each pixel  
+                                     //@< derived from meanNSB
   float nsbrate_phepns[iMAXNUMPIX][iNUMWAVEBANDS];    //@< non-diffuse nsb 
                                                      //@< photoelectron rates 
@@ -435,4 +441,6 @@
   Byte_t trigger_map[((Int_t)(TRIGGER_PIXELS/8))+1];//@< Pixels on when the
                                                     //@< camera triggers
+  Float_t fadc_elecnoise[CAMERA_PIXELS];  //@< Electronic niose for each pixel
+  UChar_t fadc_pedestals[CAMERA_PIXELS];  //@< array for fadc pedestals values
 
   float ext[iNUMWAVEBANDS] = { //@< average atmospheric extinction in each waveband
@@ -551,8 +559,11 @@
   Write_McEvt  = get_write_McEvt()  ; 
   Write_McTrig = get_write_McTrig() ; 
+  Write_McFADC = get_write_McFadc() ; 
   Write_RawEvt = get_write_RawEvt() ; 
 
   FADC_Scan = get_FADC_Scan();
   Trigger_Scan = get_Trigger_Scan();
+
+  get_FADC_properties( &FADC_response_ampl, &FADC_response_fwhm);
 
   get_Trigger_properties( &Trigger_gate_length, &Trigger_overlaping_time, &Trigger_response_ampl, &Trigger_response_fwhm);
@@ -583,5 +594,5 @@
   qThreshold = get_threshold();
   qTailCut = get_tail_cut();
-  simulateNSB = get_nsb( &meanNSB );
+  simulateNSB = get_nsb( &meanNSB, &nphe2NSB );
   countIslands = get_islands_cut( &nIslandsCut );
 
@@ -639,4 +650,5 @@
       "Write_McEvt",   ONoff(Write_McEvt),  
       "Write_McTrig",  ONoff(Write_McTrig),  
+      "Write_McFADC",  ONoff(Write_McFADC),  
       "Write_RawEvt",  ONoff(Write_RawEvt));
       
@@ -716,4 +728,5 @@
   MMcTrig **McTrig; 
   MMcTrigHeader **HeaderTrig; 
+  MMcFadcHeader **HeaderFadc;
 
   if (Write_McTrig){
@@ -732,5 +745,14 @@
   }
 
-  MFadc fadc ;                //@< A instance of the Class MFadc
+  if (Write_McFADC){
+
+    HeaderFadc = new MMcFadcHeader * [icontrigger];
+  
+    for (i=0;i<icontrigger;i++) {
+      HeaderFadc[i] = new MMcFadcHeader();
+    }
+  }
+
+  MFadc fadc(FADC_response_ampl,FADC_response_fwhm) ; //@< A instance of the Class MFadc
 
   // Set the FADC pedestals for that run
@@ -743,5 +765,5 @@
   // Prepare the raw data output
 
-       // Header file
+       // Header branch
 
   MRawEvtHeader **EvtHeader;
@@ -755,5 +777,5 @@
   }
 
-       // Header file
+       // Data branch
 
   MRawEvtData **EvtData;    // Data branch
@@ -801,5 +823,22 @@
   }  
 
-  //  Fill branches
+  if(!Trigger_Loop && Write_McFADC){
+    
+    HeaderTree.Branch("MMcFadcHeader","MMcFadcHeader", 
+		 &HeaderFadc[0], bsize, split);    
+  }
+  if (Trigger_Loop && Write_McFADC){
+    for(char branchname[20],i=0;i<icontrigger;i++){
+      
+      sprintf(help,"%i",i+1);
+      strcpy (branchname, "MMcFadcHeader");
+      strcat (branchname, & help[0]);
+      strcat (branchname, ".");
+      HeaderTree.Branch(branchname,"MMcFadcHeader", 
+		     &HeaderFadc[i], bsize, split);
+    }
+  }  
+
+  //  Fill branches for MMcTrigHeader
   
   if(!Trigger_Loop && Write_McTrig){
@@ -837,4 +876,35 @@
   }
 
+  //  Fill branches for MMcFadcHeader
+
+  for(i=0;i<CAMERA_PIXELS;i++){
+      fadc_elecnoise[i]=2.0;
+  }
+  fadc.GetPedestals(&fadc_pedestals[0]);
+
+  if(!Trigger_Loop && Write_McFADC){
+
+    HeaderFadc[0]->SetShape(0.0);
+    HeaderFadc[0]->SetAmplitud(FADC_response_ampl);
+    HeaderFadc[0]->SetFwhm(FADC_response_fwhm);
+    HeaderFadc[0]->SetPedestal(&fadc_pedestals[0],anaPixels);
+    HeaderFadc[0]->SetElecNoise(&fadc_elecnoise[0],anaPixels);
+  }
+  if(Trigger_Loop && Write_McTrig){
+
+    for (int iconcount=0,ithrescount=0;ithrescount<=Trigger_loop_uthres-Trigger_loop_lthres;ithrescount++){
+      for (imulticount=0;imulticount<=Trigger_loop_umult-Trigger_loop_lmult;imulticount++){
+	for(itopocount=0;itopocount<=Trigger_loop_utop-Trigger_loop_ltop;itopocount++){
+	  HeaderFadc[iconcount]->SetShape(0.0);
+	  HeaderFadc[iconcount]->SetAmplitud(Trigger_response_ampl);
+	  HeaderFadc[iconcount]->SetFwhm(Trigger_response_fwhm);
+	  HeaderFadc[iconcount]->SetPedestal(&fadc_pedestals[0],anaPixels);
+	  HeaderFadc[iconcount]->SetElecNoise(&fadc_elecnoise[0],anaPixels);
+	  iconcount++;
+	}
+      }   
+    }
+  }
+
   //  Fill the Header Tree with the current leaves of each branch
   HeaderTree.Fill() ;
@@ -973,5 +1043,4 @@
       for(j=0;j<iNUMWAVEBANDS;j++)
 	nsb_phepns[i]=nsb_phepns[i]+ nsbrate_phepns[i][j];
-      cout<<"Huschel "<<nsb_phepns[i]<<endl;
     }
   }
@@ -1165,22 +1234,4 @@
 	inumphe=0;
 
-	// NSB simulation
-
-	if(simulateNSB){
-
-	  //  Fill trigger and fadc response in the trigger class from teh database
-	  for(i=0;i<cam.inumpixels;i++)
-	    if(nsb_phepns[i]>0.0){
-	      k=lons.GetResponse(nsb_phepns[i],0.1,
-	      			 & nsb_trigresp[0],& nsb_fadcresp[0]);
-	      if(k==0){
-		cout << "Exiting.\n";
-		exit(1);
-	      }
- 	      Trigger.SetNSB(i,nsb_trigresp);
-	      fadc.Set(i,nsb_fadcresp);
-	    }
-	}// end if(simulateNSB) ...
-
 	// read the photons and produce the photoelectrons
 
@@ -1202,4 +1253,22 @@
 	  exit(1);
 	}
+
+	// NSB simulation
+
+	if(simulateNSB && nphe2NSB<=inumphe){
+
+	  //  Fill trigger and fadc response in the trigger class from the database
+	  for(i=0;i<cam.inumpixels;i++)
+	    if(nsb_phepns[i]>0.0){
+	      k=lons.GetResponse(nsb_phepns[i],0.1,
+	      			 & nsb_trigresp[0],& nsb_fadcresp[0]);
+	      if(k==0){
+		cout << "Exiting.\n";
+		exit(1);
+	      }
+ 	      Trigger.AddNSB(i,nsb_trigresp);
+	      fadc.AddSignal(i,nsb_fadcresp);
+	    }
+	}// end if(simulateNSB && nphe2NSB<=inumphe) ...
   
 	log(SIGNATURE, "End of this event: %d cphs(+%d). . .\n",
@@ -3146,4 +3215,8 @@
 //
 // $Log: not supported by cvs2svn $
+// Revision 1.17  2001/02/23 11:05:57  magicsol
+// Small changes due to slightly different output format and the introduction of
+// pedesals for teh FADC.
+//
 // Revision 1.16  2001/01/18 18:44:40  magicsol
 // *** empty log message ***
@@ -3172,4 +3245,8 @@
 //
 // $Log: not supported by cvs2svn $
+// Revision 1.17  2001/02/23 11:05:57  magicsol
+// Small changes due to slightly different output format and the introduction of
+// pedesals for teh FADC.
+//
 // Revision 1.16  2001/01/18 18:44:40  magicsol
 // *** empty log message ***
