Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:00

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