CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DataMixingSiStripWorker.cc
Go to the documentation of this file.
1 // File: DataMixingSiStripWorker.cc
2 // Description: see DataMixingSiStripWorker.h
3 // Author: Mike Hildreth, University of Notre Dame
4 //
5 //--------------------------------------------
6 
9 #include <map>
10 #include <memory>
11 //
12 //
14 
15 using namespace std;
16 
17 namespace edm {
18 
19  // Virtual constructor
20 
21  DataMixingSiStripWorker::DataMixingSiStripWorker() {}
22 
23  // Constructor
24  DataMixingSiStripWorker::DataMixingSiStripWorker(const edm::ParameterSet &ps, edm::ConsumesCollector &&iC)
25  : label_(ps.getParameter<std::string>("Label"))
26 
27  {
28  // get the subdetector names
29  // this->getSubdetectorNames(); //something like this may be useful to
30  // check what we are supposed to do...
31 
32  // declare the products to produce
33 
34  SistripLabelSig_ = ps.getParameter<edm::InputTag>("SistripLabelSig");
35  SiStripPileInputTag_ = ps.getParameter<edm::InputTag>("SiStripPileInputTag");
36 
37  SiStripDigiCollectionDM_ = ps.getParameter<std::string>("SiStripDigiCollectionDM");
38 
41 
42  // clear local storage for this event
43  SiHitStorage_.clear();
44  }
45 
46  // Virtual destructor needed.
48 
50  // fill in maps of hits
51 
53 
54  if (e.getByToken(SiStripDigiToken_, input)) {
55  OneDetectorMap LocalMap;
56 
57  // loop on all detsets (detectorIDs) inside the input collection
58  edm::DetSetVector<SiStripDigi>::const_iterator DSViter = input->begin();
59  for (; DSViter != input->end(); DSViter++) {
60 #ifdef DEBUG
61  LogDebug("DataMixingSiStripWorker") << "Processing DetID " << DSViter->id;
62 #endif
63 
64  LocalMap.clear();
65  LocalMap.reserve((DSViter->data).size());
66  LocalMap.insert(LocalMap.end(), (DSViter->data).begin(), (DSViter->data).end());
67 
68  SiHitStorage_.insert(SiGlobalIndex::value_type(DSViter->id, LocalMap));
69  }
70  }
71  } // end of addSiStripSignals
72 
74  const EventPrincipal *ep,
75  unsigned int eventNr,
76  ModuleCallingContext const *mcc) {
77  LogDebug("DataMixingSiStripWorker") << "\n===============> adding pileups from event " << ep->id()
78  << " for bunchcrossing " << bcr;
79 
80  // fill in maps of hits; same code as addSignals, except now applied to the
81  // pileup events
82 
83  std::shared_ptr<Wrapper<edm::DetSetVector<SiStripDigi>> const> inputPTR =
84  getProductByTag<edm::DetSetVector<SiStripDigi>>(*ep, SiStripPileInputTag_, mcc);
85 
86  if (inputPTR) {
87  const edm::DetSetVector<SiStripDigi> *input = const_cast<edm::DetSetVector<SiStripDigi> *>(inputPTR->product());
88 
89  // Handle< edm::DetSetVector<SiStripDigi> > input;
90 
91  // if(
92  // e->getByLabel(Sistripdigi_collectionPile_.label(),SistripLabelPile_.label(),input)
93  // ) {
94 
95  OneDetectorMap LocalMap;
96 
97  // loop on all detsets (detectorIDs) inside the input collection
99  for (; DSViter != input->end(); DSViter++) {
100 #ifdef DEBUG
101  LogDebug("DataMixingSiStripWorker") << "Pileups: Processing DetID " << DSViter->id;
102 #endif
103 
104  // find correct local map (or new one) for this detector ID
105 
106  SiGlobalIndex::const_iterator itest;
107 
108  itest = SiHitStorage_.find(DSViter->id);
109 
110  if (itest != SiHitStorage_.end()) { // this detID already has hits, add to existing map
111 
112  LocalMap = itest->second;
113 
114  // fill in local map with extra channels
115  LocalMap.insert(LocalMap.end(), (DSViter->data).begin(), (DSViter->data).end());
116  std::stable_sort(LocalMap.begin(), LocalMap.end(), DataMixingSiStripWorker::StrictWeakOrdering());
117  SiHitStorage_[DSViter->id] = LocalMap;
118 
119  } else { // fill local storage with this information, put in global
120  // collection
121 
122  LocalMap.clear();
123  LocalMap.reserve((DSViter->data).size());
124  LocalMap.insert(LocalMap.end(), (DSViter->data).begin(), (DSViter->data).end());
125 
126  SiHitStorage_.insert(SiGlobalIndex::value_type(DSViter->id, LocalMap));
127  }
128  }
129  }
130  }
131 
133  // collection of Digis to put in the event
134  std::vector<edm::DetSet<SiStripDigi>> vSiStripDigi;
135 
136  // loop through our collection of detectors, merging hits and putting new ones
137  // in the output
138 
139  // big loop over Detector IDs:
140 
141  for (SiGlobalIndex::const_iterator IDet = SiHitStorage_.begin(); IDet != SiHitStorage_.end(); IDet++) {
142  edm::DetSet<SiStripDigi> SSD(IDet->first); // Make empty collection with this detector ID
143 
144  OneDetectorMap LocalMap = IDet->second;
145 
146  // counter variables
147  int formerStrip = -1;
148  int currentStrip;
149  int ADCSum = 0;
150 
151  OneDetectorMap::const_iterator iLocalchk;
152  OneDetectorMap::const_iterator iLocal = LocalMap.begin();
153  for (; iLocal != LocalMap.end(); ++iLocal) {
154  currentStrip = iLocal->strip();
155 
156  if (currentStrip == formerStrip) { // we have to add these digis together
157  ADCSum += iLocal->adc(); // on every element...
158  } else {
159  if (formerStrip != -1) {
160  if (ADCSum > 511)
161  ADCSum = 255;
162  else if (ADCSum > 253 && ADCSum < 512)
163  ADCSum = 254;
164  SiStripDigi aHit(formerStrip, ADCSum);
165  SSD.push_back(aHit);
166  }
167  // save pointers for next iteration
168  formerStrip = currentStrip;
169  ADCSum = iLocal->adc();
170  }
171 
172  iLocalchk = iLocal;
173  if ((++iLocalchk) == LocalMap.end()) { // make sure not to lose the last one
174  if (ADCSum > 511)
175  ADCSum = 255;
176  else if (ADCSum > 253 && ADCSum < 512)
177  ADCSum = 254;
178  SSD.push_back(SiStripDigi(formerStrip, ADCSum));
179  } // end of loop over one detector
180  }
181  // stick this into the global vector of detector info
182  vSiStripDigi.push_back(SSD);
183 
184  } // end of big loop over all detector IDs
185 
186  // put the collection of digis in the event
187  LogInfo("DataMixingSiStripWorker") << "total # Merged strips: " << vSiStripDigi.size();
188 
189  // make new digi collection
190 
191  std::unique_ptr<edm::DetSetVector<SiStripDigi>> MySiStripDigis(new edm::DetSetVector<SiStripDigi>(vSiStripDigi));
192 
193  // put collection
194 
195  e.put(std::move(MySiStripDigis), SiStripDigiCollectionDM_);
196 
197  // clear local storage for this event
198  SiHitStorage_.clear();
199  }
200 
201 } // namespace edm
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
void push_back(const T &t)
Definition: DetSet.h:66
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
void reserve(size_t s)
Definition: DetSetVector.h:147
EventID const & id() const
std::vector< SiStripDigi > OneDetectorMap
static std::string const input
Definition: EdmProvDump.cc:47
def move
Definition: eostools.py:511
A Digi for the silicon strip detector, containing both strip and adc information, and suitable for st...
Definition: SiStripDigi.h:12
iterator end()
Return the off-the-end iterator.
Definition: DetSetVector.h:325
void addSiStripPileups(const int bcr, const edm::EventPrincipal *, unsigned int EventId, ModuleCallingContext const *)
Log< level::Info, false > LogInfo
edm::EDGetTokenT< edm::DetSetVector< SiStripDigi > > SiStripDigiToken_
edm::EDGetTokenT< edm::DetSetVector< SiStripDigi > > SiStripDigiPToken_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void insert(detset const &s)
Insert the given DetSet.
Definition: DetSetVector.h:220
void addSiStripSignals(const edm::Event &e)
string end
Definition: dataset.py:937
iterator begin()
Return an iterator to the first DetSet.
Definition: DetSetVector.h:314
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:102
#define LogDebug(id)