Go to the documentation of this file.00001
00014
00015 #include "RecoLocalTracker/SiPixelClusterizer/interface/SiPixelClusterProducer.h"
00016 #include "RecoLocalTracker/SiPixelClusterizer/interface/PixelThresholdClusterizer.h"
00017
00018
00019 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00020 #include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h"
00021
00022
00023 #include "DataFormats/Common/interface/DetSetVector.h"
00024 #include "DataFormats/SiPixelDigi/interface/PixelDigi.h"
00025 #include "DataFormats/DetId/interface/DetId.h"
00026
00027
00028 #include "CalibTracker/SiPixelESProducers/interface/SiPixelGainCalibrationService.h"
00029 #include "CalibTracker/SiPixelESProducers/interface/SiPixelGainCalibrationOfflineService.h"
00030 #include "CalibTracker/SiPixelESProducers/interface/SiPixelGainCalibrationForHLTService.h"
00031
00032
00033 #include "DataFormats/Common/interface/Handle.h"
00034 #include "FWCore/Framework/interface/ESHandle.h"
00035
00036
00037 #include <vector>
00038 #include <memory>
00039 #include <string>
00040 #include <iostream>
00041
00042
00043 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00044
00045 namespace cms
00046 {
00047
00048
00050
00051 SiPixelClusterProducer::SiPixelClusterProducer(edm::ParameterSet const& conf)
00052 :
00053 conf_(conf),
00054 theSiPixelGainCalibration_(0),
00055 clusterMode_("None"),
00056 clusterizer_(0),
00057 readyToCluster_(false),
00058 src_( conf.getParameter<edm::InputTag>( "src" ) ),
00059 maxTotalClusters_( conf.getParameter<int32_t>( "maxNumberOfClusters" ) )
00060 {
00061
00062 produces<SiPixelClusterCollectionNew>();
00063
00064 std::string payloadType = conf.getParameter<std::string>( "payloadType" );
00065
00066 if (strcmp(payloadType.c_str(), "HLT") == 0)
00067 theSiPixelGainCalibration_ = new SiPixelGainCalibrationForHLTService(conf);
00068 else if (strcmp(payloadType.c_str(), "Offline") == 0)
00069 theSiPixelGainCalibration_ = new SiPixelGainCalibrationOfflineService(conf);
00070 else if (strcmp(payloadType.c_str(), "Full") == 0)
00071 theSiPixelGainCalibration_ = new SiPixelGainCalibrationService(conf);
00072
00073
00074
00075 setupClusterizer();
00076
00077 }
00078
00079
00080 SiPixelClusterProducer::~SiPixelClusterProducer() {
00081 delete clusterizer_;
00082 delete theSiPixelGainCalibration_;
00083 }
00084
00085
00086 void SiPixelClusterProducer::beginJob( )
00087 {
00088 edm::LogInfo("SiPixelClusterizer") << "[SiPixelClusterizer::beginJob]";
00089 clusterizer_->setSiPixelGainCalibrationService(theSiPixelGainCalibration_);
00090 }
00091
00092
00094
00095 void SiPixelClusterProducer::produce(edm::Event& e, const edm::EventSetup& es)
00096 {
00097
00098
00099 theSiPixelGainCalibration_->setESObjects( es );
00100
00101
00102
00103 edm::Handle< edm::DetSetVector<PixelDigi> > input;
00104 e.getByLabel( src_, input);
00105
00106
00107 edm::ESHandle<TrackerGeometry> geom;
00108 es.get<TrackerDigiGeometryRecord>().get( geom );
00109
00110
00111 std::auto_ptr<SiPixelClusterCollectionNew> output( new SiPixelClusterCollectionNew() );
00112
00113
00114
00115
00116 run(*input, geom, *output );
00117
00118
00119 e.put( output );
00120
00121 }
00122
00123
00127
00128 void SiPixelClusterProducer::setupClusterizer() {
00129 clusterMode_ =
00130 conf_.getUntrackedParameter<std::string>("ClusterMode","PixelThresholdClusterizer");
00131
00132 if ( clusterMode_ == "PixelThresholdClusterizer" ) {
00133 clusterizer_ = new PixelThresholdClusterizer(conf_);
00134 readyToCluster_ = true;
00135 }
00136 else {
00137 edm::LogError("SiPixelClusterProducer") << "[SiPixelClusterProducer]:"
00138 <<" choice " << clusterMode_ << " is invalid.\n"
00139 << "Possible choices:\n"
00140 << " PixelThresholdClusterizer";
00141 readyToCluster_ = false;
00142 }
00143 }
00144
00145
00147
00148 void SiPixelClusterProducer::run(const edm::DetSetVector<PixelDigi> & input,
00149 edm::ESHandle<TrackerGeometry> & geom,
00150 edmNew::DetSetVector<SiPixelCluster> & output) {
00151 if ( ! readyToCluster_ ) {
00152 edm::LogError("SiPixelClusterProducer")
00153 <<" at least one clusterizer is not ready -- can't run!" ;
00154
00155 return;
00156 }
00157
00158 int numberOfDetUnits = 0;
00159 int numberOfClusters = 0;
00160
00161
00162 edm::DetSetVector<PixelDigi>::const_iterator DSViter = input.begin();
00163 for( ; DSViter != input.end(); DSViter++) {
00164 ++numberOfDetUnits;
00165
00166
00167
00168
00169 std::vector<short> badChannels;
00170 DetId detIdObject(DSViter->detId());
00171
00172
00173
00174
00175
00176
00177 const GeomDetUnit * geoUnit = geom->idToDetUnit( detIdObject );
00178 const PixelGeomDetUnit * pixDet = dynamic_cast<const PixelGeomDetUnit*>(geoUnit);
00179 if (! pixDet) {
00180
00181 assert(0);
00182 }
00183
00184
00185 edmNew::DetSetVector<SiPixelCluster>::FastFiller spc(output, DSViter->detId());
00186 clusterizer_->clusterizeDetUnit(*DSViter, pixDet, badChannels, spc);
00187 if ( spc.empty() ) {
00188 spc.abort();
00189 } else {
00190 numberOfClusters += spc.size();
00191 }
00192
00193 if ((maxTotalClusters_ >= 0) && (numberOfClusters > maxTotalClusters_)) {
00194 edm::LogError("TooManyClusters") << "Limit on the number of clusters exceeded. An empty cluster collection will be produced instead.\n";
00195 edmNew::DetSetVector<SiPixelCluster> empty;
00196 empty.swap(output);
00197 break;
00198 }
00199 }
00200
00201
00202
00203
00204 }
00205
00206 }