Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plot module residuals #23723

Merged
merged 5 commits into from Jul 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
102 changes: 102 additions & 0 deletions Alignment/OfflineValidation/macros/PlotAlignmentValidation.C
Expand Up @@ -1923,3 +1923,105 @@ return 2*(1-ROOT::Math::tdistribution_cdf(abs(t),v));
}

const TString PlotAlignmentValidation::summaryfilename = "OfflineValidationSummary.txt";



vector <TH1*> PlotAlignmentValidation::findmodule (TFile* f, unsigned int moduleid){


//TFile *f = TFile::Open(filename, "READ");
TString histnamex;
TString histnamey;
//read necessary branch/folder
auto t = (TTree*)f->Get("TrackerOfflineValidationStandalone/TkOffVal");

TkOffTreeVariables *variables=0;
t->SetBranchAddress("TkOffTreeVariables", &variables);
unsigned int number_of_entries=t->GetEntries();
for (int i=0;i<number_of_entries;i++){
t->GetEntry(i);
if (variables->moduleId==moduleid){
histnamex=variables->histNameX;
histnamey=variables->histNameY;
break;
}
}

vector <TH1*> h;

auto h1 = (TH1*)f->FindObjectAny(histnamex);
auto h2 = (TH1*)f->FindObjectAny(histnamey);

h1->SetDirectory(0);
h2->SetDirectory(0);

h.push_back(h1);
h.push_back(h2);

return h;
}

void PlotAlignmentValidation::residual_by_moduleID( unsigned int moduleid){
TCanvas *cx = new TCanvas("x_residual");
TCanvas *cy = new TCanvas("y_residual");
TLegend *legendx =new TLegend(0.55, 0.7, 1, 0.9);
TLegend *legendy =new TLegend(0.55, 0.7, 1, 0.9);

legendx->SetTextSize(0.016);
legendx->SetTextAlign(12);
legendy->SetTextSize(0.016);
legendy->SetTextAlign(12);




for (auto it : sourceList) {
TFile* file = it->getFile();
int color = it->getLineColor();
int linestyle = it->getLineStyle(); //this you set by doing h->SetLineStyle(linestyle)
TString legendname = it->getName(); //this goes in the legend
vector<TH1*> hist = findmodule(file, moduleid);

TString histnamex = legendname+" NEntries: "+to_string(int(hist[0]->GetEntries()));
hist[0]->SetTitle(histnamex);
hist[0]->SetStats(0);
hist[0]->Rebin(50);
hist[0]->SetBit(TH1::kNoTitle);
hist[0]->SetLineColor(color);
hist[0]->SetLineStyle(linestyle);
cx->cd();
hist[0]->Draw("Same");
legendx->AddEntry(hist[0], histnamex, "l");


TString histnamey = legendname+" NEntries: "+to_string(int(hist[1]->GetEntries()));
hist[1]->SetTitle(histnamey);
hist[1]->SetStats(0);
hist[1]->Rebin(50);
hist[1]->SetBit(TH1::kNoTitle);
hist[1]->SetLineColor(color);
hist[1]->SetLineStyle(linestyle);
cy->cd();
hist[1]->Draw("Same");
legendy->AddEntry(hist[1], histnamey, "l");

}

TString filenamex = "x_residual_"+to_string(moduleid);
TString filenamey = "y_residual_"+to_string(moduleid);
cx->cd();
legendx->Draw();
cx->SaveAs(outputDir + "/" +filenamex+".root");
cx->SaveAs(outputDir + "/" +filenamex+".pdf");
cx->SaveAs(outputDir + "/" +filenamex+".png");
cx->SaveAs(outputDir + "/" +filenamex+".eps");

cy->cd();
legendy->Draw();
cy->SaveAs(outputDir + "/" +filenamey+".root");
cy->SaveAs(outputDir + "/" +filenamey+".pdf");
cy->SaveAs(outputDir + "/" +filenamey+".png");
cy->SaveAs(outputDir + "/" +filenamey+".eps");


}
3 changes: 3 additions & 0 deletions Alignment/OfflineValidation/macros/PlotAlignmentValidation.h
Expand Up @@ -99,6 +99,7 @@ class PlotAlignmentValidation {
void plotHitMaps();
void setOutputDir( std::string dir );
void setTreeBaseDir( std::string dir = "TrackerOfflineValidationStandalone");
void residual_by_moduleID(unsigned int moduleid);
int numberOfLayers(int phase, int subdetector);
int maxNumberOfLayers(int subdetector);

Expand Down Expand Up @@ -175,6 +176,8 @@ private :
void plotDMRHistogram(DMRPlotInfo& plotinfo, int direction = 0, int layer = 0);
void modifySSHistAndLegend(THStack* hs, TLegend* legend);
void openSummaryFile();
vector <TH1*> findmodule (TFile* f, unsigned int moduleid);

};

#endif // PLOTALIGNNMENTVALIDATION_H_
Expand Up @@ -109,5 +109,9 @@
p.plotDMR(".oO[DMRMethod]Oo.",.oO[DMRMinimum]Oo.,".oO[DMROptions]Oo.");
p.plotSurfaceShapes(".oO[SurfaceShapes]Oo.");
p.plotChi2("root://eoscms//eos/cms/store/caf/user/$USER/.oO[eosdir]Oo./.oO[validationId]Oo._result.root");
vector<int> moduleids = {.oO[moduleid]Oo.};
for (auto moduleid : moduleids) {
p.residual_by_moduleID(moduleid);
}
}
"""
Expand Up @@ -184,7 +184,7 @@ class PlottingOptionsOffline(BasePlottingOptions):
"SurfaceShapes":"coarse",
"bigtext":"false",
"mergeOfflineParJobsScriptPath": ".oO[scriptsdir]Oo./TkAlOfflineJobsMerge.C",
"usefit": "false",
"usefit": "false","moduleid": ""
}
validationclass = OfflineValidation
def __init__(self, config):
Expand Down
16 changes: 8 additions & 8 deletions Alignment/OfflineValidation/scripts/validateAlignments.py
Expand Up @@ -41,7 +41,7 @@


####################--- Classes ---############################
class ParallelMergeJob:
class ParallelMergeJob(object):

def __init__(self, _name, _path, _dependency):
self.name=_name
Expand All @@ -68,7 +68,7 @@ def runJob(self, config):
"-w %(conditions)s "
"%(script)s"%repMap)

class ValidationJob:
class ValidationJob(object):

# these count the jobs of different varieties that are being run
crabCount = 0
Expand Down Expand Up @@ -131,18 +131,18 @@ def __getValidation( self, valType, name, alignments, config, options ):
if len( firstAlignList ) > 1:
firstRun = firstAlignList[1]
else:
firstRun = "1"
raise AllInOneError("Have to provide a run number for geometry comparison")
firstAlign = Alignment( firstAlignName, self.__config, firstRun )
firstAlignName = firstAlign.name
secondAlignList = alignmentsList[1].split()
secondAlignName = secondAlignList[0].strip()
if len( secondAlignList ) > 1:
secondRun = secondAlignList[1]
else:
secondRun = "1"
if secondAlignName == "IDEAL":
secondAlign = secondAlignName
else:
if len( secondAlignList ) > 1:
secondRun = secondAlignList[1]
else:
raise AllInOneError("Have to provide a run number for geometry comparison")
secondAlign = Alignment( secondAlignName, self.__config,
secondRun )
secondAlignName = secondAlign.name
Expand Down Expand Up @@ -372,7 +372,7 @@ def createMergeScript( path, validations, options ):
repMapTemp["RunValidationPlots"] = validationType.doRunPlots(validations)

#create script file
fileName="TkAlMerge"+validation.alignmentToValidate.name
fileName="TkAlMergeOfflineValidation"+validation.name+validation.alignmentToValidate.name
filePath = os.path.join(path, fileName+".sh")
theFile = open( filePath, "w" )
theFile.write( replaceByMap( configTemplates.mergeParallelOfflineTemplate, repMapTemp ) )
Expand Down