CMS 3D CMS Logo

SiPixelRawToDigi.cc
Go to the documentation of this file.
1 // Skip FED40 pilot-blade
2 // Include parameter driven interface to SiPixelQuality for study purposes
3 // exclude ROC(raw) based on bad ROC list in SiPixelQuality
4 // enabled by: process.siPixelDigis.UseQualityInfo = True (BY DEFAULT NOT USED)
5 // 20-10-2010 Andrew York (Tennessee)
6 // Jan 2016 Tamas Almos Vami (Tav) (Wigner RCP) -- Cabling Map label option
7 // Jul 2017 Viktor Veszpremi -- added PixelFEDChannel
8 
9 #include "SiPixelRawToDigi.h"
10 
16 
18 
20 
22 
26 
32 
34 
38 
39 #include "TH1D.h"
40 #include "TFile.h"
41 
42 using namespace std;
43 
44 // -----------------------------------------------------------------------------
46  : config_(conf),
47  badPixelInfo_(nullptr),
48  regions_(nullptr),
49  hCPU(nullptr), hDigi(nullptr)
50 {
51 
52  includeErrors = config_.getParameter<bool>("IncludeErrors");
53  useQuality = config_.getParameter<bool>("UseQualityInfo");
54  if (config_.exists("ErrorList")) {
55  tkerrorlist = config_.getParameter<std::vector<int> > ("ErrorList");
56  }
57  if (config_.exists("UserErrorList")) {
58  usererrorlist = config_.getParameter<std::vector<int> > ("UserErrorList");
59  }
60  tFEDRawDataCollection = consumes <FEDRawDataCollection> (config_.getParameter<edm::InputTag>("InputLabel"));
61 
62  //start counters
63  ndigis = 0;
64  nwords = 0;
65 
66  // Products
67  produces< edm::DetSetVector<PixelDigi> >();
68  if(includeErrors){
69  produces< edm::DetSetVector<SiPixelRawDataError> >();
70  produces<DetIdCollection>();
71  produces<DetIdCollection>("UserErrorModules");
72  produces<edmNew::DetSetVector<PixelFEDChannel> >();
73  }
74 
75  // regions
76  if (config_.exists("Regions")) {
77  if(!config_.getParameter<edm::ParameterSet>("Regions").getParameterNames().empty())
78  {
79  regions_ = new PixelUnpackingRegions(config_, consumesCollector());
80  }
81  }
82 
83  // Timing
84  bool timing = config_.getUntrackedParameter<bool>("Timing",false);
85  if (timing) {
86  theTimer.reset( new edm::CPUTimer );
87  hCPU = new TH1D ("hCPU","hCPU",100,0.,0.050);
88  hDigi = new TH1D("hDigi","hDigi",50,0.,15000.);
89  }
90 
91  // Control the usage of pilot-blade data, FED=40
92  usePilotBlade = false;
93  if (config_.exists("UsePilotBlade")) {
94  usePilotBlade = config_.getParameter<bool> ("UsePilotBlade");
95  if(usePilotBlade) edm::LogInfo("SiPixelRawToDigi") << " Use pilot blade data (FED 40)";
96  }
97 
98  // Control the usage of phase1
99  usePhase1 = false;
100  if (config_.exists("UsePhase1")) {
101  usePhase1 = config_.getParameter<bool> ("UsePhase1");
102  if(usePhase1) edm::LogInfo("SiPixelRawToDigi") << " Using phase1";
103  }
104  //CablingMap could have a label //Tav
105  cablingMapLabel = config_.getParameter<std::string> ("CablingMapLabel");
106 
107 }
108 
109 
110 // -----------------------------------------------------------------------------
112  edm::LogInfo("SiPixelRawToDigi") << " HERE ** SiPixelRawToDigi destructor!";
113 
114  if (regions_) delete regions_;
115 
116  if (theTimer) {
117  TFile rootFile("analysis.root", "RECREATE", "my histograms");
118  hCPU->Write();
119  hDigi->Write();
120  }
121 
122 }
123 
124 void
127  desc.add<bool>("IncludeErrors",true);
128  desc.add<bool>("UseQualityInfo",false);
129  {
130  std::vector<int> temp1;
131  temp1.reserve(1);
132  temp1.push_back(29);
133  desc.add<std::vector<int> >("ErrorList",temp1)->setComment("## ErrorList: list of error codes used by tracking to invalidate modules");
134  }
135  {
136  std::vector<int> temp1;
137  temp1.reserve(1);
138  temp1.push_back(40);
139  desc.add<std::vector<int> >("UserErrorList",temp1)->setComment("## UserErrorList: list of error codes used by Pixel experts for investigation");
140  }
141  desc.add<edm::InputTag>("InputLabel",edm::InputTag("siPixelRawData"));
142  {
144  psd0.addOptional<std::vector<edm::InputTag>>("inputs");
145  psd0.addOptional<std::vector<double>>("deltaPhi");
146  psd0.addOptional<std::vector<double>>("maxZ");
147  psd0.addOptional<edm::InputTag>("beamSpot");
148  desc.add<edm::ParameterSetDescription>("Regions",psd0)->setComment("## Empty Regions PSet means complete unpacking");
149  }
150  desc.addUntracked<bool>("Timing",false);
151  desc.add<bool>("UsePilotBlade",false)->setComment("## Use pilot blades");
152  desc.add<bool>("UsePhase1",false)->setComment("## Use phase1");
153  desc.add<std::string>("CablingMapLabel","")->setComment("CablingMap label"); //Tav
154  desc.addOptional<bool>("CheckPixelOrder"); // never used, kept for back-compatibility
155  descriptions.add("siPixelRawToDigi",desc);
156 }
157 
158 // -----------------------------------------------------------------------------
159 
160 
161 // -----------------------------------------------------------------------------
163  const edm::EventSetup& es)
164 {
165  const uint32_t dummydetid = 0xffffffff;
167 
168 // initialize cabling map or update if necessary
169  if (recordWatcher.check( es )) {
170  // cabling map, which maps online address (fed->link->ROC->local pixel) to offline (DetId->global pixel)
172  es.get<SiPixelFedCablingMapRcd>().get( cablingMapLabel, cablingMap ); //Tav
173  fedIds = cablingMap->fedIds();
174  cabling_ = cablingMap->cablingTree();
175  LogDebug("map version:")<< cabling_->version();
176  }
177 // initialize quality record or update if necessary
178  if (qualityWatcher.check( es )&&useQuality) {
179  // quality info for dead pixel modules or ROCs
180  edm::ESHandle<SiPixelQuality> qualityInfo;
181  es.get<SiPixelQualityRcd>().get( qualityInfo );
182  badPixelInfo_ = qualityInfo.product();
183  if (!badPixelInfo_) {
184  edm::LogError("SiPixelQualityNotPresent")<<" Configured to use SiPixelQuality, but SiPixelQuality not present"<<endl;
185  }
186  }
187 
189  ev.getByToken(tFEDRawDataCollection, buffers);
190 
191 // create product (digis & errors)
192  auto collection = std::make_unique<edm::DetSetVector<PixelDigi>>();
193  // collection->reserve(8*1024);
194  auto errorcollection = std::make_unique<edm::DetSetVector<SiPixelRawDataError>>();
195  auto tkerror_detidcollection = std::make_unique<DetIdCollection>();
196  auto usererror_detidcollection = std::make_unique<DetIdCollection>();
197  auto disabled_channelcollection = std::make_unique<edmNew::DetSetVector<PixelFEDChannel> >();
198 
199  //PixelDataFormatter formatter(cabling_.get()); // phase 0 only
200  PixelDataFormatter formatter(cabling_.get(), usePhase1); // for phase 1 & 0
201 
202  formatter.setErrorStatus(includeErrors);
203 
204  if (useQuality) formatter.setQualityStatus(useQuality, badPixelInfo_);
205 
206  if (theTimer) theTimer->start();
207  bool errorsInEvent = false;
208  PixelDataFormatter::DetErrors nodeterrors;
209 
210  if (regions_) {
211  regions_->run(ev, es);
212  formatter.setModulesToUnpack(regions_->modulesToUnpack());
213  LogDebug("SiPixelRawToDigi") << "region2unpack #feds: "<<regions_->nFEDs();
214  LogDebug("SiPixelRawToDigi") << "region2unpack #modules (BPIX,EPIX,total): "<<regions_->nBarrelModules()<<" "<<regions_->nForwardModules()<<" "<<regions_->nModules();
215  }
216 
217  for (auto aFed = fedIds.begin(); aFed != fedIds.end(); ++aFed) {
218  int fedId = *aFed;
219 
220  if(!usePilotBlade && (fedId==40) ) continue; // skip pilot blade data
221 
222  if (regions_ && !regions_->mayUnpackFED(fedId)) continue;
223 
224  if(debug) LogDebug("SiPixelRawToDigi")<< " PRODUCE DIGI FOR FED: " << fedId << endl;
225 
227 
228  //get event data for this fed
229  const FEDRawData& fedRawData = buffers->FEDData( fedId );
230 
231  //convert data to digi and strip off errors
232  formatter.interpretRawData( errorsInEvent, fedId, fedRawData, *collection, errors);
233 
234  //pack errors into collection
235  if(includeErrors) {
236  typedef PixelDataFormatter::Errors::iterator IE;
237  for (IE is = errors.begin(); is != errors.end(); is++) {
238  uint32_t errordetid = is->first;
239  if (errordetid==dummydetid) { // errors given dummy detId must be sorted by Fed
240  nodeterrors.insert( nodeterrors.end(), errors[errordetid].begin(), errors[errordetid].end() );
241  } else {
242  edm::DetSet<SiPixelRawDataError>& errorDetSet = errorcollection->find_or_insert(errordetid);
243  errorDetSet.data.insert(errorDetSet.data.end(), is->second.begin(), is->second.end());
244  // Fill detid of the detectors where there is error AND the error number is listed
245  // in the configurable error list in the job option cfi.
246  // Code needs to be here, because there can be a set of errors for each
247  // entry in the for loop over PixelDataFormatter::Errors
248 
249  std::vector<PixelFEDChannel> disabledChannelsDetSet;
250 
251  for (auto const& aPixelError : errorDetSet) {
252  // For the time being, we extend the error handling functionality with ErrorType 25
253  // In the future, we should sort out how the usage of tkerrorlist can be generalized
254  if (aPixelError.getType()==25) {
255  assert(aPixelError.getFedId()==fedId);
256  const sipixelobjects::PixelFEDCabling* fed = cabling_->fed(fedId);
257  if (fed) {
258  cms_uint32_t linkId = formatter.linkId(aPixelError.getWord32());
259  const sipixelobjects::PixelFEDLink* link = fed->link(linkId);
260  if (link) {
261  // The "offline" 0..15 numbering is fixed by definition, also, the FrameConversion depends on it
262  // in contrast, the ROC-in-channel numbering is determined by hardware --> better to use the "offline" scheme
263  PixelFEDChannel ch = {fed->id(), linkId, 25, 0};
264  for (unsigned int iRoc=1; iRoc<=link->numberOfROCs(); iRoc++) {
265  const sipixelobjects::PixelROC * roc = link->roc(iRoc);
266  if (roc->idInDetUnit()<ch.roc_first) ch.roc_first=roc->idInDetUnit();
267  if (roc->idInDetUnit()>ch.roc_last) ch.roc_last=roc->idInDetUnit();
268  }
269  disabledChannelsDetSet.push_back(ch);
270  }
271  }
272  } else {
273  // fill list of detIds to be turned off by tracking
274  if(!tkerrorlist.empty()) {
275  std::vector<int>::iterator it_find = find(tkerrorlist.begin(), tkerrorlist.end(), aPixelError.getType());
276  if(it_find != tkerrorlist.end()){
277  tkerror_detidcollection->push_back(errordetid);
278  }
279  }
280  }
281 
282  // fill list of detIds with errors to be studied
283  if(!usererrorlist.empty()) {
284  std::vector<int>::iterator it_find = find(usererrorlist.begin(), usererrorlist.end(), aPixelError.getType());
285  if(it_find != usererrorlist.end()){
286  usererror_detidcollection->push_back(errordetid);
287  }
288  }
289 
290  } // loop on DetSet of errors
291 
292  if (!disabledChannelsDetSet.empty()) {
293  disabled_channelcollection->insert(errordetid, disabledChannelsDetSet.data(), disabledChannelsDetSet.size());
294  }
295 
296  } // if error assigned to a real DetId
297  } // loop on errors in event for this FED
298  } // if errors to be included in the event
299  } // loop on FED data to be unpacked
300 
301  if(includeErrors) {
302  edm::DetSet<SiPixelRawDataError>& errorDetSet = errorcollection->find_or_insert(dummydetid);
303  errorDetSet.data = nodeterrors;
304  }
305  if (errorsInEvent) LogDebug("SiPixelRawToDigi") << "Error words were stored in this event";
306 
307  if (theTimer) {
308  theTimer->stop();
309  LogDebug("SiPixelRawToDigi") << "TIMING IS: (real)" << theTimer->realTime() ;
310  ndigis += formatter.nDigis();
311  nwords += formatter.nWords();
312  LogDebug("SiPixelRawToDigi") << " (Words/Digis) this ev: "
313  <<formatter.nWords()<<"/"<<formatter.nDigis() << "--- all :"<<nwords<<"/"<<ndigis;
314  hCPU->Fill( theTimer->realTime() );
315  hDigi->Fill(formatter.nDigis());
316  }
317 
318  //send digis and errors back to framework
319  ev.put(std::move(collection));
320  if(includeErrors){
321  ev.put(std::move(errorcollection));
322  ev.put(std::move(tkerror_detidcollection));
323  ev.put(std::move(usererror_detidcollection), "UserErrorModules");
324  ev.put(std::move(disabled_channelcollection));
325  }
326 }
327 
328 // declare this as a framework plugin
#define LogDebug(id)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::unique_ptr< edm::CPUTimer > theTimer
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
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
bool ev
std::string cablingMapLabel
void setErrorStatus(bool ErrorStatus)
void produce(edm::Event &, const edm::EventSetup &) override
get data, convert to digis attach againe to Event
#define nullptr
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
PixelUnpackingRegions * regions_
unsigned int roc_last
std::vector< SiPixelRawDataError > DetErrors
std::vector< unsigned int > fedIds
SiPixelRawToDigi(const edm::ParameterSet &)
ctor
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
unsigned int idInDetUnit() const
id of this ROC in DetUnit etermined by token path
Definition: PixelROC.h:40
std::unique_ptr< SiPixelFedCablingTree > cabling_
unsigned int nBarrelModules() const
edm::EDGetTokenT< FEDRawDataCollection > tFEDRawDataCollection
std::vector< std::string > getParameterNames() const
ParameterDescriptionBase * add(U const &iLabel, T const &value)
unsigned int cms_uint32_t
Definition: typedefs.h:15
~SiPixelRawToDigi() override
dtor
std::map< cms_uint32_t, DetErrors > Errors
edm::ESWatcher< SiPixelFedCablingMapRcd > recordWatcher
void run(const edm::Event &e, const edm::EventSetup &es)
has to be run during each event
std::unique_ptr< SiPixelFedCablingTree > cablingTree() const
unsigned int nModules() const
unsigned int roc_first
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::vector< int > tkerrorlist
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
edm::ParameterSet config_
unsigned int nForwardModules() const
collection_type data
Definition: DetSet.h:78
unsigned int nFEDs() const
various informational accessors:
T get() const
Definition: EventSetup.h:63
bool mayUnpackFED(unsigned int fed_n) const
check whether a FED has to be unpacked
std::vector< unsigned int > fedIds() const
edm::ESWatcher< SiPixelQualityRcd > qualityWatcher
T const * product() const
Definition: ESHandle.h:86
def move(src, dest)
Definition: eostools.py:510
const SiPixelQuality * badPixelInfo_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)