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 {
39 public:
40 
43 
45  ~MisalignedTrackerESProducer() override;
46 
48  std::shared_ptr<TrackerGeometry> produce(const TrackerDigiGeometryRecord& iRecord);
49 
50 private:
51  const bool theSaveToDB;
52  const bool theSaveFakeScenario;
55 
56  std::shared_ptr<TrackerGeometry> theTracker;
57 };
58 
59 //__________________________________________________________________________________________________
60 //__________________________________________________________________________________________________
61 //__________________________________________________________________________________________________
62 
63 
64 
65 //__________________________________________________________________________________________________
67  theSaveToDB(p.getUntrackedParameter<bool>("saveToDbase")),
68  theSaveFakeScenario(p.getUntrackedParameter<bool>("saveFakeScenario")),
69  theScenario(p.getParameter<edm::ParameterSet>("scenario")),
70  theAlignRecordName("TrackerAlignmentRcd"),
71  theErrorRecordName("TrackerAlignmentErrorExtendedRcd")
72 {
73  setWhatProduced(this);
74 
75 }
76 
77 
78 //__________________________________________________________________________________________________
80 
81 
82 //__________________________________________________________________________________________________
83 std::shared_ptr<TrackerGeometry>
85 {
86  //Retrieve tracker topology from geometry
88  iRecord.getRecord<TrackerTopologyRcd>().get(tTopoHandle);
89  const TrackerTopology* const tTopo = tTopoHandle.product();
90 
91  edm::LogInfo("MisalignedTracker") << "Producer called";
92 
93  // Create the tracker geometry from ideal geometry
95  iRecord.getRecord<IdealGeometryRecord>().get( gD );
97  iRecord.getRecord<PTrackerParametersRcd>().get( ptp );
99  theTracker = std::shared_ptr<TrackerGeometry>( trackerBuilder.build(&(*gD), *ptp, tTopo));
100 
101  // Create the alignable hierarchy
102  auto theAlignableTracker = std::make_unique<AlignableTracker>( &(*theTracker), tTopo );
103 
104  // Create misalignment scenario, apply to geometry
105  TrackerScenarioBuilder scenarioBuilder( &(*theAlignableTracker) );
106  scenarioBuilder.applyScenario( theScenario );
107  Alignments* alignments = theAlignableTracker->alignments();
108  AlignmentErrorsExtended* alignmentErrors = theAlignableTracker->alignmentErrors();
109 
110  // Store result to EventSetup
111  GeometryAligner aligner;
112  aligner.applyAlignments<TrackerGeometry>( &(*theTracker), alignments, alignmentErrors,
113  AlignTransform()); // dummy global position
114 
115  // Write alignments to DB: have to sort beforhand!
116  if (theSaveToDB) {
117 
118  // Call service
120  if( !poolDbService.isAvailable() ) // Die if not available
121  throw cms::Exception("NotAvailable") << "PoolDBOutputService not available";
122  if (theSaveFakeScenario) { // make empty!
123  alignments->clear();
124  alignmentErrors->clear();
125  }
126  poolDbService->writeOne<Alignments>(alignments, poolDbService->currentTime(),
128  poolDbService->writeOne<AlignmentErrorsExtended>(alignmentErrors, poolDbService->currentTime(),
130  } else {
131  // poolDbService::writeOne takes over ownership
132  // we have to delete in the case that containers are not written
133  delete alignments;
134  delete alignmentErrors;
135  }
136 
137 
138  edm::LogInfo("MisalignedTracker") << "Producer done";
139  return theTracker;
140 
141 }
142 
143 
const bool theSaveFakeScenario
whether or not writing to DB
std::shared_ptr< TrackerGeometry > produce(const TrackerDigiGeometryRecord &iRecord)
Produce the misaligned tracker geometry and store it.
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.
void setWhatProduced(T *iThis, const es::Label &iLabel=es::Label())
Definition: ESProducer.h:115
std::shared_ptr< TrackerGeometry > theTracker
MisalignedTrackerESProducer(const edm::ParameterSet &p)
Constructor.
const std::string theAlignRecordName
misalignment scenario
bool isAvailable() const
Definition: Service.h:46
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
void applyAlignments(C *geometry, const Alignments *alignments, const AlignmentErrorsExtended *alignmentErrors, const AlignTransform &globalCoordinates)
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
const edm::ParameterSet theScenario
if theSaveToDB is true, save a fake scenario (empty alignments), irrespective of the misalignment sce...
HLT enums.
Builds a scenario from configuration and applies it to the alignable tracker.
T const * product() const
Definition: ESHandle.h:86