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 
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];
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];
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 
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 
173 
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 }
MixCollectionValidation::SimVertexTags_
std::vector< edm::InputTag > SimVertexTags_
Definition: MixCollectionValidation.h:86
dqm::impl::MonitorElement
Definition: MonitorElement.h:98
runGCPTkAlMap.title
string title
Definition: runGCPTkAlMap.py:94
electrons_cff.bool
bool
Definition: electrons_cff.py:366
resolutioncreator_cfi.object
object
Definition: resolutioncreator_cfi.py:4
mps_fire.i
i
Definition: mps_fire.py:428
funct::false
false
Definition: Factorize.h:29
edm::Handle::product
T const * product() const
Definition: Handle.h:70
edm::Run
Definition: Run.h:45
MixCollectionValidation::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: MixCollectionValidation.cc:116
edm
HLT enums.
Definition: AlignableModifier.h:19
MixCollectionValidation::fillGenParticleMulti
void fillGenParticleMulti(T1 &theItr_, T2 &theColl_, MonitorElement *theProfile_)
fireworks::subdets
static const std::string subdets[7]
Definition: TrackUtils.cc:60
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89285
dqm::implementation::NavigatorBase::setCurrentFolder
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
MixCollectionValidation::~MixCollectionValidation
~MixCollectionValidation() override
Definition: MixCollectionValidation.cc:30
MixCollectionValidation::crossingFrame_SimVtx_Token_
edm::EDGetTokenT< CrossingFrame< SimVertex > > crossingFrame_SimVtx_Token_
Definition: MixCollectionValidation.h:64
protons_cff.time
time
Definition: protons_cff.py:39
FastTrackerRecHitCombiner_cfi.simHits
simHits
Definition: FastTrackerRecHitCombiner_cfi.py:5
TrackCandidateProducer_cfi.simTracks
simTracks
Definition: TrackCandidateProducer_cfi.py:15
DQMStore.h
EDAnalyzer.h
MixCollectionValidation::nbin_
int nbin_
Definition: MixCollectionValidation.h:90
edm::Handle
Definition: AssociativeIterator.h:50
MixCollection::MixItr
Definition: MixCollection.h:61
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
MixCollectionValidation::fillSimHitTime
void fillSimHitTime(T1 &theItr_, T2 &theColl_, MonitorElement *theProfile_)
MixCollectionValidation::crossingFrame_SimTr_Token_
edm::EDGetTokenT< CrossingFrame< SimTrack > > crossingFrame_SimTr_Token_
Definition: MixCollectionValidation.h:63
CrossingFrame
Definition: CrossingFrame.h:37
MakerMacros.h
names
const std::string names[nVars_]
Definition: PhotonIDValueMapProducer.cc:124
MixCollection
Definition: MixCollection.h:10
MixCollectionValidation::crossingFrame_PCaloHit_Tokens_
std::vector< edm::EDGetTokenT< CrossingFrame< PCaloHit > > > crossingFrame_PCaloHit_Tokens_
Definition: MixCollectionValidation.h:66
MixCollectionValidation::bookHistograms
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Definition: MixCollectionValidation.cc:35
dqm::impl::MonitorElement::Fill
void Fill(long long x)
Definition: MonitorElement.h:290
MixCollectionValidation::crossingFrame_Hep_Token_
edm::EDGetTokenT< CrossingFrame< edm::HepMCProduct > > crossingFrame_Hep_Token_
Definition: MixCollectionValidation.h:62
dqm::implementation::IBooker::bookProfile
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
MixCollectionValidation::nrSimTrackH_
MonitorElement * nrSimTrackH_
Definition: MixCollectionValidation.h:75
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
MixCollectionValidation::mixObjextsSet_
edm::ParameterSet mixObjextsSet_
Definition: MixCollectionValidation.h:41
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
edm::ParameterSet::getParameterNames
std::vector< std::string > getParameterNames() const
Definition: ParameterSet.cc:663
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
MixCollectionValidation::fillMultiplicity
void fillMultiplicity(T1 &theItr_, T2 &theColl_, MonitorElement *theProfile_)
MixCollectionValidation::nrHepMCProductH_
MonitorElement * nrHepMCProductH_
Definition: MixCollectionValidation.h:74
edm::EventSetup
Definition: EventSetup.h:58
MixCollectionValidation.h
MixCollectionValidation::minbunch_
int minbunch_
Definition: MixCollectionValidation.h:69
instance
static PFTauRenderPlugin instance
Definition: PFTauRenderPlugin.cc:70
MixCollectionValidation::fillCaloHitTime
void fillCaloHitTime(T1 &theItr_, T2 &theColl_, MonitorElement *theProfile_)
MixCollectionValidation::PCaloHitTags_
std::vector< edm::InputTag > PCaloHitTags_
Definition: MixCollectionValidation.h:88
MixCollectionValidation::PSimHitTags_
std::vector< edm::InputTag > PSimHitTags_
Definition: MixCollectionValidation.h:87
Frameworkfwd.h
MixCollectionValidation::SimHitTimemap_
std::map< std::string, MonitorElement * > SimHitTimemap_
Definition: MixCollectionValidation.h:79
MixCollectionValidation::crossingFrame_PSimHit_Tokens_
std::vector< edm::EDGetTokenT< CrossingFrame< PSimHit > > > crossingFrame_PSimHit_Tokens_
Definition: MixCollectionValidation.h:65
MixCollectionValidation::CaloHitTimemap_
std::map< std::string, MonitorElement * > CaloHitTimemap_
Definition: MixCollectionValidation.h:82
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
dqm::implementation::IBooker
Definition: DQMStore.h:43
triggerMatcherToHLTDebug_cfi.tags
tags
Definition: triggerMatcherToHLTDebug_cfi.py:9
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
MixCollectionValidation::SimHitNrmap_
std::map< std::string, MonitorElement * > SimHitNrmap_
Definition: MixCollectionValidation.h:78
ParameterSet.h
MixCollectionValidation::SimTrackTags_
std::vector< edm::InputTag > SimTrackTags_
Definition: MixCollectionValidation.h:85
edm::Event
Definition: Event.h:73
MixCollectionValidation::CaloHitNrmap_
std::map< std::string, MonitorElement * > CaloHitNrmap_
Definition: MixCollectionValidation.h:81
cuy.ii
ii
Definition: cuy.py:590
edm::InputTag
Definition: InputTag.h:15
label
const char * label
Definition: PFTauDecayModeTools.cc:11
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
MixCollectionValidation::HepMCProductTags_
std::vector< edm::InputTag > HepMCProductTags_
Definition: MixCollectionValidation.h:84
MixCollectionValidation::nrSimVertexH_
MonitorElement * nrSimVertexH_
Definition: MixCollectionValidation.h:76
MixCollectionValidation::MixCollectionValidation
MixCollectionValidation(const edm::ParameterSet &)
Definition: MixCollectionValidation.cc:21
MixCollectionValidation::maxbunch_
int maxbunch_
Definition: MixCollectionValidation.h:70