Fork me on GitHub

Ticket #406: TrackVertexSmearing.cc

File TrackVertexSmearing.cc, 3.8 KB (added by Michele Selvaggi, 10 years ago)
Line 
1/** \class TrackVertexSmearing
2 *
3 * Performs track vertex smearing
4 *
5 * $Date: 2014-16-03 14:57:44 +0100
6 *
7 *
8 * \author F. Nesti, IRB, Zagreb
9 *
10 */
11
12
13#include "modules/TrackVertexSmearing.h"
14
15#include "classes/DelphesClasses.h"
16#include "classes/DelphesFactory.h"
17#include "classes/DelphesFormula.h"
18
19#include "ExRootAnalysis/ExRootResult.h"
20#include "ExRootAnalysis/ExRootFilter.h"
21#include "ExRootAnalysis/ExRootClassifier.h"
22
23#include "TMath.h"
24#include "TString.h"
25#include "TFormula.h"
26#include "TRandom3.h"
27#include "TObjArray.h"
28#include "TDatabasePDG.h"
29#include "TLorentzVector.h"
30
31#include <algorithm>
32#include <stdexcept>
33#include <iostream>
34#include <sstream>
35
36using namespace std;
37
38//------------------------------------------------------------------------------
39
40TrackVertexSmearing::TrackVertexSmearing() :
41 fFormula(0), fItInputArray(0)
42{
43 fFormula = new DelphesFormula;
44}
45
46//------------------------------------------------------------------------------
47
48TrackVertexSmearing::~TrackVertexSmearing()
49{
50 if(fFormula) delete fFormula;
51}
52
53//------------------------------------------------------------------------------
54
55void TrackVertexSmearing::Init()
56{
57 // read resolution formula
58
59 fFormula->Compile(GetString("ResolutionFormula", "0.0"));
60
61 // import input array
62
63 fInputArray = ImportArray(GetString("InputArray", "TrackMerger/tracks"));
64 fItInputArray = fInputArray->MakeIterator();
65
66 // create output array
67
68 fOutputArray = ExportArray(GetString("OutputArray", "tracks"));
69}
70
71//------------------------------------------------------------------------------
72
73void TrackVertexSmearing::Finish()
74{
75 if(fItInputArray) delete fItInputArray;
76}
77
78//------------------------------------------------------------------------------
79
80void TrackVertexSmearing::Process()
81{
82 Candidate *candidate, *particle, *mother;
83 Double_t x, y, z, t, sx, sy, sz;
84 Double_t pt, eta;
85
86 cout<<"New event"<<endl;
87
88
89 fItInputArray->Reset();
90 while((candidate = static_cast<Candidate*>(fItInputArray->Next())))
91 {
92
93 //take momentum
94 particle = static_cast<Candidate*>(candidate->GetCandidates()->At(0));
95
96 const TLorentzVector &candidateMomentum = particle->Momentum;
97 // const TLorentzVector &candidateMomentum = candidate->Momentum;
98 const TLorentzVector &candidatePosition = particle->Position;
99
100 eta = candidateMomentum.Eta();
101 pt = candidateMomentum.Pt();
102
103 // vertex before smearing
104 x = candidatePosition.X();
105 y = candidatePosition.Y();
106 z = candidatePosition.Z();
107 t = candidatePosition.T();
108
109 // calculate smeared values
110 sx = gRandom->Gaus(0,fFormula->Eval(pt, eta));
111 sy = gRandom->Gaus(0,fFormula->Eval(pt, eta));
112 sz = gRandom->Gaus(0,fFormula->Eval(pt, eta));
113
114 fprintf(stdout, "Smearing (%3d) (pt,eta)=(%6.3f, %6.3f), formula=%6.3f by dx,dy,dz -> %6.4f %6.4f %6.4f\n", particle->PID, pt, eta, fFormula->Eval(pt, eta), sx, sy, sz);
115
116 x += sx;
117 y += sy;
118 z += sz;
119
120
121 //fill smeared values in candidate
122 /* mother = candidate;
123
124 candidate = static_cast<Candidate*>(candidate->Clone());
125
126 candidate->Position.SetXYZT(x, y, z, t);
127
128 cout << z << endl ;
129 cout << candidate->Position.Z() << endl ;
130
131 candidate->AddCandidate(mother);
132 fOutputArray->Add(candidate);
133 */
134
135
136 candidate = static_cast<Candidate*>(candidate->Clone());
137 mother = static_cast<Candidate*>(candidate->GetCandidates()->At(0));
138 mother = static_cast<Candidate*>(mother->Clone());
139
140 mother->Position.SetXYZT(x, y, z, t);
141
142 cout << z << endl ;
143 cout << mother->Position.Z() << endl ;
144
145 candidate->GetCandidates()->AddAt(mother, 0);
146
147 fOutputArray->Add(candidate);
148
149
150 }
151}
152
153//------------------------------------------------------------------------------