Index: /trunk/MagicSoft/Mars/NEWS
===================================================================
--- /trunk/MagicSoft/Mars/NEWS	(revision 3122)
+++ /trunk/MagicSoft/Mars/NEWS	(revision 3123)
@@ -1,4 +1,7 @@
                                                                -*-*- END -*-*-
  *** Version <cvs>
+
+   - added filter against cosmics: MFCosmics: 
+     To be used together with MContinue
 
    - added new class MArrivalTimeCalc2:
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationCalc.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationCalc.cc	(revision 3122)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationCalc.cc	(revision 3123)
@@ -115,7 +115,7 @@
 const UInt_t MCalibrationCalc::fPINDiodeId   = 9999;
 const Byte_t MCalibrationCalc::fgSaturationLimit = 254;
-const Byte_t MCalibrationCalc::fgBlindPixelFirst = 10;
-const Byte_t MCalibrationCalc::fgBlindPixelLast  = 20;
-const Int_t  MCalibrationCalc::fgBlindPixelSinglePheCut = 200;
+const Int_t  MCalibrationCalc::fgBlindPixelFirst = 10;
+const Int_t  MCalibrationCalc::fgBlindPixelLast  = 20;
+const Int_t  MCalibrationCalc::fgBlindPixelSinglePheCut = 400;
 
 // --------------------------------------------------------------------------
@@ -155,4 +155,7 @@
     fBlindPixelLast    = 0;
 
+    fNumBlindPixelSinglePhe = 0;
+    fNumBlindPixelPedestal  = 0;  
+
     fNumHiGainSamples  = 0;
     fNumLoGainSamples  = 0;
@@ -163,9 +166,10 @@
 }
 
-void MCalibrationCalc::SetBlindPixelRange(Byte_t first, Byte_t last)
+void MCalibrationCalc::SetBlindPixelRange(Int_t first, Int_t last)
 {
   
   fBlindPixelFirst = first;
   fBlindPixelLast  = last;
+
 }
 
@@ -396,10 +400,9 @@
   
   //
-  // Create a (second) loop to do fill the calibration histograms
+  // Create a loop to fill the calibration histograms
   // Search for: a signal in MExtractedSignalCam 
   // Fill histograms with:
   //             charge
   //             charge vs. event nr.
-  //             relative arrival time w.r.t. pixel 1
   //
   while (pixel.Next())
@@ -466,14 +469,16 @@
               // We need a dedicated signal extractor for the blind pixel
               //
-              Int_t diff = 0;
-
-              if (fBlindPixelLast > 15)
+              Int_t diff  = 0;
+              Int_t last  = fBlindPixelLast;
+              Int_t first = fBlindPixelFirst;
+
+              if (last > 15)
                 {
-                  diff = fBlindPixelLast - 15;
-                  fBlindPixelLast = 15;
+                  diff = last - 15;
+                  last = 15;
                 }
 
-              Byte_t *start   = ptr   + fBlindPixelFirst - 1;
-              Byte_t *end     = start + fBlindPixelLast - fBlindPixelFirst + 1;
+              Byte_t *start   = ptr + first - 1;
+              Byte_t *end     = ptr + last  - 1;
 
               ptr = start;
@@ -481,5 +486,5 @@
               Int_t sum = 0;
               
-              while (ptr<end)
+              while (ptr<=end)
                 {
                   sum += *ptr;
@@ -490,8 +495,7 @@
                 {
                   ptr = pixel.GetLoGainSamples();
+                  end = ptr + diff - 1;
                   
-                  end     = ptr + diff + 1;
-                  
-                  while (ptr<end)
+                  while (ptr<=end)
                     {
                       sum += *ptr;
@@ -531,11 +535,18 @@
 
               if (blindpixelsumhi > fBlindPixelSinglePheCut)
-                hist = (blindpixel.GetHist())->GetHSinglePheFADCSlices();
+                {
+                  hist = (blindpixel.GetHist())->GetHSinglePheFADCSlices();
+                  fNumBlindPixelSinglePhe++;
+                }
               else
-                hist = (blindpixel.GetHist())->GetHPedestalFADCSlices();
-
+                {
+                  hist = (blindpixel.GetHist())->GetHPedestalFADCSlices();
+                  fNumBlindPixelPedestal++;
+                }
+              
               ptr = pixel.GetHiGainSamples();
               for (Int_t i=1;i<16;i++)
                 hist->Fill(i,*ptr++);
+
               ptr = pixel.GetLoGainSamples();
               for (Int_t i=16;i<31;i++)
@@ -544,5 +555,5 @@
             } /* if use blind pixel */
           
-          //          break;
+          break;
         case fPINDiodeId:
 
@@ -643,51 +654,47 @@
       // so that we can use it for the fit
       //
+      Float_t pedestal;
+      Float_t pederr;
+      Float_t pedsigma;
+      Float_t pedsigmaerr;
+      
+      const ULong_t nentries    = fPedestals->GetTotalEntries();
+      const Int_t   nslices     = fBlindPixelLast-fBlindPixelFirst+1;
+      const Float_t sqrslice    = TMath::Sqrt((Float_t)nslices);
+      //
+      // retrieve the pedestal pix of the blind pixel
+      //
       if (fPedestals->GetHistSize() > fBlindPixelId)
         {
-
-          Float_t pedestal;
-          Float_t pederr;
-          Float_t pedsigma;
-          Float_t pedsigmaerr;
-
-          const ULong_t nentries    = fPedestals->GetTotalEntries();
-          const Float_t nslices     = (Float_t)(fgBlindPixelLast-fgBlindPixelFirst+1);
-          const Float_t sqrslice    = TMath::Sqrt(nslices);
+          MHPedestalPixel &pedhist = (*fPedestals)(fBlindPixelId);
+          pedestal    = pedhist.GetChargeMean()*nslices;
+          pederr      = pedhist.GetChargeMeanErr()*nslices;
           //
-          // retrieve the pedestal pix of the blind pixel
-          //
-          if (fPedestals->GetHistSize() != 0)
-            {
-              MHPedestalPixel &pedhist = (*fPedestals)(fBlindPixelId);
-              pedestal    = pedhist.GetChargeMean()*nslices;
-              pederr      = pedhist.GetChargeMeanErr()*nslices;
-              //
-              // Fitted sigma: 1. one sqrt(Nr. slices) for the division which is not 
-              //                  not appropriate: sigma(real)/slice = GetSigma*sqrt(nslices)
-              //               2. another sqrt(Nr. slices) to calculate back to number 
-              //                  of slices
-              // 
-              pedsigma    = pedhist.GetChargeSigma()*nslices;
-              pedsigmaerr = pedhist.GetChargeSigmaErr()*nslices;
-            }
-          else
-            {
-              MPedestalPix    &pedpix  = (*fPedestals)[fBlindPixelId];
-              pedestal    = pedpix.GetPedestal()*nslices;
-              pederr      = pedpix.GetPedestalRms()*nslices/nentries;
-              pedsigma    = pedpix.GetPedestalRms()*sqrslice;
-              pedsigmaerr = pederr/2.;
-            }
-          //
-          // retrieve the histogram containers
-          //
-          MHCalibrationBlindPixel *hist = blindpixel.GetHist();
-
-          hist->SetMeanPedestal(pedestal);
-          hist->SetMeanPedestalErr(pederr);
-          hist->SetSigmaPedestal(pedsigma);
-          hist->SetSigmaPedestalErr(pedsigmaerr);
+          // Fitted sigma: 1. one sqrt(Nr. slices) for the division which is not 
+          //                  not appropriate: sigma(real)/slice = GetSigma*sqrt(nslices)
+          //               2. another sqrt(Nr. slices) to calculate back to number 
+          //                  of slices
+          // 
+          pedsigma    = pedhist.GetChargeSigma()*nslices;
+          pedsigmaerr = pedhist.GetChargeSigmaErr()*nslices;
         }
-      
+      else
+        {
+          MPedestalPix    &pedpix  = (*fPedestals)[fBlindPixelId];
+          pedestal    = pedpix.GetPedestal()*nslices;
+          pederr      = pedpix.GetPedestalRms()*nslices/nentries;
+          pedsigma    = pedpix.GetPedestalRms()*sqrslice;
+          pedsigmaerr = pederr/2.;
+        }
+      //
+      // retrieve the histogram containers
+      //
+      MHCalibrationBlindPixel *hist = blindpixel.GetHist();
+      
+      hist->SetMeanPedestal(pedestal);
+      hist->SetMeanPedestalErr(pederr);
+      hist->SetSigmaPedestal(pedsigma);
+      hist->SetSigmaPedestalErr(pedsigmaerr);
+  
       if (!blindpixel.FitCharge())
         {
@@ -702,8 +709,18 @@
         fCalibrations->SetBlindPixelMethodValid(kFALSE);
 
+      TH1I *sphehist = hist->GetHSinglePheFADCSlices();
+      TH1I *pedhist  = hist->GetHPedestalFADCSlices();
+
+      if (fNumBlindPixelSinglePhe > 1)
+        sphehist->Scale(1./fNumBlindPixelSinglePhe);
+      if (fNumBlindPixelPedestal > 1)
+        pedhist->Scale(1./fNumBlindPixelPedestal);
+      
       blindpixel.DrawClone();
     }
   else 
     *fLog << inf << GetDescriptor() << ": Skipping Blind Pixel Fit " << endl;
+
+  *fLog << err << "total: " << GetNumExecutions() << " sphe: " << fNumBlindPixelSinglePhe << " ped: " << fNumBlindPixelPedestal << endl;
 
   
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationCalc.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationCalc.h	(revision 3122)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationCalc.h	(revision 3123)
@@ -38,40 +38,43 @@
 private:
 
-  static const UInt_t fBlindPixelId;        // ID of the blind pixel
-  static const UInt_t fPINDiodeId;          // ID of the PIN Diode
-  static const Byte_t fgSaturationLimit;    // Saturation of Hi Gain
-  static const Byte_t fgBlindPixelFirst;    // First FADC slice blind pixel
-  static const Byte_t fgBlindPixelLast;     // Last FADC slice blind pixel
-
+  static const UInt_t fBlindPixelId;            // ID of the blind pixel
+  static const UInt_t fPINDiodeId;              // ID of the PIN Diode
+  static const Byte_t fgSaturationLimit;        // Saturation of Hi Gain
+  static const Int_t  fgBlindPixelFirst;        // First FADC slice blind pixel
+  static const Int_t  fgBlindPixelLast;         // Last FADC slice blind pixel
   static const Int_t  fgBlindPixelSinglePheCut; // FADC sum from which on an event is considered as a S.ph. one.
   
-  MPedestalCam             *fPedestals;    // Pedestals of all pixels in the camera
-  MCalibrationCam          *fCalibrations; // Calibration events of all pixels in the camera
-  MExtractedSignalCam      *fSignals;      // Calibration events of all pixels in the camera
+  MPedestalCam             *fPedestals;         // Pedestals of all pixels in the camera
+  MCalibrationCam          *fCalibrations;      // Calibration events of all pixels in the camera
+  MExtractedSignalCam      *fSignals;           // Calibration events of all pixels in the camera
 
-  MRawEvtData              *fRawEvt;       // raw event data (time slices)
-  MRawRunHeader            *fRunHeader;    // RunHeader information
+  MRawEvtData              *fRawEvt;            // raw event data (time slices)
+  MRawRunHeader            *fRunHeader;         // RunHeader information
 
-  MTime                    *fEvtTime;      // Time of the event
+  MTime                    *fEvtTime;           // Time of the event
 
-  Byte_t fNumHiGainSamples; 
-  Byte_t fNumLoGainSamples; 
+  Byte_t  fNumHiGainSamples; 
+  Byte_t  fNumLoGainSamples; 
   Float_t fSqrtHiGainSamples; 
   
-  Byte_t fBlindPixelFirst;
-  Byte_t fBlindPixelLast;
+  Int_t   fBlindPixelFirst;
+  Int_t   fBlindPixelLast;
+  Int_t   fBlindPixelSinglePheCut;
 
-  Int_t  fBlindPixelSinglePheCut;
+  Int_t   fNumBlindPixelSinglePhe;
+  Int_t   fNumBlindPixelPedestal;  
   
   Float_t fConversionHiLo;
-  Int_t   fFlags;                           // Flag for the fits used
+  Int_t   fFlags;                                // Flag for the fits used
 
   TString fExcludedPixelsFile;
   UInt_t  fNumExcludedPixels;
 
-  enum  { kUseBlindPixelFit, kUsePinDiodeFit,
+  enum  { kUseBlindPixelFit, 
+          kUsePinDiodeFit,
           kUseQualityChecks,
           kHiLoGainCalibration,
-          kHiGainOverFlow, kLoGainOverFlow  };
+          kHiGainOverFlow, 
+          kLoGainOverFlow  };
   
 public:
@@ -97,9 +100,9 @@
   
   void SkipBlindPixelFit(Bool_t b=kTRUE)
-      {b ? CLRBIT(fFlags, kUseBlindPixelFit) : SETBIT(fFlags, kUseBlindPixelFit);}
+      {b ? CLRBIT(fFlags, kUseBlindPixelFit)    : SETBIT(fFlags, kUseBlindPixelFit);}
   void SkipPinDiodeFit(Bool_t b=kTRUE)
-      {b ? CLRBIT(fFlags, kUsePinDiodeFit) : SETBIT(fFlags, kUsePinDiodeFit);}
+      {b ? CLRBIT(fFlags, kUsePinDiodeFit)      : SETBIT(fFlags, kUsePinDiodeFit);}
   void SkipQualityChecks(Bool_t b=kTRUE)
-      {b ? CLRBIT(fFlags, kUseQualityChecks) : SETBIT(fFlags, kUseQualityChecks);}
+      {b ? CLRBIT(fFlags, kUseQualityChecks)    : SETBIT(fFlags, kUseQualityChecks);}
   void SkipHiLoGainCalibration(Bool_t b=kTRUE)
       {b ? CLRBIT(fFlags, kHiLoGainCalibration) : SETBIT(fFlags, kHiLoGainCalibration);}
@@ -107,9 +110,10 @@
 
   // Setters 
-  void SetPulserColor(PulserColor_t color)    { fColor = color; }
+  void SetPulserColor(PulserColor_t color)     { fColor          = color; }
   void SetConversionHiLo(Float_t conv)         { fConversionHiLo = conv; }
 
-  void SetBlindPixelRange(Byte_t first=fgBlindPixelFirst, Byte_t last=fgBlindPixelLast);
-  void SetBlindPixelSinglePheCut(Int_t cut=fgBlindPixelSinglePheCut)    { fBlindPixelSinglePheCut = cut;  }
+  void SetBlindPixelRange(Int_t first=fgBlindPixelFirst, Int_t last=fgBlindPixelLast);
+  void SetBlindPixelSinglePheCut(Int_t cut=fgBlindPixelSinglePheCut)    
+                                               { fBlindPixelSinglePheCut = cut;  }
   
   // Getters
