コード例 #1
0
ファイル: dumpSome.C プロジェクト: frmeier/usercode
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());
}
コード例 #2
0
ファイル: peakAnalysis.C プロジェクト: gipert/PSD-tools
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;
}
コード例 #3
0
ファイル: genDisplay01.C プロジェクト: frmeier/usercode
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;
    }
    c2 = new TCanvas();
    c2->Divide(2,2);
    c2->cd(1);
    tmph1->Draw();
    c2->cd(2);
    tmph2->Draw();
    c2->cd(3);
    tmph3->Draw();
    c2->cd(4);
    tmph4->Draw();
}
コード例 #4
0
ファイル: genDisplay01.C プロジェクト: frmeier/usercode
// 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);
    treco->SetBranchAddress("reta1m",&retamu1);
    treco->SetBranchAddress("rphi1m",&rphimu1);
    treco->SetBranchAddress("rpt2m",&rpmu2);
    treco->SetBranchAddress("reta2m",&retamu2);
    treco->SetBranchAddress("rphi2m",&rphimu2);
    treco->SetBranchAddress("rptpr",&rppr);
    treco->SetBranchAddress("retapr",&retapr);
    treco->SetBranchAddress("rphipr",&rphipr);
    treco->SetBranchAddress("rptpi",&rppi);
    treco->SetBranchAddress("retapi",&retapi);
    treco->SetBranchAddress("rphipi",&rphipi);

    drawArrowLegend(padrz);
    drawArrowLegend(padrphi,.8);
    // write the event indices
    writeLatex(padrz,.1,.9,("iGen: " + toString(iGen)).c_str());
    writeLatex(padrphi,.1,.9,("iGen: " + toString(iGen)).c_str());
    if (iReco >= 0)
    {
	writeLatex(padrz,.1,.85,("iReco: " + toString(iReco)).c_str());
	writeLatex(padrphi,.1,.85,("iReco: " + toString(iReco)).c_str());
    }

    if (iGen<0) return;
    if (iGen>tgen->GetEntries()) return;
    if (iReco>treco->GetEntries()) return;
    tgen->GetEntry(iGen);
    cout << "iGen: " << iGen << " - " << genrun << " " << genls << " " << genevt << endl;
    padrz->cd();
    drawEventZR(vrlb, vzlb, vrl0, vzl0, pmu1, etamu1, pmu2, etamu2, ppr, etapr, ppi, etapi, 0);
    padrphi->cd();
    drawEventRPhi(vxlb, vylb, vxl0, vyl0, pmu1, phimu1, pmu2, phimu2, ppr, phipr, ppi, phipi, 0);
    if(iReco>=0)
    {
        treco->GetEntry(iReco);
        cout << "iReco: " << iReco << endl;
	padrz->cd();
        drawEventZR(rvrlb, rvzlb, rvrl0, rvzl0, rpmu1, retamu1, rpmu2, retamu2, rppr, retapr, rppi, retapi, 1);
	padrphi->cd();
        drawEventRPhi(rvxlb, rvylb, rvxl0, rvyl0, rpmu1, rphimu1, rpmu2, rphimu2, rppr, rphipr, rppi, rphipi, 1);
	cout << phimu1 << " " << rphimu1 << endl;
    }

    if(savePdf)
    {
	padrz->Update();
	padrphi->Update();
	std::string filename = "genDisplay_" + toString(iGen);
	if(iReco >= 0) filename += "_" + toString(iReco);
	crz->SaveAs((filename+"_rz.pdf").c_str());
	crphi->SaveAs((filename+"_rphi.png").c_str()); // weiss der Geier warum auf PDF die Kreise und die Skala fehlen...
    }

    return;
}
コード例 #5
0
ファイル: dataPlots01.C プロジェクト: frmeier/usercode
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");

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

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

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

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

    canvaspager(c,outpdf,nPads,canvasCdCounter,canvasPageCounter);
    c->cd(canvasCdCounter);
    doPlot1d(t,"hy3", "TMath::Abs(ylb)", cutsgen+"&&"+masscutNarrow, nBins,0,etamax,"|y|(#Lambda_{b}) "+masscutNarrowTitle, "|y|(#Lambda_{b})","");
    c->Update();
    repositionStatbox("hy3");

    canvaspager(c,outpdf,nPads,canvasCdCounter,canvasPageCounter);
    c->cd(canvasCdCounter);
    doPlot1d(t,"hy3eff", "TMath::Abs(ylb)", "("+cutsgen +"&&"+masscutNarrow+")/Eff", nBins,0,etamax,"|y|(#Lambda_{b}) "+masscutNarrowTitle+", eff weight","|y|(#Lambda_{b})","");
    c->Update();
    repositionStatbox("hy3eff");

    // ----------------------
    canvaspager(c,outpdf,nPads,canvasCdCounter,canvasPageCounter);
    c->cd(canvasCdCounter);
    doPlot1d(t,"hvzl0", "TMath::Abs(vzl0)", cutsgen, nBins,0,100,"|z_{vtx}|(#Lambda_{b})","|z_{vtx}|(#Lambda_{b})","cm");
    c->Update();
    repositionStatbox("hvzl0");

    canvaspager(c,outpdf,nPads,canvasCdCounter,canvasPageCounter);
    c->cd(canvasCdCounter);
    doPlot1d(t,"hvzl0_2", "TMath::Abs(vzl0)", cutsgen+"&&"+masscutNarrow, nBins,0,100,"|z_{vtx}|(#Lambda_{b}) "+masscutNarrowTitle,"|z_{vtx}|(#Lambda_{b})","cm");
    c->Update();
    repositionStatbox("hvzl0_2");

    canvaspager(c,outpdf,nPads,canvasCdCounter,canvasPageCounter);
    c->cd(canvasCdCounter);
    doPlot1d(t,"hvrl0", "vrl0", cutsgen, nBins,0,40,"r_{vtx}|(#Lambda_{b}","r_{vtx}|(#Lambda_{b}","cm");
    c->Update();
    repositionStatbox("hvrl0");

    canvaspager(c,outpdf,nPads,canvasCdCounter,canvasPageCounter);
    c->cd(canvasCdCounter);
    doPlot1d(t,"hvrl0_2", "vrl0", cutsgen+"&&"+masscutNarrow, nBins,0,40,"r_{vtx}|(#Lambda_{b} "+masscutNarrowTitle, "r_{vtx}|(#Lambda_{b}","cm");
    c->Update();
    repositionStatbox("hvrl0_2");

    /*
    canvaspager(c,outpdf,nPads,canvasCdCounter,canvasPageCounter);
    c->cd(canvasCdCounter);
    doPlot1d(t,"heta4", "TMath::Abs(etalb)", cutsgen + "&&mlb>5.566&&mlb<5.676",20,0,etamax,"p_{T}(#Lambda_{b}) 5.566 < m_{#Lambda_{b}} < 5.676","p_{T}(#Lambda_{b})","");
    c->Update();
    repositionStatbox("heta4");
    */

    // finalize current page
    c->SaveAs((outpdf + toString(canvasPageCounter) + ".pdf").c_str());

    fout->Write();
}
コード例 #6
0
ファイル: genPlots02.C プロジェクト: frmeier/usercode
// 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();
	tl.SetTextSize(20);
	tl.SetTextFont(4);
	tl.DrawLatex(x1pi,y2pi-1.2,"p(#pi) / 1 GeV");
    }
    for (int i = 0; i!=maxN; i++)
    {
	t->GetEntry(i);
	const double thetapr = 2*TMath::ATan(TMath::Exp(-TMath::Abs(etapr)));
	const double thetapi = 2*TMath::ATan(TMath::Exp(-TMath::Abs(etapi)));
	const double x1=TMath::Abs(vzl0);
	const double y1=vrl0;
	const double x2pr=x1+scalepr*ppr*TMath::Cos(thetapr);
	const double y2pr=y1+scalepr*ppr*TMath::Sin(thetapr);
	const double x2pi=x1+scalepi*ppi*TMath::Cos(thetapi);
	const double y2pi=y1+scalepi*ppi*TMath::Sin(thetapi);
	TArrow *a;
        a = new TArrow(x1,y1,x2pr,y2pr,.01,">");
	a->SetLineColor(24);
	a->Draw();
        a = new TArrow(x1,y1,x2pi,y2pi,.01,">");
	a->SetLineColor(20);
	a->Draw();
	TMarker *m = new TMarker(x1,y1,7);
	m->SetMarkerColor(28);
	m->Draw();
    }
}
コード例 #7
0
//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) { 
				TOBTECTagger = rls[nn].second;
				keep=false; p=nn; break;
			}
		}
		else{	//if event > INT_MAX correct overflow back.
			int evtt = ((rls[nn].first).second).second + INT_MAX;
			evtt = evtt - INT_MAX;
			if(evtt==fMT2tree->misc.Event) {keep=false; p=nn; break;}
		}
	}
	//two additional taggers
	bool beamhalo = false;
	float ho = fMT2tree->misc.MET/fMT2tree->misc.CaloMETRaw;
	if(fMT2tree->misc.CaloMETRaw<=0) ho=999.;
	HOTagger = ho;
	if(fMT2tree->jet[0].lv.DeltaPhi(fMT2tree->jet[1].lv)<0.2 && !(fMT2tree->jet[0].isPFIDMedium)) beamhalo = true;
	ExtraBeamHaloFilter = beamhalo;

	if(keep) TOBTECTagger = -1;
	newtree->Fill();
	if(!keep){
		//remove event from rls vector --> increases speed.
		int tt = p;
		rls.erase(rls.begin()+p);
	}
   }
   newtree->Print();
   newtree->AutoSave();
   delete oldfile;
   delete newfile;
}