ATLAS Offline Software
Loading...
Searching...
No Matches
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"
16
17using fastjet::JetAlgorithm;
18using fastjet::JetDefinition;
19using fastjet::ClusterSequence;
20using fastjet::ClusterSequenceArea;
21using fastjet::AreaDefinition;
22using fastjet::VoronoiAreaSpec;
23
24//**********************************************************************
25
26EventDensityTool::EventDensityTool(const std::string& name)
27 : asg::AsgTool(name),
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()) {
107 ATH_CHECK( m_inPJKey.initialize() );
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
183fillEventShape( 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}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Handle class for reading from StoreGate.
Handle class for recording to StoreGate.
double area(double R)
std::vector< fastjet::PseudoJet > PseudoJetVector
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
StatusCode initialize()
Initialization.
fastjet::AreaDefinition m_fjareadef
SG::ReadHandleKey< PseudoJetContainer > m_inPJKey
SG::WriteHandleKey< xAOD::EventShape > m_outEDKey
std::string m_areadef
EventDensityTool(const std::string &name)
Constructor with parameters:
ToolHandle< IPseudoJetGetter > m_trigPJGet
~EventDensityTool()
Destructor:
StatusCode fillEventShape() const
Action.
fastjet::JetDefinition m_fjjetdef
fastjet::Selector m_fjselector
SG::Accessor< T, ALLOC > Accessor
Definition AuxElement.h:572
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
EventShape_v1 EventShape
Definition of the current event format version.
Definition EventShape.h:16