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(); } }
// Simple example of reading a generated Root file void testgeo(char *filename=NULL) { // Clear global scope gROOT->Reset(); // Load the library with class dictionary info // (create with "gmake shared") char* wcsimdirenv; wcsimdirenv = getenv ("WCSIMDIR"); if(wcsimdirenv != NULL){ gSystem->Load("${WCSIMDIR}/libWCSimRoot.so"); }else{ gSystem->Load("../libWCSimRoot.so"); } // Open the file TFile *file; if (filename==NULL){ file = new TFile("../wcsim.root","read"); }else{ file = new TFile(filename,"read"); } if (!file->IsOpen()){ cout << "Error, could not open input file: " << filename << endl; return -1; } // Get the a pointer to the tree from the file TTree *gtree = (TTree*)file->Get("wcsimGeoT"); // Get the number of events int nevent = gtree->GetEntries(); printf("geo nevent %d\n",nevent); // Create a WCSimRootGeom to put stuff from the tree in WCSimRootGeom* wcsimrootgeom = new WCSimRootGeom(); // Set the branch address for reading from the tree TBranch *branch = gtree->GetBranch("wcsimrootgeom"); branch->SetAddress(&wcsimrootgeom); // Now loop over "events" (should be only one for geo tree) int ev; for (ev=0;ev<nevent; ev++) { // Read the event from the tree into the WCSimRootGeom instance gtree->GetEntry(ev); printf("Cyl radius %f\n", wcsimrootgeom->GetWCCylRadius()); printf("Cyl length %f\n", wcsimrootgeom->GetWCCylLength()); printf("PMT radius %f\n", wcsimrootgeom->GetWCPMTRadius()); printf("Offset x y z %f %f %f\n", wcsimrootgeom->GetWCOffset(0), wcsimrootgeom->GetWCOffset(1),wcsimrootgeom->GetWCOffset(2)); int numpmt = wcsimrootgeom->GetWCNumPMT(); printf("Num PMTs %d\n", numpmt); int i; for (i=0;i<((numpmt<20)?numpmt:20);i++){ WCSimRootPMT pmt; pmt = wcsimrootgeom->GetPMT(i); printf ("pmt %d %d %d\n",i,pmt.GetTubeNo(), pmt.GetCylLoc()); printf ("position: %f %f %f\n", pmt.GetPosition(0), pmt.GetPosition(1),pmt.GetPosition(2)); printf ("orientation: %f %f %f\n", pmt.GetOrientation(0), pmt.GetOrientation(1),pmt.GetOrientation(2)); } } // End of loop over events }
void makeVNDet(){ bool testrun = 0; const int norder_ = 3; const int QnBinOrder_ = 2; const double vtxCut = 15.; static const int ptBinMin = 0; static const int ptBinMax = nptbinsDefault-1; static const int etaBinMin = 0; //0; static const int etaBinMax = netabinsDefault-1; TFile * fAna; TTree * tree; double centval; double vtx; TH2D * sumw; TH2D * sumwqx; TH2D * sumwqy; TH2I * hMult; double qnHFx_EP[NumEPNames]; double qnHFy_EP[NumEPNames]; double sumET_EP[NumEPNames]; TFile * fQNDet; TH1D * hqnHFDet_x[NumEPNames]; TH1D * hqnHFDet_y[NumEPNames]; TFile * fQN; TH1D * hqbins[NCENT][NEPSymm]; TFile * fOut; TDirectory * SubEvt_0; TDirectory * SubEvt_1; TDirectory * FullEvt; TH2D * hVNDetX_0[NQN]; TH2D * hVNDetY_0[NQN]; TH2D * hVNDetX_1[NQN]; TH2D * hVNDetY_1[NQN]; TH2D * hVNDetX_full[NQN]; TH2D * hVNDetY_full[NQN]; double VNRawX_0[NCENT][NEPSymm][NQN]; double VNRawY_0[NCENT][NEPSymm][NQN]; double VNRawX_1[NCENT][NEPSymm][NQN]; double VNRawY_1[NCENT][NEPSymm][NQN]; double VNRawX_full[NCENT][NEPSymm][NQN]; double VNRawY_full[NCENT][NEPSymm][NQN]; double sumw_0[NCENT][NEPSymm][NQN]; double sumw_1[NCENT][NEPSymm][NQN]; double sumw_full[NCENT][NEPSymm][NQN]; int evtMult_0[NCENT][NEPSymm][NQN]; int evtMult_1[NCENT][NEPSymm][NQN]; int evtMult_full[NCENT][NEPSymm][NQN]; double VNDetX_0[NCENT][NEPSymm][NQN]; double VNDetY_0[NCENT][NEPSymm][NQN]; double VNDetX_1[NCENT][NEPSymm][NQN]; double VNDetY_1[NCENT][NEPSymm][NQN]; double VNDetX_full[NCENT][NEPSymm][NQN]; double VNDetY_full[NCENT][NEPSymm][NQN]; int Nevents[NCENT][NEPSymm][NQN]; int NFails[NCENT][NEPSymm][NQN]; // // MAIN // //-- Set up the analyzer objects fAna = new TFile(fAnaTreeName); tree = (TTree*) fAna->Get("ebyeana/tree"); sumwqx = new TH2D(Form("sumwqx%i", norder_), Form("sumwqx%i", norder_), nptbinsDefault, ptbinsDefault, netabinsDefault, etabinsDefault); sumwqy = new TH2D(Form("sumwqy%i", norder_), Form("sumwqy%i", norder_), nptbinsDefault, ptbinsDefault, netabinsDefault, etabinsDefault); sumw = new TH2D("sumw", "sumw", nptbinsDefault, ptbinsDefault, netabinsDefault, etabinsDefault); hMult = new TH2I("hMult", "hMult", nptbinsDefault, ptbinsDefault, netabinsDefault, etabinsDefault); tree->SetBranchAddress("Cent", ¢val); tree->SetBranchAddress("Vtx", &vtx); tree->SetBranchAddress("mult", &hMult); tree->SetBranchAddress(Form("sumwqx%i", norder_), &sumwqx); tree->SetBranchAddress(Form("sumwqy%i", norder_), &sumwqy); tree->SetBranchAddress("sumw", &sumw); tree->SetBranchAddress("qnHFx_EP", &qnHFx_EP); tree->SetBranchAddress("qnHFy_EP", &qnHFy_EP); tree->SetBranchAddress("sumET_EP", &sumET_EP); //-- Get the QN Detector histograms fQNDet = new TFile( Form("../../../../../../v%i/eta2.4/systematicStudies/vtxCut/vtx3_15/AnalyzerResults/Q%iDet.root", QnBinOrder_, QnBinOrder_) ); for(int iEP = 0; iEP < NumEPNames; iEP++){ int EPbin = EPSymmPartnerBin[iEP]; if( EPbin != EPSymmBin ) continue; hqnHFDet_x[iEP] = (TH1D*) fQNDet->Get( Form("hqnHFDet_x_%s", EPNames[iEP].data()) ); hqnHFDet_y[iEP] = (TH1D*) fQNDet->Get( Form("hqnHFDet_y_%s", EPNames[iEP].data()) ); } //-- Setup the QN binning objects fQN = new TFile( Form( "../../../../../../v%i/eta2.4/systematicStudies/vtxCut/vtx3_15/AnalyzerResults/q%iCuts.root", QnBinOrder_, QnBinOrder_) ); for(int icent = 0; icent < NCENT; icent++){ for(int iEP = 0; iEP < NEPSymm; iEP++){ if( iEP != EPSymmBin ) continue; hqbins[icent][iEP] = (TH1D*) fQN->Get( Form("hqbins_%s_c%i", EPSymmNames[iEP].data(), icent) ); } } //-- Setup the output objects fOut = new TFile( Form("V%iDet.root", norder_), "recreate" ); SubEvt_0 = fOut->mkdir("SubEvt_0"); SubEvt_1 = fOut->mkdir("SubEvt_1"); FullEvt = fOut->mkdir("FullEvt"); for(int iqn = 0; iqn < NQN; iqn++){ SubEvt_0->cd(); hVNDetX_0[iqn] = new TH2D( Form("hVNDetX_0_qbin%i", iqn), Form("hVNDetX_0_qbin%i", iqn), NCENT, centbinsDefault, NEPSymm, epbinsDefault ); hVNDetX_0[iqn]->GetXaxis()->SetTitle("Centrality %"); hVNDetX_0[iqn]->SetOption("colz"); hVNDetY_0[iqn] = new TH2D( Form("hVNDetY_0_qbin%i", iqn), Form("hVNDetY_0_qbin%i", iqn), NCENT, centbinsDefault, NEPSymm, epbinsDefault ); hVNDetY_0[iqn]->GetXaxis()->SetTitle("Centrality %"); hVNDetY_0[iqn]->SetOption("colz"); SubEvt_1->cd(); hVNDetX_1[iqn] = new TH2D( Form("hVNDetX_1_qbin%i", iqn), Form("hVNDetX_1_qbin%i", iqn), NCENT, centbinsDefault, NEPSymm, epbinsDefault ); hVNDetX_1[iqn]->GetXaxis()->SetTitle("Centrality %"); hVNDetX_1[iqn]->SetOption("colz"); hVNDetY_1[iqn] = new TH2D( Form("hVNDetY_1_qbin%i", iqn), Form("hVNDetY_1_qbin%i", iqn), NCENT, centbinsDefault, NEPSymm, epbinsDefault ); hVNDetY_1[iqn]->GetXaxis()->SetTitle("Centrality %"); hVNDetY_1[iqn]->SetOption("colz"); FullEvt->cd(); hVNDetX_full[iqn] = new TH2D( Form("hVNDetX_full_qbin%i", iqn), Form("hVNDetX_full_qbin%i", iqn), NCENT, centbinsDefault, NEPSymm, epbinsDefault ); hVNDetX_full[iqn]->GetXaxis()->SetTitle("Centrality %"); hVNDetX_full[iqn]->SetOption("colz"); hVNDetY_full[iqn] = new TH2D( Form("hVNDetY_full_qbin%i", iqn), Form("hVNDetY_full_qbin%i", iqn), NCENT, centbinsDefault, NEPSymm, epbinsDefault ); hVNDetY_full[iqn]->GetXaxis()->SetTitle("Centrality %"); hVNDetY_full[iqn]->SetOption("colz"); for(int iEP = 0; iEP < NEPSymm; iEP++){ hVNDetX_0[iqn]->GetYaxis()->SetBinLabel(iEP+1, EPSymmNames[iEP].data()); hVNDetY_0[iqn]->GetYaxis()->SetBinLabel(iEP+1, EPSymmNames[iEP].data()); hVNDetX_1[iqn]->GetYaxis()->SetBinLabel(iEP+1, EPSymmNames[iEP].data()); hVNDetY_1[iqn]->GetYaxis()->SetBinLabel(iEP+1, EPSymmNames[iEP].data()); hVNDetX_full[iqn]->GetYaxis()->SetBinLabel(iEP+1, EPSymmNames[iEP].data()); hVNDetY_full[iqn]->GetYaxis()->SetBinLabel(iEP+1, EPSymmNames[iEP].data()); } } //-- initialize all variables for(int icent = 0; icent<NCENT; icent++){ for(int iEP = 0; iEP < NEPSymm; iEP++){ if( iEP != EPSymmBin ) continue; for(int iqn = 0; iqn < NQN; iqn++){ VNDetX_0[icent][iEP][iqn] = 0.; VNDetY_0[icent][iEP][iqn] = 0.; VNDetX_1[icent][iEP][iqn] = 0.; VNDetY_1[icent][iEP][iqn] = 0.; VNDetX_full[icent][iEP][iqn] = 0.; VNDetY_full[icent][iEP][iqn] = 0.; evtMult_0[icent][iEP][iqn] = 0; evtMult_1[icent][iEP][iqn] = 0; evtMult_full[icent][iEP][iqn] = 0; Nevents[icent][iEP][iqn] = 0; NFails[icent][iEP][iqn] = 0; } } } // // Calculate Vn_det // cout<<"Begin DETECTOR loop, contains "<<tree->GetEntries()<<" Events"<<endl; int N; if(testrun) N = 10000; else N = tree->GetEntries(); //-- Begin event loop for(int ievent = 0; ievent < N; ievent++) { if((ievent+1)% 500000 == 0) cout << "Processing Event " << ievent+1 << "\t" << (100.*(ievent+1)/N) << "% Completed" << endl; tree->GetEntry(ievent); //-- Vertex Cut if(TMath::Abs(vtx) < 3. || TMath::Abs(vtx) > 15.) continue; //-- Calculate centbin if( centval > cent_max[NCENT-1]) continue; int icent = hCentBins.FindBin(centval)-1; //-- begin EP loop for(int iEP = 0; iEP < NEP; iEP++){ int EPbin = EPSymmPartnerBin[iEP]; if( EPbin != EPSymmBin ) continue; //-- Calculate qbin double qx = qnHFx_EP[iEP]; double qy = qnHFy_EP[iEP]; double qxDet = hqnHFDet_x[iEP]->GetBinContent(icent+1); double qyDet = hqnHFDet_y[iEP]->GetBinContent(icent+1); double sumET = sumET_EP[iEP]; if(sumET == 0) continue; qx -= qxDet; qy -= qyDet; qx /= sumET; qy /= sumET; double qn = TMath::Sqrt( qx*qx + qy*qy ); int iqn = hqbins[icent][EPbin]->FindBin( qn ) - 1; if(iqn >= NQN) continue; //-- Reset Raw and sumw values VNRawX_0[icent][EPbin][iqn] = 0.; VNRawY_0[icent][EPbin][iqn] = 0.; VNRawX_1[icent][EPbin][iqn] = 0.; VNRawY_1[icent][EPbin][iqn] = 0.; VNRawX_full[icent][EPbin][iqn] = 0.; VNRawY_full[icent][EPbin][iqn] = 0.; sumw_0[icent][EPbin][iqn] = 0.; sumw_1[icent][EPbin][iqn] = 0.; sumw_full[icent][EPbin][iqn] = 0.; evtMult_0[icent][EPbin][iqn] = 0; evtMult_1[icent][EPbin][iqn] = 0; evtMult_full[icent][EPbin][iqn] = 0; Nevents[icent][EPbin][iqn]++; //-- Begin analyzer histogram loops for(int ipt = ptBinMin; ipt <= ptBinMax; ipt++){ for(int ieta = etaBinMin; ieta <= etaBinMax; ieta++){ if(sumw->GetBinContent(ipt+1,ieta+1) !=0){ //-- Subevent 0 (eta >= 0) if(etabinsDefault[ieta] >= 0){ VNRawX_0[icent][EPbin][iqn] += sumwqx->GetBinContent(ipt+1,ieta+1); VNRawY_0[icent][EPbin][iqn] += sumwqy->GetBinContent(ipt+1,ieta+1); sumw_0[icent][EPbin][iqn] += sumw->GetBinContent(ipt+1,ieta+1); evtMult_0[icent][EPbin][iqn] += hMult->GetBinContent(ipt+1,ieta+1); } //-- Subevent 1 (eta < 0) else{ VNRawX_1[icent][EPbin][iqn] += sumwqx->GetBinContent(ipt+1,ieta+1); VNRawY_1[icent][EPbin][iqn] += sumwqy->GetBinContent(ipt+1,ieta+1); sumw_1[icent][EPbin][iqn] += sumw->GetBinContent(ipt+1,ieta+1); evtMult_1[icent][EPbin][iqn] += hMult->GetBinContent(ipt+1,ieta+1); } //-- Full Event VNRawX_full[icent][EPbin][iqn] += sumwqx->GetBinContent(ipt+1,ieta+1); VNRawY_full[icent][EPbin][iqn] += sumwqy->GetBinContent(ipt+1,ieta+1); sumw_full[icent][EPbin][iqn] += sumw->GetBinContent(ipt+1,ieta+1); evtMult_full[icent][EPbin][iqn] += hMult->GetBinContent(ipt+1,ieta+1); } } //-- End eta loop } //-- End pt loop //-- Only use events that have tracks in all subevents AND subevents that have at least two tracks to determine VN if( sumw_0[icent][EPbin][iqn] == 0 || sumw_1[icent][EPbin][iqn] == 0 || evtMult_0[icent][EPbin][iqn] < 2 || evtMult_1[icent][EPbin][iqn] < 2 ){ NFails[icent][EPbin][iqn]++; } else{ VNDetX_0[icent][EPbin][iqn] += VNRawX_0[icent][EPbin][iqn] / sumw_0[icent][EPbin][iqn]; VNDetY_0[icent][EPbin][iqn] += VNRawY_0[icent][EPbin][iqn] / sumw_0[icent][EPbin][iqn]; VNDetX_1[icent][EPbin][iqn] += VNRawX_1[icent][EPbin][iqn] / sumw_1[icent][EPbin][iqn]; VNDetY_1[icent][EPbin][iqn] += VNRawY_1[icent][EPbin][iqn] / sumw_1[icent][EPbin][iqn]; VNDetX_full[icent][EPbin][iqn] += VNRawX_full[icent][EPbin][iqn] / sumw_full[icent][EPbin][iqn]; VNDetY_full[icent][EPbin][iqn] += VNRawY_full[icent][EPbin][iqn] / sumw_full[icent][EPbin][iqn]; } } //-- End EP loop } //-- End event loop std::cout<<"End DETECTOR loop"<<std::endl; //-- Average VNDet over all events for each centrality, EP and, qn bin for(int iqn = 0; iqn < NQN; iqn++){ for(int icent = 0; icent < NCENT; icent++){ for(int iEP = 0; iEP < NEPSymm; iEP++){ if( iEP != EPSymmBin ) continue; double Neffective = (double) Nevents[icent][iEP][iqn] - (double) NFails[icent][iEP][iqn]; if( Neffective == 0) continue; VNDetX_0[icent][iEP][iqn] /= Neffective; VNDetY_0[icent][iEP][iqn] /= Neffective; VNDetX_1[icent][iEP][iqn] /= Neffective; VNDetY_1[icent][iEP][iqn] /= Neffective; VNDetX_full[icent][iEP][iqn] /= Neffective; VNDetY_full[icent][iEP][iqn] /= Neffective; //-- Populate histograms that will be used by ReadTree_normDet.C hVNDetX_0[iqn] -> SetBinContent(icent+1, iEP+1, VNDetX_0[icent][iEP][iqn]); hVNDetX_1[iqn] -> SetBinContent(icent+1, iEP+1, VNDetX_1[icent][iEP][iqn]); hVNDetX_full[iqn] -> SetBinContent(icent+1, iEP+1, VNDetX_full[icent][iEP][iqn]); hVNDetY_0[iqn] -> SetBinContent(icent+1, iEP+1, VNDetY_0[icent][iEP][iqn]); hVNDetY_1[iqn] -> SetBinContent(icent+1, iEP+1, VNDetY_1[icent][iEP][iqn]); hVNDetY_full[iqn] -> SetBinContent(icent+1, iEP+1, VNDetY_full[icent][iEP][iqn]); } } } //-- END TRIPLE LOOP fOut->Write(); cout<<"File written, process completed"<<endl; }
void acceptance(string input_filename) { gROOT->Reset(); gStyle->SetPalette(1); gStyle->SetOptStat(0); const double DEG=180./3.1415926; char output_filename[80]; sprintf(output_filename, "%s_output.root",input_filename.substr(0,input_filename.find(".")).c_str()); TFile *outputfile=new TFile(output_filename, "recreate"); const int n=2; TH1F *hgen_mom,*hgen_theta; TH2F *hgen; char hstname[100]; sprintf(hstname,"gen_mom"); hgen_mom=new TH1F(hstname,hstname,110,0,11); sprintf(hstname,"gen_theta"); hgen_theta=new TH1F(hstname,hstname,250,0,50); sprintf(hstname,"gen"); TH2F *hacceptance_forwardangle,*hacceptance_largeangle,*hacceptance_overall; TH1F *hacceptance_mom[n],*hacceptance_theta[n]; TH2F *hacceptance[n]; TH2F *hhit_rz[n],*hhit_xy[n]; hgen=new TH2F(hstname,hstname,250,0,50,110,0,11); for(int i=0;i<n;i++){ sprintf(hstname,"acceptance_mom_%i",i); hacceptance_mom[i]=new TH1F(hstname,hstname,110,0,11); sprintf(hstname,"acceptance_theta_%i",i); hacceptance_theta[i]=new TH1F(hstname,hstname,250,0,50); sprintf(hstname,"acceptance_%i",i); hacceptance[i]=new TH2F(hstname,hstname,250,0,50,110,0,11); sprintf(hstname,"hit_rz_%i",i); hhit_rz[i]=new TH2F(hstname,hstname,1200,-600,600,500,0,500); sprintf(hstname,"hit_xy_%i",i); hhit_xy[i]=new TH2F(hstname,hstname,500,0,500,500,0,500); } TFile *file=new TFile(input_filename.c_str()); if (file->IsZombie()) { cout << "Error opening file" << input_filename << endl; continue; // exit(-1); } else cout << "open file " << input_filename << endl; TTree *Tgen = (TTree*) file->Get("genT"); Int_t gen_evn,gen_ngen; Int_t gen_id_array[1000]; Int_t *gen_id=gen_id_array; Float_t gen_px_array[1000],gen_py_array[1000],gen_pz_array[1000],gen_p_array[1000],gen_phi_array[1000],gen_theta_array[1000],gen_vx_array[1000],gen_vy_array[1000],gen_vz_array[1000]; Float_t *gen_px=gen_px_array,*gen_py=gen_py_array,*gen_pz=gen_pz_array,*gen_p=gen_p_array,*gen_phi=gen_phi_array,*gen_theta=gen_theta_array,*gen_vx=gen_vx_array,*gen_vy=gen_vy_array,*gen_vz=gen_vz_array; Tgen->SetBranchAddress("evn",&gen_evn); Tgen->SetBranchAddress("ngen",&gen_ngen); Tgen->SetBranchAddress("id",gen_id); Tgen->SetBranchAddress("px",gen_px); Tgen->SetBranchAddress("py",gen_py); Tgen->SetBranchAddress("pz",gen_pz); Tgen->SetBranchAddress("p",gen_p); Tgen->SetBranchAddress("phi",gen_phi); Tgen->SetBranchAddress("theta",gen_theta); Tgen->SetBranchAddress("vx",gen_vx); Tgen->SetBranchAddress("vy",gen_vy); Tgen->SetBranchAddress("vz",gen_vz); TTree *Tflux = (TTree*) file->Get("fluxT"); Int_t flux_evn,flux_nfluxhit; Int_t flux_ID_array[1000],*flux_pid_array[1000],*flux_mpid_array[1000]; Int_t *flux_ID=flux_ID_array,*flux_pid=flux_pid_array,*flux_mpid=flux_mpid_array; Float_t flux_Edep_array[1000],flux_E_array[1000],flux_x_array[1000],flux_y_array[1000],flux_z_array[1000],flux_lx_array[1000],flux_ly_array[1000],flux_lz_array[1000],flux_t_array[1000],flux_px_array[1000],flux_py_array[1000],flux_pz_array[1000],flux_vx_array[1000],flux_vy_array[1000],flux_vz_array[1000],flux_mvx_array[1000],flux_mvy_array[1000],flux_mvz_array[1000]; Float_t *flux_Edep=flux_Edep_array,*flux_E=flux_E_array,*flux_x=flux_x_array,*flux_y=flux_y_array,*flux_z=flux_z_array,*flux_lx=flux_lx_array,*flux_ly=flux_ly_array,*flux_lz=flux_lz_array,*flux_t=flux_t_array,*flux_px=flux_px_array,*flux_py=flux_py_array,*flux_pz=flux_pz_array,*flux_vx=flux_vx_array,*flux_vy=flux_vy_array,*flux_vz=flux_vz_array,*flux_mvx=flux_mvx_array,*flux_mvy=flux_mvy_array,*flux_mvz=flux_mvz_array; Tflux->SetBranchAddress("evn",&flux_evn); Tflux->SetBranchAddress("nfluxhit",&flux_nfluxhit); Tflux->SetBranchAddress("ID",flux_ID); Tflux->SetBranchAddress("Edep",flux_Edep); Tflux->SetBranchAddress("E",flux_E); Tflux->SetBranchAddress("x",flux_x); Tflux->SetBranchAddress("y",flux_y); Tflux->SetBranchAddress("z",flux_z); Tflux->SetBranchAddress("lx",flux_lx); Tflux->SetBranchAddress("ly",flux_ly); Tflux->SetBranchAddress("lz",flux_lz); Tflux->SetBranchAddress("t",flux_t); Tflux->SetBranchAddress("pid",flux_pid); Tflux->SetBranchAddress("mpid",flux_mpid); Tflux->SetBranchAddress("px",flux_px); Tflux->SetBranchAddress("py",flux_py); Tflux->SetBranchAddress("pz",flux_pz); Tflux->SetBranchAddress("vx",flux_vx); Tflux->SetBranchAddress("vy",flux_vy); Tflux->SetBranchAddress("vz",flux_vz); Tflux->SetBranchAddress("mvx",flux_mvx); Tflux->SetBranchAddress("mvy",flux_mvy); Tflux->SetBranchAddress("mvz",flux_mvz); // Int_t nevent = (Int_t)Tgen->GetEntries(); Int_t nevent = (Int_t)Tflux->GetEntries(); Int_t nselected = 0; cout << nevent << endl; ///radius cut standard as particles can travel 30cm in Z before leave calorimeter ///SIDIS largeangle EC outerradius is at 140cm double rout_cut=1000,rin_cut=0; if (input_filename.find("PVDIS",0) != string::npos){ //not used yet // rout_cut = 237; //target at 10,ec front at 320 with angle 37.4 // rin_cut = 0; //as the detector edge // cout << " PVDIS rcut " << rin_cut << " " << rout_cut << endl; } else if (input_filename.find("SIDIS_3he",0) != string::npos){ // only applys to LAEC rout_cut=126.3; //target at -350,ec front at -65 with angle 23.9 rin_cut=80; //cut at the actual edge cout << " SIDIS_3he rcut " << rin_cut << " " << rout_cut << endl; } else if (input_filename.find("SIDIS_proton",0) != string::npos){ // only applys to LAEC rout_cut=126.3; //target at -350,ec front at -65 with angle 23.9 rin_cut=80; //cut at the actual edge cout << " SIDIS_proton rcut " << rin_cut << " " << rout_cut << endl; } else if (input_filename.find("JPsi",0) != string::npos){ // only applys to LAEC // rout_cut=127.1; //target at -360,ec front at -65 with angle 23.3 // rout_cut=126.3; //target at -350,ec front at -65 with angle 23.9 // rout_cut=125.9; //target at -340,ec front at -65 with angle 24.6 // rout_cut=125.3; //target at -330,ec front at -65 with angle 25.3 // rout_cut=124.9; //target at -320,ec front at -65 with angle 26.1 // rout_cut=124.3; //target at -310,ec front at -65 with angle 26.9 // rout_cut=124.0; //target at -305,ec front at -65 with angle 27.3 rout_cut=123.9; //target at -300,ec front at -65 with angle 27.8 // rout_cut=123.8; //target at -295,ec front at -65 with angle 28.3 // rout_cut=123.2; //target at -290,ec front at -65 with angle 28.7 // rout_cut=122.6; //target at -280,ec front at -65 with angle 29.7 // rout_cut=121.7; //target at -270,ec front at -65 with angle 30.7 // rout_cut=120.1; //target at -250,ec front at -65 with angle 33.0 rin_cut=80; //cut at the actual edge cout << " JPsi rcut " << rin_cut << " " << rout_cut << endl; } else {cout << "not PVDIS or SIDIS or JPsi " << endl; return;} for (Int_t i=0;i<nevent;i++) { double theta=0,mom=0; Tgen->GetEntry(i); for (Int_t j=0;j<gen_ngen;j++) { // cout << gen_evn << " " << gen_ngen << " " << *(gen_id+j) << " " << *(gen_px+j) << " " << *(gen_py+j) << " " << *(gen_pz+j) << " " << *(gen_p+j) <<endl; theta=*(gen_theta+j); mom=*(gen_p+j)/1e3; hgen_mom->Fill(mom); hgen_theta->Fill(theta); hgen->Fill(theta,mom); } // int counter[n]={0,0,0,0,0,0,0,0,0,0}; Tflux->GetEntry(i); for (Int_t j=0;j<flux_nfluxhit;j++) { // cout << flux_evn<< " " << flux_nfluxhit << " " << *(flux_ID+j) << " " << *(flux_pid+j) << " " << *(flux_mpid+j) << " " << *(flux_Edep+j) << " " << *(flux_E+j) << " " << *(flux_x+j) << " " << *(flux_y+j) << " " << *(flux_z+j) << " " << *(flux_vx+j) << " " << *(flux_vy+j) << " " << *(flux_vz+j) << " " << *(flux_px+j) << " " << *(flux_py+j) << " " << *(flux_pz+j) << endl; int detector_ID=*(flux_ID+j)/1000000; int subdetector_ID=(*(flux_ID+j)%1000000)/100000; int subsubdetector_ID=((*(flux_ID+j)%1000000)%100000)/10000; // cout << Detector_ID << " " << SubDetector_ID << " " << channel_ID << endl; int hit_id=-1; switch (detector_ID){ case 3: switch (subdetector_ID){ case 1: switch (subsubdetector_ID){ case 1: hit_id=0; break; default: break; } break; case 2: switch (subsubdetector_ID){ case 1: hit_id=1; break; default: break; } break; default: break; } break; default: break; } if (hit_id==-1) continue; //skip other subsubdetector // double theta=atan((sqrt((*(flux_x+j))**2+(*(flux_y+j))**2)/(*(flux_z+j)-*gen_vz)))*DEG; double r=sqrt(*(flux_x+j)**2+*(flux_y+j)**2); hhit_rz[hit_id]->Fill(*(flux_z+j)/10,r/10); hhit_xy[hit_id]->Fill(*(flux_x+j)/10,*(flux_y+j)/10); if ((detector_ID==3 && subdetector_ID==2) && (r/10 < rin_cut || rout_cut < r/10)) continue; //r cut only applys to LAEC hacceptance_mom[hit_id]->Fill(mom); hacceptance_theta[hit_id]->Fill(theta); hacceptance[hit_id]->Fill(theta,mom); // if (hit_id==7 && theta >17) cout << *(flux_vz+j)/10 << " " << r/10 << " " << theta << " " << mom << endl; // cout << *(flux_vz+j)/10 << " " << r << endl; // counter[hit_id]++; } // for(int k=0;k<n;k++){ // if (counter[hit_id] > 1) cout << counter[hit_id] << " " << hit_id << endl; // counter[hit_id]=0; // } } file->Close(); for(int i=0;i<n;i++){ hacceptance[i]->Divide(hgen); hacceptance_mom[i]->Divide(hgen_mom); hacceptance_theta[i]->Divide(hgen_theta); } TCanvas *c_gen = new TCanvas("gen","gen",600,600); hgen->Draw("colz"); TCanvas *c_hit_rz = new TCanvas("hit_rz","hit_rz",1800,800); c_hit_rz->Divide(2,1); for(int k=0;k<n;k++){ c_hit_rz->cd(k+1); gPad->SetLogz(1); hhit_rz[k]->Draw("colz"); } TCanvas *c_hit_xy = new TCanvas("hit_xy","hit_xy",1800,800); c_hit_xy->Divide(2,1); for(int k=0;k<n;k++){ c_hit_xy->cd(k+1); gPad->SetLogz(1); hhit_xy[k]->Draw("colz"); } // TCanvas *c_acceptance_gem = new TCanvas("acceptance_gem","acceptance_gem",1800,800); // c_acceptance_gem->Divide(2,3); // for(int k=0;k<6;k++){ // c_acceptance_gem->cd(k+1); // hacceptance[k]->Draw("colz"); // char hsttitle[80]; // sprintf(hsttitle,"acceptance at GEM plane %i;theta (degree);P (GeV)",k+1); // hacceptance[k]->SetTitle(hsttitle); // } // c_acceptance_gem->SaveAs("acceptance_gem.png"); // TCanvas *c_acceptance_gem_1D = new TCanvas("acceptance_gem_1D","acceptance_gem_1D",1800,800); // c_acceptance_gem_1D->Divide(2,6); // for(int k=0;k<6;k++){ // c_acceptance_gem_1D->cd(k+1); // hacceptance_mom[k]->Draw(); // c_acceptance_gem_1D->cd(6+k+1); // hacceptance_theta[k]->Draw(); // } hacceptance_forwardangle=(TH2F*) hacceptance[0]->Clone("acceptance_forwardangle"); hacceptance_largeangle=(TH2F*) hacceptance[1]->Clone("acceptance_largeangle"); hacceptance_overall=(TH2F*) hacceptance_largeangle->Clone(); hacceptance_overall->Add(hacceptance_forwardangle); TCanvas *c_acceptance = new TCanvas("acceptance","acceptance",500,900); c_acceptance->Divide(1,3); c_acceptance->cd(1); gPad->SetLogy(1); hacceptance_forwardangle->SetNameTitle("acceptance_forwardangle","acceptance at forwardangle;theta (degree);P (GeV)"); hacceptance_forwardangle->Draw("colz"); c_acceptance->cd(2); gPad->SetLogy(1); hacceptance_largeangle->SetNameTitle("acceptance_largeangle","acceptance at largeangle;theta (degree);P (GeV)"); hacceptance_largeangle->Draw("colz"); c_acceptance->cd(3); gPad->SetLogy(1); hacceptance_overall->SetNameTitle("acceptance","acceptance;theta (degree);P (GeV)"); hacceptance_overall->Draw("colz"); c_acceptance->SaveAs("acceptance.png"); hacceptance_forwardangle->SetDirectory(outputfile); hacceptance_largeangle->SetDirectory(outputfile); outputfile->Write(); outputfile->Flush(); }
void run(std::string inputFile, int max_iterations, int entries_per_kernel = 100) { TFile *file2 = new TFile(inputFile.c_str()); std::vector<double>* samples = new std::vector<double>; double amplitudeTruth; TTree *tree = (TTree*)file2->Get("Samples"); tree->SetBranchAddress("amplitudeTruth", &litudeTruth); tree->SetBranchAddress("samples", &samples); int nentries = tree->GetEntries(); float time_shift = 13. ; //---- default is 13 float pedestal_shift = 0.; float return_chi2 = -99; float best_pedestal = 0; float best_chi2 = 0; std::vector<TH1F*> v_pulses; std::vector<TH1F*> v_amplitudes_reco; fout->cd(); TTree* newtree = (TTree*) tree->CloneTree(0); //("RecoAndSim"); newtree->SetName("RecoAndSim"); std::vector <double> samplesReco; std::vector < std::vector<double> > complete_samplesReco; std::vector <double> complete_chi2; std::vector <double> complete_pedestal; int ipulseintime = 0; newtree->Branch("chi2", &return_chi2, "chi2/F"); newtree->Branch("samplesReco", &samplesReco); newtree->Branch("ipulseintime", ipulseintime, "ipulseintime/I"); newtree->Branch("complete_samplesReco", &complete_samplesReco); newtree->Branch("complete_chi2", &complete_chi2); newtree->Branch("complete_pedestal", &complete_pedestal); newtree->Branch("best_pedestal", &best_pedestal, "best_pedestal/F"); newtree->Branch("best_chi2", &best_chi2, "best_chi2/F"); int totalNumberOfBxActive = 10; for (unsigned int ibx=0; ibx<totalNumberOfBxActive; ++ibx) { samplesReco.push_back(0.); } v_amplitudes_reco.clear(); struct Args { SampleVector samples; SampleMatrix samplecor; double pederr; BXVector bxs; FullSampleVector fullpulse; FullSampleMatrix fullpulsecov; Args(SampleVector const& samples, SampleMatrix const& samplecor, double pederr, BXVector const& bxs, FullSampleVector fullpulse, FullSampleMatrix fullpulsecov) : samples(samples), samplecor(samplecor), pederr(pederr), bxs(bxs), fullpulse(fullpulse), fullpulsecov(fullpulsecov) {} }; struct Output { double chi2; double ampl; int status; Output(double chi2, double ampl, int status) : chi2{chi2}, ampl{ampl}, status{status} {} }; std::cout << "max_iterations: " << max_iterations << std::endl << "entries_per_kernel: " << entries_per_kernel << std::endl; for (auto it=0; it<max_iterations; ++it) { // vector of input parameters to the kernel std::vector<Args> vargs; for (int ie=0; ie<entries_per_kernel; ++ie) { tree->GetEntry(ie % tree->GetEntries()); for (int i=0; i<NSAMPLES; ++i) amplitudes[i] = samples->at(i); double pedval = 0.; double pedrms = 1.0; vargs.emplace_back(amplitudes, noisecor, pedrms, activeBX, fullpulse, fullpulsecov); } auto kernel = [](std::vector<Args> const& vargs) -> std::vector<Output> { std::vector<Output> vresults; for (auto& args : vargs) { PulseChiSqSNNLS func; func.disableErrorCalculation(); auto status = func.DoFit(args.samples, args.samplecor, args.pederr, args.bxs, args.fullpulse, args.fullpulsecov); double chi2 = func.ChiSq(); unsigned int ip_in_time = 0; for (unsigned int ip=0; ip<func.BXs().rows(); ++ip) { if (func.BXs().coeff(ip) == 0) { ip_in_time = ip; break; } } double ampl = status ? func.X()[ip_in_time] : 0.; vresults.emplace_back(chi2, ampl, status); } return vresults; }; std::cout << "iteration: " << it << " wrapper start with vargs.size() = " << vargs.size() << std::endl; auto start_time = std::chrono::high_resolution_clock::now(); auto vresults = kernel(vargs); auto end_time = std::chrono::high_resolution_clock::now(); std::cout << "wrapper end with vresults.size() " << vresults.size() << std::endl; auto duration = std::chrono::duration_cast<std::chrono::milliseconds>( end_time - start_time).count(); hDuration->Fill(duration); std::cout << "duration = " << duration << std::endl; for (auto& results : vresults) { h01->Fill(results.ampl - amplitudeTruth); } } fout->cd(); newtree->Write(); std::cout << " Mean of REC-MC = " << h01->GetMean() << " GeV" << std::endl; std::cout << " RMS of REC-MC = " << h01->GetRMS() << " GeV" << std::endl; std::cout << " Entries Total = " << h01->GetEntries() << std::endl; std::cout << " Mean Duration = " << hDuration->GetMean() << std::endl; }
int main(int argc, char *argv[]) { ApplyLHCbStyle(); double maxrate; switch(argc) { case 2: maxrate=-1; break; case 3: if(atoi(argv[2])) maxrate=atoi(argv[2]); else { cout << "Argument not a number" << endl; return 1; } break; default: cout << "Usage: " << argv[0] << " <Filename> [<Max rate>]" << endl; return 1; } if(system("[ -a figs ]") != 0) { cout << "Directory ./figs/ does not exist" << endl; const int mkdirerr = system("mkdir figs"); if(mkdirerr != 0) { cout << "Error code " << mkdirerr << " while creating ./figs/" << endl; } else { cout << "Directory ./figs/ created" << endl; } } TFile* file = new TFile(argv[1]); if(!file->IsOpen()) { cout << "Exiting" << endl; return 1; } TTree* tree = (TTree*)file->Get("metatree"); int iHV; tree->SetBranchAddress("HV", &iHV); vector<int> HVs; string HV; int n = tree->GetEntries(); TCanvas* mapscan, * histcan, * graphcan, * indivgraphcan[4]; TPad* mapspad[4], * histpad[4]; TH1D* hist; TH2D* map; string title[4] = {"JB", "JT", "ST", "SB"}; // string title[4] = {"FA0026", "DA0024", "FA0019", "FA0006"}; TGraphErrors* graph[4]; TMultiGraph* mg; TLegend* lg; float xlo, xhi, ylo, yhi; // rainbowgradient(); heatmapgradient(); // DarkBodyRadiator(); // DarkBodyRadiator2(); // redbluegradient(); // heatmapRB(); string plotname; stringstream plotnamestream; double* x[4], * y[4], * xe[4], * ye[4]; for(int j = 0; j < 4; j++) { x[j] = new double[n]; y[j] = new double[n]; xe[j] = new double[n]; ye[j] = new double[n]; } Double_t maxima[4]; cout << "Entering loop of " << n << " events." << endl; for(int i = 0; i < n; i++) { tree->GetEntry(i); HVs.push_back(iHV); HV = itoa(iHV); for(int j = 0; j < 4; j++) { map = (TH2D*)file->Get(("DarkMap"+HV+"V"+itoa(j)).c_str()); maxima[j] = map->GetMaximum(); } } sort(HVs.begin(), HVs.end()); if(maxrate==-1) { for(int i = 1; i < 4; i++) { maxrate = TMath::Max(maxima[i-1], maxima[i]); maxima[i]=maxrate; } } // cout << "Plotting with a maximum rate of " << maxrate << endl; for(int i = 0; i < n; i++) { HV = itoa(HVs[i]); plotnamestream << "DarkRate" << setfill('0') << setw(4) << HVs[i]; plotnamestream >> plotname; histcan = new TCanvas(plotname.c_str(), "", 800, 800); plotnamestream.clear(); histcan->Draw(); plotnamestream << "DarkMap" << setfill('0') << setw(4) << HVs[i]; plotnamestream >> plotname; mapscan = new TCanvas(plotname.c_str(), "", 800, 800); plotnamestream.clear(); mapscan->Draw(); for(int j = 0; j < 4; j++) { // Set limits xlo = 0.5*((j/2)%2); xhi = xlo+0.5; ylo = 0.5*((j+((j/2)%2))%2); yhi = ylo+0.5; // 2D maps mapscan->cd(); mapspad[j] = new TPad("", "", xlo, ylo, xhi, yhi); mapspad[j]->SetLeftMargin( 0.05); mapspad[j]->SetRightMargin( 0.15); mapspad[j]->SetTopMargin( 0.05); mapspad[j]->SetBottomMargin(0.05); mapspad[j]->Draw(); mapspad[j]->cd(); map = (TH2D*)file->Get(("DarkMap"+HV+"V"+itoa(j)).c_str()); map->SetTitle(""); map->SetMaximum(maxrate); map->SetMinimum(0); map->Draw("COLZ"); // 1D histogram histcan->cd(); histpad[j] = new TPad("", "", xlo, ylo, xhi, yhi); histpad[j]->SetLeftMargin( 0.05); histpad[j]->SetRightMargin( 0.15); histpad[j]->SetTopMargin( 0.05); histpad[j]->SetBottomMargin(0.05); histpad[j]->Draw(); histpad[j]->SetLogy(); histpad[j]->cd(); hist = new TH1D(("hist"+itoa(i)+itoa(j)).c_str(), title[j].c_str(), 100, 0, maxrate); tree->Draw(("rate"+itoa(j)+">>"+hist->GetName()).c_str(), "", "", 1, i); // Graph x[j][i] = HVs[i]; xe[j][i] = 0; y[j][i] = 0; ye[j][i] = 0; double yval = 0, yerr = 0; double npix = 0; for(int k = 0; k < 64; k++) { yval = map->GetBinContent((k/8)+1, (k%8)+1); yerr = map->GetBinError((k/8)+1, (k%8)+1); if(yval<0) continue; y[j][i] += yval; ye[j][i] += yerr*yerr; npix++; } y[j][i] /= npix; ye[j][i] = sqrt(ye[j][i])/npix; cout << npix << "\t" << y[j][i] << "±" << ye[j][i] << endl; } gStyle->SetOptStat("m"); histcan->SaveAs(("./figs/"+(string)histcan->GetName()+".pdf").c_str()); histcan->SaveAs(("./figs/"+(string)histcan->GetName()+".png").c_str()); mapscan->SaveAs(("./figs/"+(string)mapscan->GetName()+".pdf").c_str()); mapscan->SaveAs(("./figs/"+(string)mapscan->GetName()+".png").c_str()); } mg = new TMultiGraph(); lg = new TLegend(0.17,0.6,0.45,0.82); lg->SetFillStyle(0); lg->SetLineWidth(0); int linecolour[4] = {kBlue,kRed+1,kGreen+1,kViolet}; int linestyle[4] = {2,9,3,5}; int index[4] = {1, 0, 2, 3}; // More sensible order for(int k = 0; k < 4; k++) { int j = index[k]; graph[j] = new TGraphErrors(n, x[j], y[j], xe[j], ye[j]); graph[j]->SetTitle(title[j].c_str()); graph[j]->SetLineWidth(2); indivgraphcan[j] = new TCanvas((title[j]+"graph").c_str(),"",1000,900); indivgraphcan[j]->Draw(); graph[j]->GetXaxis()->SetTitle("High Voltage [V]"); graph[j]->GetYaxis()->SetTitle("Dark count rate [Hz]"); graph[j]->GetYaxis()->SetTitleOffset(1.25); graph[j]->SetMinimum(0); graph[j]->Draw("APL"); indivgraphcan[j]->SaveAs(("./figs/graph"+title[j]+".pdf").c_str()); graph[j]->SetLineColor(linecolour[j]); graph[j]->Fit("pol1"); graph[j]->GetFunction("pol1")->SetLineColor(graph[j]->GetLineColor()); graph[j]->GetFunction("pol1")->SetLineStyle(linestyle[j]); lg->AddEntry(graph[j]->GetFunction("pol1"),title[j].c_str(),"L"); mg->Add(graph[j], "P"); } graphcan = new TCanvas("graph", "", 900, 900); graphcan->cd(); graphcan->Draw(); mg->SetMinimum(0); mg->Draw("APL"); mg->GetXaxis()->SetTitle("High Voltage [V]"); mg->GetYaxis()->SetTitle("Dark count rate [Hz]"); mg->GetXaxis()->SetTitleOffset(1.2); mg->GetYaxis()->SetTitleOffset(1.2); GetLHCbName()->Draw(); lg->Draw(); graphcan->SaveAs("figs/graph.pdf"); cout << "\\hline" << endl << "Voltage"; for(int j = 0; j < 4; j++) { cout << " & " << title[j]; } cout << "\\\\\\hline" << endl; for(int i = 0; i < n; i++) { cout << HVs[i]; for(int j = 0; j < 4; j++) { cout << setprecision(3) << " & " << y[j][i]; } cout << "\\\\\\hline" << endl; } return 0; }
//void Plot_Yield(){ int main(){ //Here are where you need to change //const TString Com = "DpTh40"; TString Target = "He3"; cerr<<"--- Target (H2,He3,He4,C12,Ca40 and Ca48) = "; cin >> Target; TString Kin = "Kin3.1"; cerr<<"--- Kin (e.g. 3.1) = "; cin >> Kin; Kin="Kin"+Kin; TString Arm = "L"; cerr<<"--- Arm (L or R) = "; cin >> Arm; TString Com = "J02"; cerr<<"--- Comment = "; cin >> Com; /*Read In RunNo{{{*/ TString sTarget="", sKin = ""; if(Target.Contains("H")){ sTarget = Target; sTarget.ReplaceAll("H","h"); } if(Target.Contains("C")){ sTarget = Target; sTarget.ReplaceAll("C","c"); } sKin=Kin; sKin.ReplaceAll("Kin","kin"); TString Input_Parameter = Form("%s/xs_input/%sHRS/xs_%s_%s.dat",XGT2_DIR.Data(),Arm.Data(),sTarget.Data(),sKin.Data()); ifstream input_par(Input_Parameter.Data()); TString one_line; int RunNo_Temp = gGet_InputFile_Var(Input_Parameter,0).Atoi(); vector<int> vRunNoChain = gGet_RunNoChain(RunNo_Temp, gGet_InputFile_Var(Input_Parameter,15)); const int N=vRunNoChain.size(); int RunNo[N]; for(int i=0;i<N;i++) RunNo[i] = vRunNoChain[i]; /*}}}*/ TString InputFileName = Form("%s/results/%s/%s/%s_%s_%s_Yield_%s.root", XGT2_DIR.Data(),Target.Data(),Com.Data(),Arm.Data(),Kin.Data(),Target.Data(),Com.Data()); cerr<<" &&& Reading in RootFile --> "<<InputFileName.Data()<<endl; double Ep,xbj; double Y_EX[N], Y_EX_Stat[N], Y_EX_Sys[N], Y_MC[N],Y_MC_Stat[N],Y_MC_Sys[N]; TFile *f1 = new TFile(InputFileName.Data(),"r"); if(f1->IsZombie()){ cerr<<"*** I cannot fine ROOTFile: "<<InputFileName.Data()<<" ***"<<endl; exit(-1); } TTree *T = (TTree*) gDirectory->Get("T"); const int N_Evt = T->GetEntries(); T->SetBranchAddress("Ep", &Ep); T->SetBranchAddress("xbj", &xbj); for(int i=0;i<N;i++){ T->SetBranchAddress(Form("Y_EX_%d", RunNo[i]), &Y_EX[i]); T->SetBranchAddress(Form("Y_EX_Stat_%d",RunNo[i]), &Y_EX_Stat[i]); T->SetBranchAddress(Form("Y_EX_Sys_%d" ,RunNo[i]), &Y_EX_Sys[i]); T->SetBranchAddress(Form("Y_MC_%d", RunNo[i]), &Y_MC[i]); T->SetBranchAddress(Form("Y_MC_Stat_%d",RunNo[i]), &Y_MC_Stat[i]); T->SetBranchAddress(Form("Y_MC_Sys_%d" ,RunNo[i]), &Y_MC_Sys[i]); } double Y_R[N][N_Evt], Y_R_Err[N][N_Evt]; double Ep_Bin[N_Evt],xbj_Bin[N_Evt]; double Ep_Max = -1000.0, Ep_Min = 1000.0, xbj_Max = -1000.0, xbj_Min = 1000.0, Y_EX_Err=0.0, Y_MC_Err = 0.0; for(int j=0;j<N_Evt;j++){ T->GetEntry(j); Ep_Bin[j] = Ep; if(Ep>Ep_Max) Ep_Max = Ep; if(Ep<Ep_Min) Ep_Min = Ep; xbj_Bin[j] = xbj; if(xbj>xbj_Max) xbj_Max = xbj; if(xbj<xbj_Min) xbj_Min = xbj; for(int i=0;i<N;i++){ //cerr<<Form("Run#%d: Ep = %f, Y_R = %e (%e)", RunNo[i],Ep_Bin[j], Y_EX[i],Y_EX_Stat[i])<<endl; Y_EX_Err = sqrt( pow(Y_EX_Stat[i],2)+pow(Y_EX_Sys[i],2) ); Y_MC_Err = sqrt( pow(Y_MC_Stat[i],2)+pow(Y_MC_Sys[i],2) ); if(Y_EX[i]>1e-30&&Y_MC[i]>1e-30){ Y_R[i][j] = Y_EX[i] / Y_MC[i]; Y_R_Err[i][j] = Y_R[i][j]*sqrt( pow(Y_EX_Err/Y_EX[i],2)+pow(Y_MC_Err/Y_MC[i],2) ); } else{ Y_R[i][j] = 0.0; Y_R_Err[i][j] = 0.0; } } } /*Yield Ratio{{{*/ double Y_Min =0, Y_Max = 2.0; if(N>10) Y_Min = -1.0; TCanvas *c3 = new TCanvas("c3","c3",1200,800); TH2F* r = new TH2F("r","",1000,xbj_Min-0.2,xbj_Max+0.2,1000,Y_Min, Y_Max); r->SetStats(kFALSE); r->SetXTitle("X"); r->GetXaxis()->CenterTitle(1); r->GetXaxis()->SetTitleFont(32); r->GetXaxis()->SetTitleSize(0.06); r->GetXaxis()->SetTitleOffset(0.7); r->SetYTitle("Yield_{EX}/Yield_{MC}"); r->GetYaxis()->CenterTitle(1); r->GetYaxis()->SetTitleFont(32); r->GetYaxis()->SetTitleSize(0.05); r->GetYaxis()->SetTitleOffset(0.7); r->Draw(); TGraphErrors *pl_r[N]; int N_Color = 1, N_Style = 20; for(int i=0;i<N;i++){ pl_r[i] = new TGraphErrors(N_Evt,&xbj_Bin[0],&Y_R[i][0],0,&Y_R_Err[i][0]); pl_r[i]-> SetMarkerSize(1.5); N_Color++; if (N_Color==5) N_Color++; if(N_Color>9&&N_Color<37) N_Color = 37; if(N_Color>49) N_Color = 1; pl_r[i]-> SetMarkerColor(N_Color); N_Style++; if(N_Style>30) N_Style = 2; if(N_Style>5&&N_Style<20) N_Style = 20; pl_r[i]-> SetMarkerStyle(N_Style); } TMultiGraph *mg3 = new TMultiGraph(); TLegend *l3 = new TLegend(0.35,0.17,0.60, 0.17+N*0.03,Form("%s Target",Target.Data())); l3->SetBorderSize(0); l3->SetTextSize(0.025); if(N>10) l3->SetTextSize(0.015); l3->SetTextFont(22); for(int i=0;i<N;i++){ l3->AddEntry(pl_r[i], Form(" %s (HRS-%s) #%d",Kin.Data(), Arm.Data(), RunNo[i]),"p"); mg3->Add(pl_r[i]); } mg3->Draw("P"); l3->Draw(); /*}}}*/ c3->Print(Form("%s_YR_%s_%s_%s.pdf",Target.Data(),Arm.Data(),Kin.Data(),Com.Data())); c3->Print(Form("%s_YR_%s_%s_%s.png",Target.Data(),Arm.Data(),Kin.Data(),Com.Data())); // f1->Close(); }
int main(int argc,char** argv){ int pserr = getargs(argc,argv); TString Target = gTarget; TString aKin = gKin; TString Kin = Form("Kin%s",aKin.Data()); TString Arm = gArm; TString Com = gCom; /* //Here are where you need to change*/ ////const TString Com = "DpTh40"; //TString Target = "He3"; cerr<<"--- Target (H2,He3,He4,C12,Ca40 and Ca48) = "; cin >> Target; //TString Kin = "Kin3.1"; cerr<<"--- Kin (e.g. 3.1) = "; cin >> Kin; Kin="Kin"+Kin; //TString Arm = "L"; cerr<<"--- Arm (L or R) = "; cin >> Arm; //TString Com = "J02"; cerr<<"--- Comment = "; cin >> Com; if(Arm!="L"&&Arm!="R") exit(-3); /*Read In RunNo{{{*/ TString sTarget="", sKin = ""; if(Target.Contains("H")){ sTarget = Target; sTarget.ReplaceAll("H","h"); } if(Target.Contains("C")){ sTarget = Target; sTarget.ReplaceAll("C","c"); } sKin=Kin; sKin.ReplaceAll("Kin","kin"); //TString Input_Parameter = Form("%s/xs_input/%sHRS/xs_%s_%s.dat",XGT2_DIR.Data(),Arm.Data(),sTarget.Data(),sKin.Data()); TString Input_Parameter = Form("%s/xs_input/%sHRS_FULL/xs_%s_%s.dat",XGT2_DIR.Data(),Arm.Data(),sTarget.Data(),sKin.Data()); ifstream input_par(Input_Parameter.Data()); TString one_line; int RunNo_Temp = gGet_InputFile_Var(Input_Parameter,0).Atoi(); vector<int> vRunNoChain = gGet_RunNoChain(RunNo_Temp, gGet_InputFile_Var(Input_Parameter,15)); const int N_Run=vRunNoChain.size(); int RunNo[N_Run]; cout<<endl<<"--- RunList ="; for(int i=0;i<N_Run;i++){ RunNo[i] = vRunNoChain[i]; cout<<" "<<RunNo[i]; } cout<<endl; /*}}}*/ TString InputFilePath = Form("%sresults/%s/%s/", XGT2_DIR.Data(),Target.Data(),Com.Data()); TString InputFileName = Form("%s/results/%s/%s/%s_%s_%s_Yield_%s.root", XGT2_DIR.Data(),Target.Data(),Com.Data(),Arm.Data(),Kin.Data(),Target.Data(),Com.Data()); if(!(gSystem->FindFile(InputFilePath.Data(), InputFileName))){ cerr<<" *** RootFile does exist--> "<<InputFileName.Data()<<endl; return -1; } cerr<<" &&& Reading in RootFile --> "<<InputFileName.Data()<<endl; double Ep,xbj; double XS_EX[N_Run], XS_MC[N_Run], XS_EX_Stat[N_Run], XS_EX_Sys[N_Run], Xbj_EX[N_Run]; TString InputDataName = Form("%s/results/%s/%s/%s_%s_%s_Yield.dat_%s",/*{{{*/ XGT2_DIR.Data(),Target.Data(),Com.Data(),Arm.Data(),Kin.Data(),Target.Data(),Com.Data()); if(!(gSystem->FindFile(InputFilePath.Data(), InputDataName))){ cerr<<" *** RootFile does exist--> "<<InputDataName.Data()<<endl; return -2; } cerr<<" &&& Reading in DataFile --> "<<InputDataName.Data()<<endl; ifstream run_1(InputDataName.Data()); double dummy; TString com; com.ReadLine(run_1); vector<double> vXS_MC, vXbj; double xs_mc, xbj_mc; while ( run_1>>dummy>>dummy>>dummy>>xs_mc >> xbj_mc >>dummy>>dummy>>dummy>>dummy>>dummy>>dummy>>dummy>>dummy>>dummy>>dummy>>dummy>>dummy >>dummy>>dummy>>dummy>>dummy>>dummy>>dummy>>dummy>>dummy>>dummy>>dummy>>dummy>>dummy){ cout<<Form("--- From Data: xbj=%f, XS_MC=%e", xbj_mc, xs_mc)<<endl; vXS_MC.push_back(xs_mc); vXbj.push_back(xbj_mc); }/*}}}*/ TFile *f1 = new TFile(InputFileName.Data(),"r"); if(f1->IsZombie()){ cerr<<"*** I cannot fine ROOTFile: "<<InputFileName.Data()<<" ***"<<endl; exit(-1); } TTree *T = (TTree*) gDirectory->Get("T"); const int N_Evt = T->GetEntries(); T->SetBranchAddress("Ep", &Ep); T->SetBranchAddress("xbj", &xbj); for(int i=0;i<N_Run;i++){ cout<<Form("--- For Run#%d", vRunNoChain[i])<<endl; T->SetBranchAddress(Form("XS_%d", vRunNoChain[i]), &XS_EX[i]); T->SetBranchAddress(Form("XS_Stat_%d",vRunNoChain[i]), &XS_EX_Stat[i]); T->SetBranchAddress(Form("XS_Sys_%d" ,vRunNoChain[i]), &XS_EX_Sys[i]); } double XS_R[N_Run][N_Evt], XS_R_Err[N_Run][N_Evt]; double Ep_Bin[N_Evt],xbj_Bin[N_Evt]; double Ep_Max = -1000.0, Ep_Min = 1000.0, xbj_Max = -1000.0, xbj_Min = 1000.0, XS_EX_Err=0.0; for(int j=0;j<N_Evt;j++){ T->GetEntry(j); Ep_Bin[j] = Ep; if(Ep>Ep_Max) Ep_Max = Ep; if(Ep<Ep_Min) Ep_Min = Ep; int I_Pick = 0; double mc = 0; for(int k =0;k<vXbj.size();k++){ if(fabs(vXbj[k]-xbj)<0.0001){ I_Pick = k; mc = vXS_MC[k]; cout<<Form("^^^^ xbj=%4.3f/%4.3f, XS=%6.4e/%6.4e", Xbj_EX[k], xbj, mc, XS_EX[0])<<endl; } } xbj_Bin[j] = xbj; if(xbj>xbj_Max) xbj_Max = xbj; if(xbj<xbj_Min) xbj_Min = xbj; for(int i=0;i<N_Run;i++){ cerr<<Form("Run#%d: Ep = %f, XS_R = %e (%e)", vRunNoChain[i],Ep_Bin[j], XS_EX[i],XS_EX_Stat[i])<<endl; XS_EX_Err = sqrt( pow(XS_EX_Stat[i],2)+pow(XS_EX_Sys[i],2) ); if(XS_EX[i]>1e-30){ XS_R[i][j] = XS_EX[i] / mc; XS_R_Err[i][j] = XS_R[i][j]*sqrt( pow(XS_EX_Err/XS_EX[i],2) ); } else{ XS_R[i][j] = 0.0; XS_R_Err[i][j] = 0.0; } } } /*XS Ratio{{{*/ double Y_Min =0.2, Y_Max = 1.5; if(N_Run>10) Y_Min = -1.0; TCanvas *c3 = new TCanvas("c3","c3",1200,800); gPad->SetGrid(); TH2F* r = new TH2F("r","",1000,xbj_Min-0.2,xbj_Max+0.2,1000,Y_Min, Y_Max); r->SetStats(kFALSE); r->SetXTitle("X"); r->GetXaxis()->CenterTitle(1); r->GetXaxis()->SetTitleFont(32); r->GetXaxis()->SetTitleSize(0.06); r->GetXaxis()->SetTitleOffset(0.7); r->SetYTitle("#sigma_{EX}/#sigma_{MC}"); r->GetYaxis()->CenterTitle(1); r->GetYaxis()->SetTitleFont(32); r->GetYaxis()->SetTitleSize(0.05); r->GetYaxis()->SetTitleOffset(0.7); r->Draw(); TGraphErrors *pl_r[N_Run]; int N_Color = 1, N_Style = 20; for(int i=0;i<N_Run;i++){ pl_r[i] = new TGraphErrors(N_Evt,&xbj_Bin[0],&XS_R[i][0],0,&XS_R_Err[i][0]); pl_r[i]-> SetMarkerSize(1.5); N_Color++; if (N_Color==5) N_Color++; if(N_Color>9&&N_Color<37) N_Color = 37; if(N_Color>49) N_Color = 1; pl_r[i]-> SetMarkerColor(N_Color); N_Style++; if(N_Style>30) N_Style = 2; if(N_Style>5&&N_Style<20) N_Style = 20; pl_r[i]-> SetMarkerStyle(N_Style); } TMultiGraph *mg3 = new TMultiGraph(); TLegend *l3 = new TLegend(0.15,0.10,0.40, 0.10+N_Run*0.03,Form("%s Target",Target.Data())); l3->SetBorderSize(0); l3->SetTextSize(0.025); if(N_Run>10) l3->SetTextSize(0.015); l3->SetTextFont(22); for(int i=0;i<N_Run;i++){ l3->AddEntry(pl_r[i], Form(" %s (HRS-%s) #%d",Kin.Data(), Arm.Data(), vRunNoChain[i]),"p"); mg3->Add(pl_r[i]); } mg3->Draw("P"); l3->Draw(); /*}}}*/ c3->Print(Form("%s_XSR_%s_%s_%s.pdf",Target.Data(),Arm.Data(),Kin.Data(),Com.Data())); c3->Print(Form("%s_XSR_%s_%s_%s.png",Target.Data(),Arm.Data(),Kin.Data(),Com.Data())); // f1->Close(); }
void listMismatchedEvents(TString inputFile = "L1UnpackedPureEmulator.root", testObject type = Jets) { TFile *inFile = TFile::Open(inputFile); TTree *emulatorResults = (TTree*)inFile->Get("EmulatorResults/L1UpgradeTree"); TTree *unpackerResults = (TTree*)inFile->Get("UnpackerResults/L1UpgradeTree"); int event, run, lumi; emulatorResults->SetBranchAddress("event",&event); emulatorResults->SetBranchAddress("run",&run); emulatorResults->SetBranchAddress("lumi",&lumi); std::vector<int> *e_hwPt =0; std::vector<int> *e_hwEta =0; std::vector<int> *e_hwPhi =0; std::vector<int> *e_bx =0; int e_N; std::vector<int> *u_hwPt =0; std::vector<int> *u_hwEta =0; std::vector<int> *u_hwPhi =0; std::vector<int> *u_bx =0; int u_N; TString prefix; TString nPrefix; switch(type) { case Jets: prefix = "jet"; nPrefix = "Jet"; break; case EGammas: prefix = "egamma"; nPrefix = "Egamma"; break; case Taus: prefix = "tau"; nPrefix = "Tau"; break; case Centrality: prefix = "hfring"; nPrefix = "Hfring"; break; default: prefix = "jet"; nPrefix = "Jet"; break; } emulatorResults->SetBranchAddress(prefix + "_hwPt",&e_hwPt); emulatorResults->SetBranchAddress(prefix + "_hwEta",&e_hwEta); emulatorResults->SetBranchAddress(prefix + "_hwPhi",&e_hwPhi); emulatorResults->SetBranchAddress(prefix + "_bx",&e_bx); emulatorResults->SetBranchAddress("n"+nPrefix,&e_N); unpackerResults->SetBranchAddress(prefix + "_hwPt",&u_hwPt); unpackerResults->SetBranchAddress(prefix + "_hwEta",&u_hwEta); unpackerResults->SetBranchAddress(prefix + "_hwPhi",&u_hwPhi); unpackerResults->SetBranchAddress(prefix + "_bx",&u_bx); unpackerResults->SetBranchAddress("n"+nPrefix,&u_N); long misses = 0; long entries = emulatorResults->GetEntries(); for(long i = 0; i < entries; i++) { emulatorResults->GetEntry(i); unpackerResults->GetEntry(i); int e_offset = 0; int u_offset = 0; // e_offset will always be 0, but make sure that we are not one of the // 1/100 events with multiple RCT BX. // there are 4 taus per event, 8 jets, 8 egammas, and 1 centrality if(e_N == 4) { e_offset = 0; } else if (e_N == 8) { e_offset = 0; } else if (e_N == 1) { e_offset = 0; } else { // there are multiple BX here and I don't know the alignment // skip the event continue; } // there are 20 taus per events, 40 jets, 40 egammas, and 5 centralities because of extra BX if (u_N == 5) { u_offset = 2; } else if (u_N == 20) { u_offset = 8; } else if (u_N == 40) { u_offset = 16; } else { std::cout << "ERROR, UNKNOWN BX" << std::endl; std::cout << "Event: " << event << std::endl; continue; } for(int j = 0; j < e_N; j++) { //if(e_hwPt[e_offset+j] > 0) { if((((*e_hwPt)[e_offset+j])) != (((*u_hwPt)[u_offset+j]))) { std::cout << std::dec << "" << run << ":" << lumi << ":" << event << "" << std::endl; //std::cout << std::dec << (*e_hwPt)[e_offset+j] << " " << (*u_hwPt)[u_offset+j] << std::endl; misses++; break; } //} } } std::cout << "Misses: " << misses << std::endl; }
int main(int argc, char *argv[]) { cout.setf(ios::fixed, ios::floatfield); cout.precision(12); cout << "Run " << argv[1] << " ..." << endl; // Read cuts file char tempFileCuts[500]; sprintf(tempFileCuts, "%s/cuts_MB/cuts_%s.dat", getenv("PARALLEL_DATA_PATH"),argv[1]); cout << "... Reading: " << tempFileCuts << endl; ifstream fileCuts(tempFileCuts); fileCuts >> cutBeamBurstTime >> comment; fileCuts >> nCutsTimeWindows >> comment; if (nCutsTimeWindows > 0) { for (int i=0; i<nCutsTimeWindows; i++) { fileCuts >> cutTimeWindowLower[i] >> cutTimeWindowUpper[i]; } } fileCuts >> cutEastAnode >> comment; fileCuts >> cutWestAnode >> comment; fileCuts >> cutEastTwoFold >> comment; fileCuts >> cutWestTwoFold >> comment; fileCuts >> cutEastTopVetoQADC >> comment; fileCuts >> cutEastTopVetoTDC >> comment; fileCuts >> cutEastDriftTubeTAC >> comment; fileCuts >> cutWestDriftTubeTAC >> comment; fileCuts >> cutEastBackingVetoQADC >> comment; fileCuts >> cutEastBackingVetoTDC >> comment; fileCuts >> cutWestBackingVetoQADC >> comment; fileCuts >> cutWestBackingVetoTDC >> comment; cout << "... Beam Burst T0 Cut: " << cutBeamBurstTime << endl; cout << "... Number of Time Windows Cuts: " << nCutsTimeWindows << endl; if (nCutsTimeWindows > 0) { for (int i=0; i<nCutsTimeWindows; i++) { cout << " [" << cutTimeWindowLower[i] << ", " << cutTimeWindowUpper[i] << "]" << endl; } } cout << "... East MWPC Anode Cut: " << cutEastAnode << endl; cout << "... West MWPC Anode Cut: " << cutWestAnode << endl; cout << "... East Scintillator Two-Fold Trigger Cut: " << cutEastTwoFold << endl; cout << "... West Scintillator Two-Fold Trigger Cut: " << cutWestTwoFold << endl; cout << "... East Top Veto QADC Cut: " << cutEastTopVetoQADC << endl; cout << "... East Top Veto TDC Cut: " << cutEastTopVetoTDC << endl; cout << "... East Drift Tube TAC Cut: " << cutEastDriftTubeTAC << endl; cout << "... West Drift Tube TAC Cut: " << cutWestDriftTubeTAC << endl; cout << "... East Backing Veto QADC Cut: " << cutEastBackingVetoQADC << endl; cout << "... East Backing Veto TDC Cut: " << cutEastBackingVetoTDC << endl; cout << "... West Backing Veto QADC Cut: " << cutWestBackingVetoQADC << endl; cout << "... West Backing Veto TDC Cut: " << cutWestBackingVetoTDC << endl; // Read pedestals file char tempFilePed[500]; int iRun; sprintf(tempFilePed, "/extern/UCNA/pedestals_MB/pedestals_%s.dat", argv[1]); cout << "... Reading: " << tempFilePed << endl; ifstream filePed(tempFilePed); for (int i=0; i<8; i++) { filePed >> iRun >> pedQadc[i]; } for (int i=0; i<32; i++) { filePed >> iRun >> pedPdc2[i]; } for (int i=0; i<32; i++) { filePed >> iRun >> pedPadc[i]; } //filePed >> iRun >> pedPdc30; //filePed >> iRun >> pedPdc34; //cout << iRun << " " << pedPdc30 << endl; //cout << iRun << " " << pedPdc34 << endl; // Open output ntuple char tempOut[500]; sprintf(tempOut, "%s/replay_pass1_%s.root",getenv("REPLAY_PASS1"), argv[1]); TFile *fileOut = new TFile(tempOut,"RECREATE"); TTree *Tout = new TTree("pass1", "pass1"); // Variables Tout->Branch("pmt0", &pmt[0], "pmt0/D"); Tout->Branch("pmt1", &pmt[1], "pmt1/D"); Tout->Branch("pmt2", &pmt[2], "pmt2/D"); Tout->Branch("pmt3", &pmt[3], "pmt3/D"); Tout->Branch("pmt4", &pmt[4], "pmt4/D"); Tout->Branch("pmt5", &pmt[5], "pmt5/D"); Tout->Branch("pmt6", &pmt[6], "pmt6/D"); Tout->Branch("pmt7", &pmt[7], "pmt7/D"); Tout->Branch("cathE0", &cathodeEast[0], "cathE0/D"); Tout->Branch("cathE1", &cathodeEast[1], "cathE1/D"); Tout->Branch("cathE2", &cathodeEast[2], "cathE2/D"); Tout->Branch("cathE3", &cathodeEast[3], "cathE3/D"); Tout->Branch("cathE4", &cathodeEast[4], "cathE4/D"); Tout->Branch("cathE5", &cathodeEast[5], "cathE5/D"); Tout->Branch("cathE6", &cathodeEast[6], "cathE6/D"); Tout->Branch("cathE7", &cathodeEast[7], "cathE7/D"); Tout->Branch("cathE8", &cathodeEast[8], "cathE8/D"); Tout->Branch("cathE9", &cathodeEast[9], "cathE9/D"); Tout->Branch("cathE10", &cathodeEast[10], "cathE10/D"); Tout->Branch("cathE11", &cathodeEast[11], "cathE11/D"); Tout->Branch("cathE12", &cathodeEast[12], "cathE12/D"); Tout->Branch("cathE13", &cathodeEast[13], "cathE13/D"); Tout->Branch("cathE14", &cathodeEast[14], "cathE14/D"); Tout->Branch("cathE15", &cathodeEast[15], "cathE15/D"); Tout->Branch("cathE16", &cathodeEast[16], "cathE16/D"); Tout->Branch("cathE17", &cathodeEast[17], "cathE17/D"); Tout->Branch("cathE18", &cathodeEast[18], "cathE18/D"); Tout->Branch("cathE19", &cathodeEast[19], "cathE19/D"); Tout->Branch("cathE20", &cathodeEast[20], "cathE20/D"); Tout->Branch("cathE21", &cathodeEast[21], "cathE21/D"); Tout->Branch("cathE22", &cathodeEast[22], "cathE22/D"); Tout->Branch("cathE23", &cathodeEast[23], "cathE23/D"); Tout->Branch("cathE24", &cathodeEast[24], "cathE24/D"); Tout->Branch("cathE25", &cathodeEast[25], "cathE25/D"); Tout->Branch("cathE26", &cathodeEast[26], "cathE26/D"); Tout->Branch("cathE27", &cathodeEast[27], "cathE27/D"); Tout->Branch("cathE28", &cathodeEast[28], "cathE28/D"); Tout->Branch("cathE29", &cathodeEast[29], "cathE29/D"); Tout->Branch("cathE30", &cathodeEast[30], "cathE30/D"); Tout->Branch("cathE31", &cathodeEast[31], "cathE31/D"); Tout->Branch("cathW0", &cathodeWest[0], "cathW0/D"); Tout->Branch("cathW1", &cathodeWest[1], "cathW1/D"); Tout->Branch("cathW2", &cathodeWest[2], "cathW2/D"); Tout->Branch("cathW3", &cathodeWest[3], "cathW3/D"); Tout->Branch("cathW4", &cathodeWest[4], "cathW4/D"); Tout->Branch("cathW5", &cathodeWest[5], "cathW5/D"); Tout->Branch("cathW6", &cathodeWest[6], "cathW6/D"); Tout->Branch("cathW7", &cathodeWest[7], "cathW7/D"); Tout->Branch("cathW8", &cathodeWest[8], "cathW8/D"); Tout->Branch("cathW9", &cathodeWest[9], "cathW9/D"); Tout->Branch("cathW10", &cathodeWest[10], "cathW10/D"); Tout->Branch("cathW11", &cathodeWest[11], "cathW11/D"); Tout->Branch("cathW12", &cathodeWest[12], "cathW12/D"); Tout->Branch("cathW13", &cathodeWest[13], "cathW13/D"); Tout->Branch("cathW14", &cathodeWest[14], "cathW14/D"); Tout->Branch("cathW15", &cathodeWest[15], "cathW15/D"); Tout->Branch("cathW16", &cathodeWest[16], "cathW16/D"); Tout->Branch("cathW17", &cathodeWest[17], "cathW17/D"); Tout->Branch("cathW18", &cathodeWest[18], "cathW18/D"); Tout->Branch("cathW19", &cathodeWest[19], "cathW19/D"); Tout->Branch("cathW20", &cathodeWest[20], "cathW20/D"); Tout->Branch("cathW21", &cathodeWest[21], "cathW21/D"); Tout->Branch("cathW22", &cathodeWest[22], "cathW22/D"); Tout->Branch("cathW23", &cathodeWest[23], "cathW23/D"); Tout->Branch("cathW24", &cathodeWest[24], "cathW24/D"); Tout->Branch("cathW25", &cathodeWest[25], "cathW25/D"); Tout->Branch("cathW26", &cathodeWest[26], "cathW26/D"); Tout->Branch("cathW27", &cathodeWest[27], "cathW27/D"); Tout->Branch("cathW28", &cathodeWest[28], "cathW28/D"); Tout->Branch("cathW29", &cathodeWest[29], "cathW29/D"); Tout->Branch("cathW30", &cathodeWest[30], "cathW30/D"); Tout->Branch("cathW31", &cathodeWest[31], "cathW31/D"); Tout->Branch("AnodeE", &AnodeE, "AnodeE/D"); Tout->Branch("AnodeW", &AnodeW, "AnodeW/D"); Tout->Branch("timeE", &timeE, "timeE/D"); Tout->Branch("timeW", &timeW, "timeW/D"); Tout->Branch("timeE_BB", &timeE_BB, "timeE_BB/D"); Tout->Branch("timeW_BB", &timeW_BB, "timeW_BB/D"); Tout->Branch("UBtime", &UBtime, "UBtime/D"); Tout->Branch("UBtime_BB", &UBtime_BB, "UBtime_BB/D"); Tout->Branch("twoFoldE", &twoFoldE, "twoFoldE/D"); Tout->Branch("twoFoldW", &twoFoldW, "twoFoldW/D"); Tout->Branch("xE", &xE, "xE/D"); Tout->Branch("yE", &yE, "yE/D"); Tout->Branch("xW", &xW, "xW/D"); Tout->Branch("yW", &yW, "yW/D"); // Swank's addition (1 of 2) int xeRC,yeRC,xwRC,ywRC; WireChamberResponse * WCR = new WireChamberResponse(); Tout->Branch("xeRC", &xeRC, "xeRC/I"); //x east response class. Tout->Branch("yeRC", &yeRC, "yeRC/I"); //y east response class... Tout->Branch("xwRC", &xwRC, "xwRC/I"); Tout->Branch("ywRC", &ywRC, "ywRC/I"); //end of Swank's addition (1 of 2) Tout->Branch("PID", &PID, "PID/I"); Tout->Branch("type", &type, "type/I"); Tout->Branch("side", &side, "side/I"); Tout->Branch("posError", &posError, "posError/I"); // East MWPC y posPdc2[0] = 76.20; posPdc2[1] = 66.04; posPdc2[2] = 55.88; posPdc2[3] = 45.72; posPdc2[4] = 35.56; posPdc2[5] = 25.40; posPdc2[6] = 15.24; posPdc2[7] = 5.08; posPdc2[8] = -5.08; posPdc2[9] = -15.24; posPdc2[10] = -25.40; posPdc2[11] = -35.56; posPdc2[12] = -45.72; posPdc2[13] = -55.88; posPdc2[14] = -66.04; posPdc2[15] = -76.20; // East MWPC x posPdc2[16] = 76.20; posPdc2[17] = 66.04; posPdc2[18] = 55.88; posPdc2[19] = 45.72; posPdc2[20] = 35.56; posPdc2[21] = 25.40; posPdc2[22] = 15.24; posPdc2[23] = 5.08; posPdc2[24] = -5.08; posPdc2[25] = -15.24; posPdc2[26] = -25.40; posPdc2[27] = -35.56; posPdc2[28] = -45.72; posPdc2[29] = -55.88; posPdc2[30] = -66.04; posPdc2[31] = -76.20; // West MWPC y posPadc[0] = 76.20; posPadc[1] = 66.04; posPadc[2] = 55.88; posPadc[3] = 45.72; posPadc[4] = 35.56; posPadc[5] = 25.40; posPadc[6] = 15.24; posPadc[7] = 5.08; posPadc[8] = -5.08; posPadc[9] = -15.24; posPadc[10] = -25.40; posPadc[11] = -35.56; posPadc[12] = -45.72; posPadc[13] = -55.88; posPadc[14] = -66.04; posPadc[15] = -76.20; // West MWPC x posPadc[16] = -76.20; posPadc[17] = -66.04; posPadc[18] = -55.88; posPadc[19] = -45.72; posPadc[20] = -35.56; posPadc[21] = -25.40; posPadc[22] = -15.24; posPadc[23] = -5.08; posPadc[24] = 5.08; posPadc[25] = 15.24; posPadc[26] = 25.40; posPadc[27] = 35.56; posPadc[28] = 45.72; posPadc[29] = 55.88; posPadc[30] = 66.04; posPadc[31] = 76.20; // Open input ntuple char tempIn[500]; sprintf(tempIn, "/extern/mabrow05/ucna/rawdata/full%s.root", argv[1]); TFile *fileIn = new TFile(tempIn, "READ"); TTree *Tin = (TTree*)(fileIn->Get("h1")); // Variables Tin->SetBranchAddress("Pdc30", &Pdc30); Tin->SetBranchAddress("Pdc34", &Pdc34); Tin->SetBranchAddress("Tdc016", &Tdc016); Tin->SetBranchAddress("Tdc017", &Tdc017); Tin->SetBranchAddress("Sis00", &Sis00); Tin->SetBranchAddress("Qadc0", &Qadc[0]); Tin->SetBranchAddress("Qadc1", &Qadc[1]); Tin->SetBranchAddress("Qadc2", &Qadc[2]); Tin->SetBranchAddress("Qadc3", &Qadc[3]); Tin->SetBranchAddress("Qadc4", &Qadc[4]); Tin->SetBranchAddress("Qadc5", &Qadc[5]); Tin->SetBranchAddress("Qadc6", &Qadc[6]); Tin->SetBranchAddress("Qadc7", &Qadc[7]); Tin->SetBranchAddress("Pdc20", &Pdc2[0]); Tin->SetBranchAddress("Pdc21", &Pdc2[1]); Tin->SetBranchAddress("Pdc22", &Pdc2[2]); Tin->SetBranchAddress("Pdc23", &Pdc2[3]); Tin->SetBranchAddress("Pdc24", &Pdc2[4]); Tin->SetBranchAddress("Pdc25", &Pdc2[5]); Tin->SetBranchAddress("Pdc26", &Pdc2[6]); Tin->SetBranchAddress("Pdc27", &Pdc2[7]); Tin->SetBranchAddress("Pdc28", &Pdc2[8]); Tin->SetBranchAddress("Pdc29", &Pdc2[9]); Tin->SetBranchAddress("Pdc210", &Pdc2[10]); Tin->SetBranchAddress("Pdc211", &Pdc2[11]); Tin->SetBranchAddress("Pdc212", &Pdc2[12]); Tin->SetBranchAddress("Pdc213", &Pdc2[13]); Tin->SetBranchAddress("Pdc214", &Pdc2[14]); Tin->SetBranchAddress("Pdc215", &Pdc2[15]); Tin->SetBranchAddress("Pdc216", &Pdc2[16]); Tin->SetBranchAddress("Pdc217", &Pdc2[17]); Tin->SetBranchAddress("Pdc218", &Pdc2[18]); Tin->SetBranchAddress("Pdc219", &Pdc2[19]); Tin->SetBranchAddress("Pdc220", &Pdc2[20]); Tin->SetBranchAddress("Pdc221", &Pdc2[21]); Tin->SetBranchAddress("Pdc222", &Pdc2[22]); Tin->SetBranchAddress("Pdc223", &Pdc2[23]); Tin->SetBranchAddress("Pdc224", &Pdc2[24]); Tin->SetBranchAddress("Pdc225", &Pdc2[25]); Tin->SetBranchAddress("Pdc226", &Pdc2[26]); Tin->SetBranchAddress("Pdc227", &Pdc2[27]); Tin->SetBranchAddress("Pdc228", &Pdc2[28]); Tin->SetBranchAddress("Pdc229", &Pdc2[29]); Tin->SetBranchAddress("Pdc230", &Pdc2[30]); Tin->SetBranchAddress("Pdc231", &Pdc2[31]); Tin->SetBranchAddress("Padc0", &Padc[0]); Tin->SetBranchAddress("Padc1", &Padc[1]); Tin->SetBranchAddress("Padc2", &Padc[2]); Tin->SetBranchAddress("Padc3", &Padc[3]); Tin->SetBranchAddress("Padc4", &Padc[4]); Tin->SetBranchAddress("Padc5", &Padc[5]); Tin->SetBranchAddress("Padc6", &Padc[6]); Tin->SetBranchAddress("Padc7", &Padc[7]); Tin->SetBranchAddress("Padc8", &Padc[8]); Tin->SetBranchAddress("Padc9", &Padc[9]); Tin->SetBranchAddress("Padc10", &Padc[10]); Tin->SetBranchAddress("Padc11", &Padc[11]); Tin->SetBranchAddress("Padc12", &Padc[12]); Tin->SetBranchAddress("Padc13", &Padc[13]); Tin->SetBranchAddress("Padc14", &Padc[14]); Tin->SetBranchAddress("Padc15", &Padc[15]); Tin->SetBranchAddress("Padc16", &Padc[16]); Tin->SetBranchAddress("Padc17", &Padc[17]); Tin->SetBranchAddress("Padc18", &Padc[18]); Tin->SetBranchAddress("Padc19", &Padc[19]); Tin->SetBranchAddress("Padc20", &Padc[20]); Tin->SetBranchAddress("Padc21", &Padc[21]); Tin->SetBranchAddress("Padc22", &Padc[22]); Tin->SetBranchAddress("Padc23", &Padc[23]); Tin->SetBranchAddress("Padc24", &Padc[24]); Tin->SetBranchAddress("Padc25", &Padc[25]); Tin->SetBranchAddress("Padc26", &Padc[26]); Tin->SetBranchAddress("Padc27", &Padc[27]); Tin->SetBranchAddress("Padc28", &Padc[28]); Tin->SetBranchAddress("Padc29", &Padc[29]); Tin->SetBranchAddress("Padc30", &Padc[30]); Tin->SetBranchAddress("Padc31", &Padc[31]); Tin->SetBranchAddress("S83028", &S83028); Tin->SetBranchAddress("S8200", &S8200); Tin->SetBranchAddress("Clk0", &Clk0); Tin->SetBranchAddress("Clk1", &Clk1); Tin->SetBranchAddress("Clk2", &Clk2); Tin->SetBranchAddress("Clk3", &Clk3); Tin->SetBranchAddress("Pdc38", &Pdc38); Tin->SetBranchAddress("Pdc39", &Pdc39); Tin->SetBranchAddress("Pdc310", &Pdc310); Tin->SetBranchAddress("Pdc311", &Pdc311); Tin->SetBranchAddress("Qadc9", &Qadc9); Tin->SetBranchAddress("Tdc019", &Tdc019); Tin->SetBranchAddress("Pdc313", &Pdc313); Tin->SetBranchAddress("Pdc315", &Pdc315); Tin->SetBranchAddress("Qadc8", &Qadc8); Tin->SetBranchAddress("Tdc018", &Tdc018); Tin->SetBranchAddress("Qadc10", &Qadc10); Tin->SetBranchAddress("Tdc020", &Tdc020); int nEvents = Tin->GetEntries(); cout << "... Processing nEvents = " << nEvents << endl; // Loop over events for (int i=0; i<nEvents; i++) { Tin->GetEvent(i); int iSis00 = (int) Sis00; // Calculate pedestal-subtracted PMT QADC values for (int j=0; j<8; j++) { pmt[j] = ((double) Qadc[j]) - pedQadc[j]; } // Calculate pedestal-subtracted MWPC cathode PADC values for (int j=0; j<32; j++) { cathodeEast[j] = ((double) Pdc2[j]) - pedPdc2[j]; cathodeWest[j] = ((double) Padc[j]) - pedPadc[j]; } // Calculate pedestal-subtracted MWPC Anode PADC values //Took this out for now. We are comparing against a cut instead... //AnodeE = ((double) Pdc30) - pedPdc30; //AnodeW = ((double) Pdc34) - pedPdc34; // UCN monitor events bool UCNMonitorTrigger = false; if ( (iSis00 == 260) || (iSis00 == 516) || (iSis00 == 1028) || (iSis00 == 2052) ) { UCNMonitorTrigger = true; } // Events with a muon hit bool muonHitEast = false; bool muonHitWest = false; if ( (((double) Qadc8) > cutEastBackingVetoQADC) || (((double) Tdc018) > cutEastBackingVetoTDC) || (((double) Qadc9) > cutEastTopVetoQADC) || (((double) Tdc019) > cutEastTopVetoTDC) || (((double) Pdc313) > cutEastDriftTubeTAC) ) { muonHitEast = true; } if ( (((double) Qadc10) > cutWestBackingVetoQADC) || (((double) Tdc020) > cutWestBackingVetoTDC) || (((double) Pdc315) > cutWestDriftTubeTAC) ) { muonHitWest = true; } // LED trigger events bool LEDTrigger = false; if ( (iSis00 == 128) || (iSis00 == 129) || (iSis00 == 130) || (iSis00 == 131) || (iSis00 == 163) ) { LEDTrigger = true; } // Bi pulser trigger events bool bismuthPulser = false; if (iSis00 == 32) bismuthPulser = true; // Scintillator events bool mwpcHitEast = false; bool mwpcHitWest = false; bool scintillatorHitEast = false; bool scintillatorHitWest = false; bool scintillatorHitBoth = false; bool coincidenceEast = false; bool coincidenceWest = false; bool scintillatorHitFirstEast = false; bool scintillatorHitFirstWest = false; bool scintillatorHitBothBad = false; bool triggerEast = false; bool triggerWest = false; if ( ((double) Pdc30) > cutEastAnode) mwpcHitEast = true; if ( ((double) Pdc34) > cutWestAnode) mwpcHitWest = true; double timeEastTwoFold = ((double) Tdc016)*tdcChannelToTime; double timeWestTwoFold = ((double) Tdc017)*tdcChannelToTime; if (timeEastTwoFold > 0.*tdcChannelToTime) scintillatorHitEast = true; if (timeWestTwoFold > 0.*tdcChannelToTime) scintillatorHitWest = true; if (scintillatorHitEast && scintillatorHitWest) { scintillatorHitBoth = true; if ( (timeEastTwoFold > cutEastTwoFold) && (timeWestTwoFold < cutWestTwoFold) ) { scintillatorHitFirstEast = true; } if ( (timeEastTwoFold < cutEastTwoFold) && (timeWestTwoFold > cutWestTwoFold) ) { scintillatorHitFirstWest = true; } if ( (timeEastTwoFold > cutEastTwoFold) && (timeWestTwoFold > cutWestTwoFold) ) { scintillatorHitBothBad = true; } if ( (timeEastTwoFold < cutEastTwoFold) && (timeWestTwoFold < cutWestTwoFold) ) { scintillatorHitBothBad = true; } } if (mwpcHitEast && scintillatorHitEast) coincidenceEast = true; if (mwpcHitWest && scintillatorHitWest) coincidenceWest = true; // Event PID logic if (UCNMonitorTrigger) PID = 5; else if (LEDTrigger) PID = 3; else if (muonHitEast || muonHitWest) PID = 2; else if (bismuthPulser) PID = 4; else if ( (scintillatorHitEast && !mwpcHitEast && !scintillatorHitWest && !mwpcHitWest) || (!scintillatorHitEast && !mwpcHitEast && scintillatorHitWest && !mwpcHitWest) ) PID = 0; else if ( (coincidenceEast && !scintillatorHitWest && !mwpcHitWest) || (!scintillatorHitEast && !mwpcHitEast && coincidenceWest) || (coincidenceEast && coincidenceWest && !scintillatorHitBothBad) || (coincidenceEast && !scintillatorHitWest && mwpcHitWest) || (!scintillatorHitEast && mwpcHitEast && coincidenceWest) ) PID = 1; else PID = 6; type = -1; side = -1; if (PID == 1) { if (coincidenceEast && !scintillatorHitWest && !mwpcHitWest) { type = 0; side = 0; } if (!scintillatorHitEast && !mwpcHitEast && coincidenceWest) { type = 0; side = 1; } if (coincidenceEast && coincidenceWest && !scintillatorHitBothBad) { type = 1; if (scintillatorHitFirstEast) side = 0; if (scintillatorHitFirstWest) side = 1; } if (coincidenceEast && !scintillatorHitWest && mwpcHitWest) { type = 2; side = 0; } if (!scintillatorHitEast && mwpcHitEast && coincidenceWest) { type = 2; side = 1; } } // Calculate MWPC positions for electron events xE = -100.; yE = -100.; xW = -100.; yW = -100.; posError = 0; if (PID == 1) { /* // Find cathode wire with maximum signal on each plane double cathodeEastMax_x = -1.0; double cathodeEastMax_y = -1.0; double cathodeWestMax_x = -1.0; double cathodeWestMax_y = -1.0; int intCathodeEastMax_x = -1; int intCathodeEastMax_y = -1; int intCathodeWestMax_x = -1; int intCathodeWestMax_y = -1; for (int j=0; j<16; j++) { if (cathodeEast[j+16] > cathodeEastMax_x) { cathodeEastMax_x = cathodeEast[j+16]; intCathodeEastMax_x = j+16; } if (cathodeEast[j] > cathodeEastMax_y) { cathodeEastMax_y = cathodeEast[j]; intCathodeEastMax_y = j; } if (cathodeWest[j+16] > cathodeWestMax_x) { cathodeWestMax_x = cathodeWest[j+16]; intCathodeWestMax_x = j+16; } if (cathodeWest[j] > cathodeWestMax_y) { cathodeWestMax_y = cathodeWest[j]; intCathodeWestMax_y = j; } } // East x double xMWPCEast = 0.; double xMWPCEastSum = 0.; if (mwpcHitEast) { if (intCathodeEastMax_x == 16) { xMWPCEast = cathodeEast[16]*posPdc2[16] + cathodeEast[17]*posPdc2[17]; xMWPCEastSum = cathodeEast[16] + cathodeEast[17]; } else if (intCathodeEastMax_x == 31) { xMWPCEast = cathodeEast[30]*posPdc2[30] + cathodeEast[31]*posPdc2[31]; xMWPCEastSum = cathodeEast[30] + cathodeEast[31]; } else { int n = intCathodeEastMax_x; xMWPCEast = cathodeEast[n-1]*posPdc2[n-1] + cathodeEast[n]*posPdc2[n] + cathodeEast[n+1]*posPdc2[n+1]; xMWPCEastSum = cathodeEast[n-1] + cathodeEast[n] + cathodeEast[n+1]; } } if (xMWPCEastSum > 0.) { xMWPCEast = xMWPCEast / xMWPCEastSum; } else { xMWPCEast = -100.; posError = 1; } // East y double yMWPCEast = 0.; double yMWPCEastSum = 0.; if (mwpcHitEast) { if (intCathodeEastMax_y == 0) { yMWPCEast = cathodeEast[0]*posPdc2[0] + cathodeEast[1]*posPdc2[1]; yMWPCEastSum = cathodeEast[0] + cathodeEast[0]; } else if (intCathodeEastMax_y == 15) { yMWPCEast = cathodeEast[14]*posPdc2[14] + cathodeEast[15]*posPdc2[15]; yMWPCEastSum = cathodeEast[14] + cathodeEast[15]; } else { int n = intCathodeEastMax_y; yMWPCEast = cathodeEast[n-1]*posPdc2[n-1] + cathodeEast[n]*posPdc2[n] + cathodeEast[n+1]*posPdc2[n+1]; yMWPCEastSum = cathodeEast[n-1] + cathodeEast[n] + cathodeEast[n+1]; } } if (yMWPCEastSum > 0.) { yMWPCEast = yMWPCEast / yMWPCEastSum; } else { yMWPCEast = -100.; posError = 1; } // West x double xMWPCWest = 0.; double xMWPCWestSum = 0.; if (mwpcHitWest) { if (intCathodeWestMax_x == 16) { xMWPCWest = cathodeWest[16]*posPadc[16] + cathodeWest[17]*posPadc[17]; xMWPCWestSum = cathodeWest[16] + cathodeWest[17]; } else if (intCathodeWestMax_x == 31) { xMWPCWest = cathodeWest[30]*posPadc[30] + cathodeWest[31]*posPadc[31]; xMWPCWestSum = cathodeWest[30] + cathodeWest[31]; } else { int n = intCathodeWestMax_x; xMWPCWest = cathodeWest[n-1]*posPadc[n-1] + cathodeWest[n]*posPadc[n] + cathodeWest[n+1]*posPadc[n+1]; xMWPCWestSum = cathodeWest[n-1] + cathodeWest[n] + cathodeWest[n+1]; } } if (xMWPCWestSum > 0.) { xMWPCWest = xMWPCWest / xMWPCWestSum; } else { xMWPCWest = -100.; posError = 1; } // West y double yMWPCWest = 0.; double yMWPCWestSum = 0.; if (mwpcHitWest) { if (intCathodeWestMax_y == 0) { yMWPCWest = cathodeWest[0]*posPadc[0] + cathodeWest[1]*posPadc[1]; yMWPCWestSum = cathodeWest[0] + cathodeWest[1]; } else if (intCathodeWestMax_x == 15) { yMWPCWest = cathodeWest[14]*posPadc[14] + cathodeWest[15]*posPadc[15]; yMWPCWestSum = cathodeWest[14] + cathodeWest[15]; } else { int n = intCathodeWestMax_y; yMWPCWest = cathodeWest[n-1]*posPadc[n-1] + cathodeWest[n]*posPadc[n] + cathodeWest[n+1]*posPadc[n+1]; yMWPCWestSum = cathodeWest[n-1] + cathodeWest[n] + cathodeWest[n+1]; } } if (yMWPCWestSum > 0.) { yMWPCWest = yMWPCWest / yMWPCWestSum; } else { yMWPCWest = -100.; posError = 1; } */ /* Swank's addition to the UK PA. (2 of 2) this seems like a good spot since its around the position calculation. */ //changing the length 32 double array to length 16 float array. using variables defined in WCR. for(int j = 0; j<16; j++) { WCR->cathex[j]=(float)cathodeEast[16+j]; WCR->cathey[j]=(float)cathodeEast[j]; WCR->cathwx[j]=(float)cathodeWest[16+j]; WCR->cathwy[j]=(float)cathodWest[j]; } xeRC=WCR->ResponseType(WCR->cathex); //response class x co-ordinate, East. yeRC=WCR->ResponseType(WCR->cathey); //response class y co-ordinate, East. xwRC=WCR->ResponseType(WCR->cathwx); //response class x co-ordinate, West. ywRC=WCR->ResponseType(WCR->cathwy); //response class y co-ordinate, West. /* End of swank's addtion (2 of 2) */ double xMWPCEast = 0.; double yMWPCEast = 0.; double xMWPCWest = 0.; double yMWPCWest = 0.; double xMWPCEastSum = 0.; double yMWPCEastSum = 0.; double xMWPCWestSum = 0.; double yMWPCWestSum = 0.; for (int j=0; j<16; j++) { if (cathodeEast[j+16] > 100.) { xMWPCEast += cathodeEast[j+16]*posPdc2[j+16]; xMWPCEastSum += cathodeEast[j+16]; } if (cathodeEast[j] > 100.) { yMWPCEast += cathodeEast[j]*posPdc2[j]; yMWPCEastSum += cathodeEast[j]; } if (cathodeWest[j+16] > 100.) { xMWPCWest += cathodeWest[j+16]*posPadc[j+16]; xMWPCWestSum += cathodeWest[j+16]; } if (cathodeWest[j] > 100.) { yMWPCWest += cathodeWest[j]*posPadc[j]; yMWPCWestSum += cathodeWest[j]; } } if (xMWPCEastSum > 0.) xMWPCEast = xMWPCEast / xMWPCEastSum; if (yMWPCEastSum > 0.) yMWPCEast = yMWPCEast / yMWPCEastSum; if (xMWPCWestSum > 0.) xMWPCWest = xMWPCWest / xMWPCWestSum; if (yMWPCWestSum > 0.) yMWPCWest = yMWPCWest / yMWPCWestSum; if (mwpcHitEast && xMWPCEastSum > 0.) xE = xMWPCEast * positionProjection; if (mwpcHitEast && yMWPCEastSum > 0.) yE = yMWPCEast * positionProjection; if (mwpcHitWest && xMWPCWestSum > 0.) xW = xMWPCWest * positionProjection; if (mwpcHitWest && yMWPCWestSum > 0.) yW = yMWPCWest * positionProjection; // Pass timing information to next root file timeE = Clk0*scalerCountsToTime; timeW = Clk1*scalerCountsToTime; timeE_BB = Clk2*scalerCountsToTime; timeW_BB = Clk3*scalerCountsToTime; UBtime = S83028*scalerCountsToTime; UBtime_BB = S8200*scalerCountsToTime; twoFoldE = Tdc016; twoFoldW = Tdc017; } Tout->Fill(); } // Write output ntuple fileOut->Write(); fileOut->Close(); return 0; }
void ReadPatMuWT(){ gROOT->SetStyle("Plain"); gStyle->SetPalette(1); gStyle->SetFrameBorderMode(0); gStyle->SetFrameFillColor(0); gStyle->SetCanvasColor(0); gStyle->SetTitleFillColor(0); gStyle->SetStatColor(0); gStyle->SetPadBorderSize(0); gStyle->SetCanvasBorderSize(0); gStyle->SetOptTitle(0); // at least most of the time gStyle->SetOptStat(1); // most of the time, sometimes "nemriou" might be useful to display name, //number of entries, mean, rms, integral, overflow and underflow gStyle->SetOptFit(1); // set to 1 only if you want to display fit results Double_t massMu=0.105658; TFile *infile; TTree *SingleWTPATMuonTree; char fileName[100]; //boosted sample //sprintf(fileName,"../Upsilon1S_OniaTree_All02Feb.root"); //un boosted sample sprintf(fileName,"test_Coll_Unboosted.root"); cout<<" ===================================================================== "<<endl; cout<<" opening root file : "<<fileName<<endl; infile=new TFile(fileName,"R"); SingleWTPATMuonTree=(TTree*)infile->Get("SingleWTPATMuonTree"); //Declaration of leaves types Int_t eventNbWTPAT; Int_t runNbWTPAT; Int_t lumiBlockWTPAT; Int_t rbinWTPAT; Int_t PAT_vertexNbEv; Double_t PAT_vertexTrkEv; Bool_t PAT_isVtxFakeEv; Double_t PAT_vertexXEv; Double_t PAT_vertexYEv; Double_t PAT_vertexZEv; Double_t PAT_vertexRhoEv; Int_t PAT_eventTrigger1; Int_t PAT_eventTrigger2; Int_t PAT_eventTrigger3; Int_t PAT_eventTrigger4; Int_t PAT_eventTrigger5; Int_t PAT_eventTrigger6; Int_t PAT_GenParNo; Int_t PAT_GenParSize; Double_t PAT_GenvertexXEv; Double_t PAT_GenvertexYEv; Double_t PAT_GenvertexZEv; Double_t PAT_GenParPx[10]; Double_t PAT_GenParPy[10]; Double_t PAT_GenParPz[10]; Double_t PAT_GenParPt[10]; Double_t PAT_GenParEta[10]; Double_t PAT_GenParPhi[10]; Double_t PAT_GenParRap[10]; Double_t PAT_GenParCharge[10]; Double_t PAT_GenParId[10]; Double_t PAT_GenParStatus[10]; Double_t PAT_GenParMomId[10]; Double_t PAT_GenParMomStatus[10]; Int_t WTPATMuSize; Double_t WTPATMuPx[11]; Double_t WTPATMuPy[11]; Double_t WTPATMuPz[11]; Double_t WTPATMuPt[11]; Double_t WTPATMuEta[11]; Double_t WTPATMuPhi[11]; Double_t WTPATMuCharge[11]; Double_t WTPATMu_found[11]; Double_t WTPATMu_nchi2In[11]; Double_t WTPATMu_arbitrated[11]; Double_t WTPATMu_stationTight[11]; Double_t WTPATMu_trackerLayers[11]; Double_t WTPATMu_pixeLayers[11]; Double_t WTPATMu_dxy[11]; Double_t WTPATMu_dz[11]; Double_t WTPATMu_nValidMuHits[11]; Double_t WTPATMu_nchi2Gl[11]; Int_t WTPATMu_Trigger1[11]; Int_t WTPATMu_Trigger2[11]; Int_t WTPATMu_Trigger3[11]; Int_t WTPATMu_Trigger4[11]; Int_t WTPATMu_Trigger5[11]; Int_t WTPATMu_Trigger6[11]; Int_t WTPATMu_Trigger7[11]; Int_t WTPATMu_Trigger8[11]; Int_t WTPATMu_Trigger9[11]; Int_t WTPATMu_Trigger10[11]; Int_t WTPATMu_Trigger11[11]; Int_t WTPATMu_Trigger12[11]; Int_t WTPATMu_global[11]; Int_t WTPATMu_tracker[11]; Int_t WTPATMu_sta[11]; Int_t WTPATMu_sta_noglb[11]; // Set branch addresses. SingleWTPATMuonTree->SetBranchAddress("eventNbWTPAT",&eventNbWTPAT); SingleWTPATMuonTree->SetBranchAddress("runNbWTPAT",&runNbWTPAT); SingleWTPATMuonTree->SetBranchAddress("lumiBlockWTPAT",&lumiBlockWTPAT); SingleWTPATMuonTree->SetBranchAddress("rbinWTPAT",&rbinWTPAT); SingleWTPATMuonTree->SetBranchAddress("PAT_vertexNbEv",&PAT_vertexNbEv); SingleWTPATMuonTree->SetBranchAddress("PAT_vertexTrkEv",&PAT_vertexTrkEv); SingleWTPATMuonTree->SetBranchAddress("PAT_isVtxFakeEv",&PAT_isVtxFakeEv); SingleWTPATMuonTree->SetBranchAddress("PAT_vertexXEv",&PAT_vertexXEv); SingleWTPATMuonTree->SetBranchAddress("PAT_vertexYEv",&PAT_vertexYEv); SingleWTPATMuonTree->SetBranchAddress("PAT_vertexZEv",&PAT_vertexZEv); SingleWTPATMuonTree->SetBranchAddress("PAT_vertexRhoEv",&PAT_vertexRhoEv); SingleWTPATMuonTree->SetBranchAddress("PAT_eventTrigger1",&PAT_eventTrigger1); SingleWTPATMuonTree->SetBranchAddress("PAT_eventTrigger2",&PAT_eventTrigger2); SingleWTPATMuonTree->SetBranchAddress("PAT_eventTrigger3",&PAT_eventTrigger3); SingleWTPATMuonTree->SetBranchAddress("PAT_eventTrigger4",&PAT_eventTrigger4); SingleWTPATMuonTree->SetBranchAddress("PAT_eventTrigger5",&PAT_eventTrigger5); SingleWTPATMuonTree->SetBranchAddress("PAT_eventTrigger6",&PAT_eventTrigger6); SingleWTPATMuonTree->SetBranchAddress("PAT_GenParNo",&PAT_GenParNo); SingleWTPATMuonTree->SetBranchAddress("PAT_GenParSize",&PAT_GenParSize); SingleWTPATMuonTree->SetBranchAddress("PAT_GenvertexXEv",&PAT_GenvertexXEv); SingleWTPATMuonTree->SetBranchAddress("PAT_GenvertexYEv",&PAT_GenvertexYEv); SingleWTPATMuonTree->SetBranchAddress("PAT_GenvertexZEv",&PAT_GenvertexZEv); SingleWTPATMuonTree->SetBranchAddress("PAT_GenParPx",PAT_GenParPx); SingleWTPATMuonTree->SetBranchAddress("PAT_GenParPy",PAT_GenParPy); SingleWTPATMuonTree->SetBranchAddress("PAT_GenParPz",PAT_GenParPz); SingleWTPATMuonTree->SetBranchAddress("PAT_GenParPt",PAT_GenParPt); SingleWTPATMuonTree->SetBranchAddress("PAT_GenParEta",PAT_GenParEta); SingleWTPATMuonTree->SetBranchAddress("PAT_GenParPhi",PAT_GenParPhi); SingleWTPATMuonTree->SetBranchAddress("PAT_GenParRap",PAT_GenParRap); SingleWTPATMuonTree->SetBranchAddress("PAT_GenParCharge",PAT_GenParCharge); SingleWTPATMuonTree->SetBranchAddress("PAT_GenParId",PAT_GenParId); SingleWTPATMuonTree->SetBranchAddress("PAT_GenParStatus",PAT_GenParStatus); SingleWTPATMuonTree->SetBranchAddress("PAT_GenParMomId",PAT_GenParMomId); SingleWTPATMuonTree->SetBranchAddress("PAT_GenParMomStatus",PAT_GenParMomStatus); SingleWTPATMuonTree->SetBranchAddress("WTPATMuSize",&WTPATMuSize); SingleWTPATMuonTree->SetBranchAddress("WTPATMuPx",WTPATMuPx); SingleWTPATMuonTree->SetBranchAddress("WTPATMuPy",WTPATMuPy); SingleWTPATMuonTree->SetBranchAddress("WTPATMuPz",WTPATMuPz); SingleWTPATMuonTree->SetBranchAddress("WTPATMuPt",WTPATMuPt); SingleWTPATMuonTree->SetBranchAddress("WTPATMuEta",WTPATMuEta); SingleWTPATMuonTree->SetBranchAddress("WTPATMuPhi",WTPATMuPhi); SingleWTPATMuonTree->SetBranchAddress("WTPATMuCharge",WTPATMuCharge); SingleWTPATMuonTree->SetBranchAddress("WTPATMu_found",WTPATMu_found); SingleWTPATMuonTree->SetBranchAddress("WTPATMu_nchi2In",WTPATMu_nchi2In); SingleWTPATMuonTree->SetBranchAddress("WTPATMu_arbitrated",WTPATMu_arbitrated); SingleWTPATMuonTree->SetBranchAddress("WTPATMu_stationTight",WTPATMu_stationTight); SingleWTPATMuonTree->SetBranchAddress("WTPATMu_trackerLayers",WTPATMu_trackerLayers); SingleWTPATMuonTree->SetBranchAddress("WTPATMu_pixeLayers",WTPATMu_pixeLayers); SingleWTPATMuonTree->SetBranchAddress("WTPATMu_dxy",WTPATMu_dxy); SingleWTPATMuonTree->SetBranchAddress("WTPATMu_dz",WTPATMu_dz); SingleWTPATMuonTree->SetBranchAddress("WTPATMu_nValidMuHits",WTPATMu_nValidMuHits); SingleWTPATMuonTree->SetBranchAddress("WTPATMu_nchi2Gl",WTPATMu_nchi2Gl); SingleWTPATMuonTree->SetBranchAddress("WTPATMu_Trigger1",WTPATMu_Trigger1); SingleWTPATMuonTree->SetBranchAddress("WTPATMu_Trigger2",WTPATMu_Trigger2); SingleWTPATMuonTree->SetBranchAddress("WTPATMu_Trigger3",WTPATMu_Trigger3); SingleWTPATMuonTree->SetBranchAddress("WTPATMu_Trigger4",WTPATMu_Trigger4); SingleWTPATMuonTree->SetBranchAddress("WTPATMu_Trigger5",WTPATMu_Trigger5); SingleWTPATMuonTree->SetBranchAddress("WTPATMu_Trigger6",WTPATMu_Trigger6); SingleWTPATMuonTree->SetBranchAddress("WTPATMu_Trigger7",WTPATMu_Trigger7); SingleWTPATMuonTree->SetBranchAddress("WTPATMu_Trigger8",WTPATMu_Trigger8); SingleWTPATMuonTree->SetBranchAddress("WTPATMu_Trigger9",WTPATMu_Trigger9); SingleWTPATMuonTree->SetBranchAddress("WTPATMu_Trigger10",WTPATMu_Trigger10); SingleWTPATMuonTree->SetBranchAddress("WTPATMu_Trigger11",WTPATMu_Trigger11); SingleWTPATMuonTree->SetBranchAddress("WTPATMu_Trigger12",WTPATMu_Trigger12); SingleWTPATMuonTree->SetBranchAddress("WTPATMu_global",WTPATMu_global); SingleWTPATMuonTree->SetBranchAddress("WTPATMu_tracker",WTPATMu_tracker); SingleWTPATMuonTree->SetBranchAddress("WTPATMu_sta",WTPATMu_sta); SingleWTPATMuonTree->SetBranchAddress("WTPATMu_sta_noglb",WTPATMu_sta_noglb); TH1D *muPt = new TH1D("muPt","muPt", 100,0,10.0); muPt->Sumw2(); TH1D *muEta = new TH1D("muEta","muEta", 100,-3.0,3.0); muEta->Sumw2(); TH1D *muPtWT = new TH1D("muPtWT","muPtWT", 100,0,10.0); muPtWT->Sumw2(); TH1D *muEtaWT = new TH1D("muEtaWT","muEtaWT", 100,-3.0,3.0); muEtaWT->Sumw2(); TH1D *muPhi = new TH1D("muPhi","muPhi", 100,-5.0,5.0); muPhi->Sumw2(); TH1D *muDxy = new TH1D("muDxy","muDxy", 100,-30.0,30.0); TH1D *muDz = new TH1D("muDz","muDz", 100,-50.0,50.0); TH1D *VtxX = new TH1D("VtxX","VtxX", 100,-30.0,30.0); TH1D *VtxY = new TH1D("VtxY","VtxY", 100,-30.0,30.0); TH1D *VtxZ = new TH1D("VtxZ","VtxZ", 100,-50.0,50.0); TH1D *genmuPt = new TH1D("genmuPt","genmuPt", 100,0,10.0); genmuPt->Sumw2(); TH1D *genmuEta = new TH1D("genmuEta","genmuEta", 100,-3.0,3.0); genmuEta->Sumw2(); TH1D *genmuPhi = new TH1D("genmuPhi","genmuPhi", 100,-5.0,5.0); genmuPhi->Sumw2(); Long64_t nentries = SingleWTPATMuonTree->GetEntries(); for (Long64_t i=0; i<nentries;i++) { SingleWTPATMuonTree->GetEntry(i); if(i%25000==0){cout<<i<<endl;} VtxX->Fill(PAT_vertexXEv); VtxY->Fill(PAT_vertexYEv); VtxZ->Fill(PAT_vertexZEv); if(PAT_GenParSize>0){ for (Int_t genpar1=0; genpar1<PAT_GenParSize;genpar1++){ int genmuIn=0; if(TMath::Abs(PAT_GenParId[genpar1])==13 && IsAccept(PAT_GenParPt[genpar1], PAT_GenParEta[genpar1]) ){genmuIn=1;}else{genmuIn=0;} if(TMath::Abs(PAT_GenParId[genpar1])==13 && genmuIn==1 ){ genmuPt->Fill(PAT_GenParPt[genpar1]); genmuEta->Fill(PAT_GenParEta[genpar1]); genmuPhi->Fill(PAT_GenParPhi[genpar1]); } } }//gen par size >0 if(WTPATMuSize>0){ //cout<<" PAT mu size "<<WTPATMuSize<<endl; for (Int_t patmu1=0; patmu1<WTPATMuSize;patmu1++){ //cout<<"PatMu Eta: "<<WTPATMuEta[patmu1]<<endl; int patmuPass=0; int patmuIn=0; if( WTPATMu_trackerLayers[patmu1] > 5.0 && TMath::Abs(WTPATMu_nchi2In[patmu1]) < 1.8 && TMath::Abs(WTPATMu_dxy[patmu1]) < 3.0 && TMath::Abs(WTPATMu_dz[patmu1]) < 30.0 && WTPATMu_arbitrated[patmu1]==1 && WTPATMu_stationTight[patmu1]==1 && WTPATMu_tracker[patmu1]==1 ){patmuPass=1;}else{patmuPass=0;} if(IsAccept(WTPATMuPt[patmu1],WTPATMuEta[patmu1])){patmuIn=1;}else{patmuIn=0;} if( WTPATMu_tracker[patmu1]==1){ muDxy->Fill(WTPATMu_dxy[patmu1]); muDz->Fill(WTPATMu_dz[patmu1]); } //patmuPass=1; //patmuIn=1; if(patmuPass==1 && patmuIn==1 ){ muPt->Fill(WTPATMuPt[patmu1]); muEta->Fill(WTPATMuEta[patmu1]); muPhi->Fill(WTPATMuPhi[patmu1]); } if(patmuPass==1 && patmuIn==1 && WTPATMu_Trigger1[patmu1]==1){ //if(patmuPass==1 && patmuIn==1 && PAT_eventTrigger4==1){ muPtWT->Fill(WTPATMuPt[patmu1]); muEtaWT->Fill(WTPATMuEta[patmu1]); } //for (Int_t patmu2=patmu1+1; patmu2<WTPATMuSize;patmu2++){ //} } } } //TEfficeincy *t=new TEfficiency(muEta,genmuEta); //new TCanvas; //t->Draw(); //TH1D *hratio1 = (TH1D*)h2->Clone("ratio") new TCanvas; genmuPt->Draw(); gPad->SaveAs("genmuPt.png"); new TCanvas; genmuEta->Draw(); gPad->SaveAs("genmuEta.png"); new TCanvas; genmuPhi->Draw(); gPad->SaveAs("genmuPhi.png"); new TCanvas; muPt->Draw(); gPad->SaveAs("muPt.png"); new TCanvas; muEta->Draw(); gPad->SaveAs("muEta.png"); new TCanvas; muPhi->Draw(); gPad->SaveAs("muPhi.png"); new TCanvas; muPtWT->Draw(); gPad->SaveAs("muPtWT.png"); new TCanvas; muEtaWT->Draw(); gPad->SaveAs("muEtaWT.png"); TH1D* RatioEta=(TH1D*)muEta->Clone("ratioEta"); RatioEta->Divide(genmuEta); new TCanvas; RatioEta->Draw("E"); TH1D* RatioPt=(TH1D*)muPt->Clone("ratioPt"); RatioPt->Divide(genmuPt); new TCanvas; RatioPt->Draw("E"); TH1D* RatioEtaT=(TH1D*)muEtaWT->Clone("ratioEtaT"); RatioEtaT->Divide(muEta); new TCanvas; RatioEtaT->Draw("E"); TH1D* RatioPtT=(TH1D*)muPtWT->Clone("ratioPtT"); RatioPtT->Divide(muPt); RatioPtT->GetYaxis()->SetRangeUser(0.0,1.0); new TCanvas; RatioPtT->Draw("E"); /* TEfficiency* ptEff = 0; ptEff = new TEfficiency(*muPtWT,*muPt); new TCanvas; //ptEff->GetYaxis()->SetRangeUser(0.0,1.0); ptEff->Draw("AP"); RatioPtT->Draw("same"); TEfficiency* EtaEff = 0; EtaEff = new TEfficiency(*muEtaWT,*muEta); new TCanvas; EtaEff->Draw("AP"); */ //TGraphAsymmErrors::TGraphAsymmErrors(const TH1* pass,const TH1* total,Option_t* opt) TGraphAsymmErrors *GrfTrgPt=0; GrfTrgPt=new TGraphAsymmErrors(muPtWT,muPt); GrfTrgPt->GetYaxis()->SetRangeUser(0.0,1.0); GrfTrgPt->GetXaxis()->SetTitle("#mu p_{T}"); new TCanvas; GrfTrgPt->Draw("AP"); gPad->SaveAs("TrgEffPt.png"); TGraphAsymmErrors *GrfTrgEta=0; GrfTrgEta=new TGraphAsymmErrors(muEtaWT,muEta); GrfTrgEta->GetYaxis()->SetRangeUser(0.0,1.0); GrfTrgEta->GetXaxis()->SetTitle("#eta^{#mu}"); new TCanvas; GrfTrgEta->Draw("AP"); gPad->SaveAs("TrgEffEta.png"); return; TCanvas *CanVtxX=new TCanvas; CanVtxX->SetLogy(); VtxX->Draw(); gPad->SaveAs("VtxX.png"); TCanvas *CanVtxY=new TCanvas; CanVtxY->SetLogy(); VtxY->Draw(); gPad->SaveAs("VtxY.png"); TCanvas *CanVtxZ=new TCanvas; CanVtxZ->SetLogy(); VtxZ->Draw(); gPad->SaveAs("VtxZ.png"); TCanvas *CanDxy=new TCanvas; CanDxy->SetLogy(); muDxy->Draw(); gPad->SaveAs("muDxy.png"); TCanvas *CanDz=new TCanvas; CanDz->SetLogy(); muDz->Draw(); gPad->SaveAs("muDz.png"); }
//------------------------------------------------------------------------------ // GetBoxPopulation //------------------------------------------------------------------------------ void GetBoxPopulation(TString sample, float* box1, float* box2, float& region1_box1_yield, float& region1_box2_yield, float& region2_box1_yield, float& region2_box2_yield) { TFile* file = new TFile(_inputdir + sample + ".root", "read"); TTree* tree = (TTree*)file->Get("latino"); float eventW; float mva; float nbjet; float njet; tree->SetBranchAddress("eventW", &eventW); tree->SetBranchAddress("mva_" + _signal, &mva); tree->SetBranchAddress("nbjet20loose", &nbjet); tree->SetBranchAddress("njet", &njet); region1_box1_yield = 0; region1_box2_yield = 0; region2_box1_yield = 0; region2_box2_yield = 0; Long64_t nentries = tree->GetEntries(); for (Long64_t ievt=0; ievt<nentries; ievt++) { tree->GetEntry(ievt); bool reject_region1 = (mva < _cut-0.2 || mva > _cut); bool reject_region2 = (mva < _cut-0.4 || mva > _cut-0.2); bool reject_box1 = ((box1[njmin] > -1 && njet < box1[njmin]) || (box1[njmax] > -1 && njet > box1[njmax]) || (box1[nbmin] > -1 && nbjet < box1[nbmin]) || (box1[nbmax] > -1 && nbjet > box1[nbmax])); bool reject_box2 = ((box2[njmin] > -1 && njet < box2[njmin]) || (box2[njmax] > -1 && njet > box2[njmax]) || (box2[nbmin] > -1 && nbjet < box2[nbmin]) || (box2[nbmax] > -1 && nbjet > box2[nbmax])); if (sample != "01_Data"){ if (!reject_region1) region1_box1_yield += eventW; if (!reject_region2) region2_box1_yield += eventW; } else{ if (!reject_region1 && !reject_box1) region1_box1_yield += eventW; if (!reject_region1 && !reject_box2) region1_box2_yield += eventW; if (!reject_region2 && !reject_box1) region2_box1_yield += eventW; if (!reject_region2 && !reject_box2) region2_box2_yield += eventW; } } if(sample != "01_Data") cout << sample << " -- " << region1_box1_yield << " -- " << region2_box1_yield << endl; }
//------------------------------------------------------------------------------ // GetPdfQcdSyst //------------------------------------------------------------------------------ void GetPdfQcdSyst(TString sample) { _thunc[0] = 0; _thunc[1] = 0; _thunc[2] = 0; _thunc[3] = 0; _thunc[4] = 0; _thunc[5] = 0; TFile* file = new TFile(_inputdir + sample + ".root", "read"); TTree* tree = (TTree*)file->Get("latino"); float mva; float njet; vector<float> *LHEweight = 0; tree->SetBranchAddress("mva_" + _signal, &mva); tree->SetBranchAddress("njet", &njet); tree->SetBranchAddress("LHEweight", &LHEweight ); TH1D* h_pdfsum_gen = (TH1D*)file->Get("h_pdfsum"); TH1D* h_qcdsum_gen = (TH1D*)file->Get("h_qcdsum"); TH1D* h_pdfsum_rec = (TH1D*)h_pdfsum_gen->Clone("h_pdfsum_rec"); TH1D* h_qcdsum_rec = (TH1D*)h_pdfsum_gen->Clone("h_qcdsum_rec"); h_pdfsum_rec->Reset(); h_qcdsum_rec->Reset(); int nbinpdf = h_pdfsum_gen->GetNbinsX(); int nbinqcd = h_qcdsum_gen->GetNbinsX(); // Loop over the tree //---------------------------------------------------------------------------- Long64_t nentries = tree->GetEntries(); for (Long64_t i=0; i<nentries; i++) { tree->GetEntry(i); if (mva < _cut) continue; if (njet < 1) continue; for (int a=0; a<nbinpdf; a++) h_pdfsum_rec->Fill(a, LHEweight->at(a+9)); for (int a=0; a<nbinqcd; a++) h_qcdsum_rec->Fill(a, LHEweight->at(a)); } // Produce the QCD uncertainties //---------------------------------------------------------------------------- float qcdratio_gen_up = h_qcdsum_gen->GetBinContent(9) / h_qcdsum_gen->GetBinContent(1); float qcdratio_gen_down = h_qcdsum_gen->GetBinContent(5) / h_qcdsum_gen->GetBinContent(1); float qcdratio_rec_up = h_qcdsum_rec->GetBinContent(9) / h_qcdsum_rec->GetBinContent(1); float qcdratio_rec_down = h_qcdsum_rec->GetBinContent(5) / h_qcdsum_rec->GetBinContent(1); // Produce the PDF uncertainties //---------------------------------------------------------------------------- float pdf_gen_mean = h_pdfsum_gen->Integral() / nbinpdf; float pdf_rec_mean = h_pdfsum_rec->Integral() / nbinpdf; float pdf_gen_mean_sq = 0; float pdf_rec_mean_sq = 0; for (int a=1; a<=nbinpdf; a++) { pdf_gen_mean_sq += (pow(h_pdfsum_gen->GetBinContent(a), 2) / nbinpdf); pdf_rec_mean_sq += (pow(h_pdfsum_rec->GetBinContent(a), 2) / nbinpdf); } float pdf_gen_sd = sqrt(pdf_gen_mean_sq - pow(pdf_gen_mean, 2)); float pdf_rec_sd = sqrt(pdf_rec_mean_sq - pow(pdf_rec_mean, 2)); float pdf_gen_ratio = 1 + (pdf_gen_sd / pdf_gen_mean); float pdf_rec_ratio = 1 + (pdf_rec_sd / pdf_rec_mean); // Print the uncertainties //---------------------------------------------------------------------------- //printf("\n %s\n", sample.Data()); //printf("---------------------------------------\n"); //printf(" QCD up -- xs = %5.3f -- acc = %5.3f\n", qcdratio_gen_up, qcdratio_rec_up / qcdratio_gen_up); //printf(" QCD down -- xs = %5.3f -- acc = %5.3f\n", qcdratio_gen_down, qcdratio_rec_down / qcdratio_gen_down); //printf(" PDF -- xs = %5.3f -- acc = %5.3f\n", pdf_gen_ratio, pdf_rec_ratio / pdf_gen_ratio); _thunc[0] = qcdratio_gen_up ; _thunc[1] = qcdratio_rec_up/qcdratio_gen_up ; _thunc[2] = qcdratio_gen_down ; _thunc[3] = qcdratio_rec_down/qcdratio_gen_down; _thunc[4] = pdf_gen_ratio ; _thunc[5] = pdf_rec_ratio/pdf_gen_ratio ; }
void sqrtBinsSameSign(){ //OPTIONS AND CUTS______________ bool useBlueBeam = true; bool useYellowBeam = true; bool randomizeSpin = false; bool fullEta = true; double PI = 3.14159265359; cout << "\n"; if (useBlueBeam && useYellowBeam){cout << "using both beams-----" << endl;} if (useBlueBeam && !useYellowBeam){cout << "using blue beam------" << endl;} if (!useBlueBeam && useYellowBeam){cout << "using yellow beam----" << endl;} cout << "\n"; if (randomizeSpin){cout << "randomizing spin-----" << endl;} //______________________________ //LOAD LIBS_____________________ cout << "\n"; gROOT->Macro("StRoot/LoadLibs.C"); gSystem->Load("sameSignPair"); cout << " loading of pionPair library done" << endl; //______________________________ //SET UP INPUT FILE_____________ TFile* infile = new TFile("/star/u/klandry/ucladisk/2012IFF/schedOut_samesign_4_14/allSameSign_4_14.root"); string outFileName = "./resultsNew_4_22/sameSignFrom4_25Fullrange.root"; //______________________________ //SET UP TREE TO RECEIVE INPUT__ sameSignPair* pair1 = new sameSignPair(); TTree* pairTree = infile->Get("sameSignTree"); pairTree->SetBranchAddress("sameSignPair", &pair1); //______________________________ //SET UP HISTOGRAMS_____________ //event variable histograms /* TH1D* hInvarM = new TH1D("invarM","invarM",80,0,2); TH1D* hEtaTot = new TH1D("etaTot","etaTot",60,-1.5,1.5); TH1D* hPhiR = new TH1D("hPhiR","hPhiR",60,-4,4); TH1D* hPhiS = new TH1D("hPhiS","hPhiS",60,-4,4); TH1D* hPhiSR = new TH1D("hPhiSR","hPhiSR",60,-4,4); TH1D* hTheta = new TH1D("hTheta","hTheta",30,-0.85,4); TH1D* hCosTheta = new TH1D("hCosTheta","hCosTheta",80,-1,1); TH1D* hZ = new TH1D("hZ","hZ",80,0,1); TH1D* hPtot = new TH1D("hPtot","hPtot",80,0,20); TH1D* hPtTOT = new TH1D("hPt","hPt",80,0,15); */ //histos for asym analysis double histMin = -PI; double histMax = PI; const int binNumber = 16; TH1D * hNumberUp = new TH1D("hNumberUp","hNumberUp",binNumber,histMin,histMax); TH1D * hNumberDown = new TH1D("hNumberDown","hNumberDown",binNumber,histMin,histMax); TH1D * hNumberUp_Pt[nPtBins]; TH1D * hNumberDown_Pt[nPtBins]; TH1D * hNumberUp_Mass[nMassBins]; TH1D * hNumberDown_Mass[nMassBins]; TH1D * hNumberUp_Eta[nEtaBins]; TH1D * hNumberDown_Eta[nEtaBins]; createFiveBins(hNumberUp_Pt,binNumber,histMin,histMax,"hNumUp_Ptbin_"); createFiveBins(hNumberDown_Pt,binNumber,histMin,histMax,"hNumDwn_Ptbin_"); createFiveBins(hNumberUp_Mass,binNumber,histMin,histMax,"hNumUp_Massbin_"); createFiveBins(hNumberDown_Mass,binNumber,histMin,histMax,"hNumDwn_Massbin_"); createFourBins(hNumberUp_Eta,binNumber,histMin,histMax,"hNumUp_Etabin_"); createFourBins(hNumberDown_Eta,binNumber,histMin,histMax,"hNumDwn_Etabin_"); TH1D* hAut_Pt[nPtBins]; TH1D* hAut_Mass[nMassBins]; TH1D* hAut_Eta[nEtaBins]; createFiveBins(hAut_Pt, binNumber, histMin, histMax, "hAut_Ptbin_"); createFiveBins(hAut_Mass, binNumber, histMin, histMax, "hAut_Massbin_"); createFourBins(hAut_Eta, binNumber, histMin, histMax, "hAut_Etabin_"); /* TH1D* polOfBinUp_Pt[nPtBins][binNumber]; TH1D* polOfBinDown_Pt[nPtBins][binNumber]; TH1D* polOfBinUp_Mass[nMassBins][binNumber]; TH1D* polOfBinDown_Mass[nMassBins][binNumber]; TH1D* polOfBinUp_Eta[nEtaBins][binNumber]; TH1D* polOfBinDown_Eta[nEtaBins][binNumber]; createPolHists(polOfBinUp_Pt, 25, 0, 1, "hPolOfBinUp_Ptbin_"); createPolHists(polOfBinDown_Pt, 25, 0, 1, "hPolOfBinDown_Ptbin_"); createPolHists(polOfBinUp_Mass, 25, 0, 1, "hPolOfBinUp_Massbin_"); createPolHists(polOfBinDown_Mass, 25, 0, 1, "hPolOfBinDown_Massbin_"); createPolHists(polOfBinUp_Eta, 25, 0, 1, "hPolOfBinUp_Etabin_"); createPolHists(polOfBinDown_Eta, 25, 0, 1, "hPolOfBinDown_Etabin_"); */ TH1D* polOfBin_Pt[nPtBins][binNumber]; TH1D* polOfBin_Mass[nMassBins][binNumber]; TH1D* polOfBin_Eta[nEtaBins][binNumber]; createPolHists(polOfBin_Pt, 25, 0, 1, "hPolOfBin_Ptbin_"); createPolHists(polOfBin_Mass, 25, 0, 1, "hPolOfBin_Massbin_"); createPolHistsEta(polOfBin_Eta, 25, 0, 1, "hPolOfBin_Etabin_"); //HISTOGRAMS TO HOLD PT MASS AND ETA VALES TH1D* hPt[nPtBins]; TH1D* hMass[nMassBins]; TH1D* hEta[nEtaBins]; createFiveBins(hPt, 500, 3.0, 50, "hPt_Ptbin_"); createFiveBins(hMass, 1000, 0.0, 100, "hMass_Massbin_"); createFourBins(hEta, 20, -1.4, 1.4, "hEta_Etabin_"); //TH1D * hDiff = new TH1D("hNumberSum","hNumberSum",binNumber,histMin,histMax); //TH1D * hAut = new TH1D("Aut","Aut",binNumber,histMin,histMax); //______________________________ //BEAM POLARIZATION_____________ ifstream polFile; polFile.open("/star/u/klandry/ucladisk/2012IFF/BeamPolarization2012.txt"); map<int, double> polarizationOfFill_Y; map<int, double> polErrOfFill_Y; map<int, double> polarizationOfFill_B; map<int, double> polErrOfFill_B; int fill; int beamE; int startT; string plusminus; double pAvrgBlue; double pErrAvrgBlue; double pInitialBlue; double pErrInitialBlue; double dPdTBlue; double dPdTErrBlue; double pAvrgYellow; double pErrAvrgYellow; double pInitialYellow; double pErrInitialYellow; double dPdTYellow; double dPdTErrYellow; string header; for (int i=0; i<19; i++){polFile >> header;} while (!polFile.eof()) { polFile >> fill; polFile >> beamE; polFile >> startT; polFile >> pAvrgBlue; polFile >> plusminus; polFile >> pErrAvrgBlue; polFile >> pInitialBlue; polFile >> plusminus; polFile >> pErrInitialBlue; polFile >> dPdTBlue; polFile >> plusminus; polFile >> dPdTErrBlue; polFile >> pAvrgYellow; polFile >> plusminus; polFile >> pErrAvrgYellow; polFile >> pInitialYellow; polFile >> plusminus; polFile >> pErrInitialYellow; polFile >> dPdTYellow; polFile >> plusminus; polFile >> dPdTErrYellow; polarizationOfFill_B[fill] = pAvrgBlue/100.; polErrOfFill_B[fill] = pErrAvrgBlue/100.; polarizationOfFill_Y[fill] = pAvrgYellow/100.; polErrOfFill_Y[fill] = pErrAvrgYellow/100.; } double avgPolOfBinUp[binNumber]; double polOfBinSumUp[binNumber]; double avgPerrorOfBinUp[binNumber]; double pErrorOfBinUp[binNumber]; double avgPolOfBinDown[binNumber]; double polOfBinSumDown[binNumber]; double avgPerrorOfBinDown[binNumber]; double pErrorOfBinDown[binNumber]; for (int i=0; i<binNumber; i++) { avgPolOfBinUp[i] = 0; polOfBinSumUp[i] = 0; avgPerrorOfBinUp[i] = 0; pErrorOfBinUp[i] = 0; avgPolOfBinDown[i] = 0; polOfBinSumDown[i] = 0; avgPerrorOfBinDown[i] = 0; pErrorOfBinDown[i] = 0; } //______________________________ //CUTS__________________________ double lowLimitPt = ptBinStart[0]; double hiLimitPt = ptBinEnd[4]; double lowLimitEta = etaBinStart[0]; double hiLimitEta = etaBinEnd[3]; double lowLimitMass = massBinStart[0]; double hiLimitMass = massBinEnd[4]; //hiLimitEta = 0; if (fullEta) { assert(hiLimitEta > 0); assert(lowLimitEta < 0); } cout << "Pt between " << lowLimitPt << " and " << hiLimitPt << endl; cout << "M between " << lowLimitMass << " and " << hiLimitMass << endl; cout << "Eta between " << lowLimitEta << " and " << hiLimitEta << endl; //______________________________ //* // ====================================================================== //============================================================================ //START ANALYSIS============================================================== //============================================================================ // ====================================================================== //* cout << "\n"; cout << "<----STARTING ANALYSIS---->" << endl; cout << "\n"; cout << pairTree->GetEntries() << " pairs to analyze" << endl; int blueFillNo; int yellowFillNo; int phiSRbin; TLorentzVector sum; TLorentzVector sumY; TLorentzVector sumB; //random number for randomizing spin. //set seed to zero to gaurenty unique numbers each time. TRandom3 r; r.SetSeed(0); int rand5 = 0; int rand6 = 0; int rand9 = 0; int rand10 = 0; int totalPairsFinal = 0; int blueD = 0; int blueU = 0; int yellowD = 0; int yellowU = 0; int pionStarNumber = 0; int test = 0; for (int iPair = pionStarNumber; iPair < pairTree->GetEntries(); iPair++) { if (iPair%10000 == 0) {cout << "processing pair number " << iPair << endl;} //if (iPair == pionStarNumber+10000){break;} pairTree->GetEntry(iPair); if (pair1->withinRadius(0.05, 0.3)) { bool triggerFired = false; bool fromKaon = false; bool passInitialCut_B = false; bool passInitialCut_Y = false; bool passDCAcut = false; StTriggerId trigId = pair1->triggerIds(); //JP0,JP1,JP2,AJP if (trigId.isTrigger(370601) || trigId.isTrigger(370611) || trigId.isTrigger(370621) || trigId.isTrigger(370641)) { triggerFired = true; } //BHT0VPD,BHT1VPD,BHT2BBC,BHT2 if (trigId.isTrigger(370501) || trigId.isTrigger(370511) || trigId.isTrigger(370522) || trigId.isTrigger(370531)) { triggerFired = true; } if (triggerFired) { blueFillNo = pair1->runInfo().beamFillNumber(1); //1 = blue beam yellowFillNo = pair1->runInfo().beamFillNumber(0); //0 = yellow beam sum = pair1->pion1LV() + pair1->pion2LV(); sumB = sum; //blue beam. //yellow beam must rotate around y axis by pi so the eta cut can be the same for both beams. sumY = sum; sumY.RotateY(PI); /* double dcaPlus = pair1->getPion1()->dca((pair1->getPion1()->vertexIndex())).mag(); double dcaMinus = pair1->getPion2()->dca((pair1->getPion2()->vertexIndex())).mag(); if (dcaPlus < 1 && dcaMinus < 1) { passDCAcut = true; } */ if (sumB.Pt() >= lowLimitPt && sumB.Pt() <= hiLimitPt && sumB.M() >= lowLimitMass && sumB.M() <= hiLimitMass && sumB.Eta() >= lowLimitEta && sumB.Eta() <= hiLimitEta) { passInitialCut_B = true; } if (sumY.Pt() >= lowLimitPt && sumY.Pt() <= hiLimitPt && sumY.M() >= lowLimitMass && sumY.M() <= hiLimitMass && sumY.Eta() >= lowLimitEta && sumY.Eta() <= hiLimitEta) { passInitialCut_Y = true; } if (passInitialCut_B && useBlueBeam) { //BLUE BEAM SPIN UP: spin bin 9 and 10 if (pair1->spinBit() == 9 || pair1->spinBit() == 10) { fillCorrectPtBin(hNumberUp_Pt, sumB, pair1->phiSR('b'), polOfBin_Pt, polarizationOfFill_B[blueFillNo],hPt); fillCorrectMassBin(hNumberUp_Mass, sumB, pair1->phiSR('b'), polOfBin_Mass, polarizationOfFill_B[blueFillNo],hMass); if(fullEta){fillCorrectEtaBin(hNumberUp_Eta, sumB, pair1->phiSR('b'), polOfBin_Eta, polarizationOfFill_B[blueFillNo],hEta);} } //BLUE BEAM SPIN DOWN: spin bin 5 and 6 if (pair1->spinBit() == 5 || pair1->spinBit() == 6) { fillCorrectPtBin(hNumberDown_Pt, sumB, pair1->phiSR('b'), polOfBin_Pt, polarizationOfFill_B[blueFillNo],hPt); fillCorrectMassBin(hNumberDown_Mass, sumB, pair1->phiSR('b'), polOfBin_Mass, polarizationOfFill_B[blueFillNo],hMass); if(fullEta){fillCorrectEtaBin(hNumberDown_Eta, sumB, pair1->phiSR('b'), polOfBin_Eta, polarizationOfFill_B[blueFillNo],hEta);} } }//done with blue beam if (passInitialCut_Y && useYellowBeam) { //YELLOW BEAM SPIN UP: spin bin 6 and 10 if (pair1->spinBit() == 6 || pair1->spinBit() == 10) { fillCorrectPtBin(hNumberUp_Pt, sumY, pair1->phiSR('y'), polOfBin_Pt, polarizationOfFill_Y[yellowFillNo],hPt); fillCorrectMassBin(hNumberUp_Mass, sumY, pair1->phiSR('y'), polOfBin_Mass, polarizationOfFill_Y[yellowFillNo],hMass); if(fullEta){fillCorrectEtaBin(hNumberUp_Eta, sumY, pair1->phiSR('y'), polOfBin_Eta, polarizationOfFill_Y[yellowFillNo],hEta);} } //YELLOW BEAM SPIN DOWN: spin bit 5 and 9 if (pair1->spinBit() == 5 || pair1->spinBit() == 9) { fillCorrectPtBin(hNumberDown_Pt, sumY, pair1->phiSR('y'), polOfBin_Pt, polarizationOfFill_Y[yellowFillNo],hPt); fillCorrectMassBin(hNumberDown_Mass, sumY, pair1->phiSR('y'), polOfBin_Mass, polarizationOfFill_Y[yellowFillNo],hMass); if(fullEta){fillCorrectEtaBin(hNumberDown_Eta, sumY, pair1->phiSR('y'), polOfBin_Eta, polarizationOfFill_Y[yellowFillNo],hEta);} } }//done with yellow beam }//end trigger check }//end radius check }//end pion tree loop //CALCULATE ASYMMETRY BIN BY BIN cout << "\n"; cout << "<----CALCULATING ASYMMETRY---->" << endl; cout << "\n"; double asymsPt[5]; double asymsMass[5]; double asymsEta[4]; double asymsPtE[5]; double asymsMassE[5]; double asymsEtaE[4]; cout << "\n"; cout << "\n"; cout << "\n \n calcing pt asym " << endl; calcAsym(hAut_Pt, hNumberUp_Pt, hNumberDown_Pt, polOfBin_Pt, asymsPt, asymsPtE); cout << "\n"; cout << "\n"; cout << "\n \n calcing mass asym " << endl; calcAsym(hAut_Mass, hNumberUp_Mass, hNumberDown_Mass, polOfBin_Mass, asymsMass, asymsMassE); cout << "\n"; cout << "\n"; if (fullEta) { cout << "\n \n calcing eta asym " << endl; calcAsymEta(hAut_Eta, hNumberUp_Eta, hNumberDown_Eta, polOfBin_Eta, asymsEta, asymsEtaE); } //PLOT ASYMMETRIES cout << "\n"; cout << "<----PLOTTING ASYMMETRIES---->" << endl; cout << "\n"; double ptPoints[5]; double ptPointsErr[5]; double massPoints[5]; double massPointsErr[5]; double etaPoints[5]; double etaPointsErr[5]; getPtPoints(hPt, ptPoints, ptPointsErr); getMassPoints(hMass, massPoints, massPointsErr); if(fullEta){getEtaPoints(hEta, etaPoints, etaPointsErr);} TCanvas* cAsymPt = new TCanvas(); TGraphErrors* gAsymPt = new TGraphErrors(nPtBins,ptPoints,asymsPt,ptPointsErr,asymsPtE); gAsymPt->Draw("AP"); TCanvas* cAsymMass = new TCanvas(); TGraphErrors* gAsymMass = new TGraphErrors(nMassBins,massPoints,asymsMass,massPointsErr,asymsMassE); gAsymMass->Draw("AP"); if (fullEta) { TCanvas* cAsymEta = new TCanvas(); TGraphErrors* gAsymEta = new TGraphErrors(nEtaBins,etaPoints,asymsEta,etaPointsErr,asymsEtaE); gAsymEta->Draw("AP"); } //DRAW HISTOGRAMS cout << "\n"; cout << "<----DRAWING HISTOGRAMS---->" << endl; cout << "\n"; TCanvas* cPt = new TCanvas("cPt","cPt",1200,600); TCanvas* cMass = new TCanvas("cMass","cMass",1200,600); if(fullEta){TCanvas* cEta = new TCanvas("cEta","cEta",800,600);} //drawAllBins(hPt, cPt); //drawAllBins(hMass, cMass); //polOfBin_Pt[3][8]->Draw(); drawFiveBins(hAut_Pt, cPt); drawFiveBins(hAut_Mass, cMass); if(fullEta){drawFourBins(hAut_Eta, cEta);} TFile* outFile = new TFile(outFileName.c_str(),"recreate"); writeFiveBins(hPt); writeFiveBins(hMass); writeFourBins(hEta); writeFiveBins(hAut_Pt); writeFiveBins(hAut_Mass); if(fullEta){writeFourBins(hAut_Eta);} gAsymPt->Write(); gAsymMass->Write(); if(fullEta){gAsymEta->Write();} /* cPt->SaveAs("./resultsNew_4_22/ptCanvasFullrangeLoEta.png"); cPt->SaveAs("./resultsNew_4_22/ptCanvasFullrangeLoEta.pdf"); cMass->SaveAs("./resultsNew_4_22/massCanvasFullrangeLoEta.png"); cMass->SaveAs("./resultsNew_4_22/massCanvasFullrangeLoEta.pdf"); if(fullEta) { cEta->SaveAs("./resultsNew_4_22/etaCanvasFullrangeHiEta.png"); cEta->SaveAs("./resultsNew_4_22/etaCanvasFullrangeHiEta.pdf"); } */ cout << "<----END---->" << endl; }
int main (int argc, char** argv) { std::string inputFolder = argv[1]; std::string outputFile = argv[2]; std::string leptonName = argv[3]; std::string inputFile = argv[4]; std::cout<<"file: "<<(inputFile).c_str()<<std::endl; TFile * fS = new TFile((inputFolder+leptonName+"/WWTree_"+inputFile+".root").c_str()); TTree * inputTree = (TTree *)fS->Get("otree"); int run; int event; int lumi; int njets; int nPV; int issignal; float pfMET; float pfMET_Phi; float l_pt; float l_eta; float l_phi; float l_e; float ungroomed_jet_pt; float ungroomed_jet_eta; float ungroomed_jet_phi; float ungroomed_jet_e; float jet_mass_pr; float jet_mass_so; float jet_tau2tau1; float v_pt; float v_eta; float v_phi; float v_mt; float mass_lvj_type0; int nBTagJet_medium; float jet2_pt; float jet2_btag; float jet3_pt; float jet3_btag; inputTree->SetBranchAddress("run", &run); inputTree->SetBranchAddress("event", &event); inputTree->SetBranchAddress("lumi", &lumi); inputTree->SetBranchAddress("njets", &njets); inputTree->SetBranchAddress("nPV", &nPV); inputTree->SetBranchAddress("issignal", &issignal); inputTree->SetBranchAddress("pfMET", &pfMET); inputTree->SetBranchAddress("pfMET_Phi", &pfMET_Phi); inputTree->SetBranchAddress("l_pt", &l_pt); inputTree->SetBranchAddress("l_eta", &l_eta); inputTree->SetBranchAddress("l_phi", &l_phi); inputTree->SetBranchAddress("l_e", &l_e); inputTree->SetBranchAddress("ungroomed_jet_pt", &ungroomed_jet_pt); inputTree->SetBranchAddress("ungroomed_jet_eta", &ungroomed_jet_eta); inputTree->SetBranchAddress("ungroomed_jet_phi", &ungroomed_jet_phi); inputTree->SetBranchAddress("ungroomed_jet_e", &ungroomed_jet_e); inputTree->SetBranchAddress("jet_mass_pr", &jet_mass_pr); inputTree->SetBranchAddress("jet_mass_so", &jet_mass_so); inputTree->SetBranchAddress("jet_tau2tau1", &jet_tau2tau1); inputTree->SetBranchAddress("v_pt", &v_pt); inputTree->SetBranchAddress("v_eta", &v_eta); inputTree->SetBranchAddress("v_phi", &v_phi); inputTree->SetBranchAddress("v_mt", &v_mt); inputTree->SetBranchAddress("mass_lvj_type2", &mass_lvj_type0); inputTree->SetBranchAddress("nBTagJet_medium", &nBTagJet_medium); inputTree->SetBranchAddress("jet2_pt", &jet2_pt); inputTree->SetBranchAddress("jet2_btag", &jet2_btag); inputTree->SetBranchAddress("jet3_pt", &jet3_pt); inputTree->SetBranchAddress("jet3_btag", &jet3_btag); //---------output tree---------------- TFile* outROOT = TFile::Open((std::string("output/output_synch_")+leptonName+std::string("/")+std::string("WWTree_")+outputFile+std::string(".root")).c_str(),"recreate"); outROOT->cd(); TTree* outTree = new TTree("otree", "otree"); outTree->SetDirectory(0); setOutputTreeSynch *WWTree = new setOutputTreeSynch(outTree); //---------start loop on events------------ for (Long64_t jentry=0; jentry<inputTree->GetEntries();jentry++) { inputTree->GetEntry(jentry); WWTree->initializeVariables(); //initialize all variables if(jentry % 1000 == 0) cout << "read entry: " << jentry << endl; WWTree->issignal = issignal; //save event variables WWTree->run = run; WWTree->event = event; WWTree->lumi = lumi; WWTree->njets = njets; WWTree->nPV = nPV; WWTree->l_pt = l_pt; WWTree->l_eta = l_eta; WWTree->l_phi = l_phi; WWTree->pfMET = pfMET; WWTree->pfMETPhi = pfMET_Phi; WWTree->W_pt = v_pt; WWTree->W_eta = v_eta; WWTree->W_phi = v_phi; WWTree->jet_pt = ungroomed_jet_pt; WWTree->jet_eta = ungroomed_jet_eta; WWTree->jet_phi = ungroomed_jet_phi; WWTree->jet_mass_pruned = jet_mass_pr; WWTree->jet_mass_softdrop = jet_mass_so; WWTree->jet_tau2tau1 = jet_tau2tau1; WWTree->nbtag=nBTagJet_medium; WWTree->m_lvj = mass_lvj_type0; WWTree->jet2_pt = jet2_pt; WWTree->jet2_btag = jet2_btag; WWTree->jet3_pt = jet3_pt; WWTree->jet3_btag = jet3_btag; //fill the tree if(strcmp(leptonName.c_str(),"mu")==0 && WWTree->issignal==1 && WWTree->W_pt>200 && WWTree->pfMET>40 && WWTree->l_pt>53 && WWTree->jet_pt>200 && WWTree->nbtag <1 && ((WWTree->jet_mass_pruned > 40 && WWTree->jet_mass_pruned<65) || (WWTree->jet_mass_pruned > 135 && WWTree->jet_mass_pruned<150))) { //WWTree->jet_mass_pruned > 40 && WWTree->jet_mass_pruned < 130) {//&& WWTree->jet_tau2tau1<0.5) { outTree->Fill(); } if(strcmp(leptonName.c_str(),"el")==0 && WWTree->issignal==1 && WWTree->W_pt>200 && WWTree->pfMET>80 && WWTree->l_pt>120 && WWTree->jet_pt>200 && WWTree->nbtag <1 && ((WWTree->jet_mass_pruned > 40 && WWTree->jet_mass_pruned<65) || (WWTree->jet_mass_pruned > 135 && WWTree->jet_mass_pruned<150))) { //WWTree->jet_mass_pruned > 40 && WWTree->jet_mass_pruned < 130) {//&& WWTree->jet_tau2tau1<0.5) { outTree->Fill(); } } //--------close everything------------- outTree->Write(); outROOT->Close(); return(0); }
int main (int argc, char **argv) { TFile *tf = TFile::Open("root/AnalysisOut.root"); TTree *tree = (TTree*)tf->Get("AnalysisTree"); RooWorkspace *w = new RooWorkspace("w","w"); // tree variables Double_t t_mass; Double_t t_KST1_m; Double_t t_KST2_m; int t_itype; ULong64_t t_eventNumber; Bool_t t_pass_bdt; Bool_t t_pass_pid; TString *t_evname = 0; // tree branches tree->SetBranchAddress("B_s0_DTF_B_s0_M", &t_mass ); tree->SetBranchAddress("B_s0_DTF_KST1_M", &t_KST1_m ); tree->SetBranchAddress("B_s0_DTF_KST2_M", &t_KST2_m ); tree->SetBranchAddress("itype", &t_itype ); tree->SetBranchAddress("eventNumber", &t_eventNumber ); tree->SetBranchAddress("pass_bdt", &t_pass_bdt ); tree->SetBranchAddress("pass_pid", &t_pass_pid ); tree->SetBranchAddress("evname", &t_evname ); // observables RooRealVar *mass = new RooRealVar("B_s0_DTF_B_s0_M", "m(K#piK#pi)", 5000., 5800.); RooRealVar *KST1_mass = new RooRealVar("B_s0_DTF_KST1_M", "m(K#pi)" , 750, 1700 ); RooRealVar *KST2_mass = new RooRealVar("B_s0_DTF_KST2_M", "m(K#pi)" , 750, 1700 ); RooRealVar *itype = new RooRealVar("itype","itype",-10,10); itype->removeRange(); RooRealVar *eventNumber = new RooRealVar("eventNumber","eventNumber",0,10e10); // map to store datasets map<int, RooDataSet*> dsets; for ( int ev=0; ev<tree->GetEntries(); ev++ ) { tree->GetEntry(ev); if ( t_itype >= 0 && !t_pass_bdt ) continue; if ( t_itype >= 0 && !t_pass_pid ) continue; // if entry not in map then add it if ( dsets.find( t_itype ) == dsets.end() ) { dsets[t_itype] = new RooDataSet( *t_evname, *t_evname, RooArgSet(*mass,*KST1_mass,*KST2_mass,*itype,*eventNumber) ); } // add to dataset mass->setVal( t_mass ); KST1_mass->setVal( t_KST1_m ); KST2_mass->setVal( t_KST2_m ); itype->setVal( t_itype ); eventNumber->setVal( t_eventNumber ); dsets[t_itype]->add( RooArgSet(*mass,*KST1_mass,*KST2_mass,*itype,*eventNumber) ); if ( ev%10000==0 ) { cout << ev << "/" << tree->GetEntries() << endl; cout << "\t" << t_itype << " " << *t_evname << " " << t_eventNumber << " " << t_mass << endl; } } for ( map<int, RooDataSet*>::iterator it = dsets.begin(); it != dsets.end(); it++ ) { cout << "\t" << it->first << " " << it->second->GetName() << " " << it->second->numEntries() << endl; w->import(*it->second); } tf->Close(); delete t_evname; w->writeToFile("tmp/DataSets.root"); return 0; }
void PlotDecisionBoundary( TString weightFile = "weights/TMVAClassification_BDT.weights.xml",TString v0="var0", TString v1="var1", TString dataFileName = "/home/hvoss/TMVA/TMVA_data/data/data_circ.root") { //--------------------------------------------------------------- // default MVA methods to be trained + tested // this loads the library TMVA::Tools::Instance(); std::cout << std::endl; std::cout << "==> Start TMVAClassificationApplication" << std::endl; // // create the Reader object // TMVA::Reader *reader = new TMVA::Reader( "!Color:!Silent" ); // create a set of variables and declare them to the reader // - the variable names must corresponds in name and type to // those given in the weight file(s) that you use Double_t var0, var1; reader->AddVariable( v0, &var0 ); reader->AddVariable( v1, &var1 ); // // book the MVA method // reader->BookMVA( "MyMVAMethod", weightFile ); TFile *f = new TFile(dataFileName); TTree *signal = (TTree*)f->Get("TreeS"); TTree *background = (TTree*)f->Get("TreeB"); //Declaration of leaves types Float_t svar0; Float_t svar1; Float_t bvar0; Float_t bvar1; Float_t sWeight=1.0; // just in case you have weight defined, also set these branchaddresses Float_t bWeight=1.0*signal->GetEntries()/background->GetEntries(); // just in case you have weight defined, also set these branchaddresses // Set branch addresses. signal->SetBranchAddress(v0,&svar0); signal->SetBranchAddress(v1,&svar1); background->SetBranchAddress(v0,&bvar0); background->SetBranchAddress(v1,&bvar1); UInt_t nbin = 50; Float_t xmax = signal->GetMaximum(v0.Data()); Float_t xmin = signal->GetMinimum(v0.Data()); Float_t ymax = signal->GetMaximum(v1.Data()); Float_t ymin = signal->GetMinimum(v1.Data()); xmax = TMath::Max(xmax,(Float_t)background->GetMaximum(v0.Data())); xmin = TMath::Min(xmin,(Float_t)background->GetMinimum(v0.Data())); ymax = TMath::Max(ymax,(Float_t)background->GetMaximum(v1.Data())); ymin = TMath::Min(ymin,(Float_t)background->GetMinimum(v1.Data())); TH2D *hs=new TH2D("hs","",nbin,xmin,xmax,nbin,ymin,ymax); TH2D *hb=new TH2D("hb","",nbin,xmin,xmax,nbin,ymin,ymax); hs->SetXTitle(v0); hs->SetYTitle(v1); hb->SetXTitle(v0); hb->SetYTitle(v1); hs->SetMarkerColor(4); hb->SetMarkerColor(2); TH2F * hist = new TH2F( "MVA", "MVA", nbin,xmin,xmax,nbin,ymin,ymax); // Prepare input tree (this must be replaced by your data source) // in this example, there is a toy tree with signal and one with background events // we'll later on use only the "signal" events for the test in this example. Float_t MinMVA=10000, MaxMVA=-100000; for (UInt_t ibin=1; ibin<nbin+1; ibin++){ for (UInt_t jbin=1; jbin<nbin+1; jbin++){ var0 = hs->GetXaxis()->GetBinCenter(ibin); var1 = hs->GetYaxis()->GetBinCenter(jbin); Float_t mvaVal=reader->EvaluateMVA( "MyMVAMethod" ) ; if (MinMVA>mvaVal) MinMVA=mvaVal; if (MaxMVA<mvaVal) MaxMVA=mvaVal; hist->SetBinContent(ibin,jbin, mvaVal); } } // now you need to try to find the MVA-value at which you cut for the plotting of the decision boundary // (Use the smallest number of misclassifications as criterion) const Int_t nValBins=100; Double_t sum = 0.; TH1F *mvaS= new TH1F("mvaS","",nValBins,MinMVA,MaxMVA); mvaS->SetXTitle("MVA-ouput"); mvaS->SetYTitle("#entries"); TH1F *mvaB= new TH1F("mvaB","",nValBins,MinMVA,MaxMVA); mvaB->SetXTitle("MVA-ouput"); mvaB->SetYTitle("#entries"); TH1F *mvaSC= new TH1F("mvaSC","",nValBins,MinMVA,MaxMVA); mvaSC->SetXTitle("MVA-ouput"); mvaSC->SetYTitle("cummulation"); TH1F *mvaBC= new TH1F("mvaBC","",nValBins,MinMVA,MaxMVA); mvaBC->SetXTitle("MVA-ouput"); mvaBC->SetYTitle("cummulation"); Long64_t nentries; nentries = signal->GetEntries(); for (Long64_t is=0; is<nentries;is++) { signal->GetEntry(is); sum +=sWeight; var0 = svar0; var1 = svar1; Float_t mvaVal=reader->EvaluateMVA( "MyMVAMethod" ) ; hs->Fill(svar0,svar1); mvaS->Fill(mvaVal,sWeight); } nentries = background->GetEntries(); for (Long64_t ib=0; ib<nentries;ib++) { background->GetEntry(ib); sum +=bWeight; var0 = bvar0; var1 = bvar1; Float_t mvaVal=reader->EvaluateMVA( "MyMVAMethod" ) ; hb->Fill(bvar0,bvar1); mvaB->Fill(mvaVal,bWeight); } SeparationBase *sepGain = new MisClassificationError(); //SeparationBase *sepGain = new GiniIndex(); //SeparationBase *sepGain = new CrossEntropy(); Double_t sTot = mvaS->GetSum(); Double_t bTot = mvaB->GetSum(); mvaSC->SetBinContent(1,mvaS->GetBinContent(1)); mvaBC->SetBinContent(1,mvaB->GetBinContent(1)); Double_t sSel=mvaSC->GetBinContent(1); Double_t bSel=mvaBC->GetBinContent(1); Double_t sSelBest=0; Double_t bSelBest=0; Double_t separationGain=sepGain->GetSeparationGain(sSel,bSel,sTot,bTot); Double_t mvaCut=mvaSC->GetBinCenter(1); Double_t mvaCutOrientation=1; // 1 if mva > mvaCut --> Signal and -1 if mva < mvaCut (i.e. mva*-1 > mvaCut*-1) --> Signal for (UInt_t ibin=2;ibin<nValBins;ibin++){ mvaSC->SetBinContent(ibin,mvaS->GetBinContent(ibin)+mvaSC->GetBinContent(ibin-1)); mvaBC->SetBinContent(ibin,mvaB->GetBinContent(ibin)+mvaBC->GetBinContent(ibin-1)); sSel=mvaSC->GetBinContent(ibin); bSel=mvaBC->GetBinContent(ibin); if (separationGain < sepGain->GetSeparationGain(sSel,bSel,sTot,bTot)){ separationGain = sepGain->GetSeparationGain(sSel,bSel,sTot,bTot); mvaCut=mvaSC->GetBinCenter(ibin); if (sSel/bSel > (sTot-sSel)/(bTot-bSel)) mvaCutOrientation=-1; else mvaCutOrientation=1; sSelBest=sSel; bSelBest=bSel; } } cout << "Min="<<MinMVA << " Max=" << MaxMVA << " sTot=" << sTot << " bTot=" << bTot << " sSel=" << sSelBest << " bSel=" << bSelBest << " sepGain="<<separationGain << " cut=" << mvaCut << " cutOrientation="<<mvaCutOrientation << endl; delete reader; gStyle->SetPalette(1); plot(hs,hb,hist ,v0,v1,mvaCut); TCanvas *cm=new TCanvas ("cm","",900,1200); cm->cd(); cm->Divide(1,2); cm->cd(1); mvaS->SetLineColor(4); mvaB->SetLineColor(2); mvaS->Draw(); mvaB->Draw("same"); cm->cd(2); mvaSC->SetLineColor(4); mvaBC->SetLineColor(2); mvaBC->Draw(); mvaSC->Draw("same"); // TH1F *add=(TH1F*)mvaBC->Clone("add"); // add->Add(mvaSC); // add->Draw(); // errh->Draw("same"); // // write histograms // TFile *target = new TFile( "TMVAPlotDecisionBoundary.root","RECREATE" ); hs->Write(); hb->Write(); hist->Write(); target->Close(); }
void clusterDFSReso() { TFile* file = new TFile("complete.root"); TTree* tree = (TTree *)file->Get("Signal"); int nEvents = tree->GetEntries(); double addresses[121] = {}; for (int k=0; k<121; k++){ std::stringstream ss2; ss2 << k; string str = "Crystal_"+ss2.str(); const char* charstr = str.c_str(); tree->SetBranchAddress(charstr, &addresses[k]); } TH1D* energyResoD = new TH1D("energyResoD", "DFS_Energy_Resolution", gammaEnergy/5, -1*gammaEnergy, gammaEnergy); TH1D* posResoDX = new TH1D("posResoD", "DFS_PosX_Resolution", 1000, -5, 5); TH1D* posResoDY = new TH1D("posResoD", "DFS_PosY_Resolution", 1000, -5, 5); double energyThresHi = 50.; //set energy threshold to start looking for bumps double energyThresLo = .5; //energy lower bound //Going through each scan of the calorimeter for (int k=0; k<nEvents; k++) { tree->GetEntry(k); cout << "Event number: " << k << endl; pair<int, double> bump(0, 0.); vector<pair<int, double> > geant; vector<pair<int, double> > hitMap; for(int i=0; i<121; i++) { pair<int, double> hit(i, addresses[i]); geant.push_back(hit); if (addresses[i] > energyThresHi) { hitMap.push_back(hit);} if (hit.second>bump.second) { bump = hit;} } // hitMap now stores the <ID, energy> of each crystal with energy // over a certain threshold, geant now contains all crystal information std::vector<std::vector<std::pair<int, double> > > detector; std::vector<std::pair<int, double> > shower; detector.push_back(DFS(bump, energyThresLo, shower, addresses)); //detector = uncluster(detector, hitMap); // no longer counts two showers if bumps are next to each other int num = 9; // number of crystals considered for (VVP_iterator=detector.begin(); VVP_iterator!=detector.end(); ++VVP_iterator) { energyResoD->Fill(reconstruct(detector[0]).first-gammaEnergy); posResoDX->Fill(reconstruct(detector[0]).second.first); posResoDY->Fill(reconstruct(detector[0]).second.second); } } //end of event TCanvas* canvas = new TCanvas("canvas", "canvas", 700,700); canvas->Divide(2, 2); TF1* g1dX = new TF1("g1dX", "gaus", -5, 5); posResoDX->Fit(g1dX); canvas->cd(1); posResoDX->Draw(); TF1* g1dY = new TF1("g1dY", "gaus", -5, 5); posResoDY->Fit(g1dY); canvas->cd(2); posResoDY->Draw(); TF1* g1d = new TF1("g1d", "gaus", -10, 10); energyResoD->Fit(g1d); canvas->cd(3); energyResoD->Draw(); }
void addBranches(string filename = "Bsphiphi") { double m_K = 0.493677; int nphi = count(filename, "phi"); int nBs = count(filename, "Bs"); cout << "Adding branches to " << filename << endl; /*Input************************************************************************/ // Open the input file and create the output file TFile* infile = TFile::Open((filename+".root" ).c_str()), * outfile = TFile::Open((filename+"_branches.root").c_str(),"RECREATE"); // Get the input tree and create an empty output tree TTree* intree = GetTree(infile), * outtree = intree->CloneTree(0); // Read the number of events in the input file Int_t n = intree->GetEntries(); TLorentzVector Kp_0_P, Km_0_P, Kp_1_P, Km_1_P, phi_P, KK_P; double m_b, m_phi, m_kk; double M_B, M_PHI, M_KK, M_phiKp, M_phiKm; double Kp_0_PX, Km_0_PX, Kp_1_PX, Km_1_PX; double Kp_0_PY, Km_0_PY, Kp_1_PY, Km_1_PY; double Kp_0_PZ, Km_0_PZ, Kp_1_PZ, Km_1_PZ; intree->SetBranchAddress("Kp_0_PX_TRUE",&Kp_0_PX); intree->SetBranchAddress("Kp_0_PY_TRUE",&Kp_0_PY); intree->SetBranchAddress("Kp_0_PZ_TRUE",&Kp_0_PZ); intree->SetBranchAddress("Km_0_PX_TRUE",&Km_0_PX); intree->SetBranchAddress("Km_0_PY_TRUE",&Km_0_PY); intree->SetBranchAddress("Km_0_PZ_TRUE",&Km_0_PZ); if(nBs == 1) { intree->SetBranchAddress("Bs0_0_M_TRUE",&m_b); intree->SetBranchAddress("Kp_1_PX_TRUE",&Kp_1_PX); intree->SetBranchAddress("Kp_1_PY_TRUE",&Kp_1_PY); intree->SetBranchAddress("Kp_1_PZ_TRUE",&Kp_1_PZ); intree->SetBranchAddress("Km_1_PX_TRUE",&Km_1_PX); intree->SetBranchAddress("Km_1_PY_TRUE",&Km_1_PY); intree->SetBranchAddress("Km_1_PZ_TRUE",&Km_1_PZ); outtree->Branch("B_s0_M",&M_B); outtree->Branch("KK_M",&M_KK); outtree->Branch("phiKplusM",&M_phiKm); outtree->Branch("phiKminusM",&M_phiKp); cout << "Creating branch B_s0_M" << endl; cout << "Creating branch KK_M" << endl; cout << "Creating branch phiKplusM" << endl; cout << "Creating branch phiKminusM" << endl; } outtree->Branch("phi_1020_M",&M_PHI); cout << "Creating branch phi_1020_M" << endl; if(nphi>0) { intree->SetBranchAddress("phi_0_M_TRUE",&m_phi); cout << "Can just read the branch phi_0_M" << endl; } if(nphi==2) { intree->SetBranchAddress("phi_1_M_TRUE",&m_kk); cout << "Can just read the branch phi_1_M" << endl; } /*Event loop*******************************************************************/ for(Int_t i = 0; i < n; i++) { intree->GetEntry(i); if(nBs == 1) { // M_B = m_b*1e3; Kp_0_P.SetXYZM(Kp_0_PX,Kp_0_PY,Kp_0_PZ,m_K); Km_0_P.SetXYZM(Km_0_PX,Km_0_PY,Km_0_PZ,m_K); Kp_1_P.SetXYZM(Kp_1_PX,Kp_1_PY,Kp_1_PZ,m_K); Km_1_P.SetXYZM(Km_1_PX,Km_1_PY,Km_1_PZ,m_K); M_B = (Kp_0_P+Km_0_P+Kp_1_P+Km_1_P).M()*1e3; M_phiKp = (Kp_0_P+Km_0_P+Kp_1_P).M()*1e3; M_phiKm = (Kp_0_P+Km_0_P+Km_1_P).M()*1e3; switch(nphi) { case 0: M_PHI = (Kp_0_P+Km_0_P).M()*1e3; M_KK = (Kp_1_P+Km_1_P).M()*1e3; break; case 1: M_PHI = m_phi*1e3; M_KK = (Kp_1_P+Km_1_P).M()*1e3; break; case 2: M_PHI = m_phi*1e3; M_KK = m_kk*1e3; } } else { M_PHI = m_phi*1e3; } /*Fill tree********************************************************************/ outtree->Fill(); if(i%100000 == 0) cout << "Event " << i << "/" << n << endl; } /*Write the output*************************************************************/ outtree->Write(); infile->Close(); outfile->Close(); return; }
void treeComparison(double luminosity = 19712, bool save = true, int verbose=1, TString inputFolderName= "RecentAnalysisRun8TeV_doubleKinFit", TString dataFile= "/afs/naf.desy.de/group/cms/scratch/tophh/RecentAnalysisRun8TeV_doubleKinFit/elecDiffXSecData2012ABCDAll.root:/afs/naf.desy.de/group/cms/scratch/tophh/RecentAnalysisRun8TeV_doubleKinFit/muonDiffXSecData2012ABCDAll.root", const std::string decayChannel = "combined", bool withRatioPlot=true, TString test="prob") { // test= "prob" or "PV" // data/MC -> MC/data bool invert=true; // linear fit in ratio? bool linFit=true; // =================================== // Define plotting order // =================================== std::vector<int> samples_; samples_.push_back(kSig); samples_.push_back(kBkg); samples_.push_back(kSTop); samples_.push_back(kWjets); samples_.push_back(kZjets); samples_.push_back(kDiBos); samples_.push_back(kQCD); samples_.push_back(kData); // ============================ // Set Root Style // ============================ TStyle myStyle("HHStyle","HHStyle"); setHHStyle(myStyle); myStyle.SetStripDecimals(true); myStyle.cd(); gROOT->SetStyle("HHStyle"); gROOT->ForceStyle(); TGaxis::SetMaxDigits(2); // user specific configuration TString testQuantity=""; // name of separator in tree TString treePath=""; // path of tree // values for splitting topPt (Val0<=plot1<Val1<=plot2<Val2) std::vector< double > Val_; TString treeExt=""; if(test=="PV"){ testQuantity="nPV"; treePath="compositedKinematicsKinFit/tree"; Val_.push_back(0. ); Val_.push_back(8. ); Val_.push_back(13.); Val_.push_back(17.); Val_.push_back(22.); Val_.push_back(50.); treeExt="Fit"; } if(test=="prob"){ testQuantity="chi2"; treePath="analyzeTopRecoKinematicsKinFit/tree"; Val_.push_back(0. ); Val_.push_back(1.386); // chi2<1.386 ~prob>0.50 Val_.push_back(2.1); // chi2<2.1 ~prob>0.35 Val_.push_back(3.219); // chi2<3.219 ~prob>0.20 Val_.push_back(7.824); // chi2<7.824 ~prob>0.02 Val_.push_back(99999.); treeExt=""; } // default configurations unsigned int systematicVariation=sysNo; TString ttbarMC="Madgraph"; bool scaleTtbarToMeasured=true; // adjust luminosity and data files for combined control plots double luminosityEl=constLumiElec; double luminosityMu=constLumiMuon; if(!dataFile.Contains(":")){ std::cout << "wrong input filenames, should be dataFileEl:dataFileMu, but is "; std::cout << dataFile << std::endl; exit(0); } TString dataFileEl=getStringEntry(dataFile,1 , ":"); TString dataFileMu=getStringEntry(dataFile,42, ":"); // file container std::map<unsigned int, TFile*> files_, filesMu_, filesEl_; // file vector storage std::vector< std::map<unsigned int, TFile*> > fileList_; // get analysis files TString inputFolder="/afs/naf.desy.de/group/cms/scratch/tophh/"+inputFolderName; if(verbose>0) std::cout << "loading files from " << inputFolder << std::endl; if(decayChannel!="combined"){ TString dataFiletemp= decayChannel=="muon" ? dataFileMu : dataFileEl; files_ = getStdTopAnalysisFiles(inputFolder, systematicVariation, dataFiletemp, decayChannel, ttbarMC); fileList_.push_back(files_); } else{ filesMu_ = getStdTopAnalysisFiles(inputFolder, systematicVariation, dataFileMu, "muon" , ttbarMC); filesEl_ = getStdTopAnalysisFiles(inputFolder, systematicVariation, dataFileEl, "electron", ttbarMC); fileList_.push_back(filesMu_); fileList_.push_back(filesEl_); } // topPt histogram template if(verbose>0) std::cout << "creating temp histo" << std::endl; TH1F* temp= (TH1F*)(((TH1F*)(fileList_.at(0)[kSig]->Get("analyzeTopRecoKinematicsKinFit/topPt"))->Clone())); temp->Rebin(20); temp->Reset("icms"); temp->SetTitle(""); temp->GetXaxis()->SetTitle("p_{T}^{t} #left[GeV#right]"); temp->GetYaxis()->SetTitle("Top quarks"); //axesStyle(*temp, "p_{T}^{t} #left[GeV#right]", "norm. Top quarks", 0., 0.15); temp->GetXaxis()->SetRangeUser(0.,500.); //temp->GetYaxis()->SetRangeUser(0.,0.2 ); temp->SetStats(kFALSE); temp->SetLineWidth(3); temp->SetMarkerSize(1.25); int binMax=temp->GetNbinsX()+1; // container for all histos std::map< TString, std::map <unsigned int, TH1F*> > histo_; // determine number of channels unsigned int nchannels = decayChannel=="combined" ? 2 : 1; // loop decay channels if(verbose>0) std::cout << "looping channels" << std::endl; for(unsigned int channel=0; channel<nchannels; ++channel){ std::map<unsigned int, TFile*> tempfiles_=fileList_.at(channel); std::string tempChannel= decayChannel!="combined" ? decayChannel : (channel==0 ? "muon" : "electron"); if(verbose>1) std::cout << " - " << tempChannel << std::endl; TString channelExt=getTStringFromInt(channel); // loop samples for(unsigned int sample=kSig; sample<=kSAToptW; ++sample){ bool note=false; // check if sample is relevant if(isValidsample(sample, systematicVariation)){ if(verbose>1){ std::cout << " -> processing " << sampleLabel(sample, tempChannel); std::cout << " (file " << tempfiles_[sample]->GetName() << ")" << std::endl; } // calculate luminosity event weight double lumi=decayChannel!="combined" ? luminosity : (channel==0 ? luminosityMu : luminosityEl); double lumiwgt=lumiweight(sample, lumi, systematicVariation, tempChannel); if(verbose>1) std::cout << " (lumiweight=" << lumiwgt << ")" << std::endl; // get trees TTree* tree = (TTree*)(tempfiles_[sample]->Get(treePath)); if(!tree){ std::cout << " !ERROR: tree not found!" << std::endl; exit(0); } else if(verbose>1) std::cout << " (tree found, contains " << tree->GetEntries() << " entries)" << std::endl; // container for values read from tree std::map< TString, float > value_; // initialize map entries with 0 value_["weight" ]=1.; value_["testQuantity" ]=0.; value_["topPtLep"]=0.; value_["topPtHad"]=0.; // initialize branches tree->SetBranchStatus ("*", 0); tree->SetBranchStatus ("weight" , 1); tree->SetBranchStatus ("topPtLep"+treeExt, 1); tree->SetBranchStatus ("topPtHad"+treeExt, 1); tree->SetBranchStatus (testQuantity , 1); tree->SetBranchAddress(testQuantity ,(&value_["testQuantity" ])); tree->SetBranchAddress("weight" ,(&value_["weight" ])); tree->SetBranchAddress("topPtLep"+treeExt,(&value_["topPtLep"])); tree->SetBranchAddress("topPtHad"+treeExt,(&value_["topPtHad"])); // initialize result plots histo_["topPt"+channelExt ][sample]=(TH1F*)(temp->Clone()); for(int plot=1; plot<(int)Val_.size(); ++plot){ histo_["topPtProb"+getTStringFromInt(plot)+channelExt][sample]=(TH1F*)(temp->Clone()); } if(verbose>1) std::cout << " -> looping tree" << std::endl; // loop all events to fill plots for(unsigned int event=0; event<tree->GetEntries(); ++event){ // get event tree->GetEntry(event); // check if values are reasonable if(!((value_["weight"]>0&&value_["weight"]<10)||(test!="PV"&&value_["weight"]==0.))){ if(!note){ std::cout << "!!! WARNING - some weights are strange (e.g." << value_["weight"] << ") !!!"<< std::endl; note=true; } value_["weight"]=1.0; } // get relevant quantities double weight=value_["weight"]*lumiwgt; double filterQuantity =value_["testQuantity" ]; double topPtLep=value_["topPtLep"]; double topPtHad=value_["topPtHad"]; if(verbose>2){ std::cout << " event #" << event+1 << "/" << tree->GetEntries() << ":" << std::endl; std::cout << " weight=" << weight << ", " << "testQuantity" << "=" << filterQuantity << ", topPtLep=" << topPtLep << ", topPtHad=" << topPtHad << std::endl; } // fill histo for all histo_["topPt"+channelExt][sample]->Fill(topPtLep, weight); histo_["topPt"+channelExt][sample]->Fill(topPtHad, weight); // fill histo for different ranges of the filterQuantity for(int plot=1; plot<(int)Val_.size(); ++plot){ TString nameNr=getTStringFromInt(plot); if(filterQuantity>=Val_[plot-1]&&filterQuantity<Val_[plot]){ histo_["topPtProb"+nameNr+channelExt][sample]->Fill(topPtLep, weight); histo_["topPtProb"+nameNr+channelExt][sample]->Fill(topPtHad, weight); } } // end for loop separation values } // end for loop tree events } // end if is valid sample } // end for loop samples } // end for loop decay channels // create final plots // -> combine decay channels and MC samples unsigned int kAllMC=42; // loop samples if(verbose>0) std::cout << "combining decay channels and MC samples" << std::endl; for(unsigned int sample=kSig; sample<=kSAToptW; ++sample){ // check if sample is relevant if(isValidsample(sample, systematicVariation)){ // loop decay channels for(unsigned int channel=0; channel<nchannels; ++channel){ std::string tempChannel= decayChannel!="combined" ? decayChannel : (channel==0 ? "muon" : "electron"); if(verbose>1) std::cout << " -> processing " << sampleLabel(sample, tempChannel) << "(" << tempChannel << ")" << std::endl; TString channelExt=getTStringFromInt(channel); // get plots for current channels std::vector <TH1F*> tempHist_; tempHist_.push_back((TH1F*)histo_["topPt"+channelExt ][sample]->Clone()); for(int plot=1; plot<(int)Val_.size(); ++plot){ TString nameNr=getTStringFromInt(plot); tempHist_.push_back((TH1F*)histo_["topPtProb"+nameNr+channelExt][sample]->Clone()); } std::vector <int> nevents_; for(int plot=0; plot<(int)Val_.size(); ++plot){ nevents_.push_back(tempHist_[plot]->Integral(0,binMax)); } // add all channels for final histogram if(channel==0){ for(int plot=0; plot<(int)Val_.size(); ++plot){ TString nameNr= plot==0 ? "" : "TestSlice"+getTStringFromInt(plot); histo_["topPt"+nameNr][sample]=(TH1F*)tempHist_[plot]->Clone(); } } else{ for(int plot=0; plot<(int)Val_.size(); ++plot){ TString nameNr= plot==0 ? "" : "TestSlice"+getTStringFromInt(plot); histo_["topPt"+nameNr][sample]->Add((TH1F*)tempHist_[plot]->Clone()); } } if(verbose>2){ std::cout << " (#events(" << tempChannel << ")="; for(int plot=0; plot<(int)Val_.size(); ++plot){ std::cout << nevents_[plot]; if(plot<(int)Val_.size()-1) std::cout << " / "; } std::cout << ")" << std::endl; } } // end channel for loop std::vector <double> neventsComb_; for(int plot=0; plot<(int)Val_.size(); ++plot){ TString nameNr= plot==0 ? "" : "TestSlice"+getTStringFromInt(plot); neventsComb_.push_back(histo_["topPt"+nameNr][sample]->Integral(0,binMax)); } if(verbose>1){ std::cout << " (#events="; for(int plot=0; plot<(int)Val_.size(); ++plot){ std::cout << neventsComb_[plot]; if(plot<(int)Val_.size()-1) std::cout << " / "; } std::cout << ")" << std::endl; } // combine all MC samples if(sample!=kData){ if(sample==kSig){ for(int plot=0; plot<(int)Val_.size(); ++plot){ TString nameNr= plot==0 ? "" : "TestSlice"+getTStringFromInt(plot); histo_["topPt"+nameNr][kAllMC]=(TH1F*)histo_["topPt"+nameNr][sample]->Clone(); } } else{ for(int plot=0; plot<(int)Val_.size(); ++plot){ TString nameNr= plot==0 ? "" : "TestSlice"+getTStringFromInt(plot); histo_["topPt"+nameNr][kAllMC]->Add((TH1F*)histo_["topPt"+nameNr][sample]->Clone()); } } // MC histogram style for(int plot=0; plot<(int)Val_.size(); ++plot){ TString nameNr= plot==0 ? "" : "TestSlice"+getTStringFromInt(plot); histogramStyle(*histo_["topPt"+nameNr][sample], sample, true); //histo_["topPt"+nameNr][sample]->SetLineColor(histo_["topPt"+nameNr][sample]->GetFillColor()); histo_["topPt"+nameNr][sample]->SetLineWidth(1); } } else{ // data histogram style for(int plot=0; plot<(int)Val_.size(); ++plot){ TString nameNr= plot==0 ? "" : "TestSlice"+getTStringFromInt(plot); histogramStyle(*histo_["topPt"+nameNr][sample], kData, false); } } } // end if sample is valid } // end sample for loop // print some interesting numbers // chosen slices std::vector< double >neventsMC_; if(verbose>0){ std::cout << "slices in " << testQuantity << ": all / "; for(int plot=1; plot<(int)Val_.size(); ++plot){ std::cout << "[" << Val_[plot-1] << ".." << Val_[plot] << "]"; if(plot<(int)Val_.size()-1) std::cout << "/ "; } std::cout << std::endl; } // total number of MC events for(int plot=0; plot<(int)Val_.size(); ++plot){ TString nameNr= plot==0 ? "" : "TestSlice"+getTStringFromInt(plot); neventsMC_.push_back(histo_["topPt"+nameNr][kAllMC]->Integral(0,binMax)); } if(verbose>0){ std::cout << "#events( MC )="; for(int plot=0; plot<(int)Val_.size(); ++plot){ std::cout << neventsMC_[plot]; if(plot<(int)Val_.size()-1) std::cout << ", "; } std::cout << std::endl; } // total number of data events std::vector< double >neventsData_; for(int plot=0; plot<(int)Val_.size(); ++plot){ TString nameNr= plot==0 ? "" : "TestSlice"+getTStringFromInt(plot); neventsData_.push_back(histo_["topPt"+nameNr][kData]->Integral(0,binMax)); } if(verbose>0){ std::cout << "#events(Data)="; for(int plot=0; plot<(int)Val_.size(); ++plot){ std::cout << neventsData_[plot]; if(plot<(int)Val_.size()-1) std::cout << " / "; } std::cout << std::endl; } // data over MC ratio if(verbose>0){ std::cout << "(data/MC ratio="; for(int plot=0; plot<(int)Val_.size(); ++plot){ std::cout << neventsData_[plot]/neventsMC_[plot]; if(plot<(int)Val_.size()-1) std::cout << " / "; } std::cout << ")" << std::endl; } // scale ttbar to match total number of events if(scaleTtbarToMeasured){ if(verbose>0) std::cout << "scale ttbar component to match #data events " << std::endl; std::vector<double>neventsTop_, SFTop_; for(int plot=0; plot<(int)Val_.size(); ++plot){ TString nameNr= plot==0 ? "" : "TestSlice"+getTStringFromInt(plot); neventsTop_.push_back(histo_["topPt"+nameNr][kSig]->Integral(0,binMax)+histo_["topPt"+nameNr][kBkg]->Integral(0,binMax)); SFTop_.push_back((neventsTop_[plot]+(neventsData_[plot]-neventsMC_[plot]))/neventsTop_[plot]); } // scale combined and top MC plots for(int plot=0; plot<(int)Val_.size(); ++plot){ TString nameNr= plot==0 ? "" : "TestSlice"+getTStringFromInt(plot); // subtract ttbar from all MC histo_["topPt"+nameNr][kAllMC]->Add((TH1F*)(histo_["topPt"+nameNr][kSig]->Clone()) , -1.); histo_["topPt"+nameNr][kAllMC]->Add((TH1F*)(histo_["topPt"+nameNr][kBkg]->Clone()) , -1.); // scale ttbar histo_["topPt"+nameNr][kSig]->Scale(SFTop_[plot]); histo_["topPt"+nameNr][kBkg]->Scale(SFTop_[plot]); // re-add ttbar MC histo_["topPt"+nameNr][kAllMC]->Add((TH1F*)(histo_["topPt"+nameNr][kSig]->Clone()) ); histo_["topPt"+nameNr][kAllMC]->Add((TH1F*)(histo_["topPt"+nameNr][kBkg]->Clone()) ); } // printout std::vector<double>neventsMCscaled_; for(int plot=0; plot<(int)Val_.size(); ++plot){ TString nameNr= plot==0 ? "" : "TestSlice"+getTStringFromInt(plot); neventsMCscaled_.push_back(histo_["topPt"+nameNr][kAllMC]->Integral(0,binMax)); } if(verbose>1){ std::cout << "#events(scaledMC)="; for(int plot=0; plot<(int)Val_.size(); ++plot){ std::cout << neventsMCscaled_[plot]; if(plot<(int)Val_.size()-1) std::cout << " / "; } std::cout << std::endl; std::cout << "(data/scaledMC ratio="; for(int plot=0; plot<(int)Val_.size(); ++plot){ std::cout << neventsData_[plot]/neventsMCscaled_[plot]; if(plot<(int)Val_.size()-1) std::cout << " / "; } std::cout << ")" << std::endl; } }; // combine single top subsamples for(int plot=0; plot<(int)Val_.size(); ++plot){ TString nameNr= plot==0 ? "" : "TestSlice"+getTStringFromInt(plot); histo_["topPt"+nameNr][kSTop]=(TH1F*)histo_["topPt"+nameNr][kSAToptW]->Clone(); for(int sample=(int)kSTops; sample<(int)kSAToptW; ++sample){ // add to combined STop histo_["topPt"+nameNr][kSTop]->Add((TH1F*)histo_["topPt"+nameNr][sample]->Clone()); } // end for loop single top subsamples } // end for loop plots // create MC histo stack plots int lastSample=-1; // loop samples if(verbose>0) std::cout << "creating MC stack histos" << std::endl; for(int sampleOri=(int)kDiBos; sampleOri>=(int)kSig; --sampleOri){ // use previous defined order int sampleMod=samples_[sampleOri]; if(verbose>1) std::cout << "processing " << sampleLabel(sampleMod, decayChannel) << "(= " << sampleMod <<", last sample=" << lastSample << ")" << std::endl; // exclude QCD and Diboson if(sampleMod!=kQCD&&sampleMod!=kDiBos){ if(lastSample>-1){ if(verbose>1) std::cout << "adding " << sampleLabel(lastSample, decayChannel) << " to " << sampleLabel(sampleMod, decayChannel) << std::endl; // loop plots for(int plot=0; plot<(int)Val_.size(); ++plot){ TString nameNr= plot==0 ? "" : "TestSlice"+getTStringFromInt(plot); if(verbose>1) std::cout << "processing " << "topPt"+nameNr << std::endl; // add to stack if(!histo_.count("topPt"+nameNr)>0) std::cout << "WARNING: topPt"+nameNr+" does not exist in histo_!" << std::endl; else if(!histo_["topPt"+nameNr].count(sampleMod )>0) std::cout << "WARNING: sample " << sampleMod << " does not exist in histo_[topPt"+nameNr+"]!" << std::endl; else if(!histo_["topPt"+nameNr].count(lastSample)>0) std::cout << "WARNING: sample " << lastSample << " does not exist in histo_[topPt"+nameNr+"]!" << std::endl; histo_["topPt"+nameNr][sampleMod]->Add((TH1F*)histo_["topPt"+nameNr][lastSample]->Clone()); } // end for loop plots if(verbose>1) std::cout << "done" << std::endl; } // if not last sample if(verbose>1) std::cout << "lastSample set to " << sampleMod << std::endl; lastSample=sampleMod; } // end else if !QCD } // end for loop original sample ordering // printout std::vector<double>neventsMCstack_; for(int plot=0; plot<(int)Val_.size(); ++plot){ TString nameNr= plot==0 ? "" : "TestSlice"+getTStringFromInt(plot); neventsMCstack_.push_back(histo_["topPt"+nameNr][kAllMC]->Integral(0,binMax)); } if(verbose>1){ std::cout << "#events(stack MC) ="; for(int plot=0; plot<(int)Val_.size(); ++plot){ std::cout << neventsMCstack_[plot]; if(plot<(int)Val_.size()-1) std::cout << " / "; } std::cout << std::endl; } // all MC histogram style for(int plot=0; plot<(int)Val_.size(); ++plot){ TString nameNr= plot==0 ? "" : "TestSlice"+getTStringFromInt(plot); histo_["topPt"+nameNr][kAllMC]->SetLineColor(kBlue); histo_["topPt"+nameNr][kAllMC]->SetMarkerColor(kBlue); histo_["topPt"+nameNr][kAllMC]->SetLineStyle(1); } std::vector<double> zeroerr_; for(int bin=0; bin<histo_["topPt"][kAllMC]->GetNbinsX(); ++bin) zeroerr_.push_back(0); // normalization // -> not done at the moment, scaled wrt Ndata for each plot separately // Create canvas if(verbose>0) std::cout << "creating canvas" << std::endl; std::vector<TCanvas*> plotCanvas_; for(unsigned int sample=0; sample<Val_.size(); sample++){ addCanvas(plotCanvas_); } // create legends if(verbose>0) std::cout << "creating legend" << std::endl; std::vector< TLegend* > leg_; TLegend *leg= new TLegend(0.73, 0.5, 0.91, 0.88); legendStyle(*leg,""); for(int plot=0; plot<(int)Val_.size(); ++plot){ TString nameNr = plot==0 ? "" : "TestSlice"+getTStringFromInt(plot); TString sVallow = plot==0 ? "" : getTStringFromDouble(Val_[plot-1], getRelevantDigits(Val_[plot-1])); TString sValhigh = plot==0 ? "" : getTStringFromDouble(Val_[plot ], getRelevantDigits(Val_[plot ])); TString legHeader= plot==0 ? "KinFit, all" : sVallow+"#leq"+testQuantity+"<"+sValhigh; TLegend *templeg=(TLegend*)leg->Clone(); templeg ->SetHeader(legHeader); templeg ->AddEntry(histo_["topPt"+nameNr][kData ], "data" , "P"); //templeg ->AddEntry(histo_["topPt"+nameNr][kAllMC], "all MC" , "L" ); for(unsigned int sample=kSig; sample<kData; sample++){ unsigned int sampleMod=samples_[sample]; if(sampleMod!=kQCD&&sampleMod!=kDiBos) templeg ->AddEntry(histo_["topPt"+nameNr][sampleMod], sampleLabel(sampleMod, decayChannel), "F" ); } leg_.push_back((TLegend*)(templeg->Clone())); } int canvasNumber=0; // do the plotting if(verbose>0) std::cout << "plotting " << std::endl; for(int plot=0; plot<(int)Val_.size(); ++plot){ TString nameNr= plot==0 ? "" : "TestSlice"+getTStringFromInt(plot); TString title = plot==0 ? "topPtKinFit"+TString(decayChannel) : "topPt"+testQuantity+getTStringFromInt(plot)+TString(decayChannel); plotCanvas_[canvasNumber]->cd(0); plotCanvas_[canvasNumber]->SetTitle(title); // drawing // plots histo_["topPt"+nameNr][kSig]->SetMaximum(1.3*histo_["topPt"+nameNr][kData]->GetMaximum()); histo_["topPt"+nameNr][kSig]->GetXaxis()->SetNoExponent(true); histo_["topPt"+nameNr][kSig]->GetYaxis()->SetNoExponent(true); histo_["topPt"+nameNr][kSig]->Draw("axis"); // loop samples for(int sampleOri=(int)kSig; sampleOri<=(int)kDiBos; ++sampleOri){ // use previous defined order int sampleMod=samples_[sampleOri]; if(verbose>2) std::cout << "processing sample " << sampleMod << " ("+sampleLabel(sampleMod, decayChannel)+")" << std::endl; // draw other MC samples, excluding QCD if(sampleMod!=kQCD&&sampleMod!=kDiBos){ if(verbose>2) std::cout << "-> drawing!" << sampleMod << std::endl; histo_["topPt"+nameNr][sampleMod]->Draw("hist same"); } } // end for loop ori samples //histo_["topPt"+nameNr][kAllMC]->Draw("hist same"); histo_["topPt"+nameNr][kData ]->Draw("ep same"); // legend leg_[plot]->Draw("same"); // add labels for decay channel, luminosity, energy and CMS preliminary (if applicable) if (decayChannel=="muon" ) DrawDecayChLabel("#mu + Jets"); else if (decayChannel=="electron") DrawDecayChLabel("e + Jets"); else DrawDecayChLabel("e/#mu + Jets Combined"); DrawCMSLabels(true,luminosity); // draw ratio if(withRatioPlot){ // labels of ratio TString ratioLabelNominator ="N_{MC}"; TString ratioLabelDenominator="N_{Data}"; double ratMin= invert ? 0.75 : 0.30; double ratMax= invert ? 1.75 : 1.29; std::vector<double> err_; for(int bin=1; bin<histo_["topPt"+nameNr][kSig]->GetNbinsX(); ++bin){ double ratio = histo_["topPt"+nameNr][kData]->GetBinContent(bin)/histo_["topPt"+nameNr][kSig]->GetBinContent(bin); if(invert) ratio=1./ratio; double val=ratio*(histo_["topPt"+nameNr][kData]->GetBinError(bin)/histo_["topPt"+nameNr][kData]->GetBinContent(bin)); if(val<0||val>histo_["topPt"+nameNr][kData]->GetBinContent(bin)) val=1.; err_.push_back(val); } int rval1 = drawRatio(histo_["topPt"+nameNr][kData], histo_["topPt"+nameNr][kSig], ratMin, ratMax, myStyle, verbose, err_, ratioLabelNominator, ratioLabelDenominator, "p e", kBlack, true, 0.5, 505, invert, true, linFit); if (rval1!=0) std::cout << " Problem occured when creating ratio plot for " << nameNr << std::endl; } canvasNumber++; } // saving if(verbose>0) std::cout << "saving" << std::endl; if(save){ TString outfolder="./diffXSecFromSignal/plots/combined/2012/topPtTest/"; // eps and png if(verbose==0) gErrorIgnoreLevel=kWarning; saveCanvas(plotCanvas_, outfolder, "topPtTest"+testQuantity+TString(decayChannel), true, true, true); } }
void extractJetTrack(){ //TString filename = "dj_RECOPAT_18_1_rhi"; TString filename = "dj_HCPR-GoodTrk1123_All0"; //TString filename = "dj_HydjetQ_DJQ80_F10GSR_GoodTrk1123"; //TString filename = "dj_HydjetQ_DJUQ80_F10GSR_GoodTrk1123"; TFile *f = new TFile(Form("/home/sungho/sctch101/data/jettrack/%s.root",filename.Data())); TTree *djtree = (TTree*) f->Get("djcalo/djTree"); bool debug = false; maxSampling = 10; // max number of event-by-event histogram int count=0; // variables float minpt = 0.9; float centMin = 0, centMax = 10; float njet_min = 100; float njeteta_max = 2.0; float ajet_min = 50; float ajeteta_max = 2.0; // event number of interest targetEvtNum.push_back(1490824); targetEvtNum.push_back(2084186); targetEvtNum.push_back(2983992); // prepare for output files, histograms, etc; prepareHist(); // event-by-event Nevt = djtree->GetEntries(); float cent = 0; djtree->SetBranchAddress("cent",¢); int runNum = 0, lumNum = 0, evtNum = 0; djtree->SetBranchAddress("run",&runNum); djtree->SetBranchAddress("lumi",&lumNum); djtree->SetBranchAddress("evt",&evtNum); // tracks and jet int nTrk = 0; djtree->SetBranchAddress("evtnp",&nTrk); // each jet float njeteta=0, njetphi=0, njet=0; // near side jet float ajeteta=0, ajetphi=0, ajet=0; // away side jet djtree->SetBranchAddress("nljeta",&njeteta); djtree->SetBranchAddress("nljphi",&njetphi); djtree->SetBranchAddress("nljet",&njet); djtree->SetBranchAddress("aljeta",&ajeteta); djtree->SetBranchAddress("aljphi",&ajetphi); djtree->SetBranchAddress("aljet",&ajet); // each tracks djtree->SetBranchAddress("ppt",&trkpt); djtree->SetBranchAddress("peta",&trketa); djtree->SetBranchAddress("pphi",&trkphi); for(Long_t i=0;i<djtree->GetEntries();i++){ djtree->GetEntry(i); if((i%100)==0) cout<<"counting every 100 events = "<<i<<endl; if(debug) cout<<"Evt: "<<evtNum<<" Near side jet Et = "<<njet<<" number of tracks = "<<nTrk<<endl; if(cent<centMin || cent>centMax) continue; // centrality if(njet<njet_min || njet>500) continue; // near side jet et cut if(fabs(njeteta)>njeteta_max) continue; // near side jet eta cut if(ajet<ajet_min) continue; if(fabs(ajeteta)>ajeteta_max) continue; float dphi = nljphi - aljphi; if(fabs(dphi)>=(TMath::Pi())) dphi = 2.*TMath::Pi() - fabs(dphi); if(dphi>(TMath::Pi()*(5/6)) continue; // dphi cut for back-to-back jets for(Long_t j=0;j<2;j++){ float jet = (j==0) ? njet : ajet; float jeta = (j==0) ? njeteta : ajeteta; float jphi = (j==0) ? njetphi : ajetphi; // randomize //float jeta = (j==0) ? rdn.Uniform(-2,2) : rdn.Uniform(-2,2); //float jphi = 0; //if(j==0) jphi = rdn.Uniform(0,TMath::Pi()); //else jphi = -1.*jphi; //back to back if(hdEtadPhiJetArray.FindObject(Form("hdEtadPhiJet_%d",count)) && count<maxSampling) ((TH2F*) hdEtadPhiJetArray.FindObject(Form("hdEtadPhiJet_%d",count)))->Fill(jeta,jphi); for(int z=0;z<targetEvtNum.size();z++){ if(runNum!=151969) continue; // harcoded if(evtNum==targetEvtNum[z] && hdEtadPhiJetTagArray.FindObject(Form("hdEtadPhiJetTag_%d",evtNum))) //redundent ((TH2F*) hdEtadPhiJetTagArray.FindObject(Form("hdEtadPhiJetTag_%d",evtNum)))->Fill(jeta,jphi); } // pre-loop to determine pt sum ---------------------------------------------------------- float ptSum_N = 0.0, ptSum_A = 0.0; for(Long_t n=0;n<nTrk;n++){ if(trkpt[n]<minpt) continue; // low pt cut float deta_jt_pre = fabs(jeta-trketa[n]); float dphi_jt_pre = fabs(jphi-trkphi[n]); if(dphi_jt_pre>=(TMath::Pi())) dphi_jt_pre = 2.0*TMath::Pi() - fabs(dphi_jt_pre); float dR = TMath::Sqrt(deta_jt_pre*deta_jt_pre+dphi_jt_pre*dphi_jt_pre); if(fabs(trketa[n])<5.0){ if(j==0 && dR<0.8) ptSum_N = ptSum_N + trkpt[n]; if(j==1 && dR<0.8) ptSum_A = ptSum_A + trkpt[n]; } } // end of pre-loop --------------------------------------------------------------------- if(j==0) { hdNdJetEt_NJet->Fill(jet,jet), hdNdTrkSPt_NJet->Fill(jet,ptSum_N); hdNPtEtRatio_NJet->Fill(jet,ptSum_N/jet), hdNPtEtAsymm_NJet->Fill(jet,fabs(jet-ptSum_N)/(jet+ptSum_N)); }else{ hdNdJetEt_AJet->Fill(jet,jet), hdNdTrkSPt_AJet->Fill(jet,ptSum_A); hdNPtEtRatio_AJet->Fill(jet,ptSum_A/jet), hdNPtEtAsymm_AJet->Fill(jet,fabs(jet-ptSum_A)/(jet+ptSum_A)); } // track loop for(Long_t k=0;k<nTrk;k++){ if(trkpt[k]<minpt) continue; // low pt cut float deta_jt = fabs(jeta-trketa[k]); float dphi_jt = fabs(jphi-trkphi[k]); if(fabs(dphi_jt)>=(TMath::Pi())) dphi_jt = 2.0*TMath::Pi() - dphi_jt; // by convention dPhi < Pi float dr_jt = TMath::Sqrt(deta_jt*deta_jt+dphi_jt*dphi_jt); float deta_jt_v2 = (jeta-trketa[k]); // can be negative float dphi_jt_v2 = (jphi-trkphi[k]); if(fabs(trketa[k])<5.0){ if(j==0 && dphi_jt<(0.5*(TMath::Pi()))) hdNdPt_NJet->Fill(trkpt[k]), hdNdPt_NJet_vbin->Fill(trkpt[k]), hdNdZ_NJet->Fill(trkpt[k]/ptSum_N); if(j==1 && dphi_jt<(0.5*(TMath::Pi()))) hdNdPt_AJet->Fill(trkpt[k]), hdNdPt_AJet_vbin->Fill(trkpt[k]), hdNdZ_AJet->Fill(trkpt[k]/ptSum_A); if(j==0 && fabs(dr_jt)<0.8) { hdNdNR_NJet->Fill(dr_jt/0.8), hdNdNRW_NJet->Fill(dr_jt/0.8,trkpt[k]); //hdNPtEtRatio_NJet->Fill(jet,ptSum_N/jet), hdNPtEtAsymm_NJet->Fill(jet,fabs(jet-ptSum_N)/(jet+ptSum_N)); } if(j==1 && fabs(dr_jt)<0.8) { hdNdNR_AJet->Fill(dr_jt/0.8), hdNdNRW_AJet->Fill(dr_jt/0.8,trkpt[k]); //hdNPtEtRatio_AJet->Fill(jet,ptSum_A/jet), hdNPtEtAsymm_AJet->Fill(jet,fabs(jet-ptSum_A)/(jet+ptSum_A)); } } //if(trkpt[k]<minpt) continue; // low pt cut if(debug) cout<<" trk pt = "<<trkpt[k]<<endl; if(hdEtadPhiTrkArray.FindObject(Form("hdEtadPhiTrk_%d",count)) && count<50){ ((TH2F*) hdEtadPhiTrkArray.FindObject(Form("hdEtadPhiTrk_%d",count)))->Fill(trketa[k],trkphi[k]); ((TH2F*) hdEtadPhiTrkWArray.FindObject(Form("hdEtadPhiTrkW_%d",count)))->Fill(trketa[k],trkphi[k],trkpt[k]); // with weight } if(j==0 && dphi_jt<(0.5*(TMath::Pi()))) hdN_dEtadPhiTrkNJet->Fill(deta_jt_v2,dphi_jt_v2); if(j==1 && dphi_jt<(0.5*(TMath::Pi()))) hdN_dEtadPhiTrkAJet->Fill(deta_jt_v2,dphi_jt_v2); for(int z=0;z<targetEvtNum.size();z++){ if(runNum!=151969) continue; // harcoded if(evtNum==targetEvtNum[z] && hdEtadPhiTrkTagArray.FindObject(Form("hdEtadPhiTrkTag_%d",evtNum))) { ((TH2F*) hdEtadPhiTrkTagArray.FindObject(Form("hdEtadPhiTrkTag_%d",evtNum)))->Fill(trketa[k],trkphi[k]); ((TH2F*) hdEtadPhiTrkWTagArray.FindObject(Form("hdEtadPhiTrkWTag_%d",evtNum)))->Fill(trketa[k],trkphi[k],trkpt[k]); // with weight } } if(j==0) hdN_dPhiTrkNJet->Fill(dphi_jt), hdN_dEtaTrkNJet->Fill(deta_jt), hdN_dRTrkNJet->Fill(dr_jt); else hdN_dPhiTrkAJet->Fill(dphi_jt), hdN_dEtaTrkAJet->Fill(deta_jt), hdN_dRTrkAJet->Fill(dr_jt); for(Long_t l=0;l<nTrk;l++){ if(trkpt[l]<minpt) continue; if(l==k) continue; // to remove auto-correlation float deta_tt = fabs(trketa[k]-trketa[l]); float dphi_tt = fabs(trkphi[k]-trkphi[l]); if(fabs(dphi_tt)>=(TMath::Pi())) dphi_tt = 2.0*TMath::Pi() - fabs(dphi_tt); // by convention dPhi < Pi float dr_tt = TMath::Sqrt(deta_tt*deta_tt+dphi_tt*dphi_tt); hdN_dPhiTrkTrk_dPhiTrkJet->Fill(dphi_tt,dphi_jt); hdN_dEtaTrkTrk_dEtaTrkJet->Fill(deta_tt,deta_jt); hdN_dRTrkTrk_dRTrkJet->Fill(dr_tt,dr_jt); hdN_dPhiTrkTrk_dRTrkJet->Fill(dphi_tt,dr_jt); } } // end of track loop } // end of jet loop count++; } // end of event loop // save in output files saveHistRoot(Form("./rootOutput/ANAv2_RandomJet_%s_minpT%1.1f_centFrom%1.1fto%1.1f.root",filename.Data(),minpt,centMin,centMax)); }
void simpleskim(TString infilename="HiForest.root", TString outfilename="Zevents.root", string jetname="ak4PFJetAnalyzer", int i_is_pp = 0 ) { bool is_pp = (i_is_pp == 1) ; TrkCorr* trkCorr; if(is_pp) trkCorr = new TrkCorr("TrkCorr_Mar15_Iterative_PbPb/"); else trkCorr = new TrkCorr("TrkCorr_Mar15_Iterative_pp/"); std::cout<<trkCorr<<std::endl; TFile *fin = TFile::Open(infilename); TTree *injetTree = (TTree*)fin->Get(Form("%s/t",jetname.data())); if(!injetTree){ cout<<"Could not access jet tree!"<<endl; return; } TTree *evttree = (TTree*)fin->Get("hiEvtAnalyzer/HiTree"); if(!evttree){ cout<<"Could not access event tree!"<<endl; return; } float weight = 0 , vz = -99; int hiBin = -99; evttree->SetBranchAddress("weight", &weight); evttree->SetBranchAddress("hiBin", &hiBin); evttree->SetBranchAddress("vz", &vz); TTree * tracktree_ = (TTree*) fin->Get("anaTrack/trackTree"); if( tracktree_ == 0 ) tracktree_ = (TTree*) fin->Get("ppTrack/trackTree"); if(!tracktree_){ cout<<"Could not access track tree!"<<endl; return; } tracktree_->SetBranchAddress("nTrk", &nTrk_); tracktree_->SetBranchAddress("trkPt", trkPt_); tracktree_->SetBranchAddress("trkPtError", trkPtError_); tracktree_->SetBranchAddress("trkNHit", trkNHit_); tracktree_->SetBranchAddress("trkEta", trkEta_); tracktree_->SetBranchAddress("trkPhi", trkPhi_); tracktree_->SetBranchAddress("highPurity", highPurity_); tracktree_->SetBranchAddress("trkDxy1", trkDxy1_); tracktree_->SetBranchAddress("trkDxyError1", trkDxyError1_); tracktree_->SetBranchAddress("trkDz1", trkDz1_); tracktree_->SetBranchAddress("trkDzError1", trkDzError1_); tracktree_->SetBranchAddress("trkMVA", trkMVA_); injetTree->SetBranchAddress("nref", &nref); injetTree->SetBranchAddress("jtpt", jtpt); injetTree->SetBranchAddress("jteta", jteta); injetTree->SetBranchAddress("jtphi", jtphi); // int nEv = inggTree->GetEntries(); int nEv = evttree->GetEntries(); float totaltrkeff = 0.0; for (int j=0; j<nEv; j++) { evttree->GetEntry(j); if(fabs(vz)>15) continue; injetTree->GetEntry(j); if(j%1000 == 0) { cout << "Processing event: " << j <<"/"<<nEv<< endl; } tracktree_->GetEntry(j); int ntracks = 0; if(nTrk_>100000) { std::cout<<"track error"<<std::endl; exit(1); } if(nref>10000) { std::cout<<"jet error"<<std::endl; exit(1); } for(int i = 0 ; i < nTrk_ ; ++i) { if((trkMVA_[i]<0.5 && trkMVA_[i]!=-99) || (int)trkNHit_[i]<8 || trkPtError_[i]/trkPt_[i]>0.3 || fabs(trkDz1_[i])/trkDzError1_[i]>3 || fabs(trkDxy1_[i])/trkDxyError1_[i]>3) continue; if(trkPt_[i]<1 || trkPt_[i]>300 || fabs(trkEta_[i])>2.4 ) continue; float trkweight = 0; if(is_pp) trkweight=getTrkWeight(trkCorr,i,0,j); else trkweight=getTrkWeight(trkCorr,i,hiBin,j); //std::cout<<trkweight<<endl; ntracks++; totaltrkeff += trkweight; } } std::cout<<totaltrkeff<<std::endl; }
int BfinderAna(TString infile="/data/twang/BfinderRun2/DoubleMu/BfinderData_pp_20151130/finder_pp_merged.root", TString outfile="test.root", Bool_t REAL=false, Bool_t isPbPb=false, Int_t startEntries=0, Int_t endEntries=-1, // Int_t endEntries=100000, Bool_t skim=true, Bool_t gskim=true, Bool_t checkMatching=true, Bool_t iseos=false, Bool_t SkimHLTtree=true) { if(istest) { // infile="/store/group/phys_heavyions/HeavyFlavourRun2/BfinderRun2/MC/BJpsiMM_5p02TeV_TuneCUETP8M1/crab_BfinderMC_pp_BJpsiMM_5p02TeV_TuneCUETP8M1_20160613_bPt0jpsiPt0tkPt0p5_Bp/160612_195743/0000/finder_pp_62.root"; // infile="/data/HeavyFlavourRun2/BfinderRun2/MC/crab_BfinderMC_pp_BJpsiMM_5p02TeV_TuneCUETP8M1_20160613_bPt0jpsiPt0tkPt0p5_Bp.root"; infile="/data/HeavyFlavourRun2/BfinderRun2/MC/crab_BfinderMC_PbPb_Pythia8_BJpsiMM_ptJpsi_0_inf_Hydjet_MB_20160613_bPt5jpsiPt0tkPt0p8_Bp.root"; outfile="test.root"; REAL=false; isPbPb=false; skim=false; checkMatching=true; // iseos=true; iseos=false; } cout<<endl; if(REAL) cout<<"--- Processing - REAL DATA"; else cout<<"--- Processing - MC"; if(isPbPb) cout<<" - PbPb"; else cout<<" - pp"; cout<<endl; TString ifname; if(iseos) ifname = Form("root://eoscms.cern.ch//eos/cms%s",infile.Data()); else ifname = infile; TFile* f = TFile::Open(ifname); TTree* root = (TTree*)f->Get("Bfinder/root"); TTree* hltroot = (TTree*)f->Get("hltanalysis/HltTree"); TTree* skimroot = (TTree*)f->Get("skimanalysis/HltTree"); TTree* hiroot = (TTree*)f->Get("hiEvtAnalyzer/HiTree"); EvtInfoBranches *EvtInfo = new EvtInfoBranches; VtxInfoBranches *VtxInfo = new VtxInfoBranches; MuonInfoBranches *MuonInfo = new MuonInfoBranches; TrackInfoBranches *TrackInfo = new TrackInfoBranches; BInfoBranches *BInfo = new BInfoBranches; GenInfoBranches *GenInfo = new GenInfoBranches; setHltBranch(hltroot); setHiTreeBranch(hiroot); EvtInfo->setbranchadd(root); VtxInfo->setbranchadd(root); MuonInfo->setbranchadd(root); TrackInfo->setbranchadd(root); BInfo->setbranchadd(root); GenInfo->setbranchadd(root); Long64_t nentries = root->GetEntries(); if(endEntries>nentries || endEntries == -1) endEntries = nentries; TFile *outf = TFile::Open(Form("%s", outfile.Data()),"recreate"); cout<<"--- Check the number of events for four trees"<<endl; cout<<root->GetEntries()<<" "<<hltroot->GetEntries()<<" "<<hiroot->GetEntries(); cout<<" "<<skimroot->GetEntries()<<endl; cout<<endl; // double min = 4.6; double max = 6.0; TH1D* Bmass = new TH1D("Bmass","Bmass", 50, min, max); TH1D* Bmass_nosig = new TH1D("Bmass_nosig","Bmass_nosig", 50, min, max); TH1D* BmassBpPi = new TH1D("BmassBpPi","BmassBpPi", 50, min, max); TH1D* BmassBpXPi = new TH1D("BmassBpXPi","BmassBpXPi", 50, min, max); TH1D* BmassBpK = new TH1D("BmassBpK","BmassBpK", 50, min, max); TH1D* BmassB0K = new TH1D("BmassB0K","BmassB0K", 50, min, max); TH1D* BmassBpK_tkmatch = new TH1D("BmassBpK_tkmatch","BmassBpK_tkmatch", 50, min, max); TH1D* BmassB0K_tkmatch = new TH1D("BmassB0K_tkmatch","BmassB0K_tkmatch", 50, min, max); TH1D* BmassBpK_tknotmatch = new TH1D("BmassBpK_tknotmatch","BmassBpK_tknotmatch", 50, min, max); TH1D* BmassB0K_tknotmatch = new TH1D("BmassB0K_tknotmatch","BmassB0K_tknotmatch", 50, min, max); Bmass->SetMinimum(0); Bmass_nosig->SetMinimum(0); BmassBpPi->SetMinimum(0); BmassBpXPi->SetMinimum(0); BmassBpK->SetMinimum(0); BmassB0K->SetMinimum(0); BmassBpK_tkmatch->SetMinimum(0); BmassB0K_tkmatch->SetMinimum(0); BmassBpK_tknotmatch->SetMinimum(0); BmassB0K_tknotmatch->SetMinimum(0); std::map<int,int> BtypeCountBpK; std::map<int,int> BtypeCountB0K; cout<<"--- Processing events"<<endl; for(Int_t i=startEntries;i<endEntries;i++) { root->GetEntry(i); hltroot->GetEntry(i); skimroot->GetEntry(i); hiroot->GetEntry(i); if(i%100000==0) cout<<setw(7)<<i<<" / "<<endEntries<<endl; if(checkMatching) { if(((int)Bf_HLT_Event!=EvtInfo->EvtNo||(int)Bf_HLT_Run!=EvtInfo->RunNo||(int)Bf_HLT_LumiBlock!=EvtInfo->LumiNo) || ((int)Bf_HiTree_Evt!=EvtInfo->EvtNo||(int)Bf_HiTree_Run!=EvtInfo->RunNo||(int)Bf_HiTree_Lumi!=EvtInfo->LumiNo)) { cout<<"Error: not matched "<<i<<" | (Hlt,Bfr,Hi) | "; cout<<"EvtNo("<<Bf_HLT_Event<<","<<EvtInfo->EvtNo<<","<<Bf_HiTree_Evt<<") "; cout<<"RunNo("<<Bf_HLT_Run<<","<<EvtInfo->RunNo<<","<<Bf_HiTree_Run<<") "; cout<<"LumiNo("<<Bf_HLT_LumiBlock<<","<<EvtInfo->LumiNo<<","<<Bf_HiTree_Lumi<<")"<<endl; continue; } } //Do oyur analysis here //example: checking GenInfo for(int j=0;j<GenInfo->size;j++){ if( int(GenInfo->pdgId[j]/100)%100 == 5){ // cout<<GenInfo->pdgId[j]<<endl; // if(abs(GenInfo->pdgId[GenInfo->da1[j]]) == 443 || abs(GenInfo->pdgId[GenInfo->da2[j]]) == 443){ // printDa(GenInfo, j, 1); // } if(abs(GenInfo->pdgId[j])==521) if(GenInfo->da1[j] != -1) if(abs(GenInfo->pdgId[GenInfo->da1[j]]) == 443) if(abs(GenInfo->pdgId[GenInfo->da2[j]]) == 211) { //printDa(GenInfo, j, 1); } if(abs(GenInfo->pdgId[j])==521) if(GenInfo->da1[j] != -1) if(abs(GenInfo->pdgId[GenInfo->da1[j]]) == 443) if((abs(GenInfo->pdgId[GenInfo->da2[j]])/100)%100 == 3) { //printDa(GenInfo, j, 1); } if(abs(GenInfo->pdgId[j])==511) if(GenInfo->da1[j] != -1) if(abs(GenInfo->pdgId[GenInfo->da1[j]]) == 443) if((abs(GenInfo->pdgId[GenInfo->da2[j]])/100)%100 == 3) { //printDa(GenInfo, j, 1); } } } bool isBsig = false; for(int j=0;j<BInfo->size;j++){ int rtk1idx = BInfo->rftk1_index[j]; int rtk2idx = BInfo->rftk2_index[j]; int rmu1idx = BInfo->uj_rfmu1_index[BInfo->rfuj_index[j]]; int rmu2idx = BInfo->uj_rfmu2_index[BInfo->rfuj_index[j]]; int gtk1idx = TrackInfo->geninfo_index[BInfo->rftk1_index[j]]; int gtk2idx = TrackInfo->geninfo_index[BInfo->rftk2_index[j]]; int gmu1idx = MuonInfo->geninfo_index[BInfo->uj_rfmu1_index[BInfo->rfuj_index[j]]]; int gmu2idx = MuonInfo->geninfo_index[BInfo->uj_rfmu2_index[BInfo->rfuj_index[j]]]; //some recon cut bool cut = false; if( BInfo->mass[j] > min && BInfo->mass[j] < max && BInfo->pt[j] > 10 && BInfo->pt[j] < 1000 && fabs(BInfo->eta[j]) < 2.4 ){ cut = true; } // if( // BInfo->mass[j] > min && BInfo->mass[j] < max && BInfo->pt[j] > 10 && BInfo->pt[j] < 1000 // && ((fabs(MuonInfo->eta[rmu1idx]) < 1.2 && MuonInfo->pt[rmu1idx] > 3.5) || (fabs(MuonInfo->eta[rmu1idx]) > 1.2 && fabs(MuonInfo->eta[rmu1idx]) < 2.1 && MuonInfo->pt[rmu1idx] > (5.77-1.8*fabs(MuonInfo->eta[rmu1idx]))) || (fabs(MuonInfo->eta[rmu1idx]) > 2.1 && fabs(MuonInfo->eta[rmu1idx]) < 2.4 && MuonInfo->pt[rmu1idx] > 1.8)) // && MuonInfo->TMOneStationTight[rmu1idx] && MuonInfo->i_nPixelLayer[rmu1idx] > 0 && (MuonInfo->i_nPixelLayer[rmu1idx] + MuonInfo->i_nStripLayer[rmu1idx]) > 5 && MuonInfo->dxyPV[rmu1idx] < 0.3 && MuonInfo->dzPV[rmu1idx] < 20 && MuonInfo->isGlobalMuon[rmu1idx] // && ((fabs(MuonInfo->eta[rmu2idx]) < 1.2 && MuonInfo->pt[rmu2idx] > 3.5) || (fabs(MuonInfo->eta[rmu2idx]) > 1.2 && fabs(MuonInfo->eta[rmu2idx]) < 2.1 && MuonInfo->pt[rmu2idx] > (5.77-1.8*fabs(MuonInfo->eta[rmu2idx]))) || (fabs(MuonInfo->eta[rmu2idx]) > 2.1 && fabs(MuonInfo->eta[rmu2idx]) < 2.4 && MuonInfo->pt[rmu2idx] > 1.8)) // && MuonInfo->TMOneStationTight[rmu2idx] && MuonInfo->i_nPixelLayer[rmu2idx] > 0 && (MuonInfo->i_nPixelLayer[rmu2idx] + MuonInfo->i_nStripLayer[rmu2idx]) > 5 && MuonInfo->dxyPV[rmu2idx] < 0.3 && MuonInfo->dzPV[rmu2idx] < 20 && MuonInfo->isGlobalMuon[rmu2idx] // && TrackInfo->highPurity[rtk1idx] // && TrackInfo->pt[rtk1idx] > 1.0 // && fabs(TrackInfo->eta[rtk1idx]) < 2.4 // && fabs(BInfo->eta[j]) < 2.4 // && TMath::Prob(BInfo->vtxchi2[j],BInfo->vtxdof[j]) > 0.005 // ){ // cut = true; // } if(!cut) continue; //identify B sig Bmass->Fill(BInfo->mass[j]); bool isBsig = false; if(gmu1idx != -1 && gmu2idx != -1) if(abs(GenInfo->pdgId[gmu1idx]) == 13 && abs(GenInfo->pdgId[gmu2idx]) == 13) if((GenInfo->mo1[gmu1idx]) != -1 && (GenInfo->mo1[gmu2idx]) != -1 && GenInfo->mo1[gmu1idx] == GenInfo->mo1[gmu2idx]) if(abs(GenInfo->pdgId[GenInfo->mo1[gmu1idx]]) == 443 && abs(GenInfo->pdgId[GenInfo->mo1[gmu2idx]]) == 443) if(GenInfo->mo1[GenInfo->mo1[gmu1idx]] != -1) if(gtk1idx != -1) if(GenInfo->mo1[gtk1idx] != -1) if(GenInfo->mo1[gtk1idx] == GenInfo->mo1[GenInfo->mo1[gmu1idx]] && abs(GenInfo->pdgId[GenInfo->mo1[gtk1idx]]) == 521 && abs(GenInfo->pdgId[gtk1idx]) == 321) isBsig = true; if(!isBsig) Bmass_nosig->Fill(BInfo->mass[j]); //identify jpsi + ? if(gmu1idx != -1 && gmu2idx != -1) if(abs(GenInfo->pdgId[gmu1idx]) == 13 && abs(GenInfo->pdgId[gmu2idx]) == 13) if((GenInfo->mo1[gmu1idx]) != -1 && (GenInfo->mo1[gmu2idx]) != -1 && GenInfo->mo1[gmu1idx] == GenInfo->mo1[gmu2idx]) if(abs(GenInfo->pdgId[GenInfo->mo1[gmu1idx]]) == 443 && abs(GenInfo->pdgId[GenInfo->mo1[gmu2idx]]) == 443) { int mmu1idx = GenInfo->mo1[gmu1idx]; int mmu2idx = GenInfo->mo1[gmu2idx]; int mjpsiidx = GenInfo->mo1[mmu1idx]; //B+ to jpsi pi+ if(gtk1idx != -1){ int mtk1idx = GenInfo->mo1[gtk1idx]; if(mtk1idx != 1){ int mtk1pdg = GenInfo->pdgId[mtk1idx]; int tk1pdg = GenInfo->pdgId[gtk1idx]; if(mtk1idx == mjpsiidx && abs(mtk1pdg) == 521 && abs(tk1pdg) == 211){ if(gtk1idx == GenInfo->da2[mtk1idx]){ //cout<<"-----"<<endl; //printDa(GenInfo, mtk1idx, 1); //cout<<"-----"<<endl; //printDa(GenInfo, mtk1idx, 1); //cout<<"Bmass: "<<BInfo->mass[j]<<endl; BmassBpPi->Fill(BInfo->mass[j]); } else{ //printDa(GenInfo, mtk1idx, 1); //cout<<"Bmass: "<<BInfo->mass[j]<<endl; BmassBpXPi->Fill(BInfo->mass[j]); } } } //B+ to jpsi K if(abs(GenInfo->pdgId[GenInfo->mo1[mmu1idx]]) == 521){ int bidx = GenInfo->mo1[mmu1idx]; int bda2idx = GenInfo->da2[bidx]; int bda2pdg = GenInfo->pdgId[bda2idx]; int tkancestor = getBAncestor(GenInfo, gtk1idx, 521); /* if(tkancestor != -1){ cout<<"tk1 pt: "<<GenInfo->pt[gtk1idx]<<endl; cout<<"tk1anc: "<<tkancestor<<endl; cout<<"tk1anc pdg: "<<GenInfo->pdgId[tkancestor]<<endl; cout<<"bidx: "<<bidx<<endl; printDa(GenInfo, tkancestor, 1); }*/ if((abs(bda2pdg)/100)%100==3 && abs(bda2pdg) != 321 ){ //printDa(GenInfo, bidx, 1); //cout<<"Bmass: "<<BInfo->mass[j]<<endl; BmassBpK->Fill(BInfo->mass[j]); if(tkancestor == bidx){ BmassBpK_tkmatch->Fill(BInfo->mass[j]); } else{BmassBpK_tknotmatch->Fill(BInfo->mass[j]);} if(BtypeCountBpK.find(abs(bda2pdg)) == BtypeCountBpK.end()){ BtypeCountBpK[abs(bda2pdg)] = 1; } else{ BtypeCountBpK[abs(bda2pdg)] += 1; } } } //B0 to jpsi K if(abs(GenInfo->pdgId[GenInfo->mo1[mmu1idx]]) == 511){ int bidx = GenInfo->mo1[mmu1idx]; int bda2idx = GenInfo->da2[bidx]; int bda2pdg = GenInfo->pdgId[bda2idx]; int tkancestor = getBAncestor(GenInfo, gtk1idx, 511); if((abs(bda2pdg)/100)%100==3){ //printDa(GenInfo, bidx, 1); //cout<<"Bmass: "<<BInfo->mass[j]<<endl; BmassB0K->Fill(BInfo->mass[j]); if(tkancestor == bidx){ BmassB0K_tkmatch->Fill(BInfo->mass[j]); } else{BmassB0K_tknotmatch->Fill(BInfo->mass[j]);} if(BtypeCountB0K.find(abs(bda2pdg)) == BtypeCountB0K.end()){ BtypeCountB0K[abs(bda2pdg)] = 1; } else{ BtypeCountB0K[abs(bda2pdg)] += 1; } } } } } } // } cout<<"Bp + K type count========="<<endl; std::map<int,int>::iterator BtypeCountBpKIt; for(BtypeCountBpKIt = BtypeCountBpK.begin(); BtypeCountBpKIt != BtypeCountBpK.end(); BtypeCountBpKIt++){ cout<<"Ktype: "<<BtypeCountBpKIt->first<<" Count: "<<BtypeCountBpKIt->second<<endl; } cout<<"B0 + K type count========="<<endl; std::map<int,int>::iterator BtypeCountB0KIt; for(BtypeCountB0KIt = BtypeCountB0K.begin(); BtypeCountB0KIt != BtypeCountB0K.end(); BtypeCountB0KIt++){ cout<<"Ktype: "<<BtypeCountB0KIt->first<<" Count: "<<BtypeCountB0KIt->second<<endl; } outf->Write(); cout<<"--- Writing finished"<<endl; outf->Close(); cout<<"--- In/Output files"<<endl; cout<<ifname<<endl; cout<<outfile<<endl; cout<<endl; return 1; }
void ctlMET(const TString inputFileName = "Wenu_p_select.root") { // // Settings // gStyle->SetOptStat(0); // Int_t NVTXBINS = 45; // 70 for Wenu_p, 35 for Wmunu_p // // Setup input ntuple // TFile* inputFile = new TFile(inputFileName); TTree* inputTree = (TTree*)inputFile->Get("demo/Events"); // // Declare variables to read in ntuple // Int_t nVtx, nEvents; TVector2 *t2_slimMet=0, *t2_slimMetTxy=0; inputTree->SetBranchAddress("npv", &nVtx); // number of vertices inputTree->SetBranchAddress("t2_slimMet", &t2_slimMet); inputTree->SetBranchAddress("t2_slimMetTxy", &t2_slimMetTxy); // // Declare histograms // TH1D *hSlimMet = new TH1D("hSlimMet","",100,0,150); hSlimMet->SetStats(0); hSlimMet->SetLineColor(1); TH1D *hSlimMetTxy = new TH1D("hSlimMetTxy","",100,0,150); hSlimMetTxy->SetStats(0); hSlimMetTxy->SetLineColor(2); TH1D *hPhi = new TH1D("hPhi","",100,-3.5,3.5); hPhi->SetStats(0); hPhi->SetLineColor(1); TH1D *hPhiTxy = new TH1D("hPhiTxy","",100,-3.5,3.5); hPhiTxy->SetStats(0); hPhiTxy->SetLineColor(4); TH2D *hMETnVtx_x = new TH2D("hMETnVtx_x","MET_{x} v. Number of Vertices",NVTXBINS,0,NVTXBINS,100,-150,150); hMETnVtx_x->GetXaxis()->SetTitle("Number of vertices"); hMETnVtx_x->GetYaxis()->SetTitle("MET_{x} [GeV]"); TH2D *hMETnVtx_y = new TH2D("hMETnVtx_y","MET_{y} v. Number of Vertices",NVTXBINS,0,NVTXBINS,100,-150,150); hMETnVtx_y->GetXaxis()->SetTitle("Number of vertices"); hMETnVtx_y->GetYaxis()->SetTitle("MET_{y} [GeV]"); TH2D *hMETnVtx_Txy_x = new TH2D("hMETnVtx_Txy_x","MET_{x} v. Number of Vertices",NVTXBINS,0,NVTXBINS,100,-150,150); hMETnVtx_Txy_x->GetXaxis()->SetTitle("Number of vertices"); hMETnVtx_Txy_x->GetYaxis()->SetTitle("MET_{x} [GeV]"); TH2D *hMETnVtx_Txy_y = new TH2D("hMETnVtx_Txy_y","MET_{y} v. Number of Vertices",NVTXBINS,0,NVTXBINS,100,-150,150); hMETnVtx_Txy_y->GetXaxis()->SetTitle("Number of vertices"); hMETnVtx_Txy_y->GetYaxis()->SetTitle("MET_{y} [GeV]"); Int_t totalEvents=0; double phi; for(int jentry=0;jentry<inputTree->GetEntries();jentry++) { inputTree->GetEntry(jentry); totalEvents += nEvents; // // Fill histograms // hMETnVtx_x->Fill(nVtx,t2_slimMet->Px()); hMETnVtx_y->Fill(nVtx,t2_slimMet->Py()); hMETnVtx_Txy_x->Fill(nVtx,t2_slimMetTxy->Px()); hMETnVtx_Txy_y->Fill(nVtx,t2_slimMetTxy->Py()); hSlimMet ->Fill(t2_slimMet->Mod()); hSlimMetTxy ->Fill(t2_slimMetTxy->Mod()); phi = t2_slimMet->Phi(); if( phi >TMath::Pi()) phi -= 2*TMath::Pi(); hPhi->Fill(phi); phi = t2_slimMetTxy->Phi(); if( phi >TMath::Pi()) phi -= 2*TMath::Pi(); hPhiTxy->Fill(phi); } cout << "totalEvents is " << totalEvents << endl; // Loop through nVtx bins and find the mean value of metx and mety in each bin // Plot nVtx v. mean values of metx/mety in a separate histogram (1 for metx and 1 for mety) TH1D* hmetx_proj = new TH1D(); TH1D* hmety_proj = new TH1D(); Double_t meanmetx, meanmety; TH2D* hMEtMeanVtx_x = new TH2D("hMEtMeanVtx_x","MET_{x} v. Number of vertices",NVTXBINS,0,NVTXBINS,100,-25,7); hMEtMeanVtx_x->GetXaxis()->SetTitle("Number of vertices"); hMEtMeanVtx_x->GetYaxis()->SetTitle("<MET_{x}> [GeV]"); TH2D* hMEtMeanVtx_y = new TH2D("hMEtMeanVtx_y","MET_{y} v. Number of vertices",NVTXBINS,0,NVTXBINS,100,-25,7); hMEtMeanVtx_y->GetXaxis()->SetTitle("Number of vertices"); hMEtMeanVtx_y->GetYaxis()->SetTitle("<MET_{y}> [GeV]"); TH2D* hMEtMeanVtx_Txy_x = new TH2D("hMEtMeanVtx_Txy_x","MET_{x} v. Number of vertices",NVTXBINS,0,NVTXBINS,100,-25,7); hMEtMeanVtx_Txy_x->GetXaxis()->SetTitle("Number of vertices"); hMEtMeanVtx_Txy_x->GetYaxis()->SetTitle("<MET_{x}> [GeV]"); TH2D* hMEtMeanVtx_Txy_y = new TH2D("hMEtMeanVtx_Txy_y","MET_{y} v. Number of vertices",NVTXBINS,0,NVTXBINS,100,-25,7); hMEtMeanVtx_Txy_y->GetXaxis()->SetTitle("Number of vertices"); hMEtMeanVtx_Txy_y->GetYaxis()->SetTitle("<MET_{y}> [GeV]"); for(int jbin=1;jbin<hMEtMeanVtx_x->GetNbinsX()+1;jbin++) { hmetx_proj = hMETnVtx_x->ProjectionY("metx_proj",jbin,jbin+1,""); hmety_proj = hMETnVtx_y->ProjectionY("mety_proj",jbin,jbin+1,""); meanmetx = hmetx_proj->GetMean(); meanmety = hmety_proj->GetMean(); hMEtMeanVtx_x->Fill(jbin,meanmetx); hMEtMeanVtx_y->Fill(jbin,meanmety); hmetx_proj = hMETnVtx_Txy_x->ProjectionY("metx_proj",jbin,jbin+1,""); hmety_proj = hMETnVtx_Txy_y->ProjectionY("mety_proj",jbin,jbin+1,""); meanmetx = hmetx_proj->GetMean(); meanmety = hmety_proj->GetMean(); hMEtMeanVtx_Txy_x->Fill(jbin,meanmetx); hMEtMeanVtx_Txy_y->Fill(jbin,meanmety); } // // Save plots // TLegend *leg_Vtx_x = new TLegend(0.15,0.15,0.4,0.3,NULL,"brNDC"); leg_Vtx_x->SetTextFont(62); leg_Vtx_x->SetTextSize(0.03330866); leg_Vtx_x->SetLineColor(1); leg_Vtx_x->SetLineStyle(1); leg_Vtx_x->SetLineWidth(1); leg_Vtx_x->SetFillColor(0); leg_Vtx_x->SetFillStyle(1001); leg_Vtx_x->SetBorderSize(0); leg_Vtx_x->AddEntry(hMEtMeanVtx_x,"Type1PfMet","p"); leg_Vtx_x->AddEntry(hMEtMeanVtx_Txy_x,"Type1PfMet + Txy","p"); TCanvas* tc_metVtx_x = new TCanvas(); tc_metVtx_x->cd(); hMEtMeanVtx_x->SetMarkerStyle(24); hMEtMeanVtx_x->SetMarkerSize(1); hMEtMeanVtx_x->SetMarkerColor(kRed); hMEtMeanVtx_x->Draw("p0"); //hSlimMet->Draw("p9"); hMEtMeanVtx_Txy_x->SetMarkerStyle(26); hMEtMeanVtx_Txy_x->SetMarkerSize(1); hMEtMeanVtx_Txy_x->SetMarkerColor(kBlue); hMEtMeanVtx_Txy_x->Draw("samep0"); leg_Vtx_x->Draw("same"); tc_metVtx_x->Print("Plots/MetvsVtx_x.png"); tc_metVtx_x->Print("Plots/MetvsVtx_x.pdf"); //------------------- // Met vs Vtx y-axis //------------------- TLegend *leg_Vtx_y = new TLegend(0.15,0.15,0.4,0.3,NULL,"brNDC"); leg_Vtx_y->SetTextFont(62); leg_Vtx_y->SetTextSize(0.03330866); leg_Vtx_y->SetLineColor(1); leg_Vtx_y->SetLineStyle(1); leg_Vtx_y->SetLineWidth(1); leg_Vtx_y->SetFillColor(0); leg_Vtx_y->SetFillStyle(1001); leg_Vtx_y->SetBorderSize(0); leg_Vtx_y->AddEntry(hMEtMeanVtx_y,"Type1PfMet","p"); leg_Vtx_y->AddEntry(hMEtMeanVtx_Txy_y,"Type1PfMet + Txy","p"); TCanvas* tc_metVtx_y = new TCanvas(); tc_metVtx_y->cd(); hMEtMeanVtx_y->SetMarkerStyle(24); hMEtMeanVtx_y->SetMarkerSize(1); hMEtMeanVtx_y->SetMarkerColor(kRed); hMEtMeanVtx_y->Draw("p0"); //hSlimMet->Draw("p9"); hMEtMeanVtx_Txy_y->SetMarkerStyle(26); hMEtMeanVtx_Txy_y->SetMarkerSize(1); hMEtMeanVtx_Txy_y->SetMarkerColor(kBlue); hMEtMeanVtx_Txy_y->Draw("same"); leg_Vtx_y->Draw("same"); tc_metVtx_y->Print("Plots/MetvsVtx_y.png"); tc_metVtx_y->Print("Plots/MetvsVtx_y.pdf"); /********************* //--------------------- // phi distribution //--------------------- TCanvas* tc_phi = new TCanvas(); tc_phi->cd(); hPhi->SetLineColor(kRed); hPhi->Draw(""); hPhi->SetLineColor(kRed); hPhi->Draw(""); htype1corr->Draw("same"); leg->Draw("same"); cmet->Print("met.png"); cmet->Close(); TCanvas* cmetphi = new TCanvas(); cmetphi->cd(); htype1phi->Draw("same"); htype1phicorr->Draw("same"); leg->Draw("same"); cmetphi->Print("metphi.png"); // cmetphi->Close(); TCanvas* cmetx = new TCanvas(); cmetx->cd(); hmetx->Draw(); cmetx->Print("metx.png"); cmetx->Close(); TCanvas* cmety = new TCanvas(); cmety->cd(); hmety->Draw(); cmety->Print("mety.png"); cmety->Close(); TCanvas* cmetxfit = new TCanvas(); cmetxfit->cd(); hmetxfit->Draw(); cmetxfit->Print("metxfit.png"); cmetxfit->Close(); TCanvas* cmetyfit = new TCanvas(); cmetyfit->cd(); hmetyfit->Draw(); cmetyfit->Print("metyfit.png"); cmetyfit->Close(); ***************/ }
int main(int argc, char *argv[]) { TRandom rng; rng.SetSeed(2014); hxx_tree data; std::string opt, infile, outroot, outdir; koptions options(argc, argv); //check for the --help option: if ( options.find("--help") ) { usage(); } //options.set("--seed=", seed); //if (seed > 0) rng.SetSeed(seed); double met_smear = 30.0; options.set("--met_smear=", met_smear); int num_smear = 1; options.set("--num_smear=", num_smear); double fake_rate = 0.0; options.set("--fake_rate=", fake_rate); int mode_8tev = options.find("--8tev"); int pub_plots = options.find("--pub_plots"); double lumi = 300; double met_cut = 250.0; if (mode_8tev) { lumi = 20.0; met_cut = 250; cout << "INFO: settings for sqrt(s) = 8 TeV\n"; } else { cout << "INFO: settings for sqrt(s) = 14 TeV\n"; } cout << "INFO: lumi: " << lumi << "\n"; cout << "INFO: MET cut: " << met_cut << "\n"; //check for unrecognized options (beginning with -- or -) while(options.unrecognized_option(opt)) { cout << "WARNING: unrecognized option:" << opt << "\n"; usage(); } if (options.size() != 3) { usage(); } options.shift_argument(infile); options.shift_argument(outroot); options.shift_argument(outdir); cout << "INFO: reading analysis tree file: " << infile << "\n"; cout << "INFO: writing histogram root file: " << outroot << "\n"; cout << "INFO: writing results to directory: " << outdir << "\n"; cout << "INFO: MET smearing amount is " << met_smear << "\n"; cout << "INFO: MET smearing number is " << num_smear << "\n"; cout << "INFO: W+jets fake rate is " << fake_rate << "\n"; auto_write aw; cutflow_tool cutflow; histogram_manager h0mll(new TH1F("h0mll","",60,60.0,120.0)); if (pub_plots) { h0mll.add_sample(1, "_z"); h0mll.add_sample(2, "_h"); h0mll.add_sample(3, "_w"); h0mll.add_sample(4, "_top"); cutflow.add_sample_name(1, "Z,ZZ,ZW"); cutflow.add_sample_name(2, "Higgs"); cutflow.add_sample_name(3, "W,WW"); cutflow.add_sample_name(4, "tt"); } else { h0mll.add_sample(1, "_zjj"); h0mll.add_sample(2, "_zz_zw"); h0mll.add_sample(3, "_ww"); h0mll.add_sample(4, "_tt"); h0mll.add_sample(5, "_hzz"); h0mll.add_sample(6, "_zh"); h0mll.add_sample(7, "_wh"); h0mll.add_sample(8, "_wjjj"); cutflow.add_sample_name(1, "Zjj"); cutflow.add_sample_name(2, "ZZ,ZW"); cutflow.add_sample_name(3, "WW"); cutflow.add_sample_name(4, "tt"); cutflow.add_sample_name(5, "HZZ"); cutflow.add_sample_name(6, "ZH"); cutflow.add_sample_name(7, "WH"); cutflow.add_sample_name(8, "W+jets"); } h0mll.add_sample(20, "_hxx1"); h0mll.add_sample(21, "_hxx10"); h0mll.add_sample(22, "_hxx100"); h0mll.add_sample(23, "_hxx500"); h0mll.add_sample(24, "_hxx1000"); cutflow.add_sample_name(20, "HXX1"); cutflow.add_sample_name(21, "HXX10"); cutflow.add_sample_name(22, "HXX100"); cutflow.add_sample_name(23, "HXX500"); cutflow.add_sample_name(24, "HXX1000"); h0mll.add_sample(30, "_hzp_100_1"); h0mll.add_sample(31, "_hzp_100_10"); h0mll.add_sample(32, "_hzp_100_100"); h0mll.add_sample(33, "_hzp_100_500"); h0mll.add_sample(34, "_hzp_100_1000"); h0mll.add_sample(35, "_hzp_1000_1"); h0mll.add_sample(36, "_hzp_1000_10"); h0mll.add_sample(37, "_hzp_1000_100"); h0mll.add_sample(38, "_hzp_1000_500"); h0mll.add_sample(39, "_hzp_1000_1000"); cutflow.add_sample_name(30, "HZP_100_1"); cutflow.add_sample_name(31, "HZP_100_10"); cutflow.add_sample_name(32, "HZP_100_100"); cutflow.add_sample_name(33, "HZP_100_500"); cutflow.add_sample_name(34, "HZP_100_1000"); cutflow.add_sample_name(35, "HZP_1000_1"); cutflow.add_sample_name(36, "HZP_1000_10"); cutflow.add_sample_name(37, "HZP_1000_100"); cutflow.add_sample_name(38, "HZP_1000_500"); cutflow.add_sample_name(39, "HZP_1000_1000"); h0mll.add_sample(40, "_hzpzp_100_1"); h0mll.add_sample(41, "_hzpzp_100_10"); h0mll.add_sample(42, "_hzpzp_100_100"); h0mll.add_sample(43, "_hzpzp_100_500"); h0mll.add_sample(44, "_hzpzp_100_1000"); h0mll.add_sample(45, "_hzpzp_1000_1"); h0mll.add_sample(46, "_hzpzp_1000_10"); h0mll.add_sample(47, "_hzpzp_1000_100"); h0mll.add_sample(48, "_hzpzp_1000_500"); h0mll.add_sample(49, "_hzpzp_1000_1000"); cutflow.add_sample_name(40, "HZPZP_100_1"); cutflow.add_sample_name(41, "HZPZP_100_10"); cutflow.add_sample_name(42, "HZPZP_100_100"); cutflow.add_sample_name(43, "HZPZP_100_500"); cutflow.add_sample_name(44, "HZPZP_100_1000"); cutflow.add_sample_name(45, "HZPZP_1000_1"); cutflow.add_sample_name(46, "HZPZP_1000_10"); cutflow.add_sample_name(47, "HZPZP_1000_100"); cutflow.add_sample_name(48, "HZPZP_1000_500"); cutflow.add_sample_name(49, "HZPZP_1000_1000"); h0mll.add_auto_write(aw); TH1F hfit_bkg("sample_1","", 100,0.0,300.0); TH1F hfit_sig20("signal20","", 100,0.0,300.0); TH1F hfit_sig21("signal21","", 100,0.0,300.0); TH1F hfit_sig22("signal22","", 100,0.0,300.0); TH1F hfit_sig23("signal23","", 100,0.0,300.0); TH1F hfit_sig24("signal24","", 100,0.0,300.0); int nsig = 0; double wsig = 0.0; hfit_bkg.Sumw2(); hfit_sig20.Sumw2(); hfit_sig21.Sumw2(); hfit_sig22.Sumw2(); hfit_sig23.Sumw2(); hfit_sig24.Sumw2(); //control plots (no pre-selection) histogram_manager hcnjet (new TH1F("hcnjet", "", 10, 0.0, 10.0), h0mll, aw); histogram_manager hcmjjon (new TH1F("hcmjjon", "", 75, 0.0, 150.0), h0mll, aw); histogram_manager hcmjjoff(new TH1F("hcmjjoff","", 100, 0.0, 500.0), h0mll, aw); //test new variables histogram_manager htestx (new TH1F("htestx", "", 25, 0.0, 3.2), h0mll, aw); histogram_manager htesty (new TH1F("htesty", "", 25, 0.0, 200.0), h0mll, aw); //histograms at stage 0 histogram_manager h0mjj (new TH1F("h0mjj", "", 100, 0.0, 500.0), h0mll, aw); histogram_manager h0mlj (new TH1F("h0mlj", "", 100, 0.0, 500.0), h0mll, aw); histogram_manager h0mlljj (new TH1F("h0mlljj", "", 100, 0.0, 500.0), h0mll, aw); histogram_manager h0mllj (new TH1F("h0mllj", "", 100, 0.0, 500.0), h0mll, aw); histogram_manager h0met (new TH1F("h0met", "", 100, 0.0, 300.0), h0mll, aw); histogram_manager h0njet (new TH1F("h0njet", "", 10, 0.0, 10.0), h0mll, aw); histogram_manager h0nbjet (new TH1F("h0nbjet", "", 8, 0.0, 8.0), h0mll, aw); histogram_manager h0jdphi (new TH1F("h0jdphi", "", 100, 0.0, 3.2), h0mll, aw); histogram_manager h0ptja (new TH1F("h0ptja","", 32, 0.0, 300.0), h0mll, aw); histogram_manager h0drlla (new TH1F("h0drlla","", 81, 0.0, 8.1), h0mll, aw); histogram_manager h0drllb (new TH1F("h0drllb","", 81, 0.0, 8.1), h0mll, aw); histogram_manager h0dphizz (new TH1F("h0dphizz", "", 32, 0.0, 3.2), h0mll, aw); histogram_manager h0dphizllmet (new TH1F("h0dphizllmet", "", 32, 0.0, 3.2), h0mll, aw); histogram_manager h0ht (new TH1F("h0ht", "", 100, 0.0, 500.0), h0mll, aw); histogram_manager h0l1pt (new TH1F("h0l1pt", "", 100, 0.0, 300.0), h0mll, aw); histogram_manager h0l2pt (new TH1F("h0l2pt", "", 100, 0.0, 300.0), h0mll, aw); histogram_manager h0j1pt (new TH1F("h0j1pt", "", 100, 0.0, 300.0), h0mll, aw); histogram_manager h0j2pt (new TH1F("h0j2pt", "", 100, 0.0, 300.0), h0mll, aw); histogram_manager h0l1eta(new TH1F("h0l1eta","", 60, -3.0, 3.0), h0mll, aw); histogram_manager h0l2eta(new TH1F("h0l2eta","", 60, -3.0, 3.0), h0mll, aw); histogram_manager h0j1eta(new TH1F("h0j1eta","", 60, -3.0, 3.0), h0mll, aw); histogram_manager h0j2eta(new TH1F("h0j2eta","", 60, -3.0, 3.0), h0mll, aw); //histograms at stage 1 histogram_manager h1mll (new TH1F("h1mll", "", 60, 60.0, 120.0), h0mll, aw); histogram_manager h1mjj (new TH1F("h1mjj", "", 100, 0.0, 500.0), h0mll, aw); histogram_manager h1mlj (new TH1F("h1mlj", "", 100, 0.0, 500.0), h0mll, aw); histogram_manager h1mlljj (new TH1F("h1mlljj", "", 100, 0.0, 500.0), h0mll, aw); histogram_manager h1mllj (new TH1F("h1mllj", "", 100, 0.0, 500.0), h0mll, aw); histogram_manager h1met (new TH1F("h1met", "", 100, 0.0, 300.0), h0mll, aw); histogram_manager h1njet (new TH1F("h1njet", "", 10, 0.0, 10.0), h0mll, aw); histogram_manager h1nbjet (new TH1F("h1nbjet", "", 8, 0.0, 8.0), h0mll, aw); histogram_manager h1jdphi (new TH1F("h1jdphi", "", 100, 0.0, 3.2), h0mll, aw); histogram_manager h1ptja (new TH1F("h1ptja","", 100, 0.0, 300.0), h0mll, aw); histogram_manager h1drlla (new TH1F("h1drlla","", 81, 0.0, 8.1), h0mll, aw); histogram_manager h1drllb (new TH1F("h1drllb","", 81, 0.0, 8.1), h0mll, aw); histogram_manager h1dphizz (new TH1F("h1dphizz", "", 100, 0.0, 3.2), h0mll, aw); histogram_manager h1dphizllmet (new TH1F("h1dphizllmet", "", 100, 0.0, 3.2), h0mll, aw); cout << "INFO: opening file: " << infile << "\n"; TFile * file = new TFile(infile.c_str()); TTree * tree = (TTree*) file->Get("hxxtree"); if (! tree) { cout << "ERROR: could not open tree.\n"; exit(0); } data.ReadTree(tree); long int numberOfEntries = tree->GetEntries(); //tree->Print(); int count = 0; int nupdate = numberOfEntries / 20; if (nupdate < 1) nupdate=1; cout << "PROGRESS: "; int prescale = 0; int iprescale = 0; // Loop over all events for(Int_t entry = 0; entry < numberOfEntries; ++entry) { count++; if (count % nupdate == 0) { cout << "."; cout.flush(); } if (iprescale < prescale) { iprescale++; continue; } else { iprescale = 0; } tree->GetEntry(entry); int num_smear_event = num_smear; if (data.sample == 1) { num_smear_event = num_smear * 10; } //if (data.sample == 4) { //num_smear_event = num_smear * 10; //} //if (data.sample == 3) { //num_smear_event = num_smear * 10; //} // First, apply W+jets fake rate if applicable: if (fake_rate > 0.0 && data.sample == 8) { apply_fake_rate(rng, data, fake_rate); } // remap sample id for publication plots: if (pub_plots) { switch (data.sample) { case 1: data.sample = 1; break; case 2: data.sample = 1; break; case 3: data.sample = 3; break; case 4: data.sample = 4; break; case 5: data.sample = 2; break; case 6: data.sample = 2; break; case 7: data.sample = 2; break; case 8: data.sample = 3; break; } } double mjjon; control_vars(data, mjjon); if (mjjon > 0.0) hcmjjon.Fill(data.sample, mjjon, data.weight); hcnjet.Fill(data.sample, data.jet_pt->size(), data.weight); //if (data.l1_pt < 12.0) continue; //if (data.l2_pt < 12.0) continue; if (data.l1_pt < 20.0) continue; if (data.l2_pt < 15.0) continue; // prune jet list according to analysis selection: for (int i=0; i<data.jet_pt->size(); i++) { int veto = 0; if (data.jet_pt->at(i) < 15.0) veto = 1; if (fabs(data.jet_eta->at(i)) > 2.5) veto = 1; if (veto) { data.erase_jet(i); i--; } } if (data.jet_pt->size() != data.jet_btag->size()) { cout << "ERROR: Jet vectors out of sync. Something is wrong.\n"; exit(0); } int nbtag = 0; for (int i=0; i<data.jet_btag->size(); i++) { if (data.jet_btag->at(i)) nbtag++; } //preselection cuts: if (data.jet_pt->size() < 2) continue; if (data.nmuon + data.nelec > 2) continue; // checking 2-jet bin: //if (data.jet_pt->size() > 2) continue; cutflow.increment(0, data.sample, data.weight); double mlj, pt_ja, dr_lla, dr_llb, mjj, mjj_off, mllj, mlljj, dphi_zz, zll_phi, x, y; best_mlj(data, mlj); kinematic_vars(data, pt_ja, dr_lla, dr_llb, mjj, mjj_off, mllj, mlljj, dphi_zz, zll_phi, x, y); if (mjj_off > 0.0) { hcmjjoff.Fill(data.sample, mjj_off, data.weight); } // Here we smear the MET to account for pile-up effects: vector<double> met; vector<double> met_phi; vector<double> jet_dphi; vector<double> zllmet_dphi; // use reduced weight when looping over entire MET vector: double met_weight = (data.weight / (double) num_smear_event); double nopu_metx = data.nopu_met * cos(data.nopu_met_phi); double nopu_mety = data.nopu_met * sin(data.nopu_met_phi); for (int i=0; i<num_smear_event; i++) { double metx = nopu_metx + rng.Gaus() * met_smear; double mety = nopu_mety + rng.Gaus() * met_smear; double new_met = sqrt(metx*metx + mety*mety); double new_met_phi = atan2(mety, metx); int min_i; double new_jet_dphi = min_delta_phi(new_met_phi, *data.jet_phi, min_i,-1,1); double new_zllmet_dphi = delta_phi(new_met_phi, zll_phi); met.push_back(new_met); met_phi.push_back(new_met_phi); jet_dphi.push_back(new_jet_dphi); zllmet_dphi.push_back(new_zllmet_dphi); } // high MET test: //if (data.nopu_met < 100.0) continue; h0mll.Fill(data.sample, data.mll, data.weight); if (data.jet_pt->size() > 0) { h0j1pt .Fill(data.sample, data.jet_pt ->at(0), data.weight); h0j1eta .Fill(data.sample, data.jet_eta->at(0), data.weight); } if (data.jet_pt->size() > 1) { h0j2pt .Fill(data.sample, data.jet_pt ->at(1), data.weight); h0j2eta .Fill(data.sample, data.jet_eta->at(1), data.weight); } h0l1pt .Fill(data.sample, data.l1_pt, data.weight); h0l1eta .Fill(data.sample, data.l1_eta, data.weight); h0l2pt .Fill(data.sample, data.l2_pt, data.weight); h0l2eta .Fill(data.sample, data.l2_eta, data.weight); h0njet.Fill(data.sample, data.jet_pt->size(), data.weight); h0nbjet.Fill(data.sample, nbtag, data.weight); h0mjj.Fill(data.sample, mjj, data.weight); h0mlj.Fill(data.sample, mlj, data.weight); h0mlljj.Fill(data.sample, mlljj, data.weight); h0mllj.Fill(data.sample, mllj, data.weight); h0ht.Fill(data.sample, data.ht, data.weight); h0dphizz .Fill(data.sample, dphi_zz, data.weight); h0ptja .Fill(data.sample, pt_ja, data.weight); h0drlla .Fill(data.sample, dr_lla, data.weight); h0drllb .Fill(data.sample, dr_llb, data.weight); htestx .Fill(data.sample, x); htesty .Fill(data.sample, y); for (int i=0; i<met.size(); i++) { h0met .Fill(data.sample, met[i], met_weight); h0jdphi .Fill(data.sample, jet_dphi[i], met_weight); h0dphizllmet .Fill(data.sample, zllmet_dphi[i] , met_weight); } // Z-peak: if (data.mll < 82) continue; if (data.mll > 98) continue; cutflow.increment(1, data.sample, data.weight); if (mllj > 124.0) continue; cutflow.increment(2, data.sample, data.weight); if (dphi_zz > 2.25) continue; cutflow.increment(3, data.sample, data.weight); //if (mlj > 60.0) continue; // These two cuts are applied in MET loop... 0 = no cut double jet_dphi_cut = 0.0; double zllmet_dphi_cut = 0.0; //if (mlj > 120.0) continue; // h1njet. Fill(data.sample, data.jet_pt->size(), data.weight); h1mll. Fill(data.sample, data.mll, data.weight); h1mjj. Fill(data.sample, mjj, data.weight); h1mlj. Fill(data.sample, mlj, data.weight); h1mlljj. Fill(data.sample, mlljj, data.weight); h1mllj. Fill(data.sample, mllj, data.weight); h1ptja. Fill(data.sample, pt_ja, data.weight); h1drlla. Fill(data.sample, dr_lla, data.weight); h1drllb. Fill(data.sample, dr_llb, data.weight); for (int i=0; i<met.size(); i++) { double tmet =met[i]; if (tmet > 299.0) tmet = 299.; h1jdphi .Fill(data.sample, jet_dphi[i], met_weight); h1dphizllmet .Fill(data.sample, zllmet_dphi[i] , met_weight); if (jet_dphi[i] < jet_dphi_cut) continue; // APPEARS IN TWO PLACES if (zllmet_dphi[i] < zllmet_dphi_cut) continue; // APPEARS IN TWO PLACES h1met.Fill(data.sample, tmet, met_weight); } // fill limit setting histograms: for (int i=0; i<met.size(); i++) { if (met_weight > 100) { cout << "WARNING: large weight at MET stage: " << met_weight << "\n"; } double tmet =met[i]; if (tmet > 299.0) tmet = 299.; if (jet_dphi[i] < jet_dphi_cut) continue; // APPEARS IN TWO PLACES if (zllmet_dphi[i] < zllmet_dphi_cut) continue; // APPEARS IN TWO PLACES if (data.sample < 20) hfit_bkg.Fill(tmet, met_weight); if (data.sample == 20) hfit_sig20.Fill(tmet, met_weight); if (data.sample == 21) hfit_sig21.Fill(tmet, met_weight); if (data.sample == 22) hfit_sig22.Fill(tmet, met_weight); if (data.sample == 23) hfit_sig23.Fill(tmet, met_weight); if (data.sample == 24) hfit_sig24.Fill(tmet, met_weight); if (met[i] > met_cut) cutflow.increment(4, data.sample, met_weight); } } cout << "\n"; cout << "SUMMARY: read " << count << " of " << tree->GetEntries() << " events from analysis tree.\n"; TFile * foutroot = new TFile(outroot.c_str(), "RECREATE"); foutroot->cd(); aw.WriteAll(); foutroot->Close(); //cout << "SUMMARY: done writing files.\n"; cout << "Cutflow: Stage 0 (lljj preselection)\n"; cutflow.print(0); cout << "Cutflow: Stage 1 (mll cut)\n"; cutflow.print(1); cout << "Cutflow: Stage 2 (after mjj cut) \n"; cutflow.print(2); cout << "Cutflow: Stage 3 (after mjjll cut) \n"; cutflow.print(3); cout << "Cutflow: Stage 4 (after MET cut) \n"; cutflow.print(4); cout << "Fit Histogram Summary: \n"; double SIGTOT = lumi * 149.8; hfit_sig20.Scale(1.0/SIGTOT); hfit_sig21.Scale(1.0/SIGTOT); hfit_sig22.Scale(1.0/SIGTOT); hfit_sig23.Scale(1.0/SIGTOT); hfit_sig24.Scale(1.0/SIGTOT); cout << " -> using total signal events of : " << SIGTOT << "\n"; cout << " -> background integral (evts): " << hfit_bkg.GetSumOfWeights() << "\n"; cout << " -> signal 1 integral (eff): " << hfit_sig20.GetSumOfWeights() << "\n"; cout << " -> signal 10 integral (eff): " << hfit_sig21.GetSumOfWeights() << "\n"; cout << " -> signal 100 integral (eff): " << hfit_sig22.GetSumOfWeights() << "\n"; cout << " -> signal 500 integral (eff): " << hfit_sig23.GetSumOfWeights() << "\n"; cout << " -> signal 1000 integral (eff): " << hfit_sig24.GetSumOfWeights() << "\n"; cout << " -> local count of signal events: " << nsig << "\n"; cout << " -> local integral of signal weight: " << wsig << "\n"; cout << " --> signal 1 sensitivity: " << sensitivity(&hfit_sig20, &hfit_bkg, SIGTOT) << "\n"; cout << " --> signal 10 sensitivity: " << sensitivity(&hfit_sig21, &hfit_bkg, SIGTOT) << "\n"; cout << " --> signal 100 sensitivity: " << sensitivity(&hfit_sig22, &hfit_bkg, SIGTOT) << "\n"; cout << " --> signal 500 sensitivity: " << sensitivity(&hfit_sig23, &hfit_bkg, SIGTOT) << "\n"; cout << " --> signal 1000 sensitivity: " << sensitivity(&hfit_sig24, &hfit_bkg, SIGTOT) << "\n"; char name[100]; TFile * f = NULL; TH1F * h = NULL; sprintf(name, "%s/mchi1.root", outdir.c_str()); f = new TFile(name, "RECREATE"); f->cd(); h = (TH1F *) hfit_sig20.Clone("signal"); h->Write(); hfit_bkg.Write(); f->Close(); sprintf(name, "%s/mchi10.root", outdir.c_str()); f = new TFile(name, "RECREATE"); f->cd(); h = (TH1F *) hfit_sig21.Clone("signal"); h->Write(); hfit_bkg.Write(); f->Close(); sprintf(name, "%s/mchi100.root", outdir.c_str()); f = new TFile(name, "RECREATE"); f->cd(); h = (TH1F *) hfit_sig22.Clone("signal"); h->Write(); hfit_bkg.Write(); f->Close(); sprintf(name, "%s/mchi500.root", outdir.c_str()); f = new TFile(name, "RECREATE"); f->cd(); h = (TH1F *) hfit_sig23.Clone("signal"); h->Write(); hfit_bkg.Write(); f->Close(); sprintf(name, "%s/mchi1000.root", outdir.c_str()); f = new TFile(name, "RECREATE"); f->cd(); h = (TH1F *) hfit_sig24.Clone("signal"); h->Write(); hfit_bkg.Write(); f->Close(); }
void selectProbesMuEff(const TString infilename, // input ntuple const TString outputDir, // output directory const Int_t effType, // type of efficiency to compute const Bool_t doGenMatch = kFALSE, // match to generator leptons const Bool_t doWeighted = kFALSE // store events with weights ) { gBenchmark->Start("selectProbesMuEff"); //-------------------------------------------------------------------------------------------------------------- // Settings //============================================================================================================== const Double_t TAG_PT_CUT = 25; //-------------------------------------------------------------------------------------------------------------- // Main analysis code //============================================================================================================== enum { eHLTEff, eSelEff, eTrkEff, eStaEff, eStaEff_iso, ePOGIDEff, ePOGIsoEff }; if(effType > ePOGIsoEff) { cout << "Invalid effType option! Exiting..." << endl; return; } enum { eMuMu2HLT=1, eMuMu1HLT, eMuMuNoSel, eMuSta, eMuTrk }; // event category enum Double_t nProbes = 0; // // Set up output ntuple // gSystem->mkdir(outputDir,kTRUE); TFile *outFile = new TFile(outputDir+TString("/probes.root"),"RECREATE"); TTree *outTree = new TTree("Events","Events"); EffData data; outTree->Branch("Events",&data.mass,"mass/F:pt:eta:phi:weight:q/I:npv/i:npu:pass:runNum:lumiSec:evtNum"); // // Declare output ntuple variables // UInt_t runNum, lumiSec, evtNum; UInt_t matchGen; UInt_t category; UInt_t npv, npu; Float_t scale1fb; Float_t met, metPhi, sumEt, u1, u2; Int_t q1, q2; LorentzVector *dilep=0, *lep1=0, *lep2=0; LorentzVector *sta1=0, *sta2=0; Float_t pfCombIso1, pfCombIso2; Float_t d01, dz1, d02, dz2; Float_t muNchi21, muNchi22; UInt_t nPixHits1, nTkLayers1, nPixHits2, nTkLayers2; UInt_t nValidHits1, nMatch1, nValidHits2, nMatch2; UInt_t typeBits1, typeBits2; // Read input file and get the TTrees cout << "Processing " << infilename << "..." << endl; TFile *infile = new TFile(infilename); assert(infile); TTree *intree = (TTree*)infile->Get("Events"); assert(intree); intree->SetBranchAddress("runNum", &runNum); // event run number intree->SetBranchAddress("lumiSec", &lumiSec); // event lumi section intree->SetBranchAddress("evtNum", &evtNum); // event number intree->SetBranchAddress("matchGen", &matchGen); // event has both leptons matched to MC Z->ll intree->SetBranchAddress("category", &category); // dilepton category intree->SetBranchAddress("npv", &npv); // number of primary vertices intree->SetBranchAddress("npu", &npu); // number of in-time PU events (MC) intree->SetBranchAddress("scale1fb", &scale1fb); // event weight per 1/fb (MC) intree->SetBranchAddress("met", &met); // MET intree->SetBranchAddress("metPhi", &metPhi); // phi(MET) intree->SetBranchAddress("sumEt", &sumEt); // Sum ET intree->SetBranchAddress("u1", &u1); // parallel component of recoil intree->SetBranchAddress("u2", &u2); // perpendicular component of recoil intree->SetBranchAddress("q1", &q1); // charge of tag lepton intree->SetBranchAddress("q2", &q2); // charge of probe lepton intree->SetBranchAddress("dilep", &dilep); // dilepton 4-vector intree->SetBranchAddress("lep1", &lep1); // tag lepton 4-vector intree->SetBranchAddress("lep2", &lep2); // probe lepton 4-vector intree->SetBranchAddress("sta1", &sta1); // tag STA muon 4-vector intree->SetBranchAddress("sta2", &sta2); // probe STA muon 4-vector intree->SetBranchAddress("pfCombIso1", &pfCombIso1); // PF combined isolation of tag lepton intree->SetBranchAddress("pfCombIso2", &pfCombIso2); // PF combined isolation of probe lepton intree->SetBranchAddress("d01", &d01); // transverse impact parameter of tag lepton intree->SetBranchAddress("d02", &d02); // transverse impact parameter of probe lepton intree->SetBranchAddress("dz1", &dz1); // longitudinal impact parameter of tag lepton intree->SetBranchAddress("dz2", &dz2); // longitudinal impact parameter of probe lepton intree->SetBranchAddress("muNchi21", &muNchi21); // muon fit normalized chi^2 of tag lepton intree->SetBranchAddress("muNchi22", &muNchi22); // muon fit normalized chi^2 of probe lepton intree->SetBranchAddress("nPixHits1", &nPixHits1); // number of pixel hits of tag muon intree->SetBranchAddress("nPixHits2", &nPixHits2); // number of pixel hits of probe muon intree->SetBranchAddress("nTkLayers1", &nTkLayers1); // number of tracker layers of tag muon intree->SetBranchAddress("nTkLayers2", &nTkLayers2); // number of tracker layers of probe muon intree->SetBranchAddress("nMatch1", &nMatch1); // number of matched segments of tag muon intree->SetBranchAddress("nMatch2", &nMatch2); // number of matched segments of probe muon intree->SetBranchAddress("nValidHits1",&nValidHits1); // number of valid muon hits of tag muon intree->SetBranchAddress("nValidHits2",&nValidHits2); // number of valid muon hits of probe muon intree->SetBranchAddress("typeBits1", &typeBits1); // muon type of tag muon intree->SetBranchAddress("typeBits2", &typeBits2); // muon type of probe muon // // loop over events // for(UInt_t ientry=0; ientry<intree->GetEntries(); ientry++) { intree->GetEntry(ientry); if(lep1->Pt() < TAG_PT_CUT) continue; // check GEN match if necessary if(doGenMatch && !matchGen) continue; Bool_t pass=kFALSE; Float_t mass=0; if(effType==eHLTEff) { // // probe = muon passing selection // pass = matched to HLT // * MuMu2HLT event means a passing probe, MuMu1HLT event means a failing probe // all other categories do not satisfy probe requirements // if (category==eMuMu2HLT) { pass=kTRUE; } else if(category==eMuMu1HLT) { pass=kFALSE; } else if(category==eMuMuNoSel) { continue; } else if(category==eMuSta) { continue; } else { continue; } mass = dilep->M(); } else if(effType==eSelEff) { // // probe = GLB muon // pass = passing selection // * MuMu2HLT, MuMu1HLT event means a passing probe, MuMuNoSel event means a failing probe, // all other categories do not satisfy probe requirements // if (category==eMuMu2HLT) { pass=kTRUE; } else if(category==eMuMu1HLT) { pass=kTRUE; } else if(category==eMuMuNoSel) { pass=kFALSE; } else if(category==eMuSta) { continue; } else { continue; } mass = dilep->M(); } else if(effType==eTrkEff) { // // probe = STA muon // pass = is also a GLB muon // * MuMu2HLT, MuMu1HLT, MuMuNoSel event means a passing probe, MuSta event means a failing probe, // MuTrk event does not satisfy probe requirements // if (category==eMuMu2HLT) { pass=kTRUE; } else if(category==eMuMu1HLT) { pass=kTRUE; } else if(category==eMuMuNoSel) { pass=kTRUE; } else if(category==eMuSta) { pass=kFALSE; } else { continue; } // compute mass using probe STA muon pT LorentzVector tp = *lep1 + *sta2; mass = tp.M(); } else if(effType==eStaEff) { // // probe = tracker track // pass = is also a GLB muon // * MuMu2HLT, MuMu1HLT, MuMuNoSel event means a passing probe, MuTrk event means a failing probe, // MuSta event does not satisfy probe requirements // if (category==eMuMu2HLT) { pass=kTRUE; } else if(category==eMuMu1HLT) { pass=kTRUE; } else if(category==eMuMuNoSel) { pass=kTRUE; } else if(category==eMuSta) { continue; } else { pass=kFALSE; } mass = dilep->M(); } else if(effType==eStaEff_iso) { // // probe = isolated tracker track // pass = is also a GLB muon // * MuMu2HLT, MuMu1HLT, isolated MuMuNoSel event means a passing probe, isolated MuTrk event means a failing probe, // MuSta, non-isolated MuMuNoSel, and non-isolated MuTrk events do not satisfy probe requirements // if (category==eMuMu2HLT) { pass=kTRUE; } else if(category==eMuMu1HLT) { pass=kTRUE; } else if(category==eMuMuNoSel) { if(pfCombIso2>0.12*(lep2->Pt())) continue; else pass=kTRUE; } else if(category==eMuSta) { continue; } else { if(pfCombIso2>0.12*(lep2->Pt())) continue; else pass=kFALSE; } mass = dilep->M(); } else if(effType==ePOGIDEff) { // // probe = tracker track // pass = passes "tight" muon ID // * // if (category==eMuMu2HLT) { pass=kTRUE; } else if(category==eMuMu1HLT) { pass=kTRUE; } else if(category==eMuMuNoSel) { pass=kTRUE; if(nTkLayers2 < 6) pass=kFALSE; if(nPixHits2 < 1) pass=kFALSE; if(fabs(d02) > 0.2) pass=kFALSE; if(fabs(dz2) > 0.5) pass=kFALSE; if(muNchi22 > 10) pass=kFALSE; if(nMatch2 < 2) pass=kFALSE; if(nValidHits2 < 1) pass=kFALSE; if(!(typeBits2 & 1)) pass=kFALSE; if(!(typeBits2 & 8)) pass=kFALSE; } else if(category==eMuSta) { continue; } else { pass=kFALSE; } mass = dilep->M(); } else if(effType==ePOGIsoEff) { // // probe = "tight" muon // pass = passes isolation // * // if (category==eMuMu2HLT) { pass=kTRUE; } else if(category==eMuMu1HLT) { pass=kTRUE; } else if(category==eMuMuNoSel) { if(nTkLayers2 < 6) continue; if(nPixHits2 < 1) continue; if(fabs(d02) > 0.2) continue; if(fabs(dz2) > 0.5) continue; if(muNchi22 > 10) continue; if(nMatch2 < 2) continue; if(nValidHits2 < 1) continue; if(!(typeBits2 & 1)) continue; if(!(typeBits2 & 8)) continue; pass = (pfCombIso2 < 0.12*(lep2->Pt())); } else if(category==eMuSta) { continue; } else { continue; } mass = dilep->M(); } nProbes += doWeighted ? scale1fb : 1; // Fill tree data.mass = mass; data.pt = (effType==eTrkEff) ? sta2->Pt() : lep2->Pt(); data.eta = (effType==eTrkEff) ? sta2->Eta() : lep2->Eta(); data.phi = (effType==eTrkEff) ? sta2->Phi() : lep2->Phi(); data.weight = doWeighted ? scale1fb : 1; data.q = q2; data.npv = npv; data.npu = npu; data.pass = (pass) ? 1 : 0; data.runNum = runNum; data.lumiSec = lumiSec; data.evtNum = evtNum; outTree->Fill(); if(category==eMuMu2HLT) { if(lep2->Pt() < TAG_PT_CUT) continue; nProbes += doWeighted ? scale1fb : 1; data.mass = mass; data.pt = (effType==eTrkEff) ? sta1->Pt() : lep1->Pt(); data.eta = (effType==eTrkEff) ? sta1->Eta() : lep1->Eta(); data.phi = (effType==eTrkEff) ? sta1->Phi() : lep1->Phi(); data.weight = doWeighted ? scale1fb : 1; data.q = q1; data.npv = npv; data.npu = npu; data.pass = 1; data.runNum = runNum; data.lumiSec = lumiSec; data.evtNum = evtNum; outTree->Fill(); } } delete infile; infile=0, intree=0; //-------------------------------------------------------------------------------------------------------------- // Output //============================================================================================================== cout << "*" << endl; cout << "* SUMMARY" << endl; cout << "*--------------------------------------------------" << endl; cout << endl; cout << " Number of probes selected: " << nProbes << endl; outFile->Write(); outFile->Close(); delete outFile; cout << endl; cout << " <> Output saved in " << outputDir << "/" << endl; cout << endl; gBenchmark->Show("selectProbesMuEff"); }
void pbpbEffJpsiSFSysSTA__idx_(double minPt = 6.5, double maxPt = 30.0) { int Prompt =1; int PutWeight = 1; int JpsiCat_ = 1; // 1 : prompt, 2 : non-prompt for(int iCat_ = 0; iCat_ < 7; iCat_++){ // One bin // 1.6-2.4 : 3.0-6.5, 3.0-30.0 // 0.0-2.4 : 10.0-30.0, 6.5-30.0 double minRap = 1.6; double maxRap = 2.4; minPt = 3.0; maxPt = 30.0; //double minRap = 1.6; double maxRap = 2.4; minPt = 3.0; maxPt = 6.5; //double minRap = 1.6; double maxRap = 2.4; minPt = 6.5; maxPt = 30.0; //double minRap = 0.0; double maxRap = 2.4; minPt = 10.0; maxPt = 30.0; //double minRap = 0.0; double maxRap = 2.4; minPt = 6.5; maxPt = 30.0; if(iCat_ == 0) {minRap = 1.6; maxRap = 2.4; minPt = 3.0; maxPt = 30.0;} if(iCat_ == 1) {minRap = 1.6; maxRap = 2.4; minPt = 3.0; maxPt = 6.5;} if(iCat_ == 2) {minRap = 1.6; maxRap = 2.4; minPt = 6.5; maxPt = 30.0;} if(iCat_ == 3) {minRap = 0.0; maxRap = 2.4; minPt = 10.0; maxPt = 30.0;} if(iCat_ == 4) {minRap = 0.0; maxRap = 2.4; minPt = 6.5; maxPt = 30.0;} if(iCat_ == 5) {minRap = 1.6; maxRap = 2.4; minPt = 3.0; maxPt = 5.5;} if(iCat_ == 6) {minRap = 0.0; maxRap = 2.4; minPt = 6.5; maxPt = 8.5;} cout<<"Min y = "<<minRap<<", Max y = "<<maxRap<<", Min pT = "<<minPt<<", Max pT = "<<maxPt<<endl; bool bDefault = true; // true : default, false : sailor or cowboy char cCd[512]; if(bDefault) sprintf(cCd, "default"); gROOT->SetStyle("Plain"); gStyle->SetPalette(1); gStyle->SetFrameBorderMode(0); gStyle->SetFrameFillColor(0); gStyle->SetCanvasColor(0); gStyle->SetTitleFillColor(0); gStyle->SetStatColor(0); gStyle->SetPadBorderSize(0); gStyle->SetCanvasBorderSize(0); gStyle->SetOptTitle(0); // at least most of the time gStyle->SetOptStat(0); // most of the time, sometimes "nemriou" might be useful to display name, //number of entries, mean, rms, integral, overflow and underflow gStyle->SetOptFit(0); // set to 1 only if you want to display fit results //==================================== Define Histograms==================================================== //==============================================Define Acc Eff Stuff here=========================================== // Pt bin sizes // 0-1.5, 1.5-3, 3-4.5, 4.5-6, 6-7.5... const char *cTrg[5] = {"Bit1", "L1DM0HighQ", "L2Mu3NHitQ", "L3Mu3", "L3DMOpen"}; //int iTrg = 0; TFile *outfile; char tmp_output[512]; if(JpsiCat_ == 1) sprintf(tmp_output,"pbpbPrJpsi_y_%0.1f_%0.1f_pT_%0.1f_%0.1f_HighQ_tnpWgt_pr2.root", minRap, maxRap, minPt, maxPt); if(JpsiCat_ == 2) sprintf(tmp_output,"pbpbPrJpsi_y_%0.1f_%0.1f_pT_%0.1f_%0.1f_HighQ_tnpWgt_npr2.root", minRap, maxRap, minPt, maxPt); outfile =new TFile(tmp_output, "Recreate"); TH1F *hGenCent = new TH1F("hGenCent",";Centrality (%);Weighted Counts",40,0,40); TH1F *hRecCent = new TH1F("hRecCent",";Centrality (%);Weighted Counts",40,0,40); hGenCent->Sumw2(); hRecCent->Sumw2(); for(int iSpec = 1; iSpec < 2; iSpec++){ ////const int nCentBins = 11; // Non-prompt ////const int nCentBins = 14; // Prompt const int nCentBins = 10; // Non-prompt (60-100) //const int nCentBins = 13; // Prompt (60-100) const int nPtBins = 1; const int nRapBins = 6; const int ndPhiBins = 8; //const int ndPhiBins = 4; const int ndPhi2Bins = 8; const int nPhiBins = 8; const int nFiles = 6; //if(JpsiCat_ == 2) nCentBins = 11; // more bins 0-10,10-20,20-30,30-40,40-50,50-70,70-100 // cent bins : 0-5, 5-10, 10-15, 15-20, 20-25, 25-30, 30-35, 35-40, 40-45, 45-50, 50-55, 55-60, 60-70, 70-100 ////double ct_bound[nCentBins+1] = {0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 28, 40}; //double ct_bound[nCentBins+1] = {0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 40}; // Prompt (60-100) double ct_bound[nCentBins+1] = {0, 2, 4, 6, 8, 10, 12, 16, 20, 24, 40}; // NonPrompt (60-100) double ct_bound2[nCentBins+1] = {0.0}; for(int ict = 0; ict < nCentBins+1; ict++){ ct_bound2[ict] = ct_bound[ict]*2.5; } double xct_bound[nCentBins] = {0.0}; //double pt_bound[nPtBins+1] = {0.0, 3.0, 6.5}; // pT bins : 6.5-7.5, 7.5-8.5, 8.5-9.5, 9.5-10.5, 10.5-11.5, 11.5-12.5, 12.5-14.5, 14.5-16.5, 16.5-20.0, 20.0-30.0 double pt_bound[nPtBins+1]; pt_bound[0] = minPt; pt_bound[1] = maxPt; double xpt_bound[nPtBins] = {0.0}; // rap bins : 0.0-0.3, 0.3-0.6, 0.6-0.9, 0.9-1.2, 1.2-1.5, 1.5-1.8, 1.8-2.1, 2.1-2.4 double rap_bound[nRapBins+1] = {0.0, 0.4, 0.8, 1.2, 1.6, 2.0, 2.4}; double xrap_bound[nRapBins] = {0.0}; double dphi_bound[ndPhiBins+1] = {0.0, TMath::Pi()/16, 2*TMath::Pi()/16, 3*TMath::Pi()/16, 4*TMath::Pi()/16, 5*TMath::Pi()/16, 6*TMath::Pi()/16, 7*TMath::Pi()/16, 8*TMath::Pi()/16}; double xdphi_bound[ndPhiBins] = {0.0}; double phi_bound[nPhiBins+1] = {-4*TMath::Pi()/4, -3*TMath::Pi()/4, -2*TMath::Pi()/4, -1*TMath::Pi()/4,0.0, TMath::Pi()/4, 2*TMath::Pi()/4, 3*TMath::Pi()/4, TMath::Pi()}; double xphi_bound[nPhiBins] = {0.0}; double dphi2_bound[ndPhi2Bins+1] = {0.0, TMath::Pi()/16, 2*TMath::Pi()/16, 3*TMath::Pi()/16, 4*TMath::Pi()/16, 5*TMath::Pi()/16, 6*TMath::Pi()/16, 7*TMath::Pi()/16, 8*TMath::Pi()/16}; double xdphi2_bound[ndPhi2Bins] = {0.0}; const char *cSp[6] = {"Cents","Pts","Raps","Phi","dPhi","gdPhi"}; char OutTextFile[100]; if(JpsiCat_ == 1) sprintf(OutTextFile,"eff_HighPt_%s_%s_%s_y_%0.1f_%0.1f_pT_%0.1f_%0.1f_pr.tex", cSp[iSpec], cCd, cTrg[0], minRap, maxRap, minPt, maxPt); if(JpsiCat_ == 2) sprintf(OutTextFile,"eff_HighPt_%s_%s_%s_y_%0.1f_%0.1f_pT_%0.1f_%0.1f_npr.tex", cSp[iSpec], cCd, cTrg[0], minRap, maxRap, minPt, maxPt); //sprintf(OutTextFile,"eff_HighPt_%s_%s_%s.tex", cSp[iSpec], cCd, cTrg[iCat]); ofstream dataFile(Form(OutTextFile)); char tmp_start[512]; sprintf(tmp_start,"%%%% Getting Efficiency starts, Category : %s !!!!! %%%%%", cCd); cout<< tmp_start << endl; //dataFile<< tmp_start << endl; // x, y, z - axis //dataFile<<""<<endl; //dataFile<<"xaxis of Cent"<<endl; for(int i = 0; i < nCentBins; i++){ if(i == (nCentBins-1)){ xct_bound[i] = ct_bound[i-4] + (ct_bound[i-1]-ct_bound[i-4])/2; //cout<<"xct_bound["<<i<<"] : "<<xct_bound[i]<<endl; //dataFile<<"xct_bound["<<i<<"] : "<<xct_bound[i]<<endl; }else{ xct_bound[i] = ct_bound[i] + (ct_bound[i+1]-ct_bound[i])/2; //cout<<"xct_bound["<<i<<"] : "<<xct_bound[i]<<endl; //dataFile<<"xct_bound["<<i<<"] : "<<xct_bound[i]<<endl; } } //dataFile<<""<<endl; //dataFile<<"xaxis of pT"<<endl; for(int i = 0; i < nPtBins; i++){ xpt_bound[i] = pt_bound[i] + (pt_bound[i+1]-pt_bound[i])/2; //cout<<"xpt_bound["<<i<<"] : "<<xpt_bound[i]<<endl; //dataFile<<"xpt_bound["<<i<<"] : "<<xpt_bound[i]<<endl; } //dataFile<<""<<endl; //dataFile<<"xaxis of rap"<<endl; for(int i = 0; i < nRapBins; i++){ xrap_bound[i] = rap_bound[i] + (rap_bound[i+1]-rap_bound[i])/2; //cout<<"xrap_bound["<<i<<"] : "<<xrap_bound[i]<<endl; //dataFile<<"xrap_bound["<<i<<"] : "<<xrap_bound[i]<<endl; } //dataFile<<""<<endl; //dataFile<<"xaxis of dphi"<<endl; for(int i = 0; i < ndPhiBins; i++){ xdphi_bound[i] = dphi_bound[i] + (dphi_bound[i+1]-dphi_bound[i])/2; //cout<<"xdphi_bound["<<i<<"] : "<<xdphi_bound[i]<<endl; //dataFile<<"xdphi_bound["<<i<<"] : "<<xdphi_bound[i]<<endl; } //dataFile<<""<<endl; //dataFile<<"xaxis of phi"<<endl; for(int i = 0; i < nPhiBins; i++){ xphi_bound[i] = phi_bound[i] + (phi_bound[i+1]-phi_bound[i])/2; //cout<<"xphi_bound["<<i<<"] : "<<xphi_bound[i]<<endl; //dataFile<<"xphi_bound["<<i<<"] : "<<xphi_bound[i]<<endl; } //dataFile<<""<<endl; //dataFile<<"xaxis of dphi2"<<endl; for(int i = 0; i < ndPhi2Bins; i++){ xdphi2_bound[i] = dphi2_bound[i] + (dphi2_bound[i+1]-dphi2_bound[i])/2; //cout<<"xdphi2_bound["<<i<<"] : "<<xdphi2_bound[i]<<endl; //dataFile<<"xdphi2_bound["<<i<<"] : "<<xdphi2_bound[i]<<endl; } int nBins_tmp = 0; if(iSpec == 0) { nBins_tmp = nCentBins; } if(iSpec == 1) { nBins_tmp = nPtBins; } if(iSpec == 2) { nBins_tmp = nRapBins; } if(iSpec == 3) { nBins_tmp = nPhiBins; } if(iSpec == 4) { nBins_tmp = ndPhiBins; } if(iSpec == 5) { nBins_tmp = ndPhi2Bins; } const int nBins = nBins_tmp; TH1F *hTempMass = new TH1F("hTempMass","",100, 2.0, 4.0); TH1F *hGenDiMuonf[nFiles][nBins]; TH1F *hRecoDiMuonf[nFiles][nBins]; TH1F *hGenDiMuon[nBins]; TH1F *hRecoDiMuon[nBins]; double genNo[nBins]; double genErr[nBins]; double recoNo[nBins]; double recoErr[nBins]; double eff[nBins]; double effErr[nBins]; for(int fl = 0; fl < nFiles; fl++){ for(int i = 0; i < nBins; i++){ hGenDiMuonf[fl][i] = (TH1F*)hTempMass->Clone(); hRecoDiMuonf[fl][i] = (TH1F*)hTempMass->Clone(); hGenDiMuon[i] = (TH1F*)hTempMass->Clone(); hRecoDiMuon[i] = (TH1F*)hTempMass->Clone(); hGenDiMuonf[fl][i]->Sumw2(); hRecoDiMuonf[fl][i]->Sumw2(); hGenDiMuon[i]->Sumw2(); hRecoDiMuon[i]->Sumw2(); } } char fileName[10][512]; //scales for different pT bins double scale[6]={5.83233e-06, 8.13987e-06, 3.64971e-06, 1.13816e-06, 3.50384e-07, 2.1568e-07}; if(PutWeight==0){scale[0]=(1);scale[1]=(1);scale[2]=(1);scale[3]=(1);scale[4]=(1);scale[5]=(1);} // loop for pT cout<<"================================="<<endl; sprintf(fileName[0],"/Users/dmoon/Dropbox/Analysis/HiMC/EffStudy/gRpAngRootFiles_Regit_NonPro/HiDiMuonAna_NonPrompt_RegIt_MC_20131006_Pt_0003.root"); sprintf(fileName[1],"/Users/dmoon/Dropbox/Analysis/HiMC/EffStudy/gRpAngRootFiles_Regit_NonPro/HiDiMuonAna_NonPrompt_RegIt_MC_20131006_Pt_0306.root"); sprintf(fileName[2],"/Users/dmoon/Dropbox/Analysis/HiMC/EffStudy/gRpAngRootFiles_Regit_NonPro/HiDiMuonAna_NonPrompt_RegIt_MC_20131006_Pt_0609.root"); sprintf(fileName[3],"/Users/dmoon/Dropbox/Analysis/HiMC/EffStudy/gRpAngRootFiles_Regit_NonPro/HiDiMuonAna_NonPrompt_RegIt_MC_20131006_Pt_0912.root"); sprintf(fileName[4],"/Users/dmoon/Dropbox/Analysis/HiMC/EffStudy/gRpAngRootFiles_Regit_NonPro/HiDiMuonAna_NonPrompt_RegIt_MC_20131006_Pt_1215.root"); sprintf(fileName[5],"/Users/dmoon/Dropbox/Analysis/HiMC/EffStudy/gRpAngRootFiles_Regit_NonPro/HiDiMuonAna_NonPrompt_RegIt_MC_20131006_Pt_1530.root"); TFile *infile; TTree *tree; TTree *gentree; for(int ifile = 0; ifile < nFiles; ifile++){ infile=new TFile(fileName[ifile],"R"); tree=(TTree*)infile->Get("SingleMuonTree"); gentree=(TTree*)infile->Get("SingleGenMuonTree"); //Event variables int eventNb,runNb,lumiBlock, gbin, rbin; int hbit1; double zVtx; //Jpsi Variables Double_t JpsiMass,JpsiPt,JpsiRap, JpsiCharge; Double_t JpsiVprob; Double_t JpsiPhi; Double_t JpsiEta; Double_t JpsiPsi[38]; Double_t JpsiGenPsi; //2.) muon variables RECO double muPosPx, muPosPy, muPosPz, muPosEta, muPosPt, muPosP, muPosPhi; double muNegPx, muNegPy, muNegPz, muNegEta, muNegPt, muNegP, muNegPhi; //(1).Positive Muon double muPos_nchi2In, muPos_dxy, muPos_dz, muPos_nchi2Gl; int muPos_found, muPos_pixeLayers, muPos_nValidMuHits,muPos_arbitrated,muPos_TMOneST,muPos_trkLayMeas; bool muPos_matches,muPos_tracker; int muPos_Trigger2, muPos_Trigger10; int muPos_Trigger4, muPos_Trigger12, muPos_Trigger13; int muPos_Trigger21, muPos_Trigger22; //(2).Negative Muon double muNeg_nchi2In, muNeg_dxy, muNeg_dz, muNeg_nchi2Gl; int muNeg_found, muNeg_pixeLayers, muNeg_nValidMuHits,muNeg_arbitrated,muNeg_TMOneST,muNeg_trkLayMeas; bool muNeg_matches,muNeg_tracker; int muNeg_Trigger2, muNeg_Trigger10; int muNeg_Trigger4, muNeg_Trigger12, muNeg_Trigger13; int muNeg_Trigger21, muNeg_Trigger22; //Gen Level variables //Gen PrJpsi Variables double GenJpsiMass, GenJpsiPt, GenJpsiRap; double GenJpsiPx, GenJpsiPy, GenJpsiPz; double GenJpsiPhi; double GenJpsiEta; double GenJpsiPsi; //2.) Gen muon variables double GenmuPosPx, GenmuPosPy, GenmuPosPz, GenmuPosEta, GenmuPosPt, GenmuPosPhi; double GenmuNegPx, GenmuNegPy, GenmuNegPz, GenmuNegEta, GenmuNegPt, GenmuNegPhi; //Event variables tree->SetBranchAddress("eventNb",&eventNb); tree->SetBranchAddress("runNb",&runNb); tree->SetBranchAddress("lumiBlock",&lumiBlock); tree->SetBranchAddress("hbit1",&hbit1); tree->SetBranchAddress("zVtx",&zVtx); //Jpsi Variables tree->SetBranchAddress("JpsiCharge",&JpsiCharge); tree->SetBranchAddress("JpsiMass",&JpsiMass); tree->SetBranchAddress("JpsiPt",&JpsiPt); tree->SetBranchAddress("JpsiPhi",&JpsiPhi); tree->SetBranchAddress("JpsiEta",&JpsiEta); tree->SetBranchAddress("JpsiPsi",&JpsiPsi); tree->SetBranchAddress("JpsiGenPsi",&JpsiGenPsi); tree->SetBranchAddress("JpsiRap",&JpsiRap); tree->SetBranchAddress("JpsiVprob",&JpsiVprob); tree->SetBranchAddress("rbin",&rbin); //muon variable tree->SetBranchAddress("muPosPx",&muPosPx); tree->SetBranchAddress("muPosPy",&muPosPy); tree->SetBranchAddress("muPosPz",&muPosPz); tree->SetBranchAddress("muPosEta",&muPosEta); tree->SetBranchAddress("muPosPhi",&muPosPhi); tree->SetBranchAddress("muNegPx", &muNegPx); tree->SetBranchAddress("muNegPy", &muNegPy); tree->SetBranchAddress("muNegPz", &muNegPz); tree->SetBranchAddress("muNegEta", &muNegEta); tree->SetBranchAddress("muNegPhi", &muNegPhi); //1). Positive Muon tree->SetBranchAddress("muPos_nchi2In", &muPos_nchi2In); tree->SetBranchAddress("muPos_dxy", &muPos_dxy); tree->SetBranchAddress("muPos_dz", &muPos_dz); tree->SetBranchAddress("muPos_nchi2Gl", &muPos_nchi2Gl); tree->SetBranchAddress("muPos_found", &muPos_found); tree->SetBranchAddress("muPos_pixeLayers", &muPos_pixeLayers); tree->SetBranchAddress("muPos_nValidMuHits", &muPos_nValidMuHits); tree->SetBranchAddress("muPos_matches", &muPos_matches); tree->SetBranchAddress("muPos_tracker", &muPos_tracker); tree->SetBranchAddress("muPos_arbitrated", &muPos_arbitrated); tree->SetBranchAddress("muPos_TMOneST", &muPos_TMOneST); tree->SetBranchAddress("muPos_trkLayMeas", &muPos_trkLayMeas); tree->SetBranchAddress("muPos_Trigger2", &muPos_Trigger2); tree->SetBranchAddress("muPos_Trigger21", &muPos_Trigger21); tree->SetBranchAddress("muPos_Trigger22", &muPos_Trigger22); tree->SetBranchAddress("muPos_Trigger4", &muPos_Trigger4); tree->SetBranchAddress("muPos_Trigger10", &muPos_Trigger10); tree->SetBranchAddress("muPos_Trigger12", &muPos_Trigger12); tree->SetBranchAddress("muPos_Trigger13", &muPos_Trigger13); //2). Negative Muon tree->SetBranchAddress("muNeg_nchi2In", &muNeg_nchi2In); tree->SetBranchAddress("muNeg_dxy", &muNeg_dxy); tree->SetBranchAddress("muNeg_dz", &muNeg_dz); tree->SetBranchAddress("muNeg_nchi2Gl", &muNeg_nchi2Gl); tree->SetBranchAddress("muNeg_found", &muNeg_found); tree->SetBranchAddress("muNeg_pixeLayers", &muNeg_pixeLayers); tree->SetBranchAddress("muNeg_nValidMuHits", &muNeg_nValidMuHits); tree->SetBranchAddress("muNeg_matches", &muNeg_matches); tree->SetBranchAddress("muNeg_tracker", &muNeg_tracker); tree->SetBranchAddress("muNeg_arbitrated", &muNeg_arbitrated); tree->SetBranchAddress("muNeg_TMOneST", &muNeg_TMOneST); tree->SetBranchAddress("muNeg_trkLayMeas", &muNeg_trkLayMeas); tree->SetBranchAddress("muNeg_Trigger2", &muNeg_Trigger2); tree->SetBranchAddress("muNeg_Trigger21", &muNeg_Trigger21); tree->SetBranchAddress("muNeg_Trigger22", &muNeg_Trigger22); tree->SetBranchAddress("muNeg_Trigger4", &muNeg_Trigger4); tree->SetBranchAddress("muNeg_Trigger10", &muNeg_Trigger10); tree->SetBranchAddress("muNeg_Trigger12", &muNeg_Trigger12); tree->SetBranchAddress("muNeg_Trigger13", &muNeg_Trigger13); //====================================Gen Variables========================================================= //Gen Jpsi Variables gentree->SetBranchAddress("GenJpsiMass", &GenJpsiMass); gentree->SetBranchAddress("GenJpsiPt", &GenJpsiPt); gentree->SetBranchAddress("GenJpsiPhi", &GenJpsiPhi); gentree->SetBranchAddress("GenJpsiPsi", &GenJpsiPsi); gentree->SetBranchAddress("GenJpsiRap", &GenJpsiRap); gentree->SetBranchAddress("GenJpsiEta", &GenJpsiEta); gentree->SetBranchAddress("GenJpsiPx", &GenJpsiPx); gentree->SetBranchAddress("GenJpsiPy", &GenJpsiPy); gentree->SetBranchAddress("GenJpsiPz", &GenJpsiPz); gentree->SetBranchAddress("gbin", &gbin); //muon variable gentree->SetBranchAddress("GenmuPosPx", &GenmuPosPx); gentree->SetBranchAddress("GenmuPosPy", &GenmuPosPy); gentree->SetBranchAddress("GenmuPosPz", &GenmuPosPz); gentree->SetBranchAddress("GenmuPosEta", &GenmuPosEta); gentree->SetBranchAddress("GenmuPosPhi", &GenmuPosPhi); gentree->SetBranchAddress("GenmuNegPx", &GenmuNegPx); gentree->SetBranchAddress("GenmuNegPy", &GenmuNegPy); gentree->SetBranchAddress("GenmuNegPz", &GenmuNegPz); gentree->SetBranchAddress("GenmuNegEta", &GenmuNegEta); gentree->SetBranchAddress("GenmuNegPhi", &GenmuNegPhi); //====================================================== Gen tree loop ================================================ int NAccep=0; int nGenEntries=gentree->GetEntries(); cout<<" Total Entries in GenLevel Tree for pT range: "<<fileName[ifile]<<" "<< nGenEntries<< " ==============="<<endl; for(int iGen=0; iGen< nGenEntries; iGen++) { //cout<<"i : "<<i<<endl; if(!(gentree->GetEntry(iGen))) continue; //cout<<" gentree ("<<i<<")"<<endl; //Only printing if(iGen%10000==0){ //cout<<" processing record "<<iGen<<"/"<<nGenEntries<<endl; //cout<<" Mass "<< GenJpsiMass<< " pT "<< GenJpsiPt << " Y " <<GenJpsiRap<<endl; } bool GenPosIn=0, GenNegIn=0; GenmuPosPt= TMath::Sqrt(GenmuPosPx*GenmuPosPx + GenmuPosPy*GenmuPosPy); GenmuNegPt= TMath::Sqrt(GenmuNegPx*GenmuNegPx + GenmuNegPy*GenmuNegPy); if(IsAccept(GenmuPosPt, GenmuPosEta)) {GenPosIn=1;} if(IsAccept(GenmuNegPt, GenmuNegEta)) {GenNegIn=1;} double GenCenWeight =0, GenWeight =0; GenCenWeight=FindCenWeight(gbin); GenWeight=GenCenWeight*scale[ifile]; hGenCent->Fill(gbin,GenWeight); int AccJpsi = 0; //if(GenJpsiPt < 6.5) continue; if((GenJpsiPt >= minPt && GenJpsiPt <= maxPt && fabs(GenJpsiRap) >= minRap && fabs(GenJpsiRap) <= maxRap && GenPosIn == 1 && GenNegIn == 1 && GenJpsiMass > 2.0 && GenJpsiMass < 4.0)) {AccJpsi = 1;} if((GenPosIn ==1 && GenNegIn==1)) NAccep++; if(PutWeight==0) GenWeight=1; //adding pT of all pt bins to see diss is cont //cout<<"1. GenJpsiPt : "<<GenJpsiPt<<", GenJpsiEta : "<<GenJpsiEta<<", GenJpsiRap : "<<GenJpsiRap<<", |GenJpsiPsi| : "<<TMath::Abs(GenJpsiPsi)<<endl; //cout<<"1. GenPosIn : "<<GenPosIn<<", GenNegIn : "<<GenNegIn<<endl; double vars = 0.0, bin1 = 0.0, bin2 = 0.0; if(iSpec == 0) vars = gbin; if(iSpec == 1) vars = GenJpsiPt; if(iSpec == 2) vars = fabs(GenJpsiRap); if(iSpec == 3) vars = GenJpsiPhi; if(iSpec == 4) vars = fabs(GenJpsiPsi); if(iSpec == 5) vars = fabs(GenJpsiPsi); for(int i = 0; i < nBins; i++){ if(iSpec == 0){ bin1 = ct_bound[i]; bin2 = ct_bound[i+1]; if( (AccJpsi==1) && (vars >= bin1 && vars < bin2) && GenJpsiPt >= minPt && GenJpsiPt <= maxPt && fabs(GenJpsiRap) >= minRap && fabs(GenJpsiRap) < maxRap ) { hGenDiMuonf[ifile][i]->Fill(GenJpsiMass,GenWeight); } } if(iSpec == 1){ bin1 = pt_bound[i]; bin2 = pt_bound[i+1]; if( (AccJpsi==1) && (vars >= bin1 && vars < bin2) && gbin >= 0 && gbin <= 40 && fabs(GenJpsiRap) >= minRap && fabs(GenJpsiRap) < maxRap ) { hGenDiMuonf[ifile][i]->Fill(GenJpsiMass,GenWeight); } } if(iSpec == 2){ bin1 = rap_bound[i]; bin2 = rap_bound[i+1]; if( (AccJpsi==1) && (vars >= bin1 && vars < bin2) && gbin >= 0 && gbin <= 40 && GenJpsiPt >= minPt && GenJpsiPt < maxPt) { hGenDiMuonf[ifile][i]->Fill(GenJpsiMass,GenWeight); } } if(iSpec == 3){ bin1 = phi_bound[i]; bin2 = phi_bound[i+1]; if( (AccJpsi==1) && (vars >= bin1 && vars < bin2) && gbin >= 0 && gbin <= 40 && GenJpsiPt >= minPt && GenJpsiPt < maxPt && fabs(GenJpsiRap) < maxRap) { hGenDiMuonf[ifile][i]->Fill(GenJpsiMass,GenWeight); } } if(iSpec == 4){ bin1 = dphi_bound[i]; bin2 = dphi_bound[i+1]; if( (AccJpsi==1) && (vars >= bin1 && vars < bin2) && gbin >= 0 && gbin <= 40 && GenJpsiPt >= minPt && GenJpsiPt < maxPt && fabs(GenJpsiRap) < maxRap) { hGenDiMuonf[ifile][i]->Fill(GenJpsiMass,GenWeight); } } if(iSpec == 5){ bin1 = dphi2_bound[i]; bin2 = dphi2_bound[i+1]; if( (AccJpsi==1) && (vars >= bin1 && vars < bin2) && gbin >= 0 && gbin <= 40 && GenJpsiPt >= minPt && GenJpsiPt < maxPt && fabs(GenJpsiRap) < maxRap) { hGenDiMuonf[ifile][i]->Fill(GenJpsiMass,GenWeight); } } } }//gen loop end //cout<<" accepted no "<< NAccep<<endl; //=============== Rec Tree Loop ============================================================================== int nRecEntries=tree->GetEntries(); cout<<"Total Entries in reconstructed Tree for pT range "<<fileName[ifile]<<" "<<nRecEntries<< "====="<<endl; for(int iRec=0; iRec<nRecEntries; iRec++) { tree->GetEntry(iRec); //Only printing if(iRec%10000==0){ //cout<<" processing record "<<iRec<<"/"<<nRecEntries<<endl; //cout<<" processing Run " <<runNb <<" event "<<eventNb<<" lum block "<<lumiBlock<<endl; //cout<<" Mass "<< JpsiMass<< " pT "<< JpsiPt << " Y " <<JpsiRap<<" "<<JpsiVprob<<" charge "<<JpsiCharge<<" rbin "<<rbin<<endl; } bool PosPass=0, NegPass=0, AllCut=0 ,PosIn=0, NegIn=0; muPosPt= TMath::Sqrt(muPosPx*muPosPx + muPosPy*muPosPy); muPosP = TMath::Sqrt(muPosPx*muPosPx + muPosPy*muPosPy+ muPosPz*muPosPz); muNegPt= TMath::Sqrt(muNegPx*muNegPx + muNegPy*muNegPy); muNegP = TMath::Sqrt(muNegPx*muNegPx + muNegPy*muNegPy +muNegPz*muNegPz); double tnpWgt1 = 0.0, tnpWgt2 = 0.0; double staWgt1 = 0.0, staWgt2 = 0.0; double x = 0.0; if(fabs(muPosEta) < 0.9){ x = muPosPt; tnpWgt1 = tnpSF1->Eval(x); }else if(fabs(muPosEta) < 1.6){ x = muPosPt; tnpWgt1 = tnpSF2->Eval(x); }else if(fabs(muPosEta) < 2.1){ x = muPosPt; tnpWgt1 = tnpSF3->Eval(x); }else{ x = muPosPt; tnpWgt1 = tnpSF4->Eval(x); } if(fabs(muNegEta) < 0.9){ x = muNegPt; tnpWgt2 = tnpSF1->Eval(x); }else if(fabs(muNegEta) < 1.6){ x = muNegPt; tnpWgt2 = tnpSF2->Eval(x); }else if(fabs(muNegEta) < 2.1){ x = muNegPt; tnpWgt2 = tnpSF3->Eval(x); }else{ x = muNegPt; tnpWgt2 = tnpSF4->Eval(x); } double xta = 0.0; if(fabs(muPosEta) < 1.6){ xta = muPosPt; staWgt1 = fun1->Eval(xta); }else{ xta = muPosPt; staWgt1 = fun2->Eval(xta); } if(fabs(muNegEta) < 1.6){ xta = muNegPt; staWgt2 = fun1->Eval(xta); }else{ xta = muNegPt; staWgt2 = fun2->Eval(xta); } double RecCenWeight=0,RecWeight=0; RecCenWeight=FindCenWeight(rbin); RecWeight=RecCenWeight*scale[ifile]*tnpWgt1*tnpWgt2*staWgt1*staWgt2; hRecCent->Fill(gbin,RecWeight); if(IsAccept(muPosPt, muPosEta)){PosIn=1;} if(IsAccept(muNegPt, muNegEta)){NegIn=1;} int AccJpsi = 0; if((JpsiPt >= minPt && JpsiPt <= maxPt && fabs(JpsiRap) >= minRap && fabs(JpsiRap) <= maxRap && PosIn == 1 && NegIn == 1)) {AccJpsi = 1;} /* cout<<"muPos_pixeLayers : "<<muPos_pixeLayers<<" muPos_nchi2In : "<<muPos_nchi2In <<" TMath::Abs(muPos_dxy) : "<<TMath::Abs(muPos_dxy)<<" TMath::Abs(muPos_dz) : "<<TMath::Abs(muPos_dz) <<" muPos_trkLayMeas : "<<muPos_trkLayMeas <<" muPos_arbitrated : "<<muPos_arbitrated<<" muPos_TMOneST : "<<muPos_TMOneST<<" muPos_tracker : "<<muPos_tracker<<endl; cout<<"muNeg_pixeLayers : "<<muNeg_pixeLayers<<" muNeg_nchi2In : "<<muNeg_nchi2In <<" TMath::Abs(muNeg_dxy) : "<<TMath::Abs(muNeg_dxy)<<" TMath::Abs(muNeg_dz) : "<<TMath::Abs(muNeg_dz) <<" muNeg_trkLayMeas : "<<muNeg_trkLayMeas <<" muNeg_arbitrated : "<<muNeg_arbitrated<<" muNeg_TMOneST : "<<muNeg_TMOneST<<" muNeg_tracker : "<<muNeg_tracker<<endl; */ bool mu_Global = ((muPos_nchi2Gl >=0) && (muNeg_nchi2Gl >=0)); bool mu_Tracker = ((muPos_tracker==1) && (muNeg_tracker==1)); if(muPos_found > 10 && muPos_pixeLayers > 0 && muPos_nchi2In < 4.0 && TMath::Abs(muPos_dxy) < 3 && TMath::Abs(muPos_dz) < 15 && muPos_nchi2Gl < 20 && muPos_arbitrated==1 && muPos_tracker==1){ PosPass=1; } if(muNeg_found > 10 && muNeg_pixeLayers > 0 && muNeg_nchi2In < 4.0 && TMath::Abs(muNeg_dxy) < 3 && TMath::Abs(muNeg_dz) < 15 && muNeg_nchi2Gl < 20 && muNeg_arbitrated==1 && muNeg_tracker==1){ NegPass=1; } if(hbit1 == 1 && (muPos_Trigger22==1 && muNeg_Trigger22==1) && (PosIn==1 && NegIn==1) && (PosPass==1 && NegPass==1) && mu_Global && mu_Tracker ){AllCut=1;} if(PutWeight==0)RecWeight=1; double JpsidPhi = JpsiGenPsi; //Eff loop for reco double vars = 0.0, bin1 = 0.0, bin2 = 0.0; if(iSpec == 0) vars = rbin; if(iSpec == 1) vars = JpsiPt; if(iSpec == 2) vars = fabs(JpsiRap); if(iSpec == 3) vars = JpsiPhi; if(iSpec == 4) vars = fabs(JpsidPhi); if(iSpec == 5) vars = fabs(JpsiGenPsi); if((JpsiCharge == 0) && (JpsiVprob > 0.01) && (JpsiMass >= 2.95 && JpsiMass < 3.25)) { for(int i = 0; i < nBins; i++){ if(iSpec == 0){ bin1 = ct_bound[i]; bin2 = ct_bound[i+1]; if( AccJpsi == 1 && (AllCut == 1) && (vars >= bin1 && vars < bin2) && JpsiPt >= minPt && JpsiPt <= maxPt && fabs(JpsiRap) >= minRap && fabs(JpsiRap) <= maxRap ) { hRecoDiMuonf[ifile][i]->Fill(JpsiMass,RecWeight); } } if(iSpec == 1){ bin1 = pt_bound[i]; bin2 = pt_bound[i+1]; if( AccJpsi == 1 && (AllCut == 1) && (vars >= bin1 && vars < bin2) && rbin >= 0 && rbin <= 40 && fabs(JpsiRap) >= minRap && fabs(JpsiRap) <= maxRap ) { hRecoDiMuonf[ifile][i]->Fill(JpsiMass,RecWeight); } } if(iSpec == 2){ bin1 = rap_bound[i]; bin2 = rap_bound[i+1]; if( AccJpsi == 1 && (AllCut == 1) && (vars >= bin1 && vars < bin2) && rbin >= 0 && rbin <= 40 && JpsiPt >= minPt && JpsiPt <= maxPt) { hRecoDiMuonf[ifile][i]->Fill(JpsiMass,RecWeight); } } if(iSpec == 3){ bin1 = phi_bound[i]; bin2 = phi_bound[i+1]; if( AccJpsi == 1 && (AllCut == 1) && (vars >= bin1 && vars < bin2) && rbin >= 0 && rbin <= 40 && JpsiPt >= minPt && JpsiPt <= maxPt && fabs(JpsiRap) <=maxRap) { hRecoDiMuonf[ifile][i]->Fill(JpsiMass,RecWeight); } } if(iSpec == 4){ bin1 = dphi_bound[i]; bin2 = dphi_bound[i+1]; if( AccJpsi == 1 && (AllCut == 1) && (vars >= bin1 && vars < bin2) && rbin >= 0 && rbin <= 40 && JpsiPt >= minPt && JpsiPt <= maxPt && fabs(JpsiRap) <=maxRap) { hRecoDiMuonf[ifile][i]->Fill(JpsiMass,RecWeight); } } if(iSpec == 5){ bin1 = dphi2_bound[i]; bin2 = dphi2_bound[i+1]; if( AccJpsi == 1 && (AllCut == 1) && (vars >= bin1 && vars < bin2) && rbin >= 0 && rbin <= 40 && JpsiPt >= minPt && JpsiPt <= maxPt && fabs(JpsiRap) <=maxRap) { hRecoDiMuonf[ifile][i]->Fill(JpsiMass,RecWeight); } } } } } //rec tree loop ends } // file loop ends //====================== File loop Starts ============================ /////////////////////////////////////////////////////////////////// cout<< " adding "<<endl; TCanvas *c1 = new TCanvas(); char gtmp[512], gtmp1[512]; char rtmp[512], rtmp1[512]; for(int i = 0; i < nBins; i++){ for(int ifile = 0; ifile < nFiles; ifile++){ hGenDiMuon[i]->Add(hGenDiMuonf[ifile][i],1); hRecoDiMuon[i]->Add(hRecoDiMuonf[ifile][i],1); } if(iSpec == 0) sprintf(gtmp,"hGenDiMuon_Cent_%1.f_%1.f",ct_bound[i],ct_bound[i+1]); if(iSpec == 1) sprintf(gtmp,"hGenDiMuon_Pt_%0.1f_%0.1f",pt_bound[i],pt_bound[i+1]); if(iSpec == 2) sprintf(gtmp,"hGenDiMuon_Rap_%0.1f_%0.1f",rap_bound[i],rap_bound[i+1]); if(iSpec == 0) sprintf(gtmp1,"plots/Gen/hGenDiMuon_Cent_%1.f_%1.f_%s.png",ct_bound[i],ct_bound[i+1],cCd); if(iSpec == 1) sprintf(gtmp1,"plots/Gen/hGenDiMuon_Pt_%0.1f_%0.1f_%s.png",pt_bound[i],pt_bound[i+1],cCd); if(iSpec == 2) sprintf(gtmp1,"plots/Gen/hGenDiMuon_Rap_%0.1f_%0.1f_%s.png",rap_bound[i],rap_bound[i+1],cCd); if(iSpec == 0) sprintf(rtmp,"hRecDiMuon_Cent_%1.f_%1.f",ct_bound[i],ct_bound[i+1]); if(iSpec == 1) sprintf(rtmp,"hRecDiMuon_Pt_%0.1f_%0.1f",pt_bound[i],pt_bound[i+1]); if(iSpec == 2) sprintf(rtmp,"hRecDiMuon_Rap_%0.1f_%0.1f",rap_bound[i],rap_bound[i+1]); if(iSpec == 0) sprintf(rtmp1,"plots/Rec/hRecDiMuon_Cent_%1.f_%1.f_%s.png",ct_bound[i],ct_bound[i+1],cCd); if(iSpec == 1) sprintf(rtmp1,"plots/Rec/hRecDiMuon_Pt_%0.1f_%0.1f_%s.png",pt_bound[i],pt_bound[i+1],cCd); if(iSpec == 2) sprintf(rtmp1,"plots/Rec/hRecDiMuon_Rap_%0.1f_%0.1f_%s.png",rap_bound[i],rap_bound[i+1],cCd); hGenDiMuon[i]->SetName(gtmp); //hGenDiMuon[i]->Write(); //hGenDiMuon[ipt][irap][idphi]->Draw(); //c1->SaveAs(gtmp1); hRecoDiMuon[i]->SetName(rtmp); //hRecoDiMuon[i]->Write(); //hRecoDiMuon[ipt][irap][idphi]->Draw(); //c1->SaveAs(rtmp1); } TH1F *hReco = new TH1F(); TH1F *hGen = new TH1F(); hReco->Sumw2(); hGen->Sumw2(); int nRecoBins; int nGenBins; if(iSpec == 0) {hReco = new TH1F("hReco","hReco;Centrality (%);Weighted Yields",nCentBins,ct_bound2); nRecoBins = nCentBins;} if(iSpec == 1) {hReco = new TH1F("hReco","hReco;p_{T} GeV/c;Weighted Yields",nPtBins,pt_bound); nRecoBins = nPtBins;} if(iSpec == 2) {hReco = new TH1F("hReco","hReco;y;Weighted Yields",nRapBins,rap_bound); nRecoBins = nRapBins;} if(iSpec == 3) {hReco = new TH1F("hReco","hReco;#phi;Weighted Yields",nPhiBins,phi_bound); nRecoBins = nPhiBins;} if(iSpec == 4) {hReco = new TH1F("hReco","hReco;d#phi;Weighted Yields",ndPhiBins,dphi_bound); nRecoBins = ndPhiBins;} if(iSpec == 5) {hReco = new TH1F("hReco","hReco;d#phi;Weighted Yields",ndPhi2Bins,dphi2_bound); nRecoBins = ndPhi2Bins;} if(iSpec == 0) {hGen = new TH1F("hGen","hGen;Centrality (%);Weighted Yields",nCentBins,ct_bound2); nGenBins = nCentBins;} if(iSpec == 1) {hGen = new TH1F("hGen","hGen;p_{T} GeV/c;Weighted Yields",nPtBins,pt_bound); nGenBins = nPtBins;} if(iSpec == 2) {hGen = new TH1F("hGen","hGen;y;Weighted Yields",nRapBins,rap_bound); nGenBins = nRapBins;} if(iSpec == 3) {hGen = new TH1F("hGen","hGen;#phi;Weighted Yields",nPhiBins,phi_bound); nGenBins = nPhiBins;} if(iSpec == 4) {hGen = new TH1F("hGen","hGen;d#phi;Weighted Yields",ndPhiBins,dphi_bound); nGenBins = ndPhiBins;} if(iSpec == 5) {hGen = new TH1F("hGen","hGen;d#phi;Weighted Yields",ndPhi2Bins,dphi2_bound); nGenBins = ndPhi2Bins;} cout<<"Starts to calculate efficiency"<<endl; //dataFile<<""<<endl; //=====================Loop for eff========================================================================================// //define stuff here for error on weighted samples for(int i = 0; i < nBins; i++){ int Gbinlow =hGenDiMuon[i]->GetXaxis()->FindBin(2.0);//2.95 int Gbinhi=hGenDiMuon[i]->GetXaxis()->FindBin(4.0);//2.95 //int Gbinlow =hGenDiMuon[i]->GetXaxis()->FindBin(2.95);//2.95 //int Gbinhi=hGenDiMuon[i]->GetXaxis()->FindBin(3.25);//2.95 int Rbinlow =hRecoDiMuon[i]->GetXaxis()->FindBin(2.95);//2.95 int Rbinhi=hRecoDiMuon[i]->GetXaxis()->FindBin(3.25);//2.95 cout<<"Gbinlow : "<<Gbinlow<<", Gbinhi : "<<Gbinhi<<endl; cout<<"Rbinlow : "<<Rbinlow<<", Rbinhi : "<<Rbinhi<<endl; genNo[i] = hGenDiMuon[i]->IntegralAndError(Gbinlow, Gbinhi, genErr[i]); recoNo[i] = hRecoDiMuon[i]->IntegralAndError(Rbinlow, Rbinhi, recoErr[i]); //calculate Eff if(genNo[i] == 0 || recoNo[i] == 0) { cout<<"No Gen or Reco, # of Gen : "<<genNo[i] <<", # of Reco : "<<recoNo[i]<<endl; eff[i] = 0; effErr[i] = 0; }else{ eff[i] = recoNo[i]/genNo[i]; double tmpGenNo = genNo[i]; double tmpGenErr = genErr[i]; double tmpRecNo = recoNo[i]; double tmpRecErr = recoErr[i]; double tmpEff = eff[i]; double tmpEffErr = 0.0; hReco->SetBinContent(i+1,tmpRecNo); hReco->SetBinError(i+1,tmpRecErr); hGen->SetBinContent(i+1,tmpGenNo); hGen->SetBinError(i+1,tmpGenErr); //error double tmp_err_s1_1 = (tmpEff * tmpEff)/(tmpGenNo * tmpGenNo); double tmp_err_s1_2 = (tmpRecErr * tmpRecErr); double tmp_err_cat_s1 = tmp_err_s1_1 * tmp_err_s1_2; double tmp_err_s2_1 = ( (1 - tmpEff)*(1 - tmpEff) ) / (tmpGenNo * tmpGenNo); double tmp_err_s2_2 = TMath::Abs(( tmpGenErr*tmpGenErr ) - ( tmpRecErr * tmpRecErr)); double tmp_err_cat_s2 = tmp_err_s2_1 * tmp_err_s2_2; tmpEffErr = sqrt( tmp_err_cat_s1 + tmp_err_cat_s2 ); effErr[i] = tmpEffErr; //error without weight //dataFile<<" Bin ["<<i<<"] - "<< " Reco Jpsi : "<< tmpRecNo <<", Gen Jpsi : "<< tmpGenNo <<endl; //dataFile<<" Eff ["<<i<<"] - "<< tmpEff <<" Error "<< tmpEffErr <<endl; cout<<" Bin ["<<i<<"] - "<< " Reco Jpsi : "<< tmpRecNo <<", Gen Jpsi : "<< tmpGenNo <<endl; cout<<" Eff ["<<i<<"] - "<< tmpEff <<" Error "<< tmpEffErr <<endl; } } TH1F *hEff = new TH1F(); hEff->Sumw2(); int nEffBins = 0; if(iSpec == 0) {hEff = new TH1F("hEff","hEff;Centrality (%);Efficiency",nCentBins,ct_bound2); nEffBins = nCentBins;} if(iSpec == 1) {hEff = new TH1F("hEff","hEff;p_{T} GeV/c;Efficiency",nPtBins,pt_bound); nEffBins = nPtBins;} if(iSpec == 2) {hEff = new TH1F("hEff","hEff;y;Efficiency",nRapBins,rap_bound); nEffBins = nRapBins;} if(iSpec == 3) {hEff = new TH1F("hEff","hEff;#phi;Efficiency",nPhiBins,phi_bound); nEffBins = nPhiBins;} if(iSpec == 4) {hEff = new TH1F("hEff","hEff;d#phi;Efficiency",ndPhiBins,dphi_bound); nEffBins = ndPhiBins;} if(iSpec == 5) {hEff = new TH1F("hEff","hEff;d#phi;Efficiency",ndPhi2Bins,dphi2_bound); nEffBins = ndPhi2Bins;} for(int i = 0; i < nEffBins; i++){ hEff->SetBinContent(i+1,eff[i]); hEff->SetBinError(i+1,effErr[i]); cout<<"Trying to measure Reconstruction eff vs "<<cSp[iSpec]<<endl; cout<<"Eff : "<<eff[i]<<", err : "<<effErr[i]<<endl; dataFile<<eff[i]<<endl;//", err : "<<effErr[i]<<endl; //dataFile<<"Eff : "<<eff[i]<<", err : "<<effErr[i]<<endl; } outfile->cd(); hEff->Draw(); char tmp_histo[512]; sprintf(tmp_histo,"hEff_%s",cSp[iSpec]); char tmp_histo_reco[512]; sprintf(tmp_histo_reco,"hReco_%s",cSp[iSpec]); char tmp_histo_gen[512]; sprintf(tmp_histo_gen,"hGen_%s",cSp[iSpec]); hEff->SetName(tmp_histo); hEff->Write(); hReco->SetName(tmp_histo_reco); hReco->Write(); hGen->SetName(tmp_histo_gen); hGen->Write(); //c1->SaveAs("eff_3D_default_etHFm.png"); //outfile->Close(); dataFile<<""<<endl; dataFile.close(); } hGenCent->Write(); hRecCent->Write(); outfile->Write(); } }
void AnalyseEvents(ExRootTreeReader *treeReader, TTree *evtree) { //config parameters bool runMMC_ = false; double jetsPt_ =20; double jetsEta_=5.0; double bjetsPt_ =30; double bjetsEta_ = 2.5; double jetsDeltaR_ = 0.4;//deltaR matching double jetleptonDeltaR_ = 0.3; double leptonsDeltaR_ = 0.4;//deltaR matching //double leptonIso_ = 0.15; double muonPt2_ = 20; double muonPt1_ = 20; double muonsEta_ = 2.4; double metPt_ = 20; //create branches Float_t b1_px =0; Float_t b1_py =0; Float_t b1_pz =0; Float_t b1_eta = 0; Float_t b1_phi = 0; Float_t b1_pt =0; Float_t b1_energy =0; Float_t b2_px =0; Float_t b2_py=0; Float_t b2_pz=0; Float_t b2_eta = 0; Float_t b2_phi = 0; Float_t b2_pt =0; Float_t b2_energy=0; Float_t htobb_px=0; Float_t htobb_py=0; Float_t htobb_pz=0; Float_t htobb_energy=0; Float_t htobb_mass =0; Bool_t htobb=false; Float_t genb1jet_px=0; Float_t genb1jet_py=0; Float_t genb1jet_pz=0; Float_t genb1jet_eta=0; Float_t genb1jet_phi=0; Float_t genb1jet_pt=0; Float_t genb1jet_energy=0; Float_t genb2jet_px=0; Float_t genb2jet_py=0; Float_t genb2jet_pz=0; Float_t genb2jet_eta=0; Float_t genb2jet_phi=0; Float_t genb2jet_pt=0; Float_t genb2jet_energy=0; Float_t dR_genb1jet=0; Float_t dR_genb2jet=0; Bool_t hasgenb1jet=false; Bool_t hasgenb2jet=false; Float_t dR_b1jet = 2.0; Float_t dR_b2jet = 2.0; Float_t b1jet_px=0; Float_t b1jet_py=0; Float_t b1jet_pz=0; Float_t b1jet_eta=0; Float_t b1jet_phi=0; Float_t b1jet_pt=0; Float_t b1jet_energy=0; Float_t b2jet_px=0; Float_t b2jet_py=0; Float_t b2jet_pz=0; Float_t b2jet_eta=0; Float_t b2jet_phi=0; Float_t b2jet_pt=0; Float_t b2jet_energy=0; Bool_t hasb1jet=false; Bool_t hasb2jet=false; Float_t mu1_px =0; Float_t mu1_py =0; Float_t mu1_pz =0; Float_t mu1_eta =0; Float_t mu1_phi =0; Float_t mu1_pt =0; Float_t mu1_energy =0; Float_t mu2_px =0; Float_t mu2_py =0; Float_t mu2_pz =0; Float_t mu2_eta =0; Float_t mu2_phi =0; Float_t mu2_pt =0; Float_t mu2_energy =0; Float_t nu1_px =0; Float_t nu1_py =0; Float_t nu1_pz =0; Float_t nu1_eta =0; Float_t nu1_phi =0; Float_t nu1_energy =0; Float_t nu2_px =0; Float_t nu2_py =0; Float_t nu2_pz =0; Float_t nu2_eta =0; Float_t nu2_phi =0; Float_t nu2_energy =0; Bool_t Wtomu2nu2=false; Bool_t Wtomu1nu1=false; Bool_t htoWW=false; Float_t Muon1_beforeIso_px = 0.0; Float_t Muon1_beforeIso_py = 0.0; Float_t Muon1_beforeIso_pz = 0.0; Float_t Muon1_beforeIso_eta = 0.0; Float_t Muon1_beforeIso_phi = 0.0; Float_t Muon1_beforeIso_pt = 0.0; Float_t Muon1_beforeIso_energy = 0.0; Float_t Muon2_beforeIso_px = 0.0; Float_t Muon2_beforeIso_py = 0.0; Float_t Muon2_beforeIso_pz = 0.0; Float_t Muon2_beforeIso_eta = 0.0; Float_t Muon2_beforeIso_phi = 0.0; Float_t Muon2_beforeIso_pt = 0.0; Float_t Muon2_beforeIso_energy = 0.0; Float_t dR_mu1_beforeIso = 2.0; Float_t dR_mu2_beforeIso = 2.0; Bool_t Muon1_beforeIso_hasgenMu = false; Bool_t Muon2_beforeIso_hasgenMu = false; Bool_t Muon1_beforeIso_passIso = false; Bool_t Muon2_beforeIso_passIso = false; Bool_t hasMuon1_beforeIso = false; Bool_t hasMuon2_beforeIso = false; Float_t Muon1_px = 0; Float_t Muon1_py = 0; Float_t Muon1_pz = 0; Float_t Muon1_eta = 0; Float_t Muon1_phi = 0; Float_t Muon1_pt = 0; Float_t Muon1_energy = 0; Float_t Muon2_px = 0; Float_t Muon2_py = 0; Float_t Muon2_pz = 0; Float_t Muon2_eta = 0; Float_t Muon2_phi = 0; Float_t Muon2_pt = 0; Float_t Muon2_energy = 0; Float_t dR_mu1 = 2.0; Float_t dR_mu2 = 2.0; Bool_t Muon1_hasgenMu = false; Bool_t Muon2_hasgenMu = false; Float_t htoWW_px =0; Float_t htoWW_py =0; Float_t htoWW_pz =0; Float_t htoWW_energy =0; Float_t htoWW_mass = 0; Float_t dR_b1l1; Float_t dR_b1l2; Float_t dR_b2l1; Float_t dR_b2l2; Float_t dR_l1l2; Float_t dR_b1b2; Float_t mass_l1l2; Float_t mass_b1b2; Float_t genmet = 0; Float_t genmet_phi = 0; Float_t genmet_px = 0; Float_t genmet_py = 0; Float_t met = 0; Float_t met_phi = 0; Float_t met_px = 0; Float_t met_py = 0; Float_t h2tohh_mass =0; //additional cuts Bool_t hasMET = false; Bool_t hasGenMET = false; Bool_t hastwomuons = false; Bool_t hastwogenmuons = false; Bool_t hasMuon1 = false; Bool_t hasMuon2 = false; Bool_t hasdRljet = false; Bool_t h2tohh =false; evtree->Branch("b1_px",&b1_px, "b1_px/F"); evtree->Branch("b1_py",&b1_py, "b1_py/F"); evtree->Branch("b1_pz",&b1_pz, "b1_pz/F"); evtree->Branch("b1_eta",&b1_eta, "b1_eta/F"); evtree->Branch("b1_phi",&b1_phi, "b1_phi/F"); evtree->Branch("b1_pt",&b1_pt, "b1_pt/F"); evtree->Branch("b1_energy",&b1_energy, "b1_energy/F"); evtree->Branch("b2_px",&b2_px, "b2_px/F"); evtree->Branch("b2_py",&b2_py, "b2_py/F"); evtree->Branch("b2_pz",&b2_pz, "b2_pz/F"); evtree->Branch("b2_eta",&b2_eta, "b2_eta/F"); evtree->Branch("b2_phi",&b2_phi, "b2_phi/F"); evtree->Branch("b2_pt",&b2_pt, "b2_pt/F"); evtree->Branch("b2_energy",&b2_energy, "b2_energy/F"); evtree->Branch("htobb_px",&htobb_px, "htobb_px/F"); evtree->Branch("htobb_py",&htobb_py, "htobb_py/F"); evtree->Branch("htobb_pz",&htobb_pz, "htobb_pz/F"); evtree->Branch("htobb_energy",&htobb_energy, "htobb_energy/F"); evtree->Branch("htobb_mass",&htobb_mass, "htobb_mass/F"); evtree->Branch("htobb",&htobb, "htobb/B"); evtree->Branch("genb1jet_px",&genb1jet_px, "genb1jet_px/F"); evtree->Branch("genb1jet_py",&genb1jet_py, "genb1jet_py/F"); evtree->Branch("genb1jet_pz",&genb1jet_pz, "genb1jet_pz/F"); evtree->Branch("genb1jet_eta",&genb1jet_eta, "genb1jet_eta/F"); evtree->Branch("genb1jet_phi",&genb1jet_phi, "genb1jet_phi/F"); evtree->Branch("genb1jet_pt",&genb1jet_pt, "genb1jet_pt/F"); evtree->Branch("genb1jet_energy",&genb1jet_energy, "genb1jet_energy/F"); evtree->Branch("genb2jet_px",&genb2jet_px, "genb2jet_px/F"); evtree->Branch("genb2jet_py",&genb2jet_py, "genb2jet_py/F"); evtree->Branch("genb2jet_pz",&genb2jet_pz, "genb2jet_pz/F"); evtree->Branch("genb2jet_eta",&genb2jet_eta, "genb2jet_eta/F"); evtree->Branch("genb2jet_phi",&genb2jet_phi, "genb2jet_phi/F"); evtree->Branch("genb2jet_pt",&genb2jet_pt, "genb2jet_pt/F"); evtree->Branch("genb2jet_energy",&genb2jet_energy, "genb2jet_energy/F"); evtree->Branch("dR_genb1jet", &dR_genb1jet,"dR_genb1jet/F"); evtree->Branch("dR_genb2jet", &dR_genb2jet,"dR_genb2jet/F"); evtree->Branch("hasgenb1jet",&hasgenb1jet, "hasgenb1jet/B"); evtree->Branch("hasgenb2jet",&hasgenb2jet, "hasgenb2jet/B"); evtree->Branch("b1jet_px",&b1jet_px, "b1jet_px/F"); evtree->Branch("b1jet_py",&b1jet_py, "b1jet_py/F"); evtree->Branch("b1jet_pz",&b1jet_pz, "b1jet_pz/F"); evtree->Branch("b1jet_eta",&b1jet_eta, "b1jet_eta/F"); evtree->Branch("b1jet_phi",&b1jet_phi, "b1jet_phi/F"); evtree->Branch("b1jet_pt",&b1jet_pt, "b1jet_pt/F"); evtree->Branch("b1jet_energy",&b1jet_energy, "b1jet_energy/F"); evtree->Branch("b2jet_px",&b2jet_px, "b2jet_px/F"); evtree->Branch("b2jet_py",&b2jet_py, "b2jet_py/F"); evtree->Branch("b2jet_pz",&b2jet_pz, "b2jet_pz/F"); evtree->Branch("b2jet_eta",&b2jet_eta, "b2jet_eta/F"); evtree->Branch("b2jet_phi",&b2jet_phi, "b2jet_phi/F"); evtree->Branch("b2jet_pt",&b2jet_pt, "b2jet_pt/F"); evtree->Branch("b2jet_energy",&b2jet_energy, "b2jet_energy/F"); evtree->Branch("dR_b1jet", &dR_b1jet,"dR_b1jet/F"); evtree->Branch("dR_b2jet", &dR_b2jet,"dR_b2jet/F"); evtree->Branch("hasb1jet",&hasb1jet, "hasb1jet/B"); evtree->Branch("hasb2jet",&hasb2jet, "hasb2jet/B"); evtree->Branch("hastwogenmuons",&hastwogenmuons, "hastwogenmuons/B"); evtree->Branch("hastwomuons",&hastwomuons, "hastwomuons/B"); evtree->Branch("mu1_px",&mu1_px, "mu1_px/F"); evtree->Branch("mu1_py",&mu1_py, "mu1_py/F"); evtree->Branch("mu1_pz",&mu1_pz, "mu1_pz/F"); evtree->Branch("mu1_eta",&mu1_eta, "mu1_eta/F"); evtree->Branch("mu1_phi",&mu1_phi, "mu1_phi/F"); evtree->Branch("mu1_pt",&mu1_pt, "mu1_pt/F"); evtree->Branch("mu1_energy",&mu1_energy, "mu1_energy/F"); evtree->Branch("nu1_px",&nu1_px, "nu1_px/F"); evtree->Branch("nu1_py",&nu1_py, "nu1_py/F"); evtree->Branch("nu1_pz",&nu1_pz, "nu1_pz/F"); evtree->Branch("nu1_eta",&nu1_eta, "nu1_eta/F"); evtree->Branch("nu1_phi",&nu1_phi, "nu1_phi/F"); evtree->Branch("nu1_energy",&nu1_energy, "nu1_energy/F"); evtree->Branch("mu2_px",&mu2_px, "mu2_px/F"); evtree->Branch("mu2_py",&mu2_py, "mu2_py/F"); evtree->Branch("mu2_pz",&mu2_pz, "mu2_pz/F"); evtree->Branch("mu2_eta",&mu2_eta, "mu2_eta/F"); evtree->Branch("mu2_phi",&mu2_phi, "mu2_phi/F"); evtree->Branch("mu2_pt",&mu2_pt, "mu2_pt/F"); evtree->Branch("mu2_energy",&mu2_energy, "mu2_energy/F"); evtree->Branch("nu2_px",&nu2_px, "nu2_px/F"); evtree->Branch("nu2_py",&nu2_py, "nu2_py/F"); evtree->Branch("nu2_pz",&nu2_pz, "nu2_pz/F"); evtree->Branch("nu2_eta",&nu2_eta, "nu2_eta/F"); evtree->Branch("nu2_phi",&nu2_phi, "nu2_phi/F"); evtree->Branch("nu2_energy",&nu2_energy, "nu2_energy/F"); evtree->Branch("htoWW_energy",&htoWW_energy); evtree->Branch("htoWW_px",&htoWW_px,"htoWW_px/F"); evtree->Branch("htoWW_py",&htoWW_py,"htoWW_px/F"); evtree->Branch("htoWW_pz",&htoWW_pz,"htoWW_pz/F"); evtree->Branch("htoWW_mass",&htoWW_mass,"htoWW_mass/F"); evtree->Branch("Wtomu1nu1",&Wtomu1nu1,"Wtomu1nu1/B"); evtree->Branch("Wtomu2nu2",&Wtomu2nu2,"Wtomu2nu2/B"); evtree->Branch("htoWW",&htoWW,"htoWW/B"); evtree->Branch("Muon1_beforeIso_px",&Muon1_beforeIso_px, "Muon1_beforeIso_px/F"); evtree->Branch("Muon1_beforeIso_py",&Muon1_beforeIso_py, "Muon1_beforeIso_py/F"); evtree->Branch("Muon1_beforeIso_pz",&Muon1_beforeIso_pz, "Muon1_beforeIso_pz/F"); evtree->Branch("Muon1_beforeIso_eta",&Muon1_beforeIso_eta, "Muon1_beforeIso_eta/F"); evtree->Branch("Muon1_beforeIso_phi",&Muon1_beforeIso_phi, "Muon1_beforeIso_phi/F"); evtree->Branch("Muon1_beforeIso_pt",&Muon1_beforeIso_pt, "Muon1_beforeIso_pt/F"); evtree->Branch("Muon1_beforeIso_energy",&Muon1_beforeIso_energy, "Muon1_beforeIso_energy/F"); evtree->Branch("Muon2_beforeIso_px",&Muon2_beforeIso_px, "Muon2_beforeIso_px/F"); evtree->Branch("Muon2_beforeIso_py",&Muon2_beforeIso_py, "Muon2_beforeIso_py/F"); evtree->Branch("Muon2_beforeIso_pz",&Muon2_beforeIso_pz, "Muon2_beforeIso_pz/F"); evtree->Branch("Muon2_beforeIso_eta",&Muon2_beforeIso_eta, "Muon2_beforeIso_eta/F"); evtree->Branch("Muon2_beforeIso_phi",&Muon2_beforeIso_phi, "Muon2_beforeIso_phi/F"); evtree->Branch("Muon2_beforeIso_pt",&Muon2_beforeIso_pt, "Muon2_beforeIso_pt/F"); evtree->Branch("Muon2_beforeIso_energy",&Muon2_beforeIso_energy, "Muon2_beforeIso_energy/F"); evtree->Branch("dR_mu1_beforeIso",&dR_mu1_beforeIso, "dR_mu1_beforeIso/F"); evtree->Branch("dR_mu2_beforeIso",&dR_mu2_beforeIso, "dR_mu2_beforeIso/F"); evtree->Branch("hasMuon1_beforeIso",&hasMuon1_beforeIso, "hasMuon1_beforeIso/B"); evtree->Branch("hasMuon2_beforeIso",&hasMuon2_beforeIso, "hasMuon2_beforeIso/B"); evtree->Branch("Muon1_beforeIso_hasgenMu",&Muon1_beforeIso_hasgenMu, "Muon1_beforeIso_hasgenMu/B"); evtree->Branch("Muon2_beforeIso_hasgenMu",&Muon2_beforeIso_hasgenMu, "Muon2_beforeIso_hasgenMu/B"); evtree->Branch("Muon1_beforeIso_passIso",&Muon1_beforeIso_passIso, "Muon1_beforeIso_passIso/B"); evtree->Branch("Muon2_beforeIso_passIso",&Muon2_beforeIso_passIso, "Muon2_beforeIso_passIso/B"); evtree->Branch("Muon1_px",&Muon1_px, "Muon1_px/F"); evtree->Branch("Muon1_py",&Muon1_py, "Muon1_py/F"); evtree->Branch("Muon1_pz",&Muon1_pz, "Muon1_pz/F"); evtree->Branch("Muon1_eta",&Muon1_eta, "Muon1_eta/F"); evtree->Branch("Muon1_phi",&Muon1_phi, "Muon1_phi/F"); evtree->Branch("Muon1_pt",&Muon1_pt, "Muon1_pt/F"); evtree->Branch("Muon1_energy",&Muon1_energy, "Muon1_energy/F"); evtree->Branch("Muon2_px",&Muon2_px, "Muon2_px/F"); evtree->Branch("Muon2_py",&Muon2_py, "Muon2_py/F"); evtree->Branch("Muon2_pz",&Muon2_pz, "Muon2_pz/F"); evtree->Branch("Muon2_eta",&Muon2_eta, "Muon2_eta/F"); evtree->Branch("Muon2_phi",&Muon2_phi, "Muon2_phi/F"); evtree->Branch("Muon2_pt",&Muon2_pt, "Muon2_pt/F"); evtree->Branch("Muon2_energy",&Muon2_energy, "Muon2_energy/F"); evtree->Branch("dR_mu1",&dR_mu1, "dR_mu1/F"); evtree->Branch("dR_mu2",&dR_mu2, "dR_mu2/F"); evtree->Branch("hasMuon1",&hasMuon1, "hasMuon1/B"); evtree->Branch("hasMuon2",&hasMuon2, "hasMuon2/B"); evtree->Branch("Muon1_hasgenMu",&Muon1_hasgenMu, "Muon1_hasgenMu/B"); evtree->Branch("Muon2_hasgenMu",&Muon2_hasgenMu, "Muon2_hasgenMu/B"); evtree->Branch("dR_b1l1",&dR_b1l1, "dR_b1l1/F"); evtree->Branch("dR_b1l2",&dR_b1l2, "dR_b1l2/F"); evtree->Branch("dR_b2l1",&dR_b2l1, "dR_b2l1/F"); evtree->Branch("dR_b2l2",&dR_b2l2, "dR_b2l2/F"); evtree->Branch("dR_b1b2",&dR_b1b2, "dR_b1b2/F"); evtree->Branch("dR_l1l2",&dR_l1l2, "dR_l1l2/F"); evtree->Branch("mass_b1b2",&mass_b1b2, "mass_b1b2/F"); evtree->Branch("mass_l1l2",&mass_l1l2, "mass_l1l2/F"); evtree->Branch("genmet",&genmet,"genmet/F"); evtree->Branch("genmet_phi",&genmet_phi,"genmet_phi/F"); evtree->Branch("genmet_px",&genmet_px,"genmet_px/F"); evtree->Branch("genmet_py",&genmet_py,"genmet_py/F"); evtree->Branch("met",&met,"met/F"); evtree->Branch("met_phi",&met_phi,"met_phi/F"); evtree->Branch("met_px",&met_px,"met_px/F"); evtree->Branch("met_py",&met_py,"met_py/F"); evtree->Branch("hasGenMET",&hasGenMET, "hasGenMET/B"); evtree->Branch("hasMET",&hasMET, "hasMET/B"); evtree->Branch("hasdRljet",&hasdRljet, "hasdRljet/B"); evtree->Branch("h2tohh_mass",&h2tohh_mass,"h2tohh_mass/F"); evtree->Branch("h2tohh",&h2tohh,"h2tohh/B"); //loop over events 1. find h->b bbar; 2 find two bjets after cuts; 3 fill Tree TClonesArray *branchParticle = treeReader->UseBranch("Particle"); TClonesArray *branchElectron = treeReader->UseBranch("Electron"); TClonesArray *branchPhoton = treeReader->UseBranch("Photon"); TClonesArray *branchMuon = treeReader->UseBranch("Muon"); TClonesArray *branchMuonBeforeIso = treeReader->UseBranch("MuonBeforeIso"); //TClonesArray *branchTrack = treeReader->UseBranch("Track"); // TClonesArray *branchTower = treeReader->UseBranch("Tower"); //TClonesArray *branchEFlowTrack = treeReader->UseBranch("EFlowTrack"); // TClonesArray *branchEFlowPhoton = treeReader->UseBranch("EFlowPhoton"); // TClonesArray *branchEFlowNeutralHadron = treeReader->UseBranch("EFlowNeutralHadron"); TClonesArray *branchJet = treeReader->UseBranch("Jet"); TClonesArray *branchGenJet = treeReader->UseBranch("GenJet"); TClonesArray *branchMissingET = treeReader->UseBranch("MissingET"); TClonesArray *branchGenMissingET = treeReader->UseBranch("GenMissingET"); Long64_t allEntries = treeReader->GetEntries(); cout << "** Chain contains " << allEntries << " events" << endl; Long64_t entry; Jet *genjet, *jet, *b1jet, *b2jet, *genb1jet, *genb2jet; b1jet=0; b2jet=0; genb1jet =0; genb2jet=0; MissingET *Met, *genMet; Met=0; GenParticle *particle, *genh2, *genhiggs1, *genhiggs2, *genhtobb, *genb1, *genb2; genhtobb =0; genb1= 0; genb2=0; GenParticle *genhtoWW, *genW1, *genW2, *genmu1, *genmu2, *gennu1, *gennu2; genmu1=0; genmu2=0; gennu1=0; gennu2=0; Electron *electron; Photon *photon; Muon *muon, *muon1, *muon2, *muon1_beforeIso, *muon2_beforeIso; muon1 =0; muon2=0; muon1_beforeIso =0; muon2_beforeIso =0; //Track *track; //Tower *tower; TLorentzVector momentum; TLorentzVector Muon1_p4, Muon2_p4, b1jet_p4, b2jet_p4; TLorentzVector totjets_lorentz = TLorentzVector(); //incase compilation error genhtoWW = 0; Int_t i; // Loop over all events //TFile *MMCfile = new TFile("testMMC.root", "recreate"); for(entry = 0; entry < allEntries; ++entry) //for(entry = 0; entry < 1000; ++entry) //for(entry = 0; entry < 10000; ++entry) { //gen htobb = false; hasgenb1jet = false; hasgenb2jet = false; Wtomu1nu1 = false; Wtomu2nu2 = false; hastwogenmuons = false; htoWW = false; hasGenMET = false; //reco hasb1jet = false; hasb2jet = false; hastwomuons = false; hasMET = false; hasMuon1_beforeIso = false; hasMuon2_beforeIso = false; hasMuon1 = false; hasMuon2 = false; hasdRljet = false; dR_b1jet = 2.0; dR_b2jet = 2.0; dR_genb1jet = 2.0; dR_genb2jet = 2.0; dR_mu1 = 2.0; dR_mu2 = 2.0; dR_mu1_beforeIso = 2.0; dR_mu2_beforeIso = 2.0; // Load selected branches with data from specified event treeReader->ReadEntry(entry); cout <<" event id " << entry << endl; /*for (i =0; i < branchParticle->GetEntries(); ++i){ genP = (GenParticle*) branchParticle->At(i); //defualt M1 M2 D1 D2 is -1; cout << " genP Id " << genP->PID <<" Pt " << genP->PT << " M1 "<< genP->M1<<" M2 "<< genP->M2 << " D1 "<< genP->D1 <<" D2 "<<genP->D2<< endl; if ( genP->M1 >= 0 && genP->M1 <branchParticle->GetEntries()){ GenParticle *M1P= (GenParticle*) branchParticle->At(genP->M1); cout <<" M1 Id " << M1P->PID <<" Pt " << M1P->PT << std::endl; } if ( genP->D1 >= 0 && genP->D1 <branchParticle->GetEntries()){ GenParticle *D1P= (GenParticle*) branchParticle->At(genP->D1); cout <<" D1 Id " << D1P->PID <<" Pt " << D1P->PT << std::endl; } }*/ genh2 = (GenParticle*) branchParticle->At(0); //printGenParticle(genP); h2tohh_mass = genh2->Mass; genhiggs1 = (GenParticle*) branchParticle->At(genh2->D1); //printGenParticle(genhiggs1); genhiggs2 = (GenParticle*) branchParticle->At(genh2->D2); //printGenParticle(genhiggs2); while ((genhiggs1->D1>0 && ((GenParticle*)branchParticle->At(genhiggs1->D1))->PID == genhiggs1->PID) || (genhiggs1->D2>0 && ((GenParticle*)branchParticle->At(genhiggs1->D2))->PID == genhiggs1->PID)){ if (genhiggs1->D1>0 && ((GenParticle*)branchParticle->At(genhiggs1->D1))->PID == genhiggs1->PID) genhiggs1 = (GenParticle*)branchParticle->At(genhiggs1->D1); else genhiggs1 = (GenParticle*)branchParticle->At(genhiggs1->D2); } while ((genhiggs2->D1>0 && ((GenParticle*)branchParticle->At(genhiggs2->D1))->PID == genhiggs2->PID) || (genhiggs2->D2>0 && ((GenParticle*)branchParticle->At(genhiggs2->D2))->PID == genhiggs2->PID)){ if (genhiggs2->D1>0 && ((GenParticle*)branchParticle->At(genhiggs2->D1))->PID == genhiggs2->PID) genhiggs2 = (GenParticle*)branchParticle->At(genhiggs2->D1); else genhiggs2 = (GenParticle*)branchParticle->At(genhiggs2->D2); } if (abs(((GenParticle*)branchParticle->At(genhiggs1->D1))->PID) ==5 ) { //printGenParticle(genhiggs1); //printGenParticle((GenParticle*)branchParticle->At(genhiggs1->D1)); //printGenParticle((GenParticle*)branchParticle->At(genhiggs1->D2)); htobb = true; genhtobb = genhiggs1; } else if (abs(((GenParticle*)branchParticle->At(genhiggs2->D1))->PID) ==5 ) { //printGenParticle(genhiggs2); //printGenParticle((GenParticle*)branchParticle->At(genhiggs2->D1)); //printGenParticle((GenParticle*)branchParticle->At(genhiggs2->D2)); htobb = true; genhtobb = genhiggs2; } if (abs(((GenParticle*)branchParticle->At(genhiggs2->D1))->PID) == 24){ htoWW = true; genhtoWW = genhiggs2; }else if (abs(((GenParticle*)branchParticle->At(genhiggs1->D1))->PID) == 24){ htoWW = true; genhtoWW = genhiggs1; } if (htobb){ if (((GenParticle*)branchParticle->At(genhtobb->D1))->PID == 5){ genb1 = (GenParticle*)branchParticle->At(genhtobb->D1); genb2 = (GenParticle*)branchParticle->At(genhtobb->D2); } else { genb1 = (GenParticle*)branchParticle->At(genhtobb->D2); genb2 = (GenParticle*)branchParticle->At(genhtobb->D1); } //move on to "final state" bquarks //printGenParticle(genhtobb); getFinalState(genb1, branchParticle); getFinalState(genb2, branchParticle); b1_px = genb1->Px; b1_py = genb1->Py; b1_pz = genb1->Pz; b1_eta = genb1->Eta; b1_phi = genb1->Phi; b1_pt = genb1->PT; b1_energy = genb1->E; b2_px = genb2->Px; b2_py = genb2->Py; b2_pz = genb2->Pz; b2_eta = genb2->Eta; b2_phi = genb2->Phi; b2_pt = genb2->PT; b2_energy = genb2->E; TLorentzVector bbbar_lorentz = genb1->P4()+genb2->P4(); //cout << " bbbar_lorentz Mass "<< bbbar_lorentz.M(); bbbar_lorentz.Print(); htobb_px = genhtobb->Px; htobb_py= genhtobb->Py; htobb_pz = genhtobb->Pz; htobb_energy = genhtobb->E; htobb_mass = genhtobb->Mass; } if (htoWW){ if (((GenParticle*)branchParticle->At(genhtoWW->D1))->PID == -24){//W- genW1 = (GenParticle*)branchParticle->At(genhtoWW->D1); //to muon(13) genW2 = (GenParticle*)branchParticle->At(genhtoWW->D2); } else { genW1 = (GenParticle*)branchParticle->At(genhtoWW->D2); genW2 = (GenParticle*)branchParticle->At(genhtoWW->D1); } getFinalState(genW1, branchParticle); // cout <<" htoWW genW1 "; printGenParticle(genW1); getFinalState(genW2, branchParticle); //cout <<" htoWW genW2 "; printGenParticle(genW2); if (genW1->D1>0 && ((GenParticle*)branchParticle->At(genW1->D1))->PID == 13){ genmu1 = (GenParticle*)branchParticle->At(genW1->D1); gennu1 = (GenParticle*)branchParticle->At(genW1->D2); Wtomu1nu1 = true; }else if (genW1->D2 >0 && ((GenParticle*)branchParticle->At(genW1->D2))->PID == 13){ genmu1 = (GenParticle*)branchParticle->At(genW1->D2); gennu1 = (GenParticle*)branchParticle->At(genW1->D1); Wtomu1nu1 = true; } if (genW2->D1>0 && ((GenParticle*)branchParticle->At(genW2->D1))->PID == -13){ genmu2 = (GenParticle*)branchParticle->At(genW2->D1); gennu2 = (GenParticle*)branchParticle->At(genW2->D2); Wtomu2nu2 = true; } else if (genW2->D1>0 && ((GenParticle*)branchParticle->At(genW2->D2))->PID == -13){ genmu2 = (GenParticle*)branchParticle->At(genW2->D2); gennu2 = (GenParticle*)branchParticle->At(genW2->D1); Wtomu2nu2 = true; } } if (Wtomu1nu1){ getFinalState(genmu1, branchParticle); getFinalState(gennu1, branchParticle); mu1_px = genmu1->Px; mu1_py = genmu1->Py; mu1_pz = genmu1->Pz; mu1_energy = genmu1->E; mu1_eta = genmu1->Eta; mu1_phi = genmu1->Phi; mu1_pt = genmu1->PT; nu1_px = gennu1->Px; nu1_py = gennu1->Py; nu1_pz = gennu1->Pz; nu1_energy = gennu1->E; nu1_eta = gennu1->Eta; nu1_phi = gennu1->Phi; nu1_pt = gennu1->PT; //cout << "mu1 from W "; printGenParticle(genmu1); } if (Wtomu2nu2){ getFinalState(genmu2, branchParticle); getFinalState(gennu2, branchParticle); mu2_px = genmu2->Px; mu2_py = genmu2->Py; mu2_pz = genmu2->Pz; mu2_energy = genmu2->E; mu2_eta = genmu2->Eta; mu2_phi = genmu2->Phi; mu2_pt = genmu2->PT; nu2_px = gennu2->Px; nu2_py = gennu2->Py; nu2_pz = gennu2->Pz; nu2_energy = gennu2->E; nu2_eta = gennu2->Eta; nu2_phi = gennu2->Phi; nu2_pt = gennu2->PT; //cout << "mu2 from W "; printGenParticle(genmu2); } //loop all Gen jets for (i =0; i< branchGenJet->GetEntries(); i++) { genjet = (Jet*) branchGenJet->At(i); if (genjet->PT < bjetsPt_ || abs(genjet->Eta)> bjetsEta_) continue; TLorentzVector genjet_p4 = genjet->P4(); if (htobb && genjet_p4.DeltaR(genb1->P4()) < dR_genb1jet && genjet_p4.DeltaR(genb1->P4())<jetsDeltaR_) { dR_genb1jet = genjet_p4.DeltaR(genb1->P4()); genb1jet_px = genjet_p4.Px(); genb1jet_py = genjet_p4.Py(); genb1jet_pz=genjet_p4.Pz(); genb1jet_energy = genjet_p4.Energy(); genb1jet_eta = genjet_p4.Eta(); genb1jet_phi = genjet_p4.Phi(); genb1jet_pt = genjet_p4.Pt(); hasgenb1jet = true; genb1jet = genjet; } if (htobb && genjet_p4.DeltaR(genb2->P4()) < dR_genb2jet && genjet_p4.DeltaR(genb2->P4()) < jetsDeltaR_){ dR_genb2jet = genjet_p4.DeltaR(genb2->P4()); genb2jet_px = genjet_p4.Px(); genb2jet_py = genjet_p4.Py(); genb2jet_pz=genjet_p4.Pz(); genb2jet_energy = genjet_p4.Energy(); genb2jet_eta = genjet_p4.Eta(); genb2jet_phi = genjet_p4.Phi(); genb2jet_pt = genjet_p4.Pt(); hasgenb2jet = true; genb2jet = genjet; } } //loop all reco jets for (i =0; i< branchJet->GetEntries(); i++) { jet = (Jet*) branchJet->At(i); if (jet->PT < jetsPt_ || abs(jet->Eta)> jetsEta_) continue; totjets_lorentz +=jet->P4(); if (jet->PT < bjetsPt_ || abs(jet->Eta)> bjetsEta_) continue; TLorentzVector jet_p4 = jet->P4(); if (htobb && jet_p4.DeltaR(genb1->P4()) < dR_b1jet && jet_p4.DeltaR(genb1->P4()) < jetsDeltaR_) { b1jet = jet; dR_b1jet = jet_p4.DeltaR(genb1->P4()); b1jet_p4 = jet_p4; b1jet_px = jet_p4.Px(); b1jet_py = jet_p4.Py(); b1jet_pz=jet_p4.Pz(); b1jet_energy = jet_p4.Energy(); b1jet_eta = jet_p4.Eta(); b1jet_phi = jet_p4.Phi(); b1jet_pt = jet_p4.Pt(); hasb1jet = true; } if (htobb && jet_p4.DeltaR(genb2->P4()) < dR_b2jet && jet_p4.DeltaR(genb2->P4()) < jetsDeltaR_){ b2jet = jet; dR_b2jet = jet_p4.DeltaR(genb2->P4()); b2jet_p4 = jet_p4; b2jet_px = jet_p4.Px(); b2jet_py = jet_p4.Py(); b2jet_pz=jet_p4.Pz(); b2jet_energy = jet_p4.Energy(); b2jet_eta = jet_p4.Eta(); b2jet_phi = jet_p4.Phi(); b2jet_pt = jet_p4.Pt(); hasb2jet = true; } } // b1jet should be different from b2jet if (hasb1jet && hasb2jet && b1jet == b2jet){ hasb1jet = false; hasb2jet = false; } else if (hasb1jet && hasb2jet){ //cout <<" b1jet Pt " << b1jet->PT <<" b2jet Pt " << b2jet->PT << endl; // TLorentzVector htobb_jets = b1jet->P4()+b2jet->P4(); //cout <<" htobb_jet " << htobb_jets.M(); htobb_jets.Print(); } // Analyse missing ET, generator level if(branchGenMissingET->GetEntriesFast() > 0) { genMet = (MissingET*) branchGenMissingET->At(0); genmet = genMet->MET; genmet_phi = genMet->Phi; genmet_px = genMet->P4().Px(); genmet_py = genMet->P4().Py(); if (genmet > metPt_) hasGenMET = true; } //apply muon cuts on muons // Analyse missing ET, reco level if(branchMissingET->GetEntriesFast() > 0) { Met = (MissingET*) branchMissingET->At(0); met = Met->MET; met_phi = Met->Phi; met_px = Met->P4().Px(); met_py = Met->P4().Py(); if (met > metPt_) hasMET = true; } //apply muon cuts on muons if (Wtomu1nu1 && Wtomu2nu2){ if (((genmu1->PT > muonPt1_ && genmu2->PT > muonPt2_) || (genmu1->PT > muonPt2_ && genmu2->PT > muonPt1_)) && fabs(genmu1->Eta)<muonsEta_ && fabs(genmu2->Eta)< muonsEta_) hastwogenmuons =true; } //Loop over all Muon(before Isolation) in event //how to check whether deltaR matching and matching genparticle has same performance?? // for(i = 0; i < branchMuonBeforeIso->GetEntriesFast(); ++i) { muon = (Muon*) branchMuonBeforeIso->At(i); TLorentzVector muon_p4 = muon->P4(); // particle = (GenParticle*) muon->Particle.GetObject(); // printGenParticle(particle); if (Wtomu1nu1 and muon->Charge<0 and muon_p4.DeltaR(genmu1->P4())<dR_mu1_beforeIso and muon_p4.DeltaR(genmu1->P4())<leptonsDeltaR_) { dR_mu1_beforeIso = muon_p4.DeltaR(genmu1->P4()); muon1_beforeIso = muon; hasMuon1_beforeIso = true; if (particle == genmu1) Muon1_beforeIso_hasgenMu = true; } else if(Wtomu2nu2 and muon->Charge>0 and muon_p4.DeltaR(genmu2->P4())<dR_mu2_beforeIso and muon_p4.DeltaR(genmu2->P4())<leptonsDeltaR_) { dR_mu2_beforeIso = muon_p4.DeltaR(genmu2->P4()); muon2_beforeIso = muon; hasMuon2_beforeIso = true; if (particle == genmu2) Muon2_beforeIso_hasgenMu = true; } if (hasMuon1_beforeIso) std::cout <<" has reco Muon1 before Iso " << std::endl; if (hasMuon2_beforeIso) std::cout <<" has reco Muon2 before Iso " << std::endl; } if (hasMuon1_beforeIso){ Muon1_beforeIso_px = muon1_beforeIso->P4().Px(); Muon1_beforeIso_py = muon1_beforeIso->P4().Py(); Muon1_beforeIso_pz = muon1_beforeIso->P4().Pz(); Muon1_beforeIso_energy = muon1_beforeIso->P4().E(); Muon1_beforeIso_eta = muon1_beforeIso->P4().Eta(); Muon1_beforeIso_phi = muon1_beforeIso->P4().Phi(); Muon1_pt = muon1_beforeIso->PT; } if (hasMuon2_beforeIso){ Muon2_beforeIso_px = muon2_beforeIso->P4().Px(); Muon2_beforeIso_py = muon2_beforeIso->P4().Py(); Muon2_beforeIso_pz = muon2_beforeIso->P4().Pz(); Muon2_beforeIso_energy = muon2_beforeIso->P4().E(); Muon2_beforeIso_eta = muon2_beforeIso->P4().Eta(); Muon2_beforeIso_phi = muon2_beforeIso->P4().Phi(); Muon2_pt = muon2_beforeIso->PT; } // Loop over all Muon in event, reco muon for(i = 0; i < branchMuon->GetEntriesFast(); ++i) { muon = (Muon*) branchMuon->At(i); TLorentzVector muon_p4 = muon->P4(); particle = (GenParticle*) muon->Particle.GetObject(); // printGenParticle(particle); if (hasMuon1_beforeIso and muon->Eta == muon1_beforeIso->Eta and muon->Phi == muon1_beforeIso->Phi) Muon1_beforeIso_passIso = true; if (hasMuon2_beforeIso and muon->Eta == muon2_beforeIso->Eta and muon->Phi == muon2_beforeIso->Phi) Muon2_beforeIso_passIso = true; //check charge and deltaR, genmu1: charge<0, genmu2: charge>0 if (Wtomu1nu1 and muon->Charge<0 and muon_p4.DeltaR(genmu1->P4())<dR_mu1 and muon_p4.DeltaR(genmu1->P4())<leptonsDeltaR_) { dR_mu1 = muon_p4.DeltaR(genmu1->P4()); muon1 = muon; hasMuon1 = true; if (particle == genmu1) Muon1_hasgenMu = true; } else if (Wtomu2nu2 and muon->Charge>0 and muon_p4.DeltaR(genmu2->P4())<dR_mu2 and muon_p4.DeltaR(genmu2->P4())<leptonsDeltaR_) { dR_mu2 = muon_p4.DeltaR(genmu2->P4()); muon2 = muon; hasMuon2 = true; if (particle == genmu2) Muon2_hasgenMu = true; } if (hasMuon1) std::cout <<" has reco Muon1 " << std::endl; if (hasMuon2) std::cout <<" has reco Muon2 " << std::endl; //cout <<" muon eta " << muon->Eta << " phi " << muon->Phi << " Pt "<< muon->PT << endl; } if (hasMuon1){ Muon1_p4 = muon1->P4(); Muon1_px = muon1->P4().Px(); Muon1_py = muon1->P4().Py(); Muon1_pz = muon1->P4().Pz(); Muon1_energy = muon1->P4().E(); Muon1_eta = muon1->P4().Eta(); Muon1_phi = muon1->P4().Phi(); Muon1_pt = muon1->PT; } if (hasMuon2){ Muon2_p4 = muon2->P4(); Muon2_px = muon2->P4().Px(); Muon2_py = muon2->P4().Py(); Muon2_pz = muon2->P4().Pz(); Muon2_energy = muon2->P4().E(); Muon2_eta = muon2->P4().Eta(); Muon2_phi = muon2->P4().Phi(); Muon2_pt = muon2->PT; } if (hasMuon1 && hasMuon2){ if (((muon1->PT > muonPt1_ && muon2->PT > muonPt2_) || (muon1->PT > muonPt2_ && muon2->PT > muonPt1_)) && fabs(muon1->Eta)<muonsEta_ && fabs(muon2->Eta)< muonsEta_) hastwomuons =true; } // Loop over all electrons in event for(i = 0; i < branchElectron->GetEntriesFast(); ++i) { electron = (Electron*) branchElectron->At(i); particle = (GenParticle*) electron->Particle.GetObject(); //cout <<" electron "; printGenParticle(particle); } // Loop over all photons in event for(i = 0; i < branchPhoton->GetEntriesFast(); ++i) { photon = (Photon*) branchPhoton->At(i); // skip photons with references to multiple particles if(photon->Particles.GetEntriesFast() != 1) continue; particle = (GenParticle*) photon->Particles.At(0); //cout <<" photon "; printGenParticle(particle); } if (hasb1jet and hasb2jet and hasMuon1 and hasMuon2){ dR_b1l1 = b1jet_p4.DeltaR(Muon1_p4); dR_b1l2 = b1jet_p4.DeltaR(Muon2_p4); dR_b2l1 = b2jet_p4.DeltaR(Muon1_p4); dR_b2l2 = b2jet_p4.DeltaR(Muon2_p4); dR_b1b2 = b1jet_p4.DeltaR(b2jet_p4); dR_l1l2 = Muon1_p4.DeltaR(Muon2_p4); TLorentzVector ll_p4 = Muon1_p4+Muon2_p4; TLorentzVector bjets_p4 = b1jet_p4+b2jet_p4; mass_l1l2 = ll_p4.M(); mass_b1b2 = bjets_p4.M(); if (dR_b1l1>jetleptonDeltaR_ and dR_b1l2>jetleptonDeltaR_ and dR_b2l1>jetleptonDeltaR_ and dR_b2l2>jetleptonDeltaR_) hasdRljet =true; } // Loop over all tracks in event /* for(i = 0; i < branchTrack->GetEntriesFast(); ++i) { track = (Track*) branchTrack->At(i); particle = (GenParticle*) track->Particle.GetObject(); cout <<" Track "; printGenParticle(particle); }*/ // calculate the DeltaR between bjet and lepton h2tohh = (htobb and Wtomu1nu1 and Wtomu2nu2); if (runMMC_ && h2tohh && hasgenb1jet && hasgenb2jet){ TLorentzVector bjets_lorentz=genb1jet->P4()+genb2jet->P4(); cout <<" m_{bjets} " << bjets_lorentz.M(); bjets_lorentz.Print(); TLorentzVector met_lorentz = Met->P4(); bool simulation_ = true; bool weightfromonshellnupt_func = false; bool weightfromonshellnupt_hist = true; bool weightfromonoffshellWmass_hist=true; int iterations = 100000; std::string RefPDFfile("MMCRefPDF.ROOT"); bool useMET = true; int onshellMarker_; if (genW1->Mass > genW2->Mass) onshellMarker_=1; else onshellMarker_=2; // rescale bjets in MMC????? //MMC *thismmc = new MMC(); MMC *thismmc = new MMC(genmu1->P4(), genmu2->P4(), bjets_lorentz, totjets_lorentz, met_lorentz, gennu1->P4(), gennu2->P4(), genb1->P4()+genb2->P4(), genh2->P4(), onshellMarker_,// only for simulation simulation_, entry, weightfromonshellnupt_func, weightfromonshellnupt_hist, weightfromonoffshellWmass_hist, iterations, RefPDFfile, useMET); thismmc->runMMC(); TTree *mmctree = (thismmc->getMMCTree())->CloneTree(); std::cout <<"MMCTree entries " << (thismmc->getMMCTree())->GetEntries() << std::endl; std::cout <<"testtree entries " << mmctree->GetEntries()<<" title "<< mmctree->GetTitle() << std::endl; //esttree->SetDirectory((TDirectory*)MMCfile); //MMCfile->WriteObject(mmctree,mmctree->GetTitle()); delete thismmc; } //fill branches if (htobb || (Wtomu1nu1 && Wtomu2nu2)) evtree->Fill(); } // MMCfile->Close(); //delete MMCfile; //evtree->Fill(); }
void FlagClones(string fileName = "BsphiKK_data_duplicates.root") { // get the input TTree* tree = GetTree(fileName.c_str()); // clone the tree.. int num_entries = tree->GetEntries(); vector<int> flag_clones; flag_clones.resize(num_entries); for (int i = 0; i < num_entries; ++i) { flag_clones[i] = 1; } double sort_var; //tree->SetBranchAddress("B_s0_ENDVERTEX_CHI2",&sort_var); UInt_t run;tree->SetBranchAddress("runNumber",&run); ULong64_t event; tree->SetBranchAddress("eventNumber",&event); int key1; tree->SetBranchAddress("Kminus_TRACK_Key",&key1); int key2; tree->SetBranchAddress("Kminus0_TRACK_Key",&key2); int key3; tree->SetBranchAddress("Kplus_TRACK_Key",&key3); int key4; tree->SetBranchAddress("Kplus0_TRACK_Key",&key4); int i = 0; TRandom generator(9875); cout << "Finding duplicate candidates in a sample containing " << num_entries << " events" << endl; while(i < num_entries) { tree->GetEntry(i); sort_var = generator.Rndm(); int run_i = run; int event_i = event; vector<CloneInfo> clones; CloneTagger tagger(clones); tagger.addToClones({key1,key2,key3,key4},i,sort_var); int j = i+1; for (j=i+1;j<num_entries; j++) { tree->GetEntry(j); sort_var = generator.Rndm(); int run_j = run; int event_j = event; if(run_j!=run_i || event_j!=event_i) { break; } else { tagger.addToClones({key1,key2,key3,key4},j,sort_var); } } tagger.sortClones(); tagger.tagClones(); if(clones.size() > 1) { for(auto clone : clones) { flag_clones[clone.i()] = clone.isAlive(); } } i=j; } // make the output string outputName = fileName.substr(0,fileName.size() - 5); outputName += "_Clone.root"; TFile* outFile = TFile::Open(outputName.c_str(),"RECREATE"); cout << "Reading: " << tree->GetName() << " from " << fileName << " to " << outputName << endl; TTree* newtree = tree->CloneTree(-1); int isAlive; TBranch *branch_bestVtxChi2 = newtree->Branch("isDup",&isAlive, "isDup/I"); num_entries = newtree->GetEntries(); // loop again and write the branch for (i=0;i<num_entries; i++) { newtree->GetEntry(i); isAlive = flag_clones[i]; branch_bestVtxChi2->Fill(); } newtree->Write(); outFile->Close(); return; }
void ReadSpecAOD(const char *fileName = "AliMuonAOD.root") { gSystem->Load("libTree"); gSystem->Load("libGeom"); gSystem->Load("libSTEERBase"); gSystem->Load("libAOD"); gSystem->Load("libANALYSIS"); gSystem->Load("libPWGHFbase"); gStyle->SetOptStat(111111); gStyle->SetFrameFillColor(10); gStyle->SetCanvasColor(10); gStyle->SetOptStat(0); TH1F *mass=new TH1F("mass","Invariant mass",100,0.,20.); TH1F *rap=new TH1F("rap","Rapidity",100,-5.,0.); TH1F *cost=new TH1F("cost","Cost_CS",100,-1.,1.); TH1F *pt=new TH1F("pt","Pt",100,0.,50.); TH1F *ptmuon=new TH1F("ptmuon","single muon Pt",100,0.,50.); // open input file and get the TTree TFile inFile(fileName, "READ"); TTree *aodTree = (TTree*)inFile.Get("AOD"); AliAODEvent *aod = (AliAODEvent*)aodTree->GetUserInfo()->FindObject("AliAODEvent"); TClonesArray *Dimuons; TClonesArray *tracks; TClonesArray *vertices; AliAODEventInfo *MuonInfos; aodTree->SetBranchAddress("Dimuons",&Dimuons); aodTree->SetBranchAddress("tracks",&tracks); aodTree->SetBranchAddress("vertices",&vertices); aodTree->SetBranchAddress("MuonInfos",&MuonInfos); // loop over events Int_t nEvents = aodTree->GetEntries(); for (Int_t nEv = 0; nEv < nEvents; nEv++) { cout << "Event: " << nEv+1 << "/" << nEvents << endl; aodTree->GetEntry(nEv); // loop over tracks Int_t nTracks = tracks->GetEntries(); for (Int_t nTr = 0; nTr < nTracks; nTr++) { AliAODTrack *tr = (AliAODTrack *)tracks->At(nTr); ptmuon->Fill(tr->Pt()); // print track info cout << nTr+1 << "/" << nTracks << ": track pt: " << tr->Pt(); if (tr->GetProdVertex()) { cout << ", vertex z of this track: " << tr->GetProdVertex()->GetZ(); } cout << endl; } // loop over dimuons Int_t nDimuons = Dimuons->GetEntries(); cout << nDimuons << " dimuon(s)" << endl; for(Int_t nDi=0; nDi < nDimuons; nDi++){ AliAODDimuon *di=(AliAODDimuon*)Dimuons->At(nDi); if((MuonInfos->MUON_Unlike_HPt_L0())){ mass->Fill(di->M()); pt->Fill(di->Pt()); rap->Fill(di->Y()); cost->Fill(di->CostCS()); cout << "Dimuon: " << nDi << " q: " << di->Charge() << " m: " << di->M() << " Y: " << di->Y() << " Pt: " << di->Pt()<< " CostCS: " << di->CostCS() << endl ; } } // // loop over vertices // Int_t nVtxs = vertices->GetEntries(); // for (Int_t nVtx = 0; nVtx < nVtxs; nVtx++) { // // // print track info // cout << nVtx+1 << "/" << nVtxs << ": vertex z position: " <<vertices->At(nVtx)->GetZ() << endl; // } } inFile.Close(); TCanvas *c1=new TCanvas(); c1->Show(); c1->Divide(2,2); c1->ForceUpdate(); c1->cd(1); mass->DrawClone(); c1->cd(2); rap->DrawClone(); c1->cd(3); pt->DrawClone(); c1->cd(4); cost->DrawClone(); TCanvas *c2 = new TCanvas(); c2->cd(); ptmuon->DrawClone(); return; }