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 
6 
9 
10 namespace ecaldqm {
11 
13  DQWorkerTask(_params, _paths, "TrigPrimTask"),
14  ttMap_(0),
15  realTps_(0),
16  runOnEmul_(true),
17  expectedTiming_(0),
18  HLTCaloPath_(""),
19  HLTMuonPath_(""),
20  HLTCaloBit_(false),
21  HLTMuonBit_(false),
22  bxBin_(0.),
23  towerReadouts_()
24  {
26  (0x1 << kRun) |
27  (0x1 << kEBDigi) |
28  (0x1 << kEEDigi) |
29  (0x1 << kTrigPrimDigi) |
30  (0x1 << kTrigPrimEmulDigi);
31 
32  dependencies_.push_back(std::pair<Collections, Collections>(kTrigPrimEmulDigi, kEBDigi));
33  dependencies_.push_back(std::pair<Collections, Collections>(kTrigPrimEmulDigi, kEEDigi));
34  dependencies_.push_back(std::pair<Collections, Collections>(kTrigPrimEmulDigi, kTrigPrimDigi));
35 
36  edm::ParameterSet const& taskParams(_params.getUntrackedParameterSet(name_));
37 
38  runOnEmul_ = taskParams.getUntrackedParameter<bool>("runOnEmul");
39  expectedTiming_ = taskParams.getUntrackedParameter<int>("expectedTiming");
40  HLTCaloPath_ = taskParams.getUntrackedParameter<std::string>("HLTCaloPath");
41  HLTMuonPath_ = taskParams.getUntrackedParameter<std::string>("HLTMuonPath");
42 
43  // binning in terms of bunch trains
44  int binEdges[nBXBins + 1] = {1, 271, 541, 892, 1162, 1432, 1783, 2053, 2323, 2674, 2944, 3214, 3446, 3490, 3491, 3565};
45  for(int i(0); i < nBXBins + 1; i++) bxBinEdges_[i] = binEdges[i];
46 
47  if(!runOnEmul_) collectionMask_ &= ~(0x1 << kTrigPrimEmulDigi);
48  }
49 
51  {
52  }
53 
54  void
56  {
57  std::stringstream ss;
58 
59  if(runOnEmul_){
61  MEs_[kEmulMaxIndex]->setBinLabel(-1, 1, "no emul", 1);
62  for(int i(2); i <= 6; i++){
63  ss.str("");
64  ss << (i - 1);
65  MEs_[kEmulMaxIndex]->setBinLabel(-1, i, ss.str(), 1);
66  }
67  }
68  else{
69  unsigned bookList[] = {kEtReal, kEtRealMap, kEtSummary, kEtVsBx, kOccVsBx,
71  for(unsigned iME(0); iME < sizeof(bookList) / sizeof(unsigned); iME++)
72  MEs_[bookList[iME]]->book();
73  }
74 
75  int iBin(1);
76  for(int i(1); i < nBXBins + 1; i++){
77  ss.str("");
78  if(bxBinEdges_[i] - bxBinEdges_[i - 1] == 1) ss << bxBinEdges_[i - 1];
79  else ss << bxBinEdges_[i - 1] << " - " << (bxBinEdges_[i] - 1);
80  MEs_[kEtVsBx]->setBinLabel(-1, iBin, ss.str(), 1);
81  MEs_[kOccVsBx]->setBinLabel(-1, iBin, ss.str(), 1);
82  iBin++;
83  }
84  }
85 
86  void
88  {
90  _es.get<IdealGeometryRecord>().get(ttMapHndl);
91  ttMap_ = ttMapHndl.product();
92  }
93 
94  void
96  {
97  using namespace std;
98 
99  towerReadouts_.clear();
100 
101  realTps_ = 0;
102 
103  HLTCaloBit_ = false;
104  HLTMuonBit_ = false;
105 
106  int* pBin(std::upper_bound(bxBinEdges_, bxBinEdges_ + nBXBins + 1, _evt.bunchCrossing()));
107  bxBin_ = static_cast<int>(pBin - bxBinEdges_) - 0.5;
108 
109 // if(HLTCaloPath_.size() || HLTMuonPath_.size()){
110 // edm::TriggerResultsByName results(_evt.triggerResultsByName("HLT"));
111 // if(!results.isValid()) results = _evt.triggerResultsByName("RECO");
112 // if(results.isValid()){
113 // const vector<string>& pathNames(results.triggerNames());
114 
115 // size_t caloStar(HLTCaloPath_.find('*'));
116 // if(caloStar != string::npos){
117 // string caloSub(HLTCaloPath_.substr(0, caloStar));
118 // bool found(false);
119 // for(unsigned iP(0); iP < pathNames.size(); ++iP){
120 // if(pathNames[iP].substr(0, caloStar) == caloSub){
121 // HLTCaloPath_ = pathNames[iP];
122 // found = true;
123 // break;
124 // }
125 // }
126 // if(!found) HLTCaloPath_ = "";
127 // }
128 
129 // size_t muonStar(HLTMuonPath_.find('*'));
130 // if(muonStar != string::npos){
131 // string muonSub(HLTMuonPath_.substr(0, muonStar));
132 // bool found(false);
133 // for(unsigned iP(0); iP < pathNames.size(); ++iP){
134 // if(pathNames[iP].substr(0, muonStar) == muonSub){
135 // HLTMuonPath_ = pathNames[iP];
136 // found = true;
137 // break;
138 // }
139 // }
140 // if(!found) HLTMuonPath_ = "";
141 // }
142 
143 // if(HLTCaloPath_.size()){
144 // try{
145 // HLTCaloBit_ = results.accept(HLTCaloPath_);
146 // }
147 // catch(cms::Exception e){
148 // if(e.category() != "LogicError") throw e;
149 // std::cout << e.message() << std::endl;
150 // HLTCaloPath_ = "";
151 // }
152 // }
153 // if(HLTMuonPath_.size()){
154 // try{
155 // HLTMuonBit_ = results.accept(HLTMuonPath_);
156 // }
157 // catch(cms::Exception e){
158 // if(e.category() != "LogicError") throw e;
159 // std::cout << e.message() << std::endl;
160 // HLTMuonPath_ = "";
161 // }
162 // }
163 // }
164 // }
165  }
166 
167  void
169  {
170  for(EcalDigiCollection::const_iterator digiItr(_digis.begin()); digiItr != _digis.end(); ++digiItr){
171  EcalTrigTowerDetId ttid(ttMap_->towerOf(digiItr->id()));
172  towerReadouts_[ttid.rawId()]++;
173  }
174  }
175 
176  void
178  {
179  realTps_ = &_tps;
180 
181  float nTP(0.);
182 
183  for(EcalTrigPrimDigiCollection::const_iterator tpItr(_tps.begin()); tpItr != _tps.end(); ++tpItr){
184  EcalTrigTowerDetId ttid(tpItr->id());
185  float et(tpItr->compressedEt());
186 
187  if(et > 0.){
188  nTP += 1.;
189  MEs_[kEtVsBx]->fill(ttid, bxBin_, et);
190  }
191 
192  MEs_[kEtReal]->fill(ttid, et);
193  MEs_[kEtRealMap]->fill(ttid, et);
194  MEs_[kEtSummary]->fill(ttid, et);
195 
196  int interest(tpItr->ttFlag() & 0x3);
197 
198  switch(interest){
199  case 0:
200  MEs_[kLowIntMap]->fill(ttid);
201  break;
202  case 1:
203  MEs_[kMedIntMap]->fill(ttid);
204  break;
205  case 3:
206  MEs_[kHighIntMap]->fill(ttid);
207  break;
208  default:
209  break;
210  }
211 
212  MEs_[kTTFlags]->fill(ttid, float(tpItr->ttFlag()));
213 
214  if((interest == 1 || interest == 3) && towerReadouts_[ttid.rawId()] != ttMap_->constituentsOf(ttid).size())
215  MEs_[kTTFMismatch]->fill(ttid);
216  }
217 
218  MEs_[kOccVsBx]->fill(bxBin_, nTP);
219  }
220 
221  void
223  {
224  for(EcalTrigPrimDigiCollection::const_iterator tpItr(_tps.begin()); tpItr != _tps.end(); ++tpItr){
225  EcalTrigTowerDetId ttid(tpItr->id());
226  int et(tpItr->compressedEt());
227 
228  // MEs_[kEtEmul]->fill(ttid, et);
229 
230  // MEs_[kEtEmulMap]->fill(ttid, et);
231 
232  float maxEt(0);
233  int iMax(0);
234  for(int iDigi(0); iDigi < 5; iDigi++){
235  float sampleEt((*tpItr)[iDigi].compressedEt());
236 
237  if(sampleEt > maxEt){
238  maxEt = sampleEt;
239  iMax = iDigi + 1;
240  }
241  }
242 
243  MEs_[kEtMaxEmul]->fill(ttid, maxEt);
244  MEs_[kEmulMaxIndex]->fill(ttid, iMax + 0.5);
245 
246  bool match(true);
247  bool matchFG(true);
248 
250  if(realItr != realTps_->end()){
251 
252  int realEt(realItr->compressedEt());
253 
254  if(realEt <= 0) continue;
255 
256  int interest(realItr->ttFlag() & 0x3);
257  if((interest == 1 || interest == 3) && towerReadouts_[ttid.rawId()] == ttMap_->constituentsOf(ttid).size()){
258 
259  if(et != realEt) match = false;
260  if(tpItr->fineGrain() != realItr->fineGrain()) matchFG = false;
261 
262  std::vector<int> matchedIndex(0);
263  for(int iDigi(0); iDigi < 5; iDigi++){
264  if((*tpItr)[iDigi].compressedEt() == realEt)
265  matchedIndex.push_back(iDigi + 1);
266  }
267 
268  if(!matchedIndex.size()) matchedIndex.push_back(0);
269  for(std::vector<int>::iterator matchItr(matchedIndex.begin()); matchItr != matchedIndex.end(); ++matchItr){
270  MEs_[kMatchedIndex]->fill(ttid, *matchItr + 0.5);
271 
272  // timing information is only within emulated TPs (real TPs have one time sample)
273 // if(HLTCaloBit_) MEs_[kTimingCalo]->fill(ttid, float(*matchItr));
274 // if(HLTMuonBit_) MEs_[kTimingMuon]->fill(ttid, float(*matchItr));
275 
276  if(*matchItr != expectedTiming_) MEs_[kTimingError]->fill(ttid);
277  }
278 
279  }
280  }
281  else{
282  match = false;
283  matchFG = false;
284  }
285 
286  if(!match) MEs_[kEtEmulError]->fill(ttid);
287  if(!matchFG) MEs_[kFGEmulError]->fill(ttid);
288  }
289  }
290 
291  /*static*/
292  void
293  TrigPrimTask::setMEData(std::vector<MEData>& _data)
294  {
295  BinService::AxisSpecs indexAxis;
296  indexAxis.nbins = 6;
297  indexAxis.low = 0.;
298  indexAxis.high = 6.;
299  indexAxis.title = "TP index";
300 
301  BinService::AxisSpecs etAxis;
302  etAxis.nbins = 128;
303  etAxis.low = 0.;
304  etAxis.high = 256.;
305  etAxis.title = "TP Et";
306 
307  BinService::AxisSpecs bxAxis;
308  bxAxis.nbins = 15;
309  bxAxis.low = 0.;
310  bxAxis.high = bxAxis.nbins;
311 
312  BinService::AxisSpecs flagAxis;
313  flagAxis.nbins = 8;
314  flagAxis.low = 0.;
315  flagAxis.high = 8.;
316  flagAxis.title = "TT flag";
317 
321  // _data[kEtEmulMap] = MEData("EtEmulMap", BinService::kSM, BinService::kTriggerTower, MonitorElement::DQM_KIND_TPROFILE2D, 0, 0, &etAxis);
333 // _data[kTimingCalo] = MEData("TimingCalo", BinService::kEcal2P, BinService::kTCC, MonitorElement::DQM_KIND_TH2F);
334 // _data[kTimingMuon] = MEData("TimingMuon", BinService::kEcal2P, BinService::kTCC, MonitorElement::DQM_KIND_TH2F);
337  }
338 
340 }
341 
342 
int i
Definition: DBlmapReader.cc:9
std::vector< std::pair< Collections, Collections > > dependencies_
Definition: DQWorkerTask.h:31
static void setMEData(std::vector< MEData > &)
string fill
Definition: lumiContext.py:319
#define DEFINE_ECALDQM_WORKER(TYPE)
Definition: DQWorker.h:93
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
void runOnEmulTPs(const EcalTrigPrimDigiCollection &)
std::vector< T >::const_iterator const_iterator
int bunchCrossing() const
Definition: EventBase.h:62
std::map< uint32_t, unsigned > towerReadouts_
Definition: TrigPrimTask.h:73
const_iterator begin() const
void runOnRealTPs(const EcalTrigPrimDigiCollection &)
EcalTrigTowerDetId towerOf(const DetId &id) const
Get the tower id for this det id (or null if not known)
const EcalTrigTowerConstituentsMap * ttMap_
Definition: TrigPrimTask.h:59
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
std::string HLTMuonPath_
Definition: TrigPrimTask.h:66
std::string HLTCaloPath_
Definition: TrigPrimTask.h:65
ParameterSet const & getUntrackedParameterSet(std::string const &name, ParameterSet const &defaultValue) const
TrigPrimTask(const edm::ParameterSet &, const edm::ParameterSet &)
Definition: TrigPrimTask.cc:12
const EcalTrigPrimDigiCollection * realTps_
Definition: TrigPrimTask.h:60
void beginRun(const edm::Run &, const edm::EventSetup &)
Definition: TrigPrimTask.cc:87
std::vector< DetId > constituentsOf(const EcalTrigTowerDetId &id) const
Get the constituent detids for this tower id.
void beginEvent(const edm::Event &, const edm::EventSetup &)
Definition: TrigPrimTask.cc:95
const_iterator end() const
virtual void bookMEs()
Definition: DQWorker.cc:48
std::vector< MESet * > MEs_
Definition: DQWorker.h:56
int bxBinEdges_[nBXBins+1]
Definition: TrigPrimTask.h:70
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
const_iterator end() const
iterator find(key_type k)
void runOnDigis(const EcalDigiCollection &)
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:6
std::string name_
Definition: DQWorker.h:55
const_iterator begin() const
Definition: Run.h:33