00001
00002
00003
00004
00005
00006
00007
00008
00010
00011 #include "NCUtils/Extrapolation/NCExtrapolationDP.h"
00012 #include "MessageService/MsgService.h"
00013 #include "AnalysisNtuples/ANtpAnalysisInfo.h"
00014 #include "AnalysisNtuples/ANtpBeamInfo.h"
00015 #include "AnalysisNtuples/ANtpRecoInfo.h"
00016 #include "AnalysisNtuples/ANtpHeaderInfo.h"
00017 #include "AnalysisNtuples/ANtpTruthInfoBeam.h"
00018
00019 #include "TCanvas.h"
00020 #include "TGraphErrors.h"
00021 #include "TMath.h"
00022 #include "TStopwatch.h"
00023
00024 #include <cassert>
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 static const int kNorm = 0;
00042 static const int kEshower = 1;
00043 static const int kEmu = 2;
00044 static const int kMA_QE = 3;
00045 static const int kMA_RES = 4;
00046 static const int kdisfact = 5;
00047 static const int kBeam1 = 6;
00048 static const int kBeam2 = 7;
00049 static const int kBeam3 = 8;
00050 static const int kBeam4 = 9;
00051 static const int kBeam5 = 10;
00052 static const int kReco = 11;
00053 static const int knc = 12;
00054 static TString kParNames[13] = {"Normalization", "E_shower",
00055 "E_muon", "ma_qe", "ma_res",
00056 "DISFACT", "Beam 1", "Beam 2",
00057 "Beam 3", "Beam 4", "Beam 5",
00058 "Reco", "NC"};
00059
00060 using namespace NCType;
00061
00062 CVSID("$Id: NCExtrapolationDP.cxx,v 1.35 2008/01/11 15:53:31 bckhouse Exp $");
00063
00064
00065 NCExtrapolationDP::NCExtrapolationDP() :
00066 NCExtrapolation::NCExtrapolation()
00067 {
00068 }
00069
00070
00071 NCExtrapolationDP::NCExtrapolationDP(NCAnalysisUtils *utils,
00072 std::map<Int_t,double>& dataNear,
00073 std::map<Int_t,double>& mcNear,
00074 std::map<Int_t,double>& dataFar,
00075 std::map<Int_t,double>& mcFar,
00076 bool useCC,
00077 bool useNC) :
00078 NCExtrapolation(utils, dataNear, mcNear, dataFar, mcFar, useCC, useNC)
00079 {
00080 fExtrapolationType = NCType::kExtrapolationDP;
00081 fsys = 0;
00082 }
00083
00084
00085 NCExtrapolationDP::~NCExtrapolationDP()
00086 {
00087 }
00088
00089
00090
00091
00092
00093 void NCExtrapolationDP::Prepare(const Registry& r)
00094 {
00095
00096 NCExtrapolation::Prepare(r);
00097
00098 int tmpi;
00099 double tmpd;
00100 if(r.Get("Systematics", tmpi)) fsys = tmpi;
00101 if(r.Get("FarPOT", tmpd)) fpot = tmpd;
00102 if(r.Get("MaxFarEReco", tmpd)) fMaxFarEReco = tmpd;
00103
00104 double y0[5]={0,0.25,0.5,0.75,1};
00105
00106 fnom = new TH2F("maqenom","", NCType::kNumEnergyBinsNear,NCType::kEnergyBinsNear,4,y0);
00107 fmaqewgt = new TH2F("maqewgt","", NCType::kNumEnergyBinsNear,NCType::kEnergyBinsNear,4,y0);
00108 fmareswgt = new TH2F("mareswgt","", NCType::kNumEnergyBinsNear,NCType::kEnergyBinsNear,4,y0);
00109 fdisfactwgt = new TH2F("disfactwgt","", NCType::kNumEnergyBinsNear,NCType::kEnergyBinsNear,4,y0);
00110
00111 fnomcc=new TH1F("maqenomcc","",NCType::kNumEnergyBinsNear,NCType::kEnergyBinsNear);
00112 fmaqewgtcc=new TH1F("maqewgtcc","",NCType::kNumEnergyBinsNear,NCType::kEnergyBinsNear);
00113 fmareswgtcc=new TH1F("mareswgtcc","",NCType::kNumEnergyBinsNear,NCType::kEnergyBinsNear);
00114 fdisfactwgtcc=new TH1F("disfactwgtcc","",NCType::kNumEnergyBinsNear,NCType::kEnergyBinsNear);
00115
00116 fnomnc=new TH1F("maqenomnc","",NCType::kNumEnergyBinsNear,NCType::kEnergyBinsNear);
00117 fmaqewgtnc=new TH1F("maqewgtnc","",NCType::kNumEnergyBinsNear,NCType::kEnergyBinsNear);
00118 fmareswgtnc=new TH1F("mareswgtnc","",NCType::kNumEnergyBinsNear,NCType::kEnergyBinsNear);
00119 fdisfactwgtnc=new TH1F("disfactwgtnc","",NCType::kNumEnergyBinsNear,NCType::kEnergyBinsNear);
00120
00121 fdata=new TH1D("data","",NCType::kNumEnergyBinsNear,NCType::kEnergyBinsNear);
00122 fdatanc=new TH1D("datanc","",NCType::kNumEnergyBinsNear,NCType::kEnergyBinsNear);
00123
00124 fmcnomcc=new TH1D("mcnomcc","",NCType::kNumEnergyBinsNear,NCType::kEnergyBinsNear);
00125 fmcbfcc=new TH1D("mcbfcc","",NCType::kNumEnergyBinsNear,NCType::kEnergyBinsNear);
00126 fmtempcc=new TH1D("mtempcc","",NCType::kNumEnergyBinsNear,NCType::kEnergyBinsNear);
00127
00128 fmcnomnc=new TH1D("mcnomnc","",NCType::kNumEnergyBinsNear,NCType::kEnergyBinsNear);
00129 fmcbfnc=new TH1D("mcbfnc","",NCType::kNumEnergyBinsNear,NCType::kEnergyBinsNear);
00130 fmtempnc=new TH1D("mtempnc","",NCType::kNumEnergyBinsNear,NCType::kEnergyBinsNear);
00131
00132 for (int x=0;x<21*21;x++) {
00133 for (int y=0;y<NCType::kNumEnergyBinsNear;y++) {
00134
00135 fncvcc[x][y]=0;
00136 fncvnc[x][y]=0;
00137
00138 for (int z=0;z<4;z++) {
00139
00140 fvexp[x][y][z] = 0.;
00141 fvnc[x][y][z] = 0.;
00142
00143 }
00144 }
00145 }
00146
00147 for (int i=0;i<NCType::kNumEnergyBinsFar;i++) {
00148 fobsall[0][i] = 0.;
00149 fobsall[1][i] = 0.;
00150 }
00151
00152 return;
00153 }
00154
00155
00156 void NCExtrapolationDP::AddEvent(ANtpHeaderInfo *headerInfo,
00157 ANtpBeamInfo *beamInfo,
00158 ANtpRecoInfo *recoInfo,
00159 ANtpAnalysisInfo *analysisInfo,
00160 ANtpTruthInfoBeam *truthInfo,
00161 int runType,
00162 bool useMCAsData,
00163 int fileType)
00164 {
00165
00166
00167
00168
00169
00170
00171 if(beamInfo->beamType != BeamType::ToZarko(BeamType::kL010z185i)
00172 || recoInfo->inFiducialVolume < 1
00173 || recoInfo->nuEnergy > NCType::kMaxEnergy) return;
00174
00175 if(headerInfo->detector == (int)Detector::kNear)
00176 AddNearEvent(headerInfo, beamInfo, recoInfo, analysisInfo,
00177 truthInfo, runType, useMCAsData, fileType);
00178
00179 if(headerInfo->detector == (int)Detector::kFar)
00180 AddFarEvent(headerInfo, beamInfo, recoInfo, analysisInfo,
00181 truthInfo, runType, useMCAsData, fileType);
00182
00183 return;
00184 }
00185
00186
00187 void NCExtrapolationDP::AddNearEvent(ANtpHeaderInfo *headerInfo,
00188 ANtpBeamInfo *beamInfo,
00189 ANtpRecoInfo *recoInfo,
00190 ANtpAnalysisInfo *analysisInfo,
00191 ANtpTruthInfoBeam *truthInfo,
00192 int runType,
00193 bool useMCAsData,
00194 int fileType)
00195 {
00196 MSG("NCExtrapolationDP", Msg::kDebug) << fileType << " " << beamInfo->beamType << endl;
00197
00198 NCExtrapolation::AddEvent(headerInfo, beamInfo, recoInfo, analysisInfo,
00199 truthInfo, runType, useMCAsData, fileType);
00200
00201 BeamType::BeamType_t beamType = BeamType::FromZarko(beamInfo->beamType);
00202 int beam = NCExtrapolation::FindBeamIndex(Detector::kNear, beamType, runType);
00203 double scaleFactor = fDataPOTNear[beamInfo->beamType]/fMCPOTNear[beamInfo->beamType];
00204
00205 if(headerInfo->dataType == (int)SimFlag::kMC && !useMCAsData){
00206
00207
00208 vector<bool> useParameters;
00209 vector<double> adjustedValues;
00210
00211 for(int i = 0; i < NCType::kNumNeugenParameters; ++i){
00212 useParameters.push_back(false);
00213 adjustedValues.push_back(NCType::kParameterDefaults[i]);
00214 }
00215
00216 int pars[] = {NCType::kma_qe, NCType::kma_res, NCType::kDISFACT};
00217 double weights[] = {1., 1., 1.};
00218 double shifts[] = {1.15, 1.15, 1.20};
00219
00220 for(int i = 0; i < 3; ++i){
00221 adjustedValues[pars[i]] = shifts[i]*NCType::kParameterDefaults[pars[i]];
00222 useParameters[pars[i]] = true;
00223 weights[i] = fUtils->FindNeugenWeight(useParameters, adjustedValues);
00224 adjustedValues[pars[i]] = NCType::kParameterDefaults[pars[i]];
00225 useParameters[pars[i]] = false;
00226 }
00227
00228
00229
00230
00231 float ehad=0.;
00232 float emu=0.;
00233
00234 float wgtpt=0.;
00235 float wgt2 = 1.;
00236 float prob = 1.;
00237
00238
00239
00240
00241 int esmin=10;
00242 int esmax=11;
00243 int mumin=10;
00244 int mumax=11;
00245 if(fsys==1){
00246 esmin=0;
00247 esmax=21;
00248 mumin=0;
00249 mumax=21;
00250 }
00251 float ehadshift=0.;
00252 float emushift=0.;
00253 float ereco = 0.;
00254 float recoy = 0.;
00255 int b = 0;
00256 int ybin =0;
00257
00258 if(analysisInfo->isNC > 0){
00259
00260 ehad = recoInfo->showerEnergy;
00261 emu = recoInfo->muEnergy;
00262 wgtpt = recoInfo->weight;
00263
00264 wgt2=1;
00265 prob=1.0;
00266 prob*=wgtpt;
00267
00268 fmcnomnc->Fill(ehad+emu,prob);
00269
00270 MAXMSG("NCExtrapolationDP", Msg::kInfo, 10) << "mc " << recoInfo->nuEnergy
00271 << "/" << recoInfo->showerEnergyNC
00272 << "/" << recoInfo->showerEnergy
00273 << " " << recoInfo->muEnergy
00274 << " " << recoInfo->weight
00275 << "/" << prob << endl;
00276
00277 if(truthInfo->interactionType == NCType::kNC){
00278 fmaqewgtnc->Fill(ehad+emu, weights[0]);
00279 fmareswgtnc->Fill(ehad+emu, weights[1]);
00280 fdisfactwgtnc->Fill(ehad+emu, weights[2]);
00281 fnomnc->Fill(ehad+emu);
00282 }
00283 else if(truthInfo->interactionType == NCType::kCC){
00284 fmaqewgtcc->Fill(ehad+emu, weights[0]);
00285 fmareswgtcc->Fill(ehad+emu, weights[1]);
00286 fdisfactwgtcc->Fill(ehad+emu, weights[2]);
00287 fnomcc->Fill(ehad+emu);
00288 }
00289
00290 ehadshift = 0.;
00291 emushift = 0.;
00292
00293 for(int q = esmin; q < esmax; q++){
00294
00295 ehadshift = ehad*(0.8 + q*0.02);
00296
00297 for(int l = mumin; l < mumax; l++){
00298
00299 emushift = emu*(0.9 + l*0.01);
00300
00301 ereco = ehadshift+emushift;
00302
00303 b = FindRecoEnergyBin(ereco, beam);
00304
00305 if(truthInfo->interactionType == NCType::kCC) {
00306 fncvcc[q*21+l][b] += prob;
00307 }
00308
00309 if (truthInfo->interactionType == NCType::kNC) {
00310 fncvnc[q*21+l][b] += prob;
00311 }
00312
00313 }
00314 }
00315 }
00316 else if(analysisInfo->isCC > 0){
00317
00318 ehad = recoInfo->showerEnergy;
00319 if(ehad < 0.) ehad = 0.;
00320 emu = recoInfo->muEnergy;
00321 wgtpt = recoInfo->weight;
00322
00323 wgt2 = 1.;
00324 prob = 1.0;
00325 prob *= wgtpt;
00326
00327 fmcnomcc->Fill(recoInfo->nuEnergy, prob);
00328 fmaqewgt->Fill(recoInfo->nuEnergy, recoInfo->hadronicY, weights[0]);
00329 fmareswgt->Fill(recoInfo->nuEnergy, recoInfo->hadronicY, weights[1]);
00330 fdisfactwgt->Fill(recoInfo->nuEnergy, recoInfo->hadronicY, weights[2]);
00331 fnom->Fill(recoInfo->nuEnergy, recoInfo->hadronicY);
00332
00333 ehadshift = 0.;
00334 emushift = 0.;
00335
00336 for(int q = esmin; q < esmax; q++){
00337
00338 ehadshift = ehad*(0.8 + q*0.02);
00339
00340 for(int l = mumin; l < mumax; l++){
00341
00342 emushift = emu*(0.9+l*0.01);
00343
00344 ereco = ehadshift + emushift;
00345
00346 recoy = ehadshift/ereco;
00347 ybin = TMath::Nint(4*recoy);
00348 if(ybin > 3) ybin = 3;
00349
00350 b = FindRecoEnergyBin(ereco, beam);
00351
00352 fvexp[q*21+l][b][ybin] += prob*scaleFactor;
00353
00354 if (truthInfo->interactionType == NCType::kNC) {
00355 fvnc[q*21+l][b][ybin] += prob*scaleFactor;
00356 }
00357 }
00358 }
00359 }
00360 }
00361 else if(headerInfo->dataType == (int)SimFlag::kData || useMCAsData){
00362
00363
00364
00365
00366
00367 if(analysisInfo->isNC > 0){
00368 fdatanc->Fill(recoInfo->nuEnergy, recoInfo->weight);
00369 MAXMSG("NCExtrapolationDP", Msg::kInfo, 10) << "data " << recoInfo->nuEnergy
00370 << "/" << recoInfo->showerEnergyNC
00371 << "/" << recoInfo->showerEnergy
00372 << " " << recoInfo->muEnergy
00373 << " " << recoInfo->weight
00374 << endl;
00375 }
00376 else if(analysisInfo->isCC > 0){
00377 fdata->Fill(recoInfo->nuEnergy, recoInfo->weight);
00378 }
00379
00380 }
00381
00382 return;
00383 }
00384
00385
00386 void NCExtrapolationDP::AddFarEvent(ANtpHeaderInfo *headerInfo,
00387 ANtpBeamInfo *beamInfo,
00388 ANtpRecoInfo *recoInfo,
00389 ANtpAnalysisInfo *analysisInfo,
00390 ANtpTruthInfoBeam *truthInfo,
00391 int runType,
00392 bool useMCAsData,
00393 int fileType)
00394 {
00395 MAXMSG("NCExtrapolationDP", Msg::kInfo, 1) << "AddFarEvent " << endl;
00396 MSG("NCExtrapolationDP", Msg::kDebug) << fileType << " " << beamInfo->beamType << endl;
00397
00398
00399
00400
00401
00402
00403 if(headerInfo->dataType == (int)SimFlag::kMC && !useMCAsData){
00404
00405
00406 vector<bool> useParameters;
00407 vector<double> adjustedValues;
00408
00409 int pars[] = {NCType::kma_qe, NCType::kma_res, NCType::kDISFACT};
00410 double shifts[] = {fNDFitResults[kMA_QE]*0.2 - 4.,
00411 fNDFitResults[kMA_RES]*0.2 - 4.,
00412 fNDFitResults[kdisfact]*0.2 - 4.};
00413
00414 for(int i = 0; i < NCType::kNumNeugenParameters; ++i){
00415 useParameters.push_back(false);
00416 adjustedValues.push_back(NCType::kParameterDefaults[i]);
00417 }
00418
00419 for(int i = 0; i < 3; ++i){
00420 useParameters[pars[i]] = true;
00421 adjustedValues[pars[i]] = shifts[i]*NCType::kParameterSigmas[pars[i]];
00422 adjustedValues[pars[i]] += NCType::kParameterDefaults[pars[i]];
00423 MAXMSG("NCExtrapolationDP", Msg::kInfo, 3) << adjustedValues[pars[i]] << " "
00424 << useParameters[pars[i]] << " "
00425 << NCType::kParameterNames[pars[i]]
00426 << endl;
00427 }
00428
00429 double weightNeugen = fUtils->FindNeugenWeight(useParameters, adjustedValues);
00430 double weightNC = 1.;
00431 if(truthInfo->interactionType == NCType::kNC)
00432 weightNC = 0.8+0.02*fNDFitResults[knc];
00433 double weightNorm = 0.9 + 0.005*fNDFitResults[kNorm];
00434
00435
00436 double totalWeight = weightNeugen*weightNC*weightNorm*recoInfo->weight;
00437
00438
00439
00440
00441 recoInfo->showerEnergy *= 0.8 + 0.02*fNDFitResults[kEshower];
00442 recoInfo->muEnergy *= 0.9 + 0.01*fNDFitResults[kEmu];
00443 recoInfo->nuEnergy = recoInfo->muEnergy + recoInfo->showerEnergy;
00444
00445 MAXMSG("NCExtrapolationDP", Msg::kInfo,1) << 0.8 + 0.02*fNDFitResults[kEshower] << " "
00446 << 0.9 + 0.01*fNDFitResults[kEmu] << " "
00447 << 0.9 + 0.005*fNDFitResults[kNorm] << endl;
00448 MAXMSG("NCExtrapolationDP", Msg::kInfo,1) << " weight NC = " << weightNC
00449 << " weight norm = " << weightNorm
00450 << " weight neugen = " << weightNeugen
00451 << " recoInfo->weight = " << recoInfo->weight
00452 << " total weight = " << totalWeight
00453 << endl;
00454
00455 }
00456
00457 if(recoInfo->nuEnergy > fMaxFarEReco){
00458 MAXMSG("NCExtrapolationDP", Msg::kInfo, 100) << "****Max far E_reco exceeded :"
00459 << recoInfo->nuEnergy << "/"
00460 << fMaxFarEReco << endl;
00461 return;
00462 }
00463
00464 NCExtrapolation::AddEvent(headerInfo, beamInfo, recoInfo, analysisInfo,
00465 truthInfo, runType, useMCAsData, fileType);
00466
00467 return;
00468 }
00469
00470
00471
00472 void NCExtrapolationDP::PrepareNearDetector()
00473 {
00474
00475
00476 int runType = 1;
00477 int beam = NCExtrapolation::FindBeamIndex(Detector::kNear, BeamType::kL010z185i, runType);
00478 if(beam > 100){
00479 MSG("NCExtrapolationDP", Msg::kWarning) << "could not find "
00480 << "ND beam in vector - bail"
00481 << endl;
00482 return;
00483 }
00484
00485
00486 fmaqewgt->Divide(fnom);
00487 fmareswgt->Divide(fnom);
00488 fdisfactwgt->Divide(fnom);
00489
00490 fmaqewgtcc->Divide(fnomcc);
00491 fmareswgtcc->Divide(fnomcc);
00492 fdisfactwgtcc->Divide(fnomcc);
00493
00494 fmaqewgtnc->Divide(fnomnc);
00495 fmareswgtnc->Divide(fnomnc);
00496 fdisfactwgtnc->Divide(fnomnc);
00497
00498
00499
00500 float qewgt[NCType::kNumEnergyBinsNear][4];
00501 float reswgt[NCType::kNumEnergyBinsNear][4];
00502 float diswgt[NCType::kNumEnergyBinsNear][4];
00503
00504
00505 for (int i=0;i<NCType::kNumEnergyBinsNear;i++) {
00506 for (int j=0;j<4;j++) {
00507 qewgt[i][j]=fmaqewgt->GetBinContent(i+1,j+1)-1.0;
00508 reswgt[i][j]=fmareswgt->GetBinContent(i+1,j+1)-1.0;
00509 diswgt[i][j]=fdisfactwgt->GetBinContent(i+1,j+1)-1.0;
00510 }
00511 }
00512
00513
00514 float qewgtnc_cc[NCType::kNumEnergyBinsNear];
00515 float reswgtnc_cc[NCType::kNumEnergyBinsNear];
00516 float diswgtnc_cc[NCType::kNumEnergyBinsNear];
00517
00518 float qewgtnc_nc[NCType::kNumEnergyBinsNear];
00519 float reswgtnc_nc[NCType::kNumEnergyBinsNear];
00520 float diswgtnc_nc[NCType::kNumEnergyBinsNear];
00521
00522 for(int i = 0; i < NCType::kNumEnergyBinsNear; i++){
00523
00524 qewgtnc_cc[i] = fmaqewgtcc->GetBinContent(i+1)-1.0;
00525 reswgtnc_cc[i] = fmareswgtcc->GetBinContent(i+1)-1.0;
00526 diswgtnc_cc[i] = fdisfactwgtcc->GetBinContent(i+1)-1.0;
00527
00528 qewgtnc_nc[i] = fmaqewgtnc->GetBinContent(i+1)-1.0;
00529 reswgtnc_nc[i] = fmareswgtnc->GetBinContent(i+1)-1.0;
00530 diswgtnc_nc[i] = fdisfactwgtnc->GetBinContent(i+1)-1.0;
00531
00532 }
00533
00534 float ccefficarr[11][NCType::kNumEnergyBinsNear];
00535 float ncefficarr[11][NCType::kNumEnergyBinsNear];
00536 float ccpurarr[11][NCType::kNumEnergyBinsNear];
00537
00538 for(int i = 0; i < 11; i++){
00539 for(int j = 0; j < NCType::kNumEnergyBinsNear; j++){
00540 ccefficarr[i][j] = 1.0;
00541 ncefficarr[i][j] = 1.0;
00542 ccpurarr[i][j] = 1.0;
00543 }
00544 }
00545
00546
00547 float factle=1.0;
00548
00549
00550
00551 for(int j = 0; j < NCType::kNumEnergyBinsNear; j++){
00552 fvobs[j]=fdata->GetBinContent(j+1);
00553 fvobsnclike[j]=fdatanc->GetBinContent(j+1);
00554 }
00555
00556
00557
00558
00559 float chisqmine=9999;
00560 float chisqmincc=9999;
00561 float chisqminnc=9999;
00562 float chisq=0;
00563 float chisqnc=0;
00564
00565 int cnorm=0;
00566 int cesh=0;
00567 int cemu=0;
00568 int cmaqe=0;
00569 int cmares=0;
00570 int cdis=0;
00571 int cbeam1=0;
00572 int cbeam2=0;
00573 int cbeam3=0;
00574 int cbeam4=0;
00575 int cbeam5=0;
00576
00577 int creco=0;
00578 int cnc=0;
00579
00580 float beamerr[NCType::kNumEnergyBinsNear][5];
00581
00582 for(int i = 0; i < NCType::kNumEnergyBinsNear; i++){
00583 beamerr[i][0] = 1.0;
00584 beamerr[i][1] = 1.0;
00585 beamerr[i][2] = 1.0;
00586 beamerr[i][3] = 1.0;
00587 beamerr[i][4] = 1.0;
00588 }
00589
00590 int nomin = 20;
00591 int nomax = 21;
00592 int esmin = 10;
00593 int esmax = 11;
00594 int mumin = 10;
00595 int mumax = 11;
00596 int dmmin = 20;
00597 int dmmax = 21;
00598 int dismin = 20;
00599 int dismax = 21;
00600
00601 if(fsys==1){
00602 nomin = 0;
00603 nomax = 41;
00604 esmin = 0;
00605 esmax = 21;
00606 mumin = 0;
00607 mumax = 21;
00608 dmmin = 0;
00609 dmmax = 41;
00610 dismin = 20;
00611 dismax = 41;
00612 }
00613
00614 float normfact = 0.;
00615 float eshift = 0.;
00616 float emushift = 0.;
00617 float maqe = 0.;
00618 float mares = 0.;
00619 float disfact = 0.;
00620 float beamunc1 = 0.;
00621 float beamunc2 = 0.;
00622 float beamunc3 = 0.;
00623 float beamunc4 = 0.;
00624 float beamunc5 = 0.;
00625 float ncunc = 0.;
00626 int recerr = 5;
00627
00628 float so = 0.;
00629 float se = 0.;
00630 float snc = 0.;
00631 float obs = 0.;
00632 float ex = 0.;
00633 float expnc = 0.;
00634 float beamfact = 0.;
00635 float ncex = 0.;
00636 float ncexpnc = 0.;
00637 float sonc = 0.;
00638 float senc = 0.;
00639 float chisqall = 0.;
00640 float cceff = 0.;
00641 float ccpur = 0.;
00642 float nceff = 0.;
00643
00644
00645 for(int no = nomin; no < nomax; no++){
00646 normfact = 0.9 + 0.005*no;
00647 MAXMSG("NCExtrapolationDP", Msg::kDebug, nomax-nomin)
00648 << "normfact " << normfact << "/" << no << endl;
00649
00650
00651 for(int dm = dmmin; dm < dmmax; dm++){
00652 maqe = -4. + 0.2*dm;
00653 mares = -4. + 0.2*dm;
00654 MAXMSG("NCExtrapolationDP", Msg::kDebug, dmmax-dmmin)
00655 << "maqe,mares " << maqe << "/" << dm << endl;
00656
00657
00658 for(int dis = dismin; dis < dismax; dis++){
00659 disfact = -4 + 0.2*dis;
00660 MAXMSG("NCExtrapolationDP", Msg::kDebug, dismax-dismin)
00661 << "disfact " << disfact << "/" << dis << endl;
00662
00663
00664 for(int es = esmin; es < esmax; es++){
00665 eshift = es*0.02 + 0.8;
00666
00667
00668 for(int em = mumin; em < mumax; em++){
00669 emushift = em*0.01 + 0.9;
00670
00671 fmtempcc->Reset();
00672 fmtempnc->Reset();
00673
00674
00675 chisq = 0.;
00676 chisqnc = 0.;
00677
00678
00679 for(int i = 0; i < NCType::kNumEnergyBinsNear; i++){
00680
00681
00682 beamfact = (1+beamunc1*(beamerr[i][0]-1));
00683 beamfact *= (1+beamunc2*(beamerr[i][1]-1));
00684 beamfact *= (1+beamunc3*(beamerr[i][2]-1));
00685 beamfact *= (1+beamunc4*(beamerr[i][3]-1));
00686 beamfact *= (1+beamunc5*(beamerr[i][4]-1));
00687
00688
00689 so = 0.;
00690 se = 0.;
00691 snc = 0.;
00692 sonc = 0.;
00693 senc = 0.;
00694
00695
00696 obs = fvobs[i];
00697 so += obs;
00698
00699
00700 sonc = fvobsnclike[i];
00701
00702 cceff = ccefficarr[recerr][i];
00703 ccpur = ccpurarr[recerr][i];
00704 nceff = ncefficarr[recerr][i];
00705
00706
00707 for(int j = 0; j < 4; j++){
00708
00709
00710 ex = fvexp[es*21+em][i][j]*normfact*beamfact*factle;
00711 ex *= (1.0 + qewgt[i][j]*maqe);
00712 ex *= (1.0 + reswgt[i][j]*mares);
00713 ex *= (1.0 + diswgt[i][j]*disfact);
00714
00715
00716 ex *= cceff/ccpur;
00717
00718 expnc = fvnc[es*21+em][i][j]*normfact*beamfact*factle;
00719
00720
00721 expnc *= nceff;
00722
00723
00724 se += ex;
00725
00726
00727 snc += expnc*ncunc;
00728
00729 }
00730
00731
00732
00733 ncex = fncvcc[es*21+em][i]*normfact*beamfact*factle;
00734 ncex *= (1.0 + qewgtnc_cc[i]*maqe);
00735 ncex *= (1.0 + reswgtnc_cc[i]*mares);
00736 ncex *= (1.0 + diswgtnc_cc[i]*disfact);
00737
00738
00739 ncexpnc=fncvnc[es*21+em][i]*normfact*beamfact*factle;
00740 ncexpnc *= (1.0 + qewgtnc_nc[i]*maqe);
00741 ncexpnc *= (1.0 + reswgtnc_nc[i]*mares);
00742 ncexpnc *= (1.0 + diswgtnc_nc[i]*disfact);
00743 ncexpnc *= 1.+ncunc;
00744 senc = ncex + ncexpnc;
00745
00746 fmtempcc->SetBinContent(i+1,se+snc);
00747 fmtempnc->SetBinContent(i+1,senc);
00748
00749
00750 if(se + snc > 0){
00751 chisq += TMath::Power(so-(se+snc),2)/(se+snc);
00752 }
00753
00754 if(senc > 0){
00755 chisqnc += TMath::Power(sonc-senc,2)/(senc);
00756 }
00757
00758 }
00759
00760 chisq += TMath::Power(maqe,2);
00761 chisq += TMath::Power(mares,2);
00762 chisq += TMath::Power(disfact,2);
00763 chisq += TMath::Power(eshift-1,2)/TMath::Power(0.10,2);
00764 chisq += TMath::Power(emushift-1,2)/TMath::Power(0.02,2);
00765 chisq += TMath::Power(normfact-1,2)/TMath::Power(0.05,2);
00766
00767 chisqall = chisq + chisqnc;
00768
00769 if(chisqall < chisqmine){
00770
00771 chisqmine = chisqall;
00772 chisqmincc = chisq;
00773 chisqminnc = chisqnc;
00774
00775 cnorm = no;
00776 cesh = es;
00777 cemu = em;
00778 cmaqe = dm;
00779 cmares = dm;
00780 cdis = dis;
00781 cbeam1 = 10;
00782 cbeam2 = 10;
00783 cbeam3 = 10;
00784 cbeam4 = 10;
00785 cbeam5 = 10;
00786
00787 creco = 5;
00788 cnc = 10;
00789 fmcbfcc->Reset();
00790 fmcbfnc->Reset();
00791
00792 for(int ll = 0; ll < NCType::kNumEnergyBinsNear; ll++){
00793 fmcbfcc->SetBinContent(ll+1, fmtempcc->GetBinContent(ll+1));
00794 fmcbfnc->SetBinContent(ll+1, fmtempnc->GetBinContent(ll+1));
00795 }
00796 }
00797 }
00798 }
00799 }
00800 }
00801 }
00802
00803 fNDFitResults.clear();
00804 fNDFitResults.push_back(cnorm);
00805 fNDFitResults.push_back(cesh);
00806 fNDFitResults.push_back(cemu);
00807 fNDFitResults.push_back(cmaqe);
00808 fNDFitResults.push_back(cmares);
00809 fNDFitResults.push_back(cdis);
00810 fNDFitResults.push_back(cbeam1);
00811 fNDFitResults.push_back(cbeam2);
00812 fNDFitResults.push_back(cbeam3);
00813 fNDFitResults.push_back(cbeam4);
00814 fNDFitResults.push_back(cbeam5);
00815 fNDFitResults.push_back(creco);
00816 fNDFitResults.push_back(cnc);
00817
00818 MSG("NCExtrapolationDP", Msg::kInfo)
00819 << "--------Results of NDFit---------"
00820 << endl << "chisqrmin = " << chisqmine
00821 << " cc-chisqr = " << chisqmincc
00822 << " nc-chisqr = " << chisqminnc
00823 << endl << kParNames[kNorm] << " = " << fNDFitResults[kNorm]*0.005+0.9 - 1.
00824 << endl << kParNames[kEshower] << " = "
00825 << (fNDFitResults[kEshower]*0.02+0.8-1.)*NCType::kParameterSigmas[NCType::kShowerEnergy]
00826 +NCType::kParameterDefaults[NCType::kShowerEnergy]
00827 << " = " << (fNDFitResults[kEshower]*0.02+0.8)
00828 << endl << kParNames[kEmu] << " = "
00829 << (fNDFitResults[kEmu]*0.01+0.9-1.)*NCType::kParameterSigmas[NCType::kTrackEnergy]
00830 +NCType::kParameterDefaults[NCType::kTrackEnergy]
00831 << " = " << (fNDFitResults[kEmu]*0.01+0.9)
00832 << endl << kParNames[kMA_QE] << " = "
00833 << (fNDFitResults[kMA_QE]*0.2-4.)*NCType::kParameterSigmas[NCType::kma_qe]
00834 + NCType::kParameterDefaults[NCType::kma_qe]
00835 << " = " << (fNDFitResults[kMA_QE]*0.2-4.)
00836 << endl << kParNames[kMA_RES] << " = "
00837 << (fNDFitResults[kMA_RES]*0.2-4.)*NCType::kParameterSigmas[NCType::kma_res]
00838 + NCType::kParameterDefaults[NCType::kma_res]
00839 << " = " << (fNDFitResults[kMA_RES]*0.2-4.)
00840 << endl << kParNames[kdisfact] << " = "
00841 << (fNDFitResults[kdisfact]*0.2-4.)*NCType::kParameterSigmas[NCType::kDISFACT]
00842 + NCType::kParameterDefaults[NCType::kDISFACT]
00843 << " = " << (fNDFitResults[kdisfact]*0.2-4.)
00844 << endl << kParNames[kBeam1] << " = "
00845 << (fNDFitResults[kBeam1]*0.4-4.)*1.
00846 << endl << kParNames[kBeam2] << " = "
00847 << (fNDFitResults[kBeam2]*0.4-4.)*1.
00848 << endl << kParNames[kBeam3] << " = "
00849 << (fNDFitResults[kBeam3]*0.4-4.)*1.
00850 << endl << kParNames[kBeam4] << " = "
00851 << (fNDFitResults[kBeam4]*0.4-4.)*1.
00852 << endl << kParNames[kBeam5] << " = "
00853 << (fNDFitResults[kBeam5]*0.4-4.)*1.
00854 << endl << kParNames[kReco] << " = "
00855 << (fNDFitResults[kReco]*0.4-2.)*1.
00856 << endl << kParNames[knc] << " = "
00857 << (fNDFitResults[knc]*0.02-0.2)*NCType::kParameterSigmas[NCType::kNCBackground]
00858 + NCType::kParameterDefaults[NCType::kNCBackground]
00859 << endl;
00860
00861
00862 NCEnergyBin *bin = 0;
00863 for(int i = 0; i < NCType::kNumEnergyBinsNear; ++i){
00864
00865
00866 se = 0;
00867 snc = 0;
00868 ex = 0;
00869 expnc = 0;
00870 ncex = 0;
00871 ncexpnc = 0;
00872
00873 cceff = ccefficarr[creco][i];
00874 ccpur = ccpurarr[creco][i];
00875 nceff = ncefficarr[creco][i];
00876
00877
00878 for(int j = 0; j < 4; j++){
00879
00880 ex = fvexp[cesh*21+cemu][i][j]*(cnorm*0.005+0.9)*factle;
00881 ex *= (1.0+qewgt[i][j]*(-4.+cmaqe*0.2));
00882 ex *= (1.0+reswgt[i][j]*(-4.+cmares*0.2));
00883 ex *= (1.0+diswgt[i][j]*(-4.+cdis*0.2));
00884
00885
00886 ex *= cceff/ccpur;
00887
00888
00889 expnc = fvnc[cesh*21+cemu][i][j]*(cnorm*0.005+0.9)*factle;
00890
00891
00892 expnc *= nceff;
00893
00894
00895 se += ex;
00896
00897
00898 snc += expnc*(-0.2+0.02*cnc);
00899
00900 }
00901
00902
00903
00904 ncex = fncvcc[cesh*21+cemu][i]*(cnorm*0.005+0.9)*factle;
00905 ncex *= (1.0+qewgtnc_cc[i]*(-4.+0.2*cmaqe));
00906 ncex *= (1.0+reswgtnc_cc[i]*(-4.+0.2*cmares));
00907 ncex *= (1.0+diswgtnc_cc[i]*(-4.+0.2*cdis));
00908
00909
00910 ncexpnc = fncvnc[cesh*21+cemu][i]*(cnorm*0.005+0.9)*factle;
00911 ncexpnc *= (1.0+qewgtnc_nc[i]*(-4.+0.2*cmaqe));
00912 ncexpnc *= (1.0+reswgtnc_nc[i]*(-4.+0.2*cmares));
00913 ncexpnc *= (1.0+diswgtnc_nc[i]*(-4.+0.2*cdis));
00914 ncexpnc *= 1.+(-0.2+0.02*cnc);
00915
00916
00917 bin = fBeams[beam].GetEnergyBin(i, NCType::kCC);
00918
00919
00920
00921
00922 bin = fBeams[beam].GetEnergyBin(i, NCType::kNC);
00923
00924
00925
00926
00927
00928 }
00929
00930 return;
00931 }
00932
00933
00934
00935 void NCExtrapolationDP::PredictSpectrum()
00936 {
00937 MSG("NCExtrapolationDP", Msg::kWarning) << "Predict Spectrum"
00938 << endl;
00939
00940
00941 int runType = 1;
00942 int beam = NCExtrapolation::FindBeamIndex(Detector::kFar, BeamType::kL010z185i, runType);
00943
00944
00945
00946
00947
00948
00949
00950
00951 float chisq = 0.;
00952 float chisqmin = 1.e12;
00953 float dmmin = 0.;
00954 float stmin = 0.;
00955 float fsmin = 0.;
00956 float normmin = 0.;
00957 float normfact = 0.;
00958
00959 vector <vector <vector <double> > > chiSqrPnts;
00960 chiSqrPnts.resize(NCType::kNumDeltaMSqrBins);
00961 for(int i=0; i<NCType::kNumDeltaMSqrBins; i++) {
00962 chiSqrPnts[i].resize(NCType::kNumUS3SqrBins);
00963 for(int j=0; j < NCType::kNumUS3SqrBins; j++) {
00964 chiSqrPnts[i][j].resize(NCType::kNumUMu3SqrBins);
00965 for(int k=0; k<NCType::kNumUMu3SqrBins; k++) {
00966 chiSqrPnts[i][j][k] = 0.0;
00967 }
00968 }
00969 }
00970
00971
00972 float dmsq = 0.;
00973 float s2t = 0.;
00974 float fster = 0.;
00975 float chisqminnorm = 9999.;
00976 float normtemp = 0.;
00977 float obs = 0.;
00978 float exp = 0.;
00979 int nmin = 0;
00980 int nmax = 0;
00981
00982 TStopwatch sw;
00983 sw.Start();
00984
00985 NCEnergyBin *bin = 0;
00986
00987 for(int dm = 0; dm < NCType::kNumDeltaMSqrBins; dm++){
00988
00989 dmsq = (1.*dm + 0.5)*NCType::kDeltaDeltaMSqr+NCType::kDeltaMSqrStart;
00990 dmsq *= 1.e-3;
00991
00992 MSG("NCExtrapolationDP", Msg::kDebug) << "dmsq = " << dmsq << endl;
00993
00994
00995 for(int st = 0; st < NCType::kNumUMu3SqrBins; st++){
00996
00997 s2t = (1.*st + 0.5)*NCType::kDeltaUMu3Sqr+NCType::kUMu3SqrStart;
00998 MAXMSG("NCExtrapolationDP", Msg::kDebug, kNumUMu3SqrBins) << "s2t = "
00999 << s2t << endl;
01000
01001
01002 for (int fs = 0; fs < NCType::kNumUS3SqrBins; fs++){
01003
01004 fster = (1.*fs + 0.5)*NCType::kDeltaUS3Sqr+NCType::kUS3SqrStart;
01005 MAXMSG("NCExtrapolationDP", Msg::kDebug, kNumUS3SqrBins) << "fster = "
01006 << fster << endl;
01007
01008
01009
01010
01011 chisqminnorm = 9999.;
01012 normtemp = 0.;
01013
01014 nmin = 50;
01015 nmax = 51;
01016
01017 if(fsys == 1){
01018 nmin = 0;
01019 nmax = 101;
01020 }
01021
01022
01023 for(int n = nmin; n < nmax; n++){
01024
01025 normfact = 0.95+0.001*n;
01026
01027 chisq = 0;
01028
01029
01030 for(int j = 0; j < 2; j++){
01031 for(int i = 0; i < NCType::kNumEnergyBinsFar; i++){
01032
01033 bin = fBeams[beam].GetEnergyBin(i,j);
01034 obs = bin->GetSignal();
01035 exp = bin->GetTotalMC()*normfact;
01036
01037 if(exp > 0){
01038
01039
01040 chisq += 2*(exp-obs);
01041 if(obs > 0) chisq += 2*obs*log(obs/exp);
01042
01043 }
01044
01045
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055 }
01056 }
01057
01058
01059 chisq += TMath::Power((normfact-1)/0.04, 2);
01060
01061
01062 if(chisq < chisqminnorm){
01063 chisqminnorm = chisq;
01064 normtemp = normfact;
01065 }
01066
01067 }
01068
01069
01070 chiSqrPnts[dm][fs][st] = chisqminnorm;
01071
01072
01073
01074 if(chisqminnorm < chisqmin){
01075 chisqmin = chisqminnorm;
01076 dmmin = dmsq;
01077 stmin = s2t;
01078 fsmin = fster;
01079 normmin = normtemp;
01080 }
01081 }
01082 }
01083 }
01084
01085 sw.Stop();
01086 MSG("NCExtrapolationDP", Msg::kInfo) << "grid search took "
01087 << sw.CpuTime() << " cpu, "
01088 << sw.RealTime() << " real"
01089 << endl;
01090
01091
01092 BestUMu3Sqr() = stmin;
01093 BestUS3Sqr() = fsmin;
01094 BestDeltaMSqr() = dmmin;
01095 fMinChiSqr = chisqmin;
01096
01097
01098
01099
01100 MSG("NCExtrapolationDP", Msg::kInfo) << "Best Sterile Fit at :"
01101 << " delta m^2 = " << dmmin
01102 << " f_s = " << fsmin
01103 << " sin^2(2theta) = " << stmin
01104 << " normalization = " << normmin
01105 << " chi^2 = " << chisqmin
01106 << endl;
01107
01108 NCExtrapolation::FillDeltaChiSqrMaps(chiSqrPnts);
01109
01110 return;
01111 }
01112
01113
01114 int NCExtrapolationDP::FindRecoEnergyBin(float enu, int beam)
01115 {
01116 if(enu > NCType::kMaxEnergy) return NCType::kNumEnergyBinsNear-1;
01117
01118 int bin = fBeams[beam].GetMCHistogram(NCType::kCC)->FindBin(enu) - 1;
01119
01120 return bin;
01121 }
01122
01123
01124
01125 void NCExtrapolationDP::WriteResources()
01126 {
01127
01128
01129
01130
01131 NCExtrapolation::WriteResources();
01132
01133
01134
01135 TDirectory* fileDir = gDirectory;
01136 TDirectory* saveDir = gDirectory;
01137 fileDir->cd("plots"+NCType::kExtrapolationNames[fExtrapolationType]);
01138
01139 MSG("NCExtrapolationMQ", Msg::kInfo) << "NCExtrapolationDP::WriteResources()" << endl;
01140
01141 fnom->Write();
01142 fmaqewgt->Write();
01143 fmareswgt->Write();
01144 fdisfactwgt->Write();
01145
01146 fnomcc->Write();
01147 fmaqewgtcc->Write();
01148 fmareswgtcc->Write();
01149 fdisfactwgtcc->Write();
01150
01151 fnomnc->Write();
01152 fmaqewgtnc->Write();
01153 fmareswgtnc->Write();
01154 fdisfactwgtnc->Write();
01155
01156 fdata->Write();
01157 fdatanc->Write();
01158
01159 fmcnomcc->Write();
01160 fmcbfcc->Write();
01161 fmtempcc->Write();
01162
01163 fmcnomnc->Write();
01164 fmcbfnc->Write();
01165 fmtempnc->Write();
01166
01167 saveDir->cd();
01168
01169 return;
01170 }