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
35 
36 // STL
37 #include <vector>
38 #include <memory>
39 #include <string>
40 #include <iostream>
41 
42 // MessageLogger
44 
45 
46  //---------------------------------------------------------------------------
48  //---------------------------------------------------------------------------
50  :
51  theSiPixelGainCalibration_(nullptr),
52  clusterMode_( conf.getUntrackedParameter<std::string>("ClusterMode","PixelThresholdClusterizer") ),
53  clusterizer_(nullptr), // the default, in case we fail to make one
54  readyToCluster_(false), // since we obviously aren't
55  maxTotalClusters_( conf.getParameter<int32_t>( "maxNumberOfClusters" ) ),
56  payloadType_( conf.getParameter<std::string>( "payloadType" ) )
57  {
58  if ( clusterMode_ == "PixelThresholdReclusterizer" )
59  tPixelClusters = consumes<SiPixelClusterCollectionNew>( conf.getParameter<edm::InputTag>("src") );
60  else
61  tPixelDigi = consumes<edm::DetSetVector<PixelDigi>>( conf.getParameter<edm::InputTag>("src") );
62  //--- Declare to the EDM what kind of collections we will be making.
63  produces<SiPixelClusterCollectionNew>();
64 
65  if (strcmp(payloadType_.c_str(), "HLT") == 0)
67  else if (strcmp(payloadType_.c_str(), "Offline") == 0)
69  else if (strcmp(payloadType_.c_str(), "Full") == 0)
71 
72  //--- Make the algorithm(s) according to what the user specified
73  //--- in the ParameterSet.
74  setupClusterizer(conf);
75 
76  }
77 
78  // Destructor
80  delete clusterizer_;
82  }
83 
84 
85  //---------------------------------------------------------------------------
87  //---------------------------------------------------------------------------
89  {
90 
91  //Setup gain calibration service
93 
94  // Step A.1: get input data
97  if ( clusterMode_ == "PixelThresholdReclusterizer" )
98  e.getByToken(tPixelClusters, inputClusters);
99  else
100  e.getByToken(tPixelDigi, inputDigi);
101 
102  // Step A.2: get event setup
104  es.get<TrackerDigiGeometryRecord>().get( geom );
105 
106  edm::ESHandle<TrackerTopology> trackerTopologyHandle;
107  es.get<TrackerTopologyRcd>().get(trackerTopologyHandle);
108  tTopo_ = trackerTopologyHandle.product();
109 
110  // Step B: create the final output collection
111  auto output = std::make_unique< SiPixelClusterCollectionNew>();
112  //FIXME: put a reserve() here
113 
114  // Step C: Iterate over DetIds and invoke the pixel clusterizer algorithm
115  // on each DetUnit
116  if ( clusterMode_ == "PixelThresholdReclusterizer" )
117  run(*inputClusters, geom, *output );
118  else
119  run(*inputDigi, geom, *output );
120 
121  // Step D: write output to file
122  output->shrink_to_fit();
123  e.put(std::move(output));
124 
125  }
126 
127  //---------------------------------------------------------------------------
131  //---------------------------------------------------------------------------
133 
134  if ( clusterMode_ == "PixelThresholdReclusterizer" || clusterMode_ == "PixelThresholdClusterizer" ) {
137  readyToCluster_ = true;
138  }
139  else {
140  edm::LogError("SiPixelClusterProducer") << "[SiPixelClusterProducer]:"
141  <<" choice " << clusterMode_ << " is invalid.\n"
142  << "Possible choices:\n"
143  << " PixelThresholdClusterizer";
144  readyToCluster_ = false;
145  }
146  }
147 
148 
149  //---------------------------------------------------------------------------
151  //---------------------------------------------------------------------------
152  template<typename T>
156  if ( ! readyToCluster_ ) {
157  edm::LogError("SiPixelClusterProducer")
158  <<" at least one clusterizer is not ready -- can't run!" ;
159  // TO DO: throw an exception here? The user may want to know...
160  return; // clusterizer is invalid, bail out
161  }
162 
163  int numberOfDetUnits = 0;
164  int numberOfClusters = 0;
165 
166  // Iterate on detector units
167  typename T::const_iterator DSViter = input.begin();
168  for( ; DSViter != input.end(); DSViter++) {
169  ++numberOfDetUnits;
170 
171  // LogDebug takes very long time, get rid off.
172  //LogDebug("SiStripClusterizer") << "[SiPixelClusterProducer::run] DetID" << DSViter->id;
173 
174  std::vector<short> badChannels;
175  DetId detIdObject(DSViter->detId());
176 
177  // Comment: At the moment the clusterizer depends on geometry
178  // to access information as the pixel topology (number of columns
179  // and rows in a detector module).
180  // In the future the geometry service will be replaced with
181  // a ES service.
182  const GeomDetUnit * geoUnit = geom->idToDetUnit( detIdObject );
183  const PixelGeomDetUnit * pixDet = dynamic_cast<const PixelGeomDetUnit*>(geoUnit);
184  if (! pixDet) {
185  // Fatal error! TO DO: throw an exception!
186  assert(0);
187  }
188  {
189  // Produce clusters for this DetUnit and store them in
190  // a DetSet
191  edmNew::DetSetVector<SiPixelCluster>::FastFiller spc(output, DSViter->detId());
192  clusterizer_->clusterizeDetUnit(*DSViter, pixDet, tTopo_, badChannels, spc);
193  if ( spc.empty() ) {
194  spc.abort();
195  } else {
196  numberOfClusters += spc.size();
197  }
198  } // spc is not deleted and detsetvector updated
199  if ((maxTotalClusters_ >= 0) && (numberOfClusters > maxTotalClusters_)) {
200  edm::LogError("TooManyClusters") << "Limit on the number of clusters exceeded. An empty cluster collection will be produced instead.\n";
202  empty.swap(output);
203  break;
204  }
205  } // end of DetUnit loop
206 
207  //LogDebug ("SiPixelClusterProducer") << " Executing "
208  // << clusterMode_ << " resulted in " << numberOfClusters
209  // << " SiPixelClusters in " << numberOfDetUnits << " DetUnits.";
210  }
211 
212 
213 
214 
217 
219 
PixelClusterizerBase * clusterizer_
T getParameter(std::string const &) const
virtual void setESObjects(const edm::EventSetup &es)=0
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
virtual void clusterizeDetUnit(const edm::DetSet< PixelDigi > &input, const PixelGeomDetUnit *pixDet, const TrackerTopology *tTopo, const std::vector< short > &badChannels, edmNew::DetSetVector< SiPixelCluster >::FastFiller &output)=0
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void swap(DetSetVector &rh)
#define nullptr
static std::string const input
Definition: EdmProvDump.cc:44
const TrackerGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
const std::string payloadType_
SiPixelClusterProducer(const edm::ParameterSet &conf)
Constructor: set the ParameterSet and defer all thinking to setupClusterizer().
const int32_t maxTotalClusters_
Optional limit on the total number of clusters.
EDProducer to cluster PixelDigis into SiPixelClusters.
Definition: DetId.h:18
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
edm::EDGetTokenT< SiPixelClusterCollectionNew > tPixelClusters
T get() const
Definition: EventSetup.h:63
SiPixelGainCalibrationServiceBase * theSiPixelGainCalibration_
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
T const * product() const
Definition: ESHandle.h:86
const TrackerTopology * tTopo_
def move(src, dest)
Definition: eostools.py:510
void setSiPixelGainCalibrationService(SiPixelGainCalibrationServiceBase *in)
const std::string clusterMode_
A specific threshold-based pixel clustering algorithm.