CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiPixelRawToDigi.cc
Go to the documentation of this file.
1 // Include parameter driven interface to SiPixelQuality for study purposes
2 // exclude ROC(raw) based on bad ROC list in SiPixelQuality
3 // enabled by: process.siPixelDigis.UseQualityInfo = True
4 // 20-10-2010 Andrew York (Tennessee)
5 
6 #include "SiPixelRawToDigi.h"
7 
11 
13 
15 
17 
21 
27 
29 
33 
34 #include "TH1D.h"
35 #include "TFile.h"
36 
37 using namespace std;
38 
39 // -----------------------------------------------------------------------------
41  : config_(conf),
42  badPixelInfo_(0),
43  regions_(0),
44  hCPU(0), hDigi(0), theTimer(0)
45 {
46 
47  includeErrors = config_.getParameter<bool>("IncludeErrors");
48  useQuality = config_.getParameter<bool>("UseQualityInfo");
49  if (config_.exists("ErrorList")) {
50  tkerrorlist = config_.getParameter<std::vector<int> > ("ErrorList");
51  }
52  if (config_.exists("UserErrorList")) {
53  usererrorlist = config_.getParameter<std::vector<int> > ("UserErrorList");
54  }
55  tFEDRawDataCollection = consumes <FEDRawDataCollection> (config_.getParameter<edm::InputTag>("InputLabel"));
56 
57  //start counters
58  ndigis = 0;
59  nwords = 0;
60 
61  // Products
62  produces< edm::DetSetVector<PixelDigi> >();
63  if(includeErrors){
64  produces< edm::DetSetVector<SiPixelRawDataError> >();
65  produces<DetIdCollection>();
66  produces<DetIdCollection>("UserErrorModules");
67  }
68 
69  // regions
70  if (config_.exists("Regions")) {
71  if(config_.getParameter<edm::ParameterSet>("Regions").getParameterNames().size() > 0)
72  {
74  }
75  }
76 
77  // Timing
78  bool timing = config_.getUntrackedParameter<bool>("Timing",false);
79  if (timing) {
80  theTimer = new R2DTimerObserver("**** MY TIMING REPORT ***");
81  hCPU = new TH1D ("hCPU","hCPU",100,0.,0.050);
82  hDigi = new TH1D("hDigi","hDigi",50,0.,15000.);
83  }
84 }
85 
86 
87 // -----------------------------------------------------------------------------
89  edm::LogInfo("SiPixelRawToDigi") << " HERE ** SiPixelRawToDigi destructor!";
90 
91  if (regions_) delete regions_;
92 
93  if (theTimer) {
94  TFile rootFile("analysis.root", "RECREATE", "my histograms");
95  hCPU->Write();
96  hDigi->Write();
97  delete theTimer;
98  }
99 
100 }
101 
102 
103 // -----------------------------------------------------------------------------
104 
105 
106 // -----------------------------------------------------------------------------
108  const edm::EventSetup& es)
109 {
110  const uint32_t dummydetid = 0xffffffff;
112 
113 // initialize cabling map or update if necessary
114  if (recordWatcher.check( es )) {
115  // cabling map, which maps online address (fed->link->ROC->local pixel) to offline (DetId->global pixel)
117  es.get<SiPixelFedCablingMapRcd>().get( cablingMap );
118  fedIds = cablingMap->fedIds();
119  cabling_ = cablingMap->cablingTree();
120  LogDebug("map version:")<< cabling_->version();
121  }
122 // initialize quality record or update if necessary
123  if (qualityWatcher.check( es )&&useQuality) {
124  // quality info for dead pixel modules or ROCs
125  edm::ESHandle<SiPixelQuality> qualityInfo;
126  es.get<SiPixelQualityRcd>().get( qualityInfo );
127  badPixelInfo_ = qualityInfo.product();
128  if (!badPixelInfo_) {
129  edm::LogError("SiPixelQualityNotPresent")<<" Configured to use SiPixelQuality, but SiPixelQuality not present"<<endl;
130  }
131  }
132 
134  label = config_.getParameter<edm::InputTag>("InputLabel");
135  ev.getByToken(tFEDRawDataCollection, buffers);
136 
137 // create product (digis & errors)
138  std::auto_ptr< edm::DetSetVector<PixelDigi> > collection( new edm::DetSetVector<PixelDigi> );
139  // collection->reserve(8*1024);
140  std::auto_ptr< edm::DetSetVector<SiPixelRawDataError> > errorcollection( new edm::DetSetVector<SiPixelRawDataError> );
141  std::auto_ptr< DetIdCollection > tkerror_detidcollection(new DetIdCollection());
142  std::auto_ptr< DetIdCollection > usererror_detidcollection(new DetIdCollection());
143 
145  formatter.setErrorStatus(includeErrors);
146 
147  if (useQuality) formatter.setQualityStatus(useQuality, badPixelInfo_);
148 
149  if (theTimer) theTimer->start();
150  bool errorsInEvent = false;
151  PixelDataFormatter::DetErrors nodeterrors;
152 
153  if (regions_) {
154  regions_->run(ev, es);
155  formatter.setModulesToUnpack(regions_->modulesToUnpack());
156  LogDebug("SiPixelRawToDigi") << "region2unpack #feds (BPIX,EPIX,total): "<<regions_->nBarrelFEDs()<<" "<<regions_->nForwardFEDs()<<" "<<regions_->nFEDs();
157  LogDebug("SiPixelRawToDigi") << "region2unpack #modules (BPIX,EPIX,total): "<<regions_->nBarrelModules()<<" "<<regions_->nForwardModules()<<" "<<regions_->nModules();
158  }
159 
160  for (auto aFed = fedIds.begin(); aFed != fedIds.end(); ++aFed) {
161  int fedId = *aFed;
162 
163  if (regions_ && !regions_->mayUnpackFED(fedId)) continue;
164 
165  if(debug) LogDebug("SiPixelRawToDigi")<< " PRODUCE DIGI FOR FED: " << fedId << endl;
166 
168 
169  //get event data for this fed
170  const FEDRawData& fedRawData = buffers->FEDData( fedId );
171 
172  //convert data to digi and strip off errors
173  formatter.interpretRawData( errorsInEvent, fedId, fedRawData, *collection, errors);
174 
175  //pack errors into collection
176  if(includeErrors) {
177  typedef PixelDataFormatter::Errors::iterator IE;
178  for (IE is = errors.begin(); is != errors.end(); is++) {
179  uint32_t errordetid = is->first;
180  if (errordetid==dummydetid) { // errors given dummy detId must be sorted by Fed
181  nodeterrors.insert( nodeterrors.end(), errors[errordetid].begin(), errors[errordetid].end() );
182  } else {
183  edm::DetSet<SiPixelRawDataError>& errorDetSet = errorcollection->find_or_insert(errordetid);
184  errorDetSet.data.insert(errorDetSet.data.end(), is->second.begin(), is->second.end());
185  // Fill detid of the detectors where there is error AND the error number is listed
186  // in the configurable error list in the job option cfi.
187  // Code needs to be here, because there can be a set of errors for each
188  // entry in the for loop over PixelDataFormatter::Errors
189  if(!tkerrorlist.empty() || !usererrorlist.empty()){
190  DetId errorDetId(errordetid);
191  edm::DetSet<SiPixelRawDataError>::const_iterator itPixelError=errorDetSet.begin();
192  for(; itPixelError!=errorDetSet.end(); ++itPixelError){
193  // fill list of detIds to be turned off by tracking
194  if(!tkerrorlist.empty()) {
195  std::vector<int>::iterator it_find = find(tkerrorlist.begin(), tkerrorlist.end(), itPixelError->getType());
196  if(it_find != tkerrorlist.end()){
197  tkerror_detidcollection->push_back(errordetid);
198  }
199  }
200  // fill list of detIds with errors to be studied
201  if(!usererrorlist.empty()) {
202  std::vector<int>::iterator it_find = find(usererrorlist.begin(), usererrorlist.end(), itPixelError->getType());
203  if(it_find != usererrorlist.end()){
204  usererror_detidcollection->push_back(errordetid);
205  }
206  }
207  }
208  }
209  }
210  }
211  }
212  }
213 
214  if(includeErrors) {
215  edm::DetSet<SiPixelRawDataError>& errorDetSet = errorcollection->find_or_insert(dummydetid);
216  errorDetSet.data = nodeterrors;
217  }
218  if (errorsInEvent) LogDebug("SiPixelRawToDigi") << "Error words were stored in this event";
219 
220  if (theTimer) {
221  theTimer->stop();
222  LogDebug("SiPixelRawToDigi") << "TIMING IS: (real)" << theTimer->lastMeasurement().real() ;
223  ndigis += formatter.nDigis();
224  nwords += formatter.nWords();
225  LogDebug("SiPixelRawToDigi") << " (Words/Digis) this ev: "
226  <<formatter.nWords()<<"/"<<formatter.nDigis() << "--- all :"<<nwords<<"/"<<ndigis;
227  hCPU->Fill( theTimer->lastMeasurement().real() );
228  hDigi->Fill(formatter.nDigis());
229  }
230 
231  //send digis and errors back to framework
232  ev.put( collection );
233  if(includeErrors){
234  ev.put( errorcollection );
235  ev.put( tkerror_detidcollection );
236  ev.put( usererror_detidcollection, "UserErrorModules" );
237  }
238 }
#define LogDebug(id)
iterator end()
Definition: DetSet.h:60
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
unsigned int nForwardFEDs() const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
static MessageDrop * instance()
Definition: MessageDrop.cc:60
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::vector< int > usererrorlist
const std::set< unsigned int > * modulesToUnpack() const
full set of module ids to unpack
edm::InputTag label
virtual void produce(edm::Event &, const edm::EventSetup &) override
get data, convert to digis attach againe to Event
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
PixelUnpackingRegions * regions_
std::vector< SiPixelRawDataError > DetErrors
std::vector< unsigned int > fedIds
SiPixelRawToDigi(const edm::ParameterSet &)
ctor
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
std::unique_ptr< SiPixelFedCablingTree > cabling_
unsigned int nBarrelModules() const
edm::EDGetTokenT< FEDRawDataCollection > tFEDRawDataCollection
std::vector< std::string > getParameterNames() const
tuple conf
Definition: dbtoconf.py:185
std::map< cms_uint32_t, DetErrors > Errors
virtual ~SiPixelRawToDigi()
dtor
iterator begin()
Definition: DetSet.h:59
edm::ESWatcher< SiPixelFedCablingMapRcd > recordWatcher
void run(const edm::Event &e, const edm::EventSetup &es)
has to be run during each event
Definition: DetId.h:18
unsigned int nModules() const
const LastMeasurement & lastMeasurement()
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
std::vector< int > tkerrorlist
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:58
edm::ParameterSet config_
unsigned int nForwardModules() const
collection_type data
Definition: DetSet.h:78
unsigned int nFEDs() const
various informational accessors:
unsigned int nBarrelFEDs() const
tuple formatter
Definition: fff_deleter.py:293
bool mayUnpackFED(unsigned int fed_n) const
check whether a FED has to be unpacked
edm::EDCollection< DetId > DetIdCollection
R2DTimerObserver * theTimer
collection_type::const_iterator const_iterator
Definition: DetSet.h:33
edm::ESWatcher< SiPixelQualityRcd > qualityWatcher
const SiPixelQuality * badPixelInfo_