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 |
|
---|
20 | /** \class DenseTrackFilter
|
---|
21 | *
|
---|
22 | * Applies reconstruction inefficiency on tracks in dense environment
|
---|
23 | *
|
---|
24 | * \author M. Selvaggi - CERN
|
---|
25 | *
|
---|
26 | */
|
---|
27 |
|
---|
28 | #include "modules/DenseTrackFilter.h"
|
---|
29 |
|
---|
30 | #include "classes/DelphesClasses.h"
|
---|
31 | #include "classes/DelphesFactory.h"
|
---|
32 | #include "classes/DelphesFormula.h"
|
---|
33 |
|
---|
34 | #include "ExRootAnalysis/ExRootResult.h"
|
---|
35 | #include "ExRootAnalysis/ExRootFilter.h"
|
---|
36 | #include "ExRootAnalysis/ExRootClassifier.h"
|
---|
37 |
|
---|
38 | #include "TMath.h"
|
---|
39 | #include "TString.h"
|
---|
40 | #include "TFormula.h"
|
---|
41 | #include "TRandom3.h"
|
---|
42 | #include "TObjArray.h"
|
---|
43 | #include "TDatabasePDG.h"
|
---|
44 | #include "TLorentzVector.h"
|
---|
45 |
|
---|
46 | #include <algorithm>
|
---|
47 | #include <stdexcept>
|
---|
48 | #include <iostream>
|
---|
49 | #include <sstream>
|
---|
50 |
|
---|
51 | using namespace std;
|
---|
52 |
|
---|
53 | //------------------------------------------------------------------------------
|
---|
54 |
|
---|
55 | DenseTrackFilter::DenseTrackFilter() :
|
---|
56 | fItTrackInputArray(0)
|
---|
57 | {
|
---|
58 | }
|
---|
59 |
|
---|
60 | //------------------------------------------------------------------------------
|
---|
61 |
|
---|
62 | DenseTrackFilter::~DenseTrackFilter()
|
---|
63 | {
|
---|
64 | }
|
---|
65 |
|
---|
66 | //------------------------------------------------------------------------------
|
---|
67 |
|
---|
68 | void DenseTrackFilter::Init()
|
---|
69 | {
|
---|
70 | ExRootConfParam param, paramEtaBins, paramPhiBins, paramFractions;
|
---|
71 | Long_t i, j, k, size, sizeEtaBins, sizePhiBins;
|
---|
72 | TBinMap::iterator itEtaBin;
|
---|
73 | set< Double_t >::iterator itPhiBin;
|
---|
74 | vector< Double_t > *phiBins;
|
---|
75 |
|
---|
76 | // read eta and phi bins
|
---|
77 | param = GetParam("EtaPhiBins");
|
---|
78 | size = param.GetSize();
|
---|
79 | fBinMap.clear();
|
---|
80 | fEtaBins.clear();
|
---|
81 | fPhiBins.clear();
|
---|
82 | for(i = 0; i < size/2; ++i)
|
---|
83 | {
|
---|
84 | paramEtaBins = param[i*2];
|
---|
85 | sizeEtaBins = paramEtaBins.GetSize();
|
---|
86 | paramPhiBins = param[i*2 + 1];
|
---|
87 | sizePhiBins = paramPhiBins.GetSize();
|
---|
88 |
|
---|
89 | for(j = 0; j < sizeEtaBins; ++j)
|
---|
90 | {
|
---|
91 | for(k = 0; k < sizePhiBins; ++k)
|
---|
92 | {
|
---|
93 | fBinMap[paramEtaBins[j].GetDouble()].insert(paramPhiBins[k].GetDouble());
|
---|
94 | }
|
---|
95 | }
|
---|
96 | }
|
---|
97 |
|
---|
98 | // for better performance we transform map of sets to parallel vectors:
|
---|
99 | // vector< double > and vector< vector< double >* >
|
---|
100 | for(itEtaBin = fBinMap.begin(); itEtaBin != fBinMap.end(); ++itEtaBin)
|
---|
101 | {
|
---|
102 | fEtaBins.push_back(itEtaBin->first);
|
---|
103 | phiBins = new vector< double >(itEtaBin->second.size());
|
---|
104 | fPhiBins.push_back(phiBins);
|
---|
105 | phiBins->clear();
|
---|
106 | for(itPhiBin = itEtaBin->second.begin(); itPhiBin != itEtaBin->second.end(); ++itPhiBin)
|
---|
107 | {
|
---|
108 | phiBins->push_back(*itPhiBin);
|
---|
109 | }
|
---|
110 | }
|
---|
111 |
|
---|
112 | // Eta x Phi smearing to be applied
|
---|
113 | fEtaPhiRes = GetDouble("EtaPhiRes", 0.003);
|
---|
114 |
|
---|
115 | fTrackInputArray = ImportArray(GetString("TrackInputArray", "TrackMergerProp/tracks"));
|
---|
116 | fItTrackInputArray = fTrackInputArray->MakeIterator();
|
---|
117 |
|
---|
118 | fTrackOutputArray = ExportArray(GetString("TrackOutputArray", "tracks"));
|
---|
119 | fChargedHadronOutputArray = ExportArray(GetString("ChargedHadronOutputArray", "chargedHadrons"));
|
---|
120 | fElectronOutputArray = ExportArray(GetString("ElectronOutputArray", "electrons"));
|
---|
121 | fMuonOutputArray = ExportArray(GetString("MuonOutputArray", "muons"));
|
---|
122 | }
|
---|
123 |
|
---|
124 | //------------------------------------------------------------------------------
|
---|
125 |
|
---|
126 | void DenseTrackFilter::Finish()
|
---|
127 | {
|
---|
128 | vector< vector< Double_t >* >::iterator itPhiBin;
|
---|
129 | if(fItTrackInputArray) delete fItTrackInputArray;
|
---|
130 | for(itPhiBin = fPhiBins.begin(); itPhiBin != fPhiBins.end(); ++itPhiBin)
|
---|
131 | {
|
---|
132 | delete *itPhiBin;
|
---|
133 | }
|
---|
134 | }
|
---|
135 |
|
---|
136 | //------------------------------------------------------------------------------
|
---|
137 |
|
---|
138 | void DenseTrackFilter::Process()
|
---|
139 | {
|
---|
140 | Candidate *track;
|
---|
141 | TLorentzVector position, momentum;
|
---|
142 | Short_t etaBin, phiBin, flags;
|
---|
143 | Int_t number;
|
---|
144 | Long64_t towerHit, towerEtaPhi, hitEtaPhi;
|
---|
145 | Double_t ptmax;
|
---|
146 |
|
---|
147 | vector< Double_t >::iterator itEtaBin;
|
---|
148 | vector< Double_t >::iterator itPhiBin;
|
---|
149 | vector< Double_t > *phiBins;
|
---|
150 |
|
---|
151 | vector< Long64_t >::iterator itTowerHits;
|
---|
152 |
|
---|
153 | fTowerHits.clear();
|
---|
154 |
|
---|
155 | // loop over all tracks
|
---|
156 | fItTrackInputArray->Reset();
|
---|
157 | number = -1;
|
---|
158 | while((track = static_cast<Candidate*>(fItTrackInputArray->Next())))
|
---|
159 | {
|
---|
160 | const TLorentzVector &trackPosition = track->Position;
|
---|
161 | ++number;
|
---|
162 |
|
---|
163 | // find eta bin [1, fEtaBins.size - 1]
|
---|
164 | itEtaBin = lower_bound(fEtaBins.begin(), fEtaBins.end(), trackPosition.Eta());
|
---|
165 | if(itEtaBin == fEtaBins.begin() || itEtaBin == fEtaBins.end()) continue;
|
---|
166 | etaBin = distance(fEtaBins.begin(), itEtaBin);
|
---|
167 |
|
---|
168 | // phi bins for given eta bin
|
---|
169 | phiBins = fPhiBins[etaBin];
|
---|
170 |
|
---|
171 | // find phi bin [1, phiBins.size - 1]
|
---|
172 | itPhiBin = lower_bound(phiBins->begin(), phiBins->end(), trackPosition.Phi());
|
---|
173 | if(itPhiBin == phiBins->begin() || itPhiBin == phiBins->end()) continue;
|
---|
174 | phiBin = distance(phiBins->begin(), itPhiBin);
|
---|
175 |
|
---|
176 | flags = 1;
|
---|
177 |
|
---|
178 | // make tower hit {16-bits for eta bin number, 16-bits for phi bin number, 8-bits for flags, 24-bits for track number}
|
---|
179 | towerHit = (Long64_t(etaBin) << 48) | (Long64_t(phiBin) << 32) | (Long64_t(flags) << 24) | Long64_t(number);
|
---|
180 |
|
---|
181 | fTowerHits.push_back(towerHit);
|
---|
182 | }
|
---|
183 |
|
---|
184 | // all hits are sorted first by eta bin number, then by phi bin number,
|
---|
185 | // then by flags and then by particle or track number
|
---|
186 | sort(fTowerHits.begin(), fTowerHits.end());
|
---|
187 |
|
---|
188 | // loop over all hits
|
---|
189 | towerEtaPhi = 0;
|
---|
190 | fBestTrack = 0;
|
---|
191 | ptmax = 0.0;
|
---|
192 | fTowerTrackHits = 0;
|
---|
193 |
|
---|
194 | for(itTowerHits = fTowerHits.begin(); itTowerHits != fTowerHits.end(); ++itTowerHits)
|
---|
195 | {
|
---|
196 | towerHit = (*itTowerHits);
|
---|
197 | flags = (towerHit >> 24) & 0x00000000000000FFLL;
|
---|
198 | number = (towerHit) & 0x0000000000FFFFFFLL;
|
---|
199 | hitEtaPhi = towerHit >> 32;
|
---|
200 |
|
---|
201 | if(towerEtaPhi != hitEtaPhi)
|
---|
202 | {
|
---|
203 | // switch to next tower
|
---|
204 | towerEtaPhi = hitEtaPhi;
|
---|
205 |
|
---|
206 | // saving track with highest pT that hit the tower
|
---|
207 | FillTrack();
|
---|
208 |
|
---|
209 | ptmax = 0.0;
|
---|
210 | fTowerTrackHits = 0;
|
---|
211 | fBestTrack = 0;
|
---|
212 | }
|
---|
213 | // check for track hits
|
---|
214 |
|
---|
215 | if(flags & 1)
|
---|
216 | {
|
---|
217 | ++fTowerTrackHits;
|
---|
218 | track = static_cast<Candidate*>(fTrackInputArray->At(number));
|
---|
219 | momentum = track->Momentum;
|
---|
220 |
|
---|
221 | if(momentum.Pt() > ptmax)
|
---|
222 | {
|
---|
223 | ptmax = momentum.Pt();
|
---|
224 | fBestTrack = track;
|
---|
225 | }
|
---|
226 | continue;
|
---|
227 | }
|
---|
228 |
|
---|
229 | }
|
---|
230 |
|
---|
231 | // here fill last tower
|
---|
232 | FillTrack();
|
---|
233 |
|
---|
234 | }
|
---|
235 |
|
---|
236 | //------------------------------------------------------------------------------
|
---|
237 |
|
---|
238 | void DenseTrackFilter::FillTrack()
|
---|
239 | {
|
---|
240 |
|
---|
241 | Candidate *candidate, *track;
|
---|
242 | Double_t pt, eta, phi;
|
---|
243 | Int_t numberOfCandidates;
|
---|
244 |
|
---|
245 | // saving track with highest pT that hit the tower
|
---|
246 | if(fTowerTrackHits < 1) return;
|
---|
247 |
|
---|
248 | numberOfCandidates = fBestTrack->GetCandidates()->GetEntriesFast();
|
---|
249 | if(numberOfCandidates < 1) return;
|
---|
250 |
|
---|
251 | track = static_cast<Candidate*>(fBestTrack->GetCandidates()->At(numberOfCandidates - 1));
|
---|
252 | candidate = static_cast<Candidate*>(track->Clone());
|
---|
253 | pt = candidate->Momentum.Pt();
|
---|
254 | eta = candidate->Momentum.Eta();
|
---|
255 | phi = candidate->Momentum.Phi();
|
---|
256 | eta = gRandom->Gaus(eta, fEtaPhiRes);
|
---|
257 | phi = gRandom->Gaus(phi, fEtaPhiRes);
|
---|
258 | candidate->Momentum.SetPtEtaPhiE(pt, eta, phi, pt*TMath::CosH(eta));
|
---|
259 | candidate->AddCandidate(track);
|
---|
260 |
|
---|
261 | fTrackOutputArray->Add(candidate);
|
---|
262 | switch(TMath::Abs(candidate->PID))
|
---|
263 | {
|
---|
264 | case 11:
|
---|
265 | fElectronOutputArray->Add(candidate);
|
---|
266 | break;
|
---|
267 | case 13:
|
---|
268 | fMuonOutputArray->Add(candidate);
|
---|
269 | break;
|
---|
270 | default:
|
---|
271 | fChargedHadronOutputArray->Add(candidate);
|
---|
272 | }
|
---|
273 | }
|
---|