ATLAS Offline Software
DeltaRSqrIncl1.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  * DeltaRSqrIncl1.cpp
6  * Created by Joerg Stelzer / V Sorin on 9/16/14.
7  *
8  * @brief algorithm calculates the R2-distance between objects in one list and applies dR criteria
9  *
10  * @param NumberLeading
11 **********************************/
12 
13 #include <cmath>
14 
16 #include "L1TopoCommon/Exception.h"
18 
19 REGISTER_ALG_TCS(DeltaRSqrIncl1)
20 
21 
22 // not the best solution but we will move to athena where this comes for free
23 #define LOG std::cout << "TCS::DeltaRSqrIncl1: "
24 
26 {
27  defineParameter("InputWidth", 9);
28  defineParameter("MaxTob", 0);
29  defineParameter("NumResultBits", 3);
30  defineParameter("RequireOneBarrel", 0);
31  defineParameter("MinET1",1);
32  defineParameter("MinET2",1);
33  defineParameter("DeltaRMin", 0, 0);
34  defineParameter("DeltaRMax", 0, 0);
35  defineParameter("DeltaRMin", 0, 1);
36  defineParameter("DeltaRMax", 0, 1);
37  defineParameter("DeltaRMin", 0, 2);
38  defineParameter("DeltaRMax", 0, 2);
40 }
41 
43 
44 
47  if(parameter("MaxTob").value() > 0) {
48  p_NumberLeading1 = parameter("MaxTob").value();
49  p_NumberLeading2 = parameter("MaxTob").value();
50  } else {
51  p_NumberLeading1 = parameter("InputWidth").value();
52  p_NumberLeading2 = parameter("InputWidth").value();
53  }
54  p_OneBarrel = parameter("RequireOneBarrel").value();
55 
56  for(unsigned int i=0; i<numberOutputBits(); ++i) {
57  p_DeltaRMin[i] = parameter("DeltaRMin", i).value();
58  p_DeltaRMax[i] = parameter("DeltaRMax", i).value();
59  }
60  p_MinET1 = parameter("MinET1").value();
61  p_MinET2 = parameter("MinET2").value();
62 
63  TRG_MSG_INFO("NumberLeading1 : " << p_NumberLeading1);
64  TRG_MSG_INFO("NumberLeading2 : " << p_NumberLeading2);
65  TRG_MSG_INFO("RequireOneBarrel : " << p_OneBarrel);
66 
67  for(unsigned int i=0; i<numberOutputBits(); ++i) {
68  TRG_MSG_INFO("DeltaRMin : " << p_DeltaRMin[i]);
69  TRG_MSG_INFO("DeltaRMax : " << p_DeltaRMax[i]);
70  }
71  TRG_MSG_INFO("MinET1 : " << p_MinET1);
72  TRG_MSG_INFO("MinET2 : " << p_MinET2);
73 
74  TRG_MSG_INFO("number output : " << numberOutputBits());
75 
76  // book histograms
77  for(unsigned int i=0; i<numberOutputBits(); ++i) {
78  std::string hname_accept = "hDeltaRSqrIncl1_accept_bit"+std::to_string((int)i);
79  std::string hname_reject = "hDeltaRSqrIncl1_reject_bit"+std::to_string((int)i);
80  // dR
81  bookHist(m_histAccept, hname_accept, "DR", 100, sqrt(p_DeltaRMin[i]), sqrt(p_DeltaRMax[i]));
82  bookHist(m_histReject, hname_reject, "DR", 100, sqrt(p_DeltaRMin[i]), sqrt(p_DeltaRMax[i]));
83  }
84 
85  return StatusCode::SUCCESS;
86 }
87 
88 
89 
91 TCS::DeltaRSqrIncl1::processBitCorrect( const std::vector<TCS::TOBArray const *> & input,
92  const std::vector<TCS::TOBArray *> & output,
93  Decision & decision )
94 {
95  if(input.size() == 1) {
96  for( TOBArray::const_iterator tob1 = input[0]->begin();
97  tob1 != input[0]->end() && distance( input[0]->begin(), tob1) < p_NumberLeading1;
98  ++tob1)
99  {
100  if( parType_t((*tob1)->Et()) <= std::min(p_MinET1,p_MinET2)) continue; // ET cut
101  TCS::TOBArray::const_iterator tob2 = tob1; ++tob2;
102  for( ;
103  tob2 != input[0]->end() && distance( input[0]->begin(), tob2) < p_NumberLeading2;
104  ++tob2) {
105  if( parType_t((*tob2)->Et()) <= std::min(p_MinET1,p_MinET2)) continue; // ET cut
106  if( (parType_t((*tob1)->Et()) <= std::max(p_MinET1,p_MinET2)) && (parType_t((*tob2)->Et()) <= std::max(p_MinET1,p_MinET2))) continue;
107  // OneBarrel
108  if (p_OneBarrel && parType_t(abs((*tob1)->eta())) > 10 && parType_t(abs((*tob2)->eta())) > 10 ) continue;
109  // DeltaR2 cuts
110  unsigned int deltaR2 = calcDeltaR2BW( *tob1, *tob2 );
111  for(unsigned int i=0; i<numberOutputBits(); ++i) {
112  bool accept = false;
113  accept = deltaR2 >= p_DeltaRMin[i] && deltaR2 <= p_DeltaRMax[i];
114  const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
115  const bool fillReject = fillHistos() and not fillAccept;
116  const bool alreadyFilled = decision.bit(i);
117  if( accept ) {
118  decision.setBit(i, true);
119  output[i]->push_back( TCS::CompositeTOB(*tob1, *tob2) );
120  }
121  if(fillAccept and not alreadyFilled) {
122  fillHist1D(m_histAccept[i],sqrt((float)deltaR2));
123  } else if(fillReject) {
124  fillHist1D(m_histReject[i],sqrt((float)deltaR2));
125  }
126  TRG_MSG_DEBUG("Decision " << i << ": " << (accept?"pass":"fail") << " deltaR2 = " << deltaR2);
127  }
128  }
129  }
130  } else {
131  TCS_EXCEPTION("DeltaRSqrIncl1 alg must have either 1 input, but got " << input.size());
132  }
134 }
135 
137 TCS::DeltaRSqrIncl1::process( const std::vector<TCS::TOBArray const *> & input,
138  const std::vector<TCS::TOBArray *> & output,
139  Decision & decision )
140 {
141  if(input.size() == 1) {
142  for( TOBArray::const_iterator tob1 = input[0]->begin();
143  tob1 != input[0]->end() && distance( input[0]->begin(), tob1) < p_NumberLeading1;
144  ++tob1)
145  {
146  if( parType_t((*tob1)->Et()) <= std::min(p_MinET1,p_MinET2)) continue; // ET cut
147  TCS::TOBArray::const_iterator tob2 = tob1; ++tob2;
148  for( ;
149  tob2 != input[0]->end() && distance( input[0]->begin(), tob2) < p_NumberLeading2;
150  ++tob2) {
151  if( parType_t((*tob2)->Et()) <= std::min(p_MinET1,p_MinET2)) continue; // ET cut
152  if( (parType_t((*tob1)->Et()) <= std::max(p_MinET1,p_MinET2)) && (parType_t((*tob2)->Et()) <= std::max(p_MinET1,p_MinET2))) continue;
153  // OneBarrel
154  if (p_OneBarrel && parType_t(abs((*tob1)->eta())) > 10 && parType_t(abs((*tob2)->eta())) > 10 ) continue;
155  // DeltaR2 cuts
156  unsigned int deltaR2 = calcDeltaR2( *tob1, *tob2 );
157  for(unsigned int i=0; i<numberOutputBits(); ++i) {
158  bool accept = false;
159  accept = deltaR2 >= p_DeltaRMin[i] && deltaR2 <= p_DeltaRMax[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_histAccept[i],sqrt((float)deltaR2));
169  } else if(fillReject) {
170  fillHist1D(m_histReject[i],sqrt((float)deltaR2));
171  }
172  TRG_MSG_DEBUG("Decision " << i << ": " << (accept?"pass":"fail") << " deltaR2 = " << deltaR2);
173  }
174  }
175  }
176  } else {
177  TCS_EXCEPTION("DeltaRSqrIncl1 alg must have either 1 input, but got " << input.size());
178  }
180 }
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
DeltaRSqrIncl1.h
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
athena.value
value
Definition: athena.py:124
Decision.h
xAOD::P4Helpers::deltaR2
double deltaR2(double rapidity1, double phi1, double rapidity2, double phi2)
from bare rapidity,phi
Definition: xAODP4Helpers.h:111
TCS::DecisionAlg
Definition: Trigger/TrigT1/L1Topo/L1TopoInterfaces/L1TopoInterfaces/DecisionAlg.h:22
TCS::DeltaRSqrIncl1::initialize
virtual StatusCode initialize()
Definition: DeltaRSqrIncl1.cxx:46
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_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
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
TCS::DeltaRSqrIncl1::DeltaRSqrIncl1
DeltaRSqrIncl1(const std::string &name)
Definition: DeltaRSqrIncl1.cxx:25
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::DeltaRSqrIncl1::processBitCorrect
virtual StatusCode processBitCorrect(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison)
Definition: DeltaRSqrIncl1.cxx:91
TCS::DeltaRSqrIncl1::~DeltaRSqrIncl1
virtual ~DeltaRSqrIncl1()
Definition: DeltaRSqrIncl1.cxx:42
TCS::DeltaRSqrIncl1::process
virtual StatusCode process(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison)
Definition: DeltaRSqrIncl1.cxx:137
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