Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-06-10 02:54:33

0001 /** \class CollectionMerger
0002  *
0003  * 
0004  * \author Stefan Wayand;
0005  *         Christian Veelken, LLR
0006  *
0007  * 
0008  *
0009  * 
0010  *
0011  */
0012 #ifndef TauAnalysis_MCEmbeddingTools_CollectionMerger_H
0013 #define TauAnalysis_MCEmbeddingTools_CollectionMerger_H
0014 
0015 #include "FWCore/Framework/interface/stream/EDProducer.h"
0016 #include "FWCore/Framework/interface/Event.h"
0017 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0018 #include "DataFormats/Common/interface/Handle.h"
0019 #include "DataFormats/PatCandidates/interface/Muon.h"
0020 #include "DataFormats/MuonReco/interface/MuonEnergy.h"
0021 #include "FWCore/Framework/interface/MakerMacros.h"
0022 
0023 #include "TrackingTools/TrackAssociator/interface/TrackAssociatorParameters.h"
0024 #include "TrackingTools/TrackAssociator/interface/TrackDetectorAssociator.h"
0025 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
0026 
0027 #include "DataFormats/Common/interface/SortedCollection.h"
0028 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
0029 #include "DataFormats/Common/interface/DetSetVectorNew.h"
0030 #include "DataFormats/TrackerRecHit2D/interface/BaseTrackerRecHit.h"
0031 #include "DataFormats/TrackerRecHit2D/interface/OmniClusterRef.h"
0032 
0033 //#include "TauAnalysis/MCEmbeddingTools/interface/embeddingAuxFunctions.h"
0034 #include <string>
0035 #include <iostream>
0036 #include <map>
0037 
0038 template <typename T1, typename T2>
0039 class CollectionMerger : public edm::stream::EDProducer<> {
0040 public:
0041   explicit CollectionMerger(const edm::ParameterSet &);
0042   ~CollectionMerger() override;
0043 
0044 private:
0045   void produce(edm::Event &, const edm::EventSetup &) override;
0046 
0047   typedef T1 MergeCollection;
0048   typedef T2 BaseHit;
0049   std::map<std::string, std::vector<edm::EDGetTokenT<MergeCollection> > > inputs_;
0050 
0051   void fill_output_obj(std::unique_ptr<MergeCollection> &output,
0052                        std::vector<edm::Handle<MergeCollection> > &inputCollections);
0053   void fill_output_obj_tracker(std::unique_ptr<MergeCollection> &output,
0054                                std::vector<edm::Handle<MergeCollection> > &inputCollections,
0055                                bool print_pixel = false);
0056   void fill_output_obj_calo(std::unique_ptr<MergeCollection> &output,
0057                             std::vector<edm::Handle<MergeCollection> > &inputCollections);
0058   void fill_output_obj_muonchamber(std::unique_ptr<MergeCollection> &output,
0059                                    std::vector<edm::Handle<MergeCollection> > &inputCollections);
0060 };
0061 
0062 template <typename T1, typename T2>
0063 CollectionMerger<T1, T2>::CollectionMerger(const edm::ParameterSet &iConfig) {
0064   std::vector<edm::InputTag> inCollections = iConfig.getParameter<std::vector<edm::InputTag> >("mergCollections");
0065   for (auto const &inCollection : inCollections) {
0066     inputs_[inCollection.instance()].push_back(consumes<MergeCollection>(inCollection));
0067   }
0068   for (const auto &toproduce : inputs_) {
0069     //  std::cout<<toproduce.first<<"\t"<<toproduce.second.size()<<std::endl;
0070     produces<MergeCollection>(toproduce.first);
0071   }
0072 }
0073 
0074 template <typename T1, typename T2>
0075 CollectionMerger<T1, T2>::~CollectionMerger() {
0076   // nothing to be done yet...
0077 }
0078 
0079 template <typename T1, typename T2>
0080 void CollectionMerger<T1, T2>::produce(edm::Event &iEvent, const edm::EventSetup &iSetup) {
0081   for (auto input_ : inputs_) {
0082     std::unique_ptr<MergeCollection> output(new MergeCollection());
0083     std::vector<edm::Handle<MergeCollection> > inputCollections;
0084     inputCollections.resize(input_.second.size());
0085     for (unsigned id = 0; id < input_.second.size(); id++) {
0086       iEvent.getByToken(input_.second[id], inputCollections[id]);
0087     }
0088     fill_output_obj(output, inputCollections);
0089     iEvent.put(std::move(output), input_.first);
0090   }
0091 }
0092 #endif