ATLAS Offline Software
Loading...
Searching...
No Matches
InvariantMassInclusive2.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 * InvariantMassInclusive2.cpp
6 * Created by V SOrin 2014.
7 *
8 * @brief algorithm calculates the sqr of the INVMASS between two lists and applies invmass criteria
9 *
10 * @param NumberLeading
11**********************************/
12
13
18
19#include <cmath>
20#include <iostream>
21
22REGISTER_ALG_TCS(InvariantMassInclusive2)
23
24
25// not the best solution but we will move to athena where this comes for free
26#define LOG cout << "TCS::InvariantMassInclusive2: "
27
28
30{
31 defineParameter("InputWidth1", 9);
32 defineParameter("InputWidth2", 9);
33 defineParameter("MaxTob1", 0);
34 defineParameter("MaxTob2", 0);
35 defineParameter("NumResultBits", 6);
36 defineParameter("MinMSqr", 0, 0);
37 defineParameter("MaxMSqr", 999, 0);
38 defineParameter("MinMSqr", 0, 1);
39 defineParameter("MaxMSqr", 999, 1);
40 defineParameter("MinMSqr", 0, 2);
41 defineParameter("MaxMSqr", 999, 2);
42 defineParameter("MinMSqr", 0, 3);
43 defineParameter("MaxMSqr", 999, 3);
44 defineParameter("MinMSqr", 0, 4);
45 defineParameter("MaxMSqr", 999, 4);
46 defineParameter("MinMSqr", 0, 5);
47 defineParameter("MaxMSqr", 999, 5);
48 defineParameter("MinET1",0,0);
49 defineParameter("MinET2",0,0);
50 defineParameter("MinET1",0,1);
51 defineParameter("MinET2",0,1);
52 defineParameter("MinET1",0,2);
53 defineParameter("MinET2",0,2);
54 defineParameter("MinET1",0,3);
55 defineParameter("MinET2",0,3);
56 defineParameter("MinET1",0,4);
57 defineParameter("MinET2",0,4);
58 defineParameter("MinET1",0,5);
59 defineParameter("MinET2",0,5);
60 defineParameter("ApplyEtaCut", 0);
61 defineParameter("MinEta1", 0);
62 defineParameter("MaxEta1", 31);
63 defineParameter("MinEta2", 0);
64 defineParameter("MaxEta2", 31);
65
67}
68
70
71
74 p_NumberLeading1 = parameter("InputWidth1").value();
75 p_NumberLeading2 = parameter("InputWidth2").value();
76 if(parameter("MaxTob1").value() > 0) p_NumberLeading1 = parameter("MaxTob1").value();
77 if(parameter("MaxTob2").value() > 0) p_NumberLeading2 = parameter("MaxTob2").value();
78
79 for(unsigned int i=0; i<numberOutputBits(); ++i) {
80 p_InvMassMin[i] = parameter("MinMSqr", i).value();
81 p_InvMassMax[i] = parameter("MaxMSqr", i).value();
82
83 p_MinET1[i] = parameter("MinET1",i).value();
84 p_MinET2[i] = parameter("MinET2",i).value();
85 }
86 TRG_MSG_INFO("NumberLeading1 : " << p_NumberLeading1);
87 TRG_MSG_INFO("NumberLeading2 : " << p_NumberLeading2);
88 for(unsigned int i=0; i<numberOutputBits(); ++i) {
89 TRG_MSG_INFO("InvMassMin : " << p_InvMassMin[i]);
90 TRG_MSG_INFO("InvMassMax : " << p_InvMassMax[i]);
91 TRG_MSG_INFO("MinET1 : " << p_MinET1[i]);
92 TRG_MSG_INFO("MinET2 : " << p_MinET2[i]);
93 }
94
95 p_ApplyEtaCut = parameter("ApplyEtaCut").value();
96 p_MinEta1 = parameter("MinEta1" ).value();
97 p_MaxEta1 = parameter("MaxEta1" ).value();
98 p_MinEta2 = parameter("MinEta2" ).value();
99 p_MaxEta2 = parameter("MaxEta2" ).value();
100 TRG_MSG_INFO("ApplyEtaCut : "<<p_ApplyEtaCut );
101 TRG_MSG_INFO("MinEta1 : "<<p_MinEta1 );
102 TRG_MSG_INFO("MaxEta1 : "<<p_MaxEta1 );
103 TRG_MSG_INFO("MinEta2 : "<<p_MinEta2 );
104 TRG_MSG_INFO("MaxEta2 : "<<p_MaxEta2 );
105
106 TRG_MSG_INFO("number output : " << numberOutputBits());
107
108 // book histograms
109 for(unsigned int i=0; i<numberOutputBits(); ++i) {
110 std::string hname_accept = "hInvariantMassInclusive2_accept_bit"+std::to_string((int)i);
111 std::string hname_reject = "hInvariantMassInclusive2_reject_bit"+std::to_string((int)i);
112 // mass
113 bookHist(m_histAcceptM, hname_accept, "INVM", 100, sqrt(p_InvMassMin[i]), sqrt(p_InvMassMax[i]));
114 bookHist(m_histRejectM, hname_reject, "INVM", 100, sqrt(p_InvMassMin[i]), sqrt(p_InvMassMax[i]));
115 // eta2 vs. eta1
116 bookHist(m_histAcceptEta1Eta2, hname_accept, "ETA vs ETA", 100, p_MinEta1, p_MaxEta1, 100, p_MinEta2, p_MaxEta2);
117 bookHist(m_histRejectEta1Eta2, hname_reject, "ETA vs ETA", 100, p_MinEta1, p_MaxEta1, 100, p_MinEta2, p_MaxEta2);
118 }
119
120 return StatusCode::SUCCESS;
121}
122
123
124
126TCS::InvariantMassInclusive2::processBitCorrect( const std::vector<TCS::TOBArray const *> & input,
127 const std::vector<TCS::TOBArray *> & output,
128 Decision & decision )
129{
130
131 if( input.size() == 2) {
132 for( TOBArray::const_iterator tob1 = input[0]->begin();
133 tob1 != input[0]->end() && distance(input[0]->begin(), tob1) < p_NumberLeading1;
134 ++tob1)
135 {
136 if (p_NumberLeading1 < input[0]->size()) {
137 TCS::TOBArray::const_iterator tob1_plus1 = tob1; ++tob1_plus1;
138 if ((*tob1)->Et() == (*tob1_plus1)->Et() && distance(input[0]->begin(), tob1) == p_NumberLeading1 - 1) {
139 for(unsigned int i=0; i<numberOutputBits(); ++i) {
140 output[i]->setAmbiguityFlag(true);
141 }
142 }
143 }
144 for( TCS::TOBArray::const_iterator tob2 = input[1]->begin();
145 tob2 != input[1]->end() && distance(input[1]->begin(), tob2) < p_NumberLeading2;
146 ++tob2) {
147 // Inv Mass calculation
148 unsigned int invmass2 = calcInvMassBW( *tob1, *tob2 );
149 const int eta1 = (*tob1)->eta();
150 const int eta2 = (*tob2)->eta();
151 const unsigned int aeta1 = std::abs(eta1);
152 const unsigned int aeta2 = std::abs(eta2);
153 for(unsigned int i=0; i<numberOutputBits(); ++i) {
154 bool accept = false;
155 if( parType_t((*tob1)->Et()) <= p_MinET1[i]) continue; // ET cut
156 if( parType_t((*tob2)->Et()) <= p_MinET2[i]) continue; // ET cut
157 if(p_ApplyEtaCut &&
158 ((aeta1 < p_MinEta1 || aeta1 > p_MaxEta1 ) ||
159 (aeta2 < p_MinEta2 || aeta2 > p_MaxEta2 ) )) continue;
160 accept = invmass2 >= p_InvMassMin[i] && invmass2 <= p_InvMassMax[i];
161 const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
162 const bool fillReject = fillHistos() and not fillAccept;
163 const bool alreadyFilled = decision.bit(i);
164 if( accept ) {
165 decision.setBit(i, true);
166 output[i]->push_back( TCS::CompositeTOB(*tob1, *tob2) );
167 }
168 if(fillAccept and not alreadyFilled) {
169 fillHist1D(m_histAcceptM[i],sqrt((float)invmass2));
170 fillHist2D(m_histAcceptEta1Eta2[i],eta1, eta2);
171 } else if(fillReject) {
172 fillHist1D(m_histRejectM[i],sqrt((float)invmass2));
173 fillHist2D(m_histRejectEta1Eta2[i],eta1, eta2);
174 }
175 TRG_MSG_DEBUG("Decision " << i << ": " << (accept?"pass":"fail") << " invmass2 = " << invmass2);
176 }
177 }
178 }
179 for (unsigned int i=0; i < numberOutputBits(); ++i) {
180 bool hasAmbiguousInputs = TSU::isAmbiguousTruncation(input[0], p_NumberLeading1, p_MinET1[i])
182 output[i]->setAmbiguityFlag(hasAmbiguousInputs);
183 }
184 } else {
185
186 TCS_EXCEPTION("InvariantMassInclusive2 alg must have 2 inputs, but got " << input.size());
187
188 }
190
191}
192
194TCS::InvariantMassInclusive2::process( const std::vector<TCS::TOBArray const *> & input,
195 const std::vector<TCS::TOBArray *> & output,
196 Decision & decision )
197{
198
199
200 if( input.size() == 2) {
201 for( TOBArray::const_iterator tob1 = input[0]->begin();
202 tob1 != input[0]->end() && distance(input[0]->begin(), tob1) < p_NumberLeading1;
203 ++tob1)
204 {
205 if (p_NumberLeading1 < input[0]->size()) {
206 TCS::TOBArray::const_iterator tob1_plus1 = tob1; ++tob1_plus1;
207 if ((*tob1)->Et() == (*tob1_plus1)->Et() && distance(input[0]->begin(), tob1) == p_NumberLeading1 - 1) {
208 for(unsigned int i=0; i<numberOutputBits(); ++i) {
209 output[i]->setAmbiguityFlag(true);
210 }
211 }
212 }
213 for( TCS::TOBArray::const_iterator tob2 = input[1]->begin();
214 tob2 != input[1]->end() && distance(input[1]->begin(), tob2) < p_NumberLeading2;
215 ++tob2) {
216 // Inv Mass calculation
217 unsigned int invmass2 = calcInvMass( *tob1, *tob2 );
218 const int eta1 = (*tob1)->eta();
219 const int eta2 = (*tob2)->eta();
220 const unsigned int aeta1 = std::abs(eta1);
221 const unsigned int aeta2 = std::abs(eta2);
222 for(unsigned int i=0; i<numberOutputBits(); ++i) {
223 if( parType_t((*tob1)->Et()) <= p_MinET1[i]) continue; // ET cut
224 if( parType_t((*tob2)->Et()) <= p_MinET2[i]) continue; // ET cut
225 if(p_ApplyEtaCut &&
226 ((aeta1 < p_MinEta1 || aeta1 > p_MaxEta1 ) ||
227 (aeta2 < p_MinEta2 || aeta2 > p_MaxEta2 ) )) continue;
228 bool accept = invmass2 >= p_InvMassMin[i] && invmass2 <= p_InvMassMax[i];
229 const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
230 const bool fillReject = fillHistos() and not fillAccept;
231 const bool alreadyFilled = decision.bit(i);
232 if( accept ) {
233 decision.setBit(i, true);
234 output[i]->push_back( TCS::CompositeTOB(*tob1, *tob2) );
235 }
236 if(fillAccept and not alreadyFilled) {
237 fillHist1D(m_histAcceptM[i],sqrt((float)invmass2));
238 fillHist2D(m_histAcceptEta1Eta2[i],eta1, eta2);
239 } else if(fillReject) {
240 fillHist1D(m_histRejectM[i],sqrt((float)invmass2));
241 fillHist2D(m_histRejectEta1Eta2[i],eta1, eta2);
242 }
243 TRG_MSG_DEBUG("Decision " << i << ": " << (accept ?"pass":"fail") << " invmass2 = " << invmass2);
244 }
245 }
246 }
247 } else {
248 TCS_EXCEPTION("InvariantMassInclusive2 alg must have 2 inputs, but got " << input.size());
249 }
251}
#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 calcInvMassBW(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
void defineParameter(const std::string &name, TCS::parType_t value)
unsigned int calcInvMass(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
void fillHist2D(const std::string &histName, double x, double y)
data_t::const_iterator const_iterator
std::vector< std::string > m_histAcceptEta1Eta2
Definition DecisionAlg.h:79
std::vector< std::string > m_histAcceptM
Definition DecisionAlg.h:75
void setNumberOutputBits(unsigned int numberOutputBits)
Definition DecisionAlg.h:40
DecisionAlg(const std::string &name)
Definition DecisionAlg.h:25
std::vector< std::string > m_histRejectEta1Eta2
Definition DecisionAlg.h:80
bool fillHistosBasedOnHardware() const
! getter
bool fillHistos() const
whether the monitoring histograms should be filled
unsigned int numberOutputBits() const
Definition DecisionAlg.h:39
bool getDecisionHardwareBit(const unsigned int &bitNumber) const
! get one hardware decision bit from this algo
std::vector< std::string > m_histRejectM
Definition DecisionAlg.h:76
bool bit(unsigned int index) const
Definition Decision.h:40
void setBit(unsigned int index, bool value)
Definition Decision.cxx:12
InvariantMassInclusive2(const std::string &name)
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)