Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #include "Alignment/CommonAlignment/interface/AlignableDet.h"
00008 #include "Alignment/CommonAlignment/interface/AlignableDetUnit.h"
00009 #include "Alignment/CommonAlignment/interface/AlignableExtras.h"
00010 #include "Alignment/CommonAlignment/interface/AlignableBeamSpot.h"
00011 #include "DataFormats/DetId/interface/DetId.h"
00012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00013 #include "FWCore/Utilities/interface/Exception.h"
00014
00015 #include "Alignment/CommonAlignment/interface/AlignableNavigator.h"
00016
00017
00018 AlignableNavigator::AlignableNavigator(Alignable* tracker, Alignable* muon)
00019 {
00020 theMap.clear();
00021
00022 const unsigned int numNonDets = this->recursiveGetId(tracker) + this->recursiveGetId(muon);
00023
00024 if (numNonDets) {
00025 edm::LogWarning("Alignment") <<"@SUB=AlignableNavigator" << "Created with map of size "
00026 << theMap.size() << ", but found also " << numNonDets
00027 << " Alignables that have DetId!=0,\nbeing neither "
00028 << "AlignableDet nor AlignableDetUnit. This will "
00029 << "lead to an exception in case alignableFromDetId(..) "
00030 << "is called for one of these DetIds.\n"
00031 << "If there is no exception, you can ignore this message.";
00032 } else {
00033 edm::LogInfo("Alignment") <<"@SUB=AlignableNavigator" << "Created with map of size "
00034 << theMap.size() << ".";
00035 }
00036 }
00037
00038
00039 AlignableNavigator::AlignableNavigator(AlignableExtras* extras, Alignable* tracker, Alignable* muon)
00040 {
00041 theMap.clear();
00042
00043 unsigned int numNonDets = this->recursiveGetId(tracker) + this->recursiveGetId(muon);
00044
00045 if (extras) {
00046 align::Alignables allExtras = extras->components();
00047 for ( std::vector<Alignable*>::iterator it = allExtras.begin(); it != allExtras.end(); ++it ) {
00048 numNonDets += this->recursiveGetId(*it);
00049 }
00050 }
00051
00052 if (numNonDets) {
00053 edm::LogWarning("Alignment") <<"@SUB=AlignableNavigator" << "Created with map of size "
00054 << theMap.size() << ", but found also " << numNonDets
00055 << " Alignables that have DetId!=0,\nbeing neither "
00056 << "AlignableDet nor AlignableDetUnit. This will "
00057 << "lead to an exception in case alignableFromDetId(..) "
00058 << "is called for one of these DetIds.\n"
00059 << "If there is no exception, you can ignore this message.";
00060 } else {
00061 edm::LogInfo("Alignment") <<"@SUB=AlignableNavigator" << "Created with map of size "
00062 << theMap.size() << ".";
00063 }
00064 }
00065
00066
00067 AlignableNavigator::AlignableNavigator( std::vector<Alignable*> alignables )
00068 {
00069 theMap.clear();
00070
00071 unsigned int numNonDets = 0;
00072 for ( std::vector<Alignable*>::iterator it = alignables.begin(); it != alignables.end(); ++it ) {
00073 numNonDets += this->recursiveGetId(*it);
00074 }
00075 if (numNonDets) {
00076 edm::LogWarning("Alignment") <<"@SUB=AlignableNavigator" << "Created with map of size "
00077 << theMap.size() << ", but found also " << numNonDets
00078 << " Alignables that have DetId!=0,\nbeing neither "
00079 << "AlignableDet nor AlignableDetUnit. This will "
00080 << "lead to an exception in case alignableFromDetId(..) "
00081 << "is called for one of these DetIds.\n"
00082 << "If there is no exception, you can ignore this message.";
00083 } else {
00084 edm::LogInfo("Alignment") <<"@SUB=AlignableNavigator" << "created with map of size "
00085 << theMap.size() << ".";
00086 }
00087 }
00088
00089
00090 AlignableDetOrUnitPtr AlignableNavigator::alignableFromGeomDet( const GeomDet* geomDet )
00091 {
00092 return alignableFromDetId( geomDet->geographicalId() );
00093 }
00094
00095
00096 AlignableDetOrUnitPtr AlignableNavigator::alignableFromDetId( const DetId& detid )
00097 {
00098 MapType::iterator position = theMap.find( detid );
00099 if ( position != theMap.end() ) {
00100 return position->second;
00101 }
00102
00103 throw cms::Exception("BadLogic")
00104 << "[AlignableNavigator::alignableDetFromDetId] DetId " << detid.rawId() << " not found";
00105
00106 return static_cast<AlignableDet*>(0);
00107 }
00108
00109
00110 unsigned int AlignableNavigator::recursiveGetId( Alignable* alignable )
00111 {
00112
00113
00114
00115
00116
00117 if (!alignable) return 0;
00118
00119 unsigned int nProblem = 0;
00120 const DetId detId(alignable->geomDetId());
00121 if (detId.rawId()) {
00122
00123 AlignableDet *aliDet;
00124 AlignableDetUnit *aliDetUnit;
00125 AlignableBeamSpot *aliBeamSpot;
00126
00127 if ((aliDet = dynamic_cast<AlignableDet*>(alignable))) {
00128
00129 theMap.insert( PairType( detId, aliDet ) );
00130
00131 } else if ((aliDetUnit = dynamic_cast<AlignableDetUnit*>(alignable))) {
00132
00133 theMap.insert( PairType( detId, aliDetUnit ) );
00134
00135 } else if ((aliBeamSpot = dynamic_cast<AlignableBeamSpot*>(alignable))) {
00136
00137 theMap.insert( PairType( detId, aliBeamSpot ) );
00138
00139 } else {
00140
00141 nProblem = 1;
00142
00143
00144
00145
00146 }
00147
00148 if (!nProblem && !this->detAndSubdetInMap(detId)) {
00149 theDetAndSubdet.push_back(std::pair<int, int>( detId.det(), detId.subdetId() ));
00150 }
00151 }
00152 std::vector<Alignable*> comp = alignable->components();
00153 if ( alignable->alignableObjectId() != align::AlignableDet
00154 || comp.size() > 1 ) {
00155 for ( std::vector<Alignable*>::iterator it = comp.begin(); it != comp.end(); ++it ) {
00156 nProblem += this->recursiveGetId(*it);
00157 }
00158 }
00159 return nProblem;
00160 }
00161
00162
00163 std::vector<AlignableDetOrUnitPtr>
00164 AlignableNavigator::alignablesFromHits( const std::vector<const TransientTrackingRecHit*>& hitvec )
00165 {
00166 std::vector<AlignableDetOrUnitPtr> result;
00167 result.reserve(hitvec.size());
00168
00169 for(std::vector<const TransientTrackingRecHit*>::const_iterator ih
00170 = hitvec.begin(), iEnd = hitvec.end(); ih != iEnd; ++ih) {
00171 result.push_back(this->alignableFromDetId((*ih)->geographicalId()));
00172 }
00173
00174 return result;
00175 }
00176
00177
00178 std::vector<AlignableDetOrUnitPtr>
00179 AlignableNavigator::alignablesFromHits
00180 (const TransientTrackingRecHit::ConstRecHitContainer &hitVec)
00181 {
00182
00183 std::vector<AlignableDetOrUnitPtr> result;
00184 result.reserve(hitVec.size());
00185
00186 for (TransientTrackingRecHit::ConstRecHitContainer::const_iterator it
00187 = hitVec.begin(), iEnd = hitVec.end(); it != iEnd; ++it) {
00188 result.push_back(this->alignableFromDetId((*it)->geographicalId()));
00189 }
00190
00191 return result;
00192 }
00193
00194
00195 std::vector<AlignableDetOrUnitPtr> AlignableNavigator::alignableDetOrUnits()
00196 {
00197 std::vector<AlignableDetOrUnitPtr> result;
00198 result.reserve(theMap.size());
00199
00200 for (MapType::const_iterator iIdAli = theMap.begin(); iIdAli != theMap.end(); ++iIdAli) {
00201 result.push_back(iIdAli->second);
00202 }
00203
00204 return result;
00205 }
00206
00207
00208 bool AlignableNavigator::detAndSubdetInMap( const DetId& detid ) const
00209 {
00210 int det = detid.det();
00211 int subdet = detid.subdetId();
00212 for (std::vector<std::pair<int, int> >::const_iterator i = theDetAndSubdet.begin(); i != theDetAndSubdet.end(); ++i) {
00213 if (det == i->first && subdet == i->second) return true;
00214 }
00215 return false;
00216 }