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() { }
00027
00028
00029 DataMixingSiStripRawWorker::DataMixingSiStripRawWorker(const edm::ParameterSet& ps) :
00030 label_(ps.getParameter<std::string>("Label"))
00031
00032 {
00033
00034
00035
00036
00037
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
00050 SiHitStorage_.clear();
00051
00052 }
00053
00054
00055
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 }
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 }
00101
00102
00103 void DataMixingSiStripRawWorker::putSiStrip(edm::Event &e) {
00104
00105
00106
00107
00108
00109
00110
00111 OneDetectorMap LocalMap;
00112
00113
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
00131
00132
00133
00134 std::vector< edm::DetSet<SiStripRawDigi> > vSiStripRawDigi;
00135
00136
00137 edm::DetSetVector<SiStripRawDigi>::const_iterator rawDSViter=rawdigicollection_->begin();
00138 for (; rawDSViter!=rawdigicollection_->end();rawDSViter++){
00139
00140
00141 edm::DetSet<SiStripRawDigi> SSRD(rawDSViter->id);
00142
00143
00144 SiGlobalIndex::const_iterator itest;
00145 itest = SiHitStorage_.find(rawDSViter->id);
00146
00147
00148 if(itest!=SiHitStorage_.end()) {
00149
00150 #ifdef DEBUG
00151 LogDebug("DataMixingSiStripRawWorker") << "Pileups: Processing DetID " << rawDSViter->id;
00152 #endif
00153
00154
00155 LocalMap = itest->second;
00156 OneDetectorMap::const_iterator iLocal = LocalMap.begin();
00157
00158
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
00166 if(iLocal->strip() == currentstrip) {
00167 ADCSum += iLocal->adc();
00168 iLocal++;
00169 }
00170
00171
00172 SSRD.push_back( SiStripRawDigi(ADCSum) );
00173 iRawDigi++;
00174 currentstrip++;
00175
00176 }
00177
00178
00179 vSiStripRawDigi.push_back(SSRD);
00180
00181
00182 } else {
00183 vSiStripRawDigi.push_back(*rawDSViter);
00184 }
00185
00186 }
00187
00188
00189
00190
00191
00192
00193
00194 std::auto_ptr< edm::DetSetVector<SiStripRawDigi> > MySiStripRawDigis(new edm::DetSetVector<SiStripRawDigi>(vSiStripRawDigi) );
00195
00196
00197 e.put( MySiStripRawDigis, SiStripDigiCollectionDM_ );
00198
00199
00200 SiHitStorage_.clear();
00201 }
00202
00203 }