1 |
ireid |
1.1 |
/**
|
2 |
|
|
* \file MillePedeAlignmentAlgorithm.cc
|
3 |
|
|
*
|
4 |
|
|
* \author : Gero Flucke/Ivan Reid
|
5 |
ireid |
1.6 |
* date : February 2009 * $Revision: 1.5 $
|
6 |
|
|
* $Date: 2009/04/03 08:59:05 $
|
7 |
|
|
* (last update by $Author: flucke $)
|
8 |
|
|
*/
|
9 |
|
|
/*
|
10 |
|
|
*# Parameters:
|
11 |
|
|
*# saveApeToASCII -- Do we write out an APE text file?
|
12 |
|
|
*# saveComposites -- Do we write APEs for composite detectors?
|
13 |
|
|
*# saveLocalNotGlobal -- Do we write the APEs in the local or global coordinates?
|
14 |
|
|
*# apeASCIISaveFile -- The name of the save-file.
|
15 |
|
|
*# readApeFromASCII -- Do we read in APEs from a text file?
|
16 |
|
|
*# readLocalNotGlobal -- Do we read APEs in the local or the global frame?
|
17 |
|
|
*# readFullLocalMatrix -- Do we read the full local matrix or just the diagonal elements?
|
18 |
|
|
*# Full matrix format: DetID dxx dxy dyy dxz dyz dzz
|
19 |
|
|
*# Diagonal element format: DetID sqrt(dxx) sqrt(dyy) sqrt(dzz)
|
20 |
|
|
*# setComposites -- Do we set the APEs for composite detectors or just ignore them?
|
21 |
|
|
*# apeASCIIReadFile -- Input file name.
|
22 |
|
|
*# Also note:
|
23 |
|
|
*# process.AlignmentProducer.saveApeToDB -- to save as an sqlite file
|
24 |
|
|
*# and associated entries in _cfg.py
|
25 |
ireid |
1.1 |
*/
|
26 |
|
|
|
27 |
|
|
#include "Alignment/CommonAlignmentAlgorithm/interface/AlignmentAlgorithmPluginFactory.h"
|
28 |
|
|
#include "Alignment/CommonAlignmentAlgorithm/interface/AlignmentAlgorithmBase.h"
|
29 |
ireid |
1.2 |
#include "Alignment/CommonAlignment/interface/AlignableModifier.h"
|
30 |
ireid |
1.1 |
|
31 |
|
|
#include "FWCore/ParameterSet/interface/ParameterSet.h"
|
32 |
|
|
|
33 |
|
|
#include "CondFormats/Alignment/interface/AlignmentErrors.h"
|
34 |
ireid |
1.3 |
#include "DataFormats/GeometrySurface/interface/GloballyPositioned.h"
|
35 |
ireid |
1.1 |
#include "CLHEP/Matrix/SymMatrix.h"
|
36 |
|
|
|
37 |
|
|
#include <fstream>
|
38 |
|
|
#include <string>
|
39 |
|
|
#include <set>
|
40 |
|
|
|
41 |
|
|
#include "DataFormats/TrackingRecHit/interface/AlignmentPositionError.h"
|
42 |
|
|
#include "Alignment/CommonAlignmentAlgorithm/interface/AlignmentParameterStore.h"
|
43 |
|
|
|
44 |
|
|
#include "Alignment/CommonAlignment/interface/AlignableNavigator.h"
|
45 |
|
|
#include "Alignment/CommonAlignment/interface/AlignableDetOrUnitPtr.h"
|
46 |
|
|
#include "Alignment/CommonAlignment/interface/Alignable.h"
|
47 |
|
|
|
48 |
|
|
// includes to make known that they inherit from Alignable:
|
49 |
|
|
#include "Alignment/TrackerAlignment/interface/AlignableTracker.h"
|
50 |
|
|
#include "Alignment/MuonAlignment/interface/AlignableMuon.h"
|
51 |
|
|
|
52 |
ireid |
1.3 |
#include "DataFormats/CLHEP/interface/AlgebraicObjects.h"
|
53 |
ireid |
1.6 |
#include "DataFormats/GeometryCommonDetAlgo/interface/ErrorFrameTransformer.h"
|
54 |
ireid |
1.1 |
|
55 |
|
|
class ApeSettingAlgorithm : public AlignmentAlgorithmBase
|
56 |
|
|
{
|
57 |
|
|
public:
|
58 |
|
|
/// Constructor
|
59 |
|
|
ApeSettingAlgorithm(const edm::ParameterSet &cfg);
|
60 |
|
|
|
61 |
|
|
/// Destructor
|
62 |
|
|
virtual ~ApeSettingAlgorithm();
|
63 |
|
|
|
64 |
|
|
/// Call at beginning of job
|
65 |
|
|
virtual void initialize(const edm::EventSetup &setup, AlignableTracker *tracker,
|
66 |
|
|
AlignableMuon *muon, AlignmentParameterStore *store);
|
67 |
|
|
|
68 |
|
|
/// Call at end of job
|
69 |
|
|
virtual void terminate();
|
70 |
|
|
|
71 |
flucke |
1.5 |
/// Run the algorithm
|
72 |
|
|
virtual void run(const edm::EventSetup &setup, const EventInfo &eventInfo);
|
73 |
ireid |
1.1 |
|
74 |
|
|
private:
|
75 |
|
|
edm::ParameterSet theConfig;
|
76 |
|
|
AlignableNavigator *theAlignableNavigator;
|
77 |
|
|
AlignableTracker *theTracker;
|
78 |
ireid |
1.6 |
bool saveApeToAscii_,readApeFromAscii_,readFullLocalMatrix_;
|
79 |
|
|
bool readLocalNotGlobal_,saveLocalNotGlobal_;
|
80 |
ireid |
1.4 |
bool setComposites_,saveComposites_;
|
81 |
ireid |
1.1 |
};
|
82 |
|
|
|
83 |
|
|
//____________________________________________________
|
84 |
|
|
//____________________________________________________
|
85 |
|
|
//____________________________________________________
|
86 |
|
|
//____________________________________________________
|
87 |
|
|
|
88 |
|
|
|
89 |
|
|
// Constructor ----------------------------------------------------------------
|
90 |
|
|
//____________________________________________________
|
91 |
|
|
ApeSettingAlgorithm::ApeSettingAlgorithm(const edm::ParameterSet &cfg) :
|
92 |
|
|
AlignmentAlgorithmBase(cfg), theConfig(cfg),
|
93 |
|
|
theAlignableNavigator(0)
|
94 |
|
|
{
|
95 |
|
|
edm::LogInfo("Alignment") << "@SUB=ApeSettingAlgorithm" << "Start.";
|
96 |
|
|
saveApeToAscii_ = theConfig.getUntrackedParameter<bool>("saveApeToASCII");
|
97 |
ireid |
1.4 |
saveComposites_ = theConfig.getUntrackedParameter<bool>("saveComposites");
|
98 |
ireid |
1.6 |
saveLocalNotGlobal_ = theConfig.getUntrackedParameter<bool>("saveLocalNotGlobal");
|
99 |
ireid |
1.1 |
readApeFromAscii_ = theConfig.getParameter<bool>("readApeFromASCII");
|
100 |
ireid |
1.2 |
readLocalNotGlobal_ = theConfig.getParameter<bool>("readLocalNotGlobal");
|
101 |
ireid |
1.6 |
readFullLocalMatrix_ = theConfig.getParameter<bool>("readFullLocalMatrix");
|
102 |
ireid |
1.4 |
setComposites_ = theConfig.getParameter<bool>("setComposites");
|
103 |
|
|
|
104 |
ireid |
1.1 |
}
|
105 |
|
|
|
106 |
|
|
// Destructor ----------------------------------------------------------------
|
107 |
|
|
//____________________________________________________
|
108 |
|
|
ApeSettingAlgorithm::~ApeSettingAlgorithm()
|
109 |
|
|
{
|
110 |
|
|
delete theAlignableNavigator;
|
111 |
|
|
}
|
112 |
|
|
|
113 |
|
|
// Call at beginning of job ---------------------------------------------------
|
114 |
|
|
//____________________________________________________
|
115 |
|
|
void ApeSettingAlgorithm::initialize(const edm::EventSetup &setup,
|
116 |
|
|
AlignableTracker *tracker, AlignableMuon *muon,
|
117 |
|
|
AlignmentParameterStore *store)
|
118 |
ireid |
1.2 |
{ theAlignableNavigator = new AlignableNavigator(tracker, muon);
|
119 |
|
|
theTracker = tracker;
|
120 |
|
|
|
121 |
|
|
if (readApeFromAscii_)
|
122 |
|
|
{ std::ifstream apeReadFile(theConfig.getParameter<edm::FileInPath>("apeASCIIReadFile").fullPath().c_str()); //requires <fstream>
|
123 |
|
|
if (!apeReadFile.good())
|
124 |
ireid |
1.3 |
{ edm::LogInfo("Alignment") << "@SUB=initialize" <<"Problem opening APE file: skipping"
|
125 |
ireid |
1.2 |
<< theConfig.getParameter<edm::FileInPath>("apeASCIIReadFile").fullPath();
|
126 |
|
|
return;
|
127 |
|
|
}
|
128 |
|
|
std::set<int> apeList; //To avoid duplicates
|
129 |
|
|
while (!apeReadFile.eof())
|
130 |
|
|
{ int apeId=0; double x11,x21,x22,x31,x32,x33;
|
131 |
ireid |
1.6 |
if (!readLocalNotGlobal_ || readFullLocalMatrix_)
|
132 |
|
|
{ apeReadFile>>apeId>>x11>>x21>>x22>>x31>>x32>>x33>>std::ws;}
|
133 |
|
|
else
|
134 |
|
|
{ apeReadFile>>apeId>>x11>>x22>>x33>>std::ws;}
|
135 |
ireid |
1.2 |
//idr What sanity checks do we need to put here?
|
136 |
|
|
if (apeId != 0) //read appears valid?
|
137 |
|
|
if (apeList.find(apeId) == apeList.end()) //Not previously done
|
138 |
ireid |
1.3 |
{ DetId id(apeId);
|
139 |
ireid |
1.2 |
AlignableDetOrUnitPtr alidet(theAlignableNavigator->alignableFromDetId(id)); //NULL if none
|
140 |
ireid |
1.4 |
if (alidet)
|
141 |
|
|
{ if ((alidet->components().size()<1) || setComposites_) //the problem with glued dets...
|
142 |
|
|
{ if (readLocalNotGlobal_)
|
143 |
|
|
{ AlgebraicSymMatrix as(3,0);
|
144 |
ireid |
1.6 |
if (readFullLocalMatrix_)
|
145 |
|
|
{ as[0][0]=x11; as[1][0]=x21; as[1][1]=x22;
|
146 |
|
|
as[2][0]=x31; as[2][1]=x32; as[2][2]=x33;
|
147 |
|
|
}
|
148 |
|
|
else
|
149 |
|
|
{ as[0][0]=x11*x11; as[1][1]=x22*x22; as[2][2]=x33*x33;} //local cov.
|
150 |
ireid |
1.4 |
align::RotationType rt=alidet->globalRotation();
|
151 |
|
|
AlgebraicMatrix am(3,3);
|
152 |
|
|
am[0][0]=rt.xx(); am[0][1]=rt.xy(); am[0][2]=rt.xz();
|
153 |
|
|
am[1][0]=rt.yx(); am[1][1]=rt.yy(); am[1][2]=rt.yz();
|
154 |
|
|
am[2][0]=rt.zx(); am[2][1]=rt.zy(); am[2][2]=rt.zz();
|
155 |
|
|
am=am.T()*as*am; //symmetric matrix
|
156 |
ireid |
1.6 |
alidet->setAlignmentPositionError(AlignmentPositionError(GlobalError(am[0][0],am[1][0],am[1][1],am[2][0],am[2][1],am[2][2])));
|
157 |
ireid |
1.4 |
}
|
158 |
|
|
else
|
159 |
|
|
{ alidet->setAlignmentPositionError(GlobalError(x11,x21,x22,x31,x32,x33)); //set for global
|
160 |
|
|
}
|
161 |
|
|
apeList.insert(apeId); //Flag it's been set
|
162 |
ireid |
1.3 |
}
|
163 |
|
|
else
|
164 |
ireid |
1.4 |
{ edm::LogInfo("Alignment") << "@SUB=initialize" << "Not Setting APE for Composite DetId "<<apeId;
|
165 |
ireid |
1.3 |
}
|
166 |
ireid |
1.2 |
}
|
167 |
|
|
}
|
168 |
|
|
else
|
169 |
|
|
{ edm::LogInfo("Alignment") << "@SUB=initialize" << "Skipping duplicate APE for DetId "<<apeId;
|
170 |
|
|
}
|
171 |
|
|
}
|
172 |
|
|
apeReadFile.close();
|
173 |
|
|
edm::LogInfo("Alignment") << "@SUB=initialize" << "Set "<<apeList.size()<<" APE values.";
|
174 |
|
|
}
|
175 |
|
|
}
|
176 |
ireid |
1.4 |
|
177 |
ireid |
1.1 |
|
178 |
|
|
// Call at end of job ---------------------------------------------------------
|
179 |
|
|
//____________________________________________________
|
180 |
|
|
void ApeSettingAlgorithm::terminate()
|
181 |
|
|
{
|
182 |
|
|
if (saveApeToAscii_)
|
183 |
|
|
{ AlignmentErrors* aliErr=theTracker->alignmentErrors();
|
184 |
|
|
int theSize=aliErr->m_alignError.size();
|
185 |
|
|
std::ofstream apeSaveFile(theConfig.getUntrackedParameter<std::string>("apeASCIISaveFile").c_str()); //requires <fstream>
|
186 |
|
|
for (int i=0; i < theSize; ++i)
|
187 |
ireid |
1.4 |
{ int id= aliErr->m_alignError[i].rawId();
|
188 |
|
|
AlignableDetOrUnitPtr alidet(theAlignableNavigator->alignableFromDetId(DetId(id))); //NULL if none
|
189 |
|
|
if (alidet && ((alidet->components().size()<1) || saveComposites_))
|
190 |
|
|
{ apeSaveFile<<id;
|
191 |
|
|
CLHEP::HepSymMatrix sm= aliErr->m_alignError[i].matrix();
|
192 |
ireid |
1.6 |
if (saveLocalNotGlobal_)
|
193 |
|
|
{ align::RotationType rt=alidet->globalRotation();
|
194 |
|
|
AlgebraicMatrix am(3,3);
|
195 |
|
|
am[0][0]=rt.xx(); am[0][1]=rt.xy(); am[0][2]=rt.xz();
|
196 |
|
|
am[1][0]=rt.yx(); am[1][1]=rt.yy(); am[1][2]=rt.yz();
|
197 |
|
|
am[2][0]=rt.zx(); am[2][1]=rt.zy(); am[2][2]=rt.zz();
|
198 |
|
|
am=am*sm*am.T(); //symmetric matrix
|
199 |
|
|
for (int j=0; j < 3; ++j)
|
200 |
|
|
for (int k=0; k <= j; ++k)
|
201 |
|
|
apeSaveFile<<" "<<am[j][k]; //always write full matrix
|
202 |
|
|
} //transform to local
|
203 |
|
|
else
|
204 |
|
|
{ for (int j=0; j < 3; ++j)
|
205 |
|
|
for (int k=0; k <= j; ++k)
|
206 |
|
|
apeSaveFile<<" "<<sm[j][k]; //always write full matrix
|
207 |
|
|
}
|
208 |
ireid |
1.4 |
apeSaveFile<<std::endl;
|
209 |
|
|
}
|
210 |
ireid |
1.1 |
}
|
211 |
|
|
delete aliErr;
|
212 |
|
|
apeSaveFile.close();
|
213 |
|
|
}
|
214 |
|
|
// clean up at end: // FIXME: should we delete here or in destructor?
|
215 |
|
|
delete theAlignableNavigator;
|
216 |
|
|
theAlignableNavigator = 0;
|
217 |
|
|
}
|
218 |
|
|
|
219 |
|
|
// Run the algorithm on trajectories and tracks -------------------------------
|
220 |
|
|
//____________________________________________________
|
221 |
flucke |
1.5 |
void ApeSettingAlgorithm::run(const edm::EventSetup &setup, const EventInfo &eventInfo)
|
222 |
ireid |
1.1 |
{
|
223 |
|
|
// nothing to do here?
|
224 |
|
|
}
|
225 |
|
|
|
226 |
|
|
// Plugin definition for the algorithm
|
227 |
|
|
DEFINE_EDM_PLUGIN(AlignmentAlgorithmPluginFactory,
|
228 |
|
|
ApeSettingAlgorithm, "ApeSettingAlgorithm");
|
229 |
|
|
|
230 |
|
|
|
231 |
|
|
|