1 // emacs, this is -*- C++ -*-
4 Copyright (C) 2002-2022 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);
76 inline MsgStream& Jet::operator<<( MsgStream& out) {
77 return ( out << str() );
81 /////////// ///////////
82 // Public: Access to Constituents //
83 /////////// ///////////
85 // inline const Jet::constituent_coll_t& Jet::getConstituentStore() const
86 // { return *((this->navigableBase()).getPtrToConstituents()); }
88 inline Jet::const_iterator Jet::begin() const
89 { return (this->navigableBase()).begin(); }
90 inline Jet::const_iterator Jet::end() const
91 { return (this->navigableBase()).end(); }
93 inline size_t Jet::size() const
94 { return (this->navigableBase()).size(); }
96 inline bool Jet::contains(const constituent_t* pConst) const
97 { return (this->navigableBase()).contains(pConst); }
98 inline bool Jet::contains(const collection_t* pColl,index_t ind) const
99 { return (this->navigableBase()).contains(pColl,ind); }
101 inline double Jet::getWeight(const constituent_t* pConst) const
102 { return this->getParameter(pConst); }
103 inline double Jet::getWeight(const collection_t* pColl,index_t ind) const
104 { return this->getParameter(pColl,ind); }
105 inline double Jet::getWeight(const_iterator fConst) const
106 { return this->getParameter(fConst); }
108 inline Jet* Jet::getOverlap(const Jet& rJet, bool noKine /*= false*/) const
109 { return this->getOverlap(&rJet, noKine); }
111 /** @detail Iterator to first constituent.
112 @warning To be phased out! Use @c Jet::begin() instead!
114 inline Jet::const_iterator Jet::firstConstituent() const
115 { return this->begin(); }
116 /** @detail Terminating constituent iterator.
117 @warning To be phased out! Use @c Jet::end() instead!
119 inline Jet::const_iterator Jet::lastConstituent() const
120 { return this->end(); }
122 /////////// ///////////
123 // Protected: Access to Constituents //
124 /////////// ///////////
126 inline double Jet::getParameter(const constituent_t* pConst) const
127 { return (this->navigableBase()).getParameter(pConst); }
128 inline double Jet::getParameter(const collection_t* pColl,index_t ind) const
129 { return (this->navigableBase()).getParameter(pColl,ind); }
130 inline double Jet::getParameter(const_iterator fConst) const
131 { return (this->navigableBase()).getParameter(fConst); }
133 inline const Jet::collection_t*
134 Jet::getContainer(const constituent_t* pConst) const
135 { return (this->navigableBase()).getContainer(pConst); }
136 inline const Jet::collection_t*
137 Jet::getContainer(const_iterator fConst) const
138 { return (this->navigableBase()).getContainer(fConst); }
140 inline bool Jet::getIndex(const constituent_t* pConst,index_t& ind) const
141 { return (this->navigableBase()).getIndex(pConst,ind); }
142 inline bool Jet::getIndex(const_iterator fConst,index_t& ind) const
143 { return (this->navigableBase()).getIndex(fConst,ind); }
145 /////////// ///////////
146 // Public: Constituent Management //
147 /////////// ///////////
149 inline bool Jet::removeConstituent(const collection_t* pColl,index_t ind)
153 ? this->removeConstituent((pColl->operator[])(ind))
157 inline bool Jet::removeConstituent(bool reset)
159 // reset four-momentum if needed
160 if ( reset ) this->set4Mom(hlv_t(0.,0.,0.,0.));
161 return this->remove();
164 /////////// ///////////
165 // Protected: Constituent Management //
166 /////////// ///////////
168 inline void Jet::putElement(const collection_t* pColl,
169 const constituent_t* pConst,
172 { (this->navigableBase()).putElement(pColl,pConst,wght,sizeHint); m_constituentsN++;}
173 inline void Jet::putElement(const collection_t* pColl,
177 { (this->navigableBase()).putElement(pColl,ind,wght,sizeHint); m_constituentsN++;}
179 inline void Jet::insertElement(const collection_t* pColl,
180 const constituent_t* pConst,
183 { (this->navigableBase()).insertElement(pColl,pConst,wght,sizeHint); m_constituentsN++;}
184 inline void Jet::insertElement(const collection_t* pColl,
188 { (this->navigableBase()).insertElement(pColl,ind,wght,sizeHint); m_constituentsN++;}
190 // inline void Jet::reweight(const constituent_t* pConst,double wght)
191 // { (this->navigableBase()).reweight(pConst,wght); }
192 // inline void Jet::reweight(const collection_t* pColl,index_t ind,double wght)
193 // { (this->navigableBase()).reweight(pColl,ind,wght); }
195 inline bool Jet::remove(const constituent_t* pConst)
196 { if ( (this->navigableBase()).remove(pConst) ) {m_constituentsN--;return true;} return false; }
197 inline bool Jet::remove(const collection_t* pColl,index_t ind)
198 { if ( (this->navigableBase()).remove(pColl,ind) ){ m_constituentsN--;return true;} return false; }
199 inline bool Jet::remove()
200 { if ( (this->navigableBase()).removeAll() ){ m_constituentsN=0;return true;} return false;}
202 /////////// ///////////
203 // Public: Navigation //
204 /////////// ///////////
206 inline void Jet::fillToken(INavigationToken& navToken) const
207 { (this->navigableBase()).fillToken(navToken); }
208 inline void Jet::fillToken(INavigationToken& navToken,
209 const std::any& par) const
210 { (this->navigableBase()).fillToken(navToken,par); }
212 /////////// ///////////
213 // Public: Access to Jet Shapes //
214 /////////// ///////////
216 inline void Jet::setMoment(const mkey_t& shapeName,shape_t shape,
217 bool createIfMissing) const
218 { this->setShape(shapeName,shape,createIfMissing); }
220 inline Jet::shape_t Jet::getMoment(const mkey_t& shapeName,
221 bool createIfMissing) const
222 { return this->getShape(shapeName,createIfMissing); }
224 inline std::vector<Jet::mkey_t> Jet::getMomentKeys() const
225 { return this->getShapeKeys(); }
228 inline bool Jet::checkKey(const mcat_t& cat,
231 bool createIfMissing) const
233 // get index for data word
234 aInd = keyDesc()->getIndex(cat,key,createIfMissing);
235 return keyDesc()->isValid(aInd);
238 /////////// ///////////
239 // Public: Access to Tag Info //
240 /////////// ///////////
242 inline const Jet::tagstore_t Jet::jetTagInfoVector(void) const
248 // the vector might has empty elements, because not necessarily all
249 // taginfos are filled for every event. Need to return a copy
250 // of the TagInfoStore with all zeros removed
251 if ( bool(m_tagInfoStore) )
252 for (const taginfo_t* tag : std::as_const(*m_tagInfoStore)) {
253 if ( tag != nullptr )
254 store.push_back( tag );
260 inline const Jet::taginfo_t* Jet::tagInfo(const mkey_t& key) const
262 size_t aInd(keyDesc()->getIndex(JetKeyConstants::TagCat,key,false));
263 return bool(m_tagInfoStore) && aInd < m_tagInfoStore->size()
264 ? (m_tagInfoStore->operator[])(aInd) : (const taginfo_t*)0;
268 template<typename TAGINFO>
269 const TAGINFO* Jet::getTagInfo(const mkey_t& key,bool /*useLink*/) const
271 return this->getObject<TAGINFO,tagstore_t>(key,m_tagInfoStore,JetKeyConstants::TagCat, false);
274 template<class TAGINFO>
275 const TAGINFO* Jet::tagInfo(const mkey_t& key) const
277 return this->getTagInfo<TAGINFO>(key);
280 template<class TAGINFO>
281 void Jet::addInfo(const TAGINFO* tag)
283 this->setTagInfo( tag->infoType(), tag );
289 /////////// ///////////
290 // Public: Associations //
291 /////////// ///////////
293 template<typename ASSOC> const ASSOC*
294 Jet::getAssociation(const mkey_t& key, bool /*useLink*/ ) const
296 return this->getObject<ASSOC,assostore_t>(key,m_assocStore,JetKeyConstants::AssoCat, false);
300 void Jet::setAssociation(const T* pAssoc,bool /*useLink*/)
302 // use check function
303 size_t aInd(size_t(-1));
304 std::string key = pAssoc->name();
306 if ( ! bool(m_assocStore) )
307 // checkKey automatically build new store !!!
308 m_assocStore = new assostore_t();
310 if ( this->checkKeyStore(JetKeyConstants::AssoCat,key,m_assocStore,aInd, true) ) {
311 removeAssociation(aInd);
312 (m_assocStore->operator[])(aInd) = pAssoc;
316 inline void Jet::removeAssociation( const mkey_t& key )
318 if ( bool(m_assocStore) ) {
320 if ( this->checkKeyStore(JetKeyConstants::AssoCat,key,m_assocStore,aInd, false) ) {
321 removeAssociation(aInd);
326 inline void Jet::removeAssociation (const size_t index)
328 delete (m_assocStore->operator[])(index);
329 (m_assocStore->operator[])(index) = 0;
332 /////////////////////////////////////////
333 /// constituent and jet signal states ///
334 /////////////////////////////////////////
335 inline void Jet::setConstituentSignalState( Jet::signalstate_t s )
337 m_constituentSigState = s;
340 /////////////////////////////////////////
341 /// Compatibility with JetAnalysisEDM
342 /////////////////////////////////////////
344 // Write helper class to allow specialization for std::vector<T>
345 template <typename T>
346 struct JetAnalysisEDMHelper {
347 static T get(const Jet* j, const std::string & mName){
348 return j->getMoment(mName);
350 static void set(const Jet* j, const std::string & mName, const T & v){
351 j->setMoment(mName,v);
355 template <typename T>
356 struct JetAnalysisEDMHelper<std::vector<T> > {
357 static std::vector<T> get(const Jet* j, const std::string & mName){
358 std::vector<std::string> allMoms = j->getMomentKeys() ;
359 std::vector<std::string> matchingMoms;
363 std::string prefix = mName+"_";
364 size_t msize = prefix.size();
367 // match all moments starting by "mName_"
368 for( size_t i=0; i< allMoms.size(); i++){
369 std::string & mom = allMoms[i];
370 if(mom.compare(0,msize, prefix)==0) matchingMoms.push_back(mom);
372 // We need "mName_0", "mName_1", etc... but matchingMoms also contains moments
373 // in the form "mName_something_0", ... etc. So sort them
374 std::sort(matchingMoms.begin(), matchingMoms.end() );
375 val.reserve( matchingMoms.size());
377 for( size_t i=0; i< matchingMoms.size(); i++){
378 std::stringstream s;s<< prefix<< i;
379 if( s.str() == matchingMoms[i]) val.push_back( j->getMoment(matchingMoms[i] ));
386 static void set(const Jet* j, const std::string & mName, const std::vector<T> & v){
387 for(size_t i=0;i<v.size();i++){
389 s << mName << "_"<< i;
390 j->setMoment(s.str(),v[i]);
396 T Jet::get(const std::string & mName) const { return JetAnalysisEDMHelper<T>::get(this,mName); }
399 void Jet::set(const std::string & mName, const T& v) const { return JetAnalysisEDMHelper<T>::set(this,mName,v); }