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"
31 
32 REGISTER_ALG_TCS(InvariantMassThreeTOBsIncl1)
33 
34 
36 {
37  defineParameter("InputWidth", 3);
38  defineParameter("MaxTob", 0);
39  defineParameter("NumResultBits", 6);
40  defineParameter("RequireOneBarrel", 0);
41  defineParameter("MinMSqr", 0, 0);
42  defineParameter("MaxMSqr", 999, 0);
43  defineParameter("MinMSqr", 0, 1);
44  defineParameter("MaxMSqr", 999, 1);
45  defineParameter("MinMSqr", 0, 2);
46  defineParameter("MaxMSqr", 999, 2);
47  defineParameter("MinMSqr", 0, 3);
48  defineParameter("MaxMSqr", 999, 3);
49  defineParameter("MinMSqr", 0, 4);
50  defineParameter("MaxMSqr", 999, 4);
51  defineParameter("MinMSqr", 0, 5);
52  defineParameter("MaxMSqr", 999, 5);
53  defineParameter("MinET1",0,0);
54  defineParameter("MinET1",0,1);
55  defineParameter("MinET1",0,2);
56  defineParameter("MinET1",0,3);
57  defineParameter("MinET1",0,4);
58  defineParameter("MinET1",0,5);
59 
60  setNumberOutputBits(6);
61 }
62 
64 
65 
68  if(parameter("MaxTob").value() > 0) {
69  p_NumberLeading1 = parameter("MaxTob").value();
70  } else {
71  p_NumberLeading1 = parameter("InputWidth").value();
72  }
73 
74  p_OneBarrel = parameter("RequireOneBarrel").value();
75 
76  for(unsigned int i=0; i<numberOutputBits(); ++i) {
77  p_InvMassMin[i] = parameter("MinMSqr", i).value();
78  p_InvMassMax[i] = parameter("MaxMSqr", i).value();
79 
80  p_MinET1[i] = parameter("MinET1",i).value();
81  }
82  TRG_MSG_INFO("NumberLeading1 : " << p_NumberLeading1);
83  TRG_MSG_INFO("RequireOneBarrel : " << p_OneBarrel);
84  for(unsigned int i=0; i<numberOutputBits(); ++i) {
85  TRG_MSG_INFO("InvMassMin : " << p_InvMassMin[i]);
86  TRG_MSG_INFO("InvMassMax : " << p_InvMassMax[i]);
87 
88  TRG_MSG_INFO("MinET1 : " << p_MinET1[i]);
89  }
90  TRG_MSG_INFO("number output : " << numberOutputBits());
91 
92  // book histograms
93  for(unsigned int i=0; i<numberOutputBits(); ++i) {
94  std::string hname_accept = "hInvariantMassThreeTOBsIncl1_accept_bit"+std::to_string((int)i);
95  std::string hname_reject = "hInvariantMassThreeTOBsIncl1_reject_bit"+std::to_string((int)i);
96  // mass
97  bookHist(m_histAccept, hname_accept, "INVM", 100, sqrt(p_InvMassMin[i]), sqrt(p_InvMassMax[i]));
98  bookHist(m_histReject, hname_reject, "INVM", 100, sqrt(p_InvMassMin[i]), sqrt(p_InvMassMax[i]));
99  }
100 
101 
102 
103  return StatusCode::SUCCESS;
104 }
105 
106 
107 
109 TCS::InvariantMassThreeTOBsIncl1::processBitCorrect( const std::vector<TCS::TOBArray const *> & input,
110  const std::vector<TCS::TOBArray *> & output,
111  Decision & decision )
112 {
113 
114  if(input.size() == 1) {
115 
116  for( TOBArray::const_iterator tob1 = input[0]->begin();
117  tob1 != input[0]->end() && distance( input[0]->begin(), tob1) < p_NumberLeading1;
118  ++tob1)
119  {
120 
121  TCS::TOBArray::const_iterator tob2 = tob1; ++tob2;
122  for( ;
123  tob2 != input[0]->end() && distance( input[0]->begin(), tob2) < p_NumberLeading1;
124  ++tob2) {
125 
126  TCS::TOBArray::const_iterator tob3 = tob2; ++tob3;
127  for( ;
128  tob3 != input[0]->end() && distance( input[0]->begin(), tob3) < p_NumberLeading1;
129  ++tob3) {
130 
131  // OneBarrel
132  if (p_OneBarrel && parType_t(abs((*tob1)->eta())) > 10 && parType_t(abs((*tob2)->eta())) > 10 && parType_t(abs((*tob3)->eta())) > 10 ) continue;
133 
134  // Inv Mass calculation
135  unsigned int invmass2_12 = calcInvMassBW( *tob1, *tob2 );
136  unsigned int invmass2_13 = calcInvMassBW( *tob1, *tob3 );
137  unsigned int invmass2_23 = calcInvMassBW( *tob2, *tob3 );
138  unsigned int invmass2 = invmass2_12 + invmass2_13 + invmass2_23;
139  for(unsigned int i=0; i<numberOutputBits(); ++i) {
140  bool accept = false;
141  if( parType_t((*tob1)->Et()) <= p_MinET1[i]) continue; // ET cut
142  if( parType_t((*tob2)->Et()) <= p_MinET1[i]) continue; // ET cut
143  if( parType_t((*tob3)->Et()) <= p_MinET1[i]) continue; // ET cut
144 
145  accept = invmass2 >= p_InvMassMin[i] && invmass2 <= p_InvMassMax[i]; //
146  const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
147  const bool fillReject = fillHistos() and not fillAccept;
148  const bool alreadyFilled = decision.bit(i);
149  if( accept ) {
150  std::vector<TCS::GenericTOB*> TOBvector;
151  TOBvector.push_back( *tob1 );
152  TOBvector.push_back( *tob2 );
153  TOBvector.push_back( *tob3 );
154  decision.setBit(i, true);
155  output[i]->push_back( TCS::CompositeTOB(TOBvector) ); //??? Is this going to work? Originally CompositeTOB(*tob1, *tob2)
156  TOBvector.clear();
157  }
158  if(fillAccept and not alreadyFilled) {
159  fillHist1D(m_histAccept[i],sqrt(invmass2));
160  } else if(fillReject) {
161  fillHist1D(m_histReject[i],sqrt(invmass2));
162  }
163  TRG_MSG_DEBUG("Decision " << i << ": " << (accept?"pass":"fail") << " invmass2 = " << invmass2);
164 
165  }
166  }
167  }
168  }
169  for (unsigned int i=0; i < numberOutputBits(); ++i) {
170  bool hasAmbiguousInputs = TSU::isAmbiguousTruncation(input[0], p_NumberLeading1, p_MinET1[i]);
171  output[i]->setAmbiguityFlag(hasAmbiguousInputs);
172  }
173  } else {
174 
175  TCS_EXCEPTION("InvariantMassThreeTOBsIncl1 alg must have 1 input list, but got " << input.size());
176 
177  }
178 
180 
181 }
182 
184 TCS::InvariantMassThreeTOBsIncl1::process( const std::vector<TCS::TOBArray const *> & input,
185  const std::vector<TCS::TOBArray *> & output,
186  Decision & decision )
187 {
188 
189  if(input.size() == 1) {
190  for( TOBArray::const_iterator tob1 = input[0]->begin();
191  tob1 != input[0]->end() && distance( input[0]->begin(), tob1) < p_NumberLeading1;
192  ++tob1)
193  {
194 
195 
196  TCS::TOBArray::const_iterator tob2 = tob1; ++tob2;
197  for( ;
198  tob2 != input[0]->end() && distance( input[0]->begin(), tob2) < p_NumberLeading1;
199  ++tob2) {
200 
201  TCS::TOBArray::const_iterator tob3 = tob2; ++tob3;
202  for( ;
203  tob3 != input[0]->end() && distance( input[0]->begin(), tob3) < p_NumberLeading1;
204  ++tob3) {
205 
206  // OneBarrel
207  if (p_OneBarrel && parType_t(abs((*tob1)->eta())) > 10 && parType_t(abs((*tob2)->eta())) > 10 && parType_t(abs((*tob3)->eta())) > 10 ) continue;
208 
209  // Inv Mass calculation
210 
211  unsigned int invmass2_12 = calcInvMass( *tob1, *tob2 );
212  unsigned int invmass2_13 = calcInvMass( *tob1, *tob3 );
213  unsigned int invmass2_23 = calcInvMass( *tob2, *tob3 );
214  unsigned int invmass2 = invmass2_12 + invmass2_13 + invmass2_23;
215  for(unsigned int i=0; i<numberOutputBits(); ++i) {
216  bool accept = false;
217  if( parType_t((*tob1)->Et()) <= p_MinET1[i]) continue; // ET cut
218  if( parType_t((*tob2)->Et()) <= p_MinET1[i]) continue; // ET cut
219  if( parType_t((*tob3)->Et()) <= p_MinET1[i]) continue; // ET cut
220 
221  accept = invmass2 >= p_InvMassMin[i] && invmass2 <= p_InvMassMax[i]; //
222  const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
223  const bool fillReject = fillHistos() and not fillAccept;
224  const bool alreadyFilled = decision.bit(i);
225  if( accept ) {
226  std::vector<TCS::GenericTOB*> TOBvector;
227  TOBvector.push_back( *tob1 );
228  TOBvector.push_back( *tob2 );
229  TOBvector.push_back( *tob3 );
230  decision.setBit(i, true);
231  output[i]->push_back( TCS::CompositeTOB(TOBvector) ); // Check that this won't crush
232  TOBvector.clear();
233  }
234  if(fillAccept and not alreadyFilled) {
235  fillHist1D(m_histAccept[i],sqrt(invmass2));
236  } else if(fillReject) {
237  fillHist1D(m_histReject[i],sqrt(invmass2));
238  }
239  TRG_MSG_DEBUG("Decision " << i << ": " << (accept?"pass":"fail") << " invmass2 = " << invmass2);
240 
241  }
242  }
243  }
244  }
245  } else {
246 
247  TCS_EXCEPTION("InvariantMassThreeTOBsIncl1 alg must have either 1 input list, but got " << input.size());
248 
249  }
250 
252 }
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:184
TSU::isAmbiguousTruncation
bool isAmbiguousTruncation(TCS::TOBArray const *tobs, size_t pos, unsigned minEt=0)
Definition: Trigger/TrigT1/L1Topo/L1TopoSimulationUtils/Root/Helpers.cxx:23
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
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:109
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
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:63
TRG_MSG_INFO
#define TRG_MSG_INFO(x)
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStreamMacros.h:27
REGISTER_ALG_TCS
#define REGISTER_ALG_TCS(CLASS)
Definition: AlgFactory.h:62
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
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:67
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
Helpers.h
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