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