ATLAS Offline Software
L1Topo/L1TopoAlgorithms/Root/DeltaRSqrIncl2.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
3 */
4 /*********************************
5  * DeltaRSqrIncl2.cpp
6  * Created by Joerg Stelzer / V Sorin on 9/16/14.
7  *
8  * @brief algorithm calculates the R2-distance between two lists and applies dR criteria
9  *
10  * @param NumberLeading
11 **********************************/
12 
13 #include <cmath>
14 
16 #include "L1TopoCommon/Exception.h"
18 
19 REGISTER_ALG_TCS(DeltaRSqrIncl2)
20 
21 
22 // not the best solution but we will move to athena where this comes for free
23 #define LOG std::cout << "TCS::DeltaRSqrIncl2: "
24 
26 {
27  defineParameter("InputWidth1", 9);
28  defineParameter("InputWidth2", 9);
29  defineParameter("MaxTob1", 0);
30  defineParameter("MaxTob2", 0);
31  defineParameter("NumResultBits", 3);
32  defineParameter("MinET1",1,0);
33  defineParameter("MinET2",1,0);
34  defineParameter("DeltaRMin", 0, 0);
35  defineParameter("DeltaRMax", 0, 0);
36  defineParameter("MinET1",1,1);
37  defineParameter("MinET2",1,1);
38  defineParameter("DeltaRMin", 0, 1);
39  defineParameter("DeltaRMax", 0, 1);
40  defineParameter("MinET1",1,2);
41  defineParameter("MinET2",1,2);
42  defineParameter("DeltaRMin", 0, 2);
43  defineParameter("DeltaRMax", 0, 2);
45 }
46 
48 
49 
52 
53  p_NumberLeading1 = parameter("InputWidth1").value();
54  p_NumberLeading2 = parameter("InputWidth2").value();
55  if(parameter("MaxTob1").value() > 0) p_NumberLeading1 = parameter("MaxTob1").value();
56  if(parameter("MaxTob2").value() > 0) p_NumberLeading2 = parameter("MaxTob2").value();
57 
58  for(unsigned int i=0; i<numberOutputBits(); ++i) {
59  p_DeltaRMin[i] = parameter("DeltaRMin", i).value();
60  p_DeltaRMax[i] = parameter("DeltaRMax", i).value();
61  p_MinET1[i] = parameter("MinET1",i).value();
62  p_MinET2[i] = parameter("MinET2",i).value();
63  TRG_MSG_INFO("DeltaRMin" << i << " : " << p_DeltaRMin[i]);
64  TRG_MSG_INFO("DeltaRMax" << i << " : " << p_DeltaRMax[i]);
65 
66  TRG_MSG_INFO("MinET1 : " << p_MinET1[i]);
67  TRG_MSG_INFO("MinET2 : " << p_MinET2[i]);
68 
69  }
70 
71  TRG_MSG_INFO("NumberLeading1 : " << p_NumberLeading1);
72  TRG_MSG_INFO("NumberLeading2 : " << p_NumberLeading2);
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 = "hDeltaRSqrIncl2_accept_bit"+std::to_string((int)i);
79  std::string hname_reject = "hDeltaRSqrIncl2_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 
90 TCS::DeltaRSqrIncl2::processBitCorrect( const std::vector<TCS::TOBArray const *> & input,
91  const std::vector<TCS::TOBArray *> & output,
92  Decision & decision )
93 {
94 
95  if( input.size() == 2) {
96 
97  for( TOBArray::const_iterator tob1 = input[0]->begin();
98  tob1 != input[0]->end() && distance(input[0]->begin(), tob1) < p_NumberLeading1;
99  ++tob1)
100  {
101  for( TCS::TOBArray::const_iterator tob2 = input[1]->begin();
102  tob2 != input[1]->end() && distance(input[1]->begin(), tob2) < p_NumberLeading2;
103  ++tob2) {
104  // test DeltaR2Min, DeltaR2Max
105  unsigned int deltaR2 = calcDeltaR2BW( *tob1, *tob2 );
106  TRG_MSG_DEBUG("Jet1 = " << **tob1 << ", Jet2 = " << **tob2 << ", deltaR2 = " << deltaR2);
107  for(unsigned int i=0; i<numberOutputBits(); ++i) {
108  bool accept = false;
109  if( parType_t((*tob1)->Et()) <= p_MinET1[i]) continue; // ET cut
110  if( parType_t((*tob2)->Et()) <= p_MinET2[i]) continue; // ET cut
111  accept = deltaR2 >= p_DeltaRMin[i] && deltaR2 <= p_DeltaRMax[i];
112  const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
113  const bool fillReject = fillHistos() and not fillAccept;
114  const bool alreadyFilled = decision.bit(i);
115  if( accept ) {
116  decision.setBit(i, true);
117  output[i]->push_back(TCS::CompositeTOB(*tob1, *tob2));
118  }
119  if(fillAccept and not alreadyFilled) {
120  fillHist1D(m_histAccept[i],sqrt((float)deltaR2));
121  } else if(fillReject) {
122  fillHist1D(m_histReject[i],sqrt((float)deltaR2));
123  }
124  TRG_MSG_DEBUG("Decision " << i << ": " << (accept?"pass":"fail") << " deltaR2 = " << deltaR2);
125  }
126  }
127  }
128  } else {
129  TCS_EXCEPTION("DeltaRSqrIncl2 alg must have 2 inputs, but got " << input.size());
130  }
132 }
133 
135 TCS::DeltaRSqrIncl2::process( const std::vector<TCS::TOBArray const *> & input,
136  const std::vector<TCS::TOBArray *> & output,
137  Decision & decision )
138 {
139 
140  if( input.size() == 2) {
141 
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 
147 
148  for( TCS::TOBArray::const_iterator tob2 = input[1]->begin();
149  tob2 != input[1]->end() && distance(input[1]->begin(), tob2) < p_NumberLeading2;
150  ++tob2) {
151  // test DeltaR2Min, DeltaR2Max
152  unsigned int deltaR2 = calcDeltaR2( *tob1, *tob2 );
153 
154  TRG_MSG_DEBUG("Jet1 = " << **tob1 << ", Jet2 = " << **tob2 << ", deltaR2 = " << deltaR2);
155  for(unsigned int i=0; i<numberOutputBits(); ++i) {
156  bool accept = false;
157  if( parType_t((*tob1)->Et()) <= p_MinET1[i]) continue; // ET cut
158  if( parType_t((*tob2)->Et()) <= p_MinET2[i]) continue; // ET cut
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("DeltaRSqrIncl2 alg must have 2 inputs, but got " << input.size());
178  }
180 }
TCS::DeltaRSqrIncl2::initialize
virtual StatusCode initialize()
Definition: L1Topo/L1TopoAlgorithms/Root/DeltaRSqrIncl2.cxx:51
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
TCS::DeltaRSqrIncl2::~DeltaRSqrIncl2
virtual ~DeltaRSqrIncl2()
Definition: L1Topo/L1TopoAlgorithms/Root/DeltaRSqrIncl2.cxx:47
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
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::Decision::setBit
void setBit(unsigned int index, bool value)
Definition: L1Topo/L1TopoInterfaces/Root/Decision.cxx:12
lumiFormat.i
int i
Definition: lumiFormat.py:92
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
DeltaRSqrIncl2.h
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:192
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
TCS::DeltaRSqrIncl2::DeltaRSqrIncl2
DeltaRSqrIncl2(const std::string &name)
Definition: L1Topo/L1TopoAlgorithms/Root/DeltaRSqrIncl2.cxx:25
TCS::DeltaRSqrIncl2::process
virtual StatusCode process(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison)
Definition: L1Topo/L1TopoAlgorithms/Root/DeltaRSqrIncl2.cxx:135
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::DeltaRSqrIncl2::processBitCorrect
virtual StatusCode processBitCorrect(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison)
Definition: L1Topo/L1TopoAlgorithms/Root/DeltaRSqrIncl2.cxx:90
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