CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
AlignmentProducer.cc
Go to the documentation of this file.
1 
8 #include "AlignmentProducer.h"
13 
15 
16 // System include files
17 #include <memory>
18 #include <sstream>
19 
20 // Framework
26 
28 
29 // Conditions database
32 
33 // Geometry
57 
58 // Tracking, LAS and cluster flag map (fwd is enough!)
63 
64 // Alignment
73 
74 //_____________________________________________________________________________
76  theAlignmentAlgo(0), theAlignmentParameterStore(0),
77  theAlignableExtras(0), theAlignableTracker(0), theAlignableMuon(0),
78  globalPositions_(0),
79  nevent_(0), theParameterSet(iConfig),
80  theMaxLoops( iConfig.getUntrackedParameter<unsigned int>("maxLoops") ),
81  stNFixAlignables_(iConfig.getParameter<int>("nFixAlignables") ),
82  stRandomShift_(iConfig.getParameter<double>("randomShift")),
83  stRandomRotation_(iConfig.getParameter<double>("randomRotation")),
84  applyDbAlignment_( iConfig.getUntrackedParameter<bool>("applyDbAlignment")),
85  doMisalignmentScenario_(iConfig.getParameter<bool>("doMisalignmentScenario")),
86  saveToDB_(iConfig.getParameter<bool>("saveToDB")),
87  saveApeToDB_(iConfig.getParameter<bool>("saveApeToDB")),
88  saveDeformationsToDB_(iConfig.getParameter<bool>("saveDeformationsToDB")),
89  doTracker_( iConfig.getUntrackedParameter<bool>("doTracker") ),
90  doMuon_( iConfig.getUntrackedParameter<bool>("doMuon") ),
91  useExtras_( iConfig.getUntrackedParameter<bool>("useExtras") ),
92  useSurvey_( iConfig.getParameter<bool>("useSurvey") ),
93  tjTkAssociationMapTag_(iConfig.getParameter<edm::InputTag>("tjTkAssociationMapTag")),
94  beamSpotTag_(iConfig.getParameter<edm::InputTag>("beamSpotTag")),
95  tkLasBeamTag_(iConfig.getParameter<edm::InputTag>("tkLasBeamTag")),
96  clusterValueMapTag_(iConfig.getParameter<edm::InputTag>("hitPrescaleMapTag"))
97 {
98  edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::AlignmentProducer";
99 
100  // Tell the framework what data is being produced
101  if (doTracker_) {
103  }
104  if (doMuon_) {
107  }
108 
109  // Create the alignment algorithm
110  edm::ParameterSet algoConfig = iConfig.getParameter<edm::ParameterSet>( "algoConfig" );
111  edm::VParameterSet iovSelection = iConfig.getParameter<edm::VParameterSet>( "RunRangeSelection" );
112  algoConfig.addUntrackedParameter<edm::VParameterSet>( "RunRangeSelection", iovSelection );
113  std::string algoName = algoConfig.getParameter<std::string>( "algoName" );
114  theAlignmentAlgo = AlignmentAlgorithmPluginFactory::get( )->create( algoName, algoConfig );
115 
116  // Check if found
117  if ( !theAlignmentAlgo )
118  throw cms::Exception("BadConfig") << "Couldn't find algorithm called " << algoName;
119 
120  edm::ParameterSet monitorConfig = iConfig.getParameter<edm::ParameterSet>( "monitorConfig" );
121  std::vector<std::string> monitors = monitorConfig.getUntrackedParameter<std::vector<std::string> >( "monitors" );
122 
123  for (std::vector<std::string>::const_iterator miter = monitors.begin(); miter != monitors.end(); ++miter) {
124  AlignmentMonitorBase* newMonitor = AlignmentMonitorPluginFactory::get()->create(*miter, monitorConfig.getUntrackedParameter<edm::ParameterSet>(*miter));
125 
126  if (!newMonitor) throw cms::Exception("BadConfig") << "Couldn't find monitor named " << *miter;
127 
128  theMonitors.push_back(newMonitor);
129  }
130 }
131 
132 
133 //_____________________________________________________________________________
134 // Delete new objects
136 {
138  delete theAlignableExtras;
139  delete theAlignableTracker;
140  delete theAlignableMuon;
141 
142  delete globalPositions_;
143 }
144 
145 
146 //_____________________________________________________________________________
147 // Produce tracker geometry
148 boost::shared_ptr<TrackerGeometry>
150 {
151  edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::produceTracker";
152  return theTracker;
153 }
154 
155 //_____________________________________________________________________________
156 // Produce muonDT geometry
157 boost::shared_ptr<DTGeometry>
159 {
160  edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::produceDT";
161  return theMuonDT;
162 }
163 
164 //_____________________________________________________________________________
165 // Produce muonCSC geometry
166 boost::shared_ptr<CSCGeometry>
168 {
169  edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::produceCSC";
170  return theMuonCSC;
171 }
172 
173 
174 //_____________________________________________________________________________
175 // Initialize algorithm
177 {
178  edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::beginOfJob";
179 
180  // Create the geometries from the ideal geometries (first time only)
181  this->createGeometries_( iSetup );
182 
183  // Retrieve and apply alignments, if requested (requires DB setup)
184  if ( applyDbAlignment_ ) {
185  // we need GlobalPositionRcd - and have to keep track for later removal
186  // before writing again to DB...
187  edm::ESHandle<Alignments> globalPositionRcd;
188  iSetup.get<GlobalPositionRcd>().get(globalPositionRcd);
189  globalPositions_ = new Alignments(*globalPositionRcd);
190 
191  if ( doTracker_ ) { // apply to tracker
192  this->applyDB<TrackerGeometry,TrackerAlignmentRcd,TrackerAlignmentErrorRcd>
193  (&(*theTracker), iSetup,
195  this->applyDB<TrackerGeometry,TrackerSurfaceDeformationRcd>(&(*theTracker), iSetup);
196  }
197 
198  if ( doMuon_ ) { // apply to tracker
199  this->applyDB<DTGeometry,DTAlignmentRcd,DTAlignmentErrorRcd>
200  (&(*theMuonDT), iSetup,
202  this->applyDB<CSCGeometry,CSCAlignmentRcd,CSCAlignmentErrorRcd>
203  (&(*theMuonCSC), iSetup,
205  }
206  }
207 
208  // Create alignable tracker and muon
209  if (doTracker_) {
211  }
212 
213  if (doMuon_) {
215  }
216 
217  if (useExtras_) {
219  }
220 
221  // Create alignment parameter builder
222  edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::beginOfJob"
223  << "Creating AlignmentParameterBuilder";
224  edm::ParameterSet aliParamBuildCfg =
225  theParameterSet.getParameter<edm::ParameterSet>("ParameterBuilder");
226  AlignmentParameterBuilder alignmentParameterBuilder(theAlignableTracker,
229  aliParamBuildCfg );
230  // Fix alignables if requested
231  if (stNFixAlignables_>0) alignmentParameterBuilder.fixAlignables(stNFixAlignables_);
232 
233  // Get list of alignables
234  Alignables theAlignables = alignmentParameterBuilder.alignables();
235  edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::beginOfJob"
236  << "got " << theAlignables.size() << " alignables";
237 
238  // Create AlignmentParameterStore
239  edm::ParameterSet aliParamStoreCfg =
241  theAlignmentParameterStore = new AlignmentParameterStore(theAlignables, aliParamStoreCfg);
242  edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::beginOfJob"
243  << "AlignmentParameterStore created!";
244 
245  // Apply misalignment scenario to alignable tracker and muon if requested
246  // WARNING: this assumes scenarioConfig can be passed to both muon and tracker
248  edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::beginOfJob"
249  << "Applying misalignment scenario to "
250  << (doTracker_ ? "tracker" : "")
251  << (doMuon_ ? (doTracker_ ? " and muon" : "muon") : ".");
252  edm::ParameterSet scenarioConfig
253  = theParameterSet.getParameter<edm::ParameterSet>( "MisalignmentScenario" );
254  if (doTracker_) {
255  TrackerScenarioBuilder scenarioBuilder( theAlignableTracker );
256  scenarioBuilder.applyScenario( scenarioConfig );
257  }
258  if (doMuon_) {
259  MuonScenarioBuilder muonScenarioBuilder( theAlignableMuon );
260  muonScenarioBuilder.applyScenario( scenarioConfig );
261  }
262  } else {
263  edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::beginOfJob"
264  << "NOT applying misalignment scenario!";
265  }
266 
267  // Apply simple misalignment
268  const std::string sParSel(theParameterSet.getParameter<std::string>("parameterSelectorSimple"));
269  this->simpleMisalignment_(theAlignables, sParSel, stRandomShift_, stRandomRotation_, true);
270 
271  // Initialize alignment algorithm
272  theAlignmentAlgo->initialize( iSetup,
274  theAlignmentParameterStore );
275 
276  for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = theMonitors.begin();
277  monitor != theMonitors.end(); ++monitor) {
278  (*monitor)->beginOfJob(theAlignableTracker, theAlignableMuon, theAlignmentParameterStore);
279  }
280 }
281 
282 //_____________________________________________________________________________
283 // Terminate algorithm
285 {
286  edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::endOfJob";
287 
288  for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = theMonitors.begin(); monitor != theMonitors.end(); ++monitor) {
289  (*monitor)->endOfJob();
290  }
291 
292  if (0 == nevent_) {
293  edm::LogError("Alignment") << "@SUB=AlignmentProducer::endOfJob" << "Did not process any "
294  << "events in last loop, do not dare to store to DB.";
295  } else {
296 
297  // Save alignments to database
298  if (saveToDB_ || saveApeToDB_) {
299 
300  // Expand run ranges and make them unique
301  edm::VParameterSet RunRangeSelectionVPSet = theParameterSet.getParameter<edm::VParameterSet>( "RunRangeSelection" );
302  RunRanges uniqueRunRanges = makeNonOverlappingRunRanges(RunRangeSelectionVPSet);
303 
304  if ( doTracker_ ) { // first tracker
305  const AlignTransform *trackerGlobal = 0; // will be 'removed' from constants
306  if (globalPositions_) { // i.e. applied before in applyDB
309  }
310  // Get alignments+errors - ownership taken over by writeDB(..), so no delete
311 
312  for (std::vector<RunRange>::const_iterator iRunRange = uniqueRunRanges.begin();
313  iRunRange != uniqueRunRanges.end();
314  ++iRunRange) {
316  Alignments *alignments = theAlignableTracker->alignments();
318  this->writeDB(alignments, "TrackerAlignmentRcd",
319  alignmentErrors, "TrackerAlignmentErrorRcd", trackerGlobal,
320  (*iRunRange).first);
321  }
322  }
323 
324  if ( doMuon_ ) { // now muon
325  const AlignTransform *muonGlobal = 0; // will be 'removed' from constants
326  if (globalPositions_) { // i.e. applied before in applyDB
328  DetId(DetId::Muon));
329  }
330  // Get alignments+errors, first DT - ownership taken over by writeDB(..), so no delete
331  Alignments *alignments = theAlignableMuon->dtAlignments();
332  AlignmentErrors *alignmentErrors = theAlignableMuon->dtAlignmentErrors();
333  this->writeDB(alignments, "DTAlignmentRcd",
334  alignmentErrors, "DTAlignmentErrorRcd", muonGlobal);
335 
336  // Get alignments+errors, now CSC - ownership taken over by writeDB(..), so no delete
337  alignments = theAlignableMuon->cscAlignments();
338  alignmentErrors = theAlignableMuon->cscAlignmentErrors();
339  this->writeDB(alignments, "CSCAlignmentRcd",
340  alignmentErrors, "CSCAlignmentErrorRcd", muonGlobal);
341  }
342 
343  // Save surface deformations to database
345  AlignmentSurfaceDeformations *alignmentSurfaceDeformations = theAlignableTracker->surfaceDeformations();
346  this->writeDB(alignmentSurfaceDeformations, "TrackerSurfaceDeformationRcd");
347  }
348 
349  }
350  }
351 
353 }
354 
355 //_____________________________________________________________________________
356 // Called at beginning of loop
357 void AlignmentProducer::startingNewLoop(unsigned int iLoop )
358 {
359  edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::startingNewLoop"
360  << "Starting loop number " << iLoop;
361 
362  nevent_ = 0;
363 
365 
366  for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = theMonitors.begin(); monitor != theMonitors.end(); ++monitor) {
367  (*monitor)->startingNewLoop();
368  }
369 
370  edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::startingNewLoop"
371  << "Now physically apply alignments to geometry...";
372 
373 
374  // Propagate changes to reconstruction geometry (from initialisation or iteration)
375  GeometryAligner aligner;
376  if ( doTracker_ ) {
377  std::auto_ptr<Alignments> alignments(theAlignableTracker->alignments());
378  std::auto_ptr<AlignmentErrors> alignmentErrors(theAlignableTracker->alignmentErrors());
379  aligner.applyAlignments<TrackerGeometry>( &(*theTracker),&(*alignments),&(*alignmentErrors), AlignTransform() ); // don't apply global a second time!
380  std::auto_ptr<AlignmentSurfaceDeformations> aliDeforms(theAlignableTracker->surfaceDeformations());
381  aligner.attachSurfaceDeformations<TrackerGeometry>(&(*theTracker), &(*aliDeforms));
382 
383  }
384  if ( doMuon_ ) {
385  std::auto_ptr<Alignments> dtAlignments( theAlignableMuon->dtAlignments());
386  std::auto_ptr<AlignmentErrors> dtAlignmentErrors( theAlignableMuon->dtAlignmentErrors());
387  std::auto_ptr<Alignments> cscAlignments( theAlignableMuon->cscAlignments());
388  std::auto_ptr<AlignmentErrors> cscAlignmentErrors( theAlignableMuon->cscAlignmentErrors());
389 
390  aligner.applyAlignments<DTGeometry>( &(*theMuonDT), &(*dtAlignments), &(*dtAlignmentErrors), AlignTransform() ); // don't apply global a second time!
391  aligner.applyAlignments<CSCGeometry>( &(*theMuonCSC), &(*cscAlignments), &(*cscAlignmentErrors), AlignTransform() ); // nope!
392  }
393 }
394 
395 
396 //_____________________________________________________________________________
397 // Called at end of loop
399 AlignmentProducer::endOfLoop(const edm::EventSetup& iSetup, unsigned int iLoop)
400 {
401 
402  if (0 == nevent_) {
403  // beginOfJob is usually called by the framework in the first event of the first loop
404  // (a hack: beginOfJob needs the EventSetup that is not well defined without an event)
405  // and the algorithms rely on the initialisations done in beginOfJob. We cannot call
406  // this->beginOfJob(iSetup); here either since that will access the EventSetup to get
407  // some geometry information that is not defined either without having seen an event.
408  edm::LogError("Alignment") << "@SUB=AlignmentProducer::endOfLoop"
409  << "Did not process any events in loop " << iLoop
410  << ", stop processing without terminating algorithm.";
411  return kStop;
412  }
413 
414  edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::endOfLoop"
415  << "Ending loop " << iLoop << ", terminating algorithm.";
416 
418 
419  for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = theMonitors.begin(); monitor != theMonitors.end(); ++monitor) {
420  (*monitor)->endOfLoop(iSetup);
421  }
422 
423  if ( iLoop == theMaxLoops-1 || iLoop >= theMaxLoops ) return kStop;
424  else return kContinue;
425 }
426 
427 //_____________________________________________________________________________
428 // Called at each event
431  const edm::EventSetup& setup )
432 {
433  ++nevent_;
434 
435  // reading in survey records
436  this->readInSurveyRcds(setup);
437 
438  // Printout event number
439  for ( int i=10; i<10000000; i*=10 )
440  if ( nevent_<10*i && (nevent_%i)==0 )
441  edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::duringLoop"
442  << "Events processed: " << nevent_;
443 
444  // Retrieve trajectories and tracks from the event
445  // -> merely skip if collection is empty
447  if (event.getByLabel(tjTkAssociationMapTag_, m_TrajTracksMap)) {
448 
449  // Form pairs of trajectories and tracks
450  ConstTrajTrackPairCollection trajTracks;
451  for ( TrajTrackAssociationCollection::const_iterator iPair = m_TrajTracksMap->begin();
452  iPair != m_TrajTracksMap->end(); ++iPair) {
453  trajTracks.push_back( ConstTrajTrackPair( &(*(*iPair).key), &(*(*iPair).val) ) );
454  }
456  event.getByLabel(beamSpotTag_, beamSpot);
457 
458  if (nevent_==1 && theAlignableExtras) {
459  edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::duringLoop"
460  << "initializing AlignableBeamSpot" << std::endl;
461  theAlignableExtras->initializeBeamSpot(beamSpot->x0(), beamSpot->y0(), beamSpot->z0(),
462  beamSpot->dxdz(), beamSpot->dydz());
463  }
464 
465  // Run the alignment algorithm with its input
466  const AliClusterValueMap *clusterValueMapPtr = 0;
467  if(clusterValueMapTag_.encode().size()){//check that the input tag is not empty
468  edm::Handle<AliClusterValueMap> clusterValueMap;
469  event.getByLabel(clusterValueMapTag_, clusterValueMap);
470  clusterValueMapPtr = &(*clusterValueMap);
471  }
472 
473  const AlignmentAlgorithmBase::EventInfo eventInfo(event.id(), trajTracks, *beamSpot,
474  clusterValueMapPtr);
475  theAlignmentAlgo->run(setup, eventInfo);
476 
477 
478  for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = theMonitors.begin();
479  monitor != theMonitors.end(); ++monitor) {
480  (*monitor)->duringLoop(event, setup, trajTracks); // forward eventInfo?
481  }
482  } else {
483  edm::LogError("Alignment") << "@SUB=AlignmentProducer::duringLoop"
484  << "No track collection found: skipping event";
485  }
486 
487 
488  return kContinue;
489 }
490 
491 // ----------------------------------------------------------------------------
493 {
494  theAlignmentAlgo->beginRun(setup); // do not forward edm::Run...
495 }
496 
497 // ----------------------------------------------------------------------------
499 {
500  // call with or without las beam info...
501  typedef AlignmentAlgorithmBase::EndRunInfo EndRunInfo;
502  if (tkLasBeamTag_.encode().size()) { // non-empty InputTag
505  run.getByLabel(tkLasBeamTag_, lasBeams);
506  run.getByLabel(tkLasBeamTag_, tsoses);
507 
508  theAlignmentAlgo->endRun(EndRunInfo(run.id(), &(*lasBeams), &(*tsoses)), setup);
509  } else {
510  edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::endRun"
511  << "No Tk LAS beams to forward to algorithm.";
512  theAlignmentAlgo->endRun(EndRunInfo(run.id(), 0, 0), setup);
513  }
514 }
515 
516 // ----------------------------------------------------------------------------
518  const edm::EventSetup &setup)
519 {
520  theAlignmentAlgo->beginLuminosityBlock(setup); // do not forward edm::LuminosityBlock
521 }
522 
523 // ----------------------------------------------------------------------------
525  const edm::EventSetup &setup)
526 {
527  theAlignmentAlgo->endLuminosityBlock(setup); // do not forward edm::LuminosityBlock
528 }
529 
530 // ----------------------------------------------------------------------------
531 
532 void AlignmentProducer::simpleMisalignment_(const Alignables &alivec, const std::string &selection,
533  float shift, float rot, bool local)
534 {
535 
536  std::ostringstream output; // collecting output
537 
538  if (shift > 0. || rot > 0.) {
539  output << "Adding random flat shift of max size " << shift
540  << " and adding random flat rotation of max size " << rot <<" to ";
541 
542  std::vector<bool> commSel(0);
543  if (selection != "-1") {
544  AlignmentParameterSelector aSelector(0,0); // no alignable needed here...
545  const std::vector<char> cSel(aSelector.convertParamSel(selection));
546  if (cSel.size() < RigidBodyAlignmentParameters::N_PARAM) {
547  throw cms::Exception("BadConfig")
548  << "[AlignmentProducer::simpleMisalignment_]\n"
549  << "Expect selection string '" << selection << "' to be at least of length "
550  << RigidBodyAlignmentParameters::N_PARAM << " or to be '-1'.\n"
551  << "(Most probably you have to adjust the parameter 'parameterSelectorSimple'.)";
552  }
553  for (std::vector<char>::const_iterator cIter = cSel.begin(); cIter != cSel.end(); ++cIter) {
554  commSel.push_back(*cIter == '0' ? false : true);
555  }
556  output << "parameters defined by (" << selection
557  << "), representing (x,y,z,alpha,beta,gamma),";
558  } else {
559  output << "the active parameters of each alignable,";
560  }
561  output << " in " << (local ? "local" : "global") << " frame.";
562 
563  for (std::vector<Alignable*>::const_iterator it = alivec.begin(); it != alivec.end(); ++it) {
564  Alignable* ali=(*it);
565  std::vector<bool> mysel(commSel.empty() ? ali->alignmentParameters()->selector() : commSel);
566 
567  if (std::abs(shift)>0.00001) {
568  double s0 = 0., s1 = 0., s2 = 0.;
569  if (mysel[RigidBodyAlignmentParameters::dx]) s0 = shift * double(random()%1000-500)/500.;
570  if (mysel[RigidBodyAlignmentParameters::dy]) s1 = shift * double(random()%1000-500)/500.;
571  if (mysel[RigidBodyAlignmentParameters::dz]) s2 = shift * double(random()%1000-500)/500.;
572 
573  if (local) ali->move( ali->surface().toGlobal(align::LocalVector(s0,s1,s2)) );
574  else ali->move( align::GlobalVector(s0,s1,s2) );
575 
576  //AlignmentPositionError ape(dx,dy,dz);
577  //ali->addAlignmentPositionError(ape);
578  }
579 
580  if (std::abs(rot)>0.00001) {
582  if (mysel[RigidBodyAlignmentParameters::dalpha]) r(1)=rot*double(random()%1000-500)/500.;
583  if (mysel[RigidBodyAlignmentParameters::dbeta]) r(2)=rot*double(random()%1000-500)/500.;
584  if (mysel[RigidBodyAlignmentParameters::dgamma]) r(3)=rot*double(random()%1000-500)/500.;
585 
586  const align::RotationType mrot = align::toMatrix(r);
587  if (local) ali->rotateInLocalFrame(mrot);
588  else ali->rotateInGlobalFrame(mrot);
589 
590  //ali->addAlignmentPositionErrorFromRotation(mrot);
591  }
592  } // end loop on alignables
593  } else {
594  output << "No simple misalignment added!";
595  }
596  edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::simpleMisalignment_" << output.str();
597 }
598 
599 
600 //__________________________________________________________________________________________________
602 {
604  iSetup.get<IdealGeometryRecord>().get( cpv );
605 
606  if (doTracker_) {
607  edm::ESHandle<GeometricDet> geometricDet;
608  iSetup.get<IdealGeometryRecord>().get( geometricDet );
609  TrackerGeomBuilderFromGeometricDet trackerBuilder;
610  theTracker = boost::shared_ptr<TrackerGeometry>( trackerBuilder.build(&(*geometricDet)) );
611  }
612 
613  if (doMuon_) {
615  iSetup.get<MuonNumberingRecord>().get(mdc);
616  DTGeometryBuilderFromDDD DTGeometryBuilder;
618  theMuonDT = boost::shared_ptr<DTGeometry>(new DTGeometry );
619  DTGeometryBuilder.build( theMuonDT, &(*cpv), *mdc);
620  theMuonCSC = boost::shared_ptr<CSCGeometry>( new CSCGeometry );
621  CSCGeometryBuilder.build( theMuonCSC, &(*cpv), *mdc );
622  }
623 }
624 
626 {
627  const std::vector<Alignable*>& comp = ali->components();
628 
629  unsigned int nComp = comp.size();
630 
631  for (unsigned int i = 0; i < nComp; ++i) addSurveyInfo_(comp[i]);
632 
634 
635  if ( ali->id() != error.rawId() ||
636  ali->alignableObjectId() != error.structureType() )
637  {
638  throw cms::Exception("DatabaseError")
639  << "Error reading survey info from DB. Mismatched id!";
640  }
641 
642  const CLHEP::Hep3Vector& pos = theSurveyValues->m_align[theSurveyIndex].translation();
643  const CLHEP::HepRotation& rot = theSurveyValues->m_align[theSurveyIndex].rotation();
644 
645  AlignableSurface surf( align::PositionType( pos.x(), pos.y(), pos.z() ),
646  align::RotationType( rot.xx(), rot.xy(), rot.xz(),
647  rot.yx(), rot.yy(), rot.yz(),
648  rot.zx(), rot.zy(), rot.zz() ) );
649 
650  surf.setWidth( ali->surface().width() );
651  surf.setLength( ali->surface().length() );
652 
653  ali->setSurvey( new SurveyDet( surf, error.matrix() ) );
654 
655  ++theSurveyIndex;
656 }
657 
659 
660  // Get Survey Rcds and add Survey Info
661  if ( doTracker_ && useSurvey_ ){
662  bool tkSurveyBool = watchTkSurveyRcd_.check(iSetup);
663  bool tkSurveyErrBool = watchTkSurveyErrRcd_.check(iSetup);
664  edm::LogInfo("Alignment") << "watcher tksurveyrcd: " << tkSurveyBool;
665  edm::LogInfo("Alignment") << "watcher tksurveyerrrcd: " << tkSurveyErrBool;
666  if ( tkSurveyBool || tkSurveyErrBool){
667 
668  edm::LogInfo("Alignment") << "ADDING THE SURVEY INFORMATION";
670  edm::ESHandle<SurveyErrors> surveyErrors;
671 
672  iSetup.get<TrackerSurveyRcd>().get(surveys);
673  iSetup.get<TrackerSurveyErrorRcd>().get(surveyErrors);
674 
675  theSurveyIndex = 0;
676  theSurveyValues = &*surveys;
677  theSurveyErrors = &*surveyErrors;
679  }
680  }
681 
682  if ( doMuon_ && useSurvey_) {
683  bool DTSurveyBool = watchTkSurveyRcd_.check(iSetup);
684  bool DTSurveyErrBool = watchTkSurveyErrRcd_.check(iSetup);
685  bool CSCSurveyBool = watchTkSurveyRcd_.check(iSetup);
686  bool CSCSurveyErrBool = watchTkSurveyErrRcd_.check(iSetup);
687 
688  if ( DTSurveyBool || DTSurveyErrBool || CSCSurveyBool || CSCSurveyErrBool ){
689  edm::ESHandle<Alignments> dtSurveys;
690  edm::ESHandle<SurveyErrors> dtSurveyErrors;
691  edm::ESHandle<Alignments> cscSurveys;
692  edm::ESHandle<SurveyErrors> cscSurveyErrors;
693 
694  iSetup.get<DTSurveyRcd>().get(dtSurveys);
695  iSetup.get<DTSurveyErrorRcd>().get(dtSurveyErrors);
696  iSetup.get<CSCSurveyRcd>().get(cscSurveys);
697  iSetup.get<CSCSurveyErrorRcd>().get(cscSurveyErrors);
698 
699  theSurveyIndex = 0;
700  theSurveyValues = &*dtSurveys;
701  theSurveyErrors = &*dtSurveyErrors;
702  std::vector<Alignable*> barrels = theAlignableMuon->DTBarrel();
703  for (std::vector<Alignable*>::const_iterator iter = barrels.begin(); iter != barrels.end(); ++iter) {
704  addSurveyInfo_(*iter);
705  }
706 
707  theSurveyIndex = 0;
708  theSurveyValues = &*cscSurveys;
709  theSurveyErrors = &*cscSurveyErrors;
710  std::vector<Alignable*> endcaps = theAlignableMuon->CSCEndcaps();
711  for (std::vector<Alignable*>::const_iterator iter = endcaps.begin(); iter != endcaps.end(); ++iter) {
712  addSurveyInfo_(*iter);
713  }
714  }
715  }
716 
717 }
718 
719 
721 // a templated method - but private, so not accessible from outside
722 // ==> does not have to be in header file
723 template<class G, class Rcd, class ErrRcd>
725  const AlignTransform &globalCoordinates) const
726 {
727  // 'G' is the geometry class for that DB should be applied,
728  // 'Rcd' is the record class for its Alignments
729  // 'ErrRcd' is the record class for its AlignmentErrors
730  // 'globalCoordinates' are global transformation for this geometry
731  edm::ESHandle<Alignments> alignments;
732  iSetup.get<Rcd>().get(alignments);
733 
734  edm::ESHandle<AlignmentErrors> alignmentErrors;
735  iSetup.get<ErrRcd>().get(alignmentErrors);
736 
737  GeometryAligner aligner;
738  aligner.applyAlignments<G>(geometry, &(*alignments), &(*alignmentErrors),
739  globalCoordinates);
740 }
741 
742 
744 // a templated method - but private, so not accessible from outside
745 // ==> does not have to be in header file
746 template<class G, class DeformationRcd>
748 {
749  // 'G' is the geometry class for that DB should be applied,
750  // 'DeformationRcd' is the record class for its surface deformations
752  iSetup.get<DeformationRcd>().get(surfaceDeformations);
753 
754  GeometryAligner aligner;
755  aligner.attachSurfaceDeformations<G>(geometry, &(*surfaceDeformations));
756 }
757 
758 
761  const std::string &alignRcd,
762  AlignmentErrors *alignmentErrors,
763  const std::string &errRcd,
764  const AlignTransform *globalCoordinates,
765  cond::Time_t time) const
766 {
767  Alignments * tempAlignments = alignments;
768  AlignmentErrors * tempAlignmentErrors = alignmentErrors;
769 
770  // Call service
772  if (!poolDb.isAvailable()) { // Die if not available
773  delete tempAlignments; // promised to take over ownership...
774  delete tempAlignmentErrors; // dito
775  throw cms::Exception("NotAvailable") << "PoolDBOutputService not available";
776  }
777 
778  if (globalCoordinates // happens only if (applyDbAlignment_ == true)
779  && globalCoordinates->transform() != AlignTransform::Transform::Identity) {
780 
781  tempAlignments = new Alignments(); // temporary storage for
782  tempAlignmentErrors = new AlignmentErrors(); // final alignments and errors
783 
784  GeometryAligner aligner;
785  aligner.removeGlobalTransform(alignments, alignmentErrors,
786  *globalCoordinates,
787  tempAlignments, tempAlignmentErrors);
788 
789  delete alignments; // have to delete original alignments
790  delete alignmentErrors; // same thing for the errors
791 
792  edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::writeDB"
793  << "globalCoordinates removed from alignments (" << alignRcd
794  << ") and errors (" << alignRcd << ").";
795  }
796 
797  if (saveToDB_) {
798  edm::LogInfo("Alignment") << "Writing Alignments to " << alignRcd << ".";
799  poolDb->writeOne<Alignments>(tempAlignments, 0, time, alignRcd);
800  } else { // poolDb->writeOne(..) takes over 'alignments' ownership,...
801  delete tempAlignments; // ...otherwise we have to delete, as promised!
802  }
803 
804  if (saveApeToDB_) {
805  edm::LogInfo("Alignment") << "Writing AlignmentErrors to " << errRcd << ".";
806  poolDb->writeOne<AlignmentErrors>(tempAlignmentErrors, 0, time, errRcd);
807  } else { // poolDb->writeOne(..) takes over 'alignmentErrors' ownership,...
808  delete tempAlignmentErrors; // ...otherwise we have to delete, as promised!
809  }
810 }
811 
812 
814 void AlignmentProducer::writeDB(AlignmentSurfaceDeformations *alignmentSurfaceDeformations,
815  const std::string &surfaceDeformationRcd) const
816 {
817  // Call service
819  if (!poolDb.isAvailable()) { // Die if not available
820  delete alignmentSurfaceDeformations; // promised to take over ownership...
821  throw cms::Exception("NotAvailable") << "PoolDBOutputService not available";
822  }
823 
824  if (saveDeformationsToDB_) {
825  edm::LogInfo("Alignment") << "Writing AlignmentSurfaceDeformations to "
826  << surfaceDeformationRcd << ".";
827  poolDb->writeOne<AlignmentSurfaceDeformations>(alignmentSurfaceDeformations, poolDb->beginOfTime(),
828  surfaceDeformationRcd);
829  } else { // poolDb->writeOne(..) takes over 'surfaceDeformation' ownership,...
830  delete alignmentSurfaceDeformations; // ...otherwise we have to delete, as promised!
831  }
832 }
833 
836 {
839 
840  RunRanges uniqueRunRanges;
841  std::map<RunNumber,RunNumber> uniqueFirstRunNumbers;
842  std::map<RunNumber,RunNumber> uniqueLastRunNumbers;
843  if (RunRangeSelectionVPSet.size()==0) {
844  uniqueFirstRunNumbers[beginValue] = beginValue;
845  uniqueLastRunNumbers[endValue] = endValue;
846  } else {
847  for (std::vector<edm::ParameterSet>::const_iterator ipset = RunRangeSelectionVPSet.begin();
848  ipset != RunRangeSelectionVPSet.end();
849  ++ipset) {
850  const std::vector<std::string> RunRangeStrings = (*ipset).getParameter<std::vector<std::string> >("RunRanges");
851  for (std::vector<std::string>::const_iterator irange = RunRangeStrings.begin();
852  irange != RunRangeStrings.end();
853  ++irange) {
854  std::vector<std::string> tokens = edm::tokenize(*irange, ":");
855  long int temp;
856 
857  RunNumber first = beginValue;
858  temp = strtol(tokens[0].c_str(), 0, 0);
859  if (temp!=-1) first = temp;
860  uniqueFirstRunNumbers[first] = first;
861 
862  RunNumber last = endValue;
863  temp = strtol(tokens[1].c_str(), 0, 0);
864  if (temp!=-1) last = temp;
865  uniqueLastRunNumbers[last] = last;
866  }
867  }
868  }
869 
870  for (std::map<RunNumber,RunNumber>::iterator iFirst = uniqueFirstRunNumbers.begin();
871  iFirst!=uniqueFirstRunNumbers.end();
872  ++iFirst) {
873  for (std::map<RunNumber,RunNumber>::iterator iLast = uniqueLastRunNumbers.begin();
874  iLast!=uniqueLastRunNumbers.end();
875  ++iLast) {
876  if ((*iLast).first>(*iFirst).first) {
877  uniqueRunRanges.push_back(std::pair<RunNumber,RunNumber>((*iFirst).first, (*iLast).first));
878  break;
879  }
880  }
881  }
882 
883  return uniqueRunRanges;
884 }
885 
std::vector< Alignable * > Alignables
const TimeTypeSpecs timeTypeSpecs[]
Definition: Time.cc:22
align::Scalar width() const
AlignmentProducer(const edm::ParameterSet &iConfig)
Constructor.
virtual void beginLuminosityBlock(const edm::EventSetup &setup)
called at begin of luminosity block (no lumi block info passed yet)
virtual void beginRun(const edm::EventSetup &setup)
called at begin of run
T getParameter(std::string const &) const
align::ID id() const
Return the ID of Alignable, i.e. DetId of &#39;first&#39; component GeomDet(Unit).
Definition: Alignable.h:180
bool getByLabel(std::string const &label, Handle< PROD > &result) const
Definition: Run.h:175
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
virtual void terminate()=0
Call at end of job (must be implemented in derived class)
AlignmentErrors * dtAlignmentErrors()
boost::shared_ptr< TrackerGeometry > theTracker
virtual void rotateInLocalFrame(const RotationType &rotation)
Rotation intepreted in the local reference frame.
Definition: Alignable.cc:89
const bool doMisalignmentScenario_
RunID const & id() const
Definition: RunBase.h:43
virtual void run(const edm::EventSetup &setup, const EventInfo &eventInfo)=0
Run the algorithm (must be implemented in derived class)
Builds a scenario from configuration and applies it to the alignable Muon.
AlignmentAlgorithmBase * theAlignmentAlgo
~AlignmentProducer()
Destructor.
virtual boost::shared_ptr< TrackerGeometry > produceTracker(const TrackerDigiGeometryRecord &iRecord)
Produce the tracker geometry.
Time_t beginValue
Definition: Time.h:45
Class to update a given geometry with a set of alignments.
void simpleMisalignment_(const Alignables &alivec, const std::string &selection, float shift, float rot, bool local)
Apply random shifts and rotations to selected alignables, according to configuration.
void readInSurveyRcds(const edm::EventSetup &)
read in survey records
std::vector< ParameterSet > VParameterSet
Definition: ParameterSet.h:30
ErrorMatrix matrix() const
Definition: SurveyError.h:72
virtual boost::shared_ptr< DTGeometry > produceDT(const MuonGeometryRecord &iRecord)
Produce the muon DT geometry.
virtual void endLuminosityBlock(const edm::EventSetup &setup)
called at end of luminosity block (no lumi block info passed yet)
virtual void beginRun(const edm::Run &run, const edm::EventSetup &setup)
Called at run start and calling algorithms beginRun.
#define abs(x)
Definition: mlp_lapack.h:159
#define DEFINE_FWK_LOOPER(type)
Definition: LooperFactory.h:99
virtual Status endOfLoop(const edm::EventSetup &, unsigned int iLoop)
Called at end of loop.
edm::ParameterSet theParameterSet
virtual void move(const GlobalVector &displacement)=0
Movement with respect to the global reference frame.
const std::vector< bool > & selector(void) const
Get alignment parameter selector vector.
void setWidth(align::Scalar width)
TRandom random
Definition: MVATrainer.cc:138
const edm::InputTag tkLasBeamTag_
const Alignments * theSurveyValues
void addSurveyInfo_(Alignable *)
Add survey info to an alignable.
uint8_t structureType() const
Definition: SurveyError.h:62
void createGeometries_(const edm::EventSetup &)
Create tracker and muon geometries.
virtual Alignables components() const =0
Return vector of all direct components.
std::vector< AlignTransform > m_align
Definition: Alignments.h:14
std::string encode() const
Definition: InputTag.cc:72
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
Definition: Alignable.h:57
void removeGlobalTransform(const Alignments *alignments, const AlignmentErrors *alignmentErrors, const AlignTransform &globalCoordinates, Alignments *newAlignments, AlignmentErrors *newAlignmentErrors)
void setWhatProduced(T *iThis, const es::Label &iLabel=es::Label())
Definition: ESProducer.h:115
const bool applyDbAlignment_
tuple s2
Definition: indexGen.py:106
virtual void endRun(const EndRunInfo &runInfo, const edm::EventSetup &setup)
called at end of run - order of arguments like in EDProducer etc.
AlignmentAlgorithmBase::RunNumber RunNumber
void build(boost::shared_ptr< CSCGeometry > geom, const DDCompactView *fv, const MuonDDDConstants &muonConstants)
Build the geometry.
void setLength(align::Scalar length)
const unsigned int theMaxLoops
AlignableExtras * theAlignableExtras
Alignments * dtAlignments()
unsigned long long Time_t
Definition: Time.h:16
boost::shared_ptr< CSCGeometry > theMuonCSC
std::vector< Alignable * > CSCEndcaps()
const edm::InputTag clusterValueMapTag_
void attachSurfaceDeformations(C *geometry, const AlignmentSurfaceDeformations *surfaceDeformations)
bool isAvailable() const
Definition: Service.h:47
unsigned int theSurveyIndex
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
AlignmentErrors * alignmentErrors() const
Return alignment errors, sorted by DetId.
AlignmentErrors * cscAlignmentErrors()
std::vector< AlignmentMonitorBase * > theMonitors
void applyAlignments(C *geometry, const Alignments *alignments, const AlignmentErrors *alignmentErrors, const AlignTransform &globalCoordinates)
virtual void startingNewLoop(unsigned int iLoop)
Called at beginning of loop.
RunRanges makeNonOverlappingRunRanges(const edm::VParameterSet &RunRangeSelectionVPSet)
AlignmentParameterStore * theAlignmentParameterStore
align::ID rawId() const
Definition: SurveyError.h:67
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
virtual void setParametersForRunRange(const RunRange &rr)
AlignmentSurfaceDeformations * surfaceDeformations() const
Return surface deformations, sorted by DetId.
Definition: Alignable.cc:214
virtual void initialize(const edm::EventSetup &setup, AlignableTracker *tracker, AlignableMuon *muon, AlignableExtras *extras, AlignmentParameterStore *store)=0
Call at beginning of job (must be implemented in derived class)
void applyScenario(const edm::ParameterSet &scenario)
Apply misalignment scenario to the tracker.
boost::shared_ptr< DTGeometry > theMuonDT
void initializeBeamSpot(double x, double y, double z, double dxdz, double dydz)
Initialize the alignable beam spot with the given parameters.
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
const edm::InputTag beamSpotTag_
bool first
Definition: L1TdeRCT.cc:79
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
virtual void endRun(const edm::Run &run, const edm::EventSetup &setup)
Called at run end - currently reading TkFittedLasBeam if an InpuTag is given for that.
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
Definition: Alignable.h:126
const SurveyErrors * theSurveyErrors
const edm::InputTag tjTkAssociationMapTag_
edm::ESWatcher< TrackerSurveyErrorRcd > watchTkSurveyErrRcd_
virtual Status duringLoop(const edm::Event &event, const edm::EventSetup &setup)
Called at each event.
std::vector< Alignable * > DTBarrel()
Definition: DetId.h:20
AlignableMuon * theAlignableMuon
const bool saveDeformationsToDB_
virtual void endOfJob()
Called at end of job.
AlgebraicVector EulerAngles
Definition: Definitions.h:36
align::Scalar length() const
const double stRandomShift_
virtual void beginOfJob()
Definition: EDLooperBase.cc:74
Transform transform() const
void build(boost::shared_ptr< DTGeometry > theGeometry, const DDCompactView *cview, const MuonDDDConstants &muonConstants)
virtual void rotateInGlobalFrame(const RotationType &rotation)=0
void addUntrackedParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:203
std::vector< std::string > tokenize(std::string const &input, std::string const &separator)
breaks the input string into tokens, delimited by the separator
Definition: Parse.cc:57
void setSurvey(const SurveyDet *)
Set survey info.
Definition: Alignable.cc:243
const T & get() const
Definition: EventSetup.h:55
virtual void endLuminosityBlock(const edm::LuminosityBlock &lumiBlock, const edm::EventSetup &setup)
Called at lumi block end, calling algorithm&#39;s endLuminosityBlock.
std::vector< ConstTrajTrackPair > ConstTrajTrackPairCollection
Alignments * cscAlignments()
TrackerGeometry * build(const GeometricDet *gd)
void dump(void) const
define run information passed to algorithms (in endRun)
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:59
ESHandle< TrackerGeometry > geometry
edm::EventID id() const
Definition: EventBase.h:56
virtual boost::shared_ptr< CSCGeometry > produceCSC(const MuonGeometryRecord &iRecord)
Produce the muon CSC geometry.
edm::ESWatcher< TrackerSurveyRcd > watchTkSurveyRcd_
align::GlobalPoints toGlobal(const align::LocalPoints &) const
Return in global coord given a set of local points.
AlignableTracker * theAlignableTracker
RotationType toMatrix(const EulerAngles &)
Convert rotation angles about x-, y-, z-axes to matrix.
Definition: Utilities.cc:40
virtual void beginLuminosityBlock(const edm::LuminosityBlock &lumiBlock, const edm::EventSetup &setup)
Called at lumi block start, calling algorithm&#39;s beginLuminosityBlock.
std::vector< char > convertParamSel(const std::string &selString) const
Converting std::string into std::vector&lt;char&gt;
void writeDB(Alignments *alignments, const std::string &alignRcd, AlignmentErrors *alignmentErrors, const std::string &errRcd, const AlignTransform *globalCoordinates, cond::Time_t time=cond::timeTypeSpecs[cond::runnumber].beginValue) const
static unsigned int const shift
void applyDB(G *geometry, const edm::EventSetup &iSetup, const AlignTransform &globalPosition) const
const AlignTransform & DetectorGlobalPosition(const Alignments &allGlobals, const DetId &id)
Alignments * alignments() const
Return alignments, sorted by DetId.
Time_t endValue
Definition: Time.h:46
std::vector< SurveyError > m_surveyErrors
Definition: SurveyErrors.h:21
std::pair< const Trajectory *, const reco::Track * > ConstTrajTrackPair
Builds a scenario from configuration and applies it to the alignable tracker.
const Alignments * globalPositions_
GlobalPositions that might be read from DB, NULL otherwise.
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
void applyScenario(const edm::ParameterSet &scenario)
Apply misalignment scenario to the Muon.
T get(const Candidate &c)
Definition: component.h:56
const double stRandomRotation_
Definition: Run.h:32
define event information passed to algorithms
std::vector< RunRange > RunRanges