Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 1786)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 1787)
@@ -6,4 +6,7 @@
       - Fixed mistake when analysing camera files containing all events 
         (including non-triggers): fShowers was always zero.
+
+    * macros/trigrate.C
+      - Added some explanations. Style improvements in function GetNSBEvents.
 
  2003/02/22: Wolfgang Wittek
Index: /trunk/MagicSoft/Mars/macros/trigrate.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/trigrate.C	(revision 1786)
+++ /trunk/MagicSoft/Mars/macros/trigrate.C	(revision 1787)
@@ -23,6 +23,11 @@
 !   Added one optional input parameter: a camera .root file containing
 !   pure NSB events. One such file is generated running the camera over an
-!   "empty" reflector file, with the NSB option on, and MINPHOT=0. The nsb
-!   files must contain the same trigger conditions as the proton file.
+!   "empty" reflector file, with the NSB option on, and asking the camera
+!   program (see camera program manual) to do the simulation even if no 
+!   photoelectron from the shower arrives at the camera. One also needs to
+!   write to the output file all the events, both triggered and untriggered
+!   (see again camera manual). These nsb camera files must contain the same 
+!   trigger conditions as the proton file.
+!
 !   If no nsb file is supplied, the macro will assume no triggers from 
 !   pure NSB fluctuations.
@@ -30,29 +35,41 @@
 \* ======================================================================== */
 
-Int_t GetNSBEvents(TString name, Float_t *BgR)
+Float_t GetNSBEvents(TString name, Float_t *BgR, int dim)
 {
     Int_t numnsbevents;
 
-    TChain events("Events");
-    events.Add(name);
+    TFile bgfile(name);
+    TTree *events = (TTree*) bgfile.Get("Events");
 
     TH1F h("h","",5,.5,5.5);
 
-    for (Int_t i = from; i <= to; i++)
+    UInt_t from = dim>0 ?   1 : -dim;
+    UInt_t to   = dim>0 ? dim : -dim;
+
+    for (UInt_t i = from; i <= to; i++)
     {
-        TString plot = "MMcTrig;";
-        plot+=i;
-        plot+=".fNumFirstLevel>>h";
+      TString cond("MMcTrig;");
+      cond += i;
+      cond += ".";
+      TBranch *b = events->GetBranch(cond);
+      MMcTrig *mctrig;
+      b->SetAddress(&mctrig);
 
-        if (i == 0)
-            plot = "MMcTrig.fNumFirstLevel>>h";
+      Int_t tottrig = 0.;
+      
+      UInt_t imax = b->GetEntries();
 
-        events.Draw(plot,"", "goff");
+      for (UInt_t iev = 0; iev < imax; iev++)
+	{	
+	  b->GetEvent(iev);
+	  tottrig += mctrig->GetFirstLevel();
+	}
+      // Set total number of L1 triggers:
+      BgR[dim>0? i-1: 0] = (Float_t) tottrig;
 
-        // Get total number of L1 triggers from histogram:
-        BgR[dim>0? i-1: 0] = h.Integral()*h.GetMean();
+      numnsbevents = (Float_t) imax;
+    }
 
-        numnsbevents = (Float_t) h.GetEntries();
-    }
+    cout << endl<<endl << numnsbevents << " " << BgR[0] << endl<<endl<<endl;
 
     return numnsbevents;
@@ -138,5 +155,5 @@
     Float_t numnsbevents = 5.e4; // some default value.
     if (nsbfile)
-        numnsbevents = GetNSBEvents(nsbfile, BgR);
+      numnsbevents = GetNSBEvents(nsbfile, BgR, dim);
 
     cout << "Number of Trigger conditions: " << num << endl;
