diff --git a/Alignment/OfflineValidation/macros/PlotAlignmentValidation.C b/Alignment/OfflineValidation/macros/PlotAlignmentValidation.C index 03e46293b5087..3704a7e2703c1 100644 --- a/Alignment/OfflineValidation/macros/PlotAlignmentValidation.C +++ b/Alignment/OfflineValidation/macros/PlotAlignmentValidation.C @@ -830,7 +830,7 @@ void PlotAlignmentValidation::plotChi2(const char *inputFile) TGaxis::SetMaxDigits(3); Bool_t errorflag = kTRUE; - TFile* fi1 = new TFile(inputFile,"read"); + TFile* fi1 = TFile::Open(inputFile,"read"); TDirectoryFile* mta1 = NULL; TDirectoryFile* mtb1 = NULL; TCanvas* normchi = NULL; diff --git a/Alignment/OfflineValidation/macros/trackSplitPlot.C b/Alignment/OfflineValidation/macros/trackSplitPlot.C index 9b6dfa9028f33..f481d83568083 100644 --- a/Alignment/OfflineValidation/macros/trackSplitPlot.C +++ b/Alignment/OfflineValidation/macros/trackSplitPlot.C @@ -34,7 +34,7 @@ TCanvas *trackSplitPlot(Int_t nFiles,TString *files,TString *names,TString xvar, if (nFiles < 1) nFiles = 1; const Int_t n = nFiles; - + setTDRStyle(); gStyle->SetOptStat(0); //for histograms, the mean and rms are included in the legend if nFiles >= 2 //if nFiles == 1, there is no legend, so they're in the statbox @@ -212,7 +212,7 @@ TCanvas *trackSplitPlot(Int_t nFiles,TString *files,TString *names,TString xvar, } if (relative && pull) tree->SetBranchAddress(sigmaorgvariable,&sigmaorg); - + Int_t notincluded = 0; //this counts the number that aren't in the right run range. //it's subtracted from lengths[i] in order to normalize the histograms @@ -273,14 +273,14 @@ TCanvas *trackSplitPlot(Int_t nFiles,TString *files,TString *names,TString xvar, } } - if (lengths[i] < 10 ? true : + if (lengths[i] < 10 ? true : (((j+1)/(int)(pow(10,(int)(log10(lengths[i]))-1)))*(int)(pow(10,(int)(log10(lengths[i]))-1)) == j + 1 || j + 1 == lengths[i])) //print when j+1 is a multiple of 10^x, where 10^x has 1 less digit than lengths[i] // and when it's finished //For example, if lengths[i] = 123456, it will print this when j+1 = 10000, 20000, ..., 120000, 123456 //So it will print between 10 and 100 times: 10 when lengths[i] = 10^x and 100 when lengths[i] = 10^x - 1 { - cout << j + 1 << "/" << lengths[i] << ": "; + cout << j + 1 << "/" << lengths[i] << ": "; if (type == Profile || type == ScatterPlot || type == Resolution) cout << x << ", " << y << endl; if (type == OrgHistogram) @@ -466,7 +466,7 @@ TCanvas *trackSplitPlot(Int_t nFiles,TString *files,TString *names,TString xvar, return 0; } - + c1->Update(); Double_t x1min = .98*gPad->GetUxmin() + .02*gPad->GetUxmax(); Double_t x2max = .02*gPad->GetUxmin() + .98*gPad->GetUxmax(); @@ -482,7 +482,7 @@ TCanvas *trackSplitPlot(Int_t nFiles,TString *files,TString *names,TString xvar, } Double_t newy2max = placeLegend(legend,width,height,x1min,y1min,x2max,y2max); maxp->GetYaxis()->SetRangeUser(gPad->GetUymin(),(newy2max-.02*gPad->GetUymin())/.98); - + legend->SetFillStyle(0); legend->Draw(); } @@ -556,23 +556,15 @@ void saveplot(TCanvas *c1,TString saveas) if (saveas == "") return; TString saveas2 = saveas, - saveas3 = saveas, - saveas4; + saveas3 = saveas; saveas2.ReplaceAll(".pngepsroot",""); saveas3.Remove(saveas3.Length()-11); if (saveas2 == saveas3) { - stringstream s1,s2,s3; - s1 << saveas2 << ".png"; - s2 << saveas2 << ".eps"; - s3 << saveas2 << ".root"; - saveas2 = s1.str(); - saveas3 = s2.str(); - saveas4 = s3.str(); - c1->SaveAs(saveas2); - c1->SaveAs(saveas3); - c1->SaveAs(saveas4); - return; + c1->SaveAs(saveas.ReplaceAll(".pngepsroot",".png")); + c1->SaveAs(saveas.ReplaceAll(".png",".eps")); + c1->SaveAs(saveas.ReplaceAll(".eps",".root")); + c1->SaveAs(saveas.ReplaceAll(".root",".pdf")); } else { @@ -704,7 +696,7 @@ void misalignmentDependence(TCanvas *c1old, { yaxislabel = axislabel(yvar,'y',relative,resolution,pull); for (Int_t i = 0; i < nFiles; i++) - { + { if (!used[i]) continue; if (!resolution) { @@ -865,7 +857,7 @@ void misalignmentDependence(TCanvas *c1old, stufftodelete->Add(g); delete[] xvalues; //A TGraph2DErrors has its own copy of xvalues and yvalues, so it's ok to delete these copies. delete[] yvalues; - + TString xaxislabel = "#epsilon_{"; xaxislabel.Append(misalignment); xaxislabel.Append("}cos(#delta)"); @@ -1127,7 +1119,7 @@ Bool_t misalignmentDependence(TCanvas *c1old, functionname = "#Deltad_{xy}/#delta(#Deltad_{xy})=-Asin(2#phi_{org}+B)"; //functionname = "#Deltad_{xy}/#delta(#Deltad_{xy})=-Asin(2#phi_{org}+B)+C"; } - + if (xvar == "theta" && yvar == "dz" && !resolution && !pull) { f = new TF1("line","-[0]*(x-[1])"); @@ -1280,7 +1272,7 @@ Bool_t misalignmentDependence(TCanvas *c1old, f,parameter,parametername,functionname,relative,resolution,pull,saveas); delete f; return true; - + } @@ -1426,7 +1418,7 @@ void makePlots(Int_t nFiles,TString *files,TString *names,TString misalignment,D for (Int_t i = 0; i < nPlots; i++) { stringstream ss; - ss << directory << slashstring << plotnames[i] << "." << pullstring + ss << directory << slashstring << plotnames[i] << "." << pullstring << xvarstring << yvarstring << relativestring << ".pngepsroot"; s.push_back(ss.str()); if (misalignment != "") @@ -1745,17 +1737,33 @@ TString axislabel(TString variable, Char_t axis, Bool_t relative, Bool_t resolut s << "#Delta"; s << fancyname(variable); if (relative && axis == 'y') - s << " / " << fancyname(variable); + { + s << " / "; + if (!pull) + s << "("; + s << fancyname(variable); + } Bool_t nHits = (variable[0] == 'n' && variable[1] == 'H' && variable[2] == 'i' && variable[3] == 't' && variable[4] == 's'); if (relative || (axis == 'x' && variable != "runNumber" && !nHits)) s << "_{org}"; - if (pull && axis == 'y') + if (axis == 'y') { - s << " / #delta(#Delta" << fancyname(variable); - if (relative) - s << " / " << fancyname(variable) << "_{org}"; - s << ")"; + if (pull) + { + s << " / #delta(#Delta" << fancyname(variable); + if (relative) + s << " / " << fancyname(variable) << "_{org}"; + s << ")"; + } + else + { + if (!relative) + s << " / "; + s << "#sqrt{2}"; + if (relative) + s << ")"; + } } if (resolution && axis == 'y') s << ")"; @@ -2276,7 +2284,7 @@ void setTDRStyle() { gStyle->SetEndErrorSize(2); //gStyle->SetErrorMarker(20); gStyle->SetErrorX(0.); - + gStyle->SetMarkerStyle(7); //For the fit/function: @@ -2364,7 +2372,7 @@ void setTDRStyle() { gStyle->SetOptLogz(0); // Postscript options: - + gStyle->SetPaperSize(20.,20.); // gStyle->SetLineScalePS(Float_t scale = 3); // gStyle->SetLineStyleString(Int_t i, const char* text); diff --git a/Alignment/OfflineValidation/python/TkAlAllInOneTool/betterConfigParser.py b/Alignment/OfflineValidation/python/TkAlAllInOneTool/betterConfigParser.py index 86e2eaad2cd76..c03051a55dc45 100644 --- a/Alignment/OfflineValidation/python/TkAlAllInOneTool/betterConfigParser.py +++ b/Alignment/OfflineValidation/python/TkAlAllInOneTool/betterConfigParser.py @@ -1,31 +1,29 @@ import ConfigParser import os +import re import copy +import collections from TkAlExceptions import AllInOneError -class AdaptedDict(dict): +class AdaptedDict(collections.OrderedDict): """ Dictionary which handles updates of values for already existing keys in a modified way. - Instead of replacing the old value, the new value is appended to the - value string separated by `self.getSep()`. + adapteddict[key] returns a list of all values associated with key This dictionary is used in the class `BetterConfigParser` instead of the default `dict_type` of the `ConfigParser` class. """ - def getSep(self): - """ - This method returns the separator used to separate the values for - duplicate options in a config. - """ - return " |/| " + def __init__(self, *args, **kwargs): + self.validationslist = [] + collections.OrderedDict.__init__(self, *args, **kwargs) - def __setitem__(self, key, value, dict_setitem=dict.__setitem__): + def __setitem__(self, key, value, dict_setitem=collections.OrderedDict.__setitem__): """ od.__setitem__(i, y) <==> od[i]=y Updating an existing key appends the new value to the old value - separated by `self.getSep()` instead of replacing it. + instead of replacing it. Arguments: - `key`: key part of the key-value pair @@ -33,23 +31,32 @@ def __setitem__(self, key, value, dict_setitem=dict.__setitem__): - `dict_item`: method which is used for finally setting the item """ - if "__name__" in self and self["__name__"]=="validation" \ - and key in self and value!=self[key][0]: - the_value = [self[key][0]+self.getSep()+value[0]] + if key != "__name__" and "__name__" in self and self["__name__"]=="validation": + if isinstance(value, (str, unicode)): + for index, item in enumerate(self.validationslist[:]): + if item == (key, value.split("\n")): + self.validationslist[index] = (key, value) + return + self.validationslist.append((key, value)) else: - the_value = value - dict_setitem(self, key, the_value) + dict_setitem(self, key, value) + def __getitem__(self, key): + if key != "__name__" and "__name__" in self and self["__name__"]=="validation": + return [validation[1] for validation in self.validationslist if validation[0] == key] + else: + return collections.OrderedDict.__getitem__(self, key) + + def items(self): + if "__name__" in self and self["__name__"]=="validation": + return self.validationslist + else: + return collections.OrderedDict.items(self) class BetterConfigParser(ConfigParser.ConfigParser): def __init__(self): ConfigParser.ConfigParser.__init__(self,dict_type=AdaptedDict) - dummyDict = AdaptedDict() - self._sep = dummyDict.getSep() - del dummyDict - - def getSep(self): - return self._sep + self._optcre = self.OPTCRE_VALIDATION def optionxform(self, optionstr): return optionstr @@ -172,3 +179,39 @@ def checkInput(self, section, knownSimpleOptions=[], knownKeywords=[], %(option, section)) raise AllInOneError(msg) + def items(self, section, raw=False, vars=None): + if section == "validation": + if raw or vars: + raise NotImplementedError("'raw' and 'vars' do not work for betterConfigParser.items()!") + items = self._sections["validation"].items() + return items + else: + return ConfigParser.ConfigParser.items(self, section, raw, vars) + + def write(self, fp): + """Write an .ini-format representation of the configuration state.""" + for section in self._sections: + fp.write("[%s]\n" % section) + for (key, value) in self._sections[section].items(): + if key == "__name__" or not isinstance(value, (str, unicode)): + continue + if value is not None: + key = " = ".join((key, str(value).replace('\n', '\n\t'))) + fp.write("%s\n" % (key)) + fp.write("\n") + + + #Preexisting validations in the validation section have syntax: + # preexistingoffline myoffline + #with no = or :. This regex takes care of that. + OPTCRE_VALIDATION = re.compile( + r'(?P