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