CMS 3D CMS Logo

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