Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:53:11

0001 
0002 #include "DataFormats/CSCRecHit/test/CSCSharesInputTest.h"
0003 
0004 #include <string>
0005 #include <sstream>
0006 #include <iostream>
0007 
0008 #include "FWCore/Utilities/interface/InputTag.h"
0009 
0010 #include "DataFormats/CSCRecHit/interface/CSCRecHit2D.h"
0011 #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
0012 #include "DataFormats/TrackReco/interface/Track.h"
0013 
0014 CSCSharesInputTest::CSCSharesInputTest(const edm::ParameterSet &myConfig) {
0015   rh_token = consumes<CSCRecHit2DCollection>(myConfig.getParameter<edm::InputTag>("CSCRecHitCollection"));
0016   mu_token = consumes<edm::View<reco::Muon> >(myConfig.getParameter<edm::InputTag>("MuonCollection"));
0017 
0018   // Set up plots, ntuples
0019   edm::Service<TFileService> rootFile;
0020 
0021   ntuples_["perEvent"] = rootFile->make<TNtuple>(
0022       "perEvent",
0023       "Interesting data on a per-event basis",
0024       "Muons:RecHits:TrackingRecHits:AllMatchedRecHits:SomeMatchedRecHits:AllWiresMatchedRecHits:"
0025       "SomeWiresMatchedRecHits:AllStripsMatchedRecHits:SomeStripsMatchedRecHits:NotMatchedRecHits");
0026   ntuples_["perMuon"] = rootFile->make<TNtuple>(
0027       "perMuon",
0028       "Interesting data on a per-muon basis",
0029       "TrackingRecHits:AllMatchedRecHits:SomeMatchedRecHits:AllWiresMatchedRecHits:SomeWiresMatchedRecHits:"
0030       "AllStripsMatchedRecHits:SomeStripsMatchedRecHits:NotMatchedRecHits");
0031   ntuples_["perRecHit"] = rootFile->make<TNtuple>(
0032       "perRecHit",
0033       "Interesting data per RecHit",
0034       "AllMatched:SomeMatched:AllWiresMatched:SomeWiresMatched:AllStripsMatched:SomeStripsMatched:NotMatched");
0035 }
0036 
0037 void CSCSharesInputTest::beginJob() {}
0038 
0039 void CSCSharesInputTest::analyze(const edm::Event &myEvent, const edm::EventSetup &mySetup) {
0040   ++counts_["Events"];  // presuming default init of int elem to zero
0041 
0042   edm::Handle<edm::View<reco::Muon> > muonHandle;
0043   myEvent.getByToken(mu_token, muonHandle);
0044 
0045   edm::View<reco::Muon> muons = *muonHandle;
0046 
0047   edm::Handle<CSCRecHit2DCollection> recHits;
0048   myEvent.getByToken(rh_token, recHits);
0049 
0050   // Muons:RecHits:TrackingRecHits:AllMatchedRecHits:SomeMatchedRecHits:AllWiresMatchedRecHits:SomeWiresMatchedRecHits:AllStripsMatchedRecHits:SomeStripsMatchedRecHits:NotMatchedRecHits
0051   float perEventData[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
0052 
0053   counts_["Muons"] += muons.size();
0054   perEventData[0] = muons.size();
0055   counts_["RecHits"] += recHits->size();
0056   perEventData[1] = recHits->size();
0057 
0058   for (edm::View<reco::Muon>::const_iterator iMuon = muons.begin(); iMuon != muons.end(); ++iMuon) {
0059     // TrackingRecHits:AllMatchedRecHits:SomeMatchedRecHits:AllWiresMatchedRecHits:SomeWiresMatchedRecHits:AllStripsMatchedRecHits:SomeStripsMatchedRecHits:NotMatchedRecHits
0060     float perMuonData[8] = {0, 0, 0, 0, 0, 0, 0, 0};
0061 
0062     // note:  only outer tracks are considered
0063     reco::Track *track = new reco::Track(*(iMuon->outerTrack()));
0064 
0065     counts_["TrackingRecHits"] += track->recHitsSize();
0066     perEventData[2] += track->recHitsSize();
0067     perMuonData[0] += track->recHitsSize();
0068 
0069     for (auto const &jHit : track->recHits()) {
0070       // AllMatched:SomeMatched:AllWiresMatched:SomeWiresMatched:AllStripsMatched:SomeStripsMatched:NotMatched
0071       float perRecHitData[7] = {0, 0, 0, 0, 0, 0, 0};
0072 
0073       // Kill us quickly if this is not a CSCRecHit.  Also allows us to use the CSCRecHit version of sharesInput, which we like.
0074       const CSCRecHit2D *myHit = dynamic_cast<const CSCRecHit2D *>(jHit);
0075       if (myHit == 0) {
0076         ++counts_["NotMatchedRecHits"];
0077         ++perEventData[9];
0078         ++perMuonData[7];
0079         perRecHitData[6] = 1;
0080         continue;
0081       }
0082 
0083       bool matched = false;
0084 
0085       for (CSCRecHit2DCollection::const_iterator iHit = recHits->begin(); iHit != recHits->end(); ++iHit) {
0086         // for now, this throws with DT TrackingRecHits
0087         try {
0088           if (myHit->sharesInput(&(*iHit), CSCRecHit2D::all)) {
0089             ++counts_["AllMatchedRecHits"];
0090             ++perEventData[3];
0091             ++perMuonData[1];
0092             perRecHitData[0] = 1;
0093             matched = true;
0094           }
0095           if (myHit->sharesInput(&(*iHit), CSCRecHit2D::some)) {
0096             ++counts_["SomeMatchedRecHits"];
0097             ++perEventData[4];
0098             ++perMuonData[2];
0099             perRecHitData[1] = 1;
0100             matched = true;
0101           }
0102           if (myHit->sharesInput(&(*iHit), CSCRecHit2D::allWires)) {
0103             ++counts_["AllWiresMatchedRecHits"];
0104             ++perEventData[5];
0105             ++perMuonData[3];
0106             perRecHitData[2] = 1;
0107             matched = true;
0108           }
0109           if (myHit->sharesInput(&(*iHit), CSCRecHit2D::someWires)) {
0110             ++counts_["SomeWiresMatchedRecHits"];
0111             ++perEventData[6];
0112             ++perMuonData[4];
0113             perRecHitData[3] = 1;
0114             matched = true;
0115           }
0116           if (myHit->sharesInput(&(*iHit), CSCRecHit2D::allStrips)) {
0117             ++counts_["AllStripsMatchedRecHits"];
0118             ++perEventData[7];
0119             ++perMuonData[5];
0120             perRecHitData[4] = 1;
0121             matched = true;
0122           }
0123           if (myHit->sharesInput(&(*iHit), CSCRecHit2D::someStrips)) {
0124             ++counts_["SomeStripsMatchedRecHits"];
0125             ++perEventData[8];
0126             ++perMuonData[6];
0127             perRecHitData[5] = 1;
0128             matched = true;
0129           }
0130 
0131         } catch (cms::Exception &e) {
0132           // Not a CSC RecHit, so I should break out of the loop to save time.
0133           break;
0134         }
0135       }
0136 
0137       if (!matched) {
0138         ++counts_["NotMatchedRecHits"];
0139         ++perEventData[9];
0140         ++perMuonData[7];
0141         perRecHitData[6] = 1;
0142       }
0143 
0144       ntuples_["perRecHit"]->Fill(perRecHitData);
0145     }
0146 
0147     ntuples_["perMuon"]->Fill(perMuonData);
0148   }
0149 
0150   ntuples_["perEvent"]->Fill(perEventData);
0151 }
0152 
0153 void CSCSharesInputTest::endJob() {
0154   std::cout << std::endl << "End of job statistics" << std::endl;
0155   for (std::map<std::string, uint64_t>::iterator iCount = counts_.begin(); iCount != counts_.end(); iCount++) {
0156     std::cout << iCount->first << ": " << iCount->second << std::endl;
0157   }
0158   std::cout << std::endl;
0159 }
0160 
0161 CSCSharesInputTest::~CSCSharesInputTest() {}
0162 
0163 DEFINE_FWK_MODULE(CSCSharesInputTest);