void GetRandomTest(){ double k0=1.39; double k1 = 0.425; double theta0 = 3.41; double theta1 = 1.30; int iNpart=2; double k_=k0+k1*(iNpart-2); double theta_=theta0+theta1*TMath::Log(iNpart-1); TF1 *f = new TF1("f","TMath::GammaDist(x,[0],0,[1])",0,200); f->SetParameters(k1,theta_); cout<<"Value at 0 = "<<f->Eval(0)<<endl; cout<<"Value at 1e-11 = "<<f->Eval(1e-11)<<endl; cout<<"Integral 1= "<<f->Integral(f->GetXmin(),f->GetXmax())<<endl; f->SetRange(1e-12,200); cout<<"Integral 2= "<<f->Integral(f->GetXmin(),f->GetXmax())<<endl; cout<<"fXmin = "<<f->GetXmin()<<"\tfXmax = "<<f->GetXmax()<<"\tfNpx = "<<f->GetNpx()<<endl; f->SetNpx(1e5); TCanvas *c1 = new TCanvas(); c1->SetLogy(); cout<<"f mean = "<<f->Mean(0,200)<<endl; cout<<"math mean = "<<f->GetParameter(0)*f->GetParameter(1)<<endl; TH1D* h = new TH1D("h","h",1000,0,200); for(int i=0;i<1e6;i++){ double para = f->GetRandom(); h->Fill(para); } h->Scale(1.0/h->Integral()*1000/200); h->GetYaxis()->SetRangeUser(1e-10,1); h->SetMarkerStyle(24); h->SetMarkerColor(4); h->SetMarkerSize(1.1); TLegend *leg = new TLegend(0.6,0.7,0.8,0.9); leg->SetFillColor(0); leg->SetFillStyle(0); leg->SetBorderSize(0); leg->SetTextFont(42); leg->SetTextSize(0.03); leg->AddEntry(f,"function","lp"); leg->AddEntry(h,"filled histogram","lp"); h->Draw("P"); f->Draw("same"); leg->Draw("same"); cout<<"h mean = "<<h->GetMean(1)<<endl; c1->Print("TestGetRandom.png"); }
//Plot channels with multiple hits void PlotMultCh(int run) { etf.SetPath(mypath.Data()); etf.Open(run); int maxch = MAXCH*MAXRIO; TH1D* h = MakeHist("hnch",maxch); for (int i=0;i<etf.GetNumEvents();i++) { etf.GetEvent(i); int nch = 0; for (int ch=0;ch<maxch;ch++) { if (etf.myEvent.E[ch] > 0) nch++; } if (nch > 1) for (int ch=0;ch<maxch;ch++) { if (etf.myEvent.E[ch] > 0) h->Fill(ch); } } h->Draw(); }
void SearchBinEventCount::Fill(double HT, double MHT, int NJets, int BTags, double Weight) { double bin = GetBinNumber(HT,MHT,NJets,BTags); if(bin<bins_.size()+2) { fullTH1D_->Fill(bin-0.01, Weight); unsigned int splitHist=0; // std::cout<<"bin before split: "<<bin<<std::endl; for(int ii=0;bin>splitAfter_;ii++) { splitHist++; bin = bin-splitAfter_; } // if(splitHist==3)std::cout<<"BinForSplit: "<<bin<<" with splitHistNumber "<<splitHist<<" and TH1DSearchBinsSplit_.size(): "<<TH1DSearchBinsSplit_.size()<<std::endl; splitTH1D_[splitHist]->Fill(bin-0.1, Weight); } }
//################################################################################################################################ // Get the 68% confindence interval of mu1/mu2 void getPoissonIntervalls(double mu1, double mu2){ double result = mu1/mu2; TH1D *expHist = new TH1D("mu1/mu2","mu1/mu2",1000,0,1); TRandom3 rand1(0); TRandom3 rand2(0); cout<<"mu1 = "<<mu1<<endl; cout<<"mu2 = "<<mu2<<endl; cout<<"ratio = "<<result<<endl; for(int i=0; i<10000000; i++){ expHist->Fill(1.*rand1.Poisson(mu1)/rand2.Poisson(mu2)); } // Get now the 68% upper and lower interval double errUp = 0; double errLow = 0; for(int i=1; i<=expHist->GetNbinsX();i++){ double upperIntegral = expHist->Integral(i,expHist->GetNbinsX()); double lowerIntegral = expHist->Integral(1,i); if(abs(upperIntegral/expHist->Integral()-0.32)<0.02){ cout<<"upper bound = "<<expHist->GetBinCenter(i)<<endl; errUp = expHist->GetBinCenter(i)-result; } if(abs(lowerIntegral/expHist->Integral()-0.32)<0.02){ cout<<"lower bound = "<<expHist->GetBinCenter(i)<<endl; errLow = result - expHist->GetBinCenter(i); } } cout<<"error Up = "<<errUp<<endl; cout<<"error Low = "<<errLow<<endl; TCanvas *c = new TCanvas("cExp","cExp",0,0,500,500); c->cd(); expHist->Draw(); }
void L3_pValues(double l0, double l1, double Metl, double ll, int Jets) { InitExterns(); RAND.SetSeed(5); Data d(l0,l1,Metl,ll,Jets); TH1D* h_b = Likelihood::GetBGEstimation(d); TH1D* h_pValues = new TH1D("pvalues","pvalues",22,0,1.1); int numMC = 200; for (int i=0; i<numMC; i++) { if (i % (numMC/10) == 0){ cout << i*(100./numMC) << "%-" << flush;} Data dRand; dRand = Toys::ToyData(d,h_b); TH1D* h_b_rand = Likelihood::GetBGEstimation(dRand); TH1D* pdf = new TH1D("pdf","pdf",100000,0,100); int numMC2 = 500; for (int j=0; j<numMC2; j++) { Data dToy; dToy = Toys::ToyData(dRand,h_b_rand); double qZero = Likelihood::qZero(dToy); dToy.free(); pdf->Fill(qZero,1./numMC2); } double obs = Likelihood::qZero(dRand); dRand.free(); // pdf->Draw(); double pV = utilities::pValue(pdf,obs); delete pdf; delete h_b_rand; h_pValues->Fill(pV,1./numMC); } h_pValues->Draw(); TFile* file = new TFile("f5.root","RECREATE"); h_pValues->Write("L3_pValues"); file->Close(); }
double FitConfidence::choleskyUncertainty( double xx, double * fCov, TF1 * f, int nSamples ){ int nP = f->GetNpar(); INFO( FitConfidence::classname(), "Num Params : " << nP ); double *fCovSqrt = new double[ nP * nP ]; calcCholesky( nP, fCov, fCovSqrt ); double yerr = 0; TH1D *hDistributionAtX = new TH1D("hDistributionAtX","",200,f->Eval(xx) - .2,f->Eval(xx) + .2); for (int n = 0; n < nSamples; n++ ) { double val = randomSqrtCov(xx,f,nP,fCovSqrt); hDistributionAtX->Fill( val ); } yerr = hDistributionAtX->GetRMS(); hDistributionAtX->Delete(); return yerr; }
void drawJacob(string fnm="../../output/thinRadiator/o_msc_L001um_03MeV_1e5ev.root"){ TFile *fin=TFile::Open(fnm.c_str(),"READ"); TTree *t=(TTree*)fin->Get("t"); int material, pType, trackID, parentID; double pX, pY, pZ; t->SetBranchAddress("pType", &pType); t->SetBranchAddress("material", &material); t->SetBranchAddress("trackID", &trackID); t->SetBranchAddress("parentID", &parentID); t->SetBranchAddress("postMomX", &pX); t->SetBranchAddress("postMomY", &pY); t->SetBranchAddress("postMomZ", &pZ); int nev = t->GetEntries(); TH1D *scatAng = new TH1D("scatAng","Rate/sin(theta); scattering angle [deg]", 400,0,100); double pi = acos(-1); cout<<"pi "<<pi<<endl; for(int i=0;i<nev;i++){ t->GetEntry(i); if(pType!=11) continue; if(material != 1) continue; if(trackID != 1 || parentID!=0) continue; double r = sqrt( pX*pX + pY*pY + pZ*pZ); if(r==0) continue; double thetaRad = acos(pZ/r); double theta = thetaRad * 180/pi; if(theta<0.01) continue; scatAng->Fill(theta, 1./sin(thetaRad)); } gStyle->SetOptStat("eMRou"); scatAng->DrawCopy(); fin->Close(); }
int main(int argc, char *argv[]) { int binCount = 100; if (argc > 2) { std::cout << "too many argument. exit." << std::endl; std::exit(1); } else if (argc == 2) { binCount = std::atoi(argv[1]); --argc; } TApplication app("app", &argc, argv); gStyle->SetOptStat(0); TH1D *hist = new TH1D("hist", "ns vs count", binCount, minNanoSec, maxNanoSec); char filename[256]; GetFileName(filename, "../data/muon_lifetime/muon_lifetime.dat"); std::ifstream ifs(filename); for (int i = 0; !ifs.eof(); ++i) { Double_t data; ifs >> data; if (data) { NanoSecWithError ns; ConvertTdcChannelToNanoSec(i%8, data, &ns); hist->Fill(ns.time); } } hist->Draw(); TF1 *fit = new TF1("fit", "[0] * exp(- x / [1]) + [2]", 1000, 20000); fit->SetParameters(200, 2100, 40); hist->Fit(fit, "R+"); std::cout << "chi^2/ndf: "; std::cout << fit->GetChisquare() / fit->GetNDF() << std::endl; app.Run(); return 0; }
TH1D* LoopGen(TTree* ntuple,double ptmin,double ptmax){ int Run,size; bool cut_yvsRun,cut_pt; Float_t gen[NUM_BX]; Float_t pdgId[NUM_BX]; Float_t isSignal[NUM_BX]; Float_t y[NUM_BX]; Float_t pt[NUM_BX]; ntuple->SetBranchAddress("size",&size); ntuple->SetBranchAddress("Run",&Run); ntuple->SetBranchAddress("gen",gen); ntuple->SetBranchAddress("pdgId",pdgId); ntuple->SetBranchAddress("isSignal",isSignal); ntuple->SetBranchAddress("y",y); ntuple->SetBranchAddress("pt",pt); TH1D *hPtMCGen = new TH1D("hPtMCGen","",nBins,ptBins); Int_t entries = (Int_t)ntuple->GetEntries(); for (int i=0; i<entries; i++) { ntuple->GetEntry(i); for(int j=0;j<size;j++){ cut_yvsRun=((Run<=1&&abs(y[j]+0.465)<1.93)||(Run>1&&abs(y[j]-0.465)<1.93))&&abs(pdgId[j])==511&&isSignal[j]!=0; cut_pt=((pt[j]>ptmin)&&(pt[j]<ptmax)); if(cut_yvsRun&&cut_pt) hPtMCGen->Fill(pt[j]); }//loop over candidates }// loop over events return hPtMCGen; }
void test_mc_rejection_method_lin() { const int N = 500000; const int nbins = 300; const double ymax = 1.1; const double xmin = 0; const double xmax = 10; const double dx = xmax-xmin; TRandom rg; TF1 * func = new TF1 ("func","1/(x+1)",0,10); TH1D * hgen = new TH1D ("hgen","generated",nbins,xmin,xmax); for(int i=0; i<N; i++) { cout << "..................." << i << endl; bool selected=false; while(1) { double xg = xmin + rg.Uniform() * dx; double yg = ymax * rg.Uniform(); double yc = func->Eval(xg); selected = (yg<yc); if(selected) { hgen->Fill(xg); break; } } } double IF = func->Integral(xmin,xmax); double IH = hgen->Integral("width"); double sc = IF/IH; hgen->Scale(sc); hgen->Draw(); func->Draw("same"); }
TH1D *getpuweights(TFile *file, TH1D *target) { TDirectory *dirmcpv = (TDirectory*)file->FindObjectAny("AnaFwkMod"); TH1D *hnpu = (TH1D*)dirmcpv->Get("hNPU"); TH1D *hpumc = (TH1D*)hnpu->Clone(); hpumc->Sumw2(); hpumc->Scale(1.0/hpumc->Integral(0,hpumc->GetNbinsX()+1)); TH1D *htargettmp = new TH1D("htargettmp","", hpumc->GetNbinsX(), hpumc->GetXaxis()->GetXmin(), hpumc->GetXaxis()->GetXmax()); htargettmp->Sumw2(); for (int ibin = 0; ibin<=(htargettmp->GetNbinsX()+1); ++ibin) { htargettmp->Fill(htargettmp->GetBinCenter(ibin),target->GetBinContent(target->FindFixBin(htargettmp->GetBinCenter(ibin)))); } htargettmp->Scale(1.0/htargettmp->Integral(0,htargettmp->GetNbinsX()+1)); TH1D *puweights = new TH1D((*htargettmp)/(*hpumc)); delete htargettmp; return puweights; }
//************************************************************************************************* //Main part of the macro //************************************************************************************************* void AnalyzeYYPhotonEvent(const string InputFilename) { TTree* YYTree = getTreeFromFile(InputFilename.c_str()); assert(YYTree); YYPhotonEvent photon(YYTree); TH1D *plot = new TH1D("hPlot", ";XAxis; Number of Events ", 6, -3,3); for (int n=0;n<YYTree->GetEntries();n++) { photon.GetEntry(n); Double_t weight = photon.photon_branch_weight; //cout << weight << " " << photon.photon_branch_NPhotons << endl; if (photon.photon_branch_NPhotons > 0 ) { plot->Fill(photon.photon_branch_Photon1Eta); } } TCanvas *c = new TCanvas("canvas" , "canvas" , 800, 600); plot->DrawCopy(); }
void DrawphiDis() { int ifile=0; TFile *f = TFile::Open(Form("/cms/store/user/qixu/flow/NewSTEG/pPbDataV205m300/vndata_50k_%d.root",ifile)); TTree *t = (TTree*)f->Get("tree"); Float_t eta[1000]; Float_t phi[1000]; TH1D* hphi = new TH1D("hphi","hphi",100,-2.4,2.4); int n; t->SetBranchAddress("etag",eta); t->SetBranchAddress("phig",phi); t->SetBranchAddress("n",&n); Int_t N = t->GetEntries(); for(int ievt=0; ievt<N; ievt++) { // if(ievt!=0) continue; // if(ievt%50000==0) cout<<"Processing "<<ievt<<" events"<<endl; t->GetEntry(ievt); for(int imult = 0; imult<n; imult++) { hphi->Fill(eta[imult]); } } // cout<<hphi->Integral("width")/2/TMath::Pi()<<endl; // cout<<hphi->GetMean(2)<<endl; hphi->Draw(); }
int main(int argc, char *argv[]){ ///////////////////////////////////// if (argc != 6) { std::cout << "Please enter something like: ./run \"filelist_WJets_PU20bx25_100_200.txt\" \"WJets_PU20bx25_100_200\" \"Results\" \"00\" \"0\" " << std::endl; return EXIT_FAILURE; } //get the inputs from user const string InRootList = argv[1]; const string subSampleKey = argv[2]; const string Outdir = argv[3]; const string inputnumber = argv[4]; const string verbosity = argv[5]; ////////////////////////////////////// int verbose = atoi(verbosity.c_str()); //some varaibles char filenames[500]; vector<string> filesVec; ifstream fin(InRootList.c_str()); TChain *sample_AUX = new TChain("TreeMaker2/PreSelection"); char tempname[200]; vector<TH1D > vec; map<int, string> eventType; map<string , vector<TH1D> > cut_histvec_map; map<string, map<string , vector<TH1D> > > map_map; map<string, histClass> histobjmap; histClass histObj; //build a vector of histograms TH1D weight_hist = TH1D("weight", "Weight Distribution", 5,0,5); vec.push_back(weight_hist); TH1D RA2HT_hist = TH1D("HT","HT Distribution",50,0,5000); RA2HT_hist.Sumw2(); vec.push_back(RA2HT_hist); TH1D RA2MHT_hist = TH1D("MHT","MHT Distribution",100,0,5000); RA2MHT_hist.Sumw2(); vec.push_back(RA2MHT_hist); TH1D RA2NJet_hist = TH1D("NJet","Number of Jets Distribution",20,0,20); RA2NJet_hist.Sumw2(); vec.push_back(RA2NJet_hist); TH1D RA2NBtag_hist = TH1D("NBtag","Number of Btag Distribution",20,0,20); RA2NBtag_hist.Sumw2(); vec.push_back(RA2NBtag_hist); int Nhists=((int)(vec.size())-1);//-1 is because weight shouldn't be counted. ///read the file names from the .txt files and load them to a vector. while(fin.getline(filenames, 500) ){filesVec.push_back(filenames);} cout<< "\nProcessing " << subSampleKey << " ... " << endl; for(unsigned int in=0; in<filesVec.size(); in++){ sample_AUX->Add(filesVec.at(in).c_str()); } // --- Analyse the events -------------------------------------------- // Interface to the event content Events * evt = new Events(sample_AUX, subSampleKey,verbose); // Get a pointer to the Selection class Selection2 * sel = new Selection2(); // For each selection, cut, make a vector containing the same histograms as those in vec for(int i=0; i<(int) sel->cutName().size();i++){ cut_histvec_map[sel->cutName()[i]]=vec; } // Define different event categories eventType[0]="allEvents"; //initialize a map between string and maps. copy the map of histvecs into each for(int i=0; i< eventType.size();i++){ map_map[eventType[i]]=cut_histvec_map; } //initialize histobjmap for(map<string , vector<TH1D> >::iterator it=cut_histvec_map.begin(); it!=cut_histvec_map.end();it++){ histobjmap[it->first]=histObj; } TH1D* TauIDhist = new TH1D("yield_tauId","Yield after tau Id",200,0.,200.); TH1D* TauIDhist_trk = new TH1D("yield_tauId_trk","Yield after trk veto and tau Id",200,0.,200.); map <int,string> idMap; int IdNum_=0; for(int iPile=0;iPile<4;iPile++){ for(int iIso=0;iIso<4;iIso++){ for(int iMu=0;iMu<3;iMu++){ for(int iElec=0;iElec<4;iElec++){ IdNum_++; ostringstream binS_; binS_ << (1+iPile)+10*(1+iIso)+100*(1+iMu)+1000*(1+iElec); idMap[IdNum_]=binS_.str(); TauIDhist->GetXaxis()->SetBinLabel(IdNum_,binS_.str().c_str()); TauIDhist_trk->GetXaxis()->SetBinLabel(IdNum_,binS_.str().c_str()); } } } } // Introduce cutflow histogram to monior event yields for early preselection TH1D* cutflow_preselection = new TH1D("cutflow_preselection","cutflow_preselectoion", 11,0.,11.); cutflow_preselection->GetXaxis()->SetBinLabel(1,"All Events"); cutflow_preselection->GetXaxis()->SetBinLabel(2,"Sample based gen-selection"); cutflow_preselection->GetXaxis()->SetBinLabel(3,"HBHEIsoNoiseFilter"); cutflow_preselection->GetXaxis()->SetBinLabel(4,"eeBadScFilter"); cutflow_preselection->GetXaxis()->SetBinLabel(5,"HBHENoiseFilter"); cutflow_preselection->GetXaxis()->SetBinLabel(6,"GoodVtx"); cutflow_preselection->GetXaxis()->SetBinLabel(7,"JetID Cleaning"); int sampletype=-1; if(subSampleKey.find("TTbar_Inclusive")!=string::npos)sampletype=0; //TTbar_Inclusive else if(subSampleKey.find("TTbar_Tbar_SingleLep")!=string::npos || subSampleKey.find("TTbar_T_SingleLep")!=string::npos)sampletype=1; else if(subSampleKey.find("TTbar_DiLept")!=string::npos)sampletype=2; else if(subSampleKey.find("TTbar_HT_600_800")!=string::npos)sampletype=3; else if(subSampleKey.find("TTbar_HT_800_1200")!=string::npos)sampletype=4; else if(subSampleKey.find("TTbar_HT_1200_2500")!=string::npos)sampletype=5; else if(subSampleKey.find("TTbar_HT_2500_Inf")!=string::npos)sampletype=6; else if(subSampleKey.find("TTbar")!=string::npos){ cout << " TT sample is not known. Please check the second input \n " ; return 2; } int TotNEve_ = utils2::TotNEve(subSampleKey); // Loop over the events (tree entries) int eventN=0; while( evt->loadNext() ){ //if(eventN>1000)break; // Total weight //double totWeight = evt->weight()*1.; double totWeight = 10000.*evt->XS()/TotNEve_; //printf(" XS: %g NEvents: %d weight: %g \n ",evt->XS(),TotNEve_,totWeight); cutflow_preselection->Fill(0.,totWeight); // keep track of all events processed if(!evt->DataBool_()){ if(sampletype==0){ if(evt->gen_ht()>600||evt->GenElecPtVec_().size()>0||evt->GenMuPtVec_().size()>0||evt->GenTauPtVec_().size()>0)continue; } if(sampletype==1){ if(evt->gen_ht()>600)continue; } if(sampletype==2){ if(evt->gen_ht()>600)continue; } } cutflow_preselection->Fill(1.,totWeight); if(evt->HBHEIsoNoiseFilter_()==0)continue; cutflow_preselection->Fill(2.,totWeight); if(evt->eeBadScFilter_()==0)continue; cutflow_preselection->Fill(3.,totWeight); if(evt->HBHENoiseFilter_()==0)continue; cutflow_preselection->Fill(4.,totWeight); if(!(evt->NVtx_() >0))continue; cutflow_preselection->Fill(5.,totWeight); // Through out an event that contains HTjets with bad id if(evt->JetId()==0)continue; cutflow_preselection->Fill(6.,totWeight); // events passing JetID event cleaning vector<TLorentzVector> genTauJetLorVec; for(int i=0;i<evt->GenTauLorVec()->size();i++){ TLorentzVector tempVec(evt->GenTauLorVec()->at(i).Px()-evt->GenTauNuLorVec()->at(i).Px(), evt->GenTauLorVec()->at(i).Py()-evt->GenTauNuLorVec()->at(i).Py(), evt->GenTauLorVec()->at(i).Pz()-evt->GenTauNuLorVec()->at(i).Pz(), evt->GenTauLorVec()->at(i).Energy()-evt->GenTauNuLorVec()->at(i).Energy() ); genTauJetLorVec.push_back(tempVec); } if(verbose!=0){ printf(" ############# \n Number of gen tau: %d \n ",evt->GenTauPtVec_().size()); for(int i=0; i < genTauJetLorVec.size(); i++){ if(evt->GenTauHadVec_()[i]==1 && genTauJetLorVec.at(i).Pt() > 18.){ printf(" genTauJet: Pt: %g Eta: %g Phi: %g \n ",genTauJetLorVec.at(i).Pt(),genTauJetLorVec.at(i).Eta(),genTauJetLorVec.at(i).Phi()); for(int i=0; i<evt->TauLorVec_()->size(); i++){ printf(" \n patTau: pt: %g eta: %g phi: %g \n ",evt->TauLorVec_()->at(i).Pt(),evt->TauLorVec_()->at(i).Eta(),evt->TauLorVec_()->at(i).Phi()); printf(" Tauid => id1: %g id2: %g id3: %g id4: %g id5: %g id6: %g id7: %g id8: %g id9: %g id10: %g id11: %g \n ",evt->tauId1()->at(i),evt->tauId2()->at(i),evt->tauId3()->at(i),evt->tauId4()->at(i),evt->tauId5()->at(i),evt->tauId6()->at(i),evt->tauId7()->at(i),evt->tauId8()->at(i),evt->tauId9()->at(i),evt->tauId10()->at(i),evt->tauId11()->at(i)); } } } } //printf("nTau=> 2233: %d 2243: %d 2333: %d 4333: %d 1333: %d \n ",evt->nTauMap()[2233],evt->nTauMap()[2243],evt->nTauMap()[2333],evt->nTauMap()[4333],evt->nTauMap()[1333]); // Print out some information if(verbose!=0){ printf(" ########################### \n event #: %d \n",eventN); printf(" ht: %g mht: %g nJets: %d nBtags: %d nIsoElec: %d nIsoMu: %d nIsoPion: %d nLeptons: %d \n ",evt->ht(),evt->mht(),evt->nJets(),evt->nBtags(),evt->nIsoElec(),evt->nIsoMu(),evt->nIsoPion(),evt->nLeptons()); printf(" @@@@\n Jets section: \n Njets: %d \n ", evt->nJets()); for(int i=0;i<evt->JetsPtVec_().size();i++){ printf("jet#: %d pt: %g eta: %g phi: %g \n ",i+1,evt->JetsPtVec_()[i],evt->JetsEtaVec_()[i],evt->JetsPhiVec_()[i]); } printf(" @@@@\n Muons section: \n Nmuons: %d \n ", evt->MuPtVec_().size()); for(int i=0;i<evt->MuPtVec_().size();i++){ printf("Muon#: %d pt: %g eta: %g phi: %g \n ",i+1,evt->MuPtVec_()[i],evt->MuEtaVec_()[i],evt->MuPhiVec_()[i]); } } //printf(" mu from tau: %d elec from tau : %d hadronicTau: %d \n ", evt->GenMu_GenMuFromTau_(), evt->GenElec_GenElecFromTau_(),evt->GenTau_GenTauHad_()); //printf(" #Mu: %d #Tau: %d \n ", evt->GenMuPtVec_().size(), evt->GenTauPtVec_().size()); // count the number of taus for all possible combinations of tau id s vector<int> NtauVec(200,0); // apply the baseline cuts here to study the tau id s if(sel->nolep(evt->nLeptons())&&sel->Njet_4(evt->nJets())&&sel->ht_500(evt->ht())&& sel->mht_200(evt->mht())&&sel->MuIsoTrk(evt->nIsoMu())&&sel->ElecIsoTrk(evt->nIsoElec())&& sel->dphi(evt->deltaPhi1(),evt->deltaPhi2(),evt->deltaPhi3(),evt->deltaPhi4())) { for(int i=0; i<evt->TauLorVec_()->size(); i++){ // 4 categories of tau id. First is anti-elec which has 3 id's. We also insert a 1 which means non of them are applied. // the following 4 lines correspond whith each of the categories in the tau id. int tauIdElec[4]={1,(int)evt->tauId1()->at(i),(int)evt->tauId2()->at(i),(int)evt->tauId3()->at(i)}; int tauIdMu[3] ={1,(int)evt->tauId4()->at(i),(int)evt->tauId5()->at(i)}; int tauIdIso[4] ={1,(int)evt->tauId6()->at(i),(int)evt->tauId7()->at(i),(int)evt->tauId8()->at(i)}; int tauIdPile[4]={1,(int)evt->tauId9()->at(i),(int)evt->tauId10()->at(i),(int)evt->tauId11()->at(i)}; /* printf(" id1: %d id2: %d id3: %d id4: %d id5: %d id6: %d id7: %d id8: %d id9: %d id10: %d id11: %d \n", (int)evt->tauId1()->at(i),(int)evt->tauId2()->at(i),(int)evt->tauId3()->at(i),(int)evt->tauId4()->at(i), (int)evt->tauId5()->at(i),(int)evt->tauId6()->at(i),(int)evt->tauId7()->at(i),(int)evt->tauId8()->at(i), (int)evt->tauId9()->at(i),(int)evt->tauId10()->at(i),(int)evt->tauId11()->at(i)); */ int IdNum=0; for(int iPile=0;iPile<(sizeof(tauIdPile)/sizeof(tauIdPile[0]));iPile++){ for(int iIso=0;iIso<(sizeof(tauIdIso)/sizeof(tauIdIso[0]));iIso++){ for(int iMu=0;iMu<(sizeof(tauIdMu)/sizeof(tauIdMu[0]));iMu++){ for(int iElec=0;iElec<(sizeof(tauIdElec)/sizeof(tauIdElec[0]));iElec++){ IdNum++; if(tauIdElec[iElec]==1&&tauIdMu[iMu]==1&&tauIdIso[iIso]==1&&tauIdPile[iPile]==1)NtauVec[IdNum]++; //printf(" iPile: %d => %d iIso: %d => %d iMu: %d => %d iElec: %d => %d \n",iPile,tauIdPile[iPile],iIso,tauIdIso[iIso],iMu,tauIdMu[iMu],iElec,tauIdElec[iElec]); //printf(" id #: %d nTau: %d \n ",IdNum,NtauVec[IdNum]); } } } } } for(int iId=0; iId<NtauVec.size();iId++){ //printf(" @ \n iId: %d -> %s \n ",iId,idMap[iId].c_str()); if(NtauVec[iId]==0){ TauIDhist->Fill(iId-1,totWeight); //cout << " filled \n "; if(sel->PionIsoTrk(evt->nIsoPion()))TauIDhist_trk->Fill(iId-1,totWeight); } } } // Build and array that contains the quantities we need a histogram for. // Here order is important and must be the same as RA2nocutvec double eveinfvec[] = {totWeight,(double) evt->ht(),(double) evt->mht() ,(double) evt->nJets(),(double) evt->nBtags()}; //the last one gives the RA2 defined number of jets. //loop over all the different backgrounds: "allEvents", "Wlv", "Zvv" for(map<string, map<string , vector<TH1D> > >::iterator itt=map_map.begin(); itt!=map_map.end();itt++){//this will be terminated after the cuts ////determine what type of background should pass if(itt->first=="allEvents"){//all the cuts are inside this //Cuts//Cuts//Cuts//Cuts//Cuts//Cuts//Cuts//Cuts//Cuts//Cuts//Cuts//Cuts//Cuts//Cuts//Cuts//Cuts//Cuts//Cuts//Cuts//Cuts //////loop over cut names and fill the histograms for(map<string , vector<TH1D> >::iterator ite=cut_histvec_map.begin(); ite!=cut_histvec_map.end();ite++){ if(sel->checkcut(ite->first,evt->ht(),evt->mht(),evt->deltaPhi1(),evt->deltaPhi2(),evt->deltaPhi3(),evt->deltaPhi4(),evt->nJets(),evt->nBtags(),evt->nLeptons(),evt->nIsoElec(),evt->nIsoMu(),evt->nIsoPion(),evt->nTauMap()[2233],evt->nTauMap()[2243],evt->nTauMap()[2333],evt->nTauMap()[4333],evt->nTauMap()[1333])==true){ histobjmap[ite->first].fill(Nhists,&eveinfvec[0] ,&itt->second[ite->first][0]); } }//end of loop over cut names ////EndOfCuts//EndOfCuts//EndOfCuts//EndOfCuts//EndOfCuts//EndOfCuts//EndOfCuts//EndOfCuts//EndOfCuts//EndOfCuts }//end of bg_type determination }//end of loop over all the different backgrounds: "allEvents", "Wlv", "Zvv" eventN++; } // End of loop over events //open a file to write the histograms sprintf(tempname,"%s/results_%s_%s.root",Outdir.c_str(),subSampleKey.c_str(),inputnumber.c_str()); TFile *resFile = new TFile(tempname, "RECREATE"); TDirectory *cdtoitt; TDirectory *cdtoit; cutflow_preselection->Write(); TauIDhist->Write(); TauIDhist_trk->Write(); // Loop over different event categories (e.g. "All events, Wlnu, Zll, Zvv, etc") for(int iet=0;iet<(int)eventType.size();iet++){ for(map<string, map<string , vector<TH1D> > >::iterator itt=map_map.begin(); itt!=map_map.end();itt++){ if (eventType[iet]==itt->first){ //KH ////std::cout << (itt->first).c_str() << std::endl; cdtoitt = resFile->mkdir((itt->first).c_str()); cdtoitt->cd(); for(int i=0; i< (int)sel->cutName().size();i++){ for(map<string , vector<TH1D> >::iterator it=itt->second.begin(); it!=itt->second.end();it++){ if (sel->cutName()[i]==it->first){ cdtoit = cdtoitt->mkdir((it->first).c_str()); cdtoit->cd(); int nHist = it->second.size(); for(int i=0; i<nHist; i++){//since we only have 4 type of histograms sprintf(tempname,"%s_%s_%s",it->second[i].GetName(),(it->first).c_str(),(itt->first).c_str()); it->second[i].Write(tempname); } cdtoitt->cd(); } } } } } } }
void fitWm(const TString outputDir, // output directory const Double_t lumi, // integrated luminosity (/fb) const Double_t nsigma=0 // vary MET corrections by n-sigmas (nsigma=0 means nominal correction) ) { gBenchmark->Start("fitWm"); //-------------------------------------------------------------------------------------------------------------- // Settings //============================================================================================================== // MET histogram binning and range const Int_t NBINS = 50; const Double_t METMAX = 100; const Double_t PT_CUT = 25; const Double_t ETA_CUT = 2.1; // file format for output plots const TString format("png"); // recoil correction RecoilCorrector recoilCorr("../Recoil/ZmmData/fits.root");//, (!) uncomment to perform corrections to recoil from W-MC/Z-MC //"../Recoil/WmpMC/fits.root", //"../Recoil/WmmMC/fits.root", //"../Recoil/ZmmMC/fits.root"); // NNLO boson pT k-factors TFile nnloCorrFile("/data/blue/ksung/EWKAna/8TeV/Utils/Ratio.root"); TH1D *hNNLOCorr = (TH1D*)nnloCorrFile.Get("RpT_B"); // // input ntuple file names // enum { eData, eWmunu, eEWK, eAntiData, eAntiWmunu, eAntiEWK }; // data type enum vector<TString> fnamev; vector<Int_t> typev; fnamev.push_back("/data/blue/ksung/EWKAna/8TeV/Selection/Wmunu/ntuples/data_select.root"); typev.push_back(eData); fnamev.push_back("/data/blue/ksung/EWKAna/8TeV/Selection/Wmunu/ntuples/wm_select.root"); typev.push_back(eWmunu); fnamev.push_back("/data/blue/ksung/EWKAna/8TeV/Selection/Wmunu/ntuples/ewk_select.root"); typev.push_back(eEWK); fnamev.push_back("/data/blue/ksung/EWKAna/8TeV/Selection/Wmunu/ntuples/top_select.root"); typev.push_back(eEWK); fnamev.push_back("/data/blue/ksung/EWKAna/8TeV/Selection/AntiWmunu/ntuples/data_select.root"); typev.push_back(eAntiData); fnamev.push_back("/data/blue/ksung/EWKAna/8TeV/Selection/AntiWmunu/ntuples/wm_select.root"); typev.push_back(eAntiWmunu); fnamev.push_back("/data/blue/ksung/EWKAna/8TeV/Selection/AntiWmunu/ntuples/ewk_select.root"); typev.push_back(eAntiEWK); fnamev.push_back("/data/blue/ksung/EWKAna/8TeV/Selection/AntiWmunu/ntuples/top_select.root"); typev.push_back(eAntiEWK); //-------------------------------------------------------------------------------------------------------------- // Main analysis code //============================================================================================================== // Create output directory gSystem->mkdir(outputDir,kTRUE); CPlot::sOutDir = outputDir; // // Declare MET histograms // TH1D *hDataMet = new TH1D("hDataMet","", NBINS,0,METMAX); hDataMet->Sumw2(); TH1D *hDataMetm = new TH1D("hDataMetm","", NBINS,0,METMAX); hDataMetm->Sumw2(); TH1D *hDataMetp = new TH1D("hDataMetp","", NBINS,0,METMAX); hDataMetp->Sumw2(); TH1D *hWmunuMet = new TH1D("hWmunuMet","", NBINS,0,METMAX); hWmunuMet->Sumw2(); TH1D *hWmunuMetp = new TH1D("hWmunuMetp","",NBINS,0,METMAX); hWmunuMetp->Sumw2(); TH1D *hWmunuMetm = new TH1D("hWmunuMetm","",NBINS,0,METMAX); hWmunuMetm->Sumw2(); TH1D *hEWKMet = new TH1D("hEWKMet", "", NBINS,0,METMAX); hEWKMet->Sumw2(); TH1D *hEWKMetp = new TH1D("hEWKMetp", "", NBINS,0,METMAX); hEWKMetp->Sumw2(); TH1D *hEWKMetm = new TH1D("hEWKMetm", "", NBINS,0,METMAX); hEWKMetm->Sumw2(); TH1D *hAntiDataMet = new TH1D("hAntiDataMet","", NBINS,0,METMAX); hAntiDataMet->Sumw2(); TH1D *hAntiDataMetm = new TH1D("hAntiDataMetm","", NBINS,0,METMAX); hAntiDataMetm->Sumw2(); TH1D *hAntiDataMetp = new TH1D("hAntiDataMetp","", NBINS,0,METMAX); hAntiDataMetp->Sumw2(); TH1D *hAntiWmunuMet = new TH1D("hAntiWmunuMet","", NBINS,0,METMAX); hAntiWmunuMet->Sumw2(); TH1D *hAntiWmunuMetp = new TH1D("hAntiWmunuMetp","",NBINS,0,METMAX); hAntiWmunuMetp->Sumw2(); TH1D *hAntiWmunuMetm = new TH1D("hAntiWmunuMetm","",NBINS,0,METMAX); hAntiWmunuMetm->Sumw2(); TH1D *hAntiEWKMet = new TH1D("hAntiEWKMet", "", NBINS,0,METMAX); hAntiEWKMet->Sumw2(); TH1D *hAntiEWKMetp = new TH1D("hAntiEWKMetp", "", NBINS,0,METMAX); hAntiEWKMetp->Sumw2(); TH1D *hAntiEWKMetm = new TH1D("hAntiEWKMetm", "", NBINS,0,METMAX); hAntiEWKMetm->Sumw2(); // // Declare variables to read in ntuple // UInt_t runNum, lumiSec, evtNum; UInt_t npv, npu; Float_t genVPt, genVPhi; Float_t scale1fb; Float_t met, metPhi, sumEt, mt, u1, u2; Int_t q; LorentzVector *lep=0; Float_t pfChIso, pfGamIso, pfNeuIso; TFile *infile=0; TTree *intree=0; // // Loop over files // for(UInt_t ifile=0; ifile<fnamev.size(); ifile++) { // Read input file and get the TTrees cout << "Processing " << fnamev[ifile] << "..." << endl; infile = new TFile(fnamev[ifile]); assert(infile); intree = (TTree*)infile->Get("Events"); assert(intree); intree->SetBranchAddress("runNum", &runNum); // event run number intree->SetBranchAddress("lumiSec", &lumiSec); // event lumi section intree->SetBranchAddress("evtNum", &evtNum); // event number intree->SetBranchAddress("npv", &npv); // number of primary vertices intree->SetBranchAddress("npu", &npu); // number of in-time PU events (MC) intree->SetBranchAddress("genVPt", &genVPt); // GEN W boson pT (signal MC) intree->SetBranchAddress("genVPhi", &genVPhi); // GEN W boson phi (signal MC) intree->SetBranchAddress("scale1fb", &scale1fb); // event weight per 1/fb (MC) intree->SetBranchAddress("met", &met); // MET intree->SetBranchAddress("metPhi", &metPhi); // phi(MET) intree->SetBranchAddress("sumEt", &sumEt); // Sum ET intree->SetBranchAddress("mt", &mt); // transverse mass intree->SetBranchAddress("u1", &u1); // parallel component of recoil intree->SetBranchAddress("u2", &u2); // perpendicular component of recoil intree->SetBranchAddress("q", &q); // lepton charge intree->SetBranchAddress("lep", &lep); // lepton 4-vector intree->SetBranchAddress("pfChIso", &pfChIso); intree->SetBranchAddress("pfGamIso", &pfGamIso); intree->SetBranchAddress("pfNeuIso", &pfNeuIso); // // loop over events // for(UInt_t ientry=0; ientry<intree->GetEntries(); ientry++) { intree->GetEntry(ientry); if(lep->Pt() < PT_CUT) continue; if(fabs(lep->Eta()) > ETA_CUT) continue; if( (typev[ifile]==eAntiData || typev[ifile]==eAntiWmunu || typev[ifile]==eAntiEWK) && (pfChIso+pfGamIso+pfNeuIso)>0.5*(lep->Pt()) ) continue; if(typev[ifile]==eData) { hDataMet->Fill(met); if(q>0) { hDataMetp->Fill(met); } else { hDataMetm->Fill(met); } } else if(typev[ifile]==eAntiData) { hAntiDataMet->Fill(met); if(q>0) { hAntiDataMetp->Fill(met); } else { hAntiDataMetm->Fill(met); } } else { Double_t weight = 1; weight *= scale1fb*lumi; if(typev[ifile]==eWmunu) { Double_t corrMet=met, corrMetPhi=metPhi; // apply recoil corrections to W MC Double_t lepPt = lep->Pt(); //Double_t lepPt = gRandom->Gaus(lep->Pt(),0.5); // (!) uncomment to apply scale/res corrections to MC recoilCorr.Correct(corrMet,corrMetPhi,genVPt,genVPhi,lepPt,lep->Phi(),nsigma,q); Double_t nnlocorr=1; for(Int_t ibin=1; ibin<=hNNLOCorr->GetNbinsX(); ibin++) { if(genVPt >= hNNLOCorr->GetBinLowEdge(ibin) && genVPt < (hNNLOCorr->GetBinLowEdge(ibin)+hNNLOCorr->GetBinWidth(ibin))) nnlocorr = hNNLOCorr->GetBinContent(ibin); } //weight *= nnlocorr; // (!) uncomment to apply NNLO corrections hWmunuMet->Fill(corrMet,weight); if(q>0) { hWmunuMetp->Fill(corrMet,weight); } else { hWmunuMetm->Fill(corrMet,weight); } } if(typev[ifile]==eAntiWmunu) { Double_t corrMet=met, corrMetPhi=metPhi; // apply recoil corrections to W MC Double_t lepPt = lep->Pt();//gRandom->Gaus(lep->Pt(),0.5); //Double_t lepPt = gRandom->Gaus(lep->Pt(),0.5); // (!) uncomment to apply scale/res corrections to MC recoilCorr.Correct(corrMet,corrMetPhi,genVPt,genVPhi,lepPt,lep->Phi(),nsigma,q); Double_t nnlocorr=1; for(Int_t ibin=1; ibin<=hNNLOCorr->GetNbinsX(); ibin++) { if(genVPt >= hNNLOCorr->GetBinLowEdge(ibin) && genVPt < (hNNLOCorr->GetBinLowEdge(ibin)+hNNLOCorr->GetBinWidth(ibin))) nnlocorr = hNNLOCorr->GetBinContent(ibin); } //weight *= nnlocorr; // (!) uncomment to apply NNLO corrections hAntiWmunuMet->Fill(corrMet,weight); if(q>0) { hAntiWmunuMetp->Fill(corrMet,weight); } else { hAntiWmunuMetm->Fill(corrMet,weight); } } if(typev[ifile]==eEWK) { hEWKMet->Fill(met,weight); if(q>0) { hEWKMetp->Fill(met,weight); } else { hEWKMetm->Fill(met,weight); } } if(typev[ifile]==eAntiEWK) { hAntiEWKMet->Fill(met,weight); if(q>0) { hAntiEWKMetp->Fill(met,weight); } else { hAntiEWKMetm->Fill(met,weight); } } } } } delete infile; infile=0, intree=0; // // Declare fit parameters for signal and background yields // Note: W signal and EWK+top PDFs are constrained to the ratio described in MC // RooRealVar nSig("nSig","nSig",0.7*(hDataMet->Integral()),0,hDataMet->Integral()); RooRealVar nQCD("nQCD","nQCD",0.3*(hDataMet->Integral()),0,hDataMet->Integral()); RooRealVar cewk("cewk","cewk",0.1,0,5) ; cewk.setVal(hEWKMet->Integral()/hWmunuMet->Integral()); cewk.setConstant(kTRUE); RooFormulaVar nEWK("nEWK","nEWK","cewk*nSig",RooArgList(nSig,cewk)); RooRealVar nAntiSig("nAntiSig","nAntiSig",0.05*(hAntiDataMet->Integral()),0,hAntiDataMet->Integral()); RooRealVar nAntiQCD("nAntiQCD","nAntiQCD",0.9*(hDataMet->Integral()),0,hDataMet->Integral()); RooRealVar dewk("dewk","dewk",0.1,0,5) ; dewk.setVal(hAntiEWKMet->Integral()/hAntiWmunuMet->Integral()); dewk.setConstant(kTRUE); RooFormulaVar nAntiEWK("nAntiEWK","nAntiEWK","dewk*nAntiSig",RooArgList(nAntiSig,dewk)); RooRealVar nSigp("nSigp","nSigp",0.7*(hDataMetp->Integral()),0,hDataMetp->Integral()); RooRealVar nQCDp("nQCDp","nQCDp",0.3*(hDataMetp->Integral()),0,hDataMetp->Integral()); RooRealVar cewkp("cewkp","cewkp",0.1,0,5) ; cewkp.setVal(hEWKMetp->Integral()/hWmunuMetp->Integral()); cewkp.setConstant(kTRUE); RooFormulaVar nEWKp("nEWKp","nEWKp","cewkp*nSigp",RooArgList(nSigp,cewkp)); RooRealVar nAntiSigp("nAntiSigp","nAntiSigp",0.05*(hAntiDataMetp->Integral()),0,hAntiDataMetp->Integral()); RooRealVar nAntiQCDp("nAntiQCDp","nAntiQCDp",0.9*(hAntiDataMetp->Integral()),0,hAntiDataMetp->Integral()); RooRealVar dewkp("dewkp","dewkp",0.1,0,5) ; dewkp.setVal(hAntiEWKMetp->Integral()/hAntiWmunuMetp->Integral()); dewkp.setConstant(kTRUE); RooFormulaVar nAntiEWKp("nAntiEWKp","nAntiEWKp","dewkp*nAntiSigp",RooArgList(nAntiSigp,dewkp)); RooRealVar nSigm("nSigm","nSigm",0.7*(hDataMetm->Integral()),0,hDataMetm->Integral()); RooRealVar nQCDm("nQCDm","nQCDm",0.3*(hDataMetm->Integral()),0,hDataMetm->Integral()); RooRealVar cewkm("cewkm","cewkm",0.1,0,5) ; cewkm.setVal(hEWKMetm->Integral()/hWmunuMetm->Integral()); cewkm.setConstant(kTRUE); RooFormulaVar nEWKm("nEWKm","nEWKm","cewkm*nSigm",RooArgList(nSigm,cewkm)); RooRealVar nAntiSigm("nAntiSigm","nAntiSigm",0.05*(hAntiDataMetm->Integral()),0,hAntiDataMetm->Integral()); RooRealVar nAntiQCDm("nAntiQCDm","nAntiQCDm",0.9*(hAntiDataMetm->Integral()),0,hAntiDataMetm->Integral()); RooRealVar dewkm("dewkm","dewkm",0.1,0,5) ; dewkm.setVal(hAntiEWKMetm->Integral()/hAntiWmunuMetm->Integral()); dewkm.setConstant(kTRUE); RooFormulaVar nAntiEWKm("nAntiEWKm","nAntiEWKm","dewkm*nAntiSigm",RooArgList(nAntiSigm,dewkm)); // // Construct PDFs for fitting // RooRealVar pfmet("pfmet","pfmet",0,METMAX); pfmet.setBins(NBINS); // Signal PDFs RooDataHist wmunuMet ("wmunuMET", "wmunuMET", RooArgSet(pfmet),hWmunuMet); RooHistPdf pdfWm ("wm", "wm", pfmet,wmunuMet, 1); RooDataHist wmunuMetp("wmunuMETp","wmunuMETp",RooArgSet(pfmet),hWmunuMetp); RooHistPdf pdfWmp("wmp","wmp",pfmet,wmunuMetp,1); RooDataHist wmunuMetm("wmunuMETm","wmunuMETm",RooArgSet(pfmet),hWmunuMetm); RooHistPdf pdfWmm("wmm","wmm",pfmet,wmunuMetm,1); // EWK+top PDFs RooDataHist ewkMet ("ewkMET", "ewkMET", RooArgSet(pfmet),hEWKMet); RooHistPdf pdfEWK ("ewk", "ewk", pfmet,ewkMet, 1); RooDataHist ewkMetp("ewkMETp","ewkMETp",RooArgSet(pfmet),hEWKMetp); RooHistPdf pdfEWKp("ewkp","ewkp",pfmet,ewkMetp,1); RooDataHist ewkMetm("ewkMETm","ewkMETm",RooArgSet(pfmet),hEWKMetm); RooHistPdf pdfEWKm("ewkm","ewkm",pfmet,ewkMetm,1); // QCD Pdfs CPepeModel1 qcd("qcd",pfmet); CPepeModel1 qcdp("qcdp",pfmet); CPepeModel1 qcdm("qcdm",pfmet); // Signal + Background PDFs RooAddPdf pdfMet ("pdfMet", "pdfMet", RooArgList(pdfWm,pdfEWK,*(qcd.model)), RooArgList(nSig,nEWK,nQCD)); RooAddPdf pdfMetp("pdfMetp","pdfMetp",RooArgList(pdfWmp,pdfEWKp,*(qcdp.model)),RooArgList(nSigp,nEWKp,nQCDp)); RooAddPdf pdfMetm("pdfMetm","pdfMetm",RooArgList(pdfWmm,pdfEWKm,*(qcdm.model)),RooArgList(nSigm,nEWKm,nQCDm)); // Anti-Signal PDFs RooDataHist awmunuMet ("awmunuMET", "awmunuMET", RooArgSet(pfmet),hAntiWmunuMet); RooHistPdf apdfWm ("awm", "awm", pfmet,awmunuMet, 1); RooDataHist awmunuMetp("awmunuMETp","awmunuMETp",RooArgSet(pfmet),hAntiWmunuMetp); RooHistPdf apdfWmp("awmp","awmp",pfmet,awmunuMetp,1); RooDataHist awmunuMetm("awmunuMETm","awmunuMETm",RooArgSet(pfmet),hAntiWmunuMetm); RooHistPdf apdfWmm("awmm","awmm",pfmet,awmunuMetm,1); // Anti-EWK+top PDFs RooDataHist aewkMet ("aewkMET", "aewkMET", RooArgSet(pfmet),hAntiEWKMet); RooHistPdf apdfEWK ("aewk", "aewk", pfmet,aewkMet, 1); RooDataHist aewkMetp("aewkMETp","aewkMETp",RooArgSet(pfmet),hAntiEWKMetp); RooHistPdf apdfEWKp("aewkp","aewkp",pfmet,aewkMetp,1); RooDataHist aewkMetm("aewkMETm","aewkMETm",RooArgSet(pfmet),hAntiEWKMetm); RooHistPdf apdfEWKm("aewkm","aewkm",pfmet,aewkMetm,1); // Anti-QCD Pdfs CPepeModel1 aqcd("aqcd",pfmet,qcd.a1); CPepeModel1 aqcdp("aqcdp",pfmet,qcdp.a1); CPepeModel1 aqcdm("aqcdm",pfmet,qcdm.a1); // Anti-selection PDFs RooAddPdf apdfMet ("apdfMet", "apdfMet", RooArgList(apdfWm,apdfEWK,*(aqcd.model)), RooArgList(nAntiSig,nAntiEWK,nAntiQCD)); RooAddPdf apdfMetp("apdfMetp","apdfMetp",RooArgList(apdfWmp,apdfEWKp,*(aqcdp.model)),RooArgList(nAntiSigp,nAntiEWKp,nAntiQCDp)); RooAddPdf apdfMetm("apdfMetm","apdfMetm",RooArgList(apdfWmm,apdfEWKm,*(aqcdm.model)),RooArgList(nAntiSigm,nAntiEWKm,nAntiQCDm)); // PDF for simultaneous fit RooCategory rooCat("rooCat","rooCat"); rooCat.defineType("Select"); rooCat.defineType("Anti"); RooSimultaneous pdfTotal("pdfTotal","pdfTotal",rooCat); pdfTotal.addPdf(pdfMet, "Select"); pdfTotal.addPdf(apdfMet,"Anti"); RooSimultaneous pdfTotalp("pdfTotalp","pdfTotalp",rooCat); pdfTotalp.addPdf(pdfMetp, "Select"); pdfTotalp.addPdf(apdfMetp,"Anti"); RooSimultaneous pdfTotalm("pdfTotalm","pdfTotalm",rooCat); pdfTotalm.addPdf(pdfMetm, "Select"); pdfTotalm.addPdf(apdfMetm,"Anti"); // // Perform fits // RooDataHist dataMet("dataMet", "dataMet", RooArgSet(pfmet), hDataMet); RooDataHist antiMet("antiMet", "antiMet", RooArgSet(pfmet), hAntiDataMet); RooDataHist dataTotal("dataTotal","dataTotal", RooArgList(pfmet), Index(rooCat), Import("Select", dataMet), Import("Anti", antiMet)); RooFitResult *fitRes = pdfTotal.fitTo(dataTotal,Extended(),Minos(kTRUE),Save(kTRUE)); RooDataHist dataMetp("dataMetp", "dataMetp", RooArgSet(pfmet), hDataMetp); RooDataHist antiMetp("antiMetp", "antiMetp", RooArgSet(pfmet), hAntiDataMetp); RooDataHist dataTotalp("dataTotalp","dataTotalp", RooArgList(pfmet), Index(rooCat), Import("Select", dataMetp), Import("Anti", antiMetp)); RooFitResult *fitResp = pdfTotalp.fitTo(dataTotalp,Extended(),Minos(kTRUE),Save(kTRUE)); RooDataHist dataMetm("dataMetm", "dataMetm", RooArgSet(pfmet), hDataMetm); RooDataHist antiMetm("antiMetm", "antiMetm", RooArgSet(pfmet), hAntiDataMetm); RooDataHist dataTotalm("dataTotalm","dataTotalm", RooArgList(pfmet), Index(rooCat), Import("Select", dataMetm), Import("Anti", antiMetm)); RooFitResult *fitResm = pdfTotalm.fitTo(dataTotalm,Extended(),Minos(kTRUE),Save(kTRUE)); // // Use histogram version of fitted PDFs to make ratio plots // (Will also use PDF histograms later for Chi^2 and KS tests) // TH1D *hPdfMet = (TH1D*)(pdfMet.createHistogram("hPdfMet", pfmet)); hPdfMet->Scale((nSig.getVal()+nEWK.getVal()+nQCD.getVal())/hPdfMet->Integral()); TH1D *hMetDiff = makeDiffHist(hDataMet,hPdfMet,"hMetDiff"); hMetDiff->SetMarkerStyle(kFullCircle); hMetDiff->SetMarkerSize(0.9); TH1D *hPdfMetp = (TH1D*)(pdfMetp.createHistogram("hPdfMetp", pfmet)); hPdfMetp->Scale((nSigp.getVal()+nEWKp.getVal()+nQCDp.getVal())/hPdfMetp->Integral()); TH1D *hMetpDiff = makeDiffHist(hDataMetp,hPdfMetp,"hMetpDiff"); hMetpDiff->SetMarkerStyle(kFullCircle); hMetpDiff->SetMarkerSize(0.9); TH1D *hPdfMetm = (TH1D*)(pdfMetm.createHistogram("hPdfMetm", pfmet)); hPdfMetm->Scale((nSigm.getVal()+nEWKm.getVal()+nQCDm.getVal())/hPdfMetm->Integral()); TH1D *hMetmDiff = makeDiffHist(hDataMetm,hPdfMetm,"hMetmDiff"); hMetmDiff->SetMarkerStyle(kFullCircle); hMetmDiff->SetMarkerSize(0.9); TH1D *hPdfAntiMet = (TH1D*)(apdfMet.createHistogram("hPdfAntiMet", pfmet)); hPdfAntiMet->Scale((nAntiSig.getVal()+nAntiEWK.getVal()+nAntiQCD.getVal())/hPdfAntiMet->Integral()); TH1D *hAntiMetDiff = makeDiffHist(hAntiDataMet,hPdfAntiMet,"hAntiMetDiff"); hAntiMetDiff->SetMarkerStyle(kFullCircle); hAntiMetDiff->SetMarkerSize(0.9); TH1D *hPdfAntiMetp = (TH1D*)(apdfMetp.createHistogram("hPdfAntiMetp", pfmet)); hPdfAntiMetp->Scale((nAntiSigp.getVal()+nAntiEWKp.getVal()+nAntiQCDp.getVal())/hPdfAntiMetp->Integral()); TH1D *hAntiMetpDiff = makeDiffHist(hAntiDataMetp,hPdfAntiMetp,"hAntiMetpDiff"); hAntiMetpDiff->SetMarkerStyle(kFullCircle); hAntiMetpDiff->SetMarkerSize(0.9); TH1D *hPdfAntiMetm = (TH1D*)(apdfMetm.createHistogram("hPdfAntiMetm", pfmet)); hPdfAntiMetm->Scale((nAntiSigm.getVal()+nAntiEWKm.getVal()+nAntiQCDm.getVal())/hPdfAntiMetm->Integral()); TH1D *hAntiMetmDiff = makeDiffHist(hAntiDataMetm,hPdfAntiMetm,"hAntiMetmDiff"); hAntiMetmDiff->SetMarkerStyle(kFullCircle); hAntiMetmDiff->SetMarkerSize(0.9); //-------------------------------------------------------------------------------------------------------------- // Make plots //============================================================================================================== TCanvas *c = MakeCanvas("c","c",800,800); c->Divide(1,2,0,0); c->cd(1)->SetPad(0,0.3,1.0,1.0); c->cd(1)->SetTopMargin(0.1); c->cd(1)->SetBottomMargin(0.01); c->cd(1)->SetLeftMargin(0.15); c->cd(1)->SetRightMargin(0.07); c->cd(1)->SetTickx(1); c->cd(1)->SetTicky(1); c->cd(2)->SetPad(0,0,1.0,0.3); c->cd(2)->SetTopMargin(0.05); c->cd(2)->SetBottomMargin(0.45); c->cd(2)->SetLeftMargin(0.15); c->cd(2)->SetRightMargin(0.07); c->cd(2)->SetTickx(1); c->cd(2)->SetTicky(1); gStyle->SetTitleOffset(1.100,"Y"); TGaxis::SetMaxDigits(3); char ylabel[100]; // string buffer for y-axis label // label for lumi char lumitext[100]; if(lumi<0.1) sprintf(lumitext,"%.1f pb^{-1} at #sqrt{s} = 8 TeV",lumi*1000.); else sprintf(lumitext,"%.2f fb^{-1} at #sqrt{s} = 8 TeV",lumi); // plot colors Int_t linecolorW = kOrange-3; Int_t fillcolorW = kOrange-2; Int_t linecolorEWK = kOrange+10; Int_t fillcolorEWK = kOrange+7; Int_t linecolorQCD = kViolet+2; Int_t fillcolorQCD = kViolet-5; Int_t ratioColor = kGray+2; // // Dummy histograms for TLegend // (I can't figure out how to properly pass RooFit objects...) // TH1D *hDummyData = new TH1D("hDummyData","",0,0,10); hDummyData->SetMarkerStyle(kFullCircle); hDummyData->SetMarkerSize(0.9); TH1D *hDummyW = new TH1D("hDummyW","",0,0,10); hDummyW->SetLineColor(linecolorW); hDummyW->SetFillColor(fillcolorW); hDummyW->SetFillStyle(1001); TH1D *hDummyEWK = new TH1D("hDummyEWK","",0,0,10); hDummyEWK->SetLineColor(linecolorEWK); hDummyEWK->SetFillColor(fillcolorEWK); hDummyEWK->SetFillStyle(1001); TH1D *hDummyQCD = new TH1D("hDummyQCD","",0,0,10); hDummyQCD->SetLineColor(linecolorQCD); hDummyQCD->SetFillColor(fillcolorQCD); hDummyQCD->SetFillStyle(1001); // // W MET plot // RooPlot *wmframe = pfmet.frame(Bins(NBINS)); wmframe->GetYaxis()->SetNdivisions(505); dataMet.plotOn(wmframe,MarkerStyle(kFullCircle),MarkerSize(0.9),DrawOption("ZP")); pdfMet.plotOn(wmframe,FillColor(fillcolorW),DrawOption("F")); pdfMet.plotOn(wmframe,LineColor(linecolorW)); pdfMet.plotOn(wmframe,Components(RooArgSet(pdfEWK,*(qcd.model))),FillColor(fillcolorEWK),DrawOption("F")); pdfMet.plotOn(wmframe,Components(RooArgSet(pdfEWK,*(qcd.model))),LineColor(linecolorEWK)); pdfMet.plotOn(wmframe,Components(RooArgSet(*(qcd.model))),FillColor(fillcolorQCD),DrawOption("F")); pdfMet.plotOn(wmframe,Components(RooArgSet(*(qcd.model))),LineColor(linecolorQCD)); pdfMet.plotOn(wmframe,Components(RooArgSet(pdfWm)),LineColor(linecolorW),LineStyle(2)); dataMet.plotOn(wmframe,MarkerStyle(kFullCircle),MarkerSize(0.9),DrawOption("ZP")); sprintf(ylabel,"Events / %.1f GeV",hDataMet->GetBinWidth(1)); CPlot plotMet("fitmet",wmframe,"","",ylabel); plotMet.SetLegend(0.68,0.57,0.93,0.77); plotMet.GetLegend()->AddEntry(hDummyData,"data","PL"); plotMet.GetLegend()->AddEntry(hDummyW,"W#rightarrow#mu#nu","F"); plotMet.GetLegend()->AddEntry(hDummyEWK,"EWK+t#bar{t}","F"); plotMet.GetLegend()->AddEntry(hDummyQCD,"QCD","F"); plotMet.AddTextBox(lumitext,0.55,0.80,0.90,0.86,0); plotMet.AddTextBox("CMS Preliminary",0.63,0.92,0.95,0.99,0); plotMet.SetYRange(0.1,1.1*(hDataMet->GetMaximum())); plotMet.Draw(c,kFALSE,format,1); CPlot plotMetDiff("fitmet","","#slash{E}_{T} [GeV]","#chi"); plotMetDiff.AddHist1D(hMetDiff,"EX0",ratioColor); plotMetDiff.SetYRange(-8,8); plotMetDiff.AddLine(0, 0,METMAX, 0,kBlack,1); plotMetDiff.AddLine(0, 5,METMAX, 5,kBlack,3); plotMetDiff.AddLine(0,-5,METMAX,-5,kBlack,3); plotMetDiff.Draw(c,kTRUE,format,2); plotMet.SetName("fitmetlog"); plotMet.SetLogy(); plotMet.SetYRange(1e-3*(hDataMet->GetMaximum()),10*(hDataMet->GetMaximum())); plotMet.Draw(c,kTRUE,format,1); RooPlot *awmframe = pfmet.frame(Bins(NBINS)); antiMet.plotOn(awmframe,MarkerStyle(kFullCircle),MarkerSize(0.9),DrawOption("ZP")); apdfMet.plotOn(awmframe,FillColor(fillcolorW),DrawOption("F")); apdfMet.plotOn(awmframe,LineColor(linecolorW)); apdfMet.plotOn(awmframe,Components(RooArgSet(apdfEWK,*(aqcd.model))),FillColor(fillcolorEWK),DrawOption("F")); apdfMet.plotOn(awmframe,Components(RooArgSet(apdfEWK,*(aqcd.model))),LineColor(linecolorEWK)); apdfMet.plotOn(awmframe,Components(RooArgSet(*(aqcd.model))),FillColor(fillcolorQCD),DrawOption("F")); apdfMet.plotOn(awmframe,Components(RooArgSet(*(aqcd.model))),LineColor(linecolorQCD)); apdfMet.plotOn(awmframe,Components(RooArgSet(apdfWm)),LineColor(linecolorW),LineStyle(2)); antiMet.plotOn(awmframe,MarkerStyle(kFullCircle),MarkerSize(0.9),DrawOption("ZP")); sprintf(ylabel,"Events / %.1f GeV",hAntiDataMet->GetBinWidth(1)); CPlot plotAntiMet("fitantimet",awmframe,"","",ylabel); plotAntiMet.SetLegend(0.68,0.57,0.93,0.77); plotAntiMet.GetLegend()->AddEntry(hDummyData,"data","PL"); plotAntiMet.GetLegend()->AddEntry(hDummyW,"W#rightarrow#mu#nu","F"); plotAntiMet.GetLegend()->AddEntry(hDummyEWK,"EWK+t#bar{t}","F"); plotAntiMet.GetLegend()->AddEntry(hDummyQCD,"QCD","F"); plotAntiMet.AddTextBox(lumitext,0.55,0.80,0.90,0.86,0); plotAntiMet.AddTextBox("CMS Preliminary",0.63,0.92,0.95,0.99,0); plotAntiMet.SetYRange(0.1,1.1*(hAntiDataMet->GetMaximum())); plotAntiMet.Draw(c,kFALSE,format,1); CPlot plotAntiMetDiff("fitantimet","","#slash{E}_{T} [GeV]","#chi"); plotAntiMetDiff.AddHist1D(hMetDiff,"EX0",ratioColor); plotAntiMetDiff.SetYRange(-8,8); plotAntiMetDiff.AddLine(0, 0,METMAX, 0,kBlack,1); plotAntiMetDiff.AddLine(0, 5,METMAX, 5,kBlack,3); plotAntiMetDiff.AddLine(0,-5,METMAX,-5,kBlack,3); plotAntiMetDiff.Draw(c,kTRUE,format,2); plotAntiMet.SetName("fitantimetlog"); plotAntiMet.SetLogy(); plotAntiMet.SetYRange(1e-3*(hAntiDataMet->GetMaximum()),10*(hAntiDataMet->GetMaximum())); plotAntiMet.Draw(c,kTRUE,format,1); // // W+ MET plot // RooPlot *wmpframe = pfmet.frame(Bins(NBINS)); wmpframe->GetYaxis()->SetNdivisions(505); dataMetp.plotOn(wmpframe,MarkerStyle(kFullCircle),MarkerSize(0.9),DrawOption("ZP")); pdfMetp.plotOn(wmpframe,FillColor(fillcolorW),DrawOption("F")); pdfMetp.plotOn(wmpframe,LineColor(linecolorW)); pdfMetp.plotOn(wmpframe,Components(RooArgSet(pdfEWKp,*(qcdp.model))),FillColor(fillcolorEWK),DrawOption("F")); pdfMetp.plotOn(wmpframe,Components(RooArgSet(pdfEWKp,*(qcdp.model))),LineColor(linecolorEWK)); pdfMetp.plotOn(wmpframe,Components(RooArgSet(*(qcdp.model))),FillColor(fillcolorQCD),DrawOption("F")); pdfMetp.plotOn(wmpframe,Components(RooArgSet(*(qcdp.model))),LineColor(linecolorQCD)); pdfMetp.plotOn(wmpframe,Components(RooArgSet(pdfWmp)),LineColor(linecolorW),LineStyle(2)); dataMetp.plotOn(wmpframe,MarkerStyle(kFullCircle),MarkerSize(0.9),DrawOption("ZP")); sprintf(ylabel,"Events / %.1f GeV",hDataMetp->GetBinWidth(1)); CPlot plotMetp("fitmetp",wmpframe,"","",ylabel); plotMetp.SetLegend(0.68,0.57,0.93,0.77); plotMetp.GetLegend()->AddEntry(hDummyData,"data","PL"); plotMetp.GetLegend()->AddEntry(hDummyW,"W^{+}#rightarrow#mu^{+}#nu","F"); plotMetp.GetLegend()->AddEntry(hDummyEWK,"EWK+t#bar{t}","F"); plotMetp.GetLegend()->AddEntry(hDummyQCD,"QCD","F"); plotMetp.AddTextBox(lumitext,0.55,0.80,0.90,0.86,0); plotMetp.AddTextBox("CMS Preliminary",0.63,0.92,0.95,0.99,0); // plotMetp.SetYRange(0.1,1.1*(hDataMetp->GetMaximum())); plotMetp.SetYRange(0.1,4100); plotMetp.Draw(c,kFALSE,format,1); CPlot plotMetpDiff("fitmetp","","#slash{E}_{T} [GeV]","#chi"); plotMetpDiff.AddHist1D(hMetpDiff,"EX0",ratioColor); plotMetpDiff.SetYRange(-8,8); plotMetpDiff.AddLine(0, 0,METMAX, 0,kBlack,1); plotMetpDiff.AddLine(0, 5,METMAX, 5,kBlack,3); plotMetpDiff.AddLine(0,-5,METMAX,-5,kBlack,3); plotMetpDiff.Draw(c,kTRUE,format,2); plotMetp.SetName("fitmetplog"); plotMetp.SetLogy(); plotMetp.SetYRange(1e-3*(hDataMetp->GetMaximum()),10*(hDataMetp->GetMaximum())); plotMetp.Draw(c,kTRUE,format,1); RooPlot *awmpframe = pfmet.frame(Bins(NBINS)); antiMetp.plotOn(awmpframe,MarkerStyle(kFullCircle),MarkerSize(0.9),DrawOption("ZP")); apdfMetp.plotOn(awmpframe,FillColor(fillcolorW),DrawOption("F")); apdfMetp.plotOn(awmpframe,LineColor(linecolorW)); apdfMetp.plotOn(awmpframe,Components(RooArgSet(apdfEWKp,*(aqcdp.model))),FillColor(fillcolorEWK),DrawOption("F")); apdfMetp.plotOn(awmpframe,Components(RooArgSet(apdfEWKp,*(aqcdp.model))),LineColor(linecolorEWK)); apdfMetp.plotOn(awmpframe,Components(RooArgSet(*(aqcdp.model))),FillColor(fillcolorQCD),DrawOption("F")); apdfMetp.plotOn(awmpframe,Components(RooArgSet(*(aqcdp.model))),LineColor(linecolorQCD)); apdfMetp.plotOn(awmpframe,Components(RooArgSet(apdfWmp)),LineColor(linecolorW),LineStyle(2)); antiMetp.plotOn(awmpframe,MarkerStyle(kFullCircle),MarkerSize(0.9),DrawOption("ZP")); sprintf(ylabel,"Events / %.1f GeV",hAntiDataMetp->GetBinWidth(1)); CPlot plotAntiMetp("fitantimetp",awmpframe,"","",ylabel); plotAntiMetp.SetLegend(0.68,0.57,0.93,0.77); plotAntiMetp.GetLegend()->AddEntry(hDummyData,"data","PL"); plotAntiMetp.GetLegend()->AddEntry(hDummyW,"W^{+}#rightarrow#mu^{+}#nu","F"); plotAntiMetp.GetLegend()->AddEntry(hDummyEWK,"EWK+t#bar{t}","F"); plotAntiMetp.GetLegend()->AddEntry(hDummyQCD,"QCD","F"); plotAntiMetp.AddTextBox(lumitext,0.55,0.80,0.90,0.86,0); plotAntiMetp.AddTextBox("CMS Preliminary",0.63,0.92,0.95,0.99,0); // plotAntiMetp.SetYRange(0.1,1.1*(hAntiDataMetp->GetMaximum())); plotAntiMetp.SetYRange(0.1,1500); plotAntiMetp.Draw(c,kFALSE,format,1); CPlot plotAntiMetpDiff("fitantimetp","","#slash{E}_{T} [GeV]","#chi"); plotAntiMetpDiff.AddHist1D(hAntiMetpDiff,"EX0",ratioColor); plotAntiMetpDiff.SetYRange(-8,8); plotAntiMetpDiff.AddLine(0, 0,METMAX, 0,kBlack,1); plotAntiMetpDiff.AddLine(0, 5,METMAX, 5,kBlack,3); plotAntiMetpDiff.AddLine(0,-5,METMAX,-5,kBlack,3); plotAntiMetpDiff.Draw(c,kTRUE,format,2); plotAntiMetp.SetName("fitantimetplog"); plotAntiMetp.SetLogy(); plotAntiMetp.SetYRange(1e-3*(hAntiDataMetp->GetMaximum()),10*(hAntiDataMetp->GetMaximum())); plotAntiMetp.Draw(c,kTRUE,format,1); // // W- MET plot // RooPlot *wmmframe = pfmet.frame(Bins(NBINS)); wmmframe->GetYaxis()->SetNdivisions(505); dataMetm.plotOn(wmmframe,MarkerStyle(kFullCircle),MarkerSize(0.9),DrawOption("ZP")); pdfMetm.plotOn(wmmframe,FillColor(fillcolorW),DrawOption("F")); pdfMetm.plotOn(wmmframe,LineColor(linecolorW)); pdfMetm.plotOn(wmmframe,Components(RooArgSet(pdfEWKm,*(qcdm.model))),FillColor(fillcolorEWK),DrawOption("F")); pdfMetm.plotOn(wmmframe,Components(RooArgSet(pdfEWKm,*(qcdm.model))),LineColor(linecolorEWK)); pdfMetm.plotOn(wmmframe,Components(RooArgSet(*(qcdm.model))),FillColor(fillcolorQCD),DrawOption("F")); pdfMetm.plotOn(wmmframe,Components(RooArgSet(*(qcdm.model))),LineColor(linecolorQCD)); pdfMetm.plotOn(wmmframe,Components(RooArgSet(pdfWmm)),LineColor(linecolorW),LineStyle(2)); dataMetm.plotOn(wmmframe,MarkerStyle(kFullCircle),MarkerSize(0.9),DrawOption("ZP")); sprintf(ylabel,"Events / %.1f GeV",hDataMetm->GetBinWidth(1)); CPlot plotMetm("fitmetm",wmmframe,"","",ylabel); plotMetm.SetLegend(0.68,0.57,0.93,0.77); plotMetm.GetLegend()->AddEntry(hDummyData,"data","PL"); plotMetm.GetLegend()->AddEntry(hDummyW,"W^{-}#rightarrow#mu^{-}#bar{#nu}","F"); plotMetm.GetLegend()->AddEntry(hDummyEWK,"EWK+t#bar{t}","F"); plotMetm.GetLegend()->AddEntry(hDummyQCD,"QCD","F"); plotMetm.AddTextBox(lumitext,0.55,0.80,0.90,0.86,0); plotMetm.AddTextBox("CMS Preliminary",0.63,0.92,0.95,0.99,0); // plotMetm.SetYRange(0.1,1.1*(hDataMetm->GetMaximum())); plotMetm.SetYRange(0.1,4100); plotMetm.Draw(c,kFALSE,format,1); CPlot plotMetmDiff("fitmetm","","#slash{E}_{T} [GeV]","#chi"); plotMetmDiff.AddHist1D(hMetmDiff,"EX0",ratioColor); plotMetmDiff.SetYRange(-8,8); plotMetmDiff.AddLine(0, 0,METMAX, 0,kBlack,1); plotMetmDiff.AddLine(0, 5,METMAX, 5,kBlack,3); plotMetmDiff.AddLine(0,-5,METMAX,-5,kBlack,3); plotMetmDiff.Draw(c,kTRUE,format,2); plotMetm.SetName("fitmetmlog"); plotMetm.SetLogy(); plotMetm.SetYRange(1e-3*(hDataMetm->GetMaximum()),10*(hDataMetm->GetMaximum())); plotMetm.Draw(c,kTRUE,format,1); RooPlot *awmmframe = pfmet.frame(Bins(NBINS)); antiMetm.plotOn(awmmframe,MarkerStyle(kFullCircle),MarkerSize(0.9),DrawOption("ZP")); apdfMetm.plotOn(awmmframe,FillColor(fillcolorW),DrawOption("F")); apdfMetm.plotOn(awmmframe,LineColor(linecolorW)); apdfMetm.plotOn(awmmframe,Components(RooArgSet(apdfEWKm,*(aqcdm.model))),FillColor(fillcolorEWK),DrawOption("F")); apdfMetm.plotOn(awmmframe,Components(RooArgSet(apdfEWKm,*(aqcdm.model))),LineColor(linecolorEWK)); apdfMetm.plotOn(awmmframe,Components(RooArgSet(*(aqcdm.model))),FillColor(fillcolorQCD),DrawOption("F")); apdfMetm.plotOn(awmmframe,Components(RooArgSet(*(aqcdm.model))),LineColor(linecolorQCD)); apdfMetm.plotOn(awmmframe,Components(RooArgSet(apdfWmm)),LineColor(linecolorW),LineStyle(2)); antiMetm.plotOn(awmmframe,MarkerStyle(kFullCircle),MarkerSize(0.9),DrawOption("ZP")); sprintf(ylabel,"Events / %.1f GeV",hDataMetm->GetBinWidth(1)); CPlot plotAntiMetm("fitantimetm",awmmframe,"","",ylabel); plotAntiMetm.SetLegend(0.68,0.57,0.93,0.77); plotAntiMetm.GetLegend()->AddEntry(hDummyData,"data","PL"); plotAntiMetm.GetLegend()->AddEntry(hDummyW,"W^{-}#rightarrow#mu^{-}#bar{#nu}","F"); plotAntiMetm.GetLegend()->AddEntry(hDummyEWK,"EWK+t#bar{t}","F"); plotAntiMetm.GetLegend()->AddEntry(hDummyQCD,"QCD","F"); plotAntiMetm.AddTextBox(lumitext,0.55,0.80,0.90,0.86,0); plotAntiMetm.AddTextBox("CMS Preliminary",0.63,0.92,0.95,0.99,0); // plotAntiMetm.SetYRange(0.1,1.1*(hAntiDataMetm->GetMaximum())); plotAntiMetm.SetYRange(0.1,1500); plotAntiMetm.Draw(c,kFALSE,format,1); CPlot plotAntiMetmDiff("fitantimetm","","#slash{E}_{T} [GeV]","#chi"); plotAntiMetmDiff.AddHist1D(hAntiMetmDiff,"EX0",ratioColor); plotAntiMetmDiff.SetYRange(-8,8); plotAntiMetmDiff.AddLine(0, 0,METMAX, 0,kBlack,1); plotAntiMetmDiff.AddLine(0, 5,METMAX, 5,kBlack,3); plotAntiMetmDiff.AddLine(0,-5,METMAX,-5,kBlack,3); plotAntiMetmDiff.Draw(c,kTRUE,format,2); plotAntiMetm.SetName("fitantimetmlog"); plotAntiMetm.SetLogy(); plotAntiMetm.SetYRange(1e-3*(hAntiDataMetm->GetMaximum()),10*(hAntiDataMetm->GetMaximum())); plotAntiMetm.Draw(c,kTRUE,format,1); //-------------------------------------------------------------------------------------------------------------- // Output //============================================================================================================== cout << "*" << endl; cout << "* SUMMARY" << endl; cout << "*--------------------------------------------------" << endl; // // Write fit results // ofstream txtfile; char txtfname[100]; ios_base::fmtflags flags; Double_t chi2prob, chi2ndf; Double_t ksprob, ksprobpe; chi2prob = hDataMet->Chi2Test(hPdfMet,"PUW"); chi2ndf = hDataMet->Chi2Test(hPdfMet,"CHI2/NDFUW"); ksprob = hDataMet->KolmogorovTest(hPdfMet); ksprobpe = hDataMet->KolmogorovTest(hPdfMet,"DX"); sprintf(txtfname,"%s/fitresWm.txt",CPlot::sOutDir.Data()); txtfile.open(txtfname); assert(txtfile.is_open()); flags = txtfile.flags(); txtfile << setprecision(10); txtfile << " *** Yields *** " << endl; txtfile << "Selected: " << hDataMet->Integral() << endl; txtfile << " Signal: " << nSig.getVal() << " +/- " << nSig.getPropagatedError(*fitRes) << endl; txtfile << " QCD: " << nQCD.getVal() << " +/- " << nQCD.getPropagatedError(*fitRes) << endl; txtfile << " Other: " << nEWK.getVal() << " +/- " << nEWK.getPropagatedError(*fitRes) << endl; txtfile << endl; txtfile.flags(flags); fitRes->printStream(txtfile,RooPrintable::kValue,RooPrintable::kVerbose); txtfile << endl; printCorrelations(txtfile, fitRes); txtfile << endl; printChi2AndKSResults(txtfile, chi2prob, chi2ndf, ksprob, ksprobpe); txtfile.close(); chi2prob = hDataMetp->Chi2Test(hPdfMetp,"PUW"); chi2ndf = hDataMetp->Chi2Test(hPdfMetp,"CHI2/NDFUW"); ksprob = hDataMetp->KolmogorovTest(hPdfMetp); ksprobpe = hDataMetp->KolmogorovTest(hPdfMetp,"DX"); sprintf(txtfname,"%s/fitresWmp.txt",CPlot::sOutDir.Data()); txtfile.open(txtfname); assert(txtfile.is_open()); flags = txtfile.flags(); txtfile << setprecision(10); txtfile << " *** Yields *** " << endl; txtfile << "Selected: " << hDataMetp->Integral() << endl; txtfile << " Signal: " << nSigp.getVal() << " +/- " << nSigp.getPropagatedError(*fitResp) << endl; txtfile << " QCD: " << nQCDp.getVal() << " +/- " << nQCDp.getPropagatedError(*fitResp) << endl; txtfile << " Other: " << nEWKp.getVal() << " +/- " << nEWKp.getPropagatedError(*fitResp) << endl; txtfile << endl; txtfile.flags(flags); fitResp->printStream(txtfile,RooPrintable::kValue,RooPrintable::kVerbose); txtfile << endl; printCorrelations(txtfile, fitResp); txtfile << endl; printChi2AndKSResults(txtfile, chi2prob, chi2ndf, ksprob, ksprobpe); txtfile.close(); chi2prob = hDataMetm->Chi2Test(hPdfMetm,"PUW"); chi2ndf = hDataMetm->Chi2Test(hPdfMetm,"CHI2/NDFUW"); ksprob = hDataMetm->KolmogorovTest(hPdfMetm); ksprobpe = hDataMetm->KolmogorovTest(hPdfMetm,"DX"); sprintf(txtfname,"%s/fitresWmm.txt",CPlot::sOutDir.Data()); txtfile.open(txtfname); assert(txtfile.is_open()); flags = txtfile.flags(); txtfile << setprecision(10); txtfile << " *** Yields *** " << endl; txtfile << "Selected: " << hDataMetm->Integral() << endl; txtfile << " Signal: " << nSigm.getVal() << " +/- " << nSigm.getPropagatedError(*fitResm) << endl; txtfile << " QCD: " << nQCDm.getVal() << " +/- " << nQCDm.getPropagatedError(*fitResm) << endl; txtfile << " Other: " << nEWKm.getVal() << " +/- " << nEWKm.getPropagatedError(*fitResm) << endl; txtfile << endl; txtfile.flags(flags); fitResm->printStream(txtfile,RooPrintable::kValue,RooPrintable::kVerbose); txtfile << endl; printCorrelations(txtfile, fitResm); txtfile << endl; printChi2AndKSResults(txtfile, chi2prob, chi2ndf, ksprob, ksprobpe); txtfile.close(); makeHTML(outputDir); cout << endl; cout << " <> Output saved in " << outputDir << "/" << endl; cout << endl; gBenchmark->Show("fitWm"); }
void NewCosmicstest(){ //gROOT->Reset(); TStopwatch *clock0 = new TStopwatch(); TFile *fout = new TFile("Cosmictest.root","RECREATE"); bool high = 1; //Float_t z0 = 1400; Float_t z0 = 0; Float_t yTop = 600; Float_t xTop = 300; Float_t zTop = 3650; Float_t xdist = 3000; Float_t zdist = 9000; TH2D *StartXZ = new TH2D("xz","xz;x[cm];z[cm]",30,-(xdist/2),xdist/2,90,z0 - 4500,z0 + 4500); TH1D *StartTheta = new TH1D("#theta","#theta; #theta_Zenith",100,0,2); TH1D *StartPhi = new TH1D("#phi","#phi; #phi",50,0,7); TH1D *StartPHigh = new TH1D("PHigh","P; P[GeV]",100,-1,3); TH1D *StartP = new TH1D("P","P;P[GeV]",100,-1,3); TH1D *StartPLow = new TH1D("PLow","P;P[GeV]",100,-1,3); //TH1D *StartP = new TH1D("P","P;P[GeV]",100,0.1,1000); BinLogX(StartP); BinLogX(StartPHigh); BinLogX(StartPLow); TH2D *StartPTheta = new TH2D("P,Theta","P-Theta;P[GeV];#theta",150,-1,3,50,0,2); BinLogX(StartPTheta); TH2D *MCXZ = new TH2D("MCxz","xz;x[cm];z[cm]",30,-(xdist/2),xdist/2,90,z0 - 4500,z0 + 4500); TH1D *MCTheta = new TH1D("MC#theta","#theta; #theta",100,0,2); TH1D *MCPhi = new TH1D("MC#phi","#phi, #phi",50,0,7); TH1I *MCnTry = new TH1I("nTry","nTry",100,4.6,5); Double_t totalweightsum=0; Double_t px,py,pz,x,y,z,w, weighttest, weight; Int_t nTry,nInside,nEvent,nTest; Co3Rng *fRandomEngine = new Co3Rng(); int EVENTS = 400000; Int_t kmax = 40000; float weight1,weight1Low,weight1High; weight1Low = 123*xdist*zdist/EVENTS/10000; // expected #muons per spill/ #simulated events per spill 174*30*90/500000 cout<<weight1Low<<endl; double I = fRandomEngine->fSpectrumH->Integral(100,1000); weight1High = 2*TMath::Pi()/3*I*xdist*zdist/EVENTS/10000; //weight2 = 900/I; // 1/(mean momentum weight), P_max-P_min/(3*0.3044/2pi) cout<< weight1High<<endl; Float_t weight3 = 4.833931503; // MC average of nTry/nEvents 4.833949997 +- 0.000010494 weight1 = 1; weight = weight1 / weight3; nInside = 0; nEvent = 0; nTest = 0; weighttest = 0; y = 1900; //20m over beam axis w = weight/kmax; clock0->Start(); for(Int_t k = 0;k<kmax;k++){ cout<<k<<endl; nTry =0; for(Int_t i=0;i<EVENTS;i++){ Bool_t hit = 0; do{ // shower characteristics double phi = fRandomEngine->Uniform(0,2*TMath::Pi()); double theta = fRandomEngine->fTheta->GetRandom(); //momentum components px = TMath::Sin(phi)*TMath::Sin(theta); pz = TMath::Cos(phi)*TMath::Sin(theta); py = -TMath::Cos(theta); // start position, area 1120m^2 x = fRandomEngine->Uniform(-xdist/2,xdist/2); z = fRandomEngine->Uniform(z0 - zdist/2, z0 + zdist/2); // claim for flight close to the actual detector if((abs(x-(y+yTop)*px/py) < xTop && abs(z-z0-(y+yTop)*pz/py) < zTop) || (abs(x-(y-yTop)*px/py) < xTop && abs(z-z0-(y-yTop)*pz/py) < zTop)|| abs(y-(x+xTop)*py/px)<yTop && abs(z-z0-(x+xTop)*pz/px)<zTop || abs(y-(x-xTop)*py/px)<yTop && abs(z-z0-(x-xTop)*pz/px)<zTop){ // muon momentum double P; //if (!high) {P = fRandomEngine->NEWstest(theta);} //else {P = fRandomEngine->fSpectrumH->GetRandom();} // high P = fRandomEngine->fSpectrumH->GetRandom(); w = weight1High/weight3/kmax; StartP->Fill(P,w); StartPHigh->Fill(P,w); StartPTheta->Fill(P,theta,w); // low P = fRandomEngine->NEWstest(theta); w = weight1Low/weight3/kmax; StartP->Fill(P,w); StartPLow->Fill(P,w); StartPTheta->Fill(P,theta,w); px = px*P; py = py*P; pz = pz*P; //muon or anti-muon hit = 1; nInside++; // StartP->Fill(P,w); w = weight1Low/weight3/kmax + weight1High/weight3/kmax; StartTheta->Fill(theta,w); // kein Weight! StartPhi->Fill(phi,w); // kein Weight! StartXZ->Fill(x,z,w); // kein Weight! StartPTheta->Fill(P,theta,w); } nTry++; weighttest += w; MCTheta->Fill(theta,w); // kein Weight! MCPhi->Fill(phi,w); MCXZ->Fill(x,z,w); nTest++; }while(!hit); nEvent++; } MCnTry->Fill(1.0*nTry/EVENTS); } clock0->Stop(); delete fRandomEngine; cout<<nEvent<<" events have been generated."<<endl; cout<<"There is a total of "<<nInside<<"/"<<nTest<<" muons that passed close enough to the detector."<<endl; cout<<"Including the given weight this corresponds to "; cout<<kmax*weighttest/xdist/zdist*10000/123.3044<<" spills (1 spill = "<<xdist*zdist*123.3044/10000; cout<<" real cosmic muons = "<<EVENTS<<" simulated events)."<<endl; cout<<weighttest<<endl; clock0->Print(); Double_t meanflux = 0; Int_t binsum = 0; for (Int_t ix = 2; ix<29;ix++){ for (Int_t iz = 2; iz<89;iz++){ binsum++; meanflux += MCXZ->GetBinContent(ix,iz); } } cout<< "meanflux: "<<meanflux/binsum<<" "<< meanflux<<endl<<endl; printf("MCnTry: %.9f +- %.9f",MCnTry->GetMean(),MCnTry->GetMeanError()); cout<<endl<<endl; TCanvas *c1 = new TCanvas("c1","c1",400,400); c1->Divide(1,1); c1->cd(1); MCnTry->DrawCopy(); TCanvas *c4 = new TCanvas("c4","c4",400,400); c4->Divide(1,1); c4->cd(1); StartPTheta->DrawCopy("SURF2"); gPad->SetLogx(); //TCanvas *c2 = new TCanvas("c2","c2",400,400); //c2->Divide(1,1); //c2->cd(1); //gPad->SetLogy(); //wei->DrawCopy(); TCanvas *c3 = new TCanvas("c3","c3",1600,800); c3->Divide(4,2); c3->cd(1); StartXZ->DrawCopy("COLZ"); c3->cd(2); //MCP->SetLineColor(kGreen); // MCP->DrawCopy(); //StartP->DrawCopy(); //TF1 *fs = new TF1("fs",NEWs,1,100,2); //fs->FixParameter(0, 0); //fs->FixParameter(1, 500); //StartP->Add(fs,-1); StartP->DrawCopy(); //StartP->Fit(fs,"I"); // //fs->DrawCopy("SAME"); //gPad->SetLogy(); gPad->SetLogx(); c3->cd(3); MCTheta->SetLineColor(kGreen); MCTheta->DrawCopy(); StartTheta->DrawCopy("SAME"); //TF1 *f1 = new TF1("f1","[0]*cos(x)*cos(x)",1.57,3.14); //StartTheta->Fit(f1,"","",1.57,3.14); gPad->SetLogy(0); gPad->SetLogx(0); c3->cd(4); MCPhi->SetLineColor(kGreen); MCPhi->DrawCopy(); StartPhi->DrawCopy("SAME"); //TF1 *f1 = new TF1("f1","[0]*cos(x)*cos(x)",1.57,3.14); //StartTheta->Fit(f1,"","",1.57,3.14); gPad->SetLogy(0); gPad->SetLogx(0); c3->cd(5); MCXZ->DrawCopy("COLZ"); c3->cd(6); //MCP->Divide(StartP); // MCP->DrawCopy(); gPad->SetLogy(0); gPad->SetLogx(0); c3->cd(7); //MCTheta->Divide(StartTheta); MCTheta->DrawCopy(); gPad->SetLogy(); gPad->SetLogx(0); c3->cd(8); //MCPhi->Divide(StartPhi); MCPhi->DrawCopy(); gPad->SetLogy(0); gPad->SetLogx(0); c3->Update(); c3->SaveAs("Start.png"); StartXZ->Write(); StartTheta->Write(); StartPhi->Write(); StartP->Write(); StartPLow->Write(); StartPHigh->Write(); StartPTheta->Write(); MCXZ->Write(); MCTheta->Write(); MCPhi->Write(); MCnTry->Write(); fout ->Close(); }
void run_plot(TString FileNameHead = "output_proto",TString fileKine="../Kinematics/Decay_kinematics/10Be_4He_19MeV.txt",TString fileKine2="../Kinematics/Decay_kinematics/10Be_12C_19MeV.txt") { TString workdir = getenv("VMCWORKDIR"); TString FilePath = workdir + "/macro/Unpack_GETDecoder2/"; TString FileNameTail = ".root"; TString FileName = FilePath + FileNameHead + FileNameTail; std::cout<<" Opening File : "<<FileName.Data()<<std::endl; TFile* file = new TFile(FileName.Data(),"READ"); //TFile* file = new TFile(FileNameHead_chain.Data(),"READ"); TTree* tree = (TTree*) file -> Get("cbmsim"); Int_t nEvents = tree -> GetEntriesFast(); std::cout<<" Number of events : "<<nEvents<<std::endl; TCanvas *c2 = new TCanvas("c2","c2",200,10,700,700); c2->Divide(2,1); TCanvas *c3 = new TCanvas("c3","c3",200,10,700,700); //c3->Divide(2,1); TH2D* Q02_Kine = new TH2D("Q02_Kine","Q02_Kine",1000,0,180,1000,0,180); Q02_Kine->SetMarkerColor(2); Q02_Kine->SetMarkerStyle(20); Q02_Kine->SetMarkerSize(0.7); TH2D* Q13_Kine = new TH2D("Q13_Kine","Q13_Kine",1000,0,180,1000,0,180); Q13_Kine->SetMarkerColor(2); Q13_Kine->SetMarkerStyle(20); Q13_Kine->SetMarkerSize(0.7); TH1D* Vertex = new TH1D("Vertex","Vertex",100,0,1000); TH2D* Vertex_vs_Angle = new TH2D("Vertex_vs_Angle","Vertex_vs_Angle",1000,0,1000,200,0,180); TCutG *cutg = new TCutG("CUTG",27); cutg->SetVarX("Q02_Kine"); cutg->SetVarY(""); cutg->SetTitle("Graph"); cutg->SetFillColor(1); cutg->SetPoint(0,13.91253,83.41335); cutg->SetPoint(1,16.43826,70.76698); cutg->SetPoint(2,29.69832,47.3185); cutg->SetPoint(3,32.22404,36.51639); cutg->SetPoint(4,49.90412,29.13934); cutg->SetPoint(5,68.21562,18.86417); cutg->SetPoint(6,79.79186,15.70258); cutg->SetPoint(7,86.73761,10.96019); cutg->SetPoint(8,86.52713,6.217797); cutg->SetPoint(9,77.05566,5.427399); cutg->SetPoint(10,69.26801,8.325526); cutg->SetPoint(11,55.79747,15.17564); cutg->SetPoint(12,50.53555,20.9719); cutg->SetPoint(13,35.80215,25.97775); cutg->SetPoint(14,31.17165,21.23536); cutg->SetPoint(15,24.43639,19.3911); cutg->SetPoint(16,19.80589,24.39695); cutg->SetPoint(17,20.01637,30.98361); cutg->SetPoint(18,22.75257,36.25293); cutg->SetPoint(19,21.91066,46.79157); cutg->SetPoint(20,16.0173,54.16862); cutg->SetPoint(21,8.229653,66.02459); cutg->SetPoint(22,6.545836,73.13817); cutg->SetPoint(23,7.177267,86.04801); cutg->SetPoint(24,11.59729,88.15574); cutg->SetPoint(25,13.70206,83.41335); cutg->SetPoint(26,13.91253,83.41335); TCutG *cutg2 = new TCutG("CUTG2",6); cutg2->SetVarX("Q02_Kine"); cutg2->SetVarY(""); cutg2->SetTitle("Graph"); cutg2->SetFillColor(1); cutg2->SetPoint(0,54.85507,28.95589); cutg2->SetPoint(1,64.59005,23.76482); cutg2->SetPoint(2,64.52764,10.0358); cutg2->SetPoint(3,54.81763,12.22152); cutg2->SetPoint(4,54.86755,29.0242); cutg2->SetPoint(5,54.85507,28.95589); TCutG *cutg3 = new TCutG("CUTG2",6); cutg3->SetVarX("Q02_Kine"); cutg3->SetVarY(""); cutg3->SetTitle("Graph"); cutg3->SetFillColor(1); cutg3->SetPoint(0,27.46418,21.43491); cutg3->SetPoint(1,37.45702,16.44231); cutg3->SetPoint(2,37.13467,2.463016); cutg3->SetPoint(3,27.46418,4.792898); cutg3->SetPoint(4,27.78653,21.43491); cutg3->SetPoint(5,27.46418,21.43491); TTreeReader Reader1("cbmsim", file); TTreeReaderValue<TClonesArray> analysisArray(Reader1, "ATProtoEventAna"); Int_t evnt = 0; while (Reader1.Next()) { if(evnt%1000==0) std::cout<<" Event : "<<evnt<<std::endl; evnt++; ATProtoEventAna* analysis = (ATProtoEventAna*) analysisArray->At(0); //Double_t ATProtoAnalysis::*HoughDist = &ATProtoAnalysis::fHoughDist; std::vector<Double_t> *AngleFit = analysis->GetAngleFit(); std::vector<Double_t> *Par0 = analysis->GetPar0(); std::vector<Double_t> *vertex = analysis->GetVertex(); std::vector<Double_t> *Chi2 = analysis->GetChi2(); std::vector<Int_t> *NDF = analysis->GetNDF(); if( TMath::Abs(vertex->at(0) - vertex->at(2))<20 && (vertex->at(0)>0 && vertex->at(2)>0)) if( Chi2->at(0)/NDF->at(0)<10.0 && Chi2->at(2)/NDF->at(2)<10.0 ) Q02_Kine->Fill(AngleFit->at(0),AngleFit->at(2)); if( TMath::Abs(vertex->at(1) - vertex->at(3))<20 && (vertex->at(1)>0 && vertex->at(3)>0)) if( Chi2->at(1)/NDF->at(1)<10.0 && Chi2->at(3)/NDF->at(3)<10.0 ) Q02_Kine->Fill(AngleFit->at(1),AngleFit->at(3)); if(cutg->IsInside(AngleFit->at(0),AngleFit->at(2)) ) { Vertex->Fill(Par0->at(0)); Vertex_vs_Angle->Fill(Par0->at(0),AngleFit->at(0)); } if(cutg->IsInside(AngleFit->at(1),AngleFit->at(3)) ) { Vertex->Fill(Par0->at(1)); Vertex_vs_Angle->Fill(Par0->at(1),AngleFit->at(1)); } //if(cutg3->IsInside(AngleFit->at(0),AngleFit->at(2)) ) std::cout<<evnt<<std::endl; } Double_t *ThetaCMS = new Double_t[20000]; Double_t *ThetaLabRec = new Double_t[20000]; Double_t *EnerLabRec = new Double_t[20000]; Double_t *ThetaLabSca = new Double_t[20000]; Double_t *EnerLabSca = new Double_t[20000]; Double_t *ThetaCMS2 = new Double_t[20000]; Double_t *ThetaLabRec2 = new Double_t[20000]; Double_t *EnerLabRec2 = new Double_t[20000]; Double_t *ThetaLabSca2 = new Double_t[20000]; Double_t *EnerLabSca2 = new Double_t[20000]; std::ifstream *kineStr = new std::ifstream(fileKine.Data()); Int_t numKin=0; if(!kineStr->fail()) { while(!kineStr->eof()) { *kineStr>>ThetaCMS[numKin]>>ThetaLabRec[numKin]>>EnerLabRec[numKin]>>ThetaLabSca[numKin]>>EnerLabSca[numKin]; numKin++; } } else if(kineStr->fail()) std::cout<<" Warning : No Kinematics file found for this reaction! Please run the macro on $SIMPATH/macro/Kinematics/Decay_kinematics/Mainrel.cxx"<<std::endl;
void ztree::ffgammajet(std::string outfname, int centmin, int centmax, float phoetmin, float phoetmax, std::string gen) { string tag = outfname; string s_alpha = gen; if (fChain == 0) return; Long64_t nentries = fChain->GetEntriesFast(); TFile * fout = new TFile(Form("%s_%s_%s_%d_%d.root",outfname.data(),tag.data(),s_alpha.data(),abs(centmin),abs(centmax)),"recreate"); TH2D * hsubept = new TH2D(Form("hsubept_%s_%s_%d_%d",tag.data(),s_alpha.data(),abs(centmin),abs(centmax)),Form(";#xi=ln(1/z);"),100,-0.5,99.5,100,0,100); TH2D * hsubept_refcone = new TH2D(Form("hsubept_refcone_%s_%s_%d_%d",tag.data(),s_alpha.data(),abs(centmin),abs(centmax)),Form(";#xi=ln(1/z);"),100,-0.5,99.5,100,0,100); TH1D * hjetpt = new TH1D(Form("hjetpt_%s_%s_%d_%d",tag.data(),s_alpha.data(),abs(centmin),abs(centmax)),Form(";jet p_{T};"),20,0,500); TH1D * hjetgendphi = new TH1D(Form("hjetgendphi_%s_%s_%d_%d",tag.data(),s_alpha.data(),abs(centmin),abs(centmax)),Form(";#DeltaR_{gen,reco};"),20,0,0.1); TH1D * hgammaff = new TH1D(Form("hgammaff_%s_%s_%d_%d",tag.data(),s_alpha.data(),abs(centmin),abs(centmax)),Form(";z;"),20,0,1); TH1D * hgammaffxi = new TH1D(Form("hgammaffxi_%s_%s_%d_%d",tag.data(),s_alpha.data(),abs(centmin),abs(centmax)),Form(";#xi=ln(1/z);"),10,0,5); TH1D * hgammaffxi_refcone = new TH1D(Form("hgammaffxi_refcone_%s_%s_%d_%d",tag.data(),s_alpha.data(),abs(centmin),abs(centmax)),Form(";#xi=ln(1/z);"),10,0,5); TH1D * hgammaphoffxi = new TH1D(Form("hgammaphoffxi_%s_%s_%d_%d",tag.data(),s_alpha.data(),abs(centmin),abs(centmax)),Form(";#xi=ln(1/z);"),10,0,5); TH1D * hgammaphoffxi_refcone = new TH1D(Form("hgammaphoffxi_refcone_%s_%s_%d_%d",tag.data(),s_alpha.data(),abs(centmin),abs(centmax)),Form(";#xi=ln(1/z);"),10,0,5); Long64_t nbytes = 0, nb = 0; cout<<phoetmin<<" "<<phoetmax<<endl; for (Long64_t jentry=0; jentry<nentries;jentry++) { if(jentry%10000==0) { cout<<jentry<<"/"<<nentries<<endl; } Long64_t ientry = LoadTree(jentry); if (ientry < 0) break; // cout<<njet<<endl; // if(jentry > 10000) break; nb = fChain->GetEntry(jentry); nbytes += nb; if(hiBin < centmin || hiBin >= centmax) continue; //centrality cut if(nPho!=1) continue; // if(phoEt[0]<phoetmin || phoEt[0]>phoetmax) continue; if(weight==0) weight=1; // cout<<njet<<endl; if(gen.compare("gen")==0) { for (int ijet = 0; ijet < njet; ijet++) { if(mcEt[pho_genMatchedIndex[0]]<phoetmin || mcEt[pho_genMatchedIndex[0]]>phoetmax) continue; if( nPho==2 ) continue; if( jetpt[ijet]<40 ) continue; //jet pt Cut if( fabs(jeteta[ijet]) > 1.6) continue; //jeteta Cut if( fabs(jeteta[ijet]) < 0.3) continue; //jeteta Cut for reflected cone if( jetID[ijet]==0 ) continue; //redundant in this skim (all true) if( acos(cos(jetphi[ijet] - phoPhi[0])) < 7 * pi / 8 ) continue; hjetpt->Fill(jetpt[ijet]); float denrecodphi = acos(cos(jetphi[ijet] - gjetphi[ijet])); hjetgendphi->Fill(denrecodphi); TLorentzVector vjet; vjet.SetPtEtaPhiM(gjetpt[ijet],gjeteta[ijet],gjetphi[ijet],0); for(int igen = 0 ; igen < mult ; ++igen) { if(!(abs(pdg[igen])==11 || abs(pdg[igen])==13 || abs(pdg[igen])==211 || abs(pdg[igen])==2212 || abs(pdg[igen])==321)) continue; if(sube[igen] != 0) continue; float dr = genjettrk_dr(igen,ijet); float dr_refcone = genrefconetrk_dr(igen,ijet); if(dr<0.3) { TLorentzVector vtrack; vtrack.SetPtEtaPhiM(pt[igen],eta[igen],phi[igen],0); float angle = vjet.Angle(vtrack.Vect()); float z = pt[igen]*cos(angle)/gjetpt[ijet]; float zpho = pt[igen]/phoEt[0]; float xi = log(1.0/z); float xipho = log(1.0/zpho); hgammaff->Fill(z); hgammaffxi->Fill(xi); hgammaphoffxi->Fill(xipho); hsubept->Fill(sube[igen],pt[igen]); // cout<<jetpt[ijet]<<endl; } if(dr_refcone<0.3) { float z = pt[igen]/gjetpt[ijet]; float zpho = pt[igen]/phoEt[0]; float xi = log(1.0/z); float xipho = log(1.0/zpho); hgammaffxi_refcone->Fill(xi); hgammaphoffxi_refcone->Fill(xipho); hsubept_refcone->Fill(sube[igen],pt[igen]); } } } } else { for (int ijet = 0; ijet < njet; ijet++) { if( nPho==2 ) continue; if( phoEt[0]*phoCorr[0]<phoetmin || phoEt[0]*phoCorr[0]>phoetmax) continue; if( jetpt[ijet]<40 ) continue; //jet pt Cut if( fabs(jeteta[ijet]) > 1.6) continue; //jeteta Cut if( fabs(jeteta[ijet]) < 0.3) continue; //jeteta Cut for reflected cone if( jetID[ijet]==0 ) continue; //redundant in this skim (all true) if( acos(cos(jetphi[ijet] - phoPhi[0])) < 7 * pi / 8 ) continue; hjetpt->Fill(jetpt[ijet]); TLorentzVector vjet; vjet.SetPtEtaPhiM(jetpt[ijet],jeteta[ijet],jetphi[ijet],0); for (int itrk = 0; itrk < nTrk; itrk++) { float dr = jettrk_dr(itrk,ijet); // float dr = genjetrecotrk_dr(itrk,ijet); float dr_refcone = refconetrk_dr(itrk,ijet); // float dr_refcone = genrefconerecotrk_dr(itrk,ijet); if(dr<0.3) { TLorentzVector vtrack; vtrack.SetPtEtaPhiM(trkPt[itrk],trkEta[itrk],trkPhi[itrk],0); float angle = vjet.Angle(vtrack.Vect()); float z = trkPt[itrk]*cos(angle)/jetpt[ijet]; float zpho = trkPt[itrk]/phoEt[0]; float xi = log(1.0/z); float xipho = log(1.0/zpho); hgammaff->Fill(z,trkWeight[itrk]); hgammaffxi->Fill(xi,trkWeight[itrk]); hgammaphoffxi->Fill(xipho,trkWeight[itrk]); // hgammaff->Fill(z); // hgammaffxi->Fill(xi); // hgammaphoffxi->Fill(xipho); // cout<<jetpt[ijet]<<endl; } if(dr_refcone<0.3) { float z = trkPt[itrk]/jetpt[ijet]; float zpho = trkPt[itrk]/phoEt[0]; float xi = log(1.0/z); float xipho = log(1.0/zpho); hgammaffxi_refcone->Fill(xi,trkWeight[itrk]); hgammaphoffxi_refcone->Fill(xipho,trkWeight[itrk]); // hgammaffxi_refcone->Fill(xi); // hgammaphoffxi_refcone->Fill(xipho); } } // photons: normal mode power mode // pho 40 trigger // photon spike cuts etc // phoet > 35 // phoet > 40 after correction // haven't made it yet // phoeta < 1.44 // sumiso < 1 GeV // h/em < 0.1 // sigmaetaeta < 0.01 // jets: // some pt // jeteta < 1.6 // some id cuts // none yet but we'll add some // ak3pupf jets // delphi > 7 pi / 8 } } /* */ } fout->Write(); fout->Close(); }
void drawLatinoTree(const TString inputFileName = "giveMeMyMoney.root") { TH1::SetDefaultSumw2(); // // Settings // gStyle->SetOptStat(0); // Int_t NVTXBINS = 30; // // Setup input ntuple // TFile* inputFile = new TFile(inputFileName); TTree* inputTree = (TTree*)inputFile->Get("latino"); TString path = Form("Results"); gSystem->mkdir(path, kTRUE); TFile* outFile = new TFile(path + "/out.root", "recreate"); // // Declare variables to read in ntuple // Int_t nEvents; Float_t nvtx; Float_t metPfType1, metPfType1Phi, corrMetPfType1, corrMetPfType1Phi; Float_t metPfRaw, metPfRawPhi, corrMetPfRaw, corrMetPfRawPhi; //TVector2 *t2_slimMet=0, *t2_slimMetTxy=0; inputTree->SetBranchAddress("nvtx", &nvtx); // number of vertices inputTree->SetBranchAddress("std_vector_lepton_pt", &std_vector_lepton_pt); inputTree->SetBranchAddress("std_vector_lepton_flavour", &std_vector_lepton_flavour); inputTree->SetBranchAddress("std_vector_lepton_eta", &std_vector_lepton_eta); inputTree->SetBranchAddress("std_vector_lepton_phi", &std_vector_lepton_phi); inputTree->SetBranchAddress("metPfType1", &metPfType1); inputTree->SetBranchAddress("metPfType1Phi", &metPfType1Phi); inputTree->SetBranchAddress("corrMetPfType1", &corrMetPfType1); inputTree->SetBranchAddress("corrMetPfType1Phi", &corrMetPfType1Phi); inputTree->SetBranchAddress("metPfRaw", &metPfRaw); inputTree->SetBranchAddress("metPfRawPhi", &metPfRawPhi); inputTree->SetBranchAddress("corrMetPfRaw", &corrMetPfRaw); inputTree->SetBranchAddress("corrMetPfRawPhi", &corrMetPfRawPhi); // // Declare histograms // TH1D *hSlimMet = new TH1D("hSlimMet","",100,0,150); hSlimMet->SetStats(0); hSlimMet->SetLineColor(1); TH1D *hSlimMetTxy = new TH1D("hSlimMetTxy","",100,0,150); hSlimMetTxy->SetStats(0); hSlimMetTxy->SetLineColor(2); TH1D *hMetDiff = new TH1D("hMetDiff","",100,-15,15); hMetDiff->SetStats(0); hMetDiff->GetXaxis()->SetTitle("Corr. - PfType1Met"); TH1D *hMetPull = new TH1D("hMetPull","",100,-1,1); hMetPull->SetStats(0); hMetPull->GetXaxis()->SetTitle("[Corr. - PfType1Met]/PfType1Met"); TH1D *hPhiDiff = new TH1D("hPhiDiff","",100,-1,1); hPhiDiff->SetStats(0); hPhiDiff->GetXaxis()->SetTitle("Corr.Phi - PfType1Phi"); TH1D *hPhi = new TH1D("hPhi","",20,-3.5,3.5); hPhi->SetStats(0); hPhi->SetLineColor(1); TH1D *hPhiTxy = new TH1D("hPhiTxy","",20,-3.5,3.5); hPhiTxy->SetStats(0); hPhiTxy->SetLineColor(4); TH1D *hMetRaw = new TH1D("hMetRaw","",100,0,150); hMetRaw->SetStats(0); hMetRaw->SetLineColor(1); TH1D *hMetRawTxy = new TH1D("hMetRawTxy","",100,0,150); hMetRawTxy->SetStats(0); hMetRawTxy->SetLineColor(2); TH1D *hMetRawDiff = new TH1D("hMetRawDiff","",100,-15,15); hMetRawDiff->SetStats(0); hMetRawDiff->GetXaxis()->SetTitle("Corr. - MetPfRaw"); TH1D *hMetRawPull = new TH1D("hMetRawPull","",100,-1,1); hMetRawPull->SetStats(0); hMetRawPull->GetXaxis()->SetTitle("[Corr. - MetPfRaw]/MetPfRaw"); TH1D *hRawPhiDiff = new TH1D("hRawPhiDiff","",100,-1,1); hRawPhiDiff->SetStats(0); hRawPhiDiff->GetXaxis()->SetTitle("Corr.Phi - PfRawPhi"); TH1D *hRawPhi = new TH1D("hRawPhi","",20,-3.5,3.5); hRawPhi->SetStats(0); hRawPhi->SetLineColor(1); TH1D *hRawPhiTxy = new TH1D("hRawPhiTxy","",20,-3.5,3.5); hRawPhiTxy->SetStats(0); hRawPhiTxy->SetLineColor(4); TH1D *hPhi_VtxRange[4]; TH1D *hPhiTxy_VtxRange[4]; for(int i=0;i<4;i++) { TString Tname = Form("hPhi_VtxRange_%d", i); hPhi_VtxRange[i] = new TH1D(Tname,"",20,-3.5,3.5); hPhiTxy_VtxRange[i] = new TH1D(Tname,"",20,-3.5,3.5); hPhi_VtxRange[i]->SetStats(0); hPhi_VtxRange[i]->SetLineColor(1); hPhiTxy_VtxRange[i]->SetStats(0); hPhiTxy_VtxRange[i]->SetLineColor(4); } TH1D *hPhi_NoCut = new TH1D("hPhi_NoCut","",20,-3.5,3.5); hPhi_NoCut->SetStats(0); hPhi_NoCut->SetLineColor(1); TH1D *hPhiTxy_NoCut = new TH1D("hPhiTxy_NoCut","",20,-3.5,3.5); hPhiTxy_NoCut->SetStats(0); hPhiTxy_NoCut->SetLineColor(4); TH2D *hMETnVtx_x = new TH2D("hMETnVtx_x","MET_{x} v. Number of Vertices",NVTXBINS,0,NVTXBINS,100,-150,150); hMETnVtx_x->GetXaxis()->SetTitle("Number of vertices"); hMETnVtx_x->GetYaxis()->SetTitle("MET_{x} [GeV]"); TH2D *hMETnVtx_y = new TH2D("hMETnVtx_y","MET_{y} v. Number of Vertices",NVTXBINS,0,NVTXBINS,100,-150,150); hMETnVtx_y->GetXaxis()->SetTitle("Number of vertices"); hMETnVtx_y->GetYaxis()->SetTitle("MET_{y} [GeV]"); TH2D *hMETnVtx_Txy_x = new TH2D("hMETnVtx_Txy_x","MET_{x} v. Number of Vertices",NVTXBINS,0,NVTXBINS,100,-150,150); hMETnVtx_Txy_x->GetXaxis()->SetTitle("Number of vertices"); hMETnVtx_Txy_x->GetYaxis()->SetTitle("MET_{x} [GeV]"); TH2D *hMETnVtx_Txy_y = new TH2D("hMETnVtx_Txy_y","MET_{y} v. Number of Vertices",NVTXBINS,0,NVTXBINS,100,-150,150); hMETnVtx_Txy_y->GetXaxis()->SetTitle("Number of vertices"); hMETnVtx_Txy_y->GetYaxis()->SetTitle("MET_{y} [GeV]"); TH1D *hRawPhi_NoCut = new TH1D("hRawPhi_NoCut","",20,-3.5,3.5); hRawPhi_NoCut->SetStats(0); hRawPhi_NoCut->SetLineColor(1); TH1D *hRawPhiTxy_NoCut = new TH1D("hRawPhiTxy_NoCut","",20,-3.5,3.5); hRawPhiTxy_NoCut->SetStats(0); hRawPhiTxy_NoCut->SetLineColor(4); TH2D *hMETRawNvtx_x = new TH2D("hMETRawNvtx_x","MET_{x} v. Number of Vertices",NVTXBINS,0,NVTXBINS,100,-150,150); hMETRawNvtx_x->GetXaxis()->SetTitle("Number of vertices"); hMETRawNvtx_x->GetYaxis()->SetTitle("MET_{x} [GeV]"); TH2D *hMETRawNvtx_y = new TH2D("hMETRawNvtx_y","MET_{y} v. Number of Vertices",NVTXBINS,0,NVTXBINS,100,-150,150); hMETRawNvtx_y->GetXaxis()->SetTitle("Number of vertices"); hMETRawNvtx_y->GetYaxis()->SetTitle("MET_{y} [GeV]"); TH2D *hMETRawNvtx_Txy_x = new TH2D("hMETRawNvtx_Txy_x","MET_{x} v. Number of Vertices",NVTXBINS,0,NVTXBINS,100,-150,150); hMETRawNvtx_Txy_x->GetXaxis()->SetTitle("Number of vertices"); hMETRawNvtx_Txy_x->GetYaxis()->SetTitle("MET_{x} [GeV]"); TH2D *hMETRawNvtx_Txy_y = new TH2D("hMETRawNvtx_Txy_y","MET_{y} v. Number of Vertices",NVTXBINS,0,NVTXBINS,100,-150,150); hMETRawNvtx_Txy_y->GetXaxis()->SetTitle("Number of vertices"); hMETRawNvtx_Txy_y->GetYaxis()->SetTitle("MET_{y} [GeV]"); Int_t totalEvents=0; double phi; int ttNtry = inputTree->GetEntries(); for(int jentry=0; jentry<ttNtry; jentry++) { inputTree->GetEntry(jentry); totalEvents += nEvents; hPhi_NoCut->Fill(metPfType1Phi); hPhiTxy_NoCut->Fill(corrMetPfType1Phi); hRawPhi_NoCut->Fill(metPfRawPhi); hRawPhiTxy_NoCut->Fill(corrMetPfRawPhi); if (std_vector_lepton_pt->size() < 2) continue; if( (*std_vector_lepton_flavour)[0]*(*std_vector_lepton_flavour)[1] !=-13*13) continue; double pt1=(*std_vector_lepton_pt)[0]; double pt2=(*std_vector_lepton_pt)[1]; double eta1=(*std_vector_lepton_eta)[0]; double eta2=(*std_vector_lepton_eta)[1]; double phi1=(*std_vector_lepton_phi)[0]; double phi2=(*std_vector_lepton_phi)[1]; if ( pt1< 20) continue; if ( pt2 < 10) continue; //TLorentzVector a, b; //a.SetPtEtaPhiM(pt1,eta1,phi1,0.1); //b.SetPtEtaPhiM(pt2,eta2,phi2,0.1); //double zmass = (a+b).M(); //if(fabs(zmass-91.2)>15 ) continue; if( metPfType1 < 20) continue; //if( metPfType1 > 30) continue; // // Fill histograms // hMetDiff->Fill(corrMetPfType1 - metPfType1); hMetPull->Fill( (corrMetPfType1 - metPfType1)/metPfType1 ); hPhiDiff->Fill(corrMetPfType1Phi - metPfType1Phi); hMETnVtx_x->Fill(nvtx,metPfType1*TMath::Cos(metPfType1Phi)); hMETnVtx_y->Fill(nvtx,metPfType1*TMath::Sin(metPfType1Phi)); hMETnVtx_Txy_x->Fill(nvtx,corrMetPfType1*TMath::Cos(corrMetPfType1Phi)); hMETnVtx_Txy_y->Fill(nvtx,corrMetPfType1*TMath::Sin(corrMetPfType1Phi)); hSlimMet ->Fill(metPfType1); hSlimMetTxy ->Fill(corrMetPfType1); hPhi->Fill(metPfType1Phi); hPhiTxy->Fill(corrMetPfType1Phi); hMetRawDiff->Fill(corrMetPfRaw - metPfRaw); hMetRawPull->Fill( (corrMetPfRaw - metPfRaw)/metPfRaw); hRawPhiDiff->Fill(corrMetPfRawPhi - metPfRawPhi); hMETRawNvtx_x->Fill(nvtx,metPfRaw*TMath::Cos(metPfRawPhi)); hMETRawNvtx_y->Fill(nvtx,metPfRaw*TMath::Sin(metPfRawPhi)); hMETRawNvtx_Txy_x->Fill(nvtx,corrMetPfRaw*TMath::Cos(corrMetPfRawPhi)); hMETRawNvtx_Txy_y->Fill(nvtx,corrMetPfRaw*TMath::Sin(corrMetPfRawPhi)); hMetRaw ->Fill(metPfRaw); hMetRawTxy ->Fill(corrMetPfRaw); hRawPhi->Fill(metPfRawPhi); hRawPhiTxy->Fill(corrMetPfRawPhi); if(nvtx < 5) { hPhi_VtxRange[0]->Fill(metPfType1Phi); hPhiTxy_VtxRange[0]->Fill(corrMetPfType1Phi); }else if(nvtx >=5 && nvtx <15){ hPhi_VtxRange[1]->Fill(metPfType1Phi); hPhiTxy_VtxRange[1]->Fill(corrMetPfType1Phi); }else if(nvtx >=15 && nvtx <25){ hPhi_VtxRange[2]->Fill(metPfType1Phi); hPhiTxy_VtxRange[2]->Fill(corrMetPfType1Phi); }else if(nvtx >=25 ){ hPhi_VtxRange[3]->Fill(metPfType1Phi); hPhiTxy_VtxRange[3]->Fill(corrMetPfType1Phi); } } cout << "totalEvents is " << totalEvents << endl; // Loop through nVtx bins and find the mean value of metx and mety in each bin // Plot nVtx v. mean values of metx/mety in a separate histogram (1 for metx and 1 for mety) TH1D* hmetx_proj = new TH1D(); TH1D* hmety_proj = new TH1D(); Double_t meanmetx, meanmety; TH2D* hMEtMeanVtx_x = new TH2D("hMEtMeanVtx_x","MET_{x} v. Number of vertices",NVTXBINS,0,NVTXBINS,100,-25,15); hMEtMeanVtx_x->GetXaxis()->SetTitle("Number of vertices"); hMEtMeanVtx_x->GetYaxis()->SetTitle("<MET_{x}> [GeV]"); TH2D* hMEtMeanVtx_y = new TH2D("hMEtMeanVtx_y","MET_{y} v. Number of vertices",NVTXBINS,0,NVTXBINS,100,-25,15); hMEtMeanVtx_y->GetXaxis()->SetTitle("Number of vertices"); hMEtMeanVtx_y->GetYaxis()->SetTitle("<MET_{y}> [GeV]"); TH2D* hMEtMeanVtx_Txy_x = new TH2D("hMEtMeanVtx_Txy_x","MET_{x} v. Number of vertices",NVTXBINS,0,NVTXBINS,100,-25,15); hMEtMeanVtx_Txy_x->GetXaxis()->SetTitle("Number of vertices"); hMEtMeanVtx_Txy_x->GetYaxis()->SetTitle("<MET_{x}> [GeV]"); TH2D* hMEtMeanVtx_Txy_y = new TH2D("hMEtMeanVtx_Txy_y","MET_{y} v. Number of vertices",NVTXBINS,0,NVTXBINS,100,-25,15); hMEtMeanVtx_Txy_y->GetXaxis()->SetTitle("Number of vertices"); hMEtMeanVtx_Txy_y->GetYaxis()->SetTitle("<MET_{y}> [GeV]"); for(int jbin=1;jbin<hMEtMeanVtx_x->GetNbinsX()+1;jbin++) { hmetx_proj = hMETnVtx_x->ProjectionY("metx_proj",jbin,jbin+1,""); hmety_proj = hMETnVtx_y->ProjectionY("mety_proj",jbin,jbin+1,""); meanmetx = hmetx_proj->GetMean(); meanmety = hmety_proj->GetMean(); hMEtMeanVtx_x->Fill(jbin,meanmetx); hMEtMeanVtx_y->Fill(jbin,meanmety); hmetx_proj = hMETnVtx_Txy_x->ProjectionY("metx_proj",jbin,jbin+1,""); hmety_proj = hMETnVtx_Txy_y->ProjectionY("mety_proj",jbin,jbin+1,""); meanmetx = hmetx_proj->GetMean(); meanmety = hmety_proj->GetMean(); hMEtMeanVtx_Txy_x->Fill(jbin,meanmetx); hMEtMeanVtx_Txy_y->Fill(jbin,meanmety); } TH2D* hMEtRawMeanVtx_x = new TH2D("hMEtRawMeanVtx_x","MET_{x} v. Number of vertices",NVTXBINS,0,NVTXBINS,100,-25,15); hMEtRawMeanVtx_x->GetXaxis()->SetTitle("Number of vertices"); hMEtRawMeanVtx_x->GetYaxis()->SetTitle("<MET_{x}> [GeV]"); TH2D* hMEtRawMeanVtx_y = new TH2D("hMEtRawMeanVtx_y","MET_{y} v. Number of vertices",NVTXBINS,0,NVTXBINS,100,-25,15); hMEtRawMeanVtx_y->GetXaxis()->SetTitle("Number of vertices"); hMEtRawMeanVtx_y->GetYaxis()->SetTitle("<MET_{y}> [GeV]"); TH2D* hMEtRawMeanVtx_Txy_x = new TH2D("hMEtRawMeanVtx_Txy_x","MET_{x} v. Number of vertices",NVTXBINS,0,NVTXBINS,100,-25,15); hMEtRawMeanVtx_Txy_x->GetXaxis()->SetTitle("Number of vertices"); hMEtRawMeanVtx_Txy_x->GetYaxis()->SetTitle("<MET_{x}> [GeV]"); TH2D* hMEtRawMeanVtx_Txy_y = new TH2D("hMEtRawMeanVtx_Txy_y","MET_{y} v. Number of vertices",NVTXBINS,0,NVTXBINS,100,-25,15); hMEtRawMeanVtx_Txy_y->GetXaxis()->SetTitle("Number of vertices"); hMEtRawMeanVtx_Txy_y->GetYaxis()->SetTitle("<MET_{y}> [GeV]"); for(int jbin=1;jbin<hMEtRawMeanVtx_x->GetNbinsX()+1;jbin++) { hmetx_proj = hMETRawNvtx_x->ProjectionY("metx_proj",jbin,jbin+1,""); hmety_proj = hMETRawNvtx_y->ProjectionY("mety_proj",jbin,jbin+1,""); meanmetx = hmetx_proj->GetMean(); meanmety = hmety_proj->GetMean(); hMEtRawMeanVtx_x->Fill(jbin,meanmetx); hMEtRawMeanVtx_y->Fill(jbin,meanmety); hmetx_proj = hMETRawNvtx_Txy_x->ProjectionY("metx_proj",jbin,jbin+1,""); hmety_proj = hMETRawNvtx_Txy_y->ProjectionY("mety_proj",jbin,jbin+1,""); meanmetx = hmetx_proj->GetMean(); meanmety = hmety_proj->GetMean(); hMEtRawMeanVtx_Txy_x->Fill(jbin,meanmetx); hMEtRawMeanVtx_Txy_y->Fill(jbin,meanmety); } // // Save plots // TLegend *leg_Vtx_x = new TLegend(0.15,0.15,0.4,0.3,NULL,"brNDC"); leg_Vtx_x->SetTextFont(62); leg_Vtx_x->SetTextSize(0.03330866); leg_Vtx_x->SetLineColor(1); leg_Vtx_x->SetLineStyle(1); leg_Vtx_x->SetLineWidth(1); leg_Vtx_x->SetFillColor(0); leg_Vtx_x->SetFillStyle(1001); leg_Vtx_x->SetBorderSize(0); leg_Vtx_x->AddEntry(hMEtMeanVtx_x,"Type1PfMet","p"); leg_Vtx_x->AddEntry(hMEtMeanVtx_Txy_x,"Type1PfMet + Txy","p"); TLine *metZeroLine=new TLine(0,0,NVTXBINS,0); metZeroLine->SetLineColor(kRed); metZeroLine->SetLineStyle(2); metZeroLine->SetLineWidth(2); TCanvas* tc_metVtx_x = new TCanvas(); tc_metVtx_x->cd(); hMEtMeanVtx_x->SetMarkerStyle(24); hMEtMeanVtx_x->SetMarkerSize(1); hMEtMeanVtx_x->SetMarkerColor(kRed); hMEtMeanVtx_x->Draw("p0"); //hSlimMet->Draw("p9"); hMEtMeanVtx_Txy_x->SetMarkerStyle(26); hMEtMeanVtx_Txy_x->SetMarkerSize(1); hMEtMeanVtx_Txy_x->SetMarkerColor(kBlue); hMEtMeanVtx_Txy_x->Draw("samep0"); metZeroLine->Draw("same"); leg_Vtx_x->Draw("same"); tc_metVtx_x->Print(path+"/MetvsVtx_x.png"); tc_metVtx_x->Print(path+"/MetvsVtx_x.pdf"); TLegend *lRa_Vtx_x = new TLegend(0.15,0.15,0.4,0.3,NULL,"brNDC"); lRa_Vtx_x->SetTextFont(62); lRa_Vtx_x->SetTextSize(0.03330866); lRa_Vtx_x->SetLineColor(1); lRa_Vtx_x->SetLineStyle(1); lRa_Vtx_x->SetLineWidth(1); lRa_Vtx_x->SetFillColor(0); lRa_Vtx_x->SetFillStyle(1001); lRa_Vtx_x->SetBorderSize(0); lRa_Vtx_x->AddEntry(hMEtRawMeanVtx_x,"MetPfRaw","p"); lRa_Vtx_x->AddEntry(hMEtRawMeanVtx_Txy_x,"MetPfRaw + Txy","p"); TCanvas* tc_metRawVtx_x = new TCanvas(); tc_metRawVtx_x->cd(); hMEtRawMeanVtx_x->SetMarkerStyle(24); hMEtRawMeanVtx_x->SetMarkerSize(1); hMEtRawMeanVtx_x->SetMarkerColor(kRed); hMEtRawMeanVtx_x->Draw("p0"); //hSlimMet->Draw("p9"); hMEtRawMeanVtx_Txy_x->SetMarkerStyle(26); hMEtRawMeanVtx_Txy_x->SetMarkerSize(1); hMEtRawMeanVtx_Txy_x->SetMarkerColor(kBlue); hMEtRawMeanVtx_Txy_x->Draw("samep0"); metZeroLine->Draw("same"); lRa_Vtx_x->Draw("same"); tc_metRawVtx_x->Print(path+"/MetRawvsVtx_x.png"); tc_metRawVtx_x->Print(path+"/MetRawvsVtx_x.pdf"); //------------------- // Met vs Vtx y-axis //------------------- TLegend *leg_Vtx_y = new TLegend(0.15,0.15,0.4,0.3,NULL,"brNDC"); leg_Vtx_y->SetTextFont(62); leg_Vtx_y->SetTextSize(0.03330866); leg_Vtx_y->SetLineColor(1); leg_Vtx_y->SetLineStyle(1); leg_Vtx_y->SetLineWidth(1); leg_Vtx_y->SetFillColor(0); leg_Vtx_y->SetFillStyle(1001); leg_Vtx_y->SetBorderSize(0); leg_Vtx_y->AddEntry(hMEtMeanVtx_y,"Type1PfMet","p"); leg_Vtx_y->AddEntry(hMEtMeanVtx_Txy_y,"Type1PfMet + Txy","p"); TCanvas* tc_metVtx_y = new TCanvas(); tc_metVtx_y->cd(); hMEtMeanVtx_y->SetMarkerStyle(24); hMEtMeanVtx_y->SetMarkerSize(1); hMEtMeanVtx_y->SetMarkerColor(kRed); hMEtMeanVtx_y->Draw("p0"); //hSlimMet->Draw("p9"); hMEtMeanVtx_Txy_y->SetMarkerStyle(26); hMEtMeanVtx_Txy_y->SetMarkerSize(1); hMEtMeanVtx_Txy_y->SetMarkerColor(kBlue); hMEtMeanVtx_Txy_y->Draw("same"); metZeroLine->Draw("same"); leg_Vtx_y->Draw("same"); tc_metVtx_y->Print(path+"/MetvsVtx_y.png"); tc_metVtx_y->Print(path+"/MetvsVtx_y.pdf"); TLegend *lRa_Vtx_y = new TLegend(0.15,0.15,0.4,0.3,NULL,"brNDC"); lRa_Vtx_y->SetTextFont(62); lRa_Vtx_y->SetTextSize(0.03330866); lRa_Vtx_y->SetLineColor(1); lRa_Vtx_y->SetLineStyle(1); lRa_Vtx_y->SetLineWidth(1); lRa_Vtx_y->SetFillColor(0); lRa_Vtx_y->SetFillStyle(1001); lRa_Vtx_y->SetBorderSize(0); lRa_Vtx_y->AddEntry(hMEtRawMeanVtx_y,"MetPfRaw","p"); lRa_Vtx_y->AddEntry(hMEtRawMeanVtx_Txy_y,"MetPfRaw + Txy","p"); TCanvas* tc_metRawVtx_y = new TCanvas(); tc_metRawVtx_y->cd(); hMEtRawMeanVtx_y->SetMarkerStyle(24); hMEtRawMeanVtx_y->SetMarkerSize(1); hMEtRawMeanVtx_y->SetMarkerColor(kRed); hMEtRawMeanVtx_y->Draw("p0"); //hSlimMet->Draw("p9"); hMEtRawMeanVtx_Txy_y->SetMarkerStyle(26); hMEtRawMeanVtx_Txy_y->SetMarkerSize(1); hMEtRawMeanVtx_Txy_y->SetMarkerColor(kBlue); hMEtRawMeanVtx_Txy_y->Draw("same"); metZeroLine->Draw("same"); lRa_Vtx_y->Draw("same"); tc_metRawVtx_y->Print(path+"/MetRawvsVtx_y.png"); tc_metRawVtx_y->Print(path+"/MetRawvsVtx_y.pdf"); //--------------------- // phi distribution //--------------------- TCanvas* tc_phi = new TCanvas(); tc_phi->cd(); hPhi->SetLineColor(kRed); hPhi->SetLineWidth(2); hPhi->Draw(""); hPhiTxy->SetLineColor(kBlue); hPhiTxy->SetLineWidth(2); hPhiTxy->Draw("same"); TLegend *leg_Phi = new TLegend(0.15,0.15,0.4,0.3,NULL,"brNDC"); leg_Phi->SetTextFont(62); leg_Phi->SetTextSize(0.03330866); leg_Phi->SetLineColor(1); leg_Phi->SetLineStyle(1); leg_Phi->SetLineWidth(1); leg_Phi->SetFillColor(0); leg_Phi->SetFillStyle(1001); leg_Phi->SetBorderSize(0); leg_Phi->AddEntry(hPhi,"Type1PfMet Phi","l"); leg_Phi->AddEntry(hPhiTxy,"corrected Phi","l"); leg_Phi->Draw("same"); tc_phi->Print(path+"/phi.png"); tc_phi->Print(path+"/phi.pdf"); TCanvas* tc_RawPhi = new TCanvas(); tc_RawPhi->cd(); hRawPhi->SetLineColor(kRed); hRawPhi->SetLineWidth(2); hRawPhi->Draw(""); hRawPhiTxy->SetLineColor(kBlue); hRawPhiTxy->SetLineWidth(2); hRawPhiTxy->Draw("same"); TLegend *lRa_Phi = new TLegend(0.15,0.15,0.4,0.3,NULL,"brNDC"); lRa_Phi->SetTextFont(62); lRa_Phi->SetTextSize(0.03330866); lRa_Phi->SetLineColor(1); lRa_Phi->SetLineStyle(1); lRa_Phi->SetLineWidth(1); lRa_Phi->SetFillColor(0); lRa_Phi->SetFillStyle(1001); lRa_Phi->SetBorderSize(0); lRa_Phi->AddEntry(hRawPhi,"MetPfRaw Phi","l"); lRa_Phi->AddEntry(hRawPhiTxy,"corrected Phi","l"); lRa_Phi->Draw("same"); tc_RawPhi->Print(path+"/RawPhi.png"); tc_RawPhi->Print(path+"/RawPhi.pdf"); TCanvas *c_phi[4]; TLegend *l_Phi[4]; for(int i=0;i<4;i++){ //TString Cname = Form("C_Phi_VtxRange_%d", i); c_phi[i] = new TCanvas(); c_phi[i]->cd(); hPhi_VtxRange[i]->SetLineColor(kRed); hPhi_VtxRange[i]->SetLineWidth(2); hPhi_VtxRange[i]->Draw(""); hPhiTxy_VtxRange[i]->SetLineColor(kBlue); hPhiTxy_VtxRange[i]->SetLineWidth(2); hPhiTxy_VtxRange[i]->Draw("same"); l_Phi[i] = new TLegend(0.15,0.15,0.4,0.3,NULL,"brNDC"); l_Phi[i]->SetTextFont(62); l_Phi[i]->SetTextSize(0.03330866); l_Phi[i]->SetLineColor(1); l_Phi[i]->SetLineStyle(1); l_Phi[i]->SetLineWidth(1); l_Phi[i]->SetFillColor(0); l_Phi[i]->SetFillStyle(1001); l_Phi[i]->SetBorderSize(0); l_Phi[i]->AddEntry(hPhi_VtxRange[i],"Type1PfMet Phi","l"); l_Phi[i]->AddEntry(hPhiTxy_VtxRange[i],"corrected Phi","l"); l_Phi[i]->Draw("same"); TString Oname = Form("Phi_VtxRange_%d", i); c_phi[i]->Print(path+"/"+Oname+".png"); c_phi[i]->Print(path+"/"+Oname+".pdf"); } TCanvas* tc_phi_NoCut = new TCanvas(); tc_phi_NoCut->cd(); hPhi_NoCut->SetLineColor(kRed); hPhi_NoCut->SetLineWidth(2); hPhi_NoCut->Draw(""); hPhiTxy_NoCut->SetLineColor(kBlue); hPhiTxy_NoCut->SetLineWidth(2); hPhiTxy_NoCut->Draw("same"); TLegend *leg_Phi_NoCut = new TLegend(0.15,0.15,0.4,0.3,NULL,"brNDC"); leg_Phi_NoCut->SetTextFont(62); leg_Phi_NoCut->SetTextSize(0.03330866); leg_Phi_NoCut->SetLineColor(1); leg_Phi_NoCut->SetLineStyle(1); leg_Phi_NoCut->SetLineWidth(1); leg_Phi_NoCut->SetFillColor(0); leg_Phi_NoCut->SetFillStyle(1001); leg_Phi_NoCut->SetBorderSize(0); leg_Phi_NoCut->AddEntry(hPhi,"Type1PfMet Phi","l"); leg_Phi_NoCut->AddEntry(hPhiTxy,"corrected Phi","l"); leg_Phi_NoCut->Draw("same"); tc_phi_NoCut->Print(path+"/phi_NoCut.png"); tc_phi_NoCut->Print(path+"/phi_NoCut.pdf"); TCanvas* tc_RawPhi_NoCut = new TCanvas(); tc_RawPhi_NoCut->cd(); hRawPhi_NoCut->SetLineColor(kRed); hRawPhi_NoCut->SetLineWidth(2); hRawPhi_NoCut->Draw(""); hRawPhiTxy_NoCut->SetLineColor(kBlue); hRawPhiTxy_NoCut->SetLineWidth(2); hRawPhiTxy_NoCut->Draw("same"); TLegend *lRa_Phi_NoCut = new TLegend(0.15,0.15,0.4,0.3,NULL,"brNDC"); lRa_Phi_NoCut->SetTextFont(62); lRa_Phi_NoCut->SetTextSize(0.03330866); lRa_Phi_NoCut->SetLineColor(1); lRa_Phi_NoCut->SetLineStyle(1); lRa_Phi_NoCut->SetLineWidth(1); lRa_Phi_NoCut->SetFillColor(0); lRa_Phi_NoCut->SetFillStyle(1001); lRa_Phi_NoCut->SetBorderSize(0); lRa_Phi_NoCut->AddEntry(hRawPhi,"MetPfRaw Phi","l"); lRa_Phi_NoCut->AddEntry(hRawPhiTxy,"corrected Phi","l"); lRa_Phi_NoCut->Draw("same"); tc_RawPhi_NoCut->Print(path+"/RawPhi_NoCut.png"); tc_RawPhi_NoCut->Print(path+"/RawPhi_NoCut.pdf"); //--------------------- // corr-org //--------------------- TCanvas* tc_metDiff = new TCanvas(); tc_metDiff->cd(); hMetDiff->SetMarkerStyle(21); hMetDiff->Draw("e"); tc_metDiff->Print(path+"/MetDiff.png"); tc_metDiff->Print(path+"/MetDiff.pdf"); TCanvas* tc_metPull = new TCanvas(); tc_metPull->cd(); hMetPull->SetMarkerStyle(21); hMetPull->Draw("e"); tc_metPull->Print(path+"/MetPull.png"); tc_metPull->Print(path+"/MetPull.pdf"); TCanvas* tc_phiDiff = new TCanvas(); tc_phiDiff->cd(); hPhiDiff->SetMarkerStyle(21); hPhiDiff->Draw("e"); tc_phiDiff->Print(path+"/PhiDiff.png"); tc_phiDiff->Print(path+"/PhiDiff.pdf"); outFile->cd(); outFile->Write("", TObject::kOverwrite); outFile->Close(); }
int main(int argc, char* argv[]) { TApplication theApp(srcName.Data(), &argc, argv); //============================================================================= if (argc<5) return -1; TString sPath = argv[1]; if (sPath.IsNull()) return -1; TString sFile = argv[2]; if (sFile.IsNull()) return -1; TString sJetR = argv[3]; if (sJetR.IsNull()) return -1; TString sSjeR = argv[4]; if (sSjeR.IsNull()) return -1; //============================================================================= sPath.ReplaceAll("#", "/"); //============================================================================= double dJetR = -1.; if (sJetR=="JetR02") dJetR = 0.2; if (sJetR=="JetR03") dJetR = 0.3; if (sJetR=="JetR04") dJetR = 0.4; if (sJetR=="JetR05") dJetR = 0.5; if (dJetR<0.) return -1; cout << "Jet R = " << dJetR << endl; //============================================================================= double dSjeR = -1.; if (sSjeR=="SjeR01") dSjeR = 0.1; if (sSjeR=="SjeR02") dSjeR = 0.2; if (sSjeR=="SjeR03") dSjeR = 0.3; if (sSjeR=="SjeR04") dSjeR = 0.4; if (dSjeR<0.) return -1; cout << "Sub-jet R = " << dSjeR << endl; //============================================================================= const int multiLHC = 3000; const double dJetsPtMin = 0.001; const double dCutEtaMax = 1.6; const double dJetEtaMax = 1.; const double dJetAreaRef = TMath::Pi() * dJetR * dJetR; fastjet::GhostedAreaSpec areaSpc(dCutEtaMax); fastjet::JetDefinition jetsDef(fastjet::antikt_algorithm, dJetR, fastjet::BIpt_scheme, fastjet::Best); //fastjet::AreaDefinition areaDef(fastjet::active_area,areaSpc); fastjet::AreaDefinition areaDef(fastjet::active_area_explicit_ghosts,areaSpc); fastjet::JetDefinition bkgsDef(fastjet::kt_algorithm, 0.2, fastjet::BIpt_scheme, fastjet::Best); fastjet::AreaDefinition aBkgDef(fastjet::active_area_explicit_ghosts, areaSpc); fastjet::Selector selectJet = fastjet::SelectorAbsEtaMax(dJetEtaMax); fastjet::Selector selectRho = fastjet::SelectorAbsEtaMax(dCutEtaMax-0.2); fastjet::Selector selecHard = fastjet::SelectorNHardest(2); fastjet::Selector selectBkg = selectRho * (!(selecHard)); fastjet::JetMedianBackgroundEstimator bkgsEstimator(selectBkg, bkgsDef, aBkgDef); //fastjet::Subtractor bkgSubtractor(&bkgsEstimator); fastjet::JetDefinition subjDef(fastjet::kt_algorithm, dSjeR, fastjet::BIpt_scheme, fastjet::Best); //============================================================================= TRandom3 *r3 = new TRandom3(0); TF1 *fBkg = BackgroundSpec(); //============================================================================= std::vector<fastjet::PseudoJet> fjInputVac; std::vector<fastjet::PseudoJet> fjInputHyd; //============================================================================= TList *list = new TList(); TH1D *hWeightSum = new TH1D("hWeightSum", "", 1, 0., 1.); list->Add(hWeightSum); //============================================================================= HepMC::IO_GenEvent ascii_in(Form("%s/%s.hepmc",sPath.Data(),sFile.Data()), std::ios::in); HepMC::GenEvent *evt = ascii_in.read_next_event(); while (evt) { fjInputVac.resize(0); fjInputHyd.resize(0); double dXsect = evt->cross_section()->cross_section() / 1e9; double dWeight = evt->weights().back(); double dNorm = dWeight * dXsect; hWeightSum->Fill(0.5, dWeight); int iCount = 0; TLorentzVector vPseudo; for (HepMC::GenEvent::particle_const_iterator p=evt->particles_begin(); p!=evt->particles_end(); ++p) if ((*p)->status()==1) { vPseudo.SetPtEtaPhiM((*p)->momentum().perp(), (*p)->momentum().eta(), (*p)->momentum().phi(), 0.); if ((TMath::Abs(vPar.Eta())<dCutEtaMax)) { fjInputVac.push_back(fastjet::PseudoJet(vPseudo.Px(), vPseudo.Py(), vPseudo.Pz(), vPseudo.E())); fjInputVac.back().set_user_info(new UserInfoTrk(false)); fjInputVac.back().set_user_index(iCount); iCount+=1; } } //============================================================================= for (int i=0; i<=multiLHC; i++) { double dPt = fBkg->GetRandom(fgkPtBkgMin, fgkPtBkgMax); if (dPt<0.001) continue; vPseudo.SetPtEtaPhiM(dPt, r3->Uniform(-1.*dCutEtaMax,dCutEtaMax), r3->Uniform(0.,TMath::TwoPi()), 0.); fjInputHyd.push_back(fastjet::PseudoJet(vPseudo.Px(), vPseudo.Py(), vPseudo.Pz(), vPseudo.E())); fjInputHyd.back().set_user_info(new UserInfoTrk(true)); fjInputHyd.back().set_user_index(-10); } fjInputHyd.insert(fjInputHyd.end(), fjInputVac.begin(),fjInputVac.end()); //============================================================================= fastjet::ClusterSequenceArea clustSeq(fjInputVac, jetsDef, areaDef); std::vector<fastjet::PseudoJet> includJetsPy = clustSeq.inclusive_jets(dJetsPtMin); // std::vector<fastjet::PseudoJet> subtedJetsPy = bkgSubtractor(includJetsPy); std::vector<fastjet::PseudoJet> selectJetsPy = selectJet(includJetsPy); // std::vector<fastjet::PseudoJet> sortedJetsPy = fastjet::sorted_by_pt(selectJetsPy); for (int j=0; j<selectJetsPy.size(); j++) { SetJetUserInfo(selectJetsPy[j]); selectJetsPy[j].set_user_index(j); } //============================================================================= bkgsEstimator.set_particles(fjInputHyd); double dBkgRhoHd = bkgsEstimator.rho(); double dBkgRmsHd = bkgsEstimator.sigma(); fastjet::ClusterSequenceArea clustSeqHd(fjInputHyd, jetsDef, areaDef); std::vector<fastjet::PseudoJet> includJetsHd = clustSeqHd.inclusive_jets(dJetsPtMin); std::vector<fastjet::PseudoJet> selectJetsHd = selectJet(includJetsHd); for (int j=0; j<selectJetsHd.size(); j++) { SetJetUserInfo(selectJetsHd[j]); selectJetsHd[j].set_user_index(j); if (selectJetsHd[j].user_info<UserInfoJet>().IsBkg()) continue; for (int i=0; i<selectJetsPy.size(); i++) { if (CalcDeltaR(selectJetsHd[j],selectJetsPy[i])>0.8) continue; DoTrkMatch(selectJetsHd[j], selectJetsPy[i]); } } //============================================================================= for (int j=0; j<sortedJets.size(); j++) { double dJet = sortedJets[j].pt(); hJet->Fill(dJet, dNorm); //============================================================================= fastjet::Filter trimmer(subjDef, fastjet::SelectorPtFractionMin(0.)); fastjet::PseudoJet trimmdJet = trimmer(sortedJets[j]); std::vector<fastjet::PseudoJet> trimmdSj = trimmdJet.pieces(); double nIsj = 0.; double d1sj = -1.; int k1sj = -1; double d2sj = -1.; int k2sj = -1; for (int i=0; i<trimmdSj.size(); i++) { double dIsj = trimmdSj[i].pt(); if (dIsj<0.001) continue; hJetIsj->Fill(dJet, dIsj, dNorm); hJetIsz->Fill(dJet, dIsj/dJet, dNorm); if (dIsj>d1sj) { d2sj = d1sj; k2sj = k1sj; d1sj = dIsj; k1sj = i; } else if (dIsj>d2sj) { d2sj = dIsj; k2sj = i; } nIsj += 1.; } hJetNsj->Fill(dJet, nIsj, dNorm); if (d1sj>0.) { hJet1sj->Fill(dJet, d1sj, dNorm); hJet1sz->Fill(dJet, d1sj/dJet, dNorm); } if (d2sj>0.) { hJet2sj->Fill(dJet, d2sj, dNorm); hJet2sz->Fill(dJet, d2sj/dJet, dNorm); } if ((d1sj>0.) && (d2sj>0.)) { TVector3 v1sj; v1sj.SetPtEtaPhi(d1sj, trimmdSj[k1sj].eta(), trimmdSj[k1sj].phi()); TVector3 v2sj; v2sj.SetPtEtaPhi(d2sj, trimmdSj[k2sj].eta(), trimmdSj[k2sj].phi()); double dsj = d1sj - d2sj; double dsz = dsj / dJet; double dsr = v1sj.DeltaR(v2sj) / 2. / dJetR; hJetDsj->Fill(dJet, dsj, dNorm); hJetDsz->Fill(dJet, dsz, dNorm); hJetDsr->Fill(dJet, dsz, dsr, dNorm); } } //============================================================================= delete evt; ascii_in >> evt; } //============================================================================= TFile *file = TFile::Open(Form("%s.root",sFile.Data()), "NEW"); list->Write(); file->Close(); //============================================================================= cout << "DONE" << endl; return 0; }
void ntupleViewer_Chain_MC(){ const double beamspot=-0.005; // gROOT->Reset(); gStyle->SetOptStat(1111); gStyle->SetCanvasBorderMode(0); gStyle->SetPadBorderMode(0); gStyle->SetCanvasColor(10); gStyle->SetPadColor(10); gStyle->SetFillColor(10); gStyle->SetStatColor(10); gStyle->SetTitleFillColor(10); std::string addMe = "MC_"; TH1D* eta_All =new TH1D( (addMe + std::string("eta_All")).c_str() , (addMe + std::string("eta_All")).c_str(),25,-3,3); TH1D* eta_withVertex =new TH1D( (addMe + std::string("eta_withVertex")).c_str() , (addMe + std::string("eta_withVertex")).c_str(),25,-3,3); TH1D* eta_AssVertex =new TH1D( (addMe + std::string("eta_AssVertex")).c_str() , (addMe + std::string("eta_AssVertex")).c_str(),25,-3,3); TH1D* phi_All =new TH1D( (addMe + std::string("phi_All")).c_str() , (addMe + std::string("phi_All")).c_str(),25,-3.1415,3.1415); TH1D* phi_withVertex =new TH1D( (addMe + std::string("phi_withVertex")).c_str() , (addMe + std::string("phi_withVertex")).c_str(),25,-3.1415,3.1415); TH1D* phi_AssVertex =new TH1D( (addMe + std::string("phi_AssVertex")).c_str() , (addMe + std::string("phi_AssVertex")).c_str(),25,-3.1415,3.1415); TH1D* pt_All =new TH1D( (addMe + std::string("pt_All")).c_str() , (addMe + std::string("pt_All")).c_str(),400,0.,40); TH1D* pt_withVertex =new TH1D( (addMe + std::string("pt_withVertex")).c_str() , (addMe + std::string("pt_withVertex")).c_str(),400,0.,40); TH1D* pt_AssVertex =new TH1D( (addMe + std::string("pt_AssVertex")).c_str() , (addMe + std::string("pt_AssVertex")).c_str(),400,0.,40); TH1D* track_multip_All =new TH1D( (addMe + std::string("track_multip_All")).c_str() , (addMe + std::string("track_multip_All")).c_str(),201,0,200); TH1D* track_multip_withVertex=new TH1D( (addMe + std::string("track_multip_withVertex")).c_str(), (addMe + std::string("track_multip_withVertex")).c_str(),201,0,200); TH1D* track_multip_AssVertex =new TH1D( (addMe + std::string("track_multip_AssVertex")).c_str() , (addMe + std::string("track_multip_AssVertex")).c_str(),201,0,200); TH2D* pt_vs_multip_All =new TH2D( (addMe + std::string("pt_vs_multip_All")).c_str() , (addMe + std::string("pt_vs_multip_All")).c_str(),400,0.,40,201,0,200); TH2D* pt_vs_multip_withVertex =new TH2D( (addMe + std::string("pt_vs_multip_withVertex")).c_str() , (addMe + std::string("pt_vs_multip_withVertex")).c_str(),400,0.,40,201,0,200); TH2D* pt_vs_multip_AssVertex =new TH2D( (addMe + std::string("pt_vs_multip_AssVertex")).c_str() , (addMe + std::string("pt_vs_multip_AssVertex")).c_str(),400,0.,40,201,0,200); TH2D* pt_vs_ndof_All =new TH2D( (addMe + std::string("pt_vs_ndof_All")).c_str() , (addMe + std::string("pt_vs_ndof_All")).c_str(),400,0.,40,61,0,60); TH2D* pt_vs_ndof_withVertex =new TH2D( (addMe + std::string("pt_vs_ndof_withVertex")).c_str() , (addMe + std::string("pt_vs_ndof_withVertex")).c_str(),400,0.,40,61,0,60); TH2D* pt_vs_ndof_AssVertex =new TH2D( (addMe + std::string("pt_vs_ndof_AssVertex")).c_str() , (addMe + std::string("pt_vs_ndof_AssVertex")).c_str(),400,0.,40,61,0,60); TH1D* ndof_All =new TH1D( (addMe + std::string("ndof_All")).c_str() , (addMe + std::string("ndof_All")).c_str(),61,0,60); TH1D* ndof_withVertex =new TH1D( (addMe + std::string("ndof_withVertex")).c_str() , (addMe + std::string("ndof_withVertex")).c_str(),61,0,60); TH1D* ndof_AssVertex =new TH1D( (addMe + std::string("ndof_AssVertex")).c_str() , (addMe + std::string("ndof_AssVertex")).c_str(),61,0,60); TH1D* normChi2_All =new TH1D( (addMe + std::string("normChi2_All")).c_str() , (addMe + std::string("normChi2_All")).c_str(),25,0,20); TH1D* normChi2_withVertex =new TH1D( (addMe + std::string("normChi2_withVertex")).c_str() , (addMe + std::string("normChi2_withVertex")).c_str(),25,0,20); TH1D* normChi2_AssVertex =new TH1D( (addMe + std::string("normChi2_AssVertex")).c_str() , (addMe + std::string("normChi2_AssVertex")).c_str(),25,0,20); TH2D* chi2_vs_pT_All =new TH2D( (addMe + std::string("chi2_vs_pT_All")).c_str() , (addMe + std::string("chi2_vs_pT_All")).c_str(),25,0,20,400,0.,40); TH2D* chi2_vs_pT_withVertex=new TH2D( (addMe + std::string("chi2_vs_pT_withVertex")).c_str(), (addMe + std::string("chi2_vs_pT_withVertex")).c_str(),25,0,20,400,0.,40); TH2D* chi2_vs_pT_AssVertex =new TH2D( (addMe + std::string("chi2_vs_pT_AssVertex")).c_str() , (addMe + std::string("chi2_vs_pT_AssVertex")).c_str(),25,0,20,400,0.,40); TH2D* chi2_vs_pT_lowMultip_All =new TH2D( (addMe + std::string("chi2_vs_pT_lowMultip_All")).c_str() , (addMe + std::string("chi2_vs_pT_lowMultip_All")).c_str(),25,0,20,400,0.,40); TH2D* chi2_vs_pT_lowMultip_withVertex=new TH2D( (addMe + std::string("chi2_vs_pT_lowMultip_withVertex")).c_str(), (addMe + std::string("chi2_vs_pT_lowMultip_withVertex")).c_str(),25,0,20,400,0.,40); TH2D* chi2_vs_pT_lowMultip_AssVertex =new TH2D( (addMe + std::string("chi2_vs_pT_lowMultip_AssVertex")).c_str() , (addMe + std::string("chi2_vs_pT_lowMultip_AssVertex")).c_str(),25,0,20,400,0.,40); TH2D* chi2_vs_pT_highMultip_All =new TH2D( (addMe + std::string("chi2_vs_pT_highMultip_All")).c_str() , (addMe + std::string("chi2_vs_pT_highMultip_All")).c_str(),25,0,20,400,0.,40); TH2D* chi2_vs_pT_highMultip_withVertex=new TH2D( (addMe + std::string("chi2_vs_pT_highMultip_withVertex")).c_str(), (addMe + std::string("chi2_vs_pT_highMultip_withVertex")).c_str(),25,0,20,400,0.,40); TH2D* chi2_vs_pT_highMultip_AssVertex =new TH2D( (addMe + std::string("chi2_vs_pT_highMultip_AssVertex")).c_str() , (addMe + std::string("chi2_vs_pT_highMultip_AssVertex")).c_str(),25,0,20,400,0.,40); TH1D* vertexes =new TH1D( (addMe + std::string("vertexes")).c_str() , (addMe + std::string("vertexes")).c_str(),5,0,5); TH1D* vertexes_z =new TH1D( (addMe + std::string("vertexes_z")).c_str() , (addMe + std::string("vertexes_z")).c_str(),25,-20,20); TH2D* vertexes_xy =new TH2D( (addMe + std::string("vertexes_xy")).c_str() , (addMe + std::string("vertexes_xy")).c_str(),200,-10,10,200,-10,10); TH1D* deltaZ_trackPV =new TH1D( (addMe + std::string("deltaZ_trackPV")).c_str() , (addMe + std::string("deltaZ_trackPV")).c_str(),50,-25,25); TH1D* deltaZ_trackPV_ZOOM =new TH1D( (addMe + std::string("deltaZ_trackPV_ZOOM")).c_str() , (addMe + std::string("deltaZ_trackPV_ZOOM")).c_str(),100,-3,3); TH1D* deltaX_trackPV =new TH1D( (addMe + std::string("deltaX_trackPV")).c_str() , (addMe + std::string("deltaX_trackPV")).c_str(),50,-25,25); TH1D* deltaX_trackPV_ZOOM =new TH1D( (addMe + std::string("deltaX_trackPV_ZOOM")).c_str() , (addMe + std::string("deltaX_trackPV_ZOOM")).c_str(),100,-3,3); TH1D* deltaY_trackPV =new TH1D( (addMe + std::string("deltaY_trackPV")).c_str() , (addMe + std::string("deltaY_trackPV")).c_str(),50,-25,25); TH1D* deltaY_trackPV_ZOOM =new TH1D( (addMe + std::string("deltaY_trackPV_ZOOM")).c_str() , (addMe + std::string("deltaY_trackPV_ZOOM")).c_str(),100,-3,3); TH1D* vertexesNum_NoutTrk =new TH1D( (addMe + std::string("vertexesNum_NoutTrk")).c_str() , (addMe + std::string("vertexesNum_NoutTrk")).c_str(),50,0,50); TH1D* deltaZ_v1v2 =new TH1D( (addMe + std::string("deltaZ_v1v2")).c_str() , (addMe + std::string("deltaZ_v1v2")).c_str(),100,0,50); TH1D* dZ_All =new TH1D( (addMe + std::string("dZ_All")).c_str() , (addMe + std::string("dZ_All")).c_str(),100,-3,3); TH1D* d0_All =new TH1D( (addMe + std::string("d0_All")).c_str() , (addMe + std::string("d0_All")).c_str(),100,-3,3); TH1D* dZPoint_Ass =new TH1D( (addMe + std::string("dZPoint_Ass")).c_str() , (addMe + std::string("dZPoint_Ass")).c_str(),100,-3,3); TH1D* d0Point_Ass =new TH1D( (addMe + std::string("d0Point_Ass")).c_str() , (addMe + std::string("d0Point_Ass")).c_str(),100,-3,3); TH1D* dZ_Ass =new TH1D( (addMe + std::string("dZ_Ass")).c_str() , (addMe + std::string("dZ_Ass")).c_str(),100,-3,3); TH1D* d0_Ass =new TH1D( (addMe + std::string("d0_Ass")).c_str() , (addMe + std::string("d0_Ass")).c_str(),100,-3,3); TH1D* dZPoint_Vtx =new TH1D( (addMe + std::string("dZPoint_Vtx")).c_str() , (addMe + std::string("dZPoint_Vtx")).c_str(),100,-3,3); TH1D* d0Point_Vtx =new TH1D( (addMe + std::string("d0Point_Vtx")).c_str() , (addMe + std::string("d0Point_Vtx")).c_str(),100,-3,3); TH1D* dZ_Vtx =new TH1D( (addMe + std::string("dZ_Vtx")).c_str() , (addMe + std::string("dZ_Vtx")).c_str(),100,-3,3); TH1D* d0_Vtx =new TH1D( (addMe + std::string("d0_Vtx")).c_str() , (addMe + std::string("d0_Vtx")).c_str(),100,-3,3); TH1D* dZ_Vtx_LARGE =new TH1D( (addMe + std::string("dZ_Vtx_LARGE")).c_str() , (addMe + std::string("dZ_Vtx_LARGE")).c_str(),500,-15,15); TH1D* hthrust_z_All =new TH1D( (addMe + std::string("hthrust_z_All")).c_str() , (addMe + std::string("thrust_z_All")).c_str(),50,-1.1,1.1); TH1D* hthrust_z_withVertex =new TH1D( (addMe + std::string("hthrust_z_withVertex")).c_str(), (addMe + std::string("thrust_y_withVertex")).c_str(),50,-1.1,1.1); TH1D* hthrust_z_AssVertex =new TH1D( (addMe + std::string("hthrust_z_AssVertex")).c_str() , (addMe + std::string("thrust_z_AssVertex")).c_str(),50,-1.1,1.1); TH1D* chargeAsymmetry_All = new TH1D( (addMe + std::string("chargeAsymmetry_All")).c_str() , (addMe + std::string("chargeAsymmetry_All")).c_str(),20,-10,10); TH1D* chargeAsymmetry_AssVertex = new TH1D( (addMe + std::string("chargeAsymmetry_AssVertex")).c_str() , (addMe + std::string("chargeAsymmetry_AssVertex")).c_str(),20,-10,10); //******* partonic analysis ******* TH1D* eta_All_HC =new TH1D( (addMe + std::string("eta_All_HC")).c_str() , (addMe + std::string("eta_All_HC")).c_str(),25,-3,3); TH1D* eta_AssVertex_HC =new TH1D( (addMe + std::string("eta_AssVertex_HC")).c_str() , (addMe + std::string("eta_AssVertex_HC")).c_str(),25,-3,3); TH1D* pt_All_HC =new TH1D( (addMe + std::string("pt_All_HC")).c_str() , (addMe + std::string("pt_All_HC")).c_str(),400,0.,40); TH1D* pt_AssVertex_HC =new TH1D( (addMe + std::string("pt_AssVertex_HC")).c_str() , (addMe + std::string("pt_AssVertex_HC")).c_str(),400,0.,40); TH1D* track_multip_All_HC =new TH1D( (addMe + std::string("track_multip_All_HC")).c_str() , (addMe + std::string("track_multip_All_HC")).c_str(),201,0,200); TH1D* track_multip_AssVertex_HC =new TH1D( (addMe + std::string("track_multip_AssVertex_HC")).c_str() , (addMe + std::string("track_multip_AssVertex_HC")).c_str(),201,0,200); TH1D* eta_All_DD =new TH1D( (addMe + std::string("eta_All_DD")).c_str() , (addMe + std::string("eta_All_DD")).c_str(),25,-3,3); TH1D* eta_AssVertex_DD =new TH1D( (addMe + std::string("eta_AssVertex_DD")).c_str() , (addMe + std::string("eta_AssVertex_DD")).c_str(),25,-3,3); TH1D* pt_All_DD =new TH1D( (addMe + std::string("pt_All_DD")).c_str() , (addMe + std::string("pt_All_DD")).c_str(),400,0.,40); TH1D* pt_AssVertex_DD =new TH1D( (addMe + std::string("pt_AssVertex_DD")).c_str() , (addMe + std::string("pt_AssVertex_DD")).c_str(),400,0.,40); TH1D* track_multip_All_DD =new TH1D( (addMe + std::string("track_multip_All_DD")).c_str() , (addMe + std::string("track_multip_All_DD")).c_str(),201,0,200); TH1D* track_multip_AssVertex_DD =new TH1D( (addMe + std::string("track_multip_AssVertex_DD")).c_str() , (addMe + std::string("track_multip_AssVertex_DD")).c_str(),201,0,200); TH1D* eta_All_SD =new TH1D( (addMe + std::string("eta_All_SD")).c_str() , (addMe + std::string("eta_All_SD")).c_str(),25,-3,3); TH1D* eta_AssVertex_SD =new TH1D( (addMe + std::string("eta_AssVertex_SD")).c_str() , (addMe + std::string("eta_AssVertex_SD")).c_str(),25,-3,3); TH1D* pt_All_SD =new TH1D( (addMe + std::string("pt_All_SD")).c_str() , (addMe + std::string("pt_All_SD")).c_str(),400,0.,40); TH1D* pt_AssVertex_SD =new TH1D( (addMe + std::string("pt_AssVertex_SD")).c_str() , (addMe + std::string("pt_AssVertex_SD")).c_str(),400,0.,40); TH1D* track_multip_All_SD =new TH1D( (addMe + std::string("track_multip_All_SD")).c_str() , (addMe + std::string("track_multip_All_SD")).c_str(),201,0,200); TH1D* track_multip_AssVertex_SD =new TH1D( (addMe + std::string("track_multip_AssVertex_SD")).c_str() , (addMe + std::string("track_multip_AssVertex_SD")).c_str(),201,0,200); //********************************* TChain fChain ("MyAnalyzer/EventTree") ; fChain.Add("MCntuple_Summer09-D6T_STARTUP3X_V8I_900GeV-v2/res/*root"); dati Input(&fChain); int entries = fChain.GetEntries(); //******* TRUST_Z histograms ***** //deleted // //******* TRACK parameters ****** cout<<"corro su "<<entries<<" entries"<<endl; for(int eventn=0;eventn<entries;eventn++){ fChain.GetEntry(eventn); //id_process test int unClassified=0; vector<int> unClassifiedId; if ( !(Input.genEventScale==11 || Input.genEventScale==12 || Input.genEventScale==13 || Input.genEventScale==28 || Input.genEventScale==53 || Input.genEventScale==68 || Input.genEventScale==92 ||Input.genEventScale==93 || Input.genEventScale==94 ) ) { unClassified++; bool alreadyFound=false; for( int i=0;i<unClassifiedId.size();i++) if (Input.genEventScale==unClassifiedId[i]) alreadyFound=true; if(!alreadyFound){ unClassifiedId.push_back(runNumber); } } int chargePlusY=0; int chargeMinusY=0; int trackCounter_HC=0; int trackCounter_SD=0; int trackCounter_DD=0; //All track_multip_All->Fill(Input.numTracks); for(Int_t trackn=0;trackn<Input.numTracks;trackn++){ //tutte le tracce dell'evento eta_All->Fill(Input.track_eta[trackn]); phi_All->Fill(Input.track_phi[trackn]); pt_All->Fill(Input.track_pt[trackn]); normChi2_All->Fill(Input.track_normalizedChi2[trackn]); chi2_vs_pT_All->Fill(Input.track_normalizedChi2[trackn],Input.track_pt[trackn]); pt_vs_multip_All->Fill(Input.track_pt[trackn],Input.numTracks); pt_vs_ndof_All->Fill(Input.track_pt[trackn],Input.track_ndof[trackn]); ndof_All->Fill(Input.track_ndof[trackn]); if (Input.numTracks>100) chi2_vs_pT_highMultip_All->Fill(Input.track_normalizedChi2[trackn],Input.track_pt[trackn]); else chi2_vs_pT_lowMultip_All->Fill(Input.track_normalizedChi2[trackn],Input.track_pt[trackn]); dZ_All->Fill( Input.track_dz[trackn] ); d0_All->Fill( Input.track_d0[trackn] ); if ( Input.track_py[trackn]>0. ) chargePlusY+=Input.track_charge[trackn]; else chargeMinusY+=Input.track_charge[trackn]; //partonic analysis if (Input.genEventScale==11 || Input.genEventScale==12 || Input.genEventScale==13 || Input.genEventScale==28 || Input.genEventScale==53 || Input.genEventScale==68) {//HC trackCounter_HC++; eta_All_HC->Fill(Input.track_eta[trackn]); pt_All_HC->Fill(Input.track_pt[trackn]); } else if (Input.genEventScale==92 ||Input.genEventScale==93) {//SD trackCounter_SD++; eta_All_SD->Fill(Input.track_eta[trackn]); pt_All_SD->Fill(Input.track_pt[trackn]); } else if (Input.genEventScale==94 ) {//DD trackCounter_DD++; eta_All_DD->Fill(Input.track_eta[trackn]); pt_All_DD->Fill(Input.track_pt[trackn]); } }//tutte le tracce dell'evento track_multip_All_HC->Fill(trackCounter_HC); track_multip_All_SD->Fill(trackCounter_SD); track_multip_All_DD->Fill(trackCounter_DD); chargeAsymmetry_All->Fill(chargePlusY+chargeMinusY); //vertex presence requirement for(Int_t vertexn=0;vertexn<Input.numVertices;vertexn++) { if(Input.vertex_z[vertexn]!=beamspot){ //vertice non ricostruito valore del beam spot if(fabs(Input.vertex_z[vertexn]-beamspot)<10){ track_multip_withVertex->Fill(Input.numTracks); for(Int_t trackn=0;trackn<Input.numTracks;trackn++){ //if (track_pt[trackn]>8.) continue; eta_withVertex->Fill(Input.track_eta[trackn]); phi_withVertex->Fill(Input.track_phi[trackn]); pt_withVertex->Fill(Input.track_pt[trackn]); normChi2_withVertex->Fill(Input.track_normalizedChi2[trackn]); chi2_vs_pT_withVertex->Fill(Input.track_normalizedChi2[trackn],Input.track_pt[trackn]); pt_vs_multip_withVertex->Fill(Input.track_pt[trackn],Input.numTracks); pt_vs_ndof_withVertex->Fill(Input.track_pt[trackn],Input.track_ndof[trackn]); ndof_withVertex->Fill(Input.track_ndof[trackn]); if (Input.numTracks>100) chi2_vs_pT_highMultip_withVertex->Fill(Input.track_normalizedChi2[trackn],Input.track_pt[trackn]); else chi2_vs_pT_lowMultip_withVertex->Fill(Input.track_normalizedChi2[trackn],Input.track_pt[trackn]); dZPoint_Vtx->Fill( (Input.track_vz[trackn]-Input.vertex_z[vertexn])- ( (Input.track_vx[trackn]-Input.vertex_x[vertexn])*Input.track_px[trackn] + (Input.track_vy[trackn]-Input.vertex_y[vertexn])*Input.track_py[trackn])/(Input.track_pt[trackn]) * Input.track_pz[trackn]/Input.track_pt[trackn] ); d0Point_Vtx->Fill( (-(Input.track_vx[trackn]-Input.vertex_x[vertexn])*Input.track_py[trackn]+(Input.track_vy[trackn]-Input.vertex_y[vertexn])*Input.track_px[trackn])/Input.track_pt[trackn] ); dZ_Vtx->Fill( Input.track_dz[trackn] ); dZ_Vtx_LARGE->Fill( Input.track_dz[trackn] ); d0_Vtx->Fill( Input.track_d0[trackn] ); } } break; }//vertice non ricostruito valore del beam spot } //Vertex Association requirement chargePlusY=0; chargeMinusY=0; trackCounter_HC=0; trackCounter_SD=0; trackCounter_DD=0; for(Int_t vertexn=0;vertexn<Input.numVertices;vertexn++) { //std::cout<<"vertices z: "<<Input.vertex_z[vertexn]<<endl; if(Input.vertex_z[vertexn]!=beamspot){ //vertice non ricostruito valore del beam spot if(fabs(Input.vertex_z[vertexn]-beamspot)<10){ int fillCounter=0; for(Int_t trackn=0;trackn<Input.numTracks;trackn++){ double dZ_cut= (Input.track_vz[trackn]-Input.vertex_z[vertexn])- ( (Input.track_vx[trackn]-Input.vertex_x[vertexn])*Input.track_px[trackn] + (Input.track_vy[trackn]-Input.vertex_y[vertexn])*Input.track_py[trackn])/(Input.track_pt[trackn]) * Input.track_pz[trackn]/Input.track_pt[trackn] ; double d0_cut= (-(Input.track_vx[trackn]-Input.vertex_x[vertexn])*Input.track_py[trackn]+(Input.track_vy[trackn]-Input.vertex_y[vertexn])*Input.track_px[trackn])/Input.track_pt[trackn] ; //if ( fabs(track_vz[trackn]-vertex_z[vertexn])<1. ) //old cut in acceptance if ( fabs(dZ_cut)<0.36 && fabs(d0_cut)<0.18 && Input.track_highPurity[trackn]==1 && Input.track_pt[trackn]>0.29) { fillCounter++; eta_AssVertex->Fill(Input.track_eta[trackn]); phi_AssVertex->Fill(Input.track_phi[trackn]); pt_AssVertex->Fill(Input.track_pt[trackn]); normChi2_AssVertex->Fill(Input.track_normalizedChi2[trackn]); chi2_vs_pT_AssVertex->Fill(Input.track_normalizedChi2[trackn],Input.track_pt[trackn]); pt_vs_multip_AssVertex->Fill(Input.track_pt[trackn],Input.numTracks); pt_vs_ndof_AssVertex->Fill(Input.track_pt[trackn],Input.track_ndof[trackn]); ndof_AssVertex->Fill(Input.track_ndof[trackn]); if (Input.numTracks>100) chi2_vs_pT_highMultip_AssVertex->Fill(Input.track_normalizedChi2[trackn],Input.track_pt[trackn]); else chi2_vs_pT_lowMultip_AssVertex->Fill(Input.track_normalizedChi2[trackn],Input.track_pt[trackn]); dZPoint_Ass->Fill( (Input.track_vz[trackn]-Input.vertex_z[vertexn])- ( (Input.track_vx[trackn]-Input.vertex_x[vertexn])*Input.track_px[trackn] + (Input.track_vy[trackn]-Input.vertex_y[vertexn])*Input.track_py[trackn])/(Input.track_pt[trackn]) * Input.track_pz[trackn]/Input.track_pt[trackn] ); d0Point_Ass->Fill( (-(Input.track_vx[trackn]-Input.vertex_x[vertexn])*Input.track_py[trackn]+(Input.track_vy[trackn]-Input.vertex_y[vertexn])*Input.track_px[trackn])/Input.track_pt[trackn] ); dZ_Ass->Fill( Input.track_dz[trackn] ); d0_Ass->Fill( Input.track_d0[trackn] ); if ( Input.track_py[trackn]>0. ) chargePlusY+=Input.track_charge[trackn]; else chargeMinusY+=Input.track_charge[trackn]; //partonic analysis if (Input.genEventScale==11 || Input.genEventScale==12 || Input.genEventScale==13 || Input.genEventScale==28 || Input.genEventScale==53 || Input.genEventScale==68) {//HC trackCounter_HC++; eta_AssVertex_HC->Fill(Input.track_eta[trackn]); pt_AssVertex_HC->Fill(Input.track_pt[trackn]); } else if (Input.genEventScale==92 ||Input.genEventScale==93) {//SD trackCounter_SD++; eta_AssVertex_SD->Fill(Input.track_eta[trackn]); pt_AssVertex_SD->Fill(Input.track_pt[trackn]); } else if (Input.genEventScale==94 ) {//DD trackCounter_DD++; eta_AssVertex_DD->Fill(Input.track_eta[trackn]); pt_AssVertex_DD->Fill(Input.track_pt[trackn]); } } } track_multip_AssVertex->Fill(fillCounter); track_multip_AssVertex_HC->Fill(trackCounter_HC); track_multip_AssVertex_SD->Fill(trackCounter_SD); track_multip_AssVertex_DD->Fill(trackCounter_DD); chargeAsymmetry_AssVertex->Fill(chargePlusY+chargeMinusY); } break; }//vertice non ricostruito valore del beam spot } } if (unClassifiedId.size()!=0){ cout<<"cio' dei, e sti muli do che te li meti, ah?!"<<endl; for (int id=0;id<unClassifiedId.size();id++) cout<<unClassifiedId[id]<<" "; cout<<endl; } //***** VERTEX properties ***** int contime=0; int eventsWithRealVertex=0; int eventsWithRealGoodVertex0; cout<<"corro su "<<entries<<" entries"<<endl; for(int eventn=0;eventn<entries;eventn++){ fChain.GetEntry(eventn); int fill; if (Input.numVertices==1){ if (Input.vertex_z[0]==beamspot) fill = 0; else fill = 1; } else fill = Input.numVertices; vertexes->Fill(fill); if (Input.numVertices>1) deltaZ_v1v2->Fill( fabs(Input.vertex_z[0]-Input.vertex_z[1]) ); for(Int_t vertexn=0;vertexn<Input.numVertices;vertexn++){ if(Input.vertex_z[vertexn]!=beamspot){ //vertice non ricostruito valore del beam spot vertexesNum_NoutTrk->Fill(Input.vertex_nOutgoingTracks[vertexn]); vertexes_z->Fill(Input.vertex_z[vertexn]); vertexes_xy->Fill(Input.vertex_x[vertexn],Input.vertex_y[vertexn]); }//vertice non ricostruito valore del beam spot } for(Int_t vertexn=0;vertexn<Input.numVertices;vertexn++) { if(Input.vertex_z[0]!=beamspot){ //vertice non ricostruito valore del beam spot if(fabs(Input.vertex_z[vertexn]-beamspot)<10){ contime++; for(Int_t trackn=0;trackn<Input.numTracks;trackn++){ deltaZ_trackPV->Fill(Input.track_vz[trackn]-Input.vertex_z[vertexn]); deltaZ_trackPV_ZOOM->Fill(Input.track_vz[trackn]-Input.vertex_z[vertexn]); deltaX_trackPV->Fill(Input.track_vx[trackn]-Input.vertex_x[vertexn]); deltaX_trackPV_ZOOM->Fill(Input.track_vx[trackn]-Input.vertex_x[vertexn]); deltaY_trackPV->Fill(Input.track_vy[trackn]-Input.vertex_y[vertexn]); deltaY_trackPV_ZOOM->Fill(Input.track_vy[trackn]-Input.vertex_y[vertexn]); } break; } }//vertice non ricostruito valore del beam spot } } cout<<"eventi con vertice reale e buono, li gavemo contai: "<<contime<<endl; double averageMultip = track_multip_AssVertex->GetMean(); TH1D* KNO_scaling = new TH1D("KNO_scaling","KNO_scaling",track_multip_AssVertex->GetNbinsX(),0.,double(track_multip_AssVertex->GetNbinsX())/averageMultip); KNO_scaling->GetXaxis()->SetTitle("n / < n >"); KNO_scaling->GetYaxis()->SetTitle("< n > P_{n}"); for (int k=1; k<=KNO_scaling->GetNbinsX(); k++) KNO_scaling->SetBinContent(k,averageMultip*track_multip_AssVertex->GetBinContent(k)); if (realdata){ //********* SetStatisticalError Real Data ********* setStatError(eta_withVertex); setStatError(eta_All); setStatError(eta_AssVertex); setStatError(phi_withVertex); setStatError(phi_All); setStatError(phi_AssVertex); setStatError(pt_withVertex); setStatError(pt_All); setStatError(pt_AssVertex); setStatError(normChi2_withVertex); setStatError(normChi2_All); setStatError(normChi2_AssVertex); setStatError(vertexes); setStatError(vertexes_z); setStatError(deltaZ_trackPV); setStatError(vertexesNum_NoutTrk); //**** marker styles ***** eta_withVertex->SetMarkerStyle(22); eta_AssVertex->SetMarkerStyle(22); eta_All->SetMarkerStyle(22); phi_withVertex->SetMarkerStyle(22); phi_AssVertex->SetMarkerStyle(22); phi_All->SetMarkerStyle(22); pt_withVertex->SetMarkerStyle(22); pt_AssVertex->SetMarkerStyle(22); pt_All->SetMarkerStyle(22); normChi2_withVertex->SetMarkerStyle(22); normChi2_AssVertex->SetMarkerStyle(22); normChi2_All->SetMarkerStyle(22); vertexes_z->SetMarkerStyle(22); deltaZ_trackPV->SetMarkerStyle(22); vertexesNum_NoutTrk->SetMarkerStyle(22); vertexes->SetMarkerStyle(22); } vertexes->GetXaxis()->SetBinLabel(1,"BeamSpot"); vertexes->GetXaxis()->SetBinLabel(2,"1 Vertex"); vertexes->GetXaxis()->SetBinLabel(3,"2 Vertices"); vertexes->GetXaxis()->SetBinLabel(4,"3 Vertices"); vertexes->GetXaxis()->SetBinLabel(5,"4 Vertices"); vertexes->GetXaxis()->SetTitle("N^{vtx}/evt"); deltaZ_v1v2->GetXaxis()->SetTitle("|v^{1}_{z}-v^{1}_{z}|"); //***** saving histos ***** std::string fileToOpen="histoMC_fromChain_addpTcutAndGenLevelObservations.root"; TFile outFile((fileToOpen).c_str(),"RECREATE"); eta_withVertex->Write(); eta_All->Write(); phi_withVertex->Write(); phi_All->Write(); pt_withVertex ->Write(); pt_All->Write(); normChi2_withVertex->Write(); normChi2_All->Write(); vertexes->Write(); vertexes_z->Write(); vertexes_xy->Write(); deltaZ_trackPV->Write(); vertexesNum_NoutTrk->Write(); deltaZ_v1v2->Write(); eta_AssVertex->Write(); phi_AssVertex->Write(); pt_AssVertex ->Write(); normChi2_AssVertex->Write(); hthrust_z_All->Write(); hthrust_z_withVertex->Write(); hthrust_z_AssVertex->Write(); track_multip_All->Write(); track_multip_withVertex->Write(); track_multip_AssVertex->Write(); chi2_vs_pT_All->Write(); chi2_vs_pT_withVertex->Write(); chi2_vs_pT_AssVertex->Write(); chi2_vs_pT_lowMultip_All->Write(); chi2_vs_pT_lowMultip_withVertex->Write(); chi2_vs_pT_lowMultip_AssVertex->Write(); chi2_vs_pT_highMultip_All->Write(); chi2_vs_pT_highMultip_withVertex->Write(); chi2_vs_pT_highMultip_AssVertex->Write(); pt_vs_multip_All->Write(); pt_vs_multip_withVertex->Write(); pt_vs_multip_AssVertex->Write(); pt_vs_ndof_All->Write(); pt_vs_ndof_withVertex->Write(); pt_vs_ndof_AssVertex->Write(); deltaX_trackPV->Write(); deltaX_trackPV_ZOOM->Write(); deltaY_trackPV->Write(); deltaY_trackPV_ZOOM->Write(); dZ_All->Write(); d0_All->Write(); dZPoint_Ass->Write(); d0Point_Ass->Write(); dZ_Ass->Write(); d0_Ass->Write(); dZPoint_Vtx->Write(); d0Point_Vtx->Write(); dZ_Vtx->Write(); dZ_Vtx_LARGE->Write(); d0_Vtx->Write(); // KNO_scaling->Write(); ndof_All->Write(); ndof_withVertex->Write(); ndof_AssVertex->Write(); chargeAsymmetry_All->Write(); chargeAsymmetry_AssVertex->Write(); eta_All_HC->Write(); eta_AssVertex_HC->Write(); pt_All_HC->Write(); pt_AssVertex_HC->Write(); track_multip_All_HC->Write(); track_multip_AssVertex_HC->Write(); eta_All_DD->Write(); eta_AssVertex_DD->Write(); pt_All_DD->Write(); pt_AssVertex_DD->Write(); track_multip_All_DD->Write(); track_multip_AssVertex_DD->Write(); eta_All_SD->Write(); eta_AssVertex_SD->Write(); pt_All_SD->Write(); pt_AssVertex_SD->Write(); track_multip_All_SD->Write(); track_multip_AssVertex_SD->Write(); outFile.Close(); }
void test() { style(); setLogBins(nlogfullimassbins,logfullimassmin,logfullimassmax,logfullimassbins); float Mhat; TCanvas* c = new TCanvas("c","c",600,400); c->SetLogx(); c->SetLogy(); c->Draw(); c->cd(); TLegend* leg = new TLegend(0.6627517,0.6846449,0.7919463,0.8261126,NULL,"brNDC"); leg->SetFillStyle(4000); //will be transparent leg->SetFillColor(0); leg->SetTextFont(42); TFile fLoose("/data/hod/2011/NTUPLE/analysisLocalControl_TightLoose.root", "READ"); TTree* tLoose = (TTree*)fLoose.Get("allCuts/allCuts_tree"); tLoose->SetBranchAddress("Mhat", &Mhat); Int_t nLoose = tLoose->GetEntries(); TH1D* hLoose = new TH1D("hLoose","tight-loose vs. tight-tight selection;m_{#mu#mu} TeV;Events",nlogfullimassbins,logfullimassbins); hLoose->SetLineColor(kRed); hLoose->SetMarkerColor(kRed); hLoose->SetMarkerStyle(24); hLoose->SetMarkerSize(0.8); hLoose->SetMinimum(1.e-3); hLoose->SetMaximum(7.e+5); hLoose->GetXaxis()->SetMoreLogLabels(); hLoose->GetXaxis()->SetNoExponent(); leg->AddEntry(hLoose,"tight-loose","lep"); for(Int_t i=0 ; i<nLoose ; i++) { tLoose->GetEntry(i); hLoose->Fill(Mhat*TeV2GeV); } TFile fTight("/data/hod/2011/NTUPLE/analysisLocalControl.root", "READ"); TTree* tTight = (TTree*)fTight.Get("allCuts/allCuts_tree"); tTight->SetBranchAddress("Mhat", &Mhat); Int_t nTight = tTight->GetEntries(); TH1D* hTight = new TH1D("hTight","tight-loose vs. tight-tight selection;m_{#mu#mu} TeV;Events",nlogfullimassbins,logfullimassbins); hTight->SetLineColor(kBlack); hTight->SetMarkerColor(kBlack); hTight->SetMarkerStyle(24); hTight->SetMarkerSize(0.8); hTight->SetMinimum(1.e-3); hTight->SetMaximum(7.e+5); hTight->GetXaxis()->SetMoreLogLabels(); hTight->GetXaxis()->SetNoExponent(); leg->AddEntry(hTight,"tight-tight","lep"); for(Int_t i=0 ; i<nTight ; i++) { tTight->GetEntry(i); hTight->Fill(Mhat*TeV2GeV); } hTight->Draw("e1x1"); hLoose->Draw("e1x1SAMES"); leg->Draw("SAMES"); c->RedrawAxis(); c->SaveAs("plots/Wjets.png"); }
TGraph* GetStat(TString className="CVHMV0M-B-NOPF-CENTNOTRD",Bool_t lumi=1, Bool_t goodOnly=0, TString part="PHYSICS_1"){ Double_t stat[100000]; Double_t time_stamp[100000]; TH1D* hStat = new TH1D("hStat","",1,0,1); TH1D* hTimeStart = new TH1D("hTimeStart","",1,0,1); TH1D* hTimeEnd = new TH1D("hTimeEnd","",1,0,1); TString classNameRun; for (Int_t r=0;r<t->GetEntries();r++){ t->GetEntry(r); if (!partition->String().Contains(part.Data())) continue; if (!lhcState->String().Contains("STABLE")) continue; if (!lhcPeriod->String().Contains("LHC15m")) continue; if (run<225000) continue; hTimeStart->Fill(Form("%i",run),timeStart); hTimeEnd->Fill(Form("%i",run),timeEnd); classNameRun = TString(className); if (className.EqualTo("CEMC7-B-NOPF-CENTNOTRD") && run<=236224) classNameRun="CEMC7-ABCE-NOPF-ALLNOTRD"; if (className.EqualTo("CDMC7-B-NOPF-CENTNOTRD") && run<=236224) classNameRun="CDMC7-ABCE-NOPF-ALLNOTRD"; if (className.EqualTo("CMUL7-B-NOPF-MUFAST") && run<=226606) classNameRun="CMUL7-B-NOPF-ALLNOTRD"; if (className.EqualTo("CVHMV0M-B-NOPF-CENTNOTRD") && run<=236221) classNameRun="CVHMV0M-B-NOPF-CENT"; if (className.EqualTo("CVHMSH2-B-NOPF-CENTNOTRD") && run<=236226) classNameRun="CVHMSH2-B-NOPF-CENT"; if (className.EqualTo("CVHMV0M-B-NOPF-CENTNOTRD") && run>=238432 && run<=239144) classNameRun="CVHMV0M-B-SPD1-CENTNOTRD"; if (className.EqualTo("CVHMSH2-B-NOPF-CENTNOTRD") && run>=238432 ) classNameRun="CVHMSH2-B-SPD1-CENTNOTRD"; if (className.EqualTo("CINT7-B-NOPF-CENT") && run>=225000 && run<=228935) classNameRun="CINT7-B-NOPF-ALLNOTRD"; if (className.EqualTo("CINT7-B-NOPF-CENT") && run>=228936 && run<=229893) classNameRun="CINT7-B-NOPF-CENTNOTRD"; if (className.EqualTo("CINT7-B-NOPF-CENT") && run>=229894 && run<=229899) classNameRun="CINT7-B-NOPF-ALLNOTRD"; if (className.EqualTo("CINT7-B-NOPF-CENT") && run>=229900 && run<=233911) classNameRun="CINT7-B-NOPF-CENT"; if (className.EqualTo("CINT7-B-NOPF-CENT") && run>=233912 && run<=234050) classNameRun="CINT7-B-NOPF-ALLNOTRD"; if (className.EqualTo("CINT7-B-NOPF-CENT") && run>=238890 && run<=239144) classNameRun="CINT7-I-NOPF-CENTNOTRD"; if (className.EqualTo("CEMC7-B-NOPF-CENTNOTRD") && run<=236224) classNameRun="CEMC7-ABCE-NOPF-ALLNOTRD"; if (className.EqualTo("CDMC7-B-NOPF-CENTNOTRD") && run<=236224) classNameRun="CDMC7-ABCE-NOPF-ALLNOTRD"; AliTriggerClass* cl = (AliTriggerClass*) classes->FindObject(classNameRun.Data()); if (!cl) { hStat->Fill(Form("%i",run),0.); continue; } if (goodOnly){ if (classNameRun.Contains("CINT7") || classNameRun.Contains("CVHM")){ Int_t good=0; for (Int_t i=0;i<nGoodRuns;i++) good|= (goodRuns[i]==run); if (!good) { hStat->Fill(Form("%i",run),0.); continue; } } if (className.Contains("MC7")){ if (run<235709 || run==236855 || run==236858 || run==236861 || fill==4440) { hStat->Fill(Form("%i",run),0.); continue; } } if (classNameRun.Contains("CMUL")){ if (!activeDetectors->String().Contains("MUONTRK") || !activeDetectors->String().Contains("MUONTRG") || !activeDetectors->String().Contains("T0") || !activeDetectors->String().Contains("VZERO") || !activeDetectors->String().Contains("ITSSPD") ){ hStat->Fill(Form("%i",run),0.); continue; } } } // printf("%i\n",classes->IndexOf(cl)); Double_t x = lumi ? class_lumi[classes->IndexOf(cl)] : class_l2a[classes->IndexOf(cl)]; hStat->Fill(Form("%i",run),x); } hStat->GetXaxis()->LabelsOption("a"); hTimeEnd->GetXaxis()->LabelsOption("a"); hTimeStart->GetXaxis()->LabelsOption("a"); hStat->LabelsDeflate("x"); hTimeStart->LabelsDeflate("x"); hTimeEnd->LabelsDeflate("x"); Int_t n = 2*hStat->GetNbinsX(); for (Int_t i=0;i<hStat->GetNbinsX();i++){ time_stamp[2*i ] = hTimeStart->GetBinContent(i+1); time_stamp[2*i+1] = hTimeEnd->GetBinContent(i+1); stat[2*i] = i>0?stat[2*i-1]:0; stat[2*i+1] = stat[2*i]+hStat->GetBinContent(i+1)/1000000.; } delete hStat; delete hTimeStart; delete hTimeEnd; TGraph* gStat = new TGraph(n,time_stamp,stat); gStat->SetLineColor(kBlue); gStat->SetLineWidth(2); return gStat; }
void FastME(void){ if(use_proof) TProof::Open(""); ///-------------- Preparing Inputs ----------------------------------------- TString SamplesPath = "VBF_Samples/Matrix/"; TString Out_Name = "TestingTimeBkg"; TString Data_Path = SamplesPath + "VBF_QED4_QCD0_BKG_FastME_1.root"; //TString Data_Path = SamplesPath + "VBF_QED2_QCD2_BKG_FastME_1.root"; ///MCs TString MC_Sig_Path = SamplesPath + "VBF_QED4_QCD0_SIG_FastME_2.root"; TString MC_Bkg_Path = SamplesPath + "VBF_QED4_QCD0_BKG_FastME_2.root"; TString Tree_Name = "VBF"; TString ID_Branch = "ParticleID"; TString Objs_Branch = "RecoParticle"; TString EW_Branch = "EventWeight"; TString Num_Trials = "Ntrials"; ///------------------------------------------------------------------------------------ ///Flag to control what discriminant to save ///(0: based on distance, 1: based on weight, 2: both) int Compute = 0; ///Flag to control the Data-MC comparisons to compute DR ///(0: minimum distance, 1: media of combinations) int DrMethod = 0; ///Opening the input files TFile *fData = TFile::Open(Data_Path); TFile *fMC_Sig = TFile::Open(MC_Sig_Path); TFile *fMC_Bkg = TFile::Open(MC_Bkg_Path); TTree *Data_Tree = (TTree*)fData->Get(Tree_Name); TTree *MC_Sig_Tree = (TTree*)fMC_Sig->Get(Tree_Name); TTree *MC_Bkg_Tree = (TTree*)fMC_Bkg->Get(Tree_Name); ///Creating the Data Tree Int_t DataID[nObjs]; Double_t Data[nObjs][nProp][nVals]; Data_Tree->SetBranchAddress(Objs_Branch,&Data); Data_Tree->SetBranchAddress(ID_Branch,&DataID); int ndata = Data_Tree->GetEntries(); ///Creating the Signal Tree Int_t MC_SIG_ID[nObjs], MC_SIG_NTRIALS; Double_t MC_SIG_WEIGHT, MC_SIG[nObjs][nProp][nVals]; MC_Sig_Tree->SetBranchAddress(Objs_Branch,&MC_SIG); MC_Sig_Tree->SetBranchAddress(ID_Branch,&MC_SIG_ID); if(Compute == 1 || Compute == 2){ MC_Sig_Tree->SetBranchAddress(EW_Branch,&MC_SIG_WEIGHT); MC_Sig_Tree->SetBranchAddress(Num_Trials,&MC_SIG_NTRIALS); } int nsig = MC_Sig_Tree->GetEntries(); ///Creating the Background Tree Int_t MC_BKG_ID[nObjs], MC_BKG_NTRIALS; Double_t MC_BKG_WEIGHT, MC_BKG[nObjs][nProp][nVals]; MC_Bkg_Tree->SetBranchAddress(Objs_Branch,&MC_BKG); MC_Bkg_Tree->SetBranchAddress(ID_Branch,&MC_BKG_ID); if(Compute == 1 || Compute == 2){ MC_Bkg_Tree->SetBranchAddress(EW_Branch,&MC_BKG_WEIGHT); MC_Bkg_Tree->SetBranchAddress(Num_Trials,&MC_BKG_NTRIALS); } int nbkg = MC_Bkg_Tree->GetEntries(); /* cout<<"\n::::::::::::::::::::::::::::::::::::::::"<<endl; cout<<":::::: Starting FastME Processing ::::::"<<endl; cout<<"::::::::::::::::::::::::::::::::::::::::"<<endl; cout<<":: DrComputation Mode: "; if(DrMethod == 0) cout<<"Minimum Distance"<<endl; else if(DrMethod == 1) cout<<"Media"<<endl; if(use_dPhi == false) cout<<":: No Using dPhi!"<<endl; cout<<"::--------------------------------------"<<endl; cout<<":: #Data Events: "<<ndata<<endl; cout<<":: #MC Sig Events: "<<nsig<<endl; cout<<":: #MC BKG Events: "<<nbkg<<endl; cout<<"::--------------------------------------"<<endl; */ ///Creating Tree to store Fast Matrix Element results Int_t FinalState; Double_t dr_test, minDR_toSig, minDR_toBkg, psb_distance; Double_t min_dr_sig, min_dr_bkg; TTree *FME_out = new TTree("FastME_Results","Fast Matrix Element Results"); FME_out->SetDirectory(0); FME_out->Branch("minDR_toSig",&minDR_toSig); FME_out->Branch("minDR_toBkg",&minDR_toBkg); FME_out->Branch("PSB_Distance",&psb_distance); TH1D *h = new TH1D("Distances", "Distances between Data and MC events", 50, 0, 1); ///For timming the process time_t start, stop, delaied; double seconds, elapsed_time; string unity = "s"; time(&start); ///-------------------------- ///Starts the analysis //ndata = 100; for(int i=0; i<ndata; i++){ time(&delaied); if(i % (ndata/10) == 0 && i != 0) cout<<":: Remaining Data: "<<ndata-i<<"\t||Elapsed: "<<difftime(delaied,start)<<"s"<<endl; Data_Tree->GetEntry(i); ///Reseting Variables minDR_toSig = pedestal; minDR_toBkg = pedestal; psb_distance = pedestal; min_dr_sig = 1.E15; min_dr_bkg = 1.E15; ///::::::::::::: Tests MC Signal :::::::::::::::::::::::::::::::::::::::::::::::::: //nsig = 100; for(int s=0; s<nsig; s++){ MC_Sig_Tree->GetEntry(s); dr_test = ComputeDR_MinDist(DataID,Data,MC_SIG_ID,MC_SIG); if(dr_test >= 0 && dr_test < min_dr_sig){ min_dr_sig = dr_test; //sig_event_weight = MC_SIG_WEIGHT; } } ///:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ///:::::::::: Using MC Background ::::::::::::::::::::::::::::::::::::::::::::::::: //nbkg = 100; for(int b=0; b<nbkg; b++){ MC_Bkg_Tree->GetEntry(b); dr_test = ComputeDR_MinDist(DataID,Data,MC_BKG_ID,MC_BKG); if(dr_test >= 0 && dr_test < min_dr_bkg){ min_dr_bkg = dr_test; //bkg_event_weight = MC_BKG_WEIGHT; } } ///:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ///Getting the discriminant value based on event distance if(min_dr_sig == 0 && min_dr_bkg == 0){ min_dr_sig = 1.; min_dr_bkg = 1.; } psb_distance = PsbD(min_dr_sig, min_dr_bkg); if(psb_distance < 0 || psb_distance > 1){ // cout<<"[Warning] PSB_Distance: "<<psb_distance<<" SigD: "<<min_dr_sig<<" BkgD: "<<min_dr_bkg<<endl; } //cout<<"Dt: "<<i<<"\tSigDr: "<<min_dr_sig<<"\tBkgDr: "<<min_dr_bkg<<"\tPsb: "<<psb_distance<<endl; minDR_toSig = min_dr_sig; minDR_toBkg = min_dr_bkg; ///Stores in the Tree the results //FME_out->Fill(); h->Fill(psb_distance); } h->Draw(); //TFile *FME_Results = new TFile(Out_Name+".root","recreate"); //FME_out->Write(); //FME_Results->Close(); /* ///StoPing timming time(&stop); cout<<":::::::::: Process Finished ::::::::::::"<<endl; seconds = difftime(stop,start); if(seconds < 60) elapsed_time = seconds; if(seconds >= 60){ elapsed_time = seconds/60.; unity = "min."; } if(seconds >= 3600){ elapsed_time = seconds/3600.; unity = "h"; } cout<<":: Time Consumed: "<<elapsed_time<<unity<<endl; cout<<"::--------------------------------------\n"<<endl; */ }
void L1PrescalesSimulator::loop(const std::map<unsigned int, float>& bit2prescale_) { Long64_t nevents(-1); //number of events to process if (nevents == -1 || nevents > GetEntries()) nevents = GetEntries(); std::cout << nevents << " to process ..." << std::endl; //loop over the events for (Long64_t i = 0; i < nevents; i++) { //load the i-th event Long64_t ientry = LoadTree(i); if (ientry < 0) break; GetEntry(i); ULong64_t a1 = gt_->tw1.at(2) & bitMaskVec_[0]; ULong64_t a2 = gt_->tw2.at(2) & bitMaskVec_[1]; ULong64_t tt = gt_->tt.at(2) & bitMaskVec_[2]; const int run = event_->run; const int ls = event_->lumi; if (a1 || a2 || tt) { lumiSec2rate_[run][ls]++; for(int ibit=0; ibit<64; ibit++) { if( (a1>>ibit)&1 ) Hbits_->Fill(float(ibit)); if( (a2>>ibit)&1 ) Hbits_->Fill(float(ibit+64)); if( (tt>>ibit)&1 ) Hbits_->Fill(float(ibit+128)); } } //process progress if (i != 0 && (i % 10000) == 0) { std::cout << "- processing event " << i << ", Run: " << run << " ,tw2: " << a2 << " ,LS: " << ls << "\r" << std::flush; } for (std::map<unsigned int, float>::const_iterator it = bit2prescale_.begin(); it != bit2prescale_.end(); it++) { const unsigned int bit = it->first; const float presc = it->second; if (presc != -1.) { if(bit < 64) { prescale(a1, bit, presc); } else if(bit < 128) { prescale(a2, bit-64, presc); } else { prescale(tt, bit-128, presc); } } } if (a1 || a2 || tt) { lumiSec2ratePrescaled_[run][event_->lumi]++; for(int ibit=0; ibit<64; ibit++) { if( (a1>>ibit)&1 ) Hbits2_->Fill(float(ibit)); if( (a2>>ibit)&1 ) Hbits2_->Fill(float(ibit+64)); if( (tt>>ibit)&1 ) Hbits2_->Fill(float(ibit+128)); } }
int MC_Ratio(int leptonId, double* par1, int npar1bins, double* par2, int npar2bins, TString sel_den , TString sel_num, double cut_num , TString par_x , TString par_y , TString option ){ setTDRStyle(); /////////////// //Get the TTree /////////////// //Location of the .root file TString location2 = "/Users/GLP/Desktop/CERN_data/dyjetsnew/postprocessed/"; //Reading the tree // TChain* tree = new TChain("treeProducerSusyMultilepton"); //DY events //tree->Add(location+"DYJetsToLLM50_PU_S14_POSTLS170.root"); tree->Add(location2+"dyjets_good.root"); //Plot the result Long64_t n = tree->GetEntries(); //Path for input and output file. Written in FitDataPath.txt TString _path = "/Users/GLP/Dropbox/Physique/Master_Thesis/plots_root/MC_eff/"; ////////////////////// //Name for the plots// ////////////////////// TString _filetag = ""; TString pname; TString _pname; TString _par; TString _sel_num; TString _sel_den; TString _option; ////Writing string //particle string if(abs(leptonId) == 11){pname = "e"; _pname = "e";} if(abs(leptonId) == 13){pname = " #mu"; _pname = "mu";} //Parameter string if(par_x == "Pt"){_par = "P_{t}";} else if(par_x == "eta"){_par = "#eta";} else if(par_x == "phi"){_par = "#phi";} //sel_den string if((sel_den == "tightmva")&&(leptonId == 13)){cout<<"ERROR: no tightId MVA defined for the muon !"<<endl;return 1;} if(sel_den == "tightcut"){_sel_den = "tightcut";} else if(sel_den == "tightmva"){_sel_den = "tightmva";} else if(sel_den == "loose"){_sel_den = "loose";} else if(sel_den == ""){_sel_den = "";} else{cout<<"ERROR: wrong sel_denion !";return 1;} //sel_num string if((sel_num == "tightmva")&&(leptonId == 13)){cout<<"ERROR: no tightId MVA defined for the muon !"<<endl;return 1;} if(sel_num == "tightcut"){_sel_num = "tightcut";} else if(sel_num == "tightmva"){_sel_num = "tightmva";} else if(sel_num == ""){_sel_num = "";} else if(sel_num == "loose"){_sel_num = "loose";} else if(sel_num == "reliso3"){_sel_num = Form("reliso3_%0.3lf",cut_num);} else if(sel_num == "reliso4"){_sel_num = Form("reliso4_%0.3lf",cut_num);} else if(sel_num == "chiso3"){_sel_num = Form("chiso3_%0.3lf",cut_num);} else if(sel_num == "chiso4"){_sel_num = Form("chiso4_%0.3lf",cut_num);} else if(sel_num == "dxy"){_sel_num = Form("dxy_%0.3lf",cut_num);} else if(sel_num == "dz"){_sel_num = Form("dz_%0.3lf",cut_num);} else{cout<<"ERROR: wrong numerator name !";return 1;} //option string option.Append(" "); option.Prepend(" "); if(option.Contains(" ll ")){_option += "_ll";} if(option.Contains(" unmatched ")){_option += "_unmatched";} if(option.Contains(" alleta ")){_option += "_alleta";} if(option.Contains(" short ")){_option += "_short";} _option += "_"; //parameter range string TString _par1range; _par1range = Form("%0.3f_"+par_x+"%0.3f",par1[0],par1[npar1bins]); TString _par2range; _par2range = Form("%0.3f_"+par_y+"%0.3f",par2[0],par2[npar2bins]); ///////////////////////////////////// //Write the name of the output file// ///////////////////////////////////// TString _fname = "MCeff"+_filetag+_option+_pname+_par1range+"_"+_par2range+"_den_"+_sel_den+"_num_"+_sel_num; //Output file cout<<"going to create the file"<<endl; //Check if the file exists TFile *fcheck = TFile::Open(_path+_fname+".root", "READ"); if (fcheck) { cout << "File "<<_fname<<" exists ! Please change name" << endl; return 1; } TFile* file_out = new TFile(_path+_fname+".root","recreate"); cout<<"done ! "<<endl; //Declaration of histogram TH1D **histo_num = new TH1D*[npar2bins]; TH1D **histo_den = new TH1D*[npar2bins]; TH1D **eff = new TH1D*[npar2bins]; //Par1 distribution histogram TH1D** histo_par1 = new TH1D*[npar2bins]; //Distribution of the cut parameter whose efficiency is studied TH1D *histo_other_sel = new TH1D("histo_other_sel","h",5,0,5); TH1D *histo_good_sel = new TH1D("histo_good_sel","h",5,0,5); //Histo separate in Lep_good Lep_other // TH1D **histo_num_O = new TH1D*[npar2bins]; TH1D **histo_den_O = new TH1D*[npar2bins]; TH1D **eff_O = new TH1D*[npar2bins]; TH1D **histo_num_G = new TH1D*[npar2bins]; TH1D **histo_den_G = new TH1D*[npar2bins]; TH1D **eff_G = new TH1D*[npar2bins]; //Counter LepGood vs LepOther TH1D **histo_counter = new TH1D*[npar2bins]; TH1D **histo_counter_G_par1 = new TH1D*[npar2bins]; TH1D **histo_counter_O_par1 = new TH1D*[npar2bins]; TH1D **histo_counter_par1 = new TH1D*[npar2bins]; for(int _i = 0; _i < npar2bins; ++_i){ histo_num[_i] = new TH1D("histo_num","Pt",npar1bins,par1[0],par1[npar1bins]); histo_den[_i] = new TH1D("histo_den","Pt",npar1bins,par1[0],par1[npar1bins]); eff[_i] = new TH1D("eff","Pt",npar1bins,par1[0],par1[npar1bins]); // histo_par1[_i] = new TH1D("histo_par1","par1",npar1bins*25,par1[0],par1[npar1bins]); // histo_num_O[_i] = new TH1D("histo_num_O","Pt",npar1bins,par1[0],par1[npar1bins]); histo_den_O[_i] = new TH1D("histo_den_O","Pt",npar1bins,par1[0],par1[npar1bins]); eff_O[_i] = new TH1D("eff_O","Pt",npar1bins,par1[0],par1[npar1bins]); histo_num_G[_i] = new TH1D("histo_num_G","Pt",npar1bins,par1[0],par1[npar1bins]); histo_den_G[_i] = new TH1D("histo_den_G","Pt",npar1bins,par1[0],par1[npar1bins]); eff_G[_i] = new TH1D("eff_G","Pt",npar1bins,par1[0],par1[npar1bins]); histo_counter_G_par1[_i] = new TH1D("histo_counter_G_par1","count",npar1bins,par1[0],par1[npar1bins]); histo_counter_O_par1[_i] = new TH1D("histo_counter_O_par1","count",npar1bins,par1[0],par1[npar1bins]); histo_counter_par1[_i] = new TH1D("histo_counter_par1","count",npar1bins,par1[0],par1[npar1bins]); histo_counter[_i] = new TH1D("histo_counter","count",2,0,2); } //Event variables Int_t evt_id; Double_t scale; //Generated Double_t gen_phi[200]; Double_t gen_eta[200]; Double_t Pt[200]; Double_t m[200]; Int_t Id[200]; Int_t Mo[200]; Double_t charge[200]; Int_t status[200]; Int_t GrMa[200]; Int_t ngenPart; Int_t source[200]; Int_t pile_up; //not loose Int_t On; Int_t Oid[200]; Double_t Opt[200]; Double_t Om[200]; Double_t Oeta[200]; Double_t Ophi[200]; Int_t Oq[200]; Int_t Otight[200]; Int_t Otighte[200]; //Double_t Omvaid[200]; Int_t Oloose[200]; Double_t Oiso3[200]; Double_t Oiso4[200]; Double_t Ochiso3[200]; Double_t Ochiso4[200]; Double_t Odxy[200]; Double_t Odz[200]; //loose Int_t Gn; Int_t Gid[200]; Double_t Gpt[200]; Double_t Gm[200]; Double_t Geta[200]; Double_t Gphi[200]; Int_t Gq[200]; Int_t Gtight[200]; Int_t Gtighte[200]; Int_t Gloose[200]; Double_t Giso3[200]; Double_t Giso4[200]; Double_t Gchiso3[200]; Double_t Gchiso4[200]; Double_t Gdxy[200]; Double_t Gdz[200]; //Assigne branches tree->SetBranchAddress("evt_scale1fb", &scale); tree->SetBranchAddress("evt_id", &evt_id); //generated tree->SetBranchAddress("nGenPart", &ngenPart); tree->SetBranchAddress("GenPart_pdgId", &Id); tree->SetBranchAddress("GenPart_sourceId", &source); tree->SetBranchAddress("GenPart_eta", &gen_eta); tree->SetBranchAddress("GenPart_phi", &gen_phi); tree->SetBranchAddress("GenPart_pt", &Pt); tree->SetBranchAddress("GenPart_mass", &m); tree->SetBranchAddress("GenPart_charge", &charge); tree->SetBranchAddress("GenPart_status", &status); //not loose tree->SetBranchAddress("nLepOther",&On); tree->SetBranchAddress("LepOther_pdgId",&Oid); tree->SetBranchAddress("LepOther_pt",&Opt); tree->SetBranchAddress("LepOther_mass",&Om); tree->SetBranchAddress("LepOther_eta",&Oeta); tree->SetBranchAddress("LepOther_phi",&Ophi); tree->SetBranchAddress("LepOther_charge",&Oq); tree->SetBranchAddress("LepOther_tightId",&Otight); tree->SetBranchAddress("LepOther_eleCutIdCSA14_50ns_v1",&Otighte); tree->SetBranchAddress("LepOther_relIso03",&Oiso3); tree->SetBranchAddress("LepOther_relIso04",&Oiso4); tree->SetBranchAddress("LepOther_chargedHadRelIso03",&Ochiso3); tree->SetBranchAddress("LepOther_chargedHadRelIso04",&Ochiso4); tree->SetBranchAddress("LepOther_dxy",&Odxy); tree->SetBranchAddress("LepOther_dz",&Odz); //Loose tree->SetBranchAddress("nLepGood",&Gn); tree->SetBranchAddress("LepGood_pdgId",&Gid); tree->SetBranchAddress("LepGood_pt",&Gpt); tree->SetBranchAddress("LepGood_mass",&Gm); tree->SetBranchAddress("LepGood_eta",&Geta); tree->SetBranchAddress("LepGood_phi",&Gphi); tree->SetBranchAddress("LepGood_charge",&Gq); tree->SetBranchAddress("LepGood_tightId",&Gtight); tree->SetBranchAddress("LepGood_eleCutIdCSA14_50ns_v1",&Gtighte); tree->SetBranchAddress("LepGood_relIso03",&Giso3); tree->SetBranchAddress("LepGood_relIso04",&Giso4); tree->SetBranchAddress("LepGood_chargedHadRelIso03",&Gchiso3); tree->SetBranchAddress("LepGood_chargedHadRelIso04",&Gchiso4); tree->SetBranchAddress("LepGood_dxy",&Gdxy); tree->SetBranchAddress("LepGood_dz",&Gdz); int count = 0; //Count lepgood/other int goodcount = 0; int othercount = 0; if(option.Contains(" short ")){n = 100000;} //Start loop over all events for (int k = 0; k < n; ++k) { //Declaration of event parameters Int_t evtn; Int_t evtloose[200]; Int_t evtid[200]; Double_t evtpt[200]; Double_t evtm[200]; Double_t evteta[200]; Double_t evtphi[200]; Int_t evtq[200]; Int_t evttight[200]; Int_t evttighte[200]; Double_t evtiso3[200]; Double_t evtiso4[200]; Double_t evtchiso3[200]; Double_t evtchiso4[200]; Double_t evtdxy[200]; Double_t evtdz[200]; if( 100*(double)k/n> count){cout<<count<<endl;++count;} tree->GetEntry(k); //Selection on denominator for(int j = 0; j < Gn+On; ++j){ //Separate here other from loose if(j < On){ evtloose[j] = 0; evtid[j] = Oid[j]; evtpt[j] = Opt[j]; evtm[j] = Om[j]; evteta[j] = Oeta[j]; evtphi[j] = Ophi[j]; evtq[j] = Oq[j]; evttight[j] = Otight[j]; evttighte[j] = Otighte[j]; evtiso3[j] = Oiso3[j]; evtiso4[j] = Oiso4[j]; evtchiso3[j] = Ochiso3[j]; evtchiso4[j] = Ochiso4[j]; evtdxy[j] = Odxy[j]; evtdz[j] = Odz[j]; }else if((j >= On)&&(j < Gn+On)){ evtloose[j] = 1; evtid[j] = Gid[j-On]; evtpt[j] = Gpt[j-On]; evtm[j] = Gm[j-On]; evteta[j] = Geta[j-On]; evtphi[j] = Gphi[j-On]; evtq[j] = Gq[j-On]; evttight[j] = Gtight[j-On]; evttighte[j] = Gtighte[j-On]; evtiso3[j] = Giso3[j-On]; evtiso4[j] = Giso4[j-On]; evtchiso3[j] = Gchiso3[j-On]; evtchiso4[j] = Gchiso4[j-On]; evtdxy[j] = Gdxy[j-On]; evtdz[j] = Gdz[j-On]; } if((!option.Contains(" ll "))||((option.Contains(" ll "))&&(Gn+On == 2)&&(evtq[0] == -evtq[1]))){ if(abs(evtid[j]) == leptonId){ //Cut on the denominator //if((sel_den != "loose")||(evtloose[j] == 1)){ //if(evtloose[j] == 1){ if((sel_den != "tightcut")||(((abs(evtid[j]) == 13)&&(sel_den == "tightcut")&&(evttight[j] == 1 ))||((abs(evtid[j]) == 11)&&(sel_den == "tightcut")&&(evttighte[j] >= 3)))){ if((sel_den != "tightmva")||((abs(evtid[j]) == 11)&&(sel_den == "tightmva")&&(evttight[j] == 1))){ //Veto the EE-EB gape //Variable for matching double R = 999; double delta_P = 999; double delta_charge = 999; //Parameter on the xaxis double par; double par_2; //loop over all generated particles to do the matching for (int i = 0; i < ngenPart; ++i) { if((abs(Id[i]) == leptonId)){ //Electrons selection double R2 = DeltaR(gen_eta[i],evteta[j],gen_phi[i],evtphi[j] ); //Minimise DeltaR and Fill the other variables if (R > R2) { R = R2; delta_P = abs(evtpt[j]-Pt[i])/Pt[i]; delta_charge = abs(evtq[j] - charge[i]); } } } //Choose the parameter to be filled for the eff. if(par_x == "Pt"){par = evtpt[j];} else if(par_x == "eta"){par = evteta[j];} else if(par_x == "phi"){par = evtphi[j];} if(par_y == "Pt"){par_2 = evtpt[j];} else if(par_y == "eta"){par_2 = abs(evteta[j]);} else if(par_y == "phi"){par_2 = abs(evtphi[j]);} //Fill Pt only for matched events if(((R<0.1)&&(delta_P < 0.2)&&(delta_charge < 0.5))||option.Contains(" unmatched ")){ for(int ii = 0; ii < npar2bins; ++ii){ if((par_2 > par2[ii])&&(par_2 <= par2[ii+1])){histo_den[ii]->Fill(par);histo_par1[ii]->Fill(par); if(evtloose[j] == 1){histo_good_sel->Fill(evttighte[j]);} else if(evtloose[j] == 0){histo_other_sel->Fill(evttighte[j]);} else{cout<<"Error !"<<endl; return 1;} } } //Additional cut on the numerator int a = 0; if((sel_num == "tightcut")&&(abs(evtid[j]) == 13)&&(evttight[j] == 1)){a = 1;} if((sel_num == "tightcut")&&(abs(evtid[j]) == 11)&&(evttighte[j] >= 3)){a = 1;} if((sel_num == "reliso3")&&(evtiso3[j] <= cut_num)){a = 2;} if((sel_num == "reliso4")&&(evtiso4[j] <= cut_num)){a = 3;} if((sel_num == "chiso3")&&(evtchiso3[j] <= cut_num)){a = 4;} if((sel_num == "chiso4")&&(evtchiso4[j] <= cut_num)){a = 5;} if((sel_num == "dxy")&&(abs(evtdxy[j]) <= cut_num)){a = 6;} if((sel_num == "dz")&&(abs(evtdz[j]) <= cut_num)){a = 7;} if((sel_num == "tightmva")&&(abs(evtid[j]) == 11)&&(evttight[j] == 1)){a = 9;} if((sel_num == "loose")&&(evtloose[j]) == 1){a = 8;} //Find the corresponding histogram for par2 TH1D* hist; TH1D* hist_evt; bool found = false; for(int _i = 0; _i < npar2bins; ++_i){ if((par_2 > par2[_i])&&(par_2 <= par2[_i+1])){hist = histo_num[_i];found = true;} } if(!found){a = 0;} switch(a){ case 0: break; case 1: hist->Fill(par); break; case 2: hist->Fill(par); break; case 3: hist->Fill(par); break; case 4: hist->Fill(par); break; case 5: hist->Fill(par); break; case 6: hist->Fill(par); break; case 7: hist->Fill(par); break; case 8: hist->Fill(par); break; case 9: hist->Fill(par); break; } } } } } //} } } } mkdir(_path+_fname+"_PDF/", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); /////////////////// //Draw histograms// /////////////////// //Canvas declaration for(int i = 0; i < npar2bins; ++i){ //////////////////// //Build histograms// //////////////////// histo_num[i]->Sumw2(); histo_den[i]->Sumw2(); eff[i]->Divide(histo_num[i],histo_den[i],1,1,"B"); //histo_num_O[i]->Sumw2(); //histo_den_O[i]->Sumw2(); //eff_O[i]->Divide(histo_num_O[i],histo_den_O[i],1,1,"B"); //histo_num_G[i]->Sumw2(); //histo_den_G[i]->Sumw2(); //eff_G[i]->Divide(histo_num_G[i],histo_den_G[i],1,1,"B"); //histo_counter_G_par1[i]->Sumw2(); //histo_counter_O_par1[i]->Sumw2(); //histo_counter_par1[i]->Divide(histo_counter_O_par1[i],histo_counter_G_par1[i],1,1,"B"); //histo_counter[i]->Fill(0.5,goodcount); //histo_counter[i]->Fill(1.5,othercount); //String for name of the ouput files and histograms titles // TString _parybin; //Parameter string if(par_y == "Pt"){_parybin = Form("%0.f_Pt%0.f",par2[i],par2[i+1]);} else if(par_y == "eta"){_parybin = Form("%0.3f_eta%0.3f",par2[i],par2[i+1]);cout<<"it works !"<<endl;} else if(par_y == "phi"){_parybin = Form("%0.3f_phi%0.3f",par2[i],par2[i+1]);} TString _parytitle; //Title string if(par_y == "Pt"){_parytitle = Form("%0.f #leq P_{t} #leq %0.f",par2[i],par2[i+1]);} else if(par_y == "eta"){_parytitle = Form("%0.3f #leq #||{#eta} #leq %0.3f",par2[i],par2[i+1]);cout<<"it works !"<<endl;} else if(par_y == "phi"){_parytitle = Form("%0.3f #leq #||{#phi} #leq %0.3f",par2[i],par2[i+1]);} //Draw histograms TCanvas* c1 = new TCanvas("c1","c1"); c1->cd(); eff[i]->Draw(); eff[i]->GetYaxis()->SetTitle("#epsilon"); eff[i]->GetXaxis()->SetTitle(_par); eff[i]->GetYaxis()->SetRangeUser(0,1.1); eff[i]->SetMarkerStyle(20); eff[i]->SetMarkerSize(1); eff[i]->SetMarkerColor(4); eff[i]->SetLineColor(4); eff[i]->SetTitle(_sel_num+" for "+_sel_den+" "+pname+" "+_parytitle); TCanvas* c_par1 = new TCanvas("cpar1","cpar1"); TString _partitle = _par + (TString)" distribution for "+pname+", "+_parytitle+", "+sel_num; c_par1->cd(); histo_par1[i]->Draw(); histo_par1[i]->SetTitle(_partitle); histo_par1[i]->GetXaxis()->SetTitle(_par); histo_par1[i]->SetLineWidth(2); histo_par1[i]->SetLineColor(4); histo_par1[i]->SetMarkerColor(4); histo_good_sel->Add(histo_other_sel); TCanvas* csel = new TCanvas("csel","csel"); csel->cd(); histo_good_sel->Draw(); ///////////////////// //Saving the output// ///////////////////// //Write pdf TString cname = "eff"+_filetag+_option+_pname+_par1range+"_"+_parybin+"_den_"+_sel_den+"_num_"+_sel_num; c1->SaveAs(_path+_fname+"_PDF/"+cname+".pdf"); c_par1->SaveAs(_path+_fname+"_PDF/"+cname+"par_distr.pdf"); csel->SaveAs(_path+_fname+"_PDF/"+cname+"sel.pdf"); //Write in output file file_out->cd(); eff[i]->Write("eff"+_parybin); histo_good_sel->Write("sel"+_parybin); //histo_par1[i]->Write("histo_par1_"+_parybin); } file_out->Close(); return 0; }
void doit(const char *basename, const int nbins, const double lofit, const double hifit) { // --- read in the data and create a vector with all the values // --- note that this code requires an duplicates to have already been cleaned out // --- this is automatically fixed with the new version of the DAQ/stepper code // --- but the user would do well do double check all output files anyway ifstream fin1(Form("TEMP/%s_Unaveraged_VMin1.txt",basename)); double content; vector<double> voltage1; while(fin1>>content) { voltage1.push_back(content); } fin1.close(); cout << voltage1.size() << endl; // --- do the same for SiPM2 ifstream fin2(Form("TEMP/%s_Unaveraged_VMin2.txt",basename)); vector<double> voltage2; while(fin2>>content) { voltage2.push_back(content); } fin2.close(); cout << voltage2.size() << endl; // --- get the number of entries and the min and max int number = voltage1.size(); double max = *max_element(voltage1.begin(),voltage1.end()); double min = *min_element(voltage1.begin(),voltage1.end()); cout << max << endl; cout << min << endl; // --- use the min and max to calculate a range for the histogram double newmax = min*-0.95; double newmin = max*-1.05 - newmax*0.1; // --- create the new histogram TH1D *h1 = new TH1D("h1","",nbins,newmin,newmax); TH1D *h2 = new TH1D("h2","",nbins,newmin,newmax); TH1D *hsum = new TH1D("hsum","",nbins,2*newmin,2*newmax); TH2D *hh1v2 = new TH2D("hh1v2","",nbins*2,newmin,newmax,nbins*2,newmin,newmax); // SiPM1 vs SiPM2 TH2D *hhSvA = new TH2D("hhSvA","",nbins*2,2*newmin,2*newmax,nbins*2,-1,1); // Sum vs Asymmetry TH2D *hh1v2_cut1 = new TH2D("hh1v2_cut1","",nbins*2,newmin,newmax,nbins*2,newmin,newmax); // SiPM1 vs SiPM2 TH2D *hhSvA_cut1 = new TH2D("hhSvA_cut1","",nbins*2,2*newmin,2*newmax,nbins*2,-1,1); // Sum vs Asymmetry TH2D *hh1v2_cut2 = new TH2D("hh1v2_cut2","",nbins*2,newmin,newmax,nbins*2,newmin,newmax); // SiPM1 vs SiPM2 TH2D *hhSvA_cut2 = new TH2D("hhSvA_cut2","",nbins*2,2*newmin,2*newmax,nbins*2,-1,1); // Sum vs Asymmetry vector<double> sum; vector<double> asym; // --- loop over the vector to fill the histogram for(int i=0; i<number; i++) { // --- SiPM1 h1->Fill(-voltage1[i]); // --- SiPM2 h2->Fill(-voltage2[i]); // --- SiPM1 vs SiPM2 hh1v2->Fill(-voltage1[i],-voltage2[i]); // --- sum vs asymmetry double tempsum = -voltage1[i] + -voltage2[i]; double tempasym = (voltage1[i] - voltage2[i]) / (-voltage1[i] + -voltage2[i]); hsum->Fill(tempsum); hhSvA->Fill(tempsum,tempasym); sum.push_back(tempsum); asym.push_back(tempasym); // --- now do some cuts... if(fabs(tempasym)<0.4) { hh1v2_cut1->Fill(-voltage1[i],-voltage2[i]); hhSvA_cut1->Fill(tempsum,tempasym); } if((voltage1[i]<(voltage2[i]+20*peconvert))&&(voltage2[i]<(voltage1[i]+20*peconvert))) { hh1v2_cut2->Fill(-voltage1[i],-voltage2[i]); hhSvA_cut2->Fill(tempsum,tempasym); } } // --- make a canvas and draw the histogram TCanvas *c1 = new TCanvas("c1","",800,800); // --- rescale the histograms from volts to photoelectrons h1->GetXaxis()->SetLimits(newmin/peconvert,newmax/peconvert); h1->GetXaxis()->SetTitle("Number of photoelectrons"); h1->GetYaxis()->SetTitle("Counts"); // --- define Landau function and draw // --- don't fit yet because the data have tons of ugly low voltage1 background double height = 1049; double mu = 23; double sigma = 3; //TF1 *fun = new TF1("fun","[0]*TMath::Landau(x,[1],[2])",newmin/peconvert,newmax/peconvert); TF1 *fun = new TF1("fun","[0]*TMath::Landau(x,[1],[2])",2*newmin/peconvert,2*newmax/peconvert); fun->SetParameter(0,height); fun->SetParameter(1,mu); fun->SetParameter(2,sigma); double bgscale = 650; // guess... c1->SetLogy(0); c1->Clear(); hh1v2->Draw("colz"); hh1v2->GetXaxis()->SetLimits(newmin/peconvert,newmax/peconvert); hh1v2->GetYaxis()->SetLimits(newmin/peconvert,newmax/peconvert); hh1v2->GetXaxis()->SetTitle("#pe SiPM1"); hh1v2->GetYaxis()->SetTitle("#pe SiPM2"); c1->SetLogz(0); c1->Print(Form("Cosmics/%s_cosmics_1v2.png",basename)); c1->Print(Form("Cosmics/%s_cosmics_1v2.pdf",basename)); c1->SetLogz(1); c1->Print(Form("Cosmics/%s_cosmics_1v2_log.png",basename)); c1->Print(Form("Cosmics/%s_cosmics_1v2_log.pdf",basename)); hhSvA->Draw("colz"); hhSvA->GetXaxis()->SetLimits(2*newmin/peconvert,2*newmax/peconvert); hhSvA->GetXaxis()->SetTitle("Sum"); hhSvA->GetYaxis()->SetTitle("Asymmetry"); c1->SetLogz(0); c1->Print(Form("Cosmics/%s_cosmics_SvA.png",basename)); c1->Print(Form("Cosmics/%s_cosmics_SvA.pdf",basename)); c1->SetLogz(1); c1->Print(Form("Cosmics/%s_cosmics_SvA_log.png",basename)); c1->Print(Form("Cosmics/%s_cosmics_SvA_log.pdf",basename)); // --- now for some cuts... c1->SetLogz(0); hh1v2_cut1->Draw("colz"); hh1v2_cut1->GetXaxis()->SetLimits(newmin/peconvert,newmax/peconvert); hh1v2_cut1->GetYaxis()->SetLimits(newmin/peconvert,newmax/peconvert); hh1v2_cut1->GetXaxis()->SetTitle("#pe SiPM1"); hh1v2_cut1->GetYaxis()->SetTitle("#pe SiPM2"); TLatex *tex1 = new TLatex(0.2,0.8,"|Asymmetry|<0.4"); tex1->SetTextSize(0.05); tex1->SetNDC(kTRUE); tex1->Draw(); c1->SetLogz(0); c1->Print(Form("Cosmics/%s_cosmics_1v2_cut1.png",basename)); c1->Print(Form("Cosmics/%s_cosmics_1v2_cut1.pdf",basename)); c1->SetLogz(1); c1->Print(Form("Cosmics/%s_cosmics_1v2_cut1_log.png",basename)); c1->Print(Form("Cosmics/%s_cosmics_1v2_cut1_log.pdf",basename)); hhSvA_cut1->Draw("colz"); hhSvA_cut1->GetXaxis()->SetLimits(2*newmin/peconvert,2*newmax/peconvert); hhSvA_cut1->GetXaxis()->SetTitle("Sum"); hhSvA_cut1->GetYaxis()->SetTitle("Asymmetry"); tex1->Draw(); c1->SetLogz(0); c1->Print(Form("Cosmics/%s_cosmics_SvA_cut1.png",basename)); c1->Print(Form("Cosmics/%s_cosmics_SvA_cut1.pdf",basename)); c1->SetLogz(1); c1->Print(Form("Cosmics/%s_cosmics_SvA_cut1_log.png",basename)); c1->Print(Form("Cosmics/%s_cosmics_SvA_cut1_log.pdf",basename)); c1->SetLogz(0); hh1v2_cut2->Draw("colz"); hh1v2_cut2->GetXaxis()->SetLimits(newmin/peconvert,newmax/peconvert); hh1v2_cut2->GetYaxis()->SetLimits(newmin/peconvert,newmax/peconvert); hh1v2_cut2->GetXaxis()->SetTitle("#pe SiPM1"); hh1v2_cut2->GetYaxis()->SetTitle("#pe SiPM2"); TLatex *tex2 = new TLatex(0.2,0.8,"SiPMA < SiPMB + 20"); tex2->SetTextSize(0.05); tex2->SetNDC(kTRUE); tex2->Draw(); c1->SetLogz(0); c1->Print(Form("Cosmics/%s_cosmics_1v2_cut2.png",basename)); c1->Print(Form("Cosmics/%s_cosmics_1v2_cut2.pdf",basename)); c1->SetLogz(1); c1->Print(Form("Cosmics/%s_cosmics_1v2_cut2_log.png",basename)); c1->Print(Form("Cosmics/%s_cosmics_1v2_cut2_log.pdf",basename)); hhSvA_cut2->Draw("colz"); hhSvA_cut2->GetXaxis()->SetLimits(2*newmin/peconvert,2*newmax/peconvert); hhSvA_cut2->GetXaxis()->SetTitle("Sum"); hhSvA_cut2->GetYaxis()->SetTitle("Asymmetry"); tex2->Draw(); c1->SetLogz(0); c1->Print(Form("Cosmics/%s_cosmics_SvA_cut2.png",basename)); c1->Print(Form("Cosmics/%s_cosmics_SvA_cut2.pdf",basename)); c1->SetLogz(1); c1->Print(Form("Cosmics/%s_cosmics_SvA_cut2_log.png",basename)); c1->Print(Form("Cosmics/%s_cosmics_SvA_cut2_log.pdf",basename)); hsum->SetLineColor(kBlack); hsum->SetLineWidth(2); hsum->GetXaxis()->SetLimits(2*newmin/peconvert,2*newmax/peconvert); //hsum->GetXaxis()->SetRangeUser(0.0,120.0); hsum->GetXaxis()->SetTitle("Number of photoelectrons SiPM1+SiPM2"); hsum->Draw(); c1->Print(Form("Cosmics/%s_temp.png",basename)); c1->Print(Form("Cosmics/%s_temp.pdf",basename)); hsum->SetMaximum(30); c1->Print(Form("Cosmics/%s_templow.png",basename)); c1->Print(Form("Cosmics/%s_templow.pdf",basename)); c1->SetLogy(); hsum->SetMaximum(1.1*h1->GetBinContent(hsum->GetMaximumBin())); c1->Print(Form("Cosmics/%s_templog.png",basename)); c1->Print(Form("Cosmics/%s_templog.pdf",basename)); // --------------------------------------------------------- bgscale = 100; h1->Fit(fun,"","",lofit,hifit); fun->SetLineColor(kRed); fun->SetLineWidth(2); fun->Draw("same"); cout << fun->GetChisquare() << "/" << fun->GetNDF() << endl; c1->SetLogy(0); c1->Print(Form("Cosmics/%s_tempfit.png",basename)); c1->Print(Form("Cosmics/%s_tempfit.pdf",basename)); h1->SetMaximum(175); c1->Print(Form("Cosmics/%s_templowfit.png",basename)); c1->Print(Form("Cosmics/%s_templowfit.pdf",basename)); h1->SetMaximum(100); c1->Print(Form("Cosmics/%s_tempLOWfit.png",basename)); c1->Print(Form("Cosmics/%s_tempLOWfit.pdf",basename)); c1->SetLogy(1); h1->SetMaximum(1.1*h1->GetBinContent(h1->GetMaximumBin())); c1->Print(Form("Cosmics/%s_templogfit.png",basename)); c1->Print(Form("Cosmics/%s_templogfit.pdf",basename)); c1->Clear(); h1->Draw(); double hax = fun->GetParameter(0); double mux = fun->GetParameter(1); double six = fun->GetParameter(2); fun->SetParameter(0,0.95*hax); fun->SetParameter(1,mux); fun->SetParameter(2,1.1*six); //fun->Draw("same"); //h1->Fit(simplefun,"","",0,60); TF1 *fun2 = new TF1("fun2","([0]/sqrt(6.28))*TMath::Exp(-0.5*((x-[1])/[2] + TMath::Exp(-(x-[1])/[2])))",2*newmin/peconvert,2*newmax/peconvert); // fun2->SetParameter(0,hax); // fun2->SetParameter(1,mux); // fun2->SetParameter(2,six); // fun2->SetParameter(0,93); // fun2->SetParameter(1,35); // fun2->SetParameter(2,5); fun2->SetParameter(0,93); fun2->SetParameter(1,500); fun2->SetParameter(2,100); //fun2->SetLineColor(kBlack); h1->Fit(fun2,"","",lofit,hifit); fun2->Draw("same"); cout << fun2->GetChisquare() << "/" << fun2->GetNDF() << endl; double par1 = fun2->GetParameter(1); TLine line(par1,0,par1,0.24*fun2->GetParameter(0)); line.Draw(); c1->SetLogy(0); c1->Print(Form("Cosmics/%s_tempffit.png",basename)); c1->Print(Form("Cosmics/%s_tempffit.pdf",basename)); h1->SetMaximum(25); c1->Print(Form("Cosmics/%s_templowffit.png",basename)); c1->Print(Form("Cosmics/%s_templowffit.pdf",basename)); h1->SetMaximum(0.3*fun2->GetParameter(0)); TLatex *tex = new TLatex(0.6,0.8,Form("MPV = %.1f #pm %.1f",fun2->GetParameter(1),fun2->GetParError(1))); tex->SetNDC(); tex->SetTextSize(0.05); tex->Draw(); //h1->GetXaxis()->SetRangeUser(0.0,130.0); // new... c1->Print(Form("Cosmics/SmallTileCosmics_%s_tempLOWffit.png",basename)); c1->Print(Form("Cosmics/SmallTileCosmics_%s_tempLOWffit.pdf",basename)); c1->SetLogy(1); h1->SetMaximum(1.1*h1->GetBinContent(h1->GetMaximumBin())); c1->Print(Form("Cosmics/%s_templogffit.png",basename)); c1->Print(Form("Cosmics/%s_templogffit.pdf",basename)); }
void TrackSlurm::getHistograms(TString inFile, TString outFile) { TString inFileName; inFileName = inFile; const int nPtBin=34; double ptBins[nPtBin+1]={0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2,1.4,1.6,1.8,2.0,2.2,2.4,3.2,4.0,4.8,5.6,6.4,7.2,9.6,12.0,14.4,19.2,24.0,28.8,35.2,41.6,48.0,60.8,73.6,86.4,103.6,120.8}; TH1D *ptHist = new TH1D("pthist","generalTracks pT Distribution", nPtBin, ptBins); TH1D *vzHist = new TH1D("vzhist","generalTracks pT Distribution", 100, -25,25); TH1D *nVzHist = new TH1D("nvzhist","generalTracks pT Distribution", 10, 0,10); TH1D *nVzHistSD = new TH1D("nvzhistsd","generalTracks pT Distribution", 10, 0,10); TH1D *nVzHistDD = new TH1D("nvzhistdd","generalTracks pT Distribution", 10, 0,10); TH1D *nVzHistND = new TH1D("nvzhistnd","generalTracks pT Distribution", 10, 0,10); TH1D *nVzHistNoES = new TH1D("nvzhistnoes","generalTracks pT Distribution", 10, 0,10); TH1D *nVz1PtHist = new TH1D("nvz1pthist","generalTracks pT Distribution", nPtBin, ptBins); TH1D *vzHistNoES = new TH1D("vzhistnoes","generalTracks pT Distribution", 100, -25,25); TH1D *vzHistnVz1 = new TH1D("vzhistnvz1","generalTracks pT Distribution", 100, -25,25); TH1D *ptHistCalo = new TH1D("pthistcalo","generalTracks pT Distribution", nPtBin, ptBins); TH1D *nVz1PtHistCalo = new TH1D("nvz1pthistcalo","generalTracks pT Distribution", nPtBin, ptBins); TH1D *gPtVtxptHistCalo = new TH1D("gptvtxpthistcalo","generalTracks pT Distribution", nPtBin, ptBins); TH1D *allVtxptHistCalo = new TH1D("allvtxpthistcalo","generalTracks pT Distribution", nPtBin, ptBins); TH1D *allVtxptHistCaloSD = new TH1D("allvtxpthistcalosd","generalTracks pT Distribution", nPtBin, ptBins); TH1D *allVtxptHistCaloDD = new TH1D("allvtxpthistcalodd","generalTracks pT Distribution", nPtBin, ptBins); TH1D *allVtxptHistCaloND = new TH1D("allvtxpthistcalond","generalTracks pT Distribution", nPtBin, ptBins); TH1D *allVtxptHistCaloEta1 = new TH1D("allvtxpthistcaloeta1","generalTracks pT Distribution", nPtBin, ptBins); TH1D *allVtxptHistCaloSDEta1 = new TH1D("allvtxpthistcalosdeta1","generalTracks pT Distribution", nPtBin, ptBins); TH1D *allVtxptHistCaloDDEta1 = new TH1D("allvtxpthistcaloddeta1","generalTracks pT Distribution", nPtBin, ptBins); TH1D *allVtxptHistCaloNDEta1 = new TH1D("allvtxpthistcalondeta1","generalTracks pT Distribution", nPtBin, ptBins); TH1D *proIDnVtx0Hist = new TH1D("proidnvtx0hist","process ID Distribution", 10, 100,110); TH1D *proIDnVtxnHist = new TH1D("proidnvtxnhist","process ID Distribution", 10, 100,110); TH1D *proIDAllHist = new TH1D("proidallhist","process ID Distribution", 10, 100,110); TH1D *proIDESHist = new TH1D("proideshist","process ID Distribution", 10, 100,110); TH1D *nVzHistNoESWithHLT = new TH1D("nvzhistnoeswithhlt","generalTracks pT Distribution", 10, 0,10); TH1D *proIDnVtx0HLTHist = new TH1D("proidnvtx0hlthist","process ID Distribution", 10, 100,110); TH1D *proIDnVtxnHLTHist = new TH1D("proidnvtxnhlthist","process ID Distribution", 10, 100,110); TH1D *proIDHLTHist = new TH1D("proidhlthist","process ID Distribution", 10, 100,110); TH1D *proIDHLTESHist = new TH1D("proidhlteshist","process ID Distribution", 10, 100,110); TH1D *nMultHist = new TH1D("nmulthist","Multiplicity Distribution", 200, 0,200); TH1D *nMultHistSD = new TH1D("nmulthistsd","Multiplicity Distribution", 200, 0,200); TH1D *nMultHistDD = new TH1D("nmulthistdd","Multiplicity Distribution", 200, 0,200); TH1D *nMultHistND = new TH1D("nmulthistnd","Multiplicity Distribution", 200, 0,200); TH1D *nMultHistEta24 = new TH1D("nmulthisteta24","Multiplicity Distribution", 200, 0,200); TH1D *nMultHistEta10 = new TH1D("nmulthisteta10","Multiplicity Distribution", 200, 0,200); TH1D *nMultHistEta24SD = new TH1D("nmulthisteta24sd","Multiplicity Distribution", 200, 0,200); TH1D *nMultHistEta10SD = new TH1D("nmulthisteta10sd","Multiplicity Distribution", 200, 0,200); TH1D *nMultHistEta24DD = new TH1D("nmulthisteta24dd","Multiplicity Distribution", 200, 0,200); TH1D *nMultHistEta10DD = new TH1D("nmulthisteta10dd","Multiplicity Distribution", 200, 0,200); TH1D *nMultHistEta24ND = new TH1D("nmulthisteta24nd","Multiplicity Distribution", 200, 0,200); TH1D *nMultHistEta10ND = new TH1D("nmulthisteta10nd","Multiplicity Distribution", 200, 0,200); int nmult24, nmult10; int nmult24sd, nmult10sd; int nmult24dd, nmult10dd; int nmult24nd, nmult10nd; const Int_t maxn = 90000; Float_t vz; Int_t processid; Int_t HLT_L1MinimumBiasHF1OR_v1; Int_t nTrk; Float_t trkPt[maxn], trkEta[maxn], trkPhi[maxn]; Bool_t highPurity[maxn]; Float_t trkDz1[maxn], trkDzError1[maxn],trkDxy1[maxn],trkDxyError1[maxn],trkPtError[maxn]; Int_t nTrkTimesnVtx; Float_t trkDzOverDzError[maxn], trkDxyOverDxyError[maxn]; long Nevt; int pVtx; int pBeamScrape; int nVtx; float trkMVA[maxn]; unsigned char trkNHit[maxn]; float pfEcal[maxn]; float pfHcal[maxn]; TFile * file = TFile::Open(inFileName); TTree * tree = (TTree *) file->Get("hiEvtAnalyzer/HiTree"); tree->AddFriend("pptrack=ppTrack/trackTree"); tree->AddFriend("skimTree=skimanalysis/HltTree"); tree->AddFriend("hltTree=hltanalysis/HltTree"); tree->AddFriend("genTree=HiGenParticleAna/hi"); tree->SetBranchAddress("vz",&vz); tree->SetBranchAddress("processid",&processid); tree->SetBranchAddress("HLT_L1MinimumBiasHF1OR_v1",&HLT_L1MinimumBiasHF1OR_v1); tree->SetBranchAddress("nTrk",&nTrk); tree->SetBranchAddress("trkPt",&trkPt); tree->SetBranchAddress("trkEta",&trkEta); tree->SetBranchAddress("trkPhi",&trkPhi); tree->SetBranchAddress("trkDz1",&trkDz1); tree->SetBranchAddress("trkDzError1",&trkDzError1); tree->SetBranchAddress("trkDxy1",&trkDxy1); tree->SetBranchAddress("trkDxyError1",&trkDxyError1); tree->SetBranchAddress("nTrkTimesnVtx",&nTrkTimesnVtx); tree->SetBranchAddress("trkDzOverDzError",&trkDzOverDzError); tree->SetBranchAddress("trkDxyOverDxyError",&trkDxyOverDxyError); //tree->SetBranchAddress("",&); tree->SetBranchAddress("trkPtError",&trkPtError); tree->SetBranchAddress("highPurity",&highPurity); tree->SetBranchAddress("trkMVA",&trkMVA); tree->SetBranchAddress("trkNHit",&trkNHit); tree->SetBranchAddress("pfHcal",&pfHcal); tree->SetBranchAddress("pfEcal",&pfEcal); tree->SetBranchAddress("pPAprimaryVertexFilter",&pVtx); tree->SetBranchAddress("pBeamScrapingFilter",&pBeamScrape); tree->SetBranchAddress("nVtx",&nVtx); Nevt=tree->GetEntries(); cout<<"Entries= "<<Nevt<<endl; for(long ne=0; ne<Nevt; ne++){ //for(long ne=0; ne<10000; ne++){ if(ne%3000==0) cout<<"Have run "<<ne<<" events. "<<endl; tree->GetEntry(ne); nmult24=0; nmult10=0; nmult24sd=0; nmult10sd=0; nmult24dd=0; nmult10dd=0; nmult24nd=0; nmult10nd=0; nVzHistNoES->Fill(nVtx*pVtx); if(HLT_L1MinimumBiasHF1OR_v1==1) nVzHistNoESWithHLT->Fill(nVtx*pVtx); vzHistNoES->Fill(vz); proIDAllHist->Fill(processid); if(nVtx*pVtx==0) proIDnVtx0Hist->Fill(processid); if(nVtx*pVtx==0 && HLT_L1MinimumBiasHF1OR_v1==1) proIDnVtx0HLTHist->Fill(processid); if(nVtx*pVtx>0) proIDnVtxnHist->Fill(processid); if(nVtx*pVtx>0 && HLT_L1MinimumBiasHF1OR_v1==1) proIDnVtxnHLTHist->Fill(processid); if(pVtx&&pBeamScrape) proIDESHist->Fill(processid); //only ES if(HLT_L1MinimumBiasHF1OR_v1==0) continue; proIDHLTHist->Fill(processid); //only HLT if(!(pVtx&&pBeamScrape)) continue; nVzHist->Fill(nVtx); vzHist->Fill(vz); proIDHLTESHist->Fill(processid); if(processid==103 || processid==104) nVzHistSD->Fill(nVtx); if(processid==105) nVzHistDD->Fill(nVtx); if(processid==101) nVzHistND->Fill(nVtx); if(nVtx==1) vzHistnVz1->Fill(vz); nMultHist->Fill(nTrk); if(processid==103 || processid==104) nMultHistSD->Fill(nTrk); if(processid==105) nMultHistDD->Fill(nTrk); if(processid==101) nMultHistND->Fill(nTrk); for(int ni=0;ni<nTrk;ni++){ if(!(highPurity[ni]&&trkPtError[ni]/trkPt[ni]<0.3&&trkPt[ni]>0.4&&trkPt[ni]<120.8&&fabs(trkEta[ni])<2.4)) continue; if(fabs(trkDz1[ni]/trkDzError1[ni])<3&&fabs(trkDxy1[ni]/trkDxyError1[ni])<3){ ptHist->Fill(trkPt[ni]); if(nVtx==1) nVz1PtHist->Fill(trkPt[ni]); } float Et = (pfHcal[ni]+pfEcal[ni])/TMath::CosH(trkEta[ni]); if(!(trkPt[ni]<20 || (Et>0.2*trkPt[ni] && Et>trkPt[ni]-80))) continue; //Calo Matching if(fabs(trkDz1[ni]/trkDzError1[ni])<3&&fabs(trkDxy1[ni]/trkDxyError1[ni])<3){ ptHistCalo->Fill(trkPt[ni]); if(nVtx==1) nVz1PtHistCalo->Fill(trkPt[ni]); gPtVtxptHistCalo->Fill(trkPt[ni]); } bool isCompatibleWithVertex = false; for(int v = 0; v<nVtx; v++){ if(TMath::Abs(trkDxyOverDxyError[ni*nVtx+v])<3 && TMath::Abs(trkDzOverDzError[ni*nVtx+v])<3){ isCompatibleWithVertex = true; break; } } if(!isCompatibleWithVertex) continue; allVtxptHistCalo->Fill(trkPt[ni]); if(fabs(trkEta[ni])<1.0) allVtxptHistCaloEta1->Fill(trkPt[ni]); nmult24++; if(fabs(trkEta[ni])<1.0) nmult10++; if(processid==103 || processid==104){ allVtxptHistCaloSD->Fill(trkPt[ni]); if(fabs(trkEta[ni])<1.0) allVtxptHistCaloSDEta1->Fill(trkPt[ni]); nmult24sd++; if(fabs(trkEta[ni])<1.0) nmult10sd++; } if(processid==105){ allVtxptHistCaloDD->Fill(trkPt[ni]); if(fabs(trkEta[ni])<1.0) allVtxptHistCaloDDEta1->Fill(trkPt[ni]); nmult24dd++; if(fabs(trkEta[ni])<1.0) nmult10dd++; } if(processid==101){ allVtxptHistCaloND->Fill(trkPt[ni]); if(fabs(trkEta[ni])<1.0) allVtxptHistCaloNDEta1->Fill(trkPt[ni]); nmult24nd++; if(fabs(trkEta[ni])<1.0) nmult10nd++; } }//end of ntrk nMultHistEta24->Fill(nmult24); nMultHistEta10->Fill(nmult10); nMultHistEta24SD->Fill(nmult24sd); nMultHistEta10SD->Fill(nmult10sd); nMultHistEta24DD->Fill(nmult24dd); nMultHistEta10DD->Fill(nmult10dd); nMultHistEta24ND->Fill(nmult24nd); nMultHistEta10ND->Fill(nmult10nd); } ////// TString outFileName; outFileName = outFile; TFile * outFiles = TFile::Open(outFileName,"recreate"); outFiles->cd(); vzHist->Write(); ptHist->Write(); nVzHistNoES->Write(); nVzHist->Write(); nVzHistSD->Write(); nVzHistDD->Write(); nVzHistND->Write(); nVz1PtHist->Write(); vzHistNoES->Write(); vzHistnVz1->Write(); ptHistCalo->Write(); nVz1PtHistCalo->Write(); gPtVtxptHistCalo->Write(); allVtxptHistCalo->Write(); allVtxptHistCaloSD->Write(); allVtxptHistCaloDD->Write(); allVtxptHistCaloND->Write(); allVtxptHistCaloEta1->Write(); allVtxptHistCaloSDEta1->Write(); allVtxptHistCaloDDEta1->Write(); allVtxptHistCaloNDEta1->Write(); proIDnVtx0Hist->Write(); proIDnVtxnHist->Write(); proIDAllHist->Write(); proIDESHist->Write(); nVzHistNoESWithHLT->Write(); proIDnVtx0HLTHist->Write(); proIDnVtxnHLTHist->Write(); proIDHLTHist->Write(); proIDHLTESHist->Write(); nMultHist->Write(); nMultHistSD->Write(); nMultHistDD->Write(); nMultHistND->Write(); nMultHistEta24->Write(); nMultHistEta10->Write(); nMultHistEta24SD->Write(); nMultHistEta10SD->Write(); nMultHistEta24DD->Write(); nMultHistEta10DD->Write(); nMultHistEta24ND->Write(); nMultHistEta10ND->Write(); outFiles->Close(); delete vzHist; delete ptHist; delete nVzHistNoES; delete nVzHist; delete nVzHistSD; delete nVzHistDD; delete nVzHistND; delete nVz1PtHist; delete vzHistNoES; delete vzHistnVz1; delete ptHistCalo; delete nVz1PtHistCalo; delete gPtVtxptHistCalo; delete allVtxptHistCalo; delete allVtxptHistCaloSD; delete allVtxptHistCaloDD; delete allVtxptHistCaloND; delete allVtxptHistCaloEta1; delete allVtxptHistCaloSDEta1; delete allVtxptHistCaloDDEta1; delete allVtxptHistCaloNDEta1; delete proIDnVtx0Hist; delete proIDnVtxnHist; delete proIDAllHist; delete proIDESHist; delete nVzHistNoESWithHLT; delete proIDnVtx0HLTHist; delete proIDnVtxnHLTHist; delete proIDHLTHist; delete proIDHLTESHist; delete nMultHist; delete nMultHistSD; delete nMultHistDD; delete nMultHistND; delete nMultHistEta24; delete nMultHistEta10; delete nMultHistEta24SD; delete nMultHistEta10SD; delete nMultHistEta24DD; delete nMultHistEta10DD; delete nMultHistEta24ND; delete nMultHistEta10ND; }
//need function for find container in vector by name and create if not existing void do_sync(const char * file, const char* output){ using namespace top; using namespace std; TFile * f = new TFile(file); TTree * t = (TTree*) f->Get("PFTree/pfTree"); top::leptonSelector lepSel; lepSel.setUseRhoIsoForElectrons(false); ///FIRST TRY WITHOUT RHO ISO vector<NTMuon> * pMuons = 0; t->SetBranchAddress("NTMuons",&pMuons); vector<NTElectron> * pElectrons = 0; t->SetBranchAddress("NTPFElectrons",&pElectrons); vector<NTJet> * pJets=0; t->SetBranchAddress("NTJets",&pJets); NTMet * pMet = 0; t->SetBranchAddress("NTMet",&pMet); NTEvent * pEvent = 0; t->SetBranchAddress("NTEvent",&pEvent); TH1D * h = new TH1D(file,file,20,0,20); ////just some counters double totalkinelectrons=0; double totalkinmuons=0; double totalidelectrons=0; double totalidmuons=0; double totalisoelectrons=0; double totalisomuons=0; double totalhardjets=0; // start main loop ///////////////////////////////////////////////////////// Long64_t nEntries=t->GetEntries(); Long64_t maxevents=50000; if(maxevents < nEntries) nEntries=maxevents; cout << "\n\nrunning on maximum " << nEntries << " entries." <<endl; for(Long64_t entry=0;entry<nEntries;entry++){ displayStatusBar(entry,nEntries); t->GetEntry(entry); elecRhoIsoAdder rho(true,false); vector<NTElectron> kinelectrons; ////// clean electrons against muons and make kin cuts on the fly////// for(NTElectronIt elec=pElectrons->begin();elec<pElectrons->end();++elec){ if(elec->pt() < 20) continue; if(fabs(elec->eta()) > 2.5) continue; if(!noOverlap(elec, *pMuons, 0.1)) continue; kinelectrons.push_back(*elec); } //two leps cut rho.setRho(pEvent->isoRho(2)); rho.addRhoIso(kinelectrons); vector<NTMuon> kinmuons = lepSel.selectKinMuons(*pMuons); vector<NTElectron> idelectrons =lepSel.selectIDElectrons(kinelectrons); vector<NTMuon> idmuons =lepSel.selectIDMuons(kinmuons); vector<NTElectron> isoelectrons =lepSel.selectIsolatedElectrons(idelectrons); vector<NTMuon> isomuons =lepSel.selectIsolatedMuons(idmuons); if(kinelectrons.size() + kinmuons.size() < 2) continue; totalkinelectrons+=kinelectrons.size(); totalkinmuons+=kinmuons.size(); totalidelectrons+=idelectrons.size(); totalidmuons+=idmuons.size(); totalisoelectrons+=isoelectrons.size(); totalisomuons+=isomuons.size(); vector<NTJet> hardjets; for(NTJetIt jet=pJets->begin();jet<pJets->end();++jet){ //some kin cuts plus id overlaps commented! if(jet->pt()<30) continue; if(fabs(jet->eta())>2.5) continue; if(!(jet->id())) continue; // if(!noOverlap(jet, isomuons, 0.3)) continue; // if(!noOverlap(jet, isoelectrons, 0.3)) continue; hardjets.push_back(*jet); } h->Fill(hardjets.size()); totalhardjets+=hardjets.size(); } cout << "\nkinelecs: " << totalkinelectrons << "\n" << "idelectrons: " << totalidelectrons << "\n" << "isoelectrons: " << totalisoelectrons << "\n\n" << "kinmuons: " << totalkinmuons << "\n" << "idmuons: " << totalidmuons << "\n" << "isomuons: " << totalisomuons << "\n\n" << "hardjets: " << totalhardjets << "\n" << endl; cout << "hardjets definition might be the same as in real analysis! doesn't matter for sync." << endl; TCanvas * c = new TCanvas("",""); h->Draw(); c->Print(((TString) output) + ".eps"); f->Close(); //deletes all pointers delete f; }
void plotRBDphi( double dphiCut=3.026, // double dphiCut=2.094, double dphiCut2 = 3.026, TString infname = "data.root", TString pythia = "pythia.root", TString mix = "mix.root", bool useWeight = true, bool drawXLabel = false, bool drawLeg = true) { useWeight = 0; int threshold1 = 80; int threshold2 = 120; gStyle->SetErrorX(0); TString cut1=Form("abs(eta1) < 2 && abs(eta2) < 2 && et1>%d&&et2>50",threshold1); TString cut2=Form("abs(eta1) < 2 && abs(eta2) < 2 && et1>%d&&et2>50",threshold2); cout <<cut1.Data()<<endl; cout <<cut2.Data()<<endl; TString trigcut = ""; TString cstring = ""; // open the data file TFile *inf = new TFile(infname.Data()); TTree *nt =(TTree*)inf->FindObjectAny("nt"); // open the pythia (MC) file TFile *infPythia = new TFile(pythia.Data()); TTree *ntPythia = (TTree*) infPythia->FindObjectAny("nt"); // open the datamix file TFile *infMix = new TFile(mix.Data()); TTree *ntMix =(TTree*)infMix->FindObjectAny("nt"); // open output TFile *outfile = new TFile("output.root","recreate"); TNtuple *ntOut = new TNtuple("ntOut","","npart"); nt->SetAlias("et1","pt1"); nt->SetAlias("et2","pt2"); ntMix->SetAlias("et1","pt1"); ntMix->SetAlias("et2","pt2"); ntPythia->SetAlias("et1","pt1"); ntPythia->SetAlias("et2","pt2"); // ntMix->SetAlias("pt1","et1"); // ntMix->SetAlias("pt2","et2"); // ntPythia->SetAlias("pt1","et1"); // ntPythia->SetAlias("pt2","et2"); ntPythia->SetAlias("weight","1"); ntMix->SetAlias("weight","1"); const int nBin = 6; double m[nBin+1] = {-1.5,-0.5,3.5,7.5,11.5,20.5,40.5}; double npart[nBin] = {2,358.623,232.909,97.9521}; double npart2[nBin] = {2,358.623,232.909,97.9521}; double npartValue[40]; npartValue[0] = 393.633; npartValue[1] = 368.819; npartValue[2] = 343.073; npartValue[3] = 317.625; npartValue[4] = 292.932; npartValue[5] = 271.917; npartValue[6] = 249.851; npartValue[7] = 230.72; npartValue[8] = 212.465; npartValue[9] = 194.752; npartValue[10] = 178.571; npartValue[11] = 163.23; npartValue[12] = 149.187; npartValue[13] = 136.011; npartValue[14] = 123.414; npartValue[15] = 111.7; npartValue[16] = 100.831; npartValue[17] = 90.7831; npartValue[18] = 80.9823; npartValue[19] = 72.6236; npartValue[20] = 64.1508; npartValue[21] = 56.6284; npartValue[22] = 49.9984; npartValue[23] = 43.3034; npartValue[24] = 37.8437; npartValue[25] = 32.6659; npartValue[26] = 27.83; npartValue[27] = 23.7892; npartValue[28] = 20.1745; npartValue[29] = 16.8453; npartValue[30] = 14.0322; npartValue[31] = 11.602; npartValue[32] = 9.52528; npartValue[33] = 7.6984; npartValue[34] = 6.446; npartValue[35] = 4.96683; npartValue[36] = 4.23649; npartValue[37] = 3.50147; npartValue[38] = 3.16107; npartValue[39] = 2.7877; TH1D *hTmp = new TH1D("hTmp","",100,-10,400); TH1D *h = new TH1D("h","",nBin,m); TH1D *hCut = new TH1D("hCut","",nBin,m); TH1D *h2 = new TH1D("h2","",nBin,m); TH1D *h2Cut = new TH1D("h2Cut","",nBin,m); TH1D *hStat = new TH1D("hStat","",nBin,m); TH1D *hNpartSum = new TH1D("hNpartSum","",nBin,m); TH1D *hStat2 = new TH1D("hStat2","",nBin,m); TH1D *hNpartSum2 = new TH1D("hNpartSum2","",nBin,m); Float_t bin=0; Float_t et1=0; nt->SetBranchAddress("bin",&bin); nt->SetBranchAddress("pt1",&et1); for (int i=0;i<nt->GetEntries();i++) { nt->GetEntry(i); if (et1<threshold1) continue; if (et1>threshold2) { hNpartSum2->Fill(bin,npartValue[(int)bin]); hStat2->Fill(bin); if (et1>threshold1) { hNpartSum->Fill(bin,npartValue[(int)bin]); hStat->Fill(bin); } } } hNpartSum->Divide(hStat); hNpartSum2->Divide(hStat2); for (int i=1;i<nBin;i++) { cout <<hNpartSum->GetBinContent(i+1)<<endl; npart[i]=hNpartSum->GetBinContent(i+1); cout <<hNpartSum2->GetBinContent(i+1)<<endl; npart2[i]=hNpartSum2->GetBinContent(i+1); } nt->Draw("bin>>h",Form("abs(dphi)>%f&&%s",dphiCut,cut1.Data())); nt->Draw("bin>>hCut",Form("%s",cut1.Data())); TGraphAsymmErrors *g = calcEff(hCut,h,npart); g->SetMarkerSize(1.25); cout <<cut2.Data()<<endl; nt->Draw("bin>>h2",Form("abs(dphi)>%f&&%s",dphiCut2,cut2.Data())); nt->Draw("bin>>h2Cut",Form("%s",cut2.Data())); TGraphAsymmErrors *g2 = calcEff(h2Cut,h2,npart2); g2->SetMarkerSize(1.25); ntPythia->Draw("bin>>h",Form("abs(dphi)>%f&&%s",dphiCut2,cut2.Data())); ntPythia->Draw("bin>>hCut",Form("%s",cut2.Data())); TGraphAsymmErrors *gPythia = calcEffpythia(hCut,h,npart); gPythia->SetMarkerSize(1.7); if(useWeight){ ntMix->Draw("bin>>h",Form("weight*(abs(dphi)>%f&&%s)",dphiCut2,cut2.Data())); ntMix->Draw("bin>>hCut",Form("weight*(%s)",cut2.Data())); }else{ ntMix->Draw("bin>>h",Form("(abs(dphi)>%f&&%s)",dphiCut2,cut2.Data())); ntMix->Draw("bin>>hCut",Form("(%s)",cut2.Data())); } TGraphAsymmErrors *gMix = calcEff(hCut,h,npart); gMix->SetMarkerSize(1.25); TCanvas *c = new TCanvas("c","",500,500); // hTmp->SetMaximum(g->GetY()[0]*2.2); hTmp->SetMaximum(0.85); hTmp->SetMinimum(0.); hTmp->SetXTitle("N_{part}"); hTmp->SetYTitle(Form("R_{B}(#Delta#phi_{12} > %.3f)",dphiCut)); hTmp->GetXaxis()->CenterTitle(); hTmp->GetYaxis()->CenterTitle(); // hTmp->GetYaxis()->SetTitleOffset(1.2); // hTmp->GetYaxis()->SetTitleSize(0.055); hTmp->Draw(); double errorbar = 0.02; /* for(int i = 0; i < g->GetN(); ++i){ double *x = g->GetX(); double *y = g->GetY(); // DrawTick(y[i],0.18*y[i],0.18*y[i],x[i],0.012,8.1,16); } g->Draw("p same"); g2->SetMarkerStyle(4); */ for(int i = 0; i < g2->GetN(); ++i){ double *x = g2->GetX(); double *y = g2->GetY(); double err = 1.5*(0.0001129*x[i]); err = sqrt(err * err + 0.012*0.012); cout <<err/y[i]<<" "<<1.5*(0.0001129*x[i])/y[i]<<" "<<0.012/y[i]<<endl; double tickSize = 0.012; if (err<tickSize) tickSize=err; DrawTick(y[i],err,err,x[i],tickSize,8.1,dataColor); } gPythia->SetMarkerColor(4); gPythia->SetLineColor(4); gPythia->SetMarkerStyle(29); gMix->SetMarkerColor(4); gMix->SetLineColor(4); gMix->SetMarkerStyle(25); // gMix->Draw("p same"); gPythia->Draw("p same"); g2->SetLineColor(dataColor); g2->SetMarkerColor(dataColor); g2->Draw("p same"); TLine* pline = new TLine(0,gPythia->GetY()[0],400,gPythia->GetY()[0]); pline->SetLineColor(4); pline->SetLineStyle(4); pline->Draw(); if(drawLeg){ TLegend *t3=new TLegend(0.5,0.77,0.9,0.93); t3->AddEntry(g2,"PbPb #sqrt{s}_{_{NN}}=2.76 TeV","p"); // t3->AddEntry(gPythia,"PYTHIA","p"); // t3->AddEntry(gMix,"PYTHIA+DATA","p"); // t3->AddEntry(g,"2011","p"); // t3->AddEntry(gMix,"2010","p"); t3->AddEntry(gPythia,"pp #sqrt{s}=2.76 TeV","p"); t3->SetFillColor(0); t3->SetBorderSize(0); t3->SetFillStyle(0); t3->SetTextFont(63); t3->SetTextSize(15); t3->Draw(); } TLatex *cms = new TLatex(0.20,0.88,"CMS Preliminary"); cms->SetNDC(); cms->SetTextFont(63); cms->SetTextSize(18); cms->Draw(); TLatex tsel; tsel.SetNDC(); tsel.SetTextFont(63); tsel.SetTextSize(15); tsel.DrawLatex(0.25,0.35,"p_{T,1} > 120 GeV/c"); tsel.DrawLatex(0.25,0.275,"p_{T,2} > 30 GeV/c"); // tsel.DrawLatex(0.25,0.20,"#Delta#phi_{12} > #frac{2}{3}#pi rad"); TLatex *lumi = new TLatex(0.20,0.81,"#intL dt = 6.7 #mub^{-1}"); lumi->SetNDC(); lumi->SetTextFont(63); lumi->SetTextSize(15); lumi->Draw(); /* TF1 *f = new TF1("f","0.5+[0]*x"); gMix->Fit("f"); */ TCanvas *c2 = new TCanvas("c2","",500,500); TGraphAsymmErrors *gRatio = divideGraph(g2,gMix); gRatio->Draw("ap"); gRatio->Fit("pol1"); //gRatio->Fit("pol0"); c->Print(Form("fig/RB_dphi_%d_vs_Npart.eps",(int)(1000*dphiCut))); c->Print(Form("fig/RB_dphi_%d_vs_Npart.C",(int)(1000*dphiCut))); c->Print(Form("fig/RB_dphi_%d_vs_Npart.gif",(int)(1000*dphiCut))); c->Print(Form("fig/RB_dphi_%d_vs_Npart.pdf",(int)(1000*dphiCut))); }