ATLAS Offline Software
Loading...
Searching...
No Matches
InvariantMassInclusive1.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 * InvariantMassInclusive1.cpp
6 * Created by V Sorin 2014.
7 *
8 * @brief algorithm calculates the sqr of the INVMASS between TOBs from one list and applies invmass criteria
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(InvariantMassInclusive1)
25
26
27// not the best solution but we will move to athena where this comes for free
28#define LOG cout << "TCS::InvariantMassInclusive1: "
29
31{
32 defineParameter("InputWidth", 3);
33 defineParameter("MaxTob", 0);
34 defineParameter("NumResultBits", 6);
35 defineParameter("RequireOneBarrel", 0);
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
61
63}
64
66
67
70 if(parameter("MaxTob").value() > 0) {
71 p_NumberLeading1 = parameter("MaxTob").value();
72 p_NumberLeading2 = parameter("MaxTob").value();
73 } else {
74 p_NumberLeading1 = parameter("InputWidth").value();
75 p_NumberLeading2 = parameter("InputWidth").value();
76 }
77
78 p_OneBarrel = parameter("RequireOneBarrel").value();
79
80 for(unsigned int i=0; i<numberOutputBits(); ++i) {
81 p_InvMassMin[i] = parameter("MinMSqr", i).value();
82 p_InvMassMax[i] = parameter("MaxMSqr", i).value();
83
84 p_MinET1[i] = parameter("MinET1",i).value();
85 p_MinET2[i] = parameter("MinET2",i).value();
86 }
87 TRG_MSG_INFO("NumberLeading1 : " << p_NumberLeading1);
88 TRG_MSG_INFO("NumberLeading2 : " << p_NumberLeading2);
89 TRG_MSG_INFO("RequireOneBarrel : " << p_OneBarrel);
90 for(unsigned int i=0; i<numberOutputBits(); ++i) {
91 TRG_MSG_INFO("InvMassMin : " << p_InvMassMin[i]);
92 TRG_MSG_INFO("InvMassMax : " << p_InvMassMax[i]);
93
94
95 TRG_MSG_INFO("MinET1 : " << p_MinET1[i]);
96 TRG_MSG_INFO("MinET2 : " << p_MinET2[i]);
97 }
98 TRG_MSG_INFO("number output : " << numberOutputBits());
99
100 // book histograms
101 for(unsigned int i=0; i<numberOutputBits(); ++i) {
102 std::string hname_accept = "hInvariantMassInclusive1_accept_bit"+std::to_string((int)i);
103 std::string hname_reject = "hInvariantMassInclusive1_reject_bit"+std::to_string((int)i);
104 // mass
105 bookHist(m_histAccept, hname_accept, "INVM", 100, sqrt(p_InvMassMin[i]), sqrt(p_InvMassMax[i]));
106 bookHist(m_histReject, hname_reject, "INVM", 100, sqrt(p_InvMassMin[i]), sqrt(p_InvMassMax[i]));
107 }
108
109 return StatusCode::SUCCESS;
110}
111
112
113
115TCS::InvariantMassInclusive1::processBitCorrect( const std::vector<TCS::TOBArray const *> & input,
116 const std::vector<TCS::TOBArray *> & output,
117 Decision & decision )
118{
119
120 if(input.size() == 1) {
121
122 for( TOBArray::const_iterator tob1 = input[0]->begin();
123 tob1 != input[0]->end() && distance( input[0]->begin(), tob1) < p_NumberLeading1;
124 ++tob1)
125 {
126
127
128 TCS::TOBArray::const_iterator tob2 = tob1; ++tob2;
129 for( ;
130 tob2 != input[0]->end() && distance( input[0]->begin(), tob2) < p_NumberLeading2;
131 ++tob2) {
132
133
134 // OneBarrel
135 if (p_OneBarrel && parType_t(abs((*tob1)->eta())) > 10 && parType_t(abs((*tob2)->eta())) > 10 ) continue;
136
137 // Inv Mass calculation
138 unsigned int invmass2 = calcInvMassBW( *tob1, *tob2 );
139 for(unsigned int i=0; i<numberOutputBits(); ++i) {
140 bool accept = false;
141 if( parType_t((*tob1)->Et()) <= std::min(p_MinET1[i],p_MinET2[i])) continue; // ET cut
142 if( parType_t((*tob2)->Et()) <= std::min(p_MinET1[i],p_MinET2[i])) continue; // ET cut
143 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;
144 accept = invmass2 >= p_InvMassMin[i] && invmass2 <= p_InvMassMax[i]; //
145 const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
146 const bool fillReject = fillHistos() and not fillAccept;
147 const bool alreadyFilled = decision.bit(i);
148 if( accept ) {
149 decision.setBit(i, true);
150 output[i]->push_back( TCS::CompositeTOB(*tob1, *tob2) );
151 }
152 if(fillAccept and not alreadyFilled) {
153 fillHist1D(m_histAccept[i],sqrt((float)invmass2));
154 } else if(fillReject) {
155 fillHist1D(m_histReject[i],sqrt((float)invmass2));
156 }
157 TRG_MSG_DEBUG("Decision " << i << ": " << (accept?"pass":"fail") << " invmass2 = " << invmass2);
158 }
159 }
160 }
161 for (unsigned int i=0; i < numberOutputBits(); ++i) {
162 bool hasAmbiguousInputs = TSU::isAmbiguousTruncation(input[0], p_NumberLeading1, p_MinET1[i])
164 output[i]->setAmbiguityFlag(hasAmbiguousInputs);
165 }
166 } else {
167
168 TCS_EXCEPTION("InvariantMassInclusive1 alg must have either 1 inputs, but got " << input.size());
169
170 }
171
173
174}
175
177TCS::InvariantMassInclusive1::process( const std::vector<TCS::TOBArray const *> & input,
178 const std::vector<TCS::TOBArray *> & output,
179 Decision & decision )
180{
181
182 if(input.size() == 1) {
183 for( TOBArray::const_iterator tob1 = input[0]->begin();
184 tob1 != input[0]->end() && distance( input[0]->begin(), tob1) < p_NumberLeading1;
185 ++tob1)
186 {
187
188
189 TCS::TOBArray::const_iterator tob2 = tob1; ++tob2;
190 for( ;
191 tob2 != input[0]->end() && distance( input[0]->begin(), tob2) < p_NumberLeading2;
192 ++tob2) {
193
194
195 // OneBarrel
196 if (p_OneBarrel && parType_t(abs((*tob1)->eta())) > 10 && parType_t(abs((*tob2)->eta())) > 10 ) continue;
197
198 // Inv Mass calculation
199
200 unsigned int invmass2 = calcInvMass( *tob1, *tob2 );
201
202
203 for(unsigned int i=0; i<numberOutputBits(); ++i) {
204 bool accept = false;
205 if( parType_t((*tob1)->Et()) <= std::min(p_MinET1[i],p_MinET2[i])) continue; // ET cut
206 if( parType_t((*tob2)->Et()) <= std::min(p_MinET1[i],p_MinET2[i])) continue; // ET cut
207 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;
208 accept = invmass2 >= p_InvMassMin[i] && invmass2 <= p_InvMassMax[i]; //
209 const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
210 const bool fillReject = fillHistos() and not fillAccept;
211 const bool alreadyFilled = decision.bit(i);
212 if( accept ) {
213 decision.setBit(i, true);
214 output[i]->push_back( TCS::CompositeTOB(*tob1, *tob2) );
215 }
216 if(fillAccept and not alreadyFilled) {
217 fillHist1D(m_histAccept[i],sqrt((float)invmass2));
218 } else if(fillReject) {
219 fillHist1D(m_histReject[i],sqrt((float)invmass2));
220 }
221 TRG_MSG_DEBUG("Decision " << i << ": " << (accept?"pass":"fail") << " invmass2 = " << invmass2);
222 }
223 }
224 }
225 } else {
226
227 TCS_EXCEPTION("InvariantMassInclusive1 alg must have either 1 inputs, but got " << input.size());
228
229 }
230
232}
#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)
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)
InvariantMassInclusive1(const std::string &name)
uint32_t parType_t
Definition Parameter.h:22
bool isAmbiguousTruncation(TCS::TOBArray const *tobs, size_t pos, unsigned minEt=0)