Kalanand's May 2009 Log

   April 2009   
May 2009
SuMoTuWeThFrSa
     12
3456789
10111213141516
17181920212223
24252627282930
31      
   June 2009   

May 1st

Python template to copy data from a remote site

Now I can accomplish the same task as described here more conveniently using a python template. The added advantage is that this template is highly reusable, so I can run it multiple times as part of a work-flow.
Link to the script
import FWCore.ParameterSet.Config as cms
process = cms.Process("Transfer")
process.load('FWCore.MessageService.MessageLogger_cfi')


#############   Set the number of events #############
process.maxEvents = cms.untracked.PSet(
    input = cms.untracked.int32(-1)
)
#############   Define the source file ###############
process.source = cms.Source("PoolSource",
    fileNames = cms.untracked.vstring()
)


#############   output module ########################
process.output = cms.OutputModule("PoolOutputModule", 
    outputCommands = cms.untracked.vstring('keep *'),
    fileName = cms.untracked.string('exotica-EXODiPhoSkimOct09_7TeV.root')
)


process.p = cms.EndPath(process.output)

#############   Format MessageLogger #################
process.MessageLogger.cerr.FwkReport.reportEvery = 1000

May 12th

Skimming events by trigger name

A very useful filtering tool makes it possible to skim those data (or MC) events that passed a given trigger path or set of trigger paths. Here is an example.
##-------- Jets Triggers --------------
process.HLTJets = cms.EDFilter("HLTHighLevel",
    TriggerResultsTag = cms.InputTag("TriggerResults","","HLT"),
    HLTPaths = cms.vstring('HLT_Jet100U'),
    eventSetupPathsKey = cms.string(''),
    andOr = cms.bool(True), #----- True = OR, False = AND between the HLTPaths
    throw = cms.bool(True)
)

May 26th

Jet flavor tagging

To get the true flavor of a matched calojet is a non-trivial exercise which involves a few steps. Here is a detailed recipe which works for me in CMSSW_1_6_X, but would need some tweaking in later releases. Also, please have a look at the following twiki documentation for basic ideas: https://twiki.cern.ch/twiki/bin/view/CMS/WorkBookBTagging#BtagMCTools
-------------------------------------------------------------------------

1.)  Include  "JetFlavourIdentifier" (be careful of the spelling of 
     "Flavour" here) class header in your analyzer header and intantiate 
     like this:


    #include "RecoBTag/MCTools/interface/JetFlavour.h"
    #include "RecoBTag/MCTools/interface/JetFlavourIdentifier.h"

    private:
    std::map flavoursMapf;
    edm::Handle theJetPartonMapf;

    JetFlavourIdentifier jetFlavourIdentifier_;




 2.) In your analyzer (.cc) include the following snippet:

   #include "SimDataFormats/JetMatching/interface/JetFlavourMatching.h"
 
----------------------------------------------------------------------
        // Jet Flavor identification
    flavourMatchOptionf
      = iConfig.getUntrackedParameter
                                ("flavourMatchOption", "genParticle");
    const edm::InputTag flavourSource("tagJet");
    if (flavourMatchOptionf == "fastMC") {
      flavourSourcef = iConfig.getUntrackedParameter
                                      ("flavourSource", flavourSource);
    } else if (flavourMatchOptionf == "hepMC") {
      jetIdParameters_ =
        iConfig.getParameter("jetIdParameters");
      jfi = JetFlavourIdentifier(jetIdParameters_);
    } else if (flavourMatchOptionf == "genParticle") {
      flavourSourcef = iConfig.getUntrackedParameter 
                                        ("flavourSource", flavourSource);
    }
--------------------------------------------------------------------------



 3.)   In the  "analyze()" function of your analyzer:

      /****************    Jet Flavor    ***************/
    edm::Handle jetMC;
    if (flavourMatchOptionf == "fastMC") {
      // initialize flavour identifiers
      iEvent.getByLabel(flavourSourcef, jetMC);
      for(JetFlavourMatchingCollection::const_iterator iter =
            jetMC->begin(); iter != jetMC->end(); iter++)
        flavoursMapf.insert(*iter);
    }
    else if (flavourMatchOptionf == "hepMC") {
      jfi.readEvent(iEvent);
    }
    else if (flavourMatchOptionf == "genParticle") {
      iEvent.getByLabel (flavourSourcef, theJetPartonMapf);
    }
    /****************    Jet Flavor    ***************/





  4.)  Copy the following member function called "getMatchedParton" 
       in your analyzer code (.cc file) and also declare it in your header:

  ---------------------------------------------------------------------

   JetFlavour  getMatchedParton(const reco::CaloJet &jet) {

    JetFlavour jetFlavour;

    if (flavourMatchOptionf == "fastMC") {
      jetFlavour.underlyingParton4Vec(jet.p4());
    }
    else if (flavourMatchOptionf == "hepMC") {
      jetFlavour = jfi.identifyBasedOnPartons(jet);
    }
    else if (flavourMatchOptionf == "genParticle") {

      for( reco::CandMatchMap::const_iterator f  = theJetPartonMapf->begin();
           f != theJetPartonMapf->end(); f++) {
        const reco::Candidate *theJetInTheMatchMap = &*(f->key);
        const reco::Candidate *theMatchedParton    = &*(f->val);

        if(theJetInTheMatchMap->hasMasterClone ()) {
          const reco::CaloJet* theMasterClone =
            dynamic_cast
            (theJetInTheMatchMap->masterClone().get());

          if( fabs(theMasterClone->phi() - jet.phi()) < 1.e-5 &&
              fabs(theMasterClone->eta() - jet.eta())< 1.e-5 ){

            jetFlavour.flavour(abs(theMatchedParton->pdgId()));
            jetFlavour.underlyingParton4Vec(theMatchedParton->p4());
            return jetFlavour;
          }
        }
      }
    }
    return jetFlavour;
  }
 -------------------------------------------------------------------------


 
 5.)  Now, you can get the jet flavor inside your CaloJet  iterator 
      loop in the following way:



      edm::Handle jets;
      iEvent.getByLabel( reco::iterativeCone5CaloJets,  jets );

     reco::CaloJetCollection::const_iterator jet = jets->begin ();
     for (; jet != jets->end (); jet++) {
        int flavor = getMatchedParton(*jet).flavour();
        .....
      }

 
      /** Jet flavor classification code:
        if ( flavor == 1 ) : Down
        if ( flavor == 2 ) : Up
        if ( flavor == 3 ) : Strange
        if ( flavor == 4 ) : Charm
        if ( flavor == 5 ) : Bottom
        if ( flavor == 21 ): Gluon
   */

   


 6.)   Finally, in your configuration define the tagJet collection and 
       include it in your path:


  
       module tagJet = CandJetFlavourIdentifier{
         InputTag jets = iterativeCone5CaloJets
         double coneSizeToAssociate = 0.3
         bool physicsDefinition = true
         bool debug = false
         vstring vetoFlavour = {  }
       }

 --------------------------------------------------------------------------

Go to April's log


Last modified: Tue May 26 18:10:52 CST 2009