CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/RecoLocalTracker/SiStripClusterizer/plugins/SiStripClusterToDigiProducer.cc

Go to the documentation of this file.
00001 #include "FWCore/Framework/interface/Frameworkfwd.h"
00002 #include "FWCore/Framework/interface/EDProducer.h"
00003 #include "FWCore/Framework/interface/Event.h"
00004 #include "FWCore/Framework/interface/ESHandle.h"
00005 
00006 #include "DataFormats/Common/interface/DetSetVector.h"
00007 #include "DataFormats/Common/interface/DetSetVectorNew.h"
00008 
00009 #include "CalibFormats/SiStripObjects/interface/SiStripGain.h"
00010 #include "CondFormats/SiStripObjects/interface/SiStripNoises.h"
00011 #include "CalibFormats/SiStripObjects/interface/SiStripQuality.h"
00012 
00013 #include "CalibTracker/Records/interface/SiStripDependentRecords.h"
00014 
00015 #include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
00016 #include "boost/foreach.hpp"
00017 #include <numeric>
00018 
00019 class SiStripClusterToDigiProducer : public edm::EDProducer  {
00020 
00021   typedef   edmNew::DetSetVector<SiStripCluster> ClusterCollection;
00022   typedef   edmNew::DetSet<SiStripCluster> DetClusterCollection;
00023   typedef   edmNew::DetSet<SiStripCluster>::const_iterator DetClusIter;
00024 
00025 
00026   typedef   edm::DetSetVector<SiStripDigi> DigiCollection;
00027   typedef   edm::DetSet<SiStripDigi> DetDigiCollection;
00028   typedef   edm::DetSet<SiStripDigi>::const_iterator DetDigiIter;
00029 
00030 
00031 public:
00032 
00033   explicit SiStripClusterToDigiProducer(const edm::ParameterSet& conf);
00034   void produce(edm::Event&, const edm::EventSetup&);
00035 
00036 private:
00037 
00038   void process(const ClusterCollection& input, std::vector<DetDigiCollection>& output_base);
00039   void initialize(const edm::EventSetup& es);
00040   void setDetId(const uint32_t id); 
00041   float gain(const uint16_t& strip)  const { return gainHandle->getStripGain( strip, gainRange ); }
00042   uint16_t applyGain(const uint16_t& strip,const uint16_t& adc );
00043 
00044   const edm::InputTag _inputTag;
00045   SiStripApvGain::Range gainRange;
00046   edm::ESHandle<SiStripGain> gainHandle;
00047   uint32_t gain_cache_id, detId;
00048   
00049 };
00050 
00051 
00052 SiStripClusterToDigiProducer::
00053 SiStripClusterToDigiProducer(const edm::ParameterSet& conf) 
00054   : _inputTag( conf.getParameter<edm::InputTag>("ClusterProducer") ){
00055   
00056   produces< DigiCollection > ("ZeroSuppressed");
00057   produces< DigiCollection > ("VirginRaw"     );
00058   produces< DigiCollection > ("ProcessedRaw"  );
00059   produces< DigiCollection > ("ScopeMode"     );
00060   
00061 }
00062 
00063 void SiStripClusterToDigiProducer::
00064 produce(edm::Event& event, const edm::EventSetup& es)  {
00065   
00066   initialize(es);
00067   
00068   std::vector<DetDigiCollection> output_base; 
00069   edm::Handle<ClusterCollection> input ;
00070   event.getByLabel(_inputTag,input);
00071 
00072   if(input.isValid())
00073     process(*input, output_base);
00074 
00075 
00076   std::auto_ptr< DigiCollection > outputZS(new DigiCollection(output_base) );
00077   std::auto_ptr< DigiCollection > outputVR(new DigiCollection() );
00078   std::auto_ptr< DigiCollection > outputPR(new DigiCollection() );
00079   std::auto_ptr< DigiCollection > outputSM(new DigiCollection() );
00080 
00081   event.put( outputZS, "ZeroSuppressed");
00082   event.put( outputVR, "VirginRaw"     );
00083   event.put( outputPR, "ProcessedRaw"  );
00084   event.put( outputSM, "ScopeMode"     );
00085 }
00086 
00087 void SiStripClusterToDigiProducer::
00088 process(const ClusterCollection& input, std::vector<DetDigiCollection>& output_base)  {
00089  
00090   for(ClusterCollection::const_iterator it = input.begin(); it!=input.end(); ++it) {
00091 
00092     uint32_t detid=it->detId();
00093 
00094     setDetId(detid);
00095     DetDigiCollection detDigis(detid);
00096 
00097     DetClusIter clus(it->begin()), endclus(it->end());
00098     for(;clus!=endclus;clus++){
00099       size_t istrip     = 0;
00100       size_t width      = clus->amplitudes().size();
00101       size_t firstStrip = clus->firstStrip();
00102       uint16_t stripPos=firstStrip;
00103       for(;istrip<width;++istrip){
00104         detDigis.data.push_back( SiStripDigi( stripPos, applyGain(stripPos,clus->amplitudes()[istrip]) ) );
00105         stripPos++;
00106       }
00107     }
00108     
00109     if (detDigis.size()) 
00110       output_base.push_back(detDigis); 
00111   }
00112 }
00113 
00114 void SiStripClusterToDigiProducer::
00115 initialize(const edm::EventSetup& es) {
00116   uint32_t g_cache_id = es.get<SiStripGainRcd>().cacheIdentifier();
00117 
00118   if(g_cache_id != gain_cache_id) {
00119     es.get<SiStripGainRcd>().get( gainHandle );
00120     gain_cache_id = g_cache_id;
00121   }
00122 }
00123 
00124 
00125 inline 
00126 void SiStripClusterToDigiProducer::
00127 setDetId(const uint32_t id) {
00128   gainRange =  gainHandle->getRange(id); 
00129   detId = id;
00130 }
00131 
00132 inline
00133 uint16_t SiStripClusterToDigiProducer::
00134 applyGain(const uint16_t& strip,const uint16_t& adc ) {
00135 
00136   if(adc > 255) throw cms::Exception("Invalid Charge") << " digi at strip " << strip << " has ADC out of range " << adc;
00137   if(adc > 253) return adc; //saturated, do not scale
00138   uint16_t charge = static_cast<uint16_t>( adc*gain(strip) + 0.5 ); //NB: here we revert the gain applied at the clusterizer level. for this reason the adc counts are multiplied by gain and not divided
00139   return ( charge > 1022 ? 255 : 
00140           ( charge >  253 ? 254 : charge ));
00141 }
00142 
00143 
00144 
00145 #include "FWCore/PluginManager/interface/ModuleDef.h"
00146 #include "FWCore/Framework/interface/MakerMacros.h"
00147 DEFINE_FWK_MODULE(SiStripClusterToDigiProducer);