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 
50 class APVCyclePhaseMonitor : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::SharedResources> {
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  usesResource(TFileService::kSharedResource);
112 
113  edm::LogInfo("UsedAPVCyclePhaseCollection")
114  << " APVCyclePhaseCollection " << iConfig.getParameter<edm::InputTag>("apvCyclePhaseCollection") << " used";
115 
116  for (std::vector<std::string>::const_iterator part = _selectedparts.begin(); part != _selectedparts.end(); ++part) {
117  char hname[300];
118 
119  sprintf(hname, "selected_phase_%s", part->c_str());
120  edm::LogInfo("SelectedTH1FBeingBooked") << "TH1F " << hname << " being booked";
121  _hselectedphases[*part] = m_rhm.makeTH1F(hname, hname, 70, -0.5, 69.5);
122 
123  sprintf(hname, "selected_phasevsorbit_%s", part->c_str());
124  edm::LogInfo("SelectedTProfileBeingBooked") << "TProfile " << hname << " being booked";
125  _hselectedphasevsorbit[*part] = m_rhm.makeTProfile(hname, hname, m_LSfrac * m_maxLS, 0, m_maxLS * 262144);
126  }
127 
128  for (std::vector<std::string>::const_iterator part = _selectedvectorparts.begin(); part != _selectedvectorparts.end();
129  ++part) {
130  char hname[300];
131 
132  sprintf(hname, "selected_phase_vector_%s", part->c_str());
133  edm::LogInfo("SelectedVectTH1FBeingBooked") << "TH1F " << hname << " being booked";
134  _hselectedphasesvector[*part] = m_rhm.makeTH1F(hname, hname, 70, -0.5, 69.5);
135 
136  sprintf(hname, "selected_phase_size_%s", part->c_str());
137  edm::LogInfo("SelectedVectSizeTH1FBeingBooked") << "TH1F " << hname << " being booked";
138  _hselectedphasessize[*part] = m_rhm.makeTH1F(hname, hname, 10, -0.5, 9.5);
139 
140  sprintf(hname, "selected_phasevectorvsorbit_%s", part->c_str());
141  edm::LogInfo("SelectedVectTProfileBeingBooked") << "TProfile " << hname << " being booked";
142  _hselectedphasevectorvsorbit[*part] = m_rhm.makeTProfile(hname, hname, m_LSfrac * m_maxLS, 0, m_maxLS * 262144);
143  }
144 }
145 
147  // do anything here that needs to be done at desctruction time
148  // (e.g. close files, deallocate resources etc.)
149 }
150 
151 //
152 // member functions
153 //
154 
155 // ------------ method called to for each event ------------
157  using namespace edm;
158 
159  _nevents++;
160 
162  iEvent.getByToken(_apvphasecollectionToken, apvphases);
163 
164  // improve the matchin between default and actual partitions
165 
167 
168  for (std::map<std::string, int>::const_iterator phase = apvphases->get().begin(); phase != apvphases->get().end();
169  ++phase) {
170  if (_hphases.find(phase->first) == _hphases.end()) {
171  char dirname[300];
172  sprintf(dirname, "run_%d", iEvent.run());
173  TFileDirectory subrun = tfserv->mkdir(dirname);
174 
175  char hname[300];
176 
177  sprintf(hname, "phase_%s", phase->first.c_str());
178  edm::LogInfo("TH1FBeingBooked") << "TH1F " << hname << " being booked";
179  _hphases[phase->first] = subrun.make<TH1F>(hname, hname, 70, -0.5, 69.5);
180  _hphases[phase->first]->GetXaxis()->SetTitle("BX mod 70");
181  _hphases[phase->first]->GetYaxis()->SetTitle("Events");
182 
183  sprintf(hname, "phasevsorbit_%s", phase->first.c_str());
184  edm::LogInfo("TProfileBeingBooked") << "TProfile " << hname << " being booked";
185  _hphasevsorbit[phase->first] = subrun.make<TProfile>(hname, hname, m_LSfrac * m_maxLS, 0, m_maxLS * 262144);
186  _hphasevsorbit[phase->first]->SetCanExtend(TH1::kXaxis);
187  _hphasevsorbit[phase->first]->GetXaxis()->SetTitle("time [orbit#]");
188  _hphasevsorbit[phase->first]->GetYaxis()->SetTitle("Phase");
189  }
190  _hphases[phase->first]->Fill(phase->second);
191  _hphasevsorbit[phase->first]->Fill(iEvent.orbitNumber(), phase->second);
192  }
193 
194  // selected partitions
195 
196  for (std::vector<std::string>::const_iterator part = _selectedparts.begin(); part != _selectedparts.end(); ++part) {
198  (*_hselectedphases[*part])->Fill(apvphases->getPhase(*part));
199  }
202  (*_hselectedphasevsorbit[*part])->Fill(iEvent.orbitNumber(), apvphases->getPhase(*part));
203  }
204  }
205 
206  for (std::vector<std::string>::const_iterator part = _selectedvectorparts.begin(); part != _selectedvectorparts.end();
207  ++part) {
208  const std::vector<int> phases = apvphases->getPhases(*part);
209 
212  (*_hselectedphasessize[*part])->Fill(phases.size());
213  }
214 
215  for (std::vector<int>::const_iterator phase = phases.begin(); phase != phases.end(); ++phase) {
219  }
222  (*_hselectedphasevectorvsorbit[*part])->Fill(iEvent.orbitNumber(), *phase);
223  }
224  }
225  }
226 }
227 
229  _hphases.clear();
230  _hphasevsorbit.clear();
231 
232  m_rhm.beginRun(iRun);
233 
234  for (std::map<std::string, TH1F**>::const_iterator hist = _hselectedphases.begin(); hist != _hselectedphases.end();
235  ++hist) {
236  if (*(hist->second)) {
237  (*(hist->second))->GetXaxis()->SetTitle("BX mod 70");
238  (*(hist->second))->GetYaxis()->SetTitle("Events");
239  }
240  }
241  for (std::map<std::string, TProfile**>::const_iterator prof = _hselectedphasevsorbit.begin();
242  prof != _hselectedphasevsorbit.end();
243  ++prof) {
244  if (*(prof->second)) {
245  (*(prof->second))->SetCanExtend(TH1::kXaxis);
246  (*(prof->second))->GetXaxis()->SetTitle("time [orbit#]");
247  (*(prof->second))->GetYaxis()->SetTitle("Phase");
248  }
249  }
250  for (std::map<std::string, TH1F**>::const_iterator hist = _hselectedphasesvector.begin();
251  hist != _hselectedphasesvector.end();
252  ++hist) {
253  if (*(hist->second)) {
254  (*(hist->second))->GetXaxis()->SetTitle("BX mod 70");
255  (*(hist->second))->GetYaxis()->SetTitle("Events");
256  }
257  }
258  for (std::map<std::string, TH1F**>::const_iterator hist = _hselectedphasessize.begin();
259  hist != _hselectedphasessize.end();
260  ++hist) {
261  if (*(hist->second)) {
262  (*(hist->second))->GetXaxis()->SetTitle("Number of Phases");
263  (*(hist->second))->GetYaxis()->SetTitle("Events");
264  }
265  }
266  for (std::map<std::string, TProfile**>::const_iterator prof = _hselectedphasevectorvsorbit.begin();
267  prof != _hselectedphasevectorvsorbit.end();
268  ++prof) {
269  if (*(prof->second)) {
270  (*(prof->second))->SetCanExtend(TH1::kXaxis);
271  (*(prof->second))->GetXaxis()->SetTitle("time [orbit#]");
272  (*(prof->second))->GetYaxis()->SetTitle("Phase");
273  }
274  }
275 }
276 
278 
279 // ------------ method called once each job just before starting event loop ------------
281 
282 // ------------ method called once each job just after ending the event loop ------------
283 void APVCyclePhaseMonitor::endJob() { edm::LogInfo("EndOfJob") << _nevents << " analyzed events"; }
284 
285 //define this as a plug-in
std::map< std::string, TH1F ** > _hselectedphasesvector
static const std::string kSharedResource
Definition: TFileService.h:76
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::vector< std::string > _selectedparts
edm::EDGetTokenT< APVCyclePhaseCollection > _apvphasecollectionToken
void endRun(const edm::Run &, const edm::EventSetup &) override
std::map< std::string, TProfile ** > _hselectedphasevsorbit
const std::map< std::string, int > & get() const
std::map< std::string, TH1F * > _hphases
TH1F ** makeTH1F(const char *name, const char *title, const unsigned int nbinx, const double xmin, const double xmax)
int iEvent
Definition: GenABIO.cc:224
std::map< std::string, TProfile ** > _hselectedphasevectorvsorbit
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
void beginRun(const edm::Run &, const edm::EventSetup &) override
std::map< std::string, TH1F ** > _hselectedphases
TProfile ** makeTProfile(const char *name, const char *title, const unsigned int nbinx, const double xmin, const double xmax)
APVCyclePhaseMonitor(const edm::ParameterSet &)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const std::vector< int > getPhases(const std::string partition) const
std::map< std::string, TH1F ** > _hselectedphasessize
void analyze(const edm::Event &, const edm::EventSetup &) override
const unsigned int m_maxLS
std::vector< std::string > _selectedvectorparts
Log< level::Info, false > LogInfo
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
Definition: TFileService.h:69
part
Definition: HCALResponse.h:20
void beginRun(const edm::Run &iRun)
const int getPhase(const std::string partition) const
HLT enums.
std::map< std::string, TProfile * > _hphasevsorbit
RunHistogramManager m_rhm
const unsigned int m_LSfrac
Definition: Run.h:45