diff --git a/Analyzer/test/macros_combined/ZprimeMuMuPatMiniAod.C b/Analyzer/test/macros_combined/ZprimeMuMuPatMiniAod.C index afbff69..38297bc 100644 --- a/Analyzer/test/macros_combined/ZprimeMuMuPatMiniAod.C +++ b/Analyzer/test/macros_combined/ZprimeMuMuPatMiniAod.C @@ -30,7 +30,7 @@ bool myfunction (int i,int j) { return (i rhs); } TString inputfile; -void ZprimeMuMuPatMiniAod::Loop() +void ZprimeMuMuPatMiniAod::Loop(TString outfilename ) { time_t start,end; double dif; @@ -56,11 +56,93 @@ void ZprimeMuMuPatMiniAod::Loop() float ptMax = 400.0; ptEffCut = 3000.0; double muon_mass = 0.1056583; - weight=1.; + weight=1.; // why is weight = 1.? //if( DATA_type=="2015") weight=1.; - TFile *output = new TFile("CMSSW763-Analyse_ZtoMuMu_13TeV_M5000_miniaod.root","recreate"); + if( !outfilename ){ + TString outfilename = "CMSSW803-Analyze_ZtoMuMu_13TeV_M5000_miniaod_filledhistos.root"; + } + TFile *output = new TFile(outfilename,"recreate"); //TFile *output = new TFile("CMSSW745-Analyse_ZprimeToTauTau_13TeV_50_M_3000.root","recreate"); //================================================================================== + // = + // Start a tree with important observables = + // = + //================================================================================== + tree_ = new TTree("before_cuts", "Store variables before cuts"); + tree_->SetAutoSave(10000000000); + tree_->SetAutoFlush(1000000); + tree_->Branch("RunNum",&event_runNo,"RunNum/i"); + tree_->Branch("EvtNum",&event_evtNo,"EvtNum/i"); + tree_->Branch("weight",&weight,"weight/F"); + tree_->Branch("Mu_ptTunePMuonBestTrack",&Mu_ptTunePMuonBestTrack); + tree_->Branch("Mu_absdxyTunePMuonBestTrack",&Mu_absdxyTunePMuonBestTrack); + tree_->Branch("Mu_dPToverPTTunePMuonBestTrack",&Mu_dPToverPTTunePMuonBestTrack); + tree_->Branch("Mu_trackiso",&Mu_trackiso); + tree_->Branch("Mu_ptInnerTrack",&Mu_ptInnerTrack); + tree_->Branch("Mu_numberOftrackerLayersWithMeasurement",&Mu_numberOftrackerLayersWithMeasurement); + tree_->Branch("Mu_numberOfValidPixelHits",&Mu_numberOfValidPixelHits); + tree_->Branch("Mu_numberOfMatchedStations",&Mu_numberOfMatchedStations); + // Tree for after the 2 muons cut + tree_twomuons_ = new TTree("after_twomuons_cut", "Store variables after 2 muons cut"); + tree_twomuons_->SetAutoSave(10000000000); + tree_twomuons_->SetAutoFlush(1000000); + tree_twomuons_->Branch("RunNum",&event_runNo,"RunNum/i"); + tree_twomuons_->Branch("EvtNum",&event_evtNo,"EvtNum/i"); + tree_twomuons_->Branch("weight",&weight,"weight/F"); + tree_twomuons_->Branch("Mu_ptTunePMuonBestTrack",&Mu_ptTunePMuonBestTrack); + tree_twomuons_->Branch("Mu_absdxyTunePMuonBestTrack",&Mu_absdxyTunePMuonBestTrack); + tree_twomuons_->Branch("Mu_dPToverPTTunePMuonBestTrack",&Mu_dPToverPTTunePMuonBestTrack); + tree_twomuons_->Branch("Mu_trackiso",&Mu_trackiso); + tree_twomuons_->Branch("Mu_ptInnerTrack",&Mu_ptInnerTrack); + tree_twomuons_->Branch("Mu_numberOftrackerLayersWithMeasurement",&Mu_numberOftrackerLayersWithMeasurement); + tree_twomuons_->Branch("Mu_numberOfValidPixelHits",&Mu_numberOfValidPixelHits); + tree_twomuons_->Branch("Mu_numberOfMatchedStations",&Mu_numberOfMatchedStations); + // Tree for after the vertex mass cut + tree_vtxmass_ = new TTree("after_vtxmass_cut", "Store variables after vtxmass< 60 cut"); + tree_vtxmass_->SetAutoSave(10000000000); + tree_vtxmass_->SetAutoFlush(1000000); + tree_vtxmass_->Branch("RunNum",&event_runNo,"RunNum/i"); + tree_vtxmass_->Branch("EvtNum",&event_evtNo,"EvtNum/i"); + tree_vtxmass_->Branch("weight",&weight,"weight/F"); + tree_vtxmass_->Branch("Mu_ptTunePMuonBestTrack",&Mu_ptTunePMuonBestTrack); + tree_vtxmass_->Branch("Mu_absdxyTunePMuonBestTrack",&Mu_absdxyTunePMuonBestTrack); + tree_vtxmass_->Branch("Mu_dPToverPTTunePMuonBestTrack",&Mu_dPToverPTTunePMuonBestTrack); + tree_vtxmass_->Branch("Mu_trackiso",&Mu_trackiso); + tree_vtxmass_->Branch("Mu_ptInnerTrack",&Mu_ptInnerTrack); + tree_vtxmass_->Branch("Mu_numberOftrackerLayersWithMeasurement",&Mu_numberOftrackerLayersWithMeasurement); + tree_vtxmass_->Branch("Mu_numberOfValidPixelHits",&Mu_numberOfValidPixelHits); + tree_vtxmass_->Branch("Mu_numberOfMatchedStations",&Mu_numberOfMatchedStations); + // Tree for after the hlt cut + tree_hlt_ = new TTree("after_hlt_cut", "Store variables after hlt cut"); + tree_hlt_->SetAutoSave(10000000000); + tree_hlt_->SetAutoFlush(1000000); + tree_hlt_->Branch("RunNum",&event_runNo,"RunNum/i"); + tree_hlt_->Branch("EvtNum",&event_evtNo,"EvtNum/i"); + tree_hlt_->Branch("weight",&weight,"weight/F"); + tree_hlt_->Branch("Mu_ptTunePMuonBestTrack",&Mu_ptTunePMuonBestTrack); + tree_hlt_->Branch("Mu_absdxyTunePMuonBestTrack",&Mu_absdxyTunePMuonBestTrack); + tree_hlt_->Branch("Mu_dPToverPTTunePMuonBestTrack",&Mu_dPToverPTTunePMuonBestTrack); + tree_hlt_->Branch("Mu_trackiso",&Mu_trackiso); + tree_hlt_->Branch("Mu_ptInnerTrack",&Mu_ptInnerTrack); + tree_hlt_->Branch("Mu_numberOftrackerLayersWithMeasurement",&Mu_numberOftrackerLayersWithMeasurement); + tree_hlt_->Branch("Mu_numberOfValidPixelHits",&Mu_numberOfValidPixelHits); + tree_hlt_->Branch("Mu_numberOfMatchedStations",&Mu_numberOfMatchedStations); + // Tree for after the vtxchi2mu cut + tree_vtxchi2mu_ = new TTree("after_vtxchi2mu_cut", "Store variables after vtxchi2mu< 20 cut"); + tree_vtxchi2mu_->SetAutoSave(10000000000); + tree_vtxchi2mu_->SetAutoFlush(1000000); + tree_vtxchi2mu_->Branch("RunNum",&event_runNo,"RunNum/i"); + tree_vtxchi2mu_->Branch("EvtNum",&event_evtNo,"EvtNum/i"); + tree_vtxchi2mu_->Branch("weight",&weight,"weight/F"); + tree_vtxchi2mu_->Branch("Mu_ptTunePMuonBestTrack",&Mu_ptTunePMuonBestTrack); + tree_vtxchi2mu_->Branch("Mu_absdxyTunePMuonBestTrack",&Mu_absdxyTunePMuonBestTrack); + tree_vtxchi2mu_->Branch("Mu_dPToverPTTunePMuonBestTrack",&Mu_dPToverPTTunePMuonBestTrack); + tree_vtxchi2mu_->Branch("Mu_trackiso",&Mu_trackiso); + tree_vtxchi2mu_->Branch("Mu_ptInnerTrack",&Mu_ptInnerTrack); + tree_vtxchi2mu_->Branch("Mu_numberOftrackerLayersWithMeasurement",&Mu_numberOftrackerLayersWithMeasurement); + tree_vtxchi2mu_->Branch("Mu_numberOfValidPixelHits",&Mu_numberOfValidPixelHits); + tree_vtxchi2mu_->Branch("Mu_numberOfMatchedStations",&Mu_numberOfMatchedStations); + //================================================================================== // = // Start the histograms for CollinSoper CMF = // = @@ -202,7 +284,7 @@ void ZprimeMuMuPatMiniAod::Loop() Char_t txtOUT[500]; //sprintf(txtOUT,"%s_txt.txt",datasetName.Data()); sprintf(txtOUT,"CMSSW745-Analyse_ZprimeToMuMu_13TeV_cand.txt"); - //cout << "Opening a txt file with candidate events " << txtOUT << endl; + cout << "Opening a txt file with candidate events " << txtOUT << endl; //ofstream output_txt; output_txt.open(txtOUT); output_txt << "CANDIDATES Events:" << endl; @@ -213,12 +295,15 @@ void ZprimeMuMuPatMiniAod::Loop() //TString inputfile=name; //inputfile=name; - //cout << "Name of the input file is= " << inputfile.Data() << endl; + cout << "Name of the input file is= " << inputfile.Data() << endl; //================================================================================== if (fChain == 0) return; Long64_t nentries = fChain->GetEntriesFast(); Long64_t nbytes = 0, nb = 0; + // for testing: + // + //for (Long64_t jentry=0; jentry<100;jentry++) { for (Long64_t jentry=0; jentryFill(); + // See below for save after vertex mass cut + // Search for tree_vtxmass_ + bool firstMuFinal = SelectFirstMuon(PtRecTunePMuBestTrack1,EnRecMu1,EtaRecMu1,PhiRecMu1,ChargeRecMu1,flagmu1, pxRecMu1,pyRecMu1,pzRecMu1,pRecMu1,dxyRecMu1,PtRecTunePMu1, PtRecMuBestTrack1); @@ -274,29 +365,60 @@ void ZprimeMuMuPatMiniAod::Loop() // = //========================================================= //cout << "firstMu= " << firstMuFinal << " " << "secondMu= " << secondMuFinal << endl; + if(firstMuFinal == 0 || secondMuFinal == 0) continue; + // Fill a tree after the dimuon mass cut to see its impact + tree_twomuons_->Fill(); + h1_ptHistoBefor_->Fill(PtRecTunePMu1); + h1_ptHistoBefor_->Fill(PtRecTunePMu2); + h1_etaHistoBefor_->Fill(EtaRecMu1); + h1_etaHistoBefor_->Fill(EtaRecMu2); + //================================================================================== //cout << "Vertex mass mu= " << vtxMassMu << endl; if(vtxMassMu<60) continue; + // Fill a tree after the vertex mass cut to see its impact + tree_vtxmass_->Fill(); + h1_ptHistoPassingVtxChi2Mu_->Fill(PtRecTunePMu1); + h1_ptHistoPassingVtxChi2Mu_->Fill(PtRecTunePMu2); //========================================================= // start doing matching between reco & HLT = // = //========================================================= bool fireHLT2 = isPassHLT(); if(fireHLT2 == 0) continue; + // Fill a tree after the hlt cut to see its impact + tree_hlt_->Fill(); bool RecoMuon1MatchingWithHLT1 = RecoHLTMuonMatching(EtaRecMu1,PhiRecMu1); bool RecoMuon2MatchingWithHLT2 = RecoHLTMuonMatching(EtaRecMu2,PhiRecMu2); //cout << "HLTMatching= " << RecoMuon1MatchingWithHLT1 << " " << RecoMuon2MatchingWithHLT2 << endl; if(RecoMuon1MatchingWithHLT1==1 || RecoMuon2MatchingWithHLT2==1) - { - //PrintEventInformation(256843,465,665539990,vtxChi2Mu,vtxMassMu,CosmicRejec); - if(vtxChi2Mu<20.0 && CosmicRejec>-0.9998) - { - PlotRecoInfo(CosmicRejec,vtxMassMu,MassGen,PtRecTunePMuBestTrack1,PtRecTunePMu1,PtRecMuBestTrack1,mPtGen1,EtaRecMu1, - PtRecTunePMuBestTrack2,PtRecTunePMu2,PtRecMuBestTrack2,mPtGen2,EtaRecMu2); - CosThetaCollinSoper(PtRecTunePMuBestTrack1,EtaRecMu1,PhiRecMu1,EnRecMu1, - PtRecTunePMuBestTrack2,EtaRecMu2,PhiRecMu2,EnRecMu2, - ChargeRecMu1,vtxMassMu); - } + { + h1_ptHistoPassingHLT_->Fill(PtRecTunePMu1); + h1_ptHistoPassingHLT_->Fill(PtRecTunePMu2); + h1_etaHistoPassingHLT_->Fill(EtaRecMu1); + h1_etaHistoPassingHLT_->Fill(EtaRecMu2); + //PrintEventInformation(256843,465,665539990,vtxChi2Mu,vtxMassMu,CosmicRejec); + if(vtxChi2Mu<20.0) + { + // Fill a tree after the vertex mass cut to see its impact + tree_vtxchi2mu_->Fill(); + h1_ptHistoPassingVtxChi2Mu_->Fill(PtRecTunePMu1); + h1_ptHistoPassingVtxChi2Mu_->Fill(PtRecTunePMu2); + h1_etaHistoPassingVtxChi2Mu_->Fill(EtaRecMu1); + h1_etaHistoPassingVtxChi2Mu_->Fill(EtaRecMu2); + if(CosmicRejec>-0.9998) + { + h1_ptHistoPassingCosmicRejec_->Fill(PtRecTunePMu1); + h1_ptHistoPassingCosmicRejec_->Fill(PtRecTunePMu2); + h1_etaHistoPassingCosmicRejec_->Fill(EtaRecMu1); + h1_etaHistoPassingCosmicRejec_->Fill(EtaRecMu2); + PlotRecoInfo(CosmicRejec,vtxMassMu,MassGen,PtRecTunePMuBestTrack1,PtRecTunePMu1,PtRecMuBestTrack1,mPtGen1,EtaRecMu1, + PtRecTunePMuBestTrack2,PtRecTunePMu2,PtRecMuBestTrack2,mPtGen2,EtaRecMu2); + CosThetaCollinSoper(PtRecTunePMuBestTrack1,EtaRecMu1,PhiRecMu1,EnRecMu1, + PtRecTunePMuBestTrack2,EtaRecMu2,PhiRecMu2,EnRecMu2, + ChargeRecMu1,vtxMassMu); + } + } } } //=================================================== @@ -314,6 +436,7 @@ void ZprimeMuMuPatMiniAod::Loop() time (&end); dif = difftime (end,start); printf ("It took you %.2lf minutes to run your program.\n", (dif/60.0) ); + cout << "Output written to " << outfilename << endl; } //================================================================================== // = diff --git a/Analyzer/test/macros_combined/ZprimeMuMuPatMiniAod.h b/Analyzer/test/macros_combined/ZprimeMuMuPatMiniAod.h index 92afac4..2ef70c0 100644 --- a/Analyzer/test/macros_combined/ZprimeMuMuPatMiniAod.h +++ b/Analyzer/test/macros_combined/ZprimeMuMuPatMiniAod.h @@ -36,6 +36,15 @@ using namespace std; class ZprimeMuMuPatMiniAod { public : TTree *fChain; //!pointer to the analyzed TTree or TChain + + // save a tree + TTree *tree_; // pointer to tree before cuts + TTree *tree_twomuons_; // pointer to tree after 2mu cut + TTree *tree_vtxmass_; // pointer to tree after vtxmass cut + TTree *tree_hlt_; // pointer to tree after hlt cut + TTree *tree_vtxchi2mu_; // pointer to tree after vtxchi2mu cut + vector *Mu_ptTunePMuonBestTrack_; + Int_t fCurrent; //!current Tree number in a TChain // Declaration of leaf types @@ -446,7 +455,8 @@ public : virtual Int_t GetEntry(Long64_t entry); virtual Long64_t LoadTree(Long64_t entry); virtual void Init(TTree *tree); - virtual void Loop(); + TString outfilename; + virtual void Loop(TString outfilename); virtual Bool_t Notify(); virtual void Show(Long64_t entry = -1); void PrintEventInformation(int runNumber, int lumiNumber, int eventNumber, @@ -654,9 +664,10 @@ ZprimeMuMuPatMiniAod::ZprimeMuMuPatMiniAod(TTree *tree) : fChain(0) // if parameter tree is not specified (or zero), connect the file // used to generate this class and read the Tree. if (tree == 0) { - TFile *f = (TFile*)gROOT->GetListOfFiles()->FindObject("CMSSW763_MC_DYtoMuMu_13TeV_pattuple200.root"); + TString inputfile = "/nfs/dust/cms/user/sonnevej/CMSSW803_MC_DYtoMuMu_13TeV_pattuple200.root"; + TFile *f = (TFile*)gROOT->GetListOfFiles()->FindObject(inputfile); if (!f || !f->IsOpen()) { - f = new TFile("CMSSW763_MC_DYtoMuMu_13TeV_pattuple200.root"); + f = new TFile(inputfile); } f->GetObject("tree",tree); diff --git a/Analyzer/test/macros_combined/analyze_and_make_tree.sh b/Analyzer/test/macros_combined/analyze_and_make_tree.sh new file mode 100755 index 0000000..e6586d0 --- /dev/null +++ b/Analyzer/test/macros_combined/analyze_and_make_tree.sh @@ -0,0 +1,59 @@ +#!/usr/bin/env zsh + +# Run this file to analyze a given tree + +if [ -z "$1" ] + then + OUTFILENAME="CMSSW803-Analyze_ZtoMuMu_13TeV_M5000_miniaod_filledhistos.root" + echo $0: optional usage: $0 outputfilename inputfilename + #exit 3 + else + OUTFILENAME=$1 + if [ -z "$2" ] + then + INFILENAME="/nfs/dust/cms/user/sonnevej/CMSSW803_MC_DYtoMuMu_13TeV_pattuple200.root" + echo $0: optional usage: $0 outputfilename inputfilename + #echo $0: usage: $0 outputfilename + #exit 3 + else + INFILENAME=$2 + fi +fi + + + +if [[ -a $OUTFILENAME ]] + then + echo will not analyze your tree $INFILENAME + echo outputfile $OUTFILENAME already exists + echo please remove or rename $OUTFILENAME + exit 1 + else + echo "will write output to" $OUTFILENAME + echo will now analyze your tree $INFILENAME +fi +export QUOTES='"' +export WRITE_TO_FILE=$QUOTES$OUTFILENAME$QUOTES +export ANALYZE_FILE=$QUOTES$INFILENAME$QUOTES + + + +root -b -l << EOF +Char_t name[300]; +sprintf(name,${ANALYZE_FILE}); +TFile *file0 = TFile::Open(name) +TTree *tree3 = (TTree*)file0->Get("tree"); +.L ZprimeMuMuPatMiniAod.C+ +ZprimeMuMuPatMiniAod b(tree3); +b.Loop(${WRITE_TO_FILE}); +.q +EOF + + +if [[ -a $OUTFILENAME ]] + then + echo file $OUTFILENAME has been created + else + echo did not succeed to write to $OUTFILENAME "-- Sorry!" + echo "Sorry!" +fi diff --git a/Analyzer/test/runMakeZprimeMiniAodTree_cfg.py b/Analyzer/test/runMakeZprimeMiniAodTree_cfg.py index fbb20ad..d789ffa 100644 --- a/Analyzer/test/runMakeZprimeMiniAodTree_cfg.py +++ b/Analyzer/test/runMakeZprimeMiniAodTree_cfg.py @@ -72,11 +72,11 @@ # Global tag (MC) from Configuration.AlCa.GlobalTag_condDBv2 import GlobalTag -process.GlobalTag = GlobalTag(process.GlobalTag, '76X_mcRun2_asymptotic_v12', '') +process.GlobalTag = GlobalTag(process.GlobalTag, '80X_mcRun2_asymptotic_v12', '') process.demo = cms.EDAnalyzer("MakeZprimeMiniAodTree", #outputFile = cms.string('CMSSW763_MC_DYtoEE_6000_inf_13TeV_pattuple.root'), - outputFile = cms.string('CMSSW763_MC_DYtoMuMu_13TeV_pattuple200.root'), + outputFile = cms.string('/nfs/dust/cms/user/sonnevej/CMSSW803_MC_DYtoMuMu_13TeV_pattuple200.root'), scProducer = cms.InputTag("reducedEgamma:reducedSuperClusters"), vertices = cms.InputTag("offlineSlimmedPrimaryVertices"), muons = cms.InputTag("slimmedMuons"),