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