ATLAS Offline Software
InvariantMassInclusiveDeltaRSqrIncl1Charge.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  * Created by Paula Martinez based on V Sorin and Joerg Stelzer.
6  *
7  * @brief algorithm calculates the sqr of the INVMASS and DeltaR between one list and applies invmass and deltaR criteria
8  * Events containing a pair of TGC muons with same charge are rejected
9  *
10  * @param NumberLeading
11  *
12  * For questions contact atlas-trig-l1topo-algcom@cern.ch.
13 **********************************/
14 
15 #include <cmath>
16 #include <string>
17 #include <sstream>
18 #include <vector>
19 #include "TH1F.h"
20 #include "TH2F.h"
21 
23 #include "L1TopoCommon/Exception.h"
25 // Bitwise implementation utils
30 
31 //
32 
33 REGISTER_ALG_TCS(InvariantMassInclusiveDeltaRSqrIncl1Charge)
34 
35 
37 {
38  defineParameter("InputWidth", 3);
39  defineParameter("MaxTob", 0);
40  defineParameter("NumResultBits", 6);
41  defineParameter("RequireOneBarrel", 0);
42  defineParameter("MinMSqr", 0, 0);
43  defineParameter("MaxMSqr", 999, 0);
44  defineParameter("MinMSqr", 0, 1);
45  defineParameter("MaxMSqr", 999, 1);
46  defineParameter("MinMSqr", 0, 2);
47  defineParameter("MaxMSqr", 999, 2);
48  defineParameter("MinMSqr", 0, 3);
49  defineParameter("MaxMSqr", 999, 3);
50  defineParameter("MinMSqr", 0, 4);
51  defineParameter("MaxMSqr", 999, 4);
52  defineParameter("MinMSqr", 0, 5);
53  defineParameter("MaxMSqr", 999, 5);
54  defineParameter("MinET1",0,0);
55  defineParameter("MinET2",0,0);
56  defineParameter("MinET1",0,1);
57  defineParameter("MinET2",0,1);
58  defineParameter("MinET1",0,2);
59  defineParameter("MinET2",0,2);
60  defineParameter("MinET1",0,3);
61  defineParameter("MinET2",0,3);
62  defineParameter("MinET1",0,4);
63  defineParameter("MinET2",0,4);
64  defineParameter("MinET1",0,5);
65  defineParameter("MinET2",0,5);
66  defineParameter("DeltaRMin", 0, 0);
67  defineParameter("DeltaRMax", 0, 0);
68  defineParameter("DeltaRMin", 0, 1);
69  defineParameter("DeltaRMax", 0, 1);
70  defineParameter("DeltaRMin", 0, 2);
71  defineParameter("DeltaRMax", 0, 2);
72  defineParameter("DeltaRMin", 0, 3);
73  defineParameter("DeltaRMax", 0, 3);
74  defineParameter("DeltaRMin", 0, 4);
75  defineParameter("DeltaRMax", 0, 4);
76  defineParameter("DeltaRMin", 0, 5);
77  defineParameter("DeltaRMax", 0, 5);
78 
79 
80  setNumberOutputBits(6);
81 }
82 
84 
85 
88  if(parameter("MaxTob").value() > 0) {
89  p_NumberLeading1 = parameter("MaxTob").value();
90  p_NumberLeading2 = parameter("MaxTob").value();
91  } else {
92  p_NumberLeading1 = parameter("InputWidth").value();
93  p_NumberLeading2 = parameter("InputWidth").value();
94  }
95 
96  p_OneBarrel = parameter("RequireOneBarrel").value();
97 
98  TRG_MSG_INFO("NumberLeading1 : " << p_NumberLeading1);
99  TRG_MSG_INFO("NumberLeading2 : " << p_NumberLeading2);
100  TRG_MSG_INFO("RequireOneBarrel : " << p_OneBarrel);
101 
102  for(unsigned int i=0; i<numberOutputBits(); ++i) {
103  p_InvMassMin[i] = parameter("MinMSqr", i).value();
104  p_InvMassMax[i] = parameter("MaxMSqr", i).value();
105  p_DeltaRMin[i] = parameter("DeltaRMin", i).value();
106  p_DeltaRMax[i] = parameter("DeltaRMax", i).value();
107  p_MinET1[i] = parameter("MinET1",i).value();
108  p_MinET2[i] = parameter("MinET2",i).value();
109 
110  TRG_MSG_INFO("InvMassMin "<< i << " : " << p_InvMassMin[i]);
111  TRG_MSG_INFO("InvMassMax "<< i << " : " << p_InvMassMax[i]);
112  TRG_MSG_INFO("MinET1 "<< i << " : " << p_MinET1[i]);
113  TRG_MSG_INFO("MinET2 "<< i << " : " << p_MinET2[i]);
114  TRG_MSG_INFO("DeltaRMin "<< i << " : " << p_DeltaRMin[i]);
115  TRG_MSG_INFO("DeltaRMax "<< i << " : " << p_DeltaRMax[i]);
116  }
117 
118  TRG_MSG_INFO("number output : " << numberOutputBits());
119 
120  // book histograms
121  for(unsigned int i=0; i<numberOutputBits(); ++i) {
122  std::string hname_accept = "hInvariantMassInclusiveDeltaRSqrIncl1Charge_accept_bit"+std::to_string(static_cast<int>(i));
123  std::string hname_reject = "hInvariantMassInclusiveDeltaRSqrIncl1Charge_reject_bit"+std::to_string(static_cast<int>(i));
124  // mass
125  bookHist(m_histAcceptM, hname_accept, "INVM vs DR", 100, std::sqrt(p_InvMassMin[i]), std::sqrt(p_InvMassMax[i]), 100, std::sqrt(p_DeltaRMin[i]), std::sqrt(p_DeltaRMax[i]));
126  bookHist(m_histRejectM, hname_reject, "INVM vs DR", 100, std::sqrt(p_InvMassMin[i]), std::sqrt(p_InvMassMax[i]), 100, std::sqrt(p_DeltaRMin[i]), std::sqrt(p_DeltaRMax[i]));
127  // eta2 vs. eta1
128  bookHist(m_histAcceptEta1Eta2, hname_accept, "ETA vs ETA", 100, -70, 70, 100, -70, 70);
129  bookHist(m_histRejectEta1Eta2, hname_reject, "ETA vs ETA", 100, -70, 70, 100, -70, 70);
130 
131  }
132 
133  return StatusCode::SUCCESS;
134 }
135 
136 
137 
140  const std::vector<TCS::TOBArray *> & output,
141  Decision & decision )
142 {
143 
144  if(input.size() == 1) {
145 
146  for( TOBArray::const_iterator tob1 = input[0]->begin();
147  tob1 != input[0]->end() && distance( input[0]->begin(), tob1) < p_NumberLeading1;
148  ++tob1)
149  {
150 
151 
152  TCS::TOBArray::const_iterator tob2 = tob1; ++tob2;
153  for( ;
154  tob2 != input[0]->end() && distance( input[0]->begin(), tob2) < p_NumberLeading2;
155  ++tob2) {
156 
157 
158  // OneBarrel
159  if (p_OneBarrel && parType_t(std::abs((*tob1)->eta())) > 10 && parType_t(std::abs((*tob2)->eta())) > 10 ) continue;
160 
161  // Inv Mass calculation
162  unsigned int invmass2 = calcInvMassBW( *tob1, *tob2 );
163  // test DeltaR2Min, DeltaR2Max
164  unsigned int deltaR2 = calcDeltaR2BW( *tob1, *tob2 );
165  TRG_MSG_DEBUG("Jet1 = " << **tob1 << ", Jet2 = " << **tob2 << ", invmass2 = " << invmass2 << ", deltaR2 = " << deltaR2);
166  // Charge cut ( 1 = positive, -1 = negative, 0 = undefined (RPC) )
167  int charge1 = (*tob1)->charge();
168  int charge2 = (*tob2)->charge();
169  int totalCharge = charge1 + charge2;
170  bool acceptCharge = true;
171  if ( std::abs(totalCharge) == 2 ) { acceptCharge = false; }
172  for(unsigned int i=0; i<numberOutputBits(); ++i) {
173  bool accept = false;
174  if( parType_t((*tob1)->Et()) <= std::min(p_MinET1[i],p_MinET2[i])) continue; // ET cut
175  if( parType_t((*tob2)->Et()) <= std::min(p_MinET1[i],p_MinET2[i])) continue; // ET cut
176  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;
177  accept = invmass2 >= p_InvMassMin[i] && invmass2 <= p_InvMassMax[i] && deltaR2 >= p_DeltaRMin[i] && deltaR2 <= p_DeltaRMax[i] && acceptCharge;
178  const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
179  const bool fillReject = fillHistos() and not fillAccept;
180  const bool alreadyFilled = decision.bit(i);
181  if( accept ) {
182  decision.setBit(i, true);
183  output[i]->push_back( TCS::CompositeTOB(*tob1, *tob2) );
184  }
185  if(fillAccept and not alreadyFilled) {
186  fillHist2D(m_histAcceptM[i],std::sqrt(static_cast<float>(invmass2)),std::sqrt(static_cast<float>(deltaR2)));
187  fillHist2D(m_histAcceptEta1Eta2[i],(*tob1)->eta(),(*tob2)->eta());
188  } else if(fillReject) {
189  fillHist2D(m_histRejectM[i],std::sqrt(static_cast<float>(invmass2)),std::sqrt(static_cast<float>(deltaR2)));
190  fillHist2D(m_histRejectEta1Eta2[i],(*tob1)->eta(),(*tob2)->eta());
191  }
192  TRG_MSG_DEBUG("Decision " << i << ": " << (accept?"pass":"fail") << " invmass2 = " << invmass2 << " deltaR2 = " << deltaR2 );
193  }
194  }
195  }
196  } else {
197 
198  TCS_EXCEPTION("InvariantMassInclusiveDeltaRSqrIncl1Charge alg must have either 1 inputs, but got " << input.size());
199 
200  }
201 
203 
204 }
205 
207 TCS::InvariantMassInclusiveDeltaRSqrIncl1Charge::process( const std::vector<TCS::TOBArray const *> & input,
208  const std::vector<TCS::TOBArray *> & output,
209  Decision & decision )
210 {
211 
212  if(input.size() == 1) {
213  for( TOBArray::const_iterator tob1 = input[0]->begin();
214  tob1 != input[0]->end() && distance( input[0]->begin(), tob1) < p_NumberLeading1;
215  ++tob1)
216  {
217 
218 
219  TCS::TOBArray::const_iterator tob2 = tob1; ++tob2;
220  for( ;
221  tob2 != input[0]->end() && distance( input[0]->begin(), tob2) < p_NumberLeading2;
222  ++tob2) {
223 
224 
225  // OneBarrel
226  if (p_OneBarrel && parType_t(std::abs((*tob1)->eta())) > 10 && parType_t(std::abs((*tob2)->eta())) > 10 ) continue;
227 
228  // Inv Mass calculation
229  unsigned int invmass2 = calcInvMass( *tob1, *tob2 );
230  // test DeltaR2Min, DeltaR2Max
231  unsigned int deltaR2 = calcDeltaR2( *tob1, *tob2 );
232  TRG_MSG_DEBUG("Jet1 = " << **tob1 << ", Jet2 = " << **tob2 << ", invmass2 = " << invmass2 << ", deltaR2 = " << deltaR2);
233  // Charge cut ( 1 = positive, -1 = negative, 0 = undefined (RPC) )
234  int charge1 = (*tob1)->charge();
235  int charge2 = (*tob2)->charge();
236  int totalCharge = charge1 + charge2;
237  bool acceptCharge = true;
238  if ( std::abs(totalCharge) == 2 ) { acceptCharge = false; }
239  for(unsigned int i=0; i<numberOutputBits(); ++i) {
240  bool accept = false;
241  if( parType_t((*tob1)->Et()) <= std::min(p_MinET1[i],p_MinET2[i])) continue; // ET cut
242  if( parType_t((*tob2)->Et()) <= std::min(p_MinET1[i],p_MinET2[i])) continue; // ET cut
243  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;
244  accept = invmass2 >= p_InvMassMin[i] && invmass2 <= p_InvMassMax[i] && deltaR2 >= p_DeltaRMin[i] && deltaR2 <= p_DeltaRMax[i] && acceptCharge;
245  const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
246  const bool fillReject = fillHistos() and not fillAccept;
247  const bool alreadyFilled = decision.bit(i);
248  if( accept ) {
249  decision.setBit(i, true);
250  output[i]->push_back( TCS::CompositeTOB(*tob1, *tob2) );
251  }
252  if(fillAccept and not alreadyFilled) {
253  fillHist2D(m_histAcceptM[i],std::sqrt(static_cast<float>(invmass2)),std::sqrt(static_cast<float>(deltaR2)));
254  fillHist2D(m_histAcceptEta1Eta2[i],(*tob1)->eta(),(*tob2)->eta());
255  } else if(fillReject) {
256  fillHist2D(m_histRejectM[i],std::sqrt(static_cast<float>(invmass2)),std::sqrt(static_cast<float>(deltaR2)));
257  fillHist2D(m_histRejectEta1Eta2[i],(*tob1)->eta(),(*tob2)->eta());
258  }
259  TRG_MSG_DEBUG("Decision " << i << ": " << (accept?"pass":"fail") << " invmass2 = " << invmass2 << " deltaR2 = " << deltaR2 );
260  }
261  }
262  }
263  } else {
264 
265  TCS_EXCEPTION("InvariantMassInclusiveDeltaRSqrIncl1Charge alg must have either 1 inputs, but got " << input.size());
266 
267  }
268 
270 }
Kinematics.h
TCS::InvariantMassInclusiveDeltaRSqrIncl1Charge::processBitCorrect
virtual StatusCode processBitCorrect(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison) override final
Definition: InvariantMassInclusiveDeltaRSqrIncl1Charge.cxx:139
TCS::StatusCode::SUCCESS
@ SUCCESS
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/L1TopoCommon/StatusCode.h:17
TCS::InvariantMassInclusiveDeltaRSqrIncl1Charge::initialize
virtual StatusCode initialize() override final
Definition: InvariantMassInclusiveDeltaRSqrIncl1Charge.cxx:87
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:124
Decision.h
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:560
xAOD::P4Helpers::deltaR2
double deltaR2(double rapidity1, double phi1, double rapidity2, double phi2)
from bare rapidity,phi
Definition: xAODP4Helpers.h:111
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::InvariantMassInclusiveDeltaRSqrIncl1Charge::~InvariantMassInclusiveDeltaRSqrIncl1Charge
virtual ~InvariantMassInclusiveDeltaRSqrIncl1Charge()
Definition: InvariantMassInclusiveDeltaRSqrIncl1Charge.cxx:83
TCS::InvariantMassInclusiveDeltaRSqrIncl1Charge
Definition: InvariantMassInclusiveDeltaRSqrIncl1Charge.h:18
InvariantMassInclusiveDeltaRSqrIncl1Charge.h
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
min
#define min(a, b)
Definition: cfImp.cxx:40
Trigo.h
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
Hyperbolic.h
TCS::InvariantMassInclusiveDeltaRSqrIncl1Charge::process
virtual StatusCode process(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison) override final
Definition: InvariantMassInclusiveDeltaRSqrIncl1Charge.cxx:207
L1TopoDataTypes.h
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