source: trunk/modules/MadGraphShowerPartonSelector.cc@ 5

Last change on this file since 5 was 2, checked in by Pavel Demin, 16 years ago

first commit

File size: 7.0 KB
Line 
1
2#include "modules/MadGraphShowerPartonSelector.h"
3
4
5#include "ExRootAnalysis/ExRootResult.h"
6#include "ExRootAnalysis/ExRootClasses.h"
7
8#include "ExRootAnalysis/ExRootFilter.h"
9#include "ExRootAnalysis/ExRootClassifier.h"
10
11#include "ExRootAnalysis/ExRootFactory.h"
12#include "ExRootAnalysis/ExRootCandidate.h"
13
14#include "TMath.h"
15#include "TString.h"
16#include "TLorentzVector.h"
17#include "TClonesArray.h"
18
19#include <iostream>
20#include <set>
21
22using namespace std;
23
24
25//------------------------------------------------------------------------------
26
27class MadGraphShowerPartonClassifier : public ExRootClassifier
28{
29public:
30
31 MadGraphShowerPartonClassifier(TClonesArray *branch);
32
33 Int_t GetCategory(TObject *object);
34
35 void SetEtaMax(Double_t eta);
36 void InsertParticleID(Int_t pid);
37 void InsertAncestorID(Int_t pid);
38 void SetHadronizationInfo(Bool_t info);
39
40private:
41
42 Bool_t hasBadAncestor(ExRootGenParticle *object);
43
44 Double_t fEtaMax;
45
46 TClonesArray *fBranchParticle;
47
48 set< Int_t > fParticleIDSet;
49 set< Int_t > fAncestorIDSet;
50};
51
52//------------------------------------------------------------------------------
53
54MadGraphShowerPartonClassifier::MadGraphShowerPartonClassifier(TClonesArray *branch) :
55 fBranchParticle(branch)
56{
57}
58
59//------------------------------------------------------------------------------
60
61void MadGraphShowerPartonClassifier::SetEtaMax(Double_t eta)
62{
63 fEtaMax = eta;
64}
65
66//------------------------------------------------------------------------------
67
68void MadGraphShowerPartonClassifier::InsertParticleID(Int_t pid)
69{
70 fParticleIDSet.insert(pid);
71}
72
73//------------------------------------------------------------------------------
74
75void MadGraphShowerPartonClassifier::InsertAncestorID(Int_t pid)
76{
77 fAncestorIDSet.insert(pid);
78}
79
80//------------------------------------------------------------------------------
81
82Bool_t MadGraphShowerPartonClassifier::hasBadAncestor(ExRootGenParticle *object)
83{
84 const int kMaxAncestors = 10;
85 Int_t i, pidAbs;
86 ExRootGenParticle *particle = object;
87 set< Int_t >::const_iterator itAncestorIDSet;
88
89 for(i = 0; i < kMaxAncestors && particle->Status != 3; ++i)
90 {
91 if(particle->M1 < 0) return kFALSE;
92
93 particle = static_cast<ExRootGenParticle*>(fBranchParticle->At(particle->M1));
94 }
95
96 if(particle->PID == 21) return kFALSE;
97
98 pidAbs = TMath::Abs(particle->PID);
99
100 // skip particles with pid included in list
101 itAncestorIDSet = fAncestorIDSet.find(pidAbs);
102
103 if(itAncestorIDSet != fAncestorIDSet.end()) return kTRUE;
104 if(particle->M2 > -1) return kFALSE;
105
106 for(i = 0; i < kMaxAncestors; ++i)
107 {
108 if(particle->M1 < 0) return kFALSE;
109
110 if(particle->PID == 21) return kFALSE;
111
112 particle = static_cast<ExRootGenParticle*>(fBranchParticle->At(particle->M1));
113
114 pidAbs = TMath::Abs(particle->PID);
115
116 // skip particles with pid included in list
117 itAncestorIDSet = fAncestorIDSet.find(pidAbs);
118
119 if(itAncestorIDSet != fAncestorIDSet.end()) return kTRUE;
120 if(particle->M2 > -1) return kFALSE;
121 }
122
123 return kFALSE;
124}
125
126//------------------------------------------------------------------------------
127
128Int_t MadGraphShowerPartonClassifier::GetCategory(TObject *object)
129{
130 ExRootGenParticle *particle = static_cast<ExRootGenParticle*>(object);
131 ExRootGenParticle *daughter;
132
133 set< Int_t >::const_iterator itParticleIDSet;
134
135 Int_t pidAbs = TMath::Abs(particle->PID);
136 Double_t etaAbs = TMath::Abs(particle->Eta);
137
138 // skip beam particles and initial state partons
139 if(particle->M1 < 2) return -1;
140
141 // skip particles with pid not included in list
142 itParticleIDSet = fParticleIDSet.find(pidAbs);
143
144 if(itParticleIDSet == fParticleIDSet.end() || etaAbs > fEtaMax) return -1;
145
146 // with hadronization
147 if(particle->Status == 2)
148 {
149 // skip particles if they do not form a string
150 if(particle->D1 > -1)
151 {
152 daughter = static_cast<ExRootGenParticle*>(fBranchParticle->At(particle->D1));
153 if(daughter->PID != 92) return -1;
154 }
155 }
156 // without hadronization
157 else if(particle->Status != 1) return -1;
158
159 if(hasBadAncestor(particle)) return -1;
160
161 return 0;
162}
163
164//------------------------------------------------------------------------------
165
166MadGraphShowerPartonSelector::MadGraphShowerPartonSelector() :
167 fFilter(0), fClassifier(0)
168{
169}
170
171//------------------------------------------------------------------------------
172
173MadGraphShowerPartonSelector::~MadGraphShowerPartonSelector()
174{
175}
176
177//------------------------------------------------------------------------------
178
179void MadGraphShowerPartonSelector::Init()
180{
181 ExRootConfParam param;
182
183 Int_t i, pid, sizeParam;
184
185 // import ROOT tree branch
186
187 fBranchParticle = UseBranch("GenParticle");
188
189 // create classifier and filter
190
191 fClassifier = new MadGraphShowerPartonClassifier(fBranchParticle);
192 fFilter = new ExRootFilter(fBranchParticle);
193
194 fEtaMax = GetDouble("EtaMax", 5.0);
195 fClassifier->SetEtaMax(fEtaMax);
196
197 // read particle IDs from configuration file and setup classifier
198
199 param = GetParam("PartonIDs");
200 sizeParam = param.GetSize();
201
202 for(i = 0; i < sizeParam; ++i)
203 {
204 pid = param[i].GetInt();
205 fClassifier->InsertParticleID(pid);
206 }
207
208 // read ancestor IDs from configuration file and setup classifier
209
210 param = GetParam("ExcludedAncestorIDs");
211 sizeParam = param.GetSize();
212
213 for(i = 0; i < sizeParam; ++i)
214 {
215 pid = param[i].GetInt();
216 fClassifier->InsertAncestorID(pid);
217 }
218
219 // create output arrays
220
221 fOutputArray = ExportArray("candidates");
222
223}
224
225//------------------------------------------------------------------------------
226
227void MadGraphShowerPartonSelector::Finish()
228{
229 if(fFilter) delete fFilter;
230 if(fClassifier) delete fClassifier;
231}
232
233//------------------------------------------------------------------------------
234
235void MadGraphShowerPartonSelector::Process()
236{
237 TObjArray *array = 0;
238 ExRootGenParticle *particle = 0;
239 ExRootCandidate *candidate = 0;
240 ExRootFactory *factory = GetFactory();
241
242 TLorentzVector momentum;
243
244 fFilter->Reset();
245 array = fFilter->GetSubArray(fClassifier, 0);
246
247 if(array == 0) return;
248
249 TIter itArray(array);
250
251 while(particle = static_cast<ExRootGenParticle*>(itArray.Next()))
252 {
253 momentum.SetPxPyPzE(particle->Px, particle->Py, particle->Pz, particle->E);
254
255 candidate = factory->NewCandidate();
256
257 candidate->SetP4(momentum);
258 candidate->SetType(particle->PID);
259
260 fOutputArray->Add(candidate);
261 }
262
263/*
264 cout << "==============================" << endl;
265 Int_t indexParticle = -1;
266 itArray.Reset();
267 while(particle = static_cast<ExRootGenParticle*>(itArray.Next()))
268 {
269 ++indexParticle;
270 cout << "--->\t" << particle->Status << "\t" << particle->PID << "\t";
271 cout << particle->M1 << "\t" << particle->M2 << "\t";
272 cout << particle->Px << "\t" << particle->Py << "\t" << particle->Pz << endl;
273 }
274*/
275}
276
277//------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.