CMS 3D CMS Logo

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