test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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_(0),
52  clusterMode_( conf.getUntrackedParameter<std::string>("ClusterMode","PixelThresholdClusterizer") ),
53  clusterizer_(0), // 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  // Step B: create the final output collection
107  auto output = std::make_unique< SiPixelClusterCollectionNew>();
108  //FIXME: put a reserve() here
109 
110  // Step C: Iterate over DetIds and invoke the pixel clusterizer algorithm
111  // on each DetUnit
112  if ( clusterMode_ == "PixelThresholdReclusterizer" )
113  run(*inputClusters, geom, *output );
114  else
115  run(*inputDigi, geom, *output );
116 
117  // Step D: write output to file
118  output->shrink_to_fit();
119  e.put(std::move(output));
120 
121  }
122 
123  //---------------------------------------------------------------------------
127  //---------------------------------------------------------------------------
129 
130  if ( clusterMode_ == "PixelThresholdReclusterizer" || clusterMode_ == "PixelThresholdClusterizer" ) {
133  readyToCluster_ = true;
134  }
135  else {
136  edm::LogError("SiPixelClusterProducer") << "[SiPixelClusterProducer]:"
137  <<" choice " << clusterMode_ << " is invalid.\n"
138  << "Possible choices:\n"
139  << " PixelThresholdClusterizer";
140  readyToCluster_ = false;
141  }
142  }
143 
144 
145  //---------------------------------------------------------------------------
147  //---------------------------------------------------------------------------
148  template<typename T>
152  if ( ! readyToCluster_ ) {
153  edm::LogError("SiPixelClusterProducer")
154  <<" at least one clusterizer is not ready -- can't run!" ;
155  // TO DO: throw an exception here? The user may want to know...
156  return; // clusterizer is invalid, bail out
157  }
158 
159  int numberOfDetUnits = 0;
160  int numberOfClusters = 0;
161 
162  // Iterate on detector units
163  typename T::const_iterator DSViter = input.begin();
164  for( ; DSViter != input.end(); DSViter++) {
165  ++numberOfDetUnits;
166 
167  // LogDebug takes very long time, get rid off.
168  //LogDebug("SiStripClusterizer") << "[SiPixelClusterProducer::run] DetID" << DSViter->id;
169 
170  std::vector<short> badChannels;
171  DetId detIdObject(DSViter->detId());
172 
173  // Comment: At the moment the clusterizer depends on geometry
174  // to access information as the pixel topology (number of columns
175  // and rows in a detector module).
176  // In the future the geometry service will be replaced with
177  // a ES service.
178  const GeomDetUnit * geoUnit = geom->idToDetUnit( detIdObject );
179  const PixelGeomDetUnit * pixDet = dynamic_cast<const PixelGeomDetUnit*>(geoUnit);
180  if (! pixDet) {
181  // Fatal error! TO DO: throw an exception!
182  assert(0);
183  }
184  {
185  // Produce clusters for this DetUnit and store them in
186  // a DetSet
187  edmNew::DetSetVector<SiPixelCluster>::FastFiller spc(output, DSViter->detId());
188  clusterizer_->clusterizeDetUnit(*DSViter, pixDet, badChannels, spc);
189  if ( spc.empty() ) {
190  spc.abort();
191  } else {
192  numberOfClusters += spc.size();
193  }
194  } // spc is not deleted and detsetvector updated
195  if ((maxTotalClusters_ >= 0) && (numberOfClusters > maxTotalClusters_)) {
196  edm::LogError("TooManyClusters") << "Limit on the number of clusters exceeded. An empty cluster collection will be produced instead.\n";
198  empty.swap(output);
199  break;
200  }
201  } // end of DetUnit loop
202 
203  //LogDebug ("SiPixelClusterProducer") << " Executing "
204  // << clusterMode_ << " resulted in " << numberOfClusters
205  // << " SiPixelClusters in " << numberOfDetUnits << " DetUnits.";
206  }
207 
208 
209 
210 
213 
215 
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:122
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
assert(m_qm.get())
void swap(DetSetVector &rh)
static std::string const input
Definition: EdmProvDump.cc:44
const std::string payloadType_
def move
Definition: eostools.py:510
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
virtual void produce(edm::Event &e, const edm::EventSetup &c) override
The &quot;Event&quot; entrypoint: gets called by framework for every event.
void setupClusterizer(const edm::ParameterSet &conf)
const T & get() const
Definition: EventSetup.h:56
edm::EDGetTokenT< edm::DetSetVector< PixelDigi > > tPixelDigi
edm::EDGetTokenT< SiPixelClusterCollectionNew > tPixelClusters
SiPixelGainCalibrationServiceBase * theSiPixelGainCalibration_
volatile std::atomic< bool > shutdown_flag false
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
void setSiPixelGainCalibrationService(SiPixelGainCalibrationServiceBase *in)
const std::string clusterMode_
A specific threshold-based pixel clustering algorithm.
virtual void clusterizeDetUnit(const edm::DetSet< PixelDigi > &input, const PixelGeomDetUnit *pixDet, const std::vector< short > &badChannels, edmNew::DetSetVector< SiPixelCluster >::FastFiller &output)=0