CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/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.4 2012/01/30 09:11:07 eulisse 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 "CommonTools/UtilAlgos/interface/TFileService.h"
00040 #include "TH1.h"
00041 #include "DQMServices/Core/interface/DQMStore.h"
00042 #include "DQMServices/Core/interface/MonitorElement.h"
00043 #include "FWCore/Framework/interface/Event.h"
00044 #include "FWCore/Framework/interface/EventSetup.h"
00045 #include "FWCore/Framework/interface/MakerMacros.h"
00046 #include <iostream>
00047 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00048 #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
00049 
00050 class DQMStore;
00051 class MonitorElement;
00052 
00053 class
00054   EcalZmassTask:
00055   public
00056   edm::EDAnalyzer
00057 {
00058 public:
00059   explicit
00060   EcalZmassTask (const edm::ParameterSet &);
00061    ~
00062   EcalZmassTask ();
00063 
00064   static void
00065   fillDescriptions (edm::ConfigurationDescriptions & descriptions);
00066 
00067 private:
00068   virtual void
00069   beginJob ();
00070   virtual void
00071   analyze (const edm::Event &, const edm::EventSetup &);
00072   virtual void
00073   endJob ();
00074 
00075   virtual void
00076   beginRun (edm::Run const &, edm::EventSetup const &);
00077   virtual void
00078   endRun (edm::Run const &, edm::EventSetup const &);
00079   virtual void
00080   beginLuminosityBlock (edm::LuminosityBlock const &,
00081                         edm::EventSetup const &);
00082   virtual void
00083   endLuminosityBlock (edm::LuminosityBlock const &, edm::EventSetup const &);
00084 
00085   std::string prefixME_;
00086 
00087   edm::InputTag
00088     theElectronCollectionLabel;
00089 
00090   MonitorElement *
00091     h_ee_invMass_EB;
00092   MonitorElement *
00093     h_ee_invMass_EE;
00094   MonitorElement *
00095     h_ee_invMass_BB;
00096   MonitorElement *
00097     h_ee_invMass;
00098   MonitorElement *
00099     h_e1_et;
00100   MonitorElement *
00101     h_e2_et;
00102   MonitorElement *
00103     h_e1_eta;
00104   MonitorElement *
00105     h_e2_eta;
00106   MonitorElement *
00107     h_e1_phi;
00108   MonitorElement *
00109     h_e2_phi;
00110   MonitorElement *
00111     h_95_ee_invMass_EB;
00112   MonitorElement *
00113     h_95_ee_invMass_EE;
00114   MonitorElement *
00115     h_95_ee_invMass_BB;
00116 
00117 };
00118 
00119 EcalZmassTask::EcalZmassTask (const edm::ParameterSet & parameters)
00120 {
00121   prefixME_ = parameters.getUntrackedParameter < std::string > ("prefixME", "");
00122   theElectronCollectionLabel =
00123     parameters.getParameter < edm::InputTag > ("electronCollection");
00124 
00125 }
00126 
00127 
00128 
00129 EcalZmassTask::~EcalZmassTask ()
00130 {
00131 
00132   // do anything here that needs to be done at desctruction time
00133   // (e.g. close files, deallocate resources etc.)
00134 
00135 }
00136 
00137 
00138 
00139 
00140 //
00141 // member functions
00142 //
00143 
00144 // ------------ method called for each event  ------------
00145 void
00146 EcalZmassTask::analyze (const edm::Event & iEvent,
00147                         const edm::EventSetup & iSetup)
00148 {
00149 
00150   using namespace edm;
00151   Handle < reco::GsfElectronCollection > electronCollection;
00152   iEvent.getByLabel (theElectronCollectionLabel, electronCollection);
00153   if (!electronCollection.isValid ())
00154     return;
00155 
00156   //get GSF Tracks
00157   Handle < reco::GsfTrackCollection > gsftracks_h;
00158   iEvent.getByLabel ("electronGsfTracks", gsftracks_h);
00159 
00160   bool isIsolatedBarrel;
00161   bool isIDBarrel;
00162   bool isConvertedBarrel;
00163   bool isIsolatedEndcap;
00164   bool isIDEndcap;
00165   bool isConvertedEndcap;
00166 
00167   int elIsAccepted=0;
00168   int elIsAcceptedEB=0;
00169   int elIsAcceptedEE=0;
00170 
00171   std::vector<TLorentzVector> LV;
00172 
00173   for (reco::GsfElectronCollection::const_iterator recoElectron =
00174        electronCollection->begin ();
00175        recoElectron != electronCollection->end (); recoElectron++)
00176     {
00177 
00178       if (recoElectron->et () <= 25)
00179         continue;
00180 
00181       // Define Isolation variables
00182       double IsoTrk = (recoElectron->dr03TkSumPt () / recoElectron->et ());
00183       double IsoEcal =
00184         (recoElectron->dr03EcalRecHitSumEt () / recoElectron->et ());
00185       double IsoHcal =
00186         (recoElectron->dr03HcalTowerSumEt () / recoElectron->et ());
00187       double HE = (recoElectron->hcalOverEcal ());
00188 
00189       //Define ID variables
00190 
00191       float DeltaPhiTkClu = recoElectron->deltaPhiSuperClusterTrackAtVtx ();
00192       float DeltaEtaTkClu = recoElectron->deltaEtaSuperClusterTrackAtVtx ();
00193       float sigmaIeIe = recoElectron->sigmaIetaIeta ();
00194 
00195       //Define Conversion Rejection Variables
00196 
00197       float Dcot = recoElectron->convDcot ();
00198       float Dist = recoElectron->convDist ();
00199       int NumberOfExpectedInnerHits =
00200         recoElectron->gsfTrack ()->trackerExpectedHitsInner ().
00201         numberOfHits ();
00202 
00203       //quality flags
00204 
00205       isIsolatedBarrel = false;
00206       isIDBarrel = false;
00207       isConvertedBarrel = false;
00208       isIsolatedEndcap = false;
00209       isIDEndcap = false;
00210       isConvertedEndcap = false;
00211 
00212 
00213   /***** Barrel WP80 Cuts *****/
00214 
00215       if (fabs (recoElectron->eta ()) <= 1.4442)
00216         {
00217 
00218           /* Isolation */
00219           if (IsoTrk < 0.09 && IsoEcal < 0.07 && IsoHcal < 0.10)
00220             {
00221               isIsolatedBarrel = true;
00222             }
00223 
00224           /* Identification */
00225           if (fabs (DeltaEtaTkClu) < 0.004 && fabs (DeltaPhiTkClu) < 0.06
00226               && sigmaIeIe < 0.01 && HE < 0.04)
00227             {
00228               isIDBarrel = true;
00229             }
00230 
00231           /* Conversion Rejection */
00232           if ((fabs (Dist) >= 0.02 || fabs (Dcot) >= 0.02)
00233               && NumberOfExpectedInnerHits <= 1.0)
00234             {
00235               isConvertedBarrel = true;
00236             }
00237         }
00238 
00239             if (isIsolatedBarrel && isIDBarrel && isConvertedBarrel) {
00240                 elIsAccepted++;
00241                 elIsAcceptedEB++;
00242                 TLorentzVector b_e2(recoElectron->momentum ().x (),recoElectron->momentum ().y (),recoElectron->momentum ().z (), recoElectron->p ());
00243                 LV.push_back(b_e2);
00244               }
00245 
00246   /***** Endcap WP80 Cuts *****/
00247 
00248       if (fabs (recoElectron->eta ()) >= 1.5660
00249           && fabs (recoElectron->eta ()) <= 2.5000)
00250         {
00251 
00252           /* Isolation */
00253           if (IsoTrk < 0.04 && IsoEcal < 0.05 && IsoHcal < 0.025)
00254             {
00255               isIsolatedEndcap = true;
00256             }
00257 
00258           /* Identification */
00259           if (fabs (DeltaEtaTkClu) < 0.007 && fabs (DeltaPhiTkClu) < 0.03
00260               && sigmaIeIe < 0.031 && HE < 0.15)
00261             {
00262               isIDEndcap = true;
00263             }
00264 
00265           /* Conversion Rejection */
00266           if ((fabs (Dcot) > 0.02 || fabs (Dist) > 0.02)
00267               && NumberOfExpectedInnerHits <= 1.0)
00268             {
00269               isConvertedEndcap = true;
00270             }
00271         }
00272          if (isIsolatedEndcap && isIDEndcap && isConvertedEndcap) {
00273                 elIsAccepted++;
00274                 elIsAcceptedEE++;
00275                 TLorentzVector e_e2(recoElectron->momentum ().x (),recoElectron->momentum ().y (),recoElectron->momentum ().z (), recoElectron->p ());
00276                 LV.push_back(e_e2);
00277             }
00278 
00279   }
00280 
00281   // Calculate the Z invariant masses
00282 
00283           if (elIsAccepted>1){
00284              double e_ee_invMass=0; 
00285              if (elIsAccepted>2) edm::LogWarning("EwkAnalyzer") << "WARNING: In this events we have more than two electrons accpeted!!!!!!!";
00286              if (LV.size()==2){
00287                       TLorentzVector e_pair = LV[0] + LV[1];
00288                       e_ee_invMass = e_pair.M ();
00289              }  
00290                       
00291              if (elIsAcceptedEB==2){
00292                       h_ee_invMass_BB->Fill(e_ee_invMass);
00293                }
00294              if (elIsAcceptedEE==2){
00295                       h_ee_invMass_EE->Fill(e_ee_invMass);
00296                }
00297              if (elIsAcceptedEB==1 && elIsAcceptedEE==1){
00298                       h_ee_invMass_EB->Fill(e_ee_invMass);
00299                }
00300                       
00301             LV.clear();
00302                                   
00303          }
00304 }
00305 
00306 // ------------ method called once each job just before starting event loop  ------------
00307 void
00308 EcalZmassTask::beginJob ()
00309 {
00310 
00311   DQMStore *theDbe;
00312 
00313   h_ee_invMass_EB = 0;
00314   h_ee_invMass_EE = 0;
00315   h_ee_invMass_BB = 0;
00316 
00317 
00318   LogTrace ("EwkAnalyzer") << "Parameters initialization";
00319   theDbe = edm::Service < DQMStore > ().operator-> ();
00320 
00321   if (theDbe != 0)
00322     {
00323       theDbe->setCurrentFolder (prefixME_ + "/Zmass");  // Use folder with name of PAG
00324 
00325 
00326       h_ee_invMass_EB =
00327         theDbe->book1D ("Z peak - WP80 EB-EE",
00328                         "Z peak - WP80 EB-EE;InvMass (GeV)", 60, 60.0, 120.0);
00329       h_ee_invMass_EE =
00330         theDbe->book1D ("Z peak - WP80 EE-EE",
00331                         "Z peak - WP80 EE-EE;InvMass (Gev)", 60, 60.0, 120.0);
00332       h_ee_invMass_BB =
00333         theDbe->book1D ("Z peak - WP80 EB-EB",
00334                         "Z peak - WP80 EB-EB;InvMass (Gev)", 60, 60.0, 120.0);
00335     }
00336 }
00337 
00338 // ------------ method called once each job just after ending the event loop  ------------
00339 void
00340 EcalZmassTask::endJob ()
00341 {
00342 }
00343 
00344 // ------------ method called when starting to processes a run  ------------
00345 void
00346 EcalZmassTask::beginRun (edm::Run const &, edm::EventSetup const &)
00347 {
00348 
00349 }
00350 
00351 // ------------ method called when ending the processing of a run  ------------
00352 void
00353 EcalZmassTask::endRun (edm::Run const &, edm::EventSetup const &)
00354 {
00355 }
00356 
00357 // ------------ method called when starting to processes a luminosity block  ------------
00358 void
00359 EcalZmassTask::beginLuminosityBlock (edm::LuminosityBlock const &,
00360                                      edm::EventSetup const &)
00361 {
00362 }
00363 
00364 // ------------ method called when ending the processing of a luminosity block  ------------
00365 void
00366 EcalZmassTask::endLuminosityBlock (edm::LuminosityBlock const &,
00367                                    edm::EventSetup const &)
00368 {
00369 }
00370 
00371 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
00372 void
00373 EcalZmassTask::fillDescriptions (edm::
00374                                  ConfigurationDescriptions & descriptions)
00375 {
00376   //The following says we do not know what parameters are allowed so do no validation
00377   // Please change this to state exactly what you do use, even if it is no parameters
00378   edm::ParameterSetDescription desc;
00379   desc.setUnknown ();
00380   descriptions.addDefault (desc);
00381 }
00382 
00383 //define this as a plug-in
00384 DEFINE_FWK_MODULE (EcalZmassTask);