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 "DataMixingSiStripWorker.h"
00018
00019 using namespace std;
00020
00021 namespace edm
00022 {
00023
00024
00025
00026 DataMixingSiStripWorker::DataMixingSiStripWorker() { }
00027
00028
00029 DataMixingSiStripWorker::DataMixingSiStripWorker(const edm::ParameterSet& ps) :
00030 label_(ps.getParameter<std::string>("Label"))
00031
00032 {
00033
00034
00035
00036
00037
00038
00039 SistripLabelSig_ = ps.getParameter<edm::InputTag>("SistripLabelSig");
00040 SiStripPileInputTag_ = ps.getParameter<edm::InputTag>("SiStripPileInputTag");
00041
00042 SiStripDigiCollectionDM_ = ps.getParameter<std::string>("SiStripDigiCollectionDM");
00043
00044
00045 SiHitStorage_.clear();
00046
00047 }
00048
00049
00050
00051 DataMixingSiStripWorker::~DataMixingSiStripWorker() {
00052 }
00053
00054
00055
00056 void DataMixingSiStripWorker::addSiStripSignals(const edm::Event &e) {
00057
00058
00059 Handle< edm::DetSetVector<SiStripDigi> > input;
00060
00061 if( e.getByLabel(SistripLabelSig_,input) ) {
00062 OneDetectorMap LocalMap;
00063
00064
00065 edm::DetSetVector<SiStripDigi>::const_iterator DSViter=input->begin();
00066 for (; DSViter!=input->end();DSViter++){
00067
00068 #ifdef DEBUG
00069 LogDebug("DataMixingSiStripWorker") << "Processing DetID " << DSViter->id;
00070 #endif
00071
00072 LocalMap.clear();
00073 LocalMap.reserve((DSViter->data).size());
00074 LocalMap.insert(LocalMap.end(),(DSViter->data).begin(),(DSViter->data).end());
00075
00076 SiHitStorage_.insert( SiGlobalIndex::value_type( DSViter->id, LocalMap ) );
00077 }
00078
00079 }
00080 }
00081
00082
00083
00084 void DataMixingSiStripWorker::addSiStripPileups(const int bcr, const EventPrincipal *ep, unsigned int eventNr) {
00085 LogDebug("DataMixingSiStripWorker") <<"\n===============> adding pileups from event "<<ep->id()<<" for bunchcrossing "<<bcr;
00086
00087
00088
00089 boost::shared_ptr<Wrapper<edm::DetSetVector<SiStripDigi> > const> inputPTR =
00090 getProductByTag<edm::DetSetVector<SiStripDigi> >(*ep, SiStripPileInputTag_ );
00091
00092 if(inputPTR ) {
00093
00094 const edm::DetSetVector<SiStripDigi> *input = const_cast< edm::DetSetVector<SiStripDigi> * >(inputPTR->product());
00095
00096
00097
00098
00099
00100 OneDetectorMap LocalMap;
00101
00102
00103 edm::DetSetVector<SiStripDigi>::const_iterator DSViter=input->begin();
00104 for (; DSViter!=input->end();DSViter++){
00105
00106 #ifdef DEBUG
00107 LogDebug("DataMixingSiStripWorker") << "Pileups: Processing DetID " << DSViter->id;
00108 #endif
00109
00110
00111
00112 SiGlobalIndex::const_iterator itest;
00113
00114 itest = SiHitStorage_.find(DSViter->id);
00115
00116 if(itest!=SiHitStorage_.end()) {
00117
00118 LocalMap = itest->second;
00119
00120
00121 LocalMap.insert(LocalMap.end(),(DSViter->data).begin(),(DSViter->data).end());
00122 std::stable_sort(LocalMap.begin(),LocalMap.end(),DataMixingSiStripWorker::StrictWeakOrdering());
00123 SiHitStorage_[DSViter->id]=LocalMap;
00124
00125 }
00126 else{
00127
00128 LocalMap.clear();
00129 LocalMap.reserve((DSViter->data).size());
00130 LocalMap.insert(LocalMap.end(),(DSViter->data).begin(),(DSViter->data).end());
00131
00132 SiHitStorage_.insert( SiGlobalIndex::value_type( DSViter->id, LocalMap ) );
00133 }
00134 }
00135 }
00136 }
00137
00138
00139
00140 void DataMixingSiStripWorker::putSiStrip(edm::Event &e) {
00141
00142
00143 std::vector< edm::DetSet<SiStripDigi> > vSiStripDigi;
00144
00145
00146
00147
00148
00149 for(SiGlobalIndex::const_iterator IDet = SiHitStorage_.begin();
00150 IDet != SiHitStorage_.end(); IDet++) {
00151
00152 edm::DetSet<SiStripDigi> SSD(IDet->first);
00153
00154 OneDetectorMap LocalMap = IDet->second;
00155
00156
00157 int formerStrip = -1;
00158 int currentStrip;
00159 int ADCSum = 0;
00160
00161 OneDetectorMap::const_iterator iLocalchk;
00162 OneDetectorMap::const_iterator iLocal = LocalMap.begin();
00163 for(;iLocal != LocalMap.end(); ++iLocal) {
00164
00165 currentStrip = iLocal->strip();
00166
00167 if (currentStrip == formerStrip) {
00168 ADCSum+=iLocal->adc();
00169 }
00170 else{
00171 if(formerStrip!=-1){
00172 if (ADCSum > 511) ADCSum = 255;
00173 else if (ADCSum > 253 && ADCSum < 512) ADCSum = 254;
00174 SiStripDigi aHit(formerStrip, ADCSum);
00175 SSD.push_back( aHit );
00176 }
00177
00178 formerStrip = currentStrip;
00179 ADCSum = iLocal->adc();
00180 }
00181
00182 iLocalchk = iLocal;
00183 if((++iLocalchk) == LocalMap.end()) {
00184 if (ADCSum > 511) ADCSum = 255;
00185 else if (ADCSum > 253 && ADCSum < 512) ADCSum = 254;
00186 SSD.push_back( SiStripDigi(formerStrip, ADCSum) );
00187 }
00188
00189 }
00190
00191 vSiStripDigi.push_back(SSD);
00192
00193 }
00194
00195
00196 LogInfo("DataMixingSiStripWorker") << "total # Merged strips: " << vSiStripDigi.size() ;
00197
00198
00199
00200 std::auto_ptr< edm::DetSetVector<SiStripDigi> > MySiStripDigis(new edm::DetSetVector<SiStripDigi>(vSiStripDigi) );
00201
00202
00203
00204 e.put( MySiStripDigis, SiStripDigiCollectionDM_ );
00205
00206
00207 SiHitStorage_.clear();
00208 }
00209
00210 }