1 |
|
---|
2 | #include "modules/MadGraphPartonSelector.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 |
|
---|
22 | using namespace std;
|
---|
23 |
|
---|
24 | //------------------------------------------------------------------------------
|
---|
25 |
|
---|
26 | class MadGraphPartonClassifier : public ExRootClassifier
|
---|
27 | {
|
---|
28 | public:
|
---|
29 |
|
---|
30 | MadGraphPartonClassifier(TClonesArray *branch);
|
---|
31 |
|
---|
32 | Int_t GetCategory(TObject *object);
|
---|
33 |
|
---|
34 | void InsertParticleID(Int_t pid);
|
---|
35 | void InsertExclAncestorID(Int_t pid);
|
---|
36 | void InsertInclAncestorID(Int_t pid);
|
---|
37 |
|
---|
38 | private:
|
---|
39 |
|
---|
40 | Bool_t hasBadAncestor(ExRootGenParticle *object);
|
---|
41 | Bool_t hasGoodAncestor(ExRootGenParticle *object);
|
---|
42 |
|
---|
43 | TClonesArray *fBranchParticle;
|
---|
44 |
|
---|
45 | set< Int_t > fParticleIDSet;
|
---|
46 | set< Int_t > fExclAncestorIDSet;
|
---|
47 | set< Int_t > fInclAncestorIDSet;
|
---|
48 | };
|
---|
49 |
|
---|
50 | //------------------------------------------------------------------------------
|
---|
51 |
|
---|
52 | MadGraphPartonClassifier::MadGraphPartonClassifier(TClonesArray *branch) :
|
---|
53 | fBranchParticle(branch)
|
---|
54 | {
|
---|
55 | }
|
---|
56 |
|
---|
57 | //------------------------------------------------------------------------------
|
---|
58 |
|
---|
59 | void MadGraphPartonClassifier::InsertParticleID(Int_t pid)
|
---|
60 | {
|
---|
61 | fParticleIDSet.insert(pid);
|
---|
62 | }
|
---|
63 |
|
---|
64 | //------------------------------------------------------------------------------
|
---|
65 |
|
---|
66 | void MadGraphPartonClassifier::InsertExclAncestorID(Int_t pid)
|
---|
67 | {
|
---|
68 | fExclAncestorIDSet.insert(pid);
|
---|
69 | }
|
---|
70 |
|
---|
71 | //------------------------------------------------------------------------------
|
---|
72 |
|
---|
73 | void MadGraphPartonClassifier::InsertInclAncestorID(Int_t pid)
|
---|
74 | {
|
---|
75 | fInclAncestorIDSet.insert(pid);
|
---|
76 | }
|
---|
77 |
|
---|
78 | //------------------------------------------------------------------------------
|
---|
79 |
|
---|
80 | Bool_t MadGraphPartonClassifier::hasBadAncestor(ExRootGenParticle *object)
|
---|
81 | {
|
---|
82 | const int kMaxAncestors = 10;
|
---|
83 | Int_t i, pidAbs;
|
---|
84 | ExRootGenParticle *particle = object;
|
---|
85 | set< Int_t >::const_iterator itAncestorIDSet;
|
---|
86 | set< Int_t >::const_iterator itParticleIDSet;
|
---|
87 |
|
---|
88 | // keep all particles if there is no pid in the list
|
---|
89 | if(fExclAncestorIDSet.empty())
|
---|
90 | {
|
---|
91 | return kFALSE;
|
---|
92 | }
|
---|
93 |
|
---|
94 | for(i = 0; i < kMaxAncestors; ++i)
|
---|
95 | {
|
---|
96 |
|
---|
97 | if(particle->M1 < 0 || particle->M2 > -1) return kFALSE;
|
---|
98 |
|
---|
99 | // if(particle->PID == 21) return kFALSE;
|
---|
100 |
|
---|
101 | particle = static_cast<ExRootGenParticle*>(fBranchParticle->At(particle->M1));
|
---|
102 |
|
---|
103 | if(particle->PID == 21) return kFALSE;
|
---|
104 |
|
---|
105 | pidAbs = TMath::Abs(particle->PID);
|
---|
106 |
|
---|
107 | // skip particles with pid included in list
|
---|
108 | itAncestorIDSet = fExclAncestorIDSet.find(pidAbs);
|
---|
109 |
|
---|
110 | if(itAncestorIDSet != fExclAncestorIDSet.end()) return kTRUE;
|
---|
111 | }
|
---|
112 |
|
---|
113 | return kFALSE;
|
---|
114 | }
|
---|
115 |
|
---|
116 | //------------------------------------------------------------------------------
|
---|
117 |
|
---|
118 | Bool_t MadGraphPartonClassifier::hasGoodAncestor(ExRootGenParticle *object)
|
---|
119 | {
|
---|
120 | const int kMaxAncestors = 10;
|
---|
121 | Int_t i, pidAbs;
|
---|
122 | ExRootGenParticle *particle = object;
|
---|
123 | set< Int_t >::const_iterator itAncestorIDSet;
|
---|
124 | set< Int_t >::const_iterator itParticleIDSet;
|
---|
125 |
|
---|
126 | // keep all particles if there is no pid in the list
|
---|
127 | if(fInclAncestorIDSet.empty())
|
---|
128 | {
|
---|
129 | return kTRUE;
|
---|
130 | }
|
---|
131 |
|
---|
132 | for(i = 0; i < kMaxAncestors; ++i)
|
---|
133 | {
|
---|
134 |
|
---|
135 | if(particle->M1 < 0 || particle->M2 > -1) return kFALSE;
|
---|
136 |
|
---|
137 | // if(particle->PID == 21) return kFALSE;
|
---|
138 |
|
---|
139 | particle = static_cast<ExRootGenParticle*>(fBranchParticle->At(particle->M1));
|
---|
140 |
|
---|
141 | if(particle->PID == 21) return kFALSE;
|
---|
142 |
|
---|
143 | pidAbs = TMath::Abs(particle->PID);
|
---|
144 |
|
---|
145 | // keep particles with pid included in list
|
---|
146 | itAncestorIDSet = fInclAncestorIDSet.find(pidAbs);
|
---|
147 |
|
---|
148 | if(itAncestorIDSet != fInclAncestorIDSet.end()) return kTRUE;
|
---|
149 | }
|
---|
150 |
|
---|
151 | return kFALSE;
|
---|
152 | }
|
---|
153 |
|
---|
154 | //------------------------------------------------------------------------------
|
---|
155 |
|
---|
156 | Int_t MadGraphPartonClassifier::GetCategory(TObject *object)
|
---|
157 | {
|
---|
158 | ExRootGenParticle *particle = static_cast<ExRootGenParticle*>(object);
|
---|
159 | ExRootGenParticle *beam[2], *mother, *daughter;
|
---|
160 |
|
---|
161 | Int_t i, beamPid[2], beamPidAbs[2];
|
---|
162 |
|
---|
163 | set< Int_t >::const_iterator itParticleIDSet;
|
---|
164 |
|
---|
165 | Int_t pidAbs = TMath::Abs(particle->PID);
|
---|
166 |
|
---|
167 | // skip beam particles and initial state partons
|
---|
168 | if(particle->M1 < 2) return -1;
|
---|
169 |
|
---|
170 | // skip particles with status != 3
|
---|
171 | if(particle->Status != 3) return -1;
|
---|
172 |
|
---|
173 | // skip particles with pid not included in list
|
---|
174 | itParticleIDSet = fParticleIDSet.find(pidAbs);
|
---|
175 |
|
---|
176 | if(itParticleIDSet == fParticleIDSet.end()) return -1;
|
---|
177 |
|
---|
178 | for(i = 0; i < 2; ++i)
|
---|
179 | {
|
---|
180 | beam[i] = static_cast<ExRootGenParticle*>(fBranchParticle->At(i));
|
---|
181 | beamPid[i] = beam[i]->PID;
|
---|
182 | beamPidAbs[i] = TMath::Abs(beamPid[i]);
|
---|
183 | }
|
---|
184 |
|
---|
185 | if(beamPidAbs[0] == 11 && beamPidAbs[1] == 11 && beamPid[0] == -beamPid[1])
|
---|
186 | {
|
---|
187 | mother = static_cast<ExRootGenParticle*>(fBranchParticle->At(particle->M1));
|
---|
188 | if( (mother->PID == 22 || mother->PID == 23)
|
---|
189 | && mother->M1 == 0 && mother->M2 == 1) return -1;
|
---|
190 | }
|
---|
191 |
|
---|
192 | // skip particles if they have daughters with status == 3
|
---|
193 | if(particle->D1 > -1)
|
---|
194 | {
|
---|
195 | daughter = static_cast<ExRootGenParticle*>(fBranchParticle->At(particle->D1));
|
---|
196 | if(daughter->Status == 3) return -1;
|
---|
197 | }
|
---|
198 |
|
---|
199 | if(hasBadAncestor(particle)) return -1;
|
---|
200 |
|
---|
201 | if(!hasGoodAncestor(particle)) return -1;
|
---|
202 |
|
---|
203 | return 0;
|
---|
204 | }
|
---|
205 |
|
---|
206 | //------------------------------------------------------------------------------
|
---|
207 |
|
---|
208 | MadGraphPartonSelector::MadGraphPartonSelector() :
|
---|
209 | fFilter(0), fClassifier(0)
|
---|
210 | {
|
---|
211 | }
|
---|
212 |
|
---|
213 | //------------------------------------------------------------------------------
|
---|
214 |
|
---|
215 | MadGraphPartonSelector::~MadGraphPartonSelector()
|
---|
216 | {
|
---|
217 | }
|
---|
218 |
|
---|
219 | //------------------------------------------------------------------------------
|
---|
220 |
|
---|
221 | void MadGraphPartonSelector::Init()
|
---|
222 | {
|
---|
223 | ExRootConfParam param;
|
---|
224 |
|
---|
225 | Int_t i, pid, sizeParam;
|
---|
226 |
|
---|
227 | // import ROOT tree branch
|
---|
228 |
|
---|
229 | fBranchParticle = UseBranch("GenParticle");
|
---|
230 |
|
---|
231 | // create classifier and filter
|
---|
232 |
|
---|
233 | fClassifier = new MadGraphPartonClassifier(fBranchParticle);
|
---|
234 | fFilter = new ExRootFilter(fBranchParticle);
|
---|
235 |
|
---|
236 | // read particle IDs from configuration file and setup classifier
|
---|
237 |
|
---|
238 | param = GetParam("PartonIDs");
|
---|
239 | sizeParam = param.GetSize();
|
---|
240 |
|
---|
241 | for(i = 0; i < sizeParam; ++i)
|
---|
242 | {
|
---|
243 | pid = param[i].GetInt();
|
---|
244 | fClassifier->InsertParticleID(pid);
|
---|
245 | }
|
---|
246 |
|
---|
247 | // read ancestor IDs from configuration file and setup classifier
|
---|
248 |
|
---|
249 | param = GetParam("ExcludedAncestorIDs");
|
---|
250 | sizeParam = param.GetSize();
|
---|
251 |
|
---|
252 | for(i = 0; i < sizeParam; ++i)
|
---|
253 | {
|
---|
254 | pid = param[i].GetInt();
|
---|
255 | fClassifier->InsertExclAncestorID(pid);
|
---|
256 | }
|
---|
257 |
|
---|
258 | // read ancestor IDs from configuration file and setup classifier
|
---|
259 |
|
---|
260 | param = GetParam("IncludedAncestorIDs");
|
---|
261 | sizeParam = param.GetSize();
|
---|
262 |
|
---|
263 | for(i = 0; i < sizeParam; ++i)
|
---|
264 | {
|
---|
265 | pid = param[i].GetInt();
|
---|
266 | fClassifier->InsertInclAncestorID(pid);
|
---|
267 | }
|
---|
268 |
|
---|
269 | // create output arrays
|
---|
270 |
|
---|
271 | fOutputArray = ExportArray("candidates");
|
---|
272 |
|
---|
273 | }
|
---|
274 |
|
---|
275 | //------------------------------------------------------------------------------
|
---|
276 |
|
---|
277 | void MadGraphPartonSelector::Finish()
|
---|
278 | {
|
---|
279 | if(fFilter) delete fFilter;
|
---|
280 | if(fClassifier) delete fClassifier;
|
---|
281 | }
|
---|
282 |
|
---|
283 | //------------------------------------------------------------------------------
|
---|
284 |
|
---|
285 | void MadGraphPartonSelector::Process()
|
---|
286 | {
|
---|
287 | TObjArray *array = 0;
|
---|
288 | ExRootGenParticle *particle = 0;
|
---|
289 | ExRootCandidate *candidate = 0;
|
---|
290 | ExRootFactory *factory = GetFactory();
|
---|
291 |
|
---|
292 | TLorentzVector momentum;
|
---|
293 |
|
---|
294 | fFilter->Reset();
|
---|
295 | array = fFilter->GetSubArray(fClassifier, 0);
|
---|
296 |
|
---|
297 | if(array == 0) return;
|
---|
298 |
|
---|
299 | TIter itArray(array);
|
---|
300 |
|
---|
301 | while(particle = static_cast<ExRootGenParticle*>(itArray.Next()))
|
---|
302 | {
|
---|
303 | momentum.SetPxPyPzE(particle->Px, particle->Py, particle->Pz, particle->E);
|
---|
304 |
|
---|
305 | candidate = factory->NewCandidate();
|
---|
306 |
|
---|
307 | candidate->SetP4(momentum);
|
---|
308 | candidate->SetType(particle->PID);
|
---|
309 |
|
---|
310 | fOutputArray->Add(candidate);
|
---|
311 | }
|
---|
312 |
|
---|
313 | }
|
---|
314 |
|
---|
315 | //------------------------------------------------------------------------------
|
---|