CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MixCollectionValidation.cc
Go to the documentation of this file.
1 // system include files
2 #include <memory>
3 #include <utility>
4 
5 // user include files
8 
11 
13 
16 
19 
22 
24 #include "TFile.h"
27 
28 using namespace edm;
29 
30 MixCollectionValidation::MixCollectionValidation(const edm::ParameterSet& iConfig): outputFile_(iConfig.getParameter<std::string>("outputFile")),
31  minbunch_(iConfig.getParameter<int>("minBunch")),
32  maxbunch_(iConfig.getParameter<int>("maxBunch")),
33  verbose_(iConfig.getUntrackedParameter<bool>("verbose",false)),
34  dbe_(0),nbin_(maxbunch_-minbunch_+1)
35 {
36 
37  if ( outputFile_.size() != 0 ) {
38  edm::LogInfo("OutputInfo") << " Ecal SimHits Task histograms will be saved to " << outputFile_.c_str();
39  } else {
40  edm::LogInfo("OutputInfo") << " Ecal SimHits Task histograms will NOT be saved";
41  }
42 
43  // get hold of back-end interface
45  if ( dbe_ ) {
46  if ( verbose_ ) { dbe_->setVerbose(1); }
47  else { dbe_->setVerbose(0); }
48  }
49 
50  if ( dbe_ ) {
51  if ( verbose_ ) dbe_->showDirStructure();
52  }
53 
54  // get hold of back-end interface
56 // dbe_->showDirStructure();
57  dbe_->setCurrentFolder("MixingV/Mixing");
58 
59  // define the histograms according to the configuration
60 
61  ParameterSet ps=iConfig.getParameter<ParameterSet>("mixObjects");
63 
64  for (std::vector<std::string>::iterator it=names_.begin();it!= names_.end();++it)
65  {
66  ParameterSet pset=ps.getParameter<ParameterSet>((*it));
67  if (!pset.exists("type")) continue; //to allow replacement by empty pset
68  std::string object = pset.getParameter<std::string>("type");
69  std::vector<InputTag> tags=pset.getParameter<std::vector<InputTag> >("input");
70 
71 if ( object == "HepMCProduct" ) {
72 
73  std::string title = "Log10 Number of GenParticle in " + object;
74  std::string name = "NumberOf" + object;
75  nrHepMCProductH_ = dbe_->bookProfile(name,title,nbin_,minbunch_,maxbunch_+1,40,0.,40.);
76 
78 
79  }
80  else if ( object == "SimTrack" ) {
81 
82  std::string title = "Log10 Number of " + object;
83  std::string name = "NumberOf" + object;
84  nrSimTrackH_ = dbe_->bookProfile(name,title,nbin_,minbunch_,maxbunch_+1,40,0.,40.);
85 
87 
88  }
89  else if ( object == "SimVertex" ) {
90 
91  std::string title = "Log10 Number of " + object;
92  std::string name = "NumberOf" + object;
93  nrSimVertexH_ = dbe_->bookProfile(name,title,nbin_,minbunch_,maxbunch_+1,40,0.,40.);
94 
96 
97  }
98  else if ( object == "PSimHit" ) {
99  std::vector<std::string> subdets=pset.getParameter<std::vector<std::string> >("subdets");
100  for (unsigned int ii=0;ii<subdets.size();ii++) {
101 
102  std::string title = "Log10 Number of " + subdets[ii];
103  std::string name = "NumberOf" + subdets[ii];
104  SimHitNrmap_[subdets[ii]] = dbe_->bookProfile(name,title,nbin_,minbunch_,maxbunch_+1,40,0.,40.);
105 
106  title = "Time of " + subdets[ii];
107  name = "TimeOf" + subdets[ii];
108  SimHitTimemap_[subdets[ii]] = dbe_->bookProfile(name,title,nbin_,minbunch_,maxbunch_+1,40,-125.,375.);
109 
110  }
111 
112  PSimHitTags_ = tags;
113 
114  }
115  else if ( object == "PCaloHit" ) {
116  std::vector<std::string> subdets=pset.getParameter<std::vector<std::string> >("subdets");
117  for (unsigned int ii=0;ii<subdets.size();ii++) {
118 
119  std::string title = "Log10 Number of " + subdets[ii];
120  std::string name = "NumberOf" + subdets[ii];
121  CaloHitNrmap_[subdets[ii]] = dbe_->bookProfile(name,title,nbin_,minbunch_,maxbunch_+1,40,0.,40.);
122 
123  title = "Time of " + subdets[ii];
124  name = "TimeOf" + subdets[ii];
125  CaloHitTimemap_[subdets[ii]] = dbe_->bookProfile(name,title,nbin_,minbunch_,maxbunch_+1,40,-125.,375.);
126 
127  }
128 
130  }
131  }
132 
133 }
134 
136 {
137 
138  // do anything here that needs to be done at desctruction time
139  // (e.g. close files, deallocate resources etc.)
140 }
141 
143 }
144 
145 
147  if (outputFile_.size() != 0 && dbe_ ) dbe_->save(outputFile_);
148 }
149 
150 //
151 // member functions
152 //
153 
154 // ------------ method called to analyze the data ------------
155 void
157 {
158 
159  using namespace edm;
160 
161  if ( HepMCProductTags_.size() > 0 ) {
162  bool gotHepMCProduct;
164  std::string HepMCProductLabel = HepMCProductTags_[0].label();
165  gotHepMCProduct = iEvent.getByLabel("mix",HepMCProductLabel,crossingFrame);
166 
167  if (gotHepMCProduct){
168  std::auto_ptr<MixCollection<HepMCProduct> >
169  hepMCProduct (new MixCollection<HepMCProduct>(crossingFrame.product ()));
171 
172  fillGenParticleMulti(hitItr, hepMCProduct, nrHepMCProductH_);
173  }
174  }
175 
176  if ( SimTrackTags_.size() > 0 ) {
177  bool gotSimTrack;
178  edm::Handle<CrossingFrame<SimTrack> > crossingFrame;
179  std::string SimTrackLabel = SimTrackTags_[0].label();
180  gotSimTrack = iEvent.getByLabel("mix",SimTrackLabel,crossingFrame);
181 
182  if (gotSimTrack){
183  std::auto_ptr<MixCollection<SimTrack> >
184  simTracks (new MixCollection<SimTrack>(crossingFrame.product ()));
186 
187  fillMultiplicity(hitItr, simTracks, nrSimTrackH_);
188  }
189  }
190 
191  if ( SimVertexTags_.size() > 0 ) {
192  bool gotSimVertex;
193  edm::Handle<CrossingFrame<SimVertex> > crossingFrame;
194  std::string SimVertexLabel = SimVertexTags_[0].label();
195  gotSimVertex = iEvent.getByLabel("mix",SimVertexLabel,crossingFrame);
196 
197  if (gotSimVertex){
198  std::auto_ptr<MixCollection<SimVertex> >
199  simVerteces (new MixCollection<SimVertex>(crossingFrame.product ()));
201 
202  fillMultiplicity(hitItr, simVerteces, nrSimVertexH_);
203  }
204  }
205 
206  if ( PSimHitTags_.size() > 0 ) {
207 
208  edm::Handle<CrossingFrame<PSimHit> > crossingFrame;
209 
210  for ( int i = 0; i < (int)PSimHitTags_.size(); i++ ) {
211  bool gotPSimHit;
212  std::string PSimHitLabel = PSimHitTags_[i].label()+PSimHitTags_[i].instance();
213  gotPSimHit = iEvent.getByLabel("mix",PSimHitLabel,crossingFrame);
214 
215  if (gotPSimHit){
216  std::auto_ptr<MixCollection<PSimHit> >
217  simHits (new MixCollection<PSimHit>(crossingFrame.product ()));
218 
220 
221  fillMultiplicity(hitItr, simHits, SimHitNrmap_[PSimHitTags_[i].instance()]);
222 
223  fillSimHitTime(hitItr, simHits, SimHitTimemap_[PSimHitTags_[i].instance()]);
224  }
225  }
226  }
227 
228  if ( PCaloHitTags_.size() > 0 ) {
229 
230  edm::Handle<CrossingFrame<PCaloHit> > crossingFrame;
231 
232  for ( int i = 0; i < (int)PCaloHitTags_.size(); i++ ) {
233  bool gotPCaloHit;
234  std::string PCaloHitLabel = PCaloHitTags_[i].label()+PCaloHitTags_[i].instance();
235  gotPCaloHit = iEvent.getByLabel("mix",PCaloHitLabel,crossingFrame);
236 
237  if (gotPCaloHit){
238  std::auto_ptr<MixCollection<PCaloHit> >
239  caloHits (new MixCollection<PCaloHit>(crossingFrame.product ()));
240 
242 
243  fillMultiplicity(hitItr, caloHits, CaloHitNrmap_[PCaloHitTags_[i].instance()]);
244 
245  fillCaloHitTime(hitItr, caloHits, CaloHitTimemap_[PCaloHitTags_[i].instance()]);
246  }
247  }
248  }
249 
250 }
251 
252 template<class T1, class T2> void MixCollectionValidation::fillMultiplicity(T1 & theItr_, T2 & theColl_, MonitorElement * theProfile_) {
253 
254  std::vector<int> theMult(nbin_);
255 
256  for ( theItr_ = theColl_->begin() ; theItr_ != theColl_->end() ; ++theItr_) {
257 
258  int bunch = (*theItr_).eventId().bunchCrossing();
259  int index = bunch - minbunch_;
260  if ( index >= 0 && index < nbin_ ) { theMult[index] += 1; }
261  else { edm::LogWarning("MixCollectionValidation") << "fillMultiplicity: bunch number " << bunch << " out of range"; }
262 
263  }
264 
265  for ( int i = 0; i < nbin_; i++ ) {
266  theProfile_->Fill(float(i+minbunch_+0.5),std::log10(std::max(float(0.1),float(theMult[i]))));
267  }
268 }
269 
270 
271 template<class T1, class T2> void MixCollectionValidation::fillGenParticleMulti(T1 & theItr_, T2 & theColl_, MonitorElement * theProfile_) {
272 
273  std::vector<int> theMult(nbin_);
274 
275  for ( theItr_ = theColl_->begin() ; theItr_ != theColl_->end() ; ++theItr_) {
276 
277  int bunch = theItr_.bunch();
278  int index = bunch - minbunch_;
279  if ( index >= 0 && index < nbin_ ) { theMult[index] += (*theItr_).GetEvent()->particles_size(); }
280  else { edm::LogWarning("MixCollectionValidation") << "fillMultiplicity: bunch number " << bunch << " out of range"; }
281 
282  }
283 
284  for ( int i = 0; i < nbin_; i++ ) {
285  theProfile_->Fill(float(i+minbunch_+0.5),std::log10(std::max(float(0.1),float(theMult[i]))));
286  }
287 }
288 
289 template<class T1, class T2> void MixCollectionValidation::fillSimHitTime(T1 & theItr_, T2 & theColl_, MonitorElement * theProfile_) {
290 
291  for ( theItr_ = theColl_->begin() ; theItr_ != theColl_->end() ; ++theItr_) {
292 
293  int bunch = (*theItr_).eventId().bunchCrossing();
294  float time = (*theItr_).timeOfFlight();
295  int index = bunch - minbunch_;
296  if ( index >= 0 && index < nbin_ ) { theProfile_->Fill(float(bunch+0.5),time); }
297  else { edm::LogWarning("MixCollectionValidation") << "fillSimHitTime: bunch number " << bunch << " out of range"; }
298 
299  }
300 
301 }
302 
303 template<class T1, class T2> void MixCollectionValidation::fillCaloHitTime(T1 & theItr_, T2 & theColl_, MonitorElement * theProfile_) {
304 
305  for ( theItr_ = theColl_->begin() ; theItr_ != theColl_->end() ; ++theItr_) {
306 
307  int bunch = (*theItr_).eventId().bunchCrossing();
308  float time = (*theItr_).time();
309  int index = bunch - minbunch_;
310  if ( index >= 0 && index < nbin_ ) { theProfile_->Fill(float(bunch+0.5),time); }
311  else { edm::LogWarning("MixCollectionValidation") << "fillCaloHitTime: bunch number " << bunch << " out of range"; }
312 
313  }
314 
315 }
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
std::map< std::string, MonitorElement * > CaloHitNrmap_
std::vector< edm::InputTag > HepMCProductTags_
MixCollectionValidation(const edm::ParameterSet &)
static PFTauRenderPlugin instance
void save(const std::string &filename, const std::string &path="", const std::string &pattern="", const std::string &rewrite="", SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, const std::string &fileupdate="RECREATE")
Definition: DQMStore.cc:2118
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::map< std::string, MonitorElement * > SimHitTimemap_
int ii
Definition: cuy.py:588
void Fill(long long x)
int iEvent
Definition: GenABIO.cc:243
const T & max(const T &a, const T &b)
void fillCaloHitTime(T1 &theItr_, T2 &theColl_, MonitorElement *theProfile_)
void fillMultiplicity(T1 &theItr_, T2 &theColl_, MonitorElement *theProfile_)
std::vector< edm::InputTag > PSimHitTags_
std::map< std::string, MonitorElement * > SimHitNrmap_
MonitorElement * bookProfile(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, const char *option="s")
Definition: DQMStore.cc:1036
void setVerbose(unsigned level)
Definition: DQMStore.cc:398
void fillSimHitTime(T1 &theItr_, T2 &theColl_, MonitorElement *theProfile_)
std::vector< std::string > getParameterNames() const
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
DQMStore * dbe_
std::vector< edm::InputTag > PCaloHitTags_
tuple tags
Definition: o2o.py:248
std::vector< edm::InputTag > SimTrackTags_
constexpr char const * subdets[11]
tuple simHits
Definition: trackerHits.py:16
T const * product() const
Definition: Handle.h:74
list object
Definition: dbtoconf.py:77
std::vector< edm::InputTag > SimVertexTags_
std::map< std::string, MonitorElement * > CaloHitTimemap_
virtual void analyze(const edm::Event &, const edm::EventSetup &)
void showDirStructure(void) const
Definition: DQMStore.cc:2766
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:434
void fillGenParticleMulti(T1 &theItr_, T2 &theColl_, MonitorElement *theProfile_)
std::vector< std::string > names_