ATLAS Offline Software
DeltaPhiIncl1.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  * DeltaPhiIncl1.cpp
6  * Created by Joerg Stelzer on 11/16/12.
7  * Modified by V SOrin 2014
8  *
9  * @brief algorithm calculates the phi-distance between one lists and applies delta-phi criteria
10  *
11  * @param NumberLeading
12 **********************************/
13 
14 #include <cmath>
15 
17 #include "L1TopoCommon/Exception.h"
20 
21 REGISTER_ALG_TCS(DeltaPhiIncl1)
22 
23 
25 {
26  defineParameter("InputWidth", 0);
27  defineParameter("MaxTob", 0);
28  defineParameter("NumResultBits", 2);
29  defineParameter("MinET1",0,0);
30  defineParameter("MinET2",0,0);
31  defineParameter("MinDeltaPhi", 0, 0);
32  defineParameter("MaxDeltaPhi", 31, 0);
33  defineParameter("MinET1",0,1);
34  defineParameter("MinET2",0,1);
35  defineParameter("MinDeltaPhi", 0, 1);
36  defineParameter("MaxDeltaPhi", 31, 1);
37 
38  setNumberOutputBits(2);
39 }
40 
42 
43 
46 
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 
55  for(unsigned int i=0; i<numberOutputBits(); ++i) {
56  p_DeltaPhiMin[i] = parameter("MinDeltaPhi", i).value();
57  p_DeltaPhiMax[i] = parameter("MaxDeltaPhi", i).value();
58  p_MinET1[i] = parameter("MinET1",i).value();
59  p_MinET2[i] = parameter("MinET2",i).value();
60 
61  TRG_MSG_INFO("DeltaPhiMin : " << p_DeltaPhiMin[i]);
62  TRG_MSG_INFO("DeltaPhiMax : " << p_DeltaPhiMax[i]);
63  TRG_MSG_INFO("MinET1 : " << p_MinET1[i]);
64  TRG_MSG_INFO("MinET2 : " << p_MinET2[i]);
65 
66  }
67 
68  TRG_MSG_INFO("NumberLeading1 : " << p_NumberLeading1); // note that the reading of generic parameters doesn't work yet
69  TRG_MSG_INFO("NumberLeading2 : " << p_NumberLeading2);
70  TRG_MSG_INFO("number output : " << numberOutputBits());
71 
72  // book histograms
73  for(unsigned int i=0; i<numberOutputBits(); ++i) {
74  std::string hname_accept = "hDeltaPhiIncl1_accept_bit"+std::to_string((int)i);
75  std::string hname_reject = "hDeltaPhiIncl1_reject_bit"+std::to_string((int)i);
76  // mass
77  bookHist(m_histAccept, hname_accept, "DPHI", 100, p_DeltaPhiMin[i], p_DeltaPhiMax[i]);
78  bookHist(m_histReject, hname_reject, "DPHI", 100, p_DeltaPhiMin[i], p_DeltaPhiMax[i]);
79  }
80 
81 
82  return StatusCode::SUCCESS;
83 }
84 
85 
86 
88 TCS::DeltaPhiIncl1::processBitCorrect( const std::vector<TCS::TOBArray const *> & input,
89  const std::vector<TCS::TOBArray *> & output,
90  Decision & decision )
91 {
92  if(input.size() == 1) {
93  TRG_MSG_DEBUG("input size : " << input[0]->size());
94  unsigned int nLeading = p_NumberLeading1;
95  unsigned int nLeading2 = p_NumberLeading2;
96  for( TOBArray::const_iterator tob1 = input[0]->begin();
97  tob1 != input[0]->end() && distance( input[0]->begin(), tob1) < nLeading;
98  ++tob1)
99  {
100  TCS::TOBArray::const_iterator tob2 = tob1; ++tob2;
101  for( ;
102  tob2 != input[0]->end() && distance( input[0]->begin(), tob2) < nLeading2;
103  ++tob2) {
104  // DeltaPhi cuts
105  unsigned int deltaPhi = calcDeltaPhiBW( *tob1, *tob2 );
106  std::stringstream msgss;
107  msgss << " phi1=" << (*tob1)->phi() << " , phi2=" << (*tob2)->phi()
108  << ", DeltaPhi = " << deltaPhi << " -> ";
109  for(unsigned int i=0; i<numberOutputBits(); ++i) {
110  bool accept = false;
111  if( parType_t((*tob1)->Et()) <= std::min(p_MinET1[i],p_MinET2[i])) continue; // ET cut
112  if( parType_t((*tob2)->Et()) <= std::min(p_MinET1[i],p_MinET2[i])) continue; // ET cut
113  if( (parType_t((*tob1)->Et()) <= std::max(p_MinET1[i],p_MinET2[i])) && (parType_t((*tob2)->Et()) <= std::max(p_MinET1[i],p_MinET2[i]))) continue;
114  accept = deltaPhi >= p_DeltaPhiMin[i] && deltaPhi <= p_DeltaPhiMax[i];
115  const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
116  const bool fillReject = fillHistos() and not fillAccept;
117  const bool alreadyFilled = decision.bit(i);
118  if( accept ) {
119  decision.setBit(i, true);
120  output[i]->push_back( TCS::CompositeTOB(*tob1, *tob2) );
121  }
122  if(fillAccept and not alreadyFilled) {
123  fillHist1D(m_histAccept[i],deltaPhi);
124  } else if(fillReject) {
125  fillHist1D(m_histReject[i],deltaPhi);
126  }
127  TRG_MSG_DEBUG("DeltaPhiIncl1 = " << deltaPhi << " -> "
128  << (accept?"pass":"fail"));
129  }
130  }
131  }
132  for (unsigned int i=0; i < numberOutputBits(); ++i) {
133  bool hasAmbiguousInputs = TSU::isAmbiguousTruncation(input[0], p_NumberLeading1, p_MinET1[i])
134  || TSU::isAmbiguousTruncation(input[0], p_NumberLeading2, p_MinET2[i]);
135  output[i]->setAmbiguityFlag(hasAmbiguousInputs);
136  }
137  } else {
138  TCS_EXCEPTION("DeltaPhiIncl1 alg must have 1 input, but got " << input.size());
139  }
141 }
142 
144 TCS::DeltaPhiIncl1::process( const std::vector<TCS::TOBArray const *> & input,
145  const std::vector<TCS::TOBArray *> & output,
146  Decision & decision )
147 {
148  if(input.size() == 1) {
149  TRG_MSG_DEBUG("input size : " << input[0]->size());
150  unsigned int nLeading = p_NumberLeading1;
151  unsigned int nLeading2 = p_NumberLeading2;
152  for( TOBArray::const_iterator tob1 = input[0]->begin();
153  tob1 != input[0]->end() && distance( input[0]->begin(), tob1) < nLeading;
154  ++tob1)
155  {
156  if (nLeading < input[0]->size()) {
157  TCS::TOBArray::const_iterator tob1_plus1 = tob1; ++tob1_plus1;
158  if ((*tob1)->Et() == (*tob1_plus1)->Et() && distance(input[0]->begin(), tob1) == nLeading - 1) {
159  for(unsigned int i=0; i<numberOutputBits(); ++i) {
160  output[i]->setAmbiguityFlag(true);
161  }
162  }
163  }
164  TCS::TOBArray::const_iterator tob2 = tob1; ++tob2;
165  for( ;
166  tob2 != input[0]->end() && distance( input[0]->begin(), tob2) < nLeading2;
167  ++tob2) {
168  // DeltaPhi cuts
169  unsigned int deltaPhi = calcDeltaPhi( *tob1, *tob2 );
170  std::stringstream msgss;
171  msgss << " Combination : " << distance( input[0]->begin(), tob1)
172  << " x " << distance( input[0]->begin(), tob2)
173  << " phi1=" << (*tob1)->phi()
174  << " , phi2=" << (*tob2)->phi()
175  << ", DeltaPhi = " << deltaPhi << " -> ";
176  for(unsigned int i=0; i<numberOutputBits(); ++i) {
177  bool accept = false;
178  if( parType_t((*tob1)->Et()) <= std::min(p_MinET1[i],p_MinET2[i])) continue; // ET cut
179  if( parType_t((*tob2)->Et()) <= std::min(p_MinET1[i],p_MinET2[i])) continue; // ET cut
180  if( (parType_t((*tob1)->Et()) <= std::max(p_MinET1[i],p_MinET2[i])) && (parType_t((*tob2)->Et()) <= std::max(p_MinET1[i],p_MinET2[i]))) continue;
181  accept = deltaPhi >= p_DeltaPhiMin[i] && deltaPhi <= p_DeltaPhiMax[i];
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],deltaPhi);
191  } else if(fillReject) {
192  fillHist1D(m_histReject[i],deltaPhi);
193  }
194  TRG_MSG_DEBUG("DeltaPhiIncl1 = " << deltaPhi << " -> "
195  << (accept?"pass":"fail"));
196  }
197  }
198  }
199  } else {
200  TCS_EXCEPTION("DeltaPhiIncl1 alg must have 1 input, but got " << input.size());
201  }
203 }
TCS::DeltaPhiIncl1::processBitCorrect
virtual StatusCode processBitCorrect(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison)
Definition: DeltaPhiIncl1.cxx:88
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::DeltaPhiIncl1::process
virtual StatusCode process(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison)
Definition: DeltaPhiIncl1.cxx:144
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
xAOD::deltaPhi
setSAddress setEtaMS setDirPhiMS setDirZMS setBarrelRadius setEndcapAlpha setEndcapRadius setInterceptInner setEtaMap setEtaBin setIsTgcFailure setDeltaPt deltaPhi
Definition: L2StandAloneMuon_v1.cxx:161
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
Decision.h
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:560
TCS::DecisionAlg
Definition: Trigger/TrigT1/L1Topo/L1TopoInterfaces/L1TopoInterfaces/DecisionAlg.h:22
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
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::DeltaPhiIncl1::initialize
virtual StatusCode initialize()
Definition: DeltaPhiIncl1.cxx:45
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
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
DeltaPhiIncl1.h
TCS::DeltaPhiIncl1
Definition: DeltaPhiIncl1.h:16
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::DeltaPhiIncl1::~DeltaPhiIncl1
virtual ~DeltaPhiIncl1()
Definition: DeltaPhiIncl1.cxx:41
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