File indexing completed on 2021-02-14 12:44:19
0001 #include "DrawIteration.h"
0002
0003
0004 #include <iostream>
0005 #include <iomanip>
0006 #include <sstream>
0007
0008 #include <cmath>
0009
0010 #include "TTree.h"
0011 #include "TBranch.h"
0012 #include "TCanvas.h"
0013 #include "TAxis.h"
0014 #include "TH1F.h"
0015
0016 #include "TROOT.h"
0017 #include "TStyle.h"
0018 #include "TGaxis.h"
0019 #include "TLegend.h"
0020
0021 #include "TLatex.h"
0022
0023
0024
0025
0026 DrawIteration::DrawIteration(unsigned int iterationNumber, const bool overlayMode):
0027 outpath_(nullptr), file_(nullptr), overlayMode_(overlayMode), yAxisFixed_(false), systematics_(false), cmsText_("")
0028 {
0029 if(!overlayMode_){
0030 std::stringstream ss_inpath;
0031 ss_inpath<<"$CMSSW_BASE/src/Alignment/APEEstimation/hists/workingArea/iter"<<iterationNumber<<"/";
0032 const TString* inpath = new TString(ss_inpath.str().c_str());
0033 outpath_ = new TString(inpath->Copy().Append("plots/"));
0034 const TString* fileName = new TString(inpath->Copy().Append("allData_iterationApe.root"));
0035 delete inpath;
0036
0037 std::cout<<"Outpath: "<<*outpath_<<"\n";
0038 std::cout<<"File name: "<<*fileName<<"\n";
0039
0040 file_ = new TFile(*fileName, "READ");
0041 if(!file_){
0042
0043 std::cout<<"\n\tInput file not found, please check file name: "<<*fileName<<"\n";
0044 }
0045 delete fileName;
0046 }
0047 else{
0048 outpath_ = new TString("$CMSSW_BASE/src/Alignment/APEEstimation/hists/comparison/");
0049 std::cout<<"Outpath: "<<*outpath_<<"\n";
0050 std::cout<<"Overlay mode, provide input files, and output directory\n\n";
0051 }
0052 }
0053
0054
0055
0056 DrawIteration::~DrawIteration(){
0057 if(file_)file_->Close();
0058 if(outpath_)delete outpath_;
0059 }
0060
0061
0062
0063 void DrawIteration::drawIteration(unsigned int iSectorLow, unsigned int iSectorHigh){
0064
0065 sectorValues_ = this->getSectorValues(file_);
0066
0067
0068 ExtremeValues extremeValuesX(this->getGraphs("x", iSectorLow, iSectorHigh));
0069 ExtremeValues extremeValuesY(this->getGraphs("y", iSectorLow, iSectorHigh));
0070
0071
0072 std::stringstream ss_sectorInterval;
0073 ss_sectorInterval<< "_" << iSectorLow << "_" << iSectorHigh;
0074 this->drawCorrections("x", extremeValuesX, ss_sectorInterval.str());
0075 this->drawCorrections("y", extremeValuesY, ss_sectorInterval.str());
0076
0077
0078 this->printFinalValues(iSectorLow, iSectorHigh);
0079
0080
0081 this->clear();
0082 }
0083
0084
0085
0086 void DrawIteration::drawResult(){
0087
0088 if(!overlayMode_){
0089 sectorValues_ = this->getSectorValues(file_);
0090 }
0091 else{
0092 std::vector<Input*>::iterator i_input;
0093 for(i_input = v_input_.begin(); i_input != v_input_.end(); ++i_input){
0094 (*i_input)->sectorValues = this->getSectorValues((*i_input)->file);
0095 }
0096 }
0097
0098
0099 v_resultHist_ = this->arrangeHists();
0100
0101
0102 this->drawFinals("x");
0103 this->drawFinals("y");
0104
0105
0106 this->clear();
0107 }
0108
0109
0110
0111 DrawIteration::SectorValues DrawIteration::getSectorValues(TFile* file){
0112 SectorValues sectorValues;
0113
0114
0115 TTree* nameTree(nullptr);
0116 file->GetObject("nameTree", nameTree);
0117 if(!nameTree)std::cout<<"\n\tTTree with names of sectors not found in file!\n";
0118 TTree* treeX(nullptr);
0119 file->GetObject("iterTreeX", treeX);
0120 if(!treeX)std::cout<<"\n\tTTree with iteration x values of APE not found in file!\n";
0121 TTree* treeY(nullptr);
0122 file->GetObject("iterTreeY", treeY);
0123 if(!treeY)std::cout<<"\n\tTTree with iteration y values of APE not found in file!\n";
0124
0125 unsigned int nSector(0);
0126 std::map<unsigned int, TBranch*> m_branchName;
0127 std::map<unsigned int, TBranch*> m_branchX;
0128 std::map<unsigned int, TBranch*> m_branchY;
0129 bool sectorBool(true);
0130 for(unsigned int iSector(1); sectorBool; ++iSector){
0131 std::stringstream sectorName, fullSectorName;
0132 sectorName << "Ape_Sector_" << iSector;
0133 TBranch* branchName(nullptr);
0134 branchName = nameTree->GetBranch(sectorName.str().c_str());
0135 TBranch* branchX(nullptr);
0136 branchX = treeX->GetBranch(sectorName.str().c_str());
0137 TBranch* branchY(nullptr);
0138 branchY = treeY->GetBranch(sectorName.str().c_str());
0139
0140
0141 if(branchName)m_branchName[iSector] = branchName;
0142 else{
0143 sectorBool = false;
0144 nSector = iSector-1;
0145 std::cout<<"\n\tNumber of sectors for APE calculation contained in TTree: "<<nSector<<"\n";
0146 }
0147 if(branchX)m_branchX[iSector] = branchX;
0148 if(branchY)m_branchY[iSector] = branchY;
0149 }
0150
0151 for(std::map<unsigned int, TBranch*>::const_iterator i_branch = m_branchName.begin(); i_branch != m_branchName.end(); ++i_branch){
0152 sectorValues.m_sectorName[i_branch->first] = nullptr;
0153 i_branch->second->SetAddress( &( sectorValues.m_sectorName[i_branch->first]) );
0154 i_branch->second->GetEntry(0);
0155 }
0156 const unsigned int nIter(treeX->GetEntries());
0157 for(unsigned int iIter = 0; iIter < nIter; ++iIter){
0158 for(std::map<unsigned int, TBranch*>::const_iterator i_branch = m_branchX.begin(); i_branch != m_branchX.end(); ++i_branch){
0159 sectorValues.m_sectorValueX[i_branch->first].push_back(-999);
0160 (i_branch->second)->SetAddress(&(sectorValues.m_sectorValueX[i_branch->first].back()));
0161 (i_branch->second)->GetEntry(iIter);
0162 }
0163 for(std::map<unsigned int, TBranch*>::const_iterator i_branch = m_branchY.begin(); i_branch != m_branchY.end(); ++i_branch){
0164 sectorValues.m_sectorValueY[i_branch->first].push_back(-999);
0165 (i_branch->second)->SetAddress(&(sectorValues.m_sectorValueY[i_branch->first].back()));
0166 (i_branch->second)->GetEntry(iIter);
0167 }
0168 }
0169 return sectorValues;
0170 }
0171
0172
0173
0174 DrawIteration::ExtremeValues DrawIteration::getGraphs(const std::string xOrY, unsigned int iSectorLow, unsigned int iSectorHigh){
0175 double minimumApe(999.), maximumApe(-999.);
0176 double maxAbsCorrection(-999.);
0177
0178 std::map<unsigned int, std::vector<double> >* m_sectorValue(nullptr);
0179 std::vector<TGraph*>* v_graphApe(nullptr);
0180 std::vector<TGraph*>* v_graphCorrection(nullptr);
0181
0182 if(xOrY=="x"){
0183 m_sectorValue = §orValues_.m_sectorValueX;
0184 v_graphApe = &v_graphApeX_;
0185 v_graphCorrection = &v_graphCorrectionX_;
0186 }
0187 else if(xOrY=="y"){
0188 m_sectorValue = §orValues_.m_sectorValueY;
0189 v_graphApe = &v_graphApeY_;
0190 v_graphCorrection = &v_graphCorrectionY_;
0191 }
0192 else{
0193 std::cout<<"Wrong parameter for getGraphs(...)\n";
0194 }
0195
0196 for(std::map<unsigned int, std::vector<double> >::const_iterator i_sectorValue = m_sectorValue->begin(); i_sectorValue != m_sectorValue->end(); ++i_sectorValue){
0197 if((*i_sectorValue).first >= iSectorLow && (*i_sectorValue).first<= iSectorHigh){
0198 TGraph* graphApe(nullptr);
0199 TGraph* graphCorrection(nullptr);
0200 graphApe = new TGraph(sectorValues_.m_sectorValueX[1].size());
0201 graphCorrection = new TGraph(sectorValues_.m_sectorValueX[1].size());
0202 double lastCorrection(0.);
0203 bool unregardedSector(false);
0204 int iValue(0);
0205 for(std::vector<double>::const_iterator i_value = (*i_sectorValue).second.begin(); i_value != (*i_sectorValue).second.end(); ++i_value, ++iValue){
0206 double valueApe(std::sqrt(*i_value));
0207
0208 if(valueApe>9.){
0209 unregardedSector = true;
0210 break;
0211 }
0212
0213 valueApe = valueApe*10000.;
0214 if(valueApe<minimumApe)minimumApe = valueApe;
0215 if(valueApe>maximumApe)maximumApe = valueApe;
0216 graphApe->SetPoint(iValue,static_cast<double>(iValue),valueApe);
0217
0218 const double correction(valueApe - lastCorrection);
0219
0220 if(std::fabs(correction)>maxAbsCorrection)maxAbsCorrection = correction;
0221 graphCorrection->SetPoint(iValue,static_cast<double>(iValue),correction);
0222
0223 lastCorrection = valueApe;
0224 }
0225 if(unregardedSector)continue;
0226 (*v_graphApe).push_back(graphApe);
0227 (*v_graphCorrection).push_back(graphCorrection);
0228 }
0229 }
0230
0231 return ExtremeValues(minimumApe, maximumApe, maxAbsCorrection);
0232 }
0233
0234
0235
0236 void DrawIteration::drawCorrections(const std::string& xOrY, const ExtremeValues& extremeValues, const std::string& sectorInterval){
0237
0238 std::vector<TGraph*>* v_graphApe(nullptr);
0239 std::vector<TGraph*>* v_graphCorrection(nullptr);
0240 if(xOrY=="x"){
0241 v_graphApe = &v_graphApeX_;
0242 v_graphCorrection = &v_graphCorrectionX_;
0243 }
0244 else if(xOrY=="y"){
0245 v_graphApe = &v_graphApeY_;
0246 v_graphCorrection = &v_graphCorrectionY_;
0247 }
0248 else{
0249 std::cout<<"Wrong parameter for drawCorrections(...)\n";
0250 }
0251
0252 if(v_graphApe->size()==0 || v_graphCorrection->size()==0)return;
0253
0254 TCanvas* canvas(nullptr);
0255 canvas = new TCanvas("canvas");
0256 bool firstGraph(true);
0257 for(std::vector<TGraph*>::const_iterator i_graph = v_graphApe->begin(); i_graph != v_graphApe->end(); ++i_graph){
0258 const TString yAxisTitle("#sigma_{align," + xOrY + "} [#mum]");
0259 TGraph* graph(*i_graph);
0260 graph->SetTitle("Absolute correction");
0261 graph->GetXaxis()->SetTitle("iteration");
0262 graph->GetYaxis()->SetTitle(yAxisTitle);
0263 if(firstGraph){
0264 graph->Draw("AL*");
0265 firstGraph = false;
0266 }
0267 else{
0268 graph->Draw("sameL*");
0269 }
0270 if(yAxisFixed_){
0271 graph->SetMinimum(-1.);
0272 graph->SetMaximum(35.);
0273 }
0274 else{
0275
0276 graph->SetMinimum(extremeValues.minimumApe-1.);
0277 graph->SetMaximum(extremeValues.maximumApe*1.1);
0278 }
0279 }
0280
0281 canvas->Print(outpath_->Copy().Append("ape_").Append(xOrY).Append(sectorInterval).Append(".eps"));
0282 canvas->Print(outpath_->Copy().Append("ape_").Append(xOrY).Append(sectorInterval).Append(".png"));
0283
0284 for(std::vector<TGraph*>::const_iterator i_graph = v_graphApe->begin(); i_graph != v_graphApe->end(); ++i_graph){
0285 (*i_graph)->Delete();
0286 }
0287 v_graphApe->clear();
0288 canvas->Close();
0289
0290 firstGraph = true;
0291 canvas = new TCanvas("canvas");
0292 for(std::vector<TGraph*>::const_iterator i_graph = v_graphCorrection->begin(); i_graph != v_graphCorrection->end(); ++i_graph){
0293 const TString yAxisTitle("#Delta#sigma_{align," + xOrY + "} [#mum]");
0294 TGraph* graph(*i_graph);
0295 graph->SetTitle("Relative correction");
0296 graph->GetXaxis()->SetTitle("iteration");
0297 graph->GetYaxis()->SetTitle(yAxisTitle);
0298 if(firstGraph){
0299 graph->Draw("AL*");
0300 firstGraph = false;
0301 }
0302 else{
0303 graph->Draw("sameL*");
0304 }
0305 if(yAxisFixed_){
0306 graph->SetMinimum(-5.);
0307 graph->SetMaximum(15.);
0308 }
0309 else{
0310 graph->SetMinimum(-extremeValues.maxAbsCorrection*1.1);
0311 graph->SetMaximum(extremeValues.maxAbsCorrection*1.1);
0312 }
0313 }
0314 canvas->Print(outpath_->Copy().Append("correction_").Append(xOrY).Append(sectorInterval).Append(".eps"));
0315 canvas->Print(outpath_->Copy().Append("correction_").Append(xOrY).Append(sectorInterval).Append(".png"));
0316
0317 for(std::vector<TGraph*>::const_iterator i_graph = v_graphCorrection->begin(); i_graph != v_graphCorrection->end(); ++i_graph){
0318 (*i_graph)->Delete();
0319 }
0320 v_graphCorrection->clear();
0321 canvas->Close();
0322 }
0323
0324
0325
0326 void DrawIteration::printFinalValues(unsigned int iSectorLow, unsigned int iSectorHigh){
0327 std::map<unsigned int, std::string*>::const_iterator i_sectorValue;
0328 for(i_sectorValue = sectorValues_.m_sectorName.begin(); i_sectorValue != sectorValues_.m_sectorName.end(); ++i_sectorValue){
0329 const unsigned int iSector(i_sectorValue->first);
0330 if(iSector>=iSectorLow && iSector<=iSectorHigh){
0331 const std::string* name(i_sectorValue->second);
0332 const double apeX = std::sqrt(*(--(sectorValues_.m_sectorValueX[iSector].end())));
0333 double apeY(-9.);
0334 if(sectorValues_.m_sectorValueY.count(iSector)!=0)apeY = std::sqrt(*(--(sectorValues_.m_sectorValueY[iSector].end())));
0335
0336 std::cout<<"Sector no., APE x, APE y, name:\t"<<iSector<<"\t, "<<std::fixed<<std::setprecision(5)<<apeX<<" , "<<apeY<<" , "<<*name<<"\n";
0337 }
0338 }
0339 }
0340
0341
0342
0343 void DrawIteration::clear(){
0344 std::vector<Input*>::iterator i_input;
0345 for(i_input = v_input_.begin(); i_input != v_input_.end(); ++i_input){
0346 (*i_input)->sectorValues.m_sectorName.clear();
0347 (*i_input)->sectorValues.m_sectorValueX.clear();
0348 (*i_input)->sectorValues.m_sectorValueY.clear();
0349 }
0350
0351 sectorValues_.m_sectorName.clear();
0352 sectorValues_.m_sectorValueX.clear();
0353 sectorValues_.m_sectorValueY.clear();
0354
0355 v_graphApeX_.clear();
0356 v_graphCorrectionX_.clear();
0357 v_graphApeY_.clear();
0358 v_graphCorrectionY_.clear();
0359
0360 v_resultHist_.clear();
0361 }
0362
0363
0364
0365 std::vector<std::vector<std::string> > DrawIteration::arrangeHists(){
0366 std::vector<std::vector<std::string> > v_resultHist;
0367
0368 v_resultHist.push_back(this->pixelHist());
0369
0370 v_resultHist.push_back(this->tibHist());
0371 v_resultHist.push_back(this->tobHist());
0372
0373 v_resultHist.push_back(this->tidHist());
0374 v_resultHist.push_back(this->tecHist());
0375
0376 return v_resultHist;
0377 }
0378
0379
0380
0381 std::vector<std::string> DrawIteration::pixelHist(){
0382 std::vector<std::string> v_name;
0383
0384 v_name.push_back("BpixLayer1Out");
0385 v_name.push_back("BpixLayer1In");
0386 v_name.push_back("BpixLayer2Out");
0387 v_name.push_back("BpixLayer2In");
0388 v_name.push_back("BpixLayer3Out");
0389 v_name.push_back("BpixLayer3In");
0390 v_name.push_back("BpixLayer4Out");
0391 v_name.push_back("BpixLayer4In");
0392
0393 v_name.push_back("FpixMinusLayer1");
0394 v_name.push_back("FpixMinusLayer2");
0395 v_name.push_back("FpixMinusLayer3");
0396 v_name.push_back("FpixPlusLayer1");
0397 v_name.push_back("FpixPlusLayer2");
0398 v_name.push_back("FpixPlusLayer3");
0399
0400 return v_name;
0401 }
0402
0403
0404
0405 std::vector<std::string> DrawIteration::barrelHist(){
0406 std::vector<std::string> v_name;
0407
0408 v_name.push_back("TibLayer1RphiOut");
0409 v_name.push_back("TibLayer1RphiIn");
0410 v_name.push_back("TibLayer1StereoOut");
0411 v_name.push_back("TibLayer1StereoIn");
0412 v_name.push_back("TibLayer2RphiOut");
0413 v_name.push_back("TibLayer2RphiIn");
0414 v_name.push_back("TibLayer2StereoOut");
0415 v_name.push_back("TibLayer2StereoIn");
0416 v_name.push_back("TibLayer3Out");
0417 v_name.push_back("TibLayer3In");
0418 v_name.push_back("TibLayer4Out");
0419 v_name.push_back("TibLayer4In");
0420
0421 v_name.push_back("TobLayer1StereoOut");
0422 v_name.push_back("TobLayer1RphiIn");
0423 v_name.push_back("TobLayer2RphiOut");
0424 v_name.push_back("TobLayer2StereoIn");
0425 v_name.push_back("TobLayer3Out");
0426 v_name.push_back("TobLayer3In");
0427 v_name.push_back("TobLayer4Out");
0428 v_name.push_back("TobLayer4In");
0429 v_name.push_back("TobLayer5Out");
0430 v_name.push_back("TobLayer5In");
0431 v_name.push_back("TobLayer6Out");
0432 v_name.push_back("TobLayer6In");
0433
0434 return v_name;
0435 }
0436
0437
0438
0439 std::vector<std::string> DrawIteration::tibHist(){
0440 std::vector<std::string> v_name;
0441
0442 v_name.push_back("TibLayer1RphiOut");
0443 v_name.push_back("TibLayer1RphiIn");
0444 v_name.push_back("TibLayer1StereoOut");
0445 v_name.push_back("TibLayer1StereoIn");
0446 v_name.push_back("TibLayer2RphiOut");
0447 v_name.push_back("TibLayer2RphiIn");
0448 v_name.push_back("TibLayer2StereoOut");
0449 v_name.push_back("TibLayer2StereoIn");
0450 v_name.push_back("TibLayer3Out");
0451 v_name.push_back("TibLayer3In");
0452 v_name.push_back("TibLayer4Out");
0453 v_name.push_back("TibLayer4In");
0454
0455 return v_name;
0456 }
0457
0458
0459
0460 std::vector<std::string> DrawIteration::tobHist(){
0461 std::vector<std::string> v_name;
0462
0463 v_name.push_back("TobLayer1StereoOut");
0464 v_name.push_back("TobLayer1RphiIn");
0465 v_name.push_back("TobLayer2RphiOut");
0466 v_name.push_back("TobLayer2StereoIn");
0467 v_name.push_back("TobLayer3Out");
0468 v_name.push_back("TobLayer3In");
0469 v_name.push_back("TobLayer4Out");
0470 v_name.push_back("TobLayer4In");
0471 v_name.push_back("TobLayer5Out");
0472 v_name.push_back("TobLayer5In");
0473 v_name.push_back("TobLayer6Out");
0474 v_name.push_back("TobLayer6In");
0475
0476 return v_name;
0477 }
0478
0479
0480
0481 std::vector<std::string> DrawIteration::endcapHist(){
0482 std::vector<std::string> v_name;
0483
0484 v_name.push_back("TidMinusRing1Rphi");
0485 v_name.push_back("TidMinusRing1Stereo");
0486 v_name.push_back("TidMinusRing2Rphi");
0487 v_name.push_back("TidMinusRing2Stereo");
0488 v_name.push_back("TidMinusRing3");
0489
0490 v_name.push_back("TidPlusRing1Rphi");
0491 v_name.push_back("TidPlusRing1Stereo");
0492 v_name.push_back("TidPlusRing2Rphi");
0493 v_name.push_back("TidPlusRing2Stereo");
0494 v_name.push_back("TidPlusRing3");
0495
0496 v_name.push_back("TecMinusRing1Rphi");
0497 v_name.push_back("TecMinusRing1Stereo");
0498 v_name.push_back("TecMinusRing2Rphi");
0499 v_name.push_back("TecMinusRing2Stereo");
0500 v_name.push_back("TecMinusRing3");
0501 v_name.push_back("TecMinusRing4");
0502 v_name.push_back("TecMinusRing5Rphi");
0503 v_name.push_back("TecMinusRing5Stereo");
0504 v_name.push_back("TecMinusRing6");
0505 v_name.push_back("TecMinusRing7");
0506
0507 v_name.push_back("TecPlusRing1Rphi");
0508 v_name.push_back("TecPlusRing1Stereo");
0509 v_name.push_back("TecPlusRing2Rphi");
0510 v_name.push_back("TecPlusRing2Stereo");
0511 v_name.push_back("TecPlusRing3");
0512 v_name.push_back("TecPlusRing4");
0513 v_name.push_back("TecPlusRing5Rphi");
0514 v_name.push_back("TecPlusRing5Stereo");
0515 v_name.push_back("TecPlusRing6");
0516 v_name.push_back("TecPlusRing7");
0517
0518 return v_name;
0519 }
0520
0521
0522
0523 std::vector<std::string> DrawIteration::tidHist(){
0524 std::vector<std::string> v_name;
0525
0526 v_name.push_back("TidMinusRing1Rphi");
0527 v_name.push_back("TidMinusRing1Stereo");
0528 v_name.push_back("TidMinusRing2Rphi");
0529 v_name.push_back("TidMinusRing2Stereo");
0530 v_name.push_back("TidMinusRing3");
0531
0532 v_name.push_back("TidPlusRing1Rphi");
0533 v_name.push_back("TidPlusRing1Stereo");
0534 v_name.push_back("TidPlusRing2Rphi");
0535 v_name.push_back("TidPlusRing2Stereo");
0536 v_name.push_back("TidPlusRing3");
0537
0538 return v_name;
0539 }
0540
0541
0542
0543 std::vector<std::string> DrawIteration::tecHist(){
0544 std::vector<std::string> v_name;
0545
0546 v_name.push_back("TecMinusRing1Rphi");
0547 v_name.push_back("TecMinusRing1Stereo");
0548 v_name.push_back("TecMinusRing2Rphi");
0549 v_name.push_back("TecMinusRing2Stereo");
0550 v_name.push_back("TecMinusRing3");
0551 v_name.push_back("TecMinusRing4");
0552 v_name.push_back("TecMinusRing5Rphi");
0553 v_name.push_back("TecMinusRing5Stereo");
0554 v_name.push_back("TecMinusRing6");
0555 v_name.push_back("TecMinusRing7");
0556
0557 v_name.push_back("TecPlusRing1Rphi");
0558 v_name.push_back("TecPlusRing1Stereo");
0559 v_name.push_back("TecPlusRing2Rphi");
0560 v_name.push_back("TecPlusRing2Stereo");
0561 v_name.push_back("TecPlusRing3");
0562 v_name.push_back("TecPlusRing4");
0563 v_name.push_back("TecPlusRing5Rphi");
0564 v_name.push_back("TecPlusRing5Stereo");
0565 v_name.push_back("TecPlusRing6");
0566 v_name.push_back("TecPlusRing7");
0567
0568 return v_name;
0569 }
0570
0571
0572
0573 TString DrawIteration::associateLabel(const std::string& sectorName){
0574 const TString name(sectorName.c_str());
0575 TString nameHelp("");
0576
0577 TString subdet, subdetLabel;
0578 if(name.BeginsWith("Bpix")){subdet="Bpix"; subdetLabel="BPIX";}
0579 else if(name.BeginsWith("Fpix")){subdet="Fpix"; subdetLabel="FPIX";}
0580 else if(name.BeginsWith("Tib")){subdet="Tib"; subdetLabel="TIB";}
0581 else if(name.BeginsWith("Tid")){subdet="Tid"; subdetLabel="TID";}
0582 else if(name.BeginsWith("Tob")){subdet="Tob"; subdetLabel="TOB";}
0583 else if(name.BeginsWith("Tec")){subdet="Tec"; subdetLabel="TEC";}
0584 else return "ERROR: no label found";
0585 nameHelp += subdet;
0586
0587 TString side, sideLabel;
0588 if(name.BeginsWith(nameHelp+"Minus")){side="Minus"; sideLabel="m";}
0589 else if(name.BeginsWith(nameHelp+"Plus")){side="Plus"; sideLabel="p";}
0590 else {side=""; sideLabel="";}
0591 nameHelp += side;
0592
0593 TString layer, layerLabel;
0594 if(name.BeginsWith(nameHelp+"Layer")){layer="Layer"; layerLabel=" L";}
0595 else if(name.BeginsWith(nameHelp+"Ring")){layer="Ring"; layerLabel=" R";}
0596 else return "ERROR: no label found";
0597 nameHelp += layer;
0598
0599 TString layerNo, layerNoLabel;
0600 for(unsigned int iLayer=1; iLayer<=7; ++iLayer){
0601 std::stringstream ss_layer;
0602 ss_layer<<iLayer;
0603 if(name.BeginsWith(nameHelp+ss_layer.str())){;
0604 layerNo=ss_layer.str(); layerNoLabel=ss_layer.str();
0605 break;
0606 }
0607 }
0608 nameHelp += layerNo;
0609
0610 TString sublayer, sublayerLabel;
0611 if(name.BeginsWith(nameHelp+"Rphi")){sublayer="Rphi"; sublayerLabel="R";}
0612 else if(name.BeginsWith(nameHelp+"Stereo")){sublayer="Stereo"; sublayerLabel="S";}
0613 else {sublayer=""; sublayerLabel="";}
0614 nameHelp += sublayer;
0615
0616 TString orientation, orientationLabel;
0617 if(name.BeginsWith(nameHelp+"Out")){orientation="Out"; orientationLabel="o";}
0618 else if(name.BeginsWith(nameHelp+"In")){orientation="In"; orientationLabel="i";}
0619 else {orientation=""; orientationLabel="";}
0620 nameHelp += orientation;
0621
0622 const TString label(subdetLabel+sideLabel+layerLabel+layerNoLabel+sublayerLabel+orientationLabel);
0623 return label;
0624 }
0625
0626
0627
0628 unsigned int DrawIteration::sectorNumber(const std::string& name){
0629 unsigned int sectorNo(0);
0630
0631 if(overlayMode_){
0632 sectorValues_ = (*v_input_.begin())->sectorValues;
0633 }
0634 std::map<unsigned int, std::string*>::const_iterator i_sector;
0635 for(i_sector=sectorValues_.m_sectorName.begin(); i_sector!=sectorValues_.m_sectorName.end(); ++i_sector){
0636 if(*(i_sector->second)==name){
0637 sectorNo=i_sector->first;
0638 break;
0639 }
0640 }
0641 return sectorNo;
0642 }
0643
0644
0645
0646 void DrawIteration::drawFinals(const std::string& xOrY){
0647 unsigned int iCanvas(1);
0648 std::vector<std::vector<std::string> >::const_iterator i_resultHist;
0649 for(i_resultHist=v_resultHist_.begin(); i_resultHist!=v_resultHist_.end(); ++i_resultHist, ++iCanvas){
0650
0651 TCanvas* canvas(nullptr);
0652 canvas = new TCanvas("canvas","canvas",gStyle->GetCanvasDefW()*i_resultHist->size()/10.,gStyle->GetCanvasDefH());
0653 std::vector<std::pair<TH1*, TString> > v_hist;
0654
0655 SectorValues* sectorValues(nullptr);
0656 if(!overlayMode_){
0657 unsigned int iInput(1);
0658 sectorValues = §orValues_;
0659 TH1* hist(nullptr);
0660 bool hasEntry = this->createResultHist(hist, *i_resultHist, xOrY, *sectorValues, iInput);
0661 if(hasEntry)v_hist.push_back(std::make_pair(hist, ""));
0662 else hist->Delete();
0663 }
0664 else{
0665 unsigned int iInput(1);
0666 std::vector<Input*>::const_iterator i_input;
0667 for(i_input = v_input_.begin(); i_input != v_input_.end(); ++i_input, ++iInput){
0668 sectorValues = &(*i_input)->sectorValues;
0669 TH1* hist(nullptr);
0670 TString& legendEntry = (*i_input)->legendEntry;
0671 bool hasEntry = this->createResultHist(hist, *i_resultHist, xOrY, *sectorValues, iInput);
0672 if(hasEntry)v_hist.push_back(std::make_pair(hist, legendEntry));
0673 else hist->Delete();
0674 }
0675 }
0676
0677 if(v_hist.size()!=0){
0678
0679 std::vector<std::pair<TH1*, TString> >::iterator i_hist;
0680 unsigned int iHist(1);
0681 for(i_hist = v_hist.begin(); i_hist != v_hist.end(); ++i_hist, ++iHist){
0682 TH1* hist((*i_hist).first);
0683 if(iHist==1){
0684 hist->Draw("e0");
0685 }
0686 else{
0687 hist->SetLineColor(iHist);
0688 hist->SetMarkerColor(iHist);
0689 hist->Draw("e0same");
0690 }
0691 }
0692
0693 TH1* systHist(nullptr);
0694 if(systematics_){
0695 const std::vector<std::string>& v_name(*i_resultHist);
0696
0697 bool pixel(false);
0698 bool tob(false);
0699 std::vector<std::string>::const_iterator i_name;
0700 for(i_name=v_name.begin(); i_name!=v_name.end(); ++i_name){
0701 const TString name((*i_name).c_str());
0702 if(name.BeginsWith("Bpix") || name.BeginsWith("Fpix")){
0703 pixel = true;
0704 break;
0705 }
0706 if(name.BeginsWith("Tob")){
0707 tob = true;
0708 break;
0709 }
0710 }
0711 if(pixel || tob)systHist = new TH1F("systematics", "sytematics", v_name.size(), 0, v_name.size());
0712 if(pixel){
0713 if(xOrY=="x"){
0714 systHist->SetBinContent(1, 10.);
0715 systHist->SetBinContent(2, 10.);
0716 systHist->SetBinContent(3, 10.);
0717 systHist->SetBinContent(4, 10.);
0718 systHist->SetBinContent(5, 10.);
0719 systHist->SetBinContent(6, 10.);
0720 systHist->SetBinContent(7, 10.);
0721 systHist->SetBinContent(8, 10.);
0722 systHist->SetBinContent(9, 10.);
0723 systHist->SetBinContent(10, 10.);
0724 systHist->SetBinContent(13, 5.);
0725 }
0726 else if(xOrY=="y"){
0727 systHist->SetBinContent(1, 15.);
0728 systHist->SetBinContent(2, 15.);
0729 systHist->SetBinContent(3, 15.);
0730 systHist->SetBinContent(4, 20.);
0731 systHist->SetBinContent(5, 15.);
0732 systHist->SetBinContent(6, 15.);
0733 systHist->SetBinContent(7, 15.);
0734 systHist->SetBinContent(8, 15.);
0735 systHist->SetBinContent(9, 15.);
0736 systHist->SetBinContent(10, 15.);
0737 systHist->SetBinContent(13, 5.);
0738 }
0739 }
0740 if(tob){
0741 systHist->SetBinContent(1, 15.);
0742 systHist->SetBinContent(2, 15.);
0743 systHist->SetBinContent(3, 10.);
0744 systHist->SetBinContent(4, 10.);
0745 systHist->SetBinContent(5, 10.);
0746 systHist->SetBinContent(6, 10.);
0747 systHist->SetBinContent(7, 15.);
0748 systHist->SetBinContent(8, 10.);
0749 }
0750 }
0751
0752 if(systHist){
0753 systHist->SetFillColor(1);
0754 systHist->SetFillStyle(3004);
0755 systHist->Draw("same");
0756 }
0757
0758 canvas->Modified();
0759 canvas->Update();
0760
0761 TLegend* legend(nullptr);
0762 legend = new TLegend(0.2,0.65,0.5,0.85);
0763 legend->SetFillColor(0);
0764 legend->SetFillStyle(0);
0765 legend->SetTextSize(0.04);
0766 legend->SetMargin(0.30);
0767 legend->SetBorderSize(0);
0768
0769 if(v_hist.size()>0){
0770 for(i_hist = v_hist.begin(), iHist = 1; i_hist != v_hist.end(); ++i_hist, ++iHist){
0771 legend->AddEntry((*i_hist).first, (*i_hist).second, "lp");
0772 }
0773 legend->Draw("same");
0774 }
0775
0776 canvas->Modified();
0777 canvas->Update();
0778
0779 TLatex* cmsText(nullptr);
0780 if(cmsText_!=""){
0781 cmsText = new TLatex(0.55,0.96,cmsText_);
0782 cmsText->SetNDC();
0783 cmsText->Draw("same");
0784 }
0785
0786 canvas->Modified();
0787 canvas->Update();
0788
0789 std::stringstream ss_hist;
0790 ss_hist<<"_"<<iCanvas;
0791 canvas->Print(outpath_->Copy().Append("result_").Append(xOrY).Append(ss_hist.str()).Append(".eps"));
0792 canvas->Print(outpath_->Copy().Append("result_").Append(xOrY).Append(ss_hist.str()).Append(".png"));
0793 if(cmsText)cmsText->Delete();
0794 if(legend)legend->Delete();
0795 if(systHist)systHist->Delete();
0796 }
0797
0798 std::vector<std::pair<TH1*, TString> >::iterator i_hist;
0799 for(i_hist = v_hist.begin(); i_hist != v_hist.end(); ++i_hist){
0800 if((*i_hist).first)(*i_hist).first->Delete();
0801 }
0802 v_hist.clear();
0803 if(canvas)canvas->Close();
0804 }
0805
0806 }
0807
0808
0809
0810 bool DrawIteration::createResultHist(TH1*& hist, const std::vector<std::string>& v_name, const std::string& xOrY, SectorValues& sectorValues, unsigned int iInput){
0811 bool hasEntry(false);
0812
0813 std::stringstream ss_name;
0814 ss_name<<"hist"<<iInput;
0815 const TString title("Results;;#sigma_{align,"+xOrY+"} [#mum]");
0816 hist = new TH1F(ss_name.str().c_str(), title, v_name.size(), 0, v_name.size());
0817
0818 std::map<unsigned int, std::vector<double> >* m_sectorValue(nullptr);
0819 if(xOrY=="x"){
0820 m_sectorValue = §orValues.m_sectorValueX;
0821 }
0822 else if(xOrY=="y"){
0823 m_sectorValue = §orValues.m_sectorValueY;
0824 }
0825 else{
0826 std::cout<<"Wrong parameter for drawFinals(...)\n";
0827 }
0828
0829 unsigned int iBin(1);
0830 std::vector<std::string>::const_iterator i_name;
0831 for(i_name=v_name.begin(); i_name!=v_name.end(); ++i_name, ++iBin){
0832 const TString& label = this->associateLabel(*i_name);
0833 const unsigned int iSector = this->sectorNumber(*i_name);
0834 double ape(-9.);
0835 if(m_sectorValue->count(iSector)!=0){
0836 ape = 10000.*std::sqrt(*(--((*m_sectorValue)[iSector].end())));
0837 hasEntry = true;
0838 }
0839 hist->SetBinContent(iBin, ape);
0840 hist->SetBinError(iBin, 0.0000001);
0841 hist->GetXaxis()->SetBinLabel(iBin, label);
0842 }
0843 hist->SetAxisRange(0.,100.,"Y");
0844
0845 return hasEntry;
0846 }
0847
0848
0849
0850 void DrawIteration::addSystematics(){
0851 systematics_ = true;
0852 }
0853
0854
0855
0856 void DrawIteration::addCmsText(const TString& cmsText){
0857 cmsText_ = cmsText;
0858 }
0859
0860
0861
0862
0863
0864
0865
0866
0867 void DrawIteration::addInputFile(const TString& name, const TString& legend){
0868 Input* input = new Input(name, legend);
0869
0870 input->file = new TFile(name, "READ");
0871 if(!input->file){
0872
0873 std::cout<<"\n\tInput file not found, please check file name: "<<name<<"\n";
0874 }
0875 std::cout<<"Input file, legend: "<<input->fileName<<" , "<<input->legendEntry<<"\n";
0876
0877 v_input_.push_back(input);
0878 }
0879
0880
0881
0882 void DrawIteration::outputDirectory(const TString& outpath){
0883 delete outpath_;
0884 outpath_ = new TString(outpath);
0885 }