CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10/src/Validation/EventGenerator/plugins/DuplicationChecker.cc

Go to the documentation of this file.
00001 /*class DuplicationChecker
00002  *  
00003  *  Class to monitor duplication of events
00004  *
00005  *  $Date: 2012/08/24 21:47:06 $
00006  *  $Revision: 1.3 $
00007  *
00008  */
00009  
00010 #include "Validation/EventGenerator/interface/DuplicationChecker.h"
00011 
00012 using namespace edm;
00013 
00014 DuplicationChecker::DuplicationChecker(const edm::ParameterSet& iPSet):
00015   _wmanager(iPSet),
00016   generatedCollection_(iPSet.getParameter<edm::InputTag>("hepmcCollection")),
00017   searchForLHE_(iPSet.getParameter<bool>("searchForLHE"))
00018 { 
00019   if (searchForLHE_) {
00020     lheEventProduct_ = iPSet.getParameter<edm::InputTag>("lheEventProduct");
00021   }
00022   dbe = 0;
00023   dbe = edm::Service<DQMStore>().operator->();
00024 
00025   xBjorkenHistory.clear();
00026 }
00027 
00028 DuplicationChecker::~DuplicationChecker() 
00029 {
00030   xBjorkenHistory.clear();
00031 }
00032 
00033 void DuplicationChecker::beginJob()
00034 {
00035   if(dbe){
00037         dbe->setCurrentFolder("Generator/DuplicationCheck");
00038         
00040         xBjorkenME = dbe->book1D("xBjorkenME", "x Bjorken ratio", 1000000, 0., 1.);
00041   }
00042 }
00043 
00044 void DuplicationChecker::analyze(const edm::Event& iEvent,const edm::EventSetup& iSetup)
00045 {
00046     
00047   double bjorken = 0;
00048   
00049   double weight = _wmanager.weight(iEvent);
00050 
00051   if (searchForLHE_) {
00052 
00053     Handle<LHEEventProduct> evt;
00054     iEvent.getByLabel(lheEventProduct_, evt);
00055 
00056     const lhef::HEPEUP hepeup_ = evt->hepeup();
00057 
00058     const std::vector<lhef::HEPEUP::FiveVector> pup_ = hepeup_.PUP;
00059 
00060     double pz1=(pup_[0])[3];
00061     double pz2=(pup_[1])[3];
00062     bjorken+=(pz1/(pz1+pz2));
00063   }
00064   else {
00065 
00066     edm::Handle<HepMCProduct> evt;
00067     iEvent.getByLabel(generatedCollection_, evt);
00068 
00069     const HepMC::PdfInfo *pdf = evt->GetEvent()->pdf_info();    
00070     if(pdf){
00071       bjorken = ((pdf->x1())/((pdf->x1())+(pdf->x2())));
00072     }
00073 
00074   }
00075 
00076   xBjorkenHistory.insert(std::pair<double,edm::EventID>(bjorken,iEvent.id()));
00077 
00078   xBjorkenME->Fill(bjorken,weight);
00079 
00080 }//analyze
00081 
00082 void DuplicationChecker::findValuesAssociatedWithKey(associationMap &mMap, double &key, itemList &theObjects)
00083 {
00084   associationMap::iterator itr;
00085   associationMap::iterator lastElement;
00086         
00087   theObjects.clear();
00088 
00089   // locate an iterator to the first pair object associated with key
00090   itr = mMap.find(key);
00091   if (itr == mMap.end())
00092     return; // no elements associated with key, so return immediately
00093 
00094   // get an iterator to the element that is one past the last element associated with key
00095   lastElement = mMap.upper_bound(key);
00096 
00097   // for each element in the sequence [itr, lastElement)
00098   for ( ; itr != lastElement; ++itr)
00099     theObjects.push_back(itr);
00100 }  
00101 
00102 void DuplicationChecker::endJob()
00103 {
00104 
00105   itemList theObjects;
00106   theObjects.reserve(10);
00107 
00108   for (associationMap::iterator it = xBjorkenHistory.begin(); it != xBjorkenHistory.end(); it++) {
00109     double theKey = (*it).first;
00110 
00111     findValuesAssociatedWithKey(xBjorkenHistory, theKey, theObjects);
00112 
00113     if (theObjects.size() > 1) {
00114       edm::LogWarning("DuplicatedEventFound") << "Duplicated events found with xBjorken = " << std::fixed << std::setw(16) << std::setprecision(14) << theKey; 
00115       for (unsigned int i = 0; i < theObjects.size(); i++) {
00116         edm::LogPrint("DuplicatedEventList") << "Event = " << (*theObjects[i]).second;
00117       }
00118     }
00119 
00120     theObjects.clear();
00121  
00122   }
00123 
00124 }