source: trunk/MagicSoft/Mars/mfilter/MFParticleId.cc@ 2371

Last change on this file since 2371 was 2206, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 4.6 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): 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>
37
38#include "MLog.h"
39#include "MLogManip.h"
40
41#include "MParList.h"
42
43#include "MMcEvt.hxx"
44
45ClassImp(MFParticleId);
46
47using namespace std;
48
49// --------------------------------------------------------------------------
50//
51MFParticleId::MFParticleId(const char *cname, const char type, const Int_t val,
52 const char *name, const char *title) : fMcEvt(NULL)
53{
54 fContName = cname;
55 Init(type, val, name, title);
56}
57
58// --------------------------------------------------------------------------
59//
60MFParticleId::MFParticleId(MMcEvt *mcevt, const char type, const Int_t val,
61 const char *name, const char *title) : fMcEvt(mcevt)
62{
63 Init(type, val, name, title);
64}
65
66// --------------------------------------------------------------------------
67//
68void MFParticleId::Init(const char type, const Int_t val,
69 const char *name, const char *title)
70{
71 fName = name ? name : "MFParticleId";
72 fTitle = title ? title : "Filter using monte carlo particle id";
73
74 fFilterType = (type=='=' ? kEEqual : kENotEqual);
75
76 if (type!='=' && type!='!')
77 *fLog << warn << dbginf << "Warning: Neither '=' nor '!' specified... using '>'." << endl;
78
79 fValue = val;
80
81 AddToBranchList(Form("%s.fPartId", (const char*)fContName));
82}
83
84// --------------------------------------------------------------------------
85//
86Bool_t MFParticleId::IsExpressionTrue() const
87{
88 return fResult;
89}
90
91// --------------------------------------------------------------------------
92//
93Int_t MFParticleId::PreProcess(MParList *pList)
94{
95 if (fMcEvt)
96 return kTRUE;
97
98 fMcEvt = (MMcEvt*)pList->FindObject(fContName);
99 if (fMcEvt)
100 return kTRUE;
101
102 *fLog << err << dbginf << fContName << " [MMcEvt] not found... aborting." << endl;
103 return kFALSE;
104}
105
106// --------------------------------------------------------------------------
107//
108Int_t MFParticleId::Process()
109{
110 const Int_t id = fMcEvt->GetPartId();
111
112 switch (fFilterType)
113 {
114 case kEEqual:
115 fResult = (id == fValue);
116 return kTRUE;
117 case kENotEqual:
118 fResult = (id != fValue);
119 return kTRUE;
120 }
121
122 *fLog << err << dbginf << "Operation unknown..." << endl;
123 return kFALSE;
124}
125
126void MFParticleId::StreamPrimitive(ofstream &out) const
127{
128 if (fMcEvt)
129 fMcEvt->SavePrimitive(out);
130
131 out << " MFParticleId " << GetUniqueName() << "(";
132
133 if (fMcEvt)
134 out << "&" << fMcEvt->GetUniqueName();
135 else
136 out << "\"" << fContName << "\"";
137
138 out << ", '" << (fFilterType==kEEqual?"=":"!") << "', ";
139
140 switch (fValue)
141 {
142 case kGAMMA:
143 out << "kGAMMA";
144 break;
145 case kPROTON:
146 out << "kPROTON";
147 break;
148 case kHELIUM:
149 out << "kHELIUM";
150 break;
151 case kOXYGEN:
152 out << "kOXYGEN";
153 break;
154 case kIRON:
155 out << "kIRON";
156 break;
157 default:
158 out << fValue;
159 }
160 out << ");" << endl;
161}
Note: See TracBrowser for help on using the repository browser.