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-2001
|
---|
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 | #include "TRandom.h" //for gRandom
|
---|
43 |
|
---|
44 | #include "MLog.h"
|
---|
45 | #include "MLogManip.h"
|
---|
46 |
|
---|
47 | #include "MParList.h"
|
---|
48 |
|
---|
49 | #include "MMcEvt.hxx"
|
---|
50 |
|
---|
51 | #include <TSystem.h>
|
---|
52 |
|
---|
53 | ClassImp(MFGeomag);
|
---|
54 |
|
---|
55 | using namespace std;
|
---|
56 |
|
---|
57 | // --------------------------------------------------------------------------
|
---|
58 | //
|
---|
59 | MFGeomag::MFGeomag(const char *cname, const char type, const Int_t val,
|
---|
60 | const char *name, const char *title) : fMcEvt(NULL)
|
---|
61 | {
|
---|
62 | fContName = cname;
|
---|
63 | Init(type, val, name, title);
|
---|
64 | }
|
---|
65 |
|
---|
66 | // --------------------------------------------------------------------------
|
---|
67 | //
|
---|
68 | void MFGeomag::Init(const char type, const Int_t val,
|
---|
69 | const char *name, const char *title)
|
---|
70 |
|
---|
71 | {
|
---|
72 | fName = name ? name : "MFGeomag";
|
---|
73 | fTitle = title ? title : "Filter using geomagnetic field";
|
---|
74 |
|
---|
75 | fGamm_elec = kFALSE; // logical variable, will not take gammas as electrons (default)
|
---|
76 |
|
---|
77 | AddToBranchList(Form("%s.fPartId", (const char*)fContName));
|
---|
78 | }
|
---|
79 | // --------------------------------------------------------------------------
|
---|
80 | //
|
---|
81 | Int_t MFGeomag::PreProcess(MParList *pList)
|
---|
82 | {
|
---|
83 | // reading of tables (variables defined as 'private')
|
---|
84 |
|
---|
85 | Float_t azim [2*1152]; // (these variables not used)
|
---|
86 | Float_t thet [2*1152];
|
---|
87 |
|
---|
88 | ifstream geomagp;
|
---|
89 |
|
---|
90 | TString filename = gSystem->Getenv("MARSSYS");
|
---|
91 | filename += "/mfilter/gcplus.txt";
|
---|
92 |
|
---|
93 | geomagp.open(filename);
|
---|
94 | if (!geomagp) {
|
---|
95 | *fLog << err <<" ERROR gcplus.txt file not found by Geomag"<<endl;
|
---|
96 | return kFALSE;
|
---|
97 | }
|
---|
98 | for (int i=0; i<1152; i++)
|
---|
99 | {
|
---|
100 | geomagp >>azim[i]>>thet[i];
|
---|
101 | geomagp >>fRigMin[i]>>fRigMax[i]>>fProb[i];
|
---|
102 | }
|
---|
103 | *fLog << inf << endl;
|
---|
104 | *fLog << "gcplus.txt read, first line: ";
|
---|
105 | *fLog << Form ("FRigMin=%8f fRigMax=%8f fProb=%8f",
|
---|
106 | fRigMin[0], fRigMax[0], fProb[0]) << endl;
|
---|
107 | geomagp.close();
|
---|
108 | geomagp.clear();
|
---|
109 |
|
---|
110 | ifstream geomagm;
|
---|
111 |
|
---|
112 | filename = gSystem->Getenv("MARSSYS");
|
---|
113 | filename += "/mfilter/gcminus.txt";
|
---|
114 |
|
---|
115 | geomagm.open(filename);
|
---|
116 | if (!geomagm) {
|
---|
117 | *fLog << err <<" ERROR gcminus.txt file not found by Geomag"<<endl;
|
---|
118 | return kFALSE;
|
---|
119 | }
|
---|
120 | for (int i=0; i<1152; i++)
|
---|
121 | {
|
---|
122 | geomagm >>azim[i+1152]>>thet[i+1152];
|
---|
123 | geomagm >>fRigMin[i+1152]>>fRigMax[i+1152]>>fProb[i+1152];
|
---|
124 | }
|
---|
125 | *fLog << "gcminus.txt read, first line: ";
|
---|
126 | *fLog << Form ("fRigMin=%8f fRigMax=%8f fProb=%8f",
|
---|
127 | fRigMin[1152], fRigMax[1152], fProb[1152]) << endl;
|
---|
128 | geomagm.close();
|
---|
129 | geomagm.clear();
|
---|
130 | //
|
---|
131 | if (fMcEvt)
|
---|
132 | return kTRUE;
|
---|
133 |
|
---|
134 | fMcEvt = (MMcEvt*)pList->FindObject("MMcEvt");
|
---|
135 | if (fMcEvt)
|
---|
136 | return kTRUE;
|
---|
137 |
|
---|
138 | *fLog << err << dbginf << " [MMcEvt] not found... aborting." << endl;
|
---|
139 | return kFALSE;
|
---|
140 | }
|
---|
141 | // --------------------------------------------------------------------------
|
---|
142 | //
|
---|
143 | void MFGeomag::SetGammElec()
|
---|
144 | {
|
---|
145 | fGamm_elec = kTRUE; // logical variable, will take gammas as electrons
|
---|
146 | *fLog <<" MFGeomag called to treat gammas as electrons" << endl;
|
---|
147 | return;
|
---|
148 | }
|
---|
149 |
|
---|
150 | // --------------------------------------------------------------------------
|
---|
151 | //
|
---|
152 | Int_t MFGeomag::Process()
|
---|
153 | {
|
---|
154 | const Float_t en = fMcEvt->GetEnergy(); // for rigidity (set P = E)
|
---|
155 | float rig = en;
|
---|
156 | const Float_t az = fMcEvt->GetTelescopePhi(); // charge theta phi are entries in table
|
---|
157 | const Float_t th = fMcEvt->GetTelescopeTheta();
|
---|
158 |
|
---|
159 | Int_t indadd=0; //first part of table (positive particles)
|
---|
160 | switch (fMcEvt->GetPartId())
|
---|
161 | {
|
---|
162 | case kGAMMA:
|
---|
163 | if (!fGamm_elec) //accept gammas if not set to electrons
|
---|
164 | {
|
---|
165 | fResult = 0;
|
---|
166 | return kTRUE;
|
---|
167 | }
|
---|
168 | indadd = 1152; //second part of table (negative particles)
|
---|
169 | break;
|
---|
170 |
|
---|
171 | case kHELIUM:
|
---|
172 | rig /= 2; //double charge
|
---|
173 | break;
|
---|
174 |
|
---|
175 | case kPROTON: //protons
|
---|
176 | break;
|
---|
177 |
|
---|
178 | case kELECTRON: //electrons
|
---|
179 | indadd = 1152; //second part of table (negative particles)
|
---|
180 | break;
|
---|
181 |
|
---|
182 | case kPOSITRON: //positrons
|
---|
183 | break;
|
---|
184 |
|
---|
185 | default:
|
---|
186 | Int_t id = fMcEvt->GetPartId();
|
---|
187 | *fLog << err <<" Unknown Monte Carlo Particle Id#: "<< id << endl;
|
---|
188 | return kFALSE;
|
---|
189 | }
|
---|
190 | // here is the cut for charged particles using the table
|
---|
191 | int it=(int)(th*11.459156); // table steps are in 5 deg = 1/11.459 rads
|
---|
192 | int ia=(int)(az*11.459156);
|
---|
193 | ia = (ia+36) % 72; // azimuth definitions differ by 180 deg
|
---|
194 | float r1=fRigMin[72*it+ia+indadd];
|
---|
195 | if (rig<=r1) {
|
---|
196 | fResult=1; // reject
|
---|
197 | return kTRUE;
|
---|
198 | }
|
---|
199 | float r2=fRigMax[72*it+ia+indadd];
|
---|
200 | if (rig>=r2) {
|
---|
201 | fResult=0; // accept
|
---|
202 | return kTRUE;
|
---|
203 | }
|
---|
204 | float R = gRandom->Rndm(0); //accept if above intermediate threshold
|
---|
205 | float pr=fProb [72*it+ia+indadd];
|
---|
206 | fResult = 0;
|
---|
207 | if (rig < 0.5/pr*R*(r2-r1) + r1) fResult = 1; // pretty good approximation
|
---|
208 | return kTRUE;
|
---|
209 | }
|
---|