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"
22 
23 REGISTER_ALG_TCS(DeltaRSqrIncl1Charge)
24 
25 
26 // not the best solution but we will move to athena where this comes for free
27 #define LOG std::cout << "TCS::DeltaRSqrIncl1Charge: "
28 
30 {
31  defineParameter("InputWidth", 9);
32  defineParameter("MaxTob", 0);
33  defineParameter("NumResultBits", 3);
34  defineParameter("RequireOneBarrel", 0);
35  defineParameter("MinET1",1);
36  defineParameter("MinET2",1);
37  defineParameter("DeltaRMin", 0, 0);
38  defineParameter("DeltaRMax", 0, 0);
39  defineParameter("DeltaRMin", 0, 1);
40  defineParameter("DeltaRMax", 0, 1);
41  defineParameter("DeltaRMin", 0, 2);
42  defineParameter("DeltaRMax", 0, 2);
44 }
45 
47 
48 
51  if(parameter("MaxTob").value() > 0) {
52  p_NumberLeading1 = parameter("MaxTob").value();
53  p_NumberLeading2 = parameter("MaxTob").value();
54  } else {
55  p_NumberLeading1 = parameter("InputWidth").value();
56  p_NumberLeading2 = parameter("InputWidth").value();
57  }
58  p_OneBarrel = parameter("RequireOneBarrel").value();
59 
60  for(unsigned int i=0; i<numberOutputBits(); ++i) {
61  p_DeltaRMin[i] = parameter("DeltaRMin", i).value();
62  p_DeltaRMax[i] = parameter("DeltaRMax", i).value();
63  }
64  p_MinET1 = parameter("MinET1").value();
65  p_MinET2 = parameter("MinET2").value();
66 
67  TRG_MSG_INFO("NumberLeading1 : " << p_NumberLeading1);
68  TRG_MSG_INFO("NumberLeading2 : " << p_NumberLeading2);
69  TRG_MSG_INFO("RequireOneBarrel : " << p_OneBarrel);
70 
71  for(unsigned int i=0; i<numberOutputBits(); ++i) {
72  TRG_MSG_INFO("DeltaRMin : " << p_DeltaRMin[i]);
73  TRG_MSG_INFO("DeltaRMax : " << p_DeltaRMax[i]);
74  }
75  TRG_MSG_INFO("MinET1 : " << p_MinET1);
76  TRG_MSG_INFO("MinET2 : " << p_MinET2);
77 
78  TRG_MSG_INFO("number output : " << numberOutputBits());
79 
80  // book histograms
81  for(unsigned int i=0; i<numberOutputBits(); ++i) {
82  std::string hname_accept = "hDeltaRSqrIncl1Charge_accept_bit"+std::to_string(static_cast<int>(i));
83  std::string hname_reject = "hDeltaRSqrIncl1Charge_reject_bit"+std::to_string(static_cast<int>(i));
84  // dR
85  bookHist(m_histAccept, hname_accept, "DR", 100, std::sqrt(p_DeltaRMin[i]), std::sqrt(p_DeltaRMax[i]));
86  bookHist(m_histReject, hname_reject, "DR", 100, std::sqrt(p_DeltaRMin[i]), std::sqrt(p_DeltaRMax[i]));
87  // eta2 vs. eta1
88  bookHist(m_histAcceptEta1Eta2, hname_accept, "ETA vs ETA", 100, -70, 70, 100, -70, 70);
89  bookHist(m_histRejectEta1Eta2, hname_reject, "ETA vs ETA", 100, -70, 70, 100, -70, 70);
90  }
91 
92  return StatusCode::SUCCESS;
93 }
94 
95 
96 
98 TCS::DeltaRSqrIncl1Charge::processBitCorrect( const std::vector<TCS::TOBArray const *> & input,
99  const std::vector<TCS::TOBArray *> & output,
100  Decision & decision )
101 {
102 
103  if(input.size() == 1) {
104  for( TOBArray::const_iterator tob1 = input[0]->begin();
105  tob1 != input[0]->end() && distance( input[0]->begin(), tob1) < p_NumberLeading1;
106  ++tob1)
107  {
108  if( parType_t((*tob1)->Et()) <= std::min(p_MinET1,p_MinET2)) continue; // ET cut
109  TCS::TOBArray::const_iterator tob2 = tob1; ++tob2;
110  for( ;
111  tob2 != input[0]->end() && distance( input[0]->begin(), tob2) < p_NumberLeading2;
112  ++tob2) {
113  if( parType_t((*tob2)->Et()) <= std::min(p_MinET1,p_MinET2)) continue; // ET cut
114  if( (parType_t((*tob1)->Et()) <= std::max(p_MinET1,p_MinET2)) && (parType_t((*tob2)->Et()) <= std::max(p_MinET1,p_MinET2))) continue;
115  // OneBarrel
116  if (p_OneBarrel && parType_t(std::abs((*tob1)->eta())) > 10 && parType_t(std::abs((*tob2)->eta())) > 10 ) continue;
117  // DeltaR2 cuts
118  unsigned int deltaR2 = calcDeltaR2BW( *tob1, *tob2 );
119  // Charge cut ( 1 = positive, -1 = negative, 0 = undefined (RPC) )
120  int charge1 = (*tob1)->charge();
121  int charge2 = (*tob2)->charge();
122  int totalCharge = charge1 + charge2;
123  bool acceptCharge = true;
124  if ( std::abs(totalCharge) == 2 ) { acceptCharge = false; }
125  for(unsigned int i=0; i<numberOutputBits(); ++i) {
126  bool accept = false;
127  accept = deltaR2 >= p_DeltaRMin[i] && deltaR2 <= p_DeltaRMax[i] && acceptCharge;
128  const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
129  const bool fillReject = fillHistos() and not fillAccept;
130  const bool alreadyFilled = decision.bit(i);
131  if( accept ) {
132  decision.setBit(i, true);
133  output[i]->push_back( TCS::CompositeTOB(*tob1, *tob2) );
134  }
135  if(fillAccept and not alreadyFilled) {
136  fillHist1D(m_histAccept[i],std::sqrt(static_cast<float>(deltaR2)));
137  fillHist2D(m_histAcceptEta1Eta2[i],(*tob1)->eta(),(*tob2)->eta());
138  } else if(fillReject) {
139  fillHist1D(m_histReject[i],std::sqrt(static_cast<float>(deltaR2)));
140  fillHist2D(m_histRejectEta1Eta2[i],(*tob1)->eta(),(*tob2)->eta());
141  }
142  TRG_MSG_DEBUG("Decision " << i << ": " << (accept?"pass":"fail") << " deltaR2 = " << deltaR2);
143  }
144  }
145  }
146  } else {
147  TCS_EXCEPTION("DeltaRSqrIncl1Charge alg must have either 1 input, but got " << input.size());
148  }
150 }
151 
153 TCS::DeltaRSqrIncl1Charge::process( const std::vector<TCS::TOBArray const *> & input,
154  const std::vector<TCS::TOBArray *> & output,
155  Decision & decision )
156 {
157  if(input.size() == 1) {
158  for( TOBArray::const_iterator tob1 = input[0]->begin();
159  tob1 != input[0]->end() && distance( input[0]->begin(), tob1) < p_NumberLeading1;
160  ++tob1)
161  {
162  if( parType_t((*tob1)->Et()) <= std::min(p_MinET1,p_MinET2)) continue; // ET cut
163  TCS::TOBArray::const_iterator tob2 = tob1; ++tob2;
164  for( ;
165  tob2 != input[0]->end() && distance( input[0]->begin(), tob2) < p_NumberLeading2;
166  ++tob2) {
167  if( parType_t((*tob2)->Et()) <= std::min(p_MinET1,p_MinET2)) continue; // ET cut
168  if( (parType_t((*tob1)->Et()) <= std::max(p_MinET1,p_MinET2)) && (parType_t((*tob2)->Et()) <= std::max(p_MinET1,p_MinET2))) continue;
169  // OneBarrel
170  if (p_OneBarrel && parType_t(std::abs((*tob1)->eta())) > 10 && parType_t(std::abs((*tob2)->eta())) > 10 ) continue;
171  // DeltaR2 cuts
172  unsigned int deltaR2 = calcDeltaR2( *tob1, *tob2 );
173  // Charge cut ( 1 = positive, -1 = negative, 0 = undefined (RPC) )
174  int charge1 = (*tob1)->charge();
175  int charge2 = (*tob2)->charge();
176  int totalCharge = charge1 + charge2;
177  bool acceptCharge = true;
178  if ( std::abs(totalCharge) == 2 ) { acceptCharge = false; }
179  for(unsigned int i=0; i<numberOutputBits(); ++i) {
180  bool accept = false;
181  accept = deltaR2 >= p_DeltaRMin[i] && deltaR2 <= p_DeltaRMax[i] && acceptCharge;
182  const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
183  const bool fillReject = fillHistos() and not fillAccept;
184  const bool alreadyFilled = decision.bit(i);
185  if( accept ) {
186  decision.setBit(i, true);
187  output[i]->push_back( TCS::CompositeTOB(*tob1, *tob2) );
188  }
189  if(fillAccept and not alreadyFilled) {
190  fillHist1D(m_histAccept[i],std::sqrt(static_cast<float>(deltaR2)));
191  fillHist2D(m_histAcceptEta1Eta2[i],(*tob1)->eta(),(*tob2)->eta());
192  } else if(fillReject) {
193  fillHist1D(m_histReject[i],std::sqrt(static_cast<float>(deltaR2)));
194  fillHist2D(m_histRejectEta1Eta2[i],(*tob1)->eta(),(*tob2)->eta());
195  }
196  TRG_MSG_DEBUG("Decision " << i << ": " << (accept?"pass":"fail") << " deltaR2 = " << deltaR2);
197  }
198  }
199  }
200  } else {
201  TCS_EXCEPTION("DeltaRSqrIncl1Charge alg must have either 1 input, but got " << input.size());
202  }
204 }
Kinematics.h
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:122
TCS::DeltaRSqrIncl1Charge::initialize
virtual StatusCode initialize()
Definition: DeltaRSqrIncl1Charge.cxx:50
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:98
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::DeltaRSqrIncl1Charge::~DeltaRSqrIncl1Charge
virtual ~DeltaRSqrIncl1Charge()
Definition: DeltaRSqrIncl1Charge.cxx:46
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
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
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:153
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
TCS::DeltaRSqrIncl1Charge::DeltaRSqrIncl1Charge
DeltaRSqrIncl1Charge(const std::string &name)
Definition: DeltaRSqrIncl1Charge.cxx:29
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