CMS 3D CMS Logo

MisalignedTrackerESProducer.cc
Go to the documentation of this file.
1 // Framework
8 
9 // Conditions database
12 
13 // Geometry
19 
20 // Alignment
25 
26 // C++
27 #include <memory>
28 #include <algorithm>
29 
36 
38 public:
41 
44 
46  std::unique_ptr<TrackerGeometry> produce(const TrackerDigiGeometryRecord& iRecord);
47 
48 private:
49  const bool theSaveToDB;
50  const bool
54 };
55 
56 //__________________________________________________________________________________________________
57 //__________________________________________________________________________________________________
58 //__________________________________________________________________________________________________
59 
60 //__________________________________________________________________________________________________
62  : theSaveToDB(p.getUntrackedParameter<bool>("saveToDbase")),
63  theSaveFakeScenario(p.getUntrackedParameter<bool>("saveFakeScenario")),
64  theScenario(p.getParameter<edm::ParameterSet>("scenario")),
65  theAlignRecordName("TrackerAlignmentRcd"),
66  theErrorRecordName("TrackerAlignmentErrorExtendedRcd") {
67  setWhatProduced(this);
68 }
69 
70 //__________________________________________________________________________________________________
72 
73 //__________________________________________________________________________________________________
74 std::unique_ptr<TrackerGeometry> MisalignedTrackerESProducer::produce(const TrackerDigiGeometryRecord& iRecord) {
75  //Retrieve tracker topology from geometry
77  iRecord.getRecord<TrackerTopologyRcd>().get(tTopoHandle);
78  const TrackerTopology* const tTopo = tTopoHandle.product();
79 
80  edm::LogInfo("MisalignedTracker") << "Producer called";
81 
82  // Create the tracker geometry from ideal geometry
84  iRecord.getRecord<IdealGeometryRecord>().get(gD);
86  iRecord.getRecord<PTrackerParametersRcd>().get(ptp);
88  std::unique_ptr<TrackerGeometry> theTracker(trackerBuilder.build(&(*gD), *ptp, tTopo));
89 
90  // Create the alignable hierarchy
91  auto theAlignableTracker = std::make_unique<AlignableTracker>(&(*theTracker), tTopo);
92 
93  // Create misalignment scenario, apply to geometry
94  TrackerScenarioBuilder scenarioBuilder(&(*theAlignableTracker));
95  scenarioBuilder.applyScenario(theScenario);
96  Alignments* alignments = theAlignableTracker->alignments();
97  AlignmentErrorsExtended* alignmentErrors = theAlignableTracker->alignmentErrors();
98 
99  // Store result to EventSetup
100  GeometryAligner aligner;
101  aligner.applyAlignments<TrackerGeometry>(&(*theTracker),
102  alignments,
103  alignmentErrors,
104  AlignTransform()); // dummy global position
105 
106  // Write alignments to DB: have to sort beforhand!
107  if (theSaveToDB) {
108  // Call service
110  if (!poolDbService.isAvailable()) // Die if not available
111  throw cms::Exception("NotAvailable") << "PoolDBOutputService not available";
112  if (theSaveFakeScenario) { // make empty!
113  alignments->clear();
114  alignmentErrors->clear();
115  }
116  poolDbService->writeOne<Alignments>(alignments, poolDbService->currentTime(), theAlignRecordName);
117  poolDbService->writeOne<AlignmentErrorsExtended>(alignmentErrors, poolDbService->currentTime(), theErrorRecordName);
118  } else {
119  // poolDbService::writeOne takes over ownership
120  // we have to delete in the case that containers are not written
121  delete alignments;
122  delete alignmentErrors;
123  }
124 
125  edm::LogInfo("MisalignedTracker") << "Producer done";
126  return theTracker;
127 }
128 
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:138
const bool theSaveFakeScenario
whether or not writing to DB
Class to update a given geometry with a set of alignments.
TrackerGeometry * build(const GeometricDet *gd, const PTrackerParameters &ptp, const TrackerTopology *tTopo)
~MisalignedTrackerESProducer() override
Destructor.
MisalignedTrackerESProducer(const edm::ParameterSet &p)
Constructor.
const std::string theAlignRecordName
misalignment scenario
bool isAvailable() const
Definition: Service.h:40
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
void applyAlignments(C *geometry, const Alignments *alignments, const AlignmentErrorsExtended *alignmentErrors, const AlignTransform &globalCoordinates)
const edm::ParameterSet theScenario
if theSaveToDB is true, save a fake scenario (empty alignments), irrespective of the misalignment sce...
HLT enums.
std::unique_ptr< TrackerGeometry > produce(const TrackerDigiGeometryRecord &iRecord)
Produce the misaligned tracker geometry and store it.
Builds a scenario from configuration and applies it to the alignable tracker.
T const * product() const
Definition: ESHandle.h:86