Fork me on GitHub

source: git/modules/MomentumSmearing.cc@ 505a779

ImprovedOutputFile Timing
Last change on this file since 505a779 was 341014c, checked in by Pavel Demin <pavel-demin@…>, 6 years ago

apply .clang-format to all .h, .cc and .cpp files

  • Property mode set to 100644
File size: 4.1 KB
Line 
1/*
2 * Delphes: a framework for fast simulation of a generic collider experiment
3 * Copyright (C) 2012-2014 Universite catholique de Louvain (UCL), Belgium
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19/** \class MomentumSmearing
20 *
21 * Performs transverse momentum resolution smearing.
22 *
23 * \author P. Demin - UCL, Louvain-la-Neuve
24 *
25 */
26
27#include "modules/MomentumSmearing.h"
28
29#include "classes/DelphesClasses.h"
30#include "classes/DelphesFactory.h"
31#include "classes/DelphesFormula.h"
32
33#include "ExRootAnalysis/ExRootClassifier.h"
34#include "ExRootAnalysis/ExRootFilter.h"
35#include "ExRootAnalysis/ExRootResult.h"
36
37#include "TDatabasePDG.h"
38#include "TFormula.h"
39#include "TLorentzVector.h"
40#include "TMath.h"
41#include "TObjArray.h"
42#include "TRandom3.h"
43#include "TString.h"
44
45#include <algorithm>
46#include <iostream>
47#include <sstream>
48#include <stdexcept>
49
50using namespace std;
51
52//------------------------------------------------------------------------------
53
54MomentumSmearing::MomentumSmearing() :
55 fFormula(0), fItInputArray(0)
56{
57 fFormula = new DelphesFormula;
58}
59
60//------------------------------------------------------------------------------
61
62MomentumSmearing::~MomentumSmearing()
63{
64 if(fFormula) delete fFormula;
65}
66
67//------------------------------------------------------------------------------
68
69void MomentumSmearing::Init()
70{
71 // read resolution formula
72
73 fFormula->Compile(GetString("ResolutionFormula", "0.0"));
74
75 // import input array
76
77 fInputArray = ImportArray(GetString("InputArray", "ParticlePropagator/stableParticles"));
78 fItInputArray = fInputArray->MakeIterator();
79
80 // create output array
81
82 fOutputArray = ExportArray(GetString("OutputArray", "stableParticles"));
83}
84
85//------------------------------------------------------------------------------
86
87void MomentumSmearing::Finish()
88{
89 if(fItInputArray) delete fItInputArray;
90}
91
92//------------------------------------------------------------------------------
93
94void MomentumSmearing::Process()
95{
96 Candidate *candidate, *mother;
97 Double_t pt, eta, phi, e, res;
98
99 fItInputArray->Reset();
100 while((candidate = static_cast<Candidate *>(fItInputArray->Next())))
101 {
102 const TLorentzVector &candidatePosition = candidate->Position;
103 const TLorentzVector &candidateMomentum = candidate->Momentum;
104 eta = candidatePosition.Eta();
105 phi = candidatePosition.Phi();
106 pt = candidateMomentum.Pt();
107 e = candidateMomentum.E();
108 res = fFormula->Eval(pt, eta, phi, e);
109
110 // apply smearing formula
111 //pt = gRandom->Gaus(pt, fFormula->Eval(pt, eta, phi, e) * pt);
112
113 res = (res > 1.0) ? 1.0 : res;
114
115 pt = LogNormal(pt, res * pt);
116
117 //if(pt <= 0.0) continue;
118
119 mother = candidate;
120 candidate = static_cast<Candidate *>(candidate->Clone());
121 eta = candidateMomentum.Eta();
122 phi = candidateMomentum.Phi();
123 candidate->Momentum.SetPtEtaPhiE(pt, eta, phi, pt * TMath::CosH(eta));
124 //candidate->TrackResolution = fFormula->Eval(pt, eta, phi, e);
125 candidate->TrackResolution = res;
126 candidate->AddCandidate(mother);
127
128 fOutputArray->Add(candidate);
129 }
130}
131//----------------------------------------------------------------
132
133Double_t MomentumSmearing::LogNormal(Double_t mean, Double_t sigma)
134{
135 Double_t a, b;
136
137 if(mean > 0.0)
138 {
139 b = TMath::Sqrt(TMath::Log((1.0 + (sigma * sigma) / (mean * mean))));
140 a = TMath::Log(mean) - 0.5 * b * b;
141
142 return TMath::Exp(a + b * gRandom->Gaus(0.0, 1.0));
143 }
144 else
145 {
146 return 0.0;
147 }
148}
149
150//------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.