Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-05-08 23:19:19

0001 /** SiPixelClusterProducer.cc
0002  * ---------------------------------------------------------------
0003  * Description:  see SiPixelClusterProducer.h
0004  * Author:  P. Maksimovic (porting from original ORCA version)
0005  * History: Oct 14, 2005, initial version
0006  * Get rid of the noiseVector. d.k. 28/3/06
0007  * Implementation of the DetSetVector container.    V.Chiochia, May 06
0008  * SiPixelClusterCollection typedef of DetSetVector V.Chiochia, June 06
0009  * Introduce the DetSet local container (cache) for speed. d.k. 05/07
0010  * 
0011  * ---------------------------------------------------------------
0012  */
0013 
0014 // Our own stuff
0015 #include "SiPixelClusterProducer.h"
0016 #include "PixelThresholdClusterizer.h"
0017 
0018 // Geometry
0019 #include "Geometry/CommonDetUnit/interface/PixelGeomDetUnit.h"
0020 
0021 // Data Formats
0022 #include "DataFormats/Common/interface/DetSetVector.h"
0023 #include "DataFormats/SiPixelDigi/interface/PixelDigi.h"
0024 #include "DataFormats/DetId/interface/DetId.h"
0025 
0026 // Database payloads
0027 #include "CalibTracker/SiPixelESProducers/interface/SiPixelGainCalibrationService.h"
0028 #include "CalibTracker/SiPixelESProducers/interface/SiPixelGainCalibrationOfflineService.h"
0029 #include "CalibTracker/SiPixelESProducers/interface/SiPixelGainCalibrationForHLTService.h"
0030 
0031 // Framework
0032 #include "DataFormats/Common/interface/Handle.h"
0033 #include "FWCore/Framework/interface/ESHandle.h"
0034 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0035 
0036 // STL
0037 #include <vector>
0038 #include <memory>
0039 #include <string>
0040 #include <iostream>
0041 
0042 // MessageLogger
0043 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0044 
0045 //---------------------------------------------------------------------------
0046 //!  Constructor: set the ParameterSet and defer all thinking to setupClusterizer().
0047 //---------------------------------------------------------------------------
0048 SiPixelClusterProducer::SiPixelClusterProducer(edm::ParameterSet const& conf)
0049     : tPutPixelClusters(produces<SiPixelClusterCollectionNew>()),
0050       clusterMode_(conf.getParameter<std::string>("ClusterMode")),
0051       maxTotalClusters_(conf.getParameter<int32_t>("maxNumberOfClusters")) {
0052   if (clusterMode_ == "PixelThresholdReclusterizer")
0053     tPixelClusters = consumes<SiPixelClusterCollectionNew>(conf.getParameter<edm::InputTag>("src"));
0054   else
0055     tPixelDigi = consumes<edm::DetSetVector<PixelDigi>>(conf.getParameter<edm::InputTag>("src"));
0056 
0057   trackerTopoToken_ = esConsumes<TrackerTopology, TrackerTopologyRcd>();
0058   trackerGeomToken_ = esConsumes<TrackerGeometry, TrackerDigiGeometryRecord>();
0059 
0060   const auto& payloadType = conf.getParameter<std::string>("payloadType");
0061   if (payloadType == "HLT")
0062     theSiPixelGainCalibration_ = std::make_unique<SiPixelGainCalibrationForHLTService>(conf, consumesCollector());
0063   else if (payloadType == "Offline")
0064     theSiPixelGainCalibration_ = std::make_unique<SiPixelGainCalibrationOfflineService>(conf, consumesCollector());
0065   else if (payloadType == "Full")
0066     theSiPixelGainCalibration_ = std::make_unique<SiPixelGainCalibrationService>(conf, consumesCollector());
0067 
0068   //--- Make the algorithm(s) according to what the user specified
0069   //--- in the ParameterSet.
0070   setupClusterizer(conf);
0071 }
0072 
0073 // Destructor
0074 SiPixelClusterProducer::~SiPixelClusterProducer() = default;
0075 
0076 void SiPixelClusterProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0077   edm::ParameterSetDescription desc;
0078 
0079   desc.add<edm::InputTag>("src", edm::InputTag("siPixelDigis"));
0080   desc.add<std::string>("ClusterMode", "PixelThresholdClusterizer");
0081   desc.add<int>("maxNumberOfClusters", -1)->setComment("-1 means no limit");
0082   desc.add<std::string>("payloadType", "Offline")
0083       ->setComment("Options: HLT - column granularity, Offline - gain:col/ped:pix");
0084 
0085   PixelThresholdClusterizer::fillPSetDescription(desc);
0086   SiPixelGainCalibrationServiceBase::fillPSetDescription(desc);  // no-op, but in principle the structures are there...
0087 
0088   descriptions.add("SiPixelClusterizerDefault", desc);
0089 }
0090 
0091 //---------------------------------------------------------------------------
0092 //! The "Event" entrypoint: gets called by framework for every event
0093 //---------------------------------------------------------------------------
0094 void SiPixelClusterProducer::produce(edm::Event& e, const edm::EventSetup& es) {
0095   //Setup gain calibration service
0096   theSiPixelGainCalibration_->setESObjects(es);
0097 
0098   // Step A.1: get input data
0099   edm::Handle<SiPixelClusterCollectionNew> inputClusters;
0100   edm::Handle<edm::DetSetVector<PixelDigi>> inputDigi;
0101   if (clusterMode_ == "PixelThresholdReclusterizer")
0102     e.getByToken(tPixelClusters, inputClusters);
0103   else
0104     e.getByToken(tPixelDigi, inputDigi);
0105 
0106   // Step A.2: get event setup
0107   edm::ESHandle<TrackerGeometry> geom = es.getHandle(trackerGeomToken_);
0108 
0109   edm::ESHandle<TrackerTopology> trackerTopologyHandle = es.getHandle(trackerTopoToken_);
0110   tTopo_ = trackerTopologyHandle.product();
0111 
0112   // Step B: create the final output collection
0113   auto output = std::make_unique<SiPixelClusterCollectionNew>();
0114   //FIXME: put a reserve() here
0115 
0116   // Step C: Iterate over DetIds and invoke the pixel clusterizer algorithm
0117   // on each DetUnit
0118   if (clusterMode_ == "PixelThresholdReclusterizer")
0119     run(*inputClusters, geom, *output);
0120   else
0121     run(*inputDigi, geom, *output);
0122 
0123   // Step D: write output to file
0124   output->shrink_to_fit();
0125 
0126   // set sequential identifier
0127   for (auto& clusters : *output) {
0128     uint16_t id = 0;
0129     for (auto& cluster : clusters) {
0130       cluster.setOriginalId(id++);
0131     }
0132   }
0133   e.put(tPutPixelClusters, std::move(output));
0134 }
0135 
0136 //---------------------------------------------------------------------------
0137 //!  Set up the specific algorithm we are going to use.
0138 //!  TO DO: in the future, we should allow for a different algorithm for
0139 //!  each detector subset (e.g. barrel vs forward, per layer, etc).
0140 //---------------------------------------------------------------------------
0141 void SiPixelClusterProducer::setupClusterizer(const edm::ParameterSet& conf) {
0142   if (clusterMode_ == "PixelThresholdReclusterizer" || clusterMode_ == "PixelThresholdClusterizer") {
0143     clusterizer_ = std::make_unique<PixelThresholdClusterizer>(conf);
0144     clusterizer_->setSiPixelGainCalibrationService(theSiPixelGainCalibration_.get());
0145   } else {
0146     throw cms::Exception("Configuration") << "[SiPixelClusterProducer]:"
0147                                           << " choice " << clusterMode_ << " is invalid.\n"
0148                                           << "Possible choices:\n"
0149                                           << "    PixelThresholdClusterizer";
0150   }
0151 }
0152 
0153 //---------------------------------------------------------------------------
0154 //!  Iterate over DetUnits, and invoke the PixelClusterizer on each.
0155 //---------------------------------------------------------------------------
0156 template <typename T>
0157 void SiPixelClusterProducer::run(const T& input,
0158                                  const edm::ESHandle<TrackerGeometry>& geom,
0159                                  edmNew::DetSetVector<SiPixelCluster>& output) {
0160   int numberOfClusters = 0;
0161 
0162   // Iterate on detector units
0163   for (auto const& dsv : input) {
0164     //  LogDebug takes very long time, get rid off.
0165     //LogDebug("SiStripClusterizer") << "[SiPixelClusterProducer::run] DetID" << dsv.id;
0166 
0167     std::vector<short> badChannels;
0168     DetId detIdObject(dsv.detId());
0169 
0170     // Comment: At the moment the clusterizer depends on geometry
0171     // to access information as the pixel topology (number of columns
0172     // and rows in a detector module).
0173     // In the future the geometry service will be replaced with
0174     // a ES service.
0175     const GeomDetUnit* geoUnit = geom->idToDetUnit(detIdObject);
0176     const PixelGeomDetUnit* pixDet = dynamic_cast<const PixelGeomDetUnit*>(geoUnit);
0177     if (!pixDet) {
0178       // Fatal error!  TO DO: throw an exception!
0179       assert(0);
0180     }
0181     {
0182       // Produce clusters for this DetUnit and store them in
0183       // a DetSet
0184       edmNew::DetSetVector<SiPixelCluster>::FastFiller spc(output, dsv.detId());
0185       clusterizer_->clusterizeDetUnit(dsv, pixDet, tTopo_, badChannels, spc);
0186       if (spc.empty()) {
0187         spc.abort();
0188       } else {
0189         numberOfClusters += spc.size();
0190       }
0191     }  // spc is not deleted and detsetvector updated
0192     if ((maxTotalClusters_ >= 0) && (numberOfClusters > maxTotalClusters_)) {
0193       edm::LogError("TooManyClusters")
0194           << "Limit on the number of clusters exceeded. An empty cluster collection will be produced instead.\n";
0195       edmNew::DetSetVector<SiPixelCluster> empty;
0196       empty.swap(output);
0197       break;
0198     }
0199   }  // end of DetUnit loop
0200 }
0201 
0202 #include "FWCore/PluginManager/interface/ModuleDef.h"
0203 #include "FWCore/Framework/interface/MakerMacros.h"
0204 
0205 DEFINE_FWK_MODULE(SiPixelClusterProducer);