ATLAS Offline Software
NotMatch.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  * NotMatch.cpp
6  * Created by Joerg Stelzer / V Sorin on 9/16/14.
7  *
8  * @brief algorithm calculates the phi-distance between one or two lists and applies delta-phi criteria
9  *
10  * @param NumberLeading
11 **********************************/
12 
13 #include <cmath>
14 
16 #include "L1TopoCommon/Exception.h"
18 
19 REGISTER_ALG_TCS(NotMatch)
20 
21 
22 // not the best solution but we will move to athena where this comes for free
23 #define LOG cout << "TCS::NotMatch: "
24 
25 
27 {
28  defineParameter("InputWidth1", 9);
29  defineParameter("InputWidth2", 9);
30  defineParameter("MaxTob1", 0);
31  defineParameter("MaxTob2", 0);
32  defineParameter("NumResultBits", 2);
33  defineParameter("MinET1",1,0);
34  defineParameter("MinET2",1,0);
35  defineParameter("EtaMin1",0,0);
36  defineParameter("EtaMax1",49,0);
37  defineParameter("EtaMin2",0,0);
38  defineParameter("EtaMax2",49,0);
39  defineParameter("DRCut",0,0);
40  defineParameter("MinET1",1,1);
41  defineParameter("MinET2",1,1);
42  defineParameter("EtaMin1",0,1);
43  defineParameter("EtaMax1",49,1);
44  defineParameter("EtaMin2",0,1);
45  defineParameter("EtaMax2",49,1);
46  defineParameter("DRCut",0,1);
48 }
49 
51 
52 
55  p_NumberLeading1 = parameter("InputWidth1").value();
56  p_NumberLeading2 = parameter("InputWidth2").value();
57  if(parameter("MaxTob1").value() > 0) p_NumberLeading1 = parameter("MaxTob1").value();
58  if(parameter("MaxTob2").value() > 0) p_NumberLeading2 = parameter("MaxTob2").value();
59  for(unsigned int i=0; i<numberOutputBits(); ++i) {
60  p_MinET1[i] = parameter("MinET1",i).value();
61  p_MinET2[i] = parameter("MinET2",i).value();
62  TRG_MSG_INFO("MinET1 : " << p_MinET1[i]);
63  TRG_MSG_INFO("MinET2 : " << p_MinET2[i]);
64 
65  p_EtaMin1[i] = parameter("EtaMin1",i).value();
66  p_EtaMin2[i] = parameter("EtaMin2",i).value();
67  TRG_MSG_INFO("MinEta1 : " << p_EtaMin1[i]);
68  TRG_MSG_INFO("MinEta2 : " << p_EtaMin2[i]);
69 
70  p_EtaMax1[i] = parameter("EtaMax1",i).value();
71  p_EtaMax2[i] = parameter("EtaMax2",i).value();
72  TRG_MSG_INFO("MinEta1 : " << p_EtaMax1[i]);
73  TRG_MSG_INFO("MinEta2 : " << p_EtaMax2[i]);
74 
75  p_DRCut[i] = parameter("DRCut",i).value();
76  TRG_MSG_INFO("DRCut : " << p_DRCut[i]);
77  }
78  TRG_MSG_INFO("Maxtob 1 : " << p_NumberLeading1);
79  TRG_MSG_INFO("Maxtob 2 : " << p_NumberLeading2);
80  TRG_MSG_INFO("number output : " << numberOutputBits());
81  return StatusCode::SUCCESS;
82 }
83 
85 TCS::NotMatch::processBitCorrect( const std::vector<TCS::TOBArray const *> & input,
86  const std::vector<TCS::TOBArray *> & output,
87  Decision & decision )
88 {
89  if( input.size() == 2) {
90  bool matched = false;
91  unsigned int deltaR2= 999;
92  for(unsigned int i=0; i<numberOutputBits(); ++i) {
93  bool all_unmatched = true;
94  std::vector<GenericTOB*> unmatched_tobs;
95  for( TOBArray::const_iterator tob1 = input[0]->begin();
96  tob1 != input[0]->end() && distance(input[0]->begin(), tob1) < p_NumberLeading1;
97  ++tob1)
98  {
99  if (p_NumberLeading1 < input[0]->size()) {
100  TCS::TOBArray::const_iterator tob1_plus1 = tob1; ++tob1_plus1;
101  if ((*tob1)->Et() == (*tob1_plus1)->Et() && distance(input[0]->begin(), tob1) == p_NumberLeading1 - 1) {
102  for(unsigned int i=0; i<numberOutputBits(); ++i) {
103  output[i]->setAmbiguityFlag(true);
104  }
105  }
106  }
107  if( parType_t((*tob1)->Et()) <= p_MinET1[i]) continue; // ET cut
108  if( parType_t(std::abs((*tob1)->eta())) > p_EtaMax1[i] ) continue; // Eta cut
109  if( parType_t(std::abs((*tob1)->eta())) < p_EtaMin1[i] ) continue; // Eta cut
110  matched = false;
111  deltaR2 = 999;
112  for( TCS::TOBArray::const_iterator tob2 = input[1]->begin();
113  tob2 != input[1]->end() && distance(input[1]->begin(), tob2) < p_NumberLeading2 && matched != true ;
114  ++tob2) {
115  if( parType_t((*tob2)->Et()) <= p_MinET2[i]) continue; // ET cut
116  if( parType_t(std::abs((*tob2)->eta())) > p_EtaMax2[i] ) continue; // Eta cut
117  if( parType_t(std::abs((*tob2)->eta())) < p_EtaMin2[i] ) continue; // Eta cut
118  // test DeltaR2Min, DeltaR2Max
119  deltaR2 = calcDeltaR2BW( *tob1, *tob2 );
120  if (deltaR2 <= p_DRCut[i]) matched = true;
121  } // for(tob2)
122  // protection against no jets
123  if (deltaR2 == 999) matched = true;
124  if(not matched) unmatched_tobs.push_back(*tob1);
125  all_unmatched = all_unmatched and not matched;
126  } // for(tob1)
127  const bool accept = all_unmatched and unmatched_tobs.size()>0;
128  if(accept){
129  decision.setBit(i, true);
130  for(const auto tob : unmatched_tobs)
131  output[i]->push_back(TCS::CompositeTOB(tob));
132  }
133  TRG_MSG_DEBUG("Decision " << i << ": " << (accept?"pass":"fail"));
134  } // for(i)
135  } else {
136  TCS_EXCEPTION("NotMatch alg must have 2 inputs, but got " << input.size());
137  }
139 
140 }
141 
143 TCS::NotMatch::process( const std::vector<TCS::TOBArray const *> & input,
144  const std::vector<TCS::TOBArray *> & output,
145  Decision & decision )
146 {
147  if( input.size() == 2) {
148  bool matched = false;
149  unsigned int deltaR2= 999;
150  for(unsigned int i=0; i<numberOutputBits(); ++i) {
151  bool all_unmatched = true;
152  std::vector<GenericTOB*> unmatched_tobs;
153  for( TOBArray::const_iterator tob1 = input[0]->begin();
154  tob1 != input[0]->end() && distance(input[0]->begin(), tob1) < p_NumberLeading1;
155  ++tob1)
156  {
157  if( parType_t((*tob1)->Et()) <= p_MinET1[i]) continue; // ET cut
158  if( parType_t(std::abs((*tob1)->eta())) > p_EtaMax1[i] ) continue; // Eta cut
159  if( parType_t(std::abs((*tob1)->eta())) < p_EtaMin1[i] ) continue; // Eta cut
160  matched = false;
161  deltaR2 = 999;
162  for( TCS::TOBArray::const_iterator tob2 = input[1]->begin();
163  tob2 != input[1]->end() && distance(input[1]->begin(), tob2) < p_NumberLeading2 && matched != true ;
164  ++tob2) {
165  if( parType_t((*tob2)->Et()) <= p_MinET2[i]) continue; // ET cut
166  if( parType_t(std::abs((*tob2)->eta())) > p_EtaMax2[i] ) continue; // Eta cut
167  if( parType_t(std::abs((*tob2)->eta())) < p_EtaMin2[i] ) continue; // Eta cut
168  // test DeltaR2Min, DeltaR2Max
169  deltaR2 = calcDeltaR2( *tob1, *tob2 );
170  if (deltaR2 <= p_DRCut[i]) matched = true;
171  } // for(tob2)
172  // protection against no jets
173  if (deltaR2 == 999) matched = true;
174  if(not matched) unmatched_tobs.push_back(*tob1);
175  all_unmatched = all_unmatched and not matched;
176  } // for(tob1)
177  const bool accept = all_unmatched and unmatched_tobs.size()>0;
178  if(accept){
179  decision.setBit(i, true);
180  for(const auto tob : unmatched_tobs)
181  output[i]->push_back(TCS::CompositeTOB(tob));
182  }
183  TRG_MSG_DEBUG("Decision " << i << ": " << (accept?"pass":"fail"));
184  } // for(i)
185  } else {
186  TCS_EXCEPTION("NotMatch alg must have 2 inputs, but got " << input.size());
187  }
189 }
TCS::StatusCode::SUCCESS
@ SUCCESS
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/L1TopoCommon/StatusCode.h:17
TCS::parType_t
uint32_t parType_t
Definition: Parameter.h:22
TCS::DataArrayImpl< GenericTOB >::const_iterator
data_t::const_iterator const_iterator
Definition: DataArrayImpl.h:18
TCS::NotMatch::initialize
virtual StatusCode initialize()
Definition: NotMatch.cxx:54
CutsMETMaker::accept
StatusCode accept(const xAOD::Muon *mu)
Definition: CutsMETMaker.cxx:18
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
athena.value
value
Definition: athena.py:122
Decision.h
xAOD::P4Helpers::deltaR2
double deltaR2(double rapidity1, double phi1, double rapidity2, double phi2)
from bare rapidity,phi
Definition: xAODP4Helpers.h:111
TCS::NotMatch::NotMatch
NotMatch(const std::string &name)
Definition: NotMatch.cxx:26
TCS::DecisionAlg
Definition: Trigger/TrigT1/L1Topo/L1TopoInterfaces/L1TopoInterfaces/DecisionAlg.h:22
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
TCS::Decision::setBit
void setBit(unsigned int index, bool value)
Definition: L1Topo/L1TopoInterfaces/Root/Decision.cxx:12
lumiFormat.i
int i
Definition: lumiFormat.py:92
TCS::ConfigurableAlg::defineParameter
void defineParameter(const std::string &name, TCS::parType_t value)
Definition: ConfigurableAlg.cxx:201
TCS::CompositeTOB
Definition: CompositeTOB.h:16
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
TCS_EXCEPTION
#define TCS_EXCEPTION(MSG)
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/L1TopoCommon/Exception.h:14
TCS::Decision
Definition: L1Topo/L1TopoInterfaces/L1TopoInterfaces/Decision.h:19
TRG_MSG_INFO
#define TRG_MSG_INFO(x)
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStreamMacros.h:27
merge.output
output
Definition: merge.py:17
NotMatch.h
REGISTER_ALG_TCS
#define REGISTER_ALG_TCS(CLASS)
Definition: AlgFactory.h:62
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
TCS::NotMatch::process
virtual StatusCode process(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison)
Definition: NotMatch.cxx:143
python.ElectronD3PDObject.matched
matched
Definition: ElectronD3PDObject.py:138
TCS::DecisionAlg::setNumberOutputBits
void setNumberOutputBits(unsigned int numberOutputBits)
Definition: Trigger/TrigT1/L1Topo/L1TopoInterfaces/L1TopoInterfaces/DecisionAlg.h:40
Exception.h
Amg::distance
float distance(const Amg::Vector3D &p1, const Amg::Vector3D &p2)
calculates the distance between two point in 3D space
Definition: GeoPrimitivesHelpers.h:54
TCS::NotMatch::processBitCorrect
virtual StatusCode processBitCorrect(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison)
Definition: NotMatch.cxx:85
TRG_MSG_DEBUG
#define TRG_MSG_DEBUG(x)
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStreamMacros.h:25
TCS::StatusCode
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/L1TopoCommon/StatusCode.h:15
TCS::NotMatch::~NotMatch
virtual ~NotMatch()
Definition: NotMatch.cxx:50