Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:25:01

0001 #include "FWCore/Framework/interface/Event.h"
0002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0003 #include "FWCore/Framework/interface/MakerMacros.h"
0004 #include "FWCore/Framework/interface/stream/EDProducer.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 
0007 #include "RecoLocalTracker/SiPhase2VectorHitBuilder/interface/VectorHitBuilderAlgorithmBase.h"
0008 #include "DataFormats/Phase2TrackerCluster/interface/Phase2TrackerCluster1D.h"
0009 #include "RecoLocalTracker/SiPhase2VectorHitBuilder/interface/VectorHitBuilderAlgorithm.h"
0010 #include "DataFormats/TrackerRecHit2D/interface/VectorHit.h"
0011 #include "RecoLocalTracker/Records/interface/TkPhase2OTCPERecord.h"
0012 
0013 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0014 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0015 
0016 class VectorHitBuilderEDProducer : public edm::stream::EDProducer<> {
0017 public:
0018   explicit VectorHitBuilderEDProducer(const edm::ParameterSet&);
0019   ~VectorHitBuilderEDProducer() override = default;
0020   void produce(edm::Event&, const edm::EventSetup&) override;
0021   void run(edm::Handle<edmNew::DetSetVector<Phase2TrackerCluster1D>> clusters,
0022            edmNew::DetSetVector<Phase2TrackerCluster1D>& clustersAcc,
0023            edmNew::DetSetVector<Phase2TrackerCluster1D>& clustersRej,
0024            VectorHitCollection& outputAcc,
0025            VectorHitCollection& outputRej);
0026   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0027   const VectorHitBuilderAlgorithm* algo() const { return stubsBuilder_; }
0028 
0029 private:
0030   const VectorHitBuilderAlgorithm* stubsBuilder_;
0031   std::string offlinestubsTag_;
0032   unsigned int maxOfflinestubs_;
0033   edm::ESGetToken<VectorHitBuilderAlgorithm, TkPhase2OTCPERecord> stubsBuilderToken_;
0034   edm::EDGetTokenT<edmNew::DetSetVector<Phase2TrackerCluster1D>> clusterProducer_;
0035 };
0036 
0037 VectorHitBuilderEDProducer::VectorHitBuilderEDProducer(edm::ParameterSet const& conf)
0038     : offlinestubsTag_(conf.getParameter<std::string>("offlinestubs")),
0039       maxOfflinestubs_(conf.getParameter<int>("maxVectorHits")),
0040       stubsBuilderToken_(esConsumes(conf.getParameter<edm::ESInputTag>("Algorithm"))) {
0041   clusterProducer_ =
0042       consumes<edmNew::DetSetVector<Phase2TrackerCluster1D>>(edm::InputTag(conf.getParameter<std::string>("Clusters")));
0043 
0044   produces<edmNew::DetSetVector<Phase2TrackerCluster1D>>("accepted");
0045   produces<edmNew::DetSetVector<Phase2TrackerCluster1D>>("rejected");
0046   produces<VectorHitCollection>("accepted");
0047   produces<VectorHitCollection>("rejected");
0048 }
0049 
0050 void VectorHitBuilderEDProducer::produce(edm::Event& event, const edm::EventSetup& es) {
0051   LogDebug("VectorHitBuilderEDProducer") << "VectorHitBuilderEDProducer::produce() begin";
0052 
0053   // get input clusters data
0054   auto clustersHandle = event.getHandle(clusterProducer_);
0055   // create the final output collection
0056   auto outputClustersAccepted = std::make_unique<edmNew::DetSetVector<Phase2TrackerCluster1D>>();
0057   auto outputClustersRejected = std::make_unique<edmNew::DetSetVector<Phase2TrackerCluster1D>>();
0058   std::unique_ptr<VectorHitCollection> outputVHAccepted(new VectorHitCollection());
0059   std::unique_ptr<VectorHitCollection> outputVHRejected(new VectorHitCollection());
0060 
0061   stubsBuilder_ = &es.getData(stubsBuilderToken_);
0062 #ifdef EDM_ML_DEBUG
0063   // check on the input clusters
0064   stubsBuilder_->printClusters(*clustersHandle);
0065 #endif  //EDM_ML_DEBUG
0066 
0067   // running the stub building algorithm
0068   //ERICA::output should be moved in the different algo classes?
0069   run(clustersHandle, *outputClustersAccepted, *outputClustersRejected, *outputVHAccepted, *outputVHRejected);
0070 #ifdef EDM_ML_DEBUG
0071   unsigned int numberOfVectorHits = 0;
0072   for (const auto& dSViter : *outputVHAccepted) {
0073     for (const auto& vh : dSViter) {
0074       numberOfVectorHits++;
0075       LogDebug("VectorHitBuilderEDProducer") << "\t vectorhit in output " << vh;
0076     }
0077   }
0078   LogDebug("VectorHitBuilderEDProducer") << "found\n" << numberOfVectorHits << " .\n";
0079 #endif  //EDM_ML_DEBUG
0080   // write output to file
0081   event.put(std::move(outputClustersAccepted), "accepted");
0082   event.put(std::move(outputClustersRejected), "rejected");
0083   event.put(std::move(outputVHAccepted), "accepted");
0084   event.put(std::move(outputVHRejected), "rejected");
0085 }
0086 
0087 void VectorHitBuilderEDProducer::run(edm::Handle<edmNew::DetSetVector<Phase2TrackerCluster1D>> clusters,
0088                                      edmNew::DetSetVector<Phase2TrackerCluster1D>& clustersAcc,
0089                                      edmNew::DetSetVector<Phase2TrackerCluster1D>& clustersRej,
0090                                      VectorHitCollection& outputAcc,
0091                                      VectorHitCollection& outputRej) {
0092   stubsBuilder_->run(clusters, outputAcc, outputRej, clustersAcc, clustersRej);
0093 }
0094 void VectorHitBuilderEDProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0095   edm::ParameterSetDescription desc;
0096   desc.add<std::string>("offlinestubs", "vectorHits");
0097   desc.add<int>("maxVectorHits", 999999999);
0098   desc.add<edm::ESInputTag>("Algorithm", edm::ESInputTag("", "SiPhase2VectorHitMatcher"));
0099   desc.add<edm::ESInputTag>("CPE", edm::ESInputTag("phase2StripCPEESProducer", "Phase2StripCPE"));
0100   desc.add<std::vector<double>>("BarrelCut",
0101                                 {
0102                                     0.0,
0103                                     0.05,
0104                                     0.06,
0105                                     0.08,
0106                                     0.09,
0107                                     0.12,
0108                                     0.2,
0109                                 });
0110   desc.add<std::string>("Clusters", "siPhase2Clusters");
0111   desc.add<int>("maxVectorHitsInAStack", 999);
0112   desc.add<std::vector<double>>("EndcapCut",
0113                                 {
0114                                     0.0,
0115                                     0.1,
0116                                     0.1,
0117                                     0.1,
0118                                     0.1,
0119                                     0.1,
0120                                 });
0121   descriptions.add("siPhase2VectorHits", desc);
0122 }
0123 DEFINE_FWK_MODULE(VectorHitBuilderEDProducer);
0124 #include "FWCore/Utilities/interface/typelookup.h"
0125 TYPELOOKUP_DATA_REG(VectorHitBuilderEDProducer);