ATLAS Offline Software
InvariantMassInclusive2.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  * InvariantMassInclusive2.cpp
6  * Created by V SOrin 2014.
7  *
8  * @brief algorithm calculates the sqr of the INVMASS between two lists and applies invmass criteria
9  *
10  * @param NumberLeading
11 **********************************/
12 
13 
15 #include "L1TopoCommon/Exception.h"
17 
18 #include <cmath>
19 #include <iostream>
20 
21 REGISTER_ALG_TCS(InvariantMassInclusive2)
22 
23 
24 // not the best solution but we will move to athena where this comes for free
25 #define LOG cout << "TCS::InvariantMassInclusive2: "
26 
27 
29 {
30  defineParameter("InputWidth1", 9);
31  defineParameter("InputWidth2", 9);
32  defineParameter("MaxTob1", 0);
33  defineParameter("MaxTob2", 0);
34  defineParameter("NumResultBits", 6);
35  defineParameter("MinMSqr", 0, 0);
36  defineParameter("MaxMSqr", 999, 0);
37  defineParameter("MinMSqr", 0, 1);
38  defineParameter("MaxMSqr", 999, 1);
39  defineParameter("MinMSqr", 0, 2);
40  defineParameter("MaxMSqr", 999, 2);
41  defineParameter("MinMSqr", 0, 3);
42  defineParameter("MaxMSqr", 999, 3);
43  defineParameter("MinMSqr", 0, 4);
44  defineParameter("MaxMSqr", 999, 4);
45  defineParameter("MinMSqr", 0, 5);
46  defineParameter("MaxMSqr", 999, 5);
47  defineParameter("MinET1",0,0);
48  defineParameter("MinET2",0,0);
49  defineParameter("MinET1",0,1);
50  defineParameter("MinET2",0,1);
51  defineParameter("MinET1",0,2);
52  defineParameter("MinET2",0,2);
53  defineParameter("MinET1",0,3);
54  defineParameter("MinET2",0,3);
55  defineParameter("MinET1",0,4);
56  defineParameter("MinET2",0,4);
57  defineParameter("MinET1",0,5);
58  defineParameter("MinET2",0,5);
59  defineParameter("ApplyEtaCut", 0);
60  defineParameter("MinEta1", 0);
61  defineParameter("MaxEta1", 31);
62  defineParameter("MinEta2", 0);
63  defineParameter("MaxEta2", 31);
64 
66 }
67 
69 
70 
73  p_NumberLeading1 = parameter("InputWidth1").value();
74  p_NumberLeading2 = parameter("InputWidth2").value();
75  if(parameter("MaxTob1").value() > 0) p_NumberLeading1 = parameter("MaxTob1").value();
76  if(parameter("MaxTob2").value() > 0) p_NumberLeading2 = parameter("MaxTob2").value();
77 
78  for(unsigned int i=0; i<numberOutputBits(); ++i) {
79  p_InvMassMin[i] = parameter("MinMSqr", i).value();
80  p_InvMassMax[i] = parameter("MaxMSqr", i).value();
81 
82  p_MinET1[i] = parameter("MinET1",i).value();
83  p_MinET2[i] = parameter("MinET2",i).value();
84  }
85  TRG_MSG_INFO("NumberLeading1 : " << p_NumberLeading1);
86  TRG_MSG_INFO("NumberLeading2 : " << p_NumberLeading2);
87  for(unsigned int i=0; i<numberOutputBits(); ++i) {
88  TRG_MSG_INFO("InvMassMin : " << p_InvMassMin[i]);
89  TRG_MSG_INFO("InvMassMax : " << p_InvMassMax[i]);
90  TRG_MSG_INFO("MinET1 : " << p_MinET1[i]);
91  TRG_MSG_INFO("MinET2 : " << p_MinET2[i]);
92  }
93 
94  p_ApplyEtaCut = parameter("ApplyEtaCut").value();
95  p_MinEta1 = parameter("MinEta1" ).value();
96  p_MaxEta1 = parameter("MaxEta1" ).value();
97  p_MinEta2 = parameter("MinEta2" ).value();
98  p_MaxEta2 = parameter("MaxEta2" ).value();
99  TRG_MSG_INFO("ApplyEtaCut : "<<p_ApplyEtaCut );
100  TRG_MSG_INFO("MinEta1 : "<<p_MinEta1 );
101  TRG_MSG_INFO("MaxEta1 : "<<p_MaxEta1 );
102  TRG_MSG_INFO("MinEta2 : "<<p_MinEta2 );
103  TRG_MSG_INFO("MaxEta2 : "<<p_MaxEta2 );
104 
105  TRG_MSG_INFO("number output : " << numberOutputBits());
106 
107  // book histograms
108  for(unsigned int i=0; i<numberOutputBits(); ++i) {
109  std::string hname_accept = "hInvariantMassInclusive2_accept_bit"+std::to_string((int)i);
110  std::string hname_reject = "hInvariantMassInclusive2_reject_bit"+std::to_string((int)i);
111  // mass
112  bookHist(m_histAcceptM, hname_accept, "INVM", 100, sqrt(p_InvMassMin[i]), sqrt(p_InvMassMax[i]));
113  bookHist(m_histRejectM, hname_reject, "INVM", 100, sqrt(p_InvMassMin[i]), sqrt(p_InvMassMax[i]));
114  // eta2 vs. eta1
115  bookHist(m_histAcceptEta1Eta2, hname_accept, "ETA vs ETA", 100, p_MinEta1, p_MaxEta1, 100, p_MinEta2, p_MaxEta2);
116  bookHist(m_histRejectEta1Eta2, hname_reject, "ETA vs ETA", 100, p_MinEta1, p_MaxEta1, 100, p_MinEta2, p_MaxEta2);
117  }
118 
119  return StatusCode::SUCCESS;
120 }
121 
122 
123 
125 TCS::InvariantMassInclusive2::processBitCorrect( const std::vector<TCS::TOBArray const *> & input,
126  const std::vector<TCS::TOBArray *> & output,
127  Decision & decision )
128 {
129 
130  if( input.size() == 2) {
131  for( TOBArray::const_iterator tob1 = input[0]->begin();
132  tob1 != input[0]->end() && distance(input[0]->begin(), tob1) < p_NumberLeading1;
133  ++tob1)
134  {
135  if (p_NumberLeading1 < input[0]->size()) {
136  TCS::TOBArray::const_iterator tob1_plus1 = tob1; ++tob1_plus1;
137  if ((*tob1)->Et() == (*tob1_plus1)->Et() && distance(input[0]->begin(), tob1) == p_NumberLeading1 - 1) {
138  for(unsigned int i=0; i<numberOutputBits(); ++i) {
139  output[i]->setAmbiguityFlag(true);
140  }
141  }
142  }
143  for( TCS::TOBArray::const_iterator tob2 = input[1]->begin();
144  tob2 != input[1]->end() && distance(input[1]->begin(), tob2) < p_NumberLeading2;
145  ++tob2) {
146  // Inv Mass calculation
147  unsigned int invmass2 = calcInvMassBW( *tob1, *tob2 );
148  const int eta1 = (*tob1)->eta();
149  const int eta2 = (*tob2)->eta();
150  const unsigned int aeta1 = std::abs(eta1);
151  const unsigned int aeta2 = std::abs(eta2);
152  for(unsigned int i=0; i<numberOutputBits(); ++i) {
153  bool accept = false;
154  if( parType_t((*tob1)->Et()) <= p_MinET1[i]) continue; // ET cut
155  if( parType_t((*tob2)->Et()) <= p_MinET2[i]) continue; // ET cut
156  if(p_ApplyEtaCut &&
157  ((aeta1 < p_MinEta1 || aeta1 > p_MaxEta1 ) ||
158  (aeta2 < p_MinEta2 || aeta2 > p_MaxEta2 ) )) continue;
159  accept = invmass2 >= p_InvMassMin[i] && invmass2 <= p_InvMassMax[i];
160  const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
161  const bool fillReject = fillHistos() and not fillAccept;
162  const bool alreadyFilled = decision.bit(i);
163  if( accept ) {
164  decision.setBit(i, true);
165  output[i]->push_back( TCS::CompositeTOB(*tob1, *tob2) );
166  }
167  if(fillAccept and not alreadyFilled) {
168  fillHist1D(m_histAcceptM[i],sqrt((float)invmass2));
169  fillHist2D(m_histAcceptEta1Eta2[i],eta1, eta2);
170  } else if(fillReject) {
171  fillHist1D(m_histRejectM[i],sqrt((float)invmass2));
172  fillHist2D(m_histRejectEta1Eta2[i],eta1, eta2);
173  }
174  TRG_MSG_DEBUG("Decision " << i << ": " << (accept?"pass":"fail") << " invmass2 = " << invmass2);
175  }
176  }
177  }
178  } else {
179 
180  TCS_EXCEPTION("InvariantMassInclusive2 alg must have 2 inputs, but got " << input.size());
181 
182  }
184 
185 }
186 
188 TCS::InvariantMassInclusive2::process( const std::vector<TCS::TOBArray const *> & input,
189  const std::vector<TCS::TOBArray *> & output,
190  Decision & decision )
191 {
192 
193 
194  if( input.size() == 2) {
195  for( TOBArray::const_iterator tob1 = input[0]->begin();
196  tob1 != input[0]->end() && distance(input[0]->begin(), tob1) < p_NumberLeading1;
197  ++tob1)
198  {
199  if (p_NumberLeading1 < input[0]->size()) {
200  TCS::TOBArray::const_iterator tob1_plus1 = tob1; ++tob1_plus1;
201  if ((*tob1)->Et() == (*tob1_plus1)->Et() && distance(input[0]->begin(), tob1) == p_NumberLeading1 - 1) {
202  for(unsigned int i=0; i<numberOutputBits(); ++i) {
203  output[i]->setAmbiguityFlag(true);
204  }
205  }
206  }
207  for( TCS::TOBArray::const_iterator tob2 = input[1]->begin();
208  tob2 != input[1]->end() && distance(input[1]->begin(), tob2) < p_NumberLeading2;
209  ++tob2) {
210  // Inv Mass calculation
211  unsigned int invmass2 = calcInvMass( *tob1, *tob2 );
212  const int eta1 = (*tob1)->eta();
213  const int eta2 = (*tob2)->eta();
214  const unsigned int aeta1 = std::abs(eta1);
215  const unsigned int aeta2 = std::abs(eta2);
216  for(unsigned int i=0; i<numberOutputBits(); ++i) {
217  if( parType_t((*tob1)->Et()) <= p_MinET1[i]) continue; // ET cut
218  if( parType_t((*tob2)->Et()) <= p_MinET2[i]) continue; // ET cut
219  if(p_ApplyEtaCut &&
220  ((aeta1 < p_MinEta1 || aeta1 > p_MaxEta1 ) ||
221  (aeta2 < p_MinEta2 || aeta2 > p_MaxEta2 ) )) continue;
222  bool accept = invmass2 >= p_InvMassMin[i] && invmass2 <= p_InvMassMax[i];
223  const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
224  const bool fillReject = fillHistos() and not fillAccept;
225  const bool alreadyFilled = decision.bit(i);
226  if( accept ) {
227  decision.setBit(i, true);
228  output[i]->push_back( TCS::CompositeTOB(*tob1, *tob2) );
229  }
230  if(fillAccept and not alreadyFilled) {
231  fillHist1D(m_histAcceptM[i],sqrt((float)invmass2));
232  fillHist2D(m_histAcceptEta1Eta2[i],eta1, eta2);
233  } else if(fillReject) {
234  fillHist1D(m_histRejectM[i],sqrt((float)invmass2));
235  fillHist2D(m_histRejectEta1Eta2[i],eta1, eta2);
236  }
237  TRG_MSG_DEBUG("Decision " << i << ": " << (accept ?"pass":"fail") << " invmass2 = " << invmass2);
238  }
239  }
240  }
241  } else {
242  TCS_EXCEPTION("InvariantMassInclusive2 alg must have 2 inputs, but got " << input.size());
243  }
245 }
TCS::StatusCode::SUCCESS
@ SUCCESS
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/L1TopoCommon/StatusCode.h:17
TCS::parType_t
uint32_t parType_t
Definition: Parameter.h:22
ParticleGun_SamplingFraction.eta2
eta2
Definition: ParticleGun_SamplingFraction.py:96
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:122
xAOD::eta1
setEt setPhi setE277 setWeta2 eta1
Definition: TrigEMCluster_v1.cxx:41
Decision.h
TCS::DecisionAlg
Definition: Trigger/TrigT1/L1Topo/L1TopoInterfaces/L1TopoInterfaces/DecisionAlg.h:22
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
TCS::Decision::setBit
void setBit(unsigned int index, bool value)
Definition: L1Topo/L1TopoInterfaces/Root/Decision.cxx:12
TCS::InvariantMassInclusive2::InvariantMassInclusive2
InvariantMassInclusive2(const std::string &name)
Definition: InvariantMassInclusive2.cxx:28
lumiFormat.i
int i
Definition: lumiFormat.py:92
InvariantMassInclusive2.h
TCS::ConfigurableAlg::defineParameter
void defineParameter(const std::string &name, TCS::parType_t value)
Definition: ConfigurableAlg.cxx:201
TCS::CompositeTOB
Definition: CompositeTOB.h:16
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
TCS::InvariantMassInclusive2::~InvariantMassInclusive2
virtual ~InvariantMassInclusive2()
Definition: InvariantMassInclusive2.cxx:68
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
TCS::InvariantMassInclusive2::process
virtual StatusCode process(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison)
Definition: InvariantMassInclusive2.cxx:188
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
TCS::InvariantMassInclusive2::processBitCorrect
virtual StatusCode processBitCorrect(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison)
Definition: InvariantMassInclusive2.cxx:125
TCS::InvariantMassInclusive2::initialize
virtual StatusCode initialize()
Definition: InvariantMassInclusive2.cxx:72
TCS::Decision::bit
bool bit(unsigned int index) const
Definition: L1Topo/L1TopoInterfaces/L1TopoInterfaces/Decision.h:40
TCS::DecisionAlg::setNumberOutputBits
void setNumberOutputBits(unsigned int numberOutputBits)
Definition: Trigger/TrigT1/L1Topo/L1TopoInterfaces/L1TopoInterfaces/DecisionAlg.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