CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DuplicationChecker.cc
Go to the documentation of this file.
1 /*class DuplicationChecker
2  *
3  * Class to monitor duplication of events
4  *
5  *
6  */
7 
9 
10 using namespace edm;
11 
13  wmanager_(iPSet,consumesCollector()),
14  generatedCollection_(iPSet.getParameter<edm::InputTag>("hepmcCollection")),
15  searchForLHE_(iPSet.getParameter<bool>("searchForLHE"))
16 {
17  if (searchForLHE_) {
18  lheEventProduct_ = iPSet.getParameter<edm::InputTag>("lheEventProduct");
19  }
20  dbe = 0;
22 
23  xBjorkenHistory.clear();
24 
25  if (searchForLHE_) lheEventProductToken_=consumes<LHEEventProduct>(lheEventProduct_);
26  else generatedCollectionToken_=consumes<HepMCProduct>(generatedCollection_);
27 
28 }
29 
31 {
32  xBjorkenHistory.clear();
33 }
34 
36 {
37  if(dbe){
39  dbe->setCurrentFolder("Generator/DuplicationCheck");
40 
42  xBjorkenME = dbe->book1D("xBjorkenME", "x Bjorken ratio", 1000000, 0., 1.);
43  }
44 }
45 
47 {
48 
49  double bjorken = 0;
50 
51  double weight = 1.;
52 
53  if (searchForLHE_) {
54 
56  iEvent.getByToken(lheEventProductToken_, evt);
57 
58  const lhef::HEPEUP hepeup_ = evt->hepeup();
59 
60  const std::vector<lhef::HEPEUP::FiveVector> pup_ = hepeup_.PUP;
61 
62  double pz1=(pup_[0])[3];
63  double pz2=(pup_[1])[3];
64  bjorken+=(pz1/(pz1+pz2));
65  }
66  else {
67  //change teh weight in this case
68  weight = wmanager_.weight(iEvent);
69 
72 
73  const HepMC::PdfInfo *pdf = evt->GetEvent()->pdf_info();
74  if(pdf){
75  bjorken = ((pdf->x1())/((pdf->x1())+(pdf->x2())));
76  }
77 
78  }
79 
80  xBjorkenHistory.insert(std::pair<double,edm::EventID>(bjorken,iEvent.id()));
81 
82  xBjorkenME->Fill(bjorken,weight);
83 
84 }//analyze
85 
87 {
88  associationMap::iterator itr;
89  associationMap::iterator lastElement;
90 
91  theObjects.clear();
92 
93  // locate an iterator to the first pair object associated with key
94  itr = mMap.find(key);
95  if (itr == mMap.end())
96  return; // no elements associated with key, so return immediately
97 
98  // get an iterator to the element that is one past the last element associated with key
99  lastElement = mMap.upper_bound(key);
100 
101  // for each element in the sequence [itr, lastElement)
102  for ( ; itr != lastElement; ++itr)
103  theObjects.push_back(itr);
104 }
105 
107 {
108 
109  itemList theObjects;
110  theObjects.reserve(10);
111 
112  for (associationMap::iterator it = xBjorkenHistory.begin(); it != xBjorkenHistory.end(); it++) {
113  double theKey = (*it).first;
114 
115  findValuesAssociatedWithKey(xBjorkenHistory, theKey, theObjects);
116 
117  if (theObjects.size() > 1) {
118  edm::LogWarning("DuplicatedEventFound") << "Duplicated events found with xBjorken = " << std::fixed << std::setw(16) << std::setprecision(14) << theKey;
119  for (unsigned int i = 0; i < theObjects.size(); i++) {
120  edm::LogPrint("DuplicatedEventList") << "Event = " << (*theObjects[i]).second;
121  }
122  }
123 
124  theObjects.clear();
125 
126  }
127 
128 }
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
edm::EDGetTokenT< LHEEventProduct > lheEventProductToken_
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:872
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
edm::InputTag generatedCollection_
struct HEPEUP_ hepeup_
edm::EDGetTokenT< edm::HepMCProduct > generatedCollectionToken_
std::vector< associationMap::iterator > itemList
void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup)
associationMap xBjorkenHistory
void Fill(long long x)
U second(std::pair< T, U > const &p)
int iEvent
Definition: GenABIO.cc:243
std::vector< FiveVector > PUP
Definition: LesHouches.h:248
WeightManager wmanager_
std::multimap< double, edm::EventID > associationMap
MonitorElement * xBjorkenME
edm::InputTag lheEventProduct_
DuplicationChecker(const edm::ParameterSet &)
edm::EventID id() const
Definition: EventBase.h:56
list key
Definition: combine.py:13
int weight
Definition: histoStyle.py:50
double weight(const edm::Event &)
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:584
void findValuesAssociatedWithKey(associationMap &mMap, double &key, itemList &theObjects)