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

NuSystematic.cxx

Go to the documentation of this file.
00001 
00002 // $Id: NuSystematic.cxx,v 1.46 2010/01/30 18:59:33 bckhouse Exp $
00003 //
00004 // A class to control the systematics studies. Applies systematic
00005 // shifts to NuEvents.
00006 //
00007 // Justin Evans
00008 // j.evans2@physics.ox.ac.uk
00009 //
00010 // $Log: NuSystematic.cxx,v $
00011 // Revision 1.46  2010/01/30 18:59:33  bckhouse
00012 // Only apply ND cleaning systematic to NC selected events at the near detector.
00013 //
00014 // Change the one sigma value for CC background to 15% as used in the NC analysis.
00015 //
00016 // Revision 1.45  2010/01/30 00:33:36  ahimmel
00017 //
00018 // A significant upgrade to NuSystematic.  It can now handle multiple simultaneous shifts.  In order to handle this cleanly, significant changes were made to the internal structure of the class (e.g. how systematics and their 1 sigma values are stored).  However, it's previous functionality (apply a systematic shift based on a NuXMLConfig object) is unchanged and any previous code that uses this method should work as it did before.
00019 //
00020 // As with any major upgrade, some bugs might have crept in.  I've done some testing myself, but please let me know if you see some strange behavior.
00021 //
00022 // Here are the major new features:
00023 //
00024 // It is now possible to set multiple simultaneously active systematics using these methods:
00025 //
00026 // SetShiftsAsValues()
00027 // SetShiftsAsSigmas()
00028 //
00029 // Both take an STL map with either TStrings or NuSyst::NuSystematic_t as the keys and doubles as the values.  The difference is in how the values are interpreted: SetShiftsAsValues assumes the numbers given are shifts as they might be specified in a NuXMLConfig, SetShiftsAsSigmas assumes the numbers are given in terms of sigmas.
00030 //
00031 // NuSystematic can also produce randomized systematic values using:
00032 //
00033 // Randomize()
00034 //
00035 // This takes any systematics that are "on" -- i.e. their current shift is not 0 and draws a random Gaussian for that systematic.
00036 //
00037 // There is also now a function:
00038 //
00039 // SetSigmas()
00040 //
00041 // That takes an STL map like the SetShifts functions, but now it interprets the value as the new shift that will correspond to 1 sigma.
00042 //
00043 // Revision 1.43  2009/09/04 15:00:06  evansj
00044 // Fixing a bug in the resolution systematic.
00045 //
00046 // Revision 1.42  2009/08/28 20:48:15  gmieg
00047 // Add '#include <cassert>'
00048 //
00049 // Revision 1.41  2009/08/27 14:20:40  evansj
00050 // Added energy resolution systematics. Can shift the event energy,
00051 // shower energy, amd track range and curvature energies independently,
00052 // either in both detectors or just the near.
00053 //
00054 // Revision 1.40  2009/07/06 21:20:29  ahimmel
00055 //
00056 //
00057 // Updating the DP systematic code.  FC fitting now does not consider muons part of the decay pipe.  This required adding a variable to NuFCEvent so the event library files will need to be reproduced.  Also, adjusted NuSystematic so that it used the correct codes for muons (+/-13 instead of 5/6) -- SNTPs use a different set of particle codes than the flux files.
00058 //
00059 // Revision 1.39  2009/07/02 14:28:33  evansj
00060 // Don't shift muon progeny in the decay pipe systematic.
00061 //
00062 // Revision 1.38  2009/06/24 10:36:06  evansj
00063 // The decay pipe systematic now only shifts events produced in the decay
00064 // pipe (it was previously shifting those produced in the chase as well).
00065 //
00066 // Revision 1.37  2008/10/24 19:18:30  ahimmel
00067 //
00068 //
00069 // NuFCEvent:
00070 // Added detector to the event.  It is ok if the trees are generated with a previous version, NuFCExperimentFactory adds in the detector information when loading the events.
00071 //
00072 // NuFCExperimentFactory:
00073 // Can now handle near and far detector systematics.
00074 //
00075 // NuMMHelperCPT:
00076 // Updated the cross-section systematic formula.  It is not used right now, but best it be correct if we decide to later.
00077 //
00078 // NuMMRunFC, NuMMRunTransition, NuMMRunNuBar:
00079 // Added a reduced constructor that does not take the far detector spectra.  This is for use in generating fake experiments with NuFCExperimentFactory.
00080 //
00081 // NuSystematic:
00082 // Added a NuMuBarXSecSum that applies all appropriate systematic shifts for NuBars (both combined and ratio) using the parameterized formula that gives the sum in quadrature of all the systematic effects.
00083 //
00084 // Revision 1.36  2008/09/22 00:01:52  evansj
00085 // A systematic that shifts all backgrounds in the nubar sample (CC & NC)
00086 // by a scale factor (recommended value: 50%).
00087 //
00088 // Revision 1.35  2008/09/08 22:33:36  gmieg
00089 // Change fabs(event.inu) to TMath::Abs(event.inu) to settle ambiguity.
00090 //
00091 // Revision 1.34  2008/08/27 12:01:42  evansj
00092 // An uncertainty on the tau QEL & Res cross sections (simultaneaously,
00093 // as a scale factor), the size configured from the xml files
00094 // (recommended 15%).
00095 //
00096 // Revision 1.33  2008/08/19 09:44:39  evansj
00097 // Bug fix for the target hole systematic (the hole was always being
00098 // given a non-zero width).
00099 //
00100 // Revision 1.32  2008/08/18 15:11:47  evansj
00101 // Adding a 'target hole' systematic which chops out any events in a
00102 // segment of the target of length defined (in cm) in the xml files. The
00103 // hole starts at z=20 cm, and is defined in terms of ppvz (which isn't
00104 // quite correct, but my DSTs don't have tvz in them at the moment). The
00105 // hole start of 20 cm is also a guess.
00106 //
00107 // Revision 1.31  2008/08/18 10:24:05  evansj
00108 // Updating the cross section systematics so they shift all three types
00109 // of neutrino (and antineutrino) together: not just the numus.
00110 //
00111 // Revision 1.30  2008/08/11 19:04:09  ahimmel
00112 //
00113 //
00114 // Set up so now there is a static method in NuSystemtic called FluxSyst that returns true for flux-related systematic errors and false for detector-related ones.  This is important for the transitions analysis where the transitioned events have the detector-related systematics applied but not the flux errors.
00115 //
00116 // Revision 1.29  2008/06/02 11:30:38  evans
00117 // An overall track energy scale and a near detector track energy from
00118 // curvature scale.
00119 //
00120 // Revision 1.28  2008/04/14 15:39:54  evans
00121 // More unitialised variable fixes for the optimised compiler.
00122 //
00123 // Revision 1.27  2008/03/20 16:52:53  evans
00124 // A few new systematics. Independent ma_res and ma_qe numu scales. A
00125 // combined track range and curvature systematic (assume both are
00126 // correlated, with 2% and 3% shifts respectively; and both are
00127 // furthermore correlated between both detectors). Also an
00128 // energy-dependent form of the shower energy scale systematic.
00129 //
00130 // Revision 1.26  2008/02/19 11:49:57  evans
00131 // Updating the decay pipe parent systematic so it works with the pHE beam.
00132 //
00133 // Revision 1.25  2008/02/17 06:17:00  rhatcher
00134 // Add back some neugen headers that aren't automatically included via
00135 // other headers, was via MCReweight or NeugenWeightCalculator.
00136 //
00137 // Revision 1.24  2008/02/08 16:19:52  evans
00138 // Fixing the BField systematic so it shifts every CC numu event with q/p>0.
00139 //
00140 // Revision 1.23  2008/01/20 01:11:15  evans
00141 // Fixing a bug in the application of the overall antineutrino cross
00142 // section systematic.
00143 //
00144 // Revision 1.22  2008/01/17 01:22:07  evans
00145 // A first attempt at code to systematically shift cross sections.
00146 //
00147 // Revision 1.21  2008/01/14 11:39:16  evans
00148 // Putting in the value I'm going to use for the track fit probability
00149 // systematic.
00150 //
00151 // Revision 1.20  2008/01/14 06:38:30  evans
00152 // A couple of systematics more specific to my selection. One shifts
00153 // track jitter and DPID. The other shifts track fit probability.
00154 //
00155 // Revision 1.19  2008/01/10 18:19:49  evans
00156 // Adding bounds on the Neugen r parameters (resonance/DIS transition
00157 // region) so they can't be shifted below 0 or above 1.
00158 //
00159 // Revision 1.18  2008/01/10 17:32:44  evans
00160 // A number of bug fixes to get the Neugen cross section reweighting
00161 // finally working correctly for every systematic. The shift for the
00162 // numubar resonance-DIS transition region gives a dubiously physical
00163 // reweighting (the -1sigma shift weights some events by -1; the +1sigma
00164 // shift weights them by +3), but it seems to be what's implied by
00165 // DocDB-2989.
00166 //
00167 // Revision 1.17  2008/01/10 01:51:34  evans
00168 // Fixed the Neugen cross section shifting code so it actually returns
00169 // non-unity weights and shifts the Monte Carlo.
00170 //
00171 // Revision 1.16  2008/01/06 16:01:22  evans
00172 // Adding a far-detector-only track energy from curvature shift (4% at
00173 // present; should possibly be 4%+4% in quadrature to be a near-far
00174 // relative shift).
00175 //
00176 // Revision 1.15  2008/01/05 06:23:50  rhatcher
00177 // With new versions of ROOT and gcc (v3.4.3+) we need a #include <cmath>
00178 // in order to have access to sqrt(); perhaps this worked for older versions
00179 // where includes might have been pulled in implicitly.
00180 //
00181 // Revision 1.14  2008/01/04 18:22:48  ahimmel
00182 //
00183 //
00184 // Added in kScraping systematic.  Right now 1 sigma is 25%, but that is just a guess.
00185 //
00186 // I've also added a ShiftAsValue() function analagous to ShiftAsSigma() to reduce a lot of clutter from conversion.  Now the usage of the shift is more obviously indpendent of how it is stored.
00187 //
00188 // Revision 1.13  2008/01/03 16:15:49  evans
00189 // Adding two new systematics: a scale factor in the numubar QEL cross
00190 // sections, and a scale factor in the numubar resonance cross sections
00191 // (both 8%). These replace the numubar CCMA systematic which shouldn't
00192 // be used.
00193 //
00194 // Revision 1.12  2008/01/01 16:46:43  evans
00195 // Adding the ability to shift the NC background by a scale
00196 // factor. Current default is 50%.
00197 //
00198 // Revision 1.11  2007/12/31 18:43:16  evans
00199 // Correcting the separate near and far normalisation code so it applies
00200 // the shift to the correct detector.
00201 //
00202 // Revision 1.10  2007/12/31 12:55:42  evans
00203 // Fixing a bug in the shower energy scale systematics. Adding in
00204 // separate near and far normalisation and B-field systematics.
00205 //
00206 // Revision 1.9  2007/12/30 22:43:09  evans
00207 // Adding a toy B-field systematic (double/half the CC background in the
00208 // nubar selection).
00209 //
00210 // Revision 1.8  2007/12/27 22:11:50  evans
00211 // Debugging and adding a bit of printout.
00212 //
00213 // Revision 1.7  2007/12/23 21:55:41  evans
00214 // Adding in the correct track energy systematics. TrackEnergyScale and
00215 // TrackEnergyOffset no longer exist. Instead, TrackEnergyRange and
00216 // TrackEnergyCurvature are the two systematics to apply (1 sigma = 2%
00217 // and 4% respectively).
00218 //
00219 // Revision 1.6  2007/12/13 22:00:21  evans
00220 // Putting all the cross section systematics in, as detailed in
00221 // DocDB-2989-v6. There are four combined numu+numubar CC cross section
00222 // systematics and three numubar-only CC systematics: so seven systematic
00223 // shifts in all. There are no NC cross section shifts in the class.
00224 //
00225 // Revision 1.5  2007/12/13 14:04:22  evans
00226 // Adding the ability to make a systematic shift of the CCMA
00227 // paramter. All Neugen parameters will follow the same basic method.
00228 //
00229 // Revision 1.4  2007/12/12 16:33:18  evans
00230 // Adding a normalisation systematic of 4% and setting the track energy
00231 // scale systematic to 2%.
00232 //
00233 // Revision 1.3  2007/12/07 15:25:19  evans
00234 // Adding SKZP flux errors. This code takes NuEvent::fluxErr as the
00235 // error, and alters NuEvent::rw with the equation
00236 //
00237 // NuEvent::fluxrw *= 1.0 + sigma*(NuEvent::fluxErr - 1.0).
00238 //
00239 // Revision 1.2  2007/12/06 14:15:36  evans
00240 // Putting in the correct shower energy scale uncertainties.
00241 //
00242 // kShowerEnergyScale is the absolute (near+far simultaneously) scale
00243 // uncertainty. 5.7% from calibration (DocDB-3137), added in quadrature
00244 // with 8% to account for shower modelling uncertainties
00245 // (DocDB-3362). This gives a total 1sigma uncertainty of 10%.
00246 //
00247 // There's also the possibility of doing relative detector
00248 // shifts. kShowerEnergyScaleNear shifts near detector energies by
00249 // 3.1%. kShowerEnergyScaleFar shifts far detector energies by 2.3%. The
00250 // way this systematic is traditionally evaluated is by adding these two
00251 // numbers in quadrature (3.9%) and shifting just one detector (in this
00252 // framework the near detector): kShowerEnergyScaleRelative performs
00253 // this. So either do both the first two of these shifts, or just the
00254 // last one. (All these numbers are calibration-only figures, again from
00255 // DocDB-3137.)
00256 //
00257 // All figures were calculated for the CC box opening in July so may need
00258 // to be updated for the new dataset and for Daikon_04.
00259 //
00260 // Revision 1.1  2007/11/30 17:28:18  evans
00261 // Adding a new class, NuSystematic, which takes a NuEvent and applies
00262 // the relevant sytematic shift to it. At present it only deals with
00263 // shower energy shifts and shower energy offsets (with 1sigma sizes
00264 // picked out of thin air). Takes a NuXMLConfig object in the constructor
00265 // to tell it which systematic and what size/direction of shift to use.
00266 //
00267 //
00269 
00270 #include <map>
00271 #include <cassert>
00272 #include <cmath>
00273 #include "TMath.h"
00274 #include "TString.h"
00275 #include "TRandom3.h"
00276 
00277 #include "Conventions/BeamType.h"
00278 #include "Conventions/Detector.h"
00279 #include "Conventions/Munits.h"
00280 #include "Conventions/ReleaseType.h"
00281 #include "MessageService/MsgService.h"
00282 
00283 #include "MCReweight/MCReweight.h"
00284 #include "MCReweight/NeugenWeightCalculator.h"
00285 
00286 #include "NeugenInterface/ccnc.h"
00287 #include "NeugenInterface/flavor.h"
00288 #include "NeugenInterface/init_state.h"
00289 #include "NeugenInterface/interaction.h"
00290 #include "NeugenInterface/nucleus.h"
00291 #include "NeugenInterface/process.h"
00292 #include "NeugenInterface/neugen_cuts.h"
00293 #include "NeugenInterface/neugen_config.h"
00294 #include "NeugenInterface/neugen_wrapper.h"
00295 #include "Registry/Registry.h"
00296 
00297 #include "NtupleUtils/NuCut.h"
00298 #include "NtupleUtils/NuEvent.h"
00299 //#include "NtupleUtils/NuFluctuator.h"
00300 #include "NtupleUtils/NuSystematic.h"
00301 #include "NtupleUtils/NuXMLConfig.h"
00302 
00303 
00304 ClassImp(NuSystematic)
00305 
00306 CVSID("$Id: NuSystematic.cxx,v 1.46 2010/01/30 18:59:33 bckhouse Exp $");
00307 
00308 
00310 // Static Variables //
00312 
00313 Bool_t NuSystematic::firstMCReweight = true;
00314 Int_t NuSystematic::kMinusPlus = 1;
00315 Int_t NuSystematic::kAsIs = 2;
00316 Int_t NuSystematic::kSigma = 3;
00317 
00318 
00319 
00321 // Constructors & Destructors //
00323 
00324 //____________________________________________________________________72
00325 NuSystematic::NuSystematic()
00326 {
00327   MSG("NuSystematic.cxx",Msg::kInfo)
00328     << "Constructing default NuSystematic object" << endl;
00329 
00330   this->ConfigureDefaultSystematics();
00331   this->ConfigureNeugenDefaults();
00332   this->InitializeSystematics();
00333   this->EverythingOff();
00334   
00335   fCCSelector = 0;
00336   fNCSelector = 0;
00337   fNuBarSelector = 0;
00338   fRockSelector = 0;
00339   
00340   fRandom = new TRandom3(0);
00341   //fFluctuator = new NuFluctuator();
00342 }
00343 
00344 //____________________________________________________________________72
00345 NuSystematic::NuSystematic(const NuXMLConfig& xmlConfig)
00346 {
00347   this->ConfigureDefaultSystematics();
00348   this->ConfigureNeugenDefaults();
00349   this->InitializeSystematics();
00350   this->EverythingOff();
00351   
00352   fCCSelector = 0;
00353   fNCSelector = 0;
00354   fNuBarSelector = 0;
00355   fRockSelector = 0;
00356   
00357   fRandom = new TRandom3(0);
00358   //fFluctuator = new NuFluctuator();
00359 
00360   this->ReadXML(xmlConfig);
00361 }
00362 
00363 //____________________________________________________________________72
00364 NuSystematic::~NuSystematic()
00365 {
00366   //if (fFluctuator)    {delete fFluctuator;    fFluctuator = 0;}
00367   if (fRandom)        {delete fRandom;        fRandom = 0;}
00368   if (fCCSelector)    {delete fCCSelector;    fCCSelector = 0;}
00369   if (fNCSelector)    {delete fNCSelector;    fNCSelector = 0;}
00370   if (fNuBarSelector) {delete fNuBarSelector; fNuBarSelector = 0;}
00371   if (fRockSelector)  {delete fRockSelector;  fRockSelector = 0;}
00372 }
00373 
00374 
00375 
00377 // Configuration & Initialization //
00379 
00380 //____________________________________________________________________72
00381 void NuSystematic::ConfigureDefaultSystematics()
00382 {
00383   oneSigma[NuSyst::kShowerEnergyOffset] = 100*Munits::MeV;
00384   oneSigma[NuSyst::kShowerEnergyScale] = 1.10;
00385   oneSigma[NuSyst::kShowerEnergyFunction] = 1.0;
00386   oneSigma[NuSyst::kShowerEnergyScaleFar] = 1.023;
00387   oneSigma[NuSyst::kShowerEnergyScaleNear] = 1.031;
00388   oneSigma[NuSyst::kShowerEnergyScaleRelative] = 1.039;
00389   
00390   oneSigma[NuSyst::kTrackEnergyCurvatureBoth] = 1.03;
00391   oneSigma[NuSyst::kTrackEnergyCurvatureFar] = 1.03;
00392   oneSigma[NuSyst::kTrackEnergyCurvatureNear] = 1.03;
00393   oneSigma[NuSyst::kTrackEnergyRange] = 1.02;
00394   oneSigma[NuSyst::kTrackEnergyScale] = 1.02;
00395   oneSigma[NuSyst::kTrackEnergyOverall] = -999;
00396   
00397   oneSigma[NuSyst::kBFieldBoth] = 2.0;
00398   oneSigma[NuSyst::kBFieldNear] = 2.0;
00399   oneSigma[NuSyst::kBFieldFar] = 2.0;  
00400   oneSigma[NuSyst::kAlignment] = -999;  
00401   oneSigma[NuSyst::kBeam] = 1.0;
00402   
00403   oneSigma[NuSyst::kCombinedXSecOverall] = 1.035;
00404   oneSigma[NuSyst::kCombinedXSecCCMA] = 1.15;
00405   oneSigma[NuSyst::kCombinedXSecMaRes] = 1.15;
00406   oneSigma[NuSyst::kCombinedXSecMaQE] = 1.15;
00407   oneSigma[NuSyst::kCombinedXSecDISMultip2] = 0.1;
00408   oneSigma[NuSyst::kCombinedXSecDISMultip3] = 0.2;
00409   
00410   oneSigma[NuSyst::kNuMuBarXSecSum] = 1.0;
00411   oneSigma[NuSyst::kNuMuBarXSecOverall] = 1.04;
00412   oneSigma[NuSyst::kNuMuBarXSecCCMA] = 1.08;
00413   oneSigma[NuSyst::kNuMuBarXSecDISMultip2] = 0.2;  
00414   oneSigma[NuSyst::kNuMuBarXSecQEL] = 1.08;
00415   oneSigma[NuSyst::kNuMuBarXSecRes] = 1.08;
00416   
00417   oneSigma[NuSyst::kNormalisationBoth] = 1.04;
00418   oneSigma[NuSyst::kNormalisationNear] = 1.04;
00419   oneSigma[NuSyst::kNormalisationFar] = 1.04;
00420   oneSigma[NuSyst::kNCBackground] = 1.50;
00421   oneSigma[NuSyst::kCCBackground] = 1.15;  // Value used in the NC analysis
00422   oneSigma[NuSyst::kNDCleaning] = 1.0;
00423   oneSigma[NuSyst::kAllBackgroundsScaleBoth] = 1.5;//50% scale
00424   oneSigma[NuSyst::kScraping] = 1.37;
00425   
00426   oneSigma[NuSyst::kJitterVDPID] = -999;
00427   oneSigma[NuSyst::kJitter]= 0.01;
00428   oneSigma[NuSyst::kDPID] = 0.03;  
00429   oneSigma[NuSyst::kTFProb] = 0.005;//Complete guess.
00430   oneSigma[NuSyst::kTargetHole] = 4.0;//cm: length of the hole
00431   oneSigma[NuSyst::kTauQELRes] = 1.15;//15% scale
00432   
00433   oneSigma[NuSyst::kEnergyResolutionEventBoth] = 1.1;
00434   oneSigma[NuSyst::kEnergyResolutionEventNear] = 1.1;
00435   oneSigma[NuSyst::kEnergyResolutionShowerBoth] = 1.1;
00436   oneSigma[NuSyst::kEnergyResolutionShowerNear] = 1.1;
00437   oneSigma[NuSyst::kEnergyResolutionTrackRangeBoth] = 1.1;
00438   oneSigma[NuSyst::kEnergyResolutionTrackRangeNear] = 1.1;
00439   oneSigma[NuSyst::kEnergyResolutionTrackCurveBoth] = 1.1;
00440   oneSigma[NuSyst::kEnergyResolutionTrackCurveNear] = 1.1;
00441 }
00442 
00443 
00444 //____________________________________________________________________72
00445 void NuSystematic::InitializeSystematics()
00446 {
00447   systNames[NuSyst::kNominal] = "Nominal";
00448   
00449   systNames[NuSyst::kShowerEnergyOffset] = "ShowerEnergyOffset";
00450   systNames[NuSyst::kShowerEnergyScale] = "ShowerEnergyScaleBoth"; 
00451   systNames[NuSyst::kShowerEnergyFunction] = "ShowerEnergyScaleFunctionBoth"; 
00452   systNames[NuSyst::kShowerEnergyScaleNear] = "ShowerEnergyScaleNear";
00453   systNames[NuSyst::kShowerEnergyScaleFar] = "ShowerEnergyScaleFar"; 
00454   
00455   systNames[NuSyst::kShowerEnergyScaleRelative] = "ShowerEnergyScaleRelative"; 
00456   systNames[NuSyst::kTrackEnergyCurvatureBoth] = "TrackEnergyCurvatureBoth";
00457   systNames[NuSyst::kTrackEnergyCurvatureFar] = "TrackEnergyCurvatureFar"; 
00458   systNames[NuSyst::kTrackEnergyCurvatureNear] = "TrackEnergyCurvatureNear"; 
00459   systNames[NuSyst::kTrackEnergyRange] = "TrackEnergyRange";
00460   systNames[NuSyst::kTrackEnergyOverall] = "TrackEnergyOverall"; 
00461   systNames[NuSyst::kTrackEnergyScale] = "TrackEnergyScale"; 
00462   
00463   systNames[NuSyst::kBFieldBoth] = "BFieldBoth"; 
00464   systNames[NuSyst::kBFieldNear] = "BFieldNear";
00465   systNames[NuSyst::kBFieldFar] = "BFieldFar";   
00466   systNames[NuSyst::kAlignment] = "Alignment";
00467   systNames[NuSyst::kBeam] = "Flux";
00468 
00469   systNames[NuSyst::kCombinedXSecCCMA] = "CombinedXSecCCMA"; 
00470   systNames[NuSyst::kCombinedXSecMaRes] = "CombinedXSecMaRes";
00471   systNames[NuSyst::kCombinedXSecMaQE] = "CombinedXSecMaQE"; 
00472   systNames[NuSyst::kCombinedXSecOverall] = "CombinedXSecOverall"; 
00473   systNames[NuSyst::kCombinedXSecDISMultip2] = "CombinedXSecDISMultip2";
00474   systNames[NuSyst::kCombinedXSecDISMultip3] = "CombinedXSecDISMultip3"; 
00475 
00476   systNames[NuSyst::kNuMuBarXSecCCMA] = "NuMuBarXSecCCMA"; 
00477   systNames[NuSyst::kNuMuBarXSecQEL] = "NuMuBarXSecQEL";
00478   systNames[NuSyst::kNuMuBarXSecRes] = "NuMuBarXSecRes"; 
00479   systNames[NuSyst::kNuMuBarXSecSum] = "NuMuBarXSecSum"; 
00480   systNames[NuSyst::kNuMuBarXSecOverall] = "NuMuBarXSecOverall";
00481   systNames[NuSyst::kNuMuBarXSecDISMultip2] = "NuMuBarXSecDISMultip2"; 
00482   
00483   systNames[NuSyst::kNormalisationBoth] = "NormalisationBoth"; 
00484   systNames[NuSyst::kNormalisationNear] = "NormalisationNear";
00485   systNames[NuSyst::kNormalisationFar] = "NormalisationFar"; 
00486   systNames[NuSyst::kNCBackground] = "NCBackground"; 
00487   systNames[NuSyst::kCCBackground] = "CCBackground";   
00488   systNames[NuSyst::kNDCleaning] = "NDCleaning";   
00489   systNames[NuSyst::kAllBackgroundsScaleBoth] = "AllBackgroundsScaleBoth"; 
00490   systNames[NuSyst::kScraping] = "DecayPipe"; 
00491 
00492   systNames[NuSyst::kJitterVDPID] = "JitterVDPID"; 
00493   systNames[NuSyst::kJitter] = "Jitter";
00494   systNames[NuSyst::kDPID] = "DPID"; 
00495   systNames[NuSyst::kTFProb] = "TFProb"; 
00496   systNames[NuSyst::kTargetHole] = "TargetHole";
00497   systNames[NuSyst::kTauQELRes] = "TauQELRes"; 
00498   
00499   systNames[NuSyst::kEnergyResolutionEventBoth] = "EnergyResolutionEventBoth";
00500   systNames[NuSyst::kEnergyResolutionEventNear] = "EnergyResolutionEventNear"; 
00501   systNames[NuSyst::kEnergyResolutionShowerBoth] = "EnergyResolutionShowerBoth"; 
00502   systNames[NuSyst::kEnergyResolutionShowerNear] = "EnergyResolutionShowerNear";
00503   systNames[NuSyst::kEnergyResolutionTrackRangeBoth] = "EnergyResolutionTrackRangeBoth"; 
00504   systNames[NuSyst::kEnergyResolutionTrackRangeNear] = "EnergyResolutionTrackRangeNear"; 
00505   systNames[NuSyst::kEnergyResolutionTrackCurveBoth] = "EnergyResolutionTrackCurveBoth";
00506   systNames[NuSyst::kEnergyResolutionTrackCurveNear] = "EnergyResolutionTrackCurveNear"; 
00507 
00508 
00509   systMode[NuSyst::kNominal] = kSigma;
00510   
00511   systMode[NuSyst::kShowerEnergyOffset] = kAsIs;
00512   systMode[NuSyst::kShowerEnergyScale] = kMinusPlus; 
00513   systMode[NuSyst::kShowerEnergyFunction] = kSigma; 
00514   systMode[NuSyst::kShowerEnergyScaleNear] = kMinusPlus;
00515   systMode[NuSyst::kShowerEnergyScaleFar] = kMinusPlus; 
00516   
00517   systMode[NuSyst::kShowerEnergyScaleRelative] = kMinusPlus; 
00518   systMode[NuSyst::kTrackEnergyCurvatureBoth] = kMinusPlus;
00519   systMode[NuSyst::kTrackEnergyCurvatureFar] = kMinusPlus; 
00520   systMode[NuSyst::kTrackEnergyCurvatureNear] = kMinusPlus; 
00521   systMode[NuSyst::kTrackEnergyRange] = kMinusPlus;
00522   systMode[NuSyst::kTrackEnergyOverall] = kSigma; 
00523   systMode[NuSyst::kTrackEnergyScale] = kMinusPlus; 
00524   
00525   systMode[NuSyst::kBFieldBoth] = kMinusPlus; 
00526   systMode[NuSyst::kBFieldNear] = kMinusPlus;
00527   systMode[NuSyst::kBFieldFar] = kMinusPlus;   
00528   systMode[NuSyst::kAlignment] = kMinusPlus;
00529   systMode[NuSyst::kBeam] = kSigma;
00530   
00531   systMode[NuSyst::kCombinedXSecCCMA] = kMinusPlus; 
00532   systMode[NuSyst::kCombinedXSecMaRes] = kMinusPlus;
00533   systMode[NuSyst::kCombinedXSecMaQE] = kMinusPlus; 
00534   systMode[NuSyst::kCombinedXSecOverall] = kMinusPlus; 
00535   systMode[NuSyst::kCombinedXSecDISMultip2] = kAsIs;
00536   systMode[NuSyst::kCombinedXSecDISMultip3] = kAsIs; 
00537   
00538   systMode[NuSyst::kNuMuBarXSecCCMA] = kMinusPlus; 
00539   systMode[NuSyst::kNuMuBarXSecQEL] = kMinusPlus;
00540   systMode[NuSyst::kNuMuBarXSecRes] = kMinusPlus; 
00541   systMode[NuSyst::kNuMuBarXSecSum] = kSigma; 
00542   systMode[NuSyst::kNuMuBarXSecOverall] = kMinusPlus;
00543   systMode[NuSyst::kNuMuBarXSecDISMultip2] = kAsIs; 
00544   
00545   systMode[NuSyst::kNormalisationBoth] = kMinusPlus; 
00546   systMode[NuSyst::kNormalisationNear] = kMinusPlus;
00547   systMode[NuSyst::kNormalisationFar] = kMinusPlus; 
00548   systMode[NuSyst::kNCBackground] = kMinusPlus; 
00549   systMode[NuSyst::kCCBackground] = kMinusPlus; 
00550   systMode[NuSyst::kNDCleaning] = kSigma; 
00551   systMode[NuSyst::kAllBackgroundsScaleBoth] = kMinusPlus; 
00552   systMode[NuSyst::kScraping] = kMinusPlus; 
00553   
00554   systMode[NuSyst::kJitterVDPID] = kSigma; 
00555   systMode[NuSyst::kJitter] = kAsIs;
00556   systMode[NuSyst::kDPID] = kAsIs; 
00557   systMode[NuSyst::kTFProb] = kAsIs;
00558   systMode[NuSyst::kTargetHole] = kAsIs;
00559   systMode[NuSyst::kTauQELRes] = kMinusPlus; 
00560   
00561   systMode[NuSyst::kEnergyResolutionEventBoth] = kMinusPlus;
00562   systMode[NuSyst::kEnergyResolutionEventNear] = kMinusPlus; 
00563   systMode[NuSyst::kEnergyResolutionShowerBoth] = kMinusPlus; 
00564   systMode[NuSyst::kEnergyResolutionShowerNear] = kMinusPlus;
00565   systMode[NuSyst::kEnergyResolutionTrackRangeBoth] = kMinusPlus; 
00566   systMode[NuSyst::kEnergyResolutionTrackRangeNear] = kMinusPlus; 
00567   systMode[NuSyst::kEnergyResolutionTrackCurveBoth] = kMinusPlus;
00568   systMode[NuSyst::kEnergyResolutionTrackCurveNear] = kMinusPlus; 
00569   
00570 }
00571 
00572 
00573 //____________________________________________________________________72
00574 void NuSystematic::EverythingOff()
00575 {
00576   currentSigma[NuSyst::kShowerEnergyOffset] = 0;
00577   currentSigma[NuSyst::kShowerEnergyScale] = 0;
00578   currentSigma[NuSyst::kShowerEnergyFunction] = 0;
00579   currentSigma[NuSyst::kShowerEnergyScaleFar] = 0;
00580   currentSigma[NuSyst::kShowerEnergyScaleNear] = 0;
00581   currentSigma[NuSyst::kShowerEnergyScaleRelative] = 0;
00582   currentSigma[NuSyst::kTrackEnergyCurvatureBoth] = 0;
00583   currentSigma[NuSyst::kTrackEnergyCurvatureFar] = 0;
00584   currentSigma[NuSyst::kTrackEnergyCurvatureNear] = 0;
00585   currentSigma[NuSyst::kTrackEnergyRange] = 0;
00586   currentSigma[NuSyst::kTrackEnergyScale] = 0;
00587   currentSigma[NuSyst::kTrackEnergyOverall] = 0;
00588   currentSigma[NuSyst::kBFieldBoth] = 0;
00589   currentSigma[NuSyst::kBFieldNear] = 0;
00590   currentSigma[NuSyst::kBFieldFar] = 0;  
00591   currentSigma[NuSyst::kAlignment] = 0;  
00592   currentSigma[NuSyst::kBeam] = 0;
00593   currentSigma[NuSyst::kCombinedXSecOverall] = 0;
00594   currentSigma[NuSyst::kCombinedXSecCCMA] = 0;
00595   currentSigma[NuSyst::kCombinedXSecMaRes] = 0;
00596   currentSigma[NuSyst::kCombinedXSecMaQE] = 0;
00597   currentSigma[NuSyst::kCombinedXSecDISMultip2] = 0;
00598   currentSigma[NuSyst::kCombinedXSecDISMultip3] = 0;
00599   currentSigma[NuSyst::kNuMuBarXSecSum] = 0;
00600   currentSigma[NuSyst::kNuMuBarXSecOverall] = 0;
00601   currentSigma[NuSyst::kNuMuBarXSecCCMA] = 0;
00602   currentSigma[NuSyst::kNuMuBarXSecDISMultip2] = 0;  
00603   currentSigma[NuSyst::kNuMuBarXSecQEL] = 0;
00604   currentSigma[NuSyst::kNuMuBarXSecRes] = 0;
00605   currentSigma[NuSyst::kNormalisationBoth] = 0;
00606   currentSigma[NuSyst::kNormalisationNear] = 0;
00607   currentSigma[NuSyst::kNormalisationFar] = 0;
00608   currentSigma[NuSyst::kNCBackground] = 0;
00609   currentSigma[NuSyst::kCCBackground] = 0;
00610   currentSigma[NuSyst::kNDCleaning] = 0;
00611   currentSigma[NuSyst::kScraping] = 0;
00612   currentSigma[NuSyst::kJitterVDPID] = 0;
00613   currentSigma[NuSyst::kJitter] = 0;
00614   currentSigma[NuSyst::kDPID] = 0;  
00615   currentSigma[NuSyst::kTFProb] = 0;
00616   currentSigma[NuSyst::kTargetHole] = 0;
00617   currentSigma[NuSyst::kTauQELRes] = 0;
00618   currentSigma[NuSyst::kAllBackgroundsScaleBoth] = 0;
00619   currentSigma[NuSyst::kEnergyResolutionEventBoth] = 0;
00620   currentSigma[NuSyst::kEnergyResolutionEventNear] = 0;
00621   currentSigma[NuSyst::kEnergyResolutionShowerBoth] = 0;
00622   currentSigma[NuSyst::kEnergyResolutionShowerNear] = 0;
00623   currentSigma[NuSyst::kEnergyResolutionTrackRangeBoth] = 0;
00624   currentSigma[NuSyst::kEnergyResolutionTrackRangeNear] = 0;
00625   currentSigma[NuSyst::kEnergyResolutionTrackCurveBoth] = 0;
00626   currentSigma[NuSyst::kEnergyResolutionTrackCurveNear] = 0;
00627 }
00628 
00629 
00630 //____________________________________________________________________72
00631 void NuSystematic::ConfigureNeugenDefaults()
00632 {
00633   fkno_r112Default = 0.1;
00634   fkno_r122Default = 0.3;
00635   fkno_r132Default = 0.3;
00636   fkno_r142Default = 0.1;
00637   fkno_r113Default = 1.0;
00638   fkno_r123Default = 1.0;
00639   fkno_r133Default = 1.0;
00640   fkno_r143Default = 1.0;
00641   fkno_r212Default = 0.1;
00642   fkno_r222Default = 0.3;
00643   fkno_r232Default = 0.3;
00644   fkno_r242Default = 0.1;
00645   fkno_r213Default = 1.0;
00646   fkno_r223Default = 1.0;
00647   fkno_r233Default = 1.0;
00648   fkno_r243Default = 1.0;
00649   fma_qeDefault = 0.99;
00650   fma_resDefault = 1.12;
00651 }
00652 
00653 
00654 //____________________________________________________________________72
00655 void NuSystematic::ReadXML(const NuXMLConfig& xmlConfig)
00656 {
00657   NuSyst::NuSystematic_t fSystematicID = SystFromName(xmlConfig.Name());
00658   currentSigma[fSystematicID] = 1;
00659   oneSigma[fSystematicID] = xmlConfig.Shift();
00660   
00661   MSG("NuSystematic.cxx",Msg::kInfo)
00662   << "Reading NuXMLConfig for " 
00663   << xmlConfig.Name() << " at "
00664   << currentSigma[fSystematicID] << " sigma = " << oneSigma[fSystematicID] << endl;
00665 }
00666 
00667 //____________________________________________________________________72
00668 void NuSystematic::SetShiftsAsValues(map<NuSyst::NuSystematic_t, double> input)
00669 {
00670   map<NuSyst::NuSystematic_t, double>::const_iterator it;
00671   MAXMSG("NuSystematic",Msg::kInfo,5) << "Setting " << input.size() 
00672   << " systematic shifts." << endl;
00673   
00674   for (it = input.begin(); it != input.end(); ++it) {
00675     currentSigma[it->first] = ConvertValueToSigma(it->second, it->first);
00676   }  
00677 }
00678 
00679 
00680 //____________________________________________________________________72
00681 void NuSystematic::SetShiftsAsValues(map<TString, double> input)
00682 {
00683   cout << "Calling SetShifts" << endl;
00684   map<TString, double>::const_iterator it;
00685   MAXMSG("NuSystematic",Msg::kInfo,5) << "Setting " << input.size() 
00686   << " systematic shifts." << endl;
00687   
00688   for (it = input.begin(); it != input.end(); ++it) {
00689     NuSyst::NuSystematic_t fSys = SystFromName(it->first);
00690     currentSigma[fSys] = ConvertValueToSigma(it->second, fSys);
00691   }  
00692 }
00693 
00694 //____________________________________________________________________72
00695 void NuSystematic::SetShiftsAsSigmas(map<NuSyst::NuSystematic_t, double> input)
00696 {
00697   map<NuSyst::NuSystematic_t, double>::const_iterator it;
00698   MAXMSG("NuSystematic",Msg::kInfo,5) << "Setting " << input.size() 
00699   << " systematic shifts." << endl;
00700          
00701   for (it = input.begin(); it != input.end(); ++it) {
00702     currentSigma[it->first] = it->second;
00703   }  
00704 }
00705 
00706 
00707 //____________________________________________________________________72
00708 void NuSystematic::SetShiftsAsSigmas(map<TString, double> input)
00709 {
00710   cout << "Calling SetShifts" << endl;
00711   map<TString, double>::const_iterator it;
00712   MAXMSG("NuSystematic",Msg::kInfo,5) << "Setting " << input.size() 
00713   << " systematic shifts." << endl;
00714   
00715   for (it = input.begin(); it != input.end(); ++it) {
00716     NuSyst::NuSystematic_t fSys = SystFromName(it->first);
00717     currentSigma[fSys] = it->second;
00718   }  
00719 }
00720 
00721 
00722 //____________________________________________________________________72
00723 void NuSystematic::SetSigmas(map<NuSyst::NuSystematic_t, double> input)
00724 {
00725   map<NuSyst::NuSystematic_t, double>::const_iterator it;
00726   
00727   for (it = input.begin(); it != input.end(); ++it) {
00728     MSG("NuSystematic",Msg::kInfo) << "Setting " << SystNames(it->first)
00729     << " 1 sigma to " << it->second << endl;
00730     oneSigma[it->first] = it->second;
00731   }  
00732   
00733 }
00734 
00735 
00736 //____________________________________________________________________72
00737 void NuSystematic::SetSigmas(map<TString, double> input)
00738 {
00739   map<TString, double>::const_iterator it;
00740   
00741   for (it = input.begin(); it != input.end(); ++it) {
00742     MSG("NuSystematic",Msg::kInfo) << "Setting " << it->first
00743     << " 1 sigma to " << it->second << endl;
00744     NuSyst::NuSystematic_t fSys = SystFromName(it->first);
00745     currentSigma[fSys] = it->second;
00746   }  
00747 }
00748 
00749 //____________________________________________________________________72
00750 void NuSystematic::PrintState(bool verbose) const
00751 {
00752   map<NuSyst::NuSystematic_t, double>::const_iterator it;
00753   
00754   
00755   // Find the longest name
00756   Int_t lsize = 12;
00757   for (it = currentSigma.begin(); it != currentSigma.end(); ++it) {
00758     if (it->second || verbose) {
00759       int len = SystNames(it->first).Length();
00760       if (len > lsize) lsize = len;
00761     }
00762   }
00763   
00764   lsize++;
00765   
00766   // The 'total width'
00767   // Print a summary of this events cuts
00768   //MSG("NuSystematic",Msg::kInfo)
00769   MSG("NuSystematic",Msg::kInfo) << setw(lsize+21) << left << setfill('=') << "==== NuSystematics Summary " << endl;
00770   
00771   MSG("NuSystematic",Msg::kInfo) << setw(lsize) << left << setfill(' ') << "Systematic" 
00772                                  << setw(10) << right << "1 sigma" << " "
00773                                  << setw(10) << right << "Current" << endl;
00774   
00775   for (it = currentSigma.begin(); it != currentSigma.end(); ++it) {
00776     if (it->second || verbose) {
00777       MSG("NuSystematic",Msg::kInfo) << setw(lsize) << left << setfill(' ') << SystNames(it->first) 
00778                                      << setw(10) << right << OneSigma(it->first) << " "
00779                                      << setw(10) << right << it->second << endl;
00780     }
00781   }
00782   MSG("NuSystematic",Msg::kInfo) << endl;
00783 }
00784 
00785 
00786 
00787 
00788 
00790 // Access the Systematics Maps //
00792 
00793 //____________________________________________________________________72
00794 NuSyst::NuSystematic_t NuSystematic::SystFromName(TString systName) const
00795 {
00796   // First transform alternate names into cannonical ones
00797   if (systName.Contains("Scraping",TString::kIgnoreCase))
00798     systName = "DecayPipe";
00799   else if (systName.Contains("AbsoluteEnergyCalibration",TString::kIgnoreCase))
00800     systName = "ShowerEnergyScaleBoth";
00801   else if (systName.Contains("RelativeEnergyCalibrationNear",TString::kIgnoreCase))
00802     systName = "ShowerEnergyScaleNear";
00803   else if (systName.Contains("RelativeEnergyCalibrationFar",TString::kIgnoreCase))
00804     systName = "ShowerEnergyScaleFar";
00805   else if (systName.Contains("RelativeEnergyCalibration",TString::kIgnoreCase))
00806     systName = "ShowerEnergyScaleRelative";
00807   else if (systName.Contains("Beam",TString::kIgnoreCase) ||
00808            systName.Contains("SKZP",TString::kIgnoreCase) )
00809     systName = "Flux";
00810   else if (systName.Contains("Normalization",TString::kIgnoreCase)) {
00811     systName.ToLower();
00812     systName.ReplaceAll("lization", "lisation");
00813   }
00814 
00815   map<NuSyst::NuSystematic_t, TString>::const_iterator it;
00816   
00817   for (it = systNames.begin(); it != systNames.end(); ++it) {
00818     if (it->second.Contains(systName, TString::kIgnoreCase)) {
00819       return it->first;
00820     }
00821   }
00822   
00823   MSG("NuSystematic",Msg::kError) << "Cannot find systematic named " << systName << ", returning kUnknown." << endl;
00824   return NuSyst::kUnknown;
00825 }
00826 
00827 //____________________________________________________________________72
00828 // The size of a 1-sigma shift
00829 double NuSystematic::OneSigma(NuSyst::NuSystematic_t syst) const
00830 {
00831   map<NuSyst::NuSystematic_t, double>::const_iterator it;
00832   it = oneSigma.find(syst);
00833   if (it == oneSigma.end()) {
00834     MSG("NuSystematic",Msg::kError) << "Systematic # " << syst << " does not exist in oneSigma." << endl;
00835     assert(false);
00836   }
00837   return it->second;
00838 }
00839 
00840 //____________________________________________________________________72
00841 // The number of sigmas of the current shift
00842 double NuSystematic::CurrentSigma(NuSyst::NuSystematic_t syst) const
00843 {
00844   map<NuSyst::NuSystematic_t, double>::const_iterator it;
00845   it = currentSigma.find(syst);
00846   if (it == currentSigma.end()) {
00847     MSG("NuSystematic",Msg::kError) << "Systematic # " << syst << " does not exist in currentSigma." << endl;
00848     assert(false);
00849   }
00850   return it->second;  
00851 }
00852 
00853 //____________________________________________________________________72
00854 // How to convert between # of sigma and a shift
00855 const Int_t NuSystematic::SystMode(NuSyst::NuSystematic_t syst) const
00856 {
00857   map<NuSyst::NuSystematic_t, Int_t>::const_iterator it;
00858   it = systMode.find(syst);
00859   if (it == systMode.end()) {
00860     MSG("NuSystematic",Msg::kError) << "Systematic # " << syst << " does not exist in systMode." << endl;
00861     assert(false);
00862   }
00863   return it->second;  
00864 }
00865 
00866 //____________________________________________________________________72
00867 // The cannonical names of the systematics
00868 const TString NuSystematic::SystNames(NuSyst::NuSystematic_t syst) const
00869 {
00870   map<NuSyst::NuSystematic_t, TString>::const_iterator it;
00871   it = systNames.find(syst);
00872   if (it == systNames.end()) {
00873     MSG("NuSystematic",Msg::kError) << "Systematic # " << syst << " does not exist in systNames." << endl;
00874     assert(false);
00875   }
00876   return it->second;  
00877 }
00878 
00879 //____________________________________________________________________72
00880 bool NuSystematic::FluxSyst(const NuXMLConfig& xmlConfig)
00881 {
00882   TString systName = xmlConfig.Name();
00883   if (systName.Contains("Scraping",TString::kIgnoreCase) ||
00884       systName.Contains("DecayPipe",TString::kIgnoreCase)){
00885     return true;
00886   }
00887   if (systName.Contains("Beam",TString::kIgnoreCase) ||
00888       systName.Contains("SKZP",TString::kIgnoreCase) ||
00889       systName.Contains("Flux",TString::kIgnoreCase)){
00890     return true;
00891   }
00892   if (systName.Contains("TargetHole",TString::kIgnoreCase)){
00893     return true;
00894   }
00895   
00896   return false;
00897 }
00898 
00899 
00900 
00902 // Set the various selectors //
00904 
00905 //____________________________________________________________________72
00906 void NuSystematic::SetCCSelector(NuCut *input) 
00907 { 
00908   fCCSelector = input; 
00909   MSG("NuSystematic",Msg::kInfo) << "Setting the CC selector" << endl;
00910   fCCSelector->PrintSummary();
00911 }
00912 
00913 //____________________________________________________________________72
00914 void NuSystematic::SetNCSelector(NuCut *input) 
00915 { 
00916   fNCSelector = input; 
00917   MSG("NuSystematic",Msg::kInfo) << "Setting the NC selector" << endl;
00918   fNCSelector->PrintSummary();
00919 }
00920 
00921 //____________________________________________________________________72
00922 void NuSystematic::SetNuBarSelector(NuCut *input) 
00923 { 
00924   fNuBarSelector = input; 
00925   MSG("NuSystematic",Msg::kInfo) << "Setting the NuBar selector" << endl;
00926   fNuBarSelector->PrintSummary();
00927 }
00928 
00929 //____________________________________________________________________72
00930 void NuSystematic::SetRockSelector(NuCut *input) 
00931 { 
00932   fRockSelector = input; 
00933   MSG("NuSystematic",Msg::kInfo) << "Setting the Rock selector" << endl;
00934   fRockSelector->PrintSummary();
00935 }
00936 
00937 
00938 
00939 
00940 
00942 // Determine Shifts and Apply Them //
00944 
00945 //____________________________________________________________________72
00946 void NuSystematic::Shift(NuEvent& event) const
00947 {
00948   if (CurrentSigma(NuSyst::kScraping))   this->ScrapingShift(event);
00949   if (CurrentSigma(NuSyst::kTargetHole)) this->TargetHoleShift(event);
00950   if (CurrentSigma(NuSyst::kShowerEnergyOffset)) this->ShowerEnergyOffset(event);
00951   if (CurrentSigma(NuSyst::kShowerEnergyFunction)) this->ShowerEnergyFunction(event);
00952   if (CurrentSigma(NuSyst::kShowerEnergyScale) ||
00953       CurrentSigma(NuSyst::kShowerEnergyScaleNear) ||
00954       CurrentSigma(NuSyst::kShowerEnergyScaleFar) ||
00955       CurrentSigma(NuSyst::kShowerEnergyScaleRelative) ) this->ShowerEnergyScale(event);
00956   if (CurrentSigma(NuSyst::kTrackEnergyRange) ||
00957       CurrentSigma(NuSyst::kTrackEnergyScale) ||
00958       CurrentSigma(NuSyst::kTrackEnergyCurvatureBoth) ||
00959       CurrentSigma(NuSyst::kTrackEnergyCurvatureFar) ) this->TrackEnergyScale(event);
00960   if (CurrentSigma(NuSyst::kTrackEnergyOverall)) this->TrackEnergyOverall(event);
00961   if (CurrentSigma(NuSyst::kBeam)) this->BeamShift(event);
00962   if (CurrentSigma(NuSyst::kBFieldBoth) ||
00963       CurrentSigma(NuSyst::kBFieldNear) ||
00964       CurrentSigma(NuSyst::kBFieldFar) ) this->BFieldShift(event);
00965   if (CurrentSigma(NuSyst::kAllBackgroundsScaleBoth)) this->AllBackgroundsScaleBothShift(event);
00966   if (CurrentSigma(NuSyst::kNCBackground)) this->NCBackgroundShift(event);
00967   if (CurrentSigma(NuSyst::kCCBackground)) this->CCBackgroundShift(event);
00968   if (CurrentSigma(NuSyst::kNDCleaning)) this->NDCleaningShift(event);
00969   if (CurrentSigma(NuSyst::kNormalisationBoth) ||
00970       CurrentSigma(NuSyst::kNormalisationNear) ||
00971       CurrentSigma(NuSyst::kNormalisationFar)) this->NormalisationShift(event);
00972   if (CurrentSigma(NuSyst::kNuMuBarXSecSum)) this->NuMuBarSumXSecShift(event);
00973   if (CurrentSigma(NuSyst::kCombinedXSecOverall) ||
00974       CurrentSigma(NuSyst::kNuMuBarXSecOverall)) this->OverallXSecShift(event);
00975   if (CurrentSigma(NuSyst::kNuMuBarXSecQEL)) this->NuMuBarQELXSecShift(event);
00976   if (CurrentSigma(NuSyst::kNuMuBarXSecRes)) this->NuMuBarResXSecShift(event);
00977   if (CurrentSigma(NuSyst::kCombinedXSecCCMA) ||
00978       CurrentSigma(NuSyst::kCombinedXSecMaRes) ||
00979       CurrentSigma(NuSyst::kCombinedXSecMaQE) ||
00980       CurrentSigma(NuSyst::kCombinedXSecDISMultip2) ||
00981       CurrentSigma(NuSyst::kCombinedXSecDISMultip3) ||
00982       CurrentSigma(NuSyst::kNuMuBarXSecCCMA) ||
00983       CurrentSigma(NuSyst::kNuMuBarXSecDISMultip2)) this->NeugenXSecShift(event);
00984   if (CurrentSigma(NuSyst::kJitterVDPID)) this->JitterVDPIDShift(event);
00985   if (CurrentSigma(NuSyst::kTauQELRes)) this->TauQELResShift(event);
00986   if (CurrentSigma(NuSyst::kEnergyResolutionEventBoth) ||
00987       CurrentSigma(NuSyst::kEnergyResolutionEventNear)) this->EnergyResolutionEvent(event);
00988   if (CurrentSigma(NuSyst::kEnergyResolutionShowerBoth) ||
00989       CurrentSigma(NuSyst::kEnergyResolutionShowerNear)) this->EnergyResolutionShower(event);
00990   if (CurrentSigma(NuSyst::kEnergyResolutionTrackRangeBoth) ||
00991       CurrentSigma(NuSyst::kEnergyResolutionTrackRangeNear)) this->EnergyResolutionTrackRange(event);
00992   if (CurrentSigma(NuSyst::kEnergyResolutionTrackCurveBoth) ||
00993       CurrentSigma(NuSyst::kEnergyResolutionTrackCurveNear)) this->EnergyResolutionTrackCurve(event);
00994 }
00995 
00996 //____________________________________________________________________72
00997 const Float_t NuSystematic::ConvertSigmaToValue(Float_t sigma, NuSyst::NuSystematic_t fSys) const
00998 {  
00999   if (sigma == -999) sigma = CurrentSigma(fSys);
01000   
01001   if (SystMode(fSys) == kMinusPlus) {
01002     return sigma*(OneSigma(fSys) - 1.0) + 1.0;
01003   }
01004   else if (SystMode(fSys) == kAsIs) {
01005     return sigma*OneSigma(fSys);
01006   }
01007   else if (SystMode(fSys) == kSigma) {
01008     return sigma;
01009   }
01010   else {
01011     MSG("NuSystematic",Msg::kError) << "Didn't recognize syst mode " << SystMode(fSys) << " for systematic " 
01012     << NameFromSyst(fSys) << "(" << fSys << ")" << endl;
01013     return 0;
01014   }
01015 }
01016 
01017 //____________________________________________________________________72
01018 const Float_t NuSystematic::ConvertValueToSigma(Float_t shift, NuSyst::NuSystematic_t fSys) const
01019 {
01020   if (SystMode(fSys) == kMinusPlus) {
01021     return (shift-1.0)/(OneSigma(fSys)-1.0);
01022   }
01023   else if (SystMode(fSys) == kAsIs) {
01024     return shift/OneSigma(fSys);
01025   }
01026   else if (SystMode(fSys) == kSigma) {
01027     return shift;
01028   }
01029   else {
01030     MSG("NuSystematic",Msg::kError) << "Didn't recognize syst mode " << SystMode(fSys) << " for systematic " 
01031     << NameFromSyst(fSys) << "(" << fSys << ")" << endl;
01032     return 0;
01033   }
01034 }
01035 
01036 //____________________________________________________________________72
01037 void NuSystematic::Randomize()
01038 {
01039   map<NuSyst::NuSystematic_t, double>::iterator it;
01040   
01041   MAXMSG("NuSystematic",Msg::kInfo, 1) 
01042   << "Setting random gaussian shifts for all non-zero systematics" << endl;
01043   
01044   for (it = currentSigma.begin(); it != currentSigma.end(); ++it) {
01045     if (it->second) {
01046       it->second = fRandom->Gaus(0, 1);
01047       // Prevent a systematic from being turned off 
01048       // persistently by a random draw
01049       if (!it->second) it->second = 1e-8; 
01050     }
01051   }
01052 }
01053 
01054 
01055 
01057 // Apply systematic shifts //
01059 
01060 //____________________________________________________________________72
01061 void NuSystematic::BeamShift(NuEvent& event) const
01062 {
01063   MAXMSG("NuSystematic",Msg::kInfo,1)
01064     << "Performing beam shift = " << ShiftAsSigma(NuSyst::kBeam) << "s" << endl;
01065   event.rw *= 1.0 + ShiftAsValue(NuSyst::kBeam) * (event.fluxErr-1.0);
01066   return;
01067 }
01068 
01069 //____________________________________________________________________72
01070 void NuSystematic::JitterVDPIDShift(NuEvent& event) const
01071 {
01072   MAXMSG("NuSystematic",Msg::kInfo,1)
01073     << "Performing track jitter & DPID shift = " << ShiftAsSigma(NuSyst::kJitterVDPID) << "s" << endl;
01074   event.jitter += ConvertSigmaToValue(ShiftAsSigma(NuSyst::kJitterVDPID), NuSyst::kJitter);
01075   event.dpID += ConvertSigmaToValue(ShiftAsSigma(NuSyst::kJitterVDPID), NuSyst::kDPID);
01076   return;
01077 }
01078 
01079 //____________________________________________________________________72
01080 void NuSystematic::TFProbShift(NuEvent& event) const
01081 {
01082   MAXMSG("NuSystematic",Msg::kInfo,1)
01083     << "Performing track fit probability shift = " << ShiftAsSigma(NuSyst::kTFProb) << "s" << endl;
01084   event.prob += ShiftAsValue(NuSyst::kTFProb);
01085   return;
01086 }
01087 
01088 //____________________________________________________________________72
01089 void NuSystematic::NeugenXSecShift(NuEvent& event) const
01090 {
01091     MAXMSG("NuSystematic",Msg::kInfo,1)
01092       << "Performing a Neugen cross section shift" << endl;
01093   if (0 == event.iaction) return;
01094   
01095   MCReweight& mcReweight = MCReweight::Instance();
01096   if (firstMCReweight){
01097     NeugenWeightCalculator* wc = new NeugenWeightCalculator();
01098     mcReweight.AddWeightCalculator(wc);
01099     firstMCReweight = false;
01100   }
01101   //  cout << "Num weight calc: " << mcReweight.NumWeightCalcAdded() << endl;
01102   Registry reweightConfigRegistry;
01103   Registry defaultRegistry;
01104 
01105   //Set to MODBYRS4 for Daikon.
01106   if (ReleaseType::IsDaikon(event.releaseType)){
01107     reweightConfigRegistry.Set("neugen:config_name","MODBYRS");
01108     reweightConfigRegistry.Set("neugen:config_no",4);
01109     defaultRegistry.Set("neugen:config_name","MODBYRS");
01110     defaultRegistry.Set("neugen:config_no",4);
01111   }
01112   else{
01113     MSG("NuSystematic.cxx",Msg::kError)
01114       << "Using non-daikon MC. I don't know how to apply Neugen "
01115       << "parameters to that."
01116       << endl;
01117   }
01118 
01119   //Set the shifted CombinedXSecCCMA parameters.
01120   this->SetShiftedNeugenParameters(reweightConfigRegistry, event);
01121 
01122   
01123   //Create objects to give to MCReweight.
01124   MCEventInfo mcEventInfo = this->CreateMCEventInfo(event);
01125   NuParent* nuParent = 0;
01126 
01127   mcReweight.ResetAllReweightConfigs();
01128 
01129   //    cout << "iresonance is " << event.iresonance << endl;
01130   //Get the weight.
01131   Double_t weight = mcReweight.ComputeWeight(&mcEventInfo,
01132                                              nuParent,
01133                                              &reweightConfigRegistry);
01134   //  mcReweight.PrintReweightConfig(cout);
01135 
01136 
01137   //Get the default weight.
01138   this->SetNeugenDefaults(defaultRegistry);
01139   mcReweight.ResetAllReweightConfigs();
01140   Double_t defaultWeight = mcReweight.ComputeWeight(&mcEventInfo,
01141                                                     nuParent,
01142                                                     &defaultRegistry);
01143   //  cout << "Weight changed by " << weight << "/" << defaultWeight << endl;
01144   if (defaultWeight>0.0){
01145     event.rw *= weight/defaultWeight;
01146   }
01147   else{
01148     MSG("NuSystematic.cxx",Msg::kError)
01149       << "Default weight <= 0."
01150       << endl;
01151   }
01152   return;
01153 }
01154 
01155 //____________________________________________________________________72
01156 void NuSystematic::NuMuBarSumXSecShift(NuEvent& event) const
01157 {
01158     MAXMSG("NuSystematic",Msg::kInfo,1)
01159     << "Performing numubar summed cross section shift = "
01160     << ShiftAsSigma(NuSyst::kNuMuBarXSecSum) << "s" << endl;
01161     if (1 != event.iaction) return;
01162     if (event.inu != -14) return;
01163     
01164     static double xp = 25.;
01165     static double a = 0.895;
01166     static double xc = 4.0;
01167     static double b = 7.59e-3;
01168     static double c = -8.05e-4;
01169     double E = event.neuEnMC;
01170     double shift = -0.0617;
01171     if (E < 25) shift += a - 1 + 2.*(1.-a)*E/xp + (a - 1.)*E*E/(xp*xp);
01172     if (E < xc) shift += (c*(xc-E)*(xc-E)*(xc-E)+b*(xc-E)*(xc-E));
01173     shift = 1 + ShiftAsValue(NuSyst::kNuMuBarXSecSum) * shift;
01174     
01175     event.rw *= shift;
01176     return;
01177 }
01178 
01179 //____________________________________________________________________72
01180 void NuSystematic::OverallXSecShift(NuEvent& event) const
01181 {
01182   MAXMSG("NuSystematic",Msg::kInfo,1)
01183     << "Performing overall cross section shift combined = " << ShiftAsSigma(NuSyst::kCombinedXSecOverall)
01184   << "s, numubar = " << ShiftAsSigma(NuSyst::kNuMuBarXSecOverall) << "s" << endl;
01185   if (1 != event.iaction) return;
01186   
01187   event.rw *= ShiftAsValue(NuSyst::kCombinedXSecOverall);
01188   if (event.inu < 0) 
01189     event.rw *= ShiftAsValue(NuSyst::kNuMuBarXSecOverall);
01190 }
01191 
01192 //____________________________________________________________________72
01193 void NuSystematic::TauQELResShift(NuEvent& event) const
01194 {
01195   MAXMSG("NuSystematic",Msg::kInfo,1)
01196     << "Performing tau QEL+Res shift: "
01197     << (this->ShiftAsValue(NuSyst::kTauQELRes)-1.)*100. << "%." << endl;
01198 
01199   if (16 == TMath::Abs(event.inu) && 1 == event.iaction
01200       && (1001 == event.iresonance || 1002 == event.iresonance)){
01201     event.rw *= ShiftAsValue(NuSyst::kTauQELRes);
01202   }
01203   return;
01204 }
01205 
01206 //____________________________________________________________________72
01207 void NuSystematic::NuMuBarQELXSecShift(NuEvent& event) const
01208 {
01209   MAXMSG("NuSystematic",Msg::kInfo,1)
01210     << "Performing NuMuBar QEL cross section shift = "
01211     << ShiftAsSigma(NuSyst::kNuMuBarXSecQEL) << "s" << endl;
01212 
01213   if (1 != event.iaction) return;
01214   //  if (-14 != event.inu) return;
01215   if (event.inu > 0) return;
01216   if (1001 != event.iresonance) return;
01217   event.rw *= ShiftAsValue(NuSyst::kNuMuBarXSecQEL);
01218   return;
01219 }
01220 
01221 //____________________________________________________________________72
01222 void NuSystematic::NuMuBarResXSecShift(NuEvent& event) const
01223 {
01224   MAXMSG("NuSystematic",Msg::kInfo,1)
01225     << "Performing NuMuBar Res cross section shift"
01226     << ShiftAsSigma(NuSyst::kNuMuBarXSecRes) << "s" << endl;
01227 
01228   if (1 != event.iaction) return;
01229   //  if (-14 != event.inu) return;
01230   if (event.inu > 0) return;
01231   if (1002 != event.iresonance) return;
01232   event.rw *= ShiftAsValue(NuSyst::kNuMuBarXSecRes);
01233   return;
01234 }
01235 
01236 //____________________________________________________________________72
01237 void NuSystematic::AllBackgroundsScaleBothShift(NuEvent& event) const
01238 {
01239   if (!fNuBarSelector) {
01240     MSG("NuSystematic",Msg::kError) << "Cannot apply AllBackgroundsScaleBoth without doing SetNuBarSelector()" << endl;
01241     assert(false);
01242   }
01243   
01244   fNuBarSelector->MakeCuts(event);
01245   if (1==event.charge && fNuBarSelector->Passed()
01246       && (14 == event.inu || 0 == event.iaction)) {
01247 
01248     MAXMSG("NuSystematic",Msg::kInfo,1)
01249     << "Performing AllBackgroundsScaleBoth shift ="
01250     << ShiftAsSigma(NuSyst::kAllBackgroundsScaleBoth) << "s" << endl;
01251     
01252     event.rw *= ShiftAsValue(NuSyst::kAllBackgroundsScaleBoth);
01253   }
01254   return;
01255 }
01256 
01257 //____________________________________________________________________72
01258 void NuSystematic::BFieldShift(NuEvent& event) const
01259 {
01260   MAXMSG("NuSystematic",Msg::kInfo,1)
01261     << "Performing BField shift both = " << ShiftAsSigma(NuSyst::kBFieldBoth) 
01262     << "s, near = " << ShiftAsSigma(NuSyst::kBFieldNear) 
01263     << "s, far = " << ShiftAsSigma(NuSyst::kBFieldFar) << endl;
01264   if (1==event.charge && 14 == event.inu && 1 == event.iaction){
01265     event.rw *= ShiftAsValue(NuSyst::kBFieldBoth);
01266     if (Detector::kNear==event.detector)
01267       event.rw *= ShiftAsValue(NuSyst::kBFieldNear);
01268     if (Detector::kFar==event.detector)
01269       event.rw *= ShiftAsValue(NuSyst::kBFieldFar);
01270   }
01271   return;
01272 }
01273 
01274 //____________________________________________________________________72
01275 void NuSystematic::NCBackgroundShift(NuEvent& event) const
01276 {
01277   if (!fCCSelector) {
01278     MSG("NuSystematic",Msg::kError) << "Cannot apply NCBackground without doing SetCCSelector()" << endl;
01279     assert(false);
01280   }
01281   
01282   MAXMSG("NuSystematic",Msg::kInfo,1)
01283     << "Performing NC background shift " << ShiftAsSigma(NuSyst::kNCBackground) << "s" << endl;
01284   
01285   fCCSelector->MakeCuts(event);
01286   if (0 == event.iaction && fCCSelector->Passed()) 
01287     event.rw *= ShiftAsValue(NuSyst::kNCBackground);
01288 }
01289 
01290 //____________________________________________________________________72
01291 void NuSystematic::CCBackgroundShift(NuEvent& event) const
01292 {
01293   if (!fNCSelector) {
01294     MSG("NuSystematic",Msg::kError) << "Cannot apply CCBackground without doing SetNCSelector()" << endl;
01295     assert(false);
01296   }
01297   
01298   MAXMSG("NuSystematic",Msg::kInfo,1)
01299   << "Performing CC background shift " << ShiftAsSigma(NuSyst::kCCBackground) << "s" << endl;
01300   
01301   fNCSelector->MakeCuts(event);
01302   if (1 == event.iaction && fNCSelector->Passed()) 
01303     event.rw *= ShiftAsValue(NuSyst::kCCBackground);
01304 }
01305 
01306 //____________________________________________________________________72
01307 void NuSystematic::NDCleaningShift(NuEvent& event) const
01308 {
01309   if (!fNCSelector) {
01310     MSG("NuSystematic",Msg::kError) << "Cannot apply NDCleaning without doing SetNCSelector()" << endl;
01311     assert(false);
01312   }
01313   
01314   MAXMSG("NuSystematic",Msg::kInfo,1)
01315   << "Performing ND cleaning shift " << ShiftAsSigma(NuSyst::kNDCleaning) << "s" << endl;
01316   
01317   double percent = 0;
01318   if(event.energyNC < 0.5) percent = 15.2;
01319   if(event.energyNC >= 0.5 && event.energyNC < 1.0) percent = 2.9;
01320   if(event.energyNC >= 1.0 && event.energyNC < 1.5) percent = 0.4;
01321   
01322   fNCSelector->MakeCuts(event);
01323   if(fNCSelector->Passed() && event.detector == Detector::kNear)
01324     event.rw *= 1.+(percent/100.)*ShiftAsValue(NuSyst::kNDCleaning);
01325 }
01326 
01327 //____________________________________________________________________72
01328 void NuSystematic::NormalisationShift(NuEvent& event) const
01329 {
01330     MAXMSG("NuSystematic",Msg::kInfo,1)
01331       << "Performing Normalisation shift both = "  << ShiftAsSigma(NuSyst::kNormalisationBoth)
01332       << "s, near = " << ShiftAsSigma(NuSyst::kNormalisationNear)
01333       << "s, far = " << ShiftAsSigma(NuSyst::kNormalisationFar) << endl;
01334   
01335   event.rw *= ShiftAsValue(NuSyst::kNormalisationBoth);
01336   if (Detector::kNear==event.detector)
01337     event.rw *= ShiftAsValue(NuSyst::kNormalisationNear);
01338   if (Detector::kFar==event.detector)
01339     event.rw *= ShiftAsValue(NuSyst::kNormalisationFar);
01340   return;
01341 }
01342 
01343 //____________________________________________________________________72
01344 void NuSystematic::TargetHoleShift(NuEvent& event) const
01345 {
01346   Double_t holeStart = 20.0;
01347   Double_t holeLength = ShiftAsValue(NuSyst::kTargetHole);
01348 
01349   MAXMSG("NuSystematic",Msg::kInfo,1)
01350     << "Performing target hole shift. Hole length: "
01351     << holeLength << " cm" << endl;
01352 
01353   if ((event.ppvz > holeStart) && (event.ppvz < holeStart+holeLength)){
01354     event.rw = 0;
01355   }
01356   return;
01357 }
01358 
01359 //____________________________________________________________________72
01360 void NuSystematic::ScrapingShift(NuEvent& event) const 
01361 {
01362     MAXMSG("NuSystematic",Msg::kInfo,1)
01363       << "Performing scraping shift = " << ShiftAsSigma(NuSyst::kScraping) << "s" << endl;
01364   
01365 //    Float_t r = sqrt(event.ppvx*event.ppvx +
01366 //                     event.ppvy*event.ppvy);
01367 //    Float_t z = event.ppvz;
01368 //    Float_t Znom = 52.06; // -187.06 for HE
01369 //    if (BeamType::kL250z200i == event.beamType){
01370 //      Znom = -187.06;
01371 //    }
01372 //    else if (BeamType::kL010z185i == event.beamType){
01373 //      Znom = 52.06;
01374 //    }
01375 //    else{
01376 //      Znom = 52.06;
01377 //    }
01378 
01379     //Don't shift muons
01380     if (13 == event.ptype) return;
01381     if (-13 == event.ptype) return;
01382     
01383 //    if (r < 1.65 && TMath::Abs(z - Znom) < 0.1)
01384 //        return; // Target End
01385 //    
01386 //    if (TMath::Abs(r - 1.51) < 0.11 && z < Znom)
01387 //        return; // Target Side
01388 
01389     if (event.ppvz < 4500)  return;
01390     //Not decay pipe
01391     
01392     event.rw *= ShiftAsValue(NuSyst::kScraping);
01393     
01394     return;
01395 }
01396 
01397 //____________________________________________________________________72
01398 void NuSystematic::ShowerEnergyOffset(NuEvent& event) const
01399 {
01400     MAXMSG("NuSystematic",Msg::kInfo,1)
01401       << "Performing shower energy offset shift = " << ShiftAsValue(NuSyst::kShowerEnergyOffset)/Munits::MeV << " MeV" << endl;
01402   event.shwEn += ShiftAsValue(NuSyst::kShowerEnergyOffset)/Munits::GeV;
01403   event.energy = event.shwEn+event.trkEn;
01404   return;
01405 }
01406 
01407 //____________________________________________________________________72
01408 void NuSystematic::ShowerEnergyFunction(NuEvent& event) const
01409 {
01410   MAXMSG("NuSystematic",Msg::kInfo,1)
01411     << "Performing shower energy function scale " 
01412     << ShiftAsSigma(NuSyst::kShowerEnergyFunction)
01413     << "s" << endl;
01414 
01415   Double_t offset = 7.0;
01416   Double_t scale = 4.0;
01417   Double_t eLife = 1.5; //GeV
01418   Double_t enShift = 1.0 + this->ShiftAsSigma(NuSyst::kShowerEnergyFunction)*0.01*
01419     (offset + scale*TMath::Exp(-1.0*event.shwEn/eLife));
01420   event.shwEn *= enShift;
01421   event.energy = event.shwEn+event.trkEn;
01422   return;
01423 }
01424 
01425 //____________________________________________________________________72
01426 void NuSystematic::ShowerEnergyScale(NuEvent& event) const
01427 {
01428   MAXMSG("NuSystematic",Msg::kInfo,1)
01429       << "Performing shower energy scale with near = " << ShiftAsSigma(NuSyst::kShowerEnergyScaleNear)
01430       << "s, far = " << ShiftAsSigma(NuSyst::kShowerEnergyScaleFar)
01431       << "s, relative = " << ShiftAsSigma(NuSyst::kShowerEnergyScaleRelative)
01432       << "s, overall = " << ShiftAsSigma(NuSyst::kShowerEnergyScale) << "s" << endl;
01433   
01434   if (Detector::kNear==event.detector) {
01435     event.shwEn *= ShiftAsValue(NuSyst::kShowerEnergyScaleNear);
01436     event.shwEn *= ShiftAsValue(NuSyst::kShowerEnergyScaleRelative);
01437   }
01438   if (Detector::kFar==event.detector) {
01439     event.shwEn *= ShiftAsValue(NuSyst::kShowerEnergyScaleFar);
01440   }
01441   event.shwEn *= ShiftAsValue(NuSyst::kShowerEnergyScale);
01442   event.energy = event.shwEn+event.trkEn;
01443   return;
01444 }
01445 
01446 //____________________________________________________________________72
01447 void NuSystematic::TrackEnergyScale(NuEvent& event) const
01448 {
01449   MAXMSG("NuSystematic",Msg::kInfo,1)
01450   << "Performing track energy scale with range = " << ShiftAsSigma(NuSyst::kTrackEnergyRange)
01451   << "s, curve near = " << ShiftAsSigma(NuSyst::kTrackEnergyCurvatureNear)
01452   << "s, curve far = " << ShiftAsSigma(NuSyst::kTrackEnergyCurvatureFar)
01453   << "s, curve both = " << ShiftAsSigma(NuSyst::kTrackEnergyCurvatureBoth)
01454   << "s, scale = " << ShiftAsSigma(NuSyst::kShowerEnergyScale) << "s" << endl;
01455   
01456   if (event.usedRange){
01457     event.trkEn *= ShiftAsValue(NuSyst::kTrackEnergyRange);
01458   }
01459   else {
01460     event.trkEn *= ShiftAsValue(NuSyst::kTrackEnergyCurvatureBoth);
01461     if (Detector::kNear==event.detector)
01462       event.trkEn *= ShiftAsValue(NuSyst::kTrackEnergyCurvatureNear);
01463     if (Detector::kFar==event.detector)
01464       event.trkEn *= ShiftAsValue(NuSyst::kTrackEnergyCurvatureFar);
01465   }
01466   event.trkEn *= ShiftAsValue(NuSyst::kTrackEnergyScale);
01467   event.energy = event.shwEn+event.trkEn;
01468   return;
01469 }
01470 
01471 //____________________________________________________________________72
01472 void NuSystematic::TrackEnergyOverall(NuEvent& event) const
01473 {
01474   MAXMSG("NuSystematic",Msg::kInfo,1)
01475   << "Performing overall track energy shift "
01476   << this->ShiftAsSigma(NuSyst::kTrackEnergyOverall) << " sigma"
01477   << endl;
01478   Double_t eScale = 1.0;
01479   if (event.usedRange){
01480     eScale = 2.0;
01481   }
01482   else if (event.usedCurv){
01483     eScale = 3.0;
01484   }
01485   else {
01486     eScale = 1.0;
01487   }
01488   event.trkEn *= 1.0 + this->ShiftAsSigma(NuSyst::kTrackEnergyOverall)*0.01*eScale;
01489   event.energy = event.shwEn+event.trkEn;
01490   return;
01491 }
01492 
01493 //____________________________________________________________________72
01494 void NuSystematic::EnergyResolutionEvent(NuEvent& event) const
01495 {
01496   MAXMSG("NuSystematic",Msg::kInfo,1)
01497     << "Performing event energy resolution shift both = " << ShiftAsSigma(NuSyst::kEnergyResolutionEventBoth)
01498     << "s, near = " << ShiftAsSigma(NuSyst::kEnergyResolutionEventNear) << "s" << endl;
01499   
01500   if (fabs(event.neuEnMC) < 1e-9) return;
01501   Double_t deltaE = (event.energy - event.neuEnMC) / event.neuEnMC;
01502   deltaE *= ShiftAsValue(NuSyst::kEnergyResolutionEventBoth);
01503   if (Detector::kNear == event.detector)
01504     deltaE *= ShiftAsValue(NuSyst::kEnergyResolutionEventNear);  
01505   event.energy = deltaE*event.neuEnMC + event.neuEnMC;
01506   return;
01507 }
01508 
01509 //____________________________________________________________________72
01510 void NuSystematic::EnergyResolutionShower(NuEvent& event) const
01511 {
01512   MAXMSG("NuSystematic",Msg::kInfo,1)
01513     << "Performing shower energy resolution shift both = " << ShiftAsSigma(NuSyst::kEnergyResolutionShowerBoth)
01514     << "s, near = " << ShiftAsSigma(NuSyst::kEnergyResolutionShowerNear) << "s" << endl;
01515   
01516   if (fabs(event.shwEnMC) <= 1e-9) return;
01517   if (event.nshw < 1) return;
01518   if (fabs(event.shwEn) < 1e-9) return;
01519   Double_t deltaE = (event.shwEn - event.shwEnMC) / event.shwEnMC;
01520   deltaE *= ShiftAsValue(NuSyst::kEnergyResolutionShowerBoth);
01521   if (Detector::kNear == event.detector)
01522     deltaE *= ShiftAsValue(NuSyst::kEnergyResolutionShowerNear);  
01523   event.shwEn = deltaE*event.shwEnMC + event.shwEnMC;
01524   event.energy = event.shwEn + event.trkEn;
01525   return;
01526 }
01527 
01528 //____________________________________________________________________72
01529 void NuSystematic::EnergyResolutionTrackRange(NuEvent& event) const
01530 {
01531   if (!event.usedRange) return;
01532 
01533   MAXMSG("NuSystematic",Msg::kInfo,1)
01534     << "Performing track energy range resolution shift both = " << ShiftAsSigma(NuSyst::kEnergyResolutionTrackRangeBoth)
01535     << "s, near = " << ShiftAsSigma(NuSyst::kEnergyResolutionTrackRangeNear) << "s" << endl;
01536 
01537   if (event.trkEnRange != event.trkEn){
01538     cout << "Stopping event, but event.trkEnRange != event.trkEn"
01539     << endl;
01540     assert(false);
01541   }
01542 
01543   if (fabs(event.trkEnMC) <= 1e-9) return;
01544   if (event.ntrk < 1) return;
01545   if (fabs(event.trkEn) < 1e-9) return;
01546   Double_t deltaE = (event.trkEnRange - event.trkEnMC) / event.trkEnMC;
01547   deltaE *= ShiftAsValue(NuSyst::kEnergyResolutionTrackRangeBoth);
01548   if (Detector::kNear == event.detector)
01549     deltaE *= ShiftAsValue(NuSyst::kEnergyResolutionTrackRangeNear);  
01550   
01551   event.trkEnRange = deltaE*event.trkEnMC + event.trkEnMC;
01552 
01553   event.trkEn = event.trkEnRange;
01554   event.energy = event.shwEn + event.trkEn;
01555   return;
01556 }
01557 
01558 //____________________________________________________________________72
01559 void NuSystematic::EnergyResolutionTrackCurve(NuEvent& event) const
01560 {
01561   if (!event.usedCurv) return;
01562 
01563   MAXMSG("NuSystematic",Msg::kInfo,1)
01564     << "Performing track energy curve resolution shift both = " << ShiftAsSigma(NuSyst::kEnergyResolutionTrackCurveBoth)
01565     << "s, near = " << ShiftAsSigma(NuSyst::kEnergyResolutionTrackCurveNear) << "s" << endl;
01566   
01567   
01568   if (event.trkEnCurv != event.trkEn){
01569     cout << "Exiting event, but event.trkEnCurv != event.trkEn"
01570     << endl;
01571     assert(false);
01572   }
01573 
01574 
01575   if (fabs(event.trkEnMC) <= 1e-9) return;
01576   if (event.ntrk < 1) return;
01577   if (fabs(event.trkEn) < 1e-9) return;
01578   Double_t deltaE = (event.trkEnCurv - event.trkEnMC) / event.trkEnMC;
01579   deltaE *= ShiftAsValue(NuSyst::kEnergyResolutionTrackCurveBoth);
01580   if (Detector::kNear == event.detector)
01581     deltaE *= ShiftAsValue(NuSyst::kEnergyResolutionTrackCurveNear);  
01582 
01583   event.trkEnCurv = deltaE*event.trkEnMC + event.trkEnMC;
01584 
01585   event.trkEn = event.trkEnCurv;
01586   event.energy = event.shwEn + event.trkEn;
01587   return;
01588 }
01589 
01590 
01591 
01592 
01593 
01595 // Neugen Functions //
01597 
01598 //____________________________________________________________________72
01599 const MCEventInfo NuSystematic::CreateMCEventInfo(const NuEvent& nuEvent) const
01600 {
01601   MCEventInfo mcEvent;
01602   
01603   mcEvent.nuE = nuEvent.neuEnMC;
01604   mcEvent.nuPx = nuEvent.neuPxMC;
01605   mcEvent.nuPy = nuEvent.neuPyMC;
01606   mcEvent.nuPz = nuEvent.neuPzMC;
01607   mcEvent.tarE = nuEvent.tgtEnMC;
01608   mcEvent.tarPx = nuEvent.tgtPxMC;
01609   mcEvent.tarPy = nuEvent.tgtPyMC;
01610   mcEvent.tarPz = nuEvent.tgtPzMC;
01611   mcEvent.y = nuEvent.yMC;
01612   mcEvent.x = nuEvent.xMC;
01613   mcEvent.q2 = nuEvent.q2MC;
01614   mcEvent.w2 = nuEvent.w2MC;
01615   mcEvent.iaction = nuEvent.iaction;
01616   mcEvent.inu = nuEvent.inu;
01617   mcEvent.iresonance = nuEvent.iresonance;
01618   mcEvent.initial_state = nuEvent.initialStateMC;
01619   mcEvent.nucleus = nuEvent.nucleusMC;
01620   mcEvent.had_fs = nuEvent.hadronicFinalStateMC;
01621   
01622   return mcEvent;
01623 }
01624 
01625 //____________________________________________________________________72
01626 void NuSystematic::SetNeugenDefaults(Registry& registry) const
01627 {
01628   registry.Set("neugen:kno_r112",fkno_r112Default);
01629   registry.Set("neugen:kno_r122",fkno_r122Default);
01630   registry.Set("neugen:kno_r132",fkno_r132Default);
01631   registry.Set("neugen:kno_r142",fkno_r142Default);
01632   registry.Set("neugen:kno_r113",fkno_r113Default);
01633   registry.Set("neugen:kno_r123",fkno_r123Default);
01634   registry.Set("neugen:kno_r133",fkno_r133Default);
01635   registry.Set("neugen:kno_r143",fkno_r143Default);
01636   registry.Set("neugen:ma_qe",fma_qeDefault);
01637   registry.Set("neugen:ma_res",fma_resDefault);
01638   return;
01639 }
01640 
01641 //____________________________________________________________________72
01642 void NuSystematic::SetShiftedNeugenParameters(Registry& registry, const NuEvent event) const
01643 {
01644   Float_t ma_qe = this->MA_QEDefault();
01645   Float_t ma_res = this->MA_ResDefault();
01646   
01647   ma_qe *= ShiftAsValue(NuSyst::kCombinedXSecCCMA);
01648   ma_res *= ShiftAsValue(NuSyst::kCombinedXSecCCMA);
01649   ma_qe *= ShiftAsValue(NuSyst::kCombinedXSecMaQE);
01650   ma_res *= ShiftAsValue(NuSyst::kCombinedXSecMaRes);
01651   
01652   if (event.inu<0) {
01653     ma_qe *= ShiftAsValue(NuSyst::kNuMuBarXSecCCMA);
01654     ma_res *= ShiftAsValue(NuSyst::kNuMuBarXSecCCMA);
01655   }
01656 
01657   registry.Set("neugen:ma_qe",ma_qe);
01658   registry.Set("neugen:ma_res",ma_res);
01659 
01660   Float_t kno112 = this->KNO112Default() + this->ShiftAsValue(NuSyst::kCombinedXSecDISMultip2);
01661   if (kno112<0.0){kno112=0.0;}
01662   if (kno112>1.0){kno112=1.0;}
01663   Float_t kno122 = this->KNO122Default() + this->ShiftAsValue(NuSyst::kCombinedXSecDISMultip2);
01664   if (kno122<0.0){kno122=0.0;}
01665   if (kno122>1.0){kno122=1.0;}
01666   Float_t kno132 = this->KNO132Default() + this->ShiftAsValue(NuSyst::kCombinedXSecDISMultip2);
01667   if (event.inu<0) kno132 += this->ShiftAsValue(NuSyst::kNuMuBarXSecDISMultip2);
01668   if (kno132<0.0){kno132=0.0;}
01669   if (kno132>1.0){kno132=1.0;}
01670   Float_t kno142 = this->KNO142Default() + this->ShiftAsValue(NuSyst::kCombinedXSecDISMultip2);
01671   if (event.inu<0) kno142 += this->ShiftAsValue(NuSyst::kNuMuBarXSecDISMultip2);
01672   if (kno142<0.0){kno142=0.0;}
01673   if (kno142>1.0){kno142=1.0;}
01674   Float_t kno212 = this->KNO212Default() + this->ShiftAsValue(NuSyst::kCombinedXSecDISMultip2);
01675   if (kno212<0.0){kno212=0.0;}
01676   if (kno212>1.0){kno212=1.0;}
01677   Float_t kno222 = this->KNO222Default() + this->ShiftAsValue(NuSyst::kCombinedXSecDISMultip2);
01678   if (kno222<0.0){kno222=0.0;}
01679   if (kno222>1.0){kno222=1.0;}
01680   Float_t kno232 = this->KNO232Default() + this->ShiftAsValue(NuSyst::kCombinedXSecDISMultip2);
01681   if (kno232<0.0){kno232=0.0;}
01682   if (kno232>1.0){kno232=1.0;}
01683   Float_t kno242 = this->KNO242Default() + this->ShiftAsValue(NuSyst::kCombinedXSecDISMultip2);
01684   if (kno242<0.0){kno242=0.0;}
01685   if (kno242>1.0){kno242=1.0;}
01686   registry.Set("neugen:kno_r112",kno112);
01687   registry.Set("neugen:kno_r122",kno122);
01688   registry.Set("neugen:kno_r132",kno132);
01689   registry.Set("neugen:kno_r142",kno142);
01690   registry.Set("neugen:kno_r212",kno212);
01691   registry.Set("neugen:kno_r222",kno222);
01692   registry.Set("neugen:kno_r232",kno232);
01693   registry.Set("neugen:kno_r242",kno242);
01694 
01695   Float_t kno113 = this->KNO113Default() + this->ShiftAsValue(NuSyst::kCombinedXSecDISMultip3);
01696   if (kno113<0.0){kno113=0.0;}
01697   if (kno113>1.0){kno113=1.0;}
01698   Float_t kno123 = this->KNO123Default() + this->ShiftAsValue(NuSyst::kCombinedXSecDISMultip3);
01699   if (kno123<0.0){kno123=0.0;}
01700   if (kno123>1.0){kno123=1.0;}
01701   Float_t kno133 = this->KNO133Default() + this->ShiftAsValue(NuSyst::kCombinedXSecDISMultip3);
01702   if (kno133<0.0){kno133=0.0;}
01703   if (kno133>1.0){kno133=1.0;}
01704   Float_t kno143 = this->KNO143Default() + this->ShiftAsValue(NuSyst::kCombinedXSecDISMultip3);
01705   if (kno143<0.0){kno143=0.0;}
01706   if (kno143>1.0){kno143=1.0;}
01707   Float_t kno213 = this->KNO213Default() + this->ShiftAsValue(NuSyst::kCombinedXSecDISMultip3);
01708   if (kno213<0.0){kno213=0.0;}
01709   if (kno213>1.0){kno213=1.0;}
01710   Float_t kno223 = this->KNO223Default() + this->ShiftAsValue(NuSyst::kCombinedXSecDISMultip3);
01711   if (kno223<0.0){kno223=0.0;}
01712   if (kno223>1.0){kno223=1.0;}
01713   Float_t kno233 = this->KNO233Default() + this->ShiftAsValue(NuSyst::kCombinedXSecDISMultip3);
01714   if (kno233<0.0){kno233=0.0;}
01715   if (kno233>1.0){kno233=1.0;}
01716   Float_t kno243 = this->KNO243Default() + this->ShiftAsValue(NuSyst::kCombinedXSecDISMultip3);
01717   if (kno243<0.0){kno243=0.0;}
01718   if (kno243>1.0){kno243=1.0;}
01719   registry.Set("neugen:kno_r113",kno113);
01720   registry.Set("neugen:kno_r123",kno123);
01721   registry.Set("neugen:kno_r133",kno133);
01722   registry.Set("neugen:kno_r143",kno143);
01723   registry.Set("neugen:kno_r213",kno213);
01724   registry.Set("neugen:kno_r223",kno223);
01725   registry.Set("neugen:kno_r233",kno233);
01726   registry.Set("neugen:kno_r243",kno243);
01727 }
01728 
01729 //____________________________________________________________________72
01730 void NuSystematic::SetShiftedNeugenParameters(neugen_config& config, const NuEvent event) const
01731 {
01732   Float_t ma_qe = this->MA_QEDefault();
01733   Float_t ma_res = this->MA_ResDefault();
01734   
01735   ma_qe *= ShiftAsValue(NuSyst::kCombinedXSecCCMA);
01736   ma_res *= ShiftAsValue(NuSyst::kCombinedXSecCCMA);
01737   ma_qe *= ShiftAsValue(NuSyst::kCombinedXSecMaQE);
01738   ma_res *= ShiftAsValue(NuSyst::kCombinedXSecMaRes);
01739   
01740   if (event.inu<0) {
01741     ma_qe *= ShiftAsValue(NuSyst::kNuMuBarXSecCCMA);
01742     ma_res *= ShiftAsValue(NuSyst::kNuMuBarXSecCCMA);
01743   }
01744   
01745   config.set_ma_qe(ma_qe);
01746   config.set_ma_res(ma_res);
01747   
01748   Float_t kno112 = this->KNO112Default() + this->ShiftAsValue(NuSyst::kCombinedXSecDISMultip2);
01749   if (kno112<0.0){kno112=0.0;}
01750   if (kno112>1.0){kno112=1.0;}
01751   Float_t kno122 = this->KNO122Default() + this->ShiftAsValue(NuSyst::kCombinedXSecDISMultip2);
01752   if (kno122<0.0){kno122=0.0;}
01753   if (kno122>1.0){kno122=1.0;}
01754   Float_t kno132 = this->KNO132Default() + this->ShiftAsValue(NuSyst::kCombinedXSecDISMultip2);
01755   if (event.inu<0) kno132 += this->ShiftAsValue(NuSyst::kNuMuBarXSecDISMultip2);
01756   if (kno132<0.0){kno132=0.0;}
01757   if (kno132>1.0){kno132=1.0;}
01758   Float_t kno142 = this->KNO142Default() + this->ShiftAsValue(NuSyst::kCombinedXSecDISMultip2);
01759   if (event.inu<0) kno142 += this->ShiftAsValue(NuSyst::kNuMuBarXSecDISMultip2);
01760   if (kno142<0.0){kno142=0.0;}
01761   if (kno142>1.0){kno142=1.0;}
01762   Float_t kno212 = this->KNO212Default() + this->ShiftAsValue(NuSyst::kCombinedXSecDISMultip2);
01763   if (kno212<0.0){kno212=0.0;}
01764   if (kno212>1.0){kno212=1.0;}
01765   Float_t kno222 = this->KNO222Default() + this->ShiftAsValue(NuSyst::kCombinedXSecDISMultip2);
01766   if (kno222<0.0){kno222=0.0;}
01767   if (kno222>1.0){kno222=1.0;}
01768   Float_t kno232 = this->KNO232Default() + this->ShiftAsValue(NuSyst::kCombinedXSecDISMultip2);
01769   if (kno232<0.0){kno232=0.0;}
01770   if (kno232>1.0){kno232=1.0;}
01771   Float_t kno242 = this->KNO242Default() + this->ShiftAsValue(NuSyst::kCombinedXSecDISMultip2);
01772   if (kno242<0.0){kno242=0.0;}
01773   if (kno242>1.0){kno242=1.0;}
01774   config.set_dis_res(1,2,e_vp,kno112);
01775   config.set_dis_res(1,2,e_vn,kno122);
01776   config.set_dis_res(1,2,e_vbp,kno132);
01777   config.set_dis_res(1,2,e_vbn,kno142);
01778   config.set_dis_res(2,2,e_vp,kno212);
01779   config.set_dis_res(2,2,e_vn,kno222);
01780   config.set_dis_res(2,2,e_vbp,kno232);
01781   config.set_dis_res(2,2,e_vbn,kno242);
01782   
01783   Float_t kno113 = this->KNO113Default() + this->ShiftAsValue(NuSyst::kCombinedXSecDISMultip3);
01784   if (kno113<0.0){kno113=0.0;}
01785   if (kno113>1.0){kno113=1.0;}
01786   Float_t kno123 = this->KNO123Default() + this->ShiftAsValue(NuSyst::kCombinedXSecDISMultip3);
01787   if (kno123<0.0){kno123=0.0;}
01788   if (kno123>1.0){kno123=1.0;}
01789   Float_t kno133 = this->KNO133Default() + this->ShiftAsValue(NuSyst::kCombinedXSecDISMultip3);
01790   if (kno133<0.0){kno133=0.0;}
01791   if (kno133>1.0){kno133=1.0;}
01792   Float_t kno143 = this->KNO143Default() + this->ShiftAsValue(NuSyst::kCombinedXSecDISMultip3);
01793   if (kno143<0.0){kno143=0.0;}
01794   if (kno143>1.0){kno143=1.0;}
01795   Float_t kno213 = this->KNO213Default() + this->ShiftAsValue(NuSyst::kCombinedXSecDISMultip3);
01796   if (kno213<0.0){kno213=0.0;}
01797   if (kno213>1.0){kno213=1.0;}
01798   Float_t kno223 = this->KNO223Default() + this->ShiftAsValue(NuSyst::kCombinedXSecDISMultip3);
01799   if (kno223<0.0){kno223=0.0;}
01800   if (kno223>1.0){kno223=1.0;}
01801   Float_t kno233 = this->KNO233Default() + this->ShiftAsValue(NuSyst::kCombinedXSecDISMultip3);
01802   if (kno233<0.0){kno233=0.0;}
01803   if (kno233>1.0){kno233=1.0;}
01804   Float_t kno243 = this->KNO243Default() + this->ShiftAsValue(NuSyst::kCombinedXSecDISMultip3);
01805   if (kno243<0.0){kno243=0.0;}
01806   if (kno243>1.0){kno243=1.0;}
01807   config.set_dis_res(1,3,e_vp,kno113);
01808   config.set_dis_res(1,3,e_vn,kno123);
01809   config.set_dis_res(1,3,e_vbp,kno133);
01810   config.set_dis_res(1,3,e_vbn,kno143);
01811   config.set_dis_res(2,3,e_vp,kno213);
01812   config.set_dis_res(2,3,e_vn,kno223);
01813   config.set_dis_res(2,3,e_vbp,kno233);
01814   config.set_dis_res(2,3,e_vbn,kno243);
01815 }
01816 
01817 
01818 
01819 
01821 // Xsec Shift Functions //
01823 
01824 //____________________________________________________________________72
01825 const Double_t NuSystematic
01826 ::XSecShiftScale(const Double_t energy,
01827                  const NuParticle::NuParticleType_t particle) const
01828 {
01829   if (!(NuParticle::kNuMu == particle || NuParticle::kNuMuBar == particle)){
01830     MSG("NuSystematic.cxx",Msg::kWarning)
01831       << "I don't know how to systematically shift this particle"
01832       << endl;
01833     return 1.0;
01834   }
01835 
01836   if (CurrentSigma(NuSyst::kCombinedXSecOverall)){
01837     return this->ShiftAsValue(NuSyst::kCombinedXSecOverall);
01838   }
01839   else if (CurrentSigma(NuSyst::kNuMuBarXSecOverall)){
01840     if (NuParticle::kNuMuBar == particle){
01841       return this->ShiftAsValue(NuSyst::kNuMuBarXSecOverall);
01842     }
01843     else {
01844       return 1.0;
01845     }
01846   }
01847   else if (CurrentSigma(NuSyst::kNuMuBarXSecCCMA) ||
01848            CurrentSigma(NuSyst::kNuMuBarXSecDISMultip2)){
01849     if (NuParticle::kNuMuBar != particle){
01850       return 1.0;
01851     }
01852     else {return this->NeugenXSecShiftScale(energy,particle);}
01853   }
01854   else if(CurrentSigma(NuSyst::kCombinedXSecCCMA) ||
01855           CurrentSigma(NuSyst::kCombinedXSecDISMultip2) ||
01856           CurrentSigma(NuSyst::kCombinedXSecDISMultip3)){
01857     if (!(NuParticle::kNuMu == particle || NuParticle::kNuMuBar == particle)){
01858       return 1.0;
01859     }
01860     else if(CurrentSigma(NuSyst::kNuMuBarXSecQEL)){
01861       return this->QELXSecShiftScale(energy,particle);
01862     }
01863     else if (CurrentSigma(NuSyst::kNuMuBarXSecRes)){
01864       return this->ResXSecShiftScale(energy,particle);
01865     }
01866     else {return this->NeugenXSecShiftScale(energy,particle);}
01867   }
01868   else {return 1.0;}
01869 }
01870 
01871 //____________________________________________________________________72
01872 const Double_t NuSystematic
01873 ::QELXSecShiftScale(const Double_t energy,
01874                     const NuParticle::NuParticleType_t particle)
01875   const 
01876 {
01877   neugen_config defaultConfig;
01878   neugen_wrapper defaultWrapper(&defaultConfig);
01879   init_state_t inlStateP;
01880   init_state_t inlStateN;
01881   if (NuParticle::kNuMu == particle){
01882     inlStateP = e_vp;
01883     inlStateN = e_vn;
01884   }
01885   else if (NuParticle::kNuMuBar == particle){
01886     inlStateP = e_vbp;
01887     inlStateN = e_vbn;
01888   }
01889   else{
01890     MSG("NuSystematic.cxx",kWarning)
01891       << "Bad particle type for cross section shift."
01892       << endl;
01893     inlStateP = e_undefined_init_state;
01894     inlStateN = e_undefined_init_state;
01895   }
01896   interaction interP(e_mu,e_Fe56,e_cc,inlStateP);
01897   interaction interN(e_mu,e_Fe56,e_cc,inlStateP);
01898   Double_t defaultXSec = defaultWrapper.xsec(energy,&interP,0);
01899   defaultXSec += defaultWrapper.xsec(energy,&interN,0);
01900 
01901   neugen_cuts cuts;
01902   cuts.setOneProcess(e_qel);
01903   Double_t qelXSec = defaultWrapper.xsec(energy,&interP,&cuts);
01904   qelXSec += defaultWrapper.xsec(energy,&interN,&cuts);
01905 
01906   if (!defaultXSec){return 1.0;}
01907   return (defaultXSec + (this->ShiftAsValue(NuSyst::kNuMuBarXSecQEL) - 1.0)*qelXSec)/defaultXSec;
01908 }
01909 
01910 //____________________________________________________________________72
01911 const Double_t NuSystematic
01912 ::ResXSecShiftScale(const Double_t energy,
01913                     const NuParticle::NuParticleType_t particle)
01914   const 
01915 {
01916   neugen_config defaultConfig;
01917   neugen_wrapper defaultWrapper(&defaultConfig);
01918   init_state_t inlStateP;
01919   init_state_t inlStateN;
01920   if (NuParticle::kNuMu == particle){
01921     inlStateP = e_vp;
01922     inlStateN = e_vn;
01923   }
01924   else if (NuParticle::kNuMuBar == particle){
01925     inlStateP = e_vbp;
01926     inlStateN = e_vbn;
01927   }
01928   else{
01929     MSG("NuSystematic.cxx",kWarning)
01930       << "Bad particle type for cross section shift."
01931       << endl;
01932     inlStateP = e_undefined_init_state;
01933     inlStateN = e_undefined_init_state;
01934   }
01935   interaction interP(e_mu,e_Fe56,e_cc,inlStateP);
01936   interaction interN(e_mu,e_Fe56,e_cc,inlStateP);
01937   Double_t defaultXSec = defaultWrapper.xsec(energy,&interP,0);
01938   defaultXSec += defaultWrapper.xsec(energy,&interN,0);
01939 
01940   neugen_cuts cuts;
01941   cuts.setOneProcess(e_res);
01942   Double_t qelXSec = defaultWrapper.xsec(energy,&interP,&cuts);
01943   qelXSec += defaultWrapper.xsec(energy,&interN,&cuts);
01944 
01945   if (!defaultXSec){return 1.0;}
01946   return (defaultXSec + (this->ShiftAsValue(NuSyst::kNuMuBarXSecRes) - 1.0)*qelXSec)/defaultXSec;
01947 }
01948 
01949 //____________________________________________________________________72
01950 const Double_t NuSystematic
01951 ::NeugenXSecShiftScale(const Double_t energy,
01952                        const NuParticle::NuParticleType_t particle) const
01953 {
01954   NuEvent event;
01955   if (NuParticle::kNuMuBar == particle) event.inu = -14;
01956   else                                  event.inu = 14;
01957 
01958   neugen_config shiftedConfig; //Defaults are MODBYRS4
01959   this->SetShiftedNeugenParameters(shiftedConfig, event);
01960   neugen_config defaultConfig;
01961   neugen_wrapper shiftedWrapper(&shiftedConfig);
01962   neugen_wrapper defaultWrapper(&defaultConfig);
01963   init_state_t inlStateP;
01964   init_state_t inlStateN;
01965   if (NuParticle::kNuMu == particle){
01966     inlStateP = e_vp;
01967     inlStateN = e_vn;
01968   }
01969   else if (NuParticle::kNuMuBar == particle){
01970     inlStateP = e_vbp;
01971     inlStateN = e_vbn;
01972   }
01973   else{
01974     MSG("NuSystematic.cxx",kWarning)
01975       << "Bad particle type for cross section shift."
01976       << endl;
01977     inlStateP = e_undefined_init_state;
01978     inlStateN = e_undefined_init_state;
01979   }
01980   interaction interP(e_mu,e_Fe56,e_cc,inlStateP);
01981   interaction interN(e_mu,e_Fe56,e_cc,inlStateP);
01982   Double_t defaultXSec = defaultWrapper.xsec(energy,&interP,0);
01983   defaultXSec += defaultWrapper.xsec(energy,&interN,0);
01984   Double_t shiftedXSec = shiftedWrapper.xsec(energy,&interP,0);
01985   shiftedXSec = shiftedWrapper.xsec(energy,&interN,0);
01986   if (defaultXSec){return shiftedXSec/defaultXSec;}
01987   else {return 0;}
01988 }
01989 
01990 
01991 

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