source: trunk/MagicSoft/Mars/mfilter/MFGeomag.cc@ 2790

Last change on this file since 2790 was 2779, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 6.4 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): 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
53ClassImp(MFGeomag);
54
55using namespace std;
56
57// --------------------------------------------------------------------------
58//
59MFGeomag::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//
68void 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//
81Int_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 TString filename = gSystem->Getenv("MARSSYS");
89 filename += "/mfilter/gcplus.txt";
90
91 ifstream geomagp(filename);
92
93 if (!geomagp) {
94 *fLog << err <<" ERROR gcplus.txt file not found by Geomag"<<endl;
95 return kFALSE;
96 }
97 for (int i=0; i<1152; i++)
98 {
99 geomagp >>azim[i]>>thet[i];
100 geomagp >>fRigMin[i]>>fRigMax[i]>>fProb[i];
101 }
102 *fLog << inf << endl;
103 *fLog << "gcplus.txt read, first line: ";
104 *fLog << Form ("FRigMin=%8f fRigMax=%8f fProb=%8f",
105 fRigMin[0], fRigMax[0], fProb[0]) << endl;
106
107 filename = gSystem->Getenv("MARSSYS");
108 filename += "/mfilter/gcminus.txt";
109
110 ifstream geomagm(filename);
111 if (!geomagm) {
112 *fLog << err <<" ERROR gcminus.txt file not found by Geomag"<<endl;
113 return kFALSE;
114 }
115 for (int i=0; i<1152; i++)
116 {
117 geomagm >>azim[i+1152]>>thet[i+1152];
118 geomagm >>fRigMin[i+1152]>>fRigMax[i+1152]>>fProb[i+1152];
119 }
120 *fLog << "gcminus.txt read, first line: ";
121 *fLog << Form ("fRigMin=%8f fRigMax=%8f fProb=%8f",
122 fRigMin[1152], fRigMax[1152], fProb[1152]) << endl;
123
124 //
125 if (fMcEvt)
126 return kTRUE;
127
128 fMcEvt = (MMcEvt*)pList->FindObject("MMcEvt");
129 if (!fMcEvt)
130 {
131 *fLog << err << dbginf << " [MMcEvt] not found... aborting." << endl;
132 return kFALSE;
133 }
134
135 return kTRUE;
136}
137// --------------------------------------------------------------------------
138//
139void MFGeomag::SetGammElec()
140{
141 fGamm_elec = kTRUE; // logical variable, will take gammas as electrons
142 *fLog <<" MFGeomag called to treat gammas as electrons" << endl;
143 return;
144}
145
146// --------------------------------------------------------------------------
147//
148Int_t MFGeomag::Process()
149 {
150 const Float_t en = fMcEvt->GetEnergy(); // for rigidity (set P = E)
151 float 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 (!fGamm_elec) //accept gammas if not set to electrons
160 {
161 fResult = 0;
162 return kTRUE;
163 }
164 indadd = 1152; //second part of table (negative particles)
165 break;
166
167 case kHELIUM:
168 rig /= 2; //double charge
169 break;
170
171 case kPROTON: //protons
172 break;
173
174 case kELECTRON: //electrons
175 indadd = 1152; //second part of table (negative particles)
176 break;
177
178 case kPOSITRON: //positrons
179 break;
180
181 default:
182 Int_t id = fMcEvt->GetPartId();
183 *fLog << err <<" Unknown Monte Carlo Particle Id#: "<< id << endl;
184 return kFALSE;
185 }
186 // here is the cut for charged particles using the table
187 int it=(int)(th*11.459156); // table steps are in 5 deg = 1/11.459 rads
188 int ia=(int)(az*11.459156);
189 ia = (ia+36) % 72; // azimuth definitions differ by 180 deg
190 float r1=fRigMin[72*it+ia+indadd];
191 if (rig<=r1) {
192 fResult=1; // reject
193 return kTRUE;
194 }
195 float r2=fRigMax[72*it+ia+indadd];
196 if (rig>=r2) {
197 fResult=0; // accept
198 return kTRUE;
199 }
200 float R = gRandom->Rndm(0); //accept if above intermediate threshold
201 float pr=fProb [72*it+ia+indadd];
202 fResult = 0;
203 if (rig < 0.5/pr*R*(r2-r1) + r1) fResult = 1; // pretty good approximation
204 return kTRUE;
205 }
Note: See TracBrowser for help on using the repository browser.