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 | fResult = kFALSE;
|
---|
149 |
|
---|
150 | const Float_t en = fMcEvt->GetEnergy(); // for rigidity (set P = E)
|
---|
151 | Float_t rig = en;
|
---|
152 | const Float_t az = fMcEvt->GetTelescopePhi(); // charge theta phi are entries in table
|
---|
153 | const Float_t th = fMcEvt->GetTelescopeTheta();
|
---|
154 |
|
---|
155 | Int_t indadd=0; //first part of table (positive particles)
|
---|
156 | switch (fMcEvt->GetPartId())
|
---|
157 | {
|
---|
158 | case kGAMMA:
|
---|
159 | if (!fGammaElectron) //accept gammas if not set to electrons
|
---|
160 | return kTRUE;
|
---|
161 | indadd = 1152; //second part of table (negative particles)
|
---|
162 | break;
|
---|
163 |
|
---|
164 | case kHELIUM:
|
---|
165 | rig /= 2; //double charge
|
---|
166 | break;
|
---|
167 |
|
---|
168 | case kPROTON: //protons
|
---|
169 | case kPOSITRON: //positrons
|
---|
170 | break;
|
---|
171 |
|
---|
172 | case kELECTRON: //electrons
|
---|
173 | indadd = 1152; //second part of table (negative particles)
|
---|
174 | break;
|
---|
175 |
|
---|
176 | default:
|
---|
177 | *fLog << err << " Unknown Monte Carlo Particle Id#: "<< fMcEvt->GetPartId() << endl;
|
---|
178 | return kFALSE;
|
---|
179 | }
|
---|
180 |
|
---|
181 | // here is the cut for charged particles using the table
|
---|
182 |
|
---|
183 | int it=(int)(th*11.459156); // table steps are in 5 deg = 1/11.459 rads
|
---|
184 | int ia=(int)(az*11.459156);
|
---|
185 |
|
---|
186 | ia = (ia+36) % 72; // azimuth definitions differ by 180 deg
|
---|
187 |
|
---|
188 | const Float_t r1=fRigMin[72*it+ia+indadd];
|
---|
189 | if (rig<=r1)
|
---|
190 | {
|
---|
191 | fResult=kTRUE; // reject
|
---|
192 | return kTRUE;
|
---|
193 | }
|
---|
194 |
|
---|
195 | const Float_t r2=fRigMax[72*it+ia+indadd];
|
---|
196 | if (rig>=r2)
|
---|
197 | return kTRUE; // accept
|
---|
198 |
|
---|
199 | const Float_t pr=fProb[72*it+ia+indadd];
|
---|
200 |
|
---|
201 | // accept if above intermediate threshold
|
---|
202 | const Float_t rnd = (r2-r1)/2 * gRandom->Rndm(0);
|
---|
203 |
|
---|
204 | if ((rig-r1)*pr < rnd)
|
---|
205 | fResult = kTRUE; // pretty good approximation
|
---|
206 |
|
---|
207 | return kTRUE;
|
---|
208 | }
|
---|