Go to the documentation of this file.00001
00002
00003
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
00025
00026 DataMixingSiStripRawWorker::DataMixingSiStripRawWorker() { sel_=0;}
00027
00028
00029 DataMixingSiStripRawWorker::DataMixingSiStripRawWorker(const edm::ParameterSet& ps) :
00030 label_(ps.getParameter<std::string>("Label"))
00031
00032 {
00033
00034
00035
00036
00037
00038 if (label_.size()>0){
00039 sel_=new Selector( ModuleLabelSelector(label_));
00040 }
00041 else {
00042 sel_=new Selector( MatchAllSelector());
00043 }
00044
00045
00046
00047 Sistripdigi_collectionSig_ = ps.getParameter<edm::InputTag>("SistripdigiCollectionSig");
00048 SistripLabelSig_ = ps.getParameter<edm::InputTag>("SistripLabelSig");
00049
00050 SiStripPileInputTag_ = ps.getParameter<edm::InputTag>("SiStripPileInputTag");
00051 SiStripRawInputTag_ = ps.getParameter<edm::InputTag>("SiStripRawInputTag");
00052
00053 SiStripDigiCollectionDM_ = ps.getParameter<std::string>("SiStripDigiCollectionDM");
00054
00055 SiStripRawDigiSource_ = ps.getParameter<std::string>("SiStripRawDigiSource");
00056
00057
00058 SiHitStorage_.clear();
00059
00060 }
00061
00062
00063
00064 DataMixingSiStripRawWorker::~DataMixingSiStripRawWorker() {
00065 delete sel_;
00066 sel_=0;
00067 }
00068
00069
00070
00071 void DataMixingSiStripRawWorker::addSiStripSignals(const edm::Event &e) {
00072
00073
00074 edm::Handle< edm::DetSetVector<SiStripDigi> > hSSD;
00075 edm::Handle< edm::DetSetVector<SiStripRawDigi> > hSSRD;
00076
00077 if (SiStripRawDigiSource_=="SIGNAL") {
00078 e.getByLabel(SiStripRawInputTag_,hSSRD);
00079 rawdigicollection_ = hSSRD.product();
00080 } else if (SiStripRawDigiSource_=="PILEUP") {
00081 e.getByLabel(Sistripdigi_collectionSig_.label(),SistripLabelSig_.label(),hSSD);
00082 digicollection_ = hSSD.product();
00083 } else {
00084 std::cout << "you shouldn't be here" << std::endl;
00085 }
00086
00087
00088 }
00089
00090
00091
00092 void DataMixingSiStripRawWorker::addSiStripPileups(const int bcr, const EventPrincipal *ep, unsigned int eventNr) {
00093
00094 LogDebug("DataMixingSiStripRawWorker") << "\n===============> adding pileups from event "
00095 << ep->id() << " for bunchcrossing " << bcr;
00096
00097 boost::shared_ptr<Wrapper<edm::DetSetVector<SiStripDigi> > const> pSSD;
00098 boost::shared_ptr<Wrapper<edm::DetSetVector<SiStripRawDigi> > const> pSSRD;
00099
00100 if (SiStripRawDigiSource_=="SIGNAL") {
00101 pSSD = getProductByTag<edm::DetSetVector<SiStripDigi> >(*ep, SiStripPileInputTag_);
00102 digicollection_ = const_cast< edm::DetSetVector<SiStripDigi> * >(pSSD->product());
00103 } else if (SiStripRawDigiSource_=="PILEUP") {
00104 pSSRD = getProductByTag<edm::DetSetVector<SiStripRawDigi> >(*ep, SiStripRawInputTag_ );
00105 rawdigicollection_ = const_cast< edm::DetSetVector<SiStripRawDigi> * >(pSSRD->product());
00106 } else {
00107 std::cout << "you shouldn't be here" << std::endl;
00108 }
00109
00110 }
00111
00112
00113 void DataMixingSiStripRawWorker::putSiStrip(edm::Event &e) {
00114
00115
00116
00117
00118
00119
00120
00121 OneDetectorMap LocalMap;
00122
00123
00124 edm::DetSetVector<SiStripDigi>::const_iterator DSViter=digicollection_->begin();
00125 for (; DSViter!=digicollection_->end();DSViter++){
00126
00127 #ifdef DEBUG
00128 LogDebug("DataMixingSiStripRawWorker") << "Processing DetID " << DSViter->id;
00129 #endif
00130
00131 LocalMap.clear();
00132 LocalMap.reserve((DSViter->data).size());
00133 LocalMap.insert(LocalMap.end(),(DSViter->data).begin(),(DSViter->data).end());
00134
00135 SiHitStorage_.insert( SiGlobalIndex::value_type( DSViter->id, LocalMap ) );
00136 }
00137
00138
00139
00140
00141
00142
00143
00144 std::vector< edm::DetSet<SiStripRawDigi> > vSiStripRawDigi;
00145
00146
00147 edm::DetSetVector<SiStripRawDigi>::const_iterator rawDSViter=rawdigicollection_->begin();
00148 for (; rawDSViter!=rawdigicollection_->end();rawDSViter++){
00149
00150
00151 edm::DetSet<SiStripRawDigi> SSRD(rawDSViter->id);
00152
00153
00154 SiGlobalIndex::const_iterator itest;
00155 itest = SiHitStorage_.find(rawDSViter->id);
00156
00157
00158 if(itest!=SiHitStorage_.end()) {
00159
00160 #ifdef DEBUG
00161 LogDebug("DataMixingSiStripRawWorker") << "Pileups: Processing DetID " << rawDSViter->id;
00162 #endif
00163
00164
00165 LocalMap = itest->second;
00166 OneDetectorMap::const_iterator iLocal = LocalMap.begin();
00167
00168
00169 int currentstrip=0;
00170 edm::DetSet<SiStripRawDigi>::const_iterator iRawDigi = rawDSViter->begin();
00171 while( iRawDigi != rawDSViter->end() ) {
00172
00173 int ADCSum = iRawDigi->adc();
00174
00175
00176 if(iLocal->strip() == currentstrip) {
00177 ADCSum += iLocal->adc();
00178 iLocal++;
00179 }
00180
00181
00182 SSRD.push_back( SiStripRawDigi(ADCSum) );
00183 iRawDigi++;
00184 currentstrip++;
00185
00186 }
00187
00188
00189 vSiStripRawDigi.push_back(SSRD);
00190
00191
00192 } else {
00193 vSiStripRawDigi.push_back(*rawDSViter);
00194 }
00195
00196 }
00197
00198
00199
00200
00201
00202
00203
00204 std::auto_ptr< edm::DetSetVector<SiStripRawDigi> > MySiStripRawDigis(new edm::DetSetVector<SiStripRawDigi>(vSiStripRawDigi) );
00205
00206
00207 e.put( MySiStripRawDigis, SiStripDigiCollectionDM_ );
00208
00209
00210 SiHitStorage_.clear();
00211 }
00212
00213 }