Egamma_v1.cxx 15.6 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
/*
  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/

// $Id: Egamma_v1$

// EDM include(s):
#include "xAODCore/AuxStoreAccessorMacros.h"
// Local include(s):
#include "xAODEgamma/versions/Egamma_v1.h"
#include "EgammaAccessors_v1.h"
12
#include "xAODPrimitives/tools/getIsolationAccessor.h"
13
#include "xAODPrimitives/tools/getIsolationCorrectionAccessor.h" 
14
#include <stdexcept>
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119

namespace xAOD {

  Egamma_v1::Egamma_v1()
    : IParticle(), m_p4(), m_p4Cached( false ) {
  }
  
  Egamma_v1::Egamma_v1(const Egamma_v1& eg) : IParticle(eg), m_p4(eg.m_p4), m_p4Cached(eg.m_p4Cached) {
  }

 Egamma_v1& Egamma_v1::operator=(const Egamma_v1& eg ){

    if (this != &eg){ // protect against invalid self-assignment      

      if (!this->container() && !this->hasStore() ) {      
	  makePrivateStore();
      }
      this->IParticle::operator=( eg );
      this->m_p4 = eg.m_p4;
      this->m_p4Cached = eg.m_p4Cached;
    }
    // by convention, always return *this
    return *this;
 }


  double Egamma_v1::pt() const {
    static Accessor< float > acc( "pt" );
    return acc( *this );
  }
  
  double Egamma_v1::eta() const {
    static Accessor<float > acc( "eta" );
    return acc( *this );
  }
  
  double Egamma_v1::phi() const {
    static Accessor< float > acc( "phi" );
    return acc( *this );
  }
  
  double Egamma_v1::m() const {
    static Accessor< float> acc( "m" );
    return acc( *this );
  }
  
  double Egamma_v1::e() const{
    return p4().E(); 
  }
  
  double Egamma_v1::rapidity() const {
    return p4().Rapidity();	
  }
  
  const Egamma_v1::FourMom_t& Egamma_v1::p4() const {
    if( ! m_p4Cached ) {
      m_p4.SetPtEtaPhiM( pt(), eta(), phi(),m()); 
      m_p4Cached=true;
    }
    return m_p4;	
  }
  
  void Egamma_v1::setP4(float pt, float eta, float phi, float m){
    static Accessor< float > acc1( "pt" );
    acc1( *this ) = pt;
    static Accessor< float > acc2( "eta" );
    acc2( *this ) = eta;
    static Accessor< float > acc3( "phi" );
    acc3( *this ) = phi;
    static Accessor< float > acc4( "m" );
    acc4( *this ) = m;
    //Need to recalculate m_p4 if requested after update
    m_p4Cached=false;
  }
  
  void Egamma_v1::setPt(float pt){
    static Accessor< float > acc( "pt" );
    acc( *this ) = pt;
    //Need to recalculate m_p4 if requested after update
    m_p4Cached=false;
  }
  
  void Egamma_v1::setEta(float eta){
    static Accessor< float > acc( "eta" );
    acc( *this ) = eta;
    //Need to recalculate m_p4 if requested after update
    m_p4Cached=false;
  }

  void Egamma_v1::setPhi(float phi){
    static Accessor< float > acc( "phi" );
    acc( *this ) = phi;
    //Need to recalculate m_p4 if requested after update
    m_p4Cached=false;
  }

  void Egamma_v1::setM(float m){
    static Accessor< float > acc( "m" );
    acc( *this ) = m;
    //Need to recalculate m_p4 if requested after update
    m_p4Cached=false;
  }

  Egamma_v1::EgammaCovMatrix_t Egamma_v1::covMatrix() const{
    static Accessor< std::vector<float> > acc( "EgammaCovarianceMatrix" );
120
121
122
123
124
    if(!acc.isAvailable( *this) ) { 
      EgammaCovMatrix_t dummy;
      dummy.setZero();
      return dummy;
    }
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
    const std::vector<float>& v = acc(*this);
    return Eigen::Map<const EgammaCovMatrix_t> (v.data());
  }

  void Egamma_v1::setCovMatrix(const Egamma_v1::EgammaCovMatrix_t& cov){
    //The internal storage is an std::vector
    static Accessor< std::vector < float > > acc( "EgammaCovarianceMatrix" );
    const std::vector<float> v(cov.data(),cov.data()+16);
    acc(*this)=v;
  }
  
  uint16_t Egamma_v1::author(uint16_t mask) const {
    static Accessor< uint16_t > acc( "author" );
    uint16_t author = acc( *this );
    return author & mask;
  }
  
  void Egamma_v1::addAuthor(uint16_t newAuthor) {
    static Accessor< uint16_t > acc( "author" );
    uint16_t author = acc( *this );
    acc( *this) = author | newAuthor;
  }
  
  void Egamma_v1::setAuthor(uint16_t newAuthor) {
    static Accessor< uint16_t > acc( "author" );
    acc( *this) = newAuthor;
  }
152
    
153
  /////////////// shower shapes
154
155
  bool Egamma_v1::showerShapeValue(float& value, const EgammaParameters::ShowerShapeType information)  const {
    xAOD::Egamma_v1::Accessor< float >* acc = showerShapeAccessorV1( information );
156
    if( !acc ) {
157
158
      return false;
    }
159
    if(!acc->isAvailable( *this) ) { 
160
161
162
163
164
165
      return  false;
    }
    // Retrieve the value:
    value = ( *acc )( *this );
    return true;
  }
166
167
168

  float Egamma_v1::showerShapeValue(const EgammaParameters::ShowerShapeType information)  const {
    xAOD::Egamma_v1::Accessor< float >* acc = showerShapeAccessorV1( information );
169
    if(!acc ) throw std::runtime_error( "Unknown/Unavailable Shower Shape type requested" );
170
171
    return ( *acc )( *this );
  }
172
  
173
  bool Egamma_v1::setShowerShapeValue(float value, const EgammaParameters::ShowerShapeType information){
174
    xAOD::Egamma_v1::Accessor< float >* acc = showerShapeAccessorV1( information );
175
     if( !acc ) return false;
176
177
178
179
180
    // Set the value:
    ( *acc )( *this ) = value;
    return true;

  }
181
182

  ///////////////   Isolation value
183
  bool  Egamma_v1::isolation(float& value, const Iso::IsolationType information)  const {
184
    SG::AuxElement::Accessor< float >* acc = getIsolationAccessor( information );
185
    if( !acc ) {
186
187
      return false;
    }
188
    if(!acc->isAvailable( *this) ) {
189
190
191
192
193
194
195
      return  false;
    }
    // Retrieve the value:
    value = ( *acc )( *this );
    return true;
  }

196
  float Egamma_v1::isolation( const Iso::IsolationType information)  const {
197
    SG::AuxElement::Accessor< float >* acc = getIsolationAccessor( information );
198
    if( !acc ) throw std::runtime_error( "Unknown/Unavailable Isolation type requested" );
199
200
    return  ( *acc )( *this );
  }
201

202
  bool Egamma_v1::setIsolation(float value, const Iso::IsolationType information) {
203
    SG::AuxElement::Accessor< float >* acc = getIsolationAccessor( information );
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
    if( !acc ) return false;
    // Set the value:
    ( *acc )( *this ) = value;
    return true;
  }

  /////////////// Isolation corrections

  bool Egamma_v1::isolationCaloCorrection(float& value, const Iso::IsolationFlavour flavour, const Iso::IsolationCaloCorrection corr, 
					  const Iso::IsolationCorrectionParameter param) const{
    SG::AuxElement::Accessor< float >* acc = getIsolationCorrectionAccessor(flavour,corr,param);
    if( !acc ) {
      return false;
    }
    if(!acc->isAvailable( *this) ) {
      return  false;
    }
    // Retrieve the value:
    value = ( *acc )( *this );
    return true;
 }

  float Egamma_v1::isolationCaloCorrection(const Iso::IsolationFlavour flavour, const Iso::IsolationCaloCorrection corr, 
					  const Iso::IsolationCorrectionParameter param) const{

    SG::AuxElement::Accessor< float >* acc = getIsolationCorrectionAccessor(flavour,corr,param);
    if( !acc ) throw std::runtime_error( "Unknown/Unavailable Isolation correction requested" );
    return  ( *acc )( *this );
  }

  bool Egamma_v1::setIsolationCaloCorrection(float value, const Iso::IsolationFlavour flavour, const Iso::IsolationCaloCorrection corr, 
					     const Iso::IsolationCorrectionParameter param){
    SG::AuxElement::Accessor< float >* acc = getIsolationCorrectionAccessor(flavour,corr,param);
    if( !acc ) return false;
    // Set the value:
    ( *acc )( *this ) = value;
    return true;
  }


  bool Egamma_v1::isolationCaloCorrection(float& value,  Iso::IsolationType type , Iso::IsolationCaloCorrection corr) const{
    SG::AuxElement::Accessor< float >* acc = getIsolationCorrectionAccessor(type,corr);
    if( !acc ) {
      return false;
    }
    if(!acc->isAvailable( *this) ) {
      return  false;
    }
    // Retrieve the value:
    value = ( *acc )( *this );
    return true;
  }

  float Egamma_v1::isolationCaloCorrection(Iso::IsolationType type, Iso::IsolationCaloCorrection corr) const{
    SG::AuxElement::Accessor< float >* acc = getIsolationCorrectionAccessor(type,corr);
    if( !acc ) throw std::runtime_error( "Unknown/Unavailable Isolation correction requested" );
    return  ( *acc )( *this );
  }

  bool Egamma_v1::setIsolationCaloCorrection(float value, Iso::IsolationType type, Iso::IsolationCaloCorrection corr){
    SG::AuxElement::Accessor< float >* acc = getIsolationCorrectionAccessor(type,corr);
    if( !acc ) return false;
    // Set the value:
    ( *acc )( *this ) = value;
    return true;
  }

  bool Egamma_v1::isolationTrackCorrection(float& value, const Iso::IsolationFlavour flavour, const Iso::IsolationTrackCorrection corr) const{
    SG::AuxElement::Accessor< float >* acc = getIsolationCorrectionAccessor(flavour,corr);
    if( !acc ) {
      return false;
    }
    if(!acc->isAvailable( *this) ) {
      return  false;
    }
    // Retrieve the value:
    value = ( *acc )( *this );
    return true;
  }
  
  float Egamma_v1::isolationTrackCorrection(const Iso::IsolationFlavour flavour, const Iso::IsolationTrackCorrection corr) const{
    
    SG::AuxElement::Accessor< float >* acc = getIsolationCorrectionAccessor(flavour,corr);
    if( !acc ) throw std::runtime_error( "Unknown/Unavailable Isolation correction requested" );
    return  ( *acc )( *this );
  }
  
  bool Egamma_v1::setIsolationTrackCorrection(float value, const Iso::IsolationFlavour flavour, const Iso::IsolationTrackCorrection corr){
    SG::AuxElement::Accessor< float >* acc = getIsolationCorrectionAccessor(flavour,corr);
    if( !acc ) return false;
294
295
296
    // Set the value:
    ( *acc )( *this ) = value;
    return true;
297
298
  }

299
  bool Egamma_v1::isolationCorrectionBitset( std::bitset<32>& value, const Iso::IsolationFlavour flavour ) const{
300
301
302
303
304
305
306
307
   SG::AuxElement::Accessor< uint32_t >* acc = getIsolationCorrectionBitsetAccessor( flavour );
    if( !acc ) {
      return false;
    }
    if(!acc->isAvailable( *this) ) {
      return  false;
    }
    // Retrieve the value:
308
    value =  std::bitset<32>(( *acc )( *this ));
309
310
311
    return true;
  }

312
  std::bitset<32> Egamma_v1::isolationCorrectionBitset(const Iso::IsolationFlavour flavour ) const{
313
314
   SG::AuxElement::Accessor< uint32_t >* acc = getIsolationCorrectionBitsetAccessor( flavour );
    if( !acc ) throw std::runtime_error( "Unknown/Unavailable Isolation BitSet requested" );
315
    return   std::bitset<32>(( *acc )( *this ));
316
317
318
319
320
321
322
323
324
325
  }

  bool Egamma_v1::setIsolationCorrectionBitset(uint32_t value, const Iso::IsolationFlavour flavour ) {
   SG::AuxElement::Accessor< uint32_t >* acc = getIsolationCorrectionBitsetAccessor( flavour );
    if( !acc ) return false;
    // Set the value:
    ( *acc )( *this ) = value;
    return true;
  }

326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
  ////////////////////////////////////////////////////
  /// Implementation of the CaloCluster accessor functions
  size_t Egamma_v1::nCaloClusters() const {

     static SG::AuxElement::Accessor< Egamma_v1::CLELVec_t >
        clusterAcc( "caloClusterLinks" );

     if( clusterAcc.isAvailable( *this ) ) {
        return clusterAcc( *this ).size();
     }
     return 0;
  }

  const xAOD::CaloCluster* Egamma_v1::caloCluster( size_t index ) const {
    
     if( index >= nCaloClusters() ) {
        return 0;
     }
     const CLELVec_t& cls = caloClusterLinks();
     if( ! cls[ index ].isValid() ) {
        return 0;
     }
     return *( cls[ index ] );
  }

  const ElementLink< CaloClusterContainer >&
  Egamma_v1::caloClusterLink( size_t index ) const {

     if( index >= nCaloClusters() ) {
        static const ElementLink< CaloClusterContainer > dummy;
        return dummy;
     }
     return caloClusterLinks()[ index ];
  }

  AUXSTORE_OBJECT_SETTER_AND_GETTER( Egamma_v1, Egamma_v1::CLELVec_t,
                                     caloClusterLinks, setCaloClusterLinks )

  ///////////

  bool Egamma_v1::isGoodOQ(uint32_t mask) const {
    static Accessor< uint32_t > acc( "OQ" );
    uint32_t OQ = acc( *this );
369
    return (OQ & mask)==0;
370
  }
371
372
373
374
375

  uint32_t Egamma_v1::OQ() const{
    static Accessor< uint32_t > acc( "OQ" );
    return acc( *this) ;
  }
376
377
378
379
380
381
  
  void Egamma_v1::setOQ(uint32_t newOQ) {
    static Accessor< uint32_t > acc( "OQ" );
    acc( *this) = newOQ;
  }

382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
  /////////// 

  ///Selectors / isEM and all that 

  ///First with enums (static accessor no lookup => faster but less flexible)
  bool Egamma_v1::passSelection(bool&  value, const xAOD::EgammaParameters::SelectionMenu menu ) const {
    SG::AuxElement::Accessor< char >* acc = selectionMenuAccessorV1( menu );
    if( !acc ) {
      return false;
    }
    if(!acc->isAvailable( *this) ) { 
      return  false;
    }
    value= (*acc)( *this );
    return true;
  }

  bool Egamma_v1::passSelection(const xAOD::EgammaParameters::SelectionMenu menu  ) const {
    SG::AuxElement::Accessor< char >* acc = selectionMenuAccessorV1( menu );
    if(!acc ) throw std::runtime_error( "Unknown/Unavailable bool selection menu requested" );
    return (*acc)( *this );
  }

  void Egamma_v1::setPassSelection(bool value, const xAOD::EgammaParameters::SelectionMenu menu){
    SG::AuxElement::Accessor< char >* acc = selectionMenuAccessorV1( menu );
    ( *acc )( *this )=value;
    return;
  }

  bool Egamma_v1::selectionisEM(unsigned int&  value, const xAOD::EgammaParameters::SelectionisEM isEM) const {
    SG::AuxElement::Accessor< unsigned int >* acc = selectionisEMAccessorV1( isEM );
    if(!acc ) {
      return false;
    }    
    if(!acc->isAvailable( *this) ) { 
      return  false;
    }
    value= (*acc)( *this );
    return true;
  }

  unsigned int Egamma_v1::selectionisEM(const xAOD::EgammaParameters::SelectionisEM isEM) const {
    SG::AuxElement::Accessor< unsigned int >* acc = selectionisEMAccessorV1( isEM );
    if(!acc ) throw std::runtime_error( "Unknown/Unavailable unsigned int isEM requested" );
    return (*acc)( *this );
  }

  void Egamma_v1::setSelectionisEM(unsigned int value, const xAOD::EgammaParameters::SelectionisEM isEM){
    SG::AuxElement::Accessor< unsigned int >* acc = selectionisEMAccessorV1( isEM );
    ( *acc )( *this )=value;
    return;
  }
434
435
  /////////////////////////////////////////////////////////////////////////
  ///Then with strings (full flexibility when adding new menus dynamically)
436
437
  bool Egamma_v1::passSelection(bool&  value, const std::string& menu ) const {
    SG::AuxElement::Accessor< char > acc( menu );
438
    if(!acc.isAvailable( *this) ) { 
439
440
      return  false;
    }
441
442
443
444
    value= (acc)( *this );
    return true;
  }

445
446
447
448
449
  bool Egamma_v1::passSelection(const std::string& menu ) const {
    SG::AuxElement::Accessor< char > acc( menu );
    return (acc)( *this );
  }

450
451
452
453
454
455
  void Egamma_v1::setPassSelection(bool value, const std::string& menu){
    SG::AuxElement::Accessor< char > acc( menu );
    ( acc )( *this )=value;
    return;
  }

456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
  bool Egamma_v1::selectionisEM(unsigned int&  value, const std::string& isEM) const{
    SG::AuxElement::Accessor< unsigned int > acc( isEM );
    if(!acc.isAvailable( *this) ) { 
      return  false;
    }
    value= (acc)( *this );
    return true;
  }

  unsigned int Egamma_v1::selectionisEM(const std::string& isEM) const{
    SG::AuxElement::Accessor< unsigned int > acc( isEM );
    return (acc)( *this );
  }

  void Egamma_v1::setSelectionisEM(unsigned int value, const std::string& isEM){
    SG::AuxElement::Accessor< unsigned int > acc( isEM );
    ( acc )( *this )=value;
    return;
  }

  bool Egamma_v1::likelihoodValue(float&  value, const std::string& LHValue/*=std::string("LHValue")*/) const{
    SG::AuxElement::Accessor<float> acc( LHValue );
    if(!acc.isAvailable( *this) ) { 
      return  false;
    }
    value= (acc)( *this );
    return true;
  }

  float Egamma_v1::likelihoodValue(const std::string& LHValue/*=std::string("LHValue")*/) const{
    SG::AuxElement::Accessor< float > acc( LHValue );
    return (acc)( *this );
  }

  void Egamma_v1::setLikelihoodValue(float value, const std::string& LHValue/*=std::string("LHValue")*/){
    SG::AuxElement::Accessor<float> acc( LHValue);
    ( acc )( *this )=value;
    return;
  }
 
496
497
498
} // namespace xAOD

//  LocalWords:  const el hasStore makePrivateStore