CMS 3D CMS Logo

CMSSW_4_4_3_patch1/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.2 2011/07/28 10:03:01 vieri 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 using namespace std;
00051 using namespace edm;
00052 using namespace reco;
00053 
00054 
00055 class DQMStore;
00056 class MonitorElement;
00057 
00058 std::string prefixME_;
00059 
00060 class
00061   EcalZmassTask:
00062   public
00063   edm::EDAnalyzer
00064 {
00065 public:
00066   explicit
00067   EcalZmassTask (const edm::ParameterSet &);
00068    ~
00069   EcalZmassTask ();
00070 
00071   static void
00072   fillDescriptions (edm::ConfigurationDescriptions & descriptions);
00073 
00074 private:
00075   virtual void
00076   beginJob ();
00077   virtual void
00078   analyze (const edm::Event &, const edm::EventSetup &);
00079   virtual void
00080   endJob ();
00081 
00082   virtual void
00083   beginRun (edm::Run const &, edm::EventSetup const &);
00084   virtual void
00085   endRun (edm::Run const &, edm::EventSetup const &);
00086   virtual void
00087   beginLuminosityBlock (edm::LuminosityBlock const &,
00088                         edm::EventSetup const &);
00089   virtual void
00090   endLuminosityBlock (edm::LuminosityBlock const &, edm::EventSetup const &);
00091 
00092 
00093 
00094 
00095 
00096 //
00097 // constants, enums and typedefs
00098 //
00099 
00100 //
00101 // static data member definitions
00102 //
00103 
00104 //
00105 // constructors and destructor
00106 //
00107 
00108   edm::InputTag
00109     theElectronCollectionLabel;
00110 
00111   MonitorElement *
00112     h_ee_invMass_EB;
00113   MonitorElement *
00114     h_ee_invMass_EE;
00115   MonitorElement *
00116     h_ee_invMass_BB;
00117   MonitorElement *
00118     h_ee_invMass;
00119   MonitorElement *
00120     h_e1_et;
00121   MonitorElement *
00122     h_e2_et;
00123   MonitorElement *
00124     h_e1_eta;
00125   MonitorElement *
00126     h_e2_eta;
00127   MonitorElement *
00128     h_e1_phi;
00129   MonitorElement *
00130     h_e2_phi;
00131   MonitorElement *
00132     h_95_ee_invMass_EB;
00133   MonitorElement *
00134     h_95_ee_invMass_EE;
00135   MonitorElement *
00136     h_95_ee_invMass_BB;
00137 
00138 };
00139 
00140 EcalZmassTask::EcalZmassTask (const edm::ParameterSet & parameters)
00141 {
00142   prefixME_ = parameters.getUntrackedParameter < string > ("prefixME", "");
00143   theElectronCollectionLabel =
00144     parameters.getParameter < InputTag > ("electronCollection");
00145 
00146 }
00147 
00148 
00149 
00150 EcalZmassTask::~EcalZmassTask ()
00151 {
00152 
00153   // do anything here that needs to be done at desctruction time
00154   // (e.g. close files, deallocate resources etc.)
00155 
00156 }
00157 
00158 
00159 
00160 
00161 //
00162 // member functions
00163 //
00164 
00165 // ------------ method called for each event  ------------
00166 void
00167 EcalZmassTask::analyze (const edm::Event & iEvent,
00168                         const edm::EventSetup & iSetup)
00169 {
00170 
00171   LogTrace (logTraceName) << "Analysis of event # ";
00172 
00173   using namespace edm;
00174   Handle < GsfElectronCollection > electronCollection;
00175   iEvent.getByLabel (theElectronCollectionLabel, electronCollection);
00176   if (!electronCollection.isValid ())
00177     return;
00178 
00179   //get GSF Tracks
00180   Handle < reco::GsfTrackCollection > gsftracks_h;
00181   iEvent.getByLabel ("electronGsfTracks", gsftracks_h);
00182 
00183 /*
00184   // Find the highest and 2nd highest electron in the barrel/endcap that will be selected with WP95
00185 
00186   float b_95_electron_et = -8.0;
00187   float b_95_electron_eta = -8.0;
00188   float b_95_electron_phi = -8.0;
00189   float b_95_electron2_et = -9.0;
00190   float b_95_electron2_eta = -9.0;
00191   float b_95_electron2_phi = -9.0;
00192   float b_95_ee_invMass = -9.0;
00193   TLorentzVector b_95_e1, b_95_e2;
00194 
00195   float e_95_electron_et = -8.0;
00196   float e_95_electron_eta = -8.0;
00197   float e_95_electron_phi = -8.0;
00198   float e_95_electron2_et = -9.0;
00199   float e_95_electron2_eta = -9.0;
00200   float e_95_electron2_phi = -9.0;
00201   float e_95_ee_invMass = -9.0;
00202   TLorentzVector e_95_e1, e_95_e2;
00203 
00204   float eb_95_electron_et = -8.0;
00205   float eb_95_electron_eta = -8.0;
00206   float eb_95_electron_phi = -8.0;
00207   float eb_95_electron2_et = -9.0;
00208   float eb_95_electron2_eta = -9.0;
00209   float eb_95_electron2_phi = -9.0;
00210   float eb_95_ee_invMass = -9.0;
00211   TLorentzVector eb_95_e1, eb_95_e2;
00212   
00213   float be_95_electron_et = -8.0;                       
00214   float be_95_electron_eta = -8.0;
00215   float be_95_electron_phi = -8.0;
00216   float be_95_electron2_et = -9.0;
00217   float be_95_electron2_eta = -9.0;
00218   float be_95_electron2_phi = -9.0;
00219   float be_95_ee_invMass = -9.0;
00220   TLorentzVector be_95_e1, be_95_e2;
00221 */
00222 
00223   bool isBarrelElectrons;
00224   bool isEndcapElectrons;
00225   bool isIsolatedBarrel;
00226   bool isIDBarrel;
00227   bool isConvertedBarrel;
00228   bool isIsolatedEndcap;
00229   bool isIDEndcap;
00230   bool isConvertedEndcap;
00231 
00232   int elIsAccepted=0;
00233   int elIsAcceptedEB=0;
00234   int elIsAcceptedEE=0;
00235 
00236   std::vector<TLorentzVector> LV;
00237 
00238   for (reco::GsfElectronCollection::const_iterator recoElectron =
00239        electronCollection->begin ();
00240        recoElectron != electronCollection->end (); recoElectron++)
00241     {
00242 
00243       if (recoElectron->et () <= 25)
00244         continue;
00245 
00246       // Define Isolation variables
00247       double IsoTrk = (recoElectron->dr03TkSumPt () / recoElectron->et ());
00248       double IsoEcal =
00249         (recoElectron->dr03EcalRecHitSumEt () / recoElectron->et ());
00250       double IsoHcal =
00251         (recoElectron->dr03HcalTowerSumEt () / recoElectron->et ());
00252       double HE = (recoElectron->hcalOverEcal ());
00253 
00254       //Define ID variables
00255 
00256       float DeltaPhiTkClu = recoElectron->deltaPhiSuperClusterTrackAtVtx ();
00257       float DeltaEtaTkClu = recoElectron->deltaEtaSuperClusterTrackAtVtx ();
00258       float sigmaIeIe = recoElectron->sigmaIetaIeta ();
00259 
00260       //Define Conversion Rejection Variables
00261 
00262       float Dcot = recoElectron->convDcot ();
00263       float Dist = recoElectron->convDist ();
00264       int NumberOfExpectedInnerHits =
00265         recoElectron->gsfTrack ()->trackerExpectedHitsInner ().
00266         numberOfHits ();
00267 
00268       //quality flags
00269 
00270       isBarrelElectrons = false;
00271       isEndcapElectrons = false;
00272       isIsolatedBarrel = false;
00273       isIDBarrel = false;
00274       isConvertedBarrel = false;
00275       isIsolatedEndcap = false;
00276       isIDEndcap = false;
00277       isConvertedEndcap = false;
00278 
00279 
00280   /***** Barrel WP80 Cuts *****/
00281 
00282       if (fabs (recoElectron->eta ()) <= 1.4442)
00283         {
00284 
00285           /* Isolation */
00286           if (IsoTrk < 0.09 && IsoEcal < 0.07 && IsoHcal < 0.10)
00287             {
00288               isIsolatedBarrel = true;
00289             }
00290 
00291           /* Identification */
00292           if (fabs (DeltaEtaTkClu) < 0.004 && fabs (DeltaPhiTkClu) < 0.06
00293               && sigmaIeIe < 0.01 && HE < 0.04)
00294             {
00295               isIDBarrel = true;
00296             }
00297 
00298           /* Conversion Rejection */
00299           if ((fabs (Dist) >= 0.02 || fabs (Dcot) >= 0.02)
00300               && NumberOfExpectedInnerHits <= 1.0)
00301             {
00302               isConvertedBarrel = true;
00303             }
00304         }
00305 
00306             if (isIsolatedBarrel && isIDBarrel && isConvertedBarrel) {
00307                 elIsAccepted++;
00308                 elIsAcceptedEB++;
00309                 TLorentzVector b_e2(recoElectron->momentum ().x (),recoElectron->momentum ().y (),recoElectron->momentum ().z (), recoElectron->p ());
00310                 LV.push_back(b_e2);
00311               }
00312 
00313   /***** Endcap WP80 Cuts *****/
00314 
00315       if (fabs (recoElectron->eta ()) >= 1.5660
00316           && fabs (recoElectron->eta ()) <= 2.5000)
00317         {
00318 
00319           /* Isolation */
00320           if (IsoTrk < 0.04 && IsoEcal < 0.05 && IsoHcal < 0.025)
00321             {
00322               isIsolatedEndcap = true;
00323             }
00324 
00325           /* Identification */
00326           if (fabs (DeltaEtaTkClu) < 0.007 && fabs (DeltaPhiTkClu) < 0.03
00327               && sigmaIeIe < 0.031 && HE < 0.15)
00328             {
00329               isIDEndcap = true;
00330             }
00331 
00332           /* Conversion Rejection */
00333           if ((fabs (Dcot) > 0.02 || fabs (Dist) > 0.02)
00334               && NumberOfExpectedInnerHits <= 1.0)
00335             {
00336               isConvertedEndcap = true;
00337             }
00338         }
00339          if (isIsolatedEndcap && isIDEndcap && isConvertedEndcap) {
00340                 elIsAccepted++;
00341                 elIsAcceptedEE++;
00342                 TLorentzVector e_e2(recoElectron->momentum ().x (),recoElectron->momentum ().y (),recoElectron->momentum ().z (), recoElectron->p ());
00343                 LV.push_back(e_e2);
00344             }
00345 
00346   }
00347 
00348   // Calculate the Z invariant masses
00349 
00350           if (elIsAccepted>1){
00351              double e_ee_invMass=0; 
00352              if (elIsAccepted>2) cout<<"WARNING: In this events we have more than two electrons accpeted!!!!!!!"<<endl;
00353              if (LV.size()==2){
00354                       TLorentzVector e_pair = LV[0] + LV[1];
00355                       e_ee_invMass = e_pair.M ();
00356              }  
00357                       
00358              if (elIsAcceptedEB==2){
00359                       h_ee_invMass_BB->Fill(e_ee_invMass);
00360                }
00361              if (elIsAcceptedEE==2){
00362                       h_ee_invMass_EE->Fill(e_ee_invMass);
00363                }
00364              if (elIsAcceptedEB==1 && elIsAcceptedEE==1){
00365                       h_ee_invMass_EB->Fill(e_ee_invMass);
00366                }
00367                       
00368             LV.clear();
00369                                   
00370          }
00371 }
00372 
00373 #ifdef THIS_IS_AN_EVENT_EXAMPLE
00374 Handle < ExampleData > pIn;
00375 iEvent.getByLabel ("example", pIn);
00376 #endif
00377 
00378 #ifdef THIS_IS_AN_EVENTSETUP_EXAMPLE
00379 ESHandle < SetupData > pSetup;
00380 iSetup.get < SetupRecord > ().get (pSetup);
00381 #endif
00382 
00383 
00384 
00385 // ------------ method called once each job just before starting event loop  ------------
00386 void
00387 EcalZmassTask::beginJob ()
00388 {
00389 
00390   DQMStore *theDbe;
00391   std::string logTraceName;
00392 
00393   logTraceName = "EwkAnalyzer";
00394 
00395   h_ee_invMass_EB = 0;
00396   h_ee_invMass_EE = 0;
00397   h_ee_invMass_BB = 0;
00398 
00399 
00400   LogTrace (logTraceName) << "Parameters initialization";
00401   theDbe = Service < DQMStore > ().operator-> ();
00402 
00403   if (theDbe != 0)
00404     {
00405       theDbe->setCurrentFolder (prefixME_ + "/Zmass");  // Use folder with name of PAG
00406 
00407 
00408       h_ee_invMass_EB =
00409         theDbe->book1D ("Z peak - WP80 EB-EE",
00410                         "Z peak - WP80 EB-EE;InvMass (GeV)", 60, 60.0, 120.0);
00411       h_ee_invMass_EE =
00412         theDbe->book1D ("Z peak - WP80 EE-EE",
00413                         "Z peak - WP80 EE-EE;InvMass (Gev)", 60, 60.0, 120.0);
00414       h_ee_invMass_BB =
00415         theDbe->book1D ("Z peak - WP80 EB-EB",
00416                         "Z peak - WP80 EB-EB;InvMass (Gev)", 60, 60.0, 120.0);
00417 
00418       //h_e1_et             = theDbe->book1D("h_e1_et",  "E_{T} of Leading Electron;E_{T} (GeV)"        , 20,  0.0 , 100.0);
00419       //h_e2_et             = theDbe->book1D("h_e2_et",  "E_{T} of Second Electron;E_{T} (GeV)"         , 20,  0.0 , 100.0);
00420       //h_e1_eta            = theDbe->book1D("h_e1_eta", "#eta of Leading Electron;#eta"                , 20, -4.0 , 4.0);
00421       //h_e2_eta            = theDbe->book1D("h_e2_eta", "#eta of Second Electron;#eta"                 , 20, -4.0 , 4.0);
00422       //h_e1_phi            = theDbe->book1D("h_e1_phi", "#phi of Leading Electron;#phi"                , 22, (-1.-1./10.)*pi, (1.+1./10.)*pi );
00423       //h_e2_phi            = theDbe->book1D("h_e2_phi", "#phi of Second Electron;#phi"                 , 22, (-1.-1./10.)*pi, (1.+1./10.)*pi );
00424     }
00425 }
00426 
00427 // ------------ method called once each job just after ending the event loop  ------------
00428 void
00429 EcalZmassTask::endJob ()
00430 {
00431 }
00432 
00433 // ------------ method called when starting to processes a run  ------------
00434 void
00435 EcalZmassTask::beginRun (edm::Run const &, edm::EventSetup const &)
00436 {
00437 
00438 }
00439 
00440 // ------------ method called when ending the processing of a run  ------------
00441 void
00442 EcalZmassTask::endRun (edm::Run const &, edm::EventSetup const &)
00443 {
00444 }
00445 
00446 // ------------ method called when starting to processes a luminosity block  ------------
00447 void
00448 EcalZmassTask::beginLuminosityBlock (edm::LuminosityBlock const &,
00449                                      edm::EventSetup const &)
00450 {
00451 }
00452 
00453 // ------------ method called when ending the processing of a luminosity block  ------------
00454 void
00455 EcalZmassTask::endLuminosityBlock (edm::LuminosityBlock const &,
00456                                    edm::EventSetup const &)
00457 {
00458 }
00459 
00460 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
00461 void
00462 EcalZmassTask::fillDescriptions (edm::
00463                                  ConfigurationDescriptions & descriptions)
00464 {
00465   //The following says we do not know what parameters are allowed so do no validation
00466   // Please change this to state exactly what you do use, even if it is no parameters
00467   edm::ParameterSetDescription desc;
00468   desc.setUnknown ();
00469   descriptions.addDefault (desc);
00470 }
00471 
00472 //define this as a plug-in
00473 DEFINE_FWK_MODULE (EcalZmassTask);