File indexing completed on 2024-09-10 02:59:09
0001
0002
0003
0004
0005
0006
0007 #include "DataFormats/Common/interface/Handle.h"
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 #include <map>
0010 #include <memory>
0011
0012
0013 #include "DataMixingSiStripRawWorker.h"
0014
0015 using namespace std;
0016
0017 namespace edm {
0018
0019
0020
0021 DataMixingSiStripRawWorker::DataMixingSiStripRawWorker() {}
0022
0023
0024 DataMixingSiStripRawWorker::DataMixingSiStripRawWorker(const edm::ParameterSet &ps, edm::ConsumesCollector &&iC)
0025 : label_(ps.getParameter<std::string>("Label"))
0026
0027 {
0028
0029
0030
0031
0032
0033
0034 Sistripdigi_collectionSig_ = ps.getParameter<edm::InputTag>("SistripdigiCollectionSig");
0035 SistripLabelSig_ = ps.getParameter<edm::InputTag>("SistripLabelSig");
0036
0037 SiStripPileInputTag_ = ps.getParameter<edm::InputTag>("SiStripPileInputTag");
0038 SiStripRawInputTag_ = ps.getParameter<edm::InputTag>("SiStripRawInputTag");
0039
0040 SiStripDigiCollectionDM_ = ps.getParameter<std::string>("SiStripDigiCollectionDM");
0041
0042 SiStripRawDigiSource_ = ps.getParameter<std::string>("SiStripRawDigiSource");
0043
0044
0045 SiHitStorage_.clear();
0046
0047 edm::InputTag tag = edm::InputTag(Sistripdigi_collectionSig_.label(), SistripLabelSig_.label());
0048
0049 SiStripInputTok_ = iC.consumes<edm::DetSetVector<SiStripDigi>>(tag);
0050 SiStripRawInputTok_ = iC.consumes<edm::DetSetVector<SiStripRawDigi>>(SiStripRawInputTag_);
0051 }
0052
0053
0054 DataMixingSiStripRawWorker::~DataMixingSiStripRawWorker() {}
0055
0056 void DataMixingSiStripRawWorker::addSiStripSignals(const edm::Event &e) {
0057 edm::Handle<edm::DetSetVector<SiStripDigi>> hSSD;
0058 edm::Handle<edm::DetSetVector<SiStripRawDigi>> hSSRD;
0059
0060 if (SiStripRawDigiSource_ == "SIGNAL") {
0061 e.getByToken(SiStripRawInputTok_, hSSRD);
0062 rawdigicollection_ = hSSRD.product();
0063 } else if (SiStripRawDigiSource_ == "PILEUP") {
0064 e.getByToken(SiStripInputTok_, hSSD);
0065 digicollection_ = hSSD.product();
0066 }
0067
0068
0069
0070 }
0071
0072 void DataMixingSiStripRawWorker::addSiStripPileups(const int bcr,
0073 const EventPrincipal *ep,
0074 unsigned int eventNr,
0075 ModuleCallingContext const *mcc) {
0076 LogDebug("DataMixingSiStripRawWorker")
0077 << "\n===============> adding pileups from event " << ep->id() << " for bunchcrossing " << bcr;
0078
0079 std::shared_ptr<Wrapper<edm::DetSetVector<SiStripDigi>> const> pSSD;
0080 std::shared_ptr<Wrapper<edm::DetSetVector<SiStripRawDigi>> const> pSSRD;
0081
0082 if (SiStripRawDigiSource_ == "SIGNAL") {
0083 pSSD = getProductByTag<edm::DetSetVector<SiStripDigi>>(*ep, SiStripPileInputTag_, mcc);
0084 digicollection_ = const_cast<edm::DetSetVector<SiStripDigi> *>(pSSD->product());
0085 } else if (SiStripRawDigiSource_ == "PILEUP") {
0086 pSSRD = getProductByTag<edm::DetSetVector<SiStripRawDigi>>(*ep, SiStripRawInputTag_, mcc);
0087 rawdigicollection_ = const_cast<edm::DetSetVector<SiStripRawDigi> *>(pSSRD->product());
0088 } else {
0089 std::cout << "you shouldn't be here" << std::endl;
0090 }
0091
0092 }
0093
0094 void DataMixingSiStripRawWorker::putSiStrip(edm::Event &e) {
0095
0096
0097
0098
0099
0100 OneDetectorMap LocalMap;
0101
0102
0103 edm::DetSetVector<SiStripDigi>::const_iterator DSViter = digicollection_->begin();
0104 for (; DSViter != digicollection_->end(); DSViter++) {
0105 #ifdef DEBUG
0106 LogDebug("DataMixingSiStripRawWorker") << "Processing DetID " << DSViter->id;
0107 #endif
0108
0109 LocalMap.clear();
0110 LocalMap.reserve((DSViter->data).size());
0111 LocalMap.insert(LocalMap.end(), (DSViter->data).begin(), (DSViter->data).end());
0112
0113 SiHitStorage_.insert(SiGlobalIndex::value_type(DSViter->id, LocalMap));
0114 }
0115
0116
0117
0118
0119
0120
0121 std::vector<edm::DetSet<SiStripRawDigi>> vSiStripRawDigi;
0122
0123
0124 edm::DetSetVector<SiStripRawDigi>::const_iterator rawDSViter = rawdigicollection_->begin();
0125 for (; rawDSViter != rawdigicollection_->end(); rawDSViter++) {
0126
0127 edm::DetSet<SiStripRawDigi> SSRD(rawDSViter->id);
0128
0129
0130 SiGlobalIndex::const_iterator itest;
0131 itest = SiHitStorage_.find(rawDSViter->id);
0132
0133
0134 if (itest != SiHitStorage_.end()) {
0135 #ifdef DEBUG
0136 LogDebug("DataMixingSiStripRawWorker") << "Pileups: Processing DetID " << rawDSViter->id;
0137 #endif
0138
0139
0140 LocalMap = itest->second;
0141 OneDetectorMap::const_iterator iLocal = LocalMap.begin();
0142
0143
0144 int currentstrip = 0;
0145 edm::DetSet<SiStripRawDigi>::const_iterator iRawDigi = rawDSViter->begin();
0146 while (iRawDigi != rawDSViter->end()) {
0147 int ADCSum = iRawDigi->adc();
0148
0149
0150 if (iLocal->strip() == currentstrip) {
0151 ADCSum += iLocal->adc();
0152 iLocal++;
0153 }
0154
0155
0156 SSRD.push_back(SiStripRawDigi(ADCSum));
0157 iRawDigi++;
0158 currentstrip++;
0159 }
0160
0161
0162 vSiStripRawDigi.push_back(SSRD);
0163
0164
0165
0166 } else {
0167 vSiStripRawDigi.push_back(*rawDSViter);
0168 }
0169 }
0170
0171
0172
0173
0174
0175
0176 std::unique_ptr<edm::DetSetVector<SiStripRawDigi>> MySiStripRawDigis(
0177 new edm::DetSetVector<SiStripRawDigi>(vSiStripRawDigi));
0178
0179
0180 e.put(std::move(MySiStripRawDigis), SiStripDigiCollectionDM_);
0181
0182
0183 SiHitStorage_.clear();
0184 }
0185
0186 }