Warning, /Validation/DTRecHits/test/plotHit1DReso.r is written in an unsupported language. File is not indexed.
0001
0002 class HRes1DHit;
0003 class HRes2DHit;
0004 class HRes4DHit;
0005
0006 void plotHitReso();
0007 void draw(bool, bool, bool, bool, bool, bool ThreeInOne);
0008 void plot1DRes(HRes1DHit * h1, HRes1DHit * h2, HRes1DHit * h3, bool ThreeInOne);
0009 void plot1DResVsPos(HRes1DHit * h1, HRes1DHit * h2, HRes1DHit * h3, bool ThreeInOne);
0010 bool setPreferences(bool& doRes, bool& doResVsPos, bool& doResCloseWire, bool&, bool&, bool& ThreeIn1) ;
0011
0012 // This is the main function
0013 void plotHit1DReso(){
0014 // Load needed macros and files
0015 gROOT->LoadMacro("macros.C"); // Load service macros
0016 gROOT->LoadMacro("../plugins/Histograms.h"); // Load definition of histograms
0017
0018 // Get the style
0019 TStyle * style = getStyle("tdr");
0020
0021 // //style->SetOptStat("RME");
0022 // style->SetOptStat(0);
0023 // style->SetOptFit(11);
0024 style->SetFitFormat("3.2e");
0025 // style->SetStatFontSize(0.03);
0026 // style->SetStatColor(0);
0027 // style->SetStatY(0.99);
0028 // style->SetStatX(0.99);
0029 // style->SetStatH(0.3);
0030 // style->SetStatW(0.25);
0031 // // style->SetStatW(0.25);
0032 // // style->SetStatH(0.35);
0033 // style->SetTitleFillColor(0);
0034
0035 style->cd(); // Apply style
0036
0037 //Main switches
0038 bool ThreeInOne = true; // Plot the 3 steps in a single canvas (where appl.)
0039 bool doRes = false;
0040 bool doResVsPos = false;
0041 bool doResCloseWire = false;
0042 bool doResVsAngle = false;
0043 bool doResVsFE = false;
0044 // Read user input, namely what plots should be produced
0045
0046 while(!setPreferences(doRes, doResVsPos, doResCloseWire, doResVsAngle, doResVsFE, ThreeInOne));
0047
0048 draw(doRes, doResVsPos, doResCloseWire, doResVsAngle, doResVsFE, ThreeInOne);
0049 }
0050
0051 void draw(bool doRes, bool doResVsPos, bool doResCloseWire, bool doResVsAngle, bool doResVsFE, bool ThreeInOne) {
0052 // Retrieve histogram sets
0053 TFile *f = gROOT->GetListOfFiles()->Last();
0054 if (!f) {
0055 cout << "No file loaded" << endl;
0056 return;
0057 }
0058 cout << "Loading file: " << f->GetName() << endl;
0059
0060 HRes1DHit *h1RPhi = new HRes1DHit("S1RPhi",f); // RecHits, 1. step, RPhi
0061 HRes1DHit *h2RPhi = new HRes1DHit("S2RPhi",f); // RecHits, 2. step, RPhi
0062 HRes1DHit *h3RPhi = new HRes1DHit("S3RPhi",f); // RecHits, 3. step, RPhi
0063
0064 HRes1DHit *h1RZ = new HRes1DHit("S1RZ",f); // RecHits, 1. step, RZ
0065 HRes1DHit *h2RZ = new HRes1DHit("S2RZ",f); // RecHits, 2. step, RZ
0066 HRes1DHit *h3RZ = new HRes1DHit("S3RZ",f); // RecHits, 3. step, RZ
0067
0068 HRes1DHit *h1RZ_W0 = new HRes1DHit("S1RZ_W0",f); // RecHits, 1. step, RZ, wheel 0
0069 HRes1DHit *h2RZ_W0 = new HRes1DHit("S2RZ_W0",f); // RecHits, 2. step, RZ, wheel 0
0070 HRes1DHit *h3RZ_W0 = new HRes1DHit("S3RZ_W0",f); // RecHits, 3. step, RZ, wheel 0
0071
0072 HRes1DHit *h1RZ_W1 = new HRes1DHit("S1RZ_W1",f); // RecHits, 1. step, RZ, wheel +-1
0073 HRes1DHit *h2RZ_W1 = new HRes1DHit("S2RZ_W1",f); // RecHits, 2. step, RZ, wheel +-1
0074 HRes1DHit *h3RZ_W1 = new HRes1DHit("S3RZ_W1",f); // RecHits, 3. step, RZ, wheel +-1
0075
0076 HRes1DHit *h1RZ_W2 = new HRes1DHit("S1RZ_W2",f); // RecHits, 1. step, RZ, wheel +-2
0077 HRes1DHit *h2RZ_W2 = new HRes1DHit("S2RZ_W2",f); // RecHits, 2. step, RZ, wheel +-2
0078 HRes1DHit *h3RZ_W2 = new HRes1DHit("S3RZ_W2",f); // RecHits, 3. step, RZ, wheel +-2
0079
0080 if (doRes) {
0081 // Res, Rphi
0082 plot1DRes(h1RPhi,h2RPhi,h3RPhi,ThreeInOne);
0083
0084 // Res, RZ
0085 plot1DRes(h1RZ,h2RZ,h3RZ,ThreeInOne);
0086
0087 // Res, RZ, per wheel
0088 plot1DRes(h1RZ_W0,h2RZ_W0,h3RZ_W0,ThreeInOne);
0089 plot1DRes(h1RZ_W1,h2RZ_W1,h3RZ_W1,ThreeInOne);
0090 plot1DRes(h1RZ_W2,h2RZ_W2,h3RZ_W2,ThreeInOne);
0091 }
0092
0093 if (doResVsPos){
0094 // Res, Rphi
0095 plot1DResVsPos(h1RPhi,h2RPhi,h3RPhi,ThreeInOne);
0096
0097 // Res, RZ
0098 plot1DResVsPos(h1RZ,h2RZ,h3RZ,ThreeInOne);
0099
0100 // Res, RZ, per wheel
0101 plot1DResVsPos(h1RZ_W0,h2RZ_W0,h3RZ_W0,ThreeInOne);
0102 plot1DResVsPos(h1RZ_W1,h2RZ_W1,h3RZ_W1,ThreeInOne);
0103 plot1DResVsPos(h1RZ_W2,h2RZ_W2,h3RZ_W2,ThreeInOne);
0104 }
0105
0106 if (doResCloseWire){
0107 // Res, Rphi
0108 plot1DResCloseWire(h1RPhi,h2RPhi,h3RPhi,ThreeInOne);
0109
0110 // Res, RZ
0111 plot1DResCloseWire(h1RZ,h2RZ,h3RZ,ThreeInOne);
0112
0113 // Res, RZ, per wheel
0114 plot1DResCloseWire(h1RZ_W0,h2RZ_W0,h3RZ_W0,ThreeInOne);
0115 plot1DResCloseWire(h1RZ_W1,h2RZ_W1,h3RZ_W1,ThreeInOne);
0116 plot1DResCloseWire(h1RZ_W2,h2RZ_W2,h3RZ_W2,ThreeInOne);
0117 }
0118 if (doResVsAngle){
0119 // Res, Rphi
0120 plot1DResVsAngle(h1RPhi,h2RPhi,h3RPhi,ThreeInOne);
0121
0122 // Res, RZ
0123 plot1DResVsAngle(h1RZ,h2RZ,h3RZ,ThreeInOne);
0124
0125 // Res, RZ, per wheel
0126 plot1DResVsAngle(h1RZ_W0,h2RZ_W0,h3RZ_W0,ThreeInOne);
0127 plot1DResVsAngle(h1RZ_W1,h2RZ_W1,h3RZ_W1,ThreeInOne);
0128 plot1DResVsAngle(h1RZ_W2,h2RZ_W2,h3RZ_W2,ThreeInOne);
0129 }
0130
0131 if (doResVsFE){
0132 // Res, Rphi
0133 plot1DResVsFE(h1RPhi,h2RPhi,h3RPhi,ThreeInOne);
0134
0135 // Res, RZ
0136 plot1DResVsFE(h1RZ,h2RZ,h3RZ,ThreeInOne);
0137
0138 // // Res, RZ, per wheel
0139 // plot1DResVsFE(h1RZ_W0,h2RZ_W0,h3RZ_W0,ThreeInOne);
0140 // plot1DResVsFE(h1RZ_W1,h2RZ_W1,h3RZ_W1,ThreeInOne);
0141 // plot1DResVsFE(h1RZ_W2,h2RZ_W2,h3RZ_W2,ThreeInOne);
0142 }
0143 }
0144
0145 void plot1DRes(HRes1DHit* h1, HRes1DHit* h2, HRes1DHit* h3, bool ThreeInOne) {
0146 int i = 2;
0147
0148 if(ThreeInOne)
0149 cout << "ThreeInOne = true!" << endl;
0150 else
0151 cout << "ThreeInOne = false!" << endl;
0152
0153 TString N1 = "c_1D_" + h1->name;
0154 TString N2 = "c_1D_" + h2->name;
0155 TString N3 = "c_1D_" + h3->name;
0156 int form = 2;
0157 if (ThreeInOne) c1 = newCanvas(N1.Remove(5,2)+"_hRes",3,1,800,400);
0158 else newCanvas(N1+"_hRes",form);
0159 h1->hRes->SetXTitle("(d_{reco}-d_{sim})");
0160 h1->hRes->SetYTitle("# events");
0161 drawGFit(h1->hRes, -.15,.15,-.15,.15);
0162
0163 if (ThreeInOne) c1->cd(i++);
0164 else c1 = newCanvas(N2+"_hRes",form);
0165 h2->hRes->SetXTitle("(d_{reco}-d_{sim})");
0166 h2->hRes->SetYTitle("# events");
0167 drawGFit(h2->hRes, -.15,.15,-.15,.15);
0168
0169 if (ThreeInOne) c1->cd(i++);
0170 else c1 = newCanvas(N3+"_hRes",form);
0171 h3->hRes->SetXTitle("(d_{reco}-d_{sim})");
0172 h3->hRes->SetYTitle("# events");
0173 drawGFit(h3->hRes, -.15,.15,-.15,.15);
0174
0175 }
0176
0177 void plot1DResVsPos(HRes1DHit* h1, HRes1DHit* h2, HRes1DHit* h3, bool ThreeInOne) {
0178 int i = 2;
0179
0180 if(ThreeInOne)
0181 cout << "ThreeInOne = true!" << endl;
0182 else
0183 cout << "ThreeInOne = false!" << endl;
0184
0185 TString N1 = "c_1D_" + h1->name;
0186 TString N2 = "c_1D_" + h2->name;
0187 TString N3 = "c_1D_" + h3->name;
0188 int form = 2;
0189 if (ThreeInOne) c1 = newCanvas(N1.Remove(5,2)+"_hResVsPos",3,1,800,400);
0190 else newCanvas(N1+"_hResVsPos",form);
0191 plotAndProfileXSpread(h1->hResVsPos, 0.,2.1 ,true,-.3,.3);
0192
0193 if (ThreeInOne) c1->cd(i++);
0194 else c1 = newCanvas(N2+"_hResVsPos",form);
0195 plotAndProfileXSpread(h2->hResVsPos, 0.,2.1 ,true,-.5,.5);
0196
0197 if (ThreeInOne) c1->cd(i++);
0198 else c1 = newCanvas(N3+"_hResVsPos",form);
0199 plotAndProfileXSpread(h3->hResVsPos, 0.,2.1 ,true,-.5,.5);
0200
0201 }
0202
0203 void plot1DResCloseWire(HRes1DHit* h1, HRes1DHit* h2, HRes1DHit* h3, bool ThreeInOne) {
0204 int i = 2;
0205
0206 if(ThreeInOne)
0207 cout << "ThreeInOne = true!" << endl;
0208 else
0209 cout << "ThreeInOne = false!" << endl;
0210
0211 TString N1 = "c_1D_" + h1->name;
0212 TString N2 = "c_1D_" + h2->name;
0213 TString N3 = "c_1D_" + h3->name;
0214 int form = 2;
0215 if (ThreeInOne) c1 = newCanvas(N1.Remove(5,2)+"_hResVsPos",3,1,800,400);
0216 else newCanvas(N1+"_hResCloseWire",form);
0217 drawCloseWire(h1->hResVsPos, 10);
0218
0219 if (ThreeInOne) c1->cd(i++);
0220 else c1 = newCanvas(N2+"_hResCloseWire",form);
0221 drawCloseWire(h2->hResVsPos, 10);
0222
0223 if (ThreeInOne) c1->cd(i++);
0224 else c1 = newCanvas(N3+"_hResCloseWire",form);
0225 drawCloseWire(h3->hResVsPos, 10);
0226
0227 }
0228
0229 void drawCloseWire(TH2* h2, int border) {
0230 gPad->SetGrid(1,1);
0231 gStyle->SetGridColor(15);
0232 TH1D* hall= h2->ProjectionY("_all",-1,-1);
0233 TH1D* hclose= h2->ProjectionY("_cl",-1,border);
0234 TH1D* hfar= h2->ProjectionY("_far",border+1,-1);
0235 //hfar->DrawNormalized("",hfar->GetEntries());
0236 hall->DrawCopy();
0237 hfar->SetLineColor(4);
0238 hfar->DrawCopy("same");
0239 //hclose->DrawNormalized("same",hfar->GetEntries()/2.);
0240 hclose->SetLineColor(2);
0241 hclose->DrawCopy("same");
0242
0243 }
0244
0245 void plot1DResVsAngle(HRes1DHit* h1, HRes1DHit* h2, HRes1DHit* h3, bool ThreeInOne) {
0246 int i = 2;
0247
0248 TString N1 = "c_1D_" + h1->name;
0249 TString N2 = "c_1D_" + h2->name;
0250 TString N3 = "c_1D_" + h3->name;
0251 int form = 2;
0252 if (ThreeInOne) c1 = newCanvas(N1.Remove(5,2)+"_hResVsAngle",3,1,800,400);
0253 else newCanvas(N1+"_hResVsAngle",form);
0254 plotAndProfileXSpread(h1->hResVsAngle, 0.,.6 ,true,-0.2,0.2);
0255
0256 if (ThreeInOne) c1->cd(i++);
0257 else c1 = newCanvas(N2+"_hResVsAngle",form);
0258 plotAndProfileXSpread(h2->hResVsAngle, 0.,.6 ,true,-0.2,0.2);
0259
0260 if (ThreeInOne) c1->cd(i++);
0261 else c1 = newCanvas(N3+"_hResVsAngle",form);
0262 plotAndProfileXSpread(h3->hResVsAngle, 0.,.6 ,true,-0.2,0.2);
0263
0264 }
0265
0266 void plot1DResVsFE(HRes1DHit* h1, HRes1DHit* h2, HRes1DHit* h3, bool ThreeInOne) {
0267 int i = 2;
0268
0269 TString N1 = "c_1D_" + h1->name;
0270 TString N2 = "c_1D_" + h2->name;
0271 TString N3 = "c_1D_" + h3->name;
0272 int form = 2;
0273 if (ThreeInOne) c1 = newCanvas(N1.Remove(5,2)+"_hResVsDistFE",3,1,800,400);
0274 else newCanvas(N1+"_hResVsDistFE",form);
0275 plotAndProfileXSpread(h1->hResVsDistFE, 0.,400. ,true,-0.2,0.2);
0276
0277 if (ThreeInOne) c1->cd(i++);
0278 else c1 = newCanvas(N2+"_hResVsDistFE",form);
0279 plotAndProfileXSpread(h2->hResVsDistFE, 0.,400. ,true,-0.2,0.2);
0280
0281 if (ThreeInOne) c1->cd(i++);
0282 else c1 = newCanvas(N3+"_hResVsDistFE",form);
0283 plotAndProfileXSpread(h3->hResVsDistFE, 0.,400. ,true,-0.2,0.2);
0284
0285 }
0286 bool setPreferences(bool& doRes,
0287 bool& doResVsPos,
0288 bool& doResCloseWire,
0289 bool& doResVsAngle,
0290 bool& doResVsFE,
0291 bool& ThreeIn1) {
0292
0293 int dimension = 0;
0294
0295 cout << "===================================================" << endl;
0296 cout << "==== plotHitReso User Menu =====================" << endl;
0297 cout << "Chose the plot you want to produce:" << endl;
0298 cout << "1 - 1D RecHit Res" << endl;
0299 cout << "2 - 1D RecHit Res vs Pos" << endl;
0300 cout << "3 - 1D RecHit Res close wire" << endl;
0301 cout << "4 - 1D RecHit Res vs angle" << endl;
0302 cout << "5 - 1D RecHit Res vs FE distance" << endl;
0303 cout << "-->";
0304 cin >> dimension;
0305
0306 switch(dimension)
0307 {
0308 case 1:
0309 {
0310 doRes = true;
0311 break;
0312 }
0313 case 2:
0314 {
0315 doResVsPos = true;
0316 break;
0317 }
0318 case 3:
0319 {
0320 doResCloseWire = true;
0321 break;
0322 }
0323 case 4:
0324 {
0325 doResVsAngle = true;
0326 break;
0327 }
0328 case 5:
0329 {
0330 doResVsFE = true;
0331 break;
0332 }
0333 default:
0334 {
0335 cout << "Error: option not Valid, try again!" << endl;
0336 return false;
0337 //setPreferences(do1DRecHit, do2DRecHit, do2DSLPhiRecHit, do4DRecHit, ThreeIn1);
0338 break;
0339 }
0340 }
0341
0342 return true;
0343 int threeInOne = 0;
0344
0345 cout << "" << endl;
0346 cout << "Do you want to Plot three histos in one?" << endl;
0347 cout << "0 - No" << endl;
0348 cout << "1 - Yes" << endl;
0349 cout << "-->";
0350
0351 cin >> threeInOne;
0352
0353 switch(threeInOne)
0354 {
0355 case 0:
0356 {
0357 ThreeIn1 = false;
0358 break;
0359 }
0360 case 1:
0361 {
0362 ThreeIn1 = true;
0363 break;
0364 }
0365 default:
0366 {
0367 cout << "Not a valid option: default used!" << endl;
0368 ThreeIn1 = true;
0369 break;
0370 }
0371 }
0372
0373 return true;
0374 }