CMS 3D CMS Logo

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
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
edm::DetSet::push_back
void push_back(const T &t)
Definition: DetSet.h:66
edm::DetSetVector< SiStripDigi >
edm::DataMixingSiStripWorker::SiStripDigiToken_
edm::EDGetTokenT< edm::DetSetVector< SiStripDigi > > SiStripDigiToken_
Definition: DataMixingSiStripWorker.h:61
Handle.h
input
static const std::string input
Definition: EdmProvDump.cc:48
MessageLogger.h
edm::DataMixingSiStripWorker::~DataMixingSiStripWorker
virtual ~DataMixingSiStripWorker()
Definition: DataMixingSiStripWorker.cc:47
edm::DetSetVector::end
iterator end()
Return the off-the-end iterator.
Definition: DetSetVector.h:325
edm::DetSet< SiStripDigi >
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::LogInfo
Definition: MessageLogger.h:254
edm::DetSetVector::reserve
void reserve(size_t s)
Definition: DetSetVector.h:147
edm::DetSetVector::begin
iterator begin()
Return an iterator to the first DetSet.
Definition: DetSetVector.h:314
edm::DataMixingSiStripWorker::addSiStripPileups
void addSiStripPileups(const int bcr, const edm::EventPrincipal *, unsigned int EventId, ModuleCallingContext const *)
Definition: DataMixingSiStripWorker.cc:73
edm::Handle
Definition: AssociativeIterator.h:50
end
#define end
Definition: vmac.h:39
DataMixingSiStripWorker.h
edm::DataMixingSiStripWorker::addSiStripSignals
void addSiStripSignals(const edm::Event &e)
Definition: DataMixingSiStripWorker.cc:49
edm::DataMixingSiStripWorker::SiStripDigiPToken_
edm::EDGetTokenT< edm::DetSetVector< SiStripDigi > > SiStripDigiPToken_
Definition: DataMixingSiStripWorker.h:62
edm::DetSetVector::insert
void insert(detset const &s)
Insert the given DetSet.
Definition: DetSetVector.h:220
edm::EventPrincipal
Definition: EventPrincipal.h:46
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::DataMixingSiStripWorker::OneDetectorMap
std::vector< SiStripDigi > OneDetectorMap
Definition: DataMixingSiStripWorker.h:66
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
edm::ParameterSet
Definition: ParameterSet.h:36
edm::DataMixingSiStripWorker::SiHitStorage_
SiGlobalIndex SiHitStorage_
Definition: DataMixingSiStripWorker.h:70
edm::DetSetVector::const_iterator
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:102
edm::DataMixingSiStripWorker::putSiStrip
void putSiStrip(edm::Event &e)
Definition: DataMixingSiStripWorker.cc:132
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition: JetExtendedAssociation.h:30
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
edm::DataMixingSiStripWorker::StrictWeakOrdering
Definition: DataMixingSiStripWorker.h:76
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
edm::DataMixingSiStripWorker::SiStripPileInputTag_
edm::InputTag SiStripPileInputTag_
Definition: DataMixingSiStripWorker.h:57
SiStripDigi
A Digi for the silicon strip detector, containing both strip and adc information, and suitable for st...
Definition: SiStripDigi.h:12
edm::Event
Definition: Event.h:73
edm::DataMixingSiStripWorker::SistripLabelSig_
edm::InputTag SistripLabelSig_
Definition: DataMixingSiStripWorker.h:56
SiStripBadComponentsDQMServiceTemplate_cfg.ep
ep
Definition: SiStripBadComponentsDQMServiceTemplate_cfg.py:86
edm::InputTag
Definition: InputTag.h:15
begin
#define begin
Definition: vmac.h:32
edm::ConsumesCollector
Definition: ConsumesCollector.h:39
edm::DataMixingSiStripWorker::SiStripDigiCollectionDM_
std::string SiStripDigiCollectionDM_
Definition: DataMixingSiStripWorker.h:58
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
edm::ModuleCallingContext
Definition: ModuleCallingContext.h:29