//macro for creation of signal and backfround samples for TMVA training //author: A.Karavdina //date:23/04/2014 (v.2.0) void SeparateSig(TString path ="/panda/myResults/DPMoutputMarch2014_BeamProf_newXYCut/mom_1_5/"){ double sigmaThrec = 1e-3*1*700; //1.5 GeV // double sigmaThrec = 1e-3*74; //15 GeV // double sigmaThrec = 1e-3*212; //4.06 GeV TString filename1 = path+"/TOT_Lumi_BkgSig_BeamShape_XYnewCut.root"; //input TString filename2 = path+"/GoodBadSig_3sigma_3sigma_DPMel.root";//ouput TFile *fin1 = new TFile(filename1,"READ"); TTree *tsig = (TTree *)fin1->Get("tSig"); //All signal data //fin1->Close(); Int_t neventGL = tsig->GetEntries(); double f_thmc,f_threc,f_phrec; double f_xrec,f_yrec,f_zrec,f_prec; TBranch *bismom = tsig->GetBranch("prec"); bismom->SetAddress(&f_prec); TBranch *bisthrec = tsig->GetBranch("threc"); bisthrec->SetAddress(&f_threc); TBranch *bisphrec = tsig->GetBranch("phrec"); bisphrec->SetAddress(&f_phrec); TBranch *bisthmc = tsig->GetBranch("thmc"); bisthmc->SetAddress(&f_thmc); TBranch *bisxpca = tsig->GetBranch("xrec"); bisxpca->SetAddress(&f_xrec); TBranch *bisypca = tsig->GetBranch("yrec"); bisypca->SetAddress(&f_yrec); TBranch *biszpca = tsig->GetBranch("zrec"); biszpca->SetAddress(&f_zrec); TFile *fout = new TFile(filename2,"RECREATE"); TTree *tsigGood = new TTree("sigGood","good signal"); Float_t glTheta_gd,glPhi_gd,glXpca_gd,glYpca_gd,glZpca_gd,glP_gd; Float_t glThetaMC_gd; tsigGood->Branch("athmc",&glThetaMC_gd); tsigGood->Branch("athrec",&glTheta_gd); tsigGood->Branch("aphrec",&glPhi_gd); tsigGood->Branch("axrec",&glXpca_gd); tsigGood->Branch("ayrec",&glYpca_gd); tsigGood->Branch("azrec",&glZpca_gd); tsigGood->Branch("aprec",&glP_gd); TTree *tsigBad = new TTree("sigBad","bad signal"); Float_t glTheta_bd,glPhi_bd,glXpca_bd,glYpca_bd,glZpca_bd,glP_bd; Float_t glThetaMC_bd; tsigBad->Branch("athmc",&glThetaMC_bd); tsigBad->Branch("athrec",&glTheta_bd); tsigBad->Branch("aphrec",&glPhi_bd); tsigBad->Branch("axrec",&glXpca_bd); tsigBad->Branch("ayrec",&glYpca_bd); tsigBad->Branch("azrec",&glZpca_bd); tsigBad->Branch("aprec",&glP_bd); for (Int_t i=0;iGetEntries(); tsig->GetEvent(i); // cout<<"fabs(f_thmc-f_threc) = |"<Fill(); } if(fabs(f_thmc-f_threc)>2.7*sigmaThrec){ //bad signal // if(fabs(f_thmc-f_threc)>3*sigmaThrec && f_thmc>8e-3){ //bad signal glTheta_bd = f_threc; glThetaMC_bd = f_thmc; glXpca_bd = f_xrec; glYpca_bd = f_yrec; glZpca_bd = f_zrec; glP_bd = f_prec; glPhi_bd = f_phrec; tsigBad->Fill(); } } /// add inelastic background TTree *tbkg = (TTree *)fin1->Get("tBkg"); //All rest bkg data Int_t neventGLb = tbkg->GetEntries(); double fb_thmc,fb_threc,fb_phrec; double fb_xrec,fb_yrec,fb_zrec,fb_prec; TBranch *bismomb = tbkg->GetBranch("prec"); bismomb->SetAddress(&fb_prec); TBranch *bisthrecb = tbkg->GetBranch("threc"); bisthrecb->SetAddress(&fb_threc); TBranch *bisphrecb = tbkg->GetBranch("phrec"); bisphrecb->SetAddress(&fb_phrec); TBranch *bisthmcb = tbkg->GetBranch("thmc"); bisthmcb->SetAddress(&fb_thmc); TBranch *bisxpcab = tbkg->GetBranch("xrec"); bisxpcab->SetAddress(&fb_xrec); TBranch *bisypcab = tbkg->GetBranch("yrec"); bisypcab->SetAddress(&fb_yrec); TBranch *biszpcab = tbkg->GetBranch("zrec"); biszpcab->SetAddress(&fb_zrec); for (Int_t i=0;iGetEvent(i); glTheta_bd = fb_threc; glThetaMC_bd = fb_thmc; glXpca_bd = fb_xrec; glYpca_bd = fb_yrec; glZpca_bd = fb_zrec; glP_bd = fb_prec; glPhi_bd = fb_phrec; tsigBad->Fill(); }//end loop over all bkg trks /// [END] add inelastic background tsigGood->Write(); tsigBad->Write(); fout->Write(); }