Fork me on GitHub

source: git/modules/PileUpMerger.cc@ 88a9b72

ImprovedOutputFile Timing dual_readout llp
Last change on this file since 88a9b72 was d07e957, checked in by pavel <pavel@…>, 11 years ago

add vertex block

  • Property mode set to 100644
File size: 3.9 KB
Line 
1/** \class PileUpMerger
2 *
3 * Merges particles from pile-up sample into event
4 *
5 *
6 * $Date: 2013-02-12 15:13:59 +0100 (Tue, 12 Feb 2013) $
7 * $Revision: 907 $
8 *
9 *
10 * \author M. Selvaggi - UCL, Louvain-la-Neuve
11 *
12 */
13
14#include "modules/PileUpMerger.h"
15
16#include "classes/DelphesClasses.h"
17#include "classes/DelphesFactory.h"
18#include "classes/DelphesFormula.h"
19#include "classes/DelphesPileUpReader.h"
20
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"
28#include "TRandom3.h"
29#include "TObjArray.h"
30#include "TDatabasePDG.h"
31#include "TLorentzVector.h"
32
33#include <algorithm>
34#include <stdexcept>
35#include <iostream>
36#include <sstream>
37
38using namespace std;
39
40//------------------------------------------------------------------------------
41
42PileUpMerger::PileUpMerger() :
43 fReader(0), fItInputArray(0)
44{
45}
46
47//------------------------------------------------------------------------------
48
49PileUpMerger::~PileUpMerger()
50{
51}
52
53//------------------------------------------------------------------------------
54
55void PileUpMerger::Init()
56{
57 const char *fileName;
58
59 fPileUpDistribution = GetInt("PileUpDistribution", 0);
60
61 fMeanPileUp = GetDouble("MeanPileUp", 10);
62 fZVertexSpread = GetDouble("ZVertexSpread", 0.05)*1.0E3;
63
64 fileName = GetString("PileUpFile", "MinBias.pileup");
65 fReader = new DelphesPileUpReader(fileName);
66
67 // import input array
68 fInputArray = ImportArray(GetString("InputArray", "Delphes/stableParticles"));
69 fItInputArray = fInputArray->MakeIterator();
70
71 // create output arrays
72 fParticleOutputArray = ExportArray(GetString("ParticleOutputArray", "stableParticles"));
73 fVertexOutputArray = ExportArray(GetString("VertexOutputArray", "vertices"));
74}
75
76//------------------------------------------------------------------------------
77
78void PileUpMerger::Finish()
79{
80 if(fReader) delete fReader;
81}
82
83//------------------------------------------------------------------------------
84
85void PileUpMerger::Process()
86{
87 TDatabasePDG *pdg = TDatabasePDG::Instance();
88 TParticlePDG *pdgParticle;
89 Int_t pid;
90 Float_t x, y, z, t;
91 Float_t px, py, pz, e;
92 Double_t dz, dphi;
93 Int_t numberOfEvents, event;
94 Long64_t allEntries, entry;
95 Candidate *candidate;
96 DelphesFactory *factory;
97
98 fItInputArray->Reset();
99 while((candidate = static_cast<Candidate*>(fItInputArray->Next())))
100 {
101 fParticleOutputArray->Add(candidate);
102 }
103
104 factory = GetFactory();
105
106 switch(fPileUpDistribution)
107 {
108 case 0:
109 numberOfEvents = gRandom->Poisson(fMeanPileUp);
110 break;
111 case 1:
112 numberOfEvents = gRandom->Integer(2*fMeanPileUp + 1);
113 break;
114 default:
115 numberOfEvents = gRandom->Poisson(fMeanPileUp);
116 break;
117 }
118
119 allEntries = fReader->GetEntries();
120
121 for(event = 0; event < numberOfEvents; ++event)
122 {
123 do
124 {
125 entry = TMath::Nint(gRandom->Rndm()*allEntries);
126 }
127 while(entry >= allEntries);
128
129 fReader->ReadEntry(entry);
130
131 dz = gRandom->Gaus(0.0, fZVertexSpread);
132 dphi = gRandom->Uniform(-TMath::Pi(), TMath::Pi());
133
134 candidate = factory->NewCandidate();
135 candidate->Position.SetXYZT(0.0, 0.0, dz, 0.0);
136 fVertexOutputArray->Add(candidate);
137
138 while(fReader->ReadParticle(pid, x, y, z, t, px, py, pz, e))
139 {
140 candidate = factory->NewCandidate();
141
142 candidate->PID = pid;
143
144 candidate->Status = 1;
145
146 pdgParticle = pdg->GetParticle(pid);
147 candidate->Charge = pdgParticle ? Int_t(pdgParticle->Charge()/3.0) : -999;
148 candidate->Mass = pdgParticle ? pdgParticle->Mass() : -999.9;
149
150 candidate->IsPU = 1;
151
152 candidate->Momentum.SetPxPyPzE(px, py, pz, e);
153 candidate->Momentum.RotateZ(dphi);
154
155 candidate->Position.SetXYZT(x, y, z + dz, t);
156 candidate->Position.RotateZ(dphi);
157
158 fParticleOutputArray->Add(candidate);
159 }
160 }
161}
162
163//------------------------------------------------------------------------------
164
Note: See TracBrowser for help on using the repository browser.