Index: trunk/MagicSoft/Mars/mcalib/MCalibColorSet.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibColorSet.cc	(revision 5682)
+++ trunk/MagicSoft/Mars/mcalib/MCalibColorSet.cc	(revision 5690)
@@ -39,5 +39,7 @@
 #include "MCalibColorSet.h"
 
-#include "TRegexp.h"
+#include <stdlib.h>   // needed for atoi on some platforms
+
+#include <TRegexp.h>
 
 #include "MLog.h"
@@ -51,10 +53,10 @@
 ClassImp(MCalibColorSet);
 
-
 using namespace std;
 
-const Int_t MCalibColorSet::gkIFAEBoxInaugurationRun = 20113;
-const Int_t MCalibColorSet::gkMCRunLimit             = 1000;
-const UInt_t MCalibColorSet::gkFirstRunWithFinalBits = 45626;
+const Int_t  MCalibColorSet::gkIFAEBoxInaugurationRun = 20113;
+const Int_t  MCalibColorSet::gkMCRunLimit             = 1000;
+const UInt_t MCalibColorSet::gkFirstRunWithFinalBits  = 45626;
+
 // --------------------------------------------------------------------------
 //
@@ -95,4 +97,23 @@
 
   return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Check if str contains regexp.
+// If so or pat to pattern and set color to col.
+// Otherwise do nothing.
+//
+// Normally this function is much to simple (more arguments than lines!)
+// but in this particular case it is worth to have it to avois chaotic
+// repitions of the same piece of code for many many times.
+//
+void MCalibColorSet::CheckAndSet(const TString &str, const char *regexp, UInt_t &pattern, UInt_t pat, Int_t &color, Int_t col) const
+{
+    if (!str.Contains(TRegexp(regexp)))
+        return;
+
+    pattern |= pat;
+    color = col;
 }
 
@@ -295,198 +316,129 @@
   
   if (color!=kNONE)
-    {
+  {
       *fLog << inf << "Color determined from the run-number... ";
       switch (color)
-        {
-        case kGREEN: *fLog << "Green."; fPattern |= k5LedGreen; break;
-        case kBLUE:  *fLog << "Blue.";  fPattern |= k5LedBlue1; break;
-        case kUV:    *fLog << "UV.";    fPattern |= k10LedUV; break;
-        }
+      {
+      case kGREEN: *fLog << "Green."; fPattern |= k5LedGreen; break;
+      case kBLUE:  *fLog << "Blue.";  fPattern |= k5LedBlue1; break;
+      case kUV:    *fLog << "UV.";    fPattern |= k10LedUV;   break;
+      }
       *fLog << endl;
       fIsValid  = kTRUE;
       return kTRUE;
-    }
-  else
-    {
-
-      TString proj = header->GetProjectName();
-      proj.ToLower();
-
-      // Possible green combinations
-      TRegexp gre0("0.1led[sS]?gree");
-      if (proj.Contains(gre0))
-        { fPattern |= k01LedGreen; color = kGREEN;    }
-      TRegexp gre1("1led[sS]?gree");
-      if (proj.Contains(gre1))
-        { fPattern |= k1LedGreen; color = kGREEN;    }
-      TRegexp gre2("2led[sS]?gree");
-      if (proj.Contains(gre2))
-        { fPattern |= k2LedGreen; color = kGREEN;    }
-      TRegexp gre3("3led[sS]?gree");
-      if (proj.Contains(gre3))
-        { fPattern |= k3LedGreen; color = kGREEN;    }
-      TRegexp gre5("5led[sS]?gree");
-      if (proj.Contains(gre5))
-        { fPattern |= k5LedGreen; color = kGREEN;    }
-      TRegexp gre6("6led[sS]?gree");
-      if (proj.Contains(gre6))
-        { fPattern |= k6LedGreen; color = kGREEN;    }
-      TRegexp gre7("7led[sS]?gree");
-      if (proj.Contains(gre7))
-        { fPattern |= k7LedGreen; color = kGREEN;    }
-      TRegexp gre8("8led[sS]?gree");
-      if (proj.Contains(gre8))
-        { fPattern |= k8LedGreen; color = kGREEN;    }
-
-      // Possible blue combinations
-      TRegexp blu0("0.1led[sS]?blue");
-      if (proj.Contains(blu0))
-        { fPattern |= k01LedBlue; color = kBLUE;    }
-      TRegexp blu1("1led[sS]?blue");
-      if (proj.Contains(blu1))
-        { fPattern |= k1LedBlue; color = kBLUE;    }
-      TRegexp blu2("2led[sS]?blue");
-      if (proj.Contains(blu2))
-        { fPattern |= k2LedBlue; color = kBLUE;    }
-      TRegexp blu3("3led[sS]?blue");
-      if (proj.Contains(blu3))
-        { fPattern |= k3LedBlue; color = kBLUE;    }
-      TRegexp blu5("5led[sS]?blue");
-      if (proj.Contains(blu5))
-        { fPattern |= k5LedBlue1; color = kBLUE;    }
-      TRegexp blu6("6led[sS]?blue");
-      if (proj.Contains(blu6))
-        { fPattern |= k6LedBlue; color = kBLUE;    }
-      TRegexp blu7("7led[sS]?blue");
-      if (proj.Contains(blu7))
-        { fPattern |= k7LedBlue; color = kBLUE;    }
-      TRegexp blu8("8led[sS]?blue");
-      if (proj.Contains(blu8))
-        { fPattern |= k8LedBlue; color = kBLUE;    }
-      TRegexp blu10("10led[sS]?blue");
-      if (proj.Contains(blu10))
-        { fPattern |= k10LedBlue; color = kBLUE;    }
-      TRegexp blu15("15led[sS]?blue");
-      if (proj.Contains(blu15))
-        { fPattern |= k15LedBlue; color = kBLUE;    }
-      TRegexp blu20("20led[sS]?blue");
-      if (proj.Contains(blu20))
-        { fPattern |= k20LedBlue; color = kBLUE;    }
-      TRegexp blu21("21led[sS]?blue");
-      if (proj.Contains(blu21))
-        { fPattern |= k21LedBlue; color = kBLUE;    }
-      TRegexp blu22("22led[sS]?blue");
-      if (proj.Contains(blu22))
-        { fPattern |= k22LedBlue; color = kBLUE;    }
-      TRegexp blu23("23led[sS]?blue");
-      if (proj.Contains(blu23))
-        { fPattern |= k23LedBlue; color = kBLUE;    }
-
-      // Possible UV combinations
-      TRegexp uv1("1led[sS]?uv");
-      if (proj.Contains(uv1))
-        { fPattern |= k1LedUV; color = kUV;    }
-      TRegexp uv2("2led[sS]?uv");
-      if (proj.Contains(uv2))
-        { fPattern |= k2LedUV; color = kUV;    }
-      TRegexp uv3("3led[sS]?uv");
-      if (proj.Contains(uv3))
-        { fPattern |= k3LedUV; color = kUV;    }
-      TRegexp uv5("5led[sS]?uv");
-      if (proj.Contains(uv5))
-        { fPattern |= k5LedUV1; color = kUV;    }
-      TRegexp uv6("6led[sS]?uv");
-      if (proj.Contains(uv6))
-        { fPattern |= k6LedUV; color = kUV;    }
-      TRegexp uv7("7led[sS]?uv");
-      if (proj.Contains(uv7))
-        { fPattern |= k7LedUV; color = kUV;    }
-      TRegexp uv8("8led[sS]?uv");
-      if (proj.Contains(uv8))
-        { fPattern |= k8LedUV; color = kUV;    }
-      TRegexp uv10("10led[sS]?uv");
-      if (proj.Contains(uv10))
-        { fPattern |= k10LedUV; color = kUV;    }
-      TRegexp uv11("11led[sS]?uv");
-      if (proj.Contains(uv11))
-        { fPattern |= k11LedUV; color = kUV;    }
-      TRegexp uv12("12led[sS]?uv");
-      if (proj.Contains(uv12))
-        { fPattern |= k12LedUV; color = kUV;    }
-      TRegexp uv13("13led[sS]?uv");
-      if (proj.Contains(uv13))
-        { fPattern |= k13LedUV; color = kUV;    }
-
-      // Possible slot combinations
-      TRegexp slot("slot");
-      if (proj.Contains(slot))
-        {
-          proj.ReplaceAll("slot","");
-          UInt_t nr = 0;
-          TRegexp slotnr("^[0-9]");
-          
-          if (proj.Contains(slotnr))
-            { fPattern = 0; proj.Replace(2,99,""); 
-            proj.ReplaceAll("u","");
-            proj.ReplaceAll("v","");
-            proj.ReplaceAll("g","");
-            nr = atoi(proj.Data())-1; 
-            fPattern |= BIT(nr);
-            color = nr < 2 ? kGREEN : 
-              ( nr < 3 ) ? kBLUE : 
-              ( nr < 5 ) ? kUV : 
-              ( nr < 11 ) ? kBLUE : 
-              ( nr < 13 ) ? kUV : 
-              ( nr < 14 ) ? kBLUE : 
-              ( nr < 16 ) ? kGREEN : 
-              kCT1;    
-            }
-        }
-      
+  }
+
+  TString proj = header->GetProjectName();
+  proj.ToLower();
+
+  // Possible green combinations
+  CheckAndSet(proj, "0.1led[sS]?gree", fPattern, k01LedGreen, color, kGREEN);
+  CheckAndSet(proj, "1led[sS]?gree",   fPattern, k1LedGreen,  color, kGREEN);
+  CheckAndSet(proj, "2led[sS]?gree",   fPattern, k2LedGreen,  color, kGREEN);
+  CheckAndSet(proj, "3led[sS]?gree",   fPattern, k3LedGreen,  color, kGREEN);
+  CheckAndSet(proj, "5led[sS]?gree",   fPattern, k5LedGreen,  color, kGREEN);
+  CheckAndSet(proj, "6led[sS]?gree",   fPattern, k6LedGreen,  color, kGREEN);
+  CheckAndSet(proj, "7led[sS]?gree",   fPattern, k7LedGreen,  color, kGREEN);
+  CheckAndSet(proj, "8led[sS]?gree",   fPattern, k8LedGreen,  color, kGREEN);
+
+  // Possible blue combinations
+  CheckAndSet(proj, "0.1led[sS]?blue", fPattern, k01LedBlue,  color, kBLUE);
+  CheckAndSet(proj, "1led[sS]?blue",   fPattern, k1LedBlue,   color, kBLUE);
+  CheckAndSet(proj, "2led[sS]?blue",   fPattern, k2LedBlue,   color, kBLUE);
+  CheckAndSet(proj, "3led[sS]?blue",   fPattern, k3LedBlue,   color, kBLUE);
+  CheckAndSet(proj, "5led[sS]?blue",   fPattern, k5LedBlue1,  color, kBLUE);
+  CheckAndSet(proj, "6led[sS]?blue",   fPattern, k6LedBlue,   color, kBLUE);
+  CheckAndSet(proj, "7led[sS]?blue",   fPattern, k7LedBlue,   color, kBLUE);
+  CheckAndSet(proj, "8led[sS]?blue",   fPattern, k8LedBlue,   color, kBLUE);
+  CheckAndSet(proj, "10led[sS]?blue",  fPattern, k10LedBlue,  color, kBLUE);
+  CheckAndSet(proj, "15led[sS]?blue",  fPattern, k15LedBlue,  color, kBLUE);
+  CheckAndSet(proj, "20led[sS]?blue",  fPattern, k20LedBlue,  color, kBLUE);
+  CheckAndSet(proj, "21led[sS]?blue",  fPattern, k21LedBlue,  color, kBLUE);
+  CheckAndSet(proj, "22led[sS]?blue",  fPattern, k22LedBlue,  color, kBLUE);
+  CheckAndSet(proj, "23led[sS]?blue",  fPattern, k23LedBlue,  color, kBLUE);
+
+  // Possible UV combinations
+  CheckAndSet(proj, "1led[sS]?uv",     fPattern, k1LedUV,    color,  kUV);
+  CheckAndSet(proj, "2led[sS]?uv",     fPattern, k2LedUV,    color,  kUV);
+  CheckAndSet(proj, "3led[sS]?uv",     fPattern, k3LedUV,    color,  kUV);
+  CheckAndSet(proj, "5led[sS]?uv",     fPattern, k5LedUV1,   color,  kUV);
+  CheckAndSet(proj, "6led[sS]?uv",     fPattern, k6LedUV,    color,  kUV);
+  CheckAndSet(proj, "7led[sS]?uv",     fPattern, k7LedUV,    color,  kUV);
+  CheckAndSet(proj, "8led[sS]?uv",     fPattern, k8LedUV,    color,  kUV);
+  CheckAndSet(proj, "10led[sS]?uv",    fPattern, k10LedUV,   color,  kUV);
+  CheckAndSet(proj, "11led[sS]?uv",    fPattern, k11LedUV,   color,  kUV);
+  CheckAndSet(proj, "12led[sS]?uv",    fPattern, k12LedUV,   color,  kUV);
+  CheckAndSet(proj, "13led[sS]?uv",    fPattern, k13LedUV,   color,  kUV);
+
+  // Possible slot combinations
+  TRegexp slot("slot");
+  if (proj.Contains(slot))
+  {
+      proj.ReplaceAll("slot","");
+      UInt_t nr = 0;
+      TRegexp slotnr("^[0-9]");
+
+      if (proj.Contains(slotnr))
+      {
+          fPattern = 0;
+          proj.Replace(2,99,"");
+          proj.ReplaceAll("u","");
+          proj.ReplaceAll("v","");
+          proj.ReplaceAll("g","");
+          nr = atoi(proj.Data())-1;
+
+          fPattern |= BIT(nr);
+
+          color = nr < 2 ? kGREEN :
+              ( nr < 3 ) ? kBLUE :
+              ( nr < 5 ) ? kUV :
+              ( nr < 11 ) ? kBLUE :
+              ( nr < 13 ) ? kUV :
+              ( nr < 14 ) ? kBLUE :
+              ( nr < 16 ) ? kGREEN :
+              kCT1;
+      }
+  }
+
+  if (color == kNONE)
+  {
+      CheckAndSet(proj, "gree", fPattern, k5LedGreen, color, kGREEN);
+      CheckAndSet(proj, "blue", fPattern, k5LedBlue1, color, kBLUE);
+      CheckAndSet(proj, "uv",   fPattern, k5LedUV1,   color, kUV);
+      CheckAndSet(proj, "ct1",  fPattern, kCT1Pulser, color, kCT1);
+
       if (color != kNONE)
-        *fLog << inf << "Color and Intensity determined from project-name (" << proj << ")... ";          
+          *fLog << inf << "Color determined from project-name (" << proj << ")... ";
       else
-        {
-          if (proj.Contains("gree",TString::kIgnoreCase))
-            { fPattern |= k5LedGreen; color = kGREEN; }
-          if (proj.Contains("blue",TString::kIgnoreCase))
-            { fPattern |=k5LedBlue1; color = kBLUE;}
-          if (proj.Contains("uv",TString::kIgnoreCase))
-            { fPattern |=k5LedUV1  ; color = kUV;  }
-          if (proj.Contains("ct1",TString::kIgnoreCase))
-            { fPattern |=kCT1Pulser; color = kCT1; }
-          if (color != kNONE)
-            *fLog << inf << "Color determined from project-name (" << proj << ")... ";
-          else if (proj.Contains("cl",TString::kIgnoreCase))
-            {
-              *fLog << warn << "This run has been taken with the continuous light source." << endl;
-              *fLog << warn 
-                    << "It cannot be used for calibration. Try to run a pedestal extraction on it." << endl;
+          if (proj.Contains("cl",TString::kIgnoreCase))
+          {
+              *fLog << warn;
+              *fLog << "This run has been taken with the continuous light source." << endl;
+              *fLog << "It cannot be used for calibration. Try to run a pedestal extraction on it." << endl;
               fPattern = 0;
               fIsValid = kTRUE;
               return kTRUE;
-            }
-        }
-    }
-  
-  if (color==kNONE)
-    {
-      *fLog << err << "Sorry, calibration run " << num << " was taken before the events could be" << endl;
+          }
+
+      *fLog << err;
+      *fLog << "Sorry, calibration run " << num << " was taken before the events could be" << endl;
       *fLog << "flagged with a color by the digital modul and no color" << endl;
       *fLog << "could be determined... abort." << endl;
       return kFALSE;
-    }
-  
+  }
+
+  *fLog << inf << "Color and Intensity determined from project-name (" << proj << ")... ";
+
   switch (color)
-    {
-    case kGREEN: *fLog << "Green.";  break;
-    case kBLUE:  *fLog << "Blue.";   break;
-    case kUV:    *fLog << "UV.";     break;
-    case kCT1:   *fLog << "CT1.";    break;
-    }
+  {
+  case kGREEN: *fLog << "Green.";  break;
+  case kBLUE:  *fLog << "Blue.";   break;
+  case kUV:    *fLog << "UV.";     break;
+  case kCT1:   *fLog << "CT1.";    break;
+  }
   *fLog << endl;
-  
+
   fIsValid = kTRUE;
-  
+
   return kTRUE;
 }
Index: trunk/MagicSoft/Mars/mcalib/MCalibColorSet.h
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibColorSet.h	(revision 5682)
+++ trunk/MagicSoft/Mars/mcalib/MCalibColorSet.h	(revision 5690)
@@ -21,5 +21,7 @@
   UInt_t fPattern;                            //  Current pulse pattern
   Bool_t fIsValid;                            //  Have to set the pulse pattern?
-  
+
+  void CheckAndSet(const TString &str, const char *regexp, UInt_t &pattern, UInt_t pat, Int_t &color, Int_t col) const;
+
   Bool_t ReInit(MParList *pList);
   Int_t  PreProcess(MParList *pList);
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationIntensityChargeCam.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationIntensityChargeCam.cc	(revision 5682)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationIntensityChargeCam.cc	(revision 5690)
@@ -40,16 +40,17 @@
 /////////////////////////////////////////////////////////////////////////////
 #include "MCalibrationIntensityChargeCam.h"
+
+#include <TF1.h>
+#include <TH2.h>
+#include <TGraphErrors.h>
+#include <TOrdCollection.h>
+
+#include "MLog.h"
+
+#include "MGeomCam.h"
+#include "MGeomPix.h"
+
 #include "MCalibrationChargeCam.h"
 #include "MCalibrationChargePix.h"
-
-#include "MGeomCam.h"
-#include "MGeomPix.h"
-
-#include "MLog.h"
-
-#include <TOrdCollection.h>
-#include <TGraphErrors.h>
-#include <TH2F.h>
-#include <TF1.h>
 
 ClassImp(MCalibrationIntensityChargeCam);
@@ -428,5 +429,5 @@
       const Float_t qe = pix.GetConvertedMeanErr();
       oneoverq   [i] = 1./q;
-      oneoverqerr[i] = qe / q / q;
+      oneoverqerr[i] = qe / (q * q);
     }
   
@@ -436,5 +437,5 @@
   gr->SetTitle(Form("%s%3i","Pixel ",pixid));
   gr->GetXaxis()->SetTitle("1/Q [FADC counts^{-1}]");
-  gr->GetYaxis()->SetTitle("\sigma_{red}^{2}/Q^{2} [1]");      
+  gr->GetYaxis()->SetTitle("\\sigma_{red}^{2}/Q^{2} [1]");
   return gr;
 }
