CMS 3D CMS Logo

DataMixingSiPixelWorker.cc
Go to the documentation of this file.
1 // File: DataMixingSiPixelWorker.cc
2 // Description: see DataMixingSiPixelWorker.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  DataMixingSiPixelWorker::DataMixingSiPixelWorker() {}
22 
23  // Constructor
24  DataMixingSiPixelWorker::DataMixingSiPixelWorker(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  pixeldigi_collectionSig_ = ps.getParameter<edm::InputTag>("pixeldigiCollectionSig");
35  pixeldigi_collectionPile_ = ps.getParameter<edm::InputTag>("pixeldigiCollectionPile");
36  PixelDigiCollectionDM_ = ps.getParameter<std::string>("PixelDigiCollectionDM");
37 
40 
41  // clear local storage for this event
42  SiHitStorage_.clear();
43  }
44 
45  // Virtual destructor needed.
47 
49  // fill in maps of hits
50 
51  LogDebug("DataMixingSiPixelWorker") << "===============> adding MC signals for " << e.id();
52 
54 
55  if (e.getByToken(PixelDigiToken_, input)) {
56  // loop on all detsets (detectorIDs) inside the input collection
58  for (; DSViter != input->end(); DSViter++) {
59 #ifdef DEBUG
60  LogDebug("DataMixingSiPixelWorker") << "Processing DetID " << DSViter->id;
61 #endif
62 
63  uint32_t detID = DSViter->id;
64  edm::DetSet<PixelDigi>::const_iterator begin = (DSViter->data).begin();
67 
68  OneDetectorMap LocalMap;
69 
70  for (icopy = begin; icopy != end; icopy++) {
71  LocalMap.insert(OneDetectorMap::value_type((icopy->channel()), *icopy));
72  }
73 
74  SiHitStorage_.insert(SiGlobalIndex::value_type(detID, LocalMap));
75  }
76  }
77  } // end of addSiPixelSignals
78 
80  const EventPrincipal *ep,
81  unsigned int eventNr,
82  ModuleCallingContext const *mcc) {
83  LogDebug("DataMixingSiPixelWorker") << "\n===============> adding pileups from event " << ep->id()
84  << " for bunchcrossing " << bcr;
85 
86  // fill in maps of hits; same code as addSignals, except now applied to the
87  // pileup events
88 
89  std::shared_ptr<Wrapper<edm::DetSetVector<PixelDigi>> const> inputPTR =
90  getProductByTag<edm::DetSetVector<PixelDigi>>(*ep, pixeldigi_collectionPile_, mcc);
91 
92  if (inputPTR) {
93  const edm::DetSetVector<PixelDigi> *input = const_cast<edm::DetSetVector<PixelDigi> *>(inputPTR->product());
94 
95  // Handle< edm::DetSetVector<PixelDigi> > input;
96 
97  // if( e->getByLabel(pixeldigi_collectionPile_,input) ) {
98 
99  // loop on all detsets (detectorIDs) inside the input collection
101  for (; DSViter != input->end(); DSViter++) {
102 #ifdef DEBUG
103  LogDebug("DataMixingSiPixelWorker") << "Pileups: Processing DetID " << DSViter->id;
104 #endif
105 
106  uint32_t detID = DSViter->id;
107  edm::DetSet<PixelDigi>::const_iterator begin = (DSViter->data).begin();
108  edm::DetSet<PixelDigi>::const_iterator end = (DSViter->data).end();
110 
111  // find correct local map (or new one) for this detector ID
112 
113  SiGlobalIndex::const_iterator itest;
114 
115  itest = SiHitStorage_.find(detID);
116 
117  if (itest != SiHitStorage_.end()) { // this detID already has hits, add to existing map
118 
119  OneDetectorMap LocalMap = itest->second;
120 
121  // fill in local map with extra channels
122  for (icopy = begin; icopy != end; icopy++) {
123  LocalMap.insert(OneDetectorMap::value_type((icopy->channel()), *icopy));
124  }
125 
126  SiHitStorage_[detID] = LocalMap;
127 
128  } else { // fill local storage with this information, put in global
129  // collection
130 
131  OneDetectorMap LocalMap;
132 
133  for (icopy = begin; icopy != end; icopy++) {
134  LocalMap.insert(OneDetectorMap::value_type((icopy->channel()), *icopy));
135  }
136 
137  SiHitStorage_.insert(SiGlobalIndex::value_type(detID, LocalMap));
138  }
139  }
140  }
141  }
142 
144  // collection of Digis to put in the event
145 
146  std::vector<edm::DetSet<PixelDigi>> vPixelDigi;
147 
148  // loop through our collection of detectors, merging hits and putting new ones
149  // in the output
150 
151  // big loop over Detector IDs:
152 
153  for (SiGlobalIndex::const_iterator IDet = SiHitStorage_.begin(); IDet != SiHitStorage_.end(); IDet++) {
154  edm::DetSet<PixelDigi> SPD(IDet->first); // Make empty collection with this detector ID
155 
156  OneDetectorMap LocalMap = IDet->second;
157 
158  // counter variables
159  int formerPixel = -1;
160  int currentPixel;
161  int ADCSum = 0;
162 
163  OneDetectorMap::const_iterator iLocalchk;
164 
165  for (OneDetectorMap::const_iterator iLocal = LocalMap.begin(); iLocal != LocalMap.end(); ++iLocal) {
166  currentPixel = iLocal->first;
167 
168  if (currentPixel == formerPixel) { // we have to add these digis together
169  ADCSum += (iLocal->second).adc();
170  } else {
171  if (formerPixel != -1) { // ADC info stolen from SiStrips...
172  if (ADCSum > 511)
173  ADCSum = 255;
174  else if (ADCSum > 253 && ADCSum < 512)
175  ADCSum = 254;
176  PixelDigi aHit(formerPixel, ADCSum);
177  SPD.push_back(aHit);
178  }
179  // save pointers for next iteration
180  formerPixel = currentPixel;
181  ADCSum = (iLocal->second).adc();
182  }
183 
184  iLocalchk = iLocal;
185  if ((++iLocalchk) == LocalMap.end()) { // make sure not to lose the last one
186  if (ADCSum > 511)
187  ADCSum = 255;
188  else if (ADCSum > 253 && ADCSum < 512)
189  ADCSum = 254;
190  SPD.push_back(PixelDigi(formerPixel, ADCSum));
191  }
192 
193  } // end of loop over one detector
194 
195  // stick this into the global vector of detector info
196  vPixelDigi.push_back(SPD);
197 
198  } // end of big loop over all detector IDs
199 
200  // put the collection of digis in the event
201  LogInfo("DataMixingSiPixelWorker") << "total # Merged Pixels: " << vPixelDigi.size();
202 
203  // make new digi collection
204 
205  std::unique_ptr<edm::DetSetVector<PixelDigi>> MyPixelDigis(new edm::DetSetVector<PixelDigi>(vPixelDigi));
206 
207  // put collection
208 
209  e.put(std::move(MyPixelDigis), PixelDigiCollectionDM_);
210 
211  // clear local storage for this event
212  SiHitStorage_.clear();
213  }
214 
215 } // namespace edm
edm::DetSet::push_back
void push_back(const T &t)
Definition: DetSet.h:66
edm::DetSetVector
Definition: DetSetVector.h:61
edm::DataMixingSiPixelWorker::OneDetectorMap
std::multimap< int, PixelDigi > OneDetectorMap
Definition: DataMixingSiPixelWorker.h:67
Handle.h
input
static const std::string input
Definition: EdmProvDump.cc:48
MessageLogger.h
edm::DataMixingSiPixelWorker::SiHitStorage_
SiGlobalIndex SiHitStorage_
Definition: DataMixingSiPixelWorker.h:71
edm::DetSet
Definition: DetSet.h:23
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::DataMixingSiPixelWorker::~DataMixingSiPixelWorker
virtual ~DataMixingSiPixelWorker()
Definition: DataMixingSiPixelWorker.cc:46
edm::DataMixingSiPixelWorker::PixelDigiToken_
edm::EDGetTokenT< edm::DetSetVector< PixelDigi > > PixelDigiToken_
Definition: DataMixingSiPixelWorker.h:62
PixelDigi
Definition: PixelDigi.h:14
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
edm::Handle
Definition: AssociativeIterator.h:50
edm::DataMixingSiPixelWorker::addSiPixelPileups
void addSiPixelPileups(const int bcr, const edm::EventPrincipal *, unsigned int EventId, ModuleCallingContext const *)
Definition: DataMixingSiPixelWorker.cc:79
ecalLiteDTU::adc
constexpr int adc(sample_type sample)
get the ADC sample (12 bits)
Definition: EcalLiteDTUSample.h:12
edm::EventPrincipal
Definition: EventPrincipal.h:46
mps_fire.end
end
Definition: mps_fire.py:242
edm::DataMixingSiPixelWorker::pixeldigi_collectionSig_
edm::InputTag pixeldigi_collectionSig_
Definition: DataMixingSiPixelWorker.h:56
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:223
edm::ParameterSet
Definition: ParameterSet.h:47
edm::DataMixingSiPixelWorker::PixelDigiPToken_
edm::EDGetTokenT< edm::DetSetVector< PixelDigi > > PixelDigiPToken_
Definition: DataMixingSiPixelWorker.h:63
edm::DetSetVector::const_iterator
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:102
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition: JetExtendedAssociation.h:30
edm::DataMixingSiPixelWorker::pixeldigi_collectionPile_
edm::InputTag pixeldigi_collectionPile_
Definition: DataMixingSiPixelWorker.h:58
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
edm::DataMixingSiPixelWorker::addSiPixelSignals
void addSiPixelSignals(const edm::Event &e)
Definition: DataMixingSiPixelWorker.cc:48
edm::DataMixingSiPixelWorker::PixelDigiCollectionDM_
std::string PixelDigiCollectionDM_
Definition: DataMixingSiPixelWorker.h:60
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
DataMixingSiPixelWorker.h
edm::DataMixingSiPixelWorker::putSiPixel
void putSiPixel(edm::Event &e)
Definition: DataMixingSiPixelWorker.cc:143
edm::Event
Definition: Event.h:73
SiStripBadComponentsDQMServiceTemplate_cfg.ep
ep
Definition: SiStripBadComponentsDQMServiceTemplate_cfg.py:86
edm::InputTag
Definition: InputTag.h:15
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
edm::ModuleCallingContext
Definition: ModuleCallingContext.h:29
edm::DetSet::const_iterator
collection_type::const_iterator const_iterator
Definition: DetSet.h:31