ATLAS Offline Software
Loading...
Searching...
No Matches
DeltaEtaIncl1.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 * DeltaEtaIncl1.cpp
6 * Created by Joerg Stelzer on 11/16/12.
7 * Modified by V Sorin 2014
8 *
9 * @brief algorithm calculates the eta-distance between two TOB from one list and applies delta-eta criteria
10 *
11 * @param NumberLeading
12**********************************/
13
14#include <cmath>
15#include <string>
16#include <iostream>
17#include <sstream>
18#include <vector>
19
24
25REGISTER_ALG_TCS(DeltaEtaIncl1)
26
27// not the best solution but we will move to athena where this comes for free
28#define LOG cout << fullname() << ": "
29
30
32{
33 defineParameter("InputWidth", 0);
34 defineParameter("MaxTob", 0);
35 defineParameter("NumResultBits", 4);
36 defineParameter("MinET1",0,0);
37 defineParameter("MinET2",0,0);
38 defineParameter("MinET1",0,1);
39 defineParameter("MinET2",0,1);
40 defineParameter("MinET1",0,2);
41 defineParameter("MinET2",0,2);
42 defineParameter("MinET1",0,3);
43 defineParameter("MinET2",0,3);
44
45 defineParameter("MinDeltaEta", 0, 0);
46 defineParameter("MaxDeltaEta", 127, 0);
47 defineParameter("MinDeltaEta", 0, 1);
48 defineParameter("MaxDeltaEta", 127, 1);
49 defineParameter("MinDeltaEta", 0, 2);
50 defineParameter("MaxDeltaEta", 127, 2);
51 defineParameter("MinDeltaEta", 0, 3);
52 defineParameter("MaxDeltaEta", 127, 3);
53
55}
56
58
59
62
63 if(parameter("MaxTob").value() > 0) {
64 p_NumberLeading1 = parameter("MaxTob").value();
65 p_NumberLeading2 = parameter("MaxTob").value();
66 } else {
67 p_NumberLeading1 = parameter("InputWidth").value();
68 p_NumberLeading2 = parameter("InputWidth").value();
69 }
70
71 for(unsigned int i=0; i<numberOutputBits(); ++i) {
72 p_DeltaEtaMin[i] = parameter("MinDeltaEta", i).value();
73 p_DeltaEtaMax[i] = parameter("MaxDeltaEta", i).value();
74
75 p_MinET1[i] = parameter("MinET1",i).value();
76 p_MinET2[i] = parameter("MinET2",i).value();
77 }
78
79 TRG_MSG_INFO("NumberLeading1 : " << p_NumberLeading1); // note that the reading of generic parameters doesn't work yet
80 TRG_MSG_INFO("NumberLeading2 : " << p_NumberLeading2);
81 for(unsigned int i=0; i<numberOutputBits(); ++i) {
82 TRG_MSG_INFO("DeltaEtaMin0 : " << p_DeltaEtaMin[i]);
83 TRG_MSG_INFO("DeltaEtaMax0 : " << p_DeltaEtaMax[i]);
84 TRG_MSG_INFO("MinET1 : " << p_MinET1[i]);
85 TRG_MSG_INFO("MinET2 : " << p_MinET2[i]);
86 }
87 TRG_MSG_INFO("number output : " << numberOutputBits());
88
89 // book histograms
90 for(unsigned int i=0; i<numberOutputBits(); ++i) {
91 std::string hname_accept = "hDeltaEtaIncl1_accept_bit"+std::to_string((int)i);
92 std::string hname_reject = "hDeltaEtaIncl1_reject_bit"+std::to_string((int)i);
93 // mass
94 bookHist(m_histAccept, hname_accept, "DETA", 100, p_DeltaEtaMin[i], p_DeltaEtaMax[i]);
95 bookHist(m_histReject, hname_reject, "DETA", 100, p_DeltaEtaMin[i], p_DeltaEtaMax[i]);
96 }
97
98
100}
101
102
104TCS::DeltaEtaIncl1::processBitCorrect( const std::vector<TCS::TOBArray const *> & input,
105 const std::vector<TCS::TOBArray *> & output,
106 Decision & decision )
107
108{
109 if(input.size() == 1) {
110 unsigned int nLeading = p_NumberLeading1;
111 unsigned int nLeading2 = p_NumberLeading2;
112 for( TOBArray::const_iterator tob1 = input[0]->begin();
113 tob1 != input[0]->end() && distance( input[0]->begin(), tob1) < nLeading;
114 ++tob1)
115 {
116 TCS::TOBArray::const_iterator tob2 = tob1; ++tob2;
117 for( ;
118 tob2 != input[0]->end() && distance( input[0]->begin(), tob2) < nLeading2;
119 ++tob2) {
120 for(unsigned int i=0; i < numberOutputBits(); ++i) {
121 bool accept = false;
122 if( parType_t((*tob1)->Et()) <= std::min(p_MinET1[i],p_MinET2[i])) continue; // ET cut
123 if( parType_t((*tob2)->Et()) <= std::min(p_MinET1[i],p_MinET2[i])) continue; // ET cut
124 if( (parType_t((*tob1)->Et()) <= std::max(p_MinET1[i],p_MinET2[i])) && (parType_t((*tob2)->Et()) <= std::max(p_MinET1[i],p_MinET2[i]))) continue;
125 // DeltaEta cuts
126 unsigned int deltaEta = calcDeltaEtaBW( *tob1, *tob2 );
127 std::stringstream msgss;
128 msgss << "Combination : " << distance( input[0]->begin(), tob1)
129 << " x " << distance( input[0]->begin(), tob2)
130 << " eta=" << (*tob1)->eta()
131 << " , eta=" << (*tob2)->eta()
132 << ", DeltaEta = " << deltaEta << " -> ";
133 accept = deltaEta >= p_DeltaEtaMin[i] && deltaEta <= p_DeltaEtaMax[i];
134 const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
135 const bool fillReject = fillHistos() and not fillAccept;
136 const bool alreadyFilled = decision.bit(i);
137 if( accept ) {
138 decision.setBit(i, true);
139 output[i]->push_back( TCS::CompositeTOB(*tob1, *tob2) );
140 }
141 if(fillAccept and not alreadyFilled) {
142 fillHist1D(m_histAccept[i],(float)deltaEta);
143 } else if(fillReject) {
144 fillHist1D(m_histReject[i],(float)deltaEta);
145 }
146 msgss << (accept?"pass":"fail") << "|";
147 TRG_MSG_DEBUG(msgss.str());
148 }
149 }
150 }
151 for (unsigned int i=0; i < numberOutputBits(); ++i) {
152 bool hasAmbiguousInputs = TSU::isAmbiguousTruncation(input[0], p_NumberLeading1, p_MinET1[i])
154 output[i]->setAmbiguityFlag(hasAmbiguousInputs);
155 }
156 } else {
157 TCS_EXCEPTION("DeltaEtaIncl1 alg must have 1 input, but got " << input.size());
158 }
160}
161
163TCS::DeltaEtaIncl1::process( const std::vector<TCS::TOBArray const *> & input,
164 const std::vector<TCS::TOBArray *> & output,
165 Decision & decision )
166{
167 if(input.size() == 1) {
168 //LOG << "input size : " << input[0]->size() << endl;
169 unsigned int nLeading = p_NumberLeading1;
170 unsigned int nLeading2 = p_NumberLeading2;
171 if (nLeading < input[0]->size() && nLeading2 < input[0]->size()) { output[0]->setAmbiguityFlag(false); }
172 for( TOBArray::const_iterator tob1 = input[0]->begin();
173 tob1 != input[0]->end() && distance( input[0]->begin(), tob1) < nLeading;
174 ++tob1)
175 {
176 TCS::TOBArray::const_iterator tob2 = tob1; ++tob2;
177 for( ;
178 tob2 != input[0]->end() && distance( input[0]->begin(), tob2) < nLeading2;
179 ++tob2) {
180 for(unsigned int i=0; i < numberOutputBits(); ++i) {
181 if (input[0]->size() >= nLeading2+1) {
182 TCS::TOBArray::const_iterator tob3 = tob2; ++tob3;
183 if ((*tob2)->Et() == (*tob3)->Et() && distance(input[0]->begin(), tob2) == nLeading2 - 1) {
184 output[0]->setAmbiguityFlag(true);
185 }
186 }
187 bool accept = false;
188 if( parType_t((*tob1)->Et()) <= std::min(p_MinET1[i],p_MinET2[i])) continue; // ET cut
189 if( parType_t((*tob2)->Et()) <= std::min(p_MinET1[i],p_MinET2[i])) continue; // ET cut
190 if( (parType_t((*tob1)->Et()) <= std::max(p_MinET1[i],p_MinET2[i])) && (parType_t((*tob2)->Et()) <= std::max(p_MinET1[i],p_MinET2[i]))) continue;
191 // DeltaEta cuts
192 unsigned int deltaEta = calcDeltaEta( *tob1, *tob2 );
193 std::stringstream msgss;
194 msgss << "Combination : " << distance( input[0]->begin(), tob1)
195 << " x " << distance( input[0]->begin(), tob2)
196 << " eta=" << (*tob1)->eta()
197 << " , eta=" << (*tob2)->eta()
198 << ", DeltaEta = " << deltaEta << " -> ";
199 accept = deltaEta >= p_DeltaEtaMin[i] && deltaEta <= p_DeltaEtaMax[i];
200 const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
201 const bool fillReject = fillHistos() and not fillAccept;
202 const bool alreadyFilled = decision.bit(i);
203 if( accept ) {
204 decision.setBit(i, true);
205 output[i]->push_back( TCS::CompositeTOB(*tob1, *tob2) );
206 }
207 if(fillAccept and not alreadyFilled) {
208 fillHist1D(m_histAccept[i],(float)deltaEta);
209 } else if(fillReject) {
210 fillHist1D(m_histReject[i],(float)deltaEta);
211 }
212 msgss << (accept?"pass":"fail") << "|";
213 TRG_MSG_DEBUG(msgss.str());
214 }
215 }
216 }
217 for (unsigned int i=0; i < numberOutputBits(); ++i) {
218 bool hasAmbiguousInputs = TSU::isAmbiguousTruncation(input[0], p_NumberLeading1, p_MinET1[i])
220 output[i]->setAmbiguityFlag(hasAmbiguousInputs);
221 }
222 } else {
223 TCS_EXCEPTION("DeltaEtaIncl1 alg must have 1 input, but got " << input.size());
224 }
226}
#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 calcDeltaEta(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
unsigned int calcDeltaEtaBW(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
void defineParameter(const std::string &name, TCS::parType_t value)
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_DeltaEtaMax[4]
virtual StatusCode initialize()
parType_t p_MinET1[4]
parType_t p_DeltaEtaMin[4]
virtual StatusCode processBitCorrect(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison)
parType_t p_NumberLeading1
DeltaEtaIncl1(const std::string &name)
parType_t p_NumberLeading2
virtual StatusCode process(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison)
parType_t p_MinET2[4]
uint32_t parType_t
Definition Parameter.h:22
bool isAmbiguousTruncation(TCS::TOBArray const *tobs, size_t pos, unsigned minEt=0)