int main(int argc, char *argv[]){ TFile* fout = new TFile("cascade.result.root","RECREATE"); HepMC::IO_GenEvent fin("../CASCADE_HEPMC/bin/example_test_out.dat",std::ios::in); HepMC::GenEvent* evt = new HepMC::GenEvent; TTree *tree = new TTree("tree","cascade result"); tree->Branch("event",&evt); Int_t nevt = 0; while (evt = fin.read_next_event() ) { nevt++; if(debug){ cout<<"nevt: "<<nevt<<endl; getchar(); evt->print(); } tree->Fill(); } tree->Print(); fout->cd(); tree->Write(); fout->Close(); delete fout; return(0); }
void CreateParentTree() { // create a simple TTree with 5 branches // Two branches ("Run" and "Event") will be used to index the Tree TFile *f = new TFile("treeparent.root","recreate"); TTree *T = new TTree("T","test friend trees"); T->Branch("Run",&Run,"Run/I"); T->Branch("Event",&Event,"Event/I"); T->Branch("x",&x,"x/F"); T->Branch("y",&y,"y/F"); T->Branch("z",&z,"z/F"); TRandom r; for (Int_t i=0;i<10000;i++) { if (i < 5000) Run = 1; else Run = 2; Event = i; x = r.Gaus(10,1); y = r.Gaus(20,2); z = r.Landau(2,1); T->Fill(); } T->Print(); T->Write(); delete f; }
// nEvents is how many events we want. int makeEventSample(Int_t nEvents) { // Load needed libraries loadLibraries(); // Create an instance of the Pythia event generator ... TPythia6* pythia = new TPythia6; // ... and initialise it to run p+p at sqrt(200) GeV in CMS pythia->Initialize("cms", "p", "p", 200); // Open an output file TFile* file = TFile::Open(FILENAME, "RECREATE"); if (!file || !file->IsOpen()) { Error("makeEventSample", "Couldn;t open file %s", FILENAME); return 1; } // Make a tree in that file ... TTree* tree = new TTree(TREENAME, "Pythia 6 tree"); // ... and register a the cache of pythia on a branch (It's a // TClonesArray of TMCParticle objects. ) TClonesArray* particles = (TClonesArray*)pythia->GetListOfParticles(); tree->Branch(BRANCHNAME, &particles); // Now we make some events for (Int_t i = 0; i < nEvents; i++) { // Show how far we got every 100'th event. if (i % 100 == 0) cout << "Event # " << i << endl; // Make one event. pythia->GenerateEvent(); // Maybe you want to have another branch with global event // information. In that case, you should process that here. // You can also filter out particles here if you want. // Now we're ready to fill the tree, and the event is over. tree->Fill(); } // Show tree structure tree->Print(); // After the run is over, we may want to do some summary plots: TH1D* hist = new TH1D(HISTNAME, "p_{#perp} spectrum for #pi^{+}", 100, 0, 3); hist->SetXTitle("p_{#perp}"); hist->SetYTitle("dN/dp_{#perp}"); char expression[64]; sprintf(expression,"sqrt(pow(%s.fPx,2)+pow(%s.fPy,2))>>%s", BRANCHNAME, BRANCHNAME, HISTNAME); char selection[64]; sprintf(selection,"%s.fKF==%d", BRANCHNAME, PDGNUMBER); tree->Draw(expression,selection); // Normalise to the number of events, and the bin sizes. hist->Sumw2(); hist->Scale(3 / 100. / hist->Integral()); hist->Fit("expo", "QO+", "", .25, 1.75); TF1* func = hist->GetFunction("expo"); func->SetParNames("A", "- 1 / T"); // and now we flush and close the file file->Write(); file->Close(); return 0; }
// default is Drell-Yan MC with minimal cuts void skims(int dataset = 0, int whichSkims = 1) { if ( whichSkims == 0 ) std::cout << " \n*** MERGING ALL THE FILES ***\n\n"; else if ( whichSkims == 1 ) std::cout << " \n*** APPLYING MINIMAL CUTS ***\n\n"; else if ( whichSkims == 2 ) std::cout << " \n*** APPLYING TIGHT CUTS, BUT ACCEPTANCE AND TRIGGER SELECTIONS ***\n\n"; else { std::cout << "NO SKIMS TYPE DEFINED!\n"; return; } TChain* tree = new TChain("tree"); // ======== Monte Carlo ========== if ( dataset == 0 ) { std::cout << "DYJetsToLL_M50 DATASET\n"; //ls /data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesMCDYJetsToLL_M-50_TuneZ2Star_8TeV-madgraph-tarball_Summer12_DR53X-PU_S10_START53_V7A-v1/ | grep root | awk '{print "tree->AddFile(\"/data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesMCDYJetsToLL_M-50_TuneZ2Star_8TeV-madgraph-tarball_Summer12_DR53X-PU_S10_START53_V7A-v1/"$1"\");"}' >> scripts/htomm/skims/V00-01-10/chainDYJetsToLL #include "scripts/htomm/skims/V00-01-10/chainDYJetsToLL" } else if ( dataset == 1 ) { std::cout << "DYToMuMu DATASET\n"; //ls /data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesMCDYToMuMu_M-20_CT10_TuneZ2star_v2_8TeV-powheg-pythia6_Summer12_DR53X-PU_S10_START53_V7A-v1/ | grep root | awk '{print "tree->AddFile(\"/data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesMCDYToMuMu_M-20_CT10_TuneZ2star_v2_8TeV-powheg-pythia6_Summer12_DR53X-PU_S10_START53_V7A-v1/"$1"\");"}' >> scripts/htomm/skims/V00-01-10/chainDYToMuMu #include "scripts/htomm/skims/V00-01-10/chainDYToMuMu" } else if ( dataset == 2 ) { std::cout << "TTJets DATASET\n"; //ls /data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesMCTTJets_MassiveBinDECAY_TuneZ2star_8TeV-madgraph-tauola_Summer12_DR53X-PU_S10_START53_V7C-v1/ | grep root | awk '{print "tree->AddFile(\"/data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesMCTTJets_MassiveBinDECAY_TuneZ2star_8TeV-madgraph-tauola_Summer12_DR53X-PU_S10_START53_V7C-v1/"$1"\");"}' >> scripts/htomm/skims/V00-01-10/chainTTJets #include "scripts/htomm/skims/V00-01-10/chainTTJets" } else if ( dataset == 3 ) { std::cout << "DYToTauTau DATASET\n"; //ls /data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesMCDYToTauTau_M-20_CT10_TuneZ2star_8TeV-powheg-pythia6_Summer12_DR53X-PU_S10_START53_V7A-v1/ | grep root | awk '{print "tree->AddFile(\"/data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesMCDYToTauTau_M-20_CT10_TuneZ2star_8TeV-powheg-pythia6_Summer12_DR53X-PU_S10_START53_V7A-v1/"$1"\");"}' >> scripts/htomm/skims/V00-01-10/chainDYToTauTau #include "scripts/htomm/skims/V00-01-10/chainDYToTauTau" } else if ( dataset == 4 ) { std::cout << "WJetsToLNu DATASET\n"; //ls /data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesMCWJetsToLNu_TuneZ2Star_8TeV-madgraph-tarball_Summer12_DR53X-PU_S10_START53_V7A-v2/ | grep root | awk '{print "tree->AddFile(\"/data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesMCWJetsToLNu_TuneZ2Star_8TeV-madgraph-tarball_Summer12_DR53X-PU_S10_START53_V7A-v2/"$1"\");"}' >> scripts/htomm/skims/V00-01-10/chainWJetsToLNu #include "scripts/htomm/skims/V00-01-10/chainWJetsToLNu" } else if ( dataset == 5 ) { std::cout << "WW DATASET\n"; //ls /data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesMCWW_TuneZ2star_8TeV_pythia6_tauola_Summer12_DR53X-PU_S10_START53_V7A-v1/ | grep root | awk '{print "tree->AddFile(\"/data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesMCWW_TuneZ2star_8TeV_pythia6_tauola_Summer12_DR53X-PU_S10_START53_V7A-v1/"$1"\");"}' >> scripts/htomm/skims/V00-01-10/chainWW #include "scripts/htomm/skims/V00-01-10/chainWW" } else if ( dataset == 6 ) { std::cout << "WZ DATASET\n"; //ls /data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesMCWZ_TuneZ2star_8TeV_pythia6_tauola_Summer12_DR53X-PU_S10_START53_V7A-v1/ | grep root | awk '{print "tree->AddFile(\"/data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesMCWZ_TuneZ2star_8TeV_pythia6_tauola_Summer12_DR53X-PU_S10_START53_V7A-v1/"$1"\");"}' >> scripts/htomm/skims/V00-01-10/chainWZ #include "scripts/htomm/skims/V00-01-10/chainWZ" } else if ( dataset == 7 ) { std::cout << "ZZ DATASET\n"; //ls /data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesMCZZ_TuneZ2star_8TeV_pythia6_tauola_Summer12_DR53X-PU_S10_START53_V7A-v1/ | grep root | awk '{print "tree->AddFile(\"/data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesMCZZ_TuneZ2star_8TeV_pythia6_tauola_Summer12_DR53X-PU_S10_START53_V7A-v1/"$1"\");"}' >> scripts/htomm/skims/V00-01-10/chainZZ #include "scripts/htomm/skims/V00-01-10/chainZZ" } else if ( dataset == 8 ) { std::cout << "QCD DATASET\n"; //ls /data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesMCQCD_Pt_20_MuEnrichedPt_15_TuneZ2star_8TeV_pythia6_Summer12_DR53X-PU_S10_START53_V7A-v3/ | grep root | awk '{print "tree->AddFile(\"/data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesMCQCD_Pt_20_MuEnrichedPt_15_TuneZ2star_8TeV_pythia6_Summer12_DR53X-PU_S10_START53_V7A-v3/"$1"\");"}' >> scripts/htomm/skims/V00-01-10/chainQCD_Pt_20_MuEnrichedPt_15 #include "scripts/htomm/skims/V00-01-10/chainQCD_Pt_20_MuEnrichedPt_15" } else if ( dataset == 9 ) { std::cout << "DY2JetsToLL_M50 DATASET\n"; //ls /data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesMCDY2JetsToLL_M-50_TuneZ2Star_8TeV-madgraph_Summer12_DR53X-PU_S10_START53_V7A-v1/ | grep root | awk '{print "tree->AddFile(\"/data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesMCDY2JetsToLL_M-50_TuneZ2Star_8TeV-madgraph_Summer12_DR53X-PU_S10_START53_V7A-v1/"$1"\");"}' >> scripts/htomm/skims/V00-01-10/chainDY2JetsToLL #include "scripts/htomm/skims/V00-01-10/chainDY2JetsToLL" } // ======== Special Monte Carlo ========= else if ( dataset == 9990 ) { std::cout << "DYJetsToLL_PtZ-50To70 DATASET\n"; //ls /data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesMCDYJetsToLL_PtZ-50To70_TuneZ2star_8TeV-madgraph-tarball_Summer12_DR53X-PU_S10_START53_V7A-v1/ | grep root | awk '{print "tree->AddFile(\"/data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesMCDYJetsToLL_PtZ-50To70_TuneZ2star_8TeV-madgraph-tarball_Summer12_DR53X-PU_S10_START53_V7A-v1/"$1"\");"}' >> scripts/htomm/skims/V00-01-10/chainDYJetsToLL_PtZ-50To70 #include "scripts/htomm/skims/V00-01-10/chainDYJetsToLL_PtZ-50To70" } else if ( dataset == 9991 ) { std::cout << "DYJetsToLL_PtZ-70To100 DATASET\n"; //ls /data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesMCDYJetsToLL_PtZ-70To100_TuneZ2star_8TeV-madgraph-tarball_Summer12_DR53X-PU_S10_START53_V7A-v2/ | grep root | awk '{print "tree->AddFile(\"/data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesMCDYJetsToLL_PtZ-70To100_TuneZ2star_8TeV-madgraph-tarball_Summer12_DR53X-PU_S10_START53_V7A-v2/"$1"\");"}' >> scripts/htomm/skims/V00-01-10/chainDYJetsToLL_PtZ-70To100 #include "scripts/htomm/skims/V00-01-10/chainDYJetsToLL_PtZ-70To100" } else if ( dataset == 9992 ) { std::cout << "DYJetsToLL_PtZ-100 DATASET\n"; //ls /data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesMCDYJetsToLL_PtZ-100_TuneZ2star_8TeV-madgraph-tarball_Summer12_DR53X-PU_S10_START53_V7A-v2/ | grep root | awk '{print "tree->AddFile(\"/data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesMCDYJetsToLL_PtZ-100_TuneZ2star_8TeV-madgraph-tarball_Summer12_DR53X-PU_S10_START53_V7A-v2/"$1"\");"}' >> scripts/htomm/skims/V00-01-10/chainDYJetsToLL_PtZ-100 #include "scripts/htomm/skims/V00-01-10/chainDYJetsToLL_PtZ-100" } // ======== Data ========== // Single Muon Dataset else if ( dataset == 10 ) { std::cout << "SingleMu 2012A-13Jul2012-v1 DATASET\n"; //ls /data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesDataSingleMuRun2012A-13Jul2012-v1/ | grep root | awk '{print "tree->AddFile(\"/data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesDataSingleMuRun2012A-13Jul2012-v1/"$1"\");"}' >> scripts/htomm/skims/V00-01-10/chainSingleMuRun2012A-13Jul2012-v1 #include "scripts/htomm/skims/V00-01-10/chainSingleMuRun2012A-13Jul2012-v1" } else if ( dataset == 11 ) { std::cout << "SingleMu 2012A-recover-06Aug2012-v1 DATASET\n"; //ls /data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesDataSingleMuRun2012A-recover-06Aug2012-v1/ | grep root | awk '{print "tree->AddFile(\"/data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesDataSingleMuRun2012A-recover-06Aug2012-v1/"$1"\");"}' >> scripts/htomm/skims/V00-01-10/chainSingleMuRun2012A-recover-06Aug2012-v1 #include "scripts/htomm/skims/V00-01-10/chainSingleMuRun2012A-recover-06Aug2012-v1" } else if ( dataset == 12 ) { std::cout << "SingleMu 2012B-13Jul2012-v1 DATASET\n"; //ls /data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesDataSingleMuRun2012B-13Jul2012-v1/ | grep root | awk '{print "tree->AddFile(\"/data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesDataSingleMuRun2012B-13Jul2012-v1/"$1"\");"}' >> scripts/htomm/skims/V00-01-10/chainSingleMuRun2012B-13Jul2012-v1 #include "scripts/htomm/skims/V00-01-10/chainSingleMuRun2012B-13Jul2012-v1" } else if ( dataset == 13 ) { std::cout << "SingleMu 2012C-24Aug2012-v1 DATASET\n"; //ls /data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesDataSingleMuRun2012C-24Aug2012-v1/ | grep root | awk '{print "tree->AddFile(\"/data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesDataSingleMuRun2012C-24Aug2012-v1/"$1"\");"}' >> scripts/htomm/skims/V00-01-10/chainSingleMuRun2012C-24Aug2012-v1 #include "scripts/htomm/skims/V00-01-10/chainSingleMuRun2012C-24Aug2012-v1" } else if ( dataset == 14 ) { std::cout << "SingleMu 2012C-PromptReco-v2 DATASET\n"; //ls /data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesDataSingleMuRun2012C-PromptReco-v2/ | grep root | awk '{print "tree->AddFile(\"/data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesDataSingleMuRun2012C-PromptReco-v2/"$1"\");"}' >> scripts/htomm/skims/V00-01-10/chainSingleMuRun2012C-PromptReco-v2 #include "scripts/htomm/skims/V00-01-10/chainSingleMuRun2012C-PromptReco-v2" } else if ( dataset == 15 ) { std::cout << "SingleMu 2012D-PromptReco-v1 DATASET\n"; //ls /data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesDataSingleMuRun2012D-PromptReco-v1/ | grep root | awk '{print "tree->AddFile(\"/data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesDataSingleMuRun2012D-PromptReco-v1/"$1"\");"}' >> scripts/htomm/skims/V00-01-10/chainSingleMuRun2012D-PromptReco-v1 #include "scripts/htomm/skims/V00-01-10/chainSingleMuRun2012D-PromptReco-v1" } // Double Muon Dataset else if ( dataset == 20 ) { std::cout << "DoubleMu 2012A-13Jul2012-v1 DATASET\n"; //ls /data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesDataDoubleMuRun2012A-13Jul2012-v1/ | grep root | awk '{print "tree->AddFile(\"/data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesDataDoubleMuRun2012A-13Jul2012-v1/"$1"\");"}' >> scripts/htomm/skims/V00-01-10/chainDoubleMuRun2012A-13Jul2012-v1 #include "scripts/htomm/skims/V00-01-10/chainDoubleMuRun2012A-13Jul2012-v1" } else if ( dataset == 21 ) { std::cout << "DoubleMu 2012B-13Jul2012-v4 DATASET\n"; //ls /data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesDataDoubleMuRun2012B-13Jul2012-v4/ | grep root | awk '{print "tree->AddFile(\"/data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesDataDoubleMuRun2012B-13Jul2012-v4/"$1"\");"}' >> scripts/htomm/skims/V00-01-10/chainDoubleMuRun2012B-13Jul2012-v4 #include "scripts/htomm/skims/V00-01-10/chainDoubleMuRun2012B-13Jul2012-v4" } else if ( dataset == 22 ) { std::cout << "DoubleMu 2012C-24Aug2012-v1 DATASET\n"; //ls /data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesDataDoubleMuRun2012C-24Aug2012-v1/ | grep root | awk '{print "tree->AddFile(\"/data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesDataDoubleMuRun2012C-24Aug2012-v1/"$1"\");"}' >> scripts/htomm/skims/V00-01-10/chainDoubleMuRun2012C-24Aug2012-v1 #include "scripts/htomm/skims/V00-01-10/chainDoubleMuRun2012C-24Aug2012-v1" } else if ( dataset == 23 ) { std::cout << "DoubleMu 2012C-PromptReco-v2 DATASET\n"; //ls /data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesDataDoubleMuRun2012C-PromptReco-v2/ | grep root | awk '{print "tree->AddFile(\"/data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/NtuplesDataDoubleMuRun2012C-PromptReco-v2/"$1"\");"}' >> scripts/htomm/skims/V00-01-10/chainDoubleMuRun2012C-PromptReco-v2 #include "scripts/htomm/skims/V00-01-10/chainDoubleMuRun2012C-PromptReco-v2" } else { std::cout << "NO DATASET DEFINED!\n"; return; } // ======== DEFINE THE FILENAME ======== TString path = "/data/uftrig01b/digiovan/root/higgs/CMSSW_5_3_5/V00-01-10/"; TFile *newfile; if ( dataset == 0 ) path+= "NtuplesMCDYJetsToLL_M-50_TuneZ2Star_8TeV-madgraph-tarball_Summer12_DR53X-PU_S10_START53_V7A-v1/"; else if ( dataset == 1 ) path+= "NtuplesMCDYToMuMu_M-20_CT10_TuneZ2star_v2_8TeV-powheg-pythia6_Summer12_DR53X-PU_S10_START53_V7A-v1/"; else if ( dataset == 2 ) path+= "NtuplesMCTTJets_MassiveBinDECAY_TuneZ2star_8TeV-madgraph-tauola_Summer12_DR53X-PU_S10_START53_V7C-v1/"; else if ( dataset == 3 ) path+= "NtuplesMCDYToTauTau_M-20_CT10_TuneZ2star_8TeV-powheg-pythia6_Summer12_DR53X-PU_S10_START53_V7A-v1/"; else if ( dataset == 4 ) path+= "NtuplesMCWJetsToLNu_TuneZ2Star_8TeV-madgraph-tarball_Summer12_DR53X-PU_S10_START53_V7A-v2/"; else if ( dataset == 5 ) path+= "NtuplesMCWW_TuneZ2star_8TeV_pythia6_tauola_Summer12_DR53X-PU_S10_START53_V7A-v1/"; else if ( dataset == 6 ) path+= "NtuplesMCWZ_TuneZ2star_8TeV_pythia6_tauola_Summer12_DR53X-PU_S10_START53_V7A-v1/"; else if ( dataset == 7 ) path+= "NtuplesMCZZ_TuneZ2star_8TeV_pythia6_tauola_Summer12_DR53X-PU_S10_START53_V7A-v1/"; else if ( dataset == 8 ) path+= "NtuplesMCQCD_Pt_20_MuEnrichedPt_15_TuneZ2star_8TeV_pythia6_Summer12_DR53X-PU_S10_START53_V7A-v3/"; else if ( dataset == 9 ) path+= "NtuplesMCDY2JetsToLL_M-50_TuneZ2Star_8TeV-madgraph_Summer12_DR53X-PU_S10_START53_V7A-v1/"; else if ( dataset == 9990 ) path+="NtuplesMCDYJetsToLL_PtZ-50To70_TuneZ2star_8TeV-madgraph-tarball_Summer12_DR53X-PU_S10_START53_V7A-v1/"; else if ( dataset == 9990 ) path+="NtuplesMCDYJetsToLL_PtZ-70To100_TuneZ2star_8TeV-madgraph-tarball_Summer12_DR53X-PU_S10_START53_V7A-v2/"; else if ( dataset == 9992 ) path+="NtuplesMCDYJetsToLL_PtZ-100_TuneZ2star_8TeV-madgraph-tarball_Summer12_DR53X-PU_S10_START53_V7A-v2/"; else if ( dataset == 10 ) path+="NtuplesDataSingleMuRun2012A-13Jul2012-v1/"; else if ( dataset == 11 ) path+="NtuplesDataSingleMuRun2012A-recover-06Aug2012-v1/"; else if ( dataset == 12 ) path+="NtuplesDataSingleMuRun2012B-13Jul2012-v1/"; else if ( dataset == 13 ) path+="NtuplesDataSingleMuRun2012C-24Aug2012-v1/"; else if ( dataset == 14 ) path+="NtuplesDataSingleMuRun2012C-PromptReco-v2/"; else if ( dataset == 15 ) path+="NtuplesDataSingleMuRun2012D-PromptReco-v1/"; else if ( dataset == 20 ) path+="NtuplesDataDoubleMuRun2012A-13Jul2012-v1/"; else if ( dataset == 21 ) path+="NtuplesDataDoubleMuRun2012B-13Jul2012-v4/"; else if ( dataset == 22 ) path+="NtuplesDataDoubleMuRun2012C-24Aug2012-v1/"; else if ( dataset == 23 ) path+="NtuplesDataDoubleMuRun2012C-PromptReco-v2/"; else { std::cout << "NO DATASET DEFINED!\n"; return; } if (whichSkims == 0) path += "merged/"; else if (whichSkims == 1) path += "minimal/"; else if (whichSkims == 2) path += "complete/"; else { std::cout << "NO SKIMS TYPE DEFINED!\n"; return; } if ( dataset == 0 ) path += "DYJetsToLL_"; else if ( dataset == 1 ) path += "DYToMuMu_"; else if ( dataset == 2 ) path += "TTJets_"; else if ( dataset == 3 ) path += "DYToTauTau_"; else if ( dataset == 4 ) path += "WJetsToLNu_"; else if ( dataset == 5 ) path += "WW_"; else if ( dataset == 6 ) path += "WZ_"; else if ( dataset == 7 ) path += "ZZ_"; else if ( dataset == 8 ) path += "QCD_Pt_20_MuEnrichedPt_15_"; else if ( dataset == 9 ) path += "DY2JetsToLL_"; else if ( dataset == 9990 ) path += "DYJetsToLL_PtZ-50To70_"; else if ( dataset == 9990 ) path += "DYJetsToLL_PtZ-70To100_"; else if ( dataset == 9992 ) path += "DYJetsToLL_PtZ-100_"; else if ( dataset == 10 ) path += "SingleMuRun2012A-13Jul2012-v1_"; else if ( dataset == 11 ) path += "SingleMuRun2012A-recover-06Aug2012-v1_"; else if ( dataset == 12 ) path += "SingleMuRun2012B-13Jul2012-v1_"; else if ( dataset == 13 ) path += "SingleMuRun2012C-24Aug2012-v1_"; else if ( dataset == 14 ) path += "SingleMuRun2012C-PromptReco-v2_"; else if ( dataset == 15 ) path += "SingleMuRun2012D-PromptReco-v1_"; else if ( dataset == 20 ) path += "DoubleMuRun2012A-13Jul2012-v1_"; else if ( dataset == 21 ) path += "DoubleMuRun2012B-13Jul2012-v4_"; else if ( dataset == 22 ) path += "DoubleMuRun2012C-24Aug2012-v1_"; else if ( dataset == 23 ) path += "DoubleMuRun2012C-PromptReco-v2_"; else { std::cout << "NO DATASET DEFINED!\n"; return; } if (whichSkims == 0) newfile = new TFile(path+"merged.root","recreate"); else if (whichSkims == 1) newfile = new TFile(path+"minimal.root","recreate"); else if (whichSkims == 2) newfile = new TFile(path+"complete.root","recreate"); else { std::cout << "NO SKIMS TYPE DEFINED!\n"; return; } std::cout << "saving in file " << newfile -> GetName() << std::endl; TTree *newtree = tree->CloneTree(0); // ======== GET THE HANDLES FOR SKIMMING ======== float recoCandMass; tree->SetBranchAddress("recoCandMass", &recoCandMass); float vertexNormChiSquare, angleDiMuons; tree->SetBranchAddress("vertexNormChiSquare", &vertexNormChiSquare); tree->SetBranchAddress("angleDiMuons" , &angleDiMuons ); _MuonInfo reco1, reco2; tree->SetBranchAddress("reco1", &reco1); tree->SetBranchAddress("reco2", &reco2); // ======== PERFORM THE SKIMMING ======== cout<<"Loop over the " << tree->GetEntries() << " entries ...\n"; for (int iEvt=0; iEvt < tree->GetEntries(); iEvt++) { if ( (iEvt % 500000)==0 ) cout << "event " << iEvt << endl; tree -> GetEntry(iEvt); // additional selection cuts if (recoCandMass < 60 && whichSkims > 0) continue; //if (recoCandMass > 160 && whichSkims > 0) continue; if (vertexNormChiSquare > 10 && whichSkims > 0) continue; if (angleDiMuons > TMath::Pi()-0.02 && whichSkims > 0) continue; if (!isKinTight_2012_noAcc(reco1) && whichSkims > 1) continue; if (!isKinTight_2012_noAcc(reco2) && whichSkims > 1) continue; newtree->Fill(); } newtree->Print(); newtree->AutoSave(); std::cout << "new tree has " << newtree -> GetEntries() << std::endl; delete newfile; }
int main( int argc, const char* argv[] ){ // List of arguments: // 0: The executable itself // 1: The number of times JetMET is smeared (not smeared if equal to 1) // 2: The scale and type of JES shift (if fabs(x) < 0.5, shift by eta, else absolute // fixme: Depracated float JES_JetMET = 1.0; string xmlFileName = string ("./MyMassAnalysis.xml"); for (int i=1;i<argc;++i) { if (strncmp(argv[i],"-c",2)==0) xmlFileName = string(argv[i+1]); if (strncmp(argv[i],"-h",2)==0) { cout << " -c xm_config_file\n"; exit(1); } } cout<<"#########################"<<endl; cout<<"Beginning of the program"<<endl; cout<<"#########################"<<endl; ////////////////////// //Global variables ////////////////////// // GEN TH1F * histoGenTopRapidity1 = new TH1F("GenTopRapidity1", "GenTopRapidity1", 100, -5, 5); TH1F * histoGenTopRapidity2 = new TH1F("GenTopRapidity2", "GenTopRapidity2", 100, -5, 5); TH1F * histoGenTopMass1 = new TH1F("GenTopMass1", "GenTopMass1", 200, 0, 200); TH1F * histoGenTopMass2 = new TH1F("GenTopMass2", "GenTopMass2", 200, 0, 200); TH2F * histoGenTopMass1VsTopMass2 = new TH2F("GenTopMass1VsTopMass2", "GenTopMass1VsTopMass2", 200, 0, 200, 200, 0, 200); TH1F * histoGenDelta_y = new TH1F("GenDelta_y", "GenDelta_y", 400, -2, 2); TH1F * histoGenTTRapidity = new TH1F("GenTTRapidity", "GenTTRapidity", 500, -2.5, 2.5); TH1F * histoGenTTPt = new TH1F("GenTTPt", "GenTTPt", 250, 0, 250); TH1F * histoGenTTMass = new TH1F("GenTTMass", "GenTTMass", 100, 0, 1000); TH2F * histoGenDelta_yVsTTRapidity = new TH2F("GenDelta_yVsTTRapidity", "GenDelta_yVsTTRapidity", 10, -2, 2, 5, -2.5, 2.5); TH2F * histoGenDelta_yVsTTPt = new TH2F("GenDelta_yVsTTPt", "GenDelta_yVsTTPt", 10, -2, 2, 5, 0, 250); TH2F * histoGenDelta_yVsTTMass = new TH2F("GenDelta_yVsTTMass", "GenDelta_yVsTTMass", 10, -2, 2, 5, 0, 1000); TH1F * histoGenN_plusTTRapidity = new TH1F("GenN_plusTTRapidity", "GenN_plusTTRapidity", 20, -2.5, 2.5); histoGenN_plusTTRapidity->Sumw2(); TH1F * histoGenN_plusTTPt = new TH1F("GenN_plusTTPt", "GenN_plusTTPt", 20, 0, 250); histoGenN_plusTTPt->Sumw2(); TH1F * histoGenN_plusTTMass = new TH1F("GenN_plusTTMass", "GenN_plusTTMass", 20, 0, 1000); histoGenN_plusTTMass->Sumw2(); TH1F * histoGenN_minusTTRapidity = new TH1F("GenN_minusTTRapidity", "GenN_minusTTRapidity", 20, -2.5, 2.5); histoGenN_minusTTRapidity->Sumw2(); TH1F * histoGenN_minusTTPt = new TH1F("GenN_minusTTPt", "GenN_minusTTPt", 20, 0, 250); histoGenN_minusTTPt->Sumw2(); TH1F * histoGenN_minusTTMass = new TH1F("GenN_minusTTMass", "GenN_minusTTMass", 20, 0, 1000); histoGenN_minusTTMass->Sumw2(); TH1F * histoGenN_plusMinusN_minusTTRapidity = new TH1F("GenN_plusMinusN_minusTTRapidity", "GenN_plusMinusN_minusTTRapidity", 20, -2.5, 2.5); histoGenN_plusMinusN_minusTTRapidity->Sumw2(); TH1F * histoGenN_plusPlusN_minusTTRapidity = new TH1F("GenN_plusPlusN_minusTTRapidity", "GenN_plusPlusN_minusTTRapidity", 20, -2.5, 2.5); histoGenN_plusPlusN_minusTTRapidity->Sumw2(); TH1F * histoGenN_plusMinusN_minusTTPt = new TH1F("GenN_plusMinusN_minusTTPt", "GenN_plusMinusN_minusTTPt", 20, 0, 250); histoGenN_plusMinusN_minusTTPt->Sumw2(); TH1F * histoGenN_plusPlusN_minusTTPt = new TH1F("GenN_plusPlusN_minusTTPt", "GenN_plusPlusN_minusTTPt", 20, 0, 250); histoGenN_plusPlusN_minusTTPt->Sumw2(); TH1F * histoGenN_plusMinusN_minusTTMass = new TH1F("GenN_plusMinusN_minusTTMass", "GenN_plusMinusN_minusTTMass", 20, 0, 1000); histoGenN_plusMinusN_minusTTMass->Sumw2(); TH1F * histoGenN_plusPlusN_minusTTMass = new TH1F("GenN_plusPlusN_minusTTMass", "GenN_plusPlusN_minusTTMass", 20, 0, 1000); histoGenN_plusPlusN_minusTTMass->Sumw2(); TH1F * histoGenA_cTTRapidity = new TH1F("GenA_cTTRapidity", "GenA_cTTRapidity", 20, -2.5, 2.5); histoGenA_cTTRapidity->Sumw2(); TH1F * histoGenA_cTTPt = new TH1F("GenA_cTTPt", "GenA_cTTPt", 20, 0, 250); histoGenA_cTTPt->Sumw2(); TH1F * histoGenA_cTTMass = new TH1F("GenA_cTTMass", "GenA_cTTMass", 20, 0, 1000); histoGenA_cTTMass->Sumw2(); // Fine binning TH2F * histoFineBinning_GenDelta_yVsTTRapidity = new TH2F("FineBinning_GenDelta_yVsTTRapidity", "FineBinning_GenDelta_yVsTTRapidity", 200, -2, 2, 500, -2.5, 2.5); TH2F * histoFineBinning_GenDelta_yVsTTPt = new TH2F("FineBinning_GenDelta_yVsTTPt", "FineBinning_GenDelta_yVsTTPt", 200, -2, 2, 250, 0, 250); TH2F * histoFineBinning_GenDelta_yVsTTMass = new TH2F("FineBinning_GenDelta_yVsTTMass", "FineBinning_GenDelta_yVsTTMass", 200, -2, 2, 100, 0, 1000); TH1F * histoFineBinning_GenN_plusTTRapidity = new TH1F("FineBinning_GenN_plusTTRapidity", "FineBinning_GenN_plusTTRapidity", 500, -2.5, 2.5); histoFineBinning_GenN_plusTTRapidity->Sumw2(); TH1F * histoFineBinning_GenN_plusTTPt = new TH1F("FineBinning_GenN_plusTTPt", "FineBinning_GenN_plusTTPt", 250, 0, 250); histoFineBinning_GenN_plusTTPt->Sumw2(); TH1F * histoFineBinning_GenN_plusTTMass = new TH1F("FineBinning_GenN_plusTTMass", "FineBinning_GenN_plusTTMass", 100, 0, 1000); histoFineBinning_GenN_plusTTMass->Sumw2(); TH1F * histoFineBinning_GenN_minusTTRapidity = new TH1F("FineBinning_GenN_minusTTRapidity", "FineBinning_GenN_minusTTRapidity", 500, -2.5, 2.5); histoFineBinning_GenN_minusTTRapidity->Sumw2(); TH1F * histoFineBinning_GenN_minusTTPt = new TH1F("FineBinning_GenN_minusTTPt", "FineBinning_GenN_minusTTPt", 250, 0, 250); histoFineBinning_GenN_minusTTPt->Sumw2(); TH1F * histoFineBinning_GenN_minusTTMass = new TH1F("FineBinning_GenN_minusTTMass", "FineBinning_GenN_minusTTMass", 100, 0, 1000); histoFineBinning_GenN_minusTTMass->Sumw2(); TH1F * histoFineBinning_GenN_plusMinusN_minusTTRapidity = new TH1F("FineBinning_GenN_plusMinusN_minusTTRapidity", "FineBinning_GenN_plusMinusN_minusTTRapidity", 500, -2.5, 2.5); histoFineBinning_GenN_plusMinusN_minusTTRapidity->Sumw2(); TH1F * histoFineBinning_GenN_plusPlusN_minusTTRapidity = new TH1F("FineBinning_GenN_plusPlusN_minusTTRapidity", "FineBinning_GenN_plusPlusN_minusTTRapidity", 500, -2.5, 2.5); histoFineBinning_GenN_plusPlusN_minusTTRapidity->Sumw2(); TH1F * histoFineBinning_GenN_plusMinusN_minusTTPt = new TH1F("FineBinning_GenN_plusMinusN_minusTTPt", "FineBinning_GenN_plusMinusN_minusTTPt", 250, 0, 250); histoFineBinning_GenN_plusMinusN_minusTTPt->Sumw2(); TH1F * histoFineBinning_GenN_plusPlusN_minusTTPt = new TH1F("FineBinning_GenN_plusPlusN_minusTTPt", "FineBinning_GenN_plusPlusN_minusTTPt", 250, 0, 250); histoFineBinning_GenN_plusPlusN_minusTTPt->Sumw2(); TH1F * histoFineBinning_GenN_plusMinusN_minusTTMass = new TH1F("FineBinning_GenN_plusMinusN_minusTTMass", "FineBinning_GenN_plusMinusN_minusTTMass", 100, 0, 1000); histoFineBinning_GenN_plusMinusN_minusTTMass->Sumw2(); TH1F * histoFineBinning_GenN_plusPlusN_minusTTMass = new TH1F("FineBinning_GenN_plusPlusN_minusTTMass", "FineBinning_GenN_plusPlusN_minusTTMass", 100, 0, 1000); histoFineBinning_GenN_plusPlusN_minusTTMass->Sumw2(); TH1F * histoFineBinning_GenA_cTTRapidity = new TH1F("FineBinning_GenA_cTTRapidity", "FineBinning_GenA_cTTRapidity", 500, -2.5, 2.5); histoFineBinning_GenA_cTTRapidity->Sumw2(); TH1F * histoFineBinning_GenA_cTTPt = new TH1F("FineBinning_GenA_cTTPt", "FineBinning_GenA_cTTPt", 250, 0, 250); histoFineBinning_GenA_cTTPt->Sumw2(); TH1F * histoFineBinning_GenA_cTTMass = new TH1F("FineBinning_GenA_cTTMass", "FineBinning_GenA_cTTMass", 100, 0, 1000); histoFineBinning_GenA_cTTMass->Sumw2(); // RECO TH1F * histoRecoTopRapidity1 = new TH1F("RecoTopRapidity1", "RecoTopRapidity1", 100, -5, 5); TH1F * histoRecoTopRapidity2 = new TH1F("RecoTopRapidity2", "RecoTopRapidity2", 100, -5, 5); TH1F * histoRecoLeptonRapidity1 = new TH1F("RecoLeptonRapidity1", "RecoLeptonRapidity1", 100, -5, 5); TH1F * histoRecoLeptonRapidity2 = new TH1F("RecoLeptonRapidity2", "RecoLeptonRapidity2", 100, -5, 5); TH1F * histoRecoTopMass1 = new TH1F("RecoTopMass1", "RecoTopMass1", 300, 0, 300); TH1F * histoRecoTopMass2 = new TH1F("RecoTopMass2", "RecoTopMass2", 300, 0, 300); TH2F * histoRecoTopMass1VsTopMass2 = new TH2F("RecoTopMass1VsTopMass2", "RecoTopMass1VsTopMass2", 300, 0, 300, 300, 0, 300); TH1F * histoRecoDelta_y = new TH1F("RecoDelta_y", "RecoDelta_y", 400, -2, 2); TH1F * histoRecoTTRapidity = new TH1F("RecoTTRapidity", "RecoTTRapidity", 500, -2.5, 2.5); TH1F * histoRecoTTPt = new TH1F("RecoTTPt", "RecoTTPt", 250, 0, 250); TH1F * histoRecoTTMass = new TH1F("RecoTTMass", "RecoTTMass", 100, 0, 1000); TH2F * histoRecoDelta_yVsTTRapidity = new TH2F("RecoDelta_yVsTTRapidity", "RecoDelta_yVsTTRapidity", 10, -2, 2, 5, -2.5, 2.5); TH2F * histoRecoDelta_yVsTTPt = new TH2F("RecoDelta_yVsTTPt", "RecoDelta_yVsTTPt", 10, -2, 2, 5, 0, 250); TH2F * histoRecoDelta_yVsTTMass = new TH2F("RecoDelta_yVsTTMass", "RecoDelta_yVsTTMass", 10, -2, 2, 5, 0, 1000); TH1F * histoRecoN_plusTTRapidity = new TH1F("RecoN_plusTTRapidity", "RecoN_plusTTRapidity", 20, -2.5, 2.5); histoRecoN_plusTTRapidity->Sumw2(); TH1F * histoRecoN_plusTTPt = new TH1F("RecoN_plusTTPt", "RecoN_plusTTPt", 20, 0, 250); histoRecoN_plusTTPt->Sumw2(); TH1F * histoRecoN_plusTTMass = new TH1F("RecoN_plusTTMass", "RecoN_plusTTMass", 20, 0, 1000); histoRecoN_plusTTMass->Sumw2(); TH1F * histoRecoN_minusTTRapidity = new TH1F("RecoN_minusTTRapidity", "RecoN_minusTTRapidity", 20, -2.5, 2.5); histoRecoN_minusTTRapidity->Sumw2(); TH1F * histoRecoN_minusTTPt = new TH1F("RecoN_minusTTPt", "RecoN_minusTTPt", 20, 0, 250); histoRecoN_minusTTPt->Sumw2(); TH1F * histoRecoN_minusTTMass = new TH1F("RecoN_minusTTMass", "RecoN_minusTTMass", 20, 0, 1000); histoRecoN_minusTTMass->Sumw2(); TH1F * histoRecoN_plusMinusN_minusTTRapidity = new TH1F("RecoN_plusMinusN_minusTTRapidity", "RecoN_plusMinusN_minusTTRapidity", 20, -2.5, 2.5); histoRecoN_plusMinusN_minusTTRapidity->Sumw2(); TH1F * histoRecoN_plusPlusN_minusTTRapidity = new TH1F("RecoN_plusPlusN_minusTTRapidity", "RecoN_plusPlusN_minusTTRapidity", 20, -2.5, 2.5); histoRecoN_plusPlusN_minusTTRapidity->Sumw2(); TH1F * histoRecoN_plusMinusN_minusTTPt = new TH1F("RecoN_plusMinusN_minusTTPt", "RecoN_plusMinusN_minusTTPt", 20, 0, 250); histoRecoN_plusMinusN_minusTTPt->Sumw2(); TH1F * histoRecoN_plusPlusN_minusTTPt = new TH1F("RecoN_plusPlusN_minusTTPt", "RecoN_plusPlusN_minusTTPt", 20, 0, 250); histoRecoN_plusPlusN_minusTTPt->Sumw2(); TH1F * histoRecoN_plusMinusN_minusTTMass = new TH1F("RecoN_plusMinusN_minusTTMass", "RecoN_plusMinusN_minusTTMass", 20, 0, 1000); histoRecoN_plusMinusN_minusTTMass->Sumw2(); TH1F * histoRecoN_plusPlusN_minusTTMass = new TH1F("RecoN_plusPlusN_minusTTMass", "RecoN_plusPlusN_minusTTMass", 20, 0, 1000); histoRecoN_plusPlusN_minusTTMass->Sumw2(); TH1F * histoRecoA_cTTRapidity = new TH1F("RecoA_cTTRapidity", "RecoA_cTTRapidity", 20, -2.5, 2.5); histoRecoA_cTTRapidity->Sumw2(); TH1F * histoRecoA_cTTPt = new TH1F("RecoA_cTTPt", "RecoA_cTTPt", 20, 0, 250); histoRecoA_cTTPt->Sumw2(); TH1F * histoRecoA_cTTMass = new TH1F("RecoA_cTTMass", "RecoA_cTTMass", 20, 0, 1000); histoRecoA_cTTMass->Sumw2(); // Fine binning TH2F * histoFineBinning_RecoDelta_yVsTTRapidity = new TH2F("FineBinning_RecoDelta_yVsTTRapidity", "FineBinning_RecoDelta_yVsTTRapidity", 200, -2, 2, 500, -2.5, 2.5); TH2F * histoFineBinning_RecoDelta_yVsTTPt = new TH2F("FineBinning_RecoDelta_yVsTTPt", "FineBinning_RecoDelta_yVsTTPt", 200, -2, 2, 250, 0, 250); TH2F * histoFineBinning_RecoDelta_yVsTTMass = new TH2F("FineBinning_RecoDelta_yVsTTMass", "FineBinning_RecoDelta_yVsTTMass", 200, -2, 2, 100, 0, 1000); TH1F * histoFineBinning_RecoN_plusTTRapidity = new TH1F("FineBinning_RecoN_plusTTRapidity", "FineBinning_RecoN_plusTTRapidity", 500, -2.5, 2.5); histoFineBinning_RecoN_plusTTRapidity->Sumw2(); TH1F * histoFineBinning_RecoN_plusTTPt = new TH1F("FineBinning_RecoN_plusTTPt", "FineBinning_RecoN_plusTTPt", 250, 0, 250); histoFineBinning_RecoN_plusTTPt->Sumw2(); TH1F * histoFineBinning_RecoN_plusTTMass = new TH1F("FineBinning_RecoN_plusTTMass", "FineBinning_RecoN_plusTTMass", 100, 0, 1000); histoFineBinning_RecoN_plusTTMass->Sumw2(); TH1F * histoFineBinning_RecoN_minusTTRapidity = new TH1F("FineBinning_RecoN_minusTTRapidity", "FineBinning_RecoN_minusTTRapidity", 500, -2.5, 2.5); histoFineBinning_RecoN_minusTTRapidity->Sumw2(); TH1F * histoFineBinning_RecoN_minusTTPt = new TH1F("FineBinning_RecoN_minusTTPt", "FineBinning_RecoN_minusTTPt", 250, 0, 250); histoFineBinning_RecoN_minusTTPt->Sumw2(); TH1F * histoFineBinning_RecoN_minusTTMass = new TH1F("FineBinning_RecoN_minusTTMass", "FineBinning_RecoN_minusTTMass", 100, 0, 1000); histoFineBinning_RecoN_minusTTMass->Sumw2(); TH1F * histoFineBinning_RecoN_plusMinusN_minusTTRapidity = new TH1F("FineBinning_RecoN_plusMinusN_minusTTRapidity", "FineBinning_RecoN_plusMinusN_minusTTRapidity", 500, -2.5, 2.5); histoFineBinning_RecoN_plusMinusN_minusTTRapidity->Sumw2(); TH1F * histoFineBinning_RecoN_plusPlusN_minusTTRapidity = new TH1F("FineBinning_RecoN_plusPlusN_minusTTRapidity", "FineBinning_RecoN_plusPlusN_minusTTRapidity", 500, -2.5, 2.5); histoFineBinning_RecoN_plusPlusN_minusTTRapidity->Sumw2(); TH1F * histoFineBinning_RecoN_plusMinusN_minusTTPt = new TH1F("FineBinning_RecoN_plusMinusN_minusTTPt", "FineBinning_RecoN_plusMinusN_minusTTPt", 250, 0, 250); histoFineBinning_RecoN_plusMinusN_minusTTPt->Sumw2(); TH1F * histoFineBinning_RecoN_plusPlusN_minusTTPt = new TH1F("FineBinning_RecoN_plusPlusN_minusTTPt", "FineBinning_RecoN_plusPlusN_minusTTPt", 250, 0, 250); histoFineBinning_RecoN_plusPlusN_minusTTPt->Sumw2(); TH1F * histoFineBinning_RecoN_plusMinusN_minusTTMass = new TH1F("FineBinning_RecoN_plusMinusN_minusTTMass", "FineBinning_RecoN_plusMinusN_minusTTMass", 100, 0, 1000); histoFineBinning_RecoN_plusMinusN_minusTTMass->Sumw2(); TH1F * histoFineBinning_RecoN_plusPlusN_minusTTMass = new TH1F("FineBinning_RecoN_plusPlusN_minusTTMass", "FineBinning_RecoN_plusPlusN_minusTTMass", 100, 0, 1000); histoFineBinning_RecoN_plusPlusN_minusTTMass->Sumw2(); TH1F * histoFineBinning_RecoA_cTTRapidity = new TH1F("FineBinning_RecoA_cTTRapidity", "FineBinning_RecoA_cTTRapidity", 500, -2.5, 2.5); histoFineBinning_RecoA_cTTRapidity->Sumw2(); TH1F * histoFineBinning_RecoA_cTTPt = new TH1F("FineBinning_RecoA_cTTPt", "FineBinning_RecoA_cTTPt", 250, 0, 250); histoFineBinning_RecoA_cTTPt->Sumw2(); TH1F * histoFineBinning_RecoA_cTTMass = new TH1F("FineBinning_RecoA_cTTMass", "FineBinning_RecoA_cTTMass", 100, 0, 1000); histoFineBinning_RecoA_cTTMass->Sumw2(); // RECO vs GEN TH2F * histoRecoVsGenTopRapidity1 = new TH2F("RecoVsGenTopRapidity1", "RecoVsGenTopRapidity1", 100, -5, 5, 100, -5, 5); TH2F * histoRecoVsGenTopRapidity2 = new TH2F("RecoVsGenTopRapidity2", "RecoVsGenTopRapidity2", 100, -5, 5, 100, -5, 5); TH2F * histoRecoVsGenTopMass1 = new TH2F("RecoVsGenTopMass1", "RecoVsGenTopMass1", 300, 0, 300, 200, 0, 200); TH2F * histoRecoVsGenTopMass2 = new TH2F("RecoVsGenTopMass2", "RecoVsGenTopMass2", 300, 0, 300, 200, 0, 200); TH1F * histoRecoMinusGenDivGenTopRapidity1 = new TH1F("RecoMinusGenDivGenTopRapidity1", "RecoMinusGenDivGenTopRapidity1", 100, -3, 3); TH1F * histoRecoMinusGenDivGenTopRapidity2 = new TH1F("RecoMinusGenDivGenTopRapidity2", "RecoMinusGenDivGenTopRapidity2", 100, -3, 3); TH1F * histoRecoMinusGenDivGenLeptonRapidity1 = new TH1F("RecoMinusGenDivGenLeptonRapidity1", "RecoMinusGenDivGenLeptonRapidity1", 100, -3, 3); TH1F * histoRecoMinusGenDivGenLeptonRapidity2 = new TH1F("RecoMinusGenDivGenLeptonRapidity2", "RecoMinusGenDivGenLeptonRapidity2", 100, -3, 3); TH1F * histoRecoMinusGenDivGenTopMass1 = new TH1F("RecoMinusGenDivGenTopMass1", "RecoMinusGenDivGenTopMass1", 100, -3, 3); TH1F * histoRecoMinusGenDivGenTopMass2 = new TH1F("RecoMinusGenDivGenTopMass2", "RecoMinusGenDivGenTopMass2", 100, -3, 3); TH2F * histoFineBinning_RecoVsGenDelta_y = new TH2F("FineBinning_RecoVsGenDelta_y", "FineBinning_RecoVsGenDelta_y", 400, -2, 2, 400, -2, 2); // Migration Matrix TH2F * histoRecoVsGenDelta_y = new TH2F("RecoVsGenDelta_y", "RecoVsGenDelta_y", 8, -2, 2, 16, -2, 2); // Migration Matrix TH1F * histoRecoMinusGenDivGenDelta_y = new TH1F("RecoMinusGenDivGenDelta_y", "RecoMinusGenDivGenDelta_y", 100, -3, 3); TH2F * histoRecoVsGenTTRapidity = new TH2F("RecoVsGenTTRapidity", "RecoVsGenTTRapidity", 500, -2.5, 2.5, 500, -2.5, 2.5); TH1F * histoRecoMinusGenDivGenTTRapidity = new TH1F("RecoMinusGenDivGenTTRapidity", "RecoMinusGenDivGenTTRapidity", 100, -3, 3); TH2F * histoRecoVsGenTTPt = new TH2F("RecoVsGenTTPt", "RecoVsGenTTPt", 250, 0, 250, 250, 0, 250); TH1F * histoRecoMinusGenDivGenTTPt = new TH1F("RecoMinusGenDivGenTTPt", "RecoMinusGenDivGenTTPt", 100, -3, 3); TH2F * histoRecoVsGenTTMass = new TH2F("RecoVsGenTTMass", "RecoVsGenTTMass", 100, 0, 1000, 100, 0, 1000); TH1F * histoRecoMinusGenDivGenTTMass = new TH1F("RecoMinusGenDivGenTTMass", "RecoMinusGenDivGenTTMass", 100, -3, 3); TH1F * histoDelta_yEfficiencyN = new TH1F("Delta_yEfficiencyN", "Delta_yEfficiencyN", 10, -2, 2); TH1F * histoDelta_yEfficiencyD = new TH1F("Delta_yEfficiencyD", "Delta_yEfficiencyD", 10, -2, 2); TH1F * histoDelta_yEfficiency = new TH1F("Delta_yEfficiency", "Delta_yEfficiency", 10, -2, 2); TH2F * histoDelta_yVsTTRapidityEfficiency = new TH2F("Delta_yVsTTRapidityEfficiency", "Delta_yVsTTRapidityEfficiency", 10, -2, 2, 5, -2.5, 2.5); TH2F * histoDelta_yVsTTPtEfficiency = new TH2F("Delta_yVsTTPtEfficiency", "Delta_yVsTTPtEfficiency", 10, -2, 2, 5, 0, 250); TH2F * histoDelta_yVsTTMassEfficiency = new TH2F("Delta_yVsTTMassEfficiency", "Delta_yVsTTMassEfficiency", 10, -2, 2, 5, 0, 1000); // Fine binning TH1F * histoFineBinning_Delta_yEfficiencyN = new TH1F("FineBinning_Delta_yEfficiencyN", "FineBinning_Delta_yEfficiencyN", 200, -2, 2); TH1F * histoFineBinning_Delta_yEfficiencyD = new TH1F("FineBinning_Delta_yEfficiencyD", "FineBinning_Delta_yEfficiencyD", 200, -2, 2); TH1F * histoFineBinning_Delta_yEfficiency = new TH1F("FineBinning_Delta_yEfficiency", "FineBinning_Delta_yEfficiency", 200, -2, 2); TH2F * histoFineBinning_Delta_yVsTTRapidityEfficiency = new TH2F("FineBinning_Delta_yVsTTRapidityEfficiency", "FineBinning_Delta_yVsTTRapidityEfficiency", 200, -2, 2, 500, -2.5, 2.5); TH2F * histoFineBinning_Delta_yVsTTPtEfficiency = new TH2F("FineBinning_Delta_yVsTTPtEfficiency", "FineBinning_Delta_yVsTTPtEfficiency", 200, -2, 2, 250, 0, 250); TH2F * histoFineBinning_Delta_yVsTTMassEfficiency = new TH2F("FineBinning_Delta_yVsTTMassEfficiency", "FineBinning_Delta_yVsTTMassEfficiency", 200, -2, 2, 100, 0, 1000); vector < Dataset > datasets; DiLeptonSelection sel; float Luminosity = 0; // 0: MC - 1: Data - 2 Data & MC int DataType = 0; int verbosity = -1; // Analysis variables int step; //4-vectors vector < TLorentzVector > nu1; vector < TLorentzVector > nu2; // TLorentzVector lvTop1_aux; //TLorentzVector lvTop2_aux; ////////////////////// ////////////////////// // Initialisation ////////////////////// AnalysisEnvironmentLoader anaEL (xmlFileName); anaEL.LoadSamples (datasets); // now the list of datasets written in the xml file is known anaEL.LoadDiLeptonSelection (sel); // now the parameters for the selection are given to the selection anaEL.LoadGeneralInfo(DataType, Luminosity, verbosity ); float weight_MC; int nEvents; int firstEvent; int initialEvents; anaEL.LoadAnalysisInfo("Run", "firstEvent", firstEvent); anaEL.LoadAnalysisInfo("Run", "nEvents", nEvents); anaEL.LoadAnalysisInfo("Run", "initialEvents", initialEvents); string channelName; anaEL.LoadAnalysisInfo("MassAnalysis", "ChannelName", channelName); anaEL.LoadWeight (sel); // now the parameters for SFBweight are initialized (for b-tag!) //****************************************** //Load Scale Factors for lepton efficiencies //****************************************** sel.LoadElScaleFactors(); sel.LoadMuScaleFactors(); sel.InitJESUnc(); bool nonskimmed = false; TopTree::NTEvent * event = 0; TFile * TupleFile = new TFile("TupleFileSkimmed_TTbarSemileptonicPowheg.root","RECREATE"); float mttbar_rec, mttbar_gen; float diffysquare_rec, diffysquare_gen; float diffabseta_rec, diffabseta_gen; float weight; float pt_ttbar, pt_ttbar_gen; float pz_ttbar, pz_ttbar_gen; float eta_ttbar_rec, eta_ttbar_gen; float y_ttbar_rec, y_ttbar_gen; float diffabsy_rec, diffabsy_gen; TTree *tree = new TTree("Tuple","Tuple"); tree->Branch("mttbar_rec",&mttbar_rec,"mttbar_rec/F"); tree->Branch("mttbar_gen",&mttbar_gen,"mttbar_gen/F"); tree->Branch("diffysquare_rec",&diffysquare_rec,"diffysquare_rec/F"); tree->Branch("diffysquare_gen",&diffysquare_gen,"diffysquare_gen/F"); tree->Branch("diffabseta_rec",&diffabseta_rec,"diffabseta_rec/F"); tree->Branch("diffabseta_gen",&diffabseta_gen,"diffabseta_gen/F"); tree->Branch("weight",&weight,"weight/F"); tree->Branch("pt_ttbar",&pt_ttbar,"pt_ttbar/F"); tree->Branch("pt_ttbar_gen",&pt_ttbar_gen,"pt_ttbar_gen/F"); tree->Branch("pz_ttbar",&pz_ttbar,"pz_ttbar/F"); tree->Branch("pz_ttbar_gen",&pz_ttbar_gen,"pz_ttbar_gen/F"); tree->Branch("eta_ttbar_rec",&eta_ttbar_rec,"eta_ttbar_rec/F"); tree->Branch("eta_ttbar_gen",&eta_ttbar_gen,"eta_ttbar_gen/F"); tree->Branch("y_ttbar_rec",&y_ttbar_rec,"y_ttbar_rec/F"); tree->Branch("y_ttbar_gen",&y_ttbar_gen,"y_ttbar_gen/F"); tree->Branch("diffabsy_rec",&diffabsy_rec,"diffabsy_rec/F"); tree->Branch("diffabsy_gen",&diffabsy_gen,"diffabsy_gen/F"); ////////////////////// //LOOP OVER THE DATASETS ////////////////////// if(verbosity>0) { cout<<"#########################"<<endl; cout<<" Loop over the datasets "<<endl; cout<<"#########################"<<endl; } float num_mttbar_eff = 0.; float den_mttbar_eff = 0.; for (unsigned int d = 0; d < datasets.size (); d++) { weight_MC = datasets[d].NormFactor()*Luminosity; if(datasets[d].isData() == true) weight_MC = 1.; cout << "isDATA" << endl; AMWT amwt(anaEL, datasets[d].isData()); TString sample_name(datasets[d].Name()); bool isData = datasets[d].isData (); datasets[d].eventTree ()->SetBranchAddress ("NTEvent",&event); cout << "Sample : " << sample_name<< endl; cout << "Data : " << isData<< endl; unsigned int nEventsSample = (int) (datasets[d].eventTree ()->GetEntries ()); unsigned int endEventToRun; if (firstEvent>nEventsSample) firstEvent = nEventsSample; if ((nEvents==-1)||((nEvents+firstEvent)>nEventsSample)) endEventToRun = nEventsSample; else endEventToRun = nEvents+firstEvent; cout << "Events to run: number / first / last / all: " << endEventToRun-firstEvent << " / " << firstEvent << " / " << endEventToRun << " / " << nEventsSample << endl; // Standard parameters for doFullSelection: bool applyEEScale = false; float EEScaleParam = 1.; bool applyEEResol = false; float EEResolParam = 1.; bool applyMEScale = false; float MEScaleParam = 1.; bool applyMEResol = false; float MEResolParam = 1.; bool applyMETS = false; float METScale = 1.; bool applyJES = false; float JESParam = 1.; bool applyJER = false; float JERFactor = 0.; ////////////////////// //LOOP OVER THE EVENTS ////////////////////// float N_plus_reco = 0; float N_minus_reco = 0; float N_plus_gen = 0; float N_minus_gen = 0; mttbar_rec = 0; mttbar_gen = 0; diffysquare_rec = 0; diffysquare_gen = 0; diffabseta_rec = 0; diffabseta_gen = 0; weight = weight_MC; pt_ttbar = 0; pt_ttbar_gen = 0; pz_ttbar = 0; pz_ttbar_gen = 0; eta_ttbar_rec = 0; eta_ttbar_gen = 0; y_ttbar_rec = 0; y_ttbar_gen = 0; diffabsy_rec = 0; diffabsy_gen = 0; for (unsigned int ievt = firstEvent; ievt < endEventToRun; ievt++) { // for (unsigned int ievt = 0; ievt < 10; ievt++) { datasets[d].eventTree ()->GetEntry (ievt); if(ievt%1000 == 0) cout << "number of processed events " << ievt << endl; if (verbosity >= 1) cout << "Event : "<< event->runNb<<" , " << event->lumiblock <<" , " << event->eventNb<<endl; if(!(event->TMEME == 10010 || event->TMEME == 10001 || event->TMEME == 1 || event->TMEME == 10 || event->TMEME == 10000 || event->TMEME == 11000 || event->TMEME == 10100 )) continue; string candType; vector<NTElectron> candElec; vector<NTMuon> candMuon; //Load event for the selection sel.LoadEvent(event); int finalCut = sel.doFullSelection(&(datasets[d]), channelName, false, /*print*/ verbosity, false, false, -1., -1., applyJES, JESParam, applyEEScale, EEScaleParam, applyEEResol, EEResolParam, applyMEScale, MEScaleParam, applyJER, JERFactor, applyMETS, METScale); TLorentzVector lvTop1_gen; TLorentzVector lvTop2_gen; TLorentzVector lvTop1plusTop2_gen; float yt_gen = 0.; float ytbar_gen = 0.; float Delta_y_gen = 0.; if(datasets[d].Name() == "TTJets_Sig"){ lvTop1_gen = (event->topAndDecays)[0].p4_t_gen; lvTop2_gen = (event->topAndDecays)[1].p4_t_gen; lvTop1plusTop2_gen = lvTop1_gen + lvTop2_gen; ///////////////////////// //// GENERATOR LEVEL //// ///////////////////////// histoGenTopRapidity1->Fill(lvTop1_gen.Rapidity()); histoGenTopRapidity2->Fill(lvTop2_gen.Rapidity()); histoGenTopMass1->Fill(lvTop1_gen.M()); histoGenTopMass2->Fill(lvTop2_gen.M()); histoGenTopMass1VsTopMass2->Fill(lvTop1_gen.M(),lvTop2_gen.M()); yt_gen = lvTop1_gen.Rapidity(); if(yt_gen<0.) yt_gen = (-1)*yt_gen; ytbar_gen = lvTop2_gen.Rapidity(); if(ytbar_gen<0.) ytbar_gen = (-1)*ytbar_gen; Delta_y_gen = yt_gen - ytbar_gen; // cout << "Delta_y_gen:" << Delta_y_gen << endl; histoGenDelta_y->Fill(Delta_y_gen); histoDelta_yEfficiencyD->Fill(Delta_y_gen); histoFineBinning_Delta_yEfficiencyD->Fill(Delta_y_gen); if(Delta_y_gen>0.){ N_plus_gen++; histoGenN_plusTTRapidity->Fill(lvTop1plusTop2_gen.Rapidity()); histoGenN_plusTTPt->Fill(lvTop1plusTop2_gen.Perp()); histoGenN_plusTTMass->Fill(lvTop1plusTop2_gen.M()); histoFineBinning_GenN_plusTTRapidity->Fill(lvTop1plusTop2_gen.Rapidity()); histoFineBinning_GenN_plusTTPt->Fill(lvTop1plusTop2_gen.Perp()); histoFineBinning_GenN_plusTTMass->Fill(lvTop1plusTop2_gen.M()); } if(Delta_y_gen<0.){ N_minus_gen++; histoGenN_minusTTRapidity->Fill(lvTop1plusTop2_gen.Rapidity()); histoGenN_minusTTPt->Fill(lvTop1plusTop2_gen.Perp()); histoGenN_minusTTMass->Fill(lvTop1plusTop2_gen.M()); histoFineBinning_GenN_minusTTRapidity->Fill(lvTop1plusTop2_gen.Rapidity()); histoFineBinning_GenN_minusTTPt->Fill(lvTop1plusTop2_gen.Perp()); histoFineBinning_GenN_minusTTMass->Fill(lvTop1plusTop2_gen.M()); } histoGenTTRapidity->Fill(lvTop1plusTop2_gen.Rapidity()); histoGenTTPt->Fill(lvTop1plusTop2_gen.Perp()); histoGenTTMass->Fill(lvTop1plusTop2_gen.M()); histoGenDelta_yVsTTRapidity->Fill(Delta_y_gen, lvTop1plusTop2_gen.Rapidity()); histoGenDelta_yVsTTPt->Fill(Delta_y_gen, lvTop1plusTop2_gen.Perp()); histoGenDelta_yVsTTMass->Fill(Delta_y_gen, lvTop1plusTop2_gen.M()); histoFineBinning_GenDelta_yVsTTRapidity->Fill(Delta_y_gen, lvTop1plusTop2_gen.Rapidity()); histoFineBinning_GenDelta_yVsTTPt->Fill(Delta_y_gen, lvTop1plusTop2_gen.Perp()); histoFineBinning_GenDelta_yVsTTMass->Fill(Delta_y_gen, lvTop1plusTop2_gen.M()); if(nonskimmed == true){ mttbar_gen = lvTop1plusTop2_gen.M(); diffysquare_gen = yt_gen*yt_gen - ytbar_gen*ytbar_gen; diffabseta_gen = fabs(lvTop1_gen.Eta()) - fabs(lvTop2_gen.Eta()); pt_ttbar_gen = lvTop1plusTop2_gen.Perp(); pz_ttbar_gen = lvTop1plusTop2_gen.Pz(); eta_ttbar_gen = lvTop1plusTop2_gen.Eta(); y_ttbar_gen = lvTop1plusTop2_gen.Rapidity(); diffabsy_gen = fabs(lvTop1_gen.Rapidity()) - fabs(lvTop2_gen.Rapidity()); } } if (finalCut >6) { if(nonskimmed == false){ if(datasets[d].Name() == "TTJets_Sig"){ mttbar_gen = lvTop1plusTop2_gen.M(); diffysquare_gen = yt_gen*yt_gen - ytbar_gen*ytbar_gen; diffabseta_gen = fabs(lvTop1_gen.Eta()) - fabs(lvTop2_gen.Eta()); pt_ttbar_gen = lvTop1plusTop2_gen.Perp(); pz_ttbar_gen = lvTop1plusTop2_gen.Pz(); eta_ttbar_gen = lvTop1plusTop2_gen.Eta(); y_ttbar_gen = lvTop1plusTop2_gen.Rapidity(); diffabsy_gen = fabs(lvTop1_gen.Rapidity()) - fabs(lvTop2_gen.Rapidity()); } } sel.GetLeptonPair(candMuon, candElec, candType); for(unsigned int i=0; i<candMuon.size(); i++){ if(candMuon[i].Charge == +1) histoRecoLeptonRapidity1->Fill(candMuon[i].p4.Rapidity()); if(candMuon[i].Charge == -1) histoRecoLeptonRapidity2->Fill(candMuon[i].p4.Rapidity()); } for(unsigned int j=0; j<candElec.size(); j++){ if(candElec[j].Charge == +1) histoRecoLeptonRapidity1->Fill(candElec[j].p4.Rapidity()); if(candElec[j].Charge == -1) histoRecoLeptonRapidity2->Fill(candElec[j].p4.Rapidity()); } TLorentzVector lvTop1_reco; TLorentzVector lvTop2_reco; TLorentzVector lvTop1plusTop2_reco; TopMassVariables * tmv = amwt.findMass(sel, lvTop1_reco, lvTop2_reco); lvTop1plusTop2_reco = lvTop1_reco + lvTop2_reco; //////////////////// /// RECO LEVEL ///// //////////////////// histoRecoTopRapidity1->Fill(lvTop1_reco.Rapidity()); histoRecoTopRapidity2->Fill(lvTop2_reco.Rapidity()); histoRecoTopMass1->Fill(lvTop1_reco.M()); histoRecoTopMass2->Fill(lvTop2_reco.M()); histoRecoTopMass1VsTopMass2->Fill(lvTop1_reco.M(),lvTop2_reco.M()); float yt_reco = lvTop1_reco.Rapidity(); if(yt_reco<0.) yt_reco = (-1)*yt_reco; float ytbar_reco = lvTop2_reco.Rapidity(); if(ytbar_reco<0.) ytbar_reco = (-1)*ytbar_reco; float Delta_y_reco = yt_reco - ytbar_reco; // cout << "Delta_y_reco:" << Delta_y_reco << endl; histoRecoDelta_y->Fill(Delta_y_reco); histoDelta_yEfficiencyN->Fill(Delta_y_reco); histoFineBinning_Delta_yEfficiencyN->Fill(Delta_y_reco); if(Delta_y_reco>0.){ N_plus_reco++; histoRecoN_plusTTRapidity->Fill(lvTop1plusTop2_reco.Rapidity()); histoRecoN_plusTTPt->Fill(lvTop1plusTop2_reco.Perp()); histoRecoN_plusTTMass->Fill(lvTop1plusTop2_reco.M()); histoFineBinning_RecoN_plusTTRapidity->Fill(lvTop1plusTop2_reco.Rapidity()); histoFineBinning_RecoN_plusTTPt->Fill(lvTop1plusTop2_reco.Perp()); histoFineBinning_RecoN_plusTTMass->Fill(lvTop1plusTop2_reco.M()); } if(Delta_y_reco<0.){ N_minus_reco++; histoRecoN_minusTTRapidity->Fill(lvTop1plusTop2_reco.Rapidity()); histoRecoN_minusTTPt->Fill(lvTop1plusTop2_reco.Perp()); histoRecoN_minusTTMass->Fill(lvTop1plusTop2_reco.M()); histoFineBinning_RecoN_minusTTRapidity->Fill(lvTop1plusTop2_reco.Rapidity()); histoFineBinning_RecoN_minusTTPt->Fill(lvTop1plusTop2_reco.Perp()); histoFineBinning_RecoN_minusTTMass->Fill(lvTop1plusTop2_reco.M()); } histoRecoTTRapidity->Fill(lvTop1plusTop2_reco.Rapidity()); histoRecoTTPt->Fill(lvTop1plusTop2_reco.Perp()); histoRecoTTMass->Fill(lvTop1plusTop2_reco.M()); histoRecoDelta_yVsTTRapidity->Fill(Delta_y_reco, lvTop1plusTop2_reco.Rapidity()); histoRecoDelta_yVsTTPt->Fill(Delta_y_reco, lvTop1plusTop2_reco.Perp()); histoRecoDelta_yVsTTMass->Fill(Delta_y_reco, lvTop1plusTop2_reco.M()); histoFineBinning_RecoDelta_yVsTTRapidity->Fill(Delta_y_reco, lvTop1plusTop2_reco.Rapidity()); histoFineBinning_RecoDelta_yVsTTPt->Fill(Delta_y_reco, lvTop1plusTop2_reco.Perp()); histoFineBinning_RecoDelta_yVsTTMass->Fill(Delta_y_reco, lvTop1plusTop2_reco.M()); if(nonskimmed == false){ mttbar_rec = lvTop1plusTop2_reco.M(); diffysquare_rec = yt_reco*yt_reco - ytbar_reco*ytbar_reco; diffabseta_rec = fabs(lvTop1_reco.Eta()) - fabs(lvTop2_reco.Eta()); pt_ttbar = lvTop1plusTop2_reco.Perp(); pz_ttbar = lvTop1plusTop2_reco.Pz(); eta_ttbar_rec = lvTop1plusTop2_reco.Eta(); y_ttbar_rec = lvTop1plusTop2_reco.Rapidity(); diffabsy_rec = fabs(lvTop1_reco.Rapidity()) - fabs(lvTop2_reco.Rapidity()); } //////////////////////// // RECO VS GEN LEVEL /// //////////////////////// if(datasets[d].Name() == "TTJets_Sig"){ histoRecoVsGenTopRapidity1->Fill(lvTop1_reco.Rapidity(), lvTop1_gen.Rapidity()); histoRecoVsGenTopRapidity2->Fill(lvTop2_reco.Rapidity(), lvTop2_gen.Rapidity()); histoRecoVsGenTopMass1->Fill(lvTop1_reco.M(), lvTop1_gen.M()); histoRecoVsGenTopMass2->Fill(lvTop2_reco.M(), lvTop2_gen.M()); histoRecoMinusGenDivGenTopRapidity1->Fill((lvTop1_reco.Rapidity() - lvTop1_gen.Rapidity())/lvTop1_gen.Rapidity()); histoRecoMinusGenDivGenTopRapidity2->Fill((lvTop2_reco.Rapidity() - lvTop2_gen.Rapidity())/lvTop2_gen.Rapidity()); for(unsigned int i=0; i<candMuon.size(); i++){ if(candMuon[i].Charge == +1) histoRecoMinusGenDivGenLeptonRapidity1->Fill((candMuon[i].p4.Rapidity() - lvTop1_gen.Rapidity())/lvTop1_gen.Rapidity()); if(candMuon[i].Charge == -1) histoRecoMinusGenDivGenLeptonRapidity2->Fill((candMuon[i].p4.Rapidity() - lvTop2_gen.Rapidity())/lvTop2_gen.Rapidity()); } for(unsigned int j=0; j<candElec.size(); j++){ if(candElec[j].Charge == +1) histoRecoMinusGenDivGenLeptonRapidity1->Fill((candElec[j].p4.Rapidity() - lvTop1_gen.Rapidity())/lvTop1_gen.Rapidity()); if(candElec[j].Charge == -1) histoRecoMinusGenDivGenLeptonRapidity2->Fill((candElec[j].p4.Rapidity() - lvTop2_gen.Rapidity())/lvTop2_gen.Rapidity()); } histoRecoMinusGenDivGenTopMass1->Fill((lvTop1_reco.M() - lvTop1_gen.M())/lvTop1_gen.M()); histoRecoMinusGenDivGenTopMass2->Fill((lvTop2_reco.M() - lvTop2_gen.M())/lvTop2_gen.M()); histoRecoVsGenDelta_y->Fill(Delta_y_reco, Delta_y_gen); histoFineBinning_RecoVsGenDelta_y->Fill(Delta_y_reco, Delta_y_gen); histoRecoMinusGenDivGenDelta_y->Fill((Delta_y_reco - Delta_y_gen)/Delta_y_gen); histoRecoVsGenTTRapidity->Fill(lvTop1plusTop2_reco.Rapidity(),lvTop1plusTop2_gen.Rapidity()); histoRecoMinusGenDivGenTTRapidity->Fill((lvTop1plusTop2_reco.Rapidity() - lvTop1plusTop2_gen.Rapidity())/lvTop1plusTop2_gen.Rapidity()); histoRecoVsGenTTPt->Fill(lvTop1plusTop2_reco.Perp(),lvTop1plusTop2_gen.Perp()); histoRecoMinusGenDivGenTTPt->Fill((lvTop1plusTop2_reco.Perp() - lvTop1plusTop2_gen.Perp())/lvTop1plusTop2_gen.Perp()); histoRecoVsGenTTMass->Fill(lvTop1plusTop2_reco.M(),lvTop1plusTop2_gen.M()); histoRecoMinusGenDivGenTTMass->Fill((lvTop1plusTop2_reco.M() - lvTop1plusTop2_gen.M())/lvTop1plusTop2_gen.M()); } // tmv->printAll(); delete tmv; if(nonskimmed == false && mttbar_rec > 60.){ tree->Fill(); num_mttbar_eff += weight_MC;} if(nonskimmed == false) den_mttbar_eff += weight_MC; } if(nonskimmed == true) tree->Fill(); } // end of loop over evts float A_C_reco = (N_plus_reco - N_minus_reco)/(N_plus_reco + N_minus_reco); float A_C_gen = (N_plus_gen - N_minus_gen)/(N_plus_gen + N_minus_gen); cout << "A_C_gen:" << A_C_gen << endl; cout << "A_C_reco:" << A_C_reco << endl; histoGenN_plusMinusN_minusTTRapidity->Add(histoGenN_plusTTRapidity); histoGenN_plusMinusN_minusTTRapidity->Add(histoGenN_minusTTRapidity,-1); histoGenN_plusPlusN_minusTTRapidity->Add(histoGenN_plusTTRapidity); histoGenN_plusPlusN_minusTTRapidity->Add(histoGenN_minusTTRapidity); histoGenA_cTTRapidity->Divide(histoGenN_plusMinusN_minusTTRapidity, histoGenN_plusPlusN_minusTTRapidity); histoGenN_plusMinusN_minusTTPt->Add(histoGenN_plusTTPt); histoGenN_plusMinusN_minusTTPt->Add(histoGenN_minusTTPt,-1); histoGenN_plusPlusN_minusTTPt->Add(histoGenN_plusTTPt); histoGenN_plusPlusN_minusTTPt->Add(histoGenN_minusTTPt); histoGenA_cTTPt->Divide(histoGenN_plusMinusN_minusTTPt, histoGenN_plusPlusN_minusTTPt); histoGenN_plusMinusN_minusTTMass->Add(histoGenN_plusTTMass); histoGenN_plusMinusN_minusTTMass->Add(histoGenN_minusTTMass,-1); histoGenN_plusPlusN_minusTTMass->Add(histoGenN_plusTTMass); histoGenN_plusPlusN_minusTTMass->Add(histoGenN_minusTTMass); histoGenA_cTTMass->Divide(histoGenN_plusMinusN_minusTTMass, histoGenN_plusPlusN_minusTTMass); histoRecoN_plusMinusN_minusTTRapidity->Add(histoRecoN_plusTTRapidity); histoRecoN_plusMinusN_minusTTRapidity->Add(histoRecoN_minusTTRapidity,-1); histoRecoN_plusPlusN_minusTTRapidity->Add(histoRecoN_plusTTRapidity); histoRecoN_plusPlusN_minusTTRapidity->Add(histoRecoN_minusTTRapidity); histoRecoA_cTTRapidity->Divide(histoRecoN_plusMinusN_minusTTRapidity, histoRecoN_plusPlusN_minusTTRapidity); histoRecoN_plusMinusN_minusTTPt->Add(histoRecoN_plusTTPt); histoRecoN_plusMinusN_minusTTPt->Add(histoRecoN_minusTTPt,-1); histoRecoN_plusPlusN_minusTTPt->Add(histoRecoN_plusTTPt); histoRecoN_plusPlusN_minusTTPt->Add(histoRecoN_minusTTPt); histoRecoA_cTTPt->Divide(histoRecoN_plusMinusN_minusTTPt, histoRecoN_plusPlusN_minusTTPt); histoRecoN_plusMinusN_minusTTMass->Add(histoRecoN_plusTTMass); histoRecoN_plusMinusN_minusTTMass->Add(histoRecoN_minusTTMass,-1); histoRecoN_plusPlusN_minusTTMass->Add(histoRecoN_plusTTMass); histoRecoN_plusPlusN_minusTTMass->Add(histoRecoN_minusTTMass); histoRecoA_cTTMass->Divide(histoRecoN_plusMinusN_minusTTMass, histoRecoN_plusPlusN_minusTTMass); histoFineBinning_GenN_plusMinusN_minusTTRapidity->Add(histoFineBinning_GenN_plusTTRapidity); histoFineBinning_GenN_plusMinusN_minusTTRapidity->Add(histoFineBinning_GenN_minusTTRapidity,-1); histoFineBinning_GenN_plusPlusN_minusTTRapidity->Add(histoFineBinning_GenN_plusTTRapidity); histoFineBinning_GenN_plusPlusN_minusTTRapidity->Add(histoFineBinning_GenN_minusTTRapidity); histoFineBinning_GenA_cTTRapidity->Divide(histoFineBinning_GenN_plusMinusN_minusTTRapidity, histoFineBinning_GenN_plusPlusN_minusTTRapidity); histoFineBinning_GenN_plusMinusN_minusTTPt->Add(histoFineBinning_GenN_plusTTPt); histoFineBinning_GenN_plusMinusN_minusTTPt->Add(histoFineBinning_GenN_minusTTPt,-1); histoFineBinning_GenN_plusPlusN_minusTTPt->Add(histoFineBinning_GenN_plusTTPt); histoFineBinning_GenN_plusPlusN_minusTTPt->Add(histoFineBinning_GenN_minusTTPt); histoFineBinning_GenA_cTTPt->Divide(histoFineBinning_GenN_plusMinusN_minusTTPt, histoFineBinning_GenN_plusPlusN_minusTTPt); histoFineBinning_GenN_plusMinusN_minusTTMass->Add(histoFineBinning_GenN_plusTTMass); histoFineBinning_GenN_plusMinusN_minusTTMass->Add(histoFineBinning_GenN_minusTTMass,-1); histoFineBinning_GenN_plusPlusN_minusTTMass->Add(histoFineBinning_GenN_plusTTMass); histoFineBinning_GenN_plusPlusN_minusTTMass->Add(histoFineBinning_GenN_minusTTMass); histoFineBinning_GenA_cTTMass->Divide(histoFineBinning_GenN_plusMinusN_minusTTMass, histoFineBinning_GenN_plusPlusN_minusTTMass); histoFineBinning_RecoN_plusMinusN_minusTTRapidity->Add(histoFineBinning_RecoN_plusTTRapidity); histoFineBinning_RecoN_plusMinusN_minusTTRapidity->Add(histoFineBinning_RecoN_minusTTRapidity,-1); histoFineBinning_RecoN_plusPlusN_minusTTRapidity->Add(histoFineBinning_RecoN_plusTTRapidity); histoFineBinning_RecoN_plusPlusN_minusTTRapidity->Add(histoFineBinning_RecoN_minusTTRapidity); histoFineBinning_RecoA_cTTRapidity->Divide(histoFineBinning_RecoN_plusMinusN_minusTTRapidity, histoFineBinning_RecoN_plusPlusN_minusTTRapidity); histoFineBinning_RecoN_plusMinusN_minusTTPt->Add(histoFineBinning_RecoN_plusTTPt); histoFineBinning_RecoN_plusMinusN_minusTTPt->Add(histoFineBinning_RecoN_minusTTPt,-1); histoFineBinning_RecoN_plusPlusN_minusTTPt->Add(histoFineBinning_RecoN_plusTTPt); histoFineBinning_RecoN_plusPlusN_minusTTPt->Add(histoFineBinning_RecoN_minusTTPt); histoFineBinning_RecoA_cTTPt->Divide(histoFineBinning_RecoN_plusMinusN_minusTTPt, histoFineBinning_RecoN_plusPlusN_minusTTPt); histoFineBinning_RecoN_plusMinusN_minusTTMass->Add(histoFineBinning_RecoN_plusTTMass); histoFineBinning_RecoN_plusMinusN_minusTTMass->Add(histoFineBinning_RecoN_minusTTMass,-1); histoFineBinning_RecoN_plusPlusN_minusTTMass->Add(histoFineBinning_RecoN_plusTTMass); histoFineBinning_RecoN_plusPlusN_minusTTMass->Add(histoFineBinning_RecoN_minusTTMass); histoFineBinning_RecoA_cTTMass->Divide(histoFineBinning_RecoN_plusMinusN_minusTTMass, histoFineBinning_RecoN_plusPlusN_minusTTMass); histoDelta_yEfficiency->Divide(histoDelta_yEfficiencyN, histoDelta_yEfficiencyD); histoFineBinning_Delta_yEfficiency->Divide(histoFineBinning_Delta_yEfficiencyN, histoFineBinning_Delta_yEfficiencyD); for (unsigned int bin_index1 = 1; bin_index1 < 11; bin_index1++) { for (unsigned int bin_index2 = 1; bin_index2 < 6; bin_index2++) { float value = histoRecoDelta_yVsTTRapidity->GetBinContent(bin_index1,bin_index2)/histoGenDelta_yVsTTRapidity->GetBinContent(bin_index1,bin_index2); histoDelta_yVsTTRapidityEfficiency->SetBinContent(bin_index1, bin_index2, value); float value_fb = histoFineBinning_RecoDelta_yVsTTRapidity->GetBinContent(bin_index1,bin_index2)/histoFineBinning_GenDelta_yVsTTRapidity->GetBinContent(bin_index1,bin_index2); histoFineBinning_Delta_yVsTTRapidityEfficiency->SetBinContent(bin_index1, bin_index2, value_fb); } } for (unsigned int bin_index1 = 1; bin_index1 < 11; bin_index1++) { for (unsigned int bin_index2 = 1; bin_index2 < 6; bin_index2++) { float value = histoRecoDelta_yVsTTPt->GetBinContent(bin_index1,bin_index2)/histoGenDelta_yVsTTPt->GetBinContent(bin_index1,bin_index2); histoDelta_yVsTTPtEfficiency->SetBinContent(bin_index1, bin_index2, value); float value_fb = histoFineBinning_RecoDelta_yVsTTPt->GetBinContent(bin_index1,bin_index2)/histoFineBinning_GenDelta_yVsTTPt->GetBinContent(bin_index1,bin_index2); histoFineBinning_Delta_yVsTTPtEfficiency->SetBinContent(bin_index1, bin_index2, value_fb); } } for (unsigned int bin_index1 = 1; bin_index1 < 11; bin_index1++) { for (unsigned int bin_index2 = 1; bin_index2 < 6; bin_index2++) { float value = histoRecoDelta_yVsTTMass->GetBinContent(bin_index1,bin_index2)/histoGenDelta_yVsTTMass->GetBinContent(bin_index1,bin_index2); histoDelta_yVsTTMassEfficiency->SetBinContent(bin_index1, bin_index2, value); float value_fb = histoFineBinning_RecoDelta_yVsTTPt->GetBinContent(bin_index1,bin_index2)/histoFineBinning_GenDelta_yVsTTPt->GetBinContent(bin_index1,bin_index2); histoFineBinning_Delta_yVsTTPtEfficiency->SetBinContent(bin_index1, bin_index2, value_fb); } } } // end of loop over the datasets // if(verbosity>0) { cout<<"#########################"<<endl; cout<<" End of the program "<<endl; cout<<"#########################"<<endl; // } tree->Print(); TupleFile->Write(); TupleFile->Close(); TFile * fileCA = new TFile("ChargeAsymmetryResults_Skimmed_TTbarSemileptonicPowheg.root","RECREATE"); // fileCA->cd(); // GEN histoGenTopRapidity1->Write(); histoGenTopRapidity2->Write(); histoGenTopMass1->Write(); histoGenTopMass2->Write(); histoGenTopMass1VsTopMass2->Write(); histoGenDelta_y->Write(); histoGenTTRapidity->Write(); histoGenTTPt->Write(); histoGenTTMass->Write(); histoGenDelta_yVsTTRapidity->Write(); histoGenDelta_yVsTTPt->Write(); histoGenDelta_yVsTTMass->Write(); histoGenN_plusTTRapidity->Write(); histoGenN_plusTTPt->Write(); histoGenN_plusTTMass->Write(); histoGenN_minusTTRapidity->Write(); histoGenN_minusTTPt->Write(); histoGenN_minusTTMass->Write(); histoGenN_plusMinusN_minusTTRapidity->Write(); histoGenN_plusPlusN_minusTTRapidity->Write(); histoGenN_plusMinusN_minusTTPt->Write(); histoGenN_plusPlusN_minusTTPt->Write(); histoGenN_plusMinusN_minusTTMass->Write(); histoGenN_plusPlusN_minusTTMass->Write(); histoGenA_cTTRapidity->Write(); histoGenA_cTTPt->Write(); histoGenA_cTTMass->Write(); histoFineBinning_GenDelta_yVsTTRapidity->Write(); histoFineBinning_GenDelta_yVsTTPt->Write(); histoFineBinning_GenDelta_yVsTTMass->Write(); histoFineBinning_GenN_plusTTRapidity->Write(); histoFineBinning_GenN_plusTTPt->Write(); histoFineBinning_GenN_plusTTMass->Write(); histoFineBinning_GenN_minusTTRapidity->Write(); histoFineBinning_GenN_minusTTPt->Write(); histoFineBinning_GenN_minusTTMass->Write(); histoFineBinning_GenN_plusMinusN_minusTTRapidity->Write(); histoFineBinning_GenN_plusPlusN_minusTTRapidity->Write(); histoFineBinning_GenN_plusMinusN_minusTTPt->Write(); histoFineBinning_GenN_plusPlusN_minusTTPt->Write(); histoFineBinning_GenN_plusMinusN_minusTTMass->Write(); histoFineBinning_GenN_plusPlusN_minusTTMass->Write(); histoFineBinning_GenA_cTTRapidity->Write(); histoFineBinning_GenA_cTTPt->Write(); histoFineBinning_GenA_cTTMass->Write(); // RECO histoRecoTopRapidity1->Write(); histoRecoTopRapidity2->Write(); histoRecoLeptonRapidity1->Write(); histoRecoLeptonRapidity2->Write(); histoRecoTopMass1->Write(); histoRecoTopMass2->Write(); histoRecoTopMass1VsTopMass2->Write(); histoRecoDelta_y->Write(); histoRecoTTRapidity->Write(); histoRecoTTPt->Write(); histoRecoTTMass->Write(); histoRecoDelta_yVsTTRapidity->Write(); histoRecoDelta_yVsTTPt->Write(); histoRecoDelta_yVsTTMass->Write(); histoRecoN_plusTTRapidity->Write(); histoRecoN_plusTTPt->Write(); histoRecoN_plusTTMass->Write(); histoRecoN_minusTTRapidity->Write(); histoRecoN_minusTTPt->Write(); histoRecoN_minusTTMass->Write(); histoRecoN_plusMinusN_minusTTRapidity->Write(); histoRecoN_plusPlusN_minusTTRapidity->Write(); histoRecoN_plusMinusN_minusTTPt->Write(); histoRecoN_plusPlusN_minusTTPt->Write(); histoRecoN_plusMinusN_minusTTMass->Write(); histoRecoN_plusPlusN_minusTTMass->Write(); histoRecoA_cTTRapidity->Write(); histoRecoA_cTTPt->Write(); histoRecoA_cTTMass->Write(); histoFineBinning_RecoDelta_yVsTTRapidity->Write(); histoFineBinning_RecoDelta_yVsTTPt->Write(); histoFineBinning_RecoDelta_yVsTTMass->Write(); histoFineBinning_RecoN_plusTTRapidity->Write(); histoFineBinning_RecoN_plusTTPt->Write(); histoFineBinning_RecoN_plusTTMass->Write(); histoFineBinning_RecoN_minusTTRapidity->Write(); histoFineBinning_RecoN_minusTTPt->Write(); histoFineBinning_RecoN_minusTTMass->Write(); histoFineBinning_RecoN_plusMinusN_minusTTRapidity->Write(); histoFineBinning_RecoN_plusPlusN_minusTTRapidity->Write(); histoFineBinning_RecoN_plusMinusN_minusTTPt->Write(); histoFineBinning_RecoN_plusPlusN_minusTTPt->Write(); histoFineBinning_RecoN_plusMinusN_minusTTMass->Write(); histoFineBinning_RecoN_plusPlusN_minusTTMass->Write(); histoFineBinning_RecoA_cTTRapidity->Write(); histoFineBinning_RecoA_cTTPt->Write(); histoFineBinning_RecoA_cTTMass->Write(); // RECO vs GEN histoRecoVsGenTopRapidity1->Write(); histoRecoVsGenTopRapidity2->Write(); histoRecoMinusGenDivGenLeptonRapidity1->Write(); histoRecoMinusGenDivGenLeptonRapidity2->Write(); histoRecoMinusGenDivGenTopRapidity1->Write(); histoRecoMinusGenDivGenTopRapidity2->Write(); histoRecoVsGenTopMass1->Write(); histoRecoVsGenTopMass2->Write(); histoRecoMinusGenDivGenTopMass1->Write(); histoRecoMinusGenDivGenTopMass2->Write(); histoRecoVsGenDelta_y->Write(); histoFineBinning_RecoVsGenDelta_y->Write(); histoRecoMinusGenDivGenDelta_y->Write(); histoRecoVsGenTTRapidity->Write(); histoRecoMinusGenDivGenTTRapidity->Write(); histoRecoVsGenTTPt->Write(); histoRecoMinusGenDivGenTTPt->Write(); histoRecoVsGenTTMass->Write(); histoRecoMinusGenDivGenTTMass->Write(); histoDelta_yEfficiencyN->Write(); histoDelta_yEfficiencyD->Write(); histoDelta_yEfficiency->Write(); histoDelta_yVsTTRapidityEfficiency->Write(); histoDelta_yVsTTPtEfficiency->Write(); histoDelta_yVsTTMassEfficiency->Write(); histoFineBinning_Delta_yEfficiencyN->Write(); histoFineBinning_Delta_yEfficiencyD->Write(); histoFineBinning_Delta_yEfficiency->Write(); histoFineBinning_Delta_yVsTTRapidityEfficiency->Write(); histoFineBinning_Delta_yVsTTPtEfficiency->Write(); histoFineBinning_Delta_yVsTTMassEfficiency->Write(); // fileCA->Write(); fileCA->Close(); delete fileCA; cout << "num_mttbar_eff = " << num_mttbar_eff << endl; cout << "den_mttbar_eff = " << den_mttbar_eff << endl; cout << "mttbar_eff = " << num_mttbar_eff / den_mttbar_eff << endl; return (0); }
void macroEmuTree() { string inputline; string outputline; string blankline; ifstream myfile ("listofsamples.txt"); if (myfile.is_open()) { while ( myfile.good() ) { getline (myfile,inputline); getline (myfile,outputline); getline (myfile,blankline); //gSystem->Load("$ROOTSYS/test/libEvent"); cout << "File : " << inputline << endl; //Get old file, old tree and set top branch address TString inputfilepath =inputline; TString outputfilepath = outputline; //TDCacheFile *oldfile = new TDCacheFile(inputfilepath); TFile *oldfile = new TFile(inputfilepath); TTree *oldtree = (TTree*)oldfile->Get("gsfcheckerjob/tree"); Long64_t nentries = oldtree->GetEntries(); // Declaration of leaf types UInt_t runnumber; UInt_t eventnumber; UInt_t luminosityBlock; Int_t HLT_Mu22_Photon22_CaloIdL; Int_t HLT_Mu8_Ele17_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL; Int_t HLT_Mu17_Ele8_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL; Int_t prescale_HLT_Mu22_Photon22_CaloIdL; Int_t prescale_HLT_Mu8_Ele17_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL; Int_t prescale_HLT_Mu17_Ele8_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL; Float_t rho; Float_t pfmet; Int_t pvsize; Int_t JetColl_size; Float_t Jet_pt[100]; //[JetColl_size] Int_t muon_size; Float_t muon_pt[100]; //[muon_size] Float_t muon_ptError[100]; //[muon_size] Float_t muon_eta[100]; //[muon_size] Float_t muon_phi[100]; //[muon_size] Int_t muon_charge[100]; //[muon_size] Int_t muon_nhitspixel[100]; //[muon_size] Int_t muon_nhitstrack[100]; //[muon_size] Int_t muon_nhitsmuons[100]; //[muon_size] Int_t muon_nlayerswithhits[100]; //[muon_size] Int_t muon_nSegmentMatch[100]; //[muon_size] Bool_t muon_isTrackerMuon[100]; //[muon_size] Float_t muon_normChi2[100]; //[muon_size] Float_t muon_dz_beamSpot[100]; //[muon_size] Float_t muon_dz_firstPVtx[100]; //[muon_size] Float_t muon_dxy_cmsCenter[100]; //[muon_size] Float_t muon_dxy_beamSpot[100]; //[muon_size] Float_t muon_dxy_firstPVtx[100]; //[muon_size] Float_t muon_trackIso03[100]; //[muon_size] Float_t muon_emIso03[100]; //[muon_size] Float_t muon_hadIso03[100]; //[muon_size] Int_t gsf_size; Float_t gsf_eta[100]; //[gsf_size] Float_t gsf_phi[100]; //[gsf_size] Float_t gsf_theta[100]; //[gsf_size] Int_t gsf_charge[100]; //[gsf_size] Float_t gsf_sigmaetaeta[100]; //[gsf_size] Float_t gsf_sigmaIetaIeta[100]; //[gsf_size] Float_t gsf_dxy_firstPVtx[100]; //[gsf_size] Float_t gsf_dz_beamSpot[100]; //[gsf_size] Float_t gsf_dz_firstPVtx[100]; //[gsf_size] Int_t gsf_nLostInnerHits[100]; //[gsf_size] Float_t gsf_deltaeta[100]; //[gsf_size] Float_t gsf_deltaphi[100]; //[gsf_size] Float_t gsf_hovere[100]; //[gsf_size] Float_t gsf_trackiso[100]; //[gsf_size] Float_t gsf_ecaliso[100]; //[gsf_size] Float_t gsf_hcaliso1[100]; //[gsf_size] Float_t gsf_hcaliso2[100]; //[gsf_size] Bool_t gsf_isecaldriven[100]; //[gsf_size] Float_t gsfsc_e[100]; //[gsf_size] Float_t gsfsc_eta[100]; //[gsf_size] Float_t gsfsc_phi[100]; //[gsf_size] Float_t gsf_e2x5overe5x5[100]; //[gsf_size] Float_t gsf_e1x5overe5x5[100]; //[gsf_size] Float_t gsf_gsfet[100]; //[gsf_size] Float_t genPair_mass; Int_t trueNVtx; // List of branches TBranch *b_runnumber; //! TBranch *b_eventnumber; //! TBranch *b_luminosityBlock; //! TBranch *b_HLT_Mu22_Photon22_CaloIdL; //! TBranch *b_HLT_Mu8_Ele17_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL; //! TBranch *b_HLT_Mu17_Ele8_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL; //! TBranch *b_prescale_HLT_Mu22_Photon22_CaloIdL; //! TBranch *b_prescale_HLT_Mu8_Ele17_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL; //! TBranch *b_prescale_HLT_Mu17_Ele8_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL; //! TBranch *b_rho; //! TBranch *b_pfmet; //! TBranch *b_pvsize; //! TBranch *b_JetColl_size; //! TBranch *b_Jet_pt; //! TBranch *b_muon_size; //! TBranch *b_muon_pt; //! TBranch *b_muon_ptError; //! TBranch *b_muon_eta; //! TBranch *b_muon_phi; //! TBranch *b_muon_charge; //! TBranch *b_muon_nhitspixel; //! TBranch *b_muon_nhitstrack; //! TBranch *b_muon_nhitsmuons; //! TBranch *b_muon_nlayerswithhits; //! TBranch *b_muon_nSegmentMatch; //! TBranch *b_muon_isTrackerMuon; //! TBranch *b_muon_normChi2; //! TBranch *b_muon_dz_beamSpot; //! TBranch *b_muon_dz_firstPVtx; //! TBranch *b_muon_dxy_cmsCenter; //! TBranch *b_muon_dxy_beamSpot; //! TBranch *b_muon_dxy_firstPVtx; //! TBranch *b_muon_trackIso03; //! TBranch *b_muon_emIso03; //! TBranch *b_muon_hadIso03; //! TBranch *b_gsf_size; //! TBranch *b_gsf_eta; //! TBranch *b_gsf_phi; //! TBranch *b_gsf_theta; //! TBranch *b_gsf_charge; //! TBranch *b_gsf_sigmaetaeta; //! TBranch *b_gsf_sigmaIetaIeta; //! TBranch *b_gsf_dxy_firstPVtx; //! TBranch *b_gsf_dz_beamSpot; //! TBranch *b_gsf_dz_firstPVtx; //! TBranch *b_gsf_nLostInnerHits; //! TBranch *b_gsf_deltaeta; //! TBranch *b_gsf_deltaphi; //! TBranch *b_gsf_hovere; //! TBranch *b_gsf_trackiso; //! TBranch *b_gsf_ecaliso; //! TBranch *b_gsf_hcaliso1; //! TBranch *b_gsf_hcaliso2; //! TBranch *b_gsf_isecaldriven; //! TBranch *b_gsfsc_e; //! TBranch *b_gsfsc_eta; //! TBranch *b_gsfsc_phi; //! TBranch *b_gsf_e2x5overe5x5; //! TBranch *b_gsf_e1x5overe5x5; //! TBranch *b_gsf_gsfet; //! TBranch *b_genPair_mass; //! TBranch *b_trueNVtx; //! oldtree->SetBranchAddress("runnumber", &runnumber, &b_runnumber); oldtree->SetBranchAddress("eventnumber", &eventnumber, &b_eventnumber); oldtree->SetBranchAddress("luminosityBlock", &luminosityBlock, &b_luminosityBlock); oldtree->SetBranchAddress("HLT_Mu22_Photon22_CaloIdL", &HLT_Mu22_Photon22_CaloIdL, &b_HLT_Mu22_Photon22_CaloIdL); oldtree->SetBranchAddress("HLT_Mu8_Ele17_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL", &HLT_Mu8_Ele17_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL, &b_HLT_Mu8_Ele17_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL); oldtree->SetBranchAddress("HLT_Mu17_Ele8_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL", &HLT_Mu17_Ele8_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL, &b_HLT_Mu17_Ele8_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL); oldtree->SetBranchAddress("prescale_HLT_Mu22_Photon22_CaloIdL", &prescale_HLT_Mu22_Photon22_CaloIdL, &b_prescale_HLT_Mu22_Photon22_CaloIdL); oldtree->SetBranchAddress("prescale_HLT_Mu8_Ele17_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL", &prescale_HLT_Mu8_Ele17_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL, &b_prescale_HLT_Mu8_Ele17_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL); oldtree->SetBranchAddress("prescale_HLT_Mu17_Ele8_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL", &prescale_HLT_Mu17_Ele8_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL, &b_prescale_HLT_Mu17_Ele8_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL); oldtree->SetBranchAddress("rho", &rho, &b_rho); oldtree->SetBranchAddress("pfmet", &pfmet, &b_pfmet); oldtree->SetBranchAddress("pvsize", &pvsize, &b_pvsize); oldtree->SetBranchAddress("JetColl_size", &JetColl_size, &b_JetColl_size); oldtree->SetBranchAddress("Jet_pt", Jet_pt, &b_Jet_pt); oldtree->SetBranchAddress("muon_size", &muon_size, &b_muon_size); oldtree->SetBranchAddress("muon_pt", muon_pt, &b_muon_pt); oldtree->SetBranchAddress("muon_ptError", muon_ptError, &b_muon_ptError); oldtree->SetBranchAddress("muon_eta", muon_eta, &b_muon_eta); oldtree->SetBranchAddress("muon_phi", muon_phi, &b_muon_phi); oldtree->SetBranchAddress("muon_charge", muon_charge, &b_muon_charge); oldtree->SetBranchAddress("muon_nhitspixel", muon_nhitspixel, &b_muon_nhitspixel); oldtree->SetBranchAddress("muon_nhitstrack", muon_nhitstrack, &b_muon_nhitstrack); oldtree->SetBranchAddress("muon_nhitsmuons", muon_nhitsmuons, &b_muon_nhitsmuons); oldtree->SetBranchAddress("muon_nlayerswithhits", muon_nlayerswithhits, &b_muon_nlayerswithhits); oldtree->SetBranchAddress("muon_nSegmentMatch", muon_nSegmentMatch, &b_muon_nSegmentMatch); oldtree->SetBranchAddress("muon_isTrackerMuon", muon_isTrackerMuon, &b_muon_isTrackerMuon); oldtree->SetBranchAddress("muon_normChi2", muon_normChi2, &b_muon_normChi2); oldtree->SetBranchAddress("muon_dz_beamSpot", muon_dz_beamSpot, &b_muon_dz_beamSpot); oldtree->SetBranchAddress("muon_dz_firstPVtx", muon_dz_firstPVtx, &b_muon_dz_firstPVtx); oldtree->SetBranchAddress("muon_dxy_cmsCenter", muon_dxy_cmsCenter, &b_muon_dxy_cmsCenter); oldtree->SetBranchAddress("muon_dxy_beamSpot", muon_dxy_beamSpot, &b_muon_dxy_beamSpot); oldtree->SetBranchAddress("muon_dxy_firstPVtx", muon_dxy_firstPVtx, &b_muon_dxy_firstPVtx); oldtree->SetBranchAddress("muon_trackIso03", muon_trackIso03, &b_muon_trackIso03); oldtree->SetBranchAddress("muon_emIso03", muon_emIso03, &b_muon_emIso03); oldtree->SetBranchAddress("muon_hadIso03", muon_hadIso03, &b_muon_hadIso03); oldtree->SetBranchAddress("gsf_size", &gsf_size, &b_gsf_size); oldtree->SetBranchAddress("gsf_eta", gsf_eta, &b_gsf_eta); oldtree->SetBranchAddress("gsf_phi", gsf_phi, &b_gsf_phi); oldtree->SetBranchAddress("gsf_theta", gsf_theta, &b_gsf_theta); oldtree->SetBranchAddress("gsf_charge", gsf_charge, &b_gsf_charge); oldtree->SetBranchAddress("gsf_sigmaetaeta", gsf_sigmaetaeta, &b_gsf_sigmaetaeta); oldtree->SetBranchAddress("gsf_sigmaIetaIeta", gsf_sigmaIetaIeta, &b_gsf_sigmaIetaIeta); oldtree->SetBranchAddress("gsf_dxy_firstPVtx", gsf_dxy_firstPVtx, &b_gsf_dxy_firstPVtx); oldtree->SetBranchAddress("gsf_dz_beamSpot", gsf_dz_beamSpot, &b_gsf_dz_beamSpot); oldtree->SetBranchAddress("gsf_dz_firstPVtx", gsf_dz_firstPVtx, &b_gsf_dz_firstPVtx); oldtree->SetBranchAddress("gsf_nLostInnerHits", gsf_nLostInnerHits, &b_gsf_nLostInnerHits); oldtree->SetBranchAddress("gsf_deltaeta", gsf_deltaeta, &b_gsf_deltaeta); oldtree->SetBranchAddress("gsf_deltaphi", gsf_deltaphi, &b_gsf_deltaphi); oldtree->SetBranchAddress("gsf_hovere", gsf_hovere, &b_gsf_hovere); oldtree->SetBranchAddress("gsf_trackiso", gsf_trackiso, &b_gsf_trackiso); oldtree->SetBranchAddress("gsf_ecaliso", gsf_ecaliso, &b_gsf_ecaliso); oldtree->SetBranchAddress("gsf_hcaliso1", gsf_hcaliso1, &b_gsf_hcaliso1); oldtree->SetBranchAddress("gsf_hcaliso2", gsf_hcaliso2, &b_gsf_hcaliso2); oldtree->SetBranchAddress("gsf_isecaldriven", gsf_isecaldriven, &b_gsf_isecaldriven); oldtree->SetBranchAddress("gsfsc_e", gsfsc_e, &b_gsfsc_e); oldtree->SetBranchAddress("gsfsc_eta", gsfsc_eta, &b_gsfsc_eta); oldtree->SetBranchAddress("gsfsc_phi", gsfsc_phi, &b_gsfsc_phi); oldtree->SetBranchAddress("gsf_e2x5overe5x5", gsf_e2x5overe5x5, &b_gsf_e2x5overe5x5); oldtree->SetBranchAddress("gsf_e1x5overe5x5", gsf_e1x5overe5x5, &b_gsf_e1x5overe5x5); oldtree->SetBranchAddress("gsf_gsfet", gsf_gsfet, &b_gsf_gsfet); oldtree->SetBranchAddress("genPair_mass", &genPair_mass, &b_genPair_mass); oldtree->SetBranchAddress("trueNVtx", &trueNVtx, &b_trueNVtx); // enable only used branches oldtree->SetBranchStatus("*", 0); oldtree->SetBranchStatus("runnumber", 1); oldtree->SetBranchStatus("eventnumber", 1); oldtree->SetBranchStatus("luminosityBlock", 1); oldtree->SetBranchStatus("HLT_Mu22_Photon22_CaloIdL", 1); oldtree->SetBranchStatus("HLT_Mu8_Ele17_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL", 1); oldtree->SetBranchStatus("HLT_Mu17_Ele8_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL", 1); oldtree->SetBranchStatus("prescale_HLT_Mu22_Photon22_CaloIdL", 1); oldtree->SetBranchStatus("prescale_HLT_Mu8_Ele17_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL", 1); oldtree->SetBranchStatus("prescale_HLT_Mu17_Ele8_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL", 1); oldtree->SetBranchStatus("rho", 1); oldtree->SetBranchStatus("pfmet", 1); oldtree->SetBranchStatus("pvsize", 1); oldtree->SetBranchStatus("JetColl_size", 1); oldtree->SetBranchStatus("Jet_pt", 1); oldtree->SetBranchStatus("muon_size", 1); oldtree->SetBranchStatus("muon_pt", 1); oldtree->SetBranchStatus("muon_ptError", 1); oldtree->SetBranchStatus("muon_eta", 1); oldtree->SetBranchStatus("muon_phi", 1); oldtree->SetBranchStatus("muon_charge", 1); oldtree->SetBranchStatus("muon_nhitspixel", 1); oldtree->SetBranchStatus("muon_nhitstrack", 1); oldtree->SetBranchStatus("muon_nhitsmuons", 1); oldtree->SetBranchStatus("muon_nlayerswithhits", 1); oldtree->SetBranchStatus("muon_nSegmentMatch", 1); oldtree->SetBranchStatus("muon_isTrackerMuon", 1); oldtree->SetBranchStatus("muon_normChi2", 1); oldtree->SetBranchStatus("muon_dz_beamSpot", 1); oldtree->SetBranchStatus("muon_dz_firstPVtx", 1); oldtree->SetBranchStatus("muon_dxy_cmsCenter", 1); oldtree->SetBranchStatus("muon_dxy_beamSpot", 1); oldtree->SetBranchStatus("muon_dxy_firstPVtx", 1); oldtree->SetBranchStatus("muon_trackIso03", 1); oldtree->SetBranchStatus("muon_emIso03", 1); oldtree->SetBranchStatus("muon_hadIso03", 1); oldtree->SetBranchStatus("gsf_size", 1); oldtree->SetBranchStatus("gsf_eta", 1); oldtree->SetBranchStatus("gsf_phi", 1); oldtree->SetBranchStatus("gsf_theta", 1); oldtree->SetBranchStatus("gsf_charge", 1); oldtree->SetBranchStatus("gsf_sigmaetaeta", 1); oldtree->SetBranchStatus("gsf_sigmaIetaIeta", 1); oldtree->SetBranchStatus("gsf_dxy_firstPVtx", 1); oldtree->SetBranchStatus("gsf_dz_beamSpot", 1); oldtree->SetBranchStatus("gsf_dz_firstPVtx", 1); oldtree->SetBranchStatus("gsf_nLostInnerHits", 1); oldtree->SetBranchStatus("gsf_deltaeta", 1); oldtree->SetBranchStatus("gsf_deltaphi", 1); oldtree->SetBranchStatus("gsf_hovere", 1); oldtree->SetBranchStatus("gsf_trackiso", 1); oldtree->SetBranchStatus("gsf_ecaliso", 1); oldtree->SetBranchStatus("gsf_hcaliso1", 1); oldtree->SetBranchStatus("gsf_hcaliso2", 1); oldtree->SetBranchStatus("gsf_isecaldriven", 1); oldtree->SetBranchStatus("gsfsc_e", 1); oldtree->SetBranchStatus("gsfsc_eta", 1); oldtree->SetBranchStatus("gsfsc_phi", 1); oldtree->SetBranchStatus("gsf_e2x5overe5x5", 1); oldtree->SetBranchStatus("gsf_e1x5overe5x5", 1); oldtree->SetBranchStatus("gsf_gsfet", 1); oldtree->SetBranchStatus("genPair_mass", 1); oldtree->SetBranchStatus("trueNVtx", 1); //Create a new file + a clone of old tree header. Do not copy events TFile *newfile = new TFile(outputfilepath,"recreate"); newfile->mkdir("gsfcheckerjob"); newfile->cd("gsfcheckerjob"); TTree *newtree = oldtree->CloneTree(0); for (Long64_t i = 0; i < nentries; ++i) { if (i %100000 == 0) cout << "entry nb: " <<i << endl; oldtree->GetEntry(i); if(gsf_size < 1) continue; if(muon_size < 1) continue; bool passEleSelection = false; bool passMuSelection = false; for (int it = 0; it < gsf_size; ++it) { if (gsf_gsfet[it] < 35.) continue; passEleSelection = true; } for (int muIt = 0; muIt < muon_size; ++muIt) { if (muon_pt[muIt] < 35.) continue; passMuSelection = true; } if (passEleSelection && passMuSelection) newtree->Fill(); } newtree->Print(); newfile->Write(); delete oldfile; delete newfile; } myfile.close(); } }
int stdhep2root(int nEvent=100) { gROOT->Reset(); // In order to refer to shareable libraries in this simple form, // include their paths in a .rootrc file. gSystem->Load("libLCDEvent"); gSystem->Load("libLCDRootAppsUtil"); gSystem->Load("libLCDFastMC"); gSystem->Load("libLCDStdHEPUtil"); gSystem->Load("libEG"); gSystem->Load("libEGPythia6"); gSystem->Load("libLCDEvent"); gSystem->Load("libLCDRootAppsUtil"); gSystem->Load("libLCDFastMC"); gSystem->Load("libLCDPhUtil"); gSystem->Load("libLCDGenUtil"); TString parfile_dir; parfile_dir += gSystem->Getenv("LCDROOT") ;parfile_dir += "/"; parfile_dir += "ParFiles/"; LCDEvent *event= new LCDEvent(); //Create Physics event container first. // Input stdhep data Char_t* stdFile = "test.hep"; // Char_t* stdFile = "../../../GenData/eetobbZ0.dat"; LCDreadStdFile source(stdFile,event); // // Open root file. // Int_t comp=2; Char_t* rootFile = "eetobbZ0.root"; TFile* hfile = new TFile(rootFile,"RECREATE","LCD Event ROOT file"); hfile->SetCompressionLevel(comp); // // Create a tree with one superbranch. // TTree* tree = new TTree( "T", "LCD ROOT tree" ); tree->SetAutoSave( 1000000000 ); tree->Branch( "LCDEvent", "LCDEvent", &event); // Event loop Int_t iEvent; for (iEvent = 0; iEvent < nEvent; iEvent++) { if (!source.GetEvent()) break; // Read an event from the stdhep file. tree->Fill(); } // // Clean up the ROOT file. // hfile->Write(); tree->Print(); hfile->Close(); return iEvent; }
void CutTree(){ int NMin=300000; /* char outputfilename[200]; sprintf(outputfilename,"Results/ProblemBin.txt"); printf("output filename is: %s\n", outputfilename); FILE *outputFile = fopen(outputfilename,"w"); */ TFile* fInData = new TFile(fileNameData); TTree *treeData = (TTree*)fInData->Get("data"); treeData->Print(); TTree *fChain; fChain=treeData; Long64_t nentries = fChain->GetEntries(); cout<<nentries<<endl; Long64_t nb = 0; Double_t JpsiMass; Double_t JpsiPt; Double_t JpsiRap; Double_t Jpsict; Int_t JpsiType_idx; Int_t MCType_idx; Double_t costh_CS; Double_t phi_CS; Double_t costh_HX; Double_t phi_HX; TBranch *b_JpsiMass; //! TBranch *b_JpsiPt; //! TBranch *b_JpsiRap; //! TBranch *b_Jpsict; //! TBranch *b_JpsiType_idx; //! TBranch *b_MCType_idx; //! TBranch *b_costh_CS; //! TBranch *b_phi_CS; //! TBranch *b_costh_HX; //! TBranch *b_phi_HX; //! fChain->SetBranchAddress("JpsiMass", &JpsiMass, &b_JpsiMass); fChain->SetBranchAddress("JpsiPt", &JpsiPt, &b_JpsiPt); fChain->SetBranchAddress("JpsiRap", &JpsiRap, &b_JpsiRap); fChain->SetBranchAddress("Jpsict", &Jpsict, &b_Jpsict); fChain->SetBranchAddress("JpsiType_idx", &JpsiType_idx, &b_JpsiType_idx); fChain->SetBranchAddress("MCType_idx", &MCType_idx, &b_MCType_idx); fChain->SetBranchAddress("costh_CS", &costh_CS, &b_costh_CS); fChain->SetBranchAddress("phi_CS", &phi_CS, &b_phi_CS); fChain->SetBranchAddress("costh_HX", &costh_HX, &b_costh_HX); fChain->SetBranchAddress("phi_HX", &phi_HX, &b_phi_HX); // Long64_t jentry=NMin; TNtuple* pseudodata = new TNtuple("data","data","JpsiMass:JpsiPt:JpsiRap:Jpsict:costh_CS:phi_CS:costh_HX:phi_HX:JpsiType_idx:MCType_idx"); TNtuple* data = new TNtuple("data","data","JpsiMass:JpsiPt:JpsiRap:Jpsict:costh_CS:phi_CS:costh_HX:phi_HX:JpsiType_idx:MCType_idx"); for (Long64_t jentry=0; jentry<NMin;jentry++) { if(jentry % 1000 == 0) printf("event %d\n", (Int_t) jentry); nb = fChain->GetEntry(jentry); //nbytes += nb; pseudodata->Fill(JpsiMass,JpsiPt,JpsiRap,Jpsict,costh_CS,phi_CS,costh_HX,phi_HX,JpsiType_idx,MCType_idx); } for (Long64_t jentry=0; jentry<nentries;jentry++) { if(jentry % 1000 == 0) printf("event %d\n", (Int_t) jentry); nb = fChain->GetEntry(jentry); //nbytes += nb; // fprintf(outputFile, "%f\n",Jpsict); data->Fill(JpsiMass,JpsiPt,JpsiRap,Jpsict,costh_CS,phi_CS,costh_HX,phi_HX,JpsiType_idx,MCType_idx); } pseudodata->Print(); pseudodata->SaveAs("/scratch/knuenz/Polarization/RootInput/TNtuple_red_PR_pseudo.root"); data->Print(); data->SaveAs("/scratch/knuenz/Polarization/RootInput/TNtuple_red_PR.root"); // RooDataSetData.Print(); // fclose(outputFile); // treeData.Print(); return; }
TFile *cernbuild(Int_t getFile=0, Int_t print=1) { Int_t Category; UInt_t Flag; Int_t Age; Int_t Service; Int_t Children; Int_t Grade; Int_t Step; Int_t Hrweek; Int_t Cost; Char_t Division[4]; Char_t Nation[3]; //The input file cern.dat is a copy of the CERN staff data base //from 1988 TString filename = "cernstaff.root"; TString dir = gROOT->GetTutorialDir(); dir.Append("/tree/"); dir.ReplaceAll("/./","/"); FILE *fp = fopen(Form("%scernstaff.dat",dir.Data()),"r"); TFile *hfile = 0; if (getFile) { // if the argument getFile =1 return the file "cernstaff.root" // if the file does not exist, it is created if (!gSystem->AccessPathName(dir+"cernstaff.root",kFileExists)) { hfile = TFile::Open(dir+"cernstaff.root"); //in $ROOTSYS/tutorials/tree if (hfile) return hfile; } //otherwise try $PWD/cernstaff.root if (!gSystem->AccessPathName("cernstaff.root",kFileExists)) { hfile = TFile::Open("cernstaff.root"); //in current dir if (hfile) return hfile; } } //no cernstaff.root file found. Must generate it ! //generate cernstaff.root in $ROOTSYS/tutorials/tree if we have write access if (gSystem->AccessPathName(".",kWritePermission)) { printf("you must run the script in a directory with write access\n"); return 0; } hfile = TFile::Open(filename,"RECREATE"); TTree *tree = new TTree("T","CERN 1988 staff data"); tree->Branch("Category",&Category,"Category/I"); tree->Branch("Flag",&Flag,"Flag/i"); tree->Branch("Age",&Age,"Age/I"); tree->Branch("Service",&Service,"Service/I"); tree->Branch("Children",&Children,"Children/I"); tree->Branch("Grade",&Grade,"Grade/I"); tree->Branch("Step",&Step,"Step/I"); tree->Branch("Hrweek",&Hrweek,"Hrweek/I"); tree->Branch("Cost",&Cost,"Cost/I"); tree->Branch("Division",Division,"Division/C"); tree->Branch("Nation",Nation,"Nation/C"); char line[80]; while (fgets(line,80,fp)) { sscanf(&line[0],"%d %d %d %d %d %d %d %d %d %s %s", &Category,&Flag,&Age,&Service,&Children,&Grade,&Step,&Hrweek,&Cost,Division,Nation); tree->Fill(); } if (print) tree->Print(); tree->Write(); fclose(fp); delete hfile; if (getFile) { //we come here when the script is executed outside $ROOTSYS/tutorials/tree hfile = TFile::Open(filename); return hfile; } return 0; }
void create_tree_for_toyMC()() { gROOT->Reset(); Double_t Y; Double_t Y_true; Double_t dY; Double_t Tk; Double_t Tk_true; Double_t dTk; Double_t Sa; Double_t Sa_true; Double_t dSa; Double_t Iso; Double_t Iso_true; Double_t dIso; Double_t Hlt; Double_t Hlt_true; Double_t dHlt; Double_t chi2; TFile *f; TTree *tree; f = new TFile("fitResult.root","RECREATE"); tree = new TTree("tree"," C data from ASCII file"); tree->Branch("Y",&Y,"Y/D"); tree->Branch("Y_true",&Y_true,"Y/D"); tree->Branch("dY",&dY,"dY/D"); tree->Branch("Tk",&Tk," Tk/D"); tree->Branch("Tk_true",&Tk_true," Tk_true/D"); tree->Branch("dTk",&dTk," dTk/D"); tree->Branch("Sa",&Sa," Sa/D"); tree->Branch("Sa_true",&Sa_true," Sa_true/D"); tree->Branch("dSa",&dSa," dSa/D"); tree->Branch("Iso",&Iso," Iso/D"); tree->Branch("Iso_true",&Iso_true," Iso_true/D"); tree->Branch("dIso",&dIso," dIso/D"); tree->Branch("Hlt",&Hlt," Hlt/D"); tree->Branch("Hlt_true",&Hlt_true," Hlt_true/D"); tree->Branch("dHlt",&dHlt," dHlt/D"); tree->Branch("chi2",&chi2," chi2/D"); ifstream fin; fin.open("fitResult.txt"); char line[1024]; fin.getline(line, 1024); cout << line << endl; fin >> Y_true >> Tk_true >> Sa_true >> Iso_true >> Hlt_true; cout << "Yield = " << Y_true; cout << " eff_trk = " << Tk_true; cout << " eff_sa = " << Sa_true; cout << " eff_iso = " << Iso_true; cout << " eff_hlt = " << Hlt_true << endl; while(!(fin.eof())){ Y = 0; fin >> Y >> dY >> Tk >> dTk >> Sa >> dSa >> Iso >> dIso >> Hlt >> dHlt >>chi2; if(Y > 0) tree->Fill(); } tree->Print(); f->Write(); f->Close(); }
int main(){ float data[1024], x[1024], min, area, energy, timing; int start, cut, count; TFile *fout = TFile::Open("/projects/physics/dmice/Fermilab/Co60_Temp.root", "recreate"); TTree *tree = new TTree("tree", "NaI Detector Data"); tree->Branch("Waveforms", data, "data[1024]/F"); tree->Branch("Height", &min, "min/F"); tree->Branch("Area", &area, "area/F"); tree->Branch("Saturated", &cut, "cut/I"); tree->Branch("Energy", &energy, "energy/F"); tree->Branch("Timing" , &timing, "timing/F"); TChain t("tree"); t.Add("/projects/physics/dmice/Fermilab/sourcedata/Co60raw/Waveforms_0.root"); //t.Add("/projects/physics/dmice/Fermilab/1V_runs/Fermilab_1V_raw.root"); t.SetBranchAddress("Waveforms", data); for(int e = 0; t.GetEntry(e) > 0; e++){ //&& e < 10 Float_t weight=0, avg = 0, y[1024], offavg=0, bin_sum = 0; int minLoc, n0; min = 0; for(int i = 0; i < 200; i++) offavg += data[i]; offavg = offavg/200; for(int i = 0; i < 1024; i++){ y[i] = data[i] - offavg; x[i] = i; if(i < 1021 && cut == 0) if(data[i] == data[i+1] && data[i] == data[i+2] && data[i] < -.2) cut = 1; if(y[i] < min){ min = y[i]; minLoc = i; } } int zero_counter = 0, start, end; bool foundstart = false, foundend = false; for(int i = 2; i < 997; i++){ float local_avg = y[i-2] + y[i-1] + y[i] + y[i+1] + y[i+2]; if(local_avg < -.05 && !foundstart){ start = i-2; foundstart = true; } if(local_avg >= 0 && !foundend && foundstart){ zero_counter++; if(zero_counter == 15){ end = i; foundend = true; } } } //cout <<"Pulse Start: " << start << endl; //cout <<"Pulse End: " << end << endl; // for(inti i = start; i <= end; i++){ // bin_sum += y[i]; // } TGraph gr(1024, x, y); area = gr.Integral(start, end); // area = -bin_sum; energy = (area*69.674)+1.8148; for(int i = minLoc; i > 0; i--){ if(y[i] < min/2) n0 = i; } for(int i = n0; i < (n0+100); i++) { weight += (i-n0)*y[i]; avg += y[i]; if(i == 1023) { weight = 0; avg = 0; break; } } if(avg != 0) timing = (weight/avg)*4; tree->Fill(); //cout << "min: " << min << endl; //cout << "Area: "<< area << endl; //cout << "Saturated: " << cut << endl; //cout << "Meantime: " << timing << endl; //cout << endl; count++; } tree->Write(); tree->Print(); fout ->Close("R"); delete fout; }
void makenewtree() { // Define input and output files TFile infile("OmniTree_BprimeBprimeToBHBHinc_M-650_TuneZ2star_8TeV-madgraph_tree.root"); TFile ofile("BprimeAnalysis_650.root","RECREATE"); // Point to old tree, declare new tree TTree *oldtree = infile.GetObjectChecked("EvTree","TTree"); TTree *newtree = new TTree("BprimeTree","Smaller Tree for B prime Analysis"); // Create new tree's branches newtree->Branch("nPart",&nPart,"nPart/I"); newtree->Branch("bPartons",&bPartons,"bPartons/I"); newtree->Branch("bPartons30",&bPartons30,"bPartons30/I"); newtree->Branch("nJets",&nJets,"nJets/I"); newtree->Branch("nJets30",&nJets30,"nJets30/I"); newtree->Branch("nHiggs",&nHiggs,"nHiggs/I"); newtree->Branch("partID[nPart]",partID,"partID[nPart]/I"); newtree->Branch("Motherindex[nPart]",Motherindex,"Motherindex[nPart]/I"); newtree->Branch("b_mothers[bPartons]",b_mothers,"b_mothers[bPartons]/I"); newtree->Branch("Higgs_mother[nHiggs]",Higgs_mother,"Higgs_mother[nHiggs]/I"); newtree->Branch("MCpt[nPart]",MCpt,"MCpt[nPart]/F"); newtree->Branch("b_pt[bPartons]",b_pt,"b_pt[bPartons]/F"); newtree->Branch("Higgs_pt[nHiggs]",Higgs_pt,"Higgs_pt[nHiggs]/F"); newtree->Branch("MCeta[nPart]",MCeta,"MCeta[nPart]/F"); newtree->Branch("b_eta[bPartons]",b_eta,"b_eta[bPartons]/F"); newtree->Branch("Higgs_eta[nHiggs]",Higgs_eta,"Higgs_eta[nHiggs]/F"); newtree->Branch("MCphi[nPart]",MCphi,"MCphi[nPart]/F"); newtree->Branch("b_phi[bPartons]",b_phi,"b_phi[bPartons]/F"); newtree->Branch("Higgs_phi[nHiggs]",Higgs_phi,"Higgs_phi[nHiggs]/F"); newtree->Branch("jet_pt[nJets]",jet_pt,"jet_pt[nJets]/F"); newtree->Branch("jet_eta[nJets]",jet_eta,"jet_eta[nJets]/F"); newtree->Branch("jet_phi[nJets]",jet_phi,"jet_phi[nJets]/F"); newtree->Branch("jet_bdisc[nJets]",jet_bdisc,"jet_bdisc[nJets]/F"); newtree->Branch("Ht",&Ht,"Ht/F"); // Address old tree's branches oldtree->SetBranchAddress("nGenPart", &nGenPart); oldtree->SetBranchAddress("nPFJets", &nPFJets); oldtree->SetBranchAddress("MCpx[nGenPart]",MCpx); oldtree->SetBranchAddress("MCpy[nGenPart]",MCpy); oldtree->SetBranchAddress("MCpz[nGenPart]",MCpz); oldtree->SetBranchAddress("pdgID[nGenPart]",pdgID); oldtree->SetBranchAddress("MCmotherind[nGenPart]",MCmotherind); oldtree->SetBranchAddress("jet_PF_pt[nPFJets]",jet_PF_pt); oldtree->SetBranchAddress("jet_PF_eta[nPFJets]",jet_PF_eta); oldtree->SetBranchAddress("jet_PF_phi[nPFJets]",jet_PF_phi); oldtree->SetBranchAddress("jet_PF_px[nPFJets]",jet_PF_px); oldtree->SetBranchAddress("jet_PF_py[nPFJets]",jet_PF_py); oldtree->SetBranchAddress("bdiscCSV_PF[nPFJets]",bdiscCSV_PF); // Loop over each event for(int i = 0; oldtree->GetEntry(i) > 0; ++i) { oldtree->GetEntry(i); bPartons = 0; bPartons30 = 0; nHiggs = 0; Ht = 0; nPart = nGenPart; nJets = nPFJets; nJets30 = 0; // Loop over each particle for(int j = 0; j < nGenPart; ++j) { partID[j] = pdgID[j]; //copies particle ID array MCpt[j] = sqrt(pow(MCpx[j],2)+pow(MCpy[j],2)); //calculate pT float p_mag = sqrt(pow(MCpx[j],2)+pow(MCpy[j],2)+pow(MCpz[j],2)); //magnitude of 3p vector MCeta[j] = .5*log((p_mag + MCpz[j])/(p_mag - MCpz[j])); //calculate eta MCphi[j] = atan2(MCpy[j],MCpx[j]); //calculate phi Motherindex[j] = MCmotherind[j]; //copies mother index array if(fabs(pdgID[j]) == 5) { b_pt[bPartons] = MCpt[j]; //pt, eta and phi of b partons b_eta[bPartons] = MCeta[j]; b_phi[bPartons] = MCphi[j]; b_mothers[bPartons] = pdgID[MCmotherind[j]]; //stores ID of mother, rather than index ++bPartons; //count b partons if((MCpt[j]>30)&&(fabs(MCeta[j])<2.4)) ++bPartons30; } if(fabs(pdgID[j]) == 25) { Higgs_pt[nHiggs] = MCpt[j]; //pt, eta and phi of Higgs Higgs_eta[nHiggs] = MCeta[j]; Higgs_phi[nHiggs] = MCphi[j]; Higgs_mother[nHiggs] = pdgID[MCmotherind[j]]; //stores ID of mother, rather than index ++nHiggs; //count Higgs } } // Loop over each jet for(int j = 0; j < nPFJets; ++j) { jet_pt[j] = jet_PF_pt[j]; //Copy values from old tree jet_eta[j] = jet_PF_eta[j]; jet_phi[j] = jet_PF_phi[j]; jet_bdisc[j] = bdiscCSV_PF[j]; if((jet_PF_pt[j] > 30.0)&&(fabs(jet_PF_eta[j])<2.4)) { Ht += jet_PF_pt[j]; //Ht is sum of pT of jets with pT > 30 GeV ++nJets30; } } // Fill new tree newtree->Fill(); } // Write new tree to output file newtree->Print(); newtree->Write(); // Write output file ofile.Write(); }
int TrackParametrization( TString csvfile="fitslices_out.csv" ) { /* Read data from input file */ TTree *tres = new TTree(); tres->ReadFile( csvfile, "ptrue:etatrue:psig:psig_err:pmean:pmean_err:norm", ',' ); /* Print read-in tree */ tres->Print(); /* colors array */ unsigned colors[8] = {1,2,3,4,6,7,14,16}; /* Create vector of theta values to include for visualization*/ vector< double > etas_vis; etas_vis.push_back(-2.75); etas_vis.push_back(-2.25); etas_vis.push_back(-1.75); etas_vis.push_back(-0.25); etas_vis.push_back( 0.25); etas_vis.push_back( 1.75); etas_vis.push_back( 2.25); // etas_vis.push_back(-3.25); // etas_vis.push_back(-2.25); // etas_vis.push_back(-1.25); // etas_vis.push_back(-0.25); // etas_vis.push_back( 0.25); // etas_vis.push_back( 1.25); // etas_vis.push_back( 2.25); // etas_vis.push_back( 3.25); /* Create vector of theta values to include for fitting*/ vector< double > etas_fit; for ( double eta = -4.45; eta < 4.5; eta += 0.1 ) etas_fit.push_back( eta ); /* Create fit function */ TF1* f_momres = new TF1("f_momres", "sqrt( [0]*[0] + [1]*[1]*x*x )" ); cout << "\nFit function: " << f_momres->GetTitle() << "\n" << endl; /* Create scratch canvas */ TCanvas *cscratch = new TCanvas("cscratch"); /* Create framehistogram */ TH1F* hframe = new TH1F("hframe","",100,0,40); hframe->GetYaxis()->SetRangeUser(0,0.15); hframe->GetYaxis()->SetNdivisions(505); hframe->GetXaxis()->SetTitle("Momentum (GeV/c)"); hframe->GetYaxis()->SetTitle("#sigma_{p}/p"); /* create combined canvas plot */ TCanvas *c1 = new TCanvas(); hframe->Draw(); /* Create legend */ TLegend* leg_eta = new TLegend( 0.2, 0.6, 0.5, 0.9); leg_eta->SetNColumns(2); /* Create ofstream to write fit parameter results */ ofstream ofsfit("track_momres_new.csv"); ofsfit<<"eta,par1,par1err,par2,par2err"<<endl; /* Create resolution-vs-momentum plot with fits for each selected theta value */ for ( int i = 0; i < etas_fit.size(); i++ ) { /* Switch to scratch canvas */ cscratch->cd(); double eta = etas_fit.at(i); /* No tracking outside -4 < eta < 4 */ if ( eta < -4 || eta > 4 ) continue; cout << "\n***Eta = " << eta << endl; /* Define range of theta because float comparison with fixed value doesn't work too well for cuts in ROOT trees */ double eta_min = eta * 0.999; double eta_max = eta * 1.001; /* Cut for tree */ TCut cutx( Form("ptrue > 1 && ( (etatrue > 0 && (etatrue > %f && etatrue < %f)) || (etatrue < 0 && (etatrue < %f && etatrue > %f)) )", eta_min, eta_max, eta_min, eta_max) ); /* "Draw" tree on scratch canvas to fill V1...V4 arrays */ tres->Draw("psig:ptrue:psig_err:0", cutx ); /* Create TGraphErrors with selected data from tree */ TGraphErrors *gres = new TGraphErrors( tres->GetEntries(cutx), &(tres->GetV2())[0], &(tres->GetV1())[0], &(tres->GetV4())[0], &(tres->GetV3())[0] ); /* reset function parameters before fit */ f_momres->SetParameter(0,0.1); f_momres->SetParameter(1,0.1); /* Only plot pseudorapidities listed on etas_vis; if not plotting, still do the fit */ bool vis = false; int vi = 0; for ( vi = 0; vi < etas_vis.size(); vi++ ) { if ( abs( etas_vis.at(vi) - eta ) < 0.001 ) { vis = true; break; } } if ( vis ) { /* Add graph to legend */ leg_eta->AddEntry(gres, Form("#eta = %.1f", eta), "P"); /* Add graph to plot */ c1->cd(); gres->SetMarkerColor(colors[vi]); gres->Draw("Psame"); f_momres->SetLineColor(colors[vi]); gres->Fit(f_momres); } else { gres->Fit(f_momres); } /* Write fir results to file */ double par1 = f_momres->GetParameter(0); double par1err = f_momres->GetParError(0); double par2 = f_momres->GetParameter(1); double par2err = f_momres->GetParError(1); ofsfit << eta << "," << par1 << "," << par1err << "," << par2 << "," << par2err << endl; } /* Draw legend */ c1->cd(); //TCanvas *c2 = new TCanvas(); //hframe->Draw(); leg_eta->Draw(); /* Print plots */ c1->Print("track_momres_vareta.eps"); //c2->Print("track_momres_vareta_legend.eps"); /* Close output stream */ ofsfit.close(); return 0; }
int main(int argc, char ** argv) { // select fed int month = atoi(argv[1]); string month_name [12] = {"Gen","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}; if (month < 0 || month > 12) { cout << "Give as argument a number between 1 and 12 corresponding to the chosen month" << endl; return 0; } if (month > 10) { cout << "No data corresponding to the chosen month..yet!" << endl; return 0; } //Get old tree TChain *tx = new TChain("x"); tx->Add(argv[2]); init_ttree(tx, &x); TTree *oldtree = (TTree*)tx; Long64_t nentries = oldtree->GetEntries(); cout<< "Number of entries in the tree : " << nentries << endl; //Create a new file + a clone of old tree in new file char fname[1000]; sprintf(fname,argv[3],(month_name[month - 1]).c_str()); TFile *newfile = new TFile(fname,"recreate"); TTree *newtree = oldtree->CloneTree(0); int lowerRun, upperRun = 0; if (month == 1) { lowerRun = 153941; upperRun = 156054; } if (month == 2) { lowerRun = 156225; upperRun = 159130; } if (month == 3) { lowerRun = 159248; upperRun = 161732; } if (month == 4) { lowerRun = 161846; upperRun = 163726; } if (month == 5) { lowerRun = 163762; upperRun = 166139; } if (month == 6) { lowerRun = 166243; upperRun = 168148; } if (month == 7) { lowerRun = 168266; upperRun = 172266; } if (month == 8) { lowerRun = 172319; upperRun = 174912; } if (month == 9) { lowerRun = 175118; upperRun = 177519; } if (month == 10) { lowerRun = 177624; upperRun = 179998; } for (int i=0; i<nentries; i++) { if (i%10000000==0) cout << "Analyzing entry " << i << endl; oldtree->GetEntry(i); if ( x.run > lowerRun && x.run < upperRun ) newtree->Fill(); } newtree->Print(); newtree->AutoSave(); delete newfile; }
int makePlot_LoI_Momentum( const TString infile = "data/pythia.ep.100.test.root" ) { gStyle->SetOptStat(kFALSE); /*--------------Get Input File--------------*/ TFile *f_pyth = new TFile( infile, "OPEN"); TTree* T = (TTree*)f_pyth->Get("tree"); T->Print(); /*------------------------------------------*/ /*--------------Define Cuts-----------------*/ //TCut Q2_cut = "Q2 > 1"; TCut electron_cut = "p.fKF == 11"; TCut hadron_cut = "abs(p.fKF) > 100"; TCut proton_cut = "p.fKF == 2212"; TCut neutron_cut = "p.fKF == 2112"; TCut Kaon_cut = "abs(p.fKF) == 321 || p.fKF == 311"; TCut Pion_charged_cut = "abs(p.fKF) == 211"; //TCut Pion_cut = "abs(p.fKF) == 211 || p.fKF == 111"; TCut photon_cut = "p.fKF == 22"; TCut mother_cut = "p.fParent == 0"; TCut status_cut = "p.fKS < 10"; TCut eta_cut_n3n2 = "TMath::ASinH(p.fPz/sqrt((p.fPx)**2 + (p.fPy)**2)) > -3 && TMath::ASinH(p.fPz/sqrt((p.fPx)**2 + (p.fPy)**2)) < -2"; TCut eta_cut_n2n1 = "TMath::ASinH(p.fPz/sqrt((p.fPx)**2 + (p.fPy)**2)) > -2 && TMath::ASinH(p.fPz/sqrt((p.fPx)**2 + (p.fPy)**2)) < -1"; TCut eta_cut_n1z0 = "TMath::ASinH(p.fPz/sqrt((p.fPx)**2 + (p.fPy)**2)) > -1 && TMath::ASinH(p.fPz/sqrt((p.fPx)**2 + (p.fPy)**2)) < -0"; /*------------------------------------------*/ /*-------Momentum vs. Pseudorapidity--------*/ /*------------------------------------------*/ /*------------------------------------------*/ /*---------Electrons (LoI Fig. 2-1)---------*/ /*------------------------------------------*/ TH2F *h_peta_e = new TH2F("h_peta_e", "", 100, -4, 3, 100, 0, 50 ); //250x015 10M TCanvas *c_peta_e = new TCanvas( "c_peta_e" ); c_peta_e->SetLogz(); T->Draw("sqrt((p.fPx)**2 + (p.fPy)**2 + (p.fPz)**2 ):TMath::ASinH(p.fPz/sqrt((p.fPx)**2 + (p.fPy)**2))>>h_peta_e", electron_cut && mother_cut && "Q2 > 1", "colz"); h_peta_e->GetXaxis()->SetTitle("Pseudorapidity #eta"); h_peta_e->GetYaxis()->SetTitle("Electron Momentum p_{e-} [GeV]"); // c_p_eta_e->Print("Plots/Pythia_peta_e_10M_250x010.eps"); // c_p_eta_e->Print("Plots/Pythia_peta_e_10M_250x010.png"); /*------------------------------------------*/ /*----------Hadrons (LoI Fig. 2-4)----------*/ /*------------------------------------------*/ TH2F *h_p_eta_h = new TH2F("h_p_eta_h", "", 60,-6,6, 200,0,225); //250x015 10M TCanvas *c_p_eta_h = new TCanvas( "c_p_eta_h" ); // T->Draw("sqrt((p.fPx)**2 + (p.fPy)**2 + (p.fPz)**2 ):TMath::ASinH(p.fPz/sqrt((p.fPx)**2 + (p.fPy)**2))>>h_p_eta_h",hadron_cut && "Q2 > 1 && 0.01 < y < 0.80 && W2 > 10", "colz"); T->Draw("sqrt((p.fPx)**2 + (p.fPy)**2 + (p.fPz)**2 ):TMath::ASinH(p.fPz/sqrt((p.fPx)**2 + (p.fPy)**2))>>h_p_eta_h",hadron_cut && "Q2 > 1 && 0.01 < y < 0.80", "colz"); h_p_eta_h->GetXaxis()->SetTitle("Pseudorapidity #eta"); h_p_eta_h->GetYaxis()->SetTitle("Hadron Momentum p_{Hadron} [GeV]"); c_p_eta_h->SetLogz(); // c_p_eta_h->Print("Plots/Pythia_peta_h_10M_250x010.eps"); // c_p_eta_h->Print("Plots/Pythia_peta_h_10M_250x010.png"); /*------------Momentum Spectra (Figure 2.2)--------------*/ /*-------- -3 < Eta < -2 ---------*/ TH1F* hp_e_n3n2 = new TH1F("hp_e_n3n2", "dN/dp vs. p", 60, 0, 30); TH1F* hp_p_n3n2 = new TH1F("hp_p_n3n2", "dN/dp vs. p", 60, 0, 30); TH1F* hp_y_n3n2 = new TH1F("hp_y_n3n2", "dN/dp vs. p", 60, 0, 30); TCanvas *cp_e_n3n2 = new TCanvas("cp_e_n3n2"); T->Draw("sqrt(p.fPx**2 + p.fPy**2 + p.fPz**2)>>hp_e_n3n2", electron_cut && eta_cut_n3n2 && "Q2 > 0.01", "goff"); T->Draw("sqrt(p.fPx**2 + p.fPy**2 + p.fPz**2)>>hp_p_n3n2", Pion_charged_cut && eta_cut_n3n2 && "Q2 > 0.01", "goff"); T->Draw("sqrt(p.fPx**2 + p.fPy**2 + p.fPz**2)>>hp_y_n3n2", photon_cut && eta_cut_n3n2 && status_cut && "Q2 > 0.01", "goff"); TH1F* htmp_n3n2 = hp_e_n3n2->Clone(); htmp_n3n2->SetTitle(""); htmp_n3n2->GetXaxis()->SetTitle("p [GeV]"); htmp_n3n2->GetYaxis()->SetTitle("dN/dp"); htmp_n3n2->SetMaximum( 0.99e7); htmp_n3n2->Draw(); hp_e_n3n2->SetLineColor(2); hp_e_n3n2->Draw("same"); hp_p_n3n2->SetLineColor(1); hp_p_n3n2->Draw("same"); hp_y_n3n2->SetLineColor(4); hp_y_n3n2->Draw("same"); cp_e_n3n2->SetLogy(); TLegend* leg_n3n2 = new TLegend(0.53,0.67,0.73,0.90); hp_e_n3n2->SetTitle("DIS electron"); hp_p_n3n2->SetTitle("#pi#pm"); hp_y_n3n2->SetTitle("Photons"); leg_n3n2->AddEntry(hp_e_n3n2, "", "L"); leg_n3n2->AddEntry(hp_p_n3n2, "", "L"); leg_n3n2->AddEntry(hp_y_n3n2, "", "L"); leg_n3n2->SetTextSize(0.04); leg_n3n2->Draw(); // cp_e_n3n2->Print("Plots/Pythia_MomSpec_n3n2_10M_250x010.eps"); // cp_e_n3n2->Print("Plots/Pythia_MomSpec_n3n2_10M_250x010.png"); /*Temporary Electron Purity Test*/ /*-------- -2 < Eta < -1 ---------*/ TH1F* hp_e_n2n1 = new TH1F("hp_e_n2n1", "dN/dp vs. p", 60, 0, 30); TH1F* hp_p_n2n1 = new TH1F("hp_p_n2n1", "dN/dp vs. p", 60, 0, 30); TH1F* hp_y_n2n1 = new TH1F("hp_y_n2n1", "dN/dp vs. p", 60, 0, 30); TCanvas *cp_e_n2n1 = new TCanvas("cp_e_n2n1"); T->Draw("sqrt(p.fPx**2 + p.fPy**2 + p.fPz**2)>>hp_e_n2n1", electron_cut && eta_cut_n2n1 && "Q2 > 0.01", "goff"); T->Draw("sqrt(p.fPx**2 + p.fPy**2 + p.fPz**2)>>hp_p_n2n1", Pion_charged_cut && eta_cut_n2n1 && "Q2 > 0.01", "goff"); T->Draw("sqrt(p.fPx**2 + p.fPy**2 + p.fPz**2)>>hp_y_n2n1", photon_cut && eta_cut_n2n1 && status_cut && "Q2 > 0.01", "goff"); TH1F* htmp_n2n1 = hp_e_n2n1->Clone(); htmp_n2n1->SetTitle(""); htmp_n2n1->GetXaxis()->SetTitle("p [GeV]"); htmp_n2n1->GetYaxis()->SetTitle("dN/dp"); htmp_n2n1->SetMaximum( 0.99e7); htmp_n2n1->Draw(); hp_e_n2n1->SetLineColor(2); hp_e_n2n1->Draw("same"); hp_p_n2n1->SetLineColor(1); hp_p_n2n1->Draw("same"); hp_y_n2n1->SetLineColor(4); hp_y_n2n1->Draw("same"); cp_e_n2n1->SetLogy(); TLegend* leg_n2n1 = new TLegend(0.53,0.67,0.73,0.90); hp_e_n2n1->SetTitle("DIS electron"); hp_p_n2n1->SetTitle("#pi#pm"); hp_y_n2n1->SetTitle("Photons"); leg_n2n1->AddEntry(hp_e_n2n1, "", "L"); leg_n2n1->AddEntry(hp_p_n2n1, "", "L"); leg_n2n1->AddEntry(hp_y_n2n1, "", "L"); leg_n2n1->SetTextSize(0.04); leg_n2n1->Draw(); // cp_e_n2n1->Print("Plots/Pythia_MomSpec_n2n1_10M_250x010.eps"); // cp_e_n2n1->Print("Plots/Pythia_MomSpec_n2n1_10M_250x010.png"); /*-------- -1 < Eta < 0 ---------*/ TH1F* hp_e_n1z0 = new TH1F("hp_e_n1z0", "dN/dp vs. p", 60, 0, 30); TH1F* hp_p_n1z0 = new TH1F("hp_p_n1z0", "dN/dp vs. p", 60, 0, 30); TH1F* hp_y_n1z0 = new TH1F("hp_y_n1z0", "dN/dp vs. p", 60, 0, 30); TCanvas *cp_e_n1z0 = new TCanvas("cp_e_n1z0"); T->Draw("sqrt(p.fPx**2 + p.fPy**2 + p.fPz**2)>>hp_e_n1z0", electron_cut && eta_cut_n1z0 && "Q2 > 0.01", "goff"); T->Draw("sqrt(p.fPx**2 + p.fPy**2 + p.fPz**2)>>hp_p_n1z0", Pion_charged_cut && eta_cut_n1z0 && "Q2 > 0.01", "goff"); T->Draw("sqrt(p.fPx**2 + p.fPy**2 + p.fPz**2)>>hp_y_n1z0", photon_cut && eta_cut_n1z0 && status_cut && "Q2 > 0.01", "goff"); TH1F* htmp_n1z0 = hp_e_n1z0->Clone(); htmp_n1z0->SetTitle(""); htmp_n1z0->GetXaxis()->SetTitle("p [GeV]"); htmp_n1z0->GetYaxis()->SetTitle("dN/dp"); htmp_n1z0->SetMaximum( 0.99e7 ); htmp_n1z0->Draw(); hp_e_n1z0->SetLineColor(2); hp_e_n1z0->Draw("same"); hp_p_n1z0->SetLineColor(1); hp_p_n1z0->Draw("same"); hp_y_n1z0->SetLineColor(4); hp_y_n1z0->Draw("same"); cp_e_n1z0->SetLogy(); TLegend* leg_n1z0 = new TLegend(0.53,0.67,0.73,0.90); hp_e_n1z0->SetTitle("DIS electron"); hp_p_n1z0->SetTitle("#pi#pm"); hp_y_n1z0->SetTitle("Photons"); leg_n1z0->AddEntry(hp_e_n1z0, "", "L"); leg_n1z0->AddEntry(hp_p_n1z0, "", "L"); leg_n1z0->AddEntry(hp_y_n1z0, "", "L"); leg_n1z0->SetTextSize(0.04); leg_n1z0->Draw(); // cp_e_n1z0->Print("Plots/Pythia_MomSpec_n1z0_10M_250x010.eps"); // cp_e_n1z0->Print("Plots/Pythia_MomSpec_n1z0_10M_250x010.png"); return 0 ; }
void skimTree(std::string inputFile_) { TFile *f = (TFile*)gROOT->GetListOfFiles()->FindObject(inputFile_.data()); if (!f) { f = new TFile(inputFile_.data()); f->cd(Form("%s:/tree",inputFile_.data())); } TTree* fChain = (TTree*)gDirectory->Get("tree"); cout << "Input file is " << inputFile_ << endl; // rename the output file std::string remword=".root"; size_t pos = inputFile_.find(remword); std::string forOutput = inputFile_; if(pos!= std::string::npos) forOutput.swap(forOutput.erase(pos,remword.length())); std::string endfix = "_filteredtree.root"; std::string outputFile = forOutput + endfix; // now open new root file TFile* newfile_data = new TFile(outputFile.data(),"recreate"); cout << "Output file " << outputFile << endl; // clone tree TTree* newtree = fChain->CloneTree(0); newtree->SetMaxTreeSize(4000000000); cout << "Saving " << endfix << " tree" << endl; Long64_t nentries = fChain->GetEntries(); cout << "nentries = " << nentries << endl; Int_t eventNo=-1; Int_t runNo=-1; vector<int>* trigResults; vector<string>* trigName; bool isData=false; if(forOutput.find("DoubleElectron")!= std::string::npos || forOutput.find("DoubleMu")!= std::string::npos) isData=true; fChain->SetBranchAddress("EvtInfo_EventNum",&eventNo); fChain->SetBranchAddress("EvtInfo_RunNum",&runNo); if(isData){ fChain->SetBranchAddress("trigResults", &trigResults); fChain->SetBranchAddress("trigName", &trigName); } Long64_t nlines=0; vector<runInfo> myList; ifstream fin; if(forOutput.find("DoubleElectron")!= std::string::npos) fin.open("/data4/syu/52X_533_validation/DoubleElectron_common.txt"); else if(forOutput.find("DoubleMu")!= std::string::npos) fin.open("/data4/syu/52X_533_validation/DoubleMu_common.txt"); else if(forOutput.find("GluGlu")!= std::string::npos) fin.open("/data4/syu/52X_533_validation/MC_common.txt"); runInfo tempInfo; fin >> tempInfo.run >> tempInfo.evt; while(!fin.eof()) { nlines++; myList.push_back(tempInfo); fin >> tempInfo.run >> tempInfo.evt; } fin.close(); cout << "There are " << nlines << " lines" << endl; ofstream fout; fout.open(Form("%s_updated",forOutput.data())); Long64_t nPassEvt=0; for (Long64_t jentry=0; jentry<nentries;jentry++) { eventNo = -1; runNo = -1; trigName = 0; trigResults = 0; fChain->GetEntry(jentry); bool passTrigger=false; if(isData){ for(int it=0; it< trigName->size(); it++) { std::string thisTrig= trigName->at(it); int results = trigResults->at(it); // cout << thisTrig << "\t" << results << endl; if(forOutput.find("DoubleElectron")!= std::string::npos && thisTrig.find("HLT_Ele17_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL_Ele8_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL") != std::string::npos && results==1) { passTrigger=true; // cout << "Find HLT_Ele17_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL_Ele8_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL" << endl; break; } if(forOutput.find("DoubleMu")!= std::string::npos && thisTrig.find("HLT_Mu17_Mu8")!= std::string::npos && results==1) { passTrigger=true; // cout << "Find HLT_Mu17_Mu8" << endl; break; } if(forOutput.find("DoubleMu")!= std::string::npos && thisTrig.find("HLT_Mu17_TkMu8")!= std::string::npos && results==1) { passTrigger=true; // cout << "Find HLT_Mu17_TkMu8" << endl; break; } } } if(!passTrigger && isData)continue; bool pass=false; runInfo thisInfo; thisInfo.run = runNo; thisInfo.evt = eventNo; vector<runInfo>::const_iterator location = std::find(myList.begin(), myList.end(), thisInfo); if(location != myList.end()) pass=true; if(!pass)continue; newtree->Fill(); nPassEvt++; fout << runNo << "\t" << eventNo << endl; if (jentry%100==0) printf("%4.1f%% done.\r",(float)jentry/(float)nentries*100.); } newtree->Print(); newtree->AutoSave(); delete newfile_data; fout.close(); cout << "Number of passed events = " << nPassEvt << endl; }
void filter(const int type){ int M_MODE = 0; TChain* tree = new TChain("TEvent"); string fname; switch(type){ case 0://Data tree->Add("/home/vitaly/B0toDh0/Tuples/b2dh_data.root"); fname = string("/home/vitaly/B0toDh0/Tuples/fil_b2dh_data.root"); break; case 11://Signal MC pi0 M_MODE = 1; tree->Add("/home/vitaly/B0toDh0/Tuples/b2dh_sigmcPI0_s7.root"); fname = string("/home/vitaly/B0toDh0/Tuples/fil_b2dh_sigmcPi0_s7.root"); break; case 12://Signal MC eta M_MODE = 2; tree->Add("/home/vitaly/B0toDh0/Tuples/b2dh_sigmcETA_s2.root"); fname = string("/home/vitaly/B0toDh0/Tuples/fil_b2dh_sigmcEta_s2.root"); break; case 13://Signal MC omega M_MODE = 3; tree->Add("/home/vitaly/B0toDh0/Tuples/b2dh_sigmcOMEGA_s5.root"); fname = string("/home/vitaly/B0toDh0/Tuples/fil_b2dh_sigmcOmega_s5.root"); break; case 14://Signal MC rho tree->Add("/home/vitaly/B0toDh0/Tuples/b2dh_sigmcRHO_s1.root"); fname = string("/home/vitaly/B0toDh0/Tuples/fil_b2dh_sigmcRho_s1.root"); break; case 15://Signal MC eta' tree->Add("/home/vitaly/B0toDh0/Tuples/b2dh_sigmcETAP_s1.root"); fname = string("/home/vitaly/B0toDh0/Tuples/fil_b2dh_sigmcETAP_s1.root"); break; case 21://charged tree->Add("/home/vitaly/B0toDh0/Tuples/b2dh_charged_2.root"); tree->Add("/home/vitaly/B0toDh0/Tuples/b2dh_charged_12.root"); fname = string("/home/vitaly/B0toDh0/Tuples/fil_b2dh_charged_2_12.root"); break; case 22://mixed tree->Add("/home/vitaly/B0toDh0/Tuples/b2dh_mixed_2.root"); tree->Add("/home/vitaly/B0toDh0/Tuples/b2dh_mixed_12.root"); fname = string("/home/vitaly/B0toDh0/Tuples/fil_b2dh_mixed_2_12.root"); break; case 23://charm tree->Add("/home/vitaly/B0toDh0/Tuples/b2dh_charm_12.root"); tree->Add("/home/vitaly/B0toDh0/Tuples/b2dh_charm_2.root"); fname = string("/home/vitaly/B0toDh0/Tuples/fil_b2dh_charm_2_12.root"); break; case 24://uds tree->Add("/home/vitaly/B0toDh0/Tuples/b2dh_uds_12.root"); tree->Add("/home/vitaly/B0toDh0/Tuples/b2dh_uds_2.root"); fname = string("/home/vitaly/B0toDh0/Tuples/fil_b2dh_uds_2_12.root"); break; case 2://Generic MC // tree->Add("/home/vitaly/B0toDh0/Tuples/b2dh_gen.root"); // stringstream out; // string path("/home/vitaly/B0toDh0/Tuples/"); vector<string> types; types.push_back(string("charged")); types.push_back(string("mixed")); types.push_back(string("uds")); types.push_back(string("charm")); for(int i=0; i<types.size(); i++){ for(int j=0; j<1; j++){ out.str(""); out << path << "b2dh_" << types[i] << "_" << j << ".root"; tree->Add(out.str().c_str()); } } fname = string("fil_b2dh_gen_0_2.root"); break; case 3://Continuum // tree->Add("/home/vitaly/B0toDh0/Tuples/b2dh_cont.root"); stringstream out; string path("/home/vitaly/B0toDh0/Tuples/"); vector<string> types; types.push_back(string("uds")); types.push_back(string("charm")); for(int i=0; i<types.size(); i++){ for(int j=0; j<6; j++){ out.str(""); out << path << "b2dh_" << types[i] << "_" << j << ".root"; tree->Add(out.str().c_str()); } } fname = string("fil_b2dh_cont.root"); break; case 4://Custom tree->Add("/home/vitaly/B0toDh0/Tuples/b2dh_charged_10.root"); tree->Add("/home/vitaly/B0toDh0/Tuples/b2dh_charged_0.root"); tree->Add("/home/vitaly/B0toDh0/Tuples/b2dh_mixed_10.root"); tree->Add("/home/vitaly/B0toDh0/Tuples/b2dh_mixed_0.root"); tree->Add("/home/vitaly/B0toDh0/Tuples/b2dh_charged_11.root"); tree->Add("/home/vitaly/B0toDh0/Tuples/b2dh_charged_1.root"); tree->Add("/home/vitaly/B0toDh0/Tuples/b2dh_mixed_11.root"); tree->Add("/home/vitaly/B0toDh0/Tuples/b2dh_mixed_1.root"); tree->Add("/home/vitaly/B0toDh0/Tuples/fil_b2dh_charm_0_10.root"); tree->Add("/home/vitaly/B0toDh0/Tuples/fil_b2dh_uds_0_10.root"); fname = string("fil_b2dh_gen.root"); break; default: return; } Double_t p_d0,p_h0,p_ks,p_pi0_h0,p_pip_h0,p_pim_h0,pi0_chi2,egamma,cos_thr,cos_hel,thr_sig,thr_oth; Int_t ndf_tag_vtx,phsp,bin,exp,run,evtn; Int_t b0f,d0f; Double_t k0mm2,k0et,k0hso00,k0hso02,k0hso04,k0hso10,k0hso12,k0hso14,k0hso20,k0hso22,k0hso24,k0hoo0,k0hoo1,k0hoo2,k0hoo3,k0hoo4; Double_t k1mm2,k1et,k1hso00,k1hso01,k1hso02,k1hso03,k1hso04,k1hso10,k1hso12,k1hso14,k1hso20,k1hso22,k1hso24,k1hoo0,k1hoo1,k1hoo2,k1hoo3,k1hoo4; Double_t mbc,de,mp,mm,dz,atckpi_max,mpi0,mh0,mk; Double_t ks_dr,ks_dz,ks_dphi,ks_fl,tag_LH,tag_LH_err; Double_t mp_mc,mm_mc,d0_t_mc,dt_mc,dz_mc,bin_mc,flv_mc,d0_flv_mc; // Double_t z_sig_d0; // Double_t sz_sig_d0; // Double_t dz_mc_sig_d0; Double_t chi2_vtx_d0, chi2_mass_d0; Int_t good_icpv;//,good_icpv_d0; Int_t mode,h0mode,h0f,pi0f; Double_t z_sig,z_asc; Double_t sz_sig,sz_asc; Int_t ntrk_sig,ntrk_asc,ndf_z_sig,ndf_z_asc; Double_t chisq_z_sig,chisq_z_asc,h0_chi2; Double_t cl_z_sig,cl_z_asc; Double_t costhB,costhBcms,Ecms; Double_t t_sig_mc,z_sig_mc,t_asc_mc,z_asc_mc; Double_t dz_mc_sig, dz_mc_asc; Double_t z_upsilon; // Double_t dz_pull_sig,dz_pull_sig_d0,dz_pull_asc; Int_t nptag; tree->Print(); TFile *ofile = new TFile(fname.c_str(),"RECREATE"); TTree* TEvent = new TTree("TEvent","TEvent"); tree->SetBranchAddress("exp",&exp); tree->SetBranchAddress("run",&run); tree->SetBranchAddress("evtn",&evtn); tree->SetBranchAddress("p_d0",&p_d0); tree->SetBranchAddress("p_h0",&p_h0); tree->SetBranchAddress("p_ks",&p_ks); tree->SetBranchAddress("p_pi0_h0",&p_pi0_h0); tree->SetBranchAddress("p_pip_h0",&p_pip_h0); tree->SetBranchAddress("p_pim_h0",&p_pim_h0); tree->SetBranchAddress("egamma",&egamma); tree->SetBranchAddress("cos_thr",&cos_thr); tree->SetBranchAddress("cos_hel",&cos_hel); tree->SetBranchAddress("thr_sig",&thr_sig); tree->SetBranchAddress("thr_oth",&thr_oth); tree->SetBranchAddress("ndf_tag_vtx",&ndf_tag_vtx); tree->SetBranchAddress("thr_oth",&thr_oth); tree->SetBranchAddress("phsp",&phsp); tree->SetBranchAddress("bin",&bin); Double_t px_pim,py_pim,pz_pim; Double_t px_pip,py_pip,pz_pip; Double_t px_ks,py_ks,pz_ks; tree->SetBranchAddress("px_pim",&px_pim); tree->SetBranchAddress("py_pim",&py_pim); tree->SetBranchAddress("pz_pim",&pz_pim); tree->SetBranchAddress("px_pip",&px_pip); tree->SetBranchAddress("py_pip",&py_pip); tree->SetBranchAddress("pz_pip",&pz_pip); tree->SetBranchAddress("px_ks",&px_ks); tree->SetBranchAddress("py_ks",&py_ks); tree->SetBranchAddress("pz_ks",&pz_ks); TEvent->Branch("px_pim",&px_pim,"px_pim/D"); TEvent->Branch("py_pim",&py_pim,"py_pim/D"); TEvent->Branch("pz_pim",&pz_pim,"pz_pim/D"); TEvent->Branch("px_pip",&px_pip,"px_pip/D"); TEvent->Branch("py_pip",&py_pip,"py_pip/D"); TEvent->Branch("pz_pip",&pz_pip,"pz_pip/D"); TEvent->Branch("px_ks",&px_ks,"px_ks/D"); TEvent->Branch("py_ks",&py_ks,"py_ks/D"); TEvent->Branch("pz_ks",&pz_ks,"pz_ks/D"); Int_t b0id,d0id,h0id,dst0id,dst0f,etapid,etapf; tree->SetBranchAddress("chi2_vtx_d0",&chi2_vtx_d0); tree->SetBranchAddress("chi2_mass_d0",&chi2_mass_d0); TEvent->Branch("chi2_vtx_d0",&chi2_vtx_d0,"chi2_vtx_d0/D"); TEvent->Branch("chi2_mass_d0",&chi2_mass_d0,"chi2_mass_d0/D"); TEvent->Branch("good_icpv",&good_icpv,"good_icpv/I"); if(type){ tree->SetBranchAddress("b0id",&b0id); tree->SetBranchAddress("b0f",&b0f); tree->SetBranchAddress("d0id",&d0id); tree->SetBranchAddress("d0f",&d0f); tree->SetBranchAddress("h0id",&h0id); tree->SetBranchAddress("h0f",&h0f); tree->SetBranchAddress("pi0f",&pi0f); tree->SetBranchAddress("dst0id",&dst0id); tree->SetBranchAddress("dst0f",&dst0f); tree->SetBranchAddress("etapid",&etapid); tree->SetBranchAddress("etapf",&etapf); TEvent->Branch("b0id",&b0id,"b0id/I"); TEvent->Branch("b0f",&b0f,"b0f/I"); TEvent->Branch("d0id",&d0id,"d0id/I"); TEvent->Branch("d0f",&d0f,"d0f/I"); TEvent->Branch("h0id",&h0id,"h0id/I"); TEvent->Branch("h0f",&h0f,"h0f/I"); TEvent->Branch("pi0f",&pi0f,"pi0f/I"); TEvent->Branch("dst0id",&dst0id,"dst0id/I"); TEvent->Branch("dst0f",&dst0f,"dst0f/I"); TEvent->Branch("etapid",&etapid,"etapid/I"); TEvent->Branch("etapf",&etapf,"etapf/I"); Double_t mp_raw, mm_raw; if(type>10 && type<20 || type == 111){ tree->SetBranchAddress("mp_mc",&mp_mc); tree->SetBranchAddress("mm_mc",&mm_mc); tree->SetBranchAddress("mp_raw",&mp_raw); tree->SetBranchAddress("mm_raw",&mm_raw); tree->SetBranchAddress("d0_t_mc",&d0_t_mc); tree->SetBranchAddress("z_upsilon",&z_upsilon); tree->SetBranchAddress("bin_mc",&bin_mc); tree->SetBranchAddress("flv_mc",&flv_mc); tree->SetBranchAddress("d0_flv_mc",&d0_flv_mc); tree->SetBranchAddress("t_sig_mc",&t_sig_mc); tree->SetBranchAddress("z_sig_mc",&z_sig_mc); tree->SetBranchAddress("t_asc_mc",&t_asc_mc); tree->SetBranchAddress("z_asc_mc",&z_asc_mc); TEvent->Branch("mp_mc",&mp_mc,"mp_mc/D"); TEvent->Branch("mm_mc",&mm_mc,"mm_mc/D"); TEvent->Branch("mp_raw",&mp_raw,"mp_raw/D"); TEvent->Branch("mm_raw",&mm_raw,"mm_raw/D"); TEvent->Branch("d0_t_mc",&d0_t_mc,"d0_t_mc/D"); TEvent->Branch("dt_mc",&dt_mc,"dt_mc/D"); TEvent->Branch("dz_mc",&dz_mc,"dz_mc/D"); TEvent->Branch("dz_mc_sig",&dz_mc_sig,"dz_mc_sig/D"); TEvent->Branch("dz_mc_asc",&dz_mc_asc,"dz_mc_asc/D"); // TEvent->Branch("dz_pull_sig",&dz_pull_sig,"dz_pull_sig/D"); // if(type == 12 || type == 13 || type == 14){ // tree->SetBranchAddress("z_sig_d0",&z_sig_d0); // tree->SetBranchAddress("sz_sig_d0",&sz_sig_d0); // TEvent->Branch("good_icpv_d0",&good_icpv_d0,"good_icpv_d0/I"); // TEvent->Branch("dz_mc_sig_d0",&dz_mc_sig_d0,"dz_mc_sig_d0/D"); // TEvent->Branch("dz_pull_sig_d0",&dz_pull_sig_d0,"dz_pull_sig_d0/D"); // TEvent->Branch("z_sig_d0",&z_sig_d0,"z_sig_d0/D"); // TEvent->Branch("sz_sig_d0",&sz_sig_d0,"sz_sig_d0/D"); // } // TEvent->Branch("dz_pull_asc",&dz_pull_asc,"dz_pull_asc/D"); TEvent->Branch("bin_mc",&bin_mc,"bin_mc/I"); TEvent->Branch("flv_mc",&flv_mc,"flv_mc/I"); TEvent->Branch("d0_flv_mc",&d0_flv_mc,"d0_flv_mc/I"); TEvent->Branch("t_sig_mc",&t_sig_mc,"t_sig_mc/D"); TEvent->Branch("z_sig_mc",&z_sig_mc,"z_sig_mc/D"); TEvent->Branch("t_asc_mc",&t_asc_mc,"t_asc_mc/D"); TEvent->Branch("z_asc_mc",&z_asc_mc,"z_asc_mc/D"); } } tree->SetBranchAddress("nptag",&nptag); tree->SetBranchAddress("mbc",&mbc); tree->SetBranchAddress("de",&de); tree->SetBranchAddress("mp",&mp); tree->SetBranchAddress("mm",&mm); tree->SetBranchAddress("atckpi_max",&atckpi_max); tree->SetBranchAddress("mh0_raw",&mh0); tree->SetBranchAddress("mpi0_raw",&mpi0); tree->SetBranchAddress("mks_raw",&mk); Double_t md, md_raw, md_fit, mdpip, mdpim; tree->SetBranchAddress("md0_raw",&md_raw); tree->SetBranchAddress("md0_fit",&md_fit); tree->SetBranchAddress("md0",&md); tree->SetBranchAddress("md0pip",&mdpip); tree->SetBranchAddress("md0pim",&mdpim); TEvent->Branch("md",&md,"md/D"); TEvent->Branch("md_raw",&md_raw,"md_raw/D"); TEvent->Branch("md_fit",&md_fit,"md_fit/D"); TEvent->Branch("mdpip",&mdpip,"mdpip/D"); TEvent->Branch("mdpim",&mdpim,"mdpim/D"); Double_t mdst0, metap, dmdst0, dmetap; tree->SetBranchAddress("mdst0",&mdst0); tree->SetBranchAddress("dmdst0",&dmdst0); tree->SetBranchAddress("metap",&metap); tree->SetBranchAddress("dmetap",&dmetap); TEvent->Branch("mdst0",&mdst0,"mdst0/D"); TEvent->Branch("dmdst0",&dmdst0,"dmdst0/D"); TEvent->Branch("metap",&metap,"metap/D"); TEvent->Branch("dmetap",&dmetap,"dmetap/D"); tree->SetBranchAddress("mode",&mode); tree->SetBranchAddress("h0mode",&h0mode); tree->SetBranchAddress("z_sig",&z_sig); tree->SetBranchAddress("z_asc",&z_asc); tree->SetBranchAddress("sz_sig",&sz_sig); tree->SetBranchAddress("sz_asc",&sz_asc); tree->SetBranchAddress("ntrk_sig",&ntrk_sig); tree->SetBranchAddress("ntrk_asc",&ntrk_asc); tree->SetBranchAddress("ndf_z_sig",&ndf_z_sig); tree->SetBranchAddress("ndf_z_asc",&ndf_z_asc); tree->SetBranchAddress("chisq_z_sig",&chisq_z_sig); tree->SetBranchAddress("chisq_z_asc",&chisq_z_asc); tree->SetBranchAddress("cl_z_sig",&cl_z_sig); tree->SetBranchAddress("cl_z_asc",&cl_z_asc); tree->SetBranchAddress("pi0_chi2",&pi0_chi2); tree->SetBranchAddress("h0_chi2",&h0_chi2); TEvent->Branch("h0_chi2",&h0_chi2,"h0_chi2/D"); TEvent->Branch("pi0_chi2",&pi0_chi2,"pi0_chi2/D"); tree->SetBranchAddress("costhB",&costhB); tree->SetBranchAddress("costhBcms",&costhBcms); tree->SetBranchAddress("Ecms",&Ecms); tree->SetBranchAddress("tag_LH",&tag_LH); tree->SetBranchAddress("tag_LH_err",&tag_LH_err); tree->SetBranchAddress("k0mm2",&k0mm2); tree->SetBranchAddress("k0et",&k0et); tree->SetBranchAddress("k0hso00",&k0hso00); tree->SetBranchAddress("k0hso02",&k0hso02); tree->SetBranchAddress("k0hso04",&k0hso04); tree->SetBranchAddress("k0hso10",&k0hso10); tree->SetBranchAddress("k0hso12",&k0hso12); tree->SetBranchAddress("k0hso14",&k0hso14); tree->SetBranchAddress("k0hso20",&k0hso20); tree->SetBranchAddress("k0hso22",&k0hso22); tree->SetBranchAddress("k0hso24",&k0hso24); tree->SetBranchAddress("k0hoo0",&k0hoo0); tree->SetBranchAddress("k0hoo1",&k0hoo1); tree->SetBranchAddress("k0hoo2",&k0hoo2); tree->SetBranchAddress("k0hoo3",&k0hoo3); tree->SetBranchAddress("k0hoo4",&k0hoo4); tree->SetBranchAddress("k1mm2",&k1mm2); tree->SetBranchAddress("k1et",&k1et); tree->SetBranchAddress("k1hso00",&k1hso00); tree->SetBranchAddress("k1hso01",&k1hso01); tree->SetBranchAddress("k1hso02",&k1hso02); tree->SetBranchAddress("k1hso03",&k1hso03); tree->SetBranchAddress("k1hso04",&k1hso04); tree->SetBranchAddress("k1hso10",&k1hso10); tree->SetBranchAddress("k1hso12",&k1hso12); tree->SetBranchAddress("k1hso14",&k1hso14); tree->SetBranchAddress("k1hso20",&k1hso20); tree->SetBranchAddress("k1hso22",&k1hso22); tree->SetBranchAddress("k1hso24",&k1hso24); tree->SetBranchAddress("k1hoo0",&k1hoo0); tree->SetBranchAddress("k1hoo1",&k1hoo1); tree->SetBranchAddress("k1hoo2",&k1hoo2); tree->SetBranchAddress("k1hoo3",&k1hoo3); tree->SetBranchAddress("k1hoo4",&k1hoo4); TEvent->Branch("exp",&exp,"exp/I"); TEvent->Branch("run",&run,"run/I"); TEvent->Branch("evtn",&evtn,"evtn/I"); TEvent->Branch("p_d0",&p_d0,"p_d0/D"); TEvent->Branch("p_h0",&p_h0,"p_h0/D"); TEvent->Branch("p_ks",&p_ks,"p_ks/D"); TEvent->Branch("p_pi0_h0",&p_pi0_h0,"p_pi0_h0/D"); TEvent->Branch("p_pip_h0",&p_pip_h0,"p_pip_h0/D"); TEvent->Branch("p_pim_h0",&p_pim_h0,"p_pim_h0/D"); TEvent->Branch("egamma",&egamma,"egamma/D"); TEvent->Branch("cos_thr",&cos_thr,"cos_thr/D"); TEvent->Branch("cos_hel",&cos_hel,"cos_hel/D"); TEvent->Branch("thr_sig",&thr_sig,"thr_sig/D"); TEvent->Branch("thr_oth",&thr_oth,"thr_oth/D"); TEvent->Branch("ndf_tag_vtx",&ndf_tag_vtx,"ndf_tag_vtx/I"); TEvent->Branch("thr_oth",&thr_oth,"thr_oth/D"); TEvent->Branch("phsp",&phsp,"phsp/I"); TEvent->Branch("bin",&bin,"bin/I"); TEvent->Branch("nptag",&nptag,"nptag/I"); TEvent->Branch("mbc",&mbc,"mbc/D"); TEvent->Branch("de",&de,"de/D"); TEvent->Branch("mp",&mp,"mp/D"); TEvent->Branch("mm",&mm,"mm/D"); TEvent->Branch("dz",&dz,"dz/D"); TEvent->Branch("atckpi_max",&atckpi_max,"atckpi_max/D"); TEvent->Branch("mh0",&mh0); TEvent->Branch("mpi0",&mpi0,"mpi0/D"); TEvent->Branch("mk",&mk,"mk/D"); TEvent->Branch("mode",&mode,"mode/I"); TEvent->Branch("h0mode",&h0mode,"h0mode/I"); TEvent->Branch("z_sig",&z_sig,"z_sig/D"); TEvent->Branch("z_asc",&z_asc,"z_asc/D"); TEvent->Branch("sz_sig",&sz_sig,"sz_sig/D"); TEvent->Branch("sz_asc",&sz_asc,"sz_asc/D"); TEvent->Branch("ntrk_sig",&ntrk_sig,"ntrk_sig/I"); TEvent->Branch("ntrk_asc",&ntrk_asc,"ntrk_asc/I"); TEvent->Branch("ndf_z_sig",&ndf_z_sig,"ndf_z_sig/I"); TEvent->Branch("ndf_z_asc",&ndf_z_asc,"ndf_z_asc/I"); TEvent->Branch("chisq_z_sig",&chisq_z_sig,"chisq_z_sig/D"); TEvent->Branch("chisq_z_asc",&chisq_z_asc,"chisq_z_asc/D"); TEvent->Branch("cl_z_sig",&cl_z_sig,"cl_z_sig/D"); TEvent->Branch("cl_z_asc",&cl_z_asc,"cl_z_asc/D"); TEvent->Branch("costhB",&costhB,"costhB/D"); TEvent->Branch("costhBcms",&costhBcms,"costhBcms/D"); TEvent->Branch("Ecms",&Ecms,"Ecm/D"); TEvent->Branch("ks_dr",&ks_dr,"ks_dr/D"); TEvent->Branch("ks_dz",&ks_dz,"ks_dz/D"); TEvent->Branch("ks_dphi",&ks_dphi,"ks_dphi/D"); TEvent->Branch("ks_fl",&ks_fl,"ks_fl/D"); TEvent->Branch("tag_LH",&tag_LH,"tag_LH/D"); TEvent->Branch("tag_LH_err",&tag_LH_err,"tag_LH_err/D"); TEvent->Branch("k0mm2",&k0mm2,"k0mm2/D"); TEvent->Branch("k0et",&k0et,"k0et/D"); TEvent->Branch("k0hso00",&k0hso00,"k0hso00/D"); TEvent->Branch("k0hso02",&k0hso02,"k0hso02/D"); TEvent->Branch("k0hso04",&k0hso04,"k0hso04/D"); TEvent->Branch("k0hso10",&k0hso10,"k0hso10/D"); TEvent->Branch("k0hso12",&k0hso12,"k0hso12/D"); TEvent->Branch("k0hso14",&k0hso14,"k0hso14/D"); TEvent->Branch("k0hso20",&k0hso20,"k0hso20/D"); TEvent->Branch("k0hso22",&k0hso22,"k0hso22/D"); TEvent->Branch("k0hso24",&k0hso24,"k0hso24/D"); TEvent->Branch("k0hoo0",&k0hoo0,"k0hoo0/D"); TEvent->Branch("k0hoo1",&k0hoo1,"k0hoo1/D"); TEvent->Branch("k0hoo2",&k0hoo2,"k0hoo2/D"); TEvent->Branch("k0hoo3",&k0hoo3,"k0hoo3/D"); TEvent->Branch("k0hoo4",&k0hoo4,"k0hoo4/D"); TEvent->Branch("k1mm2",&k1mm2,"k1mm2/D"); TEvent->Branch("k1et",&k1et,"k1et/D"); TEvent->Branch("k1hso00",&k1hso00,"k1hso00/D"); TEvent->Branch("k1hso01",&k1hso01,"k1hso01/D"); TEvent->Branch("k1hso02",&k1hso02,"k1hso02/D"); TEvent->Branch("k1hso03",&k1hso03,"k1hso03/D"); TEvent->Branch("k1hso04",&k1hso04,"k1hso04/D"); TEvent->Branch("k1hso10",&k1hso10,"k1hso10/D"); TEvent->Branch("k1hso12",&k1hso12,"k1hso12/D"); TEvent->Branch("k1hso14",&k1hso14,"k1hso14/D"); TEvent->Branch("k1hso20",&k1hso20,"k1hso20/D"); TEvent->Branch("k1hso22",&k1hso22,"k1hso22/D"); TEvent->Branch("k1hso24",&k1hso24,"k1hso24/D"); TEvent->Branch("k1hoo0",&k1hoo0,"k1hoo0/D"); TEvent->Branch("k1hoo1",&k1hoo1,"k1hoo1/D"); TEvent->Branch("k1hoo2",&k1hoo2,"k1hoo2/D"); TEvent->Branch("k1hoo3",&k1hoo3,"k1hoo3/D"); TEvent->Branch("k1hoo4",&k1hoo4,"k1hoo4/D"); const int NTot = tree->GetEntries(); for(int i=1; i<NTot; i++){ if(!(i%10000)){ cout << i << " events" << endl;} tree->GetEvent(i); if((b0f == 0 || b0f<-1) && type) continue; if(M_MODE){ if(M_MODE != mode) continue; } // if(type == 11){ // if((b0f != 1) && (b0f != 5) && (b0f != 10)) continue; // } // if(type == 11 || type == 12 || type == 13 || type == 14){ // if(b0f < 1) continue; // } // if(type == 3){ // if(!(b0f != 1 && b0f != 10 && !(d0f == 1 && (b0f == 5 || b0f == 4)))) continue; // } // if(type == 2){ // } // if(md_raw<(DMass-md_cut) || md_raw>(DMass+md_cut)) continue; // if(!(mode == 2 && h0mode == 10) && mode != 14){ // if(mpi0<(Pi0Mass-mpi0_cut) || mpi0>(Pi0Mass+mpi0_cut)) continue; // } if(mk<(KMass-mk_cut) || mk>(KMass+mk_cut)) continue; // if(chi2_vtx_d0>1000) continue; z_sig *= 10; z_asc *=10;// z_sig_d0 *= 10; // dz_mc_sig_d0 = z_sig_d0-z_sig_mc; dz_mc_sig = z_sig-z_sig_mc; dz_mc_asc = z_asc-z_asc_mc; dz = z_sig - z_asc; dt_mc = t_sig_mc - t_asc_mc; dz_mc = z_sig_mc - z_asc_mc; sz_sig = 10.*TMath::Sqrt(sz_sig); // sz_sig_d0 = 10.*TMath::Sqrt(sz_sig_d0); sz_asc = 10.*TMath::Sqrt(sz_asc); // dz_pull_sig = dz_mc_sig/sz_sig; // dz_pull_sig_d0 = dz_mc_sig_d0/sz_sig_d0; // dz_pull_asc = dz_mc_asc/sz_asc; // * Standatd ICPV cuts * // good_icpv = IsGoodICPV(ndf_z_sig,sz_sig,chisq_z_sig,ndf_z_asc,sz_asc,chisq_z_asc); // good_icpv_d0 = IsGoodICPV(0,sz_sig_d0,1,ndf_z_asc,sz_asc,chisq_z_asc); // * ////////////////// * // TEvent->Fill(); } TEvent->Print(); TEvent->Write(); ofile->Close(); return; }
int main (int argc, char *argv[]) { cout << endl; cout << " ,-----------------------," << endl; cout << " | Starting analysis |" << endl; cout << " `-----------------------`" << endl; cout << endl; // ################################## // # Some parameters for the user # // ################################## bool doHistoManager = false; // False will not produce histos bool doLatexOutput = true; // False will not produce latex table bool doPileUpReweigthing = false; // False will not use pileup reweighting // (can be overwritten by argv[1]) string defaultConfiguration("../../config/TTbarMETAnalysis.xml"); // (can be overwritten by argv[2]) string defaultLatexTableName("CutflowTable"); // (can be overwritten by argv[3]) string defaultRootOutputName("TTbarMETanalysis.root"); // ############################ // # Initializing variables # // ############################ INFO1_MSG << "Initializing variables..." << endl; vector < Dataset > datasets; TTbarMetSelection sel; float Luminosity = 0; float LumiError = 0.; int DataType = 0; // DataType : 0: MC - 1: Data - 2 Data & MC int verbosity = -1; reweight::LumiReWeighting *LumiWeights; IPHCTree::NTEvent * event = 0; std::vector<std::string> dileptonCol; dileptonCol.push_back("l+jets"); dileptonCol.push_back("ll"); dileptonCol.push_back("llHadrTau"); dileptonCol.push_back("llHadrTau3+"); std::vector<std::string> dileptonRow; dileptonRow.push_back("baseline"); dileptonRow.push_back("MET"); dileptonRow.push_back("stdVeto"); dileptonRow.push_back("stdVetoEff"); dileptonRow.push_back("vetoTest0"); dileptonRow.push_back("vetoTest0Eff"); dileptonRow.push_back("vetoTest1"); dileptonRow.push_back("vetoTest1Eff"); dileptonRow.push_back("vetoTest2"); dileptonRow.push_back("vetoTest2Eff"); dileptonRow.push_back("vetoTest3"); dileptonRow.push_back("vetoTest3Eff"); // Reading parameters from argv // -> configuration file string xmlFileName; if (argc > 1) xmlFileName = string(argv[1]); else xmlFileName = defaultConfiguration; // -> root output name string rootOutputName; if (argc > 2) rootOutputName = string(argv[2]); else rootOutputName = defaultRootOutputName; // -> latex table name string latexTableName; if (argc > 3) latexTableName = string(argv[3]); else latexTableName = defaultLatexTableName; // ############################# // # Loading configuration # // ############################# cout << endl; INFO1_MSG << "Loading configuration..." << endl; cout << " (config : " << xmlFileName << ")" << endl; AnalysisEnvironmentLoader anaEL (xmlFileName); anaEL.LoadSamples (datasets); // now the list of datasets written in the xml file is known anaEL.LoadSelection (sel); // now the parameters for the selection are given to the selection // no specific TTbarMET parameters anaEL.LoadGeneralInfo (DataType, Luminosity, LumiError, verbosity); // ######################################### // # Creating tables and histomanagers # // ######################################### cout << endl; INFO1_MSG << "Creating tables and histomanagers..." << endl; // Stuff TFile dileptonTreeFile("dileptonTree.root","RECREATE","Tree for Dilepton background study"); TTree *dileptonTree = new TTree("dileptonTree","Tree for Dilepton background study"); dileptonTree->Branch("dileptonData",&dileptonDataForTree,"iso_02:iso_03:iso_03_pT1GeV:iso_04:iso_05:iso_05_no01:iso_05_no015:iso_05_no015_pT1GeV:iso_05_no02:iso_045_no015:iso_055_no015:iso_05_no015_pTEqualIso02:hadronicMC_dRmeanDecay:hadronicMC_dRmaxDecay:hadronicMC_dRmeanChargedDecay:hadronicMC_dRmaxChargedDecay:hadronicMC_pTminChargedDecay:hadronicMC_pTmeanChargedDecay:hadronicMC_pTmaxChargedDecay:bestIso03_iso_03:bestIso03_iso_05_no015:bestIso03_iso_05_no01:bestIso03_iso_05_ntrk_01:bestIso03_iso_05_ntrk_015:bestIso03_iso_05_ntrk_015_pT1GeV:bestIso05no015_iso_03:bestIso05no015_iso_05_no015:bestIso05no015_iso_05_no01:bestIso05no015_iso_05_ntrk_01:bestIso05no015_iso_05_ntrk_015:bestIso05no015_iso_05_ntrk_015_pT1GeV:bestIso05no01_iso_03:bestIso05no01_iso_05_no015:bestIso05no01_iso_05_no01:bestIso05no01_iso_05_ntrk_01:bestIso05no01_iso_05_ntrk_015:bestIso05no01_iso_05_ntrk_015_pT1GeV:eventInfo_isSemilep:eventInfo_isDilep:eventInfo_haveTau:eventInfo_haveHadronicTau:eventInfo_haveHadronicTau3"); TableScrewdriver dileptonTable(dileptonCol,dileptonRow); dileptonTable.PrintTable(); // Tables SelectionTable selTable_e (sel.GetCutList (), datasets, string ("e")); SelectionTable selTable_mu (sel.GetCutList (), datasets, string ("µ")); SelectionTable selTable_l (sel.GetCutList (), datasets, string ("lepton")); // Histomanagers TTbarMetHistoManager histoManager; if(doHistoManager) { histoManager.LoadDatasets(datasets); histoManager.LoadSelectionSteps(sel.GetCutList ()); histoManager.LoadChannels(sel.GetChannelList ()); histoManager.CreateHistos(); } // HistoManager specific to Dilepton background analysis DileptonBkgAnaHistoManager histoManagerDileptonBkg; if(doHistoManager) { histoManagerDileptonBkg.LoadDatasets (datasets); histoManagerDileptonBkg.LoadSelectionSteps (sel.GetCutList ()); histoManagerDileptonBkg.LoadChannels (sel.GetChannelList ()); histoManagerDileptonBkg.CreateHistos (); } // ############################## // # Printing general infos # // ############################## cout << endl; cout << " -----------------------------" << endl; cout << " Verbosity mode : " << verbosity << endl; cout << " Luminosity : " << Luminosity << endl; cout << " DataType (whole config) : "; switch (DataType) { case 0: { cout << "MC" << endl; break; } case 1: { cout << "Data" << endl; break; } case 2: { cout << "Data & MC" << endl; break; } default: { cout << "Unknwon" << endl; break; } } cout << " -----------------------------" << endl; // ######################################### // # Start loop over the dataset infos # // ######################################### if (verbosity > 0) { cout << endl; cout << " ,---------------------------------," << endl; cout << " | Starting loop over datasets |" << endl; cout << " `---------------------------------`" << endl; cout << endl; } int nEvents_tot; for (unsigned int datasetId = 0; datasetId < datasets.size (); datasetId++) { // ######################## // # Load the dataset # // ######################## INFO1_MSG << "Loading next dataset..." << endl; datasets[datasetId].eventTree()->SetBranchAddress ("NTEvent", &event); unsigned int nEvents = static_cast<unsigned int>(datasets[datasetId].eventTree()->GetEntries ()); nEvents_tot = nEvents; if (verbosity > 2) { cout << endl; cout << " [ Dataset n°" << datasetId+1 << " ]" << endl; cout << " " << datasets[datasetId].Name() << endl; cout << endl; INFO1_MSG << " NEvents total : " << nEvents << endl; INFO1_MSG << "NEvents to run over : " << datasets[datasetId].NofEvtsToRunOver() << endl; cout << endl; } // ######################## // # Load the pile-up # // ######################## INFO1_MSG << "Loading pile-up informations..." << endl; // PU from JL's code if (datasets[datasetId].isData() == false) { // if(datasets[datasetId].Name() == "DY1" || datasets[datasetId].Name() == "signal" ){ // string datafile = "/opt/sbg/data/data1/cms/ccollard/CMSSW/CMSSW_4_2_8_patch7/src/NTuple/NTupleAnalysis/macros/data/PUdata.root"; // string mcfile = "/opt/sbg/data/data1/cms/ccollard/CMSSW/CMSSW_4_2_8_patch7/src/NTuple/NTupleAnalysis/macros/data/PU3DMC_Fall11.root"; // // LumiWeights = new reweight::LumiReWeighting(mcfile, datafile, "histoMCPU", "pileup" ); // } // else{ string datafile = "/opt/sbg/data/data1/cms/ccollard/CMSSW/CMSSW_4_2_8_patch7/src/NTuple/NTupleAnalysis/macros/data/default73.5mb.root"; string mcfile = "/opt/sbg/data/data1/cms/ccollard/CMSSW/CMSSW_4_2_8_patch7/src/NTuple/NTupleAnalysis/macros/data/PU3DMC.root"; LumiWeights = new reweight::LumiReWeighting(mcfile, datafile, "histoMCPU", "pileup" ); LumiWeights->weight3D_init( 1. ); // } } // ############################ // # Loop over the events # // ############################ if (verbosity > 0) { cout << endl; cout << " ,-------------------------------," << endl; cout << " | Starting loop over events |" << endl; cout << " `-------------------------------`" << endl; cout << endl; } for (unsigned int ievt = 0; ievt < datasets[datasetId].NofEvtsToRunOver(); ievt++) { // Display some information if (verbosity > 3) { INFO1_MSG << "run: " << event->general.runNb; std::cout << " lumi: " << event->general.lumiblock; std::cout << " event: " << event->general.eventNb; std::cout << std::endl; } if (ievt % 100000 == 0) printProgressBar(ievt,datasets[datasetId].NofEvtsToRunOver()); // Load the event datasets[datasetId].eventTree()->GetEntry(ievt); IPHCTree::NTTransient::InitializeAfterReading(event); int eventId = event->general.eventNb; sel.LoadEvent(event); // Get the weight for pile-up reweighting float weight = 1.; if (doPileUpReweigthing) { if(datasets[datasetId].isData() == false) weight = datasets[datasetId].NormFactor()*Luminosity; //if Data , weight = 1 float weightpu=1.; if(datasets[datasetId].isData() == false) { // MC // if( datasets[datasetId].Name() == "DY1" || datasets[datasetId].Name() == "signal") // { // double ave_npu = (event->pileup.before_npu+event->pileup.intime_npu+event->pileup.after_npu)/3.; // weightpu = LumiWeights->ITweight3BX(ave_npu); // } // else // { weightpu = LumiWeights->weight3D(event->pileup.before_npu, event->pileup.intime_npu, event->pileup.after_npu); // } // weight *= weightpu; //if Data , weight = 1 } // else // { // // DATA // JEC_L2L3Residuals.ApplyCorrections(event); // n'appliquer la correction que pour les donnees // } } // Apply full selection int triggerME = 0; int selLastStep = sel.doFullSelection (&(datasets[datasetId]), string("all"),&triggerME); // Get trigger info from selection bool trigger_e = false; bool trigger_mu = false; if (triggerME % 1 == 1) trigger_e = true; if (triggerME >= 10) trigger_mu = true; // Also get the lepton type int lep = sel.GetLeptonType(); // Fill the table // 1. No Selection selTable_e.Fill( datasetId, 0, weight); selTable_mu.Fill(datasetId, 0, weight); selTable_l.Fill( datasetId, 0, weight); // 2. Trigger if (selLastStep > 0) { selTable_l.Fill( datasetId, 1, weight); if (trigger_e) selTable_e.Fill( datasetId, 1, weight); if (trigger_mu) selTable_mu.Fill(datasetId, 1, weight); } // 3. Rest of the table for (unsigned int i = 2; i < (sel.GetCutList()).size() ; i++) { if (selLastStep >= (int) i && lep==0) selTable_e.Fill( datasetId, i, weight); if (selLastStep >= (int) i && lep==1) selTable_mu.Fill(datasetId, i, weight); if (selLastStep >= (int) i) selTable_l.Fill( datasetId, i, weight); } // Fill the histo int selLastStep_e = 0; int selLastStep_mu = 0; if (trigger_e) { selLastStep_e = 1; if (lep == 0) selLastStep_e=selLastStep; } if (trigger_mu) { selLastStep_mu = 1; if (lep == 1) selLastStep_mu=selLastStep; } histoManager.Fill(sel, event, sel.GetMuonsForAna(), sel.GetElectronsForAna(), selLastStep_e, 0, datasetId, weight); histoManager.Fill(sel, event, sel.GetMuonsForAna(), sel.GetElectronsForAna(), selLastStep_mu, 1, datasetId, weight); //histoManager.Fill(sel, event, sel.GetMuonsForAna(), sel.GetElectronsForAna(), selLastStep, 2, datasetId, weight); //dileptonBackgroundStudy(&sel,trigger_e,trigger_mu,lep,selLastStep,&histoManagerDileptonBkg,datasetId,weight); // Calculate efficiency for semi-leptonic and di-leptonic { const IPHCTree::NTMonteCarlo mcInfo = *(sel.GetPointer2MC()); int TMEME = mcInfo.TMEME; int MEME = TMEME % 10000; int EME = MEME % 1000; int ME = EME % 100; int E = ME % 10; int nTau = TMEME / 10000; int nMuFromTau = MEME / 1000; int nElFromTau = EME / 100; int nMuon = ME / 10; int nElec = E / 1; bool foundVeto0 = false; bool foundVeto1 = false; bool foundVeto2 = false; bool foundVeto3 = false; resetDileptonData(&dileptonDataForTree); if (selLastStep >= 5) { TLorentzVector lepton_p; // Get selected muon for the check if (sel.GetMuonsForAna().size()==1) lepton_p = (sel.GetMuonsForAna()[0]).p4; else lepton_p = (sel.GetElectronsForAna()[0]).p4; if (nTau > 0) { DEBUG_MSG << " NTauMC = " << nTau; if (nMuFromTau + nElFromTau == 0) cout << " hadr "; std::vector<IPHCTree::NTTau> localTaus = *(sel.GetPointer2Taus()); for(unsigned int i=0;i<localTaus.size();i++) { if ( lepton_p.DeltaR(localTaus[i].p4) < 0.1) continue; //DEBUG_MSG << "tipi 0" << endl; if (localTaus[i].leadTrackPt <= 5) continue; //DEBUG_MSG << "tipi 1" << endl; if ((localTaus[i].ID["byLooseIsolation"] != 1) && (localTaus[i].ID["byMediumIsolation"] != 1) && (localTaus[i].ID["byTightIsolation"] != 1) && (localTaus[i].ID["byLooseCombinedIsolationDeltaBetaCorr"] != 1) && (localTaus[i].ID["byMediumCombinedIsolationDeltaBetaCorr"] != 1) && (localTaus[i].ID["byTightCombinedIsolationDeltaBetaCorr"] != 1)) continue; if(fabs(localTaus[i].p4.Eta()) >= 2.5) continue; if(fabs(localTaus[i].p4.Eta())<1.566 && fabs(localTaus[i].p4.Eta())>1.4442) continue; if(localTaus[i].p4.Pt() < 5) continue; //if ( fabs( localTaus[i].vertex.Z() - sel.GetSelectedVertex()[0].p3.Z() ) > cfg.TauVertexMatchThr_ ) continue; if ( fabs( localTaus[i].D0) >= 0.04 ) continue; cout << " ; found"; } cout << endl; } // Output vector std::vector<IPHCTree::NTPFCandidate> vetotracks = sel.GetPFCandidates(); // Loop over pfcandidates tracks for(unsigned int i=0 ; i < vetotracks.size() ; i++) { if ((vetotracks[i].p4.Pt() > 10) && (fabs(vetotracks[i].dz_firstGoodVertex) < 0.05)) { TLorentzVector vetoTrack_p = vetotracks[i].p4; // Check pfcandidate doesnt match the selected lepton if (lepton_p.DeltaR(vetoTrack_p) > 0.1) { float thePt = vetotracks[i].p4.Pt(); if (dileptonDataForTree.iso_03 > vetotracks[i].others["iso_03"]/thePt) { dileptonDataForTree.iso_03 = vetotracks[i].others["iso_03"]/thePt; dileptonDataForTree.bestIso03_iso_03 = vetotracks[i].others["iso_03"]/thePt; dileptonDataForTree.bestIso03_iso_05_no015 = vetotracks[i].others["iso_05_no015"]/thePt; dileptonDataForTree.bestIso03_iso_05_no01 = vetotracks[i].others["iso_05_no01"]/thePt; dileptonDataForTree.bestIso03_iso_05_ntrk_01 = (float) vetotracks[i].others["ntrk_01"]; dileptonDataForTree.bestIso03_iso_05_ntrk_015 = (float) vetotracks[i].others["ntrk_015"]; dileptonDataForTree.bestIso03_iso_05_ntrk_015_pT1GeV = (float) vetotracks[i].others["ntrk_015_pT1GeV"]; } if (dileptonDataForTree.iso_05_no01 > vetotracks[i].others["iso_05_no01"]/thePt) { dileptonDataForTree.iso_05_no01 = vetotracks[i].others["iso_05_no01"]/thePt; dileptonDataForTree.bestIso05no01_iso_03 = vetotracks[i].others["iso_03"]/thePt; dileptonDataForTree.bestIso05no01_iso_05_no015 = vetotracks[i].others["iso_05_no015"]/thePt; dileptonDataForTree.bestIso05no01_iso_05_no01 = vetotracks[i].others["iso_05_no01"]/thePt; dileptonDataForTree.bestIso05no01_iso_05_ntrk_01 = (float) vetotracks[i].others["ntrk_01"]; dileptonDataForTree.bestIso05no01_iso_05_ntrk_015 = (float) vetotracks[i].others["ntrk_015"]; dileptonDataForTree.bestIso05no01_iso_05_ntrk_015_pT1GeV = (float) vetotracks[i].others["ntrk_015_pT1GeV"]; } if (dileptonDataForTree.iso_05_no015 > vetotracks[i].others["iso_05_no015"]/thePt) { dileptonDataForTree.iso_05_no015 = vetotracks[i].others["iso_05_no015"]/thePt; dileptonDataForTree.bestIso05no015_iso_03 = vetotracks[i].others["iso_03"]/thePt; dileptonDataForTree.bestIso05no015_iso_05_no015 = vetotracks[i].others["iso_05_no015"]/thePt; dileptonDataForTree.bestIso05no015_iso_05_no01 = vetotracks[i].others["iso_05_no01"]/thePt; dileptonDataForTree.bestIso05no015_iso_05_ntrk_01 = (float) vetotracks[i].others["ntrk_01"]; dileptonDataForTree.bestIso05no015_iso_05_ntrk_015 = (float) vetotracks[i].others["ntrk_015"]; dileptonDataForTree.bestIso05no015_iso_05_ntrk_015_pT1GeV = (float) vetotracks[i].others["ntrk_015_pT1GeV"]; } if (dileptonDataForTree.iso_02 > vetotracks[i].others["iso_02"]/thePt) dileptonDataForTree.iso_02 = vetotracks[i].others["iso_02"]/thePt; if (dileptonDataForTree.iso_04 > vetotracks[i].others["iso_04"]/thePt) dileptonDataForTree.iso_04 = vetotracks[i].others["iso_04"]/thePt; if (dileptonDataForTree.iso_05 > vetotracks[i].others["iso_05"]/thePt) dileptonDataForTree.iso_05 = vetotracks[i].others["iso_05"]/thePt; if (dileptonDataForTree.iso_03_pT1GeV > vetotracks[i].others["iso_03_pT1GeV"]/thePt) dileptonDataForTree.iso_03_pT1GeV = vetotracks[i].others["iso_03_pT1GeV"]/thePt; if (dileptonDataForTree.iso_05_no015_pT1GeV > vetotracks[i].others["iso_05_no015_pT1GeV"]/thePt) dileptonDataForTree.iso_05_no015_pT1GeV = vetotracks[i].others["iso_05_no015_pT1GeV"]/thePt; if (dileptonDataForTree.iso_05_no02 > vetotracks[i].others["iso_05_no02"]/thePt) dileptonDataForTree.iso_05_no02 = vetotracks[i].others["iso_05_no02"]/thePt; if (dileptonDataForTree.iso_045_no015 > vetotracks[i].others["iso_045_no015"]/thePt) dileptonDataForTree.iso_045_no015 = vetotracks[i].others["iso_045_no015"]/thePt; if (dileptonDataForTree.iso_055_no015 > vetotracks[i].others["iso_055_no015"]/thePt) dileptonDataForTree.iso_055_no015 = vetotracks[i].others["iso_055_no015"]/thePt; } } } // Loop over pfcandidates tracks for(unsigned int i=0 ; i < vetotracks.size() ; i++) { if ((vetotracks[i].p4.Pt() + vetotracks[i].others["iso_02"] > 10) && (fabs(vetotracks[i].dz_firstGoodVertex) < 0.05)) { TLorentzVector vetoTrack_p = vetotracks[i].p4; float thePt = vetotracks[i].p4.Pt() + vetotracks[i].others["iso_02"]; // Check pfcandidate doesnt match the selected lepton if (lepton_p.DeltaR(vetoTrack_p) > 0.1) { if (dileptonDataForTree.iso_05_no015_pTEqualIso02 > vetotracks[i].others["iso_05_no015"]/thePt) dileptonDataForTree.iso_05_no015_pTEqualIso02 = vetotracks[i].others["iso_05_no015"]/thePt; } } } string channelType(""); // Semi-leptonic case if (nTau + nMuon + nElec == 1) { dileptonDataForTree.eventInfo_isSemilep = 1.0; channelType = string("l+jets"); if (nTau >= 1) dileptonDataForTree.eventInfo_haveTau = 1.0; } // Di-leptonic case else if (nTau + nMuon + nElec >= 2) { dileptonDataForTree.eventInfo_isDilep = 1.0; channelType = string("ll"); if (nTau >= 1) { // Di-leptonic with a tau dileptonDataForTree.eventInfo_haveTau = 1.0; if (nMuFromTau + nElFromTau <= 0) { // Di-leptonic with a hadronic tau dileptonDataForTree.eventInfo_haveHadronicTau = 1.0; std::vector<IPHCTree::NTGenParticle> genParticles = mcInfo.genParticles; IPHCTree::NTGenParticle theGenTau; int genTauIndex = -1; bool foundTau = false; for (int i = 0 ; i < genParticles.size() ; i++) { IPHCTree::NTGenParticle particle = genParticles[i]; if (fabs(particle.id) != 15) continue; if (!foundTau) { theGenTau = particle; genTauIndex = i; } else { DEBUG_MSG << "Warning : second tau found in the event" << endl; } } int PKKPPL_ = theGenTau.decayMode; int KKPPL_ = PKKPPL_ % 100000; int KPPL_ = KKPPL_ % 10000; int PPL_ = KPPL_ % 1000; int PL_ = PPL_ % 100; int L_ = PL_ % 10; int numberOfPhotons = PKKPPL_ / 100000; int numberOfKCharged = KKPPL_ / 10000; int numberOfKZero = KPPL_ / 1000; int numberOfPiCharged = PPL_ / 100; int numberOfPiZero = PL_ / 10; int leptonFlavor = L_ / 1; int numberOfCharged = numberOfKCharged + numberOfPiCharged; if (numberOfCharged >= 3) dileptonDataForTree.eventInfo_haveHadronicTau3 = 1.0; // Compute dR mean between decays products // first we find the highest pt charged decay int maxPt = -1.0; IPHCTree::NTGenParticle maxPtChargedDecay; for (int i = 0 ; i < genParticles.size() ; i++) { IPHCTree::NTGenParticle particle = genParticles[i]; if (particle.motherIndex_ == genTauIndex) if (((abs(particle.id) == 211) || (abs(particle.id) == 321)) && (particle.p4.Pt() > maxPt)) { maxPt = particle.p4.Pt(); maxPtChargedDecay = particle; } } // then compute the sumDr float sumDr = 0.0; float DrMax = -1.0; int nDecay = 1; float sumDrCharged = 0.0; float DrMaxCharged = -1.0; float sumPtCharged = maxPtChargedDecay.p4.Pt(); float pTminCharged = maxPtChargedDecay.p4.Pt(); float pTmaxCharged = maxPtChargedDecay.p4.Pt(); int nDecayCharged = 1; for (int i = 0 ; i < genParticles.size() ; i++) { IPHCTree::NTGenParticle particle = genParticles[i]; if (particle.p4 == maxPtChargedDecay.p4) continue; if ((particle.motherIndex_ == genTauIndex) && (abs(particle.id) != 16)) { nDecay++; // For all decays sumDr += maxPtChargedDecay.p4.DeltaR(particle.p4); if (maxPtChargedDecay.p4.DeltaR(particle.p4) > DrMax) DrMax = maxPtChargedDecay.p4.DeltaR(particle.p4); // ChargedDecay if (((abs(particle.id) == 211) || (abs(particle.id) == 321))) { nDecayCharged++; sumPtCharged += particle.p4.Pt(); sumDrCharged += maxPtChargedDecay.p4.DeltaR(particle.p4); if (particle.p4.Pt() > pTmaxCharged) pTmaxCharged = particle.p4.Pt(); if (particle.p4.Pt() < pTminCharged) pTminCharged = particle.p4.Pt(); if (maxPtChargedDecay.p4.DeltaR(particle.p4) > DrMaxCharged) DrMaxCharged = maxPtChargedDecay.p4.DeltaR(particle.p4); } } } // Fill tree info dileptonDataForTree.hadronicMC_dRmeanDecay = sumDr / nDecay; dileptonDataForTree.hadronicMC_dRmaxDecay = DrMax; dileptonDataForTree.hadronicMC_dRmeanChargedDecay = sumDrCharged / nDecayCharged; dileptonDataForTree.hadronicMC_dRmaxChargedDecay = DrMaxCharged; dileptonDataForTree.hadronicMC_pTminChargedDecay = pTminCharged; dileptonDataForTree.hadronicMC_pTmeanChargedDecay = sumPtCharged / nDecayCharged; dileptonDataForTree.hadronicMC_pTmaxChargedDecay = pTmaxCharged; } } } if (channelType != string("")) { dileptonTable.Fill(channelType,"baseline",1.0); if (selLastStep >= 5) { dileptonTable.Fill(channelType,"MET" ,1.0); dileptonTable.Fill(channelType,"vetoTest0",(int) foundVeto0); dileptonTable.Fill(channelType,"vetoTest1",(int) foundVeto1); dileptonTable.Fill(channelType,"vetoTest2",(int) foundVeto2); dileptonTable.Fill(channelType,"vetoTest3",(int) foundVeto3); } if (selLastStep >= 6) dileptonTable.Fill(channelType,"stdVeto",1.0); } dileptonTree->Fill(); } } } // end of loop over evts } // end of loop over datasets dileptonTree->Print(); dileptonTreeFile.Write(); dileptonTreeFile.Close(); dileptonTable.PrintTable(); // ################################ // # Computations after loops # // ################################ cout << endl; cout << " ,-------------------------------," << endl; cout << " | Compute histos and tables |" << endl; cout << " `-------------------------------`" << endl; cout << endl; // Compute and save histograms if(!doHistoManager) INFO1_MSG << "HistoManagers [skipped]" << endl; else { INFO1_MSG << "HistoManagers ..." << endl; // Standard histograms histoManager.Compute (); string orootfilename = rootOutputName; TFile *fout = new TFile (orootfilename.c_str(), "RECREATE"); histoManager.Write (fout); fout->Close (); // DileptonBkg histograms histoManagerDileptonBkg.MergeChannels(); histoManagerDileptonBkg.DoMCStack(); histoManagerDileptonBkg.MergeMCDatasets(); histoManagerDileptonBkg.PlotsCutByCut(); string orootfilenameDileptonBkg; orootfilenameDileptonBkg = string("TTbarMETanalysis_DileptonBkgAna.root"); TFile *fout2 = new TFile (orootfilenameDileptonBkg.c_str(), "RECREATE"); histoManagerDileptonBkg.Write (fout2); fout2->Close(); string orootfilenameDileptonBkg2D; orootfilenameDileptonBkg2D = string("TTbarMETanalysis_DileptonBkgAna2D.root"); TFile *fout3 = new TFile (orootfilenameDileptonBkg2D.c_str(), "RECREATE"); histoManagerDileptonBkg.Write2D (fout3); fout3->Close(); // Clear histoManager.Clear (); histoManagerDileptonBkg.Clear (); delete fout; delete fout2; delete fout3; } // Write and compile tables if (!doLatexOutput) INFO1_MSG << "Tables [skipped]" << endl; { INFO1_MSG << "Tables ..." << endl; selTable_e.TableCalculator(); selTable_mu.TableCalculator(); selTable_l.TableCalculator(); makeSelectionTable(latexTableName,selTable_e,selTable_mu,selTable_l); } cout << endl; cout << " ,-----------------------," << endl; cout << " | Program completed |" << endl; cout << " `-----------------------`" << endl; cout << endl; return (0); }
int merging() { Long_t NUMBER_OF_ENTRIES = 100; TTree* newResult = new TTree("xxx", "Argument"); static Double_t x, y; newResult->Branch("x", &x, "x/D"); newResult->Branch("y", &y, "y/D"); for(Long_t i=0; i<NUMBER_OF_ENTRIES; ++i) { x = i; y = i*i; //fprintf(stderr,"res %lf %lf %d\n",x,y,i<NUMBER_OF_ENTRIES); newResult->Fill(); }// end of for // newResult->Scan("x:y"); // ====================================== TMessage message(kMESS_OBJECT); message.Reset(); message.SetWriteMode(); message.WriteObject(newResult); message.Reset(); message.SetReadMode(); TTree* readResult = 0; readResult = ((TTree*)message.ReadObject(message.GetClass())); readResult->SetName("yyy"); // ====================================== TTree* result = 0; result = readResult->CloneTree(0); result->SetName("zzz"); result->Print(); result->Show(19); readResult->Print(); readResult->Show(29); cout<< "Result has " << result->GetEntries()<< " entries." << endl; TList newResultCollection; newResultCollection.SetOwner(kFALSE); newResultCollection.Add(readResult); cerr<<"Hello 1\n"; result->Merge(&newResultCollection); cerr<<"Hello 2\n"; cout<<result->GetEntries()<<endl; printf("result entries = %lld\n",result->GetEntries()); // ====================================== newResultCollection.Clear(); delete newResult; delete readResult; return 0; } // end of main
//_____________________________________________________________________________ Int_t ProofAux::GenerateTree(const char *fnt, Long64_t ent, TString &fn) { // Generate the main tree for the 'friends' tutorial; the tree is called // 'Tmain', has 'ent' entries and is saved to file 'fnt'. // The full file path is returned in 'fn'. // Return 0 on success, -1 on error. Int_t rc = -1; // Check the filename fn = fnt; if (fn.IsNull()) { Error("GenerateTree", "file name undefined!"); return rc; } TUrl uu(fn, kTRUE); if (!strcmp(uu.GetProtocol(), "file") && !fn.BeginsWith("/")) { // Local file with relative path: create under the data directory if (!gProofServ || !(gProofServ->GetDataDir()) || strlen(gProofServ->GetDataDir()) <= 0) { Error("GenerateTree", "data directory undefined!"); return rc; } // Insert data directory fn.Insert(0, TString::Format("%s/", gProofServ->GetDataDir())); // Make sure the directory exists TString dir = gSystem->DirName(fn); if (gSystem->AccessPathName(dir, kWritePermission)) { if (gSystem->mkdir(dir, kTRUE) != 0) { Error("GenerateTree", "problems creating directory %s to store the file", dir.Data()); return rc; } } } // Create the file TDirectory* savedir = gDirectory; TFile *f = new TFile(fn, "RECREATE"); if (!f || f->IsZombie()) { Error("GenerateTree", "problems opening file %s", fn.Data()); return rc; } savedir->cd(); rc = 0; // Create the tree TTree *T = new TTree("Tmain","Main tree for tutorial friends"); T->SetDirectory(f); Int_t Run = 1; T->Branch("Run",&Run,"Run/I"); Long64_t Event = 0; T->Branch("Event",&Event,"Event/L"); Float_t x = 0., y = 0., z = 0.; T->Branch("x",&x,"x/F"); T->Branch("y",&y,"y/F"); T->Branch("z",&z,"z/F"); TRandom r; for (Long64_t i = 0; i < ent; i++) { if (i > 0 && i%1000 == 0) Run++; Event = i; x = r.Gaus(10,1); y = r.Gaus(20,2); z = r.Landau(2,1); T->Fill(); } T->Print(); f->cd(); T->Write(); T->SetDirectory(0); f->Close(); delete f; delete T; // Notify success Info("GenerateTree", "file '%s' successfully created", fn.Data()); // Add to the list TString fds(fn); if (!strcmp(uu.GetProtocol(), "file")) { if (gSystem->Getenv("LOCALDATASERVER")) { if (strcmp(TUrl(gSystem->Getenv("LOCALDATASERVER"), kTRUE).GetProtocol(), "file")) fds.Insert(0, TString::Format("%s/", gSystem->Getenv("LOCALDATASERVER"))); } else { fds.Insert(0, TString::Format("root://%s/", gSystem->HostName())); } } fMainList->Add(new TObjString(fds)); // Done return rc; }
//_____________________________________________________________________________ Int_t ProofAux::GenerateFriend(const char *fnt, const char *fnf) { // Generate the friend tree for the main tree in the 'friends' tutorial fetched // from 'fnt'. // the tree is called 'Tfriend', has the same number of entries as the main // tree and is saved to file 'fnf'. If 'fnf' is not defined the filename is // derived from 'fnt' either replacing 'tree' with 'friend', or adding '_friend' // before the '.root' extension. // Return 0 on success, -1 on error. Int_t rc = -1; // Check the input filename TString fin(fnt); if (fin.IsNull()) { Error("GenerateFriend", "file name for the main tree undefined!"); return rc; } // Make sure that the file can be read if (gSystem->AccessPathName(fin, kReadPermission)) { Error("GenerateFriend", "input file does not exist or cannot be read: %s", fin.Data()); return rc; } // File handlers Bool_t sameFile = kTRUE; const char *openMain = "UPDATE"; // The output filename TString fout(fnf); if (!fout.IsNull()) { sameFile = kFALSE; openMain = "READ"; // Make sure the directory exists TString dir = gSystem->DirName(fout); if (gSystem->AccessPathName(dir, kWritePermission)) { if (gSystem->mkdir(dir, kTRUE) != 0) { Error("GenerateFriend", "problems creating directory %s to store the file", dir.Data()); return rc; } } } else { // We set the same name fout = fin; } // Get main tree TFile *fi = TFile::Open(fin, openMain); if (!fi || fi->IsZombie()) { Error("GenerateFriend", "problems opening input file %s", fin.Data()); return rc; } TTree *Tin = (TTree *) fi->Get("Tmain"); if (!Tin) { Error("GenerateFriend", "problems getting tree 'Tmain' from file %s", fin.Data()); delete fi; return rc; } // Set branches Float_t x, y, z; Tin->SetBranchAddress("x", &x); Tin->SetBranchAddress("y", &y); Tin->SetBranchAddress("z", &z); TBranch *b_x = Tin->GetBranch("x"); TBranch *b_y = Tin->GetBranch("y"); TBranch *b_z = Tin->GetBranch("z"); TDirectory* savedir = gDirectory; // Create output file TFile *fo = 0; if (!sameFile) { fo = new TFile(fout, "RECREATE"); if (!fo || fo->IsZombie()) { Error("GenerateFriend", "problems opening file %s", fout.Data()); delete fi; return rc; } savedir->cd(); } else { // Same file fo = fi; } rc = 0; // Create the tree TTree *Tfrnd = new TTree("Tfrnd", "Friend tree for tutorial 'friends'"); Tfrnd->SetDirectory(fo); Float_t r = 0; Tfrnd->Branch("r",&r,"r/F"); Long64_t ent = Tin->GetEntries(); for (Long64_t i = 0; i < ent; i++) { b_x->GetEntry(i); b_y->GetEntry(i); b_z->GetEntry(i); r = TMath::Sqrt(x*x + y*y + z*z); Tfrnd->Fill(); } if (!sameFile) { fi->Close(); delete fi; } Tfrnd->Print(); fo->cd(); Tfrnd->Write(); Tfrnd->SetDirectory(0); fo->Close(); delete fo; delete Tfrnd; // Notify success Info("GenerateFriend", "friend file '%s' successfully created", fout.Data()); // Add to the list TUrl uu(fout); if (!strcmp(uu.GetProtocol(), "file")) { if (gSystem->Getenv("LOCALDATASERVER")) { if (strcmp(TUrl(gSystem->Getenv("LOCALDATASERVER"), kTRUE).GetProtocol(), "file")) fout.Insert(0, TString::Format("%s/", gSystem->Getenv("LOCALDATASERVER"))); } else { fout.Insert(0, TString::Format("root://%s/", gSystem->HostName())); } } fFriendList->Add(new TObjString(fout)); // Done return rc; }
NTPReplay( Char_t* fname, Int_t qfRecon = -1 ) { // Histogram energies, momenta, from Tree created by kinematics generator // AcquMC....ensure physics library is loaded 1st gROOT->Reset(); if (!gROOT->GetClass("TLorentzVector")) gSystem->Load("libPhysics"); // // Tree file contains 4-momenta produced by MCGenerator TFile* tFile = new TFile( fname ); TTree* tree = (TTree*)tFile->Get("h1"); tree->Print(); Int_t nbr = tree->GetNbranches(); Int_t nparticle = (nbr - 3)/5; // # particles in reaction printf(" %d particles in experiment\n", nparticle ); TObjArray* leaves = tree->GetListOfBranches(); // linked list of leaves printf(" %d leaves in branch\n",nbr); TIter nextlf( tree->GetListOfBranches() ); char** hname = new char*[nbr]; // histogram parameters Float_t* p4i = new Float_t[nbr]; for( Int_t n=0; n<nbr; n++ ){ TBranch* lf = (TBranch*)nextlf(); // Double_t leaf hname[n] = lf->GetName(); // its name tree->SetBranchAddress(hname[n], p4i+n); } Int_t nevent = tree->GetEntries(); // # events generated printf(" %d events started\n", nevent ); // // Create linked list of 1D histograms Int_t i,j,k; // for(i=0,j=0; i<nparticle; i++) if( Track[i] ) j++; // #particles tracked j = nparticle; printf(" %d final-state particles tracked\n", j ); Int_t np4 = j; Int_t nhist = 4*j + 7; // # 1D histograms Int_t nchan = 1000; // 1000 channels each Char_t* title; // title is file name if( !(title = strrchr(fname,'/')) ) title = fname; else title++; TList* hl = new TList(); TList* hAng = new TList(); TH1F* h; for( i=0; i<nhist; i++ ){ h = new TH1F( hname[i], title, nchan, 0, 0 ); hl->AddLast(h); } Char_t angName[256]; // Angular ranges (deg) for plotting Double_t thetaMin[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; Double_t thetaMax[] = { 0.5, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0 }; Double_t phiMin[] = { -200, -200, -200, -200, -200, -200, -200, -200, -200, -200, -200, -200, -200, -200, -200, -200, -200, -200, -200, -200, -200 }; Double_t phiMax[] = { 200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0 }; for( i=0; i<=np4; i++ ){ sprintf( angName, "Theta_%d", i ); h = new TH1F( angName, title, 180, thetaMin[i], thetaMax[i] ); hAng->AddLast(h); sprintf( angName, "Phi_%d", i ); h = new TH1F( angName, title, 180, phiMin[i], phiMax[i] ); hAng->AddLast(h); sprintf( angName, "P_%d", i ); h = new TH1F( angName, title, 1000, 0, 0 ); hAng->AddLast(h); } TIter next(hl); // list iterator TIter nextAng(hAng); // list iterator // // For some 4-momentum analysis TLorentzVector* P4 = new TLorentzVector[nparticle]; TLorentzVector P4tot; TLorentzVector P4beamQF; i = 0; TH2F* h2a = new TH2F("Vertex-X-Y",title,300,-3,3,300,-3,3); TH2F* h2b = new TH2F("Vertex-Z-R",title,300,-3,3,300,-3,3); TH1F* h1a = new TH1F("Momentum-Balance",title,1000,-1,1); TH1F* h1b; if( qfRecon >= 0 ) h1b = new TH1F("QF-recon-Beam-Energy",title,2000,-5,5); // // Read events from branch Double_t r; Float_t* p; for(i=0; i<nevent; i++){ next.Reset(); nextAng.Reset(); tree->GetEntry(i); p = p4i + 3; P4tot.SetXYZT(0,0,0,0); if( qfRecon >= 0 )P4beamQF.SetXYZT(0,0,0,0); for(j=0; j<=np4; j++,p+=5){ P4[j].SetXYZT(p[0]*p[3],p[1]*p[3],p[2]*p[3],p[4]); if( j )P4tot += P4[j]; else P4tot -= P4[j]; if( j >= qfRecon ) P4beamQF += P4[j]; h = (TH1F*)nextAng(); h->Fill( P4[j].Theta() * TMath::RadToDeg() ); h = (TH1F*)nextAng(); h->Fill( P4[j].Phi() * TMath::RadToDeg() ); h = (TH1F*)nextAng(); h->Fill( P4[j].P() ); } // pi0_01 = *pi0_0 + *pi0_1; // pi0_02 = *pi0_0 + *pi0_2; p = p4i; h2a->Fill( p4i[0], p4i[1] ); r = TMath::Sqrt( p4i[0]*p4i[0] + p4i[1]*p4i[1] ); h2b->Fill( p4i[2],r ); h1a->Fill( P4tot.P() ); if( qfRecon >= 0 ) h1b->Fill( P4beamQF.E() ); while( (h = (TH1F*)next()) ){ h->Fill(*p); p++; } } // // Setup of canvases Int_t ncanv = np4 + 2; // # canvases Char_t* cname[] = { // names "Vertex", "Beam", "Particle_0", "Particle_1", "Particle_2", "Particle_3", "Particle_4", "Particle_5", "Particle_6", "Particle_7", "Particle_8", "Particle_9", "Particle_10", "Particle_11", "Particle_12", "Particle_13", "Particle_14", "Particle_15", "Particle_16", "Particle_17", "Particle_18", "Particle_19", }; Int_t xplot[] = { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, }; Int_t yplot[] = { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, }; Int_t nplot[] = { 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, }; TCanvas* canv; next.Reset(); // start of histogram list nextAng.Reset(); // start of histogram list // Draw histograms for( i=0; i<ncanv; i++ ){ canv = new TCanvas(cname[i],"MCtit",240,180,700,900); canv->SetFillStyle(4000); canv->Divide(xplot[i],yplot[i],0.01,0.01); j = 1; while( (h = (TH1F*)next()) ){ canv->cd(j); h->Draw(); if( j >= nplot[i] ) break; j++; } if( i ){ for( k=0; k<3; k++ ){ j++; h = (TH1F*)nextAng(); canv->cd(j); if( k<2 ) h->Draw(); } } else{ canv->cd(4); h1a->Draw(); canv->cd(5); h2a->Draw("colz"); canv->cd(6); h2b->Draw("colz"); } } return; }
void triggerEfficiency() { //=== General CMS Style === gROOT->ForceStyle(); //gROOT->LoadMacro("tdrstyle.C"); setTDRStyle(); //gROOT->LoadMacro("CMS_lumi.C"); extraText = "Preliminary"; // default extra text is "Preliminary" writeExtraText = true; // remove or keep "Preliminary" lumi_13TeV = "2015"; // for trigger //lumi_13TeV = "65 pb^{-1}, 50ns"; // for trigger //lumi_13TeV = "15.5 pb^{-1}, 25ns"; // for trigger //lumi_13TeV = "65 pb^{-1}"; // default is "" //lumi_8TeV = "19.1 fb^{-1}"; // default is "19.7 fb^{-1}" //lumi_7TeV = "4.9 fb^{-1}"; // default is "5.1 fb^{-1}" lumi_sqrtS = "13 TeV"; // used with iPeriod = 0, e.g. for simulation-only plots (default is an empty string) int iPeriod = 4; // 1=7TeV, 2=8TeV, 3=7+8TeV, 4=13TeV, 7=7+8+13TeV, 0=free form (uses lumi_sqrtS) int iPos = 11; // 0=out , 11=left, 22=center, 33=right //==================================================================================== // Style int W = 600; int H = 600; // // Simple example of macro: plot with CMS name and lumi text // (this script does not pretend to work in all configurations) // iPeriod = 1*(0/1 7 TeV) + 2*(0/1 8 TeV) + 4*(0/1 13 TeV) // For instance: // iPeriod = 3 means: 7 TeV + 8 TeV // iPeriod = 7 means: 7 TeV + 8 TeV + 13 TeV // Initiated by: Gautier Hamel de Monchenault (Saclay) // Updated by: Dinko Ferencek (Rutgers) // int H_ref = 600; int W_ref = 600; // references for T, B, L, R float T = 0.08*H_ref; float B = 0.12*H_ref; float L = 0.15*W_ref; float R = 0.04*W_ref; TString canvName = "trigger"; canvName += W; canvName += "-"; canvName += H; canvName += "_"; canvName += iPeriod; if( writeExtraText ) canvName += "-prelim"; if( iPos%10==0 ) canvName += "-out"; else if( iPos%10==1 ) canvName += "-left"; else if( iPos%10==2 ) canvName += "-center"; else if( iPos%10==3 ) canvName += "-right"; TCanvas* canv = new TCanvas(canvName,canvName,50,50,W,H); canv->SetFillColor(0); canv->SetBorderMode(0); canv->SetFrameFillStyle(0); canv->SetFrameBorderMode(0); canv->SetLeftMargin( L/W ); canv->SetRightMargin( R/W ); canv->SetTopMargin( T/H ); canv->SetBottomMargin( B/H ); canv->SetTickx(0); canv->SetTicky(0); canv->SetGridx(true); canv->SetGridy(true); //==================================================================================== // Efficiency TFile *fileInput = TFile::Open(myinputFile); fileInput->ls(); TEfficiency* h_efficiency = 0; TH1F *h_denominator; TH1F *h_numerator; if(histoFromFile==1) { //== taking histo from file h_denominator = (TH1F*)fileInput->Get(mydenominator); h_numerator = (TH1F*)fileInput->Get(mynumerator); } else { //== creating histo from tree TTree *thistree = (TTree*)fileInput->Get("rootTupleTree/tree"); thistree->Print(); TH1F *h_denominator_tmp = (TH1F*)fileInput->Get(mydenominator); h_denominator = (TH1F*)h_denominator_tmp->Clone(); h_numerator = (TH1F*)h_denominator_tmp->Clone(); h_denominator->Reset(); h_numerator->Reset(); h_denominator->SetName("h_denominator"); h_numerator->SetName("h_numerator"); //fill histograms //-- //thistree->Draw("mjj >> h_denominator","fabs(deltaETAjj)<1.3 && passHLT_PFHT475==1"); //signal region //thistree->Draw("mjj >> h_denominator","fabs(deltaETAjj)<1.3 && passHLT_Mu45==1"); //signal region thistree->Draw("mjj >> h_denominator","fabs(deltaETAjj)>1.3 && fabs(deltaETAjj)<2.6 && passHLT_Mu45==1"); //control region //-- //thistree->Draw("mjj >> h_numerator","fabs(deltaETAjj)<1.3 && passHLT_PFHT475==1 && passHLT_PFHT800==1"); //thistree->Draw("mjj >> h_numerator","fabs(deltaETAjj)<1.3 && passHLT_Mu45==1 && passHLT_PFHT800==1"); //thistree->Draw("mjj >> h_numerator","fabs(deltaETAjj)<1.3 && passHLT_Mu45==1 && (passHLT_PFHT800==1 || passHLT_PFJET500==1)"); thistree->Draw("mjj >> h_numerator","fabs(deltaETAjj)>1.3 && fabs(deltaETAjj)<2.6 && passHLT_Mu45==1 && (passHLT_PFHT800==1 || passHLT_PFJET500==1)"); //thistree->Draw("mjj >> h_numerator","fabs(deltaETAjj)>1.3 && fabs(deltaETAjj)<2.6 && passHLT_Mu45==1 && (passHLT_PFHT800==1 || passHLT_PFJET500==1 || passHLT_PFHT650MJJ950==1 || passHLT_PFHT650MJJ900==1 || passHLT_AK8DiPFJet280200TrimMass30Btag==1 || passHLT_AK8PFHT600TriMass50Btag==1 || passHLT_AK8PFHT700TriMass50==1 || passHLT_AK8PFJet360TrimMass50==1 || passHLT_CaloJet500NoJetID==1 || passHLT_DiPFJetAve300HFJEC==1 || passHLT_DiPFJetAve500==1 || passHLT_PFHT400SixJet30Btag==1 || passHLT_PFHT450SixJet40Btag==1 || passHLT_PFHT750FourJetPt50==1 || passHLT_QuadPFJetVBF==1 || passHLT_PFHT650==1 || passHLT_PFHT475==1 || passHLT_PFHT200==1 || passHLT_PFJET450==1)"); //-- option placeholder //thistree->Draw("mjj >> h_denominator","fabs(deltaETAjj)<1.3 && passHLT_Mu45==1","",10000); //-- } //========================== if(TEfficiency::CheckConsistency(*h_numerator,*h_denominator)) { h_efficiency = new TEfficiency(*h_numerator,*h_denominator); //stat option, see https://root.cern.ch/root/html/TEfficiency.html#TEfficiency:SetStatisticOption h_efficiency->SetStatisticOption(TEfficiency::kFWilson); //h_efficiency->SetStatisticOption(TEfficiency::kFCP); //default h_efficiency->SetTitle(mytitle); h_efficiency->Draw(); gPad->Update(); h_efficiency->GetPaintedGraph()->GetXaxis()->SetRangeUser(xmin,xmax); h_efficiency->GetPaintedGraph()->GetXaxis()->SetNdivisions(505); h_efficiency->GetPaintedGraph()->GetYaxis()->SetRangeUser(ymin,ymax); //h_efficiency->GetPaintedGraph()->GetYaxis()->SetTitleOffset(0.9); // h_efficiency->GetPaintedGraph()->GetYaxis()->SetLabelSize(0.04); for (int bin=0;bin<h_efficiency->GetPaintedGraph()->GetN();bin++) { double x=-1; double y=-1; double eyh=-1; double eyl=-1; h_efficiency->GetPaintedGraph()->GetPoint(bin,x,y); eyh = h_efficiency->GetPaintedGraph()->GetErrorYhigh(bin); eyl = h_efficiency->GetPaintedGraph()->GetErrorYlow(bin); cout << "bin = " << bin << ": x= " << x << " , y = " << y << " + " << eyh << " - " << eyl << endl; } // draw the legend TLegend *legend=new TLegend(0.35,0.22,0.89,0.32); //legend->SetTextFont(72); //legend->SetTextSize(0.04); legend->SetFillStyle(0); legend->SetLineColor(0); legend->SetShadowColor(0); legend->AddEntry(h_efficiency,mytitlelegend,"lpe"); legend->Draw(); } //==================================================================================== //Draw //## Trigger Efficiency plot ## // writing the lumi information and the CMS "logo" CMS_lumi( canv, iPeriod, iPos ); canv->Update(); canv->RedrawAxis(); canv->GetFrame()->Draw(); gPad->SetTickx(1); gPad->SetTicky(1); canv->Print(myoutputfilename+".pdf",".pdf"); canv->Print(myoutputfilename+".png",".png"); canv->Print(myoutputfilename+".root",".root"); //## Trigger Efficiency plot (zoom) ## h_efficiency->GetPaintedGraph()->GetXaxis()->SetRangeUser(xminZoom,xmaxZoom); h_efficiency->GetPaintedGraph()->GetYaxis()->SetRangeUser(yminZoom,ymaxZoom); CMS_lumi( canv, iPeriod, iPos ); canv->Update(); canv->RedrawAxis(); canv->GetFrame()->Draw(); gPad->SetTickx(1); gPad->SetTicky(1); canv->Print(myoutputfilename+"_zoom.pdf",".pdf"); canv->Print(myoutputfilename+"_zoom.png",".png"); //Integral above threshold int totalNev = h_denominator->Integral(h_denominator->FindFixBin(threshold),h_denominator->GetNbinsX()); int passedNev = h_numerator->Integral(h_numerator->FindFixBin(threshold),h_numerator->GetNbinsX()); //int totalNev = h_denominator->Integral(h_denominator->FindFixBin(threshold),h_denominator->FindFixBin(threshold)); //int passedNev = h_numerator->Integral(h_numerator->FindFixBin(threshold),h_numerator->FindFixBin(threshold)); float effIntegrated = float(passedNev)/float(totalNev); cout << "totalNev = " << totalNev << " , passedNev=" << passedNev << " , efficiency=" << effIntegrated << endl; TEfficiency* pEff = 0; float effIntegrated_errUp = pEff->Wilson(totalNev,passedNev,0.683,true) - effIntegrated; float effIntegrated_errDown = pEff->Wilson(totalNev,passedNev,0.683,false) - effIntegrated; cout << "efficiency integrated above threshold of "<< threshold <<" = " << effIntegrated << " + " << effIntegrated_errUp << " - " << effIntegrated_errDown << endl; //## Mjj Spectra ## canv->SetGridx(false); canv->SetGridy(false); canv->SetLogy(true); h_denominator->UseCurrentStyle(); h_denominator->SetLineColor(2); h_numerator->SetLineColor(1); h_denominator->Draw(); h_numerator->Draw("same"); h_denominator->GetXaxis()->SetRangeUser(xmin,xmax); h_denominator->GetXaxis()->SetTitle(xAxisTitle); h_denominator->GetYaxis()->SetTitle(yAxisTitle); h_denominator->GetYaxis()->SetTitleOffset(1.3); CMS_lumi( canv, iPeriod, iPos ); canv->Update(); canv->RedrawAxis(); canv->GetFrame()->Draw(); gPad->SetTickx(1); gPad->SetTicky(1); // draw the legend TLegend *legend1=new TLegend(0.4,0.65,0.91,0.83); //legend->SetTextFont(72); //legend->SetTextSize(0.06); legend1->SetFillStyle(0); legend1->SetLineColor(0); legend1->SetShadowColor(0); legend1->AddEntry(h_denominator,mytitlelegendDen,"l"); legend1->AddEntry(h_numerator,mytitlelegendNum,"l"); legend1->Draw(); canv->Print(myoutputfilename+"_histo.pdf",".pdf"); canv->Print(myoutputfilename+"_histo.png",".png"); //----------------------------------------------------------------------------- }
int main(){ float data[1024], x[1024], min, area, energy, timing; int start, cut, count, end; TFile *fout = TFile::Open("/projects/physics/dmice/Fermilab/Cs137_NProcessed01.root", "recreate"); TTree *tree = new TTree("tree", "NaI Detector Data"); tree->Branch("Waveforms", data, "data[1024]/F"); tree->Branch("Height", &min, "min/F"); tree->Branch("Area", &area, "area/F"); tree->Branch("Saturated", &cut, "cut/I"); tree->Branch("Energy", &energy, "energy/F"); tree->Branch("Timing" , &timing, "timing/F"); tree->Branch("start" , &start, "start/F"); tree->Branch("end" , &end, "end/F"); TChain t("tree"); t.Add("/projects/physics/dmice/Fermilab/sourcedata/Cs137raw/Waveforms_0.root"); //t.Add("/projects/physics/dmice/Fermilab/1V_runs/Fermilab_1V_raw.root"); t.SetBranchAddress("Waveforms", data); Float_t offavg = .000024; for(int e = 0; t.GetEntry(e) > 0; e++){ //Loop over each entry Float_t y[1024]; for(int i = 0; i< 1024; i++){ y[i] = data[i] - offavg; x[i] = i; } Float_t weight=0, avg = 0; int minLoc, n0; int numpulse = 0; Float_t startloc[10], endloc[10]; min = 0; int zero_counter = 0; bool foundstart = false, foundzero = false; for(int i = 2; i < 997; i++){ //Loop through the data to find each startloc and endloc float local_avg = (y[i-2] + y[i-1] + y[i] + y[i+1] + y[i+2]); if(local_avg >= 0 && !foundstart){ zero_counter++; if(zero_counter == 5){ zero_counter = 0; foundzero = true; } } if(local_avg < -.1 && !foundstart && foundzero){ //play around with .01 (previously not /5 and < -.05) start = i-2; foundzero = false; foundstart = true; startloc[numpulse] = start; zero_counter = 0; } if(local_avg >= 0 && !foundzero && foundstart && i >= (start + 100 )){ zero_counter++; if(zero_counter == 6){ end = i; foundzero = true; foundstart = false; endloc[numpulse] = end; numpulse ++; } } } for(int i = 0; i < numpulse; i++){ //Loop through each pulse Float_t bin_sum = 0; if(endloc[i] == 0) startloc[i] = 0; for(int k = startloc[i]; k < endloc[i]; k++){ if(k < 1021 && cut == 0) if(data[k] == data[k+1] && data[k] == data[k+2] && data[k] < -.2) cut = 1; if(y[k] < min){ min = y[k]; minLoc = k; } } //TGraph gr(1024, x, y); //area = gr.Integral(startloc[i], endloc[i]); for(int v = startloc[i]; v <= endloc[i]; v++){ bin_sum += y[v]; } area = -bin_sum; energy = (area*69.674)+1.8148; for(int z = minLoc; z > 0; z--){ if(y[z] < min/2) n0 = z; } for(int x = n0; x< (n0+100); x++){ weight += (x-n0)*y[x]; avg += y[x]; if(x == 1023){ weight = 0; avg = 0; break; } if(avg != 0) timing = (weight/avg)*4; count++; } tree->Fill(); } } tree->Write(); tree->Print(); fout->Close("R"); delete fout; }
//call this macro via root -l -b -q AddBranchEventsMT2tree.C++ //This code takes a text file containing run:lumisection:event:taggervalue (tagger value is a new filter you want to add to your tree), //an old MT2tree file that does not contain that tagger // and creates a new MT2tree file, which is a copy of the old one and contains additionally that tagger. void AddBranchEventsMT2tree() { // Example of Root macro to copy a subset of a Tree to a new Tree // Only selected entries are copied to the new Tree. // The input file has been generated by the program in $ROOTSYS/test/Event // with Event 1000 1 99 1 //Author: Rene Brun //modified: Hannsjoerg Weber, 28/08/2013 //make cleaning // get eventlist to clean // vector contains <run, < <lumisection, event>, taggervalue > > vector<pair<pair<int,pair<int,int> >,float> > rls; rls.clear(); char buffer[200]; ifstream filterdat("/shome/haweber/AODFiles_MT2SR/taggerlist/ControlRegionSinglePhotonPart1.dat"); while( filterdat.getline(buffer, 200, '\n') ){ int rrun(-1), lls(-1), eevent(-1), d1(-1); float ttagger(-1); sscanf(buffer, "*\t%d\t*\t%d\t*\t%d\t*\t%d\t*\t%f", &d1, &eevent, &lls, &rrun, &ttagger); pair<int,int> t1(lls,eevent); pair<int,pair<int,int> > t2(rrun,t1); pair<pair<int,pair<int,int> >, float> t3(t2,ttagger); rls.push_back(t3); } cout << "Events for filtering " << rls.size() << endl; // get the old rootfile including events that should be tagged and define new event file including tagger variable TString oldfilename = "/shome/haweber/MT2Analysis/MT2trees/MT2_V02-03-02/20130914_8TeV_1g_removed/lowHT/SinglePhoton-Run2012C-PromptReco-v2-2.root"; TString newfilename = "/shome/haweber/MT2Analysis/MT2trees/MT2_V02-03-02/20130914_8TeV_1g_removed/lowHT/SinglePhoton-Run2012C-PromptReco-v2-2_Filter.root"; // if you want to apply an additional event selection, define cuts here std::ostringstream cutStream; std::ostringstream cutStreamBase; cutStream << " " << "NTausIDLoose3Hits+NMuons+NEles==0" << "&&" << "misc.Jet0Pass==1&&misc.Jet1Pass==1" << "&&" << "misc.Vectorsumpt<70&& misc.MinMetJetDPhi4Pt40 >0.3"; cutStream << "&&((misc.MET>200&&misc.HT<=750&&misc.HT>=450&&misc.MT2>200)||(misc.HT>750&&misc.MET>30&&misc.MT2>=100))"; cutStreamBase << " " << "misc.PassJet40ID ==1" << "&&" << "(misc.HBHENoiseFlag == 0 || misc.ProcessID==10)" << "&&" // not there for fastsim (i.e. signal) << "misc.CSCTightHaloIDFlag == 0" << "&&" << "misc.trackingFailureFlag==0" << "&&" << "misc.eeBadScFlag==0" << "&&" << "misc.EcalDeadCellTriggerPrimitiveFlag==0" << "&&" << "misc.TrackingManyStripClusFlag==0" << "&&" << "misc.TrackingTooManyStripClusFlag==0" << "&&" << "misc.TrackingLogErrorTooManyClustersFlag==0" << "&&" << "misc.CrazyHCAL==0"; TString cuts = cutStream.str().c_str(); TString basecuts = cutStreamBase.str().c_str(); // TString myCuts = cuts + "&&" + basecuts;// if cuts should be applied DO NOT comment this line TString myCuts = "";// if no cuts should be applied DO NOT comment this line //Get old file, old tree and set top branch address TFile *oldfile = new TFile(oldfilename.Data()); TTree *oldtree = (TTree*)oldfile->Get("MassTree"); MT2tree* fMT2tree = new MT2tree(); oldtree->SetBranchAddress("MT2tree", &fMT2tree); Long64_t nentries = oldtree->GetEntries(); Long64_t nbytes = 0, nb = 0; int nev =0; //Create a new file + a clone of old tree in new file Float_t TOBTECTagger(-1); Float_t HOTagger(-1); Bool_t ExtraBeamHaloFilter(false); TFile *newfile = new TFile(newfilename.Data(),"RECREATE"); TTree *newtree = oldtree->CloneTree(0);//clone all branches, but no event TBranch *newBranch = newtree->Branch("TOBTECTagger", &TOBTECTagger, "TOBTECTagger/F"); TBranch *newBranch2 = newtree->Branch("ExtraBeamHaloFilter", &ExtraBeamHaloFilter, "ExtraBeamHaloFilter/O"); TBranch *newBranch3 = newtree->Branch("HOTagger", &HOTagger, "HOTagger/F"); oldtree->Draw(">>selList", myCuts); TEventList *myEvtList = (TEventList*)gDirectory->Get("selList"); oldtree->SetEventList(myEvtList); int counter=0; int numEvt = myEvtList->GetN(); int printEvt = 100000; if(myEvtList->GetN()<1000000) printEvt = myEvtList->GetN()/25; cout << "Filtering done, size=" <<myEvtList->GetN() << endl; while(myEvtList->GetEntry(counter++) !=-1){ int jentry = myEvtList->GetEntry(counter-1); nb = oldtree->GetEntry(jentry); nbytes += nb; oldtree->SetBranchAddress("MT2tree", &fMT2tree); if(counter%printEvt==0) cout << "Process event " << counter << endl; //make cleaning bool keep = true; int p=-1; for(int nn=0; nn<rls.size();++nn){ if((rls[nn].first).first!=fMT2tree->misc.Run) continue; // --> run over matching if(((rls[nn].first).second).first!=fMT2tree->misc.LumiSection) continue; // --> LS over matching if(fMT2tree->misc.Event>0){ if(((rls[nn].first).second).second==fMT2tree->misc.Event) { TOBTECTagger = rls[nn].second; keep=false; p=nn; break; } } else{ //if event > INT_MAX correct overflow back. int evtt = ((rls[nn].first).second).second + INT_MAX; evtt = evtt - INT_MAX; if(evtt==fMT2tree->misc.Event) {keep=false; p=nn; break;} } } //two additional taggers bool beamhalo = false; float ho = fMT2tree->misc.MET/fMT2tree->misc.CaloMETRaw; if(fMT2tree->misc.CaloMETRaw<=0) ho=999.; HOTagger = ho; if(fMT2tree->jet[0].lv.DeltaPhi(fMT2tree->jet[1].lv)<0.2 && !(fMT2tree->jet[0].isPFIDMedium)) beamhalo = true; ExtraBeamHaloFilter = beamhalo; if(keep) TOBTECTagger = -1; newtree->Fill(); if(!keep){ //remove event from rls vector --> increases speed. int tt = p; rls.erase(rls.begin()+p); } } newtree->Print(); newtree->AutoSave(); delete oldfile; delete newfile; }
void laserCalibration( char* filename = "frascatirun", //input file int filenum = 1081, //file number int channel = 3, //trace channel int flagChannel = 5, //laser flag channel Double_t entriesN = 10, //number of entries for prcessing int sleep = 10, //sleep time between 2 processed entries, helpful for viewing traces bool gui = true //enable or disable trace visualization ) { caen_5742 caen; Int_t nbins = 1024; Double_t entries = entriesN; Int_t bin; TCanvas *c1 = new TCanvas("c1","frascatirun",900,700); c1->Divide(1,2); c1->cd(1); TGraph* g = new TGraph(); TH1F* lmPeaks = new TH1F("lm","Peaks Ratio", 1000, 0, 5000); TH1F* d = new TH1F("d","",nbins,0,nbins); TH1F* back = new TH1F("Back","",nbins,0,nbins); // input file char fname[100]=0; sprintf(fname,"%s_0%i.root",filename,filenum); TFile* infile = new TFile(fname); TTree *t = (TTree*) infile->Get("t"); t->SetBranchAddress("caen_5742", &caen.system_clock); t->Print(); if(entriesN<=0) entries = t->GetEntries(); //out file char foutname[100]=0; int lm=0; if (channel ==3)lm=1; if (channel ==4)lm=2; sprintf(foutname,"./calibration/LM%i_out_0%i.root",lm,filenum); outfile = new TFile(foutname,"RECREATE"); outTree = new TTree("LM","frascatirun output"); calibTree = new TTree("LM_cal","frascatirun output"); outTree->Branch("LM_PX1",&fPositionX1,"PX1/D"); outTree->Branch("LM_PX2",&fPositionX2,"PX2/D"); outTree->Branch("LM_PY1",&fPositionY1,"PY1/D"); outTree->Branch("LM_PY2",&fPositionY2,"PY2/D"); //outTree->Branch("baseline",baseline,"baseline[1024]/F"); outTree->Branch("time",&timeline,"time/D"); outTree->Branch("LM_P2_Integral",&integralP2,"IP2/D"); calibTree->Branch("LM_P2_Integral_mean",&integralP2_mean,"IP2_mean/D"); calibTree->Branch("LM_P2_Integral_mean_error",&integralP2_mean_error,"IP2_mean_error/D"); calibTree->Branch("LM_P2_Integral_sigma",&integralP2_sigma,"IP2_sigma/D"); calibTree->Branch("LM_P2_Integral_sigma_error",&integralP2_sigma_error,"IP2_sigma_error/D"); /************************************** * read entries ************************************** */ for (int j = 0; j < entries; ++j){ gSystem->Sleep (sleep); t->GetEntry(j); //TRIGGER SELECTION if(caen.trace[flagChannel][400]>1000 && caen.trace[flagChannel][800]<3000){ timeline = caen.system_clock; /************************************** * Peaks estimation ************************************** */ for (int i = 0; i < nbins; ++i){ g->SetPoint(i, i, caen.trace[channel][i]); } Double_t y_max = TMath::MaxElement(g->GetN(),g->GetY()); Float_t * source = new Float_t[nbins]; Float_t * dest = new Float_t[nbins]; for (int i = 0; i < nbins; ++i){ source[i]=y_max-caen.trace[channel][i]; g->SetPoint(i, i, source[i]); } //Use TSpectrum to find the peak candidates TSpectrum *s = new TSpectrum(); Int_t nfound = s->SearchHighRes(source, dest, nbins, 3, 2, kTRUE, 2, kFALSE, 5); /************************************** * Background estimation ************************************** */ Int_t ssize = nbins; Int_t numberIterations = 20; Int_t direction = s->kBackIncreasingWindow; Int_t filterOrder = s->kBackOrder2; bool smoothing = kFALSE; Int_t smoothWindow = s->kBackSmoothing3; bool compton = kFALSE; for (int i = 0; i < nbins; ++i) baseline[i] = source[i]; s->Background(baseline, ssize, numberIterations, direction, filterOrder, smoothing, smoothWindow, compton); /************************************** * Peaks and integral estimation ************************************** */ Double_t px[2], py[2]; for (int i = 0; i < nbins; ++i) dest[i] = source[i]-baseline[i]; if(nfound==2){ bin = s->GetPositionX()[0]; fPositionX1 = bin; fPositionY1 = dest[bin]; px[0] = bin; py[0] = dest[bin]; bin = s->GetPositionX()[1]; fPositionX2 = bin; fPositionY2 = dest[bin]; px[1] = bin; py[1] = dest[bin]; } int posxa=6; int posxb=9; switch (filenum){ case 1081: posxa=6; posxb=9; break; case 1082: posxa=5; posxb=7; break; case 1083: posxa=5; posxb=8; break; case 1084: posxa=5; posxb=7; break; case 1085: posxa=5; posxb=7; break; case 1086: posxa=5; posxb=5; break; case 1087: posxa=4; posxb=4; break; case 1088: posxa=3; posxb=4; break; case 1089: posxa=3; posxb=3; break; default: posxa=6; posxb=9; } integralP2 = g->Integral (fPositionX2-posxa,fPositionX2+posxb); /************************************** * print and update the canvas ************************************** */ if(gui==true){ TH1F* gh = g->GetHistogram(); gh->FillN(nbins,g->GetX(),g->GetY()); g->Draw(); TPolyMarker* pm = (TPolyMarker*)gh->GetListOfFunctions()->FindObject("TPolyMarker"); if (pm) { gh->GetListOfFunctions()->Remove(pm); delete pm; } pm = new TPolyMarker(nfound, px, py); gh->GetListOfFunctions()->Add(pm); pm->SetMarkerStyle(23); pm->SetMarkerColor(kBlue); pm->SetMarkerSize(1.3); for (i = 0; i < nbins; i++) d->SetBinContent(i,dest[i]); d->SetLineColor(kRed); d->Draw("SAME"); for (i = 0; i < nbins; i++) back->SetBinContent(i,baseline[i]); back->SetLineColor(kGreen); back->Draw("SAME"); c1->Update(); } /************************************** * Fill tree and peaks data Histogram ************************************** */ if(nfound==2) { lmPeaks->Fill(integralP2); outTree->Fill(); } //printf("time= %d, posx1= %d, posy1= %d\n",time, fPositionX1, fPositionY1); //printf("time= %d, posx2= %d, posy2= %d\n",time, fPositionX2, fPositionY2); //for (int i=0;i<nbins;i++) printf("time = %d\n",baseline[i]); } } /************************************** * switch to the bottom pan and Draw Histogram ************************************** */ c1->cd(2); //lmPeaks->SetAxisRange(TMath::MinElement(entries,binmin),TMath::MaxElement(entries,binmax)+100); //lmPeaks->SetAxisRange(0,3000); lmPeaks->Fit("gaus"); integralP2_mean = lmPeaks->GetFunction("gaus")->GetParameter(1); integralP2_sigma = lmPeaks->GetFunction("gaus")->GetParameter(2); integralP2_mean_error = lmPeaks->GetFunction("gaus")->GetParError(1); integralP2_sigma_error = lmPeaks->GetFunction("gaus")->GetParError(2); //printf("mean = %f\n",integralP2_mean); //printf("sigma = %f\n",integralP2_sigma); calibTree->Fill(); lmPeaks->Draw(); c1->Update(); outfile->cd(); gROOT->GetList()->Write(); outTree->Write(); calibTree->Write(); outfile->Close(); }
void mk_tree(const char * acc_file="datfiles/acc.dat") { // read acc file into tree TTree * acc = new TTree("acc","counts tree from acc.dat"); char cols[2048]; char bbc_cols[256]; char zdc_cols[256]; char vpd_cols[256]; for(Int_t i=0; i<=7; i++) { if(i==0) { sprintf(bbc_cols,"bbc_%d/D",i); sprintf(zdc_cols,"zdc_%d/D",i); sprintf(vpd_cols,"vpd_%d/D",i); } else { sprintf(bbc_cols,"%s:bbc_%d/D",bbc_cols,i); sprintf(zdc_cols,"%s:zdc_%d/D",zdc_cols,i); sprintf(vpd_cols,"%s:vpd_%d/D",vpd_cols,i); }; }; sprintf(cols,"i/I:runnum/I:fi/I:fill/I:t/D:bx/I:%s:%s:%s:tot_bx/D:blue/I:yell/I",bbc_cols,zdc_cols,vpd_cols); printf("%s\n",cols); acc->ReadFile(acc_file,cols); acc->Print(); Int_t IMAX_tmp = acc->GetMaximum("i"); const Int_t IMAX = IMAX_tmp; // set branch addresses to read through acc tree Int_t index,runnum,fill_index,fill,bx; Double_t bbc[8]; Double_t zdc[8]; Double_t vpd[8]; Double_t time; Double_t tot_bx; Int_t blue,yell; acc->SetBranchAddress("i",&index); acc->SetBranchAddress("runnum",&runnum); acc->SetBranchAddress("fi",&fill_index); acc->SetBranchAddress("fill",&fill); acc->SetBranchAddress("t",&time); acc->SetBranchAddress("bx",&bx); char str[16]; for(Int_t i=0; i<8; i++) { sprintf(str,"bbc_%d",i); acc->SetBranchAddress(str,&bbc[i]); }; for(Int_t i=0; i<8; i++) { sprintf(str,"zdc_%d",i); acc->SetBranchAddress(str,&zdc[i]); }; for(Int_t i=0; i<8; i++) { sprintf(str,"vpd_%d",i); acc->SetBranchAddress(str,&vpd[i]); }; acc->SetBranchAddress("tot_bx",&tot_bx); acc->SetBranchAddress("blue",&blue); acc->SetBranchAddress("yell",&yell); // build arrays for restructuring; arrays are needed so that // we can implement bXing shift corrections Double_t bbce_arr[IMAX][120]; Double_t bbcw_arr[IMAX][120]; Double_t bbcx_arr[IMAX][120]; Double_t zdce_arr[IMAX][120]; Double_t zdcw_arr[IMAX][120]; Double_t zdcx_arr[IMAX][120]; Double_t vpde_arr[IMAX][120]; Double_t vpdw_arr[IMAX][120]; Double_t vpdx_arr[IMAX][120]; Int_t runnum_arr[IMAX]; Int_t fi_arr[IMAX]; Int_t fill_arr[IMAX]; Double_t time_arr[IMAX]; Double_t tot_bx_arr[IMAX][120]; Int_t blue_arr[IMAX][120]; Int_t yell_arr[IMAX][120]; Bool_t kicked_arr[IMAX][120]; // restructure tree into one suitable for analysis TTree * sca = new TTree("sca","restructured tree"); Double_t bbce,bbcw,bbcx; // e=east, w=west, x=coincidence Double_t zdce,zdcw,zdcx; Double_t vpde,vpdw,vpdx; Bool_t okEntry,kicked; sca->Branch("i",&index,"i/I"); sca->Branch("runnum",&runnum,"runnum/I"); sca->Branch("fi",&fill_index,"fi/I"); sca->Branch("fill",&fill,"fill/I"); sca->Branch("t",&time,"t/D"); sca->Branch("bx",&bx,"bx/I"); sca->Branch("bbce",&bbce,"bbce/D"); sca->Branch("bbcw",&bbcw,"bbcw/D"); sca->Branch("bbcx",&bbcx,"bbcx/D"); sca->Branch("zdce",&zdce,"zdce/D"); sca->Branch("zdcw",&zdcw,"zdcw/D"); sca->Branch("zdcx",&zdcx,"zdcx/D"); sca->Branch("vpde",&vpde,"vpde/D"); sca->Branch("vpdw",&vpdw,"vpdw/D"); sca->Branch("vpdx",&vpdx,"vpdx/D"); sca->Branch("tot_bx",&tot_bx,"tot_bx/D"); sca->Branch("blue",&blue,"blue/I"); sca->Branch("yell",&yell,"yell/I"); sca->Branch("kicked",&kicked,"kicked/O"); // read kicked bunches tree from "kicked" file TTree * kicked_tr = new TTree(); kicked_tr->ReadFile("kicked","fill/I:bx/I:spinbit/I"); Int_t kicked_fill,kicked_bx,kicked_spinbit; kicked_tr->SetBranchAddress("fill",&kicked_fill); kicked_tr->SetBranchAddress("bx",&kicked_bx); kicked_tr->SetBranchAddress("spinbit",&kicked_spinbit); for(Int_t q=0; q<acc->GetEntries(); q++) { acc->GetEntry(q); // -- see doc for bit details // BBC, ZDC, VPD bits: [ x w e ] bbce = bbc[1] + bbc[3] + bbc[5] + bbc[7]; // e + we + xe + xwe bbcw = bbc[2] + bbc[3] + bbc[6] + bbc[7]; // w + we + xw + xwe bbcx = bbc[3] + bbc[7]; // we + xwe zdce = zdc[1] + zdc[3] + zdc[5] + zdc[7]; // e + we + xe + xwe zdcw = zdc[2] + zdc[3] + zdc[6] + zdc[7]; // w + we + xw + xwe zdcx = zdc[3] + zdc[7]; // we + xwe vpde = vpd[1] + vpd[3] + vpd[5] + vpd[7]; // e + we + xe + xwe vpdw = vpd[2] + vpd[3] + vpd[6] + vpd[7]; // w + we + xw + xwe vpdx = vpd[3] + vpd[7]; // we + xwe // KICKED BUNCHES // manually omit empty bunches documented in pathologies.dat -- CLEAN UP PROCEDURE // (see 09.01.14 log entry) okEntry=true; // kicked bunches (presumably empty) /* if(fill==17384 && (bx==29 || bx==30 || bx==117)) okEntry=false; if(fill==17416 && bx==79) okEntry=false; if(fill==17491 && bx==105) okEntry=false; if(fill==17519 && (bx==94 || bx==109)) okEntry=false; if(fill==17520 && bx==0) okEntry=false; if(fill==17529 && bx==97) okEntry=false; if(fill==17534 && bx==112) okEntry=false; if(fill==17553 && bx==73) okEntry=false; if(fill==17554 && (bx==7 || bx==14)) okEntry=false; if(fill==17555 && bx==61) okEntry=false; if(fill==17576 && bx==94) okEntry=false; // afterpulse-like bunches -- remove 1st 2 bunches after abort gaps //if(fill==17512 && (bx>=40 && bx<=59)) okEntry=false; //if((fill>=17513 && fill<=17520) && ((bx>=0 && bx<=19) || (bx>=40 && bx<=59))) okEntry=false; */ for(Int_t kk=0; kk<kicked_tr->GetEntries(); kk++) { kicked_tr->GetEntry(kk); if(fill==kicked_fill && bx==kicked_bx) okEntry=false; }; kicked=!okEntry; // cleaned up analysis //kicked=0; // take all bXings // store data into arrays, implementing bXing shift corrections on scalers if(fill==16570 || fill==16567) { bbce_arr[index-1][(bx+113)%120] = bbce; // shift down 7 bXings bbcw_arr[index-1][(bx+113)%120] = bbcw; bbcx_arr[index-1][(bx+113)%120] = bbcx; zdce_arr[index-1][(bx+113)%120] = zdce; // shift down 7 bXings zdcw_arr[index-1][(bx+113)%120] = zdcw; zdcx_arr[index-1][(bx+113)%120] = zdcx; vpde_arr[index-1][(bx+113)%120] = vpde; // shift down 7 bXings vpdw_arr[index-1][(bx+113)%120] = vpdw; vpdx_arr[index-1][(bx+113)%120] = vpdx; } else if(fill == 16582 || fill == 16586 || fill == 16587 || fill == 16592 || fill == 16593 || fill == 16594 || fill == 16597 || fill == 16602) { bbce_arr[index-1][bx] = bbce; // no shift bbcw_arr[index-1][bx] = bbcw; bbcx_arr[index-1][bx] = bbcx; zdce_arr[index-1][bx] = zdce; // no shift zdcw_arr[index-1][bx] = zdcw; zdcx_arr[index-1][bx] = zdcx; vpde_arr[index-1][(bx+1)%120] = vpde; // shift up 1 bXings vpdw_arr[index-1][(bx+1)%120] = vpdw; vpdx_arr[index-1][(bx+1)%120] = vpdx; } else { bbce_arr[index-1][bx] = bbce; bbcw_arr[index-1][bx] = bbcw; bbcx_arr[index-1][bx] = bbcx; zdce_arr[index-1][bx] = zdce; zdcw_arr[index-1][bx] = zdcw; zdcx_arr[index-1][bx] = zdcx; vpde_arr[index-1][bx] = vpde; vpdw_arr[index-1][bx] = vpdw; vpdx_arr[index-1][bx] = vpdx; }; runnum_arr[index-1] = runnum; fi_arr[index-1] = fill_index; fill_arr[index-1] = fill; time_arr[index-1] = time; tot_bx_arr[index-1][bx] = tot_bx; blue_arr[index-1][bx] = blue; yell_arr[index-1][bx] = yell; kicked_arr[index-1][bx] = kicked; }; // fill restructured tree for(Int_t i=0; i<IMAX; i++) { index = i+1; runnum = runnum_arr[i]; fill_index = fi_arr[i]; fill = fill_arr[i]; time = time_arr[i]; for(Int_t b=0; b<120; b++) { bx = b; bbce = bbce_arr[i][b]; bbcw = bbcw_arr[i][b]; bbcx = bbcx_arr[i][b]; zdce = zdce_arr[i][b]; zdcw = zdcw_arr[i][b]; zdcx = zdcx_arr[i][b]; vpde = vpde_arr[i][b]; vpdw = vpdw_arr[i][b]; vpdx = vpdx_arr[i][b]; tot_bx = tot_bx_arr[i][b]; blue = blue_arr[i][b]; yell = yell_arr[i][b]; kicked = kicked_arr[i][b]; sca->Fill(); }; }; TFile * outfile = new TFile("counts.root","RECREATE"); acc->Write("acc"); sca->Write("sca"); printf("counts.root written\n"); };
void RooToyMCFit(){ stringstream out; out.str(""); out << "toyMC_" << _sigma_over_tau << "_" << _purity << "_" << mistag_rate << ".root"; TFile* file = TFile::Open(out.str().c_str()); TTree* tree = (TTree*)file->Get("ToyTree"); tree->Print(); // TFile* file = TFile::Open("ToyData/toyMC_453_0.912888_0.3_0.8_0.root"); // TFile* file = TFile::Open("ToyData/toyMC_10000_0.9_0.3_0.8_0.root"); // TTree* tree = (TTree*)file->Get("ToyTree1"); RooRealVar tau("tau","tau",_tau,"ps"); tau.setConstant(kTRUE); RooRealVar dm("dm","dm",_dm,"ps^{-1}"); dm.setConstant(kTRUE); RooAbsReal* sin2beta; RooAbsReal* cos2beta; if(softlimit){ RooRealVar x("x","x",_cos2beta,-3.,30000.); if(constBeta) x.setConstant(kTRUE); RooRealVar y("y","y",_sin2beta,-3.,30000.); if(constBeta) y.setConstant(kTRUE); cos2beta = new RooFormulaVar("cos2beta","cos2beta","@0/sqrt(@0*@0+@1*@1)",RooArgSet(x,y)); sin2beta = new RooFormulaVar("sin2beta","sin2beta","@0/sqrt(@0*@0+@1*@1)",RooArgSet(y,x)); // sin2beta = new RooFormulaVar("sin2beta","sin2beta","2/TMath::Pi()*TMath::ATan(@0)",RooArgSet(y)); // cos2beta = new RooFormulaVar("cos2beta","cos2beta","2/TMath::Pi()*TMath::ATan(@0)",RooArgSet(x)); } else{ sin2beta = new RooRealVar("sin2beta","sin2beta",_sin2beta,-3.,3.); if(constBeta) ((RooRealVar*)sin2beta)->setConstant(kTRUE); cos2beta = new RooRealVar("cos2beta","cos2beta",_cos2beta,-3.,3.); if(constBeta) ((RooRealVar*)cos2beta)->setConstant(kTRUE); } RooRealVar dt("dt","#Deltat",-5.,5.,"ps"); RooRealVar avgMisgat("avgMisgat","avgMisgat",mistag_rate,0.0,0.5); if(constMistag) avgMisgat.setConstant(kTRUE); RooRealVar delMisgat("delMisgat","delMisgat",0); delMisgat.setConstant(kTRUE); RooRealVar mu("mu","mu",0); mu.setConstant(kTRUE); tau.Print(); dm.Print(); sin2beta->Print(); cos2beta->Print(); avgMisgat.Print(); RooRealVar moment("moment","moment",0.); moment.setConstant(kTRUE); RooRealVar parity("parity","parity",-1.); parity.setConstant(kTRUE); RooRealVar* K[8]; RooAbsReal* Kb[8]; RooArgList Kset; RooRealVar* C[8]; RooRealVar* S[8]; RooFormulaVar* a1[2][8]; RooFormulaVar* b1[2][8]; RooFormulaVar* a2[2][8]; RooFormulaVar* b2[2][8]; for(int i=0; i<8; i++){ out.str(""); out << "K" << i+1; K[i] = new RooRealVar(out.str().c_str(),out.str().c_str(),_K[i],0.,1.); Kset.add(*K[i]); if(constK) K[i]->setConstant(kTRUE); K[i]->Print(); if(i!=7){ out.str(""); out << "Kb" << i+1; Kb[i] = new RooRealVar(out.str().c_str(),out.str().c_str(),_Kb[i],0.,1.); Kset.add(*Kb[i]); if(constK) ((RooRealVar*)Kb[i])->setConstant(kTRUE); Kb[i]->Print(); } out.str(""); out << "C" << i+1; C[i] = new RooRealVar(out.str().c_str(),out.str().c_str(),_C[i]); C[i]->setConstant(kTRUE); C[i]->Print(); out.str(""); out << "S" << i+1; S[i] = new RooRealVar(out.str().c_str(),out.str().c_str(),_S[i]); S[i]->setConstant(kTRUE); S[i]->Print(); } Kb[7] = new RooFormulaVar("K8b","K8b","1-@0-@1-@2-@3-@4-@5-@6-@7-@8-@9-@10-@11-@12-@13-@14",Kset); for(int i=0; i<8; i++){ out.str(""); out << "a10_" << i+1; a1[0][i] = new RooFormulaVar(out.str().c_str(),out.str().c_str(),"-(@0-@1)/(@0+@1)",RooArgList(*K[i],*Kb[i])); a1[0][i]->Print(); out.str(""); out << "a11_" << i+1; a1[1][i] = new RooFormulaVar(out.str().c_str(),out.str().c_str(),"(@0-@1)/(@0+@1)",RooArgList(*K[i],*Kb[i])); a1[1][i]->Print(); out.str(""); out << "a20_" << i+1; a2[0][i] = new RooFormulaVar(out.str().c_str(),out.str().c_str(),"(@0-@1)/(@0+@1)",RooArgList(*K[i],*Kb[i])); a2[0][i]->Print(); out.str(""); out << "a21_" << i+1; a2[1][i] = new RooFormulaVar(out.str().c_str(),out.str().c_str(),"-(@0-@1)/(@0+@1)",RooArgList(*K[i],*Kb[i])); a2[1][i]->Print(); out.str(""); out << "b10_" << i+1; b1[0][i] = new RooFormulaVar(out.str().c_str(),out.str().c_str(),"2.*(@2*@4+@3*@5)*TMath::Sqrt(@0*@1)/(@0+@1)",RooArgList(*K[i],*Kb[i],*C[i],*S[i],*sin2beta,*cos2beta)); b1[0][i]->Print(); out.str(""); out << "b11_" << i+1; b1[1][i] = new RooFormulaVar(out.str().c_str(),out.str().c_str(),"2.*(@2*@4-@3*@5)*TMath::Sqrt(@0*@1)/(@0+@1)",RooArgList(*K[i],*Kb[i],*C[i],*S[i],*sin2beta,*cos2beta)); b1[1][i]->Print(); out.str(""); out << "b20_" << i+1; b2[0][i] = new RooFormulaVar(out.str().c_str(),out.str().c_str(),"-2.*(@2*@4+@3*@5)*TMath::Sqrt(@0*@1)/(@0+@1)",RooArgList(*K[i],*Kb[i],*C[i],*S[i],*sin2beta,*cos2beta)); b2[0][i]->Print(); out.str(""); out << "b21_" << i+1; b2[1][i] = new RooFormulaVar(out.str().c_str(),out.str().c_str(),"-2.*(@2*@4-@3*@5)*TMath::Sqrt(@0*@1)/(@0+@1)",RooArgList(*K[i],*Kb[i],*C[i],*S[i],*sin2beta,*cos2beta)); b2[1][i]->Print(); cout << "bin = " << i+1 << endl; cout << " a11 = " << a1[0][i]->getVal() << " b11 = " << b1[0][i]->getVal() << endl; cout << " a12 = " << a1[1][i]->getVal() << " b12 = " << b1[1][i]->getVal() << endl; cout << " a21 = " << a2[0][i]->getVal() << " b21 = " << b2[0][i]->getVal() << endl; cout << " a22 = " << a2[1][i]->getVal() << " b22 = " << b2[1][i]->getVal() << endl; } RooRealVar* dgamma = new RooRealVar("dgamma","dgamma",0.); dgamma->setConstant(kTRUE); RooRealVar* f0 = new RooRealVar("f0","f0",1.); f0->setConstant(kTRUE); RooRealVar* f1 = new RooRealVar("f1","f1",0.); f1->setConstant(kTRUE); RooCategory tag("tag","tag"); tag.defineType("B0",1); tag.defineType("anti-B0",-1); RooCategory bin("bin","bin"); bin.defineType("1",1); bin.defineType("2",2); bin.defineType("3",3); bin.defineType("4",4); bin.defineType("5",5); bin.defineType("6",6); bin.defineType("7",7); bin.defineType("8",8); bin.defineType("-1",-1); bin.defineType("-2",-2); bin.defineType("-3",-3); bin.defineType("-4",-4); bin.defineType("-5",-5); bin.defineType("-6",-6); bin.defineType("-7",-7); bin.defineType("-8",-8); RooSuperCategory bintag("bintag","bintag",RooArgSet(bin,tag)); tree->Print(); RooDataSet d("data","data",tree,RooArgSet(dt,bin,tag)); cout << "DataSet is ready." << endl; d.Print(); RooRealVar mean("mean","mean",0.,"ps"); mean.setConstant(kTRUE); RooRealVar sigma("sigma","sigma",_sigma_over_tau*_tau,0.,1.5*_tau,"ps"); if(constSigma) sigma.setConstant(kTRUE); RooGaussModel rf("rf","rf",dt,mean,sigma); // RooTruthModel rf("rf","rf",dt); RooGaussian rfpdf("rfpdf","rfpdf",dt,mean,sigma); cout << "Preparing PDFs..." << endl; // RooRealVar* fsigs1[8]; // RooRealVar* fsigs1b[8]; // RooRealVar* fsigs2[8]; // RooRealVar* fsigs2b[8]; RooBDecay* sigpdfs1[8]; RooBDecay* sigpdfs1b[8]; RooBDecay* sigpdfs2[8]; RooBDecay* sigpdfs2b[8]; RooAddPdf* PDFs1[8]; RooAddPdf* PDFs1b[8]; RooAddPdf* PDFs2[8]; RooAddPdf* PDFs2b[8]; RooAddPdf* pdfs1[8]; RooAddPdf* pdfs1b[8]; RooAddPdf* pdfs2[8]; RooAddPdf* pdfs2b[8]; RooSimultaneous pdf("pdf","pdf",bintag); RooRealVar fsig("fsig","fsig",_purity,0.,1.); if(constFSig) fsig.setConstant(kTRUE); fsig.Print(); for(int j=0; j<8; j++){ // out.str(""); // out << "fsig1" << j+1; // fsigs1[j] = new RooRealVar(out.str().c_str(),out.str().c_str(),_purity,0.,1.); if(constFSig) fsigs1[j]->setConstant(kTRUE); // out.str(""); // out << "fsig1b" << j+1; // fsigs1b[j] = new RooRealVar(out.str().c_str(),out.str().c_str(),_purity,0.,1.); if(constFSig) fsigs1b[j]->setConstant(kTRUE); // out.str(""); // out << "fsig2" << j+1; // fsigs2[j] = new RooRealVar(out.str().c_str(),out.str().c_str(),_purity,0.,1.); if(constFSig) fsigs2[j]->setConstant(kTRUE); // out.str(""); // out << "fsig2b" << j+1; // fsigs2b[j] = new RooRealVar(out.str().c_str(),out.str().c_str(),_purity,0.,1.); if(constFSig) fsigs2b[j]->setConstant(kTRUE); out.str(""); out << "sigpdf1" << j+1; sigpdfs1[j] = new RooBDecay(out.str().c_str(),out.str().c_str(),dt,tau,*dgamma,*f0,*f1,*a1[0][j],*b1[0][j],dm,rf,RooBDecay::DoubleSided); out.str(""); out << "sigpdf1b" << j+1; sigpdfs1b[j] = new RooBDecay(out.str().c_str(),out.str().c_str(),dt,tau,*dgamma,*f0,*f1,*a1[1][j],*b1[1][j],dm,rf,RooBDecay::DoubleSided); out.str(""); out << "sigpdf2" << j+1; sigpdfs2[j] = new RooBDecay(out.str().c_str(),out.str().c_str(),dt,tau,*dgamma,*f0,*f1,*a2[0][j],*b2[0][j],dm,rf,RooBDecay::DoubleSided); out.str(""); out << "sigpdf2b" << j+1; sigpdfs2b[j] = new RooBDecay(out.str().c_str(),out.str().c_str(),dt,tau,*dgamma,*f0,*f1,*a2[1][j],*b2[1][j],dm,rf,RooBDecay::DoubleSided); out.str(""); out << "PDF1" << j+1; PDFs1[j] = new RooAddPdf(out.str().c_str(),out.str().c_str(),RooArgList(*sigpdfs1[j],rfpdf),RooArgList(fsig)); out.str(""); out << "PDF1b" << j+1; PDFs1b[j] = new RooAddPdf(out.str().c_str(),out.str().c_str(),RooArgList(*sigpdfs1b[j],rfpdf),RooArgList(fsig)); out.str(""); out << "PDF2" << j+1; PDFs2[j] = new RooAddPdf(out.str().c_str(),out.str().c_str(),RooArgList(*sigpdfs2[j],rfpdf),RooArgList(fsig)); out.str(""); out << "PDF2b" << j+1; PDFs2b[j] = new RooAddPdf(out.str().c_str(),out.str().c_str(),RooArgList(*sigpdfs2b[j],rfpdf),RooArgList(fsig)); //Adding mistaging out.str(""); out << "pdf1" << j+1; pdfs1[j] = new RooAddPdf(out.str().c_str(),out.str().c_str(),RooArgList(*PDFs2[j],*PDFs1[j]),RooArgList(avgMisgat)); out.str(""); out << "pdf1b" << j+1; pdfs1b[j] = new RooAddPdf(out.str().c_str(),out.str().c_str(),RooArgList(*PDFs2b[j],*PDFs1b[j]),RooArgList(avgMisgat)); out.str(""); out << "pdf2" << j+1; pdfs2[j] = new RooAddPdf(out.str().c_str(),out.str().c_str(),RooArgList(*PDFs1[j],*PDFs2[j]),RooArgList(avgMisgat)); out.str(""); out << "pdf2b" << j+1; pdfs2b[j] = new RooAddPdf(out.str().c_str(),out.str().c_str(),RooArgList(*PDFs1b[j],*PDFs2b[j]),RooArgList(avgMisgat)); out.str(""); out << "{" << j+1 << ";B0}"; pdf.addPdf(*pdfs1[j],out.str().c_str()); out.str(""); out << "{" << -(j+1) << ";B0}"; pdf.addPdf(*pdfs1b[j],out.str().c_str()); out.str(""); out << "{" << j+1 << ";anti-B0}"; pdf.addPdf(*pdfs2[j],out.str().c_str()); out.str(""); out << "{" << -(j+1) << ";anti-B0}"; pdf.addPdf(*pdfs2b[j],out.str().c_str()); } cout << "Fitting..." << endl; pdf.fitTo(d,Verbose(),Timer()); dt.setBins(50); cout << "Drawing plots." << endl; for(int i=0; i<8; i++){ RooPlot* dtFrame = dt.frame(); out.str(""); out << "tag == 1 && bin == " << i+1; RooDataSet* ds = d.reduce(out.str().c_str()); ds->plotOn(dtFrame,DataError(RooAbsData::SumW2),MarkerSize(1),Cut(out.str().c_str()),MarkerColor(kBlue)); out.str(""); out << "{" << j+1 << ";B0}"; bintag = out.str().c_str(); pdf.plotOn(dtFrame,ProjWData(*ds),Slice(bintag),LineColor(kBlue)); double chi2 = dtFrame->chiSquare(); out.str(""); out << "tag == -1 && bin == " << i+1; RooDataSet* dsb = d.reduce(out.str().c_str()); dsb->plotOn(dtFrame,DataError(RooAbsData::SumW2),MarkerSize(1),Cut(out.str().c_str()),MarkerColor(kRed)); out.str(""); out << "{" << j+1 << ";anti-B0}"; bintag = out.str().c_str(); pdf.plotOn(dtFrame,ProjWData(*dsb),Slice(bintag),LineColor(kRed)); double chi2b = dtFrame->chiSquare(); out.str(""); out << "#Delta t, toy MC, bin == " << i+1; TCanvas* cm = new TCanvas(out.str().c_str(),out.str().c_str(),600,400); cm->cd(); dtFrame->GetXaxis()->SetTitleSize(0.05); dtFrame->GetXaxis()->SetTitleOffset(0.85); dtFrame->GetXaxis()->SetLabelSize(0.05); dtFrame->GetYaxis()->SetTitleOffset(1.6); TPaveText *ptB = new TPaveText(0.7,0.65,0.98,0.99,"brNDC"); ptB->SetFillColor(0); ptB->SetTextAlign(12); out.str(""); out << "bin = " << (i+1); ptB->AddText(out.str().c_str()); out.str(""); out << "#chi^{2}(B^{0}) = " << chi2; ptB->AddText(out.str().c_str()); out.str(""); out << "#chi^{2}(#barB^{0}) = " << chi2b; ptB->AddText(out.str().c_str()); out.str(""); out << "#sigma/#tau = " << _sigma_over_tau; ptB->AddText(out.str().c_str()); out.str(""); out << "purity = " << _purity; ptB->AddText(out.str().c_str()); out.str(""); out << "mistag = " << mistag_rate; ptB->AddText(out.str().c_str()); dtFrame->Draw(); ptB->Draw(); out.str(""); out << "../Reports/cpfitfigs/dt_bin" << (i+1) << ".root"; cm->Print(out.str().c_str()); out.str(""); out << "../Reports/cpfitfigs/dt_bin" << (i+1) << ".png"; cm->Print(out.str().c_str()); } for(int i=0; i<8; i++){ RooPlot* dtFrame = dt.frame(); out.str(""); out << "tag == 1 && bin == " << -(i+1); RooDataSet* ds2 = (RooDataSet*)d.reduce(out.str().c_str()); ds2->plotOn(dtFrame,DataError(RooAbsData::SumW2),MarkerSize(1),Cut(out.str().c_str()),MarkerColor(kBlue)); out.str(""); out << "{" << -(j+1) << ";B0}"; bintag = out.str().c_str(); pdf.plotOn(dtFrame,ProjWData(*ds2),Slice(bintag),LineColor(kBlue)); double chi2 = dtFrame->chiSquare(); out.str(""); out << "tag == -1 && bin == " << -(i+1); RooDataSet* ds2b = (RooDataSet*)d.reduce(out.str().c_str()); ds2b->plotOn(dtFrame,DataError(RooAbsData::SumW2),MarkerSize(1),Cut(out.str().c_str()),MarkerColor(kRed)); out.str(""); out << "{" << -(j+1) << ";anti-B0}"; bin = out.str().c_str(); pdf.plotOn(dtFrame,ProjWData(*ds2b),Slice(bintag),LineColor(kRed)); double chi2b = dtFrame->chiSquare(); out.str(""); out << "#Delta t, toy MC, bin == " << -(i+1); TCanvas* cm = new TCanvas(out.str().c_str(),out.str().c_str(),600,400); cm->cd(); dtFrame->GetXaxis()->SetTitleSize(0.05); dtFrame->GetXaxis()->SetTitleOffset(0.85); dtFrame->GetXaxis()->SetLabelSize(0.05); dtFrame->GetYaxis()->SetTitleOffset(1.6); TPaveText *ptB = new TPaveText(0.7,0.65,0.98,0.99,"brNDC"); ptB->SetFillColor(0); ptB->SetTextAlign(12); out.str(""); out << "bin = " << -(i+1); ptB->AddText(out.str().c_str()); out.str(""); out << "#chi^{2}(B^{0}) = " << chi2; ptB->AddText(out.str().c_str()); out.str(""); out << "#chi^{2}(#barB^{0}) = " << chi2b; ptB->AddText(out.str().c_str()); out.str(""); out << "#sigma/#tau = " << _sigma_over_tau; ptB->AddText(out.str().c_str()); out.str(""); out << "purity = " << _purity; ptB->AddText(out.str().c_str()); out.str(""); out << "mistag = " << mistag_rate; ptB->AddText(out.str().c_str()); dtFrame->Draw(); ptB->Draw(); out.str(""); out << "../Reports/cpfitfigs/dt_bin" << -(i+1) << ".root"; cm->Print(out.str().c_str()); out.str(""); out << "../Reports/cpfitfigs/dt_bin" << -(i+1) << ".png"; cm->Print(out.str().c_str()); } return; }
//----------------------------------------------------------------------------- StatusCode RootHistCnv::RDirectoryCnv::fillObjRefs(IOpaqueAddress* pAddr,DataObject* pObj) { MsgStream log(msgSvc(), "RDirectoryCnv"); IRegistry* pReg = pObj->registry(); std::string full = pReg->identifier(); const std::string& fname = pAddr->par()[0]; TFile *tf; findTFile(full,tf).ignore(); // cd to TFile: setDirectory(full); TIter nextkey(gDirectory->GetListOfKeys()); while (TKey *key = (TKey*)nextkey()) { IOpaqueAddress* pA = 0; TObject *obj = key->ReadObj(); std::string title = obj->GetTitle(); std::string sid = obj->GetName(); std::string f2 = full + "/" + sid; int idh = ::strtol(sid.c_str(),NULL,10); // introduced by Grigori Rybkine std::string clname = key->GetClassName(); std::string clnm = clname.substr(0,3); TClass* isa = obj->IsA(); if (isa->InheritsFrom("TTree")) { createAddress(full, CLID_ColumnWiseTuple, idh, obj, pA).ignore(); TTree* tree = (TTree*) obj; tree->Print(); log << MSG::DEBUG << "Reg CWNT \"" << obj->GetTitle() << "\" as " << f2 << endmsg; title = "/" + sid; } else if (isa->InheritsFrom("TDirectory")) { createAddress(full,CLID_NTupleDirectory, title, obj, pA).ignore(); } else if ( isa == TProfile::Class() ) { createAddress(full,CLID_ProfileH,idh,obj,pA).ignore(); title = sid; } else if ( isa == TProfile2D::Class() ) { createAddress(full,CLID_ProfileH2,idh,obj,pA).ignore(); title = sid; } else if ( isa == TH1C::Class() ) { createAddress(full,CLID_H1D,idh,obj,pA).ignore(); title = sid; } else if ( isa == TH1S::Class() ) { createAddress(full,CLID_H1D,idh,obj,pA).ignore(); title = sid; } else if ( isa == TH1I::Class() ) { createAddress(full,CLID_H1D,idh,obj,pA).ignore(); title = sid; } else if ( isa == TH1F::Class() ) { createAddress(full,CLID_H1D,idh,obj,pA).ignore(); title = sid; } else if ( isa == TH1D::Class() ) { createAddress(full,CLID_H1D,idh,obj,pA).ignore(); title = sid; } else if ( isa == TH2C::Class() ) { createAddress(full,CLID_H2D,idh,obj,pA).ignore(); title = sid; } else if ( isa == TH2S::Class() ) { createAddress(full,CLID_H2D,idh,obj,pA).ignore(); title = sid; } else if ( isa == TH2I::Class() ) { createAddress(full,CLID_H2D,idh,obj,pA).ignore(); title = sid; } else if ( isa == TH2F::Class() ) { createAddress(full,CLID_H2D,idh,obj,pA).ignore(); title = sid; } else if ( isa == TH2D::Class() ) { createAddress(full,CLID_H2D,idh,obj,pA).ignore(); title = sid; } else if ( isa == TH3C::Class() ) { createAddress(full,CLID_H3D,idh,obj,pA).ignore(); title = sid; } else if ( isa == TH3S::Class() ) { createAddress(full,CLID_H3D,idh,obj,pA).ignore(); title = sid; } else if ( isa == TH3I::Class() ) { createAddress(full,CLID_H3D,idh,obj,pA).ignore(); title = sid; } else if ( isa == TH3F::Class() ) { createAddress(full,CLID_H3D,idh,obj,pA).ignore(); title = sid; } else if ( isa == TH3D::Class() ) { createAddress(full,CLID_H3D,idh,obj,pA).ignore(); title = sid; } else { log << MSG::ERROR << "Encountered an unknown object with key: " << obj->GetName() << " in ROOT file " << fname << endmsg; return StatusCode::FAILURE; } if ( 0 != pA ) { StatusCode sc = dataManager()->registerAddress(pReg, title, pA); if ( !sc.isSuccess() ) { log << MSG::ERROR << "Failed to register address for " << full << endmsg; return sc; } log << MSG::VERBOSE << "Created address for " << clnm << "'" << title << "' in " << full << endmsg; } } return StatusCode::SUCCESS; }