Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:32:10

0001 /*class DuplicationChecker
0002  *  
0003  *  Class to monitor duplication of events
0004  *
0005  *
0006  */
0007 
0008 #include "Validation/EventGenerator/interface/DuplicationChecker.h"
0009 #include "Validation/EventGenerator/interface/DQMHelper.h"
0010 using namespace edm;
0011 
0012 DuplicationChecker::DuplicationChecker(const edm::ParameterSet &iPSet)
0013     : wmanager_(iPSet, consumesCollector()),
0014       generatedCollection_(iPSet.getParameter<edm::InputTag>("hepmcCollection")),
0015       searchForLHE_(iPSet.getParameter<bool>("searchForLHE")) {
0016   if (searchForLHE_) {
0017     lheEventProduct_ = iPSet.getParameter<edm::InputTag>("lheEventProduct");
0018   }
0019   xBjorkenHistory.clear();
0020 
0021   if (searchForLHE_)
0022     lheEventProductToken_ = consumes<LHEEventProduct>(lheEventProduct_);
0023   else
0024     generatedCollectionToken_ = consumes<HepMCProduct>(generatedCollection_);
0025 }
0026 
0027 DuplicationChecker::~DuplicationChecker() { xBjorkenHistory.clear(); }
0028 
0029 void DuplicationChecker::bookHistograms(DQMStore::IBooker &i, edm::Run const &, edm::EventSetup const &) {
0030   ///Setting the DQM top directories
0031   DQMHelper dqm(&i);
0032   i.setCurrentFolder("Generator/DuplicationCheck");
0033 
0034   ///Booking the ME's
0035   xBjorkenME = dqm.book1dHisto("xBjorkenME", "x Bjorken ratio", 1000000, 0., 1.);
0036 }
0037 
0038 void DuplicationChecker::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
0039   double bjorken = 0;
0040 
0041   double weight = 1.;
0042 
0043   if (searchForLHE_) {
0044     Handle<LHEEventProduct> evt;
0045     iEvent.getByToken(lheEventProductToken_, evt);
0046 
0047     const lhef::HEPEUP hepeup_ = evt->hepeup();
0048 
0049     const std::vector<lhef::HEPEUP::FiveVector> pup_ = hepeup_.PUP;
0050 
0051     double pz1 = (pup_[0])[3];
0052     double pz2 = (pup_[1])[3];
0053     bjorken += (pz1 / (pz1 + pz2));
0054   } else {
0055     //change teh weight in this case
0056     weight = wmanager_.weight(iEvent);
0057 
0058     edm::Handle<HepMCProduct> evt;
0059     iEvent.getByToken(generatedCollectionToken_, evt);
0060 
0061     const HepMC::PdfInfo *pdf = evt->GetEvent()->pdf_info();
0062     if (pdf) {
0063       bjorken = ((pdf->x1()) / ((pdf->x1()) + (pdf->x2())));
0064     }
0065   }
0066 
0067   xBjorkenHistory.insert(std::pair<double, edm::EventID>(bjorken, iEvent.id()));
0068 
0069   xBjorkenME->Fill(bjorken, weight);
0070 
0071 }  //analyze
0072 
0073 void DuplicationChecker::findValuesAssociatedWithKey(associationMap &mMap, double &key, itemList &theObjects) {
0074   associationMap::iterator itr;
0075   associationMap::iterator lastElement;
0076 
0077   theObjects.clear();
0078 
0079   // locate an iterator to the first pair object associated with key
0080   itr = mMap.find(key);
0081   if (itr == mMap.end())
0082     return;  // no elements associated with key, so return immediately
0083 
0084   // get an iterator to the element that is one past the last element associated with key
0085   lastElement = mMap.upper_bound(key);
0086 
0087   // for each element in the sequence [itr, lastElement)
0088   for (; itr != lastElement; ++itr)
0089     theObjects.push_back(itr);
0090 }
0091 
0092 /* no corresponding function available  in MultiThreaded version
0093 void DuplicationChecker::endJob()
0094 {
0095 
0096   itemList theObjects;
0097   theObjects.reserve(10);
0098 
0099   for (associationMap::iterator it = xBjorkenHistory.begin(); it != xBjorkenHistory.end(); it++) {
0100     double theKey = (*it).first;
0101 
0102     findValuesAssociatedWithKey(xBjorkenHistory, theKey, theObjects);
0103 
0104     if (theObjects.size() > 1) {
0105       edm::LogWarning("DuplicatedEventFound") << "Duplicated events found with xBjorken = " << std::fixed << std::setw(16) << std::setprecision(14) << theKey; 
0106       for (unsigned int i = 0; i < theObjects.size(); i++) {
0107         edm::LogPrint("DuplicatedEventList") << "Event = " << (*theObjects[i]).second;
0108       }
0109     }
0110 
0111     theObjects.clear();
0112  
0113   }
0114 
0115 }
0116 */