TrigEgammaPrecisionElectronHypoTool.cxx 12.5 KB
Newer Older
1
/*
2
  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3
4
5
*/

#include <algorithm>
6
#include <cmath>
7
8
#include "TrigCompositeUtils/HLTIdentifier.h"
#include "TrigCompositeUtils/Combinators.h"
9
10
#include "TrigCompositeUtils/TrigCompositeUtils.h"
#include "TrigSteeringEvent/TrigRoiDescriptor.h"
Charles Burton's avatar
Charles Burton committed
11
#include "AthenaMonitoringKernel/Monitored.h"
12
#include "xAODEgamma/Electron.h"
13
#include "TrigEgammaPrecisionElectronHypoTool.h"
14

15
namespace TCU = TrigCompositeUtils;
16

17
TrigEgammaPrecisionElectronHypoTool::TrigEgammaPrecisionElectronHypoTool( const std::string& type, 
18
19
20
		    const std::string& name, 
		    const IInterface* parent ) 
  : base_class( type, name, parent ),
21
22
23
    m_decisionId( HLT::Identifier::fromToolName( name ) ) {
}

24

25
StatusCode TrigEgammaPrecisionElectronHypoTool::initialize()  
26
{
27
28
29
30
31
  ATH_MSG_DEBUG( "Initialization completed successfully"   );    
  ATH_MSG_DEBUG( "EtaBins        = " << m_etabin      );
  ATH_MSG_DEBUG( "ETthr          = " << m_eTthr    );
  ATH_MSG_DEBUG( "dPHICLUSTERthr = " << m_dphicluster );
  ATH_MSG_DEBUG( "dETACLUSTERthr = " << m_detacluster );
32
  ATH_MSG_DEBUG( "d0Cut          = " << m_d0 );
33
  
34
  if ( m_etabin.empty() ) {
35
36
37
38
39
    ATH_MSG_ERROR(  " There are no cuts set (EtaBins property is an empty list)" );
    return StatusCode::FAILURE;
  }

  unsigned int nEtaBin = m_etabin.size();
40
  ATH_CHECK( m_eTthr.size() == nEtaBin-1 );
41
42
43
44
45
46
47
48
49
50

  ATH_MSG_DEBUG( "Tool configured for chain/id: " << m_decisionId );

  if ( not m_monTool.name().empty() ) 
    CHECK( m_monTool.retrieve() );

  return StatusCode::SUCCESS;
}


51
bool TrigEgammaPrecisionElectronHypoTool::decide( const ITrigEgammaPrecisionElectronHypoTool::ElectronInfo& input) const {
52

Debottam Bakshi Gupta's avatar
Debottam Bakshi Gupta committed
53
  bool pass = true;
54
55

  auto ET           = Monitored::Scalar( "Et_em"   , -1.0 );
56
  auto dEta         = Monitored::Scalar( "dEta", -1. );
57
58
  auto dPhi         = Monitored::Scalar( "dPhi", -1. );
  auto etaBin       = Monitored::Scalar( "EtaBin", -1. );
59
  auto monEta       = Monitored::Scalar( "Eta", -99. );
60
  auto monPhi       = Monitored::Scalar( "Phi", -99. );
61
  auto PassedCuts   = Monitored::Scalar<int>( "CutCounter", -1 );
62
63
  auto mon_lhval    = Monitored::Scalar("LikelihoodRatio",   -99.);
  auto mon_mu       = Monitored::Scalar("mu",   -1.);
64
65
  auto mon_ptvarcone20 = Monitored::Scalar("ptvarcone20",   -99.);
  auto mon_relptvarcone20 = Monitored::Scalar("ptvarcone20",   -99.);
66
67
  auto mon_ptcone20 = Monitored::Scalar("ptcone20",   -99.);
  auto mon_relptcone20 = Monitored::Scalar("ptcone20",   -99.);
68
  auto trk_d0       = Monitored::Scalar("trk_d0",   -1.);
69
70
71
  auto monitorIt    = Monitored::Group( m_monTool, dEta, dPhi, 
                                        etaBin, monEta,
                                        monPhi,PassedCuts,mon_lhval,mon_mu, 
72
                                        mon_ptvarcone20, mon_relptvarcone20,
73
                                        mon_ptcone20, mon_relptcone20, trk_d0);
74
75

  // when leaving scope it will ship data to monTool
76
77
78
79
80
81
  PassedCuts = PassedCuts + 1; //got called (data in place)

  auto roiDescriptor = input.roi;


  if ( fabs( roiDescriptor->eta() ) > 2.6 ) {
82
83
      ATH_MSG_DEBUG( "REJECT The electron had eta coordinates beyond the EM fiducial volume : " << roiDescriptor->eta() << "; stop the chain now" );       
      return false;
84
85
86
87
88
89
90
91
92
  } 

  ATH_MSG_DEBUG( "; RoI ID = " << roiDescriptor->roiId()
  		 << ": Eta = " << roiDescriptor->eta()
  		 << ", Phi = " << roiDescriptor->phi() );

  // fill local variables for RoI reference position
  double etaRef = roiDescriptor->eta();
  double phiRef = roiDescriptor->phi();
93
  ATH_MSG_DEBUG("etaRef: "<<etaRef);
94
95
  // correct phi the to right range ( probably not needed anymore )   
  if ( fabs( phiRef ) > M_PI ) phiRef -= 2*M_PI; // correct phi if outside range
Debottam Bakshi Gupta's avatar
Debottam Bakshi Gupta committed
96
97
  
  ATH_MSG_DEBUG("AcceptAll: "<<m_acceptAll);
98

Debottam Bakshi Gupta's avatar
Debottam Bakshi Gupta committed
99
  if(!m_acceptAll){
100

Debottam Bakshi Gupta's avatar
Debottam Bakshi Gupta committed
101
102
     pass = false;
     auto pClus = input.electron->caloCluster();
103
  
Debottam Bakshi Gupta's avatar
Debottam Bakshi Gupta committed
104
     float absEta = fabs( pClus->eta() );
105
  
Debottam Bakshi Gupta's avatar
Debottam Bakshi Gupta committed
106
     ATH_MSG_DEBUG("absEta: "<<absEta);
107

Debottam Bakshi Gupta's avatar
Debottam Bakshi Gupta committed
108
109
     const int cutIndex = findCutIndex( absEta );
     ATH_MSG_DEBUG("cutIndex: "<<cutIndex);  
110
111

  
Debottam Bakshi Gupta's avatar
Debottam Bakshi Gupta committed
112
113
114
115
116
     dEta =  pClus->eta() - etaRef;
     //  Deal with angle diferences greater than Pi
     dPhi =  fabs( pClus->phi() - phiRef );
     dPhi = ( dPhi < M_PI ? dPhi : 2*M_PI - dPhi ); // TB why only <
     ET  = pClus->et();
117

Debottam Bakshi Gupta's avatar
Debottam Bakshi Gupta committed
118
     trk_d0 = std::abs(input.electron->trackParticle()->d0());
119

Debottam Bakshi Gupta's avatar
Debottam Bakshi Gupta committed
120
121
     // apply cuts: DeltaEta( clus-ROI )
     ATH_MSG_DEBUG( "Electron : eta="  << pClus->eta() 
122
123
124
                  << " roi eta=" << etaRef << " DeltaEta=" << dEta
                  << " cut: <"   << m_detacluster );

125
  
Debottam Bakshi Gupta's avatar
Debottam Bakshi Gupta committed
126
127
128
129
130
     if ( fabs( pClus->eta() - etaRef ) > m_detacluster ) {
       ATH_MSG_DEBUG("REJECT Electron a cut failed");
       return pass;
     }
     PassedCuts = PassedCuts + 1; //Deta
131
  
Debottam Bakshi Gupta's avatar
Debottam Bakshi Gupta committed
132
133
     // DeltaPhi( clus-ROI )
     ATH_MSG_DEBUG( ": phi="  << pClus->phi()
134
135
136
  		 << " roi phi="<< phiRef    << " DeltaPhi="<< dPhi
  		 << " cut: <"  << m_dphicluster );
  
Debottam Bakshi Gupta's avatar
Debottam Bakshi Gupta committed
137
138
139
140
141
142
143
144
145
146
147
148
149
150
     if( dPhi > m_dphicluster ) {
        ATH_MSG_DEBUG("REJECT Clsuter dPhi cut failed");
        return pass;
     }
     PassedCuts = PassedCuts + 1; //DPhi

     // eta range
     if ( cutIndex == -1 ) {  // VD
       ATH_MSG_DEBUG( "Electron : " << absEta << " outside eta range " << m_etabin[m_etabin.size()-1] );
       return pass;
     } else { 
       ATH_MSG_DEBUG( "eta bin used for cuts " << cutIndex );
     }
     PassedCuts = PassedCuts + 1; // passed eta cut
151
  
Debottam Bakshi Gupta's avatar
Debottam Bakshi Gupta committed
152
153
154
155
156
157
158
     // ET_em
     ATH_MSG_DEBUG( "Electron: ET_em=" << ET << " cut: >"  << m_eTthr[cutIndex] );
     if ( ET < m_eTthr[cutIndex] ) {
       ATH_MSG_DEBUG("REJECT et cut failed");
       return pass;
     }
     PassedCuts = PassedCuts + 1; // ET_em
159
  
Debottam Bakshi Gupta's avatar
Debottam Bakshi Gupta committed
160
161
162
163
164
165
166
167
168
169
     // d0 for LRT
     if (m_d0 and m_d0>0.)
     {
       ATH_MSG_DEBUG( "Electron: trk_d0=" << trk_d0 << " cut: >"  << m_d0 );
       if ( trk_d0 < m_d0 ) {
         ATH_MSG_DEBUG("REJECT d0 cut failed");
         return pass;
       }
       PassedCuts = PassedCuts + 1; // d0
     }
170

171
 
Debottam Bakshi Gupta's avatar
Debottam Bakshi Gupta committed
172
173
174
175
176
     // This is the last step. So pass is going to be the result of LH
     // get average luminosity information to calculate LH
     if(input.valueDecorator.count("avgmu")){
        mon_mu = input.valueDecorator.at("avgmu");
     }
177

Debottam Bakshi Gupta's avatar
Debottam Bakshi Gupta committed
178
     float Rhad1(0), Rhad(0), Reta(0), Rphi(0), e277(0), weta2c(0), //emax2(0), 
179
180
        Eratio(0), DeltaE(0), f1(0), weta1c(0), wtot(0), fracm(0);

181
182
     float ptvarcone20(999), ptcone20(999), ptcone30(999), ptcone40(999), etcone20(999), etcone30(999), 
        etcone40(999), topoetcone20(999), topoetcone30(999), topoetcone40(999), relptcone20(999), relptvarcone20(999);
183

184
     bool ispt20 = input.electron->isolationValue(ptvarcone20, xAOD::Iso::ptvarcone20);
Fernando Monticelli's avatar
Fernando Monticelli committed
185
     if (!ispt20) {
186
       ATH_MSG_WARNING("ptvarcone20 not available. Will not cut on isolation");
Fernando Monticelli's avatar
Fernando Monticelli committed
187
     }
188

Debottam Bakshi Gupta's avatar
Debottam Bakshi Gupta committed
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
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
     // variables based on HCAL
     // transverse energy in 1st scintillator of hadronic calorimeter/ET
     input.electron->showerShapeValue(Rhad1, xAOD::EgammaParameters::Rhad1);
     // transverse energy in hadronic calorimeter/ET
     input.electron->showerShapeValue(Rhad, xAOD::EgammaParameters::Rhad);

     // variables based on S2 of EM CAL
     // E(7*7) in 2nd sampling
     input.electron->showerShapeValue(e277, xAOD::EgammaParameters::e277);
     // E(3*7)/E(7*7) in 2nd sampling
     input.electron->showerShapeValue(Reta, xAOD::EgammaParameters::Reta);
     // E(3*3)/E(3*7) in 2nd sampling
     input.electron->showerShapeValue(Rphi, xAOD::EgammaParameters::Rphi);
     // shower width in 2nd sampling
     input.electron->showerShapeValue(weta2c, xAOD::EgammaParameters::weta2);

     // variables based on S1 of EM CAL
     // fraction of energy reconstructed in the 1st sampling
     input.electron->showerShapeValue(f1, xAOD::EgammaParameters::f1);
     // shower width in 3 strips in 1st sampling
     input.electron->showerShapeValue(weta1c, xAOD::EgammaParameters::weta1);
     // E of 2nd max between max and min in strips [NOT USED]
     // eg->showerShapeValue(emax2, xAOD::EgammaParameters::e2tsts1);
     // (E of 1st max in strips-E of 2nd max)/(E of 1st max+E of 2nd max)
     input.electron->showerShapeValue(Eratio, xAOD::EgammaParameters::Eratio);
     // E(2nd max)-E(min) in strips
     input.electron->showerShapeValue(DeltaE, xAOD::EgammaParameters::DeltaE);
     // total shower width in 1st sampling
     input.electron->showerShapeValue(wtot, xAOD::EgammaParameters::wtots1);
     // E(+/-3)-E(+/-1)/E(+/-1)
     input.electron->showerShapeValue(fracm, xAOD::EgammaParameters::fracs1);

     input.electron->isolationValue(ptcone20, xAOD::Iso::ptcone20);

     input.electron->isolationValue(ptcone30, xAOD::Iso::ptcone30);

     input.electron->isolationValue(ptcone40, xAOD::Iso::ptcone40);

     input.electron->isolationValue(etcone20, xAOD::Iso::etcone20);

     input.electron->isolationValue(etcone30, xAOD::Iso::etcone30);

     input.electron->isolationValue(etcone40, xAOD::Iso::etcone40);

     input.electron->isolationValue(topoetcone20, xAOD::Iso::topoetcone20);

     input.electron->isolationValue(topoetcone30, xAOD::Iso::topoetcone30);

     input.electron->isolationValue(topoetcone40, xAOD::Iso::topoetcone40);

     ATH_MSG_DEBUG(" electron Cluster Et "<<ET);
     ATH_MSG_DEBUG( "  Rhad1  " << Rhad1 ) ;
     ATH_MSG_DEBUG( "  Rhad   " << Rhad ) ;
     ATH_MSG_DEBUG( "  e277   " << e277 ) ;
     ATH_MSG_DEBUG( "  Reta   " << Reta ) ;
     ATH_MSG_DEBUG( "  Rphi   " << Rphi ) ;
     ATH_MSG_DEBUG( "  weta2c " << weta2c ) ;
     ATH_MSG_DEBUG( "  f1     " << f1 ) ;
     ATH_MSG_DEBUG( "  weta1c " << weta1c ) ;
     ATH_MSG_DEBUG( "  Eratio " << Eratio ) ;
     ATH_MSG_DEBUG( "  DeltaE " << DeltaE ) ;
     ATH_MSG_DEBUG( "  wtot   " << wtot ) ;
     ATH_MSG_DEBUG( "  fracm  " << fracm ) ;
     ATH_MSG_DEBUG( " trackPT "<<input.electron->trackParticle()->pt());
     ATH_MSG_DEBUG( " d0      "<<input.electron->trackParticle()->d0());
     ATH_MSG_DEBUG( " z0      "<<input.electron->trackParticle()->z0());
255
     ATH_MSG_DEBUG( " ptvarcone20 " << ptvarcone20 ) ;
Debottam Bakshi Gupta's avatar
Debottam Bakshi Gupta committed
256
257
258
259
260
261
262
263
264
265
266
267
268
269
     ATH_MSG_DEBUG( " ptcone20 " << ptcone20 ) ;
     ATH_MSG_DEBUG( " ptcone30 " << ptcone30 ) ;
     ATH_MSG_DEBUG( " ptcone40 " << ptcone40 ) ;
     ATH_MSG_DEBUG( " etcone20 " << etcone20 ) ;
     ATH_MSG_DEBUG( " etcone30 " << etcone30 ) ;
     ATH_MSG_DEBUG( " etcone40 " << etcone40 ) ;
     ATH_MSG_DEBUG( " topoetcone20 " << topoetcone20 ) ;
     ATH_MSG_DEBUG( " topoetcone30 " << topoetcone30 ) ;
     ATH_MSG_DEBUG( " topoetcone40 " << topoetcone40 ) ;
     // Monitor showershapes
     mon_ptcone20 = ptcone20;
     relptcone20 = ptcone20/input.electron->pt();
     ATH_MSG_DEBUG("relptcone20 = " <<relptcone20  );
     mon_relptcone20 = relptcone20;
270
271
272
273
274
   
     mon_ptvarcone20 = ptvarcone20;
     relptvarcone20 = ptvarcone20/input.electron->pt();
     ATH_MSG_DEBUG("relptvarcone20 = " <<relptvarcone20  );
     mon_relptvarcone20 = relptvarcone20;
Debottam Bakshi Gupta's avatar
Debottam Bakshi Gupta committed
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
     ATH_MSG_DEBUG("m_RelPtConeCut = " << m_RelPtConeCut );
   
     // Only for LH
     if( input.valueDecorator.count(m_pidName+"LHValue")){
        mon_lhval = input.valueDecorator.at(m_pidName+"LHValue");
     }

     // Should works for DNN and LH
     if( input.pidDecorator.count(m_pidName) )
     {
       pass = input.pidDecorator.at(m_pidName);
     }     
     // Evaluating lh *after* retrieving variables for monitoing and debuging purposes
     ATH_MSG_DEBUG("AthenaLHSelectorTool: TAccept = " << pass);
     if ( !pass ){
       ATH_MSG_DEBUG("REJECT Likelihood failed");
       return pass;
     } else {
293
      ATH_MSG_DEBUG("ACCEPT Likelihood passed");
Debottam Bakshi Gupta's avatar
Debottam Bakshi Gupta committed
294
295
296
297
298
299
300
301
302
303
304
     }

     // Check if need to apply isolation
     // First check logic. if cut is very negative, then no isolation cut is defined
     // if m_RelPtConeCut <-100 then hypo is configured not to apply isolation
     if (m_RelPtConeCut < -100){
       ATH_MSG_DEBUG(" not applying isolation. Returning NOW");
       ATH_MSG_DEBUG("TAccept = " << pass);
       return pass;
     }
     // Then, It will pass if relptcone20 is less than cut:
305
     pass = (relptvarcone20 < m_RelPtConeCut);
Debottam Bakshi Gupta's avatar
Debottam Bakshi Gupta committed
306
307
308
     //

  }  // end of if(!m_acceptAll) 
309
310
311
312
  ATH_MSG_DEBUG( "pass = " << pass );
  return pass;
}

313
314


315
int TrigEgammaPrecisionElectronHypoTool::findCutIndex( float eta ) const {
316
317
318
319
320
321
322
323
324
  const float absEta = std::abs(eta);
  auto binIterator = std::adjacent_find( m_etabin.begin(), m_etabin.end(), [=](float left, float right){ return left < absEta and absEta < right; }  );
  if ( binIterator == m_etabin.end() ) {
    return -1;
  }
  return  binIterator - m_etabin.begin();
}


325
StatusCode TrigEgammaPrecisionElectronHypoTool::decide( std::vector<ElectronInfo>& input)  const {
326
  for ( auto& i: input ) {
327
    if ( TCU::passed ( m_decisionId.numeric(), i.previousDecisionIDs ) ) {
328
      if ( decide( i ) ) {
329
        TCU::addDecisionID( m_decisionId, i.decision );
330
331
332
333
334
      }
    }
  }
  return StatusCode::SUCCESS;
}