当前位置: 首页>>代码示例>>C++>>正文


C++ TTree::SetEventList方法代码示例

本文整理汇总了C++中TTree::SetEventList方法的典型用法代码示例。如果您正苦于以下问题:C++ TTree::SetEventList方法的具体用法?C++ TTree::SetEventList怎么用?C++ TTree::SetEventList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TTree的用法示例。


在下文中一共展示了TTree::SetEventList方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: dumpSome

void dumpSome(string infile, string field, string obj = "lb", string addCut = "")
{
    TFile* tfIn = TFile::Open(infile.c_str(), "READ");
    if (tfIn == 0)
    {
	cout << "Problem opening infile \"" << infile << "\" - exting";
	return;
    }
    TTree* intree = (TTree*) tfIn->Get("events");
    // cut selection
    Cuts cut;
    if (obj == "lb") cut.selectCut("acc03","lb07");
    if (obj == "B0") cut.selectCut("acc03B0","B001");
    //if (obj == "B0") cut.selectCut("acc03B0","B001exp");

    if (addCut.size() > 0)
	intree->Draw(">>lst", (cut.getCut()+"&&"+addCut).c_str());
    else
	intree->Draw(">>lst", cut.getCut().c_str());
    TEventList *lst = (TEventList*)gDirectory->Get("lst");
    intree->SetEventList(lst);

    intree->SetScanField(-1);
    intree->Scan(field.c_str());
}
开发者ID:frmeier,项目名称:usercode,代码行数:25,代码来源:dumpSome.C

示例2: peakAnalysis

void peakAnalysis( string filename2 , string filenamelist ) {
   
    TFile * file0 = new TFile(filename2.c_str());
    TFile * file1 = new TFile(filenamelist.c_str());

    TTree * tree = (TTree*)file0->Get("tree");
    TEventList * listsel = (TEventList*)file1->Get("listofselected");

    TCanvas * can = new TCanvas( "canPeaks" , "Peak Analysis" , 7500 , 5500 , 900 , 600 );
    //can->SetLogy();
    can->SetGrid();
    can->cd();

    tree->SetEventList(listsel);
    tree->Draw("GEMDEnergyGauss_1.energy[0]>>htemp(10000,10000,10000)");
    TH1D * spectrum = (TH1D*)gDirectory->Get("htemp");

    spectrum->SetTitle("Energy Spectrum");
    spectrum->SetXTitle("Energy [keV]");
    spectrum->SetYTitle("Counts");
    //spectrum->SetStats(kFALSE);
    
    TSpectrum analyzer( 8 , 2 );
        // arg1: max number of peaks
        // arg2: resolution between peaks
    analyzer.Search( spectrum , 2 , "" , 0.0025);
        // arg2: sigma of the searched peaks
        // arg3: options
        // arg4: peaks with amplitude less than threshold*highest_peak are discarded

    vector<double> peaks;
    for ( int i = 0 ; i < analyzer.GetNPeaks() ; i++ ) {
        peaks.push_back(analyzer.GetPositionX()[i]);
    }
    sort(peaks.begin(),peaks.end());

    cout << endl << "########## PEAKS ##########" << endl;
    for ( int i = 0 ; i < peaks.size() ; i++ ) cout << i+1 << "\t" << peaks.at(i) << endl;

    cout << "###########################" << endl << endl;
   
	if ( peaks.size() < 6 ) { 
		cout << "ERROR: Not enough peaks found, try to modify TSpectrum parameters.\n\n";
		return;
	}

    ofstream file("calib.txt");

    file << "// calibration"                                     << endl
         << "// ch\tkeV"                                         << endl
         << peaks.at(0) << "\t1460.882 // 40K"                   << endl
         << peaks.at(1) << "\t1512.700 // 212Bi"                 << endl
         << peaks.at(2) << "\t1592.515 // 208Tl (double escape)" << endl
         << peaks.at(3) << "\t1620.738 // 212Bi"                 << endl
         << peaks.at(5) << "\t2103.513 // 208Tl (single escape)" << endl
         << peaks.at(6) << "\t2614.511 // 208Tl";

    return;
}
开发者ID:gipert,项目名称:PSD-tools,代码行数:59,代码来源:peakAnalysis.C

示例3: listMatchedEvents

void listMatchedEvents(std::string fullPath, bool matchesonly = false)
{
    // Essentially a sort of diff for reco and gen tree
    // May get slow for large trees as the search for the matching entry in the second tree
    // traverses the whole tree. This is because for merged trees the order is not guaranteed
    const int fVerbose(1);
    // Open file
    TFile *f = TFile::Open(fullPath.c_str());
    if (f==0)
    {
	cout << "File " << fullPath << " not found -- exiting" << endl;
	return;
    }
    if(fVerbose>0)
	cout << "Succesfully opened file " << fullPath << endl;
    // Get TTree with GenEvents
    TTree* tgen = (TTree*) f->Get("genevents");
    if(fVerbose>0) cout << "Got TTree with " << tgen->GetEntries() << " entries" << endl;
    // Do a cut, if needed
    //tgen->Draw(">>lst","ptmu1>3&&ptmu2>3&&TMath::Abs(etamu1)<2.5&&TMath::Abs(etamu2)<2.5");
    tgen->Draw(">>lst","");
    TEventList *lst;
    lst = (TEventList*)gDirectory->Get("lst");
    tgen->SetEventList(lst);
    if(fVerbose>0) cout << " After cuts: " << lst->GetN() << " entries" << endl;

    // Get TTree with iRecoEvents
    TTree* treco = (TTree*) f->Get("events");
    if(fVerbose>0) cout << "Got TTree with " << treco->GetEntries() << " entries" << endl;

    // set branch addresses
    int genrun, genls, genevt;
    tgen->SetBranchAddress("run",&genrun);
    tgen->SetBranchAddress("LS",&genls);
    tgen->SetBranchAddress("event",&genevt);

    int recorun, recols, recoevt;
    treco->SetBranchAddress("run",&recorun);
    treco->SetBranchAddress("LS",&recols);
    treco->SetBranchAddress("event",&recoevt);

    int mcmatch;
    treco->SetBranchAddress("isMCmatch",&mcmatch);

    double ptmu1, ptmu2, ptpr, ptpi;
    tgen->SetBranchAddress("ptmu1",&ptmu1);
    tgen->SetBranchAddress("ptmu2",&ptmu2);
    tgen->SetBranchAddress("ptpr",&ptpr);
    tgen->SetBranchAddress("ptpi",&ptpi);
    double etamu1, etamu2, etapr, etapi;
    tgen->SetBranchAddress("etamu1",&etamu1);
    tgen->SetBranchAddress("etamu2",&etamu2);
    tgen->SetBranchAddress("etapr",&etapr);
    tgen->SetBranchAddress("etapi",&etapi);
    double phimu1, phimu2, phipr, phipi;
    tgen->SetBranchAddress("phimu1",&phimu1);
    tgen->SetBranchAddress("phimu2",&phimu2);
    tgen->SetBranchAddress("phipr",&phipr);
    tgen->SetBranchAddress("phipi",&phipi);

    cout << "#      run         LS      event     genidx    recoidx" << endl;
    cout << "---------- ---------- ---------- ---------- ----------" << endl;

    TLorentzVector tlvmu1, tlvmu2, tlvpr, tlvpi;
    tmph1 = new TH1F ("tmph1","tmphisto",20,3.096,3.098);
    tmph2 = new TH1F ("tmph2","tmphisto",20,1.112,1.120);
    tmph3 = new TH1F ("tmph3","tmphisto",20,5.61,5.64);
    tmph4 = new TH2F ("tmph4","tmphisto",20,0,5,20,-2,8);

    // outer loop on gen events
    for (int i=0; i!=lst->GetN(); i++)
    {
	tgen->GetEntry(lst->GetEntry(i));
	tlvmu1.SetPtEtaPhiM(ptmu1,etamu1,phimu1,0.105658367);
	tlvmu2.SetPtEtaPhiM(ptmu2,etamu2,phimu2,0.105658367);
	tlvpr.SetPtEtaPhiM( ptpr, etapr, phipr ,0.938272013);
	tlvpi.SetPtEtaPhiM( ptpi, etapi, phipi ,0.13957018);
	tmph1->Fill((tlvmu1+tlvmu2).M());
	tmph2->Fill((tlvpr+tlvpi).M());
	tmph3->Fill((tlvmu1+tlvmu2+tlvpr+tlvpi).M());
	tmph4->Fill((tlvpr+tlvpi).P(),tlvpr.P()-tlvpi.P());
	//cout << (tlvmu1+tlvmu2).M() << " " << (tlvpr+tlvpi).M() << " " << (tlvmu1+tlvmu2+tlvpr+tlvpi).M() << endl;
	if (!matchesonly)
	    cout << setw(10) << genrun << " " << setw(10) << genls << " " << setw(10) << genevt << " " << setw(10) << lst->GetEntry(i) << " ";
	// inner loop on reco events
	int nfound(0);
	for (int j=0; j!=treco->GetEntries(); j++)
	{
	    treco->GetEntry(j);
	    if(genrun==recorun && genls==recols && genevt==recoevt)
	    {
		nfound++;
		if (matchesonly && nfound==1)
		    cout << setw(10) << genrun << " " << setw(10) << genls << " " << setw(10) << genevt << " " << setw(10) << lst->GetEntry(i) << " ";
		if(nfound>1) cout << "                                 " << setw(10) << lst->GetEntry(i) << " ";
		cout << setw(10) << j << " match: " << mcmatch << endl;
	    }
	}
	if (!matchesonly && nfound==0) cout << "         -" << endl;
    }
//.........这里部分代码省略.........
开发者ID:frmeier,项目名称:usercode,代码行数:101,代码来源:genDisplay01.C

示例4: genDisplay

// draws the decay vertices of the Lambda_s
void genDisplay(std::string fullPath, int iGen, int iReco = -1, bool savePdf = false)
{
    const int fVerbose(0);
    setTDRStyle();
    //gStyle->SetOptStat(112211);
    gStyle->SetOptStat(0);
    gStyle->SetPalette(1);
    // Canvases
    crz = new TCanvas("crz","crz",1000,600);
    TPad* padrz = (TPad*)crz->cd(1);
    setPadMargins(padrz, 0.02, 0.05, 0.02, 0.05);
    crphi = new TCanvas("crphi","crphi",600,600);
    TPad* padrphi = (TPad*)crphi->cd(1);
    setPadMargins(padrphi, 0.02, 0.05, 0.02, 0.05);
    // Open file
    TFile *f = TFile::Open(fullPath.c_str());
    if (f==0)
    {
	cout << "File " << fullPath << " not found -- exiting" << endl;
	return;
    }
    if(fVerbose>0)
	cout << "Succesfully opened file " << fullPath << endl;
    // Get TTree with GenEvents
    TTree* tgen = (TTree*) f->Get("genevents");
    if(fVerbose>0) cout << "Got TTree with " << tgen->GetEntries() << " entries" << endl;
    // Do a cut, if needed
    tgen->Draw(">>lst","ptmu1>3&&ptmu2>3&&TMath::Abs(etamu1)<2.5&&TMath::Abs(etamu2)<2.5");
    TEventList *lst;
    lst = (TEventList*)gDirectory->Get("lst");
    tgen->SetEventList(lst);

    // Get TTree with iRecoEvents
    TTree* treco = (TTree*) f->Get("events");
    if(fVerbose>0) cout << "Got TTree with " << treco->GetEntries() << " entries" << endl;

    // Do plots
    const int nbins(30);
    const double rangeR(30), rangeZ(100); // standard
    //const double rangeR(60), rangeZ(200); // zoomed out
    //const double rangeR(100), rangeZ(200); // zoomed in
    //const double rangeR(12), rangeZ(30); // zoomed further in
    padrz->cd();
    TH2F *hrz = new TH2F("hdisp","", nbins,-rangeZ,rangeZ,nbins,-rangeR,rangeR);
    hrz->Draw();
    padrphi->cd();
    TH2F *hrphi = new TH2F("hdisp","", nbins,-rangeR,rangeR,nbins,-rangeR,rangeR);
    hrphi->Draw();

    // add tracker
    padrz->Modified();
    padrz->Update();
    drawTrackerRZ(padrz);
    padrphi->Modified();
    padrphi->Update();
    drawTrackerRPhi(padrphi);

    // set branch addresses for gentree
    double vrl0,vxl0,vyl0,vzl0,vrlb,vxlb,vylb,vzlb;
    double pmu1,phimu1,etamu1,pmu2,phimu2,etamu2;
    double ppr,ppi,phipr,phipi,etapr,etapi;
    tgen->SetBranchAddress("vrl0",&vrl0);
    tgen->SetBranchAddress("vxl0",&vxl0);
    tgen->SetBranchAddress("vyl0",&vyl0);
    tgen->SetBranchAddress("vzl0",&vzl0);
    tgen->SetBranchAddress("vrlb",&vrlb);
    tgen->SetBranchAddress("vxlb",&vxlb);
    tgen->SetBranchAddress("vylb",&vylb);
    tgen->SetBranchAddress("vzlb",&vzlb);
    tgen->SetBranchAddress("pmu1",&pmu1);
    tgen->SetBranchAddress("etamu1",&etamu1);
    tgen->SetBranchAddress("phimu1",&phimu1);
    tgen->SetBranchAddress("pmu2",&pmu2);
    tgen->SetBranchAddress("etamu2",&etamu2);
    tgen->SetBranchAddress("phimu2",&phimu2);
    tgen->SetBranchAddress("ppr",&ppr);
    tgen->SetBranchAddress("etapr",&etapr);
    tgen->SetBranchAddress("phipr",&phipr);
    tgen->SetBranchAddress("ppi",&ppi);
    tgen->SetBranchAddress("etapi",&etapi);
    tgen->SetBranchAddress("phipi",&phipi);
    int genrun, genls, genevt;
    tgen->SetBranchAddress("run",&genrun);
    tgen->SetBranchAddress("LS",&genls);
    tgen->SetBranchAddress("event",&genevt);

    // set branch addresses for recotree
    double rvrl0,rvxl0,rvyl0,rvzl0,rvrlb,rvxlb,rvylb,rvzlb;
    double rpmu1,retamu1,rphimu1,rpmu2,retamu2,rphimu2;
    double rppr,rppi,retapr,retapi,rphipr,rphipi;
    treco->SetBranchAddress("vrl0",&rvrl0);
    treco->SetBranchAddress("vxl0",&rvxl0);
    treco->SetBranchAddress("vyl0",&rvyl0);
    treco->SetBranchAddress("vzl0",&rvzl0);
    treco->SetBranchAddress("vrlb",&rvrlb);
    treco->SetBranchAddress("vxlb",&rvxlb);
    treco->SetBranchAddress("vylb",&rvylb);
    treco->SetBranchAddress("vzlb",&rvzlb);
    treco->SetBranchAddress("rpt1m",&rpmu1);
//.........这里部分代码省略.........
开发者ID:frmeier,项目名称:usercode,代码行数:101,代码来源:genDisplay01.C

示例5: dataPlots01

void dataPlots01(std::string fullPath)
{
    const std::string outpdf("dataPlots01plots");
    const int fVerbose(0);
    setTDRStyle();
    gStyle->SetOptStat(112211);
    gStyle->SetPalette(1);
    // Canvas
    c = new TCanvas("c1","c1",1000,600);
    int canvasCdCounter(0), canvasPageCounter(0);
    const unsigned int nPadX = 2;
    const unsigned int nPadY = 2;
    c->Divide(nPadX,nPadY);
    const unsigned int nPads=nPadX*nPadY;
    for(unsigned int i=1; i<=nPads; i++)
    {
	TPad* pad= (TPad*)c->cd(i);
	pad->SetTopMargin(0.10);
    }
    // Open file
    TFile *f = TFile::Open(fullPath.c_str());
    if (f==0)
    {
	cout << "File " << fullPath << " not found -- exiting" << endl;
	return;
    }
    if(fVerbose>0)
	cout << "Succesfully opened file " << fullPath << endl;
    // Get TTree
    TTree* t = (TTree*) f->Get("events");
    if(fVerbose>0) cout << "Got TTree with " << t->GetEntries() << " entries" << endl;

    // General cuts
    Cuts cuts;
    cuts.selectCut("an03","acc03","HLT_matched_01");
    std::string cutsAnalysis = cuts.getCut();

    //std::string cutsgen = "TMath::Abs(etamu1)<2.5";
    //std::string cutsgen = "TMath::Abs(etamu1)<2.5&&TMath::Abs(etamu2)<2.5";
    //std::string cutsgen = cutsAnalysis;
    std::string cutsgen = "Eff>0.01&&" + cutsAnalysis;
    //std::string cutsgen = "TMath::Abs(Seta1m)<1.6&&TMath::Abs(Seta2m)<1.6&&" + cutsAnalysis;
    cout << "Cuts: " << cutsgen << endl;
    // Do plots
    const double ptmax(50.0);
    const double etamax(4);
    const double phimax(.03);
    const double ymax(.03);
    const int nBins(10);

    // masscut
    const std::string masscutWide("mlb>5.2&&mlb<6.4"), masscutWideTitle("5.2 < m_{#Lambda_{b}} < 6.4");
    const std::string masscutNarrow("mlb>5.566&&mlb<5.676"), masscutNarrowTitle("5.566 < m_{#Lambda_{b}} < 5.676"); // 2.5 sigma
    //const std::string masscutNarrow("mlb>5.605&&mlb<5.645"), masscutNarrowTitle("5.605 < m_{#Lambda_{b}} < 5.645"); // 1 sigma

    // Apply cuts
    t->Draw(">>lst",cutsgen.c_str());
    TEventList* lst;
    lst = (TEventList*)gDirectory->Get("lst");
    t->SetEventList(lst);

    TFile *fout = new TFile("histos.root","recreate");

    canvaspager(c,outpdf,nPads,canvasCdCounter,canvasPageCounter);
    c->cd(canvasCdCounter);
    doPlot1d(t,"hpt", "ptlb", cutsgen, nBins,0,ptmax,"p_{T}(#Lambda_{b})","p_{T}(#Lambda_{b})","GeV/c");
    c->Update();
    repositionStatbox("hpt");

    canvaspager(c,outpdf,nPads,canvasCdCounter,canvasPageCounter);
    c->cd(canvasCdCounter);
    doPlot1d(t,"hpt2", "ptlb", cutsgen +"&&"+masscutWide, nBins,0,ptmax,"p_{T}(#Lambda_{b}) "+masscutWideTitle,"p_{T}(#Lambda_{b})","GeV/c");
    c->Update();
    repositionStatbox("hpt2");

    canvaspager(c,outpdf,nPads,canvasCdCounter,canvasPageCounter);
    c->cd(canvasCdCounter);
    doPlot1d(t,"hpt3", "ptlb", cutsgen+"&&"+masscutNarrow, nBins,0,ptmax,"p_{T}(#Lambda_{b}) "+masscutNarrowTitle,"p_{T}(#Lambda_{b})","GeV/c");
    c->Update();
    repositionStatbox("hpt3");

    canvaspager(c,outpdf,nPads,canvasCdCounter,canvasPageCounter);
    c->cd(canvasCdCounter);
    doPlot1d(t,"hpt4", "ptlb", "("+cutsgen +"&&"+masscutNarrow+")/Eff", nBins,0,ptmax,"p_{T}(#Lambda_{b}) "+masscutNarrowTitle+", eff weight","p_{T}(#Lambda_{b})","GeV/c");
    c->Update();
    repositionStatbox("hpt4");

    // ----------------------
    canvaspager(c,outpdf,nPads,canvasCdCounter,canvasPageCounter);
    c->cd(canvasCdCounter);
    doPlot1d(t,"heta", "TMath::Abs(etalb)", cutsgen, nBins,0,etamax,"|#eta|(#Lambda_{b})","|#eta|(#Lambda_{b})","");
    c->Update();
    repositionStatbox("heta");

    canvaspager(c,outpdf,nPads,canvasCdCounter,canvasPageCounter);
    c->cd(canvasCdCounter);
    doPlot1d(t,"heta2", "TMath::Abs(etalb)", cutsgen +"&&"+masscutWide, nBins,0,etamax,"|#eta|(#Lambda_{b}) "+masscutWideTitle, "|#eta|(#Lambda_{b})","");
    c->Update();
    repositionStatbox("heta2");

//.........这里部分代码省略.........
开发者ID:frmeier,项目名称:usercode,代码行数:101,代码来源:dataPlots01.C

示例6: genPlots02

// draw the same thing but after reco
void genPlots02(std::string fullPath, int nOverlay = 500, bool custBinning = false)
{
    const int fVerbose(1);
    setTDRStyle();
    gStyle->SetOptStat(112211);
    gStyle->SetPalette(1);
    // Canvas
    c = new TCanvas("c2","c2",1000,600);
    const unsigned int nPadX = 1;
    const unsigned int nPadY = 1;
    c->Divide(nPadX,nPadY);
    const unsigned int nPads=nPadX*nPadY;
    for(unsigned int i=1; i<=nPads; i++)
    {
	TPad* pad= (TPad*)c->cd(i);
	pad->SetTopMargin(0.10);
	pad->SetRightMargin(0.20);
	pad->SetLeftMargin(0.15);
    }
    // Open file
    TFile *f = TFile::Open(fullPath.c_str());
    if (f==0)
    {
	cout << "File " << fullPath << " not found -- exiting" << endl;
	return;
    }
    if(fVerbose>0)
	cout << "Succesfully opened file " << fullPath << endl;
    // Get TTree
    TTree* t = (TTree*) f->Get("events");
    if(fVerbose>0) cout << "Got TTree with " << t->GetEntries() << " entries" << endl;
    // Do a cut, if needed
    //t->Draw(">>lst","chi2lb>.1&&mlb>5.61&&mlb<5.63");
    //t->Draw(">>lst","chi2lb>.1&&isSig==1");
    t->Draw(">>lst","(rid1m&4)==4&&(rid2m&4)==4&&mjp>2.895&&mjp<3.295&&prob1m>0.1&&prob2m>0.1&&ptjp>2&&probjp>0.005&&ml0>1.101&&ml0<1.129&&probpr>0.02&&probpi>0.02&&rptpr>rptpi&&ptl0>3&&rptpr>1&&rptpi>0.5&&probl0>0.02&&alphal0<0.3&&d3l0>1&&d3l0/d3El0>10&&problb>0.001&&alphalb<0.3");
    TEventList *lst;
    lst = (TEventList*)gDirectory->Get("lst");
    t->SetEventList(lst);
    if(fVerbose>0) cout << "Got TTree with " << t->GetEntries() << " entries" << endl;

    // Do plots
    c->cd(1);
    //doPlot2d(t,"hrzL0vtx", "vrl0:TMath::Abs(vzl0)",30,0,300,30,0,120,"Tit","|z|","r","cm","cm");
    if (custBinning)
    {
	double newbinsX[]={0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50};
	const int newbinsX_size = sizeof(newbinsX)/sizeof(double);
	std::vector<double> binvecX(newbinsX,newbinsX+newbinsX_size);
	//double newbinsY[]={0,1,2,3,4,5,6,7,8,9,10};
	double newbinsY[]={0,0.5,1,2,4,8,16,32};
	const int newbinsY_size = sizeof(newbinsY)/sizeof(double);
	std::vector<double> binvecY(newbinsY,newbinsY+newbinsY_size);
	doPlot2d(t,"hrzL0vtxreco", "vrl0:TMath::Abs(vzl0)",binvecX, binvecY,"#Lambda vertices","|z|","r","cm","cm");
    }
    else
    {
	doPlot2d(t,"hrzL0vtxreco", "vrl0:TMath::Abs(vzl0)",30,0,50,30,0,30,"#Lambda vertices","|z|","r","cm","cm");
    }

    // add tracker
    TPad* pad;
    pad = (TPad*)c->cd(1);
    pad->Modified();
    pad->Update();
    repositionPalette("hrzL0vtxreco");
    pad->Update();
    pad->SetLogz();
    drawTracker(pad);

    if (nOverlay<=0) return;
    int maxN = nOverlay;
    if (maxN > t->GetEntries()) maxN = t->GetEntries();
    double vrl0,vzl0,ppr,ppi,etapr,etapi;
    t->SetBranchAddress("vrl0",&vrl0);
    t->SetBranchAddress("vzl0",&vzl0);
    t->SetBranchAddress("ppr",&ppr);
    t->SetBranchAddress("etapr",&etapr);
    t->SetBranchAddress("ppi",&ppi);
    t->SetBranchAddress("etapi",&etapi);
    double scalepr = 4;
    double scalepi = 8;

    { // reference indicator
	const double x1pr = 0; const double y1pr = -3;
	const double x2pr = scalepr; const double y2pr = y1pr;
	const double versatz = 14;
	const double x1pi = x1pr+versatz; const double y1pi = -3;
	const double x2pi = x2pr+versatz+scalepi; const double y2pi = y1pi;
	TArrow *a;
	a = new TArrow(x1pr,y1pr,x2pr,y2pr,.01,">");
	a->SetLineColor(24);
	a->Draw();
	TLatex tl;
	tl.SetTextSize(20);
	tl.SetTextFont(4);
	tl.DrawLatex(x1pr,y2pr-1.2,"p(p) / 1 GeV");
	a = new TArrow(x1pi,y1pi,x2pi,y2pi,.01,">");
	a->SetLineColor(20);
	a->Draw();
//.........这里部分代码省略.........
开发者ID:frmeier,项目名称:usercode,代码行数:101,代码来源:genPlots02.C

示例7: AddBranchEventsMT2tree

//call this macro via root -l -b -q AddBranchEventsMT2tree.C++
//This code takes a text file containing run:lumisection:event:taggervalue (tagger value is a new filter you want to add to your tree),
//an old MT2tree file that does not contain that tagger
// and creates a new MT2tree file, which is a copy of the old one and contains additionally that tagger.
void AddBranchEventsMT2tree() {
// Example of Root macro to copy a subset of a Tree to a new Tree
// Only selected entries are copied to the new Tree.
// The input file has been generated by the program in $ROOTSYS/test/Event
// with   Event 1000 1 99 1
//Author: Rene Brun
   
//modified: Hannsjoerg Weber, 28/08/2013

   //make cleaning
   // get eventlist to clean
   // vector contains <run, < <lumisection, event>, taggervalue > >
   vector<pair<pair<int,pair<int,int> >,float> > rls; rls.clear();
   char buffer[200];
   ifstream filterdat("/shome/haweber/AODFiles_MT2SR/taggerlist/ControlRegionSinglePhotonPart1.dat");
   while( filterdat.getline(buffer, 200, '\n') ){
	int rrun(-1), lls(-1), eevent(-1), d1(-1); float ttagger(-1);
	sscanf(buffer, "*\t%d\t*\t%d\t*\t%d\t*\t%d\t*\t%f", &d1, &eevent, &lls, &rrun, &ttagger);
	pair<int,int> t1(lls,eevent);
	pair<int,pair<int,int> > t2(rrun,t1);
        pair<pair<int,pair<int,int> >, float> t3(t2,ttagger);
	rls.push_back(t3);
   }
cout << "Events for filtering " << rls.size() << endl;

   // get the old rootfile including events that should be tagged and define new event file including tagger variable
   TString oldfilename = "/shome/haweber/MT2Analysis/MT2trees/MT2_V02-03-02/20130914_8TeV_1g_removed/lowHT/SinglePhoton-Run2012C-PromptReco-v2-2.root";
   TString newfilename = "/shome/haweber/MT2Analysis/MT2trees/MT2_V02-03-02/20130914_8TeV_1g_removed/lowHT/SinglePhoton-Run2012C-PromptReco-v2-2_Filter.root";

	// if you want to apply an additional event selection, define cuts here
	std::ostringstream cutStream;
	std::ostringstream cutStreamBase;
	cutStream << " " 
		<< "NTausIDLoose3Hits+NMuons+NEles==0"                   << "&&"
		<< "misc.Jet0Pass==1&&misc.Jet1Pass==1"                  << "&&"
		<< "misc.Vectorsumpt<70&& misc.MinMetJetDPhi4Pt40 >0.3";
		cutStream << "&&((misc.MET>200&&misc.HT<=750&&misc.HT>=450&&misc.MT2>200)||(misc.HT>750&&misc.MET>30&&misc.MT2>=100))";
	cutStreamBase << " " 
      << "misc.PassJet40ID ==1"                             << "&&"
      << "(misc.HBHENoiseFlag == 0 || misc.ProcessID==10)"  << "&&" // not there for fastsim (i.e. signal)
      << "misc.CSCTightHaloIDFlag == 0"                     << "&&"
      << "misc.trackingFailureFlag==0"                      << "&&"
      << "misc.eeBadScFlag==0"                              << "&&"
      << "misc.EcalDeadCellTriggerPrimitiveFlag==0"         << "&&"
      << "misc.TrackingManyStripClusFlag==0"                << "&&"
      << "misc.TrackingTooManyStripClusFlag==0"             << "&&"
      << "misc.TrackingLogErrorTooManyClustersFlag==0"      << "&&"
      << "misc.CrazyHCAL==0";

	TString cuts = cutStream.str().c_str();
	TString basecuts = cutStreamBase.str().c_str();
//	TString myCuts = cuts + "&&" + basecuts;// if cuts should be applied DO NOT comment this line
	TString myCuts = "";// if no cuts should be applied DO NOT comment this line

   //Get old file, old tree and set top branch address
   TFile *oldfile = new TFile(oldfilename.Data());
   TTree *oldtree = (TTree*)oldfile->Get("MassTree");

   MT2tree* fMT2tree = new MT2tree();
   oldtree->SetBranchAddress("MT2tree", &fMT2tree);
   Long64_t nentries =  oldtree->GetEntries();
   Long64_t nbytes = 0, nb = 0;
   int nev =0;

   //Create a new file + a clone of old tree in new file
   Float_t TOBTECTagger(-1);
   Float_t HOTagger(-1);
   Bool_t ExtraBeamHaloFilter(false);
   TFile *newfile = new TFile(newfilename.Data(),"RECREATE");
   TTree *newtree = oldtree->CloneTree(0);//clone all branches, but no event
   TBranch *newBranch  = newtree->Branch("TOBTECTagger", &TOBTECTagger, "TOBTECTagger/F");
   TBranch *newBranch2 = newtree->Branch("ExtraBeamHaloFilter", &ExtraBeamHaloFilter, "ExtraBeamHaloFilter/O");
   TBranch *newBranch3 = newtree->Branch("HOTagger", &HOTagger, "HOTagger/F");

   oldtree->Draw(">>selList", myCuts);
   TEventList *myEvtList = (TEventList*)gDirectory->Get("selList");
   oldtree->SetEventList(myEvtList);
   int counter=0;
   int numEvt = myEvtList->GetN();
   int printEvt = 100000;
   if(myEvtList->GetN()<1000000) printEvt = myEvtList->GetN()/25;
   cout << "Filtering done, size=" <<myEvtList->GetN()  << endl;
   while(myEvtList->GetEntry(counter++) !=-1){
	int jentry = myEvtList->GetEntry(counter-1);
	nb =  oldtree->GetEntry(jentry);   nbytes += nb;
	oldtree->SetBranchAddress("MT2tree", &fMT2tree);
	if(counter%printEvt==0) cout << "Process event " << counter << endl;	

	//make cleaning
	bool keep = true;
	int p=-1;
	for(int nn=0; nn<rls.size();++nn){
		if((rls[nn].first).first!=fMT2tree->misc.Run) continue; // --> run over matching 
		if(((rls[nn].first).second).first!=fMT2tree->misc.LumiSection) continue; // --> LS over matching 
		if(fMT2tree->misc.Event>0){
			if(((rls[nn].first).second).second==fMT2tree->misc.Event) { 
//.........这里部分代码省略.........
开发者ID:MT2Analysis,项目名称:MT2Analysis,代码行数:101,代码来源:AddBranchEventsMT2tree.C


注:本文中的TTree::SetEventList方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。