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

NuAnalysis.cxx

Go to the documentation of this file.
00001 
00002 
00003 // Coded by Jeff Hartnell Dec/2005 onwards
00004 //
00005 // Contact: j.j.hartnell@rl.ac.uk
00007 
00008 #include <set>
00009 #include <cmath>
00010 #include "TH2F.h"
00011 #include "TH3F.h"
00012 #include "TNtuple.h"
00013 #include "TProfile.h"
00014 #include "TSpline.h"
00015 #include "TRegexp.h"
00016 
00017 #include "BeamDataUtil/BeamMonSpill.h"
00018 #include "Conventions/BeamType.h"
00019 #include "BeamDataUtil/BMSpillAna.h"
00020 #include "DataUtil/infid_sr_interface.h"
00021 #include "JobControl/JobCEnv.h"
00022 #include "Mad/MadDpID.h"
00023 #include "Mad/MadAbID.h"
00024 #include "MessageService/MsgFormat.h"
00025 #include "MessageService/MsgService.h"
00026 #include "BeamDataNtuple/NtpBDLiteRecord.h"
00027 #include "CandFitTrackSA/Ntp/NtpFitSARecord.h"
00028 #include "CandNtupleSR/NtpSREvent.h"
00029 #include "CandNtupleSR/NtpSRTrack.h"
00030 #include "CandNtupleSR/NtpSRShower.h"
00031 #include "CandNtupleSR/NtpSRStrip.h"
00032 #include "StandardNtuple/NtpStRecord.h"
00033 #include "MCNtuple/NtpMCTruth.h"
00034 #include "TruthHelperNtuple/NtpTHEvent.h"
00035 #include "TruthHelperNtuple/NtpTHShower.h"
00036 #include "TruthHelperNtuple/NtpTHTrack.h"
00037 #include "Conventions/ReleaseType.h"
00038 #include "MCReweight/SKZPWeightCalculator.h"
00039 #include "UgliGeometry/UgliGeomHandle.h"
00040 
00041 #include "NtupleUtils/LISieve.h"
00042 #include "NtupleUtils/NuCounter.h"
00043 #include "NtupleUtils/NuCuts.h"
00044 #include "NtupleUtils/NuEvent.h"
00045 #include "NtupleUtils/NuExtraction.h"
00046 #include "NtupleUtils/NuGeneral.h"
00047 #include "NtupleUtils/NuHistos.h"
00048 #include "NtupleUtils/NuInputEvents.h"
00049 #include "NtupleUtils/NuReco.h"
00050 #include "NtupleUtils/NuMCEvent.h"
00051 #include "NtupleUtils/NuZBeamReweight.h"
00052 
00053 #include "NtupleUtils/NuLibrary.h"
00054 #include "NuMuBar/NuAnalysis.h"
00055 #include "NuMuBar/NuBeam.h"
00056 #include "NuMuBar/NuConfig.h"
00057 #include "NuMuBar/NuMadAnalysis.h"
00058 #include "NuMuBar/NuOutputWriter.h"
00059 #include "NuMuBar/NuPlots.h"
00060 #include "NuMuBar/NuPIDInterface.h"
00061 #include "NuMuBar/NuTime.h"
00062 
00063 // for the NC analysis
00064 #include "AnalysisNtuples/Module/CondensedNtpModule.h"
00065 #include "AnalysisNtuples/Module/ANtpRecoNtpManipulator.h"
00066 #include "AnalysisNtuples/Module/ANtpInfoObjectFillerNC.h"
00067 #include "AnalysisNtuples/ANtpEventInfoNC.h"
00068 #include "AnalysisNtuples/ANtpTrackInfoNC.h"
00069 #include "AnalysisNtuples/ANtpShowerInfoNC.h"
00070 #include "AnalysisNtuples/ANtpTruthInfoBeam.h"
00071 #include "AnalysisNtuples/ANtpBeamInfo.h"
00072 #include "AstroUtil/AstTime.h"
00073 
00074 
00075 using std::endl;
00076 using std::cout;
00077 using std::map;
00078 using std::vector;
00079 
00080 
00081 CVSID("$Id: NuAnalysis.cxx,v 1.70 2010/02/08 22:52:39 ahimmel Exp $");
00082 
00083 //......................................................................
00084 
00085 NuAnalysis::NuAnalysis()
00086 {
00087   MSG("NuAnalysis",Msg::kDebug)
00088     <<"Running NuAnalysis Constructor..."<<endl;
00089 
00090 
00091   MSG("NuAnalysis",Msg::kDebug)
00092     <<"Finished NuAnalysis Constructor"<<endl;
00093 }
00094 
00095 //......................................................................
00096 
00097 NuAnalysis::~NuAnalysis()
00098 {
00099   MSG("NuAnalysis",Msg::kDebug)
00100     <<"Running NuAnalysis Destructor..."<<endl;
00101   
00102 
00103   MSG("NuAnalysis",Msg::kDebug)
00104     <<"Finished NuAnalysis Destructor"<<endl;
00105 }
00106 
00107 //......................................................................
00108 
00109 void NuAnalysis::DemoInfidSRInterface(const NtpStRecord& ntp,
00110                                       const NtpSREvent& evt,
00111                                       const NuEvent& nu)
00112 {
00113   MAXMSG("NuAnalysis",Msg::kInfo,3)
00114     <<"Running DemoInfidSRInterface..."<<endl;
00115   
00116   //get the track and the shower
00117   //this first part is specific to the NuMuBar/NtupleUtils package
00118   //and is not part of the code demonstration
00119   
00120   //get an instance of the code library
00121   const NuLibrary& lib=NuLibrary::Instance();
00122 
00123   //get the best track in the event
00124   Int_t bestTrack=lib.reco.GetBestTrack(nu);
00125   if (bestTrack<1) return;
00126   const NtpSRTrack* ptrk=lib.reco.GetTrackWithIndexX
00127     (ntp,evt,bestTrack-1);
00128   const NtpSRTrack& trk=*ptrk;
00129 
00130   //get the best shower in the event
00131   Int_t bestShower=lib.reco.GetBestShower(nu);
00132   if (bestShower<1) return;
00133   const NtpSRShower* pshw=lib.reco.GetShowerWithIndexX
00134     (ntp,evt,bestShower-1);
00135   const NtpSRShower& shw=*pshw;
00136 
00140 
00141   //first up initialise the cuts to be the cc2008 version
00142   //just need to do this once
00143   static Bool_t infid_initialised=false;
00144   if (!infid_initialised) {
00145     infid_initialised=true;
00146     choose_infid_set("cc2008");
00147 
00148     //map out the z positions of the cuts
00149     for (Float_t z=0;z<30;z+=0.005) {
00150 
00151       //use values that will be in both detectors fiducial volumes
00152       Float_t x=1.5*Munits::m;
00153       Float_t y=0.6*Munits::m;
00154       
00155       //determine if in the fid. vol.
00156       const RecCandHeader& rec=ntp.GetHeader();
00157       Bool_t inFid=infid(rec.GetVldContext().GetDetector(),
00158                          rec.GetVldContext().GetSimFlag(),
00159                          x,y,z);
00160       MSG("NuAnalysis",Msg::kInfo)
00161         <<"z="<<z<<", inFid = "<<inFid<<endl;
00162     }
00163   }
00164   
00165   //determine if evt, trk and shw are in the fiducial volume
00166   //the offset to the trk vtx is subtracted in the function below
00167   Bool_t evtIsInFid=infid(ntp,evt);
00168   Bool_t trkIsInFid=infid(ntp,trk);
00169   Bool_t shwIsInFid=infid(ntp,shw);
00170   
00171   MAXMSG("NuAnalysis",Msg::kInfo,100)
00172     <<"Evt/Trk/Shw IsInFid = "
00173     <<evtIsInFid<<"/"<<trkIsInFid<<"/"<<shwIsInFid<<endl
00174     <<"evt(x,y,z) = ("<<evt.vtx.x<<","<<evt.vtx.y<<","<<evt.vtx.z<<")"
00175     <<endl
00176     <<"trk(x,y,z) = ("<<trk.vtx.x<<","<<trk.vtx.y<<","<<trk.vtx.z<<")"
00177     <<endl
00178     <<"shw(x,y,z) = ("<<shw.vtx.x<<","<<shw.vtx.y<<","<<shw.vtx.z<<")"
00179     <<endl;
00180   
00181   //check for differences due to trk vtx being in scintillator
00182   //and evt vtx being in the steel (usually)
00183   if (evtIsInFid!=trkIsInFid && evt.vtx.plane==trk.vtx.plane-1) {
00184     MAXMSG("NuAnalysis",Msg::kInfo,200)
00185       <<"*******************************************************"<<endl
00186       <<"*******************************************************"<<endl
00187       <<"*******************************************************"<<endl
00188       <<"Evt/Trk/Shw IsInFid = "
00189       <<evtIsInFid<<"/"<<trkIsInFid<<"/"<<shwIsInFid<<endl
00190       <<"evt(x,y,z) = ("<<evt.vtx.x<<","<<evt.vtx.y<<","<<evt.vtx.z<<")"
00191       <<endl
00192       <<"trk(x,y,z) = ("<<trk.vtx.x<<","<<trk.vtx.y<<","<<trk.vtx.z<<")"
00193       <<endl
00194       <<"shw(x,y,z) = ("<<shw.vtx.x<<","<<shw.vtx.y<<","<<shw.vtx.z<<")"
00195       <<endl
00196       <<"*******************************************************"<<endl
00197       <<"*******************************************************"<<endl
00198       <<"*******************************************************"<<endl
00199       <<endl;
00200   }
00201 }
00202 
00203 //......................................................................
00204 
00205 void NuAnalysis::BasicPlots()
00206 {
00207   MSG("NuAnalysis",Msg::kInfo) 
00208     <<" ** Running BasicPlots method... **"<<endl;
00209   
00210   //open the output file for the histograms
00211   fOutFile=this->OpenFile(100,"NuBasicPlots");
00212 
00213   TH1F* hNuInt=new TH1F("hNuInt","hNuInt",10000,-100,1000);
00214   hNuInt->SetTitle("Number of neutrino interactions per spill");
00215   hNuInt->GetXaxis()->SetTitle("# interactions");
00216   hNuInt->GetXaxis()->CenterTitle();
00217   hNuInt->GetYaxis()->SetTitle("");
00218   hNuInt->GetYaxis()->CenterTitle();
00219   hNuInt->SetFillColor(0);
00220   hNuInt->SetLineColor(1);
00221   //hNuInt->SetBit(TH1::kCanRebin);
00222 
00223   TH1F* hNuMuBarEn=new TH1F("hNuMuBarEn","hNuMuBarEn",4*352,-32,320);
00224   hNuMuBarEn->GetXaxis()->SetTitle("Energy (GeV)");
00225   hNuMuBarEn->GetXaxis()->CenterTitle();
00226   hNuMuBarEn->GetYaxis()->SetTitle("");
00227   hNuMuBarEn->GetYaxis()->CenterTitle();
00228   hNuMuBarEn->SetFillColor(0);
00229   hNuMuBarEn->SetLineColor(2);
00230   //hNuMuBarEn->SetBit(TH1::kCanRebin);
00231 
00232   TH1F* hNuMuEn=new TH1F("hNuMuEn","hNuMuEn",4*352,-32,320);
00233   hNuMuEn->GetXaxis()->SetTitle("Energy (GeV)");
00234   hNuMuEn->GetXaxis()->CenterTitle();
00235   hNuMuEn->GetYaxis()->SetTitle("");
00236   hNuMuEn->GetYaxis()->CenterTitle();
00237   hNuMuEn->SetFillColor(0);
00238   hNuMuEn->SetLineColor(1);
00239   hNuMuEn->SetLineWidth(2);
00240   //hNuMuEn->SetBit(TH1::kCanRebin);
00241 
00242   TH1F* hNueBarEn=new TH1F("hNueBarEn","hNueBarEn",4*352,-32,320);
00243   hNueBarEn->GetXaxis()->SetTitle("Energy (GeV)");
00244   hNueBarEn->GetXaxis()->CenterTitle();
00245   hNueBarEn->GetYaxis()->SetTitle("");
00246   hNueBarEn->GetYaxis()->CenterTitle();
00247   hNueBarEn->SetFillColor(0);
00248   hNueBarEn->SetLineColor(2);
00249   hNueBarEn->SetLineWidth(2);
00250   hNueBarEn->SetLineStyle(2);
00251   //hNueBarEn->SetBit(TH1::kCanRebin);
00252 
00253   TH1F* hNueEn=new TH1F("hNueEn","hNueEn",4*352,-32,320);
00254   hNueEn->GetXaxis()->SetTitle("Energy (GeV)");
00255   hNueEn->GetXaxis()->CenterTitle();
00256   hNueEn->GetYaxis()->SetTitle("");
00257   hNueEn->GetYaxis()->CenterTitle();
00258   hNueEn->SetFillColor(0);
00259   hNueEn->SetLineColor(1);
00260   hNueEn->SetLineWidth(1);
00261   hNueEn->SetLineStyle(2);
00262   //hNueEn->SetBit(TH1::kCanRebin);
00263 
00267   
00268   this->InitialiseLoopVariables();  
00269   
00270   //for(Int_t entry=0;entry<10000;entry++){
00271   for(Int_t entry=0;entry<this->GetEntries();entry++){
00272       
00273     this->SetLoopVariables(entry);
00274       
00275     //get reference to NtpStRecord from base class
00276     const NtpStRecord& ntp=(*this->GetNtpStRecord());
00277     
00278     TClonesArray& mcTca=*ntp.mc;
00279     Int_t numInt=mcTca.GetEntries();
00280     MAXMSG("NuAnalysis",Msg::kInfo,20)
00281       <<"Number of entries in NtpMCTruth="
00282       <<mcTca.GetEntries()<<endl;
00283     //if (mcTca.GetEntries()==0){ 
00284 
00285     hNuInt->Fill(mcTca.GetEntries());
00286 
00287     for (Int_t i=0;i<numInt;i++){
00288       const NtpMCTruth& mc=*(dynamic_cast<NtpMCTruth*>(mcTca[i]));
00289 
00290       string iaction="NC";
00291       if (mc.iaction==1) iaction="CC";
00292       string iresonance="QE ";
00293       if (mc.iresonance==1002) iresonance="RES";
00294       else if (mc.iresonance==1003) iresonance="DIS";
00295       else if (mc.iresonance==1004) iresonance=
00296                                       "Coherent pion production";
00297       string inu="??";
00298       if (mc.inu==14) inu="NuMu   ";
00299       else if (mc.inu==-14) inu="NuMuBar";
00300       else if (mc.inu==12) inu="NuE    ";
00301       else if (mc.inu==-12) inu="NuEBar ";
00302       
00303       MAXMSG("NuAnalysis",Msg::kInfo,100)
00304         <<"Interaction #"<<i<<" is "<<inu
00305         <<" "<<iaction
00306         <<" "<<iresonance<<endl;
00307 
00308       if (mc.inu==-14) hNuMuBarEn->Fill(mc.p4neu[3]);
00309       else if (mc.inu==14) hNuMuEn->Fill(mc.p4neu[3]);
00310       else if (mc.inu==-12) hNueBarEn->Fill(mc.p4neu[3]);
00311       else if (mc.inu==12) hNueEn->Fill(mc.p4neu[3]);
00312       else {
00313         MAXMSG("NuAnalysis",Msg::kWarning,100)
00314           <<"particle not defined for filling histo="<<mc.inu<<endl;
00315       }
00316     }
00317 
00318     //TClonesArray& tcaTk=(*ntpst.trk);
00319     //Int_t numTrks=tcaTk.GetEntries();
00320     
00321     //MAXMSG("NuAnalysis",Msg::kInfo,10)
00322     //<<"numTrks="<<numTrks
00323     //<<", ndigit="<<fRec->evthdr.ndigit
00324     //<<", nTrack="<<fRec->evthdr.ntrack<<endl;
00325 
00326     //Loop over tracks
00327     //for (Int_t itrk=0;itrk<numTrks;itrk++){
00328     //const NtpSRTrack* ptrk=
00329     //dynamic_cast<NtpSRTrack*>(tcaTk[itrk]);
00330     //const NtpSRTrack& trk=(*ptrk);
00331     //}
00332 
00333 
00334   }//end of for                                       
00335   
00339 
00340   MSG("NuAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
00341 
00342   MSG("NuAnalysis",Msg::kInfo) 
00343     <<" ** Finished BasicPlots method **"<<endl;
00344 }
00345 
00346 //......................................................................
00347 
00348 void NuAnalysis::EfficienciesOld()
00349 {
00350   MSG("NuAnalysis",Msg::kInfo) 
00351     <<" ** Running Efficiencies method... **"<<endl;
00352   
00353   //open the output file for the histograms
00354   fOutFile=this->OpenFile(100,"NuEfficiencies");
00355 
00356   TProfile* pNuMuBarQEffVsEn=new TProfile("pNuMuBarQEffVsEn","pNuMuBarQEffVsEn",50,0,50);
00357   pNuMuBarQEffVsEn->SetTitle("Charge Sign Efficiency vs. True Neutrino Energy");
00358   pNuMuBarQEffVsEn->GetXaxis()->SetTitle("Energy (GeV)");
00359   pNuMuBarQEffVsEn->GetXaxis()->CenterTitle();
00360   pNuMuBarQEffVsEn->GetYaxis()->SetTitle("Efficiency");
00361   pNuMuBarQEffVsEn->GetYaxis()->CenterTitle();
00362   pNuMuBarQEffVsEn->SetLineColor(1);
00363   pNuMuBarQEffVsEn->SetFillColor(0);
00364   //pNuMuBarQEffVsEn->SetBit(TH1::kCanRebin);
00365 
00366   TProfile* pNuMuQEffVsEn=new TProfile("pNuMuQEffVsEn","pNuMuQEffVsEn",50,0,50);
00367   pNuMuQEffVsEn->SetTitle("Charge Sign Efficiency vs. True Neutrino Energy");
00368   pNuMuQEffVsEn->GetXaxis()->SetTitle("Energy (GeV)");
00369   pNuMuQEffVsEn->GetXaxis()->CenterTitle();
00370   pNuMuQEffVsEn->GetYaxis()->SetTitle("Efficiency");
00371   pNuMuQEffVsEn->GetYaxis()->CenterTitle();
00372   pNuMuQEffVsEn->SetLineColor(1);
00373   pNuMuQEffVsEn->SetFillColor(0);
00374   //pNuMuQEffVsEn->SetBit(TH1::kCanRebin);
00375 
00376   TProfile* pNuMuBarFitPassVsEn=new TProfile("pNuMuBarFitPassVsEn","pNuMuBarFitPassVsEn",50,0,50);
00377   pNuMuBarFitPassVsEn->SetTitle("Fit Pass Fraction vs. True Neutrino Energy");
00378   pNuMuBarFitPassVsEn->GetXaxis()->SetTitle("Energy (GeV)");
00379   pNuMuBarFitPassVsEn->GetXaxis()->CenterTitle();
00380   pNuMuBarFitPassVsEn->GetYaxis()->SetTitle("Pass Fraction");
00381   pNuMuBarFitPassVsEn->GetYaxis()->CenterTitle();
00382   pNuMuBarFitPassVsEn->SetLineColor(1);
00383   pNuMuBarFitPassVsEn->SetFillColor(0);
00384   //pNuMuBarFitPassVsEn->SetBit(TH1::kCanRebin);
00385 
00386   TProfile* pNuMuFitPassVsEn=new TProfile("pNuMuFitPassVsEn","pNuMuFitPassVsEn",50,0,50);
00387   pNuMuFitPassVsEn->SetTitle("Fit Pass Fraction vs. True Neutrino Energy");
00388   pNuMuFitPassVsEn->GetXaxis()->SetTitle("Energy (GeV)");
00389   pNuMuFitPassVsEn->GetXaxis()->CenterTitle();
00390   pNuMuFitPassVsEn->GetYaxis()->SetTitle("Pass Fraction");
00391   pNuMuFitPassVsEn->GetYaxis()->CenterTitle();
00392   pNuMuFitPassVsEn->SetLineColor(1);
00393   pNuMuFitPassVsEn->SetFillColor(0);
00394   //pNuMuFitPassVsEn->SetBit(TH1::kCanRebin);
00395 
00399   
00400   this->InitialiseLoopVariables();  
00401   
00402   //for(Int_t entry=0;entry<10000;entry++){
00403   for(Int_t entry=0;entry<this->GetEntries();entry++){
00404       
00405     this->SetLoopVariables(entry);
00406       
00407     //get reference to NtpStRecord from base class
00408     const NtpStRecord& ntp=(*this->GetNtpStRecord());
00409     
00410     TClonesArray& mcTca=*ntp.mc;
00411     Int_t numInt=mcTca.GetEntries();
00412     MAXMSG("NuAnalysis",Msg::kInfo,20)
00413       <<"Number of entries in NtpMCTruth="
00414       <<mcTca.GetEntries()<<endl;
00415     //if (mcTca.GetEntries()==0){ 
00416 
00417     TClonesArray& evtTca=(*ntp.evt);
00418     const Int_t numEvts=evtTca.GetEntriesFast();
00419     
00420     TClonesArray& trkTca=(*ntp.trk);
00421     const Int_t numTrks=trkTca.GetEntriesFast();
00422 
00423     TClonesArray& thtrkTca=(*ntp.thtrk);//TruthHelper Track TCA
00424     const Int_t numthtrks=thtrkTca.GetEntriesFast();
00425 
00426     TClonesArray& thshwTca=(*ntp.thshw);//TruthHelper Shw TCA
00427     const Int_t numthshws=thshwTca.GetEntriesFast();
00428     
00429     TClonesArray& shwTca=(*ntp.shw);
00430     const Int_t numShws=shwTca.GetEntriesFast();
00431 
00432     //TClonesArray& stpTca=(*ntp.stp);
00433     //const Int_t numStps=stpTca.GetEntries();
00434 
00435     //TClonesArray& slcTca=(*ntp.slc);
00436     //const Int_t numSlcs=slcTca.GetEntries();
00437     
00438     TClonesArray& hepTca=(*ntp.stdhep);
00439     const Int_t numHeps=hepTca.GetEntriesFast();
00440     MAXMSG("NuAnalysis",Msg::kInfo,1000)
00441       <<"Num stdhep entries="<<numHeps<<endl;
00442 
00443     Int_t charmEvent=-1;
00444 
00445     //loop over stdhep
00446     for (Int_t ihep=0;ihep<numHeps;++ihep) {
00447       const NtpMCStdHep& stdhep=
00448         *dynamic_cast<NtpMCStdHep*>(hepTca[ihep]);
00449       
00450       MAXMSG("NuAnalysis",Msg::kInfo,3000)
00451         <<"ihep="<<ihep
00452         <<", mc="<<stdhep.mc
00453         <<", id="<<stdhep.IdHEP
00454         <<", Ist="<<stdhep.IstHEP
00455         <<", parent=["<<stdhep.parent[0]<<","<<stdhep.parent[1]<<"]"
00456         <<", child=["<<stdhep.child[0]<<","<<stdhep.child[1]<<"]"
00457         <<", m="<<stdhep.mass
00458         <<", E="<<stdhep.p4[3]
00459         <<endl;
00460       
00461       if (abs(stdhep.IdHEP)==411 || abs(stdhep.IdHEP)==421 ||
00462           abs(stdhep.IdHEP)==431 || abs(stdhep.IdHEP)==4122){
00463         charmEvent=stdhep.mc;
00464         MAXMSG("NuAnalysis",Msg::kInfo,3000)
00465           <<"Found Charm event, mc="<<charmEvent
00466           <<", id="<<stdhep.IdHEP<<endl;
00467       }
00468     }
00469 
00470     if (charmEvent!=-1){
00471       MAXMSG("NuAnalysis",Msg::kInfo,3000)
00472         <<"CHARM EVENT, mc="<<charmEvent
00473         <<", entry="<<entry<<endl;
00474       //loop over stdhep
00475       for (Int_t ihep=0;ihep<numHeps;++ihep) {
00476         const NtpMCStdHep& stdhep=
00477           *dynamic_cast<NtpMCStdHep*>(hepTca[ihep]);
00478         
00479         if (stdhep.mc!=charmEvent) continue;
00480         
00481         MAXMSG("NuAnalysis",Msg::kInfo,3000)
00482           <<"CH: i="<<ihep
00483           <<", mc="<<stdhep.mc
00484           <<", id="<<stdhep.IdHEP
00485           <<", Ist="<<stdhep.IstHEP
00486           <<", par=["<<stdhep.parent[0]<<","<<stdhep.parent[1]<<"]"
00487           <<", chi=["<<stdhep.child[0]<<","<<stdhep.child[1]<<"]"
00488           <<", m="<<stdhep.mass
00489           <<", E="<<stdhep.p4[3]
00490           <<endl;
00491       }
00492     }
00493     
00494     //loop over the events
00495     for (Int_t ntpevt=0;ntpevt<numEvts;++ntpevt) {
00496       const NtpSREvent& evt=
00497         *dynamic_cast<NtpSREvent*>(evtTca[ntpevt]);
00498       
00499       //ensure there is only 1 track in the event
00500       if (evt.ntrack!=1) continue;
00501       
00502       const NtpSRTrack& trk=
00503         *dynamic_cast<NtpSRTrack*>(trkTca[evt.trk[0]]);
00504 
00505       //sum up the energy of the showers
00506       Float_t totalShwEn=0;
00507       for (Int_t ishw=0;ishw<evt.nshower;++ishw) {
00508         const NtpSRShower& shw=
00509           *dynamic_cast<NtpSRShower*>(shwTca[evt.shw[ishw]]);
00510         totalShwEn+=shw.ph.gev;
00511       }
00512 
00513       MAXMSG("NuAnalysis",Msg::kInfo,100)
00514         <<"Entry "<<entry<<", event "<<ntpevt
00515         <<" has tracks="<<evt.ntrack
00516         <<", evts="<<numEvts
00517         <<", trks="<<numTrks<<", thtrks="<<numthtrks
00518         <<", shws="<<numShws<<", thshws="<<numthshws
00519         <<endl;
00520         //<<", shws="<<numShws<<", slcs="<<numSlcs<<endl;
00521       
00522       //there is a 1 to 1 correspondance between tracks and thtrks
00523       //so just use trk.index to index into the thtrkTca
00524       const NtpTHTrack& thtrk=
00525         *dynamic_cast<NtpTHTrack*>(thtrkTca[trk.index]);
00526       MAXMSG("NuAnalysis",Msg::kInfo,100)
00527         <<"numInt="<<numInt<<", thtrk.neumc="<<thtrk.neumc<<endl;
00528 
00529       //now get the mc object (neutrino interaction) that 
00530       //corresponds to the trk using the thtrk.neumc index
00531       const NtpMCTruth& mc=
00532         *(dynamic_cast<NtpMCTruth*>(mcTca[thtrk.neumc]));
00533      
00534       string iaction="NC";
00535       if (mc.iaction==1) iaction="CC";
00536       string iresonance="QE ";
00537       if (mc.iresonance==1002) iresonance="RES";
00538       else if (mc.iresonance==1003) iresonance="DIS";
00539       else if (mc.iresonance==1004) iresonance=
00540                                       "Coherent pion production";
00541       string inu="??";
00542       if (mc.inu==14) inu="NuMu   ";
00543       else if (mc.inu==-14) inu="NuMuBar";
00544       else if (mc.inu==12) inu="NuE    ";
00545       else if (mc.inu==-12) inu="NuEBar ";
00546       
00547       Float_t trkCurveP=0;
00548       if (trk.momentum.qp!=0) trkCurveP=1./trk.momentum.qp;
00549 
00550       MAXMSG("NuAnalysis",Msg::kInfo,100)
00551         <<""<<inu
00552         <<" "<<iaction
00553         <<" "<<iresonance
00554         <<", E="<<mc.p4neu[3]<<", mu="<<mc.p4mu1[3]<<" GeV"
00555         <<", Reco: trk="<<trk.momentum.range
00556         <<" (curv="<<trkCurveP<<")"
00557         <<", shw="<<totalShwEn//<<", evt="<<evt.ph.gev
00558         <<endl;
00559       
00560       //cut out the NCs
00561       if (mc.iaction==0) continue; 
00562 
00563       Int_t chargeMC=0;
00564       if (mc.p4mu1[3]<0) chargeMC=-1;
00565       else if (mc.p4mu1[3]>0) chargeMC=+1;
00566       
00567       Int_t charge=0;
00568       if (trk.momentum.qp<0) charge=-1;
00569       else if (trk.momentum.qp>0) charge=+1;
00570 
00571       //fill profiles
00572       if (mc.inu==14) {
00573         pNuMuFitPassVsEn->Fill(mc.p4neu[3],trk.fit.pass);      
00574       }
00575       else if (mc.inu==-14) {
00576         pNuMuBarFitPassVsEn->Fill(mc.p4neu[3],trk.fit.pass);      
00577       }
00578       
00579       if (trk.fit.pass){
00580         if (mc.inu==14) {
00581           pNuMuQEffVsEn->Fill(mc.p4neu[3],charge==chargeMC);
00582         }
00583         else if (mc.inu==-14) {
00584           pNuMuBarQEffVsEn->Fill(mc.p4neu[3],charge==chargeMC);
00585         }
00586       }
00587 
00588       //TruthHelperNtuple
00589       //NtpTHModule NtpTHEvent NtpTHRecord NtpTHShower NtpTHSlice
00590       //NtpTHStrip NtpTHTrack
00591       //trk.momentum.qp
00592       //trk.momentum.eqp
00593       //trk.momentum.range
00594     }
00595   }//end of for                                       
00596   
00600 
00601   MSG("NuAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
00602 
00603   MSG("NuAnalysis",Msg::kInfo) 
00604     <<" ** Finished Efficiencies method **"<<endl;
00605 }
00606 
00607 //......................................................................
00608 
00609 TSpline3* NuAnalysis::CreateTSpline3(std::string splName,
00610                                      std::string varNames,
00611                                      std::string fileName)
00612 {
00613   TNtuple nt(splName.c_str(),splName.c_str(),varNames.c_str());
00614   nt.ReadFile(fileName.c_str(),varNames.c_str());
00615   //nt.ReadFile("xsec.data", "E:xsec");
00616   //nt.Draw("E:xsec","","GOFF");
00617   nt.Print();
00618   //nt.Show(0);
00619   //nt.Show(1);
00620   //nt.Show(2);
00621 
00622   //Note: this line has to be here because it defines V1 and V2
00623   nt.Draw("energy:xsec","","GOFF");//graphics off
00624 
00625   unsigned int n = (int) nt.GetSelectedRows();
00626 #if ROOT_VERSION_CODE < ROOT_VERSION(5,21,5)
00627   int *    idx = new int[n];
00628 #else
00629   unsigned int * idx = new unsigned int[n];
00630 #endif
00631   double * xx  = new double[n];
00632   double * yy  = new double[n];
00633   
00634   TMath::Sort(n,nt.GetV1(),idx,false); // sort in energy
00635 
00636   for(unsigned int i=0; i<n; i++) {
00637     int ii = idx[i];
00638     xx[i]  = (nt.GetV1())[ii];
00639     yy[i]  = (nt.GetV2())[ii];
00640     //MSG("NuAnalysis",Msg::kInfo) 
00641     //<<"E="<<xx[i]<<" GeV, xsec="<<yy[i]<<endl;
00642   }
00643   
00644   TSpline3 * spl=new TSpline3(("spl"+splName).c_str(),xx,yy,n,"0");
00645   
00646   delete [] idx;
00647   delete [] xx;
00648   delete [] yy;
00649 
00650   return spl;
00651 }
00652 
00653 //......................................................................
00654 
00655 void NuAnalysis::CrossSections()
00656 {
00657   MSG("NuAnalysis",Msg::kInfo) 
00658     <<" ** Running CrossSections method... **"<<endl;
00659   
00660   //open the output file for the histograms
00661   fOutFile=this->OpenFile(100,"NuCrossSections");
00662 
00663   cout<<"here"<<endl;
00664   TSpline3* splnumupCC=CreateTSpline3
00665     ("numupCC","energy:xsec",
00666      "/home/hartnell/mytest/NuMuBar/numu-p-CC.txt");
00667   cout<<"here"<<endl;
00668   TSpline3* splnumunCC=CreateTSpline3
00669     ("numunCC","energy:xsec",
00670      "/home/hartnell/mytest/NuMuBar/numu-n-CC.txt");
00671   cout<<"here"<<endl;
00672   TSpline3* splnumubarpCC=CreateTSpline3
00673     ("numubarpCC","energy:xsec",
00674      "/home/hartnell/mytest/NuMuBar/numubar-p-CC.txt");
00675   cout<<"here"<<endl;
00676   TSpline3* splnumubarnCC=CreateTSpline3
00677     ("numubarnCC","energy:xsec",
00678      "/home/hartnell/mytest/NuMuBar/numubar-n-CC.txt");
00679   cout<<"hereend"<<endl;
00680  
00681   TH1F* hXsecNuMuPCC=new TH1F("hXsecNuMuPCC","hXsecNuMuPCC",
00682                               1000,0,100);
00683   hXsecNuMuPCC->SetTitle("NuMu Cross Section on Protons");
00684   hXsecNuMuPCC->GetXaxis()->SetTitle("Energy (GeV)");
00685   hXsecNuMuPCC->GetXaxis()->CenterTitle();
00686   hXsecNuMuPCC->GetYaxis()->SetTitle("#sigma (cm^{2})");
00687   hXsecNuMuPCC->GetYaxis()->CenterTitle();
00688 
00689   TH1F* hXsecNuMuNCC=new TH1F("hXsecNuMuNCC","hXsecNuMuNCC",
00690                               1000,0,100);
00691   hXsecNuMuNCC->SetTitle("NuMu Cross Section on Neutrons");
00692   hXsecNuMuNCC->GetXaxis()->SetTitle("Energy (GeV)");
00693   hXsecNuMuNCC->GetXaxis()->CenterTitle();
00694   hXsecNuMuNCC->GetYaxis()->SetTitle("#sigma (cm^{2})");
00695   hXsecNuMuNCC->GetYaxis()->CenterTitle();
00696 
00697   TH1F* hXsecNuMuBarPCC=new TH1F("hXsecNuMuBarPCC","hXsecNuMuBarPCC",
00698                                  1000,0,100);
00699   hXsecNuMuBarPCC->SetTitle("NuMuBar Cross Section on Protons");
00700   hXsecNuMuBarPCC->GetXaxis()->SetTitle("Energy (GeV)");
00701   hXsecNuMuBarPCC->GetXaxis()->CenterTitle();
00702   hXsecNuMuBarPCC->GetYaxis()->SetTitle("#sigma (cm{^2})");
00703   hXsecNuMuBarPCC->GetYaxis()->CenterTitle();
00704   
00705   TH1F* hXsecNuMuBarNCC=new TH1F("hXsecNuMuBarNCC","hXsecNuMuBarNCC",
00706                                  1000,0,100);
00707   hXsecNuMuBarNCC->SetTitle("NuMuBar Cross Section on Neutrons");
00708   hXsecNuMuBarNCC->GetXaxis()->SetTitle("Energy (GeV)");
00709   hXsecNuMuBarNCC->GetXaxis()->CenterTitle();
00710   hXsecNuMuBarNCC->GetYaxis()->SetTitle("#sigma (cm^{2})");
00711   hXsecNuMuBarNCC->GetYaxis()->CenterTitle();
00712 
00713 
00714   TH1F* hXsecNuMuFeCC=new TH1F("hXsecNuMuFeCC","hXsecNuMuFeCC",
00715                               1000,0,100);
00716   hXsecNuMuFeCC->SetTitle("NuMu Cross Section on Fe");
00717   hXsecNuMuFeCC->GetXaxis()->SetTitle("Energy (GeV)");
00718   hXsecNuMuFeCC->GetXaxis()->CenterTitle();
00719   hXsecNuMuFeCC->GetYaxis()->SetTitle("#sigma (cm^{2})");
00720   hXsecNuMuFeCC->GetYaxis()->CenterTitle();
00721 
00722   TH1F* hXsecNuMuBarFeCC=new TH1F("hXsecNuMuBarFeCC","hXsecNuMuBarFeCC",
00723                                  1000,0,100);
00724   hXsecNuMuBarFeCC->SetTitle("NuMuBar Cross Section on Fe");
00725   hXsecNuMuBarFeCC->GetXaxis()->SetTitle("Energy (GeV)");
00726   hXsecNuMuBarFeCC->GetXaxis()->CenterTitle();
00727   hXsecNuMuBarFeCC->GetYaxis()->SetTitle("#sigma (cm^{2})");
00728   hXsecNuMuBarFeCC->GetYaxis()->CenterTitle();
00729   
00730 
00731   for (Float_t i=0.05;i<100;i+=0.1){
00732     MAXMSG("NuAnalysis",Msg::kInfo,20) 
00733       <<"E="<<i<<" GeV"<<endl
00734       <<"  numu    p CC xsec="<<splnumupCC->Eval(i)<<"e-38 cm^2"
00735       <<", numu    n CC xsec="<<splnumunCC->Eval(i)<<"e-38 cm^2"<<endl
00736       <<"  numubar p CC xsec="<<splnumubarpCC->Eval(i)<<"e-38 cm^2"
00737       <<", numubar n CC xsec="<<splnumubarnCC->Eval(i)<<"e-38 cm^2"
00738       <<endl;
00739 
00740     Float_t xsecNuMuPCC=splnumupCC->Eval(i)<0 ? 0:splnumupCC->Eval(i);
00741     Float_t xsecNuMuNCC=splnumunCC->Eval(i)<0 ? 0:splnumunCC->Eval(i);
00742     Float_t xsecNuMuBarPCC=
00743       splnumubarpCC->Eval(i)<0 ? 0:splnumubarpCC->Eval(i);
00744     Float_t xsecNuMuBarNCC=
00745       splnumubarnCC->Eval(i)<0 ? 0:splnumubarnCC->Eval(i);
00746 
00747     hXsecNuMuPCC->Fill(i,xsecNuMuPCC);
00748     hXsecNuMuNCC->Fill(i,xsecNuMuNCC);
00749     hXsecNuMuBarPCC->Fill(i,xsecNuMuBarPCC);
00750     hXsecNuMuBarNCC->Fill(i,xsecNuMuBarNCC);
00751     
00752     Float_t FeA=55.845;
00753     Float_t FeZ=26;
00754     Float_t FeP=FeZ;
00755     Float_t FeN=FeA-FeZ;
00756 
00757     Float_t xsecNuMuBarFeCC=xsecNuMuBarPCC*FeP+xsecNuMuBarNCC*FeN;
00758     Float_t xsecNuMuFeCC=xsecNuMuPCC*FeP+xsecNuMuNCC*FeN;
00759     hXsecNuMuFeCC->Fill(i,xsecNuMuFeCC);
00760     hXsecNuMuBarFeCC->Fill(i,xsecNuMuBarFeCC);
00761     
00762     
00763   }
00764 
00765   MSG("NuAnalysis",Msg::kInfo) 
00766     <<" ** Finished CrossSections method **"<<endl;
00767 }
00768 
00769 //......................................................................
00770 
00771 void NuAnalysis::EnergySpectMC()
00772 {
00773   MSG("NuAnalysis",Msg::kInfo) 
00774     <<" ** Running EnergySpectMC method... **"<<endl;
00775   
00776   //open the output file for the histograms
00777   fOutFile=this->OpenFile(100,"NuEnergySpectMC");
00778 
00779   TH1F* hNuInt=new TH1F("hNuInt","hNuInt",10000,-100,1000);
00780   hNuInt->SetTitle("Number of neutrino interactions per spill");
00781   hNuInt->GetXaxis()->SetTitle("# interactions");
00782   hNuInt->GetXaxis()->CenterTitle();
00783   hNuInt->GetYaxis()->SetTitle("");
00784   hNuInt->GetYaxis()->CenterTitle();
00785   hNuInt->SetFillColor(0);
00786   hNuInt->SetLineColor(1);
00787   //hNuInt->SetBit(TH1::kCanRebin);
00788   
00789   TH1F* hinuCC=new TH1F("hinuCC","hinuCC",80,-20,20);
00790   hinuCC->SetTitle("MC Number of Neutrino");
00791   hinuCC->GetXaxis()->SetTitle("MC Number");
00792   hinuCC->GetXaxis()->CenterTitle();
00793   hinuCC->GetYaxis()->SetTitle("");
00794   hinuCC->GetYaxis()->CenterTitle();
00795   hinuCC->SetFillColor(0);
00796   hinuCC->SetLineColor(1);
00797   //hinuCC->SetBit(TH1::kCanRebin);
00798 
00799   TH1F* hinuNC=new TH1F("hinuNC","hinuNC",80,-20,20);
00800   hinuNC->SetTitle("MC Number of Neutrino");
00801   hinuNC->GetXaxis()->SetTitle("MC Number");
00802   hinuNC->GetXaxis()->CenterTitle();
00803   hinuNC->GetYaxis()->SetTitle("");
00804   hinuNC->GetYaxis()->CenterTitle();
00805   hinuNC->SetFillColor(0);
00806   hinuNC->SetLineColor(3);
00807   hinuNC->SetLineWidth(2);
00808   //hinuNC->SetBit(TH1::kCanRebin);
00809 
00810 
00811   TH1F* hNuMuBarEnCC=new TH1F("hNuMuBarEnCC","hNuMuBarEnCC",
00812                               4*352,-32,320);
00813   hNuMuBarEnCC->GetXaxis()->SetTitle("Energy (GeV)");
00814   hNuMuBarEnCC->GetXaxis()->CenterTitle();
00815   hNuMuBarEnCC->GetYaxis()->SetTitle("");
00816   hNuMuBarEnCC->GetYaxis()->CenterTitle();
00817   hNuMuBarEnCC->SetFillColor(0);
00818   hNuMuBarEnCC->SetLineColor(2);
00819   //hNuMuBarEnCC->SetBit(TH1::kCanRebin);
00820 
00821   TH1F* hNuMuBarFidEnCC=new TH1F("hNuMuBarFidEnCC","hNuMuBarFidEnCC",
00822                               4*352,-32,320);
00823   hNuMuBarFidEnCC->GetXaxis()->SetTitle("Energy (GeV)");
00824   hNuMuBarFidEnCC->GetXaxis()->CenterTitle();
00825   hNuMuBarFidEnCC->GetYaxis()->SetTitle("");
00826   hNuMuBarFidEnCC->GetYaxis()->CenterTitle();
00827   hNuMuBarFidEnCC->SetFillColor(0);
00828   hNuMuBarFidEnCC->SetLineColor(2);
00829   //hNuMuBarFidEnCC->SetBit(TH1::kCanRebin);
00830 
00831   TH1F* hNuMuBarLike=new TH1F("hNuMuBarLike","hNuMuBarLike",
00832                               4*352,-32,320);
00833   hNuMuBarLike->GetXaxis()->SetTitle("Energy (GeV)");
00834   hNuMuBarLike->GetXaxis()->CenterTitle();
00835   hNuMuBarLike->GetYaxis()->SetTitle("");
00836   hNuMuBarLike->GetYaxis()->CenterTitle();
00837   hNuMuBarLike->SetFillColor(0);
00838   hNuMuBarLike->SetLineColor(2);
00839   //hNuMuBarLike->SetBit(TH1::kCanRebin);
00840 
00841   TH1F* hNuMuEnCC=new TH1F("hNuMuEnCC","hNuMuEnCC",4*352,-32,320);
00842   hNuMuEnCC->GetXaxis()->SetTitle("Energy (GeV)");
00843   hNuMuEnCC->GetXaxis()->CenterTitle();
00844   hNuMuEnCC->GetYaxis()->SetTitle("");
00845   hNuMuEnCC->GetYaxis()->CenterTitle();
00846   hNuMuEnCC->SetFillColor(0);
00847   hNuMuEnCC->SetLineColor(1);
00848   hNuMuEnCC->SetLineWidth(2);
00849   //hNuMuEnCC->SetBit(TH1::kCanRebin);
00850 
00851   TH1F* hNuMuFidEnCC=new TH1F("hNuMuFidEnCC","hNuMuFidEnCC",
00852                               4*352,-32,320);
00853   hNuMuFidEnCC->GetXaxis()->SetTitle("Energy (GeV)");
00854   hNuMuFidEnCC->GetXaxis()->CenterTitle();
00855   hNuMuFidEnCC->GetYaxis()->SetTitle("");
00856   hNuMuFidEnCC->GetYaxis()->CenterTitle();
00857   hNuMuFidEnCC->SetFillColor(0);
00858   hNuMuFidEnCC->SetLineColor(1);
00859   hNuMuFidEnCC->SetLineWidth(2);
00860   //hNuMuFidEnCC->SetBit(TH1::kCanRebin);
00861 
00862   TH1F* hNuMuLike=new TH1F("hNuMuLike","hNuMuLike",4*352,-32,320);
00863   hNuMuLike->GetXaxis()->SetTitle("Energy (GeV)");
00864   hNuMuLike->GetXaxis()->CenterTitle();
00865   hNuMuLike->GetYaxis()->SetTitle("");
00866   hNuMuLike->GetYaxis()->CenterTitle();
00867   hNuMuLike->SetFillColor(0);
00868   hNuMuLike->SetLineColor(1);
00869   hNuMuLike->SetLineWidth(2);
00870   //hNuMuLike->SetBit(TH1::kCanRebin);
00871 
00872   TH1F* hNuMuBarEn4000CC=new TH1F("hNuMuBarEn4000CC","hNuMuBarEn4000CC",
00873                                   4000,-10,200);
00874   hNuMuBarEn4000CC->GetXaxis()->SetTitle("Energy (GeV)");
00875   hNuMuBarEn4000CC->GetXaxis()->CenterTitle();
00876   hNuMuBarEn4000CC->GetYaxis()->SetTitle("");
00877   hNuMuBarEn4000CC->GetYaxis()->CenterTitle();
00878   hNuMuBarEn4000CC->SetFillColor(0);
00879   hNuMuBarEn4000CC->SetLineColor(2);
00880   //hNuMuBarEn4000CC->SetBit(TH1::kCanRebin);
00881 
00882   TH1F* hNuMuEn4000CC=new TH1F("hNuMuEn4000CC","hNuMuEn4000CC",
00883                                4000,-10,200);
00884   hNuMuEn4000CC->GetXaxis()->SetTitle("Energy (GeV)");
00885   hNuMuEn4000CC->GetXaxis()->CenterTitle();
00886   hNuMuEn4000CC->GetYaxis()->SetTitle("");
00887   hNuMuEn4000CC->GetYaxis()->CenterTitle();
00888   hNuMuEn4000CC->SetFillColor(0);
00889   hNuMuEn4000CC->SetLineColor(1);
00890   hNuMuEn4000CC->SetLineWidth(2);
00891   //hNuMuEn4000CC->SetBit(TH1::kCanRebin);
00892 
00893   TH1F* hNueBarEnCC=new TH1F("hNueBarEnCC","hNueBarEnCC",4*352,-32,320);
00894   hNueBarEnCC->GetXaxis()->SetTitle("Energy (GeV)");
00895   hNueBarEnCC->GetXaxis()->CenterTitle();
00896   hNueBarEnCC->GetYaxis()->SetTitle("");
00897   hNueBarEnCC->GetYaxis()->CenterTitle();
00898   hNueBarEnCC->SetFillColor(0);
00899   hNueBarEnCC->SetLineColor(2);
00900   hNueBarEnCC->SetLineWidth(2);
00901   hNueBarEnCC->SetLineStyle(2);
00902   //hNueBarEnCC->SetBit(TH1::kCanRebin);
00903 
00904   TH1F* hNueEnCC=new TH1F("hNueEnCC","hNueEnCC",4*352,-32,320);
00905   hNueEnCC->GetXaxis()->SetTitle("Energy (GeV)");
00906   hNueEnCC->GetXaxis()->CenterTitle();
00907   hNueEnCC->GetYaxis()->SetTitle("");
00908   hNueEnCC->GetYaxis()->CenterTitle();
00909   hNueEnCC->SetFillColor(0);
00910   hNueEnCC->SetLineColor(1);
00911   hNueEnCC->SetLineWidth(1);
00912   hNueEnCC->SetLineStyle(2);
00913   //hNueEnCC->SetBit(TH1::kCanRebin);
00914 
00915 
00916   TH1F* hNuMuBarEnNC=new TH1F("hNuMuBarEnNC","hNuMuBarEnNC",4*352,-32,320);
00917   hNuMuBarEnNC->GetXaxis()->SetTitle("Energy (GeV)");
00918   hNuMuBarEnNC->GetXaxis()->CenterTitle();
00919   hNuMuBarEnNC->GetYaxis()->SetTitle("");
00920   hNuMuBarEnNC->GetYaxis()->CenterTitle();
00921   hNuMuBarEnNC->SetFillColor(0);
00922   hNuMuBarEnNC->SetLineColor(4);
00923   //hNuMuBarEnNC->SetBit(TH1::kCanRebin);
00924 
00925   TH1F* hNuMuEnNC=new TH1F("hNuMuEnNC","hNuMuEnNC",4*352,-32,320);
00926   hNuMuEnNC->GetXaxis()->SetTitle("Energy (GeV)");
00927   hNuMuEnNC->GetXaxis()->CenterTitle();
00928   hNuMuEnNC->GetYaxis()->SetTitle("");
00929   hNuMuEnNC->GetYaxis()->CenterTitle();
00930   hNuMuEnNC->SetFillColor(0);
00931   hNuMuEnNC->SetLineColor(1);
00932   hNuMuEnNC->SetLineWidth(3);
00933   //hNuMuEnNC->SetBit(TH1::kCanRebin);
00934 
00935   TH1F* hNueBarEnNC=new TH1F("hNueBarEnNC","hNueBarEnNC",4*352,-32,320);
00936   hNueBarEnNC->GetXaxis()->SetTitle("Energy (GeV)");
00937   hNueBarEnNC->GetXaxis()->CenterTitle();
00938   hNueBarEnNC->GetYaxis()->SetTitle("");
00939   hNueBarEnNC->GetYaxis()->CenterTitle();
00940   hNueBarEnNC->SetFillColor(0);
00941   hNueBarEnNC->SetLineColor(4);
00942   hNueBarEnNC->SetLineWidth(2);
00943   hNueBarEnNC->SetLineStyle(2);
00944   //hNueBarEnNC->SetBit(TH1::kCanRebin);
00945 
00946   TH1F* hNueEnNC=new TH1F("hNueEnNC","hNueEnNC",4*352,-32,320);
00947   hNueEnNC->GetXaxis()->SetTitle("Energy (GeV)");
00948   hNueEnNC->GetXaxis()->CenterTitle();
00949   hNueEnNC->GetYaxis()->SetTitle("");
00950   hNueEnNC->GetYaxis()->CenterTitle();
00951   hNueEnNC->SetFillColor(0);
00952   hNueEnNC->SetLineColor(3);
00953   hNueEnNC->SetLineWidth(1);
00954   hNueEnNC->SetLineStyle(2);
00955   //hNueEnNC->SetBit(TH1::kCanRebin);
00956 
00957 
00958   TH1F* hNuMuBarEnDepNC=new TH1F("hNuMuBarEnDepNC","hNuMuBarEnDepNC",4*352,-32,320);
00959   hNuMuBarEnDepNC->GetXaxis()->SetTitle("Energy (GeV)");
00960   hNuMuBarEnDepNC->GetXaxis()->CenterTitle();
00961   hNuMuBarEnDepNC->GetYaxis()->SetTitle("");
00962   hNuMuBarEnDepNC->GetYaxis()->CenterTitle();
00963   hNuMuBarEnDepNC->SetFillColor(0);
00964   hNuMuBarEnDepNC->SetLineColor(4);
00965   //hNuMuBarEnDepNC->SetBit(TH1::kCanRebin);
00966 
00967   TH1F* hNuMuEnDepNC=new TH1F("hNuMuEnDepNC","hNuMuEnDepNC",4*352,-32,320);
00968   hNuMuEnDepNC->GetXaxis()->SetTitle("Energy (GeV)");
00969   hNuMuEnDepNC->GetXaxis()->CenterTitle();
00970   hNuMuEnDepNC->GetYaxis()->SetTitle("");
00971   hNuMuEnDepNC->GetYaxis()->CenterTitle();
00972   hNuMuEnDepNC->SetFillColor(0);
00973   hNuMuEnDepNC->SetLineColor(1);
00974   hNuMuEnDepNC->SetLineWidth(3);
00975   //hNuMuEnDepNC->SetBit(TH1::kCanRebin);
00976 
00977   TH1F* hNueBarEnDepNC=new TH1F("hNueBarEnDepNC","hNueBarEnDepNC",4*352,-32,320);
00978   hNueBarEnDepNC->GetXaxis()->SetTitle("Energy (GeV)");
00979   hNueBarEnDepNC->GetXaxis()->CenterTitle();
00980   hNueBarEnDepNC->GetYaxis()->SetTitle("");
00981   hNueBarEnDepNC->GetYaxis()->CenterTitle();
00982   hNueBarEnDepNC->SetFillColor(0);
00983   hNueBarEnDepNC->SetLineColor(4);
00984   hNueBarEnDepNC->SetLineWidth(2);
00985   hNueBarEnDepNC->SetLineStyle(2);
00986   //hNueBarEnDepNC->SetBit(TH1::kCanRebin);
00987 
00988   TH1F* hNueEnDepNC=new TH1F("hNueEnDepNC","hNueEnDepNC",4*352,-32,320);
00989   hNueEnDepNC->GetXaxis()->SetTitle("Energy (GeV)");
00990   hNueEnDepNC->GetXaxis()->CenterTitle();
00991   hNueEnDepNC->GetYaxis()->SetTitle("");
00992   hNueEnDepNC->GetYaxis()->CenterTitle();
00993   hNueEnDepNC->SetFillColor(0);
00994   hNueEnDepNC->SetLineColor(3);
00995   hNueEnDepNC->SetLineWidth(1);
00996   hNueEnDepNC->SetLineStyle(2);
00997   //hNueEnDepNC->SetBit(TH1::kCanRebin);
00998 
00999 
01000   TH1F* hNuYCC=new TH1F("hNuYCC","hNuYCC",100,-0.1,1.1);
01001   hNuYCC->GetXaxis()->SetTitle("Neutrino y");
01002   hNuYCC->GetXaxis()->CenterTitle();
01003   hNuYCC->GetYaxis()->SetTitle("");
01004   hNuYCC->GetYaxis()->CenterTitle();
01005   hNuYCC->SetFillColor(0);
01006   hNuYCC->SetLineColor(1);
01007   hNuYCC->SetLineWidth(1);
01008   hNuYCC->SetLineStyle(1);
01009   //hNuYCC->SetBit(TH1::kCanRebin);
01010 
01011   TH1F* hNuYNC=new TH1F("hNuYNC","hNuYNC",100,-0.1,1.1);
01012   hNuYNC->GetXaxis()->SetTitle("Neutrino y");
01013   hNuYNC->GetXaxis()->CenterTitle();
01014   hNuYNC->GetYaxis()->SetTitle("");
01015   hNuYNC->GetYaxis()->CenterTitle();
01016   hNuYNC->SetFillColor(0);
01017   hNuYNC->SetLineColor(3);
01018   hNuYNC->SetLineWidth(2);
01019   hNuYNC->SetLineStyle(1);
01020   //hNuYNC->SetBit(TH1::kCanRebin);
01021 
01022   TH1F* hNuYFidNuMuBarCC=new TH1F("hNuYFidNuMuBarCC","hNuYFidNuMuBarCC",
01023                                   100,-0.1,1.1);
01024   hNuYFidNuMuBarCC->GetXaxis()->SetTitle("Neutrino y");
01025   hNuYFidNuMuBarCC->GetXaxis()->CenterTitle();
01026   hNuYFidNuMuBarCC->GetYaxis()->SetTitle("");
01027   hNuYFidNuMuBarCC->GetYaxis()->CenterTitle();
01028   hNuYFidNuMuBarCC->SetFillColor(0);
01029   hNuYFidNuMuBarCC->SetLineColor(1);
01030   hNuYFidNuMuBarCC->SetLineWidth(1);
01031   hNuYFidNuMuBarCC->SetLineStyle(1);
01032   //hNuYFidNuMuBarCC->SetBit(TH1::kCanRebin);
01033 
01034   TH1F* hNuYFidNuMuBarNC=new TH1F("hNuYFidNuMuBarNC","hNuYFidNuMuBarNC",
01035                                   100,-0.1,1.1);
01036   hNuYFidNuMuBarNC->GetXaxis()->SetTitle("Neutrino y");
01037   hNuYFidNuMuBarNC->GetXaxis()->CenterTitle();
01038   hNuYFidNuMuBarNC->GetYaxis()->SetTitle("");
01039   hNuYFidNuMuBarNC->GetYaxis()->CenterTitle();
01040   hNuYFidNuMuBarNC->SetFillColor(0);
01041   hNuYFidNuMuBarNC->SetLineColor(3);
01042   hNuYFidNuMuBarNC->SetLineWidth(2);
01043   hNuYFidNuMuBarNC->SetLineStyle(1);
01044   //hNuYFidNuMuBarNC->SetBit(TH1::kCanRebin);
01045 
01046   TH1F* hNuYFidNuMuCC=new TH1F("hNuYFidNuMuCC","hNuYFidNuMuCC",
01047                                100,-0.1,1.1);
01048   hNuYFidNuMuCC->GetXaxis()->SetTitle("Neutrino y");
01049   hNuYFidNuMuCC->GetXaxis()->CenterTitle();
01050   hNuYFidNuMuCC->GetYaxis()->SetTitle("");
01051   hNuYFidNuMuCC->GetYaxis()->CenterTitle();
01052   hNuYFidNuMuCC->SetFillColor(0);
01053   hNuYFidNuMuCC->SetLineColor(1);
01054   hNuYFidNuMuCC->SetLineWidth(1);
01055   hNuYFidNuMuCC->SetLineStyle(1);
01056   //hNuYFidNuMuCC->SetBit(TH1::kCanRebin);
01057 
01058   TH1F* hNuYFidNuMuNC=new TH1F("hNuYFidNuMuNC","hNuYFidNuMuNC",
01059                                100,-0.1,1.1);
01060   hNuYFidNuMuNC->GetXaxis()->SetTitle("Neutrino y");
01061   hNuYFidNuMuNC->GetXaxis()->CenterTitle();
01062   hNuYFidNuMuNC->GetYaxis()->SetTitle("");
01063   hNuYFidNuMuNC->GetYaxis()->CenterTitle();
01064   hNuYFidNuMuNC->SetFillColor(0);
01065   hNuYFidNuMuNC->SetLineColor(3);
01066   hNuYFidNuMuNC->SetLineWidth(2);
01067   hNuYFidNuMuNC->SetLineStyle(1);
01068   //hNuYFidNuMuNC->SetBit(TH1::kCanRebin);
01069 
01070 
01071   Int_t nbinsForY=60;
01072   vector<TH1F*> vNuYNuMuBarCC(nbinsForY);
01073   vector<TH1F*> vNuYNuMuCC(nbinsForY);
01074   vector<TH1F*> vNuYNuMuBarNC(nbinsForY);
01075   vector<TH1F*> vNuYNuMuNC(nbinsForY);
01076   for (Int_t i=0;i<nbinsForY;i++){
01077     Int_t en=(i+1)*5;
01078     string sEn=Form("%d",en);
01079     string s="hNuYNuMuBarCC"+sEn;
01080     //cout<<"Creating "<<s<<endl;
01081     vNuYNuMuBarCC[i]=new TH1F(s.c_str(),s.c_str(),100,-0.1,1.1);
01082     vNuYNuMuBarCC[i]->GetXaxis()->SetTitle("Neutrino y");
01083     vNuYNuMuBarCC[i]->GetXaxis()->CenterTitle();
01084     vNuYNuMuBarCC[i]->GetYaxis()->SetTitle("");
01085     vNuYNuMuBarCC[i]->GetYaxis()->CenterTitle();
01086     vNuYNuMuBarCC[i]->SetFillColor(0);
01087     vNuYNuMuBarCC[i]->SetLineColor(2);
01088     vNuYNuMuBarCC[i]->SetLineWidth(2);
01089     vNuYNuMuBarCC[i]->SetLineStyle(2);
01090     //vNuYNuMuBarCC[i]->SetBit(TH1::kCanRebin);
01091     
01092     s="hNuYNuMuCC"+sEn;
01093     //cout<<"Creating "<<s<<endl;
01094     vNuYNuMuCC[i]=new TH1F(s.c_str(),s.c_str(),100,-0.1,1.1);
01095     vNuYNuMuCC[i]->GetXaxis()->SetTitle("Neutrino y");
01096     vNuYNuMuCC[i]->GetXaxis()->CenterTitle();
01097     vNuYNuMuCC[i]->GetYaxis()->SetTitle("");
01098     vNuYNuMuCC[i]->GetYaxis()->CenterTitle();
01099     vNuYNuMuCC[i]->SetFillColor(0);
01100     vNuYNuMuCC[i]->SetLineColor(1);
01101     vNuYNuMuCC[i]->SetLineWidth(2);
01102     vNuYNuMuCC[i]->SetLineStyle(1);
01103     //vNuYNuMuCC[i]->SetBit(TH1::kCanRebin);
01104 
01105     s="hNuYNuMuBarNC"+sEn;
01106     //cout<<"Creating "<<s<<endl;
01107     vNuYNuMuBarNC[i]=new TH1F(s.c_str(),s.c_str(),100,-0.1,1.1);
01108     vNuYNuMuBarNC[i]->GetXaxis()->SetTitle("Neutrino y");
01109     vNuYNuMuBarNC[i]->GetXaxis()->CenterTitle();
01110     vNuYNuMuBarNC[i]->GetYaxis()->SetTitle("");
01111     vNuYNuMuBarNC[i]->GetYaxis()->CenterTitle();
01112     vNuYNuMuBarNC[i]->SetFillColor(0);
01113     vNuYNuMuBarNC[i]->SetLineColor(2);
01114     vNuYNuMuBarNC[i]->SetLineWidth(2);
01115     vNuYNuMuBarNC[i]->SetLineStyle(2);
01116     //vNuYNuMuBarNC[i]->SetBit(TH1::kCanRebin);
01117     
01118     s="hNuYNuMuNC"+sEn;
01119     //cout<<"Creating "<<s<<endl;
01120     vNuYNuMuNC[i]=new TH1F(s.c_str(),s.c_str(),100,-0.1,1.1);
01121     vNuYNuMuNC[i]->GetXaxis()->SetTitle("Neutrino y");
01122     vNuYNuMuNC[i]->GetXaxis()->CenterTitle();
01123     vNuYNuMuNC[i]->GetYaxis()->SetTitle("");
01124     vNuYNuMuNC[i]->GetYaxis()->CenterTitle();
01125     vNuYNuMuNC[i]->SetFillColor(0);
01126     vNuYNuMuNC[i]->SetLineColor(1);
01127     vNuYNuMuNC[i]->SetLineWidth(2);
01128     vNuYNuMuNC[i]->SetLineStyle(1);
01129     //vNuYNuMuNC[i]->SetBit(TH1::kCanRebin);
01130   }
01131 
01132   TH1F* hZCC=new TH1F("hZCC","hZCC",1000,-10,100);
01133   hZCC->GetXaxis()->SetTitle("Z (m)");
01134   hZCC->GetXaxis()->CenterTitle();
01135   hZCC->GetYaxis()->SetTitle("");
01136   hZCC->GetYaxis()->CenterTitle();
01137   hZCC->SetFillColor(0);
01138   hZCC->SetLineColor(1);
01139   hZCC->SetLineWidth(1);
01140   hZCC->SetLineStyle(1);
01141   //hZCC->SetBit(TH1::kCanRebin);
01142 
01143   TH1F* hZNC=new TH1F("hZNC","hZNC",1000,-10,100);
01144   hZNC->GetXaxis()->SetTitle("Z (m)");
01145   hZNC->GetXaxis()->CenterTitle();
01146   hZNC->GetYaxis()->SetTitle("");
01147   hZNC->GetYaxis()->CenterTitle();
01148   hZNC->SetFillColor(0);
01149   hZNC->SetLineColor(3);
01150   hZNC->SetLineWidth(2);
01151   hZNC->SetLineStyle(2);
01152   //hZNC->SetBit(TH1::kCanRebin);
01153 
01154   TH2F* hYvsXCC=new TH2F("hYvsXCC","hYvsXCC",
01155                        100,-5,5,100,-5,5);
01156   hYvsXCC->SetTitle("Y vs X");
01157   hYvsXCC->GetXaxis()->SetTitle("X");
01158   hYvsXCC->GetXaxis()->CenterTitle();
01159   hYvsXCC->GetYaxis()->SetTitle("Y");
01160   hYvsXCC->GetYaxis()->CenterTitle();
01161   hYvsXCC->SetFillColor(0);
01162   //hYvsXCC->SetBit(TH1::kCanRebin);
01163 
01164   TH2F* hYvsXNC=new TH2F("hYvsXNC","hYvsXNC",
01165                        100,-5,5,100,-5,5);
01166   hYvsXNC->SetTitle("Y vs X");
01167   hYvsXNC->GetXaxis()->SetTitle("X");
01168   hYvsXNC->GetXaxis()->CenterTitle();
01169   hYvsXNC->GetYaxis()->SetTitle("Y");
01170   hYvsXNC->GetYaxis()->CenterTitle();
01171   hYvsXNC->SetFillColor(0);
01172   //hYvsXNC->SetBit(TH1::kCanRebin);
01173 
01174   TH2F* hYvsXFidCC=new TH2F("hYvsXFidCC","hYvsXFidCC",
01175                        100,-5,5,100,-5,5);
01176   hYvsXFidCC->SetTitle("Y vs X");
01177   hYvsXFidCC->GetXaxis()->SetTitle("X");
01178   hYvsXFidCC->GetXaxis()->CenterTitle();
01179   hYvsXFidCC->GetYaxis()->SetTitle("Y");
01180   hYvsXFidCC->GetYaxis()->CenterTitle();
01181   hYvsXFidCC->SetFillColor(0);
01182   //hYvsXFidCC->SetBit(TH1::kCanRebin);
01183 
01184   TH2F* hYvsXFidNC=new TH2F("hYvsXFidNC","hYvsXFidNC",
01185                        100,-5,5,100,-5,5);
01186   hYvsXFidNC->SetTitle("Y vs X");
01187   hYvsXFidNC->GetXaxis()->SetTitle("X");
01188   hYvsXFidNC->GetXaxis()->CenterTitle();
01189   hYvsXFidNC->GetYaxis()->SetTitle("Y");
01190   hYvsXFidNC->GetYaxis()->CenterTitle();
01191   hYvsXFidNC->SetFillColor(0);
01192   //hYvsXFidNC->SetBit(TH1::kCanRebin);
01193 
01194   TH2F* hYvsX400CC=new TH2F("hYvsX400CC","hYvsX400CC",
01195                          400,-20,20,400,-20,20);
01196   hYvsX400CC->SetTitle("Y vs X");
01197   hYvsX400CC->GetXaxis()->SetTitle("X");
01198   hYvsX400CC->GetXaxis()->CenterTitle();
01199   hYvsX400CC->GetYaxis()->SetTitle("Y");
01200   hYvsX400CC->GetYaxis()->CenterTitle();
01201   hYvsX400CC->SetFillColor(0);
01202   //hYvsX400CC->SetBit(TH1::kCanRebin);
01203 
01204   TH2F* hYvsX400NC=new TH2F("hYvsX400NC","hYvsX400NC",
01205                          400,-20,20,400,-20,20);
01206   hYvsX400NC->SetTitle("Y vs X");
01207   hYvsX400NC->GetXaxis()->SetTitle("X");
01208   hYvsX400NC->GetXaxis()->CenterTitle();
01209   hYvsX400NC->GetYaxis()->SetTitle("Y");
01210   hYvsX400NC->GetYaxis()->CenterTitle();
01211   hYvsX400NC->SetFillColor(0);
01212   //hYvsX400NC->SetBit(TH1::kCanRebin);
01213 
01214 
01215   TH2F* hYvsZCC=new TH2F("hYvsZCC","hYvsZCC",
01216                             1000,-200,50,400,-20,20);
01217   hYvsZCC->SetTitle("Y vs Z");
01218   hYvsZCC->GetXaxis()->SetTitle("Z");
01219   hYvsZCC->GetXaxis()->CenterTitle();
01220   hYvsZCC->GetYaxis()->SetTitle("Y");
01221   hYvsZCC->GetYaxis()->CenterTitle();
01222   hYvsZCC->SetFillColor(0);
01223   //hYvsZCC->SetBit(TH1::kCanRebin);
01224 
01225   TH2F* hYvsZNC=new TH2F("hYvsZNC","hYvsZNC",
01226                             1000,-200,50,400,-20,20);
01227   hYvsZNC->SetTitle("Y vs Z");
01228   hYvsZNC->GetXaxis()->SetTitle("Z");
01229   hYvsZNC->GetXaxis()->CenterTitle();
01230   hYvsZNC->GetYaxis()->SetTitle("Y");
01231   hYvsZNC->GetYaxis()->CenterTitle();
01232   hYvsZNC->SetFillColor(0);
01233   //hYvsZNC->SetBit(TH1::kCanRebin);
01234 
01235 
01236   TH2F* hXvsZCC=new TH2F("hXvsZCC","hXvsZCC",
01237                             1000,-200,50,400,-20,20);
01238   hXvsZCC->SetTitle("X vs Z");
01239   hXvsZCC->GetXaxis()->SetTitle("Z");
01240   hXvsZCC->GetXaxis()->CenterTitle();
01241   hXvsZCC->GetYaxis()->SetTitle("X");
01242   hXvsZCC->GetYaxis()->CenterTitle();
01243   hXvsZCC->SetFillColor(0);
01244   //hXvsZCC->SetBit(TH1::kCanRebin);
01245 
01246   TH2F* hXvsZNC=new TH2F("hXvsZNC","hXvsZNC",
01247                             1000,-200,50,400,-20,20);
01248   hXvsZNC->SetTitle("X vs Z");
01249   hXvsZNC->GetXaxis()->SetTitle("Z");
01250   hXvsZNC->GetXaxis()->CenterTitle();
01251   hXvsZNC->GetYaxis()->SetTitle("X");
01252   hXvsZNC->GetYaxis()->CenterTitle();
01253   hXvsZNC->SetFillColor(0);
01254   //hXvsZNC->SetBit(TH1::kCanRebin);
01255 
01256   TH2F* hXvsZZoomCC=new TH2F("hXvsZZoomCC","hXvsZZoomCC",
01257                              20000,-2,25,200,-3,4);
01258   hXvsZZoomCC->SetTitle("X vs Z");
01259   hXvsZZoomCC->GetXaxis()->SetTitle("Z");
01260   hXvsZZoomCC->GetXaxis()->CenterTitle();
01261   hXvsZZoomCC->GetYaxis()->SetTitle("X");
01262   hXvsZZoomCC->GetYaxis()->CenterTitle();
01263   hXvsZZoomCC->SetFillColor(0);
01264   //hXvsZZoomCC->SetBit(TH1::kCanRebin);
01265   
01266   TH2F* hXvsZZoomNC=new TH2F("hXvsZZoomNC","hXvsZZoomNC",
01267                              20000,-2,25,200,-3,4);
01268   hXvsZZoomNC->SetTitle("X vs Z");
01269   hXvsZZoomNC->GetXaxis()->SetTitle("Z");
01270   hXvsZZoomNC->GetXaxis()->CenterTitle();
01271   hXvsZZoomNC->GetYaxis()->SetTitle("X");
01272   hXvsZZoomNC->GetYaxis()->CenterTitle();
01273   hXvsZZoomNC->SetFillColor(0);
01274   //hXvsZZoomNC->SetBit(TH1::kCanRebin);
01275 
01276   
01277   TH3F* hXYZCC=new TH3F("hXYZCC","hXYZCC",
01278                         100,-8,8,  400,-150,25,  200,-8,15);
01279   hXYZCC->SetTitle("XYZ");
01280   hXYZCC->GetXaxis()->SetTitle("X");
01281   hXYZCC->GetXaxis()->CenterTitle();
01282   hXYZCC->GetYaxis()->SetTitle("Y");
01283   hXYZCC->GetYaxis()->CenterTitle();
01284   hXYZCC->SetFillColor(0);
01285   //hXYZCC->SetBit(TH1::kCanRebin);
01286 
01287   TH3F* hXYZNC=new TH3F("hXYZNC","hXYZNC",
01288                         100,-8,8,  400,-150,25,  200,-8,15);
01289   hXYZNC->SetTitle("XYZ");
01290   hXYZNC->GetXaxis()->SetTitle("X");
01291   hXYZNC->GetXaxis()->CenterTitle();
01292   hXYZNC->GetYaxis()->SetTitle("Y");
01293   hXYZNC->GetYaxis()->CenterTitle();
01294   hXYZNC->SetFillColor(0);
01295   //hXYZNC->SetBit(TH1::kCanRebin);
01296 
01297   TH1F* hTrksPerEvt=new TH1F("hTrksPerEvt","hTrksPerEvt",10,-1,9);
01298   hTrksPerEvt->SetTitle("Tracks per Reco'd Event");
01299   hTrksPerEvt->GetXaxis()->SetTitle("# tracks");
01300   hTrksPerEvt->GetXaxis()->CenterTitle();
01301   hTrksPerEvt->GetYaxis()->SetTitle("");
01302   hTrksPerEvt->GetYaxis()->CenterTitle();
01303   hTrksPerEvt->SetFillColor(0);
01304   hTrksPerEvt->SetLineColor(1);
01305   hTrksPerEvt->SetLineWidth(1);
01306   hTrksPerEvt->SetLineStyle(1);
01307   //hTrksPerEvt->SetBit(TH1::kCanRebin);
01308 
01309   TH1F* hEvtsPerNu=new TH1F("hEvtsPerNu","hEvtsPerNu",10,-1,9);
01310   hEvtsPerNu->SetTitle("Events reco'd per neutrino interaction");
01311   hEvtsPerNu->GetXaxis()->SetTitle("Events reco'd");
01312   hEvtsPerNu->GetXaxis()->CenterTitle();
01313   hEvtsPerNu->GetYaxis()->SetTitle("");
01314   hEvtsPerNu->GetYaxis()->CenterTitle();
01315   hEvtsPerNu->SetFillColor(0);
01316   hEvtsPerNu->SetLineColor(1);
01317   hEvtsPerNu->SetLineWidth(1);
01318   hEvtsPerNu->SetLineStyle(1);
01319   //hEvtsPerNu->SetBit(TH1::kCanRebin);
01320 
01321   TH1F* hEvtsPerNuCC=new TH1F("hEvtsPerNuCC","hEvtsPerNuCC",10,-1,9);
01322   hEvtsPerNuCC->SetTitle("Events reco'd per neutrino interaction");
01323   hEvtsPerNuCC->GetXaxis()->SetTitle("Events reco'd");
01324   hEvtsPerNuCC->GetXaxis()->CenterTitle();
01325   hEvtsPerNuCC->GetYaxis()->SetTitle("");
01326   hEvtsPerNuCC->GetYaxis()->CenterTitle();
01327   hEvtsPerNuCC->SetFillColor(0);
01328   hEvtsPerNuCC->SetLineColor(1);
01329   hEvtsPerNuCC->SetLineWidth(1);
01330   hEvtsPerNuCC->SetLineStyle(1);
01331   //hEvtsPerNuCC->SetBit(TH1::kCanRebin);
01332 
01333   TH1F* hEvtsPerNuNC=new TH1F("hEvtsPerNuNC","hEvtsPerNuNC",10,-1,9);
01334   hEvtsPerNuNC->SetTitle("Events reco'd per neutrino interaction");
01335   hEvtsPerNuNC->GetXaxis()->SetTitle("Events reco'd");
01336   hEvtsPerNuNC->GetXaxis()->CenterTitle();
01337   hEvtsPerNuNC->GetYaxis()->SetTitle("");
01338   hEvtsPerNuNC->GetYaxis()->CenterTitle();
01339   hEvtsPerNuNC->SetFillColor(0);
01340   hEvtsPerNuNC->SetLineColor(3);
01341   hEvtsPerNuNC->SetLineWidth(2);
01342   hEvtsPerNuNC->SetLineStyle(1);
01343   //hEvtsPerNuNC->SetBit(TH1::kCanRebin);
01344   
01345   TH1F* hEvtsPerSlc=new TH1F("hEvtsPerSlc","hEvtsPerSlc",10,-1,9);
01346   hEvtsPerSlc->SetTitle("Events reco'd per Slice");
01347   hEvtsPerSlc->GetXaxis()->SetTitle("Events reco'd");
01348   hEvtsPerSlc->GetXaxis()->CenterTitle();
01349   hEvtsPerSlc->GetYaxis()->SetTitle("");
01350   hEvtsPerSlc->GetYaxis()->CenterTitle();
01351   hEvtsPerSlc->SetFillColor(0);
01352   hEvtsPerSlc->SetLineColor(1);
01353   hEvtsPerSlc->SetLineWidth(2);
01354   hEvtsPerSlc->SetLineStyle(1);
01355   //hEvtsPerSlc->SetBit(TH1::kCanRebin);
01356   
01357   TH1F* hEvtsPerSlcg1=new TH1F("hEvtsPerSlcg1","hEvtsPerSlcg1",10,-1,9);
01358   hEvtsPerSlcg1->SetTitle("Events reco'd per Slice");
01359   hEvtsPerSlcg1->GetXaxis()->SetTitle("Events reco'd");
01360   hEvtsPerSlcg1->GetXaxis()->CenterTitle();
01361   hEvtsPerSlcg1->GetYaxis()->SetTitle("");
01362   hEvtsPerSlcg1->GetYaxis()->CenterTitle();
01363   hEvtsPerSlcg1->SetFillColor(0);
01364   hEvtsPerSlcg1->SetLineColor(2);
01365   hEvtsPerSlcg1->SetLineWidth(2);
01366   hEvtsPerSlcg1->SetLineStyle(1);
01367   //hEvtsPerSlcg1->SetBit(TH1::kCanRebin);
01368 
01369   TH1F* hEvtsPerSlcg1T=new TH1F("hEvtsPerSlcg1T","hEvtsPerSlcg1T",10,-1,9);
01370   hEvtsPerSlcg1T->SetTitle("Events reco'd per Slice");
01371   hEvtsPerSlcg1T->GetXaxis()->SetTitle("Events reco'd");
01372   hEvtsPerSlcg1T->GetXaxis()->CenterTitle();
01373   hEvtsPerSlcg1T->GetYaxis()->SetTitle("");
01374   hEvtsPerSlcg1T->GetYaxis()->CenterTitle();
01375   hEvtsPerSlcg1T->SetFillColor(0);
01376   hEvtsPerSlcg1T->SetLineColor(4);
01377   hEvtsPerSlcg1T->SetLineWidth(2);
01378   hEvtsPerSlcg1T->SetLineStyle(1);
01379   //hEvtsPerSlcg1T->SetBit(TH1::kCanRebin);
01380 
01381   TH2F* hEvtsVsNuEnCC=new TH2F("hEvtsVsNuEnCC","hEvtsVsNuEnCC",
01382                                110,-2,20,8,-1,7);
01383   hEvtsVsNuEnCC->SetTitle("Events Reco'd per Neutrino vs True Neutrino Energy");
01384   hEvtsVsNuEnCC->GetXaxis()->SetTitle("True Neutrino Energy (GeV)");
01385   hEvtsVsNuEnCC->GetXaxis()->CenterTitle();
01386   hEvtsVsNuEnCC->GetYaxis()->SetTitle("Events Reco'd");
01387   hEvtsVsNuEnCC->GetYaxis()->CenterTitle();
01388   hEvtsVsNuEnCC->SetFillColor(0);
01389   //hEvtsVsNuEnCC->SetBit(TH1::kCanRebin);
01390 
01391   TH2F* hEvtsVsNuEnNC=new TH2F("hEvtsVsNuEnNC","hEvtsVsNuEnNC",
01392                                110,-2,20,8,-1,7);
01393   hEvtsVsNuEnNC->SetTitle("Events Reco'd per Neutrino vs True Neutrino Energy");
01394   hEvtsVsNuEnNC->GetXaxis()->SetTitle("True Neutrino Energy (GeV)");
01395   hEvtsVsNuEnNC->GetXaxis()->CenterTitle();
01396   hEvtsVsNuEnNC->GetYaxis()->SetTitle("Events Reco'd");
01397   hEvtsVsNuEnNC->GetYaxis()->CenterTitle();
01398   hEvtsVsNuEnNC->SetFillColor(0);
01399   //hEvtsVsNuEnNC->SetBit(TH1::kCanRebin);
01400 
01401 
01402 
01403   TProfile* pNuMuBarQEffVsEn=new TProfile("pNuMuBarQEffVsEn","pNuMuBarQEffVsEn",50,0,50);
01404   pNuMuBarQEffVsEn->SetTitle("Charge Sign Efficiency vs. True Neutrino Energy");
01405   pNuMuBarQEffVsEn->GetXaxis()->SetTitle("Energy (GeV)");
01406   pNuMuBarQEffVsEn->GetXaxis()->CenterTitle();
01407   pNuMuBarQEffVsEn->GetYaxis()->SetTitle("Efficiency");
01408   pNuMuBarQEffVsEn->GetYaxis()->CenterTitle();
01409   pNuMuBarQEffVsEn->SetLineColor(2);
01410   pNuMuBarQEffVsEn->SetFillColor(0);
01411   //pNuMuBarQEffVsEn->SetBit(TH1::kCanRebin);
01412 
01413   TProfile* pNuMuQEffVsEn=new TProfile("pNuMuQEffVsEn","pNuMuQEffVsEn",50,0,50);
01414   pNuMuQEffVsEn->SetTitle("Charge Sign Efficiency vs. True Neutrino Energy");
01415   pNuMuQEffVsEn->GetXaxis()->SetTitle("Energy (GeV)");
01416   pNuMuQEffVsEn->GetXaxis()->CenterTitle();
01417   pNuMuQEffVsEn->GetYaxis()->SetTitle("Efficiency");
01418   pNuMuQEffVsEn->GetYaxis()->CenterTitle();
01419   pNuMuQEffVsEn->SetLineColor(1);
01420   pNuMuQEffVsEn->SetFillColor(0);
01421   //pNuMuQEffVsEn->SetBit(TH1::kCanRebin);
01422 
01423   TProfile* pNuMuBarFitPassVsEn=new TProfile("pNuMuBarFitPassVsEn","pNuMuBarFitPassVsEn",50,0,50);
01424   pNuMuBarFitPassVsEn->SetTitle("Fit Pass Fraction vs. True Neutrino Energy");
01425   pNuMuBarFitPassVsEn->GetXaxis()->SetTitle("Energy (GeV)");
01426   pNuMuBarFitPassVsEn->GetXaxis()->CenterTitle();
01427   pNuMuBarFitPassVsEn->GetYaxis()->SetTitle("Pass Fraction");
01428   pNuMuBarFitPassVsEn->GetYaxis()->CenterTitle();
01429   pNuMuBarFitPassVsEn->SetLineColor(2);
01430   pNuMuBarFitPassVsEn->SetFillColor(0);
01431   //pNuMuBarFitPassVsEn->SetBit(TH1::kCanRebin);
01432 
01433   TProfile* pNuMuFitPassVsEn=new TProfile("pNuMuFitPassVsEn","pNuMuFitPassVsEn",50,0,50);
01434   pNuMuFitPassVsEn->SetTitle("Fit Pass Fraction vs. True Neutrino Energy");
01435   pNuMuFitPassVsEn->GetXaxis()->SetTitle("Energy (GeV)");
01436   pNuMuFitPassVsEn->GetXaxis()->CenterTitle();
01437   pNuMuFitPassVsEn->GetYaxis()->SetTitle("Pass Fraction");
01438   pNuMuFitPassVsEn->GetYaxis()->CenterTitle();
01439   pNuMuFitPassVsEn->SetLineColor(1);
01440   pNuMuFitPassVsEn->SetFillColor(0);
01441   //pNuMuFitPassVsEn->SetBit(TH1::kCanRebin);
01442 
01443 
01444   
01445   TH1F* hNuMuBarEnGoodQ=new TH1F("hNuMuBarEnGoodQ","hNuMuBarEnGoodQ",
01446                               4*352,-32,320);
01447   hNuMuBarEnGoodQ->GetXaxis()->SetTitle("Energy (GeV)");
01448   hNuMuBarEnGoodQ->GetXaxis()->CenterTitle();
01449   hNuMuBarEnGoodQ->GetYaxis()->SetTitle("");
01450   hNuMuBarEnGoodQ->GetYaxis()->CenterTitle();
01451   hNuMuBarEnGoodQ->SetFillColor(0);
01452   hNuMuBarEnGoodQ->SetLineColor(2);
01453   //hNuMuBarEnGoodQ->SetBit(TH1::kCanRebin);
01454 
01455   TH1F* hNuMuEnGoodQ=new TH1F("hNuMuEnGoodQ","hNuMuEnGoodQ",4*352,-32,320);
01456   hNuMuEnGoodQ->GetXaxis()->SetTitle("Energy (GeV)");
01457   hNuMuEnGoodQ->GetXaxis()->CenterTitle();
01458   hNuMuEnGoodQ->GetYaxis()->SetTitle("");
01459   hNuMuEnGoodQ->GetYaxis()->CenterTitle();
01460   hNuMuEnGoodQ->SetFillColor(0);
01461   hNuMuEnGoodQ->SetLineColor(1);
01462   hNuMuEnGoodQ->SetLineWidth(2);
01463   //hNuMuEnGoodQ->SetBit(TH1::kCanRebin);
01464 
01465   TH1F* hNuMuBarEnBadQ=new TH1F("hNuMuBarEnBadQ","hNuMuBarEnBadQ",
01466                               4*352,-32,320);
01467   hNuMuBarEnBadQ->GetXaxis()->SetTitle("Energy (GeV)");
01468   hNuMuBarEnBadQ->GetXaxis()->CenterTitle();
01469   hNuMuBarEnBadQ->GetYaxis()->SetTitle("");
01470   hNuMuBarEnBadQ->GetYaxis()->CenterTitle();
01471   hNuMuBarEnBadQ->SetFillColor(0);
01472   hNuMuBarEnBadQ->SetLineColor(2);
01473   //hNuMuBarEnBadQ->SetBit(TH1::kCanRebin);
01474 
01475   TH1F* hNuMuEnBadQ=new TH1F("hNuMuEnBadQ","hNuMuEnBadQ",4*352,-32,320);
01476   hNuMuEnBadQ->GetXaxis()->SetTitle("Energy (GeV)");
01477   hNuMuEnBadQ->GetXaxis()->CenterTitle();
01478   hNuMuEnBadQ->GetYaxis()->SetTitle("");
01479   hNuMuEnBadQ->GetYaxis()->CenterTitle();
01480   hNuMuEnBadQ->SetFillColor(0);
01481   hNuMuEnBadQ->SetLineColor(1);
01482   hNuMuEnBadQ->SetLineWidth(2);
01483   //hNuMuEnBadQ->SetBit(TH1::kCanRebin);
01484 
01485 
01486 
01487   TH1F* hNuMuBarRecoEnGoodQ=new TH1F("hNuMuBarRecoEnGoodQ","hNuMuBarRecoEnGoodQ",
01488                               4*352,-32,320);
01489   hNuMuBarRecoEnGoodQ->GetXaxis()->SetTitle("Energy (GeV)");
01490   hNuMuBarRecoEnGoodQ->GetXaxis()->CenterTitle();
01491   hNuMuBarRecoEnGoodQ->GetYaxis()->SetTitle("");
01492   hNuMuBarRecoEnGoodQ->GetYaxis()->CenterTitle();
01493   hNuMuBarRecoEnGoodQ->SetFillColor(0);
01494   hNuMuBarRecoEnGoodQ->SetLineColor(2);
01495   //hNuMuBarRecoEnGoodQ->SetBit(TH1::kCanRebin);
01496 
01497   TH1F* hNuMuRecoEnGoodQ=new TH1F("hNuMuRecoEnGoodQ","hNuMuRecoEnGoodQ",4*352,-32,320);
01498   hNuMuRecoEnGoodQ->GetXaxis()->SetTitle("Energy (GeV)");
01499   hNuMuRecoEnGoodQ->GetXaxis()->CenterTitle();
01500   hNuMuRecoEnGoodQ->GetYaxis()->SetTitle("");
01501   hNuMuRecoEnGoodQ->GetYaxis()->CenterTitle();
01502   hNuMuRecoEnGoodQ->SetFillColor(0);
01503   hNuMuRecoEnGoodQ->SetLineColor(1);
01504   hNuMuRecoEnGoodQ->SetLineWidth(2);
01505   //hNuMuRecoEnGoodQ->SetBit(TH1::kCanRebin);
01506 
01507   TH1F* hNuMuBarRecoEnBadQ=new TH1F("hNuMuBarRecoEnBadQ","hNuMuBarRecoEnBadQ",
01508                               4*352,-32,320);
01509   hNuMuBarRecoEnBadQ->GetXaxis()->SetTitle("Energy (GeV)");
01510   hNuMuBarRecoEnBadQ->GetXaxis()->CenterTitle();
01511   hNuMuBarRecoEnBadQ->GetYaxis()->SetTitle("");
01512   hNuMuBarRecoEnBadQ->GetYaxis()->CenterTitle();
01513   hNuMuBarRecoEnBadQ->SetFillColor(0);
01514   hNuMuBarRecoEnBadQ->SetLineColor(2);
01515   //hNuMuBarRecoEnBadQ->SetBit(TH1::kCanRebin);
01516 
01517   TH1F* hNuMuRecoEnBadQ=new TH1F("hNuMuRecoEnBadQ","hNuMuRecoEnBadQ",4*352,-32,320);
01518   hNuMuRecoEnBadQ->GetXaxis()->SetTitle("Energy (GeV)");
01519   hNuMuRecoEnBadQ->GetXaxis()->CenterTitle();
01520   hNuMuRecoEnBadQ->GetYaxis()->SetTitle("");
01521   hNuMuRecoEnBadQ->GetYaxis()->CenterTitle();
01522   hNuMuRecoEnBadQ->SetFillColor(0);
01523   hNuMuRecoEnBadQ->SetLineColor(1);
01524   hNuMuRecoEnBadQ->SetLineWidth(2);
01525   //hNuMuRecoEnBadQ->SetBit(TH1::kCanRebin);
01526 
01527 
01528 
01529   TH1F* hNuMuBarEnTrk0=new TH1F("hNuMuBarEnTrk0","hNuMuBarEnTrk0",
01530                               4*352,-32,320);
01531   hNuMuBarEnTrk0->GetXaxis()->SetTitle("Energy (GeV)");
01532   hNuMuBarEnTrk0->GetXaxis()->CenterTitle();
01533   hNuMuBarEnTrk0->GetYaxis()->SetTitle("");
01534   hNuMuBarEnTrk0->GetYaxis()->CenterTitle();
01535   hNuMuBarEnTrk0->SetFillColor(0);
01536   hNuMuBarEnTrk0->SetLineColor(2);
01537   //hNuMuBarEnTrk0->SetBit(TH1::kCanRebin);
01538 
01539   TH1F* hNuMuEnTrk0=new TH1F("hNuMuEnTrk0","hNuMuEnTrk0",4*352,-32,320);
01540   hNuMuEnTrk0->GetXaxis()->SetTitle("Energy (GeV)");
01541   hNuMuEnTrk0->GetXaxis()->CenterTitle();
01542   hNuMuEnTrk0->GetYaxis()->SetTitle("");
01543   hNuMuEnTrk0->GetYaxis()->CenterTitle();
01544   hNuMuEnTrk0->SetFillColor(0);
01545   hNuMuEnTrk0->SetLineColor(1);
01546   hNuMuEnTrk0->SetLineWidth(2);
01547   //hNuMuEnTrk0->SetBit(TH1::kCanRebin);
01548 
01549 
01550 
01551   TH1F* hNuMuBarChi2GoodQ=new TH1F("hNuMuBarChi2GoodQ",
01552                                    "hNuMuBarChi2GoodQ",
01553                                    10*176,-16,160);
01554   hNuMuBarChi2GoodQ->GetXaxis()->SetTitle("Chi2/ndof");
01555   hNuMuBarChi2GoodQ->GetXaxis()->CenterTitle();
01556   hNuMuBarChi2GoodQ->GetYaxis()->SetTitle("");
01557   hNuMuBarChi2GoodQ->GetYaxis()->CenterTitle();
01558   hNuMuBarChi2GoodQ->SetFillColor(0);
01559   hNuMuBarChi2GoodQ->SetLineColor(2);
01560   //hNuMuBarChi2GoodQ->SetBit(TH1::kCanRebin);
01561 
01562   TH1F* hNuMuChi2GoodQ=new TH1F("hNuMuChi2GoodQ","hNuMuChi2GoodQ",
01563                                 10*176,-16,160);
01564   hNuMuChi2GoodQ->GetXaxis()->SetTitle("Chi2/ndof");
01565   hNuMuChi2GoodQ->GetXaxis()->CenterTitle();
01566   hNuMuChi2GoodQ->GetYaxis()->SetTitle("");
01567   hNuMuChi2GoodQ->GetYaxis()->CenterTitle();
01568   hNuMuChi2GoodQ->SetFillColor(0);
01569   hNuMuChi2GoodQ->SetLineColor(1);
01570   hNuMuChi2GoodQ->SetLineWidth(2);
01571   //hNuMuChi2GoodQ->SetBit(TH1::kCanRebin);
01572 
01573   TH1F* hNuMuBarChi2BadQ=new TH1F("hNuMuBarChi2BadQ",
01574                                   "hNuMuBarChi2BadQ",
01575                                   10*176,-16,160);
01576   hNuMuBarChi2BadQ->GetXaxis()->SetTitle("Chi2/ndof");
01577   hNuMuBarChi2BadQ->GetXaxis()->CenterTitle();
01578   hNuMuBarChi2BadQ->GetYaxis()->SetTitle("");
01579   hNuMuBarChi2BadQ->GetYaxis()->CenterTitle();
01580   hNuMuBarChi2BadQ->SetFillColor(0);
01581   hNuMuBarChi2BadQ->SetLineColor(2);
01582   hNuMuBarChi2BadQ->SetLineStyle(2);
01583   //hNuMuBarChi2BadQ->SetBit(TH1::kCanRebin);
01584 
01585   TH1F* hNuMuChi2BadQ=new TH1F("hNuMuChi2BadQ","hNuMuChi2BadQ",
01586                                10*176,-16,160);
01587   hNuMuChi2BadQ->GetXaxis()->SetTitle("Chi2/ndof");
01588   hNuMuChi2BadQ->GetXaxis()->CenterTitle();
01589   hNuMuChi2BadQ->GetYaxis()->SetTitle("");
01590   hNuMuChi2BadQ->GetYaxis()->CenterTitle();
01591   hNuMuChi2BadQ->SetFillColor(0);
01592   hNuMuChi2BadQ->SetLineColor(1);
01593   hNuMuChi2BadQ->SetLineWidth(2);
01594   hNuMuChi2BadQ->SetLineStyle(2);
01595   //hNuMuChi2BadQ->SetBit(TH1::kCanRebin);
01596 
01597 
01598   
01599   TH1F* hNuMuBarSigqp_qpGoodQ=new TH1F("hNuMuBarSigqp_qpGoodQ",
01600                                        "hNuMuBarSigqp_qpGoodQ",
01601                                        5000,-100,100);
01602   hNuMuBarSigqp_qpGoodQ->GetXaxis()->SetTitle("#sigma(Q/P)/(Q/P)");
01603   hNuMuBarSigqp_qpGoodQ->GetXaxis()->CenterTitle();
01604   hNuMuBarSigqp_qpGoodQ->GetYaxis()->SetTitle("");
01605   hNuMuBarSigqp_qpGoodQ->GetYaxis()->CenterTitle();
01606   hNuMuBarSigqp_qpGoodQ->SetFillColor(0);
01607   hNuMuBarSigqp_qpGoodQ->SetLineColor(2);
01608   //hNuMuBarSigqp_qpGoodQ->SetBit(TH1::kCanRebin);
01609 
01610   TH1F* hNuMuSigqp_qpGoodQ=new TH1F("hNuMuSigqp_qpGoodQ",
01611                                     "hNuMuSigqp_qpGoodQ",
01612                                     5000,-100,100);
01613   hNuMuSigqp_qpGoodQ->GetXaxis()->SetTitle("#sigma(Q/P)/(Q/P)");
01614   hNuMuSigqp_qpGoodQ->GetXaxis()->CenterTitle();
01615   hNuMuSigqp_qpGoodQ->GetYaxis()->SetTitle("");
01616   hNuMuSigqp_qpGoodQ->GetYaxis()->CenterTitle();
01617   hNuMuSigqp_qpGoodQ->SetFillColor(0);
01618   hNuMuSigqp_qpGoodQ->SetLineColor(1);
01619   hNuMuSigqp_qpGoodQ->SetLineWidth(2);
01620   //hNuMuSigqp_qpGoodQ->SetBit(TH1::kCanRebin);
01621 
01622   TH1F* hNuMuBarSigqp_qpBadQ=new TH1F("hNuMuBarSigqp_qpBadQ",
01623                                       "hNuMuBarSigqp_qpBadQ",
01624                                       5000,-100,100);
01625   hNuMuBarSigqp_qpBadQ->GetXaxis()->SetTitle("#sigma(Q/P)/(Q/P)");
01626   hNuMuBarSigqp_qpBadQ->GetXaxis()->CenterTitle();
01627   hNuMuBarSigqp_qpBadQ->GetYaxis()->SetTitle("");
01628   hNuMuBarSigqp_qpBadQ->GetYaxis()->CenterTitle();
01629   hNuMuBarSigqp_qpBadQ->SetFillColor(0);
01630   hNuMuBarSigqp_qpBadQ->SetLineColor(2);
01631   hNuMuBarSigqp_qpBadQ->SetLineStyle(2);
01632   //hNuMuBarSigqp_qpBadQ->SetBit(TH1::kCanRebin);
01633 
01634   TH1F* hNuMuSigqp_qpBadQ=new TH1F("hNuMuSigqp_qpBadQ",
01635                                    "hNuMuSigqp_qpBadQ",
01636                                    5000,-100,100);
01637   hNuMuSigqp_qpBadQ->GetXaxis()->SetTitle("#sigma(Q/P)/(Q/P)");
01638   hNuMuSigqp_qpBadQ->GetXaxis()->CenterTitle();
01639   hNuMuSigqp_qpBadQ->GetYaxis()->SetTitle("");
01640   hNuMuSigqp_qpBadQ->GetYaxis()->CenterTitle();
01641   hNuMuSigqp_qpBadQ->SetFillColor(0);
01642   hNuMuSigqp_qpBadQ->SetLineColor(1);
01643   hNuMuSigqp_qpBadQ->SetLineWidth(2);
01644   hNuMuSigqp_qpBadQ->SetLineStyle(2);
01645   //hNuMuSigqp_qpBadQ->SetBit(TH1::kCanRebin);
01646 
01647   TH1F* hDeltaTime=new TH1F("hDeltaTime","hDeltaTime",10100,-100,10000);
01648   hDeltaTime->GetXaxis()->SetTitle("{#Delta}T (ns)");
01649   hDeltaTime->GetXaxis()->CenterTitle();
01650   hDeltaTime->GetYaxis()->SetTitle("");
01651   hDeltaTime->GetYaxis()->CenterTitle();
01652   hDeltaTime->SetFillColor(0);
01653   hDeltaTime->SetLineColor(1);
01654   hDeltaTime->SetLineWidth(2);
01655   hDeltaTime->SetLineStyle(2);
01656   //hDeltaTime->SetBit(TH1::kCanRebin);
01657 
01658   TH1F* hDeltaT=new TH1F("hDeltaT","hDeltaT",10100,-100,10000);
01659   hDeltaT->GetXaxis()->SetTitle("#DeltaT (ns)");
01660   hDeltaT->GetXaxis()->CenterTitle();
01661   hDeltaT->GetYaxis()->SetTitle("");
01662   hDeltaT->GetYaxis()->CenterTitle();
01663   hDeltaT->SetFillColor(0);
01664   hDeltaT->SetLineColor(1);
01665   hDeltaT->SetLineWidth(2);
01666   hDeltaT->SetLineStyle(1);
01667   //hDeltaT->SetBit(TH1::kCanRebin);
01668 
01669   TH1F* hDeltaTg1=new TH1F("hDeltaTg1","hDeltaTg1",10100,-100,10000);
01670   hDeltaTg1->GetXaxis()->SetTitle("#DeltaT (ns)");
01671   hDeltaTg1->GetXaxis()->CenterTitle();
01672   hDeltaTg1->GetYaxis()->SetTitle("");
01673   hDeltaTg1->GetYaxis()->CenterTitle();
01674   hDeltaTg1->SetFillColor(0);
01675   hDeltaTg1->SetLineColor(2);
01676   hDeltaTg1->SetLineWidth(2);
01677   hDeltaTg1->SetLineStyle(1);
01678   //hDeltaTg1->SetBit(TH1::kCanRebin);
01679 
01680   Int_t totalSnarlsCounter=0;
01681   Int_t ccInFidCounter=0;
01682   Int_t recoEvtCounter=0;
01683   Int_t nuIntCounter=0;
01684   Int_t oneRecoEvtCounter=0;
01685   Int_t zeroTrackCounter=0;
01686   Int_t zeroTrackNuMuCounter=0;
01687   Int_t zeroTrackNuMuBarCounter=0;
01688   Int_t twoTrackCounter=0;
01689   Int_t twoTrackNuMuCounter=0;
01690   Int_t twoTrackNuMuBarCounter=0;
01691   Int_t threeTrackCounter=0;
01692   Int_t gr3TrackCounter=0;
01693   Int_t oneTrackCounter=0;
01694   Int_t passFitCounter=0;
01695   Int_t badNuMuCounter=0;
01696   Int_t goodNuMuCounter=0;
01697   Int_t badNuMuBarCounter=0;
01698   Int_t goodNuMuBarCounter=0;
01699 
01700   const NuCuts cuts;
01701   const NuReco reco;
01702   const NuExtraction ext;
01703 
01704   NuConfig config;
01705   this->ExtractConfig(config);
01706   //get an instance of the code library
01707   const NuLibrary& lib=NuLibrary::Instance();
01708  
01712   
01713   this->InitialiseLoopVariables();  
01714   
01715   //for(Int_t entry=0;entry<10000;entry++){
01716   for(Int_t entry=0;entry<this->GetEntries();entry++){
01717       
01718     this->SetLoopVariables(entry);
01719       
01720     set<Int_t> setNuInFid;
01721     set<Int_t> setNuInFidCC;
01722     map<Int_t,Double_t> deltaTs;
01723     map<Int_t,Int_t> evtsPerSlc;
01724   
01725     //get reference to NtpStRecord from base class
01726     const NtpStRecord& ntp=(*this->GetNtpStRecord());
01727 
01728 
01729     const RecCandHeader& rec=ntp.GetHeader();
01730     MAXMSG("NuAnalysis",Msg::kInfo,5)
01731       <<"Found: run="<<rec.GetRun()
01732       <<", subrun="<<rec.GetSubRun()
01733       <<", detector="<<rec.GetVldContext().GetDetector()
01734       <<", simFlag="<<rec.GetVldContext().GetSimFlag()
01735       <<endl;
01736 
01737     VldTimeStamp vldts;
01738     //VldTimeStamp vldts(ev.UnixTime,0);
01739     VldContext vc(rec.GetVldContext().GetDetector(),
01740                   rec.GetVldContext().GetSimFlag(),vldts);
01741     //get the ugh
01742     UgliGeomHandle ugh(vc);
01743     
01744     TClonesArray& mcTca=*ntp.mc;
01745     Int_t numInt=mcTca.GetEntries();
01746     MAXMSG("NuAnalysis",Msg::kInfo,20)
01747       <<"Number of entries in NtpMCTruth="
01748       <<mcTca.GetEntries()<<endl;
01749     //if (mcTca.GetEntries()==0){ 
01750 
01751     hNuInt->Fill(mcTca.GetEntries());
01752 
01753     for (Int_t i=0;i<numInt;i++){
01754       const NtpMCTruth& mc=*(dynamic_cast<NtpMCTruth*>(mcTca[i]));
01755       
01756       TVector3 xyz(mc.vtxx,mc.vtxy,mc.vtxz);
01757       // calculate the positions in UVZ space
01758       TVector3 uvz=ugh.xyz2uvz(xyz);
01759       
01760       //simple event object to hold important quantities
01761       NuEvent nu;
01762       
01763       //get the run, snarl, etc info
01764       ext.ExtractGeneralInfo(ntp,nu);
01765       
01766       Bool_t isInFidVol=cuts.IsInFidVol(mc.vtxx,mc.vtxy,mc.vtxz,
01767                                         uvz.X(),uvz.Y(),
01768                                         0,0,
01769                                         nu.detector,nu.anaVersion,
01770                                         nu.releaseType,nu.simFlag);
01771 
01772       if (isInFidVol) {
01773         deltaTs.clear();
01774         reco.GetEvtDeltaTs(ntp,deltaTs);
01775         evtsPerSlc.clear();
01776         reco.GetEvtsPerSlc(ntp,evtsPerSlc);
01777         MAXMSG("NuAnalysis",Msg::kInfo,100)
01778           <<"Contained mc="<<mc.index<<endl;
01779         setNuInFid.insert(mc.index);
01780         if (mc.iaction==1 && (mc.inu==-14 || mc.inu==14)) {
01781           setNuInFidCC.insert(mc.index);
01782         }
01783       }
01784 
01785       MAXMSG("NuAnalysis",Msg::kDebug,20)
01786         <<"isInFidVol="<<isInFidVol
01787         <<", x="<<mc.vtxx<<", y="<<mc.vtxy<<", z="<<mc.vtxz
01788         <<", u="<<uvz.X()<<", v="<<uvz.Y()<<endl;
01789       
01790       if (isInFidVol){
01791         MAXMSG("NuAnalysis",Msg::kInfo,20)
01792           <<"isInFidVol="<<isInFidVol
01793           <<", x="<<mc.vtxx<<", y="<<mc.vtxy<<", z="<<mc.vtxz
01794           <<", u="<<uvz.X()<<", v="<<uvz.Y()<<endl;
01795       }
01796       
01797       //calc index for vector of histos
01798       Int_t enIndex=static_cast<Int_t>(mc.p4neu[3]*2.0+1);
01799 
01800       if (mc.iaction==1){
01801         hNuYCC->Fill(mc.y);
01802         if (isInFidVol) {
01803           hYvsXFidCC->Fill(mc.vtxx,mc.vtxy);
01804         }
01805         hYvsXCC->Fill(mc.vtxx,mc.vtxy);
01806         hYvsX400CC->Fill(mc.vtxx,mc.vtxy);
01807         hYvsZCC->Fill(mc.vtxz,mc.vtxy);
01808         hXvsZCC->Fill(mc.vtxz,mc.vtxx);
01809         if (mc.vtxy>-2.5 && mc.vtxy<3) hXvsZZoomCC->
01810                                          Fill(mc.vtxz,mc.vtxx);
01811         hXYZCC->Fill(mc.vtxx,mc.vtxz,mc.vtxy);
01812         hZCC->Fill(mc.vtxz);
01813         hinuCC->Fill(mc.inu);
01814         if (mc.inu==-14){
01815           if (enIndex<nbinsForY) vNuYNuMuBarCC[enIndex]->Fill(mc.y);
01816           hNuMuBarEnCC->Fill(mc.p4neu[3]);
01817           hNuMuBarEn4000CC->Fill(mc.p4neu[3]);
01818           if (isInFidVol) {
01819             hNuYFidNuMuBarCC->Fill(mc.y);
01820             MAXMSG("NuAnalysis",Msg::kInfo,200)
01821               <<"enIndex="<<enIndex<<", E="<<mc.p4neu[3]<<endl;
01822             hNuMuBarFidEnCC->Fill(mc.p4neu[3]);
01823             hNuMuBarLike->Fill(mc.p4neu[3]);
01824           }
01825         }
01826         else if (mc.inu==14) {
01827           if (enIndex<nbinsForY) vNuYNuMuCC[enIndex]->Fill(mc.y);
01828           hNuMuEnCC->Fill(mc.p4neu[3]);
01829           hNuMuEn4000CC->Fill(mc.p4neu[3]);
01830           if (isInFidVol) {
01831             hNuYFidNuMuCC->Fill(mc.y);
01832             hNuMuFidEnCC->Fill(mc.p4neu[3]);
01833             hNuMuLike->Fill(mc.p4neu[3]);
01834           }
01835         }
01836         else if (mc.inu==-12) hNueBarEnCC->Fill(mc.p4neu[3]);
01837         else if (mc.inu==12) hNueEnCC->Fill(mc.p4neu[3]);
01838         else {
01839           MAXMSG("NuAnalysis",Msg::kWarning,100)
01840             <<"particle not defined for filling histo="<<mc.inu<<endl;
01841         }
01842       }
01843       else if (mc.iaction==0){
01844         hNuYNC->Fill(mc.y);
01845         if (isInFidVol) {
01846           hYvsXFidNC->Fill(mc.vtxx,mc.vtxy);
01847         }
01848         hYvsXNC->Fill(mc.vtxx,mc.vtxy);
01849         hYvsX400NC->Fill(mc.vtxx,mc.vtxy);
01850         hYvsZNC->Fill(mc.vtxz,mc.vtxy);
01851         hXvsZNC->Fill(mc.vtxz,mc.vtxx);
01852         //cut out rock events above and below
01853         if (mc.vtxy>-2.5 && mc.vtxy<3) hXvsZZoomNC->
01854                                          Fill(mc.vtxz,mc.vtxx);
01855         hXYZNC->Fill(mc.vtxx,mc.vtxz,mc.vtxy);
01856         hZNC->Fill(mc.vtxz);
01857         hinuNC->Fill(mc.inu);
01858         if (mc.inu==-14) {
01859           if (enIndex<nbinsForY) vNuYNuMuBarNC[enIndex]->Fill(mc.y);
01860           hNuMuBarEnNC->Fill(mc.p4neu[3]);
01861           hNuMuBarEnDepNC->Fill(mc.y*mc.p4neu[3]);
01862           if (isInFidVol) {
01863             hNuYFidNuMuBarNC->Fill(mc.y);
01864           }
01865         }
01866         else if (mc.inu==14) { 
01867           if (enIndex<nbinsForY) vNuYNuMuNC[enIndex]->Fill(mc.y);
01868           hNuMuEnNC->Fill(mc.p4neu[3]);
01869           hNuMuEnDepNC->Fill(mc.y*mc.p4neu[3]);
01870           if (isInFidVol) {
01871             hNuYFidNuMuNC->Fill(mc.y);
01872           }
01873         }
01874         else if (mc.inu==-12) {
01875           hNueBarEnNC->Fill(mc.p4neu[3]);
01876           hNueBarEnDepNC->Fill(mc.y*mc.p4neu[3]);
01877         }
01878         else if (mc.inu==12) {
01879           hNueEnNC->Fill(mc.p4neu[3]);
01880           hNueEnDepNC->Fill(mc.y*mc.p4neu[3]);
01881         }
01882         else {
01883           MAXMSG("NuAnalysis",Msg::kWarning,100)
01884             <<"particle not defined for filling histo="<<mc.inu<<endl;
01885         }
01886       }
01887       else cout<<"Ahhh, bad iaction"<<endl;
01888     }
01889 
01890     MAXMSG("NuAnalysis",Msg::kInfo,100)
01891       <<"Number of fiducial volume interactions in spill="
01892       <<setNuInFid.size()<<endl;
01893 
01894     TClonesArray& thevtTca=(*ntp.thevt);//TruthHelper Track TCA
01895     const Int_t numthevts=thevtTca.GetEntriesFast();
01896     TClonesArray& evtTca=(*ntp.evt);
01897     //const Int_t numEvts=evtTca.GetEntriesFast();
01898     
01899     //set of events with true neutrino interactions in the fid vol
01900     set<Int_t> evtsInFid;
01901     set<Int_t> evtsInFidCC;
01902 
01903     set<Int_t>::iterator setNuInFidEnd=setNuInFid.end();
01904     map<Int_t,Int_t> nuEvtCounter;
01905     map<Int_t,Int_t> nuEvtCounterCC;
01906     map<Int_t,multiset<Double_t> > nuIntEvtTimesCC;
01907     for (Int_t ithevt=0;ithevt<numthevts;ithevt++){
01908       const NtpTHEvent& thevt=
01909         *dynamic_cast<NtpTHEvent*>(thevtTca[ithevt]);
01910       const NtpSREvent& evt=
01911         *dynamic_cast<NtpSREvent*>(evtTca[ithevt]);
01912       
01913       if (setNuInFid.find(thevt.neumc)!=setNuInFidEnd){
01914         MAXMSG("NuAnalysis",Msg::kInfo,100)
01915           <<"Found mc="<<thevt.neumc<<endl;
01916         //count the number of reco events a particular nu interaction
01917         //is believed to cause
01918         nuEvtCounter[thevt.neumc]++;
01919         //keep a list of the events corresponding to neutrinos in
01920         //the fiducial volume
01921         evtsInFid.insert(ithevt);
01922 
01923         const NtpMCTruth& mc=
01924           *(dynamic_cast<NtpMCTruth*>(mcTca[thevt.neumc]));
01925         if (mc.iaction==1 && (mc.inu==-14 || mc.inu==14)) {
01926           nuEvtCounterCC[thevt.neumc]++;
01927           evtsInFidCC.insert(ithevt);
01928 
01929           //store the median times of the events 
01930           //from each neutrino interaction
01931           Double_t time=reco.GetEvtMedianTime(ntp,evt);
01932           nuIntEvtTimesCC[thevt.neumc].insert(time);
01933         }
01934       }
01935     }
01936 
01937     //need to work out the number of times no event is found
01938     typedef set<Int_t>::iterator setNuInFidIt;
01939     for (setNuInFidIt it=setNuInFid.begin();
01940          it!=setNuInFid.end();++it){
01941       //check if event is not in the map (i.e. no evt reco'd)
01942       MAXMSG("NuAnalysis",Msg::kInfo,100)
01943         <<"Looking in evt counter for mc.index="<<*it
01944         <<", evtCo size="<<nuEvtCounter.size()
01945         <<", setNu size="<<setNuInFid.size()
01946         <<endl;
01947       if (nuEvtCounter.find(*it)!=nuEvtCounter.end()){
01948         MAXMSG("NuAnalysis",Msg::kInfo,100)
01949           <<"   Found mc.index="<<*it<<endl;
01950       }
01951       else {
01952         MAXMSG("NuAnalysis",Msg::kInfo,30)
01953           <<"   NOT found mc.index="<<*it
01954           <<", evtCo size="<<nuEvtCounter.size()
01955           <<", setNu size="<<setNuInFid.size()
01956           <<endl;
01957         //put an entry in the map with a zero
01958         nuEvtCounter[*it]=0;
01959       }
01960     }
01961 
01962     //fill histo with number of reco evts per nu interaction
01963     typedef map<Int_t,Int_t>::iterator evCounterIt;
01964     for (evCounterIt it=nuEvtCounter.begin();
01965          it!=nuEvtCounter.end();++it){
01966       //get the mc object
01967       const NtpMCTruth& mc=
01968         *(dynamic_cast<NtpMCTruth*>(mcTca[it->first]));
01969 
01970       //cut out the nues
01971       if (!(mc.inu==-14 || mc.inu==14)) continue;
01972       
01973       hEvtsPerNu->Fill(it->second);
01974       if (mc.iaction==1){//CC
01975         hEvtsPerNuCC->Fill(it->second);
01976         hEvtsVsNuEnCC->Fill(mc.p4neu[3],it->second);
01977       }
01978       else if (mc.iaction==0){//NC
01979         hEvtsPerNuNC->Fill(it->second);
01980         hEvtsVsNuEnNC->Fill(mc.p4neu[3],it->second);
01981       }
01982     }
01983 
01987 
01988     //nuEvtCounterCC
01989     totalSnarlsCounter++;
01990     //check that a CC neutrino interaction occured in fid vol
01991     if (setNuInFidCC.size()<1) continue;
01992     ccInFidCounter++;
01993     //require that there is a reco'd fid vol event
01994     if (evtsInFidCC.size()<1) continue;
01995     recoEvtCounter++;
01996 
01997     //get the TCAs
01998     TClonesArray& trkTca=(*ntp.trk);
01999     //const Int_t numTrks=trkTca.GetEntriesFast();
02000     //TClonesArray& stpTca=(*ntp.stp);
02001     //const Int_t numStps=stpTca.GetEntriesFast();
02002 
02003     typedef set<Int_t>::iterator setEvtsInFidIt;
02004     for (setEvtsInFidIt it=evtsInFidCC.begin();
02005          it!=evtsInFidCC.end();++it) {
02006       const NtpTHEvent& thevt=
02007         *dynamic_cast<NtpTHEvent*>(thevtTca[*it]);
02008       const NtpSREvent& evt=
02009         *dynamic_cast<NtpSREvent*>(evtTca[*it]);
02010       const NtpMCTruth& mc=
02011         *(dynamic_cast<NtpMCTruth*>(mcTca[thevt.neumc]));
02012 
02013       //count the total number of neutrino interactions
02014       nuIntCounter++;
02015 
02016       //cut out the NCs
02017       if (mc.iaction==0) cout<<"Ahhh NC"<<endl;
02018       //cut out the nues
02019       if (!(mc.inu==-14 || mc.inu==14)) cout<<"Ahhh nue"<<endl;
02020       
02021       //find number of reco'd events for neutrino int 
02022       //associated with this event
02023       Int_t numEvtsPerNuInt=-1;
02024       map<Int_t,Int_t>::iterator countIt=
02025         nuEvtCounterCC.find(thevt.neumc);
02026       if (countIt!=nuEvtCounterCC.end()){
02027         numEvtsPerNuInt=countIt->second;
02028 
02029         //      nuIntEvtTimesCC[thevt.neumc].insert(time);
02030         Int_t times=nuIntEvtTimesCC.find(thevt.neumc)->second.size();
02031         if (times>1 || numEvtsPerNuInt>1){
02032           MAXMSG("NuAnalysis",Msg::kInfo,200)
02033             <<"numEvtsPerNuInt="<<numEvtsPerNuInt
02034             <<", times="<<times<<endl;
02035           
02036           typedef map<Int_t,multiset<Double_t> >::iterator nuIntIt;
02037           nuIntIt nuInt=nuIntEvtTimesCC.find(thevt.neumc);
02038           typedef multiset<Double_t>::iterator timeIt;
02039           timeIt beg=nuInt->second.begin();
02040           timeIt end=nuInt->second.end();
02041           timeIt lastTimeIt=nuInt->second.end();
02042           for (timeIt it=beg;it!=end;++it){
02043             MsgFormat ffmt("%9.9f");
02044             
02045             MAXMSG("NuAnalysis",Msg::kDebug,200)
02046               <<"  in multiset time="<<ffmt(*it)
02047               <<", evt.slc="<<evt.slc<<endl;
02048             if (lastTimeIt!=end){
02049               Double_t deltaTime=(*it)-(*lastTimeIt);
02050               MAXMSG("NuAnalysis",Msg::kDebug,200)
02051               <<"  deltaTime="<<ffmt(deltaTime)<<endl;
02052               hDeltaTime->Fill(deltaTime/(Munits::ns));         
02053             }
02054 
02055             //record the current it
02056             lastTimeIt=it;
02057           }
02058           //nuIntEvtTimesCC.find(thevt.neumc)->second.begin();
02059         }
02060         //if (countIt->second!=1) {
02061           //MAXMSG("NuAnalysis",Msg::kInfo,100)
02062           //<<"NOT using mc="<<thevt.neumc
02063           //<<" with reco'd events="<<countIt->second
02064           //<<endl;
02065           //continue;
02066         //}
02067       }
02068       else cout<<"Can't find mc="<<thevt.neumc<<endl;
02069       
02070       if (numEvtsPerNuInt>1) {
02071         const NtpSREvent& evt=
02072           *dynamic_cast<NtpSREvent*>(evtTca[*it]);
02073         const NtpMCTruth& mc=
02074           *(dynamic_cast<NtpMCTruth*>(mcTca[thevt.neumc]));
02075         MAXMSG("NuAnalysis",Msg::kDebug,200)
02076           <<"entry="<<entry<<", NuInt: mc="<<thevt.neumc
02077           <<", slc="<<evt.slc
02078           <<", evt="<<*it<<" ("<<numEvtsPerNuInt<<")"
02079           <<", ntrk="<<evt.ntrack
02080           <<", nshw="<<evt.nshower
02081           <<", Nu: E="<<mc.p4neu[3]
02082           <<", y="<<mc.y
02083           <<endl;
02084         
02085         //check that a delta T was found for this event
02086         if (deltaTs.find(evt.index)!=deltaTs.end()){
02087           hDeltaTg1->Fill(deltaTs[evt.index]/(Munits::ns));
02088           //only look at evts per slice for > 50 ns dT
02089           if (deltaTs[evt.index]/(Munits::ns)>50){
02090             hEvtsPerSlcg1T->Fill(evtsPerSlc[evt.slc]);
02091           }
02092         }
02093         else cout<<"No delta T for evt="<<evt.index<<endl;
02094         hEvtsPerSlcg1->Fill(evtsPerSlc[evt.slc]);
02095       }
02096       else {
02097         if (deltaTs.find(evt.index)!=deltaTs.end()){
02098           hDeltaT->Fill(deltaTs[evt.index]/(Munits::ns));
02099         }
02100         else cout<<"No delta T for evt="<<evt.index<<endl;
02101         hEvtsPerSlc->Fill(evtsPerSlc[evt.slc]);
02102       }
02103 
02104       //only analyse further events with 1 reco'd evt
02105       if (numEvtsPerNuInt!=1) continue;
02106       
02107       //get this far with only one reco'd evt per nu
02108       oneRecoEvtCounter++;
02109 
02110       //get the current reco'd event
02111       //const NtpSREvent& evt=
02112       //*dynamic_cast<NtpSREvent*>(evtTca[*it]);
02113 
02114       //fill number of tracks in the event
02115       hTrksPerEvt->Fill(evt.ntrack);
02116 
02118       //deal with the events that don't have a track
02120       if (evt.ntrack==0) {
02121         zeroTrackCounter++;
02122         if (mc.inu==14) {
02123           zeroTrackNuMuCounter++;
02124           hNuMuEnTrk0->Fill(mc.p4neu[3]);
02125           //don't fill this since you would not assume it NuMuBar
02126           //hNuMuBarLike->Fill(mc.p4neu[3]);
02127         }
02128         else if (mc.inu==-14) {
02129           zeroTrackNuMuBarCounter++;
02130           hNuMuBarEnTrk0->Fill(mc.p4neu[3]);
02131           //add NuMuBars with no track to NuMu-like sample
02132           //also assuming here that it is not ID'd as NC
02133           hNuMuLike->Fill(mc.p4neu[3]);
02134         }
02135       }
02136       if (evt.ntrack==1) {
02137         oneTrackCounter++;
02138       }
02139       if (evt.ntrack==2) {
02140         twoTrackCounter++;
02141         if (mc.inu==14) {
02142           twoTrackNuMuCounter++;
02143         }
02144         else if (mc.inu==-14) {
02145           twoTrackNuMuBarCounter++;
02146         }
02147       }
02148       if (evt.ntrack==3) {
02149         threeTrackCounter++;
02150       }
02151       if (evt.ntrack>3) {
02152         gr3TrackCounter++;
02153       }
02154 
02155       //work out the best track to use in the case that there is 
02156       //more than one
02157       Int_t trkToUse=0;
02158       Float_t trkLength=0;
02159       if (evt.ntrack>1){
02160         for(Int_t itrk=0;itrk<evt.ntrack;itrk++){
02161           const NtpSRTrack& trk=
02162             *dynamic_cast<NtpSRTrack*>(trkTca[evt.trk[itrk]]);
02163           
02164           MAXMSG("NuAnalysis",Msg::kDebug,200)
02165             <<"trk="<<itrk<<"/"<<evt.ntrack
02166             <<", pass="<<trk.fit.pass
02167             <<", ntrklike="<<trk.plane.ntrklike
02168             <<endl;
02169           
02170           if (!trk.fit.pass) continue;//trkToUse=0 here
02171           
02172           //select the longest trk (in track-like planes)
02173           if (trk.plane.ntrklike>trkLength) {
02174             trkLength=trk.plane.ntrklike;
02175             trkToUse=itrk;
02176           }
02177         }
02178         MAXMSG("NuAnalysis",Msg::kDebug,200)
02179           <<"selected trkToUse="<<trkToUse<<endl;
02180       }
02181 
02182       //simple event object to hold important quantities
02183       NuEvent nu;
02184       
02185       //get the run, snarl, etc info
02186       lib.ext.ExtractGeneralInfo(ntp,nu);
02187       //get info from the evt
02188       lib.ext.ExtractEvtInfo(evt,nu);
02189       //extract trk info (needed to get best track info)
02190       lib.ext.ExtractTrkInfo(ntp,evt,nu);
02191       //extract shw info
02192       lib.ext.ExtractShwInfo(ntp,evt,nu);
02193       
02195       //RECONSTRUCT the neutrino energy
02196       lib.reco.GetEvtEnergy(nu, false);
02197       
02198       Float_t recoEn=nu.energy;
02199       MAXMSG("NuAnalysis",Msg::kInfo,500)
02200         <<"Reco'd event energy="<<recoEn<<endl;
02201 
02202       //ensure there is a track in the event
02203       if (evt.ntrack<1) continue;
02204       
02205       //get the track in the event
02206       const NtpSRTrack& trk=
02207         *dynamic_cast<NtpSRTrack*>(trkTca[evt.trk[trkToUse]]);
02208 
02209       Int_t chargeMC=0;
02210       if (mc.p4mu1[3]<0) chargeMC=-1;
02211       else if (mc.p4mu1[3]>0) chargeMC=+1;
02212       
02213       Int_t charge=0;
02214       if (trk.momentum.qp<0) charge=-1;
02215       else if (trk.momentum.qp>0) charge=+1;
02216 
02217       //fill profiles
02218       if (mc.inu==14) {
02219         pNuMuFitPassVsEn->Fill(mc.p4neu[3],trk.fit.pass);      
02220       }
02221       else if (mc.inu==-14) {
02222         pNuMuBarFitPassVsEn->Fill(mc.p4neu[3],trk.fit.pass);      
02223       }
02224       
02225       if (trk.fit.pass){
02226         Float_t chi2PerNdof=-1;
02227         if (trk.fit.ndof) chi2PerNdof=trk.fit.chi2/trk.fit.ndof;
02228         Float_t sigqp_qp=0;
02229         if (trk.momentum.qp) sigqp_qp=trk.momentum.eqp/trk.momentum.qp;
02230 
02231         passFitCounter++;
02232         if (mc.inu==14) {
02233           pNuMuQEffVsEn->Fill(mc.p4neu[3],charge==chargeMC);
02234           if (charge!=chargeMC){
02235             badNuMuCounter++;
02236             hNuMuEnBadQ->Fill(mc.p4neu[3]);
02237             hNuMuRecoEnBadQ->Fill(recoEn);
02238             //if Q is wrong then think NuMu is NuMuBar-like
02239             hNuMuBarLike->Fill(mc.p4neu[3]);
02240             hNuMuChi2BadQ->Fill(chi2PerNdof);
02241             hNuMuSigqp_qpBadQ->Fill(sigqp_qp);
02242           }
02243           else{
02244             goodNuMuCounter++;
02245             hNuMuEnGoodQ->Fill(mc.p4neu[3]);
02246             hNuMuRecoEnGoodQ->Fill(recoEn);
02247             hNuMuChi2GoodQ->Fill(chi2PerNdof);
02248             hNuMuSigqp_qpGoodQ->Fill(sigqp_qp);
02249           }
02250         }
02251         else if (mc.inu==-14) {
02252           pNuMuBarQEffVsEn->Fill(mc.p4neu[3],charge==chargeMC);
02253           if (charge!=chargeMC){
02254             badNuMuBarCounter++;
02255             hNuMuBarEnBadQ->Fill(mc.p4neu[3]);
02256             hNuMuBarRecoEnBadQ->Fill(recoEn);
02257             //if Q is wrong then think NuMuBar is NuMu-like
02258             hNuMuLike->Fill(mc.p4neu[3]);
02259             hNuMuBarChi2BadQ->Fill(chi2PerNdof);
02260             hNuMuBarSigqp_qpBadQ->Fill(sigqp_qp);
02261           }
02262           else{
02263             goodNuMuBarCounter++;
02264             hNuMuBarEnGoodQ->Fill(mc.p4neu[3]);
02265             hNuMuBarRecoEnGoodQ->Fill(recoEn);
02266             hNuMuBarChi2GoodQ->Fill(chi2PerNdof);
02267             hNuMuBarSigqp_qpGoodQ->Fill(sigqp_qp);
02268           }
02269         }
02270       }
02271     }
02272   }//end of for                                       
02273   
02277 
02278   MSG("NuAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
02279 
02280   MSG("NuAnalysis",Msg::kInfo)
02281     <<endl<<"  *** Summary ***"<<endl
02282     <<"Total snarls             ="<<totalSnarlsCounter<<endl
02283     <<"Snarls w/ CC NuInt in Fid="<<ccInFidCounter<<endl
02284     <<"Snarls w/ reco'd fid evt ="<<recoEvtCounter<<endl
02285     <<endl
02286     <<"Total neutrino interactions="<<nuIntCounter<<endl
02287     <<"Only 1 reco'd evt per nu   ="<<oneRecoEvtCounter<<endl
02288     <<"Only 1 track               ="<<oneTrackCounter<<endl
02289     <<"Pass track fit             ="<<passFitCounter<<endl
02290     <<"  bad Q NuMu               ="<<badNuMuCounter<<endl
02291     <<"  good Q NuMu              ="<<goodNuMuCounter<<endl
02292     <<"  bad Q NuMuBar            ="<<badNuMuBarCounter<<endl
02293     <<"  good Q NuMuBar           ="<<goodNuMuBarCounter<<endl;
02294 
02295   MSG("NuAnalysis",Msg::kInfo)
02296     <<endl<<"  *** CC NuMu Event Track Breakdown ***"<<endl
02297     <<"zeroTrackCounter ="<<zeroTrackCounter<<endl
02298     <<"  NuMu   ="<<zeroTrackNuMuCounter<<endl
02299     <<"  NuMuBar="<<zeroTrackNuMuBarCounter<<endl
02300     <<"oneTrackCounter  ="<<oneTrackCounter<<endl
02301     <<"twoTrackCounter  ="<<twoTrackCounter<<endl
02302     <<"  NuMu   ="<<twoTrackNuMuCounter<<endl
02303     <<"  NuMuBar="<<twoTrackNuMuBarCounter<<endl
02304     <<"threeTrackCounter="<<threeTrackCounter<<endl
02305     <<"g3TrackCounter   ="<<gr3TrackCounter<<endl;
02306     
02307   MSG("NuAnalysis",Msg::kInfo) 
02308     <<" ** Finished EnergySpectMC method **"<<endl;
02309 }
02310 
02311 //......................................................................
02312 
02313 void NuAnalysis::N_1()
02314 {
02315   MSG("NuAnalysis",Msg::kInfo) 
02316     <<" ** Running N_1 method... **"<<endl;
02317 
02318   //open the output file for the histograms
02319   fOutFile=this->OpenFile(100,"NuMuBarN_1");
02320   
02321   TH1F* hDpID=new TH1F("hDpID","hDpID",4*160,-1.6,1.6);
02322   hDpID->GetXaxis()->SetTitle("PID (from MadDpID)");
02323   hDpID->GetXaxis()->CenterTitle();
02324   hDpID->GetYaxis()->SetTitle("");
02325   hDpID->GetYaxis()->CenterTitle();
02326   hDpID->SetFillColor(0);
02327   hDpID->SetLineColor(1);
02328   hDpID->SetLineWidth(3);
02329   //hDpID->SetBit(TH1::kCanRebin);
02330 
02331   TH1F* hDpIDN_1=new TH1F("hDpIDN_1","hDpIDN_1",4*160,-1.6,1.6);
02332   hDpIDN_1->GetXaxis()->SetTitle("PID (from MadDpID)");
02333   hDpIDN_1->GetXaxis()->CenterTitle();
02334   hDpIDN_1->GetYaxis()->SetTitle("");
02335   hDpIDN_1->GetYaxis()->CenterTitle();
02336   hDpIDN_1->SetFillColor(0);
02337   hDpIDN_1->SetLineColor(2);//red for N-1 cuts
02338   hDpIDN_1->SetLineWidth(3);
02339   //hDpIDN_1->SetBit(TH1::kCanRebin);
02340 
02341   TH1F* hDpIDN=new TH1F("hDpIDN","hDpIDN",4*160,-1.6,1.6);
02342   hDpIDN->GetXaxis()->SetTitle("PID (from MadDpID)");
02343   hDpIDN->GetXaxis()->CenterTitle();
02344   hDpIDN->GetYaxis()->SetTitle("");
02345   hDpIDN->GetYaxis()->CenterTitle();
02346   hDpIDN->SetFillColor(0);
02347   hDpIDN->SetLineColor(4);//blue for N cuts
02348   hDpIDN->SetLineWidth(3);
02349   //hDpIDN->SetBit(TH1::kCanRebin);
02350 
02351 
02352 
02353   TH1F* hSigmaqp_qp=new TH1F("hSigmaqp_qp","hSigmaqp_qp",200*160,-160,160);
02354   hSigmaqp_qp->GetXaxis()->SetTitle("Sigmaqp_qp");
02355   hSigmaqp_qp->GetXaxis()->CenterTitle();
02356   hSigmaqp_qp->GetYaxis()->SetTitle("");
02357   hSigmaqp_qp->GetYaxis()->CenterTitle();
02358   hSigmaqp_qp->SetFillColor(0);
02359   hSigmaqp_qp->SetLineColor(1);
02360   hSigmaqp_qp->SetLineWidth(3);
02361   //hSigmaqp_qp->SetBit(TH1::kCanRebin);
02362 
02363   TH1F* hSigmaqp_qpN_1=new TH1F("hSigmaqp_qpN_1","hSigmaqp_qpN_1",200*160,-160,160);
02364   hSigmaqp_qpN_1->GetXaxis()->SetTitle("Sigmaqp_qp");
02365   hSigmaqp_qpN_1->GetXaxis()->CenterTitle();
02366   hSigmaqp_qpN_1->GetYaxis()->SetTitle("");
02367   hSigmaqp_qpN_1->GetYaxis()->CenterTitle();
02368   hSigmaqp_qpN_1->SetFillColor(0);
02369   hSigmaqp_qpN_1->SetLineColor(2);//red for N-1 cuts
02370   hSigmaqp_qpN_1->SetLineWidth(3);
02371   //hSigmaqp_qpN_1->SetBit(TH1::kCanRebin);
02372 
02373   TH1F* hSigmaqp_qpN=new TH1F("hSigmaqp_qpN","hSigmaqp_qpN",200*160,-160,160);
02374   hSigmaqp_qpN->GetXaxis()->SetTitle("Sigmaqp_qp");
02375   hSigmaqp_qpN->GetXaxis()->CenterTitle();
02376   hSigmaqp_qpN->GetYaxis()->SetTitle("");
02377   hSigmaqp_qpN->GetYaxis()->CenterTitle();
02378   hSigmaqp_qpN->SetFillColor(0);
02379   hSigmaqp_qpN->SetLineColor(4);//blue for N cuts
02380   hSigmaqp_qpN->SetLineWidth(3);
02381   //hSigmaqp_qpN->SetBit(TH1::kCanRebin);
02382 
02383 
02384 
02385   TH1F* hChi2=new TH1F("hChi2","hChi2",10*176,-16,160);
02386   hChi2->GetXaxis()->SetTitle("Chi2");
02387   hChi2->GetXaxis()->CenterTitle();
02388   hChi2->GetYaxis()->SetTitle("");
02389   hChi2->GetYaxis()->CenterTitle();
02390   hChi2->SetFillColor(0);
02391   hChi2->SetLineColor(1);
02392   hChi2->SetLineWidth(3);
02393   //hChi2->SetBit(TH1::kCanRebin);
02394 
02395   TH1F* hChi2N_1=new TH1F("hChi2N_1","hChi2N_1",10*176,-16,160);
02396   hChi2N_1->GetXaxis()->SetTitle("Chi2");
02397   hChi2N_1->GetXaxis()->CenterTitle();
02398   hChi2N_1->GetYaxis()->SetTitle("");
02399   hChi2N_1->GetYaxis()->CenterTitle();
02400   hChi2N_1->SetFillColor(0);
02401   hChi2N_1->SetLineColor(2);//red for N-1 cuts
02402   hChi2N_1->SetLineWidth(3);
02403   //hChi2N_1->SetBit(TH1::kCanRebin);
02404 
02405   TH1F* hChi2N=new TH1F("hChi2N","hChi2N",10*176,-16,160);
02406   hChi2N->GetXaxis()->SetTitle("Chi2");
02407   hChi2N->GetXaxis()->CenterTitle();
02408   hChi2N->GetYaxis()->SetTitle("");
02409   hChi2N->GetYaxis()->CenterTitle();
02410   hChi2N->SetFillColor(0);
02411   hChi2N->SetLineColor(4);//blue for N cuts
02412   hChi2N->SetLineWidth(3);
02413   //hChi2N->SetBit(TH1::kCanRebin);
02414 
02415 
02416 
02417   TH1F* hFitProb=new TH1F("hFitProb","hFitProb",10*160,-1.6,1.6);
02418   hFitProb->GetXaxis()->SetTitle("FitProb");
02419   hFitProb->GetXaxis()->CenterTitle();
02420   hFitProb->GetYaxis()->SetTitle("");
02421   hFitProb->GetYaxis()->CenterTitle();
02422   hFitProb->SetFillColor(0);
02423   hFitProb->SetLineColor(1);
02424   hFitProb->SetLineWidth(3);
02425   //hFitProb->SetBit(TH1::kCanRebin);
02426 
02427   TH1F* hFitProbN_1=new TH1F("hFitProbN_1","hFitProbN_1",10*160,-1.6,1.6);
02428   hFitProbN_1->GetXaxis()->SetTitle("FitProb");
02429   hFitProbN_1->GetXaxis()->CenterTitle();
02430   hFitProbN_1->GetYaxis()->SetTitle("");
02431   hFitProbN_1->GetYaxis()->CenterTitle();
02432   hFitProbN_1->SetFillColor(0);
02433   hFitProbN_1->SetLineColor(2);//red for N-1 cuts
02434   hFitProbN_1->SetLineWidth(3);
02435   //hFitProbN_1->SetBit(TH1::kCanRebin);
02436 
02437   TH1F* hFitProbN=new TH1F("hFitProbN","hFitProbN",10*160,-1.6,1.6);
02438   hFitProbN->GetXaxis()->SetTitle("FitProb");
02439   hFitProbN->GetXaxis()->CenterTitle();
02440   hFitProbN->GetYaxis()->SetTitle("");
02441   hFitProbN->GetYaxis()->CenterTitle();
02442   hFitProbN->SetFillColor(0);
02443   hFitProbN->SetLineColor(4);//blue for N cuts
02444   hFitProbN->SetLineWidth(3);
02445   //hFitProbN->SetBit(TH1::kCanRebin);
02446 
02447 
02448 
02449   TH1F* hDeltaT=new TH1F("hDeltaT","hDeltaT",2010,-10,2000);
02450   hDeltaT->GetXaxis()->SetTitle("Delta T (ns)");
02451   hDeltaT->GetXaxis()->CenterTitle();
02452   hDeltaT->GetYaxis()->SetTitle("");
02453   hDeltaT->GetYaxis()->CenterTitle();
02454   hDeltaT->SetFillColor(0);
02455   hDeltaT->SetLineColor(1);
02456   hDeltaT->SetLineWidth(3);
02457   //hDeltaT->SetBit(TH1::kCanRebin);
02458 
02459   TH1F* hDeltaTN_1=new TH1F("hDeltaTN_1","hDeltaTN_1",2010,-10,2000);
02460   hDeltaTN_1->GetXaxis()->SetTitle("Delta T (ns)");
02461   hDeltaTN_1->GetXaxis()->CenterTitle();
02462   hDeltaTN_1->GetYaxis()->SetTitle("");
02463   hDeltaTN_1->GetYaxis()->CenterTitle();
02464   hDeltaTN_1->SetFillColor(0);
02465   hDeltaTN_1->SetLineColor(2);//red for N-1 cuts
02466   hDeltaTN_1->SetLineWidth(3);
02467   //hDeltaTN_1->SetBit(TH1::kCanRebin);
02468 
02469   TH1F* hDeltaTN=new TH1F("hDeltaTN","hDeltaTN",2010,-10,2000);
02470   hDeltaTN->GetXaxis()->SetTitle("Delta T (ns)");
02471   hDeltaTN->GetXaxis()->CenterTitle();
02472   hDeltaTN->GetYaxis()->SetTitle("");
02473   hDeltaTN->GetYaxis()->CenterTitle();
02474   hDeltaTN->SetFillColor(0);
02475   hDeltaTN->SetLineColor(4);//blue for N cuts
02476   hDeltaTN->SetLineWidth(3);
02477   //hDeltaTN->SetBit(TH1::kCanRebin);
02478 
02479 
02480 
02481   TH1F* hEvtsPerSlc=new TH1F("hEvtsPerSlc","hEvtsPerSlc",60,-10,50);
02482   hEvtsPerSlc->GetXaxis()->SetTitle("Evts Per Slc");
02483   hEvtsPerSlc->GetXaxis()->CenterTitle();
02484   hEvtsPerSlc->GetYaxis()->SetTitle("");
02485   hEvtsPerSlc->GetYaxis()->CenterTitle();
02486   hEvtsPerSlc->SetFillColor(0);
02487   hEvtsPerSlc->SetLineColor(1);
02488   hEvtsPerSlc->SetLineWidth(3);
02489   //hEvtsPerSlc->SetBit(TH1::kCanRebin);
02490 
02491   TH1F* hEvtsPerSlcN_1=new TH1F("hEvtsPerSlcN_1","hEvtsPerSlcN_1",
02492                                 60,-10,50);
02493   hEvtsPerSlcN_1->GetXaxis()->SetTitle("Evts Per Slc");
02494   hEvtsPerSlcN_1->GetXaxis()->CenterTitle();
02495   hEvtsPerSlcN_1->GetYaxis()->SetTitle("");
02496   hEvtsPerSlcN_1->GetYaxis()->CenterTitle();
02497   hEvtsPerSlcN_1->SetFillColor(0);
02498   hEvtsPerSlcN_1->SetLineColor(2);//red for N-1 cuts
02499   hEvtsPerSlcN_1->SetLineWidth(3);
02500   //hEvtsPerSlcN_1->SetBit(TH1::kCanRebin);
02501 
02502   TH1F* hEvtsPerSlcN=new TH1F("hEvtsPerSlcN","hEvtsPerSlcN",60,-10,50);
02503   hEvtsPerSlcN->GetXaxis()->SetTitle("Evts Per Slc");
02504   hEvtsPerSlcN->GetXaxis()->CenterTitle();
02505   hEvtsPerSlcN->GetYaxis()->SetTitle("");
02506   hEvtsPerSlcN->GetYaxis()->CenterTitle();
02507   hEvtsPerSlcN->SetFillColor(0);
02508   hEvtsPerSlcN->SetLineColor(4);//blue for N cuts
02509   hEvtsPerSlcN->SetLineWidth(3);
02510   //hEvtsPerSlcN->SetBit(TH1::kCanRebin);
02511 
02512   //classes to organise the code in to related functions
02513   const NuCuts cuts;
02514   //const NuGeneral general;
02515   const NuPlots plots;
02516   const NuReco reco;
02517   const NuExtraction ext;
02518   const NuBeam beam;
02519 
02520   NuConfig config;
02521   this->ExtractConfig(config);
02522 
02523   //create these on the heap so that they don't destruct
02524   // - on purpose to avoid a segv on destruction... nice coding!
02525   NuMadAnalysis& mad=*new NuMadAnalysis();
02526   MadDpID& dp=*new MadDpID();
02527   //BeamType::BeamType_t beamType=BeamType::kLE;
02528   BeamType::BeamType_t beamType=static_cast
02529     <BeamType::BeamType_t>(config.beamType);
02530 
02531   //maps to store evt info
02532   map<Int_t,Double_t> deltaTs;
02533   map<Int_t,Int_t> evtsPerSlc;
02534 
02535   Int_t goodSpillCounter=0;
02536   Int_t badSpillCounter=0;
02537   Float_t totalPot=0;
02538   Float_t totalPotBad=0;
02539   Int_t evtCounter=0;
02540   Int_t evtInFidVolCounter=0;
02541   Int_t evtWithTrkCounter=0;
02542   Int_t goodBestTrkCounter=0;
02543   Int_t goodTrkPassCounter=0;
02544   Int_t goodRecoEnCounter=0;
02545   Int_t goodUVDiffCounter=0;
02546   //Int_t goodFitSigQPCounter=0;
02547   //Int_t goodFitProbCounter=0;
02548   //Int_t goodFitChi2Counter=0;
02549   //Int_t goodPIDCounter=0;
02550   
02551   //get an instance of the code library
02552   const NuLibrary& lib=NuLibrary::Instance();
02553  
02557   
02558   this->InitialiseLoopVariables();  
02559   
02560   //for(Int_t entry=0;entry<10000;entry++){
02561   for(Int_t entry=0;entry<this->GetEntries();entry++){
02562       
02563     this->SetLoopVariables(entry);
02564       
02565     //get reference to NtpStRecord from base class
02566     const NtpStRecord& ntp=(*this->GetNtpStRecord());
02567 
02568     const RecCandHeader& rec=ntp.GetHeader();
02569     MAXMSG("NuAnalysis",Msg::kInfo,5)
02570       <<"Found: run="<<rec.GetRun()
02571       <<", subrun="<<rec.GetSubRun()
02572       <<", detector="<<rec.GetVldContext().GetDetector()
02573       <<", simFlag="<<rec.GetVldContext().GetSimFlag()
02574       <<endl;
02575 
02576     //write out the detector, simflag, etc
02577     plots.FillGeneralHistos(ntp);
02578 
02579     //simple event object to hold important quantities for snarl
02580     NuEvent nuSnarl;
02581     
02582     //get the run, snarl, etc info
02583     ext.ExtractGeneralInfo(ntp,nuSnarl);
02584 
02585     if (!beam.IsGoodSpillAndFillPot
02586         (this->GetNtpBDLiteRecord(),config,nuSnarl)) {
02587       badSpillCounter++;
02588       totalPotBad+=nuSnarl.pot;
02589       continue;
02590     }
02591     goodSpillCounter++;
02592     totalPot+=nuSnarl.pot;    
02593 
02594     dp.ChoosePDFs(rec.GetVldContext().GetDetector(),beamType);
02595     mad.SetEntry(&ntp);
02596 
02597     TClonesArray& evtTca=(*ntp.evt);
02598     const Int_t numEvts=evtTca.GetEntriesFast();
02599     
02600     //loop over the reconstructed events
02601     for (Int_t ievt=0;ievt<numEvts;ievt++){
02602       const NtpSREvent& evt=
02603         *dynamic_cast<NtpSREvent*>(evtTca[ievt]);
02604       evtCounter++;
02605 
02606       //simple event object to hold important quantities
02607       NuEvent nu;
02608       
02609       //get the run, snarl, etc info
02610       ext.ExtractGeneralInfo(ntp,nu);
02611       //get info from the evt
02612       lib.ext.ExtractEvtInfo(evt,nu);
02613       //extract trk info (needed to get best track info)
02614       lib.ext.ExtractTrkInfo(ntp,evt,nu);
02615       //extract shw info
02616       lib.ext.ExtractShwInfo(ntp,evt,nu);
02617             
02618       Bool_t isInFidVol=cuts.IsInFidVol(evt.vtx.x,evt.vtx.y,
02619                                         evt.vtx.z,
02620                                         evt.vtx.u,evt.vtx.v,
02621                                         0,0,
02622                                         nu.detector,nu.anaVersion,
02623                                         nu.releaseType,nu.simFlag);
02624 
02625       if (!isInFidVol) continue;
02626       evtInFidVolCounter++;
02627 
02628       nu.dpID=dp.CalcPID(&mad,ievt,0);
02629       MAXMSG("NuAnalysis",Msg::kDebug,50)
02630         <<"dpID="<<nu.dpID<<endl;
02631       
02632       //ensure there is a track in the event
02633       //if (evt.ntrack<1) continue;
02634       if (evt.ntrack!=1) continue;//require exactly 1 track
02635       evtWithTrkCounter++;
02636 
02637       //get the best track in the event
02638       Int_t bestTrack=lib.reco.GetBestTrack(nu);
02639       const NtpSRTrack* ptrk=lib.reco.GetTrackWithIndexX
02640         (ntp,evt,bestTrack-1);
02641       const NtpSRTrack& trk=*ptrk;
02642       goodBestTrkCounter++;
02643 
02644       //require a trk fit
02645       if (!trk.fit.pass) continue;
02646       goodTrkPassCounter++;
02647 
02648 
02650       //RECONSTRUCT the neutrino energy
02651       lib.reco.GetEvtEnergy(nu, false);
02652       goodRecoEnCounter++;
02653   
02654       if (!cuts.IsGoodUVVtx(nu)){
02655         continue;
02656       }
02657       goodUVDiffCounter++;
02658 
02659 
02661 
02662       Bool_t goodSigmaQP=cuts.IsGoodSigmaQP_QP(nu);
02663       Bool_t goodFitProb=cuts.IsGoodFitProb(nu);
02664       Bool_t goodChi2=cuts.IsGoodFitChi2PerNdof(nu);
02665       Bool_t goodDpID=cuts.IsGoodDpID(nu);
02666       
02667       //get the maps of evts' info
02668       deltaTs.clear();
02669       reco.GetEvtDeltaTs(ntp,deltaTs);
02670       evtsPerSlc.clear();
02671       reco.GetEvtsPerSlc(ntp,evtsPerSlc);      
02672       Bool_t goodDeltaT=deltaTs[ievt]>=50*Munits::ns;
02673       Bool_t goodEvtsPerSlc=evtsPerSlc[evt.slc]==1;
02674 
02675       //only fill histos for anti-neutrinos
02676       if (nu.sigqp_qp<0) continue;
02677 
02678       //fill the ALL histos
02679       hSigmaqp_qp->Fill(nu.sigqp_qp);
02680       hFitProb->Fill(nu.prob);
02681       hChi2->Fill(nu.chi2PerNdof);
02682       hDpID->Fill(nu.dpID);
02683       hDeltaT->Fill(deltaTs[ievt]/Munits::ns);
02684       hEvtsPerSlc->Fill(evtsPerSlc[evt.slc]);
02685       
02687       //fill the N-1 cuts plots
02689       if (true && 
02690           goodFitProb &&
02691           goodChi2 &&
02692           goodDpID &&
02693           goodDeltaT &&
02694           goodEvtsPerSlc) {
02695         hSigmaqp_qpN_1->Fill(nu.sigqp_qp);
02696       }
02697 
02698       if (goodSigmaQP && 
02699           true &&
02700           goodChi2 &&
02701           goodDpID &&
02702           goodDeltaT &&
02703           goodEvtsPerSlc){
02704         hFitProbN_1->Fill(nu.prob);
02705       }
02706       
02707       if (goodSigmaQP && 
02708           goodFitProb &&
02709           true &&
02710           goodDpID &&
02711           goodDeltaT &&
02712           goodEvtsPerSlc){
02713         hChi2N_1->Fill(nu.chi2PerNdof);
02714       }
02715       
02716       if (goodSigmaQP && 
02717           goodFitProb &&
02718           goodChi2 &&
02719           true &&
02720           goodDeltaT &&
02721           goodEvtsPerSlc){
02722         hDpIDN_1->Fill(nu.dpID);
02723       }
02724 
02725       if (goodSigmaQP && 
02726           goodFitProb &&
02727           goodChi2 &&
02728           goodDpID &&
02729           true &&
02730           goodEvtsPerSlc){
02731         hDeltaTN_1->Fill(deltaTs[ievt]/Munits::ns);
02732       }
02733 
02734       if (goodSigmaQP && 
02735           goodFitProb &&
02736           goodChi2 &&
02737           goodDpID &&
02738           goodDeltaT &&
02739           true){
02740         hEvtsPerSlcN_1->Fill(evtsPerSlc[evt.slc]);
02741       }
02742 
02744       //fill the N cuts plots
02746       if (goodSigmaQP && 
02747           goodFitProb &&
02748           goodChi2 &&
02749           goodDpID &&
02750           goodDeltaT &&
02751           goodEvtsPerSlc){
02752         hSigmaqp_qpN->Fill(nu.sigqp_qp);
02753         hFitProbN->Fill(nu.prob);
02754         hChi2N->Fill(nu.chi2PerNdof);
02755         hDpIDN->Fill(nu.dpID);
02756         hDeltaTN->Fill(deltaTs[ievt]/Munits::ns);
02757         hEvtsPerSlcN->Fill(evtsPerSlc[evt.slc]);
02758       }
02759     }
02760   }//end of for                                       
02761   
02765   
02766   MSG("NuAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
02767 
02768 
02769   MSG("NuAnalysis",Msg::kInfo) 
02770     <<" ** Finished N_1 method **"<<endl;
02771 }
02772 
02773 //......................................................................
02774 
02775 void NuAnalysis::OldDetermineBeamType(NuConfig& config)
02776 {
02777   //my old version
02778   //if (config.beamTypeSntp==0) config.beamType=BeamType::kUnknown;
02779   //else if (config.beamTypeSntp==1) config.beamType=BeamType::kLE;
02780   //else if (config.beamTypeSntp==2) config.beamType=BeamType::kME;
02781   //else if (config.beamTypeSntp==3) config.beamType=BeamType::kHE;
02782   //else if (config.beamTypeSntp==4) config.beamType=BeamType::kME;
02783   //else if (config.beamTypeSntp==5) config.beamType=BeamType::kHE;
02784 
02785   //this doesn't work because the new beam type is target+hornCur
02786   //my new version
02787   //note that the conventions package does not have true ME/HE
02788   //kME and kHE are ambiguiously used for pME and pHE
02789   //if (config.beamTypeSntp==0) config.beamType=BeamType::kUnknown;
02790   //else if (config.beamTypeSntp==1) config.beamType=
02791   //                             BeamType::kL010z185i;
02792   //else if (config.beamTypeSntp==2) config.beamType=BeamType::kME;
02793   //else if (config.beamTypeSntp==3) config.beamType=BeamType::kHE;
02794   //else if (config.beamTypeSntp==4) config.beamType=
02795   //BeamType::kL100z200i;
02796   //else if (config.beamTypeSntp==5) config.beamType=
02797   //                             BeamType::kL250z200i;
02798       
02799   //my new version
02800   //note: the beamTypeSntp ONLY refers to the target position
02801   //note: the conventions package does not have true ME/HE
02802   //kME and kHE are ambiguiously used for kpME and kpHE
02803   if (config.beamTypeSntp==0) {
02804     config.targetPos=-1;
02805     config.sTargetPos="UknownTargetPos";
02806   }
02807   else if (config.beamTypeSntp==1) {
02808     config.targetPos=10;
02809     config.sTargetPos="010";
02810   }
02811   else if (config.beamTypeSntp==2) {
02812     config.targetPos=100;
02813     config.sTargetPos="100";
02814   }
02815   else if (config.beamTypeSntp==3) {
02816     config.targetPos=250;
02817     config.sTargetPos="250";
02818   }
02819   else if (config.beamTypeSntp==4) {
02820     config.targetPos=100;
02821     config.sTargetPos="100";
02822   }
02823   else if (config.beamTypeSntp==5) {
02824     config.targetPos=250;
02825     config.sTargetPos="250";
02826   }
02827   else {
02828     MAXMSG("NuAnalysis",Msg::kError,10)
02829       <<"Ahhh, don't recognise beamTypeSntp="
02830       <<config.beamTypeSntp<<endl;
02831     assert(false);
02832   }
02833 
02834   //get the horn current
02835   //config.hornCurrent=ntpBD.horncur;
02836     
02837   //for LE hornCurrent=-    (-176?) 
02838   //for run 9235 (LE I believe) the horn current is -182.352
02839   //for ME hornCurrent=-191.13
02840   //for HE hornCurrent=-190.651
02841   //the actual horncurrents are out by ~10 kA compared to MC
02842   //the -2 is for safety
02843   //it's 1/3 of the way between the 15 kA separated runs we took
02844   //this may need to be changed if the horn current in data changes
02845   if (fabs(config.hornCurrent)>200-10-2){
02846     config.sHornCurrent="200";
02847   }
02848   else if (fabs(config.hornCurrent)>185-10-2) {
02849     config.sHornCurrent="185";
02850   }
02851   else if (fabs(config.hornCurrent)>170-10-2) {
02852     config.sHornCurrent="170";
02853   }
02854   else if (fabs(config.hornCurrent)>=0) {
02855     config.sHornCurrent="000";
02856   }
02857   else {
02858     MAXMSG("NuAnalysis",Msg::kError,10)
02859       <<"Ahh, no case for hornCurrent="<<config.hornCurrent<<endl;
02860   }
02861 
02862   //create the std MC naming scheme name
02863   config.sBeamType="L"+config.sTargetPos+config.sHornCurrent;
02864 
02865   //now make the config string
02866   //the -2 is for safety
02867   //if (config.beamType==BeamType::kHE){
02868   //config.sBeamType="L250200";
02869   //}
02870   //else if (config.beamType==BeamType::kME) {
02871   //config.sBeamType="L100200";
02872   //}
02873   //else if (config.beamType==BeamType::kLE) {
02874   //if (fabs(config.hornCurrent)>200-10-2){
02875   //  config.sBeamType="L010200";
02876   //}
02877   //else if (fabs(config.hornCurrent)>185-10-2) {
02878   //  config.sBeamType="L010185";
02879   //}
02880   //else if (fabs(config.hornCurrent)>170-10-2) {
02881   //  config.sBeamType="L010170";
02882   //}
02883   //else {
02884   //  MAXMSG("NuAnalysis",Msg::kError,10)
02885   //    <<"Ahh, don't know hornCurrent="<<config.hornCurrent<<endl;
02886   //}
02887   //}
02888       
02889   //temporary selection for the FD...
02890   //if (rec.GetVldContext().GetDetector()==Detector::kFar &&
02891   //config.beamType!=BeamType::kLE) continue;
02892 
02893   //get the beam type based on the info config already holds
02894   this->DetermineBeamType(config);
02895 }
02896 
02897 //......................................................................
02898 
02899 void NuAnalysis::DetermineBeamType(NuConfig& config) const
02900 {
02905 
02906   /*
02907 
02908     //from Conventions/BeamType.h
02909 
02910     kL000z200i, // true LE (data has a few POTs before target broke)
02911     kL010z185i, // normal "LE"-like running condition (pLE)
02912     kL050z200i,
02913     kL100z200i, // pseudo-medium (pME)
02914     kL200z200i,
02915     kL250z200i, // pseudo-high (pHE)
02916     kUser,
02917     kL010z000i, // "horns off"
02918     kL010z170i, // pLE low current test run
02919     kL010z200i, // pLE high current test run
02920     kL010z185i_lowintensity,
02921     kL150z200i, // pseudo-mediumhigh (pMHE)
02922     
02923     // retain old forms (new value go before this)
02924     kLE  = kL000z200i,
02925     k010 = kL010z185i,
02926     k050 = kL050z200i,
02927     k100 = kL100z200i,
02928     k200 = kL200z200i,
02929     k250 = kL250z200i,
02930     kME  = k100,  // obsolete (ambiguiously used for pME vs. true-ME)
02931     kHE  = k250,  // obsolete (ambiguiously used for pHE vs. true-HE)
02932     kEndOfList
02933   */
02934 
02935   //25/Feb/07 NEW: now using Conventions definitions which has
02936   //horn current built in to the beam type
02937   //don't have a case for "kL010z185i_lowintensity" yet
02938   
02939   //these are the BeamMonSpill definitions, which are different
02940   //to the MCReweight definitions
02941   //0=unknown,1=LE,2=ME,3=HE,4=psME,5=psHE mask=0x1c. LE-10 is LE
02942   if (config.sTargetPos=="000") {
02943     MAXMSG("NuAnalysis",Msg::kInfo,5)
02944       <<"Identified case for sTargetPos="<<config.sTargetPos
02945       <<", now searching for horn current case..."<<endl;
02946     if (config.sHornCurrent=="200") {
02947       config.beamType=BeamType::kL000z200i;
02948     }
02949     else {
02950       MAXMSG("NuAnalysis",Msg::kError,5)
02951         <<"Ahhh, no horn current case for hornCurrent="
02952         <<config.sHornCurrent<<" for sTargetPos="<<config.sTargetPos
02953         <<endl;
02954       config.beamType=BeamType::kUnknown;
02955       assert(false);
02956     }
02957   }
02958   else if (config.sTargetPos=="010") {
02959     MAXMSG("NuAnalysis",Msg::kInfo,5)
02960       <<"Identified case for sTargetPos="<<config.sTargetPos
02961       <<", now searching for horn current..."<<endl;
02962     if (config.sHornCurrent=="185") {
02963       if(config.hornIsReverse)
02964         config.beamType=BeamType::kL010z185i_rev;
02965       else
02966         config.beamType=BeamType::kL010z185i;
02967     }
02968     else if (config.sHornCurrent=="200") {
02969       config.beamType=BeamType::kL010z200i;
02970     }
02971     else if (config.sHornCurrent=="170") {
02972       config.beamType=BeamType::kL010z170i;
02973     }
02974     else if (config.sHornCurrent=="000") {
02975       config.beamType=BeamType::kL010z000i;
02976     }
02977     else {
02978       MAXMSG("NuAnalysis",Msg::kError,5)
02979         <<"Ahhh, no horn current case for hornCurrent="
02980         <<config.sHornCurrent<<" for sTargetPos="<<config.sTargetPos
02981         <<endl;
02982       config.beamType=BeamType::kUnknown;
02983       assert(false);
02984     }
02985   }
02986   else if (config.sTargetPos=="50") {
02987     MAXMSG("NuAnalysis",Msg::kInfo,5)
02988       <<"Identified case for sTargetPos="<<config.sTargetPos
02989       <<", now searching for horn current..."<<endl;
02990     if (config.sHornCurrent=="200") {
02991       config.beamType=BeamType::kL050z200i;
02992     }
02993     else {
02994       MAXMSG("NuAnalysis",Msg::kError,5)
02995         <<"Ahhh, no horn current case for hornCurrent="
02996         <<config.sHornCurrent<<" for sTargetPos="<<config.sTargetPos
02997         <<endl;
02998       config.beamType=BeamType::kUnknown;
02999       assert(false);
03000     }
03001   }
03002   else if (config.sTargetPos=="100") {
03003     MAXMSG("NuAnalysis",Msg::kInfo,5)
03004       <<"Identified case for sTargetPos="<<config.sTargetPos
03005       <<", now searching for horn current..."<<endl;
03006     if (config.sHornCurrent=="200") {
03007       config.beamType=BeamType::kL100z200i;
03008     }
03009     else {
03010       MAXMSG("NuAnalysis",Msg::kError,5)
03011         <<"Ahhh, no horn current case for hornCurrent="
03012         <<config.sHornCurrent<<" for sTargetPos="<<config.sTargetPos
03013         <<endl;
03014       config.beamType=BeamType::kUnknown;
03015       assert(false);
03016     }
03017   }
03018   else if (config.sTargetPos=="150") {
03019     MAXMSG("NuAnalysis",Msg::kInfo,5)
03020       <<"Identified case for sTargetPos="<<config.sTargetPos
03021       <<", now searching for horn current..."<<endl;
03022     if (config.sHornCurrent=="200") {
03023       config.beamType=BeamType::kL150z200i;
03024     }
03025     else {
03026       MAXMSG("NuAnalysis",Msg::kError,5)
03027         <<"Ahhh, no horn current case for hornCurrent="
03028         <<config.sHornCurrent<<" for sTargetPos="<<config.sTargetPos
03029         <<endl;
03030       config.beamType=BeamType::kUnknown;
03031       assert(false);
03032     }
03033   }
03034   else if (config.sTargetPos=="200") {
03035     MAXMSG("NuAnalysis",Msg::kInfo,5)
03036       <<"Identified case for sTargetPos="<<config.sTargetPos
03037       <<", now searching for horn current..."<<endl;
03038     if (config.sHornCurrent=="200") {
03039       config.beamType=BeamType::kL200z200i;
03040     }
03041     else {
03042       MAXMSG("NuAnalysis",Msg::kError,5)
03043         <<"Ahhh, no horn current case for hornCurrent="
03044         <<config.sHornCurrent<<" for sTargetPos="<<config.sTargetPos
03045         <<endl;
03046       config.beamType=BeamType::kUnknown;
03047       assert(false);
03048     }
03049   }
03050   else if (config.sTargetPos=="250") {
03051     MAXMSG("NuAnalysis",Msg::kInfo,5)
03052       <<"Identified case for sTargetPos="<<config.sTargetPos
03053       <<", now searching for horn current..."<<endl;
03054     if (config.sHornCurrent=="200") {
03055       config.beamType=BeamType::kL250z200i;
03056     }
03057     else {
03058       MAXMSG("NuAnalysis",Msg::kError,5)
03059         <<"Ahhh, no horn current case for hornCurrent="
03060         <<config.sHornCurrent<<" for sTargetPos="<<config.sTargetPos
03061         <<endl;
03062       config.beamType=BeamType::kUnknown;
03063       assert(false);
03064     }
03065   }
03066   else {
03067     config.beamType=BeamType::kUnknown; 
03068     MAXMSG("NuAnalysis",Msg::kError,10)
03069       <<"Ahhhhh, target position="<<config.sTargetPos
03070       <<" case not known..."<<endl;
03071     //assert(false);
03072   }
03073 } 
03074 
03075 //......................................................................
03076 
03077 void NuAnalysis::ExtractConfig(NuConfig& config)
03078 {
03080 
03081   this->ExtractConfig(this->GetNtpStRecord(),
03082                       this->GetNtpBDLiteRecord(),config);
03083 }
03084 
03085 //......................................................................
03086 
03087 Bool_t NuAnalysis::ExtractConfig(const NtpStRecord* pntp,
03088                                  const NtpBDLiteRecord* pntpBD,
03089                                  NuConfig& config) const
03090 {
03091   //get reference to NtpStRecord
03092   const NtpStRecord& ntp=*pntp;
03093   
03094   const RecCandHeader& rec=ntp.GetHeader();
03095   MAXMSG("NuAnalysis",Msg::kInfo,5)
03096     <<"ExtractConfig: run="<<rec.GetRun()
03097     <<", subrun="<<rec.GetSubRun()
03098     <<", detector="<<ntp.GetVldContext()->GetDetector()
03099     <<", simFlag="<<ntp.GetVldContext()->GetSimFlag()
03100     <<endl;
03101     
03102   //set the variables
03103   config.run=rec.GetRun();
03104   config.subRun=rec.GetSubRun();
03105   config.snarl=rec.GetSnarl();
03106   config.timeSec=ntp.GetVldContext()->GetTimeStamp().GetSec();
03107   config.timeNanoSec=ntp.GetVldContext()->GetTimeStamp().GetNanoSec();
03108   config.detector=ntp.GetVldContext()->GetDetector();
03109   config.simFlag=ntp.GetVldContext()->GetSimFlag();
03110   config.trigSrc=rec.GetTrigSrc();
03111   
03112   //get the reco and MC version
03113   /*
03114   MAXMSG("NuAnalysis",Msg::kInfo,50)
03115     <<"Using ntp.GetTitle()="<<ntp.GetTitle()<<endl
03116     <<"Using ntp.mchdr.geninfo.codename="
03117     <<ntp.mchdr.geninfo.codename<<endl;
03118     
03119   //get the release type
03120   config.releaseType=ReleaseType::MakeReleaseType
03121     (ntp.GetTitle(),ntp.mchdr.geninfo.codename);
03122   */
03123   config.releaseType=ntp.GetRelease();
03124    
03125   // Check for obviously wrong releaseType
03126   if ( ReleaseType::IsBirch(config.releaseType)) {
03127     int oldrel = config.releaseType;
03128     config.releaseType -= ReleaseType::kBirch;
03129     config.releaseType += ReleaseType::kDogwood;
03130 
03131     MAXMSG("NuAnalysis",Msg::kInfo, 5) << "Changing the release type from " 
03132     << NuUtilities::PrintRelease(oldrel) << " to "
03133     << NuUtilities::PrintRelease(config.releaseType) << endl;
03134   }
03135   
03136   
03137   //extract the mcVersion from the releaseType
03138   config.mcVersion=ReleaseType::GetMCInfo(config.releaseType);
03139   //extract the recoVersion from the releaseType
03140   config.recoVersion=ReleaseType::GetRecoInfo(config.releaseType);
03141 
03142 
03143     
03144   MAXMSG("NuAnalysis",Msg::kInfo,50)
03145     <<"Extracted:"<<endl
03146     <<"  ReleaseType = " <<NuUtilities::PrintRelease(config.releaseType) << endl
03147     <<"  mcVersion   = " <<NuUtilities::PrintRelease(config.mcVersion) << endl
03148     <<"  recoVersion = " <<NuUtilities::PrintRelease(config.recoVersion) << endl;
03149   
03150     
03152   //check if NtpBDLiteRecord exists in the data case
03154   if (ntp.GetVldContext()->GetSimFlag()==SimFlag::kData && 
03155       (!pntpBD || config.overrideBeamDataConfigExtraction)) {
03156     if (!pntpBD) {
03157       MSG("NuAnalysis",Msg::kInfo)
03158         <<"ExtractConfig: no NtpBDLiteRecord available"
03159         <<", making up settings..."<<endl;
03160     }
03161     else if (config.overrideBeamDataConfigExtraction) {
03162       MSG("NuAnalysis",Msg::kInfo)
03163         <<"ExtractConfig: overriding use of Beam Data"
03164         <<" to extract config, making up settings..."<<endl;
03165     }
03166     config.beamType=BeamType::kL010z185i;
03167     config.hornCurrent=-185;
03168     string btAsString=BeamType::AsString
03169       (static_cast<BeamType::BeamType_t>(config.beamType));
03170     config.sTargetPos=btAsString.substr(1,3);
03171     config.targetPos=-1.*atoi(config.sTargetPos.c_str());
03172     config.sHornCurrent=btAsString.substr(5,7);      
03173     //create the std MC naming scheme name
03174     config.sBeamType="L"+config.sTargetPos+config.sHornCurrent;      
03175     //the beammonspill beamType is not same as Conventions one
03176     config.beamTypeSntp=1;
03177   }
03179   //check if DATA
03181   else if (ntp.GetVldContext()->GetSimFlag()==SimFlag::kData){
03182     MSG("NuAnalysis",Msg::kInfo)
03183       <<"ExtractConfig: running on DATA..."<<endl;
03184     const NtpBDLiteRecord& ntpBD=*pntpBD;
03185     
03186     //static BeamMonSpill spill;
03187     //static BMSpillAna bmsa;
03188     BeamMonSpill spill;
03189     BMSpillAna bmsa;
03190     //bmsa.Print();
03191 
03192     //tell it to use the database defined values of the cuts
03193     //doesn't actually load the database until you ask SelectSpill
03194     bmsa.UseDatabaseCuts();
03195       
03196     //give it the spill
03197     bmsa.SetSpill(ntpBD,spill);
03198       
03199     MAXMSG("NuAnalysis",Msg::kInfo,10)
03200       <<"ExtractConfig: after SetSpill & UseDatabaseCuts:"<<endl;
03201     bmsa.Print();
03202     cout<<endl;
03203 
03204     //check if a good spill
03205     if (!bmsa.SelectSpill()) {
03206       Double_t xmean=0;
03207       Double_t ymean=0;
03208       Double_t xrms=0;
03209       Double_t yrms=0;
03210       spill.BpmAtTarget(xmean,ymean,xrms,yrms);
03211       Int_t targetIn=spill.GetStatusBits().target_in;
03212       
03213       MSG("NuExtraction",Msg::kWarning)
03214       << "ExtractConfig: BAD SPILL:" << endl
03215       << " > Time diffrence (s):             " << ntpBD.GetHeader().GetTimeDiffStreamSpill() << endl
03216       << " > Spill intensity (1e12 pot):     " << ntpBD.trtgtd << endl
03217       << " > Horn Current (kA):              " << ntpBD.horncur << endl
03218       << " > Target in/out:                  " << targetIn << endl
03219       << " > fBeamType:                      " << BeamType::AsString(static_cast<BeamType::BeamType_t>(spill.BeamType())) <<" ("<<spill.BeamType()<<")"<<endl
03220       << " > Horizontal beam position (mm):  " << xmean << endl
03221       << " > Vertical beam position (mm):    " << ymean << endl
03222       << " > Horizontal beam width a (mm):   " << ntpBD.bwidx << endl
03223       << " > Vertical beam width a (mm):     " << ntpBD.bwidy << endl;
03224       MSG("NuBeam",Msg::kWarning)
03225         <<endl<<endl
03226         <<"Occasionally the first spill is bad so have to skip to next"
03227         <<" snarl in order to ExtractConfig... return..."
03228         <<endl<<endl<<endl;
03229       return false;
03230     }
03231 
03232     //get the beam type directly from the BeamMomSpill
03233     //the time of various data taking is hard coded
03234     //so you can differentiate le000 from le010 and le150 from le100
03235     config.beamType=spill.BeamType();
03236       
03237     //get the horn current
03238     config.hornCurrent=ntpBD.horncur;
03239       
03240     string btAsString=BeamType::AsString
03241       (static_cast<BeamType::BeamType_t>(config.beamType));
03242     //L000z200i
03243     config.sTargetPos=btAsString.substr(1,3);
03244     config.targetPos=-1.*atoi(config.sTargetPos.c_str());
03245     config.sHornCurrent=btAsString.substr(5,7);
03246       
03247     //create the std MC naming scheme name
03248     config.sBeamType="L"+config.sTargetPos+config.sHornCurrent;
03249 
03250     //the beammonspill beamType is not the same as the Conventions one
03251     //these are the beammonspill ones:
03252     //0=unknown,1=LE,2=ME,3=HE,4=psME,5=psHE mask=0x1c. LE-10 is LE.
03253     config.beamTypeSntp=spill.GetStatusBits().beam_type;      
03254   }
03256   //check if MC
03258   else if (ntp.GetVldContext()->GetSimFlag()==SimFlag::kMC){  
03259     MSG("NuAnalysis",Msg::kInfo)
03260       <<"ExtractConfig: running on MC..."<<endl;
03261     //get the filename
03262     TString sFileName="n13021160_0000_L010185.sntp.R1_18_2.root";
03263     //check if the ntp was from mom or directly accessed
03264     if (this->GetNtpStRecord()) {//direct
03265       sFileName=this->GetFirstFileName().c_str();
03266     }
03267     else {//mom
03268       sFileName=this->GetInputFileName().c_str();
03269     }
03270     
03271     Int_t lastSlash=sFileName.Last('/');
03272     sFileName.Remove(0,lastSlash+1);
03273     MAXMSG("NuAnalysis",Msg::kInfo,5)
03274       <<"Extracting MC beam info from run filename="<<sFileName<<endl;
03275 
03276     // Known filename types
03277     // Cedar-n13010100_0000_L010185_PDtest03.root
03278     // n13021160_0000_L010185.sntp.R1_18_2.root
03279     // n11011020_0000_L010185N_D00.sntp.cedar_phy.root
03280     // n13037038_0027_L250200N_D04_i194.sntp.dogwood1.root
03281     // n13035001_0003_L150200N_D07_r2.sntp.dogwood1.root
03282     // n13047001_0000_L010185R_D04.sntp.dogwood1.0.root
03283     // n13037001_0000_L010185N_D04.reroot.root
03284     // n13037009_0029_L010185N_D04_charm.reroot.root
03285     // n13035001_0000_L010170N_D07_r1.reroot.root
03286     // n13035001_0000_L010185N_D07_r1i999.reroot.root
03287     
03288     TRegexp rbeam      = "^[LMH][0-9][0-9][0-9][0-9][0-9][0-9][RN]?$";
03289     TRegexp rmc        = "^D[0-9]+$";
03290     TRegexp rboth      = "^r[1-4]i[0-9]+$";
03291     TRegexp rintensity = "^i[0-9]+$";
03292     TRegexp rrun       = "^r[1-4]$";
03293 
03294     
03295     //check for preDiakon name
03296     sFileName.ReplaceAll("Cedar-","");
03297     
03298     TObjArray* part1 = sFileName.Tokenize(".");
03299     TString info = ((TObjString*)part1->At(0))->GetString();
03300     TObjArray* part2 = info.Tokenize("_");
03301     
03302     config.sTargetPos = "010";
03303     config.sHornCurrent = "185";
03304     config.runPeriod = 0; // Unspecified Period
03305     config.intensity = 0; // Average intensity
03306     config.hornIsReverse = false;
03307     int dver = 0; // Daikon version
03308     
03309     for (int j = 0; j < part2->GetEntries(); j++) {
03310       TString temp = ((TObjString*)part2->At(j))->GetString();
03311 
03312       // Look for Beam type ex. L010185N
03313       if (temp.Contains(rbeam)) {
03314         config.sBeamType = temp;
03315         config.sTargetPos   = (temp(1,3)+"").Data();
03316         config.sHornCurrent = (temp(4,3)+"").Data();
03317         if (temp.EndsWith("R")) {
03318           config.hornIsReverse = true;
03319         }
03320         MAXMSG("NuAnalysis",Msg::kInfo,1) << "Found beam " << temp << " in name" << endl;
03321         
03322       }
03323       // Run Period + Intensity rNiXYZ
03324       else if (temp.Contains(rboth)) {
03325         TString tempR = temp(1,1);
03326         config.runPeriod = tempR.Atoi();
03327         TString tempI = temp(3,3);
03328         config.intensity = tempI.Atoi();
03329         MAXMSG("NuAnalysis",Msg::kInfo,1) << "Found run and intensity " << temp << " in name" << endl;
03330       }
03331       // Look for Run Period ex. rN
03332       else if (temp.Contains(rrun)) {
03333         temp.Remove(0,1);
03334         config.runPeriod = temp.Atoi();
03335         MAXMSG("NuAnalysis",Msg::kInfo,1) << "Found run " << temp << " in name" << endl;
03336       }              
03337       // Look for intensity ex. iXYZ
03338       else if (temp.Contains(rintensity)) {
03339         temp.Remove(0,1);
03340         config.intensity = temp.Atoi();
03341         MAXMSG("NuAnalysis",Msg::kInfo,1) << "Found intensity " << temp << " in name" << endl;
03342       }              
03343       // Look for Daikon version - not needed
03344       else if (temp.Contains(rmc)) {
03345         temp.Remove(0,1);
03346         dver = temp.Atoi();
03347         MAXMSG("NuAnalysis",Msg::kInfo,1) << "Found Daikon v. " << temp << " in name" << endl;
03348       }
03349       // Look for intensity - not needed
03350     }
03351     delete part2;
03352     delete part1;
03353        
03354     config.targetPos=-1.*atoi(config.sTargetPos.c_str());
03355     config.hornCurrent=-1.*atoi(config.sHornCurrent.c_str());
03356     
03357     if (config.hornIsReverse) config.hornCurrent *= -1;
03358     
03359     if (dver >= 7) {
03360       if (config.runPeriod <= 0) {
03361         MAXMSG("NuAnalysis",Msg::kWarning,5) << "Daikon07 found but no run period!" << endl;
03362       }
03363       if (config.runPeriod == 4 != config.hornIsReverse) {
03364         MAXMSG("NuAnalysis",Msg::kWarning,5) << "Daikon07 Run4 found with forward field" << endl;
03365       }
03366     }
03367     
03368     MAXMSG("NuAnalysis",Msg::kInfo,5)
03369         <<"Extracted from the filename: sTargetPos="<<config.sTargetPos
03370         <<", targetPos="<< config.targetPos
03371         <<", sHornCurrent="<<config.sHornCurrent
03372         <<", hornCurrent="<<config.hornCurrent
03373         <<", runPeriod="<<config.runPeriod
03374         <<", mcVersion="<<config.mcVersion
03375         <<", intensity="<<config.intensity
03376         <<", hornIsReverse="<<config.hornIsReverse
03377         << endl;
03378     
03379     //get the beam type based on the info config already holds
03380     this->DetermineBeamType(config);
03381   }
03382   
03383   // Extract run period for data from VldContext
03384   if (ntp.GetVldContext()->GetSimFlag()==SimFlag::kData){
03385     VldTimeStamp* vtsRunIEnd = new VldTimeStamp(2006,4,1,0,0,0);
03386     VldTimeStamp* vtsRunIIEnd = new VldTimeStamp(2007,8,1,0,0,0);
03387     VldTimeStamp* vtsRunIIIEnd = new VldTimeStamp(2009,8,1,0,0,0);
03388     VldTimeStamp ts = ntp.GetVldContext()->GetTimeStamp();
03389     
03390     if(ts.GetDate()<vtsRunIEnd->GetDate()) config.runPeriod = 1;
03391     else if(ts.GetDate()<vtsRunIIEnd->GetDate()) config.runPeriod = 2;
03392     else if(ts.GetDate()<vtsRunIIIEnd->GetDate()) config.runPeriod = 3;
03393     else config.runPeriod = 4;
03394   }
03395 
03396   MSG("NuAnalysis",Msg::kInfo)
03397     <<"ExtractConfig: final config is beamType="
03398     <<BeamType::AsString(static_cast<BeamType::BeamType_t>
03399                          (config.beamType))
03400     <<" ("<<config.beamType<<")"
03401     <<", btSntp="<<config.beamTypeSntp
03402     <<endl
03403     <<"               sHornCurrent="<<config.sHornCurrent
03404     <<" ("<<config.hornCurrent<<")"
03405     <<", sTargetPos="<<config.sTargetPos
03406     <<" ("<<config.targetPos<<")"
03407     <<", sBeamType="<<config.sBeamType
03408     <<", runPeriod="<<config.runPeriod
03409     <<endl;
03410 
03411   //the beamTypeSntp is only present for data when it is
03412   //obtained from the ntuples
03413   //so only print for data
03414   //if (ntp.GetVldContext().GetSimFlag()==SimFlag::kData){
03415   //MAXMSG("NuAnalysis",Msg::kInfo,5)
03416   //<<"Converting beamTypeSntp to New Conventions gives "
03417   //<<BeamType::AsString(static_cast<BeamType::BeamType_t>
03418   //                 (BeamType::
03419   //                  FromBeamMon(config.beamTypeSntp)))
03420   //<<" ("<<BeamType::FromBeamMon(config.beamTypeSntp)<<")"
03421   //<<endl
03422   //<<"  FromZarko="<<BeamType::FromZarko(config.beamType)
03423   //<<endl
03425   //<<endl;
03426   //}
03427   return true;
03428 }
03429 
03430 //......................................................................
03431 
03432 void NuAnalysis::NuMuBarAppearance()
03433 {
03434   MSG("NuAnalysis",Msg::kInfo) 
03435     <<" ** Running NuMuBarAppearance method... **"<<endl;
03436   
03437   NuConfig config;
03438   this->ExtractConfig(config);
03439 
03440   //open the output file for the histograms
03441   string sFilePrefix="NMBApp"+config.sBeamType;
03442   fOutFile=this->OpenFile(config,sFilePrefix.c_str());
03443 
03444   TH1F* hRecoEnNMBFull=new TH1F("hRecoEnNMBFull","hRecoEnNMBFull",
03445                                 4*352,-32,320);
03446   hRecoEnNMBFull->GetXaxis()->SetTitle("True Energy (GeV)");
03447   hRecoEnNMBFull->GetXaxis()->CenterTitle();
03448   hRecoEnNMBFull->GetYaxis()->SetTitle("");
03449   hRecoEnNMBFull->GetYaxis()->CenterTitle();
03450   //hRecoEnNMBFull->SetBit(TH1::kCanRebin);
03451   hRecoEnNMBFull->Sumw2();
03452 
03453   TH1F* hRecoEnNMFull=new TH1F("hRecoEnNMFull","hRecoEnNMFull",
03454                                 4*352,-32,320);
03455   hRecoEnNMFull->GetXaxis()->SetTitle("True Energy (GeV)");
03456   hRecoEnNMFull->GetXaxis()->CenterTitle();
03457   hRecoEnNMFull->GetYaxis()->SetTitle("");
03458   hRecoEnNMFull->GetYaxis()->CenterTitle();
03459   //hRecoEnNMFull->SetBit(TH1::kCanRebin);
03460   hRecoEnNMFull->Sumw2();
03461 
03462   TH1F* hRecoEnNMBOsc=new TH1F("hRecoEnNMBOsc","hRecoEnNMBOsc",
03463                                 4*352,-32,320);
03464   hRecoEnNMBOsc->GetXaxis()->SetTitle("True Energy (GeV)");
03465   hRecoEnNMBOsc->GetXaxis()->CenterTitle();
03466   hRecoEnNMBOsc->GetYaxis()->SetTitle("");
03467   hRecoEnNMBOsc->GetYaxis()->CenterTitle();
03468   //hRecoEnNMBOsc->SetBit(TH1::kCanRebin);
03469   hRecoEnNMBOsc->Sumw2();
03470 
03471   TH1F* hRecoEnNMOsc=new TH1F("hRecoEnNMOsc","hRecoEnNMOsc",
03472                                 4*352,-32,320);
03473   hRecoEnNMOsc->GetXaxis()->SetTitle("True Energy (GeV)");
03474   hRecoEnNMOsc->GetXaxis()->CenterTitle();
03475   hRecoEnNMOsc->GetYaxis()->SetTitle("");
03476   hRecoEnNMOsc->GetYaxis()->CenterTitle();
03477   //hRecoEnNMOsc->SetBit(TH1::kCanRebin);
03478   hRecoEnNMOsc->Sumw2();
03479 
03480   //vectors
03481   Int_t entries=static_cast<Int_t>(this->GetEntries());
03482   Int_t startTimeSecs=2000000000;//2 billion
03483   Int_t endTimeSecs=1;
03484   vector<Double_t> vPot;
03485   vPot.reserve(entries);
03486   vector<Double_t> vTime;
03487   vTime.reserve(entries);
03488   vector<Double_t> vPotBad;
03489   vPotBad.reserve(entries/10);
03490   vector<Double_t> vTimeBad;
03491   vTimeBad.reserve(entries/10);
03492   
03493   vector<Double_t> vTimeNuMuEvt;
03494   vTimeNuMuEvt.reserve(entries/5);
03495   vector<Double_t> vTimeNuMuBarEvt;
03496   vTimeNuMuBarEvt.reserve(entries/5);
03497  
03498   //maps to store evt info
03499   map<Int_t,Double_t> deltaTs;
03500   map<Int_t,Int_t> evtsPerSlc;
03501 
03502   //counters
03503   Int_t goodSpillCounter=0;
03504   Int_t badSpillCounter=0;
03505   Float_t totalPot=0;
03506   Float_t totalPotBad=0;
03507   Int_t evtCounter=0;
03508   Int_t evtNotlitime=0;
03509   Int_t evtNotIsLI=0;
03510   Int_t evtInFidVolCounter=0;
03511   Int_t evtWithTrkCounter=0;
03512   Int_t goodBestTrkCounter=0;
03513   Int_t goodTrkPassCounter=0;
03514   Int_t goodRecoEnCounter=0;
03515   Int_t goodUVDiffCounter=0;
03516   Int_t trkInFidVolCounter=0;
03517   Int_t goodFitSigQPCounter=0;
03518   Int_t goodFitProbCounter=0;
03519   Int_t goodFitChi2Counter=0;
03520   Int_t goodDeltaTCounter=0;
03521   Int_t goodEvtsPerSlcCounter=0; 
03522   Int_t goodPIDCounter=0;
03523   Int_t goodBeyondTrkEndCounter=0;
03524   Int_t goodShwFractCounter=0;
03525   Int_t nuNQCounter=0;
03526   Int_t nuPQCounter=0;
03527   
03528   //string sTxtFilePrefix="nmb"+config.sBeamType;
03529   //ofstream& nmbTxt=*(this->OpenTxtFile(config,
03530   //                           sTxtFilePrefix.c_str()));
03531 
03532   //classes to organise the code in to related functions
03533   const NuCuts cuts;
03534   const NuGeneral general;
03535   const NuPlots plots;
03536   const NuReco reco;
03537   const NuExtraction ext;
03538   const NuBeam beam;
03539 
03540   //create these on the heap so that they don't destruct
03541   // - on purpose to avoid a segv on destruction... nice coding!
03542   NuMadAnalysis& mad=*new NuMadAnalysis();
03543   MadDpID& dp=*new MadDpID();
03544   //BeamType::BeamType_t beamType=BeamType::kLE;
03545   BeamType::BeamType_t beamType=static_cast
03546     <BeamType::BeamType_t>(config.beamType);
03547 
03551   
03552   this->InitialiseLoopVariables();  
03553   
03554   //for(Int_t entry=0;entry<10000;entry++){
03555   for(Int_t entry=0;entry<this->GetEntries();entry++){
03556       
03557     this->SetLoopVariables(entry);
03558       
03559     //get reference to NtpStRecord from base class
03560     const NtpStRecord& ntp=(*this->GetNtpStRecord());
03561 
03562     const RecCandHeader& rec=ntp.GetHeader();
03563     MAXMSG("NuAnalysis",Msg::kInfo,5)
03564       <<"Found: run="<<rec.GetRun()
03565       <<", subrun="<<rec.GetSubRun()
03566       <<", detector="<<rec.GetVldContext().GetDetector()
03567       <<", simFlag="<<rec.GetVldContext().GetSimFlag()
03568       <<endl;
03569 
03570     //write out the detector, simflag, etc
03571     plots.FillGeneralHistos(ntp);
03572 
03573     //simple event object to hold important quantities for snarl
03574     NuEvent nuSnarl;
03575     
03576     //get the run, snarl, etc info
03577     ext.ExtractGeneralInfo(ntp,nuSnarl);
03578 
03579     if (!beam.IsGoodSpillAndFillPot
03580         (this->GetNtpBDLiteRecord(),config,nuSnarl)) {
03581       badSpillCounter++;
03582       totalPotBad+=nuSnarl.pot;
03583       continue;
03584     }
03585     goodSpillCounter++;
03586     totalPot+=nuSnarl.pot;    
03587 
03588     dp.ChoosePDFs(rec.GetVldContext().GetDetector(),beamType);
03589     mad.SetEntry(&ntp);
03590 
03591     set<Int_t> setNuMuBarInTrueFidCC;
03592   
03593     VldTimeStamp vldts;
03594     //VldTimeStamp vldts(ev.UnixTime,0);
03595     VldContext vc(rec.GetVldContext().GetDetector(),
03596                   rec.GetVldContext().GetSimFlag(),vldts);
03597     //get the ugh
03598     UgliGeomHandle ugh(vc);
03599     
03600     TClonesArray& mcTca=(*ntp.mc);
03601     Int_t numInt=mcTca.GetEntries();
03602     MAXMSG("NuAnalysis",Msg::kInfo,10)
03603       <<"Number of entries in NtpMCTruth="
03604       <<mcTca.GetEntries()<<endl;
03605     
03606     //simple event object to hold important quantities
03607     NuEvent nu;
03608     
03609     //get the run, snarl, etc info
03610     ext.ExtractGeneralInfo(ntp,nu);
03611       
03612 
03614     //loop over true events
03616     for (Int_t i=0;i<numInt;i++){
03617       const NtpMCTruth& mc=*(dynamic_cast<NtpMCTruth*>(mcTca[i]));
03618       
03619       TVector3 xyz(mc.vtxx,mc.vtxy,mc.vtxz);
03620       // calculate the positions in UVZ space
03621       TVector3 uvz=ugh.xyz2uvz(xyz);
03622       
03623       //if (!(mc.iaction==1 && mc.inu==-14)) continue;
03624       //remove all NC and non NuMu(Bar) events
03625       if (mc.iaction!=1) continue;
03626       if (abs(mc.inu)!=14) continue;
03627       
03628       Bool_t isInFidVol=cuts.IsInFidVol(mc.vtxx,mc.vtxy,mc.vtxz,
03629                                         uvz.X(),uvz.Y(),0,0,
03630                                         nu.detector,nu.anaVersion,
03631                                         nu.releaseType,nu.simFlag);
03632       
03633       if (!isInFidVol) continue;
03634       setNuMuBarInTrueFidCC.insert(mc.index);
03635 
03636       Double_t oscWeight=general.OscWeight(3e-3,1,fabs(mc.p4neu[3]));
03637       
03638       MAXMSG("NuAnalysis",Msg::kInfo,200)
03639         <<"inu="<<mc.inu<<", iaction="<<mc.iaction
03640         <<", E="<<mc.p4neu[3]<<", oscWeight="<<oscWeight<<endl;
03641 
03642       if (mc.inu==-14) {
03643         hRecoEnNMBFull->Fill(fabs(mc.p4neu[3]));
03644         hRecoEnNMBOsc->Fill(fabs(mc.p4neu[3]),oscWeight);
03645       }
03646       else if (mc.inu==14) {
03647         hRecoEnNMFull->Fill(fabs(mc.p4neu[3]));
03648         hRecoEnNMOsc->Fill(fabs(mc.p4neu[3]),oscWeight);
03649       }
03650       else {
03651         cout<<"Ahhh, bad inu"<<endl;
03652       }
03653 
03654     }
03655 
03656     MAXMSG("NuAnalysis",Msg::kInfo,20)
03657       <<"Number of NuMuBar fiducial volume interactions in spill="
03658       <<setNuMuBarInTrueFidCC.size()<<endl;
03659   }//end of for                                       
03660   
03664 
03665   MSG("NuAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
03666 
03667   //store the number of files added to the chain
03668   Int_t nf=this->GetNumFilesAddedToChain();
03669   TH1F* hRun=dynamic_cast<TH1F*>(gROOT->FindObject("hRun"));
03670   Float_t nr=-1;
03671   if (hRun) nr=hRun->GetEntries();
03672   TH1F* hNumFiles=new TH1F("hNumFiles","hNumFiles",15,-5,10);
03673   hNumFiles->Fill(1,nf);//store as weight, access with GetMaximum
03674   MSG("NuAnalysis",Msg::kInfo)
03675     <<"Files added to chain="<<hNumFiles->GetMaximum()
03676     <<", runs found="<<nr<<endl;
03677 
03678   MSG("NuAnalysis",Msg::kInfo)
03679     <<"Found start time and end time: "
03680     <<startTimeSecs<<" -> "<<endTimeSecs<<endl;
03681   general.EpochTo1995(endTimeSecs);
03682   general.EpochTo1995(startTimeSecs);
03683   
03684   MSG("NuAnalysis",Msg::kInfo)<<"Filling vs. Time plots..."<<endl;
03685   TH1F* hSpillsVsTime=new TH1F("hSpillsVsTime","hSpillsVsTime",
03686                                100,startTimeSecs,endTimeSecs);
03687   general.TH1FFill(hSpillsVsTime,vTime);
03688   general.SetGraphAxis(hSpillsVsTime->GetXaxis(),
03689                      startTimeSecs,endTimeSecs);
03690   hSpillsVsTime->GetXaxis()->CenterTitle();
03691   hSpillsVsTime->GetYaxis()->SetTitle("Spills");
03692   hSpillsVsTime->GetYaxis()->CenterTitle();
03693 
03694   TH1F* hSpillsBadVsTime=new TH1F("hSpillsBadVsTime","hSpillsBadVsTime",
03695                                   100,startTimeSecs,endTimeSecs);
03696   general.TH1FFill(hSpillsBadVsTime,vTimeBad);
03697   general.SetGraphAxis(hSpillsBadVsTime->GetXaxis(),
03698                      startTimeSecs,endTimeSecs);
03699   hSpillsBadVsTime->GetXaxis()->CenterTitle();
03700   hSpillsBadVsTime->GetYaxis()->SetTitle("Spills");
03701   hSpillsBadVsTime->GetYaxis()->CenterTitle();
03702   
03703   TH1F* hNuMuVsTime=new TH1F("hNuMuVsTime","hNuMuVsTime",
03704                              100,startTimeSecs,endTimeSecs);
03705   general.TH1FFill(hNuMuVsTime,vTimeNuMuEvt);
03706   general.SetGraphAxis(hNuMuVsTime->GetXaxis(),
03707                      startTimeSecs,endTimeSecs);
03708   hNuMuVsTime->GetXaxis()->CenterTitle();
03709   hNuMuVsTime->GetYaxis()->SetTitle("#nu_#mu events");
03710   hNuMuVsTime->GetYaxis()->CenterTitle();
03711 
03712   TH1F* hNuMuBarVsTime=new TH1F("hNuMuBarVsTime","hNuMuBarVsTime",
03713                                100,startTimeSecs,endTimeSecs);
03714   general.TH1FFill(hNuMuBarVsTime,vTimeNuMuBarEvt);
03715   general.SetGraphAxis(hNuMuBarVsTime->GetXaxis(),
03716                      startTimeSecs,endTimeSecs);
03717   hNuMuBarVsTime->GetXaxis()->CenterTitle();
03718   hNuMuBarVsTime->GetYaxis()->SetTitle("#bar{#nu_#mu} events");
03719   hNuMuBarVsTime->GetYaxis()->CenterTitle();
03720 
03721   TH1F* hPotVsTime=new TH1F("hPotVsTime","hPotVsTime",
03722                              100,startTimeSecs,endTimeSecs);
03723   general.TH1FFill(hPotVsTime,vTime,vPot);
03724   general.SetGraphAxis(hPotVsTime->GetXaxis(),
03725                      startTimeSecs,endTimeSecs);
03726   hPotVsTime->GetXaxis()->CenterTitle();
03727   hPotVsTime->GetYaxis()->SetTitle("POT");
03728   hPotVsTime->GetYaxis()->CenterTitle();
03729 
03730   TH1F* hPotBadVsTime=new TH1F("hPotBadVsTime","hPotBadVsTime",
03731                              100,startTimeSecs,endTimeSecs);
03732   general.TH1FFill(hPotBadVsTime,vTimeBad,vPotBad);
03733   general.SetGraphAxis(hPotBadVsTime->GetXaxis(),
03734                      startTimeSecs,endTimeSecs);
03735   hPotBadVsTime->GetXaxis()->CenterTitle();
03736   hPotBadVsTime->GetYaxis()->SetTitle("POT");
03737   hPotBadVsTime->GetYaxis()->CenterTitle();
03738   
03739   Float_t totalPotHist=0;
03740   Float_t totalPotBadHist=0;
03741   cuts.CalcTotalPot(totalPotHist,totalPotBadHist);
03742   Float_t pcPotRejected=0;
03743   if (totalPotHist) pcPotRejected=100.*totalPotBadHist/totalPotHist;
03744 
03745   //msg was giving pots=412886000000000000.000000... still is for MC!
03746   cout<<"Number of spills     ="<<this->GetEntries()<<endl
03747       <<"Number of good spills="<<goodSpillCounter<<endl
03748       <<"Number of bad spills ="<<badSpillCounter<<endl
03749       <<"Sum of good+bad spill="<<badSpillCounter+goodSpillCounter<<endl
03750       <<endl
03751       <<"Total POT good       ="<<totalPot*1e12<<endl
03752       <<"Total POT bad        ="<<totalPotBad*1e12<<endl
03753       <<"Total POT good (hist)="<<totalPotHist*1e12<<endl
03754       <<"Total POT bad  (hist)="<<totalPotBadHist*1e12
03755       <<"  ("<<pcPotRejected<<"%)"<<endl;
03756 
03757   MSG("NuAnalysis",Msg::kInfo)
03758     <<endl<<"*************************************"<<endl
03759     <<"Total Events    ="<<evtCounter<<endl
03760     <<"Evt not litime  ="<<evtNotlitime<<endl
03761     <<"Evt not IsLI    ="<<evtNotIsLI<<endl
03762     <<"Evts in Fid     ="<<evtInFidVolCounter<<endl
03763     <<"Evts w/ Trk     ="<<evtWithTrkCounter<<endl
03764     <<"Good Best Trk   ="<<goodBestTrkCounter<<endl
03765     <<"Track Pass      ="<<goodTrkPassCounter<<endl
03766     <<"Good reco energy="<<goodRecoEnCounter<<endl
03767     <<"Good UVDiff     ="<<goodUVDiffCounter<<endl
03768     <<"Trk Vtx in Fid  ="<<trkInFidVolCounter<<endl
03769     <<"Good Fit SigQP  ="<<goodFitSigQPCounter<<endl
03770     <<"Good Fit Prob   ="<<goodFitProbCounter<<endl
03771     <<"Good Fit Chi2   ="<<goodFitChi2Counter<<endl
03772     <<"Good Delta T    ="<<goodDeltaTCounter<<endl
03773     <<"Good EvtPerSlc  ="<<goodEvtsPerSlcCounter<<endl
03774     <<"Good DP ID      ="<<goodPIDCounter<<endl
03775     <<"Good beyond tEnd="<<goodBeyondTrkEndCounter<<endl
03776     <<"Good shw fract  ="<<goodShwFractCounter<<endl
03777     <<"*************************************"<<endl;
03778 
03779   Float_t pcPQ=0;
03780   if (nuPQCounter+nuNQCounter>0) pcPQ=100.*nuPQCounter/
03781                                    (nuPQCounter+nuNQCounter);
03782   MSG("NuAnalysis",Msg::kInfo)
03783     <<endl
03784     <<"Neutrinos with NQ="<<nuNQCounter<<endl
03785     <<"Neutrinos with PQ="<<nuPQCounter
03786     <<"   ("<<pcPQ<<"%)"<<endl
03787     <<"Sum NQ+PQ        ="<<nuNQCounter+nuPQCounter<<endl
03788     <<endl;
03789   
03790   MSG("NuAnalysis",Msg::kInfo) 
03791     <<" ** Finished NuMuBarAppearance method **"<<endl;
03792 }
03793 
03794 //......................................................................
03795 
03796 void NuAnalysis::Efficiencies()
03797 {
03798   MSG("NuAnalysis",Msg::kInfo) 
03799     <<" ** Running Efficiencies method... **"<<endl;
03800   
03801   NuConfig config;
03802   this->ExtractConfig(config);
03803 
03804   //open the output file for the histograms
03805   string sFilePrefix="NMBEff"+config.sBeamType;
03806   fOutFile=this->OpenFile(config,sFilePrefix.c_str());
03807 
03808   TH1F* hRecoEnNMBFull=new TH1F("hRecoEnNMBFull","hRecoEnNMBFull",
03809                                 4*352,-32,320);
03810   hRecoEnNMBFull->GetXaxis()->SetTitle("True Energy (GeV)");
03811   hRecoEnNMBFull->GetXaxis()->CenterTitle();
03812   hRecoEnNMBFull->GetYaxis()->SetTitle("");
03813   hRecoEnNMBFull->GetYaxis()->CenterTitle();
03814   //hRecoEnNMBFull->SetBit(TH1::kCanRebin);
03815 
03816   TH1F* hRecoEnNMBReco=new TH1F("hRecoEnNMBReco","hRecoEnNMBReco",
03817                                4*352,-32,320);
03818   hRecoEnNMBReco->GetXaxis()->SetTitle("True Energy (GeV)");
03819   hRecoEnNMBReco->GetXaxis()->CenterTitle();
03820   hRecoEnNMBReco->GetYaxis()->SetTitle("");
03821   hRecoEnNMBReco->GetYaxis()->CenterTitle();
03822   //hRecoEnNMBReco->SetBit(TH1::kCanRebin);
03823 
03824   TH1F* hRecoEnNMBFid=new TH1F("hRecoEnNMBFid","hRecoEnNMBFid",
03825                                 4*352,-32,320);
03826   hRecoEnNMBFid->GetXaxis()->SetTitle("True Energy (GeV)");
03827   hRecoEnNMBFid->GetXaxis()->CenterTitle();
03828   hRecoEnNMBFid->GetYaxis()->SetTitle("");
03829   hRecoEnNMBFid->GetYaxis()->CenterTitle();
03830   //hRecoEnNMBFid->SetBit(TH1::kCanRebin);
03831 
03832   TH1F* hRecoEnNMBTrack=new TH1F("hRecoEnNMBTrack","hRecoEnNMBTrack",
03833                                 4*352,-32,320);
03834   hRecoEnNMBTrack->GetXaxis()->SetTitle("True Energy (GeV)");
03835   hRecoEnNMBTrack->GetXaxis()->CenterTitle();
03836   hRecoEnNMBTrack->GetYaxis()->SetTitle("");
03837   hRecoEnNMBTrack->GetYaxis()->CenterTitle();
03838   //hRecoEnNMBTrack->SetBit(TH1::kCanRebin);
03839 
03840   TH1F* hRecoEnNMBPass=new TH1F("hRecoEnNMBPass","hRecoEnNMBPass",
03841                                 4*352,-32,320);
03842   hRecoEnNMBPass->GetXaxis()->SetTitle("True Energy (GeV)");
03843   hRecoEnNMBPass->GetXaxis()->CenterTitle();
03844   hRecoEnNMBPass->GetYaxis()->SetTitle("");
03845   hRecoEnNMBPass->GetYaxis()->CenterTitle();
03846   //hRecoEnNMBPass->SetBit(TH1::kCanRebin);
03847   
03848   TH1F* hRecoEnNMBQCut=new TH1F("hRecoEnNMBQCut","hRecoEnNMBQCut",
03849                                 4*352,-32,320);
03850   hRecoEnNMBQCut->GetXaxis()->SetTitle("True Energy (GeV)");
03851   hRecoEnNMBQCut->GetXaxis()->CenterTitle();
03852   hRecoEnNMBQCut->GetYaxis()->SetTitle("");
03853   hRecoEnNMBQCut->GetYaxis()->CenterTitle();
03854   //hRecoEnNMBQCut->SetBit(TH1::kCanRebin);
03855 
03856   TH1F* hRecoEnNMBSigQP=new TH1F("hRecoEnNMBSigQP","hRecoEnNMBSigQP",
03857                                 4*352,-32,320);
03858   hRecoEnNMBSigQP->GetXaxis()->SetTitle("True Energy (GeV)");
03859   hRecoEnNMBSigQP->GetXaxis()->CenterTitle();
03860   hRecoEnNMBSigQP->GetYaxis()->SetTitle("");
03861   hRecoEnNMBSigQP->GetYaxis()->CenterTitle();
03862   //hRecoEnNMBSigQP->SetBit(TH1::kCanRebin);
03863 
03864   TH1F* hRecoEnNMBProb=new TH1F("hRecoEnNMBProb","hRecoEnNMBProb",
03865                                 4*352,-32,320);
03866   hRecoEnNMBProb->GetXaxis()->SetTitle("True Energy (GeV)");
03867   hRecoEnNMBProb->GetXaxis()->CenterTitle();
03868   hRecoEnNMBProb->GetYaxis()->SetTitle("");
03869   hRecoEnNMBProb->GetYaxis()->CenterTitle();
03870   //hRecoEnNMBProb->SetBit(TH1::kCanRebin);
03871 
03872   TH1F* hRecoEnNMBProb05=new TH1F("hRecoEnNMBProb05","hRecoEnNMBProb05",
03873                                 4*352,-32,320);
03874   hRecoEnNMBProb05->GetXaxis()->SetTitle("True Energy (GeV)");
03875   hRecoEnNMBProb05->GetXaxis()->CenterTitle();
03876   hRecoEnNMBProb05->GetYaxis()->SetTitle("");
03877   hRecoEnNMBProb05->GetYaxis()->CenterTitle();
03878   //hRecoEnNMBProb05->SetBit(TH1::kCanRebin);
03879 
03880   TH1F* hRecoEnNMBDpID01=new TH1F("hRecoEnNMBDpID01","hRecoEnNMBDpID01",
03881                                 4*352,-32,320);
03882   hRecoEnNMBDpID01->GetXaxis()->SetTitle("True Energy (GeV)");
03883   hRecoEnNMBDpID01->GetXaxis()->CenterTitle();
03884   hRecoEnNMBDpID01->GetYaxis()->SetTitle("");
03885   hRecoEnNMBDpID01->GetYaxis()->CenterTitle();
03886   //hRecoEnNMBDpID01->SetBit(TH1::kCanRebin);
03887 
03888   TH1F* hRecoEnNMBDpID04=new TH1F("hRecoEnNMBDpID04","hRecoEnNMBDpID04",
03889                                 4*352,-32,320);
03890   hRecoEnNMBDpID04->GetXaxis()->SetTitle("True Energy (GeV)");
03891   hRecoEnNMBDpID04->GetXaxis()->CenterTitle();
03892   hRecoEnNMBDpID04->GetYaxis()->SetTitle("");
03893   hRecoEnNMBDpID04->GetYaxis()->CenterTitle();
03894   //hRecoEnNMBDpID04->SetBit(TH1::kCanRebin);
03895 
03896 
03897   //leak in/out histos
03898   TH1F* hRecoEnNMBLeakIn=new TH1F("hRecoEnNMBLeakIn","hRecoEnNMBLeakIn",
03899                                 4*352,-32,320);
03900   hRecoEnNMBLeakIn->GetXaxis()->SetTitle("True Energy (GeV)");
03901   hRecoEnNMBLeakIn->GetXaxis()->CenterTitle();
03902   hRecoEnNMBLeakIn->GetYaxis()->SetTitle("");
03903   hRecoEnNMBLeakIn->GetYaxis()->CenterTitle();
03904   //hRecoEnNMBLeakIn->SetBit(TH1::kCanRebin);
03905 
03906   TH1F* hRecoEnNMBLeakOut=new TH1F("hRecoEnNMBLeakOut",
03907                                    "hRecoEnNMBLeakOut",
03908                                    4*352,-32,320);
03909   hRecoEnNMBLeakOut->GetXaxis()->SetTitle("True Energy (GeV)");
03910   hRecoEnNMBLeakOut->GetXaxis()->CenterTitle();
03911   hRecoEnNMBLeakOut->GetYaxis()->SetTitle("");
03912   hRecoEnNMBLeakOut->GetYaxis()->CenterTitle();
03913   //hRecoEnNMBLeakOut->SetBit(TH1::kCanRebin);
03914 
03915 
03916 
03917   TH2F* hYvsXTrueLeakIn=new TH2F("hYvsXTrueLeakIn","hYvsXTrueLeakIn",
03918                              100,-5,5,100,-5,5);
03919   hYvsXTrueLeakIn->SetTitle("Y vs X");
03920   hYvsXTrueLeakIn->GetXaxis()->SetTitle("X");
03921   hYvsXTrueLeakIn->GetXaxis()->CenterTitle();
03922   hYvsXTrueLeakIn->GetYaxis()->SetTitle("Y");
03923   hYvsXTrueLeakIn->GetYaxis()->CenterTitle();
03924   //hYvsXTrueLeakIn->SetBit(TH1::kCanRebin);
03925 
03926   TH2F* hYvsXRecoLeakIn=new TH2F("hYvsXRecoLeakIn","hYvsXRecoLeakIn",
03927                              100,-5,5,100,-5,5);
03928   hYvsXRecoLeakIn->SetTitle("Y vs X");
03929   hYvsXRecoLeakIn->GetXaxis()->SetTitle("X");
03930   hYvsXRecoLeakIn->GetXaxis()->CenterTitle();
03931   hYvsXRecoLeakIn->GetYaxis()->SetTitle("Y");
03932   hYvsXRecoLeakIn->GetYaxis()->CenterTitle();
03933   //hYvsXRecoLeakIn->SetBit(TH1::kCanRebin);
03934 
03935   TH2F* hYvsXTrueLeakOut=new TH2F("hYvsXTrueLeakOut","hYvsXTrueLeakOut",
03936                              100,-5,5,100,-5,5);
03937   hYvsXTrueLeakOut->SetTitle("Y vs X");
03938   hYvsXTrueLeakOut->GetXaxis()->SetTitle("X");
03939   hYvsXTrueLeakOut->GetXaxis()->CenterTitle();
03940   hYvsXTrueLeakOut->GetYaxis()->SetTitle("Y");
03941   hYvsXTrueLeakOut->GetYaxis()->CenterTitle();
03942   //hYvsXTrueLeakOut->SetBit(TH1::kCanRebin);
03943 
03944   TH2F* hYvsXRecoLeakOut=new TH2F("hYvsXRecoLeakOut","hYvsXRecoLeakOut",
03945                              100,-5,5,100,-5,5);
03946   hYvsXRecoLeakOut->SetTitle("Y vs X");
03947   hYvsXRecoLeakOut->GetXaxis()->SetTitle("X");
03948   hYvsXRecoLeakOut->GetXaxis()->CenterTitle();
03949   hYvsXRecoLeakOut->GetYaxis()->SetTitle("Y");
03950   hYvsXRecoLeakOut->GetYaxis()->CenterTitle();
03951   //hYvsXRecoLeakOut->SetBit(TH1::kCanRebin);
03952 
03953 
03954   TH1F* hRecoEnNMBTrkLeakIn=new TH1F("hRecoEnNMBTrkLeakIn",
03955                                      "hRecoEnNMBTrkLeakIn",
03956                                      4*352,-32,320);
03957   hRecoEnNMBTrkLeakIn->GetXaxis()->SetTitle("True Energy (GeV)");
03958   hRecoEnNMBTrkLeakIn->GetXaxis()->CenterTitle();
03959   hRecoEnNMBTrkLeakIn->GetYaxis()->SetTitle("");
03960   hRecoEnNMBTrkLeakIn->GetYaxis()->CenterTitle();
03961   //hRecoEnNMBTrkLeakIn->SetBit(TH1::kCanRebin);
03962 
03963   TH1F* hRecoEnNMBTrkLeakOut=new TH1F("hRecoEnNMBTrkLeakOut",
03964                                       "hRecoEnNMBTrkLeakOut",
03965                                       4*352,-32,320);
03966   hRecoEnNMBTrkLeakOut->GetXaxis()->SetTitle("True Energy (GeV)");
03967   hRecoEnNMBTrkLeakOut->GetXaxis()->CenterTitle();
03968   hRecoEnNMBTrkLeakOut->GetYaxis()->SetTitle("");
03969   hRecoEnNMBTrkLeakOut->GetYaxis()->CenterTitle();
03970   //hRecoEnNMBTrkLeakOut->SetBit(TH1::kCanRebin);
03971 
03972 
03973 
03974   TH2F* hYvsXTrueTrkLeakIn=new TH2F("hYvsXTrueTrkLeakIn",
03975                                     "hYvsXTrueTrkLeakIn",
03976                                     100,-5,5,100,-5,5);
03977   hYvsXTrueTrkLeakIn->SetTitle("Y vs X");
03978   hYvsXTrueTrkLeakIn->GetXaxis()->SetTitle("X");
03979   hYvsXTrueTrkLeakIn->GetXaxis()->CenterTitle();
03980   hYvsXTrueTrkLeakIn->GetYaxis()->SetTitle("Y");
03981   hYvsXTrueTrkLeakIn->GetYaxis()->CenterTitle();
03982   //hYvsXTrueTrkLeakIn->SetBit(TH1::kCanRebin);
03983 
03984   TH2F* hYvsXRecoTrkLeakIn=new TH2F("hYvsXRecoTrkLeakIn",
03985                                     "hYvsXRecoTrkLeakIn",
03986                                     100,-5,5,100,-5,5);
03987   hYvsXRecoTrkLeakIn->SetTitle("Y vs X");
03988   hYvsXRecoTrkLeakIn->GetXaxis()->SetTitle("X");
03989   hYvsXRecoTrkLeakIn->GetXaxis()->CenterTitle();
03990   hYvsXRecoTrkLeakIn->GetYaxis()->SetTitle("Y");
03991   hYvsXRecoTrkLeakIn->GetYaxis()->CenterTitle();
03992   //hYvsXRecoTrkLeakIn->SetBit(TH1::kCanRebin);
03993   
03994   TH2F* hYvsXTrueTrkLeakOut=new TH2F("hYvsXTrueTrkLeakOut",
03995                                      "hYvsXTrueTrkLeakOut",
03996                                      100,-5,5,100,-5,5);
03997   hYvsXTrueTrkLeakOut->SetTitle("Y vs X");
03998   hYvsXTrueTrkLeakOut->GetXaxis()->SetTitle("X");
03999   hYvsXTrueTrkLeakOut->GetXaxis()->CenterTitle();
04000   hYvsXTrueTrkLeakOut->GetYaxis()->SetTitle("Y");
04001   hYvsXTrueTrkLeakOut->GetYaxis()->CenterTitle();
04002   //hYvsXTrueTrkLeakOut->SetBit(TH1::kCanRebin);
04003 
04004   TH2F* hYvsXRecoTrkLeakOut=new TH2F("hYvsXRecoTrkLeakOut",
04005                                      "hYvsXRecoTrkLeakOut",
04006                                      100,-5,5,100,-5,5);
04007   hYvsXRecoTrkLeakOut->SetTitle("Y vs X");
04008   hYvsXRecoTrkLeakOut->GetXaxis()->SetTitle("X");
04009   hYvsXRecoTrkLeakOut->GetXaxis()->CenterTitle();
04010   hYvsXRecoTrkLeakOut->GetYaxis()->SetTitle("Y");
04011   hYvsXRecoTrkLeakOut->GetYaxis()->CenterTitle();
04012   //hYvsXRecoTrkLeakOut->SetBit(TH1::kCanRebin);
04013 
04014   //vectors
04015   Int_t entries=static_cast<Int_t>(this->GetEntries());
04016   Int_t startTimeSecs=2000000000;//2 billion
04017   Int_t endTimeSecs=1;
04018   vector<Double_t> vPot;
04019   vPot.reserve(entries);
04020   vector<Double_t> vTime;
04021   vTime.reserve(entries);
04022   vector<Double_t> vPotBad;
04023   vPotBad.reserve(entries/10);
04024   vector<Double_t> vTimeBad;
04025   vTimeBad.reserve(entries/10);
04026   
04027   vector<Double_t> vTimeNuMuEvt;
04028   vTimeNuMuEvt.reserve(entries/5);
04029   vector<Double_t> vTimeNuMuBarEvt;
04030   vTimeNuMuBarEvt.reserve(entries/5);
04031  
04032   //maps to store evt info
04033   map<Int_t,Double_t> deltaTs;
04034   map<Int_t,Int_t> evtsPerSlc;
04035 
04036   //counters
04037   Int_t goodSpillCounter=0;
04038   Int_t badSpillCounter=0;
04039   Float_t totalPot=0;
04040   Float_t totalPotBad=0;
04041   Int_t evtCounter=0;
04042   Int_t evtNotlitime=0;
04043   Int_t evtNotIsLI=0;
04044   Int_t evtInFidVolCounter=0;
04045   Int_t evtWithTrkCounter=0;
04046   Int_t goodBestTrkCounter=0;
04047   Int_t goodTrkPassCounter=0;
04048   Int_t goodRecoEnCounter=0;
04049   Int_t goodUVDiffCounter=0;
04050   Int_t trkInFidVolCounter=0;
04051   Int_t goodFitSigQPCounter=0;
04052   Int_t goodFitProbCounter=0;
04053   Int_t goodFitChi2Counter=0;
04054   Int_t goodDeltaTCounter=0;
04055   Int_t goodEvtsPerSlcCounter=0; 
04056   Int_t goodPIDCounter=0;
04057   Int_t goodBeyondTrkEndCounter=0;
04058   Int_t goodShwFractCounter=0;
04059   Int_t nuNQCounter=0;
04060   Int_t nuPQCounter=0;
04061   
04062   //string sTxtFilePrefix="nmb"+config.sBeamType;
04063   //ofstream& nmbTxt=*(this->OpenTxtFile(config,
04064   //                           sTxtFilePrefix.c_str()));
04065 
04066   //classes to organise the code in to related functions
04067   const NuCuts cuts;
04068   const NuGeneral general;
04069   const NuPlots plots;
04070   const NuReco reco;
04071   const NuExtraction ext;
04072   const NuBeam beam;
04073 
04074   //create these on the heap so that they don't destruct
04075   // - on purpose to avoid a segv on destruction... nice coding!
04076   NuMadAnalysis& mad=*new NuMadAnalysis();
04077   MadDpID& dp=*new MadDpID();
04078   //BeamType::BeamType_t beamType=BeamType::kLE;
04079   BeamType::BeamType_t beamType=static_cast
04080     <BeamType::BeamType_t>(config.beamType);
04081  
04082   //get an instance of the code library
04083   const NuLibrary& lib=NuLibrary::Instance();
04084  
04088   
04089   this->InitialiseLoopVariables();  
04090   
04091   //for(Int_t entry=0;entry<10000;entry++){
04092   for(Int_t entry=0;entry<this->GetEntries();entry++){
04093       
04094     this->SetLoopVariables(entry);
04095       
04096     //get reference to NtpStRecord from base class
04097     const NtpStRecord& ntp=(*this->GetNtpStRecord());
04098 
04099     const RecCandHeader& rec=ntp.GetHeader();
04100     MAXMSG("NuAnalysis",Msg::kInfo,5)
04101       <<"Found: run="<<rec.GetRun()
04102       <<", subrun="<<rec.GetSubRun()
04103       <<", detector="<<rec.GetVldContext().GetDetector()
04104       <<", simFlag="<<rec.GetVldContext().GetSimFlag()
04105       <<endl;
04106 
04107     //write out the detector, simflag, etc
04108     plots.FillGeneralHistos(ntp);
04109 
04110     //simple event object to hold important quantities for snarl
04111     NuEvent nuSnarl;
04112     
04113     //get the run, snarl, etc info
04114     ext.ExtractGeneralInfo(ntp,nuSnarl);
04115 
04116     if (!beam.IsGoodSpillAndFillPot
04117         (this->GetNtpBDLiteRecord(),config,nuSnarl)) {
04118       badSpillCounter++;
04119       totalPotBad+=nuSnarl.pot;
04120       continue;
04121     }
04122     goodSpillCounter++;
04123     totalPot+=nuSnarl.pot;    
04124 
04125     dp.ChoosePDFs(rec.GetVldContext().GetDetector(),beamType);
04126     mad.SetEntry(&ntp);
04127 
04128     set<Int_t> setNuMuBarInTrueFidCC;
04129   
04130     VldTimeStamp vldts;
04131     //VldTimeStamp vldts(ev.UnixTime,0);
04132     VldContext vc(rec.GetVldContext().GetDetector(),
04133                   rec.GetVldContext().GetSimFlag(),vldts);
04134     //get the ugh
04135     UgliGeomHandle ugh(vc);
04136     
04137     TClonesArray& mcTca=(*ntp.mc);
04138     Int_t numInt=mcTca.GetEntries();
04139     MAXMSG("NuAnalysis",Msg::kInfo,10)
04140       <<"Number of entries in NtpMCTruth="
04141       <<mcTca.GetEntries()<<endl;
04142     
04143     //simple event object to hold important quantities
04144     NuEvent nu;
04145     
04146     //get the run, snarl, etc info
04147     ext.ExtractGeneralInfo(ntp,nu);
04148       
04149 
04151     //loop over true events
04153     for (Int_t i=0;i<numInt;i++){
04154       const NtpMCTruth& mc=*(dynamic_cast<NtpMCTruth*>(mcTca[i]));
04155       
04156       TVector3 xyz(mc.vtxx,mc.vtxy,mc.vtxz);
04157       // calculate the positions in UVZ space
04158       TVector3 uvz=ugh.xyz2uvz(xyz);
04159       
04160       if (!(mc.iaction==1 && mc.inu==-14)) continue;
04161       
04162       Bool_t isInFidVol=cuts.IsInFidVol(mc.vtxx,mc.vtxy,mc.vtxz,
04163                                         uvz.X(),uvz.Y(),0,0,
04164                                         nu.detector,nu.anaVersion,
04165                                         nu.releaseType,nu.simFlag);
04166       
04167       if (!isInFidVol) continue;
04168       setNuMuBarInTrueFidCC.insert(mc.index);
04169 
04170       hRecoEnNMBFull->Fill(fabs(mc.p4neu[3]));
04171     }
04172 
04173     MAXMSG("NuAnalysis",Msg::kInfo,20)
04174       <<"Number of NuMuBar fiducial volume interactions in spill="
04175       <<setNuMuBarInTrueFidCC.size()<<endl;
04176 
04177 
04178     TClonesArray& thevtTca=(*ntp.thevt);//TruthHelper Event TCA
04179     const Int_t numthevts=thevtTca.GetEntriesFast();
04180     if (numthevts<=0) {
04181       MSG("NuAnalysis",Msg::kWarning)
04182         <<"No THEvents..."<<endl;
04183       continue;
04184     }
04185 
04186     set<Int_t> setNuMuBarInRecoFidCC;
04187 
04188     TClonesArray& evtTca=(*ntp.evt);
04189     const Int_t numEvts=evtTca.GetEntriesFast();
04190 
04192     //loop over the reconstructed events
04194     for (Int_t ievt=0;ievt<numEvts;ievt++){
04195       const NtpSREvent& evt=
04196         *dynamic_cast<NtpSREvent*>(evtTca[ievt]);
04197       evtCounter++;
04198 
04199       const NtpTHEvent& thevt=
04200         *dynamic_cast<NtpTHEvent*>(thevtTca[evt.index]);
04201       
04202       //now get the mc object (neutrino interaction) that 
04203       //corresponds to the evt using the thevt.neumc index
04204       const NtpMCTruth& mc=
04205         *(dynamic_cast<NtpMCTruth*>(mcTca[thevt.neumc]));
04206       
04207       //cut out all but numubar cc
04208       if (!(mc.iaction==1 && mc.inu==-14)) continue;
04209 
04210       //simple event object to hold important quantities
04211       NuEvent nu;
04212 
04213       //get the run, snarl, etc info
04214       ext.ExtractGeneralInfo(ntp,nu);
04215       //get info from the evt
04216       lib.ext.ExtractEvtInfo(evt,nu);
04217       //extract trk info (needed to get best track info)
04218       lib.ext.ExtractTrkInfo(ntp,evt,nu);
04219       //extract shw info
04220       lib.ext.ExtractShwInfo(ntp,evt,nu);
04221 
04222       Bool_t isInFidVol=cuts.IsInFidVol(evt.vtx.x,evt.vtx.y,
04223                                         evt.vtx.z,
04224                                         evt.vtx.u,evt.vtx.v,0,0,
04225                                         nu.detector,nu.anaVersion,
04226                                         nu.releaseType,nu.simFlag);
04227       
04228       //make sure that no event is used twice
04229       set<Int_t>::iterator itT=setNuMuBarInRecoFidCC.find(thevt.neumc);
04230       if (itT==setNuMuBarInRecoFidCC.end()) {
04231         MAXMSG("NuAnalysis",Msg::kInfo,20)
04232           <<"Found reco event for mc="<<thevt.neumc<<endl;
04233         setNuMuBarInRecoFidCC.insert(thevt.neumc);
04234       }
04235       else {
04236         MAXMSG("NuAnalysis",Msg::kInfo,20)
04237           <<"Already found reco event for mc="<<thevt.neumc<<endl;
04238         continue;
04239       }
04240       
04241       //get the best track in the event
04242       Int_t bestTrack=lib.reco.GetBestTrack(nu);
04243       const NtpSRTrack* ptrk=lib.reco.GetTrackWithIndexX
04244         (ntp,evt,bestTrack-1);
04245       Bool_t trkIsInFidVol=false;
04246       if (ptrk!=0) {
04247         const NtpSRTrack& trk=*ptrk;
04248         trkIsInFidVol=cuts.IsInFidVol(trk.vtx.x,trk.vtx.y,
04249                                       trk.vtx.z,
04250                                       trk.vtx.u,trk.vtx.v,0,0,
04251                                       nu.detector,nu.anaVersion,
04252                                       nu.releaseType,nu.simFlag);
04253         trkIsInFidVol=true;
04254       }
04255 
04256       //these ones are leaking into the fiducial volume
04257       set<Int_t>::iterator itR=setNuMuBarInTrueFidCC.find(thevt.neumc);
04258       if (itR==setNuMuBarInTrueFidCC.end()) {
04259         MAXMSG("NuAnalysis",Msg::kInfo,20)
04260           <<"ievt="<<ievt<<" has no true event in fid"<<endl; 
04261         if (isInFidVol){
04262           hRecoEnNMBLeakIn->Fill(fabs(mc.p4neu[3]));
04263           hYvsXRecoLeakIn->Fill(evt.vtx.x,evt.vtx.y);
04264           hYvsXTrueLeakIn->Fill(mc.vtxx,mc.vtxy);
04265           if (trkIsInFidVol){
04266             const NtpSRTrack& trk=*ptrk;
04267             hRecoEnNMBTrkLeakIn->Fill(fabs(mc.p4neu[3]));
04268             hYvsXRecoTrkLeakIn->Fill(trk.vtx.x,trk.vtx.y);
04269             hYvsXTrueTrkLeakIn->Fill(mc.vtxx,mc.vtxy);
04270           }
04271         }
04272         continue;
04273       }
04274       
04275       //record events that are reconstructed regardless of fid or not
04276       hRecoEnNMBReco->Fill(fabs(mc.p4neu[3]));
04277 
04278       //any event that makes it to here is in the true fid vol
04279 
04280       //now check if the events in the true fid vol are in reco fid vol
04281       if (!trkIsInFidVol) {
04282         //these events leaked out of fid vol
04283         if (ptrk){
04284           const NtpSRTrack& trk=*ptrk;
04285           hRecoEnNMBTrkLeakOut->Fill(fabs(mc.p4neu[3]));
04286           hYvsXRecoTrkLeakOut->Fill(trk.vtx.x,trk.vtx.y);
04287           hYvsXTrueTrkLeakOut->Fill(mc.vtxx,mc.vtxy);
04288         }
04289         else{
04290           MAXMSG("NuAnalysis",Msg::kInfo,20)
04291             <<"No track, using evt vtx"<<endl;
04292           hRecoEnNMBTrkLeakOut->Fill(fabs(mc.p4neu[3]));
04293           hYvsXRecoTrkLeakOut->Fill(evt.vtx.x,evt.vtx.y);
04294           hYvsXTrueTrkLeakOut->Fill(mc.vtxx,mc.vtxy);
04295         }
04296       }
04297       if (!isInFidVol) {
04298         //these events leaked out of fid vol
04299         hRecoEnNMBLeakOut->Fill(fabs(mc.p4neu[3]));
04300         hYvsXRecoLeakOut->Fill(evt.vtx.x,evt.vtx.y);
04301         hYvsXTrueLeakOut->Fill(mc.vtxx,mc.vtxy);
04302         continue;
04303       }
04304       evtInFidVolCounter++;
04305       hRecoEnNMBFid->Fill(fabs(mc.p4neu[3]));
04306 
04307       //ensure there is a track in the event
04308       if (evt.ntrack<1) continue;
04309       //if (evt.ntrack!=1) continue;//require exactly 1 track
04310       evtWithTrkCounter++;
04311       hRecoEnNMBTrack->Fill(fabs(mc.p4neu[3]));
04312 
04313       //get the best track in the event
04314       if (ptrk==0) continue;
04315       const NtpSRTrack& trk=*ptrk;
04316       goodBestTrkCounter++;
04317 
04318       //require a trk fit
04319       if (!trk.fit.pass) continue;
04320       goodTrkPassCounter++;
04321       hRecoEnNMBPass->Fill(fabs(mc.p4neu[3]));
04322 
04323       //check for wrong sign
04324       if (trk.momentum.qp<=0) continue;
04325       hRecoEnNMBQCut->Fill(fabs(mc.p4neu[3]));
04326       
04328       //RECONSTRUCT the neutrino energy
04329       lib.reco.GetEvtEnergy(nu, false);
04330       goodRecoEnCounter++;
04331       //get the truth info (reco quantities are done above)
04332       reco.GetTruthInfo(ntp,evt,nu);
04333       //set the charge
04334       nu.charge=trk.momentum.qp<0 ? -1 : 1;
04335       if (trk.momentum.qp==0) nu.charge=0;
04336 
04337       //cut on the fractional track momentum and sign error      
04338       if (!cuts.IsGoodSigmaQP_QP(nu)) continue;
04339       goodFitSigQPCounter++;
04340       hRecoEnNMBSigQP->Fill(fabs(mc.p4neu[3]));
04341 
04342       //cut on the track fit probability      
04343       if (!cuts.IsGoodFitProb(nu)) continue;
04344       goodFitProbCounter++;
04345       hRecoEnNMBProb->Fill(fabs(mc.p4neu[3]));
04346 
04347       nu.dpID=dp.CalcPID(&mad,ievt,0);
04348       if (nu.dpID>=-0.1) {
04349         hRecoEnNMBDpID01->Fill(fabs(mc.p4neu[3]));
04350       }
04351 
04352       if (nu.dpID>=0.4) {
04353         hRecoEnNMBDpID04->Fill(fabs(mc.p4neu[3]));
04354       }
04355     }
04356   }//end of for                                       
04357   
04361 
04362   MSG("NuAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
04363 
04364   //store the number of files added to the chain
04365   Int_t nf=this->GetNumFilesAddedToChain();
04366   TH1F* hRun=dynamic_cast<TH1F*>(gROOT->FindObject("hRun"));
04367   Float_t nr=-1;
04368   if (hRun) nr=hRun->GetEntries();
04369   TH1F* hNumFiles=new TH1F("hNumFiles","hNumFiles",15,-5,10);
04370   hNumFiles->Fill(1,nf);//store as weight, access with GetMaximum
04371   MSG("NuAnalysis",Msg::kInfo)
04372     <<"Files added to chain="<<hNumFiles->GetMaximum()
04373     <<", runs found="<<nr<<endl;
04374 
04375   MSG("NuAnalysis",Msg::kInfo)
04376     <<"Found start time and end time: "
04377     <<startTimeSecs<<" -> "<<endTimeSecs<<endl;
04378   general.EpochTo1995(endTimeSecs);
04379   general.EpochTo1995(startTimeSecs);
04380   
04381   MSG("NuAnalysis",Msg::kInfo)<<"Filling vs. Time plots..."<<endl;
04382   TH1F* hSpillsVsTime=new TH1F("hSpillsVsTime","hSpillsVsTime",
04383                                100,startTimeSecs,endTimeSecs);
04384   general.TH1FFill(hSpillsVsTime,vTime);
04385   general.SetGraphAxis(hSpillsVsTime->GetXaxis(),
04386                      startTimeSecs,endTimeSecs);
04387   hSpillsVsTime->GetXaxis()->CenterTitle();
04388   hSpillsVsTime->GetYaxis()->SetTitle("Spills");
04389   hSpillsVsTime->GetYaxis()->CenterTitle();
04390 
04391   TH1F* hSpillsBadVsTime=new TH1F("hSpillsBadVsTime","hSpillsBadVsTime",
04392                                   100,startTimeSecs,endTimeSecs);
04393   general.TH1FFill(hSpillsBadVsTime,vTimeBad);
04394   general.SetGraphAxis(hSpillsBadVsTime->GetXaxis(),
04395                      startTimeSecs,endTimeSecs);
04396   hSpillsBadVsTime->GetXaxis()->CenterTitle();
04397   hSpillsBadVsTime->GetYaxis()->SetTitle("Spills");
04398   hSpillsBadVsTime->GetYaxis()->CenterTitle();
04399   
04400   TH1F* hNuMuVsTime=new TH1F("hNuMuVsTime","hNuMuVsTime",
04401                              100,startTimeSecs,endTimeSecs);
04402   general.TH1FFill(hNuMuVsTime,vTimeNuMuEvt);
04403   general.SetGraphAxis(hNuMuVsTime->GetXaxis(),
04404                      startTimeSecs,endTimeSecs);
04405   hNuMuVsTime->GetXaxis()->CenterTitle();
04406   hNuMuVsTime->GetYaxis()->SetTitle("#nu_#mu events");
04407   hNuMuVsTime->GetYaxis()->CenterTitle();
04408 
04409   TH1F* hNuMuBarVsTime=new TH1F("hNuMuBarVsTime","hNuMuBarVsTime",
04410                                100,startTimeSecs,endTimeSecs);
04411   general.TH1FFill(hNuMuBarVsTime,vTimeNuMuBarEvt);
04412   general.SetGraphAxis(hNuMuBarVsTime->GetXaxis(),
04413                      startTimeSecs,endTimeSecs);
04414   hNuMuBarVsTime->GetXaxis()->CenterTitle();
04415   hNuMuBarVsTime->GetYaxis()->SetTitle("#bar{#nu_#mu} events");
04416   hNuMuBarVsTime->GetYaxis()->CenterTitle();
04417 
04418   TH1F* hPotVsTime=new TH1F("hPotVsTime","hPotVsTime",
04419                              100,startTimeSecs,endTimeSecs);
04420   general.TH1FFill(hPotVsTime,vTime,vPot);
04421   general.SetGraphAxis(hPotVsTime->GetXaxis(),
04422                      startTimeSecs,endTimeSecs);
04423   hPotVsTime->GetXaxis()->CenterTitle();
04424   hPotVsTime->GetYaxis()->SetTitle("POT");
04425   hPotVsTime->GetYaxis()->CenterTitle();
04426 
04427   TH1F* hPotBadVsTime=new TH1F("hPotBadVsTime","hPotBadVsTime",
04428                              100,startTimeSecs,endTimeSecs);
04429   general.TH1FFill(hPotBadVsTime,vTimeBad,vPotBad);
04430   general.SetGraphAxis(hPotBadVsTime->GetXaxis(),
04431                      startTimeSecs,endTimeSecs);
04432   hPotBadVsTime->GetXaxis()->CenterTitle();
04433   hPotBadVsTime->GetYaxis()->SetTitle("POT");
04434   hPotBadVsTime->GetYaxis()->CenterTitle();
04435   
04436   Float_t totalPotHist=0;
04437   Float_t totalPotBadHist=0;
04438   cuts.CalcTotalPot(totalPotHist,totalPotBadHist);
04439   Float_t pcPotRejected=0;
04440   if (totalPotHist) pcPotRejected=100.*totalPotBadHist/totalPotHist;
04441 
04442   //msg was giving pots=412886000000000000.000000... still is for MC!
04443   cout<<"Number of spills     ="<<this->GetEntries()<<endl
04444       <<"Number of good spills="<<goodSpillCounter<<endl
04445       <<"Number of bad spills ="<<badSpillCounter<<endl
04446       <<"Sum of good+bad spill="<<badSpillCounter+goodSpillCounter<<endl
04447       <<endl
04448       <<"Total POT good       ="<<totalPot*1e12<<endl
04449       <<"Total POT bad        ="<<totalPotBad*1e12<<endl
04450       <<"Total POT good (hist)="<<totalPotHist*1e12<<endl
04451       <<"Total POT bad  (hist)="<<totalPotBadHist*1e12
04452       <<"  ("<<pcPotRejected<<"%)"<<endl;
04453 
04454   MSG("NuAnalysis",Msg::kInfo)
04455     <<endl<<"*************************************"<<endl
04456     <<"Total Events    ="<<evtCounter<<endl
04457     <<"Evt not litime  ="<<evtNotlitime<<endl
04458     <<"Evt not IsLI    ="<<evtNotIsLI<<endl
04459     <<"Evts in Fid     ="<<evtInFidVolCounter<<endl
04460     <<"Evts w/ Trk     ="<<evtWithTrkCounter<<endl
04461     <<"Good Best Trk   ="<<goodBestTrkCounter<<endl
04462     <<"Track Pass      ="<<goodTrkPassCounter<<endl
04463     <<"Good reco energy="<<goodRecoEnCounter<<endl
04464     <<"Good UVDiff     ="<<goodUVDiffCounter<<endl
04465     <<"Trk Vtx in Fid  ="<<trkInFidVolCounter<<endl
04466     <<"Good Fit SigQP  ="<<goodFitSigQPCounter<<endl
04467     <<"Good Fit Prob   ="<<goodFitProbCounter<<endl
04468     <<"Good Fit Chi2   ="<<goodFitChi2Counter<<endl
04469     <<"Good Delta T    ="<<goodDeltaTCounter<<endl
04470     <<"Good EvtPerSlc  ="<<goodEvtsPerSlcCounter<<endl
04471     <<"Good DP ID      ="<<goodPIDCounter<<endl
04472     <<"Good beyond tEnd="<<goodBeyondTrkEndCounter<<endl
04473     <<"Good shw fract  ="<<goodShwFractCounter<<endl
04474     <<"*************************************"<<endl;
04475 
04476   Float_t pcPQ=0;
04477   if (nuPQCounter+nuNQCounter>0) pcPQ=100.*nuPQCounter/
04478                                    (nuPQCounter+nuNQCounter);
04479   MSG("NuAnalysis",Msg::kInfo)
04480     <<endl
04481     <<"Neutrinos with NQ="<<nuNQCounter<<endl
04482     <<"Neutrinos with PQ="<<nuPQCounter
04483     <<"   ("<<pcPQ<<"%)"<<endl
04484     <<"Sum NQ+PQ        ="<<nuNQCounter+nuPQCounter<<endl
04485     <<endl;
04486   
04487   MSG("NuAnalysis",Msg::kInfo) 
04488     <<" ** Finished Efficiencies method **"<<endl;
04489 }
04490 
04491 //......................................................................
04492 
04493 void NuAnalysis::ChargeSignCut()
04494 {
04495   MSG("NuAnalysis",Msg::kInfo) 
04496     <<" ** Running ChargeSignCut method... **"<<endl;
04497   
04498   NuConfig config;
04499   this->ExtractConfig(config);
04500 
04501   //open the output file for the histograms
04502   string sFilePrefix="NMBCutQ"+config.sBeamType;
04503   fOutFile=this->OpenFile(config,sFilePrefix.c_str());
04504 
04505   TH1F* hNuMuBarRecoEn=new TH1F("hNuMuBarRecoEn","hNuMuBarRecoEn",
04506                                 4*352,-32,320);
04507   hNuMuBarRecoEn->GetXaxis()->SetTitle("Energy (GeV)");
04508   hNuMuBarRecoEn->GetXaxis()->CenterTitle();
04509   hNuMuBarRecoEn->GetYaxis()->SetTitle("");
04510   hNuMuBarRecoEn->GetYaxis()->CenterTitle();
04511   hNuMuBarRecoEn->SetFillColor(0);
04512   hNuMuBarRecoEn->SetLineColor(2);
04513   //hNuMuBarRecoEn->SetBit(TH1::kCanRebin);
04514   
04515   TH1F* hNuMuRecoEn=new TH1F("hNuMuRecoEn","hNuMuRecoEn",4*352,-32,320);
04516   hNuMuRecoEn->GetXaxis()->SetTitle("Energy (GeV)");
04517   hNuMuRecoEn->GetXaxis()->CenterTitle();
04518   hNuMuRecoEn->GetYaxis()->SetTitle("");
04519   hNuMuRecoEn->GetYaxis()->CenterTitle();
04520   hNuMuRecoEn->SetFillColor(0);
04521   hNuMuRecoEn->SetLineColor(1);
04522   hNuMuRecoEn->SetLineWidth(2);
04523   //hNuMuRecoEn->SetBit(TH1::kCanRebin);
04524 
04525   TH1F* hNuMuBarRecoY=new TH1F("hNuMuBarRecoY","hNuMuBarRecoY",
04526                                 4*144,-0.16,1.28);
04527   hNuMuBarRecoY->GetXaxis()->SetTitle("y");
04528   hNuMuBarRecoY->GetXaxis()->CenterTitle();
04529   hNuMuBarRecoY->GetYaxis()->SetTitle("");
04530   hNuMuBarRecoY->GetYaxis()->CenterTitle();
04531   hNuMuBarRecoY->SetFillColor(0);
04532   hNuMuBarRecoY->SetLineColor(2);
04533   //hNuMuBarRecoY->SetBit(TH1::kCanRebin);
04534   
04535   TH1F* hNuMuRecoY=new TH1F("hNuMuRecoY","hNuMuRecoY",4*144,-0.16,1.28);
04536   hNuMuRecoY->GetXaxis()->SetTitle("y");
04537   hNuMuRecoY->GetXaxis()->CenterTitle();
04538   hNuMuRecoY->GetYaxis()->SetTitle("");
04539   hNuMuRecoY->GetYaxis()->CenterTitle();
04540   hNuMuRecoY->SetFillColor(0);
04541   hNuMuRecoY->SetLineColor(1);
04542   hNuMuRecoY->SetLineWidth(2);
04543   //hNuMuRecoY->SetBit(TH1::kCanRebin);
04544 
04545   TH1F* hDpIDAll=new TH1F("hDpIDAll","hDpIDAll",4*160,-1.6,1.6);
04546   hDpIDAll->GetXaxis()->SetTitle("PID (from MadDpID)");
04547   hDpIDAll->GetXaxis()->CenterTitle();
04548   hDpIDAll->GetYaxis()->SetTitle("");
04549   hDpIDAll->GetYaxis()->CenterTitle();
04550   hDpIDAll->SetFillColor(0);
04551   hDpIDAll->SetLineColor(1);
04552   hDpIDAll->SetLineWidth(2);
04553   //hDpIDAll->SetBit(TH1::kCanRebin);
04554 
04555   TH1F* hDpIDPQ=new TH1F("hDpIDPQ","hDpIDPQ",4*160,-1.6,1.6);
04556   hDpIDPQ->GetXaxis()->SetTitle("PID (from MadDpID)");
04557   hDpIDPQ->GetXaxis()->CenterTitle();
04558   hDpIDPQ->GetYaxis()->SetTitle("");
04559   hDpIDPQ->GetYaxis()->CenterTitle();
04560   hDpIDPQ->SetFillColor(0);
04561   hDpIDPQ->SetLineColor(1);
04562   hDpIDPQ->SetLineWidth(2);
04563   //hDpIDPQ->SetBit(TH1::kCanRebin);
04564 
04565   TH1F* hDpIDNQ=new TH1F("hDpIDNQ","hDpIDNQ",4*160,-1.6,1.6);
04566   hDpIDNQ->GetXaxis()->SetTitle("PID (from MadDpID)");
04567   hDpIDNQ->GetXaxis()->CenterTitle();
04568   hDpIDNQ->GetYaxis()->SetTitle("");
04569   hDpIDNQ->GetYaxis()->CenterTitle();
04570   hDpIDNQ->SetFillColor(0);
04571   hDpIDNQ->SetLineColor(1);
04572   hDpIDNQ->SetLineWidth(2);
04573   //hDpIDNQ->SetBit(TH1::kCanRebin);
04574 
04575   TH1F* hDpIDPQN_1=new TH1F("hDpIDPQN_1","hDpIDPQN_1",4*160,-1.6,1.6);
04576   hDpIDPQN_1->GetXaxis()->SetTitle("PID (from MadDpID)");
04577   hDpIDPQN_1->GetXaxis()->CenterTitle();
04578   hDpIDPQN_1->GetYaxis()->SetTitle("");
04579   hDpIDPQN_1->GetYaxis()->CenterTitle();
04580   hDpIDPQN_1->SetFillColor(0);
04581   hDpIDPQN_1->SetLineColor(1);
04582   hDpIDPQN_1->SetLineWidth(2);
04583   //hDpIDPQN_1->SetBit(TH1::kCanRebin);
04584 
04585   TH1F* hDpIDNQN_1=new TH1F("hDpIDNQN_1","hDpIDNQN_1",4*160,-1.6,1.6);
04586   hDpIDNQN_1->GetXaxis()->SetTitle("PID (from MadDpID)");
04587   hDpIDNQN_1->GetXaxis()->CenterTitle();
04588   hDpIDNQN_1->GetYaxis()->SetTitle("");
04589   hDpIDNQN_1->GetYaxis()->CenterTitle();
04590   hDpIDNQN_1->SetFillColor(0);
04591   hDpIDNQN_1->SetLineColor(1);
04592   hDpIDNQN_1->SetLineWidth(2);
04593   //hDpIDNQN_1->SetBit(TH1::kCanRebin);
04594 
04595   //vectors
04596   Int_t entries=static_cast<Int_t>(this->GetEntries());
04597   Int_t startTimeSecs=2000000000;//2 billion
04598   Int_t endTimeSecs=1;
04599   vector<Double_t> vPot;
04600   vPot.reserve(entries);
04601   vector<Double_t> vTime;
04602   vTime.reserve(entries);
04603   vector<Double_t> vPotBad;
04604   vPotBad.reserve(entries/10);
04605   vector<Double_t> vTimeBad;
04606   vTimeBad.reserve(entries/10);
04607   
04608   vector<Double_t> vTimeNuMuEvt;
04609   vTimeNuMuEvt.reserve(entries/5);
04610   vector<Double_t> vTimeNuMuBarEvt;
04611   vTimeNuMuBarEvt.reserve(entries/5);
04612  
04613   //maps to store evt info
04614   map<Int_t,Double_t> deltaTs;
04615   map<Int_t,Int_t> evtsPerSlc;
04616 
04617   //counters
04618   Int_t goodSpillCounter=0;
04619   Int_t badSpillCounter=0;
04620   Float_t totalPot=0;
04621   Float_t totalPotBad=0;
04622   Int_t evtCounter=0;
04623   Int_t evtNotlitime=0;
04624   Int_t evtNotIsLI=0;
04625   Int_t evtInFidVolCounter=0;
04626   Int_t evtWithTrkCounter=0;
04627   Int_t goodBestTrkCounter=0;
04628   Int_t goodTrkPassCounter=0;
04629   Int_t goodRecoEnCounter=0;
04630   Int_t goodUVDiffCounter=0;
04631   Int_t trkInFidVolCounter=0;
04632   Int_t goodFitSigQPCounter=0;
04633   Int_t goodFitProbCounter=0;
04634   Int_t goodFitChi2Counter=0;
04635   Int_t goodDeltaTCounter=0;
04636   Int_t goodEvtsPerSlcCounter=0; 
04637   Int_t goodPIDCounter=0;
04638   Int_t goodBeyondTrkEndCounter=0;
04639   Int_t goodShwFractCounter=0;
04640   Int_t nuNQCounter=0;
04641   Int_t nuPQCounter=0;
04642   
04643   string sTxtFilePrefix="nmbQCut"+config.sBeamType;
04644   ofstream& nmbTxt=*(this->OpenTxtFile(config,
04645                                        sTxtFilePrefix.c_str()));
04646   nmbTxt<<"# All NuMuBar like events (with standard CC cuts)"<<endl;
04647   nmbTxt<<"#"<<endl;
04648 
04649   sTxtFilePrefix="nmbQCut05"+config.sBeamType;
04650   ofstream& nmb05Txt=*(this->OpenTxtFile(config,
04651                                        sTxtFilePrefix.c_str()));
04652   nmb05Txt<<"# NuMuBar like events below 5 GeV (with standard CC cuts)"
04653           <<endl;
04654   nmb05Txt<<"#"<<endl;
04655 
04656   sTxtFilePrefix="nmbQCut02"+config.sBeamType;
04657   ofstream& nmb02Txt=*(this->OpenTxtFile(config,
04658                                        sTxtFilePrefix.c_str()));
04659   nmb02Txt<<"# NuMuBar like events below 2 GeV (with standard CC cuts)"
04660           <<endl;
04661   nmb02Txt<<"#"<<endl;
04662 
04663   //classes to organise the code in to related functions
04664   const NuCuts cuts;
04665   const NuGeneral general;
04666   const NuPlots plots;
04667   const NuReco reco;
04668   const NuExtraction ext;
04669   const NuBeam beam;
04670 
04671   //create these on the heap so that they don't destruct
04672   // - on purpose to avoid a segv on destruction... nice coding!
04673   NuMadAnalysis& mad=*new NuMadAnalysis();
04674   MadDpID& dp=*new MadDpID();
04675   //BeamType::BeamType_t beamType=BeamType::kLE;
04676   BeamType::BeamType_t beamType=static_cast
04677     <BeamType::BeamType_t>(config.beamType);
04678 
04679   //get an instance of the code library
04680   const NuLibrary& lib=NuLibrary::Instance();
04681  
04685   
04686   this->InitialiseLoopVariables();  
04687   
04688   //for(Int_t entry=0;entry<10000;entry++){
04689   for(Int_t entry=0;entry<this->GetEntries();entry++){
04690       
04691     this->SetLoopVariables(entry);
04692       
04693     //get reference to NtpStRecord from base class
04694     const NtpStRecord& ntp=(*this->GetNtpStRecord());
04695 
04696     const RecCandHeader& rec=ntp.GetHeader();
04697     MAXMSG("NuAnalysis",Msg::kInfo,5)
04698       <<"Found: run="<<rec.GetRun()
04699       <<", subrun="<<rec.GetSubRun()
04700       <<", detector="<<rec.GetVldContext().GetDetector()
04701       <<", simFlag="<<rec.GetVldContext().GetSimFlag()
04702       <<endl;
04703 
04704     //write out the detector, simflag, etc
04705     plots.FillGeneralHistos(ntp);
04706 
04707     //simple event object to hold important quantities for snarl
04708     NuEvent nuSnarl;
04709     
04710     //get the run, snarl, etc info
04711     ext.ExtractGeneralInfo(ntp,nuSnarl);
04712 
04713     if (!beam.IsGoodSpillAndFillPot
04714         (this->GetNtpBDLiteRecord(),config,nuSnarl)) {
04715       badSpillCounter++;
04716       totalPotBad+=nuSnarl.pot;
04717       continue;
04718     }
04719     goodSpillCounter++;
04720     totalPot+=nuSnarl.pot;    
04721 
04722     dp.ChoosePDFs(rec.GetVldContext().GetDetector(),beamType);
04723     mad.SetEntry(&ntp);
04724 
04725     TClonesArray& evtTca=(*ntp.evt);
04726     const Int_t numEvts=evtTca.GetEntriesFast();
04727 
04729     //loop over the reconstructed events
04731     for (Int_t ievt=0;ievt<numEvts;ievt++){
04732       const NtpSREvent& evt=
04733         *dynamic_cast<NtpSREvent*>(evtTca[ievt]);
04734       evtCounter++;
04735 
04736       const NtpSREventSummary& evthdr=ntp.evthdr;
04737       
04738       if (evthdr.litime!=-1) {
04739         MAXMSG("NuAnalysis",Msg::kInfo,500)
04740           <<"skipping event: litime="<<evthdr.litime<<endl;
04741         continue;
04742       }
04743       evtNotlitime++;
04744 
04745       Bool_t isLI=LISieve::IsLI(ntp);
04746       if (isLI){
04747         MAXMSG("NuAnalysis",Msg::kInfo,5)
04748           <<endl<<endl<<endl
04749           <<"Found LI"
04750           <<", run="<<config.run
04751           <<", entry="<<entry
04752           <<", event="<<ievt
04753           <<", litime="<<evthdr.litime
04754           <<endl<<endl<<endl;
04755       }
04756       else {
04757         MAXMSG("NuAnalysis",Msg::kDebug,50)
04758           <<"Not LI"
04759           <<", run="<<config.run
04760           <<", entry="<<entry
04761           <<", event="<<ievt
04762           <<", litime="<<evthdr.litime
04763           <<endl;
04764       }
04765       if (isLI) continue;
04766       evtNotIsLI++;
04767 
04768       //simple event object to hold important quantities
04769       NuEvent nu;
04770       
04771       //get the run, snarl, etc info
04772       ext.ExtractGeneralInfo(ntp,nu);
04773       
04774       Bool_t isInFidVol=cuts.IsInFidVol(evt.vtx.x,evt.vtx.y,
04775                                         evt.vtx.z,
04776                                         evt.vtx.u,evt.vtx.v,0,0,
04777                                         nu.detector,nu.anaVersion,
04778                                         nu.releaseType,nu.simFlag);
04779 
04780       if (!isInFidVol) continue;
04781       evtInFidVolCounter++;
04782 
04783       nu.dpID=dp.CalcPID(&mad,ievt,0);
04784       MAXMSG("NuAnalysis",Msg::kDebug,50)
04785         <<"dpID="<<nu.dpID<<endl;
04786       hDpIDAll->Fill(nu.dpID);
04787             
04788       //ensure there is a track in the event
04789       if (evt.ntrack<1) continue;
04790       //if (evt.ntrack!=1) continue;//require exactly 1 track
04791       evtWithTrkCounter++;
04792 
04793       //get the best track in the event
04794       Int_t bestTrack=lib.reco.GetBestTrack(nu);
04795       const NtpSRTrack* ptrk=lib.reco.GetTrackWithIndexX
04796         (ntp,evt,bestTrack-1);
04797       if (ptrk==0) continue;
04798       const NtpSRTrack& trk=*ptrk;
04799       goodBestTrkCounter++;
04800 
04801       //require a trk fit
04802       if (!trk.fit.pass) continue;
04803       goodTrkPassCounter++;
04804 
04805       
04807       //RECONSTRUCT the neutrino energy
04808       lib.reco.GetEvtEnergy(nu, false);
04809       goodRecoEnCounter++;
04810   
04811       //get the truth info (reco quantities are done above)
04812       reco.GetTruthInfo(ntp,evt,nu);
04813 
04814       //set the charge
04815       nu.charge=trk.momentum.qp<0 ? -1 : +1;
04816       if (trk.momentum.qp==0) nu.charge=0;
04817 
04818       //cut on the fractional track momentum and sign error      
04819       //if (!cuts.IsGoodSigmaQP_QP(nu)) continue;
04820       //goodFitSigQPCounter++;
04821       
04822       //cut on the track fit probability      
04823       //if (!cuts.IsGoodFitProb(nu)) continue;
04824       //goodFitProbCounter++;
04825 
04826       //Float_t chi2PerNdof=999999;
04827       //if (!cuts.IsGoodFitChi2PerNdof(nu)){
04828       //MAXMSG("NuAnalysis",Msg::kVerbose,100)
04829       //<<"Cutting out bad chi2PerNdof="<<chi2PerNdof<<endl;
04830       //continue;
04831       //}
04832       //goodFitChi2Counter++;
04833 
04834       //cut on the PID
04835       //if (!cuts.IsGoodDpID(nu)) continue;
04836       if (nu.dpID<=-0.1) continue;
04837       goodPIDCounter++;
04838       
04839       if (trk.momentum.qp<0) {
04840         hNuMuRecoEn->Fill(nu.energy);
04841         hNuMuRecoY->Fill(nu.y);
04842         hDpIDNQ->Fill(nu.dpID);
04843         nuNQCounter++;
04844       }
04845       else if (trk.momentum.qp>0) {
04846         string siaction="CC";
04847         if (nu.iaction==0) siaction="NC";
04848         //file format: run snarl event
04849         nmbTxt<<"#"<<endl;
04850         nmbTxt<<"# recoEn="<<nu.energy
04851               <<", trkEn="<<nu.trkEn
04852               <<", shwEn="<<nu.shwEn
04853               <<", recoy="<<nu.y
04854               <<", true inu="<<nu.inu
04855               <<" "<<siaction
04856               <<endl;
04857         nmbTxt<<nu.run<<" "<<nu.snarl<<" "<<nu.evt<<endl;
04858         if (nu.energy<5){
04859           nmb05Txt<<"#"<<endl;
04860           nmb05Txt<<"# recoEn="<<nu.energy
04861                   <<", trkEn="<<nu.trkEn
04862                   <<", shwEn="<<nu.shwEn
04863                   <<", recoy="<<nu.y
04864                   <<", true inu="<<nu.inu
04865                   <<" "<<siaction
04866                   <<endl;
04867           nmb05Txt<<nu.run<<" "<<nu.snarl<<" "<<nu.evt<<endl;
04868         }
04869 
04870         if (nu.energy<2){
04871           nmb02Txt<<"#"<<endl;
04872           nmb02Txt<<"# recoEn="<<nu.energy
04873                   <<", trkEn="<<nu.trkEn
04874                   <<", shwEn="<<nu.shwEn
04875                   <<", recoy="<<nu.y
04876                   <<", true inu="<<nu.inu
04877                   <<" "<<siaction
04878                   <<endl;
04879           nmb02Txt<<nu.run<<" "<<nu.snarl<<" "<<nu.evt<<endl;
04880         }
04881         
04882         hNuMuBarRecoEn->Fill(nu.energy);
04883         hNuMuBarRecoY->Fill(nu.y);
04884         hDpIDPQ->Fill(nu.dpID);
04885         nuPQCounter++;
04886       }
04887       else cout<<"ahhh, zero qp"<<endl;
04888 
04889       plots.FillXYZHistos(nu);
04890       plots.FillContainmentHistos(nu);
04891       plots.FillRelativeAngleHistos(nu);
04892       plots.FillTruePIDHistos(nu);
04893       plots.FillTrackResponseHistos(ntp,trk,nu);
04894       plots.FillRangeCurvCompHistos(nu);
04895     }
04896   }//end of for                                       
04897   
04901 
04902   MSG("NuAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
04903 
04904   //store the number of files added to the chain
04905   Int_t nf=this->GetNumFilesAddedToChain();
04906   TH1F* hRun=dynamic_cast<TH1F*>(gROOT->FindObject("hRun"));
04907   Float_t nr=-1;
04908   if (hRun) nr=hRun->GetEntries();
04909   TH1F* hNumFiles=new TH1F("hNumFiles","hNumFiles",15,-5,10);
04910   hNumFiles->Fill(1,nf);//store as weight, access with GetMaximum
04911   MSG("NuAnalysis",Msg::kInfo)
04912     <<"Files added to chain="<<hNumFiles->GetMaximum()
04913     <<", runs found="<<nr<<endl;
04914 
04915   MSG("NuAnalysis",Msg::kInfo)
04916     <<"Found start time and end time: "
04917     <<startTimeSecs<<" -> "<<endTimeSecs<<endl;
04918   general.EpochTo1995(endTimeSecs);
04919   general.EpochTo1995(startTimeSecs);
04920   
04921   MSG("NuAnalysis",Msg::kInfo)<<"Filling vs. Time plots..."<<endl;
04922   TH1F* hSpillsVsTime=new TH1F("hSpillsVsTime","hSpillsVsTime",
04923                                100,startTimeSecs,endTimeSecs);
04924   general.TH1FFill(hSpillsVsTime,vTime);
04925   general.SetGraphAxis(hSpillsVsTime->GetXaxis(),
04926                      startTimeSecs,endTimeSecs);
04927   hSpillsVsTime->GetXaxis()->CenterTitle();
04928   hSpillsVsTime->GetYaxis()->SetTitle("Spills");
04929   hSpillsVsTime->GetYaxis()->CenterTitle();
04930 
04931   TH1F* hSpillsBadVsTime=new TH1F("hSpillsBadVsTime","hSpillsBadVsTime",
04932                                   100,startTimeSecs,endTimeSecs);
04933   general.TH1FFill(hSpillsBadVsTime,vTimeBad);
04934   general.SetGraphAxis(hSpillsBadVsTime->GetXaxis(),
04935                      startTimeSecs,endTimeSecs);
04936   hSpillsBadVsTime->GetXaxis()->CenterTitle();
04937   hSpillsBadVsTime->GetYaxis()->SetTitle("Spills");
04938   hSpillsBadVsTime->GetYaxis()->CenterTitle();
04939   
04940   TH1F* hNuMuVsTime=new TH1F("hNuMuVsTime","hNuMuVsTime",
04941                              100,startTimeSecs,endTimeSecs);
04942   general.TH1FFill(hNuMuVsTime,vTimeNuMuEvt);
04943   general.SetGraphAxis(hNuMuVsTime->GetXaxis(),
04944                      startTimeSecs,endTimeSecs);
04945   hNuMuVsTime->GetXaxis()->CenterTitle();
04946   hNuMuVsTime->GetYaxis()->SetTitle("#nu_#mu events");
04947   hNuMuVsTime->GetYaxis()->CenterTitle();
04948 
04949   TH1F* hNuMuBarVsTime=new TH1F("hNuMuBarVsTime","hNuMuBarVsTime",
04950                                100,startTimeSecs,endTimeSecs);
04951   general.TH1FFill(hNuMuBarVsTime,vTimeNuMuBarEvt);
04952   general.SetGraphAxis(hNuMuBarVsTime->GetXaxis(),
04953                      startTimeSecs,endTimeSecs);
04954   hNuMuBarVsTime->GetXaxis()->CenterTitle();
04955   hNuMuBarVsTime->GetYaxis()->SetTitle("#bar{#nu_#mu} events");
04956   hNuMuBarVsTime->GetYaxis()->CenterTitle();
04957 
04958   TH1F* hPotVsTime=new TH1F("hPotVsTime","hPotVsTime",
04959                              100,startTimeSecs,endTimeSecs);
04960   general.TH1FFill(hPotVsTime,vTime,vPot);
04961   general.SetGraphAxis(hPotVsTime->GetXaxis(),
04962                      startTimeSecs,endTimeSecs);
04963   hPotVsTime->GetXaxis()->CenterTitle();
04964   hPotVsTime->GetYaxis()->SetTitle("POT");
04965   hPotVsTime->GetYaxis()->CenterTitle();
04966 
04967   TH1F* hPotBadVsTime=new TH1F("hPotBadVsTime","hPotBadVsTime",
04968                              100,startTimeSecs,endTimeSecs);
04969   general.TH1FFill(hPotBadVsTime,vTimeBad,vPotBad);
04970   general.SetGraphAxis(hPotBadVsTime->GetXaxis(),
04971                      startTimeSecs,endTimeSecs);
04972   hPotBadVsTime->GetXaxis()->CenterTitle();
04973   hPotBadVsTime->GetYaxis()->SetTitle("POT");
04974   hPotBadVsTime->GetYaxis()->CenterTitle();
04975   
04976   Float_t totalPotHist=0;
04977   Float_t totalPotBadHist=0;
04978   cuts.CalcTotalPot(totalPotHist,totalPotBadHist);
04979   Float_t pcPotRejected=0;
04980   if (totalPotHist) pcPotRejected=100.*totalPotBadHist/totalPotHist;
04981 
04982   //msg was giving pots=412886000000000000.000000... still is for MC!
04983   cout<<"Number of spills     ="<<this->GetEntries()<<endl
04984       <<"Number of good spills="<<goodSpillCounter<<endl
04985       <<"Number of bad spills ="<<badSpillCounter<<endl
04986       <<"Sum of good+bad spill="<<badSpillCounter+goodSpillCounter<<endl
04987       <<endl
04988       <<"Total POT good       ="<<totalPot*1e12<<endl
04989       <<"Total POT bad        ="<<totalPotBad*1e12<<endl
04990       <<"Total POT good (hist)="<<totalPotHist*1e12<<endl
04991       <<"Total POT bad  (hist)="<<totalPotBadHist*1e12
04992       <<"  ("<<pcPotRejected<<"%)"<<endl;
04993 
04994   MSG("NuAnalysis",Msg::kInfo)
04995     <<endl<<"*************************************"<<endl
04996     <<"Total Events    ="<<evtCounter<<endl
04997     <<"Evt not litime  ="<<evtNotlitime<<endl
04998     <<"Evt not IsLI    ="<<evtNotIsLI<<endl
04999     <<"Evts in Fid     ="<<evtInFidVolCounter<<endl
05000     <<"Evts w/ Trk     ="<<evtWithTrkCounter<<endl
05001     <<"Good Best Trk   ="<<goodBestTrkCounter<<endl
05002     <<"Track Pass      ="<<goodTrkPassCounter<<endl
05003     <<"Good reco energy="<<goodRecoEnCounter<<endl
05004     <<"Good UVDiff     ="<<goodUVDiffCounter<<endl
05005     <<"Trk Vtx in Fid  ="<<trkInFidVolCounter<<endl
05006     <<"Good Fit SigQP  ="<<goodFitSigQPCounter<<endl
05007     <<"Good Fit Prob   ="<<goodFitProbCounter<<endl
05008     <<"Good Fit Chi2   ="<<goodFitChi2Counter<<endl
05009     <<"Good Delta T    ="<<goodDeltaTCounter<<endl
05010     <<"Good EvtPerSlc  ="<<goodEvtsPerSlcCounter<<endl
05011     <<"Good DP ID      ="<<goodPIDCounter<<endl
05012     <<"Good beyond tEnd="<<goodBeyondTrkEndCounter<<endl
05013     <<"Good shw fract  ="<<goodShwFractCounter<<endl
05014     <<"*************************************"<<endl;
05015 
05016   Float_t pcPQ=0;
05017   if (nuPQCounter+nuNQCounter>0) pcPQ=100.*nuPQCounter/
05018                                    (nuPQCounter+nuNQCounter);
05019   MSG("NuAnalysis",Msg::kInfo)
05020     <<endl
05021     <<"Neutrinos with NQ="<<nuNQCounter<<endl
05022     <<"Neutrinos with PQ="<<nuPQCounter
05023     <<"   ("<<pcPQ<<"%)"<<endl
05024     <<"Sum NQ+PQ        ="<<nuNQCounter+nuPQCounter<<endl
05025     <<endl;
05026   
05027   MSG("NuAnalysis",Msg::kInfo) 
05028     <<" ** Finished ChargeSignCut method **"<<endl;
05029 }
05030 
05031 //......................................................................
05032 
05033 void NuAnalysis::EnergySpect()
05034 {
05035   MSG("NuAnalysis",Msg::kInfo) 
05036     <<" ** Running EnergySpect method... **"<<endl;
05037   
05038   NuConfig config;
05039   this->ExtractConfig(config);
05040 
05041   //open the output file for the histograms
05042   string sFilePrefix="NMBEnSp"+config.sBeamType;
05043   fOutFile=this->OpenFile(config,sFilePrefix.c_str());
05044 
05045   TH1F* hNuMuBarRecoEn=new TH1F("hNuMuBarRecoEn","hNuMuBarRecoEn",
05046                                 4*352,-32,320);
05047   hNuMuBarRecoEn->GetXaxis()->SetTitle("Energy (GeV)");
05048   hNuMuBarRecoEn->GetXaxis()->CenterTitle();
05049   hNuMuBarRecoEn->GetYaxis()->SetTitle("");
05050   hNuMuBarRecoEn->GetYaxis()->CenterTitle();
05051   hNuMuBarRecoEn->SetFillColor(0);
05052   hNuMuBarRecoEn->SetLineColor(2);
05053   //hNuMuBarRecoEn->SetBit(TH1::kCanRebin);
05054   
05055   TH1F* hNuMuRecoEn=new TH1F("hNuMuRecoEn","hNuMuRecoEn",4*352,-32,320);
05056   hNuMuRecoEn->GetXaxis()->SetTitle("Energy (GeV)");
05057   hNuMuRecoEn->GetXaxis()->CenterTitle();
05058   hNuMuRecoEn->GetYaxis()->SetTitle("");
05059   hNuMuRecoEn->GetYaxis()->CenterTitle();
05060   hNuMuRecoEn->SetFillColor(0);
05061   hNuMuRecoEn->SetLineColor(1);
05062   hNuMuRecoEn->SetLineWidth(2);
05063   //hNuMuRecoEn->SetBit(TH1::kCanRebin);
05064 
05065   TH1F* hNuMuBarRecoY=new TH1F("hNuMuBarRecoY","hNuMuBarRecoY",
05066                                 4*144,-0.16,1.28);
05067   hNuMuBarRecoY->GetXaxis()->SetTitle("y");
05068   hNuMuBarRecoY->GetXaxis()->CenterTitle();
05069   hNuMuBarRecoY->GetYaxis()->SetTitle("");
05070   hNuMuBarRecoY->GetYaxis()->CenterTitle();
05071   hNuMuBarRecoY->SetFillColor(0);
05072   hNuMuBarRecoY->SetLineColor(2);
05073   //hNuMuBarRecoY->SetBit(TH1::kCanRebin);
05074   
05075   TH1F* hNuMuRecoY=new TH1F("hNuMuRecoY","hNuMuRecoY",4*144,-0.16,1.28);
05076   hNuMuRecoY->GetXaxis()->SetTitle("y");
05077   hNuMuRecoY->GetXaxis()->CenterTitle();
05078   hNuMuRecoY->GetYaxis()->SetTitle("");
05079   hNuMuRecoY->GetYaxis()->CenterTitle();
05080   hNuMuRecoY->SetFillColor(0);
05081   hNuMuRecoY->SetLineColor(1);
05082   hNuMuRecoY->SetLineWidth(2);
05083   //hNuMuRecoY->SetBit(TH1::kCanRebin);
05084 
05085   TH1F* hDpIDAll=new TH1F("hDpIDAll","hDpIDAll",4*160,-1.6,1.6);
05086   hDpIDAll->GetXaxis()->SetTitle("PID (from MadDpID)");
05087   hDpIDAll->GetXaxis()->CenterTitle();
05088   hDpIDAll->GetYaxis()->SetTitle("");
05089   hDpIDAll->GetYaxis()->CenterTitle();
05090   hDpIDAll->SetFillColor(0);
05091   hDpIDAll->SetLineColor(1);
05092   hDpIDAll->SetLineWidth(2);
05093   //hDpIDAll->SetBit(TH1::kCanRebin);
05094 
05095   TH1F* hDpIDPQ=new TH1F("hDpIDPQ","hDpIDPQ",4*160,-1.6,1.6);
05096   hDpIDPQ->GetXaxis()->SetTitle("PID (from MadDpID)");
05097   hDpIDPQ->GetXaxis()->CenterTitle();
05098   hDpIDPQ->GetYaxis()->SetTitle("");
05099   hDpIDPQ->GetYaxis()->CenterTitle();
05100   hDpIDPQ->SetFillColor(0);
05101   hDpIDPQ->SetLineColor(1);
05102   hDpIDPQ->SetLineWidth(2);
05103   //hDpIDPQ->SetBit(TH1::kCanRebin);
05104 
05105   TH1F* hDpIDNQ=new TH1F("hDpIDNQ","hDpIDNQ",4*160,-1.6,1.6);
05106   hDpIDNQ->GetXaxis()->SetTitle("PID (from MadDpID)");
05107   hDpIDNQ->GetXaxis()->CenterTitle();
05108   hDpIDNQ->GetYaxis()->SetTitle("");
05109   hDpIDNQ->GetYaxis()->CenterTitle();
05110   hDpIDNQ->SetFillColor(0);
05111   hDpIDNQ->SetLineColor(1);
05112   hDpIDNQ->SetLineWidth(2);
05113   //hDpIDNQ->SetBit(TH1::kCanRebin);
05114 
05115   TH1F* hDpIDPQN_1=new TH1F("hDpIDPQN_1","hDpIDPQN_1",4*160,-1.6,1.6);
05116   hDpIDPQN_1->GetXaxis()->SetTitle("PID (from MadDpID)");
05117   hDpIDPQN_1->GetXaxis()->CenterTitle();
05118   hDpIDPQN_1->GetYaxis()->SetTitle("");
05119   hDpIDPQN_1->GetYaxis()->CenterTitle();
05120   hDpIDPQN_1->SetFillColor(0);
05121   hDpIDPQN_1->SetLineColor(1);
05122   hDpIDPQN_1->SetLineWidth(2);
05123   //hDpIDPQN_1->SetBit(TH1::kCanRebin);
05124 
05125   TH1F* hDpIDNQN_1=new TH1F("hDpIDNQN_1","hDpIDNQN_1",4*160,-1.6,1.6);
05126   hDpIDNQN_1->GetXaxis()->SetTitle("PID (from MadDpID)");
05127   hDpIDNQN_1->GetXaxis()->CenterTitle();
05128   hDpIDNQN_1->GetYaxis()->SetTitle("");
05129   hDpIDNQN_1->GetYaxis()->CenterTitle();
05130   hDpIDNQN_1->SetFillColor(0);
05131   hDpIDNQN_1->SetLineColor(1);
05132   hDpIDNQN_1->SetLineWidth(2);
05133   //hDpIDNQN_1->SetBit(TH1::kCanRebin);
05134 
05135   //vectors
05136   Int_t entries=static_cast<Int_t>(this->GetEntries());
05137   Int_t startTimeSecs=2000000000;//2 billion
05138   Int_t endTimeSecs=1;
05139   vector<Double_t> vPot;
05140   vPot.reserve(entries);
05141   vector<Double_t> vTime;
05142   vTime.reserve(entries);
05143   vector<Double_t> vPotBad;
05144   vPotBad.reserve(entries/10);
05145   vector<Double_t> vTimeBad;
05146   vTimeBad.reserve(entries/10);
05147   
05148   vector<Double_t> vTimeNuMuEvt;
05149   vTimeNuMuEvt.reserve(entries/5);
05150   vector<Double_t> vTimeNuMuBarEvt;
05151   vTimeNuMuBarEvt.reserve(entries/5);
05152  
05153   //maps to store evt info
05154   map<Int_t,Double_t> deltaTs;
05155   map<Int_t,Int_t> evtsPerSlc;
05156 
05157   //counters
05158   Int_t goodSpillCounter=0;
05159   Int_t badSpillCounter=0;
05160   Float_t totalPot=0;
05161   Float_t totalPotBad=0;
05162   Int_t evtCounter=0;
05163   Int_t evtNotlitime=0;
05164   Int_t evtNotIsLI=0;
05165   Int_t evtInFidVolCounter=0;
05166   Int_t evtWithTrkCounter=0;
05167   Int_t goodBestTrkCounter=0;
05168   Int_t goodTrkPassCounter=0;
05169   Int_t goodRecoEnCounter=0;
05170   Int_t goodUVDiffCounter=0;
05171   Int_t trkInFidVolCounter=0;
05172   Int_t goodFitSigQPCounter=0;
05173   Int_t goodFitProbCounter=0;
05174   Int_t goodFitChi2Counter=0;
05175   Int_t goodDeltaTCounter=0;
05176   Int_t goodEvtsPerSlcCounter=0; 
05177   Int_t goodPIDCounter=0;
05178   Int_t goodBeyondTrkEndCounter=0;
05179   Int_t goodShwFractCounter=0;
05180   Int_t nuNQCounter=0;
05181   Int_t nuPQCounter=0;
05182   
05183   string sTxtFilePrefix="nmb"+config.sBeamType;
05184   ofstream& nmbTxt=*(this->OpenTxtFile(config,
05185                                        sTxtFilePrefix.c_str()));
05186 
05187   //classes to organise the code in to related functions
05188   const NuCuts cuts;
05189   const NuGeneral general;
05190   const NuPlots plots;
05191   const NuReco reco;
05192   const NuExtraction ext;
05193   const NuBeam beam;
05194 
05195   //create these on the heap so that they don't destruct
05196   // - on purpose to avoid a segv on destruction... nice coding!
05197   NuMadAnalysis& mad=*new NuMadAnalysis();
05198   MadDpID& dp=*new MadDpID();
05199   //BeamType::BeamType_t beamType=BeamType::kLE;
05200   BeamType::BeamType_t beamType=static_cast
05201     <BeamType::BeamType_t>(config.beamType);
05202  
05203   //define the analysis (cuts and reco) to use
05204   NuCuts::NuAnaVersion_t anaVersion=NuCuts::kJJH1;
05205   
05206   //get an instance of the code library
05207   const NuLibrary& lib=NuLibrary::Instance();
05208   
05212   
05213   cout<<endl
05214       <<"************************************************"<<endl
05215       <<"***      Starting main loop over snarls      ***"<<endl
05216       <<"************************************************"<<endl;
05217 
05218   this->InitialiseLoopVariables();  
05219   
05220   //for(Int_t entry=12100;entry<this->GetEntries();entry++){
05221   for(Int_t entry=0;entry<this->GetEntries();entry++){
05222       
05223     this->SetLoopVariables(entry);
05224       
05225     //get reference to NtpStRecord from base class
05226     const NtpStRecord& ntp=(*this->GetNtpStRecord());
05227 
05228     const RecCandHeader& rec=ntp.GetHeader();
05229     MAXMSG("NuAnalysis",Msg::kInfo,5)
05230       <<"Found: run="<<rec.GetRun()
05231       <<", subrun="<<rec.GetSubRun()
05232       <<", detector="<<rec.GetVldContext().GetDetector()
05233       <<", simFlag="<<rec.GetVldContext().GetSimFlag()
05234       <<endl;
05235 
05236     //write out the detector, simflag, etc
05237     plots.FillGeneralHistos(ntp);
05238 
05239     //simple event object to hold important quantities for snarl
05240     NuEvent nuSnarl;
05241     //set the analysis (cuts and reco) version to use
05242     nuSnarl.anaVersion=anaVersion;
05243     //get the run, snarl, etc info
05244     ext.ExtractGeneralInfo(ntp,nuSnarl);
05245 
05246     //get the true energy spectra of events in the fid vol
05247     plots.FillTrueFidEnergySpect(nuSnarl);
05248 
05249     Int_t evTime=rec.GetVldContext().GetTimeStamp().GetSec();
05250     //get the min and max times
05251     if (evTime>endTimeSecs) endTimeSecs=evTime;
05252     if (evTime<startTimeSecs && evTime>0) startTimeSecs=evTime;
05253     if (evTime<=0) cout<<"Bad time="<<evTime<<endl;
05254     //convert to 1995 time
05255     general.EpochTo1995(evTime);
05256     
05257     if (!beam.IsGoodSpillAndFillPot
05258         (this->GetNtpBDLiteRecord(),config,nuSnarl)) {
05259       badSpillCounter++;
05260       totalPotBad+=nuSnarl.pot;
05261       vPotBad.push_back(nuSnarl.pot*1e12);
05262       vTimeBad.push_back(evTime);
05263       continue;
05264     }
05265     goodSpillCounter++;
05266     totalPot+=nuSnarl.pot;    
05267     vPot.push_back(nuSnarl.pot*1e12);
05268     vTime.push_back(evTime);
05269 
05270     dp.ChoosePDFs(rec.GetVldContext().GetDetector(),beamType,
05271                   ReleaseType::AsString(nuSnarl.releaseType),
05272                   ReleaseType::AsString(nuSnarl.releaseType));
05273     mad.SetEntry(&ntp);
05274 
05275     TClonesArray& evtTca=(*ntp.evt);
05276     const Int_t numEvts=evtTca.GetEntriesFast();
05277 
05279     //loop over the reconstructed events
05281     for (Int_t ievt=0;ievt<numEvts;ievt++){
05282       const NtpSREvent& evt=
05283         *dynamic_cast<NtpSREvent*>(evtTca[ievt]);
05284       evtCounter++;
05285 
05286       const NtpSREventSummary& evthdr=ntp.evthdr;
05287       
05288       if (evthdr.litime!=-1) {
05289         MAXMSG("NuAnalysis",Msg::kInfo,500)
05290           <<"skipping event: litime="<<evthdr.litime<<endl;
05291         continue;
05292       }
05293       evtNotlitime++;
05294 
05295       Bool_t isLI=LISieve::IsLI(ntp);
05296       if (isLI){
05297         MAXMSG("NuAnalysis",Msg::kInfo,50)
05298           <<"Found LI"
05299           <<", run="<<config.run
05300           <<", entry="<<entry
05301           <<", event="<<ievt
05302           <<", litime="<<evthdr.litime
05303           <<endl;
05304       }
05305       else {
05306         MAXMSG("NuAnalysis",Msg::kInfo,50)
05307           <<"Not LI"
05308           <<", run="<<config.run
05309           <<", entry="<<entry
05310           <<", event="<<ievt
05311           <<", litime="<<evthdr.litime
05312           <<endl;
05313       }
05314       if (isLI) continue;
05315       evtNotIsLI++;
05316 
05317       //simple event object to hold important quantities
05318       NuEvent nu;
05319       
05320       //get the run, snarl, etc info
05321       ext.ExtractGeneralInfo(ntp,nu);
05322       //get info from the evt
05323       lib.ext.ExtractEvtInfo(evt,nu);
05324       //extract trk info (needed to get best track info)
05325       lib.ext.ExtractTrkInfo(ntp,evt,nu);
05326       //extract shw info
05327       lib.ext.ExtractShwInfo(ntp,evt,nu);
05328       
05329       Bool_t isInFidVol=cuts.IsInFidVol(evt.vtx.x,evt.vtx.y,
05330                                         evt.vtx.z,
05331                                         evt.vtx.u,evt.vtx.v,0,0,
05332                                         nu.detector,nu.anaVersion,
05333                                         nu.releaseType,nu.simFlag);
05334 
05335       if (!isInFidVol) continue;
05336       evtInFidVolCounter++;
05337 
05338       nu.dpID=dp.CalcPID(&mad,ievt,0);
05339       MAXMSG("NuAnalysis",Msg::kDebug,50)
05340         <<"dpID="<<nu.dpID<<endl;
05341       hDpIDAll->Fill(nu.dpID);
05342             
05343       //ensure there is a track in the event
05344       //if (evt.ntrack<1) continue;
05345       if (evt.ntrack!=1) continue;//require exactly 1 track
05346       evtWithTrkCounter++;
05347 
05348       //get the best track in the event
05349       Int_t bestTrack=lib.reco.GetBestTrack(nu);
05350       const NtpSRTrack* ptrk=lib.reco.GetTrackWithIndexX
05351         (ntp,evt,bestTrack-1);
05352       if (ptrk==0) continue;
05353       const NtpSRTrack& trk=*ptrk;
05354       goodBestTrkCounter++;
05355 
05356       //require a trk fit
05357       if (!trk.fit.pass) continue;
05358       goodTrkPassCounter++;
05359       
05361       //RECONSTRUCT the neutrino energy
05362       lib.reco.GetEvtEnergy(nu, false);
05363       goodRecoEnCounter++;
05364   
05365       //get the truth info (reco quantities are done above)
05366       reco.GetTruthInfo(ntp,evt,nu);
05367 
05368       if (!cuts.IsGoodUVVtx(nu)){
05369         continue;
05370       }
05371       goodUVDiffCounter++;
05372 
05373       //check if the trk is in the fiducial volume
05374       Bool_t isTrkInFidVol=cuts.IsInFidVol(trk.vtx.x,trk.vtx.y,
05375                                            trk.vtx.z,
05376                                            trk.vtx.u,trk.vtx.v,0,0,
05377                                            nu.detector,nu.anaVersion,
05378                                            nu.releaseType,nu.simFlag);
05379       if (!isTrkInFidVol) continue;
05380       trkInFidVolCounter++;
05381       
05382       plots.FillSigmaQPPlots(nu);
05383       plots.FillTrueDpIDHistos(nu);
05384 
05385       //set the charge
05386       nu.charge=trk.momentum.qp<0 ? -1 : 1;
05387       if (trk.momentum.qp==0) nu.charge=0;
05388 
05389       //cut on the fractional track momentum and sign error      
05390       if (!cuts.IsGoodSigmaQP_QP(nu)) continue;
05391       goodFitSigQPCounter++;
05392       
05393       //cut on the track fit probability      
05394       if (!cuts.IsGoodFitProb(nu)) continue;
05395       goodFitProbCounter++;
05396 
05397       Float_t chi2PerNdof=999999;
05398       if (!cuts.IsGoodFitChi2PerNdof(nu)){
05399         MAXMSG("NuAnalysis",Msg::kVerbose,100)
05400           <<"Cutting out bad chi2PerNdof="<<chi2PerNdof<<endl;
05401         continue;
05402       }
05403       goodFitChi2Counter++;
05404 
05405       //get the maps of evts' info
05406       deltaTs.clear();
05407       reco.GetEvtDeltaTs(ntp,deltaTs);
05408       evtsPerSlc.clear();
05409       reco.GetEvtsPerSlc(ntp,evtsPerSlc);      
05410       MsgFormat ffmt("%9.9f");
05411       MAXMSG("NuReco",Msg::kDebug,100)
05412         <<"smallestDelta="<<ffmt(deltaTs[ievt])
05413         <<", evtsPerSlc="<<evtsPerSlc[evt.slc]<<endl;
05414 
05415       //only do the cut for the ND
05416       if (config.detector==Detector::kNear && 
05417           deltaTs[ievt]<50*Munits::ns) continue;
05418       goodDeltaTCounter++;
05419 
05420       //only do the cut for the ND
05421       if (config.detector==Detector::kNear && 
05422           evtsPerSlc[evt.slc]!=1) continue;
05423       goodEvtsPerSlcCounter++;
05424 
05425       plots.FillTrueDpIDHistosPQNQ(nu);
05426       if (trk.momentum.qp<0) {
05427         hDpIDNQN_1->Fill(nu.dpID);
05428       }
05429       else if (trk.momentum.qp>0) {
05430         hDpIDPQN_1->Fill(nu.dpID);
05431       }
05432 
05433       //cut on the PID
05434       if (!cuts.IsGoodDpID(nu)) continue;
05435       goodPIDCounter++;
05436       
05437       Float_t sigCorBeyond=0;
05438       goodBeyondTrkEndCounter++;
05439 
05440       Float_t fractFull=0;
05441       //if (!cuts.IsGoodShwFract(ntp,evt,nu,&fractFull)) continue;
05442       goodShwFractCounter++;
05443 
05444       Float_t evtTrkVtxDiff=evt.plane.beg-trk.plane.beg;
05445       
05446       //reco.PrintTrueEnergy(ntp,evt,nu.energy);
05447       
05448       if (trk.momentum.qp<0) {
05449         hNuMuRecoEn->Fill(nu.energy);
05450         hNuMuRecoY->Fill(nu.y);
05451         hDpIDNQ->Fill(nu.dpID);
05452         vTimeNuMuEvt.push_back(evTime);
05453         nuNQCounter++;
05454       }
05455       else if (trk.momentum.qp>0) {
05456         //file format: run snarl event
05457         nmbTxt<<nu.run<<" "<<nu.snarl<<" "<<nu.evt<<endl;
05458         string sStop="PC";
05459         if (nu.containmentFlag==1 || 
05460             nu.containmentFlag==3) sStop="FC";
05461         
05462         Float_t dRng=999999;
05463         if (nu.trkEnMC) dRng=(nu.trkEnRange-nu.trkEnMC)/nu.trkEnMC;
05464         nmbTxt<<"# "
05465               <<sStop<<nu.containmentFlag
05466               <<", dRng="<<dRng
05467               <<", beyond="<<sigCorBeyond
05468               <<", frFull="<<fractFull
05469               <<", e-tVtx="<<evtTrkVtxDiff
05470               <<endl;
05471         nmbTxt<<"# "<<endl;//leave a line
05472 
05473         hNuMuBarRecoEn->Fill(nu.energy);
05474         hNuMuBarRecoY->Fill(nu.y);
05475         hDpIDPQ->Fill(nu.dpID);
05476         vTimeNuMuBarEvt.push_back(evTime);
05477         nuPQCounter++;
05478       }
05479       else cout<<"ahhh, zero qp"<<endl;
05480       
05481       plots.FillRecoEnYHistosN(nu);
05482       plots.FillDPIdSigmaQPPlotsN(nu);
05483 
05484       plots.FillShwHistos(ntp,evt,nu);
05485       plots.FillXYZHistos(nu);
05486       plots.FillContainmentHistos(nu);
05487       plots.FillTruePIDHistos(nu);
05488       plots.FillTrackResponseHistos(ntp,trk,nu);
05489     }
05490   }//end of for                                       
05491   
05495 
05496   MSG("NuAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
05497 
05498   MSG("NuAnalysis",Msg::kInfo)
05499     <<"Found start time and end time: "
05500     <<startTimeSecs<<" -> "<<endTimeSecs<<endl;
05501   general.EpochTo1995(endTimeSecs);
05502   general.EpochTo1995(startTimeSecs);
05503   
05504   MSG("NuAnalysis",Msg::kInfo)<<"Filling vs. Time plots..."<<endl;
05505   TH1F* hSpillsVsTime=new TH1F("hSpillsVsTime","hSpillsVsTime",
05506                                100,startTimeSecs,endTimeSecs);
05507   general.TH1FFill(hSpillsVsTime,vTime);
05508   general.SetGraphAxis(hSpillsVsTime->GetXaxis(),
05509                      startTimeSecs,endTimeSecs);
05510   hSpillsVsTime->GetXaxis()->CenterTitle();
05511   hSpillsVsTime->GetYaxis()->SetTitle("Spills");
05512   hSpillsVsTime->GetYaxis()->CenterTitle();
05513 
05514   TH1F* hSpillsBadVsTime=new TH1F("hSpillsBadVsTime","hSpillsBadVsTime",
05515                                   100,startTimeSecs,endTimeSecs);
05516   general.TH1FFill(hSpillsBadVsTime,vTimeBad);
05517   general.SetGraphAxis(hSpillsBadVsTime->GetXaxis(),
05518                      startTimeSecs,endTimeSecs);
05519   hSpillsBadVsTime->GetXaxis()->CenterTitle();
05520   hSpillsBadVsTime->GetYaxis()->SetTitle("Spills");
05521   hSpillsBadVsTime->GetYaxis()->CenterTitle();
05522   
05523   TH1F* hNuMuVsTime=new TH1F("hNuMuVsTime","hNuMuVsTime",
05524                              100,startTimeSecs,endTimeSecs);
05525   general.TH1FFill(hNuMuVsTime,vTimeNuMuEvt);
05526   general.SetGraphAxis(hNuMuVsTime->GetXaxis(),
05527                      startTimeSecs,endTimeSecs);
05528   hNuMuVsTime->GetXaxis()->CenterTitle();
05529   hNuMuVsTime->GetYaxis()->SetTitle("#nu_#mu events");
05530   hNuMuVsTime->GetYaxis()->CenterTitle();
05531 
05532   TH1F* hNuMuBarVsTime=new TH1F("hNuMuBarVsTime","hNuMuBarVsTime",
05533                                100,startTimeSecs,endTimeSecs);
05534   general.TH1FFill(hNuMuBarVsTime,vTimeNuMuBarEvt);
05535   general.SetGraphAxis(hNuMuBarVsTime->GetXaxis(),
05536                      startTimeSecs,endTimeSecs);
05537   hNuMuBarVsTime->GetXaxis()->CenterTitle();
05538   hNuMuBarVsTime->GetYaxis()->SetTitle("#bar{#nu_#mu} events");
05539   hNuMuBarVsTime->GetYaxis()->CenterTitle();
05540 
05541   TH1F* hPotVsTime=new TH1F("hPotVsTime","hPotVsTime",
05542                              100,startTimeSecs,endTimeSecs);
05543   general.TH1FFill(hPotVsTime,vTime,vPot);
05544   general.SetGraphAxis(hPotVsTime->GetXaxis(),
05545                      startTimeSecs,endTimeSecs);
05546   hPotVsTime->GetXaxis()->CenterTitle();
05547   hPotVsTime->GetYaxis()->SetTitle("POT");
05548   hPotVsTime->GetYaxis()->CenterTitle();
05549 
05550   TH1F* hPotBadVsTime=new TH1F("hPotBadVsTime","hPotBadVsTime",
05551                              100,startTimeSecs,endTimeSecs);
05552   general.TH1FFill(hPotBadVsTime,vTimeBad,vPotBad);
05553   general.SetGraphAxis(hPotBadVsTime->GetXaxis(),
05554                      startTimeSecs,endTimeSecs);
05555   hPotBadVsTime->GetXaxis()->CenterTitle();
05556   hPotBadVsTime->GetYaxis()->SetTitle("POT");
05557   hPotBadVsTime->GetYaxis()->CenterTitle();
05558   
05559   Float_t totalPotHist=0;
05560   Float_t totalPotBadHist=0;
05561   cuts.CalcTotalPot(totalPotHist,totalPotBadHist);
05562   Float_t pcPotRejected=0;
05563   if (totalPotHist) pcPotRejected=100.*totalPotBadHist/totalPotHist;
05564 
05565   //msg was giving pots=412886000000000000.000000... still is for MC!
05566   cout<<"Number of spills     ="<<this->GetEntries()<<endl
05567       <<"Number of good spills="<<goodSpillCounter<<endl
05568       <<"Number of bad spills ="<<badSpillCounter<<endl
05569       <<"Sum of good+bad spill="<<badSpillCounter+goodSpillCounter<<endl
05570       <<endl
05571       <<"Total POT good       ="<<totalPot*1e12<<endl
05572       <<"Total POT bad        ="<<totalPotBad*1e12<<endl
05573       <<"Total POT good (hist)="<<totalPotHist*1e12<<endl
05574       <<"Total POT bad  (hist)="<<totalPotBadHist*1e12
05575       <<"  ("<<pcPotRejected<<"%)"<<endl;
05576 
05577   MSG("NuAnalysis",Msg::kInfo)
05578     <<endl<<"*************************************"<<endl
05579     <<"Total Events    ="<<evtCounter<<endl
05580     <<"Evt not litime  ="<<evtNotlitime<<endl
05581     <<"Evt not IsLI    ="<<evtNotIsLI<<endl
05582     <<"Evts in Fid     ="<<evtInFidVolCounter<<endl
05583     <<"Evts w/ Trk     ="<<evtWithTrkCounter<<endl
05584     <<"Good Best Trk   ="<<goodBestTrkCounter<<endl
05585     <<"Track Pass      ="<<goodTrkPassCounter<<endl
05586     <<"Good reco energy="<<goodRecoEnCounter<<endl
05587     <<"Good UVDiff     ="<<goodUVDiffCounter<<endl
05588     <<"Trk Vtx in Fid  ="<<trkInFidVolCounter<<endl
05589     <<"Good Fit SigQP  ="<<goodFitSigQPCounter<<endl
05590     <<"Good Fit Prob   ="<<goodFitProbCounter<<endl
05591     <<"Good Fit Chi2   ="<<goodFitChi2Counter<<endl
05592     <<"Good Delta T    ="<<goodDeltaTCounter<<endl
05593     <<"Good EvtPerSlc  ="<<goodEvtsPerSlcCounter<<endl
05594     <<"Good DP ID      ="<<goodPIDCounter<<endl
05595     <<"Good beyond tEnd="<<goodBeyondTrkEndCounter<<endl
05596     <<"Good shw fract  ="<<goodShwFractCounter<<endl
05597     <<"*************************************"<<endl;
05598 
05599   Float_t pcPQ=0;
05600   if (nuPQCounter+nuNQCounter>0) pcPQ=100.*nuPQCounter/
05601                                    (nuPQCounter+nuNQCounter);
05602   MSG("NuAnalysis",Msg::kInfo)
05603     <<endl
05604     <<"Neutrinos with NQ="<<nuNQCounter<<endl
05605     <<"Neutrinos with PQ="<<nuPQCounter
05606     <<"   ("<<pcPQ<<"%)"<<endl
05607     <<"Sum NQ+PQ        ="<<nuNQCounter+nuPQCounter<<endl
05608     <<endl;
05609   
05610   MSG("NuAnalysis",Msg::kInfo) 
05611     <<" ** Finished EnergySpect method **"<<endl;
05612 }
05613 
05614 //......................................................................
05615 
05616 void NuAnalysis::CopyAcrossHistos(TDirectory* dirInput,
05617                                   TDirectory* dirOutput) const
05618 {
05619   //vector to store the names of the histograms to copy across
05620   vector<string> vObjectNames;
05621   vObjectNames.push_back("hDetector");
05622   vObjectNames.push_back("hSimFlag");
05623   vObjectNames.push_back("hTrigSrc");
05624   vObjectNames.push_back("hRun");
05625   vObjectNames.push_back("hPottortgt");
05626   vObjectNames.push_back("hPotBadtortgt");
05627   vObjectNames.push_back("hPottrtgtd");
05628   vObjectNames.push_back("hPotBadtrtgtd");
05629   vObjectNames.push_back("hPottor101");
05630   vObjectNames.push_back("hPotBadtor101");
05631   vObjectNames.push_back("hPottr101d");
05632   vObjectNames.push_back("hPotBadtr101d");
05633   vObjectNames.push_back("hSpillsPerFile");
05634 
05635   NuGeneral general;
05636   general.CopyAcrossObjects(dirInput,dirOutput,vObjectNames);
05637 }
05638 
05639 //......................................................................
05640 
05641 void NuAnalysis::NMBSummaryTreeAna()
05642 {
05643   string sFilePrefix="NMBSumAna";
05644   fOutFile=this->OpenFile(100,sFilePrefix.c_str());
05645 
05646   TDirectory* dirOutput=gDirectory;
05647   cout<<"After opening output file:"<<endl;
05648   dirOutput->Print();
05649   
05650   string sBase="/home/hartnell/mytest/NuMuBar/";
05651   string inputFileName=
05652     "NMBChgSepL010185iN00009059_2.root";//hs, csf, qp
05653   
05654   inputFileName=sBase+inputFileName;
05655   
05656   NuInputEvents* fpInput=new NuInputEvents();
05657   NuInputEvents& input=*fpInput;
05658   input.InputFileName(inputFileName);
05659   input.InitialiseChains();
05660   input.InitialiseNuEventBranch();
05661   TDirectory* dirInput=input.OpenInputFile();
05662   
05663   //copy across histos such hDetector, hSimFlag, and POT ones
05664   this->CopyAcrossHistos(dirInput,dirOutput);
05665 
05666   //create a cache of selected events to speed up the fitting
05667   //input.InitialiseNuEventCache();
05668   //this->CreateInputCache();
05669   
05670   //tell the input object to use cached events
05671   //input.UseNuEventCache();
05672   
05673   input.ResetNuEventLoopPositionToStart();
05674   
05675   static NuGeneral general;
05676   static NuPlots plots;
05677   static NuCuts cuts;
05678   
05679   for (Int_t i=0;i<input.GetEntriesNuEvent();++i) {
05680 
05681     this->PrintLoopProgress(i,input.GetEntriesNuEvent(),1);
05682 
05683     NuEvent& nu=const_cast<NuEvent&>(input.GetNextNuEvent(Msg::kDebug));
05684     
05685     //these ones go before the pid and other cuts
05686     plots.FillTrueDpIDHistos(nu);
05687     plots.FillTrueDpIDHistosPQNQ(nu);
05688     plots.FillDPIdSigmaQPPassPreSelCutPlots(nu);
05689     plots.FillSigmaQPPlots(nu);//sig, chi, prob plots
05690     // PoID Officially depracated
05691     //plots.FillTruePoIDHistos(nu);
05692     //plots.FillTruePoIDHistosPQNQ(nu);
05693     plots.FillTrueAbIDHistos(nu);
05694     plots.FillTrueAbIDHistosPQNQ(nu);
05695     
05696     //override the anaVersion
05697     nu.anaVersion=NuCuts::kJJH1;
05698     
05699     //cut on the PID
05700     //if (!cuts.IsGoodDpID(nu)) {
05701     if (!cuts.IsGoodAbID(nu)) {
05702       plots.FillDPIdSigmaQPFailDpIDCutPlots(nu);
05703       continue;
05704     }
05705     plots.FillDPIdSigmaQPPassDpIDCutPlots(nu);
05706     
05707     plots.FillEnergyBinHistos(nu);//just PID cut
05708     
05709     //cut on the fractional track momentum and sign error      
05710     if (!cuts.IsGoodSigmaQP_QP(nu)) {
05711       plots.FillDPIdSigmaQPFailSigQPCutPlots(nu);
05712       continue;
05713     }
05714     plots.FillDPIdSigmaQPPassSigQPCutPlots(nu);
05715     
05716     //cut on the chi2
05717     if (!cuts.IsGoodFitChi2PerNdof(nu)) continue;
05718     
05719     //was here
05720     //plots.FillEnergyBinHistos(nu);
05721 
05722     //cut on the track fit probability      
05723     if (!cuts.IsGoodFitProb(nu)) {
05724       plots.FillDPIdSigmaQPFailProbCutPlots(nu);
05725       continue;
05726     }
05727       
05728 
05729 
05730 
05731     //extra cuts to test
05732     //if (nu.dpID<+0.1) continue;
05733     //if (nu.dpID<+0.4) continue;
05734     //if (nu.dpID<+0.4 && nu.charge>0) continue;
05735     //if (nu.prob<0.1) continue;
05736     //if (nu.sigqp_qp>0.3) continue;
05737   
05738     //Bool_t weightForOsc=true;
05739     Bool_t weightForOsc=false;
05740     if (weightForOsc){
05741       //get the weight for the event
05742       Double_t weight=nu.rw;
05743       //apply the oscillation weight to CC events
05744       if (nu.iaction==1) {
05745         Float_t dm2=2.7e-3;
05746         Double_t oscWeight=general.OscWeight(dm2,1,
05747                                              nu.energyMC);
05748         weight*=oscWeight;
05749       }
05750       nu.rw=weight;
05751     }
05752 
05753     //if (nu.containedTrk && nu.rTrkEnd<0.3) {
05754     //MAXMSG("NuMinuit",Msg::kInfo,200)
05755     //<<"nu.rTrkEnd="<<nu.rTrkEnd<<endl;
05756     //}
05757 
05759     //if (nu.rTrkEnd>0.3) continue;
05760     
05761     //if (nu.xTrkEnd<-0.2 && nu.planeTrkEnd<=120 && nu.containmentFlag==1) {
05762     //MAXMSG("NuMinuit",Msg::kInfo,200)
05763     //<<"xTrkEnd="<<nu.xTrkEnd
05764     //<<", y="<<nu.yTrkEnd
05765     //<<", r="<<nu.rTrkEnd
05766     //<<", plTrkEnd"<<nu.planeTrkEnd
05767     //<<", con="<<nu.containedTrk
05768     //<<", flag="<<nu.containmentFlag
05769     //<<endl;
05770     //}
05771 
05772 
05773     //same list as below, but with trk/evt ones commented out
05774     plots.FillRecoEnYHistosN(nu);
05775     plots.FillDPIdSigmaQPPlotsN(nu);
05776     
05777     //plots.FillShwHistos(ntp,evt,nu);
05778     plots.FillXYZHistos(nu);
05779     plots.FillContainmentHistos(nu);
05780     plots.FillTruePIDHistos(nu);
05781     //plots.FillTrackResponseHistos(ntp,trk,nu);
05782     plots.FillRangeCurvCompHistos(nu);
05783     plots.FillKinematicsHistos(nu);
05784 
05785     MAXMSG("NuMinuit",Msg::kInfo,5)
05786       <<"NMBSummaryTreeAna: NuEvent: index="<<nu.index
05787       <<", energy="<<nu.energy<<", energyMC="<<nu.energyMC<<endl;    
05788   }//end of loop over summary tree
05789 
05790 }
05791 
05792 //......................................................................
05793 
05794 void NuAnalysis::LIRejectionTest()
05795 {
05796   MSG("NuAnalysis",Msg::kInfo) 
05797     <<" ** Running LIRejectionTest method... **"<<endl;
05798   
05799   NuConfig config;
05800   this->ExtractConfig(config);
05801 
05802   //open the output file for the histograms
05803   string sFilePrefix="LIRejectionTest"+config.sBeamType;
05804   fOutFile=this->OpenFile(config,sFilePrefix.c_str());
05805   
05806   string sTxt="litag"+config.sBeamType;
05807   ofstream& litagTxt=*(this->OpenTxtFile(config,sTxt.c_str()));
05808   sTxt="liSieve"+config.sBeamType;
05809   ofstream& liSieveTxt=*(this->OpenTxtFile(config,sTxt.c_str()));
05810   
05811   //classes to organise the code in to related functions
05812   const NuCuts cuts;
05813   const NuGeneral general;
05814   const NuPlots plots;
05815   const NuReco reco;
05816   const NuExtraction ext;
05817   const NuBeam beam;
05818 
05819   //classes to count numbers of events, etc and times of spills, etc
05820   NuCounter cnt;
05821   NuTime time;
05822 
05823   //interface for the pids
05824   NuPIDInterface pid;
05825   
05826   //create an object to do the beam reweighting
05827   const NuZBeamReweight zBeamReweight;
05828 
05829   config.anaVersion=NuCuts::kCC0250Std;
05830   config.useGeneratorReweight=false;
05831   config.reweightVersion=SKZPWeightCalculator::kPiMinus;
05832   Int_t mcVersionOveride=ReleaseType::kDaikon;//selects pdfs for data
05833 
05834   MSG("NuAnalysis",Msg::kInfo)
05835     <<"Setting:"<<endl
05836     <<"  anaVersion="
05837     <<cuts.AsString(static_cast<NuCuts::NuAnaVersion_t>
05838                     (config.anaVersion))
05839     <<" ("<<config.anaVersion<<")"<<endl
05840     <<"  useGeneratorReweight="<<config.useGeneratorReweight<<endl
05841     <<"  reweightVersion="<<config.reweightVersion<<endl;
05842   
05843   //if MC then the mcVersion will be determined from the file
05844   //override the version to use here (only gets set in the data case)
05845   if (config.mcVersion==ReleaseType::kData) {
05846     MSG("NuAnalysis",Msg::kInfo)
05847       <<"Overiding mcVersion:"<<endl
05848       <<"  new mcVersion="<< NuUtilities::PrintRelease(mcVersionOveride)
05849       <<", old mcVersion="<< NuUtilities::PrintRelease(config.mcVersion)
05850       <<endl;
05851     config.mcVersion=mcVersionOveride;
05852   }
05853  
05854   //get an instance of the code library
05855   const NuLibrary& lib=NuLibrary::Instance();
05856  
05860   
05861   this->InitialiseLoopVariables();  
05862   
05863   //for(Int_t entry=0;entry<10000;entry++){
05864   for(Int_t entry=0;entry<this->GetEntries();entry++){
05865       
05866     this->SetLoopVariables(entry);
05867       
05868     //get reference to NtpStRecord from base class
05869     const NtpStRecord& ntp=(*this->GetNtpStRecord());
05870 
05871     const RecCandHeader& rec=ntp.GetHeader();
05872     MAXMSG("NuAnalysis",Msg::kInfo,5)
05873       <<"Found: run="<<rec.GetRun()
05874       <<", subrun="<<rec.GetSubRun()
05875       <<", detector="<<rec.GetVldContext().GetDetector()
05876       <<", simFlag="<<rec.GetVldContext().GetSimFlag()
05877       <<", snarl="<<rec.GetSnarl()
05878       <<endl;
05879     
05880     //write out the detector, simflag, etc
05881     plots.FillGeneralHistos(ntp);
05882 
05883     //simple event object to hold important quantities for snarl
05884     NuEvent nuSnarl;
05885     nuSnarl.anaVersion=config.anaVersion;
05886     nuSnarl.mcVersion=config.mcVersion;
05887     nuSnarl.recoVersion=config.recoVersion;
05888     ext.ExtractGeneralInfo(ntp,nuSnarl);
05889 
05890     //get the true energy spectra of events in the fid vol
05891     plots.FillTrueFidEnergySpect(nuSnarl);
05892     
05893     Int_t evTime=rec.GetVldContext().GetTimeStamp().GetSec();
05894     Bool_t goodSpill=beam.IsGoodSpillAndFillPot
05895       (this->GetNtpBDLiteRecord(),config,nuSnarl);
05896     time.FillTime(evTime,nuSnarl.pot,goodSpill);
05897     if (!goodSpill) {
05898       cnt.badSpillCounter++;
05899       cnt.totalPotBad+=nuSnarl.pot;
05900       continue;
05901     }
05902     cnt.goodSpillCounter++;
05903     cnt.totalPot+=nuSnarl.pot;    
05904     
05905     TClonesArray& evtTca=(*ntp.evt);
05906     const Int_t numEvts=evtTca.GetEntriesFast();
05907 
05909     //loop over the reconstructed events
05911     for (Int_t ievt=0;ievt<numEvts;ievt++){
05912       const NtpSREvent& evt=
05913         *dynamic_cast<NtpSREvent*>(evtTca[ievt]);
05914       cnt.evtCounter++;
05915       
05916       MAXMSG("NuAnalysis",Msg::kInfo,5)
05917         <<"Found event, "<<ievt+1<<"/"<<numEvts<<endl;
05918 
05919       const NtpSREventSummary& evthdr=ntp.evthdr;
05920       
05921       if (evthdr.litime!=-1) {
05922         MAXMSG("NuAnalysis",Msg::kInfo,500)
05923           <<"skipping event: litime="<<evthdr.litime<<endl;
05924         continue;
05925       }
05926       cnt.evtNotlitime++;
05927 
05928       Bool_t isLI=LISieve::IsLI(ntp);
05929       if (isLI){
05930         MAXMSG("NuAnalysis",Msg::kInfo,5)
05931           <<endl<<endl<<endl
05932           <<"Found LI"
05933           <<", run="<<config.run
05934           <<", entry="<<entry
05935           <<", event="<<ievt
05936           <<", litime="<<evthdr.litime
05937           <<endl<<endl<<endl;
05938       }
05939       else {
05940         MAXMSG("NuAnalysis",Msg::kInfo,50)
05941           <<"Not LI"
05942           <<", run="<<config.run
05943           <<", entry="<<entry
05944           <<", event="<<ievt
05945           <<", litime="<<evthdr.litime
05946           <<endl;
05947       }
05948       //if (isLI) continue;
05949       if (!isLI) cnt.evtNotIsLI++;
05950       
05951       //simple event object to hold important quantities
05952       NuEvent nu;
05953       nu.entry=entry;//store the entry in the tree number
05954       this->CopyConfig(config,nu);
05955       
05956       //get the run, snarl, etc info
05957       ext.ExtractGeneralInfo(ntp,nu);
05958       //get info from the evt
05959       lib.ext.ExtractEvtInfo(evt,nu);
05960       //extract trk info (needed to get best track info)
05961       lib.ext.ExtractTrkInfo(ntp,evt,nu);
05962       //extract shw info
05963       lib.ext.ExtractShwInfo(ntp,evt,nu);
05964 
05965       //CC LI cut
05966       Int_t litag=reco.FDRCBoundary(nu);
05967       if (litag) {
05968         MAXMSG("NuAnalysis",Msg::kInfo,50)
05969           <<endl<<endl
05970           <<"litag="<<litag
05971           <<", run="<<config.run
05972           <<", entry="<<entry
05973           <<", event="<<ievt
05974           <<", litime="<<evthdr.litime
05975           <<endl
05976           <<", nu.nshw="<<nu.nshw
05977           <<", nu.rawPhEvt="<<nu.rawPhEvt
05978           <<", nu.planeEvtBeg="<<nu.planeEvtBeg
05979           <<", nu.planeEvtEnd="<<nu.planeEvtEnd
05980           <<endl<<endl<<endl;
05981       }
05982       if (litag>10) {
05983         MAXMSG("NuAnalysis",Msg::kInfo,50)
05984           <<endl<<endl
05985           <<"litag="<<litag
05986           <<", run="<<config.run
05987           <<", entry="<<entry
05988           <<", event="<<ievt
05989           <<", litime="<<evthdr.litime
05990           <<endl
05991           <<", nu.nshw="<<nu.nshw
05992           <<", nu.rawPhEvt="<<nu.rawPhEvt
05993           <<", nu.planeEvtBeg="<<nu.planeEvtBeg
05994           <<", nu.planeEvtEnd="<<nu.planeEvtEnd
05995           <<endl<<endl<<endl;
05996       }
05997 
05998       //only continue if event is not either litag or isLI
05999       if (!(litag || isLI)) continue;
06000       
06001       //extract trk/shw info (put this after ExtractEvtInfo to save cpu)
06002       reco.GetEvtEnergy(nu, false);
06003       cnt.goodRecoEnCounter++;
06004       
06005       //calculate PIDs
06006       pid.GetDpID(ntp,evt,nu);
06007       pid.GetAbID(ntp,evt,nu);
06008 
06009       MAXMSG("NuAnalysis",Msg::kInfo,10)
06010         <<"After reco:"<<endl;
06011       MAXMSG("NuAnalysis",Msg::kInfo,10)
06012         <<endl<<plots.PrintEventInfo(cout,nu)<<endl;
06013       
06014       //get the truth info (reco quantities are done above)
06015       reco.GetTruthInfo(ntp,evt,nu);
06016 
06017       if (litag) plots.PrintEventInfo(litagTxt,nu);
06018       if (isLI) plots.PrintEventInfo(liSieveTxt,nu);
06019 
06020       //hardly any of these
06021       if (isLI) continue;
06022 
06023       //ensure good number of tracks in the event
06024       if (!cuts.IsGoodNumberOfTracks(nu)) continue;
06025       cnt.evtWithTrkCounter++;
06026 
06027       //do the beam reweighting
06028       zBeamReweight.ExtractZBeamReweight(ntp,evt,nu);
06029       reco.ApplyReweights(nu);
06030 
06031       MAXMSG("NuAnalysis",Msg::kInfo,10)
06032         <<"PID: dp="<<nu.dpID<<", ab="<<nu.abID
06033         <<", ro="<<nu.roID<<", po="<<nu.poID
06034         <<", roNMB="<<nu.roIDNuMuBar<<endl;
06035       
06036       //check if the trk is in the fiducial volume
06037       if (!cuts.IsInFidVolTrk(nu)) continue;
06038       cnt.trkInFidVolCounter++;
06039       
06040       //require a good trk fit
06041       if (!cuts.IsGoodTrackFitPass(nu)) continue;
06042       cnt.goodTrkPassCounter++;
06043       
06044       if (!cuts.IsGoodDirCos(nu)) {
06045         MAXMSG("NuAnalysis",Msg::kInfo,50)
06046           <<"Bad DirCos, trkvtxdcosz="<<nu.trkvtxdcosz
06047           <<", dirCosNu="<<nu.dirCosNu<<endl;
06048         continue;
06049       }
06050       cnt.goodDirectionCosineCounter++;
06051 
06052       //check data quality
06053       ext.ExtractDataQuality(nu);//lots of db access
06054       if (!cuts.IsGoodDataQuality(nu)) continue;
06055       cnt.goodDataQualityCounter++;
06056 
06057       //check timing
06058       ext.ExtractMinMaxEvtTimes(ntp,evt,nu);
06059       ext.ExtractTimeToNearestSpill(nu);//lots of db access
06060       MAXMSG("NuAnalysis",Msg::kInfo,1000)
06061         <<"Time to spill="
06062         <<(nu.timeEvtMin-nu.timeToNearestSpill)/(Munits::microsecond)
06063         <<" us"<<endl;
06064       if (!cuts.IsGoodTimeToNearestSpill(nu)) continue;
06065       cnt.goodTimeToNearestSpillCounter++;
06066       
06067       //cut on the PID
06068       if (!cuts.IsGoodPID(nu)) {
06069         plots.FillDPIdSigmaQPFailDpIDCutPlots(nu);
06070         continue;
06071       }
06072       cnt.goodPIDCounter++;      
06073       plots.FillDPIdSigmaQPPassDpIDCutPlots(nu);
06074 
06075       //cut on the fractional track q/p error      
06076       if (!cuts.IsGoodSigmaQP_QP(nu)) {
06077         plots.FillDPIdSigmaQPFailSigQPCutPlots(nu);
06078         continue;
06079       }
06080       cnt.goodFitSigQPCounter++;
06081       plots.FillDPIdSigmaQPPassSigQPCutPlots(nu);
06082       
06083       //cut on the track fit probability      
06084       if (!cuts.IsGoodFitProb(nu)) {
06085         plots.FillDPIdSigmaQPFailProbCutPlots(nu);
06086         continue;
06087       }
06088       cnt.goodFitProbCounter++;
06089       
06090       if (nu.charge==-1) cnt.nuNQCounter++;
06091       else if (nu.charge==+1) cnt.nuPQCounter++;
06092       else cout<<"ahhh, bad charge (lirej)"<<endl;
06093       
06094       plots.FillRecoEnYHistosN(nu);
06095       plots.FillDPIdSigmaQPPlotsN(nu);
06096       plots.FillEnergyBinHistos(nu);
06097       
06098       plots.FillShwHistos(ntp,evt,nu);
06099       plots.FillXYZHistos(nu);
06100       plots.FillContainmentHistos(nu);
06101       plots.FillTruePIDHistos(nu);
06102       //plots.FillTrackResponseHistos(ntp,trk,nu);
06103       plots.FillRangeCurvCompHistos(nu);
06104       plots.FillKinematicsHistos(nu);
06105 
06106     }//end of loop over events
06107   }//end of for                                       
06108   
06112 
06113   MSG("NuAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
06114 
06115   cnt.PrintNMB();
06116 
06117   MSG("NuAnalysis",Msg::kInfo) 
06118     <<" ** Finished LIRejectionTest method **"<<endl;
06119 }
06120 
06121 //......................................................................
06122 
06123 void NuAnalysis::CopyConfig(const NuConfig& config,NuEvent& nu)
06124 {
06125   nu.anaVersion=config.anaVersion;
06126 
06127   nu.useGeneratorReweight=config.useGeneratorReweight;
06128   nu.sGeneratorConfigName=config.sGeneratorConfigName;
06129   nu.generatorConfigNo=config.generatorConfigNo;
06130   nu.reweightVersion=config.reweightVersion;
06131 
06132   nu.mcVersion=config.mcVersion;
06133   nu.recoVersion=config.recoVersion;
06134   nu.releaseType=config.releaseType;
06135 
06136   nu.runPeriod=config.runPeriod;
06137   nu.hornIsReverse=config.hornIsReverse;
06138   nu.beamType=config.beamType;
06139   nu.intensity=config.intensity;
06140   nu.hornCur=config.hornCurrent;
06141 
06142   nu.useDBForDataQuality=config.useDBForDataQuality;
06143   nu.useDBForSpillTiming=config.useDBForSpillTiming;
06144   nu.useDBForBeamInfo=config.useDBForBeamInfo;
06145 
06146   nu.cutOnDataQuality=config.cutOnDataQuality;
06147   nu.cutOnSpillTiming=config.cutOnSpillTiming;
06148   nu.cutOnBeamInfo=config.cutOnBeamInfo;
06149 
06150   nu.calcMajCurv=config.calcMajCurv;
06151   nu.calcRoID=config.calcRoID;
06152   nu.calcJmID=config.calcJmID;
06153 
06154 }
06155 
06156 //......................................................................
06157 
06158 void NuAnalysis::CopySnarlInfo(const NuEvent& nuSnarl,NuEvent& nu)
06159 {
06160   //copy across
06161   nu.goodBeamSntp=nuSnarl.goodBeamSntp;
06162   nu.pot=nuSnarl.pot;
06163   nu.coilIsOk=nuSnarl.coilIsOk;
06164   nu.coilIsReverse=nuSnarl.coilIsReverse;
06165   nu.coilCurrent=nuSnarl.coilCurrent;
06166 }
06167 
06168 //......................................................................
06169 
06170 void NuAnalysis::LoopOverTruthInfo(const NtpStRecord& ntp,
06171                                    NuOutputWriter& output,
06172                                    const NuEvent& nuSnarl,
06173                                    const std::vector<Int_t> vTthInd) const
06174 {
06175   //vTthInd is the list of true events we must write out
06176   //e.g. it contributes to a reconstructed event
06177 
06178   TClonesArray& mcTca=(*ntp.mc);
06179   const Int_t nummcs=mcTca.GetEntriesFast();
06180   static NuPlots plots;
06181   if (nummcs<=0) {
06182     MAXMSG("NuAnalysis",Msg::kDebug,1)
06183       <<"LoopOverTruthInfo: no MCTruth so return..."<<endl;
06184     //call this routine so that the plots are created
06185     plots.FillTrueFidEnergySpect(nuSnarl);
06186     return;
06187   }
06188   
06189   //get an instance of the code library
06190   const NuLibrary& lib=NuLibrary::Instance();
06191   
06192   //loop over all the true neutrino interactions
06193   for (Int_t imc=0;imc<nummcs;++imc){
06194     const NtpMCTruth& mc=
06195       *(dynamic_cast<NtpMCTruth*>(mcTca[imc]));
06196     
06197     //Does this true event contribute to a reco event?
06198     Bool_t mustWriteOut = false;
06199     for (std::vector<Int_t>::const_iterator it = vTthInd.begin();
06200          it != vTthInd.end();
06201          ++it){
06202       if (*it == imc){
06203         mustWriteOut = true;
06204       }
06205     }
06206     
06207     if (!mustWriteOut){
06208       //remove events that happen outside the ND calorimeter
06209       //this should speed things up
06210       if (nuSnarl.detector==Detector::kNear &&
06211           (mc.vtxz<-0.1*(Munits::m) || mc.vtxz>7.3*(Munits::m))) {
06212         MAXMSG("NuAnalysis",Msg::kInfo,1)
06213           <<"Not looping over true events occuring in front or behind"
06214           <<" the ND calorimeter (-0.1<Z<7.3m)"
06215           <<" (this mc.vtxz="<<mc.vtxz<<")"<<endl;
06216         continue;
06217       }
06218     }
06219     
06220     //extract the info from this mc object
06221     //bit inefficient to do this for every true event... but safer
06222     NuEvent nu=nuSnarl;//copy to hold truth info and weights
06223     
06224     //need to set this for both GetTruthInfo and reweight
06225     nu.mc=imc;
06226     
06227     //now get the truth info (need nu.mc to be set)
06228     lib.reco.GetTruthInfo(ntp,mc,nu);
06229     
06230     //set the reconstructed variables to the true ones
06231     //so that the MCReweight is ok about it (might not be necessary)
06232     nu.shwEn=nu.shwEnMC;
06233     nu.trkEn=fabs(nu.trkEnMC);//fabs: charge is stored with the energy
06234     
06235     //get the beam weight
06236     lib.zBeamReweight.ExtractZBeamReweight(nu);
06237     lib.reco.ApplyReweights(nu);
06238     
06239     if (!mustWriteOut){
06240       //write out events in loose fid vol
06241       if (!lib.cuts.IsInFidVolLoose
06242           (nu.vtxxMC,nu.vtxyMC,nu.vtxzMC,nu.detector)) {
06243         continue;
06244       }
06245     }
06246     
06247     //get NuMCEvent to fill
06248     NuMCEvent& numc=output.GetNuMCEventToFill();
06249     lib.ext.NuMCEventFromNuEvent(nu,numc);
06250     //don't set the value of numc.mc here, since it is done above
06251     //in NuMCEventFromNuEvent(nu,numc): changed by JJH 2009/09/17
06252     //numc.mc=imc;//the index in the TClonesArray
06253     
06254     //fill the tree
06255     output.FillNuMCEventTree();
06256     
06257     //check if true event vtx is in fid vol
06258     //NOTE: event has to have already passed the loose fid vol cut
06259     //this works for analyses up to 2008/02 but newer cuts maybe diff.
06260     Bool_t isInFidVol=lib.cuts.IsInFidVol
06261       (nu.vtxxMC,nu.vtxyMC,nu.vtxzMC,
06262        nu.vtxuMC,nu.vtxvMC,
06263        nu.planeTrkVtxMC,nu.rTrkVtxMC,
06264        nu.detector,nu.anaVersion,nu.releaseType,nu.simFlag);
06265     if (!isInFidVol) continue;
06266     
06267     //fill the plots
06268     plots.FillTrueFidEnergySpect(nu);
06269   }
06270 }
06271 
06272 //......................................................................
06273 
06274 void NuAnalysis::ChargeSeparation()
06275 {
06276   MSG("NuAnalysis",Msg::kInfo) 
06277     <<" ** Running ChargeSeparation method... **"<<endl;
06278   
06282   
06283   cout<<endl
06284       <<"************************************************"<<endl
06285       <<"***      Starting main loop over snarls      ***"<<endl
06286       <<"************************************************"<<endl;
06287   
06288   this->InitialiseLoopVariables();  
06289   
06290   for(Int_t entry=0;entry<this->GetEntries();entry++){
06291     
06292     this->SetLoopVariables(entry);
06293       
06294 
06295     this->ChargeSeparationOneSnarl(this->GetNtpStRecord(),
06296                                    this->GetNtpBDLiteRecord(),0);
06297   }
06298 
06299   //finish the job
06300   this->StoreOrFinishTree(NULL,NULL,1);
06301 
06302   MSG("NuAnalysis",Msg::kInfo) 
06303     <<" ** Finished ChargeSeparation method **"<<endl;
06304 }
06305 
06306 //......................................................................
06307 
06308 void NuAnalysis::StoreOrFinishTree(NuOutputWriter* pOutput,
06309                                    NuTime* pTime,
06310                                    Bool_t finish) const
06311 {
06312   //this stores the pointers the first time the function is called
06313   static NuTime& time=*pTime;
06314   static NuOutputWriter& output=*pOutput;
06315   static Bool_t firstTime=true;
06316 
06317   if (firstTime) {
06318     MSG("NuPIDInterface",Msg::kInfo)
06319       <<"StoreOrFinishTree: TDirectory for NuOutputWriter is:"<<endl;
06320     if (pOutput) output.GetDirectory()->pwd();
06321     else cout<<"Ahhh, no NuOutputWriter"<<endl;
06322     
06323     MSG("NuPIDInterface",Msg::kInfo)
06324       <<"StoreOrFinishTree: gDirectory is:"<<endl;
06325     gDirectory->pwd();
06326   }
06327   
06328   //this section runs methods on objects at the end of job
06329   if (finish){
06330     if (!firstTime) {
06331       //get an instance of the code library
06332       const NuLibrary& lib=NuLibrary::Instance();
06333       
06334       MSG("NuPIDInterface",Msg::kInfo)
06335         <<"StoreOrFinishTree: gDirectory is:"<<endl;
06336       gDirectory->pwd();
06337       MSG("NuPIDInterface",Msg::kInfo)
06338         <<"After reseting gDirectory to NuOutputWriter location:"<<endl;
06339       gDirectory=output.GetDirectory();
06340       gDirectory->pwd();
06341       
06342       //fill time histos
06343       time.FillTimeHistos();
06344       
06345       //print out job info
06346       lib.cnt.PrintFullDST();
06347       lib.cnt.PrintStdhepCounter();
06348       
06349       lib.hist.CalcPOTsFromHistos();
06350       
06351       //close the file and write everything out
06352       output.Finish();
06353     }
06354     else {
06355       MSG("NuAnalysis",Msg::kWarning) 
06356         <<"StoreOrFinishTree was not run in store mode"<<endl;
06357     }
06358   }
06359 
06360   //no longer first time
06361   firstTime=false;
06362 }
06363 
06364 //......................................................................
06365 
06366 void NuAnalysis::SetAnaFlags(NuConfig& config)
06367 {
06369   
06370   //get an instance of the code library
06371   const NuLibrary& lib=NuLibrary::Instance();
06372   
06373   //set the cuts version
06374   config.anaVersion=NuCuts::kFullDST;
06375 
06376   //set the reweighting variables
06377   //config.reweightVersion=SKZPWeightCalculator::kBoston;
06378   //config.reweightVersion=SKZPWeightCalculator::kPiMinus;//Cedar/Daikon
06379   if (config.mcVersion==ReleaseType::kData) {
06380     MAXMSG("NuAnalysis",Msg::kInfo,1) << "Found Data, setting reweightVersion to SKZPWeightCalculator::kUnknown" << endl;    
06381     config.reweightVersion=SKZPWeightCalculator::kUnknown;
06382   }
06383   else if (!ReleaseType::IsDaikon(config.releaseType)) {
06384     MAXMSG("NuAnalysis",Msg::kWarning,1) << "Don't know what weights to use for non-daikon MC version " 
06385     << NuUtilities::PrintRelease(config.releaseType) << " so I will assume DetXs" << endl;
06386     config.reweightVersion=SKZPWeightCalculator::kDetXs;
06387   }
06388   else {
06389     if (ReleaseType::GetMCSubVersion(config.releaseType) <= 4) {
06390       MAXMSG("NuAnalysis",Msg::kInfo,1) << "Found MC version " 
06391       <<  NuUtilities::PrintRelease(config.releaseType) 
06392       << " so I will use SKZPWeightCalculator::kDetXs" << endl;
06393       config.reweightVersion=SKZPWeightCalculator::kDetXs;
06394     }
06395     else {
06396       MAXMSG("NuAnalysis",Msg::kInfo,1) << "Found MC version " 
06397       <<  NuUtilities::PrintRelease(config.releaseType) 
06398       << " so I will use SKZPWeightCalculator::kDogwood1_Daikon07_v2" << endl;
06399       config.reweightVersion=SKZPWeightCalculator::kDogwood1_Daikon07_v2;
06400     }
06401   }
06402   
06403   
06404   config.useGeneratorReweight=false;
06405   //config.sGeneratorConfigName="MODBYRS3";
06406   //config.generatorConfigNo=-1;
06407 
06408   //flags to switch parts of the code on and off
06409   //can be used to avoid needing various database tables
06410   //config.useDBForDataQuality=false;//default is true
06411   //config.useDBForSpillTiming=false;//default is true
06412   //config.useDBForBeamInfo=false;//default is true
06413   //config.cutOnDataQuality=false;//default is true
06414   //config.cutOnSpillTiming=false;//default is true
06415   //config.cutOnBeamInfo=false;//default is true
06416   //config.calcMajCurv=false;//default is true
06417   //config.calcRoID=false;//default is true
06418 
06419   //set the MC version to determine which pdfs to use for data
06420   Int_t mcVersionOveride=ReleaseType::kDaikon;//selects data pdfs
06421   //Int_t mcVersionOveride=ReleaseType::kCarrot;//selects data pdfs
06422 
06423   MSG("NuAnalysis",Msg::kInfo)
06424     <<"Setting:"<<endl
06425     <<"  anaVersion="
06426     <<lib.cuts.AsString(static_cast<NuCuts::NuAnaVersion_t>
06427                         (config.anaVersion))
06428     <<" ("<<config.anaVersion<<")"<<endl
06429     <<"  useGeneratorReweight="<<config.useGeneratorReweight<<endl
06430     <<"  reweightVersion="<<config.reweightVersion<<endl;
06431   
06432   //if MC then the mcVersion will be determined from the file
06433   //override the version to use here (only gets set in the data case)
06434   if (config.mcVersion==ReleaseType::kData) {
06435     MSG("NuAnalysis",Msg::kInfo)
06436       <<"Overiding mcVersion for PDF selection:"<<endl
06437       <<"  new mcVersion="<<NuUtilities::PrintRelease(mcVersionOveride)
06438       <<", old mcVersion="<<NuUtilities::PrintRelease(config.mcVersion)
06439       <<endl;
06440     config.mcVersion=mcVersionOveride;
06441   }  
06442   
06443 
06444 }
06445 
06446 //......................................................................
06447 
06448 void NuAnalysis::DoExtractions(const NtpStRecord& ntp,
06449                                const NtpSREvent& evt,
06450                                const NtpFitSARecord* pntpSA,
06451                                NuPIDInterface& pid,NuEvent& nu) const
06452 {
06453   //get an instance of the code library
06454   const NuLibrary& lib=NuLibrary::Instance();
06455   
06456   //extract other necessary information
06457   lib.ext.ExtractAuxiliaryInfo(ntp,evt,pntpSA,nu);
06458   //get the truth info (reco quantities are done above)
06459   lib.reco.GetTruthInfo(ntp,evt,nu);
06460 
06461   //get the pids and the event weights
06462   this->ExtractPIDsAndWeights(ntp,evt,pid,nu);
06463 
06464 
06465 }
06466 
06467 //......................................................................
06468 
06469 void NuAnalysis::ExtractPIDsAndWeights(const NtpStRecord& ntp,
06470                                        const NtpSREvent& evt,
06471                                        NuPIDInterface& pid,
06472                                        NuEvent& nu) const
06473 {
06474   //get an instance of the code library
06475   const NuLibrary& lib=NuLibrary::Instance();
06476   
06477   //do the reweighting
06478   lib.zBeamReweight.ExtractZBeamReweight(nu);
06479   lib.zBeamReweight.CalcGeneratorReweight(ntp,evt,nu);
06480   lib.reco.ApplyReweights(nu);
06481 
06482   //calculate PIDs
06483   pid.GetDpID(ntp,evt,nu);
06484   pid.GetAbID(ntp,evt,nu);
06485   if (nu.calcRoID) pid.GetRoID(ntp,evt,nu);//gets muon and nubar pid
06486   else pid.GetRoIDNuMuBar(ntp,evt,nu);//just gets nubar pid
06487 
06488   if(nu.calcJmID) pid.GetJmID(ntp,evt,nu);
06489   // PoID Officially depracated
06490   //pid.GetPoID(nu);
06491   lib.ext.ExtractMajorityCurvature(ntp,evt,nu);
06492 }
06493 
06494 //......................................................................
06495 
06496 void NuAnalysis::EndJob()
06497 {
06498   this->StoreOrFinishTree(NULL,NULL,1);
06499   
06500   //write out any histos if a file was opened 
06501   //StoreOrFinishTree deals with the output usually
06502   cout<<"fOutFile="<<fOutFile<<endl;
06503   this->WriteOutHistos();
06504 }
06505 
06506 //......................................................................
06507 
06508 void NuAnalysis::ChargeSeparationOneSnarl(const NtpStRecord* pntp,
06509                                           const NtpBDLiteRecord* pntpBD,
06510                                           const NtpFitSARecord* pntpSA)
06511 {
06512   MAXMSG("NuAnalysis",Msg::kError,100) 
06513     <<"ChargeSeparationOneSnarl is deprecated. Use MakeFullDst instead"
06514     <<endl;
06515 
06518 
06519   //get an instance of the code library
06520   NuLibrary& lib=NuLibrary::Instance();
06521   
06522   //increment ntuple entry (snarl) counter 
06523   lib.cnt.entry++;//initialised to -1 so first entry=0
06524 
06528   
06529   //extract the config from the beam information
06530   //occasionally the first snarl fails the beam cuts
06531   //so therefore you can't determine the proper beam config
06532   //this messes up the counting of bad pot but it should be a tiny 
06533   //effect
06534   static NuConfig config;
06535   static Bool_t configNotExtracted=true;
06536   if (configNotExtracted) {
06537     configNotExtracted=!this->ExtractConfig(pntp,pntpBD,config);
06538     if (configNotExtracted) return;//skip to next snarl
06539   }
06540 
06541   static Bool_t firstTime=true;
06542   static NuOutputWriter output;
06543 
06544   static ofstream* pnmbTxt=0;
06545   static ofstream* pnmTxt=0;
06546   static ofstream* pnmbTxtProb=0;
06547   static ofstream* pnmbTxtProb001=0;
06548   static ofstream* pnmbTxtProb003=0;
06549 
06550   //classes to organise the code in to related functions
06551   static const NuPlots plots;
06552   static const NuBeam beam;
06553   static NuTime time;//class to record times of spills, etc
06554 
06555   //interface for the pids
06556   static NuPIDInterface pid;
06557 
06558   if (firstTime) {
06559     firstTime=false;//set the control variable so code not run again
06560         
06561     //open the output file for the histograms
06562     string sFilePrefix="NuDST"+config.sBeamType;
06563     //fOutFile=this->OpenFile(config,sFilePrefix.c_str());
06564     output.SetupFile(config,sFilePrefix);
06565     
06566     string sTxt="nmb"+config.sBeamType;
06567     pnmbTxt=this->OpenTxtFile(config,sTxt.c_str());
06568     string sTxtNM="nm"+config.sBeamType;
06569     pnmTxt=this->OpenTxtFile(config,sTxtNM.c_str());
06570     string sTxtProb="nmbProb"+config.sBeamType;
06571     pnmbTxtProb=this->OpenTxtFile(config,sTxtProb.c_str());
06572     string sTxtProb001="nmbProb001"+config.sBeamType;
06573     pnmbTxtProb001=this->OpenTxtFile(config,sTxtProb001.c_str());
06574     string sTxtProb003="nmbProb003"+config.sBeamType;
06575     pnmbTxtProb003=this->OpenTxtFile(config,sTxtProb003.c_str());
06576 
06577     //define the analysis flags
06578     this->SetAnaFlags(config);
06579     config.anaVersion=NuCuts::kCC0250Std;
06580 
06581     //this stores the objects' pointers for access at job end
06582     //NOTE: run this after the output file has been opened
06583     this->StoreOrFinishTree(&output,&time,false);
06584     
06585     cout<<endl
06586         <<"************************************************"<<endl
06587         <<"***      Starting main loop over snarls      ***"<<endl
06588         <<"************************************************"<<endl;
06589   }
06590   
06591   //get references (coding preference)
06592   static ofstream& nmbTxt=*pnmbTxt;
06593   static ofstream& nmTxt=*pnmTxt;
06594   static ofstream& nmbTxtProb=*pnmbTxtProb;
06595   static ofstream& nmbTxtProb001=*pnmbTxtProb001;
06596   static ofstream& nmbTxtProb003=*pnmbTxtProb003;
06597   
06598   //don't get a reference to NtpBDLiteRecord because it doesn't exist
06599   //for MC
06600   const NtpStRecord& ntp=*pntp;
06601 
06605   
06606   const RecCandHeader& rec=ntp.GetHeader();
06607   MAXMSG("NuAnalysis",Msg::kInfo,5)
06608     <<"Found: run="<<rec.GetRun()
06609     <<", subrun="<<rec.GetSubRun()
06610     <<", detector="<<rec.GetVldContext().GetDetector()
06611     <<", simFlag="<<rec.GetVldContext().GetSimFlag()
06612     <<", snarl="<<rec.GetSnarl()
06613     <<endl;
06614   
06615   //write out the detector, simflag, etc
06616   plots.FillGeneralHistos(ntp);
06617   
06618   //simple event object to hold important quantities for snarl
06619   NuEvent nuSnarl;
06620   this->CopyConfig(config,nuSnarl);
06621 
06622   //get the run, snarl, etc info
06623   lib.ext.ExtractGeneralInfo(ntp,nuSnarl);
06624 
06625   //get the true energy spectra of events in the fid vol
06626   std::vector<Int_t> vEmpty;
06627   this->LoopOverTruthInfo(ntp,output,nuSnarl,vEmpty);
06628 
06629   //extract coil info early in order to get POT counting right
06630   //doesn't matter for the FD because POTs are externally defined
06631   lib.ext.ExtractCoilInfo(nuSnarl);
06632   plots.FillCoilCurrentHistos(nuSnarl);
06633   if (!nuSnarl.coilIsOk) return;
06634   lib.cnt.goodCoilCurrentSpillCounter++;
06635   
06636   //get POT and event time info
06637   beam.IsGoodSpillAndFillPot(pntpBD,config,nuSnarl);
06638   time.FillTime(nuSnarl.timeSec,nuSnarl.pot,nuSnarl.goodBeamSntp);
06639   if (!nuSnarl.goodBeamSntp) {
06640     lib.cnt.badSpillCounter++;
06641     lib.cnt.totalPotBad+=nuSnarl.pot;
06642     return;
06643   }
06644   lib.cnt.goodSpillCounter++;
06645   lib.cnt.totalPot+=nuSnarl.pot;   
06646   
06647   //count the pots since the last evt was written to file
06648   static Float_t potSinceLastEvt=0;
06649   static Float_t potSinceLastEvtGood=0;
06650   static Float_t potSinceLastEvtBad=0;//this is always zero here
06651   potSinceLastEvt+=nuSnarl.pot;
06652   if (nuSnarl.goodBeamSntp && 
06653       nuSnarl.coilIsOk) potSinceLastEvtGood+=nuSnarl.pot;
06654   else potSinceLastEvtBad+=nuSnarl.pot;
06655 
06656   //get the tca of evts
06657   TClonesArray& evtTca=(*ntp.evt);
06658   const Int_t numEvts=evtTca.GetEntriesFast();
06659 
06661   //loop over the reconstructed events
06663   for (Int_t ievt=0;ievt<numEvts;ievt++){
06664     const NtpSREvent& evt=
06665       *dynamic_cast<NtpSREvent*>(evtTca[ievt]);
06666     lib.cnt.evtCounter++;
06667       
06668     MAXMSG("NuAnalysis",Msg::kInfo,5)
06669       <<"Found event, "<<ievt+1<<"/"<<numEvts<<endl;
06670 
06671     //loose pre-selection cut: just require 1 or more trks
06672     if (evt.ntrack<1) continue;
06673     lib.cnt.evtWithTrkCounter++;
06674 
06675     //get rid of LI events
06676     const NtpSREventSummary& evthdr=ntp.evthdr;
06677     if (evthdr.litime!=-1) continue;
06678     lib.cnt.evtNotlitime++;
06679     
06680     //simple event object to hold important quantities
06681     NuEvent& nu=output.GetNuEventToFill();
06682     nu.entry=lib.cnt.entry;//store the entry in the tree number
06683     nu.nevt=numEvts;//store the numEvts in snarl
06684     //copy info, copy the analysis (cuts and reco) version to use
06685     this->CopySnarlInfo(nuSnarl,nu);
06686     this->CopyConfig(config,nu);
06687     
06688     //extract the general info and evt, trk and shw info
06689     lib.ext.ExtractBasicInfo(ntp,evt,nu);
06690     
06691     //check if trk or evt vertex is in the loose fid vol
06692     if (!lib.cuts.IsInFidVolLoose(nu)) continue;
06693     lib.cnt.evtInFidVolCounter++;
06694     
06695     //RECONSTRUCT the neutrino energy
06696     lib.reco.GetEvtEnergy(nu, false);
06697 
06698     MAXMSG("NuAnalysis",Msg::kDebug,10)
06699       <<endl<<"After reco:"<<endl
06700       <<plots.PrintEventInfo(cout,nu)<<endl;
06701 
06702     //do multiple extractions
06703     this->DoExtractions(ntp,evt,pntpSA,pid,nu);
06704 
06705     MAXMSG("NuAnalysis",Msg::kInfo,10)
06706       <<"PID: dp="<<nu.dpID<<", ab="<<nu.abID<<", ro="<<nu.roID
06707       <<", po="<<nu.poID<<", roNMB="<<nu.roIDNuMuBar<<endl;
06708     
06709     //figure out the first and last time in the whole ntuple
06710     //this is very useful for making plots of quantities vs time
06711     plots.FillNtupleEarliestLatestTime(nu);
06712 
06713     //write out the pots since the last evt
06714     //this variable takes account of spills with zero entries
06715     //and spills with >=2 evts
06716     nu.potSinceLastEvt=potSinceLastEvt;
06717     nu.potSinceLastEvtGood=potSinceLastEvtGood;
06718     nu.potSinceLastEvtBad=potSinceLastEvtBad;
06719     potSinceLastEvt=0;//reset this for the next loop
06720     potSinceLastEvtGood=0;
06721     potSinceLastEvtBad=0;
06722 
06724     //fill the tree
06725     output.FillNuEventTree();
06726       
06727     //get the best track in the event
06728     Int_t bestTrack=lib.reco.GetBestTrack(nu);
06729     const NtpSRTrack* ptrk=lib.reco.GetTrackWithIndexX
06730       (ntp,evt,bestTrack-1);
06731     const NtpSRTrack& trk=*ptrk;
06732 
06733     //ensure good number of tracks in event (note preselection above)
06734     if (!lib.cuts.IsGoodNumberOfTracks(nu)) continue;
06735     lib.cnt.evtWithTrkCounter++;
06736 
06737     //check trk is in fiducial volume (note preselection above)
06738     if (!lib.cuts.IsInFidVolTrk(nu)) continue;
06739     lib.cnt.trkInFidVolCounter++;
06740 
06741     //cut on LI
06742     if (lib.cuts.IsLI(nu)) continue;
06743     lib.cnt.evtNotIsLI++;
06744       
06745     //cut on the data quality
06746     if (!lib.cuts.IsGoodDataQuality(nu)) continue;
06747     lib.cnt.goodDataQualityCounter++;
06748       
06749     //cut on the spill time
06750     plots.FillEvtAndSpillTimingPlots(nu);
06751     if (!lib.cuts.IsGoodTimeToNearestSpill(nu)) continue;
06752     lib.cnt.goodTimeToNearestSpillCounter++;
06753 
06754     //cut on the beam
06755     if (!lib.cuts.IsGoodBeam(nu)) continue;
06756     lib.cnt.goodBeamInfoDBCounter++;
06757       
06758     //require a good trk fit
06759     if (!lib.cuts.IsGoodTrackFitPass(nu)) continue;
06760     lib.cnt.goodTrkPassCounter++;
06761 
06762     //require a forward going neutrino about beam direction
06763     if (!lib.cuts.IsGoodDirCos(nu)) continue;
06764     lib.cnt.goodDirectionCosineCounter++;
06765 
06766     //fill pid plots AFTER pre-selection
06767     plots.FillTrueDpIDHistos(nu);
06768     plots.FillTrueDpIDHistosPQNQ(nu);
06769     plots.FillDPIdSigmaQPPassPreSelCutPlots(nu);
06770     plots.FillSigmaQPPlots(nu);//sig, chi, prob plots
06771     // PoID Officially depracated
06772     //plots.FillTruePoIDHistos(nu);
06773     //plots.FillTruePoIDHistosPQNQ(nu);
06774     plots.FillTrueAbIDHistos(nu);
06775     plots.FillTrueAbIDHistosPQNQ(nu);      
06776     plots.FillTrueRoIDHistos(nu);
06777     plots.FillTrueRoIDHistosPQNQ(nu);
06778     plots.FillDPIdSigmaQPPassUVVtxCutPlots(nu);//fill these anyway
06779     
06780     //cut on the PID
06781     if (!lib.cuts.IsGoodPID(nu)) {
06782       plots.FillDPIdSigmaQPFailDpIDCutPlots(nu);
06783       continue;
06784     }
06785     lib.cnt.goodPIDCounter++;   
06786     plots.FillDPIdSigmaQPPassDpIDCutPlots(nu);
06787 
06788     //cut on the fractional track momentum and sign error      
06789     if (!lib.cuts.IsGoodSigmaQP_QP(nu)) {
06790       plots.FillDPIdSigmaQPFailSigQPCutPlots(nu);
06791       continue;
06792     }
06793     lib.cnt.goodFitSigQPCounter++;
06794     plots.FillDPIdSigmaQPPassSigQPCutPlots(nu);
06795       
06796     //fill plots
06797     plots.FillStpfitqpPlots(ntp,trk,nu);
06798     plots.FillLowProbPlots(trk,nu);
06799 
06800     //cut on the track fit probability      
06801     if (!lib.cuts.IsGoodFitProb(nu)) {
06802       plots.FillDPIdSigmaQPFailProbCutPlots(nu);
06803       if (nu.charge==+1) {
06804         plots.PrintEventInfo(nmbTxtProb,nu);
06805         if (nu.prob<=0.001) plots.PrintEventInfo(nmbTxtProb001,nu);
06806         else if (nu.prob>0.001 && nu.prob<0.003) plots.PrintEventInfo
06807                                                    (nmbTxtProb003,nu);
06808       }
06809       continue;
06810     }
06811     lib.cnt.goodFitProbCounter++;
06812       
06813     //plots.FillStpfitqpPlots(ntp,trk,nu);
06814      
06816     //END OF STD CUTS
06818       
06819     if (nu.charge==-1) {
06820       plots.PrintEventInfo(nmTxt,nu);
06821       time.vTimeNuMuEvt.push_back(nu.timeSec);
06822       lib.cnt.nuNQCounter++;
06823     }
06824     else if (nu.charge==+1) {
06825       plots.PrintEventInfo(nmbTxt,nu);
06826       lib.cnt.CountTrkStdhepId(ntp,evt,trk,nu);
06827       time.vTimeNuMuBarEvt.push_back(nu.timeSec);
06828       lib.cnt.nuPQCounter++;
06829     }
06830     //    else cout<<"ahhh, bad charge"<<endl;
06831 
06832     MAXMSG("NuAnalysis",Msg::kDebug,100)
06833       <<plots.PrintEventInfo(cout,nu)<<endl;
06834       
06835     //fill all the plots
06836     plots.FillRecoEnYHistosN(nu);
06837     plots.FillDPIdSigmaQPPlotsN(nu);
06838     plots.FillEnergyBinHistos(nu);
06839     plots.FillShwHistos(ntp,evt,nu);
06840     plots.FillXYZHistos(nu);
06841     plots.FillContainmentHistos(nu);
06842     plots.FillTruePIDHistos(nu);
06843     plots.FillTrackResponseHistos(ntp,trk,nu);
06844     plots.FillRangeCurvCompHistos(nu);
06845     plots.FillKinematicsHistos(nu);
06846 
06847     //fill matrix method histos
06848     lib.hist.FillMatrixMethodHistos(nu);
06849   }//end of loop over events
06850 }
06851 
06852 //____________________________________________________________________72
06853 const std::vector<Int_t>
06854 NuAnalysis::ContributingTrueEvents(const NuEvent& event) const
06855 {
06856   std::vector<Int_t> vTthInd;
06857   vTthInd.push_back(event.mc);
06858   if (event.mcEvt != event.mc && event.mcEvt > -1)
06859     {vTthInd.push_back(event.mcEvt);}
06860   if (event.mcTrk != event.mc && event.mcTrk > -1)
06861     {vTthInd.push_back(event.mcTrk);}
06862   if (event.mcShw != event.mc && event.mcShw > -1)
06863     {vTthInd.push_back(event.mcShw);}
06864   if (event.mcTrk1 != event.mcTrk && event.trkExists1 && event.mcTrk1 > -1)
06865     {vTthInd.push_back(event.mcTrk1);}
06866   if (event.mcTrk2 != event.mcTrk && event.trkExists2 && event.mcTrk2 > -1)
06867     {vTthInd.push_back(event.mcTrk2);}
06868   if (event.mcTrk3 != event.mcTrk && event.trkExists3 && event.mcTrk3 > -1)
06869     {vTthInd.push_back(event.mcTrk3);}
06870   if (event.mcShw1 != event.mcShw && event.shwExists1 && event.mcShw1 > -1)
06871     {vTthInd.push_back(event.mcShw1);}
06872   if (event.mcShw2 != event.mcShw && event.shwExists2 && event.mcShw2 > -1)
06873     {vTthInd.push_back(event.mcShw2);}
06874   if (event.mcShw3 != event.mcShw && event.shwExists3 && event.mcShw3 > -1)
06875     {vTthInd.push_back(event.mcShw3);}
06876   if (event.mcShw4 != event.mcShw && event.shwExists4 && event.mcShw4 > -1)
06877     {vTthInd.push_back(event.mcShw4);}
06878   if (event.mcShw5 != event.mcShw && event.shwExists5 && event.mcShw5 > -1)
06879     {vTthInd.push_back(event.mcShw5);}
06880   return vTthInd;
06881 }
06882 
06883 //......................................................................
06884 
06885 void NuAnalysis::MakeFullDST(const NtpStRecord* pntp,
06886                              const NtpBDLiteRecord* pntpBD,
06887                              const NtpFitSARecord* pntpSA)
06888 {
06891 
06892   //get an instance of the code library
06893   NuLibrary& lib=NuLibrary::Instance();
06894   
06895   //increment ntuple entry (snarl) counter 
06896   lib.cnt.entry++;//initialised to -1 so first entry=0
06897 
06898 
06902   
06903   //extract the config from the beam information
06904   //occasionally the first snarl fails the beam cuts
06905   //so therefore you can't determine the proper beam config
06906   //this messes up the counting of bad pot but it should be a tiny 
06907   //effect (and bad pot isn't very important)
06908   static NuConfig config;
06909   static Bool_t configNotExtracted=true;
06910   if (configNotExtracted) {
06911     //set the flag to override the use of beam data in configuration
06912     //config.overrideBeamDataConfigExtraction=true;//default is false
06913     if (config.overrideBeamDataConfigExtraction) {
06914       MSG("NuAnalysis",Msg::kWarning)
06915         <<"Overriding use of Beam Data to extract configuration"<<endl
06916         <<"config.overrideBeamDataConfigExtraction="
06917         <<config.overrideBeamDataConfigExtraction<<endl;
06918     }
06919     configNotExtracted=!this->ExtractConfig(pntp,pntpBD,config);
06920     if (configNotExtracted) return;//skip to next snarl
06921   }
06922 
06923   static Bool_t firstTime=true;
06924   static NuOutputWriter output;
06925 
06926   //classes to organise the code in to related functions
06927   static const NuPlots plots;
06928   static const NuBeam beam;
06929   static NuTime time;//class to record times of spills, etc
06930 
06931   //interface for the pids
06932   static NuPIDInterface pid;
06933 
06934   if (firstTime) {
06935     firstTime=false;//set the control variable so code not run again
06936     
06937     //open the output file for the histograms
06938     string sFilePrefix="NuDSTFull"+config.sBeamType;
06939     //fOutFile=this->OpenFile(config,sFilePrefix.c_str());
06940     output.SetupFile(config,sFilePrefix);
06941     
06942     //define the analysis flags to use
06943     this->SetAnaFlags(config);
06944 
06945     //this stores the objects' pointers for access at job end
06946     //NOTE: run this after the output file has been opened
06947     this->StoreOrFinishTree(&output,&time,false);
06948 
06949     cout<<endl
06950         <<"************************************************"<<endl
06951         <<"***      Starting main loop over snarls      ***"<<endl
06952         <<"************************************************"<<endl;
06953   }
06954   
06955   //don't get a reference to NtpBDLiteRecord because it doesn't exist
06956   //for MC
06957   const NtpStRecord& ntp=*pntp;
06958 
06962   
06963   const RecCandHeader& rec=ntp.GetHeader();
06964   MAXMSG("NuAnalysis",Msg::kInfo,1)
06965     <<"Found: detector="<<rec.GetVldContext().GetDetector()
06966     <<", simFlag="<<rec.GetVldContext().GetSimFlag()
06967     <<", snarl="<<rec.GetSnarl()<<endl;
06968   
06969   //write out the detector, simflag, 
06970   //count runs or subruns, and snarls, etc
06971   plots.FillGeneralHistos(ntp);
06972   
06973   //simple event object to hold important quantities for snarl
06974   NuEvent nuSnarl;
06975   this->CopyConfig(config,nuSnarl);
06976 
06977   //get the run, snarl, etc info
06978   lib.ext.ExtractGeneralInfo(ntp,nuSnarl);
06979   lib.ext.ExtractBeamInfoDB(nuSnarl);//done again later per event
06980 
06981   //extract coil current early in order to get POT counting right
06982   //doesn't matter for the FD because POTs are externally defined
06983   lib.ext.ExtractCoilInfo(nuSnarl);
06984   plots.FillCoilCurrentHistos(nuSnarl);
06985   if (nuSnarl.coilIsOk) lib.cnt.goodCoilCurrentSpillCounter++;
06986 
06987   //extract the data quality early as well (to get pot counting right)
06988   //the data quality variable can be cut on at analysis time 
06989   //as long as the definition of data quality is exactly 
06990   //the same (otherwise pot counting is wrong)
06991   lib.ext.ExtractDataQuality(nuSnarl);//done again later per event
06992 
06993   //get POT and event time info
06994   beam.IsGoodSpillAndFillPot(pntpBD,config,nuSnarl);
06995   time.FillTime(nuSnarl.timeSec,nuSnarl.pot,nuSnarl.goodBeamSntp);
06996   if (!(nuSnarl.goodBeamSntp && nuSnarl.coilIsOk && 
06997         (nuSnarl.isGoodDataQuality || !nuSnarl.useDBForDataQuality))) {
06998     lib.cnt.badSpillCounter++;
06999     lib.cnt.totalPotBad+=nuSnarl.pot;
07000   }
07001   else {
07002     lib.cnt.goodSpillCounter++;
07003     lib.cnt.totalPot+=nuSnarl.pot;   
07004   }
07005   
07006   //count the pots since the last evt was written to file
07007   static Float_t potSinceLastEvt=0;
07008   static Float_t potSinceLastEvtGood=0;
07009   static Float_t potSinceLastEvtBad=0;
07010   static Float_t potSinceLastEvtDB=0;
07011   static Float_t potSinceLastEvtGoodDB=0;
07012   static Float_t potSinceLastEvtBadDB=0;
07013   
07014   //count the sntp version of pots
07015   potSinceLastEvt+=nuSnarl.pot;
07016   if (nuSnarl.goodBeamSntp && 
07017       nuSnarl.coilIsOk && 
07018       nuSnarl.isGoodDataQuality) potSinceLastEvtGood+=nuSnarl.pot;
07019   else potSinceLastEvtBad+=nuSnarl.pot;
07020   
07021   //count the database version of pots
07022   potSinceLastEvtDB+=nuSnarl.potDB;
07023   if (nuSnarl.goodBeam && 
07024       nuSnarl.coilIsOk && 
07025       nuSnarl.isGoodDataQuality) potSinceLastEvtGoodDB+=nuSnarl.potDB;
07026   else potSinceLastEvtBadDB+=nuSnarl.potDB;
07027   
07028   //get the tca of evts
07029   TClonesArray& evtTca=(*ntp.evt);
07030   const Int_t numEvts=evtTca.GetEntriesFast();
07031 
07033   //loop over the reconstructed events
07035   std::vector<Int_t> vTrueEventsToStore;
07036   for (Int_t ievt=0;ievt<numEvts;ievt++){
07037     const NtpSREvent& evt= *dynamic_cast<NtpSREvent*>(evtTca[ievt]);
07038     lib.cnt.evtCounter++;
07039       
07040     MAXMSG("NuAnalysis",Msg::kInfo,5)
07041       <<"Found event "<<ievt+1<<"/"<<numEvts
07042       <<", ntrk="<<evt.ntrack<<endl;
07043     
07044     //simple event object to hold important quantities
07045     NuEvent& nu=output.GetNuEventToFill();
07046 
07048     //prepare NuMuBar variables to write
07049     //loose pre-selection cut: just require 1 or more trks
07050     //removed to include NC events
07051     //if (evt.ntrack<1) continue;
07052     //lib.cnt.evtWithTrkCounter++;
07053 
07054     //get rid of LI events
07055     const NtpSREventSummary& evthdr=ntp.evthdr;
07056     if (evthdr.litime!=-1) continue;
07057     lib.cnt.evtNotlitime++;
07058  
07059     nu.entry=lib.cnt.entry;//store the entry in the tree number
07060     nu.nevt=numEvts;//store the numEvts in snarl
07061     //copy info, copy the analysis (cuts and reco) version to use
07062     this->CopySnarlInfo(nuSnarl,nu);
07063     this->CopyConfig(config,nu);
07064  
07065     //extract the general info and evt, trk and shw info
07066     lib.ext.ExtractBasicInfo(ntp,evt,nu);
07067 
07068     //check if trk or evt vertex is in the loose fid vol
07069     if (!lib.cuts.IsInFidVolLoose(nu)) continue;
07070     lib.cnt.evtInFidVolCounter++;
07071  
07072     //extract NC info
07073     lib.ext.ExtractNCInfo(pntp, ievt, nu);
07074 
07075     //RECONSTRUCT the neutrino energy, including kNN
07076     lib.reco.GetEvtEnergy(nu, true);
07077 
07078     MAXMSG("NuAnalysis",Msg::kDebug,10)
07079       <<endl<<"After reco:"<<endl
07080       <<plots.PrintEventInfo(cout,nu)<<endl;
07081 
07082     //do multiple extractions
07083     this->DoExtractions(ntp,evt,pntpSA,pid,nu);
07084 
07085 
07086     //Get a list of all the truth events which contribute to reco events
07087     const std::vector<Int_t> vTthInd = this->ContributingTrueEvents(nu);
07088     vTrueEventsToStore.insert(vTrueEventsToStore.end(),
07089                               vTthInd.begin(),
07090                               vTthInd.end());
07091 
07092     MAXMSG("NuAnalysis",Msg::kInfo,10)
07093       <<"PID: dp="<<nu.dpID<<", ab="<<nu.abID<<", ro="<<nu.roID
07094       <<", po="<<nu.poID<<", roNMB="<<nu.roIDNuMuBar<<endl;
07095     
07096     //count the positive and negative events
07097     if (nu.charge==-1) lib.cnt.nuNQCounter++;
07098     else if (nu.charge==+1) lib.cnt.nuPQCounter++;
07099     else if (nu.ntrk>0) lib.cnt.nuNoQCounter++;
07100     else if (nu.ntrk==-1) lib.cnt.nuNoTrkCounter++;
07101 
07102 
07103     //figure out the first and last time in the whole ntuple
07104     //this is very useful for making plots of quantities vs time
07105     plots.FillNtupleEarliestLatestTime(nu);
07106 
07107 
07108     //write out the pots since the last evt
07109     //this variable takes account of spills with zero entries
07110     //and spills with >=2 evts
07111     nu.potSinceLastEvt=potSinceLastEvt;
07112     nu.potSinceLastEvtGood=potSinceLastEvtGood;
07113     nu.potSinceLastEvtBad=potSinceLastEvtBad;
07114     nu.potSinceLastEvtDB=potSinceLastEvtDB;
07115     nu.potSinceLastEvtGoodDB=potSinceLastEvtGoodDB;
07116     nu.potSinceLastEvtBadDB=potSinceLastEvtBadDB;
07117     potSinceLastEvt=0;//reset this for the next loop
07118     potSinceLastEvtGood=0;
07119     potSinceLastEvtBad=0;
07120     potSinceLastEvtDB=0;
07121     potSinceLastEvtGoodDB=0;
07122     potSinceLastEvtBadDB=0;
07123 
07125     //fill the tree
07126     output.FillNuEventTree();      
07127   }//end of loop over reconstructed events
07128 
07129   //now loop over all the true events
07130   this->LoopOverTruthInfo(ntp,output,nuSnarl,vTrueEventsToStore);
07131 }
07132 
07133 //......................................................................

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