source: tags/Mars-V0.8/macros/trigrate.C

Last change on this file was 1543, checked in by tbretz, 22 years ago
*** empty log message ***
File size: 5.0 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
32Int_t GetNSBEvents(TString name, Float_t *BgR)
33{
34 Int_t numnsbevents;
35
36 TChain events("Events");
37 events.Add(name);
38
39 TH1F h("h","",5,.5,5.5);
40
41 for (Int_t i = from; i <= to; i++)
42 {
43 TString plot = "MMcTrig;";
44 plot+=i;
45 plot+=".fNumFirstLevel>>h";
46
47 if (i == 0)
48 plot = "MMcTrig.fNumFirstLevel>>h";
49
50 events.Draw(plot,"", "goff");
51
52 // Get total number of L1 triggers from histogram:
53 BgR[dim>0? i-1: 0] = h.Integral()*h.GetMean();
54
55 numnsbevents = (Float_t) h.GetEntries();
56 }
57
58 return numnsbevents;
59}
60
61
62void trigrate(int dim=0, char *filename = "data/camera.root",
63 char *nsbfile = NULL)
64{
65 // The dim parameter has three possible values:
66 // dim : = 0 -> root file with 1 trigger condition.
67 // > 0 -> number of trigger condition to be analised
68 // in multi conditon file.
69 // < 0 -> selects the -dim trigger condition.
70 //
71 // first we have to create our empty lists
72 //
73 MParList parlist;
74 MTaskList tasklist;
75
76 //
77 // Setup the parameter list.
78 // - we do not need to create any other container. All of them
79 // are created automatically without loss - we don't have to
80 // access them-
81 //
82 // - we need to create MHMcRate only. The other containers
83 // are created automatically without loss - we don't have to
84 // access them-
85 // - MHMcRate must be created by us because we need the pointer
86 // to it and if it would get created automatically it would also be
87 // deleted automatically
88 // - Actually, depending on using a single trigger option MonteCarlo
89 // file or a multyple trigger option, a MHMcRate or an array of
90 // MHMcRate are needed.
91 //
92 parlist.AddToList(&tasklist);
93
94 //
95 // You don't have to add the MHMcRate container here by hand.
96 // But if you want to print or display these containers later on
97 // it is necessary (Rem: No printing or displaying is done in this
98 // macro yet)
99 //
100 UInt_t from = dim>0 ? 1 : -dim;
101 UInt_t to = dim>0 ? dim : -dim;
102
103 Int_t num = to-from+1;
104
105 TObjArray hists(MParList::CreateObjList("MHMcRate", from, to));
106 hists.SetOwner();
107
108 //
109 // Check if the list really contains the right number of histograms
110 //
111 if (hists.GetEntriesFast() != num)
112 return;
113
114 //
115 // Add the histograms to the paramater list.
116 //
117 parlist.AddToList(&hists);
118
119 //
120 // Setup out tasks:
121 // - First we have to read the events
122 // - Then we can calculate rates, for what the number of
123 // triggered showers from a empty reflector file for the
124 // analised trigger conditions should be set (BgR[])
125 //
126 MReadTree reader("Events", filename);
127 tasklist.AddToList(&reader);
128
129 // Now we have to build the BgR array, containing the number
130 // of triggers (may be more than 1 trigger/event!) from the
131 // numnsbevents simulated in the nsbfile (3rd input parameter).
132 // If no nsbfile is supplied, we assume no triggers from NSB
133
134 Float_t* BgR = new Float_t[num];
135 memset(BgR, 0, num*sizeof(Float_t));
136
137 Float_t numnsbevents = 5.e4; // some default value.
138 if (nsbfile)
139 numnsbevents = GetNSBEvents(nsbfile, BgR);
140
141 cout << "Number of Trigger conditions: " << num << endl;
142
143 MMcTriggerRateCalc rate(dim, kPROTON, BgR, numnsbevents);
144 tasklist.AddToList(&rate);
145
146 //
147 // set up the loop for the processing
148 //
149 MEvtLoop magic;
150 magic.SetParList(&parlist);
151
152 //
153 // Start to loop over all events
154 //
155 MProgressBar bar;
156 magic.SetProgressBar(&bar);
157 if (!magic.Eventloop())
158 return;
159
160 delete BgR;
161
162 hists.Print();
163}
Note: See TracBrowser for help on using the repository browser.