ATLAS Offline Software
Loading...
Searching...
No Matches
DeltaRSqrIncl2.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
3*/
4/*********************************
5 * DeltaRSqrIncl2.cpp
6 * Created by Joerg Stelzer / V Sorin on 9/16/14.
7 *
8 * @brief algorithm calculates the R2-distance between two lists and applies dR criteria
9 *
10 * @param NumberLeading
11**********************************/
12
13#include <cmath>
14
19
20REGISTER_ALG_TCS(DeltaRSqrIncl2)
21
22
23// not the best solution but we will move to athena where this comes for free
24#define LOG std::cout << "TCS::DeltaRSqrIncl2: "
25
27{
28 defineParameter("InputWidth1", 9);
29 defineParameter("InputWidth2", 9);
30 defineParameter("MaxTob1", 0);
31 defineParameter("MaxTob2", 0);
32 defineParameter("NumResultBits", 3);
33 defineParameter("MinET1",1,0);
34 defineParameter("MinET2",1,0);
35 defineParameter("DeltaRMin", 0, 0);
36 defineParameter("DeltaRMax", 0, 0);
37 defineParameter("MinET1",1,1);
38 defineParameter("MinET2",1,1);
39 defineParameter("DeltaRMin", 0, 1);
40 defineParameter("DeltaRMax", 0, 1);
41 defineParameter("MinET1",1,2);
42 defineParameter("MinET2",1,2);
43 defineParameter("DeltaRMin", 0, 2);
44 defineParameter("DeltaRMax", 0, 2);
46}
47
49
50
53
54 p_NumberLeading1 = parameter("InputWidth1").value();
55 p_NumberLeading2 = parameter("InputWidth2").value();
56 if(parameter("MaxTob1").value() > 0) p_NumberLeading1 = parameter("MaxTob1").value();
57 if(parameter("MaxTob2").value() > 0) p_NumberLeading2 = parameter("MaxTob2").value();
58
59 for(unsigned int i=0; i<numberOutputBits(); ++i) {
60 p_DeltaRMin[i] = parameter("DeltaRMin", i).value();
61 p_DeltaRMax[i] = parameter("DeltaRMax", i).value();
62 p_MinET1[i] = parameter("MinET1",i).value();
63 p_MinET2[i] = parameter("MinET2",i).value();
64 TRG_MSG_INFO("DeltaRMin" << i << " : " << p_DeltaRMin[i]);
65 TRG_MSG_INFO("DeltaRMax" << i << " : " << p_DeltaRMax[i]);
66
67 TRG_MSG_INFO("MinET1 : " << p_MinET1[i]);
68 TRG_MSG_INFO("MinET2 : " << p_MinET2[i]);
69
70 }
71
72 TRG_MSG_INFO("NumberLeading1 : " << p_NumberLeading1);
73 TRG_MSG_INFO("NumberLeading2 : " << p_NumberLeading2);
74
75 TRG_MSG_INFO("number output : " << numberOutputBits());
76
77 // book histograms
78 for(unsigned int i=0; i<numberOutputBits(); ++i) {
79 std::string hname_accept = "hDeltaRSqrIncl2_accept_bit"+std::to_string((int)i);
80 std::string hname_reject = "hDeltaRSqrIncl2_reject_bit"+std::to_string((int)i);
81 // dR
82 bookHist(m_histAccept, hname_accept, "DR", 100, sqrt(p_DeltaRMin[i]), sqrt(p_DeltaRMax[i]));
83 bookHist(m_histReject, hname_reject, "DR", 100, sqrt(p_DeltaRMin[i]), sqrt(p_DeltaRMax[i]));
84 }
85
87}
88
89
91TCS::DeltaRSqrIncl2::processBitCorrect( const std::vector<TCS::TOBArray const *> & input,
92 const std::vector<TCS::TOBArray *> & output,
93 Decision & decision )
94{
95
96 if( input.size() == 2) {
97
98 for( TOBArray::const_iterator tob1 = input[0]->begin();
99 tob1 != input[0]->end() && distance(input[0]->begin(), tob1) < p_NumberLeading1;
100 ++tob1)
101 {
102 for( TCS::TOBArray::const_iterator tob2 = input[1]->begin();
103 tob2 != input[1]->end() && distance(input[1]->begin(), tob2) < p_NumberLeading2;
104 ++tob2) {
105 // test DeltaR2Min, DeltaR2Max
106 unsigned int deltaR2 = calcDeltaR2BW( *tob1, *tob2 );
107 TRG_MSG_DEBUG("Jet1 = " << **tob1 << ", Jet2 = " << **tob2 << ", deltaR2 = " << deltaR2);
108 for(unsigned int i=0; i<numberOutputBits(); ++i) {
109 bool accept = false;
110 if( parType_t((*tob1)->Et()) <= p_MinET1[i]) continue; // ET cut
111 if( parType_t((*tob2)->Et()) <= p_MinET2[i]) continue; // ET cut
112 accept = deltaR2 >= p_DeltaRMin[i] && deltaR2 <= p_DeltaRMax[i];
113 const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
114 const bool fillReject = fillHistos() and not fillAccept;
115 const bool alreadyFilled = decision.bit(i);
116 if( accept ) {
117 decision.setBit(i, true);
118 output[i]->push_back(TCS::CompositeTOB(*tob1, *tob2));
119 }
120 if(fillAccept and not alreadyFilled) {
121 fillHist1D(m_histAccept[i],sqrt((float)deltaR2));
122 } else if(fillReject) {
123 fillHist1D(m_histReject[i],sqrt((float)deltaR2));
124 }
125 TRG_MSG_DEBUG("Decision " << i << ": " << (accept?"pass":"fail") << " deltaR2 = " << deltaR2);
126 }
127 }
128 }
129 for (unsigned int i=0; i < numberOutputBits(); ++i) {
130 bool hasAmbiguousInputs = TSU::isAmbiguousTruncation(input[0], p_NumberLeading1, p_MinET1[i])
132 output[i]->setAmbiguityFlag(hasAmbiguousInputs);
133 }
134 } else {
135 TCS_EXCEPTION("DeltaRSqrIncl2 alg must have 2 inputs, but got " << input.size());
136 }
138}
139
141TCS::DeltaRSqrIncl2::process( const std::vector<TCS::TOBArray const *> & input,
142 const std::vector<TCS::TOBArray *> & output,
143 Decision & decision )
144{
145
146 if( input.size() == 2) {
147
148 for( TOBArray::const_iterator tob1 = input[0]->begin();
149 tob1 != input[0]->end() && distance(input[0]->begin(), tob1) < p_NumberLeading1;
150 ++tob1)
151 {
152
153
154 for( TCS::TOBArray::const_iterator tob2 = input[1]->begin();
155 tob2 != input[1]->end() && distance(input[1]->begin(), tob2) < p_NumberLeading2;
156 ++tob2) {
157 // test DeltaR2Min, DeltaR2Max
158 unsigned int deltaR2 = calcDeltaR2( *tob1, *tob2 );
159
160 TRG_MSG_DEBUG("Jet1 = " << **tob1 << ", Jet2 = " << **tob2 << ", deltaR2 = " << deltaR2);
161 for(unsigned int i=0; i<numberOutputBits(); ++i) {
162 bool accept = false;
163 if( parType_t((*tob1)->Et()) <= p_MinET1[i]) continue; // ET cut
164 if( parType_t((*tob2)->Et()) <= p_MinET2[i]) continue; // ET cut
165 accept = deltaR2 >= p_DeltaRMin[i] && deltaR2 <= p_DeltaRMax[i];
166 const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
167 const bool fillReject = fillHistos() and not fillAccept;
168 const bool alreadyFilled = decision.bit(i);
169 if( accept ) {
170 decision.setBit(i, true);
171 output[i]->push_back(TCS::CompositeTOB(*tob1, *tob2));
172 }
173 if(fillAccept and not alreadyFilled) {
174 fillHist1D(m_histAccept[i],sqrt((float)deltaR2));
175 } else if(fillReject) {
176 fillHist1D(m_histReject[i],sqrt((float)deltaR2));
177 }
178 TRG_MSG_DEBUG("Decision " << i << ": " << (accept?"pass":"fail") << " deltaR2 = " << deltaR2);
179 }
180 }
181 }
182 } else {
183 TCS_EXCEPTION("DeltaRSqrIncl2 alg must have 2 inputs, but got " << input.size());
184 }
186}
#define REGISTER_ALG_TCS(CLASS)
Definition AlgFactory.h:62
const Parameter & parameter(const std::string &parameterName) const
const std::string & name() const
void bookHist(std::vector< std::string > &regName, const std::string &name, const std::string &title, const int binx, const int xmin, const int xmax)
void fillHist1D(const std::string &histName, double x)
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
bool fillHistosBasedOnHardware() const
! getter
bool fillHistos() const
whether the monitoring histograms should be filled
std::vector< std::string > m_histAccept
Definition DecisionAlg.h:73
std::vector< std::string > m_histReject
Definition DecisionAlg.h:74
unsigned int numberOutputBits() const
Definition DecisionAlg.h:39
bool getDecisionHardwareBit(const unsigned int &bitNumber) const
! get one hardware decision bit from this algo
bool bit(unsigned int index) const
Definition Decision.h:40
void setBit(unsigned int index, bool value)
Definition Decision.cxx:12
parType_t p_MinET2[3]
parType_t p_DeltaRMax[3]
virtual StatusCode processBitCorrect(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison)
DeltaRSqrIncl2(const std::string &name)
parType_t p_DeltaRMin[3]
virtual StatusCode process(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison)
parType_t p_MinET1[3]
virtual StatusCode initialize()
uint32_t parType_t
Definition Parameter.h:22
bool isAmbiguousTruncation(TCS::TOBArray const *tobs, size_t pos, unsigned minEt=0)