1 // emacs, this is -*- C++ -*-
4 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
7 /////////// ///////////
8 // Public: Signal State //
9 /////////// ///////////
14 inline const std::vector<Jet::mkey_t> Jet::infoKeys() const
16 // the vector might has empty elements, because not necessarily all
17 // taginfos are filled for every event
18 std::vector<mkey_t> vKeys;
19 if ( bool(m_tagInfoStore) )
20 for ( tagstore_t::iterator itr = m_tagInfoStore->begin();
21 itr != m_tagInfoStore->end(); ++itr )
23 vKeys.push_back( (*itr)->infoType() );
27 inline Jet::signalstate_t Jet::constituentSignalState() const
29 return m_constituentSigState;
33 /////////// ///////////
34 // Public: Four-momentum Setters //
35 /////////// ///////////
37 inline void Jet::setP(const hlv_t& rVec) { this->set4Mom(rVec); }
40 /////////// ///////////
41 // Public: Jet Algebra Operators //
42 /////////// ///////////
45 inline void Jet::setE (double e ) { this->momentumBase().setE (e ); }
46 inline void Jet::setPx(double px) { this->momentumBase().setPx(px); }
47 inline void Jet::setPy(double py) { this->momentumBase().setPy(py); }
48 inline void Jet::setPz(double pz) { this->momentumBase().setPz(pz); }
50 inline void Jet::setE (double e , signalstate_t s) { this->momentumBase(s).setE (e ); }
51 inline void Jet::setPx(double px, signalstate_t s) { this->momentumBase(s).setPx(px); }
52 inline void Jet::setPy(double py, signalstate_t s) { this->momentumBase(s).setPy(py); }
53 inline void Jet::setPz(double pz, signalstate_t s) { this->momentumBase(s).setPz(pz); }
55 inline bool Jet::operator==(const Jet& rJet) const
56 { return this->isIdentical(rJet); }
57 inline bool Jet::operator==(const Jet* pJet) const
58 { return this->isIdentical(pJet); }
59 inline bool Jet::operator!=(const Jet& rJet) const
60 { return !(this->isIdentical(rJet)); }
61 inline bool Jet::operator!=(const Jet* pJet) const
62 { return !(this->isIdentical(pJet)); }
64 inline bool Jet::isIdentical(const Jet& rJet) const
65 { return this->isIdentical(&rJet); }
67 inline Jet& Jet::operator=(const Jet& rJet)
69 // Check for illegal self-assignment
70 // Otherwise constituents will be duplicated
72 copy_from_jet(&rJet, CopyAll);
77 /////////// ///////////
78 // Public: Access to Constituents //
79 /////////// ///////////
81 // inline const Jet::constituent_coll_t& Jet::getConstituentStore() const
82 // { return *((this->navigableBase()).getPtrToConstituents()); }
84 inline Jet::const_iterator Jet::begin() const
85 { return (this->navigableBase()).begin(); }
86 inline Jet::const_iterator Jet::end() const
87 { return (this->navigableBase()).end(); }
89 inline size_t Jet::size() const
90 { return (this->navigableBase()).size(); }
92 inline bool Jet::contains(const constituent_t* pConst) const
93 { return (this->navigableBase()).contains(pConst); }
94 inline bool Jet::contains(const collection_t* pColl,index_t ind) const
95 { return (this->navigableBase()).contains(pColl,ind); }
97 inline double Jet::getWeight(const constituent_t* pConst) const
98 { return this->getParameter(pConst); }
99 inline double Jet::getWeight(const collection_t* pColl,index_t ind) const
100 { return this->getParameter(pColl,ind); }
101 inline double Jet::getWeight(const_iterator fConst) const
102 { return this->getParameter(fConst); }
104 inline Jet* Jet::getOverlap(const Jet& rJet, bool noKine /*= false*/) const
105 { return this->getOverlap(&rJet, noKine); }
107 /** @detail Iterator to first constituent.
108 @warning To be phased out! Use @c Jet::begin() instead!
110 inline Jet::const_iterator Jet::firstConstituent() const
111 { return this->begin(); }
112 /** @detail Terminating constituent iterator.
113 @warning To be phased out! Use @c Jet::end() instead!
115 inline Jet::const_iterator Jet::lastConstituent() const
116 { return this->end(); }
118 /////////// ///////////
119 // Protected: Access to Constituents //
120 /////////// ///////////
122 inline double Jet::getParameter(const constituent_t* pConst) const
123 { return (this->navigableBase()).getParameter(pConst); }
124 inline double Jet::getParameter(const collection_t* pColl,index_t ind) const
125 { return (this->navigableBase()).getParameter(pColl,ind); }
126 inline double Jet::getParameter(const_iterator fConst) const
127 { return (this->navigableBase()).getParameter(fConst); }
129 inline const Jet::collection_t*
130 Jet::getContainer(const constituent_t* pConst) const
131 { return (this->navigableBase()).getContainer(pConst); }
132 inline const Jet::collection_t*
133 Jet::getContainer(const_iterator fConst) const
134 { return (this->navigableBase()).getContainer(fConst); }
136 inline bool Jet::getIndex(const constituent_t* pConst,index_t& ind) const
137 { return (this->navigableBase()).getIndex(pConst,ind); }
138 inline bool Jet::getIndex(const_iterator fConst,index_t& ind) const
139 { return (this->navigableBase()).getIndex(fConst,ind); }
141 /////////// ///////////
142 // Public: Constituent Management //
143 /////////// ///////////
145 inline bool Jet::removeConstituent(const collection_t* pColl,index_t ind)
149 ? this->removeConstituent((pColl->operator[])(ind))
153 inline bool Jet::removeConstituent(bool reset)
155 // reset four-momentum if needed
156 if ( reset ) this->set4Mom(hlv_t(0.,0.,0.,0.));
157 return this->remove();
160 /////////// ///////////
161 // Protected: Constituent Management //
162 /////////// ///////////
164 inline void Jet::putElement(const collection_t* pColl,
165 const constituent_t* pConst,
168 { (this->navigableBase()).putElement(pColl,pConst,wght,sizeHint); m_constituentsN++;}
169 inline void Jet::putElement(const collection_t* pColl,
173 { (this->navigableBase()).putElement(pColl,ind,wght,sizeHint); m_constituentsN++;}
175 inline void Jet::insertElement(const collection_t* pColl,
176 const constituent_t* pConst,
179 { (this->navigableBase()).insertElement(pColl,pConst,wght,sizeHint); m_constituentsN++;}
180 inline void Jet::insertElement(const collection_t* pColl,
184 { (this->navigableBase()).insertElement(pColl,ind,wght,sizeHint); m_constituentsN++;}
186 // inline void Jet::reweight(const constituent_t* pConst,double wght)
187 // { (this->navigableBase()).reweight(pConst,wght); }
188 // inline void Jet::reweight(const collection_t* pColl,index_t ind,double wght)
189 // { (this->navigableBase()).reweight(pColl,ind,wght); }
191 inline bool Jet::remove(const constituent_t* pConst)
192 { if ( (this->navigableBase()).remove(pConst) ) {m_constituentsN--;return true;} return false; }
193 inline bool Jet::remove(const collection_t* pColl,index_t ind)
194 { if ( (this->navigableBase()).remove(pColl,ind) ){ m_constituentsN--;return true;} return false; }
195 inline bool Jet::remove()
196 { if ( (this->navigableBase()).removeAll() ){ m_constituentsN=0;return true;} return false;}
198 /////////// ///////////
199 // Public: Navigation //
200 /////////// ///////////
202 inline void Jet::fillToken(INavigationToken& navToken) const
203 { (this->navigableBase()).fillToken(navToken); }
204 inline void Jet::fillToken(INavigationToken& navToken,
205 const std::any& par) const
206 { (this->navigableBase()).fillToken(navToken,par); }
208 /////////// ///////////
209 // Public: Access to Jet Shapes //
210 /////////// ///////////
212 inline void Jet::setMoment(const mkey_t& shapeName,shape_t shape,
213 bool createIfMissing) const
214 { this->setShape(shapeName,shape,createIfMissing); }
216 inline Jet::shape_t Jet::getMoment(const mkey_t& shapeName,
217 bool createIfMissing) const
218 { return this->getShape(shapeName,createIfMissing); }
220 inline std::vector<Jet::mkey_t> Jet::getMomentKeys() const
221 { return this->getShapeKeys(); }
224 inline bool Jet::checkKey(const mcat_t& cat,
227 bool createIfMissing) const
229 // get index for data word
230 aInd = keyDesc()->getIndex(cat,key,createIfMissing);
231 return keyDesc()->isValid(aInd);
234 /////////// ///////////
235 // Public: Access to Tag Info //
236 /////////// ///////////
238 inline const Jet::tagstore_t Jet::jetTagInfoVector(void) const
244 // the vector might has empty elements, because not necessarily all
245 // taginfos are filled for every event. Need to return a copy
246 // of the TagInfoStore with all zeros removed
247 if ( bool(m_tagInfoStore) )
248 for (const taginfo_t* tag : std::as_const(*m_tagInfoStore)) {
249 if ( tag != nullptr )
250 store.push_back( tag );
256 inline const Jet::taginfo_t* Jet::tagInfo(const mkey_t& key) const
258 size_t aInd(keyDesc()->getIndex(JetKeyConstants::TagCat,key,false));
259 return bool(m_tagInfoStore) && aInd < m_tagInfoStore->size()
260 ? (m_tagInfoStore->operator[])(aInd) : (const taginfo_t*)0;
264 template<typename TAGINFO>
265 const TAGINFO* Jet::getTagInfo(const mkey_t& key,bool /*useLink*/) const
267 return this->getObject<TAGINFO,tagstore_t>(key,m_tagInfoStore,JetKeyConstants::TagCat, false);
270 template<class TAGINFO>
271 const TAGINFO* Jet::tagInfo(const mkey_t& key) const
273 return this->getTagInfo<TAGINFO>(key);
276 template<class TAGINFO>
277 void Jet::addInfo(const TAGINFO* tag)
279 this->setTagInfo( tag->infoType(), tag );
285 /////////// ///////////
286 // Public: Associations //
287 /////////// ///////////
289 template<typename ASSOC> const ASSOC*
290 Jet::getAssociation(const mkey_t& key, bool /*useLink*/ ) const
292 return this->getObject<ASSOC,assostore_t>(key,m_assocStore,JetKeyConstants::AssoCat, false);
296 void Jet::setAssociation(const T* pAssoc,bool /*useLink*/)
298 // use check function
299 size_t aInd(size_t(-1));
300 std::string key = pAssoc->name();
302 if ( ! bool(m_assocStore) )
303 // checkKey automatically build new store !!!
304 m_assocStore = new assostore_t();
306 if ( this->checkKeyStore(JetKeyConstants::AssoCat,key,m_assocStore,aInd, true) ) {
307 removeAssociation(aInd);
308 (m_assocStore->operator[])(aInd) = pAssoc;
312 inline void Jet::removeAssociation( const mkey_t& key )
314 if ( bool(m_assocStore) ) {
316 if ( this->checkKeyStore(JetKeyConstants::AssoCat,key,m_assocStore,aInd, false) ) {
317 removeAssociation(aInd);
322 inline void Jet::removeAssociation (const size_t index)
324 delete (m_assocStore->operator[])(index);
325 (m_assocStore->operator[])(index) = 0;
328 /////////////////////////////////////////
329 /// constituent and jet signal states ///
330 /////////////////////////////////////////
331 inline void Jet::setConstituentSignalState( Jet::signalstate_t s )
333 m_constituentSigState = s;
336 /////////////////////////////////////////
337 /// Compatibility with JetAnalysisEDM
338 /////////////////////////////////////////
340 // Write helper class to allow specialization for std::vector<T>
341 template <typename T>
342 struct JetAnalysisEDMHelper {
343 static T get(const Jet* j, const std::string & mName){
344 return j->getMoment(mName);
346 static void set(const Jet* j, const std::string & mName, const T & v){
347 j->setMoment(mName,v);
351 template <typename T>
352 struct JetAnalysisEDMHelper<std::vector<T> > {
353 static std::vector<T> get(const Jet* j, const std::string & mName){
354 std::vector<std::string> allMoms = j->getMomentKeys() ;
355 std::vector<std::string> matchingMoms;
359 std::string prefix = mName+"_";
360 size_t msize = prefix.size();
363 // match all moments starting by "mName_"
364 for( size_t i=0; i< allMoms.size(); i++){
365 std::string & mom = allMoms[i];
366 if(mom.compare(0,msize, prefix)==0) matchingMoms.push_back(mom);
368 // We need "mName_0", "mName_1", etc... but matchingMoms also contains moments
369 // in the form "mName_something_0", ... etc. So sort them
370 std::sort(matchingMoms.begin(), matchingMoms.end() );
371 val.reserve( matchingMoms.size());
373 for( size_t i=0; i< matchingMoms.size(); i++){
374 std::stringstream s;s<< prefix<< i;
375 if( s.str() == matchingMoms[i]) val.push_back( j->getMoment(matchingMoms[i] ));
382 static void set(const Jet* j, const std::string & mName, const std::vector<T> & v){
383 for(size_t i=0;i<v.size();i++){
385 s << mName << "_"<< i;
386 j->setMoment(s.str(),v[i]);
392 T Jet::get(const std::string & mName) const { return JetAnalysisEDMHelper<T>::get(this,mName); }
395 void Jet::set(const std::string & mName, const T& v) const { return JetAnalysisEDMHelper<T>::set(this,mName,v); }