CMS 3D CMS Logo

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 "CondTools/SiPixel/interface/SiPixelGainCalibrationService.h"
00029 #include "CondTools/SiPixel/interface/SiPixelGainCalibrationOfflineService.h"
00030 #include "CondTools/SiPixel/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   {
00060     //--- Declare to the EDM what kind of collections we will be making.
00061     produces<SiPixelClusterCollectionNew>(); 
00062 
00063     std::string payloadType = conf.getParameter<std::string>( "payloadType" );
00064 
00065     if (strcmp(payloadType.c_str(), "HLT") == 0)
00066        theSiPixelGainCalibration_ = new SiPixelGainCalibrationForHLTService(conf);
00067     else if (strcmp(payloadType.c_str(), "Offline") == 0)
00068        theSiPixelGainCalibration_ = new SiPixelGainCalibrationOfflineService(conf);
00069     else if (strcmp(payloadType.c_str(), "Full") == 0)
00070        theSiPixelGainCalibration_ = new SiPixelGainCalibrationService(conf);
00071 
00072     //--- Make the algorithm(s) according to what the user specified
00073     //--- in the ParameterSet.
00074     setupClusterizer();
00075 
00076   }
00077 
00078   // Destructor
00079   SiPixelClusterProducer::~SiPixelClusterProducer() { 
00080     delete clusterizer_;
00081   }  
00082 
00083   void SiPixelClusterProducer::beginJob( const edm::EventSetup& es ) {
00084     edm::LogInfo("SiPixelClusterizer") << "[SiPixelClusterizer::beginJob]";
00085     clusterizer_->setSiPixelGainCalibrationService(theSiPixelGainCalibration_);
00086   }
00087 
00088   //---------------------------------------------------------------------------
00090   //---------------------------------------------------------------------------
00091   void SiPixelClusterProducer::produce(edm::Event& e, const edm::EventSetup& es)
00092   {
00093 
00094     //Setup gain calibration service
00095     theSiPixelGainCalibration_->setESObjects( es );
00096 
00097    // Step A.1: get input data
00098     //edm::Handle<PixelDigiCollection> pixDigis;
00099     edm::Handle< edm::DetSetVector<PixelDigi> >  input;
00100     e.getByLabel( src_, input);
00101 
00102     // Step A.2: get event setup
00103     edm::ESHandle<TrackerGeometry> geom;
00104     es.get<TrackerDigiGeometryRecord>().get( geom );
00105 
00106     // Step B: create the final output collection
00107     std::auto_ptr<SiPixelClusterCollectionNew> output( new SiPixelClusterCollectionNew() );
00108     //FIXME: put a reserve() here
00109 
00110     // Step C: Iterate over DetIds and invoke the pixel clusterizer algorithm
00111     // on each DetUnit
00112     run(*input, geom, *output );
00113 
00114     // Step D: write output to file
00115     e.put( output );
00116 
00117   }
00118 
00119   //---------------------------------------------------------------------------
00123   //---------------------------------------------------------------------------
00124   void SiPixelClusterProducer::setupClusterizer()  {
00125     clusterMode_ = 
00126       conf_.getUntrackedParameter<std::string>("ClusterMode","PixelThresholdClusterizer");
00127 
00128     if ( clusterMode_ == "PixelThresholdClusterizer" ) {
00129       clusterizer_ = new PixelThresholdClusterizer(conf_);
00130       readyToCluster_ = true;
00131     } 
00132     else {
00133       edm::LogError("SiPixelClusterProducer") << "[SiPixelClusterProducer]:"
00134                 <<" choice " << clusterMode_ << " is invalid.\n"
00135                 << "Possible choices:\n" 
00136                 << "    PixelThresholdClusterizer";
00137       readyToCluster_ = false;
00138     }
00139   }
00140 
00141   //---------------------------------------------------------------------------
00143   //---------------------------------------------------------------------------
00144   void SiPixelClusterProducer::run(const edm::DetSetVector<PixelDigi>   & input, 
00145                                    edm::ESHandle<TrackerGeometry>       & geom,
00146                                    edmNew::DetSetVector<SiPixelCluster> & output) {
00147     if ( ! readyToCluster_ ) {
00148       edm::LogError("SiPixelClusterProducer")
00149                 <<" at least one clusterizer is not ready -- can't run!" ;
00150       // TO DO: throw an exception here?  The user may want to know...
00151       return;   // clusterizer is invalid, bail out
00152     }
00153 
00154     int numberOfDetUnits = 0;
00155     int numberOfClusters = 0;
00156  
00157     // Iterate on detector units
00158     edm::DetSetVector<PixelDigi>::const_iterator DSViter = input.begin();
00159     for( ; DSViter != input.end(); DSViter++) {
00160       ++numberOfDetUnits;
00161 
00162       //  LogDebug takes very long time, get rid off.
00163       //LogDebug("SiStripClusterizer") << "[SiPixelClusterProducer::run] DetID" << DSViter->id;
00164 
00165       std::vector<short> badChannels; 
00166       DetId detIdObject(DSViter->detId());
00167       
00168       // Comment: At the moment the clusterizer depends on geometry
00169       // to access information as the pixel topology (number of columns
00170       // and rows in a detector module). 
00171       // In the future the geometry service will be replaced with
00172       // a ES service.
00173       const GeomDetUnit      * geoUnit = geom->idToDetUnit( detIdObject );
00174       const PixelGeomDetUnit * pixDet  = dynamic_cast<const PixelGeomDetUnit*>(geoUnit);
00175       if (! pixDet) {
00176         // Fatal error!  TO DO: throw an exception!
00177         assert(0);
00178       }
00179       // Produce clusters for this DetUnit and store them in 
00180       // a DetSet
00181       edmNew::DetSetVector<SiPixelCluster>::FastFiller spc(output, DSViter->detId());
00182       clusterizer_->clusterizeDetUnit(*DSViter, pixDet, badChannels, spc);
00183       if ( spc.empty() ) {
00184         spc.abort();
00185       } else {
00186         numberOfClusters += spc.size();
00187       }
00188 
00189     } // end of DetUnit loop
00190     
00191     //LogDebug ("SiPixelClusterProducer") << " Executing " 
00192     //      << clusterMode_ << " resulted in " << numberOfClusters
00193     //                              << " SiPixelClusters in " << numberOfDetUnits << " DetUnits."; 
00194   }
00195 
00196 }  // end of namespace cms

Generated on Tue Jun 9 17:43:57 2009 for CMSSW by  doxygen 1.5.4