CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/FWCore/Skeletons/scripts/mkTemplates/EDAnalyzer/edanalyzer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    anlzrname
00004 // Class:      anlzrname
00005 // 
00013 //
00014 // Original Author:  John Doe
00015 //         Created:  day-mon-xx
00016 // RCS(Id)
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 #include <memory>
00023 
00024 // user include files
00025 #include "FWCore/Framework/interface/Frameworkfwd.h"
00026 #include "FWCore/Framework/interface/EDAnalyzer.h"
00027 
00028 #include "FWCore/Framework/interface/Event.h"
00029 #include "FWCore/Framework/interface/MakerMacros.h"
00030 
00031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00032 @example_track #include "FWCore/Utilities/interface/InputTag.h"
00033 @example_track #include "DataFormats/TrackReco/interface/Track.h"
00034 @example_track #include "DataFormats/TrackReco/interface/TrackFwd.h"
00035 @example_histo #include "FWCore/ServiceRegistry/interface/Service.h"
00036 @example_histo #include "CommonTools/UtilAlgos/interface/TFileService.h"
00037 @example_histo #include "TH1.h"
00038 //
00039 // class declaration
00040 //
00041 
00042 class anlzrname : public edm::EDAnalyzer {
00043    public:
00044       explicit anlzrname(const edm::ParameterSet&);
00045       ~anlzrname();
00046 
00047       static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
00048 
00049 
00050    private:
00051       virtual void beginJob() ;
00052       virtual void analyze(const edm::Event&, const edm::EventSetup&);
00053       virtual void endJob() ;
00054 
00055       virtual void beginRun(edm::Run const&, edm::EventSetup const&);
00056       virtual void endRun(edm::Run const&, edm::EventSetup const&);
00057       virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&);
00058       virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&);
00059 
00060       // ----------member data ---------------------------
00061 @example_track       edm::InputTag trackTags_; //used to select what tracks to read from configuration file
00062 @example_histo       TH1D * histo; 
00063 };
00064 
00065 //
00066 // constants, enums and typedefs
00067 //
00068 
00069 //
00070 // static data member definitions
00071 //
00072 
00073 //
00074 // constructors and destructor
00075 //
00076 anlzrname::anlzrname(const edm::ParameterSet& iConfig)
00077 @example_track :
00078 @example_track  trackTags_(iConfig.getUntrackedParameter<edm::InputTag>("tracks"))
00079 
00080 {
00081    //now do what ever initialization is needed
00082 @example_histo   edm::Service<TFileService> fs;
00083 @example_histo   histo = fs->make<TH1D>("charge" , "Charges" , 200 , -2 , 2 );
00084 
00085 }
00086 
00087 
00088 anlzrname::~anlzrname()
00089 {
00090  
00091    // do anything here that needs to be done at desctruction time
00092    // (e.g. close files, deallocate resources etc.)
00093 
00094 }
00095 
00096 
00097 //
00098 // member functions
00099 //
00100 
00101 // ------------ method called for each event  ------------
00102 void
00103 anlzrname::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00104 {
00105    using namespace edm;
00106 
00107 @example_track   using reco::TrackCollection;
00108 
00109 @example_track    Handle<TrackCollection> tracks;
00110 @example_track    iEvent.getByLabel(trackTags_,tracks);
00111 @example_track    for(TrackCollection::const_iterator itTrack = tracks->begin();
00112 @example_track        itTrack != tracks->end();                      
00113 @example_track        ++itTrack) {
00114 @example_track_histo       int charge = 0;
00115 @example_track       charge = itTrack->charge();  
00116 @example_histo       histo->Fill( charge );
00117 @example_track    }
00118 
00119 #ifdef THIS_IS_AN_EVENT_EXAMPLE
00120    Handle<ExampleData> pIn;
00121    iEvent.getByLabel("example",pIn);
00122 #endif
00123    
00124 #ifdef THIS_IS_AN_EVENTSETUP_EXAMPLE
00125    ESHandle<SetupData> pSetup;
00126    iSetup.get<SetupRecord>().get(pSetup);
00127 #endif
00128 }
00129 
00130 
00131 // ------------ method called once each job just before starting event loop  ------------
00132 void 
00133 anlzrname::beginJob()
00134 {
00135 }
00136 
00137 // ------------ method called once each job just after ending the event loop  ------------
00138 void 
00139 anlzrname::endJob() 
00140 {
00141 }
00142 
00143 // ------------ method called when starting to processes a run  ------------
00144 void 
00145 anlzrname::beginRun(edm::Run const&, edm::EventSetup const&)
00146 {
00147 }
00148 
00149 // ------------ method called when ending the processing of a run  ------------
00150 void 
00151 anlzrname::endRun(edm::Run const&, edm::EventSetup const&)
00152 {
00153 }
00154 
00155 // ------------ method called when starting to processes a luminosity block  ------------
00156 void 
00157 anlzrname::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
00158 {
00159 }
00160 
00161 // ------------ method called when ending the processing of a luminosity block  ------------
00162 void 
00163 anlzrname::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
00164 {
00165 }
00166 
00167 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
00168 void
00169 anlzrname::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
00170   //The following says we do not know what parameters are allowed so do no validation
00171   // Please change this to state exactly what you do use, even if it is no parameters
00172   edm::ParameterSetDescription desc;
00173   desc.setUnknown();
00174   descriptions.addDefault(desc);
00175 @example_track
00176 @example_track  //Specify that only 'tracks' is allowed
00177 @example_track  //To use, remove the default given above and uncomment below
00178 @example_track  //ParameterSetDescription desc;
00179 @example_track  //desc.addUntracked<edm::InputTag>("tracks","ctfWithMaterialTracks");
00180 @example_track  //descriptions.addDefault(desc);
00181 }
00182 
00183 //define this as a plug-in
00184 DEFINE_FWK_MODULE(anlzrname);