source: trunk/MagicSoft/Mars/macros/trigrate.C@ 1379

Last change on this file since 1379 was 1379, checked in by bigongia, 22 years ago
*** empty log message ***
File size: 4.7 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Thomas Bretz 12/2000 (tbretz@uni-sw.gwdg.de)
19!
20! Copyright: MAGIC Software Development, 2000-2001
21!
22! Modified 4/7/2002, Abelardo Moralejo:
23! Added one optional input parameter: a camera .root file containing
24! pure NSB events. One such file is generated running the camera over an
25! "empty" reflector file, with the NSB option on, and MINPHOT=0. The nsb
26! files must contain the same trigger conditions as the proton file.
27! If no nsb file is supplied, the macro will assume no triggers from
28! pure NSB fluctuations.
29!
30\* ======================================================================== */
31
32void trigrate(int dim=0, char *filename = "data/camera.root",
33 char *nsbfile = NULL)
34{
35 // The dim parameter has three possible values:
36 // dim : = 0 -> root file with 1 trigger condition.
37 // > 0 -> number of trigger condition to be analised
38 // in multi conditon file.
39 // < 0 -> selects the -dim trigger condition.
40 //
41 // first we have to create our empty lists
42 //
43 MParList parlist;
44 MTaskList tasklist;
45
46 //
47 // Setup the parameter list.
48 // - we do not need to create any other container. All of them
49 // are created automatically without loss - we don't have to
50 // access them-
51 //
52 // - we need to create MHMcRate only. The other containers
53 // are created automatically without loss - we don't have to
54 // access them-
55 // - MHMcRate must be created by us because we need the pointer
56 // to it and if it would get created automatically it would also be
57 // deleted automatically
58 // - Actually, depending on using a single trigger option MonteCarlo
59 // file or a multyple trigger option, a MHMcRate or an array of
60 // MHMcRate are needed.
61 //
62 parlist.AddToList(&tasklist);
63
64 //
65 // You don't have to add the MHMcRate container here by hand.
66 // But if you want to print or display these containers later on
67 // it is necessary (Rem: No printing or displaying is done in this
68 // macro yet)
69 //
70 UInt_t from = dim>0 ? 1 : -dim;
71 UInt_t to = dim>0 ? dim : -dim;
72
73 Int_t num = to-from+1;
74
75 TObjArray hists(MParList::CreateObjList("MHMcRate", from, to));
76 hists.SetOwner();
77
78 //
79 // Check if the list really contains the right number of histograms
80 //
81 if (hists.GetEntriesFast() != num)
82 return;
83
84 //
85 // Add the histograms to the paramater list.
86 //
87 parlist.AddToList(&hists);
88
89 //
90 // Setup out tasks:
91 // - First we have to read the events
92 // - Then we can calculate rates, for what the number of
93 // triggered showers from a empty reflector file for the
94 // analised trigger conditions should be set (BgR[])
95 //
96 MReadTree reader("Events", filename);
97 tasklist.AddToList(&reader);
98
99
100 // Now we have to build the BgR array, containing the number
101 // of triggers (may be more than 1 trigger/event!) from the
102 // numnsbevents simulated in the nsbfile (3rd input parameter).
103 // If no nsbfile is supplied, we assume no triggers from NSB
104
105 Float_t numnsbevents = 5.e4; // some default value.
106
107 Float_t* BgR = new float[num];
108 for(Int_t i = 0; i < num; i++)
109 BgR[i] = 0.;
110
111 if (nsbfile)
112 {
113 TChain nsb_events("Events");
114 nsb_events.Add(nsbfile);
115
116 TH1F h("h","",5,.5,5.5);
117
118 for (Int_t i = from; i <= to; i++)
119 {
120 TString plot = "MMcTrig;";
121 plot+=i;
122 plot+=".fNumFirstLevel>>h";
123
124 nsb_events.Draw(plot,"", "goff");
125 // Get total number of L1 triggers from histogram:
126 BgR[dim>0? i-1: 0] = h.Integral()*h.GetMean();
127
128 numnsbevents = (Float_t) h.GetEntries();
129 }
130 }
131
132 cout << "Number of Trigger conditions: " << num << endl;
133
134 MMcTriggerRateCalc rate(dim, kPROTON, BgR, numnsbevents);
135 tasklist.AddToList(&rate);
136
137 //
138 // set up the loop for the processing
139 //
140 MEvtLoop magic;
141 magic.SetParList(&parlist);
142
143 //
144 // Start to loop over all events
145 //
146 if (!magic.Eventloop())
147 return;
148
149 hists.Print();
150}
Note: See TracBrowser for help on using the repository browser.