Skip to content

Commit

Permalink
2D Alignment done
Browse files Browse the repository at this point in the history
  • Loading branch information
glukicov committed Dec 7, 2017
1 parent 2017865 commit c5b69fa
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 49 deletions.
19 changes: 11 additions & 8 deletions mpIIDESY/AlignTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Grid Submission Scripts:
Function Derivations in functions.tex
ROOT Plotting macro rootlogon.C [loaded automatically e.g.: rootbrowse Tracker.root]
Other?
TODO Describe all code -> Add to Github
Expand Down Expand Up @@ -129,6 +131,7 @@ int main(int argc, char* argv[]) {
int negDCA = 0; // counting negatively smeared DCAs
const Color_t colourVector[] = {kMagenta, kOrange, kBlue, kGreen, kYellow, kRed, kGray, kBlack}; //8 colours for up to 8 modules
gErrorIgnoreLevel = kWarning; // Display ROOT Warning and above messages [i.e. suppress info]
gROOT->Macro("rootlogon.C");
// Simple LR mapping for ROOT plots
char nameLR[] = {'L', 'R'};
char nameResSign[] = {'P', 'N'};
Expand Down Expand Up @@ -287,7 +290,7 @@ int main(int argc, char* argv[]) {
TH1F* h_track_true = new TH1F("h_track_true", "All track points: Truth", 49, -3, 3);
TH1F* h_track_recon = new TH1F("h_track_recon", "All track points: Recon", 49, -3, 3);
TH1F* h_track_TR_diff = new TH1F("h_track_TR_diff", "#Delta (Recon-True) track points", 149, -0.03, 0.03);
TH1I* h_labels = new TH1I("h_labels", "Labels in PEDE", 8 , 0, 8);
TH1I* h_labels = new TH1I("h_labels", "Labels in PEDE", 72, 10, 46);
TH1F* h_residual_true = new TH1F("h_residual_true", "Residuals: Truth", 500, -0.06, 0.06);
TH1F* h_chi2_true = new TH1F("h_chi2_true", "#Chi^{2}: Truth", 40, -1, 50);
TH1F* h_residual_recon = new TH1F("h_residual_recon", "Residuals: Recon", 199, -0.2, 0.2);
Expand All @@ -301,7 +304,7 @@ int main(int argc, char* argv[]) {
TH1F* h_driftRad = new TH1F("h_driftRad", "Drift Rad: circle fit", 149, -0.1, Tracker::instance()->getStrawRadius() + 0.25);
TH1F* h_DLC1 = new TH1F("h_DLC1", "DLC1: All Modules", 149, -1.1, 1.1); h_DLC1->SetDirectory(cd_PEDE);
TH1F* h_DLC2 = new TH1F("h_DLC2", "DLC2: All Modules", 879, -65.0, 65.0); h_DLC2->SetDirectory(cd_PEDE);
TH1F* h_DGL1 = new TH1F("h_DGL1", "DGL1: All Modules", 14989, -1.1, 1.1); h_DGL1->SetDirectory(cd_PEDE);
TH1F* h_DGL1 = new TH1F("h_DGL1", "DGL1: All Modules", 149, -1.1, 1.1); h_DGL1->SetDirectory(cd_PEDE);
TH1F* h_DGL2 = new TH1F("h_DGL2", "DGL2: All Modules", 149, -0.017, 0.017); h_DGL2->SetDirectory(cd_PEDE);

// "special" histos
Expand Down Expand Up @@ -541,7 +544,7 @@ int main(int argc, char* argv[]) {
h_sigma -> Fill(sigma_mp2); // errors
h_dca->Fill(generated_MC.dca[hitCount]); // DCA
h_dca_unsmeared->Fill(generated_MC.dca_unsmeared[hitCount]);
h_labels->Fill(l1);
h_labels->Fill(l1); h_labels->Fill(l2);
h_id_dca ->Fill(strawID);
h_driftRad->Fill(generated_MC.driftRad[hitCount]);
if (generated_MC.driftRad[hitCount] < 0) negDCA++;
Expand Down Expand Up @@ -908,11 +911,11 @@ int main(int argc, char* argv[]) {
file->Write();
file->Close();

metric << "| R: " << Tracker::instance()->getResolution() * 1e4 << " um "
<< "| DCA Cut of " << Tracker::instance()->getTrackCut() * 1e4 << " um : " << boolYN[Tracker::instance()->getTrackCutBool()]
<< "| Hit rej.: " << boolYN[Tracker::instance()->getHitCutStatus()]
<< "| Truth LR : " << boolYN[Tracker::instance()->getLRStatus()]
<< "| p-value cut (<): " << Tracker::instance()->getPValCut() ;
// metric << "| R: " << Tracker::instance()->getResolution() * 1e4 << " um "
// << "| DCA Cut of " << Tracker::instance()->getTrackCut() * 1e4 << " um : " << boolYN[Tracker::instance()->getTrackCutBool()]
// << "| Hit rej.: " << boolYN[Tracker::instance()->getHitCutStatus()]
// << "| Truth LR : " << boolYN[Tracker::instance()->getLRStatus()]
// << "| p-value cut (<): " << Tracker::instance()->getPValCut() ;

helper << endl;
helper << "Programme log written to: Tracker_log.txt" << endl;
Expand Down
8 changes: 5 additions & 3 deletions mpIIDESY/AlignTracker_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ MCData Tracker::MC_launch(float scatterError, ofstream& debug_calc, ofstream& de
float x1 = x0; // for parallel lines only
float xSlope = 0.0; // for parallel lines only

bool generalLines = true; // XXX quick hack
bool generalLines = false; // XXX quick hack
if (generalLines == true) {

float signXSlope;
Expand Down Expand Up @@ -766,12 +766,14 @@ void Tracker::misalign(ofstream& debug_mis, ofstream& pede_mis, bool debugBool,
sum_of_elems += *it;
}
overallMis = sum_of_elems / moduleN;
cout << "Manual Misalignment: " << endl;
cout << "Misalignment(M) and Offsets(O): " << endl;
for (int i_module = 0; i_module < moduleN; i_module++) {
cout << "M" << noshowpos << i_module + 1 << "x :: " << showpos << sdevX[i_module] << " cm. M" << noshowpos << i_module + 1 << "z :: " << showpos << sdevZ[i_module] << " cm. "; // absolute misalignment [as set by MC]
cout << "O" << noshowpos << i_module + 1 << "x :: " << showpos << offsetX[i_module] << "cm O" << noshowpos << i_module + 1 << "z :: " << offsetZ[i_module] << " cm. " << endl; // absolute misalignment [as set by MC]
//pede_mis << (offsetZ[i_module]-sdevZ[i_module]) << " ";
pede_mis << sdevZ[i_module] << " ";
if (i_module==1 || i_module==2){ // TODO move to pre-sigma function
pede_mis << sdevX[i_module] << " " << sdevZ[i_module] << " ";
}
float relMisTmp = sdevZ[i_module] - overallMis;
//now push these misalignment parameters for all layers in the module [for use later]
for (int i_view = 0; i_view < viewN; i_view++) {
Expand Down
4 changes: 2 additions & 2 deletions mpIIDESY/AlignTracker_methods.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ class Tracker {
//initialising physics variables
// MF + inhomogeneity, E_loss, MS

float dispX[8] = {0.00, 0.03, -0.01, 0.00, 0.0, 0.0, 0.0, 0.0}; // manual misalignment [relative misalignment per module]
float dispZ[8] = {0.0, 0.02, 0.01, 0.0, 0.0, 0.0, 0.0, 0.0}; // manual misalignment [relative misalignment per module]
float dispX[8] = {0.0, 0.03, -0.03, 0.00, 0.0, 0.0, 0.0, 0.0}; // manual misalignment [relative misalignment per module]
float dispZ[8] = {0.0, 0.005, 0.01, 0.0, 0.0, 0.0, 0.0, 0.0}; // manual misalignment [relative misalignment per module]
float offsetX[8] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; // To the ideal detector, for second pede iteration
float offsetZ[8] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; // To the ideal detector, for second pede iteration

Expand Down
6 changes: 4 additions & 2 deletions mpIIDESY/ConcatenatePEDE.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
number_str = line.split()
moduleN=int(number_str[0])
trackN=int(number_str[4])
#parN=int(number_str[9])


parN = 2
print "Parameters from Simulation:"
print "moduleN= ",moduleN
print "trackN= ",trackN
print "parN= ", parN

label = []
mis = []
Expand All @@ -39,7 +41,7 @@
error.append(float(number_str[4])) # otherwise, take the error estimate by PEDE

f = open('PEDE_Mis.txt', 'a')
for i in range (0, moduleN):
for i in range (0, moduleN*parN):
f.write(str(label[i]))
f.write(" ")
f.write(str(mis[i]))
Expand Down
2 changes: 1 addition & 1 deletion mpIIDESY/PEDE_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
intercept = float(number_str[1])

for i in range(0, len(tracksCut)):
subprocess.call(["./AlignTracker", "n" , str(tracksCut[i]), "0.0", "0.0" ])
subprocess.call(["./AlignTracker", "n" , str(tracksCut[i]), "0.0", "0.0", "0.0", "0.0"])

subprocess.call(["./pede", "Tracker_str.txt" ])

Expand Down
82 changes: 52 additions & 30 deletions mpIIDESY/TrackerLaunch.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
number_str = line.split()
moduleN=int(number_str[0])

parN=2
# Quickly open the PEDe file and count lines only:
lineN= sum(1 for line in open('PEDE_Mis.txt'))

Expand All @@ -29,7 +30,7 @@
print "PEDE Trials= ",lineN


mis_C = [0 for i_module in xrange(moduleN)]
mis_C = [0 for i_module in xrange(moduleN*parN)]
# Get 1 set of misalignment from simulation

with open("Tracker_pede_mis.txt") as f:
Expand All @@ -38,11 +39,12 @@

for i_module in range(0, moduleN):
mis_C[i_module]=float(number_str[i_module])
print "mis_C= ", mis_C


Labels = [[0 for i_module in xrange(moduleN)] for i_lines in xrange(lineN)]
Misals = [[0 for i_module in xrange(moduleN)] for i_lines in xrange(lineN)]
Errors = [[0 for i_module in xrange(moduleN)] for i_lines in xrange(lineN)]
Labels = [[0 for i_module in xrange(moduleN*parN)] for i_lines in xrange(lineN)]
Misals = [[0 for i_module in xrange(moduleN*parN)] for i_lines in xrange(lineN)]
Errors = [[0 for i_module in xrange(moduleN*parN)] for i_lines in xrange(lineN)]
trackN = [] # track count correspond to line number


Expand All @@ -51,15 +53,22 @@
for line in f: #Line is a string
number_str = line.split()

for i_module in range(0, moduleN):
Labels[line_i][i_module]=int(number_str[0+i_module*3])
Misals[line_i][i_module]=float(number_str[1+i_module*3])
Errors[line_i][i_module]=float(number_str[2+i_module*3])
for i_par in range(0, moduleN*parN):
label=int(number_str[0+i_par*3])
if (label==21 or label==22 or label==31 or label==32):
error=float(number_str[2+i_par*3])
misal=float(number_str[1+i_par*3])
Labels[line_i][i_par]=label
Misals[line_i][i_par]=misal
Errors[line_i][i_par]=error
#print "label=", label, "misal=", misal, "error=", error
else:
i_par+1

if (moduleN==4):
trackN.append(int(number_str[12]))
trackN.append(int(number_str[-1]))
if (moduleN==6):
trackN.append(int(number_str[18]))
trackN.append(int(number_str[-1]))
#print number_str[18]
line_i = line_i + 1

Expand All @@ -79,34 +88,44 @@
# dM=Misals[i_lines][i_module] - mis_C[i_module]
# print dM

if (moduleN==6):
plt.rcParams.update({'font.size': 8})
plt.rcParams.update({'font.size': 8})

constN =2 # TODO
expectPars=(21, 22, 31, 32)
moduleN=moduleN-constN

#Plot difference for all modules
plt.figure(1)
for i_module in range(0, moduleN):
for i_counter in range(0, parN*moduleN):
i_par=expectPars[i_counter]
if (parN==1):
if(i_par==1):
plotID=21
if(i_par==2):
plotID=22

if (moduleN==4):
if(i_module==0):
if (parN==2):
if(i_par==21):
plotID=221
if(i_module==1):
if(i_par==22):
plotID=222
if(i_module==2):
if(i_par==31):
plotID=223
if(i_module==3):
if(i_par==32):
plotID=224
if (moduleN==6):
if(i_module==0):

if (parN==3):
if(i_par==21):
plotID=421
if(i_module==1):
if(i_par==22):
plotID=422
if(i_module==2):
if(i_par==23):
plotID=423
if(i_module==3):
if(i_par==31):
plotID=424
if(i_module==4):
if(i_par==32):
plotID=425
if(i_module==5):
if(i_par==33):
plotID=426

plt.subplot(plotID)
Expand All @@ -118,17 +137,20 @@
*zip(*itertools.chain.from_iterable(itertools.combinations(line, 2))),
color = 'green')
for i_lines in range(0, lineN):
dM=(Misals[i_lines][i_module]-mis_C[i_module])*1e4
dM=(Misals[i_lines][i_counter+2]-mis_C[i_counter])*1e4
#print 'Misals[i_lines][i_module]=', Misals[i_lines][i_module], 'mis_C[i_module]=', mis_C[i_module], 'dM=', dM
errorM=Errors[i_lines][i_module]*1e4
errorM=Errors[i_lines][i_counter+2]*1e4
print "dM=", dM, "errorM=", errorM
plt.errorbar(trackN[i_lines], dM, yerr=errorM, color="red") # converting 1 cm = 10'000 um
plt.plot(trackN[i_lines], dM, marker="_", color="red")


plt.title('FoM Module %s' %(i_module+1), fontsize=10)
plt.title('FoM Parameter %s' %(i_par), fontsize=10)
#axes.set_ylim([beamX0-1,beamX1+1])
axes.set_xlim(-500,trackN[lineN-1]+100)
axes.set_ylim(-1000, 1000)
if(i_par==22 or i_par==32):
axes.set_ylim(-500, 500)
if(i_par==21 or i_par==31):
axes.set_ylim(-20, 20)


plt.xlabel("Number of Tracks", fontsize=10)
Expand Down
6 changes: 3 additions & 3 deletions mpIIDESY/rootlogon.C
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//This is the file rootlogon.C
{
printf("\n ~/rootlogon.C loaded with !!!4 sig.fig.!!! for custom Opt Fit and Stat!\n");
printf("\n ~/rootlogon.C loaded with !!4 sig.fig.!! for custom Opt Fit and Stat!\n");

TStyle *myStyle = new TStyle("MyStyle", "My Root Styles");

Expand Down Expand Up @@ -38,8 +38,8 @@


// Histo Filling (visual)
myStyle->SetHistFillColor(kRed);
myStyle->SetHistFillStyle(3012);
myStyle->SetHistFillColor(kGreen);
myStyle->SetHistFillStyle(3013);

// Stats display options
myStyle->SetOptStat("ourRmMe"); //over/under -flows, Rms and Means with errors, number of entries
Expand Down

0 comments on commit c5b69fa

Please sign in to comment.