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

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