ATLAS Offline Software
Loading...
Searching...
No Matches
Jet.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6// Filename : Jet.cxx
7// Author : Ambreesh Gupta, Ed Frank
8// Created : Sep, 2000
9//
10// HISTORY;
11//
12// 21Sep01 Peter Loch Implement Tucson agreement for Jet class.
13// 23Apr02 Peter Loch Move to JetEvent package
14// 10Oct02 Peter Loch New package structure implemented
15// 31Jan03 Peter Loch New navigation code implemented
16// 27Jul03 Ambreesh Modified addJet method to add a constituent
17// if it does not belong to the jet.
18// 11Feb08 PL & RS new JetEDM: new inheritance structure and
19// information stores for b-tagging attached
20// Nov09 PO & PA Externalize Signal States to ParticleSigStateImpl
21// Remove pre/post processors
22//
24
25// externals
26#include "CLHEP/Units/SystemOfUnits.h"
27#include "CLHEP/Vector/LorentzVector.h"
28#include "GaudiKernel/MsgStream.h"
29
30// Navigation
33
34// FourMom
35#include "FourMom/P4PxPyPzE.h"
36#include "FourMom/P4PtEtaPhiM.h"
37#include "FourMom/P4EEtaPhiM.h"
39
40// JetEvent
41#include "JetEvent/Jet.h"
45
46// STL
47#include <algorithm>
48#include <vector>
49
50#include <cmath>
51#include <sstream>
52
53
54const size_t Jet::s_defaultJetId = 0 ;
55const size_t Jet::s_defaultJetAuthor = 0 ;
56
57// DO NOT change these lines EVER!!!!!
58// std::string Jet::m_shpCat = "JetShapes";
59// std::string Jet::m_assCat = "JetAssociations";
60// std::string Jet::m_tagCat = "JetTags";
61// std::string Jet::m_infCat = "JetInfo";
62
63
64
65// size_t Jet::m_invalidKeyIndex = size_t(-1);
66// size_t Jet::m_momMapInvalidIndex = size_t(-1);
67
68
69
70const double Jet::m_ignoreWeight = 1.0e-06;
71
72// Little helper function
73bool jet_component_identity(double p1, double p2, double epsilon = 0.1){
74 return fabs(p1-p2)< epsilon ;
75}
76
77
79// Constructors //
81
82#define JET_CONSTRUCTOR_BASE m_constituentsN(0) \
83 , m_RoIword(0xFFFFFFFF) \
84 , m_jetId(Jet::s_defaultJetId) \
85 , m_collection(NULL) \
86 , m_jetAuthor(Jet::s_defaultJetAuthor) \
87 , m_assocStore(0) \
88 , m_tagInfoStore(0) \
89 , m_constituentSigState(P4SignalState::UNKNOWN) \
90 , m_num_combinedLikelihood(0) \
91 , m_pseudoJet(0)
92
93
99 : base_t(3, signalstate_t(1)),
101
102{
103 this->setup(hlv_t(0.,0.,0.,0.));
104}
105
106
118Jet::Jet(const collection_t* pColl,
119 const constituent_t* pConst,
120 double wght)
121 : base_t(3, signalstate_t(1)),
123{
124
125 this->setup(hlv_t(0.,0.,0.,0.));
126 this->addConstituent(pColl,pConst,wght);
127}
128
140Jet::Jet(const collection_t* pColl,index_t ind,double wght)
141 : base_t(3, signalstate_t(1)),
143 this->setup(hlv_t(0.,0.,0.,0.));
144 this->addConstituent(pColl,ind,wght);
145}
146
147
154Jet::Jet(const fourmom_t* pMom)
155 : base_t(3, signalstate_t(1)),
157 this->setup(hlv_t(pMom->px(),pMom->py(),pMom->pz(),pMom->e()));
158}
159
166Jet::Jet(const fourmom_t& rMom)
167 : base_t(3, signalstate_t(1)),
169 this->setup(hlv_t(rMom.px(),rMom.py(),rMom.pz(),rMom.e()));
170}
177Jet::Jet(const hlv_t& rVec)
178 : base_t(3, signalstate_t(1)),
180{
181 this->setup(rVec);
182}
192Jet::Jet(double px, double py, double pz, double e)
193 : base_t(3, signalstate_t(1)),
195{
196 this->setup(hlv_t(px,py,pz,e));
197}
202Jet::Jet(const Jet* pJet)
203 : base_t((const base_t) *pJet) ,
205{
206
207 copy_from_jet( pJet, CopyAll);
208
209}
210
211// constructor with arguements
212Jet::Jet(const Jet* pJet, bool copyStores, bool copyConstituents)
213 : base_t( (const base_t) *pJet),
215{
216
217 CopyDataMembers cmd0 = CopyDataMembers ( copyStores ?
219
220 CopyDataMembers cmd1 = CopyDataMembers ( copyConstituents ? CopyConstituents : CopyNone ) ;
221
222 //std::cout <<"Jet copyStores:"<< copyStores << " "<< cmd0 << "| copyConstituents:"<<copyConstituents<< " "<< cmd1<< " size ="<< this->size() <<std::endl;
223
224 copy_from_jet( pJet, cmd0 , cmd1);
225}
226
227// constructor with arguements
228Jet::Jet(const Jet* pJet,
229 CopyDataMembers cmd0, CopyDataMembers cmd1,
230 CopyDataMembers cmd2, CopyDataMembers cmd3)
231 : base_t( (const base_t) *pJet ),
233{
234 copy_from_jet( pJet, cmd0 , cmd1, cmd2, cmd3 );
235}
236
241
242Jet::Jet(const Jet& rJet)
243 : IAthenaBarCode(),
244 INavigable(),
245 I4Momentum(),
247 base_t(rJet),
249{
250 copy_from_jet(&rJet, CopyAll);
251}
252
253void Jet::setup(const hlv_t& v)
254{
255
256 this->setupKine(v);
257
258}
259
262{
263 CopyDataMembers cdm = CopyDataMembers(cdm0 | cdm1 | cdm2 | cdm3);
264
265
266 //std::cout<<"Jet::copy_from_jet this="<< this->constit4MomGetter.empty() << " pjet="<< pJet->constit4MomGetter.empty() << std::endl;
267
268 // copy all kinematics
270 this->set4Mom(pJet->hlv());
271
278
279
280 this->m_RoIword = pJet->m_RoIword;
281 m_jetAuthor = pJet->m_jetAuthor;
283
284 m_pseudoJet = pJet->m_pseudoJet;
285
286 // copy members if requested
287 if ( cdm & CopyConstituents )
288 {
289 //std::cout<< "copy constituent "<< std::endl;
290 const_iterator firstConst = pJet->firstConstituent();
291 const_iterator lastConst = pJet->lastConstituent();
292 for ( ; firstConst != lastConst; ++firstConst )
293 {
294 Jet::index_type theIndex;
295 if ( pJet->getIndex(firstConst,theIndex) ) // getIndex by iterator more efficient ?
296 {
297 this->putElement(pJet->getContainer(firstConst),
298 theIndex,
299 pJet->getWeight(firstConst));
300 }
301 }
302 } else {
303 this->navigableBase().removeAll();
304 }
305
306 // this line MUST stay after copyconstituents otherwise m_constituentsN will be double.
308
309 if ( cdm & CopyMoments )
310 {
311 const shape_map_t* oMap = pJet->getMomentMap();
312 //std::cout << " Copying moment other map "<< oMap<< " author="<< pJet->jetAuthor() <<" id="<< pJet->id()<< std::endl;
313 if ( oMap != nullptr ){
314
315 const JetMomentMap::record_t *oldrec = oMap->getRecord( pJet->id() );
316 // copy the moments :
317 //std::cout << " oldrec = "<< oldrec << std::endl;
318 if( oldrec){
319 const shape_map_t* mMap = this->getMomentMap(true);
320 // this should guaranty we have a map.
321
322 JetMomentMap::record_t *newrec =
323 new JetMomentMap::record_t( *oldrec );
324
325 // assign them in the map
326 mMap->assignRecord(m_jetId, newrec);
327 }
328 }
329 }
330
331
332 if ( cdm & CopyAssociations )
333 if ( bool(pJet->m_assocStore) )
334 {
336
337 const assostore_t& old = *pJet->m_assocStore;
338 m_assocStore->reserve (old.size());
339 for (size_t i = 0; i < old.size(); i++)
340 if (bool(old[i])) m_assocStore->push_back (old[i]->clone());
341 else m_assocStore->push_back ( nullptr );
342 }
343 if ( cdm & CopyTagInfos )
344 if ( bool(pJet->m_tagInfoStore) )
345 {
347
348 const tagstore_t& old = *pJet->m_tagInfoStore;
349 m_tagInfoStore->reserve (old.size());
350 for (size_t i = 0; i < old.size(); i++)
351 if (bool(old[i])) m_tagInfoStore->push_back (old[i]->clone());
352 else m_tagInfoStore->push_back(nullptr);
353 }
354
355}
356
357
367
369{
370 // FIXME jet owns stores for right now
371
372 if( m_jetId != s_defaultJetId){
373 // we may have an entry in a moment map
374 // and need to remove ourselves from the map
375 const shape_map_t *map = getMomentMap();
376 if(map) map->removeRecord( m_jetId );
377 }
378
379 if ( m_assocStore != nullptr ) {
380 for (size_t i = 0; i < m_assocStore->size(); i++)
381 delete (*m_assocStore)[i];
382 delete m_assocStore;
383 }
384 if ( m_tagInfoStore != nullptr ) {
385 for (size_t i = 0; i < m_tagInfoStore->size(); i++)
386 delete (*m_tagInfoStore)[i];
387 delete m_tagInfoStore;
388 }
389
390}
391
392
394// Jet Constituent Algebra //
396
414 const constituent_t* pConst,
415 double wght)
416{
417 double w = this->contains(pConst) ? wght + this->getWeight(pConst) : wght;
418 this->putElement(pColl,pConst,w);
419 this->updateKine(pConst,wght);
420 return true;
421}
422
439bool Jet::addConstituent(const collection_t* pColl,index_t ind,double wght)
440{
441
442 const constituent_t * constit = (pColl->operator[])(ind) ;
443 double w = this->contains(pColl,ind) ? wght + this->getWeight(pColl,ind) : wght;
444 this->putElement(pColl,ind,w);
445 this->updateKine(constit,wght);
446 return true;
447}
448
468 index_t ind,
469 size_t sizeHint,
470 bool noKine,
471 double wght)
472{
473 // Avoid multiple linear searches if we can.
474 // Unfortunately, we can't avoid it for the case in which
475 // the constituent is already in the jet (without changing
476 // the Navigable interface, anyway); but that should be the
477 // uncommon case anyway.
478 //std::cout << " adding constit. e="<< this->e() << " c_e="<< (pColl->operator[])(ind)->e() << " size "<< this->size()<< std::endl;
479 if (this->contains(pColl, ind))
480 this->reweight(pColl,ind, wght + this->getWeight(pColl, ind));
481 else
482 this->insertElement(pColl, ind, wght, sizeHint);
483
484 if (!noKine)
485 this->updateKine(((pColl->operator[])(ind))->hlv(),wght);
486 return true;
487}
488
489// remove constituents
491{
492 if ( this->contains(pConst) )
493 {
494 double w(this->getWeight(pConst));
495 //this->updateKine(pConst->hlv(),-w);
496 this->updateKine(pConst,-w);
497 this->remove(pConst);
498 return true;
499 }
500 return false;
501}
502
503// add Jet to Jet with a global weight
504bool Jet::addJet(const Jet* pJet, double wght)
505{
506 const_iterator fC(pJet->begin());
507 const_iterator lC(pJet->end());
508 for ( ; fC != lC ; ++fC )
509 {
510 index_t ind(index_t(-1));
511 if ( pJet->getIndex(fC,ind) )
512 {
513 if ( !(this->contains(*fC)) )
514 {
515 this->addConstituent(pJet->getContainer(fC),
516 ind,
517 wght*(pJet->getWeight(fC)));
518 }
519 }
520 }
521 return pJet->size() > 0;
522}
523
525// Jet Kinematics Manipulations //
527
528// remove all children with kinematic weight 0
530{
531 unsigned int aCtr = 0;
532 // check content
533 if ( this->size() > 0 )
534 {
535 const_iterator fC(this->begin());
536 const_iterator lC(this->end());
537 for ( ; fC != lC; ++fC )
538 {
539 double weight(this->getWeight(fC));
540 if ( std::abs(weight)< m_ignoreWeight )
541 {
542 ++aCtr;
543 this->removeConstituent(*fC);
544 }
545 }
546 }
547 return aCtr > 0;
548}
549
550// re-weight child in Jet
551bool Jet::reweight(const constituent_t* pConst,double wght)
552{
553 if ( this->contains(pConst) )
554 {
555 const collection_t* pColl = this->getContainer(pConst);
556 this->removeConstituent(pConst);
557 return this->addConstituent(pColl,pConst,wght);
558 }
559 return false;
560}
561
562bool Jet::reweight(const collection_t* pColl,index_t ind,double wght)
563{
564 // std::cout << "reweighting "<< wght << std::endl;
565 return this->removeConstituent(pColl,ind)
566 ? this->addConstituent(pColl,ind,wght)
567 : false;
568}
569
571// Jet Kinematics // ///// kinematic variables from P4PxPyPzE /////
573
574void Jet::scale_momentum(double scale_factor){
575 this->set4Mom(this->hlv()*scale_factor);
576}
577
578Jet * Jet::get_scaled_copy(double scale_factor) const{
579 Jet* newjet = new Jet(this,true,true);
580 newjet->scale_momentum(scale_factor);
581 return newjet;
582}
583
585// Jet Composition //
587
588// test Jets on identity by composition
589bool Jet::isIdentical(const Jet* pJet ) const
590{
591 // need to have same size (number of constituents)
592 if ( pJet->size() != this->size() ) return false;
593
594 if( pJet->size() == 0 ){
595 // fall back on mometum comparison
596 bool isEqual = ( fabs( pJet->e() - e() )< m_ignoreWeight ) ;
597 isEqual = isEqual && ( fabs( pJet->px() - px() )< m_ignoreWeight) ;
598 isEqual = isEqual && ( fabs( pJet->py() - py() )< m_ignoreWeight) ;
599 isEqual = isEqual && ( fabs( pJet->pz() - pz() )< m_ignoreWeight) ;
600 return isEqual;
601 }
602
603 bool isEqual = true;
604 const_iterator fC(pJet->begin());
605 const_iterator lC(pJet->end());
606
607 while ( isEqual && fC != lC )
608 {
609 double wJ(pJet->getWeight(fC));
610 const_iterator fK(this->begin());
611 const_iterator lK(this->end());
612 while ( ( fK != lK ) && ((*fC) != (*fK) ||
613 fabs(this->getWeight(fK)-wJ) >= m_ignoreWeight) )
614
615 { ++fK; }
616 isEqual = fK != lK;
617 ++fC;
618 }
619
620 return isEqual;
621}
622
623// Print-out a single line to describe the Jet
624std::string Jet::str() {
625 std::ostringstream out;
626 out << jetAuthor() << ": NConstituents: " << size() << "; Eta: " << eta() << "; Phi: " << phi() << "; Pt: " << pt();
627 return out.str();
628}
629
630// Difference between two jets - Non-class method required for trigger
631void diff(const Jet& rJet1, const Jet& rJet2, std::map<std::string,double> varDiff)
632{
633 // Since this isn't part of the Jet Class, we need to re-define it here
634 // not very elegant
635 double ignoreWeight = 1.0e-06;
636 // Compare sizes
637 if(rJet1.size() != rJet2.size())
638 varDiff["NConstituents"] = rJet1.size() - rJet2.size();
639
640 // Compare 4 momenta
641 if(fabs(rJet1.e() - rJet2.e()) > ignoreWeight)
642 varDiff["e"] = rJet1.e() - rJet2.e();
643 if(fabs(rJet1.px() - rJet2.px()) > ignoreWeight)
644 varDiff["px"] = rJet1.px() - rJet2.px();
645 if(fabs(rJet1.py() - rJet2.py()) > ignoreWeight)
646 varDiff["py"] = rJet1.py() - rJet2.py();
647 if(fabs(rJet1.pz() - rJet2.pz()) > ignoreWeight)
648 varDiff["pz"] = rJet1.pz() - rJet2.pz();
649}
650
651
652
653// find overlap region
654Jet* Jet::getOverlap(const Jet* pJet, bool /*noKine = false*/) const
655{
656 if ( pJet->size() == 0 || this->size() == 0 ) return (Jet*)nullptr;
657
658 // Dereferencing ELs is a little expensive.
659 // Get the constituents into a vector so that we only
660 // need to do it once.
661 std::vector<const constituent_type*> constituents (this->begin(),
662 this->end());
663 //unused - fix warning
664 //size_t sz = std::min (this->size(), pJet->size());
665
666 // Defer allocating the new jet until we know we have something
667 // to put into it.
668 Jet* newJet = nullptr;
669 // de-compose Jet
670 const_iterator fC(pJet->begin());
671 const_iterator lC(pJet->end());
672 for ( ; fC != lC; ++fC )
673 {
674 const constituent_type* c = *fC;
675 if ( std::find (constituents.begin(), constituents.end(), c) !=
676 constituents.end() )
677 {
678 if (!newJet){
679 newJet = new Jet(this, true, false); // we copy the stores, not the constituent
680 newJet->set4Mom(hlv_t(0. ,0. , 0., 0.)) ; //and reset its fourmom to nill
681 }
683#ifndef NDEBUG
684 bool result =
685#endif
686 this->getIndex (fC, index);
687 assert (result);
688 newJet->addConstituent(this->getContainer(fC),
689 index);
690// sz,
691// noKine);
692 //std::cout<< "getoverlap new e="<< newJet->e() << " / e1="<< e() << " e2="<< pJet->e()<<" | eta= "<< newJet->eta() << " f="<< newJet->pt()/pt() << std::endl;
693 }
694 }
695 return newJet;
696}
697
699// Kinematic Updates // ///// protected /////
701
703{
704 hlv_t fmom(0.,0.,0.,0.);
707
708 for (;fC!=lC;++fC)
709 {
710 if (! fC.get_real_constit()) continue; // constit may be invalid if broken EL
711 fmom += (fC.hlv() * this->getWeight(fC.get_real_constit()));
712 }
713 return fmom;
714}
715
717{
718 hlv_t fmom(0.,0.,0.,0.);
721
722 for (;fC!=lC;++fC)
723 {
724 if (! fC.get_real_constit()) continue; // constit may be invalid if broken EL
725 fmom += (fC.hlv() * this->getWeight(fC.get_real_constit()));
726 }
727 return fmom;
728}
729
736{
737 // reset four momentum
738 this->setPx(0.);
739 this->setPy(0.);
740 this->setPz(0.);
741 this->setE(0.);
742
743 // loop children
744
747 for (;fC!=lC;++fC)
748 {
749 if (! fC.get_real_constit()) continue; // constit may be invalid if broken EL
750 this->updateKine(fC.hlv(),this->getWeight(fC.get_real_constit()));
751 }
752}
753
757void Jet::updateKine(const hlv_t& rVec,double wght)
758{
759 this->set4Mom(this->hlv()+rVec*wght);
760}
761
762void Jet::updateKine(const Jet::constituent_t* pConst,double wght)
763{
764
765 // Attempt to cast into an ISignalState object
766 const ISignalState* pSigState = dynamic_cast<const ISignalState*>(pConst);
767
768 if(bool(pSigState) && m_constituentSigState != P4SignalState::UNKNOWN)
769 {
770 // Copy kinematics for the chosen Signal State
771 this->updateKine(pSigState->hlv(m_constituentSigState),wght);
772 } else
773 this->updateKine(pConst->hlv(),wght);
774}
775
777{
778 Jet* jet = new Jet(this, false, false);
779 return jet;
780}
781
782Jet* Jet::clone(bool copyStores, bool copyConstituents) const
783{
784 Jet* jet = new Jet(this, copyStores,copyConstituents);
785 return jet;
786}
787
792
794// Moments //
796
797void Jet::setShape(const mkey_t& shapeName,shape_t shapeValue,
798 bool createIfMissing) const
799{
800 // use check function to find index of moment - index is generated if
801 // not yet in key descriptor store
802 size_t keyIndex;
803 if ( this->checkKey(JetKeyConstants::ShapeCat,shapeName,keyIndex,true) )
804 {
805 // access jet moment map
806 const shape_map_t* map = this->getMomentMap(createIfMissing);
807 // store data
808 if ( map != nullptr )
809 {
810 map->setMoment(m_jetId,keyIndex,shapeValue);
811 // m_newMomKeys = true;
812 }
813 }
814}
815
816// get shape keys
817std::vector<Jet::mkey_t> Jet::getShapeKeys() const
818{
819 std::vector<Jet::mkey_t> keys;
820 const shape_map_t* pMap = this->getMomentMap();
821 if ( pMap != nullptr )
822 {
823 size_t n(pMap->numberOfMoments(m_jetId));
824 keys.reserve(n/2);
825 for ( size_t i(0); i < n; ++i )
826 {
827 float data(0.);
828 if ( pMap->getMoment(m_jetId,i,data) )
829 keys.push_back(keyDesc()->getKey(JetKeyConstants::ShapeCat,i));
830 }
831 }
832
833 return keys;
834}
835
836Jet::shape_t Jet::getShape(const mkey_t& shapeName,bool addIfMissing) const
837{
838
839 size_t keyIndex;
840 if ( this->checkKey(JetKeyConstants::ShapeCat,shapeName,keyIndex,false) )
841 {
842 const shape_map_t* pMap = this->getMomentMap(addIfMissing);
843 return pMap != nullptr ? pMap->getMoment(m_jetId,keyIndex) : shape_t();
844 }
845 return shape_t();
846}
847
849// TagInfo //
851
852
853void Jet::setTagInfo(const mkey_t& key,
854 const taginfo_t* pTagInfo,
855 bool /* useLink */ )
856{
857 // use check function
858 size_t aInd;
859 //
860 if ( ! bool(m_tagInfoStore) )
861 {
862 // checkKey automatically build new store !!!
864 }
865 if ( this->checkKeyStore(JetKeyConstants::TagCat,key,m_tagInfoStore,aInd, true) )
866 {
867 removeInfo(aInd);
868 (m_tagInfoStore->operator[])(aInd) = pTagInfo;
869 }
870}
871
872void Jet::removeInfo (unsigned int index)
873{
874 delete (m_tagInfoStore->operator[])(index);
875 (m_tagInfoStore->operator[])(index) = nullptr;
876}
877
878void Jet::removeInfo(const mkey_t& key )
879{
880 if ( bool(m_tagInfoStore) ) {
881 size_t aInd;
882 if ( this->checkKeyStore(JetKeyConstants::TagCat,key,m_tagInfoStore,aInd, false) ) {
883 removeInfo(aInd);
884 }
885 }
886}
887
888
889void Jet::setupKine(const hlv_t& vIn)
890{
893 this->set4Mom(vIn, statename_t::JETFINAL);
894}
895
897// Signal States //
899
900
909
918
927
928double Jet::getRawE() const { return e(P4SignalState::JETEMSCALE); }
929double Jet::getRawPx() const { return px(P4SignalState::JETEMSCALE); }
930double Jet::getRawPy() const { return py(P4SignalState::JETEMSCALE); }
931double Jet::getRawPz() const { return pz(P4SignalState::JETEMSCALE); }
932
937
938double Jet::getCalE() const { return e(P4SignalState::JETFINAL); }
939double Jet::getCalPx() const { return px(P4SignalState::JETFINAL); }
940double Jet::getCalPy() const { return py(P4SignalState::JETFINAL); }
941double Jet::getCalPz() const { return pz(P4SignalState::JETFINAL); }
942
943double Jet::ei() const { return this->e(); }
944
945double Jet::pxi() const { return this->px(); }
946
947double Jet::pyi() const { return this->py(); }
948
949double Jet::pzi() const { return this->pz(); }
950
951double Jet::pti() const { return this->pt(); }
952
954 bool ok = jet_component_identity( getRawE() , getCalE() );
958 return ok;
959}
960
962// Public: CombinedLikelihood //
964
965
966std::vector<double> Jet::combinedLikelihood() const
967{
968 std::vector<double> combinedLikelihood;
970 const std::string base="LikeLihood_";
971 for(unsigned int i=0; i<m_num_combinedLikelihood; i++){
972 combinedLikelihood[i] = getShape(base+std::to_string(i)) ;
973 }
974
975 return combinedLikelihood;
976}
977
978void Jet::setCombinedLikelihood(const std::vector<double>&
980{
981 const std::string base="LikeLihood_";
982 for(unsigned int i=0; i<combinedLikelihood.size(); i++){
983 setShape(base+std::to_string(i), combinedLikelihood[i] );
984 }
986}
987
988
990{
991 double w = 0.;
992 if ( this->jetAuthor().find("Atlfast") != std::string::npos) {
993 // Fastsim
994 w = -30.;
995 const JetTagInfoBase* pos(this->tagInfo("SV1IP3D"));
996 if (pos != nullptr) {
997 std::vector<double> prob = pos->tagLikelihood();
998 if(prob.size()>1) {
999 double pb = prob[0];
1000 double pu = prob[1];
1001 if (pb != 0 && pu != 0)
1002 w = log(pb/pu);
1003 else
1004 w = 0.; //Hopefully a warning appears in the BTagger Tool
1005 }
1006 } else {
1007 // Use "binary" random b-tag only if no IP3D nor SV1 Info
1008 if (m_num_combinedLikelihood > 0) {
1009 std::vector<double> Likelihood = combinedLikelihood();
1010 if (Likelihood[0] > 0.9) w = 100;
1011 }
1012 }
1013 } else {
1014 // FullSim
1015 bool found = false;
1016 // get W from IP3D:
1017 const JetTagInfoBase* pos(this->tagInfo("IP3D"));
1018 if( pos != nullptr ) {
1019 found = true;
1020 std::vector<double> prob = pos->tagLikelihood();
1021 if(prob.size()>1) {
1022 double pb = prob[0];
1023 double pu = prob[1];
1024 if (pb > 0. && pu > 0.) {
1025 if(pb!=1.||pu!=1.e9) {
1026 w = log(pb/pu);
1027 }
1028 } else
1029 w = 0.; //Hopefully a warning appears in the BTagger Tool
1030 }
1031 }
1032 // get W from SV:
1033 pos = this->tagInfo("SV1");
1034 if( pos != nullptr ) {
1035 found = true;
1036 std::vector<double> prob = pos->tagLikelihood();
1037 if(prob.size()>1) {
1038 double pb = prob[0];
1039 double pu = prob[1];
1040 if (pb > 0. && pu > 0.) //Hopefully a warning appears in the BTagger Tool if not the case
1041 w += log(pb/pu);
1042 }
1043 }
1044 if (!found) w = -30.;
1045 }
1046 return w;
1047}
1048
1049double Jet::getFlavourTagWeight(const std::string& infoName) const
1050{
1051 double w = -100.;
1052 const JetTagInfoBase* pos(this->tagInfo(infoName));
1053 if( pos != nullptr ) {
1054 std::vector<double> prob = pos->tagLikelihood();
1055 if(prob.size() == 1) {
1056 w = prob[0];
1057 } else {
1058 if(prob.size() > 1) {
1059 double pb = prob[0];
1060 double pu = prob[1];
1061 if(pb<=0.) { // A different protection than the above one... In any case, this is not OK and should be watched out !
1062 w = -30.;
1063 } else if (pu<=0.) {
1064 w = +100.;
1065 } else {
1066 w = log(pb/pu);
1067 }
1068 }
1069 }
1070 }
1071 return w;
1072}
1073
1074
1075
1076
1077const std::vector<Jet::mkey_t>& Jet::getAssociationKeys() const
1078{
1080}
1081
1082
1087
1088
1089
1091// Public: Jet Author //
1093
1094void Jet::setJetAuthor(const mkey_t& author)
1095{
1097
1098 std::string full_auth = keyDesc()->getKey(JetKeyConstants::InfoCat,m_jetAuthor);
1099 size_t pos = full_auth.find_first_of('_');
1100
1101 if( pos != std::string::npos) // we add the _XXX_YYY part to author
1102 m_jetAuthor = keyDesc()->getIndex(JetKeyConstants::InfoCat,author+full_auth.substr(pos),true);
1103 else
1105}
1106
1107
1109{
1110 std::string full_auth = keyDesc()->getKey(JetKeyConstants::InfoCat,m_jetAuthor);
1111 // return the first part in JetAuth_XXX_YYY
1112 size_t found=full_auth.find_first_of('_');
1113 return found != std::string::npos ? full_auth.substr(0 , found) : std::move(full_auth);
1114}
1115
1116
1117
1121
1122void Jet::setJetAuthorAndCalibTags(const std::string& author) {
1124}
1125
1126
1127
1128bool Jet::hasCalibTag(const std::string& tag) const{
1129 std::string full_auth = keyDesc()->getKey(JetKeyConstants::InfoCat,m_jetAuthor);
1130 std::string full_tag = ""; full_tag+="_"; full_tag+=tag;
1131 return ( full_auth.find(full_tag) != std::string::npos );
1132}
1133
1134int Jet::numCalibTag() const {
1135 std::string full_auth = keyDesc()->getKey(JetKeyConstants::InfoCat,m_jetAuthor);
1136 size_t p = full_auth.find_first_of('_');
1137 int c=0;
1138 while(p != std::string::npos){
1139 c++;
1140 p = full_auth.find_first_of('_',p+1);
1141 }
1142 return c;
1143}
1144
1145std::string Jet::getCalibTag(int i) const{
1146 std::string full_auth = keyDesc()->getKey(JetKeyConstants::InfoCat,m_jetAuthor);
1147 size_t p = full_auth.find_first_of('_');
1148 int c=0;
1149 while(p != std::string::npos){
1150 c++;
1151 if( c==i ){
1152 return full_auth.substr(p+1,full_auth.find_first_of('_',p+1)-p-1);
1153 }
1154 p = full_auth.find_first_of('_',p+1);
1155 }
1156 return "";
1157}
1158
1159void Jet::addCalibTag(const std::string& tag){
1160 std::string full_auth = keyDesc()->getKey(JetKeyConstants::InfoCat,m_jetAuthor);
1161 full_auth +="_"+tag;
1163}
1164const Jet::shape_map_t* Jet::getMomentMap(bool addIfMissing) const
1165{
1166 if( (m_jetId == s_defaultJetId) && addIfMissing ){
1167 // we need an id to be registered in a map
1169 }
1170 return getMomentMap();
1171}
1172
1174{
1175
1176 // jets must be identified
1177 if(m_jetId == s_defaultJetId ) return nullptr;
1178
1179 if( m_collection ){
1180 // This jet belongs to a JetCollection, ask the map
1181 return m_collection->getMomentMap();
1182 }
1183 // Else, this is an orphan jet, return the global instance :
1185
1186}
1187
1188std::string Jet::getMomentMapName() const {
1189 std::string mapname = jetAuthor();
1190 mapname +="MomentMap";
1191 return mapname;
1192}
1193
1194size_t Jet::id() const {return m_jetId;}
1195
1197 return m_collection;
1198}
1199
1200void Jet::setJetId(size_t id){ m_jetId = id ; }
1201
1202void Jet::setPxPyPzE(double px, double py, double pz, double e){
1203 setPx(px);setPy(py);setPz(pz);setE(e);
1204}
1205void Jet::setPtEtaPhiE( double pt, double eta, double phi, double e ){
1206 double pz = pt*std::sinh( eta) ;
1207 double px = pt*std::cos(phi);
1208 double py = pt*std::sin(phi);
1209 setPx(px);setPy(py);setPz(pz);setE(e);
1210}
1211void Jet::setPtEtaPhiM( double a, double b, double c, double d ){
1212 set4Mom( P4PtEtaPhiM(a,b,c,d) );
1213}
1214void Jet::setEEtaPhiM( double a, double b, double c, double d ){
1215 set4Mom( P4EEtaPhiM(a,b,c,d) );
1216}
1217
1218MsgStream& Jet::operator<<( MsgStream& out) {
1219 return ( out << str() );
1220}
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
bool jet_component_identity(double p1, double p2, double epsilon=0.1)
Definition Jet.cxx:73
void diff(const Jet &rJet1, const Jet &rJet2, std::map< std::string, double > varDiff)
Difference between jets - Non-Class function required by trigger.
Definition Jet.cxx:631
#define JET_CONSTRUCTOR_BASE
Definition Jet.cxx:82
static Double_t a
I4Momentum is an abstract base class providing 4-momentum behavior.
Definition I4Momentum.h:31
virtual CLHEP::HepLorentzVector hlv() const =0
CLHEP HepLorentzVector.
virtual double pz() const =0
z component of momentum
virtual double px() const =0
x component of momentum
virtual double e() const =0
energy
virtual double py() const =0
y component of momentum
ISignalState is an abstract base class providing support for various Signal States to be associated w...
virtual CLHEP::HepLorentzVector hlv(P4SignalState::State s) const =0
obtain the CLHEP HepLorentzVector
A safe iterator on jet constituents.
static JetConstituentIterator last(const Jet *jet)
get the end iterator
static JetConstituentIterator first(const Jet *jet)
get a default iterator
const Jet::constituent_t * get_real_constit()
access to the real constituent pointer
Theses classes implement a mapping between string and index used by jets.
const std::vector< key_t > & getKeys(const category_t &cat) const
static JetKeyDescriptorInstance * instance()
size_t getIndex(const category_t &cat, const key_t &key, bool createIfMissing=true)
const key_t & getKey(const category_t &cat, size_t index) const
virtual size_t numberOfMoments(size_t jetIndex) const
virtual void assignRecord(size_t jetIndex, record_t *rec) const
assign a given record to a given jet
virtual const record_t * getRecord(size_t jetIndex) const
get the full record for a given jet
virtual bool getMoment(size_t jetIndex, size_t keyIndex, float_t &moment) const
base_t::record_t record_t
const collection_t * getContainer(const constituent_t *pConst) const
Retrieve pointer to constituent object container.
std::vector< double > combinedLikelihood() const
(depreciated) Likelihood store access
Definition Jet.cxx:966
double getRawPz() const
Definition Jet.cxx:931
bool removeConstituent(const constituent_t *pConst)
Remove a constituent.
Definition Jet.cxx:490
bool isIdentical(const Jet &rJet) const
Test if Jet is identical to given Jet.
virtual void setE(double e)
Kinematics are now handled by the base class, except for the following.
size_t size() const
Size of constituent store.
signalstate_t constituentSignalState() const
Get the current Signal state of the jet constituents.
size_t id() const
Index category for jet shapes.
Definition Jet.cxx:1194
double getCScalePy() const
Definition Jet.cxx:935
void setJetAuthorAndCalibTags(const std::string &author)
Set the full author-and-tag string.
Definition Jet.cxx:1122
double getCalPy() const
Definition Jet.cxx:940
const fastjet::PseudoJet * m_pseudoJet
Pointer to the fastjet object this jet is build from.
void removeInfo(const mkey_t &key)
(depreciated) Remove tag info object
Definition Jet.cxx:878
const shape_map_t * getMomentMap(bool addIfMissing) const
Definition Jet.cxx:1164
void setJetAuthor(const std::string &author)
Set author of this Jet (only the author, tags unchanged)
Definition Jet.cxx:1094
virtual double pzi() const
Definition Jet.cxx:949
virtual void setPx(double Px)
virtual double pyi() const
Definition Jet.cxx:947
bool addJet(const Jet *pJet, double wght=1.0)
Add a jet.
Definition Jet.cxx:504
bool remove()
bool checkKeyStore(const mcat_t &cat, const mkey_t &key, const STORE *store, size_t &aInd) const
Check key validity.
const std::vector< mkey_t > & getAssociationKeys() const
Definition Jet.cxx:1077
bool reweight(const constituent_t *pConst, double wght)
Change kinematic weight of constituent.
Definition Jet.cxx:551
size_t m_jetId
the identifier of this jet within its collection.
CLHEP::HepLorentzVector hlv_t
virtual void setPz(double pz)
void insertElement(const collection_t *pColl, const constituent_t *pConst, double wght=1.0, size_t sizeHint=0)
insert element without checking
const taginfo_t * tagInfo(const mkey_t &key) const
Retrieve tag info object.
bool getIndex(const constituent_t *pConst, index_t &ind) const
Retrieve index of object in container.
bool finalScaleEqualsEMScale() const
True if JETFINAL state equals JETEMSCALE state within 0.1 MeV on each E,px,pypz components.
Definition Jet.cxx:953
double getCScalePz() const
Definition Jet.cxx:936
void setCalE(double e)
Sets calibrated .
Definition Jet.cxx:919
double getRawPy() const
Definition Jet.cxx:930
double getWeight(const constituent_t *pConst) const
Retrieve kinematic weight of constituent.
std::string getMomentMapName() const
Definition Jet.cxx:1188
virtual void updateKine()
Resummation of kinematics from constituents.
Definition Jet.cxx:735
void scale_momentum(double scale_factor)
scale the jet 4mom by scale_factor
Definition Jet.cxx:574
static const double m_ignoreWeight
Maximum difference up to which weights are considered equal.
const_iterator lastConstituent() const
(obsolere) end iterator for constituent store
bool checkKey(const mcat_t &cat, const mkey_t &key, size_t &aInd, bool createIfMissing) const
P4SignalState::State signalstate_t
virtual Jet * clone() const
clone method : do not clone stores and constituent
Definition Jet.cxx:776
void addCalibTag(const std::string &tag)
set calib tag tag must be of the form "AAA"
Definition Jet.cxx:1159
double getRawPx() const
Definition Jet.cxx:929
std::vector< const assoc_t * > assostore_t
std::string getCalibTag(int i) const
retrieve calib tag number i (start at 1).
Definition Jet.cxx:1145
double getCalE() const
Definition Jet.cxx:938
std::string jetAuthorAndCalibTags() const
Retrieve the full author-and-tag string of this Jet.
Definition Jet.cxx:1118
tagstore_t * m_tagInfoStore
Tag info store.
std::string jetAuthor() const
Author and calibration history are encoded in a simple way inside the jet object.
Definition Jet.cxx:1108
std::vector< const taginfo_t * > tagstore_t
void setCombinedLikelihood(const std::vector< double > &combinedLikelihood)
(depreciated) Likelihood store setter
Definition Jet.cxx:978
double getCScalePx() const
Definition Jet.cxx:934
Jet * getOverlap(const Jet &rJet, bool noKine=false) const
Retrieve constituent overlap between jets.
size_t m_jetAuthor
Jet author store.
bool addConstituent(const collection_t *pColl, const constituent_t *pConst, double wght=1.0)
Add a constituent with optional kinematic weight.
Definition Jet.cxx:413
const JetCollection * parentCollection() const
a pointer to the collection this jet belongs to (can be NULL)
Definition Jet.cxx:1196
const OBJ * getObject(const mkey_t &key, const STORE *store, const mcat_t &cat) const
Get object from store with category and key.
static const size_t s_defaultJetId
navigable_t::external_index_type index_type
Constituent index type (obsolete)
Jet * get_scaled_copy(double scale_factor) const
return a NEW copy of this jet with 4mom scaled
Definition Jet.cxx:578
void setTagInfo(const mkey_t &key, const taginfo_t *pTagInfo, bool useLink=false)
Set tag info object.
Definition Jet.cxx:853
Jet()
Default constructor.
Definition Jet.cxx:98
double getCalPx() const
Definition Jet.cxx:939
virtual double pti() const
Definition Jet.cxx:951
virtual ~Jet()
Destructor.
Definition Jet.cxx:368
void setCalPy(double py)
Sets calibrated .
Definition Jet.cxx:923
static const size_t s_defaultJetAuthor
const assoc_t * getAssociationBase(const mkey_t &key) const
Definition Jet.cxx:1083
const shape_map_t * getMomentMap() const
Definition Jet.cxx:1173
navigable_t::object_iter const_iterator
JetKeyDescriptor::key_t mkey_t
void setPtEtaPhiE(double a, double b, double c, double d)
Definition Jet.cxx:1205
assostore_t * m_assocStore
key descriptor for all jet stores
void setup(const hlv_t &v)
void setShape(const mkey_t &shapeName, shape_t shape, bool addIfMissing=true) const
Set shape variable.
Definition Jet.cxx:797
virtual double pxi() const
Definition Jet.cxx:945
const_iterator begin() const
Begin iterator for constituent store.
MsgStream & operator<<(MsgStream &out)
Output operator.
Definition Jet.cxx:1218
double getCScaleE() const
Definition Jet.cxx:933
void copy_from_jet(const Jet *pjet, CopyDataMembers cdm0, CopyDataMembers cdm1=CopyNone, CopyDataMembers cdm2=CopyNone, CopyDataMembers cdm3=CopyNone)
Definition Jet.cxx:260
virtual void setupKine(const hlv_t &v)
Definition Jet.cxx:889
std::vector< mkey_t > getShapeKeys() const
Retrieve list of avalailable keys.
Definition Jet.cxx:817
void setCalPz(double pz)
Sets calibrated .
Definition Jet.cxx:925
double getFlavourTagWeight() const
get the final b-tag result from the default tagger
Definition Jet.cxx:989
hlv_t constituent_sum4Mom() const
Sum of weighted constituent four-momentums.
Definition Jet.cxx:702
INavigable4Momentum constituent_t
Constituent iterator type.
virtual double ei() const
Definition Jet.cxx:943
INavigable4MomentumCollection collection_t
Navigable object type.
void setCScaleE(double e)
Sets uncalibrated .
Definition Jet.cxx:910
void setCScalePy(double py)
Sets uncalibrated .
Definition Jet.cxx:914
const_iterator end() const
End iterator for constituent store.
CopyDataMembers
@ brief fine control over what's copied in the various stores and constituents
bool cleanUp()
Remove all constituents with kinematic weight = 0.
Definition Jet.cxx:529
void setRawPx(double px)
Sets uncalibrated .
Definition Jet.cxx:903
void setCScalePx(double px)
Sets uncalibrated .
Definition Jet.cxx:912
const_iterator firstConstituent() const
(obsolete) begin iterator for constituent store
double getRawE() const
Definition Jet.cxx:928
void setJetId(size_t id)
Definition Jet.cxx:1200
void setRawE(double e)
Sets uncalibrated .
Definition Jet.cxx:901
void setPtEtaPhiM(double a, double b, double c, double d)
Definition Jet.cxx:1211
void setRawPy(double py)
Sets uncalibrated .
Definition Jet.cxx:905
INavigable4Momentum constituent_type
Navigable object type (obsolete)
void setCalPx(double px)
Sets calibrated .
Definition Jet.cxx:921
ParticleSigStateImpl< Navigable< INavigable4MomentumCollection, double >, P4ImplPxPyPzE, ParticleEvent::Base > base_t
Internally used base type mixes particle/navigable/four-momentum interfaces with correct implementati...
void setPxPyPzE(double px, double py, double pz, double e)
compatibility with analysis EDM
Definition Jet.cxx:1202
std::string str()
Jet print-out function.
Definition Jet.cxx:624
navigable_t::external_index_type index_t
bool hasCalibTag(const std::string &tag) const
test if jet has calib tag tag
Definition Jet.cxx:1128
void setCScalePz(double pz)
Sets uncalibrated .
Definition Jet.cxx:916
int numCalibTag() const
number of calib tags for this jet
Definition Jet.cxx:1134
double getCalPz() const
Definition Jet.cxx:941
JetKeyDescriptorInstance * keyDesc() const
Definition Jet.cxx:788
void setRawPz(double pz)
Sets uncalibrated .
Definition Jet.cxx:907
const JetCollection * m_collection
Shape store link.
void putElement(const collection_t *pColl, const constituent_t *pConst, double wght=1.0, size_t sizeHint=0)
Add element with checking.
virtual void setPy(double py)
signalstate_t m_constituentSigState
Constituent Signal State.
void setConstituentSignalState(signalstate_t s)
Set the current Signal state of the jet constituents.
void setEEtaPhiM(double a, double b, double c, double d)
Definition Jet.cxx:1214
bool contains(const constituent_t *pConst) const
Check on containment.
shape_t getShape(const mkey_t &shapeName, bool addIfMissing=false) const
Retrieve shape variable.
Definition Jet.cxx:836
bool removeAll()
Definition Navigable.h:237
static OrphanJetMomentMap instance
P4PtEtaPhiM is a class with 4-momentum behavior, for which Pt, Eta, Phi and M are data members.
Definition P4PtEtaPhiM.h:25
virtual CLHEP::HepLorentzVector hlv() const
CLHEP HepLorentzVector.
virtual double pz() const
z component of momentum
virtual double e() const
energy
virtual double py() const
y component of momentum
virtual CLHEP::HepLorentzVector hlv() const
CLHEP HepLorentzVector.
virtual double px() const
We re-define here extra class routines that will allow direct access to signal state kinematics witho...
STL class.
bool setup(asg::AnaToolHandle< Interface > &tool, const std::string &type, const std::vector< std::string > &config, const std::string &progressFile="")
mostly useful for athena, which will otherwise re-use the previous tool
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:138
std::string base
Definition hcg.cxx:81
Definition index.py:1
static const key_t ShapeCat
Index category for jet shapes.
static const key_t TagCat
Index category for jet tag info.
static const key_t InfoCat
Index category for general jet info.
static const key_t AssoCat
Index category for jet associations.