10 #include "TPaveStats.h"
59 detNames[0] = TString(
"PXB");
60 detNames[1] = TString(
"PXF");
61 detNames[2] = TString(
"TIB");
62 detNames[3] = TString(
"TID");
63 detNames[4] = TString(
"TOB");
64 detNames[5] = TString(
"TEC");
66 for (
unsigned int isublevel = 0; isublevel < 6; isublevel++)
68 TGraph*
g =
new TGraph(0);
75 legend->AddEntry(
g, detNames[isublevel],
"lp");
83 cout <<
"--- extracting AlignParams ; Par " << currentPar <<
" ---" << endl << endl;
91 cout <<
"Loaded par file -. OK" << endl;
93 const TList* keysv = fv->GetListOfKeys();
94 const unsigned int maxIteration = keysv->GetSize() - 1;
98 else sprintf(fileaction,
"NEW");
102 TTree* tree0 = (TTree*)fv->Get(keysv->At(0)->GetName());
111 tree0->SetBranchAddress(
"Id", &detId0);
113 const int ndets=tree0->GetEntries();
116 sprintf(ppdirname,
"ShiftsPar%d", currentPar);
117 fout->mkdir(ppdirname);
118 gDirectory->cd(ppdirname);
122 TH1D* hpariter[maxIteration];
123 for (
unsigned int a = 0;
a < maxIteration;
a++){
124 char histoname[32], histotitle[32];
125 sprintf(histoname,
"Par_%d_Iter_%d", currentPar,
a);
126 sprintf(histotitle,
"Par %d for iteration #%d", currentPar,
a);
127 hpariter[
a]=
new TH1D(histoname, histoname, 1000, -1.0, 1.0);
130 for (
int i = 0;
i < ndets;
i++){
131 char histoname[32], histotitle[32];
132 sprintf(histoname,
"Par_%d_SiDet_%d", currentPar,
i);
133 sprintf(histotitle,
"Par %d for detector #%d", currentPar,
i);
134 hpar1[
i]=
new TH1D(histoname, histoname, maxIteration+1, -0.5, maxIteration+0.5);
138 ofstream flist(
"./List_aligned_dets.txt",
ios::out);
142 int modules_accepted = 0;
143 for (
unsigned int iter = 0; iter <= maxIteration; iter++){
147 TTree* tmpTree = (TTree*)fv->Get(keysv->At(iter)->GetName());
149 tmpTree->SetBranchAddress(
"Id", &detId);
150 tmpTree->SetBranchAddress(
"Nhit", &nHit);
151 tmpTree->SetBranchAddress(
"Par", &par);
153 std::cout <<
"iteration: " << iter <<
"..." << std::endl;
157 for (
int j = 0;
j < tmpTree->GetEntries();
j++){
159 tmpTree->GetEntry(
j);
160 bool passSubdetCut =
true;
161 if (subDet > 0){
if (
GetSubDet(detId) != subDet) passSubdetCut =
false; }
162 if (doubleSided > 0){
167 if ((nHit >=
minHits)&&(passSubdetCut)){
168 hpar1[
j]->SetBinContent(iter+1, par[currentPar]);
178 if ((iter==maxIteration-1)&&(currentPar==0))flist << detId << endl;
185 std::cout <<
"Modules accepted: " << modules_accepted << std::endl;
201 cout <<
"\n--- extracting AlignShifts ; Par " << currentPar <<
" ---" << endl << endl;
203 const TList* keysa = fa->GetListOfKeys();
204 const unsigned int maxIteration = keysa->GetSize();
207 const TList* keysv = fv->GetListOfKeys();
214 else sprintf(fileaction,
"NEW");
217 TTree* tree0 = (TTree*)fa->Get(keysa->At(0)->GetName());
218 const char* tree0v_Name = keysv->At(0)->GetName();
219 tree0->AddFriend(tree0v_Name, fv);
223 tree0->SetBranchAddress(
"Id", &detId0);
225 const int ndets=tree0->GetEntries();
228 TH1D* hiter_ali[maxIteration];
230 sprintf(ppdirname,
"Shifts%d", currentPar);
231 fout->mkdir(ppdirname);
232 gDirectory->cd(ppdirname);
234 for (
unsigned int a = 0;
a < maxIteration;
a++){
235 char histoname[64], histotitle[64];
239 sprintf(histoname,
"AlignedShift_%d_Iter_%d", currentPar,
a);
240 sprintf(histotitle,
"Aligned Shift %d for iteration #%d", currentPar,
a);
241 hiter_ali[
a]=
new TH1D(histoname, histoname, ndets, 0, ndets);
243 for (
int i = 0;
i < ndets;
i++){
244 char histoname[64], histotitle[64];
245 sprintf(histoname,
"Shift_%d_SiDet_%d", currentPar,
i);
246 sprintf(histotitle,
"Shift %d for detector #%d", currentPar,
i);
247 hshift[
i]=
new TH1D(histoname, histoname, maxIteration, -0.5, maxIteration-0.5);
251 int modules_accepted = 0;
263 detNames[0] = TString(
"PXB");
264 detNames[1] = TString(
"PXF");
265 detNames[2] = TString(
"TIB");
266 detNames[3] = TString(
"TID");
267 detNames[4] = TString(
"TOB");
268 detNames[5] = TString(
"TEC");
273 TTree* tmpTree_true = (TTree*)fa->Get(
"AlignablesAbsPos_0");
277 tmpTree_true->SetBranchAddress(
"Pos", &tpos);
279 if (currentPar >= 3){
281 tmpTree_true->SetBranchAddress(
"Rot", &trot);
284 for (
unsigned int iter = 1; iter < maxIteration; iter++){
286 TTree* tmpTree = (TTree*)fa->Get(keysa->At(iter)->GetName());
287 const char* tmpTreev = keysv->At(iter)->GetName();
288 tmpTree->AddFriend(tmpTreev, fv);
289 tmpTree->SetBranchAddress(
"Id", &detId);
290 tmpTree->SetBranchAddress(
"Nhit", &nHit);
291 tmpTree->SetBranchAddress(
"ParError", &aerr);
293 if (currentPar < 3){ tmpTree->SetBranchAddress(
"Pos", &apos); }
294 tmpTree->SetBranchAddress(
"Rot", &arot);
299 for (
int j = 0;
j < tmpTree->GetEntries();
j++){
300 tmpTree_true->GetEntry(
j);
301 tmpTree->GetEntry(
j);
307 bool passSubdetCut =
true;
309 if (subDet > 0){
if (
GetSubDet(detId) != subDet) passSubdetCut =
false; }
315 if ((nHit >=
minHits)&&(passSubdetCut)){
319 TVectorD dr_ali(3, apos);
320 TVectorD r_true(3, tpos);
321 TMatrixD R_true(3, 3, trot);
333 hshift[
j]->SetBinContent(iter+1, dr_ali[currentPar]);
337 hiter_ali[iter]->SetBinContent(
j+1, dr_ali[currentPar]);
341 if (currentPar >= 3){
343 TMatrixD dR_ali(3, 3, arot);
344 TMatrixD R_true(3, 3, trot);
346 dR_ali = dR_ali* TMatrixD(TMatrixD::kTransposed, R_true);
349 double dR_ali_euler = 0;
350 if (currentPar == 3){
352 dR_ali_euler = -std::atan2(dR_ali(2, 1), dR_ali(2, 2));
354 if (currentPar == 4){
356 dR_ali_euler = -std::asin(dR_ali(2, 0));
358 if (currentPar == 5){
360 dR_ali_euler = -std::atan2(dR_ali(1, 0), dR_ali(0, 0));
362 hshift[
j]->SetBinContent(iter+1, dR_ali_euler);
364 hiter_ali[iter]->SetBinContent(
j+1, dR_ali_euler);
367 hiter_ali[iter]->GetXaxis()->SetBinLabel(
j+1, detNames[
GetSubDet(detId)-1]);
368 hiter_ali[iter]->SetBinError(
j+1, aerr[currentPar]);
370 hiter_ali[iter]->LabelsOption(
"u",
"x");
377 std::cout <<
"Modules accepted: " << modules_accepted << std::endl;
382 std::cout <<
"Deleting..." << std::flush;
384 std::cout <<
"Deleting..." << std::flush;
397 cout <<
"_|_| plotting AlignParams |_|_" << endl <<
"---> " << ShiftsOrParams << endl;
398 bool bParams =
false;
399 bool bShifts =
false;
400 if (ShiftsOrParams ==
"PARAMS") bParams =
true;
401 if (ShiftsOrParams ==
"SHIFTS") bShifts =
true;
408 TCanvas* c_params =
new TCanvas(
"can_params",
"CAN_PARAMS", 1200, 900);
409 c_params->Divide(3, 2);
414 d = (TDirectory*)
f->Get(
"ShiftsPar0");
419 d = (TDirectory*)
f->Get(
"Shifts0");
424 for (
int iPar = 0; iPar < 6; iPar++){
426 c_params->cd(iPar+1);
427 gPad->SetTopMargin(0.15);
428 gPad->SetBottomMargin(0.15);
430 if (bParams) sprintf(ppdirname,
"ShiftsPar%d", iPar);
431 if (bShifts) sprintf(ppdirname,
"Shifts%d", iPar);
432 if (iPar > 0)gDirectory->cd(
"../");
433 gDirectory->cd(ppdirname);
438 int sampling_ratio=1;
439 int ndets_plotted=(
int)ndets/sampling_ratio;
440 cout <<
"Plotting " << ndets_plotted <<
" detectors over a total of " << ndets << endl;
442 double histomax, histomin;
467 while ((
i<ndets_plotted) && (
i*sampling_ratio<ndets)){
468 if (bParams) sprintf(histoname,
"Par_%d_SiDet_%d", iPar,
i*sampling_ratio);
469 if (bShifts) sprintf(histoname,
"Shift_%d_SiDet_%d", iPar,
i*sampling_ratio);
470 hpar1[
i]=(TH1D*)gDirectory->Get(histoname);
472 if (iPar>=3)hpar1[
i]->Scale(1000.0);
473 else hpar1[
i]->Scale(10000.0);
475 hpar1[
i]->SetMarkerStyle(7);
476 hpar1[
i]->SetStats(0);
478 double tmpmax=hpar1[
i]->GetBinContent(hpar1[
i]->GetMaximumBin());
479 double tmpmin=hpar1[
i]->GetBinContent(hpar1[
i]->GetMinimumBin());
482 if (tmpmax>histomax)histomax=tmpmax*1.2;
483 if (tmpmin<histomin)histomin=tmpmin*1.2;
488 hpar1[
i]->SetXTitle(
"Iteration");
491 if (iPar==0)hpar1[
i]->SetYTitle(
"#delta u param (#mum)");
492 else if (iPar==1)hpar1[
i]->SetYTitle(
"#delta v param (#mum)");
493 else if (iPar==2)hpar1[
i]->SetYTitle(
"#delta w param (#mum)");
494 else if (iPar==3)hpar1[
i]->SetYTitle(
"#delta #alpha param (mrad)");
495 else if (iPar==4)hpar1[
i]->SetYTitle(
"#delta #beta param (mrad)");
496 else if (iPar==5)hpar1[
i]->SetYTitle(
"#delta #gamma param (mrad)");
497 else hpar1[
i]->SetYTitle(
"dunno");
500 if (iPar==0)hpar1[
i]->SetYTitle(
"#delta u shift (#mum)");
501 else if (iPar==1)hpar1[
i]->SetYTitle(
"#delta v shift (#mum)");
502 else if (iPar==2)hpar1[
i]->SetYTitle(
"#delta w shift (#mum)");
503 else if (iPar==3)hpar1[
i]->SetYTitle(
"#delta #alpha shift (mrad)");
504 else if (iPar==4)hpar1[
i]->SetYTitle(
"#delta #beta shift (mrad)");
505 else if (iPar==5)hpar1[
i]->SetYTitle(
"#delta #gamma shift (mrad)");
506 else hpar1[
i]->SetYTitle(
"dunno");
509 hpar1[
i]->GetYaxis()->SetTitleOffset(1.5);
511 hpar1[
i]->SetTitle(
"");
512 hpar1[
i]->SetMaximum(histomax);
513 hpar1[
i]->SetMinimum(histomin);
514 hpar1[
i]->Draw(
"PL");
517 else hpar1[
i]->Draw(
"PLsame");
520 hpar1[0]->SetMaximum(histomax);
521 hpar1[0]->SetMinimum(histomin);
523 cout <<
"Plotted " <<
i <<
" aligned detectors" << endl;
529 std::cout <<
"Deleting..." << std::flush;
531 std::cout <<
"Deleting..." << std::flush;
541 cout <<
"Welcome to HIPplots::plotAlignParamsAtIter " << iter << endl;
542 bool bParams =
false;
543 bool bShifts =
false;
544 if (ShiftsOrParams ==
"PARAMS") bParams =
true;
545 else if (ShiftsOrParams ==
"SHIFTS") bShifts =
true;
546 else {
cout <<
"ERROR in plotAliParamsAtIter!!! Wrong input argument: " << ShiftsOrParams <<
" . Exiting" << endl;
return; }
552 TCanvas* c_params =
new TCanvas(
"can_params",
"CAN_PARAMS", 1200, 700);
553 c_params->Divide(3, 2);
559 for (
int iPar = 0; iPar < 6; iPar++){
561 c_params->cd(iPar+1);
563 gPad->SetTopMargin(0.15);
564 gPad->SetBottomMargin(0.15);
566 if (bParams) sprintf(ppdirname,
"ShiftsPar%d", iPar);
567 if (bShifts) sprintf(ppdirname,
"Shifts%d", iPar);
568 if (iPar > 0)gDirectory->cd(
"../");
569 gDirectory->cd(ppdirname);
574 if (bParams) sprintf(histoname,
"Par_%d_Iter_%d", iPar, iter);
575 if (bShifts) sprintf(histoname,
"AlignedShift_%d_Iter_%d", iPar, iter);
576 hiter = (TH1D*)gDirectory->Get(histoname);
582 hiter->SetXTitle(
"Sub-Det");
583 if (iPar==0)hiter->SetYTitle(
"#delta u (#mum)");
584 else if (iPar==1)hiter->SetYTitle(
"#delta v (#mum)");
585 else if (iPar==2)hiter->SetYTitle(
"#delta w (#mum)");
586 else if (iPar==3)hiter->SetYTitle(
"#delta #alpha (#murad)");
587 else if (iPar==4)hiter->SetYTitle(
"#delta #beta (#murad)");
588 else if (iPar==5)hiter->SetYTitle(
"#delta #gamma (#murad)");
589 else hiter->SetXTitle(
"dunno");
590 hiter->GetYaxis()->SetTitleOffset(1.5);
592 double histomax, histomin;
593 if (iPar==2||iPar==5) { histomax=200; histomin=-200; }
594 else { histomax=100; histomin=-100; }
596 if (iPar>=3)hiter->Scale(1000000.0);
597 else hiter->Scale(10000.0);
598 double tmpmax=hiter->GetBinContent(hiter->GetMaximumBin());
599 double tmpmin=hiter->GetBinContent(hiter->GetMinimumBin());
600 if (tmpmax>histomax)histomax=tmpmax*1.2;
601 if (tmpmin<histomin)histomin=tmpmin*1.2;
602 hiter->SetMaximum(histomax);
603 hiter->SetMinimum(histomin);
605 hiter->SetLineColor(1);
606 TColor*
col = gROOT->GetColor(kCyan+1);
608 hiter->SetFillColor(
col->GetNumber());
610 hiter->SetMarkerStyle(7);
641 cout <<
"\n--- Welcome to extractAlignableChiSquare ---" << endl;
642 cout <<
"\nInput parameters:\n\tMinimum number of hits per alignbale = " <<
minHits <<
"\n\tSubdetetctor selection" << subDet << endl;
645 cout <<
"Warning ! Allowing to select modules with NO hits. Chi2 not defined for them. Setting automatically minNhits=1 !!!" << endl;
650 const TList* keysv = fv->GetListOfKeys();
651 const unsigned int maxIteration = keysv->GetSize() - 1;
652 cout <<
"MaxIteration is " << maxIteration << endl;
656 else sprintf(fileaction,
"NEW");
659 TTree* tree0 = (TTree*)fv->Get(keysv->At(0)->GetName());
661 tree0->SetBranchAddress(
"Id", &detId0);
662 const int ndets=tree0->GetEntries();
663 TH1D* halichi2n[ndets];
664 TH1D* htotchi2n[maxIteration];
665 TH1D* hprobdist[maxIteration];
667 sprintf(ppdirname,
"AlignablesChi2n");
668 fout->mkdir(ppdirname);
669 gDirectory->cd(ppdirname);
671 for (
int iter = 1; iter <=(
int)maxIteration; iter++){
672 char histoname[64], histotitle[128];
673 sprintf(histoname,
"Chi2n_iter%d", iter);
674 sprintf(histotitle,
"Distribution of Normalised #chi^{2} for All alignables at iter %d", iter);
675 htotchi2n[iter-1]=
new TH1D(histoname, histotitle, 1000, 0.0, 10.0);
676 sprintf(histoname,
"ProbChi2_%d", iter);
677 sprintf(histotitle,
"Distribution of Prob(#chi^{2},ndof) at iter %d", iter);
678 hprobdist[iter-1]=
new TH1D(histoname, histotitle, 100, 0.0, 1.0);
680 gDirectory->mkdir(
"AlignablewiseChi2n");
681 gDirectory->cd(
"AlignablewiseChi2n");
683 for (
int i = 0;
i < (
int)ndets;
i++){
685 char histoname[64], histotitle[64];
686 sprintf(histoname,
"Chi2n_%d",
i);
687 sprintf(histotitle,
"Normalised #chi^{2} for detector #%d",
i);
688 halichi2n[
i]=
new TH1D(histoname, histotitle, maxIteration, 0.5, maxIteration+0.5);
692 int modules_accepted = 0;
693 for (
unsigned int iter = 1; iter <= maxIteration; iter++){
695 TTree* tmpTreeUV = (TTree*)fv->Get(keysv->At(iter)->GetName());
696 cout <<
"Taking tree " << keysv->At(iter)->GetName() << endl;
698 tmpTreeUV->SetBranchStatus(
"*", 0);
699 tmpTreeUV->SetBranchStatus(
"Id", 1);
700 tmpTreeUV->SetBranchStatus(
"Nhit", 1);
701 tmpTreeUV->SetBranchStatus(
"AlignableChi2", 1);
702 tmpTreeUV->SetBranchStatus(
"AlignableNdof", 1);
704 unsigned int alindof=0;
706 unsigned int detId=0;
707 tmpTreeUV->SetBranchAddress(
"AlignableChi2", &alichi2);
708 tmpTreeUV->SetBranchAddress(
"AlignableNdof", &alindof);
709 tmpTreeUV->SetBranchAddress(
"Id", &detId);
710 tmpTreeUV->SetBranchAddress(
"Nhit", &nHit);
714 for (
int j = 0;
j < tmpTreeUV->GetEntries();
j++){
715 tmpTreeUV->GetEntry(
j);
717 bool passSubdetCut =
true;
718 if (subDet > 0){
if (
GetSubDet(detId) != subDet) passSubdetCut =
false; }
719 if (doubleSided > 0){
724 if ((nHit >=
minHits)&&(passSubdetCut)){
725 halichi2n[
j]->SetBinContent(iter,
double(alichi2 / alindof));
727 double prob=TMath::Prob(
double(alichi2),
int(alindof));
729 htotchi2n[iter-1]->Fill(
double(alichi2 / alindof));
730 hprobdist[iter-1]->Fill(
prob);
735 cout <<
"alignables accepted at iteration " << iter <<
" = " << modules_accepted << endl;
750 cout <<
"Finished extractAlignableChiSquare" << endl;
756 cout <<
"\n--- extractSurveyResiduals has been called ---" << endl;
759 const TList* keysv = fv->GetListOfKeys();
760 const unsigned int maxIteration = keysv->GetSize();
761 cout <<
"MaxIteration is " << maxIteration << endl;
765 else sprintf(fileaction,
"NEW");
768 TTree* tree0 = (TTree*)fv->Get(keysv->At(0)->GetName());
770 tree0->SetBranchAddress(
"Id", &detId0);
771 const int ndets=tree0->GetEntries();
772 TH1D* hsurvey[ndets];
773 TH1D* htotres[maxIteration];
776 sprintf(ppdirname,
"SurveyResiduals");
777 fout->mkdir(ppdirname);
778 gDirectory->cd(ppdirname);
780 for (
int iter = 1; iter <=(
int)maxIteration; iter++){
781 char histoname[64], histotitle[128];
782 sprintf(histoname,
"SurveyRes_Par%d_iter%d", currentPar, iter);
783 sprintf(histotitle,
"Distribution of survey Residuals for All alignables ; Par=%d ; iter %d", currentPar, iter);
784 htotres[iter-1]=
new TH1D(histoname, histotitle, 1000, 0.0, 10.0);
786 gDirectory->mkdir(
"SurveyResiduals_alignables");
787 gDirectory->cd(
"SurveyResiduals_alignables");
789 for (
int i = 0;
i < (
int)ndets;
i++){
791 char histoname[64], histotitle[64];
792 sprintf(histoname,
"SurveyRes_Par%d_%d", currentPar,
i);
793 sprintf(histotitle,
"Survey residual for detector #%d - Par=%d",
i, currentPar);
794 hsurvey[
i]=
new TH1D(histoname, histotitle, maxIteration, 0.5, maxIteration+0.5);
798 int modules_accepted = 0;
799 for (
unsigned int iter = 1; iter <= maxIteration; iter++){
801 TTree* tmpTreeUV = (TTree*)fv->Get(keysv->At(iter)->GetName());
802 cout <<
"Taking tree " << keysv->At(iter)->GetName() << endl;
804 tmpTreeUV->SetBranchStatus(
"*", 0);
805 tmpTreeUV->SetBranchStatus(
"Id", 1);
806 tmpTreeUV->SetBranchStatus(
"Par", 1);
809 unsigned int detId=0;
810 tmpTreeUV->SetBranchAddress(
"Par", &par);
811 tmpTreeUV->SetBranchAddress(
"Id", &detId);
816 for (
int j = 0;
j < tmpTreeUV->GetEntries();
j++){
817 tmpTreeUV->GetEntry(
j);
819 bool passSubdetCut =
true;
820 if (subDet > 0){
if (
GetSubDet(detId) != subDet) passSubdetCut =
false; }
822 hsurvey[
j]->SetBinContent(iter,
double(par[currentPar]));
828 cout <<
"alignables accepted at iteration " << iter <<
" = " << modules_accepted << endl;
836 cout <<
"Finished extractAlignableChiSquare" << endl;
848 TCanvas* c_alichi2n=
new TCanvas(
"can_alichi2n",
"CAN_ALIGNABLECHI2N", 900, 900);
850 TDirectory* chi_d1=(TDirectory*)
f->Get(
"AlignablesChi2n");
851 const int maxIteration=
GetNIterations(chi_d1,
"Chi2n_iter", 1)-1;
852 cout <<
"N iterations " << maxIteration << endl;
854 gDirectory->cd(
"AlignablesChi2n");
855 TDirectory* chi_d=(TDirectory*)gDirectory->Get(
"AlignablewiseChi2n");
858 gDirectory->cd(
"AlignablewiseChi2n");
861 int sampling_ratio=1;
862 int ndets_plotted=(
int)ndets/sampling_ratio;
863 cout <<
"Sampling " << ndets_plotted <<
" detectors over a total of " << ndets << endl;
864 double histomax=0.1, histomin=-0.1;
865 bool firstplotted=
false;
866 int firstplottedindex=0;
869 while ((
i<ndets_plotted) && (
i*sampling_ratio<ndets)){
870 sprintf(histoname,
"Chi2n_%d",
i);
871 hchi2n[
i]=(TH1D*)gDirectory->Get(histoname);
876 for (
int bin=1;
bin<=hchi2n[
i]->GetNbinsX();
bin++){
877 if (hchi2n[
i]->GetBinContent(
bin)>minChi2n){ chi2ncut=
true;
break; }
886 if (chi2ncut&&plothisto){
887 double tmpmax=hchi2n[
i]->GetBinContent(hchi2n[
i]->GetMaximumBin());
888 double tmpmin=hchi2n[
i]->GetBinContent(hchi2n[
i]->GetMinimumBin());
891 if (tmpmax>histomax)histomax=tmpmax;
892 if (tmpmin<histomin)histomin=tmpmin;
894 hchi2n[
i]->SetMaximum(histomax);
895 hchi2n[
i]->SetMinimum(histomin);
896 hchi2n[
i]->SetStats(0);
900 hchi2n[
i]->SetXTitle(
"Iteration");
901 hchi2n[
i]->SetYTitle(
"#chi^{2} / # dof");
903 hchi2n[
i]->SetTitle(
"Reduced #chi^{2} for alignables");
904 hchi2n[
i]->Draw(
"PL");
908 else hchi2n[
i]->Draw(
"PLsame");
913 hchi2n[firstplottedindex]->SetMaximum(histomax*1.2);
914 hchi2n[firstplottedindex]->SetMinimum(histomin*0.8);
916 hchi2n[firstplottedindex]->SetMaximum(histomax);
917 hchi2n[firstplottedindex]->SetMinimum(histomin);
919 cout <<
"Plotted " << totalplotted <<
" alignables over an initial sample of " << ndets_plotted << endl;
920 TText* txtchi2n_1=
new TText();
921 txtchi2n_1->SetTextFont(63);
922 txtchi2n_1->SetTextSize(22);
923 char strchi2n_1[128];
924 sprintf(strchi2n_1,
"Plotted alignables (Chi2n > %.3f): %d / %d", minChi2n, totalplotted, ndets_plotted);
925 txtchi2n_1->DrawText(1.2, 0.0, strchi2n_1);
926 char finplotname[192];
927 sprintf(finplotname,
"%s.png",
plotName);
928 c_alichi2n->SaveAs(finplotname);
933 cout <<
"Doing distrib" << endl;
934 gDirectory->cd(
"../");
935 TCanvas* c_chi2ndist=
new TCanvas(
"can_chi2ndistr",
"CAN_CHI2N_DISTRIBUTION", 900, 900);
937 TH1D* hiter[maxIteration];
938 TLegend*
l=
new TLegend(0.7, 0.7, 0.9, 0.9);
941 int colors[10]={ 1, 2, 8, 4, 6, 7, 94, 52, 41, 45 };
945 for (
i=0;
i<maxIteration;
i++){
946 sprintf(histoname,
"Chi2n_iter%d",
i+1);
947 hiter[
i]=(TH1D*)gDirectory->Get(histoname);
948 hiter[
i]->SetXTitle(
"#chi^{2} / dof");
949 hiter[
i]->SetYTitle(
"Alignables");
950 hiter[
i]->SetTitle(
"Normalised #chi^{2} of Alignables");
952 hiter[
i]->GetXaxis()->SetRangeUser(0.0, 3.0);
953 hiter[
i]->SetLineColor(
i);
955 char legend_entry[64];
956 float histmean=hiter[
i]->GetMean();
958 hiter[
i]->SetLineColor(
colors[taken]);
960 sprintf(legend_entry,
"Norm #chi^{2}; Iter %d; %.4f",
i, histmean);
961 l->AddEntry(hiter[
i], legend_entry,
"L");
962 tmpmax=hiter[
i]->GetBinContent(hiter[
i]->GetMaximumBin());
966 else if ((
i+1)%5==0){
967 hiter[
i]->SetLineColor(
colors[taken]);
969 sprintf(legend_entry,
"Norm #chi^{2}; Iter %d; %.4f",
i+1, histmean);
970 l->AddEntry(hiter[
i], legend_entry,
"L");
971 tmpmax=hiter[
i]->GetBinContent(hiter[
i]->GetMaximumBin());
972 if (tmpmax>newmax)newmax=tmpmax;
976 cout <<
"NewMax after 1st loop -> " << newmax << endl;
978 for (
i=0;
i<maxIteration;
i++){
979 hiter[
i]->SetMaximum(newmax*1.1);
980 if (
i==1) hiter[
i]->Draw(
"");
981 else if ((
i+1)%5==0) hiter[
i]->Draw(
"same");
985 sprintf(finplotname,
"%s_distr.png",
plotName);
986 cout << finplotname << endl;
987 c_chi2ndist->SaveAs(finplotname);
988 c_chi2ndist->SetLogy();
989 sprintf(finplotname,
"%s_distrlog.png",
plotName);
990 cout << finplotname << endl;
991 c_chi2ndist->SaveAs(finplotname);
1002 int fin_iter=0,
i=startingcounter;
1003 bool obj_exist=kTRUE;
1006 sprintf(objname,
"%s%d",
tag,
i);
1007 if (!
f->FindObjectAny(objname))obj_exist=kFALSE;
1011 cout <<
"Max Iterations is " << fin_iter << endl;
1019 const int reserved_subdetectorstartbit=25;
1020 const int reserved_subdetectorfinalbit=27;
1022 unsigned int detID =
id;
1024 int shift = 31-reserved_subdetectorfinalbit;
1025 detID = detID << (
shift);
1026 shift = reserved_subdetectorstartbit +
shift;
1027 detID = detID>>(
shift);
1035 const int reserved_layerstartbit=14;
1036 const int reserved_layermask=0x7;
1038 return int((
id>>reserved_layerstartbit) & reserved_layermask);
1044 Double_t
xmin = 10000;
1045 Double_t
xmax = -10000;
1048 for (
int i = 1;
i <=
h->GetNbinsX(); ++
i) {
1049 if ((
h->GetBinContent(
i) > 0)&&(
h->GetBinCenter(
i)>
xmax))
xmax =
h->GetBinCenter(
i);
1051 for (
int i =
h->GetNbinsX();
i >= 1; --
i) {
1052 if ((
h->GetBinContent(
i) > 0)&&(
h->GetBinCenter(
i)<
xmin))
xmin =
h->GetBinCenter(
i);
1063 cout <<
"Starting plotHitMap" << flush;
1066 cout <<
"\tLoaded file" << flush;
1068 TTree* talignable=(TTree*)falignable->Get(
"T2");
1069 cout <<
"\t Loaded tree" << endl;
1071 float eta=-999.0,
phi=-55.0, xpos=-999.0, ypos=+999.0, zpos=-11111.0;
1074 talignable->SetBranchAddress(
"Id", &
id);
1075 talignable->SetBranchAddress(
"Layer", &
layer);
1076 talignable->SetBranchAddress(
"Type", &
type);
1077 talignable->SetBranchAddress(
"Nhit", &nhit);
1078 talignable->SetBranchAddress(
"Ypos", &ypos);
1079 talignable->SetBranchAddress(
"Eta", &
eta);
1080 talignable->SetBranchAddress(
"Phi", &
phi);
1081 talignable->SetBranchAddress(
"Ypos", &ypos);
1082 talignable->SetBranchAddress(
"Xpos", &xpos);
1083 talignable->SetBranchAddress(
"Zpos", &zpos);
1089 else if (subDet ==
TPEid){ sprintf(typetag,
"TPE");
maxLayers=2; }
1090 else if (subDet ==
TIBid){ sprintf(typetag,
"TIB");
maxLayers=4; }
1091 else if (subDet ==
TIDid){ sprintf(typetag,
"TID");
maxLayers=3; }
1092 else if (subDet ==
TOBid){ sprintf(typetag,
"TOB");
maxLayers=6; }
1093 else if (subDet ==
TECid){ sprintf(typetag,
"TEC");
maxLayers=9; }
1094 else { sprintf(typetag,
"UNKNOWN"); }
1095 cout <<
"Starting to plot Hit Distributions for " << typetag << endl;
1097 bool printbinning=
true;
1100 sprintf(psname,
"%s/Hits_%s_Layers_Skimmed.eps",
outpath, typetag);
1102 char binfilename[64];
1103 sprintf(binfilename,
"./BinningHitMaps_%s.txt", typetag);
1104 ofstream binfile(binfilename,
ios::out);
1107 binfile <<
"******** Binning for Subdet " << typetag <<
"* ********" << endl << endl;
1110 for (
int layerindex=1; layerindex<=
maxLayers; layerindex++){
1112 cout <<
"\n\n*** Layer # " << layerindex <<
"* **" << endl;
1114 talignable->SetBranchStatus(
"*", 0);
1115 talignable->SetBranchStatus(
"Id", 1);
1116 talignable->SetBranchStatus(
"Type", 1);
1117 talignable->SetBranchStatus(
"Layer", 1);
1118 talignable->SetBranchStatus(
"Nhit", 1);
1119 talignable->SetBranchStatus(
"Eta", 1);
1120 talignable->SetBranchStatus(
"Phi", 1);
1121 talignable->SetBranchStatus(
"Ypos", 1);
1122 talignable->SetBranchStatus(
"Zpos", 1);
1123 talignable->SetBranchStatus(
"Xpos", 1);
1125 TCut selA, selECpos, selECneg;
1126 char selA_str[196], selECneg_str[196], selECpos_str[196];
1127 char varA_str[64], varB_str[64];
1128 char commonsense_str[128]=
"Xpos>-150.0&&Xpos<150.0&&Ypos>-150.0&&Ypos<150.0&&Zpos>-400.0&&Zpos<400.0";
1129 TCut commonsense=commonsense_str;
1131 sprintf(selECneg_str,
"(Type==%d && Layer==%d && Zpos<0.0 && Nhit>=%d && sqrt(pow(Xpos,2)+pow(Ypos,2) )<125.0 )", subDet, layerindex,
minHits);
1132 sprintf(selECpos_str,
"(Type==%d && Layer==%d && Zpos>=0.0 && Nhit>=%d && sqrt(pow(Xpos,2)+pow(Ypos,2) )<125.0 )", subDet, layerindex,
minHits);
1134 sprintf(selA_str,
"Type==%d && Layer==%d", subDet, layerindex);
1136 sprintf(varA_str,
"Eta>>hvarx");
1137 sprintf(varB_str,
"Phi>>hvary");
1139 selECneg=selECneg_str;
1140 selECpos=selECpos_str;
1142 cout <<
"Cuts defined as " << selA << endl;
1151 int nzentries= talignable->Draw(
"Zpos>>hZ(360,-270.0,270.0)", commonsense&&selA,
"goff");
1152 TH1F* hZ=(TH1F*)gDirectory->Get(
"hZ");
1160 const int nZpeaks=
FindPeaks(hZ, Zpeaks, 99);
1161 const int nZbinlims=nZpeaks+1;
1162 float Zwidth=(Zpeaks[nZpeaks-1]-Zpeaks[0])/ (nZpeaks-1);
1163 float Zmin=Zpeaks[0]- Zwidth/2.0;
1164 float Zmax=Zpeaks[nZpeaks-1] + Zwidth/2.0;
1165 cout <<
"--> Zmin= " <<
Zmin <<
" - Zmax= " <<
Zmax <<
" Zwidth= " << Zwidth <<
" ; found " << nZpeaks <<
" Zpeaks" << endl;
1166 cout <<
"Zpeaks[0] is " << Zpeaks[0] << endl;
1169 float Phipeaks[120];
1170 if ((subDet==
TIBid||subDet==
TOBid)&&layerindex<=2) sprintf(selA_str,
"%s&&Zpos>%f&&Zpos<%f", selA_str, Zpeaks[0]-2.0, Zpeaks[0]+2.0);
1171 else sprintf(selA_str,
"%s&&Zpos>%f&&Zpos<%f", selA_str, Zpeaks[0]-2.0, Zpeaks[0]+2.0);
1172 int nphientries=talignable->Draw(
"Phi>>hPhi", selA_str,
"goff");
1173 cout <<
"N phi entries " << nphientries <<
" from sel " << selA_str << endl;
1174 TH1F* hPhi=(TH1F*)gDirectory->Get(
"hPhi");
1176 if (subDet==
TPBid&&layerindex==1)nphientries=nphientries-1;
1177 const int nPhibins=nphientries;
1178 cout <<
"+ It would have found " << nPhibins <<
" phi bins" << endl;
1181 float phibin[nPhibins+1];
1182 float zbin[nZbinlims];
1183 float Phiwidth=6.28/nPhibins;
1185 if ((subDet==
TIBid||subDet==
TOBid)&&layerindex<=2){
1188 cout <<
"Gonna loop over " << nZpeaks <<
" peaks / " << nZbinlims <<
" bin limits" << endl;
1194 zup=(Zpeaks[
bin+1]-Zpeaks[
bin])/2.0;
1197 else if (
bin==nZbinlims-2){
1198 cout <<
"Don't go overflow !" << endl;
1199 zdown=(Zpeaks[
bin]-Zpeaks[
bin-1])/2.0;
1200 if (layerindex==1) zup=(Zpeaks[
bin-1]-Zpeaks[
bin-2])/2.0;
1204 zup=(Zpeaks[
bin+1]-Zpeaks[
bin])/2.0;
1205 zdown=(Zpeaks[
bin]-Zpeaks[
bin-1])/2.0;
1207 zbin[
bin] = Zpeaks[
bin]-zdown;
1208 zbin[
bin+1]= Zpeaks[
bin]+zup;
1215 if (
bin==0)phibin[
bin]=-3.14+
bin*(Phiwidth)+Phiwidth/4;
1216 else if (
bin==nPhibins-1)phibin[
bin]=-3.14+
bin*(Phiwidth)-Phiwidth/4;
1218 else phibin[
bin]=phibin[
bin-1]+ Phiwidth;
1228 phibin[
bin]=-3.14+
bin*(Phiwidth);
1233 float Phimin=Phipeaks[0]- ((Phipeaks[1]-Phipeaks[0])/2.0);
1234 float Phimax=Phipeaks[nPhibins-1] + ((Phipeaks[nPhibins-1]-Phipeaks[nPhibins-2])/2.0);
1236 cout <<
"N Z bin LIMITs = " << nZbinlims <<
" N Phi bin LIMITS = " << nPhibins << endl;
1242 sprintf(histoname,
"%s_Layer%d", typetag, layerindex);
1243 TH2F* hetaphi=
new TH2F(histoname, histoname, nZpeaks, zbin, nPhibins, phibin);
1246 cout <<
"Starting to loop on entries" << flush;
1248 int nlowentrycells=0;
1250 for (
int j=0;
j<talignable->GetEntries();
j++){
1251 if (
j%1000==0)
cout <<
"." << flush;
1252 talignable->GetEntry(
j);
1256 hetaphi->Fill(zpos,
phi, nhit);
1260 hetaphi->Fill(zpos,
phi, -99);
1268 hetaphi->SetXTitle(
"Z [cm]");
1269 hetaphi->SetYTitle(
"#phi (rad)");
1271 int Nxbins=hetaphi->GetXaxis()->GetNbins();
1272 int Nybins=hetaphi->GetYaxis()->GetNbins();
1273 cout <<
"On x-axis there are " <<
Nxbins <<
" bins " << endl;
1274 cout <<
"On y-axis there are " <<
Nybins <<
" bins " << endl;
1277 bool smooth_etaphi=
false;
1281 float bincont=hetaphi->GetBinContent(
i,
j);
1283 float binup1=hetaphi->GetBinContent(
i,
j+1);
1284 float bindown1=hetaphi->GetBinContent(
i,
j-1);
1285 float binlx1=hetaphi->GetBinContent(
i-1,
j);
1286 float binrx1=hetaphi->GetBinContent(
i+1,
j);
1287 if (
i==1)binlx1=binrx1;
1289 if (
j==1)bindown1=binup1;
1290 if (
j==
Nybins)binup1=bindown1;
1292 if (binup1>0.0)adiacentbins++;
1293 if (bindown1>0.0)adiacentbins++;
1294 if (binlx1>0.0)adiacentbins++;
1295 if (binrx1>0.0)adiacentbins++;
1296 if (adiacentbins>=2){
1297 float avg=(binup1+bindown1+binlx1+binrx1)/adiacentbins;
1298 hetaphi->SetBinContent(
i,
j, avg);
1308 bool plotAlignablePos=
false;
1309 if (plotAlignablePos){
1310 const int ngrpoints=nmods;
1311 float etagr[ngrpoints], phigr[ngrpoints];
1313 for (
int j=0;
j<talignable->GetEntries();
j++){
1314 if (
j%1000==0)
cout <<
"." << flush;
1315 talignable->GetEntry(
j);
1323 gretaphi=
new TGraph(ngrpoints, etagr, phigr);
1324 gretaphi->SetMarkerStyle(20);
1325 gretaphi->SetMarkerColor(1);
1326 gretaphi->SetMarkerSize(0.75);
1334 float Phicellgr[512];
1336 for (
int zcells=1; zcells<=hetaphi->GetNbinsX(); zcells++){
1337 for (
int phicells=1; phicells<=hetaphi->GetNbinsY(); phicells++){
1338 if (hetaphi->GetBinContent(zcells, phicells)==-99){
1339 hetaphi->SetBinContent(zcells, phicells, 0);
1340 Zcellgr[nemptycells]=
float(hetaphi->GetXaxis()->GetBinCenter(zcells));
1341 Phicellgr[nemptycells]=
float(hetaphi->GetYaxis()->GetBinCenter(phicells));
1347 TGraph* gr_empty=
new TGraph(nlowentrycells, Zcellgr, Phicellgr);
1348 sprintf(histoname,
"gr_emptycells_subdet%d_layer%d", subDet, layerindex);
1350 gr_empty->SetName(histoname);
1351 gr_empty->SetMarkerStyle(5);
1355 cout <<
" Done! Used " << nmods <<
" alignables. Starting to plot !" << endl;
1358 gStyle->SetPalette(1, 0);
1359 TCanvas* c_barrels=
new TCanvas(
"canvas_hits_barrels",
"CANVAS_HITS_BARRELS", 1600, 1600);
1360 TCanvas* c_endcaps=
new TCanvas(
"canvas_hits_endcaps",
"CANVAS_HITS_ENDCAPS", 3200, 1600);
1361 TPad* pleft=
new TPad(
"left_panel",
"Left Panel", 0.0, 0.0, 0.49, 0.99);
1362 TPad* pcent=
new TPad(
"central_up_panel",
"Central Panel", 0.01, 0.00, 0.99, 0.99);
1363 TPad* pright=
new TPad(
"right_panel",
"Right Panel", 0.51, 0.0, 0.99, 0.99);
1366 if (subDet==1 ||subDet==3 ||subDet==5){
1370 gPad->SetRightMargin(0.15);
1374 hetaphi->SetStats(0);
1375 if (subDet==
TPBid||subDet==
TIBid||subDet==
TOBid)hetaphi->Draw(
"COLZtext");
1376 if (plotAlignablePos) gretaphi->Draw(
"P");
1377 gr_empty->Draw(
"P");
1380 binfile <<
"--> Layer #" << layerindex << endl;
1381 binfile <<
"Eta Binning: " << flush;
1382 for (
int h=1;
h<=hetaphi->GetNbinsX();
h++){
1383 binfile << hetaphi->GetXaxis()->GetBinLowEdge(
h) <<
"\t";
1384 if (
h==hetaphi->GetNbinsX()) binfile << hetaphi->GetXaxis()->GetBinLowEdge(
h)+hetaphi->GetXaxis()->GetBinWidth(
h);
1387 binfile <<
"Phi Binning: " << flush;
1388 for (
int h=1;
h<=hetaphi->GetNbinsY();
h++){
1389 binfile << hetaphi->GetYaxis()->GetBinLowEdge(
h) <<
"\t";
1390 if (
h==hetaphi->GetNbinsX()) binfile << hetaphi->GetYaxis()->GetBinLowEdge(
h)+hetaphi->GetYaxis()->GetBinWidth(
h);
1403 gPad->SetRightMargin(0.15);
1404 char selEC_str[192], varEC_str[128];
1406 if (subDet ==
TPBid){ radlimit=45.0; }
1407 else if (subDet ==
TPEid){ radlimit=45.0; }
1408 else if (subDet ==
TIBid){ radlimit=70.0; }
1409 else if (subDet ==
TIDid){ radlimit=70.0; }
1410 else if (subDet ==
TOBid){ radlimit=130.0; }
1411 else if (subDet ==
TECid){ radlimit=130.0; }
1412 else { radlimit=0.0; }
1414 sprintf(varEC_str,
"Ypos:Xpos>>hxy_negz(30,%f,%f)", -radlimit, radlimit);
1415 sprintf(selEC_str,
"Nhit*(%s&&%s)", selECneg_str, commonsense_str);
1416 cout << selEC_str << endl;
1417 int selentriesECneg=talignable->Draw(varEC_str, selEC_str,
"goff");
1418 if (selentriesECneg>0){
1419 TH2F* hxy_negz=(TH2F*)gDirectory->Get(
"hxy_negz");
1420 hxy_negz->GetXaxis()->SetRangeUser(-radlimit, radlimit);
1421 hxy_negz->GetYaxis()->SetRangeUser(-radlimit, radlimit);
1422 char histoname_negz[32];
1423 sprintf(histoname_negz,
"%s (-Z)", histoname);
1424 hxy_negz->SetStats(0);
1425 hxy_negz->SetTitle(histoname_negz);
1426 hxy_negz->SetXTitle(
"X (cm)");
1427 hxy_negz->SetYTitle(
"Y (cm)");
1428 hxy_negz->Draw(
"COLZ");
1431 cout <<
"WARNING !!!! No hits on this layer ! not plotting (-Z) !" << endl;
1436 cout <<
"PAD 3" << endl;
1438 gPad->SetRightMargin(0.15);
1439 sprintf(selEC_str,
"Nhit*(%s&&%s)", selECpos_str, commonsense_str);
1441 cout <<
"(2)" << selEC_str << endl;
1442 sprintf(varEC_str,
"Ypos:Xpos>>hxy_posz(30,%f,%f)", -radlimit, radlimit);
1443 int selentriesECpos=talignable->Draw(varEC_str, selEC_str,
"goff");
1444 if (selentriesECpos>0){
1445 TH2F* hxy_posz=(TH2F*)gDirectory->Get(
"hxy_posz");
1446 char histoname_posz[32];
1447 hxy_posz->GetXaxis()->SetRangeUser(-radlimit, radlimit);
1448 hxy_posz->GetYaxis()->SetRangeUser(-radlimit, radlimit);
1449 sprintf(histoname_posz,
"%s (+Z)", histoname);
1450 hxy_posz->SetStats(0);
1451 hxy_posz->SetTitle(histoname_posz);
1452 hxy_posz->SetXTitle(
"X (cm)");
1453 hxy_posz->SetYTitle(
"Y (cm)");
1454 hxy_posz->Draw(
"COLZ");
1457 cout <<
"WARNING !!!! No hits on this layer ! not plotting (+Z) !" << endl;
1464 cout <<
"******* " << typetag << endl;
1465 char psnamefinal[600];
1467 if (layerindex==1) sprintf(psnamefinal,
"%s(", psname);
1468 else if (layerindex==
maxLayers) sprintf(psnamefinal,
"%s)", psname);
1469 else sprintf(psnamefinal,
"%s", psname);
1471 cout <<
"Saving in " << psnamefinal << endl;
1472 if (subDet==1 ||subDet==3 ||subDet==5)c_barrels->SaveAs(psnamefinal);
1473 else c_endcaps->SaveAs(psnamefinal);
1475 if (subDet==1 ||subDet==3 ||subDet==5)
delete c_barrels;
1476 else delete c_endcaps;
1483 cout <<
"Finished " <<
maxLayers <<
" of the " << typetag << endl;
1501 if (startbin<0)startbin=1;
1502 if (endbin<0)endbin=h1->GetNbinsX();
1504 int prevbin=startbin;
1506 while (
bin<=endbin){
1508 float bincont=h1->GetBinContent(
bin);
1509 float prevbincont=h1->GetBinContent(prevbin);
1512 if (bincont>=prevbincont){
1521 peaklist[Npeaks]=h1->GetBinCenter(prevbin);
1526 if (Npeaks>=maxNpeaks){
1569 cout <<
"Output file already exists!" << endl;
1578 bool rise1=
false, rise2=
false, rise3=
false;
1579 int totbins=
h->GetNbinsX();
1584 for (
i=1;
i<=totbins-3;
i++){
1585 double cont1 =
h->GetBinContent(
i);
1586 if (
h->GetBinContent(
i+1)>cont1)rise1=
true;
1588 if (
h->GetBinContent(
i+2)>
h->GetBinContent(
i+1))rise2=
true;
1590 if (
h->GetBinContent(
i+3)>
h->GetBinContent(
i+2)){