Fork me on GitHub

source: git/modules/EnergyLoss.cc@ 6777565

Timing
Last change on this file since 6777565 was 6777565, checked in by michele <michele.selvaggi@…>, 5 years ago

truncated mean implementation of dedx

  • Property mode set to 100644
File size: 7.9 KB
RevLine 
[b982244]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
[6777565]19 /** \class EnergyLoss
20 *
21 * This module computes the charged energy loss according to the active material properties.
22 * The energy loss is simulated with a Landau convoluted by a Gaussian.
23 *
24 * \author M. Selvaggi - CERN
25 *
26 */
[b982244]27#include "modules/EnergyLoss.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
[6777565]54EnergyLoss::EnergyLoss()
[b982244]55{
56}
57
58//------------------------------------------------------------------------------
59
60EnergyLoss::~EnergyLoss()
61{
62}
63
64//------------------------------------------------------------------------------
65
66void EnergyLoss::Init()
67{
68
[6777565]69 fActiveFraction = GetDouble("ActiveFraction", 0.002); // active fraction of the detector
70 fThickness = GetDouble("Thickness", 200E-6); // active detector thickness
71 fResolution = GetDouble("Resolution", 0.4); // 0 - perfect Landau energy loss (0.15 gives good agreement with CMS pixel detector)
72 fTruncatedMeanFraction = GetDouble("TruncatedMeanFraction", 0.5); // fraction of measurements to ignore when computing mean
[b982244]73
74 // active material properties (cf. http://pdg.lbl.gov/2014/AtomicNuclearProperties/properties8.dat)
[6777565]75 fZ = GetDouble("Z", 14.);
76 fA = GetDouble("A", 28.0855); // in g/mol
77 fRho = GetDouble("rho", 2.329); // in g/cm3
78 fAa = GetDouble("a", 0.1492);
79 fM = GetDouble("m", 3.2546);
80 fX0 = GetDouble("x0", 0.2015);
81 fX1 = GetDouble("x1", 2.8716);
82 fI = GetDouble("I", 173.0); // mean excitation potential in (eV)
83 fX0 = GetDouble("c0", 4.4355);
[b982244]84
85 // import arrays with output from other modules
86
87 ExRootConfParam param = GetParam("InputArray");
88 Long_t i, size;
89 const TObjArray *array;
90 TIterator *iterator;
91
92 size = param.GetSize();
93 for(i = 0; i < size; ++i)
94 {
95 array = ImportArray(param[i].GetString());
96 iterator = array->MakeIterator();
97
98 fInputList.push_back(iterator);
99 }
100
101}
102
103//------------------------------------------------------------------------------
104
105void EnergyLoss::Finish()
106{
107 vector<TIterator *>::iterator itInputList;
108 TIterator *iterator;
109
110 for(itInputList = fInputList.begin(); itInputList != fInputList.end(); ++itInputList)
111 {
112 iterator = *itInputList;
113 if(iterator) delete iterator;
114 }
115
116}
117
118//------------------------------------------------------------------------------
119
120void EnergyLoss::Process()
121{
[6777565]122 Candidate *candidate, *particle;
[b982244]123 vector<TIterator *>::iterator itInputList;
124 TIterator *iterator;
125
[6777565]126 Double_t beta, gamma, charge;
127 Double_t kappa, chi, me, I, Wmax, delta, avdE, dP, dx, L, dE, dEdx, res;
128 Double_t eloss_truncmean;
129
130 Int_t nhits;
131 vector<Double_t> elosses;
[b982244]132
[6777565]133 cout<<"---------------- new event -------------------"<<endl;
[b982244]134
135
136 // loop over all input arrays
137 for(itInputList = fInputList.begin(); itInputList != fInputList.end(); ++itInputList)
138 {
139 iterator = *itInputList;
140
141 // loop over all candidates
142 iterator->Reset();
143 while((candidate = static_cast<Candidate *>(iterator->Next())))
144 {
[6777565]145 cout<<" ---------------- new candidate -------------------"<<endl;
[b982244]146 const TLorentzVector &candidateMomentum = candidate->Momentum;
147
[6777565]148 beta = candidateMomentum.Beta();
149 gamma = candidateMomentum.Gamma();
[b982244]150 charge = TMath::Abs(candidate->Charge);
151
152 // length of the track normalized by the fraction of active material and the charge collection efficiency in the tracker (in cm)
[6777565]153 //dx = candidate->L * fActiveFraction * 0.1;
154 // amount of material in one sensor (converted in cm)
155 dx = fThickness * 100.;
156 // path length in cm
157 L = candidate->L * 0.1;
158
159
160 // compute number of hits as path length over active length
161 nhits = Int_t(L*fActiveFraction/dx);
162
163 //cout<<L<<","<<fActiveFraction<<","<<dx<<","<<nhits<<endl;
[b982244]164
[6777565]165 kappa = 2*0.1535*TMath::Abs(charge)*TMath::Abs(charge)*fZ*fRho*dx/(fA*beta*beta); //energy loss in MeV
[b982244]166
167 chi = 0.5*kappa;
[6777565]168 me = 0.510998; // electron mass in MeV, need
[b982244]169 I = fI*1e-6; // convert I in MeV
170
171 // fixme: max energy transfer wrong for electrons
172 Wmax = 2*me*beta*beta*gamma*gamma; // this is not valid for electrons
173
[6777565]174 delta = Deltaf(fC0, fAa, fM, fX0, fX1, beta, gamma);
[b982244]175
176 // Bethe-Bloch energy loss in MeV (not used here)
177 avdE = kappa*( TMath::Log(Wmax/I) - beta*beta - delta/2);
178
[6777565]179 // most probable energy (MPV) loss for Landau in a single layer
[b982244]180 dP = chi*( TMath::Log(Wmax/I) + TMath::Log(chi/I) + 0.2 - beta*beta - delta);
181
[6777565]182 if (candidateMomentum.Pt() > 5) {
183 cout<<"Nhits: "<<nhits<<", dx: "<<dx<<", Charge: "<<charge<<", Beta: "<< beta<<", Gamma: "<<gamma<<", PT: "<<candidateMomentum.Pt()<<endl;
[b982244]184 //cout<<x<<","<<kappa<<endl;
[6777565]185 cout<<" Wmax: "<<Wmax<<", Chi: "<<chi<<", delta: "<<delta<<", DeDx: "<<avdE<<", DeltaP: "<<dP<<endl;
186 }
187
188 // simulate Nhits energy loss measurements
189 elosses.clear();
190 for (Int_t j=0; j<nhits; j++){
191 // compute total energy loss in MeV predicted by a Landau
192 dE = gRandom->Landau(dP,chi); // this is the total energy loss in MeV predicted by a Landau
193
194 // convert resolution given in Mev/cm into absolute for this sensor
195 res = fResolution*dx;
[b982244]196
[6777565]197 // apply additionnal gaussian smearing
198 dE = gRandom->Gaus(dE,res);
199 elosses.push_back(dE);
200 }
[b982244]201
[6777565]202 sort (elosses.begin(), elosses.end());
203 eloss_truncmean = TruncatedMean(elosses, fTruncatedMeanFraction);
204
205
206 dEdx = dx > 0 ? eloss_truncmean/dx : -1. ;
[b982244]207
208 // store computed dEdx in MeV/cm
[6777565]209 candidate->DeDx = dEdx;
210
[b982244]211 // add dedx also in Muons in electrons classes in treeWriter
212 // fix electrons here
213 // think whether any relevance for hits
214
[6777565]215
[b982244]216 //cout<<" eloss: "<<dE<<", dx: "<<dx<<", dEdx: "<<dEdx<<endl;
217 }
218 }
219
220}
221
222//------------------------------------------------------------------------------
223
224// formula Taken from Leo (2.30) pg. 26
225Double_t EnergyLoss::Deltaf(Double_t c0, Double_t a, Double_t m, Double_t x0, Double_t x1, Double_t beta, Double_t gamma)
226{
227 Double_t x= TMath::Log10(beta*gamma);
228 Double_t delta = 0.;
[6777565]229
[b982244]230 //cout<<x<<","<<x0<<","<<x1<<","<<endl;
[6777565]231
[b982244]232 if (x < x0)
233 delta = 0.;
234 if (x >= x0 && x< x1)
235 delta = 4.6052*x - c0 + a*TMath::Power(x1 - x,m);
236 if (x> x1)
237 delta = 4.6052*x - c0;
[6777565]238
[b982244]239 return delta;
240}
[6777565]241
242//------------------------------------------------------------------------------
243Double_t EnergyLoss::TruncatedMean(std::vector<Double_t> elosses, Double_t truncFrac)
244{
245 Int_t new_size = Int_t( elosses.size() * (1 - truncFrac));
246
247 // remove outliers and re-compute mean
248 elosses.resize(new_size);
249 return accumulate( elosses.begin(), elosses.end(), 0.0)/elosses.size();
250}
Note: See TracBrowser for help on using the repository browser.