File indexing completed on 2024-04-06 11:56:32
0001
0002
0003
0004
0005 #include <map>
0006 #include <vector>
0007 #include <iostream>
0008
0009 #include "TString.h"
0010 #include "TTree.h"
0011 #include "TGraph.h"
0012 #include "TGraphErrors.h"
0013 #include "TMultiGraph.h"
0014 #include "TCanvas.h"
0015 #include "TROOT.h"
0016 #include "TFile.h"
0017 #include "TList.h"
0018 #include "TLegend.h"
0019
0020 #include "PlotMillePede.h"
0021 #include "PlotMillePedeIOV.h"
0022 #include "GFUtils/GFHistManager.h"
0023
0024 PlotMillePedeIOV::PlotMillePedeIOV(const char *fileName, Int_t maxIov,
0025 Int_t hieraLevel)
0026 : fHistManager(new GFHistManager), fTitle("")
0027 {
0028 if (maxIov <= 0) {
0029 maxIov = 0;
0030 TFile *file = TFile::Open(fileName);
0031 if (!file) return;
0032
0033
0034 TTree *tree = 0;
0035 do {
0036 file->GetObject(Form("MillePedeUser_%d", ++maxIov), tree);
0037 } while (tree);
0038 --maxIov;
0039
0040 delete file;
0041 }
0042
0043 for (Int_t iov = 1; iov <= maxIov; ++iov) {
0044 fIovs.push_back(new PlotMillePede(fileName, iov, hieraLevel));
0045 fIovs.back()->GetHistManager()->SetBatch();
0046 TTree *tree = fIovs.back()->GetMainTree();
0047 tree->SetEstimate(tree->GetEntries());
0048 }
0049
0050 fHistManager->SetLegendX1Y1X2Y2(0.14, 0.7, 0.45, 0.9);
0051 }
0052
0053 PlotMillePedeIOV::~PlotMillePedeIOV()
0054 {
0055 delete fHistManager;
0056 for (unsigned int i = 0; i < fIovs.size(); ++i) {
0057 delete fIovs[i];
0058 }
0059 }
0060
0061
0062 void PlotMillePedeIOV::DrawPedeParam(Option_t *option, unsigned int nNonRigidParam)
0063 {
0064 const unsigned int nPar = PlotMillePede::kNpar + nNonRigidParam;
0065 const Int_t layer = this->PrepareAdd(TString(option).Contains("add", TString::kIgnoreCase));
0066 const Int_t xInTitle = TString(option).Contains("x", TString::kIgnoreCase);
0067 const Int_t yInTitle = TString(option).Contains("y", TString::kIgnoreCase);
0068 const Int_t zInTitle = TString(option).Contains("z", TString::kIgnoreCase);
0069
0070 const Int_t idInTitle = (!xInTitle && !yInTitle && !zInTitle)
0071 || TString(option).Contains("id", TString::kIgnoreCase);
0072 const Int_t doErr = TString(option).Contains("err", TString::kIgnoreCase);
0073 const Int_t noErr = TString(option).Contains("val", TString::kIgnoreCase);
0074
0075 typedef std::map<ParId, TGraphErrors*> GraphMap;
0076 GraphMap graphs;
0077
0078 unsigned int maxPar = 0;
0079 for (unsigned int iIov = 0; iIov < fIovs.size(); ++iIov) {
0080 PlotMillePede *iov = fIovs[iIov];
0081 TTree *tree = iov->GetMainTree();
0082 for (unsigned int iPar = 0; iPar < nPar; ++iPar) {
0083 if (iPar > maxPar) maxPar = iPar;
0084 const TString pedePar(iov->MpT() += iov->Par(iPar) += iov->ToMumMuRadPede(iPar));
0085 const TString parSi(iov->ParSi(iPar) += iov->ToMumMuRadPede(iPar));
0086 const TString par(doErr ? parSi : pedePar);
0087
0088 TString selection;
0089 iov->AddBasicSelection(selection);
0090
0091 const Long64_t numAlis = tree->Draw(par + ":Id:ObjId:" + parSi, selection, "goff");
0092
0093 const std::vector<double> values(tree->GetV1(), tree->GetV1() + numAlis);
0094 const std::vector<double> ids (tree->GetV2(), tree->GetV2() + numAlis);
0095 const std::vector<double> objIds(tree->GetV3(), tree->GetV3() + numAlis);
0096 const std::vector<double> sigmas(tree->GetV4(), tree->GetV4() + numAlis);
0097
0098
0099 for (Long64_t iAli = 0; iAli < numAlis; ++iAli) {
0100
0101 const ParId id(ids[iAli], objIds[iAli], iPar);
0102 TGraphErrors *&gr = graphs[id];
0103 if (!gr) {
0104
0105 tree->Draw(iov->XPos() += ":" + iov->YPos() +=
0106 ":" + iov->ZPos(), selection, "goff");
0107 gr = new TGraphErrors;
0108
0109 TString title(iov->AlignableObjIdString(id.objId_));
0110 if (idInTitle)title += Form(", %d", id.id_);
0111 if (xInTitle) title += Form(", x=%.1f", tree->GetV1()[iAli]);
0112 if (yInTitle) title += Form(", y=%.1f", tree->GetV2()[iAli]);
0113 if (zInTitle) title += Form(", z=%.f", tree->GetV3()[iAli]);
0114
0115 gr->SetTitle(title);
0116 }
0117 gr->SetPoint(gr->GetN(), iIov+1, values[iAli]);
0118 if (!doErr
0119 && !noErr
0120 && sigmas[iAli] > 0.) {
0121 gr->SetPointError(gr->GetN()-1, 0., sigmas[iAli]);
0122 }
0123 }
0124 }
0125 }
0126
0127
0128
0129
0130
0131 std::vector<TMultiGraph*> multis(maxPar+1);
0132 for (GraphMap::const_iterator iGr = graphs.begin(); iGr != graphs.end();
0133 ++iGr) {
0134 const ParId &id = iGr->first;
0135 if (!multis[id.par_]) multis[id.par_] = new TMultiGraph;
0136 multis[id.par_]->Add(iGr->second, "");
0137 }
0138
0139
0140
0141
0142 const bool isBatch = gROOT->IsBatch(); gROOT->SetBatch();
0143 TCanvas c;
0144
0145 for (unsigned int iMulti = 0; iMulti < multis.size(); ++iMulti) {
0146 if (multis[iMulti] == 0) continue;
0147 TIter iter(multis[iMulti]->GetListOfGraphs());
0148 multis[iMulti]->Draw("ALP");
0149 TH1 *h = static_cast<TH1*>(multis[iMulti]->GetHistogram()
0150 ->Clone(this->Unique(Form("IOV%u", iMulti))));
0151 const PlotMillePede *i0 = fIovs[0];
0152 if (doErr) {
0153 const TString errPar(Form("#sigma(%s)", i0->NamePede(iMulti).Data()));
0154 h->SetTitle(errPar + " IOVs" += i0->TitleAdd() += ";IOV;"
0155 + errPar + i0->UnitPede(iMulti));
0156 } else if (fTitle != "" ) {
0157 h->SetTitle(i0->NamePede(iMulti) + " IOVs" + i0->TitleAdd() + ", " + fTitle + ";IOV;"
0158 + i0->NamePede(iMulti) += i0->UnitPede(iMulti));
0159 } else {
0160 h->SetTitle((i0->NamePede(iMulti) += " IOVs") += i0->TitleAdd() += ";IOV;"
0161 + i0->NamePede(iMulti) += i0->UnitPede(iMulti));
0162 }
0163 fHistManager->AddHistSame(h, layer, iMulti);
0164 fHistManager->AddObject(multis[iMulti], layer, iMulti, "LP");
0165
0166 Double_t x1, x2, y1, y2; fHistManager->GetLegendX1Y1X2Y2(x1, y1, x2, y2);
0167 TLegend *legend = new TLegend(x1, y1, x2, y2);
0168 legend->SetFillColor(kWhite);
0169 legend->SetTextFont(42);
0170 legend->SetBorderSize(1);
0171 fHistManager->AddLegend(legend, layer, iMulti);
0172 Int_t nGr = 0;
0173 while (TGraph* graph = static_cast<TGraph*>(iter.Next())){
0174 legend->AddEntry(graph, graph->GetTitle(), "lp");
0175 this->SetLineMarkerStyle(*graph, nGr++);
0176 }
0177 }
0178 gROOT->SetBatch(isBatch);
0179
0180 fHistManager->Draw();
0181 }
0182
0183
0184 void PlotMillePedeIOV::SetSubDetId(Int_t subDet)
0185 {
0186 for (unsigned int iIov = 0; iIov < fIovs.size(); ++iIov) {
0187 fIovs[iIov]->SetSubDetId(subDet);
0188 }
0189 }
0190
0191
0192 void PlotMillePedeIOV::SetSubDetIds(Int_t id1, Int_t id2, Int_t id3, Int_t id4, Int_t id5)
0193 {
0194 for (unsigned int iIov = 0; iIov < fIovs.size(); ++iIov) {
0195 fIovs[iIov]->SetSubDetIds(id1, id2, id3, id4, id5);
0196 }
0197 }
0198
0199
0200 void PlotMillePedeIOV::SetAlignableTypeId(Int_t alignableTypeId)
0201 {
0202 for (unsigned int iIov = 0; iIov < fIovs.size(); ++iIov) {
0203 fIovs[iIov]->SetAlignableTypeId(alignableTypeId);
0204 }
0205 }
0206
0207
0208 void PlotMillePedeIOV::SetHieraLevel(Int_t hieraLevel)
0209 {
0210 for (unsigned int iIov = 0; iIov < fIovs.size(); ++iIov) {
0211 fIovs[iIov]->SetHieraLevel(hieraLevel);
0212 }
0213 }
0214
0215
0216 void PlotMillePedeIOV::SetBowsParameters(bool use)
0217 {
0218 for (unsigned int iIov = 0; iIov < fIovs.size(); ++iIov) {
0219 fIovs[iIov]->SetBowsParameters(use);
0220 }
0221 }
0222
0223
0224 void PlotMillePedeIOV::AddAdditionalSel(const TString &xyzrPhiNhit, Float_t min, Float_t max)
0225 {
0226 for (unsigned int iIov = 0; iIov < fIovs.size(); ++iIov) {
0227 fIovs[iIov]->AddAdditionalSel(xyzrPhiNhit, min, max);
0228 }
0229 }
0230
0231
0232 void PlotMillePedeIOV::ClearAdditionalSel()
0233 {
0234 for (unsigned int iIov = 0; iIov < fIovs.size(); ++iIov) {
0235 fIovs[iIov]->ClearAdditionalSel();
0236 }
0237 }
0238
0239
0240 TString PlotMillePedeIOV::Unique(const char *name) const
0241 {
0242 if (!gROOT->FindObject(name)) return name;
0243
0244 UInt_t i = 1;
0245 while (gROOT->FindObject(Form("%s_%u", name, i))) ++i;
0246
0247 return Form("%s_%u", name, i);
0248 }
0249
0250
0251 Int_t PlotMillePedeIOV::PrepareAdd(bool addPlots)
0252 {
0253 if (addPlots) {
0254 return fHistManager->GetNumLayers();
0255 } else {
0256 fHistManager->Clear();
0257 return 0;
0258 }
0259 }
0260
0261
0262 template<class T>
0263 void PlotMillePedeIOV::SetLineMarkerStyle(T &object, Int_t num) const
0264 {
0265
0266
0267 Int_t colour = num%11 + 1;
0268 if (colour > 4) ++colour;
0269 if (colour == 10) colour = 41;
0270 else if (colour == 11) colour = 46;
0271 else if (colour == 12) colour = 49;
0272 object.SetLineColor(colour);
0273 object.SetMarkerColor(object.GetLineColor());
0274
0275
0276 Int_t marker = 0;
0277 switch (num%14) {
0278 case 0: marker = kFullCircle;
0279 break;
0280 case 1: marker = kFullSquare;
0281 break;
0282 case 2: marker = kFullTriangleUp;
0283 break;
0284 case 3: marker = kFullTriangleDown;
0285 break;
0286 case 4: marker = kOpenCircle;
0287 break;
0288 case 5: marker = kOpenSquare;
0289 break;
0290 case 6: marker = kOpenTriangleUp;
0291 break;
0292 case 7: marker = kOpenTriangleDown;
0293 break;
0294 case 8: marker = kOpenStar;
0295 break;
0296 case 9: marker = kFullStar;
0297 break;
0298 case 10: marker = kOpenCross;
0299 break;
0300 case 11: marker = kFullCross;
0301 break;
0302 case 12: marker = kOpenDiamond;
0303 break;
0304 case 13: marker = kFullDiamond;
0305 break;
0306 default: marker = kPlus;
0307 }
0308 object.SetMarkerStyle(marker);
0309
0310
0311 object.SetLineStyle(num%4 + 1);
0312
0313 }
0314
0315 bool PlotMillePedeIOV::ParId::operator< (const ParId& other) const
0316 {
0317
0318
0319 if (id_ < other.id_) return true;
0320 else if (id_ > other.id_) return false;
0321 else {
0322 if (objId_ < other.objId_) return true;
0323 else if (objId_ > other.objId_) return false;
0324 else {
0325 if (par_ < other.par_) return true;
0326
0327 else return false;
0328 }
0329 }
0330 }