Go to the documentation of this file.00001
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "Alignment/CommonAlignmentAlgorithm/interface/AlignmentAlgorithmPluginFactory.h"
00029 #include "Alignment/CommonAlignmentAlgorithm/interface/AlignmentAlgorithmBase.h"
00030 #include "Alignment/CommonAlignment/interface/AlignableModifier.h"
00031
00032 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00033
00034 #include "CondFormats/Alignment/interface/AlignmentErrors.h"
00035 #include "DataFormats/GeometrySurface/interface/GloballyPositioned.h"
00036 #include "CLHEP/Matrix/SymMatrix.h"
00037
00038 #include <fstream>
00039 #include <string>
00040 #include <set>
00041
00042 #include "DataFormats/TrackingRecHit/interface/AlignmentPositionError.h"
00043 #include "Alignment/CommonAlignmentAlgorithm/interface/AlignmentParameterStore.h"
00044
00045 #include "Alignment/CommonAlignment/interface/AlignableNavigator.h"
00046 #include "Alignment/CommonAlignment/interface/AlignableDetOrUnitPtr.h"
00047 #include "Alignment/CommonAlignment/interface/Alignable.h"
00048
00049
00050 #include "Alignment/TrackerAlignment/interface/AlignableTracker.h"
00051 #include "Alignment/MuonAlignment/interface/AlignableMuon.h"
00052 #include "Alignment/CommonAlignment/interface/AlignableExtras.h"
00053
00054 #include "DataFormats/CLHEP/interface/AlgebraicObjects.h"
00055
00056 class ApeSettingAlgorithm : public AlignmentAlgorithmBase
00057 {
00058 public:
00060 ApeSettingAlgorithm(const edm::ParameterSet &cfg);
00061
00063 virtual ~ApeSettingAlgorithm();
00064
00066 virtual void initialize(const edm::EventSetup &setup,
00067 AlignableTracker *tracker, AlignableMuon *muon, AlignableExtras *extras,
00068 AlignmentParameterStore *store);
00069
00071 virtual void terminate(const edm::EventSetup& iSetup);
00072
00074 virtual void run(const edm::EventSetup &setup, const EventInfo &eventInfo);
00075
00076 private:
00077 edm::ParameterSet theConfig;
00078 AlignableNavigator *theAlignableNavigator;
00079 AlignableTracker *theTracker;
00080 bool saveApeToAscii_,readApeFromAscii_,readFullLocalMatrix_;
00081 bool readLocalNotGlobal_,saveLocalNotGlobal_;
00082 bool setComposites_,saveComposites_;
00083 };
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 ApeSettingAlgorithm::ApeSettingAlgorithm(const edm::ParameterSet &cfg) :
00094 AlignmentAlgorithmBase(cfg), theConfig(cfg),
00095 theAlignableNavigator(0)
00096 {
00097 edm::LogInfo("Alignment") << "@SUB=ApeSettingAlgorithm" << "Start.";
00098 saveApeToAscii_ = theConfig.getUntrackedParameter<bool>("saveApeToASCII");
00099 saveComposites_ = theConfig.getUntrackedParameter<bool>("saveComposites");
00100 saveLocalNotGlobal_ = theConfig.getUntrackedParameter<bool>("saveLocalNotGlobal");
00101 readApeFromAscii_ = theConfig.getParameter<bool>("readApeFromASCII");
00102 readLocalNotGlobal_ = theConfig.getParameter<bool>("readLocalNotGlobal");
00103 readFullLocalMatrix_ = theConfig.getParameter<bool>("readFullLocalMatrix");
00104 setComposites_ = theConfig.getParameter<bool>("setComposites");
00105
00106 }
00107
00108
00109
00110 ApeSettingAlgorithm::~ApeSettingAlgorithm()
00111 {
00112 delete theAlignableNavigator;
00113 }
00114
00115
00116
00117 void ApeSettingAlgorithm::initialize(const edm::EventSetup &setup,
00118 AlignableTracker *tracker, AlignableMuon *muon, AlignableExtras *extras,
00119 AlignmentParameterStore *store)
00120 {
00121 theAlignableNavigator = new AlignableNavigator(tracker, muon);
00122 theTracker = tracker;
00123
00124 if (readApeFromAscii_)
00125 { std::ifstream apeReadFile(theConfig.getParameter<edm::FileInPath>("apeASCIIReadFile").fullPath().c_str());
00126 if (!apeReadFile.good())
00127 { edm::LogInfo("Alignment") << "@SUB=initialize" <<"Problem opening APE file: skipping"
00128 << theConfig.getParameter<edm::FileInPath>("apeASCIIReadFile").fullPath();
00129 return;
00130 }
00131 std::set<int> apeList;
00132 while (!apeReadFile.eof())
00133 { int apeId=0; double x11,x21,x22,x31,x32,x33;
00134 if (!readLocalNotGlobal_ || readFullLocalMatrix_)
00135 { apeReadFile>>apeId>>x11>>x21>>x22>>x31>>x32>>x33>>std::ws;}
00136 else
00137 { apeReadFile>>apeId>>x11>>x22>>x33>>std::ws;}
00138
00139 if (apeId != 0)
00140 { if (apeList.find(apeId) == apeList.end())
00141 { DetId id(apeId);
00142 AlignableDetOrUnitPtr alidet(theAlignableNavigator->alignableFromDetId(id));
00143 if (alidet)
00144 { if ((alidet->components().size()<1) || setComposites_)
00145 { GlobalError globErr;
00146 if (readLocalNotGlobal_)
00147 { AlgebraicSymMatrix33 as;
00148 if (readFullLocalMatrix_)
00149 { as[0][0]=x11; as[1][0]=x21; as[1][1]=x22;
00150 as[2][0]=x31; as[2][1]=x32; as[2][2]=x33;
00151 }
00152 else
00153 { as[0][0]=x11*x11; as[1][1]=x22*x22; as[2][2]=x33*x33;}
00154 align::RotationType rt=alidet->globalRotation();
00155 AlgebraicMatrix33 am;
00156 am[0][0]=rt.xx(); am[0][1]=rt.xy(); am[0][2]=rt.xz();
00157 am[1][0]=rt.yx(); am[1][1]=rt.yy(); am[1][2]=rt.yz();
00158 am[2][0]=rt.zx(); am[2][1]=rt.zy(); am[2][2]=rt.zz();
00159 globErr = GlobalError(ROOT::Math::SimilarityT(am,as));
00160 }
00161 else
00162 {
00163 globErr = GlobalError(x11,x21,x22,x31,x32,x33);
00164 }
00165 alidet->setAlignmentPositionError(globErr, false);
00166 apeList.insert(apeId);
00167 }
00168 else
00169 { edm::LogInfo("Alignment") << "@SUB=initialize" << "Not Setting APE for Composite DetId "<<apeId;
00170 }
00171 }
00172 }
00173 else
00174 { edm::LogInfo("Alignment") << "@SUB=initialize" << "Skipping duplicate APE for DetId "<<apeId;
00175 }
00176 }
00177 }
00178 apeReadFile.close();
00179 edm::LogInfo("Alignment") << "@SUB=initialize" << "Set "<<apeList.size()<<" APE values.";
00180 }
00181 }
00182
00183
00184
00185
00186 void ApeSettingAlgorithm::terminate(const edm::EventSetup& iSetup)
00187 {
00188 if (saveApeToAscii_)
00189 { AlignmentErrors* aliErr=theTracker->alignmentErrors();
00190 int theSize=aliErr->m_alignError.size();
00191 std::ofstream apeSaveFile(theConfig.getUntrackedParameter<std::string>("apeASCIISaveFile").c_str());
00192 for (int i=0; i < theSize; ++i)
00193 { int id= aliErr->m_alignError[i].rawId();
00194 AlignableDetOrUnitPtr alidet(theAlignableNavigator->alignableFromDetId(DetId(id)));
00195 if (alidet && ((alidet->components().size()<1) || saveComposites_))
00196 { apeSaveFile<<id;
00197 CLHEP::HepSymMatrix sm = aliErr->m_alignError[i].matrix();
00198 if (saveLocalNotGlobal_)
00199 { align::RotationType rt=alidet->globalRotation();
00200 AlgebraicMatrix am(3,3);
00201 am[0][0]=rt.xx(); am[0][1]=rt.xy(); am[0][2]=rt.xz();
00202 am[1][0]=rt.yx(); am[1][1]=rt.yy(); am[1][2]=rt.yz();
00203 am[2][0]=rt.zx(); am[2][1]=rt.zy(); am[2][2]=rt.zz();
00204 sm=sm.similarity(am);
00205 }
00206 for (int j=0; j < 3; ++j)
00207 for (int k=0; k <= j; ++k)
00208 apeSaveFile<<" "<<sm[j][k];
00209
00210 apeSaveFile<<std::endl;
00211 }
00212 }
00213 delete aliErr;
00214 apeSaveFile.close();
00215 }
00216
00217 delete theAlignableNavigator;
00218 theAlignableNavigator = 0;
00219 }
00220
00221
00222
00223 void ApeSettingAlgorithm::run(const edm::EventSetup &setup, const EventInfo &eventInfo)
00224 {
00225
00226 }
00227
00228
00229 DEFINE_EDM_PLUGIN(AlignmentAlgorithmPluginFactory,
00230 ApeSettingAlgorithm, "ApeSettingAlgorithm");
00231
00232
00233