2 #include "TObjString.h"
41 namespace l1tVertexFinder {
51 std::vector<float>
pt;
52 std::vector<float>
eta;
53 std::vector<float>
phi;
65 std::vector<float>
pt;
66 std::vector<float>
eta;
67 std::vector<float>
phi;
84 std::vector<float>
z0;
96 std::vector<float>
pt;
97 std::vector<float>
eta;
98 std::vector<float>
phi;
99 std::vector<float>
z0;
116 trueMatchIdx.clear();
117 truthMapMatchIdx.clear();
118 truthMapIsGenuine.clear();
119 truthMapIsLooselyGenuine.clear();
120 truthMapIsCombinatoric.clear();
121 truthMapIsUnknown.clear();
126 std::vector<float>
pt;
129 std::vector<float>
z0;
143 physCollision.clear();
146 useForAlgEff.clear();
147 useForVertexReco.clear();
153 void endJob()
override;
209 : inputDataToken_(consumes<l1tVertexFinder::
InputData>(iConfig.getParameter<edm::
InputTag>(
"inputDataInputTag"))),
213 genJetsToken_(consumes<std::
vector<
reco::GenJet>>(iConfig.getParameter<edm::
InputTag>(
"genJetsInputTag"))),
215 consumes<std::
vector<l1tVertexFinder::
TP>>(iConfig.getParameter<edm::
InputTag>(
"l1TracksTPInputTags"))),
216 vTPsToken_(consumes<edm::ValueMap<l1tVertexFinder::
TP>>(
217 iConfig.getParameter<edm::
InputTag>(
"l1TracksTPValueMapInputTags"))),
219 printResults_(iConfig.getParameter<bool>(
"printResults")),
221 const std::vector<std::string> trackBranchNames(
222 iConfig.
getParameter<std::vector<std::string>>(
"l1TracksBranchNames"));
223 const std::vector<edm::InputTag> trackInputTags(
224 iConfig.
getParameter<std::vector<edm::InputTag>>(
"l1TracksInputTags"));
225 const std::vector<edm::InputTag> trackMapInputTags(
226 iConfig.
getParameter<std::vector<edm::InputTag>>(
"l1TracksTruthMapInputTags"));
233 outputTree_ = fs_->
make<TTree>(
"l1VertexReco",
"L1 vertex-related info");
235 if (trackBranchNames.size() != trackInputTags.size())
236 throw cms::Exception(
"The number of track branch names (" + std::to_string(trackBranchNames.size()) +
237 ") specified in the config does not match the number of input tags (" +
238 std::to_string(trackInputTags.size()) +
")");
239 if (trackBranchNames.size() != trackMapInputTags.size())
240 throw cms::Exception(
"The number of track branch names (" + std::to_string(trackBranchNames.size()) +
241 ") specified in the config does not match the number of track map input tags (" +
242 std::to_string(trackMapInputTags.size()) +
")");
244 const std::vector<std::string> vertexBranchNames(
245 iConfig.
getParameter<std::vector<std::string>>(
"l1VertexBranchNames"));
246 const std::vector<edm::InputTag> vertexInputTags(
247 iConfig.
getParameter<std::vector<edm::InputTag>>(
"l1VertexInputTags"));
248 const std::vector<std::string> vertexTrackNames(
249 iConfig.
getParameter<std::vector<std::string>>(
"l1VertexTrackInputs"));
251 if (vertexBranchNames.size() != vertexInputTags.size())
252 throw cms::Exception(
"The number of vertex branch names (" + std::to_string(vertexBranchNames.size()) +
253 ") specified in the config does not match the number of input tags (" +
254 std::to_string(vertexInputTags.size()) +
")");
255 if (vertexBranchNames.size() != vertexTrackNames.size())
257 "The number of vertex branch names (" + std::to_string(vertexBranchNames.size()) +
258 ") specified in the config does not match the number of associated input track collection names (" +
259 std::to_string(vertexTrackNames.size()) +
")");
276 std::vector<std::string>::const_iterator trackBranchNameIt = trackBranchNames.begin();
277 std::vector<edm::InputTag>::const_iterator trackInputTagIt = trackInputTags.begin();
278 std::vector<edm::InputTag>::const_iterator trackMapInputTagIt = trackMapInputTags.begin();
279 for (; trackBranchNameIt != trackBranchNames.end(); trackBranchNameIt++, trackInputTagIt++, trackMapInputTagIt++) {
280 l1TracksTokenMap_[*trackBranchNameIt] = consumes<TTTrackCollectionView>(*trackInputTagIt);
282 consumes<TTTrackAssociationMap<Ref_Phase2TrackerDigi_>>(*trackMapInputTagIt);
286 outputTree_->Branch((
"recoTracks_" + *trackBranchNameIt +
"_pt").c_str(), &branchData.
pt);
287 outputTree_->Branch((
"recoTracks_" + *trackBranchNameIt +
"_eta").c_str(), &branchData.
eta);
288 outputTree_->Branch((
"recoTracks_" + *trackBranchNameIt +
"_phi").c_str(), &branchData.
phi);
289 outputTree_->Branch((
"recoTracks_" + *trackBranchNameIt +
"_z0").c_str(), &branchData.
z0);
290 outputTree_->Branch((
"recoTracks_" + *trackBranchNameIt +
"_numStubs").c_str(), &branchData.
numStubs);
291 outputTree_->Branch((
"recoTracks_" + *trackBranchNameIt +
"_chi2dof").c_str(), &branchData.
chi2dof);
293 outputTree_->Branch((
"recoTracks_" + *trackBranchNameIt +
"_truthMap_matchIdx").c_str(),
295 outputTree_->Branch((
"recoTracks_" + *trackBranchNameIt +
"_truthMap_isGenuine").c_str(),
297 outputTree_->Branch((
"recoTracks_" + *trackBranchNameIt +
"_truthMap_isLooselyGenuine").c_str(),
299 outputTree_->Branch((
"recoTracks_" + *trackBranchNameIt +
"_truthMap_isCombinatoric").c_str(),
301 outputTree_->Branch((
"recoTracks_" + *trackBranchNameIt +
"_truthMap_isUnknown").c_str(),
305 std::vector<std::string>::const_iterator branchNameIt = vertexBranchNames.begin();
306 std::vector<edm::InputTag>::const_iterator inputTagIt = vertexInputTags.begin();
307 std::vector<std::string>::const_iterator l1VertexTrackNameIt = vertexTrackNames.begin();
308 for (; branchNameIt != vertexBranchNames.end(); branchNameIt++, inputTagIt++, l1VertexTrackNameIt++) {
316 throw cms::Exception(
"Invalid track collection name '" + *l1VertexTrackNameIt +
317 "' specified as input to vertex collection '" + *branchNameIt +
"'");
319 outputTree_->Branch((
"recoVertices_" + *branchNameIt +
"_numTracks").c_str(), &branchData.
numTracks);
320 outputTree_->Branch((
"recoVertices_" + *branchNameIt +
"_trackIdxs").c_str(), &branchData.
trackIdxs);
321 outputTree_->Branch((
"recoVertices_" + *branchNameIt +
"_z0").c_str(), &branchData.
z0);
322 outputTree_->Branch((
"recoVertices_" + *branchNameIt +
"_sumPt").c_str(), &branchData.
sumPt);
337 const std::vector<edm::InputTag> extraVertexInputTags(
338 iConfig.
getParameter<std::vector<edm::InputTag>>(
"extraL1VertexInputTags"));
339 const std::vector<std::string> extraVertexDescriptions(
340 iConfig.
getParameter<std::vector<std::string>>(
"extraL1VertexDescriptions"));
341 for (
const auto&
inputTag : extraVertexInputTags)
343 TObjArray* descriptionArray =
new TObjArray();
344 for (
const auto&
description : extraVertexDescriptions)
345 descriptionArray->Add(
new TObjString(
description.c_str()));
356 const bool positive = (particle.
pdgId() < 0);
357 const size_t absId =
abs(particle.
pdgId());
360 return (out << (positive ?
"d" :
"anti-d"));
362 return (out << (positive ?
"u" :
"anti-u"));
364 return (out << (positive ?
"s" :
"anti-s"));
366 return (out << (positive ?
"c" :
"anti-c"));
368 return (out << (positive ?
"b" :
"anti-b"));
370 return (out << (positive ?
"t" :
"anti-t"));
372 return (out << (positive ?
"e+" :
"e-"));
374 return (out << (positive ?
"nu_e" :
"anti-nu_e"));
376 return (out << (positive ?
"mu+" :
"mu-"));
378 return (out << (positive ?
"nu_mu" :
"anti-nu_mu"));
380 return (out << (positive ?
"tau+" :
"tau-"));
382 return (out << (positive ?
"nu_tau" :
"anti-nu_tau"));
386 return (out <<
"photon");
390 return (out << (positive ?
"W-" :
"W+"));
392 if ((((absId / 1000) % 10) != 0) and (((absId / 10) % 10) == 0))
393 return (out <<
"diquark<" << particle.
pdgId() <<
">");
395 return (out <<
"unknown<" << particle.
pdgId() <<
">");
410 std::map<std::string, std::vector<L1TrackTruthMatched>> l1TrackCollections;
411 std::map<std::string, edm::Handle<TTTrackAssMap>> truthAssocMapHandles;
418 for (; (tokenMapEntry != tokenMapEntryEnd) && (mapTokenMapEntry != mapTokenMapEntryEnd);
419 ++tokenMapEntry, ++mapTokenMapEntry) {
422 iEvent.
getByToken(tokenMapEntry->second, l1TracksHandle);
425 std::vector<L1TrackTruthMatched>& l1Tracks = l1TrackCollections[tokenMapEntry->first];
426 l1Tracks.reserve(l1TracksHandle->size());
427 for (
const auto&
track : l1TracksHandle->ptrs()) {
434 std::map<std::string, std::map<const edm::Ptr<TTTrack<Ref_Phase2TrackerDigi_>>,
const L1TrackTruthMatched*>>
438 for (
const auto&
entry : l1TrackCollections) {
439 auto& edmL1Map = edmL1TrackMaps[
entry.first];
452 for (
auto bxIt = pileupHandle->begin(); bxIt != pileupHandle->end(); bxIt++) {
453 if (bxIt->getBunchCrossing() == 0) {
464 for (
const auto&
tp : *allMatchedTPsHandle) {
490 for (
const auto&
p : *genParticlesH) {
503 for (
const auto& genJet : *genJetsHandle) {
510 for (
const auto&
entry : l1TrackCollections) {
511 const auto& l1Tracks =
entry.second;
519 branchData.
pt.push_back(
track.pt());
520 branchData.
eta.push_back(
track.eta());
521 branchData.
phi.push_back(
track.phi0());
522 branchData.
z0.push_back(
track.z0());
531 auto it = std::find_if(allMatchedTPsHandle->begin(),
532 allMatchedTPsHandle->end(),
533 [&matchedTP](
auto const&
tp) {
return tp.getTrackingParticle() == matchedTP; });
534 assert(it != allMatchedTPsHandle->end());
550 iEvent.
getByToken(tokenMapEntry.second, handle);
551 std::vector<std::shared_ptr<const RecoVertexWithTP>> recoVertices;
552 recoVertices.reserve(handle->size());
553 for (
unsigned int i = 0;
i < handle->size(); ++
i) {
554 recoVertices.push_back(std::shared_ptr<const RecoVertexWithTP>(
559 std::vector<L1TrackTruthMatched>& l1Tracks = l1TrackCollections.at(
l1VerticesInputMap_.at(tokenMapEntry.first));
560 for (
const std::shared_ptr<const RecoVertexWithTP>& vtx : recoVertices) {
561 branchData.
numTracks.push_back(vtx->numTracks());
562 branchData.
trackIdxs.push_back(std::vector<unsigned>());
565 branchData.
z0.push_back(vtx->z0());
566 branchData.
sumPt.push_back(vtx->pt());
570 edm::LogInfo(
"VertexNTupler") <<
"analyze::" << recoVertices.size() <<
" '" << tokenMapEntry.first
571 <<
"' vertices were found ... ";
572 for (
const auto& vtx : recoVertices) {
574 <<
" * z0 = " << vtx->z0() <<
"; contains " << vtx->numTracks()
576 for (
const auto& trackPtr : vtx->tracks())
578 <<
" - z0 = " << trackPtr->z0() <<
"; pt = " << trackPtr->pt()
579 <<
", eta = " << trackPtr->eta() <<
", phi = " << trackPtr->phi0();
593 const std::vector<l1t::Vertex>&
vertices = *vertexHandle;
600 for (
const auto& vertex : vertices) {
605 float etaWeightedSumZ0 = 0.0;
606 float etaWeightSum = 0.0;
607 for (
const auto&
track : vertex.tracks()) {
608 sumPt +=
track->momentum().transverse();
610 const float zRes = 0.223074 *
track->momentum().eta() *
track->momentum().eta() -
611 0.050231 *
abs(
track->momentum().eta()) + 0.209719;
612 etaWeightedSumZ0 +=
track->POCA().z() / (zRes * zRes);
613 etaWeightSum += 1.0 / (zRes * zRes);
625 edm::LogInfo(
"VertexNTupler") <<
"analyze::================ End of Event ==============";
634 using namespace l1tVertexFinder;
~VertexNTupler() override
std::vector< float > physCollision
const edm::EDGetTokenT< edm::View< reco::GenParticle > > genParticlesToken_
std::vector< std::vector< unsigned > > l1Vertices_extra_numTracks_
std::vector< edm::EDGetTokenT< std::vector< l1t::Vertex > > > l1VerticesExtraTokens_
std::vector< std::vector< float > > l1Vertices_extra_z0_
double vz() const
Vertex z position [cm].
std::vector< float > energy
std::vector< std::vector< float > > l1Vertices_extra_sumPt_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
std::unordered_map< std::string, std::vector< unsigned > > l1Vertices_branchMap_numTracks_
AnalysisSettings settings_
std::vector< float > chi2dof
#define DEFINE_FWK_MODULE(type)
std::vector< float > truthMapIsUnknown
bool isLooselyGenuine(TTTrackPtrT< T > aTrack) const
std::map< std::string, edm::EDGetTokenT< TTTrackCollectionView > > l1TracksTokenMap_
std::vector< float > truthMapIsGenuine
std::map< std::string, edm::EDGetTokenT< TTTrackAssociationMap< Ref_Phase2TrackerDigi_ > > > l1TracksMapTokenMap_
T * make(const Args &...args) const
make new ROOT object
std::map< std::string, edm::EDGetTokenT< std::vector< l1t::Vertex > > > l1VerticesTokenMap_
std::vector< std::vector< float > > l1Vertices_extra_z0_etaWeighted_
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
std::map< std::string, RecoTracksBranchData > l1TracksBranchData_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Stores association of Truth Particles (TP) to L1 Track-Trigger Tracks.
int pdgId() const final
PDG identifier.
bool isCombinatoric(TTTrackPtrT< T > aTrack) const
Both isLooselyGenuine() & isUnknown() are false.
std::vector< float > energy
RecoVertex< L1TrackTruthMatched > RecoVertexWithTP
std::vector< float > truthMapIsLooselyGenuine
std::vector< float > truePileUpVtxZ0_
Simple wrapper class for TTTrack, with match to a tracking particle.
unsigned int debug() const
std::vector< int > trueMatchIdx
bool isGenuine(TTTrackPtrT< T > aTrack) const
const edm::EDGetTokenT< std::vector< PileupSummaryInfo > > pileupSummaryToken_
bool isNull() const
Checks for null.
std::vector< float > truthMapIsCombinatoric
Abs< T >::type abs(const T &t)
float numTrueInteractions_
std::vector< float > sumPt
TTTrackAssociationMap< Ref_Phase2TrackerDigi_ > TTTrackAssMap
std::unordered_map< std::string, std::vector< float > > l1Vertices_branchMap_z0_etaWeighted_
const edm::EDGetTokenT< edm::ValueMap< l1tVertexFinder::TP > > vTPsToken_
edm::View< TTTrack< Ref_Phase2TrackerDigi_ > > TTTrackCollectionView
Log< level::Info, false > LogInfo
std::ostream & operator<<(std::ostream &out, const reco::GenParticle &particle)
std::map< std::string, edm::EDGetTokenT< std::vector< l1t::Vertex > > > l1VerticesExtraTokenMap_
std::vector< float > useForVertexReco
Class to store the L1 Track Trigger tracks.
T getParameter(std::string const &) const
std::vector< unsigned > numTracks
const TrackingParticlePtr & findTrackingParticlePtr(TTTrackPtrT< T > aTrack) const
std::vector< unsigned > numStubs
std::vector< float > useForAlgEff
GenJetsBranchData genJetsBranchData_
std::vector< float > useForEff
std::vector< int > status
void analyze(const edm::Event &evt, const edm::EventSetup &setup) override
TrueTracksBranchData trueTracksBranchData_
std::map< std::string, RecoVerticesBranchData > l1VerticesBranchData_
bool isUnknown(TTTrackPtrT< T > aTrack) const
More than one stub on track is "unknown".
std::unordered_map< std::string, std::vector< float > > l1Vertices_branchMap_z0_
const edm::EDGetTokenT< std::vector< reco::GenJet > > genJetsToken_
const edm::EDGetTokenT< l1tVertexFinder::InputData > inputDataToken_
std::unordered_map< std::string, std::vector< float > > l1Vertices_branchMap_sumPt_
std::vector< int > truthMapMatchIdx
std::map< std::string, std::string > l1VerticesInputMap_
std::vector< std::vector< unsigned > > trackIdxs
GenParticlesBranchData genParticlesHardOutgoingBranchData_
const edm::EDGetTokenT< std::vector< l1tVertexFinder::TP > > allMatchedTPsToken_