Index: trunk/Mars/mcore/DrsCalib.h
===================================================================
--- trunk/Mars/mcore/DrsCalib.h	(revision 17240)
+++ trunk/Mars/mcore/DrsCalib.h	(revision 17241)
@@ -504,6 +504,6 @@
         rc.avg /= rc.cnt;
         rc.rms /= rc.cnt;
-
-        rc.rms = sqrt(rc.rms-rc.avg*rc.avg);
+        rc.rms -= rc.avg*rc.avg;
+        rc.rms  = rc.rms<0 ? 0 : sqrt(rc.rms);
 
         return rc;
@@ -1377,5 +1377,5 @@
     }
 
-    std::string WriteFitsImp(const std::string &filename, const std::vector<float> &vec) const
+    std::string WriteFitsImp(const std::string &filename, uint32_t night, const std::vector<float> &vec) const
     {
         const size_t n = 1440*1024*4 + 1440*fRoi*2 + fNumTm*fRoi*2 + 3;
@@ -1406,22 +1406,7 @@
         file.AddColumnFloat(fRoi*fNumTm, "TriggerOffsetTMRms",  "mV");
 
-#ifdef __MARS__
-        const MTime now(-1);
-        file.SetStr(  "TELESCOP", "FACT",               "Telescope that acquired this data");
-        file.SetStr(  "PACKAGE",  "MARS",               "Package name");
-        file.SetStr(  "VERSION",  "1.0",                "Package description");
-        //file.SetStr(  "CREATOR",  "root",               "Program that wrote this file");
-        file.SetFloat("EXTREL",   1.0,                  "Release Number");
-        file.SetStr(  "COMPILED", __DATE__" "__TIME__,  "Compile time");
-        //file.SetStr(  "REVISION", REVISION,             "SVN revision");
-        file.SetStr(  "ORIGIN",   "FACT",               "Institution that wrote the file");
-        file.SetStr(  "DATE",     now.GetStringFmt("%Y-%m-%dT%H:%M:%S").Data(), "File creation date");
-        file.SetInt(  "NIGHT",    now.GetNightAsInt(),  "Night as int");
-        file.SetStr(  "TIMESYS",  "UTC",                "Time system");
-        file.SetStr(  "TIMEUNIT", "d",                  "Time given in days w.r.t. to MJDREF");
-        file.SetInt(  "MJDREF",   40587,                "MJD to UNIX time (seconds since 1970/1/1)");
-#else
-        DataWriteFits2::WriteDefaultKeys(file);
-#endif
+        file.SetDefaultKeys();
+        file.SetInt("NIGHT", night, "Night as int");
+
         file.SetStr("DATE-OBS", fDateObs, "First event of whole DRS calibration");
         file.SetStr("DATE-END", fDateEnd, "Last event of whole DRS calibration");
