Fork me on GitHub

source: svn/trunk/modules/PileUpMerger.cc@ 1322

Last change on this file since 1322 was 1268, checked in by Pavel Demin, 11 years ago

added PileUpDistribution parameter to the PileUpMerger module

File size: 3.7 KB
RevLine 
[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"
18#include "classes/DelphesFormula.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]38using namespace std;
39
40//------------------------------------------------------------------------------
41
42PileUpMerger::PileUpMerger() :
[1041]43 fReader(0), fItInputArray(0)
[1009]44{
45}
[1017]46
[1009]47//------------------------------------------------------------------------------
48
49PileUpMerger::~PileUpMerger()
50{
51}
52
53//------------------------------------------------------------------------------
54
[1016]55void PileUpMerger::Init()
[1009]56{
[1016]57 const char *fileName;
[1009]58
[1268]59 fPileUpDistribution = GetInt("PileUpDistribution", 0);
60
[1016]61 fMeanPileUp = GetDouble("MeanPileUp", 10);
[1024]62 fZVertexSpread = GetDouble("ZVertexSpread", 0.05)*1.0E3;
[1009]63
[1016]64 fileName = GetString("PileUpFile", "MinBias.pileup");
[1041]65 fReader = new DelphesPileUpReader(fileName);
[1019]66
[1016]67 // import input array
68 fInputArray = ImportArray(GetString("InputArray", "Delphes/stableParticles"));
69 fItInputArray = fInputArray->MakeIterator();
[1009]70
[1016]71 // create output arrays
72 fOutputArray = ExportArray(GetString("OutputArray", "stableParticles"));
[1009]73}
74
75//------------------------------------------------------------------------------
76
77void PileUpMerger::Finish()
78{
[1041]79 if(fReader) delete fReader;
[1009]80}
81
82//------------------------------------------------------------------------------
83
84void PileUpMerger::Process()
85{
[1016]86 TDatabasePDG *pdg = TDatabasePDG::Instance();
87 TParticlePDG *pdgParticle;
[1041]88 Int_t pid;
89 Float_t x, y, z, t;
90 Float_t px, py, pz, e;
[1111]91 Double_t dz, dphi;
[1268]92 Int_t numberOfEvents, event;
[1041]93 Long64_t allEntries, entry;
[1016]94 Candidate *candidate;
95 DelphesFactory *factory;
[1009]96
[1016]97 fItInputArray->Reset();
98 while((candidate = static_cast<Candidate*>(fItInputArray->Next())))
[1009]99 {
[1016]100 fOutputArray->Add(candidate);
101 }
[1009]102
[1016]103 factory = GetFactory();
[1009]104
[1268]105 switch(fPileUpDistribution)
106 {
107 case 0:
108 numberOfEvents = gRandom->Poisson(fMeanPileUp);
109 break;
110 case 1:
111 numberOfEvents = gRandom->Integer(2*fMeanPileUp + 1);
112 break;
113 default:
114 numberOfEvents = gRandom->Poisson(fMeanPileUp);
115 break;
116 }
[1021]117
[1041]118 allEntries = fReader->GetEntries();
119
[1268]120 for(event = 0; event < numberOfEvents; ++event)
[1016]121 {
[1027]122 do
[1019]123 {
[1041]124 entry = TMath::Nint(gRandom->Rndm()*allEntries);
[1019]125 }
[1041]126 while(entry >= allEntries);
[1009]127
[1041]128 fReader->ReadEntry(entry);
[1019]129
[1026]130 dz = gRandom->Gaus(0.0, fZVertexSpread);
[1111]131 dphi = gRandom->Uniform(-TMath::Pi(), TMath::Pi());
[1009]132
[1041]133 while(fReader->ReadParticle(pid, x, y, z, t, px, py, pz, e))
[1016]134 {
135 candidate = factory->NewCandidate();
[1009]136
[1016]137 candidate->PID = pid;
[1017]138
[1016]139 candidate->Status = 1;
[1009]140
[1016]141 pdgParticle = pdg->GetParticle(pid);
142 candidate->Charge = pdgParticle ? Int_t(pdgParticle->Charge()/3.0) : -999;
143 candidate->Mass = pdgParticle ? pdgParticle->Mass() : -999.9;
[1009]144
[1016]145 candidate->IsPU = 1;
[1009]146
[1016]147 candidate->Momentum.SetPxPyPzE(px, py, pz, e);
[1111]148 candidate->Momentum.RotateZ(dphi);
149
[1016]150 candidate->Position.SetXYZT(x, y, z + dz, t);
[1111]151 candidate->Position.RotateZ(dphi);
[1009]152
[1068]153 fOutputArray->Add(candidate);
[1016]154 }
155 }
[1009]156}
157
158//------------------------------------------------------------------------------
159
Note: See TracBrowser for help on using the repository browser.