source: releases/Mars.2014.05.26/mfilter/MFGeomag.cc@ 18029

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