ATLAS Offline Software
InvariantMassThreeTOBsIncl1Charge.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  * InvariantMassThreeTOBsIncl1Charge.cxx
6  * Created by Paula Martinez 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  * Events containing 3 TGC muons with same charge are rejected
11  *
12  * @param NumberLeading
13  *
14  * First version assuming same cuts in all TOBs.
15 **********************************/
16 
17 // TO DO size of the input list to be possibly refined
18 
19 #include <cmath>
20 #include <string>
21 #include <iostream>
22 #include <sstream>
23 #include <vector>
24 
26 #include "L1TopoCommon/Exception.h"
28 
29 
30 REGISTER_ALG_TCS(InvariantMassThreeTOBsIncl1Charge)
31 
32 
34 {
35  defineParameter("InputWidth", 3);
36  defineParameter("MaxTob", 0);
37  defineParameter("NumResultBits", 6);
38  defineParameter("RequireOneBarrel", 0);
39  defineParameter("MinMSqr", 0, 0);
40  defineParameter("MaxMSqr", 999, 0);
41  defineParameter("MinMSqr", 0, 1);
42  defineParameter("MaxMSqr", 999, 1);
43  defineParameter("MinMSqr", 0, 2);
44  defineParameter("MaxMSqr", 999, 2);
45  defineParameter("MinMSqr", 0, 3);
46  defineParameter("MaxMSqr", 999, 3);
47  defineParameter("MinMSqr", 0, 4);
48  defineParameter("MaxMSqr", 999, 4);
49  defineParameter("MinMSqr", 0, 5);
50  defineParameter("MaxMSqr", 999, 5);
51  defineParameter("MinET1",0,0);
52  defineParameter("MinET1",0,1);
53  defineParameter("MinET1",0,2);
54  defineParameter("MinET1",0,3);
55  defineParameter("MinET1",0,4);
56  defineParameter("MinET1",0,5);
57 
58  setNumberOutputBits(6);
59 }
60 
62 
63 
66  if(parameter("MaxTob").value() > 0) {
67  p_NumberLeading1 = parameter("MaxTob").value();
68  } else {
69  p_NumberLeading1 = parameter("InputWidth").value();
70  }
71 
72  p_OneBarrel = parameter("RequireOneBarrel").value();
73 
74  for(unsigned int i=0; i<numberOutputBits(); ++i) {
75  p_InvMassMin[i] = parameter("MinMSqr", i).value();
76  p_InvMassMax[i] = parameter("MaxMSqr", i).value();
77 
78  p_MinET1[i] = parameter("MinET1",i).value();
79  }
80  TRG_MSG_INFO("NumberLeading1 : " << p_NumberLeading1);
81  TRG_MSG_INFO("RequireOneBarrel : " << p_OneBarrel);
82  for(unsigned int i=0; i<numberOutputBits(); ++i) {
83  TRG_MSG_INFO("InvMassMin : " << p_InvMassMin[i]);
84  TRG_MSG_INFO("InvMassMax : " << p_InvMassMax[i]);
85 
86  TRG_MSG_INFO("MinET1 : " << p_MinET1[i]);
87  }
88  TRG_MSG_INFO("number output : " << numberOutputBits());
89 
90  // book histograms
91  for(unsigned int i=0; i<numberOutputBits(); ++i) {
92  std::string hname_accept = "hInvariantMassThreeTOBsIncl1Charge_accept_bit"+std::to_string(static_cast<int>(i));
93  std::string hname_reject = "hInvariantMassThreeTOBsIncl1Charge_reject_bit"+std::to_string(static_cast<int>(i));
94  std::string hname_acceptEta1Eta2 = "hInvariantMassThreeTOBsIncl1Charge_acceptEta1Eta2_bit"+std::to_string(static_cast<int>(i));
95  std::string hname_rejectEta1Eta2 = "hInvariantMassThreeTOBsIncl1Charge_rejectEta1Eta2_bit"+std::to_string(static_cast<int>(i));
96  std::string hname_acceptEta2Eta3 = "hInvariantMassThreeTOBsIncl1Charge_acceptEta2Eta3_bit"+std::to_string(static_cast<int>(i));
97  std::string hname_rejectEta2Eta3 = "hInvariantMassThreeTOBsIncl1Charge_rejectEta2Eta3_bit"+std::to_string(static_cast<int>(i));
98  std::string hname_acceptEta3Eta1 = "hInvariantMassThreeTOBsIncl1Charge_acceptEta3Eta1_bit"+std::to_string(static_cast<int>(i));
99  std::string hname_rejectEta3Eta1 = "hInvariantMassThreeTOBsIncl1Charge_rejectEta3Eta1_bit"+std::to_string(static_cast<int>(i));
100  // mass
101  bookHist(m_histAccept, hname_accept, "INVM", 100, std::sqrt(p_InvMassMin[i]), std::sqrt(p_InvMassMax[i]));
102  bookHist(m_histReject, hname_reject, "INVM", 100, std::sqrt(p_InvMassMin[i]), std::sqrt(p_InvMassMax[i]));
103  // eta vs eta
104  bookHist(m_histAcceptEta1Eta2, hname_acceptEta1Eta2, "ETA vs ETA", 100, -70, 70, 100, -70, 70);
105  bookHist(m_histRejectEta1Eta2, hname_rejectEta1Eta2, "ETA vs ETA", 100, -70, 70, 100, -70, 70);
106  bookHist(m_histAcceptEta2Eta3, hname_acceptEta2Eta3, "ETA vs ETA", 100, -70, 70, 100, -70, 70);
107  bookHist(m_histRejectEta2Eta3, hname_rejectEta2Eta3, "ETA vs ETA", 100, -70, 70, 100, -70, 70);
108  bookHist(m_histAcceptEta3Eta1, hname_acceptEta3Eta1, "ETA vs ETA", 100, -70, 70, 100, -70, 70);
109  bookHist(m_histRejectEta3Eta1, hname_rejectEta3Eta1, "ETA vs ETA", 100, -70, 70, 100, -70, 70);
110  }
111 
112 
113 
114  return StatusCode::SUCCESS;
115 }
116 
117 
118 
120 TCS::InvariantMassThreeTOBsIncl1Charge::processBitCorrect( const std::vector<TCS::TOBArray const *> & input,
121  const std::vector<TCS::TOBArray *> & output,
122  Decision & decision )
123 {
124 
125  if(input.size() == 1) {
126 
127  for( TCS::TOBArray::const_iterator tob1 = input[0]->begin();
128  tob1 != input[0]->end() && distance( input[0]->begin(), tob1) < p_NumberLeading1;
129  ++tob1) {
130 
131  TCS::TOBArray::const_iterator tob2 = tob1; ++tob2;
132  for( ;
133  tob2 != input[0]->end() && distance( input[0]->begin(), tob2) < p_NumberLeading1;
134  ++tob2) {
135 
136  TCS::TOBArray::const_iterator tob3 = tob2; ++tob3;
137  for( ;
138  tob3 != input[0]->end() && distance( input[0]->begin(), tob3) < p_NumberLeading1;
139  ++tob3) {
140 
141  // OneBarrel
142  if (p_OneBarrel && static_cast<parType_t>(std::abs((*tob1)->eta())) > 10 && static_cast<parType_t>(std::abs((*tob2)->eta())) > 10 && static_cast<parType_t>(std::abs((*tob3)->eta())) > 10 ) continue;
143 
144  // Inv Mass calculation
145  unsigned int invmass2_12 = calcInvMassBW( *tob1, *tob2 );
146  unsigned int invmass2_13 = calcInvMassBW( *tob1, *tob3 );
147  unsigned int invmass2_23 = calcInvMassBW( *tob2, *tob3 );
148  unsigned int invmass2 = invmass2_12 + invmass2_13 + invmass2_23;
149  // Charge cut ( 1 = positive, -1 = negative, 0 = undefined (RPC) )
150  int charge1 = (*tob1)->charge();
151  int charge2 = (*tob2)->charge();
152  int charge3 = (*tob3)->charge();
153  int totalCharge = charge1 + charge2 + charge3;
154  bool acceptCharge = true;
155  if ( std::abs(totalCharge) == 3 ) { acceptCharge = false; }
156  for(unsigned int i=0; i<numberOutputBits(); ++i) {
157  bool accept = false;
158  if( static_cast<parType_t>((*tob1)->Et()) <= p_MinET1[i]) continue; // ET cut
159  if( static_cast<parType_t>((*tob2)->Et()) <= p_MinET1[i]) continue; // ET cut
160  if( static_cast<parType_t>((*tob3)->Et()) <= p_MinET1[i]) continue; // ET cut
161 
162  accept = invmass2 >= p_InvMassMin[i] && invmass2 <= p_InvMassMax[i] && acceptCharge;
163  const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
164  const bool fillReject = fillHistos() and not fillAccept;
165  const bool alreadyFilled = decision.bit(i);
166  if( accept ) {
167  std::vector<TCS::GenericTOB*> TOBvector;
168  TOBvector.push_back( *tob1 );
169  TOBvector.push_back( *tob2 );
170  TOBvector.push_back( *tob3 );
171  decision.setBit(i, true);
172  output[i]->push_back( TCS::CompositeTOB(TOBvector) );
173  TOBvector.clear();
174  }
175  if(fillAccept and not alreadyFilled) {
176  fillHist1D(m_histAccept[i],std::sqrt(invmass2));
177  fillHist2D(m_histAcceptEta1Eta2[i],(*tob1)->eta(),(*tob2)->eta());
178  fillHist2D(m_histAcceptEta2Eta3[i],(*tob2)->eta(),(*tob3)->eta());
179  fillHist2D(m_histAcceptEta3Eta1[i],(*tob3)->eta(),(*tob1)->eta());
180  } else if(fillReject) {
181  fillHist1D(m_histReject[i],std::sqrt(invmass2));
182  fillHist2D(m_histRejectEta1Eta2[i],(*tob1)->eta(),(*tob2)->eta());
183  fillHist2D(m_histRejectEta2Eta3[i],(*tob2)->eta(),(*tob3)->eta());
184  fillHist2D(m_histRejectEta3Eta1[i],(*tob3)->eta(),(*tob1)->eta());
185  }
186  TRG_MSG_DEBUG("Decision " << i << ": " << (accept?"pass":"fail") << " invmass2 = " << invmass2);
187 
188  }
189  }
190  }
191  }
192  } else {
193 
194  TCS_EXCEPTION("InvariantMassThreeTOBsIncl1Charge alg must have 1 input list, but got " << input.size());
195 
196  }
197 
199 
200 }
201 
203 TCS::InvariantMassThreeTOBsIncl1Charge::process( const std::vector<TCS::TOBArray const *> & input,
204  const std::vector<TCS::TOBArray *> & output,
205  Decision & decision )
206 {
207 
208  if(input.size() == 1) {
209 
210  for( TCS::TOBArray::const_iterator tob1 = input[0]->begin();
211  tob1 != input[0]->end() && distance( input[0]->begin(), tob1) < p_NumberLeading1;
212  ++tob1) {
213 
214  TCS::TOBArray::const_iterator tob2 = tob1; ++tob2;
215  for( ;
216  tob2 != input[0]->end() && distance( input[0]->begin(), tob2) < p_NumberLeading1;
217  ++tob2) {
218 
219  TCS::TOBArray::const_iterator tob3 = tob2; ++tob3;
220  for( ;
221  tob3 != input[0]->end() && distance( input[0]->begin(), tob3) < p_NumberLeading1;
222  ++tob3) {
223 
224  // OneBarrel
225  if (p_OneBarrel && static_cast<parType_t>(std::abs((*tob1)->eta())) > 10 && static_cast<parType_t>(std::abs((*tob2)->eta())) > 10 && static_cast<parType_t>(std::abs((*tob3)->eta())) > 10 ) continue;
226 
227  // Inv Mass calculation
228  unsigned int invmass2_12 = calcInvMass( *tob1, *tob2 );
229  unsigned int invmass2_13 = calcInvMass( *tob1, *tob3 );
230  unsigned int invmass2_23 = calcInvMass( *tob2, *tob3 );
231  unsigned int invmass2 = invmass2_12 + invmass2_13 + invmass2_23;
232  // Charge cut ( 1 = positive, -1 = negative, 0 = undefined (RPC) )
233  int charge1 = (*tob1)->charge();
234  int charge2 = (*tob2)->charge();
235  int charge3 = (*tob3)->charge();
236  int totalCharge = charge1 + charge2 + charge3;
237  bool acceptCharge = true;
238  if ( std::abs(totalCharge) == 3 ) { acceptCharge = false; }
239  for(unsigned int i=0; i<numberOutputBits(); ++i) {
240  bool accept = false;
241  if( static_cast<parType_t>((*tob1)->Et()) <= p_MinET1[i]) continue; // ET cut
242  if( static_cast<parType_t>((*tob2)->Et()) <= p_MinET1[i]) continue; // ET cut
243  if( static_cast<parType_t>((*tob3)->Et()) <= p_MinET1[i]) continue; // ET cut
244 
245  accept = invmass2 >= p_InvMassMin[i] && invmass2 <= p_InvMassMax[i] && acceptCharge;
246  const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
247  const bool fillReject = fillHistos() and not fillAccept;
248  const bool alreadyFilled = decision.bit(i);
249  if( accept ) {
250  std::vector<TCS::GenericTOB*> TOBvector;
251  TOBvector.push_back( *tob1 );
252  TOBvector.push_back( *tob2 );
253  TOBvector.push_back( *tob3 );
254  decision.setBit(i, true);
255  output[i]->push_back( TCS::CompositeTOB(TOBvector) );
256  TOBvector.clear();
257  }
258  if(fillAccept and not alreadyFilled) {
259  fillHist1D(m_histAccept[i],std::sqrt(invmass2));
260  fillHist2D(m_histAcceptEta1Eta2[i],(*tob1)->eta(),(*tob2)->eta());
261  fillHist2D(m_histAcceptEta2Eta3[i],(*tob2)->eta(),(*tob3)->eta());
262  fillHist2D(m_histAcceptEta3Eta1[i],(*tob3)->eta(),(*tob1)->eta());
263  } else if(fillReject) {
264  fillHist1D(m_histReject[i],std::sqrt(invmass2));
265  fillHist2D(m_histRejectEta1Eta2[i],(*tob1)->eta(),(*tob2)->eta());
266  fillHist2D(m_histRejectEta2Eta3[i],(*tob2)->eta(),(*tob3)->eta());
267  fillHist2D(m_histRejectEta3Eta1[i],(*tob3)->eta(),(*tob1)->eta());
268  }
269  TRG_MSG_DEBUG("Decision " << i << ": " << (accept?"pass":"fail") << " invmass2 = " << invmass2);
270 
271  }
272  }
273  }
274  }
275  } else {
276 
277  TCS_EXCEPTION("InvariantMassThreeTOBsIncl1Charge alg must have either 1 input list, but got " << input.size());
278 
279  }
280 
282 }
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
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::InvariantMassThreeTOBsIncl1Charge::processBitCorrect
virtual StatusCode processBitCorrect(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison) override final
Definition: InvariantMassThreeTOBsIncl1Charge.cxx:120
TCS::DecisionAlg
Definition: Trigger/TrigT1/L1Topo/L1TopoInterfaces/L1TopoInterfaces/DecisionAlg.h:22
TCS::InvariantMassThreeTOBsIncl1Charge::~InvariantMassThreeTOBsIncl1Charge
virtual ~InvariantMassThreeTOBsIncl1Charge()
Definition: InvariantMassThreeTOBsIncl1Charge.cxx:61
TCS::Decision::setBit
void setBit(unsigned int index, bool value)
Definition: L1Topo/L1TopoInterfaces/Root/Decision.cxx:12
TCS::InvariantMassThreeTOBsIncl1Charge::process
virtual StatusCode process(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison) override final
Definition: InvariantMassThreeTOBsIncl1Charge.cxx:203
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
TCS::InvariantMassThreeTOBsIncl1Charge
Definition: InvariantMassThreeTOBsIncl1Charge.h:16
REGISTER_ALG_TCS
#define REGISTER_ALG_TCS(CLASS)
Definition: AlgFactory.h:62
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
InvariantMassThreeTOBsIncl1Charge.h
TCS::InvariantMassThreeTOBsIncl1Charge::initialize
virtual StatusCode initialize() override final
Definition: InvariantMassThreeTOBsIncl1Charge.cxx:65
TCS
Definition: Global/GlobalSimulation/src/IO/Decision.h:18
charge3
int charge3(const T &p)
Definition: AtlasPID.h:536
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