CMS 3D CMS Logo

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/HepMCProduct/interface/HepMCProduct.h"
00016 
00017 #include <iostream>
00018 #include <memory>
00019 
00020 using std::cout;
00021 using std::endl;
00022 
00023 HectorProducer::HectorProducer(edm::ParameterSet const & parameters): eventsAnalysed(0) {
00024   
00025   
00026   //  produces<edm::HepMCProduct>();
00027   
00028   // TransportHector
00029   
00030   m_InTag          = parameters.getParameter<std::string>("HepMCProductLabel") ;
00031   m_verbosity      = parameters.getParameter<bool>("Verbosity");
00032   m_FP420Transport = parameters.getParameter<bool>("FP420Transport");
00033   m_ZDCTransport   = parameters.getParameter<bool>("ZDCTransport");
00034   
00035   produces<edm::HepMCProduct>();
00036   //  hector = new Hector( parameters );
00037   hector = new Hector(parameters, 
00038                       m_verbosity,
00039                       m_FP420Transport,
00040                       m_ZDCTransport);
00041   
00042   edm::LogInfo ("Hector") << "HectorProducer parameters: \n" 
00043                           << "   Verbosity: " << m_verbosity << "\n"
00044                           << "   m_InTag:    " <<  m_InTag<< "\n"
00045                           << "   m_FP420Transport:    " << m_FP420Transport << "\n"
00046                           << "   m_ZDCTransport:    " << m_ZDCTransport << "\n";
00047 
00048   if(m_verbosity) {
00049     cout << "===================================================================" << endl;  
00050     cout << "=== Start create new HectorProducer                           =====" << endl;
00051     cout << "=== m_InTag: " << m_InTag << endl;
00052     cout << "=== You are going to transport:                               =====" << endl;
00053     cout << "=== FP420: " << m_FP420Transport << endl;
00054     cout << "=== ZDC: " << m_ZDCTransport << endl;
00055     cout << "===================================================================" << endl;
00056   }  
00057 }
00058 
00059 HectorProducer::~HectorProducer(){
00060   
00061   //if ( hector ) delete hector;
00062   
00063   if(m_verbosity) {
00064     cout << "===================================================================" << endl;  
00065     cout << "=== Start delete HectorProducer                               =====" << endl;
00066     cout << "=== Number of events analysed: " << eventsAnalysed << endl;
00067   }
00068   //  delete hector;
00069 
00070    if(m_verbosity) {
00071     cout << "=== DONE                              =====" << endl;
00072     cout << "===================================================================" << endl;  
00073   }
00074  
00075 }
00076 
00077 void HectorProducer::beginJob(const edm::EventSetup & es)
00078 {
00079   //  cout << "HectorProducer::beginJob" << std::endl;
00080   //  cout << "" << std::endl;
00081 }
00082 
00083 void HectorProducer::endJob()
00084 {
00085   //    std::cout << " HectorProducer terminating " << std::endl;
00086 }
00087 
00088 
00089 void HectorProducer::produce(edm::Event & iEvent, const edm::EventSetup & es){
00090   //  cout << "HectorProducer::produce" << std::endl;
00091   using namespace edm;
00092   using namespace std;
00093   //   using namespace HepMC;
00094   //   using namespace CLHEP;
00095   
00096   eventsAnalysed++;
00097   
00098   //   vector< Handle<HepMCProduct> > AllHepMCEvt ;   
00099   //   iEvent.getManyByType( AllHepMCEvt ) ;
00100   Handle<HepMCProduct>  HepMCEvt;   
00101   iEvent.getByLabel( m_InTag, HepMCEvt ) ;
00102   
00103   //   for ( unsigned int i=0; i<HepMCEvt.size(); ++i )
00104   //   {
00105   if ( !HepMCEvt.isValid() )
00106     {
00107       // in principal, should never happen, as it's taken care of bt Framework
00108       throw cms::Exception("InvalidReference")
00109         << "Invalid reference to HepMCProduct\n";
00110     }
00111   
00112   if ( HepMCEvt.provenance()->moduleLabel() == "HectorTrasported" )
00113     {
00114       throw cms::Exception("LogicError")
00115         << "HectorTrasported HepMCProduce already exists\n";
00116     }
00117   
00118   //   }
00119   
00120   evt_ = new HepMC::GenEvent( *HepMCEvt->GetEvent() );
00121   hector->clearApertureFlags();
00122   if(m_FP420Transport) {
00123     hector->clear();
00124     hector->add( evt_ ,es);
00125     hector->filterFP420();
00126   }
00127   if(m_ZDCTransport) {
00128     hector->clear();
00129     hector->add( evt_ ,es);
00130     hector->filterZDC();
00131     
00132     hector->clear();
00133     hector->add( evt_ ,es);
00134     hector->filterD1();
00135   }
00136   evt_ = hector->addPartToHepMC( evt_ );
00137   
00138   // OK, create a product and put in into edm::Event
00139   //
00140   auto_ptr<HepMCProduct> NewProduct(new HepMCProduct()) ;
00141   NewProduct->addHepMCData( evt_ ) ;
00142   
00143   //   iEvent.put( NewProduct, "HectorTrasported" ) ;
00144   iEvent.put( NewProduct ) ;
00145 }
00146 

Generated on Tue Jun 9 17:48:03 2009 for CMSSW by  doxygen 1.5.4