00001
00002
00003
00004
00005
00006
00007
00008 #include "AlignmentProducer.h"
00009 #include "FWCore/Framework/interface/LooperFactory.h"
00010 #include "Alignment/CommonAlignmentAlgorithm/interface/AlignmentParameterBuilder.h"
00011 #include "Alignment/CommonAlignmentAlgorithm/interface/AlignmentParameterStore.h"
00012 #include "Alignment/CommonAlignment/interface/Alignable.h"
00013
00014 #include "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"
00015
00016
00017 #include <memory>
00018 #include <sstream>
00019
00020
00021 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00022 #include "FWCore/Framework/interface/Event.h"
00023 #include "FWCore/Framework/interface/EventSetup.h"
00024
00025
00026 #include "FWCore/ServiceRegistry/interface/Service.h"
00027 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
00028
00029
00030 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00031 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeomBuilderFromGeometricDet.h"
00032 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00033 #include "Geometry/CSCGeometry/interface/CSCGeometry.h"
00034 #include "Geometry/Records/interface/MuonNumberingRecord.h"
00035 #include "Geometry/DTGeometryBuilder/src/DTGeometryBuilderFromDDD.h"
00036 #include "Geometry/CSCGeometryBuilder/src/CSCGeometryBuilderFromDDD.h"
00037 #include "Geometry/TrackingGeometryAligner/interface/GeometryAligner.h"
00038 #include "CondFormats/AlignmentRecord/interface/TrackerAlignmentRcd.h"
00039 #include "CondFormats/AlignmentRecord/interface/TrackerAlignmentErrorRcd.h"
00040 #include "CondFormats/AlignmentRecord/interface/DTAlignmentRcd.h"
00041 #include "CondFormats/AlignmentRecord/interface/DTAlignmentErrorRcd.h"
00042 #include "CondFormats/AlignmentRecord/interface/CSCAlignmentRcd.h"
00043 #include "CondFormats/AlignmentRecord/interface/CSCAlignmentErrorRcd.h"
00044 #include "CondFormats/AlignmentRecord/interface/TrackerSurveyRcd.h"
00045 #include "CondFormats/AlignmentRecord/interface/TrackerSurveyErrorRcd.h"
00046 #include "CondFormats/AlignmentRecord/interface/DTSurveyRcd.h"
00047 #include "CondFormats/AlignmentRecord/interface/DTSurveyErrorRcd.h"
00048 #include "CondFormats/AlignmentRecord/interface/CSCSurveyRcd.h"
00049 #include "CondFormats/AlignmentRecord/interface/CSCSurveyErrorRcd.h"
00050 #include "CondFormats/AlignmentRecord/interface/GlobalPositionRcd.h"
00051 #include "CondFormats/Alignment/interface/DetectorGlobalPosition.h"
00052
00053
00054
00055
00056 #include "CondFormats/Alignment/interface/SurveyErrors.h"
00057 #include "Alignment/TrackerAlignment/interface/TrackerScenarioBuilder.h"
00058 #include "Alignment/MuonAlignment/interface/MuonScenarioBuilder.h"
00059 #include "Alignment/CommonAlignment/interface/SurveyDet.h"
00060 #include "Alignment/CommonAlignmentParametrization/interface/RigidBodyAlignmentParameters.h"
00061 #include "Alignment/CommonAlignmentAlgorithm/interface/AlignmentAlgorithmPluginFactory.h"
00062 #include "Alignment/CommonAlignmentMonitor/interface/AlignmentMonitorPluginFactory.h"
00063 #include "Alignment/CommonAlignmentAlgorithm/interface/AlignmentParameterSelector.h"
00064
00065
00066 AlignmentProducer::AlignmentProducer(const edm::ParameterSet& iConfig) :
00067 theAlignmentAlgo(0), theAlignmentParameterStore(0),
00068 theAlignableTracker(0), theAlignableMuon(0),
00069 nevent_(0), theParameterSet(iConfig),
00070 theMaxLoops( iConfig.getUntrackedParameter<unsigned int>("maxLoops",0) ),
00071 stNFixAlignables_(iConfig.getParameter<int>("nFixAlignables") ),
00072 stRandomShift_(iConfig.getParameter<double>("randomShift")),
00073 stRandomRotation_(iConfig.getParameter<double>("randomRotation")),
00074 applyDbAlignment_( iConfig.getUntrackedParameter<bool>("applyDbAlignment",false) ),
00075 doMisalignmentScenario_(iConfig.getParameter<bool>("doMisalignmentScenario")),
00076 saveToDB_(iConfig.getParameter<bool>("saveToDB")),
00077 doTracker_( iConfig.getUntrackedParameter<bool>("doTracker") ),
00078 doMuon_( iConfig.getUntrackedParameter<bool>("doMuon") ),
00079 useSurvey_( iConfig.getParameter<bool>("useSurvey") )
00080 {
00081
00082 edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::AlignmentProducer";
00083
00084
00085 if (doTracker_) {
00086 setWhatProduced(this, &AlignmentProducer::produceTracker);
00087 }
00088 if (doMuon_) {
00089 setWhatProduced(this, &AlignmentProducer::produceDT);
00090 setWhatProduced(this, &AlignmentProducer::produceCSC);
00091 }
00092
00093
00094 edm::ParameterSet algoConfig = iConfig.getParameter<edm::ParameterSet>( "algoConfig" );
00095 std::string algoName = algoConfig.getParameter<std::string>("algoName");
00096 theAlignmentAlgo = AlignmentAlgorithmPluginFactory::get( )->create( algoName, algoConfig );
00097
00098
00099 if ( !theAlignmentAlgo )
00100 throw cms::Exception("BadConfig") << "Couldn't find algorithm called " << algoName;
00101
00102 edm::ParameterSet monitorConfig = iConfig.getParameter<edm::ParameterSet>( "monitorConfig" );
00103 std::vector<std::string> monitors = monitorConfig.getUntrackedParameter<std::vector<std::string> >( "monitors" );
00104
00105 for (std::vector<std::string>::const_iterator miter = monitors.begin(); miter != monitors.end(); ++miter) {
00106 AlignmentMonitorBase* newMonitor = AlignmentMonitorPluginFactory::get()->create(*miter, monitorConfig.getUntrackedParameter<edm::ParameterSet>(*miter));
00107
00108 if (!newMonitor) throw cms::Exception("BadConfig") << "Couldn't find monitor named " << *miter;
00109
00110 theMonitors.push_back(newMonitor);
00111 }
00112
00113 }
00114
00115
00116
00117
00118 AlignmentProducer::~AlignmentProducer()
00119 {
00120
00121 delete theAlignmentParameterStore;
00122 delete theAlignableTracker;
00123 delete theAlignableMuon;
00124
00125 }
00126
00127
00128
00129
00130 boost::shared_ptr<TrackerGeometry>
00131 AlignmentProducer::produceTracker( const TrackerDigiGeometryRecord& iRecord )
00132 {
00133 edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::produceTracker";
00134 return theTracker;
00135 }
00136
00137
00138
00139 boost::shared_ptr<DTGeometry>
00140 AlignmentProducer::produceDT( const MuonGeometryRecord& iRecord )
00141 {
00142 edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::produceDT";
00143 return theMuonDT;
00144 }
00145
00146
00147
00148 boost::shared_ptr<CSCGeometry>
00149 AlignmentProducer::produceCSC( const MuonGeometryRecord& iRecord )
00150 {
00151 edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::produceCSC";
00152 return theMuonCSC;
00153 }
00154
00155
00156
00157
00158 void AlignmentProducer::beginOfJob( const edm::EventSetup& iSetup )
00159 {
00160 edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::beginOfJob";
00161
00162 nevent_ = 0;
00163 GeometryAligner aligner;
00164
00165
00166 this->createGeometries_( iSetup );
00167
00168
00169 if ( applyDbAlignment_ ) {
00170
00171 edm::ESHandle<Alignments> globalPositionRcd;
00172 iSetup.get<GlobalPositionRcd>().get(globalPositionRcd);
00173 if ( doTracker_ ) {
00174 edm::ESHandle<Alignments> alignments;
00175 iSetup.get<TrackerAlignmentRcd>().get( alignments );
00176 edm::ESHandle<AlignmentErrors> alignmentErrors;
00177 iSetup.get<TrackerAlignmentErrorRcd>().get( alignmentErrors );
00178 aligner.applyAlignments<TrackerGeometry>( &(*theTracker), &(*alignments), &(*alignmentErrors),
00179 align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Tracker)) );
00180 }
00181 if ( doMuon_ ) {
00182 edm::ESHandle<Alignments> dtAlignments;
00183 iSetup.get<DTAlignmentRcd>().get( dtAlignments );
00184 edm::ESHandle<AlignmentErrors> dtAlignmentErrors;
00185 iSetup.get<DTAlignmentErrorRcd>().get( dtAlignmentErrors );
00186 aligner.applyAlignments<DTGeometry>( &(*theMuonDT), &(*dtAlignments), &(*dtAlignmentErrors),
00187 align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Muon)) );
00188
00189 edm::ESHandle<Alignments> cscAlignments;
00190 iSetup.get<CSCAlignmentRcd>().get( cscAlignments );
00191 edm::ESHandle<AlignmentErrors> cscAlignmentErrors;
00192 iSetup.get<CSCAlignmentErrorRcd>().get( cscAlignmentErrors );
00193 aligner.applyAlignments<CSCGeometry>( &(*theMuonCSC), &(*cscAlignments), &(*cscAlignmentErrors),
00194 align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Muon)) );
00195 }
00196 }
00197
00198
00199 if (doTracker_)
00200 {
00201 theAlignableTracker = new AlignableTracker( &(*theTracker) );
00202
00203 if (useSurvey_)
00204 {
00205 edm::ESHandle<Alignments> surveys;
00206 edm::ESHandle<SurveyErrors> surveyErrors;
00207
00208 iSetup.get<TrackerSurveyRcd>().get(surveys);
00209 iSetup.get<TrackerSurveyErrorRcd>().get(surveyErrors);
00210
00211 theSurveyIndex = 0;
00212 theSurveyValues = &*surveys;
00213 theSurveyErrors = &*surveyErrors;
00214 addSurveyInfo_(theAlignableTracker);
00215 }
00216 }
00217
00218 if (doMuon_)
00219 {
00220 theAlignableMuon = new AlignableMuon( &(*theMuonDT), &(*theMuonCSC) );
00221
00222 if (useSurvey_)
00223 {
00224 edm::ESHandle<Alignments> dtSurveys;
00225 edm::ESHandle<SurveyErrors> dtSurveyErrors;
00226 edm::ESHandle<Alignments> cscSurveys;
00227 edm::ESHandle<SurveyErrors> cscSurveyErrors;
00228
00229 iSetup.get<DTSurveyRcd>().get(dtSurveys);
00230 iSetup.get<DTSurveyErrorRcd>().get(dtSurveyErrors);
00231 iSetup.get<CSCSurveyRcd>().get(cscSurveys);
00232 iSetup.get<CSCSurveyErrorRcd>().get(cscSurveyErrors);
00233
00234 theSurveyIndex = 0;
00235 theSurveyValues = &*dtSurveys;
00236 theSurveyErrors = &*dtSurveyErrors;
00237 std::vector<Alignable*> barrels = theAlignableMuon->DTBarrel();
00238 for (std::vector<Alignable*>::const_iterator iter = barrels.begin(); iter != barrels.end(); ++iter) {
00239 addSurveyInfo_(*iter);
00240 }
00241
00242 theSurveyIndex = 0;
00243 theSurveyValues = &*cscSurveys;
00244 theSurveyErrors = &*cscSurveyErrors;
00245 std::vector<Alignable*> endcaps = theAlignableMuon->CSCEndcaps();
00246 for (std::vector<Alignable*>::const_iterator iter = endcaps.begin(); iter != endcaps.end(); ++iter) {
00247 addSurveyInfo_(*iter);
00248 }
00249 }
00250 }
00251
00252
00253 edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::beginOfJob"
00254 << "Creating AlignmentParameterBuilder";
00255 edm::ParameterSet aliParamBuildCfg =
00256 theParameterSet.getParameter<edm::ParameterSet>("ParameterBuilder");
00257 AlignmentParameterBuilder alignmentParameterBuilder(theAlignableTracker,
00258 theAlignableMuon,
00259 aliParamBuildCfg );
00260
00261 if (stNFixAlignables_>0) alignmentParameterBuilder.fixAlignables(stNFixAlignables_);
00262
00263
00264 Alignables theAlignables = alignmentParameterBuilder.alignables();
00265 edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::beginOfJob"
00266 << "got " << theAlignables.size() << " alignables";
00267
00268
00269 edm::ParameterSet aliParamStoreCfg =
00270 theParameterSet.getParameter<edm::ParameterSet>("ParameterStore");
00271 theAlignmentParameterStore = new AlignmentParameterStore(theAlignables, aliParamStoreCfg);
00272 edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::beginOfJob"
00273 << "AlignmentParameterStore created!";
00274
00275
00276
00277 if (doMisalignmentScenario_ && (doTracker_ || doMuon_)) {
00278 edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::beginOfJob"
00279 << "Applying misalignment scenario to "
00280 << (doTracker_ ? "tracker" : "")
00281 << (doMuon_ ? (doTracker_ ? " and muon" : "muon") : ".");
00282 edm::ParameterSet scenarioConfig
00283 = theParameterSet.getParameter<edm::ParameterSet>( "MisalignmentScenario" );
00284 if (doTracker_) {
00285 TrackerScenarioBuilder scenarioBuilder( theAlignableTracker );
00286 scenarioBuilder.applyScenario( scenarioConfig );
00287 }
00288 if (doMuon_) {
00289 MuonScenarioBuilder muonScenarioBuilder( theAlignableMuon );
00290 muonScenarioBuilder.applyScenario( scenarioConfig );
00291 }
00292 } else {
00293 edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::beginOfJob"
00294 << "NOT applying misalignment scenario!";
00295 }
00296
00297
00298 const std::string sParSel(theParameterSet.getParameter<std::string>("parameterSelectorSimple"));
00299 this->simpleMisalignment_(theAlignables, sParSel, stRandomShift_, stRandomRotation_, true);
00300
00301
00302 theAlignmentAlgo->initialize( iSetup, theAlignableTracker,
00303 theAlignableMuon, theAlignmentParameterStore );
00304
00305 for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = theMonitors.begin(); monitor != theMonitors.end(); ++monitor) {
00306 (*monitor)->beginOfJob(theAlignableTracker, theAlignableMuon, theAlignmentParameterStore);
00307 }
00308 }
00309
00310
00311
00312 void AlignmentProducer::endOfJob()
00313 {
00314 edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::endOfJob";
00315
00316 for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = theMonitors.begin(); monitor != theMonitors.end(); ++monitor) {
00317 (*monitor)->endOfJob();
00318 }
00319
00320
00321 if (saveToDB_) {
00322 edm::LogInfo("Alignment") << "Writing Alignments to DB...";
00323
00324 edm::Service<cond::service::PoolDBOutputService> poolDbService;
00325 if( !poolDbService.isAvailable() )
00326 throw cms::Exception("NotAvailable") << "PoolDBOutputService not available";
00327
00328 if ( doTracker_ ) {
00329
00330 Alignments* alignments = theAlignableTracker->alignments();
00331 AlignmentErrors* alignmentErrors = theAlignableTracker->alignmentErrors();
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343 const std::string alignRecordName("TrackerAlignmentRcd");
00344 const std::string errorRecordName("TrackerAlignmentErrorRcd");
00345
00346 poolDbService->writeOne<Alignments>(alignments, poolDbService->beginOfTime(),
00347 alignRecordName);
00348 poolDbService->writeOne<AlignmentErrors>(alignmentErrors, poolDbService->beginOfTime(),
00349 errorRecordName);
00350 }
00351
00352 if ( doMuon_ ) {
00353
00354 Alignments* dtAlignments = theAlignableMuon->dtAlignments();
00355 AlignmentErrors* dtAlignmentErrors = theAlignableMuon->dtAlignmentErrors();
00356 Alignments* cscAlignments = theAlignableMuon->cscAlignments();
00357 AlignmentErrors* cscAlignmentErrors = theAlignableMuon->cscAlignmentErrors();
00358
00359
00360
00361
00362
00363
00364
00365 const std::string dtAlignRecordName("DTAlignmentRcd");
00366 const std::string dtErrorRecordName("DTAlignmentErrorRcd");
00367 const std::string cscAlignRecordName("CSCAlignmentRcd");
00368 const std::string cscErrorRecordName("CSCAlignmentErrorRcd");
00369
00370 poolDbService->writeOne<Alignments>(dtAlignments, poolDbService->beginOfTime(),
00371 dtAlignRecordName);
00372 poolDbService->writeOne<AlignmentErrors>(dtAlignmentErrors, poolDbService->beginOfTime(),
00373 dtErrorRecordName);
00374
00375 poolDbService->writeOne<Alignments>(cscAlignments, poolDbService->beginOfTime(),
00376 cscAlignRecordName);
00377 poolDbService->writeOne<AlignmentErrors>(cscAlignmentErrors, poolDbService->beginOfTime(),
00378 cscErrorRecordName);
00379 }
00380 }
00381 }
00382
00383
00384
00385 void AlignmentProducer::startingNewLoop(unsigned int iLoop )
00386 {
00387 edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::startingNewLoop"
00388 << "Starting loop number " << iLoop;
00389
00390 theAlignmentAlgo->startNewLoop();
00391
00392 for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = theMonitors.begin(); monitor != theMonitors.end(); ++monitor) {
00393 (*monitor)->startingNewLoop();
00394 }
00395
00396 edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::startingNewLoop"
00397 << "Now physically apply alignments to geometry...";
00398
00399
00400
00401 GeometryAligner aligner;
00402 if ( doTracker_ ) {
00403 std::auto_ptr<Alignments> alignments(theAlignableTracker->alignments());
00404 std::auto_ptr<AlignmentErrors> alignmentErrors(theAlignableTracker->alignmentErrors());
00405 aligner.applyAlignments<TrackerGeometry>( &(*theTracker),&(*alignments),&(*alignmentErrors), AlignTransform() );
00406 }
00407 if ( doMuon_ ) {
00408 std::auto_ptr<Alignments> dtAlignments( theAlignableMuon->dtAlignments());
00409 std::auto_ptr<AlignmentErrors> dtAlignmentErrors( theAlignableMuon->dtAlignmentErrors());
00410 std::auto_ptr<Alignments> cscAlignments( theAlignableMuon->cscAlignments());
00411 std::auto_ptr<AlignmentErrors> cscAlignmentErrors( theAlignableMuon->cscAlignmentErrors());
00412
00413 aligner.applyAlignments<DTGeometry>( &(*theMuonDT), &(*dtAlignments), &(*dtAlignmentErrors), AlignTransform() );
00414 aligner.applyAlignments<CSCGeometry>( &(*theMuonCSC), &(*cscAlignments), &(*cscAlignmentErrors), AlignTransform() );
00415 }
00416 }
00417
00418
00419
00420
00421 edm::EDLooper::Status
00422 AlignmentProducer::endOfLoop(const edm::EventSetup& iSetup, unsigned int iLoop)
00423 {
00424 edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::endOfLoop"
00425 << "Ending loop " << iLoop;
00426
00427 edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::endOfLoop"
00428 << "Terminating algorithm.";
00429 theAlignmentAlgo->terminate();
00430
00431 for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = theMonitors.begin(); monitor != theMonitors.end(); ++monitor) {
00432 (*monitor)->endOfLoop(iSetup);
00433 }
00434
00435 if ( iLoop == theMaxLoops-1 || iLoop >= theMaxLoops ) return kStop;
00436 else return kContinue;
00437 }
00438
00439
00440
00441 edm::EDLooper::Status
00442 AlignmentProducer::duringLoop( const edm::Event& event,
00443 const edm::EventSetup& setup )
00444 {
00445 nevent_++;
00446
00447
00448 for ( int i=10; i<10000000; i*=10 )
00449 if ( nevent_<10*i && (nevent_%i)==0 )
00450 edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::duringLoop"
00451 << "Events processed: " << nevent_;
00452
00453
00454
00455 edm::InputTag tjTag = theParameterSet.getParameter<edm::InputTag>("tjTkAssociationMapTag");
00456 edm::Handle<TrajTrackAssociationCollection> m_TrajTracksMap;
00457 if ( event.getByLabel( tjTag, m_TrajTracksMap ) ) {
00458
00459
00460 ConstTrajTrackPairCollection trajTracks;
00461 for ( TrajTrackAssociationCollection::const_iterator iPair = m_TrajTracksMap->begin();
00462 iPair != m_TrajTracksMap->end(); iPair++ )
00463 trajTracks.push_back( ConstTrajTrackPair( &(*(*iPair).key), &(*(*iPair).val) ) );
00464
00465
00466 theAlignmentAlgo->run( setup, trajTracks );
00467
00468 for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = theMonitors.begin(); monitor != theMonitors.end(); ++monitor) {
00469 (*monitor)->duringLoop(setup, trajTracks);
00470 }
00471 } else {
00472 edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::duringLoop"
00473 << "No track collection found: skipping event";
00474 }
00475
00476
00477 return kContinue;
00478 }
00479
00480
00481
00482 void AlignmentProducer::simpleMisalignment_(const Alignables &alivec, const std::string &selection,
00483 float shift, float rot, bool local)
00484 {
00485
00486 std::ostringstream output;
00487
00488 if (shift > 0. || rot > 0.) {
00489 output << "Adding random flat shift of max size " << shift
00490 << " and adding random flat rotation of max size " << rot <<" to ";
00491
00492 std::vector<bool> commSel(0);
00493 if (selection != "-1") {
00494 AlignmentParameterSelector aSelector(0,0);
00495 const std::vector<char> cSel(aSelector.convertParamSel(selection));
00496 if (cSel.size() < RigidBodyAlignmentParameters::N_PARAM) {
00497 throw cms::Exception("BadConfig")
00498 << "[AlignmentProducer::simpleMisalignment_]\n"
00499 << "Expect selection string '" << selection << "' to be at least of length "
00500 << RigidBodyAlignmentParameters::N_PARAM << " or to be '-1'.\n"
00501 << "(Most probably you have to adjust the parameter 'parameterSelectorSimple'.)";
00502 }
00503 for (std::vector<char>::const_iterator cIter = cSel.begin(); cIter != cSel.end(); ++cIter) {
00504 commSel.push_back(*cIter == '0' ? false : true);
00505 }
00506 output << "parameters defined by (" << selection
00507 << "), representing (x,y,z,alpha,beta,gamma),";
00508 } else {
00509 output << "the active parameters of each alignable,";
00510 }
00511 output << " in " << (local ? "local" : "global") << " frame.";
00512
00513 for (std::vector<Alignable*>::const_iterator it = alivec.begin(); it != alivec.end(); ++it) {
00514 Alignable* ali=(*it);
00515 std::vector<bool> mysel(commSel.empty() ? ali->alignmentParameters()->selector() : commSel);
00516
00517 if (std::abs(shift)>0.00001) {
00518 double s0 = 0., s1 = 0., s2 = 0.;
00519 if (mysel[RigidBodyAlignmentParameters::dx]) s0 = shift * double(random()%1000-500)/500.;
00520 if (mysel[RigidBodyAlignmentParameters::dy]) s1 = shift * double(random()%1000-500)/500.;
00521 if (mysel[RigidBodyAlignmentParameters::dz]) s2 = shift * double(random()%1000-500)/500.;
00522
00523 if (local) ali->move( ali->surface().toGlobal(align::LocalVector(s0,s1,s2)) );
00524 else ali->move( align::GlobalVector(s0,s1,s2) );
00525
00526
00527
00528 }
00529
00530 if (std::abs(rot)>0.00001) {
00531 align::EulerAngles r(3);
00532 if (mysel[RigidBodyAlignmentParameters::dalpha]) r(1)=rot*double(random()%1000-500)/500.;
00533 if (mysel[RigidBodyAlignmentParameters::dbeta]) r(2)=rot*double(random()%1000-500)/500.;
00534 if (mysel[RigidBodyAlignmentParameters::dgamma]) r(3)=rot*double(random()%1000-500)/500.;
00535
00536 const align::RotationType mrot = align::toMatrix(r);
00537 if (local) ali->rotateInLocalFrame(mrot);
00538 else ali->rotateInGlobalFrame(mrot);
00539
00540
00541 }
00542 }
00543 } else {
00544 output << "No simple misalignment added!";
00545 }
00546 edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::simpleMisalignment_" << output.str();
00547 }
00548
00549
00550
00551 void AlignmentProducer::createGeometries_( const edm::EventSetup& iSetup )
00552 {
00553 edm::ESHandle<DDCompactView> cpv;
00554 iSetup.get<IdealGeometryRecord>().get( cpv );
00555
00556 if (doTracker_) {
00557 edm::ESHandle<GeometricDet> geometricDet;
00558 iSetup.get<IdealGeometryRecord>().get( geometricDet );
00559 TrackerGeomBuilderFromGeometricDet trackerBuilder;
00560 theTracker = boost::shared_ptr<TrackerGeometry>( trackerBuilder.build(&(*geometricDet)) );
00561 }
00562
00563 if (doMuon_) {
00564 edm::ESHandle<MuonDDDConstants> mdc;
00565 iSetup.get<MuonNumberingRecord>().get(mdc);
00566 DTGeometryBuilderFromDDD DTGeometryBuilder;
00567 CSCGeometryBuilderFromDDD CSCGeometryBuilder;
00568 theMuonDT = boost::shared_ptr<DTGeometry>(DTGeometryBuilder.build(&(*cpv), *mdc));
00569 theMuonCSC = boost::shared_ptr<CSCGeometry>( new CSCGeometry );
00570 CSCGeometryBuilder.build( theMuonCSC, &(*cpv), *mdc );
00571 }
00572 }
00573
00574 void AlignmentProducer::addSurveyInfo_(Alignable* ali)
00575 {
00576 const std::vector<Alignable*>& comp = ali->components();
00577
00578 unsigned int nComp = comp.size();
00579
00580 for (unsigned int i = 0; i < nComp; ++i) addSurveyInfo_(comp[i]);
00581
00582 const SurveyError& error = theSurveyErrors->m_surveyErrors[theSurveyIndex];
00583
00584 if ( ali->id() != error.rawId() ||
00585 ali->alignableObjectId() != error.structureType() )
00586 {
00587 throw cms::Exception("DatabaseError")
00588 << "Error reading survey info from DB. Mismatched id!";
00589 }
00590
00591 const CLHEP::Hep3Vector& pos = theSurveyValues->m_align[theSurveyIndex].translation();
00592 const CLHEP::HepRotation& rot = theSurveyValues->m_align[theSurveyIndex].rotation();
00593
00594 AlignableSurface surf( align::PositionType( pos.x(), pos.y(), pos.z() ),
00595 align::RotationType( rot.xx(), rot.xy(), rot.xz(),
00596 rot.yx(), rot.yy(), rot.yz(),
00597 rot.zx(), rot.zy(), rot.zz() ) );
00598
00599 surf.setWidth( ali->surface().width() );
00600 surf.setLength( ali->surface().length() );
00601
00602 ali->setSurvey( new SurveyDet( surf, error.matrix() ) );
00603
00604 ++theSurveyIndex;
00605 }
00606
00607 DEFINE_ANOTHER_FWK_LOOPER( AlignmentProducer );