ATLAS Offline Software
InvariantMassDeltaPhiInclusive1.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 /*********************************
5  * InvariantMassDeltaPhiInclusive1.cxx
6  * Based on implementation of InvariantMassDeltaPhiInclusive2. For questions contact atlas-trig-l1topo-algcom@cern.ch.
7  *
8  * @brief algorithm calculates the sqr of the INVMASS between all element of a list and applies invmass criteria.
9  * For pairs passing the INVMASS cut a further requirement based on DeltaPhi is applied, addressing ATR-19377
10  *
11 **********************************/
12 // TO DO size of the input list to be possbly refined
13 
15 #include "L1TopoCommon/Exception.h"
18 
19 #include <cmath>
20 
21 REGISTER_ALG_TCS(InvariantMassDeltaPhiInclusive1)
22 
23 
25 {
26  defineParameter("InputWidth", 9);
27  defineParameter("MaxTob", 0);
28  defineParameter("NumResultBits", 6);
29  defineParameter("MinMSqr", 0, 0);
30  defineParameter("MaxMSqr", 999, 0);
31  defineParameter("MinMSqr", 0, 1);
32  defineParameter("MaxMSqr", 999, 1);
33  defineParameter("MinMSqr", 0, 2);
34  defineParameter("MaxMSqr", 999, 2);
35  defineParameter("MinMSqr", 0, 3);
36  defineParameter("MaxMSqr", 999, 3);
37  defineParameter("MinMSqr", 0, 4);
38  defineParameter("MaxMSqr", 999, 4);
39  defineParameter("MinMSqr", 0, 5);
40  defineParameter("MaxMSqr", 999, 5);
41  defineParameter("MinET1",0,0);
42  defineParameter("MinET1",0,1);
43  defineParameter("MinET1",0,2);
44  defineParameter("MinET1",0,3);
45  defineParameter("MinET1",0,4);
46  defineParameter("MinET1",0,5);
47  defineParameter("MinET2",0,0);
48  defineParameter("MinET2",0,1);
49  defineParameter("MinET2",0,2);
50  defineParameter("MinET2",0,3);
51  defineParameter("MinET2",0,4);
52  defineParameter("MinET2",0,5);
53  defineParameter("ApplyEtaCut", 0);
54  defineParameter("MinEta1", 0);
55  defineParameter("MaxEta1", 31);
56  defineParameter("MinEta2", 0);
57  defineParameter("MaxEta2", 31);
58  defineParameter("MinDeltaPhi", 0, 0);
59  defineParameter("MaxDeltaPhi", 31, 0);
60  defineParameter("MinDeltaPhi", 0, 1);
61  defineParameter("MaxDeltaPhi", 31, 1);
62  defineParameter("MinDeltaPhi", 0, 2);
63  defineParameter("MaxDeltaPhi", 31, 2);
64  defineParameter("MinDeltaPhi", 0, 3);
65  defineParameter("MaxDeltaPhi", 31, 3);
66  defineParameter("MinDeltaPhi", 0, 4);
67  defineParameter("MaxDeltaPhi", 31, 4);
68  defineParameter("MinDeltaPhi", 0, 5);
69  defineParameter("MaxDeltaPhi", 31, 5);
70  //does this need to change?
71  setNumberOutputBits(6);
72 }
73 
75 
76 
79  p_NumberLeading = parameter("InputWidth").value();
80  if(parameter("MaxTob").value() > 0) p_NumberLeading = parameter("MaxTob").value();
81 
82  for(unsigned int i=0; i<numberOutputBits(); ++i) {
83  p_InvMassMin[i] = parameter("MinMSqr", i).value();
84  p_InvMassMax[i] = parameter("MaxMSqr", i).value();
85  p_DeltaPhiMin[i] = parameter("MinDeltaPhi", i).value();
86  p_DeltaPhiMax[i] = parameter("MaxDeltaPhi", i).value();
87  p_MinET1[i] = parameter("MinET1",i).value();
88  p_MinET2[i] = parameter("MinET2",i).value();
89  }
90 
91  TRG_MSG_INFO("NumberLeading : " << p_NumberLeading);
92  for(unsigned int i=0; i<numberOutputBits(); ++i) {
93  TRG_MSG_INFO("InvMassMin : " << p_InvMassMin[i]);
94  TRG_MSG_INFO("InvMassMax : " << p_InvMassMax[i]);
95  TRG_MSG_INFO("DeltaPhiMin : " << p_DeltaPhiMin[i]);
96  TRG_MSG_INFO("DeltaPhiMax : " << p_DeltaPhiMax[i]);
97  TRG_MSG_INFO("MinET1 : " << p_MinET1[i]);
98  TRG_MSG_INFO("MinET2 : " << p_MinET2[i]);
99  }
100 
101  p_ApplyEtaCut = parameter("ApplyEtaCut").value();
102  p_MinEta1 = parameter("MinEta1" ).value();
103  p_MaxEta1 = parameter("MaxEta1" ).value();
104  p_MinEta2 = parameter("MinEta2" ).value();
105  p_MaxEta2 = parameter("MaxEta2" ).value();
106  TRG_MSG_INFO("ApplyEtaCut : "<<p_ApplyEtaCut );
107  TRG_MSG_INFO("MinEta1 : "<<p_MinEta1 );
108  TRG_MSG_INFO("MaxEta1 : "<<p_MaxEta1 );
109  TRG_MSG_INFO("MinEta2 : "<<p_MinEta2 );
110  TRG_MSG_INFO("MaxEta2 : "<<p_MaxEta2 );
111 
112  TRG_MSG_INFO("number output : " << numberOutputBits());
113 
114  // book histograms
115  for(unsigned int i=0; i<numberOutputBits(); ++i) {
116  std::string hname_accept = "hInvariantMassDeltaPhiInclusive1_accept_bit"+std::to_string((int)i);
117  std::string hname_reject = "hInvariantMassDeltaPhiInclusive1_reject_bit"+std::to_string((int)i);
118  // mass
119  bookHist(m_histAcceptM, hname_accept, "INVM vs DPHI", 100, sqrt(p_InvMassMin[i]), sqrt(p_InvMassMax[i]), 100, p_DeltaPhiMin[i], p_DeltaPhiMax[i]);
120  bookHist(m_histRejectM, hname_reject, "INVM vs DPHI", 100, sqrt(p_InvMassMin[i]), sqrt(p_InvMassMax[i]), 100, p_DeltaPhiMin[i], p_DeltaPhiMax[i]);
121  // eta2 vs. eta1
122  bookHist(m_histAcceptEta1Eta2, hname_accept, "ETA vs ETA", 100, p_MinEta1, p_MaxEta1, 100, p_MinEta2, p_MaxEta2);
123  bookHist(m_histRejectEta1Eta2, hname_reject, "ETA vs ETA", 100, p_MinEta1, p_MaxEta1, 100, p_MinEta2, p_MaxEta2);
124  }
125  return StatusCode::SUCCESS;
126 }
127 
128 
129 
131 TCS::InvariantMassDeltaPhiInclusive1::processBitCorrect( const std::vector<TCS::TOBArray const *> & input,
132  const std::vector<TCS::TOBArray *> & output,
133  Decision & decision )
134 {
135  int k=0; int j;
136  if( input.size() == 1) {
137  for( TOBArray::const_iterator tob1 = input[0]->begin();
138  tob1 != input[0]->end() && distance(input[0]->begin(), tob1) < p_NumberLeading;
139  ++tob1)
140  {
141  k++; j=0;
142  if (p_NumberLeading < input[0]->size()) {
143  TCS::TOBArray::const_iterator tob1_plus1 = tob1; ++tob1_plus1;
144  if ((*tob1)->Et() == (*tob1_plus1)->Et() && distance(input[0]->begin(), tob1) == p_NumberLeading - 1) {
145  for(unsigned int i=0; i<numberOutputBits(); ++i) {
146  output[i]->setAmbiguityFlag(true);
147  }
148  }
149  }
150  for( TCS::TOBArray::const_iterator tob2 = input[0]->begin();
151  tob2 != input[0]->end() && distance(input[0]->begin(), tob2) < p_NumberLeading;
152  ++tob2) {
153  j++; if(j==k) continue; //Avoid diagonal cases. Both above and below diagonal cases are calculated due to asymmetric ET and eta cuts
154  // Inv Mass calculation
155  unsigned int invmass2 = calcInvMassBW( *tob1, *tob2 );
156  // test DeltaPhiMin, DeltaPhiMax
157  unsigned int deltaPhi = calcDeltaPhiBW( *tob1, *tob2 );
158  const int eta1 = (*tob1)->eta();
159  const int eta2 = (*tob2)->eta();
160  const unsigned int aeta1 = std::abs(eta1);
161  const unsigned int aeta2 = std::abs(eta2);
162  for(unsigned int i=0; i<numberOutputBits(); ++i) {
163  bool accept = false;
164  if( parType_t((*tob1)->Et()) <= p_MinET1[i]) continue; // ET cut
165  if( parType_t((*tob2)->Et()) <= p_MinET2[i]) continue; // ET cut
166  if(p_ApplyEtaCut &&
167  ((aeta1 < p_MinEta1 || aeta1 > p_MaxEta1 ) ||
168  (aeta2 < p_MinEta2 || aeta2 > p_MaxEta2 ) )) continue;
169  accept = invmass2 >= p_InvMassMin[i] && invmass2 <= p_InvMassMax[i] && deltaPhi >= p_DeltaPhiMin[i] && deltaPhi <= p_DeltaPhiMax[i];
170  const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
171  const bool fillReject = fillHistos() and not fillAccept;
172  const bool alreadyFilled = decision.bit(i);
173  if( accept ) {
174  decision.setBit(i, true);
175  output[i]->push_back( TCS::CompositeTOB(*tob1, *tob2) );
176  }
177  if(fillAccept and not alreadyFilled) {
178  fillHist2D(m_histAcceptM[i],sqrt((float)invmass2),(float)deltaPhi);
179  fillHist2D(m_histAcceptEta1Eta2[i],eta1, eta2);
180  } else if(fillReject) {
181  fillHist2D(m_histRejectM[i],sqrt((float)invmass2),(float)deltaPhi);
182  fillHist2D(m_histRejectEta1Eta2[i],eta1, eta2);
183  }
184  TRG_MSG_DEBUG("Decision " << i << ": " << (accept?"pass":"fail") << " invmass2 = " << invmass2);
185  }
186  }
187  }
188  for (unsigned int i=0; i < numberOutputBits(); ++i) {
189  bool hasAmbiguousInputs = TSU::isAmbiguousTruncation(input[0], p_NumberLeading, p_MinET1[i])
190  || TSU::isAmbiguousTruncation(input[0], p_NumberLeading, p_MinET2[i]);
191  output[i]->setAmbiguityFlag(hasAmbiguousInputs);
192  }
193  } else {
194 
195  TCS_EXCEPTION("InvariantMassDeltaPhiInclusive1 alg must have 1 inputs, but got " << input.size());
196 
197  }
199 
200 }
201 
203 TCS::InvariantMassDeltaPhiInclusive1::process( const std::vector<TCS::TOBArray const *> & input,
204  const std::vector<TCS::TOBArray *> & output,
205  Decision & decision )
206 {
207 
208 
209  if( input.size() == 1) {
210  int k=0; int j;
211  for( TOBArray::const_iterator tob1 = input[0]->begin();
212  tob1 != input[0]->end() && distance(input[0]->begin(), tob1) < p_NumberLeading;
213  ++tob1)
214  {
215  k++; j=0;
216  if (p_NumberLeading < input[0]->size()) {
217  TCS::TOBArray::const_iterator tob1_plus1 = tob1; ++tob1_plus1;
218  if ((*tob1)->Et() == (*tob1_plus1)->Et() && distance(input[0]->begin(), tob1) == p_NumberLeading - 1) {
219  for(unsigned int i=0; i<numberOutputBits(); ++i) {
220  output[i]->setAmbiguityFlag(true);
221  }
222  }
223  }
224  for( TCS::TOBArray::const_iterator tob2 = input[0]->begin();
225  tob2 != input[0]->end() && distance(input[0]->begin(), tob2) < p_NumberLeading;
226  ++tob2) {
227  j++; if (j==k) continue; //Avoid diagonal cases. Both above and below diagonal cases are calculated due to asymmetric ET and eta cuts
228  // Inv Mass calculation
229  unsigned int invmass2 = calcInvMass( *tob1, *tob2 );
230  // test DeltaPhiMin, DeltaPhiMax
231  unsigned int deltaPhi = calcDeltaPhi( *tob1, *tob2 );
232  const int eta1 = (*tob1)->eta();
233  const int eta2 = (*tob2)->eta();
234  const unsigned int aeta1 = std::abs(eta1);
235  const unsigned int aeta2 = std::abs(eta2);
236  for(unsigned int i=0; i<numberOutputBits(); ++i) {
237  if( parType_t((*tob1)->Et()) <= p_MinET1[i]) continue; // ET cut
238  if( parType_t((*tob2)->Et()) <= p_MinET2[i]) continue; // ET cut
239  if(p_ApplyEtaCut &&
240  ((aeta1 < p_MinEta1 || aeta1 > p_MaxEta1 ) ||
241  (aeta2 < p_MinEta2 || aeta2 > p_MaxEta2 ) )) continue;
242  bool accept = invmass2 >= p_InvMassMin[i] && invmass2 <= p_InvMassMax[i] && deltaPhi >= p_DeltaPhiMin[i] && deltaPhi <= p_DeltaPhiMax[i];
243  const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
244  const bool fillReject = fillHistos() and not fillAccept;
245  const bool alreadyFilled = decision.bit(i);
246  if( accept ) {
247  decision.setBit(i, true);
248  output[i]->push_back( TCS::CompositeTOB(*tob1, *tob2) );
249  }
250  if(fillAccept and not alreadyFilled) {
251  fillHist2D(m_histAcceptM[i],sqrt((float)invmass2),(float)deltaPhi);
252  fillHist2D(m_histAcceptEta1Eta2[i],eta1, eta2);
253  } else if(fillReject) {
254  fillHist2D(m_histRejectM[i],sqrt((float)invmass2),(float)deltaPhi);
255  fillHist2D(m_histRejectEta1Eta2[i],eta1, eta2);
256  }
257  TRG_MSG_DEBUG("Decision " << i << ": " << (accept ?"pass":"fail") << " invmass2 = " << invmass2);
258  }
259  }
260  }
261  } else {
262  TCS_EXCEPTION("InvariantMassDeltaPhiInclusive1 alg must have 1 inputs, but got " << input.size());
263  }
265 }
TCS::StatusCode::SUCCESS
@ SUCCESS
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/L1TopoCommon/StatusCode.h:17
TCS::parType_t
uint32_t parType_t
Definition: Parameter.h:22
ParticleGun_SamplingFraction.eta2
eta2
Definition: ParticleGun_SamplingFraction.py:96
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:161
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
xAOD::eta1
setEt setPhi setE277 setWeta2 eta1
Definition: TrigEMCluster_v1.cxx:41
TCS::InvariantMassDeltaPhiInclusive1::initialize
virtual StatusCode initialize() override final
Definition: InvariantMassDeltaPhiInclusive1.cxx:78
Decision.h
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:560
TCS::DecisionAlg
Definition: Trigger/TrigT1/L1Topo/L1TopoInterfaces/L1TopoInterfaces/DecisionAlg.h:22
TCS::InvariantMassDeltaPhiInclusive1
Definition: InvariantMassDeltaPhiInclusive1.h:17
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
TCS::InvariantMassDeltaPhiInclusive1::process
virtual StatusCode process(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison) override final
Definition: InvariantMassDeltaPhiInclusive1.cxx:203
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_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
InvariantMassDeltaPhiInclusive1.h
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
TCS::InvariantMassDeltaPhiInclusive1::processBitCorrect
virtual StatusCode processBitCorrect(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison) override final
Definition: InvariantMassDeltaPhiInclusive1.cxx:131
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
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
TRG_MSG_DEBUG
#define TRG_MSG_DEBUG(x)
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStreamMacros.h:25
fitman.k
k
Definition: fitman.py:528
TCS::InvariantMassDeltaPhiInclusive1::~InvariantMassDeltaPhiInclusive1
virtual ~InvariantMassDeltaPhiInclusive1()
Definition: InvariantMassDeltaPhiInclusive1.cxx:74
TCS::StatusCode
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/L1TopoCommon/StatusCode.h:15