ATLAS Offline Software
Loading...
Searching...
No Matches
InvariantMassInclusiveDeltaRSqrIncl1Charge.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 * Created by Paula Martinez based on V Sorin and Joerg Stelzer.
6 *
7 * @brief algorithm calculates the sqr of the INVMASS and DeltaR between one list and applies invmass and deltaR criteria
8 * Events containing a pair of TGC muons with same charge are rejected
9 *
10 * @param NumberLeading
11 *
12 * For questions contact atlas-trig-l1topo-algcom@cern.ch.
13**********************************/
14
15#include <cmath>
16#include <string>
17#include <sstream>
18#include <vector>
19#include "TH1F.h"
20#include "TH2F.h"
21
25// Bitwise implementation utils
31
32//
33
34REGISTER_ALG_TCS(InvariantMassInclusiveDeltaRSqrIncl1Charge)
35
36
38{
39 defineParameter("InputWidth", 3);
40 defineParameter("MaxTob", 0);
41 defineParameter("NumResultBits", 6);
42 defineParameter("RequireOneBarrel", 0);
43 defineParameter("MinMSqr", 0, 0);
44 defineParameter("MaxMSqr", 999, 0);
45 defineParameter("MinMSqr", 0, 1);
46 defineParameter("MaxMSqr", 999, 1);
47 defineParameter("MinMSqr", 0, 2);
48 defineParameter("MaxMSqr", 999, 2);
49 defineParameter("MinMSqr", 0, 3);
50 defineParameter("MaxMSqr", 999, 3);
51 defineParameter("MinMSqr", 0, 4);
52 defineParameter("MaxMSqr", 999, 4);
53 defineParameter("MinMSqr", 0, 5);
54 defineParameter("MaxMSqr", 999, 5);
55 defineParameter("MinET1",0,0);
56 defineParameter("MinET2",0,0);
57 defineParameter("MinET1",0,1);
58 defineParameter("MinET2",0,1);
59 defineParameter("MinET1",0,2);
60 defineParameter("MinET2",0,2);
61 defineParameter("MinET1",0,3);
62 defineParameter("MinET2",0,3);
63 defineParameter("MinET1",0,4);
64 defineParameter("MinET2",0,4);
65 defineParameter("MinET1",0,5);
66 defineParameter("MinET2",0,5);
67 defineParameter("DeltaRMin", 0, 0);
68 defineParameter("DeltaRMax", 0, 0);
69 defineParameter("DeltaRMin", 0, 1);
70 defineParameter("DeltaRMax", 0, 1);
71 defineParameter("DeltaRMin", 0, 2);
72 defineParameter("DeltaRMax", 0, 2);
73 defineParameter("DeltaRMin", 0, 3);
74 defineParameter("DeltaRMax", 0, 3);
75 defineParameter("DeltaRMin", 0, 4);
76 defineParameter("DeltaRMax", 0, 4);
77 defineParameter("DeltaRMin", 0, 5);
78 defineParameter("DeltaRMax", 0, 5);
79
80
82}
83
85
86
89 if(parameter("MaxTob").value() > 0) {
90 p_NumberLeading1 = parameter("MaxTob").value();
91 p_NumberLeading2 = parameter("MaxTob").value();
92 } else {
93 p_NumberLeading1 = parameter("InputWidth").value();
94 p_NumberLeading2 = parameter("InputWidth").value();
95 }
96
97 p_OneBarrel = parameter("RequireOneBarrel").value();
98
99 TRG_MSG_INFO("NumberLeading1 : " << p_NumberLeading1);
100 TRG_MSG_INFO("NumberLeading2 : " << p_NumberLeading2);
101 TRG_MSG_INFO("RequireOneBarrel : " << p_OneBarrel);
102
103 for(unsigned int i=0; i<numberOutputBits(); ++i) {
104 p_InvMassMin[i] = parameter("MinMSqr", i).value();
105 p_InvMassMax[i] = parameter("MaxMSqr", i).value();
106 p_DeltaRMin[i] = parameter("DeltaRMin", i).value();
107 p_DeltaRMax[i] = parameter("DeltaRMax", i).value();
108 p_MinET1[i] = parameter("MinET1",i).value();
109 p_MinET2[i] = parameter("MinET2",i).value();
110
111 TRG_MSG_INFO("InvMassMin "<< i << " : " << p_InvMassMin[i]);
112 TRG_MSG_INFO("InvMassMax "<< i << " : " << p_InvMassMax[i]);
113 TRG_MSG_INFO("MinET1 "<< i << " : " << p_MinET1[i]);
114 TRG_MSG_INFO("MinET2 "<< i << " : " << p_MinET2[i]);
115 TRG_MSG_INFO("DeltaRMin "<< i << " : " << p_DeltaRMin[i]);
116 TRG_MSG_INFO("DeltaRMax "<< i << " : " << p_DeltaRMax[i]);
117 }
118
119 TRG_MSG_INFO("number output : " << numberOutputBits());
120
121 // book histograms
122 for(unsigned int i=0; i<numberOutputBits(); ++i) {
123 std::string hname_accept = "hInvariantMassInclusiveDeltaRSqrIncl1Charge_accept_bit"+std::to_string(static_cast<int>(i));
124 std::string hname_reject = "hInvariantMassInclusiveDeltaRSqrIncl1Charge_reject_bit"+std::to_string(static_cast<int>(i));
125 // mass
126 bookHist(m_histAcceptM, hname_accept, "INVM vs DR", 100, std::sqrt(p_InvMassMin[i]), std::sqrt(p_InvMassMax[i]), 100, std::sqrt(p_DeltaRMin[i]), std::sqrt(p_DeltaRMax[i]));
127 bookHist(m_histRejectM, hname_reject, "INVM vs DR", 100, std::sqrt(p_InvMassMin[i]), std::sqrt(p_InvMassMax[i]), 100, std::sqrt(p_DeltaRMin[i]), std::sqrt(p_DeltaRMax[i]));
128 // eta2 vs. eta1
129 bookHist(m_histAcceptEta1Eta2, hname_accept, "ETA vs ETA", 100, -70, 70, 100, -70, 70);
130 bookHist(m_histRejectEta1Eta2, hname_reject, "ETA vs ETA", 100, -70, 70, 100, -70, 70);
131
132 }
133
134 return StatusCode::SUCCESS;
135}
136
137
138
140TCS::InvariantMassInclusiveDeltaRSqrIncl1Charge::processBitCorrect( const std::vector<TCS::TOBArray const *> & input,
141 const std::vector<TCS::TOBArray *> & output,
142 Decision & decision )
143{
144
145 if(input.size() == 1) {
146
147 for( TOBArray::const_iterator tob1 = input[0]->begin();
148 tob1 != input[0]->end() && distance( input[0]->begin(), tob1) < p_NumberLeading1;
149 ++tob1)
150 {
151
152
153 TCS::TOBArray::const_iterator tob2 = tob1; ++tob2;
154 for( ;
155 tob2 != input[0]->end() && distance( input[0]->begin(), tob2) < p_NumberLeading2;
156 ++tob2) {
157
158
159 // OneBarrel
160 if (p_OneBarrel && parType_t(std::abs((*tob1)->eta())) > 10 && parType_t(std::abs((*tob2)->eta())) > 10 ) continue;
161
162 // Inv Mass calculation
163 unsigned int invmass2 = calcInvMassBW( *tob1, *tob2 );
164 // test DeltaR2Min, DeltaR2Max
165 unsigned int deltaR2 = calcDeltaR2BW( *tob1, *tob2 );
166 TRG_MSG_DEBUG("Jet1 = " << **tob1 << ", Jet2 = " << **tob2 << ", invmass2 = " << invmass2 << ", deltaR2 = " << deltaR2);
167 // Charge cut ( 1 = positive, -1 = negative, 0 = undefined (RPC) )
168 int charge1 = (*tob1)->charge();
169 int charge2 = (*tob2)->charge();
170 int totalCharge = charge1 + charge2;
171 bool acceptCharge = true;
172 if ( std::abs(totalCharge) == 2 ) { acceptCharge = false; }
173 for(unsigned int i=0; i<numberOutputBits(); ++i) {
174 bool accept = false;
175 if( parType_t((*tob1)->Et()) <= std::min(p_MinET1[i],p_MinET2[i])) continue; // ET cut
176 if( parType_t((*tob2)->Et()) <= std::min(p_MinET1[i],p_MinET2[i])) continue; // ET cut
177 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;
178 accept = invmass2 >= p_InvMassMin[i] && invmass2 <= p_InvMassMax[i] && deltaR2 >= p_DeltaRMin[i] && deltaR2 <= p_DeltaRMax[i] && acceptCharge;
179 const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
180 const bool fillReject = fillHistos() and not fillAccept;
181 const bool alreadyFilled = decision.bit(i);
182 if( accept ) {
183 decision.setBit(i, true);
184 output[i]->push_back( TCS::CompositeTOB(*tob1, *tob2) );
185 }
186 if(fillAccept and not alreadyFilled) {
187 fillHist2D(m_histAcceptM[i],std::sqrt(static_cast<float>(invmass2)),std::sqrt(static_cast<float>(deltaR2)));
188 fillHist2D(m_histAcceptEta1Eta2[i],(*tob1)->eta(),(*tob2)->eta());
189 } else if(fillReject) {
190 fillHist2D(m_histRejectM[i],std::sqrt(static_cast<float>(invmass2)),std::sqrt(static_cast<float>(deltaR2)));
191 fillHist2D(m_histRejectEta1Eta2[i],(*tob1)->eta(),(*tob2)->eta());
192 }
193 TRG_MSG_DEBUG("Decision " << i << ": " << (accept?"pass":"fail") << " invmass2 = " << invmass2 << " deltaR2 = " << deltaR2 );
194 }
195 }
196 }
197 for (unsigned int i=0; i < numberOutputBits(); ++i) {
198 bool hasAmbiguousInputs = TSU::isAmbiguousTruncation(input[0], p_NumberLeading1, p_MinET1[i])
200 output[i]->setAmbiguityFlag(hasAmbiguousInputs);
201 }
202 } else {
203
204 TCS_EXCEPTION("InvariantMassInclusiveDeltaRSqrIncl1Charge alg must have either 1 inputs, but got " << input.size());
205
206 }
207
209
210}
211
213TCS::InvariantMassInclusiveDeltaRSqrIncl1Charge::process( const std::vector<TCS::TOBArray const *> & input,
214 const std::vector<TCS::TOBArray *> & output,
215 Decision & decision )
216{
217
218 if(input.size() == 1) {
219 for( TOBArray::const_iterator tob1 = input[0]->begin();
220 tob1 != input[0]->end() && distance( input[0]->begin(), tob1) < p_NumberLeading1;
221 ++tob1)
222 {
223
224
225 TCS::TOBArray::const_iterator tob2 = tob1; ++tob2;
226 for( ;
227 tob2 != input[0]->end() && distance( input[0]->begin(), tob2) < p_NumberLeading2;
228 ++tob2) {
229
230
231 // OneBarrel
232 if (p_OneBarrel && parType_t(std::abs((*tob1)->eta())) > 10 && parType_t(std::abs((*tob2)->eta())) > 10 ) continue;
233
234 // Inv Mass calculation
235 unsigned int invmass2 = calcInvMass( *tob1, *tob2 );
236 // test DeltaR2Min, DeltaR2Max
237 unsigned int deltaR2 = calcDeltaR2( *tob1, *tob2 );
238 TRG_MSG_DEBUG("Jet1 = " << **tob1 << ", Jet2 = " << **tob2 << ", invmass2 = " << invmass2 << ", deltaR2 = " << deltaR2);
239 // Charge cut ( 1 = positive, -1 = negative, 0 = undefined (RPC) )
240 int charge1 = (*tob1)->charge();
241 int charge2 = (*tob2)->charge();
242 int totalCharge = charge1 + charge2;
243 bool acceptCharge = true;
244 if ( std::abs(totalCharge) == 2 ) { acceptCharge = false; }
245 for(unsigned int i=0; i<numberOutputBits(); ++i) {
246 bool accept = false;
247 if( parType_t((*tob1)->Et()) <= std::min(p_MinET1[i],p_MinET2[i])) continue; // ET cut
248 if( parType_t((*tob2)->Et()) <= std::min(p_MinET1[i],p_MinET2[i])) continue; // ET cut
249 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;
250 accept = invmass2 >= p_InvMassMin[i] && invmass2 <= p_InvMassMax[i] && deltaR2 >= p_DeltaRMin[i] && deltaR2 <= p_DeltaRMax[i] && acceptCharge;
251 const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
252 const bool fillReject = fillHistos() and not fillAccept;
253 const bool alreadyFilled = decision.bit(i);
254 if( accept ) {
255 decision.setBit(i, true);
256 output[i]->push_back( TCS::CompositeTOB(*tob1, *tob2) );
257 }
258 if(fillAccept and not alreadyFilled) {
259 fillHist2D(m_histAcceptM[i],std::sqrt(static_cast<float>(invmass2)),std::sqrt(static_cast<float>(deltaR2)));
260 fillHist2D(m_histAcceptEta1Eta2[i],(*tob1)->eta(),(*tob2)->eta());
261 } else if(fillReject) {
262 fillHist2D(m_histRejectM[i],std::sqrt(static_cast<float>(invmass2)),std::sqrt(static_cast<float>(deltaR2)));
263 fillHist2D(m_histRejectEta1Eta2[i],(*tob1)->eta(),(*tob2)->eta());
264 }
265 TRG_MSG_DEBUG("Decision " << i << ": " << (accept?"pass":"fail") << " invmass2 = " << invmass2 << " deltaR2 = " << deltaR2 );
266 }
267 }
268 }
269 } else {
270
271 TCS_EXCEPTION("InvariantMassInclusiveDeltaRSqrIncl1Charge alg must have either 1 inputs, but got " << input.size());
272
273 }
274
276}
#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)
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)
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
virtual StatusCode process(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison) override final
virtual StatusCode processBitCorrect(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison) override final
uint32_t parType_t
Definition Parameter.h:22
bool isAmbiguousTruncation(TCS::TOBArray const *tobs, size_t pos, unsigned minEt=0)
STL namespace.