CMS 3D CMS Logo

CentralityProducer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    CentralityProducer
00004 // Class:      CentralityProducer
00005 // 
00013 //
00014 // Original Author:  Yetkin Yilmaz, Young Soo Park
00015 //         Created:  Wed Jun 11 15:31:41 CEST 2008
00016 // $Id: CentralityProducer.cc,v 1.2 2008/07/07 15:04:55 yilmaz Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 #include <memory>
00023 #include <iostream>
00024 
00025 // user include files
00026 #include "FWCore/Framework/interface/Frameworkfwd.h"
00027 #include "FWCore/Framework/interface/EDProducer.h"
00028 #include "FWCore/Framework/interface/Event.h"
00029 #include "FWCore/Framework/interface/EventSetup.h"
00030 
00031 #include "FWCore/Framework/interface/MakerMacros.h"
00032 #include "FWCore/Framework/interface/ESHandle.h"
00033 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00034 
00035 #include "DataFormats/Candidate/interface/Candidate.h"
00036 
00037 #include "DataFormats/HeavyIonEvent/interface/Centrality.h"
00038 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
00039 #include "DataFormats/Common/interface/EDProduct.h"
00040 #include "DataFormats/Common/interface/Ref.h"
00041 
00042 #include "SimDataFormats/HepMCProduct/interface/HepMCProduct.h"
00043 #include "HepMC/GenEvent.h"
00044 #include "HepMC/GenParticle.h"
00045 
00046 using namespace std;
00047 
00048 //
00049 // class decleration
00050 //
00051 
00052 class CentralityProducer : public edm::EDProducer {
00053    public:
00054       explicit CentralityProducer(const edm::ParameterSet&);
00055       ~CentralityProducer();
00056 
00057    private:
00058       virtual void beginJob(const edm::EventSetup&) ;
00059       virtual void produce(edm::Event&, const edm::EventSetup&);
00060       virtual void endJob() ;
00061       
00062       // ----------member data ---------------------------
00063 
00064   bool recoLevel_;
00065   bool genLevel_;
00066 
00067 };
00068 
00069 //
00070 // constants, enums and typedefs
00071 //
00072 
00073 
00074 //
00075 // static data member definitions
00076 //
00077 
00078 //
00079 // constructors and destructor
00080 //
00081 CentralityProducer::CentralityProducer(const edm::ParameterSet& iConfig)
00082 {
00083    //register your products
00084   
00085   recoLevel_ = iConfig.getUntrackedParameter<bool>("recoLevel",true);
00086   genLevel_ = iConfig.getUntrackedParameter<bool>("genLevel",true);
00087 
00088   if(recoLevel_){
00089     produces<reco::Centrality>("recoBased");
00090   }
00091   if(genLevel_){
00092     produces<reco::Centrality>("genBased");
00093   }
00094 
00095 }
00096 
00097 
00098 CentralityProducer::~CentralityProducer()
00099 {
00100   
00101   // do anything here that needs to be done at desctruction time
00102   // (e.g. close files, deallocate resources etc.)
00103 
00104 }
00105 
00106 
00107 //
00108 // member functions
00109 //
00110 
00111 // ------------ method called to produce the data  ------------
00112 void
00113 CentralityProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00114 {
00115   using namespace edm;
00116   using namespace reco;
00117    using namespace HepMC;
00118   
00119    const GenEvent* evt;
00120 
00121    double eHF     =  0;        // Variable for computing total HF energy 
00122    double eCASTOR =  0;
00123    double eZDC    =  0;
00124    int cnt = 0;
00125 
00126    if(recoLevel_){
00127      Handle<HFRecHitCollection> hits;
00128      iEvent.getByLabel("hfreco",hits);
00129      for( size_t ihit = 0; ihit<hits->size(); ++ ihit){
00130        const HFRecHit & rechit = (*hits)[ ihit ];
00131        eHF = eHF + rechit.energy();
00132      }
00133      std::auto_ptr<Centrality> centOutput(new Centrality(eHF,eCASTOR,eZDC,cnt));
00134      iEvent.put(centOutput, "recoBased");
00135 
00136      /*
00137      To Do : 
00138      - Add other detectors into reconstruction.
00139      */
00140 
00141    }
00142 
00143    if(genLevel_){
00144      Handle<HepMCProduct> mc;
00145      iEvent.getByLabel("source",mc);   
00146      evt=mc->GetEvent();
00147      
00148      HepMC::GenEvent::particle_const_iterator begin = evt->particles_begin();
00149      HepMC::GenEvent::particle_const_iterator end = evt->particles_end();
00150      for(HepMC::GenEvent::particle_const_iterator it = begin;it!=end;++it)
00151        {
00152          HepMC::GenParticle* p = *it;
00153          float status = p->status();
00154          float pdg_id = p->pdg_id();
00155          float eta = p->momentum().eta();
00156          float phi = p->momentum().phi();
00157          float pt = p->momentum().perp();
00158          float e = p->momentum().e();
00159          
00160          
00161          if(fabs(eta)>=3&&fabs(eta)<=5){
00162            
00163            eHF+=e;
00164          }
00165          if(fabs(eta)>=5.3&&fabs(eta)<=6.7){
00166            
00167            eCASTOR+=e;
00168          }
00169          if(fabs(eta)>=5.9){
00170            if(pdg_id==2112){
00171              
00172              eZDC+=e;
00173              cnt+=1;
00174            }
00175          }    
00176        }
00177      
00178      std::auto_ptr<Centrality> centOutput(new Centrality(eHF,eCASTOR,eZDC,cnt));
00179      iEvent.put(centOutput, "genBased");
00180      
00181    }
00182 }
00183 
00184 // ------------ method called once each job just before starting event loop  ------------
00185 void 
00186 CentralityProducer::beginJob(const edm::EventSetup&)
00187 {
00188 }
00189 
00190 // ------------ method called once each job just after ending the event loop  ------------
00191 void 
00192 CentralityProducer::endJob() {
00193 }
00194 
00195 //define this as a plug-in
00196 DEFINE_FWK_MODULE(CentralityProducer);

Generated on Tue Jun 9 17:43:35 2009 for CMSSW by  doxygen 1.5.4