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
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 namespace cms
46 {
47 
48  //---------------------------------------------------------------------------
50  //---------------------------------------------------------------------------
52  :
53  conf_(conf),
54  theSiPixelGainCalibration_(0),
55  clusterMode_("None"), // bogus
56  clusterizer_(0), // the default, in case we fail to make one
57  readyToCluster_(false), // since we obviously aren't
58  src_( conf.getParameter<edm::InputTag>( "src" ) ),
59  maxTotalClusters_( conf.getParameter<int32_t>( "maxNumberOfClusters" ) )
60  {
61  tPixelDigi = consumes<edm::DetSetVector<PixelDigi>>(src_);
62  //--- Declare to the EDM what kind of collections we will be making.
63  produces<SiPixelClusterCollectionNew>();
64 
65  std::string payloadType = conf.getParameter<std::string>( "payloadType" );
66 
67  if (strcmp(payloadType.c_str(), "HLT") == 0)
69  else if (strcmp(payloadType.c_str(), "Offline") == 0)
71  else if (strcmp(payloadType.c_str(), "Full") == 0)
73 
74  //--- Make the algorithm(s) according to what the user specified
75  //--- in the ParameterSet.
77 
78  }
79 
80  // Destructor
82  delete clusterizer_;
84  }
85 
86  //void SiPixelClusterProducer::beginJob( const edm::EventSetup& es )
88  {
89  edm::LogInfo("SiPixelClusterizer") << "[SiPixelClusterizer::beginJob]";
91  }
92 
93  //---------------------------------------------------------------------------
95  //---------------------------------------------------------------------------
97  {
98 
99  //Setup gain calibration service
101 
102  // Step A.1: get input data
103  //edm::Handle<PixelDigiCollection> pixDigis;
105  e.getByToken(tPixelDigi, input);
106 
107  // Step A.2: get event setup
109  es.get<TrackerDigiGeometryRecord>().get( geom );
110 
111  // Step B: create the final output collection
112  std::auto_ptr<SiPixelClusterCollectionNew> output( new SiPixelClusterCollectionNew() );
113  //FIXME: put a reserve() here
114 
115  // Step C: Iterate over DetIds and invoke the pixel clusterizer algorithm
116  // on each DetUnit
117  run(*input, geom, *output );
118 
119  // Step D: write output to file
120  e.put( output );
121 
122  }
123 
124  //---------------------------------------------------------------------------
128  //---------------------------------------------------------------------------
130  clusterMode_ =
131  conf_.getUntrackedParameter<std::string>("ClusterMode","PixelThresholdClusterizer");
132 
133  if ( clusterMode_ == "PixelThresholdClusterizer" ) {
135  readyToCluster_ = true;
136  }
137  else {
138  edm::LogError("SiPixelClusterProducer") << "[SiPixelClusterProducer]:"
139  <<" choice " << clusterMode_ << " is invalid.\n"
140  << "Possible choices:\n"
141  << " PixelThresholdClusterizer";
142  readyToCluster_ = false;
143  }
144  }
145 
146  //---------------------------------------------------------------------------
148  //---------------------------------------------------------------------------
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
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  // Produce clusters for this DetUnit and store them in
185  // a DetSet
186  edmNew::DetSetVector<SiPixelCluster>::FastFiller spc(output, DSViter->detId());
187  clusterizer_->clusterizeDetUnit(*DSViter, pixDet, badChannels, spc);
188  if ( spc.empty() ) {
189  spc.abort();
190  } else {
191  numberOfClusters += spc.size();
192  }
193 
194  if ((maxTotalClusters_ >= 0) && (numberOfClusters > maxTotalClusters_)) {
195  edm::LogError("TooManyClusters") << "Limit on the number of clusters exceeded. An empty cluster collection will be produced instead.\n";
197  empty.swap(output);
198  break;
199  }
200  } // end of DetUnit loop
201 
202  //LogDebug ("SiPixelClusterProducer") << " Executing "
203  // << clusterMode_ << " resulted in " << numberOfClusters
204  // << " SiPixelClusters in " << numberOfDetUnits << " DetUnits.";
205  }
206 
207 } // end of namespace cms
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
PixelClusterizerBase * clusterizer_
virtual void setESObjects(const edm::EventSetup &es)=0
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
void swap(DetSetVector &rh)
static std::string const input
Definition: EdmProvDump.cc:44
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
virtual void beginJob() override
virtual void produce(edm::Event &e, const edm::EventSetup &c) override
The &quot;Event&quot; entrypoint: gets called by framework for every event.
edm::EDGetTokenT< edm::DetSetVector< PixelDigi > > tPixelDigi
iterator end()
Return the off-the-end iterator.
Definition: DetSetVector.h:363
tuple conf
Definition: dbtoconf.py:185
Definition: DetId.h:18
const T & get() const
Definition: EventSetup.h:55
SiPixelClusterProducer(const edm::ParameterSet &conf)
Constructor: set the ParameterSet and defer all thinking to setupClusterizer().
edmNew::DetSetVector< SiPixelCluster > SiPixelClusterCollectionNew
void run(const edm::DetSetVector< PixelDigi > &input, edm::ESHandle< TrackerGeometry > &geom, edmNew::DetSetVector< SiPixelCluster > &output)
Iterate over DetUnits, and invoke the PixelClusterizer on each.
iterator begin()
Return an iterator to the first DetSet.
Definition: DetSetVector.h:348
volatile std::atomic< bool > shutdown_flag false
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:106
int32_t maxTotalClusters_
Optional limit on the total number of clusters.
SiPixelGainCalibrationServiceBase * theSiPixelGainCalibration_
void setSiPixelGainCalibrationService(SiPixelGainCalibrationServiceBase *in)
An explicit threshold-based clustering algorithm.
virtual void clusterizeDetUnit(const edm::DetSet< PixelDigi > &input, const PixelGeomDetUnit *pixDet, const std::vector< short > &badChannels, edmNew::DetSetVector< SiPixelCluster >::FastFiller &output)=0