CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/DQMOffline/Ecal/src/EcalZmassTask.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    Zanalyzer
00004 // Class:      Zanalyzer
00005 // 
00013 //
00014 // Original Author:  Vieri Candelise
00015 //         Created:  Wed May 11 14:53:26 CEST 2011
00016 // $Id: EcalZmassTask.cc,v 1.5 2012/02/28 16:39:18 yiiyama Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 #include <memory>
00023 
00024 // user include files
00025 
00026 #include "DQM/Physics/src/EwkDQM.h"
00027 #include "FWCore/Framework/interface/Frameworkfwd.h"
00028 #include "FWCore/Framework/interface/EDAnalyzer.h"
00029 #include "FWCore/ServiceRegistry/interface/Service.h"
00030 #include "DataFormats/Candidate/interface/Candidate.h"
00031 #include "DataFormats/Common/interface/Handle.h"
00032 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
00033 #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
00034 #include "DataFormats/Math/interface/LorentzVector.h"
00035 #include "TLorentzVector.h"
00036 #include "TMath.h"
00037 #include <string>
00038 #include <cmath>
00039 #include "TH1.h"
00040 #include "DQMServices/Core/interface/DQMStore.h"
00041 #include "DQMServices/Core/interface/MonitorElement.h"
00042 #include "FWCore/Framework/interface/Event.h"
00043 #include "FWCore/Framework/interface/EventSetup.h"
00044 #include "FWCore/Framework/interface/MakerMacros.h"
00045 #include <iostream>
00046 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00047 #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
00048 
00049 class DQMStore;
00050 class MonitorElement;
00051 
00052 class EcalZmassTask: public edm::EDAnalyzer {
00053 
00054 public:
00055   explicit EcalZmassTask (const edm::ParameterSet &);
00056   ~EcalZmassTask ();
00057 
00058   static void fillDescriptions (edm::ConfigurationDescriptions & descriptions);
00059 
00060 private:
00061   virtual void beginJob ();
00062   virtual void analyze (const edm::Event &, const edm::EventSetup &);
00063   virtual void endJob ();
00064 
00065   virtual void beginRun (edm::Run const &, edm::EventSetup const &);
00066   virtual void endRun (edm::Run const &, edm::EventSetup const &);
00067   virtual void beginLuminosityBlock (edm::LuminosityBlock const &, edm::EventSetup const &);
00068   virtual void endLuminosityBlock (edm::LuminosityBlock const &, edm::EventSetup const &);
00069 
00070   const edm::InputTag theElectronCollectionLabel;
00071 
00072   const std::string prefixME_;
00073 
00074   MonitorElement *h_ee_invMass_EB;
00075   MonitorElement *h_ee_invMass_EE;
00076   MonitorElement *h_ee_invMass_BB;
00077   MonitorElement *h_ee_invMass;
00078   MonitorElement *h_e1_et;
00079   MonitorElement *h_e2_et;
00080   MonitorElement *h_e1_eta;
00081   MonitorElement *h_e2_eta;
00082   MonitorElement *h_e1_phi;
00083   MonitorElement *h_e2_phi;
00084   MonitorElement *h_95_ee_invMass_EB;
00085   MonitorElement *h_95_ee_invMass_EE;
00086   MonitorElement *h_95_ee_invMass_BB;
00087 
00088 };
00089 
00090 EcalZmassTask::EcalZmassTask (const edm::ParameterSet & parameters) :
00091   theElectronCollectionLabel(parameters.getParameter < edm::InputTag > ("electronCollection")),
00092   prefixME_(parameters.getUntrackedParameter < std::string > ("prefixME", ""))
00093 {
00094 }
00095 
00096 EcalZmassTask::~EcalZmassTask ()
00097 {
00098 }
00099 
00100 // ------------ method called for each event  ------------
00101 void
00102 EcalZmassTask::analyze (const edm::Event & iEvent,
00103                         const edm::EventSetup & iSetup)
00104 {
00105   using namespace edm;
00106   Handle < reco::GsfElectronCollection > electronCollection;
00107   iEvent.getByLabel (theElectronCollectionLabel, electronCollection);
00108   if (!electronCollection.isValid ()) return;
00109 
00110   //get GSF Tracks
00111   Handle < reco::GsfTrackCollection > gsftracks_h;
00112   iEvent.getByLabel ("electronGsfTracks", gsftracks_h);
00113 
00114   bool isIsolatedBarrel;
00115   bool isIDBarrel;
00116   bool isConvertedBarrel;
00117   bool isIsolatedEndcap;
00118   bool isIDEndcap;
00119   bool isConvertedEndcap;
00120 
00121   int elIsAccepted=0;
00122   int elIsAcceptedEB=0;
00123   int elIsAcceptedEE=0;
00124 
00125   std::vector<TLorentzVector> LV;
00126 
00127   for (reco::GsfElectronCollection::const_iterator recoElectron =
00128          electronCollection->begin ();
00129        recoElectron != electronCollection->end (); recoElectron++)
00130     {
00131 
00132       if (recoElectron->et () <= 25)
00133         continue;
00134 
00135       // Define Isolation variables
00136       double IsoTrk = (recoElectron->dr03TkSumPt () / recoElectron->et ());
00137       double IsoEcal =
00138         (recoElectron->dr03EcalRecHitSumEt () / recoElectron->et ());
00139       double IsoHcal =
00140         (recoElectron->dr03HcalTowerSumEt () / recoElectron->et ());
00141       double HE = (recoElectron->hcalOverEcal ());
00142 
00143       //Define ID variables
00144 
00145       float DeltaPhiTkClu = recoElectron->deltaPhiSuperClusterTrackAtVtx ();
00146       float DeltaEtaTkClu = recoElectron->deltaEtaSuperClusterTrackAtVtx ();
00147       float sigmaIeIe = recoElectron->sigmaIetaIeta ();
00148 
00149       //Define Conversion Rejection Variables
00150 
00151       float Dcot = recoElectron->convDcot ();
00152       float Dist = recoElectron->convDist ();
00153       int NumberOfExpectedInnerHits =
00154         recoElectron->gsfTrack ()->trackerExpectedHitsInner ().
00155         numberOfHits ();
00156 
00157       //quality flags
00158 
00159       isIsolatedBarrel = false;
00160       isIDBarrel = false;
00161       isConvertedBarrel = false;
00162       isIsolatedEndcap = false;
00163       isIDEndcap = false;
00164       isConvertedEndcap = false;
00165 
00166 
00167       /***** Barrel WP80 Cuts *****/
00168 
00169       if (fabs (recoElectron->eta ()) <= 1.4442)
00170         {
00171 
00172           /* Isolation */
00173           if (IsoTrk < 0.09 && IsoEcal < 0.07 && IsoHcal < 0.10)
00174             {
00175               isIsolatedBarrel = true;
00176             }
00177 
00178           /* Identification */
00179           if (fabs (DeltaEtaTkClu) < 0.004 && fabs (DeltaPhiTkClu) < 0.06
00180               && sigmaIeIe < 0.01 && HE < 0.04)
00181             {
00182               isIDBarrel = true;
00183             }
00184 
00185           /* Conversion Rejection */
00186           if ((fabs (Dist) >= 0.02 || fabs (Dcot) >= 0.02)
00187               && NumberOfExpectedInnerHits <= 1.0)
00188             {
00189               isConvertedBarrel = true;
00190             }
00191         }
00192 
00193       if (isIsolatedBarrel && isIDBarrel && isConvertedBarrel) {
00194         elIsAccepted++;
00195         elIsAcceptedEB++;
00196         TLorentzVector b_e2(recoElectron->momentum ().x (),recoElectron->momentum ().y (),recoElectron->momentum ().z (), recoElectron->p ());
00197         LV.push_back(b_e2);
00198       }
00199 
00200       /***** Endcap WP80 Cuts *****/
00201 
00202       if (fabs (recoElectron->eta ()) >= 1.5660
00203           && fabs (recoElectron->eta ()) <= 2.5000)
00204         {
00205 
00206           /* Isolation */
00207           if (IsoTrk < 0.04 && IsoEcal < 0.05 && IsoHcal < 0.025)
00208             {
00209               isIsolatedEndcap = true;
00210             }
00211 
00212           /* Identification */
00213           if (fabs (DeltaEtaTkClu) < 0.007 && fabs (DeltaPhiTkClu) < 0.03
00214               && sigmaIeIe < 0.031 && HE < 0.15)
00215             {
00216               isIDEndcap = true;
00217             }
00218 
00219           /* Conversion Rejection */
00220           if ((fabs (Dcot) > 0.02 || fabs (Dist) > 0.02)
00221               && NumberOfExpectedInnerHits <= 1.0)
00222             {
00223               isConvertedEndcap = true;
00224             }
00225         }
00226       if (isIsolatedEndcap && isIDEndcap && isConvertedEndcap) {
00227         elIsAccepted++;
00228         elIsAcceptedEE++;
00229         TLorentzVector e_e2(recoElectron->momentum ().x (),recoElectron->momentum ().y (),recoElectron->momentum ().z (), recoElectron->p ());
00230         LV.push_back(e_e2);
00231       }
00232 
00233     }
00234 
00235   // Calculate the Z invariant masses
00236 
00237   if (elIsAccepted>1){
00238     double e_ee_invMass=0; 
00239     if (elIsAccepted>2) edm::LogWarning("EcalZmassTask") << "WARNING: In this events we have more than two electrons accpeted!!!!!!!";
00240     if (LV.size()==2){
00241       TLorentzVector e_pair = LV[0] + LV[1];
00242       e_ee_invMass = e_pair.M ();
00243     }  
00244                       
00245     if (elIsAcceptedEB==2){
00246       h_ee_invMass_BB->Fill(e_ee_invMass);
00247     }
00248     if (elIsAcceptedEE==2){
00249       h_ee_invMass_EE->Fill(e_ee_invMass);
00250     }
00251     if (elIsAcceptedEB==1 && elIsAcceptedEE==1){
00252       h_ee_invMass_EB->Fill(e_ee_invMass);
00253     }
00254                       
00255     LV.clear();
00256                                   
00257   }
00258 }
00259 
00260 // ------------ method called once each job just before starting event loop  ------------
00261 void
00262 EcalZmassTask::beginJob ()
00263 {
00264 
00265   DQMStore *theDbe;
00266   std::string logTraceName("EcalZmassTask");
00267 
00268   h_ee_invMass_EB = 0;
00269   h_ee_invMass_EE = 0;
00270   h_ee_invMass_BB = 0;
00271 
00272   LogTrace (logTraceName) << "Parameters initialization";
00273   theDbe = edm::Service < DQMStore > ().operator-> ();
00274 
00275   if (theDbe != 0)
00276     {
00277       theDbe->setCurrentFolder (prefixME_ + "/Zmass");  // Use folder with name of PAG
00278 
00279 
00280       h_ee_invMass_EB =
00281         theDbe->book1D ("Z peak - WP80 EB-EE",
00282                         "Z peak - WP80 EB-EE;InvMass (GeV)", 60, 60.0, 120.0);
00283       h_ee_invMass_EE =
00284         theDbe->book1D ("Z peak - WP80 EE-EE",
00285                         "Z peak - WP80 EE-EE;InvMass (Gev)", 60, 60.0, 120.0);
00286       h_ee_invMass_BB =
00287         theDbe->book1D ("Z peak - WP80 EB-EB",
00288                         "Z peak - WP80 EB-EB;InvMass (Gev)", 60, 60.0, 120.0);
00289     }
00290 }
00291 
00292 // ------------ method called once each job just after ending the event loop  ------------
00293 void
00294 EcalZmassTask::endJob ()
00295 {
00296 }
00297 
00298 // ------------ method called when starting to processes a run  ------------
00299 void
00300 EcalZmassTask::beginRun (edm::Run const &, edm::EventSetup const &)
00301 {
00302 
00303 }
00304 
00305 // ------------ method called when ending the processing of a run  ------------
00306 void
00307 EcalZmassTask::endRun (edm::Run const &, edm::EventSetup const &)
00308 {
00309 }
00310 
00311 // ------------ method called when starting to processes a luminosity block  ------------
00312 void
00313 EcalZmassTask::beginLuminosityBlock (edm::LuminosityBlock const &,
00314                                      edm::EventSetup const &)
00315 {
00316 }
00317 
00318 // ------------ method called when ending the processing of a luminosity block  ------------
00319 void
00320 EcalZmassTask::endLuminosityBlock (edm::LuminosityBlock const &,
00321                                    edm::EventSetup const &)
00322 {
00323 }
00324 
00325 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
00326 void
00327 EcalZmassTask::fillDescriptions (edm::
00328                                  ConfigurationDescriptions & descriptions)
00329 {
00330   //The following says we do not know what parameters are allowed so do no validation
00331   // Please change this to state exactly what you do use, even if it is no parameters
00332   edm::ParameterSetDescription desc;
00333   desc.setUnknown ();
00334   descriptions.addDefault (desc);
00335 }
00336 
00337 //define this as a plug-in
00338 DEFINE_FWK_MODULE (EcalZmassTask);