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

NueModule.cxx

Go to the documentation of this file.
00001 
00002 // $Id: NueModule.cxx,v 1.54 2009/08/19 22:05:32 pawloski Exp $
00003 //
00004 // FILL_IN: [Document your code!!]
00005 //
00006 // vahle@hep.ucl.ac.uk
00008 #include <dirent.h>
00009 #include "TFile.h"
00010 #include "TChain.h"
00011 #include "TClonesArray.h"
00012 #include "TProfile2D.h"
00013 #include "StandardNtuple/NtpStRecord.h"
00014 #include "MessageService/MsgService.h"
00015 #include "MinosObjectMap/MomNavigator.h"
00016 #include "JobControl/JobCModuleRegistry.h" // For JOBMODULE macro
00017 #include "Calibrator/CalMIPCalibration.h"
00018 #include "MCNtuple/NtpMCRecord.h"
00019 #include "MCNtuple/NtpMCTruth.h"
00020 #include "TruthHelperNtuple/NtpTHRecord.h"
00021 #include "CandNtupleSR/NtpSRRecord.h"
00022 #include "CandNtupleSR/NtpSRStrip.h"
00023 #include "CandNtupleSR/NtpSREvent.h"
00024 #include "CandNtupleSR/NtpSRTrack.h"
00025 #include "NueAna/NueAnaTools/SntpHelpers.h"
00026 #include "NueAna/Module/NueModule.h"
00027 #include "NueAna/NueRecord.h"
00028 #include "NueAna/NueRecordAna.h"
00029 #include "BeamData/ana/Summary/BeamSummary.h"
00030 #include "MCReweight/MuParentHelper.h"
00031 #include "MCReweight/Zbeam.h"
00032 #include "MCReweight/Zfluk.h"
00033 #include "MCReweight/Kfluk.h"
00034 #include "MCReweight/NeugenWeightCalculator.h"
00035 #include "MCReweight/MCReweight.h"
00036 #include "MuonRemoval/NtpMRRecord.h"
00037 #include "CalDetDST/UberRecord.h"
00038 #include "MCReweight/SKZPWeightCalculator.h"
00039 #include "VertexFinder/NtpVtxFinder/NtpVtxFinder.h"
00040 #include "MuonRemoval/NtpMREvent.h"
00041 
00042 #include "NueAna/NueStandard.h"
00043 #include "NueAna/NueAnaTools/Selection.h"
00044 #include "DataUtil/GetTempTags.h"   
00045 #include "TSystem.h"
00046 #include "NueAna/Module/SetKNNModule.h"
00047 
00048 #include "PhysicsNtuple/Handle.h"
00049 #include "PhysicsNtuple/Factory.h"
00050 
00051 
00052 CVSID("$Id: NueModule.cxx,v 1.54 2009/08/19 22:05:32 pawloski Exp $");
00053 
00054 #include "DatabaseInterface/DbiResultPtr.tpl"
00055 
00056 
00057 JOBMODULE(NueModule, "NueModule",
00058           "");
00059 //......................................................................
00060 
00061 NueModule::NueModule():
00062    tmpltfile(""),
00063    kDPlaneCut(-1),
00064    kLoPhNStripCut(-1),
00065    kLoPhNPlaneCut(-1),
00066    kPhStripCut(-1),
00067    kPhPlaneCut(-1),
00068    kCPhPlaneCut(-1),
00069    kBeamType(BeamType::kUnknown),
00070    kMuPiDir(""),
00071    kOpenedMuPiFile(false),
00072    counter(0),
00073    passcounter(0),
00074    passcutcounter(0),
00075    failcounter(0),
00076    writecounter(0),
00077    foundmeu(false),
00078    MSTminsig(0.),
00079    MSTmaxmetric(0.),
00080    MSTminfarsig(0.),
00081    MSTmaxmetriclowz(0.),
00082    SIGMAPMEU(1.),
00083    MSTetemplate(0),
00084    MSTbtemplate(0),
00085    MSTemtemplate(0),
00086    MSTbmtemplate(0),
00087    threshCut(0.),
00088    sasFileName(""),
00089    pot(0.),
00090    MEUPERGEV(25),   //not correct but close, correctly set by NueCalibration
00091                     //  adjusted on 01-08-2008 by JAB
00092    foundRelease(false),
00093    release(0),
00094    //   skzpcfg("PiMinus_CedarDaikon")
00095    skzpcfg("DetXs")
00096 {
00097 
00098 //make sure that pointers that have objects deleted at end are initialized at 0 to start
00099   mupar=0;
00100   zbeam=0;
00101   skzpCalc=0;
00102   zfluk=0;
00103   kfluk=0;
00104 //end ptr initilization
00105 
00106 
00107   if(kFixMuParents){
00108     mupar = new MuParentHelper();
00109   }
00110   else{
00111     mupar=0;
00112   }
00113 //  zbeam = new Zbeam();
00114 //  zfluk = new Zfluk();
00115 //  zfluk->UseParameterization("SKZP"); //this is the default
00116 //  kfluk = new Kfluk();
00117   kfluk = 0;
00118 
00119   skzpCalc = new SKZPWeightCalculator(skzpcfg, true);
00120   mcr = &MCReweight::Instance();
00121   //  NeugenWeightCalculator *n=new NeugenWeightCalculator();
00122   //  mcr->AddWeightCalculator(n);
00123 
00124   xsecreweightreg = new Registry();
00125   xsecreweightreg->UnLockValues();
00126   xsecreweightreg->UnLockKeys();
00127   xsecreweightreg->Clear();
00128   //  xsecreweightreg->Set("neugen:config_name","MODBYRS");
00129   //  xsecreweightreg->Set("neugen:config_no",3);
00130   xsecreweightreg->LockValues();
00131   xsecreweightreg->LockKeys();
00132 
00133   mrccRun = false;
00134   
00135   kPidName = "None";
00136   kPIDHighCut = ANtpDefVal::kDouble;
00137   kPIDLowCut = ANtpDefVal::kDouble;
00138   kCCPIDCut = ANtpDefVal::kDouble;
00139   kHighECut = ANtpDefVal::kDouble;
00140   kLowECut = ANtpDefVal::kDouble;
00141 }
00142 
00143 //......................................................................
00144 
00145 NueModule::~NueModule()
00146 {
00147   if(mupar){
00148     delete mupar;
00149     mupar=0;
00150   }
00151   if(zbeam){
00152     delete zbeam;
00153     zbeam=0;
00154   }
00155 
00156   if(skzpCalc){
00157     delete skzpCalc;
00158     skzpCalc=0;
00159   }
00160   if(zfluk){
00161     delete zfluk;
00162     zfluk=0;
00163   }
00164   if(kfluk){
00165     delete kfluk;
00166     kfluk=0;
00167   }
00168 }
00169 
00170 //.......................................................................
00171 
00172 JobCResult NueModule::Reco(MomNavigator* mom)
00173 {
00174 //======================================================================
00175 // Reads in sue-style ntuples from mom, calculates a bunch of useful
00176 // nue quantites
00177 //======================================================================
00178    MSG("NueModule",Msg::kDebug)<<"In NueModule::Reco"<<endl;
00179 
00180    if(counter%1000==0){      
00181       MSG("NueModule",Msg::kInfo)<<"On entry "<<counter<<endl;
00182    }
00183    counter++;
00184    bool foundMR=false;
00185    bool foundUR=false;
00186 
00187    bool foundST=false;
00188 //   bool passesCuts = false;
00189 
00190    NtpStRecord *str = 0;
00191    NtpStRecord *oldst = 0;
00192    NtpMRRecord *mr = 0;
00193 
00194 
00195    VldContext vc;  
00196    str = dynamic_cast<NtpStRecord *>(mom->GetFragment("NtpStRecord",
00197                                                       "Primary"));
00198 
00199    std::vector<TObject*> stRecords =  mom->GetFragmentList("NtpStRecord");
00200 
00201    if(str){
00202      foundST=true;
00203      vc=str->GetHeader().GetVldContext();
00204      if(!foundRelease){
00205         release = str->GetRelease();
00206         foundRelease = true; 
00207         title = ReleaseType::AsString(release);
00208         string file = DataUtil::GetTempTagString(str, "file");
00209         filename = gSystem->BaseName(file.c_str());
00210      }
00211      //check for MR:
00212      mr =  dynamic_cast<NtpMRRecord *>(mom->GetFragment("NtpMRRecord"));
00213      if(mr){
00214        if(ReleaseType::IsBirch(release)) {
00215          oldst=dynamic_cast<NtpStRecord *>(mom->GetFragment("NtpStRecord",
00216                                                             "NtpStRecordOld")); 
00217        }
00218        else {
00219          oldst=str;
00220          str=dynamic_cast<NtpStRecord *>(mom->GetFragment("NtpStRecord",
00221                                                           "MuonRemoved"));
00222        }
00223        if(oldst) foundMR = true;
00224      }
00225    }
00226 
00227    if(!foundST&&!foundMR){
00228       //got nothing useful from mom
00229       MSG("NueModule",Msg::kWarning)<<"Got Nothing from mom"<<endl;
00230       failcounter++;
00231       return JobCResult::kFailed;
00232    }
00233    if(mrccRun&&!(foundMR&&foundST)){
00234       return JobCResult::kFailed;
00235    }
00236 
00237 
00238    std::vector<TObject*> urRecords =  mom->GetFragmentList("UberRecord");
00239    if(urRecords.size()) foundUR=true;
00240    
00241    //UGLY!!!!
00242    //need to be able to compare single strip 
00243    //pulseheight between ND and FD, but we can't
00244    //in the ntuple.  Will ask the db for the
00245    //conversion from sigcor to MEU 
00246    //on the first event, and use throughout.  
00247    //Since sigcorrs are already corrected for all strip variations, 
00248    //it's ok to ask for 1 number.  
00249    //Should be ok for MC, maybe ok for 1 run of data at a time, but will
00250    //definitely be wrong if many weeks worth of data are strung together
00251    //we should revisit this and make it better in the future!!!!!!!
00252    if(!foundmeu)
00253    {
00254     //Setup and give context
00255     DbiResultPtr<CalMIPCalibration> fResPtr;
00256     fResPtr.NewQuery(vc,10);
00257 
00258     //Get Scale
00259     if(fResPtr.GetNumRows()>0)
00260     {
00261      const CalMIPCalibration* mipcal = fResPtr.GetRow(0);
00262      SIGMAPMEU = mipcal->GetScale();
00263      foundmeu=true;
00264     }
00265    }
00266 
00267   bool oneGood = false;
00268   //check if we find a UberRecord
00269   if(foundUR){
00270     //if we did, it's a caldet record and we have to treat it specially
00271     //note, we're assuming we will never want to MRCC caldet!
00272     for(unsigned int i = 0; i < stRecords.size(); i++)
00273       {
00274         UberRecord* uTemp = 0;
00275         NtpStRecord* st  = dynamic_cast<NtpStRecord *>(stRecords[i]);
00276         if(foundUR) uTemp = dynamic_cast<UberRecord *>(urRecords[i]);
00277         Analyze(mom,st, 0, uTemp, oldst);
00278         oneGood = true;
00279       }
00280   }
00281   else{
00282     //its not caldet, and there should only be one StRecord, one MRRecord, and no UberRecords
00283     Analyze(mom,str,mr,0,oldst);
00284     oneGood=true;
00285   }
00286 
00287   if(oneGood)  return JobCResult::kPassed ;
00288   return JobCResult::kFailed;
00289 }
00290 
00291 JobCResult NueModule::Analyze(MomNavigator* mom, NtpStRecord* str, NtpMRRecord* mr, UberRecord* ur, NtpStRecord* oldst)
00292 {
00293    bool foundSR=false;
00294    bool foundMC=false;
00295    bool foundTH=false;
00296    bool foundMR=false;
00297    bool foundUR=false;
00298 
00299    bool foundST=false;
00300    bool passesCuts = false;
00301 
00302   if(str) foundST = true;
00303   if(mr) foundMR = true;
00304   if(ur) foundUR = true;
00305 
00306 
00307   int evtn = 0;
00308   const RecCandHeader *header = 0;
00309   VldContext vc;
00310    
00311    if(foundST){ 
00312      vc=str->GetHeader().GetVldContext();
00313      evtn=str->evthdr.nevent;
00314      header = &(str->GetHeader());
00315    }
00316 
00317 //   if(!foundSR&&foundMC){
00318 //      vc = mc->GetHeader().GetVldContext();
00319 //      header = &(mc->GetHeader());
00320 //      evtn = 0;
00321 //   }
00322 
00323    if(foundSR){
00324 //     MSG("NueModule",Msg::kDebug)<<"Got SR from mom"<<endl;
00325 //     evtn=sr->evthdr.nevent;
00326 //     header = &(sr->GetHeader());
00327    }
00328 
00329    //if first event and we want to fix the Mu parents,
00330    // set the mupar file directory
00331    if(header->GetVldContext().GetSimFlag() == SimFlag::kData)
00332      kFixMuParents = 0;
00333 
00334    if(ReleaseType::IsData(release))
00335       kBeamType = DetermineBeamType(vc);
00336    else
00337       kBeamType = DetermineBeamType(filename);
00338 
00339    if(!kOpenedMuPiFile&&kFixMuParents && ReleaseType::IsCarrot(release)){
00340      string flxsfx="le010z185i";
00341      if(kBeamType==BeamType::kL010z185i){     flxsfx="le010z185i";  }
00342      else if(kBeamType==BeamType::kL100z200i){flxsfx="le100z200i";  }
00343      else if(kBeamType==BeamType::kL250z200i){flxsfx="le250z200i";  }
00344      else if(kBeamType==BeamType::kL150z200i){flxsfx="le150z200i";  }
00345      else if(kBeamType==BeamType::kL010z170i){flxsfx="le010z170i";  }
00346      else if(kBeamType==BeamType::kL010z200i){flxsfx="le010z200i";  }
00347      else if(kBeamType==BeamType::kL010z000i){flxsfx="le010z000i";  }
00348         
00349      string fullPath = kMuPiDir + flxsfx;
00350      mupar->SetFileDir(kMuPiDir,true);
00351      kOpenedMuPiFile=true;
00352    }
00353 
00354    MSG("NueModule",Msg::kDebug)<<"Events in this snarl: "<<evtn<<endl;
00355 
00356    if(ReleaseType::IsData(release))
00357       kBeamType = DetermineBeamType(vc);
00358 
00359 
00360    bool fUseROPID = true;
00361    //Loading up Rustems variables
00362    Anp::Handle<StorekNNData> data = Anp::Factory<StorekNNData>::Instance().Get("kNNData");
00363    if(!data.valid())
00364    {
00365       MAXMSG("NueModule", Msg::kError, 1)
00366           << "NueModule::Reco - Handle<StorekNNData> is invalid, assuming no Rustem variable to run" 
00367           << endl;
00368       fUseROPID = false;
00369    }
00370 
00371    if(fUseROPID){
00372      VldContext roVld = data->GetValidity();
00373      if(roVld != vc){
00374         MSG("NueModule", Msg::kError)
00375           << "NueModule::Reco - Validity sheer when trying to access Rustem's PID, assuming no Rustem variable to run"
00376           << endl;
00377         fUseROPID = false;
00378      }
00379    }           
00380    //int kzarkoBeamType = BeamType::ToZarko(kBeamType);
00381                                              
00382    if(evtn == 0)
00383    {
00384       NueHeader h(vc);
00385       h.SetSnarl(header->GetSnarl());
00386       h.SetRun(header->GetRun());
00387       h.SetSubRun(header->GetSubRun());
00388       h.SetEventNo(-1);
00389       h.SetEvents(0);
00390       h.SetTrackLength(0);
00391       h.SetRelease(release);
00392       h.SetBeamType(kBeamType);
00393       h.SetFoundBits(foundSR, foundMC || foundST, foundTH,foundMR);
00394 
00395      //make an ana_nue object
00396      NueRecord *nue = new NueRecord(h);
00397      //make a nuerecordana object
00398      NueRecordAna ana_nue(*nue);
00399      ana_nue.SetRelease(release);
00400      ana_nue.SetBeamType(kBeamType);
00401 
00402      nue->SetTitle(title.c_str());
00403      //fill the truth info
00404      //if it's data, we can also do beam mon analyze
00405      //  ana_nue.bmona.SetBeamSummary(bsum);
00406                                                                                 
00407      //must set the beam and parent helper to fill flux info
00408 //     ana_nue.anaia.SetBeam(kzarkoBeamType);
00409 //     ana_nue.nuefwa.SetBeam(kzarkoBeamType);
00410 //     ana_nue.anaia.SetBeam(kBeamType);
00411 //     ana_nue.nuefwa.SetBeam(kBeamType);
00412      ana_nue.nuefwa.SetSKZPCalc(skzpCalc, skzpcfg);
00413 //     ana_nue.nuefwa.SetZfluk(zfluk);
00414      ana_nue.nuefwa.SetKfluk(kfluk);
00415      ana_nue.fiana.SetMuParentHelper(mupar);
00416      ana_nue.fiana.FixMuParents(kFixMuParents);
00417                
00418      //set xsec registry and mcreweight to do xsec reweighting
00419      ana_nue.nuexsa.SetMCReweight(mcr);
00420      ana_nue.nuexsa.SetRegistry(xsecreweightreg);
00421      
00422      if(foundST)
00423        ana_nue.FillTrue(0,str);
00424 //     if(foundMC || foundSR)
00425 //       ana_nue.FillTrue(0,sr,mc,th);
00426 
00427      ana_nue.aneia.Analyze(-10,str);  //need to fill srevent to get quality
00428      ana_nue.equala.Analyze(-10, str);
00429                                                                                 
00430      //give the ana_nue object to mom, she'll write it to the file
00431      mom->AdoptFragment(nue);
00432      writecounter++;
00433      failcounter++;
00434      if(fUseROPID) data->Clear();
00435      return JobCResult::kPassed;
00436    }
00437 
00438    bool anypassed = false;
00439 
00440    //Correct all the vertex information 
00441    // because of the nearby event check this has to be done all at once 
00442    //  and seperate from the analysis loop
00443 
00444 
00445    if(ReleaseType::IsCedar(release)){
00446     for(int i = 0; i < evtn; i++){
00447       NtpSREvent *event = SntpHelpers::GetEvent(i,str);
00448       if(event == 0) continue;
00449 
00450       NtpVtxFinder vtxf;
00451       vtxf.SetTargetEvent(i, str);
00452       if(vtxf.FindVertex() > 0){
00453         event->vtx.x = vtxf.VtxX();
00454         event->vtx.y = vtxf.VtxY();
00455         event->vtx.z = vtxf.VtxZ();
00456         event->vtx.u = vtxf.VtxU();
00457         event->vtx.v = vtxf.VtxV();
00458         event->vtx.t = vtxf.VtxT();
00459         event->vtx.plane = vtxf.VtxPlane();
00460       }
00461     }
00462    }
00463 
00464   const int SIZE = (str->evthdr).nstrip;
00465   float* ph0 = new float[SIZE];
00466   float* ph1 = new float[SIZE];
00467 
00468   for(int i=0;i<evtn;i++){
00469      passesCuts = false;
00470 
00471      for(int k=0; k < SIZE; k++) { ph0[k] = ph1[k] = -1;}
00472 
00473      SntpHelpers::FillEventEnergy(ph0, ph1, i, str, SIZE);
00474 
00475      for(int k=0; k < SIZE; k++) { 
00476        //Protection for uncalibrated strips
00477        // no evidence they exist but still protected
00478        if(ph0[k] < 0) ph0[k] = 0;
00479        if(ph1[k] < 0) ph1[k] = 0;
00480      }
00481  
00482      //make a header
00483      NueHeader h(vc);
00484      
00485      //fill header info
00486      h.SetSnarl(header->GetSnarl());
00487      h.SetRun(header->GetRun());
00488      h.SetSubRun(header->GetSubRun());
00489      h.SetEventNo(i);
00490      h.SetEvents(evtn);
00491      h.SetRelease(release);
00492      h.SetNueRelease(NueConvention::kGriffin);
00493      h.SetBeamType(kBeamType);
00494      h.SetFoundBits((foundSR || foundST), foundMC || foundST,
00495                     foundTH || foundST, foundMR);
00496 
00497      MSG("NueModule",Msg::kDebug)<<"Getting event "<<evtn<<endl;
00498      
00499      NtpSREvent *event = 0;
00500      if(foundST) event = SntpHelpers::GetEvent(i,str);
00501 //     if(foundSR) event = SntpHelpers::GetEvent(i,sr);
00502      
00503      //loop over tracks in this event, find longest
00504      int longtrack=0;
00505      if(event){
00506        for(int j=0;j<event->ntrack;j++){
00507            int tindex = SntpHelpers::GetTrackIndex(j,event);
00508            NtpSRTrack *track = 0;
00509            if(foundST) track = SntpHelpers::GetTrack(tindex,str);
00510 //           if(foundSR) track = SntpHelpers::GetTrack(tindex,sr);
00511            if(track && longtrack<track->plane.n){
00512               longtrack = track->plane.n;
00513            }
00514         }
00515      }
00516      
00517      h.SetTrackLength(longtrack);
00518      
00519      NueRecord *nue = new NueRecord(h);
00520      //make a nuerecordana object
00521      NueRecordAna ana_nue(*nue);
00522      ana_nue.SetRelease(release);
00523      ana_nue.SetBeamType(kBeamType);
00524      ana_nue.SetEventEnergyArray(ph0, ph1);
00525 
00526      nue->SetTitle(title.c_str());
00527 
00528      
00529      if(foundST && event != 0)
00530      {                   
00531         fCut.SetInfoObject(i, str);
00532         passesCuts = fCut.PassesAllCuts();
00533      }
00534 
00535      if(foundSR && event != 0)
00536      {
00537        passesCuts = true;
00538        MSG("NueModule",Msg::kWarning)
00539           <<"Unable to cut on pre-Birch files - why are you running these files?"<<endl;
00540      }
00541      
00542      ana_nue.aneia.SetParams(SIGMAPMEU, MEUPERGEV);
00543      ana_nue.ansia.SetParams(SIGMAPMEU, MEUPERGEV);
00544      ana_nue.antia.SetParams(SIGMAPMEU, MEUPERGEV);
00545      ana_nue.hca.SetParams(SIGMAPMEU, MEUPERGEV);
00546 
00547      //must set the beam and parent helper to fill flux info
00548 //     ana_nue.nuefwa.SetBeam(kzarkoBeamType);
00549 //     ana_nue.nuefwa.SetBeam(kBeamType);
00550      ana_nue.nuefwa.SetSKZPCalc(skzpCalc, skzpcfg);
00551 
00552 //     ana_nue.nuefwa.SetZbeam(zbeam);
00553 //     ana_nue.nuefwa.SetZfluk(zfluk);
00554      ana_nue.nuefwa.SetKfluk(kfluk);
00555      ana_nue.fiana.SetMuParentHelper(mupar);
00556      ana_nue.fiana.FixMuParents(kFixMuParents);
00557 
00558      //set xsec registry and mcreweight to do xsec reweighting
00559      ana_nue.nuexsa.SetMCReweight(mcr);
00560      ana_nue.nuexsa.SetRegistry(xsecreweightreg);
00561 
00562      if(event != 0){
00563 
00564        if(foundST){
00565          if(!foundMR){
00566            ana_nue.FillTrue(i,str);
00567          }
00568                  else{
00569            //find the best matching rmmu entry for this event
00570            Int_t best_rmmu = -1;
00571            //Int_t best_rmmu = i;
00572            Float_t best_com = 0;
00573            for(int xi=0;xi<mr->mrhdr.nmrevt;xi++){        
00574              NtpMREvent *ev = SntpHelpers::GetMREvent(xi,mr);
00575              if(ev && ev->best_event==i && ev->best_complete>best_com) {
00576                best_com = ev->best_complete;
00577                best_rmmu = ev->orig_event;
00578                //              cout<<"found mr match "<<i<<" "<<ev->best_event<<" "<<xi<<endl;
00579              }
00580            }
00581            if(best_rmmu>=0){
00582              ana_nue.FillTrue(best_rmmu,oldst);
00583            }    
00584          }
00585          ana_nue.FillReco(i,str);
00586        }
00587 //       if(foundSR){
00588 //         ana_nue.FillTrue(i,sr,mc,th);
00589 //         ana_nue.FillReco(i,sr);
00590 //       } 
00591                                                                               
00592        if(passesCuts)
00593        {
00594          MSG("NueModule",Msg::kDebug)<<"Tracklength: "<<longtrack
00595             <<"Event Length: "<<event->plane.n
00596             <<"Event Energy: "<<event->ph.sigcor
00597             <<"Event Energy : "<<event->ph.sigcor<<endl;
00598 
00599          passcutcounter++;
00600          //analyze calculates everybodies variables, then calls the Truth and Reco Object Fillers
00601          //configure MSTCalcAna routine
00602          MSG("NueModule",Msg::kDebug)<<"Setting templates: "
00603                                      <<MSTetemplate->GetName()<<" "
00604                                      <<MSTbtemplate->GetName()<<" "
00605                                      <<MSTemtemplate->GetName()<<" "
00606                                      <<MSTbmtemplate->GetName()<<endl;
00607          
00608          ana_nue.msta.SetSigTemplate(MSTetemplate);
00609          ana_nue.msta.SetBGTemplate(MSTbtemplate);
00610          ana_nue.msta.SetSigMIPTemplate(MSTemtemplate);
00611          ana_nue.msta.SetBGMIPTemplate(MSTemtemplate);
00612          ana_nue.msta.SetMSTParams(MSTminsig,MSTmaxmetric,
00613                                    MSTminfarsig,MSTmaxmetriclowz,SIGMAPMEU);
00614          ana_nue.sfa.SetParams(SIGMAPMEU, MEUPERGEV);
00615          ana_nue.sfa.SetCutParams(kDPlaneCut,kPhStripCut,kPhPlaneCut, kCPhPlaneCut);
00616          ana_nue.fva.SetParams(SIGMAPMEU, MEUPERGEV);
00617          ana_nue.mda.SetMdaParams(threshCut, sasFileName);
00618                                
00619          if(foundST)  ana_nue.Analyze(i,str);
00620 //         if(foundSR)  ana_nue.Analyze(i,sr);
00621          if(foundMR)  ana_nue.Analyze(i,mr,oldst);
00622          if(foundUR)  ana_nue.Analyze(ur);
00623        }// end of If(passcuts)
00624        else{
00625          cout<<"Rejecting based on cuts"<<endl;
00626        }
00627      }else{
00628        //No event here - still fill for POT info
00629        ana_nue.aneia.Analyze(-10,str);
00630        ana_nue.equala.Analyze(-10, str);
00631      }
00632 
00633      if(PassesBlindingCuts(nue)){  
00634        anypassed = true;
00635        //give the ana_nue object to mom, she'll write it to the file
00636        MSG("NueModule",Msg::kDebug)<<"Giving Fragment to mom  "<<event<<endl;
00637        writecounter++;
00638        mom->AdoptFragment(nue);
00639        MSG("NueModule",Msg::kDebug)<<"Mom took it"<<endl;
00640      }else{
00641         //we aren't saving this nue object.. so delete it to prevent a memory leak
00642         //sc 7/6/09
00643         delete nue;
00644         nue=0;
00645      }
00646  
00647      if(i+1 == evtn && !anypassed){ 
00648        //push through something so the POT are still counted
00649        h.SetEvents(evtn);
00650        NueRecord *nueblank = new NueRecord(h);
00651        NueRecordAna ana_nue(*nueblank);
00652        ana_nue.SetRelease(release);
00653        ana_nue.SetBeamType(kBeamType);
00654        nueblank->SetTitle(title.c_str());
00655        ana_nue.aneia.Analyze(-10,str);
00656        ana_nue.equala.Analyze(-10, str);
00657        writecounter++;
00658        mom->AdoptFragment(nueblank);
00659      }
00660 
00661    }
00662    delete [] ph0;
00663    delete [] ph1;
00664 
00665    if(fUseROPID) data->Clear();
00666 
00667    MSG("NueModule",Msg::kDebug)<<"Done with snarl"<<endl;
00668    passcounter++;
00669    return JobCResult::kPassed; // kNoDecision, kFailed, etc.
00670 }
00671 
00672 //......................................................................
00673 
00674 const Registry& NueModule::DefaultConfig() const
00675 {
00676 //======================================================================
00677 // Supply the default configuration for the module
00678 //======================================================================
00679    MSG("NueModule",Msg::kDebug)<<"In NueModule::DefaultConfig"<<endl;
00680 
00681   static Registry r  = fCut.DefaultConfig(); // Default configuration for module
00682 
00683   // Set name of config
00684   std::string name = this->GetName();
00685   name += ".config.default";
00686   r.SetName(name.c_str());
00687 
00688   // Set values in configuration
00689   r.UnLockValues();
00690   r.Set("MSTTmpltFile","templates.root");
00691   r.Set("DPlaneCut",-1);
00692   r.Set("LoPhNStripCut",-1);
00693   r.Set("LoPhNPlaneCut",-1);
00694 
00695   r.Set("PhStripCut",-1);
00696   r.Set("PhPlaneCut",-1);
00697   r.Set("ContPhPlaneCut",-1.);
00698 
00699   r.Set("MSTminsig",0.5);
00700   r.Set("MSTmaxmetric",1000.);
00701   r.Set("MSTminfarsig",1.5);
00702   r.Set("MSTmaxmetriclowz",20.);
00703   
00704   r.Set("MdaThreshCut",0.0);
00705   r.Set("MdaSASFile","");
00706   r.Set("BeamString", "");
00707   r.Set("MuPiDir","");
00708   r.Set("BeamType",2);
00709   r.Set("FixMuParents",0);
00710   r.Set("MRCC", 0);
00711 
00712   r.Set("HighEnergyCut", ANtpDefVal::kDouble);
00713   r.Set("LowEnergyCut", ANtpDefVal::kDouble);
00714   r.Set("HighPIDCut", ANtpDefVal::kDouble);
00715   r.Set("LowPIDCut", ANtpDefVal::kDouble);
00716   r.Set("ANTIPID", "None");
00717   r.Set("CCPID", "None");
00718 
00719   r.LockValues();
00720 
00721   return r;
00722 }
00723 
00724 //......................................................................
00725 
00726 void NueModule::Config(const Registry& r)
00727 {
00728 //======================================================================
00729 // Configure the module given the Registry r
00730 //======================================================================
00731   MSG("NueModule",Msg::kDebug)<<"In NueModule::Config"<<endl;
00732 
00733   fCut.Config(r);
00734 
00735   const char* tmps;
00736 
00737   if(r.Get("ANTIPID", tmps)) {kPidName = tmps;}
00738   if(r.Get("CCPID", tmps))      { kCCPidName = tmps;}
00739 
00740   if(r.Get("MSTTmpltFile",tmps)) { tmpltfile = tmps;}
00741   int imps;
00742   if(r.Get("DPlaneCut",imps)) { kDPlaneCut=imps;}
00743   if(r.Get("LoPhNStripCut",imps)) { kLoPhNStripCut=imps;}
00744   if(r.Get("LoPhNPlaneCut",imps)) { kLoPhNPlaneCut=imps;}
00745 
00746   if(r.Get("MdaSASFile",tmps)) { sasFileName = tmps;}
00747 
00748   double fmps;
00749   if(r.Get("HighPIDCut", fmps)) { kPIDHighCut = fmps; }
00750   if(r.Get("LowPIDCut", fmps))  { kPIDLowCut = fmps; }
00751   if(r.Get("CCPIDCut", fmps))   { kCCPIDCut = fmps;  }
00752   if(r.Get("HighEnergyCut", fmps)) { kHighECut = fmps; }
00753   if(r.Get("LowEnergyCut", fmps))  { kLowECut = fmps; }
00754 
00755   if(r.Get("PhStripCut",fmps)) { kPhStripCut=fmps;}
00756   if(r.Get("PhPlaneCut",fmps)) { kPhPlaneCut=fmps;}
00757   if(r.Get("ContPhPlaneCut",fmps)) { kCPhPlaneCut=fmps;}
00758 
00759 
00760   if(r.Get("MSTminsig",fmps)){ MSTminsig=fmps; }
00761   if(r.Get("MSTmaxmetric",fmps)){ MSTmaxmetric=fmps; }
00762   if(r.Get("MSTminfarsig",fmps)){ MSTminfarsig=fmps; }
00763   if(r.Get("MSTmaxmetriclowz",fmps)){ MSTmaxmetriclowz=fmps; }
00764   if(r.Get("MdaThreshCut",fmps)) { threshCut = fmps;}
00765 
00766   if(r.Get("MuPiDir",tmps)){kMuPiDir=(string)(tmps);}
00767 
00768 //  if(r.Get("BeamType",imps)){kBeamType=imps;}
00769 
00770   if(r.Get("BeamString", tmps)){
00771      beamstring = tmps;  
00772      BeamType::BeamType_t beam = BeamType::kUnknown;
00773      if(beamstring.find("le010z185i")!=string::npos){ beam=BeamType::kL010z185i; }
00774      if(beamstring.find("le100z200i")!=string::npos){ beam=BeamType::kL100z200i; }
00775      if(beamstring.find("le250z200i")!=string::npos){ beam=BeamType::kL250z200i; }
00776      if(beamstring.find("le150z200i")!=string::npos){ beam=BeamType::kL150z200i; }
00777      if(beamstring.find("le010z200i")!=string::npos){ beam=BeamType::kL010z200i; }
00778      if(beamstring.find("le010z170i")!=string::npos){ beam=BeamType::kL010z170i; }
00779      if(beamstring.find("le010z000i")!=string::npos){ beam=BeamType::kL010z200i; }
00780      kBeamType = beam;
00781   }
00782 
00783   if(r.Get("FixMuParents",imps)){ 
00784     if(imps==1) kFixMuParents=true; 
00785     else kFixMuParents=false;
00786   }
00787 
00788   if(r.Get("MRCC",imps)){ SetMRCCRunning(imps);}
00789 }
00790 
00791 void NueModule::BeginJob()
00792 {
00793   MSG("NueModule",Msg::kDebug)<<"In NueModule::BeginJob"<<endl;
00794    
00795   if(tmpltfile!=""){
00796     MSG("NueModule",Msg::kDebug)<<"opening MST template file "
00797                                 <<tmpltfile<<endl;
00798     TFile f(tmpltfile.c_str());
00799     if(f.IsOpen()){
00800       MSTetemplate = (TProfile2D *)f.Get("nlambdanele");
00801       MSTbtemplate = (TProfile2D *)f.Get("nlambdanother");
00802       MSTemtemplate = (TProfile2D *)f.Get("mipdistele");
00803       MSTbmtemplate = (TProfile2D *)f.Get("mipdistother");
00804       MSG("NueModule",Msg::kDebug)<<"Did I get the histos? "
00805                                   <<MSTetemplate<<" "<<MSTbtemplate<<" "
00806                                   <<MSTemtemplate<<" "<<MSTbmtemplate<<endl;
00807       MSTetemplate->SetDirectory(0);
00808       MSTbtemplate->SetDirectory(0);
00809       MSTemtemplate->SetDirectory(0);
00810       MSTbmtemplate->SetDirectory(0);
00811       f.Close();
00812       MSG("NueModule",Msg::kDebug)<<"Do I still have them? "
00813                                   <<MSTetemplate->GetName()<<endl;
00814 
00815     }
00816   }
00817 // Beam Summary ntuples are obsolete!
00818 //  LoadBeamSummaryData(bmondir.c_str());
00819 }
00820 
00821 void NueModule::EndJob()
00822 {
00823 
00824    MSG("NueModule",Msg::kInfo)<<"Counter "<<counter
00825                               <<" passcutcounter "<<passcutcounter
00826                               <<" passcounter "<<passcounter
00827                               <<" failcounter "<<failcounter
00828                               <<" writecounter "<<writecounter<<endl;
00829 //   MSG("NueModule",Msg::kInfo)<<"Number of POT in this run: "<<pot<<endl;
00830 
00831    if(MSTetemplate!=0){
00832      delete MSTetemplate;
00833      MSTetemplate=0;
00834    }
00835    if(MSTbtemplate!=0){
00836      delete MSTbtemplate;
00837      MSTbtemplate=0;
00838    }
00839    if(MSTemtemplate!=0){
00840      delete MSTemtemplate;
00841      MSTemtemplate=0;
00842    }
00843    if(MSTbmtemplate!=0){
00844      delete MSTbmtemplate;
00845      MSTbmtemplate=0;
00846    }
00847 
00848 }
00849 
00850 void NueModule::LoadBeamSummaryData(const char *bd)
00851 {
00852     MSG("NueModule",Msg::kError)<<"Beam Summary ntuples are obsolete!"<<endl;
00853     return;
00854 
00855 
00856   DIR *dfd;
00857   if(!(dfd =  opendir(bd))){
00858     MSG("NueModule",Msg::kError)<<"Can not ls Beam Monitoring path "
00859                                 <<bd<<" "<<dfd<<std::endl;
00860     return;
00861   }
00862 }
00863 
00864 BeamType::BeamType_t NueModule::DetermineBeamType(VldContext vc){
00865 
00866 /*    BDSpillAccessor& sa = BDSpillAccessor::Get();
00867     VldContext evt_vldc = nr->GetHeader().GetVldContext();
00868 
00869     const BeamMonSpill* bms = sa.LoadSpill(vc.GetTimeStamp());
00870     VldTimeStamp bms_vts;
00871     if (!bms) {
00872        MSG("NueBeamMon",Msg::kError) << "No BeamMonSpill found for " << evt_vldc << endl;
00873        bms_vts = VldTimeStamp::GetEOT();
00874     }
00875     else {
00876         bms_vts = bms->SpillTime();
00877     }
00878     return bms->BeamType();
00879 */
00880     int time = vc.GetTimeStamp().GetSec();
00881 
00882     BeamType::BeamType_t beam = BeamType::kUnknown;
00883 
00884     if(time >= 1107216000 && time < 1109539850) beam = BeamType::kL100z200i;
00885     if(time >= 1109540615 && time < 1109899325) beam = BeamType::kL250z200i;
00886     if(time >= 1109899938 && time < 1110239564) beam = BeamType::kL100z200i;
00887     if(time >= 1110323763 && time < 1111622400) beam = BeamType::kL000z200i;
00888     if(time >= 1114892377 && time < 1115927583) beam = BeamType::kL100z200i;
00889     if(time >= 1115937438 && time < 1116604821) beam = BeamType::kL250z200i;
00890     if(time >= 1116618256 && time < 1122659668) beam = BeamType::kL010z185i;
00891     if(time >= 1122659886 && time < 1122922688) beam = BeamType::kL010z170i;
00892     if(time >= 1122922890 && time < 1123112674) beam = BeamType::kL010z200i;
00893     if(time >= 1123112803 && time < 1139605423) beam = BeamType::kL010z185i;
00894     if(time >= 1139605543 && time < 1140022084) beam = BeamType::kL010z000i;
00895     if(time >= 1140026702 && time < 1140908579) beam = BeamType::kL010z185i;
00896     // End of Run 1
00897     if(time >= 1149180600 && time < 1150047780) beam = BeamType::kL150z200i;
00898     if(time >= 1150047780 && time < 1151690460) beam = BeamType::kL250z200i;
00899     if(time >= 1153956600 && time < 1155510000) beam = BeamType::kL250z200i;
00900     if(time >= 1158004800 && time < 1158019870) beam = BeamType::kL010z200i;
00901     if(time >= 1158019870 && time < 1161892800) beam = BeamType::kL010z185i;
00902     if(time >= 1161892800 && time < 1184351737) beam = BeamType::kL010z185i;
00903     if(time >= 1184351737 && time < 1184708040) beam = BeamType::kL010z000i;
00904     //End of Run 2
00905 
00906     if(time >= 1195357170 && time < 1226738986) beam = BeamType::kL010z185i;
00907     if(time >= 1226738986 && time < 1229106262) beam = BeamType::kL010z000i;// Nov. 2008
00908     if(time >= 1229106262 && time < 1238766448) beam = BeamType::kL010z185i;
00909     if(time >= 1238766448 && time < 1239062404) beam = BeamType::kL010z000i;
00910     if(time >= 1239062404 && time < 1239608626) beam = BeamType::kL010z185i;
00911     if(time >= 1239608626 && time < 1239641024) beam = BeamType::kL010z000i;
00912     if(time >= 1239641024 && time < 1240002769) beam = BeamType::kL010z185i;
00913     if(time >= 1240002769 && time < 1240159225) beam = BeamType::kL010z000i;
00914     if(time >= 1240159225 && time < 1244887229) beam = BeamType::kL010z185i;// need to be modified when new data is available
00915     // End of Run 16502_0000
00916 
00917 
00918     return beam;
00919 }
00920 
00921 BeamType::BeamType_t NueModule::DetermineBeamType(string file)
00922 {
00923    BeamType::BeamType_t beam = BeamType::kUnknown;
00924    if(file.find("L010185")!=string::npos)
00925    {
00926     beam=BeamType::kL010z185i;
00927     //Check to see if this has a special intensity
00928     if(file.find("D04_i124")!=string::npos){beam=BeamType::kL010z185i_i124;}
00929     else if(file.find("D04_i191")!=string::npos){beam=BeamType::kL010z185i_i191;}
00930     else if(file.find("D04_i213")!=string::npos){beam=BeamType::kL010z185i_i213;}
00931     else if(file.find("D04_i224")!=string::npos){beam=BeamType::kL010z185i_i224;}
00932     else if(file.find("D04_i232")!=string::npos){beam=BeamType::kL010z185i_i232;}
00933     else if(file.find("D04_i243")!=string::npos){beam=BeamType::kL010z185i_i243;}
00934     else if(file.find("D04_i257")!=string::npos){beam=BeamType::kL010z185i_i257;}
00935     else if(file.find("D04_i282")!=string::npos){beam=BeamType::kL010z185i_i282;}
00936     else if(file.find("D04_i303")!=string::npos){beam=BeamType::kL010z185i_i303;}
00937     else if(file.find("D04_i324")!=string::npos){beam=BeamType::kL010z185i_i324;}
00938    }
00939    if(file.find("L010000")!=string::npos)
00940    {
00941     beam=BeamType::kL010z000i; 
00942     //Check to see if this has a special intensity
00943     if(file.find("D04_i209")!=string::npos){beam=BeamType::kL010z000i_i209;}
00944     else if(file.find("D04_i225")!=string::npos){beam=BeamType::kL010z000i_i225;}
00945     else if(file.find("D04_i232")!=string::npos){beam=BeamType::kL010z000i_i232;}
00946     else if(file.find("D04_i259")!=string::npos){beam=BeamType::kL010z000i_i259;}
00947     else if(file.find("D04_i300")!=string::npos){beam=BeamType::kL010z000i_i300;}
00948     else if(file.find("D04_i317")!=string::npos){beam=BeamType::kL010z000i_i317;}
00949     else if(file.find("D04_i326")!=string::npos){beam=BeamType::kL010z000i_i326;}
00950     else if(file.find("D04_i380")!=string::npos){beam=BeamType::kL010z000i_i380;}
00951    }
00952    if(file.find("L100200")!=string::npos){ beam=BeamType::kL100z200i; }
00953    if(file.find("L250200")!=string::npos)
00954    { 
00955     beam=BeamType::kL250z200i;
00956     //Check to see if this has a special intensity
00957     if(file.find("D04_i100")!=string::npos){beam=BeamType::kL250z200i_i100;}
00958     else if(file.find("D04_i114")!=string::npos){beam=BeamType::kL250z200i_i114;}
00959     else if(file.find("D04_i130")!=string::npos){beam=BeamType::kL250z200i_i130;}
00960     else if(file.find("D04_i152")!=string::npos){beam=BeamType::kL250z200i_i152;}
00961     else if(file.find("D04_i165")!=string::npos){beam=BeamType::kL250z200i_i165;}
00962     else if(file.find("D04_i194")!=string::npos){beam=BeamType::kL250z200i_i194;}
00963     else if(file.find("D04_i232")!=string::npos){beam=BeamType::kL250z200i_i232;}
00964    }
00965    if(file.find("L150200")!=string::npos){ beam=BeamType::kL150z200i; }
00966    if(file.find("L010200")!=string::npos){ beam=BeamType::kL010z200i; }
00967    if(file.find("L010170")!=string::npos){ beam=BeamType::kL010z170i; }
00968 
00969    return beam;
00970 }
00971 
00972 bool NueModule::PassesBlindingCuts(NueRecord *nr)
00973 {
00974   bool passes = true;
00975 
00976   if( kPidName != "None"){
00977      Selection::Selection_t pid = Selection::StringToEnum(kPidName.c_str());
00978 
00979      double pidVal = NueStandard::GetPIDValue(nr, pid);
00980      
00981      if(!ANtpDefVal::IsDefault(kPIDHighCut))
00982          passes = pidVal < kPIDHighCut;
00983 
00984      if(!ANtpDefVal::IsDefault(kPIDLowCut))
00985          passes = (passes) && pidVal > kPIDLowCut;
00986 
00987     if(pid != Selection::kANN6) nr->ann.pid_6inp = ANtpDefVal::kDouble;
00988     if(pid != Selection::kANN30) nr->ann.pid_30inp = ANtpDefVal::kDouble;
00989     if(pid != Selection::kSSPID) 
00990              nr->subshowervars.pid = ANtpDefVal::kDouble;
00991     if(pid != Selection::kMCNN) nr->mcnnv.fracCCy = ANtpDefVal::kDouble;
00992     if(pid != Selection::kCuts) nr->treepid.fCutPID = ANtpDefVal::kInt;
00993 
00994   }
00995 
00996   if(!ANtpDefVal::IsDefault(kCCPIDCut)){
00997      if(kCCPidName == "CC_DP")
00998          passes = passes &&  nr->mri.orig_cc_pid > kCCPIDCut;
00999      if(kCCPidName == "CC_AB")
01000          passes = passes &&  nr->mri.orig_abCCPID > kCCPIDCut;
01001   }
01002 
01003   NueConvention::NueEnergyCorrection(nr);
01004 
01005   if(!ANtpDefVal::IsDefault(kHighECut))
01006      passes = passes && nr->srevent.phNueGeV < kHighECut;
01007 
01008   if(!ANtpDefVal::IsDefault(kLowECut))
01009      passes =  passes && nr->srevent.phNueGeV > kLowECut;
01010 
01011   return passes;
01012 }
01013 

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