Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:26: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 
0062   if (payloadType == "HLT")
0063     theSiPixelGainCalibration_ = std::make_unique<SiPixelGainCalibrationForHLTService>(conf, consumesCollector());
0064   else if (payloadType == "Offline")
0065     theSiPixelGainCalibration_ = std::make_unique<SiPixelGainCalibrationOfflineService>(conf, consumesCollector());
0066   else if (payloadType == "Full")
0067     theSiPixelGainCalibration_ = std::make_unique<SiPixelGainCalibrationService>(conf, consumesCollector());
0068   else if (payloadType == "None")
0069     theSiPixelGainCalibration_ = nullptr;
0070 
0071   //--- Make the algorithm(s) according to what the user specified
0072   //--- in the ParameterSet.
0073   setupClusterizer(conf);
0074 }
0075 
0076 // Destructor
0077 SiPixelClusterProducer::~SiPixelClusterProducer() = default;
0078 
0079 void SiPixelClusterProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0080   edm::ParameterSetDescription desc;
0081 
0082   desc.add<edm::InputTag>("src", edm::InputTag("siPixelDigis"));
0083   desc.add<std::string>("ClusterMode", "PixelThresholdClusterizer");
0084   desc.add<int>("maxNumberOfClusters", -1)->setComment("-1 means no limit");
0085   desc.add<std::string>("payloadType", "Offline")
0086       ->setComment("Options: HLT - column granularity, Offline - gain:col/ped:pix, None: no gain calibrations");
0087 
0088   PixelThresholdClusterizer::fillPSetDescription(desc);
0089   SiPixelGainCalibrationServiceBase::fillPSetDescription(desc);  // no-op, but in principle the structures are there...
0090 
0091   descriptions.add("SiPixelClusterizerDefault", desc);
0092 }
0093 
0094 //---------------------------------------------------------------------------
0095 //! The "Event" entrypoint: gets called by framework for every event
0096 //---------------------------------------------------------------------------
0097 void SiPixelClusterProducer::produce(edm::Event& e, const edm::EventSetup& es) {
0098   //Setup gain calibration service
0099   if (theSiPixelGainCalibration_.get())
0100     theSiPixelGainCalibration_->setESObjects(es);
0101 
0102   // Step A.1: get input data
0103   edm::Handle<SiPixelClusterCollectionNew> inputClusters;
0104   edm::Handle<edm::DetSetVector<PixelDigi>> inputDigi;
0105   if (clusterMode_ == "PixelThresholdReclusterizer")
0106     e.getByToken(tPixelClusters, inputClusters);
0107   else
0108     e.getByToken(tPixelDigi, inputDigi);
0109 
0110   // Step A.2: get event setup
0111   edm::ESHandle<TrackerGeometry> geom = es.getHandle(trackerGeomToken_);
0112 
0113   edm::ESHandle<TrackerTopology> trackerTopologyHandle = es.getHandle(trackerTopoToken_);
0114   tTopo_ = trackerTopologyHandle.product();
0115 
0116   // Step B: create the final output collection
0117   auto output = std::make_unique<SiPixelClusterCollectionNew>();
0118   //FIXME: put a reserve() here
0119 
0120   // Step C: Iterate over DetIds and invoke the pixel clusterizer algorithm
0121   // on each DetUnit
0122   if (clusterMode_ == "PixelThresholdReclusterizer")
0123     run(*inputClusters, geom, *output);
0124   else
0125     run(*inputDigi, geom, *output);
0126 
0127   // Step D: write output to file
0128   output->shrink_to_fit();
0129 
0130   // set sequential identifier
0131   for (auto clusters : *output) {
0132     uint16_t id = 0;
0133     for (auto& cluster : clusters) {
0134       cluster.setOriginalId(id++);
0135     }
0136   }
0137   e.put(tPutPixelClusters, std::move(output));
0138 }
0139 
0140 //---------------------------------------------------------------------------
0141 //!  Set up the specific algorithm we are going to use.
0142 //!  TO DO: in the future, we should allow for a different algorithm for
0143 //!  each detector subset (e.g. barrel vs forward, per layer, etc).
0144 //---------------------------------------------------------------------------
0145 void SiPixelClusterProducer::setupClusterizer(const edm::ParameterSet& conf) {
0146   if (clusterMode_ == "PixelThresholdReclusterizer" || clusterMode_ == "PixelThresholdClusterizer") {
0147     clusterizer_ = std::make_unique<PixelThresholdClusterizer>(conf);
0148     if (theSiPixelGainCalibration_.get()) {
0149       clusterizer_->setSiPixelGainCalibrationService(theSiPixelGainCalibration_.get());
0150     }
0151   } else {
0152     throw cms::Exception("Configuration") << "[SiPixelClusterProducer]:"
0153                                           << " choice " << clusterMode_ << " is invalid.\n"
0154                                           << "Possible choices:\n"
0155                                           << "    PixelThresholdClusterizer";
0156   }
0157 }
0158 
0159 //---------------------------------------------------------------------------
0160 //!  Iterate over DetUnits, and invoke the PixelClusterizer on each.
0161 //---------------------------------------------------------------------------
0162 template <typename T>
0163 void SiPixelClusterProducer::run(const T& input,
0164                                  const edm::ESHandle<TrackerGeometry>& geom,
0165                                  edmNew::DetSetVector<SiPixelCluster>& output) {
0166   int numberOfClusters = 0;
0167 
0168   // Iterate on detector units
0169   for (auto const& dsv : input) {
0170     //  LogDebug takes very long time, get rid off.
0171     //LogDebug("SiStripClusterizer") << "[SiPixelClusterProducer::run] DetID" << dsv.id;
0172 
0173     std::vector<short> badChannels;
0174     DetId detIdObject(dsv.detId());
0175 
0176     // Comment: At the moment the clusterizer depends on geometry
0177     // to access information as the pixel topology (number of columns
0178     // and rows in a detector module).
0179     // In the future the geometry service will be replaced with
0180     // a ES service.
0181     const GeomDetUnit* geoUnit = geom->idToDetUnit(detIdObject);
0182     const PixelGeomDetUnit* pixDet = dynamic_cast<const PixelGeomDetUnit*>(geoUnit);
0183     if (!pixDet) {
0184       // Fatal error!  TO DO: throw an exception!
0185       assert(0);
0186     }
0187     {
0188       // Produce clusters for this DetUnit and store them in
0189       // a DetSet
0190       edmNew::DetSetVector<SiPixelCluster>::FastFiller spc(output, dsv.detId());
0191       clusterizer_->clusterizeDetUnit(dsv, pixDet, tTopo_, badChannels, spc);
0192       if (spc.empty()) {
0193         spc.abort();
0194       } else {
0195         numberOfClusters += spc.size();
0196       }
0197     }  // spc is not deleted and detsetvector updated
0198     if ((maxTotalClusters_ >= 0) && (numberOfClusters > maxTotalClusters_)) {
0199       edm::LogError("TooManyClusters")
0200           << "Limit on the number of clusters exceeded. An empty cluster collection will be produced instead.\n";
0201       edmNew::DetSetVector<SiPixelCluster> empty;
0202       empty.swap(output);
0203       break;
0204     }
0205   }  // end of DetUnit loop
0206 }
0207 
0208 #include "PixelThresholdClusterizer.icc"
0209 #include "FWCore/PluginManager/interface/ModuleDef.h"
0210 #include "FWCore/Framework/interface/MakerMacros.h"
0211 
0212 DEFINE_FWK_MODULE(SiPixelClusterProducer);