Code preparation

Use framework template script to prepare EDAnalyzer skeleton

mkedanlzr -track MyTrackAnalyzer

Include root libraries into BuildFile (CMS makefile)

<use name=FWCore/Framework>
<use name=Foundation/PluginManager>
<use name=FWCore/ParameterSet>
<flags SEAL_PLUGIN_NAME="DemoMyTrackAnalyzer">
<use name=DataFormats/TrackReco>
<use name=root>
<export>
   <lib name=DemoMyTrackAnalyzer>
   <use name=FWCore/Framework>
   <use name=Foundation/PluginManager>
   <use name=FWCore/ParameterSet>
   <use name=DataFormats/TrackReco>
   <use name=root>
</export>

Add analysis code and output ROOT file for histograms to skeleton:

// -*- C++ -*-
//
// Package:    MyTrackAnalyzer
// Class:      MyTrackAnalyzer
// 
/**\class MyTrackAnalyzer MyTrackAnalyzer.cc Demo/MyTrackAnalyzer/src/MyTrackAnalyzer.cc

 Description: <one line class summary>

 Implementation:
     <Notes on implementation>
*/
//
// Original Author:  Oliver Gutsche
//         Created:  Mon Jan 15 10:28:42 CST 2007
// $Id: MidWestGridWorkshop2007Code.txt,v 1.1 2007/03/24 22:32:17 OliverGutsche Exp $
//
//


// system include files
#include <memory>

// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDAnalyzer.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"

#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/InputTag.h"
#include "DataFormats/TrackReco/interface/Track.h"

#include "TH1D.h"
#include "TFile.h"
#include "TLorentzVector.h"

//
// class decleration
//

class MyTrackAnalyzer : public edm::EDAnalyzer {
   public:
      explicit MyTrackAnalyzer(const edm::ParameterSet&);
      ~MyTrackAnalyzer();

   private:
      virtual void beginJob(const edm::EventSetup&) ;
      virtual void analyze(const edm::Event&, const edm::EventSetup&);
      virtual void endJob() ;

      // ----------member data ---------------------------
      edm::InputTag trackTags_; //used to select what tracks to read from configuration file
      TH1D *pt_;
      TH1D *mmumu_;
      TH1D *mzz_;
      TFile *file_;
};

//
// constants, enums and typedefs
//

//
// static data member definitions
//

//
// constructors and destructor
//
MyTrackAnalyzer::MyTrackAnalyzer(const edm::ParameterSet& iConfig)
:
 trackTags_(iConfig.getUntrackedParameter<edm::InputTag>("tracks"))
{
   //now do what ever initialization is needed
   file_ = new TFile("histograms.root","RECREATE");

   pt_ = new TH1D("pt","Track p_{T}",250,0.,250.);
   pt_->Sumw2();
   pt_->SetXTitle("p_{T} [GeV]");
   pt_->SetYTitle("Events");

  mmumu_ = new TH1D("mmumu","m_{#mu#mu}",250,0.,250.);
  mmumu_->Sumw2();
  mmumu_->SetXTitle("m_{#mu#mu} [GeV]");
  mmumu_->SetYTitle("Events");

  mzz_ = new TH1D("mzz","m_{ZZ}",250,0.,250.);
  mzz_->Sumw2();
  mzz_->SetXTitle("m_{ZZ} [GeV]");
  mzz_->SetYTitle("Events");

}


MyTrackAnalyzer::~MyTrackAnalyzer()
{
 
   // do anything here that needs to be done at desctruction time
   // (e.g. close files, deallocate resources etc.)

  file_->Write();
  file_->Close();

}


//
// member functions
//

// ------------ method called to for each event  ------------
void
MyTrackAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
{
   using namespace edm;
   using reco::TrackCollection;
  
   Handle<TrackCollection> tracks;
   iEvent.getByLabel(trackTags_,tracks);
   for(TrackCollection::const_iterator itTrack = tracks->begin();
       itTrack != tracks->end();
       ++itTrack) {
     pt_->Fill(itTrack->pt());
     std::vector<TLorentzVector> mumus;
     TLorentzVector track1(itTrack->px(),itTrack->py(),itTrack->pz(),std::sqrt(itTrack->p()*itTrack->p()+0.10566*0.10566));
     for(TrackCollection::const_iterator itTrack2 = tracks->begin();
         itTrack2 != tracks->end();
         ++itTrack2) {
       if ( itTrack->charge() != itTrack2->charge() ) {
         TLorentzVector track2(itTrack2->px(),itTrack2->py(),itTrack2->pz(),std::sqrt(itTrack2->p()*itTrack2->p()+0.10566*0.10566));
         TLorentzVector mumu = track1 + track2;

         mmumu_->Fill(mumu.M());
         mumus.push_back(mumu);

       }
     }

     if ( mumus.size() > 1 ) {
       for ( std::vector<TLorentzVector>::iterator mumu1 = mumus.begin();
             mumu1 != mumus.end();
             ++mumu1) {
         if ( mumu1->M() > 80. && mumu1->M() < 100.0 ) {
           for ( std::vector<TLorentzVector>::iterator mumu2 = mumu1+1;
                 mumu2 != mumus.end();
                 ++mumu2) {
             if ( mumu2->M() > 80. && mumu2->M() < 100.0 ) {
               TLorentzVector zz = *mumu1 + *mumu2;
               mzz_->Fill(zz.M());
             }
           }
         }
       }
     }
  }
}


// ------------ method called once each job just before starting event loop  ------------
void 
MyTrackAnalyzer::beginJob(const edm::EventSetup&)
{
}

// ------------ method called once each job just after ending the event loop  ------------
void 
MyTrackAnalyzer::endJob() {
}

//define this as a plug-in
DEFINE_FWK_MODULE(MyTrackAnalyzer);

Prepare parameter-set to run EDAnalyzer:

process A = {

  source = PoolSource {
        untracked vstring fileNames = {
                "file:test.root"
        }
        untracked int32 maxEvents = -1
        untracked uint32 skipEvents = 0
  }

  module higgs = MyTrackAnalyzer {
        untracked InputTag tracks = ctfWithMaterialTracks
  }

  path p = {
        higgs
  }

}
Edit | Attach | Watch | Print version | History: r1 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r1 - 2007-03-24 - OliverGutsche
 
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    Main 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