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) :
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 
52  }
53 
54 
55  // Virtual destructor needed.
57  }
58 
59 
60 
62 
63 
66 
67  if (SiStripRawDigiSource_=="SIGNAL") {
69  rawdigicollection_ = hSSRD.product();
70  } else if (SiStripRawDigiSource_=="PILEUP") {
72  digicollection_ = hSSD.product();
73  } else {
74  std::cout << "you shouldn't be here" << std::endl;
75  }
76 
77 
78  } // end of addSiStripSignals
79 
80 
81 
82  void DataMixingSiStripRawWorker::addSiStripPileups(const int bcr, const EventPrincipal *ep, unsigned int eventNr) {
83 
84  LogDebug("DataMixingSiStripRawWorker") << "\n===============> adding pileups from event "
85  << ep->id() << " for bunchcrossing " << bcr;
86 
87  boost::shared_ptr<Wrapper<edm::DetSetVector<SiStripDigi> > const> pSSD;
88  boost::shared_ptr<Wrapper<edm::DetSetVector<SiStripRawDigi> > const> pSSRD;
89 
90  if (SiStripRawDigiSource_=="SIGNAL") {
91  pSSD = getProductByTag<edm::DetSetVector<SiStripDigi> >(*ep, SiStripPileInputTag_);
92  digicollection_ = const_cast< edm::DetSetVector<SiStripDigi> * >(pSSD->product());
93  } else if (SiStripRawDigiSource_=="PILEUP") {
94  pSSRD = getProductByTag<edm::DetSetVector<SiStripRawDigi> >(*ep, SiStripRawInputTag_ );
95  rawdigicollection_ = const_cast< edm::DetSetVector<SiStripRawDigi> * >(pSSRD->product());
96  } else {
97  std::cout << "you shouldn't be here" << std::endl;
98  }
99 
100  } // end of addSiStripPileups
101 
102 
104 
105 
106  //------------------
107  // (1) Fill a map from the Digi collection
108  //
109 
110  // fill in maps of SiStripDigis
111  OneDetectorMap LocalMap;
112 
113  //loop on all detsets (detectorIDs) inside the input collection
115  for (; DSViter!=digicollection_->end();DSViter++){
116 
117 #ifdef DEBUG
118  LogDebug("DataMixingSiStripRawWorker") << "Processing DetID " << DSViter->id;
119 #endif
120 
121  LocalMap.clear();
122  LocalMap.reserve((DSViter->data).size());
123  LocalMap.insert(LocalMap.end(),(DSViter->data).begin(),(DSViter->data).end());
124 
125  SiHitStorage_.insert( SiGlobalIndex::value_type( DSViter->id, LocalMap ) );
126  }
127 
128 
129  //------------------
130  // (2) Loop over the input RawDigi collection and add the Digis from the map
131  //
132 
133  // collection of RawDigis to put back in the event
134  std::vector< edm::DetSet<SiStripRawDigi> > vSiStripRawDigi;
135 
136  //loop on all detsets (detectorIDs) inside the SiStripRawDigis collection
138  for (; rawDSViter!=rawdigicollection_->end();rawDSViter++){
139 
140  // Make empty collection with this detID
141  edm::DetSet<SiStripRawDigi> SSRD(rawDSViter->id);
142 
143  // find local map (if it exists) for this detector ID
144  SiGlobalIndex::const_iterator itest;
145  itest = SiHitStorage_.find(rawDSViter->id);
146 
147  // if detID already has digis in existing map, add them to rawdigis
148  if(itest!=SiHitStorage_.end()) {
149 
150 #ifdef DEBUG
151  LogDebug("DataMixingSiStripRawWorker") << "Pileups: Processing DetID " << rawDSViter->id;
152 #endif
153 
154  // get the map from storage
155  LocalMap = itest->second;
156  OneDetectorMap::const_iterator iLocal = LocalMap.begin();
157 
158  // loop on all strips in rawdigi detset
159  int currentstrip=0;
160  edm::DetSet<SiStripRawDigi>::const_iterator iRawDigi = rawDSViter->begin();
161  while( iRawDigi != rawDSViter->end() ) {
162 
163  int ADCSum = iRawDigi->adc();
164 
165  // if current strip exists in map, add ADC values
166  if(iLocal->strip() == currentstrip) {
167  ADCSum += iLocal->adc();
168  iLocal++;
169  }
170 
171  // put ADC sum in DetSet and go to next strip
172  SSRD.push_back( SiStripRawDigi(ADCSum) );
173  iRawDigi++;
174  currentstrip++;
175 
176  }
177 
178  // copy combined digi+rawdigi into rawdigi DetSetVector
179  vSiStripRawDigi.push_back(SSRD);
180 
181  // otherwise, just copy the rawdigis from the background event to the output
182  } else {
183  vSiStripRawDigi.push_back(*rawDSViter);
184  }
185 
186  }
187 
188 
189  //------------------
190  // (3) Put the new RawDigi collection back into the event
191  //
192 
193  // make new raw digi collection
194  std::auto_ptr< edm::DetSetVector<SiStripRawDigi> > MySiStripRawDigis(new edm::DetSetVector<SiStripRawDigi>(vSiStripRawDigi) );
195 
196  // put collection
197  e.put( MySiStripRawDigis, SiStripDigiCollectionDM_ );
198 
199  // clear local storage for this event
200  SiHitStorage_.clear();
201  }
202 
203 }
#define LogDebug(id)
T getParameter(std::string const &) const
const edm::DetSetVector< SiStripDigi > * digicollection_
void push_back(const T &t)
Definition: DetSet.h:69
void addSiStripSignals(const edm::Event &e)
EventID const & id() const
std::vector< SiStripDigi > OneDetectorMap
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
#define end
Definition: vmac.h:38
Container::value_type value_type
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
iterator end()
Return the off-the-end iterator.
Definition: DetSetVector.h:356
void addSiStripPileups(const int bcr, const edm::EventPrincipal *, unsigned int EventId)
T const * product() const
Definition: Handle.h:74
std::string const & label() const
Definition: InputTag.h:42
void insert(detset const &s)
Insert the given DetSet.
Definition: DetSetVector.h:234
#define begin
Definition: vmac.h:31
tuple cout
Definition: gather_cfg.py:121
iterator begin()
Return an iterator to the first DetSet.
Definition: DetSetVector.h:341
collection_type::const_iterator const_iterator
Definition: DetSet.h:34
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 ...