ATLAS Offline Software
InvariantMassThreeTOBsIncl1.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  * InvariantMassThreeTOBsIncl1.cxx
6  * Created by Carlos Moreno based on InvariantMassInclusive1 by V Sorin
7  *
8  * For questions contact atlas-trig-l1topo-algcom@cern.ch.
9  * @brief algorithm calculates the sqr of the INVMASS of three TOBs from one list and applies invmass criteria
10  *
11  * @param NumberLeading
12  *
13  * First version assuming same cuts in all TOBs. If we'd like to have a version similar to *INVM*-MU4ab-MU6ab-MU10ab
14  * we'll need to change the following:
15  * p_NumberLeading* will need to be added to account for the different lists. This could help to have something like *INVM*-2MU4ab-MU6ab
16  * MinET2,3 will need to be added to apply the different cuts on the lists
17 **********************************/
18 
19 // TO DO size of the input list to be possbly refined
20 
21 #include <cmath>
22 #include <string>
23 #include <iostream>
24 #include <sstream>
25 #include <vector>
26 
28 #include "L1TopoCommon/Exception.h"
30 
31 REGISTER_ALG_TCS(InvariantMassThreeTOBsIncl1)
32 
33 
35 {
36  defineParameter("InputWidth", 3);
37  defineParameter("MaxTob", 0);
38  defineParameter("NumResultBits", 6);
39  defineParameter("RequireOneBarrel", 0);
40  defineParameter("MinMSqr", 0, 0);
41  defineParameter("MaxMSqr", 999, 0);
42  defineParameter("MinMSqr", 0, 1);
43  defineParameter("MaxMSqr", 999, 1);
44  defineParameter("MinMSqr", 0, 2);
45  defineParameter("MaxMSqr", 999, 2);
46  defineParameter("MinMSqr", 0, 3);
47  defineParameter("MaxMSqr", 999, 3);
48  defineParameter("MinMSqr", 0, 4);
49  defineParameter("MaxMSqr", 999, 4);
50  defineParameter("MinMSqr", 0, 5);
51  defineParameter("MaxMSqr", 999, 5);
52  defineParameter("MinET1",0,0);
53  defineParameter("MinET1",0,1);
54  defineParameter("MinET1",0,2);
55  defineParameter("MinET1",0,3);
56  defineParameter("MinET1",0,4);
57  defineParameter("MinET1",0,5);
58 
59  setNumberOutputBits(6);
60 }
61 
63 
64 
67  if(parameter("MaxTob").value() > 0) {
68  p_NumberLeading1 = parameter("MaxTob").value();
69  } else {
70  p_NumberLeading1 = parameter("InputWidth").value();
71  }
72 
73  p_OneBarrel = parameter("RequireOneBarrel").value();
74 
75  for(unsigned int i=0; i<numberOutputBits(); ++i) {
76  p_InvMassMin[i] = parameter("MinMSqr", i).value();
77  p_InvMassMax[i] = parameter("MaxMSqr", i).value();
78 
79  p_MinET1[i] = parameter("MinET1",i).value();
80  }
81  TRG_MSG_INFO("NumberLeading1 : " << p_NumberLeading1);
82  TRG_MSG_INFO("RequireOneBarrel : " << p_OneBarrel);
83  for(unsigned int i=0; i<numberOutputBits(); ++i) {
84  TRG_MSG_INFO("InvMassMin : " << p_InvMassMin[i]);
85  TRG_MSG_INFO("InvMassMax : " << p_InvMassMax[i]);
86 
87  TRG_MSG_INFO("MinET1 : " << p_MinET1[i]);
88  }
89  TRG_MSG_INFO("number output : " << numberOutputBits());
90 
91  // book histograms
92  for(unsigned int i=0; i<numberOutputBits(); ++i) {
93  std::string hname_accept = "hInvariantMassThreeTOBsIncl1_accept_bit"+std::to_string((int)i);
94  std::string hname_reject = "hInvariantMassThreeTOBsIncl1_reject_bit"+std::to_string((int)i);
95  // mass
96  bookHist(m_histAccept, hname_accept, "INVM", 100, sqrt(p_InvMassMin[i]), sqrt(p_InvMassMax[i]));
97  bookHist(m_histReject, hname_reject, "INVM", 100, sqrt(p_InvMassMin[i]), sqrt(p_InvMassMax[i]));
98  }
99 
100 
101 
102  return StatusCode::SUCCESS;
103 }
104 
105 
106 
108 TCS::InvariantMassThreeTOBsIncl1::processBitCorrect( const std::vector<TCS::TOBArray const *> & input,
109  const std::vector<TCS::TOBArray *> & output,
110  Decision & decision )
111 {
112 
113  if(input.size() == 1) {
114 
115  for( TOBArray::const_iterator tob1 = input[0]->begin();
116  tob1 != input[0]->end() && distance( input[0]->begin(), tob1) < p_NumberLeading1;
117  ++tob1)
118  {
119 
120  TCS::TOBArray::const_iterator tob2 = tob1; ++tob2;
121  for( ;
122  tob2 != input[0]->end() && distance( input[0]->begin(), tob2) < p_NumberLeading1;
123  ++tob2) {
124 
125  TCS::TOBArray::const_iterator tob3 = tob2; ++tob3;
126  for( ;
127  tob3 != input[0]->end() && distance( input[0]->begin(), tob3) < p_NumberLeading1;
128  ++tob3) {
129 
130  // OneBarrel
131  if (p_OneBarrel && parType_t(abs((*tob1)->eta())) > 10 && parType_t(abs((*tob2)->eta())) > 10 && parType_t(abs((*tob3)->eta())) > 10 ) continue;
132 
133  // Inv Mass calculation
134  unsigned int invmass2_12 = calcInvMassBW( *tob1, *tob2 );
135  unsigned int invmass2_13 = calcInvMassBW( *tob1, *tob3 );
136  unsigned int invmass2_23 = calcInvMassBW( *tob2, *tob3 );
137  unsigned int invmass2 = invmass2_12 + invmass2_13 + invmass2_23;
138  for(unsigned int i=0; i<numberOutputBits(); ++i) {
139  bool accept = false;
140  if( parType_t((*tob1)->Et()) <= p_MinET1[i]) continue; // ET cut
141  if( parType_t((*tob2)->Et()) <= p_MinET1[i]) continue; // ET cut
142  if( parType_t((*tob3)->Et()) <= p_MinET1[i]) continue; // ET cut
143 
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  std::vector<TCS::GenericTOB*> TOBvector;
150  TOBvector.push_back( *tob1 );
151  TOBvector.push_back( *tob2 );
152  TOBvector.push_back( *tob3 );
153  decision.setBit(i, true);
154  output[i]->push_back( TCS::CompositeTOB(TOBvector) ); //??? Is this going to work? Originally CompositeTOB(*tob1, *tob2)
155  TOBvector.clear();
156  }
157  if(fillAccept and not alreadyFilled) {
158  fillHist1D(m_histAccept[i],sqrt(invmass2));
159  } else if(fillReject) {
160  fillHist1D(m_histReject[i],sqrt(invmass2));
161  }
162  TRG_MSG_DEBUG("Decision " << i << ": " << (accept?"pass":"fail") << " invmass2 = " << invmass2);
163 
164  }
165  }
166  }
167  }
168  } else {
169 
170  TCS_EXCEPTION("InvariantMassThreeTOBsIncl1 alg must have 1 input list, but got " << input.size());
171 
172  }
173 
175 
176 }
177 
179 TCS::InvariantMassThreeTOBsIncl1::process( const std::vector<TCS::TOBArray const *> & input,
180  const std::vector<TCS::TOBArray *> & output,
181  Decision & decision )
182 {
183 
184  if(input.size() == 1) {
185  for( TOBArray::const_iterator tob1 = input[0]->begin();
186  tob1 != input[0]->end() && distance( input[0]->begin(), tob1) < p_NumberLeading1;
187  ++tob1)
188  {
189 
190 
191  TCS::TOBArray::const_iterator tob2 = tob1; ++tob2;
192  for( ;
193  tob2 != input[0]->end() && distance( input[0]->begin(), tob2) < p_NumberLeading1;
194  ++tob2) {
195 
196  TCS::TOBArray::const_iterator tob3 = tob2; ++tob3;
197  for( ;
198  tob3 != input[0]->end() && distance( input[0]->begin(), tob3) < p_NumberLeading1;
199  ++tob3) {
200 
201  // OneBarrel
202  if (p_OneBarrel && parType_t(abs((*tob1)->eta())) > 10 && parType_t(abs((*tob2)->eta())) > 10 && parType_t(abs((*tob3)->eta())) > 10 ) continue;
203 
204  // Inv Mass calculation
205 
206  unsigned int invmass2_12 = calcInvMass( *tob1, *tob2 );
207  unsigned int invmass2_13 = calcInvMass( *tob1, *tob3 );
208  unsigned int invmass2_23 = calcInvMass( *tob2, *tob3 );
209  unsigned int invmass2 = invmass2_12 + invmass2_13 + invmass2_23;
210  for(unsigned int i=0; i<numberOutputBits(); ++i) {
211  bool accept = false;
212  if( parType_t((*tob1)->Et()) <= p_MinET1[i]) continue; // ET cut
213  if( parType_t((*tob2)->Et()) <= p_MinET1[i]) continue; // ET cut
214  if( parType_t((*tob3)->Et()) <= p_MinET1[i]) continue; // ET cut
215 
216  accept = invmass2 >= p_InvMassMin[i] && invmass2 <= p_InvMassMax[i]; //
217  const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
218  const bool fillReject = fillHistos() and not fillAccept;
219  const bool alreadyFilled = decision.bit(i);
220  if( accept ) {
221  std::vector<TCS::GenericTOB*> TOBvector;
222  TOBvector.push_back( *tob1 );
223  TOBvector.push_back( *tob2 );
224  TOBvector.push_back( *tob3 );
225  decision.setBit(i, true);
226  output[i]->push_back( TCS::CompositeTOB(TOBvector) ); // Check that this won't crush
227  TOBvector.clear();
228  }
229  if(fillAccept and not alreadyFilled) {
230  fillHist1D(m_histAccept[i],sqrt(invmass2));
231  } else if(fillReject) {
232  fillHist1D(m_histReject[i],sqrt(invmass2));
233  }
234  TRG_MSG_DEBUG("Decision " << i << ": " << (accept?"pass":"fail") << " invmass2 = " << invmass2);
235 
236  }
237  }
238  }
239  }
240  } else {
241 
242  TCS_EXCEPTION("InvariantMassThreeTOBsIncl1 alg must have either 1 input list, but got " << input.size());
243 
244  }
245 
247 }
TCS::InvariantMassThreeTOBsIncl1
Definition: InvariantMassThreeTOBsIncl1.h:16
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
CutsMETMaker::accept
StatusCode accept(const xAOD::Muon *mu)
Definition: CutsMETMaker.cxx:18
TCS::InvariantMassThreeTOBsIncl1::process
virtual StatusCode process(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison) override final
Definition: InvariantMassThreeTOBsIncl1.cxx:179
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
athena.value
value
Definition: athena.py:122
Decision.h
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:562
TCS::DecisionAlg
Definition: Trigger/TrigT1/L1Topo/L1TopoInterfaces/L1TopoInterfaces/DecisionAlg.h:22
TCS::InvariantMassThreeTOBsIncl1::processBitCorrect
virtual StatusCode processBitCorrect(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison) override final
Definition: InvariantMassThreeTOBsIncl1.cxx:108
TCS::Decision::setBit
void setBit(unsigned int index, bool value)
Definition: L1Topo/L1TopoInterfaces/Root/Decision.cxx:12
lumiFormat.i
int i
Definition: lumiFormat.py:92
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
TCS::InvariantMassThreeTOBsIncl1::~InvariantMassThreeTOBsIncl1
virtual ~InvariantMassThreeTOBsIncl1()
Definition: InvariantMassThreeTOBsIncl1.cxx:62
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:195
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
InvariantMassThreeTOBsIncl1.h
TCS::InvariantMassThreeTOBsIncl1::initialize
virtual StatusCode initialize() override final
Definition: InvariantMassThreeTOBsIncl1.cxx:66
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
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
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