ATLAS Offline Software
Loading...
Searching...
No Matches
Reconstruction/MissingETEvent/MissingETEvent/MissingETComposition.h
Go to the documentation of this file.
1// -*- c++ -*-
2
3/*
4 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
5*/
6
7#ifndef MISSINGETEVENT_MISSINGETCOMPOSITION_H
8#define MISSINGETEVENT_MISSINGETCOMPOSITION_H
9
12
15
16#include <vector>
17#include <tuple>
18
20
21 typedef unsigned short bitmask_t;
22
23 enum Tags {
24 UNKNOWN = 0x0000,
25 DEFAULT = 0x0001,
26 SPECTRO = 0x0002,
27 TRACK = 0x0004,
28 REFMUON = 0x0008,
29 MUID = 0x0010,
30 EFLOW_CLUSTER = 0x0020,
32 VTX_SHIFTED_CLUSTER_DEF = 0x0081, // shifted default
33 VTX_SHIFTED_CLUSTER = 0x0080, // just shift indicator
35 PU_TRACK_STVF = 0x1100,
36 PU_TRACK_SUM = 0x1200,
37 PU_TRACK_CONE = 0x1400,
38 PU_JET_AREA = 0x1800,
40 PU_JET_JVF = 0x3100,
42 PU_JET_JVFCUT = 0x3300,
45 //NEXT_COMES = 0x0080,
46 //THEN = 0x0100,
47 };
48
49 // general test for tag pattern
50 static bool usesTags(bitmask_t tag,bitmask_t test)
51 { return (tag & test) == test; }
52
53 //isDEFAULT means use default pt and no other bits are set
54 static bool isDEFAULT(bitmask_t tag)
55 { return tag == DEFAULT || tag == VTX_SHIFTED_CLUSTER_DEF; }
56
57 //usesDEFAULT means use default pt but other bits could also be set
58 static bool usesDEFAULT(bitmask_t tag)
59 { return tag & DEFAULT; }
60
61 static bool usesSPECTRO(bitmask_t tag)
62 { return tag & SPECTRO; }
63
64 static bool usesTRACK(bitmask_t tag)
65 { return tag & TRACK; }
66
67 static bool usesREFMUON(bitmask_t tag)
68 { return tag & REFMUON; }
69
70 static bool usesMUID(bitmask_t tag)
71 { return tag & MUID; }
72
74 { return tag & EFLOW_CLUSTER; }
75
77 { return tag & REMOVED_CLUSTER; }
78
80 { return tag & PILEUP_CORRECTED; }
81
83 { return tag & PU_TRACK_STVF; }
84
85 static bool usesPU_TRACK_SUM(bitmask_t tag)
86 { return tag & PU_TRACK_SUM; }
87
89 { return tag & PU_TRACK_CONE; }
90
91 static bool usesPU_JET_AREA(bitmask_t tag)
92 { return tag & PU_JET_AREA; }
93
95 { return tag & PU_JET_CORRECTION; }
96
97 static bool usesPU_JET_JVF(bitmask_t tag)
98 { return tag & PU_JET_JVF; }
99
101 { return tag & PU_JET_JVFCUT; }
102
104 { return tag & PU_JET_CUSTOM_JVF; }
105
107 { return tag & PU_JET_AREA_JET; }
108
110 { return tag & PU_JET_AREA_JVF; }
111
113 { return tag & VTX_SHIFTED_CLUSTER; }
114
116 { return tag & VTX_SHIFTED_CLUSTER_DEF; }
117
118 static void setUsesDEFAULT(bitmask_t &tag)
119 { tag = tag | DEFAULT;}
120
121 static void setUsesSPECTRO(bitmask_t &tag)
122 { tag = tag | SPECTRO;}
123
124 static void setUsesTRACK(bitmask_t &tag)
125 { tag = tag | TRACK;}
126
127 static void setUsesREFMUON(bitmask_t &tag)
128 { tag = tag | REFMUON;}
129
130 static void setUsesMUID(bitmask_t &tag)
131 { tag = tag | MUID;}
132
134 { tag = tag | EFLOW_CLUSTER;}
135
137 { tag = tag | REMOVED_CLUSTER;}
138
140 { tag = tag | PILEUP_CORRECTED;}
141
143 { tag = tag | PU_TRACK_STVF;}
144
146 { tag = tag | PU_TRACK_SUM;}
147
149 { tag = tag | PU_TRACK_CONE;}
150
152 { tag = tag | PU_JET_AREA;}
153
155 { tag = tag | PU_JET_CORRECTION; }
156
157 static void setUsesPU_JET_JVF(bitmask_t &tag)
158 { tag = tag | PU_JET_JVF; }
159
161 { tag = tag | PU_JET_JVFCUT; }
162
164 { tag = tag | PU_JET_CUSTOM_JVF; }
165
167 { tag = tag | PU_JET_AREA_JET; }
168
170 { tag = tag | PU_JET_AREA_JVF; }
171
173 { tag = tag | VTX_SHIFTED_CLUSTER; }
174
177};
178
180
181 typedef std::tuple<float,float,float,unsigned short int> struct_t;
182
183 static float precision() { return 0.0001; }
184
185 class Weight : public struct_t
186 {
187 public:
188 // templated constructor
189 template <typename PERS>
190 /* explicit */ Weight(PERS&)
191 {
192 this->setWpx(0);
193 this->setWpy(0);
194 this->setWet(0);
195 this->setStatusWord(0);
196 std::cerr << "Rolf: calling general template for Weight c'tor ! You need to specialize it for " << typeid(PERS).name() << " !\n";
197 abort();
198 }
199
200 Weight() = default;
201 Weight(float wpx,float wpy,float wet) : struct_t(wpx,wpy,wet,0) { }
202 Weight(float wpx,float wpy,float wet, unsigned short int status) : struct_t(wpx,wpy,wet,status) { }
203 virtual ~Weight() = default;
204
205 Weight(const Weight& w) = default;
206 Weight& operator=(const Weight& w) = default;
207 Weight(Weight&& w) = default;
208 Weight& operator=(Weight&& w) = default;
209
210 float wpx() const { return (float)std::get<0>(*this); }
211 float wpy() const { return (float)std::get<1>(*this); }
212 float wet() const { return (float)std::get<2>(*this); }
213 unsigned short int statusWord() const { return (unsigned short int)std::get<3>(*this); }
214
215 void setWpx(float wpx) { std::get<0>(*this) = wpx; }
216 void setWpy(float wpy) { std::get<1>(*this) = wpy; }
217 void setWet(float wet) { std::get<2>(*this) = wet; }
218 void setStatusWord(unsigned short int status) { std::get<3>(*this) = status; }
219
221 {
222 this->setWpx(w.wpx()+this->wpx());
223 this->setWpy(w.wpy()+this->wpy());
224 this->setWet(w.wet()+this->wet());
225 return *this;
226 }
227
229 {
230 this->setWpx(this->wpx()-w.wpx());
231 this->setWpy(this->wpy()-w.wpy());
232 this->setWet(this->wet()-w.wet());
233 return *this;
234 }
235
237 {
238 this->setWpx(w.wpx()*this->wpx());
239 this->setWpy(w.wpy()*this->wpy());
240 this->setWet(w.wet()*this->wet());
241 return *this;
242 }
243
245 {
246 this->setWpx(this->divide(this->wpx(),w.wpx()));
247 this->setWpy(this->divide(this->wpy(),w.wpy()));
248 this->setWet(this->divide(this->wet(),w.wet()));
249 return *this;
250 }
251
252 bool operator==(const Weight& w) const
253 {
254 return
255 isEqual(w.wpx(),this->wpx()) &&
256 isEqual(w.wpy(),this->wpy()) &&
257 isEqual(w.wet(),this->wet());
258 }
259
260 bool operator!=(const Weight& w) const
261 { return !(this->operator==)(w); }
262
263 static float divide(float x,float y)
264 { return y != 0. ? x /y : 0.; }
265
266 static bool isEqual(float x,float y)
267 { return fabs(x-y) <= precision()*fabs(x); }
268
269 };//class Weight
270
271
272Weight operator*(const Weight& w1,
273 const Weight& w2);
274Weight operator*(const Weight& w, double scale);
275Weight operator*(double scale, const Weight& w);
276Weight operator/(const Weight& w1,
277 const Weight& w2);
278Weight operator+(const Weight& w1,
279 const Weight& w2);
280Weight operator-(const Weight& w1,
281 const Weight& w2);
282
283
284}//namespace MissingETHandlers
285
286
287
289 public Navigable<INavigable4MomentumCollection,MissingETHandlers::Weight>
290{
291public:
292
298
299 // iterators
300 template<class OBJECT>
302 {
303 public:
305 const_iterator(const base_t* store,iiterator_t iiter)
306 : m_store(store), m_actual(iiter) { }
307 virtual ~const_iterator() { }
308 // copy
310 : m_store(iter.m_store), m_actual(iter.m_actual) { }
311
313 if(&iter != this) {
314 m_store = iter.m_store;
315 m_actual = iter.m_actual;
316 }
317 return *this;
318 }
319
320 // increment
322 {
323 m_actual++;
324 while ( m_actual != m_store->end() &&
325 dynamic_cast<const OBJECT*>(*m_actual) == 0 ) { m_actual++; };
326 return *this;
327 }
329 {
330 const_iterator tmp(*this);
331 m_actual++;
332 while ( m_actual != m_store->end() &&
333 dynamic_cast<const OBJECT*>(*m_actual) == 0 ) { m_actual++; };
334 return tmp;
335 }
336
337 // decrement
339 {
340 m_actual--;
341 while ( m_actual != m_store->begin() &&
342 dynamic_cast<const OBJECT*>(*m_actual) == 0 ) { m_actual--; };
343 return m_actual != m_store->begin() ? *this : 0;
344 }
346 {
347 const_iterator tmp(*this);
348 m_actual--;
349 while ( m_actual != m_store->end() &&
350 dynamic_cast<const OBJECT*>(*m_actual) == 0 ) { m_actual--; };
351 return tmp;
352 }
353
354 // equality
355 bool operator==(const const_iterator& iter) const
356 { return m_store == iter.m_store && m_actual == iter.m_actual; }
357 bool operator!=(const const_iterator& iter) const
358 { return !(this->operator==)(iter); }
359
360 // access
361 const OBJECT* operator*() const
362 {
363 return dynamic_cast<const OBJECT*>(*m_actual);
364 }
365 const OBJECT*& operator->() const
366 {
367 if (dynamic_cast<const OBJECT*>(*m_actual)==0) {
368 std::cout << "dynamic cast==0 in operator*" << std::endl;
369 }
370
371 return dynamic_cast<const OBJECT*>(*m_actual);
372 }
373
374 const OBJECT* getObject() const { return this->operator*(); }
375 const weight_t getParameter() const { return m_actual.getParameter(); }
376 // helpful for copying compositions
378 { return m_store->getContainer(m_actual); }
379
380 private:
381
384 };
385
387 virtual ~MissingETComposition();
388
389 void insert(const collection_t* pColl,const object_t* pObj,
390 weight_t weight)
391 {
392 this->insertElement(pColl,pObj,weight);
393 }
394
395 weight_t getWeight(const object_t* pObj) const
396 {
397 return this->getParameter(pObj);
398 }
399
400 template<class OBJECT>
402 {
403 return fObj.getParameter();
404 }
405
406 template<class OBJECT>
408 {
409 if (this->begin() != this->end()) {
410 const_iterator<OBJECT> temp(static_cast<const base_t*>(this), this->begin());
411 if ((*temp)==0) {++temp; return temp;}
412 return temp;
413 }
414 else { return const_iterator<OBJECT>(static_cast<const base_t*>(this), this->begin()); }
415 }
416
417 template<class OBJECT>
419 {
420 return const_iterator<OBJECT>(static_cast<const base_t*>(this), this->end());
421 }
422
423 template<class OBJECT>
424 const_iterator<OBJECT> find(const OBJECT* pObj) const
425 {
428 while ( fObj != lObj && pObj != *fObj ) { ++fObj; }
429 return fObj;
430 }
431
432 // fill missing ET object - really adds!!
433 template<class OBJECT>
435 unsigned short rejectTag=(MissingETtags::PILEUP_CORRECTED |
437 {
438 // sanity check
439 if ( pMET == 0 ) return false;
440 // sum up
441 float px(0.);
442 float py(0.);
443 float et(0.);
444 float eta(0.);
445 float e(0.);
448 for ( ; fObj != lObj; ++fObj )
449 {
450 if ( !MissingETtags::usesTags(fObj.statusWord(),rejectTag) )
451 {
452 px += (*fObj)->px() * fObj.getParameter().wpx();
453 py += (*fObj)->py() * fObj.getParameter().wpy();
454 et += (*fObj)->et() * fObj.getParameter().wet();
455 // eta
456 eta += (*fObj)->eta() * (*fObj)->e() * fObj.getParameter().wet();
457 e += (*fObj)->e() * fObj.getParameter().wet();
458 }
459 }
460 // get eta
461 eta = e != 0. ? eta/e : 0.;
462 //
463 pMET->add(px,py,et,eta,1.0);
464 return true;
465 }
466
467 // get contributions from given object
468 template<class OBJECT>
469 MissingET* getMissingET(unsigned short rejectTag=
471 const
472 {
473 //
475 if ( this->fillMissingET<OBJECT>(pMET,rejectTag) ) return pMET;
476 // error raised
477 if ( pMET != 0 ) delete pMET;
478 return (MissingET*)0;
479 }
480
481};
482
483CLASS_DEF(MissingETComposition, 264867051, 1)
484
485#endif
Scalar eta() const
pseudorapidity method
macros to associate a CLID to a type
#define CLASS_DEF(NAME, CID, VERSION)
associate a clid and a version to a type eg
DataVector< INavigable4Momentum > INavigable4MomentumCollection
float et(const xAOD::jFexSRJetRoI *j)
Athena::TPCnvVers::Old Athena::TPCnvVers::Old MissingET
Definition RecTPCnv.cxx:64
RpcSectorLogicContainer_p1 PERS
#define y
#define x
INavigable4Momentum base_value_type
Definition DataVector.h:825
void insert(const collection_t *pColl, const object_t *pObj, weight_t weight)
bool fillMissingET(MissingET *pMET, unsigned short rejectTag=(MissingETtags::PILEUP_CORRECTED|MissingETtags::REMOVED_CLUSTER)) const
const_iterator< OBJECT > find(const OBJECT *pObj) const
MissingET * getMissingET(unsigned short rejectTag=(MissingETtags::PILEUP_CORRECTED|MissingETtags::REMOVED_CLUSTER)) const
Weight & operator=(Weight &&w)=default
virtual ~Weight()=default
Weight(Weight &&w)=default
Weight(const Weight &w)=default
Weight & operator=(const Weight &w)=default
Weight(float wpx, float wpy, float wet, unsigned short int status)
virtual void add(double theEx, double theEy, double theEt, double theEta, double weight)
NavigableIterator< collection_t, weight_t, typename NavigationDefaults::DefaultChildColl< collection_t, weight_t >::type > object_iter
Definition Navigable.h:159
MissingETHandlers::Weight getParameter(const constituent_type *aConstituent) const
void insertElement(const INavigable4MomentumCollection *objectContainer, const constituent_type *constituentObject, const MissingETHandlers::Weight &objectParameter=MissingETHandlers::Weight(), size_t sizeHint=0)
Weight operator+(const Weight &w1, const Weight &w2)
std::tuple< float, float, float, unsigned short int > struct_t
Weight operator/(const Weight &w1, const Weight &w2)
Weight operator-(const Weight &w1, const Weight &w2)
Weight operator*(const Weight &w1, const Weight &w2)
static bool usesTags(bitmask_t tag, bitmask_t test)
Extra patterns decribing particle interation process.