00001 #ifndef maduseranalysis_cxx
00002 #define maduseranalysis_cxx
00003 #include <iostream>
00004 #include "Mad/MadUserAnalysis.h"
00005
00006 using namespace std;
00007
00008
00009 MadUserAnalysis::MadUserAnalysis(TChain *chainSR,TChain *chainMC,
00010 TChain *chainTH,TChain *chainEM)
00011 {
00012
00013 if(!chainSR) {
00014 record = 0;
00015 strecord = 0;
00016 emrecord = 0;
00017 mcrecord = 0;
00018 threcord = 0;
00019 Clear();
00020 whichSource = -1;
00021 isMC = true;
00022 isTH = true;
00023 isEM = true;
00024 Nentries = -1;
00025 return;
00026 }
00027
00028 InitChain(chainSR,chainMC,chainTH,chainEM);
00029 whichSource = 0;
00030
00031 user_variable = 0;
00032
00033 }
00034
00035
00036 MadUserAnalysis::MadUserAnalysis(JobC *j,string path,int entries)
00037 {
00038 record = 0;
00039 strecord = 0;
00040 emrecord = 0;
00041 mcrecord = 0;
00042 threcord = 0;
00043 Clear();
00044 isMC = true;
00045 isTH = true;
00046 isEM = true;
00047 Nentries = entries;
00048 whichSource = 1;
00049 jcPath = path;
00050 fJC = j;
00051
00052 user_variable = 0;
00053
00054 }
00055
00056
00057 MadUserAnalysis::~MadUserAnalysis()
00058 {
00059
00060 }
00061
00062
00063 Bool_t MadUserAnalysis::PassTruthSignal(Int_t mcevent)
00064 {
00065 if(!LoadTruth(mcevent)) return false;
00066 if(abs(ntpTruth->inu)==14&&ntpTruth->iaction==1) return true;
00067 return false;
00068 }
00069
00070
00071 Bool_t MadUserAnalysis::PassAnalysisCuts(Int_t event)
00072 {
00073 if(!LoadEvent(event)) return false;
00074 if(PassBasicCuts(event)) {
00075 if(PID(event,0)>=1.) return true;
00076 }
00077 return false;
00078 }
00079
00080
00081 Bool_t MadUserAnalysis::PassBasicCuts(Int_t event)
00082 {
00083
00084 if(!LoadEvent(event)) return false;
00085 Int_t track = -1;
00086 if(!LoadLargestTrackFromEvent(event,track)) return false;
00087 if(RecoMuEnergy(track)<100.) return true;
00088 return false;
00089 }
00090
00091
00092 Float_t MadUserAnalysis::PID(Int_t event,Int_t method){
00093 if(!LoadEvent(event)) return 0;
00094 if(method==0) return 1.0;
00095 return 0;
00096 }
00097
00098
00099 Float_t MadUserAnalysis::RecoAnalysisEnergy(Int_t event){
00100
00101 if(!LoadEvent(event)) return 0;
00102 int largestTrack = -1;
00103 LoadLargestTrackFromEvent(event,largestTrack);
00104 float emu = RecoMuEnergy(0,largestTrack);
00105 float ehad = RecoShwEnergy(event);
00106 float ereco = emu + ehad;
00107 return ereco;
00108
00109 }
00110
00111
00112 Float_t MadUserAnalysis::GetWeight(Int_t event)
00113 {
00114 if(event>=0) return 1.0;
00115 return 0;
00116 }
00117
00118
00119 Bool_t MadUserAnalysis::AddUserBranches(TTree *tree)
00120 {
00121 if(!tree) return false;
00122 tree->Branch("user_variable",&user_variable,"user_variable/D",32000);
00123 return true;
00124 }
00125
00126
00127 void MadUserAnalysis::CallUserFunctions(Int_t event)
00128 {
00129 user_variable = 0;
00130
00131 if(!LoadEvent(event)) return;
00132 user_variable = 0.5;
00133
00134 }
00135
00136
00137 void MadUserAnalysis::MakeMyFile(std::string tag){
00138
00139 std::string savename = "QEHistos_" + tag + ".root";
00140 TFile save(savename.c_str(),"RECREATE");
00141 save.cd();
00142
00143
00144 TH1F *NEvent_NC = new TH1F("NEvent_NC",
00145 "Number of Reco'd Events - NC",
00146 20,0,20);
00147 NEvent_NC->SetXTitle("Number of Events");
00148 TH1F *NEvent_CC = new TH1F("NEvent_CC",
00149 "Number of Reco'd Events - CC",
00150 20,0,20);
00151 NEvent_CC->SetXTitle("Number of Events");
00152
00153 for(int i=0;i<Nentries;i++){
00154
00155 if(i%1000==0) std::cout << float(i)*100./float(Nentries)
00156 << "% done" << std::endl;
00157
00158 if(!this->GetEntry(i)) continue;
00159
00160
00161
00162
00163 for(int j=0;j<eventSummary->nevent;j++){
00164
00165 if(!LoadEvent(j)) continue;
00166
00167
00168 int mcevent = -1;
00169 if(LoadTruthForRecoTH(j,mcevent)){
00170
00171 if(PassTruthSignal()) {
00172 NEvent_CC->Fill(eventSummary->nevent);
00173 }
00174 else {
00175 NEvent_NC->Fill(eventSummary->nevent);
00176 }
00177 }
00178 }
00179 }
00180
00181 save.Write();
00182 save.Close();
00183 }
00184
00185 #endif // #ifdef maduseranalysis_cxx