ATLAS Offline Software
InvariantMassInclusiveDeltaRSqrIncl1.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  * Based on InvariantMassInclusive1 and DeltaRSqrIncl1. 01/03/2019.
6  * Created by V Sorin and Joerg Stelzer 2014.
7  *
8  * @brief algorithm calculates the sqr of the INVMASS and DeltaR between one list and applies invmass and deltaR criteria
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 
21 #include "L1TopoCommon/Exception.h"
23 
24 
25 REGISTER_ALG_TCS(InvariantMassInclusiveDeltaRSqrIncl1)
26 
27 
29 {
30  defineParameter("InputWidth", 3);
31  defineParameter("MaxTob", 0);
32  defineParameter("NumResultBits", 6);
33  defineParameter("RequireOneBarrel", 0);
34  defineParameter("MinMSqr", 0, 0);
35  defineParameter("MaxMSqr", 999, 0);
36  defineParameter("MinMSqr", 0, 1);
37  defineParameter("MaxMSqr", 999, 1);
38  defineParameter("MinMSqr", 0, 2);
39  defineParameter("MaxMSqr", 999, 2);
40  defineParameter("MinMSqr", 0, 3);
41  defineParameter("MaxMSqr", 999, 3);
42  defineParameter("MinMSqr", 0, 4);
43  defineParameter("MaxMSqr", 999, 4);
44  defineParameter("MinMSqr", 0, 5);
45  defineParameter("MaxMSqr", 999, 5);
46  defineParameter("MinET1",0,0);
47  defineParameter("MinET2",0,0);
48  defineParameter("MinET1",0,1);
49  defineParameter("MinET2",0,1);
50  defineParameter("MinET1",0,2);
51  defineParameter("MinET2",0,2);
52  defineParameter("MinET1",0,3);
53  defineParameter("MinET2",0,3);
54  defineParameter("MinET1",0,4);
55  defineParameter("MinET2",0,4);
56  defineParameter("MinET1",0,5);
57  defineParameter("MinET2",0,5);
58  defineParameter("DeltaRMin", 0, 0);
59  defineParameter("DeltaRMax", 0, 0);
60  defineParameter("DeltaRMin", 0, 1);
61  defineParameter("DeltaRMax", 0, 1);
62  defineParameter("DeltaRMin", 0, 2);
63  defineParameter("DeltaRMax", 0, 2);
64  defineParameter("DeltaRMin", 0, 3);
65  defineParameter("DeltaRMax", 0, 3);
66  defineParameter("DeltaRMin", 0, 4);
67  defineParameter("DeltaRMax", 0, 4);
68  defineParameter("DeltaRMin", 0, 5);
69  defineParameter("DeltaRMax", 0, 5);
70 
71 
72  setNumberOutputBits(6);
73 }
74 
76 
77 
80  if(parameter("MaxTob").value() > 0) {
81  p_NumberLeading1 = parameter("MaxTob").value();
82  p_NumberLeading2 = parameter("MaxTob").value();
83  } else {
84  p_NumberLeading1 = parameter("InputWidth").value();
85  p_NumberLeading2 = parameter("InputWidth").value();
86  }
87 
88  p_OneBarrel = parameter("RequireOneBarrel").value();
89 
90  TRG_MSG_INFO("NumberLeading1 : " << p_NumberLeading1);
91  TRG_MSG_INFO("NumberLeading2 : " << p_NumberLeading2);
92  TRG_MSG_INFO("RequireOneBarrel : " << p_OneBarrel);
93 
94  for(unsigned int i=0; i<numberOutputBits(); ++i) {
95  p_InvMassMin[i] = parameter("MinMSqr", i).value();
96  p_InvMassMax[i] = parameter("MaxMSqr", i).value();
97  p_DeltaRMin[i] = parameter("DeltaRMin", i).value();
98  p_DeltaRMax[i] = parameter("DeltaRMax", i).value();
99  p_MinET1[i] = parameter("MinET1",i).value();
100  p_MinET2[i] = parameter("MinET2",i).value();
101 
102  TRG_MSG_INFO("InvMassMin "<< i << " : " << p_InvMassMin[i]);
103  TRG_MSG_INFO("InvMassMax "<< i << " : " << p_InvMassMax[i]);
104  TRG_MSG_INFO("MinET1 "<< i << " : " << p_MinET1[i]);
105  TRG_MSG_INFO("MinET2 "<< i << " : " << p_MinET2[i]);
106  TRG_MSG_INFO("DeltaRMin "<< i << " : " << p_DeltaRMin[i]);
107  TRG_MSG_INFO("DeltaRMax "<< i << " : " << p_DeltaRMax[i]);
108  }
109 
110  TRG_MSG_INFO("number output : " << numberOutputBits());
111 
112  // book histograms
113  for(unsigned int i=0; i<numberOutputBits(); ++i) {
114  std::string hname_accept = "hInvariantMassInclusiveDeltaRSqrIncl1_accept_bit"+std::to_string((int)i);
115  std::string hname_reject = "hInvariantMassInclusiveDeltaRSqrIncl1_reject_bit"+std::to_string((int)i);
116  // mass
117  bookHist(m_histAcceptM, hname_accept, "INVM vs DR", 100, sqrt(p_InvMassMin[i]), sqrt(p_InvMassMax[i]), 100, sqrt(p_DeltaRMin[i]), sqrt(p_DeltaRMax[i]));
118  bookHist(m_histRejectM, hname_reject, "INVM vs DR", 100, sqrt(p_InvMassMin[i]), sqrt(p_InvMassMax[i]), 100, sqrt(p_DeltaRMin[i]), sqrt(p_DeltaRMax[i]));
119 
120  }
121 
122  return StatusCode::SUCCESS;
123 }
124 
125 
126 
128 TCS::InvariantMassInclusiveDeltaRSqrIncl1::processBitCorrect( const std::vector<TCS::TOBArray const *> & input,
129  const std::vector<TCS::TOBArray *> & output,
130  Decision & decision )
131 {
132 
133  if(input.size() == 1) {
134 
135  for( TOBArray::const_iterator tob1 = input[0]->begin();
136  tob1 != input[0]->end() && distance( input[0]->begin(), tob1) < p_NumberLeading1;
137  ++tob1)
138  {
139 
140 
141  TCS::TOBArray::const_iterator tob2 = tob1; ++tob2;
142  for( ;
143  tob2 != input[0]->end() && distance( input[0]->begin(), tob2) < p_NumberLeading2;
144  ++tob2) {
145 
146 
147  // OneBarrel
148  if (p_OneBarrel && parType_t(abs((*tob1)->eta())) > 10 && parType_t(abs((*tob2)->eta())) > 10 ) continue;
149 
150  // Inv Mass calculation
151  unsigned int invmass2 = calcInvMassBW( *tob1, *tob2 );
152  // test DeltaR2Min, DeltaR2Max
153  unsigned int deltaR2 = calcDeltaR2BW( *tob1, *tob2 );
154  TRG_MSG_DEBUG("Jet1 = " << **tob1 << ", Jet2 = " << **tob2 << ", invmass2 = " << invmass2 << ", deltaR2 = " << deltaR2);
155  for(unsigned int i=0; i<numberOutputBits(); ++i) {
156  bool accept = false;
157  if( parType_t((*tob1)->Et()) <= std::min(p_MinET1[i],p_MinET2[i])) continue; // ET cut
158  if( parType_t((*tob2)->Et()) <= std::min(p_MinET1[i],p_MinET2[i])) continue; // ET cut
159  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;
160  accept = invmass2 >= p_InvMassMin[i] && invmass2 <= p_InvMassMax[i] && deltaR2 >= p_DeltaRMin[i] && deltaR2 <= p_DeltaRMax[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  fillHist2D(m_histAcceptM[i],sqrt((float)invmass2),sqrt((float)deltaR2));
170  } else if(fillReject) {
171  fillHist2D(m_histRejectM[i],sqrt((float)invmass2),sqrt((float)deltaR2));
172  }
173  TRG_MSG_DEBUG("Decision " << i << ": " << (accept?"pass":"fail") << " invmass2 = " << invmass2 << " deltaR2 = " << deltaR2 );
174  }
175  }
176  }
177  } else {
178 
179  TCS_EXCEPTION("InvariantMassInclusiveDeltaRSqrIncl1 alg must have either 1 inputs, but got " << input.size());
180 
181  }
182 
184 
185 }
186 
188 TCS::InvariantMassInclusiveDeltaRSqrIncl1::process( const std::vector<TCS::TOBArray const *> & input,
189  const std::vector<TCS::TOBArray *> & output,
190  Decision & decision )
191 {
192 
193  if(input.size() == 1) {
194  for( TOBArray::const_iterator tob1 = input[0]->begin();
195  tob1 != input[0]->end() && distance( input[0]->begin(), tob1) < p_NumberLeading1;
196  ++tob1)
197  {
198 
199 
200  TCS::TOBArray::const_iterator tob2 = tob1; ++tob2;
201  for( ;
202  tob2 != input[0]->end() && distance( input[0]->begin(), tob2) < p_NumberLeading2;
203  ++tob2) {
204 
205 
206  // OneBarrel
207  if (p_OneBarrel && parType_t(abs((*tob1)->eta())) > 10 && parType_t(abs((*tob2)->eta())) > 10 ) continue;
208 
209  // Inv Mass calculation
210  unsigned int invmass2 = calcInvMass( *tob1, *tob2 );
211  // test DeltaR2Min, DeltaR2Max
212  unsigned int deltaR2 = calcDeltaR2( *tob1, *tob2 );
213  TRG_MSG_DEBUG("Jet1 = " << **tob1 << ", Jet2 = " << **tob2 << ", invmass2 = " << invmass2 << ", deltaR2 = " << deltaR2);
214 
215  for(unsigned int i=0; i<numberOutputBits(); ++i) {
216  bool accept = false;
217  if( parType_t((*tob1)->Et()) <= std::min(p_MinET1[i],p_MinET2[i])) continue; // ET cut
218  if( parType_t((*tob2)->Et()) <= std::min(p_MinET1[i],p_MinET2[i])) continue; // ET cut
219  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;
220  accept = invmass2 >= p_InvMassMin[i] && invmass2 <= p_InvMassMax[i] && deltaR2 >= p_DeltaRMin[i] && deltaR2 <= p_DeltaRMax[i];
221  const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
222  const bool fillReject = fillHistos() and not fillAccept;
223  const bool alreadyFilled = decision.bit(i);
224  if( accept ) {
225  decision.setBit(i, true);
226  output[i]->push_back( TCS::CompositeTOB(*tob1, *tob2) );
227  }
228  if(fillAccept and not alreadyFilled) {
229  fillHist2D(m_histAcceptM[i],sqrt((float)invmass2),sqrt((float)deltaR2));
230  } else if(fillReject) {
231  fillHist2D(m_histRejectM[i],sqrt((float)invmass2),sqrt((float)deltaR2));
232  }
233  TRG_MSG_DEBUG("Decision " << i << ": " << (accept?"pass":"fail") << " invmass2 = " << invmass2 << " deltaR2 = " << deltaR2 );
234  }
235  }
236  }
237  } else {
238 
239  TCS_EXCEPTION("InvariantMassInclusiveDeltaRSqrIncl1 alg must have either 1 inputs, but got " << input.size());
240 
241  }
242 
244 }
TCS::StatusCode::SUCCESS
@ SUCCESS
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/L1TopoCommon/StatusCode.h:17
TCS::parType_t
uint32_t parType_t
Definition: Parameter.h:22
TCS::DataArrayImpl< GenericTOB >::const_iterator
data_t::const_iterator const_iterator
Definition: DataArrayImpl.h:18
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
CutsMETMaker::accept
StatusCode accept(const xAOD::Muon *mu)
Definition: CutsMETMaker.cxx:18
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
athena.value
value
Definition: athena.py:124
Decision.h
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:560
xAOD::P4Helpers::deltaR2
double deltaR2(double rapidity1, double phi1, double rapidity2, double phi2)
from bare rapidity,phi
Definition: xAODP4Helpers.h:111
TCS::InvariantMassInclusiveDeltaRSqrIncl1::process
virtual StatusCode process(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison) override final
Definition: InvariantMassInclusiveDeltaRSqrIncl1.cxx:188
TCS::DecisionAlg
Definition: Trigger/TrigT1/L1Topo/L1TopoInterfaces/L1TopoInterfaces/DecisionAlg.h:22
TCS::InvariantMassInclusiveDeltaRSqrIncl1::initialize
virtual StatusCode initialize() override final
Definition: InvariantMassInclusiveDeltaRSqrIncl1.cxx:79
InvariantMassInclusiveDeltaRSqrIncl1.h
TCS::Decision::setBit
void setBit(unsigned int index, bool value)
Definition: L1Topo/L1TopoInterfaces/Root/Decision.cxx:12
lumiFormat.i
int i
Definition: lumiFormat.py:85
TCS::CompositeTOB
Definition: CompositeTOB.h:16
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
TCS_EXCEPTION
#define TCS_EXCEPTION(MSG)
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/L1TopoCommon/Exception.h:14
TCS::Decision
Definition: L1Topo/L1TopoInterfaces/L1TopoInterfaces/Decision.h:19
TRG_MSG_INFO
#define TRG_MSG_INFO(x)
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStreamMacros.h:27
merge.output
output
Definition: merge.py:17
REGISTER_ALG_TCS
#define REGISTER_ALG_TCS(CLASS)
Definition: AlgFactory.h:62
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
TCS
Definition: Global/GlobalSimulation/src/IO/Decision.h:18
TCS::Decision::bit
bool bit(unsigned int index) const
Definition: L1Topo/L1TopoInterfaces/L1TopoInterfaces/Decision.h:40
TCS::InvariantMassInclusiveDeltaRSqrIncl1::processBitCorrect
virtual StatusCode processBitCorrect(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison) override final
Definition: InvariantMassInclusiveDeltaRSqrIncl1.cxx:128
Exception.h
Amg::distance
float distance(const Amg::Vector3D &p1, const Amg::Vector3D &p2)
calculates the distance between two point in 3D space
Definition: GeoPrimitivesHelpers.h:54
TCS::InvariantMassInclusiveDeltaRSqrIncl1::~InvariantMassInclusiveDeltaRSqrIncl1
virtual ~InvariantMassInclusiveDeltaRSqrIncl1()
Definition: InvariantMassInclusiveDeltaRSqrIncl1.cxx:75
TRG_MSG_DEBUG
#define TRG_MSG_DEBUG(x)
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStreamMacros.h:25
TCS::StatusCode
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/L1TopoCommon/StatusCode.h:15
TCS::InvariantMassInclusiveDeltaRSqrIncl1
Definition: InvariantMassInclusiveDeltaRSqrIncl1.h:18