[1009] | 1 | /** \class PileUpMerger
|
---|
| 2 | *
|
---|
[1027] | 3 | * Merges particles from pile-up sample into event
|
---|
[1009] | 4 | *
|
---|
[1017] | 5 | *
|
---|
[1009] | 6 | * $Date: 2013-02-12 15:13:59 +0100 (Tue, 12 Feb 2013) $
|
---|
| 7 | * $Revision: 907 $
|
---|
| 8 | *
|
---|
| 9 | *
|
---|
[1027] | 10 | * \author M. Selvaggi - UCL, Louvain-la-Neuve
|
---|
[1009] | 11 | *
|
---|
| 12 | */
|
---|
[1027] | 13 |
|
---|
[1009] | 14 | #include "modules/PileUpMerger.h"
|
---|
| 15 |
|
---|
[1016] | 16 | #include "classes/DelphesClasses.h"
|
---|
| 17 | #include "classes/DelphesFactory.h"
|
---|
[1345] | 18 | #include "classes/DelphesTF2.h"
|
---|
[1041] | 19 | #include "classes/DelphesPileUpReader.h"
|
---|
[1016] | 20 |
|
---|
[1009] | 21 | #include "ExRootAnalysis/ExRootResult.h"
|
---|
| 22 | #include "ExRootAnalysis/ExRootFilter.h"
|
---|
| 23 | #include "ExRootAnalysis/ExRootClassifier.h"
|
---|
| 24 |
|
---|
| 25 | #include "TMath.h"
|
---|
| 26 | #include "TString.h"
|
---|
| 27 | #include "TFormula.h"
|
---|
[1016] | 28 | #include "TRandom3.h"
|
---|
| 29 | #include "TObjArray.h"
|
---|
| 30 | #include "TDatabasePDG.h"
|
---|
[1009] | 31 | #include "TLorentzVector.h"
|
---|
| 32 |
|
---|
[1017] | 33 | #include <algorithm>
|
---|
[1009] | 34 | #include <stdexcept>
|
---|
| 35 | #include <iostream>
|
---|
| 36 | #include <sstream>
|
---|
[1016] | 37 |
|
---|
[1009] | 38 | using namespace std;
|
---|
| 39 |
|
---|
| 40 | //------------------------------------------------------------------------------
|
---|
| 41 |
|
---|
| 42 | PileUpMerger::PileUpMerger() :
|
---|
[1345] | 43 | fFunction(0), fReader(0), fItInputArray(0)
|
---|
[1009] | 44 | {
|
---|
[1345] | 45 | fFunction = new DelphesTF2;
|
---|
[1009] | 46 | }
|
---|
[1017] | 47 |
|
---|
[1345] | 48 |
|
---|
[1009] | 49 | //------------------------------------------------------------------------------
|
---|
| 50 |
|
---|
| 51 | PileUpMerger::~PileUpMerger()
|
---|
| 52 | {
|
---|
[1345] | 53 | delete fFunction;
|
---|
[1009] | 54 | }
|
---|
| 55 |
|
---|
| 56 | //------------------------------------------------------------------------------
|
---|
| 57 |
|
---|
[1016] | 58 | void PileUpMerger::Init()
|
---|
[1009] | 59 | {
|
---|
[1016] | 60 | const char *fileName;
|
---|
[1009] | 61 |
|
---|
[1268] | 62 | fPileUpDistribution = GetInt("PileUpDistribution", 0);
|
---|
| 63 |
|
---|
[1016] | 64 | fMeanPileUp = GetDouble("MeanPileUp", 10);
|
---|
[1345] | 65 |
|
---|
| 66 | fZVertexSpread = GetDouble("ZVertexSpread", 0.15);
|
---|
| 67 | fTVertexSpread = GetDouble("TVertexSpread", 1.5E-09);
|
---|
[1009] | 68 |
|
---|
[1345] | 69 | // read vertex smearing formula
|
---|
| 70 |
|
---|
| 71 | fFunction->Compile(GetString("VertexDistributionFormula", "0.0"));
|
---|
| 72 | fFunction->SetRange(-fZVertexSpread,-fTVertexSpread,fZVertexSpread,fTVertexSpread);
|
---|
| 73 |
|
---|
[1016] | 74 | fileName = GetString("PileUpFile", "MinBias.pileup");
|
---|
[1041] | 75 | fReader = new DelphesPileUpReader(fileName);
|
---|
[1019] | 76 |
|
---|
[1016] | 77 | // import input array
|
---|
| 78 | fInputArray = ImportArray(GetString("InputArray", "Delphes/stableParticles"));
|
---|
| 79 | fItInputArray = fInputArray->MakeIterator();
|
---|
[1009] | 80 |
|
---|
[1016] | 81 | // create output arrays
|
---|
[1323] | 82 | fParticleOutputArray = ExportArray(GetString("ParticleOutputArray", "stableParticles"));
|
---|
| 83 | fVertexOutputArray = ExportArray(GetString("VertexOutputArray", "vertices"));
|
---|
[1009] | 84 | }
|
---|
| 85 |
|
---|
| 86 | //------------------------------------------------------------------------------
|
---|
| 87 |
|
---|
| 88 | void PileUpMerger::Finish()
|
---|
| 89 | {
|
---|
[1041] | 90 | if(fReader) delete fReader;
|
---|
[1009] | 91 | }
|
---|
| 92 |
|
---|
| 93 | //------------------------------------------------------------------------------
|
---|
| 94 |
|
---|
| 95 | void PileUpMerger::Process()
|
---|
| 96 | {
|
---|
[1016] | 97 | TDatabasePDG *pdg = TDatabasePDG::Instance();
|
---|
| 98 | TParticlePDG *pdgParticle;
|
---|
[1041] | 99 | Int_t pid;
|
---|
| 100 | Float_t x, y, z, t;
|
---|
| 101 | Float_t px, py, pz, e;
|
---|
[1345] | 102 | Double_t dz, dphi, dt;
|
---|
[1268] | 103 | Int_t numberOfEvents, event;
|
---|
[1041] | 104 | Long64_t allEntries, entry;
|
---|
[1345] | 105 | Candidate *candidate, *vertexcandidate;
|
---|
[1016] | 106 | DelphesFactory *factory;
|
---|
[1345] | 107 |
|
---|
| 108 | const Double_t c_light = 2.99792458E8;
|
---|
[1009] | 109 |
|
---|
[1016] | 110 | fItInputArray->Reset();
|
---|
[1345] | 111 |
|
---|
| 112 | // --- Deal with Primary vertex first ------
|
---|
| 113 |
|
---|
| 114 | fFunction->GetRandom2(dz,dt);
|
---|
| 115 |
|
---|
| 116 | dt *= c_light*1.0E3; //necessary in order to make t in mm/c
|
---|
| 117 | dz *= 1.0E3; //necessary in order to make z in mm
|
---|
| 118 |
|
---|
[1016] | 119 | while((candidate = static_cast<Candidate*>(fItInputArray->Next())))
|
---|
[1009] | 120 | {
|
---|
[1345] | 121 | candidate->Position.SetXYZT(x, y, z+dz, t+dt);
|
---|
[1323] | 122 | fParticleOutputArray->Add(candidate);
|
---|
[1016] | 123 | }
|
---|
[1009] | 124 |
|
---|
[1016] | 125 | factory = GetFactory();
|
---|
[1345] | 126 |
|
---|
| 127 | vertexcandidate = factory->NewCandidate();
|
---|
| 128 | vertexcandidate->Position.SetXYZT(0.0, 0.0, dz, dt);
|
---|
| 129 | fVertexOutputArray->Add(vertexcandidate);
|
---|
| 130 |
|
---|
| 131 |
|
---|
| 132 | // --- Then with pile-up vertices ------
|
---|
| 133 |
|
---|
[1268] | 134 | switch(fPileUpDistribution)
|
---|
| 135 | {
|
---|
| 136 | case 0:
|
---|
| 137 | numberOfEvents = gRandom->Poisson(fMeanPileUp);
|
---|
| 138 | break;
|
---|
| 139 | case 1:
|
---|
| 140 | numberOfEvents = gRandom->Integer(2*fMeanPileUp + 1);
|
---|
| 141 | break;
|
---|
| 142 | default:
|
---|
| 143 | numberOfEvents = gRandom->Poisson(fMeanPileUp);
|
---|
| 144 | break;
|
---|
| 145 | }
|
---|
[1021] | 146 |
|
---|
[1041] | 147 | allEntries = fReader->GetEntries();
|
---|
[1345] | 148 |
|
---|
[1268] | 149 | for(event = 0; event < numberOfEvents; ++event)
|
---|
[1016] | 150 | {
|
---|
[1027] | 151 | do
|
---|
[1019] | 152 | {
|
---|
[1041] | 153 | entry = TMath::Nint(gRandom->Rndm()*allEntries);
|
---|
[1019] | 154 | }
|
---|
[1041] | 155 | while(entry >= allEntries);
|
---|
[1009] | 156 |
|
---|
[1041] | 157 | fReader->ReadEntry(entry);
|
---|
[1345] | 158 |
|
---|
| 159 | // --- Pile-up vertex smearing
|
---|
| 160 |
|
---|
| 161 | fFunction->GetRandom2(dz,dt);
|
---|
| 162 |
|
---|
| 163 | dt *= c_light*1.0E3; //necessary in order to make t in mm/c
|
---|
| 164 | dz *= 1.0E3; //necessary in order to make z in mm
|
---|
| 165 |
|
---|
[1111] | 166 | dphi = gRandom->Uniform(-TMath::Pi(), TMath::Pi());
|
---|
[1009] | 167 |
|
---|
[1345] | 168 | vertexcandidate = factory->NewCandidate();
|
---|
| 169 | vertexcandidate->Position.SetXYZT(0.0, 0.0, dz, dt);
|
---|
| 170 | vertexcandidate->IsPU = 1;
|
---|
| 171 |
|
---|
| 172 | fVertexOutputArray->Add(vertexcandidate);
|
---|
[1323] | 173 |
|
---|
[1041] | 174 | while(fReader->ReadParticle(pid, x, y, z, t, px, py, pz, e))
|
---|
[1016] | 175 | {
|
---|
| 176 | candidate = factory->NewCandidate();
|
---|
[1009] | 177 |
|
---|
[1016] | 178 | candidate->PID = pid;
|
---|
[1017] | 179 |
|
---|
[1016] | 180 | candidate->Status = 1;
|
---|
[1009] | 181 |
|
---|
[1016] | 182 | pdgParticle = pdg->GetParticle(pid);
|
---|
| 183 | candidate->Charge = pdgParticle ? Int_t(pdgParticle->Charge()/3.0) : -999;
|
---|
| 184 | candidate->Mass = pdgParticle ? pdgParticle->Mass() : -999.9;
|
---|
[1009] | 185 |
|
---|
[1016] | 186 | candidate->IsPU = 1;
|
---|
[1345] | 187 |
|
---|
[1016] | 188 | candidate->Momentum.SetPxPyPzE(px, py, pz, e);
|
---|
[1111] | 189 | candidate->Momentum.RotateZ(dphi);
|
---|
| 190 |
|
---|
[1345] | 191 | candidate->Position.SetXYZT(x, y, z+dz, t+dt);
|
---|
[1111] | 192 | candidate->Position.RotateZ(dphi);
|
---|
[1345] | 193 |
|
---|
[1323] | 194 | fParticleOutputArray->Add(candidate);
|
---|
[1016] | 195 | }
|
---|
| 196 | }
|
---|
[1009] | 197 | }
|
---|
| 198 |
|
---|
| 199 | //------------------------------------------------------------------------------
|
---|
| 200 |
|
---|