ATLAS Offline Software
DeltaEtaIncl1.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  * DeltaEtaIncl1.cpp
6  * Created by Joerg Stelzer on 11/16/12.
7  * Modified by V Sorin 2014
8  *
9  * @brief algorithm calculates the eta-distance between two TOB from one list and applies delta-eta criteria
10  *
11  * @param NumberLeading
12 **********************************/
13 
14 #include <cmath>
15 #include <string>
16 #include <iostream>
17 #include <sstream>
18 #include <vector>
19 
21 #include "L1TopoCommon/Exception.h"
23 
24 REGISTER_ALG_TCS(DeltaEtaIncl1)
25 
26 // not the best solution but we will move to athena where this comes for free
27 #define LOG cout << fullname() << ": "
28 
29 
31 {
32  defineParameter("InputWidth", 0);
33  defineParameter("MaxTob", 0);
34  defineParameter("NumResultBits", 4);
35  defineParameter("MinET1",0,0);
36  defineParameter("MinET2",0,0);
37  defineParameter("MinET1",0,1);
38  defineParameter("MinET2",0,1);
39  defineParameter("MinET1",0,2);
40  defineParameter("MinET2",0,2);
41  defineParameter("MinET1",0,3);
42  defineParameter("MinET2",0,3);
43 
44  defineParameter("MinDeltaEta", 0, 0);
45  defineParameter("MaxDeltaEta", 127, 0);
46  defineParameter("MinDeltaEta", 0, 1);
47  defineParameter("MaxDeltaEta", 127, 1);
48  defineParameter("MinDeltaEta", 0, 2);
49  defineParameter("MaxDeltaEta", 127, 2);
50  defineParameter("MinDeltaEta", 0, 3);
51  defineParameter("MaxDeltaEta", 127, 3);
52 
54 }
55 
57 
58 
61 
62  if(parameter("MaxTob").value() > 0) {
63  p_NumberLeading1 = parameter("MaxTob").value();
64  p_NumberLeading2 = parameter("MaxTob").value();
65  } else {
66  p_NumberLeading1 = parameter("InputWidth").value();
67  p_NumberLeading2 = parameter("InputWidth").value();
68  }
69 
70  for(unsigned int i=0; i<numberOutputBits(); ++i) {
71  p_DeltaEtaMin[i] = parameter("MinDeltaEta", i).value();
72  p_DeltaEtaMax[i] = parameter("MaxDeltaEta", i).value();
73 
74  p_MinET1[i] = parameter("MinET1",i).value();
75  p_MinET2[i] = parameter("MinET2",i).value();
76  }
77 
78  TRG_MSG_INFO("NumberLeading1 : " << p_NumberLeading1); // note that the reading of generic parameters doesn't work yet
79  TRG_MSG_INFO("NumberLeading2 : " << p_NumberLeading2);
80  for(unsigned int i=0; i<numberOutputBits(); ++i) {
81  TRG_MSG_INFO("DeltaEtaMin0 : " << p_DeltaEtaMin[i]);
82  TRG_MSG_INFO("DeltaEtaMax0 : " << p_DeltaEtaMax[i]);
83  TRG_MSG_INFO("MinET1 : " << p_MinET1[i]);
84  TRG_MSG_INFO("MinET2 : " << p_MinET2[i]);
85  }
86  TRG_MSG_INFO("number output : " << numberOutputBits());
87 
88  // book histograms
89  for(unsigned int i=0; i<numberOutputBits(); ++i) {
90  std::string hname_accept = "hDeltaEtaIncl1_accept_bit"+std::to_string((int)i);
91  std::string hname_reject = "hDeltaEtaIncl1_reject_bit"+std::to_string((int)i);
92  // mass
93  bookHist(m_histAccept, hname_accept, "DETA", 100, p_DeltaEtaMin[i], p_DeltaEtaMax[i]);
94  bookHist(m_histReject, hname_reject, "DETA", 100, p_DeltaEtaMin[i], p_DeltaEtaMax[i]);
95  }
96 
97 
98  return StatusCode::SUCCESS;
99 }
100 
101 
103 TCS::DeltaEtaIncl1::processBitCorrect( const std::vector<TCS::TOBArray const *> & input,
104  const std::vector<TCS::TOBArray *> & output,
105  Decision & decision )
106 
107 {
108  if(input.size() == 1) {
109  unsigned int nLeading = p_NumberLeading1;
110  unsigned int nLeading2 = p_NumberLeading2;
111  if (nLeading < input[0]->size() && nLeading2 < input[0]->size()) { output[0]->setAmbiguityFlag(false); }
112  for( TOBArray::const_iterator tob1 = input[0]->begin();
113  tob1 != input[0]->end() && distance( input[0]->begin(), tob1) < nLeading;
114  ++tob1)
115  {
116  TCS::TOBArray::const_iterator tob2 = tob1; ++tob2;
117  for( ;
118  tob2 != input[0]->end() && distance( input[0]->begin(), tob2) < nLeading2;
119  ++tob2) {
120  for(unsigned int i=0; i < numberOutputBits(); ++i) {
121  if (input[0]->size() >= nLeading2+1) {
122  TCS::TOBArray::const_iterator tob3 = tob2; ++tob3;
123  if ((*tob2)->Et() == (*tob3)->Et() && distance(input[0]->begin(), tob2) == nLeading2 - 1) {
124  output[0]->setAmbiguityFlag(true);
125  }
126  }
127  bool accept = false;
128  if( parType_t((*tob1)->Et()) <= std::min(p_MinET1[i],p_MinET2[i])) continue; // ET cut
129  if( parType_t((*tob2)->Et()) <= std::min(p_MinET1[i],p_MinET2[i])) continue; // ET cut
130  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;
131  // DeltaEta cuts
132  unsigned int deltaEta = calcDeltaEtaBW( *tob1, *tob2 );
133  std::stringstream msgss;
134  msgss << "Combination : " << distance( input[0]->begin(), tob1)
135  << " x " << distance( input[0]->begin(), tob2)
136  << " eta=" << (*tob1)->eta()
137  << " , eta=" << (*tob2)->eta()
138  << ", DeltaEta = " << deltaEta << " -> ";
139  accept = deltaEta >= p_DeltaEtaMin[i] && deltaEta <= p_DeltaEtaMax[i];
140  const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
141  const bool fillReject = fillHistos() and not fillAccept;
142  const bool alreadyFilled = decision.bit(i);
143  if( accept ) {
144  decision.setBit(i, true);
145  output[i]->push_back( TCS::CompositeTOB(*tob1, *tob2) );
146  }
147  if(fillAccept and not alreadyFilled) {
148  fillHist1D(m_histAccept[i],(float)deltaEta);
149  } else if(fillReject) {
150  fillHist1D(m_histReject[i],(float)deltaEta);
151  }
152  msgss << (accept?"pass":"fail") << "|";
153  TRG_MSG_DEBUG(msgss.str());
154  }
155  }
156  }
157  } else {
158  TCS_EXCEPTION("DeltaEtaIncl1 alg must have 1 input, but got " << input.size());
159  }
161 }
162 
164 TCS::DeltaEtaIncl1::process( const std::vector<TCS::TOBArray const *> & input,
165  const std::vector<TCS::TOBArray *> & output,
166  Decision & decision )
167 {
168  if(input.size() == 1) {
169  //LOG << "input size : " << input[0]->size() << endl;
170  unsigned int nLeading = p_NumberLeading1;
171  unsigned int nLeading2 = p_NumberLeading2;
172  if (nLeading < input[0]->size() && nLeading2 < input[0]->size()) { output[0]->setAmbiguityFlag(false); }
173  for( TOBArray::const_iterator tob1 = input[0]->begin();
174  tob1 != input[0]->end() && distance( input[0]->begin(), tob1) < nLeading;
175  ++tob1)
176  {
177  TCS::TOBArray::const_iterator tob2 = tob1; ++tob2;
178  for( ;
179  tob2 != input[0]->end() && distance( input[0]->begin(), tob2) < nLeading2;
180  ++tob2) {
181  for(unsigned int i=0; i < numberOutputBits(); ++i) {
182  if (input[0]->size() >= nLeading2+1) {
183  TCS::TOBArray::const_iterator tob3 = tob2; ++tob3;
184  if ((*tob2)->Et() == (*tob3)->Et() && distance(input[0]->begin(), tob2) == nLeading2 - 1) {
185  output[0]->setAmbiguityFlag(true);
186  }
187  }
188  bool accept = false;
189  if( parType_t((*tob1)->Et()) <= std::min(p_MinET1[i],p_MinET2[i])) continue; // ET cut
190  if( parType_t((*tob2)->Et()) <= std::min(p_MinET1[i],p_MinET2[i])) continue; // ET cut
191  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;
192  // DeltaEta cuts
193  unsigned int deltaEta = calcDeltaEta( *tob1, *tob2 );
194  std::stringstream msgss;
195  msgss << "Combination : " << distance( input[0]->begin(), tob1)
196  << " x " << distance( input[0]->begin(), tob2)
197  << " eta=" << (*tob1)->eta()
198  << " , eta=" << (*tob2)->eta()
199  << ", DeltaEta = " << deltaEta << " -> ";
200  accept = deltaEta >= p_DeltaEtaMin[i] && deltaEta <= p_DeltaEtaMax[i];
201  const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
202  const bool fillReject = fillHistos() and not fillAccept;
203  const bool alreadyFilled = decision.bit(i);
204  if( accept ) {
205  decision.setBit(i, true);
206  output[i]->push_back( TCS::CompositeTOB(*tob1, *tob2) );
207  }
208  if(fillAccept and not alreadyFilled) {
209  fillHist1D(m_histAccept[i],(float)deltaEta);
210  } else if(fillReject) {
211  fillHist1D(m_histReject[i],(float)deltaEta);
212  }
213  msgss << (accept?"pass":"fail") << "|";
214  TRG_MSG_DEBUG(msgss.str());
215  }
216  }
217  }
218  } else {
219  TCS_EXCEPTION("DeltaEtaIncl1 alg must have 1 input, but got " << input.size());
220  }
222 }
TCS::StatusCode::SUCCESS
@ SUCCESS
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/L1TopoCommon/StatusCode.h:17
DeltaEtaIncl1.h
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
Decision.h
TCS::DeltaEtaIncl1::~DeltaEtaIncl1
virtual ~DeltaEtaIncl1()
Definition: DeltaEtaIncl1.cxx:56
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
P4Helpers::deltaEta
double deltaEta(const I4Momentum &p1, const I4Momentum &p2)
Computes efficiently .
Definition: P4Helpers.h:53
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::DeltaEtaIncl1::initialize
virtual StatusCode initialize()
Definition: DeltaEtaIncl1.cxx:60
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
TCS::DeltaEtaIncl1::DeltaEtaIncl1
DeltaEtaIncl1(const std::string &name)
Definition: DeltaEtaIncl1.cxx:30
min
#define min(a, b)
Definition: cfImp.cxx:40
TCS::DeltaEtaIncl1::process
virtual StatusCode process(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison)
Definition: DeltaEtaIncl1.cxx:164
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::DeltaEtaIncl1::processBitCorrect
virtual StatusCode processBitCorrect(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison)
Definition: DeltaEtaIncl1.cxx:103
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