CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/SimGeneral/DataMixingModule/plugins/DataMixingSiStripRawWorker.cc

Go to the documentation of this file.
00001 // File: DataMixingSiStripRawWorker.cc
00002 // Description:  see DataMixingSiStripRawWorker.h
00003 // Author:  Mike Hildreth, University of Notre Dame
00004 //
00005 //--------------------------------------------
00006 
00007 #include <map>
00008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00009 #include "FWCore/Utilities/interface/EDMException.h"
00010 #include "FWCore/Framework/interface/ConstProductRegistry.h"
00011 #include "FWCore/ServiceRegistry/interface/Service.h"
00012 #include "DataFormats/Common/interface/Handle.h"
00013 #include "DataFormats/Provenance/interface/Provenance.h"
00014 #include "DataFormats/Provenance/interface/BranchDescription.h"
00015 //
00016 //
00017 #include "DataMixingSiStripRawWorker.h"
00018 
00019 using namespace std;
00020 
00021 namespace edm
00022 {
00023 
00024   // Virtual constructor
00025 
00026   DataMixingSiStripRawWorker::DataMixingSiStripRawWorker() { }
00027 
00028   // Constructor 
00029   DataMixingSiStripRawWorker::DataMixingSiStripRawWorker(const edm::ParameterSet& ps) : 
00030                                                             label_(ps.getParameter<std::string>("Label"))
00031 
00032   {                                                         
00033 
00034     // get the subdetector names
00035     //    this->getSubdetectorNames();  //something like this may be useful to check what we are supposed to do...
00036 
00037     // declare the products to produce
00038 
00039     Sistripdigi_collectionSig_   = ps.getParameter<edm::InputTag>("SistripdigiCollectionSig");
00040     SistripLabelSig_   = ps.getParameter<edm::InputTag>("SistripLabelSig");
00041 
00042     SiStripPileInputTag_ = ps.getParameter<edm::InputTag>("SiStripPileInputTag");
00043     SiStripRawInputTag_ = ps.getParameter<edm::InputTag>("SiStripRawInputTag");
00044 
00045     SiStripDigiCollectionDM_  = ps.getParameter<std::string>("SiStripDigiCollectionDM");
00046 
00047     SiStripRawDigiSource_ = ps.getParameter<std::string>("SiStripRawDigiSource");
00048 
00049     // clear local storage for this event                                                                     
00050     SiHitStorage_.clear();
00051 
00052   }
00053                
00054 
00055   // Virtual destructor needed.
00056   DataMixingSiStripRawWorker::~DataMixingSiStripRawWorker() { 
00057   }  
00058 
00059 
00060 
00061   void DataMixingSiStripRawWorker::addSiStripSignals(const edm::Event &e) { 
00062 
00063     
00064     edm::Handle< edm::DetSetVector<SiStripDigi> >      hSSD;
00065     edm::Handle< edm::DetSetVector<SiStripRawDigi> >   hSSRD;
00066     
00067     if (SiStripRawDigiSource_=="SIGNAL") {
00068       e.getByLabel(SiStripRawInputTag_,hSSRD);
00069       rawdigicollection_ = hSSRD.product();
00070     } else if (SiStripRawDigiSource_=="PILEUP") {
00071       e.getByLabel(Sistripdigi_collectionSig_.label(),SistripLabelSig_.label(),hSSD);
00072       digicollection_ =  hSSD.product();
00073     } else {
00074       std::cout << "you shouldn't be here" << std::endl;
00075     }
00076     
00077 
00078   } // end of addSiStripSignals
00079 
00080 
00081 
00082   void DataMixingSiStripRawWorker::addSiStripPileups(const int bcr, const EventPrincipal *ep, unsigned int eventNr) {
00083     
00084     LogDebug("DataMixingSiStripRawWorker") << "\n===============> adding pileups from event  "
00085                                            << ep->id() << " for bunchcrossing " << bcr;
00086 
00087     boost::shared_ptr<Wrapper<edm::DetSetVector<SiStripDigi> > const>    pSSD;
00088     boost::shared_ptr<Wrapper<edm::DetSetVector<SiStripRawDigi> > const> pSSRD;
00089     
00090     if (SiStripRawDigiSource_=="SIGNAL") {
00091       pSSD = getProductByTag<edm::DetSetVector<SiStripDigi> >(*ep, SiStripPileInputTag_);
00092       digicollection_ = const_cast< edm::DetSetVector<SiStripDigi> * >(pSSD->product());
00093     } else if (SiStripRawDigiSource_=="PILEUP") {
00094       pSSRD = getProductByTag<edm::DetSetVector<SiStripRawDigi> >(*ep, SiStripRawInputTag_ );
00095       rawdigicollection_ = const_cast< edm::DetSetVector<SiStripRawDigi> * >(pSSRD->product());
00096     } else {
00097       std::cout << "you shouldn't be here" << std::endl;
00098     }
00099 
00100   } // end of addSiStripPileups
00101 
00102  
00103   void DataMixingSiStripRawWorker::putSiStrip(edm::Event &e) {
00104 
00105 
00106     //------------------
00107     //  (1) Fill a map from the Digi collection
00108     //
00109 
00110     // fill in maps of SiStripDigis
00111     OneDetectorMap LocalMap;
00112     
00113     //loop on all detsets (detectorIDs) inside the input collection
00114     edm::DetSetVector<SiStripDigi>::const_iterator DSViter=digicollection_->begin();
00115     for (; DSViter!=digicollection_->end();DSViter++){
00116       
00117 #ifdef DEBUG
00118       LogDebug("DataMixingSiStripRawWorker")  << "Processing DetID " << DSViter->id;
00119 #endif
00120       
00121       LocalMap.clear();
00122       LocalMap.reserve((DSViter->data).size());
00123       LocalMap.insert(LocalMap.end(),(DSViter->data).begin(),(DSViter->data).end());    
00124       
00125       SiHitStorage_.insert( SiGlobalIndex::value_type( DSViter->id, LocalMap ) );
00126     }
00127 
00128 
00129     //------------------
00130     //  (2) Loop over the input RawDigi collection and add the Digis from the map
00131     //
00132 
00133     // collection of RawDigis to put back in the event
00134     std::vector< edm::DetSet<SiStripRawDigi> > vSiStripRawDigi;
00135 
00136     //loop on all detsets (detectorIDs) inside the SiStripRawDigis collection
00137     edm::DetSetVector<SiStripRawDigi>::const_iterator rawDSViter=rawdigicollection_->begin();
00138     for (; rawDSViter!=rawdigicollection_->end();rawDSViter++){
00139 
00140       // Make empty collection with this detID
00141       edm::DetSet<SiStripRawDigi> SSRD(rawDSViter->id); 
00142 
00143       // find local map (if it exists) for this detector ID
00144       SiGlobalIndex::const_iterator itest;
00145       itest = SiHitStorage_.find(rawDSViter->id);
00146 
00147       // if detID already has digis in existing map, add them to rawdigis
00148       if(itest!=SiHitStorage_.end()) {  
00149 
00150 #ifdef DEBUG
00151         LogDebug("DataMixingSiStripRawWorker")  << "Pileups: Processing DetID " << rawDSViter->id;
00152 #endif
00153 
00154         // get the map from storage
00155         LocalMap = itest->second;
00156         OneDetectorMap::const_iterator iLocal  = LocalMap.begin();
00157 
00158         // loop on all strips in rawdigi detset
00159         int currentstrip=0;
00160         edm::DetSet<SiStripRawDigi>::const_iterator iRawDigi = rawDSViter->begin();
00161         while( iRawDigi != rawDSViter->end() ) {
00162 
00163           int ADCSum = iRawDigi->adc();
00164 
00165           // if current strip exists in map, add ADC values
00166           if(iLocal->strip() == currentstrip) {
00167             ADCSum += iLocal->adc();
00168             iLocal++;
00169           }
00170 
00171           // put ADC sum in DetSet and go to next strip
00172           SSRD.push_back( SiStripRawDigi(ADCSum) );
00173           iRawDigi++;
00174           currentstrip++;
00175 
00176         }
00177 
00178         // copy combined digi+rawdigi into rawdigi DetSetVector
00179         vSiStripRawDigi.push_back(SSRD);
00180 
00181       // otherwise, just copy the rawdigis from the background event to the output
00182       } else {
00183         vSiStripRawDigi.push_back(*rawDSViter);
00184       }
00185 
00186     }
00187 
00188 
00189     //------------------
00190     //  (3) Put the new RawDigi collection back into the event
00191     //
00192 
00193     // make new raw digi collection
00194     std::auto_ptr< edm::DetSetVector<SiStripRawDigi> > MySiStripRawDigis(new edm::DetSetVector<SiStripRawDigi>(vSiStripRawDigi) );
00195 
00196     // put collection
00197     e.put( MySiStripRawDigis, SiStripDigiCollectionDM_ );
00198 
00199     // clear local storage for this event
00200     SiHitStorage_.clear();
00201   }
00202 
00203 }