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): R.K.Bock 11/2003 <mailto:rkb@mppmu.mpg.de>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | /////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MFGeomag
|
---|
28 | //
|
---|
29 | // A filter to reject Monte Carlo events based on phi/theta/charge of the
|
---|
30 | // incident particle. Uses tables calculated by Adrian Biland, which contain
|
---|
31 | // three parameters, used with rigidity (= particle momentum / charge) :
|
---|
32 | // rig < min_rig: reject unconditionally
|
---|
33 | // rig > max_rig: accept unconditionally
|
---|
34 | // rig in between: reject it with 'probability'
|
---|
35 | // the two tables, for + and - rigidity, are stored in ASCII form in mfilter/
|
---|
36 | //
|
---|
37 | /////////////////////////////////////////////////////////////////////////////
|
---|
38 |
|
---|
39 | #include "MFGeomag.h"
|
---|
40 |
|
---|
41 | #include <fstream> //for ifstream
|
---|
42 |
|
---|
43 | #include <TRandom.h> //for gRandom
|
---|
44 | #include <TSystem.h>
|
---|
45 |
|
---|
46 | #include "MLog.h"
|
---|
47 | #include "MLogManip.h"
|
---|
48 |
|
---|
49 | #include "MParList.h"
|
---|
50 |
|
---|
51 | #include "MMcEvt.hxx"
|
---|
52 |
|
---|
53 | ClassImp(MFGeomag);
|
---|
54 |
|
---|
55 | using namespace std;
|
---|
56 |
|
---|
57 | // --------------------------------------------------------------------------
|
---|
58 | //
|
---|
59 | MFGeomag::MFGeomag(const char *name, const char *title) : fMcEvt(NULL)
|
---|
60 | {
|
---|
61 | fName = name ? name : "MFGeomag";
|
---|
62 | fTitle = title ? title : "Filter using geomagnetic field";
|
---|
63 |
|
---|
64 | fGammaElectron = kFALSE; // logical variable, will not take gammas as electrons (default)
|
---|
65 |
|
---|
66 | AddToBranchList("MMcEvt.fPartId");
|
---|
67 | }
|
---|
68 |
|
---|
69 | // --------------------------------------------------------------------------
|
---|
70 | //
|
---|
71 | Int_t MFGeomag::PreProcess(MParList *pList)
|
---|
72 | {
|
---|
73 | // reading of tables (variables defined as 'private')
|
---|
74 | TString marssys(gSystem->Getenv("MARSSYS"));
|
---|
75 | if (!marssys.IsNull() && !marssys.EndsWith("/"))
|
---|
76 | marssys += "/";
|
---|
77 |
|
---|
78 | //
|
---|
79 | // Read gcminus.txt
|
---|
80 | //
|
---|
81 | TString filename(marssys);
|
---|
82 | filename += "mfilter/gcplus.txt";
|
---|
83 |
|
---|
84 | ifstream geomagp(filename);
|
---|
85 |
|
---|
86 | if (!geomagp)
|
---|
87 | {
|
---|
88 | *fLog << err << "ERROR - file " << filename << " not found." << endl;
|
---|
89 | return kFALSE;
|
---|
90 | }
|
---|
91 | for (int i=0; i<1152; i++)
|
---|
92 | {
|
---|
93 | Float_t dummy;
|
---|
94 | geomagp >> dummy >> dummy >> fRigMin[i] >> fRigMax[i] >> fProb[i];
|
---|
95 | }
|
---|
96 | *fLog << inf << endl;
|
---|
97 | *fLog << "gcplus.txt - first line: ";
|
---|
98 | *fLog << Form ("FRigMin=%8f fRigMax=%8f fProb=%8f",
|
---|
99 | fRigMin[0], fRigMax[0], fProb[0]) << endl;
|
---|
100 |
|
---|
101 | //
|
---|
102 | // Read gcminus.txt
|
---|
103 | //
|
---|
104 | filename = marssys;
|
---|
105 | filename += "mfilter/gcminus.txt";
|
---|
106 |
|
---|
107 | ifstream geomagm(filename);
|
---|
108 | if (!geomagm)
|
---|
109 | {
|
---|
110 | *fLog << err << "ERROR - file " << filename << " not found." << endl;
|
---|
111 | return kFALSE;
|
---|
112 | }
|
---|
113 | for (int i=1152; i<2304; i++)
|
---|
114 | {
|
---|
115 | Float_t dummy;
|
---|
116 | geomagm >> dummy >> dummy >> fRigMin[i] >> fRigMax[i] >> fProb[i];
|
---|
117 | }
|
---|
118 | *fLog << "gcminus.txt - first line: ";
|
---|
119 | *fLog << Form ("fRigMin=%8f fRigMax=%8f fProb=%8f",
|
---|
120 | fRigMin[1152], fRigMax[1152], fProb[1152]) << endl;
|
---|
121 |
|
---|
122 | //
|
---|
123 | if (fMcEvt)
|
---|
124 | return kTRUE;
|
---|
125 |
|
---|
126 | fMcEvt = (MMcEvt*)pList->FindObject("MMcEvt");
|
---|
127 | if (!fMcEvt)
|
---|
128 | {
|
---|
129 | *fLog << err << "MMcEvt not found... aborting." << endl;
|
---|
130 | return kFALSE;
|
---|
131 | }
|
---|
132 |
|
---|
133 | return kTRUE;
|
---|
134 | }
|
---|
135 | // --------------------------------------------------------------------------
|
---|
136 | //
|
---|
137 | void MFGeomag::SetGammElec()
|
---|
138 | {
|
---|
139 | fGammaElectron = kTRUE; // logical variable, will take gammas as electrons
|
---|
140 | *fLog <<" MFGeomag called to treat gammas as electrons" << endl;
|
---|
141 | return;
|
---|
142 | }
|
---|
143 |
|
---|
144 | // --------------------------------------------------------------------------
|
---|
145 | //
|
---|
146 | Int_t MFGeomag::Process()
|
---|
147 | {
|
---|
148 | const Float_t en = fMcEvt->GetEnergy(); // for rigidity (set P = E)
|
---|
149 | float rig = en;
|
---|
150 | const Float_t az = fMcEvt->GetTelescopePhi(); // charge theta phi are entries in table
|
---|
151 | const Float_t th = fMcEvt->GetTelescopeTheta();
|
---|
152 |
|
---|
153 | Int_t indadd=0; //first part of table (positive particles)
|
---|
154 | switch (fMcEvt->GetPartId())
|
---|
155 | {
|
---|
156 | case kGAMMA:
|
---|
157 | if (!fGammaElectron) //accept gammas if not set to electrons
|
---|
158 | {
|
---|
159 | fResult = kFALSE;
|
---|
160 | return kTRUE;
|
---|
161 | }
|
---|
162 | indadd = 1152; //second part of table (negative particles)
|
---|
163 | break;
|
---|
164 |
|
---|
165 | case kHELIUM:
|
---|
166 | rig /= 2; //double charge
|
---|
167 | break;
|
---|
168 |
|
---|
169 | case kPROTON: //protons
|
---|
170 | break;
|
---|
171 |
|
---|
172 | case kELECTRON: //electrons
|
---|
173 | indadd = 1152; //second part of table (negative particles)
|
---|
174 | break;
|
---|
175 |
|
---|
176 | case kPOSITRON: //positrons
|
---|
177 | break;
|
---|
178 |
|
---|
179 | default:
|
---|
180 | *fLog << err << " Unknown Monte Carlo Particle Id#: "<< fMcEvt->GetPartId() << endl;
|
---|
181 | return kFALSE;
|
---|
182 | }
|
---|
183 | // here is the cut for charged particles using the table
|
---|
184 | int it=(int)(th*11.459156); // table steps are in 5 deg = 1/11.459 rads
|
---|
185 | int ia=(int)(az*11.459156);
|
---|
186 | ia = (ia+36) % 72; // azimuth definitions differ by 180 deg
|
---|
187 |
|
---|
188 | float r1=fRigMin[72*it+ia+indadd];
|
---|
189 | if (rig<=r1) {
|
---|
190 | fResult=kTRUE; // reject
|
---|
191 | return kTRUE;
|
---|
192 | }
|
---|
193 |
|
---|
194 | float r2=fRigMax[72*it+ia+indadd];
|
---|
195 | if (rig>=r2) {
|
---|
196 | fResult=kFALSE; // accept
|
---|
197 | return kTRUE;
|
---|
198 | }
|
---|
199 |
|
---|
200 | float R = gRandom->Rndm(0); // accept if above intermediate threshold
|
---|
201 | float pr=fProb[72*it+ia+indadd];
|
---|
202 | fResult = kFALSE;
|
---|
203 |
|
---|
204 | if (rig < 0.5/pr*R*(r2-r1) + r1)
|
---|
205 | fResult = kTRUE; // pretty good approximation
|
---|
206 |
|
---|
207 | return kTRUE;
|
---|
208 | }
|
---|