CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 
20 // system include files
21 #include <memory>
22 
23 // user include files
24 #include "TH1F.h"
25 #include "TProfile.h"
26 
29 
33 
35 
37 
40 
42 
44 
46 
47 //
48 // class decleration
49 //
50 
52  public:
53  explicit APVCyclePhaseMonitor(const edm::ParameterSet&);
55 
56 
57  private:
58  virtual void beginJob() override ;
59  virtual void beginRun(const edm::Run&, const edm::EventSetup&) override;
60  virtual void endRun(const edm::Run&, const edm::EventSetup&) override;
61  virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
62  virtual void endJob() override ;
63 
64  // ----------member data ---------------------------
65 
67  std::vector<std::string> _selectedparts;
68  std::vector<std::string> _selectedvectorparts;
69  const unsigned int m_maxLS;
70  const unsigned int m_LSfrac;
72  std::map<std::string,TH1F*> _hphases;
73  std::map<std::string,TH1F**> _hselectedphases;
74  std::map<std::string,TH1F**> _hselectedphasesvector;
75  std::map<std::string,TH1F**> _hselectedphasessize;
76  std::map<std::string,TProfile*> _hphasevsorbit;
77  std::map<std::string,TProfile**> _hselectedphasevsorbit;
78  std::map<std::string,TProfile**> _hselectedphasevectorvsorbit;
79  unsigned int _nevents;
80 };
81 
82 //
83 // constants, enums and typedefs
84 //
85 
86 //
87 // static data member definitions
88 //
89 
90 //
91 // constructors and destructor
92 //
94  _apvphasecollection(iConfig.getParameter<edm::InputTag>("apvCyclePhaseCollection")),
95  _selectedparts(iConfig.getUntrackedParameter<std::vector<std::string> >("selectedPartitions",std::vector<std::string>())),
96  _selectedvectorparts(iConfig.getUntrackedParameter<std::vector<std::string> >("selectedVectorPartitions",std::vector<std::string>())),
97  m_maxLS(iConfig.getUntrackedParameter<unsigned int>("maxLSBeforeRebin",125)),
98  m_LSfrac(iConfig.getUntrackedParameter<unsigned int>("startingLSFraction",16)),
99  _hphases(),_hselectedphases(),_hselectedphasesvector(),_hselectedphasessize(),
100  _hphasevsorbit(),_hselectedphasevsorbit(),_hselectedphasevectorvsorbit(),
101  _nevents(0)
102 {
103  //now do what ever initialization is needed
104 
105  edm::LogInfo("UsedAPVCyclePhaseCollection") << " APVCyclePhaseCollection " << _apvphasecollection << " used";
106 
107  for(std::vector<std::string>::const_iterator part=_selectedparts.begin();part!=_selectedparts.end();++part) {
108 
109  char hname[300];
110 
111  sprintf(hname,"selected_phase_%s",part->c_str());
112  edm::LogInfo("SelectedTH1FBeingBooked") << "TH1F " << hname << " being booked" ;
113  _hselectedphases[*part] = m_rhm.makeTH1F(hname,hname,70,-0.5,69.5);
114 
115  sprintf(hname,"selected_phasevsorbit_%s",part->c_str());
116  edm::LogInfo("SelectedTProfileBeingBooked") << "TProfile " << hname << " being booked" ;
117  _hselectedphasevsorbit[*part] = m_rhm.makeTProfile(hname,hname,m_LSfrac*m_maxLS,0,m_maxLS*262144);
118  }
119 
120  for(std::vector<std::string>::const_iterator part=_selectedvectorparts.begin();
121  part!=_selectedvectorparts.end();++part) {
122 
123  char hname[300];
124 
125  sprintf(hname,"selected_phase_vector_%s",part->c_str());
126  edm::LogInfo("SelectedVectTH1FBeingBooked") << "TH1F " << hname << " being booked" ;
127  _hselectedphasesvector[*part] = m_rhm.makeTH1F(hname,hname,70,-0.5,69.5);
128 
129  sprintf(hname,"selected_phase_size_%s",part->c_str());
130  edm::LogInfo("SelectedVectSizeTH1FBeingBooked") << "TH1F " << hname << " being booked" ;
131  _hselectedphasessize[*part] = m_rhm.makeTH1F(hname,hname,10,-0.5,9.5);
132 
133  sprintf(hname,"selected_phasevectorvsorbit_%s",part->c_str());
134  edm::LogInfo("SelectedVectTProfileBeingBooked") << "TProfile " << hname << " being booked" ;
135  _hselectedphasevectorvsorbit[*part] = m_rhm.makeTProfile(hname,hname,m_LSfrac*m_maxLS,0,m_maxLS*262144);
136  }
137 
138 
139 }
140 
141 
143 {
144 
145  // do anything here that needs to be done at desctruction time
146  // (e.g. close files, deallocate resources etc.)
147 
148 }
149 
150 
151 //
152 // member functions
153 //
154 
155 // ------------ method called to for each event ------------
156 void
158 {
159  using namespace edm;
160 
161  _nevents++;
162 
164  iEvent.getByLabel(_apvphasecollection,apvphases);
165 
166  // improve the matchin between default and actual partitions
167 
169 
170  for(std::map<std::string,int>::const_iterator phase = apvphases->get().begin(); phase != apvphases->get().end(); ++phase) {
171 
172  if(_hphases.find(phase->first)==_hphases.end()) {
173  char dirname[300];
174  sprintf(dirname,"run_%d",iEvent.run());
175  TFileDirectory subrun = tfserv->mkdir(dirname);
176 
177  char hname[300];
178 
179  sprintf(hname,"phase_%s",phase->first.c_str());
180  edm::LogInfo("TH1FBeingBooked") << "TH1F " << hname << " being booked" ;
181  _hphases[phase->first] = subrun.make<TH1F>(hname,hname,70,-0.5,69.5);
182  _hphases[phase->first]->GetXaxis()->SetTitle("BX mod 70"); _hphases[phase->first]->GetYaxis()->SetTitle("Events");
183 
184  sprintf(hname,"phasevsorbit_%s",phase->first.c_str());
185  edm::LogInfo("TProfileBeingBooked") << "TProfile " << hname << " being booked" ;
186  _hphasevsorbit[phase->first] = subrun.make<TProfile>(hname,hname,m_LSfrac*m_maxLS,0,m_maxLS*262144);
187  _hphasevsorbit[phase->first]->SetBit(TH1::kCanRebin);
188  _hphasevsorbit[phase->first]->GetXaxis()->SetTitle("time [orbit#]"); _hphasevsorbit[phase->first]->GetYaxis()->SetTitle("Phase");
189 
190  }
191  _hphases[phase->first]->Fill(phase->second);
192  _hphasevsorbit[phase->first]->Fill(iEvent.orbitNumber(),phase->second);
193  }
194 
195  // selected partitions
196 
197  for(std::vector<std::string>::const_iterator part=_selectedparts.begin();part!=_selectedparts.end();++part) {
199  (*_hselectedphases[*part])->Fill(apvphases->getPhase(*part));
200  }
202  (*_hselectedphasevsorbit[*part])->Fill(iEvent.orbitNumber(),apvphases->getPhase(*part));
203  }
204  }
205 
206  for(std::vector<std::string>::const_iterator part=_selectedvectorparts.begin();
207  part!=_selectedvectorparts.end();++part) {
208 
209  const std::vector<int> phases = apvphases->getPhases(*part);
210 
212  (*_hselectedphasessize[*part])->Fill(phases.size());
213  }
214 
215  for(std::vector<int>::const_iterator phase=phases.begin();phase!=phases.end();++phase) {
217  (*_hselectedphasesvector[*part])->Fill(*phase);
218  }
221  (*_hselectedphasevectorvsorbit[*part])->Fill(iEvent.orbitNumber(),*phase);
222  }
223  }
224 
225  }
226 }
227 
228 void
230 {
231 
232  _hphases.clear();
233  _hphasevsorbit.clear();
234 
235  m_rhm.beginRun(iRun);
236 
237  for(std::map<std::string,TH1F**>::const_iterator hist=_hselectedphases.begin();hist!=_hselectedphases.end();++hist) {
238  if(*(hist->second)) {
239  (*(hist->second))->GetXaxis()->SetTitle("BX mod 70"); (*(hist->second))->GetYaxis()->SetTitle("Events");
240  }
241  }
242  for(std::map<std::string,TProfile**>::const_iterator prof=_hselectedphasevsorbit.begin();prof!=_hselectedphasevsorbit.end();++prof) {
243  if(*(prof->second)) {
244  (*(prof->second))->SetBit(TH1::kCanRebin);
245  (*(prof->second))->GetXaxis()->SetTitle("time [orbit#]");
246  (*(prof->second))->GetYaxis()->SetTitle("Phase");
247  }
248  }
249  for(std::map<std::string,TH1F**>::const_iterator hist=_hselectedphasesvector.begin();hist!=_hselectedphasesvector.end();++hist) {
250  if(*(hist->second)) {
251  (*(hist->second))->GetXaxis()->SetTitle("BX mod 70"); (*(hist->second))->GetYaxis()->SetTitle("Events");
252  }
253  }
254  for(std::map<std::string,TH1F**>::const_iterator hist=_hselectedphasessize.begin();hist!=_hselectedphasessize.end();++hist) {
255  if(*(hist->second)) {
256  (*(hist->second))->GetXaxis()->SetTitle("Number of Phases"); (*(hist->second))->GetYaxis()->SetTitle("Events");
257  }
258  }
259  for(std::map<std::string,TProfile**>::const_iterator prof=_hselectedphasevectorvsorbit.begin();prof!=_hselectedphasevectorvsorbit.end();++prof) {
260  if(*(prof->second)) {
261  (*(prof->second))->SetBit(TH1::kCanRebin);
262  (*(prof->second))->GetXaxis()->SetTitle("time [orbit#]");
263  (*(prof->second))->GetYaxis()->SetTitle("Phase");
264  }
265  }
266 
267 }
268 
269 void
271 {
272 }
273 
274 
275 // ------------ method called once each job just before starting event loop ------------
276 void
278 {
279 
280 }
281 
282 // ------------ method called once each job just after ending the event loop ------------
283 void
285 
286  edm::LogInfo("EndOfJob") << _nevents << " analyzed events";
287 
288 }
289 
290 
291 //define this as a plug-in
std::map< std::string, TH1F ** > _hselectedphasesvector
std::vector< std::string > _selectedparts
std::map< std::string, TProfile ** > _hselectedphasevectorvsorbit
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::map< std::string, TProfile ** > _hselectedphasevsorbit
virtual void endJob() override
std::map< std::string, TH1F * > _hphases
virtual void endRun(const edm::Run &, const edm::EventSetup &) override
TH1F ** makeTH1F(const char *name, const char *title, const unsigned int nbinx, const double xmin, const double xmax)
int iEvent
Definition: GenABIO.cc:243
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
virtual void beginRun(const edm::Run &, const edm::EventSetup &) override
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:88
APVCyclePhaseMonitor(const edm::ParameterSet &)
std::map< std::string, TH1F ** > _hselectedphasessize
int orbitNumber() const
Definition: EventBase.h:63
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
const unsigned int m_maxLS
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
std::vector< std::string > _selectedvectorparts
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)
std::map< std::string, TH1F ** > _hselectedphases
const edm::InputTag _apvphasecollection
virtual void beginJob() override
std::map< std::string, TProfile * > _hphasevsorbit
RunHistogramManager m_rhm
const unsigned int m_LSfrac
Definition: Run.h:41