CMS 3D CMS Logo

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