Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:43:48

0001 /**_________________________________________________________________
0002 class:   AlcaPCCEventProducer.cc
0003 
0004 
0005 
0006 authors: Sam Higginbotham (shigginb@cern.ch), Chris Palmer (capalmer@cern.ch), Attila Radl (attila.radl@cern.ch)
0007 
0008 ________________________________________________________________**/
0009 
0010 // C++ standard
0011 #include <string>
0012 // CMS
0013 #include "DataFormats/SiPixelCluster/interface/SiPixelCluster.h"
0014 #include "DataFormats/DetId/interface/DetId.h"
0015 #include "DataFormats/Luminosity/interface/PixelClusterCountsInEvent.h"
0016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0017 #include "FWCore/Framework/interface/MakerMacros.h"
0018 #include "FWCore/Framework/interface/ConsumesCollector.h"
0019 #include "FWCore/Framework/interface/Frameworkfwd.h"
0020 #include "FWCore/Framework/interface/stream/EDProducer.h"
0021 #include "FWCore/Framework/interface/Event.h"
0022 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0023 #include "FWCore/Utilities/interface/EDGetToken.h"
0024 #include "FWCore/ServiceRegistry/interface/Service.h"
0025 #include "FWCore/Framework/interface/ESHandle.h"
0026 #include "FWCore/Framework/interface/EventSetup.h"
0027 #include "FWCore/Framework/interface/LuminosityBlock.h"
0028 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0029 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0030 #include "TMath.h"
0031 //The class
0032 class AlcaPCCEventProducer : public edm::stream::EDProducer<> {
0033 public:
0034   explicit AlcaPCCEventProducer(const edm::ParameterSet&);
0035   ~AlcaPCCEventProducer() override;
0036   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0037 
0038 private:
0039   void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
0040 
0041   edm::EDGetTokenT<edmNew::DetSetVector<SiPixelCluster> > pixelToken;
0042   edm::InputTag fPixelClusterLabel;
0043 
0044   std::string trigstring_;  //specifies the trigger Rand or ZeroBias
0045   int countEvt_;            //counter
0046   int countLumi_;           //counter
0047 
0048   std::unique_ptr<reco::PixelClusterCountsInEvent> thePCCob;
0049 };
0050 
0051 //--------------------------------------------------------------------------------------------------
0052 AlcaPCCEventProducer::AlcaPCCEventProducer(const edm::ParameterSet& iConfig) {
0053   fPixelClusterLabel = iConfig.getParameter<edm::InputTag>("pixelClusterLabel");
0054   trigstring_ = iConfig.getUntrackedParameter<std::string>("trigstring", "alcaPCCEvent");
0055   produces<reco::PixelClusterCountsInEvent, edm::Transition::Event>(trigstring_);
0056   pixelToken = consumes<edmNew::DetSetVector<SiPixelCluster> >(fPixelClusterLabel);
0057 }
0058 
0059 //--------------------------------------------------------------------------------------------------
0060 AlcaPCCEventProducer::~AlcaPCCEventProducer() {}
0061 
0062 //--------------------------------------------------------------------------------------------------
0063 void AlcaPCCEventProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0064   countEvt_++;
0065   thePCCob = std::make_unique<reco::PixelClusterCountsInEvent>();
0066 
0067   unsigned int bx = iEvent.bunchCrossing();
0068 
0069   //Looping over the clusters and adding the counts up
0070   edm::Handle<edmNew::DetSetVector<SiPixelCluster> > hClusterColl;
0071   iEvent.getByToken(pixelToken, hClusterColl);
0072 
0073   const edmNew::DetSetVector<SiPixelCluster>& clustColl = *(hClusterColl.product());
0074   // ----------------------------------------------------------------------
0075   // -- Clusters without tracks
0076   for (auto const& mod : clustColl) {
0077     if (mod.empty()) {
0078       continue;
0079     }
0080     DetId detId = mod.id();
0081 
0082     //--The following will be used when we make a theshold for the clusters.
0083     //--Keeping this for features that may be implemented later.
0084     // -- clusters on this det
0085     //edmNew::DetSet<SiPixelCluster>::const_iterator  di;
0086     //int nClusterCount=0;
0087     //for (di = mod.begin(); di != mod.end(); ++di) {
0088     //    nClusterCount++;
0089     //}
0090     int nCluster = mod.size();
0091     thePCCob->increment(detId(), nCluster);
0092     thePCCob->setbxID(bx);
0093   }
0094 
0095   iEvent.put(std::move(thePCCob), std::string(trigstring_));
0096 }
0097 
0098 //--------------------------------------------------------------------------------------------------
0099 void AlcaPCCEventProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0100   edm::ParameterSetDescription evtParamDesc;
0101   evtParamDesc.add<edm::InputTag>("pixelClusterLabel", edm::InputTag("siPixelClustersForLumi"));
0102   evtParamDesc.addUntracked<std::string>("trigstring", "alcaPCCEvent");
0103   descriptions.add("alcaPCCEventProducer", evtParamDesc);
0104 }
0105 
0106 DEFINE_FWK_MODULE(AlcaPCCEventProducer);