MyAnalysisExample/src/MyAnalysisExample.cxx

00001 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00002 // 09.11.2006, AUTHOR: OLIVER KORTNER
00003 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00004 
00005 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
00006 //:: IMPLEMENTATION OF METHODS DEFINED IN THE CLASS MyAnalysisExample ::
00007 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
00008 
00009 //::::::::::::::::::
00010 //:: HEADER FILES ::
00011 //::::::::::::::::::
00012 
00013 #include "MyAnalysisExample/MyAnalysisExample.h"
00014 
00015 //:::::::::::::::::::::::::
00016 //:: NAME SPACE SETTINGS ::
00017 //:::::::::::::::::::::::::
00018 
00019 using namespace std;
00020 
00021 //*****************************************************************************
00022 
00023 //:::::::::::::::::
00024 //:: METHOD init ::
00025 //:::::::::::::::::
00026 
00027 void MyAnalysisExample::init(void) {
00028    
00029    filename = "testfile";
00030    return;
00031 
00032 }
00033 
00034 //*****************************************************************************
00035 
00036 //:::::::::::::::::::::
00037 //:: METHOD destruct ::
00038 //:::::::::::::::::::::
00039 
00040 void MyAnalysisExample::destruct(void) {
00041 
00042         return;
00043 
00044 }
00045 
00046 //*****************************************************************************
00047 
00048 //:::::::::::::::::::::::
00049 //:: METHOD initialize ::
00050 //:::::::::::::::::::::::
00051 
00052 void MyAnalysisExample::initialize(void) {
00053 
00055 // CREATE THE ROOT FILE //
00057 
00058    //m_tfile = new TFile("tmp.root", "RECREATE");
00059    m_tfile = new TFile( filename.ReplaceAll(".aan",".selection") , "RECREATE");
00060 
00061 
00063 // BOOK THE HISTOGRAM //
00065 
00066         m_nb_electrons = new TH1F("nb_electrons",
00067                                 "NUMBER OF RECONSTRUCTED ELECTRONS / EVENT",
00068                                 11, -0.5, 10.5);
00069         m_e_energy = new TH1F("e_energy", "ELECTRON ENERGY (GeV)", 
00070                                 201, -0.5, 200.5);
00071         m_e_pt = new TH1F("e_pt", "ELECTRON PT (GeV)", 
00072                                 201, -0.5, 200.5);
00073         m_nb_muons = new TH1F("nb_muons",
00074                                 "NUMBER OF RECONSTRUCTED MUONS / EVENT",
00075                                 11, -0.5, 10.5);
00076         m_nb_jets = new TH1F("nb_jets",
00077                                 "NUMBER OF RECONSTRUCTED JETS / EVENT",
00078                                 11, -0.5, 10.5);
00079         
00080         m_missinget_x = new TH1F("missinget_x",
00081                                 "MISSING ET IN X DIRECTION",
00082                                 1001, -500.5, 500.5);
00083 
00084         h_nb_matchedjets = new TH1F("nb_matchedjets",
00085                                   "NUMBER OF MATCHED JETS / EVENT",
00086                                   11, -0.5, 10.5);
00087 
00088         h_nb_fakedjets = new TH1F("nb_fakedjets",
00089                                   "NUMBER OF FAKED JETS / EVENT",
00090                                   11, -0.5, 10.5);
00091 
00092 
00093 
00094         return;
00095 
00096 }
00097 
00098 //*****************************************************************************
00099 
00100 //::::::::::::::::::::::::::
00101 //:: METHOD analyse_event ::
00102 //::::::::::::::::::::::::::
00103 
00104 void MyAnalysisExample::analyse_event(const MyEvent & event) {
00105 
00107 // FILL HISTOGRAMS //
00109 
00110     // number of reconstructed electrons, muons, and jets //
00111     m_nb_electrons->Fill(event.reco_electrons().size(), 1.0);
00112     m_nb_muons->Fill(event.reco_muons().size(), 1.0);
00113     m_nb_jets->Fill(event.reco_jets().size(), 1.0);
00114     
00115     // electron energy distribution //
00116         //for (unsigned int k=0; k<event.reco_electrons().size(); k++) {
00117         //m_e_energy->Fill(0.001*
00118         //              event.reco_electrons()[k]->tlv()[3],
00119     //                                                  1.0);
00120                 // get index in original vector of electrons
00121                 //cout<<"elctron index: "
00122                 //  <<event.reco_electrons()[k]->index()<<endl;
00123                 // get type
00124                 //cout<<"elctron type: "
00125                 //  <<event.reco_electrons()[k]->type()<<endl;
00126                 // get charge
00127                 //cout<<"elctron charge: "
00128                 //  <<event.reco_electrons()[k]->charge()<<endl;
00129 //}
00130         
00131 // electron pt distribution //
00132     for (unsigned int k=0; k<event.reco_electrons().size(); k++) {
00133         m_e_pt->Fill(event.reco_electrons()[k]->tlv().Pt(),1.0);
00134     }
00135     
00136 // missing et in x direction
00137     //cout <<"missinget_x: "<< event.missinget().missinget_x() << endl; 
00138     
00139     m_missinget_x->Fill(event.met_manager().get_missinget("MET_RefFinal").met_x(),1.0);
00140     
00141 // matching between reco and truth jets //
00142 
00143     int nb_matchedjets = 0;
00144     int nb_fakedjets = 0;
00145 
00146     std::vector<MyParticle*> 
00147         selected_truthjets = select_jets( event.truth_jets() );
00148 
00149     for (unsigned int k=0; k<event.reco_jets().size(); k++) {
00150         
00151         MyParticle* tmp_jet = NULL;
00152          
00153         tmp_jet = 
00154             (MyParticle*)m_tools.find_matching_particle( event.reco_jets()[k], 
00155                                                          selected_truthjets
00156                                                          );
00157         
00158         if(tmp_jet!=NULL) nb_matchedjets++;
00159         else              nb_fakedjets++;
00160         
00161     }
00162 
00163     h_nb_matchedjets->Fill(nb_matchedjets);
00164     h_nb_fakedjets->Fill(nb_fakedjets);
00165 
00166     
00167     //for (unsigned int k=0; k<selected_truthjets.size(); k++){
00168     //cout << "matchingflag: " << selected_truthjets[k]->matchingflag() << endl;
00169     //}
00170 
00171    
00172     //m_tools.test();
00173     
00174    return;
00175 
00176 }
00177 
00178 //*****************************************************************************
00179 
00180 //::::::::::::::::::::::::
00181 //:: METHOD select_jets ::
00182 //::::::::::::::::::::::::
00183 
00184 std::vector<MyParticle*>
00185 MyAnalysisExample::select_jets( std::vector<MyParticle*> jet_vector){
00186 
00187   std::vector<MyParticle*> selected_jets(0);
00188   
00189   for (unsigned int k=0; k<jet_vector.size(); k++) {
00190   
00191       //if( !(jet_vector[k]->tlv().Pt() > cutvalue_jet_pt_min) )      continue;
00192 
00193       selected_jets.push_back( jet_vector[k] );
00194       
00195       
00196   }
00197   
00198   return selected_jets;
00199   
00200 }
00201 
00202 
00203 
00204 //*****************************************************************************
00205 
00206 //::::::::::::::::::::::::::::
00207 //:: METHOD end_of_analysis ::
00208 //::::::::::::::::::::::::::::
00209 
00210 void MyAnalysisExample::end_of_analysis(void) {
00211 
00212     //----------------------
00213     //-- MULTIPLE MATCHES --
00214     //----------------------
00215     
00216     Int_t multiplematches1 = m_tools.nb_multiple_matches();
00217     m_tools.clear_nb_multiple_matches();
00218     Int_t multiplematches2 = m_tools.nb_multiple_matches();
00219     
00220     cout << "multiplematches1: " <<  multiplematches1 << endl;
00221     cout << "multiplematches2: " <<  multiplematches2 << endl;
00222 
00223         
00224     //------------------------
00225     //-- SAVE THE ROOT FILE --
00226     //------------------------
00227     
00228     m_tfile->Write();
00229     
00230     return;
00231     
00232 }

Generated on Tue Oct 21 11:50:43 2008 for NtupleAnalysis by  doxygen 1.5.1