CMS 3D CMS Logo

APVCyclePhaseMonitor.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SiStripTools
4 // Class: APVCyclePhaseMonitor
5 //
13 //
14 // Original Author: Andrea Venturi
15 // Created: Tue Jul 19 11:56:00 CEST 2009
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 
22 // user include files
23 #include "TH1F.h"
24 #include "TProfile.h"
25 
28 
32 
34 
36 
39 
41 
43 
45 
46 //
47 // class decleration
48 //
49 
51 public:
52  explicit APVCyclePhaseMonitor(const edm::ParameterSet&);
53  ~APVCyclePhaseMonitor() override;
54 
55 private:
56  void beginJob() override;
57  void beginRun(const edm::Run&, const edm::EventSetup&) override;
58  void endRun(const edm::Run&, const edm::EventSetup&) override;
59  void analyze(const edm::Event&, const edm::EventSetup&) override;
60  void endJob() override;
61 
62  // ----------member data ---------------------------
63 
65  std::vector<std::string> _selectedparts;
66  std::vector<std::string> _selectedvectorparts;
67  const unsigned int m_maxLS;
68  const unsigned int m_LSfrac;
70  std::map<std::string, TH1F*> _hphases;
71  std::map<std::string, TH1F**> _hselectedphases;
72  std::map<std::string, TH1F**> _hselectedphasesvector;
73  std::map<std::string, TH1F**> _hselectedphasessize;
74  std::map<std::string, TProfile*> _hphasevsorbit;
75  std::map<std::string, TProfile**> _hselectedphasevsorbit;
76  std::map<std::string, TProfile**> _hselectedphasevectorvsorbit;
77  unsigned int _nevents;
78 };
79 
80 //
81 // constants, enums and typedefs
82 //
83 
84 //
85 // static data member definitions
86 //
87 
88 //
89 // constructors and destructor
90 //
92  : _apvphasecollectionToken(
93  consumes<APVCyclePhaseCollection>(iConfig.getParameter<edm::InputTag>("apvCyclePhaseCollection"))),
94  _selectedparts(
95  iConfig.getUntrackedParameter<std::vector<std::string> >("selectedPartitions", std::vector<std::string>())),
96  _selectedvectorparts(iConfig.getUntrackedParameter<std::vector<std::string> >("selectedVectorPartitions",
97  std::vector<std::string>())),
98  m_maxLS(iConfig.getUntrackedParameter<unsigned int>("maxLSBeforeRebin", 125)),
99  m_LSfrac(iConfig.getUntrackedParameter<unsigned int>("startingLSFraction", 16)),
100  m_rhm(consumesCollector()),
101  _hphases(),
102  _hselectedphases(),
103  _hselectedphasesvector(),
104  _hselectedphasessize(),
105  _hphasevsorbit(),
106  _hselectedphasevsorbit(),
107  _hselectedphasevectorvsorbit(),
108  _nevents(0) {
109  //now do what ever initialization is needed
110 
111  edm::LogInfo("UsedAPVCyclePhaseCollection")
112  << " APVCyclePhaseCollection " << iConfig.getParameter<edm::InputTag>("apvCyclePhaseCollection") << " used";
113 
114  for (std::vector<std::string>::const_iterator part = _selectedparts.begin(); part != _selectedparts.end(); ++part) {
115  char hname[300];
116 
117  sprintf(hname, "selected_phase_%s", part->c_str());
118  edm::LogInfo("SelectedTH1FBeingBooked") << "TH1F " << hname << " being booked";
119  _hselectedphases[*part] = m_rhm.makeTH1F(hname, hname, 70, -0.5, 69.5);
120 
121  sprintf(hname, "selected_phasevsorbit_%s", part->c_str());
122  edm::LogInfo("SelectedTProfileBeingBooked") << "TProfile " << hname << " being booked";
123  _hselectedphasevsorbit[*part] = m_rhm.makeTProfile(hname, hname, m_LSfrac * m_maxLS, 0, m_maxLS * 262144);
124  }
125 
126  for (std::vector<std::string>::const_iterator part = _selectedvectorparts.begin(); part != _selectedvectorparts.end();
127  ++part) {
128  char hname[300];
129 
130  sprintf(hname, "selected_phase_vector_%s", part->c_str());
131  edm::LogInfo("SelectedVectTH1FBeingBooked") << "TH1F " << hname << " being booked";
132  _hselectedphasesvector[*part] = m_rhm.makeTH1F(hname, hname, 70, -0.5, 69.5);
133 
134  sprintf(hname, "selected_phase_size_%s", part->c_str());
135  edm::LogInfo("SelectedVectSizeTH1FBeingBooked") << "TH1F " << hname << " being booked";
136  _hselectedphasessize[*part] = m_rhm.makeTH1F(hname, hname, 10, -0.5, 9.5);
137 
138  sprintf(hname, "selected_phasevectorvsorbit_%s", part->c_str());
139  edm::LogInfo("SelectedVectTProfileBeingBooked") << "TProfile " << hname << " being booked";
140  _hselectedphasevectorvsorbit[*part] = m_rhm.makeTProfile(hname, hname, m_LSfrac * m_maxLS, 0, m_maxLS * 262144);
141  }
142 }
143 
145  // do anything here that needs to be done at desctruction time
146  // (e.g. close files, deallocate resources etc.)
147 }
148 
149 //
150 // member functions
151 //
152 
153 // ------------ method called to for each event ------------
155  using namespace edm;
156 
157  _nevents++;
158 
160  iEvent.getByToken(_apvphasecollectionToken, apvphases);
161 
162  // improve the matchin between default and actual partitions
163 
165 
166  for (std::map<std::string, int>::const_iterator phase = apvphases->get().begin(); phase != apvphases->get().end();
167  ++phase) {
168  if (_hphases.find(phase->first) == _hphases.end()) {
169  char dirname[300];
170  sprintf(dirname, "run_%d", iEvent.run());
171  TFileDirectory subrun = tfserv->mkdir(dirname);
172 
173  char hname[300];
174 
175  sprintf(hname, "phase_%s", phase->first.c_str());
176  edm::LogInfo("TH1FBeingBooked") << "TH1F " << hname << " being booked";
177  _hphases[phase->first] = subrun.make<TH1F>(hname, hname, 70, -0.5, 69.5);
178  _hphases[phase->first]->GetXaxis()->SetTitle("BX mod 70");
179  _hphases[phase->first]->GetYaxis()->SetTitle("Events");
180 
181  sprintf(hname, "phasevsorbit_%s", phase->first.c_str());
182  edm::LogInfo("TProfileBeingBooked") << "TProfile " << hname << " being booked";
183  _hphasevsorbit[phase->first] = subrun.make<TProfile>(hname, hname, m_LSfrac * m_maxLS, 0, m_maxLS * 262144);
184  _hphasevsorbit[phase->first]->SetCanExtend(TH1::kXaxis);
185  _hphasevsorbit[phase->first]->GetXaxis()->SetTitle("time [orbit#]");
186  _hphasevsorbit[phase->first]->GetYaxis()->SetTitle("Phase");
187  }
188  _hphases[phase->first]->Fill(phase->second);
189  _hphasevsorbit[phase->first]->Fill(iEvent.orbitNumber(), phase->second);
190  }
191 
192  // selected partitions
193 
194  for (std::vector<std::string>::const_iterator part = _selectedparts.begin(); part != _selectedparts.end(); ++part) {
196  (*_hselectedphases[*part])->Fill(apvphases->getPhase(*part));
197  }
200  (*_hselectedphasevsorbit[*part])->Fill(iEvent.orbitNumber(), apvphases->getPhase(*part));
201  }
202  }
203 
204  for (std::vector<std::string>::const_iterator part = _selectedvectorparts.begin(); part != _selectedvectorparts.end();
205  ++part) {
206  const std::vector<int> phases = apvphases->getPhases(*part);
207 
210  (*_hselectedphasessize[*part])->Fill(phases.size());
211  }
212 
213  for (std::vector<int>::const_iterator phase = phases.begin(); phase != phases.end(); ++phase) {
217  }
220  (*_hselectedphasevectorvsorbit[*part])->Fill(iEvent.orbitNumber(), *phase);
221  }
222  }
223  }
224 }
225 
227  _hphases.clear();
228  _hphasevsorbit.clear();
229 
230  m_rhm.beginRun(iRun);
231 
232  for (std::map<std::string, TH1F**>::const_iterator hist = _hselectedphases.begin(); hist != _hselectedphases.end();
233  ++hist) {
234  if (*(hist->second)) {
235  (*(hist->second))->GetXaxis()->SetTitle("BX mod 70");
236  (*(hist->second))->GetYaxis()->SetTitle("Events");
237  }
238  }
239  for (std::map<std::string, TProfile**>::const_iterator prof = _hselectedphasevsorbit.begin();
240  prof != _hselectedphasevsorbit.end();
241  ++prof) {
242  if (*(prof->second)) {
243  (*(prof->second))->SetCanExtend(TH1::kXaxis);
244  (*(prof->second))->GetXaxis()->SetTitle("time [orbit#]");
245  (*(prof->second))->GetYaxis()->SetTitle("Phase");
246  }
247  }
248  for (std::map<std::string, TH1F**>::const_iterator hist = _hselectedphasesvector.begin();
249  hist != _hselectedphasesvector.end();
250  ++hist) {
251  if (*(hist->second)) {
252  (*(hist->second))->GetXaxis()->SetTitle("BX mod 70");
253  (*(hist->second))->GetYaxis()->SetTitle("Events");
254  }
255  }
256  for (std::map<std::string, TH1F**>::const_iterator hist = _hselectedphasessize.begin();
257  hist != _hselectedphasessize.end();
258  ++hist) {
259  if (*(hist->second)) {
260  (*(hist->second))->GetXaxis()->SetTitle("Number of Phases");
261  (*(hist->second))->GetYaxis()->SetTitle("Events");
262  }
263  }
264  for (std::map<std::string, TProfile**>::const_iterator prof = _hselectedphasevectorvsorbit.begin();
265  prof != _hselectedphasevectorvsorbit.end();
266  ++prof) {
267  if (*(prof->second)) {
268  (*(prof->second))->SetCanExtend(TH1::kXaxis);
269  (*(prof->second))->GetXaxis()->SetTitle("time [orbit#]");
270  (*(prof->second))->GetYaxis()->SetTitle("Phase");
271  }
272  }
273 }
274 
276 
277 // ------------ method called once each job just before starting event loop ------------
279 
280 // ------------ method called once each job just after ending the event loop ------------
281 void APVCyclePhaseMonitor::endJob() { edm::LogInfo("EndOfJob") << _nevents << " analyzed events"; }
282 
283 //define this as a plug-in
APVCyclePhaseMonitor::_selectedparts
std::vector< std::string > _selectedparts
Definition: APVCyclePhaseMonitor.cc:65
MessageLogger.h
APVCyclePhaseMonitor::_hphasevsorbit
std::map< std::string, TProfile * > _hphasevsorbit
Definition: APVCyclePhaseMonitor.cc:74
edm::Run
Definition: Run.h:45
phases
std::vector< int > phases
Definition: compareAlignments.cc:30
edm::EDGetTokenT< APVCyclePhaseCollection >
edm
HLT enums.
Definition: AlignableModifier.h:19
APVCyclePhaseMonitor::endRun
void endRun(const edm::Run &, const edm::EventSetup &) override
Definition: APVCyclePhaseMonitor.cc:275
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89285
APVCyclePhaseMonitor::endJob
void endJob() override
Definition: APVCyclePhaseMonitor.cc:281
EDAnalyzer.h
TFileDirectory
Definition: TFileDirectory.h:24
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
edm::Handle
Definition: AssociativeIterator.h:50
edm::EDAnalyzer
Definition: EDAnalyzer.h:28
APVCyclePhaseMonitor::_hselectedphasevectorvsorbit
std::map< std::string, TProfile ** > _hselectedphasevectorvsorbit
Definition: APVCyclePhaseMonitor.cc:76
BTVHLTOfflineSource_cfi.dirname
dirname
Definition: BTVHLTOfflineSource_cfi.py:7
MakerMacros.h
APVCyclePhaseMonitor::~APVCyclePhaseMonitor
~APVCyclePhaseMonitor() override
Definition: APVCyclePhaseMonitor.cc:144
part
part
Definition: HCALResponse.h:20
RunHistogramManager
Definition: RunHistogramManager.h:210
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Service.h
RunHistogramManager.h
APVCyclePhaseCollection
Definition: APVCyclePhaseCollection.h:8
Run.h
APVCyclePhaseMonitor::_hselectedphases
std::map< std::string, TH1F ** > _hselectedphases
Definition: APVCyclePhaseMonitor.cc:71
APVCyclePhaseMonitor::beginRun
void beginRun(const edm::Run &, const edm::EventSetup &) override
Definition: APVCyclePhaseMonitor.cc:226
APVCyclePhaseCollection::getPhases
const std::vector< int > getPhases(const std::string partition) const
Definition: APVCyclePhaseCollection.cc:23
APVCyclePhaseMonitor::_hphases
std::map< std::string, TH1F * > _hphases
Definition: APVCyclePhaseMonitor.cc:70
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
SiPixelPI::phase
phase
Definition: SiPixelPayloadInspectorHelper.h:39
TFileService.h
APVCyclePhaseCollection::get
const std::map< std::string, int > & get() const
Definition: APVCyclePhaseCollection.h:13
TFileService::mkdir
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
Definition: TFileService.h:69
RunHistogramManager::makeTH1F
TH1F ** makeTH1F(const char *name, const char *title, const unsigned int nbinx, const double xmin, const double xmax)
Definition: RunHistogramManager.cc:33
APVCyclePhaseMonitor
Definition: APVCyclePhaseMonitor.cc:50
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
gpuVertexFinder::hist
__shared__ Hist hist
Definition: gpuClusterTracksDBSCAN.h:48
APVCyclePhaseMonitor::_hselectedphasevsorbit
std::map< std::string, TProfile ** > _hselectedphasevsorbit
Definition: APVCyclePhaseMonitor.cc:75
RunHistogramManager::beginRun
void beginRun(const edm::Run &iRun)
Definition: RunHistogramManager.cc:101
APVCyclePhaseCollection.h
edm::Service< TFileService >
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
APVCyclePhaseMonitor::APVCyclePhaseMonitor
APVCyclePhaseMonitor(const edm::ParameterSet &)
Definition: APVCyclePhaseMonitor.cc:91
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
APVCyclePhaseMonitor::beginJob
void beginJob() override
Definition: APVCyclePhaseMonitor.cc:278
edm::EventSetup
Definition: EventSetup.h:58
APVCyclePhaseMonitor::_hselectedphasessize
std::map< std::string, TH1F ** > _hselectedphasessize
Definition: APVCyclePhaseMonitor.cc:73
HcalObjRepresent::Fill
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
Definition: HcalObjRepresent.h:1053
APVCyclePhaseMonitor::m_LSfrac
const unsigned int m_LSfrac
Definition: APVCyclePhaseMonitor.cc:68
InputTag.h
std
Definition: JetResolutionObject.h:76
APVCyclePhaseMonitor::_selectedvectorparts
std::vector< std::string > _selectedvectorparts
Definition: APVCyclePhaseMonitor.cc:66
Frameworkfwd.h
APVCyclePhaseMonitor::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: APVCyclePhaseMonitor.cc:154
APVCyclePhaseMonitor::m_maxLS
const unsigned int m_maxLS
Definition: APVCyclePhaseMonitor.cc:67
APVCyclePhaseCollection::getPhase
const int getPhase(const std::string partition) const
Definition: APVCyclePhaseCollection.cc:5
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
APVCyclePhaseMonitor::_hselectedphasesvector
std::map< std::string, TH1F ** > _hselectedphasesvector
Definition: APVCyclePhaseMonitor.cc:72
APVCyclePhaseMonitor::m_rhm
RunHistogramManager m_rhm
Definition: APVCyclePhaseMonitor.cc:69
ParameterSet.h
APVCyclePhaseMonitor::_nevents
unsigned int _nevents
Definition: APVCyclePhaseMonitor.cc:77
edm::Event
Definition: Event.h:73
APVCyclePhaseMonitor::_apvphasecollectionToken
edm::EDGetTokenT< APVCyclePhaseCollection > _apvphasecollectionToken
Definition: APVCyclePhaseMonitor.cc:64
edm::InputTag
Definition: InputTag.h:15
RunHistogramManager::makeTProfile
TProfile ** makeTProfile(const char *name, const char *title, const unsigned int nbinx, const double xmin, const double xmax)
Definition: RunHistogramManager.cc:52