CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HLTBJet.cc
Go to the documentation of this file.
1 #include <cmath>
2 #include <algorithm>
3 #include <utility>
4 #include <cstring>
5 #include <boost/foreach.hpp>
6 
7 #include <TTree.h>
8 
13 
17 
19 
20 static const size_t kMaxBJets = 10;
21 
22 #include "HLTMessages.h"
23 
25 {
26  // set of variables for uncorrected L2 jets
27  NohBJetL2 = 0;
28  ohBJetL2Energy = new float[kMaxBJets];
29  ohBJetL2Et = new float[kMaxBJets];
30  ohBJetL2Pt = new float[kMaxBJets];
31  ohBJetL2Eta = new float[kMaxBJets];
32  ohBJetL2Phi = new float[kMaxBJets];
33 
34  // set of variables for corrected L2 jets
37  ohBJetL2CorrectedEt = new float[kMaxBJets];
38  ohBJetL2CorrectedPt = new float[kMaxBJets];
39  ohBJetL2CorrectedEta = new float[kMaxBJets];
40  ohBJetL2CorrectedPhi = new float[kMaxBJets];
41 
42  // set of variables for lifetime-based b-tag
43  ohBJetIPL25Tag = new float[kMaxBJets];
44  ohBJetIPL3Tag = new float[kMaxBJets];
45 
46  // set of variables for soft-muon-based b-tag
47  ohBJetMuL25Tag = new int[kMaxBJets]; // do not optimize
48  ohBJetMuL3Tag = new float[kMaxBJets]; // SoftMuonbyPt
49 
50  // set of variables for b-tagging performance measurements
51  // SoftMuonbyDR
52  ohBJetPerfL25Tag = new int[kMaxBJets]; // do not optimize
53  ohBJetPerfL3Tag = new int[kMaxBJets]; // do not optimize
54 }
55 
57 {
58  NohBJetL2 = 0;
60  std::memset(ohBJetL2Energy, '\0', kMaxBJets * sizeof(float));
61  std::memset(ohBJetL2Et, '\0', kMaxBJets * sizeof(float));
62  std::memset(ohBJetL2Et, '\0', kMaxBJets * sizeof(float));
63  std::memset(ohBJetL2Pt, '\0', kMaxBJets * sizeof(float));
64  std::memset(ohBJetL2Eta, '\0', kMaxBJets * sizeof(float));
65  std::memset(ohBJetL2Phi, '\0', kMaxBJets * sizeof(float));
66  std::memset(ohBJetL2CorrectedEnergy, '\0', kMaxBJets * sizeof(float));
67  std::memset(ohBJetL2CorrectedEt, '\0', kMaxBJets * sizeof(float));
68  std::memset(ohBJetL2CorrectedPt, '\0', kMaxBJets * sizeof(float));
69  std::memset(ohBJetL2CorrectedEta, '\0', kMaxBJets * sizeof(float));
70  std::memset(ohBJetL2CorrectedPhi, '\0', kMaxBJets * sizeof(float));
71 
72  std::memset(ohBJetIPL25Tag, '\0', kMaxBJets * sizeof(float));
73  std::memset(ohBJetIPL3Tag, '\0', kMaxBJets * sizeof(float));
74 
75  std::memset(ohBJetMuL25Tag, '\0', kMaxBJets * sizeof(int));
76  std::memset(ohBJetMuL3Tag, '\0', kMaxBJets * sizeof(float));
77  std::memset(ohBJetPerfL25Tag, '\0', kMaxBJets * sizeof(int));
78  std::memset(ohBJetPerfL3Tag, '\0', kMaxBJets * sizeof(int));
79 }
80 
82 { }
83 
85 {
86  // create the TTree branches
87  if (tree) {
88  tree->Branch("NohBJetL2", & NohBJetL2, "NohBJetL2/I");
89  tree->Branch("ohBJetL2Energy", ohBJetL2Energy, "ohBJetL2Energy[NohBJetL2]/F");
90  tree->Branch("ohBJetL2Et", ohBJetL2Et, "ohBJetL2Et[NohBJetL2]/F");
91  tree->Branch("ohBJetL2Pt", ohBJetL2Pt, "ohBJetL2Pt[NohBJetL2]/F");
92  tree->Branch("ohBJetL2Eta", ohBJetL2Eta, "ohBJetL2Eta[NohBJetL2]/F");
93  tree->Branch("ohBJetL2Phi", ohBJetL2Phi, "ohBJetL2Phi[NohBJetL2]/F");
94 
95  tree->Branch("NohBJetL2Corrected", & NohBJetL2Corrected, "NohBJetL2Corrected/I");
96  tree->Branch("ohBJetL2CorrectedEnergy", ohBJetL2CorrectedEnergy, "ohBJetL2CorrectedEnergy[NohBJetL2Corrected]/F");
97  tree->Branch("ohBJetL2CorrectedEt", ohBJetL2CorrectedEt, "ohBJetL2CorrectedEt[NohBJetL2Corrected]/F");
98  tree->Branch("ohBJetL2CorrectedPt", ohBJetL2CorrectedPt, "ohBJetL2CorrectedPt[NohBJetL2Corrected]/F");
99  tree->Branch("ohBJetL2CorrectedEta", ohBJetL2CorrectedEta, "ohBJetL2CorrectedEta[NohBJetL2Corrected]/F");
100  tree->Branch("ohBJetL2CorrectedPhi", ohBJetL2CorrectedPhi, "ohBJetL2CorrectedPhi[NohBJetL2Corrected]/F");
101 
102  tree->Branch("ohBJetIPL25Tag", ohBJetIPL25Tag, "ohBJetIPL25Tag[NohBJetL2]/F");
103  tree->Branch("ohBJetIPL3Tag", ohBJetIPL3Tag, "ohBJetIPL3Tag[NohBJetL2]/F");
104 
105  tree->Branch("ohBJetMuL25Tag", ohBJetMuL25Tag, "ohBJetMuL25Tag[NohBJetL2]/I");
106  tree->Branch("ohBJetMuL3Tag", ohBJetMuL3Tag, "ohBJetMuL3Tag[NohBJetL2]/F");
107  tree->Branch("ohBJetPerfL25Tag", ohBJetPerfL25Tag, "ohBJetPerfL25Tag[NohBJetL2]/I");
108  tree->Branch("ohBJetPerfL3Tag", ohBJetPerfL3Tag, "ohBJetPerfL3Tag[NohBJetL2]/I");
109  }
110 }
111 
113  const edm::Handle<edm::View<reco::Jet> > & rawBJets,
114  const edm::Handle<edm::View<reco::Jet> > & correctedBJets,
115  const edm::Handle<reco::JetTagCollection> & lifetimeBJetsL25,
116  const edm::Handle<reco::JetTagCollection> & lifetimeBJetsL3,
117  const edm::Handle<reco::JetTagCollection> & softmuonBJetsL25,
118  const edm::Handle<reco::JetTagCollection> & softmuonBJetsL3,
119  const edm::Handle<reco::JetTagCollection> & performanceBJetsL25,
120  const edm::Handle<reco::JetTagCollection> & performanceBJetsL3,
121  TTree * tree)
122 {
123  // reset the tree variables
124  clear();
125 
126  // if the required collections are available, fill the corresponding tree branches
127  if (rawBJets.isValid())
128  analyseJets(* rawBJets);
129 
130  if (correctedBJets.isValid())
131  analyseCorrectedJets(* correctedBJets);
132 
133  if (correctedBJets.isValid() and lifetimeBJetsL25.isValid() and lifetimeBJetsL3.isValid())
134  analyseLifetime(* correctedBJets, * lifetimeBJetsL25, * lifetimeBJetsL3);
135 
136  if (correctedBJets.isValid() and softmuonBJetsL25.isValid() and softmuonBJetsL3.isValid())
137  analyseSoftmuon(* correctedBJets, * softmuonBJetsL25, * softmuonBJetsL3);
138 
139  if (correctedBJets.isValid() and performanceBJetsL25.isValid() and performanceBJetsL3.isValid())
140  analysePerformance(* correctedBJets, * performanceBJetsL25, * performanceBJetsL3);
141 
142 }
143 
145 {
146  // the jets need to be persistable, so .size() returns an 'unsigned int' to be stable across the architectures
147  // so, for the comparison, we cast back to size_t
148  size_t size = std::min(kMaxBJets, size_t(jets.size()) );
149  NohBJetL2 = size;
150  for (size_t i = 0; i < size; ++i) {
151  ohBJetL2Energy[i] = jets[i].energy();
152  ohBJetL2Et[i] = jets[i].et();
153  ohBJetL2Pt[i] = jets[i].pt();
154  ohBJetL2Eta[i] = jets[i].eta();
155  ohBJetL2Phi[i] = jets[i].phi();
156  }
157 }
158 
160 {
161  // the jets need to be persistable, so .size() returns an 'unsigned int' to be stable across the architectures
162  // so, for the comparison, we cast back to size_t
163  size_t size = std::min(kMaxBJets, size_t(jets.size()) );
165  for (size_t i = 0; i < size; ++i) {
166  ohBJetL2CorrectedEnergy[i] = jets[i].energy();
167  ohBJetL2CorrectedEt[i] = jets[i].et();
168  ohBJetL2CorrectedPt[i] = jets[i].pt();
169  ohBJetL2CorrectedEta[i] = jets[i].eta();
170  ohBJetL2CorrectedPhi[i] = jets[i].phi();
171  }
172 }
173 
175  const edm::View<reco::Jet> & jets,
176  const reco::JetTagCollection & tagsL25,
177  const reco::JetTagCollection & tagsL3)
178 {
179  if (tagsL25.size() != jets.size()) {
180  edm::LogWarning("OpenHLT") << kBTagLifetimeBJetsL25 << " collection has " << tagsL25.size() << " elements, but " << jets.size() << " where expected from L2" << std::endl;
181  return;
182  }
183  if (tagsL3.size() != jets.size()) {
184  edm::LogWarning("OpenHLT") << kBTagLifetimeBJetsL3 << " collection has " << tagsL3.size() << " elements, but " << jets.size() << " where expected from L2" << std::endl;
185  return;
186  }
187  // the jets need to be persistable, so .size() returns an 'unsigned int' to be stable across the architectures
188  // so, for the comparison, we cast back to size_t
189  size_t size = std::min(kMaxBJets, size_t(jets.size()) );
190  for (size_t i = 0; i < size; i++) {
191  ohBJetIPL25Tag[i] = tagsL25[i].second;
192  ohBJetIPL3Tag[i] = tagsL3[i].second;
193  }
194 }
195 
197  const edm::View<reco::Jet> & jets,
198  const reco::JetTagCollection & tagsL25,
199  const reco::JetTagCollection & tagsL3)
200 {
201  if (tagsL25.size() != jets.size()) {
202  edm::LogWarning("OpenHLT") << kBTagSoftmuonBJetsL25 << " collection has " << tagsL25.size() << " elements, but " << jets.size() << " where expected from L2" << std::endl;
203  return;
204  }
205  if (tagsL3.size() != jets.size()) {
206  edm::LogWarning("OpenHLT") << kBTagSoftmuonBJetsL3 << " collection has " << tagsL3.size() << " elements, but " << jets.size() << " where expected from L2" << std::endl;
207  return;
208  }
209  // the jets need to be persistable, so .size() returns an 'unsigned int' to be stable across the architectures
210  // so, for the comparison, we cast back to size_t
211  size_t size = std::min(kMaxBJets, size_t(jets.size()) );
212  for (size_t i = 0; i < size; i++) {
213  ohBJetMuL25Tag[i] = (tagsL25[i].second > 0.) ? 1 : 0;
214  ohBJetMuL3Tag[i] = tagsL3[i].second;
215  }
216 }
217 
219  const edm::View<reco::Jet> & jets,
220  const reco::JetTagCollection & tagsL25,
221  const reco::JetTagCollection & tagsL3)
222 {
223  if (tagsL25.size() != jets.size()) {
224  edm::LogWarning("OpenHLT") << kBTagPerformanceBJetsL25 << " collection has " << tagsL25.size() << " elements, but " << jets.size() << " where expected from L2" << std::endl;
225  return;
226  }
227  if (tagsL3.size() != jets.size()) {
228  edm::LogWarning("OpenHLT") << kBTagPerformanceBJetsL3 << " collection has " << tagsL3.size() << " elements, but " << jets.size() << " where expected from L2" << std::endl;
229  return;
230  }
231  // the jets need to be persistable, so .size() returns an 'unsigned int' to be stable across the architectures
232  // so, for the comparison, we cast back to size_t
233  size_t size = std::min(kMaxBJets, size_t(jets.size()) );
234  for (size_t i = 0; i < size; i++) {
235  ohBJetPerfL25Tag[i] = (tagsL25[i].second > 0.) ? 1 : 0;
236  ohBJetPerfL3Tag[i] = (tagsL3[i].second > 0.) ? 1 : 0;
237  }
238 }
const char * kBTagSoftmuonBJetsL3
Definition: HLTMessages.cc:56
float * ohBJetL2Pt
Definition: HLTBJet.h:57
int i
Definition: DBlmapReader.cc:9
void analysePerformance(const edm::View< reco::Jet > &jets, const reco::JetTagCollection &tagsL25, const reco::JetTagCollection &tagsL3)
Definition: HLTBJet.cc:218
void analyseSoftmuon(const edm::View< reco::Jet > &jets, const reco::JetTagCollection &tagsL25, const reco::JetTagCollection &tagsL3)
Definition: HLTBJet.cc:196
void analyseJets(const edm::View< reco::Jet > &jets)
Definition: HLTBJet.cc:144
void clear(void)
Definition: HLTBJet.cc:56
#define min(a, b)
Definition: mlp_lapack.h:161
float * ohBJetL2Eta
Definition: HLTBJet.h:58
int NohBJetL2
Definition: HLTBJet.h:54
const char * kBTagPerformanceBJetsL25
Definition: HLTMessages.cc:57
const char * kBTagSoftmuonBJetsL25
Definition: HLTMessages.cc:55
int NohBJetL2Corrected
Definition: HLTBJet.h:62
void analyseCorrectedJets(const edm::View< reco::Jet > &jets)
Definition: HLTBJet.cc:159
int * ohBJetPerfL3Tag
Definition: HLTBJet.h:79
float * ohBJetL2CorrectedEt
Definition: HLTBJet.h:64
const char * kBTagLifetimeBJetsL25
Definition: HLTMessages.cc:51
static const size_t kMaxBJets
Definition: HLTBJet.cc:20
float * ohBJetL2CorrectedEta
Definition: HLTBJet.h:66
float * ohBJetL2Et
Definition: HLTBJet.h:56
HLTBJet()
Definition: HLTBJet.cc:24
float * ohBJetMuL3Tag
Definition: HLTBJet.h:75
void analyze(const edm::Handle< edm::View< reco::Jet > > &rawBJets, const edm::Handle< edm::View< reco::Jet > > &correctedBJets, const edm::Handle< reco::JetTagCollection > &lifetimeBJetsL25, const edm::Handle< reco::JetTagCollection > &lifetimeBJetsL3, const edm::Handle< reco::JetTagCollection > &softmuonBJetsL25, const edm::Handle< reco::JetTagCollection > &softmuonBJetsL3, const edm::Handle< reco::JetTagCollection > &performanceBJetsL25, const edm::Handle< reco::JetTagCollection > &performanceBJetsL3, TTree *tree)
Definition: HLTBJet.cc:112
const char * kBTagLifetimeBJetsL3
Definition: HLTMessages.cc:52
const char * kBTagPerformanceBJetsL3
Definition: HLTMessages.cc:58
bool isValid() const
Definition: HandleBase.h:76
float * ohBJetL2CorrectedEnergy
Definition: HLTBJet.h:63
size_type size() const
float * ohBJetIPL3Tag
Definition: HLTBJet.h:71
float * ohBJetL2CorrectedPt
Definition: HLTBJet.h:65
float * ohBJetIPL25Tag
Definition: HLTBJet.h:70
float * ohBJetL2CorrectedPhi
Definition: HLTBJet.h:67
float * ohBJetL2Phi
Definition: HLTBJet.h:59
void setup(const edm::ParameterSet &config, TTree *tree)
Definition: HLTBJet.cc:84
void analyseLifetime(const edm::View< reco::Jet > &jets, const reco::JetTagCollection &tagsL25, const reco::JetTagCollection &tagsL3)
Definition: HLTBJet.cc:174
float * ohBJetL2Energy
Definition: HLTBJet.h:55
int * ohBJetPerfL25Tag
Definition: HLTBJet.h:78
tuple size
Write out results.
size_type size() const
~HLTBJet()
Definition: HLTBJet.cc:81
int * ohBJetMuL25Tag
Definition: HLTBJet.h:74