CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/GeneratorInterface/HiGenCommon/plugins/GenHIEventProducer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    GenHIEventProducer
00004 // Class:      GenHIEventProducer
00005 // 
00013 //
00014 // Original Author:  Yetkin Yilmaz
00015 //         Created:  Thu Aug 13 08:39:51 EDT 2009
00016 // $Id: GenHIEventProducer.cc,v 1.7 2010/08/18 16:45:26 yilmaz Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 #include <memory>
00023 #include <string>
00024 #include <iostream>
00025 
00026 // user include files
00027 #include "FWCore/Framework/interface/Frameworkfwd.h"
00028 #include "FWCore/Framework/interface/EDProducer.h"
00029 #include "FWCore/Framework/interface/EventSetup.h"
00030 
00031 #include "FWCore/Framework/interface/Event.h"
00032 #include "FWCore/Framework/interface/MakerMacros.h"
00033 
00034 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00035 #include "FWCore/Utilities/interface/InputTag.h"
00036 
00037 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
00038 #include "SimDataFormats/HiGenData/interface/GenHIEvent.h"
00039 
00040 #include "HepMC/HeavyIon.h"
00041 #include "FWCore/Framework/interface/ESHandle.h"
00042 #include "SimGeneral/HepPDTRecord/interface/ParticleDataTable.h"
00043 using namespace std;
00044 
00045 //
00046 // class decleration
00047 //
00048 
00049 class GenHIEventProducer : public edm::EDProducer {
00050     public:
00051         explicit GenHIEventProducer(const edm::ParameterSet&);
00052         ~GenHIEventProducer();
00053 
00054     private:
00055         virtual void produce(edm::Event&, const edm::EventSetup&);
00056         std::vector<std::string> hepmcSrc_;
00057         edm::ESHandle < ParticleDataTable > pdt;
00058 
00059   double ptCut_;
00060   bool doParticleInfo_;
00061 };
00062 
00063 //
00064 // constants, enums and typedefs
00065 //
00066 
00067 
00068 //
00069 // static data member definitions
00070 //
00071 
00072 //
00073 // constructors and destructor
00074 //
00075 GenHIEventProducer::GenHIEventProducer(const edm::ParameterSet& iConfig)
00076 {
00077     produces<edm::GenHIEvent>();
00078     hepmcSrc_ = iConfig.getParameter<std::vector<std::string> >("generators");
00079     doParticleInfo_ = iConfig.getUntrackedParameter<bool>("doParticleInfo",false);
00080     if(doParticleInfo_){
00081       ptCut_ = iConfig.getUntrackedParameter<double> ("ptCut",1.);
00082     }
00083 }
00084 
00085 
00086 GenHIEventProducer::~GenHIEventProducer()
00087 {
00088 
00089     // do anything here that needs to be done at desctruction time
00090     // (e.g. close files, deallocate resources etc.)
00091 
00092 }
00093 
00094 
00095 //
00096 // member functions
00097 //
00098 
00099 // ------------ method called to produce the data  ------------
00100     void
00101 GenHIEventProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00102 {
00103     using namespace edm;
00104 
00105     if(!(pdt.isValid())) iSetup.getData(pdt);
00106 
00107     double b = -1;
00108     int npart = -1;
00109     int ncoll = 0;
00110     int nhard = 0;
00111     double phi = 0;
00112     double ecc = -1;
00113 
00114     int nCharged = 0;
00115     int nChargedMR = 0;
00116     int nChargedPtCut = 0; // NchargedPtCut bym
00117     int nChargedPtCutMR = 0; // NchargedPtCutMR bym
00118 
00119     double meanPt = 0;
00120     double meanPtMR = 0;
00121     double EtMR = 0; // Normalized of total energy bym
00122     double TotEnergy = 0; // Total energy bym
00123 
00124     for(size_t ihep = 0; ihep < hepmcSrc_.size(); ++ihep){
00125         Handle<edm::HepMCProduct> hepmc;
00126         iEvent.getByLabel(hepmcSrc_[ihep],hepmc);
00127 
00128         const HepMC::GenEvent* evt = hepmc->GetEvent();
00129         if(doParticleInfo_){
00130           HepMC::GenEvent::particle_const_iterator begin = evt->particles_begin();
00131           HepMC::GenEvent::particle_const_iterator end = evt->particles_end();
00132           for(HepMC::GenEvent::particle_const_iterator it = begin; it != end; ++it){
00133             if((*it)->status() != 1) continue;
00134             int pdg_id = (*it)->pdg_id();
00135             const ParticleData * part = pdt->particle(pdg_id );
00136             int charge = static_cast<int>(part->charge());
00137             
00138             if(charge == 0) continue;
00139             float pt = (*it)->momentum().perp();
00140             float eta = (*it)->momentum().eta();
00141             float energy = (*it)->momentum().e(); // energy bym
00142             //float energy = (*it)->momentum().energy(); // energy bym
00143             nCharged++;
00144             meanPt += pt;
00145             // Get the total energy bym
00146             if(fabs(eta)<1.0){
00147               TotEnergy += energy;
00148             }
00149             if(pt>ptCut_){
00150               nChargedPtCut++;
00151               if(fabs(eta)<0.5){
00152                   nChargedPtCutMR++;
00153                 }
00154             }
00155             // end bym
00156             
00157             if(fabs(eta) > 0.5) continue;
00158             nChargedMR++;
00159             meanPtMR += pt;
00160           }
00161         }
00162         const HepMC::HeavyIon* hi = evt->heavy_ion();
00163 
00164         if(hi){
00165             ncoll = ncoll + hi->Ncoll();
00166             nhard = nhard + hi->Ncoll_hard();
00167             int np = hi->Npart_proj() + hi->Npart_targ();
00168             if(np >= 0){
00169                 npart = np;
00170                 b = hi->impact_parameter();
00171                 phi = hi->event_plane_angle();
00172                 ecc = hi->eccentricity();
00173             }
00174         }
00175     }
00176     // Get the normalized total energy bym
00177     if(TotEnergy != 0){
00178         EtMR = TotEnergy/2;
00179     }
00180 
00181     if(nChargedMR != 0){
00182         meanPtMR /= nChargedMR;
00183     }
00184     if(nCharged != 0){
00185         meanPt /= nCharged;
00186     }
00187 
00188     std::auto_ptr<edm::GenHIEvent> pGenHI(new edm::GenHIEvent(b,
00189                                                               npart,
00190                                                               ncoll,
00191                                                               nhard,
00192                                                               phi, 
00193                                                               ecc,
00194                                                               nCharged,
00195                                                               nChargedMR,
00196                                                               meanPt,
00197                                                               meanPtMR,   
00198                                                               EtMR, 
00199                                                               nChargedPtCut,
00200                                                               nChargedPtCutMR
00201                                                               ));
00202 
00203     iEvent.put(pGenHI);
00204 
00205 }
00206 
00207 //define this as a plug-in
00208 DEFINE_FWK_MODULE(GenHIEventProducer);