File indexing completed on 2024-04-06 11:57:13
0001
0002
0003 #include <TGClient.h>
0004 #include <TCanvas.h>
0005 #include <TF1.h>
0006 #include <TGraph.h>
0007 #include <TRandom.h>
0008 #include <TGButton.h>
0009 #include <TGFrame.h>
0010 #include <TFrame.h>
0011 #include <TRootEmbeddedCanvas.h>
0012 #include <RQ_OBJECT.h>
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055 const char * varx[3] = { "r", "z", "phi" };
0056
0057 const char * vary[3] = { "dr", "dz", "dphi" };
0058
0059 char selection[255];
0060
0061 char * gName = 0;
0062
0063
0064 char * strdup_new(const char * text)
0065 {
0066 char * temp = new char[strlen(text)+1];
0067 strcpy(temp, text);
0068 return temp;
0069 }
0070
0071
0072 class MyMainFrame {
0073 RQ_OBJECT("MyMainFrame")
0074 private:
0075 TGMainFrame * fMain;
0076 TRootEmbeddedCanvas * fEcanvas[3][3];
0077
0078 public:
0079 MyMainFrame(const TGWindow *p);
0080 virtual ~MyMainFrame();
0081
0082 void DoDraw();
0083 void Reset();
0084 void Exec(Int_t event, Int_t x, Int_t y, TObject *selected);
0085 };
0086
0087 void MyMainFrame::Exec(Int_t event, Int_t x, Int_t y, TObject *selected)
0088 {
0089 static double x1, y1, x2, y2;
0090 static TGraph * gr = 0;
0091 TCanvas * c = (TCanvas *) gTQSender;
0092
0093
0094
0095
0096 int theNr = atoi(c->GetName()+7)-1;
0097 int xval = theNr % 3;
0098 int yval = theNr / 3;
0099
0100
0101
0102
0103 if (event == 2 && (selected->IsA() == TH2F::Class() || selected->IsA() == TFrame::Class())) {
0104
0105
0106 x1 = c->AbsPixeltoX(x);
0107 y1 = c->AbsPixeltoY(y);
0108 }
0109
0110
0111 if ((event == 22 || event == 12) && ((selected->IsA() == TH2F::Class()) || selected->IsA() == TFrame::Class())) {
0112
0113
0114
0115
0116 if (gr != 0) {
0117 delete gr;
0118 gr = 0;
0119 }
0120 c->Modified();
0121 c->Update();
0122
0123
0124 x2 = c->AbsPixeltoX(x);
0125 y2 = c->AbsPixeltoY(y);
0126
0127 c->cd();
0128
0129
0130 double xf[5] = { x1, x2, x2, x1, x1 };
0131 double yf[5] = { y1, y1, y2, y2, y1 };
0132 gr = new TGraph(5, xf, yf);
0133 gr->Draw();
0134 c->Update();
0135
0136
0137
0138
0139
0140 if (event == 12) {
0141
0142
0143
0144 sprintf(selection,
0145 "(%s>%f)&&(%s<%f)&&(%s>%f)&&(%s<%f)",
0146 vary[xval],
0147 TMath::Min(y2, y1),
0148 vary[xval],
0149 TMath::Max(y2, y1),
0150 varx[yval],
0151 TMath::Min(x2, x1),
0152 varx[yval],
0153 TMath::Max(x2, x1));
0154
0155 }
0156 }
0157 }
0158
0159 MyMainFrame::MyMainFrame(const TGWindow *p) {
0160
0161 fMain = new TGMainFrame(p, 800, 600);
0162
0163
0164 TGHorizontalFrame * hframe = new TGHorizontalFrame(fMain,200,200);
0165
0166 fEcanvas[0][0] = new TRootEmbeddedCanvas("Ecanvas1",hframe,200,200);
0167 hframe->AddFrame(fEcanvas[0][0], new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,
0168 5, 5, 5, 5));
0169 fEcanvas[0][0]->GetCanvas()->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", "MyMainFrame", "",
0170 "Exec(Int_t,Int_t,Int_t,TObject*)");
0171 fEcanvas[1][0] = new TRootEmbeddedCanvas("Ecanvas2",hframe,200,200);
0172 hframe->AddFrame(fEcanvas[1][0], new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,
0173 5, 5, 5, 5));
0174 fEcanvas[1][0]->GetCanvas()->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", "MyMainFrame", "",
0175 "Exec(Int_t,Int_t,Int_t,TObject*)");
0176 fEcanvas[2][0] = new TRootEmbeddedCanvas("Ecanvas3",hframe,200,200);
0177 hframe->AddFrame(fEcanvas[2][0], new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,
0178 5, 5, 5, 5));
0179 fEcanvas[2][0]->GetCanvas()->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", "MyMainFrame", "",
0180 "Exec(Int_t,Int_t,Int_t,TObject*)");
0181
0182 fMain->AddFrame(hframe, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,
0183 5, 5, 5, 5));
0184
0185
0186
0187 TGHorizontalFrame * hframe = new TGHorizontalFrame(fMain,200,200);
0188
0189 fEcanvas[0][1] = new TRootEmbeddedCanvas("Ecanvas4",hframe,200,200);
0190 hframe->AddFrame(fEcanvas[0][1], new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,
0191 5, 5, 5, 5));
0192 fEcanvas[0][1]->GetCanvas()->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", "MyMainFrame", "",
0193 "Exec(Int_t,Int_t,Int_t,TObject*)");
0194 fEcanvas[1][1] = new TRootEmbeddedCanvas("Ecanvas5",hframe,200,200);
0195 hframe->AddFrame(fEcanvas[1][1], new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,
0196 5, 5, 5, 5));
0197 fEcanvas[1][1]->GetCanvas()->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", "MyMainFrame", "",
0198 "Exec(Int_t,Int_t,Int_t,TObject*)");
0199 fEcanvas[2][1] = new TRootEmbeddedCanvas("Ecanvas6",hframe,200,200);
0200 hframe->AddFrame(fEcanvas[2][1], new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,
0201 5, 5, 5, 5));
0202 fEcanvas[2][1]->GetCanvas()->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", "MyMainFrame", "",
0203 "Exec(Int_t,Int_t,Int_t,TObject*)");
0204
0205 fMain->AddFrame(hframe, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,
0206 5, 5, 5, 5));
0207
0208
0209 TGHorizontalFrame * hframe = new TGHorizontalFrame(fMain,200,200);
0210
0211 fEcanvas[0][2] = new TRootEmbeddedCanvas("Ecanvas7",hframe,200,200);
0212 hframe->AddFrame(fEcanvas[0][2], new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,
0213 5, 5, 5, 5));
0214 fEcanvas[0][2]->GetCanvas()->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", "MyMainFrame", "",
0215 "Exec(Int_t,Int_t,Int_t,TObject*)");
0216 fEcanvas[1][2] = new TRootEmbeddedCanvas("Ecanvas8",hframe,200,200);
0217 hframe->AddFrame(fEcanvas[1][2], new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,
0218 5, 5, 5, 5));
0219 fEcanvas[1][2]->GetCanvas()->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", "MyMainFrame", "",
0220 "Exec(Int_t,Int_t,Int_t,TObject*)");
0221 fEcanvas[2][2] = new TRootEmbeddedCanvas("Ecanvas9",hframe,200,200);
0222 hframe->AddFrame(fEcanvas[2][2], new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,
0223 5, 5, 5, 5));
0224 fEcanvas[2][2]->GetCanvas()->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", "MyMainFrame", "",
0225 "Exec(Int_t,Int_t,Int_t,TObject*)");
0226
0227 fMain->AddFrame(hframe, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,
0228 5, 5, 5, 5));
0229
0230
0231 hframe = new TGHorizontalFrame(fMain,200,40);
0232 TGTextButton *draw = new TGTextButton(hframe,"&Draw");
0233 draw->Connect("Clicked()","MyMainFrame",this,"DoDraw()");
0234 hframe->AddFrame(draw, new TGLayoutHints(kLHintsCenterX,5,5,3,4));
0235 TGTextButton *reset = new TGTextButton(hframe,"&Reset");
0236 reset->Connect("Clicked()","MyMainFrame",this,"Reset()");
0237 hframe->AddFrame(reset, new TGLayoutHints(kLHintsCenterX,5,5,3,4));
0238 TGTextButton *exit = new TGTextButton(hframe,"&Exit",
0239 "gApplication->Terminate(0)");
0240
0241 hframe->AddFrame(exit, new TGLayoutHints(kLHintsCenterX,5,5,3,4));
0242
0243 fMain->AddFrame(hframe, new TGLayoutHints(kLHintsCenterX,2,2,2,2));
0244
0245
0246
0247 fMain->SetWindowName("Geometry Comparison GUI");
0248
0249 fMain->MapSubwindows();
0250
0251 fMain->Resize(fMain->GetDefaultSize());
0252
0253 fMain->MapWindow();
0254 }
0255
0256
0257
0258
0259 void MyMainFrame::DoDraw()
0260 {
0261
0262 float dr, dphi, dz, r, phi, z;
0263
0264
0265 TFile * infile = new TFile(gName);
0266 TTree * t = (TTree *) infile->Get("alignTree");
0267 if (t == 0) {
0268 cout << "ERR: could not find \"alignTree\" in file " << gName << endl;
0269 gApplication->Terminate(0);
0270 }
0271
0272
0273
0274
0275
0276 char histname[20];
0277 char histname2[20];
0278 char drawstring[64];
0279 char drawstring2[64];
0280
0281
0282 for (int i = 0; i < 3; i++) {
0283 for (int j = 0; j < 3; j++) {
0284
0285 TCanvas * fCanvas = fEcanvas[i][j]->GetCanvas();
0286 fCanvas->cd();
0287
0288
0289 sprintf(histname, "%s vs %s", vary[i], varx[j]);
0290 sprintf(histname2, "%s vs %s_2", vary[i], varx[j]);
0291 sprintf(drawstring, "%s:%s>>%s", vary[i], varx[j], histname);
0292 sprintf(drawstring2, "%s:%s>>%s", vary[i], varx[j], histname2);
0293
0294
0295
0296 t->Draw(drawstring, "", "goff");
0297
0298
0299 TObject * obj = gDirectory->Get(histname);
0300
0301 TH2F * h2 = (TH2F *) obj;
0302 if (h2 != 0) {
0303 h2->SetTitle(histname);
0304 h2->Draw();
0305 h2->SetDirectory(0);
0306 h2->SetMarkerStyle(1);
0307 h2->Draw("p");
0308 }
0309 else {
0310 cout << "Histo " << histname << " not found" << endl;
0311 }
0312
0313
0314 t->Draw(drawstring2, selection, "goff");
0315
0316
0317 TH2F * h22 = (TH2F *) gDirectory->Get(histname2);
0318 if (h22 != 0) {
0319
0320 h22->SetDirectory(0);
0321 h22->SetTitle(histname2);
0322 h22->SetMarkerColor(kRed);
0323 h22->SetMarkerStyle(7);
0324 h22->Draw("psame");
0325 }
0326 else {
0327 cout << "Histo " << histname2 << " not found" << endl;
0328 }
0329 fCanvas->Update();
0330 }
0331 }
0332
0333 delete infile;
0334 }
0335
0336 void MyMainFrame::Reset()
0337 {
0338
0339 strcpy(selection, "z==3000");
0340 DoDraw();
0341 }
0342
0343 MyMainFrame::~MyMainFrame()
0344 {
0345
0346 fMain->Cleanup();
0347 delete fMain;
0348 }
0349
0350
0351 void GeoComparisonGUI(const char * fname) {
0352
0353 gEnv->SetValue("Hist.Binning.2D.x", "1000");
0354 gEnv->SetValue("Hist.Binning.2D.y", "1000");
0355 gStyle->SetOptStat(0);
0356
0357 gName = strdup_new(fname);
0358 MyMainFrame * frame = new MyMainFrame(gClient->GetRoot());
0359 frame->Reset();
0360 }