Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

NuDSTAna.cxx

Go to the documentation of this file.
00001 
00002 
00003 // Coded by Jeff Hartnell Jul/2007 onwards
00004 //
00005 // Contact: j.j.hartnell@rl.ac.uk
00007 #include <cmath>
00008 #include <cstdlib>
00009 #include <memory>
00010 
00011 #include "TFile.h"
00012 #include "TROOT.h"
00013 #include "TObject.h"
00014 #include "TDirectory.h"
00015 #include "TH1D.h"
00016 #include "TH1F.h"
00017 #include "TH2D.h"
00018 #include "TProfile2D.h"
00019 #include "TMath.h"
00020 #include "TGraph.h"
00021 
00022 #include "MessageService/MsgFormat.h"
00023 #include "MessageService/MsgService.h"
00024 #include "Conventions/ReleaseType.h"
00025 
00026 #include "NtupleUtils/NuEvent.h"
00027 #include "NtupleUtils/NuFCEvent.h"
00028 #include "NtupleUtils/NuInputEvents.h"
00029 #include "NtupleUtils/NuLibrary.h"
00030 #include "NtupleUtils/NuSystematic.h"
00031 #include "NtupleUtils/NuXMLConfig.h"
00032 #include "NtupleUtils/NuCutImps.h"
00033 #include "NtupleUtils/NuCutter.h"
00034 
00035 #include "NuMuBar/NuTransition.h"
00036 #include "NuMuBar/NuConfig.h"
00037 #include "NuMuBar/NuDSTAna.h"
00038 #include "NuMuBar/NuOutputWriter.h"
00039 #include "NuMuBar/NuPlots.h"
00040 #include "NuMuBar/NuTime.h"
00041 #include "NuMuBar/NuPIDInterface.h"
00042 
00043 // Neugen Stuff
00044 #include "NeugenInterface/neugen_wrapper.h"
00045 #include "NeugenInterface/neugen_config.h"
00046 #include "NeugenInterface/interaction.h"
00047 #include "NeugenInterface/process.h"
00048 #include "NeugenInterface/kinematic_variable.h"
00049 #include "NeugenInterface/init_state.h"
00050 #include "NeugenInterface/final_state.h"
00051 #include "NeugenInterface/flavor.h"
00052 #include "TLorentzVector.h"
00053 
00054 using std::endl;
00055 using std::cout;
00056 using std::map;
00057 using std::vector;
00058 
00059 CVSID("$Id: NuDSTAna.cxx,v 1.156 2010/02/07 16:02:01 bckhouse Exp $");
00060 
00061 //......................................................................
00062 
00063 NuDSTAna::NuDSTAna()
00064 {
00065   MSG("NuDSTAna",Msg::kDebug)
00066     <<"Running NuDSTAna Constructor..."<<endl;
00067 
00068 
00069   MSG("NuDSTAna",Msg::kDebug)
00070     <<"Finished NuDSTAna Constructor"<<endl;
00071 }
00072 
00073 //......................................................................
00074 
00075 NuDSTAna::~NuDSTAna()
00076 {
00077   MSG("NuDSTAna",Msg::kDebug)
00078     <<"Running NuDSTAna Destructor..."<<endl;
00079 
00080 
00081   MSG("NuDSTAna",Msg::kDebug)
00082     <<"Finished NuDSTAna Destructor"<<endl;
00083 }
00084 
00085 //......................................................................
00086 
00087 void NuDSTAna::NMBAna()
00088 {
00089   //open the input file with the tree in it
00090   string inputFileName=this->GetInputFileName();
00091   NuInputEvents* fpInput=new NuInputEvents();
00092   NuInputEvents& input=*fpInput;
00093   input.InputFileName(inputFileName);
00094   input.InitialiseChains();
00095   input.InitialiseNuEventBranch();
00096   TDirectory* dirInput=input.OpenInputFile();
00097   Int_t firstRunNumber=input.GetFirstRunNumberNuEvent();
00098 
00099   //open the output file for histos etc
00100   string sFilePrefix="NMBSumAna";
00101   fOutFile=this->OpenFile(firstRunNumber,sFilePrefix.c_str());
00102   TDirectory* dirOutput=gDirectory;
00103   cout<<"After opening output file:"<<endl;
00104   dirOutput->Print();
00105 
00106   //copy across histos such hDetector, hSimFlag, and POT ones
00107   this->CopyAcrossHistos(dirInput,dirOutput);
00108 
00109   cout<<"Before creating histos output file:"<<endl;
00110   gDirectory->Print();
00111 
00112   static NuGeneral general;
00113   static NuPlots* plots;
00114   static NuCuts cuts;
00115 
00116   //version to do reco/cuts with
00117     NuCuts::NuAnaVersion_t overrideAnaVersion=NuCuts::kNMB0325Bravo;
00118 
00119   //draw detailed distance to edge plot
00120   //static NuReco reco;
00121   //reco.TestGetSmallestDeepDistToEdge();
00122 
00123   input.ResetNuEventLoopPositionToStart();
00124 
00125   for (Int_t i=0;i<input.GetEntriesNuEvent();++i) {
00126 
00127     this->PrintLoopProgress(i,input.GetEntriesNuEvent(),1);
00128 
00129     NuEvent& nu=const_cast<NuEvent&>(input.GetNextNuEvent(Msg::kDebug));
00130 
00131     //set the analysis version (could be kFullDST)
00132     nu.anaVersion=this->SanityCheckedAnaVersion
00133       (nu.anaVersion,overrideAnaVersion);
00134 
00135     //OVERRIDE
00136     nu.rw=nu.beamWeight*nu.detectorWeight*nu.generatorWeight;
00137     nu.trkEn=nu.trkEnRw;
00138     nu.shwEn=nu.shwEnRw;
00139     nu.energy=nu.energyRw;
00140 
00141     //const Float_t beamzerox=1.4885*(Munits::m);
00142     const Float_t beamzerox=1.4828*(Munits::m);//new for 2.5 analysis
00143     //const Float_t beamzerox=1.2*(Munits::m);
00144     //const Float_t beamzeroy=0.1397*(Munits::m);
00145     const Float_t beamzeroy=0.2384*(Munits::m);//new for 2.5 analysis
00146     //const Float_t beamzeroy=0.0*(Munits::m);
00147     const Float_t minZ=1.0*(Munits::m);
00148     const Float_t maxZ=4.0*(Munits::m);
00149     const Float_t maxR=0.5*(Munits::m);
00150     //additional cut on x position to remove coil hole
00151     //if (nu.xTrkVtx<0.7) continue;
00152 
00153     Bool_t passFid=cuts.IsInCylindricalVolume(nu.xTrkVtx,nu.yTrkVtx,
00154                                               nu.zTrkVtx,
00155                                               beamzerox,beamzeroy,
00156                                               minZ,maxZ,maxR);
00157 
00158     if (!passFid) continue;
00159     //if (nu.containmentFlagPitt>=3) continue;//got to downstream
00160     //if (nu.containmentFlagPitt<=2) continue;//only got to upstream
00161 
00162     //override the anaVersion
00163     //nu.anaVersion=NuCuts::kNMB0325Bravo;
00164 
00165     //check if the trk is in the fiducial volume
00166     if (!cuts.IsInFidVolTrk(nu)) continue;
00167 
00168     //require a good trk fit
00169     if (!cuts.IsGoodTrackFitPass(nu)) continue;
00170 
00171     //make the post-preselection plots
00172     this->MakePostPreSelectionPlots(plots,nu);
00173 
00174     //cut on the PID
00175     //if (!cuts.IsGoodDpID(nu)) {
00176     if (!cuts.IsGoodAbID(nu)) {
00177       plots->FillDPIdSigmaQPFailDpIDCutPlots(nu);
00178       continue;
00179     }
00180     plots->FillDPIdSigmaQPPassDpIDCutPlots(nu);
00181 
00182     plots->FillEnergyBinHistos(nu);//just PID cut
00183 
00184     //cut on the fractional track momentum and sign error
00185     if (!cuts.IsGoodSigmaQP_QP(nu)) {
00186       plots->FillDPIdSigmaQPFailSigQPCutPlots(nu);
00187       continue;
00188     }
00189     plots->FillDPIdSigmaQPPassSigQPCutPlots(nu);
00190 
00191     //cut on the chi2
00192     if (!cuts.IsGoodFitChi2PerNdof(nu)) continue;
00193 
00194     //was here
00195     //plots->FillEnergyBinHistos(nu);
00196 
00197     //cut on the track fit probability
00198     if (!cuts.IsGoodFitProb(nu)) {
00199       plots->FillDPIdSigmaQPFailProbCutPlots(nu);
00200       continue;
00201     }
00202 
00203     if (nu.trkEn<0.5) {
00204       Float_t momCurv=-1;
00205       if (nu.qp!=0) momCurv=1./nu.qp;
00206       MAXMSG("NuReco",Msg::kInfo,10)
00207         <<endl
00208         <<"DST:"
00209         <<" nshw="<<nu.nshw
00210         <<", ntrk="<<nu.ntrk
00211         <<", primshw="<<nu.primshw
00212         <<", primtrk="<<nu.primtrk
00213         <<", shwExists="<<nu.shwExists<<","
00214         <<", trkExists="<<nu.trkExists<<","
00215         <<endl
00216         <<"shwExists1,2,3="<<nu.shwExists1<<","
00217         <<nu.shwExists2<<","<<nu.shwExists3
00218         <<",  trkExists1,2,3="<<nu.trkExists1<<","
00219         <<nu.trkExists2<<","<<nu.trkExists3<<endl
00220         <<"E="<<nu.energy<<", trkEn="<<nu.trkEn<<", shwEn="<<nu.shwEn
00221         <<endl
00222         <<"trkMomentumRange="<<nu.trkMomentumRange
00223         <<", momCurv="<<momCurv
00224         <<", usedCurv="<<nu.usedCurv<<", fitpass="<<nu.trkfitpass
00225         <<endl
00226         <<"dircosnu="<<nu.dirCosNu
00227         <<", y="<<nu.y<<", q2="<<nu.q2
00228         <<", w2="<<nu.w2<<", x="<<nu.x
00229         <<endl
00230         <<"shwEn1="<<nu.shwEnCor1
00231         <<", shw2="<<nu.shwEnCor2
00232         <<", shw3="<<nu.shwEnCor3
00233         <<", shw4="<<nu.shwEnCor4
00234         <<", shw5="<<nu.shwEnCor5
00235         //<<", shw6="<<nu.shwEnCor6
00236         //<<", shw7="<<nu.shwEnCor7
00237         <<endl
00238         <<"trkCv1="<<nu.trkEnCorCurv1
00239         <<", trkCv2="<<nu.trkEnCorCurv2
00240         <<", trkCv3="<<nu.trkEnCorCurv3
00241         <<endl
00242         <<"trkRg1="<<nu.trkEnCorRange1
00243         <<", trkRg2="<<nu.trkEnCorRange2
00244         <<", trkRg3="<<nu.trkEnCorRange3
00245         <<endl;
00246     }
00247 
00248     //extra cuts to test
00249     //if (nu.dpID<+0.1) continue;
00250     //if (nu.dpID<+0.4) continue;
00251     //if (nu.dpID<+0.4 && nu.charge>0) continue;
00252     //if (nu.prob<0.1) continue;
00253     //if (nu.sigqp_qp>0.3) continue;
00254 
00255     //Bool_t weightForOsc=true;
00256     Bool_t weightForOsc=false;
00257     if (weightForOsc){
00258       //get the weight for the event
00259       Double_t weight=nu.rw;
00260       //apply the oscillation weight to CC events
00261       if (nu.iaction==1) {
00262         Float_t dm2=2.7e-3;
00263         Double_t oscWeight=general.OscWeight(dm2,1,
00264                                              nu.energyMC);
00265         weight*=oscWeight;
00266       }
00267       nu.rw=weight;
00268     }
00269 
00270     //if (nu.containedTrk && nu.rTrkEnd<0.3) {
00271     //MAXMSG("NuDSTAna",Msg::kInfo,200)
00272     //<<"nu.rTrkEnd="<<nu.rTrkEnd<<endl;
00273     //}
00274 
00276     //if (nu.rTrkEnd>0.3) continue;
00277 
00278     //if (nu.xTrkEnd<-0.2 && nu.planeTrkEnd<=120 && nu.containmentFlag==1) {
00279     //MAXMSG("NuDSTAna",Msg::kInfo,200)
00280     //<<"xTrkEnd="<<nu.xTrkEnd
00281     //<<", y="<<nu.yTrkEnd
00282     //<<", r="<<nu.rTrkEnd
00283     //<<", plTrkEnd"<<nu.planeTrkEnd
00284     //<<", con="<<nu.containedTrk
00285     //<<", flag="<<nu.containmentFlag
00286     //<<endl;
00287     //}
00288 
00289     //make the final plots
00290     this->MakeFinalPlots(plots,nu);
00291 
00292     MAXMSG("NuDSTAna",Msg::kInfo,5)
00293       <<"NMBSummaryTreeAna: NuEvent: index="<<nu.index
00294       <<", energy="<<nu.energy<<", energyMC="<<nu.energyMC<<endl;
00295   }//end of loop over summary tree
00296 }
00297 
00298 //......................................................................
00299 
00300 void NuDSTAna::FDTestAna()
00301 {
00302   //open the input file with the tree in it
00303   string inputFileName=this->GetInputFileName();
00304   NuInputEvents* fpInput=new NuInputEvents();
00305   NuInputEvents& input=*fpInput;
00306   input.InputFileName(inputFileName);
00307   input.InitialiseChains();
00308   input.InitialiseNuEventBranch();
00309   TDirectory* dirInput=input.OpenInputFile();
00310   Int_t firstRunNumber=input.GetFirstRunNumberNuEvent();
00311 
00312   //open the output file for histos etc
00313   string sFilePrefix="NMBSumAna";
00314   fOutFile=this->OpenFile(firstRunNumber,sFilePrefix.c_str());
00315   TDirectory* dirOutput=gDirectory;
00316   cout<<"After opening output file:"<<endl;
00317   dirOutput->Print();
00318 
00319   //copy across histos such hDetector, hSimFlag, and POT ones
00320   this->CopyAcrossHistos(dirInput,dirOutput);
00321 
00322   //use config object to store info
00323   NuConfig config;
00324   config.detector=Detector::kFar;
00325   config.run=100;
00326 
00327   string sTxt="nmb";
00328   ofstream& nmbTxt=*(this->OpenTxtFile(config,sTxt.c_str()));
00329   string sTxtNM="nm";
00330   ofstream& nmTxt=*(this->OpenTxtFile(config,sTxtNM.c_str()));
00331   //string sTxtLINM="nmLI";
00332   //ofstream& nmLITxt=*(this->OpenTxtFile(config,sTxtLINM.c_str()));
00333 
00334   //object to count events
00335   NuCounter cnt;
00336 
00337   static NuGeneral general;
00338   static NuPlots* plots=0;
00339   static NuCuts cuts;
00340   static NuReco reco;
00341 
00342   TH1F* hRecoEnDiff=new TH1F("hRecoEnDiff","hRecoEnDiff",
00343                        200000,-100,100);
00344   hRecoEnDiff->SetTitle("Reconstructed Energy Difference (GeV)");
00345   hRecoEnDiff->GetXaxis()->
00346     SetTitle("Reconstructed Energy Difference (GeV)");
00347   hRecoEnDiff->GetXaxis()->CenterTitle();
00348   hRecoEnDiff->GetYaxis()->SetTitle("");
00349   hRecoEnDiff->GetYaxis()->CenterTitle();
00350   hRecoEnDiff->SetFillColor(0);
00351   hRecoEnDiff->SetLineColor(1);
00352   //hRecoEnDiff->SetBit(TH1::kCanRebin);
00353 
00354   TH1F* hRecoEnDiffCurv=new TH1F("hRecoEnDiffCurv","hRecoEnDiffCurv",
00355                                  200000,-100,100);
00356   hRecoEnDiffCurv->SetTitle("Reconstructed Energy Difference (GeV)");
00357   hRecoEnDiffCurv->GetXaxis()->
00358     SetTitle("Reconstructed Energy Difference (GeV)");
00359   hRecoEnDiffCurv->GetXaxis()->CenterTitle();
00360   hRecoEnDiffCurv->GetYaxis()->SetTitle("");
00361   hRecoEnDiffCurv->GetYaxis()->CenterTitle();
00362   hRecoEnDiffCurv->SetFillColor(0);
00363   hRecoEnDiffCurv->SetLineColor(1);
00364   //hRecoEnDiffCurv->SetBit(TH1::kCanRebin);
00365 
00366   TH1F* hRecoEnDiffRange=new TH1F("hRecoEnDiffRange","hRecoEnDiffRange",
00367                                   200000,-100,100);
00368   hRecoEnDiffRange->SetTitle("Reconstructed Energy Difference (GeV)");
00369   hRecoEnDiffRange->GetXaxis()->
00370     SetTitle("Reconstructed Energy Difference (GeV)");
00371   hRecoEnDiffRange->GetXaxis()->CenterTitle();
00372   hRecoEnDiffRange->GetYaxis()->SetTitle("");
00373   hRecoEnDiffRange->GetYaxis()->CenterTitle();
00374   hRecoEnDiffRange->SetFillColor(0);
00375   hRecoEnDiffRange->SetLineColor(1);
00376   //hRecoEnDiffRange->SetBit(TH1::kCanRebin);
00377 
00378 
00379   TH1F* hRecoTrkEnDiff=new TH1F("hRecoTrkEnDiff","hRecoTrkEnDiff",
00380                        200000,-100,100);
00381   hRecoTrkEnDiff->SetTitle("Reconstructed Trk Energy Difference (GeV)");
00382   hRecoTrkEnDiff->GetXaxis()->
00383     SetTitle("Reconstructed Trk Energy Difference (GeV)");
00384   hRecoTrkEnDiff->GetXaxis()->CenterTitle();
00385   hRecoTrkEnDiff->GetYaxis()->SetTitle("");
00386   hRecoTrkEnDiff->GetYaxis()->CenterTitle();
00387   hRecoTrkEnDiff->SetFillColor(0);
00388   hRecoTrkEnDiff->SetLineColor(1);
00389   //hRecoTrkEnDiff->SetBit(TH1::kCanRebin);
00390 
00391   TH1F* hRecoTrkEnDiffCurv=new TH1F("hRecoTrkEnDiffCurv","hRecoTrkEnDiffCurv",
00392                                  200000,-100,100);
00393   hRecoTrkEnDiffCurv->SetTitle("Reconstructed Trk Energy Difference (GeV)");
00394   hRecoTrkEnDiffCurv->GetXaxis()->
00395     SetTitle("Reconstructed Trk Energy Difference (GeV)");
00396   hRecoTrkEnDiffCurv->GetXaxis()->CenterTitle();
00397   hRecoTrkEnDiffCurv->GetYaxis()->SetTitle("");
00398   hRecoTrkEnDiffCurv->GetYaxis()->CenterTitle();
00399   hRecoTrkEnDiffCurv->SetFillColor(0);
00400   hRecoTrkEnDiffCurv->SetLineColor(1);
00401   //hRecoTrkEnDiffCurv->SetBit(TH1::kCanRebin);
00402 
00403   TH1F* hRecoTrkEnDiffRange=new TH1F("hRecoTrkEnDiffRange","hRecoTrkEnDiffRange",
00404                                   200000,-100,100);
00405   hRecoTrkEnDiffRange->SetTitle("Reconstructed Trk Energy Difference (GeV)");
00406   hRecoTrkEnDiffRange->GetXaxis()->
00407     SetTitle("Reconstructed Trk Energy Difference (GeV)");
00408   hRecoTrkEnDiffRange->GetXaxis()->CenterTitle();
00409   hRecoTrkEnDiffRange->GetYaxis()->SetTitle("");
00410   hRecoTrkEnDiffRange->GetYaxis()->CenterTitle();
00411   hRecoTrkEnDiffRange->SetFillColor(0);
00412   hRecoTrkEnDiffRange->SetLineColor(1);
00413   //hRecoTrkEnDiffRange->SetBit(TH1::kCanRebin);
00414 
00415 
00416 
00417 
00418   TH1F* hRecoShwEnDiff=new TH1F("hRecoShwEnDiff","hRecoShwEnDiff",
00419                        200000,-100,100);
00420   hRecoShwEnDiff->SetTitle("Reconstructed Shw Energy Difference (GeV)");
00421   hRecoShwEnDiff->GetXaxis()->
00422     SetTitle("Reconstructed Shw Energy Difference (GeV)");
00423   hRecoShwEnDiff->GetXaxis()->CenterTitle();
00424   hRecoShwEnDiff->GetYaxis()->SetTitle("");
00425   hRecoShwEnDiff->GetYaxis()->CenterTitle();
00426   hRecoShwEnDiff->SetFillColor(0);
00427   hRecoShwEnDiff->SetLineColor(1);
00428   //hRecoShwEnDiff->SetBit(TH1::kCanRebin);
00429 
00430   TH1F* hRecoShwEnDiffCurv=new TH1F("hRecoShwEnDiffCurv","hRecoShwEnDiffCurv",
00431                                  200000,-100,100);
00432   hRecoShwEnDiffCurv->SetTitle("Reconstructed Shw Energy Difference (GeV)");
00433   hRecoShwEnDiffCurv->GetXaxis()->
00434     SetTitle("Reconstructed Shw Energy Difference (GeV)");
00435   hRecoShwEnDiffCurv->GetXaxis()->CenterTitle();
00436   hRecoShwEnDiffCurv->GetYaxis()->SetTitle("");
00437   hRecoShwEnDiffCurv->GetYaxis()->CenterTitle();
00438   hRecoShwEnDiffCurv->SetFillColor(0);
00439   hRecoShwEnDiffCurv->SetLineColor(1);
00440   //hRecoShwEnDiffCurv->SetBit(TH1::kCanRebin);
00441 
00442   TH1F* hRecoShwEnDiffRange=new TH1F("hRecoShwEnDiffRange","hRecoShwEnDiffRange",
00443                                   200000,-100,100);
00444   hRecoShwEnDiffRange->SetTitle("Reconstructed Shw Energy Difference (GeV)");
00445   hRecoShwEnDiffRange->GetXaxis()->
00446     SetTitle("Reconstructed Shw Energy Difference (GeV)");
00447   hRecoShwEnDiffRange->GetXaxis()->CenterTitle();
00448   hRecoShwEnDiffRange->GetYaxis()->SetTitle("");
00449   hRecoShwEnDiffRange->GetYaxis()->CenterTitle();
00450   hRecoShwEnDiffRange->SetFillColor(0);
00451   hRecoShwEnDiffRange->SetLineColor(1);
00452   //hRecoShwEnDiffRange->SetBit(TH1::kCanRebin);
00453 
00454 
00455 
00456 
00457   TH1F* hRecoEnOfDiff=new TH1F("hRecoEnOfDiff","hRecoEnOfDiff",
00458                                400,-100,100);
00459   hRecoEnOfDiff->SetTitle("Reconstructed Energy (GeV)");
00460   hRecoEnOfDiff->GetXaxis()->
00461     SetTitle("Reconstructed Energy (GeV)");
00462   hRecoEnOfDiff->GetXaxis()->CenterTitle();
00463   hRecoEnOfDiff->GetYaxis()->SetTitle("");
00464   hRecoEnOfDiff->GetYaxis()->CenterTitle();
00465   hRecoEnOfDiff->SetFillColor(0);
00466   hRecoEnOfDiff->SetLineColor(1);
00467   //hRecoEnOfDiff->SetBit(TH1::kCanRebin);
00468 
00469   TH1F* hRecoTrkEnOfDiff=new TH1F("hRecoTrkEnOfDiff","hRecoTrkEnOfDiff",
00470                                400,-100,100);
00471   hRecoTrkEnOfDiff->SetTitle("Reconstructed Trk Energy (GeV)");
00472   hRecoTrkEnOfDiff->GetXaxis()->
00473     SetTitle("Reconstructed Trk Energy (GeV)");
00474   hRecoTrkEnOfDiff->GetXaxis()->CenterTitle();
00475   hRecoTrkEnOfDiff->GetYaxis()->SetTitle("");
00476   hRecoTrkEnOfDiff->GetYaxis()->CenterTitle();
00477   hRecoTrkEnOfDiff->SetFillColor(0);
00478   hRecoTrkEnOfDiff->SetLineColor(1);
00479   //hRecoTrkEnOfDiff->SetBit(TH1::kCanRebin);
00480 
00481   TH1F* hRecoShwEnOfDiff=new TH1F("hRecoShwEnOfDiff","hRecoShwEnOfDiff",
00482                                400,-100,100);
00483   hRecoShwEnOfDiff->SetTitle("Reconstructed Shw Energy (GeV)");
00484   hRecoShwEnOfDiff->GetXaxis()->
00485     SetTitle("Reconstructed Shw Energy (GeV)");
00486   hRecoShwEnOfDiff->GetXaxis()->CenterTitle();
00487   hRecoShwEnOfDiff->GetYaxis()->SetTitle("");
00488   hRecoShwEnOfDiff->GetYaxis()->CenterTitle();
00489   hRecoShwEnOfDiff->SetFillColor(0);
00490   hRecoShwEnOfDiff->SetLineColor(1);
00491   //hRecoShwEnOfDiff->SetBit(TH1::kCanRebin);
00492 
00493   //version to do reco/cuts with
00494   NuCuts::NuAnaVersion_t overrideAnaVersion=NuCuts::kCC0250Std;
00495 
00496   input.ResetNuEventLoopPositionToStart();
00497 
00498   cout<<endl
00499       <<"************************************************"<<endl
00500       <<"***      Starting main loop over snarls      ***"<<endl
00501       <<"************************************************"<<endl;
00502 
00503   for (Int_t i=0;i<input.GetEntriesNuEvent();++i) {
00504     cnt.evtCounter++;
00505 
00506     this->PrintLoopProgress(i,input.GetEntriesNuEvent(),1);
00507 
00508     NuEvent& nu=const_cast<NuEvent&>(input.GetNextNuEvent(Msg::kDebug));
00509 
00510     //OVERRIDE
00511     nu.releaseType=8240;
00512     //set the analysis version (could be kFullDST)
00513     nu.anaVersion=this->SanityCheckedAnaVersion
00514       (nu.anaVersion,overrideAnaVersion);
00515 
00516     //RE-RECONSTRUCT the neutrino energy
00517     reco.GetEvtEnergy(nu, false);
00518     reco.ApplyReweights(nu);
00519 
00520     //make all the std cuts
00521     if (!this->IsGoodStdCuts(plots,nu)) continue;
00522 
00523     if (nu.charge==-1) {
00524       plots->PrintEventInfo(nmTxt,nu);
00525       cnt.nuNQCounter++;
00526     }
00527     else if (nu.charge==+1) {
00528       plots->PrintEventInfo(nmbTxt,nu);
00529       cnt.nuPQCounter++;
00530     }
00531     else cout<<"ahhh, bad charge (1)"<<endl;
00532 
00533     Float_t energyDiff=-999;
00534 
00535     Bool_t printToScreen=false;
00536     const NuEvent* pnu=0;
00537     if (printToScreen) pnu=this->GetEvent(nu);
00538 
00539     if (printToScreen && pnu && nu.charge==-1) {
00540       const NuEvent& nui=*pnu;
00541 
00542       static NuReco reco;
00543       reco.GetShowerEnergyCC(nu);
00544 
00545       energyDiff=nu.energy-nui.energy;
00546       Float_t rangeCurvDiff=nu.trkEnRange-nu.trkEnCurv;
00547 
00548       if (TMath::Abs(energyDiff)>0.005*(Munits::GeV)) {
00549         MAXMSG("NuDSTAna",Msg::kInfo,500)
00550           <<endl<<"************************"<<endl
00551           <<endl<<"************************"<<endl
00552           <<endl<<"************************"<<endl
00553           <<endl<<"************************"<<endl
00554           <<endl<<"************************"<<endl
00555           <<endl<<"************************"<<endl
00556           <<endl<<"************************"<<endl
00557           <<endl<<"************************"<<endl
00558           <<endl<<"************************"<<endl
00559           <<endl<<"************************"<<endl
00560           <<endl<<"************************"<<endl
00561           <<endl<<"************************"<<endl
00562           <<endl<<"************************"<<endl
00563           <<"run="<<nu.run<<", snarl="<<nu.snarl<<", evt="<<nu.evt
00564           <<endl
00565           <<"My energy="<<nu.energy<<", CC std energy="<<nui.energy
00566           <<", Ediff="<<energyDiff
00567           <<endl
00568           <<"shwEn="<<nu.shwEn
00569           <<", shwEnCor="<<nu.shwEnCor
00570           <<", shwEnNoCor="<<nu.shwEnNoCor
00571           <<", primshw="<<nu.primshw
00572           <<", nshw="<<nu.nshw
00573           <<endl
00574           <<"shwEnNoCor1="<<nu.shwEnNoCor1
00575           <<", shwEnNoCor2="<<nu.shwEnNoCor2
00576           <<", shwEnNOCor3="<<nu.shwEnNoCor3
00577           <<", shwEnNoCor4="<<nu.shwEnNoCor4
00578           <<endl
00579           <<"shower1 E="<<reco.GetShowerEnergyCor(nu.shwEnNoCor1,CandShowerHandle::kCC,nu)
00580           <<" : x,y,z="<<nu.xShwVtx1
00581           <<","<<nu.yShwVtx1
00582           <<","<<nu.zShwVtx1
00583           <<endl
00584           <<"shower2 E="<<reco.GetShowerEnergyCor(nu.shwEnNoCor2,CandShowerHandle::kCC,nu)
00585           <<" : x,y,z="<<nu.xShwVtx2
00586           <<","<<nu.yShwVtx2
00587           <<","<<nu.zShwVtx2
00588           <<endl
00589           <<"shower3 E="<<reco.GetShowerEnergyCor(nu.shwEnNoCor3,CandShowerHandle::kCC,nu)
00590           <<" : x,y,z="<<nu.xShwVtx3
00591           <<","<<nu.yShwVtx3
00592           <<","<<nu.zShwVtx3
00593           <<endl
00594           <<"shower4 E="<<reco.GetShowerEnergyCor(nu.shwEnNoCor4,CandShowerHandle::kCC,nu)
00595           <<" : x,y,z="<<nu.xShwVtx4
00596           <<","<<nu.yShwVtx4
00597           <<","<<nu.zShwVtx4
00598           <<endl
00599           <<"track  x,y,z="<<nu.xTrkVtx
00600           <<","<<nu.yTrkVtx
00601           <<","<<nu.zTrkVtx
00602           <<endl
00603           <<"trkEnRange="<<nu.trkEnRange
00604           <<", trkEnCurv="<<nu.trkEnCurv
00605           <<", rng-crv="<<rangeCurvDiff
00606           <<endl
00607           <<"trkEnCorRange1="<<nu.trkEnCorRange1
00608           <<", trkEnCorRange2="<<nu.trkEnCorRange2
00609           <<", trkEnCorRange3="<<nu.trkEnCorRange3
00610           <<endl
00611           <<"trkEnCorCurv1="<<nu.trkEnCorCurv1
00612           <<", trkEnCorCurv2="<<nu.trkEnCorCurv2
00613           <<", trkEnCorCurv3="<<nu.trkEnCorCurv3
00614           <<endl;
00615       }
00616     }
00617 
00618     if (printToScreen && ((!pnu && nu.charge==-1) || nu.energy>200)) {
00619       Float_t p=-1;
00620       if (nu.qp) p=1./nu.qp;
00621 
00622       MAXMSG("NuDSTAna",Msg::kInfo,500)
00623         <<endl<<"************************"<<endl
00624         <<"run="<<nu.run<<", snarl="<<nu.snarl<<", evt="<<nu.evt
00625         <<", entry="<<nu.entry
00626         <<endl
00627         <<"My energy="<<nu.energy<<", trkEn="<<nu.trkEn
00628         <<", shwEn="<<nu.shwEn
00629         <<endl
00630         <<"shwEnCor="<<nu.shwEnCor
00631         <<", shwEnNoCor="<<nu.shwEnNoCor
00632         <<", primshw="<<nu.primshw
00633         <<", nshw="<<nu.nshw
00634         <<", ntrk="<<nu.ntrk<<", nevt="<<nu.nevt
00635         <<endl
00636         <<"shwEnNoCor1="<<nu.shwEnNoCor1
00637         <<", shwEnNoCor2="<<nu.shwEnNoCor2
00638         <<", shwEnNOCor3="<<nu.shwEnNoCor3
00639         <<", shwEnNoCor4="<<nu.shwEnNoCor4
00640         <<endl
00641         <<"shower1 E="<<reco.GetShowerEnergyCor(nu.shwEnNoCor1,CandShowerHandle::kCC,nu)
00642         <<" : x,y,z="<<nu.xShwVtx1
00643         <<","<<nu.yShwVtx1
00644         <<","<<nu.zShwVtx1
00645         <<endl
00646         <<"shower2 E="<<reco.GetShowerEnergyCor(nu.shwEnNoCor2,CandShowerHandle::kCC,nu)
00647         <<" : x,y,z="<<nu.xShwVtx2
00648         <<","<<nu.yShwVtx2
00649         <<","<<nu.zShwVtx2
00650         <<endl
00651         <<"shower3 E="<<reco.GetShowerEnergyCor(nu.shwEnNoCor3,CandShowerHandle::kCC,nu)
00652         <<" : x,y,z="<<nu.xShwVtx3
00653         <<","<<nu.yShwVtx3
00654         <<","<<nu.zShwVtx3
00655         <<endl
00656         <<"shower4 E="<<reco.GetShowerEnergyCor(nu.shwEnNoCor4,CandShowerHandle::kCC,nu)
00657         <<" : x,y,z="<<nu.xShwVtx4
00658         <<","<<nu.yShwVtx4
00659         <<","<<nu.zShwVtx4
00660         <<endl
00661         <<"track  x,y,z="<<nu.xTrkVtx
00662         <<","<<nu.yTrkVtx
00663         <<","<<nu.zTrkVtx
00664         <<endl
00665         <<"trkEnRange="<<nu.trkEnRange
00666         <<", trkEnCurv="<<nu.trkEnCurv
00667         <<", fitpass="<<nu.trkfitpass
00668         <<endl
00669         <<"rangeNoCor="<<nu.trkMomentumRange
00670         <<", curvNoCor="<<p
00671         <<endl
00672         <<"trkEnCorRange1="<<nu.trkEnCorRange1
00673         <<", trkEnCorRange2="<<nu.trkEnCorRange2
00674         <<", trkEnCorRange3="<<nu.trkEnCorRange3
00675         <<endl
00676         <<"trkEnCorCurv1="<<nu.trkEnCorCurv1
00677         <<", trkEnCorCurv2="<<nu.trkEnCorCurv2
00678         <<", trkEnCorCurv3="<<nu.trkEnCorCurv3
00679         <<endl
00680         <<"nshw="<<nu.nshw
00681         <<", rawPhEvt="<<nu.rawPhEvt
00682         <<", planeEvtHdrBeg="<<nu.planeEvtHdrBeg
00683         <<", planeEvtHdrEnd="<<nu.planeEvtHdrEnd
00684         <<endl;
00685 
00686       hRecoEnOfDiff->Fill(nu.energy);
00687       hRecoEnDiff->Fill(nu.energy);
00688       if (nu.containmentFlag==1) hRecoEnDiffRange->Fill(nu.energy);
00689       else if (nu.containmentFlag==2) hRecoEnDiffCurv->Fill(nu.energy);
00690       else cout<<"Ahhhhh"<<endl;
00691     }
00692 
00693     //if (pnu) continue;
00694     //if (energyDiff==-999) continue;
00695     //if (TMath::Abs(energyDiff)<0.005) continue;
00696 
00697     //make the final plots
00698     this->MakeFinalPlots(plots,nu);
00699 
00700     MAXMSG("NuDSTAna",Msg::kInfo,5)
00701       <<"Passed: index="<<nu.index
00702       <<", energy="<<nu.energy<<", energyMC="<<nu.energyMC<<endl;
00703   }//end of loop over summary tree
00704 
00705   MSG("NuAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
00706 
00710 
00711   //print out the numbers of events
00712   cnt.PrintMicroDST();
00713 
00714   MSG("NuAnalysis",Msg::kInfo)
00715     <<" ** Finished StdAna method **"<<endl;
00716 }
00717 
00718 //......................................................................
00719 
00720 const NuEvent* NuDSTAna::GetEventND(const NuEvent& nu)
00721 {
00722   static map<Int_t,map<Int_t,map<Int_t,NuEvent> > > mymap;
00723   static Bool_t firstTime=true;
00724 
00725   //check if file exists
00726   if (firstTime){
00727     firstTime=false;
00728 
00729     //string sFileName="fdlist-allevents.txt";
00730     //string sFileName="eventsFDDataTrish-sorted.txt";
00731     string sFileName="eventsNDDataTrish-sorted.txt";
00732 
00733     //open the file
00734     cout<<"Opening file "<<sFileName<<"..."<<endl;
00735     ifstream file(sFileName.c_str());
00736 
00737     if (file){
00738       cout<<"File exists..."<<endl;
00739       //variables to hold input from file
00740       //Int_t index=-1;
00741       Int_t run=-1;
00742       Int_t subrun=-1;
00743       Int_t snarl=-1;
00744       Int_t evt=-1;
00745       Float_t energy=-1;
00746       Float_t trkEn=-1;
00747       Float_t shwEn=-1;
00748       Float_t abID=-1;
00749 
00750 
00751       string s;
00752       Int_t counter=0;
00753 
00754       //read in from the text file, have to deal with all the *'s
00755       while (file>>run>>subrun>>snarl>>evt
00756              >>energy>>trkEn>>shwEn>>abID) {
00757         MAXMSG("NuDSTAna",Msg::kInfo,100)
00758           <<"run="<<run<<", snarl="<<snarl<<", evt="<<evt
00759           <<", energy="<<energy<<", trkEn="<<trkEn
00760           <<", shwEn="<<shwEn<<", abID="<<abID<<endl;
00761 
00762         if (run<9200 || run>9300) continue;
00763 
00764         NuEvent& nui=*new NuEvent();
00765         nui.run=run;
00766         nui.snarl=snarl;
00767         nui.evt=evt;
00768         nui.energy=energy;
00769         nui.trkEn=trkEn;
00770         nui.shwEn=shwEn;
00771         nui.abID=abID;
00772 
00773         mymap[run][snarl][evt]=nui;
00774 
00775         counter++;
00776       }
00777       cout<<"Total events found in txt file="<<counter<<endl;
00778     }
00779     else cout<<"No file"<<endl;
00780 
00781     Int_t counter=0;
00782     for (map<Int_t,map<Int_t,map<Int_t,NuEvent> > >::iterator it=
00783            mymap.begin();
00784          it!=mymap.end();++it) {
00785 
00786       for (map<Int_t,map<Int_t,NuEvent> >::iterator it2=
00787              it->second.begin();
00788            it2!=it->second.end();++it2) {
00789 
00790         for (map<Int_t,NuEvent>::iterator it3=it2->second.begin();
00791              it3!=it2->second.end();++it3) {
00792 
00793           NuEvent& n=it3->second;
00794           MAXMSG("NuDSTAna",Msg::kInfo,100)
00795             <<"Map: run="<<n.run<<", snarl="<<n.snarl<<", evt="<<n.evt
00796             <<", energy="<<n.energy<<endl;
00797 
00798           if (n.run==9259) {
00799             if (n.snarl<56595) {//140344
00800               MAXMSG("NuDSTAna",Msg::kInfo,100)
00801                 <<"Map: run="<<n.run
00802                 <<", snarl="<<n.snarl<<", evt="<<n.evt
00803                 <<", energy="<<n.energy<<endl;
00804               counter++;
00805             }
00806           }
00807 
00808         }
00809       }
00810     }
00811     cout<<"Total events in map="<<counter<<endl;
00812   }
00813 
00814   //look up the run and snarl in the map
00815   //return the NuEvent if found
00816   map<Int_t,map<Int_t,map<Int_t,NuEvent> > >::iterator it=
00817     mymap.find(nu.run);
00818   if (it==mymap.end()) {
00819     cout<<"No such run in map="<<nu.run<<endl;
00820     return NULL;
00821   }
00822   else {
00823     map<Int_t,map<Int_t,NuEvent> >::iterator it2=
00824       it->second.find(nu.snarl);
00825     if (it2==it->second.end()) {
00826       cout<<"No such snarl in map for run="<<nu.run
00827           <<", snarl="<<nu.snarl<<endl;
00828       return NULL;
00829     }
00830     else {
00831       map<Int_t,NuEvent>::iterator it3=it2->second.find(nu.evt);
00832       if (it3==it2->second.end()) {
00833         cout<<"No such evt in map for run="<<nu.run
00834             <<", snarl="<<nu.snarl<<", evt="<<nu.evt<<endl;
00835         return NULL;
00836       }
00837       else {
00838         return &(it3->second);
00839       }
00840     }
00841   }
00842 }
00843 
00844 //......................................................................
00845 
00846 const NuEvent* NuDSTAna::GetEvent(const NuEvent& nu)
00847 {
00848   static map<Int_t,map<Int_t,NuEvent> > mymap;
00849   static Bool_t firstTime=true;
00850 
00851   //check if file exists
00852   if (firstTime){
00853     firstTime=false;
00854 
00855     string sFileName="fdlist-allevents.txt";
00856 
00857     //open the file
00858     cout<<"Opening file "<<sFileName<<"..."<<endl;
00859     ifstream file(sFileName.c_str());
00860 
00861     if (file){
00862       cout<<"File exists"<<endl;
00863       //variables to hold input from file
00864       Int_t index=-1;
00865       Int_t run=-1;
00866       Int_t snarl=-1;
00867       Int_t evt=-1;
00868       Float_t energy=-1;
00869 
00870 
00871       string s;
00872       Int_t counter=0;
00873 
00874       //read in from the text file, have to deal with all the *'s
00875       while (file>>s>>index>>s>>run>>s>>snarl>>s>>evt>>s>>energy>>s) {
00876         //cout<<"index="<<index<<", run="<<run<<", snarl="<<snarl
00877         //  <<", evt="<<evt<<", energy="<<energy<<endl;
00878 
00879         NuEvent& nui=*new NuEvent();
00880         nui.run=run;
00881         nui.snarl=snarl;
00882         nui.evt=evt;
00883         nui.energy=energy;
00884 
00885         mymap[run][snarl]=nui;
00886 
00887         counter++;
00888       }
00889       cout<<"Total events found in txt file="<<counter<<endl;
00890     }
00891     else cout<<"No file"<<endl;
00892 
00893     Int_t counter=0;
00894     for (map<Int_t,map<Int_t,NuEvent> >::iterator it=mymap.begin();
00895          it!=mymap.end();++it) {
00896 
00897       for (map<Int_t,NuEvent>::iterator it2=it->second.begin();
00898            it2!=it->second.end();++it2) {
00899         //NuEvent& n=it2->second;
00900         //cout<<"run="<<n.run<<", snarl="<<n.snarl<<", energy="<<n.energy
00901         //<<endl;
00902         counter++;
00903       }
00904     }
00905     cout<<"Total events in map="<<counter<<endl;
00906   }
00907 
00908   //look up the run and snarl in the map
00909   //return the NuEvent if found
00910   map<Int_t,map<Int_t,NuEvent> >::iterator it=mymap.find(nu.run);
00911   if (it==mymap.end()) {
00912     cout<<"No such run in map="<<nu.run<<endl;
00913     return NULL;
00914   }
00915   else {
00916     map<Int_t,NuEvent>::iterator it2=it->second.find(nu.snarl);
00917     if (it2==it->second.end()) {
00918       cout<<"No such snarl in map for run="<<nu.run
00919           <<", snarl="<<nu.snarl<<endl;
00920       return NULL;
00921     }
00922     else return &(it2->second);
00923   }
00924 }
00925 
00926 //......................................................................
00927 
00928 void NuDSTAna::CopyAcrossHistos(TDirectory* dirInput,
00929                                 TDirectory* dirOutput) const
00930 {
00931   //vector to store the names of the histograms to copy across
00932   vector<string> vObjectNames;
00933   vObjectNames.push_back("hDetector");
00934   vObjectNames.push_back("hSimFlag");
00935   vObjectNames.push_back("hTrigSrc");
00936   vObjectNames.push_back("hSpillsPerFile");
00937 
00938   //these were commented out
00939   vObjectNames.push_back("hRun");
00940   vObjectNames.push_back("hPottortgt");
00941   vObjectNames.push_back("hPotBadtortgt");
00942   vObjectNames.push_back("hPottrtgtd");
00943   vObjectNames.push_back("hPotBadtrtgtd");
00944   vObjectNames.push_back("hPottor101");
00945   vObjectNames.push_back("hPotBadtor101");
00946   vObjectNames.push_back("hPottr101d");
00947   vObjectNames.push_back("hPotBadtr101d");
00948 
00949   //these are new
00950   vObjectNames.push_back("hTotalPot");
00951   vObjectNames.push_back("hNtupleEarliestTime");
00952   vObjectNames.push_back("hNtupleLatestTime");
00953 
00954   NuGeneral general;
00955   general.CopyAcrossObjects(dirInput,dirOutput,vObjectNames);
00956 }
00957 
00958 //......................................................................
00959 
00960 NuInputEvents& NuDSTAna::DoIOSimple(std::string sFilePrefix)
00961 {
00962   //open the input file with the tree in it
00963   string inputFileName=this->GetInputFileName();
00964   NuInputEvents* fpInput=new NuInputEvents();
00965   NuInputEvents& input=*fpInput;
00966   input.InputFileName(inputFileName);
00967   input.InitialiseChains();
00968   input.InitialiseNuEventBranch();
00969   TDirectory* dirInput=input.OpenInputFile();
00970   Int_t firstRunNumber=input.GetFirstRunNumberNuEvent();
00971 
00972   //open the output file for histos etc
00973   if (sFilePrefix!="") {
00974     fOutFile=this->OpenFile(firstRunNumber,sFilePrefix.c_str());
00975     TDirectory* dirOutput=gDirectory;
00976     cout<<"After opening output file:"<<endl;
00977     dirOutput->Print();
00978 
00979     //copy across histos such hDetector, hSimFlag, and POT ones
00980     this->CopyAcrossHistos(dirInput,dirOutput);
00981   }
00982   else cout<<"Not opening an output file"<<endl;
00983 
00984   return input;
00985 }
00986 
00987 //......................................................................
00988 
00989 NuInputEvents& NuDSTAna::DoIO(NuOutputWriter* poutput,
00990                               std::string sFilePrefix,
00991                               std::string sFullFileName)
00992 {
00993   //open the input file with the tree in it
00994   string inputFileName=this->GetInputFileName();
00995   NuInputEvents* fpInput=new NuInputEvents();
00996   NuInputEvents& input=*fpInput;
00997   input.InputFileName(inputFileName);
00998   input.InitialiseChains();
00999   input.InitialiseNuEventBranch();
01000 
01001   TDirectory* dirInput=0;
01002 
01003   //formatting string for times
01004   MsgFormat ffmt("%9.f");
01005 
01006   NuXMLConfig *xmlConfigClone=0;
01007   TH1F* hDetectorClone=0;
01008   TH1F* hSimFlagClone=0;
01009   TH1F* hTrigSrcClone=0;
01010   TH1F* hSpillsPerFileClone=0;
01011 
01012   TH1F* hTotalPotClone=0;
01013 
01014   TH1F* hPottortgtClone=0;
01015   TH1F* hPotBadtortgtClone=0;
01016   TH1F* hPottrtgtdClone=0;
01017   TH1F* hPotBadtrtgtdClone=0;
01018   TH1F* hPottor101Clone=0;
01019   TH1F* hPotBadtor101Clone=0;
01020   TH1F* hPottr101dClone=0;
01021   TH1F* hPotBadtr101dClone=0;
01022   TH1F* hRunClone=0;
01023 
01024   TH1F* hNtupleEarliestTimeClone=0;
01025   TH1F* hNtupleLatestTimeClone=0;
01026 
01027   //Matrix method histograms (numu CC):
01028   TH2D *hRecoVsTrueEnergy_NDClone = 0;
01029   TH2D *hRecoVsTrueEnergy_FDClone = 0;
01030   TH1D *hEfficiency_NDClone = 0;
01031   TH1D *hEfficiency_FDClone = 0;
01032   TH1D *hPurity_NDClone = 0;
01033   TH1D *hPurity_FDClone = 0;
01034   TH1D *hRecoEnergyAllEvents_NDClone = 0;
01035   TH1D *hRecoEnergyCCOnlyEvents_NDClone = 0;
01036   TH1D *hTrueEnergyCCOnlyEvents_NDClone = 0;
01037   TH1D *hTrueEnergyTrueCCFidEvents_NDClone = 0;
01038   TH1D *hTrueEnergyTrueCCFidEvents_FDClone = 0;
01039   TH1D *hTrueEnergyCCOnlyEvents_FDClone = 0;
01040   TH1D *hRecoEnergyCCOnlyEvents_FDClone = 0;
01041   TH1D *hRecoEnergyAllEvents_FDClone = 0;
01042   TH1D* hRecoEnergy_NDClone = 0;
01043   TH1D* hRecoEnergy_FDClone = 0;
01044   TH1D* hRecoEnergy_ND_NCClone = 0;
01045   TH1D* hRecoEnergy_FD_NCClone = 0;
01046   TH2D* hRecoVsTrueEnergy_ND_NCClone = 0;
01047   TH2D* hRecoVsTrueEnergy_FD_NCClone = 0;
01048 
01049   TH2D* hRecoVsTrueEnergy_NCClone_truly[ENCTruth::kNumTruths][2] = {{0,},};
01050 
01051   TH1D* hCCContamination_FDClone = 0;
01052   TH1D* hCCContamination_NDClone = 0;
01053   TH2D* hCCContaminationRecoVsTrue_FDClone = 0;
01054   TH1D* hNCContamination_FDClone = 0;
01055   TH1D* hNCContamination_NDClone = 0;
01056   //Matrix method histograms (numubar CC):
01057   TH2D *hRecoVsTrueEnergyPQ_NDClone = 0;
01058   TH2D *hRecoVsTrueEnergyPQ_FDClone = 0;
01059   TH1D *hEfficiencyPQ_NDClone = 0;
01060   TH1D *hEfficiencyPQ_FDClone = 0;
01061   TH1D *hPurityPQ_NDClone = 0;
01062   TH1D *hPurityPQ_FDClone = 0;
01063   TH1D *hRecoEnergyAllEventsPQ_NDClone = 0;
01064   TH1D *hRecoEnergyCCOnlyEventsPQ_NDClone = 0;
01065   TH1D *hTrueEnergyCCOnlyEventsPQ_NDClone = 0;
01066   TH1D *hTrueEnergyTrueCCFidEventsPQ_NDClone = 0;
01067   TH1D *hTrueEnergyTrueCCFidEventsPQ_FDClone = 0;
01068   TH1D *hTrueEnergyCCOnlyEventsPQ_FDClone = 0;
01069   TH1D *hRecoEnergyCCOnlyEventsPQ_FDClone = 0;
01070   TH1D *hRecoEnergyAllEventsPQ_FDClone = 0;
01071   TH1D* hRecoEnergyPQ_NDClone = 0;
01072   TH1D* hRecoEnergyPQ_FDClone = 0;
01073   TH1D* hCCContaminationPQ_FDClone = 0;
01074   TH1D* hCCContaminationPQ_NDClone = 0;
01075   TH2D* hCCContaminationRecoVsTruePQ_FDClone = 0;
01076   TH1D* hNCContaminationPQ_FDClone = 0;
01077   TH1D* hNCContaminationPQ_NDClone = 0;
01078   //Matrix method Decay Pipe histograms
01079   TH1D* hTrueEnergyAllEventsPQ_NDClone = 0;
01080   TH1D* hTrueEnergyAllEventsPQ_FDClone = 0;
01081   TH1D* hTrueEnergyDecayPipePQ_NDClone = 0;
01082   TH1D* hTrueEnergyDecayPipePQ_FDClone = 0;
01083   //Matrix method histograms (numu + numubar CC):
01084   TH2D *hRecoVsTrueEnergyAll_NDClone = 0;
01085   TH2D *hRecoVsTrueEnergyAll_FDClone = 0;
01086   TH1D *hEfficiencyAll_NDClone = 0;
01087   TH1D *hEfficiencyAll_FDClone = 0;
01088   TH1D *hPurityAll_NDClone = 0;
01089   TH1D *hPurityAll_FDClone = 0;
01090   TH1D *hRecoEnergyAllEventsAll_NDClone = 0;
01091   TH1D *hRecoEnergyCCOnlyEventsAll_NDClone = 0;
01092   TH1D *hTrueEnergyCCOnlyEventsAll_NDClone = 0;
01093   TH1D *hTrueEnergyTrueCCFidEventsAll_NDClone = 0;
01094   TH1D *hTrueEnergyTrueCCFidEventsAll_FDClone = 0;
01095   TH1D *hTrueEnergyCCOnlyEventsAll_FDClone = 0;
01096   TH1D *hRecoEnergyCCOnlyEventsAll_FDClone = 0;
01097   TH1D *hRecoEnergyAllEventsAll_FDClone = 0;
01098   TH1D* hRecoEnergyAll_NDClone = 0;
01099   TH1D* hRecoEnergyAll_FDClone = 0;
01100   //Matrix method histograms (nutau CC):
01101   TH2D* hRecoVsTrueEnergyTau_FDClone = 0;
01102   TH1D* hEfficiencyTau_FDClone = 0;
01103   TH1D* hTrueEnergyTrueCCFidEventsTau_FDClone = 0;
01104   TH1D* hTrueEnergyCCOnlyEventsTau_FDClone = 0;
01105   //Matrix method histograms (nutaubar CC):
01106   TH2D* hRecoVsTrueEnergyTauPQ_FDClone = 0;
01107   TH1D* hEfficiencyTauPQ_FDClone = 0;
01108   TH1D* hTrueEnergyTrueCCFidEventsTauPQ_FDClone = 0;
01109   TH1D* hTrueEnergyCCOnlyEventsTauPQ_FDClone = 0;
01110   //Matrix method histograms (nutau + nutaubar CC):
01111   TH2D* hRecoVsTrueEnergyTauAll_FDClone = 0;
01112   TH1D* hEfficiencyTauAll_FDClone = 0;
01113   TH1D* hTrueEnergyTrueCCFidEventsTauAll_FDClone = 0;
01114   TH1D* hTrueEnergyCCOnlyEventsTauAll_FDClone = 0;
01115 
01116   
01117   for (Int_t i=0;i<10000;i++){
01118 
01119     //get the next file
01120     TDirectory* tmpDirInput=input.OpenNextInputFile();
01121 
01122     //check file exists
01123     if (!tmpDirInput) continue;
01124 
01125     //store input file directory
01126     dirInput=tmpDirInput;
01127     gDirectory=dirInput;
01128     dirInput->Print();
01129 
01130     NuXMLConfig *xmlConfig = (NuXMLConfig*)gROOT->FindObject("NuXMLConfig");
01131 
01132     //get the histograms
01133     TH1F* hDetector=(TH1F*)gROOT->FindObject("hDetector");
01134     TH1F* hSimFlag=(TH1F*)gROOT->FindObject("hSimFlag");
01135     TH1F* hTrigSrc=(TH1F*)gROOT->FindObject("hTrigSrc");
01136     TH1F* hSpillsPerFile=(TH1F*)gROOT->FindObject("hSpillsPerFile");
01137 
01138     TH1F* hTotalPot=(TH1F*)gROOT->FindObject("hTotalPot");
01139 
01140     TH1F* hPottortgt=(TH1F*)gROOT->FindObject("hPottortgt");
01141     TH1F* hPotBadtortgt=(TH1F*)gROOT->FindObject("hPotBadtortgt");
01142     TH1F* hPottrtgtd=(TH1F*)gROOT->FindObject("hPottrtgtd");
01143     TH1F* hPotBadtrtgtd=(TH1F*)gROOT->FindObject("hPotBadtrtgtd");
01144     TH1F* hPottor101=(TH1F*)gROOT->FindObject("hPottor101");
01145     TH1F* hPotBadtor101=(TH1F*)gROOT->FindObject("hPotBadtor101");
01146     TH1F* hPottr101d=(TH1F*)gROOT->FindObject("hPottr101d");
01147     TH1F* hPotBadtr101d=(TH1F*)gROOT->FindObject("hPotBadtr101d");
01148     TH1F* hRun=(TH1F*)gROOT->FindObject("hRun");
01149 
01150     TH1F* hNtupleEarliestTime=(TH1F*)gROOT->FindObject("hNtupleEarliestTime");
01151     TH1F* hNtupleLatestTime=(TH1F*)gROOT->FindObject("hNtupleLatestTime");
01152 
01153     //get Matrix Method histograms (numu CC):
01154     TH2D *hRecoVsTrueEnergy_ND = (TH2D*) gROOT->FindObject("RecoVsTrueEnergy_ND");
01155     TH2D *hRecoVsTrueEnergy_FD = (TH2D*) gROOT->FindObject("RecoVsTrueEnergy_FD");
01156     TH1D *hEfficiency_ND = (TH1D*) gROOT->FindObject("Efficiency_ND");
01157     TH1D *hEfficiency_FD = (TH1D*) gROOT->FindObject("Efficiency_FD");
01158     TH1D *hPurity_ND = (TH1D*) gROOT->FindObject("Purity_ND");
01159     TH1D *hPurity_FD = (TH1D*) gROOT->FindObject("Purity_FD");
01160     TH1D *hRecoEnergyAllEvents_ND = (TH1D*) gROOT->FindObject("RecoEnergyAllEvents_ND");
01161     TH1D *hRecoEnergyCCOnlyEvents_ND = (TH1D*) gROOT->FindObject("RecoEnergyCCOnlyEvents_ND");
01162     TH1D *hTrueEnergyCCOnlyEvents_ND = (TH1D*) gROOT->FindObject("TrueEnergyCCOnlyEvents_ND");
01163     TH1D *hTrueEnergyTrueCCFidEvents_ND = (TH1D*) gROOT->FindObject("TrueEnergyTrueCCFidEvents_ND");
01164     TH1D *hTrueEnergyTrueCCFidEvents_FD = (TH1D*) gROOT->FindObject("TrueEnergyTrueCCFidEvents_FD");
01165     TH1D *hTrueEnergyCCOnlyEvents_FD = (TH1D*) gROOT->FindObject("TrueEnergyCCOnlyEvents_FD");
01166     TH1D *hRecoEnergyCCOnlyEvents_FD = (TH1D*) gROOT->FindObject("RecoEnergyCCOnlyEvents_FD");
01167     TH1D *hRecoEnergyAllEvents_FD = (TH1D*) gROOT->FindObject("RecoEnergyAllEvents_FD");
01168     TH1D *hRecoEnergy_ND = (TH1D*) gROOT->FindObject("RecoEnergy_ND");
01169     
01170     TH1D *hRecoEnergy_FD = (TH1D*) gROOT->FindObject("RecoEnergy_FD");
01171     TH1D *hRecoEnergy_ND_NC = (TH1D*) gROOT->FindObject("RecoEnergy_ND_NC");
01172     TH1D *hRecoEnergy_FD_NC = (TH1D*) gROOT->FindObject("RecoEnergy_FD_NC");
01173     TH2D *hRecoVsTrueEnergy_ND_NC = (TH2D*) gROOT->FindObject("RecoVsTrueEnergy_ND_NC");
01174     TH2D *hRecoVsTrueEnergy_FD_NC = (TH2D*) gROOT->FindObject("RecoVsTrueEnergy_FD_NC");
01175 
01176     TH2D* RecoVsTrueEnergy_NC_truly[ENCTruth::kNumTruths][2];
01177     for(int truth = 0; truth < ENCTruth::kNumTruths; ++truth){
01178       for(int det = 0; det <= 1; ++det){
01179         const TString detstr = det ? "FD" : "ND";
01180         const TString name = "RecoVsTrueEnergy_truly"+ENCTruth::truthNames[truth]+"_"+detstr+"_NC";
01181         RecoVsTrueEnergy_NC_truly[truth][det] = (TH2D*)gROOT->FindObject(name);
01182       }
01183     }
01184 
01185 
01186     TH1D* hCCContamination_FD =(TH1D*) gROOT->FindObject("CCContamination_FD");
01187     TH1D* hCCContamination_ND =(TH1D*) gROOT->FindObject("CCContamination_ND");
01188     TH2D* hCCContaminationRecoVsTrue_FD =(TH2D*) gROOT->FindObject("CCContaminationRecoVsTrue_FD");
01189     TH1D* hNCContamination_FD =(TH1D*) gROOT->FindObject("NCContamination_FD");
01190     TH1D* hNCContamination_ND =(TH1D*) gROOT->FindObject("NCContamination_ND");
01191     //get Matrix Method histograms (numubar CC):
01192     TH2D *hRecoVsTrueEnergyPQ_ND = (TH2D*) gROOT->FindObject("RecoVsTrueEnergyPQ_ND");
01193     TH2D *hRecoVsTrueEnergyPQ_FD = (TH2D*) gROOT->FindObject("RecoVsTrueEnergyPQ_FD");
01194     TH1D *hEfficiencyPQ_ND = (TH1D*) gROOT->FindObject("EfficiencyPQ_ND");
01195     TH1D *hEfficiencyPQ_FD = (TH1D*) gROOT->FindObject("EfficiencyPQ_FD");
01196     TH1D *hPurityPQ_ND = (TH1D*) gROOT->FindObject("PurityPQ_ND");
01197     TH1D *hPurityPQ_FD = (TH1D*) gROOT->FindObject("PurityPQ_FD");
01198     TH1D *hRecoEnergyAllEventsPQ_ND = (TH1D*) gROOT->FindObject("RecoEnergyAllEventsPQ_ND");
01199     TH1D *hRecoEnergyCCOnlyEventsPQ_ND = (TH1D*) gROOT->FindObject("RecoEnergyCCOnlyEventsPQ_ND");
01200     TH1D *hTrueEnergyCCOnlyEventsPQ_ND = (TH1D*) gROOT->FindObject("TrueEnergyCCOnlyEventsPQ_ND");
01201     TH1D *hTrueEnergyTrueCCFidEventsPQ_ND = (TH1D*) gROOT->FindObject("TrueEnergyTrueCCFidEventsPQ_ND");
01202     TH1D *hTrueEnergyTrueCCFidEventsPQ_FD = (TH1D*) gROOT->FindObject("TrueEnergyTrueCCFidEventsPQ_FD");
01203     TH1D *hTrueEnergyCCOnlyEventsPQ_FD = (TH1D*) gROOT->FindObject("TrueEnergyCCOnlyEventsPQ_FD");
01204     TH1D *hRecoEnergyCCOnlyEventsPQ_FD = (TH1D*) gROOT->FindObject("RecoEnergyCCOnlyEventsPQ_FD");
01205     TH1D *hRecoEnergyAllEventsPQ_FD = (TH1D*) gROOT->FindObject("RecoEnergyAllEventsPQ_FD");
01206     TH1D *hRecoEnergyPQ_ND = (TH1D*) gROOT->FindObject("RecoEnergyPQ_ND");
01207     TH1D *hRecoEnergyPQ_FD = (TH1D*) gROOT->FindObject("RecoEnergyPQ_FD");
01208     TH1D* hCCContaminationPQ_FD =(TH1D*) gROOT->FindObject("CCContaminationPQ_FD");
01209     TH1D* hCCContaminationPQ_ND =(TH1D*) gROOT->FindObject("CCContaminationPQ_ND");
01210     TH2D* hCCContaminationRecoVsTruePQ_FD =(TH2D*) gROOT->FindObject("CCContaminationRecoVsTruePQ_FD");
01211     TH1D* hNCContaminationPQ_FD =(TH1D*) gROOT->FindObject("NCContaminationPQ_FD");
01212     TH1D* hNCContaminationPQ_ND =(TH1D*) gROOT->FindObject("NCContaminationPQ_ND");
01213     //get Matrix Method histograms (Decay Pipe)
01214     TH1D* hTrueEnergyAllEventsPQ_ND =(TH1D*) gROOT->FindObject("TrueEnergyAllEventsPQ_ND");
01215     TH1D* hTrueEnergyAllEventsPQ_FD =(TH1D*) gROOT->FindObject("TrueEnergyAllEventsPQ_FD");
01216     TH1D* hTrueEnergyDecayPipePQ_ND =(TH1D*) gROOT->FindObject("TrueEnergyDecayPipePQ_ND");
01217     TH1D* hTrueEnergyDecayPipePQ_FD =(TH1D*) gROOT->FindObject("TrueEnergyDecayPipePQ_FD");
01218     //get Matrix Method histograms (numu + numubar CC):
01219     TH2D *hRecoVsTrueEnergyAll_ND = (TH2D*) gROOT->FindObject("RecoVsTrueEnergyAll_ND");
01220     TH2D *hRecoVsTrueEnergyAll_FD = (TH2D*) gROOT->FindObject("RecoVsTrueEnergyAll_FD");
01221     TH1D *hEfficiencyAll_ND = (TH1D*) gROOT->FindObject("EfficiencyAll_ND");
01222     TH1D *hEfficiencyAll_FD = (TH1D*) gROOT->FindObject("EfficiencyAll_FD");
01223     TH1D *hPurityAll_ND = (TH1D*) gROOT->FindObject("PurityAll_ND");
01224     TH1D *hPurityAll_FD = (TH1D*) gROOT->FindObject("PurityAll_FD");
01225     TH1D *hRecoEnergyAllEventsAll_ND = (TH1D*) gROOT->FindObject("RecoEnergyAllEventsAll_ND");
01226     TH1D *hRecoEnergyCCOnlyEventsAll_ND = (TH1D*) gROOT->FindObject("RecoEnergyCCOnlyEventsAll_ND");
01227     TH1D *hTrueEnergyCCOnlyEventsAll_ND = (TH1D*) gROOT->FindObject("TrueEnergyCCOnlyEventsAll_ND");
01228     TH1D *hTrueEnergyTrueCCFidEventsAll_ND = (TH1D*) gROOT->FindObject("TrueEnergyTrueCCFidEventsAll_ND");
01229     TH1D *hTrueEnergyTrueCCFidEventsAll_FD = (TH1D*) gROOT->FindObject("TrueEnergyTrueCCFidEventsAll_FD");
01230     TH1D *hTrueEnergyCCOnlyEventsAll_FD = (TH1D*) gROOT->FindObject("TrueEnergyCCOnlyEventsAll_FD");
01231     TH1D *hRecoEnergyCCOnlyEventsAll_FD = (TH1D*) gROOT->FindObject("RecoEnergyCCOnlyEventsAll_FD");
01232     TH1D *hRecoEnergyAllEventsAll_FD = (TH1D*) gROOT->FindObject("RecoEnergyAllEventsAll_FD");
01233     TH1D *hRecoEnergyAll_ND = (TH1D*) gROOT->FindObject("RecoEnergyAll_ND");
01234     TH1D *hRecoEnergyAll_FD = (TH1D*) gROOT->FindObject("RecoEnergyAll_FD");
01235     //get Matrix Method histograms (nutau CC):
01236     TH2D* hRecoVsTrueEnergyTau_FD = (TH2D*) gROOT->FindObject("RecoVsTrueEnergyTau_FD");
01237     TH1D* hEfficiencyTau_FD = (TH1D*) gROOT->FindObject("EfficiencyTau_FD");
01238     TH1D* hTrueEnergyTrueCCFidEventsTau_FD = (TH1D*) gROOT->FindObject("TrueEnergyTrueCCFidEventsTau_FD");
01239     TH1D* hTrueEnergyCCOnlyEventsTau_FD = (TH1D*) gROOT->FindObject("TrueEnergyCCOnlyEventsTau_FD");
01240     //get Matrix Method histograms (nutaubar CC):
01241     TH2D* hRecoVsTrueEnergyTauPQ_FD = (TH2D*) gROOT->FindObject("RecoVsTrueEnergyTauPQ_FD");
01242     TH1D* hEfficiencyTauPQ_FD = (TH1D*) gROOT->FindObject("EfficiencyTauPQ_FD");
01243     TH1D* hTrueEnergyTrueCCFidEventsTauPQ_FD = (TH1D*) gROOT->FindObject("TrueEnergyTrueCCFidEventsTauPQ_FD");
01244     TH1D* hTrueEnergyCCOnlyEventsTauPQ_FD = (TH1D*) gROOT->FindObject("TrueEnergyCCOnlyEventsTauPQ_FD");
01245     //get Matrix Method histograms (nutau CC):
01246     TH2D* hRecoVsTrueEnergyTauAll_FD = (TH2D*) gROOT->FindObject("RecoVsTrueEnergyTauAll_FD");
01247     TH1D* hEfficiencyTauAll_FD = (TH1D*) gROOT->FindObject("EfficiencyTauAll_FD");
01248     TH1D* hTrueEnergyTrueCCFidEventsTauAll_FD = (TH1D*) gROOT->FindObject("TrueEnergyTrueCCFidEventsTauAll_FD");
01249     TH1D* hTrueEnergyCCOnlyEventsTauAll_FD = (TH1D*) gROOT->FindObject("TrueEnergyCCOnlyEventsTauAll_FD");
01250 
01251     //check if histo found
01252     if (!hPottortgt) {
01253       MSG("NuDSTAna",Msg::kWarning) <<"hPottortgt does not exist in file:"<<endl;
01254       dirInput->Print();
01255       // There is not always an hPottortgt
01256       //continue;
01257     }
01258 
01259     //clone the histos for the first file
01260     if (!hPottortgtClone) {
01261       MSG("NuDSTAna",Msg::kInfo) << "Clone the histos for the first file" << endl;
01262 
01263       if (xmlConfig) {
01264         MSG("NuDSTAna",Msg::kInfo)<< "NuXMLConfig cloned from input file" << endl;
01265         xmlConfigClone = (NuXMLConfig*)xmlConfig->Clone("NuXMLConfigClone");
01266       }
01267       else {
01268         MSG("NuDSTAna",Msg::kInfo)
01269         <<"No NuXMLConfig object found in input"
01270         <<" file (not necessarily unexpected)" << endl;
01271 
01272       }
01273 
01274 
01275       hDetectorClone=(TH1F*)hDetector->Clone("hDetectorClone");
01276       hSimFlagClone=(TH1F*)hSimFlag->Clone("hSimFlagClone");
01277       hTrigSrcClone=(TH1F*)hTrigSrc->Clone("hTrigSrcClone");
01278       hSpillsPerFileClone=(TH1F*)hSpillsPerFile->Clone("hSpillsPerFileClone");
01279 
01280       if (hTotalPot) {
01281         hTotalPotClone=(TH1F*)hTotalPot->Clone("hTotalPotClone");
01282       }
01283 
01284       hPottortgtClone=(TH1F*)hPottortgt->Clone("hPottortgtClone");
01285       hPotBadtortgtClone=(TH1F*)hPotBadtortgt->Clone("hPotBadtortgtClone");
01286       hPottrtgtdClone=(TH1F*)hPottrtgtd->Clone("hPottrtgtdClone");
01287       hPotBadtrtgtdClone=(TH1F*)hPotBadtrtgtd->Clone("hPotBadtrtgtdClone");
01288       hPottor101Clone=(TH1F*)hPottor101->Clone("hPottor101Clone");
01289       hPotBadtor101Clone=(TH1F*)hPotBadtor101->Clone("hPotBadtor101Clone");
01290       hPottr101dClone=(TH1F*)hPottr101d->Clone("hPottr101dClone");
01291       hPotBadtr101dClone=(TH1F*)hPotBadtr101d->Clone("hPotBadtr101dClone");
01292       hRunClone=(TH1F*)hRun->Clone("hRunClone");
01293 
01294       Double_t earliestTime=2000000000;
01295       Double_t latestTime=0;
01296       if (hNtupleLatestTime) {
01297         hNtupleLatestTimeClone=(TH1F*)hNtupleLatestTime->Clone("hNtupleLatestTimeClone");
01298         hNtupleEarliestTimeClone=(TH1F*)hNtupleEarliestTime->Clone("hNtupleEarliestTimeClone");
01299 
01300         //get the times
01301         earliestTime=hNtupleEarliestTimeClone->Integral();
01302         latestTime=hNtupleLatestTimeClone->Integral();
01303         MSG("NuDSTAna",Msg::kInfo) <<"First histo: earliestTime="<<ffmt(earliestTime)
01304                                    <<", latestTime="<<ffmt(latestTime)<<endl;
01305       }
01306       else {//only run once
01307         MSG("NuDSTAna",Msg::kInfo) <<"DoIO: hNtupleLatestTime not found"<<endl;
01308 
01309       }
01310 
01311       //after and before are the same for the first file
01312       Float_t potBefore=hPottortgtClone->GetMean()*
01313             hPottortgtClone->GetEntries();
01314       Float_t potAfter=hPottortgtClone->GetMean()*
01315             hPottortgtClone->GetEntries();
01316       Float_t runBefore=hRunClone->GetEntries();
01317       Float_t runAfter=hRunClone->GetEntries();
01318       MSG("NuDSTAna",Msg::kInfo) <<"First histo: potBefore="<<potBefore*1e12
01319                                  <<", potAfter="<<potAfter*1e12<<endl;
01320       MSG("NuDSTAna",Msg::kInfo) <<"First histo: runBefore="<<runBefore
01321                                  <<", runAfter="<<runAfter<<endl;
01322 
01323       //check that MM histos exist
01324 
01325       if (!hRecoVsTrueEnergyPQ_FD) {
01326 
01327         MSG("NuDSTAna",Msg::kInfo) << "MM Histos not gettting cloned" << endl;
01328       }
01329       else {
01330         MSG("NuDSTAna",Msg::kInfo) << "Cloning MM histos" << endl;
01331         //clone the MM histograms (numu CC):
01332         hRecoVsTrueEnergy_NDClone = (TH2D*) hRecoVsTrueEnergy_ND->Clone("hRecoVsTrueEnergy_NDClone");
01333         hRecoVsTrueEnergy_FDClone = (TH2D*) hRecoVsTrueEnergy_FD->Clone("hRecoVsTrueEnergy_FDClone");
01334         hEfficiency_NDClone = (TH1D*) hEfficiency_ND->Clone("hEfficiency_NDClone");
01335         hEfficiency_FDClone = (TH1D*) hEfficiency_FD->Clone("hEfficiency_FDClone");
01336         hPurity_NDClone = (TH1D*) hPurity_ND->Clone("hPurity_NDClone");
01337         hPurity_FDClone = (TH1D*) hPurity_FD->Clone("hPurity_FDClone");
01338         hRecoEnergyAllEvents_NDClone = (TH1D*) hRecoEnergyAllEvents_ND->Clone("hRecoEnergyAllEvents_NDClone");
01339         hRecoEnergyCCOnlyEvents_NDClone = (TH1D*) hRecoEnergyCCOnlyEvents_ND->Clone("hRecoEnergyCCOnlyEvents_NDClone");
01340         hTrueEnergyCCOnlyEvents_NDClone = (TH1D*) hTrueEnergyCCOnlyEvents_ND->Clone("hTrueEnergyCCOnlyEvents_NDClone");
01341 
01342         if (hTrueEnergyTrueCCFidEvents_ND){
01343           hTrueEnergyTrueCCFidEvents_NDClone =
01344             (TH1D*) hTrueEnergyTrueCCFidEvents_ND->
01345             Clone("hTrueEnergyTrueCCFidEvents_NDClone");
01346         }
01347 
01348         if (hTrueEnergyTrueCCFidEvents_FD){
01349           hTrueEnergyTrueCCFidEvents_FDClone = (TH1D*) hTrueEnergyTrueCCFidEvents_FD->Clone("hTrueEnergyTrueCCFidEvents_FDClone");
01350         }
01351 
01352         hTrueEnergyCCOnlyEvents_FDClone = (TH1D*) hTrueEnergyCCOnlyEvents_FD->Clone("hTrueEnergyCCOnlyEvents_FDClone");
01353         hRecoEnergyCCOnlyEvents_FDClone = (TH1D*) hRecoEnergyCCOnlyEvents_FD->Clone("hRecoEnergyCCOnlyEvents_FDClone");
01354         hRecoEnergyAllEvents_FDClone = (TH1D*) hRecoEnergyAllEvents_FD->Clone("hRecoEnergyAllEvents_FDClone");
01355         hRecoEnergy_NDClone = (TH1D*) hRecoEnergy_ND->Clone("hRecoEnergy_NDClone");
01356         hRecoEnergy_FDClone = (TH1D*) hRecoEnergy_FD->Clone("hRecoEnergy_FDClone");
01357         if (hRecoEnergy_ND_NC){
01358           hRecoEnergy_ND_NCClone = (TH1D*) hRecoEnergy_ND_NC->Clone("hRecoEnergy_ND_NCClone");
01359         }
01360         if (hRecoEnergy_FD_NC){
01361           hRecoEnergy_FD_NCClone = (TH1D*) hRecoEnergy_FD_NC->Clone("hRecoEnergy_FD_NCClone");
01362         }
01363         if (hRecoVsTrueEnergy_ND_NC){
01364           hRecoVsTrueEnergy_ND_NCClone= (TH2D*) hRecoVsTrueEnergy_ND_NC->Clone("hRecoVsTrueEnergy_ND_NCClone");
01365         }
01366         if (hRecoVsTrueEnergy_FD_NC){
01367           hRecoVsTrueEnergy_FD_NCClone= (TH2D*) hRecoVsTrueEnergy_FD_NC->Clone("hRecoVsTrueEnergy_FD_NCClone");
01368         }
01369 
01370         for(int truth = 0; truth < ENCTruth::kNumTruths; ++truth){
01371           for(int det = 0; det <= 1; ++det){
01372             const TString detstr = det ? "FD" : "ND";
01373             if (RecoVsTrueEnergy_NC_truly[truth][det]){
01374               hRecoVsTrueEnergy_NCClone_truly[truth][det] = (TH2D*)RecoVsTrueEnergy_NC_truly[truth][det]->Clone("RecoVsTrueEnergy_truly"+ENCTruth::truthNames[truth]+"_"+detstr+"_NC");
01375             }
01376           }
01377         }
01378 
01379         if (hCCContamination_FD){
01380           hCCContamination_FDClone = (TH1D*) hCCContamination_FD->Clone("hCCContamination_FDClone");
01381           if (hCCContaminationRecoVsTrue_FD){
01382             hCCContaminationRecoVsTrue_FDClone = (TH2D*) hCCContaminationRecoVsTrue_FD->Clone("hCCContaminationRecoVsTrue_FDClone");
01383           }
01384           hNCContamination_FDClone = (TH1D*) hNCContamination_FD->Clone("hNCContamination_FDClone");
01385         }
01386 
01387         if (hCCContamination_ND){
01388           hCCContamination_NDClone = (TH1D*) hCCContamination_ND->Clone("hCCContamination_NDClone");
01389         }
01390         if (hNCContamination_ND){
01391           hNCContamination_NDClone = (TH1D*) hNCContamination_ND->Clone("hNCContamination_NDClone");
01392         }
01393 
01394         //clone the MM histograms (numubar CC):
01395         hRecoVsTrueEnergyPQ_NDClone = (TH2D*) hRecoVsTrueEnergyPQ_ND->Clone("hRecoVsTrueEnergyPQ_NDClone");
01396         hRecoVsTrueEnergyPQ_FDClone = (TH2D*) hRecoVsTrueEnergyPQ_FD->Clone("hRecoVsTrueEnergyPQ_FDClone");
01397         hEfficiencyPQ_NDClone = (TH1D*) hEfficiencyPQ_ND->Clone("hEfficiencyPQ_NDClone");
01398         hEfficiencyPQ_FDClone = (TH1D*) hEfficiencyPQ_FD->Clone("hEfficiencyPQ_FDClone");
01399         hPurityPQ_NDClone = (TH1D*) hPurityPQ_ND->Clone("hPurityPQ_NDClone");
01400         hPurityPQ_FDClone = (TH1D*) hPurityPQ_FD->Clone("hPurityPQ_FDClone");
01401         hRecoEnergyAllEventsPQ_NDClone = (TH1D*) hRecoEnergyAllEventsPQ_ND->Clone("hRecoEnergyAllEventsPQ_NDClone");
01402         hRecoEnergyCCOnlyEventsPQ_NDClone = (TH1D*) hRecoEnergyCCOnlyEventsPQ_ND->Clone("hRecoEnergyCCOnlyEventsPQ_NDClone");
01403         hTrueEnergyCCOnlyEventsPQ_NDClone = (TH1D*) hTrueEnergyCCOnlyEventsPQ_ND->Clone("hTrueEnergyCCOnlyEventsPQ_NDClone");
01404 
01405         if (hTrueEnergyTrueCCFidEventsPQ_ND){
01406           hTrueEnergyTrueCCFidEventsPQ_NDClone = (TH1D*) hTrueEnergyTrueCCFidEventsPQ_ND->Clone("hTrueEnergyTrueCCFidEventsPQ_NDClone");
01407         }
01408         if (hTrueEnergyTrueCCFidEventsPQ_FD){
01409           hTrueEnergyTrueCCFidEventsPQ_FDClone = (TH1D*) hTrueEnergyTrueCCFidEventsPQ_FD->Clone("hTrueEnergyTrueCCFidEventsPQ_FDClone");
01410         }
01411 
01412         hTrueEnergyCCOnlyEventsPQ_FDClone = (TH1D*) hTrueEnergyCCOnlyEventsPQ_FD->Clone("hTrueEnergyCCOnlyEventsPQ_FDClone");
01413         hRecoEnergyCCOnlyEventsPQ_FDClone = (TH1D*) hRecoEnergyCCOnlyEventsPQ_FD->Clone("hRecoEnergyCCOnlyEventsPQ_FDClone");
01414         hRecoEnergyAllEventsPQ_FDClone = (TH1D*) hRecoEnergyAllEventsPQ_FD->Clone("hRecoEnergyAllEventsPQ_FDClone");
01415         hRecoEnergyPQ_NDClone = (TH1D*) hRecoEnergyPQ_ND->Clone("hRecoEnergyPQ_NDClone");
01416         hRecoEnergyPQ_FDClone = (TH1D*) hRecoEnergyPQ_FD->Clone("hRecoEnergyPQ_FDClone");
01417         if (hCCContaminationPQ_FD){
01418           hCCContaminationPQ_FDClone =
01419             (TH1D*) hCCContaminationPQ_FD->        Clone("hCCContaminationPQ_FDClone");
01420           if (hCCContaminationRecoVsTruePQ_FD){
01421             hCCContaminationRecoVsTruePQ_FDClone =
01422 
01423               (TH2D*) hCCContaminationRecoVsTruePQ_FD->Clone("hCCContaminationRecoVsTruePQ_FDClone");
01424           }
01425           hNCContaminationPQ_FDClone =(TH1D*) hNCContaminationPQ_FD->Clone("hNCContaminationPQ_FDClone");
01426         }
01427         if (hCCContaminationPQ_ND){
01428           hCCContaminationPQ_NDClone = (TH1D*) hCCContaminationPQ_ND->Clone("hCCContaminationPQ_NDClone");
01429         }
01430         if (hNCContaminationPQ_ND){
01431           hNCContaminationPQ_NDClone = (TH1D*) hNCContaminationPQ_ND->Clone("hNCContaminationPQ_NDClone");
01432         }
01433         //clone the MM histograms (Decay Pipe)
01434         if (hTrueEnergyAllEventsPQ_ND){
01435           hTrueEnergyAllEventsPQ_NDClone = (TH1D*) hTrueEnergyAllEventsPQ_ND->Clone("hTrueEnergyAllEventsPQ_NDClone");
01436         }
01437         if (hTrueEnergyAllEventsPQ_FD){
01438           hTrueEnergyAllEventsPQ_FDClone = (TH1D*) hTrueEnergyAllEventsPQ_FD->Clone("hTrueEnergyAllEventsPQ_FDClone");
01439         }
01440         if (hTrueEnergyDecayPipePQ_ND){
01441           hTrueEnergyDecayPipePQ_NDClone = (TH1D*) hTrueEnergyDecayPipePQ_ND->Clone("hTrueEnergyDecayPipePQ_NDClone");
01442         }
01443         if (hTrueEnergyDecayPipePQ_FD){
01444           hTrueEnergyDecayPipePQ_FDClone = (TH1D*) hTrueEnergyDecayPipePQ_FD->Clone("hTrueEnergyDecayPipePQ_FDClone");
01445         }
01446         //clone the MM histograms (numu + numubar CC):
01447         hRecoVsTrueEnergyAll_NDClone = (TH2D*) hRecoVsTrueEnergyAll_ND->Clone("hRecoVsTrueEnergyAll_NDClone");
01448         hRecoVsTrueEnergyAll_FDClone = (TH2D*) hRecoVsTrueEnergyAll_FD->Clone("hRecoVsTrueEnergyAll_FDClone");
01449         hEfficiencyAll_NDClone = (TH1D*) hEfficiencyAll_ND->Clone("hEfficiencyAll_NDClone");
01450         hEfficiencyAll_FDClone = (TH1D*) hEfficiencyAll_FD->Clone("hEfficiencyAll_FDClone");
01451         hPurityAll_NDClone = (TH1D*) hPurityAll_ND->Clone("hPurityAll_NDClone");
01452         hPurityAll_FDClone = (TH1D*) hPurityAll_FD->Clone("hPurityAll_FDClone");
01453         hRecoEnergyAllEventsAll_NDClone = (TH1D*) hRecoEnergyAllEventsAll_ND->Clone("hRecoEnergyAllEventsAll_NDClone");
01454         hRecoEnergyCCOnlyEventsAll_NDClone = (TH1D*) hRecoEnergyCCOnlyEventsAll_ND->Clone("hRecoEnergyCCOnlyEventsAll_NDClone");
01455         hTrueEnergyCCOnlyEventsAll_NDClone = (TH1D*) hTrueEnergyCCOnlyEventsAll_ND->Clone("hTrueEnergyCCOnlyEventsAll_NDClone");
01456 
01457         if (hTrueEnergyTrueCCFidEventsAll_ND){
01458           hTrueEnergyTrueCCFidEventsAll_NDClone = (TH1D*) hTrueEnergyTrueCCFidEventsAll_ND->Clone("hTrueEnergyTrueCCFidEventsAll_NDClone");
01459         }
01460         if (hTrueEnergyTrueCCFidEventsAll_FD){
01461           hTrueEnergyTrueCCFidEventsAll_FDClone = (TH1D*) hTrueEnergyTrueCCFidEventsAll_FD->Clone("hTrueEnergyTrueCCFidEventsAll_FDClone");
01462         }
01463 
01464         hTrueEnergyCCOnlyEventsAll_FDClone = (TH1D*) hTrueEnergyCCOnlyEventsAll_FD->Clone("hTrueEnergyCCOnlyEventsAll_FDClone");
01465         hRecoEnergyCCOnlyEventsAll_FDClone = (TH1D*) hRecoEnergyCCOnlyEventsAll_FD->Clone("hRecoEnergyCCOnlyEventsAll_FDClone");
01466         hRecoEnergyAllEventsAll_FDClone = (TH1D*) hRecoEnergyAllEventsAll_FD->Clone("hRecoEnergyAllEventsAll_FDClone");
01467         hRecoEnergyAll_NDClone = (TH1D*) hRecoEnergyAll_ND->Clone("hRecoEnergyAll_NDClone");
01468         hRecoEnergyAll_FDClone = (TH1D*) hRecoEnergyAll_FD->Clone("hRecoEnergyAll_FDClone");
01469         //Clone the taus:
01470         if (hEfficiencyTau_FD){
01471           hEfficiencyTau_FDClone = (TH1D*) hEfficiencyTau_FD->Clone("hEfficiencyTau_FDClone");
01472         }
01473         if (hRecoVsTrueEnergyTau_FD){
01474           hRecoVsTrueEnergyTau_FDClone = (TH2D*) hRecoVsTrueEnergyTau_FD->Clone("hRecoVsTrueEnergyTau_FDClone");
01475             }
01476         if (hTrueEnergyTrueCCFidEventsTau_FD){
01477           hTrueEnergyTrueCCFidEventsTau_FDClone = (TH1D*) hTrueEnergyTrueCCFidEventsTau_FD->Clone("hTrueEnergyTrueCCFidEventsTau_FDClone");
01478         }
01479         if (hTrueEnergyCCOnlyEventsTau_FD){
01480           hTrueEnergyCCOnlyEventsTau_FDClone = (TH1D*) hTrueEnergyCCOnlyEventsTau_FD->Clone("hTrueEnergyCCOnlyEventsTau_FDClone");
01481         }
01482         //Clone the taubars:
01483         if (hEfficiencyTauPQ_FD){
01484           hEfficiencyTauPQ_FDClone = (TH1D*) hEfficiencyTauPQ_FD->Clone("hEfficiencyTauPQ_FDClone");
01485         }
01486         if (hRecoVsTrueEnergyTauPQ_FD){
01487           hRecoVsTrueEnergyTauPQ_FDClone = (TH2D*) hRecoVsTrueEnergyTauPQ_FD->Clone("hRecoVsTrueEnergyTauPQ_FDClone");
01488             }
01489         if (hTrueEnergyTrueCCFidEventsTauPQ_FD){
01490           hTrueEnergyTrueCCFidEventsTauPQ_FDClone = (TH1D*) hTrueEnergyTrueCCFidEventsTauPQ_FD->Clone("hTrueEnergyTrueCCFidEventsTauPQ_FDClone");
01491         }
01492         if (hTrueEnergyCCOnlyEventsTauPQ_FD){
01493           hTrueEnergyCCOnlyEventsTauPQ_FDClone = (TH1D*) hTrueEnergyCCOnlyEventsTauPQ_FD->Clone("hTrueEnergyCCOnlyEventsTauPQ_FDClone");
01494         }
01495         //Clone the taus + taubars:
01496         if (hEfficiencyTauAll_FD){
01497           hEfficiencyTauAll_FDClone = (TH1D*) hEfficiencyTauAll_FD->Clone("hEfficiencyTauAll_FDClone");
01498         }
01499         if (hRecoVsTrueEnergyTauAll_FD){
01500           hRecoVsTrueEnergyTauAll_FDClone = (TH2D*) hRecoVsTrueEnergyTauAll_FD->Clone("hRecoVsTrueEnergyTauAll_FDClone");
01501             }
01502         if (hTrueEnergyTrueCCFidEventsTauAll_FD){
01503           hTrueEnergyTrueCCFidEventsTauAll_FDClone = (TH1D*) hTrueEnergyTrueCCFidEventsTauAll_FD->Clone("hTrueEnergyTrueCCFidEventsTauAll_FDClone");
01504         }
01505         if (hTrueEnergyCCOnlyEventsTauAll_FD){
01506           hTrueEnergyCCOnlyEventsTauAll_FDClone = (TH1D*) hTrueEnergyCCOnlyEventsTauAll_FD->Clone("hTrueEnergyCCOnlyEventsTauAll_FDClone");
01507         }
01508       }
01509     }
01510     else {//for second file onwards add the new histo to the clone
01511       MSG("NuDSTAna",Msg::kInfo) << "Adding up pots for later files" << endl;
01512       Float_t potBefore=hPottortgtClone->GetMean()*
01513             hPottortgtClone->GetEntries();
01514       Float_t potNew=hPottortgt->GetMean()*hPottortgt->GetEntries();
01515       Float_t runBefore=hRunClone->GetEntries();
01516 
01517       if (hNtupleLatestTime && hNtupleLatestTimeClone) {
01518         Double_t earliestTime=2000000000;
01519         Double_t latestTime=0;
01520         Double_t newEarliestTime=2000000000;
01521         Double_t newLatestTime=0;
01522         //get the times from clone
01523         earliestTime=hNtupleEarliestTimeClone->Integral();
01524         latestTime=hNtupleLatestTimeClone->Integral();
01525 
01526         //get the next set of times
01527         newEarliestTime=hNtupleEarliestTime->Integral();
01528         newLatestTime=hNtupleLatestTime->Integral();
01529 
01530         MAXMSG("NuDSTAna",Msg::kInfo,5)
01531           <<"Previous file(s): earliestTime="<<ffmt(earliestTime)
01532           <<", latestTime="<<ffmt(latestTime)<<endl
01533           <<"This file:        earliestTime="<<ffmt(newEarliestTime)
01534           <<", latestTime="<<ffmt(newLatestTime)<<endl;
01535 
01536         //work out which time is the earliest/latest
01537         if (newEarliestTime<earliestTime) {
01538           Float_t oldT=earliestTime;
01539           earliestTime=newEarliestTime;
01540           hNtupleEarliestTimeClone->Reset("ICE");
01541           hNtupleEarliestTimeClone->Fill(1,earliestTime);
01542           MSG("NuDSTAna",Msg::kInfo)
01543             <<"Using new earliestTime="<<ffmt(earliestTime)
01544             <<" (was "<<ffmt(oldT)<<")"<<endl;
01545         }
01546         if (newLatestTime>latestTime) {
01547           Float_t oldT=latestTime;
01548           latestTime=newLatestTime;
01549           hNtupleLatestTimeClone->Reset("ICE");
01550           hNtupleLatestTimeClone->Fill(1,latestTime);
01551           MSG("NuDSTAna",Msg::kInfo)
01552             <<"Using new latestTime="<<ffmt(latestTime)
01553             <<" (was "<<ffmt(oldT)<<")"<<endl;
01554         }
01555       }
01556       else {
01557         MAXMSG("NuDSTAna",Msg::kInfo,3)
01558           <<"DoIO: Next file hNtupleLatestTime not found"<<endl;
01559       }
01560 
01562       //add the histos up
01563 
01564       //don't need to do this for
01565       //hDetectorClone
01566       //hSimFlagClone
01567       //hTrigSrcClone
01568       //hSpillsPerFileClone
01569 
01570       if (hTotalPotClone) hTotalPotClone->Add(hTotalPot);
01571 
01572       hPottortgtClone->Add(hPottortgt);
01573       hPotBadtortgtClone->Add(hPotBadtortgt);
01574       hPottrtgtdClone->Add(hPottrtgtd);
01575       hPotBadtrtgtdClone->Add(hPotBadtrtgtd);
01576       hPottor101Clone->Add(hPottor101);
01577       hPotBadtor101Clone->Add(hPotBadtor101);
01578       hPottr101dClone->Add(hPottr101d);
01579       hPotBadtr101dClone->Add(hPotBadtr101d);
01580       hRunClone->Add(hRun);
01581 
01582       Float_t potAfter=hPottortgtClone->GetMean()*
01583             hPottortgtClone->GetEntries();
01584       Float_t runAfter=hRunClone->GetEntries();
01585 
01586       MSG("NuDSTAna",Msg::kInfo)
01587             <<"Adding histos: potBefore="<<potBefore*1e12
01588             <<", potAfter="<<potAfter*1e12
01589             <<", potNew="<<potNew*1e12<<endl;
01590       MSG("NuDSTAna",Msg::kInfo)
01591             <<"Adding histos: runsBefore="<<runBefore
01592             <<", runsAfter="<<runAfter<<endl;
01593 
01594       //Add the MM histograms up (if they exist) (numu CC):
01595       if (hRecoVsTrueEnergyPQ_FDClone) {
01596         MSG("NuDSTAna",Msg::kInfo) << "Adding to MM histos" << endl;
01597 
01598         hRecoVsTrueEnergy_NDClone->Add(hRecoVsTrueEnergy_ND);
01599         hRecoVsTrueEnergy_FDClone->Add(hRecoVsTrueEnergy_FD);
01600         hEfficiency_NDClone->Add(hEfficiency_ND);
01601         hEfficiency_FDClone->Add(hEfficiency_FD);
01602         hPurity_NDClone->Add(hPurity_ND);
01603         hPurity_FDClone->Add(hPurity_FD);
01604         hRecoEnergyAllEvents_NDClone->Add(hRecoEnergyAllEvents_ND);
01605         hRecoEnergyCCOnlyEvents_NDClone->Add(hRecoEnergyCCOnlyEvents_ND);
01606         hTrueEnergyCCOnlyEvents_NDClone->Add(hTrueEnergyCCOnlyEvents_ND);
01607 
01608         if (hTrueEnergyTrueCCFidEvents_NDClone){
01609           hTrueEnergyTrueCCFidEvents_NDClone->Add(hTrueEnergyTrueCCFidEvents_ND);
01610         }
01611         if (hTrueEnergyTrueCCFidEvents_FDClone){
01612           hTrueEnergyTrueCCFidEvents_FDClone->Add(hTrueEnergyTrueCCFidEvents_FD);
01613         }
01614 
01615         hTrueEnergyCCOnlyEvents_FDClone->Add(hTrueEnergyCCOnlyEvents_FD);
01616         hRecoEnergyCCOnlyEvents_FDClone->Add(hRecoEnergyCCOnlyEvents_FD);
01617         hRecoEnergyAllEvents_FDClone->Add(hRecoEnergyAllEvents_FD);
01618         hRecoEnergy_NDClone->Add(hRecoEnergy_ND);
01619         hRecoEnergy_FDClone->Add(hRecoEnergy_FD);
01620         if (hRecoEnergy_ND_NCClone){
01621           hRecoEnergy_ND_NCClone->Add(hRecoEnergy_ND_NC);
01622         }
01623         if (hRecoEnergy_FD_NCClone){
01624           hRecoEnergy_FD_NCClone->Add(hRecoEnergy_FD_NC);
01625         }
01626         if (hRecoVsTrueEnergy_ND_NCClone){
01627           hRecoVsTrueEnergy_ND_NCClone->Add(hRecoVsTrueEnergy_ND_NC);
01628         }
01629         if (hRecoVsTrueEnergy_ND_NCClone){
01630           hRecoVsTrueEnergy_FD_NCClone->Add(hRecoVsTrueEnergy_FD_NC);
01631         }
01632 
01633         for(int truth = 0; truth < ENCTruth::kNumTruths; ++truth){
01634           for(int det = 0; det <= 1; ++det){
01635             if (hRecoVsTrueEnergy_NCClone_truly[truth][det]){
01636               hRecoVsTrueEnergy_NCClone_truly[truth][det]->
01637                 Add(RecoVsTrueEnergy_NC_truly[truth][det]);
01638             }
01639           }
01640         }
01641 
01642         if (hCCContamination_FDClone){
01643           hCCContamination_FDClone->Add(hCCContamination_FD);
01644           if (hCCContaminationRecoVsTrue_FDClone){
01645             hCCContaminationRecoVsTrue_FDClone->Add(hCCContaminationRecoVsTrue_FD);
01646           }
01647           hNCContamination_FDClone->Add(hNCContamination_FD);
01648           if (hCCContamination_NDClone){
01649             hCCContamination_NDClone->Add(hCCContamination_ND);
01650           }
01651           if (hNCContamination_NDClone){
01652             hNCContamination_NDClone->Add(hNCContamination_ND);
01653           }
01654         }
01655         //Add the MM histograms up (Decay Pipe):
01656         if(hTrueEnergyAllEventsPQ_NDClone) {
01657           hTrueEnergyAllEventsPQ_NDClone->Add(hTrueEnergyAllEventsPQ_ND);
01658         }
01659         if(hTrueEnergyAllEventsPQ_FDClone) {
01660           hTrueEnergyAllEventsPQ_FDClone->Add(hTrueEnergyAllEventsPQ_FD);
01661         }
01662         if(hTrueEnergyDecayPipePQ_NDClone) {
01663           hTrueEnergyDecayPipePQ_NDClone->Add(hTrueEnergyDecayPipePQ_ND);
01664         }
01665         if(hTrueEnergyDecayPipePQ_FDClone) {
01666           hTrueEnergyDecayPipePQ_FDClone->Add(hTrueEnergyDecayPipePQ_FD);
01667         }
01668         //Add the MM histograms up (numubar CC):
01669         hRecoVsTrueEnergyPQ_NDClone->Add(hRecoVsTrueEnergyPQ_ND);
01670         hRecoVsTrueEnergyPQ_FDClone->Add(hRecoVsTrueEnergyPQ_FD);
01671         hEfficiencyPQ_NDClone->Add(hEfficiencyPQ_ND);
01672         hEfficiencyPQ_FDClone->Add(hEfficiencyPQ_FD);
01673         hPurityPQ_NDClone->Add(hPurityPQ_ND);
01674         hPurityPQ_FDClone->Add(hPurityPQ_FD);
01675         hRecoEnergyAllEventsPQ_NDClone->Add(hRecoEnergyAllEventsPQ_ND);
01676         hRecoEnergyCCOnlyEventsPQ_NDClone->Add(hRecoEnergyCCOnlyEventsPQ_ND);
01677         hTrueEnergyCCOnlyEventsPQ_NDClone->Add(hTrueEnergyCCOnlyEventsPQ_ND);
01678 
01679         if (hTrueEnergyTrueCCFidEventsPQ_NDClone){
01680           hTrueEnergyTrueCCFidEventsPQ_NDClone->Add(hTrueEnergyTrueCCFidEventsPQ_ND);
01681         }
01682         if (hTrueEnergyTrueCCFidEventsPQ_FDClone){
01683           hTrueEnergyTrueCCFidEventsPQ_FDClone->Add(hTrueEnergyTrueCCFidEventsPQ_FD);
01684         }
01685 
01686         hTrueEnergyCCOnlyEventsPQ_FDClone->Add(hTrueEnergyCCOnlyEventsPQ_FD);
01687         hRecoEnergyCCOnlyEventsPQ_FDClone->Add(hRecoEnergyCCOnlyEventsPQ_FD);
01688         hRecoEnergyAllEventsPQ_FDClone->Add(hRecoEnergyAllEventsPQ_FD);
01689         hRecoEnergyPQ_NDClone->Add(hRecoEnergyPQ_ND);
01690         hRecoEnergyPQ_FDClone->Add(hRecoEnergyPQ_FD);
01691         if (hCCContaminationPQ_FDClone){
01692           hCCContaminationPQ_FDClone->Add(hCCContaminationPQ_FD);
01693           if (hCCContaminationRecoVsTruePQ_FDClone){
01694             hCCContaminationRecoVsTruePQ_FDClone->Add(hCCContaminationRecoVsTruePQ_FD);
01695           }
01696           hNCContaminationPQ_FDClone->Add(hNCContaminationPQ_FD);
01697           if (hCCContaminationPQ_NDClone){
01698             hCCContaminationPQ_NDClone->
01699               Add(hCCContaminationPQ_ND);
01700           }
01701           if (hNCContaminationPQ_NDClone){
01702             hNCContaminationPQ_NDClone->
01703               Add(hNCContaminationPQ_ND);
01704           }
01705         }
01706         //Add the MM histograms up (numu + numubar CC):
01707         hRecoVsTrueEnergyAll_NDClone->Add(hRecoVsTrueEnergyAll_ND);
01708         hRecoVsTrueEnergyAll_FDClone->Add(hRecoVsTrueEnergyAll_FD);
01709         hEfficiencyAll_NDClone->Add(hEfficiencyAll_ND);
01710         hEfficiencyAll_FDClone->Add(hEfficiencyAll_FD);
01711         hPurityAll_NDClone->Add(hPurityAll_ND);
01712         hPurityAll_FDClone->Add(hPurityAll_FD);
01713         hRecoEnergyAllEventsAll_NDClone->Add(hRecoEnergyAllEventsAll_ND);
01714         hRecoEnergyCCOnlyEventsAll_NDClone->Add(hRecoEnergyCCOnlyEventsAll_ND);
01715         hTrueEnergyCCOnlyEventsAll_NDClone->Add(hTrueEnergyCCOnlyEventsAll_ND);
01716 
01717         if (hTrueEnergyTrueCCFidEventsAll_NDClone){
01718           hTrueEnergyTrueCCFidEventsAll_NDClone->Add(hTrueEnergyTrueCCFidEventsAll_ND);
01719         }
01720         if (hTrueEnergyTrueCCFidEventsAll_FDClone){
01721           hTrueEnergyTrueCCFidEventsAll_FDClone->Add(hTrueEnergyTrueCCFidEventsAll_FD);
01722         }
01723 
01724         hTrueEnergyCCOnlyEventsAll_FDClone->Add(hTrueEnergyCCOnlyEventsAll_FD);
01725         hRecoEnergyCCOnlyEventsAll_FDClone->Add(hRecoEnergyCCOnlyEventsAll_FD);
01726         hRecoEnergyAllEventsAll_FDClone->Add(hRecoEnergyAllEventsAll_FD);
01727         hRecoEnergyAll_NDClone->Add(hRecoEnergyAll_ND);
01728         hRecoEnergyAll_FDClone->Add(hRecoEnergyAll_FD);
01729         //Add the MM histograms up (nutau CC):
01730         if (hRecoVsTrueEnergyTau_FDClone){
01731           hRecoVsTrueEnergyTau_FDClone->Add(hRecoVsTrueEnergyTau_FD);
01732         }
01733         if (hEfficiencyTau_FDClone){
01734           hEfficiencyTau_FDClone->Add(hEfficiencyTau_FD);
01735         }
01736         if (hTrueEnergyTrueCCFidEventsTau_FDClone){
01737           hTrueEnergyTrueCCFidEventsTau_FDClone->Add(hTrueEnergyTrueCCFidEventsTau_FD);
01738         }
01739         if (hTrueEnergyCCOnlyEventsTau_FDClone){
01740           hTrueEnergyCCOnlyEventsTau_FDClone->Add(hTrueEnergyCCOnlyEventsTau_FD);
01741         }
01742         //Add the MM histograms up (nutaubar CC):
01743         if (hRecoVsTrueEnergyTauPQ_FDClone){
01744           hRecoVsTrueEnergyTauPQ_FDClone->Add(hRecoVsTrueEnergyTauPQ_FD);
01745         }
01746         if (hEfficiencyTauPQ_FDClone){
01747           hEfficiencyTauPQ_FDClone->Add(hEfficiencyTauPQ_FD);
01748         }
01749         if (hTrueEnergyTrueCCFidEventsTauPQ_FDClone){
01750           hTrueEnergyTrueCCFidEventsTauPQ_FDClone->Add(hTrueEnergyTrueCCFidEventsTauPQ_FD);
01751         }
01752         if (hTrueEnergyCCOnlyEventsTauPQ_FDClone){
01753           hTrueEnergyCCOnlyEventsTauPQ_FDClone->Add(hTrueEnergyCCOnlyEventsTauPQ_FD);
01754         }
01755         //Add the MM histograms up (nutau + nutaubar CC):
01756         if (hRecoVsTrueEnergyTauAll_FDClone){
01757           hRecoVsTrueEnergyTauAll_FDClone->Add(hRecoVsTrueEnergyTauAll_FD);
01758         }
01759         if (hEfficiencyTauAll_FDClone){
01760           hEfficiencyTauAll_FDClone->Add(hEfficiencyTauAll_FD);
01761         }
01762         if (hTrueEnergyTrueCCFidEventsTauAll_FDClone){
01763           hTrueEnergyTrueCCFidEventsTauAll_FDClone->Add(hTrueEnergyTrueCCFidEventsTauAll_FD);
01764         }
01765         if (hTrueEnergyCCOnlyEventsTauAll_FDClone){
01766           hTrueEnergyCCOnlyEventsTauAll_FDClone->Add(hTrueEnergyCCOnlyEventsTauAll_FD);
01767         }
01768       }
01769     }
01770   }
01771   //Normalise the ND reco v. true CC matrix (if exists)
01772   if (hRecoVsTrueEnergyPQ_FDClone) {
01773     MSG("NuDSTAna",Msg::kInfo) << "Doing MM Normalization" << endl;
01774     for(int i=1;i<=hRecoVsTrueEnergy_NDClone->GetNbinsX();i++){
01775       //loop over true bins
01776       for(int j=1;j<=hRecoVsTrueEnergy_NDClone->GetNbinsY()+1;j++){
01777         //loop over reco bins
01778         if(hRecoEnergyCCOnlyEvents_NDClone->GetBinContent(j)>0 &&
01779            hRecoVsTrueEnergy_NDClone->GetBinContent(i,j)>0) {
01780           Float_t error=(hRecoVsTrueEnergy_NDClone->GetBinError(i,j)/
01781                          hRecoVsTrueEnergy_NDClone->GetBinContent(i,j));
01782 
01783           hRecoVsTrueEnergy_NDClone->SetBinContent
01784             (i,j,hRecoVsTrueEnergy_NDClone->GetBinContent(i,j)/
01785              hRecoEnergyCCOnlyEvents_NDClone->GetBinContent(j));
01786 
01787           hRecoVsTrueEnergy_NDClone->SetBinError
01788             (i,j,error*hRecoVsTrueEnergy_NDClone->GetBinContent(i,j));
01789         }
01790         else {
01791           hRecoVsTrueEnergy_NDClone->SetBinContent(i,j,0);
01792           hRecoVsTrueEnergy_NDClone->SetBinError(i,j,0);
01793         }
01794       }
01795     }
01796     //(numubar CC):
01797     for(int i=1;i<=hRecoVsTrueEnergyPQ_NDClone->GetNbinsX();i++){
01798       //loop over true bins
01799       for(int j=1;j<=hRecoVsTrueEnergyPQ_NDClone->GetNbinsY()+1;j++){
01800         //loop over reco bins
01801         if(hRecoEnergyCCOnlyEventsPQ_NDClone->GetBinContent(j)>0 &&
01802            hRecoVsTrueEnergyPQ_NDClone->GetBinContent(i,j)>0) {
01803           Float_t error=(hRecoVsTrueEnergyPQ_NDClone->GetBinError(i,j)/
01804                          hRecoVsTrueEnergyPQ_NDClone->GetBinContent(i,j));
01805 
01806           hRecoVsTrueEnergyPQ_NDClone->SetBinContent
01807             (i,j,hRecoVsTrueEnergyPQ_NDClone->GetBinContent(i,j)/
01808              hRecoEnergyCCOnlyEventsPQ_NDClone->GetBinContent(j));
01809 
01810           hRecoVsTrueEnergyPQ_NDClone->SetBinError
01811             (i,j,error*hRecoVsTrueEnergyPQ_NDClone->GetBinContent(i,j));
01812         }
01813         else {
01814           hRecoVsTrueEnergyPQ_NDClone->SetBinContent(i,j,0);
01815           hRecoVsTrueEnergyPQ_NDClone->SetBinError(i,j,0);
01816         }
01817       }
01818     }
01819     //(numu + numubar CC):
01820     for(int i=1;i<=hRecoVsTrueEnergyAll_NDClone->GetNbinsX();i++){
01821       //loop over true bins
01822       for(int j=1;j<=hRecoVsTrueEnergyAll_NDClone->GetNbinsY()+1;j++){
01823         //loop over reco bins
01824         if(hRecoEnergyCCOnlyEventsAll_NDClone->GetBinContent(j)>0 &&
01825            hRecoVsTrueEnergyAll_NDClone->GetBinContent(i,j)>0) {
01826           Float_t error=(hRecoVsTrueEnergyAll_NDClone->GetBinError(i,j)/
01827                          hRecoVsTrueEnergyAll_NDClone->GetBinContent(i,j));
01828 
01829           hRecoVsTrueEnergyAll_NDClone->SetBinContent
01830             (i,j,hRecoVsTrueEnergyAll_NDClone->GetBinContent(i,j)/
01831              hRecoEnergyCCOnlyEventsAll_NDClone->GetBinContent(j));
01832 
01833           hRecoVsTrueEnergyAll_NDClone->SetBinError
01834             (i,j,error*hRecoVsTrueEnergyAll_NDClone->GetBinContent(i,j));
01835         }
01836         else {
01837           hRecoVsTrueEnergyAll_NDClone->SetBinContent(i,j,0);
01838           hRecoVsTrueEnergyAll_NDClone->SetBinError(i,j,0);
01839         }
01840       }
01841     }
01842 
01843     //Normalise the FD reco v. true CC matrix (numu CC):
01844     for(int i=1;i<=hRecoVsTrueEnergy_FDClone->GetNbinsX();i++){
01845       //loop over true bins
01846       for(int j=1;j<=hRecoVsTrueEnergy_FDClone->GetNbinsY()+1;j++){
01847         //loop over reco bins
01848         if( hTrueEnergyCCOnlyEvents_FDClone->GetBinContent(i)>0 &&
01849             hRecoVsTrueEnergy_FDClone->GetBinContent(i,j)>0 ) {
01850           Float_t error=(hRecoVsTrueEnergy_FDClone->GetBinError(i,j)/
01851                          hRecoVsTrueEnergy_FDClone->GetBinContent(i,j));
01852 
01853           hRecoVsTrueEnergy_FDClone->SetBinContent
01854             (i,j,hRecoVsTrueEnergy_FDClone->GetBinContent(i,j)/
01855              hTrueEnergyCCOnlyEvents_FDClone->GetBinContent(i));
01856 
01857           hRecoVsTrueEnergy_FDClone->SetBinError
01858             (i,j,error*hRecoVsTrueEnergy_FDClone->GetBinContent(i,j));
01859         }
01860         else {
01861           hRecoVsTrueEnergy_FDClone->SetBinContent(i,j,0);
01862           hRecoVsTrueEnergy_FDClone->SetBinError(i,j,0);
01863         }
01864       }
01865     }
01866 
01867     // The NC histograms are normalized (to 1 POT) in CombineMMHelpers.C
01868 
01869     //Normalise the FD reco v. true CC matrix (numubar CC):
01870     for(int i=1;i<=hRecoVsTrueEnergyPQ_FDClone->GetNbinsX();i++){
01871       //loop over true bins
01872       for(int j=1;j<=hRecoVsTrueEnergyPQ_FDClone->GetNbinsY()+1;j++){
01873         //loop over reco bins
01874         if( hTrueEnergyCCOnlyEventsPQ_FDClone->GetBinContent(i)>0 &&
01875             hRecoVsTrueEnergyPQ_FDClone->GetBinContent(i,j)>0 ) {
01876           Float_t error=(hRecoVsTrueEnergyPQ_FDClone->GetBinError(i,j)/
01877                          hRecoVsTrueEnergyPQ_FDClone->GetBinContent(i,j));
01878 
01879           hRecoVsTrueEnergyPQ_FDClone->SetBinContent
01880             (i,j,hRecoVsTrueEnergyPQ_FDClone->GetBinContent(i,j)/
01881              hTrueEnergyCCOnlyEventsPQ_FDClone->GetBinContent(i));
01882 
01883           hRecoVsTrueEnergyPQ_FDClone->SetBinError
01884             (i,j,error*hRecoVsTrueEnergyPQ_FDClone->GetBinContent(i,j));
01885         }
01886         else {
01887           hRecoVsTrueEnergyPQ_FDClone->SetBinContent(i,j,0);
01888           hRecoVsTrueEnergyPQ_FDClone->SetBinError(i,j,0);
01889         }
01890       }
01891     }
01892     //Normalise the FD reco v. true CC matrix (numu + numubar CC):
01893     for(int i=1;i<=hRecoVsTrueEnergyAll_FDClone->GetNbinsX();i++){
01894       //loop over true bins
01895       for(int j=1;j<=hRecoVsTrueEnergyAll_FDClone->GetNbinsY()+1;j++){
01896         //loop over reco bins
01897         if( hTrueEnergyCCOnlyEventsAll_FDClone->GetBinContent(i)>0 &&
01898             hRecoVsTrueEnergyAll_FDClone->GetBinContent(i,j)>0 ) {
01899           Float_t error=(hRecoVsTrueEnergyAll_FDClone->GetBinError(i,j)/
01900                          hRecoVsTrueEnergyAll_FDClone->GetBinContent(i,j));
01901 
01902           hRecoVsTrueEnergyAll_FDClone->SetBinContent
01903             (i,j,hRecoVsTrueEnergyAll_FDClone->GetBinContent(i,j)/
01904              hTrueEnergyCCOnlyEventsAll_FDClone->GetBinContent(i));
01905 
01906           hRecoVsTrueEnergyAll_FDClone->SetBinError
01907             (i,j,error*hRecoVsTrueEnergyAll_FDClone->GetBinContent(i,j));
01908         }
01909         else {
01910           hRecoVsTrueEnergyAll_FDClone->SetBinContent(i,j,0);
01911           hRecoVsTrueEnergyAll_FDClone->SetBinError(i,j,0);
01912         }
01913       }
01914     }
01915 
01916     //Normalise the FD reco v. true CC matrix (nutau CC):
01917     for(int i=1;i<=hRecoVsTrueEnergyTau_FDClone->GetNbinsX();i++){
01918       //loop over true bins
01919       for(int j=1;j<=hRecoVsTrueEnergyTau_FDClone->GetNbinsY()+1;j++){
01920         //loop over reco bins
01921         if( hTrueEnergyCCOnlyEventsTau_FDClone->GetBinContent(i)>0 &&
01922             hRecoVsTrueEnergyTau_FDClone->GetBinContent(i,j)>0 ) {
01923           Float_t error=(hRecoVsTrueEnergyTau_FDClone->GetBinError(i,j)/
01924                          hRecoVsTrueEnergyTau_FDClone->GetBinContent(i,j));
01925 
01926           hRecoVsTrueEnergyTau_FDClone->SetBinContent
01927             (i,j,hRecoVsTrueEnergyTau_FDClone->GetBinContent(i,j)/
01928              hTrueEnergyCCOnlyEventsTau_FDClone->GetBinContent(i));
01929 
01930           hRecoVsTrueEnergyTau_FDClone->SetBinError
01931             (i,j,error*hRecoVsTrueEnergyTau_FDClone->GetBinContent(i,j));
01932         }
01933         else {
01934           hRecoVsTrueEnergyTau_FDClone->SetBinContent(i,j,0);
01935           hRecoVsTrueEnergyTau_FDClone->SetBinError(i,j,0);
01936         }
01937       }
01938     }
01939     //Normalise the FD reco v. true CC matrix (nutaubar CC):
01940     for(int i=1;i<=hRecoVsTrueEnergyTauPQ_FDClone->GetNbinsX();i++){
01941       //loop over true bins
01942       for(int j=1;j<=hRecoVsTrueEnergyTauPQ_FDClone->GetNbinsY()+1;j++){
01943         //loop over reco bins
01944         if( hTrueEnergyCCOnlyEventsTauPQ_FDClone->GetBinContent(i)>0 &&
01945             hRecoVsTrueEnergyTauPQ_FDClone->GetBinContent(i,j)>0 ) {
01946           Float_t error=(hRecoVsTrueEnergyTauPQ_FDClone->GetBinError(i,j)/
01947                          hRecoVsTrueEnergyTauPQ_FDClone->GetBinContent(i,j));
01948 
01949           hRecoVsTrueEnergyTauPQ_FDClone->SetBinContent
01950             (i,j,hRecoVsTrueEnergyTauPQ_FDClone->GetBinContent(i,j)/
01951              hTrueEnergyCCOnlyEventsTauPQ_FDClone->GetBinContent(i));
01952 
01953           hRecoVsTrueEnergyTauPQ_FDClone->SetBinError
01954             (i,j,error*hRecoVsTrueEnergyTauPQ_FDClone->GetBinContent(i,j));
01955         }
01956         else {
01957           hRecoVsTrueEnergyTauPQ_FDClone->SetBinContent(i,j,0);
01958           hRecoVsTrueEnergyTauPQ_FDClone->SetBinError(i,j,0);
01959         }
01960       }
01961     }
01962     //Normalise the FD reco v. true CC matrix (nutau + nutaubar CC):
01963     for(int i=1;i<=hRecoVsTrueEnergyTauAll_FDClone->GetNbinsX();i++){
01964       //loop over true bins
01965       for(int j=1;j<=hRecoVsTrueEnergyTauAll_FDClone->GetNbinsY()+1;j++){
01966         //loop over reco bins
01967         if( hTrueEnergyCCOnlyEventsTauAll_FDClone->GetBinContent(i)>0 &&
01968             hRecoVsTrueEnergyTauAll_FDClone->GetBinContent(i,j)>0 ) {
01969           Float_t error=(hRecoVsTrueEnergyTauAll_FDClone->GetBinError(i,j)/
01970                          hRecoVsTrueEnergyTauAll_FDClone->GetBinContent(i,j));
01971 
01972           hRecoVsTrueEnergyTauAll_FDClone->SetBinContent
01973             (i,j,hRecoVsTrueEnergyTauAll_FDClone->GetBinContent(i,j)/
01974              hTrueEnergyCCOnlyEventsTauAll_FDClone->GetBinContent(i));
01975 
01976           hRecoVsTrueEnergyTauAll_FDClone->SetBinError
01977             (i,j,error*hRecoVsTrueEnergyTauAll_FDClone->GetBinContent(i,j));
01978         }
01979         else {
01980           hRecoVsTrueEnergyTauAll_FDClone->SetBinContent(i,j,0);
01981           hRecoVsTrueEnergyTauAll_FDClone->SetBinError(i,j,0);
01982         }
01983       }
01984     }
01985   }
01986 
01987 
01989   //POT section
01991   if (!hTotalPotClone) {
01992     MSG("NuDSTAna",Msg::kInfo)
01993       <<"No hTotalPot histo so recalculating..."<<endl;
01994 
01995     //get an instance of the code library
01996     const NuLibrary& lib=NuLibrary::Instance();
01997 
01998     //calc pot histograms (hPotTotal gets written by default)
01999     lib.hist.CalcPOTsFromHistos("Clone");
02000 
02001     //set the clone pointer to the newly created histo
02002     //it will then get written out below
02003     hTotalPotClone=(TH1F*)gROOT->FindObject("hTotalPot");
02004   }
02005   else {
02006     MAXMSG("NuDSTAna",Msg::kInfo,1)
02007       <<"hTotalPot histo(s) exist(s) so they were summed"<<endl;
02008     MAXMSG("NuDSTAna",Msg::kInfo,1)
02009       <<"Total POT (from hTotalPot)="<<hTotalPotClone->Integral()<<endl;
02010   }
02011 
02013   //section to open output file
02015 
02016   //variable to store the output directory
02017   TDirectory* dirOutput=0;
02018 
02019   //open the output file for histos if not given etc
02020   if (poutput==0) {
02021     if (sFullFileName!="" && sFullFileName != "null") {
02022       fOutFile=this->OpenFileRECREATE(sFullFileName);
02023     }
02024     else if (fOutFile) {
02025         if (fOutFile->IsOpen())
02026             fOutFile->cd();
02027         else {
02028             MSG("NuDSTAna",Msg::kError) << "fOutFile was closed somehow." << endl;
02029             MSG("NuDSTAna",Msg::kFatal) << "fOutFile was closed somehow." << endl;
02030         }
02031     }
02032     else {
02033       Int_t firstRunNumber=input.GetFirstRunNumberNuEvent();
02034       if (sFilePrefix=="") sFilePrefix="NMBSumAna";
02035       fOutFile=this->OpenFile(firstRunNumber,sFilePrefix);
02036     }
02037     dirOutput=gDirectory;
02038     MSG("NuDSTAna",Msg::kInfo)<<"After opening output file:"<<endl;
02039     dirOutput->Print();
02040   }
02041   else {
02042     //get config object
02043     NuConfig config=this->GetNuConfig(input.GetNextNuEvent(Msg::kDebug));
02044     if (sFilePrefix=="") string sFilePrefix="NuDSTMicro";
02045     poutput->SetupFile(config,sFilePrefix);
02046 
02047     //get the directory of the new file
02048     dirOutput=gDirectory;
02049     MSG("NuDSTAna",Msg::kInfo)<<"Set up tree for NuOutputWriter"<<endl;
02050     //dirOutput->Print();//too verbose
02051   }
02052 
02053   //get rid of Clone in the name
02054   hDetectorClone->SetName("hDetector");
02055   hSimFlagClone->SetName("hSimFlag");
02056   hTrigSrcClone->SetName("hTrigSrc");
02057   hSpillsPerFileClone->SetName("hSpillsPerFile");
02058 
02059   if (hTotalPotClone) hTotalPotClone->SetName("hTotalPot");
02060 
02061   hPottortgtClone->SetName("hPottortgt");
02062   hPotBadtortgtClone->SetName("hPotBadtortgt");
02063   hPottrtgtdClone->SetName("hPottrtgtd");
02064   hPotBadtrtgtdClone->SetName("hPotBadtrtgtd");
02065   hPottor101Clone->SetName("hPottor101");
02066   hPotBadtor101Clone->SetName("hPotBadtor101");
02067   hPottr101dClone->SetName("hPottr101d");
02068   hPotBadtr101dClone->SetName("hPotBadtr101d");
02069   hRunClone->SetName("hRun");
02070 
02071   if (hNtupleEarliestTimeClone) {
02072     hNtupleEarliestTimeClone->SetName("hNtupleEarliestTime");
02073     hNtupleLatestTimeClone->SetName("hNtupleLatestTime");
02074   }
02075 
02076   //Rename MM histograms
02077   if (hRecoVsTrueEnergyPQ_FDClone) {
02078     MSG("NuDSTAna",Msg::kInfo) << "Renaming MM histos" << endl;
02079     //Numu CC:
02080     hRecoVsTrueEnergy_NDClone->SetName("RecoVsTrueEnergy_ND");
02081     hRecoVsTrueEnergy_FDClone->SetName("RecoVsTrueEnergy_FD");
02082     hEfficiency_NDClone->SetName("Efficiency_ND");
02083     hEfficiency_FDClone->SetName("Efficiency_FD");
02084     hPurity_NDClone->SetName("Purity_ND");
02085     hPurity_FDClone->SetName("Purity_FD");
02086     hRecoEnergyAllEvents_NDClone->SetName("RecoEnergyAllEvents_ND");
02087     hRecoEnergyCCOnlyEvents_NDClone->SetName("RecoEnergyCCOnlyEvents_ND");
02088     hTrueEnergyCCOnlyEvents_NDClone->SetName("TrueEnergyCCOnlyEvents_ND");
02089 
02090     if (hTrueEnergyTrueCCFidEvents_NDClone){
02091       hTrueEnergyTrueCCFidEvents_NDClone->SetName("TrueEnergyTrueCCFidEvents_ND");
02092     }
02093     if (hTrueEnergyTrueCCFidEvents_FDClone){
02094       hTrueEnergyTrueCCFidEvents_FDClone->SetName("TrueEnergyTrueCCFidEvents_FD");
02095     }
02096 
02097     hTrueEnergyCCOnlyEvents_FDClone->SetName("TrueEnergyCCOnlyEvents_FD");
02098     hRecoEnergyCCOnlyEvents_FDClone->SetName("RecoEnergyCCOnlyEvents_FD");
02099     hRecoEnergyAllEvents_FDClone->SetName("RecoEnergyAllEvents_FD");
02100     hRecoEnergy_NDClone->SetName("RecoEnergy_ND");
02101     hRecoEnergy_FDClone->SetName("RecoEnergy_FD");
02102     if (hRecoEnergy_ND_NCClone){
02103       hRecoEnergy_ND_NCClone->SetName("RecoEnergy_ND_NC");
02104     }
02105     if (hRecoEnergy_FD_NCClone){
02106       hRecoEnergy_FD_NCClone->SetName("RecoEnergy_FD_NC");
02107     }
02108     if (hRecoVsTrueEnergy_ND_NCClone){
02109       hRecoVsTrueEnergy_ND_NCClone->SetName("RecoVsTrueEnergy_ND_NC");
02110     }
02111     if (hRecoVsTrueEnergy_FD_NCClone){
02112       hRecoVsTrueEnergy_FD_NCClone->SetName("RecoVsTrueEnergy_FD_NC");
02113     }
02114 
02115     for(int truth = 0; truth < ENCTruth::kNumTruths; ++truth){
02116       for(int det = 0; det <= 1; ++det){
02117         const TString detstr = det ? "FD" : "ND";
02118         const TString name = "RecoVsTrueEnergy_truly"+ENCTruth::truthNames[truth]+"_"+detstr+"_NC";
02119         if (hRecoVsTrueEnergy_NCClone_truly[truth][det]){
02120           hRecoVsTrueEnergy_NCClone_truly[truth][det]->SetName(name);
02121         }
02122       }
02123     }
02124 
02125     if (hCCContamination_FDClone){
02126       hCCContamination_FDClone->SetName("CCContamination_FD");
02127       if (hCCContaminationRecoVsTrue_FDClone){
02128         hCCContaminationRecoVsTrue_FDClone->SetName("CCContaminationRecoVsTrue_FD");
02129       }
02130       hNCContamination_FDClone->SetName("NCContamination_FD");
02131     }
02132     if (hCCContamination_NDClone){
02133       hCCContamination_NDClone->SetName("CCContamination_ND");
02134     }
02135     if (hNCContamination_NDClone){
02136       hNCContamination_NDClone->SetName("NCContamination_ND");
02137     }
02138     //Decay Pipe:
02139     if(hTrueEnergyAllEventsPQ_NDClone) {
02140       hTrueEnergyAllEventsPQ_NDClone->SetName("TrueEnergyAllEventsPQ_ND");
02141     }
02142     if(hTrueEnergyAllEventsPQ_FDClone) {
02143       hTrueEnergyAllEventsPQ_FDClone->SetName("TrueEnergyAllEventsPQ_FD");
02144     }
02145     if(hTrueEnergyDecayPipePQ_NDClone) {
02146       hTrueEnergyDecayPipePQ_NDClone->SetName("TrueEnergyDecayPipePQ_ND");
02147     }
02148     if(hTrueEnergyDecayPipePQ_FDClone) {
02149       hTrueEnergyDecayPipePQ_FDClone->SetName("TrueEnergyDecayPipePQ_FD");
02150     }
02151     //Numubar CC:
02152     hRecoVsTrueEnergyPQ_NDClone->SetName("RecoVsTrueEnergyPQ_ND");
02153     hRecoVsTrueEnergyPQ_FDClone->SetName("RecoVsTrueEnergyPQ_FD");
02154     hEfficiencyPQ_NDClone->SetName("EfficiencyPQ_ND");
02155     hEfficiencyPQ_FDClone->SetName("EfficiencyPQ_FD");
02156     hPurityPQ_NDClone->SetName("PurityPQ_ND");
02157     hPurityPQ_FDClone->SetName("PurityPQ_FD");
02158     hRecoEnergyAllEventsPQ_NDClone->SetName("RecoEnergyAllEventsPQ_ND");
02159     hRecoEnergyCCOnlyEventsPQ_NDClone->SetName("RecoEnergyCCOnlyEventsPQ_ND");
02160     hTrueEnergyCCOnlyEventsPQ_NDClone->SetName("TrueEnergyCCOnlyEventsPQ_ND");
02161 
02162     if (hTrueEnergyTrueCCFidEventsPQ_NDClone){
02163       hTrueEnergyTrueCCFidEventsPQ_NDClone->SetName("TrueEnergyTrueCCFidEventsPQ_ND");
02164     }
02165     if (hTrueEnergyTrueCCFidEventsPQ_FDClone){
02166       hTrueEnergyTrueCCFidEventsPQ_FDClone->SetName("TrueEnergyTrueCCFidEventsPQ_FD");
02167     }
02168 
02169     hTrueEnergyCCOnlyEventsPQ_FDClone->SetName("TrueEnergyCCOnlyEventsPQ_FD");
02170     hRecoEnergyCCOnlyEventsPQ_FDClone->SetName("RecoEnergyCCOnlyEventsPQ_FD");
02171     hRecoEnergyAllEventsPQ_FDClone->SetName("RecoEnergyAllEventsPQ_FD");
02172     hRecoEnergyPQ_NDClone->SetName("RecoEnergyPQ_ND");
02173     hRecoEnergyPQ_FDClone->SetName("RecoEnergyPQ_FD");
02174     if (hCCContaminationPQ_FDClone){
02175       hCCContaminationPQ_FDClone->SetName("CCContaminationPQ_FD");
02176       if (hCCContaminationRecoVsTruePQ_FDClone){
02177         hCCContaminationRecoVsTruePQ_FDClone->SetName("CCContaminationRecoVsTruePQ_FD");
02178       }
02179       hNCContaminationPQ_FDClone->SetName("NCContaminationPQ_FD");
02180     }
02181     if (hCCContaminationPQ_NDClone){
02182       hCCContaminationPQ_NDClone->SetName("CCContaminationPQ_ND");
02183     }
02184     if (hNCContaminationPQ_NDClone){
02185       hNCContaminationPQ_NDClone->SetName("NCContaminationPQ_ND");
02186     }
02187     //Numu + numubar CC:
02188     hRecoVsTrueEnergyAll_NDClone->SetName("RecoVsTrueEnergyAll_ND");
02189     hRecoVsTrueEnergyAll_FDClone->SetName("RecoVsTrueEnergyAll_FD");
02190     hEfficiencyAll_NDClone->SetName("EfficiencyAll_ND");
02191     hEfficiencyAll_FDClone->SetName("EfficiencyAll_FD");
02192     hPurityAll_NDClone->SetName("PurityAll_ND");
02193     hPurityAll_FDClone->SetName("PurityAll_FD");
02194     hRecoEnergyAllEventsAll_NDClone->SetName("RecoEnergyAllEventsAll_ND");
02195     hRecoEnergyCCOnlyEventsAll_NDClone->SetName("RecoEnergyCCOnlyEventsAll_ND");
02196     hTrueEnergyCCOnlyEventsAll_NDClone->SetName("TrueEnergyCCOnlyEventsAll_ND");
02197 
02198     if (hTrueEnergyTrueCCFidEventsAll_NDClone){
02199       hTrueEnergyTrueCCFidEventsAll_NDClone->SetName("TrueEnergyTrueCCFidEventsAll_ND");
02200       hTrueEnergyTrueCCFidEventsAll_FDClone->SetName("TrueEnergyTrueCCFidEventsAll_FD");
02201     }
02202 
02203     hTrueEnergyCCOnlyEventsAll_FDClone->SetName("TrueEnergyCCOnlyEventsAll_FD");
02204     hRecoEnergyCCOnlyEventsAll_FDClone->SetName("RecoEnergyCCOnlyEventsAll_FD");
02205     hRecoEnergyAllEventsAll_FDClone->SetName("RecoEnergyAllEventsAll_FD");
02206     hRecoEnergyAll_NDClone->SetName("RecoEnergyAll_ND");
02207     hRecoEnergyAll_FDClone->SetName("RecoEnergyAll_FD");
02208   }
02209   //nutau CC:
02210   if (hRecoVsTrueEnergyTau_FDClone){
02211     hRecoVsTrueEnergyTau_FDClone->SetName("RecoVsTrueEnergyTau_FD");
02212   }
02213   if (hEfficiencyTau_FDClone){
02214     hEfficiencyTau_FDClone->SetName("EfficiencyTau_FD");
02215   }
02216   if (hTrueEnergyTrueCCFidEventsTau_FDClone){
02217     hTrueEnergyTrueCCFidEventsTau_FDClone->SetName("TrueEnergyTrueCCFidEventsTau_FD");
02218   }
02219   if (hTrueEnergyTrueCCFidEventsTau_FDClone){
02220     hTrueEnergyCCOnlyEventsTau_FDClone->SetName("TrueEnergyCCOnlyEventsTau_FD");
02221   }
02222   //nutaubar CC:
02223   if (hRecoVsTrueEnergyTauPQ_FDClone){
02224     hRecoVsTrueEnergyTauPQ_FDClone->SetName("RecoVsTrueEnergyTauPQ_FD");
02225   }
02226   if (hEfficiencyTauPQ_FDClone){
02227     hEfficiencyTauPQ_FDClone->SetName("EfficiencyTauPQ_FD");
02228   }
02229   if (hTrueEnergyTrueCCFidEventsTauPQ_FDClone){
02230     hTrueEnergyTrueCCFidEventsTauPQ_FDClone->SetName("TrueEnergyTrueCCFidEventsTauPQ_FD");
02231   }
02232   if (hTrueEnergyTrueCCFidEventsTauPQ_FDClone){
02233     hTrueEnergyCCOnlyEventsTauPQ_FDClone->SetName("TrueEnergyCCOnlyEventsTauPQ_FD");
02234   }
02235   //nutau + nutaubar CC:
02236   if (hRecoVsTrueEnergyTauAll_FDClone){
02237     hRecoVsTrueEnergyTauAll_FDClone->SetName("RecoVsTrueEnergyTauAll_FD");
02238   }
02239   if (hEfficiencyTauAll_FDClone){
02240     hEfficiencyTauAll_FDClone->SetName("EfficiencyTauAll_FD");
02241   }
02242   if (hTrueEnergyTrueCCFidEventsTauAll_FDClone){
02243     hTrueEnergyTrueCCFidEventsTauAll_FDClone->SetName("TrueEnergyTrueCCFidEventsTauAll_FD");
02244   }
02245   if (hTrueEnergyTrueCCFidEventsTauAll_FDClone){
02246     hTrueEnergyCCOnlyEventsTauAll_FDClone->SetName("TrueEnergyCCOnlyEventsTauAll_FD");
02247   }
02248 
02250   //now write to file
02252   hDetectorClone->Write();
02253   hSimFlagClone->Write();
02254   hTrigSrcClone->Write();
02255   hSpillsPerFileClone->Write();
02256 
02257   if (hTotalPotClone) {
02258     if (hTotalPotClone->Integral() < 0) {
02259       MSG("NuDSTAna",Msg::kWarning) << "Warning: Negative total POT = " << hTotalPotClone->Integral() << endl;
02260       if (hDetectorClone->GetMean() == 2 && hSimFlagClone->GetMean() == 4) {
02261         double pot = hTotalPotClone->Integral();
02262         pot /= hPottortgtClone->GetMean();
02263         pot *= 6.5; // 6.5 (e20) should replace whatever negative value of spills per file was used.  All else is unchanged
02264         MSG("NuDSTAna",Msg::kWarning) << "This appears to be FD MC.  Setting POTs to default dogwood value, which for this file is " << pot << endl;       
02265         hTotalPotClone->SetBinContent(1, pot);
02266       }
02267     }
02268     
02269     
02270     hTotalPotClone->Write();
02271   }
02272 
02273   if (xmlConfigClone) {
02274     cout << "NuXMLConfig Transfered" << endl;
02275     xmlConfigClone->Write("NuXMLConfig");
02276   }
02277 
02278   hPottortgtClone->Write();
02279   hPotBadtortgtClone->Write();
02280   hPottrtgtdClone->Write();
02281   hPotBadtrtgtdClone->Write();
02282   hPottor101Clone->Write();
02283   hPotBadtor101Clone->Write();
02284   hPottr101dClone->Write();
02285   hPotBadtr101dClone->Write();
02286   hRunClone->Write();
02287 
02288   if (hNtupleEarliestTimeClone) hNtupleEarliestTimeClone->Write();
02289   if (hNtupleLatestTimeClone) hNtupleLatestTimeClone->Write();
02290 
02291   //Write the MM histograms
02292   if (hRecoVsTrueEnergyPQ_FDClone) {
02293     MSG("NuDSTAna",Msg::kInfo) << "Writing MM histos to File" << endl;
02294     //Numu CC:
02295     hRecoVsTrueEnergy_NDClone->Write();
02296     hRecoVsTrueEnergy_FDClone->Write();
02297     hEfficiency_NDClone->Write();
02298     hEfficiency_FDClone->Write();
02299     hPurity_NDClone->Write();
02300     hPurity_FDClone->Write();
02301     hRecoEnergyAllEvents_NDClone->Write();
02302     hRecoEnergyCCOnlyEvents_NDClone->Write();
02303     hTrueEnergyCCOnlyEvents_NDClone->Write();
02304 
02305     if (hTrueEnergyTrueCCFidEvents_NDClone){
02306       hTrueEnergyTrueCCFidEvents_NDClone->Write();
02307     }
02308     if (hTrueEnergyTrueCCFidEvents_FDClone){
02309       hTrueEnergyTrueCCFidEvents_FDClone->Write();
02310     }
02311 
02312     hTrueEnergyCCOnlyEvents_FDClone->Write();
02313     hRecoEnergyCCOnlyEvents_FDClone->Write();
02314     hRecoEnergyAllEvents_FDClone->Write();
02315     hRecoEnergy_NDClone->Write();
02316     hRecoEnergy_FDClone->Write();
02317 
02318     if (hRecoEnergy_ND_NCClone){
02319       hRecoEnergy_ND_NCClone->Write();
02320     }
02321     if (hRecoEnergy_FD_NCClone){
02322       hRecoEnergy_FD_NCClone->Write();
02323     }
02324     if (hRecoVsTrueEnergy_ND_NCClone){
02325       hRecoVsTrueEnergy_ND_NCClone->Write();
02326     }
02327     if (hRecoVsTrueEnergy_FD_NCClone){
02328       hRecoVsTrueEnergy_FD_NCClone->Write();
02329     }
02330 
02331     for(int truth = 0; truth < ENCTruth::kNumTruths; ++truth){
02332       for(int det = 0; det <= 1; ++det){
02333         if (hRecoVsTrueEnergy_NCClone_truly[truth][det]){
02334           hRecoVsTrueEnergy_NCClone_truly[truth][det]->Write();
02335         }
02336       }
02337     }
02338     
02339     if (hCCContamination_FDClone){
02340       hCCContamination_FDClone->Write();
02341       if (hCCContaminationRecoVsTrue_FDClone){
02342         hCCContaminationRecoVsTrue_FDClone->Write();
02343       }
02344       hNCContamination_FDClone->Write();
02345     }
02346     if (hCCContamination_NDClone){
02347       hCCContamination_NDClone->Write();
02348     }
02349     if (hNCContamination_NDClone){
02350       hNCContamination_NDClone->Write();
02351     }
02352     //Decay Pipe:
02353     if(hTrueEnergyAllEventsPQ_NDClone) {
02354       hTrueEnergyAllEventsPQ_NDClone->Write();
02355     }
02356     if(hTrueEnergyAllEventsPQ_FDClone) {
02357       hTrueEnergyAllEventsPQ_FDClone->Write();
02358     }
02359     if(hTrueEnergyDecayPipePQ_NDClone) {
02360       hTrueEnergyDecayPipePQ_NDClone->Write();
02361     }
02362     if(hTrueEnergyDecayPipePQ_FDClone) {
02363       hTrueEnergyDecayPipePQ_FDClone->Write();
02364     }
02365     //Numubar CC:
02366     hRecoVsTrueEnergyPQ_NDClone->Write();
02367     hRecoVsTrueEnergyPQ_FDClone->Write();
02368     hEfficiencyPQ_NDClone->Write();
02369     hEfficiencyPQ_FDClone->Write();
02370     hPurityPQ_NDClone->Write();
02371     hPurityPQ_FDClone->Write();
02372     hRecoEnergyAllEventsPQ_NDClone->Write();
02373     hRecoEnergyCCOnlyEventsPQ_NDClone->Write();
02374     hTrueEnergyCCOnlyEventsPQ_NDClone->Write();
02375 
02376     if (hTrueEnergyTrueCCFidEventsPQ_NDClone){
02377       hTrueEnergyTrueCCFidEventsPQ_NDClone->Write();
02378     }
02379     if (hTrueEnergyTrueCCFidEventsPQ_FDClone){
02380       hTrueEnergyTrueCCFidEventsPQ_FDClone->Write();
02381     }
02382 
02383     hTrueEnergyCCOnlyEventsPQ_FDClone->Write();
02384     hRecoEnergyCCOnlyEventsPQ_FDClone->Write();
02385     hRecoEnergyAllEventsPQ_FDClone->Write();
02386     hRecoEnergyPQ_NDClone->Write();
02387     hRecoEnergyPQ_FDClone->Write();
02388     if (hCCContaminationPQ_FDClone){
02389       hCCContaminationPQ_FDClone->Write();
02390       if (hCCContaminationRecoVsTruePQ_FDClone){
02391         hCCContaminationRecoVsTruePQ_FDClone->Write();
02392       }
02393       hNCContaminationPQ_FDClone->Write();
02394     }
02395     if (hCCContaminationPQ_NDClone){
02396       hCCContaminationPQ_NDClone->Write();
02397     }
02398     if (hNCContaminationPQ_NDClone){
02399       hNCContaminationPQ_NDClone->Write();
02400     }
02401     //Numu + numubar CC:
02402     hRecoVsTrueEnergyAll_NDClone->Write();
02403     hRecoVsTrueEnergyAll_FDClone->Write();
02404     hEfficiencyAll_NDClone->Write();
02405     hEfficiencyAll_FDClone->Write();
02406     hPurityAll_NDClone->Write();
02407     hPurityAll_FDClone->Write();
02408     hRecoEnergyAllEventsAll_NDClone->Write();
02409     hRecoEnergyCCOnlyEventsAll_NDClone->Write();
02410     hTrueEnergyCCOnlyEventsAll_NDClone->Write();
02411 
02412     if (hTrueEnergyTrueCCFidEventsAll_NDClone){
02413       hTrueEnergyTrueCCFidEventsAll_NDClone->Write();
02414     }
02415     if (hTrueEnergyTrueCCFidEventsAll_FDClone){
02416       hTrueEnergyTrueCCFidEventsAll_FDClone->Write();
02417     }
02418 
02419     hTrueEnergyCCOnlyEventsAll_FDClone->Write();
02420     hRecoEnergyCCOnlyEventsAll_FDClone->Write();
02421     hRecoEnergyAllEventsAll_FDClone->Write();
02422     hRecoEnergyAll_NDClone->Write();
02423     hRecoEnergyAll_FDClone->Write();
02424     //nutau CC:
02425     if (hRecoVsTrueEnergyTau_FDClone){
02426       hRecoVsTrueEnergyTau_FDClone->Write();
02427     }
02428     if (hEfficiencyTau_FDClone){
02429       hEfficiencyTau_FDClone->Write();
02430     }
02431     if (hTrueEnergyTrueCCFidEventsTau_FDClone){
02432       hTrueEnergyTrueCCFidEventsTau_FDClone->Write();
02433     }
02434     if (hTrueEnergyTrueCCFidEventsTau_FDClone){
02435       hTrueEnergyCCOnlyEventsTau_FDClone->Write();
02436     }
02437     //nutaubar CC:
02438     if (hRecoVsTrueEnergyTauPQ_FDClone){
02439       hRecoVsTrueEnergyTauPQ_FDClone->Write();
02440     }
02441     if (hEfficiencyTauPQ_FDClone){
02442       hEfficiencyTauPQ_FDClone->Write();
02443     }
02444     if (hTrueEnergyTrueCCFidEventsTauPQ_FDClone){
02445       hTrueEnergyTrueCCFidEventsTauPQ_FDClone->Write();
02446     }
02447     if (hTrueEnergyTrueCCFidEventsTauPQ_FDClone){
02448       hTrueEnergyCCOnlyEventsTauPQ_FDClone->Write();
02449     }
02450     //nutau _ nutaubar CC:
02451     if (hRecoVsTrueEnergyTauAll_FDClone){
02452       hRecoVsTrueEnergyTauAll_FDClone->Write();
02453     }
02454     if (hEfficiencyTauAll_FDClone){
02455       hEfficiencyTauAll_FDClone->Write();
02456     }
02457     if (hTrueEnergyTrueCCFidEventsTauAll_FDClone){
02458       hTrueEnergyTrueCCFidEventsTauAll_FDClone->Write();
02459     }
02460     if (hTrueEnergyTrueCCFidEventsTauAll_FDClone){
02461       hTrueEnergyCCOnlyEventsTauAll_FDClone->Write();
02462     }
02463   }
02464 
02465   //copy across histos such hDetector, hSimFlag, and POT ones
02466   //do this above now
02467   //this->CopyAcrossHistos(dirInput,dirOutput);
02468 
02469   return input;
02470 }
02471 
02472 //......................................................................
02473 
02474 void NuDSTAna::NDTestAna()
02475 {
02476   NuInputEvents& input=this->DoIO();
02477 
02478   //use config object to store info
02479   NuConfig config;
02480   config.detector=Detector::kFar;
02481   config.run=100;
02482 
02483   string sTxt="nmb";
02484   ofstream& nmbTxt=*(this->OpenTxtFile(config,sTxt.c_str()));
02485   string sTxtNM="nm";
02486   ofstream& nmTxt=*(this->OpenTxtFile(config,sTxtNM.c_str()));
02487   //string sTxtLINM="nmLI";
02488   //ofstream& nmLITxt=*(this->OpenTxtFile(config,sTxtLINM.c_str()));
02489 
02490   //object to count events
02491   NuCounter cnt;
02492 
02493   static NuGeneral general;
02494   const NuPlots* plots=0;
02495   static NuCuts cuts;
02496   //static NuReco reco;//make a local one
02497 
02498   TH1F* hRecoEnDiff=new TH1F("hRecoEnDiff","hRecoEnDiff",
02499            200000,-100,100);
02500   hRecoEnDiff->SetTitle("Reconstructed Energy Difference (GeV)");
02501   hRecoEnDiff->GetXaxis()->
02502     SetTitle("Reconstructed Energy Difference (GeV)");
02503   hRecoEnDiff->GetXaxis()->CenterTitle();
02504   hRecoEnDiff->GetYaxis()->SetTitle("");
02505   hRecoEnDiff->GetYaxis()->CenterTitle();
02506   hRecoEnDiff->SetFillColor(0);
02507   hRecoEnDiff->SetLineColor(1);
02508   //hRecoEnDiff->SetBit(TH1::kCanRebin);
02509 
02510   TH1F* hRecoEnDiffCurv=new TH1F("hRecoEnDiffCurv","hRecoEnDiffCurv",
02511          200000,-100,100);
02512   hRecoEnDiffCurv->SetTitle("Reconstructed Energy Difference (GeV)");
02513   hRecoEnDiffCurv->GetXaxis()->
02514     SetTitle("Reconstructed Energy Difference (GeV)");
02515   hRecoEnDiffCurv->GetXaxis()->CenterTitle();
02516   hRecoEnDiffCurv->GetYaxis()->SetTitle("");
02517   hRecoEnDiffCurv->GetYaxis()->CenterTitle();
02518   hRecoEnDiffCurv->SetFillColor(0);
02519   hRecoEnDiffCurv->SetLineColor(1);
02520   //hRecoEnDiffCurv->SetBit(TH1::kCanRebin);
02521 
02522   TH1F* hRecoEnDiffRange=new TH1F("hRecoEnDiffRange","hRecoEnDiffRange",
02523           200000,-100,100);
02524   hRecoEnDiffRange->SetTitle("Reconstructed Energy Difference (GeV)");
02525   hRecoEnDiffRange->GetXaxis()->
02526     SetTitle("Reconstructed Energy Difference (GeV)");
02527   hRecoEnDiffRange->GetXaxis()->CenterTitle();
02528   hRecoEnDiffRange->GetYaxis()->SetTitle("");
02529   hRecoEnDiffRange->GetYaxis()->CenterTitle();
02530   hRecoEnDiffRange->SetFillColor(0);
02531   hRecoEnDiffRange->SetLineColor(1);
02532   //hRecoEnDiffRange->SetBit(TH1::kCanRebin);
02533 
02534 
02535   TH1F* hRecoTrkEnDiff=new TH1F("hRecoTrkEnDiff","hRecoTrkEnDiff",
02536            200000,-100,100);
02537   hRecoTrkEnDiff->SetTitle("Reconstructed Trk Energy Difference (GeV)");
02538   hRecoTrkEnDiff->GetXaxis()->
02539     SetTitle("Reconstructed Trk Energy Difference (GeV)");
02540   hRecoTrkEnDiff->GetXaxis()->CenterTitle();
02541   hRecoTrkEnDiff->GetYaxis()->SetTitle("");
02542   hRecoTrkEnDiff->GetYaxis()->CenterTitle();
02543   hRecoTrkEnDiff->SetFillColor(0);
02544   hRecoTrkEnDiff->SetLineColor(1);
02545   //hRecoTrkEnDiff->SetBit(TH1::kCanRebin);
02546 
02547   TH1F* hRecoTrkEnDiffCurv=new TH1F("hRecoTrkEnDiffCurv","hRecoTrkEnDiffCurv",
02548          200000,-100,100);
02549   hRecoTrkEnDiffCurv->SetTitle("Reconstructed Trk Energy Difference (GeV)");
02550   hRecoTrkEnDiffCurv->GetXaxis()->
02551     SetTitle("Reconstructed Trk Energy Difference (GeV)");
02552   hRecoTrkEnDiffCurv->GetXaxis()->CenterTitle();
02553   hRecoTrkEnDiffCurv->GetYaxis()->SetTitle("");
02554   hRecoTrkEnDiffCurv->GetYaxis()->CenterTitle();
02555   hRecoTrkEnDiffCurv->SetFillColor(0);
02556   hRecoTrkEnDiffCurv->SetLineColor(1);
02557   //hRecoTrkEnDiffCurv->SetBit(TH1::kCanRebin);
02558 
02559   TH1F* hRecoTrkEnDiffRange=new TH1F("hRecoTrkEnDiffRange","hRecoTrkEnDiffRange",
02560           200000,-100,100);
02561   hRecoTrkEnDiffRange->SetTitle("Reconstructed Trk Energy Difference (GeV)");
02562   hRecoTrkEnDiffRange->GetXaxis()->
02563     SetTitle("Reconstructed Trk Energy Difference (GeV)");
02564   hRecoTrkEnDiffRange->GetXaxis()->CenterTitle();
02565   hRecoTrkEnDiffRange->GetYaxis()->SetTitle("");
02566   hRecoTrkEnDiffRange->GetYaxis()->CenterTitle();
02567   hRecoTrkEnDiffRange->SetFillColor(0);
02568   hRecoTrkEnDiffRange->SetLineColor(1);
02569   //hRecoTrkEnDiffRange->SetBit(TH1::kCanRebin);
02570 
02571 
02572 
02573 
02574   TH1F* hRecoShwEnDiff=new TH1F("hRecoShwEnDiff","hRecoShwEnDiff",
02575            200000,-100,100);
02576   hRecoShwEnDiff->SetTitle("Reconstructed Shw Energy Difference (GeV)");
02577   hRecoShwEnDiff->GetXaxis()->
02578     SetTitle("Reconstructed Shw Energy Difference (GeV)");
02579   hRecoShwEnDiff->GetXaxis()->CenterTitle();
02580   hRecoShwEnDiff->GetYaxis()->SetTitle("");
02581   hRecoShwEnDiff->GetYaxis()->CenterTitle();
02582   hRecoShwEnDiff->SetFillColor(0);
02583   hRecoShwEnDiff->SetLineColor(1);
02584   //hRecoShwEnDiff->SetBit(TH1::kCanRebin);
02585 
02586   TH1F* hRecoShwEnDiffCurv=new TH1F("hRecoShwEnDiffCurv","hRecoShwEnDiffCurv",
02587          200000,-100,100);
02588   hRecoShwEnDiffCurv->SetTitle("Reconstructed Shw Energy Difference (GeV)");
02589   hRecoShwEnDiffCurv->GetXaxis()->
02590     SetTitle("Reconstructed Shw Energy Difference (GeV)");
02591   hRecoShwEnDiffCurv->GetXaxis()->CenterTitle();
02592   hRecoShwEnDiffCurv->GetYaxis()->SetTitle("");
02593   hRecoShwEnDiffCurv->GetYaxis()->CenterTitle();
02594   hRecoShwEnDiffCurv->SetFillColor(0);
02595   hRecoShwEnDiffCurv->SetLineColor(1);
02596   //hRecoShwEnDiffCurv->SetBit(TH1::kCanRebin);
02597 
02598   TH1F* hRecoShwEnDiffRange=new TH1F("hRecoShwEnDiffRange","hRecoShwEnDiffRange",
02599           200000,-100,100);
02600   hRecoShwEnDiffRange->SetTitle("Reconstructed Shw Energy Difference (GeV)");
02601   hRecoShwEnDiffRange->GetXaxis()->
02602     SetTitle("Reconstructed Shw Energy Difference (GeV)");
02603   hRecoShwEnDiffRange->GetXaxis()->CenterTitle();
02604   hRecoShwEnDiffRange->GetYaxis()->SetTitle("");
02605   hRecoShwEnDiffRange->GetYaxis()->CenterTitle();
02606   hRecoShwEnDiffRange->SetFillColor(0);
02607   hRecoShwEnDiffRange->SetLineColor(1);
02608   //hRecoShwEnDiffRange->SetBit(TH1::kCanRebin);
02609 
02610 
02611 
02612 
02613   TH1F* hRecoEnOfDiff=new TH1F("hRecoEnOfDiff","hRecoEnOfDiff",
02614                    400,-100,100);
02615   hRecoEnOfDiff->SetTitle("Reconstructed Energy (GeV)");
02616   hRecoEnOfDiff->GetXaxis()->
02617     SetTitle("Reconstructed Energy (GeV)");
02618   hRecoEnOfDiff->GetXaxis()->CenterTitle();
02619   hRecoEnOfDiff->GetYaxis()->SetTitle("");
02620   hRecoEnOfDiff->GetYaxis()->CenterTitle();
02621   hRecoEnOfDiff->SetFillColor(0);
02622   hRecoEnOfDiff->SetLineColor(1);
02623   //hRecoEnOfDiff->SetBit(TH1::kCanRebin);
02624 
02625   TH1F* hRecoTrkEnOfDiff=new TH1F("hRecoTrkEnOfDiff","hRecoTrkEnOfDiff",
02626                    400,-100,100);
02627   hRecoTrkEnOfDiff->SetTitle("Reconstructed Trk Energy (GeV)");
02628   hRecoTrkEnOfDiff->GetXaxis()->
02629     SetTitle("Reconstructed Trk Energy (GeV)");
02630   hRecoTrkEnOfDiff->GetXaxis()->CenterTitle();
02631   hRecoTrkEnOfDiff->GetYaxis()->SetTitle("");
02632   hRecoTrkEnOfDiff->GetYaxis()->CenterTitle();
02633   hRecoTrkEnOfDiff->SetFillColor(0);
02634   hRecoTrkEnOfDiff->SetLineColor(1);
02635   //hRecoTrkEnOfDiff->SetBit(TH1::kCanRebin);
02636 
02637   TH1F* hRecoShwEnOfDiff=new TH1F("hRecoShwEnOfDiff","hRecoShwEnOfDiff",
02638                    400,-100,100);
02639   hRecoShwEnOfDiff->SetTitle("Reconstructed Shw Energy (GeV)");
02640   hRecoShwEnOfDiff->GetXaxis()->
02641     SetTitle("Reconstructed Shw Energy (GeV)");
02642   hRecoShwEnOfDiff->GetXaxis()->CenterTitle();
02643   hRecoShwEnOfDiff->GetYaxis()->SetTitle("");
02644   hRecoShwEnOfDiff->GetYaxis()->CenterTitle();
02645   hRecoShwEnOfDiff->SetFillColor(0);
02646   hRecoShwEnOfDiff->SetLineColor(1);
02647   //hRecoShwEnOfDiff->SetBit(TH1::kCanRebin);
02648 
02649   //get an instance of the code library
02650   const NuLibrary& lib=NuLibrary::Instance();
02651 
02652   //version to do reco/cuts with
02653   NuCuts::NuAnaVersion_t overrideAnaVersion=NuCuts::kCC0325Std;
02654 
02655   input.ResetNuEventLoopPositionToStart();
02656 
02660 
02661   cout<<endl
02662       <<"************************************************"<<endl
02663       <<"***      Starting main loop over snarls      ***"<<endl
02664       <<"************************************************"<<endl;
02665 
02666   for (Int_t i=0;i<input.GetEntriesNuEvent();++i) {
02667     cnt.evtCounter++;
02668 
02669     this->PrintLoopProgress(i,input.GetEntriesNuEvent(),1);
02670 
02671     NuEvent& nu=const_cast<NuEvent&>(input.GetNextNuEvent(Msg::kDebug));
02672 
02673     //OVERRIDE
02674     //set the analysis version (could be kFullDST)
02675     nu.anaVersion=this->SanityCheckedAnaVersion
02676       (nu.anaVersion,overrideAnaVersion);
02677 
02678     nu.applyEnergyShifts=false;
02679     nu.applyBeamWeight=true;
02680     nu.applyDetectorWeight=false;
02681     nu.applyGeneratorWeight=false;
02682     nu.cutOnDataQuality=false;
02683 
02684     //RE-RECONSTRUCT the neutrino energy
02685     lib.reco.GetEvtEnergy(nu, false);
02686     lib.reco.ApplyReweights(nu);
02687 
02688     //make all the std cuts
02689     if (!this->IsGoodStdCuts(plots,nu)) continue;
02690 
02691     Bool_t printToScreen=true;
02692     const NuEvent* pnu=0;
02693     if (printToScreen && nu.charge==-1) pnu=this->GetEventND(nu);
02694     Float_t energyDiff=-1;
02695     Float_t trkEnDiff=-1;
02696     Float_t shwEnDiff=-1;
02697 
02698     if (printToScreen && pnu && nu.charge==-1) {
02699       const NuEvent& nui=*pnu;
02700 
02701       static NuReco reco;
02702       //reco.GetShowerEnergy(nu);
02703 
02704       energyDiff=nu.energy-nui.energy;
02705       trkEnDiff=nu.trkEn-nui.trkEn;
02706       shwEnDiff=nu.shwEn-nui.shwEn;
02707       Float_t rangeCurvDiff=nu.trkEnRange-nu.trkEnCurv;
02708 
02709       MAXMSG("NuDSTAna",Msg::kInfo,50)
02710         <<endl<<"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"<<endl
02711         <<"Exists in map: run="<<nu.run
02712         <<", snarl="<<nu.snarl<<", evt="<<nu.evt
02713         <<endl
02714         <<"My energy="<<nu.energy<<", CC std energy="<<nui.energy
02715         <<", Ediff="<<energyDiff
02716         <<endl
02717         <<"My trkEn="<<nu.trkEn<<", CC std trkEn="<<nui.trkEn
02718         <<", trkEnDiff="<<trkEnDiff
02719         <<endl
02720         <<"My shwEn="<<nu.shwEn<<", CC std shwEn="<<nui.shwEn
02721         <<", shwEnDiff="<<shwEnDiff
02722         <<endl;
02723 
02724 
02725       if (TMath::Abs(energyDiff)>0.005*(Munits::GeV)) {
02726         Float_t p=-1;
02727         if (nu.qp) p=1./nu.qp;
02728 
02729         MAXMSG("NuDSTAna",Msg::kInfo,50)
02730           <<endl<<"************************"<<endl
02731           <<endl<<"************************"<<endl
02732           <<endl<<"************************"<<endl
02733           <<endl<<"************************"<<endl
02734           <<"run="<<nu.run<<", snarl="<<nu.snarl<<", evt="<<nu.evt
02735           <<endl
02736           <<"My energy="<<nu.energy<<", CC std energy="<<nui.energy
02737           <<", Ediff="<<energyDiff
02738           <<endl
02739           <<"My trkEn="<<nu.trkEn<<", CC std trkEn="<<nui.trkEn
02740           <<", trkEnDiff="<<trkEnDiff
02741           <<endl
02742           <<"My shwEn="<<nu.shwEn<<", CC std shwEn="<<nui.shwEn
02743           <<", shwEnDiff="<<shwEnDiff
02744           <<endl
02745           <<"shwEn="<<nu.shwEn
02746           <<", shwEnCor="<<nu.shwEnCor
02747           <<", shwEnNoCor="<<nu.shwEnNoCor
02748           <<", primshw="<<nu.primshw
02749           <<", nshw="<<nu.nshw
02750           <<endl
02751           <<"shwEnNoCor1="<<nu.shwEnNoCor1
02752           <<", shwEnNoCor2="<<nu.shwEnNoCor2
02753           <<", shwEnNOCor3="<<nu.shwEnNoCor3
02754           <<", shwEnNoCor4="<<nu.shwEnNoCor4
02755           <<endl
02756           <<"shower1 E="<<reco.GetShowerEnergyCor(nu.shwEnNoCor1,CandShowerHandle::kCC,nu)
02757           <<" : x,y,z="<<nu.xShwVtx1
02758           <<","<<nu.yShwVtx1
02759           <<","<<nu.zShwVtx1
02760           <<endl
02761           <<"shower2 E="<<reco.GetShowerEnergyCor(nu.shwEnNoCor2,CandShowerHandle::kCC,nu)
02762           <<" : x,y,z="<<nu.xShwVtx2
02763           <<","<<nu.yShwVtx2
02764           <<","<<nu.zShwVtx2
02765           <<endl
02766           <<"shower3 E="<<reco.GetShowerEnergyCor(nu.shwEnNoCor3,CandShowerHandle::kCC,nu)
02767           <<" : x,y,z="<<nu.xShwVtx3
02768           <<","<<nu.yShwVtx3
02769           <<","<<nu.zShwVtx3
02770           <<endl
02771           <<"shower4 E="<<reco.GetShowerEnergyCor(nu.shwEnNoCor4,CandShowerHandle::kCC,nu)
02772           <<" : x,y,z="<<nu.xShwVtx4
02773           <<","<<nu.yShwVtx4
02774           <<","<<nu.zShwVtx4
02775           <<endl
02776           <<"track  x,y,z="<<nu.xTrkVtx
02777           <<","<<nu.yTrkVtx
02778           <<","<<nu.zTrkVtx
02779           <<endl
02780           <<"trkEnRange="<<nu.trkEnRange
02781           <<", trkEnCurv="<<nu.trkEnCurv
02782           <<", rng-crv="<<rangeCurvDiff
02783           <<endl
02784           <<"rangeNoCor="<<nu.trkMomentumRange
02785           <<", curvNoCor="<<p
02786           <<endl
02787           <<"trkEnCorRange1="<<nu.trkEnCorRange1
02788           <<", trkEnCorRange2="<<nu.trkEnCorRange2
02789           <<", trkEnCorRange3="<<nu.trkEnCorRange3
02790           <<endl
02791           <<"trkEnCorCurv1="<<nu.trkEnCorCurv1
02792           <<", trkEnCorCurv2="<<nu.trkEnCorCurv2
02793           <<", trkEnCorCurv3="<<nu.trkEnCorCurv3
02794           <<endl;
02795 
02796         hRecoEnOfDiff->Fill(nu.energy);
02797         hRecoTrkEnOfDiff->Fill(nu.trkEn);
02798         hRecoShwEnOfDiff->Fill(nu.shwEn);
02799 
02800       }
02801 
02802       hRecoEnDiff->Fill(energyDiff);
02803       hRecoTrkEnDiff->Fill(trkEnDiff);
02804       hRecoShwEnDiff->Fill(shwEnDiff);
02805       if (nu.containmentFlag==1 || nu.containmentFlag==3) {
02806         hRecoEnDiffRange->Fill(energyDiff);
02807         hRecoTrkEnDiffRange->Fill(trkEnDiff);
02808         hRecoShwEnDiffRange->Fill(shwEnDiff);
02809       }
02810       else if (nu.containmentFlag==2 || nu.containmentFlag==4) {
02811         hRecoEnDiffCurv->Fill(energyDiff);
02812         hRecoTrkEnDiffCurv->Fill(trkEnDiff);
02813         hRecoShwEnDiffCurv->Fill(shwEnDiff);
02814       }
02815       else cout<<"Ahhhhh"<<endl;
02816     }
02817 
02818     //only pass the ones that aren't in trish's sample
02819     //if (pnu) continue;
02820     //if (nu.snarl>=140344) continue;
02821     if (nu.snarl>=56595) continue;
02822 
02823     if (nu.charge==-1) {
02824       plots->PrintEventInfo(nmTxt,nu);
02825       cnt.nuNQCounter++;
02826     }
02827     else if (nu.charge==+1) {
02828       plots->PrintEventInfo(nmbTxt,nu);
02829       cnt.nuPQCounter++;
02830     }
02831     else cout<<"ahhh, bad charge (2)"<<endl;
02832 
02833 
02834     MAXMSG("NuDSTAna",Msg::kInfo,50)
02835       <<"Weights before: beam="<<nu.beamWeight
02836       <<", det="<<nu.detectorWeight
02837       <<", trk="<<nu.trkEnWeight
02838       <<", shw="<<nu.shwEnWeight
02839       <<endl;
02840     Float_t beamWeightBefore=nu.beamWeight;
02841 
02842     //lib.zBeamReweight.ExtractZBeamReweight(nu);
02843 
02844 
02845     Float_t beamDiff=nu.beamWeight-beamWeightBefore;
02846     MAXMSG("NuDSTAna",Msg::kInfo,50)
02847       <<"Weights after:  beam="<<nu.beamWeight
02848       <<", det="<<nu.detectorWeight
02849       <<", trk="<<nu.trkEnWeight
02850       <<", shw="<<nu.shwEnWeight
02851       <<", bdiff="<<beamDiff
02852       <<endl;
02853 
02854     //make the final plots
02855     this->MakeFinalPlots(plots,nu);
02856 
02857     MAXMSG("NuDSTAna",Msg::kInfo,5)
02858       <<"Passed: index="<<nu.index
02859       <<", energy="<<nu.energy<<", energyMC="<<nu.energyMC<<endl;
02860   }//end of loop over summary tree
02861 
02862   MSG("NuAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
02863 
02867 
02868   //print out the numbers of events
02869   cnt.PrintMicroDST();
02870 
02871   MSG("NuAnalysis",Msg::kInfo)
02872     <<" ** Finished FDTestAna method **"<<endl;
02873 }
02874 
02875 //......................................................................
02876 
02877 void NuDSTAna::StdNMBAna(TString xmlFileName)
02878 {
02880   NuInputEvents& input=this->DoIO();
02881 
02882   //use config object to store info
02883   NuConfig config;
02884   config.detector=Detector::kFar;
02885   config.run=100;
02886 
02887   // If we have been given an XML file, then we want to use it for
02888   // oscillation. Read it in (and put it in the output file)
02889   NuXMLConfig *xmlConfig = 0;
02890   if (!xmlFileName.IsNull()) {
02891       xmlConfig = new NuXMLConfig(xmlFileName);
02892       xmlConfig->Write();
02893   }
02894 
02895   //text files to store info for evts passing cuts
02896   string sTxt="nmb";//nubars
02897   ofstream& nmbTxt=*(this->OpenTxtFile(config,sTxt.c_str()));
02898   string sTxtNM="nm";//neutrinos
02899   ofstream& nmTxt=*(this->OpenTxtFile(config,sTxtNM.c_str()));
02900 
02901   //get an instance of the code library
02902   NuLibrary& lib=NuLibrary::Instance();
02903 
02904   //get an object to fill plots
02905   const NuPlots* plots=new NuPlots();
02906 
02907   //create the object that gathers the information for transitions reweighting
02908   cout << "**** About to construct NuTransition object" << endl;
02909   NuTransition * transition = new NuTransition(xmlConfig);
02910   cout << "**** Done" << endl;
02911 
02912   //version to do reco/cuts with
02913   //NuCuts::NuAnaVersion_t overrideAnaVersion=NuCuts::kJJH1;
02914   NuCuts::NuAnaVersion_t overrideAnaVersion=NuCuts::kNMB0325Bravo;
02915 
02916 
02920 
02921   input.InitialiseNuMCEventBranch();
02922   input.ResetNuMCEventLoopPositionToStart();
02923 
02924   cout<<endl
02925   <<"************************************************"<<endl
02926   <<"***       Starting loop over truth info      ***"<<endl
02927   <<"************************************************"<<endl;
02928 
02929   for (Int_t i=0;i<input.GetEntriesNuMCEvent();++i) {
02930     lib.cnt.evtCounter++;
02931 
02932     this->PrintLoopProgress(i,input.GetEntriesNuMCEvent(),1);
02933 
02934     NuMCEvent& mc = const_cast<NuMCEvent&>(input.GetNextNuMCEvent
02935                                          (Msg::kDebug));
02936 
02937     //set the analysis version (could be kFullDST)
02938     mc.anaVersion=this->SanityCheckedAnaVersion
02939     (mc.anaVersion,overrideAnaVersion);
02940 
02941     MAXMSG("NuDSTAna",Msg::kInfo,5)
02942     <<"energyMC="<<mc.energyMC<<endl;
02943 
02944     //make fid vol cut
02945     if (!lib.cuts.IsInFidVolTrueEvt(mc)) continue;
02946 
02947     //store the information needed for transitions reweighting
02948     transition->Fill(mc);
02949 
02950     //fill plots
02951     plots->FillTrueFidEnergySpect(mc);
02952     plots->FillTrueFidEnergySpectSpecial(mc);
02953   }
02954 
02955   MSG("NuAnalysis",Msg::kInfo)<<"Finished truth loop"<<endl;
02956 
02957 
02961 
02962   input.ResetNuEventLoopPositionToStart();
02963 
02964   cout<<endl
02965       <<"************************************************"<<endl
02966       <<"***      Starting main loop over snarls      ***"<<endl
02967       <<"************************************************"<<endl;
02968 
02969   for (Int_t i=0;i<input.GetEntriesNuEvent();++i) {
02970     lib.cnt.evtCounter++;
02971 
02972     this->PrintLoopProgress(i,input.GetEntriesNuEvent(),1);
02973 
02974     NuEvent& nu=const_cast<NuEvent&>(input.GetNextNuEvent(Msg::kDebug));
02975 
02976     //set the analysis version (could be kFullDST)
02977     nu.anaVersion=this->SanityCheckedAnaVersion
02978       (nu.anaVersion,overrideAnaVersion);
02979 
02980     //RE-RECONSTRUCT the neutrino energy
02981     lib.reco.GetEvtEnergy(nu, false);//this re-reconstructs the neutrino energy
02982     lib.reco.ApplyReweights(nu);
02983 
02984     // Reweight for systematics, oscillations and transitions
02985     transition->Reweight(nu);
02986 
02987     //make all the std cuts
02988     if (!this->IsGoodStdCuts(plots,nu)) continue;
02989 
02990     if (nu.charge==-1) {
02991       plots->PrintEventInfo(nmTxt,nu);
02992       lib.cnt.nuNQCounter++;
02993     }
02994     else if (nu.charge==+1) {
02995       plots->PrintEventInfo(nmbTxt,nu);
02996       lib.cnt.nuPQCounter++;
02997     }
02998     else cout<<"ahhh, bad charge (3)"<<endl;
02999 
03000     //make the final plots
03001     this->MakeFinalPlots(plots,nu);
03002 
03003     //fill matrix method histos
03004     lib.hist.FillMatrixMethodHistos(nu);//might override file ones
03005 
03006     MAXMSG("NuDSTAna",Msg::kInfo,5)
03007       <<"Passed: index="<<nu.index
03008       <<", energy="<<nu.energy<<", energyMC="<<nu.energyMC<<endl;
03009   }//end of loop over summary tree
03010 
03011 
03012   MSG("NuAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
03013 
03017 
03018   //print out the numbers of events
03019   lib.cnt.PrintMicroDST();
03020 
03021   MSG("NuAnalysis",Msg::kInfo)
03022     <<" ** Finished StdAna method **"<<endl;
03023 }
03024 
03025 //......................................................................
03026 
03027 NuConfig NuDSTAna::GetNuConfig(const NuEvent& nu) const
03028 {
03029   //create a config object
03030   NuConfig config;
03031 
03032   //copy all the info across
03033   config.run=nu.run;
03034   config.detector=nu.detector;
03035   config.simFlag=nu.simFlag;
03036 
03037   config.runPeriod=nu.runPeriod;
03038   config.intensity = (Int_t) nu.intensity;
03039 
03040   config.anaVersion=nu.anaVersion;
03041   config.useGeneratorReweight=nu.useGeneratorReweight;
03042   config.reweightVersion=nu.reweightVersion;
03043   config.mcVersion=nu.mcVersion;
03044   config.recoVersion=nu.recoVersion;
03045   config.releaseType=nu.releaseType;
03046   config.beamType=nu.beamType;
03047   config.useDBForDataQuality=nu.useDBForDataQuality;
03048   config.useDBForSpillTiming=nu.useDBForSpillTiming;
03049   config.useDBForBeamInfo=nu.useDBForBeamInfo;
03050   config.cutOnDataQuality=nu.cutOnDataQuality;
03051   config.cutOnSpillTiming=nu.cutOnSpillTiming;
03052   config.cutOnBeamInfo=nu.cutOnBeamInfo;
03053 
03054   return config;
03055 }
03056 
03057 //......................................................................
03058 
03059 void NuDSTAna::UpdatePotSinceLastEvt(NuEvent& nu,
03060              Bool_t newEvt) const
03061 {
03062   //count the pots since the last evt was written to file
03063   static Float_t potSinceLastEvt=0;
03064   static Float_t potSinceLastEvtGood=0;
03065   static Float_t potSinceLastEvtBad=0;//this is always zero here
03066   static Float_t potSinceLastEvtDB=0;
03067   static Float_t potSinceLastEvtGoodDB=0;
03068   static Float_t potSinceLastEvtBadDB=0;
03069 
03070   if (newEvt) {
03071     //write out the pots since the last evt
03072     nu.potSinceLastEvt=potSinceLastEvt;
03073     nu.potSinceLastEvtGood=potSinceLastEvtGood;
03074     nu.potSinceLastEvtBad=potSinceLastEvtBad;
03075     nu.potSinceLastEvtDB=potSinceLastEvtDB;
03076     nu.potSinceLastEvtGoodDB=potSinceLastEvtGoodDB;
03077     nu.potSinceLastEvtBadDB=potSinceLastEvtBadDB;
03078     potSinceLastEvt=0;//reset this for the next loop
03079     potSinceLastEvtGood=0;
03080     potSinceLastEvtBad=0;
03081     potSinceLastEvtDB=0;
03082     potSinceLastEvtGoodDB=0;
03083     potSinceLastEvtBadDB=0;
03084   }
03085   else {
03086     potSinceLastEvt+=nu.potSinceLastEvt;
03087     potSinceLastEvtGood+=nu.potSinceLastEvtGood;
03088     potSinceLastEvtBad+=nu.potSinceLastEvtBad;
03089     potSinceLastEvtDB+=nu.potSinceLastEvtDB;
03090     potSinceLastEvtGoodDB+=nu.potSinceLastEvtGoodDB;
03091     potSinceLastEvtBadDB+=nu.potSinceLastEvtBadDB;
03092   }
03093 }
03094 
03095 //......................................................................
03096 
03097 
03098 void NuDSTAna::MakeMicroDST(const TString anaVersion, const TString xmlFilename)
03099 {
03100   //do the histogram IO
03101   NuOutputWriter output;
03102   NuInputEvents& input = this->DoIO(&output,("NuDSTMicro" + anaVersion).Data());
03103 
03104   // Set up useful and needed instances
03105   NuLibrary& lib=NuLibrary::Instance();
03106   const NuPlots* plots = 0;
03107 
03108   // Initialise the XML object
03109   auto_ptr<NuXMLConfig> xmlConfig;
03110   if (xmlFilename.IsNull()) {
03111     xmlConfig.reset(new NuXMLConfig());
03112   } else {
03113     xmlConfig.reset(new NuXMLConfig(xmlFilename));
03114   }
03115 
03116   // Decide which analysis version to use
03117   TString realAna;
03118   // If we have been given an ana version directly, use that.
03119   // Otherwise, use the string from the XML file
03120   if (!anaVersion.IsNull()) realAna = anaVersion;
03121   else realAna = xmlConfig->AnaVersionString();
03122   
03123   // Whichever we used, set the XML string now
03124   xmlConfig->SetAnaVersionString(realAna);
03125 
03126   // Save a copy to the output file
03127   xmlConfig->Write();
03128   
03129   // Build the cutter object
03130   NuCutter cutter(realAna, plots);
03131 
03135 
03136   cout<<endl
03137   <<"************************************************"<<endl
03138   <<"***      Starting main loop over snarls      ***"<<endl
03139   <<"************************************************"<<endl;
03140 
03141   input.ResetNuEventLoopPositionToStart();
03142 
03143   for (Int_t i=0;i<input.GetEntriesNuEvent();++i) {
03144     lib.cnt.evtCounter++;
03145 
03146     this->PrintLoopProgress(i,input.GetEntriesNuEvent(),1);
03147 
03148     NuEvent& nu=const_cast<NuEvent&>(input.GetNextNuEvent(Msg::kDebug));
03149 
03150     // Stop cutting on data quality for now
03151     //nu.useDBForDataQuality = false;
03152 
03153     // Record the POTs as they go past, so that when we get an event
03154     // that passes, it has the correct POT
03155     this->UpdatePotSinceLastEvt(nu,false);
03156     
03157     // Do the run reweighting
03158     if (-1==xmlConfig->RunPeriod()){
03159       MAXMSG("NuDSTAna",Msg::kInfo,5)
03160         <<"Not performing any reweighting" << endl;
03161       nu.applyBeamWeight = false;
03162     }
03163     //Should change rwActual, not beamWeight
03164     if (0==xmlConfig->RunPeriod()){
03165       nu.applyBeamWeight = true;
03166       nu.beamWeight = nu.beamWeight;
03167     }
03168     if (1==xmlConfig->RunPeriod()){
03169       nu.applyBeamWeight = true;
03170       nu.beamWeight = nu.beamWeightRunI;
03171       nu.trkEnWeight = nu.trkEnWeightRunI;
03172       nu.shwEnWeight = nu.shwEnWeightRunI;
03173       nu.detectorWeightNMB = nu.detectorWeightNMBRunI;
03174       nu.detectorWeightNM = nu.detectorWeightNMRunI;
03175     }
03176     if (2==xmlConfig->RunPeriod()){
03177       nu.applyBeamWeight = true;
03178       nu.beamWeight = nu.beamWeightRunII;
03179       nu.trkEnWeight = nu.trkEnWeightRunII;
03180       nu.shwEnWeight = nu.shwEnWeightRunII;
03181       nu.detectorWeightNMB = nu.detectorWeightNMBRunII;
03182       nu.detectorWeightNM = nu.detectorWeightNMRunII;
03183     }
03184 
03185     //RE-RECONSTRUCT the neutrino energy including kNN, reweight
03186     lib.reco.GetEvtEnergy(nu, true);
03187     lib.reco.ApplyReweights(nu);
03188     
03189     // Apply the systematic shift if required according to xmlConfig
03190     this->DoSystematicShifts(nu,xmlConfig.get());
03191     
03192     // Make the cuts!
03193     if (!cutter.MakeCuts(nu)) continue;
03194 
03195     // Oscillate if desired (to make fake data)
03196     this->Oscillate(nu,xmlConfig.get());
03197 
03198     // figure out the first and last time in the whole ntuple
03199     // this is very useful for making plots of quantities vs time
03200     // plots->FillNtupleEarliestLatestTime(nu);
03201 
03202     // Count the events to print to screen
03203     if      (nu.charge==-1) lib.cnt.nuNQCounter++;
03204     else if (nu.charge==+1) lib.cnt.nuPQCounter++;
03205     // else MSG("NuDSTAna",Msg::kWarning) << "Bad charge (" << nu.charge
03206     //         << ") found!" << endl;
03207 
03208 
03209     // Copy pots since last event to ntuple for this new evt
03210     this->UpdatePotSinceLastEvt(nu,true);
03211 
03212     //get the output nu to fill, copy nu to the output nu, fill tree
03213     NuEvent& nuOutput=output.GetNuEventToFill();
03214     nuOutput=nu;
03215     output.FillNuEventTree();
03216   }
03217 
03221 
03222   input.InitialiseNuMCEventBranch();
03223   input.ResetNuMCEventLoopPositionToStart();
03224 
03225   cout<<endl
03226   <<"************************************************"<<endl
03227   <<"***       Starting loop over truth info      ***"<<endl
03228   <<"************************************************"<<endl;
03229 
03230   for (Int_t i=0;i<input.GetEntriesNuMCEvent();++i) {
03231     lib.cnt.evtCounter++;
03232 
03233     this->PrintLoopProgress(i,input.GetEntriesNuMCEvent(),1);
03234 
03235     NuMCEvent& mc=const_cast<NuMCEvent&>(input.GetNextNuMCEvent
03236                                          (Msg::kDebug));
03237 
03238     //OVERRIDE
03239     // mc.anaVersion=this->SanityCheckedAnaVersion
03240     // (mc.anaVersion,overrideAnaVersion);
03241 
03242     MAXMSG("NuDSTAna",Msg::kInfo,5)
03243     <<"energyMC="<<mc.energyMC<<endl;
03244 
03245     // Make fid vol cut
03246     if (!cutter.GetCut()->InFidVolTrueEvt(mc)) continue;
03247 
03248     //override weights
03249     //mc.rw=mc.beamWeightRunI;
03250     if (-1==xmlConfig->RunPeriod()){
03251       mc.rw = 1.0;
03252     }
03253     //Should change rwActual, not beamWeight
03254     if (0==xmlConfig->RunPeriod()){
03255       mc.rw = mc.beamWeight;
03256     }
03257     if (1==xmlConfig->RunPeriod()){
03258       mc.rw = mc.beamWeightRunI;
03259     }
03260     if (2==xmlConfig->RunPeriod()){
03261       mc.rw = mc.beamWeightRunII;
03262     }
03263 
03264     this->Oscillate(mc,xmlConfig.get());
03265 
03266     //get the output nu to fill,copy mc to the output mc, fill tree
03267     NuMCEvent& mcOutput=output.GetNuMCEventToFill();
03268     mcOutput=mc;
03269     output.FillNuMCEventTree();
03270   }
03271 
03272   cutter.PrintSummary();
03273   
03274   //close the file and write out everything
03275   output.Finish();
03276 }
03277 
03278 //......................................................................
03279 
03280 void NuDSTAna::MakeMicroDstForCSSSystematics()
03281 {
03283 
03284   //do the histogram IO
03285   NuOutputWriter* poutput=new NuOutputWriter();
03286   NuInputEvents& input=this->DoIO(poutput,"NuDSTMicroCSS");
03287 
03288   //get a reference
03289   NuOutputWriter& output=(*poutput);
03290 
03291   //get an instance of the code library
03292   NuLibrary& lib=NuLibrary::Instance();
03293 
03294   //get plots object
03295   const NuPlots* plots=0;
03296 
03297   //version to do reco/cuts with
03298   NuCuts::NuAnaVersion_t overrideAnaVersion=NuCuts::kNMB0325Bravo;
03299 
03303 
03304   //prepare for loop
03305   input.ResetNuEventLoopPositionToStart();
03306 
03307   cout<<endl
03308       <<"************************************************"<<endl
03309       <<"***      Starting main loop over snarls      ***"<<endl
03310       <<"************************************************"<<endl;
03311 
03312   for (Int_t i=0;i<input.GetEntriesNuEvent();++i) {
03313     lib.cnt.evtCounter++;
03314 
03315     this->PrintLoopProgress(i,input.GetEntriesNuEvent(),1);
03316 
03317     NuEvent& nu=const_cast<NuEvent&>(input.GetNextNuEvent(Msg::kDebug));
03318 
03319     //OVERRIDE
03320     nu.anaVersion=this->SanityCheckedAnaVersion
03321       (nu.anaVersion,overrideAnaVersion);
03322 
03323     //count up the pots
03324     Bool_t newEvt=false;
03325     this->UpdatePotSinceLastEvt(nu,newEvt);
03326 
03327     //RE-RECONSTRUCT the neutrino energy, including kNN
03328     lib.reco.GetEvtEnergy(nu, true);
03329     lib.reco.ApplyReweights(nu);
03330 
03331     MAXMSG("NuDSTAna",Msg::kWarning,5)
03332       <<"Note: setting rw variable to use SKZP RunI beam weight"<<endl;
03333     nu.rw=nu.beamWeightRunI;
03334 
03335     //make the preselection cuts
03336     if (!this->IsGoodPreSelectionCuts(plots,nu)) continue;
03337 
03338     //NC PID taken out due to the fact that Andy's PID uses the charge
03339     //and the effect of this is not yet understood.
03340     //cut on the PID
03341     //if (!lib.cuts.IsGoodPID(nu)) {
03342     //continue;
03343     //}
03344     //lib.cnt.goodPIDCounter++;
03345 
03346     //figure out the first and last time in the whole ntuple
03347     //this is very useful for making plots of quantities vs time
03348     plots->FillNtupleEarliestLatestTime(nu);
03349 
03350     //count the events to print to screen
03351     if (nu.charge==-1) lib.cnt.nuNQCounter++;
03352     else if (nu.charge==+1) lib.cnt.nuPQCounter++;
03353 
03354     //copy pots since last event to ntuple for this new evt
03355     newEvt=true;
03356     this->UpdatePotSinceLastEvt(nu,newEvt);
03357 
03358     //get the output nu to fill, copy nu to the output nu, fill tree
03359     NuEvent& nuOutput=output.GetNuEventToFill();
03360     nuOutput=nu;
03361     output.FillNuEventTree();
03362   }
03363 
03367 
03368   input.InitialiseNuMCEventBranch();
03369   input.ResetNuMCEventLoopPositionToStart();
03370 
03371   cout<<endl
03372       <<"************************************************"<<endl
03373       <<"***       Starting loop over truth info      ***"<<endl
03374       <<"************************************************"<<endl;
03375 
03376   for (Int_t i=0;i<input.GetEntriesNuMCEvent();++i) {
03377     lib.cnt.evtCounter++;
03378 
03379     this->PrintLoopProgress(i,input.GetEntriesNuMCEvent(),1);
03380 
03381     NuMCEvent& mc=const_cast<NuMCEvent&>(input.GetNextNuMCEvent
03382                  (Msg::kDebug));
03383 
03384     //OVERRIDE
03385     mc.anaVersion=this->SanityCheckedAnaVersion
03386       (mc.anaVersion,overrideAnaVersion);
03387 
03388     MAXMSG("NuDSTAna",Msg::kInfo,5)
03389       <<"energyMC="<<mc.energyMC<<endl;
03390 
03391     //make fid vol cut
03392     if (!lib.cuts.IsInFidVolTrueEvt(mc)) continue;
03393 
03394     MAXMSG("NuDSTAna",Msg::kWarning,5)
03395       <<"Note: setting rw variable to use SKZP RunI beam weight"<<endl;
03396     mc.rw=mc.beamWeightRunI;
03397 
03398     //get the output nu to fill,copy mc to the output mc, fill tree
03399     NuMCEvent& mcOutput=output.GetNuMCEventToFill();
03400     mcOutput=mc;
03401     output.FillNuMCEventTree();
03402   }
03403 
03404   //print out the numbers of events
03405   lib.cnt.PrintMicroDST();
03406 
03407   //close the file and write out everything
03408   output.Finish();
03409 }
03410 
03411 //......................................................................
03412 
03413 void NuDSTAna::ConcatenateDSTs()
03414 {
03419 
03420   //do the histogram IO
03421   NuOutputWriter* poutput=new NuOutputWriter();
03422   NuInputEvents& input=this->DoIO(poutput,"NuDSTConcat");
03423 
03424   //get a reference
03425   NuOutputWriter& output=(*poutput);
03426 
03427   //get an instance of the code library
03428   NuLibrary& lib=NuLibrary::Instance();
03429 
03430   // This can be put back in as necessary. At the moment all it does
03431   // Is throw up an annoying compiler warning.
03432   // static const NuPlots* plots;
03433 
03437 
03438   //prepare for next loop
03439   input.ResetNuEventLoopPositionToStart();
03440 
03441   cout<<endl
03442       <<"************************************************"<<endl
03443       <<"***      Starting main loop over snarls      ***"<<endl
03444       <<"************************************************"<<endl;
03445 
03446   for (Int_t i=0;i<input.GetEntriesNuEvent();++i) {
03447     lib.cnt.evtCounter++;
03448 
03449     this->PrintLoopProgress(i,input.GetEntriesNuEvent(),1);
03450 
03451     NuEvent& nu=const_cast<NuEvent&>(input.GetNextNuEvent(Msg::kDebug));
03452 
03453     //make sanity check to avoid erroneous use
03454     this->SanityCheckAnaVersionSameAsPrevious(nu.anaVersion);
03455 
03457     //NO CUTS WHATSOEVER
03459 
03460     //count the events to print to screen after loop
03461     if (nu.charge==-1) lib.cnt.nuNQCounter++;
03462     else if (nu.charge==+1) lib.cnt.nuPQCounter++;
03463 
03464     //get the output nu to fill, copy nu to the output nu, fill tree
03465     NuEvent& nuOutput=output.GetNuEventToFill();
03466     nuOutput=nu;
03467     output.FillNuEventTree();
03468   }
03469 
03473 
03474   input.InitialiseNuMCEventBranch();
03475   input.ResetNuMCEventLoopPositionToStart();
03476 
03477   cout<<endl
03478       <<"************************************************"<<endl
03479       <<"***       Starting loop over truth info      ***"<<endl
03480       <<"************************************************"<<endl;
03481 
03482   for (Int_t i=0;i<input.GetEntriesNuMCEvent();++i) {
03483     lib.cnt.evtCounter++;
03484 
03485     this->PrintLoopProgress(i,input.GetEntriesNuMCEvent(),1);
03486 
03487     NuMCEvent& mc=const_cast<NuMCEvent&>(input.GetNextNuMCEvent
03488                  (Msg::kDebug));
03489 
03490     //make sanity check to avoid erroneous use
03491     this->SanityCheckAnaVersionSameAsPrevious(mc.anaVersion);
03492 
03493     MAXMSG("NuDSTAna",Msg::kInfo,5)
03494       <<"energyMC="<<mc.energyMC<<endl;
03495 
03497     //NO CUTS WHATSOEVER
03499 
03500     //get the output nu to fill,copy mc to the output mc, fill tree
03501     NuMCEvent& mcOutput=output.GetNuMCEventToFill();
03502     mcOutput=mc;
03503     output.FillNuMCEventTree();
03504   }
03505 
03506   //print out the numbers of events
03507   lib.cnt.PrintFullDST();
03508 
03509   //close the file and write out everything
03510   output.Finish();
03511 }
03512 
03513 //......................................................................
03514 
03515 void NuDSTAna::MakeSelMicroDST(Int_t selector)
03516 {
03517 
03519 
03520   //do the histogram IO
03521   NuOutputWriter* poutput=new NuOutputWriter();
03522   NuInputEvents& input=this->DoIO(poutput,"NuDSTMicroNMB11");
03523 
03524   //get a reference
03525   NuOutputWriter& output=(*poutput);
03526 
03527   //get an instance of the code library
03528   NuLibrary& lib=NuLibrary::Instance();
03529   const NuPlots* plots=0;
03530 
03531   //version to do reco/cuts with
03532   NuCuts::NuAnaVersion_t overrideAnaVersion=
03533     (NuCuts::NuAnaVersion_t)selector;
03534 
03538 
03539   //prepare for loop
03540   input.ResetNuEventLoopPositionToStart();
03541 
03542   cout<<endl
03543       <<"************************************************"<<endl
03544       <<"***      Starting main loop over snarls      ***"<<endl
03545       <<"************************************************"<<endl;
03546 
03547   for (Int_t i=0;i<input.GetEntriesNuEvent();++i) {
03548     lib.cnt.evtCounter++;
03549 
03550     this->PrintLoopProgress(i,input.GetEntriesNuEvent(),1);
03551 
03552     NuEvent& nu=const_cast<NuEvent&>(input.GetNextNuEvent(Msg::kDebug));
03553 
03554     //OVERRIDE
03555     nu.anaVersion=this->SanityCheckedAnaVersion
03556       (nu.anaVersion,overrideAnaVersion);
03557 
03558     //count up the pots
03559     Bool_t newEvt=false;
03560     this->UpdatePotSinceLastEvt(nu,newEvt);
03561 
03562     //RE-RECONSTRUCT the neutrino energy, including kNN
03563     lib.reco.GetEvtEnergy(nu, true);
03564     lib.reco.ApplyReweights(nu);
03565 
03566     //MAXMSG("NuDSTAna",Msg::kWarning,5)
03567     //<<"Note: setting rw variable to use SKZP RunI beam weight"<<endl;
03568     //nu.rw=nu.beamWeightRunI;
03569 
03570     //make the preselection cuts
03571     if (!this->IsGoodPreSelectionCuts(plots,nu)) continue;
03572 
03573     // Make the advanced cuts
03574     if (!this->IsGoodStdCuts(plots,nu)) continue;
03575 
03576     //figure out the first and last time in the whole ntuple
03577     //this is very useful for making plots of quantities vs time
03578     plots->FillNtupleEarliestLatestTime(nu);
03579 
03580     //count the events to print to screen
03581     if (nu.charge==-1) {
03582       lib.cnt.nuNQCounter++;
03583     }
03584     else if (nu.charge==+1) {
03585       lib.cnt.nuPQCounter++;
03586     }
03587 
03588     //copy pots since last event to ntuple for this new evt
03589     newEvt=true;
03590     this->UpdatePotSinceLastEvt(nu,newEvt);
03591 
03592     //get the output nu to fill, copy nu to the output nu, fill tree
03593     NuEvent& nuOutput=output.GetNuEventToFill();
03594     nuOutput=nu;
03595     output.FillNuEventTree();
03596   }
03597 
03601 
03602   input.InitialiseNuMCEventBranch();
03603   input.ResetNuMCEventLoopPositionToStart();
03604 
03605   cout<<endl
03606       <<"************************************************"<<endl
03607       <<"***       Starting loop over truth info      ***"<<endl
03608       <<"************************************************"<<endl;
03609 
03610   for (Int_t i=0;i<input.GetEntriesNuMCEvent();++i) {
03611     lib.cnt.evtCounter++;
03612 
03613     this->PrintLoopProgress(i,input.GetEntriesNuMCEvent(),1);
03614 
03615     NuMCEvent& mc=const_cast<NuMCEvent&>(input.GetNextNuMCEvent
03616                  (Msg::kDebug));
03617 
03618     //OVERRIDE
03619     mc.anaVersion=this->SanityCheckedAnaVersion
03620       (mc.anaVersion,overrideAnaVersion);
03621 
03622     MAXMSG("NuDSTAna",Msg::kInfo,5)
03623       <<"energyMC="<<mc.energyMC<<endl;
03624 
03625     //make fid vol cut
03626     if (!lib.cuts.IsInFidVolTrueEvt(mc)) continue;
03627 
03628     //MAXMSG("NuDSTAna",Msg::kWarning,5)
03629     //<<"Note: setting rw variable to use SKZP RunI beam weight"<<endl;
03630     //mc.rw=mc.beamWeightRunI;
03631 
03632     //get the output nu to fill,copy mc to the output mc, fill tree
03633     NuMCEvent& mcOutput=output.GetNuMCEventToFill();
03634     mcOutput=mc;
03635     output.FillNuMCEventTree();
03636   }
03637 
03638   //print out the numbers of events
03639   lib.cnt.PrintMicroDST();
03640 
03641   //close the file and write out everything
03642   output.Finish();
03643 }
03644 
03645 //......................................................................
03646 
03647 void NuDSTAna::MakeMicroDstWithStdCCRecoAndCuts()
03648 {
03650 
03651   //do the histogram IO
03652   NuOutputWriter* poutput=new NuOutputWriter();
03653   NuInputEvents& input=this->DoIO(poutput,"NuDSTMicroStdCC");
03654 
03655   //get a reference
03656   NuOutputWriter& output=(*poutput);
03657 
03658   //get an instance of the code library
03659   NuLibrary& lib=NuLibrary::Instance();
03660   const NuPlots* plots=0;
03661 
03662   //version to do reco/cuts with
03663   NuCuts::NuAnaVersion_t overrideAnaVersion=NuCuts::kCC0325Std;
03664 
03668 
03669   //prepare for loop
03670   input.ResetNuEventLoopPositionToStart();
03671 
03672   cout<<endl
03673       <<"************************************************"<<endl
03674       <<"***      Starting main loop over snarls      ***"<<endl
03675       <<"************************************************"<<endl;
03676 
03677   for (Int_t i=0;i<input.GetEntriesNuEvent();++i) {
03678     lib.cnt.evtCounter++;
03679 
03680     this->PrintLoopProgress(i,input.GetEntriesNuEvent(),1);
03681 
03682     NuEvent& nu=const_cast<NuEvent&>(input.GetNextNuEvent(Msg::kDebug));
03683 
03684     //OVERRIDE
03685     nu.anaVersion=this->SanityCheckedAnaVersion
03686       (nu.anaVersion,overrideAnaVersion);
03687 
03688     //count up the pots
03689     Bool_t newEvt=false;
03690     this->UpdatePotSinceLastEvt(nu,newEvt);
03691 
03692     //RE-RECONSTRUCT the neutrino energy, including kNN
03693     lib.reco.GetEvtEnergy(nu, true);
03694     lib.reco.ApplyReweights(nu);
03695 
03696     //MAXMSG("NuDSTAna",Msg::kWarning,5)
03697     //<<"Note: setting rw variable to use SKZP RunI beam weight"<<endl;
03698     //nu.rw=nu.beamWeightRunI;
03699 
03700     //make the preselection cuts
03701     if (!this->IsGoodPreSelectionCuts(plots,nu)) continue;
03702 
03703     //figure out the first and last time in the whole ntuple
03704     //this is very useful for making plots of quantities vs time
03705     plots->FillNtupleEarliestLatestTime(nu);
03706 
03707     //count the events to print to screen
03708     if (nu.charge==-1) {
03709       lib.cnt.nuNQCounter++;
03710     }
03711     else if (nu.charge==+1) {
03712       lib.cnt.nuPQCounter++;
03713     }
03714 
03715     //copy pots since last event to ntuple for this new evt
03716     newEvt=true;
03717     this->UpdatePotSinceLastEvt(nu,newEvt);
03718 
03719     //get the output nu to fill, copy nu to the output nu, fill tree
03720     NuEvent& nuOutput=output.GetNuEventToFill();
03721     nuOutput=nu;
03722     output.FillNuEventTree();
03723   }
03724 
03728 
03729   input.InitialiseNuMCEventBranch();
03730   input.ResetNuMCEventLoopPositionToStart();
03731 
03732   cout<<endl
03733       <<"************************************************"<<endl
03734       <<"***       Starting loop over truth info      ***"<<endl
03735       <<"************************************************"<<endl;
03736 
03737   for (Int_t i=0;i<input.GetEntriesNuMCEvent();++i) {
03738     lib.cnt.evtCounter++;
03739 
03740     this->PrintLoopProgress(i,input.GetEntriesNuMCEvent(),1);
03741 
03742     NuMCEvent& mc=const_cast<NuMCEvent&>(input.GetNextNuMCEvent
03743                  (Msg::kDebug));
03744 
03745     //OVERRIDE
03746     mc.anaVersion=this->SanityCheckedAnaVersion
03747       (mc.anaVersion,overrideAnaVersion);
03748 
03749     MAXMSG("NuDSTAna",Msg::kInfo,5)
03750       <<"energyMC="<<mc.energyMC<<endl;
03751 
03752     //make fid vol cut
03753     if (!lib.cuts.IsInFidVolTrueEvt(mc)) continue;
03754 
03755     //MAXMSG("NuDSTAna",Msg::kWarning,5)
03756     //<<"Note: setting rw variable to use SKZP RunI beam weight"<<endl;
03757     //mc.rw=mc.beamWeightRunI;
03758 
03759     //get the output nu to fill,copy mc to the output mc, fill tree
03760     NuMCEvent& mcOutput=output.GetNuMCEventToFill();
03761     mcOutput=mc;
03762     output.FillNuMCEventTree();
03763   }
03764 
03765   //print out the numbers of events
03766   lib.cnt.PrintMicroDST();
03767 
03768   //close the file and write out everything
03769   output.Finish();
03770 }
03771 
03772 //......................................................................
03773 
03774 void NuDSTAna::MakeMicroDstJJEPresel(int run)
03775 {
03777 
03778   //do the histogram IO
03779   NuOutputWriter* poutput=new NuOutputWriter();
03780   NuInputEvents& input=this->DoIO(poutput,"NuDSTMicroJJEPresel");
03781 
03782    
03783   //get a reference
03784   NuOutputWriter& output=(*poutput);
03785 
03786   //get an instance of the code library
03787   NuLibrary& lib=NuLibrary::Instance();
03788 
03789   //interface for the pids, plots
03790   NuPIDInterface pid;
03791   const NuPlots* plots=0;
03792 
03793   //version to do reco/cuts with
03794   NuCuts::NuAnaVersion_t overrideAnaVersion=NuCuts::kJJE1;
03795 
03799 
03800   //prepare for loop
03801   input.ResetNuEventLoopPositionToStart();
03802 
03803   cout<<endl
03804   <<"************************************************"<<endl
03805   <<"***      Starting main loop over snarls      ***"<<endl
03806   <<"************************************************"<<endl;
03807 
03808   for (Int_t i=0;i<input.GetEntriesNuEvent();++i) {
03809     lib.cnt.evtCounter++;
03810 
03811     this->PrintLoopProgress(i,input.GetEntriesNuEvent(),1);
03812 
03813     NuEvent& nu=const_cast<NuEvent&>(input.GetNextNuEvent(Msg::kDebug));
03814 
03815     // Stop cutting on data quality for now
03816     //nu.useDBForDataQuality = false;
03817     
03818     //OVERRIDE
03819     nu.anaVersion=this->SanityCheckedAnaVersion
03820     (nu.anaVersion,overrideAnaVersion);
03821 
03822     //count up the pots
03823     Bool_t newEvt=false;
03824     this->UpdatePotSinceLastEvt(nu,newEvt);
03825 
03826     if (run >= 0) {
03827       // LE Times
03828       int startRunI  = 1116619345; // 2005-05-20 20:02:25
03829       int endRunI    = 1140934189; // 2006-02-26 06:09:49
03830       int startRunII = 1158043200; // 2006-09-12 00:06:40
03831       int endRunII   = 1184352157; // 2007-07-13 18:42:37
03832 
03833       bool RunILE =  (nu.timeSec >= startRunI  && nu.timeSec <= endRunI);
03834       bool RunIILE = (nu.timeSec >= startRunII && nu.timeSec <= endRunII);
03835 
03836       if (run == 1 && !RunILE) continue;
03837       if (run == 2 && !RunIILE) continue;
03838       if (!RunILE && !RunIILE) continue;
03839     }
03840     
03841   
03842    
03843     
03844     //RE-RECONSTRUCT the neutrino energy including kNN, reweight
03845     lib.reco.GetEvtEnergy(nu, true);
03846     lib.reco.ApplyReweights(nu);
03847 
03848     if (nu.coilIsReverse != nu.hornIsReverse) {
03849       MAXMSG("NuDSTAna",Msg::kWarning,50) << "Found a " << (nu.coilIsReverse?"reversed":"forward") << " coil event in a " << (nu.hornIsReverse?"reversed":"forward")
03850       << " horn run.  The event is being kept, but there may be a problem!  This warning is expected for RHC MC." << endl;
03851     }
03852     
03853     
03854 //    // Hack to fix misreconstructed FD RHC MC
03855 //    if (nu.detector == Detector::kFar && nu.simFlag == SimFlag::kMC && nu.runPeriod == 4) {
03856 //      MAXMSG("NuDSTAna",Msg::kWarning,50) << "Reversing the charge for " << NuUtilities::PrintRelease(nu.releaseType) 
03857 //      << " events from RunPeriod 4.  This is because the first round of FD RHC Daikon07 MC was reconstructed with the wrong field." << endl
03858 //      << "Pleae confirm that results from these files make sense." << endl;
03859 //      
03860 //      nu.charge *= -1;
03861 //      nu.sigqp_qp *= -1;
03862 //      
03863 //      nu.qp *= -1;
03864 //      nu.qp_rangebiased *= -1;
03865 //      nu.qp_sigqp *= -1;
03866 //      nu.qp1 *= -1;
03867 //      nu.qp_rangebiased1 *= -1;
03868 //      nu.qp_sigqp1 *= -1;
03869 //      nu.qp2 *= -1;
03870 //      nu.qp_rangebiased2 *= -1;
03871 //      nu.qp_sigqp2 *= -1;
03872 //      nu.qp3 *= -1;
03873 //      nu.qp_rangebiased3 *= -1;
03874 //      nu.qp_sigqp3 *= -1;
03875 //    }
03876     
03877 
03878     //MAXMSG("NuDSTAna",Msg::kWarning,5)
03879     //<<"Note: setting rw variable to use SKZP RunI beam weight"<<endl;
03880     //nu.rw=nu.beamWeightRunI;
03881 
03882     //make the preselection cuts
03883     if (!this->IsGoodPreSelectionCuts(plots,nu)) continue;
03884 
03885     //figure out the first and last time in the whole ntuple
03886     //this is very useful for making plots of quantities vs time
03887     plots->FillNtupleEarliestLatestTime(nu);
03888 
03889     //count the events to print to screen
03890     if (nu.charge==-1) {
03891       lib.cnt.nuNQCounter++;
03892     }
03893     else if (nu.charge==+1) {
03894       lib.cnt.nuPQCounter++;
03895     }
03896 
03897     //copy pots since last event to ntuple for this new evt
03898     newEvt=true;
03899     this->UpdatePotSinceLastEvt(nu,newEvt);
03900 
03901     //get the output nu to fill, copy nu to the output nu, fill tree
03902     NuEvent& nuOutput=output.GetNuEventToFill();
03903     nuOutput=nu;
03904     output.FillNuEventTree();
03905   }
03906 
03910 
03911   input.InitialiseNuMCEventBranch();
03912   input.ResetNuMCEventLoopPositionToStart();
03913 
03914   cout<<endl
03915   <<"************************************************"<<endl
03916   <<"***       Starting loop over truth info      ***"<<endl
03917   <<"************************************************"<<endl;
03918 
03919   for (Int_t i=0;i<input.GetEntriesNuMCEvent();++i) {
03920     lib.cnt.evtCounter++;
03921 
03922     this->PrintLoopProgress(i,input.GetEntriesNuMCEvent(),1);
03923 
03924     NuMCEvent& mc=const_cast<NuMCEvent&>(input.GetNextNuMCEvent
03925                                          (Msg::kDebug));
03926 
03927     //OVERRIDE
03928     mc.anaVersion=this->SanityCheckedAnaVersion
03929     (mc.anaVersion,overrideAnaVersion);
03930 
03931     MAXMSG("NuDSTAna",Msg::kInfo,5)
03932     <<"energyMC="<<mc.energyMC<<endl;
03933 
03934     //make fid vol cut
03935     if (!lib.cuts.IsInFidVolTrueEvt(mc)) continue;
03936 
03937     //MAXMSG("NuDSTAna",Msg::kWarning,5)
03938     //<<"Note: setting rw variable to use SKZP RunI beam weight"<<endl;
03939     //mc.rw=mc.beamWeightRunI;
03940 
03941     //get the output nu to fill,copy mc to the output mc, fill tree
03942     NuMCEvent& mcOutput=output.GetNuMCEventToFill();
03943     mcOutput=mc;
03944     output.FillNuMCEventTree();
03945   }
03946 
03947   //print out the numbers of events
03948   lib.cnt.PrintMicroDST();
03949 
03950   //close the file and write out everything
03951   output.Finish();
03952 }
03953 
03954 //......................................................................
03955 
03956 void NuDSTAna::MakeMicroDst2010()
03957 {
03958   //do the histogram IO
03959   NuOutputWriter* poutput = new NuOutputWriter;
03960   NuInputEvents& input = DoIO(poutput, "NuDSTMicro2010");
03961 
03962   //get a reference
03963   NuOutputWriter& output=(*poutput);
03964 
03965   //get an instance of the code library
03966   NuLibrary& lib = NuLibrary::Instance();
03967 
03968   //interface for the pids, plots
03969   NuPIDInterface pid;
03970   const NuPlots* plots = 0;
03971 
03972   NuCutter ccCutter("CCA");
03973   NuCutter ncCutter("CCA_NC");
03974 
03978 
03979   //prepare for loop
03980   input.ResetNuEventLoopPositionToStart();
03981 
03982   cout<<endl
03983   <<"************************************************"<<endl
03984   <<"***      Starting main loop over snarls      ***"<<endl
03985   <<"************************************************"<<endl;
03986 
03987   for(int i = 0; i < input.GetEntriesNuEvent(); ++i){
03988     ++lib.cnt.evtCounter;
03989 
03990     PrintLoopProgress(i, input.GetEntriesNuEvent(), 1);
03991 
03992     NuEvent& nu = const_cast<NuEvent&>(input.GetNextNuEvent(Msg::kDebug));
03993 
03994     //OVERRIDE
03995     nu.anaVersion = SanityCheckedAnaVersion(nu.anaVersion, NuCuts::kCC0720Std);
03996 
03997     //count up the pots
03998     UpdatePotSinceLastEvt(nu, false);
03999 
04000     //RE-RECONSTRUCT the neutrino energy including kNN, reweight
04001     lib.reco.GetEvtEnergy(nu, true);
04002     lib.reco.ApplyReweights(nu);
04003 
04004     if(nu.coilIsReverse != nu.hornIsReverse){
04005       MAXMSG("NuDSTAna", Msg::kWarning, 50)
04006         << "Found a " << (nu.coilIsReverse ? "reversed" : "forward")
04007         << " coil event in a " << (nu.hornIsReverse ? "reversed" : "forward")
04008         << " horn run.  The event is being kept, but there may be a problem!"
04009         << " This warning is expected for RHC MC." << endl;
04010     }
04011 
04012     // Need to reset otherwise previous event failing will fail this one
04013     ccCutter.ResetStatus();
04014     ncCutter.ResetStatus();
04015 
04016     // Always do both so that the final statistics will make more sense
04017     ccCutter.MakePreselectionCuts(nu);
04018     ncCutter.MakePreselectionCuts(nu);
04019 
04020     // If the event passes either preselection then we keep it
04021     if(!ccCutter.Passed() && !ncCutter.Passed()) continue;
04022 
04023     //figure out the first and last time in the whole ntuple
04024     //this is very useful for making plots of quantities vs time
04025     plots->FillNtupleEarliestLatestTime(nu);
04026 
04027     //count the events to print to screen
04028     if(nu.charge == -1) ++lib.cnt.nuNQCounter;
04029     if(nu.charge == +1) ++lib.cnt.nuPQCounter;
04030 
04031     //copy pots since last event to ntuple for this new evt
04032     UpdatePotSinceLastEvt(nu, true);
04033 
04034     //get the output nu to fill, copy nu to the output nu, fill tree
04035     output.GetNuEventToFill() = nu;
04036     output.FillNuEventTree();
04037   } // end for i
04038 
04042 
04043   input.InitialiseNuMCEventBranch();
04044   input.ResetNuMCEventLoopPositionToStart();
04045 
04046   cout<<endl
04047   <<"************************************************"<<endl
04048   <<"***       Starting loop over truth info      ***"<<endl
04049   <<"************************************************"<<endl;
04050 
04051   for(int i = 0; i < input.GetEntriesNuMCEvent(); ++i){
04052     ++lib.cnt.evtCounter;
04053 
04054     PrintLoopProgress(i, input.GetEntriesNuMCEvent(), 1);
04055 
04056     NuMCEvent& mc = const_cast<NuMCEvent&>(input.GetNextNuMCEvent(Msg::kDebug));
04057 
04058     //OVERRIDE
04059     mc.anaVersion = SanityCheckedAnaVersion(mc.anaVersion, NuCuts::kCC0720Std);
04060 
04061     MAXMSG("NuDSTAna", Msg::kInfo,5) << "energyMC=" << mc.energyMC << endl;
04062 
04063     //make fid vol cut
04064     if(!lib.cuts.IsInFidVolTrueEvt(mc)) continue;
04065 
04066     //get the output nu to fill,copy mc to the output mc, fill tree
04067     output.GetNuMCEventToFill() = mc;
04068     output.FillNuMCEventTree();
04069   } // end for i
04070 
04071   ccCutter.PrintSummary();
04072   ncCutter.PrintSummary();
04073 
04074   //print out the numbers of events
04075   lib.cnt.PrintMicroDST();
04076 
04077   //close the file and write out everything
04078   output.Finish();
04079 }
04080 
04081 //......................................................................
04082 
04083 void NuDSTAna::MakeMicroDstHe(bool forceRHC)
04084 {
04087 
04088   //do the histogram IO
04089   NuOutputWriter* poutput=new NuOutputWriter();
04090   NuInputEvents& input=this->DoIO(poutput,"NuDSTPreselHe");
04091 
04092   //get a reference
04093   NuOutputWriter& output=(*poutput);
04094 
04095   //get an instance of the code library
04096   NuLibrary& lib=NuLibrary::Instance();
04097 
04098   //interface for the pids, plots
04099   NuPIDInterface pid;
04100   const NuPlots* plots=0;
04101 
04102   //version to do reco/cuts with
04103   NuCuts::NuAnaVersion_t overrideAnaVersion=NuCuts::kJJE1;
04104 
04108 
04109   //prepare for loop
04110   input.ResetNuEventLoopPositionToStart();
04111 
04112   cout<<endl
04113   <<"************************************************"<<endl
04114   <<"***      Starting main loop over snarls      ***"<<endl
04115   <<"************************************************"<<endl;
04116 
04117   for (Int_t i=0;i<input.GetEntriesNuEvent();++i) {
04118     lib.cnt.evtCounter++;
04119 
04120     this->PrintLoopProgress(i,input.GetEntriesNuEvent(),1);
04121 
04122     NuEvent& nu=const_cast<NuEvent&>(input.GetNextNuEvent(Msg::kDebug));
04123 
04124     if (nu.simFlag != SimFlag::kMC) {
04125       MSG("NuDSTAna",Msg::kError) << "Cout this is not an MC file -- He reweighting is inappropriate.  Bailing." << endl;
04126       assert(false);
04127     }
04128 
04129     if (ReleaseType::IsDaikon(nu.releaseType) &&
04130         ReleaseType::GetMCSubVersion(nu.releaseType) > 4) {
04131       MSG("NuDSTAna",Msg::kError) << "Trying to make an NuDSTPreselHe for releaseType = "
04132       << NuUtilities::PrintRelease(nu.releaseType)
04133       << " -- He should already be accounted for.  Use MakeMicroDstJJEPresel().  Bailing." << endl;
04134       assert(false);
04135     }
04136 
04137 
04138     if (forceRHC) {
04139       if (nu.runPeriod == 4) {
04140         MAXMSG("NuDSTAna",Msg::kWarning, 10) << "This file already seems to be RHC -- no forcing need, but done anyways." << endl;
04141       }
04142       else if (nu.runPeriod != 0) {
04143         MAXMSG("NuDSTAna",Msg::kWarning, 10) << "This file has runPeriod=" << nu.runPeriod
04144         << " so it should know if it is RHC.  Forcing anyways but you've been warned." << endl;
04145       }
04146 
04147       // Force some parameters:
04148       nu.runPeriod = 4;
04149       nu.hornIsReverse = true;
04150       nu.beamType = BeamType::kL010z185i_rev;
04151 
04152       // Redo the beam weights
04153       lib.zBeamReweight.ExtractZBeamReweight(nu);
04154 
04155       //Reweighting
04156       nu.applyBeamWeight = true;
04157     }
04158 
04159 
04160     //OVERRIDE
04161     nu.anaVersion=this->SanityCheckedAnaVersion
04162     (nu.anaVersion,overrideAnaVersion);
04163 
04164     //count up the pots
04165     Bool_t newEvt=false;
04166     this->UpdatePotSinceLastEvt(nu,newEvt);
04167 
04168 
04169     //RE-RECONSTRUCT the neutrino energy including kNN, reweight
04170     lib.reco.GetEvtEnergy(nu, true);
04171     lib.reco.ApplyReweights(nu);
04172     nu.rw *= lib.zBeamReweight.GetWeightHelium(nu);
04173 
04174     if (nu.coilIsReverse != nu.hornIsReverse) {
04175       MAXMSG("NuDSTAna",Msg::kWarning,50) << "Found a reversed coil event.  Skipping it, but POT counting will be off!" << endl;
04176       continue;
04177     }
04178 
04179     //MAXMSG("NuDSTAna",Msg::kWarning,5)
04180     //<<"Note: setting rw variable to use SKZP RunI beam weight"<<endl;
04181     //nu.rw=nu.beamWeightRunI;
04182 
04183     //make the preselection cuts
04184     if (!this->IsGoodPreSelectionCuts(plots,nu)) continue;
04185 
04186     //figure out the first and last time in the whole ntuple
04187     //this is very useful for making plots of quantities vs time
04188     plots->FillNtupleEarliestLatestTime(nu);
04189 
04190     //count the events to print to screen
04191     if (nu.charge==-1) {
04192       lib.cnt.nuNQCounter++;
04193     }
04194     else if (nu.charge==+1) {
04195       lib.cnt.nuPQCounter++;
04196     }
04197 
04198     //copy pots since last event to ntuple for this new evt
04199     newEvt=true;
04200     this->UpdatePotSinceLastEvt(nu,newEvt);
04201 
04202     //get the output nu to fill, copy nu to the output nu, fill tree
04203     NuEvent& nuOutput=output.GetNuEventToFill();
04204     nuOutput=nu;
04205     output.FillNuEventTree();
04206   }
04207 
04211 
04212   input.InitialiseNuMCEventBranch();
04213   input.ResetNuMCEventLoopPositionToStart();
04214 
04215   cout<<endl
04216   <<"************************************************"<<endl
04217   <<"***       Starting loop over truth info      ***"<<endl
04218   <<"************************************************"<<endl;
04219 
04220   for (Int_t i=0;i<input.GetEntriesNuMCEvent();++i) {
04221     lib.cnt.evtCounter++;
04222 
04223     this->PrintLoopProgress(i,input.GetEntriesNuMCEvent(),1);
04224 
04225     NuMCEvent& mc=const_cast<NuMCEvent&>(input.GetNextNuMCEvent
04226                                          (Msg::kDebug));
04227 
04228     //OVERRIDE
04229     mc.anaVersion=this->SanityCheckedAnaVersion
04230     (mc.anaVersion,overrideAnaVersion);
04231 
04232     MAXMSG("NuDSTAna",Msg::kInfo,5)
04233     <<"energyMC="<<mc.energyMC<<endl;
04234 
04235     //make fid vol cut
04236     if (!lib.cuts.IsInFidVolTrueEvt(mc)) continue;
04237 
04238     //MAXMSG("NuDSTAna",Msg::kWarning,5)
04239     //<<"Note: setting rw variable to use SKZP RunI beam weight"<<endl;
04240     //mc.rw=mc.beamWeightRunI;
04241 
04242     //get the output nu to fill,copy mc to the output mc, fill tree
04243     NuMCEvent& mcOutput=output.GetNuMCEventToFill();
04244     mcOutput=mc;
04245     output.FillNuMCEventTree();
04246   }
04247 
04248   //print out the numbers of events
04249   lib.cnt.PrintMicroDST();
04250 
04251   //close the file and write out everything
04252   output.Finish();
04253 }
04254 
04255 //......................................................................
04256 
04257 void NuDSTAna::MakeMicroDstFakeData(bool presel)
04258 {
04260 
04261     //do the histogram IO
04262     NuOutputWriter* poutput=new NuOutputWriter();
04263     TString name;
04264     if (presel) name = "NuDSTMicroFakeData";
04265     else        name = "NuDSTFullFakeData";
04266     NuInputEvents& input=this->DoIO(poutput,name.Data());
04267 
04268     //get a reference
04269     NuOutputWriter& output=(*poutput);
04270 
04271     //get an instance of the code library
04272     NuLibrary& lib=NuLibrary::Instance();
04273 
04274     //interface for the pids, plots
04275     NuPIDInterface pid;
04276     const NuPlots* plots=0;
04277 
04278     //version to do reco/cuts with
04279     NuCuts::NuAnaVersion_t overrideAnaVersion=NuCuts::kJJE1;
04280 
04281     // Make an xmlConfig object for oscilaltions
04282     NuXMLConfig *xmlConfig = new NuXMLConfig();
04283     xmlConfig->SetCPT();
04284     xmlConfig->Write("NuXMLConfig");
04285 
04289 
04290     //prepare for loop
04291     input.ResetNuEventLoopPositionToStart();
04292 
04293     cout<<endl
04294     <<"************************************************"<<endl
04295     <<"***      Starting main loop over snarls      ***"<<endl
04296     <<"************************************************"<<endl;
04297 
04298 
04299     int RunIPart = static_cast<Int_t>(input.GetEntriesNuEvent() *
04300                                       1.27 / 3.21);
04301 
04302     for (Int_t i=0;i<input.GetEntriesNuEvent();++i) {
04303         lib.cnt.evtCounter++;
04304 
04305         this->PrintLoopProgress(i,input.GetEntriesNuEvent(),1);
04306 
04307         NuEvent& nu=const_cast<NuEvent&>(input.GetNextNuEvent(Msg::kDebug));
04308 
04309         //OVERRIDE
04310         nu.anaVersion=this->SanityCheckedAnaVersion
04311         (nu.anaVersion,overrideAnaVersion);
04312 
04313         //count up the pots
04314         Bool_t newEvt=false;
04315         this->UpdatePotSinceLastEvt(nu,newEvt);
04316 
04317         //OVERRIDE
04318         //Selection
04319         nu.anaVersion=this->SanityCheckedAnaVersion
04320         (nu.anaVersion,overrideAnaVersion);
04321 
04322 
04323         if (i < RunIPart){
04324             nu.applyBeamWeight = true;
04325             nu.beamWeight = nu.beamWeightRunI;
04326             nu.trkEnWeight = nu.trkEnWeightRunI;
04327             nu.shwEnWeight = nu.shwEnWeightRunI;
04328             nu.detectorWeightNMB = nu.detectorWeightNMBRunI;
04329             nu.detectorWeightNM = nu.detectorWeightNMRunI;
04330         }
04331         else{
04332             nu.applyBeamWeight = true;
04333             nu.beamWeight = nu.beamWeightRunII;
04334             nu.trkEnWeight = nu.trkEnWeightRunII;
04335             nu.shwEnWeight = nu.shwEnWeightRunII;
04336             nu.detectorWeightNMB = nu.detectorWeightNMBRunII;
04337             nu.detectorWeightNM = nu.detectorWeightNMRunII;
04338         }
04339 
04340         //RE-RECONSTRUCT the neutrino energy, including kNN
04341         lib.reco.GetEvtEnergy(nu, true);
04342         lib.reco.ApplyReweights(nu);
04343 
04344         //Oscillate if desired (to make fake data)
04345         this->Oscillate(nu,xmlConfig);
04346 
04347         // PoID Officially depracated
04348         // Add in Pedro's pid's
04349         // pid.GetPoID(nu);
04350 
04351         //make the preselection cuts
04352         if (presel) {
04353             if (!this->IsGoodPreSelectionCuts(plots,nu)) continue;
04354         }
04355 
04356         //figure out the first and last time in the whole ntuple
04357         //this is very useful for making plots of quantities vs time
04358         plots->FillNtupleEarliestLatestTime(nu);
04359 
04360         //count the events to print to screen
04361         if (nu.charge==-1) {
04362             lib.cnt.nuNQCounter++;
04363         }
04364         else if (nu.charge==+1) {
04365             lib.cnt.nuPQCounter++;
04366         }
04367 
04368         //copy pots since last event to ntuple for this new evt
04369         newEvt=true;
04370         this->UpdatePotSinceLastEvt(nu,newEvt);
04371 
04372         //get the output nu to fill, copy nu to the output nu, fill tree
04373         NuEvent& nuOutput=output.GetNuEventToFill();
04374         nuOutput=nu;
04375         output.FillNuEventTree();
04376     }
04377 
04381 
04382     input.InitialiseNuMCEventBranch();
04383     input.ResetNuMCEventLoopPositionToStart();
04384 
04385     cout<<endl
04386     <<"************************************************"<<endl
04387     <<"***       Starting loop over truth info      ***"<<endl
04388     <<"************************************************"<<endl;
04389 
04390     RunIPart = static_cast<Int_t>(input.GetEntriesNuMCEvent() *
04391                                   1.27 / 3.21);
04392 
04393     for (Int_t i=0;i<input.GetEntriesNuMCEvent();++i) {
04394         lib.cnt.evtCounter++;
04395 
04396         this->PrintLoopProgress(i,input.GetEntriesNuMCEvent(),1);
04397 
04398         NuMCEvent& mc=const_cast<NuMCEvent&>(input.GetNextNuMCEvent
04399                                              (Msg::kDebug));
04400 
04401         //OVERRIDE
04402         mc.anaVersion=this->SanityCheckedAnaVersion
04403         (mc.anaVersion,overrideAnaVersion);
04404 
04405         MAXMSG("NuDSTAna",Msg::kInfo,5)
04406         <<"energyMC="<<mc.energyMC<<endl;
04407 
04408         //make fid vol cut
04409         if (!lib.cuts.IsInFidVolTrueEvt(mc)) continue;
04410 
04411 
04412         if (i < RunIPart){
04413             mc.rw=mc.beamWeightRunI;
04414       }
04415         else{
04416             mc.rw=mc.beamWeightRunII;
04417         }
04418 
04419         //Oscillate if desired (to make fake data)
04420         this->Oscillate(mc,xmlConfig);
04421 
04422         //get the output nu to fill,copy mc to the output mc, fill tree
04423         NuMCEvent& mcOutput=output.GetNuMCEventToFill();
04424         mcOutput=mc;
04425         output.FillNuMCEventTree();
04426     }
04427 
04428     //print out the numbers of events
04429     lib.cnt.PrintMicroDST();
04430 
04431     //close the file and write out everything
04432     output.Finish();
04433 }
04434 
04435 //......................................................................
04436 
04437 void NuDSTAna::MakeFCTree(TString xmlFileName)
04438 {
04439   NuInputEvents& input=this->DoIO(0,"","null");
04440   //get an instance of the code library
04441   NuLibrary& lib=NuLibrary::Instance();
04442   //get an object to fill plots
04443   const NuPlots* plots=0;
04444   //Get the NuXMLConfig object for configuration.
04445   NuXMLConfig* xmlConfig = 0;
04446   if (xmlFileName.IsNull()) {
04447     xmlConfig = new NuXMLConfig();
04448     xmlConfig->Write();
04449   }
04450   else {
04451     xmlConfig = new NuXMLConfig(xmlFileName);
04452     xmlConfig->Write();
04453   }
04454 
04455   //version to do reco/cuts with
04456   NuCuts::NuAnaVersion_t overrideAnaVersion =
04457   static_cast<NuCuts::NuAnaVersion_t>(xmlConfig->AnaVersion());
04458 
04459   const NuUtilities cuts;
04460 
04461   TDirectory *save = gDirectory;
04462   gDirectory->pwd();
04463 
04464   const char* type = "FCTree";
04465 
04466   cout << "Create the dummy event" << endl;
04467   NuFCEvent *dummy_nu = new NuFCEvent();
04468   cout << "Create tree type " << type << endl;
04469   TTree *tree = new TTree(type,type);
04470   cout << "Create branch" << endl;
04471   tree->Branch("NuFCEvent","NuFCEvent",&dummy_nu,32000,2);
04472   cout<<"Tree initialized."<<endl;
04473 
04477 
04478   input.ResetNuEventLoopPositionToStart();
04479 
04480   cout<<endl
04481   <<"************************************************"<<endl
04482   <<"***      Starting main loop over snarls      ***"<<endl
04483   <<"************************************************"<<endl;
04484 
04485   for (Int_t i=0;i<input.GetEntriesNuEvent();++i) {
04486 
04487     lib.cnt.evtCounter++;
04488     //this->PrintLoopProgress(i,input.GetEntriesNuEvent(),1);
04489 
04490     NuEvent &nu=const_cast<NuEvent&>(input.GetNextNuEvent(Msg::kInfo));
04491 
04492     //OVERRIDE
04493     //Selection
04494     nu.anaVersion=this->SanityCheckedAnaVersion
04495     (nu.anaVersion,overrideAnaVersion);
04496     //Reweighting
04497     if (-1==xmlConfig->RunPeriod()){
04498       MAXMSG("NuFarNear",Msg::kInfo,5)
04499       <<"Not performing any reweighting" << endl;
04500       nu.applyBeamWeight = false;
04501     }
04502     //Should change rwActual, not beamWeight
04503     if (0==xmlConfig->RunPeriod()){
04504       nu.applyBeamWeight = true;
04505       nu.beamWeight = nu.beamWeight;
04506     }
04507     if (1==xmlConfig->RunPeriod()){
04508       nu.applyBeamWeight = true;
04509       nu.beamWeight = nu.beamWeightRunI;
04510       nu.trkEnWeight = nu.trkEnWeightRunI;
04511       nu.shwEnWeight = nu.shwEnWeightRunI;
04512       nu.detectorWeightNMB = nu.detectorWeightNMBRunI;
04513       nu.detectorWeightNM = nu.detectorWeightNMRunI;
04514     }
04515     if (2==xmlConfig->RunPeriod()){
04516       nu.applyBeamWeight = true;
04517       nu.beamWeight = nu.beamWeightRunII;
04518       nu.trkEnWeight = nu.trkEnWeightRunII;
04519       nu.shwEnWeight = nu.shwEnWeightRunII;
04520       nu.detectorWeightNMB = nu.detectorWeightNMBRunII;
04521       nu.detectorWeightNM = nu.detectorWeightNMRunII;
04522     }
04523 
04524     //RE-RECONSTRUCT the neutrino energy
04525     lib.reco.GetEvtEnergy(nu, false);
04526     lib.reco.ApplyReweights(nu);
04527 
04528     // No Systematics
04529     //this->DoSystematicShifts(nu,xmlConfig);
04530 
04531     //Get NuMuBars only
04532     if (!lib.cuts.IsGoodQP(nu)) continue;
04533 
04534     //make all the std cuts
04535     if (!this->IsGoodStdCuts(plots,nu)) continue;
04536 
04537     //this is added to vary cuts via xml
04538     if (xmlConfig->AnaVersion() == 16 && nu.charge>0){
04539       if(!lib.cuts.FreeCuts(nu,xmlConfig))continue;
04540     }
04541 
04542     // No oscillations
04543     //this->Oscillate(nu,xmlConfig);
04544 
04545     if (nu.charge==-1) lib.cnt.nuNQCounter++;
04546     else if (nu.charge==+1) lib.cnt.nuPQCounter++;
04547     else cout<<"ahhh, bad charge (4)"<<endl;
04548 
04549     //cout << "About to extract" << endl;
04550     dummy_nu->Extract(nu);
04551     //cout << "Extracted.  About to fill." << endl;
04552     tree->Fill();
04553     //cout << "Filled.  About to reset." << endl;
04554     dummy_nu->Reset();
04555 
04556     MAXMSG("NuFarNear",Msg::kInfo,5)
04557     <<"Passed: index="<<nu.index
04558     <<", energy="<<nu.energy<<", energyMC="<<nu.energyMC<<endl;
04559   }//end of loop over summary tree
04560 
04561   save->cd();
04562   tree->Write();
04563 
04567   //print out the numbers of events
04568   lib.cnt.PrintMicroDST();
04569 
04570   MSG("NuDSTAna",Msg::kInfo)
04571   <<" ** Finished MakeFCTree method **"<<endl;
04572 }
04573 
04574 //......................................................................
04575 
04576 void NuDSTAna::MakeDstPQ()
04577 {
04579 
04580   //do the histogram IO
04581   NuOutputWriter* poutput=new NuOutputWriter();
04582   NuInputEvents& input=this->DoIO(poutput,"NuDSTMicroPQ");
04583 
04584   //get a reference
04585   NuOutputWriter& output=(*poutput);
04586 
04587   //get an instance of the code library
04588   NuLibrary& lib=NuLibrary::Instance();
04589 
04590   input.ResetNuEventLoopPositionToStart();
04591 
04595 
04596   cout<<endl
04597       <<"************************************************"<<endl
04598       <<"***      Starting main loop over snarls      ***"<<endl
04599       <<"************************************************"<<endl;
04600 
04601   for (Int_t i=0;i<input.GetEntriesNuEvent();++i) {
04602     lib.cnt.evtCounter++;
04603 
04604     this->PrintLoopProgress(i,input.GetEntriesNuEvent(),1);
04605 
04606     NuEvent& nu=const_cast<NuEvent&>(input.GetNextNuEvent(Msg::kDebug));
04607 
04608     //count up the pots
04609     Bool_t newEvt=false;
04610     this->UpdatePotSinceLastEvt(nu,newEvt);
04611 
04612     //speed up cut for looking at nmb only
04613     if (nu.charge==-1) {
04614       lib.cnt.nuNQCounter++;
04615       if (nu.inu < 0) {//need the mis-id ones for eff/pur plots
04616         //keep these
04617       }
04618       else {
04619         continue;
04620       }
04621     }
04622 
04623     if (nu.charge==+1) {
04624       lib.cnt.nuPQCounter++;
04625     }
04626 
04627     //copy pots since last event to ntuple for this new evt
04628     newEvt=true;
04629     this->UpdatePotSinceLastEvt(nu,newEvt);
04630 
04631     //get the output nu to fill, copy across and fill tree
04632     NuEvent& nuOutput=output.GetNuEventToFill();
04633     nuOutput=nu;
04634     output.FillNuEventTree();
04635   }
04636 
04637   //print out the numbers of events
04638   lib.cnt.PrintMicroDST();
04639 
04640   //close the file and write out everything
04641   output.Finish();
04642 }
04643 
04644 //......................................................................
04645 
04646 void NuDSTAna::OverwriteSntpBeamDataInNtuple(NuEvent& nu)
04647 {
04648 
04649   //lib.ext.ExtractBeamInfoDB(nu);
04650   //static Int_t lastSnarl=-1;
04651   //static Float_t potCounter=0;
04652   //Bool_t goodBeam=lib.cuts.IsGoodBeam(nu);
04654   //if (nu.snarl!=lastSnarl && goodBeam) {
04655   //potCounter+=nu.potSinceLastEvtDB;
04656   //}
04657   //lastSnarl=nu.snarl;
04658   //MAXMSG("NuDSTAna",Msg::kInfo,100)
04659   //<<"Pot from DB="<<nu.potDB<<", snarl="<<nu.snarl
04660   //<<", running total="<<potCounter<<endl;
04661 
04662   MAXMSG("NuDSTAna",Msg::kWarning,100)
04663     <<"Overwriting beam data in NuEvent (ntuple)"<<endl;
04664 
04665   //use the values from the beam
04666   nu.goodBeamSntp=nu.goodBeam;
04667   nu.pot=nu.potDB;
04668   nu.potSinceLastEvt=nu.potSinceLastEvtDB;
04669   nu.potSinceLastEvtGood=nu.potSinceLastEvtGoodDB;
04670   nu.potSinceLastEvtBad=nu.potSinceLastEvtBadDB;
04671 }
04672 
04673 //......................................................................
04674 
04675 void NuDSTAna::OverwriteCoilDataInNtuple(NuEvent& nu)
04676 {
04677   MAXMSG("NuDSTAna",Msg::kWarning,100)
04678     <<"Overwriting coil data in NuEvent (ntuple)"<<endl;
04679 
04680   //just assume that it's true
04681   nu.coilIsOk=true;
04682 }
04683 
04684 //......................................................................
04685 
04686 void NuDSTAna::VsTime()
04687 {
04691 
04692   NuInputEvents& input=this->DoIO(NULL,"VsTime");
04693   //get an instance of the code library
04694   NuLibrary& lib=NuLibrary::Instance();
04695 
04696   //get objects to fill plots
04697   const NuPlots* plots=new NuPlots();
04698   NuTime time;
04699 
04700   //get the earliest and latest times in order to define the time range
04701   TH1I* hNtupleEarliestTime=
04702     (TH1I*)gROOT->FindObject("hNtupleEarliestTime");
04703   TH1I* hNtupleLatestTime=
04704     (TH1I*)gROOT->FindObject("hNtupleLatestTime");
04705   Int_t earliestTime=1;
04706   Int_t latestTime=1;
04707   if (hNtupleLatestTime && hNtupleEarliestTime) {
04708     earliestTime=static_cast<Int_t>(hNtupleEarliestTime->Integral());
04709     latestTime=static_cast<Int_t>(hNtupleLatestTime->Integral());
04710     MAXMSG("NuDSTAna",Msg::kInfo,100)
04711       <<"Ntuple: earliestTime="<<earliestTime
04712       <<", latestTime="<<latestTime<<endl;
04713   }
04714   else {
04715     MSG("NuDSTAna",Msg::kError)
04716       <<"Ahhh, no earliest and latest time histos, aborting..."<<endl;
04717     assert(false);
04718   }
04719 
04720   //version to do reco/cuts with
04721   //NuCuts::NuAnaVersion_t overrideAnaVersion=NuCuts::kCC0250Std
04722   NuCuts::NuAnaVersion_t overrideAnaVersion=NuCuts::kNMB0325Bravo;
04723 
04727 
04728   cout<<endl
04729       <<"************************************************"<<endl
04730       <<"***      Starting main loop over snarls      ***"<<endl
04731       <<"************************************************"<<endl;
04732 
04733   for (Int_t i=0;i<input.GetEntriesNuEvent();++i) {
04734   //for (Int_t i=0;i<0;++i) {
04735     lib.cnt.evtCounter++;
04736 
04737     this->PrintLoopProgress(i,input.GetEntriesNuEvent(),1);
04738 
04739     NuEvent& nu=const_cast<NuEvent&>(input.GetNextNuEvent(Msg::kDebug));
04740 
04741     //OVERRIDE
04742     nu.anaVersion=this->SanityCheckedAnaVersion
04743       (nu.anaVersion,overrideAnaVersion);
04744 
04748     //only do this if you absolutely have to
04749     //and don't commit the code without these commented out
04750     //this->OverwriteCoilDataInNtuple(nu);
04751     //this->OverwriteSntpBeamDataInNtuple(nu);
04752     //nu.potSinceLastEvtGoodDB=nu.potSinceLastEvtDB;//Good not written to file
04753 
04754     //count up the good pots in the file (according to the sntp data or the database)
04755     if (nu.goodBeamSntp && nu.coilIsOk) lib.cnt.totalPot+=nu.potSinceLastEvtGood;
04756     if (nu.goodBeam && nu.coilIsOk) lib.cnt.totalPotDB+=nu.potSinceLastEvtGoodDB;
04757 
04758     //RE-RECONSTRUCT the neutrino energy
04759     //lib.reco.GetEvtEnergy(nu);
04760     //lib.reco.ApplyReweights(nu);
04761 
04762     //count up the pots
04763     Bool_t newEvt=false;
04764     this->UpdatePotSinceLastEvt(nu,newEvt);
04765 
04766     //fill vs time histos with just minimum number of cuts
04767     if (lib.cuts.IsGoodNumberOfTracks(nu) &&
04768         lib.cuts.IsInFidVolTrk(nu) &&
04769         !lib.cuts.IsLI(nu) &&
04770         lib.cuts.IsGoodTimeToNearestSpill(nu) &&
04771         lib.cuts.IsGoodPID(nu)) {
04772       MAXMSG("NuDSTAna",Msg::kDebug,5)
04773         <<"Filling timeAll..."<<endl;
04774 
04775       //copy pots since last event to ntuple for this new evt
04776       newEvt=true;
04777       this->UpdatePotSinceLastEvt(nu,newEvt);
04778 
04779       //fill the vs time histos
04780       time.FillVsTimeHistos2(nu,earliestTime,latestTime,"All");
04781     }
04782 
04783     //make the preselection cuts
04784     //if (!this->IsGoodPreSelectionCuts(plots,nu)) continue;
04785 
04786     //make all the std cuts
04787     if (!this->IsGoodStdCuts(plots,nu)) continue;
04788 
04789     if (nu.charge==-1) {
04790       lib.cnt.nuNQCounter++;
04791     }
04792     else if (nu.charge==+1) {
04793       lib.cnt.nuPQCounter++;
04794     }
04795     else cout<<"ahhh, bad charge (5)"<<endl;
04796 
04798     //fill the vs time histos
04799     time.FillVsTimeHistos(nu,earliestTime,latestTime);
04800 
04801     MAXMSG("NuDSTAna",Msg::kInfo,5)
04802       <<"Passed: index="<<nu.index
04803       <<", energy="<<nu.energy<<", energyMC="<<nu.energyMC<<endl;
04804   }//end of loop over summary tree
04805 
04806   MSG("NuAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
04807 
04811 
04812   //print out the numbers of events
04813   lib.cnt.PrintMicroDST();
04814 
04815   MSG("NuAnalysis",Msg::kInfo)
04816     <<" ** Finished VsTime method **"<<endl;
04817 }
04818 
04819 //......................................................................
04820 
04821 void NuDSTAna::JeffsTestAna()
04822 {
04823   NuInputEvents& input=this->DoIO();
04824 
04825   //use config object to store info
04826   NuConfig config;
04827   config.detector=Detector::kFar;
04828   config.run=100;
04829 
04830   //text files to store info for evts passing cuts
04831   string sTxt="nmb";//nubars
04832   ofstream& nmbTxt=*(this->OpenTxtFile(config,sTxt.c_str()));
04833   string sTxtNM="nm";//neutrinos
04834   ofstream& nmTxt=*(this->OpenTxtFile(config,sTxtNM.c_str()));
04835 
04836   //get an instance of the code library
04837   NuLibrary& lib=NuLibrary::Instance();
04838 
04839   //get an object to fill plots
04840   const NuPlots* plots=new NuPlots();
04841 
04842   //version to do reco/cuts with
04843   NuCuts::NuAnaVersion_t overrideAnaVersion=NuCuts::kCC0250Std;
04844 
04848 
04849   input.ResetNuEventLoopPositionToStart();
04850 
04851   cout<<endl
04852       <<"************************************************"<<endl
04853       <<"***      Starting main loop over snarls      ***"<<endl
04854       <<"************************************************"<<endl;
04855 
04856   for (Int_t i=0;i<input.GetEntriesNuEvent();++i) {
04857     lib.cnt.evtCounter++;
04858 
04859     this->PrintLoopProgress(i,input.GetEntriesNuEvent(),1);
04860 
04861     NuEvent& nu=const_cast<NuEvent&>(input.GetNextNuEvent(Msg::kDebug));
04862 
04863     //OVERRIDE
04864     nu.anaVersion=this->SanityCheckedAnaVersion
04865       (nu.anaVersion,overrideAnaVersion);
04866 
04867     //cut on new 0.8m radius
04868     const Float_t beamzerox=1.4828*(Munits::m);//new for 2.5 analysis
04869     const Float_t beamzeroy=0.2384*(Munits::m);//new for 2.5 analysis
04870     Bool_t inFid=lib.cuts.IsInCylindricalVolume
04871       (nu.xTrkVtx,nu.yTrkVtx,nu.zTrkVtx,beamzerox,beamzeroy,
04872        1*(Munits::m),5*(Munits::m),0.8*(Munits::m));
04873     if (!inFid) continue;
04874 
04875     //RE-RECONSTRUCT the neutrino energy
04876     lib.reco.GetEvtEnergy(nu, false);
04877     lib.reco.ApplyReweights(nu);
04878 
04879     //make all the std cuts
04880     if (!this->IsGoodStdCuts(plots,nu)) continue;
04881 
04882     if (nu.charge==-1) {
04883       plots->PrintEventInfo(nmTxt,nu);
04884       lib.cnt.nuNQCounter++;
04885     }
04886     else if (nu.charge==+1) {
04887       plots->PrintEventInfo(nmbTxt,nu);
04888       lib.cnt.nuPQCounter++;
04889     }
04890     else cout<<"ahhh, bad charge(6)"<<endl;
04891 
04892 
04893 
04894 
04895     //OVERRIDE
04896     nu.anaVersion=NuCuts::kNMB0325Bravo;
04897 
04898 
04899     //cut on the PID
04900     if (!lib.cuts.IsGoodPID(nu)) {
04901       plots->FillDPIdSigmaQPFailDpIDCutPlots(nu);
04902       continue;
04903     }
04904     lib.cnt.goodPIDCounter++;
04905     plots->FillDPIdSigmaQPPassDpIDCutPlots(nu);
04906 
04907     //cut on the fractional track momentum and sign error
04908     if (!lib.cuts.IsGoodSigmaQP_QP(nu)) {
04909       plots->FillDPIdSigmaQPFailSigQPCutPlots(nu);
04910       continue;
04911     }
04912     lib.cnt.goodFitSigQPCounter++;
04913     plots->FillDPIdSigmaQPPassSigQPCutPlots(nu);
04914 
04915     //cut on the track fit probability
04916     if (!lib.cuts.IsGoodFitProb(nu)) {
04917       plots->FillDPIdSigmaQPFailProbCutPlots(nu);
04918       continue;
04919     }
04920     lib.cnt.goodFitProbCounter++;
04921 
04922 
04923 
04924 
04925 
04926 
04927     //make the final plots
04928     this->MakeFinalPlots(plots,nu);
04929 
04930     //fill matrix method histos
04931     lib.hist.FillMatrixMethodHistos(nu);
04932 
04933     MAXMSG("NuDSTAna",Msg::kInfo,5)
04934       <<"Passed: index="<<nu.index
04935       <<", energy="<<nu.energy<<", energyMC="<<nu.energyMC<<endl;
04936   }
04937 
04938   //print out the numbers of events
04939   lib.cnt.PrintMicroDST();
04940 
04941 
04942 /*
04943   for (Int_t i=0;i<input.GetEntriesNuEvent();++i) {
04944   //for (Int_t i=0;i<0;++i) {
04945     lib.cnt.evtCounter++;
04946 
04947     this->PrintLoopProgress(i,input.GetEntriesNuEvent(),1);
04948 
04949     NuEvent& nu=const_cast<NuEvent&>(input.GetNextNuEvent(Msg::kDebug));
04950 
04951     //speed up cut for looking at nmb only
04952     //if (nu.charge==-1) continue;
04953 
04954     //OVERRIDE
04955     nu.anaVersion=NuCuts::kCC0250Std;
04956     //nu.applyEnergyShifts=false;
04957     //nu.applyBeamWeight=true;
04958     //nu.applyDetectorWeight=false;
04959     //nu.applyGeneratorWeight=false;
04960     //nu.cutOnDataQuality=false;
04961 
04962     nu.anaVersion=NuCuts::kNMB0325Bravo;
04963 
04964     //RE-RECONSTRUCT the neutrino energy
04965     lib.reco.GetEvtEnergy(nu);
04966     lib.reco.ApplyReweights(nu);
04967 
04968     nu.anaVersion=NuCuts::kCC0250Std;
04969 
04970     //Bool_t passFid=lib.cuts.IsInFidVolOffset(nu);
04971     //if (!passFid) continue;
04972     //if (passFid) continue;//for Anti-FV
04973 
04974     //if (nu.ntrk==1) continue;
04975     //if (nu.ntrk>=2) continue;
04976 
04977     //select specific true events
04978     //if (nu.charge==-1) continue;//remove NQ events
04979     //if (nu.inu==-14) continue;//remove the true nubars
04980     //if (nu.iaction==1) continue;//remove the CC events
04981 
04983     //START OF STD CUTS
04985 
04986     //cut on the sntp good beam and that coil is on
04987     if (!lib.cuts.IsGoodBeamDetPOTCountingStage(nu)) continue;
04988     lib.cnt.goodBeamDetPOTCountingStage++;
04989 
04990     //ensure good number of tracks in the event
04991     if (!lib.cuts.IsGoodNumberOfTracks(nu)) continue;
04992     lib.cnt.evtWithTrkCounter++;
04993 
04994     //check if the trk is in the fiducial volume
04995     if (!lib.cuts.IsInFidVolTrk(nu)) continue;
04996     lib.cnt.trkInFidVolCounter++;
04997 
04998     //cut on LI
04999     if (lib.cuts.IsLI(nu)) continue;
05000     lib.cnt.evtNotIsLI++;
05001 
05002     //cut on the data quality
05003     if (!lib.cuts.IsGoodDataQuality(nu)) continue;
05004     lib.cnt.goodDataQualityCounter++;
05005 
05006     //cut on the spill time
05007     plots->FillEvtAndSpillTimingPlots(nu);
05008     if (!lib.cuts.IsGoodTimeToNearestSpill(nu)) continue;
05009     lib.cnt.goodTimeToNearestSpillCounter++;
05010 
05011     //cut on the beam
05012     if (!lib.cuts.IsGoodBeam(nu)) continue;
05013     lib.cnt.goodBeamInfoDBCounter++;
05014 
05015     //require a good trk fit
05016     if (!lib.cuts.IsGoodTrackFitPass(nu)) continue;
05017     lib.cnt.goodTrkPassCounter++;
05018 
05019     //require a forward going neutrino about beam direction
05020     if (!lib.cuts.IsGoodDirCos(nu)) continue;
05021     lib.cnt.goodDirectionCosineCounter++;
05022 
05023     //make the post-preselection plots
05024     this->MakePostPreSelectionPlots(plots,nu);
05025 
05026 
05027     //OVERRIDE
05028     nu.anaVersion=NuCuts::kNMB0325Bravo;
05029 
05033     //Float_t r=pow(nu.xTrkEnd,2)+pow(nu.yTrkEnd,2);
05034     //if (r) r=sqrt(r);
05035     //if (r<0.5) continue;
05036     //if (nu.planeTrkEnd-nu.planeTrkBeg<50) continue;
05037 
05038     //cut on the PID
05039     if (!lib.cuts.IsGoodPID(nu)) {
05040       plots->FillDPIdSigmaQPFailDpIDCutPlots(nu);
05041       continue;
05042     }
05043     lib.cnt.goodPIDCounter++;
05044     plots->FillDPIdSigmaQPPassDpIDCutPlots(nu);
05045 
05046     //cut on the fractional track momentum and sign error
05047     if (!lib.cuts.IsGoodSigmaQP_QP(nu)) {
05048       plots->FillDPIdSigmaQPFailSigQPCutPlots(nu);
05049       continue;
05050     }
05051     lib.cnt.goodFitSigQPCounter++;
05052     plots->FillDPIdSigmaQPPassSigQPCutPlots(nu);
05053 
05054     //cut on the track fit probability
05055     if (!lib.cuts.IsGoodFitProb(nu)) {
05056       plots->FillDPIdSigmaQPFailProbCutPlots(nu);
05057       continue;
05058     }
05059     lib.cnt.goodFitProbCounter++;
05060 
05062     //END OF STD CUTS
05064 
05065     if (nu.charge==-1) {
05066       plots->PrintEventInfo(nmTxt,nu);
05067       lib.cnt.nuNQCounter++;
05068     }
05069     else if (nu.charge==+1) {
05070       plots->PrintEventInfo(nmbTxt,nu);
05071       lib.cnt.nuPQCounter++;
05072     }
05073     else cout<<"ahhh, bad charge"<<endl;
05074 
05075     //make the final plots
05076     this->MakeFinalPlots(plots,nu);
05077 
05078     //fill matrix method histos
05079     lib.hist.FillMatrixMethodHistos(nu);
05080 
05081     MAXMSG("NuDSTAna",Msg::kInfo,5)
05082       <<"Passed: index="<<nu.index
05083       <<", energy="<<nu.energy<<", energyMC="<<nu.energyMC<<endl;
05084   }//end of loop over summary tree
05085 */
05086 
05087 
05091 
05092   input.InitialiseNuMCEventBranch();
05093   input.ResetNuMCEventLoopPositionToStart();
05094 
05095   cout<<endl
05096       <<"************************************************"<<endl
05097      <<"***       Starting loop over truth info      ***"<<endl
05098       <<"************************************************"<<endl;
05099 
05100   //for (Int_t i=0;i<input.GetEntriesNuMCEvent();++i) {
05101   for (Int_t i=0;i<0;++i) {
05102     lib.cnt.evtCounter++;
05103 
05104     this->PrintLoopProgress(i,input.GetEntriesNuMCEvent(),1);
05105 
05106     NuMCEvent& mc=const_cast<NuMCEvent&>(input.GetNextNuMCEvent
05107                  (Msg::kDebug));
05108 
05109     //OVERRIDE
05110     mc.anaVersion=this->SanityCheckedAnaVersion
05111       (mc.anaVersion,overrideAnaVersion);
05112 
05113     MAXMSG("NuDSTAna",Msg::kInfo,5)
05114       <<"energyMC="<<mc.energyMC<<endl;
05115 
05116     //make fid vol cut
05117     if (!lib.cuts.IsInFidVolTrueEvt(mc)) continue;
05118 
05119     //fill plots
05120     plots->FillTrueFidEnergySpect(mc);
05121     plots->FillTrueFidEnergySpectSpecial(mc);
05122   }
05123 
05124   MSG("NuAnalysis",Msg::kInfo)
05125     <<" ** Finished JeffsTestAna method **"<<endl;
05126 }
05127 
05128 //......................................................................
05129 
05130 void NuDSTAna::SanityCheckAnaVersionSameAsPrevious
05131 (Int_t anaVersion) const
05132 {
05133   //sanity check that the same analysis version is used in all
05134   //the files to be concatenated... could be nasty otherwise
05135   //Note: can't use SanityCheckedAnaVersion() due to kFull
05136 
05137   //get an instance of the code library
05138   const NuLibrary& lib=NuLibrary::Instance();
05139 
05140   static const Int_t firstAnaVersion=anaVersion;
05141   if (anaVersion!=firstAnaVersion) {
05142     MSG("NuDSTAna",Msg::kError)
05143       <<"Different analysis version found, anaVersion="
05144       <<lib.cuts.AsString(static_cast<NuCuts::NuAnaVersion_t>
05145               (anaVersion))
05146       <<", first version="
05147       <<lib.cuts.AsString(static_cast<NuCuts::NuAnaVersion_t>
05148               (firstAnaVersion))
05149       <<endl<<"Aborting..."<<endl;
05150     assert(false);
05151   }
05152 }
05153 
05154 //......................................................................
05155 
05156 Int_t NuDSTAna::SanityCheckedAnaVersion(Int_t anaVersion,
05157                 Int_t overrideAnaVersion) const
05158 {
05159   //get an instance of the code library
05160   //const NuLibrary& lib=NuLibrary::Instance();
05161 
05162   //sanity check that the right DST was used
05163     if (!(anaVersion==overrideAnaVersion ||
05164           anaVersion==NuCuts::kFullDST)) {
05165       //give up on this for now... trust the users... and pray
05166 
05167       //MAXMSG("NuDSTAna",Msg::kError,5)
05168       //<<"Note: the DSTs were reconstructed with a different"
05169       //<<" analysis version, anaVersion="
05170       //<<lib.cuts.AsString(static_cast<NuCuts::NuAnaVersion_t>
05171       //                    (anaVersion))<<endl
05172       //<<"Only FullDSTs or micro DSTs with anaVersion="
05173       //         <<lib.cuts.AsString(static_cast<NuCuts::NuAnaVersion_t>
05174       //                 (overrideAnaVersion))
05175       //<<" should be used here, aborting..."<<endl;
05176 
05177       //assert(false);
05178     }
05179     //return the analysis version (could be kFullDST)
05180     return overrideAnaVersion;
05181 }
05182 
05183 //......................................................................
05184 
05185 void NuDSTAna::StdCCAna()
05186 {
05187   NuInputEvents& input=this->DoIO();
05188 
05189   //use config object to store info
05190   NuConfig config;
05191   config.detector=Detector::kFar;
05192   config.run=100;
05193 
05194   //text files to store info for evts passing cuts
05195   string sTxt="nmb";//nubars
05196   ofstream& nmbTxt=*(this->OpenTxtFile(config,sTxt.c_str()));
05197   string sTxtNM="nm";//neutrinos
05198   ofstream& nmTxt=*(this->OpenTxtFile(config,sTxtNM.c_str()));
05199 
05200   //get an instance of the code library
05201   NuLibrary& lib=NuLibrary::Instance();
05202 
05203   //get an object to fill plots
05204   const NuPlots* plots=new NuPlots();
05205 
05206   //version to do reco/cuts with
05207   //NuCuts::NuAnaVersion_t overrideAnaVersion=NuCuts::kCC0250Std;
05208   NuCuts::NuAnaVersion_t overrideAnaVersion=NuCuts::kCC0325Std;
05209 
05213 
05214   input.ResetNuEventLoopPositionToStart();
05215 
05216   cout<<endl
05217       <<"************************************************"<<endl
05218       <<"***      Starting main loop over snarls      ***"<<endl
05219       <<"************************************************"<<endl;
05220 
05221   for (Int_t i=0;i<input.GetEntriesNuEvent();++i) {
05222     lib.cnt.evtCounter++;
05223 
05224     this->PrintLoopProgress(i,input.GetEntriesNuEvent(),1);
05225 
05226     NuEvent& nu=const_cast<NuEvent&>(input.GetNextNuEvent(Msg::kDebug));
05227 
05228     //set ana version
05229     nu.anaVersion=this->SanityCheckedAnaVersion
05230       (nu.anaVersion,overrideAnaVersion);
05231 
05232     //RE-RECONSTRUCT the neutrino energy
05233     lib.reco.GetEvtEnergy(nu, false);//this re-reconstructs the neutrino energy
05234     lib.reco.ApplyReweights(nu);
05235 
05236     //make all the std cuts
05237     if (!this->IsGoodStdCuts(plots,nu)) continue;
05238 
05239     if (nu.charge==-1) {
05240       plots->PrintEventInfo(nmTxt,nu);
05241       lib.cnt.nuNQCounter++;
05242     }
05243     else if (nu.charge==+1) {
05244       plots->PrintEventInfo(nmbTxt,nu);
05245       lib.cnt.nuPQCounter++;
05246     }
05247     else cout<<"ahhh, bad charge (7)"<<endl;
05248 
05249     //make the final plots
05250     this->MakeFinalPlots(plots,nu);
05251 
05252     //fill matrix method histos
05253     lib.hist.FillMatrixMethodHistos(nu);
05254 
05255     MAXMSG("NuDSTAna",Msg::kInfo,5)
05256       <<"Passed: index="<<nu.index
05257       <<", energy="<<nu.energy<<", energyMC="<<nu.energyMC<<endl;
05258   }//end of loop over summary tree
05259 
05263 
05264   input.InitialiseNuMCEventBranch();
05265   input.ResetNuMCEventLoopPositionToStart();
05266 
05267   cout<<endl
05268       <<"************************************************"<<endl
05269      <<"***       Starting loop over truth info      ***"<<endl
05270       <<"************************************************"<<endl;
05271 
05272   for (Int_t i=0;i<input.GetEntriesNuMCEvent();++i) {
05273     lib.cnt.evtCounter++;
05274 
05275     this->PrintLoopProgress(i,input.GetEntriesNuMCEvent(),1);
05276 
05277     NuMCEvent& mc=const_cast<NuMCEvent&>(input.GetNextNuMCEvent
05278                  (Msg::kDebug));
05279 
05280     //set ana version
05281     mc.anaVersion=this->SanityCheckedAnaVersion
05282       (mc.anaVersion,overrideAnaVersion);
05283 
05284     MAXMSG("NuDSTAna",Msg::kInfo,5)
05285       <<"energyMC="<<mc.energyMC<<endl;
05286 
05287     //make fid vol cut
05288     if (!lib.cuts.IsInFidVolTrueEvt(mc)) continue;
05289 
05290     //fill plots
05291     plots->FillTrueFidEnergySpect(mc);
05292     plots->FillTrueFidEnergySpectSpecial(mc);
05293   }
05294 
05295   MSG("NuAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
05296 
05300 
05301   //print out the numbers of events
05302   lib.cnt.PrintMicroDST();
05303 
05304   MSG("NuAnalysis",Msg::kInfo)
05305     <<" ** Finished StdCCAna method **"<<endl;
05306 }
05307 
05308 //......................................................................
05309 
05310 Bool_t NuDSTAna::IsGoodPreSelectionCuts(const NuPlots* plots,
05311                                         const NuEvent& nu) const
05312 {
05313   // In order to move over to the new cuts system, the cutting logic
05314   // has been moved. See NuCutsSelection.cxx for the implementation of
05315   // this function
05316   NuCutImps::NuCutsSelection cut(nu.anaVersion, plots);
05317   return cut.MakePreselectionCuts(nu);
05318 }
05319 
05320 //......................................................................
05321 
05322 Bool_t NuDSTAna::IsGoodStdCuts(const NuPlots* plots,
05323                                const NuEvent& nu) const
05324 {
05325   // In order to move over to the new cuts system, the cutting logic
05326   // has been moved. See NuCutsSelection.cxx for the implementation of
05327   // this function
05328   NuCutImps::NuCutsSelection cut(nu.anaVersion, plots);
05329   return cut.MakeCuts(nu);
05330 }
05331 
05332 //......................................................................
05333 
05334 void NuDSTAna::MakePostPreSelectionPlots(const NuPlots* plots,
05335                  const NuEvent& nu) const
05336 {
05337   // In order to move over to the new cuts system, the cutting logic
05338   // has been moved. See NuCutsSelection.cxx for the implementation of
05339   // this function
05340   NuCutImps::NuCutsSelection cut(plots);
05341   cut.MakePostPreSelectionPlots(nu);
05342 }
05343 
05344 //......................................................................
05345 
05346 void NuDSTAna::MakeFinalPlots(const NuPlots* plots,
05347                               const NuEvent& nu) const
05348 {
05349   //same list as in NuAnalysis, but with trk/evt ones commented out
05350   plots->FillRecoEnYHistosN(nu);
05351   plots->FillDPIdSigmaQPPlotsN(nu);
05352   plots->FillEnergyBinHistos(nu);
05353 
05354   //plots->FillShwHistos(ntp,evt,nu);
05355   plots->FillUVHistos(nu);
05356   plots->FillXYZHistos(nu);
05357   plots->FillContainmentHistos(nu);
05358   plots->FillRelativeAngleHistos(nu);
05359   plots->FillTruePIDHistos(nu);
05360   //plots->FillTrackResponseHistos(ntp,trk,nu);
05361   plots->FillRangeCurvCompHistos(nu);
05362   plots->FillKinematicsHistos(nu);
05363 }
05364 
05365 //......................................................................
05366 
05367 void NuDSTAna::MMAna(std::string sOutputFileName)
05368 {
05369   this->DoIO(0,"",sOutputFileName);
05370 }
05371 
05372 //....................................................................72
05373 void NuDSTAna::DoSystematicShifts(NuEvent& event,
05374           const NuXMLConfig* xmlConfig) const
05375 {
05376   if (!xmlConfig){
05377     MAXMSG("NuDSTAna",Msg::kInfo,5)
05378       << "No NuXMLConfig object supplied: "
05379       << "performing no systematic shifts."
05380       << endl;
05381     return;
05382   } else if (xmlConfig->Name().IsNull()) {
05383     MAXMSG("NuDSTAna",Msg::kInfo,5)
05384       << "No Shift supplied in XML. Not doing shifts."
05385       << endl;
05386     return;
05387   } else {
05388     MAXMSG("NuDSTAna",Msg::kInfo,5)
05389       << "Performing systematic shift "
05390       << xmlConfig->FullTitle()
05391       << endl;
05392     static NuSystematic nuSyst(*xmlConfig);
05393     nuSyst.Shift(event);
05394     return;
05395   }
05396 }
05397 
05398 //......................................................................
05399 
05400 void NuDSTAna::MMRereco(std::string sOutputFileName,
05401                         TString xmlFileName)
05402 {
05403   NuInputEvents& input=this->DoIO(0,"",sOutputFileName);
05404 
05405   //get an instance of the code library
05406   NuLibrary& lib=NuLibrary::Instance();
05407 
05408   //get an object to fill plots
05409   const NuPlots* plots=new NuPlots();
05410 
05411   //Get the NuXMLConfig object for configuration.
05412   NuXMLConfig* xmlConfig = 0;
05413   if (xmlFileName.IsNull()) {
05414     xmlConfig = new NuXMLConfig();
05415     xmlConfig->Write();
05416   }
05417   else {
05418     xmlConfig = new NuXMLConfig(xmlFileName);
05419     xmlConfig->Write();
05420   }
05421 
05422   //Binning scheme
05423   NuBinningScheme::NuBinningScheme_t binningScheme =
05424     static_cast<NuBinningScheme::NuBinningScheme_t>(xmlConfig->BinningScheme());
05425 
05426   // Create the cutter objects
05427   NuCutter cutter(xmlConfig->AnaVersionString(), plots);
05428   NuCutter NCcutter;
05429 
05430   //version to do reco/cuts with
05431   NuCuts::NuAnaVersion_t overrideAnaVersion =
05432     static_cast<NuCuts::NuAnaVersion_t>(cutter.AnaVersion());
05433   
05434   // Check to see if the user wants to do an NC cut along with the CC one
05435   if (! xmlConfig->GetUnknownKey("anaVersionNC").IsNull()) {
05436     MSG("NuDSTAna",Msg::kInfo) << "Found anaVersionNC in configuration... Doing additional NC cuts" << endl;
05437     NCcutter.SetCut(xmlConfig->GetUnknownKey("anaVersionNC"));
05438   }
05439   else{
05440     MSG("NuDSTAna",Msg::kInfo) << "Didn't find anaVersionNC key in configuration. No NC histograms will be produced." << endl;
05441   }
05442   
05446 
05447   input.ResetNuEventLoopPositionToStart();
05448 
05449   cout<<endl
05450       <<"************************************************"<<endl
05451       <<"***      Starting main loop over snarls      ***"<<endl
05452       <<"************************************************"<<endl;
05453   for (Int_t i=0;i<input.GetEntriesNuEvent();++i) {
05454 
05455     lib.cnt.evtCounter++;
05456 
05457     this->PrintLoopProgress(i,input.GetEntriesNuEvent(),1);
05458 
05459     NuEvent &nu=const_cast<NuEvent&>(input.GetNextNuEvent(Msg::kDebug));
05460 
05461     //OVERRIDE
05462     //Selection
05463     nu.anaVersion=this->SanityCheckedAnaVersion
05464       (nu.anaVersion,overrideAnaVersion);
05465     //Reweighting
05466     if (-1==xmlConfig->RunPeriod()){
05467       MAXMSG("NuDSTAna",Msg::kInfo,5)
05468         <<"Not performing any reweighting" << endl;
05469       nu.applyBeamWeight = false;
05470     }
05471     //Should change rwActual, not beamWeight
05472     if (0==xmlConfig->RunPeriod()){
05473       nu.applyBeamWeight = true;
05474       nu.beamWeight = nu.beamWeight;
05475     }
05476     if (1==xmlConfig->RunPeriod()){
05477       nu.applyBeamWeight = true;
05478       nu.beamWeight = nu.beamWeightRunI;
05479       nu.trkEnWeight = nu.trkEnWeightRunI;
05480       nu.shwEnWeight = nu.shwEnWeightRunI;
05481       nu.detectorWeightNMB = nu.detectorWeightNMBRunI;
05482       nu.detectorWeightNM = nu.detectorWeightNMRunI;
05483     }
05484     if (2==xmlConfig->RunPeriod()){
05485       nu.applyBeamWeight = true;
05486       nu.beamWeight = nu.beamWeightRunII;
05487       nu.trkEnWeight = nu.trkEnWeightRunII;
05488       nu.shwEnWeight = nu.shwEnWeightRunII;
05489       nu.detectorWeightNMB = nu.detectorWeightNMBRunII;
05490       nu.detectorWeightNM = nu.detectorWeightNMRunII;
05491     }
05492 
05493     
05494     //RE-RECONSTRUCT the neutrino energy
05495     lib.reco.GetEvtEnergy(nu, false);
05496 
05497     lib.reco.ApplyReweights(nu);
05498 
05499     //apply the systematic shift if required according to xmlConfig
05500     this->DoSystematicShifts(nu,xmlConfig);
05501 
05502     // Do the cuts:
05503     cutter.MakeCuts(nu);
05504     NCcutter.MakeCuts(nu);
05505     
05506     // If neither of these passed, continue
05507     if (cutter.Failed() && NCcutter.Failed()) continue;
05508 
05509     // For now, print a warning if the event passes both cuts. If we care, we can 
05510     // print more information out here
05511     if (cutter.Passed() && NCcutter.Passed()) {
05512       MAXMSG("NuDSTAna",Msg::kWarning, 10) << "Event passed multiple cuts!" << endl;
05513     }
05514     // Oscillate if desired (to make fake data)
05515     this->Oscillate(nu,xmlConfig);
05516 
05517     // did we pass the (CC?) selection?
05518     if (cutter.Passed()) {
05519       // making the cuts via the xml
05520       MAXMSG("NuDSTAna",Msg::kInfo,5)
05521         <<"xmlcut: "  << xmlConfig->AnaVersionString()
05522         <<" charge: " << nu.charge << endl;
05523         
05524       // Process dave's free cuts stuff
05525       if (xmlConfig->AnaVersion() == 16 && nu.charge>0){
05526         if(!lib.cuts.FreeCuts(nu,xmlConfig))continue;
05527       }
05528       //make the final plots
05529       //if (plots) this->MakeFinalPlots(plots,nu);
05530 
05531       if (nu.charge==-1) lib.cnt.nuNQCounter++;
05532       else if (nu.charge==+1) lib.cnt.nuPQCounter++;
05533       else cout<<"ahhh, bad charge (8)"<<endl;
05534 
05535       //fill matrix method histos
05536       lib.hist.FillMatrixMethodHistos(nu, binningScheme);
05537 
05538         MAXMSG("NuDSTAna",Msg::kInfo,5)
05539           <<"Passed: index="<<nu.index
05540           <<", energy="<<nu.energy<<", energyMC="<<nu.energyMC<<endl;
05541     }
05542     
05543     // Now, if we selected NC:
05544     if (NCcutter.Passed()) {
05545       lib.hist.FillMatrixMethodNCHistos(nu, binningScheme);
05546     }
05547     
05548   }//end of loop over summary tree
05549 
05550 
05551   input.InitialiseNuMCEventBranch();
05552   input.ResetNuMCEventLoopPositionToStart();
05553 
05557 
05558   input.InitialiseNuMCEventBranch();
05559   input.ResetNuMCEventLoopPositionToStart();
05560 
05561   cout<<endl
05562       <<"************************************************"<<endl
05563      <<"***       Starting loop over truth info      ***"<<endl
05564       <<"************************************************"<<endl;
05565 
05566   for (Int_t i=0;i<input.GetEntriesNuMCEvent();++i) {
05567     lib.cnt.evtCounter++;
05568 
05569     this->PrintLoopProgress(i,input.GetEntriesNuMCEvent(),1);
05570 
05571     NuMCEvent& mc=const_cast<NuMCEvent&>(input.GetNextNuMCEvent
05572                  (Msg::kDebug));
05573 
05574     //OVERRIDE
05575     //Selection
05576     mc.anaVersion=this->SanityCheckedAnaVersion
05577       (mc.anaVersion,overrideAnaVersion);
05578 
05579     MAXMSG("NuDSTAna",Msg::kInfo,5)
05580       <<"energyMC="<<mc.energyMC<<endl;
05581 
05582 
05583     //make fid vol cut
05584     //if (!lib.cuts.IsInFidVolTrueEvt(mc)) continue;
05585     if (!cutter.GetCut()->InFidVolTrueEvt(mc)) continue;
05586     
05587     //override weights
05588     //mc.rw=mc.beamWeightRunI;
05589     if (-1==xmlConfig->RunPeriod()){
05590       mc.rw = 1.0;
05591     }
05592     //Should change rwActual, not beamWeight
05593     if (0==xmlConfig->RunPeriod()){
05594       mc.rw = mc.beamWeight;
05595     }
05596     if (1==xmlConfig->RunPeriod()){
05597       mc.rw = mc.beamWeightRunI;
05598     }
05599     if (2==xmlConfig->RunPeriod()){
05600       mc.rw = mc.beamWeightRunII;
05601     }
05602 
05603     this->Oscillate(mc,xmlConfig);
05604 
05605     //fill plots
05606     if (plots) plots->FillTrueFidEnergySpect(mc,binningScheme);
05607   }
05608 
05609   MSG("NuAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
05610 
05614 
05615   cutter.PrintSummary();
05616   
05617   // If the NC cutter is valid, print for that too
05618   if (NCcutter.IsValid()) {
05619     MSG("NuDSTAna",Msg::kInfo) << "Cutting statistics for NC cut:" << endl;
05620     NCcutter.PrintSummary();
05621   }
05622 
05623   MSG("NuAnalysis",Msg::kInfo)
05624     <<" ** Finished MMRereco method **"<<endl;
05625 }
05626 
05627 //......................................................................
05628 
05629 void NuDSTAna::MMTransition(std::string sOutputFileName,
05630                             TString xmlFileName)
05631 {
05632   NuInputEvents& input=this->DoIO(0,"",sOutputFileName);
05633 
05634   //get an instance of the code library
05635   NuLibrary& lib = NuLibrary::Instance();
05636 
05637   //get an object to fill plots
05638   const NuPlots* plots=0;
05639 
05640   //Get the NuXMLConfig object for configuration.
05641   NuXMLConfig* xmlConfig = 0;
05642   if (xmlFileName.IsNull()) {
05643     xmlConfig = new NuXMLConfig();
05644     xmlConfig->Write();
05645   }
05646   else {
05647     xmlConfig = new NuXMLConfig(xmlFileName);
05648     xmlConfig->Write();
05649   }
05650 
05651   //version to do reco/cuts with
05652   NuCuts::NuAnaVersion_t overrideAnaVersion =
05653   static_cast<NuCuts::NuAnaVersion_t>(xmlConfig->AnaVersion());
05654 
05655   //Binning scheme
05656   NuBinningScheme::NuBinningScheme_t binningScheme =
05657   static_cast<NuBinningScheme::NuBinningScheme_t>(xmlConfig->BinningScheme());
05658 
05659   NuTransition * transition = new NuTransition(xmlConfig);
05660 
05664 
05665   input.InitialiseNuMCEventBranch();
05666   input.ResetNuMCEventLoopPositionToStart();
05667 
05668   NuMCEvent& mc=const_cast<NuMCEvent&>(input.GetNextNuMCEvent(Msg::kDebug));
05669 
05670   if (xmlConfig->TransitionProb() > 0 && mc.detector == Detector::kFar) {
05671 
05672     input.ResetNuMCEventLoopPositionToStart();
05673 
05674     cout<<endl
05675         <<"************************************************"<<endl
05676         <<"***       Starting loop over truth info      ***"<<endl
05677         <<"************************************************"<<endl;
05678 
05679     for (Int_t i=0;i<input.GetEntriesNuMCEvent();++i) {
05680       lib.cnt.evtCounter++;
05681 
05682       this->PrintLoopProgress(i,input.GetEntriesNuMCEvent(),1);
05683 
05684       NuMCEvent& mc=const_cast<NuMCEvent&>(input.GetNextNuMCEvent
05685                                            (Msg::kDebug));
05686 
05687       //OVERRIDE
05688       //Selection
05689       mc.anaVersion=this->SanityCheckedAnaVersion
05690       (mc.anaVersion,overrideAnaVersion);
05691 
05692       MAXMSG("NuDSTAna",Msg::kInfo,5)
05693       <<"energyMC="<<mc.energyMC<<endl;
05694 
05695 
05696       //make fid vol cut
05697       if (!lib.cuts.IsInFidVolTrueEvt(mc)) continue;
05698 
05699       //override weights
05700       //mc.rw=mc.beamWeightRunI;
05701       if (-1==xmlConfig->RunPeriod()){
05702         mc.rw = 1.0;
05703       }
05704       //Should change rwActual, not beamWeight
05705       if (0==xmlConfig->RunPeriod()){
05706         mc.rw = mc.beamWeight;
05707       }
05708       if (1==xmlConfig->RunPeriod()){
05709         mc.rw = mc.beamWeightRunI;
05710       }
05711       if (2==xmlConfig->RunPeriod()){
05712         mc.rw = mc.beamWeightRunII;
05713       }
05714 
05715       transition->Fill(mc);
05716 
05717       this->Oscillate(mc,xmlConfig);
05718 
05719       //fill plots
05720       plots->FillTrueFidEnergySpect(mc,binningScheme);
05721     }
05722 
05723   }
05724 
05728 
05729 
05730   input.InitialiseNuEventBranch();
05731   input.ResetNuEventLoopPositionToStart();
05732 
05733   cout<<endl
05734       <<"************************************************"<<endl
05735       <<"***      Starting main loop over snarls      ***"<<endl
05736       <<"************************************************"<<endl;
05737   for (Int_t i=0;i<input.GetEntriesNuEvent();++i) {
05738       //for (Int_t i=0;i<0;++i) {
05739       lib.cnt.evtCounter++;
05740 
05741       this->PrintLoopProgress(i,input.GetEntriesNuEvent(),1);
05742 
05743       NuEvent &nu=const_cast<NuEvent&>(input.GetNextNuEvent(Msg::kDebug));
05744       //OVERRIDE
05745       //Selection
05746       nu.anaVersion=this->SanityCheckedAnaVersion
05747           (nu.anaVersion,overrideAnaVersion);
05748       //Reweighting
05749     if (-1==xmlConfig->RunPeriod()){
05750       MAXMSG("NuDSTAna",Msg::kInfo,5)
05751       <<"Not performing any reweighting" << endl;
05752       nu.applyBeamWeight = false;
05753     }
05754     //Should change rwActual, not beamWeight
05755     if (0==xmlConfig->RunPeriod()){
05756       nu.applyBeamWeight = true;
05757       nu.beamWeight = nu.beamWeight;
05758     }
05759     if (1==xmlConfig->RunPeriod()){
05760       nu.applyBeamWeight = true;
05761       nu.beamWeight = nu.beamWeightRunI;
05762       nu.trkEnWeight = nu.trkEnWeightRunI;
05763       nu.shwEnWeight = nu.shwEnWeightRunI;
05764       nu.detectorWeightNMB = nu.detectorWeightNMBRunI;
05765       nu.detectorWeightNM = nu.detectorWeightNMRunI;
05766     }
05767     if (2==xmlConfig->RunPeriod()){
05768       nu.applyBeamWeight = true;
05769       nu.beamWeight = nu.beamWeightRunII;
05770       nu.trkEnWeight = nu.trkEnWeightRunII;
05771       nu.shwEnWeight = nu.shwEnWeightRunII;
05772       nu.detectorWeightNMB = nu.detectorWeightNMBRunII;
05773       nu.detectorWeightNM = nu.detectorWeightNMRunII;
05774     }
05775 
05776     //RE-RECONSTRUCT the neutrino energy
05777     lib.reco.GetEvtEnergy(nu, false);
05778     lib.reco.ApplyReweights(nu);
05779 
05780 
05781 
05782     if (!this->IsGoodStdCuts(plots,nu)) continue;
05783 
05784     //NuEvent *nuOsc = (NuEvent*)nu.Clone();
05785     //NuEvent *nuTrans = transition->GetTransitionEvent(nu);
05786 
05787 
05788     // Reweight for systematics, oscillations and transitions
05789     transition->Reweight(nu);
05790 
05791     // apply the systematic shift if required according to xmlConfig
05792     // but only to the normal, not the appeared event
05793     //this->DoSystematicShifts(*nuOsc,xmlConfig);
05794 
05795     // Oscillate if desired (to make fake data)
05796 
05797     //this->Oscillate(*nuOsc,xmlConfig);
05798 
05799     // Reduce taus corresponding to transitions
05800 
05801     //if (nuOsc->inu == 16 || nuOsc->inu == -16) {
05802     //  MAXMSG("NuDSTAna",Msg::kInfo,1)
05803     //  << "Weighting down appeared NuTaus IN NUDSTANA for transitions by "
05804     //  << (1.0 - xmlConfig->TransitionProb()) << endl;
05805     //  nuOsc->rw *= (1.0 - xmlConfig->TransitionProb());
05806     //}
05807 
05808     //double oldWeight = nuOsc->rw;
05809     //delete nuOsc;
05810 
05811     //if (nuTrans) {
05812     //  oldWeight += nuTrans->rw;
05813     //  delete nuTrans;
05814     //}
05815 
05816 
05817     //if (TMath::Abs(oldWeight - nu.rw) < 1e-5) {
05818     //  MAXMSG("NuDSTAna",Msg::kInfo,5) << "===> Weights OK!" << endl;
05819     //}
05820     //else {
05821     //  MSG("NuDSTAna",Msg::kInfo) << "===> Weights disagree: old = " << oldWeight << ", new = " << nu.rw << endl;
05822     //}
05823 
05824     // fill matrix method histos
05825     // for the original oscillated event, nu or nubar
05826     lib.hist.FillMatrixMethodHistos(nu, binningScheme);
05827   }
05828 
05829    MSG("NuAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
05830 
05834 
05835   //print out the numbers of events
05836   lib.cnt.PrintMicroDST();
05837 
05838   MSG("NuAnalysis",Msg::kInfo)
05839   <<" ** Finished MMTransition method **"<<endl;
05840 }
05841 
05842 //......................................................................
05843 
05844 void NuDSTAna::DPSystematic()
05845 {
05846   NuInputEvents& input=this->DoIO(0,"","null");
05847 
05848   //get an instance of the code library
05849   NuLibrary& lib = NuLibrary::Instance();
05850 
05851   //version to do reco/cuts with
05852   NuCuts::NuAnaVersion_t overrideAnaVersion =
05853   static_cast<NuCuts::NuAnaVersion_t>(NuCuts::kNMB0325Bravo);
05854 
05855   //Binning scheme
05856   const NuUtilities cuts;
05857   NuBinningScheme::NuBinningScheme_t binningScheme =
05858   static_cast<NuBinningScheme::NuBinningScheme_t>(4);
05859   std::vector<Double_t> vReco = cuts.RecoBins(binningScheme);
05860   int numRecoBins = vReco.size() - 1;
05861 
05862   TH1::AddDirectory(true);
05863   TH1D *hUpI  = new TH1D("hUpI",  "Upstream #bar{#nu} Run I",    numRecoBins, &(vReco[0]));
05864   TH1D *hUpII = new TH1D("hUpII", "Upstream #bar{#nu} Run II",   numRecoBins, &(vReco[0]));
05865   TH1D *hDnI  = new TH1D("hDnI",  "Downstream #bar{#nu} Run I",  numRecoBins, &(vReco[0]));
05866   TH1D *hDnII = new TH1D("hDnII", "Downstream #bar{#nu} Run II", numRecoBins, &(vReco[0]));
05867 
05868 
05869 
05873 
05874   bool dp;
05875 
05876   input.InitialiseNuEventBranch();
05877   input.ResetNuEventLoopPositionToStart();
05878 
05879   cout<<endl
05880   <<"************************************************"<<endl
05881   <<"***      Starting main loop over snarls      ***"<<endl
05882   <<"************************************************"<<endl;
05883   for (Int_t i=0;i<input.GetEntriesNuEvent();++i) {
05884     //for (Int_t i=0;i<0;++i) {
05885     lib.cnt.evtCounter++;
05886 
05887     this->PrintLoopProgress(i,input.GetEntriesNuEvent(),1);
05888 
05889     NuEvent &nu=const_cast<NuEvent&>(input.GetNextNuEvent(Msg::kDebug));
05890     //OVERRIDE
05891     //Selection
05892     nu.anaVersion=this->SanityCheckedAnaVersion
05893     (nu.anaVersion,overrideAnaVersion);
05894 
05895     if (nu.charge < 0) continue;  // Only care about numubars
05896 
05897     if (!this->IsGoodStdCuts(0,nu)) continue;
05898 
05899     dp = nu.ppvz > 4500 && nu.ptype != 13 && nu.ptype != -13;
05900 
05901     nu.applyBeamWeight = true;
05902 
05903     nu.reweightVersion = 1; // Force numu-only SKZP
05904     //lib.zBeamReweight.ExtractZBeamReweight(nu);
05905     // Use custom set of weights (no NuMuBar spectrum in fit)
05906     lib.zBeamReweight.ExtractZBeamReweightCustom(nu);
05907 
05908     nu.beamWeight = nu.beamWeightRunI;
05909     nu.trkEnWeight = nu.trkEnWeightRunI;
05910     nu.shwEnWeight = nu.shwEnWeightRunI;
05911     nu.detectorWeightNMB = nu.detectorWeightNMBRunI;
05912     nu.detectorWeightNM = nu.detectorWeightNMRunI;
05913     //RE-RECONSTRUCT the neutrino energy
05914     lib.reco.GetEvtEnergy(nu, false);
05915     lib.reco.ApplyReweights(nu);
05916 
05917     if (dp) {
05918       hDnI->Fill(nu.energy, nu.rw);
05919     }
05920     else {
05921       hUpI->Fill(nu.energy, nu.rw);
05922     }
05923 
05924 
05925     nu.beamWeight = nu.beamWeightRunII;
05926     nu.trkEnWeight = nu.trkEnWeightRunII;
05927     nu.shwEnWeight = nu.shwEnWeightRunII;
05928     nu.detectorWeightNMB = nu.detectorWeightNMBRunII;
05929     nu.detectorWeightNM = nu.detectorWeightNMRunII;
05930     //RE-RECONSTRUCT the neutrino energy
05931     lib.reco.GetEvtEnergy(nu, false);
05932     lib.reco.ApplyReweights(nu);
05933 
05934     if (dp) {
05935       hDnII->Fill(nu.energy, nu.rw);
05936     }
05937     else {
05938       hUpII->Fill(nu.energy, nu.rw);
05939     }
05940   }
05941 
05942   MSG("NuAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
05943 
05947 
05948   //print out the numbers of events
05949   lib.cnt.PrintMicroDST();
05950 
05951   MSG("NuAnalysis",Msg::kInfo)
05952   <<" ** Finished DPSystematic method **"<<endl;
05953 }
05954 
05955 
05956 //......................................................................
05957 
05958 void NuDSTAna::FluxComponents(TString xmlFileName)
05959 {
05960   NuInputEvents& input=this->DoIO(0,"","null");
05961 
05962   //get an instance of the code library
05963   NuLibrary& lib = NuLibrary::Instance();
05964 
05965   
05966   //Get the NuXMLConfig object for configuration.
05967   NuXMLConfig* xmlConfig = 0;
05968   if (xmlFileName.IsNull()) {
05969     xmlConfig = new NuXMLConfig();
05970     xmlConfig->Write();
05971   }
05972   else {
05973     xmlConfig = new NuXMLConfig(xmlFileName);
05974     xmlConfig->Write();
05975   }
05976   
05977   // Selection
05978   NuCuts::NuAnaVersion_t overrideAnaVersion =
05979   static_cast<NuCuts::NuAnaVersion_t>(xmlConfig->AnaVersion());
05980   NuCutter cutter(xmlConfig->AnaVersionString());
05981   
05982   // Binning scheme
05983   const NuUtilities cuts;
05984   NuBinningScheme::NuBinningScheme_t binningScheme =
05985   static_cast<NuBinningScheme::NuBinningScheme_t>(xmlConfig->BinningScheme());
05986   std::vector<Double_t> vReco = cuts.RecoBins(binningScheme);
05987   int numRecoBins = vReco.size() - 1;
05988 
05989   
05990   TH1::AddDirectory(true);
05991   TString names[] = {"hTotal", "hUpPi", "hUpK", "hDecayPipe"};
05992   TString titles[] = {"Total", "Upstream Pions", "Upstream Kaons", "Decay Pipe"};
05993 
05994 
05995   TH1D *hPQ[5];
05996   TH1D *hNQ[5];
05997   TH1D *hVzPQ[5];
05998   TH1D *hVzNQ[5];
05999 
06000   for (int i = 0; i < 4; i++) {
06001     hPQ[i]   = new TH1D(names[i],        titles[i],          numRecoBins, &(vReco[0]));
06002     hNQ[i]   = new TH1D(names[i]+"NQ",   titles[i]+" NQ",    numRecoBins, &(vReco[0]));
06003     hVzPQ[i] = new TH1D(names[i]+"Vz",   titles[i]+" Vz",    500,0,800);
06004     hVzNQ[i] = new TH1D(names[i]+"VzNQ", titles[i]+" Vz NQ", 500,0,800);
06005   }
06006 
06010 
06011   input.ResetNuEventLoopPositionToStart();
06012   
06013   cout<<endl
06014   <<"************************************************"<<endl
06015   <<"***      Starting main loop over snarls      ***"<<endl
06016   <<"************************************************"<<endl;
06017   for (Int_t i=0;i<input.GetEntriesNuEvent();++i) {
06018     //for (Int_t i=0;i<0;++i) {
06019     lib.cnt.evtCounter++;
06020     
06021     this->PrintLoopProgress(i,input.GetEntriesNuEvent(),1);
06022     
06023     NuEvent &nu=const_cast<NuEvent&>(input.GetNextNuEvent(Msg::kDebug));
06024     
06025     nu.anaVersion=this->SanityCheckedAnaVersion
06026     (nu.anaVersion,overrideAnaVersion);
06027     //Reweighting
06028     if (-1==xmlConfig->RunPeriod()){
06029       MAXMSG("NuDSTAna",Msg::kInfo,5)
06030       <<"Not performing any reweighting" << endl;
06031       nu.applyBeamWeight = false;
06032     }
06033     //Should change rwActual, not beamWeight
06034     if (0==xmlConfig->RunPeriod()){
06035       nu.applyBeamWeight = true;
06036       nu.beamWeight = nu.beamWeight;
06037     }
06038     if (1==xmlConfig->RunPeriod()){
06039       nu.applyBeamWeight = true;
06040       nu.beamWeight = nu.beamWeightRunI;
06041       nu.trkEnWeight = nu.trkEnWeightRunI;
06042       nu.shwEnWeight = nu.shwEnWeightRunI;
06043       nu.detectorWeightNMB = nu.detectorWeightNMBRunI;
06044       nu.detectorWeightNM = nu.detectorWeightNMRunI;
06045     }
06046     if (2==xmlConfig->RunPeriod()){
06047       nu.applyBeamWeight = true;
06048       nu.beamWeight = nu.beamWeightRunII;
06049       nu.trkEnWeight = nu.trkEnWeightRunII;
06050       nu.shwEnWeight = nu.shwEnWeightRunII;
06051       nu.detectorWeightNMB = nu.detectorWeightNMBRunII;
06052       nu.detectorWeightNM = nu.detectorWeightNMRunII;
06053     }
06054     
06055     //RE-RECONSTRUCT the neutrino energy
06056     lib.reco.GetEvtEnergy(nu, false);
06057     lib.reco.ApplyReweights(nu);
06058     
06059     this->DoSystematicShifts(nu,xmlConfig);
06060     
06061     cutter.MakeCuts(nu);
06062     if (cutter.Failed()) continue;
06063     
06064     int plotNo = 0;
06065 
06066     if (nu.simFlag == SimFlag::kMC) {
06067       bool isDP = nu.ppvz > 4500;
06068       
06069       int type = nu.ptype;
06070       if (type == -1) {
06071         cout << "Using old files.  Bailing now." << endl;
06072         assert(false);
06073       }
06074       if (type == -13 || type == 13) {
06075         type = nu.tptype;
06076         isDP = false;
06077       }
06078       
06079 
06080       if (isDP) {// Decay Pipe
06081         plotNo = 3;
06082       }
06083       else if (type == -311 || type == 311 ||
06084                type == -321 || type == 321 ||
06085                type == 130  || type == 310) {// Kaons
06086         plotNo = 2;
06087       }
06088       else {// Pions
06089         plotNo = 1;
06090       }
06091       
06092       if (nu.charge == 1) {
06093         hPQ[plotNo]->Fill(nu.energy, nu.rw);
06094         if (nu.Vz > -900) hVzPQ[plotNo]->Fill(nu.Vz/100., nu.rw);
06095       }
06096       else {
06097         hNQ[plotNo]->Fill(nu.energy, nu.rw);
06098         if (nu.Vz > -900) hVzNQ[plotNo]->Fill(nu.Vz/100., nu.rw);
06099       }
06100     }
06101     if (nu.charge == 1) {
06102       hPQ[0]->Fill(nu.energy, nu.rw);
06103       if (nu.Vz > -900) hVzPQ[0]->Fill(nu.Vz/100., nu.rw);
06104     }
06105     else {
06106       hNQ[0]->Fill(nu.energy, nu.rw);
06107       if (nu.Vz > -900) hVzNQ[0]->Fill(nu.Vz/100., nu.rw);
06108     }
06109   }
06110   cout<<endl;
06111 
06112   MSG("NuAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
06113 
06114   cutter.PrintSummary();
06115   
06119 
06120   //print out the numbers of events
06121   lib.cnt.PrintMicroDST();
06122 
06123   MSG("NuAnalysis",Msg::kInfo)
06124   <<" ** Finished NewFieldAna method **"<<endl;
06125 }
06126 
06127 //......................................................................
06128 
06129 void NuDSTAna::Contamination()
06130 {
06131   NuInputEvents& input=this->DoIO(0,"","null");
06132 
06133   //get an instance of the code library
06134   NuLibrary& lib = NuLibrary::Instance();
06135 
06136   //version to do reco/cuts with
06137   NuCuts::NuAnaVersion_t overrideAnaVersion =
06138   static_cast<NuCuts::NuAnaVersion_t>(NuCuts::kNMB0325Bravo);
06139 
06140   //Binning scheme
06141   const NuUtilities cuts;
06142   NuBinningScheme::NuBinningScheme_t binningScheme =
06143   static_cast<NuBinningScheme::NuBinningScheme_t>(2);
06144   std::vector<Double_t> vReco = cuts.RecoBins(binningScheme);
06145   int numRecoBins = vReco.size() - 1;
06146 
06147   TH1::AddDirectory(true);
06148   TH1D * hEffDenom = new TH1D("hEffDenom","True NuBars in fid with a track",numRecoBins,&(vReco[0]));
06149 
06150   TH1D * hSignal = new TH1D("hSignal","PQ Signal before Selection",numRecoBins,&(vReco[0]));
06151   TH1D * hNC = new TH1D("hNC","PQ NC Events before Selection",numRecoBins,&(vReco[0]));
06152   TH1D * hWS = new TH1D("hWS","PQ Wrong Sign Events before Selection",numRecoBins,&(vReco[0]));
06153   TH1D * hTau = new TH1D("hTau","PQ Tau Events before Selection",numRecoBins,&(vReco[0]));
06154   TH1D * hBkgd = new TH1D("hBkgd","All PQ Background before Selection",numRecoBins,&(vReco[0]));
06155   TH1D * hAllEvents = new TH1D("hAllEvents","All PQ Events before Selection",numRecoBins,&(vReco[0]));
06156 
06157   TH1D * hSignal_sel = new TH1D("hSignal_sel","PQ Signal after Selection",numRecoBins,&(vReco[0]));
06158   TH1D * hNC_sel = new TH1D("hNC_sel","PQ NC Events after Selection",numRecoBins,&(vReco[0]));
06159   TH1D * hWS_sel = new TH1D("hWS_sel","PQ Wrong Sign Events after Selection",numRecoBins,&(vReco[0]));
06160   TH1D * hTau_sel = new TH1D("hTau_sel","PQ Tau Events before Selection",numRecoBins,&(vReco[0]));
06161   TH1D * hBkgd_sel = new TH1D("hBkgd_sel","All PQ Background after Selection",numRecoBins,&(vReco[0]));
06162   TH1D * hAllEvents_sel = new TH1D("hAllEvents_sel","All PQ Events after Selection",numRecoBins,&(vReco[0]));
06163 
06164   input.InitialiseNuEventBranch();
06165   input.ResetNuEventLoopPositionToStart();
06166 
06167   cout<<endl
06168   <<"************************************************"<<endl
06169   <<"***      Starting main loop over snarls      ***"<<endl
06170   <<"************************************************"<<endl;
06171   for (Int_t i=0;i<input.GetEntriesNuEvent();++i) {
06172     //for (Int_t i=0;i<0;++i) {
06173     lib.cnt.evtCounter++;
06174 
06175     this->PrintLoopProgress(i,input.GetEntriesNuEvent(),1);
06176 
06177     NuEvent &nu=const_cast<NuEvent&>(input.GetNextNuEvent(Msg::kDebug));
06178 
06179     //OVERRIDE
06180     //Selection
06181     nu.anaVersion=this->SanityCheckedAnaVersion
06182     (nu.anaVersion,overrideAnaVersion);
06183     //Reweighting
06184     nu.applyBeamWeight = true;
06185     nu.beamWeight = nu.beamWeightRunI;
06186     nu.trkEnWeight = nu.trkEnWeightRunI;
06187     nu.shwEnWeight = nu.shwEnWeightRunI;
06188     nu.detectorWeightNMB = nu.detectorWeightNMBRunI;
06189     nu.detectorWeightNM = nu.detectorWeightNMRunI;
06190 
06191 
06192     //RE-RECONSTRUCT the neutrino energy
06193     lib.reco.GetEvtEnergy(nu, false);
06194     lib.reco.ApplyReweights(nu);
06195 
06196     if (nu.charge==-1) lib.cnt.nuNQCounter++;
06197     else if (nu.charge==+1) lib.cnt.nuPQCounter++;
06198     else cout<<"ahhh, bad charge (9)"<<endl;
06199 
06200     // Pre-pre selection (Ntracks and fid vol)
06201     if (!lib.cuts.IsGoodNumberOfTracks(nu)) continue;
06202     if (!lib.cuts.IsInFidVolTrk(nu)) continue;
06203 
06204     if (nu.inu == -14 && nu.iaction != 0)
06205         hEffDenom->Fill(nu.energy, nu.rw);
06206 
06207     if (nu.charge == -1) continue; // Only interested in PQ events
06208 
06209     if (!this->IsGoodPreSelectionCuts(0,nu)) continue;
06210 
06211     hAllEvents->Fill(nu.energy, nu.rw);
06212     if (nu.inu == 16 || nu.inu == -16) { // Taus
06213       if (nu.iaction == 1) {
06214         hTau->Fill(nu.energy, nu.rw);
06215         hBkgd->Fill(nu.energy, nu.rw);
06216       }
06217     }
06218     else if (nu.iaction == 0) {    // NC Background
06219       hNC->Fill(nu.energy, nu.rw);
06220       hBkgd->Fill(nu.energy, nu.rw);
06221     }
06222     else if (nu.inu == 14) { // Wrong Sign Background
06223       hWS->Fill(nu.energy, nu.rw);
06224       hBkgd->Fill(nu.energy, nu.rw);
06225     }
06226     else if (nu.inu == -14) {  // Signal
06227       hSignal->Fill(nu.energy, nu.rw);
06228     }
06229     else { // Other?
06230       hBkgd->Fill(nu.energy, nu.rw);
06231     }
06232 
06233     if (!this->IsGoodStdCuts(0,nu)) continue;
06234 
06235     hAllEvents_sel->Fill(nu.energy, nu.rw);
06236     if (nu.inu == 16 || nu.inu == -16) { // Taus
06237       if (nu.iaction == 1) {
06238         hTau_sel->Fill(nu.energy, nu.rw);
06239         hBkgd_sel->Fill(nu.energy, nu.rw);
06240       }
06241     }
06242     else if (nu.iaction == 0) {    // NC Background
06243       hNC_sel->Fill(nu.energy, nu.rw);
06244       hBkgd_sel->Fill(nu.energy, nu.rw);
06245     }
06246     else if (nu.inu == 14) { // Wrong Sign Background
06247       hWS_sel->Fill(nu.energy, nu.rw);
06248       hBkgd_sel->Fill(nu.energy, nu.rw);
06249     }
06250     else if (nu.inu == -14) {  // Signal
06251       hSignal_sel->Fill(nu.energy, nu.rw);
06252     }
06253     else { // Other?
06254       hBkgd_sel->Fill(nu.energy, nu.rw);
06255     }
06256 
06257   }
06258 
06259   cout<<endl;
06260 
06261   MSG("NuAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
06262 
06266 
06267   //print out the numbers of events
06268   lib.cnt.PrintMicroDST();
06269 
06270   MSG("NuAnalysis",Msg::kInfo)
06271   <<" ** Finished NewFieldAna method **"<<endl;
06272 }
06273 
06274 //......................................................................
06275 
06276 void NuDSTAna::NewFieldAna(std::string sOutputFileName)
06277 {
06278   NuInputEvents& input=this->DoIO(0,"",sOutputFileName);
06279 
06280   //get an instance of the code library
06281   NuLibrary& lib = NuLibrary::Instance();
06282 
06283   //get an object to fill plots
06284   const NuPlots* plots=0;
06285 
06286   //version to do reco/cuts with
06287   NuCuts::NuAnaVersion_t overrideAnaVersion =
06288   static_cast<NuCuts::NuAnaVersion_t>(NuCuts::kJJE2);
06289 
06290   //Binning scheme
06291   NuBinningScheme::NuBinningScheme_t binningScheme =
06292   static_cast<NuBinningScheme::NuBinningScheme_t>(3);
06293 
06294   const NuUtilities cuts;
06295 
06296   std::vector<Double_t> vReco = cuts.RecoBins(binningScheme);
06297   std::vector<Double_t> vTrue = cuts.TrueBins(binningScheme);
06298 
06299   TH1::AddDirectory(true);
06300   TH1D * hqp_numu = new TH1D("hqp_numu","qp for NuMus", 200, -5, 5);
06301   TH1D * hqp_nubar = new TH1D("hqp_nubar","qp for NuBars", 200, -5, 5);
06302   TH1D * htrken_numu = new TH1D("htrken_numu","Track Energy for NuMus", 200, 0, 20);
06303   TH1D * htrken_nubar = new TH1D("htrken_nubar","Track Energy for NuBars", 200, 0, 20);
06304 
06305 
06306   input.InitialiseNuEventBranch();
06307   input.ResetNuEventLoopPositionToStart();
06308 
06309   cout<<endl
06310   <<"************************************************"<<endl
06311   <<"***      Starting main loop over snarls      ***"<<endl
06312   <<"************************************************"<<endl;
06313   for (Int_t i=0;i<input.GetEntriesNuEvent();++i) {
06314     //for (Int_t i=0;i<0;++i) {
06315     lib.cnt.evtCounter++;
06316 
06317     this->PrintLoopProgress(i,input.GetEntriesNuEvent(),1);
06318 
06319     NuEvent &nu=const_cast<NuEvent&>(input.GetNextNuEvent(Msg::kDebug));
06320 
06321     // Select only the right runs
06322     if (nu.detector == Detector::kFar && nu.run > 21037019)
06323       continue;
06324     if (nu.detector == Detector::kNear && nu.run > 13037009)
06325       continue;
06326 
06327 
06328     //OVERRIDE
06329     //Selection
06330     nu.anaVersion=this->SanityCheckedAnaVersion
06331     (nu.anaVersion,overrideAnaVersion);
06332     //Reweighting
06333     nu.applyBeamWeight = true;
06334     nu.beamWeight = nu.beamWeightRunI;
06335     nu.trkEnWeight = nu.trkEnWeightRunI;
06336     nu.shwEnWeight = nu.shwEnWeightRunI;
06337     nu.detectorWeightNMB = nu.detectorWeightNMBRunI;
06338     nu.detectorWeightNM = nu.detectorWeightNMRunI;
06339 
06340 
06341     //RE-RECONSTRUCT the neutrino energy
06342     lib.reco.GetEvtEnergy(nu, false);
06343     lib.reco.ApplyReweights(nu);
06344 
06345     // CC-only
06346     if (nu.iaction==1) {
06347 
06348       if (nu.inu == -14) {
06349         hqp_nubar->Fill(nu.qp, nu.rw);
06350         htrken_nubar->Fill(nu.trkEnCurv, nu.rw);
06351       }
06352       else if (nu.inu == 14) {
06353         hqp_numu->Fill(nu.qp, nu.rw);
06354         htrken_numu->Fill(nu.trkEnCurv, nu.rw);
06355       }
06356     }
06357 
06358     if (!this->IsGoodStdCuts(plots,nu)) continue;
06359 
06360     if (nu.charge==-1) lib.cnt.nuNQCounter++;
06361     else if (nu.charge==+1) lib.cnt.nuPQCounter++;
06362     else cout<<"ahhh, bad charge (10)"<<endl;
06363 
06364 
06365     //make the final plots
06366     this->MakeFinalPlots(plots,nu);
06367 
06368     //fill matrix method histos
06369     lib.hist.FillMatrixMethodHistos(nu, binningScheme);
06370 
06371 
06372   }
06373 
06374   MSG("NuAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
06375 
06379 
06380   //print out the numbers of events
06381   lib.cnt.PrintMicroDST();
06382 
06383   MSG("NuAnalysis",Msg::kInfo)
06384   <<" ** Finished NewFieldAna method **"<<endl;
06385 }
06386 
06387 
06388 //......................................................................
06389 
06390 void NuDSTAna::NDOsc()
06391 {
06392     NuInputEvents& input=this->DoIO(0,"","");
06393 
06394     //get an instance of the code library
06395     NuLibrary& lib=NuLibrary::Instance();
06396 
06397     //get an object to fill plots
06398     //const NuPlots* plots=0;
06399 
06400     //version to do reco/cuts with
06401     NuCuts::NuAnaVersion_t overrideAnaVersion  = NuCuts::kNMB0325Bravo;
06402 
06403     //Binning scheme
06404     NuBinningScheme::NuBinningScheme_t binningScheme = NuBinningScheme::kNuMuBar0325Std2;
06405 
06406     const NuUtilities cuts;
06407 
06408     std::vector<Double_t> vReco = cuts.RecoBins(binningScheme);
06409     int nbins = vReco.size() - 1;
06410     Double_t *bins = &(vReco[0]);
06411 
06412 
06413     // Initialize the plots
06414     TH1D *gdist = new TH1D("gdist","#nu_{#mu} Distance Traveled",1000,0,2);
06415     TH1D *hdist = new TH1D("hdist","#bar{#nu}_{#mu} Distance Traveled",1000,0,2);
06416     TH1D *h[100];
06417     TH1D *g[100];
06418     TString num;
06419     for (int i = 0; i < 100; i++) {
06420         num.Form("%04i",i*20);
06421         h[i] = new TH1D("h"+num,"#Delta #bar{m}^{2} = "+num+"e-3 eV^{2}",nbins, bins);
06422         g[i] = new TH1D("g"+num,"#Delta m^{2} = "+num+"e-3 eV^{2}",nbins, bins);
06423     }
06424 
06425     double osc = 1.;
06426     double sn2 = 1.;
06427     double dm2 = 0;
06428     double dist = 0;
06429     double cm2km = 1./(100.*1000.);
06430     double m2km = 1./(1000.);
06431 
06435 
06436     input.ResetNuEventLoopPositionToStart();
06437 
06438     cout<<endl
06439     <<"************************************************"<<endl
06440     <<"***      Starting main loop over snarls      ***"<<endl
06441     <<"************************************************"<<endl;
06442     for (Int_t i=0;i<input.GetEntriesNuEvent();++i) {
06443         //for (Int_t i=0;i<0;++i) {
06444         lib.cnt.evtCounter++;
06445 
06446         this->PrintLoopProgress(i,input.GetEntriesNuEvent(),1);
06447 
06448         NuEvent &nu=const_cast<NuEvent&>(input.GetNextNuEvent(Msg::kDebug));
06449 
06450         //OVERRIDE
06451         //Selection
06452         nu.anaVersion=this->SanityCheckedAnaVersion
06453         (nu.anaVersion,overrideAnaVersion);
06454         //Reweighting
06455         nu.applyBeamWeight = true;
06456         nu.beamWeight = nu.beamWeightRunI;
06457         nu.trkEnWeight = nu.trkEnWeightRunI;
06458         nu.shwEnWeight = nu.shwEnWeightRunI;
06459         nu.detectorWeightNMB = nu.detectorWeightNMBRunI;
06460         nu.detectorWeightNM = nu.detectorWeightNMRunI;
06461 
06462         //RE-RECONSTRUCT the neutrino energy
06463         lib.reco.GetEvtEnergy(nu, false);
06464         lib.reco.ApplyReweights(nu);
06465 
06466         //make all the std cuts
06467         if (!this->IsGoodStdCuts(0,nu)) continue;
06468 
06469         osc = 1;
06470 
06471         for (int i = 0; i < 100; i++) {
06472             //check for CC nubars
06473             if (1 == nu.iaction && abs(nu.inu) == 14) {
06474                 dm2 = i;
06475                 dm2 *= 20.*1e-3;
06476                 dist = (104000.0 - nu.Vz)*cm2km + (nu.zTrkVtx - 13.5)*m2km;
06477                 osc = NuUtilities::OscillationWeight(nu.neuEnMC, dm2, sn2);
06478             }
06479 
06480             if (nu.charge == 1) {
06481                 h[i]->Fill(nu.energy, nu.rw*osc);
06482             }
06483             else {
06484                 g[i]->Fill(nu.energy, nu.rw*osc);
06485             }
06486 
06487         }
06488 
06489         if (nu.charge == 1) {
06490             hdist->Fill(dist, nu.rw);
06491         }
06492         else {
06493             gdist->Fill(dist, nu.rw);
06494         }
06495 
06496 
06497         if (nu.charge==-1) lib.cnt.nuNQCounter++;
06498         else if (nu.charge==+1) lib.cnt.nuPQCounter++;
06499         else cout<<"ahhh, bad charge (11)"<<endl;
06500 
06501 
06502         MAXMSG("NuDSTAna",Msg::kInfo,5)
06503         <<"Passed: index="<<nu.index
06504         <<", energy="<<nu.energy<<", energyMC="<<nu.energyMC<<endl;
06505     }//end of loop over summary tree
06506 
06507     MSG("NuAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
06508 
06512 
06513     //print out the numbers of events
06514     lib.cnt.PrintMicroDST();
06515 
06516     MSG("NuAnalysis",Msg::kInfo)
06517     <<" ** Finished NDOsc method **"<<endl;
06518 }
06519 
06520 
06521 
06522 //......................................................................
06523 
06524 void NuDSTAna::RHCTest()
06525 {
06526   NuInputEvents& input=this->DoIO(0,"","");
06527 
06528   //get an instance of the code library
06529   NuLibrary& lib=NuLibrary::Instance();
06530 
06531   //get an object to fill plots
06532   //const NuPlots* plots=0;
06533 
06534   //version to do reco/cuts with
06535   NuCuts::NuAnaVersion_t overrideAnaVersion  = NuCuts::kRHC;
06536 
06537 
06538   const NuUtilities cuts;
06539 
06540   TH1D *hRecoEnergy_PQ = new TH1D("hRecoEnergy_PQ","Reconstructed RHC Spectrum (+ve charge)",200,0,50);
06541   TH1D *hRecoEnergy_NQ = new TH1D("hRecoEnergy_NQ","Reconstructed RHC Spectrum (-ve charge)",200,0,50);
06542   TH1D *hRecoEnergy_rw_PQ = new TH1D("hRecoEnergy_rw_PQ","SKZP Reconstructed RHC Spectrum (+ve charge)",200,0,50);
06543   TH1D *hRecoEnergy_rw_NQ = new TH1D("hRecoEnergy_rw_NQ","SKZP Reconstructed RHC Spectrum (-ve charge)",200,0,50);
06544   TH1D *hRecoEnergy_he_PQ = new TH1D("hRecoEnergy_he_PQ","He Reconstructed RHC Spectrum (+ve charge)",200,0,50);
06545   TH1D *hRecoEnergy_he_NQ = new TH1D("hRecoEnergy_he_NQ","He Reconstructed RHC Spectrum (-ve charge)",200,0,50);
06546 
06547   TH1D *hShowerEnergy_PQ = new TH1D("hShowerEnergy_PQ","Shower RHC Spectrum (+ve charge)",200,0,50);
06548   TH1D *hShowerEnergy_NQ = new TH1D("hShowerEnergy_NQ","Shower RHC Spectrum (-ve charge)",200,0,50);
06549   TH1D *hShowerEnergy_rw_PQ = new TH1D("hShowerEnergy_rw_PQ","SKZP Shower RHC Spectrum (+ve charge)",200,0,50);
06550   TH1D *hShowerEnergy_rw_NQ = new TH1D("hShowerEnergy_rw_NQ","SKZP Shower RHC Spectrum (-ve charge)",200,0,50);
06551   TH1D *hShowerEnergy_he_PQ = new TH1D("hShowerEnergy_he_PQ","He Shower RHC Spectrum (+ve charge)",200,0,50);
06552   TH1D *hShowerEnergy_he_NQ = new TH1D("hShowerEnergy_he_NQ","He Shower RHC Spectrum (-ve charge)",200,0,50);
06553 
06554   TH1D *hTrackEnergy_PQ = new TH1D("hTrackEnergy_PQ","Track RHC Spectrum (+ve charge)",200,0,50);
06555   TH1D *hTrackEnergy_NQ = new TH1D("hTrackEnergy_NQ","Track RHC Spectrum (-ve charge)",200,0,50);
06556   TH1D *hTrackEnergy_rw_PQ = new TH1D("hTrackEnergy_rw_PQ","SKZP Track RHC Spectrum (+ve charge)",200,0,50);
06557   TH1D *hTrackEnergy_rw_NQ = new TH1D("hTrackEnergy_rw_NQ","SKZP Track RHC Spectrum (-ve charge)",200,0,50);
06558   TH1D *hTrackEnergy_he_PQ = new TH1D("hTrackEnergy_he_PQ","He Track RHC Spectrum (+ve charge)",200,0,50);
06559   TH1D *hTrackEnergy_he_NQ = new TH1D("hTrackEnergy_he_NQ","He Track RHC Spectrum (-ve charge)",200,0,50);
06560   
06561   
06562   TH1D *hRecoEnergy_numu = new TH1D("hRecoEnergy_numu","Reconstructed RHC Spectrum (numu)",200,0,50);
06563   TH1D *hRecoEnergy_nubar = new TH1D("hRecoEnergy_nubar","Reconstructed RHC Spectrum (nubar)",200,0,50);
06564   TH1D *hRecoEnergy_rw_numu = new TH1D("hRecoEnergy_rw_numu","SKZP Reconstructed RHC Spectrum (numu)",200,0,50);
06565   TH1D *hRecoEnergy_rw_nubar = new TH1D("hRecoEnergy_rw_nubar","SKZP Reconstructed RHC Spectrum (nubar)",200,0,50);
06566   TH1D *hRecoEnergy_he_numu = new TH1D("hRecoEnergy_he_numu","He Reconstructed RHC Spectrum (numu)",200,0,50);
06567   TH1D *hRecoEnergy_he_nubar = new TH1D("hRecoEnergy_he_nubar","He Reconstructed RHC Spectrum (nubar)",200,0,50);
06568 
06569   TH1D *hShowerEnergy_numu = new TH1D("hShowerEnergy_numu","Shower RHC Spectrum (numu)",200,0,50);
06570   TH1D *hShowerEnergy_nubar = new TH1D("hShowerEnergy_nubar","Shower RHC Spectrum (nubar)",200,0,50);
06571   TH1D *hShowerEnergy_rw_numu = new TH1D("hShowerEnergy_rw_numu","SKZP Shower RHC Spectrum (numu)",200,0,50);
06572   TH1D *hShowerEnergy_rw_nubar = new TH1D("hShowerEnergy_rw_nubar","SKZP Shower RHC Spectrum (nubar)",200,0,50);
06573   TH1D *hShowerEnergy_he_numu = new TH1D("hShowerEnergy_he_numu","He Shower RHC Spectrum (numu)",200,0,50);
06574   TH1D *hShowerEnergy_he_nubar = new TH1D("hShowerEnergy_he_nubar","He Shower RHC Spectrum (nubar)",200,0,50);
06575 
06576   TH1D *hTrackEnergy_numu = new TH1D("hTrackEnergy_numu","Track RHC Spectrum (numu)",200,0,50);
06577   TH1D *hTrackEnergy_nubar = new TH1D("hTrackEnergy_nubar","Track RHC Spectrum (nubar)",200,0,50);
06578   TH1D *hTrackEnergy_rw_numu = new TH1D("hTrackEnergy_rw_numu","SKZP Track RHC Spectrum (numu)",200,0,50);
06579   TH1D *hTrackEnergy_rw_nubar = new TH1D("hTrackEnergy_rw_nubar","SKZP Track RHC Spectrum (nubar)",200,0,50);
06580   TH1D *hTrackEnergy_he_numu = new TH1D("hTrackEnergy_he_numu","He Track RHC Spectrum (numu)",200,0,50);
06581   TH1D *hTrackEnergy_he_nubar = new TH1D("hTrackEnergy_he_nubar","He Track RHC Spectrum (nubar)",200,0,50);
06582   
06583   TH1D *hRecoEnergy_rw_PQ_ws = new TH1D("hRecoEnergy_rw_PQ_ws","SKZP Reconstructed RHC Spectrum Wrong Sign (+ve charge)",200,0,50);
06584   TH1D *hRecoEnergy_rw_NQ_ws = new TH1D("hRecoEnergy_rw_NQ_ws","SKZP Reconstructed RHC Spectrum Wrong Sign (+ve charge)",200,0,50);
06585   TH1D *hRecoEnergy_rw_PQ_nc = new TH1D("hRecoEnergy_rw_PQ_nc","SKZP Reconstructed RHC Spectrum Neutral Current (+ve charge)",200,0,50);
06586   TH1D *hRecoEnergy_rw_NQ_nc = new TH1D("hRecoEnergy_rw_NQ_nc","SKZP Reconstructed RHC Spectrum Neutral Current (+ve charge)",200,0,50);
06587 
06588   TH1D *hShowerEnergy_rw_PQ_ws = new TH1D("hShowerEnergy_rw_PQ_ws","SKZP Shower RHC Spectrum Wrong Sign (+ve charge)",200,0,50);
06589   TH1D *hShowerEnergy_rw_NQ_ws = new TH1D("hShowerEnergy_rw_NQ_ws","SKZP Shower RHC Spectrum Wrong Sign (+ve charge)",200,0,50);
06590   TH1D *hShowerEnergy_rw_PQ_nc = new TH1D("hShowerEnergy_rw_PQ_nc","SKZP Shower RHC Spectrum Neutral Current (+ve charge)",200,0,50);
06591   TH1D *hShowerEnergy_rw_NQ_nc = new TH1D("hShowerEnergy_rw_NQ_nc","SKZP Shower RHC Spectrum Neutral Current (+ve charge)",200,0,50);
06592 
06593   TH1D *hTrackEnergy_rw_PQ_ws = new TH1D("hTrackEnergy_rw_PQ_ws","SKZP Track RHC Spectrum Wrong Sign (+ve charge)",200,0,50);
06594   TH1D *hTrackEnergy_rw_NQ_ws = new TH1D("hTrackEnergy_rw_NQ_ws","SKZP Track RHC Spectrum Wrong Sign (+ve charge)",200,0,50);
06595   TH1D *hTrackEnergy_rw_PQ_nc = new TH1D("hTrackEnergy_rw_PQ_nc","SKZP Track RHC Spectrum Neutral Current (+ve charge)",200,0,50);
06596   TH1D *hTrackEnergy_rw_NQ_nc = new TH1D("hTrackEnergy_rw_NQ_nc","SKZP Track RHC Spectrum Neutral Current (+ve charge)",200,0,50);
06597   
06598   int bins2d = 100;
06599   TH2D* ptpz_nubar = new TH2D("ptpz_PQ","pt vz. pz for nubar",bins2d,0,120,bins2d,0,1);
06600   TH2D* ptpz_numu = new TH2D("ptpz_NQ","pt vz. pz for numu",bins2d,0,120,bins2d,0,1);
06601   TProfile2D* skzp_nubar = new TProfile2D("skzp_PQ","SKZP weights for nubar",bins2d,0,120,bins2d,0,1);
06602   TProfile2D* skzp_numu = new TProfile2D("skzp_NQ","SKZP weights for numu",bins2d,0,120,bins2d,0,1);
06603 
06604   input.ResetNuEventLoopPositionToStart();
06605 
06606   cout<<endl
06607   <<"************************************************"<<endl
06608   <<"***      Starting main loop over snarls      ***"<<endl
06609   <<"************************************************"<<endl;
06610   for (Int_t i=0;i<input.GetEntriesNuEvent();++i) {
06611     //for (Int_t i=0;i<0;++i) {
06612     lib.cnt.evtCounter++;
06613 
06614     this->PrintLoopProgress(i,input.GetEntriesNuEvent(),1);
06615 
06616     NuEvent &nu=const_cast<NuEvent&>(input.GetNextNuEvent(Msg::kDebug));
06617    
06618     if (nu.simFlag == SimFlag::kMC) {
06619       // Force some parameters:
06620       nu.runPeriod = 4;
06621       nu.hornIsReverse = true;
06622       nu.beamType = BeamType::kL010z185i_rev;
06623 
06624       // Redo the beam weights
06625       lib.zBeamReweight.ExtractZBeamReweight(nu);
06626 
06627       //Reweighting
06628       nu.applyBeamWeight = true;
06629       nu.applyEnergyShifts = false;
06630       nu.rw = 1;
06631       lib.reco.ApplyReweights(nu);
06632     }
06633 
06634     nu.cutOnDataQuality = nu.useDBForDataQuality;
06635     
06636     
06637     //OVERRIDE
06638     //Selection
06639     nu.anaVersion=this->SanityCheckedAnaVersion
06640     (nu.anaVersion,overrideAnaVersion);
06641 
06642     //RE-RECONSTRUCT the neutrino energy
06643     lib.reco.GetEvtEnergy(nu, false);
06644 
06645     //make all the std cuts
06646     //if (!lib.cuts.IsGoodQP(nu)) continue;
06647     if (!this->IsGoodStdCuts(0,nu)) continue;
06648 
06649 
06650     //hRecoEnergy_unosc->Fill(nu.energy, nu.rw);
06651 
06652 
06653     //this->Oscillate(nu,xmlConfig);
06654 
06655     double recoE = nu.energy;
06656     double showerE = nu.shwEn;
06657     double trackE = nu.trkEn;
06658     double hew   = lib.zBeamReweight.GetWeightHelium(nu);
06659 
06660     if (nu.charge == +1) { // Reco NuBar
06661       hRecoEnergy_PQ->Fill(recoE, 1);
06662       hRecoEnergy_rw_PQ->Fill(recoE, nu.rw);
06663       hRecoEnergy_he_PQ->Fill(recoE, nu.rw*hew);
06664 
06665       hShowerEnergy_PQ->Fill(showerE, 1);
06666       hShowerEnergy_rw_PQ->Fill(showerE, nu.rw);
06667       hShowerEnergy_he_PQ->Fill(showerE, nu.rw*hew);
06668 
06669       hTrackEnergy_PQ->Fill(trackE, 1);
06670       hTrackEnergy_rw_PQ->Fill(trackE, nu.rw);
06671       hTrackEnergy_he_PQ->Fill(trackE, nu.rw*hew);
06672       
06673       
06674       if (nu.simFlag == SimFlag::kMC) {
06675         if (nu.iaction != 1) {
06676           hRecoEnergy_rw_PQ_nc->Fill(recoE, nu.rw);
06677           hShowerEnergy_rw_PQ_nc->Fill(showerE, nu.rw);
06678           hTrackEnergy_rw_PQ_nc->Fill(trackE, nu.rw);
06679         }
06680         else if (nu.inu != -14) {
06681           hRecoEnergy_rw_PQ_ws->Fill(recoE, nu.rw);
06682           hShowerEnergy_rw_PQ_ws->Fill(showerE, nu.rw);
06683           hTrackEnergy_rw_PQ_ws->Fill(trackE, nu.rw);
06684         }
06685       }
06686     }
06687     else { // Reco NuMu
06688       hRecoEnergy_NQ->Fill(recoE, 1);
06689       hRecoEnergy_rw_NQ->Fill(recoE, nu.rw);
06690       hRecoEnergy_he_NQ->Fill(recoE, nu.rw*hew);
06691 
06692       hShowerEnergy_NQ->Fill(showerE, 1);
06693       hShowerEnergy_rw_NQ->Fill(showerE, nu.rw);
06694       hShowerEnergy_he_NQ->Fill(showerE, nu.rw*hew);
06695 
06696       hTrackEnergy_NQ->Fill(trackE, 1);
06697       hTrackEnergy_rw_NQ->Fill(trackE, nu.rw);
06698       hTrackEnergy_he_NQ->Fill(trackE, nu.rw*hew);
06699       
06700       
06701       if (nu.simFlag == SimFlag::kMC) {        
06702         if (nu.iaction != 1) {
06703           hRecoEnergy_rw_NQ_nc->Fill(recoE, nu.rw);
06704           hShowerEnergy_rw_NQ_nc->Fill(showerE, nu.rw);
06705           hTrackEnergy_rw_NQ_nc->Fill(trackE, nu.rw);
06706         }
06707         else if (nu.inu != 14) {
06708           hRecoEnergy_rw_NQ_ws->Fill(recoE, nu.rw);
06709           hShowerEnergy_rw_NQ_ws->Fill(showerE, nu.rw);
06710           hTrackEnergy_rw_NQ_ws->Fill(trackE, nu.rw);
06711         }
06712       }
06713     }
06714 
06715 
06716     if (nu.simFlag == SimFlag::kMC) {
06717       if (nu.iaction == 1) {
06718         if (nu.inu == -14) { // True NuBar
06719           double tpt = sqrt(nu.tpx*nu.tpx+nu.tpy*nu.tpy);
06720           ptpz_nubar->Fill(nu.tpz, tpt);
06721           skzp_nubar->Fill(nu.tpz, tpt, nu.rw);
06722 
06723           hRecoEnergy_nubar->Fill(recoE, 1);
06724           hRecoEnergy_rw_nubar->Fill(recoE, nu.rw);
06725           hRecoEnergy_he_nubar->Fill(recoE, nu.rw*hew);
06726           
06727           hShowerEnergy_nubar->Fill(showerE, 1);
06728           hShowerEnergy_rw_nubar->Fill(showerE, nu.rw);
06729           hShowerEnergy_he_nubar->Fill(showerE, nu.rw*hew);
06730           
06731           hTrackEnergy_nubar->Fill(trackE, 1);
06732           hTrackEnergy_rw_nubar->Fill(trackE, nu.rw);
06733           hTrackEnergy_he_nubar->Fill(trackE, nu.rw*hew);
06734         }
06735         else if (nu.inu == 14){ // True NuMu
06736           double tpt = sqrt(nu.tpx*nu.tpx+nu.tpy*nu.tpy);
06737           ptpz_numu->Fill(nu.tpz, tpt);
06738           skzp_numu->Fill(nu.tpz, tpt, nu.rw);
06739           
06740           hRecoEnergy_numu->Fill(recoE, 1);
06741           hRecoEnergy_rw_numu->Fill(recoE, nu.rw);
06742           hRecoEnergy_he_numu->Fill(recoE, nu.rw*hew);
06743           
06744           hShowerEnergy_numu->Fill(showerE, 1);
06745           hShowerEnergy_rw_numu->Fill(showerE, nu.rw);
06746           hShowerEnergy_he_numu->Fill(showerE, nu.rw*hew);
06747           
06748           hTrackEnergy_numu->Fill(trackE, 1);
06749           hTrackEnergy_rw_numu->Fill(trackE, nu.rw);
06750           hTrackEnergy_he_numu->Fill(trackE, nu.rw*hew);
06751         }
06752       }
06753     }
06754 
06755 
06756     if (nu.charge==-1) lib.cnt.nuNQCounter++;
06757     else if (nu.charge==+1) lib.cnt.nuPQCounter++;
06758     else cout<<"ahhh, bad charge (11)"<<endl;
06759 
06760 
06761     MAXMSG("NuDSTAna",Msg::kInfo,5)
06762     <<"Passed: index="<<nu.index
06763     <<", energy="<<recoE<<", energyMC="<<nu.energyMC<<endl;
06764   }//end of loop over summary tree
06765 
06766   MSG("NuAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
06767 
06771 
06772   //print out the numbers of events
06773   lib.cnt.PrintMicroDST();
06774 
06775   MSG("NuAnalysis",Msg::kInfo)
06776   <<" ** Finished RHCTest method **"<<endl;
06777 }
06778 
06779 
06780 
06781 //......................................................................
06782 
06783 void NuDSTAna::SelectorTable()
06784 {
06785   NuInputEvents& input=this->DoIO(0,"","");
06786   
06787   //get an instance of the code library
06788   NuLibrary& lib=NuLibrary::Instance();
06789   
06790   //get an object to fill plots
06791   const NuPlots* plots=new NuPlots();
06792   
06793   TString bravoCutNames[] = {"DpID","SigmaQP_QP","RelativeAngle"};
06794   TString charlieCutNames[] = {"RoID","MajorityCurv","TrackLength"};
06795   //TString catNames[] = {"Signal","NC","WrongSign"};
06796   
06797   
06798   input.ResetNuEventLoopPositionToStart();
06799 
06800   NuCutImps::Bravo bravoCut(plots);
06801   NuCutImps::BravoPrime bravoPrimeCut(plots);
06802   NuCutImps::Charlie charlieCut(plots);
06803   
06804   
06805   cout<<endl
06806   <<"************************************************"<<endl
06807   <<"***      Starting main loop over snarls      ***"<<endl
06808   <<"************************************************"<<endl;
06809   for (Int_t i=0;i<input.GetEntriesNuEvent();++i) {
06810     //for (Int_t i=0;i<0;++i) {
06811     lib.cnt.evtCounter++;
06812     
06813     this->PrintLoopProgress(i,input.GetEntriesNuEvent(),1);
06814     
06815     NuEvent &nu=const_cast<NuEvent&>(input.GetNextNuEvent(Msg::kDebug));
06816       
06817     // Only care about preselected nubars here
06818     nu.anaVersion = NuCuts::kNMB0325Bravo;
06819     if (!this->IsGoodPreSelectionCuts(plots,nu)) continue;
06820     
06821     //OVERRIDE
06822     
06823     //RE-RECONSTRUCT the neutrino energy
06824     NuUtilities::FixDogwoodQP(nu);
06825     //lib.reco.GetEvtEnergy(nu);
06826     
06827     bravoCut.MakeCuts(nu);
06828     bravoPrimeCut.MakeCuts(nu);
06829     charlieCut.MakeCuts(nu);
06830 
06831     // Fill Preselection spectra
06832     plots->FillSpectra(nu, "Presel");
06833     
06834     for (int i = 0; i < 3; i++) {
06835       // Fill Preselection Selector Plots
06836       plots->FillSelPlots(nu, bravoCutNames[i], "BravoPre");
06837       plots->FillSelPlots(nu, bravoCutNames[i], "BravoPrimePre");
06838       plots->FillSelPlots(nu, charlieCutNames[i], "CharliePre");
06839       
06840       if (nu.charge == 1) {
06841         // Fill N-1 Selector Plots      
06842         if (bravoCut.PassedExcept(bravoCutNames[i])) plots->FillSelPlots(nu, bravoCutNames[i], "BravoN_1");
06843         if (bravoPrimeCut.PassedExcept(bravoCutNames[i])) plots->FillSelPlots(nu, bravoCutNames[i], "BravoPrimeN_1");
06844         if (charlieCut.PassedExcept(charlieCutNames[i])) plots->FillSelPlots(nu, charlieCutNames[i], "CharlieN_1");
06845         
06846         // Fill individual selector spectra
06847         if (bravoCut.Passed(bravoCutNames[i])) plots->FillSpectra(nu, "Bravo_"+bravoCutNames[i]);
06848         if (bravoPrimeCut.Passed(bravoCutNames[i])) plots->FillSpectra(nu, "BravoPrime_"+bravoCutNames[i]);
06849         if (charlieCut.Passed(charlieCutNames[i])) plots->FillSpectra(nu, "Charlie_"+charlieCutNames[i]);
06850         
06851         // Fill N-1 spectra
06852         if (bravoCut.PassedExcept(bravoCutNames[i])) plots->FillSpectra(nu, "BravoN_1_"+bravoCutNames[i]);
06853         if (bravoPrimeCut.PassedExcept(bravoCutNames[i])) plots->FillSpectra(nu, "BravoPrimeN_1_"+bravoCutNames[i]);
06854         if (charlieCut.PassedExcept(charlieCutNames[i])) plots->FillSpectra(nu, "CharlieN_1_"+charlieCutNames[i]);
06855       }
06856     }
06857 
06858     // Fill full selection spectra
06859     if (bravoCut.Passed()) plots->FillSpectra(nu, "Bravo");
06860     if (bravoPrimeCut.Passed()) plots->FillSpectra(nu, "BravoPrime");
06861     if (charlieCut.Passed()) plots->FillSpectra(nu, "Charlie");
06862     
06863 //    
06864 //    
06865 //    
06866 //    nu.anaVersion = NuCuts::kNMB0325Bravo;
06867 //    if (bravoCut.Passed() != IsGoodStdCuts(0,nu)) {
06868 //      MSG("NuDSTAna",Msg::kWarning) << "Bravo disagrees." << endl;
06869 //      for (int i = 1; i < 4; i++) cout << "  " << bravoCutNames[i] << ": " << bravoCutVals[i] << endl;
06870 //      bravoCut.PrintCurrent();
06871 //    }
06872 //    nu.anaVersion = NuCuts::kNMB0325Charlie;
06873 //    if (charlieCut.Passed() != IsGoodStdCuts(0,nu)) {
06874 //      MAXMSG("NuDSTAna",Msg::kWarning,100) << "Charlie disagrees." << endl;
06875 //      for (int i = 1; i < 4; i++) cout << "  " << charlieCutNames[i] << ": " << charlieCutVals[i] << endl;
06876 //      charlieCut.PrintCurrent();
06877 //    }
06878 //    
06879     if (nu.charge==-1) lib.cnt.nuNQCounter++;
06880     else if (nu.charge==+1) lib.cnt.nuPQCounter++;
06881     else cout<<"ahhh, bad charge (11)"<<endl;
06882 
06883   }//end of loop over summary tree
06884 //  
06885 //  double allBravo[5][2];
06886 //  double allCharlie[5][2];
06887 //  
06888 //  double effBravo[5][2];
06889 //  double cNCBravo[5][2];
06890 //  double cWSBravo[5][2];
06891 //
06892 //  double effCharlie[5][2];
06893 //  double cNCCharlie[5][2];
06894 //  double cWSCharlie[5][2];
06895 //  
06896 //  for (int k = 0; k < 2; k++) {
06897 //    for (int i = 0; i < 5; i++) {
06898 //      for (int j = 0; j < 3; j++) {
06899 //        cout << "bravoCounts[" << i << "][" << j << "][" << k << "] =" << bravoCounts[i][j][k] << endl;
06900 //        cout << "charlieCounts[" << i << "][" << j << "][" << k << "] =" << charlieCounts[i][j][k] << endl;
06901 //      }
06902 //    }
06903 //  }
06904 //  
06905 //  
06906 //  for (int en = 0; en < 2; en++) {
06907 //    if (en == 0) cout << "Below 5 GeV: " << endl;
06908 //    else         cout << "Above 5 GeV: " << endl;
06909 //    for (int i = 0; i < 5; i++) {
06910 //      allBravo[i][en] = bravoCounts[i][0][en] + bravoCounts[i][1][en] + bravoCounts[i][2][en];
06911 //      allCharlie[i][en] = charlieCounts[i][0][en] + charlieCounts[i][1][en] + charlieCounts[i][2][en];
06912 //      
06913 //      effBravo[i][en] = bravoCounts[i][0][en] / bravoCounts[0][0][en];
06914 //      cNCBravo[i][en] = bravoCounts[i][1][en] / allBravo[i][en];
06915 //      cWSBravo[i][en] = bravoCounts[i][2][en] / allBravo[i][en];
06916 //      
06917 //      effCharlie[i][en] = charlieCounts[i][0][en] / charlieCounts[0][0][en];
06918 //      cNCCharlie[i][en] = charlieCounts[i][1][en] / allCharlie[i][en];
06919 //      cWSCharlie[i][en] = charlieCounts[i][2][en] / allCharlie[i][en];
06920 //    }
06921 //  
06922 //    cout << endl << "Bravo: " << endl;
06923 //    cout << "Cut" << "\t" << "Eff" << "\t" << "NC" << "\t" << "WS" << endl;
06924 //    for (int i = 0; i < 5; i++) 
06925 //      cout << bravoCutNames[i] << "\t" << effBravo[i][en]
06926 //                               << "\t" << cNCBravo[i][en] 
06927 //                               << "\t" << cWSBravo[i][en] << endl;
06928 //
06929 //    cout << endl << "Charlie: " << endl;
06930 //    cout << "Cut" << "\t" << "Eff" << "\t" << "NC" << "\t" << "WS" << endl;
06931 //    for (int i = 0; i < 5; i++) 
06932 //      cout << charlieCutNames[i] << "\t" << effCharlie[i][en] 
06933 //                               << "\t" << cNCCharlie[i][en] 
06934 //                               << "\t" << cWSCharlie[i][en] << endl;
06935 //    cout << endl;
06936 //  }
06937   
06938   MSG("NuAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
06939   
06943   
06944   //print out the numbers of events
06945   lib.cnt.PrintMicroDST();
06946   
06947   MSG("NuAnalysis",Msg::kInfo)
06948   <<" ** Finished SelectorTable method **"<<endl;
06949 }
06950 
06951 
06952 //......................................................................
06953 
06954 void NuDSTAna::QPStudy()
06955 {
06956   cout<<endl
06957   <<"************************************************"<<endl
06958   <<"***            Starting QPStudy()            ***"<<endl
06959   <<"************************************************"<<endl << endl;;
06960   
06961   NuInputEvents& input=this->DoIO(0,"","");
06962   
06963   //get an instance of the code library
06964   NuLibrary& lib=NuLibrary::Instance();
06965   
06966   //get an object to fill plots
06967   const NuPlots* plots=new NuPlots();
06968   NuCutImps::Bravo bravoCut(plots);
06969   
06970   input.ResetNuEventLoopPositionToStart();
06971   
06972   TString post[] = {"_nom_skzp", "_nom_norw", "_qpfix_skzp", "_qpfix_norw"};
06973 
06974   TString cont; 
06975   
06976   cout<<endl
06977   <<"************************************************"<<endl
06978   <<"***      Starting main loop over snarls      ***"<<endl
06979   <<"************************************************"<<endl;
06980   for (Int_t i=0;i<input.GetEntriesNuEvent();++i) {
06981     lib.cnt.evtCounter++;
06982     
06983     this->PrintLoopProgress(i,input.GetEntriesNuEvent(),1);
06984     if (i < 200) cout << "Debug: i=" << i << "/" << input.GetEntriesNuEvent() << endl;;
06985     
06986     
06987     NuEvent &nu=const_cast<NuEvent&>(input.GetNextNuEvent(Msg::kInfo));
06988     
06989     // Only care about preselected nubars here
06990     nu.anaVersion = NuCuts::kNMB0325Bravo;
06991     if (!this->IsGoodPreSelectionCuts(plots,nu)) continue;
06992     
06993     //OVERRIDE
06994     
06995     //RE-RECONSTRUCT the neutrino energy
06996     // Redo the beam weights
06997     if (nu.simFlag==SimFlag::kMC) {
06998       nu.runPeriod = 0;
06999       lib.zBeamReweight.ExtractZBeamReweight(nu);
07000     
07001       //Reweighting
07002       nu.applyBeamWeight = true;
07003       nu.applyEnergyShifts = false;
07004       nu.rw = 1;
07005       lib.reco.ApplyReweights(nu);
07006     }
07007     double rwprev = nu.rw;
07008     
07009 
07010     if (i < 200) {
07011       cout << "nu.charge    = " << nu.charge << endl
07012       << "nu.qp_rangebiased = " << nu.qp_rangebiased << endl
07013       << "nu.qp             = " << nu.qp << endl  
07014       << "nu.energy         = " << nu.energy << endl;
07015     }
07016     
07017     
07018 
07019     // First do nominal qp, nominal SKZP
07020     lib.reco.GetEvtEnergy(nu, false);
07021 
07022     if (nu.containmentFlag==1 || nu.containmentFlag==3) 
07023       cont = "Cont";
07024     else 
07025       cont = "Exit";
07026     
07027     
07028     for (int i = 0; i < 4; i++) {
07029       if (i % 2 == 0) nu.rw = rwprev;
07030       else            nu.rw = 1;
07031       
07032       if (i == 2) NuUtilities::FixDogwoodQP(nu);
07033       
07034       bravoCut.MakeCuts(nu);
07035       plots->FillSpectra(nu, "Presel"+post[i]);
07036       plots->FillSpectra(nu, cont+"Presel"+post[i]);
07037       plots->FillSelPlots(nu, "RoID", "Presel"+post[i]);
07038       plots->FillSelPlots(nu, "RoID", cont+"Presel"+post[i]);
07039       plots->FillSelPlots(nu, "SigmaQP_QP", "Presel"+post[i]);
07040       plots->FillSelPlots(nu, "SigmaQP_QP", cont+"Presel"+post[i]);
07041       plots->FillSelPlots(nu, "DpID", "Presel"+post[i]);
07042       plots->FillSelPlots(nu, "DpID", cont+"Presel"+post[i]);
07043       plots->FillSelPlots(nu, "RelativeAngle", "Presel"+post[i]);
07044       plots->FillSelPlots(nu, "RelativeAngle", cont+"Presel"+post[i]);      
07045       plots->FillSelPlots(nu, "TrackLength", "Presel"+post[i]);
07046       plots->FillSelPlots(nu, "TrackLength", cont+"Presel"+post[i]);
07047       
07048       if (nu.charge == 1) {
07049         if (bravoCut.PassedExcept("SigmaQP_QP")) {
07050           plots->FillSelPlots(nu, "SigmaQP_QP", "NotSigqp"+post[i]);
07051           plots->FillSelPlots(nu, "SigmaQP_QP", cont+"NotSigqp"+post[i]);
07052           plots->FillSelPlots(nu, "TrackLength", "NotSigqp"+post[i]);
07053           plots->FillSelPlots(nu, "TrackLength", cont+"NotSigqp"+post[i]);
07054           plots->FillSpectra(nu, "NotSigqp"+post[i]);
07055           plots->FillSpectra(nu, cont+"NotSigqp"+post[i]);
07056         }
07057         if (bravoCut.PassedExcept("DpID")) {
07058           plots->FillSelPlots(nu, "DpID", "NotDpID"+post[i]);
07059           plots->FillSelPlots(nu, "DpID", cont+"NotDpID"+post[i]);
07060           plots->FillSelPlots(nu, "TrackLength", "NotDpID"+post[i]);
07061           plots->FillSelPlots(nu, "TrackLength", cont+"NotDpID"+post[i]);
07062           plots->FillSpectra(nu, "NotDpID"+post[i]);
07063           plots->FillSpectra(nu, cont+"NotDpID"+post[i]);
07064         }
07065         if (bravoCut.PassedExcept("RelativeAngle")) {
07066           plots->FillSelPlots(nu, "RelativeAngle", "NotRelativeAngle"+post[i]);
07067           plots->FillSelPlots(nu, "RelativeAngle", cont+"NotRelativeAngle"+post[i]);
07068           plots->FillSelPlots(nu, "TrackLength", "NotRelativeAngle"+post[i]);
07069           plots->FillSelPlots(nu, "TrackLength", cont+"NotRelativeAngle"+post[i]);
07070           plots->FillSpectra(nu, "NotRelativeAngle"+post[i]);
07071           plots->FillSpectra(nu, cont+"NotRelativeAngle"+post[i]);
07072         }
07073       }    
07074       if (bravoCut.Passed()) {
07075         plots->FillSelPlots(nu, "TrackLength", "Selected"+post[i]);
07076         plots->FillSelPlots(nu, "TrackLength", cont+"Selected"+post[i]);
07077         plots->FillSpectra(nu, "Selected"+post[i]);
07078         plots->FillSpectra(nu, cont+"Selected"+post[i]);
07079       }
07080     }
07081     
07082     
07083     if (nu.charge==-1) lib.cnt.nuNQCounter++;
07084     else if (nu.charge==+1) lib.cnt.nuPQCounter++;
07085     else cout<<"ahhh, bad charge (11)"<<endl;
07086     
07087   }//end of loop over summary tree
07088   
07089   MSG("NuAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
07090   
07094   
07095   //print out the numbers of events
07096   lib.cnt.PrintMicroDST();
07097   
07098   cout<<endl
07099   <<"************************************************"<<endl
07100   <<"***             Ending QPStudy()             ***"<<endl
07101   <<"************************************************"<<endl << endl;;
07102   
07103 }
07104 
07105 
07106 //......................................................................
07107 
07108 void NuDSTAna::NDQPRB(bool cedar)
07109 {
07110   cout<<endl
07111   <<"***********************************************"<<endl
07112   <<"***            Starting NDQPRB()            ***"<<endl
07113   <<"***********************************************"<<endl << endl;;
07114   
07115   NuInputEvents& input=this->DoIO(0,"","");
07116   
07117   //get an instance of the code library
07118   NuLibrary& lib=NuLibrary::Instance();
07119   
07120   input.ResetNuEventLoopPositionToStart();
07121   
07122   const int Ncont = 4;
07123   
07124   TString contNames[] = {"cont1","cont2","cont3","cont4"};
07125   TString varNames[99];
07126   double varMin[99];
07127   double varMax[99];
07128   double vals[99];
07129   
07130   int v = 0;
07131   varNames[0] = "trkEnMC";
07132   varMin[v]   = 0;
07133   varMax[v]   = 50;
07134   v = 1;
07135   varNames[v] = "xTrkVtx";
07136   varMin[v]   = 0.5;
07137   varMax[v]   = 2.5;
07138   v = 2;
07139   varNames[v] = "yTrkVtx";
07140   varMin[v]   = -0.75;
07141   varMax[v]   = 1.25;
07142   v = 3;
07143   varNames[v] = "zTrkVtx";
07144   varMin[v]   = 0.5;
07145   varMax[v]   = 4.5;
07146   v = 4;
07147   varNames[v] = "xTrkEnd";
07148   varMin[v]   = -2;
07149   varMax[v]   = 3;
07150   v = 5;
07151   varNames[v] = "yTrkEnd";
07152   varMin[v]   = -2.5;
07153   varMax[v]   = 2.5;
07154   v = 6;
07155   varNames[v] = "zTrkEnd";
07156   varMin[v]   = 7;
07157   varMax[v]   = 17;
07158   v = 7;
07159   varNames[v] = "trkLength";
07160   varMin[v]   = 40;
07161   varMax[v]   = 280;
07162   v = 8;
07163   varNames[v] = "qp";
07164   varMin[v]   = -1;
07165   varMax[v]   = 1;
07166   v = 9;
07167   varNames[v] = "invqp";
07168   varMin[v]   = -200;
07169   varMax[v]   = 200;
07170   
07171   v = 10;
07172   varNames[v] = "specLength";
07173   varMin[v]   = 0;
07174   varMax[v]   = 180;
07175 
07176   const int Nvars = 11;
07177   
07178   int nbinsX = 250;
07179   int nbinsY = 500;
07180   double minY = -1;
07181   double maxY = 9;
07182   double valy;
07183   
07184   TH2D *plots[Nvars][Ncont];
07185   
07186   for (int v = 0; v < Nvars; v++) {
07187     for (int c = 0; c < Ncont; c++) {
07188       plots[v][c] = new TH2D("h"+varNames[v]+"_"+contNames[c],
07189                              contNames[c]+";"+varNames[v]+";Reco-True/True",
07190                              nbinsX, varMin[v], varMax[v],
07191                              nbinsY, minY, maxY);
07192     }
07193   }
07194   
07195   cout<<endl
07196   <<"************************************************"<<endl
07197   <<"***      Starting main loop over snarls      ***"<<endl
07198   <<"************************************************"<<endl;
07199   for (Int_t i=0;i<input.GetEntriesNuEvent();++i) {
07200     lib.cnt.evtCounter++;
07201     
07202     this->PrintLoopProgress(i,input.GetEntriesNuEvent(),1);
07203     if (i < 200) cout << "Debug: i=" << i << "/" << input.GetEntriesNuEvent() << endl;;
07204     
07205     
07206     NuEvent &nu=const_cast<NuEvent&>(input.GetNextNuEvent(Msg::kInfo));
07207     
07208     if (nu.trkEnMC == 0) continue; // Only events with real track energy
07209     if (!cedar && nu.qp_rangebiased == 0) continue; // Only events with passed track
07210     if (cedar && nu.qp == 0) continue; // Only events with passed track
07211     
07212     // Only care about preselected nubars here
07213     nu.anaVersion = NuCuts::kNMB0325Bravo;
07214     if (!this->IsGoodPreSelectionCuts(0,nu)) continue;
07215     
07216     //OVERRIDE
07217     
07218     //RE-RECONSTRUCT the neutrino energy
07219     // Redo the beam weights
07220     if (nu.simFlag==SimFlag::kMC) {
07221       nu.runPeriod = 0;
07222       lib.zBeamReweight.ExtractZBeamReweight(nu);
07223       
07224       //Reweighting
07225       nu.applyBeamWeight = true;
07226       nu.applyEnergyShifts = false;
07227       nu.rw = 1;
07228       lib.reco.ApplyReweights(nu);
07229     }
07230     
07231     // First do nominal qp, nominal SKZP
07232     lib.reco.GetEvtEnergy(nu, false);
07233     
07234     int c = nu.containmentFlag - 1;
07235     vals[0] = nu.trkEnMC;
07236     vals[1] = nu.xTrkVtx;
07237     vals[2] = nu.yTrkVtx;
07238     vals[3] = nu.zTrkVtx;
07239     vals[4] = nu.xTrkEnd;
07240     vals[5] = nu.yTrkEnd;
07241     vals[6] = nu.zTrkEnd;
07242     vals[7] = nu.trkLength;
07243     if (cedar) {
07244       if (nu.qp == 0 || nu.trkEnMC == 0) continue;
07245       vals[8] = nu.qp;
07246       vals[9] = 1./nu.qp;
07247       valy = TMath::Abs(nu.qp*nu.trkEnMC) - 1.;
07248     }
07249     else {
07250       if (nu.qp_rangebiased == 0 || nu.trkEnMC == 0) continue;
07251       vals[8] = nu.qp_rangebiased;
07252       vals[9] = 1./nu.qp_rangebiased;
07253       valy = TMath::Abs(nu.qp_rangebiased*nu.trkEnMC) - 1.;
07254     }
07255     vals[10] = nu.trkLength - (118-nu.planeTrkVtx);
07256     
07257     
07258     for (int v = 0; v < Nvars; v++) {
07259       plots[v][c]->Fill(vals[v], valy, nu.rw);
07260     }
07261     
07262     
07263     if (nu.charge==-1) lib.cnt.nuNQCounter++;
07264     else if (nu.charge==+1) lib.cnt.nuPQCounter++;
07265     else cout<<"ahhh, bad charge (11)"<<endl;
07266     
07267   }//end of loop over summary tree
07268   
07269   MSG("NuAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
07270   
07274   
07275   //print out the numbers of events
07276   lib.cnt.PrintMicroDST();
07277   
07278   cout<<endl
07279   <<"***********************************************"<<endl
07280   <<"***             Ending NDQPRB()             ***"<<endl
07281   <<"***********************************************"<<endl << endl;;
07282   
07283 }
07284 
07285 
07286 //......................................................................
07287 
07288 void NuDSTAna::BRevAna()
07289 {
07290   NuInputEvents& input=this->DoIO(0,"","");
07291 
07292   //use config object to store info
07293   NuConfig config;
07294   config.detector=Detector::kFar;
07295   config.run=100;
07296 
07297   TString post;
07298 
07299   //get an instance of the code library
07300   NuLibrary& lib=NuLibrary::Instance();
07301 
07302   //get an object to fill plots
07303   const NuPlots* plots=0;
07304 
07305   //version to do reco/cuts with
07306   NuCuts::NuAnaVersion_t overrideAnaVersion=NuCuts::kNMB0325Bravo;
07307   //NuCuts::NuAnaVersion_t overrideAnaVersion=NuCuts::kRM2;
07308 
07309   input.ResetNuEventLoopPositionToStart();
07310   TH1::AddDirectory(true);
07311 
07315 
07316   cout<<endl
07317         <<"************************************************"<<endl
07318         <<"***      Starting main loop over snarls      ***"<<endl
07319         <<"************************************************"<<endl;
07320 
07321   for (Int_t i=0;i<input.GetEntriesNuEvent();++i) {
07322     lib.cnt.evtCounter++;
07323 
07324     this->PrintLoopProgress(i,input.GetEntriesNuEvent(),1);
07325 
07326     NuEvent &nu=const_cast<NuEvent&>(input.GetNextNuEvent(Msg::kDebug));
07327 
07328     //OVERRIDE
07329     //Selection
07330     nu.anaVersion=this->SanityCheckedAnaVersion(nu.anaVersion,overrideAnaVersion);
07331 
07332     // Set RunII Weighting
07333     nu.applyBeamWeight = true;
07334     nu.beamWeight = nu.beamWeightRunII;
07335     nu.trkEnWeight = nu.trkEnWeightRunII;
07336     nu.shwEnWeight = nu.shwEnWeightRunII;
07337     nu.detectorWeightNMB = nu.detectorWeightNMBRunII;
07338     nu.detectorWeightNM = nu.detectorWeightNMRunII;
07339 
07340     //RE-RECONSTRUCT the neutrino energy
07341     lib.reco.GetEvtEnergy(nu, false);
07342     lib.reco.ApplyReweights(nu);
07343 
07345     // Fill Truth Histos before cuts
07347 
07348     if (!this->IsGoodPreSelectionCuts(plots,nu)) continue;
07349 
07350     if (nu.simFlag == SimFlag::kMC) {
07351       if (nu.iaction != 1) {
07352         post = "NC";
07353       }
07354       else {
07355         if (lib.cuts.IsInFidVolTrueEvt(nu)) {
07356           plots->FillBRev(nu,"True",true);
07357         }
07358         if ( (nu.charge > 0 && nu.inu != -14) || (nu.charge < 0 && nu.inu != 14) ) {
07359           post = "WrSn";
07360         } else {
07361           post = "Sig";
07362         }
07363       }
07364     }
07365     else {
07366       post = "Data";
07367     }
07368 
07369     //make all the std cuts
07370     if (!this->IsGoodStdCuts(plots,nu)) continue;
07371 
07373     //END OF STD CUTS
07375 
07376     if (nu.charge==-1) lib.cnt.nuNQCounter++;
07377     else if (nu.charge==+1) lib.cnt.nuPQCounter++;
07378     else cout<<"ahhh, bad charge(12)"<<endl;
07379 
07380 
07381     plots->FillBRev(nu,post);
07382     if (nu.simFlag == SimFlag::kMC) {
07383       plots->FillBRev(nu,"All");
07384     }
07385 
07386   }//end of loop over summary tree
07387 
07388   MSG("NuAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
07389 
07393 
07394   //print out the numbers of events
07395   lib.cnt.PrintMicroDST();
07396 
07397   MSG("NuAnalysis",Msg::kInfo)
07398         <<" ** Finished BRevAna method **"<<endl;
07399 }
07400 
07401 //......................................................................
07402 
07403 void NuDSTAna::CoilHoleAna()
07404 {
07405   NuInputEvents& input=this->DoIO(0,"","null");
07406 
07407   //use config object to store info
07408   NuConfig config;
07409   config.detector=Detector::kFar;
07410   config.run=100;
07411 
07412 
07413   //get an object to fill plots
07414   const NuPlots* plots=0;
07415 
07416   //version to do reco/cuts with
07417   //NuCuts::NuAnaVersion_t overrideAnaVersion=NuCuts::kNMB0325Bravo;
07418 
07419   input.ResetNuEventLoopPositionToStart();
07420 
07424 
07425   cout<<endl
07426       <<"************************************************"<<endl
07427       <<"***      Starting main loop over snarls      ***"<<endl
07428       <<"************************************************"<<endl;
07429 
07430   for (Int_t i=0;i<input.GetEntriesNuEvent();++i) {
07431     this->PrintLoopProgress(i,input.GetEntriesNuEvent(),1);
07432 
07433     NuEvent& nu=const_cast<NuEvent&>(input.GetNextNuEvent(Msg::kDebug));
07434 
07435     nu.anaVersion=NuCuts::kCC0250Std;
07436 
07437     //make the preselection cuts
07438     //if (!this->IsGoodPreSelectionCuts(plots,nu)) continue;
07439     plots->FillCoilHole(nu);
07440 
07441   } //end of loop over summary tree
07442 
07443   MSG("NuDSTAna",Msg::kInfo)<<"Finished main loop"<<endl;
07444 
07448 
07449   MSG("NuDSTAna",Msg::kInfo)
07450     <<" ** Finished BRevAna method **"<<endl;
07451 }
07452 
07453 //......................................................................
07454 
07455 void NuDSTAna::CSSAnaRashid()
07456 {
07457   NuInputEvents& input=this->DoIO();
07458 
07459   //get an object to fill plots
07460   const NuPlots* plots=0;
07461 
07462   input.ResetNuEventLoopPositionToStart();
07463 
07467 
07468   cout<<endl
07469       <<"************************************************"<<endl
07470       <<"***      Starting main loop over snarls      ***"<<endl
07471       <<"************************************************"<<endl;
07472 
07473   for (Int_t i=0;i<input.GetEntriesNuEvent();++i) {
07474     this->PrintLoopProgress(i,input.GetEntriesNuEvent(),1);
07475 
07476     NuEvent& nu=const_cast<NuEvent&>(input.GetNextNuEvent(Msg::kDebug));
07477 
07478     //make the post-preselection plots (do this first)
07479     this->MakePostPreSelectionPlots(plots,nu);
07480 
07482     //NOW MAKE THE CUTS THAT YOU ARE INVESTIGATING THE EFFECT OF
07483     //THE SYSTEMATICS ON
07485 
07486     //speed up cut for looking at nmb only
07487     if (nu.charge==-1) {
07488       //neutrino-like event
07489       if (nu.dpID<-0.1) continue;
07490     }
07491     else if (nu.charge==+1) {
07492       //anti-neutrino-like event
07493 
07494       //EXAMPLE CUTS:
07495 
07496       if (nu.dpID<+0.4) continue;
07497 
07498       //if (nu.prob<0.1) continue;
07499 
07500       //if (roID<0.3) continue;//WHAT VALUE TO USE???
07501 
07502       //OTHER CUTS INVESTIGATED HERE...
07503     }
07504 
07505     //now fill the plots after the selection has been applied
07506     this->MakeFinalPlots(plots,nu);
07507 
07508   }//end of loop over summary tree
07509 
07510   MSG("NuAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
07511 
07515 
07516   MSG("NuAnalysis",Msg::kInfo)
07517     <<" ** Finished CSSAnaRashid method **"<<endl;
07518 }
07519 
07520 //......................................................................
07521 
07522 void NuDSTAna::CSSAna()
07523 {
07524   NuInputEvents& input=this->DoIO();
07525 
07526   //get an object to fill plots
07527   const NuPlots* plots=0;
07528 
07529   input.ResetNuEventLoopPositionToStart();
07530 
07534 
07535   cout<<endl
07536       <<"************************************************"<<endl
07537       <<"***      Starting main loop over snarls      ***"<<endl
07538       <<"************************************************"<<endl;
07539 
07540   for (Int_t i=0;i<input.GetEntriesNuEvent();++i) {
07541     this->PrintLoopProgress(i,input.GetEntriesNuEvent(),1);
07542 
07543     NuEvent& nu=const_cast<NuEvent&>(input.GetNextNuEvent(Msg::kDebug));
07544 
07545     //speed up cut for looking at nmb only
07546     if (nu.charge==-1) continue;
07547 
07548     plots->FillEffPur(nu, nu.prob > 0.1);
07549   }//end of loop over summary tree
07550 
07551   MSG("NuAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
07552 
07556 
07557   MSG("NuAnalysis",Msg::kInfo)
07558     <<" ** Finished CSSAna method **"<<endl;
07559 }
07560 
07561 //......................................................................
07562 
07563 void NuDSTAna::Oscillate(NuEvent& nu,
07564                          const NuXMLConfig* xmlConfig) const
07565 {
07566   //check that the xmlConfig object exists
07567   if (!xmlConfig) return;
07568 
07569   //don't oscillate real data
07570   if (SimFlag::kData == nu.simFlag){
07571     MAXMSG("NuDSTAna",Msg::kInfo,1)
07572       << "Not applying fake oscillations to data" << endl;
07573     return;
07574   }
07575 
07576   //don't oscillate the ND data
07577   if (Detector::kFar != nu.detector){
07578     MAXMSG("NuDSTAna",Msg::kInfo,1)
07579       << "Not applying fake oscillations to ND MC" << endl;
07580     return;
07581   }
07582 
07583   //check for !CC (i.e. NC)
07584   if (1 != nu.iaction && (16 == nu.inu || -16 == nu.inu)){
07585     nu.rw=0;
07586     MAXMSG("NuDSTAna",Msg::kInfo,1)
07587       <<"Removing NC events from tau file (nu.rw set to zero)"<<endl;
07588     return;
07589   }
07590 
07591   if(xmlConfig->OscillationModel() == 1){
07592     switch(nu.iaction){
07593     case 0:
07594       nu.rw *= NuUtilities::DecayWeightNC(nu.neuEnMC,
07595                                       xmlConfig->DM2Nu(),
07596                                       xmlConfig->SN2Nu());
07597     return;
07598     case 1:
07599       nu.rw *= NuUtilities::DecayWeightCC(nu.neuEnMC,
07600                                           xmlConfig->DM2Nu(),
07601                                           xmlConfig->SN2Nu());
07602       return;
07603     default:
07604       assert(0 && "Unknown iaction");
07605     }
07606   }
07607 
07608   if(xmlConfig->OscillationModel() == 2){
07609     nu.rw *= NuUtilities::DecoherenceWeight(nu.neuEnMC,
07610                                             xmlConfig->DM2Nu(),
07611                                             xmlConfig->SN2Nu());
07612     return;
07613   }
07614 
07615   // It's not decay or decoherence, so it must be oscillations
07616   assert(xmlConfig->OscillationModel() == 0);
07617 
07618   if (1 != nu.iaction){
07619     MAXMSG("NuDSTAna",Msg::kInfo,1)
07620       << "NCs don't oscillate" << endl;
07621     return;
07622   }
07623 
07624   //select everything that is not NuMu(bar) or NuTau(bar)
07625   //i.e. true if nue(bar)
07626   if (!(14 == nu.inu || -14 == nu.inu ||
07627         16 == nu.inu || -16 == nu.inu)){
07628     MAXMSG("NuDSTAna",Msg::kInfo,1)
07629       <<"Not oscillating nue events (non-muon/tau (anti)neutinos)"<<endl;
07630     return;
07631   }
07632 
07633   //select events that started as nues and were turned in to nutaus
07634   //we can ignore these
07635   if((nu.inunoosc == 12 || nu.inunoosc==-12) &&
07636      (nu.inu==16 || nu.inu==-16)){
07637     nu.rw=0;
07638     MAXMSG("NuDSTAna",Msg::kInfo,1)
07639       <<"Removing beam nue events from tau file (nu.rw set to zero)"
07640       <<endl;
07641     return;
07642   }
07643 
07644   //Do this last, so that taus and nue's are still properly
07645   //reweighted, even in the no-oscillation case
07646   //For example, in the no-osc case the nutaus are given a weight of 0
07647   //so have to explictly just not touch them
07648   if (xmlConfig->DM2Nu() < 0.0 ||
07649       xmlConfig->SN2Nu() < 0.0 ||
07650       xmlConfig->DM2Bar() < 0.0 ||
07651       xmlConfig->SN2Bar() < 0.0){
07652     MAXMSG("NuDSTAna",Msg::kInfo,1)
07653       <<"Not applying fake oscillations due to xml configuration"<<endl;
07654     return;
07655   }
07656 
07657   //include the oscillation weight in the general nu.rw variable
07658   nu.rw *= this->OscillationWeight(nu.neuEnMC,nu.inu,xmlConfig);
07659   MAXMSG("NuDSTAna",Msg::kInfo,10)
07660     <<"Oscillating with dm2="<<xmlConfig->DM2Nu()
07661     <<"; weight="<<this->OscillationWeight(nu.neuEnMC,nu.inu,xmlConfig)
07662     <<"; energy="<<nu.neuEnMC
07663     <<endl;
07664   return;
07665 }
07666 
07667 //......................................................................
07668 
07669 void NuDSTAna::Oscillate(NuMCEvent& mc,
07670                          const NuXMLConfig* xmlConfig) const
07671 {
07672   if (!xmlConfig){return;}
07673   if (SimFlag::kData == mc.simFlag){
07674     MAXMSG("NuDSTAna",Msg::kInfo,1)
07675       << "Not applying fake oscillations to data" << endl;
07676     return;
07677   }
07678   if (Detector::kFar != mc.detector){
07679     MAXMSG("NuDSTAna",Msg::kInfo,1)
07680       << "Not applying fake oscillations to ND MC" << endl;
07681     return;
07682   }
07683   if (xmlConfig->DM2Nu() < 0.0 ||
07684       xmlConfig->SN2Nu() < 0.0 ||
07685       xmlConfig->DM2Bar() < 0.0 ||
07686       xmlConfig->SN2Bar() < 0.0){
07687     MAXMSG("NuDSTAna",Msg::kInfo,1)
07688       << "Not applying fake oscillations due to xml configuration"
07689       << endl;
07690     return;
07691   }
07692   if (1 != mc.iaction && (16 == mc.inu || -16 == mc.inu)){
07693     mc.rw=0;
07694     MAXMSG("NuDSTAna",Msg::kInfo,1)
07695       <<"Removing MC NC from Tau file"<<endl;
07696     return;
07697   }
07698 
07699   if(xmlConfig->OscillationModel() == 1){
07700     switch(mc.iaction){
07701     case 0:
07702       mc.rw *= NuUtilities::DecayWeightNC(mc.neuEnMC,
07703                                       xmlConfig->DM2Nu(),
07704                                       xmlConfig->SN2Nu());
07705     return;
07706     case 1:
07707       mc.rw *= NuUtilities::DecayWeightCC(mc.neuEnMC,
07708                                           xmlConfig->DM2Nu(),
07709                                           xmlConfig->SN2Nu());
07710       return;
07711     default:
07712       assert(0 && "Unknown iaction");
07713     }
07714   }
07715 
07716   if(xmlConfig->OscillationModel() == 2){
07717     mc.rw *= NuUtilities::DecoherenceWeight(mc.neuEnMC,
07718                                             xmlConfig->DM2Nu(),
07719                                             xmlConfig->SN2Nu());
07720     return;
07721   }
07722 
07723   // It's not decay or decoherence, so it must be oscillations
07724   assert(xmlConfig->OscillationModel() == 0);
07725 
07726   if (1 != mc.iaction){
07727     MAXMSG("NuDSTAna",Msg::kInfo,1)
07728       << "NCs don't oscillate" << endl;
07729     return;
07730   }
07731 
07732   if (!(14 == mc.inu || -14 == mc.inu) ||
07733       16 == mc.inu || -16 == mc.inu){
07734     MAXMSG("NuDSTAna",Msg::kInfo,1)
07735       << "Not oscillating non-muon(tau) (anti)neutino" << endl;
07736     return;
07737   }
07738   if( (mc.inunoosc == 12 ||mc.inunoosc==-12) &&
07739       (mc.inu==16 || mc.inu==-16)){
07740     mc.rw=0;
07741     MAXMSG("NuDSTAna",Msg::kInfo,1)
07742       <<"beam nue already don't oscillate to tau"
07743       <<endl;
07744     return;
07745   }
07746 
07747   mc.rw *= this->OscillationWeight(mc.neuEnMC,mc.inu,xmlConfig);
07748   return;
07749 }
07750 
07751 //......................................................................
07752 
07753 const Float_t NuDSTAna::OscillationWeight
07754 (const Float_t energy,const Int_t inu,const NuXMLConfig* xmlConfig) const
07755 {
07756   if (14==inu){
07757     return NuUtilities::OscillationWeight(energy,
07758                                           xmlConfig->DM2Nu(),
07759                                           xmlConfig->SN2Nu());
07760   }
07761   else if (-14==inu){
07762     return NuUtilities::OscillationWeight(energy,
07763                                           xmlConfig->DM2Bar(),
07764                                           xmlConfig->SN2Bar());
07765   }
07766   if (16==inu){
07767     return 1-NuUtilities::OscillationWeight(energy,
07768                                             xmlConfig->DM2Nu(),
07769                                             xmlConfig->SN2Nu());
07770   }
07771   else if (-16==inu){
07772     return 1-NuUtilities::OscillationWeight(energy,
07773                                             xmlConfig->DM2Bar(),
07774                                             xmlConfig->SN2Bar());
07775   }
07776   else return 1; // Doesn't oscillate
07777 }
07778 
07779 
07780 //......................................................................
07781 
07782 void NuDSTAna::TestNuSyst()
07783 {
07784   NuInputEvents& input=this->DoIO();
07785   input.ResetNuEventLoopPositionToStart();
07786 
07787   
07788   NuSystematic syst;
07789   
07790   cout << "Initial: " << endl;
07791   syst.PrintState(1);
07792   
07793   std::map<TString, double> shifts;
07794   
07795   //shifts["ShowerEnergyScaleBoth"] = 1;
07796   //shifts["DecayPipe"] = 1;
07797   //shifts["NuMuBarXSecSum"] = 1;
07798   
07799   cout << "Setting Shifts as Values" << endl;
07800   shifts["AllBackgroundsScaleBoth"] = 1.25;
07801   shifts["TrackEnergyRange"] = 1.04;
07802   syst.SetShiftsAsValues(shifts);
07803   syst.PrintState();
07804   
07805   cout << "Randomize: " << endl;
07806   syst.Randomize();
07807   syst.PrintState();
07808 
07809   
07810   cout << "Setting Shifts to 1 Sigma" << endl;
07811   shifts["AllBackgroundsScaleBoth"] = 1;
07812   shifts["TrackEnergyRange"] = 1;
07813   syst.SetShiftsAsSigmas(shifts);
07814   
07815   cout << "One Sigma: " << endl;
07816   syst.PrintState();
07817   
07818   
07819   //NuCutter cutter(9);
07820   NuCutImps::Bravo bravoCut;
07821   
07822   syst.SetNuBarSelector(&bravoCut);
07823   
07824   
07825   return;
07826   
07827   //get an instance of the code library
07828   //NuLibrary& lib=NuLibrary::Instance();
07829   
07830   
07831   
07832   int selCount = 0;
07833   int cutCount = 0;
07834   
07835   cout<<endl
07836   <<"************************************************"<<endl
07837   <<"***      Starting main loop over snarls      ***"<<endl
07838   <<"************************************************"<<endl;
07839   for (Int_t i=0;i<input.GetEntriesNuEvent();++i) {
07840     //for (Int_t i=0;i<0;++i) {
07841     
07842     this->PrintLoopProgress(i,input.GetEntriesNuEvent(),1);
07843     
07844     NuEvent &nu=const_cast<NuEvent&>(input.GetNextNuEvent(Msg::kWarning));
07845    
07846     if (nu.charge == -1) continue;
07847     
07848     bravoCut.MakeCuts(nu);
07849     
07850     if (nu.iaction == 0 || nu.inu == 14) {
07851       if (bravoCut.Passed()) {
07852         selCount++;
07853       }
07854       else {
07855         cutCount++;
07856       }
07857       
07858       cout << "Event #" << i << ": " << endl;
07859       cout << "  passed    = " << (bravoCut.Passed() ? "Yes" : "No") << endl
07860       //<< "  contained = " << (nu.usedRange ? "Yes" : "No") << endl
07861       << "  pre rw    = " << nu.rw << endl;
07862       //<< "  pre E     = " << nu.energy << endl;
07863       
07864       syst.Shift(nu);
07865 
07866       cout << "  post rw   = " << nu.rw << endl;
07867       //<< "  post E    = " << nu.energy << endl;
07868     }
07869 
07870     if (selCount > 10 && cutCount > 10) {
07871       break;
07872     }
07873     
07874   }    
07875   cout << "Done." << endl;;
07876   
07877 }
07878 
07879 
07880 

Generated on Mon Feb 15 11:07:10 2010 for loon by  doxygen 1.3.9.1