diff --git a/Alignment/OfflineValidation/macros/PlotAlignmentValidation.C b/Alignment/OfflineValidation/macros/PlotAlignmentValidation.C index ac26ba7ea0a88..db8e05dae9419 100644 --- a/Alignment/OfflineValidation/macros/PlotAlignmentValidation.C +++ b/Alignment/OfflineValidation/macros/PlotAlignmentValidation.C @@ -42,26 +42,23 @@ #include #include - /*! \class PlotAlignmentValidation * \brief Class PlotAlignmentValidation * Class used as the last step for Offline Track Validation tool. * The main goal of this class is creating the plots regarding DMRs and Surface Deformations for modules and substructures. */ - //------------------------------------------------------------------------------ /*! \fn PlotAlignmentValidation * \brief Constructor for the class */ -PlotAlignmentValidation::PlotAlignmentValidation(bool bigtext) : bigtext_(bigtext) -{ +PlotAlignmentValidation::PlotAlignmentValidation(bool bigtext) : bigtext_(bigtext) { setOutputDir("."); setTreeBaseDir(); sourcelist = NULL; - - moreThanOneSource=false; + + moreThanOneSource = false; useFit_ = false; // Force ROOT to use scientific notation even with smaller datasets @@ -81,8 +78,9 @@ PlotAlignmentValidation::PlotAlignmentValidation(bool bigtext) : bigtext_(bigtex /*! \fn PlotAlignmentValidation * \brief Constructor for the class. This function also retrieves the list of root files used to produce DMRs and Surface Deformations */ -PlotAlignmentValidation::PlotAlignmentValidation(const char *inputFile,std::string legendName, int lineColor, int lineStyle, bool bigtext) : PlotAlignmentValidation(bigtext) -{ +PlotAlignmentValidation::PlotAlignmentValidation( + const char* inputFile, std::string legendName, int lineColor, int lineStyle, bool bigtext) + : PlotAlignmentValidation(bigtext) { loadFileList(inputFile, legendName, lineColor, lineStyle); } @@ -90,16 +88,12 @@ PlotAlignmentValidation::PlotAlignmentValidation(const char *inputFile,std::stri /*! \fn ~PlotAlignmentValidation * \brief Default destructor */ -PlotAlignmentValidation::~PlotAlignmentValidation() -{ - - for(std::vector::iterator it = sourceList.begin(); - it != sourceList.end(); ++it){ +PlotAlignmentValidation::~PlotAlignmentValidation() { + for (std::vector::iterator it = sourceList.begin(); it != sourceList.end(); ++it) { delete (*it); } delete sourcelist; - } //------------------------------------------------------------------------------ @@ -108,23 +102,21 @@ PlotAlignmentValidation::~PlotAlignmentValidation() * \brief Create/open the root and txt summary files, where the DMR histograms and the associtated mean/sigma are stored respectively */ - -void PlotAlignmentValidation::openSummaryFile() -{ +void PlotAlignmentValidation::openSummaryFile() { if (!openedsummaryfile) { openedsummaryfile = true; - summaryfile.open(outputDir+"/"+summaryfilename+".txt"); + summaryfile.open(TString(outputDir + "/") + summaryfilename + ".txt"); //Rootfile introduced to store the DMR histograms - rootsummaryfile= new TFile(outputDir+"/"+summaryfilename+".root","RECREATE"); + rootsummaryfile = new TFile(TString(outputDir + "/") + summaryfilename + ".root", "RECREATE"); for (auto vars : sourceList) { summaryfile << "\t" << vars->getName(); } summaryfile << "\tformat={}\n"; - }else{ + } else { //Check for the rootfile to be open, and open it in case it is not already. - if (!rootsummaryfile->IsOpen()) rootsummaryfile->Open(outputDir+"/"+summaryfilename+".root","UPDATE"); - + if (!rootsummaryfile->IsOpen()) + rootsummaryfile->Open(TString(outputDir + "/") + summaryfilename + ".root", "UPDATE"); } } @@ -132,27 +124,19 @@ void PlotAlignmentValidation::openSummaryFile() /*! \fn loadFileList * \brief Add to the list of sources the rootfile associated to a particular geometry */ -void PlotAlignmentValidation::loadFileList(const char *inputFile, std::string legendName, int lineColor, int lineStyle) -{ - +void PlotAlignmentValidation::loadFileList(const char* inputFile, std::string legendName, int lineColor, int lineStyle) { if (openedsummaryfile) { std::cout << "Can't load a root file after opening the summary file!" << std::endl; assert(0); } - sourceList.push_back( new TkOfflineVariables( inputFile, treeBaseDir, legendName, lineColor, lineStyle ) ); - + sourceList.push_back(new TkOfflineVariables(inputFile, treeBaseDir, legendName, lineColor, lineStyle)); } //------------------------------------------------------------------------------ /*! \fn useFitForDMRplots * \brief Store the selected boolean in one of the private members of the class */ -void PlotAlignmentValidation::useFitForDMRplots(bool usefit) -{ - - useFit_ = usefit; - -} +void PlotAlignmentValidation::useFitForDMRplots(bool usefit) { useFit_ = usefit; } //------------------------------------------------------------------------------ /*! \fn numberOfLayers @@ -161,27 +145,42 @@ void PlotAlignmentValidation::useFitForDMRplots(bool usefit) //TODO Possible improvement: reduce the number of switches in the code by implementing a map int PlotAlignmentValidation::numberOfLayers(int phase, int subdetector) { switch (phase) { - case 0: - switch (subdetector) { - case 1: return 3; - case 2: return 2; - case 3: return 4; - case 4: return 3; - case 5: return 6; - case 6: return 9; - default: assert(false); - } - case 1: - switch (subdetector) { - case 1: return 4; - case 2: return 3; - case 3: return 4; - case 4: return 3; - case 5: return 6; - case 6: return 9; - default: assert(false); - } - default: assert(false); + case 0: + switch (subdetector) { + case 1: + return 3; + case 2: + return 2; + case 3: + return 4; + case 4: + return 3; + case 5: + return 6; + case 6: + return 9; + default: + assert(false); + } + case 1: + switch (subdetector) { + case 1: + return 4; + case 2: + return 3; + case 3: + return 4; + case 4: + return 3; + case 5: + return 6; + case 6: + return 9; + default: + assert(false); + } + default: + assert(false); } return 0; } @@ -202,16 +201,14 @@ int PlotAlignmentValidation::maxNumberOfLayers(int subdetector) { /*! \fn legendOptions * \brief Assign legend options to members of the class */ -void PlotAlignmentValidation::legendOptions(TString options) -{ - +void PlotAlignmentValidation::legendOptions(TString options) { showMean_ = false; showRMS_ = false; showMeanError_ = false; showRMSError_ = false; showModules_ = false; showUnderOverFlow_ = false; - options.ReplaceAll(" ","").ToLower(); + options.ReplaceAll(" ", "").ToLower(); if (options.Contains("mean") || options.Contains("all")) showMean_ = true; if (options.Contains("meanerror") || options.Contains("all")) @@ -232,8 +229,7 @@ void PlotAlignmentValidation::legendOptions(TString options) /*! \fn setOutputDir * \brief Set the output direcotry */ -void PlotAlignmentValidation::setOutputDir( std::string dir ) -{ +void PlotAlignmentValidation::setOutputDir(std::string dir) { if (openedsummaryfile) { std::cout << "Can't set the output dir after opening the summary file!" << std::endl; assert(0); @@ -246,64 +242,81 @@ void PlotAlignmentValidation::setOutputDir( std::string dir ) /*! \fn plotSubDetResiduals * \brief Function used to plot residuals for a subdetector */ -void PlotAlignmentValidation::plotSubDetResiduals(bool plotNormHisto,unsigned int subDetId) -{ +void PlotAlignmentValidation::plotSubDetResiduals(bool plotNormHisto, unsigned int subDetId) { gStyle->SetOptStat(11111); gStyle->SetOptFit(0000); - TCanvas *c = new TCanvas("c", "c"); + TCanvas* c = new TCanvas("c", "c"); c->SetTopMargin(0.15); - TString histoName= ""; - if (plotNormHisto) {histoName= "h_NormXprime";} - else histoName= "h_Xprime_"; - switch (subDetId){ - case 1 : histoName+="TPBBarrel_0";break; - case 2 : histoName+="TPEendcap_1";break; - case 3 : histoName+="TPEendcap_2";break; - case 4 : histoName+="TIBBarrel_0";break; - case 5 : histoName+="TIDEndcap_1";break; - case 6 : histoName+="TIDEndcap_2";break; - case 7 : histoName+="TOBBarrel_3";break; - case 8 : histoName+="TECEndcap_4";break; - case 9 : histoName+="TECEndcap_5";break; + TString histoName = ""; + if (plotNormHisto) { + histoName = "h_NormXprime"; + } else + histoName = "h_Xprime_"; + switch (subDetId) { + case 1: + histoName += "TPBBarrel_0"; + break; + case 2: + histoName += "TPEendcap_1"; + break; + case 3: + histoName += "TPEendcap_2"; + break; + case 4: + histoName += "TIBBarrel_0"; + break; + case 5: + histoName += "TIDEndcap_1"; + break; + case 6: + histoName += "TIDEndcap_2"; + break; + case 7: + histoName += "TOBBarrel_3"; + break; + case 8: + histoName += "TECEndcap_4"; + break; + case 9: + histoName += "TECEndcap_5"; + break; } int tmpcounter = 0; - TH1 *sumHisto = 0; - for(std::vector::iterator it = sourceList.begin(); - it != sourceList.end(); ++it) { - if (tmpcounter == 0 ) { - TFile *f= (*it)->getFile(); - sumHisto =(TH1*) f->FindKeyAny(histoName)->ReadObj();//FindObjectAny(histoName.Data()); - sumHisto->SetLineColor(tmpcounter+1); - sumHisto->SetLineStyle(tmpcounter+1); + TH1* sumHisto = 0; + for (std::vector::iterator it = sourceList.begin(); it != sourceList.end(); ++it) { + if (tmpcounter == 0) { + TFile* f = (*it)->getFile(); + sumHisto = (TH1*)f->FindKeyAny(histoName)->ReadObj(); //FindObjectAny(histoName.Data()); + sumHisto->SetLineColor(tmpcounter + 1); + sumHisto->SetLineStyle(tmpcounter + 1); sumHisto->GetFunction("tmp")->SetBit(TF1::kNotDraw); sumHisto->Draw(); - + //get statistic box coordinate to plot all boxes one below the other //gStyle->SetStatY(0.91); //gStyle->SetStatW(0.15); //gStyle->SetStatBorderSize(1); //gStyle->SetStatH(0.10); - - + tmpcounter++; } else { - sumHisto = (TH1*) (*it)->getFile()->FindObjectAny(histoName); - sumHisto->SetLineColor(tmpcounter+1); - sumHisto->SetLineStyle(tmpcounter+1); + sumHisto = (TH1*)(*it)->getFile()->FindObjectAny(histoName); + sumHisto->SetLineColor(tmpcounter + 1); + sumHisto->SetLineStyle(tmpcounter + 1); sumHisto->GetFunction("tmp")->SetBit(TF1::kNotDraw); //hstack->Add(sumHisto); - + c->Update(); - tmpcounter++; + tmpcounter++; } - TObject *statObj = sumHisto->GetListOfFunctions()->FindObject("stats"); + TObject* statObj = sumHisto->GetListOfFunctions()->FindObject("stats"); if (statObj && statObj->InheritsFrom(TPaveStats::Class())) { - TPaveStats *stats = static_cast(statObj); - stats->SetLineColor(tmpcounter+1); - stats->SetTextColor(tmpcounter+1); + TPaveStats* stats = static_cast(statObj); + stats->SetLineColor(tmpcounter + 1); + stats->SetTextColor(tmpcounter + 1); stats->SetFillColor(10); - stats->SetX1NDC(0.91-tmpcounter*0.1); + stats->SetX1NDC(0.91 - tmpcounter * 0.1); stats->SetX2NDC(0.15); stats->SetY1NDC(1); stats->SetY2NDC(0.10); @@ -312,200 +325,191 @@ void PlotAlignmentValidation::plotSubDetResiduals(bool plotNormHisto,unsigned in } //hstack->Draw("nostack"); char PlotName[1000]; - sprintf( PlotName, "%s/%s.png", outputDir.c_str(), histoName.Data() ); + sprintf(PlotName, "%s/%s.png", outputDir.c_str(), histoName.Data()); c->Print(PlotName); - sprintf( PlotName, "%s/%s.eps", outputDir.c_str(), histoName.Data() ); + sprintf(PlotName, "%s/%s.eps", outputDir.c_str(), histoName.Data()); c->Print(PlotName); - sprintf( PlotName, "%s/%s.pdf", outputDir.c_str(), histoName.Data() ); + sprintf(PlotName, "%s/%s.pdf", outputDir.c_str(), histoName.Data()); c->Print(PlotName); - sprintf( PlotName, "%s/%s.root", outputDir.c_str(), histoName.Data() ); + sprintf(PlotName, "%s/%s.root", outputDir.c_str(), histoName.Data()); c->Print(PlotName); //delete c; //c=0; - } //------------------------------------------------------------------------------ -void PlotAlignmentValidation::plotHitMaps() -{ - +void PlotAlignmentValidation::plotHitMaps() { //gStyle->SetOptStat(0); - - TCanvas *c = new TCanvas("c", "c", 1200,400); - c->Divide(3,1); + + TCanvas* c = new TCanvas("c", "c", 1200, 400); + c->Divide(3, 1); //ps->NewPage(); //------------------------------------------------- //plot Hit map //------------------------------------------------- - std::string histName_="Entriesprofile"; + std::string histName_ = "Entriesprofile"; c->cd(1); - TTree *tree= (*sourceList.begin())->getTree(); - tree->Draw("entries:posR:posZ","","COLZ2Prof"); + TTree* tree = (*sourceList.begin())->getTree(); + tree->Draw("entries:posR:posZ", "", "COLZ2Prof"); c->cd(2); - tree->Draw("entries:posY:posX","","COLZ2Prof"); + tree->Draw("entries:posY:posX", "", "COLZ2Prof"); c->cd(3); - tree->Draw("entries:posR:posPhi","","COLZ2Prof"); - + tree->Draw("entries:posR:posPhi", "", "COLZ2Prof"); + char PlotName[1000]; - sprintf( PlotName, "%s/%s.png", outputDir.c_str(), histName_.c_str() ); + sprintf(PlotName, "%s/%s.png", outputDir.c_str(), histName_.c_str()); c->Print(PlotName); - sprintf( PlotName, "%s/%s.eps", outputDir.c_str(), histName_.c_str() ); + sprintf(PlotName, "%s/%s.eps", outputDir.c_str(), histName_.c_str()); c->Print(PlotName); - sprintf( PlotName, "%s/%s.pdf", outputDir.c_str(), histName_.c_str() ); + sprintf(PlotName, "%s/%s.pdf", outputDir.c_str(), histName_.c_str()); c->Print(PlotName); - sprintf( PlotName, "%s/%s.root", outputDir.c_str(), histName_.c_str() ); + sprintf(PlotName, "%s/%s.root", outputDir.c_str(), histName_.c_str()); c->Print(PlotName); // //c->Update(); - c->Close(); + c->Close(); //---------------------------------------------------- - } //------------------------------------------------------------------------------ -void PlotAlignmentValidation::plotOutlierModules(const char *outputFileName, std::string plotVariable, - float plotVariable_cut ,int unsigned minHits) -{ - - Int_t counter=0; - +void PlotAlignmentValidation::plotOutlierModules(const char* outputFileName, + std::string plotVariable, + float plotVariable_cut, + int unsigned minHits) { + Int_t counter = 0; + gStyle->SetOptStat(111111); gStyle->SetStatY(0.9); //TList* treelist=getTreeList(); - - TCanvas *c1 = new TCanvas("canv", "canv", 800, 500); - outputFile = outputDir +'/'+ outputFileName; - c1->Print( (outputFile+'[').Data() ); - - - c1->Divide(2,1); - - TTree *tree= (*sourceList.begin())->getTree(); - TkOffTreeVariables *treeMem = 0; // ROOT will initilise + + TCanvas* c1 = new TCanvas("canv", "canv", 800, 500); + outputFile = outputDir + '/' + outputFileName; + c1->Print((outputFile + '[').Data()); + + c1->Divide(2, 1); + + TTree* tree = (*sourceList.begin())->getTree(); + TkOffTreeVariables* treeMem = 0; // ROOT will initilise tree->SetBranchAddress("TkOffTreeVariables", &treeMem); - - - Long64_t nentries = tree->GetEntriesFast(); - - for (Long64_t i = 0; i < nentries; i++){ - + + Long64_t nentries = tree->GetEntriesFast(); + + for (Long64_t i = 0; i < nentries; i++) { tree->GetEntry(i); float var = 0; - if (plotVariable == "chi2PerDofX") var =treeMem->chi2PerDofX; - else if(plotVariable == "chi2PerDofY") var =treeMem->chi2PerDofY; - else if(plotVariable == "fitMeanX") var =treeMem->fitMeanX; - else if(plotVariable == "fitMeanY") var =treeMem->fitMeanY; - else if(plotVariable == "fitSigmaX") var =treeMem->fitSigmaX; - else if(plotVariable == "fitSigmaY") var =treeMem->fitSigmaY; + if (plotVariable == "chi2PerDofX") + var = treeMem->chi2PerDofX; + else if (plotVariable == "chi2PerDofY") + var = treeMem->chi2PerDofY; + else if (plotVariable == "fitMeanX") + var = treeMem->fitMeanX; + else if (plotVariable == "fitMeanY") + var = treeMem->fitMeanY; + else if (plotVariable == "fitSigmaX") + var = treeMem->fitSigmaX; + else if (plotVariable == "fitSigmaY") + var = treeMem->fitSigmaY; else { - cout<<"There is no variable "<entries "<entries< plotVariable_cut && treeMem->entries > minHits) - { - - TFile *f=(*sourceList.begin())->getFile();//(TFile*)sourcelist->First(); - - if(f->FindKeyAny(treeMem->histNameX.c_str())!=0){ - TH1 *h = (TH1*) f->FindKeyAny(treeMem->histNameX.c_str())->ReadObj();//f->FindObjectAny(treeMem->histNameX.c_str()); - gStyle->SetOptFit(0111); - cout<<"hist name "<GetName()<GetPath(), "TrackerOfflineValidation" ); - //cout<<"hist path "<GetEntries()<cd(0); - TPaveText * text=new TPaveText(0,0.95,0.99,0.99); - text->AddText(path); - text->SetFillColor(0); - text->SetShadowColor(0); - text->SetBorderSize( 0 ); - text->Draw(); - - //residual histogram - c1->cd(1); - TPad *subpad = (TPad*)c1->GetPad(1); - subpad->SetPad(0,0,0.5,0.94); - h->Draw(); - - //norm. residual histogram - h = (TH1*) f->FindObjectAny(treeMem->histNameNormX.c_str()); - if(h) cout<GetEntries()<cd(2); - TPad *subpad2 = (TPad*)c1->GetPad(2); - subpad2->SetPad(0.5,0,0.99,0.94); - h->Draw(); - - c1->Print(outputFile); - counter++; - } - else{ - cout<<"There are no residual histograms on module level stored!"<entries "<entries< plotVariable_cut && treeMem->entries > minHits) { + TFile* f = (*sourceList.begin())->getFile(); //(TFile*)sourcelist->First(); + + if (f->FindKeyAny(treeMem->histNameX.c_str()) != 0) { + TH1* h = + (TH1*)f->FindKeyAny(treeMem->histNameX.c_str())->ReadObj(); //f->FindObjectAny(treeMem->histNameX.c_str()); + gStyle->SetOptFit(0111); + cout << "hist name " << h->GetName() << endl; + + TString path = (char*)strstr(gDirectory->GetPath(), "TrackerOfflineValidation"); + //cout<<"hist path "<GetEntries() << endl; + + //modules' location as title + c1->cd(0); + TPaveText* text = new TPaveText(0, 0.95, 0.99, 0.99); + text->AddText(path); + text->SetFillColor(0); + text->SetShadowColor(0); + text->SetBorderSize(0); + text->Draw(); + + //residual histogram + c1->cd(1); + TPad* subpad = (TPad*)c1->GetPad(1); + subpad->SetPad(0, 0, 0.5, 0.94); + h->Draw(); + + //norm. residual histogram + h = (TH1*)f->FindObjectAny(treeMem->histNameNormX.c_str()); + if (h) + cout << h->GetEntries() << endl; + c1->cd(2); + TPad* subpad2 = (TPad*)c1->GetPad(2); + subpad2->SetPad(0.5, 0, 0.99, 0.94); + h->Draw(); + + c1->Print(outputFile); + counter++; + } else { + cout << "There are no residual histograms on module level stored!" << endl; + cout << "Please make sure that moduleLevelHistsTransient = cms.bool(False) in the validation job!" << endl; + break; } - + } } - c1->Print( (outputFile+"]").Data() ); - if (counter == 0) cout<<"no bad modules found"<Print((outputFile + "]").Data()); + if (counter == 0) + cout << "no bad modules found" << endl; + //read the number of entries in the t3 //TTree* tree=0; //tree=(TTree*)treeList->At(0); - - + //c1->Close(); - } //------------------------------------------------------------------------------ /*! \fn getTreeList * \brief Extract from the rootfiles stored in the sourcelist the corresponding trees. */ -TList* PlotAlignmentValidation::getTreeList() -{ - TList *treeList = new TList(); - TFile *first_source = (TFile*)sourcelist->First(); - std::cout<GetName()<Get( treeBaseDir.c_str() ); - treeList->Add( (TTree*)(*d).Get("TkOffVal") ); - - if( moreThanOneSource ==true ){ - TFile *nextsource = (TFile*)sourcelist->After( first_source ); - while ( nextsource ) { - std::cout<GetName()<Get("TrackerOfflineValidation"); - +TList* PlotAlignmentValidation::getTreeList() { + TList* treeList = new TList(); + TFile* first_source = (TFile*)sourcelist->First(); + std::cout << first_source->GetName() << std::endl; + TDirectoryFile* d = (TDirectoryFile*)first_source->Get(treeBaseDir.c_str()); + treeList->Add((TTree*)(*d).Get("TkOffVal")); + + if (moreThanOneSource == true) { + TFile* nextsource = (TFile*)sourcelist->After(first_source); + while (nextsource) { + std::cout << nextsource->GetName() << std::endl; + d = (TDirectoryFile*)nextsource->Get("TrackerOfflineValidation"); + treeList->Add((TTree*)(*d).Get("TkOffVal")); - - nextsource = (TFile*)sourcelist->After( nextsource ); + + nextsource = (TFile*)sourcelist->After(nextsource); } } return treeList; } //------------------------------------------------------------------------------ -void PlotAlignmentValidation::setTreeBaseDir( std::string dir ) -{ - treeBaseDir = dir; -} +void PlotAlignmentValidation::setTreeBaseDir(std::string dir) { treeBaseDir = dir; } //------------------------------------------------------------------------------ -void PlotAlignmentValidation::plotSurfaceShapes( const std::string& options, const std::string& residType ) -{ +void PlotAlignmentValidation::plotSurfaceShapes(const std::string& options, const std::string& residType) { cout << "-------- plotSurfaceShapes called with " << options << endl; if (options == "none") return; - else if (options == "coarse"){ + else if (options == "coarse") { plotSS("subdet=1"); plotSS("subdet=2"); plotSS("subdet=3"); @@ -514,23 +518,22 @@ void PlotAlignmentValidation::plotSurfaceShapes( const std::string& options, con plotSS("subdet=6"); } // else if (options == "fine") ... - else - plotSS( options, residType ); + else + plotSS(options, residType); return; } //------------------------------------------------------------------------------ -void PlotAlignmentValidation::plotSS( const std::string& options, const std::string& residType ) -{ +void PlotAlignmentValidation::plotSS(const std::string& options, const std::string& residType) { if (residType == "") { - plotSS( options, "ResXvsXProfile"); - plotSS( options, "ResXvsYProfile"); + plotSS(options, "ResXvsXProfile"); + plotSS(options, "ResXvsYProfile"); return; } int bkperrorx = gStyle->GetErrorX(); - gStyle->SetErrorX(1); //regardless of style settings, we want x error bars here + gStyle->SetErrorX(1); //regardless of style settings, we want x error bars here int plotLayerN = 0; // int plotRingN = 0; @@ -538,41 +541,44 @@ void PlotAlignmentValidation::plotSS( const std::string& options, const std::str bool plotLayers = false; // overrides plotLayerN // bool plotRings = false; // Todo: implement this? bool plotSplits = false; - int plotSubDetN = 0; // if zero, plot all + int plotSubDetN = 0; // if zero, plot all TRegexp layer_re("layer=[0-9]+"); Ssiz_t index, len; - if (options.find("split") != std::string::npos) { plotSplits = true; } - if (options.find("layers") != std::string::npos) { plotLayers = true; } + if (options.find("split") != std::string::npos) { + plotSplits = true; + } + if (options.find("layers") != std::string::npos) { + plotLayers = true; + } if ((index = layer_re.Index(options, &len)) != -1) { if (plotLayers) { std::cerr << "Warning: option 'layers' overrides 'layer=N'" << std::endl; } else { - std::string substr = options.substr(index+6, len-6); + std::string substr = options.substr(index + 6, len - 6); plotLayerN = atoi(substr.c_str()); } } TRegexp subdet_re("subdet=[1-6]+"); if ((index = subdet_re.Index(options, &len)) != -1) { - std::string substr = options.substr(index+7, len-7); + std::string substr = options.substr(index + 7, len - 7); plotSubDetN = atoi(substr.c_str()); } gStyle->SetOptStat(0); - + TCanvas c("canv", "canv"); // todo: title, min/max, nbins? // Loop over detectors - for (int iSubDet=1; iSubDet<=6; ++iSubDet) { - + for (int iSubDet = 1; iSubDet <= 6; ++iSubDet) { // TEC requires special care since rings 1-4 and 5-7 are plotted separately - bool isTEC = (iSubDet==6); + bool isTEC = (iSubDet == 6); // if subdet is specified, skip other subdets - if (plotSubDetN!=0 && iSubDet!=plotSubDetN) + if (plotSubDetN != 0 && iSubDet != plotSubDetN) continue; // Skips plotting too high layers @@ -586,120 +592,131 @@ void PlotAlignmentValidation::plotSS( const std::string& options, const std::str int maxlayer = plotLayers ? maxNumberOfLayers(iSubDet) : plotLayerN; // see later where this is used int maxlayerphase0 = plotLayers ? numberOfLayers(0, iSubDet) : plotLayerN; - + for (int layer = minlayer; layer <= maxlayer; layer++) { + // two plots for TEC, skip first + for (int iTEC = 0; iTEC < 2; iTEC++) { + if (!isTEC && iTEC == 0) + continue; + + char selection[1000]; + if (!isTEC) { + if (layer == 0) + sprintf(selection, "subDetId==%d", iSubDet); + else + sprintf(selection, "subDetId==%d && layer == %d", iSubDet, layer); + } else { // TEC + if (iTEC == 0) // rings + sprintf(selection, "subDetId==%d && ring <= 4", iSubDet); + else + sprintf(selection, "subDetId==%d && ring > 4", iSubDet); + } - // two plots for TEC, skip first - for (int iTEC = 0; iTEC<2; iTEC++) { - if (!isTEC && iTEC==0) continue; - - char selection[1000]; - if (!isTEC){ - if (layer==0) - sprintf(selection,"subDetId==%d",iSubDet); - else - sprintf(selection,"subDetId==%d && layer == %d",iSubDet,layer); - } - else{ // TEC - if (iTEC==0) // rings - sprintf(selection,"subDetId==%d && ring <= 4",iSubDet); - else - sprintf(selection,"subDetId==%d && ring > 4",iSubDet); - } - - - // Title for plot and name for the file - - TString subDetName; - switch (iSubDet) { - case 1: subDetName = "BPIX"; break; - case 2: subDetName = "FPIX"; break; - case 3: subDetName = "TIB"; break; - case 4: subDetName = "TID"; break; - case 5: subDetName = "TOB"; break; - case 6: subDetName = "TEC"; break; - } + // Title for plot and name for the file + + TString subDetName; + switch (iSubDet) { + case 1: + subDetName = "BPIX"; + break; + case 2: + subDetName = "FPIX"; + break; + case 3: + subDetName = "TIB"; + break; + case 4: + subDetName = "TID"; + break; + case 5: + subDetName = "TOB"; + break; + case 6: + subDetName = "TEC"; + break; + } TString secondline = ""; - if (layer!=0) { - // TEC and TID have discs, the rest have layers - if (iSubDet==4 || iSubDet==6) - secondline = "disc "; - else { - secondline = "layer "; - } - secondline += Form("%d",layer); - secondline += " "; - } - if (isTEC && iTEC==0) - secondline += TString("R1-4"); - if (isTEC && iTEC>0) - secondline += TString("R5-7"); - - // Generate histograms with selection - TLegend* legend = 0; + if (layer != 0) { + // TEC and TID have discs, the rest have layers + if (iSubDet == 4 || iSubDet == 6) + secondline = "disc "; + else { + secondline = "layer "; + } + secondline += Form("%d", layer); + secondline += " "; + } + if (isTEC && iTEC == 0) + secondline += TString("R1-4"); + if (isTEC && iTEC > 0) + secondline += TString("R5-7"); + + // Generate histograms with selection + TLegend* legend = 0; // Any file from phase 0 will be skipped if the last argument is false - THStack *hs = addHists(selection, residType, &legend, false, /*validforphase0 = */layer <= maxlayerphase0); - if (!hs || hs->GetHists()==0 || hs->GetHists()->GetSize()==0) { - std::cout << "No histogram for " << subDetName << - ", perhaps not enough data? Creating default histogram." << std::endl; - if(hs == 0) - hs = new THStack("hstack", ""); - - TProfile* defhist = new TProfile("defhist", "Empty default histogram", 100, -1, 1, -1, 1); - hs->Add(defhist); - hs->Draw(); - } - else { - hs->Draw("nostack PE"); - modifySSHistAndLegend(hs, legend); - legend->Draw(); - setTitleStyle(*hs, "", "", iSubDet, true, secondline); - - // Adjust Labels - TH1* firstHisto = (TH1*) hs->GetHists()->First(); - TString xName = firstHisto->GetXaxis()->GetTitle(); - TString yName = firstHisto->GetYaxis()->GetTitle(); - hs->GetHistogram()->GetXaxis()->SetTitleColor( kBlack ); - hs->GetHistogram()->GetXaxis()->SetTitle( xName ); - hs->GetHistogram()->GetYaxis()->SetTitleColor( kBlack ); - // micrometers: - yName.ReplaceAll("cm", "#mum"); - hs->GetHistogram()->GetYaxis()->SetTitle( yName ); - } - - // Save plot to file - std::ostringstream plotName; - plotName << outputDir << "/SurfaceShape_" << subDetName << "_"; - plotName << residType; - if (layer!=0) { - plotName << "_"; - // TEC and TID have discs, the rest have layers - if (iSubDet==4 || iSubDet==6) - plotName << "disc"; - else { - plotName << "layer"; - } - plotName << layer; - } - if (isTEC && iTEC==0) - plotName << "_" << "R1-4"; - if (isTEC && iTEC>0) - plotName << "_" << "R5-7"; - - // PNG,EPS,PDF files - c.Update(); - c.Print((plotName.str() + ".png").c_str()); - c.Print((plotName.str() + ".eps").c_str()); - c.Print((plotName.str() + ".pdf").c_str()); - - // ROOT file - TFile f((plotName.str() + ".root").c_str(), "recreate"); - c.Write(); - f.Close(); - - delete legend; - delete hs; + THStack* hs = addHists(selection, residType, &legend, false, /*validforphase0 = */ layer <= maxlayerphase0); + if (!hs || hs->GetHists() == 0 || hs->GetHists()->GetSize() == 0) { + std::cout << "No histogram for " << subDetName << ", perhaps not enough data? Creating default histogram." + << std::endl; + if (hs == 0) + hs = new THStack("hstack", ""); + + TProfile* defhist = new TProfile("defhist", "Empty default histogram", 100, -1, 1, -1, 1); + hs->Add(defhist); + hs->Draw(); + } else { + hs->Draw("nostack PE"); + modifySSHistAndLegend(hs, legend); + legend->Draw(); + setTitleStyle(*hs, "", "", iSubDet, true, secondline); + + // Adjust Labels + TH1* firstHisto = (TH1*)hs->GetHists()->First(); + TString xName = firstHisto->GetXaxis()->GetTitle(); + TString yName = firstHisto->GetYaxis()->GetTitle(); + hs->GetHistogram()->GetXaxis()->SetTitleColor(kBlack); + hs->GetHistogram()->GetXaxis()->SetTitle(xName); + hs->GetHistogram()->GetYaxis()->SetTitleColor(kBlack); + // micrometers: + yName.ReplaceAll("cm", "#mum"); + hs->GetHistogram()->GetYaxis()->SetTitle(yName); + } + + // Save plot to file + std::ostringstream plotName; + plotName << outputDir << "/SurfaceShape_" << subDetName << "_"; + plotName << residType; + if (layer != 0) { + plotName << "_"; + // TEC and TID have discs, the rest have layers + if (iSubDet == 4 || iSubDet == 6) + plotName << "disc"; + else { + plotName << "layer"; + } + plotName << layer; + } + if (isTEC && iTEC == 0) + plotName << "_" + << "R1-4"; + if (isTEC && iTEC > 0) + plotName << "_" + << "R5-7"; + + // PNG,EPS,PDF files + c.Update(); + c.Print((plotName.str() + ".png").c_str()); + c.Print((plotName.str() + ".eps").c_str()); + c.Print((plotName.str() + ".pdf").c_str()); + + // ROOT file + TFile f((plotName.str() + ".root").c_str(), "recreate"); + c.Write(); + f.Close(); + + delete legend; + delete hs; } } } @@ -708,36 +725,34 @@ void PlotAlignmentValidation::plotSS( const std::string& options, const std::str return; } - //------------------------------------------------------------------------------ /*! \fn plotDMR * \brief Main function used to plot DMRs for a single IOV printing the canvases in the output directory and saving histograms and fit funtions in a root file. */ -void PlotAlignmentValidation::plotDMR(const std::string& variable, Int_t minHits, const std::string& options) -{ +void PlotAlignmentValidation::plotDMR(const std::string& variable, Int_t minHits, const std::string& options) { // If several, comma-separated values are given in 'variable', // call plotDMR with each value separately. // If a comma is found, the string is divided to two. // (no space allowed) std::size_t findres = variable.find(","); - if ( findres != std::string::npos) { - std::string substring1 = variable.substr(0, findres); - std::string substring2 = variable.substr(findres+1, std::string::npos); + if (findres != std::string::npos) { + std::string substring1 = variable.substr(0, findres); + std::string substring2 = variable.substr(findres + 1, std::string::npos); plotDMR(substring1, minHits, options); plotDMR(substring2, minHits, options); return; - } + } // Variable name should end with X or Y. If it doesn't, recursively calls plotDMR twice with // X and Y added, respectively - if (variable == "mean" || variable == "median" || variable == "meanNorm" || - variable == "rms" || variable == "rmsNorm") { - plotDMR(variable+"X", minHits, options); - plotDMR(variable+"Y", minHits, options); + if (variable == "mean" || variable == "median" || variable == "meanNorm" || variable == "rms" || + variable == "rmsNorm") { + plotDMR(variable + "X", minHits, options); + plotDMR(variable + "Y", minHits, options); return; } - // options: + // options: // -plain (default, the whole distribution) // -split (distribution splitted to two) // -layers (plain db for each layer/disc superimposed in one plot) @@ -749,30 +764,38 @@ void PlotAlignmentValidation::plotDMR(const std::string& variable, Int_t minHits bool plotPlain = false, plotSplits = false, plotLayers = false; int plotLayerN = 0; Ssiz_t index, len; - if (options.find("plain") != std::string::npos) { plotPlain = true; } - if (options.find("split") != std::string::npos) { plotSplits = true; } - if (options.find("layers") != std::string::npos) { plotLayers = true; } + if (options.find("plain") != std::string::npos) { + plotPlain = true; + } + if (options.find("split") != std::string::npos) { + plotSplits = true; + } + if (options.find("layers") != std::string::npos) { + plotLayers = true; + } if ((index = layer_re.Index(options, &len)) != -1) { if (plotLayers) { std::cerr << "Warning: option 'layers' overrides 'layer=N'" << std::endl; } else { - std::string substr = options.substr(index+6, len-6); + std::string substr = options.substr(index + 6, len - 6); plotLayerN = atoi(substr.c_str()); } } // Defaults to plotting only plain plot if empty (or invalid) // option string is given - if (!plotPlain && !plotSplits) { plotPlain = true; } + if (!plotPlain && !plotSplits) { + plotPlain = true; + } // This boolean array tells for which detector modules to plot split DMR plots // They are plotted for BPIX, FPIX, TIB and TOB - static bool plotSplitsFor[6] = { true, true, true, false, true, false }; + static bool plotSplitsFor[6] = {true, true, true, false, true, false}; DMRPlotInfo plotinfo; gStyle->SetOptStat(0); - + TCanvas c("canv", "canv"); plotinfo.variable = variable; @@ -783,38 +806,77 @@ void PlotAlignmentValidation::plotDMR(const std::string& variable, Int_t minHits // width in cm // for DMRS, use 100 bins in range +-10 um, bin width 0.2um // if modified, check also TrackerOfflineValidationSummary_cfi.py and TrackerOfflineValidation_Standalone_cff.py - if (variable == "meanX") { plotinfo.nbins = 50; plotinfo.min = -0.001; plotinfo.max = 0.001; } - else if (variable == "meanY") { plotinfo.nbins = 50; plotinfo.min = -0.005; plotinfo.max = 0.005; } - else if (variable == "medianX") - if (plotSplits) { plotinfo.nbins = 50; plotinfo.min = -0.0005; plotinfo.max = 0.0005;} - else { plotinfo.nbins = 100; plotinfo.min = -0.001; plotinfo.max = 0.001; } + if (variable == "meanX") { + plotinfo.nbins = 50; + plotinfo.min = -0.001; + plotinfo.max = 0.001; + } else if (variable == "meanY") { + plotinfo.nbins = 50; + plotinfo.min = -0.005; + plotinfo.max = 0.005; + } else if (variable == "medianX") + if (plotSplits) { + plotinfo.nbins = 50; + plotinfo.min = -0.0005; + plotinfo.max = 0.0005; + } else { + plotinfo.nbins = 100; + plotinfo.min = -0.001; + plotinfo.max = 0.001; + } else if (variable == "medianY") - if (plotSplits) { plotinfo.nbins = 50; plotinfo.min = -0.0005; plotinfo.max = 0.0005;} - else { plotinfo.nbins = 100; plotinfo.min = -0.001; plotinfo.max = 0.001; } - else if (variable == "meanNormX") { plotinfo.nbins = 100; plotinfo.min = -2.0; plotinfo.max = 2.0; } - else if (variable == "meanNormY") { plotinfo.nbins = 100; plotinfo.min = -2.0; plotinfo.max = 2.0; } - else if (variable == "rmsX") { plotinfo.nbins = 100; plotinfo.min = 0.0; plotinfo.max = 0.1; } - else if (variable == "rmsY") { plotinfo.nbins = 100; plotinfo.min = 0.0; plotinfo.max = 0.1; } - else if (variable == "rmsNormX") { plotinfo.nbins = 100; plotinfo.min = 0.3; plotinfo.max = 1.8; } - else if (variable == "rmsNormY") { plotinfo.nbins = 100; plotinfo.min = 0.3; plotinfo.max = 1.8; } - else { + if (plotSplits) { + plotinfo.nbins = 50; + plotinfo.min = -0.0005; + plotinfo.max = 0.0005; + } else { + plotinfo.nbins = 100; + plotinfo.min = -0.001; + plotinfo.max = 0.001; + } + else if (variable == "meanNormX") { + plotinfo.nbins = 100; + plotinfo.min = -2.0; + plotinfo.max = 2.0; + } else if (variable == "meanNormY") { + plotinfo.nbins = 100; + plotinfo.min = -2.0; + plotinfo.max = 2.0; + } else if (variable == "rmsX") { + plotinfo.nbins = 100; + plotinfo.min = 0.0; + plotinfo.max = 0.1; + } else if (variable == "rmsY") { + plotinfo.nbins = 100; + plotinfo.min = 0.0; + plotinfo.max = 0.1; + } else if (variable == "rmsNormX") { + plotinfo.nbins = 100; + plotinfo.min = 0.3; + plotinfo.max = 1.8; + } else if (variable == "rmsNormY") { + plotinfo.nbins = 100; + plotinfo.min = 0.3; + plotinfo.max = 1.8; + } else { std::cerr << "Unknown variable " << variable << std::endl; - plotinfo.nbins = 100; plotinfo.min = -0.1; plotinfo.max = 0.1; + plotinfo.nbins = 100; + plotinfo.min = -0.1; + plotinfo.max = 0.1; } //Begin loop on structures - for (int i=1; i<=6; ++i) { - + for (int i = 1; i <= 6; ++i) { // Skip strip detectors if plotting any "Y" variable - if (i != 1 && i != 2 && variable.length() > 0 && variable[variable.length()-1] == 'Y') { + if (i != 1 && i != 2 && variable.length() > 0 && variable[variable.length() - 1] == 'Y') { continue; } - + // Skips plotting too high layers if (plotLayerN > maxNumberOfLayers(i)) { continue; } - plotinfo.plotSplits = plotSplits && plotSplitsFor[i-1]; + plotinfo.plotSplits = plotSplits && plotSplitsFor[i - 1]; if (!plotinfo.plotPlain && !plotinfo.plotSplits) { continue; } @@ -824,17 +886,27 @@ void PlotAlignmentValidation::plotDMR(const std::string& variable, Int_t minHits bool hasheader = (TkAlStyle::legendheader != ""); int nPlots = 1; - if (plotinfo.plotSplits) { nPlots = 3; } + if (plotinfo.plotSplits) { + nPlots = 3; + } // This will make the legend a bit bigger than necessary if there is a mixture of phase 0 and phase 1. // Not worth it to implement more complicated logic. - if (plotinfo.plotLayers) { nPlots *= maxNumberOfLayers(i); } + if (plotinfo.plotLayers) { + nPlots *= maxNumberOfLayers(i); + } nPlots *= sourceList.size(); - if (twolines_) { nPlots *= 2; } + if (twolines_) { + nPlots *= 2; + } nPlots += hasheader; double legendY = 0.80; - if (nPlots > 3) { legendY -= 0.01 * (nPlots - 3); } - if (bigtext_) { legendY -= 0.05; } + if (nPlots > 3) { + legendY -= 0.01 * (nPlots - 3); + } + if (bigtext_) { + legendY -= 0.05; + } if (legendY < 0.6) { std::cerr << "Warning: Huge legend!" << std::endl; legendY = 0.6; @@ -845,53 +917,72 @@ void PlotAlignmentValidation::plotDMR(const std::string& variable, Int_t minHits plotinfo.subDetId = i; plotinfo.legend = new TLegend(0.17, legendY, 0.85, 0.88); plotinfo.legend->SetNColumns(2); - if (hasheader) plotinfo.legend->SetHeader(TkAlStyle::legendheader); - if (bigtext_) plotinfo.legend->SetTextSize(TkAlStyle::textSize); + if (hasheader) + plotinfo.legend->SetHeader(TkAlStyle::legendheader); + if (bigtext_) + plotinfo.legend->SetTextSize(TkAlStyle::textSize); plotinfo.legend->SetFillStyle(0); plotinfo.hstack = &hstack; plotinfo.h = plotinfo.h1 = plotinfo.h2 = 0; plotinfo.firsthisto = true; openSummaryFile(); - vmean.clear(); vrms.clear(); vdeltamean.clear(); vmeanerror.clear(); vPValueEqualSplitMeans.clear(), vAlignmentUncertainty.clear(); vPValueMeanEqualIdeal.clear(); vPValueRMSEqualIdeal.clear(); + vmean.clear(); + vrms.clear(); + vdeltamean.clear(); + vmeanerror.clear(); + vPValueEqualSplitMeans.clear(), vAlignmentUncertainty.clear(); + vPValueMeanEqualIdeal.clear(); + vPValueRMSEqualIdeal.clear(); std::string stringsubdet; switch (i) { - case 1: stringsubdet = "BPIX"; break; - case 2: stringsubdet = "FPIX"; break; - case 3: stringsubdet = "TIB"; break; - case 4: stringsubdet = "TID"; break; - case 5: stringsubdet = "TOB"; break; - case 6: stringsubdet = "TEC"; break; + case 1: + stringsubdet = "BPIX"; + break; + case 2: + stringsubdet = "FPIX"; + break; + case 3: + stringsubdet = "TIB"; + break; + case 4: + stringsubdet = "TID"; + break; + case 5: + stringsubdet = "TOB"; + break; + case 6: + stringsubdet = "TEC"; + break; } - for(std::vector::iterator it = sourceList.begin(); - it != sourceList.end(); ++it) { - + for (std::vector::iterator it = sourceList.begin(); it != sourceList.end(); ++it) { plotinfo.vars = *it; plotinfo.h1 = plotinfo.h2 = plotinfo.h = 0; int minlayer = plotLayers ? 1 : plotLayerN; //Layer 0 is associated to the entire structure, this check ensures that even when both the plotLayers and the plotPlain options are active, also the histogram for the entire structure is made. - if(plotinfo.plotPlain) minlayer=0; + if (plotinfo.plotPlain) + minlayer = 0; int maxlayer = plotLayers ? numberOfLayers(plotinfo.vars->getPhase(), plotinfo.subDetId) : plotLayerN; for (int layer = minlayer; layer <= maxlayer; layer++) { + if (plotinfo.plotPlain) { + plotDMRHistogram(plotinfo, 0, layer, stringsubdet); + } - if (plotinfo.plotPlain) { - plotDMRHistogram(plotinfo, 0, layer, stringsubdet); - } - - if (plotinfo.plotSplits) { - plotDMRHistogram(plotinfo, -1, layer, stringsubdet); - plotDMRHistogram(plotinfo, 1, layer, stringsubdet); - } + if (plotinfo.plotSplits) { + plotDMRHistogram(plotinfo, -1, layer, stringsubdet); + plotDMRHistogram(plotinfo, 1, layer, stringsubdet); + } - if (plotinfo.plotPlain) { - if (plotinfo.h) { + if (plotinfo.plotPlain) { + if (plotinfo.h) { setDMRHistStyleAndLegend(plotinfo.h, plotinfo, 0, layer); } else { - if ((plotinfo.variable == "medianX" || plotinfo.variable == "medianY") && /*!plotinfo.plotLayers && */layer==0) { + if ((plotinfo.variable == "medianX" || plotinfo.variable == "medianY") && + /*!plotinfo.plotLayers && */ layer == 0) { vmean.push_back(nan("")); vrms.push_back(nan("")); vmeanerror.push_back(nan("")); @@ -904,57 +995,58 @@ void PlotAlignmentValidation::plotDMR(const std::string& variable, Int_t minHits } } } - } - - if (plotinfo.plotSplits) { - // Add delta mu to the histogram - if (plotinfo.h1 != 0 && plotinfo.h2 != 0 && !plotinfo.plotPlain) { - std::ostringstream legend; - std::string unit = " #mum"; - legend.precision(3); - legend << fixed; // to always show 3 decimals - float factor = 10000.0f; - if (plotinfo.variable == "meanNormX" || plotinfo.variable == "meanNormY" || - plotinfo.variable == "rmsNormX" || plotinfo.variable == "rmsNormY") { - factor = 1.0f; - unit = ""; - } - float deltamu = factor*(plotinfo.h2->GetMean(1) - plotinfo.h1->GetMean(1)); - legend << plotinfo.vars->getName(); - if (layer > 0) { - // TEC and TID have discs, the rest have layers - if (i==4 || i==6) - legend << ", disc "; - else - legend << ", layer "; - legend << layer; - } - plotinfo.legend->AddEntry(static_cast(0), legend.str().c_str(), ""); - legend.str(""); - legend << "#Delta#mu = " << deltamu << unit; - plotinfo.legend->AddEntry(static_cast(0), legend.str().c_str(), ""); - - if ((plotinfo.variable == "medianX" || plotinfo.variable == "medianY") && !plotLayers && layer==0) { - vdeltamean.push_back(deltamu); + } + + if (plotinfo.plotSplits) { + // Add delta mu to the histogram + if (plotinfo.h1 != 0 && plotinfo.h2 != 0 && !plotinfo.plotPlain) { + std::ostringstream legend; + std::string unit = " #mum"; + legend.precision(3); + legend << fixed; // to always show 3 decimals + float factor = 10000.0f; + if (plotinfo.variable == "meanNormX" || plotinfo.variable == "meanNormY" || + plotinfo.variable == "rmsNormX" || plotinfo.variable == "rmsNormY") { + factor = 1.0f; + unit = ""; + } + float deltamu = factor * (plotinfo.h2->GetMean(1) - plotinfo.h1->GetMean(1)); + legend << plotinfo.vars->getName(); + if (layer > 0) { + // TEC and TID have discs, the rest have layers + if (i == 4 || i == 6) + legend << ", disc "; + else + legend << ", layer "; + legend << layer; } - } - if (plotinfo.h1) { setDMRHistStyleAndLegend(plotinfo.h1, plotinfo, -1, layer); } - if (plotinfo.h2) { setDMRHistStyleAndLegend(plotinfo.h2, plotinfo, 1, layer); } - } + plotinfo.legend->AddEntry(static_cast(0), legend.str().c_str(), ""); + legend.str(""); + legend << "#Delta#mu = " << deltamu << unit; + plotinfo.legend->AddEntry(static_cast(0), legend.str().c_str(), ""); + if ((plotinfo.variable == "medianX" || plotinfo.variable == "medianY") && !plotLayers && layer == 0) { + vdeltamean.push_back(deltamu); + } + } + if (plotinfo.h1) { + setDMRHistStyleAndLegend(plotinfo.h1, plotinfo, -1, layer); + } + if (plotinfo.h2) { + setDMRHistStyleAndLegend(plotinfo.h2, plotinfo, 1, layer); + } + } } - } - if (hstack.GetHists()!=0 && hstack.GetHists()->GetSize()!=0) { + if (hstack.GetHists() != 0 && hstack.GetHists()->GetSize() != 0) { hstack.Draw("nostack"); - hstack.SetMaximum(plotinfo.maxY*1.3); + hstack.SetMaximum(plotinfo.maxY * 1.3); setTitleStyle(hstack, variable.c_str(), "#modules", plotinfo.subDetId); setHistStyle(*hstack.GetHistogram(), variable.c_str(), "#modules", 1); - plotinfo.legend->Draw(); - } - else { + plotinfo.legend->Draw(); + } else { // Draw an empty default histogram plotinfo.h = new TH1F("defhist", "Empty default histogram", plotinfo.nbins, plotinfo.min, plotinfo.max); plotinfo.h->SetMaximum(10); @@ -968,42 +1060,66 @@ void PlotAlignmentValidation::plotDMR(const std::string& variable, Int_t minHits std::ostringstream plotName; plotName << outputDir << "/D"; - if (variable=="medianX") plotName << "medianR_"; - else if (variable=="medianY") plotName << "medianYR_"; - else if (variable=="meanX") plotName << "meanR_"; - else if (variable=="meanY") plotName << "meanYR_"; - else if (variable=="meanNormX") plotName << "meanNR_"; - else if (variable=="meanNormY") plotName << "meanNYR_"; - else if (variable=="rmsX") plotName << "rmsR_"; - else if (variable=="rmsY") plotName << "rmsYR_"; - else if (variable=="rmsNormX") plotName << "rmsNR_"; - else if (variable=="rmsNormY") plotName << "rmsNYR_"; - + if (variable == "medianX") + plotName << "medianR_"; + else if (variable == "medianY") + plotName << "medianYR_"; + else if (variable == "meanX") + plotName << "meanR_"; + else if (variable == "meanY") + plotName << "meanYR_"; + else if (variable == "meanNormX") + plotName << "meanNR_"; + else if (variable == "meanNormY") + plotName << "meanNYR_"; + else if (variable == "rmsX") + plotName << "rmsR_"; + else if (variable == "rmsY") + plotName << "rmsYR_"; + else if (variable == "rmsNormX") + plotName << "rmsNR_"; + else if (variable == "rmsNormY") + plotName << "rmsNYR_"; TString subdet; switch (i) { - case 1: subdet = "BPIX"; break; - case 2: subdet = "FPIX"; break; - case 3: subdet = "TIB"; break; - case 4: subdet = "TID"; break; - case 5: subdet = "TOB"; break; - case 6: subdet = "TEC"; break; + case 1: + subdet = "BPIX"; + break; + case 2: + subdet = "FPIX"; + break; + case 3: + subdet = "TIB"; + break; + case 4: + subdet = "TID"; + break; + case 5: + subdet = "TOB"; + break; + case 6: + subdet = "TEC"; + break; } plotName << subdet; - if (plotPlain && !plotSplits) { plotName << "_plain"; } - else if (!plotPlain && plotSplits) { plotName << "_split"; } + if (plotPlain && !plotSplits) { + plotName << "_plain"; + } else if (!plotPlain && plotSplits) { + plotName << "_split"; + } if (plotLayers) { // TEC and TID have discs, the rest have layers - if (i==4 || i==6) + if (i == 4 || i == 6) plotName << "_discs"; else plotName << "_layers"; } if (plotLayerN > 0) { // TEC and TID have discs, the rest have layers - if (i==4 || i==6) + if (i == 4 || i == 6) plotName << "_disc"; else plotName << "_layer"; @@ -1011,7 +1127,7 @@ void PlotAlignmentValidation::plotDMR(const std::string& variable, Int_t minHits } // PNG,EPS,PDF files - c.Update(); + c.Update(); c.Print((plotName.str() + ".png").c_str()); c.Print((plotName.str() + ".eps").c_str()); c.Print((plotName.str() + ".pdf").c_str()); @@ -1020,7 +1136,7 @@ void PlotAlignmentValidation::plotDMR(const std::string& variable, Int_t minHits TFile f((plotName.str() + ".root").c_str(), "recreate"); c.Write(); f.Close(); - + // Free allocated memory. delete plotinfo.h; delete plotinfo.h1; @@ -1028,120 +1144,143 @@ void PlotAlignmentValidation::plotDMR(const std::string& variable, Int_t minHits if (vmean.size()) { summaryfile << " mu_" << subdet; - if (plotinfo.variable == "medianY") summaryfile << "_y"; + if (plotinfo.variable == "medianY") + summaryfile << "_y"; summaryfile << " (um)\t" << "latexname=$\\mu_\\text{" << subdet << "}"; - if (plotinfo.variable == "medianY") summaryfile << "^{y}"; + if (plotinfo.variable == "medianY") + summaryfile << "^{y}"; summaryfile << "$ ($\\mu$m)\t" << "format={:.3g}\t" << "latexformat=${:.3g}$"; - for (auto mu : vmean) summaryfile << "\t" << mu; + for (auto mu : vmean) + summaryfile << "\t" << mu; summaryfile << "\n"; } if (vrms.size()) { summaryfile << "sigma_" << subdet; - if (plotinfo.variable == "medianY") summaryfile << "_y"; + if (plotinfo.variable == "medianY") + summaryfile << "_y"; summaryfile << " (um)\t" << "latexname=$\\sigma_\\text{" << subdet << "}"; - if (plotinfo.variable == "medianY") summaryfile << "^{y}"; + if (plotinfo.variable == "medianY") + summaryfile << "^{y}"; summaryfile << "$ ($\\mu$m)\t" << "format={:.3g}\t" << "latexformat=${:.3g}$"; - for (auto sigma : vrms) summaryfile << "\t" << sigma; + for (auto sigma : vrms) + summaryfile << "\t" << sigma; summaryfile << "\n"; } if (vdeltamean.size()) { - summaryfile << " dmu_" << subdet ; - if (plotinfo.variable == "medianY") summaryfile << "_y"; + summaryfile << " dmu_" << subdet; + if (plotinfo.variable == "medianY") + summaryfile << "_y"; summaryfile << " (um)\t" << "latexname=$\\Delta\\mu_\\text{" << subdet << "}"; - if (plotinfo.variable == "medianY") summaryfile << "^{y}"; + if (plotinfo.variable == "medianY") + summaryfile << "^{y}"; summaryfile << "$ ($\\mu$m)\t" << "format={:.3g}\t" << "latexformat=${:.3g}$"; - for (auto dmu : vdeltamean) summaryfile << "\t" << dmu; + for (auto dmu : vdeltamean) + summaryfile << "\t" << dmu; summaryfile << "\n"; } if (vmeanerror.size()) { - summaryfile << " sigma_mu_" << subdet ; - if (plotinfo.variable == "medianY") summaryfile << "_y"; + summaryfile << " sigma_mu_" << subdet; + if (plotinfo.variable == "medianY") + summaryfile << "_y"; summaryfile << " (um)\t" << "latexname=$\\sigma\\mu_\\text{" << subdet << "}"; - if (plotinfo.variable == "medianY") summaryfile << "^{y}"; + if (plotinfo.variable == "medianY") + summaryfile << "^{y}"; summaryfile << "$ ($\\mu$m)\t" << "format={:.3g}\t" << "latexformat=${:.3g}$"; - for (auto dmu : vmeanerror) summaryfile << "\t" << dmu; + for (auto dmu : vmeanerror) + summaryfile << "\t" << dmu; summaryfile << "\n"; } if (vPValueEqualSplitMeans.size()) { - summaryfile << " p_delta_mu_equal_zero_" << subdet ; - if (plotinfo.variable == "medianY") summaryfile << "_y"; + summaryfile << " p_delta_mu_equal_zero_" << subdet; + if (plotinfo.variable == "medianY") + summaryfile << "_y"; summaryfile << "\t" << "latexname=$P(\\delta\\mu_\\text{" << subdet << "}=0)"; - if (plotinfo.variable == "medianY") summaryfile << "^{y}"; + if (plotinfo.variable == "medianY") + summaryfile << "^{y}"; summaryfile << "$\t" << "format={:.3g}\t" << "latexformat=${:.3g}$"; - for (auto dmu : vPValueEqualSplitMeans) summaryfile << "\t" << dmu; + for (auto dmu : vPValueEqualSplitMeans) + summaryfile << "\t" << dmu; summaryfile << "\n"; } if (vAlignmentUncertainty.size()) { - summaryfile << " alignment_uncertainty_" << subdet ; - if (plotinfo.variable == "medianY") summaryfile << "_y"; + summaryfile << " alignment_uncertainty_" << subdet; + if (plotinfo.variable == "medianY") + summaryfile << "_y"; summaryfile << " (um)\t" << "latexname=$\\sigma_\\text{align}_\\text{" << subdet << "}"; - if (plotinfo.variable == "medianY") summaryfile << "^{y}"; + if (plotinfo.variable == "medianY") + summaryfile << "^{y}"; summaryfile << "$ ($\\mu$m)\t" << "format={:.3g}\t" << "latexformat=${:.3g}$"; - for (auto dmu : vAlignmentUncertainty) summaryfile << "\t" << dmu; + for (auto dmu : vAlignmentUncertainty) + summaryfile << "\t" << dmu; summaryfile << "\n"; } if (vPValueMeanEqualIdeal.size()) { - summaryfile << " p_mean_equals_ideal_" << subdet ; - if (plotinfo.variable == "medianY") summaryfile << "_y"; + summaryfile << " p_mean_equals_ideal_" << subdet; + if (plotinfo.variable == "medianY") + summaryfile << "_y"; summaryfile << "\t" << "latexname=$P(\\mu_\\text{" << subdet << "}=\\mu_\\text{ideal})"; - if (plotinfo.variable == "medianY") summaryfile << "^{y}"; + if (plotinfo.variable == "medianY") + summaryfile << "^{y}"; summaryfile << "$\t" << "format={:.3g}\t" << "latexformat=${:.3g}$"; - for (auto dmu : vPValueMeanEqualIdeal) summaryfile << "\t" << dmu; + for (auto dmu : vPValueMeanEqualIdeal) + summaryfile << "\t" << dmu; summaryfile << "\n"; } if (vPValueRMSEqualIdeal.size()) { - summaryfile << " p_RMS_equals_ideal_" << subdet ; - if (plotinfo.variable == "medianY") summaryfile << "_y"; + summaryfile << " p_RMS_equals_ideal_" << subdet; + if (plotinfo.variable == "medianY") + summaryfile << "_y"; summaryfile << "\t" << "latexname=$P(\\sigma_\\text{" << subdet << "}=\\sigma_\\text{ideal})"; - if (plotinfo.variable == "medianY") summaryfile << "^{y}"; + if (plotinfo.variable == "medianY") + summaryfile << "^{y}"; summaryfile << "$\t" << "format={:.3g}\t" << "latexformat=${:.3g}$"; - for (auto dmu : vPValueRMSEqualIdeal) summaryfile << "\t" << dmu; + for (auto dmu : vPValueRMSEqualIdeal) + summaryfile << "\t" << dmu; summaryfile << "\n"; } } } //------------------------------------------------------------------------------ -void PlotAlignmentValidation::plotChi2(const char *inputFile) -{ +void PlotAlignmentValidation::plotChi2(const char* inputFile) { // Opens the file (it should be OfflineValidation(Parallel)_result.root) // and reads and plots the norm_chi^2 and h_chi2Prob -distributions. Bool_t errorflag = kTRUE; - TFile* fi1 = TFile::Open(inputFile,"read"); + TFile* fi1 = TFile::Open(inputFile, "read"); TDirectoryFile* mta1 = NULL; TDirectoryFile* mtb1 = NULL; TCanvas* normchi = NULL; TCanvas* chiprob = NULL; if (fi1 != NULL) { - mta1 = (TDirectoryFile*) fi1->Get("TrackerOfflineValidationStandalone"); - if(mta1 != NULL) { - mtb1 = (TDirectoryFile*) mta1->Get("GlobalTrackVariables"); - if(mtb1 != NULL) { + mta1 = (TDirectoryFile*)fi1->Get("TrackerOfflineValidationStandalone"); + if (mta1 != NULL) { + mtb1 = (TDirectoryFile*)mta1->Get("GlobalTrackVariables"); + if (mtb1 != NULL) { normchi = dynamic_cast(mtb1->Get("h_normchi2")); chiprob = dynamic_cast(mtb1->Get("h_chi2Prob")); if (normchi != NULL && chiprob != NULL) { @@ -1150,17 +1289,17 @@ void PlotAlignmentValidation::plotChi2(const char *inputFile) } } } - if(errorflag) - { + if (errorflag) { std::cout << "PlotAlignmentValidation::plotChi2: Can't find data from given file," << " no chi^2-plots produced" << std::endl; return; } - TLegend *legend = 0; + TLegend* legend = 0; for (auto primitive : *normchi->GetListOfPrimitives()) { legend = dynamic_cast(primitive); - if (legend) break; + if (legend) + break; } if (legend) { openSummaryFile(); @@ -1172,10 +1311,11 @@ void PlotAlignmentValidation::plotChi2(const char *inputFile) int style = alignment->getLineStyle(); bool foundit = false; for (auto entry : *legend->GetListOfPrimitives()) { - TLegendEntry *legendentry = dynamic_cast(entry); + TLegendEntry* legendentry = dynamic_cast(entry); assert(legendentry); - TH1 *h = dynamic_cast(legendentry->GetObject()); - if (!h) continue; + TH1* h = dynamic_cast(legendentry->GetObject()); + if (!h) + continue; if (legendentry->GetLabel() == title && h->GetLineColor() == color && h->GetLineStyle() == style) { foundit = true; summaryfile << h->GetEntries(); @@ -1210,56 +1350,72 @@ void PlotAlignmentValidation::plotChi2(const char *inputFile) fi3.Close(); delete fi1; - } //------------------------------------------------------------------------------ -THStack* PlotAlignmentValidation::addHists(const TString& selection, const TString &residType, - TLegend **myLegend, bool printModuleIds, bool validforphase0) -{ +THStack* PlotAlignmentValidation::addHists( + const TString& selection, const TString& residType, TLegend** myLegend, bool printModuleIds, bool validforphase0) { enum ResidType { - xPrimeRes, yPrimeRes, xPrimeNormRes, yPrimeNormRes, xRes, yRes, xNormRes, /*yResNorm*/ - ResXvsXProfile, ResXvsYProfile, ResYvsXProfile, ResYvsYProfile + xPrimeRes, + yPrimeRes, + xPrimeNormRes, + yPrimeNormRes, + xRes, + yRes, + xNormRes, /*yResNorm*/ + ResXvsXProfile, + ResXvsYProfile, + ResYvsXProfile, + ResYvsYProfile }; ResidType rType = xPrimeRes; - if (residType == "xPrime") rType = xPrimeRes; - else if (residType == "yPrime") rType = yPrimeRes; - else if (residType == "xPrimeNorm") rType = xPrimeNormRes; - else if (residType == "yPrimeNorm") rType = yPrimeNormRes; - else if (residType == "x") rType = xRes; - else if (residType == "y") rType = yRes; - else if (residType == "xNorm") rType = xNormRes; + if (residType == "xPrime") + rType = xPrimeRes; + else if (residType == "yPrime") + rType = yPrimeRes; + else if (residType == "xPrimeNorm") + rType = xPrimeNormRes; + else if (residType == "yPrimeNorm") + rType = yPrimeNormRes; + else if (residType == "x") + rType = xRes; + else if (residType == "y") + rType = yRes; + else if (residType == "xNorm") + rType = xNormRes; // else if (residType == "yNorm") rType = yResNorm; - else if (residType == "ResXvsXProfile") rType = ResXvsXProfile; - else if (residType == "ResYvsXProfile") rType = ResYvsXProfile; - else if (residType == "ResXvsYProfile") rType = ResXvsYProfile; - else if (residType == "ResYvsYProfile") rType = ResYvsYProfile; + else if (residType == "ResXvsXProfile") + rType = ResXvsXProfile; + else if (residType == "ResYvsXProfile") + rType = ResYvsXProfile; + else if (residType == "ResXvsYProfile") + rType = ResXvsYProfile; + else if (residType == "ResYvsYProfile") + rType = ResYvsYProfile; else { - std::cout << "PlotAlignmentValidation::addHists: Unknown residual type " - << residType << std::endl; + std::cout << "PlotAlignmentValidation::addHists: Unknown residual type " << residType << std::endl; return 0; } cout << "PlotAlignmentValidation::addHists: using selection " << selection << endl; - THStack * retHistoStack = new THStack("hstack", ""); + THStack* retHistoStack = new THStack("hstack", ""); if (myLegend != 0) if (*myLegend == 0) { *myLegend = new TLegend(0.17, 0.80, 0.85, 0.88); } - for(std::vector::iterator itSourceFile = sourceList.begin(); - itSourceFile != sourceList.end(); ++itSourceFile) { - + for (std::vector::iterator itSourceFile = sourceList.begin(); itSourceFile != sourceList.end(); + ++itSourceFile) { std::vector histnames; - TFile *f = (*itSourceFile)->getFile(); - TTree *tree= (*itSourceFile)->getTree(); + TFile* f = (*itSourceFile)->getFile(); + TTree* tree = (*itSourceFile)->getTree(); int myLineColor = (*itSourceFile)->getLineColor(); int myLineStyle = (*itSourceFile)->getLineStyle(); TString myLegendName = (*itSourceFile)->getName(); - TH1 *h = 0; // becomes result - UInt_t nEmpty = 0;// selected, but empty hists - Long64_t nentries = tree->GetEntriesFast(); + TH1* h = 0; // becomes result + UInt_t nEmpty = 0; // selected, but empty hists + Long64_t nentries = tree->GetEntriesFast(); if (!f || !tree) { std::cout << "PlotAlignmentValidation::addHists: no tree or no file" << std::endl; return 0; @@ -1267,19 +1423,19 @@ THStack* PlotAlignmentValidation::addHists(const TString& selection, const TStri bool histnamesfilled = false; int phase = (bool)(f->Get("TrackerOfflineValidationStandalone/Pixel/P1PXBBarrel_1")); - if (residType.Contains("Res") && residType.Contains("Profile")) - { - TString basename = TString(residType).ReplaceAll("Res","p_res") - .ReplaceAll("vs","") - .ReplaceAll("Profile","_"); //gives e.g.: p_resXX_ + if (residType.Contains("Res") && residType.Contains("Profile")) { + TString basename = TString(residType) + .ReplaceAll("Res", "p_res") + .ReplaceAll("vs", "") + .ReplaceAll("Profile", "_"); //gives e.g.: p_resXX_ if (selection == "subDetId==1") { - if (phase==1) + if (phase == 1) histnames.push_back(TString(basename) += "P1PXBBarrel_1"); else histnames.push_back(TString(basename) += "TPBBarrel_1"); histnamesfilled = true; } else if (selection == "subDetId==2") { - if (phase==1) { + if (phase == 1) { histnames.push_back(TString(basename) += "P1PXECEndcap_2"); histnames.push_back(TString(basename) += "P1PXECEndcap_3"); } else { @@ -1297,7 +1453,7 @@ THStack* PlotAlignmentValidation::addHists(const TString& selection, const TStri } else if (selection == "subDetId==5") { histnames.push_back(TString(basename) += "TOBBarrel_4"); histnamesfilled = true; - } else if (selection == "subDetId==6") { //whole TEC - doesn't happen by default but easy enough to account for + } else if (selection == "subDetId==6") { //whole TEC - doesn't happen by default but easy enough to account for histnames.push_back(TString(basename) += "TECEndcap_5"); histnames.push_back(TString(basename) += "TECEndcap_6"); histnamesfilled = true; @@ -1307,16 +1463,13 @@ THStack* PlotAlignmentValidation::addHists(const TString& selection, const TStri for (int iDisk = 1; iDisk <= 9; iDisk++) for (int iSide = 1; iSide <= 2; iSide++) for (int iPetal = 1; iPetal <= 8; iPetal++) - for (int iRing = 1; iRing <= 4 - (iDisk>=4) - (iDisk>=7) - (iDisk>=9); iRing++) + for (int iRing = 1; iRing <= 4 - (iDisk >= 4) - (iDisk >= 7) - (iDisk >= 9); iRing++) //in the higher disks, the inner rings go away. But the numbering in the file structure removes the higher numbers // so the numbers there do not correspond to the actual ring numbers { stringstream s; - s << "TrackerOfflineValidationStandalone/Strip/TECEndcap_" << iEndcap - << "/TECDisk_" << iDisk - << "/TECSide_" << iSide - << "/TECPetal_" << iPetal - << "/" << basename << "TECRing_" << iRing; + s << "TrackerOfflineValidationStandalone/Strip/TECEndcap_" << iEndcap << "/TECDisk_" << iDisk + << "/TECSide_" << iSide << "/TECPetal_" << iPetal << "/" << basename << "TECRing_" << iRing; histnames.push_back(TString(s.str())); } histnamesfilled = true; @@ -1326,23 +1479,21 @@ THStack* PlotAlignmentValidation::addHists(const TString& selection, const TStri for (int iDisk = 1; iDisk <= 9; iDisk++) for (int iSide = 1; iSide <= 2; iSide++) for (int iPetal = 1; iPetal <= 8; iPetal++) - for (int iRing = 5 - (iDisk>=4) - (iDisk>=7) - (iDisk>=9); iRing <= 7 - (iDisk>=4) - (iDisk>=7) - (iDisk>=9); iRing++) + for (int iRing = 5 - (iDisk >= 4) - (iDisk >= 7) - (iDisk >= 9); + iRing <= 7 - (iDisk >= 4) - (iDisk >= 7) - (iDisk >= 9); + iRing++) //in the higher disks, the inner rings go away. But the numbering in the file structure removes the higher numbers // so the numbers there do not correspond to the actual ring numbers { stringstream s; - s << "TrackerOfflineValidationStandalone/Strip/TECEndcap_" << iEndcap - << "/TECDisk_" << iDisk - << "/TECSide_" << iSide - << "/TECPetal_" << iPetal - << "/" << basename << "TECRing_" << iRing; + s << "TrackerOfflineValidationStandalone/Strip/TECEndcap_" << iEndcap << "/TECDisk_" << iDisk + << "/TECSide_" << iSide << "/TECPetal_" << iPetal << "/" << basename << "TECRing_" << iRing; histnames.push_back(TString(s.str())); } histnamesfilled = true; } } - Long64_t nSel = 0; if (histnamesfilled && histnames.size() > 0) { nSel = (Long64_t)histnames.size(); @@ -1351,7 +1502,8 @@ THStack* PlotAlignmentValidation::addHists(const TString& selection, const TStri // first loop on tree to find out which entries (i.e. modules) fulfill the selection // 'Entry$' gives the entry number in the tree nSel = tree->Draw("Entry$", selection, "goff"); - if (nSel == -1) return 0; // error in selection + if (nSel == -1) + return 0; // error in selection if (nSel == 0) { std::cout << "PlotAlignmentValidation::addHists: no selected module." << std::endl; return 0; @@ -1363,56 +1515,79 @@ THStack* PlotAlignmentValidation::addHists(const TString& selection, const TStri // second loop on tree: // for each selected entry get the hist from the file and merge - TkOffTreeVariables *treeMem = 0; // ROOT will initialise + TkOffTreeVariables* treeMem = 0; // ROOT will initialise tree->SetBranchAddress("TkOffTreeVariables", &treeMem); - for (Long64_t i = 0; i < nentries; i++){ - if (i < *iterEnt - 0.1 // smaller index (with tolerance): skip - || iterEnt == selected.end()) { // at the end: skip - continue; + for (Long64_t i = 0; i < nentries; i++) { + if (i < *iterEnt - 0.1 // smaller index (with tolerance): skip + || iterEnt == selected.end()) { // at the end: skip + continue; } else if (TMath::Abs(i - *iterEnt) < 0.11) { - ++iterEnt; // take this entry! - } else std::cout << "Must not happen: " << i << " " << *iterEnt << std::endl; + ++iterEnt; // take this entry! + } else + std::cout << "Must not happen: " << i << " " << *iterEnt << std::endl; tree->GetEntry(i); if (printModuleIds) { - std::cout << treeMem->moduleId << ": " << treeMem->entries << " entries" << std::endl; + std::cout << treeMem->moduleId << ": " << treeMem->entries << " entries" << std::endl; } if (treeMem->entries <= 0) { // little speed up: skip empty hists - ++nEmpty; - continue; + ++nEmpty; + continue; } TString hName; - switch(rType) { - case xPrimeRes: hName = treeMem->histNameX.c_str(); break; - case yPrimeRes: hName = treeMem->histNameY.c_str(); break; - case xPrimeNormRes: hName = treeMem->histNameNormX.c_str(); break; - case yPrimeNormRes: hName = treeMem->histNameNormY.c_str(); break; - case xRes: hName = treeMem->histNameLocalX.c_str(); break; - case yRes: hName = treeMem->histNameLocalY.c_str(); break; - case xNormRes: hName = treeMem->histNameNormLocalX.c_str(); break; - /*case yResNorm: hName = treeMem->histNameNormLocalY.c_str(); break;*/ - case ResXvsXProfile: hName = treeMem->profileNameResXvsX.c_str(); break; - case ResXvsYProfile: hName = treeMem->profileNameResXvsY.c_str(); break; - case ResYvsXProfile: hName = treeMem->profileNameResYvsX.c_str(); break; - case ResYvsYProfile: hName = treeMem->profileNameResYvsY.c_str(); break; + switch (rType) { + case xPrimeRes: + hName = treeMem->histNameX.c_str(); + break; + case yPrimeRes: + hName = treeMem->histNameY.c_str(); + break; + case xPrimeNormRes: + hName = treeMem->histNameNormX.c_str(); + break; + case yPrimeNormRes: + hName = treeMem->histNameNormY.c_str(); + break; + case xRes: + hName = treeMem->histNameLocalX.c_str(); + break; + case yRes: + hName = treeMem->histNameLocalY.c_str(); + break; + case xNormRes: + hName = treeMem->histNameNormLocalX.c_str(); + break; + /*case yResNorm: hName = treeMem->histNameNormLocalY.c_str(); break;*/ + case ResXvsXProfile: + hName = treeMem->profileNameResXvsX.c_str(); + break; + case ResXvsYProfile: + hName = treeMem->profileNameResXvsY.c_str(); + break; + case ResYvsXProfile: + hName = treeMem->profileNameResYvsX.c_str(); + break; + case ResYvsYProfile: + hName = treeMem->profileNameResYvsY.c_str(); + break; } histnames.push_back(hName); } } - for (std::vector::iterator ithistname = histnames.begin(); - ithistname != histnames.end(); ++ithistname) { - if (phase == 0 && !validforphase0) break; - TH1 *newHist; + for (std::vector::iterator ithistname = histnames.begin(); ithistname != histnames.end(); ++ithistname) { + if (phase == 0 && !validforphase0) + break; + TH1* newHist; if (ithistname->Contains("/")) { newHist = (TH1*)f->Get(*ithistname); } else { - TKey *histKey = f->FindKeyAny(*ithistname); + TKey* histKey = f->FindKeyAny(*ithistname); newHist = (histKey ? static_cast(histKey->ReadObj()) : 0); } if (!newHist) { - std::cout << "Hist " << *ithistname << " not found in file, break loop." << std::endl; - break; + std::cout << "Hist " << *ithistname << " not found in file, break loop." << std::endl; + break; } if (newHist->GetEntries() == 0) { nEmpty++; @@ -1420,24 +1595,26 @@ THStack* PlotAlignmentValidation::addHists(const TString& selection, const TStri } newHist->SetLineColor(myLineColor); newHist->SetLineStyle(myLineStyle); - if (!h) { // first hist: clone, but rename keeping only first part of name - TString name(newHist->GetName()); - Ssiz_t pos_ = 0; - for (UInt_t i2 = 0; i2 < 3; ++i2) pos_ = name.Index("_", pos_+1); - name = name(0, pos_); // only up to three '_' - h = static_cast(newHist->Clone("summed_"+name)); - // TString myTitle = Form("%s: %lld modules", selection, nSel); - // h->SetTitle( myTitle ); - } else { // otherwise just add - h->Add(newHist); + if (!h) { // first hist: clone, but rename keeping only first part of name + TString name(newHist->GetName()); + Ssiz_t pos_ = 0; + for (UInt_t i2 = 0; i2 < 3; ++i2) + pos_ = name.Index("_", pos_ + 1); + name = name(0, pos_); // only up to three '_' + h = static_cast(newHist->Clone("summed_" + name)); + // TString myTitle = Form("%s: %lld modules", selection, nSel); + // h->SetTitle( myTitle ); + } else { // otherwise just add + h->Add(newHist); } delete newHist; } - std::cout << "PlotAlignmentValidation::addHists" << "Result is merged from " << nSel-nEmpty - << " hists, " << nEmpty << " hists were empty." << std::endl; + std::cout << "PlotAlignmentValidation::addHists" + << "Result is merged from " << nSel - nEmpty << " hists, " << nEmpty << " hists were empty." << std::endl; - if (nSel-nEmpty == 0) continue; + if (nSel - nEmpty == 0) + continue; if (myLegend != 0) (*myLegend)->AddEntry(h, myLegendName, "L"); @@ -1452,56 +1629,52 @@ THStack* PlotAlignmentValidation::addHists(const TString& selection, const TStri /*! \fn fitGauss * \brief Operate a Gaussian fit to the given histogram */ -TF1 * -PlotAlignmentValidation::fitGauss(TH1 *hist,int color) -{ +TF1* PlotAlignmentValidation::fitGauss(TH1* hist, int color) { //1. fits a Gauss function to the inner range of abs(2 rms) //2. repeates the Gauss fit in a 2 sigma range around mean of first fit //returns mean and sigma from fit in micron - if (!hist || hist->GetEntries() < 20) return 0; + if (!hist || hist->GetEntries() < 20) + return 0; - float mean = hist->GetMean(); + float mean = hist->GetMean(); float sigma = hist->GetRMS(); - string functionname="gaussian_"; - functionname+=hist->GetName(); - TF1 *func = new TF1(functionname.c_str(), "gaus", mean - 2.*sigma, mean + 2.*sigma); - + string functionname = "gaussian_"; + functionname += hist->GetName(); + TF1* func = new TF1(functionname.c_str(), "gaus", mean - 2. * sigma, mean + 2. * sigma); + func->SetLineColor(color); func->SetLineStyle(2); - if (0 == hist->Fit(func,"QNR")) { // N: do not blow up file by storing fit! - mean = func->GetParameter(1); + if (0 == hist->Fit(func, "QNR")) { // N: do not blow up file by storing fit! + mean = func->GetParameter(1); sigma = func->GetParameter(2); // second fit: three sigma of first fit around mean of first fit - func->SetRange(mean - 3.*sigma, mean + 3.*sigma); + func->SetRange(mean - 3. * sigma, mean + 3. * sigma); // I: integral gives more correct results if binning is too wide // L: Likelihood can treat empty bins correctly (if hist not weighted...) if (0 == hist->Fit(func, "Q0ILR")) { - if (hist->GetFunction(func->GetName())) { // Take care that it is later on drawn: - //hist->GetFunction(func->GetName())->ResetBit(TF1::kNotDraw); + if (hist->GetFunction(func->GetName())) { // Take care that it is later on drawn: + //hist->GetFunction(func->GetName())->ResetBit(TF1::kNotDraw); } } } return func; } - //------------------------------------------------------------------------------ /*! \fn storeHistogramInRootfile * \brief Store the histogram and the gaussian function resulting from the fitGauss function into a root file */ -void PlotAlignmentValidation::storeHistogramInRootfile(TH1* hist) -{ +void PlotAlignmentValidation::storeHistogramInRootfile(TH1* hist) { //Store histogram and fit function in the root summary file rootsummaryfile->cd(); hist->Write(); } //------------------------------------------------------------------------------ -void PlotAlignmentValidation::scaleXaxis(TH1* hist, Int_t scale) -{ +void PlotAlignmentValidation::scaleXaxis(TH1* hist, Int_t scale) { Double_t xmin = hist->GetXaxis()->GetXmin(); Double_t xmax = hist->GetXaxis()->GetXmax(); - hist->GetXaxis()->SetLimits(xmin*scale, xmax*scale); + hist->GetXaxis()->SetLimits(xmin * scale, xmax * scale); } //------------------------------------------------------------------------------ @@ -1511,7 +1684,7 @@ TObject* PlotAlignmentValidation::findObjectFromCanvas(TCanvas* canv, const char TObject* obj = 0; Int_t found = 0; while ((obj = next())) { - if(strncmp(obj->ClassName(), className, 10) == 0) { + if (strncmp(obj->ClassName(), className, 10) == 0) { if (++found == n) return obj; } @@ -1521,30 +1694,42 @@ TObject* PlotAlignmentValidation::findObjectFromCanvas(TCanvas* canv, const char } //------------------------------------------------------------------------------ -void PlotAlignmentValidation::setTitleStyle( TNamed &hist,const char* titleX, const char* titleY,int subDetId, bool isSurfaceDeformation, TString secondline) -{ +void PlotAlignmentValidation::setTitleStyle( + TNamed& hist, const char* titleX, const char* titleY, int subDetId, bool isSurfaceDeformation, TString secondline) { std::stringstream title_Xaxis; std::stringstream title_Yaxis; - TString titleXAxis=titleX; - TString titleYAxis=titleY; + TString titleXAxis = titleX; + TString titleYAxis = titleY; if (titleXAxis != "" && titleYAxis != "") - cout<<"plot "<SetFillStyle(0); text2->SetBorderSize(0); text2->SetMargin(0.01); - text2->SetTextAlign(12); // align left - text2->AddText(0.01,0.75,subD); + text2->SetTextAlign(12); // align left + text2->AddText(0.01, 0.75, subD); if (secondline != "") { text2->AddText(0.01, 0.25, secondline); } text2->Draw(); } - //------------------------------------------------------------------------------ /*! \fn * \brief */ -void PlotAlignmentValidation::setHistStyle( TH1& hist,const char* titleX, const char* titleY, int color) -{ +void PlotAlignmentValidation::setHistStyle(TH1& hist, const char* titleX, const char* titleY, int color) { std::stringstream title_Xaxis; std::stringstream title_Yaxis; - TString titleXAxis=titleX; - TString titleYAxis=titleY; - - if ( titleXAxis.Contains("Phi") )title_Xaxis<InheritsFrom( TH1F::Class() ) )hist.SetLineColor(color); - if (hist.IsA()->InheritsFrom( TProfile::Class() ) ) { + TString titleXAxis = titleX; + TString titleYAxis = titleY; + + if (titleXAxis.Contains("Phi")) + title_Xaxis << titleX << "[rad]"; + else if (titleXAxis.Contains("meanX")) + title_Xaxis << "#LTx'_{pred}-x'_{hit}#GT[#mum]"; + else if (titleXAxis.Contains("meanY")) + title_Xaxis << "#LTy'_{pred}-y'_{hit}#GT[#mum]"; + else if (titleXAxis.Contains("rmsX")) + title_Xaxis << "RMS(x'_{pred}-x'_{hit})[#mum]"; + else if (titleXAxis.Contains("rmsY")) + title_Xaxis << "RMS(y'_{pred}-y'_{hit})[#mum]"; + else if (titleXAxis.Contains("meanNormX")) + title_Xaxis << "#LTx'_{pred}-x'_{hit}/#sigma#GT"; + else if (titleXAxis.Contains("meanNormY")) + title_Xaxis << "#LTy'_{pred}-y'_{hit}/#sigma#GT"; + else if (titleXAxis.Contains("rmsNormX")) + title_Xaxis << "RMS(x'_{pred}-x'_{hit}/#sigma)"; + else if (titleXAxis.Contains("rmsNormY")) + title_Xaxis << "RMS(y'_{pred}-y'_{hit}/#sigma)"; + else if (titleXAxis.Contains("meanLocalX")) + title_Xaxis << "#LTx_{pred}-x_{hit}#GT[#mum]"; + else if (titleXAxis.Contains("rmsLocalX")) + title_Xaxis << "RMS(x_{pred}-x_{hit})[#mum]"; + else if (titleXAxis.Contains("meanNormLocalX")) + title_Xaxis << "#LTx_{pred}-x_{hit}/#sigma#GT[#mum]"; + else if (titleXAxis.Contains("rmsNormLocalX")) + title_Xaxis << "RMS(x_{pred}-x_{hit}/#sigma)[#mum]"; + else if (titleXAxis.Contains("medianX")) + title_Xaxis << "median(x'_{pred}-x'_{hit})[#mum]"; + else if (titleXAxis.Contains("medianY")) + title_Xaxis << "median(y'_{pred}-y'_{hit})[#mum]"; + else + title_Xaxis << titleX << "[cm]"; + + if (hist.IsA()->InheritsFrom(TH1F::Class())) + hist.SetLineColor(color); + if (hist.IsA()->InheritsFrom(TProfile::Class())) { hist.SetMarkerStyle(20); hist.SetMarkerSize(0.8); hist.SetMarkerColor(color); } - - hist.GetXaxis()->SetTitle( (title_Xaxis.str()).c_str() ); + + hist.GetXaxis()->SetTitle((title_Xaxis.str()).c_str()); double binning = (hist.GetXaxis()->GetXmax() - hist.GetXaxis()->GetXmin()) / hist.GetNbinsX(); title_Yaxis.precision(2); - if ( ((titleYAxis.Contains("layer") || titleYAxis.Contains("ring")) - && titleYAxis.Contains("subDetId")) - || titleYAxis.Contains("#modules")) { - title_Yaxis<<"number of modules"; + if (((titleYAxis.Contains("layer") || titleYAxis.Contains("ring")) && titleYAxis.Contains("subDetId")) || + titleYAxis.Contains("#modules")) { + title_Yaxis << "number of modules"; if (TString(title_Xaxis.str()).Contains("[#mum]")) title_Yaxis << " / " << binning << " #mum"; else if (TString(title_Xaxis.str()).Contains("[cm]")) title_Yaxis << " / " << binning << " cm"; else title_Yaxis << " / " << binning; - } - else title_Yaxis<SetTitle( (title_Yaxis.str()).c_str() ); + hist.GetYaxis()->SetTitle((title_Yaxis.str()).c_str()); hist.GetXaxis()->SetTitleFont(42); hist.GetYaxis()->SetTitleFont(42); } //------------------------------------------------------------------------------ -std::string PlotAlignmentValidation:: -getSelectionForDMRPlot(int minHits, int subDetId, int direction, int layer) -{ +std::string PlotAlignmentValidation::getSelectionForDMRPlot(int minHits, int subDetId, int direction, int layer) { std::ostringstream builder; builder << "entries >= " << minHits; builder << " && subDetId == " << subDetId; if (direction != 0) { - if (subDetId == 2) { // FPIX is split by zDirection + if (subDetId == 2) { // FPIX is split by zDirection builder << " && zDirection == " << direction; } else { builder << " && rDirection == " << direction; @@ -1644,21 +1841,19 @@ getSelectionForDMRPlot(int minHits, int subDetId, int direction, int layer) return builder.str(); } -std::string PlotAlignmentValidation:: -getVariableForDMRPlot(const std::string& histoname, const std::string& variable, int nbins, double min, - double max) -{ +std::string PlotAlignmentValidation::getVariableForDMRPlot( + const std::string& histoname, const std::string& variable, int nbins, double min, double max) { std::ostringstream builder; - builder << variable << ">>" << histoname << "(" << nbins << "," << min << - "," << max << ")"; + builder << variable << ">>" << histoname << "(" << nbins << "," << min << "," << max << ")"; return builder.str(); } //------------------------------------------------------------------------------ -void PlotAlignmentValidation:: -setDMRHistStyleAndLegend(TH1F* h, PlotAlignmentValidation::DMRPlotInfo& plotinfo, int direction, int layer) -{ - TF1 *fitResults = 0; +void PlotAlignmentValidation::setDMRHistStyleAndLegend(TH1F* h, + PlotAlignmentValidation::DMRPlotInfo& plotinfo, + int direction, + int layer) { + TF1* fitResults = 0; h->SetDirectory(0); @@ -1671,47 +1866,60 @@ setDMRHistStyleAndLegend(TH1F* h, PlotAlignmentValidation::DMRPlotInfo& plotinfo // -However if only direction split plots are to be plotted, the additions should be 0 and +1 respectively // -Modulo 4 arithmetic, because the styles run from 1..4 int linestyle = plotinfo.vars->getLineStyle() - 1, linestyleplus = 0; - if (direction == 1) { linestyleplus = 1; } - if (direction == -1) { linestyleplus = 2; } - if (direction != 0 && plotinfo.plotSplits && !plotinfo.plotPlain) { linestyleplus--; } + if (direction == 1) { + linestyleplus = 1; + } + if (direction == -1) { + linestyleplus = 2; + } + if (direction != 0 && plotinfo.plotSplits && !plotinfo.plotPlain) { + linestyleplus--; + } linestyle = (linestyle + linestyleplus) % 4 + 1; int linecolor = plotinfo.vars->getLineColor(); - if (plotinfo.plotLayers && layer > 0) { linecolor += layer - 1; } + if (plotinfo.plotLayers && layer > 0) { + linecolor += layer - 1; + } if (plotinfo.firsthisto) { - setHistStyle(*h, plotinfo.variable.c_str(), "#modules", 1); //set color later + setHistStyle(*h, plotinfo.variable.c_str(), "#modules", 1); //set color later plotinfo.firsthisto = false; } - h->SetLineColor( linecolor ); - h->SetLineStyle( linestyle ); - - if (plotinfo.maxYGetMaximum()){ - plotinfo.maxY=h->GetMaximum(); + h->SetLineColor(linecolor); + h->SetLineStyle(linestyle); + + if (plotinfo.maxY < h->GetMaximum()) { + plotinfo.maxY = h->GetMaximum(); } - + //fit histogram for median and mean - if (plotinfo.variable == "medianX" || plotinfo.variable == "meanX" || plotinfo.variable == "medianY" || plotinfo.variable == "meanY") { - fitResults = fitGauss(h, linecolor ); + if (plotinfo.variable == "medianX" || plotinfo.variable == "meanX" || plotinfo.variable == "medianY" || + plotinfo.variable == "meanY") { + fitResults = fitGauss(h, linecolor); } - + plotinfo.hstack->Add(h); std::ostringstream legend; legend.precision(3); - legend << fixed; // to always show 3 decimals + legend << fixed; // to always show 3 decimals // Legend: header part - if (direction == -1 && plotinfo.subDetId != 2) { legend << "rDirection < 0"; } - else if (direction == 1 && plotinfo.subDetId != 2) { legend << "rDirection > 0"; } - else if (direction == -1 && plotinfo.subDetId == 2) { legend << "zDirection < 0"; } - else if (direction == 1 && plotinfo.subDetId == 2) { legend << "zDirection > 0"; } - else { - legend << plotinfo.vars->getName(); + if (direction == -1 && plotinfo.subDetId != 2) { + legend << "rDirection < 0"; + } else if (direction == 1 && plotinfo.subDetId != 2) { + legend << "rDirection > 0"; + } else if (direction == -1 && plotinfo.subDetId == 2) { + legend << "zDirection < 0"; + } else if (direction == 1 && plotinfo.subDetId == 2) { + legend << "zDirection > 0"; + } else { + legend << plotinfo.vars->getName(); if (layer > 0) { // TEC and TID have discs, the rest have layers - if (plotinfo.subDetId==4 || plotinfo.subDetId==6) + if (plotinfo.subDetId == 4 || plotinfo.subDetId == 6) legend << ", disc "; else legend << ", layer "; @@ -1725,27 +1933,27 @@ setDMRHistStyleAndLegend(TH1F* h, PlotAlignmentValidation::DMRPlotInfo& plotinfo // Legend: Statistics double mean, meanerror, rms, rmserror; TString rmsname, units; - bool showdeltamu = (plotinfo.h1 != 0 && plotinfo.h2 != 0 && plotinfo.plotSplits && plotinfo.plotPlain && direction == 0); - if (plotinfo.variable == "medianX" || plotinfo.variable == "meanX" || - plotinfo.variable == "medianY" || plotinfo.variable == "meanY" || - plotinfo.variable == "rmsX" || plotinfo.variable == "rmsY") { + bool showdeltamu = + (plotinfo.h1 != 0 && plotinfo.h2 != 0 && plotinfo.plotSplits && plotinfo.plotPlain && direction == 0); + if (plotinfo.variable == "medianX" || plotinfo.variable == "meanX" || plotinfo.variable == "medianY" || + plotinfo.variable == "meanY" || plotinfo.variable == "rmsX" || plotinfo.variable == "rmsY") { if (useFit_ && fitResults) { - mean = fitResults->GetParameter(1)*10000; - meanerror = fitResults->GetParError(1)*10000; - rms = fitResults->GetParameter(2)*10000; - rmserror = fitResults->GetParError(2)*10000; + mean = fitResults->GetParameter(1) * 10000; + meanerror = fitResults->GetParError(1) * 10000; + rms = fitResults->GetParameter(2) * 10000; + rmserror = fitResults->GetParError(2) * 10000; rmsname = "#sigma"; delete fitResults; } else { - mean = h->GetMean(1)*10000; - meanerror = h->GetMeanError(1)*10000; - rms = h->GetRMS(1)*10000; - rmserror = h->GetRMSError(1)*10000; + mean = h->GetMean(1) * 10000; + meanerror = h->GetMeanError(1) * 10000; + rms = h->GetRMS(1) * 10000; + rmserror = h->GetRMSError(1) * 10000; rmsname = "rms"; } units = " #mum"; - } else if (plotinfo.variable == "meanNormX" || plotinfo.variable == "meanNormY" || - plotinfo.variable == "rmsNormX" || plotinfo.variable == "rmsNormY") { + } else if (plotinfo.variable == "meanNormX" || plotinfo.variable == "meanNormY" || plotinfo.variable == "rmsNormX" || + plotinfo.variable == "rmsNormY") { mean = h->GetMean(1); meanerror = h->GetMeanError(1); rms = h->GetRMS(1); @@ -1753,8 +1961,7 @@ setDMRHistStyleAndLegend(TH1F* h, PlotAlignmentValidation::DMRPlotInfo& plotinfo rmsname = "rms"; units = ""; } - if (showMean_) - { + if (showMean_) { legend << " #mu = " << mean; if (showMeanError_) legend << " #pm " << meanerror; @@ -1762,8 +1969,7 @@ setDMRHistStyleAndLegend(TH1F* h, PlotAlignmentValidation::DMRPlotInfo& plotinfo if (showRMS_ || showdeltamu || ((showModules_ || showUnderOverFlow_) && !twolines_)) legend << ", "; } - if (showRMS_) - { + if (showRMS_) { legend << " " << rmsname << " = " << rms; if (showRMSError_) legend << " #pm " << rmserror; @@ -1772,44 +1978,42 @@ setDMRHistStyleAndLegend(TH1F* h, PlotAlignmentValidation::DMRPlotInfo& plotinfo legend << ", "; } - if ((plotinfo.variable == "medianX" || plotinfo.variable == "medianY") && /*!plotinfo.plotLayers && */layer==0 && direction==0) { + if ((plotinfo.variable == "medianX" || plotinfo.variable == "medianY") && /*!plotinfo.plotLayers && */ layer == 0 && + direction == 0) { vmean.push_back(mean); vrms.push_back(rms); vmeanerror.push_back(meanerror); - TH1F* ideal = (TH1F*)plotinfo.hstack->GetHists()->At(0); - TH1F* h = plotinfo.h; - if(h->GetRMS() >= ideal->GetRMS()) - { - vAlignmentUncertainty.push_back(sqrt(pow(h->GetRMS(),2)-pow(ideal->GetRMS(),2))); - } - else{ - vAlignmentUncertainty.push_back(nan("")); - } - float p = (float)resampleTestOfEqualMeans(ideal, h, 10000); - vPValueMeanEqualIdeal.push_back(p); - p=resampleTestOfEqualRMS(ideal, h, 10000); - vPValueRMSEqualIdeal.push_back(p); - + TH1F* ideal = (TH1F*)plotinfo.hstack->GetHists()->At(0); + TH1F* h = plotinfo.h; + if (h->GetRMS() >= ideal->GetRMS()) { + vAlignmentUncertainty.push_back(sqrt(pow(h->GetRMS(), 2) - pow(ideal->GetRMS(), 2))); + } else { + vAlignmentUncertainty.push_back(nan("")); + } + float p = (float)resampleTestOfEqualMeans(ideal, h, 10000); + vPValueMeanEqualIdeal.push_back(p); + p = resampleTestOfEqualRMS(ideal, h, 10000); + vPValueRMSEqualIdeal.push_back(p); } // Legend: Delta mu for split plots if (showdeltamu) { float factor = 10000.0f; - if (plotinfo.variable == "meanNormX" || plotinfo.variable == "meanNormY" || - plotinfo.variable == "rmsNormX" || plotinfo.variable == "rmsNormY") { + if (plotinfo.variable == "meanNormX" || plotinfo.variable == "meanNormY" || plotinfo.variable == "rmsNormX" || + plotinfo.variable == "rmsNormY") { factor = 1.0f; } - float deltamu = factor*(plotinfo.h2->GetMean(1) - plotinfo.h1->GetMean(1)); + float deltamu = factor * (plotinfo.h2->GetMean(1) - plotinfo.h1->GetMean(1)); legend << "#Delta#mu = " << deltamu << units; if ((showModules_ || showUnderOverFlow_) && !twolines_) legend << ", "; - if ((plotinfo.variable == "medianX" || plotinfo.variable == "medianY") && /*!plotinfo.plotLayers && */layer==0 && direction==0) { + if ((plotinfo.variable == "medianX" || plotinfo.variable == "medianY") && /*!plotinfo.plotLayers && */ layer == 0 && + direction == 0) { vdeltamean.push_back(deltamu); - if(plotinfo.h1->GetEntries()&&plotinfo.h2->GetEntries()){ - float p = (float)resampleTestOfEqualMeans(plotinfo.h1,plotinfo.h2, 10000); - vPValueEqualSplitMeans.push_back(p); - + if (plotinfo.h1->GetEntries() && plotinfo.h2->GetEntries()) { + float p = (float)resampleTestOfEqualMeans(plotinfo.h1, plotinfo.h2, 10000); + vPValueEqualSplitMeans.push_back(p); } } } @@ -1821,13 +2025,14 @@ setDMRHistStyleAndLegend(TH1F* h, PlotAlignmentValidation::DMRPlotInfo& plotinfo } if (!showUnderOverFlow_ && showModules_) { - legend << (int) h->GetEntries() << " modules"; + legend << (int)h->GetEntries() << " modules"; } if (showUnderOverFlow_) { if (showModules_) { - legend << (int) h->GetEntries() << " modules (" << (int) h->GetBinContent(0) + (int)h->GetBinContent(h->GetNbinsX()+1) << " outside range)"; + legend << (int)h->GetEntries() << " modules (" + << (int)h->GetBinContent(0) + (int)h->GetBinContent(h->GetNbinsX() + 1) << " outside range)"; } else { - legend << (int) h->GetBinContent(0) + (int)h->GetBinContent(h->GetNbinsX()+1) << " modules outside range"; + legend << (int)h->GetBinContent(0) + (int)h->GetBinContent(h->GetNbinsX() + 1) << " modules outside range"; } } plotinfo.legend->AddEntry((TObject*)0, legend.str().c_str(), ""); @@ -1835,7 +2040,6 @@ setDMRHistStyleAndLegend(TH1F* h, PlotAlignmentValidation::DMRPlotInfo& plotinfo // Scale the x-axis (cm to um), if needed if (plotinfo.variable.find("Norm") == std::string::npos) scaleXaxis(h, 10000); - } /*! @@ -1843,60 +2047,81 @@ setDMRHistStyleAndLegend(TH1F* h, PlotAlignmentValidation::DMRPlotInfo& plotinfo * \brief Create the DMR histrogram using data stored in trees and store them in the plotinfo structure. */ -void PlotAlignmentValidation:: -plotDMRHistogram(PlotAlignmentValidation::DMRPlotInfo& plotinfo, int direction, int layer, std::string subdet) -{ +void PlotAlignmentValidation::plotDMRHistogram(PlotAlignmentValidation::DMRPlotInfo& plotinfo, + int direction, + int layer, + std::string subdet) { TH1F* h = 0; //Create a name for the histogram that summarize all relevant information: name of the geometry, variable plotted, structure, layer, and whether the modules considered point inward or outward. - TString histoname=""; - if(plotinfo.variable == "medianX" || plotinfo.variable == "medianY" )histoname="median"; - else if(plotinfo.variable == "rmsNormX" || plotinfo.variable == "rmsNormY")histoname="DrmsNR"; - histoname+="_"; histoname+=plotinfo.vars->getName(); - histoname.ReplaceAll(" ","_"); - histoname+="_"; histoname+=subdet.c_str(); - if (plotinfo.variable == "medianY" || plotinfo.variable == "rmsNormY")histoname+="_y"; - if(layer!=0){ - if(subdet=="TID"||subdet=="TEC")histoname+="_disc"; - else histoname+="_layer"; - histoname+=to_string(layer); - } - if (direction == -1) { histoname += "_minus"; } - else if (direction == 1) { histoname += "_plus"; } - else { histoname += ""; } - std::string plotVariable = getVariableForDMRPlot(histoname.Data(), plotinfo.variable, plotinfo.nbins, plotinfo.min, plotinfo.max); + TString histoname = ""; + if (plotinfo.variable == "medianX" || plotinfo.variable == "medianY") + histoname = "median"; + else if (plotinfo.variable == "rmsNormX" || plotinfo.variable == "rmsNormY") + histoname = "DrmsNR"; + histoname += "_"; + histoname += plotinfo.vars->getName(); + histoname.ReplaceAll(" ", "_"); + histoname += "_"; + histoname += subdet.c_str(); + if (plotinfo.variable == "medianY" || plotinfo.variable == "rmsNormY") + histoname += "_y"; + if (layer != 0) { + if (subdet == "TID" || subdet == "TEC") + histoname += "_disc"; + else + histoname += "_layer"; + histoname += to_string(layer); + } + if (direction == -1) { + histoname += "_minus"; + } else if (direction == 1) { + histoname += "_plus"; + } else { + histoname += ""; + } + std::string plotVariable = + getVariableForDMRPlot(histoname.Data(), plotinfo.variable, plotinfo.nbins, plotinfo.min, plotinfo.max); std::string selection = getSelectionForDMRPlot(plotinfo.minHits, plotinfo.subDetId, direction, layer); plotinfo.vars->getTree()->Draw(plotVariable.c_str(), selection.c_str(), "goff"); - if (gDirectory) gDirectory->GetObject(histoname.Data(), h); + if (gDirectory) + gDirectory->GetObject(histoname.Data(), h); if (h && h->GetEntries() > 0) { - if (direction == -1) { plotinfo.h1 = h; } - else if (direction == 1) { plotinfo.h2 = h; } - else { plotinfo.h = h; } + if (direction == -1) { + plotinfo.h1 = h; + } else if (direction == 1) { + plotinfo.h2 = h; + } else { + plotinfo.h = h; + } } - if(plotinfo.variable == "medianX" || plotinfo.variable == "medianY" || plotinfo.variable == "rmsNormX" || plotinfo.variable == "rmsNormY") + if (plotinfo.variable == "medianX" || plotinfo.variable == "medianY" || plotinfo.variable == "rmsNormX" || + plotinfo.variable == "rmsNormY") storeHistogramInRootfile(h); - } -void PlotAlignmentValidation::modifySSHistAndLegend(THStack* hs, TLegend* legend) -{ +void PlotAlignmentValidation::modifySSHistAndLegend(THStack* hs, TLegend* legend) { // Add mean-y-values to the legend and scale the histograms. Double_t legendY = 0.80; bool hasheader = (TkAlStyle::legendheader != ""); - if (hasheader) legend->SetHeader(TkAlStyle::legendheader); + if (hasheader) + legend->SetHeader(TkAlStyle::legendheader); legend->SetFillStyle(0); int legendsize = hs->GetHists()->GetSize() + hasheader; if (legendsize > 3) legendY -= 0.01 * (legendsize - 3); - if (bigtext_) { legendY -= 0.05; } + if (bigtext_) { + legendY -= 0.05; + } if (legendY < 0.6) { std::cerr << "Warning: Huge legend!" << std::endl; legendY = 0.6; } legend->SetY1(legendY); - if (bigtext_) legend->SetTextSize(TkAlStyle::textSize); + if (bigtext_) + legend->SetTextSize(TkAlStyle::textSize); // Loop over all profiles TProfile* prof = 0; @@ -1912,8 +2137,8 @@ void PlotAlignmentValidation::modifySSHistAndLegend(THStack* hs, TLegend* legend std::ostringstream legendtext; legendtext.precision(3); - legendtext << fixed; // to always show 3 decimals - legendtext << ": y mean = " << stats[4]/stats[0]*scale << " #mum"; + legendtext << fixed; // to always show 3 decimals + legendtext << ": y mean = " << stats[4] / stats[0] * scale << " #mum"; TLegendEntry* entry = (TLegendEntry*)legend->GetListOfPrimitives()->At(index); if (entry == 0) @@ -1924,58 +2149,55 @@ void PlotAlignmentValidation::modifySSHistAndLegend(THStack* hs, TLegend* legend } // Make some room for the legend - hs->SetMaximum(hs->GetMaximum("nostack PE")*1.3); + hs->SetMaximum(hs->GetMaximum("nostack PE") * 1.3); } - //random variable: \sigma_{X_1}-\sigma_{X_2}-\delta_{RMS} //is centered approx around 0 //null hypothesis: \delta_{RMS}=0 //so \delta_\sigma is a realization of this random variable //how probable is it to get our value of \delta_\sigma? //->p-value -double PlotAlignmentValidation::resampleTestOfEqualRMS(TH1F* h1, TH1F* h2, int numSamples){ -//vector to store realizations of random variable - vector diff; - diff.clear(); -//"true" (in bootstrap terms) difference of the samples' RMS - double rmsdiff = abs(h1->GetRMS()-h2->GetRMS()); -//means of the samples to calculate RMS - double m1 = h1->GetMean(); - double m2 = h2->GetMean(); -//realization of random variable - double d1 = 0; - double d2 = 0; -//mean of random variable - double test_mean=0; - for(int i=0;iGetEntries();i++){ - d1+=h1->GetRandom()-m1; - } - for(int i=0;iGetEntries();i++){ - d2+=h2->GetRandom()+m2; - } - d1/=h1->GetEntries(); - d2/=h2->GetEntries(); - diff.push_back(abs(d1-d2-rmsdiff)); - test_mean+=abs(d1-d2-rmsdiff); +double PlotAlignmentValidation::resampleTestOfEqualRMS(TH1F* h1, TH1F* h2, int numSamples) { + //vector to store realizations of random variable + vector diff; + diff.clear(); + //"true" (in bootstrap terms) difference of the samples' RMS + double rmsdiff = abs(h1->GetRMS() - h2->GetRMS()); + //means of the samples to calculate RMS + double m1 = h1->GetMean(); + double m2 = h2->GetMean(); + //realization of random variable + double d1 = 0; + double d2 = 0; + //mean of random variable + double test_mean = 0; + for (int i = 0; i < numSamples; i++) { + d1 = 0; + d2 = 0; + for (int i = 0; i < h1->GetEntries(); i++) { + d1 += h1->GetRandom() - m1; } - test_mean/=numSamples; -//p value - double p=0; - for(double d:diff){ - if(d>rmsdiff){ - p+=1; - } + for (int i = 0; i < h2->GetEntries(); i++) { + d2 += h2->GetRandom() + m2; } - - p/=numSamples; - return p; -} - + d1 /= h1->GetEntries(); + d2 /= h2->GetEntries(); + diff.push_back(abs(d1 - d2 - rmsdiff)); + test_mean += abs(d1 - d2 - rmsdiff); + } + test_mean /= numSamples; + //p value + double p = 0; + for (double d : diff) { + if (d > rmsdiff) { + p += 1; + } + } + p /= numSamples; + return p; +} //random variable: (\overline{X_1}-\mu_1)-(\overline{X_2}-\mu_2) //is centered approx around 0 @@ -1983,150 +2205,137 @@ double PlotAlignmentValidation::resampleTestOfEqualRMS(TH1F* h1, TH1F* h2, int n //so \delta_\mu is a realization of this random variable //how probable is it to get our value of \delta_\mu? //->p-value -double PlotAlignmentValidation::resampleTestOfEqualMeans(TH1F* h1, TH1F* h2, int numSamples){ -//vector to store realization of random variable - vector diff; - diff.clear(); -//"true" (in bootstrap terms) difference of the samples' means - double meandiff = abs(h1->GetMean()-h2->GetMean()); -//realization of random variable - double d1 = 0; - double d2=0; -//mean of random variable - double test_mean=0; - for(int i=0;iGetEntries();i++){ - d1+=h1->GetRandom(); - } - for(int i=0;iGetEntries();i++){ - d2+=h2->GetRandom(); - } - d1/=h1->GetEntries(); - d2/=h2->GetEntries(); - diff.push_back(abs(d1-d2-meandiff)); - test_mean+=abs(d1-d2-meandiff); +double PlotAlignmentValidation::resampleTestOfEqualMeans(TH1F* h1, TH1F* h2, int numSamples) { + //vector to store realization of random variable + vector diff; + diff.clear(); + //"true" (in bootstrap terms) difference of the samples' means + double meandiff = abs(h1->GetMean() - h2->GetMean()); + //realization of random variable + double d1 = 0; + double d2 = 0; + //mean of random variable + double test_mean = 0; + for (int i = 0; i < numSamples; i++) { + d1 = 0; + d2 = 0; + for (int i = 0; i < h1->GetEntries(); i++) { + d1 += h1->GetRandom(); } - test_mean/=numSamples; -//p-value - double p=0; - for(double d:diff){ - if(d>meandiff){ - p+=1; - } + for (int i = 0; i < h2->GetEntries(); i++) { + d2 += h2->GetRandom(); } - - p/=numSamples; - return p; -} - + d1 /= h1->GetEntries(); + d2 /= h2->GetEntries(); + diff.push_back(abs(d1 - d2 - meandiff)); + test_mean += abs(d1 - d2 - meandiff); + } + test_mean /= numSamples; + //p-value + double p = 0; + for (double d : diff) { + if (d > meandiff) { + p += 1; + } + } + p /= numSamples; + return p; +} -float PlotAlignmentValidation::twotailedStudentTTestEqualMean(float t, float v){ -return 2*(1-ROOT::Math::tdistribution_cdf(abs(t),v)); +float PlotAlignmentValidation::twotailedStudentTTestEqualMean(float t, float v) { + return 2 * (1 - ROOT::Math::tdistribution_cdf(abs(t), v)); } const TString PlotAlignmentValidation::summaryfilename = "OfflineValidationSummary"; +vector 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 (unsigned int i = 0; i < number_of_entries; i++) { + t->GetEntry(i); + if (variables->moduleId == moduleid) { + histnamex = variables->histNameX; + histnamey = variables->histNameY; + break; + } + } + vector h; -vector 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 (unsigned int i=0;iGetEntry(i); - if (variables->moduleId==moduleid){ - histnamex=variables->histNameX; - histnamey=variables->histNameY; - break; - } - } - - vector 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 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"); - + 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 hist = findmodule(file, moduleid); + + TString histnamex = legendname + " NEntries: " + TString(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: " + TString(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(TString(outputDir + "/") + filenamex + ".root"); + cx->SaveAs(TString(outputDir + "/") + filenamex + ".pdf"); + cx->SaveAs(TString(outputDir + "/") + filenamex + ".png"); + cx->SaveAs(TString(outputDir + "/") + filenamex + ".eps"); + + cy->cd(); + legendy->Draw(); + cy->SaveAs(TString(outputDir + "/") + filenamey + ".root"); + cy->SaveAs(TString(outputDir + "/") + filenamey + ".pdf"); + cy->SaveAs(TString(outputDir + "/") + filenamey + ".png"); + cy->SaveAs(TString(outputDir + "/") + filenamey + ".eps"); } diff --git a/Alignment/OfflineValidation/macros/trackSplitPlot.h b/Alignment/OfflineValidation/macros/trackSplitPlot.h index 123208cc73b90..a75958e2f6592 100644 --- a/Alignment/OfflineValidation/macros/trackSplitPlot.h +++ b/Alignment/OfflineValidation/macros/trackSplitPlot.h @@ -9,6 +9,7 @@ #include "TClass.h" #include "TColor.h" #include "TFile.h" +#include "TF1.h" #include "TGaxis.h" #include "TGraph2DErrors.h" #include "TGraphErrors.h" @@ -29,9 +30,8 @@ #include "TText.h" #include "TTree.h" - -enum PlotType {ScatterPlot,Profile,Histogram,OrgHistogram,Resolution}; -enum Statistic {Minimum, Maximum, Average, RMS}; +enum PlotType { ScatterPlot, Profile, Histogram, OrgHistogram, Resolution }; +enum Statistic { Minimum, Maximum, Average, RMS }; const Double_t pi = TMath::Pi(); vector colors; @@ -45,15 +45,15 @@ Int_t legendGrid = 100; Double_t margin = .1; Double_t increaseby = .1; -TString xvariables[xsize] = {"", "pt", "eta", "phi", "dz", "dxy", "theta", "qoverpt"}; -TString yvariables[ysize] = {"pt", "pt", "eta", "phi", "dz", "dxy", "theta", "qoverpt", ""}; -Bool_t relativearray[ysize] = {true, false, false, false, false, false, false, false, false}; +TString xvariables[xsize] = {"", "pt", "eta", "phi", "dz", "dxy", "theta", "qoverpt"}; +TString yvariables[ysize] = {"pt", "pt", "eta", "phi", "dz", "dxy", "theta", "qoverpt", ""}; +Bool_t relativearray[ysize] = {true, false, false, false, false, false, false, false, false}; TList *stufftodelete = new TList(); TString subdetector = "PIXEL"; -double outliercut = 0.99; //use the middle 99% of tracks to find the mean and RMS - //(a few tracks are fit badly and skew them otherwise) +double outliercut = 0.99; //use the middle 99% of tracks to find the mean and RMS + //(a few tracks are fit badly and skew them otherwise) /*********************************** Table Of Contents @@ -68,136 +68,335 @@ Table Of Contents #include "trackSplitPlot.h" ofstream devnull("/dev/null"); -template T identity(T t) {return t;} +template +T identity(T t) { + return t; +} //=================== //0. Track Split Plot //=================== -TCanvas *trackSplitPlot(Int_t nFiles,TString *files,TString *names,TString xvar,TString yvar, - Bool_t relative = false,Bool_t resolution = false,Bool_t pull = false, - TString saveas = "", ostream& summaryfile=devnull); -TCanvas *trackSplitPlot(Int_t nFiles,TString *files,TString *names,TString var, - Bool_t relative = false,Bool_t pull = false,TString saveas = "", ostream& summaryfile=devnull); -TCanvas *trackSplitPlot(TString file,TString xvar,TString yvar,Bool_t profile = false, - Bool_t relative = false,Bool_t resolution = false,Bool_t pull = false, - TString saveas = "", ostream& summaryfile=devnull); -TCanvas *trackSplitPlot(TString file,TString var, - Bool_t relative = false,Bool_t pull = false, - TString saveas = "", ostream& summaryfile=devnull); -void placeholder(TString saveas = "",Bool_t wide = false); -void saveplot(TCanvas *c1,TString saveas); +TCanvas *trackSplitPlot(Int_t nFiles, + TString *files, + TString *names, + TString xvar, + TString yvar, + Bool_t relative = false, + Bool_t resolution = false, + Bool_t pull = false, + TString saveas = "", + ostream &summaryfile = devnull); +TCanvas *trackSplitPlot(Int_t nFiles, + TString *files, + TString *names, + TString var, + Bool_t relative = false, + Bool_t pull = false, + TString saveas = "", + ostream &summaryfile = devnull); +TCanvas *trackSplitPlot(TString file, + TString xvar, + TString yvar, + Bool_t profile = false, + Bool_t relative = false, + Bool_t resolution = false, + Bool_t pull = false, + TString saveas = "", + ostream &summaryfile = devnull); +TCanvas *trackSplitPlot(TString file, + TString var, + Bool_t relative = false, + Bool_t pull = false, + TString saveas = "", + ostream &summaryfile = devnull); +void placeholder(TString saveas = "", Bool_t wide = false); +void saveplot(TCanvas *c1, TString saveas); void deleteCanvas(TObject *canvas); void setupcolors(); -void runNumberZoomed(Int_t nFiles,TString *files,TString *names,TString yvar, - Bool_t relative = false,Bool_t resolution = false,Bool_t pull = false, - Int_t firstRun = -1,Int_t lastRun = -1,TString saveas = ""); +void runNumberZoomed(Int_t nFiles, + TString *files, + TString *names, + TString yvar, + Bool_t relative = false, + Bool_t resolution = false, + Bool_t pull = false, + Int_t firstRun = -1, + Int_t lastRun = -1, + TString saveas = ""); //========================== //1. Misalignment Dependence //========================== void misalignmentDependence(TCanvas *c1old, - Int_t nFiles,TString *names,TString misalignment,Double_t *values,Double_t *phases,TString xvar,TString yvar, - TF1 *function,Int_t parameter,TString parametername = "",TString functionname = "", - Bool_t relative = false,Bool_t resolution = false,Bool_t pull = false, + Int_t nFiles, + TString *names, + TString misalignment, + Double_t *values, + Double_t *phases, + TString xvar, + TString yvar, + TF1 *function, + Int_t parameter, + TString parametername = "", + TString functionname = "", + Bool_t relative = false, + Bool_t resolution = false, + Bool_t pull = false, TString saveas = ""); void misalignmentDependence(TCanvas *c1old, - Int_t nFiles,TString *names,TString misalignment,Double_t *values,Double_t *phases,TString xvar,TString yvar, - TF1 *function,Int_t nParameters,Int_t *parameters,TString *parameternames,TString functionname = "", - Bool_t relative = false,Bool_t resolution = false,Bool_t pull = false, + Int_t nFiles, + TString *names, + TString misalignment, + Double_t *values, + Double_t *phases, + TString xvar, + TString yvar, + TF1 *function, + Int_t nParameters, + Int_t *parameters, + TString *parameternames, + TString functionname = "", + Bool_t relative = false, + Bool_t resolution = false, + Bool_t pull = false, TString saveas = ""); -void misalignmentDependence(Int_t nFiles,TString *files,TString *names,TString misalignment,Double_t *values,Double_t *phases,TString xvar,TString yvar, - TF1 *function,Int_t parameter,TString parametername = "",TString functionname = "", - Bool_t relative = false,Bool_t resolution = false,Bool_t pull = false, +void misalignmentDependence(Int_t nFiles, + TString *files, + TString *names, + TString misalignment, + Double_t *values, + Double_t *phases, + TString xvar, + TString yvar, + TF1 *function, + Int_t parameter, + TString parametername = "", + TString functionname = "", + Bool_t relative = false, + Bool_t resolution = false, + Bool_t pull = false, TString saveas = ""); -void misalignmentDependence(Int_t nFiles,TString *files,TString *names,TString misalignment,Double_t *values,Double_t *phases,TString xvar,TString yvar, - TF1 *function,Int_t nParameters,Int_t *parameters,TString *parameternames,TString functionname = "", - Bool_t relative = false,Bool_t resolution = false,Bool_t pull = false, +void misalignmentDependence(Int_t nFiles, + TString *files, + TString *names, + TString misalignment, + Double_t *values, + Double_t *phases, + TString xvar, + TString yvar, + TF1 *function, + Int_t nParameters, + Int_t *parameters, + TString *parameternames, + TString functionname = "", + Bool_t relative = false, + Bool_t resolution = false, + Bool_t pull = false, TString saveas = ""); void misalignmentDependence(TCanvas *c1old, - Int_t nFiles,TString *names,TString misalignment,Double_t *values,Double_t *phases,TString xvar,TString yvar, - TString function,Int_t parameter,TString parametername = "",TString functionname = "", - Bool_t relative = false,Bool_t resolution = false,Bool_t pull = false, + Int_t nFiles, + TString *names, + TString misalignment, + Double_t *values, + Double_t *phases, + TString xvar, + TString yvar, + TString function, + Int_t parameter, + TString parametername = "", + TString functionname = "", + Bool_t relative = false, + Bool_t resolution = false, + Bool_t pull = false, TString saveas = ""); void misalignmentDependence(TCanvas *c1old, - Int_t nFiles,TString *names,TString misalignment,Double_t *values,Double_t *phases,TString xvar,TString yvar, - TString function,Int_t nParameters,Int_t *parameters,TString *parameternames,TString functionname = "", - Bool_t relative = false,Bool_t resolution = false,Bool_t pull = false, + Int_t nFiles, + TString *names, + TString misalignment, + Double_t *values, + Double_t *phases, + TString xvar, + TString yvar, + TString function, + Int_t nParameters, + Int_t *parameters, + TString *parameternames, + TString functionname = "", + Bool_t relative = false, + Bool_t resolution = false, + Bool_t pull = false, TString saveas = ""); -void misalignmentDependence(Int_t nFiles,TString *files,TString *names,TString misalignment,Double_t *values,Double_t *phases,TString xvar,TString yvar, - TString function,Int_t parameter,TString parametername = "",TString functionname = "", - Bool_t relative = false,Bool_t resolution = false,Bool_t pull = false, +void misalignmentDependence(Int_t nFiles, + TString *files, + TString *names, + TString misalignment, + Double_t *values, + Double_t *phases, + TString xvar, + TString yvar, + TString function, + Int_t parameter, + TString parametername = "", + TString functionname = "", + Bool_t relative = false, + Bool_t resolution = false, + Bool_t pull = false, TString saveas = ""); -void misalignmentDependence(Int_t nFiles,TString *files,TString *names,TString misalignment,Double_t *values,Double_t *phases,TString xvar,TString yvar, - TString function,Int_t nParameters,Int_t *parameters,TString *parameternames,TString functionname = "", - Bool_t relative = false,Bool_t resolution = false,Bool_t pull = false, +void misalignmentDependence(Int_t nFiles, + TString *files, + TString *names, + TString misalignment, + Double_t *values, + Double_t *phases, + TString xvar, + TString yvar, + TString function, + Int_t nParameters, + Int_t *parameters, + TString *parameternames, + TString functionname = "", + Bool_t relative = false, + Bool_t resolution = false, + Bool_t pull = false, TString saveas = ""); Bool_t misalignmentDependence(TCanvas *c1old, - Int_t nFiles,TString *names,TString misalignment,Double_t *values,Double_t *phases,TString xvar,TString yvar, + Int_t nFiles, + TString *names, + TString misalignment, + Double_t *values, + Double_t *phases, + TString xvar, + TString yvar, Bool_t drawfits = true, - Bool_t relative = false,Bool_t resolution = false,Bool_t pull = false, + Bool_t relative = false, + Bool_t resolution = false, + Bool_t pull = false, TString saveas = ""); -Bool_t misalignmentDependence(Int_t nFiles,TString *files,TString *names,TString misalignment,Double_t *values,Double_t *phases,TString xvar,TString yvar, +Bool_t misalignmentDependence(Int_t nFiles, + TString *files, + TString *names, + TString misalignment, + Double_t *values, + Double_t *phases, + TString xvar, + TString yvar, Bool_t drawfits = true, - Bool_t relative = false,Bool_t resolution = false,Bool_t pull = false, + Bool_t relative = false, + Bool_t resolution = false, + Bool_t pull = false, TString saveas = ""); -Bool_t hasFit(TString misalignment,TString xvar,TString yvar,Bool_t relative = false,Bool_t resolution = false,Bool_t pull = false); - +Bool_t hasFit(TString misalignment, + TString xvar, + TString yvar, + Bool_t relative = false, + Bool_t resolution = false, + Bool_t pull = false); //============= //2. Make Plots //============= -void makePlots(Int_t nFiles,TString *files,TString *names,TString misalignment,Double_t *values,Double_t *phases,TString directory,Bool_t matrix[xsize][ysize]); -void makePlots(Int_t nFiles,TString *files,TString *names,TString directory, Bool_t matrix[xsize][ysize]); -void makePlots(TString file,TString misalignment,Double_t *values,Double_t *phases,TString directory,Bool_t matrix[xsize][ysize]); -void makePlots(TString file,TString directory,Bool_t matrix[xsize][ysize]); -void makePlots(Int_t nFiles,TString *files,TString *names,TString misalignment,Double_t *values,Double_t *phases,TString directory,TString xvar,TString yvar); -void makePlots(Int_t nFiles,TString *files,TString *names,TString directory,TString xvar,TString yvar); -void makePlots(TString file,TString misalignment,Double_t *values,Double_t *phases,TString directory, - TString xvar,TString yvar); -void makePlots(TString file,TString directory,TString xvar,TString yvar); -void makePlots(Int_t nFiles,TString *files,TString *names,TString misalignment,Double_t *values,Double_t *phases,TString directory); -void makePlots(Int_t nFiles,TString *files,TString *names,TString directory); -void makePlots(TString file,TString misalignment,Double_t *values,Double_t *phases,TString directory); -void makePlots(TString file,TString directory); +void makePlots(Int_t nFiles, + TString *files, + TString *names, + TString misalignment, + Double_t *values, + Double_t *phases, + TString directory, + Bool_t matrix[xsize][ysize]); +void makePlots(Int_t nFiles, TString *files, TString *names, TString directory, Bool_t matrix[xsize][ysize]); +void makePlots(TString file, + TString misalignment, + Double_t *values, + Double_t *phases, + TString directory, + Bool_t matrix[xsize][ysize]); +void makePlots(TString file, TString directory, Bool_t matrix[xsize][ysize]); +void makePlots(Int_t nFiles, + TString *files, + TString *names, + TString misalignment, + Double_t *values, + Double_t *phases, + TString directory, + TString xvar, + TString yvar); +void makePlots(Int_t nFiles, TString *files, TString *names, TString directory, TString xvar, TString yvar); +void makePlots(TString file, + TString misalignment, + Double_t *values, + Double_t *phases, + TString directory, + TString xvar, + TString yvar); +void makePlots(TString file, TString directory, TString xvar, TString yvar); +void makePlots(Int_t nFiles, + TString *files, + TString *names, + TString misalignment, + Double_t *values, + Double_t *phases, + TString directory); +void makePlots(Int_t nFiles, TString *files, TString *names, TString directory); +void makePlots(TString file, TString misalignment, Double_t *values, Double_t *phases, TString directory); +void makePlots(TString file, TString directory); //============= //3. Axis Label //============= TString fancyname(TString variable); -TString units(TString variable,Char_t axis); -TString plainunits(TString variable,Char_t axis); -TString latexunits(TString variable,Char_t axis); -TString axislabel(TString variable, Char_t axis, Bool_t relative = false, Bool_t resolution = false, Bool_t pull = false); -TString latexlabel(TString variable, Char_t axis, Bool_t relative = false, Bool_t resolution = false, Bool_t pull = false); -void setAxisLabels(TH1 *p, PlotType type,TString xvar,TString yvar,Bool_t relative,Bool_t pull); -void setAxisLabels(TMultiGraph *p, PlotType type,TString xvar,TString yvar,Bool_t relative,Bool_t pull); -TString nPart(Int_t part,TString string,TString delimit = ";",Bool_t removerest = true); +TString units(TString variable, Char_t axis); +TString plainunits(TString variable, Char_t axis); +TString latexunits(TString variable, Char_t axis); +TString axislabel( + TString variable, Char_t axis, Bool_t relative = false, Bool_t resolution = false, Bool_t pull = false); +TString latexlabel( + TString variable, Char_t axis, Bool_t relative = false, Bool_t resolution = false, Bool_t pull = false); +void setAxisLabels(TH1 *p, PlotType type, TString xvar, TString yvar, Bool_t relative, Bool_t pull); +void setAxisLabels(TMultiGraph *p, PlotType type, TString xvar, TString yvar, Bool_t relative, Bool_t pull); +TString nPart(Int_t part, TString string, TString delimit = ";", Bool_t removerest = true); //============== //4. Axis Limits //============== -Double_t findStatistic(Statistic what,Int_t nFiles,TString *files,TString var,Char_t axis,Bool_t relative = false,Bool_t pull = false); -Double_t findAverage(Int_t nFiles,TString *files,TString var,Char_t axis,Bool_t relative = false,Bool_t pull = false); -Double_t findMin(Int_t nFiles,TString *files,TString var,Char_t axis,Bool_t relative = false,Bool_t pull = false); -Double_t findMax(Int_t nFiles,TString *files,TString var,Char_t axis,Bool_t relative = false,Bool_t pull = false); -Double_t findRMS(Int_t nFiles,TString *files,TString var,Char_t axis,Bool_t relative = false,Bool_t pull = false); -Double_t findStatistic(Statistic what,TString file,TString var,Char_t axis,Bool_t relative = false,Bool_t pull = false); -Double_t findAverage(TString file,TString var,Char_t axis,Bool_t relative = false,Bool_t pull = false); -Double_t findMin(TString file,TString var,Char_t axis,Bool_t relative = false,Bool_t pull = false); -Double_t findMax(TString file,TString var,Char_t axis,Bool_t relative = false,Bool_t pull = false); -Double_t findRMS(TString file,TString var,Char_t axis,Bool_t relative = false,Bool_t pull = false); -void axislimits(Int_t nFiles,TString *files,TString var,Char_t axis,Bool_t relative,Bool_t pull,Double_t &min,Double_t &max,Double_t &bins); +Double_t findStatistic(Statistic what, + Int_t nFiles, + TString *files, + TString var, + Char_t axis, + Bool_t relative = false, + Bool_t pull = false); +Double_t findAverage( + Int_t nFiles, TString *files, TString var, Char_t axis, Bool_t relative = false, Bool_t pull = false); +Double_t findMin(Int_t nFiles, TString *files, TString var, Char_t axis, Bool_t relative = false, Bool_t pull = false); +Double_t findMax(Int_t nFiles, TString *files, TString var, Char_t axis, Bool_t relative = false, Bool_t pull = false); +Double_t findRMS(Int_t nFiles, TString *files, TString var, Char_t axis, Bool_t relative = false, Bool_t pull = false); +Double_t findStatistic( + Statistic what, TString file, TString var, Char_t axis, Bool_t relative = false, Bool_t pull = false); +Double_t findAverage(TString file, TString var, Char_t axis, Bool_t relative = false, Bool_t pull = false); +Double_t findMin(TString file, TString var, Char_t axis, Bool_t relative = false, Bool_t pull = false); +Double_t findMax(TString file, TString var, Char_t axis, Bool_t relative = false, Bool_t pull = false); +Double_t findRMS(TString file, TString var, Char_t axis, Bool_t relative = false, Bool_t pull = false); +void axislimits(Int_t nFiles, + TString *files, + TString var, + Char_t axis, + Bool_t relative, + Bool_t pull, + Double_t &min, + Double_t &max, + Double_t &bins); //=============== //5. Place Legend //=============== -Double_t placeLegend(TLegend *l, Double_t width, Double_t height, Double_t x1min, Double_t y1min, Double_t x2max, Double_t y2max); -Bool_t fitsHere(TLegend *l,Double_t x1, Double_t y1, Double_t x2, Double_t y2); +Double_t placeLegend( + TLegend *l, Double_t width, Double_t height, Double_t x1min, Double_t y1min, Double_t x2max, Double_t y2max); +Bool_t fitsHere(TLegend *l, Double_t x1, Double_t y1, Double_t x2, Double_t y2); #endif diff --git a/Alignment/OfflineValidation/scripts/GeometryComparisonPlotter.cc b/Alignment/OfflineValidation/scripts/GeometryComparisonPlotter.cc index 9a2c86493da08..4110c34dfafaa 100644 --- a/Alignment/OfflineValidation/scripts/GeometryComparisonPlotter.cc +++ b/Alignment/OfflineValidation/scripts/GeometryComparisonPlotter.cc @@ -8,1543 +8,1649 @@ /* Thanks a million <3 */ /***********************************************************************************/ -// NOTE: look for "TO DO" as a keyword to now what should be upgraded in later versions.... - +// NOTE: look for "TO DO" as a keyword to now what should be upgraded in later versions.... // modes -#define TALKATIVE // get some comments while processing +#define TALKATIVE // get some comments while processing //#define DEBUG // get a lot of comments while processing + canvases -> resource-consuming! // MACROS -#define INSIDE_VECTOR(vector) \ - cout << #vector << "={"; for (unsigned int i = 0 ; i < vector.size()-1 ; i++) cout << vector[i] << ","; cout << vector.back() << "}"; -#define CHECK_MAP_CONTENT(m,type) \ - for (map::iterator it = m.begin() ; it != m.end() ; it++) \ - cout << __FILE__ << ":" << __LINE__ << ":Info: " << #m << "[" << it->first << "]=" << it->second << endl; +#define INSIDE_VECTOR(vector) \ + cout << #vector << "={"; \ + for (unsigned int i = 0; i < vector.size() - 1; i++) \ + cout << vector[i] << ","; \ + cout << vector.back() << "}"; +#define CHECK_MAP_CONTENT(m, type) \ + for (map::iterator it = m.begin(); it != m.end(); it++) \ + cout << __FILE__ << ":" << __LINE__ << ":Info: " << #m << "[" << it->first << "]=" << it->second << endl; // CONSTRUCTOR AND DESTRUCTOR -GeometryComparisonPlotter::GeometryComparisonPlotter (TString tree_file_name, - TString output_directory, - TString modulesToPlot, - TString alignmentName, - TString referenceName, - bool printOnlyGlobal, - bool makeProfilePlots - ) : - _output_directory(output_directory + TString(output_directory.EndsWith("/") ? "" : "/")), - _output_filename("comparison.root"), - _print_option("pdf"), - _module_plot_option(modulesToPlot), - _alignment_name(alignmentName), - _reference_name(referenceName), - _print_only_global(printOnlyGlobal), - _make_profile_plots(makeProfilePlots), - _print(true), // print the graphs in a file (e.g. pdf) - _legend(true), // print the graphs in a file (e.g. pdf) - _write(true), // write the graphs in a root file - _batchMode( +GeometryComparisonPlotter::GeometryComparisonPlotter(TString tree_file_name, + TString output_directory, + TString modulesToPlot, + TString alignmentName, + TString referenceName, + bool printOnlyGlobal, + bool makeProfilePlots) + : _output_directory(output_directory + TString(output_directory.EndsWith("/") ? "" : "/")), + _output_filename("comparison.root"), + _print_option("pdf"), + _module_plot_option(modulesToPlot), + _alignment_name(alignmentName), + _reference_name(referenceName), + _print_only_global(printOnlyGlobal), + _make_profile_plots(makeProfilePlots), + _print(true), // print the graphs in a file (e.g. pdf) + _legend(true), // print the graphs in a file (e.g. pdf) + _write(true), // write the graphs in a root file + _batchMode( #ifdef DEBUG - false // false = display canvases (very time- and resource-consuming) + false // false = display canvases (very time- and resource-consuming) #else - true // true = no canvases + true // true = no canvases #endif - ), - _1dModule(true), // cut on 1d modules - _2dModule(true), // cut on 2d modules - _levelCut (DEFAULT_LEVEL), // module level (see branch of same name) - _grid_x(0), // by default no display the grid in the canvases - _grid_y(0), // by default no display the grid in the canvases - _window_width(DEFAULT_WINDOW_WIDTH), - _window_height(DEFAULT_WINDOW_HEIGHT) -{ + ), + _1dModule(true), // cut on 1d modules + _2dModule(true), // cut on 2d modules + _levelCut(DEFAULT_LEVEL), // module level (see branch of same name) + _grid_x(0), // by default no display the grid in the canvases + _grid_y(0), // by default no display the grid in the canvases + _window_width(DEFAULT_WINDOW_WIDTH), + _window_height(DEFAULT_WINDOW_HEIGHT) { #ifdef TALKATIVE - cout << ">>> TALKATIVE MODE ACTIVATED <<<" << endl; + cout << ">>> TALKATIVE MODE ACTIVATED <<<" << endl; #endif #ifdef DEBUG - cout << ">>> DEBUG MODE ACTIVATED <<<" << endl; - cout << __FILE__ << ":"<< __LINE__ << ":Info: inside constructor of GeometryComparisonPlotter utility"<< endl; + cout << ">>> DEBUG MODE ACTIVATED <<<" << endl; + cout << __FILE__ << ":" << __LINE__ << ":Info: inside constructor of GeometryComparisonPlotter utility" << endl; #endif - //_sublevel_names = {"PXB", "PXF", "TIB", "TID", "TOB", "TEC"}; // C++11 - _sublevel_names[0] = TString("PXB"); - _sublevel_names[1] = TString("PXF"); - _sublevel_names[2] = TString("TIB"); - _sublevel_names[3] = TString("TID"); - _sublevel_names[4] = TString("TOB"); - _sublevel_names[5] = TString("TEC"); - // TO DO: handle other structures - - // read tree - tree_file = new TFile(tree_file_name, "UPDATE"); - data = (TTree*) tree_file->Get("alignTree"); - // int branches - data->SetBranchAddress("id" ,&branch_i["id"]); - data->SetBranchAddress("inModuleList" ,&branch_i["inModuleList"]); - data->SetBranchAddress("badModuleQuality" ,&branch_i["badModuleQuality"]); - data->SetBranchAddress("mid" ,&branch_i["mid"]); - data->SetBranchAddress("level" ,&branch_i["level"]); - data->SetBranchAddress("mlevel" ,&branch_i["mlevel"]); - data->SetBranchAddress("sublevel" ,&branch_i["sublevel"]); - data->SetBranchAddress("useDetId" ,&branch_i["useDetId"]); - data->SetBranchAddress("detDim" ,&branch_i["detDim"]); - // float branches - data->SetBranchAddress("x" ,&branch_f["x"]); - data->SetBranchAddress("y" ,&branch_f["y"]); - data->SetBranchAddress("z" ,&branch_f["z"]); - data->SetBranchAddress("alpha" ,&branch_f["alpha"]); - data->SetBranchAddress("beta" ,&branch_f["beta"]); - data->SetBranchAddress("gamma" ,&branch_f["gamma"]); - data->SetBranchAddress("phi" ,&branch_f["phi"]); - data->SetBranchAddress("eta" ,&branch_f["eta"]); - data->SetBranchAddress("r" ,&branch_f["r"]); - data->SetBranchAddress("dx" ,&branch_f["dx"]); - data->SetBranchAddress("dy" ,&branch_f["dy"]); - data->SetBranchAddress("dz" ,&branch_f["dz"]); - data->SetBranchAddress("dphi" ,&branch_f["dphi"]); - data->SetBranchAddress("dr" ,&branch_f["dr"]); - data->SetBranchAddress("dalpha" ,&branch_f["dalpha"]); - data->SetBranchAddress("dbeta" ,&branch_f["dbeta"]); - data->SetBranchAddress("dgamma" ,&branch_f["dgamma"]); - if (data->GetBranch("rdphi") == 0x0) // in the case of rdphi branch not existing, it is created from r and dphi branches - { + //_sublevel_names = {"PXB", "PXF", "TIB", "TID", "TOB", "TEC"}; // C++11 + _sublevel_names[0] = TString("PXB"); + _sublevel_names[1] = TString("PXF"); + _sublevel_names[2] = TString("TIB"); + _sublevel_names[3] = TString("TID"); + _sublevel_names[4] = TString("TOB"); + _sublevel_names[5] = TString("TEC"); + // TO DO: handle other structures + + // read tree + tree_file = new TFile(tree_file_name, "UPDATE"); + data = (TTree *)tree_file->Get("alignTree"); + // int branches + data->SetBranchAddress("id", &branch_i["id"]); + data->SetBranchAddress("inModuleList", &branch_i["inModuleList"]); + data->SetBranchAddress("badModuleQuality", &branch_i["badModuleQuality"]); + data->SetBranchAddress("mid", &branch_i["mid"]); + data->SetBranchAddress("level", &branch_i["level"]); + data->SetBranchAddress("mlevel", &branch_i["mlevel"]); + data->SetBranchAddress("sublevel", &branch_i["sublevel"]); + data->SetBranchAddress("useDetId", &branch_i["useDetId"]); + data->SetBranchAddress("detDim", &branch_i["detDim"]); + // float branches + data->SetBranchAddress("x", &branch_f["x"]); + data->SetBranchAddress("y", &branch_f["y"]); + data->SetBranchAddress("z", &branch_f["z"]); + data->SetBranchAddress("alpha", &branch_f["alpha"]); + data->SetBranchAddress("beta", &branch_f["beta"]); + data->SetBranchAddress("gamma", &branch_f["gamma"]); + data->SetBranchAddress("phi", &branch_f["phi"]); + data->SetBranchAddress("eta", &branch_f["eta"]); + data->SetBranchAddress("r", &branch_f["r"]); + data->SetBranchAddress("dx", &branch_f["dx"]); + data->SetBranchAddress("dy", &branch_f["dy"]); + data->SetBranchAddress("dz", &branch_f["dz"]); + data->SetBranchAddress("dphi", &branch_f["dphi"]); + data->SetBranchAddress("dr", &branch_f["dr"]); + data->SetBranchAddress("dalpha", &branch_f["dalpha"]); + data->SetBranchAddress("dbeta", &branch_f["dbeta"]); + data->SetBranchAddress("dgamma", &branch_f["dgamma"]); + if (data->GetBranch("rdphi") == + 0x0) // in the case of rdphi branch not existing, it is created from r and dphi branches + { #ifdef TALKATIVE - cout << __FILE__ << ":" << __LINE__ << ":Info: computing the rdphi branch from r and dphi branches (assuming they exist...)" << endl; + cout << __FILE__ << ":" << __LINE__ + << ":Info: computing the rdphi branch from r and dphi branches (assuming they exist...)" << endl; #endif - TBranch * br_rdphi = data->Branch("rdphi", &branch_f["rdphi"], "rdphi/F"); - for (unsigned int ientry = 0 ; ientry < data->GetEntries() ; ientry++) - { - data->GetEntry(ientry); - branch_f["rdphi"] = branch_f["r"]*branch_f["dphi"]; - br_rdphi->Fill(); - } + TBranch *br_rdphi = data->Branch("rdphi", &branch_f["rdphi"], "rdphi/F"); + for (unsigned int ientry = 0; ientry < data->GetEntries(); ientry++) { + data->GetEntry(ientry); + branch_f["rdphi"] = branch_f["r"] * branch_f["dphi"]; + br_rdphi->Fill(); } - else - data->SetBranchAddress("rdphi",&branch_f["rdphi"]); + } else + data->SetBranchAddress("rdphi", &branch_f["rdphi"]); #ifdef DEBUG - cout << __FILE__ << ":" << __LINE__ << ":Info: branch addresses set" << endl; + cout << __FILE__ << ":" << __LINE__ << ":Info: branch addresses set" << endl; #endif - // style - gROOT->Reset(); - - data->SetMarkerSize(0.5); - data->SetMarkerStyle(6); - - gStyle->SetOptStat("emr"); - gStyle->SetTitleAlign(22); - gStyle->SetTitleX(0.5); - gStyle->SetTitleY(0.97); - gStyle->SetTitleFont(62); - //gStyle->SetOptTitle(0); - - gStyle->SetTextFont(132); - gStyle->SetTextSize(0.08); - gStyle->SetLabelFont(132,"x"); - gStyle->SetLabelFont(132,"y"); - gStyle->SetLabelFont(132,"z"); - gStyle->SetTitleSize(0.08,"x"); - gStyle->SetTitleSize(0.08,"y"); - gStyle->SetTitleSize(0.08,"z"); - gStyle->SetLabelSize(0.08,"x"); - gStyle->SetLabelSize(0.08,"y"); - gStyle->SetLabelSize(0.08,"z"); - - gStyle->SetMarkerStyle(8); - gStyle->SetHistLineWidth(2); - gStyle->SetLineStyleString(2,"[12 12]"); // postscript dashes - - gStyle->SetFrameBorderMode(0); - gStyle->SetCanvasBorderMode(0); - gStyle->SetPadBorderMode(0); - gStyle->SetPadColor(0); - gStyle->SetCanvasColor(0); - gStyle->SetTitleColor(1); - gStyle->SetStatColor(0); - gStyle->SetStatBorderSize(1); - gStyle->SetFrameFillColor(0); - - gStyle->SetPadTickX(1); - gStyle->SetPadTickY(1); - - gStyle->SetPadTopMargin(0.1); - gStyle->SetPadRightMargin(0.05); - gStyle->SetPadBottomMargin(0.16); - gStyle->SetPadLeftMargin(0.18); + // style + gROOT->Reset(); + + data->SetMarkerSize(0.5); + data->SetMarkerStyle(6); + + gStyle->SetOptStat("emr"); + gStyle->SetTitleAlign(22); + gStyle->SetTitleX(0.5); + gStyle->SetTitleY(0.97); + gStyle->SetTitleFont(62); + //gStyle->SetOptTitle(0); + + gStyle->SetTextFont(132); + gStyle->SetTextSize(0.08); + gStyle->SetLabelFont(132, "x"); + gStyle->SetLabelFont(132, "y"); + gStyle->SetLabelFont(132, "z"); + gStyle->SetTitleSize(0.08, "x"); + gStyle->SetTitleSize(0.08, "y"); + gStyle->SetTitleSize(0.08, "z"); + gStyle->SetLabelSize(0.08, "x"); + gStyle->SetLabelSize(0.08, "y"); + gStyle->SetLabelSize(0.08, "z"); + + gStyle->SetMarkerStyle(8); + gStyle->SetHistLineWidth(2); + gStyle->SetLineStyleString(2, "[12 12]"); // postscript dashes + + gStyle->SetFrameBorderMode(0); + gStyle->SetCanvasBorderMode(0); + gStyle->SetPadBorderMode(0); + gStyle->SetPadColor(0); + gStyle->SetCanvasColor(0); + gStyle->SetTitleColor(1); + gStyle->SetStatColor(0); + gStyle->SetStatBorderSize(1); + gStyle->SetFrameFillColor(0); + + gStyle->SetPadTickX(1); + gStyle->SetPadTickY(1); + + gStyle->SetPadTopMargin(0.1); + gStyle->SetPadRightMargin(0.05); + gStyle->SetPadBottomMargin(0.16); + gStyle->SetPadLeftMargin(0.18); #ifdef DEBUG - cout << __FILE__ << ":" << __LINE__ << ":Info: end of constructor" << endl; + cout << __FILE__ << ":" << __LINE__ << ":Info: end of constructor" << endl; #endif } -GeometryComparisonPlotter::~GeometryComparisonPlotter () -{ +GeometryComparisonPlotter::~GeometryComparisonPlotter() { #ifdef DEBUG - cout << __FILE__ << ":" << __LINE__ << ":Info: in destructor of the GeometryComparisonPlotter utility" << endl; + cout << __FILE__ << ":" << __LINE__ << ":Info: in destructor of the GeometryComparisonPlotter utility" << endl; #endif - tree_file->Close(); + tree_file->Close(); #ifdef DEBUG - cout << __FILE__ << ":" << __LINE__ << ":Info: ending." << endl; + cout << __FILE__ << ":" << __LINE__ << ":Info: ending." << endl; #endif } // MAIN METHOD -void GeometryComparisonPlotter::MakePlots (vector x, // axes to combine to plot - vector y, // every combination (except the ones such that x=y) will be perfomed - vector dyMin, // Minimum of y-variable to enable fixed ranges of the histogram - vector dyMax) // Minimum of y-variable +void GeometryComparisonPlotter::MakePlots( + vector x, // axes to combine to plot + vector y, // every combination (except the ones such that x=y) will be perfomed + vector dyMin, // Minimum of y-variable to enable fixed ranges of the histogram + vector dyMax) // Minimum of y-variable { - /// -1) check that only existing branches are called - // (we use a macro to avoid copy/paste) -#define CHECK_BRANCHES(branchname_vector) \ - for (unsigned int i = 0 ; i < branchname_vector.size() ; i++) \ - { \ - if (branch_f.find(branchname_vector[i]) == branch_f.end()) \ - { \ - cout << __FILE__ << ":" << __LINE__ << ":Error: The branch " << branchname_vector[i] << " is not recognised." << endl; \ - return; \ - } \ - } - CHECK_BRANCHES(x); - CHECK_BRANCHES(y); - - const unsigned int nentries = data->GetEntries(); + /// -1) check that only existing branches are called + // (we use a macro to avoid copy/paste) +#define CHECK_BRANCHES(branchname_vector) \ + for (unsigned int i = 0; i < branchname_vector.size(); i++) { \ + if (branch_f.find(branchname_vector[i]) == branch_f.end()) { \ + cout << __FILE__ << ":" << __LINE__ << ":Error: The branch " << branchname_vector[i] << " is not recognised." \ + << endl; \ + return; \ + } \ + } + CHECK_BRANCHES(x); + CHECK_BRANCHES(y); + + const unsigned int nentries = data->GetEntries(); #ifdef TALKATIVE - cout << __FILE__ << ":" << __LINE__ << ":Info: "; INSIDE_VECTOR(x); cout << endl - << __FILE__ << ":" << __LINE__ << ":Info: "; INSIDE_VECTOR(y); cout << endl; + cout << __FILE__ << ":" << __LINE__ << ":Info: "; + INSIDE_VECTOR(x); + cout << endl << __FILE__ << ":" << __LINE__ << ":Info: "; + INSIDE_VECTOR(y); + cout << endl; #endif - /// 0) min and max values - // the max and min of the graphs are computed from the tree if they have not been manually input yet - // (we use a macro to avoid copy/paste) -#define LIMITS(axes_vector) \ - for (unsigned int i = 0 ; i < axes_vector.size() ; i++) \ - { \ - if ( _SF.find(axes_vector[i]) == _SF.end()) _SF[axes_vector[i]] = 1.; \ - if (_min.find(axes_vector[i]) == _min.end()) _min[axes_vector[i]] = _SF[axes_vector[i]]*data->GetMinimum(axes_vector[i]); \ - if (_max.find(axes_vector[i]) == _max.end()) _max[axes_vector[i]] = _SF[axes_vector[i]]*data->GetMaximum(axes_vector[i]); \ - } - LIMITS(x); - LIMITS(y); + /// 0) min and max values + // the max and min of the graphs are computed from the tree if they have not been manually input yet + // (we use a macro to avoid copy/paste) +#define LIMITS(axes_vector) \ + for (unsigned int i = 0; i < axes_vector.size(); i++) { \ + if (_SF.find(axes_vector[i]) == _SF.end()) \ + _SF[axes_vector[i]] = 1.; \ + if (_min.find(axes_vector[i]) == _min.end()) \ + _min[axes_vector[i]] = _SF[axes_vector[i]] * data->GetMinimum(axes_vector[i]); \ + if (_max.find(axes_vector[i]) == _max.end()) \ + _max[axes_vector[i]] = _SF[axes_vector[i]] * data->GetMaximum(axes_vector[i]); \ + } + LIMITS(x); + LIMITS(y); -#ifdef TALKATIVE - CHECK_MAP_CONTENT(_min,float); - CHECK_MAP_CONTENT(_max,float); - CHECK_MAP_CONTENT(_SF ,float); +#ifdef TALKATIVE + CHECK_MAP_CONTENT(_min, float); + CHECK_MAP_CONTENT(_max, float); + CHECK_MAP_CONTENT(_SF, float); #endif - /// 1) declare TGraphs and Histograms for profile plots if these are to be plotted - // the idea is to produce at the end a table of 8 TMultiGraphs and histograms: - // - 0=Tracker, with color code for the different sublevels - // - 1..6=different sublevels, with color code for z < or > 0 - // - 7=only pixel with color code for BPIX and FPIX - - // (convention: the six first (resp. last) correspond to z>0 (resp. z<0)) - // Modules with bad quality and in a list of modules that is given - // by the user (e.g. list of bad/untouched modules, default: empty list) - // are stored in seperate graphs and might be plotted (depends on the module - // plot option, default: all modules plotted) - // This means that 3*2*6 TGraphs will be filled during the loop on the TTree, - // and will be arranged differently with different color codes in the TMultiGraphs - - // For the profile plots - // Either all modules, only good modules or good modules + those in a given list will be plotted - // This means that 2*6 TH2F will be filled during the loop on the TTree, - // and will be arranged differently with different color codes in the Histograms + /// 1) declare TGraphs and Histograms for profile plots if these are to be plotted + // the idea is to produce at the end a table of 8 TMultiGraphs and histograms: + // - 0=Tracker, with color code for the different sublevels + // - 1..6=different sublevels, with color code for z < or > 0 + // - 7=only pixel with color code for BPIX and FPIX + + // (convention: the six first (resp. last) correspond to z>0 (resp. z<0)) + // Modules with bad quality and in a list of modules that is given + // by the user (e.g. list of bad/untouched modules, default: empty list) + // are stored in seperate graphs and might be plotted (depends on the module + // plot option, default: all modules plotted) + // This means that 3*2*6 TGraphs will be filled during the loop on the TTree, + // and will be arranged differently with different color codes in the TMultiGraphs + + // For the profile plots + // Either all modules, only good modules or good modules + those in a given list will be plotted + // This means that 2*6 TH2F will be filled during the loop on the TTree, + // and will be arranged differently with different color codes in the Histograms #ifndef NB_SUBLEVELS #define NB_SUBLEVELS 6 #endif #define NB_Z_SLICES 2 #define NB_MODULE_QUALITY 3 -#define COLOR_CODE(icolor) int(icolor/4)+icolor+1 - - TGraph * graphs[x.size()][y.size()][NB_SUBLEVELS*NB_Z_SLICES*NB_MODULE_QUALITY]; - long int ipoint[x.size()][y.size()][NB_SUBLEVELS*NB_Z_SLICES*NB_MODULE_QUALITY]; - - TMultiGraph * mgraphs[x.size()][y.size()][2+NB_SUBLEVELS]; // the 0th is for global plots, the 1..6th for sublevel plots, 7th for pixel only - TCanvas * c[x.size()][y.size()][2+NB_SUBLEVELS], - * c_global[2+NB_SUBLEVELS]; - canvas_index++; // this static index is a safety used in case the MakePlots method is used several times to avoid overloading - - // histograms for profile plots, - // 2D-hists to store the data - // 1D-hists to calculate mean and sigma of y-values for each x-bin of the 2D-hists and for the final profile hist - TH2F * histos2D[x.size()][y.size()][NB_SUBLEVELS*NB_Z_SLICES]; - TH1F * histos[x.size()][y.size()][NB_SUBLEVELS*NB_Z_SLICES]; - TH1F * histosYValues[x.size()][y.size()][NB_SUBLEVELS*NB_Z_SLICES]; // Used to calculate the mean and RMS for each x-bin of the 2D-hist - TH1F * histosTracker[x.size()][y.size()][NB_SUBLEVELS*NB_Z_SLICES]; // for the tracker plots all histos are copied to avoid using the same hists in different canvas - - TCanvas * c_hist[x.size()][y.size()][2+NB_SUBLEVELS], * c_global_hist[2+NB_SUBLEVELS]; - - unsigned int nXBins; // Sensible number of x-bins differs depending on the variable - - - - - for (unsigned int ic = 0 ; ic <= NB_SUBLEVELS+1 ; ic++) - { - c_global[ic] = new TCanvas (TString::Format("global_%s_%d", ic==0 ? "tracker" : ( ic==7 ? "pixel" : _sublevel_names[ic-1].Data() ), - canvas_index), - TString::Format("Global overview of the %s variables", ic==0 ? "tracker" : ( ic==7 ? "pixel" : _sublevel_names[ic-1].Data() ) ), - _window_width, - _window_height); - c_global[ic]->Divide(x.size(),y.size()); - - if (_make_profile_plots) { - c_global_hist[ic] = new TCanvas (TString::Format("global_profile_plots_%s_%d", ic==0 ? "tracker" : ( ic==7 ? "pixel" : _sublevel_names[ic-1].Data() ), - canvas_index), - TString::Format("Global overview profile plots of the %s variables", ic==0 ? "tracker" : ( ic==7 ? "pixel" : _sublevel_names[ic-1].Data() ) ), - _window_width, - _window_height); - c_global_hist[ic]->Divide(x.size(),y.size()); - } - - } +#define COLOR_CODE(icolor) int(icolor / 4) + icolor + 1 + + TGraph *graphs[x.size()][y.size()][NB_SUBLEVELS * NB_Z_SLICES * NB_MODULE_QUALITY]; + long int ipoint[x.size()][y.size()][NB_SUBLEVELS * NB_Z_SLICES * NB_MODULE_QUALITY]; + + TMultiGraph + *mgraphs[x.size()][y.size()] + [2 + NB_SUBLEVELS]; // the 0th is for global plots, the 1..6th for sublevel plots, 7th for pixel only + TCanvas *c[x.size()][y.size()][2 + NB_SUBLEVELS], *c_global[2 + NB_SUBLEVELS]; + canvas_index++; // this static index is a safety used in case the MakePlots method is used several times to avoid overloading + + // histograms for profile plots, + // 2D-hists to store the data + // 1D-hists to calculate mean and sigma of y-values for each x-bin of the 2D-hists and for the final profile hist + TH2F *histos2D[x.size()][y.size()][NB_SUBLEVELS * NB_Z_SLICES]; + TH1F *histos[x.size()][y.size()][NB_SUBLEVELS * NB_Z_SLICES]; + TH1F *histosYValues[x.size()][y.size()] + [NB_SUBLEVELS * NB_Z_SLICES]; // Used to calculate the mean and RMS for each x-bin of the 2D-hist + TH1F *histosTracker + [x.size()][y.size()] + [NB_SUBLEVELS * + NB_Z_SLICES]; // for the tracker plots all histos are copied to avoid using the same hists in different canvas + + TCanvas *c_hist[x.size()][y.size()][2 + NB_SUBLEVELS], *c_global_hist[2 + NB_SUBLEVELS]; + + unsigned int nXBins; // Sensible number of x-bins differs depending on the variable + + for (unsigned int ic = 0; ic <= NB_SUBLEVELS + 1; ic++) { + c_global[ic] = new TCanvas( + TString::Format( + "global_%s_%d", ic == 0 ? "tracker" : (ic == 7 ? "pixel" : _sublevel_names[ic - 1].Data()), canvas_index), + TString::Format("Global overview of the %s variables", + ic == 0 ? "tracker" : (ic == 7 ? "pixel" : _sublevel_names[ic - 1].Data())), + _window_width, + _window_height); + c_global[ic]->Divide(x.size(), y.size()); - - for (unsigned int ix = 0 ; ix < x.size() ; ix++) - { - for (unsigned int iy = 0 ; iy < y.size() ; iy++) - { - //if (x[ix] == y[iy]) continue; // do not plot graphs like (r,r) or (phi,phi) - for (unsigned int igraph = 0 ; igraph < NB_SUBLEVELS*NB_Z_SLICES*NB_MODULE_QUALITY ; igraph++) - { - // declaring - ipoint[ix][iy][igraph] = 0; // the purpose of an index for every graph is to avoid thousands of points at the origin of each - graphs[ix][iy][igraph] = new TGraph (); - - graphs[ix][iy][igraph]->SetMarkerColor(COLOR_CODE(igraph)); - graphs[ix][iy][igraph]->SetMarkerStyle(6); - // pimping - graphs[ix][iy][igraph]->SetName (x[ix]+y[iy]+_sublevel_names[igraph%NB_SUBLEVELS] - +TString(igraph%(NB_SUBLEVELS*NB_Z_SLICES)>=NB_SUBLEVELS ? "n" : "p" ) // graphs for negative/positive z - +TString(igraph >= NB_SUBLEVELS*NB_Z_SLICES ? - ( igraph >= 2*NB_SUBLEVELS*NB_Z_SLICES ? "bad" : "list") : "good" ));// graphs for good, bad modules and from a list - graphs[ix][iy][igraph]->SetTitle( _sublevel_names[igraph%NB_SUBLEVELS] - +TString(igraph%(NB_SUBLEVELS*NB_Z_SLICES)>=NB_SUBLEVELS ? " at z<0": " at z>=0") - +TString(igraph >= NB_SUBLEVELS*NB_Z_SLICES ? - ( igraph >= 2*NB_SUBLEVELS*NB_Z_SLICES ? " bad modules" : " in list") : " good modules" ) - + TString (";") + LateXstyle(x[ix]) + " /" + _units[x[ix]] - + TString (";") + LateXstyle(y[iy]) + " /" + _units[y[iy]]); - graphs[ix][iy][igraph]->SetMarkerStyle(igraph >= NB_SUBLEVELS*NB_Z_SLICES ? - ( igraph >= 2*NB_SUBLEVELS*NB_Z_SLICES ? 4 : 5) : 6); // empty circle for bad modules, X for those in list, dot for good ones - } + if (_make_profile_plots) { + c_global_hist[ic] = + new TCanvas(TString::Format("global_profile_plots_%s_%d", + ic == 0 ? "tracker" : (ic == 7 ? "pixel" : _sublevel_names[ic - 1].Data()), + canvas_index), + TString::Format("Global overview profile plots of the %s variables", + ic == 0 ? "tracker" : (ic == 7 ? "pixel" : _sublevel_names[ic - 1].Data())), + _window_width, + _window_height); + c_global_hist[ic]->Divide(x.size(), y.size()); + } + } + + for (unsigned int ix = 0; ix < x.size(); ix++) { + for (unsigned int iy = 0; iy < y.size(); iy++) { + //if (x[ix] == y[iy]) continue; // do not plot graphs like (r,r) or (phi,phi) + for (unsigned int igraph = 0; igraph < NB_SUBLEVELS * NB_Z_SLICES * NB_MODULE_QUALITY; igraph++) { + // declaring + ipoint[ix][iy][igraph] = + 0; // the purpose of an index for every graph is to avoid thousands of points at the origin of each + graphs[ix][iy][igraph] = new TGraph(); + + graphs[ix][iy][igraph]->SetMarkerColor(COLOR_CODE(igraph)); + graphs[ix][iy][igraph]->SetMarkerStyle(6); + // pimping + graphs[ix][iy][igraph]->SetName( + x[ix] + y[iy] + _sublevel_names[igraph % NB_SUBLEVELS] + + TString(igraph % (NB_SUBLEVELS * NB_Z_SLICES) >= NB_SUBLEVELS ? "n" + : "p") // graphs for negative/positive z + + TString(igraph >= NB_SUBLEVELS * NB_Z_SLICES ? (igraph >= 2 * NB_SUBLEVELS * NB_Z_SLICES ? "bad" : "list") + : "good")); // graphs for good, bad modules and from a list + graphs[ix][iy][igraph]->SetTitle( + _sublevel_names[igraph % NB_SUBLEVELS] + + TString(igraph % (NB_SUBLEVELS * NB_Z_SLICES) >= NB_SUBLEVELS ? " at z<0" : " at z>=0") + + TString(igraph >= NB_SUBLEVELS * NB_Z_SLICES + ? (igraph >= 2 * NB_SUBLEVELS * NB_Z_SLICES ? " bad modules" : " in list") + : " good modules") + + TString(";") + LateXstyle(x[ix]) + " /" + _units[x[ix]] + TString(";") + LateXstyle(y[iy]) + " /" + + _units[y[iy]]); + graphs[ix][iy][igraph]->SetMarkerStyle( + igraph >= NB_SUBLEVELS * NB_Z_SLICES + ? (igraph >= 2 * NB_SUBLEVELS * NB_Z_SLICES ? 4 : 5) + : 6); // empty circle for bad modules, X for those in list, dot for good ones + } + } + } + + // Use seperate loop for the profile histograms since we do not produce histograms for the different module qualities + if (_make_profile_plots) { + for (unsigned int ix = 0; ix < x.size(); ix++) { + if (x[ix] == "phi") + nXBins = 10; + else + nXBins = 40; + + for (unsigned int iy = 0; iy < y.size(); iy++) { + for (unsigned int igraph = 0; igraph < NB_SUBLEVELS * NB_Z_SLICES; igraph++) { + // declaring + histos2D[ix][iy][igraph] = + new TH2F("2Dhist" + x[ix] + y[iy] + _sublevel_names[igraph % NB_SUBLEVELS] + + TString(igraph % (NB_SUBLEVELS * NB_Z_SLICES) >= NB_SUBLEVELS ? "n" : "p") + + TString(std::to_string(canvas_index)), + "", + nXBins, + _min[x[ix]], + _max[x[ix]], + 1000, + _min[y[iy]], + _max[y[iy]] + 1.); } + } } - - // Use seperate loop for the profile histograms since we do not produce histograms for the different module qualities - if (_make_profile_plots) { - for (unsigned int ix = 0 ; ix < x.size() ; ix++) - { - if ( x[ix] == "phi") nXBins = 10; - else nXBins = 40; - - for (unsigned int iy = 0 ; iy < y.size() ; iy++) - { - for (unsigned int igraph = 0 ; igraph < NB_SUBLEVELS*NB_Z_SLICES ; igraph++) - { - // declaring - histos2D[ix][iy][igraph] = new TH2F ("2Dhist"+x[ix]+y[iy]+_sublevel_names[igraph%NB_SUBLEVELS] - +TString(igraph%(NB_SUBLEVELS*NB_Z_SLICES)>=NB_SUBLEVELS ? "n" : "p" ) - +std::to_string(canvas_index), - "",nXBins,_min[x[ix]],_max[x[ix]], - 1000,_min[y[iy]],_max[y[iy]]+1.); - } - } - } - } - + } + #ifdef DEBUG - cout << __FILE__ << ":" << __LINE__ << ":Info: Creation of the TGraph[" << x.size() << "][" << y.size() << "][" << NB_SUBLEVELS*NB_Z_SLICES*NB_MODULE_QUALITY << "] ended." << endl; + cout << __FILE__ << ":" << __LINE__ << ":Info: Creation of the TGraph[" << x.size() << "][" << y.size() << "][" + << NB_SUBLEVELS * NB_Z_SLICES * NB_MODULE_QUALITY << "] ended." << endl; #endif - /// 2) loop on the TTree data + /// 2) loop on the TTree data #ifdef DEBUG - cout << __FILE__ << ":" << __LINE__ << ":Info: Looping on the TTree" << endl; + cout << __FILE__ << ":" << __LINE__ << ":Info: Looping on the TTree" << endl; #endif #ifdef TALKATIVE - unsigned int progress = 0; - cout << __FILE__ << ":" << __LINE__ << ":Info: 0%" << endl; + unsigned int progress = 0; + cout << __FILE__ << ":" << __LINE__ << ":Info: 0%" << endl; #endif - for (unsigned int ientry = 0 ; ientry < nentries ; ientry++) - { -#ifdef TALKATIVE - if (10*ientry/nentries != progress) - { - progress = 10*ientry/nentries; - cout << __FILE__ << ":" << __LINE__ << ":Info: " << 10*progress << "%" << endl; - } + for (unsigned int ientry = 0; ientry < nentries; ientry++) { +#ifdef TALKATIVE + if (10 * ientry / nentries != progress) { + progress = 10 * ientry / nentries; + cout << __FILE__ << ":" << __LINE__ << ":Info: " << 10 * progress << "%" << endl; + } #endif - // load current tree entry - data->GetEntry(ientry); - - // CUTS on entry - if (branch_i["level"] != _levelCut) continue; - if (!_1dModule && branch_i["detDim"] == 1) continue; - if (!_2dModule && branch_i["detDim"] == 2) continue; - - // loop on the different couples of variables to plot in a graph - for (unsigned int ix = 0 ; ix < x.size() ; ix++) - { - // CUTS on x[ix] - if (_SF[x[ix]]*branch_f[x[ix]] > _max[x[ix]] || _SF[x[ix]]*branch_f[x[ix]] < _min[x[ix]]) - { -//#ifdef DEBUG -// cout << "branch_f[x[ix]]=" << branch_f[x[ix]] << endl; -//#endif - continue; - } + // load current tree entry + data->GetEntry(ientry); + + // CUTS on entry + if (branch_i["level"] != _levelCut) + continue; + if (!_1dModule && branch_i["detDim"] == 1) + continue; + if (!_2dModule && branch_i["detDim"] == 2) + continue; + + // loop on the different couples of variables to plot in a graph + for (unsigned int ix = 0; ix < x.size(); ix++) { + // CUTS on x[ix] + if (_SF[x[ix]] * branch_f[x[ix]] > _max[x[ix]] || _SF[x[ix]] * branch_f[x[ix]] < _min[x[ix]]) { + //#ifdef DEBUG + // cout << "branch_f[x[ix]]=" << branch_f[x[ix]] << endl; + //#endif + continue; + } + + for (unsigned int iy = 0; iy < y.size(); iy++) { + // CUTS on y[iy] + //if (x[ix] == y[iy]) continue; // TO DO: handle display when such a case occurs + if (branch_i["sublevel"] < 1 || branch_i["sublevel"] > NB_SUBLEVELS) + continue; + + // FILLING histograms take even those outside the plotted range into account + if (_make_profile_plots) { + if (_module_plot_option == "all") { + const short int igraph = (branch_i["sublevel"] - 1) + (branch_f["z"] >= 0 ? 0 : NB_SUBLEVELS); + histos2D[ix][iy][igraph]->Fill(_SF[x[ix]] * branch_f[x[ix]], _SF[y[iy]] * branch_f[y[iy]]); + } else if (_module_plot_option == "good" && branch_i["badModuleQuality"] == 0) { + const short int igraph = (branch_i["sublevel"] - 1) + (branch_f["z"] >= 0 ? 0 : NB_SUBLEVELS); + histos2D[ix][iy][igraph]->Fill(_SF[x[ix]] * branch_f[x[ix]], _SF[y[iy]] * branch_f[y[iy]]); + } else if (_module_plot_option == "list" && + (branch_i["inModuleList"] == 1 || branch_i["badModuleQuality"] == 0)) { + const short int igraph = (branch_i["sublevel"] - 1) + (branch_f["z"] >= 0 ? 0 : NB_SUBLEVELS); + histos2D[ix][iy][igraph]->Fill(_SF[x[ix]] * branch_f[x[ix]], _SF[y[iy]] * branch_f[y[iy]]); + } + } - for (unsigned int iy = 0 ; iy < y.size() ; iy++) - { - // CUTS on y[iy] - //if (x[ix] == y[iy]) continue; // TO DO: handle display when such a case occurs - if (branch_i["sublevel"] < 1 || branch_i["sublevel"] > NB_SUBLEVELS) continue; - - // FILLING histograms take even those outside the plotted range into account - if (_make_profile_plots) { - if (_module_plot_option == "all"){ - const short int igraph = (branch_i["sublevel"]-1) - + (branch_f["z"]>=0?0:NB_SUBLEVELS); - histos2D[ix][iy][igraph]->Fill(_SF[x[ix]]*branch_f[x[ix]], - _SF[y[iy]]*branch_f[y[iy]]); - } - else if (_module_plot_option == "good" && branch_i["badModuleQuality"]==0 ){ - const short int igraph = (branch_i["sublevel"]-1) - + (branch_f["z"]>=0?0:NB_SUBLEVELS); - histos2D[ix][iy][igraph]->Fill(_SF[x[ix]]*branch_f[x[ix]], - _SF[y[iy]]*branch_f[y[iy]]); - } - else if (_module_plot_option == "list" && (branch_i["inModuleList"]==1 || branch_i["badModuleQuality"]==0) ){ - const short int igraph = (branch_i["sublevel"]-1) - + (branch_f["z"]>=0?0:NB_SUBLEVELS); - histos2D[ix][iy][igraph]->Fill(_SF[x[ix]]*branch_f[x[ix]], - _SF[y[iy]]*branch_f[y[iy]]); - } - } - - // restrict scatter plots to chosen range - if (_SF[y[iy]]*branch_f[y[iy]] > _max[y[iy]] || _SF[y[iy]]*branch_f[y[iy]] < _min[y[iy]]) - { -//#ifdef DEBUG -// cout << "branch_f[y[iy]]=" << branch_f[y[iy]] << endl; -//#endif - continue; - } - - // FILLING GRAPH - if (y.size() >= x.size()){ - if (branch_i["inModuleList"]==0 && branch_i["badModuleQuality"]==0 ){ - const short int igraph = (branch_i["sublevel"]-1) - + (branch_f["z"]>=0?0:NB_SUBLEVELS); - graphs[ix][iy][igraph]->SetPoint(ipoint[ix][iy][igraph], - _SF[x[ix]]*branch_f[x[ix]], - _SF[y[iy]]*branch_f[y[iy]]); - ipoint[ix][iy][igraph]++; - } - if (branch_i["inModuleList"]>0){ - const short int igraph = (branch_i["sublevel"]-1) - + (branch_f["z"]>=0?0:NB_SUBLEVELS) - + NB_SUBLEVELS*NB_Z_SLICES; - graphs[ix][iy][igraph]->SetPoint(ipoint[ix][iy][igraph], - _SF[x[ix]]*branch_f[x[ix]], - _SF[y[iy]]*branch_f[y[iy]]); - ipoint[ix][iy][igraph]++; - } - if (branch_i["badModuleQuality"]>0){ - const short int igraph = (branch_i["sublevel"]-1) - + (branch_f["z"]>=0?0:NB_SUBLEVELS) - + 2*NB_SUBLEVELS*NB_Z_SLICES; - graphs[ix][iy][igraph]->SetPoint(ipoint[ix][iy][igraph], - _SF[x[ix]]*branch_f[x[ix]], - _SF[y[iy]]*branch_f[y[iy]]); - ipoint[ix][iy][igraph]++; - } - } - else{ - if (branch_i["inModuleList"]==0 && branch_i["badModuleQuality"]==0 ){ - const short int igraph = (branch_i["sublevel"]-1) - + (branch_f["z"]>=0?0:NB_SUBLEVELS); - graphs[iy][ix][igraph]->SetPoint(ipoint[iy][ix][igraph], - _SF[x[ix]]*branch_f[x[ix]], - _SF[y[iy]]*branch_f[y[iy]]); - ipoint[iy][ix][igraph]++; - } - if (branch_i["inModuleList"]>0){ - const short int igraph = (branch_i["sublevel"]-1) - + (branch_f["z"]>=0?0:NB_SUBLEVELS) - + NB_SUBLEVELS*NB_Z_SLICES; - graphs[iy][ix][igraph]->SetPoint(ipoint[iy][ix][igraph], - _SF[x[ix]]*branch_f[x[ix]], - _SF[y[iy]]*branch_f[y[iy]]); - ipoint[iy][ix][igraph]++; - } - if (branch_i["badModuleQuality"]>0){ - const short int igraph = (branch_i["sublevel"]-1) - + (branch_f["z"]>=0?0:NB_SUBLEVELS) - + 2*NB_SUBLEVELS*NB_Z_SLICES; - graphs[iy][ix][igraph]->SetPoint(ipoint[ix][iy][igraph], - _SF[x[ix]]*branch_f[x[ix]], - _SF[y[iy]]*branch_f[y[iy]]); - ipoint[iy][ix][igraph]++; - } - } - } + // restrict scatter plots to chosen range + if (_SF[y[iy]] * branch_f[y[iy]] > _max[y[iy]] || _SF[y[iy]] * branch_f[y[iy]] < _min[y[iy]]) { + //#ifdef DEBUG + // cout << "branch_f[y[iy]]=" << branch_f[y[iy]] << endl; + //#endif + continue; } + + // FILLING GRAPH + if (y.size() >= x.size()) { + if (branch_i["inModuleList"] == 0 && branch_i["badModuleQuality"] == 0) { + const short int igraph = (branch_i["sublevel"] - 1) + (branch_f["z"] >= 0 ? 0 : NB_SUBLEVELS); + graphs[ix][iy][igraph]->SetPoint( + ipoint[ix][iy][igraph], _SF[x[ix]] * branch_f[x[ix]], _SF[y[iy]] * branch_f[y[iy]]); + ipoint[ix][iy][igraph]++; + } + if (branch_i["inModuleList"] > 0) { + const short int igraph = + (branch_i["sublevel"] - 1) + (branch_f["z"] >= 0 ? 0 : NB_SUBLEVELS) + NB_SUBLEVELS * NB_Z_SLICES; + graphs[ix][iy][igraph]->SetPoint( + ipoint[ix][iy][igraph], _SF[x[ix]] * branch_f[x[ix]], _SF[y[iy]] * branch_f[y[iy]]); + ipoint[ix][iy][igraph]++; + } + if (branch_i["badModuleQuality"] > 0) { + const short int igraph = + (branch_i["sublevel"] - 1) + (branch_f["z"] >= 0 ? 0 : NB_SUBLEVELS) + 2 * NB_SUBLEVELS * NB_Z_SLICES; + graphs[ix][iy][igraph]->SetPoint( + ipoint[ix][iy][igraph], _SF[x[ix]] * branch_f[x[ix]], _SF[y[iy]] * branch_f[y[iy]]); + ipoint[ix][iy][igraph]++; + } + } else { + if (branch_i["inModuleList"] == 0 && branch_i["badModuleQuality"] == 0) { + const short int igraph = (branch_i["sublevel"] - 1) + (branch_f["z"] >= 0 ? 0 : NB_SUBLEVELS); + graphs[iy][ix][igraph]->SetPoint( + ipoint[iy][ix][igraph], _SF[x[ix]] * branch_f[x[ix]], _SF[y[iy]] * branch_f[y[iy]]); + ipoint[iy][ix][igraph]++; + } + if (branch_i["inModuleList"] > 0) { + const short int igraph = + (branch_i["sublevel"] - 1) + (branch_f["z"] >= 0 ? 0 : NB_SUBLEVELS) + NB_SUBLEVELS * NB_Z_SLICES; + graphs[iy][ix][igraph]->SetPoint( + ipoint[iy][ix][igraph], _SF[x[ix]] * branch_f[x[ix]], _SF[y[iy]] * branch_f[y[iy]]); + ipoint[iy][ix][igraph]++; + } + if (branch_i["badModuleQuality"] > 0) { + const short int igraph = + (branch_i["sublevel"] - 1) + (branch_f["z"] >= 0 ? 0 : NB_SUBLEVELS) + 2 * NB_SUBLEVELS * NB_Z_SLICES; + graphs[iy][ix][igraph]->SetPoint( + ipoint[ix][iy][igraph], _SF[x[ix]] * branch_f[x[ix]], _SF[y[iy]] * branch_f[y[iy]]); + ipoint[iy][ix][igraph]++; + } + } + } } + } #ifdef TALKATIVE - cout << __FILE__ << ":" << __LINE__ << ":Info: 100%\tLoop ended" << endl; + cout << __FILE__ << ":" << __LINE__ << ":Info: 100%\tLoop ended" << endl; #endif - /// 3) merge TGraph objects into TMultiGraph objects, then draw, print and write (according to the options _batchMode, _print and _write respectively) - gROOT->SetBatch(_batchMode); // if true, then equivalent to "root -b", i.e. no canvas - if (_write) - { // opening the file to write the graphs - output = new TFile(_output_directory+TString(_output_filename), "UPDATE"); // possibly existing file will be updated, otherwise created - if (output->IsZombie()) - { - cout << __FILE__ << ":" << __LINE__ << ":Error: Opening of " << _output_directory+TString(_output_filename) << " failed" << endl; - exit(-1); - } + /// 3) merge TGraph objects into TMultiGraph objects, then draw, print and write (according to the options _batchMode, _print and _write respectively) + gROOT->SetBatch(_batchMode); // if true, then equivalent to "root -b", i.e. no canvas + if (_write) { // opening the file to write the graphs + output = new TFile(_output_directory + TString(_output_filename), + "UPDATE"); // possibly existing file will be updated, otherwise created + if (output->IsZombie()) { + cout << __FILE__ << ":" << __LINE__ << ":Error: Opening of " << _output_directory + TString(_output_filename) + << " failed" << endl; + exit(-1); + } #ifdef TALKATIVE - cout << __FILE__ << ":"<< __LINE__ << ":Info: output file is " << _output_directory+TString(_output_filename) << endl; + cout << __FILE__ << ":" << __LINE__ << ":Info: output file is " << _output_directory + TString(_output_filename) + << endl; #endif - } - // declaring TMultiGraphs and TCanvas - // Usually more y variables than x variables - // creating TLegend - TLegend * legend = MakeLegend(.1,.92,.9,1.,NB_SUBLEVELS); - if (_write) legend->Write(); - - // check which modules are supposed to be plotted - unsigned int n_module_types = 1; - if (_module_plot_option == "all"){ - n_module_types = 3; //plot all modules (good, list and bad ) - } - else if (_module_plot_option == "list"){ - n_module_types = 2; // plot good modules and those in the list - } - else if (_module_plot_option == "good"){ - n_module_types = 1; // only plot the modules that are neither bad or in the list - } - - -#define INDEX_IN_GLOBAL_CANVAS(i1,i2) 1 + i1 + i2*x.size() - // running on the TGraphs to produce the TMultiGraph and draw/print them - for (unsigned int ix = 0 ; ix < x.size() ; ix++) - { + } + // declaring TMultiGraphs and TCanvas + // Usually more y variables than x variables + // creating TLegend + TLegend *legend = MakeLegend(.1, .92, .9, 1., NB_SUBLEVELS); + if (_write) + legend->Write(); + + // check which modules are supposed to be plotted + unsigned int n_module_types = 1; + if (_module_plot_option == "all") { + n_module_types = 3; //plot all modules (good, list and bad ) + } else if (_module_plot_option == "list") { + n_module_types = 2; // plot good modules and those in the list + } else if (_module_plot_option == "good") { + n_module_types = 1; // only plot the modules that are neither bad or in the list + } + +#define INDEX_IN_GLOBAL_CANVAS(i1, i2) 1 + i1 + i2 *x.size() + // running on the TGraphs to produce the TMultiGraph and draw/print them + for (unsigned int ix = 0; ix < x.size(); ix++) { #ifdef DEBUG - cout << __FILE__ << ":" << __LINE__ << ":Info: x[" << ix << "]="<< x[ix] << endl; + cout << __FILE__ << ":" << __LINE__ << ":Info: x[" << ix << "]=" << x[ix] << endl; #endif - // looping on Y axes - for (unsigned int iy = 0 ; iy < y.size() ; iy++) - { - - + // looping on Y axes + for (unsigned int iy = 0; iy < y.size(); iy++) { #ifdef DEBUG - cout << __FILE__ << ":" << __LINE__ << ":Info: x[" << ix << "]=" << x[ix] - << " and y[" << iy << "]=" << y[iy] - << "\t-> creating TMultiGraph" << endl; + cout << __FILE__ << ":" << __LINE__ << ":Info: x[" << ix << "]=" << x[ix] << " and y[" << iy << "]=" << y[iy] + << "\t-> creating TMultiGraph" << endl; #endif - mgraphs[ix][iy][0] = new TMultiGraph (TString::Format("mgr_%s_vs_%s_tracker_%d", x[ix].Data(), - y[iy].Data(), - canvas_index), // name - //LateXstyle(x[ix]) + TString(" vs. ") + LateXstyle(y[iy]) + TString(" for Tracker") // graph title - TString (";") + LateXstyle(x[ix]) + " /" + _units[x[ix]] // x axis title - + TString (";") + LateXstyle(y[iy]) + " /" + _units[y[iy]]); // y axis title - - mgraphs[ix][iy][7] = new TMultiGraph (TString::Format("mgr_%s_vs_%s_pixel_%d", x[ix].Data(), - y[iy].Data(), - canvas_index), // name - //LateXstyle(x[ix]) + TString(" vs. ") + LateXstyle(y[iy]) + TString(" for Tracker") // graph title - TString (";") + LateXstyle(x[ix]) + " /" + _units[x[ix]] // x axis title - + TString (";") + LateXstyle(y[iy]) + " /" + _units[y[iy]]); // y axis title - - /// TRACKER and PIXEL - // fixing ranges and filling TMultiGraph - // for (unsigned short int jgraph = NB_SUBLEVELS*NB_Z_SLICES-1 ; jgraph >= 0 ; --jgraph) - for (unsigned short int jgraph = 0 ; jgraph < NB_SUBLEVELS*NB_Z_SLICES*n_module_types ; jgraph++) - { - unsigned short int igraph = NB_SUBLEVELS*NB_Z_SLICES*n_module_types - jgraph - 1; // reverse counting for humane readability (one of the sublevel takes much more place than the others) + mgraphs[ix][iy][0] = new TMultiGraph( + TString::Format("mgr_%s_vs_%s_tracker_%d", + x[ix].Data(), + y[iy].Data(), + canvas_index), // name + //LateXstyle(x[ix]) + TString(" vs. ") + LateXstyle(y[iy]) + TString(" for Tracker") // graph title + TString(";") + LateXstyle(x[ix]) + " /" + _units[x[ix]] // x axis title + + TString(";") + LateXstyle(y[iy]) + " /" + _units[y[iy]]); // y axis title + + mgraphs[ix][iy][7] = new TMultiGraph( + TString::Format("mgr_%s_vs_%s_pixel_%d", + x[ix].Data(), + y[iy].Data(), + canvas_index), // name + //LateXstyle(x[ix]) + TString(" vs. ") + LateXstyle(y[iy]) + TString(" for Tracker") // graph title + TString(";") + LateXstyle(x[ix]) + " /" + _units[x[ix]] // x axis title + + TString(";") + LateXstyle(y[iy]) + " /" + _units[y[iy]]); // y axis title + + /// TRACKER and PIXEL + // fixing ranges and filling TMultiGraph + // for (unsigned short int jgraph = NB_SUBLEVELS*NB_Z_SLICES-1 ; jgraph >= 0 ; --jgraph) + for (unsigned short int jgraph = 0; jgraph < NB_SUBLEVELS * NB_Z_SLICES * n_module_types; jgraph++) { + unsigned short int igraph = + NB_SUBLEVELS * NB_Z_SLICES * n_module_types - jgraph - + 1; // reverse counting for humane readability (one of the sublevel takes much more place than the others) #ifdef DEBUG - cout << __FILE__ << ":" << __LINE__ << ":Info: writing TGraph to file" << endl; + cout << __FILE__ << ":" << __LINE__ << ":Info: writing TGraph to file" << endl; #endif - // write into root file - if (_write) graphs[ix][iy][igraph]->Write(); - if (graphs[ix][iy][igraph]->GetN() == 0) - { + // write into root file + if (_write) + graphs[ix][iy][igraph]->Write(); + if (graphs[ix][iy][igraph]->GetN() == 0) { #ifdef TALKATIVE - cout << __FILE__ << ":" << __LINE__ << ":Info: " << graphs[ix][iy][igraph]->GetName() << " is empty." << endl; + cout << __FILE__ << ":" << __LINE__ << ":Info: " << graphs[ix][iy][igraph]->GetName() << " is empty." << endl; #endif - continue; - } + continue; + } #ifdef DEBUG - cout << __FILE__ << ":" << __LINE__ << ":Info: cloning, coloring and adding TGraph " - << _sublevel_names[igraph%NB_SUBLEVELS] - << (igraph >= NB_SUBLEVELS ? "(z<0)" : "(z>0)") - << " to global TMultiGraph" << endl; + cout << __FILE__ << ":" << __LINE__ << ":Info: cloning, coloring and adding TGraph " + << _sublevel_names[igraph % NB_SUBLEVELS] << (igraph >= NB_SUBLEVELS ? "(z<0)" : "(z>0)") + << " to global TMultiGraph" << endl; #endif - // clone to prevent any injure on the graph - TGraph * gr = (TGraph *) graphs[ix][iy][igraph]->Clone(); - // color - gr->SetMarkerColor(COLOR_CODE(igraph%NB_SUBLEVELS)); - mgraphs[ix][iy][0]->Add(gr, "P");//, (mgraphs[ix][iy][0]->GetListOfGraphs()==0?"AP":"P")); - - if (igraph%NB_SUBLEVELS == 0 || igraph%NB_SUBLEVELS == 1) mgraphs[ix][iy][7]->Add(gr, "P"); // Add BPIX (0) and FPIX (1) to pixel plot - - } - - /// SUBLEVELS (1..6) - for (unsigned int isublevel = 1 ; isublevel <= NB_SUBLEVELS ; isublevel++) - { + // clone to prevent any injure on the graph + TGraph *gr = (TGraph *)graphs[ix][iy][igraph]->Clone(); + // color + gr->SetMarkerColor(COLOR_CODE(igraph % NB_SUBLEVELS)); + mgraphs[ix][iy][0]->Add(gr, "P"); //, (mgraphs[ix][iy][0]->GetListOfGraphs()==0?"AP":"P")); + + if (igraph % NB_SUBLEVELS == 0 || igraph % NB_SUBLEVELS == 1) + mgraphs[ix][iy][7]->Add(gr, "P"); // Add BPIX (0) and FPIX (1) to pixel plot + } + + /// SUBLEVELS (1..6) + for (unsigned int isublevel = 1; isublevel <= NB_SUBLEVELS; isublevel++) { #ifdef DEBUG - cout << __FILE__ << ":" << __LINE__ << ":Info: cloning, coloring and adding TGraph " - << _sublevel_names[isublevel-1] << " to sublevel TMultiGraph" << endl; + cout << __FILE__ << ":" << __LINE__ << ":Info: cloning, coloring and adding TGraph " + << _sublevel_names[isublevel - 1] << " to sublevel TMultiGraph" << endl; #endif - mgraphs[ix][iy][isublevel] = new TMultiGraph (TString::Format("%s_vs_%s_%s_%d", x[ix].Data(), - y[iy].Data(), - _sublevel_names[isublevel-1].Data(), - canvas_index), // name - //LateXstyle(x[ix]) + TString(" vs. ") + LateXstyle(y[iy]) + TString(" for ") + - _sublevel_names[isublevel-1] // graph title - + TString (";") + LateXstyle(x[ix]) + " /" + _units[x[ix]] // x axis title - + TString (";") + LateXstyle(y[iy]) + " /" + _units[y[iy]]); // y axis title - - graphs[ix][iy][ isublevel-1]->SetMarkerColor(kBlack); - graphs[ix][iy][NB_SUBLEVELS+isublevel-1]->SetMarkerColor(kRed); - graphs[ix][iy][2*NB_SUBLEVELS+isublevel-1]->SetMarkerColor(kGray+1); - graphs[ix][iy][3*NB_SUBLEVELS+isublevel-1]->SetMarkerColor(kRed-7); - graphs[ix][iy][4*NB_SUBLEVELS+isublevel-1]->SetMarkerColor(kGray+1); - graphs[ix][iy][5*NB_SUBLEVELS+isublevel-1]->SetMarkerColor(kRed-7); - if (graphs[ix][iy][ isublevel-1]->GetN() > 0) mgraphs[ix][iy][isublevel]->Add(graphs[ix][iy][ isublevel-1], "P"); //(mgraphs[ix][iy][isublevel-1]->GetListOfGraphs()==0?"AP":"P")); // z>0 + mgraphs[ix][iy][isublevel] = + new TMultiGraph(TString::Format("%s_vs_%s_%s_%d", + x[ix].Data(), + y[iy].Data(), + _sublevel_names[isublevel - 1].Data(), + canvas_index), // name + //LateXstyle(x[ix]) + TString(" vs. ") + LateXstyle(y[iy]) + TString(" for ") + + _sublevel_names[isublevel - 1] // graph title + + TString(";") + LateXstyle(x[ix]) + " /" + _units[x[ix]] // x axis title + + TString(";") + LateXstyle(y[iy]) + " /" + _units[y[iy]]); // y axis title + + graphs[ix][iy][isublevel - 1]->SetMarkerColor(kBlack); + graphs[ix][iy][NB_SUBLEVELS + isublevel - 1]->SetMarkerColor(kRed); + graphs[ix][iy][2 * NB_SUBLEVELS + isublevel - 1]->SetMarkerColor(kGray + 1); + graphs[ix][iy][3 * NB_SUBLEVELS + isublevel - 1]->SetMarkerColor(kRed - 7); + graphs[ix][iy][4 * NB_SUBLEVELS + isublevel - 1]->SetMarkerColor(kGray + 1); + graphs[ix][iy][5 * NB_SUBLEVELS + isublevel - 1]->SetMarkerColor(kRed - 7); + if (graphs[ix][iy][isublevel - 1]->GetN() > 0) + mgraphs[ix][iy][isublevel]->Add( + graphs[ix][iy][isublevel - 1], + "P"); //(mgraphs[ix][iy][isublevel-1]->GetListOfGraphs()==0?"AP":"P")); // z>0 #ifdef TALKATIVE - else cout << __FILE__ << ":" << __LINE__ << ":Info: graphs[ix][iy][isublevel-1]=" << graphs[ix][iy][isublevel-1]->GetName() << " is empty -> not added into " << mgraphs[ix][iy][isublevel]->GetName() << endl; + else + cout << __FILE__ << ":" << __LINE__ + << ":Info: graphs[ix][iy][isublevel-1]=" << graphs[ix][iy][isublevel - 1]->GetName() + << " is empty -> not added into " << mgraphs[ix][iy][isublevel]->GetName() << endl; #endif - if (graphs[ix][iy][NB_SUBLEVELS+isublevel-1]->GetN() > 0) mgraphs[ix][iy][isublevel]->Add(graphs[ix][iy][NB_SUBLEVELS+isublevel-1], "P"); //(mgraphs[ix][iy][isublevel-1]->GetListOfGraphs()==0?"AP":"P")); // z<0 + if (graphs[ix][iy][NB_SUBLEVELS + isublevel - 1]->GetN() > 0) + mgraphs[ix][iy][isublevel]->Add( + graphs[ix][iy][NB_SUBLEVELS + isublevel - 1], + "P"); //(mgraphs[ix][iy][isublevel-1]->GetListOfGraphs()==0?"AP":"P")); // z<0 #ifdef TALKATIVE - else cout << __FILE__ << ":" << __LINE__ << ":Info: graphs[ix][iy][NB_SUBLEVEL+isublevel-1]=" << graphs[ix][iy][NB_Z_SLICES+isublevel-1]->GetName() << " is empty -> not added into " << mgraphs[ix][iy][isublevel]->GetName() << endl; + else + cout << __FILE__ << ":" << __LINE__ << ":Info: graphs[ix][iy][NB_SUBLEVEL+isublevel-1]=" + << graphs[ix][iy][NB_Z_SLICES + isublevel - 1]->GetName() << " is empty -> not added into " + << mgraphs[ix][iy][isublevel]->GetName() << endl; #endif -#if NB_Z_SLICES!=2 - cout << __FILE__ << ":" << __LINE__ << ":Error: color code incomplete for Z slices..." << endl; +#if NB_Z_SLICES != 2 + cout << __FILE__ << ":" << __LINE__ << ":Error: color code incomplete for Z slices..." << endl; #endif - if (_module_plot_option == "all"){ - if (graphs[ix][iy][2*NB_SUBLEVELS+isublevel-1]->GetN() > 0) mgraphs[ix][iy][isublevel]->Add(graphs[ix][iy][2*NB_SUBLEVELS+isublevel-1], "P"); - if (graphs[ix][iy][3*NB_SUBLEVELS+isublevel-1]->GetN() > 0) mgraphs[ix][iy][isublevel]->Add(graphs[ix][iy][3*NB_SUBLEVELS+isublevel-1], "P"); - if (graphs[ix][iy][4*NB_SUBLEVELS+isublevel-1]->GetN() > 0) mgraphs[ix][iy][isublevel]->Add(graphs[ix][iy][4*NB_SUBLEVELS+isublevel-1], "P"); - if (graphs[ix][iy][5*NB_SUBLEVELS+isublevel-1]->GetN() > 0) mgraphs[ix][iy][isublevel]->Add(graphs[ix][iy][5*NB_SUBLEVELS+isublevel-1], "P"); - } - if (_module_plot_option == "list"){ - if (graphs[ix][iy][2*NB_SUBLEVELS+isublevel-1]->GetN() > 0) mgraphs[ix][iy][isublevel]->Add(graphs[ix][iy][2*NB_SUBLEVELS+isublevel-1], "P"); - if (graphs[ix][iy][3*NB_SUBLEVELS+isublevel-1]->GetN() > 0) mgraphs[ix][iy][isublevel]->Add(graphs[ix][iy][3*NB_SUBLEVELS+isublevel-1], "P"); - } - } - + if (_module_plot_option == "all") { + if (graphs[ix][iy][2 * NB_SUBLEVELS + isublevel - 1]->GetN() > 0) + mgraphs[ix][iy][isublevel]->Add(graphs[ix][iy][2 * NB_SUBLEVELS + isublevel - 1], "P"); + if (graphs[ix][iy][3 * NB_SUBLEVELS + isublevel - 1]->GetN() > 0) + mgraphs[ix][iy][isublevel]->Add(graphs[ix][iy][3 * NB_SUBLEVELS + isublevel - 1], "P"); + if (graphs[ix][iy][4 * NB_SUBLEVELS + isublevel - 1]->GetN() > 0) + mgraphs[ix][iy][isublevel]->Add(graphs[ix][iy][4 * NB_SUBLEVELS + isublevel - 1], "P"); + if (graphs[ix][iy][5 * NB_SUBLEVELS + isublevel - 1]->GetN() > 0) + mgraphs[ix][iy][isublevel]->Add(graphs[ix][iy][5 * NB_SUBLEVELS + isublevel - 1], "P"); + } + if (_module_plot_option == "list") { + if (graphs[ix][iy][2 * NB_SUBLEVELS + isublevel - 1]->GetN() > 0) + mgraphs[ix][iy][isublevel]->Add(graphs[ix][iy][2 * NB_SUBLEVELS + isublevel - 1], "P"); + if (graphs[ix][iy][3 * NB_SUBLEVELS + isublevel - 1]->GetN() > 0) + mgraphs[ix][iy][isublevel]->Add(graphs[ix][iy][3 * NB_SUBLEVELS + isublevel - 1], "P"); + } + } - // fixing ranges, saving, and drawing of TMultiGraph (tracker AND sublevels AND pixel, i.e. 2+NB_SUBLEVELS objects) - // the individual canvases are saved, but the global are just drawn and will be saved later - for (unsigned short int imgr = 0 ; imgr <= NB_SUBLEVELS+1 ; imgr++) - { + // fixing ranges, saving, and drawing of TMultiGraph (tracker AND sublevels AND pixel, i.e. 2+NB_SUBLEVELS objects) + // the individual canvases are saved, but the global are just drawn and will be saved later + for (unsigned short int imgr = 0; imgr <= NB_SUBLEVELS + 1; imgr++) { #ifdef DEBUG - cout << __FILE__ << ":" << __LINE__ << ":Info: treating individual canvases." << endl; + cout << __FILE__ << ":" << __LINE__ << ":Info: treating individual canvases." << endl; #endif - // drawing into individual canvas and printing it (including a legend for the tracker canvas) - c[ix][iy][imgr] = new TCanvas (TString::Format("c_%s_vs_%s_%s_%d", x[ix].Data(), - y[iy].Data(), - imgr==0 ? "tracker" : ( imgr==7 ? "pixel" : _sublevel_names[imgr-1].Data() ), - canvas_index), - TString::Format("%s vs. %s at %s level", x[ix].Data(), - y[iy].Data(), - imgr==0 ? "tracker" : ( imgr==7 ? "pixel" : _sublevel_names[imgr-1].Data() ) ), - _window_width, - _window_height); - c[ix][iy][imgr]->SetGrid(_grid_x,_grid_y); // grid - - if (mgraphs[ix][iy][imgr]->GetListOfGraphs() != 0) { - if (dyMin[iy] != -99999) { - mgraphs[ix][iy][imgr]->SetMinimum(dyMin[iy]); - } - if (dyMax[iy] != -99999) { - mgraphs[ix][iy][imgr]->SetMaximum(dyMax[iy]); - } - mgraphs[ix][iy][imgr]->Draw("A"); - } - if (imgr == 0 && _legend) legend->Draw(); // only for the tracker - if (_print && !_print_only_global) c[ix][iy][imgr]->Print(_output_directory + mgraphs[ix][iy][imgr]->GetName() + ExtensionFromPrintOption(_print_option), _print_option); - - // writing into root file - if (_write) mgraphs[ix][iy][imgr]->Write(); - - // drawing into global canvas - c_global[imgr]->cd(INDEX_IN_GLOBAL_CANVAS(ix,iy)); - c_global[imgr]->GetPad(INDEX_IN_GLOBAL_CANVAS(ix,iy))->SetFillStyle(4000); // make the pad transparent - c_global[imgr]->GetPad(INDEX_IN_GLOBAL_CANVAS(ix,iy))->SetGrid(_grid_x,_grid_y); // grid - if (mgraphs[ix][iy][imgr]->GetListOfGraphs() != 0) { - if (dyMin[iy] != -99999) { - mgraphs[ix][iy][imgr]->SetMinimum(dyMin[iy]); - } - if (dyMax[iy] != -99999) { - mgraphs[ix][iy][imgr]->SetMaximum(dyMax[iy]); - } - mgraphs[ix][iy][imgr]->Draw("A"); - } - // printing will be performed after customisation (e.g. legend or title) just after the loops on ix and iy + // drawing into individual canvas and printing it (including a legend for the tracker canvas) + c[ix][iy][imgr] = new TCanvas( + TString::Format("c_%s_vs_%s_%s_%d", + x[ix].Data(), + y[iy].Data(), + imgr == 0 ? "tracker" : (imgr == 7 ? "pixel" : _sublevel_names[imgr - 1].Data()), + canvas_index), + TString::Format("%s vs. %s at %s level", + x[ix].Data(), + y[iy].Data(), + imgr == 0 ? "tracker" : (imgr == 7 ? "pixel" : _sublevel_names[imgr - 1].Data())), + _window_width, + _window_height); + c[ix][iy][imgr]->SetGrid(_grid_x, _grid_y); // grid + + if (mgraphs[ix][iy][imgr]->GetListOfGraphs() != 0) { + if (dyMin[iy] != -99999) { + mgraphs[ix][iy][imgr]->SetMinimum(dyMin[iy]); + } + if (dyMax[iy] != -99999) { + mgraphs[ix][iy][imgr]->SetMaximum(dyMax[iy]); + } + mgraphs[ix][iy][imgr]->Draw("A"); + } + if (imgr == 0 && _legend) + legend->Draw(); // only for the tracker + if (_print && !_print_only_global) + c[ix][iy][imgr]->Print( + _output_directory + mgraphs[ix][iy][imgr]->GetName() + ExtensionFromPrintOption(_print_option), + _print_option); + + // writing into root file + if (_write) + mgraphs[ix][iy][imgr]->Write(); + + // drawing into global canvas + c_global[imgr]->cd(INDEX_IN_GLOBAL_CANVAS(ix, iy)); + c_global[imgr]->GetPad(INDEX_IN_GLOBAL_CANVAS(ix, iy))->SetFillStyle(4000); // make the pad transparent + c_global[imgr]->GetPad(INDEX_IN_GLOBAL_CANVAS(ix, iy))->SetGrid(_grid_x, _grid_y); // grid + if (mgraphs[ix][iy][imgr]->GetListOfGraphs() != 0) { + if (dyMin[iy] != -99999) { + mgraphs[ix][iy][imgr]->SetMinimum(dyMin[iy]); + } + if (dyMax[iy] != -99999) { + mgraphs[ix][iy][imgr]->SetMaximum(dyMax[iy]); + } + mgraphs[ix][iy][imgr]->Draw("A"); + } + // printing will be performed after customisation (e.g. legend or title) just after the loops on ix and iy + } + } // end of loop on y + } // end of loop on x + + // CUSTOMISATION + gStyle->SetOptTitle(0); // otherwise, the title is repeated in every pad of the global canvases + // -> instead, we will write it in the upper part in a TPaveText or in a TLegend + for (unsigned int ic = 0; ic <= NB_SUBLEVELS + 1; ic++) { + c_global[ic]->Draw(); + + // setting legend to tracker canvases + if (!_legend) + break; + TCanvas *c_temp = (TCanvas *)c_global[ic]->Clone(c_global[ic]->GetTitle() + TString("_sub")); + c_temp->Draw(); + c_global[ic] = new TCanvas( + c_temp->GetName() + TString("_final"), c_temp->GetTitle(), c_temp->GetWindowWidth(), c_temp->GetWindowHeight()); + c_global[ic]->Draw(); + TPad *p_up = new TPad(TString("legend_") + c_temp->GetName(), + "", + 0., + 0.9, + 1., + 1., // relative position + -1, + 0, + 0), // display options + *p_down = new TPad(TString("main_") + c_temp->GetName(), "", 0., 0., 1., 0.9, -1, 0, 0); + // in the lower part, draw the plots + p_down->Draw(); + p_down->cd(); + c_temp->DrawClonePad(); + c_global[ic]->cd(); + // in the upper part, pimp the canvas :p + p_up->Draw(); + p_up->cd(); + if (ic == 0) // tracker + { + TLegend *global_legend = MakeLegend(.05, .1, .7, .8, NB_SUBLEVELS); //, "brNDC"); + global_legend->Draw(); + TPaveText *pt_geom = new TPaveText(.75, .1, .95, .8, "NB"); + pt_geom->SetFillColor(0); + pt_geom->SetTextSize(0.25); + pt_geom->AddText(TString("x: ") + _reference_name); + pt_geom->AddText(TString("y: ") + _alignment_name + TString(" - ") + _reference_name); + pt_geom->Draw(); + } else if (ic == 7) // pixel + { + TLegend *global_legend = MakeLegend(.05, .1, .7, .8, 2); //, "brNDC"); + global_legend->Draw(); + TPaveText *pt_geom = new TPaveText(.75, .1, .95, .8, "NB"); + pt_geom->SetFillColor(0); + pt_geom->SetTextSize(0.25); + pt_geom->AddText(TString("x: ") + _reference_name); + pt_geom->AddText(TString("y: ") + _alignment_name + TString(" - ") + _reference_name); + pt_geom->Draw(); + } else // sublevels + { + TPaveText *pt = new TPaveText(.05, .1, .7, .8, "NB"); + pt->SetFillColor(0); + pt->AddText(_sublevel_names[ic - 1]); + pt->Draw(); + TPaveText *pt_geom = new TPaveText(.6, .1, .95, .8, "NB"); + pt_geom->SetFillColor(0); + pt_geom->SetTextSize(0.3); + pt_geom->AddText(TString("x: ") + _reference_name); + pt_geom->AddText(TString("y: ") + _alignment_name + TString(" - ") + _reference_name); + pt_geom->Draw(); + } + // printing + if (_print) + c_global[ic]->Print(_output_directory + c_global[ic]->GetName() + ExtensionFromPrintOption(_print_option), + _print_option); + if (_write) + c_global[ic]->Write(); + } + + // printing global canvases + if (_write) + output->Close(); + + // Now produce the profile plots if the option is chosen + // Use seperate loops since no seperate plots are produced for different module qualities + if (_make_profile_plots) { + // Fill Content of 2D-hists into 1D-hists for the profile plots + // Loop over all y-bins for a certain x-bin, calculate mean and RMS as entries of the 1D-hists + bool entries = false; + for (unsigned int ix = 0; ix < x.size(); ix++) { + for (unsigned int iy = 0; iy < y.size(); iy++) { + for (unsigned int igraph = 0; igraph < NB_SUBLEVELS * NB_Z_SLICES; igraph++) { + // Declare hists which will be plotted for the profile plots + histos[ix][iy][igraph] = + new TH1F("1Dhist" + x[ix] + y[iy] + _sublevel_names[igraph % NB_SUBLEVELS] + + TString(igraph % (NB_SUBLEVELS * NB_Z_SLICES) >= NB_SUBLEVELS ? "n" : "p") + + TString(std::to_string(canvas_index)), + "", + histos2D[ix][iy][igraph]->GetXaxis()->GetNbins(), + _min[x[ix]], + _max[x[ix]]); + histos[ix][iy][igraph]->SetMarkerColor(COLOR_CODE(igraph)); + histos[ix][iy][igraph]->SetLineColor(COLOR_CODE(igraph)); + histos[ix][iy][igraph]->StatOverflows(kTRUE); + + // Loop over x bins + for (int binx = 0; binx <= histos2D[ix][iy][igraph]->GetXaxis()->GetNbins(); binx++) { + entries = false; + // Declare y-histogram for each x bin + histosYValues[ix][iy][igraph] = + new TH1F("1Dhist_Y-Values" + x[ix] + y[iy] + _sublevel_names[igraph % NB_SUBLEVELS] + + TString(igraph % (NB_SUBLEVELS * NB_Z_SLICES) >= NB_SUBLEVELS ? "n" : "p") + + TString(std::to_string(canvas_index)) + TString(std::to_string(binx)), + "", + histos2D[ix][iy][igraph]->GetYaxis()->GetNbins(), + _min[y[iy]], + _max[y[iy]] + 1.); + histosYValues[ix][iy][igraph]->StatOverflows(kTRUE); + // Loop over y-bins for each x-bin of the 2D histogram and put it into the 1-d y histograms + // Take overflow bin into account + for (int biny = 0; biny <= histos2D[ix][iy][igraph]->GetYaxis()->GetNbins() + 1; biny++) { + if (histos2D[ix][iy][igraph]->GetBinContent(binx, biny) > 1.) { + histosYValues[ix][iy][igraph]->SetBinContent(biny, histos2D[ix][iy][igraph]->GetBinContent(binx, biny)); + entries = true; + } } - } // end of loop on y - } // end of loop on x - - + if (entries) { + histos[ix][iy][igraph]->SetBinContent(binx, histosYValues[ix][iy][igraph]->GetMean()); + histos[ix][iy][igraph]->SetBinError(binx, histosYValues[ix][iy][igraph]->GetRMS()); + } else + histos[ix][iy][igraph]->SetBinContent(binx, -999999.); + } + } - // CUSTOMISATION - gStyle->SetOptTitle(0); // otherwise, the title is repeated in every pad of the global canvases - // -> instead, we will write it in the upper part in a TPaveText or in a TLegend - for (unsigned int ic = 0 ; ic <= NB_SUBLEVELS+1 ; ic++) - { - c_global[ic]->Draw(); - - // setting legend to tracker canvases - if (!_legend) break; - TCanvas * c_temp = (TCanvas *) c_global[ic]->Clone(c_global[ic]->GetTitle() + TString("_sub")); - c_temp->Draw(); - c_global[ic] = new TCanvas (c_temp->GetName() + TString("_final"), c_temp->GetTitle(), c_temp->GetWindowWidth(), c_temp->GetWindowHeight()); - c_global[ic]->Draw(); - TPad * p_up = new TPad (TString("legend_") + c_temp->GetName(), "", - 0., 0.9, 1., 1., // relative position - -1, 0, 0), // display options - * p_down = new TPad (TString("main_") + c_temp->GetName(), "", - 0., 0., 1., 0.9, - -1, 0, 0); - // in the lower part, draw the plots - p_down->Draw(); - p_down->cd(); - c_temp->DrawClonePad(); - c_global[ic]->cd(); - // in the upper part, pimp the canvas :p - p_up->Draw(); - p_up->cd(); - if (ic == 0) // tracker - { - TLegend * global_legend = MakeLegend(.05,.1,.7,.8,NB_SUBLEVELS);//, "brNDC"); - global_legend->Draw(); - TPaveText * pt_geom = new TPaveText(.75,.1,.95,.8, "NB"); - pt_geom->SetFillColor(0); - pt_geom->SetTextSize(0.25); - pt_geom->AddText(TString("x: ")+_reference_name); - pt_geom->AddText(TString("y: ")+_alignment_name+TString(" - ")+_reference_name); - pt_geom->Draw(); + // Customize and print the histograms + + /// TRACKER + // fixing ranges and draw profile plot histos + + c_hist[ix][iy][0] = + new TCanvas(TString::Format("c_hist_%s_vs_%s_tracker_%d", x[ix].Data(), y[iy].Data(), canvas_index), + TString::Format("Profile plot %s vs. %s at tracker level", x[ix].Data(), y[iy].Data()), + _window_width, + _window_height); + c_hist[ix][iy][0]->SetGrid(_grid_x, _grid_y); // grid + // Draw the frame that will contain the histograms + // One needs to specify the binning and title + c_hist[ix][iy][0]->GetPad(0)->DrawFrame(_min[x[ix]], + dyMin[iy] != -99999 ? dyMin[iy] : _min[y[iy]], + _max[x[ix]], + dyMax[iy] != -99999 ? dyMax[iy] : _max[y[iy]], + TString(";") + LateXstyle(x[ix]) + " /" + _units[x[ix]] + TString(";") + + LateXstyle(y[iy]) + " /" + _units[y[iy]]); + if (_legend) + legend->Draw("same"); + + for (unsigned short int jgraph = 0; jgraph < NB_SUBLEVELS * NB_Z_SLICES; jgraph++) { + unsigned short int igraph = + NB_SUBLEVELS * NB_Z_SLICES - jgraph - + 1; // reverse counting for humane readability (one of the sublevel takes much more place than the others) + + // clone to prevent any injure on the graph + histosTracker[ix][iy][igraph] = (TH1F *)histos[ix][iy][igraph]->Clone(); + // color + histosTracker[ix][iy][igraph]->SetMarkerColor(COLOR_CODE(igraph % NB_SUBLEVELS)); + histosTracker[ix][iy][igraph]->SetLineColor(COLOR_CODE(igraph % NB_SUBLEVELS)); + histosTracker[ix][iy][igraph]->SetMarkerStyle(6); + histosTracker[ix][iy][igraph]->Draw("same pe0"); + } + + if (_print && !_print_only_global) + c_hist[ix][iy][0]->Print( + _output_directory + + TString::Format("Profile_plot_%s_vs_%s_tracker_%d", x[ix].Data(), y[iy].Data(), canvas_index) + + ExtensionFromPrintOption(_print_option), + _print_option); + + //Draw into profile hists global tracker canvas + c_global_hist[0]->cd(INDEX_IN_GLOBAL_CANVAS(ix, iy)); + c_global_hist[0]->GetPad(INDEX_IN_GLOBAL_CANVAS(ix, iy))->SetFillStyle(4000); // make the pad transparent + c_global_hist[0]->GetPad(INDEX_IN_GLOBAL_CANVAS(ix, iy))->SetGrid(_grid_x, _grid_y); // grid + c_global_hist[0] + ->GetPad(INDEX_IN_GLOBAL_CANVAS(ix, iy)) + ->DrawFrame(_min[x[ix]], + dyMin[iy] != -99999 ? dyMin[iy] : _min[y[iy]], + _max[x[ix]], + dyMax[iy] != -99999 ? dyMax[iy] : _max[y[iy]], + TString(";") + LateXstyle(x[ix]) + " /" + _units[x[ix]] + TString(";") + LateXstyle(y[iy]) + + " /" + _units[y[iy]]); + + for (unsigned short int jgraph = 0; jgraph < NB_SUBLEVELS * NB_Z_SLICES; jgraph++) { + unsigned short int igraph = + NB_SUBLEVELS * NB_Z_SLICES - jgraph - + 1; // reverse counting for humane readability (one of the sublevel takes much more place than the others) + histosTracker[ix][iy][igraph]->Draw("same pe0"); + } + + /// PIXEL + // fixing ranges and draw profile plot histos + + c_hist[ix][iy][7] = + new TCanvas(TString::Format("c_hist_%s_vs_%s_pixel_%d", x[ix].Data(), y[iy].Data(), canvas_index), + TString::Format("Profile plot %s vs. %s at pixel level", x[ix].Data(), y[iy].Data()), + _window_width, + _window_height); + c_hist[ix][iy][7]->SetGrid(_grid_x, _grid_y); // grid + // Draw the frame that will contain the histograms + // One needs to specify the binning and title + c_hist[ix][iy][7]->GetPad(0)->DrawFrame(_min[x[ix]], + dyMin[iy] != -99999 ? dyMin[iy] : _min[y[iy]], + _max[x[ix]], + dyMax[iy] != -99999 ? dyMax[iy] : _max[y[iy]], + TString(";") + LateXstyle(x[ix]) + " /" + _units[x[ix]] + TString(";") + + LateXstyle(y[iy]) + " /" + _units[y[iy]]); + if (_legend) + legend->Draw("same"); + + for (unsigned short int jgraph = 0; jgraph < NB_SUBLEVELS * NB_Z_SLICES; jgraph++) { + unsigned short int igraph = + NB_SUBLEVELS * NB_Z_SLICES - jgraph - + 1; // reverse counting for humane readability (one of the sublevel takes much more place than the others) + + if (igraph % NB_SUBLEVELS == 0 || igraph % NB_SUBLEVELS == 1) //Only BPIX and FPIX + { + // clone to prevent any injure on the graph + histosTracker[ix][iy][igraph] = (TH1F *)histos[ix][iy][igraph]->Clone(); + // color + histosTracker[ix][iy][igraph]->SetMarkerColor(COLOR_CODE(igraph % NB_SUBLEVELS)); + histosTracker[ix][iy][igraph]->SetLineColor(COLOR_CODE(igraph % NB_SUBLEVELS)); + histosTracker[ix][iy][igraph]->SetMarkerStyle(6); + histosTracker[ix][iy][igraph]->Draw("same pe0"); + } } - else if (ic == 7) // pixel - { - TLegend * global_legend = MakeLegend(.05,.1,.7,.8,2);//, "brNDC"); - global_legend->Draw(); - TPaveText * pt_geom = new TPaveText(.75,.1,.95,.8, "NB"); - pt_geom->SetFillColor(0); - pt_geom->SetTextSize(0.25); - pt_geom->AddText(TString("x: ")+_reference_name); - pt_geom->AddText(TString("y: ")+_alignment_name+TString(" - ")+_reference_name); - pt_geom->Draw(); + + if (_print && !_print_only_global) + c_hist[ix][iy][7]->Print( + _output_directory + + TString::Format("Profile_plot_%s_vs_%s_pixel_%d", x[ix].Data(), y[iy].Data(), canvas_index) + + ExtensionFromPrintOption(_print_option), + _print_option); + + //Draw into profile hists global tracker canvas + c_global_hist[7]->cd(INDEX_IN_GLOBAL_CANVAS(ix, iy)); + c_global_hist[7]->GetPad(INDEX_IN_GLOBAL_CANVAS(ix, iy))->SetFillStyle(4000); // make the pad transparent + c_global_hist[7]->GetPad(INDEX_IN_GLOBAL_CANVAS(ix, iy))->SetGrid(_grid_x, _grid_y); // grid + c_global_hist[7] + ->GetPad(INDEX_IN_GLOBAL_CANVAS(ix, iy)) + ->DrawFrame(_min[x[ix]], + dyMin[iy] != -99999 ? dyMin[iy] : _min[y[iy]], + _max[x[ix]], + dyMax[iy] != -99999 ? dyMax[iy] : _max[y[iy]], + TString(";") + LateXstyle(x[ix]) + " /" + _units[x[ix]] + TString(";") + LateXstyle(y[iy]) + + " /" + _units[y[iy]]); + + for (unsigned short int jgraph = 0; jgraph < NB_SUBLEVELS * NB_Z_SLICES; jgraph++) { + unsigned short int igraph = + NB_SUBLEVELS * NB_Z_SLICES - jgraph - + 1; // reverse counting for humane readability (one of the sublevel takes much more place than the others) + histosTracker[ix][iy][igraph]->Draw("same pe0"); } - else // sublevels - { - TPaveText * pt = new TPaveText(.05,.1,.7,.8, "NB"); - pt->SetFillColor(0); - pt->AddText(_sublevel_names[ic-1]); - pt->Draw(); - TPaveText * pt_geom = new TPaveText(.6,.1,.95,.8, "NB"); - pt_geom->SetFillColor(0); - pt_geom->SetTextSize(0.3); - pt_geom->AddText(TString("x: ")+_reference_name); - pt_geom->AddText(TString("y: ")+_alignment_name+TString(" - ")+_reference_name); - pt_geom->Draw(); + // printing will be performed after customisation (e.g. legend or title) just after the loops on ix and iy + /// SUBLEVELS (1..6) + for (unsigned int isublevel = 1; isublevel <= NB_SUBLEVELS; isublevel++) { + // Draw and print profile histograms + c_hist[ix][iy][isublevel] = + new TCanvas(TString::Format("c_hist_%s_vs_%s_%s_%d", + x[ix].Data(), + y[iy].Data(), + isublevel == 0 ? "tracker" : _sublevel_names[isublevel - 1].Data(), + canvas_index), + TString::Format("Profile plot %s vs. %s at %s level", + x[ix].Data(), + y[iy].Data(), + isublevel == 0 ? "tracker" : _sublevel_names[isublevel - 1].Data()), + _window_width, + _window_height); + c_hist[ix][iy][isublevel]->SetGrid(_grid_x, _grid_y); // grid + c_hist[ix][iy][isublevel]->GetPad(0)->DrawFrame(_min[x[ix]], + dyMin[iy] != -99999 ? dyMin[iy] : _min[y[iy]], + _max[x[ix]], + dyMax[iy] != -99999 ? dyMax[iy] : _max[y[iy]], + TString(";") + LateXstyle(x[ix]) + " /" + _units[x[ix]] + + TString(";") + LateXstyle(y[iy]) + " /" + _units[y[iy]]); + + histos[ix][iy][isublevel - 1]->SetMarkerColor(kBlack); + histos[ix][iy][isublevel - 1]->SetLineColor(kBlack); + histos[ix][iy][NB_SUBLEVELS + isublevel - 1]->SetMarkerColor(kRed); + histos[ix][iy][NB_SUBLEVELS + isublevel - 1]->SetLineColor(kRed); + + histos[ix][iy][isublevel - 1]->Draw("same pe0"); + histos[ix][iy][NB_SUBLEVELS + isublevel - 1]->Draw("same pe0"); + + if (_print && !_print_only_global) + c_hist[ix][iy][isublevel]->Print(_output_directory + + TString::Format("Profile_plot_%s_vs_%s_%s_%d", + x[ix].Data(), + y[iy].Data(), + _sublevel_names[isublevel - 1].Data(), + canvas_index) + + ExtensionFromPrintOption(_print_option), + _print_option); + + // draw into global canvas + // printing will be performed after customisation (e.g. legend or title) just after the loops on ix and iy + c_global_hist[isublevel]->cd(INDEX_IN_GLOBAL_CANVAS(ix, iy)); + c_global_hist[isublevel] + ->GetPad(INDEX_IN_GLOBAL_CANVAS(ix, iy)) + ->SetFillStyle(4000); // make the pad transparent + c_global_hist[isublevel]->GetPad(INDEX_IN_GLOBAL_CANVAS(ix, iy))->SetGrid(_grid_x, _grid_y); // grid + c_global_hist[isublevel] + ->GetPad(INDEX_IN_GLOBAL_CANVAS(ix, iy)) + ->DrawFrame(_min[x[ix]], + dyMin[iy] != -99999 ? dyMin[iy] : _min[y[iy]], + _max[x[ix]], + dyMax[iy] != -99999 ? dyMax[iy] : _max[y[iy]], + TString(";") + LateXstyle(x[ix]) + " /" + _units[x[ix]] + TString(";") + LateXstyle(y[iy]) + + " /" + _units[y[iy]]); + + histos[ix][iy][isublevel - 1]->Draw("same pe0"); + histos[ix][iy][NB_SUBLEVELS + isublevel - 1]->Draw("same pe0"); } - // printing - if (_print) c_global[ic]->Print(_output_directory + c_global[ic]->GetName() + ExtensionFromPrintOption(_print_option), _print_option); - if (_write) c_global[ic]->Write(); + + } // end of loop on y + } // end of loop on x + + // CUSTOMISATION + gStyle->SetOptTitle(0); // otherwise, the title is repeated in every pad of the global canvases + // -> instead, we will write it in the upper part in a TPaveText or in a TLegend + for (unsigned int ic = 0; ic <= NB_SUBLEVELS; ic++) { + // setting legend to tracker canvases + if (!_legend) + break; + + // setting legend to tracker canvases + if (!_legend) + break; + TCanvas *c_temp_hist = (TCanvas *)c_global_hist[ic]->Clone(c_global_hist[ic]->GetTitle() + TString("_sub")); + c_temp_hist->Draw(); + c_global_hist[ic] = new TCanvas(c_temp_hist->GetName() + TString("_final"), + c_temp_hist->GetTitle(), + c_temp_hist->GetWindowWidth(), + c_temp_hist->GetWindowHeight()); + c_global_hist[ic]->Draw(); + TPad *p_up = new TPad(TString("legend_") + c_temp_hist->GetName(), + "", + 0., + 0.9, + 1., + 1., // relative position + -1, + 0, + 0), // display options + *p_down = new TPad(TString("main_") + c_temp_hist->GetName(), "", 0., 0., 1., 0.9, -1, 0, 0); + // in the lower part, draw the plots + p_down->Draw(); + p_down->cd(); + c_temp_hist->DrawClonePad(); + c_global_hist[ic]->cd(); + // in the upper part, pimp the canvas :p + p_up->Draw(); + p_up->cd(); + if (ic == 0) // tracker + { + TLegend *global_legend = MakeLegend(.05, .1, .7, .8, NB_SUBLEVELS); //, "brNDC"); + global_legend->Draw(); + TPaveText *pt_geom = new TPaveText(.75, .1, .95, .8, "NB"); + pt_geom->SetFillColor(0); + pt_geom->SetTextSize(0.25); + pt_geom->AddText(TString("x: ") + _reference_name); + pt_geom->AddText(TString("y: ") + _alignment_name + TString(" - ") + _reference_name); + pt_geom->Draw(); + } else if (ic == 7) // pixel + { + TLegend *global_legend = MakeLegend(.05, .1, .7, .8, 2); //, "brNDC"); + global_legend->Draw(); + TPaveText *pt_geom = new TPaveText(.75, .1, .95, .8, "NB"); + pt_geom->SetFillColor(0); + pt_geom->SetTextSize(0.25); + pt_geom->AddText(TString("x: ") + _reference_name); + pt_geom->AddText(TString("y: ") + _alignment_name + TString(" - ") + _reference_name); + pt_geom->Draw(); + } else // sublevels + { + TPaveText *pt = new TPaveText(.05, .1, .7, .8, "NB"); + pt->SetFillColor(0); + pt->AddText(_sublevel_names[ic - 1]); + pt->Draw(); + TPaveText *pt_geom = new TPaveText(.6, .1, .95, .8, "NB"); + pt_geom->SetFillColor(0); + pt_geom->SetTextSize(0.3); + pt_geom->AddText(TString("x: ") + _reference_name); + pt_geom->AddText(TString("y: ") + _alignment_name + TString(" - ") + _reference_name); + pt_geom->Draw(); + } + // printing + if (_print) + c_global_hist[ic]->Print( + _output_directory + c_global_hist[ic]->GetName() + ExtensionFromPrintOption(_print_option), _print_option); } - - // printing global canvases - if (_write) output->Close(); - - - // Now produce the profile plots if the option is chosen - // Use seperate loops since no seperate plots are produced for different module qualities - if (_make_profile_plots) { - - // Fill Content of 2D-hists into 1D-hists for the profile plots - // Loop over all y-bins for a certain x-bin, calculate mean and RMS as entries of the 1D-hists - bool entries = false; - for (unsigned int ix = 0 ; ix < x.size() ; ix++) - { - for (unsigned int iy = 0 ; iy < y.size() ; iy++) - { - for (unsigned int igraph = 0 ; igraph < NB_SUBLEVELS*NB_Z_SLICES ; igraph++) - { - - // Declare hists which will be plotted for the profile plots - histos[ix][iy][igraph] = new TH1F ("1Dhist"+x[ix]+y[iy]+_sublevel_names[igraph%NB_SUBLEVELS] - +TString(igraph%(NB_SUBLEVELS*NB_Z_SLICES)>=NB_SUBLEVELS ? "n" : "p" ) - +std::to_string(canvas_index), - "",histos2D[ix][iy][igraph]->GetXaxis()->GetNbins(),_min[x[ix]],_max[x[ix]]); - histos[ix][iy][igraph]->SetMarkerColor(COLOR_CODE(igraph)); - histos[ix][iy][igraph]->SetLineColor(COLOR_CODE(igraph)); - histos[ix][iy][igraph]->StatOverflows(kTRUE); - - - // Loop over x bins - for (int binx = 0 ; binx <= histos2D[ix][iy][igraph]->GetXaxis()->GetNbins() ; binx++) - { - entries = false; - // Declare y-histogram for each x bin - histosYValues[ix][iy][igraph] = new TH1F ("1Dhist_Y-Values"+x[ix]+y[iy]+_sublevel_names[igraph%NB_SUBLEVELS] - +TString(igraph%(NB_SUBLEVELS*NB_Z_SLICES)>=NB_SUBLEVELS ? "n" : "p" ) - +std::to_string(canvas_index) - +std::to_string(binx), - "",histos2D[ix][iy][igraph]->GetYaxis()->GetNbins(), - _min[y[iy]], - _max[y[iy]]+1.); - histosYValues[ix][iy][igraph]->StatOverflows(kTRUE); - // Loop over y-bins for each x-bin of the 2D histogram and put it into the 1-d y histograms - // Take overflow bin into account - for (int biny = 0 ; biny <= histos2D[ix][iy][igraph]->GetYaxis()->GetNbins()+1 ; biny++) - { - if (histos2D[ix][iy][igraph]->GetBinContent(binx,biny) > 1.) - { - histosYValues[ix][iy][igraph]->SetBinContent(biny,histos2D[ix][iy][igraph]->GetBinContent(binx,biny)); - entries = true; - } - } - if (entries) - { - histos[ix][iy][igraph]->SetBinContent(binx,histosYValues[ix][iy][igraph]->GetMean()); - histos[ix][iy][igraph]->SetBinError(binx,histosYValues[ix][iy][igraph]->GetRMS()); - } - else histos[ix][iy][igraph]->SetBinContent(binx,-999999.); - - } - - } - - // Customize and print the histograms - - /// TRACKER - // fixing ranges and draw profile plot histos - - c_hist[ix][iy][0] = new TCanvas (TString::Format("c_hist_%s_vs_%s_tracker_%d", x[ix].Data(), - y[iy].Data(), - canvas_index), - TString::Format("Profile plot %s vs. %s at tracker level", x[ix].Data(), - y[iy].Data()), - _window_width, - _window_height); - c_hist[ix][iy][0]->SetGrid(_grid_x,_grid_y); // grid - // Draw the frame that will contain the histograms - // One needs to specify the binning and title - c_hist[ix][iy][0]->GetPad(0)->DrawFrame(_min[x[ix]], - dyMin[iy] != -99999 ? dyMin[iy] : _min[y[iy]], - _max[x[ix]], - dyMax[iy] != -99999 ? dyMax[iy] : _max[y[iy]], - TString (";") + LateXstyle(x[ix]) + " /" + _units[x[ix]] - + TString (";") + LateXstyle(y[iy]) + " /" + _units[y[iy]]); - if (_legend) legend->Draw("same"); - - for (unsigned short int jgraph = 0 ; jgraph < NB_SUBLEVELS*NB_Z_SLICES ; jgraph++) - { - unsigned short int igraph = NB_SUBLEVELS*NB_Z_SLICES - jgraph - 1; // reverse counting for humane readability (one of the sublevel takes much more place than the others) - - // clone to prevent any injure on the graph - histosTracker[ix][iy][igraph] = (TH1F *) histos[ix][iy][igraph]->Clone(); - // color - histosTracker[ix][iy][igraph]->SetMarkerColor(COLOR_CODE(igraph%NB_SUBLEVELS)); - histosTracker[ix][iy][igraph]->SetLineColor(COLOR_CODE(igraph%NB_SUBLEVELS)); - histosTracker[ix][iy][igraph]->SetMarkerStyle(6); - histosTracker[ix][iy][igraph]->Draw("same pe0"); - - } - - if (_print && !_print_only_global) c_hist[ix][iy][0]->Print(_output_directory - + TString::Format("Profile_plot_%s_vs_%s_tracker_%d", x[ix].Data(), y[iy].Data(), canvas_index) - + ExtensionFromPrintOption(_print_option), - _print_option); - - //Draw into profile hists global tracker canvas - c_global_hist[0]->cd(INDEX_IN_GLOBAL_CANVAS(ix,iy)); - c_global_hist[0]->GetPad(INDEX_IN_GLOBAL_CANVAS(ix,iy))->SetFillStyle(4000); // make the pad transparent - c_global_hist[0]->GetPad(INDEX_IN_GLOBAL_CANVAS(ix,iy))->SetGrid(_grid_x,_grid_y); // grid - c_global_hist[0]->GetPad(INDEX_IN_GLOBAL_CANVAS(ix,iy))->DrawFrame(_min[x[ix]], - dyMin[iy] != -99999 ? dyMin[iy] : _min[y[iy]], - _max[x[ix]], - dyMax[iy] != -99999 ? dyMax[iy] : _max[y[iy]], - TString (";") + LateXstyle(x[ix]) + " /" + _units[x[ix]] - + TString (";") + LateXstyle(y[iy]) + " /" + _units[y[iy]]); - - for (unsigned short int jgraph = 0 ; jgraph < NB_SUBLEVELS*NB_Z_SLICES ; jgraph++) - { - unsigned short int igraph = NB_SUBLEVELS*NB_Z_SLICES - jgraph - 1; // reverse counting for humane readability (one of the sublevel takes much more place than the others) - histosTracker[ix][iy][igraph]->Draw("same pe0"); - } - - /// PIXEL - // fixing ranges and draw profile plot histos - - c_hist[ix][iy][7] = new TCanvas (TString::Format("c_hist_%s_vs_%s_pixel_%d", x[ix].Data(), - y[iy].Data(), - canvas_index), - TString::Format("Profile plot %s vs. %s at pixel level", x[ix].Data(), - y[iy].Data()), - _window_width, - _window_height); - c_hist[ix][iy][7]->SetGrid(_grid_x,_grid_y); // grid - // Draw the frame that will contain the histograms - // One needs to specify the binning and title - c_hist[ix][iy][7]->GetPad(0)->DrawFrame(_min[x[ix]], - dyMin[iy] != -99999 ? dyMin[iy] : _min[y[iy]], - _max[x[ix]], - dyMax[iy] != -99999 ? dyMax[iy] : _max[y[iy]], - TString (";") + LateXstyle(x[ix]) + " /" + _units[x[ix]] - + TString (";") + LateXstyle(y[iy]) + " /" + _units[y[iy]]); - if (_legend) legend->Draw("same"); - - for (unsigned short int jgraph = 0 ; jgraph < NB_SUBLEVELS*NB_Z_SLICES ; jgraph++) - { - unsigned short int igraph = NB_SUBLEVELS*NB_Z_SLICES - jgraph - 1; // reverse counting for humane readability (one of the sublevel takes much more place than the others) - - if (igraph%NB_SUBLEVELS == 0 || igraph%NB_SUBLEVELS == 1) //Only BPIX and FPIX - { - // clone to prevent any injure on the graph - histosTracker[ix][iy][igraph] = (TH1F *) histos[ix][iy][igraph]->Clone(); - // color - histosTracker[ix][iy][igraph]->SetMarkerColor(COLOR_CODE(igraph%NB_SUBLEVELS)); - histosTracker[ix][iy][igraph]->SetLineColor(COLOR_CODE(igraph%NB_SUBLEVELS)); - histosTracker[ix][iy][igraph]->SetMarkerStyle(6); - histosTracker[ix][iy][igraph]->Draw("same pe0"); - } - - } - - if (_print && !_print_only_global) c_hist[ix][iy][7]->Print(_output_directory - + TString::Format("Profile_plot_%s_vs_%s_pixel_%d", x[ix].Data(), y[iy].Data(), canvas_index) - + ExtensionFromPrintOption(_print_option), - _print_option); - - //Draw into profile hists global tracker canvas - c_global_hist[7]->cd(INDEX_IN_GLOBAL_CANVAS(ix,iy)); - c_global_hist[7]->GetPad(INDEX_IN_GLOBAL_CANVAS(ix,iy))->SetFillStyle(4000); // make the pad transparent - c_global_hist[7]->GetPad(INDEX_IN_GLOBAL_CANVAS(ix,iy))->SetGrid(_grid_x,_grid_y); // grid - c_global_hist[7]->GetPad(INDEX_IN_GLOBAL_CANVAS(ix,iy))->DrawFrame(_min[x[ix]], - dyMin[iy] != -99999 ? dyMin[iy] : _min[y[iy]], - _max[x[ix]], - dyMax[iy] != -99999 ? dyMax[iy] : _max[y[iy]], - TString (";") + LateXstyle(x[ix]) + " /" + _units[x[ix]] - + TString (";") + LateXstyle(y[iy]) + " /" + _units[y[iy]]); - - for (unsigned short int jgraph = 0 ; jgraph < NB_SUBLEVELS*NB_Z_SLICES ; jgraph++) - { - unsigned short int igraph = NB_SUBLEVELS*NB_Z_SLICES - jgraph - 1; // reverse counting for humane readability (one of the sublevel takes much more place than the others) - histosTracker[ix][iy][igraph]->Draw("same pe0"); - } - // printing will be performed after customisation (e.g. legend or title) just after the loops on ix and iy - /// SUBLEVELS (1..6) - for (unsigned int isublevel = 1 ; isublevel <= NB_SUBLEVELS ; isublevel++) - { - - // Draw and print profile histograms - c_hist[ix][iy][isublevel] = new TCanvas (TString::Format("c_hist_%s_vs_%s_%s_%d", x[ix].Data(), - y[iy].Data(), - isublevel==0?"tracker":_sublevel_names[isublevel-1].Data(), - canvas_index), - TString::Format("Profile plot %s vs. %s at %s level", x[ix].Data(), - y[iy].Data(), - isublevel==0?"tracker":_sublevel_names[isublevel-1].Data()), - _window_width, - _window_height); - c_hist[ix][iy][isublevel]->SetGrid(_grid_x,_grid_y); // grid - c_hist[ix][iy][isublevel]->GetPad(0)->DrawFrame(_min[x[ix]], - dyMin[iy] != -99999 ? dyMin[iy] : _min[y[iy]], - _max[x[ix]], - dyMax[iy] != -99999 ? dyMax[iy] : _max[y[iy]], - TString (";") + LateXstyle(x[ix]) + " /" + _units[x[ix]] - + TString (";") + LateXstyle(y[iy]) + " /" + _units[y[iy]]); - - histos[ix][iy][ isublevel-1]->SetMarkerColor(kBlack); - histos[ix][iy][ isublevel-1]->SetLineColor(kBlack); - histos[ix][iy][NB_SUBLEVELS+isublevel-1]->SetMarkerColor(kRed); - histos[ix][iy][NB_SUBLEVELS+isublevel-1]->SetLineColor(kRed); - - - histos[ix][iy][ isublevel-1]->Draw("same pe0"); - histos[ix][iy][NB_SUBLEVELS+isublevel-1]->Draw("same pe0"); - - if (_print && !_print_only_global) c_hist[ix][iy][isublevel]->Print(_output_directory - + TString::Format("Profile_plot_%s_vs_%s_%s_%d", x[ix].Data(), y[iy].Data(),_sublevel_names[isublevel-1].Data(), canvas_index) - + ExtensionFromPrintOption(_print_option), - _print_option); - - // draw into global canvas - // printing will be performed after customisation (e.g. legend or title) just after the loops on ix and iy - c_global_hist[isublevel]->cd(INDEX_IN_GLOBAL_CANVAS(ix,iy)); - c_global_hist[isublevel]->GetPad(INDEX_IN_GLOBAL_CANVAS(ix,iy))->SetFillStyle(4000); // make the pad transparent - c_global_hist[isublevel]->GetPad(INDEX_IN_GLOBAL_CANVAS(ix,iy))->SetGrid(_grid_x,_grid_y); // grid - c_global_hist[isublevel]->GetPad(INDEX_IN_GLOBAL_CANVAS(ix,iy))->DrawFrame(_min[x[ix]], - dyMin[iy] != -99999 ? dyMin[iy] : _min[y[iy]], - _max[x[ix]], - dyMax[iy] != -99999 ? dyMax[iy] : _max[y[iy]], - TString (";") + LateXstyle(x[ix]) + " /" + _units[x[ix]] - + TString (";") + LateXstyle(y[iy]) + " /" + _units[y[iy]]); - - - histos[ix][iy][ isublevel-1]->Draw("same pe0"); - histos[ix][iy][NB_SUBLEVELS+isublevel-1]->Draw("same pe0"); - } - - } // end of loop on y - } // end of loop on x - - - - // CUSTOMISATION - gStyle->SetOptTitle(0); // otherwise, the title is repeated in every pad of the global canvases - // -> instead, we will write it in the upper part in a TPaveText or in a TLegend - for (unsigned int ic = 0 ; ic <= NB_SUBLEVELS ; ic++) - { - // setting legend to tracker canvases - if (!_legend) break; - - // setting legend to tracker canvases - if (!_legend) break; - TCanvas * c_temp_hist = (TCanvas *) c_global_hist[ic]->Clone(c_global_hist[ic]->GetTitle() + TString("_sub")); - c_temp_hist->Draw(); - c_global_hist[ic] = new TCanvas (c_temp_hist->GetName() + TString("_final"), c_temp_hist->GetTitle(), c_temp_hist->GetWindowWidth(), c_temp_hist->GetWindowHeight()); - c_global_hist[ic]->Draw(); - TPad * p_up = new TPad (TString("legend_") + c_temp_hist->GetName(), "", - 0., 0.9, 1., 1., // relative position - -1, 0, 0), // display options - * p_down = new TPad (TString("main_") + c_temp_hist->GetName(), "", - 0., 0., 1., 0.9, - -1, 0, 0); - // in the lower part, draw the plots - p_down->Draw(); - p_down->cd(); - c_temp_hist->DrawClonePad(); - c_global_hist[ic]->cd(); - // in the upper part, pimp the canvas :p - p_up->Draw(); - p_up->cd(); - if (ic == 0) // tracker - { - TLegend * global_legend = MakeLegend(.05,.1,.7,.8,NB_SUBLEVELS);//, "brNDC"); - global_legend->Draw(); - TPaveText * pt_geom = new TPaveText(.75,.1,.95,.8, "NB"); - pt_geom->SetFillColor(0); - pt_geom->SetTextSize(0.25); - pt_geom->AddText(TString("x: ")+_reference_name); - pt_geom->AddText(TString("y: ")+_alignment_name+TString(" - ")+_reference_name); - pt_geom->Draw(); - } - else if (ic == 7) // pixel - { - TLegend * global_legend = MakeLegend(.05,.1,.7,.8,2);//, "brNDC"); - global_legend->Draw(); - TPaveText * pt_geom = new TPaveText(.75,.1,.95,.8, "NB"); - pt_geom->SetFillColor(0); - pt_geom->SetTextSize(0.25); - pt_geom->AddText(TString("x: ")+_reference_name); - pt_geom->AddText(TString("y: ")+_alignment_name+TString(" - ")+_reference_name); - pt_geom->Draw(); - } - else // sublevels - { - TPaveText * pt = new TPaveText(.05,.1,.7,.8, "NB"); - pt->SetFillColor(0); - pt->AddText(_sublevel_names[ic-1]); - pt->Draw(); - TPaveText * pt_geom = new TPaveText(.6,.1,.95,.8, "NB"); - pt_geom->SetFillColor(0); - pt_geom->SetTextSize(0.3); - pt_geom->AddText(TString("x: ")+_reference_name); - pt_geom->AddText(TString("y: ")+_alignment_name+TString(" - ")+_reference_name); - pt_geom->Draw(); - } - // printing - if (_print) c_global_hist[ic]->Print(_output_directory + c_global_hist[ic]->GetName() + ExtensionFromPrintOption(_print_option), _print_option); - } - - } - + } + #ifdef TALKATIVE - cout << __FILE__ << ":" << __LINE__ << ":Info: End of MakePlots method" << endl; + cout << __FILE__ << ":" << __LINE__ << ":Info: End of MakePlots method" << endl; #endif - } - // Make additional table for the mean/RMS values of differences -void GeometryComparisonPlotter::MakeTables (vector x, // axes to combine to plot - vector y, // only requires the differences (y values in the plots) and ranges - vector dyMin, // Minimum of y-variable to enable fixed ranges of the histogram - vector dyMax) // Maximum of y-variable to enable fixed ranges of the histogram +void GeometryComparisonPlotter::MakeTables( + vector x, // axes to combine to plot + vector y, // only requires the differences (y values in the plots) and ranges + vector dyMin, // Minimum of y-variable to enable fixed ranges of the histogram + vector dyMax) // Maximum of y-variable to enable fixed ranges of the histogram { - - /// -1) check that only existing branches are called - // (we use a macro to avoid copy/paste) -#define CHECK_BRANCHES(branchname_vector) \ - for (unsigned int i = 0 ; i < branchname_vector.size() ; i++) \ - { \ - if (branch_f.find(branchname_vector[i]) == branch_f.end()) \ - { \ - cout << __FILE__ << ":" << __LINE__ << ":Error: The branch " << branchname_vector[i] << " is not recognised." << endl; \ - return; \ - } \ - } - CHECK_BRANCHES(x); - CHECK_BRANCHES(y); - - const unsigned int nentries = data->GetEntries(); + /// -1) check that only existing branches are called + // (we use a macro to avoid copy/paste) +#define CHECK_BRANCHES(branchname_vector) \ + for (unsigned int i = 0; i < branchname_vector.size(); i++) { \ + if (branch_f.find(branchname_vector[i]) == branch_f.end()) { \ + cout << __FILE__ << ":" << __LINE__ << ":Error: The branch " << branchname_vector[i] << " is not recognised." \ + << endl; \ + return; \ + } \ + } + CHECK_BRANCHES(x); + CHECK_BRANCHES(y); + + const unsigned int nentries = data->GetEntries(); #ifdef TALKATIVE - cout << __FILE__ << ":" << __LINE__ << ":Info: "; INSIDE_VECTOR(x); cout << endl; - cout << __FILE__ << ":" << __LINE__ << ":Info: "; INSIDE_VECTOR(y); cout << endl; + cout << __FILE__ << ":" << __LINE__ << ":Info: "; + INSIDE_VECTOR(x); + cout << endl; + cout << __FILE__ << ":" << __LINE__ << ":Info: "; + INSIDE_VECTOR(y); + cout << endl; #endif + /// 0) min and max values + // the max and min of the graphs are computed from the tree if they have not been manually input yet + // (we use a macro to avoid copy/paste) +#define LIMITS(axes_vector) \ + for (unsigned int i = 0; i < axes_vector.size(); i++) { \ + if (_SF.find(axes_vector[i]) == _SF.end()) \ + _SF[axes_vector[i]] = 1.; \ + if (_min.find(axes_vector[i]) == _min.end()) \ + _min[axes_vector[i]] = _SF[axes_vector[i]] * data->GetMinimum(axes_vector[i]); \ + if (_max.find(axes_vector[i]) == _max.end()) \ + _max[axes_vector[i]] = _SF[axes_vector[i]] * data->GetMaximum(axes_vector[i]); \ + } + LIMITS(x); + LIMITS(y); - /// 0) min and max values - // the max and min of the graphs are computed from the tree if they have not been manually input yet - // (we use a macro to avoid copy/paste) -#define LIMITS(axes_vector) \ - for (unsigned int i = 0 ; i < axes_vector.size() ; i++) \ - { \ - if ( _SF.find(axes_vector[i]) == _SF.end()) _SF[axes_vector[i]] = 1.; \ - if (_min.find(axes_vector[i]) == _min.end()) _min[axes_vector[i]] = _SF[axes_vector[i]]*data->GetMinimum(axes_vector[i]); \ - if (_max.find(axes_vector[i]) == _max.end()) _max[axes_vector[i]] = _SF[axes_vector[i]]*data->GetMaximum(axes_vector[i]); \ - } - LIMITS(x); - LIMITS(y); - -#ifdef TALKATIVE - CHECK_MAP_CONTENT(_min,float); - CHECK_MAP_CONTENT(_max,float); - CHECK_MAP_CONTENT(_SF ,float); +#ifdef TALKATIVE + CHECK_MAP_CONTENT(_min, float); + CHECK_MAP_CONTENT(_max, float); + CHECK_MAP_CONTENT(_SF, float); #endif - /// 1) declare histograms - // the idea is to produce tables of the differences and the absolute positions containing mean and RMS values - // for the different subdetectors - 0..5=different sublevels. - // Values for each endcap detector are to be split in +/-z, for the barrel detectors in +/- x (half barrels) - // Since it is easier to handle in the loops, all subdetectors will be split in - // 4 parts at first: (+/-x)X(+/-z) - // This means that 2*2*6 histograms will be filled during the loop on the TTree - // Pairs of histograms need to be combined afterwards again - // Histograms 0-5 are at +x and +z, 6-11 at +x and -z, 12-17 at -x and +z, and 18-23 at -x and -z - // - // Two version of the table containing the differences are produced. Once using Gaussian fits (more stable - // vs single outliers but perform poorly if the distributions are non-Gaussian) and once using - // the mean and RMS of the histograms (more stable but outliers have a strong impact on the RMS). - // For the absolute positions, only mean+RMS are used since the detector layout is not Gaussian - // (structures due to layers/rings etc) + /// 1) declare histograms + // the idea is to produce tables of the differences and the absolute positions containing mean and RMS values + // for the different subdetectors - 0..5=different sublevels. + // Values for each endcap detector are to be split in +/-z, for the barrel detectors in +/- x (half barrels) + // Since it is easier to handle in the loops, all subdetectors will be split in + // 4 parts at first: (+/-x)X(+/-z) + // This means that 2*2*6 histograms will be filled during the loop on the TTree + // Pairs of histograms need to be combined afterwards again + // Histograms 0-5 are at +x and +z, 6-11 at +x and -z, 12-17 at -x and +z, and 18-23 at -x and -z + // + // Two version of the table containing the differences are produced. Once using Gaussian fits (more stable + // vs single outliers but perform poorly if the distributions are non-Gaussian) and once using + // the mean and RMS of the histograms (more stable but outliers have a strong impact on the RMS). + // For the absolute positions, only mean+RMS are used since the detector layout is not Gaussian + // (structures due to layers/rings etc) #ifndef NB_SUBLEVELS #define NB_SUBLEVELS 6 #endif #define NB_Z_SLICES 2 #define NB_X_SLICES 2 - - TH1F * histosx[x.size()][NB_SUBLEVELS*NB_Z_SLICES*NB_X_SLICES]; - float meanValuex[x.size()][NB_SUBLEVELS*NB_Z_SLICES*NB_X_SLICES]; - float RMSx[x.size()][NB_SUBLEVELS*NB_Z_SLICES*NB_X_SLICES]; - - TH1F * histos[y.size()][NB_SUBLEVELS*NB_Z_SLICES*NB_X_SLICES]; - TF1 * gausFit[y.size()][NB_SUBLEVELS*NB_Z_SLICES*NB_X_SLICES]; - float meanValue[y.size()][NB_SUBLEVELS*NB_Z_SLICES*NB_X_SLICES]; - float meanValueGaussian[y.size()][NB_SUBLEVELS*NB_Z_SLICES*NB_X_SLICES]; - float RMS[y.size()][NB_SUBLEVELS*NB_Z_SLICES*NB_X_SLICES]; - float RMSGaussian[y.size()][NB_SUBLEVELS*NB_Z_SLICES*NB_X_SLICES]; - - for (unsigned int iy = 0 ; iy < y.size() ; iy++) - { - for (unsigned int ihist = 0 ; ihist < NB_SUBLEVELS*NB_Z_SLICES*NB_X_SLICES ; ihist++) - { - - // Create and correctly name a histogram for each subdetector*Z_Slice*X_Slice - histos[iy][ihist] = new TH1F ("hist"+y[iy]+_sublevel_names[ihist%NB_SUBLEVELS] - +TString(ihist%(NB_SUBLEVELS*NB_Z_SLICES)>=NB_SUBLEVELS ? "zn" : "zp" ) - +TString(ihist>=NB_SUBLEVELS*NB_Z_SLICES ? "xn" : "xp" ), - "",1000, - _min[y[iy]], - _max[y[iy]]+1.); - histos[iy][ihist]->StatOverflows(kTRUE); - - } - } - - for (unsigned int ix = 0 ; ix < x.size() ; ix++) - { - for (unsigned int ihist = 0 ; ihist < NB_SUBLEVELS*NB_Z_SLICES*NB_X_SLICES ; ihist++) - { - - // Create and correctly name a histogram for each subdetector*Z_Slice*ModuleType - histosx[ix][ihist] = new TH1F ("histx"+x[ix]+_sublevel_names[ihist%NB_SUBLEVELS] - +TString(ihist%(NB_SUBLEVELS*NB_Z_SLICES)>=NB_SUBLEVELS ? "zn" : "zp" ) - +TString(ihist>=NB_SUBLEVELS*NB_Z_SLICES ? "xn" : "xp" ), - "",1000, - _min[x[ix]], - _max[x[ix]]+1.); - histosx[ix][ihist]->StatOverflows(kTRUE); - - } - } + + TH1F *histosx[x.size()][NB_SUBLEVELS * NB_Z_SLICES * NB_X_SLICES]; + float meanValuex[x.size()][NB_SUBLEVELS * NB_Z_SLICES * NB_X_SLICES]; + float RMSx[x.size()][NB_SUBLEVELS * NB_Z_SLICES * NB_X_SLICES]; + + TH1F *histos[y.size()][NB_SUBLEVELS * NB_Z_SLICES * NB_X_SLICES]; + TF1 *gausFit[y.size()][NB_SUBLEVELS * NB_Z_SLICES * NB_X_SLICES]; + float meanValue[y.size()][NB_SUBLEVELS * NB_Z_SLICES * NB_X_SLICES]; + float meanValueGaussian[y.size()][NB_SUBLEVELS * NB_Z_SLICES * NB_X_SLICES]; + float RMS[y.size()][NB_SUBLEVELS * NB_Z_SLICES * NB_X_SLICES]; + float RMSGaussian[y.size()][NB_SUBLEVELS * NB_Z_SLICES * NB_X_SLICES]; + + for (unsigned int iy = 0; iy < y.size(); iy++) { + for (unsigned int ihist = 0; ihist < NB_SUBLEVELS * NB_Z_SLICES * NB_X_SLICES; ihist++) { + // Create and correctly name a histogram for each subdetector*Z_Slice*X_Slice + histos[iy][ihist] = new TH1F("hist" + y[iy] + _sublevel_names[ihist % NB_SUBLEVELS] + + TString(ihist % (NB_SUBLEVELS * NB_Z_SLICES) >= NB_SUBLEVELS ? "zn" : "zp") + + TString(ihist >= NB_SUBLEVELS * NB_Z_SLICES ? "xn" : "xp"), + "", + 1000, + _min[y[iy]], + _max[y[iy]] + 1.); + histos[iy][ihist]->StatOverflows(kTRUE); + } + } + + for (unsigned int ix = 0; ix < x.size(); ix++) { + for (unsigned int ihist = 0; ihist < NB_SUBLEVELS * NB_Z_SLICES * NB_X_SLICES; ihist++) { + // Create and correctly name a histogram for each subdetector*Z_Slice*ModuleType + histosx[ix][ihist] = new TH1F("histx" + x[ix] + _sublevel_names[ihist % NB_SUBLEVELS] + + TString(ihist % (NB_SUBLEVELS * NB_Z_SLICES) >= NB_SUBLEVELS ? "zn" : "zp") + + TString(ihist >= NB_SUBLEVELS * NB_Z_SLICES ? "xn" : "xp"), + "", + 1000, + _min[x[ix]], + _max[x[ix]] + 1.); + histosx[ix][ihist]->StatOverflows(kTRUE); + } + } #ifdef DEBUG - cout << __FILE__ << ":" << __LINE__ << ":Info: Creation of the TH1F[" << y.size() << "][" << NB_SUBLEVELS*NB_Z_SLICES*NB_X_SLICES << "] ended." << endl; + cout << __FILE__ << ":" << __LINE__ << ":Info: Creation of the TH1F[" << y.size() << "][" + << NB_SUBLEVELS * NB_Z_SLICES * NB_X_SLICES << "] ended." << endl; #endif - /// 2) loop on the TTree data + /// 2) loop on the TTree data #ifdef DEBUG - cout << __FILE__ << ":" << __LINE__ << ":Info: Looping on the TTree" << endl; + cout << __FILE__ << ":" << __LINE__ << ":Info: Looping on the TTree" << endl; #endif #ifdef TALKATIVE - unsigned int progress = 0; - cout << __FILE__ << ":" << __LINE__ << ":Info: 0%" << endl; + unsigned int progress = 0; + cout << __FILE__ << ":" << __LINE__ << ":Info: 0%" << endl; #endif - for (unsigned int ientry = 0 ; ientry < nentries ; ientry++) - { -#ifdef TALKATIVE - if (10*ientry/nentries != progress) - { - progress = 10*ientry/nentries; - cout << __FILE__ << ":" << __LINE__ << ":Info: " << 10*progress << "%" << endl; - } + for (unsigned int ientry = 0; ientry < nentries; ientry++) { +#ifdef TALKATIVE + if (10 * ientry / nentries != progress) { + progress = 10 * ientry / nentries; + cout << __FILE__ << ":" << __LINE__ << ":Info: " << 10 * progress << "%" << endl; + } #endif - // load current tree entry - data->GetEntry(ientry); - - // CUTS on entry - if (branch_i["level"] != _levelCut) continue; - if (!_1dModule && branch_i["detDim"] == 1) continue; - if (!_2dModule && branch_i["detDim"] == 2) continue; - - - for (unsigned int iy = 0 ; iy < y.size() ; iy++) - { - if (branch_i["sublevel"] < 1 || branch_i["sublevel"] > NB_SUBLEVELS) continue; - if (_SF[y[iy]]*branch_f[y[iy]] > _max[y[iy]] || _SF[y[iy]]*branch_f[y[iy]] < _min[y[iy]]) - { -//#ifdef DEBUG -// cout << "branch_f[y[iy]]=" << branch_f[y[iy]] << endl; -//#endif - continue; - } - - // FILLING HISTOGRAMS - - // histogram for all modules - const short int ihisto = (branch_i["sublevel"]-1) + (branch_f["z"]>=0?0:NB_SUBLEVELS) + (branch_f["x"]>=0?0:NB_SUBLEVELS*NB_Z_SLICES); - - if (_module_plot_option == "all") histos[iy][ihisto]->Fill( _SF[y[iy]]*branch_f[y[iy]]); - - // Only good modules - else if (_module_plot_option == "good" && branch_i["badModuleQuality"]==0) histos[iy][ihisto]->Fill( _SF[y[iy]]*branch_f[y[iy]]); - - // Only good modules and those in the list - else if (_module_plot_option == "list" && (branch_i["inModuleList"]==1 || branch_i["badModuleQuality"]==0)) histos[iy][ihisto]->Fill( _SF[y[iy]]*branch_f[y[iy]]); - - } - - for (unsigned int ix = 0 ; ix < x.size() ; ix++) - { - if (branch_i["sublevel"] < 1 || branch_i["sublevel"] > NB_SUBLEVELS) continue; - if (_SF[x[ix]]*branch_f[x[ix]] > _max[x[ix]] || _SF[x[ix]]*branch_f[x[ix]] < _min[x[ix]]) - { -//#ifdef DEBUG -// cout << "branch_f[y[iy]]=" << branch_f[y[iy]] << endl; -//#endif - continue; - } - - // FILLING HISTOGRAMS - - // histogram for all modules - const short int ihistosx = (branch_i["sublevel"]-1) + (branch_f["z"]>=0?0:NB_SUBLEVELS) + (branch_f["x"]>=0?0:NB_SUBLEVELS*NB_Z_SLICES); - - if (_module_plot_option == "all") histosx[ix][ihistosx]->Fill( _SF[x[ix]]*branch_f[x[ix]]); - - // Only good modules - else if (_module_plot_option == "good" && branch_i["badModuleQuality"]==0) histosx[ix][ihistosx]->Fill( _SF[x[ix]]*branch_f[x[ix]]); - - // Only good modules and those in the list - else if (_module_plot_option == "list" && (branch_i["inModuleList"]==1 || branch_i["badModuleQuality"]==0)) histosx[ix][ihistosx]->Fill( _SF[x[ix]]*branch_f[x[ix]]); - - } + // load current tree entry + data->GetEntry(ientry); + + // CUTS on entry + if (branch_i["level"] != _levelCut) + continue; + if (!_1dModule && branch_i["detDim"] == 1) + continue; + if (!_2dModule && branch_i["detDim"] == 2) + continue; + + for (unsigned int iy = 0; iy < y.size(); iy++) { + if (branch_i["sublevel"] < 1 || branch_i["sublevel"] > NB_SUBLEVELS) + continue; + if (_SF[y[iy]] * branch_f[y[iy]] > _max[y[iy]] || _SF[y[iy]] * branch_f[y[iy]] < _min[y[iy]]) { + //#ifdef DEBUG + // cout << "branch_f[y[iy]]=" << branch_f[y[iy]] << endl; + //#endif + continue; + } + + // FILLING HISTOGRAMS + + // histogram for all modules + const short int ihisto = (branch_i["sublevel"] - 1) + (branch_f["z"] >= 0 ? 0 : NB_SUBLEVELS) + + (branch_f["x"] >= 0 ? 0 : NB_SUBLEVELS * NB_Z_SLICES); + + if (_module_plot_option == "all") + histos[iy][ihisto]->Fill(_SF[y[iy]] * branch_f[y[iy]]); + + // Only good modules + else if (_module_plot_option == "good" && branch_i["badModuleQuality"] == 0) + histos[iy][ihisto]->Fill(_SF[y[iy]] * branch_f[y[iy]]); + + // Only good modules and those in the list + else if (_module_plot_option == "list" && (branch_i["inModuleList"] == 1 || branch_i["badModuleQuality"] == 0)) + histos[iy][ihisto]->Fill(_SF[y[iy]] * branch_f[y[iy]]); + } + + for (unsigned int ix = 0; ix < x.size(); ix++) { + if (branch_i["sublevel"] < 1 || branch_i["sublevel"] > NB_SUBLEVELS) + continue; + if (_SF[x[ix]] * branch_f[x[ix]] > _max[x[ix]] || _SF[x[ix]] * branch_f[x[ix]] < _min[x[ix]]) { + //#ifdef DEBUG + // cout << "branch_f[y[iy]]=" << branch_f[y[iy]] << endl; + //#endif + continue; + } + + // FILLING HISTOGRAMS + + // histogram for all modules + const short int ihistosx = (branch_i["sublevel"] - 1) + (branch_f["z"] >= 0 ? 0 : NB_SUBLEVELS) + + (branch_f["x"] >= 0 ? 0 : NB_SUBLEVELS * NB_Z_SLICES); + + if (_module_plot_option == "all") + histosx[ix][ihistosx]->Fill(_SF[x[ix]] * branch_f[x[ix]]); + + // Only good modules + else if (_module_plot_option == "good" && branch_i["badModuleQuality"] == 0) + histosx[ix][ihistosx]->Fill(_SF[x[ix]] * branch_f[x[ix]]); + + // Only good modules and those in the list + else if (_module_plot_option == "list" && (branch_i["inModuleList"] == 1 || branch_i["badModuleQuality"] == 0)) + histosx[ix][ihistosx]->Fill(_SF[x[ix]] * branch_f[x[ix]]); } + } #ifdef TALKATIVE - cout << __FILE__ << ":" << __LINE__ << ":Info: 100%\tLoop ended" << endl; + cout << __FILE__ << ":" << __LINE__ << ":Info: 100%\tLoop ended" << endl; #endif - //~ TString rangeLabel = ""; - // Calculate mean and standard deviation for each histogram - for (unsigned int iy = 0 ; iy < y.size() ; iy++) - { - - for (unsigned int ihist = 0 ; ihist < NB_SUBLEVELS*NB_Z_SLICES*NB_X_SLICES ; ihist++) - { - // combine +/-z histograms for barrel detectors - if (ihist%(NB_SUBLEVELS*NB_Z_SLICES) == 0 || ihist%(NB_SUBLEVELS*NB_Z_SLICES) == 2 || ihist%(NB_SUBLEVELS*NB_Z_SLICES) == 4) { - histos[iy][ihist]->Add(histos[iy][ihist+NB_SUBLEVELS]); - } - // combine +/-x histograms for endcap detectors (only used for half shells in barrel) - if (ihist < NB_SUBLEVELS*NB_Z_SLICES && ( ihist%NB_SUBLEVELS == 1 || ihist%NB_SUBLEVELS == 3 || ihist%NB_SUBLEVELS == 5)) { - histos[iy][ihist]->Add(histos[iy][ihist+NB_SUBLEVELS*NB_Z_SLICES]); - } - meanValue[iy][ihist] = histos[iy][ihist]->GetMean(); - RMS[iy][ihist] = histos[iy][ihist]->GetRMS(); - - histos[iy][ihist]->Fit("gaus"); - gausFit[iy][ihist] = histos[iy][ihist]->GetFunction("gaus"); - meanValueGaussian[iy][ihist] = gausFit[iy][ihist]->GetParameter(1); - RMSGaussian[iy][ihist] = gausFit[iy][ihist]->GetParameter(2); - - - - } - } - - for (unsigned int ix = 0 ; ix < x.size() ; ix++) - { - - for (unsigned int ihist = 0 ; ihist < NB_SUBLEVELS*NB_Z_SLICES*NB_X_SLICES ; ihist++) - { - // combine +/-z histograms for barrel detectors - if (ihist%(NB_SUBLEVELS*NB_Z_SLICES) == 0 || ihist%(NB_SUBLEVELS*NB_Z_SLICES) == 2 || ihist%(NB_SUBLEVELS*NB_Z_SLICES) == 4) { - histosx[ix][ihist]->Add(histosx[ix][ihist+NB_SUBLEVELS]); - } - // combine +/-x histograms for endcap detectors (only used for half shells in barrel) - if (ihist < NB_SUBLEVELS*NB_Z_SLICES && ( ihist%NB_SUBLEVELS == 1 || ihist%NB_SUBLEVELS == 3 || ihist%NB_SUBLEVELS == 5) ) { - histosx[ix][ihist]->Add(histosx[ix][ihist+NB_SUBLEVELS*NB_Z_SLICES]); - } - meanValuex[ix][ihist] = histosx[ix][ihist]->GetMean(); - RMSx[ix][ihist] = histosx[ix][ihist]->GetRMS(); - - } - } - - TString tableFileName,tableCaption,tableAlign,tableHeadline; - TString PXBpLine,PXBmLine,PXFpLine,PXFmLine,TIBpLine,TIBmLine,TOBpLine,TOBmLine,TIDpLine,TIDmLine,TECpLine,TECmLine; - - - // table using mean and RMS, round to integers in µm etc. - tableFileName = "table_differences.tex"; - if (_module_plot_option == "all") tableCaption = "Means and standard deviations of "+_alignment_name+" - "+_reference_name+" for each subdetector, all modules used."; - else if (_module_plot_option == "good") tableCaption = "Means and standard deviations of "+_alignment_name+" - "+_reference_name+" for each subdetector, only good modules used."; - else if (_module_plot_option == "list") tableCaption = "Means and standard deviations of "+_alignment_name+" - "+_reference_name+" for each subdetector, good modules and those in given list used."; - - WriteTable(y,NB_SUBLEVELS*NB_Z_SLICES*NB_X_SLICES,meanValue,RMS,"0",tableCaption,tableFileName); - - - //~ // table using Gaussian fit, round to integers in µm etc. - tableFileName = "table_differences_Gaussian.tex"; - if (_module_plot_option == "all") tableCaption = "Means and standard deviations for Gaussian fit of "+_alignment_name+" - "+_reference_name+" for each subdetector, all modules used."; - else if (_module_plot_option == "good") tableCaption = "Means and standard deviations for Gaussian fit of "+_alignment_name+" - "+_reference_name+" for each subdetector, only good modules used."; - else if (_module_plot_option == "list") tableCaption = "Means and standard deviations for Gaussian fit of "+_alignment_name+" - "+_reference_name+" for each subdetector, good modules and those in given list used."; - - - WriteTable(y,NB_SUBLEVELS*NB_Z_SLICES*NB_X_SLICES,meanValueGaussian,RMSGaussian,"0",tableCaption,tableFileName); - - - - // Table for the mean positions on the x-axis, round to 3 digits in cm etc. - tableFileName = "table_meanPos.tex"; - - if (_module_plot_option == "all") tableCaption = "Mean positions and standard deviations in "+_reference_name+" geometry for each subdetector, all modules used."; - else if (_module_plot_option == "good") tableCaption = "Mean positions and standard deviations in "+_reference_name+" geometry for each subdetector, only good modules used."; - else if (_module_plot_option == "list") tableCaption = "Mean positions and standard deviations in "+_reference_name+" geometry for each subdetector, good modules and those in given list used."; - - WriteTable(x,NB_SUBLEVELS*NB_Z_SLICES*NB_X_SLICES,meanValuex,RMSx,"3",tableCaption,tableFileName); - - + //~ TString rangeLabel = ""; + // Calculate mean and standard deviation for each histogram + for (unsigned int iy = 0; iy < y.size(); iy++) { + for (unsigned int ihist = 0; ihist < NB_SUBLEVELS * NB_Z_SLICES * NB_X_SLICES; ihist++) { + // combine +/-z histograms for barrel detectors + if (ihist % (NB_SUBLEVELS * NB_Z_SLICES) == 0 || ihist % (NB_SUBLEVELS * NB_Z_SLICES) == 2 || + ihist % (NB_SUBLEVELS * NB_Z_SLICES) == 4) { + histos[iy][ihist]->Add(histos[iy][ihist + NB_SUBLEVELS]); + } + // combine +/-x histograms for endcap detectors (only used for half shells in barrel) + if (ihist < NB_SUBLEVELS * NB_Z_SLICES && + (ihist % NB_SUBLEVELS == 1 || ihist % NB_SUBLEVELS == 3 || ihist % NB_SUBLEVELS == 5)) { + histos[iy][ihist]->Add(histos[iy][ihist + NB_SUBLEVELS * NB_Z_SLICES]); + } + meanValue[iy][ihist] = histos[iy][ihist]->GetMean(); + RMS[iy][ihist] = histos[iy][ihist]->GetRMS(); + + histos[iy][ihist]->Fit("gaus"); + gausFit[iy][ihist] = histos[iy][ihist]->GetFunction("gaus"); + meanValueGaussian[iy][ihist] = gausFit[iy][ihist]->GetParameter(1); + RMSGaussian[iy][ihist] = gausFit[iy][ihist]->GetParameter(2); + } + } + + for (unsigned int ix = 0; ix < x.size(); ix++) { + for (unsigned int ihist = 0; ihist < NB_SUBLEVELS * NB_Z_SLICES * NB_X_SLICES; ihist++) { + // combine +/-z histograms for barrel detectors + if (ihist % (NB_SUBLEVELS * NB_Z_SLICES) == 0 || ihist % (NB_SUBLEVELS * NB_Z_SLICES) == 2 || + ihist % (NB_SUBLEVELS * NB_Z_SLICES) == 4) { + histosx[ix][ihist]->Add(histosx[ix][ihist + NB_SUBLEVELS]); + } + // combine +/-x histograms for endcap detectors (only used for half shells in barrel) + if (ihist < NB_SUBLEVELS * NB_Z_SLICES && + (ihist % NB_SUBLEVELS == 1 || ihist % NB_SUBLEVELS == 3 || ihist % NB_SUBLEVELS == 5)) { + histosx[ix][ihist]->Add(histosx[ix][ihist + NB_SUBLEVELS * NB_Z_SLICES]); + } + meanValuex[ix][ihist] = histosx[ix][ihist]->GetMean(); + RMSx[ix][ihist] = histosx[ix][ihist]->GetRMS(); + } + } + + TString tableFileName, tableCaption, tableAlign, tableHeadline; + TString PXBpLine, PXBmLine, PXFpLine, PXFmLine, TIBpLine, TIBmLine, TOBpLine, TOBmLine, TIDpLine, TIDmLine, TECpLine, + TECmLine; + + // table using mean and RMS, round to integers in µm etc. + tableFileName = "table_differences.tex"; + if (_module_plot_option == "all") + tableCaption = "Means and standard deviations of " + _alignment_name + " - " + _reference_name + + " for each subdetector, all modules used."; + else if (_module_plot_option == "good") + tableCaption = "Means and standard deviations of " + _alignment_name + " - " + _reference_name + + " for each subdetector, only good modules used."; + else if (_module_plot_option == "list") + tableCaption = "Means and standard deviations of " + _alignment_name + " - " + _reference_name + + " for each subdetector, good modules and those in given list used."; + + WriteTable(y, NB_SUBLEVELS * NB_Z_SLICES * NB_X_SLICES, meanValue, RMS, "0", tableCaption, tableFileName); + + //~ // table using Gaussian fit, round to integers in µm etc. + tableFileName = "table_differences_Gaussian.tex"; + if (_module_plot_option == "all") + tableCaption = "Means and standard deviations for Gaussian fit of " + _alignment_name + " - " + _reference_name + + " for each subdetector, all modules used."; + else if (_module_plot_option == "good") + tableCaption = "Means and standard deviations for Gaussian fit of " + _alignment_name + " - " + _reference_name + + " for each subdetector, only good modules used."; + else if (_module_plot_option == "list") + tableCaption = "Means and standard deviations for Gaussian fit of " + _alignment_name + " - " + _reference_name + + " for each subdetector, good modules and those in given list used."; + + WriteTable( + y, NB_SUBLEVELS * NB_Z_SLICES * NB_X_SLICES, meanValueGaussian, RMSGaussian, "0", tableCaption, tableFileName); + + // Table for the mean positions on the x-axis, round to 3 digits in cm etc. + tableFileName = "table_meanPos.tex"; + + if (_module_plot_option == "all") + tableCaption = "Mean positions and standard deviations in " + _reference_name + + " geometry for each subdetector, all modules used."; + else if (_module_plot_option == "good") + tableCaption = "Mean positions and standard deviations in " + _reference_name + + " geometry for each subdetector, only good modules used."; + else if (_module_plot_option == "list") + tableCaption = "Mean positions and standard deviations in " + _reference_name + + " geometry for each subdetector, good modules and those in given list used."; + + WriteTable(x, NB_SUBLEVELS * NB_Z_SLICES * NB_X_SLICES, meanValuex, RMSx, "3", tableCaption, tableFileName); + #ifdef TALKATIVE - cout << __FILE__ << ":" << __LINE__ << ":Info: End of MakeLegends method" << endl; + cout << __FILE__ << ":" << __LINE__ << ":Info: End of MakeLegends method" << endl; #endif - } // OPTION METHODS -void GeometryComparisonPlotter::SetPrint (const bool kPrint) { _print = kPrint ; } -void GeometryComparisonPlotter::SetLegend (const bool kLegend) { _legend = kLegend ; } -void GeometryComparisonPlotter::SetWrite (const bool kWrite) { _write = kWrite ; } -void GeometryComparisonPlotter::Set1dModule (const bool k1dModule) { _1dModule = k1dModule ; } -void GeometryComparisonPlotter::Set2dModule (const bool k2dModule) { _2dModule = k2dModule ; } -void GeometryComparisonPlotter::SetLevelCut (const int kLevelCut) { _levelCut = kLevelCut ; } -void GeometryComparisonPlotter::SetBatchMode (const bool kBatchMode) { _batchMode = kBatchMode ; } -void GeometryComparisonPlotter::SetGrid (const int kGridX, - const int kGridY) { _grid_x = kGridX ; - _grid_y = kGridY ; } -void GeometryComparisonPlotter::SetBranchMax (const TString branchname, - const float max) { _max[branchname] = max ; } -void GeometryComparisonPlotter::SetBranchMin (const TString branchname, - const float min) { _min[branchname] = min ; } -void GeometryComparisonPlotter::SetBranchSF (const TString branchname, - const float SF) { _SF[branchname] = SF ; } -void GeometryComparisonPlotter::SetBranchUnits (const TString branchname, - const TString units) { _units[branchname] = units ; } -void GeometryComparisonPlotter::SetPrintOption (const Option_t * print_option) { _print_option = print_option ; } -void GeometryComparisonPlotter::SetCanvasSize (const int window_width, - const int window_height) { _window_width = window_width ; - _window_height = window_height ; } -void GeometryComparisonPlotter::SetOutputFileName (const TString name) { _output_filename = name ; } -void GeometryComparisonPlotter::SetOutputDirectoryName (const TString name) { _output_directory = name - + TString(name.EndsWith("/") ? "" : "/") ; } +void GeometryComparisonPlotter::SetPrint(const bool kPrint) { _print = kPrint; } +void GeometryComparisonPlotter::SetLegend(const bool kLegend) { _legend = kLegend; } +void GeometryComparisonPlotter::SetWrite(const bool kWrite) { _write = kWrite; } +void GeometryComparisonPlotter::Set1dModule(const bool k1dModule) { _1dModule = k1dModule; } +void GeometryComparisonPlotter::Set2dModule(const bool k2dModule) { _2dModule = k2dModule; } +void GeometryComparisonPlotter::SetLevelCut(const int kLevelCut) { _levelCut = kLevelCut; } +void GeometryComparisonPlotter::SetBatchMode(const bool kBatchMode) { _batchMode = kBatchMode; } +void GeometryComparisonPlotter::SetGrid(const int kGridX, const int kGridY) { + _grid_x = kGridX; + _grid_y = kGridY; +} +void GeometryComparisonPlotter::SetBranchMax(const TString branchname, const float max) { _max[branchname] = max; } +void GeometryComparisonPlotter::SetBranchMin(const TString branchname, const float min) { _min[branchname] = min; } +void GeometryComparisonPlotter::SetBranchSF(const TString branchname, const float SF) { _SF[branchname] = SF; } +void GeometryComparisonPlotter::SetBranchUnits(const TString branchname, const TString units) { + _units[branchname] = units; +} +void GeometryComparisonPlotter::SetPrintOption(const Option_t *print_option) { _print_option = print_option; } +void GeometryComparisonPlotter::SetCanvasSize(const int window_width, const int window_height) { + _window_width = window_width; + _window_height = window_height; +} +void GeometryComparisonPlotter::SetOutputFileName(const TString name) { _output_filename = name; } +void GeometryComparisonPlotter::SetOutputDirectoryName(const TString name) { + _output_directory = name + TString(name.EndsWith("/") ? "" : "/"); +} // PRIVATE METHODS -TString GeometryComparisonPlotter::LateXstyle (TString word) -{ - word.ToLower(); - if (word.BeginsWith("d")) word.ReplaceAll("d", "#Delta"); - if (word == TString("rdphi")) word = "r#Delta#phi"; // TO DO: find something less ad hoc... - else if (word.EndsWith("phi")) word.ReplaceAll("phi", "#phi"); - else if (word.EndsWith("alpha")) word.ReplaceAll("alpha", "#alpha"); - else if (word.EndsWith("beta")) word.ReplaceAll("beta" , "#beta"); - else if (word.EndsWith("gamma")) word.ReplaceAll("gamma", "#gamma"); - else if (word.EndsWith("eta")) word.ReplaceAll("eta", "#eta"); - return word; +TString GeometryComparisonPlotter::LateXstyle(TString word) { + word.ToLower(); + if (word.BeginsWith("d")) + word.ReplaceAll("d", "#Delta"); + if (word == TString("rdphi")) + word = "r#Delta#phi"; // TO DO: find something less ad hoc... + else if (word.EndsWith("phi")) + word.ReplaceAll("phi", "#phi"); + else if (word.EndsWith("alpha")) + word.ReplaceAll("alpha", "#alpha"); + else if (word.EndsWith("beta")) + word.ReplaceAll("beta", "#beta"); + else if (word.EndsWith("gamma")) + word.ReplaceAll("gamma", "#gamma"); + else if (word.EndsWith("eta")) + word.ReplaceAll("eta", "#eta"); + return word; } -TString GeometryComparisonPlotter::LateXstyleTable (TString word) -{ - word.ToLower(); - if (word.BeginsWith("d")) word.ReplaceAll("d", "$\\Delta$"); - if (word == TString("rdphi")) word = "r$\\Delta\\phi$"; // TO DO: find something less ad hoc... - else if (word.EndsWith("phi")) word.ReplaceAll("phi", "$\\phi$"); - else if (word.EndsWith("alpha")) word.ReplaceAll("alpha", "$\\alpha$"); - else if (word.EndsWith("beta")) word.ReplaceAll("beta" , "$\\beta$"); - else if (word.EndsWith("gamma")) word.ReplaceAll("gamma", "#$\\gamma$"); - else if (word.EndsWith("eta")) word.ReplaceAll("eta", "$\\eta$"); - return word; +TString GeometryComparisonPlotter::LateXstyleTable(TString word) { + word.ToLower(); + if (word.BeginsWith("d")) + word.ReplaceAll("d", "$\\Delta$"); + if (word == TString("rdphi")) + word = "r$\\Delta\\phi$"; // TO DO: find something less ad hoc... + else if (word.EndsWith("phi")) + word.ReplaceAll("phi", "$\\phi$"); + else if (word.EndsWith("alpha")) + word.ReplaceAll("alpha", "$\\alpha$"); + else if (word.EndsWith("beta")) + word.ReplaceAll("beta", "$\\beta$"); + else if (word.EndsWith("gamma")) + word.ReplaceAll("gamma", "#$\\gamma$"); + else if (word.EndsWith("eta")) + word.ReplaceAll("eta", "$\\eta$"); + return word; } -TString GeometryComparisonPlotter::ExtensionFromPrintOption (TString print_option) -{ - if (print_option.Contains("pdf" )) return TString(".pdf" ); - else if (print_option.Contains("eps" )) return TString(".eps" ); - else if (print_option.Contains("ps" )) return TString(".ps" ); - else if (print_option.Contains("svg" )) return TString(".svg" ); - else if (print_option.Contains("tex" )) return TString(".tex" ); - else if (print_option.Contains("gif" )) return TString(".gif" ); - else if (print_option.Contains("xpm" )) return TString(".xpm" ); - else if (print_option.Contains("png" )) return TString(".png" ); - else if (print_option.Contains("jpg" )) return TString(".jpg" ); - else if (print_option.Contains("tiff")) return TString(".tiff"); - else if (print_option.Contains("cxx" )) return TString(".cxx" ); - else if (print_option.Contains("xml" )) return TString(".xml" ); - else if (print_option.Contains("root")) return TString(".root"); - else - { - cout << __FILE__ << ":" << __LINE__ << ":Warning: unknown format. Returning .pdf, but possibly wrong..." << endl; - return TString(".pdf"); - } +TString GeometryComparisonPlotter::ExtensionFromPrintOption(TString print_option) { + if (print_option.Contains("pdf")) + return TString(".pdf"); + else if (print_option.Contains("eps")) + return TString(".eps"); + else if (print_option.Contains("ps")) + return TString(".ps"); + else if (print_option.Contains("svg")) + return TString(".svg"); + else if (print_option.Contains("tex")) + return TString(".tex"); + else if (print_option.Contains("gif")) + return TString(".gif"); + else if (print_option.Contains("xpm")) + return TString(".xpm"); + else if (print_option.Contains("png")) + return TString(".png"); + else if (print_option.Contains("jpg")) + return TString(".jpg"); + else if (print_option.Contains("tiff")) + return TString(".tiff"); + else if (print_option.Contains("cxx")) + return TString(".cxx"); + else if (print_option.Contains("xml")) + return TString(".xml"); + else if (print_option.Contains("root")) + return TString(".root"); + else { + cout << __FILE__ << ":" << __LINE__ << ":Warning: unknown format. Returning .pdf, but possibly wrong..." << endl; + return TString(".pdf"); + } } -TLegend * GeometryComparisonPlotter::MakeLegend (double x1, - double y1, - double x2, - double y2, - int nPlottedSublevels, - const TString title) -{ - TLegend * legend = new TLegend (x1, y1, x2, y2, title.Data(), "NBNDC"); - legend->SetNColumns(nPlottedSublevels); - legend->SetFillColor(0); - legend->SetLineColor(0); // redundant with option - legend->SetLineWidth(0); // redundant with option - for (int isublevel = 0 ; isublevel < nPlottedSublevels ; isublevel++) // nPlottedSublevels is either NB_SUBLEVELS for the tracker or 2 for the pixel - { - TGraph * g = new TGraph (0); - g->SetMarkerColor(COLOR_CODE(isublevel)); - g->SetFillColor(COLOR_CODE(isublevel)); - g->SetMarkerStyle(kFullSquare); - g->SetMarkerSize(10); - legend->AddEntry(g,_sublevel_names[isublevel], "p"); - } - return legend; +TLegend *GeometryComparisonPlotter::MakeLegend( + double x1, double y1, double x2, double y2, int nPlottedSublevels, const TString title) { + TLegend *legend = new TLegend(x1, y1, x2, y2, title.Data(), "NBNDC"); + legend->SetNColumns(nPlottedSublevels); + legend->SetFillColor(0); + legend->SetLineColor(0); // redundant with option + legend->SetLineWidth(0); // redundant with option + for (int isublevel = 0; isublevel < nPlottedSublevels; + isublevel++) // nPlottedSublevels is either NB_SUBLEVELS for the tracker or 2 for the pixel + { + TGraph *g = new TGraph(0); + g->SetMarkerColor(COLOR_CODE(isublevel)); + g->SetFillColor(COLOR_CODE(isublevel)); + g->SetMarkerStyle(kFullSquare); + g->SetMarkerSize(10); + legend->AddEntry(g, _sublevel_names[isublevel], "p"); + } + return legend; } - - -void GeometryComparisonPlotter::WriteTable (vector x, - unsigned int nLevelsTimesSlices, - float meanValue[10][24], - float RMS[10][24], - const TString nDigits, - const TString tableCaption, - const TString tableFileName) -{ - std::ofstream output(_output_directory+tableFileName); - - TString tableAlign,tableHeadline; - TString PXBpLine,PXBmLine,PXFpLine,PXFmLine,TIBpLine,TIBmLine,TOBpLine,TOBmLine,TIDpLine,TIDmLine,TECpLine,TECmLine; - char meanChar[x.size()][nLevelsTimesSlices][10]; - char RMSChar[x.size()][nLevelsTimesSlices][10]; - - tableAlign = "l"; - tableHeadline = ""; - PXBpLine = "PXB x$+$"; - PXBmLine = "PXB x$-$"; - PXFpLine = "PXF z$+$"; - PXFmLine = "PXF z$-$"; - TIBpLine = "TIB x$+$"; - TIBmLine = "TIB x$-$"; - TIDpLine = "TID z$+$"; - TIDmLine = "TID z$-$"; - TOBpLine = "TOB x$+$"; - TOBmLine = "TOB x$-$"; - TECpLine = "TEC z$+$"; - TECmLine = "TEC z$-$"; - - - - for (unsigned int ix = 0 ; ix < x.size() ; ix++) - { - for (unsigned int isubDet = 0 ; isubDet < nLevelsTimesSlices; isubDet++) - { - - sprintf(meanChar[ix][isubDet],"%."+nDigits+"f",meanValue[ix][isubDet]); - sprintf(RMSChar[ix][isubDet],"%."+nDigits+"f",RMS[ix][isubDet]); - } - tableAlign += "|c"; - tableHeadline += " & " + LateXstyleTable(x[ix]) + " / " + _units[x[ix]].ReplaceAll("#mum", "$\\mu$m"); - - PXBpLine += " & $"; PXBpLine += meanChar[ix][0]; PXBpLine += "\\pm"; PXBpLine += RMSChar[ix][0]; PXBpLine += " $"; - PXBmLine += " & $"; PXBmLine += meanChar[ix][12]; PXBmLine += "\\pm"; PXBmLine += RMSChar[ix][12]; PXBmLine += " $"; - PXFpLine += " & $"; PXFpLine += meanChar[ix][1]; PXFpLine += "\\pm"; PXFpLine += RMSChar[ix][1]; PXFpLine += " $"; - PXFmLine += " & $"; PXFmLine += meanChar[ix][7]; PXFmLine += "\\pm"; PXFmLine += RMSChar[ix][7]; PXFmLine += " $"; - TIBpLine += " & $"; TIBpLine += meanChar[ix][2]; TIBpLine += "\\pm"; TIBpLine += RMSChar[ix][2]; TIBpLine += " $"; - TIBmLine += " & $"; TIBmLine += meanChar[ix][14]; TIBmLine += "\\pm"; TIBmLine += RMSChar[ix][14]; TIBmLine += " $"; - TIDpLine += " & $"; TIDpLine += meanChar[ix][3]; TIDpLine += "\\pm"; TIDpLine += RMSChar[ix][3]; TIDpLine += " $"; - TIDmLine += " & $"; TIDmLine += meanChar[ix][9]; TIDmLine += "\\pm"; TIDmLine += RMSChar[ix][9]; TIDmLine += " $"; - TOBpLine += " & $"; TOBpLine += meanChar[ix][4]; TOBpLine += "\\pm"; TOBpLine += RMSChar[ix][4]; TOBpLine += " $"; - TOBmLine += " & $"; TOBmLine += meanChar[ix][16]; TOBmLine += "\\pm"; TOBmLine += RMSChar[ix][16]; TOBmLine += " $"; - TECpLine += " & $"; TECpLine += meanChar[ix][5]; TECpLine += "\\pm"; TECpLine += RMSChar[ix][5]; TECpLine += " $"; - TECmLine += " & $"; TECmLine += meanChar[ix][11]; TECmLine += "\\pm"; TECmLine += RMSChar[ix][11]; TECmLine += " $"; - } - - // Write the table to the tex file - output << "\\begin{table}" << std::endl; - output << "\\caption{" << tableCaption << "}" << std::endl; - output << "\\begin{tabular}{"<< tableAlign <<"}" << std::endl; - output << "\\hline" << std::endl; - output << tableHeadline << " \\\\" << std::endl; - output << "\\hline" << std::endl; - output << PXBpLine << " \\\\"<< std::endl; - output << PXBmLine << " \\\\"<< std::endl; - output << PXFpLine << " \\\\"<< std::endl; - output << PXFmLine << " \\\\"<< std::endl; - output << TIBpLine << " \\\\"<< std::endl; - output << TIBmLine << " \\\\"<< std::endl; - output << TIDpLine << " \\\\"<< std::endl; - output << TIDmLine << " \\\\"<< std::endl; - output << TOBpLine << " \\\\"<< std::endl; - output << TOBmLine << " \\\\"<< std::endl; - output << TECpLine << " \\\\"<< std::endl; - output << TECmLine << " \\\\"<< std::endl; - output << "\\hline" << std::endl; - output << "\\end{tabular}" << std::endl; - output << "\\end{table}" << std::endl; - + +void GeometryComparisonPlotter::WriteTable(vector x, + unsigned int nLevelsTimesSlices, + float meanValue[10][24], + float RMS[10][24], + const TString nDigits, + const TString tableCaption, + const TString tableFileName) { + std::ofstream output(_output_directory + tableFileName); + + TString tableAlign, tableHeadline; + TString PXBpLine, PXBmLine, PXFpLine, PXFmLine, TIBpLine, TIBmLine, TOBpLine, TOBmLine, TIDpLine, TIDmLine, TECpLine, + TECmLine; + char meanChar[x.size()][nLevelsTimesSlices][10]; + char RMSChar[x.size()][nLevelsTimesSlices][10]; + + tableAlign = "l"; + tableHeadline = ""; + PXBpLine = "PXB x$+$"; + PXBmLine = "PXB x$-$"; + PXFpLine = "PXF z$+$"; + PXFmLine = "PXF z$-$"; + TIBpLine = "TIB x$+$"; + TIBmLine = "TIB x$-$"; + TIDpLine = "TID z$+$"; + TIDmLine = "TID z$-$"; + TOBpLine = "TOB x$+$"; + TOBmLine = "TOB x$-$"; + TECpLine = "TEC z$+$"; + TECmLine = "TEC z$-$"; + + for (unsigned int ix = 0; ix < x.size(); ix++) { + for (unsigned int isubDet = 0; isubDet < nLevelsTimesSlices; isubDet++) { + sprintf(meanChar[ix][isubDet], "%." + nDigits + "f", meanValue[ix][isubDet]); + sprintf(RMSChar[ix][isubDet], "%." + nDigits + "f", RMS[ix][isubDet]); + } + tableAlign += "|c"; + tableHeadline += " & " + LateXstyleTable(x[ix]) + " / " + _units[x[ix]].ReplaceAll("#mum", "$\\mu$m"); + + PXBpLine += " & $"; + PXBpLine += meanChar[ix][0]; + PXBpLine += "\\pm"; + PXBpLine += RMSChar[ix][0]; + PXBpLine += " $"; + PXBmLine += " & $"; + PXBmLine += meanChar[ix][12]; + PXBmLine += "\\pm"; + PXBmLine += RMSChar[ix][12]; + PXBmLine += " $"; + PXFpLine += " & $"; + PXFpLine += meanChar[ix][1]; + PXFpLine += "\\pm"; + PXFpLine += RMSChar[ix][1]; + PXFpLine += " $"; + PXFmLine += " & $"; + PXFmLine += meanChar[ix][7]; + PXFmLine += "\\pm"; + PXFmLine += RMSChar[ix][7]; + PXFmLine += " $"; + TIBpLine += " & $"; + TIBpLine += meanChar[ix][2]; + TIBpLine += "\\pm"; + TIBpLine += RMSChar[ix][2]; + TIBpLine += " $"; + TIBmLine += " & $"; + TIBmLine += meanChar[ix][14]; + TIBmLine += "\\pm"; + TIBmLine += RMSChar[ix][14]; + TIBmLine += " $"; + TIDpLine += " & $"; + TIDpLine += meanChar[ix][3]; + TIDpLine += "\\pm"; + TIDpLine += RMSChar[ix][3]; + TIDpLine += " $"; + TIDmLine += " & $"; + TIDmLine += meanChar[ix][9]; + TIDmLine += "\\pm"; + TIDmLine += RMSChar[ix][9]; + TIDmLine += " $"; + TOBpLine += " & $"; + TOBpLine += meanChar[ix][4]; + TOBpLine += "\\pm"; + TOBpLine += RMSChar[ix][4]; + TOBpLine += " $"; + TOBmLine += " & $"; + TOBmLine += meanChar[ix][16]; + TOBmLine += "\\pm"; + TOBmLine += RMSChar[ix][16]; + TOBmLine += " $"; + TECpLine += " & $"; + TECpLine += meanChar[ix][5]; + TECpLine += "\\pm"; + TECpLine += RMSChar[ix][5]; + TECpLine += " $"; + TECmLine += " & $"; + TECmLine += meanChar[ix][11]; + TECmLine += "\\pm"; + TECmLine += RMSChar[ix][11]; + TECmLine += " $"; + } + + // Write the table to the tex file + output << "\\begin{table}" << std::endl; + output << "\\caption{" << tableCaption << "}" << std::endl; + output << "\\begin{tabular}{" << tableAlign << "}" << std::endl; + output << "\\hline" << std::endl; + output << tableHeadline << " \\\\" << std::endl; + output << "\\hline" << std::endl; + output << PXBpLine << " \\\\" << std::endl; + output << PXBmLine << " \\\\" << std::endl; + output << PXFpLine << " \\\\" << std::endl; + output << PXFmLine << " \\\\" << std::endl; + output << TIBpLine << " \\\\" << std::endl; + output << TIBmLine << " \\\\" << std::endl; + output << TIDpLine << " \\\\" << std::endl; + output << TIDmLine << " \\\\" << std::endl; + output << TOBpLine << " \\\\" << std::endl; + output << TOBmLine << " \\\\" << std::endl; + output << TECpLine << " \\\\" << std::endl; + output << TECmLine << " \\\\" << std::endl; + output << "\\hline" << std::endl; + output << "\\end{tabular}" << std::endl; + output << "\\end{table}" << std::endl; }