Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:15:33

0001 #include "HeavyFlavorAnalysis/Onia2MuMu/interface/OniaAddV0TracksProducer.h"
0002 #include "DataFormats/PatCandidates/interface/CompositeCandidate.h"
0003 #include "DataFormats/TrackReco/interface/Track.h"
0004 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
0005 #include <vector>
0006 
0007 OniaAddV0TracksProducer::OniaAddV0TracksProducer(const edm::ParameterSet& ps)
0008     : events_v0{0}, total_v0{0}, total_lambda{0}, total_kshort{0} {
0009   LambdaCollectionToken_ =
0010       consumes<reco::VertexCompositeCandidateCollection>(ps.getParameter<edm::InputTag>("LambdaTag"));
0011   KShortCollectionToken_ =
0012       consumes<reco::VertexCompositeCandidateCollection>(ps.getParameter<edm::InputTag>("KShortTag"));
0013 
0014   produces<pat::CompositeCandidateCollection>("Kshort");
0015   produces<pat::CompositeCandidateCollection>("Lambda");
0016 }
0017 
0018 void OniaAddV0TracksProducer::produce(edm::StreamID, edm::Event& event, const edm::EventSetup& esetup) const {
0019   // Create unique_ptr for each collection to be stored in the Event
0020   std::unique_ptr<pat::CompositeCandidateCollection> Enhanced_kShortCandidates(new pat::CompositeCandidateCollection);
0021   std::unique_ptr<pat::CompositeCandidateCollection> Enhanced_lambdaCandidates(new pat::CompositeCandidateCollection);
0022 
0023   edm::Handle<reco::VertexCompositeCandidateCollection> lcandidates;
0024   event.getByToken(LambdaCollectionToken_, lcandidates);
0025 
0026   edm::Handle<reco::VertexCompositeCandidateCollection> kcandidates;
0027   event.getByToken(KShortCollectionToken_, kcandidates);
0028 
0029   int exits_l = 0;
0030   int exits_k = 0;
0031   for (reco::VertexCompositeCandidateCollection::const_iterator ik = kcandidates->begin(); ik != kcandidates->end();
0032        ++ik) {
0033     pat::CompositeCandidate kc{};
0034     edm::RefToBase<reco::Track> ktrk0((*(dynamic_cast<const reco::RecoChargedCandidate*>(ik->daughter(0)))).track());
0035     edm::RefToBase<reco::Track> ktrk1((*(dynamic_cast<const reco::RecoChargedCandidate*>(ik->daughter(1)))).track());
0036     kc.addUserData<reco::Track>("track0", *ktrk0);
0037     kc.addUserData<reco::Track>("track1", *ktrk1);
0038     Enhanced_kShortCandidates->emplace_back(std::move(kc));
0039     exits_k++;
0040   }
0041 
0042   for (reco::VertexCompositeCandidateCollection::const_iterator il = lcandidates->begin(); il != lcandidates->end();
0043        ++il) {
0044     pat::CompositeCandidate lc{};
0045     edm::RefToBase<reco::Track> ltrk0((*(dynamic_cast<const reco::RecoChargedCandidate*>(il->daughter(0)))).track());
0046     edm::RefToBase<reco::Track> ltrk1((*(dynamic_cast<const reco::RecoChargedCandidate*>(il->daughter(1)))).track());
0047     lc.addUserData<reco::Track>("track0", *ltrk0);
0048     lc.addUserData<reco::Track>("track1", *ltrk1);
0049     Enhanced_lambdaCandidates->emplace_back(std::move(lc));
0050     exits_l++;
0051   }
0052 
0053   // Write the collections to the Event
0054 
0055   total_v0 += exits_k;
0056   total_v0 += exits_l;
0057   total_kshort += exits_k;
0058   total_lambda += exits_l;
0059   if (exits_k || exits_l)
0060     events_v0++;
0061 
0062   event.put(std::move(Enhanced_kShortCandidates), "Kshort");
0063   event.put(std::move(Enhanced_lambdaCandidates), "Lambda");
0064 }
0065 
0066 void OniaAddV0TracksProducer::endJob() {
0067   edm::LogVerbatim("OniaAddV0TracksSummary") << "############################\n"
0068                                                 "OniaAddV0Tracks producer report \n"
0069                                                 "############################\n"
0070                                                 "Total events with v0 :      "
0071                                              << events_v0
0072                                              << "\n"
0073                                                 "Total v0 :                  "
0074                                              << total_v0
0075                                              << "\n"
0076                                                 "Total number of lambda :    "
0077                                              << total_lambda
0078                                              << "\n"
0079                                                 "Total number of kshort :    "
0080                                              << total_kshort
0081                                              << "\n"
0082                                                 "############################";
0083 }
0084 //define this as a plug-in
0085 DEFINE_FWK_MODULE(OniaAddV0TracksProducer);