CMS 3D CMS Logo

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