ATLAS Offline Software
InvariantMassInclusive1.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  * InvariantMassInclusive1.cpp
6  * Created by V Sorin 2014.
7  *
8  * @brief algorithm calculates the sqr of the INVMASS between TOBs from one list and applies invmass criteria
9  *
10  * @param NumberLeading
11 **********************************/
12 
13 #include <cmath>
14 #include <string>
15 #include <iostream>
16 #include <sstream>
17 #include <vector>
18 
20 #include "L1TopoCommon/Exception.h"
22 
23 
24 REGISTER_ALG_TCS(InvariantMassInclusive1)
25 
26 
27 // not the best solution but we will move to athena where this comes for free
28 #define LOG cout << "TCS::InvariantMassInclusive1: "
29 
31 {
32  defineParameter("InputWidth", 3);
33  defineParameter("MaxTob", 0);
34  defineParameter("NumResultBits", 6);
35  defineParameter("RequireOneBarrel", 0);
36  defineParameter("MinMSqr", 0, 0);
37  defineParameter("MaxMSqr", 999, 0);
38  defineParameter("MinMSqr", 0, 1);
39  defineParameter("MaxMSqr", 999, 1);
40  defineParameter("MinMSqr", 0, 2);
41  defineParameter("MaxMSqr", 999, 2);
42  defineParameter("MinMSqr", 0, 3);
43  defineParameter("MaxMSqr", 999, 3);
44  defineParameter("MinMSqr", 0, 4);
45  defineParameter("MaxMSqr", 999, 4);
46  defineParameter("MinMSqr", 0, 5);
47  defineParameter("MaxMSqr", 999, 5);
48  defineParameter("MinET1",0,0);
49  defineParameter("MinET2",0,0);
50  defineParameter("MinET1",0,1);
51  defineParameter("MinET2",0,1);
52  defineParameter("MinET1",0,2);
53  defineParameter("MinET2",0,2);
54  defineParameter("MinET1",0,3);
55  defineParameter("MinET2",0,3);
56  defineParameter("MinET1",0,4);
57  defineParameter("MinET2",0,4);
58  defineParameter("MinET1",0,5);
59  defineParameter("MinET2",0,5);
60 
61 
63 }
64 
66 
67 
70  if(parameter("MaxTob").value() > 0) {
71  p_NumberLeading1 = parameter("MaxTob").value();
72  p_NumberLeading2 = parameter("MaxTob").value();
73  } else {
74  p_NumberLeading1 = parameter("InputWidth").value();
75  p_NumberLeading2 = parameter("InputWidth").value();
76  }
77 
78  p_OneBarrel = parameter("RequireOneBarrel").value();
79 
80  for(unsigned int i=0; i<numberOutputBits(); ++i) {
81  p_InvMassMin[i] = parameter("MinMSqr", i).value();
82  p_InvMassMax[i] = parameter("MaxMSqr", i).value();
83 
84  p_MinET1[i] = parameter("MinET1",i).value();
85  p_MinET2[i] = parameter("MinET2",i).value();
86  }
87  TRG_MSG_INFO("NumberLeading1 : " << p_NumberLeading1);
88  TRG_MSG_INFO("NumberLeading2 : " << p_NumberLeading2);
89  TRG_MSG_INFO("RequireOneBarrel : " << p_OneBarrel);
90  for(unsigned int i=0; i<numberOutputBits(); ++i) {
91  TRG_MSG_INFO("InvMassMin : " << p_InvMassMin[i]);
92  TRG_MSG_INFO("InvMassMax : " << p_InvMassMax[i]);
93 
94 
95  TRG_MSG_INFO("MinET1 : " << p_MinET1[i]);
96  TRG_MSG_INFO("MinET2 : " << p_MinET2[i]);
97  }
98  TRG_MSG_INFO("number output : " << numberOutputBits());
99 
100  // book histograms
101  for(unsigned int i=0; i<numberOutputBits(); ++i) {
102  std::string hname_accept = "hInvariantMassInclusive1_accept_bit"+std::to_string((int)i);
103  std::string hname_reject = "hInvariantMassInclusive1_reject_bit"+std::to_string((int)i);
104  // mass
105  bookHist(m_histAccept, hname_accept, "INVM", 100, sqrt(p_InvMassMin[i]), sqrt(p_InvMassMax[i]));
106  bookHist(m_histReject, hname_reject, "INVM", 100, sqrt(p_InvMassMin[i]), sqrt(p_InvMassMax[i]));
107  }
108 
109  return StatusCode::SUCCESS;
110 }
111 
112 
113 
115 TCS::InvariantMassInclusive1::processBitCorrect( const std::vector<TCS::TOBArray const *> & input,
116  const std::vector<TCS::TOBArray *> & output,
117  Decision & decision )
118 {
119 
120  if(input.size() == 1) {
121 
122  for( TOBArray::const_iterator tob1 = input[0]->begin();
123  tob1 != input[0]->end() && distance( input[0]->begin(), tob1) < p_NumberLeading1;
124  ++tob1)
125  {
126 
127 
128  TCS::TOBArray::const_iterator tob2 = tob1; ++tob2;
129  for( ;
130  tob2 != input[0]->end() && distance( input[0]->begin(), tob2) < p_NumberLeading2;
131  ++tob2) {
132 
133 
134  // OneBarrel
135  if (p_OneBarrel && parType_t(abs((*tob1)->eta())) > 10 && parType_t(abs((*tob2)->eta())) > 10 ) continue;
136 
137  // Inv Mass calculation
138  unsigned int invmass2 = calcInvMassBW( *tob1, *tob2 );
139  for(unsigned int i=0; i<numberOutputBits(); ++i) {
140  bool accept = false;
141  if( parType_t((*tob1)->Et()) <= std::min(p_MinET1[i],p_MinET2[i])) continue; // ET cut
142  if( parType_t((*tob2)->Et()) <= std::min(p_MinET1[i],p_MinET2[i])) continue; // ET cut
143  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;
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  decision.setBit(i, true);
150  output[i]->push_back( TCS::CompositeTOB(*tob1, *tob2) );
151  }
152  if(fillAccept and not alreadyFilled) {
153  fillHist1D(m_histAccept[i],sqrt((float)invmass2));
154  } else if(fillReject) {
155  fillHist1D(m_histReject[i],sqrt((float)invmass2));
156  }
157  TRG_MSG_DEBUG("Decision " << i << ": " << (accept?"pass":"fail") << " invmass2 = " << invmass2);
158  }
159  }
160  }
161  } else {
162 
163  TCS_EXCEPTION("InvariantMassInclusive1 alg must have either 1 inputs, but got " << input.size());
164 
165  }
166 
168 
169 }
170 
172 TCS::InvariantMassInclusive1::process( const std::vector<TCS::TOBArray const *> & input,
173  const std::vector<TCS::TOBArray *> & output,
174  Decision & decision )
175 {
176 
177  if(input.size() == 1) {
178  for( TOBArray::const_iterator tob1 = input[0]->begin();
179  tob1 != input[0]->end() && distance( input[0]->begin(), tob1) < p_NumberLeading1;
180  ++tob1)
181  {
182 
183 
184  TCS::TOBArray::const_iterator tob2 = tob1; ++tob2;
185  for( ;
186  tob2 != input[0]->end() && distance( input[0]->begin(), tob2) < p_NumberLeading2;
187  ++tob2) {
188 
189 
190  // OneBarrel
191  if (p_OneBarrel && parType_t(abs((*tob1)->eta())) > 10 && parType_t(abs((*tob2)->eta())) > 10 ) continue;
192 
193  // Inv Mass calculation
194 
195  unsigned int invmass2 = calcInvMass( *tob1, *tob2 );
196 
197 
198  for(unsigned int i=0; i<numberOutputBits(); ++i) {
199  bool accept = false;
200  if( parType_t((*tob1)->Et()) <= std::min(p_MinET1[i],p_MinET2[i])) continue; // ET cut
201  if( parType_t((*tob2)->Et()) <= std::min(p_MinET1[i],p_MinET2[i])) continue; // ET cut
202  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;
203  accept = invmass2 >= p_InvMassMin[i] && invmass2 <= p_InvMassMax[i]; //
204  const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
205  const bool fillReject = fillHistos() and not fillAccept;
206  const bool alreadyFilled = decision.bit(i);
207  if( accept ) {
208  decision.setBit(i, true);
209  output[i]->push_back( TCS::CompositeTOB(*tob1, *tob2) );
210  }
211  if(fillAccept and not alreadyFilled) {
212  fillHist1D(m_histAccept[i],sqrt((float)invmass2));
213  } else if(fillReject) {
214  fillHist1D(m_histReject[i],sqrt((float)invmass2));
215  }
216  TRG_MSG_DEBUG("Decision " << i << ": " << (accept?"pass":"fail") << " invmass2 = " << invmass2);
217  }
218  }
219  }
220  } else {
221 
222  TCS_EXCEPTION("InvariantMassInclusive1 alg must have either 1 inputs, but got " << input.size());
223 
224  }
225 
227 }
TCS::InvariantMassInclusive1::~InvariantMassInclusive1
virtual ~InvariantMassInclusive1()
Definition: InvariantMassInclusive1.cxx:65
TCS::StatusCode::SUCCESS
@ SUCCESS
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/L1TopoCommon/StatusCode.h:17
max
#define max(a, b)
Definition: cfImp.cxx:41
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
TCS::DecisionAlg
Definition: Trigger/TrigT1/L1Topo/L1TopoInterfaces/L1TopoInterfaces/DecisionAlg.h:22
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::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::InvariantMassInclusive1::InvariantMassInclusive1
InvariantMassInclusive1(const std::string &name)
Definition: InvariantMassInclusive1.cxx:30
TCS_EXCEPTION
#define TCS_EXCEPTION(MSG)
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/L1TopoCommon/Exception.h:14
TCS::Decision
Definition: L1Topo/L1TopoInterfaces/L1TopoInterfaces/Decision.h:19
InvariantMassInclusive1.h
TRG_MSG_INFO
#define TRG_MSG_INFO(x)
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStreamMacros.h:27
min
#define min(a, b)
Definition: cfImp.cxx:40
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:221
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
TCS::InvariantMassInclusive1::initialize
virtual StatusCode initialize()
Definition: InvariantMassInclusive1.cxx:69
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
TCS::InvariantMassInclusive1::processBitCorrect
virtual StatusCode processBitCorrect(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison)
Definition: InvariantMassInclusive1.cxx:115
TCS::InvariantMassInclusive1::process
virtual StatusCode process(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison)
Definition: InvariantMassInclusive1.cxx:172
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