CMS 3D CMS Logo

SiPixelClusterProducer.cc
Go to the documentation of this file.
1 
14 // Our own stuff
15 #include "SiPixelClusterProducer.h"
17 
18 // Geometry
21 
22 // Data Formats
26 
27 // Database payloads
31 
32 // Framework
36 
37 // STL
38 #include <vector>
39 #include <memory>
40 #include <string>
41 #include <iostream>
42 
43 // MessageLogger
45 
46 //---------------------------------------------------------------------------
48 //---------------------------------------------------------------------------
50  : tPutPixelClusters(produces<SiPixelClusterCollectionNew>()),
51  clusterMode_(conf.getParameter<std::string>("ClusterMode")),
52  maxTotalClusters_(conf.getParameter<int32_t>("maxNumberOfClusters")) {
53  if (clusterMode_ == "PixelThresholdReclusterizer")
54  tPixelClusters = consumes<SiPixelClusterCollectionNew>(conf.getParameter<edm::InputTag>("src"));
55  else
56  tPixelDigi = consumes<edm::DetSetVector<PixelDigi>>(conf.getParameter<edm::InputTag>("src"));
57 
58  const auto& payloadType = conf.getParameter<std::string>("payloadType");
59  if (payloadType == "HLT")
60  theSiPixelGainCalibration_ = std::make_unique<SiPixelGainCalibrationForHLTService>(conf);
61  else if (payloadType == "Offline")
62  theSiPixelGainCalibration_ = std::make_unique<SiPixelGainCalibrationOfflineService>(conf);
63  else if (payloadType == "Full")
64  theSiPixelGainCalibration_ = std::make_unique<SiPixelGainCalibrationService>(conf);
65 
66  //--- Make the algorithm(s) according to what the user specified
67  //--- in the ParameterSet.
68  setupClusterizer(conf);
69 }
70 
71 // Destructor
73 
76 
77  desc.add<edm::InputTag>("src", edm::InputTag("siPixelDigis"));
78  desc.add<std::string>("ClusterMode", "PixelThresholdClusterizer");
79  desc.add<int>("maxNumberOfClusters", -1)->setComment("-1 means no limit");
80  desc.add<std::string>("payloadType", "Offline")
81  ->setComment("Options: HLT - column granularity, Offline - gain:col/ped:pix");
82 
84  SiPixelGainCalibrationServiceBase::fillPSetDescription(desc); // no-op, but in principle the structures are there...
85 
86  descriptions.add("SiPixelClusterizerDefault", desc);
87 }
88 
89 //---------------------------------------------------------------------------
91 //---------------------------------------------------------------------------
93  //Setup gain calibration service
94  theSiPixelGainCalibration_->setESObjects(es);
95 
96  // Step A.1: get input data
99  if (clusterMode_ == "PixelThresholdReclusterizer")
100  e.getByToken(tPixelClusters, inputClusters);
101  else
102  e.getByToken(tPixelDigi, inputDigi);
103 
104  // Step A.2: get event setup
106  es.get<TrackerDigiGeometryRecord>().get(geom);
107 
108  edm::ESHandle<TrackerTopology> trackerTopologyHandle;
109  es.get<TrackerTopologyRcd>().get(trackerTopologyHandle);
110  tTopo_ = trackerTopologyHandle.product();
111 
112  // Step B: create the final output collection
113  auto output = std::make_unique<SiPixelClusterCollectionNew>();
114  //FIXME: put a reserve() here
115 
116  // Step C: Iterate over DetIds and invoke the pixel clusterizer algorithm
117  // on each DetUnit
118  if (clusterMode_ == "PixelThresholdReclusterizer")
119  run(*inputClusters, geom, *output);
120  else
121  run(*inputDigi, geom, *output);
122 
123  // Step D: write output to file
124  output->shrink_to_fit();
126 }
127 
128 //---------------------------------------------------------------------------
132 //---------------------------------------------------------------------------
134  if (clusterMode_ == "PixelThresholdReclusterizer" || clusterMode_ == "PixelThresholdClusterizer") {
135  clusterizer_ = std::make_unique<PixelThresholdClusterizer>(conf);
136  clusterizer_->setSiPixelGainCalibrationService(theSiPixelGainCalibration_.get());
137  } else {
138  throw cms::Exception("Configuration") << "[SiPixelClusterProducer]:"
139  << " choice " << clusterMode_ << " is invalid.\n"
140  << "Possible choices:\n"
141  << " PixelThresholdClusterizer";
142  }
143 }
144 
145 //---------------------------------------------------------------------------
147 //---------------------------------------------------------------------------
148 template <typename T>
152  int numberOfDetUnits = 0;
153  int numberOfClusters = 0;
154 
155  // Iterate on detector units
156  typename T::const_iterator DSViter = input.begin();
157  for (; DSViter != input.end(); DSViter++) {
158  ++numberOfDetUnits;
159 
160  // LogDebug takes very long time, get rid off.
161  //LogDebug("SiStripClusterizer") << "[SiPixelClusterProducer::run] DetID" << DSViter->id;
162 
163  std::vector<short> badChannels;
164  DetId detIdObject(DSViter->detId());
165 
166  // Comment: At the moment the clusterizer depends on geometry
167  // to access information as the pixel topology (number of columns
168  // and rows in a detector module).
169  // In the future the geometry service will be replaced with
170  // a ES service.
171  const GeomDetUnit* geoUnit = geom->idToDetUnit(detIdObject);
172  const PixelGeomDetUnit* pixDet = dynamic_cast<const PixelGeomDetUnit*>(geoUnit);
173  if (!pixDet) {
174  // Fatal error! TO DO: throw an exception!
175  assert(0);
176  }
177  {
178  // Produce clusters for this DetUnit and store them in
179  // a DetSet
180  edmNew::DetSetVector<SiPixelCluster>::FastFiller spc(output, DSViter->detId());
181  clusterizer_->clusterizeDetUnit(*DSViter, pixDet, tTopo_, badChannels, spc);
182  if (spc.empty()) {
183  spc.abort();
184  } else {
185  numberOfClusters += spc.size();
186  }
187  } // spc is not deleted and detsetvector updated
188  if ((maxTotalClusters_ >= 0) && (numberOfClusters > maxTotalClusters_)) {
189  edm::LogError("TooManyClusters")
190  << "Limit on the number of clusters exceeded. An empty cluster collection will be produced instead.\n";
192  empty.swap(output);
193  break;
194  }
195  } // end of DetUnit loop
196 
197  //LogDebug ("SiPixelClusterProducer") << " Executing "
198  // << clusterMode_ << " resulted in " << numberOfClusters
199  // << " SiPixelClusters in " << numberOfDetUnits << " DetUnits.";
200 }
201 
204 
T getParameter(std::string const &) const
static void fillPSetDescription(edm::ParameterSetDescription &desc)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
void swap(DetSetVector &rh)
static std::string const input
Definition: EdmProvDump.cc:48
const TrackerGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
std::unique_ptr< PixelClusterizerBase > clusterizer_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
SiPixelClusterProducer(const edm::ParameterSet &conf)
Constructor: set the ParameterSet and defer all thinking to setupClusterizer().
std::unique_ptr< SiPixelGainCalibrationServiceBase > theSiPixelGainCalibration_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
edm::EDPutTokenT< SiPixelClusterCollectionNew > tPutPixelClusters
const int32_t maxTotalClusters_
Optional limit on the total number of clusters.
EDProducer to cluster PixelDigis into SiPixelClusters.
static void fillPSetDescription(edm::ParameterSetDescription &desc)
Definition: DetId.h:17
void produce(edm::Event &e, const edm::EventSetup &c) override
The "Event" entrypoint: gets called by framework for every event.
void setupClusterizer(const edm::ParameterSet &conf)
edm::EDGetTokenT< edm::DetSetVector< PixelDigi > > tPixelDigi
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::EDGetTokenT< SiPixelClusterCollectionNew > tPixelClusters
T get() const
Definition: EventSetup.h:73
~SiPixelClusterProducer() override
void run(const T &input, const edm::ESHandle< TrackerGeometry > &geom, edmNew::DetSetVector< SiPixelCluster > &output)
Iterate over DetUnits, and invoke the PixelClusterizer on each.
long double T
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
T const * product() const
Definition: ESHandle.h:86
const TrackerTopology * tTopo_
def move(src, dest)
Definition: eostools.py:511
const std::string clusterMode_