Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-22 06:26:43

0001 // -*- C++ -*-
0002 //
0003 //
0004 // Description: Module to add a custom APE to the alignment object
0005 //
0006 //
0007 // Original Author:  Frederic Ronga
0008 //         Created:  December 5, 2006
0009 //
0010 
0011 // system include files
0012 
0013 // user include files
0014 //#include "FWCore/Framework/interface/Frameworkfwd.h"
0015 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0016 
0017 #include "FWCore/Framework/interface/EventSetup.h"
0018 #include "FWCore/Framework/interface/ESHandle.h"
0019 #include "FWCore/Framework/interface/MakerMacros.h"
0020 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0021 
0022 // Conditions database
0023 #include "FWCore/ServiceRegistry/interface/Service.h"
0024 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0025 
0026 #include "Alignment/TrackerAlignment/interface/AlignableTracker.h"
0027 
0028 #include "CondFormats/AlignmentRecord/interface/TrackerAlignmentRcd.h"
0029 #include "CondFormats/Alignment/interface/AlignmentErrorsExtended.h"
0030 #include "CondFormats/AlignmentRecord/interface/TrackerAlignmentErrorExtendedRcd.h"
0031 #include "DataFormats/GeometryCommonDetAlgo/interface/AlignmentPositionError.h"
0032 
0033 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0034 
0035 // Class declaration
0036 class ApeAdder : public edm::one::EDAnalyzer<> {
0037 public:
0038   explicit ApeAdder(const edm::ParameterSet&);
0039   ~ApeAdder() override = default;
0040 
0041   void analyze(const edm::Event&, const edm::EventSetup&) override;
0042 
0043 private:
0044   // methods
0045   void addApe(const align::Alignables& alignables);
0046 
0047 private:
0048   // members
0049   const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> tTopoToken_;
0050   const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> tkGeomToken_;
0051   std::string theErrorRecordName;
0052   std::vector<double> theApe;  // Amount of APE to add (from config.)
0053 };
0054 
0055 ApeAdder::ApeAdder(const edm::ParameterSet& iConfig)
0056     : tTopoToken_(esConsumes()), tkGeomToken_(esConsumes()), theErrorRecordName("TrackerAlignmentErrorExtendedRcd") {
0057   // The APE to set to all GeomDets
0058   theApe = iConfig.getUntrackedParameter<std::vector<double> >("apeVector");
0059 }
0060 
0061 //__________________________________________________________________________________________________
0062 void ApeAdder::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
0063 
0064 {
0065   //Retrieve tracker topology from geometry
0066   const TrackerTopology* const tTopo = &iSetup.getData(tTopoToken_);
0067   // Get geometry from ES
0068   const TrackerGeometry* trackerGeometry = &iSetup.getData(tkGeomToken_);
0069 
0070   // Create the alignable hierarchy
0071   AlignableTracker* theAlignableTracker = new AlignableTracker(&(*trackerGeometry), tTopo);
0072 
0073   // Now loop on alignable dets and add alignment error
0074   if (theAlignableTracker->barrelGeomDets().size())
0075     this->addApe(theAlignableTracker->barrelGeomDets());
0076   if (theAlignableTracker->pixelHalfBarrelGeomDets().size())
0077     this->addApe(theAlignableTracker->pixelHalfBarrelGeomDets());
0078   if (theAlignableTracker->endcapGeomDets().size())
0079     this->addApe(theAlignableTracker->endcapGeomDets());
0080   if (theAlignableTracker->TIDGeomDets().size())
0081     this->addApe(theAlignableTracker->TIDGeomDets());
0082   if (theAlignableTracker->pixelEndcapGeomDets().size())
0083     this->addApe(theAlignableTracker->pixelEndcapGeomDets());
0084 
0085   // Store to DB
0086   AlignmentErrorsExtended* alignmentErrors = theAlignableTracker->alignmentErrors();
0087 
0088   // Call service
0089   edm::Service<cond::service::PoolDBOutputService> poolDbService;
0090   if (!poolDbService.isAvailable())  // Die if not available
0091     throw cms::Exception("NotAvailable") << "PoolDBOutputService not available";
0092 
0093   // Save to DB (assuming that the delete below will also delete the concerned payload )
0094   poolDbService->writeOneIOV<AlignmentErrorsExtended>(
0095       *alignmentErrors, poolDbService->beginOfTime(), theErrorRecordName);
0096 
0097   delete theAlignableTracker;
0098 }
0099 
0100 void ApeAdder::addApe(const align::Alignables& alignables) {
0101   AlignmentPositionError ape(theApe[0], theApe[1], theApe[2]);
0102   for (const auto& iDet : alignables) {
0103     iDet->setAlignmentPositionError(ape, true);  // true: propagate to components
0104   }
0105 }
0106 
0107 //define this as a plug-in
0108 DEFINE_FWK_MODULE(ApeAdder);