CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  }
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
std::map< std::string, TH1F ** > _hselectedphasesvector
std::vector< std::string > _selectedparts
edm::EDGetTokenT< APVCyclePhaseCollection > _apvphasecollectionToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void endRun(const edm::Run &, const edm::EventSetup &) override
std::map< std::string, TProfile ** > _hselectedphasevsorbit
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)
m_rhm(consumesCollector())
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)
RunNumber_t run() const
Definition: Event.h:109
APVCyclePhaseMonitor(const edm::ParameterSet &)
std::map< std::string, TH1F ** > _hselectedphasessize
int orbitNumber() const
Definition: EventBase.h:65
void analyze(const edm::Event &, const edm::EventSetup &) override
const unsigned int m_maxLS
std::vector< std::string > _selectedvectorparts
__shared__ Hist hist
Log< level::Info, false > LogInfo
std::vector< int > phases
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
part
Definition: HCALResponse.h:20
void beginRun(const edm::Run &iRun)
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
_nevents(0)
std::map< std::string, TProfile * > _hphasevsorbit
RunHistogramManager m_rhm
const unsigned int m_LSfrac
Definition: Run.h:45