ATLAS Offline Software
Loading...
Searching...
No Matches
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
18
19REGISTER_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());
82}
83
85TCS::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
143TCS::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}
#define REGISTER_ALG_TCS(CLASS)
Definition AlgFactory.h:62
const Parameter & parameter(const std::string &parameterName) const
const std::string & name() const
unsigned int calcDeltaR2BW(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
void defineParameter(const std::string &name, TCS::parType_t value)
unsigned int calcDeltaR2(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
data_t::const_iterator const_iterator
void setNumberOutputBits(unsigned int numberOutputBits)
Definition DecisionAlg.h:40
DecisionAlg(const std::string &name)
Definition DecisionAlg.h:25
unsigned int numberOutputBits() const
Definition DecisionAlg.h:39
void setBit(unsigned int index, bool value)
Definition Decision.cxx:12
NotMatch(const std::string &name)
Definition NotMatch.cxx:26
virtual StatusCode process(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison)
Definition NotMatch.cxx:143
parType_t p_NumberLeading1
Definition NotMatch.h:33
virtual ~NotMatch()
Definition NotMatch.cxx:50
parType_t p_DRCut[2]
Definition NotMatch.h:41
parType_t p_MinET2[2]
Definition NotMatch.h:38
parType_t p_EtaMin2[2]
Definition NotMatch.h:39
parType_t p_EtaMin1[2]
Definition NotMatch.h:36
parType_t p_MinET1[2]
Definition NotMatch.h:35
parType_t p_NumberLeading2
Definition NotMatch.h:34
parType_t p_EtaMax1[2]
Definition NotMatch.h:37
parType_t p_EtaMax2[2]
Definition NotMatch.h:40
virtual StatusCode processBitCorrect(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison)
Definition NotMatch.cxx:85
virtual StatusCode initialize()
Definition NotMatch.cxx:54
uint32_t parType_t
Definition Parameter.h:22