Fork me on GitHub

source: svn/trunk/src/SmearUtil.cc@ 7

Last change on this file since 7 was 2, checked in by Xavier Rouby, 16 years ago

first commit

File size: 14.9 KB
Line 
1/*
2 ---- Delphes ----
3 A Fast Simulator for general purpose LHC detector
4 S. Ovyn ~~~~ severine.ovyn@uclouvain.be
5
6 Center for Particle Physics and Phenomenology (CP3)
7 Universite Catholique de Louvain (UCL)
8 Louvain-la-Neuve, Belgium
9*/
10
11/// \file SmearUtil.cc
12/// \brief RESOLution class, and some generic definitions
13
14
15#include "interface/SmearUtil.h"
16#include "TRandom.h"
17
18#include <iostream>
19#include <sstream>
20#include <fstream>
21using namespace std;
22
23//------------------------------------------------------------------------------
24
25RESOLution::RESOLution() {
26
27MAX_TRACKER = 2.5; // tracker coverage
28MAX_CALO_CEN = 3.0; // central calorimeter coverage
29MAX_CALO_FWD = 5.0; // forward calorimeter pseudorapidity coverage
30MAX_MU = 2.4; // muon chambers pseudorapidity coverage
31MIN_CALO_VFWD= 5.2; // very forward calorimeter (if any), like CASTOR
32MAX_CALO_VFWD= 6.6; // very forward calorimeter (if any), like CASTOR
33MIN_ZDC = 8.3; // zero-degree calorimeter, coverage
34
35ZDC_S = 140.; // ZDC distance to IP
36RP220_S = 220; // distance of the RP to the IP, in meters
37RP220_X = 0.002;// distance of the RP to the beam, in meters
38FP420_S = 420; // distance of the RP to the IP, in meters
39FP420_X = 0.004;// distance of the RP to the beam, in meters
40
41
42ELG_Scen = 0.028; // S term for central ECAL
43ELG_Ncen = 0.124 ; // N term for central ECAL
44ELG_Ccen = 0.0026 ; // C term for central ECAL
45ELG_Cfwd = 0.107 ; // S term for forward ECAL
46ELG_Sfwd = 2.084 ; // C term for forward ECAL
47ELG_Nfwd = 0.0 ; // N term for central ECAL
48
49HAD_Secal = 0.05 ; // S term for central ECAL // electromagnetic calorimeter
50HAD_Necal = 0.25 ; // N term for central ECAL
51HAD_Cecal = 0.0055 ; // C term for central ECAL
52HAD_Shcal = 0.91 ; // S term for central HCAL // hadronic calorimeter
53HAD_Nhcal = 0. ; // N term for central HCAL
54HAD_Chcal = 0.038 ; // C term for central HCAL
55HAD_Shf = 2.7 ; // S term for central HF // forward calorimeter
56HAD_Nhf = 0. ; // N term for central HF
57HAD_Chf = 0.13 ; // C term for central HF
58
59MU_SmearPt = 0.01 ;
60
61TAU_CONE_ENERGY = 0.15 ; // Delta R = radius of the cone // for "electromagnetic collimation"
62TAU_EM_COLLIMATION = 0.95;
63TAU_CONE_TRACKS= 0.4 ; //Delta R for tracker isolation for tau's
64PT_TRACK_TAU = 2.0 ; // GeV // 6 GeV ????
65
66
67PT_TRACKS_MIN = 0.9 ; // minimal pt needed to reach the calorimeter, in GeV
68PT_QUARKS_MIN = 2.0 ; // minimal pt needed by quarks to reach the tracker, in GeV (??????)
69TRACKING_EFF = 90;
70
71
72TAGGING_B = 40;
73MISTAGGING_C = 10;
74MISTAGGING_L = 1;
75
76
77CONERADIUS = 0.7; // generic jet radius ; not for tau's !!!
78JETALGO = 1;
79// Define Cone algorithm.
80C_SEEDTHRESHOLD = 1.0;
81C_ADJACENCYCUT = 2;
82C_MAXITERATIONS = 100;
83C_IRATCH = 1;
84C_OVERLAPTHRESHOLD = 0.75;
85
86//Define MidPoint algorithm.
87M_SEEDTHRESHOLD = 1.0;
88M_CONEAREAFRACTION = 0.25;
89M_MAXPAIRSIZE = 2;
90M_MAXITERATIONS = 100;
91M_OVERLAPTHRESHOLD = 0.75;
92
93}
94
95//------------------------------------------------------------------------------
96void RESOLution::ReadDataCard(const string datacard) {
97
98 string temp_string;
99 istringstream curstring;
100
101 ifstream fichier_a_lire(datacard.c_str());
102 if(!fichier_a_lire.good()) {
103 cout << datacard << "Datadard " << datacard << " not found, use default values" << endl;
104 return;
105 }
106
107 while (getline(fichier_a_lire,temp_string)) {
108 curstring.clear(); // needed when using several times istringstream::str(string)
109 curstring.str(temp_string);
110 string varname;
111 float value;
112
113 if(strstr(temp_string.c_str(),"#")) { }
114 else if(strstr(temp_string.c_str(),"MAX_TRACKER")){curstring >> varname >> value; MAX_TRACKER = value;}
115 else if(strstr(temp_string.c_str(),"MAX_CALO_CEN")){curstring >> varname >> value; MAX_CALO_CEN = value;}
116 else if(strstr(temp_string.c_str(),"MAX_CALO_FWD")){curstring >> varname >> value; MAX_CALO_FWD = value;}
117 else if(strstr(temp_string.c_str(),"MAX_MU")){curstring >> varname >> value; MAX_MU = value;}
118 else if(strstr(temp_string.c_str(),"ELG_Scen")){curstring >> varname >> value; ELG_Scen = value;}
119 else if(strstr(temp_string.c_str(),"ELG_Ncen")){curstring >> varname >> value; ELG_Ncen = value;}
120 else if(strstr(temp_string.c_str(),"ELG_Ccen")){curstring >> varname >> value; ELG_Ccen = value;}
121 else if(strstr(temp_string.c_str(),"ELG_Sfwd")){curstring >> varname >> value; ELG_Sfwd = value;}
122 else if(strstr(temp_string.c_str(),"ELG_Cfwd")){curstring >> varname >> value; ELG_Cfwd = value;}
123 else if(strstr(temp_string.c_str(),"ELG_Nfwd")){curstring >> varname >> value; ELG_Nfwd = value;}
124 else if(strstr(temp_string.c_str(),"HAD_Secal")){curstring >> varname >> value; HAD_Secal = value;}
125 else if(strstr(temp_string.c_str(),"HAD_Necal")){curstring >> varname >> value; HAD_Necal = value;}
126 else if(strstr(temp_string.c_str(),"HAD_Cecal")){curstring >> varname >> value; HAD_Cecal = value;}
127 else if(strstr(temp_string.c_str(),"HAD_Shcal")){curstring >> varname >> value; HAD_Shcal = value;}
128 else if(strstr(temp_string.c_str(),"HAD_Nhcal")){curstring >> varname >> value; HAD_Nhcal = value;}
129 else if(strstr(temp_string.c_str(),"HAD_Chcal")){curstring >> varname >> value; HAD_Chcal = value;}
130 else if(strstr(temp_string.c_str(),"HAD_Shf")){curstring >> varname >> value; HAD_Shf = value;}
131 else if(strstr(temp_string.c_str(),"HAD_Nhf")){curstring >> varname >> value; HAD_Nhf = value;}
132 else if(strstr(temp_string.c_str(),"HAD_Chf")){curstring >> varname >> value; HAD_Chf = value;}
133 else if(strstr(temp_string.c_str(),"MU_SmearPt")){curstring >> varname >> value; MU_SmearPt = value;}
134 else if(strstr(temp_string.c_str(),"TAU_CONE_ENERGY")){curstring >> varname >> value; TAU_CONE_ENERGY = value;}
135 else if(strstr(temp_string.c_str(),"TAU_CONE_TRACKS")){curstring >> varname >> value; TAU_CONE_TRACKS = value;}
136 else if(strstr(temp_string.c_str(),"PT_TRACK_TAU")){curstring >> varname >> value; PT_TRACK_TAU = value;}
137 else if(strstr(temp_string.c_str(),"PT_TRACKS_MIN")){curstring >> varname >> value; PT_TRACKS_MIN = value;}
138 else if(strstr(temp_string.c_str(),"TAGGING_B")){curstring >> varname >> value; TAGGING_B = (int)value;}
139 else if(strstr(temp_string.c_str(),"MISTAGGING_C")){curstring >> varname >> value; MISTAGGING_C = (int)value;}
140 else if(strstr(temp_string.c_str(),"MISTAGGING_L")){curstring >> varname >> value; MISTAGGING_L = (int)value;}
141 else if(strstr(temp_string.c_str(),"CONERADIUS")){curstring >> varname >> value; CONERADIUS = value;}
142 else if(strstr(temp_string.c_str(),"JETALGO")){curstring >> varname >> value; JETALGO = (int)value;}
143 else if(strstr(temp_string.c_str(),"TRACKING_EFF")){curstring >> varname >> value; TRACKING_EFF = (int)value;}
144 }
145
146// Define Cone algorithm.
147 C_SEEDTHRESHOLD = 1.0;
148 C_ADJACENCYCUT = 2;
149 C_MAXITERATIONS = 100;
150 C_IRATCH = 1;
151 C_OVERLAPTHRESHOLD = 0.75;
152
153//Define MidPoint algorithm.
154 M_SEEDTHRESHOLD = 1.0;
155 M_CONEAREAFRACTION = 0.25;
156 M_MAXPAIRSIZE = 2;
157 M_MAXITERATIONS = 100;
158 M_OVERLAPTHRESHOLD = 0.75;
159
160}
161
162
163// **********Provides the smeared TLorentzVector for the electrons********
164// Smears the electron energy, and changes the 4-momentum accordingly
165// different smearing if the electron is central (eta < 2.5) or forward
166void RESOLution::SmearElectron(TLorentzVector &electron) {
167 // the 'electron' variable will be changed by the function
168 float energy = electron.E(); // before smearing
169 float energyS = 0.0; // after smearing // \sigma/E = C + N/E + S/\sqrt{E}
170
171 if(fabs(electron.Eta()) < MAX_TRACKER) { // if the electron is inside the tracker
172 energyS = gRandom->Gaus(energy, sqrt(
173 pow(ELG_Ncen,2) +
174 pow(ELG_Ccen*energy,2) +
175 pow(ELG_Scen*sqrt(energy),2) ) );
176 } else { // outside the tracker
177 energyS = gRandom->Gaus(energy, sqrt(
178 pow(ELG_Nfwd,2) +
179 pow(ELG_Cfwd*energy,2) +
180 pow(ELG_Sfwd*sqrt(energy),2) ) );
181 }
182 electron.SetPtEtaPhiE(energyS/cosh(electron.Eta()), electron.Eta(), electron.Phi(), energyS);
183
184 if(electron.E() < 0)electron.SetPxPyPzE(0,0,0,0); // no negative values after smearing !
185}
186
187
188// **********Provides the smeared TLorentzVector for the muons********
189// Smears the muon pT and changes the 4-momentum accordingly
190void RESOLution::SmearMu(TLorentzVector &muon) {
191 // the 'muon' variable will be changed by the function
192 float pt = muon.Pt(); // before smearing
193 float ptS = gRandom->Gaus(pt, MU_SmearPt*pt ); // after smearing // \sigma/E = C + N/E + S/\sqrt{E}
194
195 muon.SetPtEtaPhiE(ptS, muon.Eta(), muon.Phi(), ptS*cosh(muon.Eta()));
196
197 if(muon.E() < 0)muon.SetPxPyPzE(0,0,0,0); // no negative values after smearing !
198}
199
200
201// **********Provides the smeared TLorentzVector for the hadrons********
202// Smears the hadron 4-momentum
203void RESOLution::SmearHadron(TLorentzVector &hadron, const float frac)
204 // the 'hadron' variable will be changed by the function
205 // the 'frac' variable describes the long-living particles. Should be 0.7 for K0S and Lambda, 1. otherwise
206{
207 float energy = hadron.E(); // before smearing
208 float energyS = 0.0; // after smearing // \sigma/E = C + N/E + S/\sqrt{E}
209 float energy_ecal = (1.0 - frac)*energy; // electromagnetic calorimeter
210 float energy_hcal = frac*energy; // hadronic calorimeter
211 // frac takes into account the decay of long-living particles, that decay in the calorimeters
212 // some of the particles decay mostly in the ecal, some mostly in the hcal
213
214 if(fabs(hadron.Eta()) < MAX_CALO_CEN) {
215 energyS = gRandom->Gaus(energy_hcal, sqrt(
216 pow(HAD_Nhcal,2) +
217 pow(HAD_Chcal*energy_hcal,2) +
218 pow(HAD_Shcal*sqrt(energy_hcal),2) ))
219 +
220 gRandom->Gaus(energy_ecal, sqrt(
221 pow(HAD_Necal,2) +
222 pow(HAD_Cecal*energy_ecal,2) +
223 pow(HAD_Secal*sqrt(energy_ecal),2) ) );
224 } else {
225 energyS = gRandom->Gaus(energy,
226 pow(HAD_Nhf,2) +
227 pow(HAD_Chf*energy,2) +
228 pow(HAD_Shf*sqrt(energy),2) );
229 }
230 hadron.SetPtEtaPhiE(energyS/cosh(hadron.Eta()),hadron.Eta(), hadron.Phi(), energyS);
231
232 if(hadron.E() < 0)hadron.SetPxPyPzE(0,0,0,0);
233}
234
235// **********Provides the energy in the cone of radius TAU_CONE_ENERGY for the tau identification********
236// to be taken into account, a calo tower should
237// 1) have a transverse energy \f$ E_T = \sqrt{E_X^2 + E_Y^2} \f$ above a given threshold
238// 2) be inside a cone with a radius R and the axis defined by (eta,phi)
239double RESOLution::EnergySmallCone(const vector<PhysicsTower> &towers, const float eta, const float phi) {
240 double Energie=0;
241 for(unsigned int i=0; i < towers.size(); i++) {
242 if(towers[i].fourVector.pt() < M_SEEDTHRESHOLD) continue;
243 if((DeltaR(phi,eta,towers[i].fourVector.phi(),towers[i].fourVector.eta()) < TAU_CONE_ENERGY)) {
244 Energie += towers[i].fourVector.E;
245 }
246 }
247 return Energie;
248}
249
250
251// **********Provides the number of tracks in the cone of radius TAU_CONE_TRACKS for the tau identification********
252// to be taken into account, a track should
253// 1) avec a transverse momentum \$f p_T \$ above a given threshold
254// 2) be inside a cone with a radius R and the axis defined by (eta,phi)
255// IMPORTANT REMARK !!!!!
256// previously, the argument 'phi' was before the argument 'eta'
257// this has been changed for consistency with the other functions
258// double check your running code that uses NumTracks !
259unsigned int RESOLution::NumTracks(const vector<TLorentzVector> &tracks, const float pt_track, const float eta, const float phi) {
260 unsigned int numtrack=0;
261 for(unsigned int i=0; i < tracks.size(); i++) {
262 if((tracks[i].Pt() < pt_track )||
263 (DeltaR(phi,eta,tracks[i].Phi(),tracks[i].Eta()) > TAU_CONE_TRACKS)
264 )continue;
265 numtrack++;
266 }
267 return numtrack;
268}
269
270
271//*** Returns the PID of the particle with the highest energy, in a cone with a radius CONERADIUS and an axis (eta,phi) *********
272//used by Btaggedjet
273///// Attention : bug removed => CONERADIUS/2 -> CONERADIUS !!
274int RESOLution::Bjets(const TSimpleArray<TRootGenParticle> &subarray, const float eta, const float phi) {
275 float emax=0;
276 int Ppid=0;
277 if(subarray.GetEntries()>0) {
278 for(int i=0; i < subarray.GetEntries();i++) { // should have pt>PT_JETMIN and a small cone radius (r<CONE_JET)
279 float genDeltaR = DeltaR(subarray[i]->Phi,subarray[i]->Eta,phi,eta);
280 if(genDeltaR < CONERADIUS && subarray[i]->E > emax) {
281 emax=subarray[i]->E;
282 Ppid=abs(subarray[i]->PID);
283 }
284 }
285 }
286 return Ppid;
287}
288
289
290//******************** Simulates the b-tagging efficiency for real bjet, or the misendentification for other jets****************
291bool RESOLution::Btaggedjet(const TLorentzVector &JET, const TSimpleArray<TRootGenParticle> &subarray) {
292 if( rand()%100 < (TAGGING_B+1) && Bjets(subarray,JET.Eta(),JET.Phi())==pB ) return true; // b-tag of b-jets is 40%
293 else if( rand()%100 < (MISTAGGING_C+1) && Bjets(subarray,JET.Eta(),JET.Phi())==pC ) return true; // b-tag of c-jets is 10%
294 else if( rand()%100 < (MISTAGGING_L+1) && Bjets(subarray,JET.Eta(),JET.Phi())!=0) return true; // b-tag of light jets is 1%
295 return false;
296}
297
298//**************************** Returns the delta Phi ****************************
299float DeltaPhi(const float phi1, const float phi2) {
300 float deltaphi=phi1-phi2; // in here, -PI < phi < PI
301 if(fabs(deltaphi) > PI) deltaphi=2.*PI-fabs(deltaphi);// put deltaphi between 0 and PI
302 else deltaphi=fabs(deltaphi);
303
304 return deltaphi;
305}
306
307//**************************** Returns the delta R****************************
308float DeltaR(const float phi1, const float eta1, const float phi2, const float eta2) {
309 return sqrt(pow(DeltaPhi(phi1,phi2),2) + pow(eta1-eta2,2));
310}
311
312int sign(const int myint) {
313 if (myint >0) return 1;
314 else if (myint <0) return -1;
315 else return 0;
316}
317
318int sign(const float myfloat) {
319 if (myfloat >0) return 1;
320 else if (myfloat <0) return -1;
321 else return 0;
322}
323
324
325float Charge(const long int pid) {
326 // source: RPP chap 34 Monte Carlo Particle Numbering Scheme
327/* switch (abs(pid)) {
328 case 1: case 3: case 5: case 7: return (float) sign(pid)*(-1/3); break; // d, s, b, b'
329 case 2: case 4: case 6: case 8: return (float) sign(pid)*2/3; break; // u, c, t, t'
330
331 case 11: case 13: case 15: return (float) sign(pid)*(-1); break; // e, mu, tau
332 case 12: case 14: case 16: return (float) 0; break; // nu_e, nu_mu, nu_tau
333
334 case 9: case 21: case 22: case 23: case 25:
335 case 32: case 33: case 35: case 36: return (float) 0; break; // neutral gauge/higgs bosons
336 case 24: case 34: case 37: return (float) sign(pid); break; // charged gauge/higgs bosons
337 }
338*/
339 return 0;
340}
Note: See TracBrowser for help on using the repository browser.