Fork me on GitHub

source: git/modules/PileUpMerger.cc@ fb21bc8

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

add vertex block

  • Property mode set to 100644
File size: 3.9 KB
RevLine 
[d7d2da3]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
[76d3973]59 fPileUpDistribution = GetInt("PileUpDistribution", 0);
60
[d7d2da3]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
[d07e957]72 fParticleOutputArray = ExportArray(GetString("ParticleOutputArray", "stableParticles"));
73 fVertexOutputArray = ExportArray(GetString("VertexOutputArray", "vertices"));
[d7d2da3]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;
[b68a60f]92 Double_t dz, dphi;
[76d3973]93 Int_t numberOfEvents, event;
[d7d2da3]94 Long64_t allEntries, entry;
95 Candidate *candidate;
96 DelphesFactory *factory;
97
98 fItInputArray->Reset();
99 while((candidate = static_cast<Candidate*>(fItInputArray->Next())))
100 {
[d07e957]101 fParticleOutputArray->Add(candidate);
[d7d2da3]102 }
103
104 factory = GetFactory();
105
[76d3973]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 }
[d7d2da3]118
119 allEntries = fReader->GetEntries();
120
[76d3973]121 for(event = 0; event < numberOfEvents; ++event)
[d7d2da3]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);
[b68a60f]132 dphi = gRandom->Uniform(-TMath::Pi(), TMath::Pi());
[d7d2da3]133
[d07e957]134 candidate = factory->NewCandidate();
135 candidate->Position.SetXYZT(0.0, 0.0, dz, 0.0);
136 fVertexOutputArray->Add(candidate);
137
[d7d2da3]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);
[b68a60f]153 candidate->Momentum.RotateZ(dphi);
154
[d7d2da3]155 candidate->Position.SetXYZT(x, y, z + dz, t);
[b68a60f]156 candidate->Position.RotateZ(dphi);
[d7d2da3]157
[d07e957]158 fParticleOutputArray->Add(candidate);
[d7d2da3]159 }
160 }
161}
162
163//------------------------------------------------------------------------------
164
Note: See TracBrowser for help on using the repository browser.