CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MixCollectionValidation.cc
Go to the documentation of this file.
1 // system include files
3 
4 // user include files
7 
10 
12 
14 #include "TFile.h"
15 
16 #include <memory>
17 #include <utility>
18 
19 using namespace edm;
20 
22  : minbunch_(iConfig.getParameter<int>("minBunch")),
23  maxbunch_(iConfig.getParameter<int>("maxBunch")),
24  verbose_(iConfig.getUntrackedParameter<bool>("verbose", false)),
25  nbin_(maxbunch_ - minbunch_ + 1) {
26  // Histograms will be defined according to the configuration
27  ParameterSet mixObjextsSet_ = iConfig.getParameter<ParameterSet>("mixObjects");
28 }
29 
31  // do anything here that needs to be done at desctruction time
32  // (e.g. close files, deallocate resources etc.)
33 }
34 
36  edm::Run const &iRun,
37  edm::EventSetup const & /* iSetup */) {
38  iBooker.setCurrentFolder("MixingV/Mixing");
39 
40  std::vector<std::string> names = mixObjextsSet_.getParameterNames();
41 
42  for (std::vector<std::string>::iterator it = names.begin(); it != names.end(); ++it) {
44  if (!pset.exists("type"))
45  continue; // to allow replacement by empty pset
46  std::string object = pset.getParameter<std::string>("type");
47  std::vector<InputTag> tags = pset.getParameter<std::vector<InputTag>>("input");
48 
49  if (object == "HepMCProduct") {
50  std::string title = "Log10 Number of GenParticle in " + object;
51  std::string name = "NumberOf" + object;
52  nrHepMCProductH_ = iBooker.bookProfile(name, title, nbin_, minbunch_, maxbunch_ + 1, 40, 0., 40.);
53 
55  if (!HepMCProductTags_.empty()) {
57  consumes<CrossingFrame<HepMCProduct>>(edm::InputTag("mix", HepMCProductTags_[0].label()));
58  }
59  } else if (object == "SimTrack") {
60  std::string title = "Log10 Number of " + object;
61  std::string name = "NumberOf" + object;
62  nrSimTrackH_ = iBooker.bookProfile(name, title, nbin_, minbunch_, maxbunch_ + 1, 40, 0., 40.);
63 
65  if (!SimTrackTags_.empty()) {
66  crossingFrame_SimTr_Token_ = consumes<CrossingFrame<SimTrack>>(edm::InputTag("mix", SimTrackTags_[0].label()));
67  }
68  } else if (object == "SimVertex") {
69  std::string title = "Log10 Number of " + object;
70  std::string name = "NumberOf" + object;
71  nrSimVertexH_ = iBooker.bookProfile(name, title, nbin_, minbunch_, maxbunch_ + 1, 40, 0., 40.);
72 
74  if (!SimVertexTags_.empty()) {
76  consumes<CrossingFrame<SimVertex>>(edm::InputTag("mix", SimVertexTags_[0].label()));
77  }
78  } else if (object == "PSimHit") {
79  std::vector<std::string> subdets = pset.getParameter<std::vector<std::string>>("subdets");
80  for (unsigned int ii = 0; ii < subdets.size(); ii++) {
81  std::string title = "Log10 Number of " + subdets[ii];
82  std::string name = "NumberOf" + subdets[ii];
83  SimHitNrmap_[subdets[ii]] = iBooker.bookProfile(name, title, nbin_, minbunch_, maxbunch_ + 1, 40, 0., 40.);
84 
85  title = "Time of " + subdets[ii];
86  name = "TimeOf" + subdets[ii];
87  SimHitTimemap_[subdets[ii]] =
88  iBooker.bookProfile(name, title, nbin_, minbunch_, maxbunch_ + 1, 40, -125., 375.);
89  }
90 
92  for (auto const &it : PSimHitTags_)
94  consumes<CrossingFrame<PSimHit>>(edm::InputTag("mix", it.label() + it.instance())));
95  } else if (object == "PCaloHit") {
96  std::vector<std::string> subdets = pset.getParameter<std::vector<std::string>>("subdets");
97  for (unsigned int ii = 0; ii < subdets.size(); ii++) {
98  std::string title = "Log10 Number of " + subdets[ii];
99  std::string name = "NumberOf" + subdets[ii];
100  CaloHitNrmap_[subdets[ii]] = iBooker.bookProfile(name, title, nbin_, minbunch_, maxbunch_ + 1, 40, 0., 40.);
101 
102  title = "Time of " + subdets[ii];
103  name = "TimeOf" + subdets[ii];
104  CaloHitTimemap_[subdets[ii]] =
105  iBooker.bookProfile(name, title, nbin_, minbunch_, maxbunch_ + 1, 40, -125., 375.);
106  }
107 
109  for (auto const &it : PCaloHitTags_)
111  consumes<CrossingFrame<PCaloHit>>(edm::InputTag("mix", it.label() + it.instance())));
112  }
113  }
114 }
115 
117  using namespace edm;
118 
119  if (!HepMCProductTags_.empty()) {
120  bool gotHepMCProduct;
122  gotHepMCProduct = iEvent.getByToken(crossingFrame_Hep_Token_, crossingFrame);
123 
124  if (gotHepMCProduct) {
125  std::unique_ptr<MixCollection<HepMCProduct>> hepMCProduct(
126  new MixCollection<HepMCProduct>(crossingFrame.product()));
128 
129  fillGenParticleMulti(hitItr, hepMCProduct, nrHepMCProductH_);
130  }
131  }
132 
133  if (!SimTrackTags_.empty()) {
134  bool gotSimTrack;
136  gotSimTrack = iEvent.getByToken(crossingFrame_SimTr_Token_, crossingFrame);
137 
138  if (gotSimTrack) {
139  std::unique_ptr<MixCollection<SimTrack>> simTracks(new MixCollection<SimTrack>(crossingFrame.product()));
141 
142  fillMultiplicity(hitItr, simTracks, nrSimTrackH_);
143  }
144  }
145 
146  if (!SimVertexTags_.empty()) {
147  bool gotSimVertex;
149  std::string SimVertexLabel = SimVertexTags_[0].label();
150  gotSimVertex = iEvent.getByToken(crossingFrame_SimVtx_Token_, crossingFrame);
151 
152  if (gotSimVertex) {
153  std::unique_ptr<MixCollection<SimVertex>> simVerteces(new MixCollection<SimVertex>(crossingFrame.product()));
155 
156  fillMultiplicity(hitItr, simVerteces, nrSimVertexH_);
157  }
158  }
159 
160  if (!PSimHitTags_.empty()) {
161  edm::Handle<CrossingFrame<PSimHit>> crossingFrame;
162 
163  for (int i = 0; i < (int)PSimHitTags_.size(); i++) {
164  bool gotPSimHit;
165  gotPSimHit = iEvent.getByToken(crossingFrame_PSimHit_Tokens_[i], crossingFrame);
166 
167  if (gotPSimHit) {
168  std::unique_ptr<MixCollection<PSimHit>> simHits(new MixCollection<PSimHit>(crossingFrame.product()));
169 
171 
172  fillMultiplicity(hitItr, simHits, SimHitNrmap_[PSimHitTags_[i].instance()]);
173 
174  fillSimHitTime(hitItr, simHits, SimHitTimemap_[PSimHitTags_[i].instance()]);
175  }
176  }
177  }
178 
179  if (!PCaloHitTags_.empty()) {
181 
182  for (int i = 0; i < (int)PCaloHitTags_.size(); i++) {
183  bool gotPCaloHit;
184  std::string PCaloHitLabel = PCaloHitTags_[i].label() + PCaloHitTags_[i].instance();
185  gotPCaloHit = iEvent.getByToken(crossingFrame_PCaloHit_Tokens_[i], crossingFrame);
186 
187  if (gotPCaloHit) {
188  std::unique_ptr<MixCollection<PCaloHit>> caloHits(new MixCollection<PCaloHit>(crossingFrame.product()));
189 
191 
192  fillMultiplicity(hitItr, caloHits, CaloHitNrmap_[PCaloHitTags_[i].instance()]);
193 
194  fillCaloHitTime(hitItr, caloHits, CaloHitTimemap_[PCaloHitTags_[i].instance()]);
195  }
196  }
197  }
198 }
199 
200 template <class T1, class T2>
201 void MixCollectionValidation::fillMultiplicity(T1 &theItr_, T2 &theColl_, MonitorElement *theProfile_) {
202  std::vector<int> theMult(nbin_);
203 
204  for (theItr_ = theColl_->begin(); theItr_ != theColl_->end(); ++theItr_) {
205  int bunch = (*theItr_).eventId().bunchCrossing();
206  int index = bunch - minbunch_;
207  if (index >= 0 && index < nbin_) {
208  theMult[index] += 1;
209  } else {
210  edm::LogWarning("MixCollectionValidation") << "fillMultiplicity: bunch number " << bunch << " out of range";
211  }
212  }
213 
214  for (int i = 0; i < nbin_; i++) {
215  theProfile_->Fill(float(i + minbunch_ + 0.5), std::log10(std::max(float(0.1), float(theMult[i]))));
216  }
217 }
218 
219 template <class T1, class T2>
220 void MixCollectionValidation::fillGenParticleMulti(T1 &theItr_, T2 &theColl_, MonitorElement *theProfile_) {
221  std::vector<int> theMult(nbin_);
222 
223  for (theItr_ = theColl_->begin(); theItr_ != theColl_->end(); ++theItr_) {
224  int bunch = theItr_.bunch();
225  int index = bunch - minbunch_;
226  if (index >= 0 && index < nbin_) {
227  theMult[index] += (*theItr_).GetEvent()->particles_size();
228  } else {
229  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 template <class T1, class T2>
239 void MixCollectionValidation::fillSimHitTime(T1 &theItr_, T2 &theColl_, MonitorElement *theProfile_) {
240  for (theItr_ = theColl_->begin(); theItr_ != theColl_->end(); ++theItr_) {
241  int bunch = (*theItr_).eventId().bunchCrossing();
242  float time = (*theItr_).timeOfFlight();
243  int index = bunch - minbunch_;
244  if (index >= 0 && index < nbin_) {
245  theProfile_->Fill(float(bunch + 0.5), time);
246  } else {
247  edm::LogWarning("MixCollectionValidation") << "fillSimHitTime: bunch number " << bunch << " out of range";
248  }
249  }
250 }
251 
252 template <class T1, class T2>
253 void MixCollectionValidation::fillCaloHitTime(T1 &theItr_, T2 &theColl_, MonitorElement *theProfile_) {
254  for (theItr_ = theColl_->begin(); theItr_ != theColl_->end(); ++theItr_) {
255  int bunch = (*theItr_).eventId().bunchCrossing();
256  float time = (*theItr_).time();
257  int index = bunch - minbunch_;
258  if (index >= 0 && index < nbin_) {
259  theProfile_->Fill(float(bunch + 0.5), time);
260  } else {
261  edm::LogWarning("MixCollectionValidation") << "fillCaloHitTime: bunch number " << bunch << " out of range";
262  }
263  }
264 }
std::map< std::string, MonitorElement * > SimHitNrmap_
std::vector< edm::EDGetTokenT< CrossingFrame< PSimHit > > > crossingFrame_PSimHit_Tokens_
std::map< std::string, MonitorElement * > CaloHitTimemap_
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
std::vector< edm::InputTag > HepMCProductTags_
MixCollectionValidation(const edm::ParameterSet &)
static PFTauRenderPlugin instance
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
std::vector< edm::EDGetTokenT< CrossingFrame< PCaloHit > > > crossingFrame_PCaloHit_Tokens_
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
std::map< std::string, MonitorElement * > CaloHitNrmap_
bool exists(std::string const &parameterName) const
checks if a parameter exists
int ii
Definition: cuy.py:589
const std::string names[nVars_]
void Fill(long long x)
char const * label
int iEvent
Definition: GenABIO.cc:224
void fillCaloHitTime(T1 &theItr_, T2 &theColl_, MonitorElement *theProfile_)
MonitorElement * bookProfile(TString const &name, TString const &title, int nchX, double lowX, double highX, int, double lowY, double highY, char const *option="s", FUNC onbooking=NOOP())
Definition: DQMStore.h:322
edm::EDGetTokenT< CrossingFrame< SimVertex > > crossingFrame_SimVtx_Token_
void fillMultiplicity(T1 &theItr_, T2 &theColl_, MonitorElement *theProfile_)
std::vector< edm::InputTag > PSimHitTags_
void fillSimHitTime(T1 &theItr_, T2 &theColl_, MonitorElement *theProfile_)
std::map< std::string, MonitorElement * > SimHitTimemap_
edm::EDGetTokenT< CrossingFrame< SimTrack > > crossingFrame_SimTr_Token_
std::vector< std::string > getParameterNames() const
std::vector< edm::InputTag > PCaloHitTags_
std::vector< edm::InputTag > SimTrackTags_
edm::EDGetTokenT< CrossingFrame< edm::HepMCProduct > > crossingFrame_Hep_Token_
T const * product() const
Definition: Handle.h:70
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
tuple simHits
Definition: trackerHits.py:16
std::vector< edm::InputTag > SimVertexTags_
Log< level::Warning, false > LogWarning
static const std::string subdets[7]
Definition: TrackUtils.cc:60
Definition: Run.h:45
void analyze(const edm::Event &, const edm::EventSetup &) override
void fillGenParticleMulti(T1 &theItr_, T2 &theColl_, MonitorElement *theProfile_)