Fork me on GitHub

source: git/modules/DenseTrackFilter.cc@ e999d62

ImprovedOutputFile Timing dual_readout llp
Last change on this file since e999d62 was e999d62, checked in by Michele Selvaggi <michele.selvaggi@…>, 7 years ago

subtract merged tracks from existing trk coll

  • Property mode set to 100644
File size: 7.8 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
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
51using namespace std;
52
53//------------------------------------------------------------------------------
54
55DenseTrackFilter::DenseTrackFilter() :
56 fItTrackInputArray(0), fItDenseChargedInputArray(0)
57{
58}
59
60//------------------------------------------------------------------------------
61
62DenseTrackFilter::~DenseTrackFilter()
63{
64}
65
66//------------------------------------------------------------------------------
67
68void 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.005);
114
115 fTrackInputArray = ImportArray(GetString("TrackInputArray", "TrackMerger/tracks"));
116 fItTrackInputArray = fTrackInputArray->MakeIterator();
117
118 fDenseChargedInputArray = ImportArray(GetString("DenseChargedInputArray", "DenseMergeTracks/tracks"));
119 fItDenseChargedInputArray = fDenseChargedInputArray->MakeIterator();
120
121 fTrackOutputArray = ExportArray(GetString("TrackOutputArray", "tracks"));
122}
123
124//------------------------------------------------------------------------------
125
126void DenseTrackFilter::Finish()
127{
128 vector< vector< Double_t >* >::iterator itPhiBin;
129 if(fItTrackInputArray) delete fItTrackInputArray;
130 if(fItDenseChargedInputArray) delete fItDenseChargedInputArray;
131 for(itPhiBin = fPhiBins.begin(); itPhiBin != fPhiBins.end(); ++itPhiBin)
132 {
133 delete *itPhiBin;
134 }
135}
136
137//------------------------------------------------------------------------------
138
139void DenseTrackFilter::Process()
140{
141 Candidate *candidate, *track, *bestTrack, *mother, *trackRef, *bestTrackRef;
142 TLorentzVector position, momentum;
143 Short_t etaBin, phiBin, flags;
144 Int_t number, towerTrackHits;
145 Long64_t towerHit, towerEtaPhi, hitEtaPhi;
146
147 Double_t pt, ptmax, eta, phi;
148 Bool_t matched;
149
150 vector< Double_t >::iterator itEtaBin;
151 vector< Double_t >::iterator itPhiBin;
152 vector< Double_t > *phiBins;
153
154 vector< Long64_t >::iterator itTowerHits;
155
156 fTowerHits.clear();
157
158 // loop over all tracks
159 fItDenseChargedInputArray->Reset();
160 number = -1;
161 while((track = static_cast<Candidate*>(fItDenseChargedInputArray->Next())))
162 {
163 const TLorentzVector &trackPosition = track->Position;
164 ++number;
165
166 // find eta bin [1, fEtaBins.size - 1]
167 itEtaBin = lower_bound(fEtaBins.begin(), fEtaBins.end(), trackPosition.Eta());
168 if(itEtaBin == fEtaBins.begin() || itEtaBin == fEtaBins.end()) continue;
169 etaBin = distance(fEtaBins.begin(), itEtaBin);
170
171 // phi bins for given eta bin
172 phiBins = fPhiBins[etaBin];
173
174 // find phi bin [1, phiBins.size - 1]
175 itPhiBin = lower_bound(phiBins->begin(), phiBins->end(), trackPosition.Phi());
176 if(itPhiBin == phiBins->begin() || itPhiBin == phiBins->end()) continue;
177 phiBin = distance(phiBins->begin(), itPhiBin);
178
179 flags = 1;
180
181 // make tower hit {16-bits for eta bin number, 16-bits for phi bin number, 8-bits for flags, 24-bits for track number}
182 towerHit = (Long64_t(etaBin) << 48) | (Long64_t(phiBin) << 32) | (Long64_t(flags) << 24) | Long64_t(number);
183
184 fTowerHits.push_back(towerHit);
185 }
186
187 // all hits are sorted first by eta bin number, then by phi bin number,
188 // then by flags and then by particle or track number
189 sort(fTowerHits.begin(), fTowerHits.end());
190
191 // loop over all hits
192 towerEtaPhi = 0;
193 bestTrack = 0;
194 fTower = 0;
195 ptmax = 0.0;
196 towerTrackHits = 0;
197
198 for(itTowerHits = fTowerHits.begin(); itTowerHits != fTowerHits.end(); ++itTowerHits)
199 {
200 towerHit = (*itTowerHits);
201 flags = (towerHit >> 24) & 0x00000000000000FFLL;
202 number = (towerHit) & 0x0000000000FFFFFFLL;
203 hitEtaPhi = towerHit >> 32;
204 if(towerEtaPhi != hitEtaPhi)
205 {
206 // switch to next tower
207 towerEtaPhi = hitEtaPhi;
208
209 // saving track with highest pT that hit the tower
210 if(towerTrackHits > 0)
211 {
212 bestTrackRef = static_cast<Candidate*>(bestTrack->GetCandidates()->At(0));
213
214 // find corresponding track in properly propagated tracks
215
216
217 fItTrackInputArray->Reset();
218 matched = kFALSE;
219 int ntrack = 0;
220 while((track = static_cast<Candidate*>(fItTrackInputArray->Next())))
221 {
222 ntrack++;
223 trackRef = static_cast<Candidate*>(track->GetCandidates()->At(0));
224 if (trackRef->GetUniqueID() == bestTrackRef->GetUniqueID())
225 {
226 mother = track;
227 candidate = static_cast<Candidate*>(track->Clone());
228 pt = candidate->Momentum.Pt();
229 eta = candidate->Momentum.Eta();
230 phi = candidate->Momentum.Phi();
231 eta = gRandom->Gaus(eta, fEtaPhiRes);
232 phi = gRandom->Gaus(phi, fEtaPhiRes);
233 candidate->Momentum.SetPtEtaPhiE(pt, eta, phi, pt*TMath::CosH(eta));
234 candidate->AddCandidate(mother);
235 fTrackOutputArray->Add(candidate);
236 matched = kTRUE;
237 }
238 if (matched) break;
239 }
240
241 // find track
242 }
243
244 ptmax = 0.0;
245 towerTrackHits = 0;
246 bestTrack = 0;
247 }
248 // check for track hits
249
250 if(flags & 1)
251 {
252 ++towerTrackHits;
253 track = static_cast<Candidate*>(fDenseChargedInputArray->At(number));
254 momentum = track->Momentum;
255
256 if (momentum.Pt() > ptmax)
257 {
258 ptmax = momentum.Pt();
259 bestTrack = track;
260 }
261 continue;
262 }
263 }
264
265}
Note: See TracBrowser for help on using the repository browser.