CMS 3D CMS Logo

TrigPrimTask.cc
Go to the documentation of this file.
2 
5 
9 
10 #include <iomanip>
11 
12 namespace ecaldqm {
14  : DQWorkerTask(),
15  realTps_(nullptr),
16  runOnEmul_(false),
17  // HLTCaloPath_(""),
18  // HLTMuonPath_(""),
19  // HLTCaloBit_(false),
20  // HLTMuonBit_(false),
21  bxBinEdges_(),
22  bxBinEdgesFine_(),
23  bxBin_(0.),
24  bxBinFine_(0.),
25  towerReadouts_(),
26  lhcStatusInfoCollectionTag_() {}
27 
29  runOnEmul_ = _params.getUntrackedParameter<bool>("runOnEmul");
30  if (!runOnEmul_) {
31  MEs_.erase(std::string("EtMaxEmul"));
32  MEs_.erase(std::string("EmulMaxIndex"));
33  MEs_.erase(std::string("MatchedIndex"));
34  MEs_.erase(std::string("EtEmulError"));
35  MEs_.erase(std::string("FGEmulError"));
36  MEs_.erase(std::string("RealvEmulEt"));
37  }
38  lhcStatusInfoCollectionTag_ = _params.getUntrackedParameter<edm::InputTag>(
39  "lhcStatusInfoCollectionTag", edm::InputTag("tcdsDigis", "tcdsRecord"));
40  bxBinEdges_ = _params.getUntrackedParameter<std::vector<int> >("bxBins");
41  bxBinEdgesFine_ = _params.getUntrackedParameter<std::vector<int> >("bxBinsFine");
42  }
43 
45  if (runOnEmul_)
47  }
48 
49  void TrigPrimTask::beginRun(edm::Run const&, edm::EventSetup const& _es) {
50  // Read-in Status records:
51  // Status records stay constant over run so they are read-in only once here
52  // but filled by LS in runOnRealTPs() because MEs are not yet booked at beginRun()
55  }
56 
58  edm::EventSetup const& _es,
59  bool const& ByLumiResetSwitch,
60  bool& lhcStatusSet) {
61  using namespace std;
62 
63  towerReadouts_.clear();
64 
65  if (ByLumiResetSwitch) {
66  MEs_.at("EtSummaryByLumi").reset(GetElectronicsMap());
67  MEs_.at("TTFlags4ByLumi").reset(GetElectronicsMap());
68  MEs_.at("LHCStatusByLumi").reset(GetElectronicsMap(), -1);
69  }
70 
71  if (!lhcStatusSet) {
72  // Update LHC status once each LS
73  MESet& meLHCStatusByLumi(static_cast<MESet&>(MEs_.at("LHCStatusByLumi")));
74  edm::Handle<TCDSRecord> tcdsData;
75  _evt.getByToken(lhcStatusInfoRecordToken_, tcdsData);
76  if (tcdsData.isValid()) {
77  meLHCStatusByLumi.fill(getEcalDQMSetupObjects(), double(tcdsData->getBST().getBeamMode()));
78  lhcStatusSet = true;
79  }
80  }
81 
82  realTps_ = nullptr;
83 
84  // HLTCaloBit_ = false;
85  // HLTMuonBit_ = false;
86 
87  std::vector<int>::iterator pBin(std::upper_bound(bxBinEdges_.begin(), bxBinEdges_.end(), _evt.bunchCrossing()));
88  bxBin_ = static_cast<int>(pBin - bxBinEdges_.begin()) - 0.5;
89  // fine binning for TP Occ vs BX plot as requested by DAQ in March 2021
90  std::vector<int>::iterator pBinFine(
92  bxBinFine_ = static_cast<int>(pBinFine - bxBinEdgesFine_.begin()) - 0.5;
93 
94  const EcalTPGTowerStatusMap& towerMap = TTStatus->getMap();
95  const EcalTPGStripStatusMap& stripMap = StripStatus->getMap();
96 
97  MESet& meTTMaskMap(MEs_.at("TTMaskMap"));
98 
99  for (EcalTPGTowerStatusMap::const_iterator ttItr(towerMap.begin()); ttItr != towerMap.end(); ++ttItr) {
100  if ((*ttItr).second > 0) {
101  const EcalTrigTowerDetId ttid((*ttItr).first);
102  //if(ttid.subDet() == EcalBarrel)
103  meTTMaskMap.fill(getEcalDQMSetupObjects(), ttid, 1);
104  } //masked
105  } //loop on towers
106 
107  for (EcalTPGStripStatusMap::const_iterator stItr(stripMap.begin()); stItr != stripMap.end(); ++stItr) {
108  if ((*stItr).second > 0) {
109  const EcalElectronicsId stid((*stItr).first);
110  //if(stid.subdet() == EcalEndcap);
111  meTTMaskMap.fill(getEcalDQMSetupObjects(), stid, 1);
112  } //masked
113  } //loop on pseudo-strips
114 
115  // if(HLTCaloPath_.size() || HLTMuonPath_.size()){
116  // edm::TriggerResultsByName results(_evt.triggerResultsByName("HLT"));
117  // if(!results.isValid()) results = _evt.triggerResultsByName("RECO");
118  // if(results.isValid()){
119  // const vector<string>& pathNames(results.triggerNames());
120 
121  // size_t caloStar(HLTCaloPath_.find('*'));
122  // if(caloStar != string::npos){
123  // string caloSub(HLTCaloPath_.substr(0, caloStar));
124  // bool found(false);
125  // for(unsigned iP(0); iP < pathNames.size(); ++iP){
126  // if(pathNames[iP].substr(0, caloStar) == caloSub){
127  // HLTCaloPath_ = pathNames[iP];
128  // found = true;
129  // break;
130  // }
131  // }
132  // if(!found) HLTCaloPath_ = "";
133  // }
134 
135  // size_t muonStar(HLTMuonPath_.find('*'));
136  // if(muonStar != string::npos){
137  // string muonSub(HLTMuonPath_.substr(0, muonStar));
138  // bool found(false);
139  // for(unsigned iP(0); iP < pathNames.size(); ++iP){
140  // if(pathNames[iP].substr(0, muonStar) == muonSub){
141  // HLTMuonPath_ = pathNames[iP];
142  // found = true;
143  // break;
144  // }
145  // }
146  // if(!found) HLTMuonPath_ = "";
147  // }
148 
149  // if(HLTCaloPath_.size()){
150  // try{
151  // HLTCaloBit_ = results.accept(HLTCaloPath_);
152  // }
153  // catch(cms::Exception e){
154  // if(e.category() != "LogicError") throw e;
155  // HLTCaloPath_ = "";
156  // }
157  // }
158  // if(HLTMuonPath_.size()){
159  // try{
160  // HLTMuonBit_ = results.accept(HLTMuonPath_);
161  // }
162  // catch(cms::Exception e){
163  // if(e.category() != "LogicError") throw e;
164  // HLTMuonPath_ = "";
165  // }
166  // }
167  // }
168  // }
169  }
170 
171  template <typename DigiCollection>
173  for (typename DigiCollection::const_iterator digiItr(_digis.begin()); digiItr != _digis.end(); ++digiItr) {
174  EcalTrigTowerDetId ttid(GetTrigTowerMap()->towerOf(digiItr->id()));
175  towerReadouts_[ttid.rawId()]++;
176  }
177  }
178 
183  }
184 
186  MESet& meEtVsBx(MEs_.at("EtVsBx"));
187  MESet& meEtReal(MEs_.at("EtReal"));
188  MESet& meEtRealMap(MEs_.at("EtRealMap"));
189  MESet& meEtSummary(MEs_.at("EtSummary"));
190  MESet& meEtSummaryByLumi(MEs_.at("EtSummaryByLumi"));
191  MESet& meLowIntMap(MEs_.at("LowIntMap"));
192  MESet& meMedIntMap(MEs_.at("MedIntMap"));
193  MESet& meHighIntMap(MEs_.at("HighIntMap"));
194  MESet& meTTFlags(MEs_.at("TTFlags"));
195  MESet& meTTFlagsVsEt(MEs_.at("TTFlagsVsEt"));
196  MESet& meTTFlags4(MEs_.at("TTFlags4"));
197  MESet& meTTFlags4ByLumi(MEs_.at("TTFlags4ByLumi"));
198  MESet& meTTFMismatch(MEs_.at("TTFMismatch"));
199  MESet& meOccVsBx(MEs_.at("OccVsBx"));
200 
201  realTps_ = &_tps;
202 
203  double nTP[] = {0., 0., 0.};
204 
205  for (EcalTrigPrimDigiCollection::const_iterator tpItr(_tps.begin()); tpItr != _tps.end(); ++tpItr) {
206  EcalTrigTowerDetId ttid(tpItr->id());
207  float et(tpItr->compressedEt());
208 
209  if (et > 0.) {
210  if (ttid.subDet() == EcalBarrel)
211  nTP[0] += 1.;
212  else if (ttid.zside() < 0)
213  nTP[1] += 1.;
214  else
215  nTP[2] += 2.;
216  meEtVsBx.fill(getEcalDQMSetupObjects(), ttid, bxBin_, et);
217  }
218 
219  meEtReal.fill(getEcalDQMSetupObjects(), ttid, et);
220  meEtRealMap.fill(getEcalDQMSetupObjects(), ttid, et);
221  meEtSummary.fill(getEcalDQMSetupObjects(), ttid, et);
222  meEtSummaryByLumi.fill(getEcalDQMSetupObjects(), ttid, et);
223 
224  int interest(tpItr->ttFlag() & 0x3);
225 
226  switch (interest) {
227  case 0:
228  meLowIntMap.fill(getEcalDQMSetupObjects(), ttid);
229  break;
230  case 1:
231  meMedIntMap.fill(getEcalDQMSetupObjects(), ttid);
232  break;
233  case 3:
234  meHighIntMap.fill(getEcalDQMSetupObjects(), ttid);
235  break;
236  default:
237  break;
238  }
239 
240  // Fill TT Flag MEs
241  int ttF(tpItr->ttFlag());
242  meTTFlags.fill(getEcalDQMSetupObjects(), ttid, 1.0 * ttF);
243  meTTFlagsVsEt.fill(getEcalDQMSetupObjects(), ttid, et, 1.0 * ttF);
244  // Monitor occupancy of TTF=4
245  // which contains info about TT auto-masking
246  if (ttF >= 4) {
247  meTTFlags4.fill(getEcalDQMSetupObjects(), ttid);
248  meTTFlags4ByLumi.fill(getEcalDQMSetupObjects(), ttid);
249  }
250  if ((ttF == 1 || ttF == 3) && towerReadouts_[ttid.rawId()] != GetTrigTowerMap()->constituentsOf(ttid).size())
251  meTTFMismatch.fill(getEcalDQMSetupObjects(), ttid);
252  }
253 
254  meOccVsBx.fill(getEcalDQMSetupObjects(), EcalBarrel, bxBinFine_, nTP[0]);
255  meOccVsBx.fill(getEcalDQMSetupObjects(), -EcalEndcap, bxBinFine_, nTP[1]);
256  meOccVsBx.fill(getEcalDQMSetupObjects(), EcalEndcap, bxBinFine_, nTP[2]);
257 
258  // Set TT/Strip Masking status in Ecal3P view
259  // Status Records are read-in at beginRun() but filled here
260  // Requestied by ECAL Trigger in addition to TTMaskMap plots in SM view
261  MESet& meTTMaskMapAll(MEs_.at("TTMaskMapAll"));
262 
263  // Fill from TT Status Rcd
264  const EcalTPGTowerStatusMap& TTStatusMap(TTStatus->getMap());
265  for (EcalTPGTowerStatusMap::const_iterator ttItr(TTStatusMap.begin()); ttItr != TTStatusMap.end(); ++ttItr) {
266  const EcalTrigTowerDetId ttid(ttItr->first);
267  if (ttItr->second > 0)
268  meTTMaskMapAll.setBinContent(getEcalDQMSetupObjects(), ttid, 1); // TT is masked
269  } // TTs
270 
271  // Fill from Strip Status Rcd
272  const EcalTPGStripStatusMap& StripStatusMap(StripStatus->getMap());
273  for (EcalTPGStripStatusMap::const_iterator stItr(StripStatusMap.begin()); stItr != StripStatusMap.end(); ++stItr) {
274  const EcalTriggerElectronicsId stid(stItr->first);
275  // Since ME has kTriggerTower binning, convert to EcalTrigTowerDetId first
276  // In principle, setBinContent() could be implemented for EcalTriggerElectronicsId class as well
277  const EcalTrigTowerDetId ttid(GetElectronicsMap()->getTrigTowerDetId(stid.tccId(), stid.ttId()));
278  if (stItr->second > 0)
279  meTTMaskMapAll.setBinContent(getEcalDQMSetupObjects(), ttid, 1); // PseudoStrip is masked
280  } // PseudoStrips
281 
282  } // TrigPrimTask::runOnRealTPs()
283 
285  MESet& meEtMaxEmul(MEs_.at("EtMaxEmul"));
286  MESet& meEmulMaxIndex(MEs_.at("EmulMaxIndex"));
287  MESet& meMatchedIndex(MEs_.at("MatchedIndex"));
288  MESet& meEtEmulError(MEs_.at("EtEmulError"));
289  MESet& meFGEmulError(MEs_.at("FGEmulError"));
290  MESet& meRealvEmulEt(MEs_.at("RealvEmulEt"));
291 
292  for (EcalTrigPrimDigiCollection::const_iterator tpItr(_tps.begin()); tpItr != _tps.end(); ++tpItr) {
293  EcalTrigTowerDetId ttid(tpItr->id());
294 
295  int et(tpItr->compressedEt());
296 
297  float maxEt(0.);
298  int iMax(0);
299  for (int iDigi(0); iDigi < 5; iDigi++) {
300  float sampleEt((*tpItr)[iDigi].compressedEt());
301 
302  if (sampleEt > maxEt) {
303  maxEt = sampleEt;
304  iMax = iDigi + 1;
305  }
306  }
307 
308  meEtMaxEmul.fill(getEcalDQMSetupObjects(), ttid, maxEt);
309  if (maxEt > 0.)
310  meEmulMaxIndex.fill(getEcalDQMSetupObjects(), ttid, iMax);
311 
312  bool match(true);
313  bool matchFG(true);
314 
315  // Loop over real TPs and look for an emulated TP index with matching Et:
316  // If an Et match is found, return TP index correpsonding to BX of emulated TP where match was found
317  // Standard TPG comparison: { TP index:matched BX } = { no emul:No Et match, 0:BX-2, 1:BX-1, 2:in-time, 3:BX+1, 4:BX+2 }
319  if (realItr != realTps_->end()) {
320  int realEt(realItr->compressedEt());
321 
322  if (realEt > 0) {
323  int ttF(realItr->ttFlag());
324  if ((ttF == 1 || ttF == 3) &&
325  towerReadouts_[ttid.rawId()] == GetTrigTowerMap()->constituentsOf(ttid).size()) {
326  if (et != realEt)
327  match = false;
328  if (tpItr->fineGrain() != realItr->fineGrain())
329  matchFG = false;
330 
331  // NOTE: matchedIndex comparison differs from Standard TPG comparison:
332  // { matchedIndex:TP index } = { 0:no emul, 1:BX-2, 2:BX-1, 3:in-time, 4:BX+1, 5:BX+2 }
333  std::vector<int> matchedIndex(0);
334  // iDigi only loops over explicit Et matches:
335  // { iDigi:TP index } = { 0:BX-2, 1:BX-1, 2:in-time, 3:BX+1, 4:BX+2 }
336  for (int iDigi(0); iDigi < 5; iDigi++) {
337  if ((*tpItr)[iDigi].compressedEt() == realEt) {
338  // matchedIndex = iDigi + 1
339  if (iDigi != 2) {
340  matchedIndex.push_back(iDigi + 1);
341  }
342  // If an in-time match is found, exit loop and clear out any other matches:
343  // Ensures multiple matches are not returned (e.g. during saturation)
344  else {
345  matchedIndex.clear();
346  matchedIndex.push_back(3); // Et match is to in-time emulated TP
347  break;
348  }
349  } // Et match found
350  } // iDigi
351  if (matchedIndex.empty())
352  matchedIndex.push_back(0); // no Et match found => no emul
353 
354  // Fill Real vs Emulated TP Et
355  meRealvEmulEt.fill(
356  getEcalDQMSetupObjects(), ttid, realEt, (*tpItr)[2].compressedEt()); // iDigi=2:in-time BX
357 
358  // Fill matchedIndex ME
359  for (std::vector<int>::iterator matchItr(matchedIndex.begin()); matchItr != matchedIndex.end();
360  ++matchItr) {
361  meMatchedIndex.fill(getEcalDQMSetupObjects(), ttid, *matchItr + 0.5);
362 
363  // timing information is only within emulated TPs (real TPs have one time sample)
364  // if(HLTCaloBit_) MEs_[kTimingCalo].fill(ttid, float(*matchItr));
365  // if(HLTMuonBit_) MEs_[kTimingMuon].fill(ttid, float(*matchItr));
366  }
367  }
368  }
369  } else {
370  match = false;
371  matchFG = false;
372  }
373 
374  if (!match)
375  meEtEmulError.fill(getEcalDQMSetupObjects(), ttid);
376  if (!matchFG)
377  meFGEmulError.fill(getEcalDQMSetupObjects(), ttid);
378  }
379  }
380 
382 } // namespace ecaldqm
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
const EcalTPGTowerStatus * TTStatus
Definition: TrigPrimTask.h:63
std::map< uint32_t, uint16_t > EcalTPGTowerStatusMap
#define DEFINE_ECALDQM_WORKER(TYPE)
Definition: DQWorker.h:168
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
std::vector< DetId > constituentsOf(const EcalTrigTowerDetId &id) const
Get the constituent detids for this tower id.
MESet & at(const std::string &key)
Definition: MESet.h:401
void beginRun(edm::Run const &, edm::EventSetup const &) override
Definition: TrigPrimTask.cc:49
void setParams(edm::ParameterSet const &) override
Definition: TrigPrimTask.cc:28
Ecal readout channel identification [32:20] Unused (so far) [19:13] DCC id [12:6] tower [5:3] strip [...
void beginEvent(edm::Event const &, edm::EventSetup const &, bool const &, bool &) override
Definition: TrigPrimTask.cc:57
edm::ESGetToken< EcalTPGTowerStatus, EcalTPGTowerStatusRcd > TTStatusRcd_
Definition: TrigPrimTask.h:61
std::vector< int > bxBinEdgesFine_
Definition: TrigPrimTask.h:55
std::vector< T >::const_iterator const_iterator
std::map< uint32_t, unsigned > towerReadouts_
Definition: TrigPrimTask.h:59
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:526
Class to contain information from TCDS FED.
Definition: TCDSRecord.h:19
edm::EDGetTokenT< TCDSRecord > lhcStatusInfoRecordToken_
Definition: TrigPrimTask.h:67
void addDependencies(DependencySet &) override
Definition: TrigPrimTask.cc:44
void runOnEmulTPs(EcalTrigPrimDigiCollection const &)
virtual void fill(EcalDQMSetupObjects const, DetId const &, double=1., double=1., double=1.)
Definition: MESet.h:74
CaloTowerDetId towerOf(reco::CaloCluster const &cluster, CaloTowerConstituentsMap const &towerMap)
edm::ESGetToken< EcalTPGStripStatus, EcalTPGStripStatusRcd > StripStatusRcd_
Definition: TrigPrimTask.h:62
const EcalTPGStripStatus * StripStatus
Definition: TrigPrimTask.h:64
const_iterator begin() const
int tccId() const
get the DCC (Ecal Local DCC value not global one) id
void runOnDigis(DigiCollection const &)
const BSTRecord & getBST() const
Definition: TCDSRecord.h:100
const_iterator end() const
uint16_t const getBeamMode() const
Definition: BSTRecord.h:70
EcalElectronicsMapping const * GetElectronicsMap()
Definition: DQWorker.cc:150
EcalDQMSetupObjects const getEcalDQMSetupObjects()
Definition: DQWorker.cc:170
EcalTrigPrimDigiCollection const * realTps_
Definition: TrigPrimTask.h:45
void setTokens(edm::ConsumesCollector &) override
std::vector< int > bxBinEdges_
Definition: TrigPrimTask.h:54
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
void runOnRealTPs(EcalTrigPrimDigiCollection const &)
int bunchCrossing() const
Definition: EventBase.h:68
MESetCollection MEs_
Definition: DQWorker.h:131
bool isValid() const
Definition: HandleBase.h:70
iterator find(key_type k)
int ttId() const
get the tower id
const std::map< uint32_t, uint16_t > & getMap() const
EcalTrigTowerConstituentsMap const * GetTrigTowerMap()
Definition: DQWorker.cc:155
const std::map< uint32_t, uint16_t > & getMap() const
std::map< uint32_t, uint16_t > EcalTPGStripStatusMap
virtual void reset(EcalElectronicsMapping const *, double=0., double=0., double=0.)
Definition: MESet.cc:98
void push_back(Dependency const &_d)
Definition: DQWorkerTask.h:46
Ecal trigger electronics identification [32:20] Unused (so far) [19:13] TCC id [12:6] TT id [5:3] pse...
void erase(const std::string &key)
Definition: MESet.h:392
Definition: Run.h:45
edm::InputTag lhcStatusInfoCollectionTag_
Definition: TrigPrimTask.h:66