CMS 3D CMS Logo

DataMixingSiStripWorker.cc

Go to the documentation of this file.
00001 // File: DataMixingSiStripWorker.cc
00002 // Description:  see DataMixingSiStripWorker.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 "DataMixingSiStripWorker.h"
00018 
00019 using namespace std;
00020 
00021 namespace edm
00022 {
00023 
00024   // Virtual constructor
00025 
00026   DataMixingSiStripWorker::DataMixingSiStripWorker() { sel_=0;}
00027 
00028   // Constructor 
00029   DataMixingSiStripWorker::DataMixingSiStripWorker(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     // create input selector
00038     if (label_.size()>0){
00039       sel_=new Selector( ModuleLabelSelector(label_));
00040     }
00041     else {
00042       sel_=new Selector( MatchAllSelector());
00043     }
00044 
00045     // declare the products to produce
00046 
00047     Sistripdigi_collection_   = ps.getParameter<edm::InputTag>("SistripdigiCollection");
00048     SistripLabel_   = ps.getParameter<edm::InputTag>("SistripLabel");
00049     SiStripDigiCollectionDM_  = ps.getParameter<std::string>("SiStripDigiCollectionDM");
00050 
00051     // clear local storage for this event                                                                     
00052     SiHitStorage_.clear();
00053 
00054   }
00055                
00056 
00057   // Virtual destructor needed.
00058   DataMixingSiStripWorker::~DataMixingSiStripWorker() { 
00059     delete sel_;
00060     sel_=0;
00061   }  
00062 
00063 
00064 
00065   void DataMixingSiStripWorker::addSiStripSignals(const edm::Event &e) { 
00066     // fill in maps of hits
00067 
00068     Handle< edm::DetSetVector<SiStripDigi> >  input;
00069 
00070     if( e.getByLabel(Sistripdigi_collection_.label(),SistripLabel_.label(),input) ) {
00071       OneDetectorMap LocalMap;
00072 
00073       //loop on all detsets (detectorIDs) inside the input collection
00074       edm::DetSetVector<SiStripDigi>::const_iterator DSViter=input->begin();
00075       for (; DSViter!=input->end();DSViter++){
00076 
00077 #ifdef DEBUG
00078         LogDebug("DataMixingSiStripWorker")  << "Processing DetID " << DSViter->id;
00079 #endif
00080 
00081         LocalMap.clear();
00082         LocalMap.reserve((DSViter->data).size());
00083         LocalMap.insert(LocalMap.end(),(DSViter->data).begin(),(DSViter->data).end());  
00084         
00085         SiHitStorage_.insert( SiGlobalIndex::value_type( DSViter->id, LocalMap ) );
00086       }
00087  
00088     }
00089   } // end of addSiStripSignals
00090 
00091 
00092 
00093   void DataMixingSiStripWorker::addSiStripPileups(const int bcr, Event *e, unsigned int eventNr) {
00094     LogDebug("DataMixingSiStripWorker") <<"\n===============> adding pileups from event  "<<e->id()<<" for bunchcrossing "<<bcr;
00095 
00096     // fill in maps of hits; same code as addSignals, except now applied to the pileup events
00097 
00098     Handle< edm::DetSetVector<SiStripDigi> >  input;
00099 
00100     if( e->getByLabel(Sistripdigi_collection_.label(),SistripLabel_.label(),input) ) {
00101 
00102       OneDetectorMap LocalMap;
00103 
00104       //loop on all detsets (detectorIDs) inside the input collection
00105       edm::DetSetVector<SiStripDigi>::const_iterator DSViter=input->begin();
00106       for (; DSViter!=input->end();DSViter++){
00107 
00108 #ifdef DEBUG
00109         LogDebug("DataMixingSiStripWorker")  << "Pileups: Processing DetID " << DSViter->id;
00110 #endif
00111 
00112         // find correct local map (or new one) for this detector ID
00113 
00114         SiGlobalIndex::const_iterator itest;
00115 
00116         itest = SiHitStorage_.find(DSViter->id);
00117 
00118         if(itest!=SiHitStorage_.end()) {  // this detID already has hits, add to existing map
00119 
00120           LocalMap = itest->second;
00121 
00122           // fill in local map with extra channels
00123           LocalMap.insert(LocalMap.end(),(DSViter->data).begin(),(DSViter->data).end());
00124           std::stable_sort(LocalMap.begin(),LocalMap.end(),DataMixingSiStripWorker::StrictWeakOrdering());
00125           SiHitStorage_[DSViter->id]=LocalMap;
00126           
00127         }
00128         else{ // fill local storage with this information, put in global collection
00129 
00130           LocalMap.clear();
00131           LocalMap.reserve((DSViter->data).size());
00132           LocalMap.insert(LocalMap.end(),(DSViter->data).begin(),(DSViter->data).end());
00133 
00134           SiHitStorage_.insert( SiGlobalIndex::value_type( DSViter->id, LocalMap ) );
00135         }
00136       }
00137     }
00138   }
00139 
00140 
00141  
00142   void DataMixingSiStripWorker::putSiStrip(edm::Event &e) {
00143 
00144     // collection of Digis to put in the event
00145     std::vector< edm::DetSet<SiStripDigi> > vSiStripDigi;
00146 
00147     // loop through our collection of detectors, merging hits and putting new ones in the output
00148 
00149     // big loop over Detector IDs:
00150 
00151     for(SiGlobalIndex::const_iterator IDet = SiHitStorage_.begin();
00152         IDet != SiHitStorage_.end(); IDet++) {
00153 
00154       edm::DetSet<SiStripDigi> SSD(IDet->first); // Make empty collection with this detector ID
00155         
00156       OneDetectorMap LocalMap = IDet->second;
00157 
00158       //counter variables
00159       int formerStrip = -1;
00160       int currentStrip;
00161       int ADCSum = 0;
00162 
00163       OneDetectorMap::const_iterator iLocalchk;
00164       OneDetectorMap::const_iterator iLocal  = LocalMap.begin();
00165       for(;iLocal != LocalMap.end(); ++iLocal) {
00166 
00167         currentStrip = iLocal->strip(); 
00168 
00169         if (currentStrip == formerStrip) { // we have to add these digis together
00170           ADCSum+=iLocal->adc();          // on every element...
00171         }
00172         else{
00173           if(formerStrip!=-1){
00174             if (ADCSum > 511) ADCSum = 255;
00175             else if (ADCSum > 253 && ADCSum < 512) ADCSum = 254;
00176             SiStripDigi aHit(formerStrip, ADCSum);
00177             SSD.push_back( aHit );        
00178           }
00179           // save pointers for next iteration
00180           formerStrip = currentStrip;
00181           ADCSum = iLocal->adc();
00182         }
00183 
00184         iLocalchk = iLocal;
00185         if((++iLocalchk) == LocalMap.end()) {  //make sure not to lose the last one
00186           if (ADCSum > 511) ADCSum = 255;
00187           else if (ADCSum > 253 && ADCSum < 512) ADCSum = 254;
00188           SSD.push_back( SiStripDigi(formerStrip, ADCSum) );      
00189         } // end of loop over one detector
00190         
00191       }
00192       // stick this into the global vector of detector info
00193       vSiStripDigi.push_back(SSD);
00194 
00195     } // end of big loop over all detector IDs
00196 
00197     // put the collection of digis in the event   
00198     LogInfo("DataMixingSiStripWorker") << "total # Merged strips: " << vSiStripDigi.size() ;
00199 
00200     // make new digi collection
00201     
00202     std::auto_ptr< edm::DetSetVector<SiStripDigi> > MySiStripDigis(new edm::DetSetVector<SiStripDigi>(vSiStripDigi) );
00203 
00204     // put collection
00205 
00206     e.put( MySiStripDigis, SiStripDigiCollectionDM_ );
00207 
00208     // clear local storage for this event
00209     SiHitStorage_.clear();
00210   }
00211 
00212 } //edm

Generated on Tue Jun 9 17:47:27 2009 for CMSSW by  doxygen 1.5.4