ATLAS Offline Software
Loading...
Searching...
No Matches
VP1CaloClusterCollection.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5
7// //
8// Implementation of class VP1CaloClusterCollection //
9// //
10// Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) //
11// Initial version: June 2007 //
12// //
14
18#include "VP1Base/IVP1System.h"
24
25#include <Inventor/SoPath.h>
26#include <Inventor/nodes/SoSeparator.h>
28
29#include "CLHEP/Units/SystemOfUnits.h"
30#include "CaloEvent/CaloCluster.h"
31#include "CaloEvent/CaloClusterContainer.h"
32
33//_____________________________________________________________________________________
35{
36 QList<VP1CaloClusterCollection*> cols;
37 for (const QString& key : VP1SGContentsHelper(sys).getKeys<CaloClusterContainer>()) {
38 VP1CaloClusterCollection * col = new VP1CaloClusterCollection(key,sys,controller);
39 col->init();
40 cols << col;
41 }
42 return cols;
43}
44
45//____________________________________________________________________
47public:
51 QString key;
52
54 QPair<bool,double> scale;
55 bool showOutlines = false;
58 QList<VP1Interval> allowedPhi;
59 double last_highestEnergy = 0.0;
61
62 double energyToLength(const double&energy) {
63 return std::max(1*CLHEP::mm, scale.second*(scale.first?log(1+fabs(energy)):energy));
64 }
65
66 static const double calo_start_r;
67 static const double calo_start_z;
68 static const double calo_crack_eta;
69
71 public:
73 {
74 m_transverseEnergy = sin(2*atan(exp(-fabs(eta()))))*energy();
75 }
78 if (!m_genericBox) {
80 m_genericBox->drawEdgeLines = d->showOutlines;
81 m_genericBox->forceEdgeLinesInBaseColour = true;
82 m_genericBox->ref();
83 }
84 m_attached = true;
86 d->sephelper->addNode(m_genericBox);
87 }
89 if (m_genericBox) {
90 sh->removeNode(m_genericBox);
91 }
92 m_attached = false;
93 }
95 if (!m_attached)
96 return;
97 const double dEta = 0.05;//FIXME
98 const double dPhi = 0.05;//FIXME
99 const double theEta = eta();
100 const double thePhi = phi();
101 const double cellDepth = d->energyToLength(energyForLengthAndCuts(d));
103 m_genericBox->setParametersForBarrelEtaPhiCell( theEta-0.5*dEta, theEta+0.5*dEta,thePhi-0.5*dPhi, thePhi+0.5*dPhi,
105 } else {
106 m_genericBox->setParametersForEndCapEtaPhiCell( theEta-0.5*dEta, theEta+0.5*dEta,thePhi-0.5*dPhi, thePhi+0.5*dPhi,
108 }
109 }
110
112 double phi() const { return m_cluster->phi(); }
113 double eta() const { return m_cluster->eta(); }
114 double transverseEnergy() const { return m_transverseEnergy; }
115 double energy() const { return m_cluster->e(); }
116 double energyForLengthAndCuts(const VP1CaloClusterCollection::Imp * d) { return d->considerTransverseEnergies ? transverseEnergy() : energy(); }
117 const CaloCluster* cluster() const { return m_cluster; }
118 bool attached() const { return m_attached; }
119 private:
124 };
126 if (!allowedEnergies.contains(c->energyForLengthAndCuts(this)))
127 return false;
128 if (!allowedEta.contains(c->eta()))
129 return false;
130 double phi(c->phi());
131 for (const VP1Interval& i : allowedPhi) {
132 if (i.contains(phi)||i.contains(phi+2*M_PI)||i.contains(phi-2*M_PI))
133 return true;
134 }
135 return false;
136 }
137
139 const bool cutval = cut(c);
140 if (cutval!=c->attached()) {
141 if (cutval)
142 c->attach(this);
143 else
144 c->detach(sephelper);
145 }
146 }
147
148 QList<ClusterHandle*> clusters;
149
150};
151
152//Fixme: Just some approximate values for now:
153const double VP1CaloClusterCollection::Imp::calo_start_r = 1.1*CLHEP::m + 0.05*CLHEP::m;
154const double VP1CaloClusterCollection::Imp::calo_start_z = 3.671*CLHEP::m + 0.05*CLHEP::m;
155const double VP1CaloClusterCollection::Imp::calo_crack_eta = fabs(log(tan(0.5*atan(calo_start_r/calo_start_z))));
156
157//____________________________________________________________________
162
163//____________________________________________________________________
165 : VP1StdCollection(sys,"VP1CaloClusterCollection_"+key), m_d(new Imp)
166{
168
169 m_d->theclass = this;
170 m_d->controller = controller;
171 m_d->key = key;
172 m_d->sephelper = 0;
173 //We start out with no clusters visible:
174 m_d->last_highestEnergy = 0;
175 m_d->showOutlines = false;
176 m_d->considerTransverseEnergies = true;
177
178 connect(this,SIGNAL(highestVisibleClusterEnergyChanged()),controller,SLOT(possibleChange_scale()));
179 connect(this,SIGNAL(visibilityChanged(bool)),this,SLOT(recheckHighestVisibleClusterEnergy()));
180
181 connect(controller,SIGNAL(useTransverseEnergiesChanged(bool)),this,SLOT(setConsiderTransverseEnergies(bool)));
183 connect(controller,SIGNAL(scaleChanged(const QPair<bool,double>&)),this,SLOT(setScale(const QPair<bool,double>&)));
184 setScale(controller->scale());
185 connect(controller,SIGNAL(showVolumeOutLinesChanged(bool)),this,SLOT(setShowVolumeOutLines(bool)));
187 connect(controller,SIGNAL(cutAllowedEnergiesChanged(const VP1Interval&)),this,SLOT(setAllowedEnergies(const VP1Interval&)));
189 connect(controller,SIGNAL(cutAllowedEtaChanged(const VP1Interval&)),this,SLOT(setAllowedEta(const VP1Interval&)));
190 setAllowedEta(controller->cutAllowedEta());
191 connect(controller,SIGNAL(cutAllowedPhiChanged(const QList<VP1Interval>&)),this,SLOT(setAllowedPhi(const QList<VP1Interval>&)));
192 setAllowedPhi(controller->cutAllowedPhi());
193
194
195}
196
197//____________________________________________________________________
199{
200 if (m_d->sephelper) {
201 SoSeparator * sep = m_d->sephelper->topSeparator();
202 delete m_d->sephelper;
203 sep->unref();
204 }
205 for (Imp::ClusterHandle*cluster : m_d->clusters)
206 delete cluster;
207 delete m_d;
208}
209
210//____________________________________________________________________
212{
213 return "";
214}
215
216//____________________________________________________________________
218{
219 return m_d->key;
220}
221
222//____________________________________________________________________
224{
225 VP1MaterialButton::setMaterialParameters( m, 1.0, 0.9, 0.0, 0.15/*brightness*/, 0.5/*transp*/ );
226}
227
228
229//____________________________________________________________________
231{
232 double e = 0;
233 if (theclass->visible()) {
234 for (Imp::ClusterHandle*cluster : clusters) {
235 if (cluster->attached()&&e<cluster->energyForLengthAndCuts(this))
236 e=cluster->energyForLengthAndCuts(this);
237 }
238 }
239 return e;
240}
241
242//____________________________________________________________________
244{
245 //When visibility or cut changes:
246 double newhighest = m_d->calculateHighestVisibleClusterEnergy();
247 if (m_d->last_highestEnergy == newhighest)
248 return;
249 m_d->last_highestEnergy = newhighest;
251}
252
253//____________________________________________________________________
255{
256 return m_d->last_highestEnergy;
257}
258
259//____________________________________________________________________
261{
262 //Get collection:
263 const CaloClusterContainer *theClusterCollection(0);
264 if (!VP1SGAccessHelper(systemBase()).retrieve(theClusterCollection,m_d->key))
265 return false;
266
267 SoSeparator * sep = new SoSeparator;
268 sep->setName("ClusterSepHelperTopSep");
269 sep->ref();
270 m_d->sephelper = new VP1ExtraSepLayerHelper(sep);
272 int i(0);
273 CaloClusterContainer::const_iterator it(theClusterCollection->begin()),itE(theClusterCollection->end());
274 for ( ; it != itE; ++it) {
275 if (i++%40==0)
277 Imp::ClusterHandle * clusterHandle = new Imp::ClusterHandle(*it);
278 m_d->clusters << clusterHandle;
279 m_d->recheckCut(clusterHandle);
280 }
282 collSep()->addChild(sep);
283
284 return true;
285}
286
287//____________________________________________________________________
288QStringList VP1CaloClusterCollection::infoOnClicked(SoPath* pickedPath)
289{
290 SoNode * pickedNode = pickedPath->getNodeFromTail(0);
291 const CaloCluster*cluster(0);
292 Imp::ClusterHandle*clusterHandle(0);
293 if (pickedNode->getTypeId()==SoGenericBox::getClassTypeId()) {
294 for (Imp::ClusterHandle*c : m_d->clusters) {
295 if (c->genericBox()==pickedNode) {
296 cluster = c->cluster();
297 clusterHandle = c;
298 break;
299 }
300 }
301 }
302
303 if (!cluster||!clusterHandle)
304 return QStringList() << "Error: Collection "+m_d->key+" does not have cluster information for picked node";
305
306 QStringList l;
307 if (m_d->controller->printInfoOnClick()) {
308 l << " Eta: "+str(cluster->eta());
309 l << " Phi: "+str(cluster->phi());
310 l << " Energy [GeV]: "+str(clusterHandle->energy()/CLHEP::GeV);
311 l << " Transverse Energy [GeV]: "+str(clusterHandle->transverseEnergy()/CLHEP::GeV);
312 if (m_d->controller->printVerboseInfoOnClick()) {
313 l << "(no verbose information available)";
314 // l << " Lambda_center [CLHEP::cm]: "+str(cluster->getMoment(CaloClusterMoment::CENTER_LAMBDA).getValue()/CLHEP::cm);
315 }
316 }
317 if (m_d->controller->zoomOnClick()) {
318 std::set<SoCamera*> cameras = static_cast<IVP13DSystem*>(systemBase())->getCameraList();
319 std::set<SoCamera*>::iterator it,itE = cameras.end();
320 for (it=cameras.begin();it!=itE;++it)
321 VP1CameraHelper::animatedZoomToPath(*it,collSep(),pickedPath,2.0,1.0);
322 }
323
324 return l;
325}
326//____________________________________________________________________
328{
330 m_d->sephelper->largeChangesBegin();
331}
332//____________________________________________________________________
334{
336 m_d->sephelper->largeChangesEnd();
337}
338
339//____________________________________________________________________
341{
342 if (m_d->allowedEnergies==i)
343 return;
344 m_d->allowedEnergies=i;
345 if (!isLoaded())
346 return;
347 static_cast<IVP13DSystemSimple *>(systemBase())->deselectAll();
349 for (Imp::ClusterHandle*cluster : m_d->clusters)
350 m_d->recheckCut(cluster);
352 //Fixme relaxed/tightened stuff
353
355}
356
357//____________________________________________________________________
359{
360 if (m_d->allowedEta==i)
361 return;
362 m_d->allowedEta=i;
363 if (!isLoaded())
364 return;
365 static_cast<IVP13DSystemSimple *>(systemBase())->deselectAll();
367 for (Imp::ClusterHandle*cluster : m_d->clusters)
368 m_d->recheckCut(cluster);
370 //Fixme relaxed/tightened stuff
371
373}
374
375//____________________________________________________________________
376void VP1CaloClusterCollection::setAllowedPhi(const QList<VP1Interval>& i)
377{
378 if (m_d->allowedPhi==i)
379 return;
380 m_d->allowedPhi=i;
381 if (!isLoaded())
382 return;
383 static_cast<IVP13DSystemSimple *>(systemBase())->deselectAll();
385 for (Imp::ClusterHandle*cluster : m_d->clusters)
386 m_d->recheckCut(cluster);
388 //Fixme relaxed/tightened stuff
389
391}
392
393#include <Inventor/nodes/SoMaterial.h>//Fixme: just for hack below
394//____________________________________________________________________
395void VP1CaloClusterCollection::setScale(const QPair<bool,double>& s)
396{
397 if (m_d->scale==s)
398 return;
399 m_d->scale=s;
400 if (!isLoaded())
401 return;
403 for (Imp::ClusterHandle*cluster : m_d->clusters)
404 if (cluster->attached())
405 cluster->updateShapePars(m_d);
407
408 // if (verbose())
409 // static_cast<IVP13DSystemSimple *>(systemBase())->warnOnDisabledNotifications();
410
411 material()->touch();//FIXME: This is needed (and nothing else seems to matter). BUT WHY?????? Where is the bug?!?!?
412}
413
414//____________________________________________________________________
416{
417 if (m_d->showOutlines==b)
418 return;
419 m_d->showOutlines=b;
420 if (!isLoaded())
421 return;
423 for (Imp::ClusterHandle*cluster : m_d->clusters)
424 if (cluster->genericBox())
425 cluster->genericBox()->drawEdgeLines = b;
427}
428
429//____________________________________________________________________
431{
432 if (m_d->considerTransverseEnergies==b)
433 return;
434 m_d->considerTransverseEnergies=b;
435 if (!isLoaded())
436 return;
438 for (Imp::ClusterHandle*cluster : m_d->clusters) {
439 bool attachPrev(cluster->attached());
440 m_d->recheckCut(cluster);
441 if (attachPrev&&cluster->attached())
442 cluster->updateShapePars(m_d);
443 }
446}
#define M_PI
Scalar phi() const
phi method
QList< VP1Interval > cutAllowedPhi() const
QPair< bool, double > scale() const
Principal data class for CaloCell clusters.
virtual double eta() const
Retrieve eta independent of signal state.
virtual double phi() const
Retrieve phi independent of signal state.
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
void updateGUI()
static void initClass()
SoSFBool drawEdgeLines
void updateShapePars(VP1CaloClusterCollection::Imp *d)
double energyForLengthAndCuts(const VP1CaloClusterCollection::Imp *d)
void attach(VP1CaloClusterCollection::Imp *d)
CaloClusterSysController * controller
double energyToLength(const double &energy)
static QList< VP1CaloClusterCollection * > createCollections(IVP1System *, CaloClusterSysController *)
void assignDefaultMaterial(SoMaterial *) const
void setAllowedEnergies(const VP1Interval &)
void setAllowedPhi(const QList< VP1Interval > &)
VP1CaloClusterCollection(const QString &key, IVP1System *sys, CaloClusterSysController *)
QStringList infoOnClicked(SoPath *pickedPath)
void setScale(const QPair< bool, double > &)
void setAllowedEta(const VP1Interval &)
void highestVisibleClusterEnergyChanged()
static VP1CameraHelper * animatedZoomToPath(SoCamera *camera, SoGroup *sceneroot, SoPath *path, double duration_in_secs=1.0, double clipVolPercent=100.0, double slack=1.0, const SbVec3f &lookat=SbVec3f(999, 999, 999), const SbVec3f &upvec=SbVec3f(999, 999, 999), bool varySpeed=true, bool forceCircular=false)
IVP1System * systemBase() const
static void setMaterialParameters(SoMaterial *m, const QColor &, const double &brightness=0.0, const double &transp=0.0)
SoMaterial * material() const
virtual void largeChangesEnd()
virtual void init(VP1MaterialButtonBase *button=0)
SoSeparator * collSep() const
All 3D objects from this coll.
virtual void largeChangesBegin()
void visibilityChanged(bool)
VP1StdCollection(IVP1System *, const QString &helperClassName)