CMS 3D CMS Logo

EventTimeDistribution.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SiStripTools
4 // Class: EventTimeDistribution
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 <string>
25 #include <vector>
26 
27 #include "TH1F.h"
28 #include "TH2F.h"
29 
32 
36 
38 
40 
43 
45 
48 
50 //
51 // class decleration
52 //
53 
55  public:
57  ~EventTimeDistribution() override;
58 
59 
60  private:
61  void beginJob() override ;
62  void beginRun(const edm::Run&, const edm::EventSetup&) override;
63  void endRun(const edm::Run&, const edm::EventSetup&) override;
64  void analyze(const edm::Event&, const edm::EventSetup&) override;
65  void endJob() override ;
66 
67  // ----------member data ---------------------------
68 
72  const bool _wantdbxvsbxincycle;
73  const bool _wantdbxvsbx;
74  const bool _wantbxincyclevsbx;
76  unsigned int _nevents;
77  const unsigned int m_maxLS;
78  const unsigned int m_LSfrac;
79  const bool m_ewhdepthHisto;
80 
81 
82 
84 
85  TH1F** _dbx;
86  std::vector<TH1F**> m_dbxhistos;
87  std::vector<std::pair<unsigned int,unsigned int> > m_dbxindices;
88  TH1F** _bx;
89  TH1F** _bxincycle;
90  TH1F** _orbit;
92  TH2F** _dbxvsbx;
95  TH1F** m_ewhdepth;
96 
97 };
98 
99 //
100 // constants, enums and typedefs
101 //
102 
103 //
104 // static data member definitions
105 //
106 
107 //
108 // constructors and destructor
109 //
111  _historyProductToken(consumes<EventWithHistory>(iConfig.getParameter<edm::InputTag>("historyProduct"))),
112  _apvphasecollToken(consumes<APVCyclePhaseCollection>(iConfig.getParameter<edm::InputTag>("apvPhaseCollection"))),
113  _phasepart(iConfig.getUntrackedParameter<std::string>("phasePartition","None")),
114  _wantdbxvsbxincycle(iConfig.getUntrackedParameter<bool>("wantDBXvsBXincycle",false)),
115  _wantdbxvsbx(iConfig.getUntrackedParameter<bool>("wantDBXvsBX",false)),
116  _wantbxincyclevsbx(iConfig.getUntrackedParameter<bool>("wantBXincyclevsBX",false)),
117  _wantorbitvsbxincycle(iConfig.getUntrackedParameter<bool>("wantOrbitvsBXincycle",false)),
118  _nevents(0),
119  m_maxLS(iConfig.getUntrackedParameter<unsigned int>("maxLSBeforeRebin",100)),
120  m_LSfrac(iConfig.getUntrackedParameter<unsigned int>("startingLSFraction",4)),
121  m_ewhdepthHisto(iConfig.getUntrackedParameter<bool>("wantEWHDepthHisto",false)),
124 {
125  //now do what ever initialization is needed
126 
127  std::vector<edm::ParameterSet> dbxhistoparams(iConfig.getUntrackedParameter<std::vector<edm::ParameterSet> >("dbxHistosParams",std::vector<edm::ParameterSet>()));
128 
129  for(std::vector<edm::ParameterSet>::const_iterator params=dbxhistoparams.begin();params!=dbxhistoparams.end();++params) {
130  m_dbxindices.push_back(std::pair<unsigned int,unsigned int>(params->getParameter<unsigned int>("firstEvent"),params->getParameter<unsigned int>("secondEvent")));
131  char hname[300];
132  sprintf(hname,"dbx_%d_%d",params->getParameter<unsigned int>("firstEvent"),params->getParameter<unsigned int>("secondEvent"));
133  char htitle[300];
134  sprintf(htitle,"dbx(%d,%d)",params->getParameter<unsigned int>("firstEvent"),params->getParameter<unsigned int>("secondEvent"));
135 
136  m_dbxhistos.push_back(_rhm.makeTH1F(hname,htitle,params->getParameter<int>("nbins"),params->getParameter<double>("min"),
137  params->getParameter<double>("max")));
138  LogDebug("DBXHistoPreBooking") << "Booked DBX histo named " << hname << " untitled " << htitle;
139  }
140 
141 
142 
143  _dbx = _rhm.makeTH1F("dbx","dbx",1000,-0.5,999.5);
144  _bx = _rhm.makeTH1F("bx","BX number",3564,-0.5,3563.5);
145  _bxincycle = _rhm.makeTH1F("bxcycle","bxcycle",70,-0.5,69.5);
146  _orbit = _rhm.makeTH1F("orbit","orbit",m_LSfrac*m_maxLS,0,m_maxLS*262144);
147  if(_wantdbxvsbxincycle) _dbxvsbxincycle = _rhm.makeTH2F("dbxvsbxincycle","dbxvsbxincycle",70,-0.5,69.5,1000,-0.5,999.5);
148  if(_wantdbxvsbx) _dbxvsbx = _rhm.makeTH2F("dbxvsbx","dbxvsbx",3564,-0.5,3563.5,1000,-0.5,999.5);
149  if(_wantbxincyclevsbx) _bxincyclevsbx = _rhm.makeTH2F("bxincyclevsbx","bxincyclevsbx",3564,-0.5,3563.5,70,-0.5,69.5);
150  if(_wantorbitvsbxincycle) _orbitvsbxincycle = _rhm.makeTH2F("orbitvsbxincycle","orbitvsbxincycle",70,-0.5,69.5,m_maxLS,0,m_maxLS*262144);
151  if(m_ewhdepthHisto) m_ewhdepth = _rhm.makeTH1F("ewhdepth","EventWithHistory Depth",11,-0.5,10.5);
152 
153  edm::LogInfo("UsedAPVCyclePhaseCollection") << " APVCyclePhaseCollection " << iConfig.getParameter<edm::InputTag>("apvPhaseCollection") << " used";
154 
155 }
156 
157 
159 {
160 
161  // do anything here that needs to be done at desctruction time
162  // (e.g. close files, deallocate resources etc.)
163 
164 }
165 
166 
167 //
168 // member functions
169 //
170 
171 // ------------ method called to for each event ------------
172 void
174 {
175  using namespace edm;
176 
177  _nevents++;
178 
180  iEvent.getByToken(_historyProductToken,he);
181 
182  // improve the matchin between default and actual partitions
183 
184  (*_dbx)->Fill(he->deltaBX());
185  std::vector<std::pair<unsigned int,unsigned int> >::const_iterator indices=m_dbxindices.begin();
186  for(std::vector<TH1F**>::const_iterator dbxhist=m_dbxhistos.begin();dbxhist!=m_dbxhistos.end();++dbxhist,++indices) {
187  (*(*dbxhist))->Fill(he->deltaBX(indices->first,indices->second));
188  }
189 
190  (*_bx)->Fill(iEvent.bunchCrossing()%3564);
191  (*_orbit)->Fill(iEvent.orbitNumber());
192  if(_dbxvsbx && *_dbxvsbx) (*_dbxvsbx)->Fill(iEvent.bunchCrossing()%3564,he->deltaBX());
193  if(m_ewhdepth && *m_ewhdepth) (*m_ewhdepth)->Fill(he->depth());
194 
196  iEvent.getByToken(_apvphasecollToken,apvphase);
197 
198  long long tbx = he->absoluteBX();
199  if(apvphase.isValid() && !apvphase.failedToGet()) {
200  const int thephase = apvphase->getPhase(_phasepart);
201  if(thephase!=APVCyclePhaseCollection::invalid &&
204 
205  tbx -= thephase;
206  (*_bxincycle)->Fill(tbx%70);
207  if(_dbxvsbxincycle && *_dbxvsbxincycle) (*_dbxvsbxincycle)->Fill(tbx%70,he->deltaBX());
208  if(_bxincyclevsbx && *_bxincyclevsbx) (*_bxincyclevsbx)->Fill(iEvent.bunchCrossing()%3564,tbx%70);
209  if(_orbitvsbxincycle && *_orbitvsbxincycle) (*_orbitvsbxincycle)->Fill(tbx%70,iEvent.orbitNumber());
210 
211  }
212  else {
213  LogDebug("InvalidPhase") << "Invalid APVCyclePhase value : " << _phasepart << " " << thephase;
214  }
215  }
216 }
217 
218 void
220 {
221 
222  _rhm.beginRun(iRun);
223 
224  if(*_dbx) { (*_dbx)->GetXaxis()->SetTitle("#DeltaBX"); }
225 
226  LogDebug("NomberOfHistos") << m_dbxhistos.size();
227  for(std::vector<TH1F**>::const_iterator dbxhist=m_dbxhistos.begin();dbxhist!=m_dbxhistos.end();++dbxhist) {
228  LogDebug("HistoPointer") << *dbxhist;
229  if(*(*dbxhist)) { (*(*dbxhist))->GetXaxis()->SetTitle("#DeltaBX"); }
230  }
231  LogDebug("LabelDone") << "all labels set";
232 
233  if(*_bx) { (*_bx)->GetXaxis()->SetTitle("BX"); }
234 
235  if(*_bxincycle) { (*_bxincycle)->GetXaxis()->SetTitle("Event BX mod(70)"); }
236 
237  if(*_orbit) {
238  (*_orbit)->SetCanExtend(TH1::kXaxis);
239  (*_orbit)->GetXaxis()->SetTitle("time [Orb#]");
240  }
241 
242  LogDebug("StdPlotsDone") << "all labels in std plots set";
243 
245  (*_dbxvsbxincycle)->GetXaxis()->SetTitle("Event BX mod(70)"); (*_dbxvsbxincycle)->GetYaxis()->SetTitle("#DeltaBX");
246  }
247 
248  if(_dbxvsbx && *_dbxvsbx) { (*_dbxvsbx)->GetXaxis()->SetTitle("BX"); (*_dbxvsbx)->GetYaxis()->SetTitle("#DeltaBX"); }
249 
251  (*_bxincyclevsbx)->GetXaxis()->SetTitle("BX"); (*_bxincyclevsbx)->GetYaxis()->SetTitle("Event BX mod(70)");
252  }
253 
255  (*_orbitvsbxincycle)->SetCanExtend(TH1::kYaxis);
256  (*_orbitvsbxincycle)->GetXaxis()->SetTitle("Event BX mod(70)"); (*_orbitvsbxincycle)->GetYaxis()->SetTitle("time [Orb#]");
257  }
258 
259  if(m_ewhdepth && *m_ewhdepth) {
260  (*m_ewhdepth)->GetXaxis()->SetTitle("Depth");
261  }
262 
263 }
264 
265 void
267 {
268 }
269 
270 
271 // ------------ method called once each job just before starting event loop ------------
272 void
274 {
275 
276 }
277 
278 // ------------ method called once each job just after ending the event loop ------------
279 void
281 
282  edm::LogInfo("EndOfJob") << _nevents << " analyzed events";
283 
284 }
285 
286 
287 //define this as a plug-in
#define LogDebug(id)
unsigned int depth() const
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
long long deltaBX(const unsigned int ev2, const unsigned int ev1) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
void beginRun(const edm::Run &, const edm::EventSetup &) override
#define nullptr
int bunchCrossing() const
Definition: EventBase.h:64
long long absoluteBX(const unsigned int ev1) const
edm::EDGetTokenT< APVCyclePhaseCollection > _apvphasecollToken
std::vector< std::pair< unsigned int, unsigned int > > m_dbxindices
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
edm::EDGetTokenT< EventWithHistory > _historyProductToken
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:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const int getPhase(const std::string partition) const
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
const unsigned int m_LSfrac
int orbitNumber() const
Definition: EventBase.h:65
bool isValid() const
Definition: HandleBase.h:74
RunHistogramManager _rhm
const std::string _phasepart
EventTimeDistribution(const edm::ParameterSet &)
bool failedToGet() const
Definition: HandleBase.h:78
void beginRun(const edm::Run &iRun)
const unsigned int m_maxLS
HLT enums.
void analyze(const edm::Event &, const edm::EventSetup &) override
TH2F ** makeTH2F(const char *name, const char *title, const unsigned int nbinx, const double xmin, const double xmax, const unsigned int nbiny, const double ymin, const double ymax)
std::vector< TH1F ** > m_dbxhistos
Definition: Run.h:45