[2] | 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 InsertAncestorID(Int_t pid);
|
---|
| 36 |
|
---|
| 37 | private:
|
---|
| 38 |
|
---|
| 39 | Bool_t hasBadAncestor(ExRootGenParticle *object);
|
---|
| 40 |
|
---|
| 41 | TClonesArray *fBranchParticle;
|
---|
| 42 |
|
---|
| 43 | set< Int_t > fParticleIDSet;
|
---|
| 44 | set< Int_t > fAncestorIDSet;
|
---|
| 45 | };
|
---|
| 46 |
|
---|
| 47 | //------------------------------------------------------------------------------
|
---|
| 48 |
|
---|
| 49 | MadGraphPartonClassifier::MadGraphPartonClassifier(TClonesArray *branch) :
|
---|
| 50 | fBranchParticle(branch)
|
---|
| 51 | {
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | //------------------------------------------------------------------------------
|
---|
| 55 |
|
---|
| 56 | void MadGraphPartonClassifier::InsertParticleID(Int_t pid)
|
---|
| 57 | {
|
---|
| 58 | fParticleIDSet.insert(pid);
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | //------------------------------------------------------------------------------
|
---|
| 62 |
|
---|
| 63 | void MadGraphPartonClassifier::InsertAncestorID(Int_t pid)
|
---|
| 64 | {
|
---|
| 65 | fAncestorIDSet.insert(pid);
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | //------------------------------------------------------------------------------
|
---|
| 69 |
|
---|
| 70 | Bool_t MadGraphPartonClassifier::hasBadAncestor(ExRootGenParticle *object)
|
---|
| 71 | {
|
---|
| 72 | const int kMaxAncestors = 10;
|
---|
| 73 | Int_t i, pidAbs;
|
---|
| 74 | ExRootGenParticle *particle = object;
|
---|
| 75 | set< Int_t >::const_iterator itAncestorIDSet;
|
---|
| 76 | set< Int_t >::const_iterator itParticleIDSet;
|
---|
| 77 |
|
---|
| 78 | for(i = 0; i < kMaxAncestors; ++i)
|
---|
| 79 | {
|
---|
| 80 |
|
---|
| 81 | if(particle->M1 < 0 || particle->M2 > -1) return kFALSE;
|
---|
| 82 |
|
---|
| 83 | // if(particle->PID == 21) return kFALSE;
|
---|
| 84 |
|
---|
| 85 | particle = static_cast<ExRootGenParticle*>(fBranchParticle->At(particle->M1));
|
---|
| 86 |
|
---|
| 87 | if(particle->PID == 21) return kFALSE;
|
---|
| 88 |
|
---|
| 89 | pidAbs = TMath::Abs(particle->PID);
|
---|
| 90 |
|
---|
| 91 | // skip particles with pid included in list
|
---|
| 92 | itAncestorIDSet = fAncestorIDSet.find(pidAbs);
|
---|
| 93 |
|
---|
| 94 | if(itAncestorIDSet != fAncestorIDSet.end()) return kTRUE;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | return kFALSE;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | //------------------------------------------------------------------------------
|
---|
| 101 |
|
---|
| 102 | Int_t MadGraphPartonClassifier::GetCategory(TObject *object)
|
---|
| 103 | {
|
---|
| 104 | ExRootGenParticle *particle = static_cast<ExRootGenParticle*>(object);
|
---|
| 105 | ExRootGenParticle *beam[2], *mother, *daughter;
|
---|
| 106 |
|
---|
| 107 | Int_t i, beamPid[2], beamPidAbs[2];
|
---|
| 108 |
|
---|
| 109 | set< Int_t >::const_iterator itParticleIDSet;
|
---|
| 110 |
|
---|
| 111 | Int_t pidAbs = TMath::Abs(particle->PID);
|
---|
| 112 |
|
---|
| 113 | // skip beam particles and initial state partons
|
---|
| 114 | if(particle->M1 < 2) return -1;
|
---|
| 115 |
|
---|
| 116 | // skip particles with status != 3
|
---|
| 117 | if(particle->Status != 3) return -1;
|
---|
| 118 |
|
---|
| 119 | // skip particles with pid not included in list
|
---|
| 120 | itParticleIDSet = fParticleIDSet.find(pidAbs);
|
---|
| 121 |
|
---|
| 122 | if(itParticleIDSet == fParticleIDSet.end()) return -1;
|
---|
| 123 |
|
---|
| 124 | for(i = 0; i < 2; ++i)
|
---|
| 125 | {
|
---|
| 126 | beam[i] = static_cast<ExRootGenParticle*>(fBranchParticle->At(i));
|
---|
| 127 | beamPid[i] = beam[i]->PID;
|
---|
| 128 | beamPidAbs[i] = TMath::Abs(beamPid[i]);
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | if(beamPidAbs[0] == 11 && beamPidAbs[1] == 11 && beamPid[0] == -beamPid[1])
|
---|
| 132 | {
|
---|
| 133 | mother = static_cast<ExRootGenParticle*>(fBranchParticle->At(particle->M1));
|
---|
| 134 | if( (mother->PID == 22 || mother->PID == 23)
|
---|
| 135 | && mother->M1 == 0 && mother->M2 == 1) return -1;
|
---|
| 136 | }
|
---|
| 137 |
|
---|
| 138 | // skip particles if they have daughters with status == 3
|
---|
| 139 | if(particle->D1 > -1)
|
---|
| 140 | {
|
---|
| 141 | daughter = static_cast<ExRootGenParticle*>(fBranchParticle->At(particle->D1));
|
---|
| 142 | if(daughter->Status == 3) return -1;
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | if(hasBadAncestor(particle)) return -1;
|
---|
| 146 |
|
---|
| 147 | return 0;
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | //------------------------------------------------------------------------------
|
---|
| 151 |
|
---|
| 152 | MadGraphPartonSelector::MadGraphPartonSelector() :
|
---|
| 153 | fFilter(0), fClassifier(0)
|
---|
| 154 | {
|
---|
| 155 | }
|
---|
| 156 |
|
---|
| 157 | //------------------------------------------------------------------------------
|
---|
| 158 |
|
---|
| 159 | MadGraphPartonSelector::~MadGraphPartonSelector()
|
---|
| 160 | {
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 | //------------------------------------------------------------------------------
|
---|
| 164 |
|
---|
| 165 | void MadGraphPartonSelector::Init()
|
---|
| 166 | {
|
---|
| 167 | ExRootConfParam param;
|
---|
| 168 |
|
---|
| 169 | Int_t i, pid, sizeParam;
|
---|
| 170 |
|
---|
| 171 | // import ROOT tree branch
|
---|
| 172 |
|
---|
| 173 | fBranchParticle = UseBranch("GenParticle");
|
---|
| 174 |
|
---|
| 175 | // create classifier and filter
|
---|
| 176 |
|
---|
| 177 | fClassifier = new MadGraphPartonClassifier(fBranchParticle);
|
---|
| 178 | fFilter = new ExRootFilter(fBranchParticle);
|
---|
| 179 |
|
---|
| 180 | // read particle IDs from configuration file and setup classifier
|
---|
| 181 |
|
---|
| 182 | param = GetParam("PartonIDs");
|
---|
| 183 | sizeParam = param.GetSize();
|
---|
| 184 |
|
---|
| 185 | for(i = 0; i < sizeParam; ++i)
|
---|
| 186 | {
|
---|
| 187 | pid = param[i].GetInt();
|
---|
| 188 | fClassifier->InsertParticleID(pid);
|
---|
| 189 | }
|
---|
| 190 |
|
---|
| 191 | // read ancestor IDs from configuration file and setup classifier
|
---|
| 192 |
|
---|
| 193 | param = GetParam("ExcludedAncestorIDs");
|
---|
| 194 | sizeParam = param.GetSize();
|
---|
| 195 |
|
---|
| 196 | for(i = 0; i < sizeParam; ++i)
|
---|
| 197 | {
|
---|
| 198 | pid = param[i].GetInt();
|
---|
| 199 | fClassifier->InsertAncestorID(pid);
|
---|
| 200 | }
|
---|
| 201 |
|
---|
| 202 | // create output arrays
|
---|
| 203 |
|
---|
| 204 | fOutputArray = ExportArray("candidates");
|
---|
| 205 |
|
---|
| 206 | }
|
---|
| 207 |
|
---|
| 208 | //------------------------------------------------------------------------------
|
---|
| 209 |
|
---|
| 210 | void MadGraphPartonSelector::Finish()
|
---|
| 211 | {
|
---|
| 212 | if(fFilter) delete fFilter;
|
---|
| 213 | if(fClassifier) delete fClassifier;
|
---|
| 214 | }
|
---|
| 215 |
|
---|
| 216 | //------------------------------------------------------------------------------
|
---|
| 217 |
|
---|
| 218 | void MadGraphPartonSelector::Process()
|
---|
| 219 | {
|
---|
| 220 | TObjArray *array = 0;
|
---|
| 221 | ExRootGenParticle *particle = 0;
|
---|
| 222 | ExRootCandidate *candidate = 0;
|
---|
| 223 | ExRootFactory *factory = GetFactory();
|
---|
| 224 |
|
---|
| 225 | TLorentzVector momentum;
|
---|
| 226 |
|
---|
| 227 | fFilter->Reset();
|
---|
| 228 | array = fFilter->GetSubArray(fClassifier, 0);
|
---|
| 229 |
|
---|
| 230 | if(array == 0) return;
|
---|
| 231 |
|
---|
| 232 | TIter itArray(array);
|
---|
| 233 |
|
---|
| 234 | while(particle = static_cast<ExRootGenParticle*>(itArray.Next()))
|
---|
| 235 | {
|
---|
| 236 | momentum.SetPxPyPzE(particle->Px, particle->Py, particle->Pz, particle->E);
|
---|
| 237 |
|
---|
| 238 | candidate = factory->NewCandidate();
|
---|
| 239 |
|
---|
| 240 | candidate->SetP4(momentum);
|
---|
| 241 | candidate->SetType(particle->PID);
|
---|
| 242 |
|
---|
| 243 | fOutputArray->Add(candidate);
|
---|
| 244 | }
|
---|
| 245 |
|
---|
| 246 | }
|
---|
| 247 |
|
---|
| 248 | //------------------------------------------------------------------------------
|
---|