CMS 3D CMS Logo

MixCollectionValidation.cc
Go to the documentation of this file.
1 // system include files
3 
4 // user include files
7 
10 
12 
13 #include "TFile.h"
16 
17 #include <memory>
18 #include <utility>
19 
20 using namespace edm;
21 
23  minbunch_(iConfig.getParameter<int>("minBunch")),
24  maxbunch_(iConfig.getParameter<int>("maxBunch")),
25  verbose_(iConfig.getUntrackedParameter<bool>("verbose",false)),
26  nbin_(maxbunch_-minbunch_+1)
27 {
28  // Histograms will be defined according to the configuration
29  ParameterSet mixObjextsSet_ = iConfig.getParameter<ParameterSet>("mixObjects");
30 }
31 
33 {
34  // do anything here that needs to be done at desctruction time
35  // (e.g. close files, deallocate resources etc.)
36 }
37 
38 void MixCollectionValidation::bookHistograms(DQMStore::IBooker & iBooker, edm::Run const & iRun, edm::EventSetup const & /* iSetup */)
39 {
40  iBooker.setCurrentFolder("MixingV/Mixing");
41 
42  std::vector<std::string> names = mixObjextsSet_.getParameterNames();
43 
44  for (std::vector<std::string>::iterator it = names.begin();it!= names.end();++it)
45  {
47  if (!pset.exists("type")) continue; //to allow replacement by empty pset
48  std::string object = pset.getParameter<std::string>("type");
49  std::vector<InputTag> tags = pset.getParameter<std::vector<InputTag> >("input");
50 
51  if ( object == "HepMCProduct" ) {
52 
53  std::string title = "Log10 Number of GenParticle in " + object;
54  std::string name = "NumberOf" + object;
55  nrHepMCProductH_ = iBooker.bookProfile(name,title,nbin_,minbunch_,maxbunch_+1,40,0.,40.);
56 
57  HepMCProductTags_ = tags;
58  if (HepMCProductTags_.size()) {
59  crossingFrame_Hep_Token_ = consumes<CrossingFrame<HepMCProduct> >(
61  }
62  }
63  else if ( object == "SimTrack" ) {
64 
65  std::string title = "Log10 Number of " + object;
66  std::string name = "NumberOf" + object;
67  nrSimTrackH_ = iBooker.bookProfile(name,title,nbin_,minbunch_,maxbunch_+1,40,0.,40.);
68 
69  SimTrackTags_ = tags;
70  if (SimTrackTags_.size()) {
71  crossingFrame_SimTr_Token_ = consumes<CrossingFrame<SimTrack> >(
72  edm::InputTag("mix", SimTrackTags_[0].label()));
73  }
74  }
75  else if ( object == "SimVertex" ) {
76 
77  std::string title = "Log10 Number of " + object;
78  std::string name = "NumberOf" + object;
79  nrSimVertexH_ = iBooker.bookProfile(name,title,nbin_,minbunch_,maxbunch_+1,40,0.,40.);
80 
81  SimVertexTags_ = tags;
82  if (SimVertexTags_.size()) {
83  crossingFrame_SimVtx_Token_ = consumes<CrossingFrame<SimVertex> >(
84  edm::InputTag("mix", SimVertexTags_[0].label()));
85  }
86  }
87  else if ( object == "PSimHit" ) {
88  std::vector<std::string> subdets=pset.getParameter<std::vector<std::string> >("subdets");
89  for (unsigned int ii=0;ii<subdets.size();ii++) {
90 
91  std::string title = "Log10 Number of " + subdets[ii];
92  std::string name = "NumberOf" + subdets[ii];
93  SimHitNrmap_[subdets[ii]] = iBooker.bookProfile(name,title,nbin_,minbunch_,maxbunch_+1,40,0.,40.);
94 
95  title = "Time of " + subdets[ii];
96  name = "TimeOf" + subdets[ii];
97  SimHitTimemap_[subdets[ii]] = iBooker.bookProfile(name,title,nbin_,minbunch_,maxbunch_+1,40,-125.,375.);
98 
99  }
100 
101  PSimHitTags_ = tags;
102  for (auto const & it : PSimHitTags_)
104  edm::InputTag("mix", it.label() + it.instance())));
105  }
106  else if ( object == "PCaloHit" ) {
107  std::vector<std::string> subdets=pset.getParameter<std::vector<std::string> >("subdets");
108  for (unsigned int ii=0;ii<subdets.size();ii++) {
109 
110  std::string title = "Log10 Number of " + subdets[ii];
111  std::string name = "NumberOf" + subdets[ii];
112  CaloHitNrmap_[subdets[ii]] = iBooker.bookProfile(name,title,nbin_,minbunch_,maxbunch_+1,40,0.,40.);
113 
114  title = "Time of " + subdets[ii];
115  name = "TimeOf" + subdets[ii];
116  CaloHitTimemap_[subdets[ii]] = iBooker.bookProfile(name,title,nbin_,minbunch_,maxbunch_+1,40,-125.,375.);
117 
118  }
119 
120  PCaloHitTags_ = tags;
121  for (auto const & it : PCaloHitTags_)
123  edm::InputTag("mix", it.label() + it.instance())));
124  }
125  }
126 }
127 
129 {
130  using namespace edm;
131 
132  if ( HepMCProductTags_.size() > 0 ) {
133  bool gotHepMCProduct;
135  gotHepMCProduct = iEvent.getByToken(crossingFrame_Hep_Token_, crossingFrame);
136 
137  if (gotHepMCProduct){
138  std::auto_ptr<MixCollection<HepMCProduct> >
139  hepMCProduct (new MixCollection<HepMCProduct>(crossingFrame.product ()));
141 
142  fillGenParticleMulti(hitItr, hepMCProduct, nrHepMCProductH_);
143  }
144  }
145 
146  if ( SimTrackTags_.size() > 0 ) {
147  bool gotSimTrack;
148  edm::Handle<CrossingFrame<SimTrack> > crossingFrame;
149  gotSimTrack = iEvent.getByToken(crossingFrame_SimTr_Token_,crossingFrame);
150 
151  if (gotSimTrack){
152  std::auto_ptr<MixCollection<SimTrack> >
153  simTracks (new MixCollection<SimTrack>(crossingFrame.product ()));
155 
156  fillMultiplicity(hitItr, simTracks, nrSimTrackH_);
157  }
158  }
159 
160  if ( SimVertexTags_.size() > 0 ) {
161  bool gotSimVertex;
162  edm::Handle<CrossingFrame<SimVertex> > crossingFrame;
163  std::string SimVertexLabel = SimVertexTags_[0].label();
164  gotSimVertex = iEvent.getByToken(crossingFrame_SimVtx_Token_, crossingFrame);
165 
166  if (gotSimVertex){
167  std::auto_ptr<MixCollection<SimVertex> >
168  simVerteces (new MixCollection<SimVertex>(crossingFrame.product ()));
170 
171  fillMultiplicity(hitItr, simVerteces, nrSimVertexH_);
172  }
173  }
174 
175  if ( PSimHitTags_.size() > 0 ) {
176 
177  edm::Handle<CrossingFrame<PSimHit> > crossingFrame;
178 
179  for ( int i = 0; i < (int)PSimHitTags_.size(); i++ ) {
180  bool gotPSimHit;
181  gotPSimHit = iEvent.getByToken(crossingFrame_PSimHit_Tokens_[i], crossingFrame);
182 
183  if (gotPSimHit){
184  std::auto_ptr<MixCollection<PSimHit> >
185  simHits (new MixCollection<PSimHit>(crossingFrame.product ()));
186 
188 
189  fillMultiplicity(hitItr, simHits, SimHitNrmap_[PSimHitTags_[i].instance()]);
190 
191  fillSimHitTime(hitItr, simHits, SimHitTimemap_[PSimHitTags_[i].instance()]);
192  }
193  }
194  }
195 
196  if ( PCaloHitTags_.size() > 0 ) {
197 
198  edm::Handle<CrossingFrame<PCaloHit> > crossingFrame;
199 
200  for ( int i = 0; i < (int)PCaloHitTags_.size(); i++ ) {
201  bool gotPCaloHit;
202  std::string PCaloHitLabel = PCaloHitTags_[i].label()+PCaloHitTags_[i].instance();
203  gotPCaloHit = iEvent.getByToken(crossingFrame_PCaloHit_Tokens_[i], crossingFrame);
204 
205  if (gotPCaloHit){
206  std::auto_ptr<MixCollection<PCaloHit> >
207  caloHits (new MixCollection<PCaloHit>(crossingFrame.product ()));
208 
210 
211  fillMultiplicity(hitItr, caloHits, CaloHitNrmap_[PCaloHitTags_[i].instance()]);
212 
213  fillCaloHitTime(hitItr, caloHits, CaloHitTimemap_[PCaloHitTags_[i].instance()]);
214  }
215  }
216  }
217 
218 }
219 
220 template<class T1, class T2> void MixCollectionValidation::fillMultiplicity(T1 & theItr_, T2 & theColl_, MonitorElement * theProfile_) {
221 
222  std::vector<int> theMult(nbin_);
223 
224  for ( theItr_ = theColl_->begin() ; theItr_ != theColl_->end() ; ++theItr_) {
225 
226  int bunch = (*theItr_).eventId().bunchCrossing();
227  int index = bunch - minbunch_;
228  if ( index >= 0 && index < nbin_ ) { theMult[index] += 1; }
229  else { edm::LogWarning("MixCollectionValidation") << "fillMultiplicity: bunch number " << bunch << " out of range"; }
230 
231  }
232 
233  for ( int i = 0; i < nbin_; i++ ) {
234  theProfile_->Fill(float(i+minbunch_+0.5),std::log10(std::max(float(0.1),float(theMult[i]))));
235  }
236 }
237 
238 
239 template<class T1, class T2> void MixCollectionValidation::fillGenParticleMulti(T1 & theItr_, T2 & theColl_, MonitorElement * theProfile_) {
240 
241  std::vector<int> theMult(nbin_);
242 
243  for ( theItr_ = theColl_->begin() ; theItr_ != theColl_->end() ; ++theItr_) {
244 
245  int bunch = theItr_.bunch();
246  int index = bunch - minbunch_;
247  if ( index >= 0 && index < nbin_ ) { theMult[index] += (*theItr_).GetEvent()->particles_size(); }
248  else { edm::LogWarning("MixCollectionValidation") << "fillMultiplicity: bunch number " << bunch << " out of range"; }
249 
250  }
251 
252  for ( int i = 0; i < nbin_; i++ ) {
253  theProfile_->Fill(float(i+minbunch_+0.5),std::log10(std::max(float(0.1),float(theMult[i]))));
254  }
255 }
256 
257 template<class T1, class T2> void MixCollectionValidation::fillSimHitTime(T1 & theItr_, T2 & theColl_, MonitorElement * theProfile_) {
258 
259  for ( theItr_ = theColl_->begin() ; theItr_ != theColl_->end() ; ++theItr_) {
260 
261  int bunch = (*theItr_).eventId().bunchCrossing();
262  float time = (*theItr_).timeOfFlight();
263  int index = bunch - minbunch_;
264  if ( index >= 0 && index < nbin_ ) { theProfile_->Fill(float(bunch+0.5),time); }
265  else { edm::LogWarning("MixCollectionValidation") << "fillSimHitTime: bunch number " << bunch << " out of range"; }
266 
267  }
268 
269 }
270 
271 template<class T1, class T2> void MixCollectionValidation::fillCaloHitTime(T1 & theItr_, T2 & theColl_, MonitorElement * theProfile_) {
272 
273  for ( theItr_ = theColl_->begin() ; theItr_ != theColl_->end() ; ++theItr_) {
274 
275  int bunch = (*theItr_).eventId().bunchCrossing();
276  float time = (*theItr_).time();
277  int index = bunch - minbunch_;
278  if ( index >= 0 && index < nbin_ ) { theProfile_->Fill(float(bunch+0.5),time); }
279  else { edm::LogWarning("MixCollectionValidation") << "fillCaloHitTime: bunch number " << bunch << " out of range"; }
280 
281  }
282 
283 }
T getParameter(std::string const &) const
std::map< std::string, MonitorElement * > CaloHitNrmap_
std::vector< edm::EDGetTokenT< CrossingFrame< PCaloHit > > > crossingFrame_PCaloHit_Tokens_
static const HistoName names[]
std::vector< edm::InputTag > HepMCProductTags_
MonitorElement * bookProfile(Args &&...args)
Definition: DQMStore.h:157
MixCollectionValidation(const edm::ParameterSet &)
static PFTauRenderPlugin instance
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
std::vector< edm::EDGetTokenT< CrossingFrame< PSimHit > > > crossingFrame_PSimHit_Tokens_
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::map< std::string, MonitorElement * > SimHitTimemap_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
void Fill(long long x)
int iEvent
Definition: GenABIO.cc:230
void fillCaloHitTime(T1 &theItr_, T2 &theColl_, MonitorElement *theProfile_)
edm::EDGetTokenT< CrossingFrame< SimVertex > > crossingFrame_SimVtx_Token_
void fillMultiplicity(T1 &theItr_, T2 &theColl_, MonitorElement *theProfile_)
std::vector< edm::InputTag > PSimHitTags_
std::map< std::string, MonitorElement * > SimHitNrmap_
void fillSimHitTime(T1 &theItr_, T2 &theColl_, MonitorElement *theProfile_)
edm::EDGetTokenT< CrossingFrame< SimTrack > > crossingFrame_SimTr_Token_
std::vector< std::string > getParameterNames() const
std::vector< edm::InputTag > PCaloHitTags_
ii
Definition: cuy.py:588
std::vector< edm::InputTag > SimTrackTags_
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:277
edm::EDGetTokenT< CrossingFrame< edm::HepMCProduct > > crossingFrame_Hep_Token_
T const * product() const
Definition: Handle.h:81
std::vector< edm::InputTag > SimVertexTags_
HLT enums.
std::map< std::string, MonitorElement * > CaloHitTimemap_
static const std::string subdets[7]
Definition: TrackUtils.cc:66
Definition: Run.h:42
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
void fillGenParticleMulti(T1 &theItr_, T2 &theColl_, MonitorElement *theProfile_)