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