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): Antonio Stamerra 02/2003 <mailto:antonio.stamerra@pi.infn.it>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2003
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | /////////////////////////////////////////////////////////////////////////////
|
---|
26 | // //
|
---|
27 | // MFEnergySlope //
|
---|
28 | // //
|
---|
29 | // A filter to select MC events (generated with a energy slope MCSlope) //
|
---|
30 | // with a different energy slope NewSlope set by the user. //
|
---|
31 | // //
|
---|
32 | // The new slope is set by the user with SetSlope(). //
|
---|
33 | // Only negative slopes are admitted; positive ones are internally //
|
---|
34 | // converted. //
|
---|
35 | // Events are selected following the new energy power slope, and the //
|
---|
36 | // sample is normalized to the number of events at: //
|
---|
37 | // 1. McMaxEnergy, if abs(NewSlope) < abs(McSlope); //
|
---|
38 | // 2. McMinEnergy, if abs(NewSlope) > abs(McSlope); //
|
---|
39 | // Mc{Max,Min}Energy are set with SetMcMinEnergy() and SetMcMaxEnergy(); //
|
---|
40 | // with GeV values. //
|
---|
41 | // Default values are the min/max energy of the MC sample. //
|
---|
42 | // //
|
---|
43 | // With this filter the statistics of the MC sample is reduced. //
|
---|
44 | // camera ver.0.6 and reflector ver.0.6 are required to fetch //
|
---|
45 | // the correct MC information //
|
---|
46 | // //
|
---|
47 | /////////////////////////////////////////////////////////////////////////////
|
---|
48 | #include "MFEnergySlope.h"
|
---|
49 |
|
---|
50 | #include <fstream.h>
|
---|
51 | #include <TRandom.h>
|
---|
52 |
|
---|
53 | #include "MParList.h"
|
---|
54 |
|
---|
55 | #include "MLog.h"
|
---|
56 | #include "MLogManip.h"
|
---|
57 |
|
---|
58 | #include "MMcEvt.hxx"
|
---|
59 | #include "MMcCorsikaRunHeader.h"
|
---|
60 |
|
---|
61 | ClassImp(MFEnergySlope);
|
---|
62 |
|
---|
63 | // --------------------------------------------------------------------------
|
---|
64 | //
|
---|
65 | // Constructor
|
---|
66 | //
|
---|
67 | MFEnergySlope::MFEnergySlope(const char *name, const char *title):
|
---|
68 | fNumSelectedEvts(0), fNewSlope(-1), fMcMinEnergy(-1.), fMcMaxEnergy(-1.)
|
---|
69 | {
|
---|
70 | // fContName = cname;
|
---|
71 | fName = name ? name : "MFEnergySlope";
|
---|
72 | fTitle = title ? title : "Filter to select energy with given slope";
|
---|
73 | }
|
---|
74 |
|
---|
75 | // --------------------------------------------------------------------------
|
---|
76 | //
|
---|
77 | // Preprocess
|
---|
78 | //
|
---|
79 | // MC slope and min/max energy are read
|
---|
80 | // Normalization factor is computed
|
---|
81 | //
|
---|
82 | Bool_t MFEnergySlope::PreProcess(MParList *pList)
|
---|
83 | {
|
---|
84 |
|
---|
85 | MMcCorsikaRunHeader *runheader = (MMcCorsikaRunHeader*)pList->FindObject("MMcCorsikaRunHeader");
|
---|
86 |
|
---|
87 | if (!runheader)
|
---|
88 | {
|
---|
89 | *fLog << err << dbginf << fName << " [MMcCorsikaRunHeader] not found... aborting." << endl;
|
---|
90 | return kFALSE;
|
---|
91 | }
|
---|
92 | //
|
---|
93 | // Read info from the MC sample (it must be generated with
|
---|
94 | // reflector ver.0.6 and camera ver. 0.6)
|
---|
95 | //
|
---|
96 | fMcSlope = runheader->GetSlopeSpec();
|
---|
97 | if (fMcMinEnergy<0)
|
---|
98 | fMcMinEnergy = runheader->GetELowLim();
|
---|
99 | if (fMcMinEnergy<0)
|
---|
100 | fMcMaxEnergy = runheader->GetEUppLim();
|
---|
101 |
|
---|
102 | *fLog << inf;
|
---|
103 | *fLog << "MFEnergySlope::PreProcess: fetched MC info:" << endl;
|
---|
104 | *fLog << " E Slope: " << fMcSlope << endl;
|
---|
105 | *fLog << " E Min: " << fMcMinEnergy << endl;
|
---|
106 | *fLog << " E Max: " << fMcMaxEnergy << endl;
|
---|
107 | *fLog << " New E Slope: " << fNewSlope << endl;
|
---|
108 |
|
---|
109 | // Slope is used with positive values in the code
|
---|
110 | if (fNewSlope < 0)
|
---|
111 | fNewSlope *= -1;
|
---|
112 | if (fMcSlope < 0)
|
---|
113 | fMcSlope *= -1;
|
---|
114 |
|
---|
115 |
|
---|
116 | // Set normalization on energy
|
---|
117 | fN0 = pow(fNewSlope>fMcSlope?fMcMinEnergy:fMcMaxEnergy,fNewSlope-fMcSlope);
|
---|
118 |
|
---|
119 | *fLog << "Normalization factor:" <<fN0 << endl;
|
---|
120 |
|
---|
121 | //---
|
---|
122 | fEvt = (MMcEvt*)pList->FindObject("MMcEvt");
|
---|
123 | if (!fEvt)
|
---|
124 | {
|
---|
125 | *fLog << err << dbginf << fName << " [MMcEvt] not found... aborting." << endl;
|
---|
126 | return kFALSE;
|
---|
127 | }
|
---|
128 |
|
---|
129 | return kTRUE;
|
---|
130 | }
|
---|
131 |
|
---|
132 | // --------------------------------------------------------------------------
|
---|
133 | //
|
---|
134 | // Select events randomly according to the MC ("old") and required ("new")
|
---|
135 | // energy slope.
|
---|
136 | // Old E slope is fMcSlope
|
---|
137 | // New E slope is set by the user (fval; fNewSlope)
|
---|
138 | // If old and new energy slope are the same skip the selection.
|
---|
139 | // The MC energy slope and lower and upper limits are taken from the
|
---|
140 | // run header (requires reflector ver.>0.6 and camera ver.>0.6)
|
---|
141 | //
|
---|
142 | Bool_t MFEnergySlope::Process()
|
---|
143 | {
|
---|
144 | fResult = kTRUE;
|
---|
145 |
|
---|
146 | // Energy slopes are the same: skip it
|
---|
147 | if (fNewSlope == fMcSlope)
|
---|
148 | return kTRUE;
|
---|
149 |
|
---|
150 | // The value of the normalized spectrum is compared with a
|
---|
151 | // random value in [0,1];
|
---|
152 | // if the latter is higher the event is accepted
|
---|
153 | const Float_t energy = fEvt->GetEnergy();
|
---|
154 |
|
---|
155 | /*
|
---|
156 | //
|
---|
157 | // If energy bounds different from MC ones are selected, then
|
---|
158 | // events outside these bounds are rejected, as their slope has
|
---|
159 | // not been changed.
|
---|
160 | //
|
---|
161 | if (energy > fMcMaxEnergy || energy < fMcMinEnergy)
|
---|
162 | {
|
---|
163 | fResult = kFALSE;
|
---|
164 | return kTRUE;
|
---|
165 | }
|
---|
166 | */
|
---|
167 |
|
---|
168 | const Float_t Nexp = fN0 * pow(energy,fMcSlope-fNewSlope);
|
---|
169 | const Float_t Nrnd = gRandom->Uniform();
|
---|
170 |
|
---|
171 | fResult = Nexp > Nrnd;
|
---|
172 |
|
---|
173 | if (!fResult)
|
---|
174 | return kTRUE;
|
---|
175 |
|
---|
176 | fNumSelectedEvts++;
|
---|
177 | return kTRUE;
|
---|
178 | }
|
---|
179 |
|
---|