ATLAS Offline Software
DeltaRSqrIncl1Charge.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  * DeltaRSqrIncl1Charge.cxx
6  * Created by Paula Martinez based on Joerg Stelzer / V Sorin.
7  *
8  * @brief algorithm calculates the R2-distance between objects in one list and applies dR criteria
9  * Events containing a pair of TGC muons with same charge are rejected
10  *
11  * @param NumberLeading
12 **********************************/
13 
14 #include <cmath>
15 #include "TH1F.h"
16 #include "TH2F.h"
17 
19 #include "L1TopoCommon/Exception.h"
23 
24 REGISTER_ALG_TCS(DeltaRSqrIncl1Charge)
25 
26 
27 // not the best solution but we will move to athena where this comes for free
28 #define LOG std::cout << "TCS::DeltaRSqrIncl1Charge: "
29 
31 {
32  defineParameter("InputWidth", 9);
33  defineParameter("MaxTob", 0);
34  defineParameter("NumResultBits", 3);
35  defineParameter("RequireOneBarrel", 0);
36  defineParameter("MinET1",1);
37  defineParameter("MinET2",1);
38  defineParameter("DeltaRMin", 0, 0);
39  defineParameter("DeltaRMax", 0, 0);
40  defineParameter("DeltaRMin", 0, 1);
41  defineParameter("DeltaRMax", 0, 1);
42  defineParameter("DeltaRMin", 0, 2);
43  defineParameter("DeltaRMax", 0, 2);
45 }
46 
48 
49 
52  if(parameter("MaxTob").value() > 0) {
53  p_NumberLeading1 = parameter("MaxTob").value();
54  p_NumberLeading2 = parameter("MaxTob").value();
55  } else {
56  p_NumberLeading1 = parameter("InputWidth").value();
57  p_NumberLeading2 = parameter("InputWidth").value();
58  }
59  p_OneBarrel = parameter("RequireOneBarrel").value();
60 
61  for(unsigned int i=0; i<numberOutputBits(); ++i) {
62  p_DeltaRMin[i] = parameter("DeltaRMin", i).value();
63  p_DeltaRMax[i] = parameter("DeltaRMax", i).value();
64  }
65  p_MinET1 = parameter("MinET1").value();
66  p_MinET2 = parameter("MinET2").value();
67 
68  TRG_MSG_INFO("NumberLeading1 : " << p_NumberLeading1);
69  TRG_MSG_INFO("NumberLeading2 : " << p_NumberLeading2);
70  TRG_MSG_INFO("RequireOneBarrel : " << p_OneBarrel);
71 
72  for(unsigned int i=0; i<numberOutputBits(); ++i) {
73  TRG_MSG_INFO("DeltaRMin : " << p_DeltaRMin[i]);
74  TRG_MSG_INFO("DeltaRMax : " << p_DeltaRMax[i]);
75  }
76  TRG_MSG_INFO("MinET1 : " << p_MinET1);
77  TRG_MSG_INFO("MinET2 : " << p_MinET2);
78 
79  TRG_MSG_INFO("number output : " << numberOutputBits());
80 
81  // book histograms
82  for(unsigned int i=0; i<numberOutputBits(); ++i) {
83  std::string hname_accept = "hDeltaRSqrIncl1Charge_accept_bit"+std::to_string(static_cast<int>(i));
84  std::string hname_reject = "hDeltaRSqrIncl1Charge_reject_bit"+std::to_string(static_cast<int>(i));
85  // dR
86  bookHist(m_histAccept, hname_accept, "DR", 100, std::sqrt(p_DeltaRMin[i]), std::sqrt(p_DeltaRMax[i]));
87  bookHist(m_histReject, hname_reject, "DR", 100, std::sqrt(p_DeltaRMin[i]), std::sqrt(p_DeltaRMax[i]));
88  // eta2 vs. eta1
89  bookHist(m_histAcceptEta1Eta2, hname_accept, "ETA vs ETA", 100, -70, 70, 100, -70, 70);
90  bookHist(m_histRejectEta1Eta2, hname_reject, "ETA vs ETA", 100, -70, 70, 100, -70, 70);
91  }
92 
93  return StatusCode::SUCCESS;
94 }
95 
96 
97 
99 TCS::DeltaRSqrIncl1Charge::processBitCorrect( const std::vector<TCS::TOBArray const *> & input,
100  const std::vector<TCS::TOBArray *> & output,
101  Decision & decision )
102 {
103 
104  if(input.size() == 1) {
105  for( TOBArray::const_iterator tob1 = input[0]->begin();
106  tob1 != input[0]->end() && distance( input[0]->begin(), tob1) < p_NumberLeading1;
107  ++tob1)
108  {
109  if( parType_t((*tob1)->Et()) <= std::min(p_MinET1,p_MinET2)) continue; // ET cut
110  TCS::TOBArray::const_iterator tob2 = tob1; ++tob2;
111  for( ;
112  tob2 != input[0]->end() && distance( input[0]->begin(), tob2) < p_NumberLeading2;
113  ++tob2) {
114  if( parType_t((*tob2)->Et()) <= std::min(p_MinET1,p_MinET2)) continue; // ET cut
115  if( (parType_t((*tob1)->Et()) <= std::max(p_MinET1,p_MinET2)) && (parType_t((*tob2)->Et()) <= std::max(p_MinET1,p_MinET2))) continue;
116  // OneBarrel
117  if (p_OneBarrel && parType_t(std::abs((*tob1)->eta())) > 10 && parType_t(std::abs((*tob2)->eta())) > 10 ) continue;
118  // DeltaR2 cuts
119  unsigned int deltaR2 = calcDeltaR2BW( *tob1, *tob2 );
120  // Charge cut ( 1 = positive, -1 = negative, 0 = undefined (RPC) )
121  int charge1 = (*tob1)->charge();
122  int charge2 = (*tob2)->charge();
123  int totalCharge = charge1 + charge2;
124  bool acceptCharge = true;
125  if ( std::abs(totalCharge) == 2 ) { acceptCharge = false; }
126  for(unsigned int i=0; i<numberOutputBits(); ++i) {
127  bool accept = false;
128  accept = deltaR2 >= p_DeltaRMin[i] && deltaR2 <= p_DeltaRMax[i] && acceptCharge;
129  const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
130  const bool fillReject = fillHistos() and not fillAccept;
131  const bool alreadyFilled = decision.bit(i);
132  if( accept ) {
133  decision.setBit(i, true);
134  output[i]->push_back( TCS::CompositeTOB(*tob1, *tob2) );
135  }
136  if(fillAccept and not alreadyFilled) {
137  fillHist1D(m_histAccept[i],std::sqrt(static_cast<float>(deltaR2)));
138  fillHist2D(m_histAcceptEta1Eta2[i],(*tob1)->eta(),(*tob2)->eta());
139  } else if(fillReject) {
140  fillHist1D(m_histReject[i],std::sqrt(static_cast<float>(deltaR2)));
141  fillHist2D(m_histRejectEta1Eta2[i],(*tob1)->eta(),(*tob2)->eta());
142  }
143  TRG_MSG_DEBUG("Decision " << i << ": " << (accept?"pass":"fail") << " deltaR2 = " << deltaR2);
144  }
145  }
146  }
147  bool hasAmbiguousInputs = TSU::isAmbiguousTruncation(input[0], p_NumberLeading1, p_MinET1)
148  || TSU::isAmbiguousTruncation(input[0], p_NumberLeading2, p_MinET2);
149  for (unsigned int i=0; i < numberOutputBits(); ++i) {
150  output[i]->setAmbiguityFlag(hasAmbiguousInputs);
151  }
152  } else {
153  TCS_EXCEPTION("DeltaRSqrIncl1Charge alg must have either 1 input, but got " << input.size());
154  }
156 }
157 
159 TCS::DeltaRSqrIncl1Charge::process( const std::vector<TCS::TOBArray const *> & input,
160  const std::vector<TCS::TOBArray *> & output,
161  Decision & decision )
162 {
163  if(input.size() == 1) {
164  for( TOBArray::const_iterator tob1 = input[0]->begin();
165  tob1 != input[0]->end() && distance( input[0]->begin(), tob1) < p_NumberLeading1;
166  ++tob1)
167  {
168  if( parType_t((*tob1)->Et()) <= std::min(p_MinET1,p_MinET2)) continue; // ET cut
169  TCS::TOBArray::const_iterator tob2 = tob1; ++tob2;
170  for( ;
171  tob2 != input[0]->end() && distance( input[0]->begin(), tob2) < p_NumberLeading2;
172  ++tob2) {
173  if( parType_t((*tob2)->Et()) <= std::min(p_MinET1,p_MinET2)) continue; // ET cut
174  if( (parType_t((*tob1)->Et()) <= std::max(p_MinET1,p_MinET2)) && (parType_t((*tob2)->Et()) <= std::max(p_MinET1,p_MinET2))) continue;
175  // OneBarrel
176  if (p_OneBarrel && parType_t(std::abs((*tob1)->eta())) > 10 && parType_t(std::abs((*tob2)->eta())) > 10 ) continue;
177  // DeltaR2 cuts
178  unsigned int deltaR2 = calcDeltaR2( *tob1, *tob2 );
179  // Charge cut ( 1 = positive, -1 = negative, 0 = undefined (RPC) )
180  int charge1 = (*tob1)->charge();
181  int charge2 = (*tob2)->charge();
182  int totalCharge = charge1 + charge2;
183  bool acceptCharge = true;
184  if ( std::abs(totalCharge) == 2 ) { acceptCharge = false; }
185  for(unsigned int i=0; i<numberOutputBits(); ++i) {
186  bool accept = false;
187  accept = deltaR2 >= p_DeltaRMin[i] && deltaR2 <= p_DeltaRMax[i] && acceptCharge;
188  const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
189  const bool fillReject = fillHistos() and not fillAccept;
190  const bool alreadyFilled = decision.bit(i);
191  if( accept ) {
192  decision.setBit(i, true);
193  output[i]->push_back( TCS::CompositeTOB(*tob1, *tob2) );
194  }
195  if(fillAccept and not alreadyFilled) {
196  fillHist1D(m_histAccept[i],std::sqrt(static_cast<float>(deltaR2)));
197  fillHist2D(m_histAcceptEta1Eta2[i],(*tob1)->eta(),(*tob2)->eta());
198  } else if(fillReject) {
199  fillHist1D(m_histReject[i],std::sqrt(static_cast<float>(deltaR2)));
200  fillHist2D(m_histRejectEta1Eta2[i],(*tob1)->eta(),(*tob2)->eta());
201  }
202  TRG_MSG_DEBUG("Decision " << i << ": " << (accept?"pass":"fail") << " deltaR2 = " << deltaR2);
203  }
204  }
205  }
206  } else {
207  TCS_EXCEPTION("DeltaRSqrIncl1Charge alg must have either 1 input, but got " << input.size());
208  }
210 }
Kinematics.h
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
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
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
athena.value
value
Definition: athena.py:124
TCS::DeltaRSqrIncl1Charge::initialize
virtual StatusCode initialize()
Definition: DeltaRSqrIncl1Charge.cxx:51
Decision.h
xAOD::P4Helpers::deltaR2
double deltaR2(double rapidity1, double phi1, double rapidity2, double phi2)
from bare rapidity,phi
Definition: xAODP4Helpers.h:111
TCS::DeltaRSqrIncl1Charge::processBitCorrect
virtual StatusCode processBitCorrect(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison)
Definition: DeltaRSqrIncl1Charge.cxx:99
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
TCS::DeltaRSqrIncl1Charge::~DeltaRSqrIncl1Charge
virtual ~DeltaRSqrIncl1Charge()
Definition: DeltaRSqrIncl1Charge.cxx:47
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
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
DeltaRSqrIncl1Charge.h
TCS::DeltaRSqrIncl1Charge::process
virtual StatusCode process(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison)
Definition: DeltaRSqrIncl1Charge.cxx:159
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
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::DeltaRSqrIncl1Charge::DeltaRSqrIncl1Charge
DeltaRSqrIncl1Charge(const std::string &name)
Definition: DeltaRSqrIncl1Charge.cxx:30
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