Fork me on GitHub

source: git/display/DelphesBranchElement.cc@ e01b141

Last change on this file since e01b141 was 341014c, checked in by Pavel Demin <pavel-demin@…>, 6 years ago

apply .clang-format to all .h, .cc and .cpp files

  • Property mode set to 100644
File size: 11.1 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#include "display/DelphesBranchElement.h"
20#include "TEveArrow.h"
21#include "TEveJetCone.h"
22#include "TEveTrack.h"
23#include "TEveTrackPropagator.h"
24#include "TEveVector.h"
25#include "classes/DelphesClasses.h"
26#include <iostream>
27
28// special case for calo towers
29template <>
30DelphesBranchElement<DelphesCaloData>::DelphesBranchElement(const char *name, TClonesArray *branch, const enum EColor color, Float_t maxPt) :
31 DelphesBranchBase(name, branch, color, maxPt)
32{
33 data_ = new DelphesCaloData(2);
34 data_->RefSliceInfo(0).Setup("ECAL", 0.1, kRed);
35 data_->RefSliceInfo(1).Setup("HCAL", 0.1, kBlue);
36 data_->IncDenyDestroy();
37}
38template <>
39void DelphesBranchElement<DelphesCaloData>::Reset() { data_->ClearTowers(); }
40template <>
41void DelphesBranchElement<DelphesCaloData>::ReadBranch()
42{
43 if(TString(GetType()) == "Tower")
44 {
45 // Loop over all towers
46 TIter itTower(branch_);
47 Tower *tower;
48 while((tower = (Tower *)itTower.Next()))
49 {
50 data_->AddTower(tower->Edges[0], tower->Edges[1], tower->Edges[2], tower->Edges[3]);
51 data_->FillSlice(0, tower->Eem);
52 data_->FillSlice(1, tower->Ehad);
53 }
54 data_->DataChanged();
55 }
56}
57template <>
58std::vector<TLorentzVector> DelphesBranchElement<DelphesCaloData>::GetVectors()
59{
60 std::vector<TLorentzVector> output;
61 if(TString(GetType()) == "Tower")
62 {
63 TIter itTower(branch_);
64 Tower *tower;
65 while((tower = (Tower *)itTower.Next()))
66 {
67 TLorentzVector v;
68 v.SetPtEtaPhiM(tower->Eem + tower->Ehad, (tower->Edges[0] + tower->Edges[1]) / 2., (tower->Edges[2] + tower->Edges[3]) / 2., 0.);
69 output.push_back(v);
70 }
71 }
72 return output;
73}
74
75// special case for element lists
76template <>
77DelphesBranchElement<TEveElementList>::DelphesBranchElement(const char *name, TClonesArray *branch, const enum EColor color, Float_t maxPt) :
78 DelphesBranchBase(name, branch, color, maxPt)
79{
80 data_ = new TEveElementList(name);
81 data_->SetMainColor(color_);
82}
83template <>
84void DelphesBranchElement<TEveElementList>::Reset() { data_->DestroyElements(); }
85template <>
86void DelphesBranchElement<TEveElementList>::ReadBranch()
87{
88 if(TString(GetType()) == "Jet")
89 {
90 TIter itJet(branch_);
91 Jet *jet;
92 TEveJetCone *eveJetCone;
93 // Loop over all jets
94 Int_t counter = 0;
95 while((jet = (Jet *)itJet.Next()))
96 {
97 eveJetCone = new TEveJetCone();
98 eveJetCone->SetTitle(Form("jet [%d]: Pt=%f, Eta=%f, \nPhi=%f, M=%f", counter, jet->PT, jet->Eta, jet->Phi, jet->Mass));
99 eveJetCone->SetName(Form("jet [%d]", counter++));
100 eveJetCone->SetMainTransparency(60);
101 eveJetCone->SetLineColor(GetColor());
102 eveJetCone->SetFillColor(GetColor());
103 eveJetCone->SetCylinder(tkRadius_ - 10, tkHalfLength_ - 10);
104 eveJetCone->SetPickable(kTRUE);
105 eveJetCone->AddEllipticCone(jet->Eta, jet->Phi, jet->DeltaEta, jet->DeltaPhi);
106 data_->AddElement(eveJetCone);
107 }
108 }
109 else if(TString(GetType()) == "MissingET")
110 {
111 // MissingET as invisible track (like a photon)
112 MissingET *MET;
113 TEveTrack *eveMet;
114 TEveTrackPropagator *trkProp = new TEveTrackPropagator();
115 trkProp->SetMagField(0., 0., -tk_Bz_);
116 trkProp->SetMaxR(tkRadius_);
117 trkProp->SetMaxZ(tkHalfLength_);
118 if(branch_->GetEntriesFast() > 0)
119 {
120 MET = (MissingET *)branch_->At(0);
121 TParticle pb(13, 1, 0, 0, 0, 0,
122 (tkRadius_ * MET->MET / maxPt_) * cos(MET->Phi),
123 (tkRadius_ * MET->MET / maxPt_) * sin(MET->Phi),
124 0., MET->MET, 0.0, 0.0, 0.0, 0.0);
125 eveMet = new TEveTrack(&pb, 0, trkProp);
126 eveMet->SetName("Missing Et");
127 eveMet->SetStdTitle();
128 eveMet->SetRnrPoints(0);
129 eveMet->SetMarkerColor(kMagenta);
130 eveMet->SetMarkerStyle(4);
131 eveMet->SetMarkerSize(2.);
132 eveMet->SetLineWidth(2.);
133 eveMet->SetLineStyle(7);
134 data_->AddElement(eveMet);
135 eveMet->SetLineColor(GetColor());
136 eveMet->MakeTrack();
137 }
138 }
139}
140template <>
141std::vector<TLorentzVector> DelphesBranchElement<TEveElementList>::GetVectors()
142{
143 std::vector<TLorentzVector> output;
144 if(TString(GetType()) == "Jet")
145 {
146 TIter itJet(branch_);
147 Jet *jet;
148 // Loop over all jets
149 while((jet = (Jet *)itJet.Next()))
150 {
151 TLorentzVector v;
152 v.SetPtEtaPhiM(jet->PT, jet->Eta, jet->Phi, jet->Mass);
153 output.push_back(v);
154 }
155 }
156 else if(TString(GetType()) == "MissingET")
157 {
158 TIter itMet(branch_);
159 MissingET *MET;
160 // Missing Et
161 while((MET = (MissingET *)itMet.Next()))
162 {
163 TLorentzVector v;
164 v.SetPtEtaPhiM(MET->MET, MET->Eta, MET->Phi, 0.);
165 output.push_back(v);
166 }
167 }
168 return output;
169}
170
171// special case for track lists
172template <>
173DelphesBranchElement<TEveTrackList>::DelphesBranchElement(const char *name, TClonesArray *branch, const enum EColor color, Float_t maxPt) :
174 DelphesBranchBase(name, branch, color, maxPt)
175{
176 data_ = new TEveTrackList(name);
177 data_->SetMainColor(color_);
178 data_->SetMarkerColor(color_);
179 data_->SetMarkerStyle(kCircle);
180 data_->SetMarkerSize(0.5);
181}
182template <>
183void DelphesBranchElement<TEveTrackList>::SetTrackingVolume(Float_t r, Float_t l, Float_t Bz)
184{
185 tkRadius_ = r;
186 tkHalfLength_ = l;
187 tk_Bz_ = Bz;
188 TEveTrackPropagator *trkProp = data_->GetPropagator();
189 trkProp->SetMagField(0., 0., -tk_Bz_);
190 trkProp->SetMaxR(tkRadius_);
191 trkProp->SetMaxZ(tkHalfLength_);
192}
193template <>
194void DelphesBranchElement<TEveTrackList>::Reset() { data_->DestroyElements(); }
195template <>
196void DelphesBranchElement<TEveTrackList>::ReadBranch()
197{
198 TString type = GetType();
199 TIter itTrack(branch_);
200 Int_t counter = 0;
201 TEveTrack *eveTrack;
202 TEveTrackPropagator *trkProp = data_->GetPropagator();
203 trkProp->SetMagField(0., 0., -tk_Bz_);
204 trkProp->SetMaxR(tkRadius_);
205 trkProp->SetMaxZ(tkHalfLength_);
206 GenParticle *particle;
207 if(type == "Track")
208 { // CASE 1: TRACKS
209 Track *track;
210 while((track = (Track *)itTrack.Next()))
211 {
212 TParticle pb(track->PID, 1, 0, 0, 0, 0,
213 track->P4().Px(), track->P4().Py(),
214 track->P4().Pz(), track->P4().E(),
215 track->X / 10.0, track->Y / 10.0, track->Z / 10.0, track->T / 10.0);
216 eveTrack = new TEveTrack(&pb, counter, trkProp);
217 eveTrack->SetName(Form("%s [%d]", pb.GetName(), counter++));
218 eveTrack->SetStdTitle();
219 eveTrack->SetAttLineAttMarker(data_);
220 data_->AddElement(eveTrack);
221 eveTrack->SetLineColor(GetColor());
222 eveTrack->MakeTrack();
223 }
224 }
225 else if(type == "Electron")
226 { // CASE 2: ELECTRONS
227 Electron *electron;
228 while((electron = (Electron *)itTrack.Next()))
229 {
230 particle = (GenParticle *)electron->Particle.GetObject();
231 TParticle pb(electron->Charge < 0 ? 11 : -11, 1, 0, 0, 0, 0,
232 electron->P4().Px(), electron->P4().Py(),
233 electron->P4().Pz(), electron->P4().E(),
234 particle->X / 10.0, particle->Y / 10.0, particle->Z / 10.0, particle->T / 10.0);
235 eveTrack = new TEveTrack(&pb, counter, trkProp);
236 eveTrack->SetName(Form("%s [%d]", pb.GetName(), counter++));
237 eveTrack->SetStdTitle();
238 eveTrack->SetAttLineAttMarker(data_);
239 data_->AddElement(eveTrack);
240 eveTrack->SetLineColor(GetColor());
241 eveTrack->MakeTrack();
242 }
243 }
244 else if(type == "Muon")
245 { // CASE 3: MUONS
246 Muon *muon;
247 while((muon = (Muon *)itTrack.Next()))
248 {
249 particle = (GenParticle *)muon->Particle.GetObject();
250 TParticle pb(muon->Charge < 0 ? 13 : -13, 1, 0, 0, 0, 0,
251 muon->P4().Px(), muon->P4().Py(),
252 muon->P4().Pz(), muon->P4().E(),
253 particle->X / 10.0, particle->Y / 10.0, particle->Z / 10.0, particle->T / 10.0);
254 eveTrack = new TEveTrack(&pb, counter, trkProp);
255 eveTrack->SetName(Form("%s [%d]", pb.GetName(), counter++));
256 eveTrack->SetStdTitle();
257 eveTrack->SetAttLineAttMarker(data_);
258 data_->AddElement(eveTrack);
259 eveTrack->SetLineColor(GetColor());
260 eveTrack->MakeTrack();
261 }
262 }
263 else if(type == "Photon")
264 { // CASE 4: PHOTONS
265 Photon *photon;
266 while((photon = (Photon *)itTrack.Next()))
267 {
268 TParticle pb(22, 1, 0, 0, 0, 0,
269 photon->P4().Px(), photon->P4().Py(),
270 photon->P4().Pz(), photon->P4().E(),
271 0.0, 0.0, 0.0, 0.0);
272 eveTrack = new TEveTrack(&pb, counter, trkProp);
273 eveTrack->SetName(Form("%s [%d]", pb.GetName(), counter++));
274 eveTrack->SetStdTitle();
275 eveTrack->SetAttLineAttMarker(data_);
276 eveTrack->SetLineStyle(7);
277 data_->AddElement(eveTrack);
278 eveTrack->SetLineColor(GetColor());
279 eveTrack->MakeTrack();
280 }
281 }
282 else if(type == "GenParticle")
283 { // CASE 5: GENPARTICLES
284 GenParticle *particle;
285 while((particle = (GenParticle *)itTrack.Next()))
286 {
287 if(particle->Status != 1) continue;
288 TParticle pb(particle->PID, particle->Status, particle->M1, particle->M2, particle->D1, particle->D2,
289 particle->P4().Px(), particle->P4().Py(),
290 particle->P4().Pz(), particle->P4().E(),
291 particle->X / 10.0, particle->Y / 10.0, particle->Z / 10.0, particle->T / 10.0);
292 eveTrack = new TEveTrack(&pb, counter, trkProp);
293 eveTrack->SetName(Form("%s [%d]", pb.GetName(), counter++));
294 eveTrack->SetStdTitle();
295 eveTrack->SetAttLineAttMarker(data_);
296 data_->AddElement(eveTrack);
297 eveTrack->SetLineColor(GetColor());
298 if(particle->Charge == 0) eveTrack->SetLineStyle(7);
299 eveTrack->MakeTrack();
300 }
301 }
302}
303template <>
304std::vector<TLorentzVector> DelphesBranchElement<TEveTrackList>::GetVectors()
305{
306 std::vector<TLorentzVector> output;
307 TString type = GetType();
308 TIter itTrack(branch_);
309 if(type == "Track")
310 { // CASE 1: TRACKS
311 Track *track;
312 while((track = (Track *)itTrack.Next()))
313 {
314 output.push_back(track->P4());
315 }
316 }
317 else if(type == "Electron")
318 { // CASE 2: ELECTRONS
319 Electron *electron;
320 while((electron = (Electron *)itTrack.Next()))
321 {
322 output.push_back(electron->P4());
323 }
324 }
325 else if(type == "Muon")
326 { // CASE 3: MUONS
327 Muon *muon;
328 while((muon = (Muon *)itTrack.Next()))
329 {
330 output.push_back(muon->P4());
331 }
332 }
333 else if(type == "Photon")
334 { // CASE 4: PHOTONS
335 Photon *photon;
336 while((photon = (Photon *)itTrack.Next()))
337 {
338 output.push_back(photon->P4());
339 }
340 }
341 else if(type == "GenParticle")
342 { // CASE 5: GENPARTICLES
343 GenParticle *particle;
344 while((particle = (GenParticle *)itTrack.Next()))
345 {
346 if(particle->Status != 1) continue;
347 output.push_back(particle->P4());
348 }
349 }
350 return output;
351}
Note: See TracBrowser for help on using the repository browser.