ATLAS Offline Software
MinDeltaPhiIncl2.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 /*********************************
5  * MinDeltaPhiIncl2.cpp
6  * Created by Veronica Sorin on 14/8/14.
7  *
8  * @brief algorithm calculates the min phi-distance between two lists and applies delta-phi criteria
9  *
10  * @param NumberLeading
11 **********************************/
12 
13 
14 
16 #include "L1TopoCommon/Exception.h"
18 #include <cmath>
19 #include <string>
20 #include <algorithm>
21 
22 REGISTER_ALG_TCS(MinDeltaPhiIncl2)
23 
24 // not the best solution but we will move to athena where this comes for free
25 #define LOG std::cout << "TCS::MinDeltaPhiIncl2: "
26 
28 {
29  defineParameter("InputWidth1", 9);
30  defineParameter("InputWidth2", 9);
31  defineParameter("MaxTob1", 0);
32  defineParameter("MaxTob2", 0);
33  defineParameter("NumResultBits", 3);
34  defineParameter("DeltaPhiMin", 0, 0);
35  defineParameter("DeltaPhiMin", 0, 1);
36  defineParameter("DeltaPhiMin", 0, 2);
37  defineParameter("MinET1",1);
38  defineParameter("MinET2",1);
40 }
41 
43 
44 
47  p_NumberLeading1 = parameter("InputWidth1").value();
48  p_NumberLeading2 = parameter("InputWidth2").value();
49  if(parameter("MaxTob1").value() > 0) p_NumberLeading1 = parameter("MaxTob1").value();
50  if(parameter("MaxTob2").value() > 0) p_NumberLeading2 = parameter("MaxTob2").value();
51 
52  for(unsigned int i=0; i< numberOutputBits(); ++i) {
53  p_DeltaPhiMin[i] = parameter("DeltaPhiMin", i).value();
54  }
55  p_MinET1 = parameter("MinET1").value();
56  p_MinET2 = parameter("MinET2").value();
57  TRG_MSG_INFO("NumberLeading1 : " << p_NumberLeading1);
58  TRG_MSG_INFO("NumberLeading2 : " << p_NumberLeading2);
59  for(unsigned int i=0; i< numberOutputBits(); ++i) {
60  TRG_MSG_INFO("DeltaPhiMin"<<i<<" : " << p_DeltaPhiMin[i]);
61  }
62  TRG_MSG_INFO("MinET1 : " << p_MinET1);
63  TRG_MSG_INFO("MinET2 : " << p_MinET2);
64  TRG_MSG_INFO("nummber output : " << numberOutputBits());
65 
66  // book histograms
67  for(unsigned int i=0; i<numberOutputBits(); ++i) {
68  std::string hname_accept = "hMinDeltaPhiIncl2_accept_bit"+std::to_string((int)i);
69  std::string hname_reject = "hMinDeltaPhiIncl2_reject_bit"+std::to_string((int)i);
70  // mass
71  bookHist(m_histAccept, hname_accept, "DPHI", 100, p_DeltaPhiMin[i], 70);
72  bookHist(m_histReject, hname_reject, "DPHI", 100, p_DeltaPhiMin[i], 70);
73  }
74 
75  return StatusCode::SUCCESS;
76 }
77 
78 
79 
81 TCS::MinDeltaPhiIncl2::processBitCorrect( const std::vector<TCS::TOBArray const *> & input,
82  const std::vector<TCS::TOBArray *> & output,
83  Decision & decision )
84 {
85 
86  // mindphi
87  unsigned int mindphi = *std::min_element(std::begin(p_DeltaPhiMin),std::end(p_DeltaPhiMin));
88  bool firstphi = true;
89 
90  // declare iterator for the tob with min dphi
91  TCS::TOBArray::const_iterator tobmin1,tobmin2;
92  const TCS::TOBArray::const_iterator invalidIterator;
93 
94  if (input.size() == 2) {
95 
96  for( TOBArray::const_iterator tob1 = input[0]->begin();
97  tob1 != input[0]->end() && distance(input[0]->begin(), tob1) < p_NumberLeading1;
98  ++tob1)
99  {
100 
101  if( parType_t((*tob1)->Et()) <= p_MinET1) continue; // ET cut
102 
103  for( TCS::TOBArray::const_iterator tob2 = input[1]->begin();
104  tob2 != input[1]->end() && distance(input[1]->begin(), tob2) < p_NumberLeading2;
105  ++tob2) {
106 
107  if( parType_t((*tob2)->Et()) <= p_MinET2) continue; // ET cut
108 
109  // test DeltaPhiMin, DeltaPhiMax
110  unsigned int deltaPhi = calcDeltaPhiBW( *tob1, *tob2 );
111 
112  if (firstphi) {
113  mindphi = deltaPhi;
114  tobmin1=tob1;
115  tobmin2=tob2;
116  firstphi = false;
117  }
118 
119  if ( deltaPhi < mindphi ) {
120 
121  mindphi = deltaPhi;
122  tobmin1=tob1;
123  tobmin2=tob2;
124 
125  }
126 
127  }
128  }
129 
130  for(unsigned int i=0; i<numberOutputBits(); ++i) {
131  bool accept = mindphi > p_DeltaPhiMin[i] ;
132  const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
133  const bool fillReject = fillHistos() and not fillAccept;
134  const bool alreadyFilled = decision.bit(i);
135  if( accept and (tobmin1!=invalidIterator and tobmin2!=invalidIterator)) {
136  decision.setBit(i, true);
137  output[i]->push_back(TCS::CompositeTOB(*tobmin1, *tobmin2));
138  }
139  if(fillAccept and not alreadyFilled){
140  fillHist1D(m_histAccept[i],(float)mindphi);
141  } else if(fillReject){
142  fillHist1D(m_histReject[i],(float)mindphi);
143  }
144  TRG_MSG_DEBUG("Decision " << i << ": " << (accept?"pass":"fail"));
145  } // for(i)
146  } else {
147  TCS_EXCEPTION("MinDeltaPhiIncl2 alg must have 2 inputs, but got " << input.size());
148  }
149 
151 }
152 
154 TCS::MinDeltaPhiIncl2::process( const std::vector<TCS::TOBArray const *> & input,
155  const std::vector<TCS::TOBArray *> & output,
156  Decision & decision )
157 {
158 
159  // mindphi
160  unsigned int mindphi = *std::min_element(std::begin(p_DeltaPhiMin),std::end(p_DeltaPhiMin));
161  bool firstphi = true;
162 
163  // declare iterator for the tob with min dphi
164  TCS::TOBArray::const_iterator tobmin1,tobmin2;
165 
166  if (input.size() == 2) {
167 
168  for( TOBArray::const_iterator tob1 = input[0]->begin();
169  tob1 != input[0]->end() && distance(input[0]->begin(), tob1) < p_NumberLeading1;
170  ++tob1)
171  {
172 
173  if( parType_t((*tob1)->Et()) <= p_MinET1) continue; // ET cut
174 
175  for( TCS::TOBArray::const_iterator tob2 = input[1]->begin();
176  tob2 != input[1]->end() && distance(input[1]->begin(), tob2) < p_NumberLeading2;
177  ++tob2) {
178 
179  if( parType_t((*tob2)->Et()) <= p_MinET2) continue; // ET cut
180 
181  // test DeltaPhiMin, DeltaPhiMax
182  unsigned int deltaPhi = calcDeltaPhi( *tob1, *tob2 );
183 
184  if (firstphi) {
185  mindphi = deltaPhi;
186  tobmin1=tob1;
187  tobmin2=tob2;
188  firstphi = false;
189  }
190 
191  if ( deltaPhi < mindphi ) {
192 
193  mindphi = deltaPhi;
194  tobmin1=tob1;
195  tobmin2=tob2;
196 
197  }
198 
199  }
200  }
201 
202  for(unsigned int i=0; i<numberOutputBits(); ++i) {
203  bool accept = mindphi > p_DeltaPhiMin[i] ;
204  const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
205  const bool fillReject = fillHistos() and not fillAccept;
206  const bool alreadyFilled = decision.bit(i);
207  if( accept) {
208  decision.setBit(i, true);
209  output[i]->push_back(TCS::CompositeTOB(*tobmin1, *tobmin2));
210  }
211  if(fillAccept and not alreadyFilled){
212  fillHist1D(m_histAccept[i],(float)mindphi);
213  } else if(fillReject) {
214  fillHist1D(m_histReject[i],(float)mindphi);
215  }
216  TRG_MSG_DEBUG("Decision " << i << ": " << (accept?"pass":"fail"));
217  }
218  } else {
219  TCS_EXCEPTION("MinDeltaPhiIncl2 alg must have 2 inputs, but got " << input.size());
220  }
221 
223 }
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
xAOD::deltaPhi
setSAddress setEtaMS setDirPhiMS setDirZMS setBarrelRadius setEndcapAlpha setEndcapRadius setInterceptInner setEtaMap setEtaBin setIsTgcFailure setDeltaPt deltaPhi
Definition: L2StandAloneMuon_v1.cxx:160
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
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
TCS::MinDeltaPhiIncl2::processBitCorrect
virtual StatusCode processBitCorrect(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison)
Definition: MinDeltaPhiIncl2.cxx:81
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
TCS::MinDeltaPhiIncl2::~MinDeltaPhiIncl2
virtual ~MinDeltaPhiIncl2()
Definition: MinDeltaPhiIncl2.cxx:42
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
MinDeltaPhiIncl2.h
TCS::MinDeltaPhiIncl2::MinDeltaPhiIncl2
MinDeltaPhiIncl2(const std::string &name)
Definition: MinDeltaPhiIncl2.cxx:27
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
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::MinDeltaPhiIncl2::initialize
virtual StatusCode initialize()
Definition: MinDeltaPhiIncl2.cxx:46
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
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::MinDeltaPhiIncl2::process
virtual StatusCode process(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison)
Definition: MinDeltaPhiIncl2.cxx:154