ATLAS Offline Software
Loading...
Searching...
No Matches
DeltaRSqrIncl1Charge.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 * DeltaRSqrIncl1Charge.cxx
6 * Created by Paula Martinez based on Joerg Stelzer / V Sorin.
7 *
8 * @brief algorithm calculates the R2-distance between objects in one list and applies dR criteria
9 * Events containing a pair of TGC muons with same charge are rejected
10 *
11 * @param NumberLeading
12**********************************/
13
14#include <cmath>
15#include "TH1F.h"
16#include "TH2F.h"
17
23
24REGISTER_ALG_TCS(DeltaRSqrIncl1Charge)
25
26
27// not the best solution but we will move to athena where this comes for free
28#define LOG std::cout << "TCS::DeltaRSqrIncl1Charge: "
29
31{
32 defineParameter("InputWidth", 9);
33 defineParameter("MaxTob", 0);
34 defineParameter("NumResultBits", 3);
35 defineParameter("RequireOneBarrel", 0);
36 defineParameter("MinET1",1);
37 defineParameter("MinET2",1);
38 defineParameter("DeltaRMin", 0, 0);
39 defineParameter("DeltaRMax", 0, 0);
40 defineParameter("DeltaRMin", 0, 1);
41 defineParameter("DeltaRMax", 0, 1);
42 defineParameter("DeltaRMin", 0, 2);
43 defineParameter("DeltaRMax", 0, 2);
45}
46
48
49
52 if(parameter("MaxTob").value() > 0) {
53 p_NumberLeading1 = parameter("MaxTob").value();
54 p_NumberLeading2 = parameter("MaxTob").value();
55 } else {
56 p_NumberLeading1 = parameter("InputWidth").value();
57 p_NumberLeading2 = parameter("InputWidth").value();
58 }
59 p_OneBarrel = parameter("RequireOneBarrel").value();
60
61 for(unsigned int i=0; i<numberOutputBits(); ++i) {
62 p_DeltaRMin[i] = parameter("DeltaRMin", i).value();
63 p_DeltaRMax[i] = parameter("DeltaRMax", i).value();
64 }
65 p_MinET1 = parameter("MinET1").value();
66 p_MinET2 = parameter("MinET2").value();
67
68 TRG_MSG_INFO("NumberLeading1 : " << p_NumberLeading1);
69 TRG_MSG_INFO("NumberLeading2 : " << p_NumberLeading2);
70 TRG_MSG_INFO("RequireOneBarrel : " << p_OneBarrel);
71
72 for(unsigned int i=0; i<numberOutputBits(); ++i) {
73 TRG_MSG_INFO("DeltaRMin : " << p_DeltaRMin[i]);
74 TRG_MSG_INFO("DeltaRMax : " << p_DeltaRMax[i]);
75 }
76 TRG_MSG_INFO("MinET1 : " << p_MinET1);
77 TRG_MSG_INFO("MinET2 : " << p_MinET2);
78
79 TRG_MSG_INFO("number output : " << numberOutputBits());
80
81 // book histograms
82 for(unsigned int i=0; i<numberOutputBits(); ++i) {
83 std::string hname_accept = "hDeltaRSqrIncl1Charge_accept_bit"+std::to_string(static_cast<int>(i));
84 std::string hname_reject = "hDeltaRSqrIncl1Charge_reject_bit"+std::to_string(static_cast<int>(i));
85 // dR
86 bookHist(m_histAccept, hname_accept, "DR", 100, std::sqrt(p_DeltaRMin[i]), std::sqrt(p_DeltaRMax[i]));
87 bookHist(m_histReject, hname_reject, "DR", 100, std::sqrt(p_DeltaRMin[i]), std::sqrt(p_DeltaRMax[i]));
88 // eta2 vs. eta1
89 bookHist(m_histAcceptEta1Eta2, hname_accept, "ETA vs ETA", 100, -70, 70, 100, -70, 70);
90 bookHist(m_histRejectEta1Eta2, hname_reject, "ETA vs ETA", 100, -70, 70, 100, -70, 70);
91 }
92
94}
95
96
97
99TCS::DeltaRSqrIncl1Charge::processBitCorrect( const std::vector<TCS::TOBArray const *> & input,
100 const std::vector<TCS::TOBArray *> & output,
101 Decision & decision )
102{
103
104 if(input.size() == 1) {
105 for( TOBArray::const_iterator tob1 = input[0]->begin();
106 tob1 != input[0]->end() && distance( input[0]->begin(), tob1) < p_NumberLeading1;
107 ++tob1)
108 {
109 if( parType_t((*tob1)->Et()) <= std::min(p_MinET1,p_MinET2)) continue; // ET cut
110 TCS::TOBArray::const_iterator tob2 = tob1; ++tob2;
111 for( ;
112 tob2 != input[0]->end() && distance( input[0]->begin(), tob2) < p_NumberLeading2;
113 ++tob2) {
114 if( parType_t((*tob2)->Et()) <= std::min(p_MinET1,p_MinET2)) continue; // ET cut
115 if( (parType_t((*tob1)->Et()) <= std::max(p_MinET1,p_MinET2)) && (parType_t((*tob2)->Et()) <= std::max(p_MinET1,p_MinET2))) continue;
116 // OneBarrel
117 if (p_OneBarrel && parType_t(std::abs((*tob1)->eta())) > 10 && parType_t(std::abs((*tob2)->eta())) > 10 ) continue;
118 // DeltaR2 cuts
119 unsigned int deltaR2 = calcDeltaR2BW( *tob1, *tob2 );
120 // Charge cut ( 1 = positive, -1 = negative, 0 = undefined (RPC) )
121 int charge1 = (*tob1)->charge();
122 int charge2 = (*tob2)->charge();
123 int totalCharge = charge1 + charge2;
124 bool acceptCharge = true;
125 if ( std::abs(totalCharge) == 2 ) { acceptCharge = false; }
126 for(unsigned int i=0; i<numberOutputBits(); ++i) {
127 bool accept = false;
128 accept = deltaR2 >= p_DeltaRMin[i] && deltaR2 <= p_DeltaRMax[i] && acceptCharge;
129 const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
130 const bool fillReject = fillHistos() and not fillAccept;
131 const bool alreadyFilled = decision.bit(i);
132 if( accept ) {
133 decision.setBit(i, true);
134 output[i]->push_back( TCS::CompositeTOB(*tob1, *tob2) );
135 }
136 if(fillAccept and not alreadyFilled) {
137 fillHist1D(m_histAccept[i],std::sqrt(static_cast<float>(deltaR2)));
138 fillHist2D(m_histAcceptEta1Eta2[i],(*tob1)->eta(),(*tob2)->eta());
139 } else if(fillReject) {
140 fillHist1D(m_histReject[i],std::sqrt(static_cast<float>(deltaR2)));
141 fillHist2D(m_histRejectEta1Eta2[i],(*tob1)->eta(),(*tob2)->eta());
142 }
143 TRG_MSG_DEBUG("Decision " << i << ": " << (accept?"pass":"fail") << " deltaR2 = " << deltaR2);
144 }
145 }
146 }
147 bool hasAmbiguousInputs = TSU::isAmbiguousTruncation(input[0], p_NumberLeading1, p_MinET1)
149 for (unsigned int i=0; i < numberOutputBits(); ++i) {
150 output[i]->setAmbiguityFlag(hasAmbiguousInputs);
151 }
152 } else {
153 TCS_EXCEPTION("DeltaRSqrIncl1Charge alg must have either 1 input, but got " << input.size());
154 }
156}
157
159TCS::DeltaRSqrIncl1Charge::process( const std::vector<TCS::TOBArray const *> & input,
160 const std::vector<TCS::TOBArray *> & output,
161 Decision & decision )
162{
163 if(input.size() == 1) {
164 for( TOBArray::const_iterator tob1 = input[0]->begin();
165 tob1 != input[0]->end() && distance( input[0]->begin(), tob1) < p_NumberLeading1;
166 ++tob1)
167 {
168 if( parType_t((*tob1)->Et()) <= std::min(p_MinET1,p_MinET2)) continue; // ET cut
169 TCS::TOBArray::const_iterator tob2 = tob1; ++tob2;
170 for( ;
171 tob2 != input[0]->end() && distance( input[0]->begin(), tob2) < p_NumberLeading2;
172 ++tob2) {
173 if( parType_t((*tob2)->Et()) <= std::min(p_MinET1,p_MinET2)) continue; // ET cut
174 if( (parType_t((*tob1)->Et()) <= std::max(p_MinET1,p_MinET2)) && (parType_t((*tob2)->Et()) <= std::max(p_MinET1,p_MinET2))) continue;
175 // OneBarrel
176 if (p_OneBarrel && parType_t(std::abs((*tob1)->eta())) > 10 && parType_t(std::abs((*tob2)->eta())) > 10 ) continue;
177 // DeltaR2 cuts
178 unsigned int deltaR2 = calcDeltaR2( *tob1, *tob2 );
179 // Charge cut ( 1 = positive, -1 = negative, 0 = undefined (RPC) )
180 int charge1 = (*tob1)->charge();
181 int charge2 = (*tob2)->charge();
182 int totalCharge = charge1 + charge2;
183 bool acceptCharge = true;
184 if ( std::abs(totalCharge) == 2 ) { acceptCharge = false; }
185 for(unsigned int i=0; i<numberOutputBits(); ++i) {
186 bool accept = false;
187 accept = deltaR2 >= p_DeltaRMin[i] && deltaR2 <= p_DeltaRMax[i] && acceptCharge;
188 const bool fillAccept = fillHistos() and (fillHistosBasedOnHardware() ? getDecisionHardwareBit(i) : accept);
189 const bool fillReject = fillHistos() and not fillAccept;
190 const bool alreadyFilled = decision.bit(i);
191 if( accept ) {
192 decision.setBit(i, true);
193 output[i]->push_back( TCS::CompositeTOB(*tob1, *tob2) );
194 }
195 if(fillAccept and not alreadyFilled) {
196 fillHist1D(m_histAccept[i],std::sqrt(static_cast<float>(deltaR2)));
197 fillHist2D(m_histAcceptEta1Eta2[i],(*tob1)->eta(),(*tob2)->eta());
198 } else if(fillReject) {
199 fillHist1D(m_histReject[i],std::sqrt(static_cast<float>(deltaR2)));
200 fillHist2D(m_histRejectEta1Eta2[i],(*tob1)->eta(),(*tob2)->eta());
201 }
202 TRG_MSG_DEBUG("Decision " << i << ": " << (accept?"pass":"fail") << " deltaR2 = " << deltaR2);
203 }
204 }
205 }
206 } else {
207 TCS_EXCEPTION("DeltaRSqrIncl1Charge alg must have either 1 input, but got " << input.size());
208 }
210}
#define REGISTER_ALG_TCS(CLASS)
Definition AlgFactory.h:62
const Parameter & parameter(const std::string &parameterName) const
const std::string & name() const
void bookHist(std::vector< std::string > &regName, const std::string &name, const std::string &title, const int binx, const int xmin, const int xmax)
void fillHist1D(const std::string &histName, double x)
unsigned int calcDeltaR2BW(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
void defineParameter(const std::string &name, TCS::parType_t value)
unsigned int calcDeltaR2(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
void fillHist2D(const std::string &histName, double x, double y)
data_t::const_iterator const_iterator
std::vector< std::string > m_histAcceptEta1Eta2
Definition DecisionAlg.h:79
void setNumberOutputBits(unsigned int numberOutputBits)
Definition DecisionAlg.h:40
DecisionAlg(const std::string &name)
Definition DecisionAlg.h:25
std::vector< std::string > m_histRejectEta1Eta2
Definition DecisionAlg.h:80
bool fillHistosBasedOnHardware() const
! getter
bool fillHistos() const
whether the monitoring histograms should be filled
std::vector< std::string > m_histAccept
Definition DecisionAlg.h:73
std::vector< std::string > m_histReject
Definition DecisionAlg.h:74
unsigned int numberOutputBits() const
Definition DecisionAlg.h:39
bool getDecisionHardwareBit(const unsigned int &bitNumber) const
! get one hardware decision bit from this algo
bool bit(unsigned int index) const
Definition Decision.h:40
void setBit(unsigned int index, bool value)
Definition Decision.cxx:12
virtual StatusCode process(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison)
DeltaRSqrIncl1Charge(const std::string &name)
virtual StatusCode processBitCorrect(const std::vector< TCS::TOBArray const * > &input, const std::vector< TCS::TOBArray * > &output, Decision &decison)
uint32_t parType_t
Definition Parameter.h:22
bool isAmbiguousTruncation(TCS::TOBArray const *tobs, size_t pos, unsigned minEt=0)