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): Thomas Bretz 07/2001 <mailto:tbretz@uni-sw.gwdg.de>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2001
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | /////////////////////////////////////////////////////////////////////////////
|
---|
26 | // //
|
---|
27 | // MFParticleId //
|
---|
28 | // //
|
---|
29 | // A filter to choose between different particle types, identified by //
|
---|
30 | // their monte carlo particle type. For a list of idetifiers see //
|
---|
31 | // mbase/MAGIC.h //
|
---|
32 | // //
|
---|
33 | /////////////////////////////////////////////////////////////////////////////
|
---|
34 | #include "MFParticleId.h"
|
---|
35 |
|
---|
36 | #include <fstream.h>
|
---|
37 |
|
---|
38 | #include "MLog.h"
|
---|
39 | #include "MLogManip.h"
|
---|
40 |
|
---|
41 | #include "MParList.h"
|
---|
42 |
|
---|
43 | #include "MMcEvt.hxx"
|
---|
44 |
|
---|
45 | ClassImp(MFParticleId);
|
---|
46 |
|
---|
47 |
|
---|
48 | // --------------------------------------------------------------------------
|
---|
49 | //
|
---|
50 | MFParticleId::MFParticleId(const char *cname, const char type, const Int_t val,
|
---|
51 | const char *name, const char *title) : fMcEvt(NULL)
|
---|
52 | {
|
---|
53 | fContName = cname;
|
---|
54 | Init(type, val, name, title);
|
---|
55 | }
|
---|
56 |
|
---|
57 | // --------------------------------------------------------------------------
|
---|
58 | //
|
---|
59 | MFParticleId::MFParticleId(MMcEvt *mcevt, const char type, const Int_t val,
|
---|
60 | const char *name, const char *title) : fMcEvt(mcevt)
|
---|
61 | {
|
---|
62 | Init(type, val, name, title);
|
---|
63 | }
|
---|
64 |
|
---|
65 | // --------------------------------------------------------------------------
|
---|
66 | //
|
---|
67 | void MFParticleId::Init(const char type, const Int_t val,
|
---|
68 | const char *name, const char *title)
|
---|
69 | {
|
---|
70 | fName = name ? name : "MFParticleId";
|
---|
71 | fTitle = title ? title : "Filter using monte carlo particle id";
|
---|
72 |
|
---|
73 | fFilterType = (type=='=' ? kEEqual : kENotEqual);
|
---|
74 |
|
---|
75 | if (type!='=' && type!='!')
|
---|
76 | *fLog << warn << dbginf << "Warning: Neither '=' nor '!' specified... using '>'." << endl;
|
---|
77 |
|
---|
78 | fValue = val;
|
---|
79 |
|
---|
80 | AddToBranchList(Form("%s.fPartId", (const char*)fContName));
|
---|
81 | }
|
---|
82 |
|
---|
83 | // --------------------------------------------------------------------------
|
---|
84 | //
|
---|
85 | Bool_t MFParticleId::IsExpressionTrue() const
|
---|
86 | {
|
---|
87 | return fResult;
|
---|
88 | }
|
---|
89 |
|
---|
90 | // --------------------------------------------------------------------------
|
---|
91 | //
|
---|
92 | Bool_t MFParticleId::PreProcess(MParList *pList)
|
---|
93 | {
|
---|
94 | if (fMcEvt)
|
---|
95 | return kTRUE;
|
---|
96 |
|
---|
97 | fMcEvt = (MMcEvt*)pList->FindObject(fContName);
|
---|
98 | if (fMcEvt)
|
---|
99 | return kTRUE;
|
---|
100 |
|
---|
101 | *fLog << err << dbginf << fContName << " [MMcEvt] not found... aborting." << endl;
|
---|
102 | return kFALSE;
|
---|
103 | }
|
---|
104 |
|
---|
105 | // --------------------------------------------------------------------------
|
---|
106 | //
|
---|
107 | Bool_t MFParticleId::Process()
|
---|
108 | {
|
---|
109 | const Int_t id = fMcEvt->GetPartId();
|
---|
110 |
|
---|
111 | switch (fFilterType)
|
---|
112 | {
|
---|
113 | case kEEqual:
|
---|
114 | fResult = (id == fValue);
|
---|
115 | return kTRUE;
|
---|
116 | case kENotEqual:
|
---|
117 | fResult = (id != fValue);
|
---|
118 | return kTRUE;
|
---|
119 | }
|
---|
120 |
|
---|
121 | *fLog << err << dbginf << "Operation unknown..." << endl;
|
---|
122 | return kFALSE;
|
---|
123 | }
|
---|
124 |
|
---|
125 | void MFParticleId::StreamPrimitive(ofstream &out) const
|
---|
126 | {
|
---|
127 | if (fMcEvt)
|
---|
128 | fMcEvt->SavePrimitive(out);
|
---|
129 |
|
---|
130 | out << " MFParticleId " << GetUniqueName() << "(";
|
---|
131 |
|
---|
132 | if (fMcEvt)
|
---|
133 | out << "&" << fMcEvt->GetUniqueName();
|
---|
134 | else
|
---|
135 | out << "\"" << fContName << "\"";
|
---|
136 |
|
---|
137 | out << ", '" << (fFilterType==kEEqual?"=":"!") << "', ";
|
---|
138 |
|
---|
139 | switch (fValue)
|
---|
140 | {
|
---|
141 | case kGAMMA:
|
---|
142 | out << "kGAMMA";
|
---|
143 | break;
|
---|
144 | case kPROTON:
|
---|
145 | out << "kPROTON";
|
---|
146 | break;
|
---|
147 | case kHELIUM:
|
---|
148 | out << "kHELIUM";
|
---|
149 | break;
|
---|
150 | case kOXYGEN:
|
---|
151 | out << "kOXYGEN";
|
---|
152 | break;
|
---|
153 | case kIRON:
|
---|
154 | out << "kIRON";
|
---|
155 | break;
|
---|
156 | default:
|
---|
157 | out << fValue;
|
---|
158 | }
|
---|
159 | out << ");" << endl;
|
---|
160 | }
|
---|