本文整理汇总了C++中TFile::Close方法的典型用法代码示例。如果您正苦于以下问题:C++ TFile::Close方法的具体用法?C++ TFile::Close怎么用?C++ TFile::Close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TFile
的用法示例。
在下文中一共展示了TFile::Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: trim
//.........这里部分代码省略.........
char trig2m = 0;
outtree->Branch("mcwgt" , &mcwgt , "mcwgt/D" );
outtree->Branch("puwgt" , &puwgt , "puwgt/D" );
outtree->Branch("lidw1" , &lidw1 , "lidw1/D" );
outtree->Branch("lidw2" , &lidw2 , "lidw2/D" );
outtree->Branch("midw1" , &midw1 , "midw1/D" );
outtree->Branch("midw2" , &midw2 , "midw2/D" );
outtree->Branch("tidw1" , &tidw1 , "tidw1/D" );
outtree->Branch("tidw2" , &tidw2 , "tidw2/D" );
outtree->Branch("m1pt" , &m1pt , "m1pt/D" );
outtree->Branch("m1eta" , &m1eta , "m1eta/D" );
outtree->Branch("m1eta" , &m1phi , "m1phi/D" );
outtree->Branch("m1id" , &m1id , "m1id/B" );
outtree->Branch("m1iso" , &m1iso , "m1iso/D" );
outtree->Branch("m2pt" , &m2pt , "m2pt/D" );
outtree->Branch("m2eta" , &m2eta , "m2eta/D" );
outtree->Branch("m2eta" , &m2phi , "m2phi/D" );
outtree->Branch("m2id" , &m2id , "m2id/B" );
outtree->Branch("m2iso" , &m2iso , "m2iso/D" );
outtree->Branch("mmpt" , &mmpt , "mmpt/D" );
outtree->Branch("mmeta" , &mmeta , "mmeta/D" );
outtree->Branch("mmeta" , &mmphi , "mmphi/D" );
outtree->Branch("mass" , &mass , "mass/D" );
outtree->Branch("merr" , &merr , "merr/D" );
outtree->Branch("trig1m", &trig1m, "trig1m/b");
outtree->Branch("trig2m", &trig2m, "trig2m/b");
while(reader.Next()) {
if (muons->size() != 2) continue;
if (dimuons->size() != 1) continue;
unsigned numvtx = *nvtx;
if (numvtx > 40) numvtx = 40;
double pt1 = muons->at((*m1idx)[0]).Pt();
double pt2 = muons->at((*m2idx)[0]).Pt();
double eta1 = fabs(muons->at((*m1idx)[0]).Eta());
double eta2 = fabs(muons->at((*m2idx)[0]).Eta());
if (pt1 >= 120.0) pt1 = 119.9;
if (pt2 >= 120.0) pt2 = 119.9;
if (pt1 <= 20.0) pt1 = 20.1;
if (pt2 <= 20.0) pt2 = 20.1;
if (isMC) {
mcwgt = 35.9 * (*wgt) * (*xsec) / wgtsum;
puwgt = purwthist->GetBinContent(purwthist->FindBin(numvtx));
lidw1 = muidlhist->GetBinContent(muidlhist->FindBin(eta1, pt1));
lidw1*= muislhist->GetBinContent(muislhist->FindBin(eta1, pt1));
lidw2 = muidlhist->GetBinContent(muidlhist->FindBin(eta2, pt2));
lidw2*= muislhist->GetBinContent(muislhist->FindBin(eta2, pt2));
midw1 = muidmhist->GetBinContent(muidmhist->FindBin(eta1, pt1));
midw1*= muismhist->GetBinContent(muismhist->FindBin(eta1, pt1));
midw2 = muidmhist->GetBinContent(muidmhist->FindBin(eta2, pt2));
midw2*= muismhist->GetBinContent(muismhist->FindBin(eta2, pt2));
tidw1 = muidthist->GetBinContent(muidthist->FindBin(eta1, pt1));
tidw1*= muisthist->GetBinContent(muisthist->FindBin(eta1, pt1));
tidw2 = muidthist->GetBinContent(muidthist->FindBin(eta2, pt2));
tidw2*= muisthist->GetBinContent(muisthist->FindBin(eta2, pt2));
}
m1pt = muons->at((*m1idx)[0]).Pt();
m1eta = muons->at((*m1idx)[0]).Eta();
m1phi = muons->at((*m1idx)[0]).Phi();
m2pt = muons->at((*m2idx)[0]).Pt();
m2eta = muons->at((*m2idx)[0]).Eta();
m2phi = muons->at((*m2idx)[0]).Phi();
mmpt = (*dimuons)[0].Pt();
mmeta = (*dimuons)[0].Eta();
mmphi = (*dimuons)[0].Phi();
mass = (*dimuons)[0].M();
merr = (*masserr)[0];
m1id = mid->at((*m1idx)[0]);
m2id = mid->at((*m2idx)[0]);
m1iso = miso->at((*m1idx)[0]);
m2iso = miso->at((*m2idx)[0]);
trig1m = (*hlt1m);
trig2m = (*hlt2m);
outtree->Fill();
}
outtree->Write();
outfile->Close();
}
示例2: MakeAllDCsyst
//.........这里部分代码省略.........
int mMother = KParser::getOptionValue<int>(setnames[1]);
int mLSP = KParser::getOptionValue<int>(setnames[2]);
tree->Branch("mMother",&mMother,"mMother/I");
tree->Branch("mLSP",&mLSP,"mLSP/I");
//map to keep track of maximum pct diffs
KMap<double> pctDiffMap;
double nominal_yield = nominal->Integral(0,nominal->GetNbinsX()+1);
//divide, bound, set labels (prepended w/ "signal_")
for(auto isyst : hsyst){
vector<string> inames;
KParser::process(isyst->GetName(),'_',inames);
string binname;
bool up = (inames.back().find("up")!=string::npos or inames.back().find("Up")!=string::npos);
if(up) binname = inames.back().substr(0,inames.back().size()-2);
else binname = inames.back().substr(0,inames.back().size()-4); //down
string treename = binname;
binname = "signal_"+binname;
//check yield (keep max diff in case of up and down)
double iyield = isyst->Integral(0,isyst->GetNbinsX()+1);
double pctdiff = fabs(1.-iyield/nominal_yield)*100;
if(!pctDiffMap.Has(treename) or pctDiffMap.Get(treename) < pctdiff){
pctDiffMap.Add(treename,pctdiff);
}
for(unsigned b = 1; b <= isyst->GetNbinsX(); ++b){
//divide
double unc = 1.0;
double denom = nominal->GetBinContent(b);
//if central value is zero, treat syst as a shift
if(denom==0.) denom = 1.0;
unc = isyst->GetBinContent(b)/denom;
//bound
unc = min(max(unc,0.01),3.0);
//set
isyst->SetBinContent(b,unc);
isyst->GetXaxis()->SetBinLabel(b,binname.c_str());
}
}
//make stat error
string sname = changeHistoName(nominal->GetName(),"MCStatErr");
TH1F* ssyst = (TH1F*)nominal->Clone(sname.c_str());
double stat_yield = 0;
for(unsigned b = 1; b <= ssyst->GetNbinsX(); ++b){
//label
string slabel = "signal_MCStatErr_";
slabel += ssyst->GetXaxis()->GetBinLabel(b);
ssyst->GetXaxis()->SetBinLabel(b,slabel.c_str());
stat_yield += ssyst->GetBinError(b)+ssyst->GetBinContent(b);
//divide
if(ssyst->GetBinContent(b)>0.) ssyst->SetBinContent(b, 1.0+ssyst->GetBinError(b)/ssyst->GetBinContent(b));
else ssyst->SetBinContent(b, 1.0+ssyst->GetBinError(b));
}
hsyst.push_back(ssyst);
pctDiffMap.Add("MCStatErr",fabs(1-stat_yield/nominal_yield)*100);
//genMHT correction and unc for fastsim
if(genMHT){
//keep original nominal histogram
string nname = changeHistoName(nominal->GetName(),"nominalOrig");
TH1F* nominalOrig = (TH1F*)nominal->Clone(nname.c_str());
string gname = changeHistoName(nominal->GetName(),"MHTSyst");
TH1F* gsyst = (TH1F*)nominal->Clone(gname.c_str());
double g_yield = 0;
//modify nominal as average of nominal and genMHT & compute syst as difference
for(unsigned b = 1; b <= nominal->GetNbinsX(); ++b){
gsyst->SetBinContent(b, 1.0+abs(nominal->GetBinContent(b) - genMHT->GetBinContent(b))/2.0);
gsyst->GetXaxis()->SetBinLabel(b,"signal_MHTSyst");
nominal->SetBinContent(b, (nominal->GetBinContent(b) + genMHT->GetBinContent(b))/2.0);
g_yield += (gsyst->GetBinContent(b)-1.0)+nominal->GetBinContent(b);
}
hsyst.push_back(gsyst);
hsyst.push_back(nominalOrig);
hsyst.push_back(genMHT);
pctDiffMap.Add("MHTSyst",fabs(1-g_yield/nominal_yield)*100);
}
//add branches to syst tree
for(auto& systpair : pctDiffMap.GetTable()){
tree->Branch(systpair.first.c_str(),&systpair.second,(systpair.first+"/D").c_str());
}
//fill and write tree w/ hadd-able filename
tree->Fill();
string thetrfile = "tree_syst_"+setnames[0]+"_block"+setnames[1]+"-"+setnames[2]+"_fast.root";
TFile* trfile = TFile::Open(thetrfile.c_str(),"RECREATE");
trfile->cd();
tree->Write();
trfile->Close();
//write processed syst histos
string thenewfile = outpre+"proc"+osuff+".root";
TFile* outfile = TFile::Open(thenewfile.c_str(),"RECREATE");
outfile->cd();
nominal->Write();
for(auto isyst : hsyst) isyst->Write();
outfile->Close();
}
示例3: TMVAClassification_ttV
//.........这里部分代码省略.........
factory->BookMethod( TMVA::Types::kFDA, "FDA_SA",
"H:!V:Formula=(0)+(1)*x0+(2)*x1+(3)*x2+(4)*x3:ParRanges=(-1,1);(-10,10);(-10,10);(-10,10);(-10,10):FitMethod=SA:MaxCalls=15000:KernelTemp=IncAdaptive:InitialTemp=1e+6:MinTemp=1e-6:Eps=1e-10:UseDefaultScale" );
if (Use["FDA_MT"])
factory->BookMethod( TMVA::Types::kFDA, "FDA_MT",
"H:!V:Formula=(0)+(1)*x0+(2)*x1+(3)*x2+(4)*x3:ParRanges=(-1,1);(-10,10);(-10,10);(-10,10);(-10,10):FitMethod=MINUIT:ErrorLevel=1:PrintLevel=-1:FitStrategy=2:UseImprove:UseMinos:SetBatch" );
if (Use["FDA_GAMT"])
factory->BookMethod( TMVA::Types::kFDA, "FDA_GAMT",
"H:!V:Formula=(0)+(1)*x0+(2)*x1+(3)*x2+(4)*x3:ParRanges=(-1,1);(-10,10);(-10,10);(-10,10);(-10,10):FitMethod=GA:Converger=MINUIT:ErrorLevel=1:PrintLevel=-1:FitStrategy=0:!UseImprove:!UseMinos:SetBatch:Cycles=1:PopSize=5:Steps=5:Trim" );
if (Use["FDA_MCMT"])
factory->BookMethod( TMVA::Types::kFDA, "FDA_MCMT",
"H:!V:Formula=(0)+(1)*x0+(2)*x1+(3)*x2+(4)*x3:ParRanges=(-1,1);(-10,10);(-10,10);(-10,10);(-10,10):FitMethod=MC:Converger=MINUIT:ErrorLevel=1:PrintLevel=-1:FitStrategy=0:!UseImprove:!UseMinos:SetBatch:SampleSize=20" );
// TMVA ANN: MLP (recommended ANN) -- all ANNs in TMVA are Multilayer Perceptrons
if (Use["MLP"])
factory->BookMethod( TMVA::Types::kMLP, "MLP", "H:!V:NeuronType=tanh:VarTransform=N:NCycles=600:HiddenLayers=N+5:TestRate=5:!UseRegulator" );
if (Use["MLPBFGS"])
factory->BookMethod( TMVA::Types::kMLP, "MLPBFGS", "H:!V:NeuronType=tanh:VarTransform=N:NCycles=600:HiddenLayers=N+5:TestRate=5:TrainingMethod=BFGS:!UseRegulator" );
if (Use["MLPBNN"])
factory->BookMethod( TMVA::Types::kMLP, "MLPBNN", "H:!V:NeuronType=tanh:VarTransform=N:NCycles=600:HiddenLayers=N+5:TestRate=5:TrainingMethod=BFGS:UseRegulator" ); // BFGS training with bayesian regulators
// CF(Clermont-Ferrand)ANN
if (Use["CFMlpANN"])
factory->BookMethod( TMVA::Types::kCFMlpANN, "CFMlpANN", "!H:!V:NCycles=2000:HiddenLayers=N+1,N" ); // n_cycles:#nodes:#nodes:...
// Tmlp(Root)ANN
if (Use["TMlpANN"])
factory->BookMethod( TMVA::Types::kTMlpANN, "TMlpANN", "!H:!V:NCycles=200:HiddenLayers=N+1,N:LearningMethod=BFGS:ValidationFraction=0.3" ); // n_cycles:#nodes:#nodes:...
// Support Vector Machine
if (Use["SVM"])
factory->BookMethod( TMVA::Types::kSVM, "SVM", "Gamma=0.25:Tol=0.001:VarTransform=Norm" );
// Boosted Decision Trees
if (Use["BDTG"]) // Gradient Boost
factory->BookMethod( TMVA::Types::kBDT, "BDTG",
"!H:!V:NTrees=1000:BoostType=Grad:Shrinkage=0.10:UseBaggedGrad:GradBaggingFraction=0.5:nCuts=20:NNodesMax=5" );
if (Use["BDT"]) // Adaptive Boost
factory->BookMethod( TMVA::Types::kBDT, "BDT",
"!H:!V:NTrees=850:nEventsMin=150:MaxDepth=3:BoostType=AdaBoost:AdaBoostBeta=0.5:SeparationType=GiniIndex:nCuts=20:PruneMethod=NoPruning" );
if (Use["BDTB"]) // Bagging
factory->BookMethod( TMVA::Types::kBDT, "BDTB",
"!H:!V:NTrees=400:BoostType=Bagging:SeparationType=GiniIndex:nCuts=20:PruneMethod=NoPruning" );
if (Use["BDTD"]) // Decorrelation + Adaptive Boost
factory->BookMethod( TMVA::Types::kBDT, "BDTD",
"!H:!V:NTrees=400:nEventsMin=400:MaxDepth=3:BoostType=AdaBoost:SeparationType=GiniIndex:nCuts=20:PruneMethod=NoPruning:VarTransform=Decorrelate" );
if (Use["BDTF"]) // Allow Using Fisher discriminant in node splitting for (strong) linearly correlated variables
factory->BookMethod( TMVA::Types::kBDT, "BDTMitFisher",
"!H:!V:NTrees=50:nEventsMin=150:UseFisherCuts:MaxDepth=3:BoostType=AdaBoost:AdaBoostBeta=0.5:SeparationType=GiniIndex:nCuts=20:PruneMethod=NoPruning" );
// RuleFit -- TMVA implementation of Friedman's method
if (Use["RuleFit"])
factory->BookMethod( TMVA::Types::kRuleFit, "RuleFit",
"H:!V:RuleFitModule=RFTMVA:Model=ModRuleLinear:MinImp=0.001:RuleMinDist=0.001:NTrees=20:fEventsMin=0.01:fEventsMax=0.5:GDTau=-1.0:GDTauPrec=0.01:GDStep=0.01:GDNSteps=10000:GDErrScale=1.02" );
// For an example of the category classifier usage, see: TMVAClassificationCategory
// --------------------------------------------------------------------------------------------------
// ---- Now you can optimize the setting (configuration) of the MVAs using the set of training events
// factory->OptimizeAllMethods("SigEffAt001","Scan");
// factory->OptimizeAllMethods("ROCIntegral","GA");
// --------------------------------------------------------------------------------------------------
// ---- Now you can tell the factory to train, test, and evaluate the MVAs
cout<<"TrainAllMethods"<<endl;
// Train MVAs using the set of training events
factory->TrainAllMethods();
// ---- Evaluate all MVAs using the set of test events
factory->TestAllMethods();
// ----- Evaluate and compare performance of all configured MVAs
factory->EvaluateAllMethods();
// --------------------------------------------------------------
// Save the output
outputFile->Close();
std::cout << "==> Wrote root file: " << outputFile->GetName() << std::endl;
std::cout << "==> TMVAClassification is done!" << std::endl;
delete factory;
// Launch the GUI for the root macros
if (!gROOT->IsBatch()) TMVAGui( outfileName );
}
示例4: ZinvVisualization
//.........这里部分代码省略.........
} if(i3==1&&i2==3){//mHT,35j,1b
histos[mapname]->SetBinContent(1, 16.86); histos[mapname]->SetBinError(1,sqrt(pow( 1.14,2)+pow( 3.89,2)));
histos[mapname]->SetBinContent(2, 15.66); histos[mapname]->SetBinError(2,sqrt(pow( 1.16,2)+pow( 3.62,2)));
histos[mapname]->SetBinContent(3, 16.99); histos[mapname]->SetBinError(3,sqrt(pow( 1.18,2)+pow( 3.92,2)));
histos[mapname]->SetBinContent(4, 13.70); histos[mapname]->SetBinError(4,sqrt(pow( 1.13,2)+pow( 3.17,2)));
histos[mapname]->SetBinContent(5, 8.91); histos[mapname]->SetBinError(5,sqrt(pow( 0.89,2)+pow( 2.87,2)));
histos[mapname]->SetBinContent(6, 2.27); histos[mapname]->SetBinError(6,sqrt(pow( 0.45,2)+pow( 0.73,2)));
} if(i3==1&&i2==6){//mHT,6j,1b
histos[mapname]->SetBinContent(1, 2.41); histos[mapname]->SetBinError(1,sqrt(pow( 0.70,2)+pow( 1.39,2)));
histos[mapname]->SetBinContent(2, 1.55); histos[mapname]->SetBinError(2,sqrt(pow( 0.52,2)+pow( 0.89,2)));
histos[mapname]->SetBinContent(3, 1.11); histos[mapname]->SetBinError(3,sqrt(pow( 0.45,2)+pow( 0.64,2)));
histos[mapname]->SetBinContent(4, 0.85); histos[mapname]->SetBinError(4,sqrt(pow( 0.42,2)+pow( 0.53,2)));
} if(i3==2&&i2==1){//hHT,2j,1b
histos[mapname]->SetBinContent(1, 2.69); histos[mapname]->SetBinError(1,sqrt(pow( 0.31,2)+pow( 1.80,2)));
histos[mapname]->SetBinContent(2, 2.25); histos[mapname]->SetBinError(2,sqrt(pow( 0.31,2)+pow( 1.51,2)));
} if(i3==2&&i2==3){//hHT,35j,1b
histos[mapname]->SetBinContent(1, 2.16); histos[mapname]->SetBinError(1,sqrt(pow( 0.41,2)+pow( 0.61,2)));
histos[mapname]->SetBinContent(2, 2.40); histos[mapname]->SetBinError(2,sqrt(pow( 0.43,2)+pow( 0.67,2)));
histos[mapname]->SetBinContent(3, 2.57); histos[mapname]->SetBinError(3,sqrt(pow( 0.49,2)+pow( 0.72,2)));
histos[mapname]->SetBinContent(4, 1.70); histos[mapname]->SetBinError(4,sqrt(pow( 0.40,2)+pow( 0.61,2)));
} if(i3==2&&i2==6){//hHT,6j,1b
histos[mapname]->SetBinContent(1, 1.06); histos[mapname]->SetBinError(1,sqrt(pow( 0.44,2)+pow( 0.84,2)));
histos[mapname]->SetBinContent(2, 0.92); histos[mapname]->SetBinError(2,sqrt(pow( 0.53,2)+pow( 0.73,2)));
// histos[mapname]->SetBinContent(3,); histos[mapname]->SetBinError(3,sqrt(pow(,2)+pow(,2)));
}
}}
cout << "Saving." << endl;
TFile *fsavefile = new TFile("../Results/Filtered/GammaJetsPrediction/20130617_test/ZinvPredictionNumbers.root","RECREATE");
fsavefile->cd();
for(map<string,TH1D*>::iterator h=histos.begin(); h!=histos.end();++h){
h->second->Write();
}
fsavefile->Close();
cout << "Saved histograms in " << fsavefile->GetName() << endl;
//make the plots - not TDR style
TLatex TitleBox;
TitleBox.SetNDC();
TitleBox.SetNDC();
TitleBox.SetTextAlign(12);
TitleBox.SetTextFont(42);
TitleBox.SetTextSize(0.04219409);
TitleBox.SetLineWidth(2);
TString text;
string outname;
double max = 0.;
double max1,max2;
string outputdir = "../Results/Filtered/GammaJetsPrediction/20130617_test/ZinvPredictionPlots/";
Util::MakeOutputDir(outputdir);
TCanvas *c1 = new TCanvas("c1", "c1",485,220,700,504);
c1->Range(82.71719,-0.4425771,532.9945,2.212885);
c1->SetFillColor(0);
c1->SetBorderMode(0);
c1->SetBorderSize(2);
c1->SetLeftMargin(0.1494253);
c1->SetRightMargin(0.07327586);
c1->SetTopMargin(0.08016878);
c1->SetBottomMargin(0.1666667);
c1->SetFrameBorderMode(0);
c1->SetFrameBorderMode(0);
for(int i3 = 0; i3<HTbinsize; ++i3){
for(int i2 = 0; i2<signalregionsize; ++i2){
string hs = string("_") + HT_bin[i3] + string("_") + signal_region[i2];// + string("_") + sample_type[i1];
string mapname = "MT2pred" + hs;
示例5: SetStyle
//.........这里部分代码省略.........
InitSignal(scales[4+offset]);
InitSignal(scales[5+offset]);
InitSignal(scales[6+offset]);
#endif
scales[0]->Draw();
scales[0]->GetXaxis()->SetBinLabel(1, "#bf{Fakes}");
scales[0]->GetXaxis()->SetBinLabel(2, "#bf{EWK}" );
scales[0]->GetXaxis()->SetBinLabel(3, "#bf{ttbar}");
scales[0]->GetXaxis()->SetBinLabel(4, "#bf{Ztt}" );
#ifdef MSSM
scales[0]->GetXaxis()->SetBinLabel(5, "#bf{ggH}" );
scales[0]->GetXaxis()->SetBinLabel(6, "#bf{bbH}" );
scales[0]->GetXaxis()->SetBinLabel(7, "#bf{NONE}" );
#else
#ifdef HWW_BG
scales[0]->GetXaxis()->SetBinLabel(5, "#bf{ggH_hww}");
scales[0]->GetXaxis()->SetBinLabel(6, "#bf{qqH_hww}");
#endif
scales[0]->GetXaxis()->SetBinLabel(5+offset, "#bf{ggH}" );
scales[0]->GetXaxis()->SetBinLabel(6+offset, "#bf{qqH}" );
scales[0]->GetXaxis()->SetBinLabel(7+offset, "#bf{VH}" );
#endif
scales[0]->SetMaximum(+0.5);
scales[0]->SetMinimum(-0.5);
scales[0]->GetYaxis()->CenterTitle();
scales[0]->GetYaxis()->SetTitle("#bf{Postfit/Prefit-1}");
scales[1]->Draw("same");
scales[2]->Draw("same");
scales[3]->Draw("same");
#ifdef HWW_BG
scales[4]->Draw("same");
scales[5]->Draw("same");
#endif
#ifndef DROP_SIGNAL
scales[4+offset]->Draw("same");
scales[5+offset]->Draw("same");
scales[6+offset]->Draw("same");
#endif
TH1F* zero_samples = (TH1F*)scales[0]->Clone("zero_samples"); zero_samples->Clear();
zero_samples->SetBinContent(1,0.);
zero_samples->Draw("same");
canv2->RedrawAxis();
/*
prepare output
*/
bool isSevenTeV = std::string(inputfile).find("7TeV")!=std::string::npos;
canv ->Print(TString::Format("%s_%sfit_%s_%s.png" , directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN"));
canv ->Print(TString::Format("%s_%sfit_%s_%s.pdf" , directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN"));
canv ->Print(TString::Format("%s_%sfit_%s_%s.eps" , directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN"));
if(!log || FULLPLOTS)
{
canv0->Print(TString::Format("%s_datamc_%sfit_%s_%s.png", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN"));
canv0->Print(TString::Format("%s_datamc_%sfit_%s_%s.pdf", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN"));
canv0->Print(TString::Format("%s_datamc_%sfit_%s_%s.eps", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN"));
}
if((!log && scaled) || FULLPLOTS)
{
canv1->Print(TString::Format("%s_prefit_%sfit_%s_%s.png", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN"));
canv1->Print(TString::Format("%s_prefit_%sfit_%s_%s.pdf", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN"));
canv1->Print(TString::Format("%s_prefit_%sfit_%s_%s.eps", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN"));
canv2->Print(TString::Format("%s_sample_%sfit_%s_%s.png", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN"));
canv2->Print(TString::Format("%s_sample_%sfit_%s_%s.pdf", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN"));
canv2->Print(TString::Format("%s_sample_%sfit_%s_%s.eps", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN"));
}
TFile* output = new TFile(TString::Format("%s_%sfit_%s_%s.root", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN"), "update");
output->cd();
data ->Write("data_obs");
Fakes->Write("Fakes" );
EWK ->Write("EWK" );
ttbar->Write("ttbar" );
Ztt ->Write("Ztt" );
#ifdef MSSM
ggH ->Write("ggH" );
bbH ->Write("bbH" );
#else
#ifdef HWW_BG
ggH_hww ->Write("ggH_hww" );
#endif
#ifndef DROP_SIGNAL
ggH ->Write("ggH" );
qqH ->Write("qqH" );
VH ->Write("VH" );
#endif
#endif
if(errorBand){
errorBand->Write("errorBand");
}
output->Close();
delete errorBand;
delete model;
delete test1;
delete zero;
delete rat1;
delete rat2;
delete zero_samples;
delete ref;
}
示例6: diffXsecZbb
//.........这里部分代码省略.........
histo1->Draw();
histo2->SetLineColor(56);
histo2->Draw("same");
histo3->SetLineColor(60);
histo3->Draw("same");
histoTot->Draw("same");
legendTot->Clear();
sprintf(nev,"Zb\\bar{b}+0jets");
legendTot->AddEntry(histo1,nev,"l");
sprintf(nev,"Zb\\bar{b}+1jets");
legendTot->AddEntry(histo2,nev,"l");
sprintf(nev,"Zb\\bar{b}+2jets");
legendTot->AddEntry(histo3,nev,"l");
sprintf(nev,"inclusive");
legendTot->AddEntry(histoTot,nev,"l");
legendTot->Draw();
TCanvas * canvasirrBkg = new TCanvas ( "diffxSecirrbkg", "differential xSec for irriducible background", 1200, 400 );
gStyle->SetOptStat(0);
canvasirrBkg->UseCurrentStyle();
canvasirrBkg->Divide(3,1);
canvasirrBkg->cd(1);
histoirrBkg1->SetNormFactor(histoirrBkg1Entries*invLuminosityEff1*luminosityFactor);
histoirrBkg1->Draw();
sprintf(nev,"number of events in 100 fb^{-1}:");
sprintf(nev,"%.2f",histoirrBkg1Entries*invLuminosityEff1*luminosityFactor);
legend1->AddEntry(histoirrBkg1,nev,"");
legend1->Draw();
canvasirrBkg->cd(2);
histoirrBkg2->SetNormFactor(histoirrBkg2Entries*invLuminosityEff2*luminosityFactor);
histoirrBkg2->Draw();
legend2->Clear();
sprintf(nev,"number of events in 100 fb^{-1}:");
sprintf(nev,"%.2f",histoirrBkg2Entries*invLuminosityEff2*luminosityFactor);
legend2->AddEntry(histoirrBkg2,nev,"");
legend2->Draw();
canvasirrBkg->cd(3);
histoirrBkg3->SetNormFactor(histoirrBkg3Entries*invLuminosityEff3*luminosityFactor);
histoirrBkg3->Draw();
legend3->Clear();
sprintf(nev,"number of events in 100 fb^{-1}:");
sprintf(nev,"%.2f",histoirrBkg3Entries*invLuminosityEff3*luminosityFactor);
legend3->AddEntry(histoirrBkg3,nev,"");
legend3->Draw();
histoirrBkgTot->Sumw2();
histoirrBkgTot->Add(histoirrBkg1);
histoirrBkgTot->Add(histoirrBkg2);
histoirrBkgTot->Add(histoirrBkg3);
TCanvas * canvasirrBkgTot = new TCanvas ( "inclusivediffxSecirrBkg", "differential xSec", 1200, 400 );
gStyle->SetOptStat(0);
canvasirrBkgTot->UseCurrentStyle();
canvasirrBkgTot->cd();
gPad->SetLogy();
histoirrBkg1->SetTitle("4-body mass (100 fb^{-1})");
histoirrBkg1->GetXaxis()->SetTitle("m_{llbb} (GeV)");
histoirrBkg1->GetYaxis()->SetTitle("d#sigma/dm_{llbb} events/10GeV");
histoirrBkg1->SetMinimum(0.001);
histoirrBkg1->SetLineColor(51);
histoirrBkg1->Draw();
histoirrBkg2->SetLineColor(56);
histoirrBkg2->Draw("same");
histoirrBkg3->SetLineColor(60);
histoirrBkg3->Draw("same");
histoirrBkgTot->Draw("same");
legendTot->Clear();
sprintf(nev,"Zb\\bar{b}+0jets");
legendTot->AddEntry(histoirrBkg1,nev,"l");
sprintf(nev,"Zb\\bar{b}+1jets");
legendTot->AddEntry(histoirrBkg2,nev,"l");
sprintf(nev,"Zb\\bar{b}+2jets");
legendTot->AddEntry(histoirrBkg3,nev,"l");
sprintf(nev,"inclusive");
legendTot->AddEntry(histoirrBkgTot,nev,"l");
legendTot->Draw();
canvas->Print("Zbb.jpg");
canvasTot->Print("Zbbtot.jpg");
canvasirrBkg->Print("ZbbIrr.jpg");
canvasirrBkgTot->Print("ZbbIrrtot.jpg");
TFile * outputFile = new TFile("diffXsecZbb.root","RECREATE");
histo1->Write();
histo2->Write();
histo3->Write();
histoTot->Write();
histoirrBkg1->Write();
histoirrBkg2->Write();
histoirrBkg3->Write();
histoirrBkgTot->Write();
outputFile->Close();
}
示例7: produce_MJJdistributions_one
//.........这里部分代码省略.........
double simulatedZ = hVBF_onshell_LC[0]->Integral(binWZthreshold,endZ-1);
double simulatedWbkg = simulatedSB*(WZthreshold-beginWMass)/(endZMass-beginWMass);
double simulatedZbkg = simulatedSB*(endZMass-WZthreshold)/(endZMass-beginWMass);
cout << "W Total / Bkg: " << simulatedW << " / " << simulatedWbkg << endl;
cout << "Z Total / Bkg: " << simulatedZ << " / " << simulatedZbkg << endl;
double brval = BR_Table[1][2];
if (folder==2) brval = BR_Table[1][3];
brval *= 1000.;
double ratioW = (XSEC_Table_WH[EnergyIndex][1]*brval*luminosity[EnergyIndex]) / (simulatedW-simulatedWbkg);
double ratioZ = (XSEC_Table_ZH[EnergyIndex][1]*brval*luminosity[EnergyIndex]) / (simulatedZ-simulatedZbkg);
double scale_SB_VBF = (simulatedW + simulatedZ)/(ratioW*simulatedW + ratioZ*simulatedZ);
double scale_SB_HH = 1.5;
double nVBF_Sig_Simulated = 0;
cout << "VBF SB scale: " << scale_SB_VBF << endl;
cout << "WH scale: " << ratioW << endl;
cout << "ZH scale: " << ratioZ << endl;
for (int tr = 0; tr < 4; tr++){
for (int binx=1; binx<=hVBF_onshell_LC[tr]->GetNbinsX(); binx++){
double bincontent = hVBF_onshell_LC[tr]->GetBinContent(binx);
if (binx < endZ && binx >= binWZthreshold) bincontent *= ratioZ;
else if (binx < binWZthreshold && binx >= beginW) bincontent *= ratioW;
else{
if ((binx < endSB && binx >= endZ) || (binx < beginW && binx >= beginSB)) bincontent *= scale_SB_VBF;
if (tr==0){
double bincount = bincontent;
if (binx<beginLowHH || (binx>=beginHH && binx<endHH)) bincount=0;
if ((binx<beginHH && binx>=sidebandBeginHH) || (binx<sidebandEndHH && binx>=endHH)) bincount*=scale_SB_HH;
nVBF_Sig_Simulated += bincount;
}
}
hVBF_onshell_scaled[tr]->SetBinContent(binx, bincontent);
}
for (int binx=1; binx<=hVBF_offshell_LC[tr]->GetNbinsX(); binx++){
double bincontent = hVBF_offshell_LC[tr]->GetBinContent(binx);
if ((binx < endSB && binx >= endZ) || (binx < beginW && binx >= beginSB)) bincontent *= scale_SB_VBF;
if (binx < endZ && binx >= binWZthreshold) bincontent *= ratioZ;
if (binx < binWZthreshold && binx >= beginW) bincontent *= ratioW;
hVBF_offshell_scaled[tr]->SetBinContent(binx, bincontent);
}
}
double vbfscale = (XSEC_Table_VBF[EnergyIndex][1]*brval*luminosity[EnergyIndex]) / nVBF_Sig_Simulated;
cout << "VBF scale: " << vbfscale << endl;
for (int tr = 0; tr < 4; tr++){
for (int binx=1; binx<=hVBF_onshell_scaled[tr]->GetNbinsX(); binx++){
double bincontent = hVBF_onshell_scaled[tr]->GetBinContent(binx);
if (!(binx < endZ && binx >= binWZthreshold) && !(binx < binWZthreshold && binx >= beginW)) bincontent *= vbfscale;
if (binx<beginLowHH || (binx>=beginHH && binx<endHH)) bincontent=0;
if ((binx<beginHH && binx>=sidebandBeginHH) || (binx<sidebandEndHH && binx>=endHH)) bincontent*=scale_SB_HH;
hVBF_onshell_scaled_wVBF[tr]->SetBinContent(binx, bincontent);
}
for (int binx=1; binx<=hVBF_offshell_scaled[tr]->GetNbinsX(); binx++){
double bincontent = hVBF_offshell_scaled[tr]->GetBinContent(binx);
if (!(binx < endZ && binx >= binWZthreshold) && !(binx < binWZthreshold && binx >= beginW)) bincontent *= vbfscale;
if (binx<beginLowHH || (binx>=beginHH && binx<endHH)) bincontent=0;
if ((binx<beginHH && binx>=sidebandBeginHH) || (binx<sidebandEndHH && binx>=endHH)) bincontent*=scale_SB_HH;
hVBF_offshell_scaled_wVBF[tr]->SetBinContent(binx, bincontent);
}
cout << "Initial yield for " << templatetitles[tr] << ": " << hVBF_offshell_LC[tr]->Integral() << endl;
cout << "Intermediate yield for " << templatetitles[tr] << " without VBF re-scaling: " << hVBF_offshell_scaled[tr]->Integral() << endl;
cout << "Final yield for " << templatetitles[tr] << ": " << hVBF_offshell_scaled_wVBF[tr]->Integral() << endl;
cout << endl;
}
TH1F* hRatio = (TH1F*)hVBF_offshell_scaled_wVBF[0]->Clone("Phantom_VBFVH_ScalingRatio");
hRatio->Divide(hVBF_offshell_LC[0]);
for (int binx=1; binx<=hRatio->GetNbinsX(); binx++){
double bincontent = hRatio->GetBinContent(binx);
if (bincontent<=0 && !(binx<beginLowHH || (binx>=beginHH && binx<endHH))) cout << "Bin " << binx << " is unexpectedly non-positive!" << endl;
}
foutput->WriteTObject(hRatio);
delete hRatio;
for (int tr = 0; tr < 4; tr++){
foutput->WriteTObject(h2DVBF[tr]);
foutput->WriteTObject(hVBF_onshell[tr]);
foutput->WriteTObject(hVBF_offshell[tr]);
foutput->WriteTObject(hVBF_onshell_LC[tr]);
foutput->WriteTObject(hVBF_offshell_LC[tr]);
foutput->WriteTObject(hVBF_onshell_scaled[tr]);
foutput->WriteTObject(hVBF_offshell_scaled[tr]);
foutput->WriteTObject(hVBF_onshell_scaled_wVBF[tr]);
foutput->WriteTObject(hVBF_offshell_scaled_wVBF[tr]);
delete h2DVBF[tr];
delete hVBF_onshell[tr];
delete hVBF_offshell[tr];
delete hVBF_onshell_LC[tr];
delete hVBF_offshell_LC[tr];
delete hVBF_onshell_scaled[tr];
delete hVBF_offshell_scaled[tr];
delete hVBF_onshell_scaled_wVBF[tr];
delete hVBF_offshell_scaled_wVBF[tr];
}
foutput->Close();
}
}
示例8: mtl
//---------------------------------------------------------------
double *unbinnedFit(TString fiName, vector<double> xlim, double mtop, TLatex *channel_tex, TString outdir, double lumi)
//---------------------------------------------------------------
{
using namespace RooFit;
// reduce RooFit's verbosity on the INFO level
RooMsgService::instance().getStream(1).removeTopic(Minimization);
RooMsgService::instance().getStream(1).removeTopic(Plotting);
RooMsgService::instance().getStream(1).removeTopic(ObjectHandling);
RooMsgService::instance().getStream(1).removeTopic(Eval);
RooMsgService::instance().getStream(1).removeTopic(Fitting);
RooMsgService::instance().setSilentMode(true);
RooMsgService::instance().setGlobalKillBelow(RooFit::FATAL);
TFile *res = TFile::Open(fiName);
RooRealVar mtl("mass", "M_{J/#psi+l}", 0., 250., "GeV");
RooRealVar weight("weight", "weight", 0., 2.);
//RooRealVar mean("mean", "mass", (xlim[1]+xlim[0])/2., (xlim[1]+3.*xlim[0])/4., (3.*xlim[1]+xlim[0])/4.);
RooRealVar mean("mean", "mass", 70., 60., 80.);
RooRealVar width("width", "width", 25., 15., 40.);
TTree *tree = (TTree*)res->Get("MTriLept");
RooDataSet *dataset = new RooDataSet("dataset", "dataset", RooArgSet(mtl, weight), Import(*tree), WeightVar(weight));
RooGaussian pdf("gaus", "gaus", mtl, mean, width);
pdf.fitTo(*dataset, Range(xlim[0], xlim[1]), SumW2Error(kTRUE), PrintLevel(-1), PrintEvalErrors(-1));
TCanvas *cn = new TCanvas("cn", "cn", 800, 800);
cn->cd();
RooPlot *massframe = mtl.frame();
if (mtop < 1e-6)
dataset->plotOn(massframe, Binning(25), DataError(RooAbsData::SumW2));
else
dataset->plotOn(massframe, Binning(50), DataError(RooAbsData::SumW2));
pdf.plotOn(massframe, Range(xlim[0], xlim[1]));
massframe->Draw();
TLegend *leg = new TLegend(0.58,0.82,0.93,0.92,NULL,"brNDC");
if (mtop < 1e-6)
leg->SetHeader(TString::Format("#tilde{M}_{J/#psi+l} = (%3.1f #pm %3.1f) GeV", mean.getVal(), mean.getError()));
else
leg->SetHeader(TString::Format("#splitline{M_{t}^{gen} = %3.1f GeV}{#tilde{M}_{J/#psi+l} = (%3.1f #pm %3.1f) GeV}", mtop+0.5, mean.getVal(), mean.getError()));
leg_myStyle(leg);
leg->Draw("same");
channel_tex->Draw("same");
if (mtop < 1e-6)
cms_myStyle(lumi, true);
else
cms_myStyle(lumi, false);
TString outFile = outdir;
if (mtop < 1e-6)
outFile += "GausianUnbinnedFit_Data";
else
outFile += TString::Format("GaussianUnbinnedFit_%d_5", (int)mtop);
cn->SaveAs(outFile+".pdf");
cn->SaveAs(outFile+".C");
cn->SaveAs(outFile+".jpg");
cn->SaveAs(outFile+".eps");
res->Close();
double *mean_err = new double[2];
mean_err[0] = mean.getVal();
mean_err[1] = mean.getError();
return mean_err;
}
示例9: main
//.........这里部分代码省略.........
chBoard0 = true;
x0 = xmppc[i];
y0 = ymppc[i];
}
}
}
else //it was on board1
{
if( (((TMath::Power(floodx[1] - xPos[i],2)/ TMath::Power(xSigma[i],2)) + ( TMath::Power(floody[1] - yPos[i] ,2 ) / TMath::Power(ySigma[i],2))) < 1 ) && sumCharge1 > eMin[i] && sumCharge1 < eMax[i] )
{
if(chBoard1 == true) // 2 511 in the same matrix, get rid of the event
{
continue;
}
else
{
chBoard1 = true;
x1 = xmppc[i];
y1 = ymppc[i];
}
}
}
}
// for(int i = 0 ; i < 32 ; i++)
// {
// TTreeFormula* Formula = new TTreeFormula("Formula",Crystals[i],tree);
// if( Formula->EvalInstance() )
// {
// if(i < 16) //it was on board0
// {
// if(chBoard0 == true) // 2 511 in the same matrix, get rid of the event
// {
// continue;
// }
// else
// {
// chBoard0 = true;
// x0 = xmppc[i];
// y0 = ymppc[i];
// }
// }
// else //it was on board1
// {
// if(chBoard1 == true) // 2 511 in the same matrix, get rid of the event
// {
// continue;
// }
// else
// {
// chBoard1 = true;
// x1 = xmppc[i];
// y1 = ymppc[i];
// }
// }
// }
// }
if(chBoard0&&chBoard1)
{
//std::cout << " coincidence " << x0 << " " << y0 << " " << z0 << " " << x1 << " " << y1 << " " << z1 << std::endl;
float u = x0-x1;
float v = y0-y1;
float mx = x0 + s*u;
float my = y0 + s*v;
histo2->Fill(mx,my);
}
//std::cout << std::endl;
/*
if( Formula->EvalInstance() )
{
TimeTag = ExtendedTimeTag;
CrystalID = 0; //TODO
t2->Fill();
}*/
counter++;
int perc = ((100*counter)/nentries); //should strictly have not decimal part, written like this...
if( (perc % 10) == 0 )
{
std::cout << "\r";
std::cout << perc << "% done... ";
//std::cout << counter << std::endl;
}
}
TCanvas *canvas= new TCanvas("ciao1", "Distribuzione di Poisson");
histo2->Draw("COLZ");
TFile *outFile = new TFile ("histo2d.root","recreate");
//histo->Write();
histo2->Write();
canvas->Write();
outFile->Close();
return 0;
}
示例10: MultiHistoOverlap
//.........这里部分代码省略.........
// // histoSigmaVsEtaPlusMinusDiff[j]->SetMarkerSize(0.75);
// if ( j == 0 ) {
// histoSigmaVsEtaPlusMinusDiff[j]->GetXaxis()->SetTitle("#eta pos. muon - #eta neg. muon");
// histoSigmaVsEtaPlusMinusDiff[j]->GetYaxis()->SetTitle("#sigma(M_{#mu#mu}) (GeV)");
// // histoSigmaVsEtaPlusMinusDiff[j]->GetYaxis()->SetRangeUser(88.0,96.0);
// histoSigmaVsEtaPlusMinusDiff[j]->GetYaxis()->SetRangeUser(0.,3.);
// //histoSigmaVsEtaPlusMinusDiff[j]->GetYaxis()->SetRangeUser(90.60,90.75);
// histoSigmaVsEtaPlusMinusDiff[j]->GetXaxis()->SetRangeUser(-3.2,3.2);
// histoSigmaVsEtaPlusMinusDiff[j]->Draw();
// } else {
// histoSigmaVsEtaPlusMinusDiff[j]->Draw("SAME");
// }
// leg->AddEntry(histoSigmaVsEtaPlusMinusDiff[j],LegLabels[j],"PL");
// }
// }
// //cmsprel->Draw("same");
// leg->Draw("same");
// c2s->SaveAs(outDir+"SigmaVsEtaPlusMinusDiff.png");
// //----------------- CANVAS C3S --------------//
// c3s->SetFillColor(0);
// c3s->cd();
// leg = new TLegend(0.35,0.15,0.55,0.35);
// leg->SetBorderSize(1);
// leg->SetFillColor(0);
// leg->SetTextFont(42);
// // Sigma VS muon pT -------------------------------
// TH1D *histoSigmaVsPt[nOfFiles];
// for(Int_t j=0; j < nOfFiles; j++) {
// TFile *fin = (TFile*)FileList->At(j);
// if ( histoSigmaVsPt[j] = (TH1D*)fin->Get("MassVsPt/allHistos/sigmaHisto")){
// histoSigmaVsPt[j]->SetLineStyle(linestylelist_resol[j]);
// histoSigmaVsPt[j]->SetMarkerColor(colorlist_resol[j]);
// histoSigmaVsPt[j]->SetLineColor(colorlist_resol[j]);
// histoSigmaVsPt[j]->SetMarkerStyle(markerstylelist_resol[j]);
// // histoSigmaVsPt[j]->SetMarkerSize(0.75);
// if ( j == 0 ) {
// histoSigmaVsPt[j]->GetXaxis()->SetTitle("muon p_T (GeV)");
// histoSigmaVsPt[j]->GetYaxis()->SetTitle("#sigma(M_{#mu#mu}) (GeV)");
// // histoSigmaVsPt[j]->GetYaxis()->SetRangeUser(88.0,96.0);
// histoSigmaVsPt[j]->GetYaxis()->SetRangeUser(0.,3.);
// //histoSigmaVsPt[j]->GetYaxis()->SetRangeUser(90.60,90.75);
// histoSigmaVsPt[j]->GetXaxis()->SetRangeUser(15.,105.);
// histoSigmaVsPt[j]->Draw();
// } else {
// histoSigmaVsPt[j]->Draw("SAME");
// }
// leg->AddEntry(histoSigmaVsPt[j],LegLabels[j],"PL");
// }
// }
// //cmsprel->Draw("same");
// leg->Draw("same");
// c3s->SaveAs(outDir+"SigmaVsPt.png");
//----------------- CANVAS CFIT --------------//
cFit->SetFillColor(0);
cFit->cd();
Float_t nN = TMath::Sqrt(nOfFiles);
Int_t nX = (Int_t)nN;
if ( nN-nX > 0.5 ) nX++;
Int_t nY = (Int_t)(nOfFiles/nX);
std::cout << nX << " ," << nY << std::endl;
cFit->Divide(nOfFiles,1);
// Mass VS muon phi plus -------------------------------
TFile *ZFitFile = new TFile("ZFitFile.root","RECREATE");
RooPlot *histoLineShape[nOfFiles];
for(Int_t j=0; j < nOfFiles; j++) {
TFile *fin = (TFile*)FileList->At(j);
if ( histoLineShape[j] = (RooPlot*)fin->Get("hRecBestResAllEvents_Mass_frame")) {
std::cout<<"Writing fit histogrem file n. "<<j<<std::endl;
histoLineShape[j]->Write();
cFit->cd(j+1);
histoLineShape[j]->SetTitle(LegLabels[j]);
histoLineShape[j]->Draw();
histoLineShape[j]->GetXaxis()->SetTitle("M_{#mu#mu} (GeV)");
// TPaveText *cmsprel2 = new TPaveText(0.19, 0.95, 0.95, 0.99, "NDC");
// cmsprel2->SetTextSize(0.03);
// cmsprel2->SetTextFont(42);
// cmsprel2->SetFillColor(0);
// cmsprel2->SetBorderSize(0);
// cmsprel2->SetMargin(0.01);
// cmsprel2->SetTextAlign(12); // align left
// cmsprel2->AddText(0.666666, 0.5, LegLabels[j]);
}
}
ZFitFile->Close();
// cmsprel2->Draw("same");
cFit->SaveAs("ZFitFile.root");
return;
};
示例11: main
//.........这里部分代码省略.........
{
saveSimulationIntegration[j]->DoStraightStep();
}
else{
#ifdef Axial_
saveSimulationIntegration[j]->DoIntegrationStepAxialVelocityVerlet();
#else
saveSimulationIntegration[j]->DoIntegrationStepPlanarVelocityVerlet();
#endif
}
#else
#ifdef Axial_
saveSimulationIntegration[j]->DoIntegrationStepAxialVelocityVerlet();
#else
saveSimulationIntegration[j]->DoIntegrationStepPlanarVelocityVerlet();
#endif
#endif
#ifdef bMultipleScattering
saveMultipleScattering[j]->SetCrossedMaterialLength(saveSimulationIntegration[j]->GetStepLength());
saveMultipleScattering[j]->UpdateElectronScatteringOutgoingDistribution();
saveMultipleScattering[j]->DoElectronScatteringPlanar();
saveMultipleScattering[j]->UpdateNuclearScatteringOutgoingDistribution();
saveMultipleScattering[j]->DoNuclearScatteringPlanar();
#endif
saveOutgoingAngle[j] = saveParticle[j]->GetPositionVector()->GetZ()/saveStrip[j]->GetCurvatureRadius()->GetX();
#ifdef bSaveTrajectory
if(saveParticle[j]->GetPositionVector()->GetZ() > saveTrajPoint[j]*bSaveTrajectoryMinDistance){
#pragma omp critical
{
vOutAng = saveOutgoingAngle[j];
vOutPos = saveOutgoingPosition[j];
#ifdef bUndulator
vOutPos += saveUndulator[j]->GetOsculatorRadius()->GetX();
#endif
saveParticle[j]->PrintParticleOn(vPart);
saveStrip[j]->PrintStripOn(vStrip);
vTreeTraj->Fill();
saveTrajPoint[j]++;
fOutputTrajectory << i+j;
fOutputTrajectory << " " << - cos(vPart.z/vStrip.Rx) * (vStrip.Rx - (vPart.x + vOutPos)) + vStrip.Rx;
fOutputTrajectory << " " << vPart.y;
fOutputTrajectory << " " << sin(vPart.z/vStrip.Rx) * (vStrip.Rx - (vPart.x + vOutPos));
fOutputTrajectory << " " << vPart.px/vPart.pz + vOutAng;
fOutputTrajectory << " " << vPart.py/vPart.pz;
fOutputTrajectory << std::endl;
}
}
#endif
if(saveParticle[j]->GetPositionVector()->GetZ() > saveStrip[j]->GetDimension()->GetZ()) bIntegrationEnd[j] = true;
} while (bIntegrationEnd[j] != true);
saveParticle[j]->PrintParticleOn(saveParticleOutgoing[j]);
#pragma omp critical
{
vRadius = saveStripCurvatureRadius[j]->GetX();
vLength = saveStripDimension[j]->GetZ();
vOutAng = saveOutgoingAngle[j]/vLength;
vOutPos = saveOutgoingPosition[j];
ECHARM_Particle_Save_Copy(saveParticleIncoming[j],vPartIn);
ECHARM_Particle_Save_Copy(saveParticleOutgoing[j],vPartOut);
vTree->Fill();
#ifdef bSaveTrajectory
fOutputTrajectory << "***next_particle***" << std::endl;
#endif
}
}
#ifdef bPrintScreenNumberOfParticles
if(fmod(i+1,bPrintScreenNumberOfParticles)==0){
std::cout << " --- Time Elapsed (m): " << std::setw(10) << float(time(NULL) - vInitialTime)/60. << std::endl;
std::cout << " --- Time Left (m): " << std::setw(10) << (float(time(NULL) - vInitialTime)/(i)*(vNumberOfParticlesOMP) )/60. << std::endl;
}
#endif
}
vRootFile->Write(); // write ROOT file
vRootFile->Close(); // close ROOT file
vParameterFile.open(vParameterFileName.c_str(),std::fstream::app);
vParameterFile << "******************************" << std::endl;
vParameterFile << "******** Job Finished ********" << std::endl;
vParameterFile << "***** Total Elapsed Time *****" << std::endl;
vParameterFile << "******************************" << std::endl;
vParameterFile << "Time [m] = " << float(time(NULL) - vInitialTime)/60. << std::endl;
vParameterFile.close();
#ifdef bSaveTrajectory
fOutputTrajectory.close();
#endif
return 0;
}
示例12: drawQGFraction
//.........这里部分代码省略.........
//double xsecs[11] = {5.335E-01, 3.378E-02, 3.778E-03, 4.412E-04, 6.147E-05, 1.018E-05, 2.477E-06, 6.160E-07, 1.088E-07, 3.216E-08, 0}; //pythia6 5.02 tev weights
double xsecs[11] = {2.043e-01, 1.075E-02, 1.025E-03, 9.865E-05, 1.129E-05, 1.465E-06, 2.837E-07, 5.323E-08, 5.934e-09, 8.125e-10, 0}; //2.76 tev weights
int recalculatedEntries[10] = {0,0,0,0,0,0,0,0,0,0};
double pthatbins[11] = {15,30,50,80,120,170,220,280,370,460,9999};
TFile *fout = new TFile("QGFrac_pythia6_2p76TeV.root","recreate");
TH1D *quarkFracIncl = new TH1D("quarkFracIncl","",20,120,500); quarkFracIncl->Sumw2();
TH1D *glueFracIncl = new TH1D("glueFracIncl","",20,120,500); glueFracIncl->Sumw2();
TH1D *inclJets = new TH1D("inclJets","",20,120,500); inclJets->Sumw2();
TH1D *quarkFracLead = new TH1D("quarkFracLead","",20,120,500); quarkFracLead->Sumw2();
TH1D *glueFracLead = new TH1D("glueFracLead","",20,120,500); glueFracLead->Sumw2();
TH1D *leadJets = new TH1D("leadJets","",20,120,500); leadJets->Sumw2();
Int_t HBHENoiseFilterResultRun2Loose, pPAprimaryVertexFilter;
vector<float> *calo_corrpt=0, *calo_jtphi=0;
vector<int> *calo_refparton_flavor=0;
float pthat;
mix->SetBranchAddress("calo_corrpt",&calo_corrpt);
mix->SetBranchAddress("calo_jtphi",&calo_jtphi);
mix->SetBranchAddress("calo_refparton_flavor",&calo_refparton_flavor);
mix->SetBranchAddress("pthat",&pthat);
mix->SetBranchAddress("HBHENoiseFilterResultRun2Loose",&HBHENoiseFilterResultRun2Loose);
mix->SetBranchAddress("pPAprimaryVertexFilter",&pPAprimaryVertexFilter);
TH1D *pthatHisto = new TH1D("pthatHisto","",10,pthatbins);
mix->Project("pthatHisto","pthat");
for(int i=0; i<10; i++){
recalculatedEntries[i] = pthatHisto->GetBinContent(i+1);
cout << "entries between pthat " << pthatbins[i] << " and " << pthatbins[i+1] << ": " << recalculatedEntries[i] << endl;
cout << "weight: " << (xsecs[i]-xsecs[i+1])/recalculatedEntries[i] <<endl;
}
int totEntries = mix->GetEntries();
cout << "entries: "<< totEntries << endl;
totEntries=100000;
for(int ievt=0; ievt<totEntries; ievt++){
mix->GetEntry(ievt);
if(ievt && ievt%10000==0) cout << "entry: " << ievt << endl;
//if(!HBHENoiseFilterResultRun2Loose || !pPAprimaryVertexFilter) continue;
int ibin=0;
double weight=0.;
while(pthat>pthatbins[ibin]) ibin++;
ibin--;
weight = (xsecs[ibin]-xsecs[ibin+1])/recalculatedEntries[ibin];
if(weight>1){
cout << "xsec: "<< xsecs[ibin]-xsecs[ibin+1] << " entries: " << recalculatedEntries[ibin] << endl;
cout << "pthat: "<< pthat << " bin " << ibin << endl;
}
for(unsigned int ijet=0; ijet<calo_corrpt->size(); ijet++){
if(abs(calo_refparton_flavor->at(ijet))>0 && abs(calo_refparton_flavor->at(ijet))<6) quarkFracIncl->Fill(calo_corrpt->at(ijet), weight);
if(abs(calo_refparton_flavor->at(ijet))==21){ glueFracIncl->Fill(calo_corrpt->at(ijet), weight); }
inclJets->Fill(calo_corrpt->at(ijet), weight);
if(ijet==0 && calo_corrpt->size()>1){
double dphi = abs(calo_jtphi->at(0) - calo_jtphi->at(1));
if(dphi>(7*PI/8.) && dphi<(9*PI/8.) && calo_corrpt->at(1)>50) {
if(abs(calo_refparton_flavor->at(ijet))>0 && abs(calo_refparton_flavor->at(ijet))<6) quarkFracLead->Fill(calo_corrpt->at(ijet), weight);
if(abs(calo_refparton_flavor->at(ijet))==21) glueFracLead->Fill(calo_corrpt->at(ijet), weight);
leadJets->Fill(calo_corrpt->at(ijet), weight);
}
}
}
}
//quarkFracLead->Divide(leadJets);
//glueFracLead->Divide(leadJets);
//quarkFracIncl->Divide(inclJets);
//glueFracIncl->Divide(inclJets);
fout->cd();
formatHisto(quarkFracLead,1);
formatHisto(glueFracLead,2);
formatHisto(quarkFracIncl,4);
formatHisto(glueFracIncl,8);
quarkFracLead->Write();
glueFracLead->Write();
quarkFracIncl->Write();
glueFracIncl->Write();
leadJets->Write();
inclJets->Write();
fout->Close();
}
示例13: createCorrectedBackgroundModel
void createCorrectedBackgroundModel(std::string fileName, int nsidebands=6, bool makePlots=false, std::string defaultPrepend="CMS-HGG" ){
if (makePlots){
system("mkdir -p BMplots/ada");
system("mkdir -p BMplots/grad");
gStyle->SetPalette(1);
gStyle->SetOptStat(0);
}
global_nMassBins=nsidebands;
double massMin = 120;
double massMax = 130;
double dM = 0.1;
// Open the original Workspace
TFile *in = TFile::Open(fileName.c_str(),"UPDATE");
RooWorkspace *work = (RooWorkspace*)in->Get("cms_hgg_workspace");
std::string types[2]={"grad","ada"};
for (int ty=0;ty<2;ty++){
std::string type = types[ty];
// Create An output file for the TF1 Sideband Fits
std::string pathToFile=fileName.substr(0,fileName.find(defaultPrepend.c_str()));
std::string fName=fileName.substr(fileName.find(defaultPrepend.c_str()),fileName.size());
TFile *out = new TFile(Form("%sbdtSidebandFits_%s_%s",pathToFile.c_str(),type.c_str(),fName.c_str()),"RECREATE");
for (double mH=massMin;mH<=massMax;mH+=dM){
//TH1F *originalHist = (TH1F*) in->Get(Form("th1f_bkg_%s_%3.1f_cat0",type.c_str(),mH)); // This histogram is normalized to the inclusive fit (will not include VBF cat)
RooRealVar *nSignalVar = (RooRealVar*)work->var(Form("NBkgInSignal_mH%3.1f",mH));
TH1F *dataHist = (TH1F*) in->Get(Form("th1f_data_%s_%3.1f_cat0",type.c_str(),mH)); // Data Histogram, includes VBF category
int nBins = dataHist->GetNbinsX();
// Want to make a "corrected" histogram
TH1F *correctedHist = new TH1F(Form("th1f_bkg_%s_%3.1f_cat0_fitsb_biascorr",type.c_str(),mH),Form("th1f_bkg_%s_%3.1f_cat0_fitsb_biascorr",type.c_str(),mH),nBins,0,nBins);
TH1F *correctedHistFR = new TH1F(Form("th1f_bkg_%s_%3.1f_cat0_fitsb_biascorr_frac",type.c_str(),mH),Form("th1f_bkg_%s_%3.1f_cat0_fitsb_biascorr_frac",type.c_str(),mH),nBins,0,nBins);
TH2F *hFCovar=new TH2F(Form("fCovar_%3.1f",mH),
Form("Fraction covariance matrix m %3.1f",mH),
nBins,0.0,nBins,nBins,0.0,nBins);
TH2F *uCorrErr = new TH2F(Form("fUncorrErr_%s_%3.1f",type.c_str(),mH),
Form("Uncorrelated Errors m %3.1f",mH),
nBins,0.0,nBins,nBins,0.0,nBins);
TDirectory *mass_dir = out->mkdir(Form("mH_%3.1f",mH));
// For a given mass point, need to set up globals
global_nBdtBins=nBins;
global_mH=mH;
global_nSignalRegion=nSignalVar->getVal();
fillData(mH,in,type);
paulFit(mass_dir,correctedHistFR,correctedHist,hFCovar,makePlots,type);
// Finally Get the uncorrleated errors from the covariance matrix
diagonalizeMatrix(hFCovar,uCorrErr);
std::cout << "Final Check of Normalizations at mH="<<mH <<std::endl;
std::cout << "Original - "<< global_nSignalRegion << ", After - " <<correctedHist->Integral() <<std::endl;
// Write out the Hists into the original File
in->cd();
correctedHist->Write(correctedHist->GetName(),TObject::kOverwrite);
correctedHistFR->Write(correctedHistFR->GetName(),TObject::kOverwrite);
//hFCovar->Write();
uCorrErr->Write(uCorrErr->GetName(),TObject::kOverwrite);
out->cd();
mass_dir->cd();
uCorrErr->Write(uCorrErr->GetName(),TObject::kOverwrite);
if (makePlots){
TCanvas *canv = new TCanvas();
uCorrErr->SetMarkerColor(kGray);
gPad->SetRightMargin(2.);
uCorrErr->Draw("colz text");
canv->Print(Form("BMplots/%s/uncorrErr_m%3.1f.png",type.c_str(),mH));
canv->Print(Form("BMplots/%s/uncorrErr_m%3.1f.pdf",type.c_str(),mH));
}
}
std::cout << "Saving Fits to file -> " << out->GetName() << std::endl;
out->Close();
}
std::cout << "Updated (with corrected background model) -> " << in->GetName() << std::endl;
in->Close();
}
示例14: PlotDecisionBoundary
//.........这里部分代码省略.........
}
nentries = background->GetEntries();
for (Long64_t ib=0; ib<nentries;ib++) {
background->GetEntry(ib);
sum +=bWeight;
var0 = bvar0;
var1 = bvar1;
Float_t mvaVal=reader->EvaluateMVA( "MyMVAMethod" ) ;
hb->Fill(bvar0,bvar1);
mvaB->Fill(mvaVal,bWeight);
}
SeparationBase *sepGain = new MisClassificationError();
//SeparationBase *sepGain = new GiniIndex();
//SeparationBase *sepGain = new CrossEntropy();
Double_t sTot = mvaS->GetSum();
Double_t bTot = mvaB->GetSum();
mvaSC->SetBinContent(1,mvaS->GetBinContent(1));
mvaBC->SetBinContent(1,mvaB->GetBinContent(1));
Double_t sSel=mvaSC->GetBinContent(1);
Double_t bSel=mvaBC->GetBinContent(1);
Double_t sSelBest=0;
Double_t bSelBest=0;
Double_t separationGain=sepGain->GetSeparationGain(sSel,bSel,sTot,bTot);
Double_t mvaCut=mvaSC->GetBinCenter(1);
Double_t mvaCutOrientation=1; // 1 if mva > mvaCut --> Signal and -1 if mva < mvaCut (i.e. mva*-1 > mvaCut*-1) --> Signal
for (UInt_t ibin=2;ibin<nValBins;ibin++){
mvaSC->SetBinContent(ibin,mvaS->GetBinContent(ibin)+mvaSC->GetBinContent(ibin-1));
mvaBC->SetBinContent(ibin,mvaB->GetBinContent(ibin)+mvaBC->GetBinContent(ibin-1));
sSel=mvaSC->GetBinContent(ibin);
bSel=mvaBC->GetBinContent(ibin);
if (separationGain < sepGain->GetSeparationGain(sSel,bSel,sTot,bTot)){
separationGain = sepGain->GetSeparationGain(sSel,bSel,sTot,bTot);
mvaCut=mvaSC->GetBinCenter(ibin);
if (sSel/bSel > (sTot-sSel)/(bTot-bSel)) mvaCutOrientation=-1;
else mvaCutOrientation=1;
sSelBest=sSel;
bSelBest=bSel;
}
}
cout << "Min="<<MinMVA << " Max=" << MaxMVA
<< " sTot=" << sTot
<< " bTot=" << bTot
<< " sSel=" << sSelBest
<< " bSel=" << bSelBest
<< " sepGain="<<separationGain
<< " cut=" << mvaCut
<< " cutOrientation="<<mvaCutOrientation
<< endl;
delete reader;
gStyle->SetPalette(1);
plot(hs,hb,hist ,v0,v1,mvaCut);
TCanvas *cm=new TCanvas ("cm","",900,1200);
cm->cd();
cm->Divide(1,2);
cm->cd(1);
mvaS->SetLineColor(4);
mvaB->SetLineColor(2);
mvaS->Draw();
mvaB->Draw("same");
cm->cd(2);
mvaSC->SetLineColor(4);
mvaBC->SetLineColor(2);
mvaBC->Draw();
mvaSC->Draw("same");
// TH1F *add=(TH1F*)mvaBC->Clone("add");
// add->Add(mvaSC);
// add->Draw();
// errh->Draw("same");
//
// write histograms
//
TFile *target = new TFile( "TMVAPlotDecisionBoundary.root","RECREATE" );
hs->Write();
hb->Write();
hist->Write();
target->Close();
}
示例15: BfinderAna
//.........这里部分代码省略.........
//cout<<"-----"<<endl;
//printDa(GenInfo, mtk1idx, 1);
//cout<<"-----"<<endl;
//printDa(GenInfo, mtk1idx, 1);
//cout<<"Bmass: "<<BInfo->mass[j]<<endl;
BmassBpPi->Fill(BInfo->mass[j]);
}
else{
//printDa(GenInfo, mtk1idx, 1);
//cout<<"Bmass: "<<BInfo->mass[j]<<endl;
BmassBpXPi->Fill(BInfo->mass[j]);
}
}
}
//B+ to jpsi K
if(abs(GenInfo->pdgId[GenInfo->mo1[mmu1idx]]) == 521){
int bidx = GenInfo->mo1[mmu1idx];
int bda2idx = GenInfo->da2[bidx];
int bda2pdg = GenInfo->pdgId[bda2idx];
int tkancestor = getBAncestor(GenInfo, gtk1idx, 521);
/*
if(tkancestor != -1){
cout<<"tk1 pt: "<<GenInfo->pt[gtk1idx]<<endl;
cout<<"tk1anc: "<<tkancestor<<endl;
cout<<"tk1anc pdg: "<<GenInfo->pdgId[tkancestor]<<endl;
cout<<"bidx: "<<bidx<<endl;
printDa(GenInfo, tkancestor, 1);
}*/
if((abs(bda2pdg)/100)%100==3
&& abs(bda2pdg) != 321
){
//printDa(GenInfo, bidx, 1);
//cout<<"Bmass: "<<BInfo->mass[j]<<endl;
BmassBpK->Fill(BInfo->mass[j]);
if(tkancestor == bidx){
BmassBpK_tkmatch->Fill(BInfo->mass[j]);
}
else{BmassBpK_tknotmatch->Fill(BInfo->mass[j]);}
if(BtypeCountBpK.find(abs(bda2pdg)) == BtypeCountBpK.end()){
BtypeCountBpK[abs(bda2pdg)] = 1;
}
else{
BtypeCountBpK[abs(bda2pdg)] += 1;
}
}
}
//B0 to jpsi K
if(abs(GenInfo->pdgId[GenInfo->mo1[mmu1idx]]) == 511){
int bidx = GenInfo->mo1[mmu1idx];
int bda2idx = GenInfo->da2[bidx];
int bda2pdg = GenInfo->pdgId[bda2idx];
int tkancestor = getBAncestor(GenInfo, gtk1idx, 511);
if((abs(bda2pdg)/100)%100==3){
//printDa(GenInfo, bidx, 1);
//cout<<"Bmass: "<<BInfo->mass[j]<<endl;
BmassB0K->Fill(BInfo->mass[j]);
if(tkancestor == bidx){
BmassB0K_tkmatch->Fill(BInfo->mass[j]);
}
else{BmassB0K_tknotmatch->Fill(BInfo->mass[j]);}
if(BtypeCountB0K.find(abs(bda2pdg)) == BtypeCountB0K.end()){
BtypeCountB0K[abs(bda2pdg)] = 1;
}
else{
BtypeCountB0K[abs(bda2pdg)] += 1;
}
}
}
}
}
}
//
}
cout<<"Bp + K type count========="<<endl;
std::map<int,int>::iterator BtypeCountBpKIt;
for(BtypeCountBpKIt = BtypeCountBpK.begin(); BtypeCountBpKIt != BtypeCountBpK.end(); BtypeCountBpKIt++){
cout<<"Ktype: "<<BtypeCountBpKIt->first<<" Count: "<<BtypeCountBpKIt->second<<endl;
}
cout<<"B0 + K type count========="<<endl;
std::map<int,int>::iterator BtypeCountB0KIt;
for(BtypeCountB0KIt = BtypeCountB0K.begin(); BtypeCountB0KIt != BtypeCountB0K.end(); BtypeCountB0KIt++){
cout<<"Ktype: "<<BtypeCountB0KIt->first<<" Count: "<<BtypeCountB0KIt->second<<endl;
}
outf->Write();
cout<<"--- Writing finished"<<endl;
outf->Close();
cout<<"--- In/Output files"<<endl;
cout<<ifname<<endl;
cout<<outfile<<endl;
cout<<endl;
return 1;
}