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 SimpleCalorimeter
|
---|
21 | *
|
---|
22 | * Fills SimpleCalorimeter towers, performs SimpleCalorimeter resolution smearing,
|
---|
23 | * and creates energy flow objects (tracks, photons, and neutral hadrons).
|
---|
24 | *
|
---|
25 | * \author P. Demin - UCL, Louvain-la-Neuve
|
---|
26 | *
|
---|
27 | */
|
---|
28 |
|
---|
29 | #include "modules/SimpleCalorimeter.h"
|
---|
30 |
|
---|
31 | #include "classes/DelphesClasses.h"
|
---|
32 | #include "classes/DelphesFactory.h"
|
---|
33 | #include "classes/DelphesFormula.h"
|
---|
34 |
|
---|
35 | #include "ExRootAnalysis/ExRootResult.h"
|
---|
36 | #include "ExRootAnalysis/ExRootFilter.h"
|
---|
37 | #include "ExRootAnalysis/ExRootClassifier.h"
|
---|
38 |
|
---|
39 | #include "TMath.h"
|
---|
40 | #include "TString.h"
|
---|
41 | #include "TFormula.h"
|
---|
42 | #include "TRandom3.h"
|
---|
43 | #include "TObjArray.h"
|
---|
44 | #include "TDatabasePDG.h"
|
---|
45 | #include "TLorentzVector.h"
|
---|
46 |
|
---|
47 | #include <algorithm>
|
---|
48 | #include <stdexcept>
|
---|
49 | #include <iostream>
|
---|
50 | #include <sstream>
|
---|
51 |
|
---|
52 | using namespace std;
|
---|
53 |
|
---|
54 | //------------------------------------------------------------------------------
|
---|
55 |
|
---|
56 | SimpleCalorimeter::SimpleCalorimeter() :
|
---|
57 | fResolutionFormula(0),
|
---|
58 | fItParticleInputArray(0), fItTrackInputArray(0),
|
---|
59 | fTowerTrackArray(0), fItTowerTrackArray(0)
|
---|
60 | {
|
---|
61 | fResolutionFormula = new DelphesFormula;
|
---|
62 |
|
---|
63 | fTowerTrackArray = new TObjArray;
|
---|
64 | fItTowerTrackArray = fTowerTrackArray->MakeIterator();
|
---|
65 | }
|
---|
66 |
|
---|
67 | //------------------------------------------------------------------------------
|
---|
68 |
|
---|
69 | SimpleCalorimeter::~SimpleCalorimeter()
|
---|
70 | {
|
---|
71 | if(fResolutionFormula) delete fResolutionFormula;
|
---|
72 |
|
---|
73 | if(fTowerTrackArray) delete fTowerTrackArray;
|
---|
74 | if(fItTowerTrackArray) delete fItTowerTrackArray;
|
---|
75 | }
|
---|
76 |
|
---|
77 | //------------------------------------------------------------------------------
|
---|
78 |
|
---|
79 | void SimpleCalorimeter::Init()
|
---|
80 | {
|
---|
81 | ExRootConfParam param, paramEtaBins, paramPhiBins, paramFractions;
|
---|
82 | Long_t i, j, k, size, sizeEtaBins, sizePhiBins;
|
---|
83 | Double_t fraction;
|
---|
84 | TBinMap::iterator itEtaBin;
|
---|
85 | set< Double_t >::iterator itPhiBin;
|
---|
86 | vector< Double_t > *phiBins;
|
---|
87 |
|
---|
88 | // read eta and phi bins
|
---|
89 | param = GetParam("EtaPhiBins");
|
---|
90 | size = param.GetSize();
|
---|
91 | fBinMap.clear();
|
---|
92 | fEtaBins.clear();
|
---|
93 | fPhiBins.clear();
|
---|
94 | for(i = 0; i < size/2; ++i)
|
---|
95 | {
|
---|
96 | paramEtaBins = param[i*2];
|
---|
97 | sizeEtaBins = paramEtaBins.GetSize();
|
---|
98 | paramPhiBins = param[i*2 + 1];
|
---|
99 | sizePhiBins = paramPhiBins.GetSize();
|
---|
100 |
|
---|
101 | for(j = 0; j < sizeEtaBins; ++j)
|
---|
102 | {
|
---|
103 | for(k = 0; k < sizePhiBins; ++k)
|
---|
104 | {
|
---|
105 | fBinMap[paramEtaBins[j].GetDouble()].insert(paramPhiBins[k].GetDouble());
|
---|
106 | }
|
---|
107 | }
|
---|
108 | }
|
---|
109 |
|
---|
110 | // for better performance we transform map of sets to parallel vectors:
|
---|
111 | // vector< double > and vector< vector< double >* >
|
---|
112 | for(itEtaBin = fBinMap.begin(); itEtaBin != fBinMap.end(); ++itEtaBin)
|
---|
113 | {
|
---|
114 | fEtaBins.push_back(itEtaBin->first);
|
---|
115 | phiBins = new vector< double >(itEtaBin->second.size());
|
---|
116 | fPhiBins.push_back(phiBins);
|
---|
117 | phiBins->clear();
|
---|
118 | for(itPhiBin = itEtaBin->second.begin(); itPhiBin != itEtaBin->second.end(); ++itPhiBin)
|
---|
119 | {
|
---|
120 | phiBins->push_back(*itPhiBin);
|
---|
121 | }
|
---|
122 | }
|
---|
123 |
|
---|
124 | // read energy fractions for different particles
|
---|
125 | param = GetParam("EnergyFraction");
|
---|
126 | size = param.GetSize();
|
---|
127 |
|
---|
128 | // set default energy fractions values
|
---|
129 | fFractionMap.clear();
|
---|
130 | fFractionMap[0] = 1.0;
|
---|
131 |
|
---|
132 | for(i = 0; i < size/2; ++i)
|
---|
133 | {
|
---|
134 | paramFractions = param[i*2 + 1];
|
---|
135 | fraction = paramFractions[0].GetDouble();
|
---|
136 | fFractionMap[param[i*2].GetInt()] = fraction;
|
---|
137 | }
|
---|
138 | /*
|
---|
139 | TFractionMap::iterator itFractionMap;
|
---|
140 | for(itFractionMap = fFractionMap.begin(); itFractionMap != fFractionMap.end(); ++itFractionMap)
|
---|
141 | {
|
---|
142 | cout << itFractionMap->first << " " << itFractionMap->second.first << " " << itFractionMap->second.second << endl;
|
---|
143 | }
|
---|
144 | */
|
---|
145 |
|
---|
146 | // read min E value for towers to be saved
|
---|
147 | fEnergyMin = GetDouble("TowerMinEnergy", 0.0);
|
---|
148 | fSigmaMin = GetDouble("TowerMinSignificance", 0.0);
|
---|
149 |
|
---|
150 | // read resolution formulas
|
---|
151 | fResolutionFormula->Compile(GetString("ResolutionFormula", "0"));
|
---|
152 |
|
---|
153 | // import array with output from other modules
|
---|
154 | fParticleInputArray = ImportArray(GetString("ParticleInputArray", "ParticlePropagator/particles"));
|
---|
155 | fItParticleInputArray = fParticleInputArray->MakeIterator();
|
---|
156 |
|
---|
157 | fTrackInputArray = ImportArray(GetString("TrackInputArray", "ParticlePropagator/tracks"));
|
---|
158 | fItTrackInputArray = fTrackInputArray->MakeIterator();
|
---|
159 |
|
---|
160 | // create output arrays
|
---|
161 | fTowerOutputArray = ExportArray(GetString("TowerOutputArray", "towers"));
|
---|
162 | fEFlowTowerOutputArray = ExportArray(GetString("EFlowTowerOutputArray", "eflowTowers"));
|
---|
163 |
|
---|
164 | }
|
---|
165 |
|
---|
166 | //------------------------------------------------------------------------------
|
---|
167 |
|
---|
168 | void SimpleCalorimeter::Finish()
|
---|
169 | {
|
---|
170 | vector< vector< Double_t >* >::iterator itPhiBin;
|
---|
171 | if(fItParticleInputArray) delete fItParticleInputArray;
|
---|
172 | if(fItTrackInputArray) delete fItTrackInputArray;
|
---|
173 | for(itPhiBin = fPhiBins.begin(); itPhiBin != fPhiBins.end(); ++itPhiBin)
|
---|
174 | {
|
---|
175 | delete *itPhiBin;
|
---|
176 | }
|
---|
177 | }
|
---|
178 |
|
---|
179 | //------------------------------------------------------------------------------
|
---|
180 |
|
---|
181 | void SimpleCalorimeter::Process()
|
---|
182 | {
|
---|
183 | Candidate *particle, *track;
|
---|
184 | TLorentzVector position, momentum;
|
---|
185 | Short_t etaBin, phiBin, flags;
|
---|
186 | Int_t number;
|
---|
187 | Long64_t towerHit, towerEtaPhi, hitEtaPhi;
|
---|
188 | Double_t fraction;
|
---|
189 | Double_t energy;
|
---|
190 | Int_t pdgCode;
|
---|
191 |
|
---|
192 | TFractionMap::iterator itFractionMap;
|
---|
193 |
|
---|
194 | vector< Double_t >::iterator itEtaBin;
|
---|
195 | vector< Double_t >::iterator itPhiBin;
|
---|
196 | vector< Double_t > *phiBins;
|
---|
197 |
|
---|
198 | vector< Long64_t >::iterator itTowerHits;
|
---|
199 |
|
---|
200 | DelphesFactory *factory = GetFactory();
|
---|
201 | fTowerHits.clear();
|
---|
202 | fTowerFractions.clear();
|
---|
203 | fTrackFractions.clear();
|
---|
204 |
|
---|
205 | // loop over all particles
|
---|
206 | fItParticleInputArray->Reset();
|
---|
207 | number = -1;
|
---|
208 | while((particle = static_cast<Candidate*>(fItParticleInputArray->Next())))
|
---|
209 | {
|
---|
210 | const TLorentzVector &particlePosition = particle->Position;
|
---|
211 | ++number;
|
---|
212 |
|
---|
213 | pdgCode = TMath::Abs(particle->PID);
|
---|
214 |
|
---|
215 | itFractionMap = fFractionMap.find(pdgCode);
|
---|
216 | if(itFractionMap == fFractionMap.end())
|
---|
217 | {
|
---|
218 | itFractionMap = fFractionMap.find(0);
|
---|
219 | }
|
---|
220 |
|
---|
221 | fraction = itFractionMap->second;
|
---|
222 | fTowerFractions.push_back(fraction);
|
---|
223 |
|
---|
224 | if(fraction < 1.0E-9) continue;
|
---|
225 |
|
---|
226 | // find eta bin [1, fEtaBins.size - 1]
|
---|
227 | itEtaBin = lower_bound(fEtaBins.begin(), fEtaBins.end(), particlePosition.Eta());
|
---|
228 | if(itEtaBin == fEtaBins.begin() || itEtaBin == fEtaBins.end()) continue;
|
---|
229 | etaBin = distance(fEtaBins.begin(), itEtaBin);
|
---|
230 |
|
---|
231 | // phi bins for given eta bin
|
---|
232 | phiBins = fPhiBins[etaBin];
|
---|
233 |
|
---|
234 | // find phi bin [1, phiBins.size - 1]
|
---|
235 | itPhiBin = lower_bound(phiBins->begin(), phiBins->end(), particlePosition.Phi());
|
---|
236 | if(itPhiBin == phiBins->begin() || itPhiBin == phiBins->end()) continue;
|
---|
237 | phiBin = distance(phiBins->begin(), itPhiBin);
|
---|
238 |
|
---|
239 | flags = 0;
|
---|
240 | flags |= (pdgCode == 11 || pdgCode == 22) << 1;
|
---|
241 |
|
---|
242 | // make tower hit {16-bits for eta bin number, 16-bits for phi bin number, 8-bits for flags, 24-bits for particle number}
|
---|
243 | towerHit = (Long64_t(etaBin) << 48) | (Long64_t(phiBin) << 32) | (Long64_t(flags) << 24) | Long64_t(number);
|
---|
244 |
|
---|
245 | fTowerHits.push_back(towerHit);
|
---|
246 | }
|
---|
247 |
|
---|
248 | // loop over all tracks
|
---|
249 | fItTrackInputArray->Reset();
|
---|
250 | number = -1;
|
---|
251 | while((track = static_cast<Candidate*>(fItTrackInputArray->Next())))
|
---|
252 | {
|
---|
253 | const TLorentzVector &trackPosition = track->Position;
|
---|
254 | ++number;
|
---|
255 |
|
---|
256 | pdgCode = TMath::Abs(track->PID);
|
---|
257 |
|
---|
258 | itFractionMap = fFractionMap.find(pdgCode);
|
---|
259 | if(itFractionMap == fFractionMap.end())
|
---|
260 | {
|
---|
261 | itFractionMap = fFractionMap.find(0);
|
---|
262 | }
|
---|
263 |
|
---|
264 | fraction = itFractionMap->second;
|
---|
265 |
|
---|
266 | fTrackFractions.push_back(fraction);
|
---|
267 |
|
---|
268 | // find eta bin [1, fEtaBins.size - 1]
|
---|
269 | itEtaBin = lower_bound(fEtaBins.begin(), fEtaBins.end(), trackPosition.Eta());
|
---|
270 | if(itEtaBin == fEtaBins.begin() || itEtaBin == fEtaBins.end()) continue;
|
---|
271 | etaBin = distance(fEtaBins.begin(), itEtaBin);
|
---|
272 |
|
---|
273 | // phi bins for given eta bin
|
---|
274 | phiBins = fPhiBins[etaBin];
|
---|
275 |
|
---|
276 | // find phi bin [1, phiBins.size - 1]
|
---|
277 | itPhiBin = lower_bound(phiBins->begin(), phiBins->end(), trackPosition.Phi());
|
---|
278 | if(itPhiBin == phiBins->begin() || itPhiBin == phiBins->end()) continue;
|
---|
279 | phiBin = distance(phiBins->begin(), itPhiBin);
|
---|
280 |
|
---|
281 | flags = 1;
|
---|
282 |
|
---|
283 | // make tower hit {16-bits for eta bin number, 16-bits for phi bin number, 8-bits for flags, 24-bits for track number}
|
---|
284 | towerHit = (Long64_t(etaBin) << 48) | (Long64_t(phiBin) << 32) | (Long64_t(flags) << 24) | Long64_t(number);
|
---|
285 |
|
---|
286 | fTowerHits.push_back(towerHit);
|
---|
287 | }
|
---|
288 |
|
---|
289 | // all hits are sorted first by eta bin number, then by phi bin number,
|
---|
290 | // then by flags and then by particle or track number
|
---|
291 | sort(fTowerHits.begin(), fTowerHits.end());
|
---|
292 |
|
---|
293 | // loop over all hits
|
---|
294 | towerEtaPhi = 0;
|
---|
295 | fTower = 0;
|
---|
296 | for(itTowerHits = fTowerHits.begin(); itTowerHits != fTowerHits.end(); ++itTowerHits)
|
---|
297 | {
|
---|
298 | towerHit = (*itTowerHits);
|
---|
299 | flags = (towerHit >> 24) & 0x00000000000000FFLL;
|
---|
300 | number = (towerHit) & 0x0000000000FFFFFFLL;
|
---|
301 | hitEtaPhi = towerHit >> 32;
|
---|
302 |
|
---|
303 | if(towerEtaPhi != hitEtaPhi)
|
---|
304 | {
|
---|
305 | // switch to next tower
|
---|
306 | towerEtaPhi = hitEtaPhi;
|
---|
307 |
|
---|
308 | // finalize previous tower
|
---|
309 | FinalizeTower();
|
---|
310 |
|
---|
311 | // create new tower
|
---|
312 | fTower = factory->NewCandidate();
|
---|
313 |
|
---|
314 | phiBin = (towerHit >> 32) & 0x000000000000FFFFLL;
|
---|
315 | etaBin = (towerHit >> 48) & 0x000000000000FFFFLL;
|
---|
316 |
|
---|
317 | // phi bins for given eta bin
|
---|
318 | phiBins = fPhiBins[etaBin];
|
---|
319 |
|
---|
320 | // calculate eta and phi of the tower's center
|
---|
321 | fTowerEta = 0.5*(fEtaBins[etaBin - 1] + fEtaBins[etaBin]);
|
---|
322 | fTowerPhi = 0.5*((*phiBins)[phiBin - 1] + (*phiBins)[phiBin]);
|
---|
323 |
|
---|
324 | fTowerEdges[0] = fEtaBins[etaBin - 1];
|
---|
325 | fTowerEdges[1] = fEtaBins[etaBin];
|
---|
326 | fTowerEdges[2] = (*phiBins)[phiBin - 1];
|
---|
327 | fTowerEdges[3] = (*phiBins)[phiBin];
|
---|
328 |
|
---|
329 | fTowerEnergy = 0.0;
|
---|
330 | fTrackEnergy = 0.0;
|
---|
331 |
|
---|
332 | fTowerTime = 0.0;
|
---|
333 | fTrackTime = 0.0;
|
---|
334 |
|
---|
335 | fTowerWeightTime = 0.0;
|
---|
336 |
|
---|
337 | fTowerTrackHits = 0;
|
---|
338 | fTowerPhotonHits = 0;
|
---|
339 |
|
---|
340 | fTowerTrackArray->Clear();
|
---|
341 | }
|
---|
342 |
|
---|
343 | // check for track hits
|
---|
344 | if(flags & 1)
|
---|
345 | {
|
---|
346 | ++fTowerTrackHits;
|
---|
347 |
|
---|
348 | track = static_cast<Candidate*>(fTrackInputArray->At(number));
|
---|
349 | momentum = track->Momentum;
|
---|
350 | position = track->Position;
|
---|
351 |
|
---|
352 | energy = momentum.E() * fTrackFractions[number];
|
---|
353 |
|
---|
354 | fTrackEnergy += energy;
|
---|
355 |
|
---|
356 | fTrackTime += TMath::Sqrt(energy)*position.T();
|
---|
357 | fTrackWeightTime += TMath::Sqrt(energy);
|
---|
358 |
|
---|
359 | fTowerTrackArray->Add(track);
|
---|
360 |
|
---|
361 | continue;
|
---|
362 | }
|
---|
363 |
|
---|
364 | // check for photon and electron hits in current tower
|
---|
365 | if(flags & 2) ++fTowerPhotonHits;
|
---|
366 |
|
---|
367 | particle = static_cast<Candidate*>(fParticleInputArray->At(number));
|
---|
368 | momentum = particle->Momentum;
|
---|
369 | position = particle->Position;
|
---|
370 |
|
---|
371 | // fill current tower
|
---|
372 | energy = momentum.E() * fTowerFractions[number];
|
---|
373 |
|
---|
374 | fTowerEnergy += energy;
|
---|
375 |
|
---|
376 | fTowerTime += TMath::Sqrt(energy)*position.T();
|
---|
377 | fTowerWeightTime += TMath::Sqrt(energy);
|
---|
378 |
|
---|
379 | fTower->AddCandidate(particle);
|
---|
380 | }
|
---|
381 |
|
---|
382 | // finalize last tower
|
---|
383 | FinalizeTower();
|
---|
384 | }
|
---|
385 |
|
---|
386 | //------------------------------------------------------------------------------
|
---|
387 |
|
---|
388 | void SimpleCalorimeter::FinalizeTower()
|
---|
389 | {
|
---|
390 | Candidate *tower;
|
---|
391 | Double_t energy, pt, eta, phi;
|
---|
392 | Double_t sigma;
|
---|
393 | Double_t time;
|
---|
394 |
|
---|
395 | if(!fTower) return;
|
---|
396 |
|
---|
397 | sigma = fResolutionFormula->Eval(0.0, fTowerEta, 0.0, fTowerEnergy);
|
---|
398 |
|
---|
399 | // energy = gRandom->Gaus(fTowerEnergy, sigma);
|
---|
400 | // if(energy < 0.0) energy = 0.0;
|
---|
401 |
|
---|
402 | energy = LogNormal(fTowerEnergy, sigma);
|
---|
403 | time = (fTowerWeightTime < 1.0E-09 ) ? 0 : fTowerTime/fTowerWeightTime;
|
---|
404 |
|
---|
405 | sigma = fResolutionFormula->Eval(0.0, fTowerEta, 0.0, energy);
|
---|
406 |
|
---|
407 | energy = (energy < fEnergyMin || energy < fSigmaMin*sigma) ? 0 : energy;
|
---|
408 |
|
---|
409 | eta = gRandom->Uniform(fTowerEdges[0], fTowerEdges[1]);
|
---|
410 | phi = gRandom->Uniform(fTowerEdges[2], fTowerEdges[3]);
|
---|
411 |
|
---|
412 | pt = energy / TMath::CosH(eta);
|
---|
413 |
|
---|
414 | // fTower->Position.SetXYZT(-time, 0.0, 0.0, time);
|
---|
415 | fTower->Position.SetPtEtaPhiE(1.0, eta, phi, time);
|
---|
416 | fTower->Momentum.SetPtEtaPhiE(pt, eta, phi, energy);
|
---|
417 |
|
---|
418 | fTower->Edges[0] = fTowerEdges[0];
|
---|
419 | fTower->Edges[1] = fTowerEdges[1];
|
---|
420 | fTower->Edges[2] = fTowerEdges[2];
|
---|
421 | fTower->Edges[3] = fTowerEdges[3];
|
---|
422 |
|
---|
423 |
|
---|
424 | // fill SimpleCalorimeter towers
|
---|
425 | if(energy > 0.0) fTowerOutputArray->Add(fTower);
|
---|
426 |
|
---|
427 |
|
---|
428 | // fill energy flow candidates
|
---|
429 | energy -= fTrackEnergy;
|
---|
430 | if(energy < fEnergyMin || energy < fSigmaMin*fResolutionFormula->Eval(0.0, fTowerEta, 0.0, energy)) energy = 0.0;
|
---|
431 |
|
---|
432 | // save energy excess as an energy flow tower
|
---|
433 | if(energy > 0.0)
|
---|
434 | {
|
---|
435 | // create new photon tower
|
---|
436 | tower = static_cast<Candidate*>(fTower->Clone());
|
---|
437 | pt = energy / TMath::CosH(eta);
|
---|
438 |
|
---|
439 | tower->Momentum.SetPtEtaPhiE(pt, eta, phi, energy);
|
---|
440 | fEFlowTowerOutputArray->Add(tower);
|
---|
441 | }
|
---|
442 |
|
---|
443 | }
|
---|
444 |
|
---|
445 | //------------------------------------------------------------------------------
|
---|
446 |
|
---|
447 | Double_t SimpleCalorimeter::LogNormal(Double_t mean, Double_t sigma)
|
---|
448 | {
|
---|
449 | Double_t a, b;
|
---|
450 |
|
---|
451 | if(mean > 0.0)
|
---|
452 | {
|
---|
453 | b = TMath::Sqrt(TMath::Log((1.0 + (sigma*sigma)/(mean*mean))));
|
---|
454 | a = TMath::Log(mean) - 0.5*b*b;
|
---|
455 |
|
---|
456 | return TMath::Exp(a + b*gRandom->Gaus(0, 1));
|
---|
457 | }
|
---|
458 | else
|
---|
459 | {
|
---|
460 | return 0.0;
|
---|
461 | }
|
---|
462 | }
|
---|