00001 #include "NueAna/NueAnalysisCuts.h"
00002 #include "Calibrator/CalMIPCalibration.h"
00003 #include "CandNtupleSR/NtpSRRecord.h"
00004 #include "CandNtupleSR/NtpSREvent.h"
00005 #include "CandNtupleSR/NtpSRTrack.h"
00006 #include "CandNtupleSR/NtpSRShower.h"
00007 #include "StandardNtuple/NtpStRecord.h"
00008 #include "AnalysisNtuples/ANtpDefaultValue.h"
00009 #include "NueAna/NueAnaTools/NueConvention.h"
00010 #include "NueAna/NueAnaTools/SntpHelpers.h"
00011 #include "MessageService/MsgService.h"
00012 #include <fstream>
00013 #include "TList.h"
00014 #include "TClass.h"
00015 #include "TDataType.h"
00016 #include "TDataMember.h"
00017 #include "TRealData.h"
00018 #include "DataUtil/infid.h"
00019
00020
00021 ClassImp(NueAnalysisCuts)
00022 CVSID("$Id: NueAnalysisCuts.cxx,v 1.17 2008/11/19 18:22:51 rhatcher Exp $");
00023
00024 #include "DatabaseInterface/DbiResultPtr.tpl"
00025
00026 NueAnalysisCuts::NueAnalysisCuts()
00027 {
00028 kMEUPerGeV =25.66;
00029 kSigCorrPerMEU = 1.0;
00030 Reset();
00031 }
00032
00033 void NueAnalysisCuts::Reset()
00034 {
00035 LowCuts.Reset();
00036 HighCuts.Reset();
00037
00038 fDetectorType = Detector::kUnknown;
00039 fSimFlag = SimFlag::kUnknown;
00040
00041 fCheckHotChannel = 0;
00042 fFiducialCut = 0;
00043 fFidVtxChoice = FiducialAlg::kUseEvtVtx;
00044 fFidVolumeChoice = FiducialAlg::kExtendedVolume;
00045 fContainmentCut = 0;
00046 fBeamCut = 0;
00047 fTargetCurrent = -1000;
00048 fPhProngCut = -1;
00049 fFileTrim = 0;
00050 fEventNum = 0;
00051 }
00052
00053
00054 void NueAnalysisCuts::SetInfoObject(NueRecord* nr)
00055 {
00056 nrInfo = nr;
00057
00058 stInfo = NULL;
00059 srInfo = NULL;
00060 eventInfo = NULL;
00061 trackInfo = NULL;
00062 mcInfo = NULL;
00063 showerInfo = NULL;
00064
00065 fDetectorType = nr->GetHeader().GetVldContext().GetDetector();
00066 fSimFlag = nrInfo->GetHeader().GetVldContext().GetSimFlag();
00067 }
00068
00069 void NueAnalysisCuts::SetInfoObject(int evtn, NtpStRecord* st)
00070 {
00071 if(!st) return;
00072
00073 stInfo = st;
00074
00075 VldContext vc;
00076 vc=st->GetHeader().GetVldContext();
00077
00078 int run = st->GetHeader().GetRun();
00079 ntpManipulator.SetRecord(st);
00080 SetNtpInfoObjects(evtn,run, vc);
00081
00082 nrInfo = NULL;
00083 }
00084
00085 void NueAnalysisCuts::SetInfoObject(int evtn, NtpSRRecord* st, NtpMCRecord * mcobj, NtpTHRecord * thobj)
00086 {
00087 if(!st) return;
00088 srInfo = st;
00089 VldContext vc;
00090 vc=st->GetHeader().GetVldContext();
00091
00092 int run = st->GetHeader().GetRun();
00093 ntpManipulator.SetRecord(st, mcobj, thobj);
00094 SetNtpInfoObjects(evtn,run,vc);
00095 nrInfo = NULL;
00096 }
00097
00098 void NueAnalysisCuts::SetNtpInfoObjects(int evtn, int run, VldContext &vc)
00099 {
00100 fDetectorType = vc.GetDetector();
00101 fSimFlag = vc.GetSimFlag();
00102
00103 fEventNum = evtn;
00104 ntpManipulator.SetPrimaryShowerCriteria(0,1);
00105 ntpManipulator.SetPrimaryTrackCriteria(0,1,0);
00106
00107 ANtpEventManipulator * ntpEventManipulator =
00108 ntpManipulator.GetEventManipulator();
00109 ntpEventManipulator->SetEventInSnarl(evtn);
00110
00111 eventInfo=ntpEventManipulator->GetEvent();
00112 showerInfo = ntpEventManipulator->GetPrimaryShower();
00113 trackInfo = SntpHelpers::GetPrimaryTrack(evtn, stInfo);
00114 thEventInfo = ntpManipulator.GetMCManipulator()->GetNtpTHEvent(evtn);
00115
00116 if(thEventInfo){
00117 mcInfo = ntpManipulator.GetMCManipulator()->GetNtpMCTruth(thEventInfo->neumc);
00118
00119 }
00120
00121 static int currentRun = 0;
00122 if(run != currentRun)
00123 {
00124 DbiResultPtr<CalMIPCalibration> dbp(vc);
00125 if(dbp.GetNumRows()>0){
00126 const CalMIPCalibration *m = dbp.GetRow(0);
00127 float mip=m->GetMIP(1.);
00128 if(mip>0){
00129 kSigCorrPerMEU=1./mip;
00130 }
00131 }
00132 currentRun = run;
00133 }
00134 }
00135
00136
00137 const Registry& NueAnalysisCuts::DefaultConfig() const
00138 {
00139 static Registry r;
00140
00141 r.UnLockValues();
00142
00143 r.Set("HiPlaneTrackCut",-1);
00144 r.Set("LoPlaneEventCut",-1);
00145 r.Set("HiPlaneEventCut",-1);
00146 r.Set("HiTrackLikeCut",-1);
00147 r.Set("CheckHotChannel", 0);
00148 r.Set("FiducialCut", 0);
00149 r.Set("FiducialVtx", 1);
00150 r.Set("FiducialVolumeAlg", 2);
00151 r.Set("HiEnergyCut",-1);
00152 r.Set("LoEnergyCut",-1);
00153 r.Set("HiShowerEnergyCut",-1);
00154 r.Set("LoShowerEnergyCut",-1);
00155
00156
00157
00158
00159 r.Set("CutOnClasses", 0);
00160 r.Set("BeamQualityCut", 0);
00161 r.Set("LoPhNStripCut",-1);
00162 r.Set("LoPhNPlaneCut",-1);
00163 r.Set("HiEnergyCut",-1);
00164 r.Set("LoEnergyCut",-1);
00165 r.Set("HiEnergyShowerCut",-1);
00166 r.Set("LoEnergyShowerCut",-1);
00167
00168
00169
00170
00171 r.Set("LoCurrentCut", 0.1);
00172 r.Set("LoHorBeamWidth", 0.0);
00173 r.Set("HiHorBeamWidth", 2.9);
00174 r.Set("LoVertBeamWidth", 0.0);
00175 r.Set("HiVertBeamWidth", 2.9);
00176 r.Set("LoNuTarZ", -1);
00177 r.Set("HiNuTarZ", 1000);
00178 r.Set("Oscillate", 0);
00179 r.Set("OutputFile", "HistManInfo.root");
00180
00181 r.Set("FileCut", 0);
00182 r.Set("TrimFile", "Default.txt");
00183
00184
00185
00186 r.Set("AddSignal", 2);
00187
00188
00189
00190
00191
00192
00193 r.Set("TargetHornCurrent", -185);
00194 r.Set("CutonResCode", 0);
00195
00196
00197 r.LockValues();
00198
00199 return r;
00200 }
00201
00202 void NueAnalysisCuts::Config(const Registry& r)
00203 {
00204 int imps;
00205 if(r.Get("HiPlaneTrackCut",imps)) { HighCuts.srtrack.planes=imps;}
00206 if(r.Get("HiTrackLikeCut",imps)) { HighCuts.srtrack.trklikePlanes=imps;}
00207 if(r.Get("LoPlaneEventCut",imps)) { LowCuts.srevent.planes=imps;}
00208 if(r.Get("HiPlaneEventCut",imps)) { HighCuts.srevent.planes=imps;}
00209 if(r.Get("CheckHotChannel",imps)) { fCheckHotChannel=imps;}
00210 if(r.Get("FiducialCut", imps)) { fFiducialCut = imps;}
00211 if(r.Get("FiducialVtx", imps)) { fFidVtxChoice = imps;}
00212 if(r.Get("FiducialVolumeAlg", imps)) { fFidVolumeChoice = imps;}
00213 if(r.Get("ContainmentCut", imps)) {fContainmentCut = imps;}
00214
00215 if(r.Get("CutOnClasses", imps)) { fCutClasses = imps; }
00216 if(r.Get("SetSignal", imps)) {
00217 signalClasses.clear(); signalClasses.push_back(imps);
00218 }
00219 if(r.Get("AddSignal", imps)) { signalClasses.push_back(imps); }
00220 if(r.Get("SetBackground", imps)) {
00221 bgClasses.clear(); bgClasses.push_back(imps);
00222 }
00223 if(r.Get("AddBackground", imps)) { bgClasses.push_back(imps); }
00224
00225 if(r.Get("SetSignalResCode",imps)) {
00226 sigResonanceCodes.clear(); sigResonanceCodes.push_back(imps); }
00227 if(r.Get("SetBackgroundResCode",imps)) {
00228 bgResonanceCodes.clear(); bgResonanceCodes.push_back(imps); }
00229
00230 if(r.Get("AddSignalResCode",imps)) {sigResonanceCodes.push_back(imps); }
00231 if(r.Get("AddBackgroundResCode",imps)) {bgResonanceCodes.push_back(imps); }
00232 if(r.Get("CutonResCode", imps)) {fCutResCode = imps;}
00233
00234 if(r.Get("BeamQualityCut", imps)) {fBeamCut = imps;}
00235 if(r.Get("LoPhNStripCut",imps)) { LowCuts.shwfit.hiPhStripCount=imps;}
00236 if(r.Get("LoPhNPlaneCut",imps)) { LowCuts.shwfit.hiPhPlaneCountM2=imps;}
00237
00238
00239
00240
00241 if(r.Get("FileCut", imps)) {fFileTrim = imps;}
00242
00243
00244
00245 double fmps;
00246 if(r.Get("HiShowerEnergyCut",fmps)) { HighCuts.srshower.phNueGeV =fmps;}
00247 if(r.Get("LoShowerEnergyCut",fmps)) { LowCuts.srshower.phNueGeV =fmps;}
00248 if(r.Get("HiEnergyCut",fmps)) { HighCuts.srevent.phNueGeV =fmps;}
00249 if(r.Get("LoEnergyCut",fmps)) { LowCuts.srevent.phNueGeV =fmps;}
00250 if(r.Get("PhProngCut",fmps)) { fPhProngCut=fmps; }
00251 if(r.Get("HiSigEmFracCut", fmps)) {
00252 HighSigCuts.emShowerFraction = fmps;}
00253 if(r.Get("LoSigEmFracCut", fmps)) {
00254 LowSigCuts.emShowerFraction = fmps;}
00255 if(r.Get("HiBgEmFracCut", fmps)) {
00256 HighBgCuts.emShowerFraction = fmps;}
00257 if(r.Get("LoBgEmFracCut", fmps)) {
00258 LowBgCuts.emShowerFraction = fmps; }
00259
00260 if(r.Get("TargetHornCurrent", fmps)) {fTargetCurrent = fmps;}
00261
00262
00263
00264
00265 const char* tmps;
00266
00267 if(r.Get("SetBackground", tmps)) {
00268 if(tmps == "All"){
00269 bgClasses.clear();
00270 for(int i = 0; i < 5; i++) bgClasses.push_back(i);
00271 }
00272 }
00273
00274 if(r.Get("SetSignal", tmps)) {
00275 if(tmps == "All"){
00276 signalClasses.clear();
00277 for(int i = 0; i < 5; i++) signalClasses.push_back(i);
00278 }
00279 }
00280
00281 if(r.Get("TrimFile", tmps)) {fFileCutName = tmps;}
00282 if(r.Get("OutputFile", tmps)) {kOutputFile = tmps;}
00283
00284 }
00285
00286
00287
00288
00289
00290 bool NueAnalysisCuts::IsValid()
00291 {
00292 bool retval = false;
00293 if(nrInfo || stInfo || srInfo) retval = true;
00294 return retval;
00295 }
00296
00297 bool NueAnalysisCuts::IsMC()
00298 {
00299 if(!IsValid()) return false;
00300 return (fSimFlag == SimFlag::kMC);
00301 }
00302
00303
00304
00305
00306
00307
00308 bool NueAnalysisCuts::PassesAllCuts()
00309 {
00310 bool goodEvent = true;
00311 goodEvent = goodEvent && PassesTrackPlaneCut();
00312 goodEvent = goodEvent && PassesTrackLikePlaneCut();
00313 goodEvent = goodEvent && PassesHighShowerEnergyCut();
00314 goodEvent = goodEvent && PassesLowShowerEnergyCut();
00315 goodEvent = goodEvent && PassesHighEnergyCut();
00316 goodEvent = goodEvent && PassesLowEnergyCut();
00317 goodEvent = goodEvent && PassesEventPlaneCut();
00318 goodEvent = goodEvent && PassesHotChannel();
00319 goodEvent = goodEvent && PassesFiducialVolume();
00320 goodEvent = goodEvent && PassesFullContainment();
00321 goodEvent = goodEvent && PassesPhProngCut();
00322 goodEvent = goodEvent && PassesCutOnClasses();
00323
00324 goodEvent = goodEvent && PassesLowPhNPlaneCut();
00325 goodEvent = goodEvent && PassesLowPhNStripCut();
00326 goodEvent = goodEvent && PassesEMFraction();
00327 goodEvent = goodEvent && PassesResonanceCode();
00328 goodEvent = goodEvent && PassesFileCut();
00329
00330 return goodEvent;
00331 }
00332
00333
00334
00335
00336
00337 bool NueAnalysisCuts::PassesTrackPlaneCut()
00338 {
00339 if(!IsValid()) return false;
00340 if(HighCuts.srtrack.planes < 0) return true;
00341
00342 int planes = 0;
00343 if(nrInfo) planes = nrInfo->srtrack.planes;
00344 if(stInfo && trackInfo) planes = trackInfo->plane.n;
00345
00346 bool goodEvent = !(planes > HighCuts.srtrack.planes);
00347
00348 return goodEvent;
00349 }
00350
00351 bool NueAnalysisCuts::PassesEventPlaneCut()
00352 {
00353 if(!IsValid()) return false;
00354
00355 int planes = 0;
00356 if(nrInfo) planes = nrInfo->srevent.planes;
00357 if(eventInfo) planes = eventInfo->plane.n;
00358
00359 bool goodEvent = true;
00360 if(HighCuts.srevent.planes > 0){
00361 goodEvent = !(planes > HighCuts.srevent.planes);
00362 }
00363 if(LowCuts.srevent.planes > 0){
00364 goodEvent = goodEvent && (planes >= LowCuts.srevent.planes);
00365 }
00366
00367 return goodEvent;
00368 }
00369
00370 bool NueAnalysisCuts::PassesTrackLikePlaneCut()
00371 {
00372 if(!IsValid()) return false;
00373 if(HighCuts.srtrack.trklikePlanes < 0) return true;
00374
00375 int planes = 0;
00376 if(nrInfo) planes = nrInfo->srtrack.trklikePlanes;
00377 if(stInfo && trackInfo) planes = trackInfo->plane.ntrklike;
00378
00379 bool goodEvent = planes <= HighCuts.srtrack.trklikePlanes;
00380
00381 return goodEvent;
00382 }
00383
00384
00385
00386
00387
00388 bool NueAnalysisCuts::PassesHighShowerEnergyCut()
00389 {
00390 if(!IsValid()) return false;
00391
00392 bool goodEvent = true;
00393 if(HighCuts.srshower.phNueGeV < 0) return goodEvent;
00394
00395 if(nrInfo){
00396 if(nrInfo->srshower.phNueGeV > HighCuts.srshower.phNueGeV)
00397 goodEvent = false;
00398 }else
00399 if(stInfo && showerInfo){
00400 float shwEnergyInNueGeV = showerInfo->ph.mip;
00401 shwEnergyInNueGeV = shwEnergyInNueGeV/kMEUPerGeV;
00402
00403 if(shwEnergyInNueGeV > HighCuts.srshower.phNueGeV)
00404 goodEvent = false;
00405 }
00406
00407 return goodEvent;
00408 }
00409
00410 bool NueAnalysisCuts::PassesLowShowerEnergyCut()
00411 {
00412 if(!IsValid()) return false;
00413
00414 bool goodEvent = true;
00415 if(LowCuts.srshower.phNueGeV < 0) return goodEvent;
00416
00417 if(nrInfo){
00418 int nShw = nrInfo->srevent.showers;
00419 if(nShw == 0) goodEvent = false;
00420 if(nShw == 1 && nrInfo->srshower.phNueGeV < LowCuts.srshower.phNueGeV)
00421 goodEvent = false;
00422 if(nShw > 1 && nrInfo->srshower.phNueGeV < LowCuts.srshower.phNueGeV/2)
00423 goodEvent = false;
00424
00425 }else
00426 if(stInfo && showerInfo){
00427 float EnergyInNueGeV = showerInfo->ph.mip;
00428 EnergyInNueGeV = EnergyInNueGeV/kMEUPerGeV;
00429 int nShw = eventInfo->nshower;
00430
00431 if(nShw == 0) goodEvent = false;
00432 if(nShw == 1 && EnergyInNueGeV < LowCuts.srshower.phNueGeV)
00433 goodEvent = false;
00434 if(nShw > 1 && EnergyInNueGeV < LowCuts.srshower.phNueGeV/2)
00435 goodEvent = false;
00436 }
00437
00438 return goodEvent;
00439 }
00440
00441 bool NueAnalysisCuts::PassesHighEnergyCut()
00442 {
00443 if(!IsValid()) return false;
00444
00445 bool goodEvent = true;
00446 if(HighCuts.srevent.phNueGeV < 0) return goodEvent;
00447
00448 if(nrInfo){
00449 if(nrInfo->srevent.phNueGeV > HighCuts.srevent.phNueGeV)
00450 goodEvent = false;
00451 }else
00452 if(stInfo && eventInfo){
00453 float EnergyInNueGeV = eventInfo->ph.mip;
00454 EnergyInNueGeV = EnergyInNueGeV/kMEUPerGeV;
00455
00456 if(EnergyInNueGeV > HighCuts.srevent.phNueGeV)
00457 goodEvent = false;
00458 }
00459
00460 return goodEvent;
00461 }
00462
00463 bool NueAnalysisCuts::PassesLowEnergyCut()
00464 {
00465 if(!IsValid()) return false;
00466 bool goodEvent = true;
00467 if(LowCuts.srevent.phNueGeV < 0) return goodEvent;
00468
00469 if(nrInfo){
00470 if(nrInfo->srevent.phNueGeV < HighCuts.srevent.phNueGeV)
00471 goodEvent = false;
00472 }else
00473 if(stInfo && eventInfo){
00474 float EnergyInNueGeV = eventInfo->ph.mip;
00475 EnergyInNueGeV = EnergyInNueGeV/kMEUPerGeV;
00476
00477 if(EnergyInNueGeV < HighCuts.srevent.phNueGeV)
00478 goodEvent = false;
00479 }
00480
00481 return goodEvent;
00482 }
00483
00484
00485
00486
00487
00488 bool NueAnalysisCuts::PassesFullContainment()
00489 {
00490 if(!IsValid()) return false;
00491
00492 if(fContainmentCut == 0) return true;
00493
00494 if(nrInfo == 0){
00495 MAXMSG("NueAnalysisCuts",Msg::kError,10)
00496 <<"FullContainment may only be called on ana_nue files"
00497 <<" the cut will not be applied"<<endl;
00498 return true;
00499 }
00500
00501 bool goodEvent = false;
00502
00503 if(fDetectorType == Detector::kFar)
00504 goodEvent = (nrInfo->anainfo.isFullyContained == 1);
00505
00506 if(fDetectorType == Detector::kNear)
00507 goodEvent = (nrInfo->anainfo.isFullyContained == 1 ||
00508 nrInfo->anainfo.isFullyContained == -2);
00509
00510 return goodEvent;
00511 }
00512
00513 bool NueAnalysisCuts::PassesFiducialVolume()
00514 {
00515 if(!IsValid()) return false;
00516 if(fFiducialCut == 0) return true;
00517
00518 bool goodEvent = false;
00519
00520 float x = -9999; float y = -9999; float z = -9999;
00521 FillVertexPosition(x,y,z);
00522
00523 if(x + y + z < -1000) return false;
00524
00525 if(fDetectorType == Detector::kFar)
00526 goodEvent = IsInsideFarFiducial(x,y,z);
00527 if(fDetectorType == Detector::kNear)
00528 goodEvent = IsInsideNearFiducial(x,y,z);
00529
00530 return goodEvent;
00531 }
00532
00533 void NueAnalysisCuts::FillVertexPosition(float &x, float &y, float &z)
00534 {
00535 if(nrInfo){
00536 if(fFidVtxChoice == FiducialAlg::kUseEvtVtx){
00537 x = nrInfo->srevent.vtxX;
00538 y = nrInfo->srevent.vtxY;
00539 z = nrInfo->srevent.vtxZ;
00540 }
00541 if(fFidVtxChoice == FiducialAlg::kUseTrkVtx){
00542 x = nrInfo->srtrack.vtxX;
00543 y = nrInfo->srtrack.vtxY;
00544 z = nrInfo->srtrack.vtxZ;
00545 }
00546 }
00547
00548 if(eventInfo || trackInfo){
00549 if(eventInfo && fFidVtxChoice == FiducialAlg::kUseEvtVtx){
00550 x = eventInfo->vtx.x;
00551 y = eventInfo->vtx.y;
00552 z = eventInfo->vtx.z;
00553 }
00554 if(trackInfo && fFidVtxChoice == FiducialAlg::kUseTrkVtx){
00555 x = trackInfo->vtx.x;
00556 y = trackInfo->vtx.y;
00557 z = trackInfo->vtx.z;
00558 }
00559 }
00560
00561 return;
00562 }
00563
00564 bool NueAnalysisCuts::IsInsideNearFiducial(float x, float y, float z)
00565 {
00566 if(fFidVolumeChoice == FiducialAlg::kDefaultVolume)
00567 return (infid(fDetectorType, fSimFlag, x,y,z) > 0);
00568 if(fFidVolumeChoice == FiducialAlg::kExtendedVolume){
00569 return (NueConvention::IsInsideNearFiducial_Nue_Extended(x,y,z) > 0);
00570 }
00571 return false;
00572 }
00573
00574 bool NueAnalysisCuts::IsInsideFarFiducial(float x, float y, float z)
00575 {
00576 if(fFidVolumeChoice == FiducialAlg::kDefaultVolume)
00577 return (infid(fDetectorType, fSimFlag, x,y,z) > 0);
00578 if(fFidVolumeChoice == FiducialAlg::kExtendedVolume){
00579 return (NueConvention::IsInsideFarFiducial_Nue_Extended(x,y,z) > 0);
00580 }
00581 return false;
00582 }
00583
00584
00585
00586
00587
00588 bool NueAnalysisCuts::PassesHotChannel()
00589 {
00590 if(!IsValid()) return false;
00591
00592 bool goodEvent = true;
00593 if(fCheckHotChannel == 0) return goodEvent;
00594
00595 if(nrInfo){
00596 if(nrInfo->srevent.hotch == 1) goodEvent = false;
00597 }else
00598 if(stInfo){
00599 if(fDetectorType == Detector::kFar) return true;
00600 TClonesArray* Strips = ntpManipulator.GetStripArray();
00601
00602 for(int i=0;i<eventInfo->nstrip;i++){
00603 NtpSRStrip *strip =
00604 dynamic_cast<NtpSRStrip *>(Strips->At(eventInfo->stp[i]));
00605 if(!strip){
00606 MSG("NueAnalysisCuts",Msg::kError)<<"Couldn't get strip "
00607 <<endl;
00608 return true;
00609 }
00610 if(strip->ph0.raw+strip->ph1.raw>60000) goodEvent = false;
00611 }
00612 }
00613
00614 return goodEvent;
00615 }
00616
00617 bool NueAnalysisCuts::PassesLowPhNStripCut()
00618 {
00619 if(!IsValid()) return false;
00620
00621 bool goodEvent = true;
00622 if(LowCuts.shwfit.hiPhStripCount < 0) return goodEvent;
00623
00624 if(nrInfo){
00625 if(nrInfo->shwfit.hiPhStripCount < LowCuts.shwfit.hiPhStripCount)
00626 goodEvent = false;
00627 }else
00628 if(stInfo){
00629 MAXMSG("NueAnalysisCuts",Msg::kError,10)
00630 <<"PhNStripCut may only be called on ana_nue files"
00631 <<" the cut will not be applied"<<endl;
00632 }
00633
00634 return goodEvent;
00635 }
00636
00637 bool NueAnalysisCuts::PassesLowPhNPlaneCut()
00638 {
00639 if(!IsValid()) return false;
00640
00641 bool goodEvent = true;
00642 if(LowCuts.shwfit.hiPhPlaneCountM2 < 0) return goodEvent;
00643
00644 if(nrInfo){
00645 if(nrInfo->shwfit.hiPhPlaneCountM2 < LowCuts.shwfit.hiPhPlaneCountM2)
00646 goodEvent = false;
00647 }else
00648 if(stInfo){
00649 MAXMSG("NueAnalysisCuts",Msg::kError,10)
00650 <<"PhNPlaneCutM2 may only be called on ana_nue files"
00651 <<" the cut will not be applied"<<endl;
00652 }
00653
00654 return goodEvent;
00655 }
00656
00657 bool NueAnalysisCuts::PassesPhProngCut()
00658 {
00659 if(!IsValid()) return false;
00660
00661 bool goodEvent = true;
00662 if(fPhProngCut < 0) return goodEvent;
00663
00664 if(nrInfo){
00665 float prongPh = TMath::Max(nrInfo->srtrack.pulseHeight,
00666 nrInfo->srshower.pulseHeight);
00667 if(prongPh< fPhProngCut)
00668 goodEvent=false;
00669 }else
00670 if(stInfo){
00671 if(showerInfo || trackInfo){
00672 float shwEnergy = 0;
00673 float trkEnergy = 0;
00674 if(showerInfo) shwEnergy = showerInfo->ph.mip;
00675 if(trackInfo) trkEnergy = trackInfo->ph.mip;
00676 float prongPh = TMath::Max(shwEnergy, trkEnergy);
00677
00678 if(prongPh< fPhProngCut) goodEvent=false;
00679 }else{
00680 goodEvent = false;
00681 }
00682 }
00683
00684 return goodEvent;
00685 }
00686
00687
00688
00689
00690
00691 bool NueAnalysisCuts::IsSignal()
00692 {
00693 if(!IsValid()) return false;
00694 if(!IsMC()) return true;
00695 if(fCutClasses == 0) return true;
00696
00697 bool goodEvent = false;
00698 Int_t cType = -10;
00699
00700 if(nrInfo) cType = nrInfo->mctrue.fNueClass;
00701 if(mcInfo){
00702 int inu = mcInfo->inu;
00703 int inunoosc = mcInfo->inunoosc;
00704 int iaction = mcInfo->iaction;
00705 cType = ClassType::DetermineClassType(inu, inunoosc, iaction);
00706 }
00707
00708 for(unsigned int i = 0; i < signalClasses.size(); i++){
00709 if(signalClasses[i] == cType)
00710 goodEvent = true;
00711 }
00712
00713 return goodEvent;
00714 }
00715
00716 bool NueAnalysisCuts::IsBackground()
00717 {
00718 if(!IsValid()) return false;
00719 if(!IsMC()) return true;
00720 if(fCutClasses == 0) return true;
00721
00722 bool goodEvent = false;
00723 Int_t cType = -10;
00724
00725 if(nrInfo) cType = nrInfo->mctrue.fNueClass;
00726 if(mcInfo){
00727 int inu = mcInfo->inu;
00728 int inunoosc = mcInfo->inunoosc;
00729 int iaction = mcInfo->iaction;
00730 cType = ClassType::DetermineClassType(inu, inunoosc, iaction);
00731 }
00732
00733 for(unsigned int i = 0; i < bgClasses.size(); i++){
00734 if(bgClasses[i] == cType)
00735 goodEvent = true;
00736 }
00737
00738 return goodEvent;
00739 }
00740
00741 bool NueAnalysisCuts::PassesCutOnClasses()
00742 {
00743 if(!IsValid()) return false;
00744 if(!IsMC()) return true;
00745 if(fCutClasses == 0) return true;
00746
00747 bool goodEvent = false;
00748 if(IsSignal() || IsBackground())
00749 goodEvent = true;
00750
00751 return goodEvent;
00752 }
00753
00754
00755 bool NueAnalysisCuts::PassesResonanceCode()
00756 {
00757 if(!IsValid()) return false;
00758 if(!IsMC()) return true;
00759 if(fCutResCode != 1) return true;
00760
00761 bool goodEvent = true;
00762
00763 int code = 0;
00764 if(nrInfo) code = nrInfo->mctrue.resonanceCode;
00765 if(mcInfo) code = mcInfo->iresonance;
00766
00767 if(IsSignal() && sigResonanceCodes.size() > 0)
00768 {
00769 goodEvent = false;
00770 for(unsigned int i = 0; i < sigResonanceCodes.size(); i++)
00771 {
00772 if(code == sigResonanceCodes[i]) goodEvent = true;
00773 }
00774 }
00775 if(IsBackground() && bgResonanceCodes.size() > 0)
00776 {
00777 goodEvent = false;
00778 for(unsigned int i = 0; i < bgResonanceCodes.size(); i++)
00779 {
00780 if(code == bgResonanceCodes[i]) goodEvent = true;
00781 }
00782 }
00783
00784 return goodEvent;
00785 }
00786
00787 bool NueAnalysisCuts::PassesEMFraction()
00788 {
00789 if(!IsValid()) return false;
00790 if(!IsMC()) return true;
00791 bool goodEvent = true;
00792
00793 goodEvent = PassesHighEMFraction();
00794 goodEvent = goodEvent && PassesLowEMFraction();
00795
00796 return goodEvent;
00797 }
00798
00799 bool NueAnalysisCuts::PassesHighEMFraction()
00800 {
00801 if(!IsValid()) return false;
00802 if(!IsMC()) return true;
00803
00804 float emfrac = 0.0;
00805 if(nrInfo) emfrac = nrInfo->mctrue.emShowerFraction;
00806 if(mcInfo) emfrac = mcInfo->emfrac;
00807
00808 bool goodEvent = true;
00809 if(IsSignal())
00810 {
00811 if(HighSigCuts.emShowerFraction < 0) return true;
00812 if(emfrac > HighSigCuts.emShowerFraction)
00813 goodEvent = false;
00814 }
00815 if(IsBackground())
00816 {
00817 if(HighBgCuts.emShowerFraction < 0) return true;
00818 if(emfrac > HighBgCuts.emShowerFraction)
00819 goodEvent = false;
00820 }
00821
00822 return goodEvent;
00823 }
00824
00825 bool NueAnalysisCuts::PassesLowEMFraction()
00826 {
00827 if(!IsValid()) return false;
00828 if(!IsMC()) return true;
00829
00830 float emfrac = 2.0;
00831 if(nrInfo) emfrac = nrInfo->mctrue.emShowerFraction;
00832 if(mcInfo) emfrac = mcInfo->emfrac;
00833
00834 bool goodEvent = true;
00835 if(IsSignal())
00836 {
00837 if(LowSigCuts.emShowerFraction < 0) return true;
00838 if(emfrac < LowSigCuts.emShowerFraction)
00839 goodEvent = false;
00840 }
00841 if(IsBackground())
00842 {
00843 if(LowBgCuts.emShowerFraction < 0) return true;
00844 if(emfrac < LowBgCuts.emShowerFraction)
00845 goodEvent = false;
00846 }
00847
00848 return goodEvent;
00849 }
00850
00851
00852
00853
00854
00855 bool NueAnalysisCuts::PassesFileCut()
00856 {
00857 if(!IsValid()) return false;
00858 if(fFileTrim == 0) return true;
00859
00860 static vector<FilePosition> eventList;
00861 static unsigned int pos = 0;
00862
00863
00864 if(eventList.size() == 0) {
00865 std::ifstream ins;
00866 ins.open(fFileCutName.c_str());
00867 if(!ins.is_open())
00868 MSG("NueAnalysisCuts", Msg::kError)<<"Unable to open cut file "
00869 <<fFileCutName<<endl;
00870
00871 while(!ins.eof()){
00872 int Snarl, Run, SubRun, Event;
00873 ins>>Run>>SubRun>>Snarl>>Event;
00874 FilePosition temp;
00875 if(!ins.eof()){
00876 temp.Run = Run; temp.SubRun = SubRun;
00877 temp.Snarl = Snarl; temp.Event = Event;
00878 eventList.push_back(temp);
00879 }
00880 }
00881 if(eventList.size() == 0) return false;
00882 }
00883
00884
00885 FilePosition current;
00886
00887 if(nrInfo){
00888 current.Snarl = nrInfo->GetHeader().GetSnarl();
00889 current.Event = nrInfo->GetHeader().GetEventNo();
00890 current.Run = nrInfo->GetHeader().GetRun();
00891 current.SubRun = nrInfo->GetHeader().GetSubRun();
00892 if(IsMC()) current.SubRun = 0;
00893 }
00894
00895 if(stInfo){
00896 current.Snarl = stInfo->GetHeader().GetSnarl();
00897 current.Event = fEventNum;
00898 current.Run = stInfo->GetHeader().GetRun();
00899 current.SubRun = stInfo->GetHeader().GetSubRun();
00900 if(IsMC()) current.SubRun = 0;
00901 }
00902
00903 if(current < eventList[0]) return false;
00904
00905 if(current > eventList[eventList.size() - 1]) return false;
00906
00907 if(pos >= eventList.size())
00908 {
00909 if(current < eventList[eventList.size() - 1]){
00910 MSG("NueAnalysisCuts", Msg::kWarning)<<"Problem with file list "
00911 <<"the file list should always be >= to the position of "
00912 <<"the files being scanned\n"<<endl;
00913 return false;
00914 }
00915 }
00916
00917 if(current > eventList[pos] )
00918 {
00919 while(current > eventList[pos] && pos < eventList.size())
00920 pos++;
00921 }
00922
00923 if(current == eventList[pos])
00924 {
00925 pos++;
00926 return true;
00927 }
00928
00929 if(pos > 0 && current < eventList[pos-1])
00930 {
00931 MSG("NueAnalysisCuts", Msg::kWarning)<<"Problem with file list "
00932 <<" appears to be out of order at position "<<pos<<endl;
00933 return false;
00934 }
00935
00936 return false;
00937 }
00938
00939
00940
00941
00942
00943 bool NueAnalysisCuts::IsGoodBeam()
00944 {
00945 if(!IsValid()) return false;
00946 if(IsMC()) return true;
00947 if(fBeamCut != 1) return true;
00948
00949 if(nrInfo)
00950 return (nrInfo->bmon.goodBeamMon == 1);
00951
00952 if(eventInfo)
00953 MSG("NueAnalysisCuts", Msg::kWarning)<<"Beam Cut cannot be used on NtpSt data"<<endl;
00954
00955 return false;
00956 }
00957
00958 bool NueAnalysisCuts::PassesHornCurrent()
00959 {
00960 if(!IsValid()) return false;
00961 if(IsMC()) return true;
00962 if(fTargetCurrent < 0) return true;
00963
00964 if(nrInfo){
00965 Float_t diffCurrent = TMath::Abs(nrInfo->bmon.hornI) - fTargetCurrent;
00966 bool goodEvent = TMath::Abs(diffCurrent) < 5;
00967 return goodEvent;
00968 }
00969
00970 if(eventInfo)
00971 MSG("NueAnalysisCuts", Msg::kWarning)<<"Beam Cut cannot be used on NtpSt data"<<endl;
00972
00973 return false;
00974 }
00975
00976 bool NueAnalysisCuts::PassesDataQuality()
00977 {
00978 if(!IsValid()) return false;
00979 if(IsMC()) return true;
00980
00981 if(nrInfo == 0)
00982 MSG("NueAnalysisCuts", Msg::kWarning)
00983 <<"Data Quality Cut cannot be used on NtpSt data"<<endl;
00984
00985 bool goodEvent = true;
00986 if(fDetectorType == Detector::kFar)
00987 {
00988 goodEvent = (nrInfo->srevent.liTime == -1);
00989 goodEvent = goodEvent && (nrInfo->srevent.rcBoundary == 0);
00990 goodEvent = goodEvent && (nrInfo->srevent.daveFDDataQuality == 1);
00991 }
00992 if(fDetectorType == Detector::kNear)
00993 {
00994 goodEvent = (nrInfo->srevent.coilCurrent < -1000);
00995 }
00996
00997 return goodEvent;
00998 }
00999
01000
01001
01002
01003 void NueAnalysisCuts::ReportOnRecord(NueRecord *nr, string ID)
01004 {
01005 TClass *cl;
01006 TRealData *rd;
01007 TDataMember *member;
01008 TDataType *membertype;
01009 Float_t value = 0.0;
01010 string vName;
01011
01012 cl=nr->IsA();
01013 TIter next(cl->GetListOfRealData());
01014
01015 while ((rd =dynamic_cast<TRealData*>(next()))) {
01016 member = rd->GetDataMember();
01017 membertype = member->GetDataType();
01018 vName=rd->GetName();
01019
01020 Int_t offset = rd->GetThisOffset();
01021 char *pointer = (char*)nr + offset;
01022 value = -9999;
01023 if(!NeedsSpecialAttention(vName)){
01024 value=atof(membertype->AsString(pointer));
01025 if(!ANtpDefVal::IsDefault(value) &&
01026 !ANtpDefVal::IsDefault(static_cast<Double_t> (value)) &&
01027 !ANtpDefVal::IsDefault(static_cast<Int_t> (value))){
01028 MSG("NueCutReport",Msg::kInfo)<<ID<<"Cut applied on variable "<<vName<<" with value "<<value<<endl;
01029 }
01030 }
01031 }
01032 }
01033
01034 void NueAnalysisCuts::Report()
01035 {
01036 MSG("NueCutReport",Msg::kInfo)
01037 <<"-------------------------- Summary of Cuts ------------------------\n";
01038 ReportOnRecord(&HighCuts, "High End");
01039 ReportOnRecord(&LowCuts, "Low End");
01040
01041
01042 MSG("NueCutReport",Msg::kInfo)
01043 <<"-------------------------- End of Summary -------------------------\n";
01044
01045
01046 }
01047
01048
01049 bool NueAnalysisCuts::NeedsSpecialAttention(TString name)
01050 {
01051
01052 if(name == "fHeader.fSnarl"
01053 || name == "fHeader.fRun"
01054 || name == "fHeader.fSubRun"
01055 || name == "fHeader.fEvtNo"
01056 || name == "fHeader.fEvents"
01057 || name == "fHeader.fTrackLength"
01058 || name == "mstvars.eallw1"
01059 || name == "mstvars.oallw1"
01060 || name == "mstvars.eallm1"
01061 || name == "mstvars.oallm1")
01062 return true;
01063
01064 return false;
01065 }
01066
01067