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 
45 //
46 // class decleration
47 //
48 
50  public:
51  explicit APVCyclePhaseMonitor(const edm::ParameterSet&);
53 
54 
55  private:
56  virtual void beginJob() ;
57  virtual void beginRun(const edm::Run&, const edm::EventSetup&) ;
58  virtual void endRun(const edm::Run&, const edm::EventSetup&) ;
59  virtual void analyze(const edm::Event&, const edm::EventSetup&);
60  virtual void endJob() ;
61 
62  // ----------member data ---------------------------
63 
65  std::vector<std::string> _selectedparts;
66  std::vector<std::string> _selectedvectorparts;
67  std::map<std::string,TH1F*> _hphases;
68  std::map<std::string,TH1F*> _hselectedphases;
69  std::map<std::string,TH1F*> _hselectedphasesvector;
70  std::map<std::string,TH1F*> _hselectedphasessize;
71  std::map<std::string,TProfile*> _hphasevsorbit;
72  std::map<std::string,TProfile*> _hselectedphasevsorbit;
73  std::map<std::string,TProfile*> _hselectedphasevectorvsorbit;
74  unsigned int _nevents;
75 };
76 
77 //
78 // constants, enums and typedefs
79 //
80 
81 //
82 // static data member definitions
83 //
84 
85 //
86 // constructors and destructor
87 //
89  _apvphasecollection(iConfig.getParameter<edm::InputTag>("apvCyclePhaseCollection")),
90  _selectedparts(iConfig.getUntrackedParameter<std::vector<std::string> >("selectedPartitions",std::vector<std::string>())),
91  _selectedvectorparts(iConfig.getUntrackedParameter<std::vector<std::string> >("selectedVectorPartitions",std::vector<std::string>())),
92  _hphases(),_hselectedphases(),_hselectedphasesvector(),_hselectedphasessize(),
93  _hphasevsorbit(),_hselectedphasevsorbit(),_hselectedphasevectorvsorbit(),
94  _nevents(0)
95 {
96  //now do what ever initialization is needed
97 
98  edm::LogInfo("UsedAPVCyclePhaseCollection") << " APVCyclePhaseCollection " << _apvphasecollection << " used";
99 
100 }
101 
102 
104 {
105 
106  // do anything here that needs to be done at desctruction time
107  // (e.g. close files, deallocate resources etc.)
108 
109 }
110 
111 
112 //
113 // member functions
114 //
115 
116 // ------------ method called to for each event ------------
117 void
119 {
120  using namespace edm;
121 
122  _nevents++;
123 
125  iEvent.getByLabel(_apvphasecollection,apvphases);
126 
127  // improve the matchin between default and actual partitions
128 
130 
131  for(std::map<std::string,int>::const_iterator phase = apvphases->get().begin(); phase != apvphases->get().end(); ++phase) {
132 
133  if(_hphases.find(phase->first)==_hphases.end()) {
134  char dirname[300];
135  sprintf(dirname,"run_%d",iEvent.run());
136  TFileDirectory subrun = tfserv->mkdir(dirname);
137 
138  char hname[300];
139 
140  sprintf(hname,"phase_%s",phase->first.c_str());
141  edm::LogInfo("TH1FBeingBooked") << "TH1F " << hname << " being booked" ;
142  _hphases[phase->first] = subrun.make<TH1F>(hname,hname,70,-0.5,69.5);
143  _hphases[phase->first]->GetXaxis()->SetTitle("BX mod 70"); _hphases[phase->first]->GetYaxis()->SetTitle("Events");
144 
145  sprintf(hname,"phasevsorbit_%s",phase->first.c_str());
146  edm::LogInfo("TProfileBeingBooked") << "TProfile " << hname << " being booked" ;
147  _hphasevsorbit[phase->first] = subrun.make<TProfile>(hname,hname,1800,0.,1800*11223);
148  _hphasevsorbit[phase->first]->SetBit(TH1::kCanRebin);
149  _hphasevsorbit[phase->first]->GetXaxis()->SetTitle("time [orbit#]"); _hphasevsorbit[phase->first]->GetYaxis()->SetTitle("Phase");
150 
151  }
152  _hphases[phase->first]->Fill(phase->second);
153  _hphasevsorbit[phase->first]->Fill(iEvent.orbitNumber(),phase->second);
154  }
155 
156  // selected partitions
157 
158  for(std::vector<std::string>::const_iterator part=_selectedparts.begin();part!=_selectedparts.end();++part) {
159  if(_hselectedphases.find(*part)!=_hselectedphases.end()) {
160  _hselectedphases[*part]->Fill(apvphases->getPhase(*part));
161  }
163  _hselectedphasevsorbit[*part]->Fill(iEvent.orbitNumber(),apvphases->getPhase(*part));
164  }
165  }
166 
167  for(std::vector<std::string>::const_iterator part=_selectedvectorparts.begin();
168  part!=_selectedvectorparts.end();++part) {
169 
170  const std::vector<int> phases = apvphases->getPhases(*part);
171 
173  _hselectedphasessize[*part]->Fill(phases.size());
174  }
175 
176  for(std::vector<int>::const_iterator phase=phases.begin();phase!=phases.end();++phase) {
178  _hselectedphasesvector[*part]->Fill(*phase);
179  }
181  _hselectedphasevectorvsorbit[*part]->Fill(iEvent.orbitNumber(),*phase);
182  }
183  }
184 
185  }
186 }
187 
188 void
190 {
191 
192  _hphases.clear();
193  _hselectedphases.clear();
194  _hselectedphasesvector.clear();
195  _hselectedphasessize.clear();
196  _hphasevsorbit.clear();
197  _hselectedphasevsorbit.clear();
199 
201 
202  char dirname[300];
203  sprintf(dirname,"run_%d",iRun.run());
204  TFileDirectory subrun = tfserv->mkdir(dirname);
205 
206  for(std::vector<std::string>::const_iterator part=_selectedparts.begin();part!=_selectedparts.end();++part) {
207 
208  char hname[300];
209 
210  sprintf(hname,"selected_phase_%s",part->c_str());
211  edm::LogInfo("SelectedTH1FBeingBooked") << "TH1F " << hname << " being booked" ;
212  _hselectedphases[*part] = subrun.make<TH1F>(hname,hname,70,-0.5,69.5);
213  _hselectedphases[*part]->GetXaxis()->SetTitle("BX mod 70"); _hselectedphases[*part]->GetYaxis()->SetTitle("Events");
214 
215  sprintf(hname,"selected_phasevsorbit_%s",part->c_str());
216  edm::LogInfo("SelectedTProfileBeingBooked") << "TProfile " << hname << " being booked" ;
217  _hselectedphasevsorbit[*part] = subrun.make<TProfile>(hname,hname,1800,0.,1800*11223);
218  _hselectedphasevsorbit[*part]->SetBit(TH1::kCanRebin);
219  _hselectedphasevsorbit[*part]->GetXaxis()->SetTitle("time [orbit#]");
220  _hselectedphasevsorbit[*part]->GetYaxis()->SetTitle("Phase");
221  }
222 
223  for(std::vector<std::string>::const_iterator part=_selectedvectorparts.begin();
224  part!=_selectedvectorparts.end();++part) {
225 
226  char hname[300];
227 
228  sprintf(hname,"selected_phase_vector_%s",part->c_str());
229  edm::LogInfo("SelectedVectTH1FBeingBooked") << "TH1F " << hname << " being booked" ;
230  _hselectedphasesvector[*part] = subrun.make<TH1F>(hname,hname,70,-0.5,69.5);
231  _hselectedphasesvector[*part]->GetXaxis()->SetTitle("BX mod 70");
232  _hselectedphasesvector[*part]->GetYaxis()->SetTitle("Events");
233 
234  sprintf(hname,"selected_phase_size_%s",part->c_str());
235  edm::LogInfo("SelectedVectSizeTH1FBeingBooked") << "TH1F " << hname << " being booked" ;
236  _hselectedphasessize[*part] = subrun.make<TH1F>(hname,hname,10,-0.5,9.5);
237  _hselectedphasessize[*part]->GetXaxis()->SetTitle("Number of Phases");
238  _hselectedphasessize[*part]->GetYaxis()->SetTitle("Events");
239 
240  sprintf(hname,"selected_phasevectorvsorbit_%s",part->c_str());
241  edm::LogInfo("SelectedVectTProfileBeingBooked") << "TProfile " << hname << " being booked" ;
242  _hselectedphasevectorvsorbit[*part] = subrun.make<TProfile>(hname,hname,1800,0.,1800*11223);
243  _hselectedphasevectorvsorbit[*part]->SetBit(TH1::kCanRebin);
244  _hselectedphasevectorvsorbit[*part]->GetXaxis()->SetTitle("time [orbit#]");
245  _hselectedphasevectorvsorbit[*part]->GetYaxis()->SetTitle("Phase");
246  }
247 }
248 
249 void
251 {
252 }
253 
254 
255 // ------------ method called once each job just before starting event loop ------------
256 void
258 {
259 
260 }
261 
262 // ------------ method called once each job just after ending the event loop ------------
263 void
265 
266  edm::LogInfo("EndOfJob") << _nevents << " analyzed events";
267 
268 }
269 
270 
271 //define this as a plug-in
std::vector< std::string > _selectedparts
virtual void endRun(const edm::Run &, const edm::EventSetup &)
RunNumber_t run() const
Definition: RunBase.h:44
std::map< std::string, TH1F * > _hselectedphasessize
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::map< std::string, TH1F * > _hselectedphasesvector
std::map< std::string, TH1F * > _hphases
int iEvent
Definition: GenABIO.cc:243
RunNumber_t run() const
Definition: Event.h:66
APVCyclePhaseMonitor(const edm::ParameterSet &)
virtual void beginRun(const edm::Run &, const edm::EventSetup &)
int orbitNumber() const
Definition: EventBase.h:63
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:359
std::vector< std::string > _selectedvectorparts
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
part
Definition: HCALResponse.h:21
std::map< std::string, TProfile * > _hselectedphasevsorbit
const edm::InputTag _apvphasecollection
std::map< std::string, TProfile * > _hphasevsorbit
std::map< std::string, TProfile * > _hselectedphasevectorvsorbit
Definition: Run.h:31
virtual void analyze(const edm::Event &, const edm::EventSetup &)
std::map< std::string, TH1F * > _hselectedphases