Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 1375)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 1376)
@@ -1,3 +1,15 @@
                                                                   -*-*- END -*-*-
+ 2002/07/04: Abelardo Moralejo
+
+   * mmontecarlo/MMcTriggerRateCalc.h,cc:
+     - Now the dimension of fTrigger is set dinamically, to allow
+       the processing of files with an arbitrarily large number of 
+       trigger conditions inside.
+   * macros/trigrate.C:
+     - Adapted the macro to changes above, and added a third argument:
+       the name of a file containing pure NSB events from which the
+       accidental trigger rate is calculated. Previously, this had to 
+       be introduced in the macro by hand by the user.
+
  2002/06/14: Thomas Bretz
 
Index: /trunk/MagicSoft/Mars/macros/trigrate.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/trigrate.C	(revision 1375)
+++ /trunk/MagicSoft/Mars/macros/trigrate.C	(revision 1376)
@@ -20,11 +20,19 @@
 !   Copyright: MAGIC Software Development, 2000-2001
 !
+!   Modified 4/7/2002, Abelardo Moralejo:
+!   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.
+!   If no nsb file is supplied, the macro will assume no triggers from 
+!   pure NSB fluctuations.
 !
 \* ======================================================================== */
 
 
-void trigrate(int dim=0, char *filename = "data/camera.root" )
+void trigrate(int dim=0, char *filename = "data/camera.root", 
+	      char *nsbfile = NULL)
 {
-    // This macro has two input parameter:
+    // The dim parameter has three possible values:
     // dim : = 0 -> root file with 1 trigger condition.
     //       > 0 -> number of trigger condition to be analised 
@@ -90,8 +98,54 @@
     tasklist.AddToList(&reader);
 
-    Float_t BgR[10]={0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+ 
+    // Now we have to build the BgR array, containing the number 
+    // of triggers (may be more than 1 trigger/event!) from the
+    // total_nsb_events simulated in the nsbfile (3rd input parameter).
+    // If no nsbfile is supplied, we assume no triggers from NSB
+
+    Float_t total_nsb_events = 5.e4; // some default value.
+
+    Float_t* BgR = new float[num];
+    for(Int_t i = 0; i < num; i++)
+      BgR[i] = 0.;
+
+    //    Float_t* BgR = new float[36];
+    //    for(Int_t i = 0; i < 36; i++)
+    //      BgR[i] = 0.;
+
+    if (nsbfile)
+      {
+	nsb_events = new TChain("Events");
+	nsb_events->Add(nsbfile);
+
+	//	nsb_events = new TFile(nsbfile);
+	//	nsb_events->cd();
+
+	h = new TH1F("h","",5,.5,5.5);
+
+	Char_t plot[256];
+	for (Int_t i = from; i <= to; i++)
+	  {
+	    // For each trigger condition (i)...
+	    // histogram Number of L1 triggers:
+	    sprintf(plot, "MMcTrig;%d.fNumFirstLevel>>h", i);
+	    nsb_events->Draw(plot,"", "goff");
+	    // Get total number of L1 triggers from histogram:
+	    if (dim > 0)
+	      BgR[i-1] = h->Integral()*h->GetMean();
+	    else
+	      BgR[0] = h->Integral()*h->GetMean();
+
+	    total_nsb_events = (Float_t) h->GetEntries();
+	  }
+	h->Delete();
+	nsb_events->Delete();
+	//	nsb_headers = new TChain("RunHeaders");
+	//	nsb_headers->Add(nsbfile);
+      }
+
     cout << "Number of Trigger conditions: " << num << endl;
 
-    MMcTriggerRateCalc rate(dim, 14, BgR, 100000);
+    MMcTriggerRateCalc rate(dim, kPROTON, BgR, total_nsb_events);
     tasklist.AddToList(&rate);
 
Index: /trunk/MagicSoft/Mars/mmontecarlo/MMcTriggerRateCalc.cc
===================================================================
--- /trunk/MagicSoft/Mars/mmontecarlo/MMcTriggerRateCalc.cc	(revision 1375)
+++ /trunk/MagicSoft/Mars/mmontecarlo/MMcTriggerRateCalc.cc	(revision 1376)
@@ -21,4 +21,8 @@
 !   Copyright: MAGIC Software Development, 2000-2001
 !
+!   Modified 4/7/2002 Abelardo Moralejo: now the dimension of fTrigger is
+!    set dinamically, to allow an arbitrary large number of trigger 
+!    conditions to be processed.
+!
 !
 \* ======================================================================== */
@@ -47,7 +51,4 @@
     fMcRate = NULL;
 
-    for (int i=0;i<10;i++)
-        fTrigger[i] = dim&&trigbg ? trigbg[i] : 0;
-
     fShowers = 0;
     fAnalShow = simbg;
@@ -59,4 +60,9 @@
 
     fNum = fLast-fFirst+1;
+
+    fTrigger = new float[fNum];
+
+    for (UInt_t i=0;i<fNum;i++)
+        fTrigger[i] = dim&&trigbg ? trigbg[i] : 0;
 
     AddToBranchList("MMcEvt.fImpact");
Index: /trunk/MagicSoft/Mars/mmontecarlo/MMcTriggerRateCalc.h
===================================================================
--- /trunk/MagicSoft/Mars/mmontecarlo/MMcTriggerRateCalc.h	(revision 1375)
+++ /trunk/MagicSoft/Mars/mmontecarlo/MMcTriggerRateCalc.h	(revision 1376)
@@ -26,5 +26,6 @@
     UInt_t     fLast;
 
-    Float_t    fTrigger[10];   // Number of triggered showers
+    Float_t*    fTrigger;   // Number of triggered showers
+
     Float_t    fShowers;       // Number of simulated showers
     Float_t    fAnalShow;      // Number of analysed showers
