Index: trunk/MagicSoft/Simulation/Detector/Camera/camera.cxx
===================================================================
--- trunk/MagicSoft/Simulation/Detector/Camera/camera.cxx	(revision 6566)
+++ trunk/MagicSoft/Simulation/Detector/Camera/camera.cxx	(revision 6567)
@@ -1206,5 +1206,15 @@
 
   RunHeader->SetMagicNumber(MRawRunHeader::kMagicNumber);
+
+  //
+  // We set as format version 5, the current real data version as of February 2005.
+  // These data have the peculiarity that the trigger pattern bits 
+  // (MRawEventHeader.fTrigPattern[0]) will be inverted (0 <-> 1) with respect 
+  // to the definitions in Mars/mtrigger/MTriggerPattern. We will account for this 
+  // below when setting the trigger pattern.
+  //
   RunHeader->SetFormatVersion(5);
+
+
   RunHeader->SetSoftVersion((UShort_t) (VERSION*10));
   RunHeader->SetRunType(256);
@@ -2085,5 +2095,5 @@
 	    }
 	  
-	  }// end if(simulateNSB && inumphe_CT[0] >= nphe2NSB) ...
+	  }// end if(simulateNSB && inumphe >= nphe2NSB) ...
 
 
@@ -2292,8 +2302,15 @@
 				    EvtHeader[iconcount]->
 				      FillHeader( (UInt_t) (ntshow + nshow),0);
+
+				    // Set trigger pattern. WARNING: the trigger pattern of real
+				    // data is inverted for the MRawRunHeader.fFormatVersion=5 
+				    // which is the one we now set in the camera outputs. Hence
+				    /// we use the binary inversion operator "~" below:
+
 				    EvtHeader[iconcount]->
-				      SetTriggerPattern((UInt_t)MTriggerPattern::kTriggerLvl1);
+				      SetTriggerPattern((UInt_t)~MTriggerPattern::kTriggerLvl1);
+
 				    //   fill pixel information
-				    if (Lev1 /*|| Write_All_Event_Headers AMTEST*/){
+				    if (Lev1){
 				      if (addElecNoise) Fadc_CT[0]->DigitalNoise();
 				      for(UInt_t i=0;
@@ -2564,5 +2581,11 @@
 		EvtHeader[ict]
 		  ->FillHeader ( (UInt_t) (ntshow + nshow) , 0 ) ; 
-		EvtHeader[ict]->SetTriggerPattern((UInt_t)MTriggerPattern::kTriggerLvl1);
+
+
+		// Set trigger pattern. WARNING: the trigger pattern of real
+		// data is inverted for the MRawRunHeader.fFormatVersion=5 
+		// which is the one we now set in the camera outputs. Hence
+		/// we use the binary inversion operator "~" below:
+		EvtHeader[ict]->SetTriggerPattern((UInt_t)~MTriggerPattern::kTriggerLvl1);
 
 		// Fill pixel information
@@ -4753,6 +4776,11 @@
 	  if (phot_per_pix > 1.e-3)
 	    {
-	      EvtHeader[ict]->SetTriggerPattern((UInt_t)(MTriggerPattern::kCalibration |
-	      MTriggerPattern::kTriggerLvl1));
+	      // Set trigger pattern. WARNING: the trigger pattern of real
+	      // data is inverted for the MRawRunHeader.fFormatVersion=5 
+	      // which is the one we now set in the camera outputs. Hence
+	      // we use the binary inversion operators "~" below. The Calibration
+	      // pattern, on the contrary, is not inverted.
+	      EvtHeader[ict]->SetTriggerPattern((UInt_t)(~(MTriggerPattern::kCalibration |
+	      MTriggerPattern::kTriggerLvl1)));
 	      //
 	      // FIXME! For now color and intensity of the pulser is fixed!
@@ -4760,5 +4788,5 @@
 	    }
 	  else  // 0 cal. photons per pixel ==> pedestal run
-	    EvtHeader[ict]->SetTriggerPattern((UInt_t)MTriggerPattern::kPedestal);
+	    EvtHeader[ict]->SetTriggerPattern((UInt_t)~MTriggerPattern::kPedestal);
 
 
@@ -5031,4 +5059,17 @@
 //
 // $Log: not supported by cvs2svn $
+// Revision 1.89  2005/02/17 09:15:28  moralejo
+//
+// Set as default option that of writing all event headers to output file,
+// not only those of the triggered events. To disable it, set the input card
+// flag "no_write_all_event_headers".
+//
+// Changed such that output images for events below the minimum number of
+// photoelectrons nphe2NSB required to simulate the noise (NSB & electronic)
+// will be empty. This will avoid the problem of these events being processed,
+// without any noise, later in the chain. Although those images are not in the
+// output, one can still check in the headers (MMcTrig) how many such events
+// with less than nphe2NSB photoelectrons would have triggered.
+//
 // Revision 1.88  2005/02/11 20:00:01  moralejo
 //
