Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:30:46

0001 /*
0002  *  TrackCategoriesAnalyzer.C
0003  *
0004  *  Created by Victor Eduardo Bazterra on 06/17/08.
0005  *
0006  */
0007 
0008 #include "TH1F.h"
0009 
0010 #include "FWCore/Framework/interface/Frameworkfwd.h"
0011 #include "FWCore/Framework/interface/MakerMacros.h"
0012 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0014 #include "FWCore/ServiceRegistry/interface/Service.h"
0015 
0016 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0017 
0018 #include "SimTracker/TrackHistory/interface/TrackClassifier.h"
0019 
0020 //
0021 // class decleration
0022 //
0023 
0024 class TrackCategoriesAnalyzer : public edm::one::EDAnalyzer<edm::one::SharedResources> {
0025 public:
0026   explicit TrackCategoriesAnalyzer(const edm::ParameterSet &);
0027   ~TrackCategoriesAnalyzer() override;
0028 
0029 private:
0030   void analyze(const edm::Event &, const edm::EventSetup &) override;
0031 
0032   // Member data
0033 
0034   edm::EDGetTokenT<edm::View<reco::Track>> trackProducer_;
0035 
0036   std::size_t totalTracks_;
0037 
0038   TrackClassifier classifier_;
0039 
0040   TH1F *trackCategories_;
0041 
0042   Int_t numberTrackCategories_;
0043 };
0044 
0045 TrackCategoriesAnalyzer::TrackCategoriesAnalyzer(const edm::ParameterSet &config)
0046     : classifier_(config, consumesCollector()) {
0047   // Get the track collection
0048   trackProducer_ = consumes<edm::View<reco::Track>>(config.getUntrackedParameter<edm::InputTag>("trackProducer"));
0049 
0050   // Get the file service
0051   usesResource("TFileService");
0052   edm::Service<TFileService> fs;
0053 
0054   // Create a sub directory associated to the analyzer
0055   TFileDirectory directory = fs->mkdir("TrackCategoriesAnalyzer");
0056 
0057   // Number of track categories
0058   numberTrackCategories_ = TrackCategories::Unknown + 1;
0059 
0060   // Define a new histograms
0061   trackCategories_ = fs->make<TH1F>("Frequency",
0062                                     "Frequency for the different track categories",
0063                                     numberTrackCategories_,
0064                                     -0.5,
0065                                     numberTrackCategories_ - 0.5);
0066 
0067   // Set the proper categories names
0068   for (Int_t i = 0; i < numberTrackCategories_; ++i)
0069     trackCategories_->GetXaxis()->SetBinLabel(i + 1, TrackCategories::Names[i]);
0070 }
0071 
0072 TrackCategoriesAnalyzer::~TrackCategoriesAnalyzer() {}
0073 
0074 void TrackCategoriesAnalyzer::analyze(const edm::Event &event, const edm::EventSetup &setup) {
0075   // Track collection
0076   edm::Handle<edm::View<reco::Track>> trackCollection;
0077   event.getByToken(trackProducer_, trackCollection);
0078 
0079   // Set the classifier for a new event
0080   classifier_.newEvent(event, setup);
0081 
0082   // Loop over the track collection.
0083   for (std::size_t index = 0; index < trackCollection->size(); index++) {
0084     edm::RefToBase<reco::Track> track(trackCollection, index);
0085 
0086     // Classify the tracks
0087     classifier_.evaluate(track);
0088 
0089     // Fill the histogram with the categories
0090     for (Int_t i = 0; i != numberTrackCategories_; ++i)
0091       if (classifier_.is((TrackCategories::Category)i))
0092         trackCategories_->Fill(i);
0093   }
0094 }
0095 
0096 DEFINE_FWK_MODULE(TrackCategoriesAnalyzer);