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() { sel_=0;}
00027
00028
00029 DataMixingSiStripWorker::DataMixingSiStripWorker(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_collection_ = ps.getParameter<edm::InputTag>("SistripdigiCollection");
00048 SistripLabel_ = ps.getParameter<edm::InputTag>("SistripLabel");
00049 SiStripDigiCollectionDM_ = ps.getParameter<std::string>("SiStripDigiCollectionDM");
00050
00051
00052 SiHitStorage_.clear();
00053
00054 }
00055
00056
00057
00058 DataMixingSiStripWorker::~DataMixingSiStripWorker() {
00059 delete sel_;
00060 sel_=0;
00061 }
00062
00063
00064
00065 void DataMixingSiStripWorker::addSiStripSignals(const edm::Event &e) {
00066
00067
00068 Handle< edm::DetSetVector<SiStripDigi> > input;
00069
00070 if( e.getByLabel(Sistripdigi_collection_.label(),SistripLabel_.label(),input) ) {
00071 OneDetectorMap LocalMap;
00072
00073
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 }
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
00097
00098 Handle< edm::DetSetVector<SiStripDigi> > input;
00099
00100 if( e->getByLabel(Sistripdigi_collection_.label(),SistripLabel_.label(),input) ) {
00101
00102 OneDetectorMap LocalMap;
00103
00104
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
00113
00114 SiGlobalIndex::const_iterator itest;
00115
00116 itest = SiHitStorage_.find(DSViter->id);
00117
00118 if(itest!=SiHitStorage_.end()) {
00119
00120 LocalMap = itest->second;
00121
00122
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{
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
00145 std::vector< edm::DetSet<SiStripDigi> > vSiStripDigi;
00146
00147
00148
00149
00150
00151 for(SiGlobalIndex::const_iterator IDet = SiHitStorage_.begin();
00152 IDet != SiHitStorage_.end(); IDet++) {
00153
00154 edm::DetSet<SiStripDigi> SSD(IDet->first);
00155
00156 OneDetectorMap LocalMap = IDet->second;
00157
00158
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) {
00170 ADCSum+=iLocal->adc();
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
00180 formerStrip = currentStrip;
00181 ADCSum = iLocal->adc();
00182 }
00183
00184 iLocalchk = iLocal;
00185 if((++iLocalchk) == LocalMap.end()) {
00186 if (ADCSum > 511) ADCSum = 255;
00187 else if (ADCSum > 253 && ADCSum < 512) ADCSum = 254;
00188 SSD.push_back( SiStripDigi(formerStrip, ADCSum) );
00189 }
00190
00191 }
00192
00193 vSiStripDigi.push_back(SSD);
00194
00195 }
00196
00197
00198 LogInfo("DataMixingSiStripWorker") << "total # Merged strips: " << vSiStripDigi.size() ;
00199
00200
00201
00202 std::auto_ptr< edm::DetSetVector<SiStripDigi> > MySiStripDigis(new edm::DetSetVector<SiStripDigi>(vSiStripDigi) );
00203
00204
00205
00206 e.put( MySiStripDigis, SiStripDigiCollectionDM_ );
00207
00208
00209 SiHitStorage_.clear();
00210 }
00211
00212 }