| [2] | 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 |  | 
|---|
| [13] | 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 | 
|---|
| [2] | 52 | // import array with output from filter/classifier/jetfinder modules | 
|---|
|  | 53 |  | 
|---|
| [13] | 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; | 
|---|
| [2] | 60 |  | 
|---|
| [13] | 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(); | 
|---|
| [2] | 67 |  | 
|---|
| [13] | 68 | branchClass = gROOT->GetClass(branchClassName); | 
|---|
| [2] | 69 |  | 
|---|
| [13] | 70 | if(!branchClass) | 
|---|
|  | 71 | { | 
|---|
|  | 72 | cout << "** ERROR: cannot find class '" << branchClassName << "'" << endl; | 
|---|
|  | 73 | continue; | 
|---|
|  | 74 | } | 
|---|
| [2] | 75 |  | 
|---|
| [13] | 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 |  | 
|---|
| [2] | 89 | } | 
|---|
|  | 90 |  | 
|---|
|  | 91 | //------------------------------------------------------------------------------ | 
|---|
|  | 92 |  | 
|---|
|  | 93 | void MadGraphMatchingTreeWriter::Finish() | 
|---|
|  | 94 | { | 
|---|
| [13] | 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 | } | 
|---|
| [2] | 103 | } | 
|---|
|  | 104 |  | 
|---|
|  | 105 | //------------------------------------------------------------------------------ | 
|---|
|  | 106 |  | 
|---|
| [13] | 107 | void MadGraphMatchingTreeWriter::ProcessPartons(ExRootTreeBranch *branch, TIterator *iterator) | 
|---|
| [2] | 108 | { | 
|---|
|  | 109 | ExRootCandidate *candidate = 0; | 
|---|
| [13] | 110 | ExRootGenParticle *entry = 0; | 
|---|
| [2] | 111 | Double_t pt, signPz, eta, rapidity; | 
|---|
|  | 112 |  | 
|---|
| [13] | 113 | // loop over all partons | 
|---|
|  | 114 | iterator->Reset(); | 
|---|
|  | 115 | while((candidate = static_cast<ExRootCandidate*>(iterator->Next()))) | 
|---|
| [2] | 116 | { | 
|---|
|  | 117 | const TLorentzVector &momentum = candidate->GetP4(); | 
|---|
|  | 118 |  | 
|---|
| [13] | 119 | entry = static_cast<ExRootGenParticle*>(branch->NewEntry()); | 
|---|
|  | 120 |  | 
|---|
| [2] | 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 |  | 
|---|
| [13] | 126 | entry->PID = candidate->GetType()->PdgCode(); | 
|---|
| [2] | 127 |  | 
|---|
| [13] | 128 | entry->E = momentum.E(); | 
|---|
|  | 129 | entry->Px = momentum.Px(); | 
|---|
|  | 130 | entry->Py = momentum.Py(); | 
|---|
|  | 131 | entry->Pz = momentum.Pz(); | 
|---|
| [2] | 132 |  | 
|---|
| [13] | 133 | entry->Eta = eta; | 
|---|
|  | 134 | entry->Phi = momentum.Phi(); | 
|---|
|  | 135 | entry->PT = pt; | 
|---|
| [2] | 136 |  | 
|---|
| [13] | 137 | entry->Rapidity = rapidity; | 
|---|
|  | 138 | } | 
|---|
|  | 139 | } | 
|---|
| [2] | 140 |  | 
|---|
| [13] | 141 | //------------------------------------------------------------------------------ | 
|---|
| [2] | 142 |  | 
|---|
| [13] | 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; | 
|---|
| [2] | 155 | } | 
|---|
| [13] | 156 | } | 
|---|
| [2] | 157 |  | 
|---|
| [13] | 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()))) | 
|---|
| [2] | 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 |  | 
|---|
| [13] | 180 | entry = static_cast<ExRootGenJet*>(branch->NewEntry()); | 
|---|
| [2] | 181 |  | 
|---|
| [13] | 182 | entry->E = momentum.E(); | 
|---|
|  | 183 | entry->Px = momentum.Px(); | 
|---|
|  | 184 | entry->Py = momentum.Py(); | 
|---|
|  | 185 | entry->Pz = momentum.Pz(); | 
|---|
| [2] | 186 |  | 
|---|
| [13] | 187 | entry->Eta = eta; | 
|---|
|  | 188 | entry->Phi = momentum.Phi(); | 
|---|
|  | 189 | entry->PT = pt; | 
|---|
| [2] | 190 |  | 
|---|
| [13] | 191 | entry->Rapidity = rapidity; | 
|---|
| [2] | 192 |  | 
|---|
| [13] | 193 | entry->Mass = momentum.M(); | 
|---|
| [2] | 194 | } | 
|---|
| [13] | 195 | } | 
|---|
| [2] | 196 |  | 
|---|
| [13] | 197 | //------------------------------------------------------------------------------ | 
|---|
| [2] | 198 |  | 
|---|
| [13] | 199 | void MadGraphMatchingTreeWriter::Process() | 
|---|
|  | 200 | { | 
|---|
| [2] | 201 |  | 
|---|
| [13] | 202 | TBranchMap::iterator itBranchMap; | 
|---|
|  | 203 | ExRootTreeBranch *branch; | 
|---|
|  | 204 | TProcessMethod method; | 
|---|
|  | 205 | TIterator *iterator; | 
|---|
|  | 206 |  | 
|---|
|  | 207 | for(itBranchMap = fBranchMap.begin(); itBranchMap != fBranchMap.end(); ++itBranchMap) | 
|---|
| [2] | 208 | { | 
|---|
| [13] | 209 | branch = itBranchMap->first; | 
|---|
|  | 210 | method = itBranchMap->second.first; | 
|---|
|  | 211 | iterator = itBranchMap->second.second; | 
|---|
| [2] | 212 |  | 
|---|
| [13] | 213 | (this->*method)(branch, iterator); | 
|---|
|  | 214 | } | 
|---|
| [2] | 215 |  | 
|---|
|  | 216 | } | 
|---|
|  | 217 |  | 
|---|
|  | 218 | //------------------------------------------------------------------------------ | 
|---|
|  | 219 |  | 
|---|