Index: trunk/Mars/msimcamera/MSimRandomPhotons.cc
===================================================================
--- trunk/Mars/msimcamera/MSimRandomPhotons.cc	(revision 9932)
+++ trunk/Mars/msimcamera/MSimRandomPhotons.cc	(revision 9991)
@@ -150,29 +150,4 @@
 }
 
-Bool_t MSimRandomPhotons::CheckWavelengthRange(const MParSpline &sp, const char *txt) const
-{
-    const Float_t min = sp.GetXmin();
-    const Float_t max = sp.GetXmax();
-
-    if (min>fRunHeader->GetWavelengthMin())
-    {
-        *fLog << err << "ERROR - Minimum wavelength (" << min << "nm)";
-        *fLog << " defined for " << txt;
-        *fLog << " exceeds minimum wavelength simulated (";
-        *fLog << fRunHeader->GetWavelengthMin() << "nm)." << endl;
-        return kFALSE;
-    }
-    if (max<fRunHeader->GetWavelengthMax())
-    {
-        *fLog << err << "ERROR - Maximum wavelength (" << max << "nm)";
-        *fLog << " defined for " << txt;
-        *fLog << " undershoots maximum wavelength simulated (";
-        *fLog << fRunHeader->GetWavelengthMax() << "nm)." << endl;
-        return kFALSE;
-    }
-
-    return kTRUE;
-}
-
 // --------------------------------------------------------------------------
 //
@@ -221,5 +196,5 @@
 
     fRunHeader = (MCorsikaRunHeader*)pList->FindObject("MCorsikaRunHeader");
-    if (!fRunHeader)
+    if (fSimulateWavelength && !fRunHeader)
     {
         *fLog << err << "MCorsikaRunHeader not found... aborting." << endl;
@@ -239,14 +214,34 @@
     const MParSpline *s4 = (MParSpline*)pList->FindObject("ConesAngularAcceptance",    "MParSpline");
 
-    // Check if all splines are defined in the relevant range
-    if (!CheckWavelengthRange(*s1, "PhotonDetectionEfficiency [MParSpline]"))
-        return kFALSE;
-    if (!CheckWavelengthRange(*s2, "ConesTransmission [MParSpline]"))
-        return kFALSE;
-    if (!CheckWavelengthRange(*s3, "MirrorReflectivity [MParSpline]"))
-        return kFALSE;
-
-    const Float_t wmin = fRunHeader->GetWavelengthMin();
-    const Float_t wmax = fRunHeader->GetWavelengthMax();
+    // Ensure that all efficiencies are at least defined in the raneg of the
+    // photon detection efficiency. We assume that this is the limiting factor
+    // and has to be zero at both ends.
+    if (s2->GetXmin()>s1->GetXmin())
+    {
+        *fLog << err << "ERROR - ConeTransmission range must be defined down to " << s1->GetXmin() << "nm (PhotonDetectionEffciency)." << endl;
+        return kFALSE;
+    }
+    if (s2->GetXmax()<s1->GetXmax())
+    {
+        *fLog << err << "ERROR - ConeTransmission range must be defined up to " << s1->GetXmax() << "nm (PhotonDetectionEffciency)." << endl;
+        return kFALSE;
+    }
+    if (s3->GetXmin()>s1->GetXmin())
+    {
+        *fLog << err << "ERROR - MirrorReflectivity range must be defined down to " << s1->GetXmin() << "nm (PhotonDetectionEffciency)." << endl;
+        return kFALSE;
+    }
+    if (s3->GetXmax()<s1->GetXmax())
+    {
+        *fLog << err << "ERROR - MirrorReflectivity range must be defined up to " << s1->GetXmax() << "nm (PhotonDetectionEffciency)." << endl;
+        return kFALSE;
+    }
+
+    // If the simulated wavelenth range exists and is smaller reduce the
+    // range to it. Later it is checked that at both edges the transmission
+    // is 0. This must be true in both cases: The simulated wavelength range
+    // exceed the PDE or the PDE range exceeds the simulated waveband.
+    const Float_t wmin = fRunHeader && fRunHeader->GetWavelengthMin()>s1->GetXmin() ? fRunHeader->GetWavelengthMin() : s1->GetXmin();
+    const Float_t wmax = fRunHeader && fRunHeader->GetWavelengthMax()<s1->GetXmax() ? fRunHeader->GetWavelengthMax() : s1->GetXmax();
 
     const Int_t min = TMath::FloorNint(wmin);
@@ -316,6 +311,14 @@
         return kFALSE;
 
-    if (!CheckWavelengthRange(flux, TString("night sky background flux from ")+fFileNameNSB))
-        return kFALSE;
+    if (flux.GetXmin()>wmin)
+    {
+        *fLog << err << "ERROR - NSB flux from " << fFileNameNSB << " must be defined down to " << wmin << "nm." << endl;
+        return kFALSE;
+    }
+    if (flux.GetXmax()<wmax)
+    {
+        *fLog << err << "ERROR - NSB flux from " << fFileNameNSB << " must be defined up to " << wmax << "nm." << endl;
+        return kFALSE;
+    }
 
     MParSpline nsb;
@@ -334,10 +337,10 @@
     if (eff.GetSpline()->Eval(min)>1e-5)
     {
-        *fLog << warn << "WARNING - Total transmission efficiency at detector at ";
+        *fLog << warn << "WARNING - Total transmission efficiency at ";
         *fLog << min << "nm is not zero, but " << nsb.GetSpline()->Eval(min) << "... abort." << endl;
     }
     if (eff.GetSpline()->Eval(max)>1e-5)
     {
-        *fLog << warn << "WARNING - Total transmission efficiency at detector at ";
+        *fLog << warn << "WARNING - Total transmission efficiency at ";
         *fLog << max << "nm is not zero, but " << nsb.GetSpline()->Eval(max) << "... abort." << endl;
     }
@@ -346,5 +349,5 @@
     if (eff.GetSpline()->Eval(wmin)>1e-5)
     {
-        *fLog << err << "ERROR - Total transmission efficiency at detector at minimum simulated wavelength ";
+        *fLog << err << "ERROR - Total transmission efficiency at ";
         *fLog << wmin << "nm is not zero... abort." << endl;
         *fLog << "        PhotonDetectionEfficency: " << s1->GetSpline()->Eval(wmin) << endl;
@@ -356,5 +359,5 @@
     if (eff.GetSpline()->Eval(wmax)>1e-5)
     {
-        *fLog << err << "ERROR - Total transmission efficiency at detector at maximum simulated wavelength ";
+        *fLog << err << "ERROR - Total transmission efficiency at ";
         *fLog << wmax << "nm is not zero... abort." << endl;
         *fLog << "        PhotonDetectionEfficency: " << s1->GetSpline()->Eval(wmax) << endl;
