ATLAS Offline Software
Loading...
Searching...
No Matches
InvariantMassInclusive1Disambiguation2.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4/*********************************
5 * InvariantMassInclusive1Disambiguation2.cpp
6 * Created by Gabriel Oliveira Correa on 10/2025.
7 *
8 * @brief Algorithm selects events based on invariant masses of TOB pairs from one list. Additionally there shall be a disambiguation with TOBs from a second list from which there must be at least one valid object that does not overlap (within a configurable distance DeltaR) with the TOBs forming the TOBs from the first list that form a given invM pair.
9 *
10 * @param NumberLeading
11**********************************/
12
13#include <cmath>
14#include <string>
15#include <iostream>
16#include <sstream>
17#include <vector>
18
23
24REGISTER_ALG_TCS(InvariantMassInclusive1Disambiguation2)
25
26
27// not the best solution but we will move to athena where this comes for free
28// #define LOG cout << "TCS::InvariantMassInclusive1Disambiguation2: "
29
31{
32 defineParameter("InputWidth1", 6);
33 defineParameter("InputWidth2", 6);
34 defineParameter("MaxTob1", 0);
35 defineParameter("MaxTob2", 0);
36 defineParameter("NumResultBits", 6);
38
39 for (unsigned int i=0;i<numberOutputBits();i++){
40 // Algo parameters
41 defineParameter("MinMSqr", 0, i);
42 defineParameter("MaxMSqr", 999, i);
43 defineParameter("MinET1a", 0, i);
44 defineParameter("MinET1b", 0, i);
45 defineParameter("MinET2", 0, i);
46 defineParameter("DisambDRSqrMin", 0, i);
47 }
48
49}
50
52
53
56
57 p_NumberLeading1a = parameter("InputWidth1").value();
58 p_NumberLeading1b = parameter("InputWidth1").value();
59 p_NumberLeading2 = parameter("InputWidth2").value();
60 if(parameter("MaxTob1").value() > 0) {
61 p_NumberLeading1a = parameter("MaxTob1").value();
62 p_NumberLeading1b = parameter("MaxTob1").value();
63 }
64 if(parameter("MaxTob2").value() > 0) {
65 p_NumberLeading2 = parameter("MaxTob2").value();
66 }
67
68 TRG_MSG_INFO("NumberLeading1a : " << p_NumberLeading1a);
69 TRG_MSG_INFO("NumberLeading1b : " << p_NumberLeading1b);
70 TRG_MSG_INFO("NumberLeading2 : " << p_NumberLeading2);
71
72 for(unsigned int i=0; i<numberOutputBits(); ++i) {
73 p_InvMassMin[i] = parameter("MinMSqr", i).value();
74 p_InvMassMax[i] = parameter("MaxMSqr", i).value();
75
76 p_MinET1a[i] = parameter("MinET1a",i).value();
77 p_MinET1b[i] = parameter("MinET1b",i).value();
78 p_MinET2[i] = parameter("MinET2",i).value();
79
80 p_DisambDR[i] = parameter("DisambDRSqrMin", i).value();
81 }
82
83 for(unsigned int i=0; i<numberOutputBits(); ++i) {
84 TRG_MSG_INFO("InvMassMin " << i << " : " << p_InvMassMin[i]);
85 TRG_MSG_INFO("InvMassMax " << i << " : " << p_InvMassMax[i]);
86
87 TRG_MSG_INFO("MinET1a " << i << " : " << p_MinET1a[i]);
88 TRG_MSG_INFO("MinET1b " << i << " : " << p_MinET1b[i]);
89 TRG_MSG_INFO("MinET2 " << i << " : " << p_MinET2[i]);
90
91 TRG_MSG_INFO("DisambDR " << i << " : " << p_DisambDR[i]);
92 }
93 TRG_MSG_INFO("number output : " << numberOutputBits());
94
95 // book histograms
96 for(unsigned int i=0; i<numberOutputBits(); ++i) {
97 std::string hname_accept = "hInvariantMassInclusive1Disambiguation2_accept_bit"+std::to_string((int)i);
98 std::string hname_reject = "hInvariantMassInclusive1Disambiguation2_reject_bit"+std::to_string((int)i);
99 // mass
100 bookHist(m_histAccept, hname_accept, "INVM", 100, sqrt(p_InvMassMin[i]), sqrt(p_InvMassMax[i]));
101 bookHist(m_histReject, hname_reject, "INVM", 100, sqrt(p_InvMassMin[i]), sqrt(p_InvMassMax[i]));
102 }
103
104 return StatusCode::SUCCESS;
105}
106
107
108
110TCS::InvariantMassInclusive1Disambiguation2::processBitCorrect( const std::vector<TCS::TOBArray const *> & input,
111 const std::vector<TCS::TOBArray *> & output,
112 Decision & decision )
113{
114
115 if(input.size() == 2) {
116
117 for( TOBArray::const_iterator tob1a = input[0]->begin();
118 tob1a != input[0]->end() && distance( input[0]->begin(), tob1a) < p_NumberLeading1a;
119 ++tob1a) {
120
121 TCS::TOBArray::const_iterator tob1b = tob1a; ++tob1b;
122 for( ;
123 tob1b != input[0]->end() && distance( input[0]->begin(), tob1b) < p_NumberLeading1b;
124 ++tob1b) {
125
126 // Inv Mass calculation
127 unsigned int invmass2 = calcInvMassBW( *tob1a, *tob1b );
128 for(unsigned int i=0; i<numberOutputBits(); ++i) {
129
130 bool accept = false;
131 if( parType_t((*tob1a)->Et()) <= std::min(p_MinET1a[i],p_MinET1b[i])) continue; // ET cut
132 if( parType_t((*tob1b)->Et()) <= std::min(p_MinET1a[i],p_MinET1b[i])) continue; // ET cut
133 if( (parType_t((*tob1a)->Et()) <= std::max(p_MinET1a[i],p_MinET1b[i])) && (parType_t((*tob1b)->Et()) <= std::max(p_MinET1a[i],p_MinET1b[i]))) continue;
134
135 bool passInvM = invmass2 >= p_InvMassMin[i] && invmass2 <= p_InvMassMax[i];
136
137 for( TOBArray::const_iterator tob2 = input[1]->begin();
138 tob2 != input[1]->end() && distance( input[1]->begin(), tob2) < p_NumberLeading2;
139 ++tob2) {
140
141 if( parType_t((*tob2)->Et()) <= p_MinET2[i]) continue; // ET cut
142
143 unsigned int deltaR2a = calcDeltaR2BW( *tob1a, *tob2 );
144 unsigned int deltaR2b = calcDeltaR2BW( *tob1b, *tob2 );
145
146 accept = passInvM && deltaR2a > p_DisambDR[i] && deltaR2b > p_DisambDR[i];
147 const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
148 const bool fillReject = fillHistos() and not fillAccept;
149 const bool alreadyFilled = decision.bit(i);
150 if( accept ) {
151 decision.setBit(i, true);
152 output[i]->push_back( TCS::CompositeTOB(*tob1a, *tob1b) );
153 }
154 if(fillAccept and not alreadyFilled) {
155 fillHist1D(m_histAccept[i],sqrt((float)invmass2));
156 } else if(fillReject) {
157 fillHist1D(m_histReject[i],sqrt((float)invmass2));
158 }
159 TRG_MSG_DEBUG("Decision " << i << ": " << (accept?"pass":"fail") << " invmass2 = " << invmass2);
160 }
161 }
162 }
163 }
164 for (unsigned int i=0; i < numberOutputBits(); ++i) {
165 bool hasAmbiguousInputs = TSU::isAmbiguousTruncation(input[0], p_NumberLeading1a, p_MinET1a[i])
168 output[i]->setAmbiguityFlag(hasAmbiguousInputs);
169 }
170 } else {
171
172 TCS_EXCEPTION("InvariantMassInclusive1Disambiguation2 alg must have 2 inputs, but got " << input.size());
173
174 }
175
177
178}
179
181TCS::InvariantMassInclusive1Disambiguation2::process( const std::vector<TCS::TOBArray const *> & input,
182 const std::vector<TCS::TOBArray *> & output,
183 Decision & decision )
184{
185
186 if(input.size() == 2) {
187
188 for( TOBArray::const_iterator tob1a = input[0]->begin();
189 tob1a != input[0]->end() && distance( input[0]->begin(), tob1a) < p_NumberLeading1a;
190 ++tob1a) {
191
192 TCS::TOBArray::const_iterator tob1b = tob1a; ++tob1b;
193 for( ;
194 tob1b != input[0]->end() && distance( input[0]->begin(), tob1b) < p_NumberLeading1b;
195 ++tob1b) {
196
197 // Inv Mass calculation
198 unsigned int invmass2 = calcInvMass( *tob1a, *tob1b );
199
200 for(unsigned int i=0; i<numberOutputBits(); ++i) {
201
202 bool accept = false;
203
204 if( parType_t((*tob1a)->Et()) <= std::min(p_MinET1a[i],p_MinET1b[i])) continue; // ET cut
205 if( parType_t((*tob1b)->Et()) <= std::min(p_MinET1a[i],p_MinET1b[i])) continue; // ET cut
206 if( (parType_t((*tob1a)->Et()) <= std::max(p_MinET1a[i],p_MinET1b[i])) && (parType_t((*tob1b)->Et()) <= std::max(p_MinET1a[i],p_MinET1b[i]))) continue;
207
208 bool passInvM = invmass2 >= p_InvMassMin[i] && invmass2 <= p_InvMassMax[i];
209
210 for( TOBArray::const_iterator tob2 = input[1]->begin();
211 tob2 != input[1]->end() && distance( input[1]->begin(), tob2) < p_NumberLeading2;
212 ++tob2) {
213
214 if( parType_t((*tob2)->Et()) <= p_MinET2[i]) continue; // ET cut
215
216 unsigned int deltaR2a = calcDeltaR2( *tob1a, *tob2 );
217 unsigned int deltaR2b = calcDeltaR2( *tob1b, *tob2 );
218
219 accept = passInvM && deltaR2a > p_DisambDR[i] && deltaR2b > p_DisambDR[i];
220 const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
221 const bool fillReject = fillHistos() and not fillAccept;
222 const bool alreadyFilled = decision.bit(i);
223 if( accept ) {
224 decision.setBit(i, true);
225 output[i]->push_back( TCS::CompositeTOB(*tob1a, *tob1b) );
226 }
227 if(fillAccept and not alreadyFilled) {
228 fillHist1D(m_histAccept[i],sqrt((float)invmass2));
229 } else if(fillReject) {
230 fillHist1D(m_histReject[i],sqrt((float)invmass2));
231 }
232 TRG_MSG_DEBUG("Decision " << i << ": " << (accept?"pass":"fail") << " invmass2 = " << invmass2);
233 }
234 }
235 }
236 }
237 } else {
238
239 TCS_EXCEPTION("InvariantMassInclusive1Disambiguation2 alg must have either 2 inputs, but got " << input.size());
240
241 }
242
244}
#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)
unsigned int calcInvMassBW(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)
unsigned int calcInvMass(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 processBitCorrect(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison)
virtual StatusCode process(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison)
uint32_t parType_t
Definition Parameter.h:22
bool isAmbiguousTruncation(TCS::TOBArray const *tobs, size_t pos, unsigned minEt=0)
STL namespace.