CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/RecoLocalTracker/SiPixelRecHits/plugins/SiPixelRecHitConverter.cc

Go to the documentation of this file.
00001 
00012 // Our own stuff
00013 #include "RecoLocalTracker/SiPixelRecHits/interface/SiPixelRecHitConverter.h"
00014 #include "RecoLocalTracker/SiPixelRecHits/interface/PixelCPETemplateReco.h"
00015 #include "RecoLocalTracker/SiPixelRecHits/interface/PixelCPEGeneric.h"
00016 
00017 // Geometry
00018 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00019 #include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h"
00020 
00021 // Data Formats
00022 #include "DataFormats/DetId/interface/DetId.h"
00023 #include "DataFormats/Common/interface/Ref.h"
00024 #include "DataFormats/Common/interface/DetSet2RangeMap.h"
00025 
00026 // Framework Already defined in the *.h file
00027 //#include "DataFormats/Common/interface/Handle.h"
00028 //#include "FWCore/Framework/interface/ESHandle.h"
00029 
00030 // STL
00031 #include <vector>
00032 #include <memory>
00033 #include <string>
00034 #include <iostream>
00035 
00036 // MessageLogger
00037 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00038 
00039 #include "RecoLocalTracker/Records/interface/TkPixelCPERecord.h"
00040 
00041 using namespace std;
00042 
00043 namespace cms
00044 {
00045   //---------------------------------------------------------------------------
00047   //---------------------------------------------------------------------------
00048   SiPixelRecHitConverter::SiPixelRecHitConverter(edm::ParameterSet const& conf) 
00049     : 
00050     conf_(conf),
00051     cpeName_("None"),     // bogus
00052     cpe_(0),              // the default, in case we fail to make one
00053     ready_(false),        // since we obviously aren't
00054     src_( conf.getParameter<edm::InputTag>( "src" ) ),
00055     theVerboseLevel(conf.getUntrackedParameter<int>("VerboseLevel",0))
00056   {
00057     //--- Declare to the EDM what kind of collections we will be making.
00058     produces<SiPixelRecHitCollection>();
00059    
00060   }
00061   
00062   // Destructor
00063   SiPixelRecHitConverter::~SiPixelRecHitConverter() 
00064   { 
00065   }  
00066   
00067   //---------------------------------------------------------------------------
00068   // Begin job: get magnetic field
00069   //---------------------------------------------------------------------------
00070   //void SiPixelRecHitConverter::beginJob() 
00071   void SiPixelRecHitConverter::beginJob() 
00072   {
00073   }
00074   
00075   //---------------------------------------------------------------------------
00077   //---------------------------------------------------------------------------
00078   void SiPixelRecHitConverter::produce(edm::Event& e, const edm::EventSetup& es)
00079   {
00080 
00081     // Step A.1: get input data
00082     edm::Handle< edmNew::DetSetVector<SiPixelCluster> > input;
00083     e.getByLabel( src_, input);
00084     
00085     // Step A.2: get event setup
00086     edm::ESHandle<TrackerGeometry> geom;
00087     es.get<TrackerDigiGeometryRecord>().get( geom );
00088 
00089                 // Step B: create empty output collection
00090     std::auto_ptr<SiPixelRecHitCollectionNew> output(new SiPixelRecHitCollectionNew);
00091 
00092     // Step B*: create CPE
00093     edm::ESHandle<PixelClusterParameterEstimator> hCPE;
00094     std::string cpeName_ = conf_.getParameter<std::string>("CPE");
00095     es.get<TkPixelCPERecord>().get(cpeName_,hCPE);
00096     const PixelClusterParameterEstimator &cpe(*hCPE);
00097     cpe_ = &cpe;
00098     
00099     if(cpe_) ready_ = true;
00100     
00101     
00102     // Step C: Iterate over DetIds and invoke the strip CPE algorithm
00103     // on each DetUnit
00104 
00105     run( input, *output, geom );
00106 
00107 
00108     e.put(output);
00109 
00110   }
00111 
00112   //---------------------------------------------------------------------------
00116   //---------------------------------------------------------------------------
00117   void SiPixelRecHitConverter::run(edm::Handle<edmNew::DetSetVector<SiPixelCluster> >  inputhandle,
00118                                    SiPixelRecHitCollectionNew &output,
00119                                    edm::ESHandle<TrackerGeometry> & geom) 
00120   {
00121     if ( ! ready_ ) 
00122       {
00123         edm::LogError("SiPixelRecHitConverter") << " at least one CPE is not ready -- can't run!";
00124         // TO DO: throw an exception here?  The user may want to know...
00125         assert(0);
00126         return;   // clusterizer is invalid, bail out
00127       }
00128     
00129     int numberOfDetUnits = 0;
00130     int numberOfClusters = 0;
00131     
00132     const edmNew::DetSetVector<SiPixelCluster>& input = *inputhandle;
00133     
00134     edmNew::DetSetVector<SiPixelCluster>::const_iterator DSViter=input.begin();
00135     
00136     for ( ; DSViter != input.end() ; DSViter++) 
00137       {
00138         numberOfDetUnits++;
00139         unsigned int detid = DSViter->detId();
00140         DetId detIdObject( detid );  
00141         const GeomDetUnit * genericDet = geom->idToDetUnit( detIdObject );
00142         const PixelGeomDetUnit * pixDet = dynamic_cast<const PixelGeomDetUnit*>(genericDet);
00143         assert(pixDet); 
00144         SiPixelRecHitCollectionNew::FastFiller recHitsOnDetUnit(output,detid);
00145         
00146         edmNew::DetSet<SiPixelCluster>::const_iterator clustIt = DSViter->begin(), clustEnd = DSViter->end();
00147         
00148         for ( ; clustIt != clustEnd; clustIt++) 
00149           {
00150             numberOfClusters++;
00151             std::pair<LocalPoint, LocalError> lv = cpe_->localParameters( *clustIt, *genericDet );
00152             LocalPoint lp( lv.first );
00153             LocalError le( lv.second );
00154             // Create a persistent edm::Ref to the cluster
00155             edm::Ref< edmNew::DetSetVector<SiPixelCluster>, SiPixelCluster > cluster = edmNew::makeRefTo( inputhandle, clustIt);
00156             // Make a RecHit and add it to the DetSet
00157             // old : recHitsOnDetUnit.push_back( new SiPixelRecHit( lp, le, detIdObject, &*clustIt) );
00158             SiPixelRecHit hit( lp, le, detIdObject, cluster);
00159             // Copy the extra stuff; unfortunately, only the derivatives of PixelCPEBase
00160             // are capable of doing that.  So until we get rid of CPEFromDetPosition
00161             // we'll have to dynamic_cast :(
00162             // &&& This cast can be moved to the setupCPE, so that it's done once per job.
00163             const PixelCPEBase * cpeBase 
00164               = dynamic_cast< const PixelCPEBase* >( cpe_ );
00165             if (cpeBase) 
00166               {
00167                 hit.setRawQualityWord( cpeBase->rawQualityWord() );
00168                 // hit.setProbabilityX( cpeBase->probabilityX() );
00169                 // hit.setProbabilityY( cpeBase->probabilityY() );
00170                 // hit.setQBin( cpeBase->qBin() );
00171                 // hit.setCotAlphaFromCluster( cpeBase->cotAlphaFromCluster() );
00172                 // hit.setCotBetaFromCluster ( cpeBase->cotBetaFromCluster()  );
00173               }
00174             // 
00175             // Now save it =================
00176             recHitsOnDetUnit.push_back(hit);
00177             // =============================
00178           } //  <-- End loop on Clusters
00179         
00180         if ( recHitsOnDetUnit.size()>0 ) 
00181           {
00182             if (theVerboseLevel > 2) 
00183               LogDebug("SiPixelRecHitConverter") << " Found " 
00184                                                  << recHitsOnDetUnit.size() << " RecHits on " << detid; 
00185           }
00186         
00187       } //    <-- End loop on DetUnits
00188     
00189     if ( theVerboseLevel > 2 ) LogDebug ("SiPixelRecHitConverter") 
00190       << cpeName_ << " converted " << numberOfClusters 
00191       << " SiPixelClusters into SiPixelRecHits, in " 
00192       << numberOfDetUnits << " DetUnits.";      
00193   }
00194 }  // end of namespace cms