Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:29:01

0001 //
0002 // Original Author:  Elisabetta Manca
0003 //         Created:  Wed, 01 Aug 2018 12:02:51 GMT
0004 //
0005 //
0006 
0007 // system include files
0008 #include <memory>
0009 
0010 // user include files
0011 #include "FWCore/Framework/interface/Frameworkfwd.h"
0012 #include "FWCore/Framework/interface/one/EDFilter.h"
0013 
0014 #include "FWCore/Framework/interface/Event.h"
0015 #include "FWCore/Framework/interface/MakerMacros.h"
0016 
0017 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0018 #include "FWCore/Utilities/interface/StreamID.h"
0019 
0020 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0021 #include "DataFormats/TrackReco/interface/Track.h"
0022 #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
0023 #include "DataFormats/TrackingRecHit/interface/TrackingRecHitFwd.h"
0024 #include "DataFormats/SiStripDetId/interface/SiStripDetId.h"
0025 #include "TrackingTools/PatternTools/interface/Trajectory.h"
0026 #include "TrackingTools/TrackFitters/interface/TrajectoryStateCombiner.h"
0027 
0028 #include "Geometry/CommonDetUnit/interface/GlobalTrackingGeometry.h"
0029 #include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h"
0030 #include "DataFormats/GeometryCommonDetAlgo/interface/MeasurementPoint.h"
0031 #include "Geometry/CommonTopologies/interface/StripTopology.h"
0032 #include "Geometry/CommonTopologies/interface/TkRadialStripTopology.h"
0033 
0034 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
0035 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
0036 #include "SimTracker/TrackerHitAssociation/interface/TrackerHitAssociator.h"
0037 
0038 #include "RecoTracker/TransientTrackingRecHit/interface/TkTransientTrackingRecHitBuilder.h"
0039 #include "TrackingTools/Records/interface/TransientRecHitRecord.h"
0040 #include "RecoLocalTracker/ClusterParameterEstimator/interface/FakeCPE.h"
0041 #include "RecoLocalTracker/ClusterParameterEstimator/interface/PixelFakeCPE.h"
0042 #include "RecoLocalTracker/ClusterParameterEstimator/interface/StripFakeCPE.h"
0043 
0044 //
0045 // class declaration
0046 //
0047 
0048 class FakeCPEFiller final : public edm::one::EDFilter<> {
0049 public:
0050   explicit FakeCPEFiller(const edm::ParameterSet&);
0051   ~FakeCPEFiller() = default;
0052 
0053   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0054 
0055 private:
0056   bool filter(edm::Event&, const edm::EventSetup&) override;
0057 
0058   // ----------member data ---------------------------
0059 
0060   edm::EDGetTokenT<std::vector<Trajectory> > inputTraj_;
0061   TrackerHitAssociator::Config trackerHitAssociatorConfig_;
0062   edm::ESGetToken<TransientTrackingRecHitBuilder, TransientRecHitRecord> theBToken_;
0063   edm::ESGetToken<GlobalTrackingGeometry, GlobalTrackingGeometryRecord> globalGeometryToken_;
0064 
0065   FakeCPE fakeCPE;
0066 };
0067 
0068 //
0069 // constants, enums and typedefs
0070 //
0071 
0072 //
0073 // static data member definitions
0074 //
0075 
0076 //
0077 // constructors and destructor
0078 //
0079 FakeCPEFiller::FakeCPEFiller(const edm::ParameterSet& iConfig)
0080     : inputTraj_(consumes<std::vector<Trajectory> >(edm::InputTag("FinalTracks"))),
0081       trackerHitAssociatorConfig_(iConfig, consumesCollector()),
0082       theBToken_(esConsumes(edm::ESInputTag("", "Fake"))),
0083       globalGeometryToken_(esConsumes()) {}
0084 
0085 // ------------ method called on each new Event  ------------
0086 bool FakeCPEFiller::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0087   bool accept = true;
0088   fakeCPE.map().clear();
0089 
0090   edm::ESHandle<TransientTrackingRecHitBuilder> theB = iSetup.getHandle(theBToken_);
0091 
0092   auto const& ttb = static_cast<TkTransientTrackingRecHitBuilder const&>(*theB);
0093   const_cast<StripFakeCPE*>(static_cast<StripFakeCPE const*>(ttb.stripClusterParameterEstimator()))
0094       ->setFakeCPE(&fakeCPE);
0095   const_cast<PixelFakeCPE*>(static_cast<PixelFakeCPE const*>(ttb.pixelClusterParameterEstimator()))
0096       ->setFakeCPE(&fakeCPE);
0097 
0098   using namespace edm;
0099 
0100   edm::ESHandle<GlobalTrackingGeometry> globalGeometry = iSetup.getHandle(globalGeometryToken_);
0101 
0102   Handle<std::vector<Trajectory> > trajH;
0103   iEvent.getByToken(inputTraj_, trajH);
0104 
0105   TrackerHitAssociator HitAssoc(iEvent, trackerHitAssociatorConfig_);
0106 
0107   using LocalValues = std::pair<LocalPoint, LocalError>;
0108 
0109   for (unsigned int j = 0; j < trajH->size(); ++j) {
0110     const std::vector<TrajectoryMeasurement>& tms = (*trajH)[j].measurements();
0111 
0112     for (unsigned int i = 0; i < tms.size(); ++i) {
0113       TrajectoryStateOnSurface updatedState = tms[i].updatedState();
0114 
0115       if (!updatedState.isValid())
0116         continue;
0117 
0118       if (!tms[i].recHit()->isValid())
0119         continue;
0120 
0121       auto const& thit = static_cast<BaseTrackerRecHit const&>(*tms[i].recHit());
0122       auto const& clus = thit.firstClusterRef();
0123 
0124       auto const& simHits = HitAssoc.associateHit(*(tms[i].recHit()));
0125 
0126       std::cout << "rechit " << thit.detUnit()->geographicalId().rawId() << ' ' << thit.localPosition() << ' '
0127                 << thit.localPositionError() << ' ' << simHits.size() << std::endl;
0128 
0129       /*        
0130         if (simHits.empty()) {
0131           LocalValues lv(thit.localPosition(),thit.localPositionError());
0132          // Fill The Map
0133          if (clus.isPixel())
0134               fakeCPE.map().add(clus.pixelCluster(), *thit.detUnit(),lv);
0135          else
0136              fakeCPE.map().add(clus.stripCluster(), *thit.detUnit(),lv);
0137         }
0138 
0139 */
0140 
0141       bool ok = false;
0142       for (auto const& sh : simHits) {
0143         if (sh.processType() != 0)
0144           continue;
0145 
0146         std::cout << "simhit " << sh.localPosition() << std::endl;
0147 
0148         // fill with simhit and rechit error (in alternative hand-made error)
0149         LocalValues lv(sh.localPosition(), thit.localPositionError());
0150         //LocalValues lv(thit.localPosition(),thit.localPositionError());  // fill with rechit (to verify nothing changes!)
0151         // Fill The Map
0152         if (clus.isPixel())
0153           fakeCPE.map().add(clus.pixelCluster(), *thit.detUnit(), lv);
0154         else
0155           fakeCPE.map().add(clus.stripCluster(), *thit.detUnit(), lv);
0156         ok = true;
0157         break;
0158 
0159       }  // closes loop on simHits
0160       if (!ok) {
0161         std::cout << "SimHit non found in det " << thit.detUnit()->geographicalId().rawId() << std::endl;
0162         accept = false;
0163       }
0164     }  // closes loop on trajectory measurements
0165 
0166   }  // closes loop on trajectories
0167 
0168   return accept;  // false if  just one hit did not match
0169 }
0170 
0171 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0172 void FakeCPEFiller::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0173   //The following says we do not know what parameters are allowed so do no validation
0174   // Please change this to state exactly what you do use, even if it is no parameters
0175   edm::ParameterSetDescription desc;
0176   desc.setUnknown();
0177   descriptions.addDefault(desc);
0178 }
0179 //define this as a plug-in
0180 DEFINE_FWK_MODULE(FakeCPEFiller);