void EventListHelper::addFileToList ( const char * file_name, const char * tree_name ) { if(std::string(file_name).find(".root") != std::string::npos) { std::cout << "INFO: Adding root file " << file_name << " containing tree named " << tree_name << " to event list..."; TFile* file = TFile::Open(file_name); if(file->IsOpen()) { TTreeReader reader(tree_name,file); TTreeReaderValue<UInt_t> run(reader,"run"); // aka unsigned int TTreeReaderValue<UInt_t> lumi(reader,"lumi"); // aka unsigned int TTreeReaderValue<ULong64_t> event(reader,"event"); // aka unsigned long long while(reader.Next()) { addEventToList (*run, *lumi, *event); } file->Close(); } else { std::cout << "ERROR: could not open event list file " << file_name << " Cowardly exiting." << std::endl; exit(-1); } } else { std::cout << "ERROR: event list file " << file_name << " does not end with .root. We don't know how to handle this. Cowardly exiting." << std::endl; exit(-1); } if(m_set.size() < 1) { std::cout << "ERROR: event list has size < 1. Did something go wrong when reading it? Cowardly exiting." << std::endl; exit(-1); } std::cout << "INFO: added " << m_set.size() << " events." << std::endl; }
void calculate_b_efficiency() { TH2D * h2_btag_num_b = 0; plot2("btag_num_b"); for (int i = 0; i < gMaxProcess; i++) { if (strstr(gProcess[i].fname, "ttjets") != 0) { h2_btag_num_b = new TH2D(*gHisto2[i]); } } TH2D * h2_btag_denom_b = 0; plot2("btag_denom_b"); for (int i = 0; i < gMaxProcess; i++) { if (strstr(gProcess[i].fname, "ttjets") != 0) { h2_btag_denom_b = new TH2D(*gHisto2[i]); } } TH2D * h2_b_eff = new TH2D(*h2_btag_num_b); h2_b_eff->Divide(h2_btag_num_b, h2_btag_denom_b, 1., 1., "B"); new TCanvas; //h2_b_eff->GetXaxis()->SetRangeUser(5,800); //h2_b_eff->GetYaxis()->SetRangeUser(-2.4,2.4); h2_b_eff->Draw(); TFile * f = new TFile("btag_eff_map.root", "UPDATE"); h2_b_eff->Smooth(); h2_b_eff->Write(); f->Close(); INFO("Written efficiency map for b-quarks to btag_eff_map.root"); TH1D * h1_btag_num_b = h2_btag_num_b->ProjectionX(); TH1D * h1_btag_denom_b = h2_btag_denom_b->ProjectionX(); TH1D * h1_b_eff = new TH1D(*h1_btag_num_b); h1_b_eff->Divide(h1_btag_num_b, h1_btag_denom_b, 1., 1., "B"); TCanvas * b_proj = new TCanvas("b_proj", "b_proj", 800,600); b_proj->cd(); setopt(b_proj); setopt(h1_b_eff); h1_b_eff->SetMarkerStyle(8); h1_b_eff->SetMarkerSize(.7); h1_b_eff->SetTitle(""); h1_b_eff->GetYaxis()->SetTitle("b-tagging efficiency"); h1_b_eff->GetXaxis()->SetTitle("transverse momentum of jets [GeV]"); h1_b_eff->GetXaxis()->CenterTitle(); h1_b_eff->GetYaxis()->SetTitleFont(62); h1_b_eff->GetYaxis()->SetTitleSize(0.04); h1_b_eff->GetYaxis()->SetLabelFont(62); h1_b_eff->GetYaxis()->SetLabelSize(0.04); h1_b_eff->GetXaxis()->SetTitleFont(62); h1_b_eff->GetXaxis()->SetTitleSize(0.04); h1_b_eff->GetXaxis()->SetLabelFont(62); h1_b_eff->GetXaxis()->SetLabelSize(0.04); h1_b_eff->Draw(); lumi(); drawperiod(); }
void buildtupledata(TString code)//(TString collision = "PbPbBJet", TString jetalgo = "akVs4PFJetAnalyzer") { if (!dt(code)) { cout<<"Not data: "<<code<<", exiting..."<<endl; return;} bool PbPb = isPbPb(code); TString sample = getSample(code); jettree = getjettree(code); subTag = subTagging(code); Init(PbPb, sample); TString outputfilenamedj = outputfolder+"/"+code+"_djt.root"; TString outputfilenameinc = outputfolder+"/"+code+"_inc.root"; TString outputfilenameevt = outputfolder+"/"+code+"_evt.root"; TString djvars = TString("run:lumi:event:prew:triggermatched:bin:vz:hiHF:hltCSV60:hltCSV80:hltCaloJet40:hltCaloJet60:hltCaloJet80:hltPFJet60:hltPFJet80:dijet:")+ "hltCalo60jtpt:hltCalo60jtphi:hltCalo60jteta:hltCalo80jtpt:hltCalo80jtphi:hltCalo80jteta:hltCSV60jtpt:hltCSV60jtphi:hltCSV60jteta:hltCSV80jtpt:hltCSV80jtphi:hltCSV80jteta:"+ "rawpt1:jtpt1:jtphi1:jteta1:discr_csvV1_1:svtxm1:discr_prob1:svtxdls1:svtxpt1:svtxntrk1:nsvtx1:nselIPtrk1:"+ "rawpt2:jtpt2:jtphi2:jteta2:discr_csvV1_2:svtxm2:discr_prob2:svtxdls2:svtxpt2:svtxntrk2:nsvtx2:nselIPtrk2:dphi21:"+ "rawpt3:jtpt3:jtphi3:jteta3:discr_csvV1_3:svtxm3:discr_prob3:svtxdls3:svtxpt3:svtxntrk3:nsvtx3:nselIPtrk3:dphi31:dphi32:"+ "SLord:rawptSL:jtptSL:jtphiSL:jtetaSL:discr_csvV1_SL:svtxmSL:discr_probSL:svtxdlsSL:svtxptSL:svtxntrkSL:nsvtxSL:nselIPtrkSL:dphiSL1"; for (auto w:weights) cout<<w<<"\t"; cout<<endl; int totentries = 0; //now fill histos TFile *foutdj = new TFile(outputfilenamedj,"recreate"); TNtuple *ntdj = new TNtuple("nt","ntdj",djvars); TFile *foutinc = new TFile(outputfilenameinc,"recreate"); TNtuple *ntinc = new TNtuple("nt","ntinc","prew:goodevent:bin:vz:hiHF:hltCSV60:hltCSV80:hltCaloJet40:hltCaloJet60:hltCaloJet80:hltPFJet60:hltPFJet80:rawpt:jtpt:jtphi:jteta:discr_csvV1:svtxm:discr_prob:svtxdls:svtxpt:svtxntrk:nsvtx:nselIPtrk"); TFile *foutevt = new TFile(outputfilenameevt,"recreate"); TNtuple *ntevt = new TNtuple("nt","ntinc","prew:bin:vz:hiHF:hltCSV60:hltCSV80"); for (unsigned i=0;i<subfoldernames.size();i++) { //get all files for unmerged forests auto files = list_files(TString::Format("%s/%s/",samplesfolder.Data(),subfoldernames[i].Data())); for (auto filename:files) { cout<<endl<<"Processing file "<<filename<<endl; TFile *f = new TFile(filename); TString treename = jettree;//f->Get(jettree) != 0 ? jettree : "ak3PFJetAnalyzer"; TTreeReader reader(treename,f); TTreeReaderValue<int> nref(reader, "nref"); TTreeReaderArray<float> rawpt(reader, "rawpt"); TTreeReaderArray<float> jtpt(reader, "jtpt"); TTreeReaderArray<float> jteta(reader, "jteta"); TTreeReaderArray<float> jtphi(reader, "jtphi"); TTreeReaderArray<float> discr_csvV1(reader, "discr_csvV1"); TTreeReaderArray<float> discr_prob(reader, "discr_prob"); TTreeReaderArray<float> svtxm(reader, "svtxm"); TTreeReaderArray<float> svtxdls(reader, "svtxdls"); TTreeReaderArray<float> svtxpt(reader, "svtxpt"); TTreeReaderArray<int> svtxntrk(reader, "svtxntrk"); TTreeReaderArray<int> nsvtx(reader, "nsvtx"); TTreeReaderArray<int> nselIPtrk(reader, "nselIPtrk"); TTreeReaderArray<float> *muMax=0, *muMaxTRK=0, *muMaxGBL=0; if (PbPb) { muMax = new TTreeReaderArray<float> (reader, "muMax"); muMaxTRK = new TTreeReaderArray<float>(reader, "muMaxTRK"); muMaxGBL = new TTreeReaderArray<float>(reader, "muMaxGBL"); } //HLT_HIPuAK4CaloBJetCSV80_Eta2p1_v1 HLT_HIPuAK4CaloJet80_Eta5p1_v1 TString calojet40trigger = !PbPb ? "HLT_AK4CaloJet40_Eta5p1_v1" : "HLT_HIPuAK4CaloJet40_Eta5p1_v1"; TString calojet40triggerv2 = !PbPb ? "HLT_AK4CaloJet40_Eta5p1_v1" : "HLT_HIPuAK4CaloJet40_Eta5p1_v2"; TString calojet60trigger = !PbPb ? "HLT_AK4CaloJet60_Eta5p1_v1" : "HLT_HIPuAK4CaloJet60_Eta5p1_v1"; TString calojet80trigger = !PbPb ? "HLT_AK4CaloJet80_Eta5p1_v1" : "HLT_HIPuAK4CaloJet80_Eta5p1_v1"; //dummy vars in PbPb case TString pfjet60trigger = !PbPb ? "HLT_AK4PFJet60_Eta5p1_v1" : "LumiBlock"; TString pfjet80trigger = !PbPb ? "HLT_AK4PFJet80_Eta5p1_v1" : "LumiBlock"; TString csv60trigger = !PbPb ? "HLT_AK4PFBJetBCSV60_Eta2p1_v1" : "HLT_HIPuAK4CaloBJetCSV60_Eta2p1_v1"; TString csv80trigger = !PbPb ? "HLT_AK4PFBJetBCSV80_Eta2p1_v1" : "HLT_HIPuAK4CaloBJetCSV80_Eta2p1_v1"; //PbPb pprimaryVertexFilter && pclusterCompatibilityFilter do nothing vector<TString> filterNames; if (PbPb) filterNames = {"pcollisionEventSelection", "HBHENoiseFilterResultRun2Loose"}; else filterNames = {"pPAprimaryVertexFilter", "HBHENoiseFilterResultRun2Loose", "pBeamScrapingFilter"}; TTreeReader readerhlt("hltanalysis/HltTree",f); TTreeReaderValue<int> PFJet60(readerhlt, pfjet60trigger); TTreeReaderValue<int> PFJet80(readerhlt, pfjet80trigger); TTreeReaderValue<int> CaloJet40(readerhlt, calojet40trigger); TTreeReaderValue<int> CaloJet40v2(readerhlt, calojet40triggerv2); TTreeReaderValue<int> CaloJet60(readerhlt, calojet60trigger); TTreeReaderValue<int> CaloJet80(readerhlt, calojet80trigger); TTreeReaderValue<int> CSV60(readerhlt, csv60trigger); TTreeReaderValue<int> CSV80(readerhlt, csv80trigger); TTreeReader readercsv60object("hltobject/HLT_HIPuAK4CaloBJetCSV60_Eta2p1_v",f); TTreeReaderValue<vector<Double_t> > csv60pt(readercsv60object, "pt"); TTreeReaderValue<vector<Double_t> > csv60eta(readercsv60object, "eta"); TTreeReaderValue<vector<Double_t> > csv60phi(readercsv60object, "phi"); TTreeReader readercsv80object("hltobject/HLT_HIPuAK4CaloBJetCSV80_Eta2p1_v",f); TTreeReaderValue<vector<Double_t> > csv80pt(readercsv80object, "pt"); TTreeReaderValue<vector<Double_t> > csv80eta(readercsv80object, "eta"); TTreeReaderValue<vector<Double_t> > csv80phi(readercsv80object, "phi"); TTreeReader readerCalo60object("hltobject/HLT_HIPuAK4CaloJet60_Eta5p1_v",f); TTreeReaderValue<vector<Double_t> > calo60pt(readerCalo60object, "pt"); TTreeReaderValue<vector<Double_t> > calo60eta(readerCalo60object, "eta"); TTreeReaderValue<vector<Double_t> > calo60phi(readerCalo60object, "phi"); TTreeReader readerCalo80object("hltobject/HLT_HIPuAK4CaloJet80_Eta5p1_v",f); TTreeReaderValue<vector<Double_t> > calo80pt(readerCalo80object, "pt"); TTreeReaderValue<vector<Double_t> > calo80eta(readerCalo80object, "eta"); TTreeReaderValue<vector<Double_t> > calo80phi(readerCalo80object, "phi"); TTreeReader readerevt("hiEvtAnalyzer/HiTree",f); TTreeReaderValue<float> vz(readerevt, "vz"); TTreeReaderValue<int> bin(readerevt, "hiBin"); TTreeReaderValue<float> hiHF(readerevt, "hiHF"); TTreeReaderValue<unsigned int> run(readerevt, "run"); TTreeReaderValue<unsigned int> lumi(readerevt, "lumi"); TTreeReaderValue<unsigned long long> event(readerevt, "evt"); TTreeReader readerskim("skimanalysis/HltTree",f); vector<TTreeReaderValue<int> *>filters; for (auto f:filterNames) filters.push_back(new TTreeReaderValue<int>(readerskim, f)); cout<<"added filters"<<endl; int nev = reader.GetEntries(true); cout<<nev<<endl; totentries+=nev; int onep = nev/100; int evCounter = 0; TTimeStamp t0; //for testing - only 10% of data //while (evCounter<2*onep && reader.Next()) { //go full file while (reader.Next()) { readerhlt.Next(); readerevt.Next(); readerskim.Next(); readercsv60object.Next(); readercsv80object.Next(); readerCalo60object.Next(); readerCalo80object.Next(); evCounter++; if (evCounter%onep==0) { std::cout << std::fixed; TTimeStamp t1; cout<<" \r"<<evCounter/onep<<"% "<<" total time "<<(int)round((t1-t0)*nev/(evCounter+.1))<<" s "<<flush; } int bPFJet60 = !PbPb ? *PFJet60 : 1; int bPFJet80 = !PbPb ? *PFJet80 : 1; //int jet40 = *CaloJet40 || *CaloJet40v2; float weight = 1; if (!PbPb) weight = getweight(subfoldernames[i], bPFJet60, bPFJet80); if (PbPb && sample=="j60") weight = *CaloJet60;//only calojet 40 ntevt->Fill(weight, *bin, *vz, *hiHF, *CSV60, *CSV80); if (weight==0) continue; //good event is vertex cut and noise cuts bool goodevent = abs(*vz)<15; for (auto f:filters) goodevent&=*(*f); int ind1=-1, ind2=-1, ind3=-1, indSL=-1; //indices of leading/subleading jets in jet array int indTrigCSV60=-1, indTrigCSV80=-1, indTrigCalo60=-1, indTrigCalo80=-1; int SLord = 0; bool foundJ1=false, foundJ2 = false, foundJ3 = false, foundSL = false; //found/not found yet, for convenience bool triggermatched = false; if (goodevent) for (int j=0;j<*nref;j++) { //acceptance selection if (abs(jteta[j])>1.5) continue; //muon cuts if (PbPb) { if((*muMax)[j]/rawpt[j]>0.95) continue; if( ((*muMaxTRK)[j]-(*muMaxGBL)[j]) / ((*muMaxTRK)[j]+(*muMaxGBL)[j]) > 0.1) continue; } if (!foundJ1) { //looking for the leading jet ind1 = j; foundJ1=true; if (PbPb) { indTrigCSV60 = triggeredLeadingJetCSV(jtphi[j], jteta[j], *csv60pt, *csv60phi, *csv60eta); indTrigCSV80 = triggeredLeadingJetCSV(jtphi[j], jteta[j], *csv80pt, *csv80phi, *csv80eta); indTrigCalo60 = triggeredLeadingJetCalo(jtphi[j], jteta[j], *calo60pt, *calo60phi, *calo60eta); indTrigCalo80 = triggeredLeadingJetCalo(jtphi[j], jteta[j], *calo80pt, *calo80phi, *calo80eta); } triggermatched = !PbPb || indTrigCSV60!=-1 || indTrigCSV80!=-1; } else if (foundJ1 && !foundJ2) { ind2 = j; foundJ2 = true; } else if (foundJ1 && foundJ2 && !foundJ3) { ind3 = j; foundJ3 = true; } //we need ordinal number of SL jets, so counting until found //indSL != SLord because some jets are not in acceptance region if (!foundSL) SLord++; //ind1!=j otherwise SL will be = J1 if (foundJ1 && ind1!=j && !foundSL && discr_csvV1[j]>0.9) { indSL = j; foundSL = true; } //at this point foundLJ = true always, so triggermatched is determined vector<float> vinc = {weight, (float)triggermatched, (float) *bin, *vz, *hiHF,(float)*CSV60, (float)*CSV80,(float)*CaloJet40, (float)*CaloJet60, (float)*CaloJet80, (float)bPFJet60,(float)bPFJet80, rawpt[j], jtpt[j], jtphi[j], jteta[j], discr_csvV1[j],svtxm[j],discr_prob[j], svtxdls[j],svtxpt[j],(float)svtxntrk[j],(float)nsvtx[j],(float)nselIPtrk[j]}; ntinc->Fill(&vinc[0]); } //fill dijet ntuple vector<float> vdj; vdj = {(float)*run, (float)*lumi, (float)*event, weight, (float)triggermatched, (float)*bin, *vz,*hiHF, (float)*CSV60, (float)*CSV80,(float)*CaloJet40,(float)*CaloJet60, (float)*CaloJet80,(float)bPFJet60,(float)bPFJet80, foundJ1 && foundJ2 ? (float)1 : (float)0, indTrigCalo60!=-1 ? (float)(*calo60pt)[indTrigCalo60] : NaN, indTrigCalo60!=-1 ? (float)(*calo60phi)[indTrigCalo60] : NaN, indTrigCalo60!=-1 ? (float)(*calo60eta)[indTrigCalo60] : NaN, indTrigCalo80!=-1 ? (float)(*calo80pt)[indTrigCalo80] : NaN, indTrigCalo80!=-1 ? (float)(*calo80phi)[indTrigCalo80] : NaN, indTrigCalo80!=-1 ? (float)(*calo80eta)[indTrigCalo80] : NaN, indTrigCSV60!=-1 ? (float)(*csv60pt)[indTrigCSV60] : NaN, indTrigCSV60!=-1 ? (float)(*csv60phi)[indTrigCSV60] : NaN, indTrigCSV60!=-1 ? (float)(*csv60eta)[indTrigCSV60] : NaN, indTrigCSV80!=-1 ? (float)(*csv80pt)[indTrigCSV80] : NaN, indTrigCSV80!=-1 ? (float)(*csv80phi)[indTrigCSV80] : NaN, indTrigCSV80!=-1 ? (float)(*csv80eta)[indTrigCSV80] : NaN, foundJ1 ? rawpt[ind1] : NaN, foundJ1 ? jtpt[ind1] : NaN, foundJ1 ? jtphi[ind1] : NaN, foundJ1 ? jteta[ind1] : NaN, foundJ1 ? discr_csvV1[ind1] : NaN, foundJ1 ? svtxm[ind1] : NaN, foundJ1 ? discr_prob[ind1] : NaN, foundJ1 ? svtxdls[ind1] : NaN, foundJ1 ? svtxpt[ind1] : NaN, foundJ1 ? (float)svtxntrk[ind1] : NaN, foundJ1 ? (float)nsvtx[ind1] : NaN, foundJ1 ? (float)nselIPtrk[ind1] : NaN, foundJ2 ? rawpt[ind2] : NaN, foundJ2 ? jtpt[ind2] : NaN, foundJ2 ? jtphi[ind2] : NaN, foundJ2 ? jteta[ind2] : NaN, foundJ2 ? discr_csvV1[ind2] : NaN, foundJ2 ? svtxm[ind2] : NaN, foundJ2 ? discr_prob[ind2] : NaN, foundJ2 ? svtxdls[ind2] : NaN, foundJ2 ? svtxpt[ind2] : NaN, foundJ2 ? (float)svtxntrk[ind2] : NaN, foundJ2 ? (float)nsvtx[ind2] : NaN, foundJ2 ? (float)nselIPtrk[ind2] : NaN, foundJ2 && foundJ1 ? acos(cos(jtphi[ind2]-jtphi[ind1])) : NaN, foundJ3 ? rawpt[ind3] : NaN, foundJ3 ? jtpt[ind3] : NaN, foundJ3 ? jtphi[ind3] : NaN, foundJ3 ? jteta[ind3] : NaN, foundJ3 ? discr_csvV1[ind3] : NaN, foundJ3 ? svtxm[ind3] : NaN, foundJ3 ? discr_prob[ind3] : NaN, foundJ3 ? svtxdls[ind3] : NaN, foundJ3 ? svtxpt[ind3] : NaN, foundJ3 ? (float)svtxntrk[ind3] : NaN, foundJ3 ? (float)nsvtx[ind3] : NaN, foundJ3 ? (float)nselIPtrk[ind3] : NaN, foundJ3 && foundJ1 ? acos(cos(jtphi[ind3]-jtphi[ind1])) : NaN, foundJ3 && foundJ2 ? acos(cos(jtphi[ind3]-jtphi[ind2])) : NaN, foundSL ? (float)SLord : NaN, foundSL ? rawpt[indSL] : NaN, foundSL ? jtpt[indSL] : NaN, foundSL ? jtphi[indSL] : NaN, foundSL ? jteta[indSL] : NaN, foundSL ? discr_csvV1[indSL] : NaN, foundSL ? svtxm[indSL] : NaN, foundSL ? discr_prob[indSL] : NaN, foundSL ? svtxdls[indSL] : NaN, foundSL ? svtxpt[indSL] : NaN, foundSL ? (float)svtxntrk[indSL] : NaN, foundSL ? (float)nsvtx[indSL] : NaN, foundSL ? (float)nselIPtrk[indSL] : NaN, foundSL && foundJ1 ? acos(cos(jtphi[indSL]-jtphi[ind1])) : NaN}; ntdj->Fill(&vdj[0]); } f->Close(); } } foutevt->cd(); ntevt->Write(); foutevt->Close(); foutdj->cd(); ntdj->Write(); foutdj->Close(); foutinc->cd(); ntinc->Write(); foutinc->Close(); cout<<endl; cout<<"Total input entries "<<totentries<<endl; //making centrality-dependent ntuples //PutInCbins(outputfolder, code, {{0,40}, {80,200}}); if (PbPb && sample=="bjt"){ auto w = calculateWeightsBjet(outputfilenamedj); updatePbPbBtriggerweight(outputfilenamedj,w); updatePbPbBtriggerweight(outputfilenameinc,w); updatePbPbBtriggerweight(outputfilenameevt,w); } else { updateweight(outputfilenamedj); updateweight(outputfilenameinc); updateweight(outputfilenameevt); } }
void makeMuonTimingPlot (std::string fname) { TFile file(fname.c_str()); TDirectoryFile *dir = (TDirectoryFile*)file.Get("Muons"); TList *hlist = dir->GetListOfKeys(); TH1F *h1; bool foundHist = false; for (auto hist : *hlist) { TString name = hist->GetName(); if (!name.Contains("hMuTimeP")) continue; TH1F *h0 = (TH1F*)dir->Get(name.Data()); if (!foundHist) { h1 = (TH1F*)h0->Clone(); h1->Sumw2(); foundHist = true; } else { h1->Add(h0); } } TH1F *h2 = new TH1F("h2", "h2", 200, -100, 100); h2->GetXaxis()->SetTitle("muon time (ns)"); h2->GetYaxis()->SetTitle("Fraction of Muons/ns"); h2->GetYaxis()->SetTitleOffset(1.1); h2->GetXaxis()->SetTitleOffset(0.8); h2->SetTitle("CSC Muon Time"); h2->SetTitleFont(42); h2->SetTitleSize(0.052); h2->Sumw2(); h2->SetLineColor(kCyan+3); h2->SetFillColor(kCyan+3); for (int ibin = 1; ibin <= 200; ibin++) { h2->SetBinContent(ibin, h1->GetBinContent(ibin)); h2->SetBinError(ibin, h1->GetBinError(ibin)); if (ibin == 200) h2->SetEntries(h1->GetEntries()); } TCanvas c1("c1", "c1", 600, 400); gStyle->SetOptStat(""); double rms = h2->GetRMS(); double avg = h2->GetMean(); TLatex cms(0.17, 0.83, "CMS"); cms.SetNDC(); cms.SetTextFont(61); cms.SetTextSize(0.06); TLatex prelim(0.17, 0.81, "Preliminary"); prelim.SetNDC(); prelim.SetTextAlign(13); prelim.SetTextFont(52); prelim.SetTextSize(0.0456); TLatex data(0.17, 0.76, "Data 2016"); data.SetNDC(); data.SetTextAlign(13); data.SetTextFont(52); data.SetTextSize(0.0456); TLatex lumi(0.9, 0.93, "4.0 fb^{-1} (13 TeV)"); lumi.SetNDC(); lumi.SetTextAlign(31); lumi.SetTextFont(42); lumi.SetTextSize(0.052); TLatex mean(0.7, 0.81, Form("Mean %2.1f", avg)); mean.SetNDC(); mean.SetTextAlign(11); mean.SetTextFont(61); mean.SetTextSize(0.06); TLatex stdev(0.7, 0.76, Form("RMS %2.1f", rms)); stdev.SetNDC(); stdev.SetTextAlign(11); stdev.SetTextFont(61); stdev.SetTextSize(0.06); h2->GetXaxis()->SetRangeUser(-6*rms,6*rms); TH1F* h2norm = (TH1F*)h2->DrawNormalized("hist"); gPad->Update(); cms.Draw(); prelim.Draw(); data.Draw(); lumi.Draw(); mean.Draw(); stdev.Draw(); TPaveText *title = (TPaveText*)gPad->GetPrimitive("title"); title->SetBorderSize(0); title->SetFillColor(0); title->SetFillStyle(0); title->SetX1NDC(0.13); title->SetY1NDC(0.88); title->SetX2NDC(0.9); title->SetY2NDC(0.98); title->SetTextFont(42); title->SetTextSize(0.052); title->SetTextAlign(11); c1.Print("plots/muon_time_all.pdf"); c1.Print("plots/muon_time_all.png"); c1.Print("plots/muon_time_all.root"); }
void writeFrames(const Kinect::FrameSource::IntrinsicParameters& ip,const Kinect::FrameBuffer& color,const Kinect::MeshBuffer& mesh,const char* lwoFileName) { /* Create the texture file name: */ std::string textureFileName(lwoFileName,Misc::getExtension(lwoFileName)); textureFileName.append("-color.png"); /* Write the color frame as a texture image: */ { Images::RGBImage texImage(color.getSize(0),color.getSize(1)); Images::RGBImage::Color* tiPtr=texImage.modifyPixels(); const unsigned char* cfPtr=reinterpret_cast<const unsigned char*>(color.getBuffer()); for(int y=0;y<color.getSize(1);++y) for(int x=0;x<color.getSize(0);++x,++tiPtr,cfPtr+=3) *tiPtr=Images::RGBImage::Color(cfPtr); Images::writeImageFile(texImage,textureFileName.c_str()); } /* Open the LWO file: */ IO::FilePtr lwoFile=IO::openFile(lwoFileName,IO::File::WriteOnly); lwoFile->setEndianness(Misc::BigEndian); /* Create the LWO file structure via the FORM chunk: */ { IFFChunkWriter form(lwoFile,"FORM"); form.write<char>("LWO2",4); /* Create the TAGS chunk: */ { IFFChunkWriter tags(&form,"TAGS"); tags.writeString("ColorImage"); tags.writeChunk(); } /* Create the LAYR chunk: */ { IFFChunkWriter layr(&form,"LAYR"); layr.write<Misc::UInt16>(0U); layr.write<Misc::UInt16>(0x0U); for(int i=0;i<3;++i) layr.write<Misc::Float32>(0.0f); layr.writeString("DepthImage"); layr.writeChunk(); } /* Create an index map for all vertices to omit unused vertices: */ unsigned int* indices=new unsigned int[mesh.numVertices]; for(unsigned int i=0;i<mesh.numVertices;++i) indices[i]=~0x0U; unsigned int numUsedVertices=0; /* Create the PNTS, BBOX and VMAP chunks in one go: */ { typedef Kinect::FrameSource::IntrinsicParameters::PTransform PTransform; typedef PTransform::Point Point; typedef Geometry::Box<Point::Scalar,3> Box; IFFChunkWriter bbox(&form,"BBOX"); IFFChunkWriter pnts(&form,"PNTS"); IFFChunkWriter vmap(&form,"VMAP"); /* Write the VMAP header: */ vmap.write<char>("TXUV",4); vmap.write<Misc::UInt16>(2U); vmap.writeString("ColorImageUV"); /* Process all triangle vertices: */ Box pBox=Box::empty; const Kinect::MeshBuffer::Vertex* vertices=mesh.getVertices(); const Kinect::MeshBuffer::Index* tiPtr=mesh.getTriangleIndices(); for(unsigned int i=0;i<mesh.numTriangles*3;++i,++tiPtr) { /* Check if the triangle vertex doesn't already have an index: */ if(indices[*tiPtr]==~0x0U) { /* Assign an index to the triangle vertex: */ indices[*tiPtr]=numUsedVertices; /* Transform the mesh vertex to camera space using the depth projection matrix: */ Point dp(vertices[*tiPtr].position.getXyzw()); Point cp=ip.depthProjection.transform(dp); /* Transform the depth-space point to texture space using the color projection matrix: */ Point tp=ip.colorProjection.transform(dp); /* Add the point to the bounding box: */ pBox.addPoint(cp); /* Store the point and its texture coordinates: */ pnts.writePoint(cp); vmap.writeVarIndex(numUsedVertices); for(int i=0;i<2;++i) vmap.write<Misc::Float32>(tp[i]); ++numUsedVertices; } } /* Write the bounding box: */ bbox.writeBox(pBox); /* Write the BBOX, PNTS, and VMAP chunks: */ bbox.writeChunk(); pnts.writeChunk(); vmap.writeChunk(); } /* Create the POLS chunk: */ { IFFChunkWriter pols(&form,"POLS"); pols.write<char>("FACE",4); const Kinect::MeshBuffer::Index* tiPtr=mesh.getTriangleIndices(); for(unsigned int triangleIndex=0;triangleIndex<mesh.numTriangles;++triangleIndex,tiPtr+=3) { pols.write<Misc::UInt16>(3U); for(int i=0;i<3;++i) pols.writeVarIndex(indices[tiPtr[2-i]]); } pols.writeChunk(); } /* Delete the vertex index map: */ delete[] indices; /* Create the PTAG chunk: */ { IFFChunkWriter ptag(&form,"PTAG"); ptag.write<char>("SURF",4); for(unsigned int triangleIndex=0;triangleIndex<mesh.numTriangles;++triangleIndex) { ptag.writeVarIndex(triangleIndex); ptag.write<Misc::UInt16>(0U); } ptag.writeChunk(); } /* Create the CLIP chunk: */ { IFFChunkWriter clip(&form,"CLIP"); clip.write<Misc::UInt32>(1U); /* Create the STIL chunk: */ { IFFChunkWriter stil(&clip,"STIL",true); stil.writeString(textureFileName.c_str()); stil.writeChunk(); } clip.writeChunk(); } /* Create the SURF chunk: */ { IFFChunkWriter surf(&form,"SURF"); surf.writeString("ColorImage"); surf.writeString(""); /* Create the SIDE subchunk: */ { IFFChunkWriter side(&surf,"SIDE",true); side.write<Misc::UInt16>(3U); side.writeChunk(); } /* Create the SMAN subchunk: */ { IFFChunkWriter sman(&surf,"SMAN",true); sman.write<Misc::Float32>(Math::rad(90.0f)); sman.writeChunk(); } /* Create the COLR subchunk: */ { IFFChunkWriter colr(&surf,"COLR",true); colr.writeColor(1.0f,1.0f,1.0f); colr.writeVarIndex(0U); colr.writeChunk(); } /* Create the DIFF subchunk: */ { IFFChunkWriter diff(&surf,"DIFF",true); diff.write<Misc::Float32>(1.0f); diff.writeVarIndex(0U); diff.writeChunk(); } /* Create the LUMI subchunk: */ { IFFChunkWriter lumi(&surf,"LUMI",true); lumi.write<Misc::Float32>(0.0f); lumi.writeVarIndex(0U); lumi.writeChunk(); } /* Create the BLOK subchunk: */ { IFFChunkWriter blok(&surf,"BLOK",true); /* Create the IMAP subchunk: */ { IFFChunkWriter imap(&blok,"IMAP",true); imap.writeString("1"); /* Create the CHAN subchunk: */ { IFFChunkWriter chan(&imap,"CHAN",true); chan.write<char>("COLR",4); chan.writeChunk(); } imap.writeChunk(); } /* Create the PROJ subchunk: */ { IFFChunkWriter proj(&blok,"PROJ",true); proj.write<Misc::UInt16>(5U); proj.writeChunk(); } /* Create the IMAG subchunk: */ { IFFChunkWriter imag(&blok,"IMAG",true); imag.writeVarIndex(1U); imag.writeChunk(); } /* Create the VMAP subchunk: */ { IFFChunkWriter vmap(&blok,"VMAP",true); vmap.writeString("ColorImageUV"); vmap.writeChunk(); } blok.writeChunk(); } /* Write the SURF chunk: */ surf.writeChunk(); } /* Write the FORM chunk: */ form.writeChunk(); } }