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

do_extrap.h

Go to the documentation of this file.
00001 #ifndef __CINT__
00002 
00003 #include "MCReweight/MCReweight.h"
00004 #include "MCReweight/NeugenWeightCalculator.h"
00005 #include "NCUtils/Extrapolation/NCExtrapolationModule.h"
00006 
00007 #include "NCUtils/NCOscProb.h"
00008 #include "NCUtils/NCType.h"
00009 
00010 #include "TString.h"
00011 
00012 #include <iostream>
00013 
00014 enum EFitType {
00015   kRealData,
00016   kFakeData,
00017   kFakeDataSplitMC,
00018   kMockData
00019 };
00020 
00021 // The Module and its Registry as globals so they don't need to be
00022 // passed to all the functions
00023 NCExtrapolationModule extrapMod;
00024 Registry reg;
00025 
00026 // =====================================================================
00027 //         Utility functions
00028 // =====================================================================
00029 
00030 TString add_to_output_name(TString s, bool appendSep=true)
00031 {
00032   static TString outputName;
00033   outputName.Append(s);
00034   if (appendSep) outputName.Append("_");
00035 
00036   return outputName;
00037 }
00038 
00039 // =====================================================================
00040 //        Basics
00041 // =====================================================================
00042 
00043 void set_msg_levels()
00044 {
00045   MsgService* m=MsgService::Instance();
00046   m->GetStream("NCExtrapolationModule")->SetLogLevel(Msg::kInfo);
00047   m->GetStream("NCAnalysisCuts")->SetLogLevel(Msg::kInfo);
00048   m->GetStream("NCUtils")->SetLogLevel(Msg::kInfo);
00049   //m->GetStream("NCExtrapolation"->SetLogLevel(Msg::kInfo);
00050   //m->GetStream("MinosMinimization"->SetLogLevel(Msg::kDebug);
00051   m->GetStream("Registry")->SetLogLevel(Msg::kFatal);
00052 }
00053 
00054 void set_beam_types(TString beamTypes)
00055 {
00056   reg.Set("BeamType", beamTypes);
00057 }
00058 
00059 void set_weight_config()
00060 {
00061   //default is PiMinus_CedarDaikon
00062   reg.Set("MEGAWeightConfig", "PiMinus_CedarDaikon");
00063 }
00064 
00065 
00066 void set_near_run_limits(int dataLimit, int mcLimit)
00067 {
00068   reg.Set("RunLimitNearData", dataLimit);
00069   reg.Set("RunLimitNearMC",   mcLimit);
00070 }
00071 
00072 void set_far_run_limits(int dataLimit, int mcLimit)
00073 {
00074   reg.Set("RunLimitFarData", dataLimit);
00075   reg.Set("RunLimitFarMC",   mcLimit);
00076 }
00077 
00078 void set_run_to_use(int run)
00079 {
00080   //set which runs to use - see NCRunUtil.h for the numbering
00081   reg.Set("RunToUse", run);
00082 }
00083 
00084 // =====================================================================
00085 //        General settings
00086 // =====================================================================
00087 void set_data_mc_type(EFitType fitType,
00088                       int mockDataRun=-1,
00089                       /* -1 mock data subrun means "use all subruns",
00090                          so use -2 as default */
00091                       int mockDataSubRun=-2)
00092 {
00093 
00094   if (fitType!=kMockData &&
00095       (mockDataRun!=-1 || mockDataSubRun!=-2))
00096     assert(0 && "Mock data parameters set when fit type is not mock data");
00097 
00098   if (fitType==kMockData &&
00099       (mockDataRun==-1 || mockDataSubRun==-2))
00100     assert(0 && "Mock data parameters not set when fit type is mock data");
00101 
00102   switch (fitType) {
00103   case kRealData:
00104     reg.Set("UseMCAsData", false);
00105     reg.Set("UseMockData", false);
00106     add_to_output_name("data");
00107     break;
00108   case kFakeData:
00109     reg.Set("UseMCAsData", true);
00110     reg.Set("UseMockData", false);
00111     reg.Set("SplitMC",     false);
00112     add_to_output_name("mconly");
00113     break;
00114   case kFakeDataSplitMC:
00115     reg.Set("UseMCAsData", true);
00116     reg.Set("UseMockData", false);
00117     reg.Set("SplitMC",     true);
00118     add_to_output_name("splitmc");
00119     break;
00120   case kMockData:
00121     reg.Set("UseMCAsData", false);
00122     reg.Set("UseMockData", true);
00123     reg.Set("MockDataSet", Form("F%d", mockDataRun));
00124     reg.Set("MockDataSubRun", mockDataSubRun);
00125     add_to_output_name("mock");
00126     add_to_output_name(Form("run%d", mockDataRun));
00127     add_to_output_name(Form("%d", mockDataSubRun));
00128     break;
00129   default:
00130     assert(0 && "Invalid fit type");
00131   }
00132 }
00133 
00134 void set_data_mc_path(TString uDSTDir)
00135 {
00136   reg.Set("DataMCPath", uDSTDir);
00137 }
00138 
00139 void set_mc_exposure_for_beam(BeamType::BeamType_t beamType, NC::RunUtil::ERunType run, double pot)
00140 {
00141   extrapMod.SetMCExposureForBeam(NCBeam::Info(beamType, run), pot);
00142 }
00143 
00144 void set_extraction(TString name)
00145 {
00146   // Add a dot at the end if we missed it
00147   if (!name.EndsWith(".")) name+=".";
00148 
00149   // pick the extraction to use - use only 1 at a time
00150   // in this module.
00151   //Loop through extractions and use the one we want
00152   for (Int_t i = 0; i < NCType::kNumExtractions; ++i){
00153     if(name == NCType::kExtractionNames[i]){
00154       reg.Set("ExtractionType", i);
00155       return;
00156     }
00157   }
00158 
00159   assert(0 && "Specified extraction not found");
00160 }
00161 
00162 void set_use_custom_pid_cut_and_value(bool useCustom,
00163                                       float value=-9999)
00164 {
00165   reg.Set("UsePIDCustomCut", useCustom);
00166   if (useCustom)
00167     reg.Set("PIDCustomCut", value);
00168 }
00169 
00170 void set_prediction(bool makePred, bool writeFDData=false)
00171 {
00172   reg.Set("Prediction", makePred);
00173   if(writeFDData) reg.Set("PredictionWriteData", writeFDData);
00174 }
00175 
00176 
00177 // =====================================================================
00178 //          Systematics-related stuff
00179 // =====================================================================
00180 
00181 void set_syst_study_params(bool doSystStudy, float shiftInSigma)
00182 {
00183   //Whether or not to do syst study.
00184   //If true, Adjust conditions are ignored in favor of SystShift(sigma).
00185   reg.Set("DoSystStudy", doSystStudy);
00186   reg.Set("SystShift", shiftInSigma);
00187 }
00188 
00189 void turn_off_systematic_params()
00190 {
00191   // This is mostly copy-pasted from NCExtrapolationModule, so we don't
00192   // actually *have* to do it. Anyway, it doesn't hurt to make it
00193   // explicit in the macro
00194 
00195   TString adjust   = "Adjust";
00196   TString mcAsData = "ChangeMCAsData";
00197   TString fit      = "Fit";
00198   for(int i = 0; i < NCType::kNumSystematicParameters; ++i){
00199     reg.Set(NCType::kParams[i].name,         false);
00200     reg.Set(mcAsData + NCType::kParams[i].name, false);
00201     reg.Set(fit + NCType::kParams[i].name,      false);
00202   }
00203 }
00204 
00205 // No adjustment value given, so will use the value of "SystShift"
00206 void adjust_systematic(NCType::EFitParam syst)
00207 {
00208   reg.Set("ChangeMCAsData"+NCType::kParams[syst].name, true);
00209 }
00210 
00211 void adjust_systematic(NCType::EFitParam syst, float adjVal)
00212 {
00213   reg.Set("ChangeMCAsData"+NCType::kParams[syst].name, true);
00214   reg.Set("Adjust"+NCType::kParams[syst].name, adjVal);
00215 }
00216 
00217 void fit_systematic(NCType::EFitParam syst)
00218 {
00219   reg.Set("Fit"+NCType::kParams[syst].name, true);
00220 }
00221 
00222 // =====================================================================
00223 //        Oscillation and fitter things
00224 // =====================================================================
00225 
00226 TString get_model_short_name(NCType::EOscModel m)
00227 {
00228   switch(m) {
00229   case NCType::kThreeFlavor: return "3flavor";
00230   case NCType::kNoOscillations: return "noOsc";
00231   case NCType::kFourFlavorGeneral: return "4flavorGen";
00232   case NCType::kFourFlavorDelta43IsBig: return "delta43IsBig";
00233   case NCType::kFourFlavorDelta41Is0: return "delta41Is0";
00234   case NCType::kFourFlavorDelta43Is0: return "delta43Is0";
00235   case NCType::kSterileFraction: return "sFrac";
00236   case NCType::kDecay: return "decay";
00237   case NCType::kDecoherence: return "decoherence";
00238   default:
00239     assert(0 && "Unknown oscmodel");
00240     return "Unknown";
00241   }
00242 }
00243 
00244 TString get_param_string(NCType::EFitParam p)
00245 {
00246   switch(p) {
00247   case NCType::kUE3Sqr:  return "UE3Sqr";
00248   case NCType::kTheta13: return "Theta13";
00249   case NCType::kDelta1:  return "Delta1";
00250   case NCType::kDelta2:  return "Delta2";
00251   case NCType::kTheta14: return "Theta14";
00252   case NCType::kTheta24: return "Theta24";
00253   case NCType::kTheta23: return "Theta23";
00254   case NCType::kFs:      return "Fs";
00255   default:
00256     assert(0 && "No String for parameter");
00257     return "Unknown";
00258   }
00259 
00260 }
00261 
00262 void fit_osc_param(NCType::EFitParam p)
00263 {
00264   const TString paramString=get_param_string(p);
00265   reg.Set("Fit"+paramString, true);
00266 }
00267 
00268 void fix_osc_param(NCType::EFitParam p, double value)
00269 {
00270   const TString paramString=get_param_string(p);
00271   reg.Set("Fit"+paramString, false);
00272   reg.Set(paramString+"Val", value);
00273 }
00274 
00275 void set_osc_pars(NC::OscProb::OscPars* oscPars)
00276 {
00277   assert(sizeof(oscPars) == sizeof(int));
00278   reg.Set("OscPars", int(oscPars));
00279   add_to_output_name(get_model_short_name(oscPars->OscillationModel()));
00280 }
00281 
00282 void set_model_to_fit(NCType::EOscModel m)
00283 {
00284   reg.Set("OscillationModel", int(m));
00285   add_to_output_name(get_model_short_name(m)+"Fit");
00286 }
00287 
00288 void use_fitter_confidence(int confidenceLevel, bool wanted=true)
00289 {
00290   assert(confidenceLevel==68 || confidenceLevel==90 || confidenceLevel==99);
00291   reg.Set(Form("LazyContoursWant%d", confidenceLevel), wanted);
00292 }
00293 
00294 void set_fitter_params(float precScale=1.)
00295 {
00296   use_fitter_confidence(68);
00297   use_fitter_confidence(90);
00298   use_fitter_confidence(99, false);
00299 
00300   reg.Set("PrecScale", precScale);
00301 }
00302 
00303 void add_contour(NCType::EFitParam x, NCType::EFitParam y)
00304 {
00305   static TString contoursList("");
00306   contoursList+=Form("(%d,%d) ", x, y);
00307 
00308   reg.Set("ContoursList", contoursList);
00309 }
00310 
00311 void add_projection(NCType::EFitParam proj)
00312 {
00313   static TString projsList;
00314   projsList += TString::Format("%d ", proj);
00315   reg.Set("ProjectionsList", projsList);
00316 }
00317 
00318 void do_syst_interpolation(bool interp)
00319 {
00320   reg.Set("DoSystematicInterpolation", interp);
00321 }
00322 
00323 void make_shifted_beams(bool make)
00324 {
00325   reg.Set("MakeShiftedBeams", make);
00326   reg.Set("ShiftedBeamsSimpleOnly", make);
00327 }
00328 
00329 void force_best_fit_to_truth(bool force)
00330 {
00331   reg.Set("ForceBestFitToTruth", force);
00332 }
00333 
00334 // =====================================================================
00335 //       Extrapolation settings
00336 // =====================================================================
00337 
00338 void farnear_smooth_width(double smoothingWidth)
00339 {
00340   reg.Set("FarNearSmoothingWidth", smoothingWidth);
00341 }
00342 
00343 void pid_emulate_farnear(bool emulate)
00344 {
00345   reg.Set("PIDFitEmulateFarNear", emulate);
00346 }
00347 
00348 void pid_true_bin_factor(int factor)
00349 {
00350   reg.Set("PIDFitTrueBinFactor", factor);
00351 }
00352 
00353 void pid_binning(int nbins, double minpid, double maxpid)
00354 {
00355   // Number of bins in PID to use
00356   reg.Set("PIDFitPIDNbins",          nbins);
00357   // Minimum, maximum value of PID
00358   reg.Set("PIDFitPIDmin",          minpid);
00359   reg.Set("PIDFitPIDmax",          maxpid);
00360 }
00361 
00362 // =====================================================================
00363 //       Miscellaneous
00364 // =====================================================================
00365 void add_neugen_weight_calculator()
00366 {
00367   MCReweight &mcReweight = MCReweight::Instance();
00368   NeugenWeightCalculator *fNeugenWeightCal = new NeugenWeightCalculator;
00369   mcReweight.AddWeightCalculator(fNeugenWeightCal);
00370 }
00371 
00372 void run()
00373 {
00374 
00375   // Add the .root to the end of the output filename and set it in the module
00376   reg.Set("FileName", add_to_output_name(".root", false));
00377 
00378   add_neugen_weight_calculator();
00379 
00380   Registry def = extrapMod.DefaultConfig();
00381   def.UnLockValues();
00382 
00383   def.Merge(reg);
00384   extrapMod.Config(def);
00385 
00386   extrapMod.Run();
00387 }
00388 
00389 #endif

Generated on Mon Feb 15 11:06:38 2010 for loon by  doxygen 1.3.9.1