ATLAS Offline Software
Loading...
Searching...
No Matches
MinDeltaPhiIncl2.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4/*********************************
5 * MinDeltaPhiIncl2.cpp
6 * Created by Veronica Sorin on 14/8/14.
7 *
8 * @brief algorithm calculates the min phi-distance between two lists and applies delta-phi criteria
9 *
10 * @param NumberLeading
11**********************************/
12
13
14
18#include <cmath>
19#include <string>
20#include <algorithm>
21
22REGISTER_ALG_TCS(MinDeltaPhiIncl2)
23
24// not the best solution but we will move to athena where this comes for free
25#define LOG std::cout << "TCS::MinDeltaPhiIncl2: "
26
28{
29 defineParameter("InputWidth1", 9);
30 defineParameter("InputWidth2", 9);
31 defineParameter("MaxTob1", 0);
32 defineParameter("MaxTob2", 0);
33 defineParameter("NumResultBits", 3);
34 defineParameter("DeltaPhiMin", 0, 0);
35 defineParameter("DeltaPhiMin", 0, 1);
36 defineParameter("DeltaPhiMin", 0, 2);
37 defineParameter("MinET1",1);
38 defineParameter("MinET2",1);
40}
41
43
44
47 p_NumberLeading1 = parameter("InputWidth1").value();
48 p_NumberLeading2 = parameter("InputWidth2").value();
49 if(parameter("MaxTob1").value() > 0) p_NumberLeading1 = parameter("MaxTob1").value();
50 if(parameter("MaxTob2").value() > 0) p_NumberLeading2 = parameter("MaxTob2").value();
51
52 for(unsigned int i=0; i< numberOutputBits(); ++i) {
53 p_DeltaPhiMin[i] = parameter("DeltaPhiMin", i).value();
54 }
55 p_MinET1 = parameter("MinET1").value();
56 p_MinET2 = parameter("MinET2").value();
57 TRG_MSG_INFO("NumberLeading1 : " << p_NumberLeading1);
58 TRG_MSG_INFO("NumberLeading2 : " << p_NumberLeading2);
59 for(unsigned int i=0; i< numberOutputBits(); ++i) {
60 TRG_MSG_INFO("DeltaPhiMin"<<i<<" : " << p_DeltaPhiMin[i]);
61 }
62 TRG_MSG_INFO("MinET1 : " << p_MinET1);
63 TRG_MSG_INFO("MinET2 : " << p_MinET2);
64 TRG_MSG_INFO("nummber output : " << numberOutputBits());
65
66 // book histograms
67 for(unsigned int i=0; i<numberOutputBits(); ++i) {
68 std::string hname_accept = "hMinDeltaPhiIncl2_accept_bit"+std::to_string((int)i);
69 std::string hname_reject = "hMinDeltaPhiIncl2_reject_bit"+std::to_string((int)i);
70 // mass
71 bookHist(m_histAccept, hname_accept, "DPHI", 100, p_DeltaPhiMin[i], 70);
72 bookHist(m_histReject, hname_reject, "DPHI", 100, p_DeltaPhiMin[i], 70);
73 }
74
76}
77
78
79
81TCS::MinDeltaPhiIncl2::processBitCorrect( const std::vector<TCS::TOBArray const *> & input,
82 const std::vector<TCS::TOBArray *> & output,
83 Decision & decision )
84{
85
86 // mindphi
87 unsigned int mindphi = *std::min_element(std::begin(p_DeltaPhiMin),std::end(p_DeltaPhiMin));
88 bool firstphi = true;
89
90 // declare iterator for the tob with min dphi
91 TCS::TOBArray::const_iterator tobmin1,tobmin2;
92 const TCS::TOBArray::const_iterator invalidIterator;
93
94 if (input.size() == 2) {
95
96 for( TOBArray::const_iterator tob1 = input[0]->begin();
97 tob1 != input[0]->end() && distance(input[0]->begin(), tob1) < p_NumberLeading1;
98 ++tob1)
99 {
100
101 if( parType_t((*tob1)->Et()) <= p_MinET1) continue; // ET cut
102
103 for( TCS::TOBArray::const_iterator tob2 = input[1]->begin();
104 tob2 != input[1]->end() && distance(input[1]->begin(), tob2) < p_NumberLeading2;
105 ++tob2) {
106
107 if( parType_t((*tob2)->Et()) <= p_MinET2) continue; // ET cut
108
109 // test DeltaPhiMin, DeltaPhiMax
110 unsigned int deltaPhi = calcDeltaPhiBW( *tob1, *tob2 );
111
112 if (firstphi) {
113 mindphi = deltaPhi;
114 tobmin1=tob1;
115 tobmin2=tob2;
116 firstphi = false;
117 }
118
119 if ( deltaPhi < mindphi ) {
120
121 mindphi = deltaPhi;
122 tobmin1=tob1;
123 tobmin2=tob2;
124
125 }
126
127 }
128 }
129
130 for(unsigned int i=0; i<numberOutputBits(); ++i) {
131 bool accept = mindphi > p_DeltaPhiMin[i] ;
132 const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
133 const bool fillReject = fillHistos() and not fillAccept;
134 const bool alreadyFilled = decision.bit(i);
135 if( accept and (tobmin1!=invalidIterator and tobmin2!=invalidIterator)) {
136 decision.setBit(i, true);
137 output[i]->push_back(TCS::CompositeTOB(*tobmin1, *tobmin2));
138 }
139 if(fillAccept and not alreadyFilled){
140 fillHist1D(m_histAccept[i],(float)mindphi);
141 } else if(fillReject){
142 fillHist1D(m_histReject[i],(float)mindphi);
143 }
144 TRG_MSG_DEBUG("Decision " << i << ": " << (accept?"pass":"fail"));
145 } // for(i)
146 } else {
147 TCS_EXCEPTION("MinDeltaPhiIncl2 alg must have 2 inputs, but got " << input.size());
148 }
149
151}
152
154TCS::MinDeltaPhiIncl2::process( const std::vector<TCS::TOBArray const *> & input,
155 const std::vector<TCS::TOBArray *> & output,
156 Decision & decision )
157{
158
159 // mindphi
160 unsigned int mindphi = *std::min_element(std::begin(p_DeltaPhiMin),std::end(p_DeltaPhiMin));
161 bool firstphi = true;
162
163 // declare iterator for the tob with min dphi
164 TCS::TOBArray::const_iterator tobmin1,tobmin2;
165
166 if (input.size() == 2) {
167
168 for( TOBArray::const_iterator tob1 = input[0]->begin();
169 tob1 != input[0]->end() && distance(input[0]->begin(), tob1) < p_NumberLeading1;
170 ++tob1)
171 {
172
173 if( parType_t((*tob1)->Et()) <= p_MinET1) continue; // ET cut
174
175 for( TCS::TOBArray::const_iterator tob2 = input[1]->begin();
176 tob2 != input[1]->end() && distance(input[1]->begin(), tob2) < p_NumberLeading2;
177 ++tob2) {
178
179 if( parType_t((*tob2)->Et()) <= p_MinET2) continue; // ET cut
180
181 // test DeltaPhiMin, DeltaPhiMax
182 unsigned int deltaPhi = calcDeltaPhi( *tob1, *tob2 );
183
184 if (firstphi) {
185 mindphi = deltaPhi;
186 tobmin1=tob1;
187 tobmin2=tob2;
188 firstphi = false;
189 }
190
191 if ( deltaPhi < mindphi ) {
192
193 mindphi = deltaPhi;
194 tobmin1=tob1;
195 tobmin2=tob2;
196
197 }
198
199 }
200 }
201
202 for(unsigned int i=0; i<numberOutputBits(); ++i) {
203 bool accept = mindphi > p_DeltaPhiMin[i] ;
204 const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
205 const bool fillReject = fillHistos() and not fillAccept;
206 const bool alreadyFilled = decision.bit(i);
207 if( accept) {
208 decision.setBit(i, true);
209 output[i]->push_back(TCS::CompositeTOB(*tobmin1, *tobmin2));
210 }
211 if(fillAccept and not alreadyFilled){
212 fillHist1D(m_histAccept[i],(float)mindphi);
213 } else if(fillReject) {
214 fillHist1D(m_histReject[i],(float)mindphi);
215 }
216 TRG_MSG_DEBUG("Decision " << i << ": " << (accept?"pass":"fail"));
217 }
218 } else {
219 TCS_EXCEPTION("MinDeltaPhiIncl2 alg must have 2 inputs, but got " << input.size());
220 }
221
223}
#define REGISTER_ALG_TCS(CLASS)
Definition AlgFactory.h:62
Scalar deltaPhi(const MatrixBase< Derived > &vec) const
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 calcDeltaPhiBW(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
void defineParameter(const std::string &name, TCS::parType_t value)
unsigned int calcDeltaPhi(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
virtual StatusCode process(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison)
MinDeltaPhiIncl2(const std::string &name)
virtual StatusCode initialize()
virtual StatusCode processBitCorrect(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison)
uint32_t parType_t
Definition Parameter.h:22