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