From 490325aa088740af7de0dd3b8adaae8a01759974 Mon Sep 17 00:00:00 2001 From: Michael Staib Date: Tue, 31 Oct 2017 10:33:56 -0400 Subject: [PATCH 1/3] Code to iterate the internal FDC alignment procedure -- Align wires and cathodes per cell --- TrackingAlignment/IterateFDCInternal.py | 59 +++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100755 TrackingAlignment/IterateFDCInternal.py diff --git a/TrackingAlignment/IterateFDCInternal.py b/TrackingAlignment/IterateFDCInternal.py new file mode 100755 index 00000000..9cd0d253 --- /dev/null +++ b/TrackingAlignment/IterateFDCInternal.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python + +import sys +import os +from subprocess import call + +################################# +# Setup Parameters for iterations +################################# + +nIterations=10 +filename='/raid12/gluex/RunPeriod-2017-01/rawdata/Run030778/hd_rawdata_030778_000.evio' +nThreads=4 +nEvents=1000000 + +############################################# +# You shouldn't have to edit below this lines +############################################# + +ccdb_connection = os.environ['CCDB_CONNECTION'] + +if 'mysql' in ccdb_connection: + print "CONNECTED TO JLAB MYSQL DATABASE === ABORTING" + quit() + +if 'sqlite' not in ccdb_connection: + print "UNKNOWN DATABASE TYPE %s == MUST USE SQLITE" % ccdb_connection + quit() + +try: + os.mkdir('FDCInternalAlignIterations'); +except OSError: + pass + +for iter in range(1,nIterations): + print "Iteration %.2i of %.2i" % (iter, nIterations) + call('hd_root -PPLUGINS=FDC_InternalAlignment %s -PNTHREADS=%i -PEVENTS_TO_KEEP=%i' % (filename, nThreads, nEvents), shell=True) + call(r'root -l -b -q $HALLD_HOME/src/plugins/Alignment/FDC_InternalAlignment/FitScripts/FitCathodeAlignment.C\(\"hd_root.root\"\)',shell=True) + call('mv Result.png FDCInternalAlignIterations/Result_Iter%.2i.png' % iter, shell=True) + call('mv Result.png FDCInternalAlignIterations/hd_root_Planes_Iter%.2i.png' % iter, shell=True) + call('ccdb add /FDC/cathode_alignment CathodeAlignment.txt', shell=True) + call('hd_root -PPLUGINS=FDC_InternalAlignment %s -PNTHREADS=%i -PEVENTS_TO_KEEP=%i' % (filename, nThreads, nEvents), shell=True) + call(r'root -l -b -q $HALLD_HOME/src/plugins/Alignment/FDC_InternalAlignment/FitScripts/FitCathodeProjections.C\(\"hd_root.root\"\)',shell=True) + call('ccdb add /FDC/cathode_alignment CathodeAlignment.txt', shell=True) + call('ccdb add /FDC/strip_pitches_v2 StripPitchesV2.txt',shell=True) + call('mv Result.png FDCInternalAlignIterations/hd_root_Projections_Iter%.2i.png' % iter, shell=True) + call('mv ResultU.png FDCInternalAlignIterations/ResultU_Iter%.2i.png' % iter, shell=True) + call('mv ResultV.png FDCInternalAlignIterations/ResultV_Iter%.2i.png' % iter, shell=True) + +print "======= FINAL ITERATION =======" +call('hd_root -PPLUGINS=FDC_InternalAlignment %s -PNTHREADS=%i -PEVENTS_TO_KEEP=%i' % (filename, nThreads, nEvents), shell=True) +call(r'root -l -b -q $HALLD_HOME/src/plugins/Alignment/FDC_InternalAlignment/FitScripts/FitCathodeAlignment.C\(\"hd_root.root\"\)',shell=True) +call('ccdb add /FDC/cathode_alignment CathodeAlignment.txt', shell=True) +call('mv Result.png FDCInternalAlignIterations/Result_Iter%.2i.png' % nIterations, shell=True) +call(r'root -l -b -q $HALLD_HOME/src/plugins/Alignment/FDC_InternalAlignment/FitScripts/FitCathodeProjections.C\(\"hd_root.root\"\)',shell=True) +call('mv ResultU.png FDCInternalAlignIterations/ResultU_Iter%.2i.png' % nIterations, shell=True) +call('mv ResultV.png FDCInternalAlignIterations/ResultV_Iter%.2i.png' % nIterations, shell=True) + + From 788d48dad5599c3abe2c9420733c82b4b1437f48 Mon Sep 17 00:00:00 2001 From: Michael Staib Date: Mon, 13 Nov 2017 13:02:31 -0500 Subject: [PATCH 2/3] Save root output, Change Directory structure. --- TrackingAlignment/{ => Step1}/IterateFDCInternal.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) rename TrackingAlignment/{ => Step1}/IterateFDCInternal.py (89%) diff --git a/TrackingAlignment/IterateFDCInternal.py b/TrackingAlignment/Step1/IterateFDCInternal.py similarity index 89% rename from TrackingAlignment/IterateFDCInternal.py rename to TrackingAlignment/Step1/IterateFDCInternal.py index 9cd0d253..32ccd213 100755 --- a/TrackingAlignment/IterateFDCInternal.py +++ b/TrackingAlignment/Step1/IterateFDCInternal.py @@ -37,18 +37,19 @@ call('hd_root -PPLUGINS=FDC_InternalAlignment %s -PNTHREADS=%i -PEVENTS_TO_KEEP=%i' % (filename, nThreads, nEvents), shell=True) call(r'root -l -b -q $HALLD_HOME/src/plugins/Alignment/FDC_InternalAlignment/FitScripts/FitCathodeAlignment.C\(\"hd_root.root\"\)',shell=True) call('mv Result.png FDCInternalAlignIterations/Result_Iter%.2i.png' % iter, shell=True) - call('mv Result.png FDCInternalAlignIterations/hd_root_Planes_Iter%.2i.png' % iter, shell=True) + call('mv hd_root.root FDCInternalAlignIterations/hd_root_Planes_Iter%.2i.root' % iter, shell=True) call('ccdb add /FDC/cathode_alignment CathodeAlignment.txt', shell=True) call('hd_root -PPLUGINS=FDC_InternalAlignment %s -PNTHREADS=%i -PEVENTS_TO_KEEP=%i' % (filename, nThreads, nEvents), shell=True) call(r'root -l -b -q $HALLD_HOME/src/plugins/Alignment/FDC_InternalAlignment/FitScripts/FitCathodeProjections.C\(\"hd_root.root\"\)',shell=True) call('ccdb add /FDC/cathode_alignment CathodeAlignment.txt', shell=True) call('ccdb add /FDC/strip_pitches_v2 StripPitchesV2.txt',shell=True) - call('mv Result.png FDCInternalAlignIterations/hd_root_Projections_Iter%.2i.png' % iter, shell=True) + call('mv hd_root.root FDCInternalAlignIterations/hd_root_Projections_Iter%.2i.root' % iter, shell=True) call('mv ResultU.png FDCInternalAlignIterations/ResultU_Iter%.2i.png' % iter, shell=True) call('mv ResultV.png FDCInternalAlignIterations/ResultV_Iter%.2i.png' % iter, shell=True) print "======= FINAL ITERATION =======" call('hd_root -PPLUGINS=FDC_InternalAlignment %s -PNTHREADS=%i -PEVENTS_TO_KEEP=%i' % (filename, nThreads, nEvents), shell=True) +call('mv hd_root.root FDCInternalAlignIterations/hd_root_Planes_Iter%.2i.root' % nIterations, shell=True) call(r'root -l -b -q $HALLD_HOME/src/plugins/Alignment/FDC_InternalAlignment/FitScripts/FitCathodeAlignment.C\(\"hd_root.root\"\)',shell=True) call('ccdb add /FDC/cathode_alignment CathodeAlignment.txt', shell=True) call('mv Result.png FDCInternalAlignIterations/Result_Iter%.2i.png' % nIterations, shell=True) From cdb5ca0300029fc9564c8f2d172e1b4e4bddcfbd Mon Sep 17 00:00:00 2001 From: Michael Staib Date: Mon, 13 Nov 2017 14:17:40 -0500 Subject: [PATCH 3/3] Change directory structure --- .../ResetTrackingAlignmentConstants.py | 0 .../zeros/CDC_global_alignment.txt | 0 .../{ => Step0}/zeros/CDC_timing.txt | 0 .../{ => Step0}/zeros/CDC_wire_alignment.txt | 0 .../zeros/FDC_cathode_alignment.txt | 0 .../{ => Step0}/zeros/FDC_cell_offsets.txt | 0 .../{ => Step0}/zeros/FDC_cell_rotations.txt | 0 .../{ => Step0}/zeros/FDC_strip_gains_v2.txt | 0 .../zeros/FDC_strip_pitches_v2.txt | 0 .../{ => Step0}/zeros/FDC_wire_alignment.txt | 0 .../zeros/FDC_wire_timing_offsets.txt | 0 TrackingAlignment/Utilities/DumpCDCOffsets.C | 43 +++++++++ TrackingAlignment/Utilities/DumpFDCOffsets.C | 95 +++++++++++++++++++ 13 files changed, 138 insertions(+) rename TrackingAlignment/{ => Step0}/ResetTrackingAlignmentConstants.py (100%) rename TrackingAlignment/{ => Step0}/zeros/CDC_global_alignment.txt (100%) rename TrackingAlignment/{ => Step0}/zeros/CDC_timing.txt (100%) rename TrackingAlignment/{ => Step0}/zeros/CDC_wire_alignment.txt (100%) rename TrackingAlignment/{ => Step0}/zeros/FDC_cathode_alignment.txt (100%) rename TrackingAlignment/{ => Step0}/zeros/FDC_cell_offsets.txt (100%) rename TrackingAlignment/{ => Step0}/zeros/FDC_cell_rotations.txt (100%) rename TrackingAlignment/{ => Step0}/zeros/FDC_strip_gains_v2.txt (100%) rename TrackingAlignment/{ => Step0}/zeros/FDC_strip_pitches_v2.txt (100%) rename TrackingAlignment/{ => Step0}/zeros/FDC_wire_alignment.txt (100%) rename TrackingAlignment/{ => Step0}/zeros/FDC_wire_timing_offsets.txt (100%) create mode 100644 TrackingAlignment/Utilities/DumpCDCOffsets.C create mode 100644 TrackingAlignment/Utilities/DumpFDCOffsets.C diff --git a/TrackingAlignment/ResetTrackingAlignmentConstants.py b/TrackingAlignment/Step0/ResetTrackingAlignmentConstants.py similarity index 100% rename from TrackingAlignment/ResetTrackingAlignmentConstants.py rename to TrackingAlignment/Step0/ResetTrackingAlignmentConstants.py diff --git a/TrackingAlignment/zeros/CDC_global_alignment.txt b/TrackingAlignment/Step0/zeros/CDC_global_alignment.txt similarity index 100% rename from TrackingAlignment/zeros/CDC_global_alignment.txt rename to TrackingAlignment/Step0/zeros/CDC_global_alignment.txt diff --git a/TrackingAlignment/zeros/CDC_timing.txt b/TrackingAlignment/Step0/zeros/CDC_timing.txt similarity index 100% rename from TrackingAlignment/zeros/CDC_timing.txt rename to TrackingAlignment/Step0/zeros/CDC_timing.txt diff --git a/TrackingAlignment/zeros/CDC_wire_alignment.txt b/TrackingAlignment/Step0/zeros/CDC_wire_alignment.txt similarity index 100% rename from TrackingAlignment/zeros/CDC_wire_alignment.txt rename to TrackingAlignment/Step0/zeros/CDC_wire_alignment.txt diff --git a/TrackingAlignment/zeros/FDC_cathode_alignment.txt b/TrackingAlignment/Step0/zeros/FDC_cathode_alignment.txt similarity index 100% rename from TrackingAlignment/zeros/FDC_cathode_alignment.txt rename to TrackingAlignment/Step0/zeros/FDC_cathode_alignment.txt diff --git a/TrackingAlignment/zeros/FDC_cell_offsets.txt b/TrackingAlignment/Step0/zeros/FDC_cell_offsets.txt similarity index 100% rename from TrackingAlignment/zeros/FDC_cell_offsets.txt rename to TrackingAlignment/Step0/zeros/FDC_cell_offsets.txt diff --git a/TrackingAlignment/zeros/FDC_cell_rotations.txt b/TrackingAlignment/Step0/zeros/FDC_cell_rotations.txt similarity index 100% rename from TrackingAlignment/zeros/FDC_cell_rotations.txt rename to TrackingAlignment/Step0/zeros/FDC_cell_rotations.txt diff --git a/TrackingAlignment/zeros/FDC_strip_gains_v2.txt b/TrackingAlignment/Step0/zeros/FDC_strip_gains_v2.txt similarity index 100% rename from TrackingAlignment/zeros/FDC_strip_gains_v2.txt rename to TrackingAlignment/Step0/zeros/FDC_strip_gains_v2.txt diff --git a/TrackingAlignment/zeros/FDC_strip_pitches_v2.txt b/TrackingAlignment/Step0/zeros/FDC_strip_pitches_v2.txt similarity index 100% rename from TrackingAlignment/zeros/FDC_strip_pitches_v2.txt rename to TrackingAlignment/Step0/zeros/FDC_strip_pitches_v2.txt diff --git a/TrackingAlignment/zeros/FDC_wire_alignment.txt b/TrackingAlignment/Step0/zeros/FDC_wire_alignment.txt similarity index 100% rename from TrackingAlignment/zeros/FDC_wire_alignment.txt rename to TrackingAlignment/Step0/zeros/FDC_wire_alignment.txt diff --git a/TrackingAlignment/zeros/FDC_wire_timing_offsets.txt b/TrackingAlignment/Step0/zeros/FDC_wire_timing_offsets.txt similarity index 100% rename from TrackingAlignment/zeros/FDC_wire_timing_offsets.txt rename to TrackingAlignment/Step0/zeros/FDC_wire_timing_offsets.txt diff --git a/TrackingAlignment/Utilities/DumpCDCOffsets.C b/TrackingAlignment/Utilities/DumpCDCOffsets.C new file mode 100644 index 00000000..c284f37b --- /dev/null +++ b/TrackingAlignment/Utilities/DumpCDCOffsets.C @@ -0,0 +1,43 @@ +// Script to get current values of the offsets from the alignment root file, and shift them according to the MILLEPEDE result. +#include +#include +#include +#include +#include "TProfile.h" +#include "TFile.h" + +using namespace std; + +void DumpCDCOffsets(TString rootFile = "hd_root.root"){ + + TFile *file = TFile::Open(rootFile); + TProfile *hCDCConstants; + file->GetObject("AlignmentConstants/CDCAlignmentConstants",hCDCConstants); + + // Global CDC offsets + ofstream outFile; + outFile.open("cdc_global.txt"); + for (unsigned int i = 1; i<=6; i++){ + int histIndex = i; + outFile << hCDCConstants->GetBinContent(histIndex) << " " ; + } + outFile.close(); + + // Wire alignment + outFile.open("cdc_wire_alignment.txt"); + for (unsigned int i = 1001; i<=15088; i++){ + int histIndex = i; + outFile << hCDCConstants->GetBinContent(histIndex) << " " ; + if (i%4 == 0) outFile << endl; + } + outFile.close(); + + // t0 alignment + outFile.open("cdc_t0_alignment.txt"); + for (unsigned int i = 16001; i<=19522; i++){ + int histIndex = i; + outFile << hCDCConstants->GetBinContent(histIndex) << endl; + } + outFile.close(); + +} diff --git a/TrackingAlignment/Utilities/DumpFDCOffsets.C b/TrackingAlignment/Utilities/DumpFDCOffsets.C new file mode 100644 index 00000000..a44f4703 --- /dev/null +++ b/TrackingAlignment/Utilities/DumpFDCOffsets.C @@ -0,0 +1,95 @@ +// Script to get current values of the offsets from the alignment root file and dump them to text files +#include +#include +#include +#include +#include "TProfile.h" +#include "TFile.h" + +using namespace std; + +void DumpFDCOffsets(TString rootFile = "hd_root.root"){ + + TFile *file = TFile::Open(rootFile); + TProfile *hFDCConstants; + file->GetObject("AlignmentConstants/FDCAlignmentConstants",hFDCConstants); + + // Cell offsets + // Indices are 101001, 101100 etc... + ofstream outFile; + outFile.open("cell_offsets.txt"); + for (unsigned int i = 1; i<=24; i++){ + int histIndex = i*1000; + outFile << hFDCConstants->GetBinContent(histIndex+1) << " " ; + outFile << hFDCConstants->GetBinContent(histIndex+100) << endl ; + } + outFile.close(); + + // Cathode Offsets + // Indices are 101, 102, 103, 104 + outFile.open("cathode_alignment.txt"); + for (unsigned int i = 1; i<=24; i++){ + int histIndex = i*1000; + outFile << hFDCConstants->GetBinContent(histIndex+103) << " " ;//dPhiU + outFile << hFDCConstants->GetBinContent(histIndex+101) << " " ;//dU + outFile << hFDCConstants->GetBinContent(histIndex+104) << " " ;//dPhiV + outFile << hFDCConstants->GetBinContent(histIndex+102) << endl ;//dV + } + outFile.close(); + + // Strip Pitches + // Indices are 200...209 + outFile.open("strip_pitches.txt"); + for (unsigned int i = 1; i<=24; i++){ + int histIndex = i*1000; + outFile << hFDCConstants->GetBinContent(histIndex+200) << " " ; + outFile << hFDCConstants->GetBinContent(histIndex+201) << " " ; + outFile << hFDCConstants->GetBinContent(histIndex+202) << " " ; + outFile << hFDCConstants->GetBinContent(histIndex+203) << " " ; + outFile << hFDCConstants->GetBinContent(histIndex+204) << " " ; + outFile << hFDCConstants->GetBinContent(histIndex+205) << " " ; + outFile << hFDCConstants->GetBinContent(histIndex+206) << " " ; + outFile << hFDCConstants->GetBinContent(histIndex+207) << " " ; + outFile << hFDCConstants->GetBinContent(histIndex+208) << " " ; + outFile << hFDCConstants->GetBinContent(histIndex+209) << endl; + } + outFile.close(); + + // Wire Alignment + // Indices are 2 + outFile.open("wire_alignment.txt"); + for (unsigned int i = 1; i<=24; i++){ + int histIndex = i*1000; + outFile << hFDCConstants->GetBinContent(histIndex+2) << " 0.0 0.0" << endl; + } + outFile.close(); + + for (unsigned int i = 1; i<=4; i++){ + outFile.open(Form("t0_package%i.txt",i)); + for (unsigned int j=1; j<=6;j++){ + for (unsigned int k = 1; k<= 96; k++){ + int histIndex = ((i-1)*4+j)*1000 + 900; + outFile << hFDCConstants->GetBinContent(histIndex+k)<< " " ; + } + outFile << endl; + } + outFile.close(); + } + //gains + for (unsigned int i = 1; i<=4; i++){ + outFile.open(Form("gains_package%i.txt",i)); + for (unsigned int j=1; j<=6;j++){ + for (unsigned int k = 1; k<= 216; k++){ + int histIndex = ((i-1)*4+j)*1000 + 300; + outFile << hFDCConstants->GetBinContent(histIndex+k) << " " ; + } + outFile << endl; + for (unsigned int k = 1; k<= 216; k++){ + int histIndex = ((i-1)*4+j)*1000 + 600; + outFile << hFDCConstants->GetBinContent(histIndex+k) << " " ; + } + outFile << endl; + } + outFile.close(); + } +}