CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/Calibration/HcalAlCaRecoProducers/src/ProducerAnalyzer.cc

Go to the documentation of this file.
00001 // system include files
00002 
00003 // user include files
00004 
00005 #include "Calibration/HcalAlCaRecoProducers/src/ProducerAnalyzer.h"
00006 #include "DataFormats/Provenance/interface/Provenance.h"
00007 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
00008 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00009 #include "DataFormats/JetReco/interface/CaloJetCollection.h"
00010 #include "DataFormats/MuonReco/interface/MuonFwd.h"
00011 #include "DataFormats/MuonReco/interface/Muon.h"
00012 #include "TrackingTools/TransientTrack/interface/TransientTrack.h"
00013 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
00014 #include "DataFormats/EgammaReco/interface/SuperClusterFwd.h"
00015 #include "DataFormats/TrackReco/interface/Track.h"
00016 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00017 #include "Geometry/Records/interface/CaloGeometryRecord.h" 
00018 #include "Geometry/CaloGeometry/interface/CaloGeometry.h" 
00019 #include "DataFormats/GeometryVector/interface/GlobalPoint.h" 
00020 #include "DataFormats/HcalCalibObjects/interface/HOCalibVariables.h"
00021 #include "DataFormats/HcalCalibObjects/interface/HOCalibVariableCollection.h"
00022 #include "DataFormats/TrackReco/interface/TrackExtra.h"
00023 #include "DataFormats/TrackReco/interface/TrackExtraFwd.h"
00024 #include "RecoTracker/TrackProducer/interface/TrackProducerBase.h"
00025 
00026 #include <map>
00027 
00028 using namespace std;
00029 using namespace reco;
00030 
00031 namespace cms
00032 {
00033 
00034 //
00035 // constructors and destructor
00036 //
00037 ProducerAnalyzer::ProducerAnalyzer(const edm::ParameterSet& iConfig)
00038 {
00039   // get name of output file with histogramms  
00040    
00041    nameProd_ = iConfig.getUntrackedParameter<std::string>("nameProd");
00042    jetCalo_ = iConfig.getUntrackedParameter<std::string>("jetCalo","GammaJetJetBackToBackCollection");
00043    gammaClus_ = iConfig.getUntrackedParameter<std::string>("gammaClus","GammaJetGammaBackToBackCollection");
00044    ecalInput_=iConfig.getUntrackedParameter<std::string>("ecalInput","GammaJetEcalRecHitCollection");
00045    hbheInput_ = iConfig.getUntrackedParameter<std::string>("hbheInput");
00046    hoInput_ = iConfig.getUntrackedParameter<std::string>("hoInput");
00047    hfInput_ = iConfig.getUntrackedParameter<std::string>("hfInput");
00048    Tracks_ = iConfig.getUntrackedParameter<std::string>("Tracks","GammaJetTracksCollection");    
00049 
00050 }
00051 
00052 ProducerAnalyzer::~ProducerAnalyzer()
00053 {
00054  
00055    // do anything here that needs to be done at desctruction time
00056    // (e.g. close files, deallocate resources etc.)
00057 
00058 }
00059 
00060 void ProducerAnalyzer::beginJob()
00061 {
00062 }
00063 
00064 void ProducerAnalyzer::endJob()
00065 {
00066 }
00067 
00068 
00069 //
00070 // member functions
00071 //
00072 
00073 // ------------ method called to produce the data  ------------
00074 void
00075 ProducerAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00076 {
00077 
00078   using namespace edm;
00079 
00080    const CaloGeometry* geo;
00081    edm::ESHandle<CaloGeometry> pG;
00082    iSetup.get<CaloGeometryRecord>().get(pG);
00083    geo = pG.product();
00084    
00085 
00086   std::vector<Provenance const*> theProvenance;
00087   iEvent.getAllProvenance(theProvenance);
00088   for( std::vector<Provenance const*>::const_iterator ip = theProvenance.begin();
00089                                                       ip != theProvenance.end(); ip++)
00090   {
00091      cout<<" Print all module/label names "<<(**ip).moduleName()<<" "<<(**ip).moduleLabel()<<
00092      " "<<(**ip).productInstanceName()<<endl;
00093   }
00094   
00095   
00096   if(nameProd_ == "hoCalibProducer")
00097   {
00098      edm::Handle<HOCalibVariableCollection> ho;
00099      iEvent.getByLabel(nameProd_,hoInput_, ho);
00100      const HOCalibVariableCollection Hitho = *(ho.product());
00101      std::cout<<" Size of HO "<<(Hitho).size()<<std::endl;
00102   }
00103   
00104    if(nameProd_ == "ALCARECOMuAlZMuMu" )
00105    {
00106    
00107    edm::Handle<HORecHitCollection> ho;
00108    iEvent.getByLabel("horeco", ho);
00109    const HORecHitCollection Hitho = *(ho.product());
00110    std::cout<<" Size of HO "<<(Hitho).size()<<std::endl;
00111    edm::Handle<MuonCollection> mucand;
00112    iEvent.getByLabel(nameProd_,"SelectedMuons", mucand);
00113    std::cout<<" Size of muon collection "<<mucand->size()<<std::endl;
00114    for(MuonCollection::const_iterator it =  mucand->begin(); it != mucand->end(); it++)
00115    {
00116       TrackRef mu = (*it).combinedMuon();
00117       std::cout<<" Pt muon "<<mu->innerMomentum()<<std::endl;
00118    }
00119    
00120    }  
00121   
00122    if(nameProd_ != "IsoProd" && nameProd_ != "ALCARECOMuAlZMuMu" && nameProd_ != "hoCalibProducer")
00123    {
00124    edm::Handle<HBHERecHitCollection> hbhe;
00125    iEvent.getByLabel(hbheInput_, hbhe);
00126    const HBHERecHitCollection Hithbhe = *(hbhe.product());
00127    std::cout<<" Size of HBHE "<<(Hithbhe).size()<<std::endl;
00128 
00129 
00130    edm::Handle<HORecHitCollection> ho;
00131    iEvent.getByLabel(hoInput_, ho);
00132    const HORecHitCollection Hitho = *(ho.product());
00133    std::cout<<" Size of HO "<<(Hitho).size()<<std::endl;
00134 
00135 
00136    edm::Handle<HFRecHitCollection> hf;
00137    iEvent.getByLabel(hfInput_, hf);
00138    const HFRecHitCollection Hithf = *(hf.product());
00139    std::cout<<" Size of HF "<<(Hithf).size()<<std::endl;
00140    }
00141    if(nameProd_ == "IsoProd")
00142    {
00143    cout<<" We are here "<<endl;
00144    edm::Handle<reco::TrackCollection> tracks;
00145    iEvent.getByLabel(nameProd_,Tracks_,tracks);
00146  
00147    
00148    std::cout<<" Tracks size "<<(*tracks).size()<<std::endl;
00149    reco::TrackCollection::const_iterator track = tracks->begin ();
00150 
00151           for (; track != tracks->end (); track++)
00152          {
00153            cout<<" P track "<<(*track).p()<<" eta "<<(*track).eta()<<" phi "<<(*track).phi()<<" Outer "<<(*track).outerMomentum()<<" "<<
00154            (*track).outerPosition()<<endl;
00155            TrackExtraRef myextra = (*track).extra();
00156            cout<<" Track extra "<<myextra->outerMomentum()<<" "<<myextra->outerPosition()<<endl;
00157          }  
00158 
00159    edm::Handle<EcalRecHitCollection> ecal;
00160    iEvent.getByLabel(nameProd_,ecalInput_,ecal);
00161    const EcalRecHitCollection Hitecal = *(ecal.product());
00162    std::cout<<" Size of Ecal "<<(Hitecal).size()<<std::endl;
00163    EcalRecHitCollection::const_iterator hite = (ecal.product())->begin ();
00164 
00165          double energyECAL = 0.;
00166          double energyHCAL = 0.;
00167 
00168           for (; hite != (ecal.product())->end (); hite++)
00169          {
00170 
00171 //           cout<<" Energy ECAL "<<(*hite).energy()<<endl;
00172 
00173 
00174 //         " eta "<<(*hite).detid()<<" phi "<<(*hite).detid().getPosition().phi()<<endl;
00175 
00176          GlobalPoint posE = geo->getPosition((*hite).detid());
00177 
00178            cout<<" Energy ECAL "<<(*hite).energy()<<
00179            " eta "<<posE.eta()<<" phi "<<posE.phi()<<endl;
00180 
00181          energyECAL = energyECAL + (*hite).energy();
00182          
00183          }
00184 
00185    edm::Handle<HBHERecHitCollection> hbhe;
00186    iEvent.getByLabel(nameProd_,hbheInput_,hbhe);
00187    const HBHERecHitCollection Hithbhe = *(hbhe.product());
00188    std::cout<<" Size of HBHE "<<(Hithbhe).size()<<std::endl;
00189    HBHERecHitCollection::const_iterator hith = (hbhe.product())->begin ();
00190 
00191           for (; hith != (hbhe.product())->end (); hith++)
00192          {
00193 
00194          GlobalPoint posH = geo->getPosition((*hith).detid());
00195 
00196            cout<<" Energy HCAL "<<(*hith).energy()<<
00197            " eta "<<posH.eta()<<" phi "<<posH.phi()<<endl;
00198 
00199          energyHCAL = energyHCAL + (*hith).energy();
00200          
00201          }
00202    
00203    cout<<" Energy ECAL "<< energyECAL<<" Energy HCAL "<< energyHCAL<<endl;
00204    
00205    edm::Handle<HORecHitCollection> ho;
00206    iEvent.getByLabel(nameProd_,hoInput_,ho);
00207    const HORecHitCollection Hitho = *(ho.product());
00208    std::cout<<" Size of HO "<<(Hitho).size()<<std::endl;
00209    HORecHitCollection::const_iterator hito = (ho.product())->begin ();
00210 
00211           for (; hito != (ho.product())->end (); hito++)
00212          {
00213 //           cout<<" Energy HO    "<<(*hito).energy()<<endl;
00214 //         " eta "<<(*hite).eta()<<" phi "<<(*hite).phi()<<endl;
00215          }
00216 
00217    }
00218    
00219    
00220    if(nameProd_ == "GammaJetProd" || nameProd_ == "DiJProd")
00221    {
00222     cout<<" we are in GammaJetProd area "<<endl;
00223    edm::Handle<EcalRecHitCollection> ecal;
00224    iEvent.getByLabel(nameProd_,ecalInput_, ecal);
00225    std::cout<<" Size of ECAL "<<(*ecal).size()<<std::endl;
00226 
00227    edm::Handle<reco::CaloJetCollection> jets;
00228    iEvent.getByLabel(nameProd_,jetCalo_, jets);
00229    std::cout<<" Jet size "<<(*jets).size()<<std::endl; 
00230    reco::CaloJetCollection::const_iterator jet = jets->begin ();
00231           for (; jet != jets->end (); jet++)
00232          {
00233            cout<<" Et jet "<<(*jet).et()<<" eta "<<(*jet).eta()<<" phi "<<(*jet).phi()<<endl;
00234          }  
00235 
00236    edm::Handle<reco::TrackCollection> tracks;
00237    iEvent.getByLabel(nameProd_,Tracks_, tracks);
00238    std::cout<<" Tracks size "<<(*tracks).size()<<std::endl; 
00239    }
00240    if( nameProd_ == "GammaJetProd")
00241    {
00242    edm::Handle<reco::SuperClusterCollection> eclus;
00243    iEvent.getByLabel(nameProd_,gammaClus_, eclus);
00244    std::cout<<" GammaClus size "<<(*eclus).size()<<std::endl;
00245       reco::SuperClusterCollection::const_iterator iclus = eclus->begin ();
00246           for (; iclus != eclus->end (); iclus++)
00247          {
00248            cout<<" Et gamma "<<(*iclus).energy()/cosh((*iclus).eta())<<" eta "<<(*iclus).eta()<<" phi "<<(*iclus).phi()<<endl;
00249          }
00250    }
00251 
00252 }
00253 //define this as a plug-in
00254 //DEFINE_FWK_MODULE(ProducerAnalyzer)
00255 }