本文整理汇总了C++中TObject::GetName方法的典型用法代码示例。如果您正苦于以下问题:C++ TObject::GetName方法的具体用法?C++ TObject::GetName怎么用?C++ TObject::GetName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TObject
的用法示例。
在下文中一共展示了TObject::GetName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: log
//-----------------------------------------------------------------------------
StatusCode
RootHistCnv::RDirectoryCnv::fillObjRefs(IOpaqueAddress* pAddr,DataObject* pObj) {
MsgStream log(msgSvc(), "RDirectoryCnv");
IRegistry* pReg = pObj->registry();
std::string full = pReg->identifier();
const std::string& fname = pAddr->par()[0];
TFile *tf;
findTFile(full,tf).ignore();
// cd to TFile:
setDirectory(full);
TIter nextkey(gDirectory->GetListOfKeys());
while (TKey *key = (TKey*)nextkey()) {
IOpaqueAddress* pA = 0;
TObject *obj = key->ReadObj();
std::string title = obj->GetTitle();
std::string sid = obj->GetName();
std::string f2 = full + "/" + sid;
int idh = ::strtol(sid.c_str(),NULL,10);
// introduced by Grigori Rybkine
std::string clname = key->GetClassName();
std::string clnm = clname.substr(0,3);
TClass* isa = obj->IsA();
if (isa->InheritsFrom("TTree")) {
createAddress(full, CLID_ColumnWiseTuple, idh, obj, pA).ignore();
TTree* tree = (TTree*) obj;
tree->Print();
log << MSG::DEBUG << "Reg CWNT \"" << obj->GetTitle()
<< "\" as " << f2 << endmsg;
title = "/" + sid;
} else if (isa->InheritsFrom("TDirectory")) {
createAddress(full,CLID_NTupleDirectory, title, obj, pA).ignore();
} else if ( isa == TProfile::Class() ) {
createAddress(full,CLID_ProfileH,idh,obj,pA).ignore();
title = sid;
} else if ( isa == TProfile2D::Class() ) {
createAddress(full,CLID_ProfileH2,idh,obj,pA).ignore();
title = sid;
} else if ( isa == TH1C::Class() ) {
createAddress(full,CLID_H1D,idh,obj,pA).ignore();
title = sid;
} else if ( isa == TH1S::Class() ) {
createAddress(full,CLID_H1D,idh,obj,pA).ignore();
title = sid;
} else if ( isa == TH1I::Class() ) {
createAddress(full,CLID_H1D,idh,obj,pA).ignore();
title = sid;
} else if ( isa == TH1F::Class() ) {
createAddress(full,CLID_H1D,idh,obj,pA).ignore();
title = sid;
} else if ( isa == TH1D::Class() ) {
createAddress(full,CLID_H1D,idh,obj,pA).ignore();
title = sid;
} else if ( isa == TH2C::Class() ) {
createAddress(full,CLID_H2D,idh,obj,pA).ignore();
title = sid;
} else if ( isa == TH2S::Class() ) {
createAddress(full,CLID_H2D,idh,obj,pA).ignore();
title = sid;
} else if ( isa == TH2I::Class() ) {
createAddress(full,CLID_H2D,idh,obj,pA).ignore();
title = sid;
} else if ( isa == TH2F::Class() ) {
createAddress(full,CLID_H2D,idh,obj,pA).ignore();
title = sid;
} else if ( isa == TH2D::Class() ) {
createAddress(full,CLID_H2D,idh,obj,pA).ignore();
title = sid;
} else if ( isa == TH3C::Class() ) {
createAddress(full,CLID_H3D,idh,obj,pA).ignore();
title = sid;
} else if ( isa == TH3S::Class() ) {
createAddress(full,CLID_H3D,idh,obj,pA).ignore();
title = sid;
} else if ( isa == TH3I::Class() ) {
createAddress(full,CLID_H3D,idh,obj,pA).ignore();
title = sid;
} else if ( isa == TH3F::Class() ) {
createAddress(full,CLID_H3D,idh,obj,pA).ignore();
title = sid;
} else if ( isa == TH3D::Class() ) {
createAddress(full,CLID_H3D,idh,obj,pA).ignore();
title = sid;
} else {
log << MSG::ERROR << "Encountered an unknown object with key: "
<< obj->GetName() << " in ROOT file " << fname << endmsg;
return StatusCode::FAILURE;
}
if ( 0 != pA ) {
StatusCode sc = dataManager()->registerAddress(pReg, title, pA);
if ( !sc.isSuccess() ) {
log << MSG::ERROR << "Failed to register address for " << full << endmsg;
return sc;
}
log << MSG::VERBOSE << "Created address for " << clnm
<< "'" << title << "' in " << full << endmsg;
}
}
//.........这里部分代码省略.........
示例2: alice_esd_split
//______________________________________________________________________________
void alice_esd_split(Bool_t auto_size=kFALSE)
{
// Main function, initializes the application.
//
// 1. Load the auto-generated library holding ESD classes and ESD dictionaries.
// 2. Open ESD data-files.
// 3. Load cartoon geometry.
// 4. Spawn simple GUI.
// 5. Load first event.
TFile::SetCacheFileDir(".");
if (!alice_esd_loadlib(esd_file_name, "aliesd"))
{
Error("alice_esd", "Can not load project libraries.");
return;
}
printf("*** Opening ESD ***\n");
esd_file = TFile::Open(esd_file_name, "CACHEREAD");
if (!esd_file)
return;
printf("*** Opening ESD-friends ***\n");
esd_friends_file = TFile::Open(esd_friends_file_name, "CACHEREAD");
if (!esd_friends_file)
return;
esd_tree = (TTree*) esd_file->Get("esdTree");
esd = (AliESDEvent*) esd_tree->GetUserInfo()->FindObject("AliESDEvent");
// Set the branch addresses.
{
TIter next(esd->fESDObjects);
TObject *el;
while ((el=(TNamed*)next()))
{
TString bname(el->GetName());
if(bname.CompareTo("AliESDfriend")==0)
{
// AliESDfriend needs some '.' magick.
esd_tree->SetBranchAddress("ESDfriend.", esd->fESDObjects->GetObjectRef(el));
}
else
{
esd_tree->SetBranchAddress(bname, esd->fESDObjects->GetObjectRef(el));
}
}
}
TEveManager::Create();
// Adapt the main frame to the screen size...
if (auto_size)
{
Int_t qq;
UInt_t ww, hh;
gVirtualX->GetWindowSize(gVirtualX->GetDefaultRootWindow(), qq, qq, ww, hh);
Float_t screen_ratio = (Float_t)ww/(Float_t)hh;
if (screen_ratio > 1.5) {
gEve->GetBrowser()->MoveResize(100, 50, ww - 300, hh - 100);
} else {
gEve->GetBrowser()->Move(50, 50);
}
}
{ // Simple geometry
TFile* geom = TFile::Open(esd_geom_file_name, "CACHEREAD");
if (!geom)
return;
TEveGeoShapeExtract* gse = (TEveGeoShapeExtract*) geom->Get("Gentle");
gGeoShape = TEveGeoShape::ImportShapeExtract(gse, 0);
geom->Close();
delete geom;
gEve->AddGlobalElement(gGeoShape);
}
make_gui();
// import the geometry in the projection managers
if (gRPhiMgr) {
TEveProjectionAxes* a = new TEveProjectionAxes(gRPhiMgr);
a->SetNdivisions(3);
gEve->GetScenes()->FindChild("R-Phi Projection")->AddElement(a);
gRPhiMgr->ImportElements(gGeoShape);
}
if (gRhoZMgr) {
TEveProjectionAxes* a = new TEveProjectionAxes(gRhoZMgr);
a->SetNdivisions(3);
gEve->GetScenes()->FindChild("Rho-Z Projection")->AddElement(a);
gRhoZMgr->ImportElements(gGeoShape);
}
load_event();
update_projections();
gEve->Redraw3D(kTRUE); // Reset camera after the first event has been shown.
//.........这里部分代码省略.........
示例3: nextkey
void
//Impose (TDirectory * target, TList * sourcelist, string & np_title_, vector<string> titles,vector<float> xsecs)
Impose (TList * sourcelist, string & np_title_, vector<string> titles,vector<float> xsecs, TString &variable)
{
cout << " " << "========================================================" << endl;
cout << " " << "This is a macro to superimpose plots of different root files." << endl;
cout << " " << "Only TH2Dobjects are superimposed." << endl;
float Lumi=1;
Lumi = 15939.;
bool norm_=false;
int MaxEventsBin = 10;
cout<<titles[0]<<" "<<titles.size()<<endl;
//not really useful if plots already weighted to lumi - usefull is plots are in a.u.
vector <float > lumiweights;
lumiweights.clear();
// for (unsigned int kk=0; kk<signal_names.size();kk++){
// cout<<" HERE is some signal =============================================== "<<signal_names[kk]<<" "<<signalnames[kk]<<endl;
// }
TH2D* allbkg, *htt,*hstop,*hwj,*hdyj,*hrare,*hdib,*hqcd,*httx, *hrest;
TFile *first_source = (TFile *) sourcelist->First ();
first_source->cd ("muel");
TH1D* eventCount = (TH1D*)first_source->Get("muel/histWeightsH");
//TH1D* eventCount = (TH1D*)first_source->Get("muel/inputEventsH");
//TH1D* hxsec = (TH1D*)first_source->Get("muel/xsec");
float nGen = eventCount->GetSumOfWeights();
float xsec = 1;//hxsec->GetMean();
float norm = xsec*Lumi/nGen;
norm =1;
lumiweights.push_back(float(norm));
//cout<< " for first source file, there where "<<nGen<<" events with xsec "<<xsec<<" weight "<<lumiweights[0]<<endl;//" weight "<<float(xsec*Lumi/nGen)<<" norm "<<norm<<endl;
TDirectory *current_sourcedir = gDirectory;
//gain time, do not add the objects in the list in memory
Bool_t status = TH1::AddDirectoryStatus ();
TH1::AddDirectory (kFALSE);
// loop over all keys in this directory
TChain *globChain = 0;
TIter nextkey (current_sourcedir->GetListOfKeys ());
//TIter nextkey (((TDirectory *) current_sourcedir->Get ("ana"))->GetListOfKeys ());
TKey *key, *oldkey = 0;
while ((key = (TKey *) nextkey ())) {
//variable="met_MTsum_16";
int count=0;
count++;
//if (count>20) break;
//keep only the highest cycle number for each key
// if (oldkey && !strcmp (oldkey->GetName (), key->GetName ()))
// continue;
// read object from first source file and create a canvas
// first_source->cd (path);
first_source->cd ("muel");
TObject *obj = key->ReadObj ();
//string nn = obj->GetName();
// if (std::string::npos == nn.find("Cut")) continue;
//cout<<obj->GetName()<<endl;
string nn = obj->GetName();
bool flcont = true;
bool NormTT = false;
if (string::npos != nn.find("_9") || string::npos != nn.find("_10") || string::npos != nn.find("_11") || string::npos != nn.find("_12") || string::npos != nn.find("_13") || string::npos != nn.find("_14") || string::npos != nn.find("_15") || string::npos != nn.find("_16") || string::npos != nn.find("_17") || string::npos != nn.find("_18") || string::npos != nn.find("_19")) NormTT = true;
//if ( string::npos != nn.find("_11") || string::npos != nn.find("_12") || string::npos != nn.find("_13") || string::npos != nn.find("_14")) NormTT = true;
NormTT=true;
//if ( string::npos == nn.find("CutFlowUnW")) flcont=false;
//if (string::npos == nn.find(""+variable) ) flcont=false;
if (string::npos == nn.find(variable) ) continue;
// if (!flcont) continue;
if (obj->IsA ()->InheritsFrom ("TTree") ) continue;
// if (obj->IsA ()->InheritsFrom ("TH1") ) continue;
if (obj->IsA ()->InheritsFrom ("TH2") ) {
cout<<"=================================================== OK for variable "<<variable<<endl;
TH2D* hh[1500];
TH2D* hsignal[1500];
TH2D* h1 = (TH2D*) obj;
ModifyHist (h1,1,Lumi,lumiweights[0],titles[0],norm_);
TFile *nextsource = (TFile *) sourcelist->After (first_source);
int cl, countsignal;
h1->SetStats(000000);
cl=1;
countsignal=1;
hh[cl]=h1;
//.........这里部分代码省略.........
示例4: DrawComparisonXSecSyst
void DrawComparisonXSecSyst(void){
struct STestFunctor {
bool operator()(TObject *aObj) {
cout<<aObj->GetTitle()<<endl;
//cout<<"pippo"<<endl;
//comparisonJetMCData(aObj->GetTitle,1);
return true;
}
};
treeBKG_->Branch("bckg_leadingJetPt",&bckg_leadingJetPt);
treeBKG_->Branch("bckg_2leadingJetPt",&bckg_2leadingJetPt);
treeBKG_->Branch("bckg_3leadingJetPt",&bckg_3leadingJetPt);
treeBKG_->Branch("bckg_4leadingJetPt",&bckg_4leadingJetPt);
treeBKG_->Branch("bckg_JetMultiplicity",&bckg_JetMultiplicity);
gROOT->Reset();
gROOT->ForceStyle();
gROOT->LoadMacro("tdrStyle.C++");
tdrStyle();
// Recupero l'informazione sul numero di eventi processati per singolo MC
dataNumEvents = numEventsPerStep(datafile, "demo");
zNumEvents = numEventsPerStep(mcfile, "demo");
ttNumEvents = numEventsPerStep(back_ttbar, "demo");
wNumEvents = numEventsPerStep(back_w, "demo");
wzEvents = numEventsPerStep(WZ, "demo");
zzEvents = numEventsPerStep(ZZ, "demo");
wwEvents = numEventsPerStep(WW, "demo");
// ---------------------------------------------------
string direc="/gpfs/cms/data/2011/Observables/";
//string direc=plotpath;
if (isAngularAnalysis){
mcfile=direc+"MC_zjets"+version;
back_w=direc+"MC_wjets"+version;
back_ttbar=direc+"MC_ttbar"+version;
WW=direc+"MC_diW"+version;
ZZ=direc+"MC_siZ"+version;
WZ=direc+"MC_diWZ"+version;
datafile=direc+"DATA"+version;
}
TFile *mcf = TFile::Open(mcfile.c_str()); //MC file
mcf->cd("validationJEC/");
TDirectory *dir=gDirectory;
TList *mylist=(TList*)dir->GetListOfKeys();
TIter iter(mylist);
// Use TIter::Next() to get each TObject mom owns.
TObject* tobj = 0;
string tmpname;
// input and output files
string FileName(outfilename);
//FileName += ".root";
OutputFile = TFile::Open(FileName.c_str() , "RECREATE" ) ;
int i=0; // solo di servizio quando debuggo...
while ( (tobj = iter.Next()) ) {
gROOT->Reset();
gROOT->ForceStyle();
tdrStyle();
gStyle->SetPadRightMargin(0.15);
string name=tobj->GetName();
TString temp = (TString)name;
//int num=tobj->GetUniqueID();
if(temp.Contains("weight")){
mcf = TFile::Open(mcfile.c_str());
TFile *ttbarf = TFile::Open(back_ttbar.c_str());
TFile *wf = TFile::Open(back_w.c_str());
TFile *wzf = TFile::Open(WZ.c_str());
TFile *zzf = TFile::Open(ZZ.c_str());
TFile *wwf = TFile::Open(WW.c_str());
TCanvas * Canvweight = new TCanvas("Canvweight","Canvweight",0,0,800,600);
//if (Canv) delete Canv;
//Canv = new TCanvas("Canv","Canv",0,0,800,600);
gPad->SetLogy(1);
//---- weights
mcf->cd("validationJEC");
TH1F* mc;
gDirectory->GetObject(name.c_str(),mc);
if(mc){
mc->SetFillColor(kRed);
mc->GetXaxis()->SetRangeUser(0.,12.);
mc->SetMinimum(1.);
mc->Draw();
zwemean = mc->GetMean();
tmpname=plotpath+name+"-zjets.png";
Canvweight->Print(tmpname.c_str());
}
//---- weights
//.........这里部分代码省略.........
示例5: browseStacks
void browseStacks( bool makePictures=false, bool wait=true , bool addHistName = false, Double_t maxYScaleF = 1.,
bool logScale = false, bool setMinZero = true) {
gStyle->SetOptTitle(0);
bool keep2D=false;
//fix the hNJet histos
TList *list = gDirectory->GetList();
TIterator *iter = list->MakeIterator();
TObject *obj = 0;
while(obj = iter->Next()) {
if(TString(obj->GetName()).Contains("hnJet") && obj->InheritsFrom(TH1::Class())) {
int nbins = ((TH1F*)obj)->GetNbinsX();
float overflow = ((TH1F*)obj)->GetBinContent(nbins+1);
float lastbinval = ((TH1F*)obj)->GetBinContent(nbins);
((TH1F*)obj)->SetBinContent(nbins, overflow+lastbinval);
((TH1F*)obj)->GetXaxis()->SetBinLabel(nbins, "#geq4");
}
}
// Find out what the names of the existing histograms are
// The histogram names are XX_YY_ZZ, where XX is the sample,
// eg, "tt", YY is the actual name, ZZ is the final state, eg, "ee"
TObjArray* myNames = getMyHistosNames("ttdil","ee",keep2D);
// Now loop over histograms, and make stacks
TCanvas *c = new TCanvas();
c->Divide(2,2);
char* suffix[4];
suffix[0] = "ee";
suffix[1] = "mm";
suffix[2] = "em";
suffix[3] = "all";
if (makePictures) c->Print("out/stacks.ps[");
for (int i=0; i<myNames->GetEntries(); i++) {
for (int sample=0; sample<4; sample++) {
hist::stack(Form("st_%s_%s",myNames->At(i)->GetName(),suffix[sample]),
Form("%s_%s$",myNames->At(i)->GetName(), suffix[sample]));
THStack* thisStack = (THStack*) gROOT->FindObjectAny(
Form("st_%s_%s", myNames->At(i)->GetName(), suffix[sample]));
thisStack->SetMaximum(thisStack->GetMaximum()*maxYScaleF);
if(TString(myNames->At(i)->GetName()).Contains("hnJet")) {
TList* histolist = thisStack->GetHists();
int hatchcount = 0;
// for(int j = 0; j<histolist->GetSize();j++) {
// if(TString(histolist->At(j)->GetName()).Contains("tt") ||
// TString(histolist->At(j)->GetName()).Contains("tautau") ||
// TString(histolist->At(j)->GetName()).Contains("ww") ) continue;
// hatch(histolist->At(j)->GetName(), FavoriteHatches[hatchcount]);
// hatchcount++;
// }
}
TLegend* thisLeg = hist::legend(thisStack, "lpf", 0, 0, 0.75, 0.65, 0.99, 0.99);
c->cd(sample+1);
if (logScale) gPad->SetLogy(); else gPad->SetLogy(0);
double stackMax = ((TH1*)thisStack->GetHists()->At(0))->GetMaximum();
double stackMin = ((TH1*)thisStack->GetHists()->At(0))->GetMinimum();
thisStack->SetMinimum(stackMin);
if (setMinZero) thisStack->SetMinimum(0);
if (logScale && stackMin <=0) thisStack->SetMinimum(1e-2*stackMax);
if (logScale && stackMax == 0) thisStack->SetMinimum(1e-12);
thisStack->Draw("hist");
string xtitle( ((TH1*)gROOT->FindObjectAny(Form("ttdil_%s_%s", myNames->At(i)->GetName(), suffix[sample])))->GetXaxis()->GetTitle());
string ytitle( ((TH1*)gROOT->FindObjectAny(Form("ttdil_%s_%s", myNames->At(i)->GetName(), suffix[sample])))->GetYaxis()->GetTitle());
thisStack->GetXaxis()->SetTitle(xtitle.c_str());
thisStack->GetYaxis()->SetTitle(ytitle.c_str());
TString hname = thisStack->GetName();
if(hname.Contains("hnJet")) {
thisStack->GetXaxis()->SetLabelSize(0.075);
thisStack->GetYaxis()->SetLabelSize(0.05);
thisStack->GetXaxis()->SetTitle("N_{jets}");
}
thisLeg->Draw();
TPaveText *pt1 = new TPaveText(0.1, 0.95, 0.4, 0.999, "brNDC");
pt1->SetName("pt1name");
pt1->SetBorderSize(0);
pt1->SetFillStyle(0);
TText *blah;
if (addHistName) blah = pt1->AddText(hname);
else blah = pt1->AddText("CMS Preliminary");
blah->SetTextSize(0.05);
pt1->Draw();
c->Modified();
//.........这里部分代码省略.........
示例6: plotGlobalWeightedEvts_Kpipi
/*
* this script takes 2 TStrings as root filenames as a parameters
* basic functionality:
* loop through all directories (the mass bins) in the root file
* -> create difference plots
* -> create global plots
* -> create 2D diff vs mass plots
* -> etc...
*/
void plotGlobalWeightedEvts_Kpipi(TString input_filename, TString output_filename) {
setupBookies();
gROOT->SetStyle("Plain");
gStyle->SetTitleFont(10*13+2,"xyz");
gStyle->SetTitleSize(0.06, "xyz");
gStyle->SetTitleOffset(1.3,"y");
gStyle->SetTitleOffset(1.3,"z");
gStyle->SetLabelFont(10*13+2,"xyz");
gStyle->SetLabelSize(0.06,"xyz");
gStyle->SetLabelOffset(0.009,"xyz");
gStyle->SetPadBottomMargin(0.16);
gStyle->SetPadTopMargin(0.16);
gStyle->SetPadLeftMargin(0.16);
gStyle->SetPadRightMargin(0.16);
gStyle->SetOptTitle(0);
gStyle->SetOptStat(0);
gROOT->ForceStyle();
gStyle->SetFrameFillColor(0);
gStyle->SetFrameFillStyle(0);
TGaxis::SetMaxDigits(3);
//IsPhDStyle = true;
int massbins =0;
double mass= 0.0, massstart =1000.0, massend=0.0;
std::map<std::string, std::pair<double, std::pair<double, double> > > diffbounds;
TFile* infile = TFile::Open(input_filename, "READ");
TFile* outfile = new TFile(output_filename, "RECREATE");
outfile->mkdir("global");
TList *dirlist = infile->GetListOfKeys();
massbins = dirlist->GetSize();
infile->cd();
TIter diriter(dirlist);
TDirectory *dir;
std::cout<< "scanning directories and creating overview canvases..." <<std::endl;
while ((dir = (TDirectory *)diriter())) {
std::string dirname = dir->GetName();
// check if directory is mass bin dir
unsigned int pointpos = dirname.find(".");
if(pointpos == 0 || pointpos == dirname.size()) continue;
std::string masslow = dirname.substr(0, pointpos+1);
std::string masshigh = dirname.substr(pointpos+1);
double massstarttemp = atof(masslow.c_str())/1000;
double massendtemp = atof(masshigh.c_str())/1000;
if((int)(massendtemp - massstarttemp) != massbinwidth)
massbinwidth = (int)(massendtemp - massstarttemp);
mass = (massstarttemp + massendtemp)/2;
if(massstart > massstarttemp) massstart = massstarttemp;
if(massend < massendtemp) massend = massendtemp;
outfile->cd();
outfile->mkdir(dir->GetName());
infile->cd(dir->GetName());
// make list of MC Histograms
TList mclist;
TList *histlist = gDirectory->GetListOfKeys();
TIter histiter(histlist);
TObject *obj;
while ((obj = histiter())) {
TString s(obj->GetName());
if(s.EndsWith("MC"))
mclist.Add(obj);
else if(s.Contains("MC_"))
mclist.Add(obj);
}
make1DOverviewCanvas(infile, outfile, &mclist, dirname);
histiter = TIter(&mclist);
TH1D *diffhist, *mchist;
while ((mchist = (TH1D*)histiter())) {
// generate difference histograms
std::string hnamemc(mchist->GetName());
// create new string with MC exchanged for Diff
std::string hnamediff(hnamemc);
int pos = hnamemc.find("MC");
hnamediff.erase(pos, 2);
hnamediff.insert(pos, "Diff");
infile->GetObject((std::string(dir->GetName())+"/"+hnamediff).c_str(), diffhist);
if (diffhist) {
// get diff min max values
std::pair<double, std::pair<double, double> > p;
bool change =false;
double maxdiff = diffhist->GetMaximum();
double maxdifftemp = diffhist->GetMinimum();
if(abs(maxdifftemp) > maxdiff) maxdiff = maxdifftemp;
//.........这里部分代码省略.........
示例7: alice_esd
//______________________________________________________________________________
void alice_esd()
{
// Main function, initializes the application.
//
// 1. Load the auto-generated library holding ESD classes and
// ESD dictionaries.
// 2. Open ESD data-files.
// 3. Load cartoon geometry.
// 4. Spawn simple GUI.
// 5. Load first event.
const TString weh("alice_esd()");
if (gROOT->LoadMacro("MultiView.C+") != 0)
{
Error(weh, "Failed loading MultiView.C in compiled mode.");
return;
}
TFile::SetCacheFileDir(".");
if (!alice_esd_loadlib("aliesd"))
{
Error("alice_esd", "Can not load project libraries.");
return;
}
printf("*** Opening ESD ***\n");
esd_file = TFile::Open(esd_file_name, "CACHEREAD");
if (!esd_file)
return;
esd_tree = (TTree*) esd_file->Get("esdTree");
esd = (AliESDEvent*) esd_tree->GetUserInfo()->FindObject("AliESDEvent");
esd_objs = esd->fESDObjects;
if (esd_friends_file_name != 0)
{
printf("*** Opening ESD-friends ***\n");
esd_friends_file = TFile::Open(esd_friends_file_name, "CACHEREAD");
if (!esd_friends_file)
return;
esd_tree->SetBranchStatus ("ESDfriend*", 1);
}
// Set the branch addresses.
{
TIter next(esd_objs);
TObject *el;
while ((el = (TNamed*)next()))
{
TString bname(el->GetName());
if (bname == "AliESDfriend")
{
// AliESDfriend needs special treatment.
TBranch *br = esd_tree->GetBranch("ESDfriend.");
br->SetAddress(esd_objs->GetObjectRef(el));
}
else
{
TBranch *br = esd_tree->GetBranch(bname);
if (br)
{
br->SetAddress(esd_objs->GetObjectRef(el));
}
else
{
br = esd_tree->GetBranch(bname + ".");
if (br)
{
br->SetAddress(esd_objs->GetObjectRef(el));
}
else
{
Warning("AliESDEvent::ReadFromTree() "
"No Branch found with Name '%s' or '%s.'.",
bname.Data(),bname.Data());
}
}
}
}
}
TEveManager::Create();
{ // Simple geometry
TFile* geom = TFile::Open(esd_geom_file_name, "CACHEREAD");
if (!geom)
return;
TEveGeoShapeExtract* gse = (TEveGeoShapeExtract*) geom->Get("Gentle");
gGeomGentle = TEveGeoShape::ImportShapeExtract(gse, 0);
geom->Close();
delete geom;
gEve->AddGlobalElement(gGeomGentle);
}
//.........这里部分代码省略.........
示例8: MergeRootfile
void MergeRootfile( TDirectory *target, const vector<pair<TFile*, float> >& vFileList) {
// cout << "Target path: " << target->GetPath() << endl;
TString path( (char*)strstr( target->GetPath(), ":" ) );
path.Remove( 0, 2 );
vec_pair_it it = vFileList.begin();
TFile *first_source = (*it).first;
const float first_weight = (*it).second;
first_source->cd( path );
TDirectory *current_sourcedir = gDirectory;
//gain time, do not add the objects in the list in memory
Bool_t status = TH1::AddDirectoryStatus();
TH1::AddDirectory(kFALSE);
// loop over all keys in this directory
TChain *globChain = 0;
TIter nextkey( current_sourcedir->GetListOfKeys() );
TKey *key, *oldkey=0;
while ( (key = (TKey*)nextkey())) {
//keep only the highest cycle number for each key
if (oldkey && !strcmp(oldkey->GetName(),key->GetName())) continue;
// read object from first source file
first_source->cd( path );
TObject *obj = key->ReadObj();
if ( obj->IsA()->InheritsFrom( TH1::Class() ) ) {
// descendant of TH1 -> merge it
// cout << "Merging histogram " << obj->GetName() << endl;
TH1 *h1 = (TH1*)obj;
if (first_weight>0) {
h1->Scale(first_weight);
}
// loop over all source files and add the content of the
// correspondant histogram to the one pointed to by "h1"
for (vec_pair_it nextsrc = vFileList.begin()+1; nextsrc != vFileList.end(); ++nextsrc ) {
// make sure we are at the correct directory level by cd'ing to path
(*nextsrc).first->cd( path );
const float next_weight = (*nextsrc).second;
TKey *key2 = (TKey*)gDirectory->GetListOfKeys()->FindObject(h1->GetName());
if (key2) {
TH1 *h2 = (TH1*)key2->ReadObj();
if (next_weight>0) h2->Scale(next_weight);
h1->Add( h2 );
delete h2;
}
}
} else if ( obj->IsA()->InheritsFrom( TTree::Class() ) ) {
// loop over all source files create a chain of Trees "globChain"
const char* obj_name= obj->GetName();
globChain = new TChain(obj_name);
globChain->Add(first_source->GetName());
for (vec_pair_it nextsrc = vFileList.begin()+1; nextsrc != vFileList.end(); ++nextsrc ) {
globChain->Add(nextsrc->first->GetName());
}
} else if ( obj->IsA()->InheritsFrom( TDirectory::Class() ) ) {
// it's a subdirectory
cout << "Found subdirectory " << obj->GetName() << endl;
// create a new subdir of same name and title in the target file
target->cd();
TDirectory *newdir = target->mkdir( obj->GetName(), obj->GetTitle() );
// newdir is now the starting point of another round of merging
// newdir still knows its depth within the target file via
// GetPath(), so we can still figure out where we are in the recursion
MergeRootfile( newdir, vFileList);
} else {
// object is of no type that we know or can handle
cout << "Unknown object type, name: "
<< obj->GetName() << " title: " << obj->GetTitle() << endl;
}
// now write the merged histogram (which is "in" obj) to the target file
// note that this will just store obj in the current directory level,
// which is not persistent until the complete directory itself is stored
// by "target->Write()" below
if ( obj ) {
target->cd();
//!!if the object is a tree, it is stored in globChain...
if(obj->IsA()->InheritsFrom( TTree::Class() ))
globChain->Merge(target->GetFile(),0,"keep");
else
obj->Write( key->GetName() );
}
//.........这里部分代码省略.........
示例9: bfcread_histBranch
void bfcread_histBranch(
Int_t nevents=1,
const char *MainFile=
"/afs/rhic.bnl.gov/star/data/samples/gstar.dst.root",
const char *fname="qa_hist.out")
{
//
cout << " events to process = " << nevents << endl;
cout << " Input File Name = " << MainFile << endl;
cout << " Output file containing printouts = " << fname << endl;
ofstream fout(fname);
fout << " Running: bfcread_histBranch.C " << endl;
fout << " events to process = " << nevents << endl;
fout << " Input File Name = " << MainFile << endl;
fout << " Output file containing printouts = " << fname << endl;
fout << endl << endl;
gSystem->Load("St_base");
gSystem->Load("StChain");
gSystem->Load("StIOMaker");
gSystem->Load("libglobal_Tables");
// Setup top part of chain
chain = new StChain("bfc");
chain->SetDebug();
StIOMaker *IOMk = new StIOMaker("IO","r",MainFile,"bfcTree");
IOMk->SetDebug();
IOMk->SetIOMode("r");
IOMk->SetBranch("*",0,"0"); //deactivate all branches
IOMk->SetBranch("histBranch",0,"r"); //activate hist Branch
// --- now execute chain member functions
chain->Init();
TDataSet *ds=0;
TDataSet *obj=0;
int istat=0;
int i=0;
int countev=0;
int countevhds=0;
// Event loop
EventLoop: if (i < nevents && !istat) {
chain->Clear();
istat = chain->Make(i);
// count # times Make is called
i++;
// Now look at the data in the event:
int countObj=0;
int countHist=0;
if (!istat) {
countev++;
cout << " start event # " << countev << endl;
ds=chain->GetDataSet("hist");
TDataSetIter tabiter(ds);
if (ds) {
countevhds++;
TDataSetIter nextHistList(ds);
St_ObjectSet *histContainer = 0;
TList *dirList = 0;
// loop over directories:
while (histContainer = (St_ObjectSet *)nextHistList()) {
dirList = (TList *) histContainer->GetObject();
cout << " QAInfo: found directory: " <<
histContainer->GetName() << endl;
fout << " QAInfo: found directory: " <<
histContainer->GetName() << endl;
countObj++;
// Notes for future reference (if we want to generalize this...)
// dirList is returned 0 for non-histogram file
// in that case, use GetList instead of GetObject
TIter nextHist(dirList);
TObject *o = 0;
// loop over histograms in the directory:
while (o= nextHist()) {
countHist++;
cout << " QAInfo: Hist name: " << o->GetName() <<
" ==> Title: " << o->GetTitle() << endl;
fout << " QAInfo: Hist name: " << o->GetName() <<
" ==> Title: " << o->GetTitle() << endl;
//.........这里部分代码省略.........
示例10: generatePlots
void generatePlots(Files *inputs, const string &path)
{
Files::const_iterator first_source = inputs->begin();
TDirectory *folder = dynamic_cast<TDirectory *>(first_source->second->Get(path.c_str()));
if (!folder)
{
cerr << "Failed to extract folder: " << path << endl;
return;
}
//
//gain time, do not add the objects in the list in memory
//
Bool_t status = TH1::AddDirectoryStatus();
TH1::AddDirectory(kFALSE);
// loop over all keys in this directory
TIter nextkey(folder->GetListOfKeys() );
for(TKey *key, *oldkey=0; key = (TKey*) nextkey(); )
{
//keep only the highest cycle number for each key
if (oldkey
&& !strcmp(oldkey->GetName(), key->GetName()))
continue;
// read object from first source file
//
TObject *obj = key->ReadObj();
if ( obj->IsA()->InheritsFrom(TH1::Class()))
{
cout << obj->GetName() << endl;
TCanvas *canvas = new TCanvas();
canvas->SetWindowSize(640, 480);
THStack *stack = new THStack();
TLegend *legend = new TLegend(.6, .98, .98, .58);
legend->SetBorderSize(1);
legend->SetLineStyle(1);
legend->SetTextFont(43);
legend->SetTextSizePixels(12);
legend->SetFillColor(0);
TH1 *h1 = dynamic_cast<TH1*>(obj);
legend->AddEntry(h1, style(h1, first_source->first).c_str(), "pl");
h1->Scale(1.0 / h1->Integral());
stack->Add(h1);
// loop over all source files and add the content of the
// correspondant histogram to the one pointed to by "h1"
for(Files::const_iterator input = ++inputs->begin();
inputs->end() != input;
++input)
{
TH1 *h2 = dynamic_cast<TH1*>(input->second->Get((path + "/" + obj->GetName()).c_str()));
if (!h2)
{
cerr << "Failed to extract plot from input: " << endl;
continue;
}
h2->Scale(1. / h2->Integral());
legend->AddEntry(h2, style(h2, input->first).c_str(), "pl");
stack->Add(h2);
}
stack->Draw("h nostack");
legend->Draw();
stack->GetXaxis()->SetTitle(h1->GetXaxis()->GetTitle());
canvas->Update();
} else {
// object is of no type that we know or can handle
//
cout << "Unknown object type, name: "
<< obj->GetName() << " title: " << obj->GetTitle() << endl;
}
}
// save modifications to target file
TH1::AddDirectory(status);
}
示例11: MatrixMethod
void MatrixMethod(bool isData=false){
TFile* f = new TFile("MMethod.root", "update");
string dataset="";
string channels[] = {"mumumu", "mumue", "eemu", "eee"};
// Loop over channels
for(int iChannel=0; iChannel<4; iChannel++)
{
cout<<"-------------"<<endl;
cout<<"Channel "<<channels[iChannel]<<endl;
cout<<"-------------"<<endl;
TH1F* htight=0;
TH1F* hloose=0;
TH1F* htight_err=0;
TH1F* hloose_err=0;
// Get cut flow histos
if(isData)
{
if(iChannel==0) dataset="DataMu";
if(iChannel==1) dataset="DataMuEG";
if(iChannel==2) dataset="DataMuEG";
if(iChannel==3) dataset="DataEG";
htight = (TH1F*) f->Get(string("CutFlow_"+channels[iChannel]+"_tight_"+dataset).c_str());
hloose = (TH1F*) f->Get(string("CutFlow_"+channels[iChannel]+"_loose_"+dataset).c_str());
htight_err = (TH1F*) f->Get(string("ErrCutFlow_"+channels[iChannel]+"_tight_"+dataset).c_str());
hloose_err = (TH1F*) f->Get(string("ErrCutFlow_"+channels[iChannel]+"_loose_"+dataset).c_str());
}
else
{
dataset="MC";
TIter nextkey( gDirectory->GetListOfKeys() );
TKey *key;
while ( (key = (TKey*)nextkey()))
{
TObject *obj = key->ReadObj();
if(! obj->IsA()->InheritsFrom( TH1F::Class() )) continue;
TString name(obj->GetName());
if(!name.Contains("CutFlow")) continue;
if(name.Contains("Data") || name.Contains("FCNC")) continue;
TH1F* h = (TH1F*) obj;
if(!name.Contains(channels[iChannel])) continue;
//cout<<name<<endl;
if(name.Contains("CutFlow") && !name.Contains("ErrCutFlow"))
{
if(name.Contains("tight"))
{
cout<<name<<endl;
if(!htight) htight = (TH1F*) h->Clone();
else htight->Add(h);
//htight->Print("all");
}
if(name.Contains("loose"))
{
if(!hloose) hloose = (TH1F*) h->Clone();
else hloose->Add(h);
}
}
if(name.Contains("ErrCutFlow"))
{
if(name.Contains("tight"))
{
if(!htight_err) htight_err = (TH1F*) h->Clone();
else htight_err->Add(h);
}
if(name.Contains("loose"))
{
if(!hloose_err) hloose_err = (TH1F*) h->Clone();
else hloose_err->Add(h);
}
}
}
}
if(!htight || !hloose) {cout<<"Histos not found."<<endl; return;}
if(!htight_err || !hloose_err) {cout<<"Error histos not found."<<endl; return;}
htight->Print("all");
// Prepare estimations histos
TH1F* hestimation_S = (TH1F*) htight->Clone();
hestimation_S->SetName(string("Estimation_"+channels[iChannel]+"_S_"+dataset).c_str());
hestimation_S->Reset();
TH1F* hestimation_Z = (TH1F*) htight->Clone();
hestimation_Z->SetName(string("Estimation_"+channels[iChannel]+"_Z_"+dataset).c_str());
hestimation_Z->Reset();
double Nt, Nl, NtS, NtZ, Nt_err, Nl_err, NtS_err_eff, NtZ_err_eff, NtS_err_stat, NtZ_err_stat;
//.........这里部分代码省略.........
示例12: readHistos
TList* readHistos(vector<string> inputRootFiles, bool fillNameStrings){
TList* thelistHistos = new TList();
for (int j=0; j< inputRootFiles.size(); j++)
{
int numMax = 0;
//cout <<"inputProcess: "<<inputProcess.at(j)<<endl;
// Access input ROOT file (can access over secure shell)
cout <<"inputRootFiles.at(j) "<<inputRootFiles.at(j)<<endl;
TFile *rootTFile = new TFile((inputRootFiles.at(j)).c_str()); // open root file
TDirectory *current_sourcedir = gDirectory;
TIter nextkey( current_sourcedir->GetListOfKeys() );
TKey *key;
// loop over keys(ROOT objects) within the root file
while ((key = (TKey*)nextkey()))
{
TObject *obj = key->ReadObj();
TH1 *histoObj = (TH1*)obj;
TH1* h1 = 0; //points to the new copied hist we will make
int totalbins = 0;
// rename histogram
if ( obj->IsA()->InheritsFrom( "TH1" ) )
{
string histname = obj->GetName();
size_t found = histname.find("lumi");
string theProcess = "lumi";
string new_theProcess = "_" + theProcess;
histname.erase(found-1, new_theProcess.size());
string histName = histname;
cout << histName << endl;
for (int o = 0; o < inputHistoName.size(); o++)
{
if ( histName == inputHistoName.at(o) )
{
int numBins = histoObj->GetXaxis()->GetNbins();
double lowerEdge = histoObj->GetXaxis()->GetXmin();
double upperEdge = histoObj->GetXaxis()->GetXmax();
h1 = new TH1F (histName.c_str(), histName.c_str(),
numBins, lowerEdge, upperEdge);
TH1F* tmp2 = static_cast<TH1F*>(h1);
totalbins = tmp2->GetSize();
for (int k=0; k <= totalbins; k++)
{
h1->SetBinContent(k,(histoObj->GetBinContent(k)));
h1->SetBinError(k,(histoObj->GetBinError(k)));
}
h1 = Rebinh(h1);
//cout<<"h1 "<<h1->GetName()<<" Integral "<<h1->Integral()<<endl;
thelistHistos->Add(h1);
if(fillNameStrings) nHistList++;
if(fillNameStrings) theHistNameStrings.push_back(histName);
numMax++;
} // close if loop on selected histograms
} // close for loop on selected histograms
} // close if loop InheritsFrom("TH1")
} // close while loop
// If first input ROOT file (Data), store total number of histograms
if (j == 0)
numHistos = numMax;
// Else exit the code if a ROOT file has a different number of histograms
else
{
if (numMax != numHistos)
{
cerr << "ERROR: Input Root Files DO NOT have the same number"
<< " of histograms." << endl;
exit (1);
}
}
} // close for loop over root files
return thelistHistos;
}
示例13: plotylms
void plotylms()
{
gStyle->SetOptStat(1000000001);
TIter gdiriter(gDirectory->GetListOfKeys());
TObject *cur;
char *buf;
char suff[500];
char lbuf[500];
char nbuf[500];
suff[0] = '\0';
while (cur = gdiriter()) {
buf = cur->GetName();
if (strstr(buf, "CfnReYlm00")) {
cout << "Found suffix " << buf+10 << endl;
strcpy(suff, buf+10);
break;
}
}
if (!suff[0]) {
cout << "Did not find suffix" << endl;
return;
}
int maxl = 0;
gdiriter->Reset();
while (cur = gdiriter()) {
buf = cur->GetName();
if ((strstr(buf, "CfnReYlm")) && (strstr(buf, suff))){
cout << "Found l " << buf+8 << endl;
strncpy(lbuf, buf+8,1);
lbuf[1] = '\0';
int lcur = atoi(lbuf);
cout << "Found l " << lcur << endl;
if (lcur > maxl) maxl = lcur;
}
}
cout << "Maximum l " << maxl << endl;
int ilmcount= 0;
TH1D **cfnsr;
cfnsr = malloc(sizeof(TH1D *) * (maxl+1)*(maxl+1));
TH1D **cfnsi;
cfnsi = malloc(sizeof(TH1D *) * (maxl+1)*(maxl+1));
for (int il=0; il<=maxl; il++)
for (int im=0; im<=il; im++) {
sprintf(nbuf, "CfnReYlm%i%i%s", il, im, suff);
cfnsr[ilmcount] = new TH1D(*((TH1D *) gDirectory->Get(nbuf)));
checknan(cfnsr[ilmcount]);
sprintf(nbuf, "CfnImYlm%i%i%s", il, im, suff);
cfnsi[ilmcount] = new TH1D(*((TH1D *) gDirectory->Get(nbuf)));
checknan(cfnsi[ilmcount]);
ilmcount++;
}
TLine *l1 = new TLine(0.0, 1.0, cfnsr[0]->GetXaxis()->GetXmax(), 1.0);
l1->SetLineColor(14);
l1->SetLineStyle(2);
TLine *l0 = new TLine(0.0, 0.0, cfnsr[0]->GetXaxis()->GetXmax(), 0.0);
l0->SetLineColor(14);
l0->SetLineStyle(2);
TCanvas *canylm = new TCanvas("canylm","canylm",1600,800);
gPad->SetFillColor(0);
gPad->SetFillStyle(4000);
canylm->Divide(5, 2, 0.0001, 0.0001);
for (int ilm=0; ilm<(maxl+1)*(maxl+2)/2; ilm++) {
cout << "Drawing " << ilm << endl;
canylm->cd(ilm+1);
gPad->SetFillColor(0);
gPad->SetFillStyle(4000);
gPad->SetTopMargin(0.01);
gPad->SetRightMargin(0.01);
cfnsr[ilm]->SetTitle("");
cfnsr[ilm]->SetMarkerColor(2);
cfnsr[ilm]->SetMarkerSize(0.8);
cfnsr[ilm]->SetMarkerStyle(8);
cfnsr[ilm]->Draw();
cout << "Drawn " << ilm << endl;
cfnsi[ilm]->SetTitle("");
cfnsi[ilm]->SetMarkerColor(4);
cfnsi[ilm]->SetMarkerSize(0.8);
cfnsi[ilm]->SetMarkerStyle(8);
cfnsi[ilm]->Draw("SAME");
cout << "Drawn " << ilm << endl;
if (ilm)
l0->Draw();
else
l1->Draw();
//.........这里部分代码省略.........
示例14: makePlots_Combinations
void makePlots_Combinations(short makePlots=0) {
TString dirPlots("/home/rossin/Dropbox/TT/Work/figures_stubCleaning/");
TFile fIn ("/home/rossin/Dropbox/TT/Work/figures_stubCleaning/stubCleaning_Neutrino_PU140_sf1_nz4_pt3_5oo6_14k.root"); TString sLogic ("5oo6"); TString pName("Neutrino_PU140_sf1_nz4_pt3_5oo6_14k"); TString pTitle(" PU140 SF=1 Nz=4 Pt>3 GeV/c");
TFile fIn2("/home/rossin/Dropbox/TT/Work/figures_stubCleaning/stubCleaning_Neutrino_PU140_sf1_nz4_pt3_6oo6_14k.root"); TString sLogic2("6oo6"); //TString pName("Neutrino_PU140_sf1_nz4_pt3_6oo6_14k"); TString pTitle(" PU140 SF=1 Nz=4 Pt>3 GeV/c");
TFile fInOR("/home/rossin/Dropbox/TT/Work/figures_stubCleaning/stubCleaning_Neutrino_PU140_sf1_nz4_pt3_5oo6_14k_OverlapRemoved.root");
// TFile fIn("/home/rossin/Dropbox/TT/Work/figures_stubCleaning/stubCleaning_Neutrino_PU200_sf1_nz4_pt3_5oo6_4k.root"); TString sLogic("5oo6"); TString pName("Neutrino_PU200_sf1_nz4_pt3_5oo6_4k"); TString pTitle(" PU200 SF=1 Nz=4 Pt>3 GeV/c");
// TFile fInOR("/home/rossin/Dropbox/TT/Work/figures_stubCleaning/stubCleaning_Neutrino_PU200_sf1_nz4_pt3_5oo6_4k_OverlapRemoved.root");
// TFile fIn("/home/rossin/Dropbox/TT/Work/figures_stubCleaning/stubCleaning_Neutrino_PU250_sf1_nz4_pt3_5oo6_4k.root"); TString sLogic("5oo6"); TString pName("Neutrino_PU250_sf1_nz4_pt3_5oo6_4k"); TString pTitle(" PU250 SF=1 Nz=4 Pt>3 GeV/c");
// TFile fInOR("/home/rossin/Dropbox/TT/Work/figures_stubCleaning/stubCleaning_Neutrino_PU250_sf1_nz4_pt3_5oo6_4k_OverlapRemoved.root");
TH1* h1stubsInLayer [6][2];
TH1* h1stubsInLayerOR[6][2];
TH1* h1RoadPerEvent [2];
TH1* h1RoadPerEventOR[2];
TH1* h1CombPerRoad [2];
TH1* h1CombPerRoadOR [2];
TH1* h1CombPerEvent [2];
TH1* h1CombPerEventOR[2];
TH1* h1RoadPerEvent6oo6 [2];
TH1* h1CombPerRoad6oo6 [2];
TH1* h1CombPerEvent6oo6 [2];
TString sClean[2] = {TString(""), TString("_Cleaned")};
for (unsigned short iLay=0; iLay<6; ++iLay) {
TList* tl = fIn.GetListOfKeys();
TIter next(tl);
TObject *obj;
char cc[20];
sprintf(cc,"_%d",iLay);
TString hString("h1stubsInLayer__"+sLogic+TString(cc));
while ((obj=next())) {
TString hName(obj->GetName());
if (hName==hString) {
for (unsigned short iClean = 0; iClean < 2; ++iClean) {
char cc2[100];
h1stubsInLayer [iLay][iClean] = (TH1*) fIn .Get(hName+sClean[iClean]);
sprintf(cc2,"L%d - ",iLay+5);
h1stubsInLayer [iLay][iClean]->SetTitle(TString(cc2)+sLogic+pTitle);
h1stubsInLayerOR[iLay][iClean] = (TH1*) fInOR.Get(hName+sClean[iClean]);
if (h1stubsInLayer [iLay][iClean]==0) {
std::cout << "ERROR. " << hName+sClean[iClean] << " not loaded." << std::endl;
return;
}
if (h1stubsInLayerOR[iLay][iClean]==0) {
std::cout << "ERROR. " << hName+sClean[iClean] << " overlap removed not loaded." << std::endl;
return;
}
}
}
}
// std::cout << h1stubsInLayer [iLay][0] << "\t" << h1stubsInLayer [iLay][1] << "\t" << h1stubsInLayerOR[iLay][0] << "\t" << h1stubsInLayerOR[iLay][1] << std::endl;
}
for (unsigned short iClean = 0; iClean < 2; ++iClean) {
TString hString("h1RoadPerEvent_"+sLogic);
h1RoadPerEvent [iClean] = (TH1*) fIn .Get(hString+sClean[iClean]);
h1RoadPerEventOR[iClean] = (TH1*) fInOR.Get(hString+sClean[iClean]);
hString=TString("h1CombPerRoad_")+sLogic;
h1CombPerRoad [iClean] = (TH1*) fIn .Get(hString+sClean[iClean]);
h1CombPerRoadOR [iClean] = (TH1*) fInOR.Get(hString+sClean[iClean]);
hString=TString("h1CombPerEvent_")+sLogic;
h1CombPerEvent [iClean] = (TH1*) fIn .Get(hString+sClean[iClean]);
h1CombPerEventOR [iClean] = (TH1*) fInOR.Get(hString+sClean[iClean]);
hString=TString("h1RoadPerEvent_"+sLogic2);
h1RoadPerEvent6oo6 [iClean] = (TH1*) fIn2 .Get(hString+sClean[iClean]);
hString=TString("h1CombPerRoad_")+sLogic2;
h1CombPerRoad6oo6 [iClean] = (TH1*) fIn2 .Get(hString+sClean[iClean]);
hString=TString("h1CombPerEvent_")+sLogic2;
h1CombPerEvent6oo6 [iClean] = (TH1*) fIn2 .Get(hString+sClean[iClean]);
}
TString cName("cStubsPerLayer_"+sLogic+pName);
TString cTitle("StubsPerLayer "+sLogic+pTitle);
TCanvas* cStubsPerLayer = new TCanvas(cName,cTitle,0,0,1400,900);
cStubsPerLayer->Divide(3,2);
for (unsigned short iLay=0; iLay<6; ++iLay) {
char cc3[100];
cStubsPerLayer->cd(iLay+1);
gPad->SetLogy();
h1stubsInLayer [iLay][0]->DrawCopy();
TLegend* tl = new TLegend(0.3,0.75,0.9,0.9);
sprintf(cc3,"Mean # stubs: %3.2lf",h1stubsInLayer [iLay][0]->GetMean());
TLegendEntry* tle = tl->AddEntry(h1stubsInLayer [iLay][0],cc3,"l");
tle->SetLineColor(h1stubsInLayer [iLay][0]->GetLineColor());
tle->SetLineWidth(h1stubsInLayer [iLay][0]->GetLineWidth());
tl->Draw("L");
}
if (makePlots) {
cStubsPerLayer->SaveAs(dirPlots+cName+"__.pdf");
cStubsPerLayer->SaveAs(dirPlots+cName+"__.png");
}
for (unsigned short iLay=0; iLay<6; ++iLay) {
//.........这里部分代码省略.........
示例15: ScaleAll1file
void ScaleAll1file( TDirectory *target, FileInfo_t& source ) {
cout << "Target path: " << target->GetPath() << endl;
TString path( (char*)strstr( target->GetPath(), ":" ) );
path.Remove( 0, 2 );
source.fp->cd( path );
TDirectory *current_sourcedir = gDirectory;
// loop over all keys in this directory
bool newdir = true;
TIter nextkey( current_sourcedir->GetListOfKeys() );
TKey *key;
while ( (key = (TKey*)nextkey())) {
// read object from first source file
source.fp->cd( path );
TObject *obj = key->ReadObj();
if ( obj->IsA()->InheritsFrom( "TH1" ) ) {
// descendant of TH1 -> scale it
if (newdir) {
newdir=false;
cout << "Scaling histograms: " << endl;
}
cout << obj->GetName() << " ";
TH1 *h1 = (TH1*)obj;
h1->Scale(source.weight);
} else if ( obj->IsA()->InheritsFrom( "TDirectory" ) ) {
// it's a subdirectory
newdir = true;
cout << "\n=====> Found subdirectory " << obj->GetName();
cout << "<=====\n" << endl;
// create a new subdir of same name and title in the target file
target->cd();
TDirectory *newdir = target->mkdir( obj->GetName(), obj->GetTitle() );
// newdir is now the starting point of another round of merging
// newdir still knows its depth within the target file via
// GetPath(), so we can still figure out where we are in the recursion
ScaleAll1file( newdir, source );
} else {
// object is of no type that we know or can handle
cout << "\n======> Unknown object type, name: "
<< obj->GetName() << " title: " << obj->GetTitle();
cout << "<======\n" << endl;
}
// now write the scaledd histogram (which is "in" obj) to the target file
// note that this will just store obj in the current directory level,
// which is not persistent until the complete directory itself is stored
// by "target->Write()" below
if ( obj ) {
target->cd();
obj->Write( key->GetName() );
}
} // while ( ( TKey *key = (TKey*)nextkey() ) )
cout << endl;
// save modifications to target file
target->Write();
}