CMS 3D CMS Logo

DataMixingSiStripRawWorker.cc
Go to the documentation of this file.
1 // File: DataMixingSiStripRawWorker.cc
2 // Description: see DataMixingSiStripRawWorker.h
3 // Author: Mike Hildreth, University of Notre Dame
4 //
5 //--------------------------------------------
6 
7 #include <map>
8 #include <memory>
16 //
17 //
19 
20 using namespace std;
21 
22 namespace edm
23 {
24 
25  // Virtual constructor
26 
27  DataMixingSiStripRawWorker::DataMixingSiStripRawWorker() { }
28 
29  // Constructor
30  DataMixingSiStripRawWorker::DataMixingSiStripRawWorker(const edm::ParameterSet& ps, edm::ConsumesCollector && iC) :
31  label_(ps.getParameter<std::string>("Label"))
32 
33  {
34 
35  // get the subdetector names
36  // this->getSubdetectorNames(); //something like this may be useful to check what we are supposed to do...
37 
38  // declare the products to produce
39 
40  Sistripdigi_collectionSig_ = ps.getParameter<edm::InputTag>("SistripdigiCollectionSig");
41  SistripLabelSig_ = ps.getParameter<edm::InputTag>("SistripLabelSig");
42 
43  SiStripPileInputTag_ = ps.getParameter<edm::InputTag>("SiStripPileInputTag");
44  SiStripRawInputTag_ = ps.getParameter<edm::InputTag>("SiStripRawInputTag");
45 
46  SiStripDigiCollectionDM_ = ps.getParameter<std::string>("SiStripDigiCollectionDM");
47 
48  SiStripRawDigiSource_ = ps.getParameter<std::string>("SiStripRawDigiSource");
49 
50  // clear local storage for this event
51  SiHitStorage_.clear();
52 
54 
57 
58  }
59 
60 
61  // Virtual destructor needed.
63  }
64 
65 
66 
68 
69 
72 
73  if (SiStripRawDigiSource_=="SIGNAL") {
75  rawdigicollection_ = hSSRD.product();
76  } else if (SiStripRawDigiSource_=="PILEUP") {
78  digicollection_ = hSSD.product();
79  } //else {
80  //std::cout << "you shouldn't be here" << std::endl;
81  //}
82 
83 
84  } // end of addSiStripSignals
85 
86 
87 
88  void DataMixingSiStripRawWorker::addSiStripPileups(const int bcr, const EventPrincipal *ep, unsigned int eventNr,
89  ModuleCallingContext const* mcc) {
90 
91  LogDebug("DataMixingSiStripRawWorker") << "\n===============> adding pileups from event "
92  << ep->id() << " for bunchcrossing " << bcr;
93 
94  std::shared_ptr<Wrapper<edm::DetSetVector<SiStripDigi> > const> pSSD;
95  std::shared_ptr<Wrapper<edm::DetSetVector<SiStripRawDigi> > const> pSSRD;
96 
97  if (SiStripRawDigiSource_=="SIGNAL") {
98  pSSD = getProductByTag<edm::DetSetVector<SiStripDigi> >(*ep, SiStripPileInputTag_, mcc);
99  digicollection_ = const_cast< edm::DetSetVector<SiStripDigi> * >(pSSD->product());
100  } else if (SiStripRawDigiSource_=="PILEUP") {
101  pSSRD = getProductByTag<edm::DetSetVector<SiStripRawDigi> >(*ep, SiStripRawInputTag_, mcc);
102  rawdigicollection_ = const_cast< edm::DetSetVector<SiStripRawDigi> * >(pSSRD->product());
103  } else {
104  std::cout << "you shouldn't be here" << std::endl;
105  }
106 
107  } // end of addSiStripPileups
108 
109 
111 
112 
113  //------------------
114  // (1) Fill a map from the Digi collection
115  //
116 
117  // fill in maps of SiStripDigis
118  OneDetectorMap LocalMap;
119 
120  //loop on all detsets (detectorIDs) inside the input collection
122  for (; DSViter!=digicollection_->end();DSViter++){
123 
124 #ifdef DEBUG
125  LogDebug("DataMixingSiStripRawWorker") << "Processing DetID " << DSViter->id;
126 #endif
127 
128  LocalMap.clear();
129  LocalMap.reserve((DSViter->data).size());
130  LocalMap.insert(LocalMap.end(),(DSViter->data).begin(),(DSViter->data).end());
131 
132  SiHitStorage_.insert( SiGlobalIndex::value_type( DSViter->id, LocalMap ) );
133  }
134 
135 
136  //------------------
137  // (2) Loop over the input RawDigi collection and add the Digis from the map
138  //
139 
140  // collection of RawDigis to put back in the event
141  std::vector< edm::DetSet<SiStripRawDigi> > vSiStripRawDigi;
142 
143  //loop on all detsets (detectorIDs) inside the SiStripRawDigis collection
145  for (; rawDSViter!=rawdigicollection_->end();rawDSViter++){
146 
147  // Make empty collection with this detID
148  edm::DetSet<SiStripRawDigi> SSRD(rawDSViter->id);
149 
150  // find local map (if it exists) for this detector ID
151  SiGlobalIndex::const_iterator itest;
152  itest = SiHitStorage_.find(rawDSViter->id);
153 
154  // if detID already has digis in existing map, add them to rawdigis
155  if(itest!=SiHitStorage_.end()) {
156 
157 #ifdef DEBUG
158  LogDebug("DataMixingSiStripRawWorker") << "Pileups: Processing DetID " << rawDSViter->id;
159 #endif
160 
161  // get the map from storage
162  LocalMap = itest->second;
163  OneDetectorMap::const_iterator iLocal = LocalMap.begin();
164 
165  // loop on all strips in rawdigi detset
166  int currentstrip=0;
167  edm::DetSet<SiStripRawDigi>::const_iterator iRawDigi = rawDSViter->begin();
168  while( iRawDigi != rawDSViter->end() ) {
169 
170  int ADCSum = iRawDigi->adc();
171 
172  // if current strip exists in map, add ADC values
173  if(iLocal->strip() == currentstrip) {
174  ADCSum += iLocal->adc();
175  iLocal++;
176  }
177 
178  // put ADC sum in DetSet and go to next strip
179  SSRD.push_back( SiStripRawDigi(ADCSum) );
180  iRawDigi++;
181  currentstrip++;
182 
183  }
184 
185  // copy combined digi+rawdigi into rawdigi DetSetVector
186  vSiStripRawDigi.push_back(SSRD);
187 
188  // otherwise, just copy the rawdigis from the background event to the output
189  } else {
190  vSiStripRawDigi.push_back(*rawDSViter);
191  }
192 
193  }
194 
195 
196  //------------------
197  // (3) Put the new RawDigi collection back into the event
198  //
199 
200  // make new raw digi collection
201  std::unique_ptr< edm::DetSetVector<SiStripRawDigi> > MySiStripRawDigis(new edm::DetSetVector<SiStripRawDigi>(vSiStripRawDigi) );
202 
203  // put collection
204  e.put(std::move(MySiStripRawDigis), SiStripDigiCollectionDM_ );
205 
206  // clear local storage for this event
207  SiHitStorage_.clear();
208  }
209 
210 }
#define LogDebug(id)
T getParameter(std::string const &) const
const edm::DetSetVector< SiStripDigi > * digicollection_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:136
void push_back(const T &t)
Definition: DetSet.h:68
void addSiStripSignals(const edm::Event &e)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
void reserve(size_t s)
Definition: DetSetVector.h:150
EventID const & id() const
edm::EDGetTokenT< edm::DetSetVector< SiStripDigi > > SiStripInputTok_
std::vector< SiStripDigi > OneDetectorMap
void addSiStripPileups(const int bcr, const edm::EventPrincipal *, unsigned int EventId, ModuleCallingContext const *)
#define end
Definition: vmac.h:39
iterator end()
Return the off-the-end iterator.
Definition: DetSetVector.h:361
T const * product() const
Definition: Handle.h:81
edm::EDGetTokenT< edm::DetSetVector< SiStripRawDigi > > SiStripRawInputTok_
std::string const & label() const
Definition: InputTag.h:36
#define begin
Definition: vmac.h:32
HLT enums.
iterator begin()
Return an iterator to the first DetSet.
Definition: DetSetVector.h:346
collection_type::const_iterator const_iterator
Definition: DetSet.h:33
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:104
const edm::DetSetVector< SiStripRawDigi > * rawdigicollection_
A Digi for the silicon strip detector, containing only adc information, and suitable for storing raw ...
def move(src, dest)
Definition: eostools.py:510