Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:59:47

0001 #include "ShallowRechitClustersProducer.h"
0002 
0003 #include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h"
0004 #include "Geometry/CommonTopologies/interface/StripTopology.h"
0005 #include "FWCore/Framework/interface/ESHandle.h"
0006 #include "FWCore/Framework/interface/Event.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0008 
0009 #include "CalibTracker/SiStripCommon/interface/ShallowTools.h"
0010 
0011 ShallowRechitClustersProducer::ShallowRechitClustersProducer(const edm::ParameterSet& iConfig)
0012     : Suffix(iConfig.getParameter<std::string>("Suffix")),
0013       Prefix(iConfig.getParameter<std::string>("Prefix")),
0014       geomToken_(esConsumes<TrackerGeometry, TrackerDigiGeometryRecord>()),
0015       clusters_token_(consumes<edmNew::DetSetVector<SiStripCluster>>(iConfig.getParameter<edm::InputTag>("Clusters"))) {
0016   std::vector<edm::InputTag> rec_hits_tags = iConfig.getParameter<std::vector<edm::InputTag>>("InputTags");
0017   for (const auto& itag : rec_hits_tags) {
0018     rec_hits_tokens_.push_back(consumes<SiStripRecHit2DCollection>(itag));
0019   }
0020 
0021   produces<std::vector<float>>(Prefix + "strip" + Suffix);
0022   produces<std::vector<float>>(Prefix + "merr" + Suffix);
0023   produces<std::vector<float>>(Prefix + "localx" + Suffix);
0024   produces<std::vector<float>>(Prefix + "localy" + Suffix);
0025   produces<std::vector<float>>(Prefix + "localxerr" + Suffix);
0026   produces<std::vector<float>>(Prefix + "localyerr" + Suffix);
0027   produces<std::vector<float>>(Prefix + "globalx" + Suffix);
0028   produces<std::vector<float>>(Prefix + "globaly" + Suffix);
0029   produces<std::vector<float>>(Prefix + "globalz" + Suffix);
0030 }
0031 
0032 void ShallowRechitClustersProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0033   shallow::CLUSTERMAP clustermap = shallow::make_cluster_map(iEvent, clusters_token_);
0034 
0035   int size = clustermap.size();
0036   auto strip = std::make_unique<std::vector<float>>(size, -10000);
0037   auto merr = std::make_unique<std::vector<float>>(size, -10000);
0038   auto localx = std::make_unique<std::vector<float>>(size, -10000);
0039   auto localy = std::make_unique<std::vector<float>>(size, -10000);
0040   auto localxerr = std::make_unique<std::vector<float>>(size, -1);
0041   auto localyerr = std::make_unique<std::vector<float>>(size, -1);
0042   auto globalx = std::make_unique<std::vector<float>>(size, -10000);
0043   auto globaly = std::make_unique<std::vector<float>>(size, -10000);
0044   auto globalz = std::make_unique<std::vector<float>>(size, -10000);
0045 
0046   edm::ESHandle<TrackerGeometry> theTrackerGeometry = iSetup.getHandle(geomToken_);
0047 
0048   for (auto recHit_token : rec_hits_tokens_) {
0049     edm::Handle<SiStripRecHit2DCollection> recHits;
0050     iEvent.getByToken(recHit_token, recHits);
0051     for (auto const& ds : *recHits) {
0052       for (auto const& hit : ds) {
0053         shallow::CLUSTERMAP::iterator cluster =
0054             clustermap.find(std::make_pair(hit.geographicalId().rawId(), hit.cluster()->firstStrip()));
0055         if (cluster != clustermap.end()) {
0056           const StripGeomDetUnit* theStripDet =
0057               dynamic_cast<const StripGeomDetUnit*>(theTrackerGeometry->idToDet(hit.geographicalId()));
0058           unsigned int i = cluster->second;
0059           strip->at(i) = theStripDet->specificTopology().strip(hit.localPosition());
0060           merr->at(i) = sqrt(
0061               theStripDet->specificTopology().measurementError(hit.localPosition(), hit.localPositionError()).uu());
0062           localx->at(i) = hit.localPosition().x();
0063           localy->at(i) = hit.localPosition().y();
0064           localxerr->at(i) = sqrt(hit.localPositionError().xx());
0065           localyerr->at(i) = sqrt(hit.localPositionError().yy());
0066           globalx->at(i) = theStripDet->toGlobal(hit.localPosition()).x();
0067           globaly->at(i) = theStripDet->toGlobal(hit.localPosition()).y();
0068           globalz->at(i) = theStripDet->toGlobal(hit.localPosition()).z();
0069         } else {
0070           throw cms::Exception("cluster not found");
0071         }
0072       }
0073     }
0074   }
0075 
0076   iEvent.put(std::move(strip), Prefix + "strip" + Suffix);
0077   iEvent.put(std::move(merr), Prefix + "merr" + Suffix);
0078   iEvent.put(std::move(localx), Prefix + "localx" + Suffix);
0079   iEvent.put(std::move(localy), Prefix + "localy" + Suffix);
0080   iEvent.put(std::move(localxerr), Prefix + "localxerr" + Suffix);
0081   iEvent.put(std::move(localyerr), Prefix + "localyerr" + Suffix);
0082   iEvent.put(std::move(globalx), Prefix + "globalx" + Suffix);
0083   iEvent.put(std::move(globaly), Prefix + "globaly" + Suffix);
0084   iEvent.put(std::move(globalz), Prefix + "globalz" + Suffix);
0085 }