7.4.1 PAT Examples: Electron Example

Contents

Introduction

In this example you will find how to make a simple analysis (including some more physics contents) with pat::Electrons within a simple EDAnalyzer. You can find the EDAnalyzer and the configuration file in the PatExamples package. It will provide you with the following information:

  • how to access information from the pat::Electron.
  • how to determine an electron reconstruction efficiency from simulation.
  • how to estimate an electronID efficiency applying a simple tag and probe method.

It is required that you have a clear picture of:

  • how to write an EDAnalyzer (in principle).
  • how to read in parameters from the configuration file.
  • how to clone modules with different parameters in python.
  • how to access a pat::Candidate collection from the event content with an EDAnalyzer.

ALERT! Note: For more fundamental examples have a look at the WorkBookPATAccessExercise. This example currently is only supported on the B2_2_X development branch of PAT.

How to get the code

To run the example check out the latest tags for PAT as given on the SWGuidePATRecipes#CMSSW_2_2_X_with_PAT_version_2 and checkout the following tags in addition:

cd CMSSW_2_2_13/src
cmsenv
cvs co -r desyTutorial_june09_electron PhysicsTools/PatExamples/BuildFile
cvs co -r desyTutorial_june09_electron PhysicsTools/PatExamples/plugins/BuildFile
cvs co -r desyTutorial_june09_electron PhysicsTools/PatExamples/plugins/PatElectronAnalyzer.cc
cvs co -r desyTutorial_june09_electron PhysicsTools/PatExamples/python/PatElectronAnalyzer_cfi.py
cvs co -r desyTutorial_june09_electron PhysicsTools/PatExamples/python/tagAndProbeAnalysis_cff.py
cvs co -r desyTutorial_june09_electron PhysicsTools/PatExamples/test/analyzePatElectron_cfg.py
cvs co -r desyTutorial_june09_electron PhysicsTools/PatExamples/test/patElectron_recoEfficiency.C
cvs co -r desyTutorial_june09_electron PhysicsTools/PatExamples/test/patElectron_eidEfficiency.C

These files have the following functionality:

How to run the code

Compile and run the example as given below:

scram b 
cmsRun PhysicsTools/PatExamples/test/analyzePatElectron_cfg.py

You can inspect the outcome using the two root macros which are provided with the example:

root -l 
.x patElectron_recoEfficiency.C
.x patElectron_eidEfficiency.C

Find out more about the details

In the main configuration file (analyzePatElectron_cfg.py) the two files PatElectronAnalyzer_cfi and tagAndProbeAnalysis_cff are added to the process:

# calculate the efficiency for electron reconstruction
# from the simulation
process.load("PhysicsTools.PatExamples.PatElectronAnalyzer_cfi")

# calculate the efficiency for electronID from a tag
# and probe method
process.load("PhysicsTools.PatExamples.tagAndProbeAnalysis_cff")

ALERT! Note: The file PatElectronAnalyzer_cfi corresponds to the plain definition of the module. In the file tagAndProbeAnalysis_cff the structure for the simple tag and probe method is defined.


In the initialising configuration file (PatElectronAnalyzer_cfi.py) the module is defined with the name analyzePatElectron:

## define pat electron analyzer
analyzePatElectron = cms.EDAnalyzer("PatElectronAnalyzer",
    ## choose mode to run in:
    ## 0 : genMatch, 1 : tagAndProbe
    mode = cms.uint32(0),

    ## maximal pt  for the electron to be considered
    minPt = cms.double(10.),
    ## maximal eta for the electron to be considered
    maxEta= cms.double(1.4),
    ## electronId to be used for probe the following
    ## types are  available:
    ##  * none
    ##  * eidRobustLoose
    ##  * eidRobustTight
    ##  * eidLoose
    ##  * eidTight
    ##  * eidRobustHighEnergy
    electronID = cms.string('none'), 
                                   
    ## input collection for electrons
    electronSrc  = cms.InputTag("selectedLayer1Electrons"),
    ## input collection for generator particles
    particleSrc  = cms.InputTag("genParticles"),
                                    
    ## parameters for genMatch mode
    genMatchMode = cms.PSet(
      ## maximal allowed value of deltaR
      maxDeltaR = cms.double(0.1)
    ),

    ## parameters for tagAndProbe mode
    tagAndProbeMode = cms.PSet(
      ## maximal allowed value of deltaM
      maxDeltaM = cms.double(10.),
      ## maximal allowed value of isolation
      ## of the tag electron
      maxTagIso = cms.double(1.0)      
    )                                 
)

ALERT! Note: As you can see it contains quite a few input parameters:

  • The parameter mode will allow to switch between the modes genMatch, which uses generator information to determine the absolute reconstruction efficiency of electrons and tagAndPtobe, which applies a simple tag and probe method to determine the electronID efficiency.
  • The parameter sets genMatchMode and tagAndProbeMode hold parameters related to these modes.
  • The parameters minPt and maxEta allow to restrict the range of the (probe) electrons in consideration. Have a look into the module to see how this restriction exactly works.
  • The parameter electronID allows to impose several kinds of cut based ID flags on the (probe) electron of consideration.


In the tag and probe configuration file (tagAndProbeAnalysis_cff.py) the analysis structure for a simple tag and probe method is defined:

plainElectronID = analyzePatElectron.clone(mode=1, electronID = "none")
looseElectronID = analyzePatElectron.clone(mode=1, electronID = "eidRobustLoose")
tightElectronID = analyzePatElectron.clone(mode=1, electronID = "eidRobustTight")

tagAndProbeAnalysis = cms.Sequence(
    plainElectronID +
    looseElectronID +
    tightElectronID
    )

ALERT! Note: The initial module is cloned three times. It's mode is switched to tagAndProbe and different flags for the electronID are set. Finally the three cloned modules are combined into a single sequence. The + sign indicates that no module depends on its predecessor.


The first part of the module contains the class structure:

class PatElectronAnalyzer : public edm::EDAnalyzer {

 public:
  
  explicit PatElectronAnalyzer(const edm::ParameterSet&);
  ~PatElectronAnalyzer();
  
 private:
  
  virtual void beginJob(const edm::EventSetup&) ;
  virtual void analyze(const edm::Event&, const edm::EventSetup&);
  virtual void endJob() ;

  // restrictions for the electron to be 
  // considered
  double minPt_;
  double maxEta_;

  // decide in which mode to run the analyzer
  // 0 : genMatch, 1 : tagAndProbe are 
  // supported depending on the line comments
  unsigned int mode_;

  // choose a given electronID for the electron
  // in consideration; the following types are 
  // available: 
  // * eidRobustLoose
  // * eidRobustTight
  // * eidLoose
  // * eidTight
  // * eidRobustHighEnergy
  std::string electronID_;

  // source of electrons
  edm::InputTag electronSrc_;
  // source of generator particles
  edm::InputTag particleSrc_;

  edm::ParameterSet genMatchMode_;
  edm::ParameterSet tagAndProbeMode_;

  // internal variables for genMatchMode and
  // tagAndProbeMode 
  double maxDeltaR_;
  double maxDeltaM_;
  double maxTagIso_;
  
  // book histograms of interest
  TH1I *nr_;
  TH1F *pt_;
  TH1F *eta_;
  TH1F *phi_;
  TH1F *genPt_;
  TH1F *genEta_;
  TH1F *genPhi_;
  TH1F *deltaR_;
  TH1F *isoTag_;
  TH1F *invMass_;
  TH1F *deltaPhi_;
};  

ALERT! Note: Apart from the input parameters the histograms of interest are defined. We will use:

  • The histograms pt_, eta_ and phi_ for the reconstructed electron quantities.
  • The histograms genPt_, genEta_ and genPhi_ for the electron quantities on generator level.
  • The histogram deltaR_ will serve to monitor the generator matching in the genMatch mode
  • The histogram isoTag_ will serve to monitor the isolation of the tag electron in the tagAndProbe mode.
  • The histogram invMass_ will serve to monitor the invariant mass peak of the Z boson in the tagAndProbe mode.
  • The histogram deltaPhi_ will serve to monitor the back to back structure of the two electrons in the tagAndProbe mode.


The analyze function contains two main parts. The first part is dedicated to the genMatch mode:

// ----------------------------------------------------------------------
  //
  // First Part Mode 0: genMatch
  //
  // ----------------------------------------------------------------------
  if( mode_==0 ){
    // loop generator particles 
    for(reco::GenParticleCollection::const_iterator part=particles->begin(); 
	part!=particles->end(); ++part){
      // only loop stable electrons
      if( part->status()==1  && abs(part->pdgId())==11 ){
	if( part->pt()>minPt_ && fabs(part->eta())<maxEta_ ){
	  genPt_ ->Fill( part->pt()  );
	  genEta_->Fill( part->eta() );
	  genPhi_->Fill( part->phi() );      
	}
      }
    }
    
    // loop electrons
    for( std::vector<pat::Electron>::const_iterator elec=electrons->begin(); elec!=electrons->end(); ++elec ){
      if( elec->genLepton() ){
	float deltaR = ROOT::Math::VectorUtil::DeltaR(elec->genLepton()->p4(), elec->p4());
	deltaR_->Fill(TMath::Log10(deltaR));	
	if( deltaR<maxDeltaR_ ){
	  if( electronID_.compare("none")!=0 ){
	    if( elec->electronID(electronID_)<0.5 ) 
	      continue;
	  }
	  if( elec->pt()>minPt_ && fabs(elec->eta())<maxEta_ ){
	    pt_ ->Fill( elec->pt()  );
	    eta_->Fill( elec->eta() );
	    phi_->Fill( elec->phi() );
	  }
	}
      }
    }
  }

ALERT! Note: First the generator particles are looped and the the corresponding histograms are filled. In a second loop the histograms for the reconstructed electrons are filled. The generated electrons are required to be stable and to have the PDG code 11. A restriction on electronID acts only on the reconstructed electron. A range restriction (in eta and pt) acts on both the generated and the reconstructed electron.


The first part is dedicated to the tagAndProbe mode:

// ----------------------------------------------------------------------
  //
  // Second Part Mode 1: tagAndProbe
  //
  // ----------------------------------------------------------------------
  if( mode_==1 ){
    // loop tag electron
    for( std::vector<pat::Electron>::const_iterator elec=electrons->begin(); elec!=electrons->end(); ++elec ){
      isoTag_->Fill(elec->trackIso());	
      if( elec->trackIso()<maxTagIso_  && elec->electronID("eidTight")>0.5 ){
	// loop probe electron
	for( std::vector<pat::Electron>::const_iterator probe=electrons->begin(); probe!=electrons->end(); ++probe ){
	  // skip the tag electron itself
	  if( probe==elec ) continue;
	  
	  float zMass = (probe->p4()+elec->p4()).mass();
	  invMass_ ->Fill(zMass);	
	  float deltaPhi = ROOT::Math::VectorUtil::DeltaPhi(elec->p4(), probe->p4());
	  deltaPhi_->Fill(deltaPhi);	
	  
	  // check for the Z mass
	  if( fabs( zMass-90. )<maxDeltaM_ ){
	    if( electronID_.compare("none")!=0 ){
	      if( probe->electronID(electronID_)<0.5 ) 
		continue;
	    }
	    if( probe->pt()>minPt_ && fabs(probe->eta())<maxEta_ ){
	      pt_ ->Fill( probe->pt()  );
	      eta_->Fill( probe->eta() );
	      phi_->Fill( probe->phi() );
	    }
	  }
	}
      }
    }
  }

ALERT! Note: In a first loop the tag electron is identified. This requires the strongest electronID offered by the EgammaPOG and some minimal isolation. From that point on a nested loop over the electron collection is initiated to identify the probe electron. A minimal fit to the invariant mass off the two electrons to the mass of the Z boson is required. Different types of electronID may be imposed on the probe electron. A restriction in eta and pt only acts on the considered probe electron.


The results may be displayed by the two root macros patElectron_recoEfficiency.C and patElectron_eidEfficiency.C. Both macros open the the root file and read in the corresponding histograms for pt, eta and phi of the electron. Corresponding histograms are divided and the efficiency as a function of these variables is shown. In addition the pt and the eta distribution of the (probe) electron are shown.

How to get more information

You have more questions? Don't hesitate to contact the SWGuidePAT#Support.

Exercises

To get a feeling of the module you should do the following exercises:

  • Check the parameter maxDeltaR and adapt it to some sensible value according to the monitoring histogram.
  • Vary the restriction of the visible range for the genMatch mode.
  • Vary the electronID parameter genMatch mode.

  • Check the parameters maxIsoTag and maxDeltaM and adapt it to some sensible value according to the monitoring histogram.
  • Vary the restriction of the visible range for the tagAndProbe mode.
  • Vary the electronID parameter tagAndProbe mode, therefore change the line comments in the patElectron_eidEfficiency.C macro acccordingly.

  • Think what kind of tag and probe method you would need (how would the probe object look like?) to get an answer to the following questions:
    • What is the track reconstruction efficiency?
    • What is the cluster finding efficiency?

  • Z to electron electron events restrict the method to a very special kinematic and topological range. Can you think of other event types to which this method could be applied?

Review status

Reviewer/Editor and Date (copy from screen) Comments
RogerWolf - 11 june 2009 Moved from SWGuidePATExamples

Responsible: RogerWolf
Last reviewed by: most recent reviewer and date

-- RogerWolf - 11 Jun 2009

Edit | Attach | Watch | Print version | History: r12 | r9 < r8 < r7 < r6 | Backlinks | Raw View | Raw edit | More topic actions...
Topic revision: r7 - 2010-08-06 - SudhirMalik
 
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    CMSPublic All webs login

This site is powered by the TWiki collaboration platform Powered by PerlCopyright & 2008-2021 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
or Ideas, requests, problems regarding TWiki? use Discourse or Send feedback