ATLAS Offline Software
EventDensityTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // EventDensityTool.cxx
6 
8 #include "fastjet/JetDefinition.hh"
9 #include "fastjet/AreaDefinition.hh"
10 #include "fastjet/ClusterSequenceArea.hh"
13 #include "JetEDM/PseudoJetVector.h"
16 
17 using fastjet::JetAlgorithm;
18 using fastjet::JetDefinition;
20 using fastjet::ClusterSequenceArea;
21 using fastjet::AreaDefinition;
22 using fastjet::VoronoiAreaSpec;
23 
24 //**********************************************************************
25 
27  : asg::AsgTool(name),
28  m_useAreaFourMom(true)
29 {
30  declareProperty("JetAlgorithm", m_jetalg = "Kt");
31  declareProperty("JetRadius", m_jetrad = 0.4);
32  declareProperty("AbsRapidityMin", m_rapmin = 0.0);
33  declareProperty("AbsRapidityMax", m_rapmax = 2.0);
34  declareProperty("AreaDefinition", m_areadef = "Voronoi");
35  declareProperty("VoronoiRfact", m_vrfact = 1.0);
36  declareProperty("UseFourMomArea", m_useAreaFourMom);
37  declareProperty("TrigPseudoJetGetter", m_trigPJGet);
38 }
39 
40 //**********************************************************************
41 
43 
44 //**********************************************************************
45 
47  ATH_MSG_INFO ("Initializing " << name() << "...");
48 
49  // Initialise output handle
50  ATH_CHECK( m_outEDKey.initialize() );
51 
52  // Fetch the fastjet algorithm enum
53  JetAlgorithm fjalg;
54  if ( m_jetalg == "Kt" ) fjalg = fastjet::kt_algorithm;
55  else if ( m_jetalg == "AntiKt" ) fjalg = fastjet::antikt_algorithm;
56  else if ( m_jetalg == "CamKt" ) fjalg = fastjet::cambridge_algorithm;
57  else {
58  ATH_MSG_ERROR("Invalid jet algorithm name: " << m_jetalg);
59  ATH_MSG_ERROR("Allowed values are Kt, CamKt, AntiKt, etc.");
60  return StatusCode::FAILURE;
61  }
62 
63  // Build jet definition.
64  m_fjjetdef = JetDefinition(fjalg, m_jetrad);
65 
66  // Build area definition.
67  if ( m_areadef == "Voronoi" ) {
68  m_fjareadef = AreaDefinition(fastjet::voronoi_area, VoronoiAreaSpec(m_vrfact));
69  } else if ( m_areadef == "Active" || m_useAreaFourMom ) {
70  // Default is fine here for now.
71  // Later might want to switch to seeds and binning used in jet reco.
72  // See JetRec/JetFinder for that.
73  } else {
74  ATH_MSG_WARNING("Unsupported area option: " << m_areadef);
75  return StatusCode::FAILURE;
76  }
77 
78  // Build the jet selector.
79  if ( m_rapmin >= 0.0 && m_rapmax > m_rapmin ) {
80  m_fjselector = fastjet::SelectorAbsRapRange(m_rapmin, m_rapmax);
81  } else {
82  ATH_MSG_WARNING("Invalid absolute rapidity range: ("
83  << m_rapmin << ", " << m_rapmax << ")");
84  return StatusCode::FAILURE;
85  }
86  ATH_MSG_INFO("Configured properties:");
87  ATH_MSG_INFO(" JetAlgorithm: " << m_jetalg);
88  ATH_MSG_INFO(" JetRadius: " << m_jetrad);
89  if(!m_inPJKey.key().empty()) {
90  ATH_MSG_INFO(" InputContainer: " << m_inPJKey.key());
91  } else {
92  ATH_MSG_INFO(" TrigPJGetter: " << m_trigPJGet.name());
93  }
94  ATH_MSG_INFO(" AbsRapidityMin: " << m_rapmin);
95  ATH_MSG_INFO(" AbsRapidityMax: " << m_rapmax);
96  ATH_MSG_INFO(" AreaDefinition: " << m_areadef);
97  ATH_MSG_INFO(" VoronoiRfact: " << m_vrfact);
98  ATH_MSG_INFO(" OutputContainer: " << m_outEDKey.key());
99  ATH_MSG_INFO("Derived properties:");
100  ATH_MSG_INFO(" Fastjet jet defn: " << m_fjjetdef.description());
101  ATH_MSG_INFO(" Fastjet area defn: " << m_fjareadef.description());
102  ATH_MSG_INFO(" Fastjet jet selector: " << m_fjselector.description());
103  ATH_MSG_INFO(" Use area four-momentum: " << m_useAreaFourMom);
104 
105  // Input sources
106  if(!m_inPJKey.key().empty() && m_trigPJGet.empty()) {
108  }
109  // { FIXME: To be removed when trigger moves to DataHandles fully
110  else if(m_inPJKey.key().empty() && !m_trigPJGet.empty()) {
111  ATH_CHECK( m_trigPJGet.retrieve() );
112  }
113  // } FIXME
114  else {
115  ATH_MSG_ERROR( "Inconsistent/ambiguous input setup."
116  << " InPJKey: " << m_inPJKey.key()
117  << " TrigPJGetter: " << m_trigPJGet.name() );
118  return StatusCode::FAILURE;
119  }
120 
121  return StatusCode::SUCCESS;
122 }
123 
124 //**********************************************************************
125 
127 
128  ATH_MSG_DEBUG("Begin fillEventShape()");
129 
130  std::unique_ptr<xAOD::EventShape> eventShape(std::make_unique<xAOD::EventShape>());
131  std::unique_ptr<xAOD::EventShapeAuxInfo> eventShapeaux(std::make_unique<xAOD::EventShapeAuxInfo>());
132  eventShape->setStore( eventShapeaux.get() );
133 
134  // Change the order: first fill the object and then record
135  ATH_CHECK(fillEventShape(eventShape.get()));
136 
137  auto h_out = makeHandle(m_outEDKey);
138  if ( ! h_out.record(std::move(eventShape), std::move(eventShapeaux) )) {
139  ATH_MSG_WARNING("Unable to write new EventShape and aux store to event store: " << m_outEDKey.key());
140  } else {
141  ATH_MSG_DEBUG("Created new EventShape container: " << m_outEDKey.key());
142  }
143 
144  return StatusCode::SUCCESS;
145 }
146 
147 //**********************************************************************
149 
150  if(!m_inPJKey.key().empty() && m_trigPJGet.empty()) {
151  auto h_in = makeHandle(m_inPJKey);
152  if( ! h_in.isValid() ) {
153  ATH_MSG_ERROR("No input PseudoJetContainer "<< m_inPJKey.key() );
154  return StatusCode::FAILURE;
155  }
156  if ( h_in->size() == 0 ) {
157  ATH_MSG_DEBUG( "Input PseudoJetContainer size()=0 for pseudojets from "<< m_inPJKey.key() );
158  } else {
159  ATH_MSG_DEBUG("Retrieved input pseudojets " << m_inPJKey.key() << " , count: " << h_in->size());
160  }
161  return fillEventShape(eventShape, *(h_in->casVectorPseudoJet()));
162  }
163  // { FIXME: To be removed when trigger moves to DataHandles fully
164  else if(m_inPJKey.key().empty() && !m_trigPJGet.empty()) {
165  const PseudoJetVector& ppjv = *(m_trigPJGet->get());
166  // !!! FIXME !!! Downgraded ERROR to WARNING and no FAILURE
167  if ( ppjv.size() == 0 ) {
168  ATH_MSG_WARNING( "Input PseudoJetVector size()=0 for pseudojets from "<< m_trigPJGet.name() );
169  //return StatusCode::FAILURE;
170  } else {
171  ATH_MSG_DEBUG("Retrieved input pseudojets " << m_trigPJGet.name() << " , count: " << ppjv.size());
172  }
173  return fillEventShape(eventShape, ppjv);
174  }
175  // } FIXME
176 
177  return StatusCode::FAILURE;
178 }
179 
180 //**********************************************************************
181 
183 fillEventShape( xAOD::EventShape* eventShape, const PseudoJetVector& pjv) const {
184  ATH_MSG_DEBUG("Input pseudojet count: " << pjv.size());
185  ATH_MSG_DEBUG("Event shape container address: " << eventShape);
186 
187  for(const auto & pj : pjv) {
188  ATH_MSG_DEBUG(" pj input e="<<pj.e() << " pz="<<pj.pz() << " px="<<pj.px() );
189  }
190  // Find jets.
191  std::unique_ptr<ClusterSequenceArea> pcsa=std::make_unique<ClusterSequenceArea>(pjv, m_fjjetdef, m_fjareadef);
192  ATH_MSG_DEBUG("Found jet count: " << pcsa->inclusive_jets().size());
193 
194  // Extract rho.
195  double rho, sigma, area;
196  pcsa->get_median_rho_and_sigma(m_fjselector, m_useAreaFourMom, rho, sigma, area);
197  ATH_MSG_DEBUG(" calculated rho="<< rho);
198 
199  // Record rho.
200 
201  // Fill the EventShape object
202  const static SG::AuxElement::Accessor<float> rhoDec("Density");
203  const static SG::AuxElement::Accessor<float> sigmaDec("DensitySigma");
204  const static SG::AuxElement::Accessor<float> areaDec("DensityArea");
205  rhoDec(*eventShape) = rho;
206  sigmaDec(*eventShape) = sigma;
207  areaDec(*eventShape) = area;
208 
209  ATH_MSG_DEBUG("Recorded event density: = " << 0.001*rho << " GeV");
210 
211  return StatusCode::SUCCESS;
212 }
WriteHandle.h
Handle class for recording to StoreGate.
pdg_comparison.sigma
sigma
Definition: pdg_comparison.py:324
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
xAOD::JetAlgorithmType::kt_algorithm
@ kt_algorithm
Definition: JetContainerInfo.h:31
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:66
EventShape.h
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
PseudoJetVector.h
ViewHelper::makeHandle
SG::ReadHandle< T > makeHandle(const SG::View *view, const SG::ReadHandleKey< T > &rhKey, const EventContext &context)
navigate from the TrigComposite to nearest view and fetch object from it
Definition: ViewHelper.h:258
asg
Definition: DataHandleTestTool.h:28
EventDensityTool::m_trigPJGet
ToolHandle< IPseudoJetGetter > m_trigPJGet
Definition: EventDensityTool.h:74
EventDensityTool::m_useAreaFourMom
bool m_useAreaFourMom
Definition: EventDensityTool.h:92
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
EventDensityTool.h
EventDensityTool::m_fjjetdef
fastjet::JetDefinition m_fjjetdef
Definition: EventDensityTool.h:89
EventDensityTool::m_jetrad
float m_jetrad
Definition: EventDensityTool.h:82
EventDensityTool::m_rapmin
float m_rapmin
Definition: EventDensityTool.h:83
EventDensityTool::~EventDensityTool
~EventDensityTool()
Destructor:
Definition: EventDensityTool.cxx:42
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
jet::ClusterSequence
fastjet::ClusterSequence ClusterSequence
Definition: ClusterSequence.h:21
SG::AuxElement::setStore
void setStore(const SG::IConstAuxStore *store)
Set the store associated with this object.
Definition: AuxElement.cxx:221
EventDensityTool::m_jetalg
std::string m_jetalg
Definition: EventDensityTool.h:81
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
EventDensityTool::m_fjselector
fastjet::Selector m_fjselector
Definition: EventDensityTool.h:91
EventDensityTool::m_inPJKey
SG::ReadHandleKey< PseudoJetContainer > m_inPJKey
Definition: EventDensityTool.h:77
EventDensityTool::m_outEDKey
SG::WriteHandleKey< xAOD::EventShape > m_outEDKey
Definition: EventDensityTool.h:78
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
xAOD::EventShape_v1
Data class for event shapes.
Definition: EventShape_v1.h:28
EventDensityTool::initialize
StatusCode initialize()
Initialization.
Definition: EventDensityTool.cxx:46
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
EventDensityTool::m_rapmax
float m_rapmax
Definition: EventDensityTool.h:84
ReadHandle.h
Handle class for reading from StoreGate.
xAOD::JetAlgorithmType::cambridge_algorithm
@ cambridge_algorithm
Definition: JetContainerInfo.h:32
xAOD::JetAlgorithmType::antikt_algorithm
@ antikt_algorithm
Definition: JetContainerInfo.h:33
EventShapeAuxInfo.h
EventDensityTool::m_areadef
std::string m_areadef
Definition: EventDensityTool.h:85
PseudoJetVector
std::vector< fastjet::PseudoJet > PseudoJetVector
Definition: JetConstituentFiller.cxx:17
EventDensityTool::m_fjareadef
fastjet::AreaDefinition m_fjareadef
Definition: EventDensityTool.h:90
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
area
double area(double R)
Definition: ConvertStaveServices.cxx:42
EventDensityTool::m_vrfact
float m_vrfact
Definition: EventDensityTool.h:86
EventDensityTool::fillEventShape
StatusCode fillEventShape() const
Action.
Definition: EventDensityTool.cxx:126
EventDensityTool::EventDensityTool
EventDensityTool(const std::string &name)
Constructor with parameters:
Definition: EventDensityTool.cxx:26
fitman.rho
rho
Definition: fitman.py:532
JetAlgorithm
Definition: JetAlgorithm.h:17