ATLAS Offline Software
Loading...
Searching...
No Matches
IParticleHandle_CaloCluster.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5
7// //
8// Implementation of class IParticleHandle_CaloCluster //
9// //
10// //
12
13// Local
16#include "AODSysCommonData.h"
18
19//VP1
20#include "VP1Base/VP1Msg.h"
21#include "VP1Utils/SoTools.h"
23
24//SoCoin
25#include <Inventor/nodes/SoLineSet.h>
26#include <Inventor/nodes/SoPointSet.h>
27#include <Inventor/nodes/SoVertexProperty.h>
28#include <Inventor/nodes/SoMaterial.h>
29//#include <Inventor/nodes/SoCone.h>
30#include <Inventor/nodes/SoSeparator.h>
31#include <Inventor/nodes/SoTranslation.h>
32#include <Inventor/nodes/SoRotationXYZ.h>
33#include <Inventor/nodes/SoScale.h>
34#include <Inventor/nodes/SoSwitch.h>
35#include <SoDebug.h> // it's stored at /afs/cern.ch/sw/lcg/external/coin3d/3.1.3p2/x86_64-slc6-gcc47-opt/include/SoDebug.h
36
37// System of units
38#ifdef BUILDVP1LIGHT
39 #include "GeoModelKernel/Units.h"
40 #define SYSTEM_OF_UNITS GeoModelKernelUnits // --> 'GeoModelKernelUnits::cm'
41#else
42 #include "GaudiKernel/SystemOfUnits.h"
43 #define SYSTEM_OF_UNITS Gaudi::Units // --> 'Gaudi::Units::cm'
44#endif
45
46
47//____________________________________________________________________
49public:
50
51 IParticleHandle_CaloCluster * theclass = nullptr; // the Jet class
52 const IParticleCollHandle_CaloCluster* theCollHandle = nullptr; // the CollHandle instance
53
54 const xAOD::CaloCluster * m_cluster = nullptr; // the single jet
55
56 SoSeparator * sep = nullptr; // everything hangs from this.
57 SoGenericBox* m_genericBox = nullptr; //This is the box representing the calorimeter cluster.
58
59 //Settings:
60 bool considerTransverseEnergies = true; // TODO: update with button connection "E/Et" (see VP1JetCollection.cxx)
61
62 // Getters
63 const xAOD::CaloCluster* cluster() const { return m_cluster; }
65 double phi() const { /*VP1Msg::messageVerbose("phi: " + QString::number(m_cluster->phi()) );*/ return m_cluster->phi(); }
66 double eta() const { /*VP1Msg::messageVerbose("eta: " + QString::number(m_cluster->eta()) );*/ return m_cluster->eta(); }
67 double et() const { VP1Msg::messageDebug("et()");return m_cluster->et(); }
68 double e() const { VP1Msg::messageDebug("e()");return m_cluster->e(); }
69
70 double energyForLengthAndCuts(const IParticleCollHandle_CaloCluster* coll_handle) { return coll_handle->isConsiderTransverseEnergy() ? et() : e(); } // TODO: is this used at all??
71 double energyForLengthAndCuts() { VP1Msg::messageDebug("energyForLengthAndCuts()"); return theclass->isConsiderTransverseEnergies() ? et() : e(); }
72
73 // Create/manipulate 3D objects
75 void updateShapePars(const IParticleCollHandle_CaloCluster* coll_handle);
76
77};
78
79//____________________________________________________________________
81: IParticleHandleBase(ch), m_d(new Imp)
82{
83 // VP1Msg::messageVerbose("IParticleHandle_CaloCluster::IParticleHandle_CaloCluster() - constructor");
84
85 // set the Imp members
86 m_d->theclass = this;
87 m_d->m_cluster = cluster;
88 m_d->sep = 0;
89 m_d->m_genericBox = 0;
90
91 //
93}
94
95
96
97
98//____________________________________________________________________
100{
101 // VP1Msg::messageVerbose("IParticleHandle_CaloCluster::~IParticleHandle_CaloCluster() - destructor");
102 if (m_d->m_genericBox) m_d->m_genericBox->unref();
103 if (m_d->sep) m_d->sep->unref();
104 delete m_d;
105}
106
107
108
109//____________________________________________________________________
111{
112 return m_d->genericBox();
113}
114
115
116//____________________________________________________________________
118{
119 const IParticleCollHandle_CaloCluster* collHandleJet = dynamic_cast<const IParticleCollHandle_CaloCluster*>(collHandle());
120 if (not collHandleJet) return false;
121 bool Et = collHandleJet->isConsiderTransverseEnergy();
122 VP1Msg::messageDebug("IParticleHandle_CaloCluster::isConsiderTransverseEnergies() - " + QString::number(Et));
123 return Et;
124}
125
126// Setter
128//void IParticleHandle_CaloCluster::setScale( const double& sc) { m_d->scale = sc; }
129
130//____________________________________________________________________
131//void IParticleHandle_CaloCluster::setMaxR(const double& maxR) { m_d->maxR = maxR * SYSTEM_OF_UNITS::m; }
132
133
134//____________________________________________________________________
135//void IParticleHandle_CaloCluster::rerandomiseMaterial() {m_d->rerandomiseMaterial(); }
136
137//____________________________________________________________________
139{
140 // VP1Msg::messageVerbose("IParticleHandle_CaloCluster::has3DObjects()");
141 return 0 != m_d->sep;
142}
143
144
145//____________________________________________________________________
147 // VP1Msg::messageVerbose("IParticleHandle_CaloCluster::clear3DObjects()");
148
149 // if (m_d->m_randomMat) {
150 // m_d->m_randomMat->unref();
151 // m_d->m_randomMat = 0;
152 // }
153 if (m_d->m_genericBox) {
154 m_d->m_genericBox->unref();
155 m_d->m_genericBox = 0;
156 }
157 if (m_d->sep) {
158 m_d->sep->unref();
159 m_d->sep = 0;
160 }
161
162}
163
164
165
166/*
167 * This is the method which makes the 3D objects from the measurements
168 */
169//____________________________________________________________________
171
172 VP1Msg::messageVerbose("IParticleHandle_CaloCluster::nodes()");
173
174 if (m_d->sep) {
175 VP1Msg::messageVerbose("d->sep already defined (" + VP1Msg::str(m_d->sep) + "). Returning d->sep.");
176 return m_d->sep; // FIXME - do we need to check if anything need to be redrawn?
177 }
178 if (!m_d->sep) {
179 VP1Msg::messageVerbose("d->sep not defined. Creating shapes and a new d->sep.");
180 m_d->sep = new SoSeparator();
181 m_d->sep->ref();
182 }
183
184 const IParticleCollHandle_CaloCluster* coll_handle = dynamic_cast<const IParticleCollHandle_CaloCluster*>(collHandle());
185 if (not coll_handle) return m_d->sep;
186 VP1Msg::messageVerbose("creating the shapes");
187
188 /*
189 * Build the 3D objects for the physics object, and update m_d->sep.
190 */
191 // m_d->createShapeFromJetParameters(collHandle, m_d->coneR(), m_d->eta(), m_d->phi(), m_d->energyForLengthAndCuts(), origin);
192 // m_d->createShapeFromParameters(coll_handle, origin);
193 m_d->createShapeFromParameters(coll_handle);
194
195
196 return m_d->sep;
197}
198
199
201//void IParticleHandle_CaloCluster::updateHeight() {
202// m_d->updateConeHeightParameters();
203//}
204
206{
207 VP1Msg::messageDebug("IParticleHandle_CaloCluster::updateShape()");
208 m_d->updateShapePars(coll);
209}
210
211
212//____________________________________________________________________
214{
215 VP1Msg::messageDebug("IParticleHandle_CaloCluster::Imp::updateShapePars()");
216
217
218 const double dEta = 0.05;//FIXME
219 const double dPhi = 0.05;//FIXME
220 const double theEta = eta();
221 const double thePhi = phi();
222 const double cellDepth = coll_handle->energyToLength( energyForLengthAndCuts(coll_handle) );
224 m_genericBox->setParametersForBarrelEtaPhiCell( theEta-0.5*dEta, theEta+0.5*dEta,thePhi-0.5*dPhi, thePhi+0.5*dPhi,
226 } else {
227 m_genericBox->setParametersForEndCapEtaPhiCell( theEta-0.5*dEta, theEta+0.5*dEta,thePhi-0.5*dPhi, thePhi+0.5*dPhi,
229 }
230}
231
232//____________________________________________________________________
233//void IParticleHandle_CaloCluster::Imp::createShapeFromJetParameters(const IParticleCollHandle_CaloCluster* collHandle, const double& inputconeR, const double& eta,
234// const double& phi, const double& energy, const SbVec3f& origin)
235//void IParticleHandle_CaloCluster::Imp::createShapeFromParameters(const IParticleCollHandle_CaloCluster* coll_handle, const SbVec3f& origin)
237{
238 VP1Msg::messageVerbose("IParticleHandle_CaloCluster::Imp::createShapeFromParameters()");
239
240 if (!m_genericBox) {
243 m_genericBox->drawEdgeLines = coll_handle->showOutlines();
244 m_genericBox->forceEdgeLinesInBaseColour = true;
245 m_genericBox->ref();
246 }
247
248 // m_attached = true;
249 updateShapePars(coll_handle);
250 // m_d->sephelper->addNode(m_genericBox);
251
252
253 //std::cout << "Using material: " << coll_handle->material() << std::endl; // ^^ FIXME - should rearrange so we don't need to reset material
254
255 sep->addChild(coll_handle->material());
256 sep->addChild(m_genericBox);
257
258
259
260
261
262
263 // sep = new SoSeparator();
264 // sep->ref();
265
266
267 // cone = new SoCone();
268 // cone->ref();
269
270 // // coneR IS the opening half-angle of the jet, in delta phi (easy) and in
271 // // delta eta (trickier)
272 // // to try to get the jet extent right in eta, find theta corresponding
273 // // to eta+R, eta-R, and take half of the difference:
274 // double thetaMax = 2.*atan(exp(-(eta+inputconeR)));
275 // double thetaMin = 2.*atan(exp(-(eta-inputconeR)));
276 // double deltaTheta = fabs(thetaMax-thetaMin);
277 // double etaScale = deltaTheta/(2.*inputconeR);
278 //
279 // // Translate by half cone height and flip 180 deg so point is at IP:
280 // SoTranslation *translate = new SoTranslation();
281 //
282 // SoRotationXYZ *flip = new SoRotationXYZ();
283 // flip->axis=SoRotationXYZ::Z;
284 // flip->angle=M_PI;
285 //
286 // SoRotationXYZ *ytoz = new SoRotationXYZ();
287 // ytoz->axis=SoRotationXYZ::X;
288 // ytoz->angle=M_PI/2.;
289 //
290 // // Cones should now be along Z-axis,point at IP.
291 // SoRotationXYZ *rotationPhi = new SoRotationXYZ();
292 // rotationPhi->axis=SoRotationXYZ::Z;
293 // rotationPhi->angle = phi+M_PI/2.; // starts from -y-axis in x-y plane
294 // // phi is measured from x-axis, so +M_PI/2
295 //
296 // SoRotationXYZ *rotationEta = new SoRotationXYZ();
297 // double signEta = fabs(eta)/eta;
298 // double theta = 2.*atan(signEta*exp(-fabs(eta)));
299 // if (theta<0.)theta+=M_PI;
300 // rotationEta->axis=SoRotationXYZ::X;
301 // rotationEta->angle=theta;
302 //
303 // //message("Eta: "+QString::number(eta)+" theta: "+QString::number(theta)+" phi: "+QString::number(phi));
304 //
305 // updateConeHeightParameters(cone, translate, energy);
306 //
307 // // play with Scale:
308 // SoScale* myScale = new SoScale();
309 // //message("Eta scaling factor is "+QString::number(etaScale));
310 // // maybe we need to squish along both axes...
311 // myScale->scaleFactor.setValue(etaScale,1.,etaScale);
312 //
313 // // translate to origin vertex rather than (0,0,0)
314 // SoTranslation *transvertex = new SoTranslation();
315 // transvertex->translation = origin;
316 //
317 // sep->addChild(transvertex);
318 // sep->addChild(rotationPhi);
319 // sep->addChild(rotationEta);//theta rotation done around x-axis
320 // sep->addChild(ytoz); // now it's along the z-axis
321 // sep->addChild(flip); // flip so tip at origin
322 // sep->addChild(translate); // back it up so base at origin // DO NOT MOVE THIS: ITS POSITION IS USED BY "updateConeHeightParameters(SoSeparator* sep,const double& energy)"
323 // sep->addChild(myScale); // squeeze jet according to eta
324 // //This is the point in the child sequence where we MAY add a random colour when appropriate.
325 // //Thus: The translation is the SIXTH child and the cone is the LAST child.
326 //
327 // // sep->addChild(collHandle->collSettingsButton().defaultParameterMaterial());
328 //
329 // std::cout<<"About to add material: "<<collHandle->material()<<std::endl;
330 // sep->addChild(collHandle->material());
331 // // ^^ FIXME - should rearrange so we don't need to reset material
332 //
333 // sep->addChild(cone); // starts along y-axis // DO NOT MOVE THIS: ITS POSITION IS USED BY "updateConeHeightParameters(SoSeparator* sep,const double& energy)"
334
335}
336
338//void IParticleHandle_CaloCluster::Imp::updateConeHeightParameters(SoCone*cone, SoTranslation* trans, const double& energy) const
339//{
340// VP1Msg::messageVerbose("IParticleHandle_CaloCluster::Imp::updateConeHeightParameters()");
341//
342// double h(scale * energy);
343//
344// // FIXME: check this! when maxR is set, what should that do?? Here it's only used as "h", but maybe it should set the max length of the cone's bottom radius?? Check with Ed!
345// if (maxR > 0.0001) { // maxR > 0. is not univocally defined, because maxR is a floating point number
346// VP1Msg::messageVerbose("maxR > 0.0001 ==> setting h = min(h, maxR)");
347// h = std::min(h, maxR);
348// }
349//
350// cone->height = h;
351// cone->bottomRadius = tan(coneR()) * h;
352// trans->translation = SbVec3f(0,-0.5*h, 0);
353//
354//
355//
356// //debug
357// SbString strHeight, strRadius;
358// (cone->height).get(strHeight);
359// (cone->bottomRadius).get(strRadius);
360// std::cout << "input - energy: " << energy << " - scale: " << scale << " - maxR: " << maxR << " - h: " << h << " --- updated cone - height: " << strHeight.getString() << " - bottom radius: " << strRadius.getString() << std::endl;
361//
362// // you can also use the 'writeField()' method, direct to std output
363// //SoDebug::writeField(&(cone->height));
364//
365// // QString text = "updated cone - height: " + QString::number(cone->height) + " - bottom radius: " + QString::number(cone->bottomRadius) " - translation: " + trans->translation;
366// // VP1Msg::messageVerbose(text);
367//}
368
369
371//void IParticleHandle_CaloCluster::Imp::updateConeHeightParameters() const {
372//
373//
374// if (!sep) {
375// VP1Msg::messageVerbose("sep not defined. Returning.");
376// return;
377// }
378//
379// //NB: The translation is the SIXTH child and the cone is the LAST child.
380// if (sep->getNumChildren()<6) {
381// VP1Msg::messageVerbose("getNumChildren() < 6!!! Returning...");
382// return;
383// }
384//
385// const double energyJet = energyForLengthAndCuts();
386//
387// SoNode * sixthChild = sep->getChild(5);
388// if (sixthChild->getTypeId()!=SoTranslation::getClassTypeId()) {
389// VP1Msg::messageVerbose("6th child is not a translation!!! Returning...");
390// return;
391// }
392// SoNode * lastChild = sep->getChild(sep->getNumChildren()-1);
393// if (lastChild->getTypeId()!=SoCone::getClassTypeId()) {
394// VP1Msg::messageVerbose("lastChild is not a cone!!! Returning...");
395// return;
396// }
397// updateConeHeightParameters(static_cast<SoCone*>(lastChild),static_cast<SoTranslation*>(sixthChild), energyJet);
398//}
399
400
404//____________________________________________________________________
406{
407 QStringList l;
408 l << "--CaloCluster:";
409 //l << IParticleHandleBase::baseInfo();
410
411 // info and parameters,
412 // they go in the "Information" column in the Browser window
413 // see: http://acode-browser.usatlas.bnl.gov/lxr/source/atlas/Event/xAOD/xAODCaloEvent/xAODCaloEvent/versions/CaloCluster_v1.h
414 //
415 l +=" - pt: " + QString::number(m_d->m_cluster->pt() / SYSTEM_OF_UNITS::GeV) +" [GeV]";
416 l +=" - et: " + QString::number(m_d->et() / SYSTEM_OF_UNITS::GeV) +" [GeV]";
417 l +=" - eta: " + QString::number(m_d->eta());
418 l +=" - phi: " + QString::number(m_d->phi());
419 l +=" - m: " + QString::number(m_d->m_cluster->m() / SYSTEM_OF_UNITS::GeV) +" [GeV] (invariant mass of the particle)";
420 l +=" - e: " + QString::number(m_d->m_cluster->e() / SYSTEM_OF_UNITS::GeV) +" [GeV] (total energy of the particle)";
421 l +=" - rapidity: " + QString::number(m_d->m_cluster->rapidity());
422 l +=" - type: " + QString::number(m_d->m_cluster->type());
423 l +=" - ClusterSize: " + QString::number(m_d->m_cluster->clusterSize());
424 l +=" - inBarrel: " + QString::number(m_d->m_cluster->inBarrel());
425 l +=" - inEndcap: " + QString::number(m_d->m_cluster->inEndcap());
426
427 return l;
428}
429
430/*
431//____________________________________________________________________
432Amg::Vector3D IParticleHandle_CaloCluster::momentum() const
433{
434 const Trk::Perigee& p = m_d->trackparticle->perigeeParameters();
435 return p.momentum();
436}
437 */
438
439//____________________________________________________________________
441{
442 return *(m_d->m_cluster);
443}
444
445
446//____________________________________________________________________
448{
449 //return m_d->trackparticle->charge(); // TODO: check in Jet interface if a "charge" quantity is defined
450 return 0; // FIXME: dummy value now
451}
452
453
454
455/*
456 * TODO: If Jet class has something like SummaryType like TrackParticle has, implement this method. Otherwise, remove it!
457 *
458 */
459/*
460//____________________________________________________________________
461unsigned IParticleHandle_CaloCluster::summaryValue(xAOD::SummaryType type) const
462{
463 uint8_t num = 0;
464 if (m_d->trackparticle->summaryValue(num,type)){
465 return num;
466 }
467 // else...
468 VP1Msg::message("IParticleHandle_CaloCluster::getSummaryValue - unable to retrieve the requested enum: "+VP1Msg::str(type));
469 return 999999;
470}
471 */
472
473
477//____________________________________________________________________
479{
480 QString dParameters("(");
481
482 // info and parameters,
483 // they go in the "Information" column in the Browser window
484 dParameters +="pt: ";
485 dParameters += QString::number(m_d->m_cluster->pt() / SYSTEM_OF_UNITS::GeV);
486
487 dParameters +=", et: ";
488 dParameters += QString::number(m_d->m_cluster->et() / SYSTEM_OF_UNITS::GeV);
489
490 dParameters +=", eta: ";
491 dParameters += QString::number(m_d->m_cluster->eta());
492
493 dParameters +=", phi: ";
494 dParameters += QString::number(m_d->m_cluster->phi());
495
496 dParameters+="";
497
498 dParameters+=")" ;
499
500 return dParameters;
501}
502
503
507//____________________________________________________________________
508void IParticleHandle_CaloCluster::fillObjectBrowser( QList<QTreeWidgetItem *>& listOfItems)
509{
510 IParticleHandleBase::fillObjectBrowser(listOfItems); // Obligatory!
511
512 QTreeWidgetItem* TSOSitem = new QTreeWidgetItem(browserTreeItem());
513
514 // Jet "Object" title, in the Browser window
515 TSOSitem->setText(0, QString("CaloCluster Parameters " ) );
516
517 QString dParameters = shortInfo();
518 dParameters += " [more info in the main Message Box]";
519
520 TSOSitem->setText(1, dParameters );
521
522}
523
524
525
526
527//____________________________________________________________________
529 /*VP1Msg::messageVerbose("phi: " + QString::number(m_cluster->phi()) );*/
530 return m_d->phi();
531}
532
533
534//____________________________________________________________________
536 /*VP1Msg::messageVerbose("eta: " + QString::number(m_cluster->eta()) );*/
537 return m_d->eta();
538}
539
540
541//____________________________________________________________________
542double IParticleHandle_CaloCluster::e() const { return m_d->e(); }
543
544
545//____________________________________________________________________
547 VP1Msg::messageDebug("IParticleHandle_CaloCluster::energyForCuts()");
548 return m_d->energyForLengthAndCuts();
549}
550
551
552//____________________________________________________________________
553double IParticleHandle_CaloCluster::et() const { return m_d->et(); }
554
555
557
558//____________________________________________________________________
559//void IParticleHandle_CaloCluster::Imp::updateMaterial()
560//void IParticleHandle_CaloCluster::updateMaterial(bool isRandomColors)
562{
563 VP1Msg::messageVerbose("IParticleHandle_CaloCluster::Imp::updateMaterial()");
564
565 // check if we have 3D objects; if not, return
566 if ( m_d->sep == 0 )
567 return;
568
569 // if (!isRandomColors && !m_d->m_randomMat)
570 // return;//m_randomMat can never have been attached
571 //
572 // if (isRandomColors && !m_d->m_randomMat) {
573 // m_d->m_randomMat = new SoMaterial;
574 // m_d->m_randomMat->ref();
575 // rerandomiseMaterial();
576 // }
577
578
579 // int i = m_d->sep->findChild(m_d->m_randomMat);
580
581 // if ( (i>=0) == isRandomColors ) {
582 // VP1Msg::messageVerbose("(i>=0)==isRandomColors. Returning.");
583 // return;
584 // }
585
586 // if (!isRandomColors )
587 // m_d->sep->removeChild(m_d->m_randomMat);
588 // else
589 // m_d->sep->insertChild(m_d->m_randomMat, m_d->sep->getNumChildren()-1);
590}
591
592
593void IParticleHandle_CaloCluster::dumpToJSON( std::ofstream& str) const {
594 str << "\"phi\":" <<m_d->phi() <<", ";
595 str << "\"eta\":" <<m_d->eta() <<", ";
596 str << "\"energy\":" <<m_d->e();
597}
598
const AODCollHandleBase * collHandle() const
QTreeWidgetItem * browserTreeItem() const
Return the QTreeWidgetItem;.
virtual void fillObjectBrowser(QList< QTreeWidgetItem * > &list)
Create and fill the object browser QTreeWidgetItem.
Base class for collections holding AOD objects of iParticle type Handles pt etc cuts Local data:
double energyToLength(const double &energy) const
IParticleHandleBase(IParticleCollHandleBase *)
const xAOD::CaloCluster * cluster() const
void createShapeFromParameters(const IParticleCollHandle_CaloCluster *coll_handle)
const IParticleCollHandle_CaloCluster * theCollHandle
void updateShapePars(const IParticleCollHandle_CaloCluster *coll_handle)
double energyForLengthAndCuts(const IParticleCollHandle_CaloCluster *coll_handle)
virtual SoNode * nodes()
Returns the 3Dobjects.
IParticleHandle_CaloCluster(IParticleCollHandleBase *, const xAOD::CaloCluster *)
virtual void dumpToJSON(std::ofstream &) const
virtual void clear3DObjects()
Delete objects.
QString shortInfo() const
This returns the information shown about the object in the object browser.
virtual QStringList clicked() const
This gives the complete information about the object, shown in the main Message Box.
const xAOD::IParticle & iParticle() const
virtual bool has3DObjects()
Returns true if the 3D objects have been created.
void updateShape(IParticleCollHandle_CaloCluster *coll)
void fillObjectBrowser(QList< QTreeWidgetItem * > &listOfItems)
This gives the list of object's properties, shown in the 'Information' field in the Browser,...
virtual double charge() const
Returns unknown() in case of trouble.
static void initClass()
static void messageVerbose(const QString &)
Definition VP1Msg.cxx:84
static void messageDebug(const QString &)
Definition VP1Msg.cxx:39
SoMaterial * material() const
static QString str(const QString &s)
Definition VP1String.h:49
Class providing the definition of the 4-vector interface.
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.