File indexing completed on 2024-04-06 12:30:04
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
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
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131 #include "TCanvas.h"
0132 #include "TChain.h"
0133 #include "TDirectory.h"
0134 #include "TF1.h"
0135 #include "TFile.h"
0136 #include "TFitResult.h"
0137 #include "TFitResultPtr.h"
0138 #include "TGraphAsymmErrors.h"
0139 #include "TH1D.h"
0140 #include "TH2.h"
0141 #include "THStack.h"
0142 #include "TLegend.h"
0143 #include "TMinuit.h"
0144 #include "TMath.h"
0145 #include "TPaveStats.h"
0146 #include "TPaveText.h"
0147 #include "TProfile.h"
0148 #include "TROOT.h"
0149 #include "TStyle.h"
0150
0151 #include <cstdlib>
0152 #include <fstream>
0153 #include <iomanip>
0154 #include <iostream>
0155 #include <string>
0156 #include <vector>
0157
0158
0159
0160 bool debug_ = false;
0161
0162 class TB06Analysis {
0163 public :
0164 TTree *fChain;
0165 Int_t fCurrent;
0166
0167
0168 Double_t eBeam_;
0169 Double_t etaBeam_;
0170 Double_t phiBeam_;
0171 Double_t edepEC_;
0172 Double_t edepHB_;
0173 Double_t edepHO_;
0174 Double_t noiseEC_;
0175 Double_t noiseHB_;
0176 Double_t noiseHO_;
0177 Double_t edepS1_;
0178 Double_t edepS2_;
0179 Double_t edepS3_;
0180 Double_t edepS4_;
0181 Double_t edepVC_;
0182 Double_t edepS7_;
0183 Double_t edepS8_;
0184
0185
0186 TBranch *b_eBeam_;
0187 TBranch *b_etaBeam_;
0188 TBranch *b_phiBeam_;
0189 TBranch *b_edepEC_;
0190 TBranch *b_edepHB_;
0191 TBranch *b_edepHO_;
0192 TBranch *b_noiseEC_;
0193 TBranch *b_noiseHB_;
0194 TBranch *b_noiseHO_;
0195 TBranch *b_edepS1_;
0196 TBranch *b_edepS2_;
0197 TBranch *b_edepS3_;
0198 TBranch *b_edepS4_;
0199 TBranch *b_edepVC_;
0200 TBranch *b_edepS7_;
0201 TBranch *b_edepS8_;
0202
0203 TB06Analysis(std::string infname, std::string outfname, int ipar, int ien,
0204 int model, double corrEB=1, double corrHB=1);
0205 virtual ~TB06Analysis();
0206 virtual Int_t Cut(Long64_t entry);
0207 virtual Int_t GetEntry(Long64_t entry);
0208 virtual Long64_t LoadTree(Long64_t entry);
0209 virtual void Init(TTree *tree);
0210 virtual void Loop();
0211 virtual Bool_t Notify();
0212 virtual void Show(Long64_t entry = -1);
0213 std::string outName_, modName_, partNam_, partFil_;
0214 double scaleEB_, scaleHB_, mipCut_, cutS4_, cutVC_, cutS8_;
0215 double xmin_, xmax_, delx_, corrEB_, corrHB_;
0216 int model_, nbin_, iene_;
0217 };
0218
0219 TB06Analysis::TB06Analysis(std::string inName, std::string outName, int ipar,
0220 int ien, int model, double corrEB,
0221 double corrHB) : fChain(0), outName_(outName),
0222 corrEB_(corrEB), corrHB_(corrHB) {
0223
0224 TFile *file = new TFile(inName.c_str());
0225 TDirectory *dir = (TDirectory*)file->FindObjectAny("testbeam");
0226 TTree *tree = (TTree*)dir->Get("TB06Sim");
0227 Init(tree);
0228 const int nmodels=36;
0229 double scaleEB[nmodels] = { 1.010, 1.011, 1.011, 1.011, 1.011, 1.011, 1.011, 1.011, 1.011, 1.011, 1.011, 1.011, 1.010, 1.010, 1.015, 1.015, 1.015, 1.015, 1.015, 1.015, 1.010, 1.011, 1.015, 1.015, 1.015, 1.015, 1.015, 1.015, 1.015, 1.015, 1.015, 1.015, 1.015, 1.015, 1.015, 1.015};
0230 double scaleHB[nmodels] = {114.13, 114.29, 106.61, 106.54, 106.33, 106.43, 106.38, 106.50, 106.59, 107.37, 106.47, 107.14, 107.11, 107.11, 105.94, 106.59, 106.64, 106.64, 106.59, 106.64, 107.11, 107.09, 105.89, 105.93, 105.87, 105.93, 105.86, 106.58, 106.65, 105.86, 105.91, 105.91, 105.90, 105.86, 105.78, 105.81};
0231 double cutS4[nmodels] = {0.0028, 0.0028, 0.0028, 0.0028, 0.0028, 0.0028, 0.0028, 0.0028, 0.0028, 0.0028, 0.0028, 0.0028, 0.0028, 0.0028, 0.0028, 0.0028, 0.0028, 0.0028, 0.0028, 0.0028, 0.0028, 0.0028, 0.0028, 0.0028, 0.0028, 0.0028, 0.0028, 0.0028, 0.0028, 0.0028, 0.0028, 0.0028, 0.0028, 0.0028, 0.0028, 0.0028};
0232 double cutVC[nmodels] = {0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014};
0233 double cutS8[nmodels] = {0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014, 0.0014};
0234 std::string modelNames[nmodels] = {"10.0.p02 QGSP_FTFP_BERT_EML",
0235 "10.0.p02 FTFP_BERT_EML",
0236 "10.2.p02 QGSP_FTFP_BERT_EMM",
0237 "10.2.p02 FTFP_BERT_EMM",
0238 "10.2.p02 FTFP_BERT_ATL_EMM",
0239 "10.4.0.beta FTFP_BERT_EMM",
0240 "10.3.ref08 FTFP_BERT_EMM",
0241 "10.3.ref09 FTFP_BERT_EMM",
0242 "10.3.ref10 FTFP_BERT_EMM",
0243 "10.3.ref11 FTFP_BERT_EMM",
0244 "10.3.p03 FTFP_BERT_EMM",
0245 "10.4.cand01 FTFP_BERT_EMM",
0246 "10.4.cand02 FTFP_BERT_EMM",
0247 "10.4 FTFP_BERT_EMM",
0248 "10.2.p02 FTFP_BERT_EMM 10.0.pre3",
0249 "10.4 FTFP_BERT_EMM 10.0.pre3",
0250 "10.4 FTFP_BERT_EMM VecGeom 10.0.pre3",
0251 "10.4 FTFP_BERT_EMM VecGeom+CLHEP 10.0.pre3",
0252 "10.4 FTFP_BERT_EMM CLHEP",
0253 "10.4 FTFP_BERT_EMM VecGeom+CLHEP",
0254 "10.4.ref01 FTFP_BERT_EMM",
0255 "10.4.ref02 FTFP_BERT_EMM",
0256 "10.5.0.beta FTFP_BERT_EMM",
0257 "10.4.ref07 FTFP_BERT_EMM",
0258 "10.4.ref08 FTFP_BERT_EMM",
0259 "10.4.ref08 FTFP_BERT_EMM",
0260 "10.5.cand01 FTFP_BERT_EMM",
0261 "10.4.ref00 FTFP_BERT_EMM",
0262 "10.4.p03 FTFP_BERT_EMM",
0263 "10.5.ref00 FTFP_BERT_EMM",
0264 "10.5.ref01 FTFP_BERT_EMM",
0265 "10.5.ref02 FTFP_BERT_EMM",
0266 "10.5.ref03 FTFP_BERT_EMM",
0267 "10.5.ref04 FTFP_BERT_EMM",
0268 "10.5.ref05 FTFP_BERT_EMM"
0269 "10.5.ref06 FTFP_BERT_EMM"
0270 };
0271 std::string partsF[7] = {"pi-","pi+","k-","k+","pro+","pro-","e-"};
0272 std::string partsN[7] = {"#pi^{-}","#pi^{+}","K^{-}","K^{+}","p","pbar","e"};
0273 int iens[16] = {2,3,4,5,6,7,8,9,20,30,50,100,150,200,300,350};
0274
0275
0276
0277
0278
0279 double xminh[16] = {-2,-2,-1,-1,-1,-1,-1,-1,2,6,10,40,70,90,120,140};
0280 double xmaxh[16] = {6,9,11,14,15,17,18,20,30,40,70,130,170,250,370,420};
0281 double delxs[16] = {.2,.2,.2,.2,.2,.2,.2,.2,.5,.5,1.,1.,2.,2.,2.,2.};
0282
0283 if (model < 0 || model >= nmodels) model_ = 0;
0284 else model_ = model;
0285 if (ien < 0 || ien > 15) ien = 0;
0286 if (ipar < 0 || ipar > 6) ipar = 0;
0287 scaleEB_ = scaleEB[model_];
0288 scaleHB_ = scaleHB[model_];
0289 modName_ = modelNames[model_];
0290 mipCut_ = 1.20;
0291 cutS4_ = cutS4[model_];
0292 cutVC_ = cutVC[model_];
0293 cutS8_ = cutS8[model_];
0294 xmin_ = xminh[ien];
0295 xmax_ = xmaxh[ien];
0296 delx_ = delxs[ien];
0297 nbin_ = (int)((xmax_-xmin_)/delx_);
0298 iene_ = iens[ien];
0299 partFil_ = partsF[ipar];
0300 partNam_ = partsN[ipar];
0301 std::cout << "Model " << model_ << ":" << modName_ << " Particle " << partFil_
0302 << " Scale " << scaleEB_ << ":" << scaleHB_ << " Cuts " << cutS4_
0303 << ":" << cutVC_ << ":" << cutS8_ << std::endl;
0304 }
0305
0306 TB06Analysis::~TB06Analysis() {
0307 if (!fChain) return;
0308 delete fChain->GetCurrentFile();
0309 }
0310
0311 Int_t TB06Analysis::GetEntry(Long64_t entry) {
0312
0313 if (!fChain) return 0;
0314 return fChain->GetEntry(entry);
0315 }
0316
0317 Long64_t TB06Analysis::LoadTree(Long64_t entry) {
0318
0319 if (!fChain) return -5;
0320 Long64_t centry = fChain->LoadTree(entry);
0321 if (centry < 0) return centry;
0322 if (fChain->GetTreeNumber() != fCurrent) {
0323 fCurrent = fChain->GetTreeNumber();
0324 Notify();
0325 }
0326 return centry;
0327 }
0328
0329 void TB06Analysis::Init(TTree *tree) {
0330
0331
0332
0333
0334
0335
0336
0337
0338
0339 if (!tree) return;
0340 fChain = tree;
0341 fCurrent = -1;
0342 fChain->SetMakeClass(1);
0343
0344 fChain->SetBranchAddress("eBeam_", &eBeam_, &b_eBeam_);
0345 fChain->SetBranchAddress("etaBeam_", &etaBeam_, &b_etaBeam_);
0346 fChain->SetBranchAddress("phiBeam_", &phiBeam_, &b_phiBeam_);
0347 fChain->SetBranchAddress("edepEC_", &edepEC_, &b_edepEC_);
0348 fChain->SetBranchAddress("edepHB_", &edepHB_, &b_edepHB_);
0349 fChain->SetBranchAddress("edepHO_", &edepHO_, &b_edepHO_);
0350 fChain->SetBranchAddress("noiseEC_", &noiseEC_, &b_noiseEC_);
0351 fChain->SetBranchAddress("noiseHB_", &noiseHB_, &b_noiseHB_);
0352 fChain->SetBranchAddress("noiseHO_", &noiseHO_, &b_noiseHO_);
0353 fChain->SetBranchAddress("edepS1_", &edepS1_, &b_edepS1_);
0354 fChain->SetBranchAddress("edepS2_", &edepS2_, &b_edepS2_);
0355 fChain->SetBranchAddress("edepS3_", &edepS3_, &b_edepS3_);
0356 fChain->SetBranchAddress("edepS4_", &edepS4_, &b_edepS4_);
0357 fChain->SetBranchAddress("edepVC_", &edepVC_, &b_edepVC_);
0358 fChain->SetBranchAddress("edepS7_", &edepS7_, &b_edepS7_);
0359 fChain->SetBranchAddress("edepS8_", &edepS8_, &b_edepS8_);
0360 Notify();
0361
0362 }
0363
0364 Bool_t TB06Analysis::Notify() {
0365
0366
0367
0368
0369
0370
0371 return kTRUE;
0372 }
0373
0374 void TB06Analysis::Show(Long64_t entry) {
0375
0376
0377 if (!fChain) return;
0378 fChain->Show(entry);
0379 }
0380
0381 Int_t TB06Analysis::Cut(Long64_t ) {
0382
0383
0384
0385 return 1;
0386 }
0387
0388 void TB06Analysis::Loop() {
0389
0390
0391
0392
0393
0394
0395
0396
0397
0398
0399
0400
0401
0402
0403
0404
0405
0406
0407
0408
0409
0410
0411
0412
0413 if (fChain == 0) return;
0414 TFile *fout = new TFile(outName_.c_str(), "RECREATE");
0415 TH1D *h_es[7], *h_EC, *h_HB, *h_EN1, *h_EN2;
0416 std::string names[7] = {"h1", "h2", "h3", "h4", "h5", "h6", "h7"};
0417 std::string title[7] = {"Energy in S1", "Energy in S2", "Energy in S3",
0418 "Energy in S4", "Energy in VC", "Energy in S7",
0419 "Energy in S8"};
0420 for (int i=0; i<7; ++i) {
0421 h_es[i] = new TH1D(names[i].c_str(), title[i].c_str(), 1000, 0, 0.02);
0422 h_es[i]->GetXaxis()->SetTitle("Energy (GeV)");
0423 h_es[i]->GetYaxis()->SetTitle("Events");
0424 }
0425 h_EC = new TH1D("EC", "Energy in EB", 2000, 0, 100.0);
0426 h_EC->GetXaxis()->SetTitle("Energy (GeV)");
0427 h_EC->GetYaxis()->SetTitle("Events");
0428 h_HB = new TH1D("HB", "Energy in HB", 2000, 0, 1.0);
0429 h_HB->GetXaxis()->SetTitle("Energy (GeV)");
0430 h_HB->GetYaxis()->SetTitle("Events");
0431 char nameh[100], titlh[100];
0432 sprintf (nameh, "EN1%s%d", partFil_.c_str(), model_);
0433 sprintf (titlh, "Total Energy (%d GeV/c %s)", iene_, partNam_.c_str());
0434 h_EN1 = new TH1D(nameh, titlh, nbin_, xmin_, xmax_);
0435 h_EN1->Sumw2();
0436 h_EN1->GetXaxis()->SetTitle("Energy (GeV)");
0437 h_EN1->GetYaxis()->SetTitle("Events");
0438 sprintf (nameh, "EN2%s%d", partFil_.c_str(), model_);
0439 sprintf (titlh, "Total Energy (MIP in ECAL %d GeV/c %s)", iene_, partNam_.c_str());
0440 h_EN2 = new TH1D(nameh, titlh, nbin_, xmin_, xmax_);
0441 h_EN2->Sumw2();
0442 h_EN2->GetXaxis()->SetTitle("Energy (GeV)");
0443 h_EN2->GetYaxis()->SetTitle("Events");
0444
0445 Long64_t nentries = fChain->GetEntriesFast();
0446 Long64_t nbytes = 0, nb = 0;
0447 std::cout << "Correction Factors " << corrEB_ << ":" << corrHB_ << " and "
0448 << nentries << " entries" << std::endl;
0449
0450 for (Long64_t jentry=0; jentry<nentries;jentry++) {
0451 Long64_t ientry = LoadTree(jentry);
0452 if (ientry < 0) break;
0453 nb = fChain->GetEntry(jentry); nbytes += nb;
0454
0455 h_es[0]->Fill(edepS1_);
0456 h_es[1]->Fill(edepS2_);
0457 h_es[2]->Fill(edepS3_);
0458 h_es[3]->Fill(edepS4_);
0459 h_es[4]->Fill(edepVC_);
0460 h_es[5]->Fill(edepS7_);
0461 h_es[6]->Fill(edepS8_);
0462 if (debug_) {
0463 std::cout << edepS4_ << ":" << edepVC_ << ":" << edepS8_ << " Cuts "
0464 << cutS4_ << ":" << cutVC_ << ":" << cutS8_ << " Result "
0465 << (edepS4_ < cutS4_ && edepVC_ < cutVC_ && edepS8_ < cutS8_)
0466 << std::endl;
0467 std::cout << edepEC_ << ":" << edepHB_ << " Scale " << scaleEB_ << ":"
0468 << scaleHB_ << " Noise " << corrEB_*noiseEC_ << ":"
0469 << corrHB_*noiseHB_ << std::endl;
0470 }
0471 if (edepS4_ < cutS4_ && edepVC_ < cutVC_ && edepS8_ < cutS8_) {
0472 h_EC->Fill(edepEC_);
0473 h_HB->Fill(edepHB_);
0474 double enEB = scaleEB_*(edepEC_+corrEB_*noiseEC_);
0475 double enHB = scaleHB_*edepHB_+corrHB_*noiseHB_;
0476 double eTot = enEB+enHB;
0477 h_EN1->Fill(eTot);
0478 if (enEB < mipCut_) h_EN2->Fill(eTot);
0479 }
0480 }
0481 fout->cd(); fout->Write(); fout->Close();
0482 }
0483
0484 TCanvas* DrawTrigger(std::string fileName) {
0485 std::string names[7] = {"h1", "h2", "h3", "h4", "h5", "h6", "h7"};
0486 std::string title[7] = {"S1", "S2", "S3", "S4", "Veto Counter", "MC1", "MC2"};
0487 int colors[7] = {2,6,4,1,7,9,3};
0488 int mtype[7] = {20,21,22,23,24,33,25};
0489
0490 TCanvas* pad(0);
0491 gStyle->SetCanvasBorderMode(0); gStyle->SetCanvasColor(kWhite);
0492 gStyle->SetPadColor(kWhite); gStyle->SetFillColor(kWhite);
0493 gStyle->SetOptTitle(0);
0494 gStyle->SetOptStat(1110); gStyle->SetOptFit(0);
0495 TFile* file = new TFile(fileName.c_str());
0496 if (file) {
0497 bool first(true);
0498 double dy = 0.06;
0499 double yh = 0.90;
0500 double yh1 = yh-5*dy - 0.01;
0501 pad = new TCanvas("Trigger","TriggerCounter", 700, 500);
0502 pad->SetLogy();
0503 TLegend *legend = new TLegend(0.65, yh1-0.20, 0.90, yh1);
0504 legend->SetFillColor(kWhite);
0505 for (int i=0; i<7; ++i) {
0506 TH1D *hist = (TH1D*)file->FindObjectAny(names[i].c_str());
0507 if (hist) {
0508 hist->SetLineColor(colors[i]);
0509 hist->SetMarkerColor(colors[i]);
0510 hist->SetMarkerStyle(mtype[i]);
0511 hist->GetXaxis()->SetTitle("Energy (GeV)");
0512 hist->GetYaxis()->SetTitle("Events");
0513 hist->GetYaxis()->SetLabelOffset(0.005);
0514 hist->GetYaxis()->SetTitleOffset(1.20);
0515 if (first) hist->Draw("");
0516 else hist->Draw("sames");
0517 first = false;
0518 pad->Update();
0519 TPaveStats* st1 = (TPaveStats*)hist->GetListOfFunctions()->FindObject("stats");
0520 if (st1 != NULL) {
0521 st1->SetFillColor(kWhite);
0522 st1->SetLineColor(colors[i]);
0523 st1->SetTextColor(colors[i]);
0524 st1->SetY1NDC(yh-dy); st1->SetY2NDC(yh);
0525 st1->SetX1NDC(0.70); st1->SetX2NDC(0.90);
0526 yh -= dy;
0527 }
0528 legend->AddEntry(hist,title[i].c_str(),"lp");
0529 }
0530 }
0531 legend->Draw("same");
0532 pad->Update();
0533 }
0534 return pad;
0535 }
0536
0537 Double_t langaufun(Double_t *x, Double_t *par) {
0538
0539
0540
0541
0542
0543
0544
0545
0546
0547
0548
0549
0550
0551 Double_t invsq2pi = 0.3989422804014;
0552 Double_t mpshift = -0.22278298;
0553
0554
0555 Double_t np = 100.0;
0556 Double_t sc = 5.0;
0557
0558
0559 Double_t xx;
0560 Double_t mpc;
0561 Double_t fland;
0562 Double_t sum = 0.0;
0563 Double_t xlow,xupp;
0564 Double_t step;
0565 Double_t i;
0566 Double_t par0=0.2;
0567
0568
0569 mpc = par[1] - mpshift * par0 * par[1];
0570
0571
0572 xlow = x[0] - sc * par[3];
0573 xupp = x[0] + sc * par[3];
0574
0575 step = (xupp-xlow) / np;
0576
0577
0578 for(i=1.0; i<=np/2; i++) {
0579 xx = xlow + (i-.5) * step;
0580 fland = TMath::Landau(xx,mpc,par0*par[1], kTRUE);
0581 sum += fland * TMath::Gaus(x[0],xx,par[3]);
0582
0583 xx = xupp - (i-.5) * step;
0584 fland = TMath::Landau(xx,mpc,par0*par[1], kTRUE);
0585 sum += fland * TMath::Gaus(x[0],xx,par[3]);
0586 }
0587
0588 return (par[2] * step * sum * invsq2pi / par[3]);
0589 }
0590
0591 Double_t crystalfun(Double_t *x, Double_t *par) {
0592
0593
0594 Double_t xx = x[0] - par[1];
0595 Double_t sigma = par[2];
0596 Double_t an = par[3];
0597 Double_t alpha = par[4];
0598
0599 double crystal = 0;
0600 if (xx > -alpha*sigma) {
0601 crystal = par[0]*std::exp(-0.5*(xx/sigma)*(xx/sigma));
0602 } else {
0603 Double_t den = (1.0-(alpha/an)*(xx/sigma) - (alpha*alpha)/an);
0604 if (den > 0) {
0605 Double_t den1 = an*std::log(den);
0606 crystal = par[0]*std::exp(-0.5*alpha*alpha)/std::exp(den1);
0607 }
0608 }
0609 return crystal;
0610 }
0611
0612 std::pair<TF1*,TFitResultPtr> functionFit(TH1D *his, double *fitrange,
0613 double *startvalues,
0614 double *parlimitslo,
0615 double *parlimitshi, int mode) {
0616
0617 char FunName[100];
0618 std::string fname("LanGau");
0619 if (mode < 0) fname = "CrysBall";
0620 sprintf(FunName,"%s_%s",fname.c_str(), his->GetName());
0621
0622 TF1 *ffitold = (TF1*)gROOT->GetListOfFunctions()->FindObject(FunName);
0623 if (ffitold) delete ffitold;
0624
0625 TF1 *ffit;
0626 int npar=4;
0627 if (mode >=0) {
0628 ffit = new TF1(FunName,langaufun,fitrange[0],fitrange[1],npar);
0629 } else {
0630 npar = 5;
0631 ffit = new TF1(FunName,crystalfun,fitrange[0],fitrange[1],npar);
0632 }
0633 ffit->SetParameters(startvalues);
0634 if (mode >=0) {
0635 ffit->SetParNames("Width","MP","Area","GSigma");
0636 } else {
0637 ffit->SetParNames("Area","Mean","Width","AN","Alpha");
0638 }
0639 if (mode == 0) {
0640 for (int i=0; i<npar; i++)
0641 ffit->SetParLimits(i, parlimitslo[i], parlimitshi[i]);
0642 }
0643
0644 TFitResultPtr fptr = his->Fit(FunName,"wwqRB0S");
0645 return std::pair<TF1*,TFitResultPtr>(ffit,fptr);
0646 }
0647
0648 TCanvas* FitTrigger(std::string fileName, int type) {
0649 std::string names[7] = {"h1", "h2", "h3", "h4", "h5", "h6", "h7"};
0650 std::string title[7] = {"S1", "S2", "S3", "S4", "Veto Counter", "MC1", "MC2"};
0651 int colors[7] = {2,6,4,1,7,9,3};
0652 int mtype[7] = {20,21,22,23,24,33,25};
0653
0654 TCanvas* pad(0);
0655 gStyle->SetCanvasBorderMode(0); gStyle->SetCanvasColor(kWhite);
0656 gStyle->SetPadColor(kWhite); gStyle->SetFillColor(kWhite);
0657 gStyle->SetOptTitle(0);
0658 gStyle->SetOptStat(1110); gStyle->SetOptFit(10);
0659 TFile* file = new TFile(fileName.c_str());
0660 if (file) {
0661 double dy = 0.15;
0662 double yh = 0.90;
0663 double yh1 = yh-dy-0.01;
0664 TH1D *hist = (TH1D*)file->FindObjectAny(names[type].c_str());
0665 if (hist) {
0666 char name[100];
0667 sprintf(name,"TriggerFit%d",type);
0668 pad = new TCanvas(name,name,700,500);
0669 TLegend *legend = new TLegend(0.65, yh1-0.05, 0.90, yh1);
0670 legend->SetFillColor(kWhite);
0671 hist->SetLineColor(colors[type]);
0672 hist->SetMarkerColor(colors[type]);
0673 hist->SetMarkerStyle(mtype[type]);
0674 hist->GetXaxis()->SetTitle("Energy (GeV)");
0675 hist->GetYaxis()->SetTitle("Events");
0676 hist->GetYaxis()->SetLabelOffset(0.005);
0677 hist->GetYaxis()->SetTitleOffset(1.20);
0678 double LowEdge(0.001);
0679 double HighEdge(0.005);
0680 TF1 *Fitfun = new TF1(name,"landau",LowEdge,HighEdge);
0681 TFitResultPtr Fit = hist->Fit(Fitfun, "+0wwqR");
0682 hist->GetXaxis()->SetRangeUser(0, 0.005);
0683 hist->Draw("");
0684 Fitfun->Draw("same");
0685
0686 pad->Update();
0687 TPaveStats* st1 = (TPaveStats*)hist->GetListOfFunctions()->FindObject("stats");
0688 if (st1 != NULL) {
0689 st1->SetFillColor(kWhite);
0690 st1->SetLineColor(colors[type]);
0691 st1->SetTextColor(colors[type]);
0692 st1->SetY1NDC(yh-dy); st1->SetY2NDC(yh);
0693 st1->SetX1NDC(0.60); st1->SetX2NDC(0.90);
0694 }
0695 legend->AddEntry(hist,title[type].c_str(),"lp");
0696 legend->Draw("same");
0697 pad->Update();
0698 }
0699 }
0700 return pad;
0701 }
0702
0703 TCanvas* FitEBHB(std::string fileName, int type, int model=0, bool save=false) {
0704 std::string names[2] = {"EC", "HB"};
0705 std::string title[2] = {"Energy in EB", "Energy in HB"};
0706 int colors[6] = {2,6,4,1,7,9};
0707 int mtype[6] = {20,21,22,23,24,33};
0708
0709 TCanvas* pad(0);
0710 gStyle->SetCanvasBorderMode(0); gStyle->SetCanvasColor(kWhite);
0711 gStyle->SetPadColor(kWhite); gStyle->SetFillColor(kWhite);
0712 gStyle->SetOptTitle(0);
0713 gStyle->SetOptStat(1110); gStyle->SetOptFit(10);
0714 char name[100];
0715 sprintf (name, "model%d/%s", model, fileName.c_str());
0716 TFile* file = new TFile(name);
0717 if (file) {
0718 double dy = 0.20;
0719 double yh = 0.90;
0720 double yh1 = yh-dy-0.01;
0721 double xh = (type == 0) ? 0.40 : 0.90;
0722 TH1D *hist = (TH1D*)file->FindObjectAny(names[type].c_str());
0723 if (hist) {
0724 sprintf(name,"%sFit%d",names[type].c_str(),model);
0725 pad = new TCanvas(name,name,700,500);
0726 hist->SetLineColor(colors[type]);
0727 hist->SetLineWidth(2);
0728 hist->SetMarkerColor(colors[type]);
0729 hist->SetMarkerStyle(mtype[type]);
0730 hist->GetXaxis()->SetTitle("Energy (GeV)");
0731 hist->GetYaxis()->SetTitle("Events");
0732 hist->GetYaxis()->SetLabelOffset(0.005);
0733 hist->GetYaxis()->SetTitleOffset(1.20);
0734 double LowEdge = hist->GetMean() - 0.8*hist->GetRMS();
0735 double HighEdge = hist->GetMean() + 2.*hist->GetRMS();
0736 TFitResultPtr Fit = hist->Fit("gaus", "+0wwqRS", "", LowEdge, HighEdge);
0737 std::cout << Fit->Value(0) << " 1 " << Fit->Value(1) << " 2 " << Fit->Value(2) << std::endl;
0738 double startvalues[5], fitrange[2], lowValue[5], highValue[5];
0739 startvalues[0] = Fit->Value(0); lowValue[0] = 0.0; highValue[0] = 10.0*startvalues[0];
0740 startvalues[1] = Fit->Value(1); lowValue[1] = 0.5*startvalues[1]; highValue[1] = 2.*startvalues[1];
0741 startvalues[2] = Fit->Value(2); lowValue[2] = 0.5*startvalues[2]; highValue[2] = 2.*startvalues[2];
0742 startvalues[3] = 6.45; lowValue[3] = 0.5*startvalues[3]; highValue[3] = 2.*startvalues[3];
0743 startvalues[4] = 0.91; lowValue[4] = 0.5*startvalues[4]; highValue[4] = 2.*startvalues[4];
0744 TF1 *Fitfun;
0745 if (type == 0) {
0746 fitrange[0] = startvalues[1]-10.*startvalues[2];
0747 fitrange[1] = startvalues[1]+2.*startvalues[2];
0748 std::pair<TF1*,TFitResultPtr> ffit = functionFit(hist, fitrange, startvalues, lowValue,highValue,-1);
0749 Fitfun = ffit.first;
0750 Fit = ffit.second;
0751 } else {
0752 fitrange[0] = startvalues[1]-10.*startvalues[2];
0753 fitrange[1] = startvalues[1]+10.*startvalues[2];
0754 Fitfun = new TF1(name,"gaus",fitrange[0],fitrange[1]);
0755 Fit = hist->Fit(Fitfun, "+0wwqRS");
0756 }
0757 std::cout << LowEdge << " " << startvalues[1]-2.*startvalues[3] << " "
0758 << HighEdge << " " << fitrange[1] << " Fit " << Fit->Value(1)
0759 << ":" << (50.0/Fit->Value(1)) << std::endl;
0760 double low = fitrange[0]-2.*startvalues[2];
0761 double high = fitrange[1]+2.*startvalues[2];
0762 hist->GetXaxis()->SetRangeUser(low, high);
0763 hist->Draw("");
0764 Fitfun->Draw("same");
0765 pad->Update();
0766
0767 TPaveStats* st1 = (TPaveStats*)hist->GetListOfFunctions()->FindObject("stats");
0768 if (st1 != NULL) {
0769 st1->SetFillColor(kWhite);
0770 st1->SetLineColor(colors[type]);
0771 st1->SetTextColor(colors[type]);
0772 st1->SetY1NDC(yh-dy); st1->SetY2NDC(yh);
0773 st1->SetX1NDC(xh-0.3); st1->SetX2NDC(xh);
0774 }
0775 TLegend *legend = new TLegend(xh-0.25, yh1-0.05, xh, yh1);
0776 legend->SetFillColor(kWhite);
0777 legend->AddEntry(hist,title[type].c_str(),"lp");
0778 legend->Draw("same");
0779 pad->Update();
0780 if (save) {
0781 sprintf (name, "%s.pdf", pad->GetName());
0782 pad->Print(name);
0783 }
0784 }
0785 }
0786 return pad;
0787 }
0788
0789 double GetScaleFactor(int type, int ie, std::string dirName="RespAll") {
0790 char infil1[200], infil2[200];
0791 std::string partsF[6] = {"pim","pip","km","kp","prop","prom"};
0792 int iens[16] = {2,3,4,5,6,7,8,9,20,30,50,100,150,200,300,350};
0793 if (dirName == "") {
0794 sprintf(infil1,"%s.txt", partsF[type].c_str());
0795 sprintf(infil2,"%sn.txt", partsF[type].c_str());
0796 } else {
0797 sprintf(infil1,"%s/%s.txt", dirName.c_str(), partsF[type].c_str());
0798 sprintf(infil2,"%s/%sn.txt", dirName.c_str(), partsF[type].c_str());
0799 }
0800 double pbeam, resp, reso, scale(1.0), resp1(0), resp2(0);
0801 bool ok(false);
0802 std::ifstream fInput1(infil1);
0803 if (!fInput1.good()) {
0804 std::cout << "Cannot open file " << infil1 << std::endl;
0805 } else {
0806 while (1) {
0807 fInput1 >> pbeam >> resp >> reso;
0808 if (!fInput1.good()) break;
0809 int ip = (int)(pbeam+0.01);
0810 if (ip == iens[ie]) {
0811 resp1 = resp; ok = true; break;
0812 }
0813 }
0814 fInput1.close();
0815 }
0816 if (ok) {
0817 std::ifstream fInput2(infil2);
0818 ok = false;
0819 if (!fInput2.good()) {
0820 std::cout << "Cannot open file " << infil2 << std::endl;
0821 } else {
0822 while (1) {
0823 fInput2 >> pbeam >> resp >> reso;
0824 if (!fInput2.good()) break;
0825 int ip = (int)(pbeam+0.01);
0826 if (ip == iens[ie]) {
0827 resp2 = resp; ok = true; break;
0828 }
0829 }
0830 fInput2.close();
0831 }
0832 }
0833 if (ok) scale = resp1/resp2;
0834 if (debug_)
0835 std::cout << type << ":" << ie << ":" << iens[ie] << " response " << resp1
0836 << ":" << resp2 << ":" << scale << std::endl;
0837 return scale;
0838 }
0839
0840 bool FillHistData(char* infile, TH1D* h_eEB, TH1D* h_eHB, TH1D* h_eTot,
0841 double scale=1.0) {
0842
0843 bool flag(false);
0844 std::ifstream fInput(infile);
0845 if (!fInput.good()) {
0846 std::cout << "Cannot open file " << infile << std::endl;
0847 } else {
0848 char buffer [1024];
0849 unsigned int all(1), good(0);
0850 fInput.getline(buffer, 1024);
0851 if (debug_) std::cout << buffer << std::endl;
0852 double eEB, eHB, eHO;
0853 double eEBl(9999), eEBh(-9999), eHBl(9999), eHBh(-9999), eTotl(9999), eToth(-9999);
0854 while (1) {
0855 fInput >> eEB >> eHB >> eHO;
0856 if (!fInput.good()) break;
0857 all++; good++;
0858 double eTot = eEB+eHB;
0859 if (h_eEB != 0) h_eEB->Fill(scale*eEB);
0860 if (h_eHB != 0) h_eHB->Fill(scale*eHB);
0861 if (h_eTot != 0) h_eTot->Fill(scale*eTot);
0862 if (eEB < eEBl) eEBl = eEB; if (eEB > eEBh) eEBh = eEB;
0863 if (eHB < eHBl) eHBl = eHB; if (eHB > eHBh) eHBh = eHB;
0864 if (eTot < eTotl) eTotl = eTot; if (eTot > eToth) eToth = eTot;
0865 }
0866 if (debug_) {
0867 std::cout << "Reads " << all << " (" << good << ") records from "
0868 << infile << std::endl << "Minimum/maximum for EB " << eEBl
0869 << ":" << eEBh << " HB " << eHBl << ":" << eHBh << " Total "
0870 << eTotl << ":" << eToth << std::endl;
0871 }
0872 fInput.close();
0873 flag = (good>0);
0874 }
0875 return flag;
0876 }
0877
0878 std::vector<TCanvas*> DrawHistData(int type, int ie, std::string dirName="TB06",
0879 bool rescale=false) {
0880 std::string partsF[6] = {"pi-","pi+","k-","k+","pro+","pro-"};
0881 std::string partsN[6] = {"#pi^{-}","#pi^{+}","K^{-}","K^{+}","p","pbar"};
0882 std::string names[3] = {"ECAL", "HCAL", "Total"};
0883 int iens[16] = {2,3,4,5,6,7,8,9,20,30,50,100,150,200,300,350};
0884 double xmine(-2);
0885 double xmaxe[16] = {3,4,4,6,6,8,8,10,45,45,100,200,200,350,350,500};
0886
0887
0888
0889
0890
0891 double xminh[16] = {-2,-2,-1,-1,-1,-1,-1,-1,2,6,10,40,70,90,120,140};
0892 double xmaxh[16] = {6,9,11,14,15,17,18,20,30,40,70,130,170,250,370,420};
0893 double delxs[16] = {.2,.2,.2,.2,.2,.2,.2,.2,.5,.5,1.,1.,2.,2.,2.,2.};
0894
0895 std::vector<TCanvas*> pads;
0896 char infile[200], title[50], name[50];
0897 if (dirName == "") sprintf(infile,"%s%d.txt", partsF[type].c_str(), iens[ie]);
0898 else sprintf(infile,"%s/%s%d.txt", dirName.c_str(), partsF[type].c_str(), iens[ie]);
0899 sprintf (title, "%d GeV %s", iens[ie], partsN[type].c_str());
0900 TH1D* hist[3];
0901 double xmin(xmine), xmax, delx;
0902 int nbin(0);
0903 xmax = xmaxe[ie];
0904 delx = delxs[ie];
0905 nbin = (int)((xmax-xmin)/delx);
0906 sprintf (name, "%s%s%d", names[0].c_str(), partsF[type].c_str(), iens[ie]);
0907 hist[0] = new TH1D(name, title, nbin, xmin, xmax);
0908 hist[0]->Sumw2();
0909 xmin = xminh[ie];
0910 xmax = xmaxh[ie];
0911 nbin = (int)((xmax-xmin)/delx);
0912 sprintf (name, "%s%s%d", names[1].c_str(), partsF[type].c_str(), iens[ie]);
0913 hist[1] = new TH1D(name, title, nbin, xmin, xmax);
0914 hist[1]->Sumw2();
0915 sprintf (name, "%s%s%d", names[2].c_str(), partsF[type].c_str(), iens[ie]);
0916 hist[2] = new TH1D(name, title, nbin, xmin, xmax);
0917 hist[2]->Sumw2();
0918 double scale = rescale ? GetScaleFactor(type, ie) : 1.0;
0919 bool ok = FillHistData(infile, hist[0], hist[1], hist[2], scale);
0920
0921 gStyle->SetCanvasBorderMode(0); gStyle->SetCanvasColor(kWhite);
0922 gStyle->SetPadColor(kWhite); gStyle->SetFillColor(kWhite);
0923 gStyle->SetOptTitle(0);
0924 gStyle->SetOptStat(1110); gStyle->SetOptFit(0);
0925 if (ok) {
0926 double mean[3], rms[3];
0927 for (int k=0; k<3; ++k) {
0928 sprintf(name, "%s%s%d", names[k].c_str(), partsF[type].c_str(), iens[ie]);
0929 TCanvas* pad = new TCanvas(name, name, 700, 500);
0930 pad->SetRightMargin(0.10); pad->SetTopMargin(0.10);
0931 sprintf(name, "%s Energy (GeV)", names[k].c_str());
0932 hist[k]->GetXaxis()->SetTitle(name);
0933 hist[k]->GetYaxis()->SetTitle("Events");
0934 hist[k]->GetYaxis()->SetTitleOffset(1.2);
0935 hist[k]->Draw(); pad->Update();
0936 TPaveStats* st1 = (TPaveStats*)hist[k]->GetListOfFunctions()->FindObject("stats");
0937 if (st1 != NULL) {
0938 st1->SetFillColor(0);
0939 st1->SetY1NDC(0.75); st1->SetY2NDC(0.90);
0940 st1->SetX1NDC(0.70); st1->SetX2NDC(0.90);
0941 }
0942 mean[k] = hist[k]->GetMean(); rms[k] = hist[k]->GetRMS();
0943 TPaveText *text = new TPaveText(0.70,0.70,0.90,0.745,"blNDC");
0944 text->SetFillColor(0); text->AddText(title); text->Draw("same");
0945 pad->Modified(); pad->Update();
0946 pads.push_back(pad);
0947 }
0948 std::cout << partsF[type] << " " << iens[ie] << " GeV";
0949 for (int k=0; k<3; ++k) std::cout << " " << mean[k] << " " << rms[k];
0950 std::cout << " " << mean[2]/iens[ie] << " " << rms[2]/mean[2] << std::endl;
0951 }
0952 return pads;
0953 }
0954
0955 void DrawHistDataAll(std::string dirName="TB06", bool rescale=false,
0956 bool save=false) {
0957 char filename[100];
0958 for (int k1=0; k1<6; ++k1) {
0959 for (int k2=0; k2<16; ++k2) {
0960 std::vector<TCanvas*> pads = DrawHistData(k1,k2,dirName,rescale);
0961 if (save) {
0962 for (unsigned int k=0; k<pads.size(); ++k) {
0963 sprintf (filename, "%s.pdf", pads[k]->GetName());
0964 pads[k]->Print(filename);
0965 }
0966 }
0967 }
0968 }
0969 }
0970
0971
0972 TCanvas* plotDataMC(int ipar, int ien, std::vector<int> models, int type,
0973 int rebin=1, int irtype=1, std::string prefix="model",
0974 bool approve=false, bool stat=true, double xmin0=-1,
0975 double xmax0=-1, bool rescale=true) {
0976 static const int nmodels=36;
0977 std::string modelNames[nmodels] = {"G4 10.0.p02 QGSP_FTFP_BERT_EML",
0978 "G4 10.0.p02 FTFP_BERT_EML",
0979 "G4 10.2.p02 QGSP_FTFP_BERT_EMM",
0980 "G4 10.2.p02 FTFP_BERT_EMM",
0981 "G4 10.2.p02 FTFP_BERT_ATL_EMM",
0982 "G4 10.4.beta FTFP_BERT_EMM",
0983 "G4 10.3.ref08 FTFP_BERT_EMM",
0984 "G4 10.3.ref09 FTFP_BERT_EMM",
0985 "G4 10.3.ref10 FTFP_BERT_EMM",
0986 "G4 10.3.ref11 FTFP_BERT_EMM",
0987 "G4 10.3.p03 FTFP_BERT_EMM",
0988 "G4 10.4.cand01 FTFP_BERT_EMM",
0989 "G4 10.4.cand02 FTFP_BERT_EMM",
0990 "G4 10.4 FTFP_BERT_EMM",
0991 "G4 10.2.p02 FTFP_BERT_EMM 10.0.pre3",
0992 "G4 10.4 FTFP_BERT_EMM 10.0.pre3",
0993 "G4 10.4 FTFP_BERT_EMM VecGeom 10.0.pre3",
0994 "G4 10.4 FTFP_BERT_EMM VecGeom+CLHEP 10.0.pre3",
0995 "G4 10.4 FTFP_BERT_EMM CLHEP",
0996 "G4 10.4 FTFP_BERT_EMM VecGeom+CLHEP",
0997 "G4 10.4.ref01 FTFP_BERT_EMM",
0998 "G4 10.4.ref02 FTFP_BERT_EMM",
0999 "G4 10.5.0.beta FTFP_BERT_EMM",
1000 "G4 10.4.ref07 FTFP_BERT_EMM",
1001 "G4 10.4.ref08 FTFP_BERT_EMM",
1002 "G4 10.4.ref09 FTFP_BERT_EMM",
1003 "10.5.cand01 FTFP_BERT_EMM",
1004 "10.4.ref00 FTFP_BERT_EMM",
1005 "10.4.p03 FTFP_BERT_EMM",
1006 "10.5.ref00 FTFP_BERT_EMM",
1007 "10.5.ref01 FTFP_BERT_EMM",
1008 "10.5.ref02 FTFP_BERT_EMM",
1009 "10.5.ref03 FTFP_BERT_EMM",
1010 "10.5.ref04 FTFP_BERT_EMM",
1011 "10.5.ref05 FTFP_BERT_EMM",
1012 "10.5.ref06 FTFP_BERT_EMM"
1013 };
1014 std::string partsF[6] = {"pi-","pi+","k-","k+","pro+","pro-"};
1015 std::string partsM[6] = {"pim","pip","km","kp","prop","prom"};
1016 std::string partsN[6] = {"#pi^{-}","#pi^{+}","K^{-}","K^{+}","proton","antiproton"};
1017 int iens[16] = {2,3,4,5,6,7,8,9,20,30,50,100,150,200,300,350};
1018 int types[16] = {0,0,0,0,0,0,0,0, 1, 1, 1, 1, 1, 2, 2, 2};
1019 int colors[nmodels]= { 2, 7, 6, 4, 9, 8,40, 7, 6, 9,46,48,30, 2, 6,
1020 2, 7, 4, 2, 6, 4, 1, 7, 6, 7, 9, 8, 6, 2, 9,
1021 1, 7, 7, 4, 7, 4};
1022 int mtype[nmodels] = {21,22,23,24,25,26,27,22,23,25,29,33,42,21,21,
1023 22,23,24,21,22,23,24,21,22,23,33,26,22,21,23,
1024 26,21,21,26,21,26};
1025 int colorD(1), mtypeD(20);
1026 std::string titlty[2] = {"All events", "MIP in ECAL"};
1027
1028 if (debug_) {
1029 std::cout << "plotDataMC " << ipar << ", " << ien << ", " << models.size()
1030 << " Models:";
1031 for (unsigned int k=0; k<models.size(); ++k)
1032 std::cout << " " << models[k] << ",";
1033 std::cout << " Type... " << type << ", " << rebin << ", " << irtype << ", "
1034 << prefix << ", " << approve << ", " << xmin0 << ", " << xmax0
1035 << ", " << rescale << std::endl;
1036 }
1037 TCanvas* pad(0);
1038 gStyle->SetCanvasBorderMode(0); gStyle->SetCanvasColor(kWhite);
1039 gStyle->SetPadColor(kWhite); gStyle->SetFillColor(kWhite);
1040 gStyle->SetOptTitle(0); gStyle->SetOptFit(10);
1041 if (stat) gStyle->SetOptStat(1110);
1042 else gStyle->SetOptStat(0);
1043 if (type != 2) type = 1;
1044 std::vector<int> icol;
1045 std::vector<TH1D*> hists;
1046 if (irtype < 0 || irtype > 3) irtype = 1;
1047
1048
1049 char infile[120], title[100], name[120];
1050 double xmin(-5.0), xmax(500.0), ymax(0);
1051 int nbin(0), nmod(0);
1052 for (unsigned int k=0; k<models.size(); ++k) {
1053 if (models[k] <= nmodels) {
1054 int i = models[k];
1055 sprintf (infile,"%s%d/%s%d.root", prefix.c_str(), i, partsM[ipar].c_str(),
1056 iens[ien]);
1057 TFile *file = new TFile(infile);
1058 if (debug_)
1059 std::cout << "File " << i << " " << infile << " " << file << std::endl;
1060 if (file) {
1061 sprintf (name,"EN%d%s%d",type,partsF[ipar].c_str(),i);
1062 TH1D* h1 = (TH1D*)file->FindObjectAny(name);
1063 if (debug_)
1064 std::cout << "Hist " << i << " " << name << " " << h1 << std::endl;
1065 if (h1) {
1066 nmod++;
1067 if (nbin == 0) {
1068 nbin = h1->GetNbinsX();
1069 xmin = h1->GetBinLowEdge(1);
1070 xmax = h1->GetBinLowEdge(nbin) + h1->GetBinWidth(nbin);
1071 }
1072 }
1073 file->Close();
1074 }
1075 }
1076 }
1077 if (xmax0 > 0) {
1078 nbin = (int)((xmax0-xmin0)/((xmax-xmin)*rebin));
1079 xmax = xmax0;
1080 xmin = xmin0;
1081 } else {
1082 nbin /= rebin;
1083 }
1084
1085
1086 TH1D *hist(0);
1087 sprintf (infile, "TB06/%s%d.txt", partsF[ipar].c_str(), iens[ien]);
1088 sprintf (title, "%d GeV %s", iens[ien], partsN[ipar].c_str());
1089 sprintf (name, "Data%d%d%s%d", type, irtype, partsF[ipar].c_str(), iens[ien]);
1090 double scalef = rescale ? GetScaleFactor(ipar, ien) : 1.0;
1091 std::ifstream fInput(infile);
1092 if (!fInput.good()) {
1093 std::cout << "Cannot open file " << infile << std::endl;
1094 } else {
1095 hist = new TH1D(name, title, nbin, xmin, xmax);
1096 hist->Sumw2();
1097 hist->GetXaxis()->SetTitle("Energy (GeV)");
1098 hist->GetYaxis()->SetTitle("Events");
1099 hist->GetYaxis()->SetTitleOffset(1.3);
1100 hist->SetMarkerColor(colorD);
1101 hist->SetMarkerStyle(mtypeD);
1102 hist->SetMarkerSize(1.2);
1103 hist->SetLineColor(colorD);
1104 hist->SetLineWidth(2);
1105 char buffer [1024];
1106 fInput.getline(buffer, 1024);
1107 double eEB, eHB, eHO;
1108 while (1) {
1109 fInput >> eEB >> eHB >> eHO;
1110 if (!fInput.good()) break;
1111 eEB *= scalef; eHB *= scalef;
1112 double eTot = (eEB+eHB);
1113 if (type == 1) hist->Fill(eTot);
1114 else if (eEB < 1.2) hist->Fill(eTot);
1115 }
1116 fInput.close();
1117 for (int k=1; k<=nbin; ++k) {
1118 if (hist->GetBinContent(k)+hist->GetBinError(k) > ymax) {
1119 ymax = hist->GetBinContent(k)+hist->GetBinError(k);
1120 }
1121 }
1122 hists.push_back(hist);
1123 icol.push_back(colorD);
1124 }
1125
1126
1127 if (hist) {
1128 double total(0);
1129 double legsize(0.04);
1130 for (int k=1; k<=nbin; ++k) total += hist->GetBinContent(k);
1131 double yext(0);
1132 if (irtype == 1) {
1133 yext = 500;
1134 sprintf (name,"EN%d%s%dH",type,partsF[ipar].c_str(),iens[ien]);
1135 } else if (irtype == 2) {
1136 yext = 300;
1137 sprintf (name,"EN%d%s%dR",type,partsF[ipar].c_str(),iens[ien]);
1138 } else {
1139 yext = 700;
1140 sprintf (name,"EN%d%s%d",type,partsF[ipar].c_str(),iens[ien]);
1141 }
1142 pad = new TCanvas(name, name, 700, yext);
1143 double dy = 0.08;
1144 double xh(0.89), yh(0.89);
1145 double yh1 = yh-dy*(nmod+1)- 0.02;
1146 TLegend *legend(0);
1147 if (!stat) {
1148 if (approve) legend = new TLegend(xh-0.5, yh-legsize*(nmod+1)-0.01, xh, yh-0.01);
1149 else legend = new TLegend(xh-0.35, yh-legsize*(nmod+1)-0.01, xh, yh-0.01);
1150 } else if (types[ien] == 2) {
1151 legend = new TLegend(xh-0.35, yh-legsize*(nmod+1)-0.01, xh, yh-0.01);
1152 xh = 0.4;
1153 } else if (types[ien] == 1) {
1154 legend = new TLegend(0.11, yh-legsize*(nmod+1), 0.45, yh-0.01);
1155 } else {
1156 legend = new TLegend(xh-0.35, yh1-legsize*(nmod+1), xh, yh1);
1157 }
1158 legend->SetFillColor(kWhite); legend->SetBorderSize(0);
1159 legend->SetMargin(0.2);
1160
1161 sprintf (name,"ENStack1%d%s%d",type,partsF[ipar].c_str(),iens[ien]);
1162 THStack *Hs = new THStack(name,"");
1163 Hs->Add(hist,"pe sames");
1164 sprintf (title, "%d GeV %s (%s)", iens[ien], partsN[ipar].c_str(), titlty[type-1].c_str());
1165 legend->AddEntry(hist,title,"lp");
1166
1167 for (unsigned int k=0; k<models.size(); ++k) {
1168 if (models[k] <= nmodels) {
1169 int i = models[k];
1170 sprintf (infile,"%s%d/%s%d.root",prefix.c_str(),i,partsM[ipar].c_str(),iens[ien]);
1171 TFile *file = new TFile(infile);
1172 if (file) {
1173 sprintf (name,"EN%d%s%d",type,partsF[ipar].c_str(),i);
1174 TH1D* h1 = (TH1D*)file->FindObjectAny(name);
1175 if (h1) {
1176 sprintf (name,"EN%d%s%d1",type,partsF[ipar].c_str(),i);
1177 TH1D *h2 = new TH1D(name, "", nbin, xmin, xmax);
1178 h2->Sumw2();
1179 double totm(0);
1180 for (int k=1; k<=h1->GetNbinsX(); ++k) totm += h1->GetBinContent(k);
1181 double scale = total/totm;
1182 int ibin = (int)((xmin-h1->GetBinLowEdge(1))/h1->GetBinWidth(1));
1183 for (int k=1; k<=nbin; ++k) {
1184 double cont(0);
1185 for (int k1=0; k1<rebin; ++k1) {
1186 ++ibin;
1187 double cv = h1->GetBinContent(ibin);
1188 cont += scale*cv;
1189 }
1190 h2->SetBinContent(k,cont);
1191 if (cont > ymax) ymax = cont;
1192
1193 }
1194 h2->SetMarkerColor(colors[i]);
1195 h2->SetMarkerStyle(mtype[i]);
1196 h2->SetMarkerSize(1.2);
1197 h2->SetLineColor(colors[i]);
1198 h2->SetLineWidth(2);
1199 Hs->Add(h2,"hist sames");
1200 legend->AddEntry(h2,modelNames[i].c_str(),"lp");
1201 icol.push_back(colors[i]);
1202 hists.push_back(h2);
1203 }
1204 }
1205 }
1206 }
1207
1208 int imax = (ymax > 100) ? (int)(0.01*ymax) : (int)(0.1*ymax);
1209 double ymx = (ymax > 100) ? 100*(imax+2) : 10*(imax+2);
1210 Hs->SetMinimum(0.0); Hs->SetMaximum(ymx);
1211 if (irtype != 2) {
1212 TPad *pad1(pad);
1213 if (irtype != 1) {
1214 sprintf (name,"ENPad1%d%s%d",type,partsF[ipar].c_str(),iens[ien]);
1215 pad1 = new TPad(name,"pad1",0,0.3,1,1);
1216 pad1->SetBottomMargin(0.01);
1217 }
1218 pad1->SetTopMargin(0.10); pad1->SetRightMargin(0.10);
1219 pad1->Draw(); pad1->cd();
1220 Hs->Draw("nostack");
1221 Hs->GetHistogram()->GetYaxis()->SetTitle("Events");
1222 if (irtype == 1) {
1223 Hs->GetHistogram()->GetXaxis()->SetTitle("Energy (GeV)");
1224 Hs->GetHistogram()->GetXaxis()->SetTitleOffset(0.90);
1225 Hs->GetHistogram()->GetYaxis()->SetTitleOffset(1.20);
1226 }
1227 pad1->Update(); pad1->Modified();
1228 if (stat) {
1229 for (unsigned int k=0; k<hists.size(); ++k) {
1230 TPaveStats* st1 = (TPaveStats*)hists[k]->GetListOfFunctions()->FindObject("stats");
1231 if (st1 != NULL) {
1232 st1->SetFillColor(kWhite);
1233 st1->SetLineColor(icol[k]); st1->SetTextColor(icol[k]);
1234 st1->SetY1NDC(yh-dy); st1->SetY2NDC(yh);
1235 st1->SetX1NDC(xh-0.3); st1->SetX2NDC(xh);
1236 yh -= dy;
1237 }
1238 }
1239 }
1240 legend->Draw("same");
1241 if (approve) {
1242 double yht = ((types[ien] == 2) || (!stat)) ? (0.88-legsize*(nmod+1)) :
1243 ((types[ien] == 1) ? (yh1-0.02) : (yh1-legsize*(nmod+1)-0.02));
1244 TPaveText* text = new TPaveText(0.60, yht-0.04, 0.89, yht, "brNDC");
1245 text->AddText("CMS Preliminary");
1246 text->Draw("same");
1247
1248 TPaveText* txt2 = new TPaveText(0.11, 0.85, 0.35, 0.89, "brNDC");
1249 txt2->AddText("2006 Test Beam Data");
1250 txt2->Draw("same");
1251 }
1252 }
1253
1254 pad->cd();
1255 if (irtype != 1) {
1256 sprintf (name,"ENStack2%d%s%d",type,partsF[ipar].c_str(),iens[ien]);
1257 THStack *Hsr = new THStack(name,"");
1258 Hsr->SetMinimum(0.0); Hsr->SetMaximum(3.99);
1259 TPad *pad2(pad);
1260 if (irtype != 2) {
1261 sprintf (name,"ENPad2%d%s%d",type,partsF[ipar].c_str(),iens[ien]);
1262 pad2 = new TPad(name,"pad2",0,0,1,0.3);
1263 pad2->SetTopMargin(0.005);
1264 }
1265 pad2->SetBottomMargin(0.20); pad2->SetRightMargin(0.10);
1266 pad2->Draw(); pad2->cd();
1267 double xh2 = (types[ien] == 2) ? 0.90 : xh;
1268 double yh2 = (irtype == 2) ? 0.88 : 0.98;
1269 double xh1 = (approve) ? (xh2-0.40) : ((irtype == 2) ? (xh2-0.60) : (xh2-0.30));
1270 double yh1 = (irtype == 2) ? (yh2-0.05*nmod) : (yh2-0.10*nmod);
1271 TLegend *legend1 = new TLegend(xh1, yh1, xh2, yh2);
1272 legend1->SetFillColor(kWhite); legend1->SetBorderSize(0);
1273 legend1->SetMargin(0.2);
1274 TH1D *h_ref = (TH1D*)hists[0];
1275 int imx1 = (ymax > 100) ? 10 : 1;
1276 int imx2 = (ymax > 100) ? 100 : 5;
1277 for (unsigned int i=1; i<hists.size(); i++) {
1278 sprintf (name,"ENRatio%d%s%d",i,partsF[ipar].c_str(),iens[ien]);
1279 TH1D *ratio = new TH1D(name, "Ratio", nbin, xmin, xmax);
1280 double sumNum(0), sumDen(0);
1281 for (int k=1; k<=nbin; ++k) {
1282 if (h_ref->GetBinContent(k) > imx1 && hists[i]->GetBinContent(k) > imx1) {
1283 double rat = hists[i]->GetBinContent(k)/h_ref->GetBinContent(k);
1284 double drt = rat*(h_ref->GetBinError(k)/h_ref->GetBinContent(k));
1285 ratio->SetBinContent(k,rat); ratio->SetBinError(k,drt);
1286 if (h_ref->GetBinContent(k) > imx2) {
1287 if (rat > 1.) {
1288 rat = 1./rat; drt *= (rat*rat);
1289 }
1290 sumNum += (fabs(1.0-rat)/(drt*drt));
1291 sumDen += (1.0/(drt*drt));
1292 }
1293 }
1294 }
1295 double mean = (sumDen>0) ? (sumNum/sumDen) : 0;
1296 double error = (sumDen>0) ? 1.0/sqrt(sumDen) : 0;
1297 std::cout << "Model " << i << " Delta " << mean << " +- " << error
1298 << std::endl;
1299 if (approve) {
1300 sprintf (name, "%s",modelNames[i-1].c_str());
1301 } else if (irtype == 2) {
1302 sprintf (name, "#delta = %6.3f #pm %6.3f %s",mean,error,modelNames[i-1].c_str());
1303 } else {
1304 sprintf (name, "#delta = %6.3f #pm %6.3f",mean,error);
1305 }
1306 legend1->AddEntry(ratio,name,"lp");
1307 ratio->SetStats(0);
1308 ratio->SetLineColor(icol[i]);
1309 ratio->SetLineWidth(2);
1310 ratio->SetMarkerColor(icol[i]);
1311 ratio->SetMarkerStyle(mtype[i]);
1312 ratio->SetMarkerSize(1.2);
1313 ratio->SetLineWidth(2);
1314 Hsr->Add(ratio,"pe same");
1315 }
1316 Hsr->Draw("nostack");
1317 pad2->Update();
1318 Hsr->GetHistogram()->SetStats(0);
1319 Hsr->GetHistogram()->GetYaxis()->SetTitle("MC/Data");
1320 Hsr->GetHistogram()->GetXaxis()->SetTitle("Energy (GeV)");
1321 if (irtype == 2) {
1322 Hsr->GetHistogram()->GetXaxis()->SetTitleSize(0.06);
1323 Hsr->GetHistogram()->GetYaxis()->SetTitleSize(0.06);
1324 Hsr->GetHistogram()->GetXaxis()->SetTitleOffset(1.00);
1325 Hsr->GetHistogram()->GetYaxis()->SetTitleOffset(0.60);
1326 Hsr->GetHistogram()->GetXaxis()->SetLabelSize(0.07);
1327 Hsr->GetHistogram()->GetYaxis()->SetLabelSize(0.07);
1328 } else {
1329 Hsr->GetHistogram()->GetXaxis()->SetTitleSize(0.10);
1330 Hsr->GetHistogram()->GetYaxis()->SetTitleSize(0.10);
1331 Hsr->GetHistogram()->GetXaxis()->SetTitleOffset(0.90);
1332 Hsr->GetHistogram()->GetYaxis()->SetTitleOffset(0.35);
1333 Hsr->GetHistogram()->GetXaxis()->SetLabelSize(0.10);
1334 Hsr->GetHistogram()->GetYaxis()->SetLabelSize(0.10);
1335 }
1336 TLine *line = new TLine(xmin,1.0,xmax,1.0);
1337 line->SetLineStyle(2); line->SetLineWidth(2);
1338 line->SetLineColor(kBlack); line->Draw();
1339 if (approve) {
1340 double dyt = (irtype == 3) ? 0.08 : 0.08;
1341 TPaveText* text = new TPaveText(0.11,yh2-dyt,xh2-0.29,yh2,"brNDC");
1342 sprintf (name, "2006 Test Beam Data (%d GeV %s %s)", iens[ien],
1343 partsN[ipar].c_str(), titlty[type-1].c_str());
1344 text->AddText(name);
1345 text->Draw("same");
1346 TPaveText* txt2 = new TPaveText(xh2-0.25, yh2-dyt, xh2, yh2, "brNDC");
1347 txt2->AddText("CMS Preliminary");
1348 txt2->Draw("same");
1349 } else {
1350 legend1->Draw("same");
1351 }
1352 pad2->Update();
1353 }
1354 pad->Update();
1355 }
1356 return pad;
1357 }
1358
1359 void plotDataMCDist(int ipar, int ien, std::vector<int> models, int rebin=2,
1360 std::string prefix="model", bool approve=true,
1361 bool stat=true, double xmin0=-1, double xmax0=-1,
1362 int save=0) {
1363
1364 for (int type=1; type<3; ++type) {
1365 char filename[100];
1366 TCanvas* c1 = plotDataMC(ipar, ien, models, type, rebin, 1, prefix, approve, stat, xmin0, xmax0, true);
1367 if (save != 0) {
1368 if (save < 0) sprintf (filename, "%s.jpg", c1->GetName());
1369 else sprintf (filename, "%s.pdf", c1->GetName());
1370 c1->Print(filename);
1371 }
1372 TCanvas* c2 = plotDataMC(ipar, ien, models, type, rebin, 2, prefix, approve, stat, xmin0, xmax0, true);
1373 if (save != 0) {
1374 if (save < 0) sprintf (filename, "%s.jpg", c2->GetName());
1375 else sprintf (filename, "%s.pdf", c2->GetName());
1376 c2->Print(filename);
1377 }
1378 }
1379 }
1380
1381 void plotDataMCDist(std::string prefix, int type, int irtype,
1382 std::vector<int> models, int rebin=2, bool approve=true,
1383 bool stat=true, double xmin0=-1, double xmax0=-1,
1384 int save=0) {
1385 int ienMin[6] = {0,0,2,3,0,0};
1386 int ienMax[6] = {8,8,6,6,8,8};
1387
1388 char filename[100];
1389 for (int ipar=0; ipar<6; ++ipar) {
1390 for (int ien=ienMin[ipar]; ien<ienMax[ipar]; ++ien) {
1391 TCanvas* c1 = plotDataMC(ipar, ien, models, type, rebin, irtype, prefix,
1392 approve, stat, xmin0, xmax0, true);
1393 if (save != 0) {
1394 if (save < 0) sprintf (filename, "%s.jpg", c1->GetName());
1395 else sprintf (filename, "%s.pdf", c1->GetName());
1396 c1->Print(filename);
1397 }
1398 }
1399 }
1400 }
1401
1402 TCanvas* plotDataMC(int ipar, std::vector<int> models, bool ratio=false,
1403 std::string dirName="RespAll", bool approve=false) {
1404
1405 static const int nmodels=37;
1406 std::string names[nmodels] = {"Test Beam Data",
1407 "G4 10.0.p02 QGSP_FTFP_BERT_EML",
1408 "G4 10.0.p02 FTFP_BERT_EML",
1409 "G4 10.2.p02 QGSP_FTFP_BERT_EMM",
1410 "G4 10.2.p02 FTFP_BERT_EMM",
1411 "G4 10.2.p02 FTFP_BERT_ATL_EMM",
1412 "G4 10.4.beta FTFP_BERT_EMM",
1413 "G4 10.3.ref08 FTFP_BERT_EMM",
1414 "G4 10.3.ref09 FTFP_BERT_EMM",
1415 "G4 10.3.ref10 FTFP_BERT_EMM",
1416 "G4 10.3.ref11 FTFP_BERT_EMM",
1417 "G4 10.3.p03 FTFP_BERT_EMM",
1418 "G4 10.4.cand01 FTFP_BERT_EMM",
1419 "G4 10.4.cand02 FTFP_BERT_EMM",
1420 "G4 10.4 FTFP_BERT_EMM",
1421 "G4 10.2.p02 FTFP_BERT_EMM 10.0.pre3",
1422 "G4 10.4 FTFP_BERT_EMM 10.0.pre3",
1423 "G4 10.4 FTFP_BERT_EMM VecGeom 10.0.pre3",
1424 "G4 10.4 FTFP_BERT_EMM VecGeom+CLHEP 10.0.pre3",
1425 "G4 10.4 FTFP_BERT_EMM CLHEP",
1426 "G4 10.4 FTFP_BERT_EMM VecGeom+CLHEP",
1427 "G4 10.4.ref01 FTFP_BERT_EMM",
1428 "G4 10.4.ref02 FTFP_BERT_EMM",
1429 "G4 10.5.0.beta FTFP_BERT_EMM",
1430 "G4 10.4.ref07 FTFP_BERT_EMM",
1431 "G4 10.4.ref08 FTFP_BERT_EMM",
1432 "G4 10.4.ref09 FTFP_BERT_EMM",
1433 "G4 10.5.cand01 FTFP_BERT_EMM",
1434 "G4 10.4.ref00 FTFP_BERT_EMM",
1435 "G4 10.4.p03 FTFP_BERT_EMM",
1436 "G4 10.5.ref00 FTFP_BERT_EMM",
1437 "G4 10.5.ref01 FTFP_BERT_EMM",
1438 "G4 10.5.ref02 FTFP_BERT_EMM",
1439 "G4 10.5.ref03 FTFP_BERT_EMM",
1440 "G4 10.5.ref04 FTFP_BERT_EMM",
1441 "G4 10.5.ref05 FTFP_BERT_EMM",
1442 "G4 10.5.ref06 FTFP_BERT_EMM"
1443 };
1444 std::string partsM[6] = {"pim","pip","km","kp","prop","prom"};
1445 std::string partsN[6] = {"#pi^{-}","#pi^{+}","K^{-}","K^{+}","proton","antiproton"};
1446 double xmax[6] = {400.0,30.0,15.0,15.0,400.0,15.0};
1447 double ylow[6] = {0.4,0.4,0.2,0.2,0.2,0.6};
1448 double ylowr[6] = {0.9,0.9,0.7,0.5,0.9,0.9};
1449 double ymaxr[6] = {1.2,1.2,1.2,1.4,1.2,1.2};
1450 int colors[nmodels+1]= { 1, 2, 7, 6, 4, 9, 8,40, 7, 6, 9,46,48,30, 2,
1451 6, 2, 7, 4, 2, 6, 4, 1, 7, 6, 7, 9, 8, 2, 9,
1452 6, 7,30,30, 7,30, 7};
1453 int mtype[nmodels+1] = {20,21,22,23,24,25,26,27,22,23,25,29,33,42,21,
1454 21,22,23,24,21,22,23,24,21,22,23,33,26,22,21,
1455 23,33,21,21,33,21,33};
1456
1457 TCanvas* canvas(0);
1458 char cname[100];
1459 int nm(0);
1460 for (unsigned int i=0; i<models.size(); ++i) {
1461 if (models[i] < nmodels) ++nm;
1462 }
1463 double ymax = 0.948;
1464 double ymin = ymax-0.04*nm;
1465 TLegend* legend(0);
1466 if (ratio) {
1467 legend = new TLegend(0.175, ymin, 0.970, ymax);
1468 } else {
1469 legend = new TLegend(0.175, ymin, 0.973, ymax);
1470 }
1471 legend->SetBorderSize(0); legend->SetFillColor(kWhite);
1472 legend->SetMargin(0.2);
1473 std::vector<TGraphAsymmErrors*> graphs;
1474 const int NPT=20;
1475 double mom[NPT], dmom[NPT], momd[NPT], meand[NPT], dmeand[NPT], mean[NPT], dmean[NPT];
1476
1477
1478 char infile[100];
1479 if (dirName == "") {
1480 sprintf(infile,"%s.txt", partsM[ipar].c_str());
1481 } else {
1482 sprintf(infile,"%s/%s.txt", dirName.c_str(), partsM[ipar].c_str());
1483 }
1484 double pb, resp, errsp;
1485 bool ok(false);
1486 int nptd(0);
1487
1488 std::ifstream fInput1(infile);
1489 if (!fInput1.good()) {
1490 std::cout << "Cannot open file " << infile << std::endl;
1491 } else {
1492 ok = true;
1493 while (1) {
1494 fInput1 >> pb >> resp >> errsp;
1495 if (!fInput1.good()) break;
1496 momd[nptd] = pb; dmom[nptd] = 0; meand[nptd] = resp; dmeand[nptd] = errsp; ++nptd;
1497 }
1498 fInput1.close();
1499 ok = (nptd > 0);
1500 if (debug_) {
1501 std::cout << "Reads " << nptd << " points from " << infile << std::endl;
1502 for (int k=0; k<nptd; ++k)
1503 std::cout << "[" << k << "] " << momd[k] << " +- " << dmom[k] << " "
1504 << meand[k] << " +- " << dmeand[k] << std::endl;
1505 }
1506 }
1507 if (ok) {
1508 if (!ratio) {
1509 TGraphAsymmErrors *graph = new TGraphAsymmErrors(nptd,momd,meand,dmom,dmom,dmeand,dmeand);
1510 graph->SetMarkerStyle(mtype[0]);
1511 graph->SetMarkerColor(colors[0]);
1512 graph->SetMarkerSize(1.4);
1513 graph->SetLineColor(colors[0]);
1514 graph->SetLineWidth(2);
1515 graphs.push_back(graph);
1516 sprintf(cname, "2006 %s (%s)", names[0].c_str(), partsN[ipar].c_str());
1517 legend->AddEntry(graph, cname, "lp");
1518 }
1519 for (unsigned int k=0; k<models.size(); ++k) {
1520 int npt(0);
1521 double sumNum(0), sumDen(0);
1522 if (models[k] < nmodels) {
1523 int i = models[k];
1524 if (dirName == "") {
1525 sprintf(infile,"%sm%d.txt",partsM[ipar].c_str(),i);
1526 } else {
1527 sprintf(infile,"%s/%sm%d.txt",dirName.c_str(),partsM[ipar].c_str(),i);
1528 }
1529 std::ifstream fInput2(infile);
1530 if (!fInput2.good()) {
1531 std::cout << "Cannot open file " << infile << std::endl;
1532 } else {
1533 while (1) {
1534 fInput2 >> pb >> resp;
1535 if (!fInput2.good()) break;
1536 if (ratio) {
1537 for (int k=0; k<nptd; ++k) {
1538 if (std::abs(momd[k]-pb) < 0.1) {
1539 double rat = resp/meand[k]; double drt = dmeand[k]/meand[k];
1540 mom[npt] = pb; dmom[npt] = 0; mean[npt] = rat; dmean[npt] = drt;
1541 if (rat > 1.) {
1542 rat = 1./rat; drt *= (rat*rat);
1543 }
1544 sumNum += (fabs(1.0-rat)/(drt*drt));
1545 sumDen += (1.0/(drt*drt));
1546 ++npt; break;
1547 }
1548 }
1549 } else {
1550 mom[npt] = pb; dmom[npt] = 0; mean[npt] = resp; dmean[npt] = 0.001; ++npt;
1551 }
1552 }
1553 }
1554 fInput2.close();
1555 if (npt > 0) {
1556 if (debug_) {
1557 std::cout << "Reads " << npt << " points from " << infile
1558 << std::endl;
1559 for (int k=0; k<npt; ++k)
1560 std::cout << "[" << k << "] " << mom[k] << " +- " << dmom[k]
1561 << " " << mean[k] << " +- " << dmean[k] << std::endl;
1562 }
1563 TGraphAsymmErrors *graph = new TGraphAsymmErrors(npt,mom,mean,dmom,dmom,dmean,dmean);
1564 graph->SetMarkerStyle(mtype[i+1]);
1565 graph->SetMarkerColor(colors[i+1]);
1566 graph->SetMarkerSize(1.2);
1567 graph->SetLineColor(colors[i+1]);
1568 graph->SetLineWidth(2);
1569 graphs.push_back(graph);
1570 if (ratio) {
1571 double rat = (sumDen>0) ? (sumNum/sumDen) : 0;
1572 double err = (sumDen>0) ? sqrt(1./sumDen) : 0;
1573 std::cout << "Particle " << partsM[ipar] << " Model "
1574 << names[i+1] << " ratio " << rat << " +- "
1575 << err << std::endl;
1576 if (approve) sprintf (cname, "%s", names[i+1].c_str());
1577 else sprintf (cname, "(#delta = %5.3f) %s", rat, names[i+1].c_str());
1578 } else {
1579 sprintf (cname, "%s", names[i+1].c_str());
1580 }
1581 legend->AddEntry(graph, cname, "lp");
1582 }
1583 }
1584 }
1585
1586 gStyle->SetCanvasBorderMode(0); gStyle->SetCanvasColor(kWhite);
1587 gStyle->SetPadColor(kWhite); gStyle->SetFillColor(kWhite);
1588 gStyle->SetOptTitle(kFALSE); gStyle->SetPadBorderMode(0);
1589 gStyle->SetCanvasBorderMode(0); gStyle->SetOptStat(0);
1590 if (ratio) {
1591 sprintf(cname, "c_%sRespR", partsM[ipar].c_str());
1592 canvas = new TCanvas(cname, cname, 500, 300);
1593 } else {
1594 sprintf(cname, "c_%sResp", partsM[ipar].c_str());
1595 canvas = new TCanvas(cname, cname, 500, 500);
1596 }
1597 canvas->SetTopMargin(0.05); canvas->SetLogx();
1598 canvas->SetLeftMargin(0.15); canvas->SetRightMargin(0.025);
1599 canvas->SetBottomMargin(0.14);
1600 TH1F *vFrame = canvas->DrawFrame(1.0, 0.01, xmax[ipar], 2.0);
1601 vFrame->GetXaxis()->SetRangeUser(1.0,xmax[ipar]);
1602 if (ratio) {
1603 if (approve) vFrame->GetYaxis()->SetRangeUser(ylowr[ipar],ymaxr[ipar]);
1604 else vFrame->GetYaxis()->SetRangeUser(ylowr[ipar],1.4);
1605 } else {
1606 vFrame->GetYaxis()->SetRangeUser(ylow[ipar],1.0);
1607 }
1608 if (ratio) {
1609 vFrame->GetXaxis()->SetLabelSize(0.06);
1610 vFrame->GetYaxis()->SetLabelSize(0.06);
1611 vFrame->GetXaxis()->SetTitleSize(0.06);
1612 vFrame->GetYaxis()->SetTitleSize(0.06);
1613 vFrame->GetXaxis()->SetTitleOffset(0.9);
1614 vFrame->GetYaxis()->SetTitleOffset(1.0);
1615 } else {
1616 vFrame->GetXaxis()->SetLabelSize(0.04);
1617 vFrame->GetYaxis()->SetLabelSize(0.04);
1618 vFrame->GetXaxis()->SetTitleSize(0.04);
1619 vFrame->GetYaxis()->SetTitleSize(0.04);
1620 vFrame->GetXaxis()->SetTitleOffset(1.2);
1621 vFrame->GetYaxis()->SetTitleOffset(1.6);
1622 }
1623 vFrame->GetXaxis()->SetLabelOffset(0.0);
1624 vFrame->GetXaxis()->SetTitle("p_{Beam} (GeV/c)");
1625 if (ratio) {
1626 vFrame->GetYaxis()->SetTitle("MC/Data (Response)");
1627 } else {
1628 if (approve) vFrame->GetYaxis()->SetTitle("Mean of E_{Measured}/p_{Beam}");
1629 else vFrame->GetYaxis()->SetTitle("<E_{Measured}>/p_{Beam}");
1630 }
1631 for (unsigned int ii=0; ii<graphs.size(); ++ii) {
1632 if (ii == 0 && !ratio) graphs[ii]->Draw("P");
1633 else graphs[ii]->Draw("LP");
1634 }
1635 if ((!approve) || (!ratio)) legend->Draw();
1636 double yvl = (approve && ratio) ? ymax : ymin;
1637 if ((!approve) || ratio) {
1638 TPaveText* text = new TPaveText(0.16,yvl-0.08, 0.70,yvl-0.01,"brNDC");
1639 sprintf(cname, "2006 %s (%s)", names[0].c_str(), partsN[ipar].c_str());
1640 text->AddText(cname);
1641 text->Draw("same");
1642 }
1643 TPaveText* txt2 = new TPaveText(0.70, yvl-0.08, 0.948, yvl-0.01, "brNDC");
1644 sprintf (cname, "CMS Preliminary");
1645 txt2->AddText(cname);
1646 txt2->Draw("same");
1647 if (ratio) {
1648 TLine *line = new TLine(1.0,1.0,xmax[ipar],1.0);
1649 line->SetLineStyle(2); line->SetLineWidth(2);
1650 line->SetLineColor(kBlack); line->Draw();
1651 }
1652 }
1653 return canvas;
1654
1655 }
1656
1657 void plotDataMCResp(std::vector<int> models, std::string dirName="RespAll",
1658 bool approve=true, int save=0) {
1659
1660 for (int k=0; k<6; ++k) {
1661 char filename[100];
1662 TCanvas* c1 = plotDataMC(k, models, false, dirName, approve);
1663 if (save != 0) {
1664 if (save < 0) sprintf (filename, "%s.jpg", c1->GetName());
1665 else sprintf (filename, "%s.pdf", c1->GetName());
1666 c1->Print(filename);
1667 }
1668 TCanvas* c2 = plotDataMC(k, models, true, dirName, approve);
1669 if (save != 0) {
1670 if (save < 0) sprintf (filename, "%s.jpg", c2->GetName());
1671 else sprintf (filename, "%s.pdf", c2->GetName());
1672 c2->Print(filename);
1673 }
1674 }
1675 }
1676
1677 void convertel(std::string indir="nmodel0", std::string outdir="model0", int md=0) {
1678
1679 TB06Analysis p01((indir+"/el50e.root"), (outdir+"/el50e.root"), 6,10, md, 1.0, 1.0);
1680 p01.Loop();
1681 TB06Analysis p02((indir+"/el50h.root"), (outdir+"/el50h.root"), 6,10, md, 1.0, 1.0);
1682 p02.Loop();
1683 }
1684
1685 void convert(std::string indir="nmodel0", std::string outdir="model0", int md=0) {
1686
1687 TB06Analysis p01((indir+"/km4.root"), (outdir+"/km4.root"), 2, 3, md, 1.0, 1.0);
1688 p01.Loop();
1689 TB06Analysis p02((indir+"/km5.root"), (outdir+"/km5.root"), 2, 4, md, 1.0, 1.0);
1690 p02.Loop();
1691 TB06Analysis p03((indir+"/km6.root"), (outdir+"/km6.root"), 2, 5, md, 1.0, 1.0);
1692 p03.Loop();
1693 TB06Analysis p04((indir+"/km7.root"), (outdir+"/km7.root"), 2, 6, md, 1.0, 1.0);
1694 p04.Loop();
1695 TB06Analysis p05((indir+"/kp5.root"), (outdir+"/kp5.root"), 3, 4, md, 1.0, 1.0);
1696 p05.Loop();
1697 TB06Analysis p06((indir+"/kp6.root"), (outdir+"/kp6.root"), 3, 5, md, 1.0, 1.0);
1698 p06.Loop();
1699 TB06Analysis p07((indir+"/kp7.root"), (outdir+"/kp7.root"), 3, 6, md, 1.0, 1.0);
1700 p07.Loop();
1701 TB06Analysis p08((indir+"/pim2.root"), (outdir+"/pim2.root"), 0, 0, md, 1.0, 1.0);
1702 p08.Loop();
1703 TB06Analysis p09((indir+"/pim3.root"), (outdir+"/pim3.root"), 0, 1, md, 1.0, 1.0);
1704 p09.Loop();
1705 TB06Analysis p10((indir+"/pim4.root"), (outdir+"/pim4.root"), 0, 2, md, 1.0, 1.0);
1706 p10.Loop();
1707 TB06Analysis p11((indir+"/pim5.root"), (outdir+"/pim5.root"), 0, 3, md, 1.0, 1.0);
1708 p11.Loop();
1709 TB06Analysis p12((indir+"/pim6.root"), (outdir+"/pim6.root"), 0, 4, md, 1.0, 1.0);
1710 p12.Loop();
1711 TB06Analysis p13((indir+"/pim7.root"), (outdir+"/pim7.root"), 0, 5, md, 1.0, 1.0);
1712 p13.Loop();
1713 TB06Analysis p14((indir+"/pim8.root"), (outdir+"/pim8.root"), 0, 6, md, 1.0, 1.0);
1714 p14.Loop();
1715 TB06Analysis p15((indir+"/pim9.root"), (outdir+"/pim9.root"), 0, 7, md, 1.0, 1.0);
1716 p15.Loop();
1717 TB06Analysis p16((indir+"/pim20.root"), (outdir+"/pim20.root"), 0, 8, md, 1.0, 1.0);
1718 p16.Loop();
1719 TB06Analysis p17((indir+"/pim30.root"), (outdir+"/pim30.root"), 0, 9, md, 1.0, 1.0);
1720 p17.Loop();
1721 TB06Analysis p18((indir+"/pim50.root"), (outdir+"/pim50.root"), 0,10, md, 1.0, 1.0);
1722 p18.Loop();
1723 TB06Analysis p19((indir+"/pim100.root"), (outdir+"/pim100.root"), 0,11, md, 1.0, 1.0);
1724 p19.Loop();
1725 TB06Analysis p20((indir+"/pim150.root"), (outdir+"/pim150.root"), 0,12, md, 1.0, 1.0);
1726 p20.Loop();
1727 TB06Analysis p21((indir+"/pim200.root"), (outdir+"/pim200.root"), 0,13, md, 1.0, 1.0);
1728 p21.Loop();
1729 TB06Analysis p22((indir+"/pim300.root"), (outdir+"/pim300.root"), 0,14, md, 1.0, 1.0);
1730 p22.Loop();
1731 TB06Analysis p23((indir+"/pip2.root"), (outdir+"/pip2.root"), 1, 0, md, 1.0, 1.0);
1732 p23.Loop();
1733 TB06Analysis p24((indir+"/pip3.root"), (outdir+"/pip3.root"), 1, 1, md, 1.0, 1.0);
1734 p24.Loop();
1735 TB06Analysis p25((indir+"/pip4.root"), (outdir+"/pip4.root"), 1, 2, md, 1.0, 1.0);
1736 p25.Loop();
1737 TB06Analysis p26((indir+"/pip5.root"), (outdir+"/pip5.root"), 1, 3, md, 1.0, 1.0);
1738 p26.Loop();
1739 TB06Analysis p27((indir+"/pip6.root"), (outdir+"/pip6.root"), 1, 4, md, 1.0, 1.0);
1740 p27.Loop();
1741 TB06Analysis p28((indir+"/pip7.root"), (outdir+"/pip7.root"), 1, 5, md, 1.0, 1.0);
1742 p28.Loop();
1743 TB06Analysis p29((indir+"/pip8.root"), (outdir+"/pip8.root"), 1, 6, md, 1.0, 1.0);
1744 p29.Loop();
1745 TB06Analysis p30((indir+"/pip9.root"), (outdir+"/pip9.root"), 1, 7, md, 1.0, 1.0);
1746 p30.Loop();
1747 TB06Analysis p31((indir+"/prom2.root"), (outdir+"/prom2.root"), 5, 0, md, 1.0, 1.0);
1748 p31.Loop();
1749 TB06Analysis p32((indir+"/prom3.root"), (outdir+"/prom3.root"), 5, 1, md, 1.0, 1.0);
1750 p32.Loop();
1751 TB06Analysis p33((indir+"/prom4.root"), (outdir+"/prom4.root"), 5, 2, md, 1.0, 1.0);
1752 p33.Loop();
1753 TB06Analysis p34((indir+"/prom5.root"), (outdir+"/prom5.root"), 5, 3, md, 1.0, 1.0);
1754 p34.Loop();
1755 TB06Analysis p35((indir+"/prom6.root"), (outdir+"/prom6.root"), 5, 4, md, 1.0, 1.0);
1756 p35.Loop();
1757 TB06Analysis p36((indir+"/prom7.root"), (outdir+"/prom7.root"), 5, 5, md, 1.0, 1.0);
1758 p36.Loop();
1759 TB06Analysis p37((indir+"/prom8.root"), (outdir+"/prom8.root"), 5, 6, md, 1.0, 1.0);
1760 p37.Loop();
1761 TB06Analysis p38((indir+"/prom9.root"), (outdir+"/prom9.root"), 5, 7, md, 1.0, 1.0);
1762 p38.Loop();
1763 TB06Analysis p39((indir+"/prop2.root"), (outdir+"/prop2.root"), 4, 0, md, 1.0, 1.0);
1764 p39.Loop();
1765 TB06Analysis p40((indir+"/prop3.root"), (outdir+"/prop3.root"), 4, 1, md, 1.0, 1.0);
1766 p40.Loop();
1767 TB06Analysis p41((indir+"/prop4.root"), (outdir+"/prop4.root"), 4, 2, md, 1.0, 1.0);
1768 p41.Loop();
1769 TB06Analysis p42((indir+"/prop5.root"), (outdir+"/prop5.root"), 4, 3, md, 1.0, 1.0);
1770 p42.Loop();
1771 TB06Analysis p43((indir+"/prop6.root"), (outdir+"/prop6.root"), 4, 4, md, 1.0, 1.0);
1772 p43.Loop();
1773 TB06Analysis p44((indir+"/prop7.root"), (outdir+"/prop7.root"), 4, 5, md, 1.0, 1.0);
1774 p44.Loop();
1775 TB06Analysis p45((indir+"/prop8.root"), (outdir+"/prop8.root"), 4, 6, md, 1.0, 1.0);
1776 p45.Loop();
1777 TB06Analysis p46((indir+"/prop9.root"), (outdir+"/prop9.root"), 4, 7, md, 1.0, 1.0);
1778 p46.Loop();
1779 TB06Analysis p47((indir+"/prop20.root"), (outdir+"/prop20.root"), 4, 8, md, 1.0, 1.0);
1780 p47.Loop();
1781 TB06Analysis p48((indir+"/prop30.root"), (outdir+"/prop30.root"), 4, 9, md, 1.0, 1.0);
1782 p48.Loop();
1783 TB06Analysis p49((indir+"/prop350.root"),(outdir+"/prop350.root"),4,15, md, 1.0, 1.0);
1784 p49.Loop();
1785 }
1786
1787 void makePlots(int model1, int model2, int model3=-1, int model4=-1,
1788 int model5=-1, int save=0) {
1789 std::vector<int> models;
1790 if (model1 >= 0) models.push_back(model1);
1791 if (model2 >= 0) models.push_back(model2);
1792 if (model3 >= 0) models.push_back(model3);
1793 if (model4 >= 0) models.push_back(model4);
1794 if (model5 >= 0) models.push_back(model5);
1795 for (int ien=0; ien<8; ++ien)
1796 plotDataMCDist(0,ien,models,2,"model",true,true,-1,-1,save);
1797 for (int ien=0; ien<8; ++ien)
1798 plotDataMCDist(1,ien,models,2,"model",true,true,-1,-1,save);
1799
1800
1801
1802
1803
1804
1805 for (int ien=0; ien<8; ++ien)
1806 plotDataMCDist(4,ien,models,2,"model",true,true,-1,-1,save);
1807
1808
1809
1810
1811 }
1812
1813 void PrintMeanRatio(const char* infile="ResMean.out", int maxset=-1) {
1814 std::ifstream fInput(infile);
1815 if (!fInput.good()) {
1816 std::cout << "Cannot open file " << infile << std::endl;
1817 } else {
1818 int nset(0);
1819 fInput >> nset;
1820 if (fInput.good()) {
1821 int nsets = ((maxset < 0) || (maxset >= nset)) ? nset-1 : maxset;
1822 std::cout << "Will look into " << nsets << ":" << nset << " sets\n";
1823 for (int iset=0; iset<=nsets; ++iset) {
1824 char buff[200];
1825 int npt(0);
1826 fInput >> npt >> buff;
1827 std::cout << "Data set " << iset << " " << buff << " with " << npt
1828 << " points" << std::endl;
1829 double sumNum(0), sumDen(0);
1830 for (int ip=0; ip<npt; ++ip) {
1831 double pbeam, rat, drt;
1832 fInput >> pbeam >> rat >> drt;
1833 if (rat > 1.) {
1834 rat = 1./rat; drt *= (rat*rat);
1835 }
1836 sumNum += (fabs(1.0-rat)/(drt*drt));
1837 sumDen += (1.0/(drt*drt));
1838 }
1839 double mean = (sumDen>0) ? (sumNum/sumDen) : 0;
1840 double error = (sumDen>0) ? 1.0/sqrt(sumDen) : 0;
1841 std::cout << "Set " << iset << " Delta " << mean << " +- " << error
1842 << std::endl;
1843 }
1844 }
1845 fInput.close();
1846 }
1847 }