00001 #include <iostream> 00002 #include "TChain.h" 00003 #include "TFile.h" 00004 #include "TClonesArray.h" 00005 #include "TMath.h" 00006 #include "NueAnaReader.h" 00007 #include "NueAna/NuePOT.h" 00008 #include "NueAna/MCNNBestMatch.h" 00009 #include <fstream> 00010 00011 using std::cout; 00012 using std::endl; 00013 00014 const Float_t NueAnaReader::POT_file_carrot_FD=2.91*1e20; 00015 const Float_t NueAnaReader::POT_file_daikon_FD=6.5*1e20; 00016 const Float_t NueAnaReader::POT_file_carrot_ND=1.0024*1e16; 00017 const Float_t NueAnaReader::POT_file_daikon_ND=1.936*1e16; 00018 00019 // ****************** CONSTRUCTOR & DESTRUCTOR **************** 00020 00021 NueAnaReader::NueAnaReader(){ 00022 00023 //Make chains 00024 chain = new TChain("ana_nue"); 00025 chain_pot = new TChain("pottree"); 00026 00027 nuerecord = new NueRecord(); 00028 nuepot = new NuePOT(); 00029 00030 //defaults 00031 num_best_matches=50; 00032 h_weight=new TH1F(); 00033 //weightfile = new TFile("./files/MakeHistosForSpectralReweighting.root","READ"); 00034 00035 } 00036 00037 NueAnaReader::NueAnaReader(const char* name){ 00038 00039 //Make chains 00040 chain = new TChain("ana_nue"); 00041 chain_pot = new TChain("pottree"); 00042 00043 filenum=chain->Add(name); 00044 chain_pot->Add(name); 00045 00046 cout << "Added " << filenum << " to NueAnaReader" << endl; 00047 00048 nuerecord = new NueRecord(); 00049 nuepot = new NuePOT(); 00050 00051 Setup(); 00052 00053 //defaults 00054 num_best_matches=50; 00055 h_weight=new TH1F(); 00056 00057 } 00058 00059 NueAnaReader::~NueAnaReader(){ 00060 00061 delete chain; 00062 delete chain_pot; 00063 delete nuerecord; 00064 delete nuepot; 00065 00066 } 00067 00068 // ******** SETUP (PRIVATE METHOD) 00069 void NueAnaReader::Setup(){ 00070 00071 //Branches 00072 //-------- 00073 if(chain->GetBranchStatus("NueRecord")){ 00074 chain->SetBranchAddress("NueRecord",&nuerecord); 00075 } 00076 if(chain_pot->GetBranchStatus("NuePOT")){ 00077 chain_pot->SetBranchAddress("NuePOT",&nuepot); 00078 chain_pot->GetEntry(0); 00079 } 00080 00081 } 00082 00083 // ****** Public Methods ************* 00084 Int_t NueAnaReader::Add(const char* name){ 00085 00086 Int_t filenum = chain->Add(name); 00087 cout << "Added " << chain_pot->Add(name) << " to the pottree chain" << endl; 00088 Setup(); 00089 return filenum; 00090 00091 } 00092 00093 //---------------------------------------- 00094 Int_t NueAnaReader::GetEntry(Int_t srCtr_in){ 00095 00096 return chain->GetEntry(srCtr_in); 00097 00098 } 00099 00100 //---------------------------------------- 00101 Int_t NueAnaReader::GetEntries(){ 00102 00103 return chain->GetEntries(); 00104 00105 } 00106 //---------------------------------------- 00107 Bool_t NueAnaReader::NuePresel(){ 00108 00109 Bool_t passpresel=false; 00110 if(nuerecord!=NULL){ 00111 if(nuerecord->anainfo.inFiducialVolume == 1){// && nuerecord->srevent.vtxZ<29){ 00112 if(nuerecord->srevent.phNueGeV > 1 && nuerecord->srevent.phNueGeV < 8){ 00113 if(nuerecord->srtrack.planes < 25){ 00114 if(nuerecord->srtrack.trklikePlanes < 16){ 00115 passpresel=true; 00116 } 00117 } 00118 } 00119 } 00120 } else { 00121 cout << "Warning ! Emtpy NueRecord in NuePresel" << endl; 00122 } 00123 00124 return passpresel; 00125 00126 } 00127 00128 //-------------------------------------- 00129 Float_t NueAnaReader::CalculatePOT(){ 00130 00131 Int_t srCtr_pot=0; 00132 Float_t pot_out=0; 00133 NuePOT *nuepot = new NuePOT(); 00134 chain_pot->SetBranchAddress("NuePOT",&nuepot); 00135 00136 while(chain_pot->GetEntry(srCtr_pot)){ 00137 ++srCtr_pot; 00138 pot_out += nuepot->pot; 00139 } 00140 00141 delete nuepot; 00142 00143 return pot_out; 00144 00145 } 00146 00147 //-------------------------------------- 00148 Float_t NueAnaReader::CalculatePOT(Int_t filenum, Int_t filetype){ 00149 00150 Float_t pot_out=0; 00151 00152 if(filetype==0){//<--carrot FD 00153 pot_out=filenum*POT_file_carrot_FD*1e-12; 00154 cout << "Using carrot FD POT" << endl; 00155 } 00156 if(filetype==1){//<--daikon FD 00157 pot_out=filenum*POT_file_daikon_FD*1e-12; 00158 cout << "Using daikon FD POT " << endl; 00159 } 00160 if(filetype==2){//<--carrot ND 00161 pot_out=filenum*POT_file_carrot_ND*1e-12; 00162 cout << "Using carrot ND POT" << endl; 00163 } 00164 if(filetype==3){//<--daikon ND 00165 pot_out=filenum*POT_file_daikon_ND*1e-12; 00166 cout << "Using daikon ND POT " << endl; 00167 } 00168 00169 return pot_out; 00170 00171 } 00172 00173 //-------------------------------------------- 00174 MCNNBestMatch* NueAnaReader::GetBestMatch(Int_t ii){ 00175 00176 MCNNBestMatch *castedbmatch = 0; 00177 TClonesArray& bmatcharray = *(nuerecord->mcnnv.bmatch); 00178 castedbmatch = dynamic_cast<MCNNBestMatch *>(bmatcharray[ii]); 00179 return castedbmatch; 00180 00181 00182 } 00183 00184 //--------------------------------------------- 00185 void NueAnaReader::SetMaxNumBestMatches(Int_t nbm_in){ 00186 00187 num_best_matches=nbm_in; 00188 00189 } 00190 00191 //---------------------------------------------- 00192 Float_t NueAnaReader::GetfracCC(){ 00193 00194 Int_t nresults=nuerecord->mcnnv.bestmatches; 00195 Int_t match_nue=0; 00196 Int_t matches=0; 00197 Int_t bm=0; 00198 00199 while(bm<num_best_matches && bm<nresults){ 00200 00201 MCNNBestMatch *mcnnbm = GetBestMatch(bm); 00202 00203 if(TMath::Abs(mcnnbm->nuFlavor)==12 && mcnnbm->interactionType==1){ 00204 ++match_nue; 00205 } 00206 ++matches; 00207 ++bm; 00208 } 00209 00210 Float_t fracCC=-1; 00211 00212 if(matches>0){ 00213 fracCC=match_nue*1./matches; 00214 } 00215 00216 return fracCC; 00217 00218 } 00219 00220 00221 //---------------------------------------------- 00222 Float_t NueAnaReader::GetfracCCy(Float_t y_cut){ 00223 00224 Int_t nresults=nuerecord->mcnnv.bestmatches; 00225 Int_t match_nue=0; 00226 Int_t matches=0; 00227 Int_t bm=0; 00228 00229 while(matches<num_best_matches && bm<nresults){ 00230 00231 MCNNBestMatch *mcnnbm = GetBestMatch(bm); 00232 00233 //Int_t filetype=mcnnbm->run/100000; 00234 //Int_t max_run=0; 00235 //if(filetype==210){ 00236 // max_run=21011200; 00237 // } else { 00238 // max_run=21111100; 00239 // } 00240 00241 //if(mcnnbm->run <= max_run){ 00242 00243 if(TMath::Abs(mcnnbm->nuFlavor)==12 && mcnnbm->interactionType==1 && mcnnbm->true_y<y_cut){ 00244 ++match_nue; 00245 } 00246 ++matches; 00247 //} 00248 00249 ++bm; 00250 } 00251 00252 Float_t fracCCy=-1; 00253 00254 if(matches>0){ 00255 fracCCy=match_nue*1./matches; 00256 } 00257 00258 return fracCCy; 00259 00260 } 00261 00262 00263 //--------------------------------------------------- 00264 Float_t NueAnaReader::Getymean(Float_t y_cut){ 00265 00266 Int_t nresults=nuerecord->mcnnv.bestmatches; 00267 Float_t ely=0; 00268 Int_t matches=0; 00269 Int_t bm=0; 00270 00271 while(bm<num_best_matches && bm<nresults){ 00272 00273 MCNNBestMatch *mcnnbm = GetBestMatch(bm); 00274 if(TMath::Abs(mcnnbm->nuFlavor)==12 && mcnnbm->interactionType==1 && mcnnbm->true_y < y_cut){ 00275 ely += mcnnbm->true_y; 00276 ++matches; 00277 } 00278 ++bm; 00279 } 00280 00281 Float_t result=-1; 00282 00283 if(matches>0){ 00284 result=ely*1./matches; 00285 } 00286 00287 return result; 00288 00289 } 00290 00291 //------------------------------------------------------ 00292 Float_t NueAnaReader::GetMeanFracQMatched(Float_t y_cut){ 00293 00294 Int_t nresults=nuerecord->mcnnv.bestmatches; 00295 Float_t mfqm=0; 00296 Int_t matches=0; 00297 Int_t bm=0; 00298 00299 while(bm<num_best_matches && bm<nresults){ 00300 00301 MCNNBestMatch *mcnnbm = GetBestMatch(bm); 00302 00303 if(TMath::Abs(mcnnbm->nuFlavor)==12 && mcnnbm->interactionType==1 && mcnnbm->true_y < y_cut){ 00304 mfqm += mcnnbm->fracQmatched; 00305 ++matches; 00306 } 00307 ++bm; 00308 } 00309 00310 Float_t result=-1; 00311 00312 if(matches>0){ 00313 result=mfqm*1./matches; 00314 } 00315 00316 return result; 00317 00318 } 00319 00320 //------------------------------------------------------ 00321 Float_t NueAnaReader::GetdlnLmean(){ 00322 00323 Int_t nresults=nuerecord->mcnnv.bestmatches; 00324 Float_t mfqm=0; 00325 Int_t matches=0; 00326 Int_t bm=0; 00327 00328 while(bm<num_best_matches && bm<nresults){ 00329 00330 MCNNBestMatch *mcnnbm = GetBestMatch(bm); 00331 00332 if(TMath::Abs(mcnnbm->nuFlavor)==12 && mcnnbm->interactionType==1){ 00333 mfqm += mcnnbm->dlnL; 00334 ++matches; 00335 } 00336 ++bm; 00337 } 00338 00339 Float_t result=-1; 00340 00341 if(matches>0){ 00342 result=mfqm*1./matches; 00343 } 00344 00345 return result; 00346 00347 } 00348 00349 //---------------------------------------------- 00350 void NueAnaReader::SetLibraryWeightingFile(char* weightfile_in, char* histname_in){ 00351 00352 TFile *weightfile = new TFile(weightfile_in,"READ"); 00353 h_weight = (TH1F*)weightfile->Get(histname_in); 00354 00355 } 00356 00357 //---------------------------------------------- 00358 Float_t NueAnaReader::GetWeightedfracCC(){ 00359 00360 Int_t nresults=nuerecord->mcnnv.bestmatches; 00361 Float_t match_nue=0; 00362 Float_t matches=0; 00363 Int_t bm=0; 00364 00365 while(bm<num_best_matches && bm<nresults){ 00366 00367 MCNNBestMatch *mcnnbm = GetBestMatch(bm); 00368 00369 Float_t weight=1.0; 00370 if(TMath::Abs(mcnnbm->nuFlavor)==12 && mcnnbm->interactionType==1) weight=h_weight->GetBinContent(h_weight->FindBin(mcnnbm->true_enu)); 00371 00372 if(TMath::Abs(mcnnbm->nuFlavor)==12 && mcnnbm->interactionType==1){ 00373 match_nue+=weight;; 00374 } 00375 matches+=weight; 00376 ++bm; 00377 } 00378 00379 Float_t fracCC=-1; 00380 00381 if(matches>0){ 00382 fracCC=match_nue*1./matches; 00383 } 00384 00385 return fracCC; 00386 00387 } 00388 00389 //---------------------------------------------- 00390 Float_t NueAnaReader::GetWeightedfracCCy(Float_t y_cut){ 00391 00392 Int_t nresults=nuerecord->mcnnv.bestmatches; 00393 Float_t match_nue=0; 00394 Float_t matches=0; 00395 Int_t bm=0; 00396 00397 while(matches<num_best_matches && bm<nresults){ 00398 00399 MCNNBestMatch *mcnnbm = GetBestMatch(bm); 00400 00401 //Int_t filetype=mcnnbm->run/100000; 00402 //Int_t max_run=0; 00403 //if(filetype==210){ 00404 // max_run=21011200; 00405 // } else { 00406 // max_run=21111100; 00407 // } 00408 00409 //if(mcnnbm->run <= max_run){ 00410 00411 //Setting a non-1 weight for nueCC best matches 00412 Float_t weight=1.0; 00413 if(TMath::Abs(mcnnbm->nuFlavor)==12 && mcnnbm->interactionType==1) weight=h_weight->GetBinContent(h_weight->FindBin(mcnnbm->true_enu)); 00414 00415 if(TMath::Abs(mcnnbm->nuFlavor)==12 && mcnnbm->interactionType==1 && mcnnbm->true_y<y_cut){ 00416 match_nue+=weight; 00417 } 00418 matches+=weight; 00419 00420 00421 //} 00422 00423 ++bm; 00424 } 00425 00426 Float_t fracCCy=-1; 00427 00428 if(matches>0){ 00429 fracCCy=match_nue*1./matches; 00430 } 00431 00432 return fracCCy; 00433 00434 } 00435 00436 //------------------------------------------------------ 00437 Float_t NueAnaReader::GetWeightedMeanFracQMatched(Float_t y_cut){ 00438 00439 Int_t nresults=nuerecord->mcnnv.bestmatches; 00440 Float_t mfqm=0; 00441 Float_t matches=0; 00442 Int_t bm=0; 00443 00444 while(bm<num_best_matches && bm<nresults){ 00445 00446 MCNNBestMatch *mcnnbm = GetBestMatch(bm); 00447 00448 Float_t weight=1.0; 00449 if(TMath::Abs(mcnnbm->nuFlavor)==12 && mcnnbm->interactionType==1) weight=h_weight->GetBinContent(h_weight->FindBin(mcnnbm->true_enu)); 00450 00451 if(TMath::Abs(mcnnbm->nuFlavor)==12 && mcnnbm->interactionType==1 && mcnnbm->true_y < y_cut){ 00452 mfqm += mcnnbm->fracQmatched*weight; 00453 matches+=weight; 00454 } 00455 ++bm; 00456 } 00457 00458 Float_t result=-1; 00459 00460 if(matches>0){ 00461 result=mfqm*1./matches; 00462 } 00463 00464 return result; 00465 00466 } 00467 00468 //--------------------------------------------------- 00469 Float_t NueAnaReader::GetWeightedymean(Float_t y_cut){ 00470 00471 Int_t nresults=nuerecord->mcnnv.bestmatches; 00472 Float_t ely=0; 00473 Float_t matches=0; 00474 Int_t bm=0; 00475 00476 while(bm<num_best_matches && bm<nresults){ 00477 00478 MCNNBestMatch *mcnnbm = GetBestMatch(bm); 00479 00480 Float_t weight=1.0; 00481 if(TMath::Abs(mcnnbm->nuFlavor)==12 && mcnnbm->interactionType==1) weight=h_weight->GetBinContent(h_weight->FindBin(mcnnbm->true_enu)); 00482 00483 if(TMath::Abs(mcnnbm->nuFlavor)==12 && mcnnbm->interactionType==1 && mcnnbm->true_y < y_cut){ 00484 ely += mcnnbm->true_y*weight; 00485 matches+=weight; 00486 } 00487 ++bm; 00488 } 00489 00490 Float_t result=-1; 00491 00492 if(matches>0){ 00493 result=ely*1./matches; 00494 } 00495 00496 return result; 00497 00498 }
1.3.9.1