CMS 3D CMS Logo

TrigPrimTask.cc
Go to the documentation of this file.
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("TTFlags4ByLumi").reset();
69  MEs_.at("LHCStatusByLumi").reset(-1);
70 
71  // 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
72  lhcStatusSet_ = false;
73  }
74 
75  void
77  {
78  using namespace std;
79 
80  towerReadouts_.clear();
81 
82  if (!lhcStatusSet_) {
83  // Update LHC status once each LS
84  MESet& meLHCStatusByLumi(static_cast<MESet&>(MEs_.at("LHCStatusByLumi")));
85  edm::Handle<TCDSRecord> tcdsData;
86  _evt.getByToken(lhcStatusInfoRecordToken_, tcdsData);
87  if (tcdsData.isValid()) {
88  meLHCStatusByLumi.fill(double(tcdsData->getBST().getBeamMode()));
89  lhcStatusSet_ = true;
90  }
91  }
92 
93  realTps_ = nullptr;
94 
95  // HLTCaloBit_ = false;
96  // HLTMuonBit_ = false;
97 
98  int* pBin(std::upper_bound(bxBinEdges_.begin(), bxBinEdges_.end(), _evt.bunchCrossing()));
99  bxBin_ = static_cast<int>(pBin - bxBinEdges_.begin()) - 0.5;
100 
102  _es.get<EcalTPGTowerStatusRcd>().get(TTStatusRcd_);
103  const EcalTPGTowerStatus * TTStatus=TTStatusRcd_.product();
104  const EcalTPGTowerStatusMap &towerMap=TTStatus->getMap();
105 
106  edm::ESHandle<EcalTPGStripStatus> StripStatusRcd_;
107  _es.get<EcalTPGStripStatusRcd>().get(StripStatusRcd_);
108  const EcalTPGStripStatus * StripStatus=StripStatusRcd_.product();
109  const EcalTPGStripStatusMap &stripMap=StripStatus->getMap();
110 
111  MESet& meTTMaskMap(MEs_.at("TTMaskMap"));
112 
113  for(EcalTPGTowerStatusMap::const_iterator ttItr(towerMap.begin()); ttItr != towerMap.end(); ++ttItr){
114 
115  if ((*ttItr).second > 0)
116  {
117  const EcalTrigTowerDetId ttid((*ttItr).first);
118  //if(ttid.subDet() == EcalBarrel)
119  meTTMaskMap.fill(ttid,1);
120  }//masked
121  }//loop on towers
122 
123  for(EcalTPGStripStatusMap::const_iterator stItr(stripMap.begin()); stItr != stripMap.end(); ++stItr){
124 
125  if ((*stItr).second > 0)
126  {
127  const EcalElectronicsId stid((*stItr).first);
128  //if(stid.subdet() == EcalEndcap);
129  meTTMaskMap.fill(stid,1);
130  }//masked
131  }//loop on pseudo-strips
132 
133  // if(HLTCaloPath_.size() || HLTMuonPath_.size()){
134  // edm::TriggerResultsByName results(_evt.triggerResultsByName("HLT"));
135  // if(!results.isValid()) results = _evt.triggerResultsByName("RECO");
136  // if(results.isValid()){
137  // const vector<string>& pathNames(results.triggerNames());
138 
139  // size_t caloStar(HLTCaloPath_.find('*'));
140  // if(caloStar != string::npos){
141  // string caloSub(HLTCaloPath_.substr(0, caloStar));
142  // bool found(false);
143  // for(unsigned iP(0); iP < pathNames.size(); ++iP){
144  // if(pathNames[iP].substr(0, caloStar) == caloSub){
145  // HLTCaloPath_ = pathNames[iP];
146  // found = true;
147  // break;
148  // }
149  // }
150  // if(!found) HLTCaloPath_ = "";
151  // }
152 
153  // size_t muonStar(HLTMuonPath_.find('*'));
154  // if(muonStar != string::npos){
155  // string muonSub(HLTMuonPath_.substr(0, muonStar));
156  // bool found(false);
157  // for(unsigned iP(0); iP < pathNames.size(); ++iP){
158  // if(pathNames[iP].substr(0, muonStar) == muonSub){
159  // HLTMuonPath_ = pathNames[iP];
160  // found = true;
161  // break;
162  // }
163  // }
164  // if(!found) HLTMuonPath_ = "";
165  // }
166 
167  // if(HLTCaloPath_.size()){
168  // try{
169  // HLTCaloBit_ = results.accept(HLTCaloPath_);
170  // }
171  // catch(cms::Exception e){
172  // if(e.category() != "LogicError") throw e;
173  // HLTCaloPath_ = "";
174  // }
175  // }
176  // if(HLTMuonPath_.size()){
177  // try{
178  // HLTMuonBit_ = results.accept(HLTMuonPath_);
179  // }
180  // catch(cms::Exception e){
181  // if(e.category() != "LogicError") throw e;
182  // HLTMuonPath_ = "";
183  // }
184  // }
185  // }
186  // }
187  }
188 
189  template<typename DigiCollection>
190  void
191  TrigPrimTask::runOnDigis(DigiCollection const& _digis)
192  {
193  for(typename DigiCollection::const_iterator digiItr(_digis.begin()); digiItr != _digis.end(); ++digiItr){
194  EcalTrigTowerDetId ttid(getTrigTowerMap()->towerOf(digiItr->id()));
195  towerReadouts_[ttid.rawId()]++;
196  }
197  }
198 
199  void
201  {
203  }
204 
205  void
207  {
208  MESet& meEtVsBx(MEs_.at("EtVsBx"));
209  MESet& meEtReal(MEs_.at("EtReal"));
210  MESet& meEtRealMap(MEs_.at("EtRealMap"));
211  MESet& meEtSummary(MEs_.at("EtSummary"));
212  MESet& meEtSummaryByLumi(MEs_.at("EtSummaryByLumi"));
213  MESet& meLowIntMap(MEs_.at("LowIntMap"));
214  MESet& meMedIntMap(MEs_.at("MedIntMap"));
215  MESet& meHighIntMap(MEs_.at("HighIntMap"));
216  MESet& meTTFlags(MEs_.at("TTFlags"));
217  MESet& meTTFlagsVsEt(MEs_.at("TTFlagsVsEt"));
218  MESet& meTTFlags4( MEs_.at("TTFlags4") );
219  MESet& meTTFlags4ByLumi( MEs_.at("TTFlags4ByLumi") );
220  MESet& meTTFMismatch(MEs_.at("TTFMismatch"));
221  MESet& meOccVsBx(MEs_.at("OccVsBx"));
222 
223  realTps_ = &_tps;
224 
225  double nTP[] = {0., 0., 0.};
226 
227  for(EcalTrigPrimDigiCollection::const_iterator tpItr(_tps.begin()); tpItr != _tps.end(); ++tpItr){
228  EcalTrigTowerDetId ttid(tpItr->id());
229  float et(tpItr->compressedEt());
230 
231  if(et > 0.){
232  if(ttid.subDet() == EcalBarrel)
233  nTP[0] += 1.;
234  else if(ttid.zside() < 0)
235  nTP[1] += 1.;
236  else
237  nTP[2] += 2.;
238  meEtVsBx.fill(ttid, bxBin_, et);
239  }
240 
241  meEtReal.fill(ttid, et);
242  meEtRealMap.fill(ttid, et);
243  meEtSummary.fill(ttid, et);
244  meEtSummaryByLumi.fill(ttid, et);
245 
246  int interest(tpItr->ttFlag() & 0x3);
247 
248  switch(interest){
249  case 0:
250  meLowIntMap.fill(ttid);
251  break;
252  case 1:
253  meMedIntMap.fill(ttid);
254  break;
255  case 3:
256  meHighIntMap.fill(ttid);
257  break;
258  default:
259  break;
260  }
261 
262  // Fill TT Flag MEs
263  int ttF( tpItr->ttFlag() );
264  meTTFlags.fill( ttid, 1.0*ttF );
265  meTTFlagsVsEt.fill(ttid, et, 1.0*ttF);
266  // Monitor occupancy of TTF=4
267  // which contains info about TT auto-masking
268  if ( ttF >= 4 ) {
269  meTTFlags4.fill( ttid );
270  meTTFlags4ByLumi.fill( ttid );
271  }
272  if((ttF == 1 || ttF == 3) && towerReadouts_[ttid.rawId()] != getTrigTowerMap()->constituentsOf(ttid).size())
273  meTTFMismatch.fill(ttid);
274  }
275 
276  meOccVsBx.fill( EcalBarrel, bxBin_, nTP[0]);
277  meOccVsBx.fill(-EcalEndcap, bxBin_, nTP[1]);
278  meOccVsBx.fill( EcalEndcap, bxBin_, nTP[2]);
279 
280  // Set TT/Strip Masking status in Ecal3P view
281  // Status Records are read-in at beginRun() but filled here
282  // Requestied by ECAL Trigger in addition to TTMaskMap plots in SM view
283  MESet& meTTMaskMapAll(MEs_.at("TTMaskMapAll"));
284 
285  // Fill from TT Status Rcd
286  const EcalTPGTowerStatus *TTStatus( TTStatusRcd.product() );
287  const EcalTPGTowerStatusMap &TTStatusMap( TTStatus->getMap() );
288  for( EcalTPGTowerStatusMap::const_iterator ttItr(TTStatusMap.begin()); ttItr != TTStatusMap.end(); ++ttItr ){
289  const EcalTrigTowerDetId ttid( ttItr->first );
290  if ( ttItr->second > 0 )
291  meTTMaskMapAll.setBinContent( ttid,1 ); // TT is masked
292  } // TTs
293 
294  // Fill from Strip Status Rcd
295  const EcalTPGStripStatus *StripStatus( StripStatusRcd.product() );
296  const EcalTPGStripStatusMap &StripStatusMap( StripStatus->getMap() );
297  for( EcalTPGStripStatusMap::const_iterator stItr(StripStatusMap.begin()); stItr != StripStatusMap.end(); ++stItr ){
298  const EcalTriggerElectronicsId stid( stItr->first );
299  // Since ME has kTriggerTower binning, convert to EcalTrigTowerDetId first
300  // In principle, setBinContent() could be implemented for EcalTriggerElectronicsId class as well
301  const EcalTrigTowerDetId ttid( getElectronicsMap()->getTrigTowerDetId(stid.tccId(), stid.ttId()) );
302  if ( stItr->second > 0 )
303  meTTMaskMapAll.setBinContent( ttid,1 ); // PseudoStrip is masked
304  } // PseudoStrips
305 
306  } // TrigPrimTask::runOnRealTPs()
307 
308  void
310  {
311  MESet& meEtMaxEmul(MEs_.at("EtMaxEmul"));
312  MESet& meEmulMaxIndex(MEs_.at("EmulMaxIndex"));
313  MESet& meMatchedIndex(MEs_.at("MatchedIndex"));
314  MESet& meEtEmulError(MEs_.at("EtEmulError"));
315  MESet& meFGEmulError(MEs_.at("FGEmulError"));
316  MESet& meRealvEmulEt(MEs_.at("RealvEmulEt"));
317 
318  for(EcalTrigPrimDigiCollection::const_iterator tpItr(_tps.begin()); tpItr != _tps.end(); ++tpItr){
319  EcalTrigTowerDetId ttid(tpItr->id());
320 
321  int et(tpItr->compressedEt());
322 
323  float maxEt(0.);
324  int iMax(0);
325  for(int iDigi(0); iDigi < 5; iDigi++){
326  float sampleEt((*tpItr)[iDigi].compressedEt());
327 
328  if(sampleEt > maxEt){
329  maxEt = sampleEt;
330  iMax = iDigi + 1;
331  }
332  }
333 
334  meEtMaxEmul.fill(ttid, maxEt);
335  if(maxEt > 0.)
336  meEmulMaxIndex.fill(ttid, iMax);
337 
338  bool match(true);
339  bool matchFG(true);
340 
341  // Loop over real TPs and look for an emulated TP index with matching Et:
342  // If an Et match is found, return TP index correpsonding to BX of emulated TP where match was found
343  // 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 }
345  if(realItr != realTps_->end()){
346 
347  int realEt(realItr->compressedEt());
348 
349  if(realEt > 0){
350 
351  int ttF(realItr->ttFlag());
352  if((ttF == 1 || ttF == 3) && towerReadouts_[ttid.rawId()] == getTrigTowerMap()->constituentsOf(ttid).size()){
353 
354  if(et != realEt) match = false;
355  if(tpItr->fineGrain() != realItr->fineGrain()) matchFG = false;
356 
357  // NOTE: matchedIndex comparison differs from Standard TPG comparison:
358  // { matchedIndex:TP index } = { 0:no emul, 1:BX-2, 2:BX-1, 3:in-time, 4:BX+1, 5:BX+2 }
359  std::vector<int> matchedIndex(0);
360  // iDigi only loops over explicit Et matches:
361  // { iDigi:TP index } = { 0:BX-2, 1:BX-1, 2:in-time, 3:BX+1, 4:BX+2 }
362  for(int iDigi(0); iDigi < 5; iDigi++){
363  if((*tpItr)[iDigi].compressedEt() == realEt) {
364  // matchedIndex = iDigi + 1
365  if (iDigi != 2) {
366  matchedIndex.push_back(iDigi + 1);
367  }
368  // If an in-time match is found, exit loop and clear out any other matches:
369  // Ensures multiple matches are not returned (e.g. during saturation)
370  else {
371  matchedIndex.clear();
372  matchedIndex.push_back(3); // Et match is to in-time emulated TP
373  break;
374  }
375  } // Et match found
376  } // iDigi
377  if(matchedIndex.empty()) matchedIndex.push_back(0); // no Et match found => no emul
378 
379  // Fill Real vs Emulated TP Et
380  meRealvEmulEt.fill( ttid,realEt,(*tpItr)[2].compressedEt() ); // iDigi=2:in-time BX
381 
382  // Fill matchedIndex ME
383  for(std::vector<int>::iterator matchItr(matchedIndex.begin()); matchItr != matchedIndex.end(); ++matchItr){
384  meMatchedIndex.fill(ttid, *matchItr + 0.5);
385 
386  // timing information is only within emulated TPs (real TPs have one time sample)
387  // if(HLTCaloBit_) MEs_[kTimingCalo].fill(ttid, float(*matchItr));
388  // if(HLTMuonBit_) MEs_[kTimingMuon].fill(ttid, float(*matchItr));
389  }
390  }
391 
392  }
393  }
394  else{
395  match = false;
396  matchFG = false;
397  }
398 
399  if(!match) meEtEmulError.fill(ttid);
400  if(!matchFG) meFGEmulError.fill(ttid);
401  }
402  }
403 
405 }
406 
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:109
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:76
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
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()
#define nullptr
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
std::vector< T >::const_iterator const_iterator
int bunchCrossing() const
Definition: EventBase.h:64
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
uint16_t const getBeamMode() const
Definition: BSTRecord.h:73
Class to contain information from TCDS FED.
Definition: TCDSRecord.h:21
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 &)
virtual void fill(DetId const &, double=1., double=1., double=1.)
Definition: MESet.h:45
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)
T get() const
Definition: EventSetup.h:71
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:45
edm::InputTag lhcStatusInfoCollectionTag_
Definition: TrigPrimTask.h:62