CMS 3D CMS Logo

Phase2ITPixelClusterProducer.cc
Go to the documentation of this file.
1 
13 // Our own stuff
16 
17 // Geometry
20 
21 // Data Formats
25 
26 // Database payloads
30 
31 // Framework
34 
35 // STL
36 #include <vector>
37 #include <memory>
38 #include <string>
39 #include <iostream>
40 
41 // MessageLogger
43 
44 
45  //---------------------------------------------------------------------------
47  //---------------------------------------------------------------------------
49  :
50  conf_(conf),
51  theSiPixelGainCalibration_(0),
52  clusterMode_("None"), // bogus
53  clusterizer_(0), // the default, in case we fail to make one
54  readyToCluster_(false), // since we obviously aren't
55  src_( conf.getParameter<edm::InputTag>( "src" ) ),
56  maxTotalClusters_( conf.getParameter<int32_t>( "maxNumberOfClusters" ) )
57  {
58  tPixelDigi = consumes<edm::DetSetVector<PixelDigi>>(src_);
59  //--- Declare to the EDM what kind of collections we will be making.
60  produces<Phase2ITPixelClusterCollectionNew>();
61 
62  std::string payloadType = conf.getParameter<std::string>( "payloadType" );
63 
64  if (strcmp(payloadType.c_str(), "HLT") == 0)
66  else if (strcmp(payloadType.c_str(), "Offline") == 0)
68  else if (strcmp(payloadType.c_str(), "Full") == 0)
70 
71  //--- Make the algorithm(s) according to what the user specified
72  //--- in the ParameterSet.
74 
75  }
76 
77  // Destructor
79  delete clusterizer_;
81  }
82 
83 
84  //---------------------------------------------------------------------------
86  //---------------------------------------------------------------------------
88  {
89 
90  //Setup gain calibration service
92 
93  // Step A.1: get input data
94  //edm::Handle<PixelDigiCollection> pixDigis;
96  e.getByToken(tPixelDigi, input);
97 
98  // Step A.2: get event setup
100  es.get<TrackerDigiGeometryRecord>().get( geom );
101 
102  // Step B: create the final output collection
103  auto output = std::make_unique<Phase2ITPixelClusterCollectionNew>();
104  //FIXME: put a reserve() here
105 
106  // Step C: Iterate over DetIds and invoke the pixel clusterizer algorithm
107  // on each DetUnit
108  run(*input, geom, *output );
109 
110  // Step D: write output to file
111  output->shrink_to_fit();
112  e.put(std::move(output));
113 
114  }
115 
116  //---------------------------------------------------------------------------
120  //---------------------------------------------------------------------------
122  clusterMode_ =
123  conf_.getUntrackedParameter<std::string>("ClusterMode","Phase2ITPixelThresholdClusterizer");
124 
125  if ( clusterMode_ == "Phase2ITPixelThresholdClusterizer" ) {
128  readyToCluster_ = true;
129  }
130  else {
131  edm::LogError("Phase2ITPixelClusterProducer") << "[Phase2ITPixelClusterProducer]:"
132  <<" choice " << clusterMode_ << " is invalid.\n"
133  << "Possible choices:\n"
134  << " Phase2ITPixelThresholdClusterizer";
135  readyToCluster_ = false;
136  }
137  }
138 
139  //---------------------------------------------------------------------------
141  //---------------------------------------------------------------------------
145  if ( ! readyToCluster_ ) {
146  edm::LogError("Phase2ITPixelClusterProducer")
147  <<" at least one clusterizer is not ready -- can't run!" ;
148  // TO DO: throw an exception here? The user may want to know...
149  return; // clusterizer is invalid, bail out
150  }
151 
152  int numberOfDetUnits = 0;
153  int numberOfClusters = 0;
154 
155  // Iterate on detector units
157  for( ; DSViter != input.end(); DSViter++) {
158  ++numberOfDetUnits;
159 
160  // LogDebug takes very long time, get rid off.
161  //LogDebug("SiStripClusterizer") << "[Phase2ITPixelClusterProducer::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  // Produce clusters for this DetUnit and store them in
178  // a DetSet
179  edmNew::DetSetVector<Phase2ITPixelCluster>::FastFiller spc(output, DSViter->detId());
180  clusterizer_->clusterizeDetUnit(*DSViter, pixDet, badChannels, spc);
181  if ( spc.empty() ) {
182  spc.abort();
183  } else {
184  numberOfClusters += spc.size();
185  }
186 
187  if ((maxTotalClusters_ >= 0) && (numberOfClusters > maxTotalClusters_)) {
188  edm::LogError("TooManyClusters") << "Limit on the number of clusters exceeded. An empty cluster collection will be produced instead.\n";
190  empty.swap(output);
191  break;
192  }
193  } // end of DetUnit loop
194 
195  //LogDebug ("Phase2ITPixelClusterProducer") << " Executing "
196  // << clusterMode_ << " resulted in " << numberOfClusters
197  // << " Phase2ITPixelClusters in " << numberOfDetUnits << " DetUnits.";
198  }
199 
200 
201 
202 
205 
207 
T getParameter(std::string const &) const
const TrackerGeomDet * idToDetUnit(DetId) const
Return the pointer to the GeomDetUnit corresponding to a given DetId.
T getUntrackedParameter(std::string const &, T const &) const
virtual void produce(edm::Event &e, const edm::EventSetup &c) override
The "Event" entrypoint: gets called by framework for every event.
virtual void setESObjects(const edm::EventSetup &es)=0
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
edm::EDGetTokenT< edm::DetSetVector< PixelDigi > > tPixelDigi
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
int32_t maxTotalClusters_
Optional limit on the total number of clusters.
void swap(DetSetVector &rh)
A specific threshold-based pixel clustering algorithm.
static std::string const input
Definition: EdmProvDump.cc:44
void setSiPixelGainCalibrationService(SiPixelGainCalibrationServiceBase *in)
SiPixelGainCalibrationServiceBase * theSiPixelGainCalibration_
iterator end()
Return the off-the-end iterator.
Definition: DetSetVector.h:361
void run(const edm::DetSetVector< PixelDigi > &input, edm::ESHandle< TrackerGeometry > &geom, edmNew::DetSetVector< Phase2ITPixelCluster > &output)
Iterate over DetUnits, and invoke the Phase2ITPixelClusterizer on each.
Definition: DetId.h:18
const T & get() const
Definition: EventSetup.h:56
Phase2ITPixelClusterizerBase * clusterizer_
HLT enums.
Phase2ITPixelClusterProducer(const edm::ParameterSet &conf)
Constructor: set the ParameterSet and defer all thinking to setupClusterizer().
iterator begin()
Return an iterator to the first DetSet.
Definition: DetSetVector.h:346
virtual void clusterizeDetUnit(const edm::DetSet< PixelDigi > &input, const PixelGeomDetUnit *pixDet, const std::vector< short > &badChannels, edmNew::DetSetVector< Phase2ITPixelCluster >::FastFiller &output)=0
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:104
def move(src, dest)
Definition: eostools.py:510
EDProducer to cluster PixelDigis into Phase2ITPixelClusters.