CMS 3D CMS Logo

AlCaDiJetsProducer.cc

Go to the documentation of this file.
00001 #include "Calibration/HcalAlCaRecoProducers/interface/AlCaDiJetsProducer.h"
00002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00003 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00004 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00005 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
00006 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00007 #include "DataFormats/JetReco/interface/CaloJetCollection.h"
00008 #include "FWCore/Utilities/interface/Exception.h"
00009 
00010 using namespace edm;
00011 using namespace std;
00012 using namespace reco;
00013 
00014 namespace cms
00015 {
00016 
00017 AlCaDiJetsProducer::AlCaDiJetsProducer(const edm::ParameterSet& iConfig)
00018 {
00019    jetsInput_ = iConfig.getParameter<edm::InputTag>("jetsInput");
00020    ecalLabels_=iConfig.getParameter<std::vector<edm::InputTag> >("ecalInputs");
00021    hbheInput_ = iConfig.getParameter<edm::InputTag>("hbheInput");
00022    hoInput_ = iConfig.getParameter<edm::InputTag>("hoInput");
00023    hfInput_ = iConfig.getParameter<edm::InputTag>("hfInput"); 
00024    allowMissingInputs_ = true;
00025 
00026 //register your products
00027    produces<CaloJetCollection>("DiJetsBackToBackCollection");
00028    produces<EcalRecHitCollection>("DiJetsEcalRecHitCollection");
00029    produces<HBHERecHitCollection>("DiJetsHBHERecHitCollection");
00030    produces<HORecHitCollection>("DiJetsHORecHitCollection");
00031    produces<HFRecHitCollection>("DiJetsHFRecHitCollection");
00032 
00033 }
00034 void AlCaDiJetsProducer::beginJob( const edm::EventSetup& iSetup)
00035 {
00036 }
00037 
00038 AlCaDiJetsProducer::~AlCaDiJetsProducer()
00039 {
00040  
00041 
00042 }
00043 
00044 
00045 // ------------ method called to produce the data  ------------
00046 void
00047 AlCaDiJetsProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00048 {
00049 
00050   double pi = 4.*atan(1.);
00051 
00052    std::auto_ptr<CaloJetCollection> result (new CaloJetCollection); //Corrected jets
00053    std::auto_ptr<EcalRecHitCollection> miniDiJetsEcalRecHitCollection(new EcalRecHitCollection);
00054    std::auto_ptr<HBHERecHitCollection> miniDiJetsHBHERecHitCollection(new HBHERecHitCollection);
00055    std::auto_ptr<HORecHitCollection> miniDiJetsHORecHitCollection(new HORecHitCollection);
00056    std::auto_ptr<HFRecHitCollection> miniDiJetsHFRecHitCollection(new HFRecHitCollection);
00057 
00058    edm::ESHandle<CaloGeometry> pG;
00059    iSetup.get<CaloGeometryRecord>().get(pG);
00060    const CaloGeometry* geo = pG.product();
00061 
00062   // Jets Collections 
00063 
00064    vector<CaloJet> jetv; 
00065    try {
00066    CaloJet fJet1, fJet2, fJet3;
00067    edm::Handle<CaloJetCollection> jets;                
00068    iEvent.getByLabel(jetsInput_, jets);    
00069    int iflag_select = 0; 
00070    if(jets->size()>1){
00071     fJet1 = (*jets)[0];
00072     fJet2 = (*jets)[1];
00073     double dphi = fabs(fJet1.phi() - fJet2.phi());  
00074     if(dphi > pi){dphi = 2*pi - dphi;}
00075     double degreedphi = dphi*180./pi; 
00076     if(fabs(degreedphi-180)<30.){iflag_select = 1;}
00077    }
00078    if(iflag_select == 1){
00079      result->push_back(fJet1);
00080      result->push_back(fJet2);
00081      jetv.push_back(fJet1); 
00082      jetv.push_back(fJet2); 
00083      if(jets->size()>2){
00084      fJet3 = (*jets)[2]; 
00085      result->push_back(fJet3);
00086      jetv.push_back(fJet3);
00087      }     
00088    } else {
00089      iEvent.put( result, "DiJetsBackToBackCollection");
00090      iEvent.put( miniDiJetsEcalRecHitCollection,"DiJetsEcalRecHitCollection");
00091      iEvent.put( miniDiJetsHBHERecHitCollection, "DiJetsHBHERecHitCollection");
00092      iEvent.put( miniDiJetsHORecHitCollection, "DiJetsHORecHitCollection");
00093      iEvent.put( miniDiJetsHFRecHitCollection, "DiJetsHFRecHitCollection");
00094      return;
00095    }  
00096    } catch (cms::Exception& e) { // can't find it!
00097      if (!allowMissingInputs_) { cout << "No jets collection" << endl; throw e; }  
00098    }
00099 
00100   // Ecal Collections 
00101 
00102    std::vector<edm::InputTag>::const_iterator i;
00103    for (i=ecalLabels_.begin(); i!=ecalLabels_.end(); i++) {
00104    try {
00105    edm::Handle<EcalRecHitCollection> ec;
00106    iEvent.getByLabel(*i,ec);
00107    for(EcalRecHitCollection::const_iterator ecItr = (*ec).begin();
00108                                                  ecItr != (*ec).end(); ++ecItr)
00109         {
00110 // EcalBarrel = 1, EcalEndcap = 2
00111           GlobalPoint pos = geo->getPosition(ecItr->detid());
00112           double phihit = pos.phi();
00113           double etahit = pos.eta();
00114           int iflag_select = 0;  
00115           for(unsigned int i=0; i<jetv.size(); i++){
00116             double deta = fabs(etahit - jetv[i].eta());
00117             double dphi = fabs(phihit - jetv[i].phi());
00118             if(dphi > pi) dphi = 2*pi - dphi;
00119             double dr = sqrt(deta*deta+dphi*dphi);
00120             if(dr < 1.4){iflag_select = 1;}
00121           }  
00122           if(iflag_select==1){miniDiJetsEcalRecHitCollection->push_back(*ecItr);}
00123        }
00124 
00125    } catch (cms::Exception& e) { // can't find it!
00126      if (!allowMissingInputs_) { cout << "No Ecal Collections" << endl; throw e;}
00127    }
00128    }
00129 
00130   // HB & HE Collections 
00131    
00132    try {
00133    edm::Handle<HBHERecHitCollection> hbhe;
00134    iEvent.getByLabel(hbheInput_,hbhe);
00135    for(HBHERecHitCollection::const_iterator hbheItr=hbhe->begin(); 
00136                                                   hbheItr!=hbhe->end(); hbheItr++)
00137         {
00138           GlobalPoint pos = geo->getPosition(hbheItr->detid());
00139           double phihit = pos.phi();
00140           double etahit = pos.eta();
00141           int iflag_select = 0;  
00142           for(unsigned int i=0; i<jetv.size(); i++){
00143             double deta = fabs(etahit - jetv[i].eta());
00144             double dphi = fabs(phihit - jetv[i].phi());
00145             if(dphi > pi) dphi = 2*pi - dphi;
00146             double dr = sqrt(deta*deta+dphi*dphi);
00147             if(dr < 1.4){iflag_select = 1;}
00148           }  
00149           if(iflag_select==1){miniDiJetsHBHERecHitCollection->push_back(*hbheItr);}
00150         }
00151    } catch (cms::Exception& e) { // can't find it!
00152      if (!allowMissingInputs_) {cout<<"No HBHE collection "<<endl; throw e;}
00153    }
00154 
00155 // HO Collections 
00156 
00157    try{  
00158    edm::Handle<HORecHitCollection> ho;
00159    iEvent.getByLabel(hoInput_,ho);
00160    for(HORecHitCollection::const_iterator hoItr=ho->begin(); 
00161                                                 hoItr!=ho->end(); hoItr++)
00162      {
00163           GlobalPoint pos = geo->getPosition(hoItr->detid());
00164           double phihit = pos.phi();
00165           double etahit = pos.eta();
00166           int iflag_select = 0;  
00167           for(unsigned int i=0; i<jetv.size(); i++){
00168             double deta = fabs(etahit - jetv[i].eta());
00169             double dphi = fabs(phihit - jetv[i].phi());
00170             if(dphi > pi) dphi = 2*pi - dphi;
00171             double dr = sqrt(deta*deta+dphi*dphi);
00172             if(dr < 1.4){iflag_select = 1;}
00173           }  
00174           if(iflag_select==1){miniDiJetsHORecHitCollection->push_back(*hoItr);}
00175         }
00176    } catch (cms::Exception& e) { // can't find it!
00177      if (!allowMissingInputs_) {cout<<" No HO collection "<<endl; throw e;}
00178    }
00179 
00180   // HF Collection
00181 
00182    try {
00183    edm::Handle<HFRecHitCollection> hf;
00184    iEvent.getByLabel(hfInput_,hf);
00185    for(HFRecHitCollection::const_iterator hfItr=hf->begin(); 
00186                                                 hfItr!=hf->end(); hfItr++)
00187        {
00188           GlobalPoint pos = geo->getPosition(hfItr->detid());
00189           double phihit = pos.phi();
00190           double etahit = pos.eta();
00191           int iflag_select = 0;  
00192           for(unsigned int i=0; i<jetv.size(); i++){
00193             double deta = fabs(etahit - jetv[i].eta());
00194             double dphi = fabs(phihit - jetv[i].phi());
00195             if(dphi > pi) dphi = 2*pi - dphi;
00196             double dr = sqrt(deta*deta+dphi*dphi);
00197             if(dr < 1.4){iflag_select = 1;}
00198           }  
00199           if(iflag_select==1){miniDiJetsHFRecHitCollection->push_back(*hfItr);}
00200        }
00201    } catch (cms::Exception& e) { // can't find it!
00202      if (!allowMissingInputs_) throw e;
00203    }
00204 
00205   //Put selected information in the event
00206 
00207    iEvent.put( result, "DiJetsBackToBackCollection");
00208    iEvent.put( miniDiJetsEcalRecHitCollection,"DiJetsEcalRecHitCollection");
00209    iEvent.put( miniDiJetsHBHERecHitCollection, "DiJetsHBHERecHitCollection");
00210    iEvent.put( miniDiJetsHORecHitCollection, "DiJetsHORecHitCollection");
00211    iEvent.put( miniDiJetsHFRecHitCollection, "DiJetsHFRecHitCollection");
00212 }
00213 }

Generated on Tue Jun 9 17:25:33 2009 for CMSSW by  doxygen 1.5.4