CMS 3D CMS Logo

APVCyclePhaseProducerFromL1ABC.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SiStripTools
4 // Class: APVCyclePhaseProducerFromL1ABC
5 //
13 //
14 // Original Author: Andrea Venturi
15 // Created: Mon Jan 12 09:05:45 CET 2009
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 
22 // user include files
25 
29 
31 
33 
36 
37 #include <map>
38 #include <vector>
39 #include <string>
40 
41 #include "TH1F.h"
42 #include "TProfile.h"
43 
47 
49 
50 //
51 // class decleration
52 //
53 
55 public:
58 
59 private:
60  void beginJob() override;
61  void beginRun(const edm::Run&, const edm::EventSetup&) override;
62  void endRun(const edm::Run&, const edm::EventSetup&) override;
63  void produce(edm::Event&, const edm::EventSetup&) override;
64  void endJob() override;
65 
66  // ----------member data ---------------------------
67 
70  const std::vector<std::string> _defpartnames;
71  const std::vector<int> _defphases;
72  const int _orbitoffsetSOR;
73  const bool _wantHistos;
74  const bool _forceSCAL;
76 
77  TH1F** _hbx;
78  TH1F** _hdbx;
79  TH1F** _hdorbit;
80  const unsigned int _firstgoodrun;
81  std::map<edm::EventNumber_t, long long> _offsets;
82  long long _curroffset;
84 };
85 
86 //
87 // constants, enums and typedefs
88 //
89 
90 //
91 // static data member definitions
92 //
93 
94 //
95 // constructors and destructor
96 //
98  : _l1abccollectionToken(
99  mayConsume<L1AcceptBunchCrossingCollection>(iConfig.getParameter<edm::InputTag>("l1ABCCollection"))),
100  _tcdsRecordToken(mayConsume<TCDSRecord>(iConfig.getParameter<edm::InputTag>("tcdsRecordLabel"))),
101  _defpartnames(iConfig.getParameter<std::vector<std::string> >("defaultPartitionNames")),
102  _defphases(iConfig.getParameter<std::vector<int> >("defaultPhases")),
103  _orbitoffsetSOR(iConfig.getParameter<int>("StartOfRunOrbitOffset")),
104  _wantHistos(iConfig.getUntrackedParameter<bool>("wantHistos", false)),
105  _forceSCAL(iConfig.getParameter<bool>("forceSCAL")),
106  m_rhm(consumesCollector()),
107  _hbx(nullptr),
108  _hdbx(nullptr),
109  _hdorbit(nullptr),
110  _firstgoodrun(110878),
111  _offsets(),
112  _curroffset(0),
113  _curroffevent(0) {
114  produces<APVCyclePhaseCollection, edm::InEvent>();
115 
116  //now do what ever other initialization is needed
117 
118  if (_wantHistos) {
119  _hbx = m_rhm.makeTH1F("l1abcbx", "BX number from TCDS (or L1ABC as fallback)", 4096, -0.5, 4095.5);
120  _hdbx = m_rhm.makeTH1F("dbx", "BX number difference", 4096 * 2 - 1, -4095.5, 4095.5);
121  _hdorbit = m_rhm.makeTH1F("dorbit", "Orbit Number difference", 9999, -4999.5, 4999.5);
122  }
123 }
124 
126  // do anything here that needs to be done at desctruction time
127  // (e.g. close files, deallocate resources etc.)
128 }
129 
130 //
131 // member functions
132 //
133 
134 // ------------ method called to produce the data ------------
136 
137 {
138  // reset offset vector
139 
140  _offsets.clear();
141  edm::LogInfo("AbsoluteBXOffsetReset") << "Absolute BX offset map reset";
142 
143  if (_wantHistos) {
144  m_rhm.beginRun(iRun);
145 
146  if (_hbx && *_hbx) {
147  (*_hbx)->GetXaxis()->SetTitle("BX");
148  (*_hbx)->GetYaxis()->SetTitle("Events");
149  }
150 
151  if (_hdbx && *_hdbx) {
152  (*_hdbx)->GetXaxis()->SetTitle("#DeltaBX");
153  (*_hdbx)->GetYaxis()->SetTitle("Events");
154  }
155 
156  if (_hdorbit && *_hdorbit) {
157  (*_hdorbit)->GetXaxis()->SetTitle("#Deltaorbit");
158  (*_hdorbit)->GetYaxis()->SetTitle("Events");
159  }
160  }
161 
162  if (iRun.run() < _firstgoodrun) {
163  edm::LogInfo("UnreliableMissingL1AcceptBunchCrossingCollection")
164  << "In this run L1AcceptBunchCrossingCollection is missing or unreliable: default phases will be used";
165  }
166 }
167 
169  // summary of absolute bx offset vector
170 
171  edm::LogInfo("L1AcceptBunchCrossingAbsoluteBXOffsetSummary") << "Absolute BX offset summary:";
172  for (std::map<edm::EventNumber_t, long long>::const_iterator offset = _offsets.begin(); offset != _offsets.end();
173  ++offset) {
174  edm::LogVerbatim("L1AcceptBunchCrossingAbsoluteBXOffsetSummary") << offset->first << " " << offset->second;
175  }
176 }
177 
179  using namespace edm;
180 
181  std::unique_ptr<APVCyclePhaseCollection> apvphases(new APVCyclePhaseCollection());
182 
183  const std::vector<int>& phases = _defphases;
184  const std::vector<std::string>& partnames = _defpartnames;
185 
186  // Look for the L1AcceptBunchCrossingCollection
187 
188  int phasechange = 0;
189 
190  if (iEvent.run() >= _firstgoodrun) {
192  iEvent.getByToken(_l1abccollectionToken, pIn);
193  Handle<TCDSRecord> tcds_pIn;
194  iEvent.getByToken(_tcdsRecordToken, tcds_pIn);
195  bool useTCDS(tcds_pIn.isValid() && !_forceSCAL);
196  const auto* tcdsRecord = useTCDS ? tcds_pIn.product() : nullptr;
197  // offset computation
198 
199  long long orbitoffset = _orbitoffsetSOR;
200  int bxoffset = 0;
201 
202  if (useTCDS) {
203  if (tcdsRecord->getL1aHistoryEntry(0).getIndex() == 0) {
204  if (tcdsRecord->getEventType() != 0) {
205  orbitoffset = (long long)tcdsRecord->getOrbitNr() - (long long)iEvent.orbitNumber();
206  // In EventWithHistoryProducerFromL1ABC, it's -1\times this, following the corresponding L1ABC line below. I keep this difference here, because I am not sure if it should be kept or not
207  bxoffset = iEvent.bunchCrossing() - tcdsRecord->getBXID();
208  // If I understand correctly, tcdsRecord has no l1AcceptOffset thing, so the control done for l1abc can be safely skipped
209  if (_wantHistos) {
210  if (_hbx && *_hbx)
211  (*_hbx)->Fill(tcdsRecord->getBXID());
212  if (_hdbx && *_hdbx)
213  (*_hdbx)->Fill(bxoffset);
214  if (_hdorbit && *_hdorbit)
215  (*_hdorbit)->Fill(orbitoffset);
216  }
217  }
218  } else {
219  edm::LogWarning("L1AcceptBunchCrossingNoType") << "L1AcceptBunchCrossing with no type found: ";
220  edm::LogPrint("L1AcceptBunchCrossingNoType") << *tcdsRecord;
221  }
222  } else {
223  for (L1AcceptBunchCrossingCollection::const_iterator l1abc = pIn->begin(); l1abc != pIn->end(); ++l1abc) {
224  if (l1abc->l1AcceptOffset() == 0) {
225  if (l1abc->eventType() != 0) {
226  orbitoffset = (long long)iEvent.orbitNumber() - (long long)l1abc->orbitNumber();
227  bxoffset =
228  iEvent.bunchCrossing() -
229  l1abc->bunchCrossing(); // In EventWithHistoryProducerFromL1ABC, it's l1abc - iEvent. I keep this difference here, because I am not sure if it should be kept or not
230 
231  if (_wantHistos) {
232  if (_hbx && *_hbx)
233  (*_hbx)->Fill(l1abc->bunchCrossing());
234  if (_hdbx && *_hdbx)
235  (*_hdbx)->Fill(bxoffset);
236  if (_hdorbit && *_hdorbit)
237  (*_hdorbit)->Fill(orbitoffset);
238  }
239  } else {
240  edm::LogWarning("L1AcceptBunchCrossingNoType") << "L1AcceptBunchCrossing with no type found: ";
241  for (L1AcceptBunchCrossingCollection::const_iterator debu = pIn->begin(); debu != pIn->end(); ++debu) {
242  edm::LogPrint("L1AcceptBunchCrossingNoType") << *debu;
243  }
244  }
245  }
246  }
247  }
248 
249  long long absbxoffset = orbitoffset * 3564 + bxoffset;
250 
251  if (orbitoffset != _orbitoffsetSOR)
252  phasechange = (orbitoffset * 3564) % 70;
253 
254  if (_offsets.empty()) {
255  _curroffset = absbxoffset;
256  _curroffevent = iEvent.id().event();
257  _offsets[iEvent.id().event()] = absbxoffset;
258  } else {
259  if (_curroffset != absbxoffset || iEvent.id().event() < _curroffevent) {
260  if (_curroffset != absbxoffset) {
261  edm::LogInfo("L1AcceptBunchCrossingAbsoluteBXOffsetChanged")
262  << "Absolute BX offset changed from " << _curroffset << " to " << absbxoffset << " at orbit "
263  << iEvent.orbitNumber() << " and BX " << iEvent.bunchCrossing();
264  if (useTCDS) {
265  edm::LogVerbatim("AbsoluteBXOffsetChanged") << *tcdsRecord; // Not sure about this
266  } else {
267  for (L1AcceptBunchCrossingCollection::const_iterator l1abc = pIn->begin(); l1abc != pIn->end(); ++l1abc) {
268  edm::LogVerbatim("L1AcceptBunchCrossingAbsoluteBXOffsetChanged") << *l1abc;
269  }
270  }
271  }
272 
273  _curroffset = absbxoffset;
274  _curroffevent = iEvent.id().event();
275  _offsets[iEvent.id().event()] = absbxoffset;
276  }
277  }
278  }
279 
280  if (phases.size() < partnames.size()) {
281  // throw exception
282  throw cms::Exception("InvalidAPVCyclePhases")
283  << " Inconsistent phases/partitions vector sizes: " << phases.size() << " " << partnames.size();
284  }
285 
286  for (unsigned int ipart = 0; ipart < partnames.size(); ++ipart) {
287  if (phases[ipart] >= 0) {
288  apvphases->get()[partnames[ipart]] = (phases[ipart] + phasechange) % 70;
289  }
290  }
291 
292  iEvent.put(std::move(apvphases));
293 }
294 
295 // ------------ method called once each job just before starting event loop ------------
297 
298 // ------------ method called once each job just after ending the event loop ------------
300 
301 //define this as a plug-in
electrons_cff.bool
bool
Definition: electrons_cff.py:366
MessageLogger.h
funct::false
false
Definition: Factorize.h:29
edm::Handle::product
T const * product() const
Definition: Handle.h:70
EDProducer.h
APVCyclePhaseProducerFromL1ABC::_forceSCAL
const bool _forceSCAL
Definition: APVCyclePhaseProducerFromL1ABC.cc:74
APVCyclePhaseProducerFromL1ABC::beginRun
void beginRun(const edm::Run &, const edm::EventSetup &) override
Definition: APVCyclePhaseProducerFromL1ABC.cc:135
edm::Run
Definition: Run.h:45
phases
std::vector< int > phases
Definition: compareAlignments.cc:30
edm::EDGetTokenT< L1AcceptBunchCrossingCollection >
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::LogPrint
Log< level::Warning, true > LogPrint
Definition: MessageLogger.h:130
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
L1AcceptBunchCrossing.h
APVCyclePhaseProducerFromL1ABC::_tcdsRecordToken
edm::EDGetTokenT< TCDSRecord > _tcdsRecordToken
Definition: APVCyclePhaseProducerFromL1ABC.cc:69
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
edm::Handle
Definition: AssociativeIterator.h:50
edm::RunBase::run
RunNumber_t run() const
Definition: RunBase.h:40
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
APVCyclePhaseProducerFromL1ABC::endRun
void endRun(const edm::Run &, const edm::EventSetup &) override
Definition: APVCyclePhaseProducerFromL1ABC.cc:168
MakerMacros.h
APVCyclePhaseProducerFromL1ABC::_wantHistos
const bool _wantHistos
Definition: APVCyclePhaseProducerFromL1ABC.cc:73
RunHistogramManager
Definition: RunHistogramManager.h:210
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
TCDSRecord.h
APVCyclePhaseProducerFromL1ABC::_curroffevent
edm::EventNumber_t _curroffevent
Definition: APVCyclePhaseProducerFromL1ABC.cc:83
RunHistogramManager.h
APVCyclePhaseCollection
Definition: APVCyclePhaseCollection.h:8
L1AcceptBunchCrossingCollection
std::vector< L1AcceptBunchCrossing > L1AcceptBunchCrossingCollection
Definition: L1AcceptBunchCrossing.h:83
Run.h
edm::EventNumber_t
unsigned long long EventNumber_t
Definition: RunLumiEventNumber.h:12
APVCyclePhaseProducerFromL1ABC
Definition: APVCyclePhaseProducerFromL1ABC.cc:54
RunHistogramManager::makeTH1F
TH1F ** makeTH1F(const char *name, const char *title, const unsigned int nbinx, const double xmin, const double xmax)
Definition: RunHistogramManager.cc:33
APVCyclePhaseProducerFromL1ABC::APVCyclePhaseProducerFromL1ABC
APVCyclePhaseProducerFromL1ABC(const edm::ParameterSet &)
Definition: APVCyclePhaseProducerFromL1ABC.cc:97
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
RunHistogramManager::beginRun
void beginRun(const edm::Run &iRun)
Definition: RunHistogramManager.cc:101
APVCyclePhaseProducerFromL1ABC::_offsets
std::map< edm::EventNumber_t, long long > _offsets
Definition: APVCyclePhaseProducerFromL1ABC.cc:81
APVCyclePhaseCollection.h
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
APVCyclePhaseProducerFromL1ABC::_curroffset
long long _curroffset
Definition: APVCyclePhaseProducerFromL1ABC.cc:82
APVCyclePhaseProducerFromL1ABC::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: APVCyclePhaseProducerFromL1ABC.cc:178
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
edm::EventSetup
Definition: EventSetup.h:58
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
InputTag.h
APVCyclePhaseProducerFromL1ABC::endJob
void endJob() override
Definition: APVCyclePhaseProducerFromL1ABC.cc:299
APVCyclePhaseProducerFromL1ABC::_orbitoffsetSOR
const int _orbitoffsetSOR
Definition: APVCyclePhaseProducerFromL1ABC.cc:72
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
Frameworkfwd.h
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
TCDSRecord
Class to contain information from TCDS FED.
Definition: TCDSRecord.h:19
Exception
Definition: hltDiff.cc:245
APVCyclePhaseProducerFromL1ABC::_l1abccollectionToken
edm::EDGetTokenT< L1AcceptBunchCrossingCollection > _l1abccollectionToken
Definition: APVCyclePhaseProducerFromL1ABC.cc:68
edm::EDProducer
Definition: EDProducer.h:35
APVCyclePhaseProducerFromL1ABC::beginJob
void beginJob() override
Definition: APVCyclePhaseProducerFromL1ABC.cc:296
Exception.h
APVCyclePhaseProducerFromL1ABC::_defphases
const std::vector< int > _defphases
Definition: APVCyclePhaseProducerFromL1ABC.cc:71
ParameterSet.h
APVCyclePhaseProducerFromL1ABC::~APVCyclePhaseProducerFromL1ABC
~APVCyclePhaseProducerFromL1ABC() override
Definition: APVCyclePhaseProducerFromL1ABC.cc:125
APVCyclePhaseProducerFromL1ABC::_firstgoodrun
const unsigned int _firstgoodrun
Definition: APVCyclePhaseProducerFromL1ABC.cc:80
APVCyclePhaseProducerFromL1ABC::_hdorbit
TH1F ** _hdorbit
Definition: APVCyclePhaseProducerFromL1ABC.cc:79
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
hltrates_dqm_sourceclient-live_cfg.offset
offset
Definition: hltrates_dqm_sourceclient-live_cfg.py:82
edm::Event
Definition: Event.h:73
APVCyclePhaseProducerFromL1ABC::m_rhm
RunHistogramManager m_rhm
Definition: APVCyclePhaseProducerFromL1ABC.cc:75
APVCyclePhaseProducerFromL1ABC::_hbx
TH1F ** _hbx
Definition: APVCyclePhaseProducerFromL1ABC.cc:77
APVCyclePhaseProducerFromL1ABC::_hdbx
TH1F ** _hdbx
Definition: APVCyclePhaseProducerFromL1ABC.cc:78
APVCyclePhaseProducerFromL1ABC::_defpartnames
const std::vector< std::string > _defpartnames
Definition: APVCyclePhaseProducerFromL1ABC.cc:70