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

NCEventInfo.cxx

Go to the documentation of this file.
00001 #include "NCEventInfo.h"
00002 
00003 #include <cassert>
00004 
00005 #include "AnalysisNtuples/ANtpAnalysisInfo.h"
00006 #include "AnalysisNtuples/ANtpBeamInfo.h"
00007 #include "AnalysisNtuples/ANtpDefaultValue.h"
00008 #include "AnalysisNtuples/ANtpEventInfo.h"
00009 #include "AnalysisNtuples/ANtpEventInfoNC.h"
00010 #include "AnalysisNtuples/ANtpHeaderInfo.h"
00011 #include "AnalysisNtuples/ANtpRecoInfo.h"
00012 #include "AnalysisNtuples/ANtpShowerInfo.h"
00013 #include "AnalysisNtuples/ANtpShowerInfoNC.h"
00014 #include "AnalysisNtuples/ANtpTrackInfoAtm.h"
00015 #include "AnalysisNtuples/ANtpTrackInfoNC.h"
00016 #include "AnalysisNtuples/ANtpTruthInfo.h"
00017 #include "AnalysisNtuples/ANtpTruthInfoAtm.h"
00018 #include "AnalysisNtuples/ANtpTruthInfoBeam.h"
00019 
00020 #include "Conventions/Detector.h"
00021 #include "Conventions/Munits.h"
00022 
00023 #include "DataUtil/EnergyCorrections.h"
00024 
00025 #include "MCReweight/MCReweight.h"
00026 #include "MCReweight/SKZPWeightCalculator.h"
00027 
00028 #include "MessageService/MsgService.h"
00029 
00030 #include "Validity/VldTimeStamp.h"
00031 #include "Validity/VldContext.h"
00032 
00033 
00034 #include "TChain.h"
00035 #include "TDirectory.h"
00036 #include "TFile.h"
00037 #include "TH2F.h"
00038 #include "TMath.h"
00039 #include "TRandom.h"
00040 #include "TSystem.h"
00041 
00042 #include "NCUtils/NCOscProb.h"
00043 #include "NCUtils/NCType.h"
00044 #include "NCUtils/NCRunUtil.h"
00045 #include "NCUtils/NCUtility.h"
00046 using NC::Utility::SQR;
00047 
00048 using namespace EnergyCorrections;
00049 
00050 CVSID("$Id: NCEventInfo.cxx,v 1.24 2009/03/04 12:07:46 bckhouse Exp $");
00051 
00052 const ReleaseType::Release_t kReleaseTypeData = ReleaseType::kCedarPhy;
00053 const ReleaseType::Release_t kReleaseTypeMC = ReleaseType::kCedarPhy+ReleaseType::kDaikon;
00054 
00055 static const int kQE = 0;
00056 static const int kRES = 1;
00057 static const int kDIS = 2;
00058 static const int kBeamToZbeam[14] = {0, 2, 0, 0, 3, 4, 5, 6, 7, 8, 2, 2, 2, 0};
00059 
00060 // define static member
00061 NCEventInfo::INukeHists NCEventInfo::sfINukeHists;
00062 
00063 NCEventInfo::INukeHists::INukeHists()
00064 {
00065   //save the current working directory
00066   TDirectory* tmp = gDirectory;
00067 
00068   //  fCuts = new NCAnalysisCutsNC();
00069   //  fZbeam = new Zbeam();
00070   //  fZfluk = new Zfluk();
00071 
00072   //  fSKZPWeight = new SKZPWeightCalculator(beamWeightConfig,true);
00073   //  fZbeam->SetReweightConfig(beamWeightConfig);
00074 
00075   // ---RPL 05/09/06: instantiate the mcReweight object now, and give
00076   // it a (neugen) weight calculator
00077   // Back this off; Brian says it should be done in the script.
00078   //MCReweight &mcReweight = MCReweight::Instance();
00079   //fNeugenWeightCal = new NeugenWeightCalculator();
00080   //mcReweight.AddWeightCalculator(fNeugenWeightCal);
00081   // ---
00082 
00083   //gotta load shower energy weighting histograms from Mike K.
00084   TString scaleFromName = "integrated_smearing_histos_default.root";
00085   TString scaleToNameMinus = "integrated_smearing_histos_1501.root";
00086   TString scaleToNamePlus = "integrated_smearing_histos_1500.root";
00087   TString offsetName = "integrated_smearing_histos_offset.root";
00088 
00089   TString topDir="MCReweight/data";
00090   TString base=getenv("SRT_PRIVATE_CONTEXT");
00091   if(base!="" && base!="."){
00092     // check if directory exists in SRT_PRIVATE_CONTEXT
00093     TString path = base + "/" + topDir;
00094     void *dir_ptr = gSystem->OpenDirectory(path);
00095     if(!dir_ptr) base=getenv("SRT_PUBLIC_CONTEXT");
00096   }
00097   // if it doesn't exist then use SRT_PUBLIC_CONTEXT
00098   else base=getenv("SRT_PUBLIC_CONTEXT");
00099 
00100   if(base==""){
00101     MSG("NCUtils",Msg::kFatal) << "No SRT_PUBLIC_CONTEXT set" << endl;
00102     assert(false);
00103   }
00104   topDir = base+ "/" + topDir + "/";
00105 
00106   MSG("NCUtils",Msg::kDebug)
00107     << "Zbeam reading files from: " << topDir << endl;
00108   TFile scaleFileFrom(topDir+scaleFromName);
00109   TFile scaleFileToMinus(topDir+scaleToNameMinus);
00110   TFile scaleFileToPlus(topDir+scaleToNamePlus);
00111   TFile offsetFile(topDir+offsetName);
00112 
00113   TString names[] = {"h_qe", "h_res", "h_dis"};
00114 
00115   TH2F *histFrom = dynamic_cast<TH2F *>(scaleFileFrom.Get(names[kQE]));
00116   TH2F *histToMinus = dynamic_cast<TH2F *>(scaleFileToMinus.Get(names[kQE]));
00117   TH2F *histToPlus = dynamic_cast<TH2F *>(scaleFileToPlus.Get(names[kQE]));
00118   TH2F *hist = dynamic_cast<TH2F *>(offsetFile.Get(names[kQE]));
00119 
00120   for(int i = kQE; i < kDIS+1; ++i){
00121 
00122     histFrom = dynamic_cast<TH2F *>(scaleFileFrom.Get(names[i]));
00123     histToMinus = dynamic_cast<TH2F *>(scaleFileToMinus.Get(names[i]));
00124     histToPlus = dynamic_cast<TH2F *>(scaleFileToPlus.Get(names[i]));
00125     hist = dynamic_cast<TH2F *>(offsetFile.Get(names[i]));
00126 
00127     MSG("NCAnalysisUtils", Msg::kDebug)
00128       << histFrom->GetName() << " "
00129       << histToMinus->GetName() << " "
00130       << histToPlus->GetName() << " "
00131       << hist->GetName() << endl;
00132 
00133     from.push_back(histFrom);
00134     toMinus.push_back(histToMinus);
00135     toPlus.push_back(histToPlus);
00136     offset.push_back(hist);
00137 
00138     from[i]->SetDirectory(0);
00139     toMinus[i]->SetDirectory(0);
00140     toPlus[i]->SetDirectory(0);
00141     offset[i]->SetDirectory(0);
00142 
00143     MSG("NCAnalysisUtils", Msg::kDebug)
00144       << from[i]->GetName() << " "
00145       << toMinus[i]->GetName() << " "
00146       << toPlus[i]->GetName() << " "
00147       << offset[i]->GetName() << endl;
00148 
00149   }//end loop to fill histograms
00150 
00151   gDirectory = tmp;
00152 }
00153 
00154 //---------------------------------------------------------------------
00155 NCEventInfo::INukeHists::~INukeHists()
00156 {
00157   for(unsigned int n = 0; n < offset.size(); ++n) delete offset[n];
00158   for(unsigned int n = 0; n < from.size(); ++n) delete from[n];
00159   for(unsigned int n = 0; n < toMinus.size(); ++n) delete toMinus[n];
00160   for(unsigned int n = 0; n < toPlus.size(); ++n) delete toPlus[n];
00161 }
00162 
00163 //---------------------------------------------------------------------
00164 void NCEventInfo::DeepCopy(const NCEventInfo* evt)
00165 {
00166 #define COPYFIELD(fld, typ) \
00167   if(evt->fld){             \
00168     if(!fld) fld = new typ; \
00169     *fld = *evt->fld;       \
00170   }                         \
00171   else{                     \
00172     if(fld) delete fld;     \
00173     fld = 0;                \
00174   }
00175 
00176   COPYFIELD(analysis, ANtpAnalysisInfo);
00177   COPYFIELD(beam,     ANtpBeamInfo);
00178   COPYFIELD(event,    ANtpEventInfoNC);
00179   COPYFIELD(header,   ANtpHeaderInfo);
00180   COPYFIELD(reco,     ANtpRecoInfo);
00181   COPYFIELD(shower,   ANtpShowerInfoNC);
00182   COPYFIELD(track,    ANtpTrackInfoNC);
00183   COPYFIELD(truth,    ANtpTruthInfoBeam);
00184 
00185 #undef COPYFIELD
00186 }
00187 
00188 //---------------------------------------------------------------------
00189 double NCEventInfo::GetEventVertex(double& x, double& y, double& z)
00190 {
00191   // choice of whether to use Event or Track vertex should follow what is in
00192   //NCAnalysisCuts::InBeamFiducialVolumeOx(), otherwise the vertex that is being
00193   //cut and the vertex that is being stored are not the same
00194 
00195   assert(header);
00196   assert(reco || (event && track && shower));
00197 
00198   if(reco){
00199     x = reco->vtxX;
00200     y = reco->vtxY;
00201     z = reco->vtxZ;
00202   }
00203   else{
00204     if(event->tracks > 0
00205        && track->planes - shower->planes > 0){
00206       x = track->vtxX;
00207       y = track->vtxY;
00208       z = track->vtxZ  - NCType::kTrackVtxAdjustment;
00209     }
00210     else{
00211       x = event->vtxX;
00212       y = event->vtxY;
00213       z = event->vtxZ;
00214     }
00215   }
00216 
00217   if(header->detector == int(Detector::kNear)){
00218     x -= NCType::kNDBeamCenterX;
00219     y -= NCType::kNDBeamCenterY + NCType::kNDBeamAngle*z;
00220   }
00221 
00222   return TMath::Sqrt(x*x + y*y);
00223 }
00224 
00225 
00226 //---------------------------------------------------------------------
00227 double NCEventInfo::GetEventEnergy(CandShowerHandle::ShowerType_t showerType,
00228                                    bool stoppingBeamMuon)
00229 {
00230   double showerEnergy = 0.;
00231   double trackEnergy = 0.;
00232 
00233   if(reco){
00234     return reco->nuEnergy;
00235   }
00236   else{
00237     if(event->showers > 0)
00238       showerEnergy = GetShowerEnergy(showerType);
00239     if(event->tracks > 0)
00240       trackEnergy = GetTrackEnergy(stoppingBeamMuon);//fCuts->IsStoppingBeamMuon());
00241   }
00242 
00243   if(showerType == CandShowerHandle::kWtNC) return showerEnergy;
00244 
00245   return trackEnergy + showerEnergy;
00246 }
00247 
00248 
00249 //---------------------------------------------------------------------
00250 double NCEventInfo::GetTrackEnergy(bool contained)
00251 {
00252   assert(header);
00253 
00254   ReleaseType::Release_t releaseType = kReleaseTypeData;
00255   SimFlag::SimFlag_t sim = SimFlag::kData;
00256   if(header->dataType == int(SimFlag::kMC)){
00257     sim = SimFlag::kMC;
00258     releaseType = kReleaseTypeMC;
00259   }
00260 
00261   Detector::Detector_t det = Detector::kNear;
00262   if(header->detector == int(Detector::kFar))
00263     det = Detector::kFar;
00264 
00265   //get a validity context for the energy corrections
00266   VldContext vldc(det, sim, GetTimestamp());
00267 
00268   bool fromCurve = false;
00269   bool fromRange = false;
00270 
00271   double inputMomentum;
00272 
00273   //check if this is a stopping muon first
00274   if(reco){
00275     if(reco->isFullyContained){
00276       fromRange = true;
00277       inputMomentum = reco->trackRange;
00278     }
00279     else{
00280       fromCurve = true;
00281       inputMomentum = reco->trackMomentum;
00282     }
00283   }
00284   // check if this is a stopping muon first or the fit value is stupid,
00285   // use the range momentum
00286   else if(contained || track->fitMomentum < -9000) {
00287     if(track->rangeMomentum > 0){
00288       fromRange = true;
00289       inputMomentum = track->rangeMomentum;
00290     }
00291     else{
00292       fromCurve = true;
00293       inputMomentum = track->fitMomentum;
00294     }
00295   }
00296   else{
00297     fromCurve = true;
00298     inputMomentum = track->fitMomentum;
00299   }
00300 
00301   assert(fromCurve || fromRange);
00302   assert(!(fromCurve && fromRange));
00303 
00304   // required to shut gcc up in optimized mode
00305   // the asserts above guarantee that one of the branches below will be taken
00306   double trackMomentum = 0;
00307 
00308   if(fromCurve)
00309     trackMomentum = FullyCorrectSignedMomentumFromCurvature(inputMomentum,
00310                                                             vldc, releaseType);
00311   if(fromRange)
00312     trackMomentum = FullyCorrectMomentumFromRange(inputMomentum,
00313                                                   vldc, releaseType);
00314 
00315   return TMath::Sqrt(SQR(trackMomentum) + SQR(NCType::kMuMassGeV));
00316 }
00317 
00318 
00319 //---------------------------------------------------------------------
00320 double NCEventInfo::GetShowerEnergy(CandShowerHandle::ShowerType_t showerType)
00321 {
00322   assert(header);
00323   assert(reco || shower);
00324 
00325   ReleaseType::Release_t releaseType = kReleaseTypeData;
00326   SimFlag::SimFlag_t sim = SimFlag::kData;
00327   if(header->dataType == int(SimFlag::kMC)){
00328     sim = SimFlag::kMC;
00329     releaseType = kReleaseTypeMC;
00330   }
00331 
00332   Detector::Detector_t det = Detector::kNear;
00333   if(header->detector == int(Detector::kFar))
00334     det = Detector::kFar;
00335 
00336   //get a validity context for the energy corrections
00337   VldContext vldc(det, sim, GetTimestamp());
00338 
00339   if(reco){
00340     if(reco->showerEnergy < 0) return ANtpDefaultValue::kDouble;
00341 
00342     return FullyCorrectShowerEnergy(reco->showerEnergy,
00343                                     showerType, vldc, releaseType);
00344   }
00345 
00346   double showerEnergy = ANtpDefaultValue::kDouble;
00347 
00348   switch(showerType){
00349   case CandShowerHandle::kCC:
00350     showerEnergy = shower->linearCCGeV;
00351     break;
00352   case CandShowerHandle::kWtCC:
00353     showerEnergy = shower->deweightCCGeV;
00354     break;
00355   case CandShowerHandle::kNC:
00356     showerEnergy = shower->linearNCGeV;
00357     break;
00358   case CandShowerHandle::kWtNC:
00359     showerEnergy = shower->deweightNCGeV;
00360     break;
00361   case CandShowerHandle::kEM:
00362     assert(0 && "Not implemented");
00363   }
00364 
00365   if(showerEnergy > 0)
00366     return FullyCorrectShowerEnergy(showerEnergy,
00367                                     showerType, vldc, releaseType);
00368 
00369   return showerEnergy;
00370 }
00371 
00372 
00373 //---------------------------------------------------------------------------
00374 //will find MODBYRS3 weight for MC version carrot or earlier even when all
00375 //values of useParameters are set to false.
00376 double NCEventInfo::FindNeugenWeight(const bool* useParameters,
00377                                      const std::vector<double>& adjustedValues,
00378                                      bool useMODBYRS3, int overrideMODBYRS)
00379 {
00380   assert(truth);
00381 
00382   TString neugen = "neugen:";
00383 
00384   MCReweight &mcReweight = MCReweight::Instance();
00385 
00386   int nucleus = 1; //default
00387 
00388   //figure out the nucleus
00389   if(int(truth->atomicNumber == 1))  nucleus = 0; // free
00390   else if(int(truth->atomicNumber == 6))  nucleus = 274; // oxygen
00391   else if(int(truth->atomicNumber == 8))  nucleus = 284; // carbon
00392   else if(int(truth->atomicNumber == 26)) nucleus = 372; // iron
00393 
00394   if(nucleus == 1) return 1;
00395 
00396   MCEventInfo ei;
00397   ei.nuE           = truth->nuEnergy;
00398   ei.nuPx          = truth->nuDCosX*truth->nuEnergy;
00399   ei.nuPy          = truth->nuDCosY*truth->nuEnergy;
00400   ei.nuPz          = truth->nuDCosZ*truth->nuEnergy;
00401   ei.tarE          = truth->targetEnergy;
00402   ei.tarPx         = truth->targetPX;
00403   ei.tarPy         = truth->targetPY;
00404   ei.tarPz         = truth->targetPZ;
00405   ei.y             = truth->hadronicY;
00406   ei.x             = truth->bjorkenX;
00407   ei.q2            = truth->q2;
00408   ei.w2            = truth->w2;
00409   ei.iaction       = truth->interactionType;
00410   ei.inu           = truth->nuFlavor;
00411   ei.iresonance    = truth->resonanceCode;
00412   ei.initial_state = truth->initialState;
00413   ei.nucleus       = nucleus;
00414   ei.had_fs        = truth->hadronicFinalState;
00415 
00416   NuParent* np = 0;
00417 
00418   Registry fReweightConfigRegistry;
00419   fReweightConfigRegistry.UnLockValues();
00420   Registry defaultConfigRegistry;
00421 
00422   const char* mcString = (header->softVersion).Data();
00423   ReleaseType::Release_t mcType=ReleaseType::StringToType(mcString);
00424 
00425 
00426   //Only apply MODBYRS3 for Carrot or earlier
00427   //Note: According to discussion with Hugh G. and
00428   //Tricia V., Carrot was actually generated with MODBYRS2
00429   //and then found to agree better with data using MODBYRS3.
00430   //Anyone using this code on carrot will get unweighted carrot if
00431   //useMODBYRS3=false and reweighted carrot if flag useMODBYRS3=true
00432 
00433   //overriding default version values for MODBYRS
00434   if(overrideMODBYRS != 0)
00435   {
00436      fReweightConfigRegistry.Set("neugen:config_name", "MODBYRS");
00437      fReweightConfigRegistry.Set("neugen:config_no", overrideMODBYRS);
00438   }
00439   //no override
00440   else
00441   {
00442      if(useMODBYRS3 && ReleaseType::IsCarrot(mcType) ){
00443         fReweightConfigRegistry.Set("neugen:config_name", "MODBYRS");
00444         fReweightConfigRegistry.Set("neugen:config_no", 3);
00445      }
00446      else if(ReleaseType::IsDaikon(mcType)){
00447         fReweightConfigRegistry.Set("neugen:config_name", "MODBYRS");
00448         fReweightConfigRegistry.Set("neugen:config_no", 4);
00449      }
00450   }
00451   /*
00452   if((int) useParameters.size() < NCType::kNumNeugenParameters){
00453     MSG("NCAnalysisUtils", Msg::kWarning) << "use parameters not same size"
00454                                           << " as neugen parameters - return"
00455                                           << " weight of 1." << endl;
00456     return 1.;
00457   }
00458   */
00459 
00460   //set the configuration for the reweight based on the percent change
00461   double change = 1.;
00462   for(int i = 0; i < (int)adjustedValues.size(); ++i){
00463     change = adjustedValues[i];
00464 
00465     //for now the reweighting doesnt work right - see comment below
00466     //make sure that the defaults for all unchanged parameters are the
00467     //current defaults
00468     if(!useParameters[i]
00469        && i < NCType::kDISFACT
00470        && !(i == NCType::kma_qe && useParameters[NCType::kCCMA])
00471        && !(i == NCType::kma_res && useParameters[NCType::kCCMA])
00472        && !(i == NCType::kkno_r112 && useParameters[NCType::kkno_r112122])
00473        && !(i == NCType::kkno_r122 && useParameters[NCType::kkno_r112122])
00474        && !(i == NCType::kkno_r113 && useParameters[NCType::kkno_r113123])
00475        && !(i == NCType::kkno_r123 && useParameters[NCType::kkno_r113123])
00476        && !(i == NCType::kkno_r212 && useParameters[NCType::kkno_r212222])
00477        && !(i == NCType::kkno_r222 && useParameters[NCType::kkno_r212222])
00478        && !(i == NCType::kkno_r213 && useParameters[NCType::kkno_r213223])
00479        && !(i == NCType::kkno_r223 && useParameters[NCType::kkno_r213223])) {
00480 
00481        if(ReleaseType::IsDaikon(mcType))
00482        {
00483           fReweightConfigRegistry.Set(neugen+NCType::kParams[i].name,
00484                                       NCType::kParams[i].defaultVal);
00485        }
00486     }
00487 
00488     if(useParameters[i] && i < NCType::kDISFACT){
00489       fReweightConfigRegistry.Set(neugen+NCType::kParams[i].name, change);
00490     }
00491     else if(useParameters[i] && i == NCType::kDISFACT){
00492       //here adjusted values is the fractional change for the parameters,
00493       //multiply it by the default values
00494       fReweightConfigRegistry.Set("neugen:kno_r112",
00495                                   change*NCType::kParams[NCType::kkno_r112].defaultVal);
00496       fReweightConfigRegistry.Set("neugen:kno_r122",
00497                                   change*NCType::kParams[NCType::kkno_r122].defaultVal);
00498       fReweightConfigRegistry.Set("neugen:kno_r132",
00499                                   change*NCType::kParams[NCType::kkno_r132].defaultVal);
00500       fReweightConfigRegistry.Set("neugen:kno_r142",
00501                                   change*NCType::kParams[NCType::kkno_r142].defaultVal);
00502       fReweightConfigRegistry.Set("neugen:kno_r113",
00503                                   change*NCType::kParams[NCType::kkno_r113].defaultVal);
00504       fReweightConfigRegistry.Set("neugen:kno_r123",
00505                                   change*NCType::kParams[NCType::kkno_r123].defaultVal);
00506       fReweightConfigRegistry.Set("neugen:kno_r133",
00507                                   change*NCType::kParams[NCType::kkno_r133].defaultVal);
00508       fReweightConfigRegistry.Set("neugen:kno_r143",
00509                                   change*NCType::kParams[NCType::kkno_r143].defaultVal);
00510     }
00511     else if(useParameters[i] && i == NCType::kCCMA){
00512       fReweightConfigRegistry.Set("neugen:ma_qe",
00513                                   change*NCType::kParams[NCType::kma_qe].defaultVal);
00514       fReweightConfigRegistry.Set("neugen:ma_res",
00515                                   change*NCType::kParams[NCType::kma_res].defaultVal);
00516     }
00517     else if(useParameters[i] && i == NCType::kkno_r112122){
00518       fReweightConfigRegistry.Set("neugen:kno_r112",
00519                                   change*NCType::kParams[NCType::kkno_r112].defaultVal);
00520       fReweightConfigRegistry.Set("neugen:kno_r122",
00521                                   change*NCType::kParams[NCType::kkno_r122].defaultVal);
00522     }
00523     else if(useParameters[i] && i == NCType::kkno_r113123){
00524       fReweightConfigRegistry.Set("neugen:kno_r113",
00525                                   change*NCType::kParams[NCType::kkno_r113].defaultVal);
00526       fReweightConfigRegistry.Set("neugen:kno_r123",
00527                                   change*NCType::kParams[NCType::kkno_r123].defaultVal);
00528     }
00529     else if(useParameters[i] && i == NCType::kkno_r212222){
00530       fReweightConfigRegistry.Set("neugen:kno_r212",
00531                                   change*NCType::kParams[NCType::kkno_r212].defaultVal);
00532       fReweightConfigRegistry.Set("neugen:kno_r222",
00533                                   change*NCType::kParams[NCType::kkno_r222].defaultVal);
00534     }
00535     else if(useParameters[i] && i == NCType::kkno_r213223){
00536       fReweightConfigRegistry.Set("neugen:kno_r213",
00537                                   change*NCType::kParams[NCType::kkno_r213].defaultVal);
00538       fReweightConfigRegistry.Set("neugen:kno_r223",
00539                                   change*NCType::kParams[NCType::kkno_r223].defaultVal);
00540     }
00541 
00542   }//end loop over adjusted values
00543 
00544   mcReweight.ResetAllReweightConfigs();
00545 
00546   double weight = mcReweight.ComputeWeight(&ei,np,&fReweightConfigRegistry);
00547 
00548   //reweighting is in strange state right now - it returns the weight
00549   //with respect to parameters as of MODBYRS2 - Daikon is MODBYRS4
00550   //so have to get weight from MODBYRS2 defaults to MODBYRS4 defaults first
00551   double defaultWeight = 1.;
00552   if(ReleaseType::IsDaikon(mcType)){
00553     defaultConfigRegistry.Set("neugen:config_name", "MODBYRS");
00554     defaultConfigRegistry.Set("neugen:config_no", 4);
00555 
00556     //use defaults for all parameters up to the combinations
00557     for(int i = 0; i < NCType::kDISFACT; ++i)
00558       defaultConfigRegistry.Set(neugen+NCType::kParams[i].name,
00559                                 NCType::kParams[i].defaultVal);
00560 
00561     mcReweight.ResetAllReweightConfigs();
00562 
00563     defaultWeight = mcReweight.ComputeWeight(&ei,np,&defaultConfigRegistry);
00564 
00565   }//end if daikon
00566 
00567   //divide reweight by default weight
00568   //cout << "oldw = " << weight << endl;
00569   if(TMath::Abs(defaultWeight) > 0.) weight /= defaultWeight;
00570   //cout << "neww = " << weight << endl;
00571   //cout << "neww*w = " << weight * reco->weight << endl;
00572   if( TMath::IsNaN(weight) ){
00573     MSG("NCAnalysisUtils", Msg::kWarning)
00574       << "mcreweight IsNaN "
00575       <<  truth->nuEnergy
00576       << " " << truth->interactionType
00577       << " " << truth->resonanceCode
00578       << " " << truth->nuFlavor
00579       << " " << truth->initialState
00580       << " " << truth->hadronicFinalState
00581       << " " << nucleus
00582       << endl;
00583     weight = 1.;
00584   }
00585 
00586   if(weight != 1.){
00587     MAXMSG("NCAnalysisUtils", Msg::kDebug, 100)
00588       << "mcreweight to " << weight << endl
00589       << "values into neugen" << endl
00590       << "event:nu_en "
00591       << truth->nuEnergy << endl
00592       << "event:nu_px "
00593       << truth->nuDCosX*truth->nuEnergy << endl
00594       << "event:nu_py "
00595       << truth->nuDCosY*truth->nuEnergy << endl
00596       << "event:nu_pz "
00597       << truth->nuDCosZ*truth->nuEnergy << endl
00598       << "event:tar_en "
00599       << truth->targetEnergy << endl
00600       << "event:tar_px "
00601       << truth->targetPX << endl
00602       << "event:tar_py "
00603       << truth->targetPY << endl
00604       << "event:tar_pz "
00605       << truth->targetPZ << endl
00606       << "event:x "
00607       << truth->bjorkenX << endl
00608       << "event:y "
00609       << truth->hadronicY << endl
00610       << "event:q2 " << truth->q2 << endl
00611       << "event:w2 " << truth->w2 << endl
00612       << "event:iaction "
00613       << truth->interactionType << endl
00614       << "event:inu "
00615       << truth->nuFlavor << endl
00616       << "event:iresonance "
00617       << truth->resonanceCode << endl
00618       << "event:initial_state "
00619       << truth->initialState << endl
00620       << "event:nucleus " << nucleus << endl
00621       << "event:had_fs "
00622       << truth->hadronicFinalState
00623       << endl << endl;
00624   }
00625 
00626   return weight;
00627 }
00628 
00629 
00630 //---------------------------------------------------------------------------
00631 double NCEventInfo::FindCrossSectionWeight(const bool* useParameters,
00632                                            const std::vector<double>& adjustedValues) const
00633 {
00634   double weight = 1.;
00635   double trueE = truth->nuEnergy;
00636 
00637   if(useParameters[NCType::kNCCrossSection]
00638      && truth->interactionType == NCType::kNC){
00639     if(trueE <= 10.)
00640       weight = 1. + 0.2*adjustedValues[NCType::kNCCrossSection];
00641     else if(trueE < 100.)
00642       weight = 1. + 0.2*(1. - 0.0111*(trueE-10.))*adjustedValues[NCType::kNCCrossSection];
00643     else
00644       weight = 1.;
00645   }
00646 
00647   if(useParameters[NCType::kNuBarCrossSection]
00648      && truth->interactionType == NCType::kCC
00649      && truth->nuFlavor < 0)
00650     weight *= 1. + adjustedValues[NCType::kNuBarCrossSection];
00651 
00652   return weight;
00653 }
00654 
00655 
00656 //----------------------------------------------------------------------
00657 //calls FindNeugenWeight without any parameters set to true.  FindNeugenWeight
00658 //returns the MODBYRS3 weight in that case if the release is carrot or
00659 //earlier, otherwise returns 1.
00660 double NCEventInfo::FindMODBYRSWeight()
00661 {
00662   vector<double> adjustedValues;
00663   bool useParameters[NCType::kNumNeugenParameters] = {false,};
00664 
00665   for(int i = 0; i < NCType::kNumNeugenParameters; ++i){
00666     adjustedValues.push_back(NCType::kParams[i].defaultVal);
00667   }
00668 
00669   return FindNeugenWeight(useParameters, adjustedValues);
00670 }
00671 
00672 
00673 //---------------------------------------------------------------------------
00674 //this version of the method uses the shiny new functionality
00675 //in MCReweight to get the #'s from the db
00676 double NCEventInfo::FindMEGAFitWeight(SKZPWeightCalculator* SKZPWeight, int beamType, int runType)
00677 {
00678   //check if there is a beam object loaded, if so use it to get the beam type,
00679   //otherwise use the passed in int.
00680   int beamt = beamType;
00681   if(beam) beamt = beam->beamType;
00682   SKZPWeightCalculator::RunPeriod_t rp = SKZPWeightCalculator::kRunI;
00683   if(runType == NC::RunUtil::kRunII) rp = SKZPWeightCalculator::kRunII;
00684 
00685   double pt = TMath::Sqrt(SQR(truth->targetParentPX)
00686                           +SQR(truth->targetParentPY));
00687   double emuNew = 0.;
00688   double eshwNew = 0.;
00689   double beamweight = 0.;
00690   double detweight = 0.;
00691   double weightbeam = SKZPWeight->GetWeight(header->detector,
00692                                             beamt,
00693                                             truth->targetParentType,
00694                                             pt,
00695                                             1.*truth->targetParentPZ,
00696                                             truth->interactionType,
00697                                             truth->nuEnergy,
00698                                             truth->nuFlavor,
00699                                             0.,
00700                                             0.,
00701                                             emuNew,
00702                                             eshwNew,
00703                                             beamweight,
00704                                             detweight,
00705                                             rp);
00706 
00707   //only do the MODBYRS weighting if using carrot
00708   double weightMODBYRS = 1.;
00709   const char* mcString = (header->softVersion).Data();
00710   ReleaseType::Release_t mcType = ReleaseType::StringToType(mcString);
00711   if( ReleaseType::IsCarrot(mcType) ) weightMODBYRS = FindMODBYRSWeight();
00712 
00713   MAXMSG("NCAnalysisUtils", Msg::kDebug, 10)
00714     << "MODBYRS3 = " << weightMODBYRS
00715     << " beam = " << weightbeam
00716     << endl;
00717 
00718   return weightMODBYRS*weightbeam;
00719 }
00720 
00721 
00722 //---------------------------------------------------------------------------
00723 double NCEventInfo::FindMEGAFitWeightUncertainty(int beamType,
00724                                                  int runType,
00725                                                  double sigma,
00726                                                  SKZPWeightCalculator* skzpcalc)
00727 {
00728   assert(header && truth);
00729 
00730   SKZPWeightCalculator::RunPeriod_t rp = SKZPWeightCalculator::kRunI;
00731   if(runType == NC::RunUtil::kRunII) rp = SKZPWeightCalculator::kRunII;
00732 
00733   return skzpcalc->GetFluxError(header->detector,
00734                                 beamType,
00735                                 truth->nuFlavor,
00736                                 truth->nuEnergy,
00737                                 SKZPWeightCalculator::kTotalErrorAfterTune,
00738                                 sigma);
00739 }
00740 
00741 
00742 //---------------------------------------------------------------------------
00743 double NCEventInfo::FindRecoWeight(const bool* useParameters,
00744                                    const vector<double>& adjustedValues,
00745                                    double& energy, double& trackEnergy,
00746                                    double& showerEnergy) const
00747 {
00748   assert(analysis);
00749 
00750   //  assert(useParameters.size() == adjustedValues.size());
00751 
00752 
00753   if(TMath::Abs(trackEnergy) > NCType::kMuMassGeV){
00754     double trackMomentum = TMath::Sqrt(SQR(trackEnergy) - SQR(NCType::kMuMassGeV));
00755 
00756     if(useParameters[NCType::kTrackEnergy])
00757       trackMomentum *= 1. + adjustedValues[NCType::kTrackEnergy];
00758 
00759     trackEnergy = TMath::Sqrt(SQR(trackMomentum) + SQR(NCType::kMuMassGeV));
00760   }
00761 
00762   // Only try to shift the shower if there is one
00763   if(!ANtpDefaultValue::IsDefault(showerEnergy)){
00764     //old way of doing it by scaling shower energy
00765     if(useParameters[NCType::kShowerEnergy] &&
00766        !useParameters[NCType::kAbsoluteHadronicCalibration]) {
00767       showerEnergy  *= 1. + adjustedValues[NCType::kShowerEnergy];
00768     }
00769     if(useParameters[NCType::kAbsoluteHadronicCalibration])
00770       showerEnergy  *= 1. + adjustedValues[NCType::kAbsoluteHadronicCalibration];
00771 
00772     if(useParameters[NCType::kRelativeHadronicCalibration] &&
00773        header->detector == Detector::kFar)
00774       showerEnergy  *= 1. + adjustedValues[NCType::kRelativeHadronicCalibration];
00775 
00776     assert(showerEnergy >= 0);
00777   }
00778 
00779   //new way using mike's histograms
00780 
00781   int offset = kQE;
00782   int from = kQE;
00783   int to = kQE;
00784   SelectINukeHist(offset, from, to);
00785 
00786 //   if(useParameters[1] && adjustedValues[1] < 0.)
00787 //     showerEnergy = ReweightInuke(fINukeFrom[from], fINukeToMinus[to]);
00788 //   else if(useParameters[1] && adjustedValues[1] > 0.)
00789 //     showerEnergy = ReweightInuke(fINukeFrom[from], fINukeToPlus[to]);
00790 
00791   //Shower offset must be greater than 0 to use.
00792   if(useParameters[NCType::kShowerEnergyOffset]
00793      && TMath::Abs(adjustedValues[NCType::kShowerEnergyOffset])>0.0)
00794     showerEnergy  = SimulateShowerOffset(sfINukeHists.offset[offset],
00795                                          adjustedValues[NCType::kShowerEnergyOffset]);
00796 
00797   if(analysis->isNC>0) energy = showerEnergy;
00798   if(analysis->isCC>0) energy = trackEnergy + showerEnergy;
00799 
00800   double weight = 1;
00801 
00802   //adjust the weight for the event based on the parameters to fit
00803   if(useParameters[NCType::kNormalization]
00804      && header->dataType==SimFlag::kMC
00805      && header->detector==Detector::kFar)
00806     weight *= 1.+adjustedValues[NCType::kNormalization];
00807 
00808   if(useParameters[NCType::kNCBackground]
00809      && truth->interactionType < 1
00810      && analysis->isCC > 0)
00811     weight *= 1.+adjustedValues[NCType::kNCBackground];
00812 
00813   //CC background is real CC's, not less than 50% complete CC's.
00814   //9/4/07: BJR - >50% complete is still chosen as CC after the data cleaning
00815   if(useParameters[NCType::kCCBackground]
00816      && truth->interactionType > 0
00817      && TMath::Abs(truth->nuFlavor) == 14
00818      && analysis->isNC > 0
00819      //     && truth->eventCompleteness > 0.5
00820      ) {
00821     weight *= 1.+adjustedValues[NCType::kCCBackground];
00822   }
00823   if(useParameters[NCType::kPIDCut]
00824      && analysis->separationParameterPAN < adjustedValues[NCType::kPIDCut])
00825     weight = 0.;
00826 
00827   if(useParameters[NCType::kLowCompleteness]
00828      && analysis->isNC > 0
00829      && truth->eventCompleteness < 0.5) {
00830     weight *= 1.+adjustedValues[NCType::kLowCompleteness];
00831     //cout << "LC w = " << weight << endl;
00832   }
00833 
00834   //NCFarCleanNoise +-7.8% if Ereco<0.5 GeV +-1.5% if 0.5<EReco<0.75GeV
00835   if(useParameters[NCType::kNCFarCleanNoise]
00836      && header->detector==Detector::kFar
00837      && analysis->isNC > 0){
00838     if(showerEnergy <= 0.5)
00839       weight  *= 1. + 0.078*adjustedValues[NCType::kNCFarCleanNoise];
00840     else if (showerEnergy > 0.5 && showerEnergy <=0.75)
00841       weight  *= 1. + 0.015*adjustedValues[NCType::kNCFarCleanNoise];
00842     else weight *= 1.;
00843   }
00844 
00845   //NCFarCleanCR +-0.0161*e^(-Ereco/6.96)
00846   if(useParameters[NCType::kNCFarCleanCR]
00847      && header->detector==Detector::kFar
00848      && analysis->isNC > 0){
00849     weight  *= 1. + (0.0161*TMath::Exp(-showerEnergy)/6.96)*adjustedValues[NCType::kNCFarCleanCR];
00850   }
00851 
00852 
00853   //Tobi's NCNearClean +-15.2% if     Ereco<0.5 GeV
00854   //                   +- 2.9% if 0.5<EReco<1.0 GeV
00855   //                   +- 0.4% if 1.0<EReco<1.5 GeV
00856   if(useParameters[NCType::kNCNearClean]
00857      && header->detector==Detector::kNear
00858      && analysis->isNC > 0){
00859     if(showerEnergy <= 0.5)
00860       weight  *= 1. + 0.152*adjustedValues[NCType::kNCNearClean];
00861     else if (showerEnergy > 0.5 && showerEnergy <=1.0)
00862       weight  *= 1. + 0.029*adjustedValues[NCType::kNCNearClean];
00863     else if (showerEnergy > 1.0 && showerEnergy <=1.5)
00864       weight  *= 1. + 0.004*adjustedValues[NCType::kNCNearClean];
00865     else weight *= 1.;
00866   }
00867 
00868 
00869   //NCCleanRunDiff survey  +-4% if     Ereco<1 GeV in ND
00870   if(useParameters[NCType::kNCCleanRunDiff]
00871      && header->detector==Detector::kNear
00872      && analysis->isNC > 0){
00873     if(showerEnergy <= 1.0)
00874       weight  *= 1. + 0.04*adjustedValues[NCType::kNCCleanRunDiff];
00875     else weight *= 1.;
00876   }
00877 
00878 
00879   //NCRunDiff survey  +-4% if     Ereco<=1 GeV
00880   //                  +-2% if  1 < Ereco < 5 GeV
00881   if(useParameters[NCType::kNCRunDiff]
00882        && analysis->isNC > 0){
00883     if(showerEnergy <= 1.0)
00884       weight  *= 1. + 0.04*adjustedValues[NCType::kNCRunDiff];
00885     else if(showerEnergy > 1.0 && showerEnergy < 5.0)
00886       weight  *= 1. + 0.02*adjustedValues[NCType::kNCRunDiff];
00887     else weight *= 1.;
00888   }
00889 
00890   // Messages are slow
00891   /*
00892   for(int i = NCType::kTrackEnergy; i < NCType::kNCFarCleanCR; ++i){
00893     MAXMSG("NCAnalysisUtils", Msg::kDebug, 1) << adjustedValues[i] << " ";
00894   }
00895   MAXMSG("NCAnalysisUtils", Msg::kDebug, 1) << endl;
00896 
00897   MAXMSG("NCAnalysisUtils", Msg::kDebug, 30)
00898     << trackEnergy << "/" << reco->muEnergy << " "
00899     << showerEnergy << "/" << reco->showerEnergy
00900     << " " << energy << "/" << reco->nuEnergy
00901     << " " << weight << endl;
00902   */
00903 
00904   return weight;
00905 }
00906 
00907 
00908 //---------------------------------------------------------------------
00909 void NCEventInfo::SelectINukeHist(int& offset, int& from, int& to) const
00910 {
00911   assert(truth);
00912 
00913   const double trueY = truth->nuEnergy*truth->hadronicY;
00914 
00915   // pick the histograms to use, based on process but with
00916   // cut on energy. (reason for cut = sparse statistics)
00917   if(truth->resonanceCode == 1001){
00918     if(truth->trueVisibleE < 1.0) offset = kQE;
00919     else if(truth->trueVisibleE < 2.0) offset = kRES;
00920     else offset = kDIS;
00921 
00922     if(trueY < 1.0){
00923       from = kQE;
00924       to = kQE;
00925     }
00926     else if(trueY < 2.0){
00927       from = kRES;
00928       to = kRES;
00929     }
00930     else{
00931       from = kDIS;
00932       to = kDIS;
00933     }
00934   }//end if QE
00935   else if(truth->resonanceCode == 1002
00936           || truth->resonanceCode == 1004){
00937     if(truth->trueVisibleE < 2.0) offset = kRES;
00938     else offset = kDIS;
00939 
00940     if(trueY < 2.0){
00941       from = kRES;
00942       to = kRES;
00943     }
00944     else{
00945       from = kDIS;
00946       to = kDIS;
00947     }
00948   }
00949   else{
00950     from = kDIS;
00951     to = kDIS;
00952     offset = kDIS;
00953   }
00954 }
00955 
00956 
00957 //---------------------------------------------------------------------
00958 double NCEventInfo::SimulateShowerOffset(TH2F* offsetHist, double offset) const
00959 {
00960   assert(truth && reco);
00961 
00962   MAXMSG("NCAnalysisUtils", Msg::kDebug, 20)
00963     << "simulate offset "
00964     << offsetHist->GetName()
00965     << " " << offset
00966     << " " << truth->trueVisibleE
00967     << " " << reco->nuEnergy
00968     << " " << reco->muEnergy
00969     << " " << reco->showerEnergy
00970     << endl;
00971 
00972   // don't do anything to IMD
00973   if(truth->resonanceCode==1005) return reco->showerEnergy;
00974   // sufficiently far from zero
00975   if(truth->trueVisibleE > 5.){
00976 
00977     if(reco->showerEnergy+offset < 0.)
00978       return 0.;
00979 
00980     return reco->showerEnergy+offset;
00981   }
00982   // below zero = zero
00983   if(truth->trueVisibleE+offset < 0.) return 0.;
00984 
00985   // find original bin in reco and true visible energy
00986   int iox = offsetHist->GetXaxis()->FindBin(truth->trueVisibleE);
00987   int ioy = offsetHist->GetYaxis()->FindBin(reco->showerEnergy);
00988   double porig = offsetHist->GetBinContent(iox,ioy);
00989 
00990   // find shifted bin
00991   int isx = offsetHist->GetXaxis()->FindBin(truth->trueVisibleE
00992                                             + offset);
00993   int isy = 0;
00994   double pnew = 0;
00995   for(int i = 1; i <= offsetHist->GetNbinsY(); i++){
00996     pnew = offsetHist->GetBinContent(isx,i);
00997     if(pnew >= porig){
00998       isy = i;
00999       break;
01000     }
01001   }
01002 
01003   // if we have moved bins, sample from a uniform distribution
01004   // in the new bins
01005   double eup = offsetHist->GetYaxis()->GetBinUpEdge(isy);
01006   double elow = offsetHist->GetYaxis()->GetBinLowEdge(isy);
01007   double E = gRandom->Rndm()*(eup-elow) + elow;
01008 
01009   // if we haven't moved bins in reco
01010   // do not change the energy
01011   if(isy == ioy) return reco->showerEnergy;
01012 
01013   return E;
01014 }
01015 
01016 
01017 // UNUSED
01018 /*
01019 //---------------------------------------------------------------------
01020 double NCEventInfo::ReweightInuke(TH2F* intranukeFromHist,
01021                                   TH2F* intranukeToHist)
01022 {
01023   double trueShowerE = truth->nuEnergy*truth->hadronicY;
01024 
01025   // don't do anything to IMD
01026   if(truth->resonanceCode==1005) return reco->showerEnergy;
01027   // very high energy showers do not suffer much from intranuke
01028   // also, they are hard to cope with due to poor statistical precision
01029   if(trueShowerE > 15.0) return reco->showerEnergy;
01030 
01031   // find original bin in reco and true visible energy
01032   int iox = intranukeFromHist->GetXaxis()->FindBin(trueShowerE);
01033   int ioy = intranukeFromHist->GetYaxis()->FindBin(reco->showerEnergy);
01034   double porig = intranukeFromHist->GetBinContent(iox, ioy);
01035 
01036   // find new bin in reco energy
01037   int isx = intranukeToHist->GetXaxis()->FindBin(trueShowerE);
01038   int isy = 0;
01039   double pnew = 0;
01040   for(int i = 1; i <= intranukeToHist->GetNbinsY(); i++){
01041     pnew = intranukeToHist->GetBinContent(isx, i);
01042     if(pnew >= porig){
01043       isy = i;
01044       break;
01045     }
01046   }
01047 
01048   // if we have moved bins, sample from a uniform distribution
01049   // in the new bins
01050   double eup = intranukeToHist->GetYaxis()->GetBinUpEdge(isy);
01051   double elow = intranukeToHist->GetYaxis()->GetBinLowEdge(isy);
01052   double E = gRandom->Rndm()*(eup - elow) + elow;
01053 
01054   // if we haven't moved bins in reco
01055   // do not change the energy
01056   if(isy == ioy) return reco->showerEnergy;
01057 
01058   return E;
01059 }
01060 */
01061 
01062 
01063 //----------------------------------------------------------------------
01064 double NCEventInfo::FindTransitionProbability(const NC::OscProb::OscPars* pars,
01065                                               bool useNuE) const
01066 {
01067   assert(header && truth);
01068 
01069   if(header->detector != int(Detector::kFar)) return 1;
01070 
01071   const int from = TMath::Abs(truth->nonOscNuFlavor);
01072   const int to = TMath::Abs(truth->nuFlavor);
01073 
01074   if(from == 14 && to == 12 && !useNuE) return 0;
01075 
01076   return pars->TransitionProbability(from, to,
01077                                      NCType::EEventType(truth->interactionType),
01078                                      NCType::kBaseLineFar,
01079                                      truth->nuEnergy);
01080 }
01081 
01082 
01083 //---------------------------------------------------------------------
01084 void NCEventInfo::SetEventWeight(const bool* useParameters,
01085                                  const vector<double>& adjustedValues,
01086                                  const NC::OscProb::OscPars* pars,
01087                                  SKZPWeightCalculator* skzpcalc,
01088                                  NC::RunUtil::ERunType runType,
01089                                  bool useNue,
01090                                  bool useOscProb)
01091 {
01092   double neugenWeight = 1.;
01093   double xfptWeight   = reco->weight;
01094   if(runType == NC::RunUtil::kRunII) xfptWeight = reco->weightRunII;
01095 
01096   //set the defaults for the systematic parameters from the config
01097   //set the adjustment to be an actual value, the macro should have
01098   //passed in a number of sigma
01099   bool use = false;
01100   for(int i = 0; i < NCType::kNumNeugenParameters; ++i){
01101     if(useParameters[i]){use = true; break;}
01102   }
01103 
01104   if(use){
01105     //Only apply MODBYRS for Carrot or earlier.
01106     /* StringToType is very heavy on the string comparisons...
01107        const char* mcString = (header->softVersion).Data();
01108        ReleaseType::Release_t mcType = ReleaseType::StringToType(mcString);
01109        bool useMOD = ReleaseType::IsCarrot(mcType);
01110     */
01111     const bool useMOD = string(header->softVersion).find("Carrot") != string::npos;
01112     neugenWeight = FindNeugenWeight(useParameters, adjustedValues, useMOD);
01113   }
01114 
01115   // Check all the remaining parameters
01116   for(int i = NCType::kNumNeugenParameters; i < NCType::kNumSystematicParameters; ++i){
01117     if( useParameters[i] ){use = true; break;}
01118   }//end loop over parameters
01119 
01120   double energy = reco->nuEnergy;
01121   double trackEnergy = reco->muEnergy;
01122   double showerEnergy = reco->showerEnergy;
01123   double showerEnergyNC = reco->showerEnergyNC;
01124   double showerEnergyCC = reco->showerEnergyCC;
01125 
01126   double recoWeight = 1;
01127   double crossSectionWeight = 1;
01128   if(use){
01129     crossSectionWeight = FindCrossSectionWeight(useParameters, adjustedValues);
01130 
01131     // Only need to shift track energy and total energy once. Other times
01132     // throw the result away in this variable.
01133     double junk = 0;
01134 
01135     recoWeight = FindRecoWeight(useParameters, adjustedValues, energy,
01136                                 trackEnergy, showerEnergy);
01137     // Do this again to adjust the NC shower energy too
01138     FindRecoWeight(useParameters, adjustedValues, junk,
01139                    junk, showerEnergyNC);
01140     // ...and the CC shower energy
01141     FindRecoWeight(useParameters, adjustedValues, junk,
01142                    junk, showerEnergyCC);
01143   }
01144 
01145   reco->nuEnergy = energy;
01146   reco->muEnergy = trackEnergy;
01147   reco->showerEnergy = showerEnergy;
01148   reco->showerEnergyNC = showerEnergyNC;
01149   reco->showerEnergyCC = showerEnergyCC;
01150   reco->nuEnergyCC = trackEnergy + showerEnergyCC;
01151   reco->nuEnergyNC = showerEnergyNC ? showerEnergyNC : ANtpDefaultValue::kDouble;
01152 
01153 
01154   if(useParameters[NCType::kSKZP])
01155     xfptWeight *= FindMEGAFitWeightUncertainty(beam->beamType,
01156                                                runType,
01157                                                adjustedValues[NCType::kSKZP],
01158                                                skzpcalc);
01159 
01160   const double survivalProb = useOscProb ?
01161     FindTransitionProbability(pars, useNue) : 1;
01162 
01163   reco->weight = neugenWeight*recoWeight*crossSectionWeight*xfptWeight*survivalProb;
01164 }
01165 
01166 
01167 //-----------------------------------------------------------------------
01168 //this is a catch all for final cuts on whether an event should be used.
01169 bool NCEventInfo::FinalEventCheck() const
01170 {
01171   assert(analysis && header && reco);
01172 
01173   if(analysis->isCC > 0 &&
01174      analysis->isNC < 1 &&
01175      reco->trackMomentum > 0)
01176     return false;
01177 
01178   if(header->detector == Detector::kNear &&
01179      !NC::RunUtil::IsNDRunGood(header->run, header->subRun))
01180     return false;
01181 
01182   return true;
01183 }
01184 
01185 
01186 //-----------------------------------------------------------------------
01187 void NCEventInfo::SetChainBranches(TChain* ch,
01188                                    TString extractionName,
01189                                    bool setTruthBranch)
01190 {
01191   const TString extractionBranch = "analysis"+extractionName;
01192 
01193   ch->SetBranchStatus("*", 0);
01194   ch->SetBranchStatus("header.*", 1);
01195   ch->SetBranchStatus("beam.*", 1);
01196   ch->SetBranchStatus("reco.*", 1);
01197   ch->SetBranchStatus(extractionBranch+"*", 1);
01198 
01199   ch->SetBranchAddress("header.", &header);
01200   ch->SetBranchAddress("beam.", &beam);
01201   ch->SetBranchAddress("reco.", &reco);
01202   ch->SetBranchAddress(extractionBranch, &analysis);
01203 
01204   if(setTruthBranch){
01205     ch->SetBranchStatus("truth.*", 1);
01206     ch->SetBranchAddress("truth.", &truth);
01207   }
01208 }
01209 
01210 
01211 //-----------------------------------------------------------------------
01212 VldTimeStamp NCEventInfo::GetTimestamp() const
01213 {
01214   return VldTimeStamp(header->year, header->month, header->day,
01215                       header->hour, header->minute,
01216                       TMath::FloorNint(header->second));
01217 }

Generated on Sat Mar 14 22:40:49 2009 for loon by doxygen 1.3.5