ATLAS Offline Software
Loading...
Searching...
No Matches
xAODMissingETAuxAssociationMapCnv_v1.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5// $Id: xAODMissingETAuxAssociationMapCnv_v1.cxx 693797 2015-09-08 22:06:19Z khoo $
6
7// System include(s):
8#include <stdexcept>
9
10// Gaudi/Athena include(s):
11#include "GaudiKernel/MsgStream.h"
12
13// Core EDM include(s):
17
18// Local include(s):
20
21#include <utility>
22#include <algorithm>
23
25#define MSGLVL MSG::VERBOSE
26
28#define ATH_MSG( MSG ) \
29 do { \
30 if( log.level() <= MSGLVL ) { \
31 log << MSGLVL << MSG << endmsg; \
32 } \
33 } while( 0 )
34
35using namespace MissingETBase;
36using namespace MissingETBase::Types;
37
41
42bool maskSumptSort(const std::pair<bitmask_t,constvec_t>& p1, const std::pair<bitmask_t,constvec_t>& p2) {
43 if(MissingETBase::Numerical::isEqual(p1.second.sumpt(),p2.second.sumpt())) {
44 return p1.first>p2.first;
45 }
46 return p1.second.sumpt()<p2.second.sumpt();
47}
48
52 MsgStream& log ) const {
53
54 // Greet the user:
55 ATH_MSG( "Converting xAOD::MissingETAuxAssociationMap_v1 to current version..." );
56
57 // Clear the transient object:
58 newObj->resize( 0 );
59
60 // Copy the payload of the v1 object into the latest one by misusing
61 // the thinning code a bit...
62 SG::copyAuxStoreThinned( *oldObj, *newObj, nullptr );
63
64 // Set up interface containers on top of them:
65
66 //The old uses v_
68 for( size_t i = 0; i < oldObj->size(); ++i ) {
70 }
71 oldInt.setStore( oldObj );
72
74 for( size_t i = 0; i < newObj->size(); ++i ) {
76 }
77 newInt.setStore( newObj );
78
79 unsigned char calOverlap(11), trkOverlap(25);
80 std::map<bitmask_t,constvec_t> calmap, trkmap;
81 std::vector<std::pair<bitmask_t,constvec_t> > sortedCalPairs, sortedTrkPairs;
82 sortedCalPairs.reserve(10);
83 sortedTrkPairs.reserve(10);
84 for( size_t iAssoc=0; iAssoc < oldInt.size(); ++iAssoc ) {
85 const xAOD::MissingETAssociation* assoc = oldInt[iAssoc];
86 ATH_MSG("On assoc " << iAssoc << ", size = " << assoc->size() );
87
89 // Set up maps
90 calmap.clear();
91 trkmap.clear();
92 sortedCalPairs.clear();
93 sortedTrkPairs.clear();
94
95 for(size_t iObj=0; iObj<assoc->size(); ++iObj) {
96 constvec_t calvec = assoc->calVec(iObj);
97 constvec_t trkvec = assoc->trkVec(iObj);
98 bitmask_t calmask = static_cast<bitmask_t>(1)<<iObj;
99 bitmask_t trkmask = static_cast<bitmask_t>(1)<<iObj;
100 ATH_MSG(" Obj " << iObj);
101 // Build up masks identifying overlaps
102 for(size_t iOverlap=0; iOverlap<assoc->overlapIndices(iObj).size(); ++iOverlap) {
103 size_t overlapIndex = assoc->overlapIndices(iObj)[iOverlap];
104 size_t overlapType = assoc->overlapTypes(iObj)[iOverlap];
105 ATH_MSG(" Overlap " << iOverlap << " (" << overlapIndex << ", " << overlapType << ")" );
106 if( (calOverlap&overlapType) && calvec.sumpt() <= assoc->calVec(overlapIndex).sumpt() ) {
107 ATH_MSG(" cal overlap " << overlapIndex);
108 calmask |= static_cast<bitmask_t>(1)<<overlapIndex;
109 }
110 if( (trkOverlap&overlapType) && trkvec.sumpt() <= assoc->trkVec(overlapIndex).sumpt() ) {
111 ATH_MSG(" trk overlap " << overlapIndex);
112 trkmask |= static_cast<bitmask_t>(1)<<overlapIndex;
113 }
114 }
115 ATH_MSG(" calmask = " << calmask << ", trkmask = " << trkmask);
116 // Ensure uniqueness
117 if(calmap[calmask].sumpt()==0 && calvec.sumpt()>1e-9) {
118 calmap[calmask] = calvec;
119 sortedCalPairs.emplace_back(calmask,calvec);
120 ATH_MSG(" Add unique cal mask " << calmask << ", sumpt " << calvec.sumpt());
121 }
122 if(trkmap[trkmask].sumpt()==0 && trkvec.sumpt()>1e-9) {
123 trkmap[trkmask] = trkvec;
124 sortedTrkPairs.emplace_back(trkmask,trkvec);
125 ATH_MSG(" Add unique trk mask " << trkmask << ", sumpt " << trkvec.sumpt());
126 }
127 }
128
129 // Sort in ascending sumpT then by increasing mask value
130 // Probably redundant as identical values should have been overlap-removed
131 std::sort(sortedCalPairs.begin(),sortedCalPairs.end(),maskSumptSort);
132 size_t iPair(0);
133 for(auto& calpair : sortedCalPairs) {
134 bitmask_t calmask = calpair.first;
135 double sumpt = calpair.second.sumpt();
136 ATH_MSG(" Do subtractions on calmask " << calmask << " with sumpt " << sumpt);
137
138 for(size_t jPair(iPair+1); jPair<sortedCalPairs.size(); ++jPair) {
139 const auto& calpair2=sortedCalPairs[jPair];
140 ATH_MSG(" Check calmask " << calpair2.first << " with sumpt " << calpair2.second.sumpt());
141 if(calmask > calpair2.first && (calmask & calpair2.first)==calpair2.first) {
142 // subtract from the next most inclusive calmask that overlaps this one
143 calmap[calpair2.first] -= calpair.second;
144 ATH_MSG(" Cal mask " << calmask << ", sumpt " << sumpt
145 << ", subtract from " << calpair2.first
146 << " (" << calpair2.second.sumpt() << " --> " << calmap[calpair2.first].sumpt() << ")");
147 break;
148 }
149 }
150 ++iPair;
151 }
152
153 std::sort(sortedTrkPairs.begin(),sortedTrkPairs.end(),maskSumptSort);
154 iPair = 0;
155 for(auto& trkpair : sortedTrkPairs) {
156 bitmask_t trkmask = trkpair.first;
157 double sumpt = trkpair.second.sumpt();
158 ATH_MSG(" Do subtractions on trkmask " << trkmask << " with sumpt " << sumpt);
159
160 for(size_t jPair(iPair+1); jPair<sortedTrkPairs.size(); ++jPair) {
161 const auto& trkpair2=sortedTrkPairs[jPair];
162 ATH_MSG(" Check trkmask " << trkpair2.first << " with sumpt " << trkpair2.second.sumpt());
163 if(trkmask > trkpair2.first && (trkmask&trkpair2.first)==trkpair2.first) {
164 // subtract from the next most inclusive trkmask that overlaps this one
165 trkmap[trkpair2.first] -= trkpair.second;
166 ATH_MSG(" Trk mask " << trkmask << ", sumpt " << sumpt
167 << ", subtract from " << trkpair2.first
168 << " (" << trkpair2.second.sumpt() << " --> " << trkmap[trkpair2.first].sumpt() << ")");
169 break;
170 }
171 }
172 ++iPair;
173 }
174
175 xAOD::MissingETAssociation* newassoc = newInt[iAssoc];
176 newassoc->clearCalVecs();
177 // Convert maps to vector representation
178 size_t iKey(0);
179 for (const auto& calpair : calmap) {
180 bitmask_t bm = calpair.first;
181 constvec_t cv = calpair.second;
182 if(cv.sumpt()>1e-9) {
183 ATH_MSG(" CalKey " << bm << ", constvec sumpt = " << cv.sumpt());
184 newassoc->addCalVec(bm,cv.cpx(),cv.cpy(),cv.cpz(),cv.ce(),cv.sumpt());
185 ATH_MSG(" retrieve key " << newassoc->calkey(iKey) << ", sumpt " <<
186 newassoc->calVec(iKey).sumpt() );
187 ++iKey;
188 }
189 }
190 ATH_MSG("Final calsize = " << newassoc->sizeCal() << ", " << newassoc->cale().size());
191
192 iKey=0;
193 newassoc->clearTrkVecs();
194 for (const auto& trkpair : trkmap) {
195 bitmask_t bm = trkpair.first;
196 constvec_t cv = trkpair.second;
197 if(cv.sumpt()>1e-9) {
198 ATH_MSG(" TrkKey " << bm << ", constvec sumpt = " << cv.sumpt());
199 newassoc->addTrkVec(bm,cv.cpx(),cv.cpy(),cv.cpz(),cv.ce(),cv.sumpt());
200 ATH_MSG(" retrieve key " << newassoc->trkkey(iKey) << ", sumpt " <<
201 newassoc->trkVec(iKey).sumpt() );
202 ++iKey;
203 }
204 }
205 ATH_MSG("Final trksize = " << newassoc->sizeTrk() << ", " << newassoc->trke().size());
206
207 } // Loop over associations
208
209 // Print what happened:
210 ATH_MSG( "Converting xAOD::MissingETAuxAssociationMap_v1 to current version "
211 "[OK]" );
212
213 return;
214}
215
222 MsgStream& log ) const {
223
224 log << MSG::ERROR
225 << "Somebody called xAODMissingETAuxAssociationMapCnv_v1::transToPers"
226 << endmsg;
227 throw std::runtime_error( "Somebody called xAODMissingETAuxAssociationMapCnv_v1::"
228 "transToPers" );
229
230 return;
231}
#define endmsg
#define ATH_MSG(lvl)
value_type push_back(value_type pElem)
Add an element to the end of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
virtual void transToPers(const xAOD::MissingETAuxAssociationMap *, xAOD::MissingETAuxAssociationMap_v1 *, MsgStream &log) const override
Dummy function inherited from the base class.
virtual void persToTrans(const xAOD::MissingETAuxAssociationMap_v1 *oldObj, xAOD::MissingETAuxAssociationMap *newObj, MsgStream &log) const override
Function converting from the old type to the current one.
virtual bool resize(size_t size) override
Resize the arrays to a given size.
virtual size_t size() const override
Get the size of the container.
float sumpt() const
Returns sum of component pt.
MET association descriptor contains object links and corresponding parameters.
const std::vector< float > & cale() const
Get the vector of .
const std::vector< MissingETBase::Types::bitmask_t > & calkey() const
Get the vector of cal keys.
bool clearTrkVecs()
Reset the track constituent vectors and keys.
size_t size() const
Update all internally used ElementLink instances.
ConstVec trkVec(const IParticle *pPart) const
Get track constituent vector for a given object.
const std::vector< std::vector< unsigned char > > & overlapTypes() const
Get the list of object overlapTypes.
const std::vector< MissingETBase::Types::bitmask_t > & trkkey() const
Get the vector of trk keys.
bool addTrkVec(MissingETBase::Types::bitmask_t key, float trkpx, float trkpy, float trkpz, float ce, float sumpt)
Add a key/vector pair for calo contributions.
const std::vector< float > & trke() const
Get the vector of .
bool clearCalVecs()
Reset the calo constituent vectors and keys.
bool addCalVec(MissingETBase::Types::bitmask_t key, float calpx, float calpy, float calpz, float cale, float sumpt)
Add a key/vector pair for calo contributions.
const std::vector< std::vector< size_t > > & overlapIndices() const
Get the list of object overlapIndices.
ConstVec calVec(const IParticle *pPart) const
Get calo constituent vector for a given object.
Auxiliary data store for xAOD::MissingETAssociationMap_v1.
Helper to copy an aux store while applying thinning.
Namespace for generally used type definitions.
xAOD::MissingETAssociation_v1::ConstVec constvec_t
Type for constituent vector.
uint64_t bitmask_t
Type for status word bit mask.
General namespace for MET EDM software.
void copyAuxStoreThinned(const SG::IConstAuxStore &orig, SG::IAuxStore &copy, const SG::ThinningInfo *info)
Helper to copy an aux store while applying thinning.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
MissingETAuxAssociationMap_v2 MissingETAuxAssociationMap
Version control by type definition.
MissingETAssociation_v1 MissingETAssociation
Version control by type definition.
MissingETAssociationMap_v1 MissingETAssociationMap
Version control by type defintion.
static bool isEqual(double x, double y)
Test of equality.
bool maskSumptSort(const std::pair< bitmask_t, constvec_t > &p1, const std::pair< bitmask_t, constvec_t > &p2)