ATLAS Offline Software
xAODMissingETAuxAssociationMapCnv_v1.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 // $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 
35 using namespace MissingETBase;
36 using namespace MissingETBase::Types;
37 
39 {
40 }
41 
42 bool 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 ) {
75  newInt.push_back( new xAOD::MissingETAssociation() );
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 = 1<<iObj;
99  bitmask_t trkmask = 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 |= 1<<overlapIndex;
109  }
110  if( (trkOverlap&overlapType) && trkvec.sumpt() <= assoc->trkVec(overlapIndex).sumpt() ) {
111  ATH_MSG(" trk overlap " << overlapIndex);
112  trkmask |= 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 }
SG::copyAuxStoreThinned
void copyAuxStoreThinned(const SG::IConstAuxStore &orig, SG::IAuxStore &copy, const SG::ThinningInfo *info)
Helper to copy an aux store while applying thinning.
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
xAOD::MissingETAssociation_v1
MET association descriptor contains object links and corresponding parameters.
Definition: MissingETAssociation_v1.h:29
xAOD::MissingETAssociation_v1::cale
const std::vector< float > & cale() const
Get the vector of
TRTCalib_cfilter.p1
p1
Definition: TRTCalib_cfilter.py:130
xAODMissingETAuxAssociationMapCnv_v1::xAODMissingETAuxAssociationMapCnv_v1
xAODMissingETAuxAssociationMapCnv_v1()
Default constructor.
Definition: xAODMissingETAuxAssociationMapCnv_v1.cxx:38
xAOD::MissingETAuxAssociationMap_v2
Auxiliary data store for xAOD::MissingETAssociationMap_v2.
Definition: MissingETAuxAssociationMap_v2.h:26
xAODMissingETAuxAssociationMapCnv_v1.h
MissingETBase
General namespace for MET EDM software.
Definition: MissingETAssociation_v1.h:454
xAOD::MissingETAssociation_v1::overlapTypes
const std::vector< std::vector< unsigned char > > & overlapTypes() const
Get the list of object overlapTypes.
MissingETBase::Types::bitmask_t
uint64_t bitmask_t
Type for status word bit mask.
Definition: MissingETBase.h:39
xAOD::AuxContainerBase::resize
virtual bool resize(size_t size) override
Resize the arrays to a given size.
Definition: AuxContainerBase.cxx:505
xAOD::MissingETAssociation_v1::overlapIndices
const std::vector< std::vector< size_t > > & overlapIndices() const
Get the list of object overlapIndices.
xAOD::MissingETAssociation_v1::ConstVec
Vector sum of constituents for subtractive overlap removal.
Definition: MissingETAssociation_v1.h:36
xAOD::MissingETAssociationMap_v1
Definition: MissingETAssociationMap_v1.h:29
xAOD::MissingETAssociation_v1::clearTrkVecs
bool clearTrkVecs()
Reset the track constituent vectors and keys.
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
xAOD::AuxContainerBase::size
virtual size_t size() const override
Get the size of the container.
Definition: AuxContainerBase.cxx:430
TRTCalib_cfilter.p2
p2
Definition: TRTCalib_cfilter.py:131
copyAuxStoreThinned.h
Helper to copy an aux store while applying thinning.
xAOD::MissingETAuxAssociationMap_v1
Auxiliary data store for xAOD::MissingETAssociationMap_v1.
Definition: MissingETAuxAssociationMap_v1.h:26
lumiFormat.i
int i
Definition: lumiFormat.py:85
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
xAOD::MissingETAssociation_v1::ConstVec::cpy
float cpy() const
Returns .
xAOD::MissingETAssociation_v1::ConstVec::sumpt
float sumpt() const
Returns sum of component pt.
xAOD::MissingETAssociation_v1::trkkey
const std::vector< MissingETBase::Types::bitmask_t > & trkkey() const
Get the vector of trk keys.
xAOD::MissingETAssociation_v1::ConstVec::cpz
float cpz() const
Returns .
xAOD::MissingETAssociation_v1::calVec
ConstVec calVec(const IParticle *pPart) const
Get calo constituent vector for a given object.
Definition: MissingETAssociation_v1.cxx:540
xAOD::MissingETAssociation_v1::addCalVec
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.
Definition: MissingETAssociation_v1.cxx:347
MissingETAssociationMap_v1.h
xAOD::MissingETAssociation_v1::trke
const std::vector< float > & trke() const
Get the vector of
MissingETBase::Numerical::isEqual
static bool isEqual(double x, double y)
Test of equality.
Definition: MissingETBase.h:119
maskSumptSort
bool maskSumptSort(const std::pair< bitmask_t, constvec_t > &p1, const std::pair< bitmask_t, constvec_t > &p2)
Definition: xAODMissingETAuxAssociationMapCnv_v1.cxx:42
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
xAOD::MissingETAssociation_v1::clearCalVecs
bool clearCalVecs()
Reset the calo constituent vectors and keys.
xAODMissingETAuxAssociationMapCnv_v1::persToTrans
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.
Definition: xAODMissingETAuxAssociationMapCnv_v1.cxx:50
xAOD::MissingETAssociation_v1::calkey
const std::vector< MissingETBase::Types::bitmask_t > & calkey() const
Get the vector of cal keys.
xAOD::MissingETAssociation_v1::addTrkVec
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.
Definition: MissingETAssociation_v1.cxx:381
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
ATH_MSG
#define ATH_MSG(MSG)
Another convenience macro for printing messages in the converter.
Definition: xAODMissingETAuxAssociationMapCnv_v1.cxx:28
xAOD::MissingETAssociation_v1::trkVec
ConstVec trkVec(const IParticle *pPart) const
Get track constituent vector for a given object.
Definition: MissingETAssociation_v1.cxx:550
MissingETAssociationMap.h
xAOD::MissingETAssociation_v1::ConstVec::cpx
float cpx() const
Returns .
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
xAOD::MissingETAssociation_v1::ConstVec::ce
float ce() const
Returns .
xAODMissingETAuxAssociationMapCnv_v1::transToPers
virtual void transToPers(const xAOD::MissingETAuxAssociationMap *, xAOD::MissingETAuxAssociationMap_v1 *, MsgStream &log) const override
Dummy function inherited from the base class.
Definition: xAODMissingETAuxAssociationMapCnv_v1.cxx:220
MissingETBase::Types
Namespace for generally used type definitions.
Definition: MissingETAssociation_v1.h:456