ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/benhoob/HWW/Classify_HWW.C
(Generate patch)

Comparing UserCode/benhoob/HWW/Classify_HWW.C (file contents):
Revision 1.5 by benhoob, Mon Feb 21 14:30:47 2011 UTC vs.
Revision 1.6 by benhoob, Wed Feb 23 15:14:14 2011 UTC

# Line 54 | Line 54 | void Classify_HWW( TString myMethodList
54  
55    //--------------------------------------------------------------------
56    // path to weights dir (this is where MVA training info is stored)
57 +  // output root file will be stored at [path]/output
58    //--------------------------------------------------------------------
59  
60 <  //TString path   = "Trainings/H130_WW_GGWW_WJets_4vars/";
61 <  TString path   = "Trainings/H130_allbkg_4vars/";
60 >  //TString path   = "Trainings/H130_WJetsFO3_tight_4vars/";
61 >  TString path   = "./";
62  
63    //-----------------------------------
64    // select samples to run over
# Line 75 | Line 76 | void Classify_HWW( TString myMethodList
76    samples.push_back("WJetsToLNu");
77    samples.push_back("DY");
78    samples.push_back("Higgs130");
79 +  samples.push_back("WJetsFO3");
80    //   samples.push_back("Higgs160");
81    //   samples.push_back("Higgs200");
82  
# Line 83 | Line 85 | void Classify_HWW( TString myMethodList
85    //--------------------------------------------------------------------------------
86    
87    std::map<std::string,int> mvaVar;
88 <  mvaVar[ "lephard_pt" ]      = 1;
89 <  mvaVar[ "lepsoft_pt" ]      = 1;
90 <  mvaVar[ "dil_dphi" ]        = 1;
91 <  mvaVar[ "dil_mass" ]        = 1;
92 <  mvaVar[ "event_type" ]      = 0;
93 <  mvaVar[ "met_projpt" ]      = 0;
94 <  mvaVar[ "met_pt" ]          = 0;
95 <  mvaVar[ "mt_lephardmet" ]   = 0;
96 <  mvaVar[ "mt_lepsoftmet" ]   = 0;
97 <  mvaVar[ "dphi_lephardmet" ] = 0;
98 <  mvaVar[ "dphi_lepsoftmet" ] = 0;
88 >  mvaVar[ "lephard_pt" ]        = 1;
89 >  mvaVar[ "lepsoft_pt" ]        = 1;
90 >  mvaVar[ "dil_dphi" ]          = 1;
91 >  mvaVar[ "dil_mass" ]          = 1;
92 >  mvaVar[ "event_type" ]        = 0;
93 >  mvaVar[ "met_projpt" ]        = 0;
94 >  mvaVar[ "met_pt" ]            = 0;
95 >  mvaVar[ "mt_lephardmet" ]     = 0;
96 >  mvaVar[ "mt_lepsoftmet" ]     = 0;
97 >  mvaVar[ "dphi_lephardmet" ]   = 0;
98 >  mvaVar[ "dphi_lepsoftmet" ]   = 0;
99 >  mvaVar[ "lepsoft_fbrem" ]     = 0;
100 >  mvaVar[ "lepsoft_eOverPIn" ]  = 0;
101 >  mvaVar[ "lepsoft_qdphi" ]     = 0;
102  
103    //---------------------------------------------------------------
104  
# Line 219 | Line 224 | void Classify_HWW( TString myMethodList
224      Float_t mt_lepsoftmet;
225      Float_t dphi_lephardmet;
226      Float_t dphi_lepsoftmet;
227 <
228 <    if( mvaVar["lephard_pt"])      reader->AddVariable( "lephard_pt"        ,   &lephard_pt );
229 <    if( mvaVar["lepsoft_pt"])      reader->AddVariable( "lepsoft_pt"        ,   &lepsoft_pt );
230 <    if( mvaVar["dil_dphi"])        reader->AddVariable( "dil_dphi"          ,   &dil_dphi   );
231 <    if( mvaVar["dil_mass"])        reader->AddVariable( "dil_mass"          ,   &dil_mass   );
232 <    if( mvaVar["event_type"])      reader->AddVariable( "event_type"        ,   &event_type );
233 <    if( mvaVar["met_projpt"])      reader->AddVariable( "met_projpt"        ,   &met_pt     );
234 <    if( mvaVar["met_pt"])          reader->AddVariable( "met_pt"            ,   &met_pt     );
235 <    if( mvaVar["mt_lephardmet"])   reader->AddVariable( "mt_lephardmet"     ,   &mt_lephardmet     );
236 <    if( mvaVar["mt_lepsoftmet"])   reader->AddVariable( "mt_lepsoftmet"     ,   &mt_lepsoftmet     );
237 <    if( mvaVar["dphi_lephardmet"]) reader->AddVariable( "dphi_lephardmet"   ,   &dphi_lephardmet     );
238 <    if( mvaVar["dphi_lepsoftmet"]) reader->AddVariable( "dphi_lepsoftmet"   ,   &dphi_lepsoftmet     );
227 >    Float_t lepsoft_fbrem;
228 >    Float_t lepsoft_eOverPIn;
229 >    Float_t lepsoft_qdphi;
230 >
231 >    if( mvaVar["lephard_pt"])       reader->AddVariable( "lephard_pt"                  ,   &lephard_pt );
232 >    if( mvaVar["lepsoft_pt"])       reader->AddVariable( "lepsoft_pt"                  ,   &lepsoft_pt );
233 >    if( mvaVar["dil_dphi"])         reader->AddVariable( "dil_dphi"                    ,   &dil_dphi   );
234 >    if( mvaVar["dil_mass"])         reader->AddVariable( "dil_mass"                    ,   &dil_mass   );
235 >    if( mvaVar["event_type"])       reader->AddVariable( "event_type"                  ,   &event_type );
236 >    if( mvaVar["met_projpt"])       reader->AddVariable( "met_projpt"                  ,   &met_pt     );
237 >    if( mvaVar["met_pt"])           reader->AddVariable( "met_pt"                      ,   &met_pt     );
238 >    if( mvaVar["mt_lephardmet"])    reader->AddVariable( "mt_lephardmet"               ,   &mt_lephardmet     );
239 >    if( mvaVar["mt_lepsoftmet"])    reader->AddVariable( "mt_lepsoftmet"               ,   &mt_lepsoftmet     );
240 >    if( mvaVar["dphi_lephardmet"])  reader->AddVariable( "dphi_lephardmet"             ,   &dphi_lephardmet   );
241 >    if( mvaVar["dphi_lepsoftmet"])  reader->AddVariable( "dphi_lepsoftmet"             ,   &dphi_lepsoftmet   );
242 >    if( mvaVar["lepsoft_fbrem"])    reader->AddVariable( "lepsoft_fbrem"               ,   &lepsoft_fbrem     );
243 >    if( mvaVar["lepsoft_eOverPIn"]) reader->AddVariable( "lepsoft_eOverPIn"            ,   &lepsoft_eOverPIn  );
244 >    if( mvaVar["lepsoft_qdphi"])    reader->AddVariable( "lepsoft_q * lepsoft_dPhiIn"  ,   &lepsoft_qdphi     );
245  
246  
247      // Spectator variables declared in the training have to be added to the reader, too
# Line 254 | Line 265 | void Classify_HWW( TString myMethodList
265      // and the output root file is written to [path]/[output]
266      //--------------------------------------------------------------------------------------
267  
257    //TString dir    = "weights/";
258    //TString path   = "Trainings/H130_WWTo2L2Nu/";
259    //TString path   = "Trainings/H130_WWTo2L2Nu_WJetsToLNu/";
260  
268      TString dir    = path + "weights/";
269      TString outdir = path + "output/";
263
270      TString prefix = "TMVAClassification";
271  
272      // Book method(s)
# Line 299 | Line 305 | void Classify_HWW( TString myMethodList
305      if (Use["MLPBNN"])        histNnbnn   = new TH1F( "MVA_MLPBNN",        "MVA_MLPBNN",        nbin, -1.25, 1.5 );
306      if (Use["CFMlpANN"])      histNnC     = new TH1F( "MVA_CFMlpANN",      "MVA_CFMlpANN",      nbin,  0, 1 );
307      if (Use["TMlpANN"])       histNnT     = new TH1F( "MVA_TMlpANN",       "MVA_TMlpANN",       nbin, -1.3, 1.3 );
308 <    if (Use["BDT"])           histBdt     = new TH1F( "MVA_BDT",           "MVA_BDT",           nbin, -1.5, 0.5 );
308 >    if (Use["BDT"])           histBdt     = new TH1F( "MVA_BDT",           "MVA_BDT",           nbin, -1. , 1. );
309      if (Use["BDTD"])          histBdtD    = new TH1F( "MVA_BDTD",          "MVA_BDTD",          nbin, -0.8, 0.8 );
310      if (Use["BDTG"])          histBdtG    = new TH1F( "MVA_BDTG",          "MVA_BDTG",          nbin, -1.0, 1.0 );
311      if (Use["RuleFit"])       histRf      = new TH1F( "MVA_RuleFit",       "MVA_RuleFit",       nbin, -2.0, 2.0 );
# Line 356 | Line 362 | void Classify_HWW( TString myMethodList
362        rarityHistFi = new TH1F( "MVA_Fisher_Rarity", "MVA_Fisher_Rarity", nbin, 0, 1 );
363      }
364  
359    TH1F *hdilmass_BDT    = new TH1F("hdilmass_BDT",   "",100,0,200);
360    TH1F *hdilmass_MLPBNN = new TH1F("hdilmass_MLPBNN","",100,0,200);
361
365      // Prepare input tree (this must be replaced by your data source)
366      // in this example, there is a toy tree with signal and one with background events
367      // we'll later on use only the "signal" events for the test in this example.
# Line 375 | Line 378 | void Classify_HWW( TString myMethodList
378        ch -> Add( Form("%s/DYToTauTauM20_PU_testFinal_baby.root",babyPath) );
379        ch -> Add( Form("%s/DYToTauTauM10To20_PU_testFinal_baby.root",babyPath) );
380      }
381 +    if( strcmp( samples.at(i) , "WJetsFO3" ) == 0 ){
382 +      ch -> Add( Form("%s/WJetsToLNu_FOv3_PU_testFinal_baby.root",babyPath) );
383 +      ch -> Add( Form("%s/WToLNu_FOv3_testFinal_baby.root",babyPath) );
384 +    }
385      else if( strcmp( samples.at(i) , "Higgs130" ) == 0 ){
386        ch -> Add( Form("%s/HToWWTo2L2NuM130_PU_testFinal_baby.root",babyPath) );
387        ch -> Add( Form("%s/HToWWToLNuTauNuM130_PU_testFinal_baby.root",babyPath) );
# Line 394 | Line 401 | void Classify_HWW( TString myMethodList
401        ch -> Add( Form("%s/%s_PU_testFinal_baby.root",babyPath,samples.at(i)) );
402      }
403  
397
398
404      // --- Event loop
405  
406      // Prepare the event tree
# Line 418 | Line 423 | void Classify_HWW( TString myMethodList
423  
424      Float_t lephard_pt_;
425      Float_t lepsoft_pt_;
426 +    Float_t lepsoft_fr_;
427      Float_t dil_dphi_;
428      Float_t dil_mass_;
429      Float_t event_type_;
# Line 433 | Line 439 | void Classify_HWW( TString myMethodList
439      Float_t mt_lepsoftmet_;
440      Float_t dphi_lephardmet_;
441      Float_t dphi_lepsoftmet_;
442 +    Float_t lepsoft_fbrem_;
443 +    Float_t lepsoft_eOverPIn_;
444 +    Float_t lepsoft_q_;
445 +    Float_t lepsoft_dPhiIn_;
446  
447      theTree->SetBranchAddress( "lephard_pt_"             ,   &lephard_pt_              );
448      theTree->SetBranchAddress( "lepsoft_pt_"             ,   &lepsoft_pt_              );
449 +    theTree->SetBranchAddress( "lepsoft_fr_"             ,   &lepsoft_fr_              );
450      theTree->SetBranchAddress( "dil_dphi_"               ,   &dil_dphi_                );
451      theTree->SetBranchAddress( "dil_mass_"               ,   &dil_mass_                );
452      theTree->SetBranchAddress( "event_type_"             ,   &event_type_              );
# Line 446 | Line 457 | void Classify_HWW( TString myMethodList
457      theTree->SetBranchAddress( "softmu_num_"             ,   &softmu_num_              );
458      theTree->SetBranchAddress( "event_scale1fb_"         ,   &event_scale1fb_          );
459      theTree->SetBranchAddress( "lepsoft_passTighterId_"  ,   &lepsoft_passTighterId_   );
449    theTree->SetBranchAddress( "event_type_"             ,   &event_type_              );
460      theTree->SetBranchAddress( "met_pt_"                 ,   &met_pt_                  );
461      theTree->SetBranchAddress( "mt_lephardmet_"          ,   &mt_lephardmet_           );
462      theTree->SetBranchAddress( "mt_lepsoftmet_"          ,   &mt_lepsoftmet_           );
463      theTree->SetBranchAddress( "dphi_lephardmet_"        ,   &dphi_lephardmet_         );
464      theTree->SetBranchAddress( "dphi_lepsoftmet_"        ,   &dphi_lepsoftmet_         );
465 +    theTree->SetBranchAddress( "lepsoft_fbrem_"          ,   &lepsoft_fbrem_           );
466 +    theTree->SetBranchAddress( "lepsoft_eOverPIn_"       ,   &lepsoft_eOverPIn_        );
467 +    theTree->SetBranchAddress( "lepsoft_q_"              ,   &lepsoft_q_               );
468 +    theTree->SetBranchAddress( "lepsoft_dPhiIn_"         ,   &lepsoft_dPhiIn_          );
469  
470      // Efficiency calculator for cut method
471      Int_t    nSelCutsGA = 0;
# Line 463 | Line 477 | void Classify_HWW( TString myMethodList
477      TStopwatch sw;
478      sw.Start();
479  
480 <    int npass = 0;
481 <
480 >    int npass   = 0;
481 >    float yield = 0.;
482 >    
483      for (Long64_t ievt=0; ievt<theTree->GetEntries();ievt++) {
484  
485        if (ievt%1000 == 0) std::cout << "--- ... Processing event: " << ievt << std::endl;
# Line 484 | Line 499 | void Classify_HWW( TString myMethodList
499          if( met_projpt_ < 35. )   continue;
500        }
501  
502 <      if( lephard_pt_ < 20.    )                    continue;
503 <      if( lepsoft_pt_ < 10.    )                    continue;
504 <      //if( lepsoft_pt_ < 20.    )                    continue;
505 <      if( jets_num_ > 0        )                    continue;
506 <      if( extralep_num_ > 0    )                    continue;
507 <      if( lowptbtags_num_ > 0  )                    continue;
508 <      if( softmu_num_ > 0      )                    continue;
509 <      if( dil_mass_ < 12.      )                    continue;
510 <      if( lepsoft_passTighterId_ == 0 )             continue;
511 <      if( dil_mass_ > 90. )                         continue;
502 >       if( lephard_pt_ < 20.    )                    continue;
503 >       if( lepsoft_pt_ < 10.    )                    continue;
504 >       //if( lepsoft_pt_ < 20.    )                    continue;
505 >       if( jets_num_ > 0        )                    continue;
506 >       if( extralep_num_ > 0    )                    continue;
507 >       if( lowptbtags_num_ > 0  )                    continue;
508 >       if( softmu_num_ > 0      )                    continue;
509 >       if( dil_mass_ < 12.      )                    continue;
510 >       if( lepsoft_passTighterId_ == 0 )             continue;
511 >       if( event_type_ < 1.5    )                    continue;
512 >       if( dil_mass_ > 90. )                         continue;
513  
514 <      float weight = event_scale1fb_ * 0.0355;
514 >      float weight = event_scale1fb_ * lepsoft_fr_ * 0.5;
515  
516        //--------------------------------------------------------
517        // important: here we associate branches to MVA variables
518        //--------------------------------------------------------
519  
520 <      lephard_pt      = lephard_pt_;
521 <      lepsoft_pt      = lepsoft_pt_;
522 <      dil_mass        = dil_mass_;
523 <      dil_dphi        = dil_dphi_;
524 <      event_type      = event_type_;
525 <      met_pt          = met_pt_;
526 <      met_projpt      = met_projpt_;
527 <      mt_lephardmet   = mt_lephardmet_;
528 <      mt_lepsoftmet   = mt_lepsoftmet_;
529 <      dphi_lephardmet = dphi_lephardmet_;
530 <      dphi_lepsoftmet = dphi_lepsoftmet_;
520 >      lephard_pt        = lephard_pt_;
521 >      lepsoft_pt        = lepsoft_pt_;
522 >      dil_mass          = dil_mass_;
523 >      dil_dphi          = dil_dphi_;
524 >      event_type        = event_type_;
525 >      met_pt            = met_pt_;
526 >      met_projpt        = met_projpt_;
527 >      mt_lephardmet     = mt_lephardmet_;
528 >      mt_lepsoftmet     = mt_lepsoftmet_;
529 >      dphi_lephardmet   = dphi_lephardmet_;
530 >      dphi_lepsoftmet   = dphi_lepsoftmet_;
531 >      lepsoft_fbrem     = lepsoft_fbrem_;
532 >      lepsoft_eOverPIn  = lepsoft_eOverPIn_;
533 >      lepsoft_qdphi     = lepsoft_q_ * lepsoft_dPhiIn_;
534  
535        npass++;
536 +      yield+=weight;
537 +
538        //       var1 = userVar1 + userVar2;
539        //       var2 = userVar1 - userVar2;
540  
# Line 556 | Line 577 | void Classify_HWW( TString myMethodList
577        if (Use["Category"     ])   histCat    ->Fill( reader->EvaluateMVA( "Category method"      ) , weight);
578        if (Use["Plugin"       ])   histPBdt   ->Fill( reader->EvaluateMVA( "P_BDT method"         ) , weight);
579  
559      if( reader->EvaluateMVA( "BDT method" ) < -0.8 ){
560        fillUnderOverFlow( hdilmass_BDT , dil_mass_ , weight );
561      }
562      if( reader->EvaluateMVA( "MLPBNN method" ) < 0.1 ){
563        fillUnderOverFlow( hdilmass_MLPBNN , dil_mass_ , weight );
564      }
565
580        // Retrieve also per-event error
581        if (Use["PDEFoam"]) {
582          Double_t val = reader->EvaluateMVA( "PDEFoam method" );
# Line 579 | Line 593 | void Classify_HWW( TString myMethodList
593        }
594      }
595  
596 <    std::cout << npass << " events passing selection" << std::endl;
596 >    std::cout << npass << " events passing selection, yield " << yield << std::endl;
597  
598      // Get elapsed time
599      sw.Stop();
# Line 649 | Line 663 | void Classify_HWW( TString myMethodList
663      if (Use["FDA_GA"       ])   histFDAGA  ->Write();
664      if (Use["Category"     ])   histCat    ->Write();
665      if (Use["Plugin"       ])   histPBdt   ->Write();
652    hdilmass_BDT->Write();
653    hdilmass_MLPBNN->Write();
666  
667      // Write also error and significance histos
668      if (Use["PDEFoam"]) { histPDEFoam->Write(); histPDEFoamErr->Write(); histPDEFoamSig->Write(); }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines