Index: /trunk/MagicSoft/Mars/mbase/MTime.cc
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MTime.cc	(revision 8550)
+++ /trunk/MagicSoft/Mars/mbase/MTime.cc	(revision 8551)
@@ -89,6 +89,7 @@
 using namespace std;
 
-const UInt_t MTime::kHour = 3600000;         // [ms] one hour
-const UInt_t MTime::kDay  = MTime::kHour*24; // [ms] one day
+const UInt_t MTime::kHour   = 3600000;         // [ms] one hour
+const UInt_t MTime::kDay    = MTime::kHour*24; // [ms] one day
+const UInt_t MTime::kDaySec = 3600*24;         // [s] one day
 
 // --------------------------------------------------------------------------
@@ -238,5 +239,5 @@
 TDatime MTime::GetRootDatime() const
 {
-    return TDatime((UInt_t)((GetMjd()-40587)*kDay/1000));
+    return TDatime((UInt_t)((GetMjd()-40587)*kDaySec));
 }
 
@@ -252,5 +253,5 @@
 Double_t MTime::GetAxisTime() const
 {
-    return (GetMjd()-49718)*kDay/1000;
+    return (GetMjd()-49718)*kDaySec;
 }
 
@@ -261,14 +262,29 @@
 void MTime::SetAxisTime(Double_t time)
 {
-    SetMjd(time*1000/kDay+49718);
-}
-
-// --------------------------------------------------------------------------
-//
-// Set unix time (seconds since epoche 1970-01-01)
-//
-void MTime::SetUnixTime(Long_t tm)
-{
-    SetMjd(1000.*tm/kDay+40587);
+    SetMjd(time/kDaySec+49718);
+}
+
+// --------------------------------------------------------------------------
+//
+// Set unix time (seconds since epoche 1970-01-01 00:00)
+//
+void MTime::SetUnixTime(Long64_t sec, ULong64_t usec)
+{
+    const Long64_t totsec = sec + usec/1000000;
+    const UInt_t   mjd    = totsec/kDaySec + 40587;
+
+    const UInt_t   ms     = totsec%kDaySec*1000 + (usec/1000)%1000;
+    const UInt_t   us     = usec%1000;
+
+    SetMjd(mjd, ms, us*1000);
+}
+
+// --------------------------------------------------------------------------
+//
+// Set MTime to time expressed in a 'struct timeval'
+//
+void MTime::Set(const struct timeval &tv)
+{
+    SetUnixTime(tv.tv_sec, tv.tv_usec);
 }
 
@@ -342,18 +358,4 @@
 
     return SetMjd(mjd, tm, ns);
-}
-
-// --------------------------------------------------------------------------
-//
-// Set MTime to time expressed in a 'struct timeval'
-//
-void MTime::Set(const struct timeval &tv)
-{
-    const UInt_t mjd = (UInt_t)TMath::Floor(1000.*tv.tv_sec/kDay) + 40587;
-
-    const Long_t tm  = tv.tv_sec%(24*3600)*1000 + tv.tv_usec/1000;
-    const UInt_t ms  = tv.tv_usec%1000;
-
-    SetMjd(mjd, tm, ms*1000);
 }
 
@@ -489,5 +491,5 @@
     const Double_t r2 = 86400.0*ut;
 
-    const Double_t sum = (r1+r2)/(24*3600);
+    const Double_t sum = (r1+r2)/kDaySec;
 
     return fmod(sum, 1)*TMath::TwoPi();//+TMath::TwoPi();
@@ -975,5 +977,5 @@
 void MTime::SetMean(Double_t t0, Double_t t1)
 {
-    const Double_t mean = (t0+t1)*(500./kDay);
+    const Double_t mean = (t0+t1)*(0.5/kDaySec);
     SetMjd(mean);
 }
Index: /trunk/MagicSoft/Mars/mbase/MTime.h
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MTime.h	(revision 8550)
+++ /trunk/MagicSoft/Mars/mbase/MTime.h	(revision 8551)
@@ -27,6 +27,7 @@
 {
 public:
-    static const UInt_t kHour; // [ms] one hour
-    static const UInt_t kDay;  // [ms] one day
+    static const UInt_t kHour;    // [ms] one hour
+    static const UInt_t kDay;     // [ms] one day
+    static const UInt_t kDaySec;  // [s] one day
 
     enum {
@@ -98,5 +99,5 @@
     void     SetMjd(Double_t m);
     void     SetAxisTime(Double_t time);
-    void     SetUnixTime(Long_t time);
+    void     SetUnixTime(Long64_t sec, ULong64_t usec=0);
     void     SetEaster(Short_t year=0);
 
@@ -126,14 +127,17 @@
     }
 
-    UInt_t Year() const    { UShort_t y; Byte_t m, d; GetDate(y,m,d); return y; }
-    UInt_t Month() const   { UShort_t y; Byte_t m, d; GetDate(y,m,d); return m; }
-    UInt_t Day() const     { UShort_t y; Byte_t m, d; GetDate(y,m,d); return d; }
-    Byte_t WeekDay() const { return TMath::Nint(TMath::Floor(GetMjd()+3))%7; } // Return Day of the week: Sun=0, Mon=1, ..., Sat=6
-    UInt_t Hour() const    { Byte_t h, m, s; GetTime(h,m,s); return h; }
-    UInt_t Min() const     { Byte_t h, m, s; GetTime(h,m,s); return m; }
-    UInt_t Sec() const     { Byte_t h, m, s; GetTime(h,m,s); return s; }
+    UInt_t Year() const     { UShort_t y; Byte_t m, d; GetDate(y,m,d); return y; }
+    UInt_t Month() const    { UShort_t y; Byte_t m, d; GetDate(y,m,d); return m; }
+    UInt_t Day() const      { UShort_t y; Byte_t m, d; GetDate(y,m,d); return d; }
+    Byte_t WeekDay() const  { return TMath::Nint(TMath::Floor(GetMjd()+3))%7; } // Return Day of the week: Sun=0, Mon=1, ..., Sat=6
+    UInt_t Hour() const     { Byte_t h, m, s; GetTime(h,m,s); return h; }
+    UInt_t Min() const      { Byte_t h, m, s; GetTime(h,m,s); return m; }
+    UInt_t Sec() const      { Byte_t h, m, s; GetTime(h,m,s); return s; }
+    UInt_t MilliSec() const { return (GetTime()+kDay)%1000; }
+    UInt_t MicroSec() const { return fNanoSec/1000+MilliSec()*1000; }
+    UInt_t NanoSec() const  { return fNanoSec+MilliSec()*1000000; }
+    Int_t  Week() const     { Short_t y; return Week(y); }
+    Int_t  Week(Short_t &year) const;
     UInt_t DayOfYear() const;
-    Int_t  Week() const    { Short_t y; return Week(y); }
-    Int_t  Week(Short_t &year) const;
 
     Bool_t IsMidnight() const { return (Long_t)fTime==0 && fNanoSec==0; }
Index: unk/MagicSoft/Mars/mtemp/mpisa/macros/first_ana.C
===================================================================
--- /trunk/MagicSoft/Mars/mtemp/mpisa/macros/first_ana.C	(revision 8550)
+++ 	(revision )
@@ -1,125 +1,0 @@
-/* ======================================================================== *\
-!
-! *
-! * This file is part of MARS, the MAGIC Analysis and Reconstruction
-! * Software. It is distributed to you in the hope that it can be a useful
-! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
-! * It is distributed WITHOUT ANY WARRANTY.
-! *
-! * Permission to use, copy, modify and distribute this software and its
-! * documentation for any purpose is hereby granted without fee,
-! * provided that the above copyright notice appear in all copies and
-! * that both that copyright notice and this permission notice appear
-! * in supporting documentation. It is provided "as is" without express
-! * or implied warranty.
-! *
-!
-!
-!   Author(s): Alessio Piccioli, 04/2004 <mailto:alessio.piccioli@pi.infn.it>
-!   Author(s): Antonio Stamerra, 04/2004 <mailto:antonio.stamerra@pi.infn.it>
-!
-!   Copyright: MAGIC Software Development, 2000-2004
-!
-!
-\* ======================================================================== */
-
-///////////////////////////////////////////////////////////////////////////
-//
-// first_ana.C
-// =============
-//
-//  This macro produces a ON/OFF plot using the alpha HillasSrc branch
-//  taken from an analysis file produced by the AnalisiHillas.C macro
-//  The significance of excess events is also computed (simple calculation,
-//   no Li-Ma)
-//
-///////////////////////////////////////////////////////////////////////////
-
-
-Float_t degTomm ( Float_t deg ) {
-  return deg / 57.29577951 * 17000 ;
-}
-
-Int_t first_ana ( Char_t *fNameOn = "crab.root" , Char_t *fNameOff = "offcrab.root" , Float_t minsize = 1000 , Float_t minWdeg = 0.00 , Float_t maxWdeg = 0.125 , Float_t minLdeg = 0.0 , Float_t maxLdeg = 0.26 , Float_t minDdeg = 0.2 , Float_t maxDdeg = 0.8 ) {
-
-  TFile *fileOn = new TFile ( fNameOn , "READ" ) ;
-  TFile *fileOff = new TFile ( fNameOff , "READ" ) ;
-
-  TTree *treeOn = (TTree *) fileOn -> Get ( "Parameters" ) ;
-  TTree *treeOff = (TTree *) fileOff -> Get ( "Parameters" ) ;
-
-  TString title ;
-
-  title = "Abs(Alpha) plot ON-Source" ;
-  TH1D *absalphaOn = new TH1D ( "absalphaOn" , title , 9 , 0 , 90 ) ;
-
-  title = "Abs(Alpha) plot ON-Source" ;
-  TH1D *absalphaOff = new TH1D ( "absalphaOff" , title , 9 , 0 , 90 ) ;
-
-  TString scut ;
-  scut = "MHillas.fSize>" ;
-  scut += minsize ;
-  cout << "CUT ON SIZE: " << scut << endl ;
-  TCut Scut = scut ; 
-
-  scut = "" ;
-  scut += degTomm(minWdeg) ;
-  scut += " < MHillas.fWidth && MHillas.fWidth < " ;
-  scut += degTomm(maxWdeg) ;
-  cout << "CUT ON WIDTH: " << scut << endl ;
-  TCut Wcut = scut ; 
-
-  scut = "" ;
-  scut += degTomm(minLdeg) ;
-  scut += " < MHillas.fLength && MHillas.fLength < " ;
-  scut += degTomm(maxLdeg) ;
-  cout << "CUT ON LENGTH: " << scut << endl ;
-  TCut Lcut = scut ; 
-
-  scut = "" ;
-  scut += degTomm(minDdeg) ;
-  scut += " < MHillasSrc.fDist && MHillasSrc.fDist < " ;
-  scut += degTomm(maxDdeg) ;
-  cout << "CUT ON DIST: " << scut << endl ;
-  TCut Dcut = scut ; 
-
-  treeOn -> Draw ( "abs(MHillasSrc.fAlpha)>>absalphaOn" , Scut && Wcut && Lcut && Dcut ) ; 
-  treeOff -> Draw ( "abs(MHillasSrc.fAlpha)>>absalphaOff" , Scut && Wcut && Lcut && Dcut ) ;
-  Double_t alpha = absalphaOn -> Integral ( 4 , 9 ) / absalphaOff -> Integral ( 4 , 9 ) ;
-  Double_t evoff = absalphaOff -> Integral ( 1 , 3 ) ;
-
-  absalphaOff -> Scale ( alpha ) ;
-
-  Double_t fakeMax = absalphaOn -> GetMaximum ( ) ;
-  fakeMax *= 1.1 ;
-
-  Double_t fakeMin = absalphaOn -> GetMinimum ( ) ;
-  fakeMin *= 0.8 ;
-
-  TH2D *fake = new TH2D ( "fake" , "Mrk421 Sample B (ON/OFF) 15/02/2004" , 100 , 0 , 90 , 100 , fakeMin , fakeMax ) ;
-  fake -> GetXaxis ( ) -> SetTitle ( "Parameter Alpha (deg)" ) ;
-  fake -> GetYaxis ( ) -> SetTitle ( "NUmber of Events" ) ;
-  fake -> GetYaxis ( ) -> SetTitleOffset ( 1.3 ) ;
-  fake -> SetStats ( 0 ) ;
-
-  TCanvas *c = new TCanvas ( "c" , "Alpha Canvas" , 800 , 600 ) ;
-  c -> SetGridx ( ) ;
-  c -> SetGridy ( ) ;
-  
-  absalphaOn -> SetMarkerStyle ( 22 ) ;
-  absalphaOn -> SetMarkerSize ( 2.7 ) ;
-  absalphaOff -> SetFillStyle ( 1001 ) ;
-  absalphaOff -> SetFillColor ( 3 ) ;
-
-  fake -> Draw ( ) ;
-  absalphaOff -> Draw ( "SAME" ) ;
-  absalphaOn -> Draw ( "SAMEE1" ) ;
-
-  Double_t evon = absalphaOn -> Integral ( 1 , 3 ) ;
-
-  cout << endl << "EntriesON:" << absalphaOn -> GetEntries ( ) ;
-  cout << endl << "EntriesOFF:" << absalphaOff -> GetEntries ( ) ;
-  cout << endl << "ON:" << evon << " OFF:" << evoff << " EXCESS:" << evon-evoff*alpha << " SIGMA:" << (evon-evoff*alpha)/TMath::Sqrt(evoff)/alpha << endl << endl ;
-  
-}
-
