ATLAS Offline Software
DeltaRSqrIncl2Charge.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  * DeltaRSqrIncl2Charge.cxx
6  * Created by Paula Martinez based on Joerg Stelzer / V Sorin.
7  *
8  * @brief algorithm calculates the R2-distance between two lists and applies dR criteria
9  * Events containing a pair of TGC muons with same charge are rejected
10  *
11  * @param NumberLeading
12 **********************************/
13 
15 
16 #include "L1TopoCommon/Exception.h"
19 
20 #include <cmath>
21 
22 REGISTER_ALG_TCS(DeltaRSqrIncl2Charge)
23 
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);
44  setNumberOutputBits(3);
45 }
46 
48 
49 
52 
53  m_NumberLeading1 = parameter("InputWidth1").value();
54  m_NumberLeading2 = parameter("InputWidth2").value();
55  if(parameter("MaxTob1").value() > 0) m_NumberLeading1 = parameter("MaxTob1").value();
56  if(parameter("MaxTob2").value() > 0) m_NumberLeading2 = parameter("MaxTob2").value();
57 
58  for(unsigned int i=0; i<numberOutputBits(); ++i) {
59  m_DeltaRMin[i] = parameter("DeltaRMin", i).value();
60  m_DeltaRMax[i] = parameter("DeltaRMax", i).value();
61  m_MinET1[i] = parameter("MinET1",i).value();
62  m_MinET2[i] = parameter("MinET2",i).value();
63  TRG_MSG_INFO("DeltaRMin" << i << " : " << m_DeltaRMin[i]);
64  TRG_MSG_INFO("DeltaRMax" << i << " : " << m_DeltaRMax[i]);
65 
66  TRG_MSG_INFO("MinET1 : " << m_MinET1[i]);
67  TRG_MSG_INFO("MinET2 : " << m_MinET2[i]);
68 
69  }
70 
71  TRG_MSG_INFO("NumberLeading1 : " << m_NumberLeading1);
72  TRG_MSG_INFO("NumberLeading2 : " << m_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 = "hDeltaRSqrIncl2Charge_accept_bit"+std::to_string(static_cast<int>(i));
79  std::string hname_reject = "hDeltaRSqrIncl2Charge_reject_bit"+std::to_string(static_cast<int>(i));
80  // dR
81  bookHist(m_histAccept, hname_accept, "DR", 100, std::sqrt(m_DeltaRMin[i]), std::sqrt(m_DeltaRMax[i]));
82  bookHist(m_histReject, hname_reject, "DR", 100, std::sqrt(m_DeltaRMin[i]), std::sqrt(m_DeltaRMax[i]));
83  // eta2 vs. eta1
84  bookHist(m_histAcceptEta1Eta2, hname_accept, "ETA vs ETA", 100, -70, 70, 100, -70, 70);
85  bookHist(m_histRejectEta1Eta2, hname_reject, "ETA vs ETA", 100, -70, 70, 100, -70, 70);
86  }
87 
88  return StatusCode::SUCCESS;
89 }
90 
91 
93 TCS::DeltaRSqrIncl2Charge::processBitCorrect( const std::vector<TCS::TOBArray const *> & input,
94  const std::vector<TCS::TOBArray *> & output,
95  Decision & decision )
96 {
97 
98  if( input.size() == 2) {
99 
100  for( TOBArray::const_iterator tob1 = input[0]->begin();
101  tob1 != input[0]->end() && distance(input[0]->begin(), tob1) < m_NumberLeading1;
102  ++tob1)
103  {
104  for( TCS::TOBArray::const_iterator tob2 = input[1]->begin();
105  tob2 != input[1]->end() && distance(input[1]->begin(), tob2) < m_NumberLeading2;
106  ++tob2) {
107  // test DeltaR2Min, DeltaR2Max
108  unsigned int deltaR2 = calcDeltaR2BW( *tob1, *tob2 );
109  TRG_MSG_DEBUG("Jet1 = " << **tob1 << ", Jet2 = " << **tob2 << ", deltaR2 = " << deltaR2);
110  // Charge cut ( 1 = positive, -1 = negative, 0 = undefined (RPC) )
111  int charge1 = (*tob1)->charge();
112  int charge2 = (*tob2)->charge();
113  int totalCharge = charge1 + charge2;
114  bool acceptCharge = true;
115  if ( std::abs(totalCharge) == 2 ) { acceptCharge = false; }
116  for(unsigned int i=0; i<numberOutputBits(); ++i) {
117  bool accept = false;
118  if( parType_t((*tob1)->Et()) <= m_MinET1[i]) continue; // ET cut
119  if( parType_t((*tob2)->Et()) <= m_MinET2[i]) continue; // ET cut
120  accept = deltaR2 >= m_DeltaRMin[i] && deltaR2 <= m_DeltaRMax[i] && acceptCharge;
121  const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
122  const bool fillReject = fillHistos() and not fillAccept;
123  const bool alreadyFilled = decision.bit(i);
124  if( accept ) {
125  decision.setBit(i, true);
126  output[i]->push_back(TCS::CompositeTOB(*tob1, *tob2));
127  }
128  if(fillAccept and not alreadyFilled) {
129  fillHist1D(m_histAccept[i],std::sqrt(static_cast<float>(deltaR2)));
130  fillHist2D(m_histAcceptEta1Eta2[i],(*tob1)->eta(),(*tob2)->eta());
131  } else if(fillReject) {
132  fillHist1D(m_histReject[i],std::sqrt(static_cast<float>(deltaR2)));
133  fillHist2D(m_histRejectEta1Eta2[i],(*tob1)->eta(),(*tob2)->eta());
134  }
135  TRG_MSG_DEBUG("Decision " << i << ": " << (accept?"pass":"fail") << " deltaR2 = " << deltaR2);
136  }
137  }
138  }
139  for (unsigned int i=0; i < numberOutputBits(); ++i) {
140  bool hasAmbiguousInputs = TSU::isAmbiguousTruncation(input[0], m_NumberLeading1, m_MinET1[i])
141  || TSU::isAmbiguousTruncation(input[1], m_NumberLeading2, m_MinET2[i]);
142  output[i]->setAmbiguityFlag(hasAmbiguousInputs);
143  }
144  } else {
145  TCS_EXCEPTION("DeltaRSqrIncl2Charge alg must have 2 inputs, but got " << input.size());
146  }
148 }
149 
151 TCS::DeltaRSqrIncl2Charge::process( const std::vector<TCS::TOBArray const *> & input,
152  const std::vector<TCS::TOBArray *> & output,
153  Decision & decision )
154 {
155 
156  if( input.size() == 2) {
157 
158  for( TOBArray::const_iterator tob1 = input[0]->begin();
159  tob1 != input[0]->end() && distance(input[0]->begin(), tob1) < m_NumberLeading1;
160  ++tob1)
161  {
162 
163 
164  for( TCS::TOBArray::const_iterator tob2 = input[1]->begin();
165  tob2 != input[1]->end() && distance(input[1]->begin(), tob2) < m_NumberLeading2;
166  ++tob2) {
167  // test DeltaR2Min, DeltaR2Max
168  unsigned int deltaR2 = calcDeltaR2( *tob1, *tob2 );
169  TRG_MSG_DEBUG("Jet1 = " << **tob1 << ", Jet2 = " << **tob2 << ", deltaR2 = " << deltaR2);
170  // Charge cut ( 1 = positive, -1 = negative, 0 = undefined (RPC) )
171  int charge1 = (*tob1)->charge();
172  int charge2 = (*tob2)->charge();
173  int totalCharge = charge1 + charge2;
174  bool acceptCharge = true;
175  if ( std::abs(totalCharge) == 2 ) { acceptCharge = false; }
176  for(unsigned int i=0; i<numberOutputBits(); ++i) {
177  bool accept = false;
178  if( parType_t((*tob1)->Et()) <= m_MinET1[i]) continue; // ET cut
179  if( parType_t((*tob2)->Et()) <= m_MinET2[i]) continue; // ET cut
180  accept = deltaR2 >= m_DeltaRMin[i] && deltaR2 <= m_DeltaRMax[i] && acceptCharge;
181  const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
182  const bool fillReject = fillHistos() and not fillAccept;
183  const bool alreadyFilled = decision.bit(i);
184  if( accept ) {
185  decision.setBit(i, true);
186  output[i]->push_back(TCS::CompositeTOB(*tob1, *tob2));
187  }
188  if(fillAccept and not alreadyFilled) {
189  fillHist1D(m_histAccept[i],std::sqrt(static_cast<float>(deltaR2)));
190  fillHist2D(m_histAcceptEta1Eta2[i],(*tob1)->eta(),(*tob2)->eta());
191  } else if(fillReject) {
192  fillHist1D(m_histReject[i],std::sqrt(static_cast<float>(deltaR2)));
193  fillHist2D(m_histRejectEta1Eta2[i],(*tob1)->eta(),(*tob2)->eta());
194  }
195  TRG_MSG_DEBUG("Decision " << i << ": " << (accept?"pass":"fail") << " deltaR2 = " << deltaR2);
196  }
197  }
198  }
199  } else {
200  TCS_EXCEPTION("DeltaRSqrIncl2Charge alg must have 2 inputs, but got " << input.size());
201  }
203 }
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
TSU::isAmbiguousTruncation
bool isAmbiguousTruncation(TCS::TOBArray const *tobs, size_t pos, unsigned minEt=0)
Definition: Trigger/TrigT1/L1Topo/L1TopoSimulationUtils/Root/Helpers.cxx:23
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
TCS::DeltaRSqrIncl2Charge::initialize
virtual StatusCode initialize()
Definition: DeltaRSqrIncl2Charge.cxx:51
athena.value
value
Definition: athena.py:124
Decision.h
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:560
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:85
TCS::CompositeTOB
Definition: CompositeTOB.h:16
TCS_EXCEPTION
#define TCS_EXCEPTION(MSG)
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/L1TopoCommon/Exception.h:14
TCS::Decision
Definition: L1Topo/L1TopoInterfaces/L1TopoInterfaces/Decision.h:19
DeltaRSqrIncl2Charge.h
TRG_MSG_INFO
#define TRG_MSG_INFO(x)
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStreamMacros.h:27
REGISTER_ALG_TCS
#define REGISTER_ALG_TCS(CLASS)
Definition: AlgFactory.h:62
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
TCS::DeltaRSqrIncl2Charge::process
virtual StatusCode process(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison)
Definition: DeltaRSqrIncl2Charge.cxx:151
TCS
Definition: Global/GlobalSimulation/src/IO/Decision.h:18
TCS::Decision::bit
bool bit(unsigned int index) const
Definition: L1Topo/L1TopoInterfaces/L1TopoInterfaces/Decision.h:40
TCS::DeltaRSqrIncl2Charge::processBitCorrect
virtual StatusCode processBitCorrect(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison)
Definition: DeltaRSqrIncl2Charge.cxx:93
Helpers.h
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
TCS::DeltaRSqrIncl2Charge::~DeltaRSqrIncl2Charge
virtual ~DeltaRSqrIncl2Charge()
Definition: DeltaRSqrIncl2Charge.cxx:47
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
TCS::DeltaRSqrIncl2Charge
Definition: DeltaRSqrIncl2Charge.h:15