本文整理汇总了C++中TNamed::Write方法的典型用法代码示例。如果您正苦于以下问题:C++ TNamed::Write方法的具体用法?C++ TNamed::Write怎么用?C++ TNamed::Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TNamed
的用法示例。
在下文中一共展示了TNamed::Write方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: execCreateAndMerge
void execCreateAndMerge() {
//--------------------------------------------------------------------------
for ( Int_t ifile = 0 ; ifile < 4 ; ifile++ ) {
TFile* outputFile = TFile::Open(Form("a_file_%d.root",ifile),"RECREATE");
TNamed* namedObj = new TNamed(Form("namedObj%d",ifile),Form("namedObj%d",ifile));
namedObj->Write();
outputFile->Close();
}
cout << "4 a files created" << endl;
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
for ( Int_t ifile = 0 ; ifile < 4 ; ifile++ ) {
TFile* outputFile = TFile::Open(Form("b_file_%d.root",ifile),"RECREATE");
TNamed* namedObj = new TNamed("namedObj","namedObj");
namedObj->Write();
outputFile->Close();
}
cout << "4 b files created" << endl;
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
TFileMerger* aMerger = new TFileMerger(kFALSE);
for ( Int_t ifile = 0 ; ifile < 4 ; ifile++ ) {
TFile* inFile = TFile::Open(Form("a_file_%d.root",ifile));
aMerger->AddFile(inFile);
}
aMerger->OutputFile("a_file.root");
aMerger->Merge();
cout << "4 a files merged" << endl;
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
TFileMerger* bMerger = new TFileMerger(kFALSE);
for ( Int_t ifile = 0 ; ifile < 4 ; ifile++ ) {
TFile* inFile = TFile::Open(Form("b_file_%d.root",ifile));
bMerger->AddFile(inFile);
}
bMerger->OutputFile("b_file.root");
bMerger->Merge();
cout << "4 b files merged" << endl;
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
TFile* inAFile = TFile::Open("a_file.root");
cout << "******* MERGED A FILE ******** 4 objects with different names" << endl;
inAFile->ls();
cout << "******************************" << endl;
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
TFile* inBFile = TFile::Open("b_file.root");
cout << "******* MERGED B FILE ******** 4 objects with the same names" << endl;
inBFile->ls();
cout << "******************************" << endl;
//--------------------------------------------------------------------------
}
示例2: saveSummaryLoop
void RootWImage::saveSummaryLoop(TPad* basePad, std::string baseName, TFile* myTargetFile) {
TList* aList;
TObject* anObject;
TPad* myPad;
std::string myClass;
std::string myName;
TNamed* aNamed;
// TSystemFile* aFile;
// string aFileName;
// string aFileNameTail;
// TFile* myRootFile;
aList = basePad->GetListOfPrimitives();
for (int i=0; i<aList->GetEntries(); ++i) {
anObject = aList->At(i);
myClass = anObject->ClassName();
if (myClass=="TPad") { // Go one step inside
myPad = (TPad*) anObject;
saveSummaryLoop(myPad, baseName, myTargetFile);
} else if (
(myClass=="TProfile") ||
(myClass=="TGraph") ||
(myClass=="TH1D") ||
(myClass=="TH2C") ||
(myClass=="TH2D") ||
(myClass=="THStack")
) {
aNamed = (TNamed*) anObject;
myTargetFile->cd();
myName = Form("%s.%s", baseName.c_str(), aNamed->GetName());
myName = RootWeb::cleanUpObjectName(myName);
aNamed->SetName(myName.c_str());
aNamed->Write();
} else if (
(myClass=="TEllipse") ||
(myClass=="TFrame") ||
(myClass=="TLatex") ||
(myClass=="TLegend") ||
(myClass=="TLine") ||
(myClass=="TPaveText") ||
(myClass=="TPolyLine") ||
(myClass=="TText")
) {
} else {
std::cerr << Form("Unhandled class %s", myClass.c_str()) << std::endl;
}
}
}
示例3: dumpObject
bool PlotManager::dumpObject(const string& objName,
const string& objTitle,
const string& srcObjName)
{
if ( ! isSetup_ ) return false;
// Push to base directory
string pwd(gDirectory->GetPath());
string newObjPath = dirname(objName);
string newObjName = basename(objName);
if ( newObjPath.empty() ) {
theOutFile_->cd();
}
else if ( theOutFile_->cd(newObjPath.c_str()) == kFALSE ) {
cout << "Cannot find dir, do mkdirs : " << newObjPath << endl;
mkdirs(theOutFile_, newObjPath)->cd();
}
TNamed* srcObj = dynamic_cast<TNamed*>(theSrcFile_->Get(srcObjName.c_str()));
if ( srcObj == NULL ) {
cerr << "Cannot get object : " << srcObjName << endl;
return false;
}
TNamed* saveObj = dynamic_cast<TNamed*>(srcObj->Clone(newObjName.c_str()));
saveObj->SetTitle(objTitle.c_str());
// Save histogram
saveObj->Write();
// Pop directory
gDirectory->cd(pwd.c_str());
return true;
}
示例4: studyBinZero
//.........这里部分代码省略.........
funcRatioVtxCutZ->SetLineWidth(2);
funcRatioVtxCutZ->SetLineColor(kRed);
const Double_t meanRatioVtxCutZ = funcRatioVtxCutZ->GetParameter(0);
const Double_t ratioNevtVtxCutZ = numEvtsTriggerSelVtxCutZ > 0 ? numEvtsTriggerSelVtxCut / numEvtsTriggerSelVtxCutZ : -1.;
TH1D* hRatioPileUp = new TH1D(*hSpectraTriggerSelVtxCutZPileUpRej);
hRatioPileUp->SetName("hRatioPileUp");
setupHist(hRatioPileUp, kBlack, "MB & vtx & #it{z} vtx & pile-up / MB & vtx & #it{z} vtx");
hRatioPileUp->GetYaxis()->SetTitle("1/#it{N}_{evt} d#it{N}/d#it{p}_{T}^{gen} ratio");
hRatioPileUp->Divide(hRatioPileUp, hSpectraTriggerSelVtxCutZ, 1., 1., "B");
/*
TF1* funcRatioPileUp = new TF1("funcRatioPileUp", "pol0",
0.15, hRatioPileUp->GetXaxis()->GetBinUpEdge(hSpectraTriggerSelVtxCutZPileUpRej->FindLastBinAbove(0)));
hRatioPileUp->Fit(funcRatioPileUp, "N");*/
ClearTitleFromHistoInCanvas(canvSpectra);
TCanvas* canvRatioVtx = new TCanvas("canvRatioVtx", "Ratio vertex", 760, 420);
canvRatioVtx->SetLogx();
canvRatioVtx->SetGrid(0, 1);
SetCanvasMargins(canvRatioVtx);
hRatioVtxCut->Draw();
funcRatioVtxCut->Draw("same");
TLegend* leg2 = new TLegend(0.22, 0.7, drawPileUp ? 0.87 : 0.72, 0.9);
leg2->SetHeader(Form("MC pp #sqrt{s}=7 TeV, inclusive, %s", etaRange.Data()));
leg2->AddEntry(hRatioVtxCut, "", "l");
SetupLegend(leg2);
leg2->SetMargin(0.1);
leg2->Draw("same");
ClearTitleFromHistoInCanvas(canvRatioVtx);
TCanvas* canvRatioOther = new TCanvas("canvRatioOther", "Ratio others", 760, 420);
canvRatioOther->SetLogx();
canvRatioOther->SetGrid(0, 1);
SetCanvasMargins(canvRatioOther);
hRatioVtxCutZ->Draw();
if (drawPileUp)
hRatioPileUp->Draw("same");
TLegend* leg3 = new TLegend(0.22, drawPileUp ? 0.63 : 0.7, drawPileUp ? 0.87 : 0.72, 0.9);
leg3->SetHeader(Form("MC pp #sqrt{s}=7 TeV, inclusive, %s", etaRange.Data()));
leg3->AddEntry(hRatioVtxCutZ, "", "l");
if (drawPileUp)
leg3->AddEntry(hRatioPileUp, "", "l");
SetupLegend(leg3);
leg3->SetMargin(0.1);
leg3->Draw("same");
ClearTitleFromHistoInCanvas(canvRatioOther);
printf("meanRatioVtxCut %f <-> ratioNevtVtxCut %f => meanRatioVtxCutZ/ratioNevtVtxCutZ - 1 = %f\nmeanRatioVtxCutZ %f <-> ratioNevtVtxCutZ %f\n",
meanRatioVtxCut, ratioNevtVtxCut, doubleRatioMinusOne, meanRatioVtxCutZ, ratioNevtVtxCutZ);
TNamed* settings = new TNamed(
Form("Settings: Data file \"%s\", lowerEta %.2f, uppEta %.2f, lowerCentrality %.3f, upperCentrality %.3f, doubleRatioMinusOne %.4f\n",
pathNameData.Data(), etaLow, etaUp, lowerCentrality, upperCentrality, doubleRatioMinusOne), "");
// Save results to file
TString saveFileName = pathNameData;
saveFileName = Form("%s_binZeroStudy.root", saveFileName.ReplaceAll(".root", "").Data());
TFile *saveFile = TFile::Open(saveFileName.Data(), "RECREATE");
saveFile->cd();
hSpectraTriggerSel->Write();
hSpectraTriggerSelVtxCut->Write();
hSpectraTriggerSelVtxCutZ->Write();
hSpectraTriggerSelVtxCutZPileUpRej->Write();
hRatioVtxCut->Write();
hRatioVtxCutZ->Write();
hRatioPileUp->Write();
funcRatioVtxCut->Write();
funcRatioVtxCutZ->Write();
canvSpectra->Write();
canvRatioVtx->Write();
canvRatioOther->Write();
settings->Write();
saveFile->Close();
TString temp = saveFileName;
canvRatioVtx->SaveAs(Form("%s", temp.ReplaceAll(".root", "_ratioVtx.pdf").Data()));
temp = saveFileName;
canvRatioOther->SaveAs(Form("%s", temp.ReplaceAll(".root", "_ratioOther.pdf").Data()));
PrintSettingsAxisRangeForMultiplicityAxisForMB();
return 0;
}
示例5: SaveInformation
/**
* Store some information on the output
*
* @param dir Where to store
* @param method Method used
* @param mId Method identifier
* @param regParam Regularization parameter
* @param sys Collision system
* @param sNN Center of mass energy
* @param trigger Trigger mask
* @param minIpZ Least z coordinate of interaction point
* @param maxIpZ Largest z coordinate of interaction point
* @param self Self-consistency check
*/
void SaveInformation(TDirectory* dir,
const TString& method,
Int_t mId,
Double_t regParam,
UShort_t sys,
UShort_t sNN,
UInt_t trigger,
Double_t minIpZ,
Double_t maxIpZ,
Bool_t self) const
{
dir->cd();
TParameter<bool>* pM = new TParameter<bool>("self", self);
pM->SetBit(BIT(19));
pM->Write();
TNamed* outMeth = new TNamed("method", method.Data());
outMeth->SetUniqueID(mId);
outMeth->Write();
TParameter<double>* pR = new TParameter<double>("regParam", regParam);
pR->SetBit(BIT(19));
pR->Write();
TString tS = (sys == 1 ? "pp" : sys == 2 ? "PbPb" : sys == 3 ? "pPb" : "?");
TNamed* pS = new TNamed("sys", tS.Data()); pS->SetUniqueID(sys);
pS->Write();
TString tE;
if (sNN < 1000) tE = Form("%dGeV", sNN);
else if (sNN < 3000) tE = Form("%4.2fTeV", float(sNN)/1000);
else tE = Form("%dTeV", sNN/1000);
TNamed* pE = new TNamed("sNN", tE.Data()); pE->SetUniqueID(sNN);
pE->Write();
TString tT;
/**
* Bits of the trigger pattern
*/
enum {
/** In-elastic collision */
kInel = 0x0001,
/** In-elastic collision with at least one SPD tracklet */
kInelGt0 = 0x0002,
/** Non-single diffractive collision */
kNSD = 0x0004,
/** Empty bunch crossing */
kEmpty = 0x0008,
/** A-side trigger */
kA = 0x0010,
/** B(arrel) trigger */
kB = 0x0020,
/** C-side trigger */
kC = 0x0080,
/** Empty trigger */
kE = 0x0100,
/** pileup from SPD */
kPileUp = 0x0200,
/** true NSD from MC */
kMCNSD = 0x0400,
/** Offline MB triggered */
kOffline = 0x0800,
/** At least one SPD cluster */
kNClusterGt0 = 0x1000,
/** V0-AND trigger */
kV0AND = 0x2000,
/** Satellite event */
kSatellite = 0x4000
};
if ((trigger & kInel) != 0x0) AppendAnd(tT, "INEL");
if ((trigger & kInelGt0) != 0x0) AppendAnd(tT, "INEL>0");
if ((trigger & kNSD) != 0x0) AppendAnd(tT, "NSD");
if ((trigger & kV0AND) != 0x0) AppendAnd(tT, "V0AND");
if ((trigger & kA) != 0x0) AppendAnd(tT, "A");
if ((trigger & kB) != 0x0) AppendAnd(tT, "B");
if ((trigger & kC) != 0x0) AppendAnd(tT, "C");
if ((trigger & kE) != 0x0) AppendAnd(tT, "E");
if ((trigger & kMCNSD) != 0x0) AppendAnd(tT, "MCNSD");
if ((trigger & kNClusterGt0) != 0x0) AppendAnd(tT, "NCluster>0");
if ((trigger & kSatellite) != 0x0) AppendAnd(tT, "Satellite");
TNamed* pT = new TNamed("trigger", tT.Data()); pT->SetUniqueID(trigger);
pT->Write();
TParameter<double>* pY = new TParameter<double>("minIpZ", minIpZ);
pY->SetBit(BIT(19));
//.........这里部分代码省略.........
示例6: main
//.........这里部分代码省略.........
try {
nameWeight = gConfigParser -> readStringOption("PU::nameWeight");
}
catch (char const* exceptionString){
std::cerr << " exception = " << exceptionString << std::endl;
}
std::cout << ">>>>> PU::nameWeight " << nameWeight << std::endl;
}
if (!doWeightFromFile) {
PUMC = gConfigParser -> readDoubleListOption("PU::PUMC");
PUDATA = gConfigParser -> readDoubleListOption("PU::PUDATA");
std::cout << " PUMC.size() = " << PUMC.size() << std::endl;
std::cout << " PUDATA.size() = " << PUDATA.size() << std::endl;
if (PUMC.size() != PUDATA.size()) {
std::cerr << " ERROR " << std::endl;
return 1;
}
for (int itVPU = 0; itVPU < PUMC.size(); itVPU++ ){
sumPUMC += PUMC.at(itVPU);
}
for (int itVPU = 0; itVPU < PUDATA.size(); itVPU++ ){
sumPUDATA += PUDATA.at(itVPU);
}
for (int itVPU = 0; itVPU < PUMC.size(); itVPU++ ){
PU.PUWeight.push_back(PUDATA.at(itVPU) / PUMC.at(itVPU) * sumPUMC / sumPUDATA);
}
PU.Write("autoWeight.cxx");
gROOT->ProcessLine(".L autoWeight.cxx");
///==== save PU distribution in TH1F ====
hPUMC = new TH1F("hPUMC","hPUMC",PUMC.size(),0,PUMC.size());
hPUDATA = new TH1F("hPUDATA","hPUDATA",PUDATA.size(),0,PUDATA.size());
hPUWeight = new TH1F("hPUWeight","hPUWeight",PUDATA.size(),0,PUDATA.size());
for (int itVPU = 0; itVPU < PUMC.size(); itVPU++ ){
hPUMC -> SetBinContent(itVPU+1,PUMC.at(itVPU) / sumPUMC);
hPUDATA -> SetBinContent(itVPU+1,PUDATA.at(itVPU) / sumPUDATA);
hPUWeight -> SetBinContent(itVPU+1,PUDATA.at(itVPU) / PUMC.at(itVPU) * sumPUMC / sumPUDATA);
}
}
///==== PU reweight (end) ====
///==== pT Higgs reweight (begin) ====
std::string nameptHWeight;
try {
nameptHWeight = gConfigParser -> readStringOption("Input::nameptHWeight");
}
catch (char const* exceptionString){
std::cerr << " exception = " << exceptionString << std::endl;
}
std::cout << ">>>>> input::nameptHWeight " << nameptHWeight << std::endl;
if (nameptHWeight != ""){
TString toLoad;
// toLoad = Form("cp %s ./",nameptHWeight.c_str());
// gROOT->ProcessLine(toLoad.Data());
toLoad = Form(".L %s",nameptHWeight.c_str());
gROOT->ProcessLine(toLoad.Data());
示例7: checkPullTree
//.........这里部分代码省略.........
for (Int_t i = 0, j = nThetaHistos; i < nThetaHistos + 1; i++, j--) {
canvPullCorr[i] = new TCanvas(Form("canvPullCorr_%d", i), "canvPullCorr", 100,10,1380,800);
canvPullCorr[i]->cd();
canvPullCorr[i]->SetLogx(kTRUE);
canvPullCorr[i]->SetLogz(kTRUE);
canvPullCorr[i]->SetGrid(kTRUE, kTRUE);
TH2D* hTemp = 0x0;
TString thetaString = "";
if (i == nThetaHistos) {
hTemp = hPullAdditionalCorr;
thetaString = "tan(#Theta) integrated";
}
else {
hTemp = hPullAdditionalCorrTheta[i];
thetaString = Form("%.2f #leq |tan(#Theta)| < %.2f", tThetaLow[i], tThetaHigh[i]);
}
normaliseHisto(hTemp);
hTemp->FitSlicesY();
hTemp->GetYaxis()->SetNdivisions(12);
hTemp->GetXaxis()->SetMoreLogLabels(kTRUE);
TH1D* hTempMean = (TH1D*)gDirectory->Get(Form("%s_1", hTemp->GetName()));
hTempMean->SetTitle(Form("mean(pull), %s", thetaString.Data()));
hTempMean->GetXaxis()->SetMoreLogLabels(kTRUE);
hTempMean->SetLineWidth(2);
hTempMean->SetMarkerStyle(20);
TH1D* hTempSigma = (TH1D*)gDirectory->Get(Form("%s_2", hTemp->GetName()));
hTempSigma->SetTitle(Form("#sigma(pull), %s", thetaString.Data()));
hTempSigma->GetXaxis()->SetMoreLogLabels(kTRUE);
hTempSigma->SetLineColor(kMagenta);
hTempSigma->SetMarkerStyle(20);
hTempSigma->SetMarkerColor(kMagenta);
hTempSigma->SetLineWidth(2);
TH1D* hTempChi2 = (TH1D*)gDirectory->Get(Form("%s_chi2", hTemp->GetName()));
hTempChi2->SetTitle(Form("#chi^{2} / NDF (pull), %s", thetaString.Data()));
hTempChi2->GetXaxis()->SetMoreLogLabels(kTRUE);
hTempChi2->SetLineColor(kMagenta + 2);
hTempChi2->SetMarkerStyle(20);
hTempChi2->SetMarkerColor(kMagenta + 2);
hTempChi2->SetLineWidth(2);
hTemp->DrawCopy("colz");
hTempMean->DrawCopy("same");
hTempSigma->DrawCopy("same");
hTempChi2->Scale(-1./10.);
hTempChi2->DrawCopy("same");
hTempChi2->Scale(-10.);
canvPullMeanCorr->cd();
hTempMean->SetLineColor(1 + ((j >= 9) ? (39 + 2 * (j - 9)) : j));
hTempMean->SetMarkerColor(1 + ((j >= 9) ? (39 + 2 * (j - 9)) : j));
hTempMean->DrawCopy((i == 0 ? "" : "same"));
canvPullSigmaCorr->cd();
hTempSigma->SetLineColor(1 + ((j >= 9) ? (39 + 2 * (j - 9)) : j));
hTempSigma->SetMarkerColor(1 + ((j >= 9) ? (39 + 2 * (j - 9)) : j));
hTempSigma->DrawCopy((i == 0 ? "" : "same"));
canvPullChi2Corr->cd();
hTempChi2->SetLineColor(1 + ((j >= 9) ? (39 + 2 * (j - 9)) : j));
hTempChi2->SetMarkerColor(1 + ((j >= 9) ? (39 + 2 * (j - 9)) : j));
hTempChi2->DrawCopy((i == 0 ? "" : "same"));
}
canvPullMeanCorr->BuildLegend();
canvPullSigmaCorr->BuildLegend();
canvPullChi2Corr->BuildLegend();
}
fSave->cd();
/*canvPullMean->Write();
canvPullSigma->Write();
canvPullChi2->Write();
for (Int_t i = 0; i < nThetaHistos + 1; i++) {
canvPull[i]->Write();
}*/
canvPullMeanCorr->Write();
canvPullSigmaCorr->Write();
canvPullChi2Corr->Write();
for (Int_t i = 0; i < nThetaHistos + 1; i++) {
canvPullCorr[i]->Write();
}
TNamed* info = new TNamed(Form("Theta map: %s\n\nSigma map: %s\n\nSplines file: %s\n\nSplines name: %s", pathNameThetaMap.Data(),
pathNameSigmaMap.Data(), pathNameSplinesFile.Data(), prSplinesName.Data()),
"info");
info->Write();
fSave->Close();
return 0;
}
示例8: extractPtResolution
//.........这里部分代码省略.........
upperJetPtBinLimit = hPtResolutionRaw[species]->GetAxis(kPtResJetPt)->FindBin(upperJetPt - 0.001);
// Check if the values look reasonable
if (lowerJetPtBinLimit <= upperJetPtBinLimit && lowerJetPtBinLimit >= 1 &&
upperJetPtBinLimit <= hPtResolutionRaw[species]->GetAxis(kPtResJetPt)->GetNbins()) {
actualLowerJetPt = hPtResolutionRaw[species]->GetAxis(kPtResJetPt)->GetBinLowEdge(lowerJetPtBinLimit);
actualUpperJetPt = hPtResolutionRaw[species]->GetAxis(kPtResJetPt)->GetBinUpEdge(upperJetPtBinLimit);
restrictJetPtAxis = kTRUE;
}
else {
std::cout << std::endl;
std::cout << "Requested jet pT range out of limits or upper and lower limit are switched!" << std::endl;
return -1;
}
}
std::cout << "jet pT: ";
if (restrictJetPtAxis) {
std::cout << actualLowerJetPt << " - " << actualUpperJetPt << std::endl;
hPtResolutionRaw[species]->GetAxis(kPtResJetPt)->SetRange(lowerJetPtBinLimit, upperJetPtBinLimit);
}
else {
std::cout << "All" << std::endl;
}
hPtResolution[species] = hPtResolutionRaw[species]->Projection(kPtResGenPt, kPtResRecPt, "e");
hPtResolution[species]->SetName(Form("hPtResolution_%s", AliPID::ParticleShortName(species)));
hPtResolution[species]->SetTitle(Form("%s", AliPID::ParticleLatexName(species)));
hPtResolution[species]->SetStats(kFALSE);
hPtResolution[species]->SetLineColor(getLineColorAliPID(species));
hPtResolution[species]->SetMarkerColor(getLineColorAliPID(species));
normaliseHist(hPtResolution[species]);
TObjArray aSlices;
hPtResolution[species]->FitSlicesY(0, 0, -1, 0, "QNR", &aSlices);
TH1D* hMean = (TH1D*)(aSlices.At(1));
TH1D* hSigma = (TH1D*)(aSlices.At(2));
hPtResolutionFit[species] = new TH1D(*hSigma);
hPtResolutionFit[species]->SetName(Form("hPtResolutionFit_%s", AliPID::ParticleShortName(species)));
hPtResolutionFit[species]->SetTitle(Form("%s", AliPID::ParticleLatexName(species)));
hPtResolutionFit[species]->SetLineColor(getLineColorAliPID(species));
hPtResolutionFit[species]->SetMarkerColor(getLineColorAliPID(species));
hPtResolutionFit[species]->Divide(hSigma, hMean);
}
// Save results to file
TString chargeString = "";
if (chargeMode == kPosCharge)
chargeString = "_posCharge";
else if (chargeMode == kNegCharge)
chargeString = "_negCharge";
TString saveFileName = pathNameData;
saveFileName.Replace(0, pathNameData.Last('/') + 1, "");
TString savePath = pathNameData;
savePath.ReplaceAll(Form("/%s", saveFileName.Data()), "");
saveFileName.Prepend("output_extractedPTResolution_");
TString centralityString = restrictCentrality ? Form("_centrality_%.0f_%.0f.root", actualLowerCentrality,
actualUpperCentrality)
: "_centrality_all";
TString jetPtString = restrictJetPtAxis ? Form("_jetPt_%.0f_%.0f.root", actualLowerJetPt, actualUpperJetPt)
: "";
saveFileName.ReplaceAll(".root", Form("%s%s%s.root", centralityString.Data(), jetPtString.Data(), chargeString.Data()));
TString saveFilePathName = Form("%s/%s", savePath.Data(), saveFileName.Data());
TFile* saveFile = TFile::Open(saveFilePathName.Data(), "RECREATE");
if (!saveFile) {
printf("Failed to save results to file \"%s\"!\n", saveFilePathName.Data());
return -1;
}
saveFile->cd();
for (Int_t species = 0; species < AliPID::kSPECIES; species++) {
if (hPtResolution[species])
hPtResolution[species]->Write();
if (hPtResolutionFit[species])
hPtResolutionFit[species]->Write();
}
TNamed* settings = new TNamed(
Form("Settings: Data file \"%s\", lowerCentrality %.3f, upperCentrality %.3f, lowerJetPt %.1f, upperJetPt %.1f\n",
pathNameData.Data(), lowerCentrality, upperCentrality, lowerJetPt, upperJetPt), "");
settings->Write();
saveFile->Close();
return 0;
}
示例9: main
//.........这里部分代码省略.........
titles.push_back(first_line.substr(index+1));
}
else{
std::stringstream stream;
if(i < 9){ stream << "line00" << i+1; }
else if(i < 99){ stream << "line0" << i+1; }
else{ stream << "line" << i+1; }
names.push_back(stream.str());
titles.push_back(first_line);
}
}
}
/*for(int i = 0; i < names.size(); i++){
char *cstr1 = new char[names[i].length()+1];
for(int j = 0; j < names[i].length(); j++){
cstr1[j] = names[i].at(j);
//std::cout << names[i][j] << "\t" << cstr1[j] << std::endl;
}
cstr1[names[i].length()] = '\0';
std::cout << names[i].length() << "\t" << strlen(cstr1) << std::endl;
printf("cstr1: %s\n", cstr1);
char *cstr2 = new char[titles[i].length()+1];
for(int j = 0; j < titles[i].length(); j++){
cstr2[j] = titles[i][j];
}
cstr2[titles[i].length()] = '\0';
delete[] cstr1;
delete[] cstr2;
}*/
// Get the number of columns
std::getline(input_file, first_line);
if(input_file.eof() || !input_file.good()){
input_file.close();
output_file->Close();
return 1;
}
std::vector<std::string> column_names;
num_columns = count_columns(first_line, column_names, delimiter);
std::cout << " Found " << num_columns << " columns of data\n";
std::string bname;
float *vars = new float[num_columns];
for(int i = 0; i < num_columns; i++){
vars[i] = 0.0;
}
if(!use_column_names){
input_file.seekg(-first_line.size(), std::ios::cur);
for(int i = 0; i < num_columns; i++){
std::stringstream stream;
if(i < 10){ stream << "Col0" << i; }
else{ stream << "Col" << i; }
tree->Branch(stream.str().c_str(),&vars[i]);
}
}
else{ // Extract column names from data
for(int i = 0; i < num_columns; i++){
tree->Branch(column_names[i].c_str(),&vars[i]);
}
}
while(true){
// Get a line of data
if(count % 10000 == 0 && count != 0){ std::cout << " Line " << count << " of data file\n"; }
if(count+1 <= last_skip_line && is_in(skip_lines, ++count)){ continue; }
for(int i = 0; i < num_columns; i++){
input_file >> vars[i];
}
if(input_file.eof() || !input_file.good()){ break; }
// Fill all branches
tree->Fill();
count++;
}
output_file->cd();
TNamed *named = new TNamed();
std::vector<std::string>::iterator iter1, iter2;
for(iter1 = names.begin(), iter2 = titles.begin(); iter1 != names.end() && iter2 != titles.end(); iter1++, iter2++){
named->SetNameTitle(iter1->c_str(), iter2->c_str());
named->Write();
}
tree->Write();
std::cout << " Found " << count << " entries in " << num_columns << " columns\n";
std::cout << " Generated file " << fname << ".root\n";
input_file.close();
output_file->Close();
delete[] vars;
return 0;
}