CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/RecoLocalTracker/SiPixelClusterizer/plugins/SiPixelClusterProducer.cc

Go to the documentation of this file.
00001 
00014 // Our own stuff
00015 #include "RecoLocalTracker/SiPixelClusterizer/interface/SiPixelClusterProducer.h"
00016 #include "RecoLocalTracker/SiPixelClusterizer/interface/PixelThresholdClusterizer.h"
00017 
00018 // Geometry
00019 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00020 #include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h"
00021 
00022 // Data Formats
00023 #include "DataFormats/Common/interface/DetSetVector.h"
00024 #include "DataFormats/SiPixelDigi/interface/PixelDigi.h"
00025 #include "DataFormats/DetId/interface/DetId.h"
00026 
00027 // Database payloads
00028 #include "CalibTracker/SiPixelESProducers/interface/SiPixelGainCalibrationService.h"
00029 #include "CalibTracker/SiPixelESProducers/interface/SiPixelGainCalibrationOfflineService.h"
00030 #include "CalibTracker/SiPixelESProducers/interface/SiPixelGainCalibrationForHLTService.h"
00031 
00032 // Framework
00033 #include "DataFormats/Common/interface/Handle.h"
00034 #include "FWCore/Framework/interface/ESHandle.h"
00035 
00036 // STL
00037 #include <vector>
00038 #include <memory>
00039 #include <string>
00040 #include <iostream>
00041 
00042 // MessageLogger
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"),     // bogus
00056     clusterizer_(0),          // the default, in case we fail to make one
00057     readyToCluster_(false),   // since we obviously aren't
00058     src_( conf.getParameter<edm::InputTag>( "src" ) ),
00059     maxTotalClusters_( conf.getParameter<int32_t>( "maxNumberOfClusters" ) )
00060   {
00061     //--- Declare to the EDM what kind of collections we will be making.
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     //--- Make the algorithm(s) according to what the user specified
00074     //--- in the ParameterSet.
00075     setupClusterizer();
00076 
00077   }
00078 
00079   // Destructor
00080   SiPixelClusterProducer::~SiPixelClusterProducer() { 
00081     delete clusterizer_;
00082     delete theSiPixelGainCalibration_;
00083   }  
00084 
00085   //void SiPixelClusterProducer::beginJob( const edm::EventSetup& es ) 
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     //Setup gain calibration service
00099     theSiPixelGainCalibration_->setESObjects( es );
00100 
00101    // Step A.1: get input data
00102     //edm::Handle<PixelDigiCollection> pixDigis;
00103     edm::Handle< edm::DetSetVector<PixelDigi> >  input;
00104     e.getByLabel( src_, input);
00105 
00106     // Step A.2: get event setup
00107     edm::ESHandle<TrackerGeometry> geom;
00108     es.get<TrackerDigiGeometryRecord>().get( geom );
00109 
00110     // Step B: create the final output collection
00111     std::auto_ptr<SiPixelClusterCollectionNew> output( new SiPixelClusterCollectionNew() );
00112     //FIXME: put a reserve() here
00113 
00114     // Step C: Iterate over DetIds and invoke the pixel clusterizer algorithm
00115     // on each DetUnit
00116     run(*input, geom, *output );
00117 
00118     // Step D: write output to file
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       // TO DO: throw an exception here?  The user may want to know...
00155       return;   // clusterizer is invalid, bail out
00156     }
00157 
00158     int numberOfDetUnits = 0;
00159     int numberOfClusters = 0;
00160  
00161     // Iterate on detector units
00162     edm::DetSetVector<PixelDigi>::const_iterator DSViter = input.begin();
00163     for( ; DSViter != input.end(); DSViter++) {
00164       ++numberOfDetUnits;
00165 
00166       //  LogDebug takes very long time, get rid off.
00167       //LogDebug("SiStripClusterizer") << "[SiPixelClusterProducer::run] DetID" << DSViter->id;
00168 
00169       std::vector<short> badChannels; 
00170       DetId detIdObject(DSViter->detId());
00171       
00172       // Comment: At the moment the clusterizer depends on geometry
00173       // to access information as the pixel topology (number of columns
00174       // and rows in a detector module). 
00175       // In the future the geometry service will be replaced with
00176       // a ES service.
00177       const GeomDetUnit      * geoUnit = geom->idToDetUnit( detIdObject );
00178       const PixelGeomDetUnit * pixDet  = dynamic_cast<const PixelGeomDetUnit*>(geoUnit);
00179       if (! pixDet) {
00180         // Fatal error!  TO DO: throw an exception!
00181         assert(0);
00182       }
00183       // Produce clusters for this DetUnit and store them in 
00184       // a DetSet
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     } // end of DetUnit loop
00200     
00201     //LogDebug ("SiPixelClusterProducer") << " Executing " 
00202     //      << clusterMode_ << " resulted in " << numberOfClusters
00203     //                              << " SiPixelClusters in " << numberOfDetUnits << " DetUnits."; 
00204   }
00205 
00206 }  // end of namespace cms