CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/AnalysisAlgos/SiStripClusterInfoProducer/plugins/SiStripProcessedRawDigiProducer.cc

Go to the documentation of this file.
00001 #include "AnalysisAlgos/SiStripClusterInfoProducer/plugins/SiStripProcessedRawDigiProducer.h"
00002 
00003 #include "FWCore/Framework/interface/Event.h"
00004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00005 #include "FWCore/Framework/interface/EventSetup.h"
00006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00007 
00008 #include "CalibFormats/SiStripObjects/interface/SiStripGain.h"
00009 #include "CalibTracker/Records/interface/SiStripGainRcd.h"
00010 
00011 #include "DataFormats/SiStripDigi/interface/SiStripDigi.h"
00012 #include "DataFormats/SiStripDigi/interface/SiStripRawDigi.h"
00013 #include "DataFormats/SiStripDigi/interface/SiStripProcessedRawDigi.h"
00014 
00015 #include <functional>
00016 
00017 SiStripProcessedRawDigiProducer::SiStripProcessedRawDigiProducer(edm::ParameterSet const& conf) 
00018   : inputTags(conf.getParameter<std::vector<edm::InputTag> >("DigiProducersList")),
00019     subtractorPed(SiStripRawProcessingFactory::create_SubtractorPed(conf)),
00020     subtractorCMN(SiStripRawProcessingFactory::create_SubtractorCMN(conf)){
00021 
00022   produces< edm::DetSetVector<SiStripProcessedRawDigi> >("");
00023 }
00024 
00025 void SiStripProcessedRawDigiProducer::
00026 produce(edm::Event& e, const edm::EventSetup& es) {
00027 
00028   std::auto_ptr< edm::DetSetVector<SiStripProcessedRawDigi> > output(new edm::DetSetVector<SiStripProcessedRawDigi>());
00029   edm::Handle< edm::DetSetVector<SiStripDigi> > inputDigis; 
00030   edm::Handle< edm::DetSetVector<SiStripRawDigi> > inputRawdigis; 
00031 
00032   es.get<SiStripGainRcd>().get(gainHandle);
00033   subtractorPed->init(es);
00034   subtractorCMN->init(es);
00035   
00036   std::string label = findInput(inputRawdigis, e);
00037   if(      "VirginRaw"  == label )  vr_process(*inputRawdigis, *output); 
00038   else if( "ProcessedRaw" == label )  pr_process(*inputRawdigis, *output); 
00039   else if( "ZeroSuppressed" == findInput(inputDigis,e) ) zs_process(*inputDigis, *output);
00040   else 
00041     edm::LogError("Input Not Found");
00042 
00043   e.put(output);
00044 }
00045 
00046 template<class T>
00047 inline
00048 std::string SiStripProcessedRawDigiProducer::
00049 findInput(edm::Handle<T>& handle, const edm::Event& e ) {
00050 
00051   for( std::vector<edm::InputTag>::const_iterator 
00052          inputTag = inputTags.begin(); inputTag != inputTags.end(); ++inputTag ) {
00053     
00054     e.getByLabel(*inputTag, handle);
00055     if( handle.isValid() && !handle->empty() ) {
00056       edm::LogInfo("Input") << *inputTag;
00057       return inputTag->instance();
00058     }
00059   }
00060   return "Input Not Found";
00061 }
00062 
00063 
00064 void SiStripProcessedRawDigiProducer::
00065 zs_process(const edm::DetSetVector<SiStripDigi> & input, edm::DetSetVector<SiStripProcessedRawDigi>& output) {
00066   std::vector<float> digis;
00067   for(edm::DetSetVector<SiStripDigi>::const_iterator detset = input.begin(); detset != input.end(); detset++ )  {
00068     digis.clear();
00069     for(edm::DetSet<SiStripDigi>::const_iterator digi = detset->begin();  digi != detset->end();  digi++) {
00070       digis.resize( digi->strip(), 0);
00071       digis.push_back( digi->adc() );
00072     }
00073     common_process( detset->id, digis, output);
00074   }
00075 }
00076 
00077 void SiStripProcessedRawDigiProducer::
00078 pr_process(const edm::DetSetVector<SiStripRawDigi> & input, edm::DetSetVector<SiStripProcessedRawDigi>& output) {
00079   for(edm::DetSetVector<SiStripRawDigi>::const_iterator detset=input.begin(); detset!=input.end(); detset++) {
00080     std::vector<float> digis;
00081     transform(detset->begin(), detset->end(), back_inserter(digis), boost::bind(&SiStripRawDigi::adc , _1));
00082     subtractorCMN->subtract(detset->id, 0, digis);
00083     common_process( detset->id, digis, output);
00084   }
00085 }
00086 
00087 void SiStripProcessedRawDigiProducer::
00088 vr_process(const edm::DetSetVector<SiStripRawDigi> & input, edm::DetSetVector<SiStripProcessedRawDigi>& output) {
00089   for(edm::DetSetVector<SiStripRawDigi>::const_iterator detset=input.begin(); detset!=input.end(); detset++) {
00090     std::vector<int16_t> int_digis(detset->size());
00091     subtractorPed->subtract(*detset,int_digis);
00092     std::vector<float> digis(int_digis.begin(), int_digis.end());
00093     subtractorCMN->subtract(detset->id, 0, digis);
00094     common_process( detset->id, digis, output);
00095   }
00096 }
00097 
00098 void SiStripProcessedRawDigiProducer::
00099 common_process(const uint32_t detId, std::vector<float> & digis, edm::DetSetVector<SiStripProcessedRawDigi>& output) {
00100 
00101   //Apply Gains
00102   SiStripApvGain::Range detGainRange =  gainHandle->getRange(detId);   
00103   for(std::vector<float>::iterator it=digis.begin(); it<digis.end(); it++) 
00104     (*it)/= (gainHandle->getStripGain(it-digis.begin(), detGainRange));
00105 
00106   //Insert as DetSet
00107   edm::DetSet<SiStripProcessedRawDigi> ds(detId);
00108   copy(digis.begin(), digis.end(), back_inserter(ds.data) ); 
00109   output.insert(ds);
00110 }