22 #include "CLHEP/Vector/RotationInterfaces.h" 44 #include "TPaveStats.h" 57 static const std::map<AlignmentPI::coordinate,float> hardcodeGPR =
72 bool fill(
const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs )
override{
74 std::vector<std::tuple<cond::Time_t,cond::Hash> > sorted_iovs = iovs;
77 std::sort(
begin(sorted_iovs),
end(sorted_iovs), [](
auto const &t1,
auto const &t2) {
78 return std::get<0>(t1) < std::get<0>(t2);
81 auto firstiov = sorted_iovs.front();
82 auto lastiov = sorted_iovs.back();
84 std::shared_ptr<Alignments> last_payload =
fetchPayload( std::get<1>(lastiov) );
85 std::shared_ptr<Alignments> first_payload =
fetchPayload( std::get<1>(firstiov) );
87 std::string lastIOVsince = std::to_string(std::get<0>(lastiov));
88 std::string firstIOVsince = std::to_string(std::get<0>(firstiov));
90 std::vector<AlignTransform> ref_ali = first_payload->m_align;
91 std::vector<AlignTransform> target_ali = last_payload->m_align;
93 TCanvas
canvas(
"Alignment Comparison",
"Alignment Comparison",1200,1200);
95 if(ref_ali.size() != target_ali.size()){
96 edm::LogError(
"TrackerAlignment_PayloadInspector") <<
"the size of the reference alignment (" << ref_ali.size() <<
") is different from the one of the target ("<< target_ali.size() <<
")! You are probably trying to compare different underlying geometries. Exiting";
101 const char * path_toTopologyXML = (ref_ali.size()==
AlignmentPI::phase0size) ?
"Geometry/TrackerCommonData/data/trackerParameters.xml" :
"Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml";
104 for (
const auto &ali : ref_ali){
105 auto mydetid = ali.rawId();
117 std::unique_ptr<TH1F>
compare = std::unique_ptr<TH1F>(
new TH1F(
"comparison",Form(
";Detector Id index; #Delta%s %s",s_coord.c_str(),unit.c_str()),ref_ali.size(),-0.5,ref_ali.size()-0.5));
119 std::vector<int> boundaries;
121 for(
unsigned int i=0;
i<=ref_ali.size();
i++){
123 if(ref_ali[
i].rawId() == target_ali[
i].rawId()){
129 if( thePart != currentPart ){
131 boundaries.push_back(counter);
134 CLHEP::HepRotation target_rot( target_ali[
i].
rotation() );
135 CLHEP::HepRotation ref_rot( ref_ali[
i].
rotation() );
138 target_rot.yx(), target_rot.yy(), target_rot.yz(),
139 target_rot.zx(), target_rot.zy(), target_rot.zz() );
142 ref_rot.yx(), ref_rot.yy(), ref_rot.yz(),
143 ref_rot.zx(), ref_rot.zy(), ref_rot.zz() );
159 compare->SetBinContent(
i+1,(target_eulerAngles[0]-ref_eulerAngles[0])*1000.);
162 compare->SetBinContent(
i+1,(target_eulerAngles[1]-ref_eulerAngles[1])*1000.);
165 compare->SetBinContent(
i+1,(target_eulerAngles[2]-ref_eulerAngles[2])*1000.);
168 edm::LogError(
"TrackerAlignment_PayloadInspector") <<
"Unrecognized coordinate "<< coord << std::endl;
176 canvas.SetLeftMargin(0.17);
177 canvas.SetRightMargin(0.05);
178 canvas.SetBottomMargin(0.15);
180 auto max = compare->GetMaximum();
181 auto min = compare->GetMinimum();
184 compare->GetYaxis()->SetRangeUser(-range*1.3,range*1.2);
185 compare->SetMarkerStyle(20);
186 compare->SetMarkerSize(0.5);
192 TLine
l[boundaries.size()];
194 for (
const auto &
line : boundaries){
195 l[
i] = TLine(compare->GetBinLowEdge(
line),
canvas.cd()->GetUymin(),compare->GetBinLowEdge(
line),
canvas.cd()->GetUymax());
196 l[
i].SetLineWidth(1);
197 l[
i].SetLineStyle(9);
198 l[
i].SetLineColor(2);
205 tSubdet.SetTextAlign(21);
206 tSubdet.SetTextSize(0.027);
207 tSubdet.SetTextAngle(90);
208 for (
unsigned int j=1;j<=6;j++ ){
210 tSubdet.SetTextColor(kRed);
212 float theX_ = myPair.first+0.025;
216 TLegend
legend = TLegend(0.58,0.82,0.95,0.9);
217 legend.SetTextSize(0.03);
218 legend.SetHeader(
"Alignment comparison",
"C");
219 legend.AddEntry(compare.get(),(
"IOV:"+std::to_string(std::get<0>(lastiov))+
"-"+std::to_string(std::get<0>(firstiov))).c_str(),
"PL");
225 t1.SetTextSize(0.05);
226 t1.DrawLatex(0.2, 0.93, Form(
"%s",s_coord.c_str()));
227 t1.SetTextColor(kBlue);
228 t1.DrawLatex(0.6, 0.93, Form(
"IOV %s - %s ",lastIOVsince.c_str(),firstIOVsince.c_str()));
237 typedef TrackerAlignmentCompare<AlignmentPI::t_x> TrackerAlignmentCompareX;
238 typedef TrackerAlignmentCompare<AlignmentPI::t_y> TrackerAlignmentCompareY;
239 typedef TrackerAlignmentCompare<AlignmentPI::t_z> TrackerAlignmentCompareZ;
241 typedef TrackerAlignmentCompare<AlignmentPI::rot_alpha> TrackerAlignmentCompareAlpha;
242 typedef TrackerAlignmentCompare<AlignmentPI::rot_beta> TrackerAlignmentCompareBeta;
243 typedef TrackerAlignmentCompare<AlignmentPI::rot_gamma> TrackerAlignmentCompareGamma;
251 TrackerAlignmentSummary() :
cond::payloadInspector::PlotImage<
Alignments>(
"Comparison of all coordinates between two geometries for "+
getStringFromPart (
q) ){
252 setSingleIov(
false );
255 bool fill(
const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs )
override{
257 std::vector<std::tuple<cond::Time_t,cond::Hash> > sorted_iovs = iovs;
260 std::sort(
begin(sorted_iovs),
end(sorted_iovs), [](
auto const &t1,
auto const &t2) {
261 return std::get<0>(t1) < std::get<0>(t2);
264 auto firstiov = sorted_iovs.front();
265 auto lastiov = sorted_iovs.back();
267 std::shared_ptr<Alignments> last_payload = fetchPayload( std::get<1>(lastiov) );
268 std::shared_ptr<Alignments> first_payload = fetchPayload( std::get<1>(firstiov) );
270 std::string lastIOVsince = std::to_string(std::get<0>(lastiov));
271 std::string firstIOVsince = std::to_string(std::get<0>(firstiov));
273 std::vector<AlignTransform> ref_ali = first_payload->m_align;
274 std::vector<AlignTransform> target_ali = last_payload->m_align;
276 if(ref_ali.size() != target_ali.size()){
277 edm::LogError(
"TrackerAlignment_PayloadInspector") <<
"the size of the reference alignment (" << ref_ali.size() <<
") is different from the one of the target ("<< target_ali.size() <<
")! You are probably trying to compare different underlying geometries. Exiting";
282 const char * path_toTopologyXML = (ref_ali.size()==
AlignmentPI::phase0size) ?
"Geometry/TrackerCommonData/data/trackerParameters.xml" :
"Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml";
285 for (
const auto &ali : ref_ali){
286 auto mydetid = ali.rawId();
293 TCanvas
canvas(
"Alignment Comparison",
"Alignment Comparison",1800,1200);
296 std::unordered_map<AlignmentPI::coordinate,std::unique_ptr<TH1F> > diffs;
299 for (
const auto &coord : coords){
304 diffs[coord] = std::make_unique<TH1F>(Form(
"hDiff_%s",s_coord.c_str()),Form(
";#Delta%s %s;n. of modules",s_coord.c_str(),unit.c_str()),1000,-500.,500.);
309 int loopedComponents(0);
310 for(
unsigned int i=0;i<=ref_ali.size();i++){
312 if(ref_ali[i].rawId() == target_ali[
i].rawId()){
317 if(thePart!=
q)
continue;
319 CLHEP::HepRotation target_rot( target_ali[i].
rotation() );
320 CLHEP::HepRotation ref_rot( ref_ali[i].
rotation() );
323 target_rot.yx(), target_rot.yy(), target_rot.yz(),
324 target_rot.zx(), target_rot.zy(), target_rot.zz() );
327 ref_rot.yx(), ref_rot.yy(), ref_rot.yz(),
328 ref_rot.zx(), ref_rot.zy(), ref_rot.zz() );
333 for (
const auto &coord : coords){
336 diffs[coord]->Fill((target_ali[i].translation().
x()-ref_ali[i].translation().
x())*
AlignmentPI::cmToUm);
339 diffs[coord]->Fill((target_ali[i].translation().
y()-ref_ali[i].translation().
y())*
AlignmentPI::cmToUm);
342 diffs[coord]->Fill((target_ali[i].translation().
z()-ref_ali[i].translation().
z())*
AlignmentPI::cmToUm);
345 diffs[coord]->Fill((target_eulerAngles[0]-ref_eulerAngles[0])*1000.);
348 diffs[coord]->Fill((target_eulerAngles[1]-ref_eulerAngles[1])*1000.);
350 case AlignmentPI::rot_gamma:
351 diffs[coord]->Fill((target_eulerAngles[2]-ref_eulerAngles[2])*1000.);
354 edm::LogError(
"TrackerAlignment_PayloadInspector") <<
"Unrecognized coordinate "<< coord << std::endl;
363 auto legend = std::unique_ptr<TLegend>(
new TLegend(0.14,0.93,0.55,0.98));
364 legend->AddEntry(diffs[
AlignmentPI::t_x].
get(),(
"#DeltaIOV: "+std::to_string(std::get<0>(lastiov))+
"-"+std::to_string(std::get<0>(firstiov))).c_str(),
"L");
365 legend->SetTextSize(0.03);
367 for (
const auto &coord : coords){
368 canvas.cd(c_index)->SetLogy();
369 canvas.cd(c_index)->SetTopMargin(0.02);
370 canvas.cd(c_index)->SetBottomMargin(0.15);
371 canvas.cd(c_index)->SetLeftMargin(0.14);
372 canvas.cd(c_index)->SetRightMargin(0.04);
373 diffs[coord]->SetLineWidth(2);
381 int i_max = diffs[coord]->FindLastBinAbove(0.);
382 int i_min = diffs[coord]->FindFirstBinAbove(0.);
383 diffs[coord]->GetXaxis()->SetRange(
std::max(1,i_min-10),
std::min(i_max+10,diffs[coord]->GetNbinsX()));
384 diffs[coord]->Draw(
"HIST");
387 legend->Draw(
"same");
399 typedef TrackerAlignmentSummary<AlignmentPI::BPix> TrackerAlignmentSummaryBPix;
400 typedef TrackerAlignmentSummary<AlignmentPI::FPix> TrackerAlignmentSummaryFPix;
401 typedef TrackerAlignmentSummary<AlignmentPI::TIB> TrackerAlignmentSummaryTIB;
403 typedef TrackerAlignmentSummary<AlignmentPI::TID> TrackerAlignmentSummaryTID;
404 typedef TrackerAlignmentSummary<AlignmentPI::TOB> TrackerAlignmentSummaryTOB;
405 typedef TrackerAlignmentSummary<AlignmentPI::TEC> TrackerAlignmentSummaryTEC;
415 ~BPixBarycenterHistory()
override =
default;
419 std::vector<AlignTransform> alignments = payload.
m_align;
423 for(
const auto& ali : alignments ){
426 edm::LogWarning(
"TrackerAlignment_PayloadInspector") <<
"Encountered invalid Tracker DetId:" << ali.rawId() <<
" "<<
DetId(ali.rawId()).det()<<
" is different from "<<
DetId::Tracker<<
" - terminating ";
430 int subid =
DetId(ali.rawId()).subdetId();
436 barycenter+=(ali.translation().x());
439 barycenter+=(ali.translation().y());
442 barycenter+=(ali.translation().z());
445 edm::LogError(
"TrackerAlignment_PayloadInspector") <<
"Unrecognized coordinate "<< coord << std::endl;
450 edm::LogInfo(
"TrackerAlignment_PayloadInspector")<<
"barycenter ("<<barycenter<<
")/n. modules ("<< nmodules <<
") = "<< barycenter/nmodules << std::endl;
453 barycenter/=nmodules;
456 barycenter+=hardcodeGPR.at(coord);
463 typedef BPixBarycenterHistory<AlignmentPI::t_x> X_BPixBarycenterHistory;
464 typedef BPixBarycenterHistory<AlignmentPI::t_y> Y_BPixBarycenterHistory;
465 typedef BPixBarycenterHistory<AlignmentPI::t_z> Z_BPixBarycenterHistory;
void makeNicePlotStyle(TH1 *hist, int color)
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)
constexpr uint32_t rawId() const
get the raw id
std::string getStringFromPart(AlignmentPI::partitions i)
std::vector< AlignTransform > m_align
static const float cmToUm
void makeNiceStats(TH1F *hist, AlignmentPI::partitions part, int color)
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
static const unsigned int phase0size
std::pair< double, double > calculatePosition(TVirtualPad *myPad, int boundary)
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
virtual bool fill(const std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs)=0
Abs< T >::type abs(const T &t)
EulerAngles toAngles(const RotationType &)
Convert rotation matrix to angles about x-, y-, z-axes (frame rotation).
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
AlgebraicVector EulerAngles
std::string getStringFromCoordinate(AlignmentPI::coordinate coord)
void setSingleIov(bool flag)
bool tidIsDoubleSide(const DetId &id) const
TrackerTopology fromTrackerParametersXMLFile(const std::string &xmlFileName)
constexpr Detector det() const
get the detector field from this detid