1 |
|
---|
2 | #include "modules/MadGraphMatchingTreeWriter.h"
|
---|
3 |
|
---|
4 |
|
---|
5 | #include "ExRootAnalysis/ExRootResult.h"
|
---|
6 | #include "ExRootAnalysis/ExRootClasses.h"
|
---|
7 | #include "ExRootAnalysis/ExRootTreeBranch.h"
|
---|
8 |
|
---|
9 | #include "ExRootAnalysis/ExRootCandidate.h"
|
---|
10 |
|
---|
11 | #include "TClonesArray.h"
|
---|
12 |
|
---|
13 | #include "TH1.h"
|
---|
14 | #include "TH2.h"
|
---|
15 | #include "TString.h"
|
---|
16 | #include "TCanvas.h"
|
---|
17 | #include "TLorentzVector.h"
|
---|
18 |
|
---|
19 | #include <iostream>
|
---|
20 |
|
---|
21 | using namespace std;
|
---|
22 |
|
---|
23 | //------------------------------------------------------------------------------
|
---|
24 |
|
---|
25 | MadGraphMatchingTreeWriter::MadGraphMatchingTreeWriter()
|
---|
26 | {
|
---|
27 | }
|
---|
28 |
|
---|
29 | //------------------------------------------------------------------------------
|
---|
30 |
|
---|
31 | MadGraphMatchingTreeWriter::~MadGraphMatchingTreeWriter()
|
---|
32 | {
|
---|
33 | }
|
---|
34 |
|
---|
35 | //------------------------------------------------------------------------------
|
---|
36 |
|
---|
37 | void MadGraphMatchingTreeWriter::Init()
|
---|
38 | {
|
---|
39 | fJetPTMin = GetDouble("JetPTMin", 20.0);
|
---|
40 | fJetEtaMax = GetDouble("JetEtaMax", 4.5);
|
---|
41 |
|
---|
42 | fClassMap[ExRootGenParticle::Class()] = &MadGraphMatchingTreeWriter::ProcessPartons;
|
---|
43 |
|
---|
44 | fClassMap[ExRootMatching::Class()] = &MadGraphMatchingTreeWriter::ProcessMatching;
|
---|
45 |
|
---|
46 | fClassMap[ExRootGenJet::Class()] = &MadGraphMatchingTreeWriter::ProcessJets;
|
---|
47 |
|
---|
48 | TBranchMap::iterator itBranchMap;
|
---|
49 | map< TClass *, TProcessMethod >::iterator itClassMap;
|
---|
50 |
|
---|
51 | // read branch configuration and
|
---|
52 | // import array with output from filter/classifier/jetfinder modules
|
---|
53 |
|
---|
54 | ExRootConfParam param = GetParam("Branch");
|
---|
55 | Long_t i, size;
|
---|
56 | TString branchName, branchClassName, branchInputArray;
|
---|
57 | TClass *branchClass;
|
---|
58 | const TObjArray *array;
|
---|
59 | ExRootTreeBranch *branch;
|
---|
60 |
|
---|
61 | size = param.GetSize();
|
---|
62 | for(i = 0; i < size; ++i)
|
---|
63 | {
|
---|
64 | branchName = param[i][0].GetString();
|
---|
65 | branchClassName = param[i][1].GetString();
|
---|
66 | branchInputArray = param[i][2].GetString();
|
---|
67 |
|
---|
68 | branchClass = gROOT->GetClass(branchClassName);
|
---|
69 |
|
---|
70 | if(!branchClass)
|
---|
71 | {
|
---|
72 | cout << "** ERROR: cannot find class '" << branchClassName << "'" << endl;
|
---|
73 | continue;
|
---|
74 | }
|
---|
75 |
|
---|
76 | itClassMap = fClassMap.find(branchClass);
|
---|
77 | if(itClassMap == fClassMap.end())
|
---|
78 | {
|
---|
79 | cout << "** ERROR: cannot create branch for class '" << branchClassName << "'" << endl;
|
---|
80 | continue;
|
---|
81 | }
|
---|
82 |
|
---|
83 | array = ImportArray(branchInputArray);
|
---|
84 | branch = NewBranch(branchName, branchClass);
|
---|
85 |
|
---|
86 | fBranchMap.insert(make_pair(branch, make_pair(itClassMap->second, array->MakeIterator())));
|
---|
87 | }
|
---|
88 |
|
---|
89 | }
|
---|
90 |
|
---|
91 | //------------------------------------------------------------------------------
|
---|
92 |
|
---|
93 | void MadGraphMatchingTreeWriter::Finish()
|
---|
94 | {
|
---|
95 | TBranchMap::iterator itBranchMap;
|
---|
96 | TIterator *iterator;
|
---|
97 |
|
---|
98 | for(itBranchMap = fBranchMap.begin(); itBranchMap != fBranchMap.end(); ++itBranchMap)
|
---|
99 | {
|
---|
100 | iterator = itBranchMap->second.second;
|
---|
101 | if(iterator) delete iterator;
|
---|
102 | }
|
---|
103 | }
|
---|
104 |
|
---|
105 | //------------------------------------------------------------------------------
|
---|
106 |
|
---|
107 | void MadGraphMatchingTreeWriter::ProcessPartons(ExRootTreeBranch *branch, TIterator *iterator)
|
---|
108 | {
|
---|
109 | ExRootCandidate *candidate = 0;
|
---|
110 | ExRootGenParticle *entry = 0;
|
---|
111 | Double_t pt, signPz, eta, rapidity;
|
---|
112 |
|
---|
113 | // loop over all partons
|
---|
114 | iterator->Reset();
|
---|
115 | while((candidate = static_cast<ExRootCandidate*>(iterator->Next())))
|
---|
116 | {
|
---|
117 | const TLorentzVector &momentum = candidate->GetP4();
|
---|
118 |
|
---|
119 | entry = static_cast<ExRootGenParticle*>(branch->NewEntry());
|
---|
120 |
|
---|
121 | pt = momentum.Pt();
|
---|
122 | signPz = (momentum.Pz() >= 0.0) ? 1.0 : -1.0;
|
---|
123 | eta = (pt == 0.0 ? signPz*999.9 : momentum.Eta());
|
---|
124 | rapidity = (pt == 0.0 ? signPz*999.9 : momentum.Rapidity());
|
---|
125 |
|
---|
126 | entry->PID = candidate->GetType()->PdgCode();
|
---|
127 |
|
---|
128 | entry->E = momentum.E();
|
---|
129 | entry->Px = momentum.Px();
|
---|
130 | entry->Py = momentum.Py();
|
---|
131 | entry->Pz = momentum.Pz();
|
---|
132 |
|
---|
133 | entry->Eta = eta;
|
---|
134 | entry->Phi = momentum.Phi();
|
---|
135 | entry->PT = pt;
|
---|
136 |
|
---|
137 | entry->Rapidity = rapidity;
|
---|
138 | }
|
---|
139 | }
|
---|
140 |
|
---|
141 | //------------------------------------------------------------------------------
|
---|
142 |
|
---|
143 | void MadGraphMatchingTreeWriter::ProcessMatching(ExRootTreeBranch *branch, TIterator *iterator)
|
---|
144 | {
|
---|
145 | ExRootMatching *matching = 0, *entry = 0;
|
---|
146 |
|
---|
147 | // loop over all matching
|
---|
148 | iterator->Reset();
|
---|
149 | while((matching = static_cast<ExRootMatching*>(iterator->Next())))
|
---|
150 | {
|
---|
151 | entry = static_cast<ExRootMatching*>(branch->NewEntry());
|
---|
152 |
|
---|
153 | entry->DMerge = matching->DMerge;
|
---|
154 | entry->YMerge = matching->YMerge;
|
---|
155 | }
|
---|
156 | }
|
---|
157 |
|
---|
158 | //------------------------------------------------------------------------------
|
---|
159 |
|
---|
160 | void MadGraphMatchingTreeWriter::ProcessJets(ExRootTreeBranch *branch, TIterator *iterator)
|
---|
161 | {
|
---|
162 | ExRootCandidate *candidate = 0;
|
---|
163 | ExRootGenJet *entry = 0;
|
---|
164 | Double_t pt, signPz, eta, rapidity;
|
---|
165 |
|
---|
166 | // loop over all jets
|
---|
167 | iterator->Reset();
|
---|
168 | while((candidate = static_cast<ExRootCandidate*>(iterator->Next())))
|
---|
169 | {
|
---|
170 | const TLorentzVector &momentum = candidate->GetP4();
|
---|
171 |
|
---|
172 | pt = momentum.Pt();
|
---|
173 | signPz = (momentum.Pz() >= 0.0) ? 1.0 : -1.0;
|
---|
174 | eta = (pt == 0.0 ? signPz*999.9 : momentum.Eta());
|
---|
175 | rapidity = (pt == 0.0 ? signPz*999.9 : momentum.Rapidity());
|
---|
176 |
|
---|
177 | if(pt < fJetPTMin) continue;
|
---|
178 | if(TMath::Abs(eta) > fJetEtaMax) continue;
|
---|
179 |
|
---|
180 | entry = static_cast<ExRootGenJet*>(branch->NewEntry());
|
---|
181 |
|
---|
182 | entry->E = momentum.E();
|
---|
183 | entry->Px = momentum.Px();
|
---|
184 | entry->Py = momentum.Py();
|
---|
185 | entry->Pz = momentum.Pz();
|
---|
186 |
|
---|
187 | entry->Eta = eta;
|
---|
188 | entry->Phi = momentum.Phi();
|
---|
189 | entry->PT = pt;
|
---|
190 |
|
---|
191 | entry->Rapidity = rapidity;
|
---|
192 |
|
---|
193 | entry->Mass = momentum.M();
|
---|
194 | }
|
---|
195 | }
|
---|
196 |
|
---|
197 | //------------------------------------------------------------------------------
|
---|
198 |
|
---|
199 | void MadGraphMatchingTreeWriter::Process()
|
---|
200 | {
|
---|
201 |
|
---|
202 | TBranchMap::iterator itBranchMap;
|
---|
203 | ExRootTreeBranch *branch;
|
---|
204 | TProcessMethod method;
|
---|
205 | TIterator *iterator;
|
---|
206 |
|
---|
207 | for(itBranchMap = fBranchMap.begin(); itBranchMap != fBranchMap.end(); ++itBranchMap)
|
---|
208 | {
|
---|
209 | branch = itBranchMap->first;
|
---|
210 | method = itBranchMap->second.first;
|
---|
211 | iterator = itBranchMap->second.second;
|
---|
212 |
|
---|
213 | (this->*method)(branch, iterator);
|
---|
214 | }
|
---|
215 |
|
---|
216 | }
|
---|
217 |
|
---|
218 | //------------------------------------------------------------------------------
|
---|
219 |
|
---|