CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/SimTransport/HectorProducer/src/HectorProducer.cc

Go to the documentation of this file.
00001 // Framework headers
00002 #include "FWCore/Framework/interface/ESHandle.h"
00003 #include "FWCore/ServiceRegistry/interface/Service.h"
00004 // SimpleConfigurable replacement
00005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00006 
00007 // HepMC headers
00008 #include "HepMC/GenEvent.h"
00009 
00010 // Hector headers
00011 #include "SimTransport/HectorProducer/interface/HectorProducer.h"
00012 #include "SimTransport/HectorProducer/interface/Hector.h"
00013 
00014 // SimDataFormats headers
00015 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
00016 #include "SimDataFormats/Forward/interface/LHCTransportLinkContainer.h"
00017 
00018 #include <iostream>
00019 #include <memory>
00020 
00021 using std::cout;
00022 using std::endl;
00023 
00024 HectorProducer::HectorProducer(edm::ParameterSet const & parameters): eventsAnalysed(0) {
00025   
00026   
00027   // TransportHector
00028   
00029   m_InTag          = parameters.getParameter<std::string>("HepMCProductLabel") ;
00030   m_verbosity      = parameters.getParameter<bool>("Verbosity");
00031   m_FP420Transport = parameters.getParameter<bool>("FP420Transport");
00032   m_ZDCTransport   = parameters.getParameter<bool>("ZDCTransport");
00033   
00034   produces<edm::HepMCProduct>();
00035   produces<edm::LHCTransportLinkContainer>();
00036 
00037   hector = new Hector(parameters, 
00038                       m_verbosity,
00039                       m_FP420Transport,
00040                       m_ZDCTransport);
00041   
00042 }
00043 
00044 HectorProducer::~HectorProducer(){
00045   
00046   if(m_verbosity) {
00047     LogDebug("HectorSetup") << "Delete HectorProducer"  
00048                             << "Number of events analysed: " << eventsAnalysed;
00049   }
00050 
00051 }
00052 
00053 void HectorProducer::produce(edm::Event & iEvent, const edm::EventSetup & es){
00054 
00055   using namespace edm;
00056   using namespace std;
00057   
00058   eventsAnalysed++;
00059   
00060   Handle<HepMCProduct>  HepMCEvt;   
00061   iEvent.getByLabel( m_InTag, HepMCEvt ) ;
00062   
00063   if ( !HepMCEvt.isValid() )
00064     {
00065       throw cms::Exception("InvalidReference")
00066         << "Invalid reference to HepMCProduct\n";
00067     }
00068   
00069   if ( HepMCEvt.provenance()->moduleLabel() == "LHCTransport" )
00070     {
00071       throw cms::Exception("LogicError")
00072         << "HectorTrasported HepMCProduce already exists\n";
00073     }
00074 
00075   evt_ = new HepMC::GenEvent( *HepMCEvt->GetEvent() );
00076   hector->clearApertureFlags();
00077   if(m_FP420Transport) {
00078     hector->clear();
00079     hector->add( evt_ ,es);
00080     hector->filterFP420();
00081   }
00082   if(m_ZDCTransport) {
00083     hector->clear();
00084     hector->add( evt_ ,es);
00085     hector->filterZDC();
00086     
00087     hector->clear();
00088     hector->add( evt_ ,es);
00089     hector->filterD1();
00090   }
00091   evt_ = hector->addPartToHepMC( evt_ );
00092   if (m_verbosity) {
00093     evt_->print();
00094   }
00095   
00096   auto_ptr<HepMCProduct> NewProduct(new HepMCProduct()) ;
00097   NewProduct->addHepMCData( evt_ ) ;
00098   
00099   iEvent.put( NewProduct ) ;
00100 
00101   auto_ptr<LHCTransportLinkContainer> NewCorrespondenceMap(new edm::LHCTransportLinkContainer() );
00102   edm::LHCTransportLinkContainer thisLink(hector->getCorrespondenceMap());
00103   (*NewCorrespondenceMap).swap(thisLink);
00104 
00105   if ( m_verbosity ) {
00106     for ( unsigned int i = 0; i < (*NewCorrespondenceMap).size(); i++) 
00107       LogDebug("HectorEventProcessing") << "Hector correspondence table: " << (*NewCorrespondenceMap)[i];
00108   }
00109 
00110   iEvent.put( NewCorrespondenceMap );
00111 
00112 }
00113