ATLAS Offline Software
InvariantMassDeltaPhiInclusive2Charge.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  * InvariantMassDeltaPhiInclusive2Charge.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  * Events containing a pair of TGC muons with same charge are rejected
11  *
12 **********************************/
13 // TO DO size of the input list to be possbly refined
14 
16 #include "L1TopoCommon/Exception.h"
18 
19 #include <cmath>
20 
21 REGISTER_ALG_TCS(InvariantMassDeltaPhiInclusive2Charge)
22 
23 
25 {
26  defineParameter("InputWidth1", 9);
27  defineParameter("InputWidth2", 9);
28  defineParameter("MaxTob1", 0);
29  defineParameter("MaxTob2", 0);
30  defineParameter("NumResultBits", 6);
31  defineParameter("MinMSqr", 0, 0);
32  defineParameter("MaxMSqr", 999, 0);
33  defineParameter("MinMSqr", 0, 1);
34  defineParameter("MaxMSqr", 999, 1);
35  defineParameter("MinMSqr", 0, 2);
36  defineParameter("MaxMSqr", 999, 2);
37  defineParameter("MinMSqr", 0, 3);
38  defineParameter("MaxMSqr", 999, 3);
39  defineParameter("MinMSqr", 0, 4);
40  defineParameter("MaxMSqr", 999, 4);
41  defineParameter("MinMSqr", 0, 5);
42  defineParameter("MaxMSqr", 999, 5);
43  defineParameter("MinET1",0,0);
44  defineParameter("MinET2",0,0);
45  defineParameter("MinET1",0,1);
46  defineParameter("MinET2",0,1);
47  defineParameter("MinET1",0,2);
48  defineParameter("MinET2",0,2);
49  defineParameter("MinET1",0,3);
50  defineParameter("MinET2",0,3);
51  defineParameter("MinET1",0,4);
52  defineParameter("MinET2",0,4);
53  defineParameter("MinET1",0,5);
54  defineParameter("MinET2",0,5);
55  defineParameter("ApplyEtaCut", 0);
56  defineParameter("MinEta1", 0);
57  defineParameter("MaxEta1", 31);
58  defineParameter("MinEta2", 0);
59  defineParameter("MaxEta2", 31);
60  defineParameter("MinDeltaPhi", 0, 0);
61  defineParameter("MaxDeltaPhi", 31, 0);
62  defineParameter("MinDeltaPhi", 0, 1);
63  defineParameter("MaxDeltaPhi", 31, 1);
64  defineParameter("MinDeltaPhi", 0, 2);
65  defineParameter("MaxDeltaPhi", 31, 2);
66  defineParameter("MinDeltaPhi", 0, 3);
67  defineParameter("MaxDeltaPhi", 31, 3);
68  defineParameter("MinDeltaPhi", 0, 4);
69  defineParameter("MaxDeltaPhi", 31, 4);
70  defineParameter("MinDeltaPhi", 0, 5);
71  defineParameter("MaxDeltaPhi", 31, 5);
72  //does this need to change?
73  setNumberOutputBits(6);
74 }
75 
77 
78 
81  p_NumberLeading1 = parameter("InputWidth1").value();
82  p_NumberLeading2 = parameter("InputWidth2").value();
83  if(parameter("MaxTob1").value() > 0) p_NumberLeading1 = parameter("MaxTob1").value();
84  if(parameter("MaxTob2").value() > 0) p_NumberLeading2 = parameter("MaxTob2").value();
85 
86  for(unsigned int i=0; i<numberOutputBits(); ++i) {
87  p_InvMassMin[i] = parameter("MinMSqr", i).value();
88  p_InvMassMax[i] = parameter("MaxMSqr", i).value();
89  p_DeltaPhiMin[i] = parameter("MinDeltaPhi", i).value();
90  p_DeltaPhiMax[i] = parameter("MaxDeltaPhi", i).value();
91  p_MinET1[i] = parameter("MinET1",i).value();
92  p_MinET2[i] = parameter("MinET2",i).value();
93  }
94 
95  TRG_MSG_INFO("NumberLeading1 : " << p_NumberLeading1);
96  TRG_MSG_INFO("NumberLeading2 : " << p_NumberLeading2);
97  for(unsigned int i=0; i<numberOutputBits(); ++i) {
98  TRG_MSG_INFO("InvMassMin : " << p_InvMassMin[i]);
99  TRG_MSG_INFO("InvMassMax : " << p_InvMassMax[i]);
100  TRG_MSG_INFO("DeltaPhiMin : " << p_DeltaPhiMin[i]);
101  TRG_MSG_INFO("DeltaPhiMax : " << p_DeltaPhiMax[i]);
102  TRG_MSG_INFO("MinET1 : " << p_MinET1[i]);
103  TRG_MSG_INFO("MinET2 : " << p_MinET2[i]);
104  }
105 
106  p_ApplyEtaCut = parameter("ApplyEtaCut").value();
107  p_MinEta1 = parameter("MinEta1" ).value();
108  p_MaxEta1 = parameter("MaxEta1" ).value();
109  p_MinEta2 = parameter("MinEta2" ).value();
110  p_MaxEta2 = parameter("MaxEta2" ).value();
111  TRG_MSG_INFO("ApplyEtaCut : "<<p_ApplyEtaCut );
112  TRG_MSG_INFO("MinEta1 : "<<p_MinEta1 );
113  TRG_MSG_INFO("MaxEta1 : "<<p_MaxEta1 );
114  TRG_MSG_INFO("MinEta2 : "<<p_MinEta2 );
115  TRG_MSG_INFO("MaxEta2 : "<<p_MaxEta2 );
116 
117  TRG_MSG_INFO("number output : " << numberOutputBits());
118 
119  // book histograms
120  for(unsigned int i=0; i<numberOutputBits(); ++i) {
121  std::string hname_accept = "hInvariantMassDeltaPhiInclusive2Charge_accept_bit"+std::to_string(static_cast<int>(i));
122  std::string hname_reject = "hInvariantMassDeltaPhiInclusive2Charge_reject_bit"+std::to_string(static_cast<int>(i));
123  // mass
124  bookHist(m_histAcceptM, hname_accept, "INVM vs DPHI", 100, std::sqrt(p_InvMassMin[i]), std::sqrt(p_InvMassMax[i]), 100, p_DeltaPhiMin[i], p_DeltaPhiMax[i]);
125  bookHist(m_histRejectM, hname_reject, "INVM vs DPHI", 100, std::sqrt(p_InvMassMin[i]), std::sqrt(p_InvMassMax[i]), 100, p_DeltaPhiMin[i], p_DeltaPhiMax[i]);
126  // eta2 vs. eta1
127  bookHist(m_histAcceptEta1Eta2, hname_accept, "ETA vs ETA", 100, p_MinEta1, p_MaxEta1, 100, p_MinEta2, p_MaxEta2);
128  bookHist(m_histRejectEta1Eta2, hname_reject, "ETA vs ETA", 100, p_MinEta1, p_MaxEta1, 100, p_MinEta2, p_MaxEta2);
129  }
130  return StatusCode::SUCCESS;
131 }
132 
133 
134 
136 TCS::InvariantMassDeltaPhiInclusive2Charge::processBitCorrect( const std::vector<TCS::TOBArray const *> & input,
137  const std::vector<TCS::TOBArray *> & output,
138  Decision & decision )
139 {
140 
141  if( input.size() == 2) {
142  for( TOBArray::const_iterator tob1 = input[0]->begin();
143  tob1 != input[0]->end() && distance(input[0]->begin(), tob1) < p_NumberLeading1;
144  ++tob1)
145  {
146 
147 
148  for( TCS::TOBArray::const_iterator tob2 = input[1]->begin();
149  tob2 != input[1]->end() && distance(input[1]->begin(), tob2) < p_NumberLeading2;
150  ++tob2) {
151  // Inv Mass calculation
152  unsigned int invmass2 = calcInvMassBW( *tob1, *tob2 );
153  // test DeltaPhiMin, DeltaPhiMax
154  unsigned int deltaPhi = calcDeltaPhiBW( *tob1, *tob2 );
155  const int eta1 = (*tob1)->eta();
156  const int eta2 = (*tob2)->eta();
157  const unsigned int aeta1 = std::abs(eta1);
158  const unsigned int aeta2 = std::abs(eta2);
159  // Charge cut ( 1 = positive, -1 = negative, 0 = undefined (RPC) )
160  int charge1 = (*tob1)->charge();
161  int charge2 = (*tob2)->charge();
162  int totalCharge = charge1 + charge2;
163  bool acceptCharge = true;
164  if ( std::abs(totalCharge) == 2 ) { acceptCharge = false; }
165  for(unsigned int i=0; i<numberOutputBits(); ++i) {
166  bool accept = false;
167  if( static_cast<parType_t>((*tob1)->Et()) <= p_MinET1[i]) continue; // ET cut
168  if( static_cast<parType_t>((*tob2)->Et()) <= p_MinET2[i]) continue; // ET cut
169  if(p_ApplyEtaCut &&
170  ((aeta1 < p_MinEta1 || aeta1 > p_MaxEta1 ) ||
171  (aeta2 < p_MinEta2 || aeta2 > p_MaxEta2 ) )) continue;
172  accept = invmass2 >= p_InvMassMin[i] && invmass2 <= p_InvMassMax[i] && deltaPhi >= p_DeltaPhiMin[i] && deltaPhi <= p_DeltaPhiMax[i] && acceptCharge;
173  const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
174  const bool fillReject = fillHistos() and not fillAccept;
175  const bool alreadyFilled = decision.bit(i);
176  if( accept ) {
177  decision.setBit(i, true);
178  output[i]->push_back( TCS::CompositeTOB(*tob1, *tob2) );
179  }
180  if(fillAccept and not alreadyFilled) {
181  fillHist2D(m_histAcceptM[i],std::sqrt(static_cast<float>(invmass2)),static_cast<float>(deltaPhi));
182  fillHist2D(m_histAcceptEta1Eta2[i],eta1, eta2);
183  } else if(fillReject) {
184  fillHist2D(m_histRejectM[i],std::sqrt(static_cast<float>(invmass2)),static_cast<float>(deltaPhi));
185  fillHist2D(m_histRejectEta1Eta2[i],eta1, eta2);
186  }
187  TRG_MSG_DEBUG("Decision " << i << ": " << (accept?"pass":"fail") << " invmass2 = " << invmass2);
188  }
189  }
190  }
191  } else {
192 
193  TCS_EXCEPTION("InvariantMassDeltaPhiInclusive2Charge alg must have 2 inputs, but got " << input.size());
194 
195  }
197 
198 }
199 
201 TCS::InvariantMassDeltaPhiInclusive2Charge::process( const std::vector<TCS::TOBArray const *> & input,
202  const std::vector<TCS::TOBArray *> & output,
203  Decision & decision )
204 {
205 
206 
207  if( input.size() == 2) {
208  for( TOBArray::const_iterator tob1 = input[0]->begin();
209  tob1 != input[0]->end() && distance(input[0]->begin(), tob1) < p_NumberLeading1;
210  ++tob1)
211  {
212  for( TCS::TOBArray::const_iterator tob2 = input[1]->begin();
213  tob2 != input[1]->end() && distance(input[1]->begin(), tob2) < p_NumberLeading2;
214  ++tob2) {
215  // Inv Mass calculation
216  unsigned int invmass2 = calcInvMass( *tob1, *tob2 );
217  // test DeltaPhiMin, DeltaPhiMax
218  unsigned int deltaPhi = calcDeltaPhi( *tob1, *tob2 );
219  const int eta1 = (*tob1)->eta();
220  const int eta2 = (*tob2)->eta();
221  const unsigned int aeta1 = std::abs(eta1);
222  const unsigned int aeta2 = std::abs(eta2);
223  // Charge cut ( 1 = positive, -1 = negative, 0 = undefined (RPC) )
224  int charge1 = (*tob1)->charge();
225  int charge2 = (*tob2)->charge();
226  int totalCharge = charge1 + charge2;
227  bool acceptCharge = true;
228  if ( std::abs(totalCharge) == 2 ) { acceptCharge = true; }
229  for(unsigned int i=0; i<numberOutputBits(); ++i) {
230  if( static_cast<parType_t>((*tob1)->Et()) <= p_MinET1[i]) continue; // ET cut
231  if( static_cast<parType_t>((*tob2)->Et()) <= p_MinET2[i]) continue; // ET cut
232  if(p_ApplyEtaCut &&
233  ((aeta1 < p_MinEta1 || aeta1 > p_MaxEta1 ) ||
234  (aeta2 < p_MinEta2 || aeta2 > p_MaxEta2 ) )) continue;
235  bool accept = invmass2 >= p_InvMassMin[i] && invmass2 <= p_InvMassMax[i] && deltaPhi >= p_DeltaPhiMin[i] && deltaPhi <= p_DeltaPhiMax[i] && acceptCharge;
236  const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
237  const bool fillReject = fillHistos() and not fillAccept;
238  const bool alreadyFilled = decision.bit(i);
239  if( accept ) {
240  decision.setBit(i, true);
241  output[i]->push_back( TCS::CompositeTOB(*tob1, *tob2) );
242  }
243  if(fillAccept and not alreadyFilled) {
244  fillHist2D(m_histAcceptM[i],std::sqrt(static_cast<float>(invmass2)),static_cast<float>(deltaPhi));
245  fillHist2D(m_histAcceptEta1Eta2[i],eta1, eta2);
246  } else if(fillReject) {
247  fillHist2D(m_histRejectM[i],std::sqrt(static_cast<float>(invmass2)),static_cast<float>(deltaPhi));
248  fillHist2D(m_histRejectEta1Eta2[i],eta1, eta2);
249  }
250  TRG_MSG_DEBUG("Decision " << i << ": " << (accept ?"pass":"fail") << " invmass2 = " << invmass2);
251  }
252  }
253  }
254  } else {
255  TCS_EXCEPTION("InvariantMassDeltaPhiInclusive2Charge alg must have 2 inputs, but got " << input.size());
256  }
258 }
TCS::InvariantMassDeltaPhiInclusive2Charge::~InvariantMassDeltaPhiInclusive2Charge
virtual ~InvariantMassDeltaPhiInclusive2Charge()
Definition: InvariantMassDeltaPhiInclusive2Charge.cxx:76
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: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: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::InvariantMassDeltaPhiInclusive2Charge::initialize
virtual StatusCode initialize() override final
Definition: InvariantMassDeltaPhiInclusive2Charge.cxx:80
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
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
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:221
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
InvariantMassDeltaPhiInclusive2Charge.h
TCS::InvariantMassDeltaPhiInclusive2Charge::process
virtual StatusCode process(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison) override final
Definition: InvariantMassDeltaPhiInclusive2Charge.cxx:201
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
TCS::InvariantMassDeltaPhiInclusive2Charge
Definition: InvariantMassDeltaPhiInclusive2Charge.h:18
TCS::InvariantMassDeltaPhiInclusive2Charge::processBitCorrect
virtual StatusCode processBitCorrect(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison) override final
Definition: InvariantMassDeltaPhiInclusive2Charge.cxx:136
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