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.29 2008/01/10 18:18:34 boehm 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 
00040 #include "NueAna/NueStandard.h"
00041 #include "NueAna/NueAnaTools/Selection.h"
00042 #include "DataUtil/GetTempTags.h"   
00043 #include "TSystem.h"
00044 
00045 
00046 CVSID("$Id: NueModule.cxx,v 1.29 2008/01/10 18:18:34 boehm Exp $");
00047 
00048 #include "DatabaseInterface/DbiResultPtr.tpl"
00049 
00050 
00051 JOBMODULE(NueModule, "NueModule",
00052           "");
00053 //......................................................................
00054 
00055 NueModule::NueModule():
00056    tmpltfile(""),
00057    kDPlaneCut(-1),
00058    kLoPhNStripCut(-1),
00059    kLoPhNPlaneCut(-1),
00060    kPhStripCut(-1),
00061    kPhPlaneCut(-1),
00062    kBeamType(BeamType::kUnknown),
00063    kMuPiDir(""),
00064    kOpenedMuPiFile(false),
00065    counter(0),
00066    passcounter(0),
00067    passcutcounter(0),
00068    failcounter(0),
00069    writecounter(0),
00070    foundmeu(false),
00071    MSTminsig(0.),
00072    MSTmaxmetric(0.),
00073    MSTminfarsig(0.),
00074    MSTmaxmetriclowz(0.),
00075    SIGCORRMEU(1.),
00076    MSTetemplate(0),
00077    MSTbtemplate(0),
00078    MSTemtemplate(0),
00079    MSTbmtemplate(0),
00080    threshCut(0.),
00081    sasFileName(""),
00082    pot(0.),
00083    MEUPERGEV(25),   //not correct but close, correctly set by NueCalibration
00084                     //  adjusted on 01-08-2008 by JAB
00085    foundRelease(false),
00086    release(0),
00087    skzpcfg("PiMinus_CedarDaikon")
00088 {
00089   mupar = new MuParentHelper();
00090 //  zbeam = new Zbeam();
00091 //  zfluk = new Zfluk();
00092 //  zfluk->UseParameterization("SKZP"); //this is the default
00093   kfluk = new Kfluk();
00094 
00095   skzpCalc = new SKZPWeightCalculator(skzpcfg, true);
00096   mcr = &MCReweight::Instance();
00097   NeugenWeightCalculator *n=new NeugenWeightCalculator();
00098   mcr->AddWeightCalculator(n);
00099 
00100   xsecreweightreg = new Registry();
00101   xsecreweightreg->UnLockValues();
00102   xsecreweightreg->UnLockKeys();
00103   xsecreweightreg->Clear();
00104   xsecreweightreg->Set("neugen:config_name","MODBYRS");
00105   xsecreweightreg->Set("neugen:config_no",3);
00106   xsecreweightreg->LockValues();
00107   xsecreweightreg->LockKeys();
00108 
00109   mrccRun = false;
00110   
00111   kPidName = "None";
00112   kPIDHighCut = ANtpDefVal::kDouble;
00113   kPIDLowCut = ANtpDefVal::kDouble;
00114   kCCPIDCut = ANtpDefVal::kDouble;
00115   kHighECut = ANtpDefVal::kDouble;
00116   kLowECut = ANtpDefVal::kDouble;
00117 }
00118 
00119 //......................................................................
00120 
00121 NueModule::~NueModule()
00122 {
00123   if(mupar){
00124     delete mupar;
00125     mupar=0;
00126   }
00127   if(zbeam){
00128     delete zbeam;
00129     zbeam=0;
00130   }
00131 
00132   if(skzpCalc){
00133     delete skzpCalc;
00134     skzpCalc=0;
00135   }
00136   if(zfluk){
00137     delete zfluk;
00138     zfluk=0;
00139   }
00140   if(kfluk){
00141     delete kfluk;
00142     kfluk=0;
00143   }
00144 }
00145 
00146 //......................................................................
00147 
00148 JobCResult NueModule::Reco(MomNavigator* mom)
00149 {
00150 //======================================================================
00151 // Reads in sue-style ntuples from mom, calculates a bunch of useful
00152 // nue quantites
00153 //======================================================================
00154    MSG("NueModule",Msg::kDebug)<<"In NueModule::Reco"<<endl;
00155 
00156    if(counter%1000==0){      
00157       MSG("NueModule",Msg::kInfo)<<"On entry "<<counter<<endl;
00158    }
00159    counter++;
00160    bool foundSR=false;
00161    bool foundMC=false;
00162    bool foundTH=false;
00163    bool foundMR=false;
00164    bool foundUR=false;
00165 
00166    bool foundST=false;
00167    bool passesCuts = false;
00168 
00169    NtpStRecord *str = 0;
00170    NtpStRecord *oldst = 0;
00171    NtpMRRecord *mr = 0;
00172 
00173    //if we didn't find a NtpStRecord, it could be because we're reading an 
00174    //old tree, check for the other records
00175    NtpMCRecord *mc=0;
00176    NtpSRRecord *sr=0;
00177    NtpTHRecord *th=0;
00178 
00179    VldContext vc;  
00180    str = dynamic_cast<NtpStRecord *>(mom->GetFragment("NtpStRecord",
00181                                                       "Primary"));
00182    if(str){
00183      foundST=true;
00184      vc=str->GetHeader().GetVldContext();
00185      if(!foundRelease){
00186         release = str->GetRelease();
00187         foundRelease = true; 
00188         title = ReleaseType::AsString(release);
00189 
00190         string file = DataUtil::GetTempTagString(str, "file");
00191         filename = gSystem->BaseName(file.c_str());
00192      }
00193      //check for MR:
00194      mr=dynamic_cast<NtpMRRecord *>(mom->GetFragment("NtpMRRecord"));
00195      if(mr){
00196        if(ReleaseType::IsBirch(release)) {
00197          oldst=dynamic_cast<NtpStRecord *>(mom->GetFragment("NtpStRecord",
00198                                                             "NtpStRecordOld")); 
00199        }
00200        else if(ReleaseType::IsCedar(release)){
00201          oldst=str;
00202          str=dynamic_cast<NtpStRecord *>(mom->GetFragment("NtpStRecord",
00203                                                           "MuonRemoved"));
00204        }
00205        if(oldst) foundMR = true;
00206      }
00207    }
00208    else {
00209      release = ReleaseType::kUnknown;
00210      title = ReleaseType::AsString(release);
00211      sr = dynamic_cast<NtpSRRecord *>(mom->GetFragment("NtpSRRecord"));
00212      if (sr) {
00213        foundSR = true;
00214        vc=sr->GetHeader().GetVldContext();        
00215      }
00216      mc = static_cast<NtpMCRecord *>(mom->GetFragment("NtpMCRecord"));
00217      if (mc) {
00218        foundMC = true;
00219        th = static_cast<NtpTHRecord *>(mom->GetFragment("NtpTHRecord"));
00220        if (th) foundTH = true;
00221      }
00222    }
00223 
00224    if(!foundSR&&!foundMC&&!foundST&&!foundMR){
00225       //got nothing useful from mom
00226       MSG("NueModule",Msg::kWarning)<<"Got Nothing from mom"<<endl;
00227       failcounter++;
00228       return JobCResult::kFailed;
00229    }
00230    if(mrccRun&&!foundMR&&foundST){
00231       return JobCResult::kFailed;
00232    }
00233 
00234    UberRecord *ur = dynamic_cast<UberRecord *>(mom->GetFragment("UberRecord"));
00235    if(ur) foundUR=true;
00236    
00237    //UGLY!!!!
00238    //need to be able to compare single strip 
00239    //pulseheight between ND and FD, but we can't
00240    //in the ntuple.  Will ask the db for the
00241    //conversion from sigcor to MEU 
00242    //on the first event, and use throughout.  
00243    //Since sigcorrs are already corrected for all strip variations, 
00244    //it's ok to ask for 1 number.  
00245    //Should be ok for MC, maybe ok for 1 run of data at a time, but will
00246    //definitely be wrong if many weeks worth of data are strung together
00247    //we should revisit this and make it better in the future!!!!!!!
00248    if(!foundmeu){
00249      DbiResultPtr<CalMIPCalibration> dbp(vc);
00250      if(dbp.GetNumRows()>0){
00251        const CalMIPCalibration *m = dbp.GetRow(0);
00252        float mip=m->GetMIP(1.); 
00253        if(mip>0){
00254          SIGCORRMEU=1./mip;
00255          foundmeu=true;
00256        }
00257      }
00258    }
00259 
00260   int evtn = 0;
00261   const RecCandHeader *header = 0;
00262 
00263    if(foundST){
00264      evtn=str->evthdr.nevent;
00265      header = &(str->GetHeader());
00266    }
00267 
00268    if(!foundSR&&foundMC){
00269       vc = mc->GetHeader().GetVldContext();
00270       header = &(mc->GetHeader());
00271       evtn = 0;
00272    }
00273 
00274    if(foundSR){
00275      MSG("NueModule",Msg::kDebug)<<"Got SR from mom"<<endl;
00276      evtn=sr->evthdr.nevent;
00277      header = &(sr->GetHeader());
00278    }
00279 
00280    //if first event and we want to fix the Mu parents,
00281    // set the mupar file directory
00282    if(header->GetVldContext().GetSimFlag() == SimFlag::kData)
00283      kFixMuParents = 0;
00284 
00285    if(ReleaseType::IsData(release))
00286       kBeamType = DetermineBeamType(vc);
00287    else
00288       kBeamType = DetermineBeamType(filename);
00289 
00290    if(!kOpenedMuPiFile&&kFixMuParents && ReleaseType::IsCarrot(release)){
00291      string flxsfx="le010z185i";
00292      if(kBeamType==BeamType::kL010z185i){     flxsfx="le010z185i";  }
00293      else if(kBeamType==BeamType::kL100z200i){flxsfx="le100z200i";  }
00294      else if(kBeamType==BeamType::kL250z200i){flxsfx="le250z200i";  }
00295      else if(kBeamType==BeamType::kL150z200i){flxsfx="le150z200i";  }
00296      else if(kBeamType==BeamType::kL010z170i){flxsfx="le010z170i";  }
00297      else if(kBeamType==BeamType::kL010z200i){flxsfx="le010z200i";  }
00298      else if(kBeamType==BeamType::kL010z000i){flxsfx="le010z000i";  }
00299         
00300      string fullPath = kMuPiDir + flxsfx;
00301      mupar->SetFileDir(kMuPiDir,true);
00302      kOpenedMuPiFile=true;
00303    }
00304 
00305    MSG("NueModule",Msg::kDebug)<<"Events in this snarl: "<<evtn<<endl;
00306 
00307    if(ReleaseType::IsData(release))
00308       kBeamType = DetermineBeamType(vc);
00309                
00310    //int kzarkoBeamType = BeamType::ToZarko(kBeamType);
00311                                              
00312    if(evtn == 0)
00313    {
00314       NueHeader h(vc);
00315       h.SetSnarl(header->GetSnarl());
00316       h.SetRun(header->GetRun());
00317       h.SetSubRun(header->GetSubRun());
00318       h.SetEventNo(-1);
00319       h.SetEvents(0);
00320       h.SetTrackLength(0);
00321       h.SetRelease(release);
00322       h.SetBeamType(kBeamType);
00323       h.SetFoundBits(foundSR, foundMC || foundST, foundTH,foundMR);
00324 
00325      //make an ana_nue object
00326      NueRecord *nue = new NueRecord(h);
00327      //make a nuerecordana object
00328      NueRecordAna ana_nue(*nue);
00329      ana_nue.SetRelease(release);
00330      ana_nue.SetBeamType(kBeamType);
00331 
00332      nue->SetTitle(title.c_str());
00333      //fill the truth info
00334      //if it's data, we can also do beam mon analyze
00335      //  ana_nue.bmona.SetBeamSummary(bsum);
00336                                                                                 
00337      //must set the beam and parent helper to fill flux info
00338 //     ana_nue.anaia.SetBeam(kzarkoBeamType);
00339 //     ana_nue.nuefwa.SetBeam(kzarkoBeamType);
00340 //     ana_nue.anaia.SetBeam(kBeamType);
00341 //     ana_nue.nuefwa.SetBeam(kBeamType);
00342      ana_nue.nuefwa.SetSKZPCalc(skzpCalc, skzpcfg);
00343 //     ana_nue.nuefwa.SetZfluk(zfluk);
00344      ana_nue.nuefwa.SetKfluk(kfluk);
00345      ana_nue.fiana.SetMuParentHelper(mupar);
00346      ana_nue.fiana.FixMuParents(kFixMuParents);
00347                
00348      //set xsec registry and mcreweight to do xsec reweighting
00349      ana_nue.nuexsa.SetMCReweight(mcr);
00350      ana_nue.nuexsa.SetRegistry(xsecreweightreg);
00351      
00352      if(foundST)
00353        ana_nue.FillTrue(0,str);
00354      if(foundMC || foundSR)
00355        ana_nue.FillTrue(0,sr,mc,th);
00356                                                                                 
00357      //give the ana_nue object to mom, she'll write it to the file
00358      mom->AdoptFragment(nue);
00359      writecounter++;
00360      failcounter++;
00361      return JobCResult::kPassed;
00362    }
00363 
00364    bool anypassed = false;
00365   for(int i=0;i<evtn;i++){
00366      passesCuts = false;
00367     
00368      const int SIZE = 5500;
00369      float ph0[SIZE] = {-1};
00370      float ph1[SIZE] = {-1};
00371      for(int k=0; k < SIZE; k++) { ph0[k] = ph1[k] = -1;}
00372 
00373      SntpHelpers::FillEventEnergy(ph0, ph1, i, str, SIZE);
00374  
00375      //make a header
00376      NueHeader h(vc);
00377      
00378      //fill header info
00379      h.SetSnarl(header->GetSnarl());
00380      h.SetRun(header->GetRun());
00381      h.SetSubRun(header->GetSubRun());
00382      h.SetEventNo(i);
00383      h.SetEvents(evtn);
00384      h.SetRelease(release);
00385      h.SetBeamType(kBeamType);
00386      h.SetFoundBits((foundSR || foundST), foundMC || foundST,
00387                     foundTH || foundST, foundMR);
00388 
00389      MSG("NueModule",Msg::kDebug)<<"Getting event"<<endl;
00390      
00391      NtpSREvent *event = 0;
00392      if(foundST) event = SntpHelpers::GetEvent(i,str);
00393      if(foundSR) event = SntpHelpers::GetEvent(i,sr);
00394      
00395      //loop over tracks in this event, find longest
00396      int longtrack=0;
00397      if(event){
00398        for(int j=0;j<event->ntrack;j++){
00399            int tindex = SntpHelpers::GetTrackIndex(j,event);
00400            NtpSRTrack *track = 0;
00401            if(foundST) track = SntpHelpers::GetTrack(tindex,str);
00402            if(foundSR) track = SntpHelpers::GetTrack(tindex,sr);
00403            if(track && longtrack<track->plane.n){
00404               longtrack = track->plane.n;
00405            }
00406         }
00407      }
00408      
00409      h.SetTrackLength(longtrack);
00410      
00411      NueRecord *nue = new NueRecord(h);
00412      //make a nuerecordana object
00413      NueRecordAna ana_nue(*nue);
00414      ana_nue.SetRelease(release);
00415      ana_nue.SetBeamType(kBeamType);
00416      ana_nue.SetEventEnergyArray(ph0, ph1);
00417 
00418      nue->SetTitle(title.c_str());
00419 
00420      
00421      if(foundST)
00422      {                   
00423         fCut.SetInfoObject(i, str);
00424         passesCuts = fCut.PassesAllCuts();
00425      }
00426 
00427      if(foundSR)
00428      {
00429        passesCuts = true;
00430        MSG("NueModule",Msg::kWarning)
00431           <<"Unable to cut on pre-Birch files - why are you running these files?"<<endl;
00432      }
00433      
00434      ana_nue.aneia.SetParams(SIGCORRMEU, MEUPERGEV);
00435      ana_nue.ansia.SetParams(SIGCORRMEU, MEUPERGEV);
00436      ana_nue.antia.SetParams(SIGCORRMEU, MEUPERGEV);
00437      ana_nue.hca.SetParams(SIGCORRMEU, MEUPERGEV);
00438 
00439      //must set the beam and parent helper to fill flux info
00440 //     ana_nue.nuefwa.SetBeam(kzarkoBeamType);
00441 //     ana_nue.nuefwa.SetBeam(kBeamType);
00442      ana_nue.nuefwa.SetSKZPCalc(skzpCalc, skzpcfg);
00443 
00444 //     ana_nue.nuefwa.SetZbeam(zbeam);
00445 //     ana_nue.nuefwa.SetZfluk(zfluk);
00446      ana_nue.nuefwa.SetKfluk(kfluk);
00447      ana_nue.fiana.SetMuParentHelper(mupar);
00448      ana_nue.fiana.FixMuParents(kFixMuParents);
00449 
00450      //set xsec registry and mcreweight to do xsec reweighting
00451      ana_nue.nuexsa.SetMCReweight(mcr);
00452      ana_nue.nuexsa.SetRegistry(xsecreweightreg);
00453   
00454 
00455      if(foundST){
00456          ana_nue.FillTrue(i,str);
00457          ana_nue.FillReco(i,str);
00458      }
00459      if(foundSR){
00460          ana_nue.FillTrue(i,sr,mc,th);
00461          ana_nue.FillReco(i,sr);
00462      }
00463                                                                               
00464      if(passesCuts)
00465      {
00466          MSG("NueModule",Msg::kDebug)<<"Tracklength: "<<longtrack
00467             <<"Event Length: "<<event->plane.n
00468             <<"Event Energy: "<<event->ph.sigcor
00469             <<"Event Energy : "<<event->ph.sigcor<<endl;
00470 
00471          passcutcounter++;
00472          //analyze calculates everybodies variables, then calls the Truth and Reco Object Fillers
00473          //configure MSTCalcAna routine
00474          MSG("NueModule",Msg::kDebug)<<"Setting templates: "
00475                                      <<MSTetemplate->GetName()<<" "
00476                                      <<MSTbtemplate->GetName()<<" "
00477                                      <<MSTemtemplate->GetName()<<" "
00478                                      <<MSTbmtemplate->GetName()<<endl;
00479          
00480          ana_nue.msta.SetSigTemplate(MSTetemplate);
00481          ana_nue.msta.SetBGTemplate(MSTbtemplate);
00482          ana_nue.msta.SetSigMIPTemplate(MSTemtemplate);
00483          ana_nue.msta.SetBGMIPTemplate(MSTemtemplate);
00484          ana_nue.msta.SetMSTParams(MSTminsig,MSTmaxmetric,
00485                                    MSTminfarsig,MSTmaxmetriclowz,SIGCORRMEU);
00486          ana_nue.sfa.SetParams(SIGCORRMEU, MEUPERGEV);
00487          ana_nue.sfa.SetCutParams(kDPlaneCut,kPhStripCut,kPhPlaneCut);
00488          ana_nue.fva.SetParams(SIGCORRMEU, MEUPERGEV);
00489          ana_nue.mda.SetMdaParams(threshCut, sasFileName);
00490                                
00491          if(foundST)  ana_nue.Analyze(i,str);
00492          if(foundSR)  ana_nue.Analyze(i,sr);
00493          if(foundMR)  ana_nue.Analyze(i,mr,oldst);
00494          if(foundUR)  ana_nue.Analyze(ur);
00495      }// end of If(passcuts)
00496      else{
00497        cout<<"Rejecting based on cuts"<<endl;
00498      }
00499 
00500      if(PassesBlindingCuts(nue)){  
00501        anypassed = true;
00502        //give the ana_nue object to mom, she'll write it to the file
00503        MSG("NueModule",Msg::kDebug)<<"Giving Fragment to mom"<<endl;
00504        writecounter++;
00505        mom->AdoptFragment(nue);
00506        MSG("NueModule",Msg::kDebug)<<"Mom took it"<<endl;
00507      }
00508  
00509      if(i+1 == evtn && !anypassed){ 
00510        //push through something so the POT are still counted
00511        NueRecord *nue = new NueRecord(h);
00512        writecounter++;
00513        mom->AdoptFragment(nue);
00514      }
00515    }
00516    MSG("NueModule",Msg::kDebug)<<"Done with snarl"<<endl;
00517    passcounter++;
00518    return JobCResult::kPassed; // kNoDecision, kFailed, etc.
00519 }
00520 
00521 //......................................................................
00522 
00523 const Registry& NueModule::DefaultConfig() const
00524 {
00525 //======================================================================
00526 // Supply the default configuration for the module
00527 //======================================================================
00528    MSG("NueModule",Msg::kDebug)<<"In NueModule::DefaultConfig"<<endl;
00529 
00530   static Registry r  = fCut.DefaultConfig(); // Default configuration for module
00531 
00532   // Set name of config
00533   std::string name = this->GetName();
00534   name += ".config.default";
00535   r.SetName(name.c_str());
00536 
00537   // Set values in configuration
00538   r.UnLockValues();
00539   r.Set("MSTTmpltFile","templates.root");
00540   r.Set("DPlaneCut",-1);
00541   r.Set("LoPhNStripCut",-1);
00542   r.Set("LoPhNPlaneCut",-1);
00543   r.Set("PhStripCut",-1);
00544   r.Set("PhPlaneCut",-1);
00545 
00546   r.Set("MSTminsig",0.5);
00547   r.Set("MSTmaxmetric",1000.);
00548   r.Set("MSTminfarsig",1.5);
00549   r.Set("MSTmaxmetriclowz",20.);
00550   
00551   r.Set("MdaThreshCut",0.0);
00552   r.Set("MdaSASFile","");
00553   r.Set("BeamString", "");
00554   r.Set("MuPiDir","");
00555   r.Set("BeamType",2);
00556   r.Set("FixMuParents",0);
00557   r.Set("MRCC", 0);
00558 
00559   r.Set("HighEnergyCut", ANtpDefVal::kDouble);
00560   r.Set("LowEnergyCut", ANtpDefVal::kDouble);
00561   r.Set("HighPIDCut", ANtpDefVal::kDouble);
00562   r.Set("LowPIDCut", ANtpDefVal::kDouble);
00563   r.Set("ANTIPID", "None");
00564   r.Set("CCPID", "None");
00565 
00566   r.LockValues();
00567 
00568   return r;
00569 }
00570 
00571 //......................................................................
00572 
00573 void NueModule::Config(const Registry& r)
00574 {
00575 //======================================================================
00576 // Configure the module given the Registry r
00577 //======================================================================
00578   MSG("NueModule",Msg::kDebug)<<"In NueModule::Config"<<endl;
00579 
00580   fCut.Config(r);
00581 
00582   const char* tmps;
00583 
00584   if(r.Get("ANTIPID", tmps)) {kPidName = tmps;}
00585   if(r.Get("CCPID", tmps))      { kCCPidName = tmps;}
00586 
00587   if(r.Get("MSTTmpltFile",tmps)) { tmpltfile = tmps;}
00588   int imps;
00589   if(r.Get("DPlaneCut",imps)) { kDPlaneCut=imps;}
00590   if(r.Get("LoPhNStripCut",imps)) { kLoPhNStripCut=imps;}
00591   if(r.Get("LoPhNPlaneCut",imps)) { kLoPhNPlaneCut=imps;}
00592 
00593   if(r.Get("MdaSASFile",tmps)) { sasFileName = tmps;}
00594 
00595   double fmps;
00596   if(r.Get("HighPIDCut", fmps)) { kPIDHighCut = fmps; }
00597   if(r.Get("LowPIDCut", fmps))  { kPIDLowCut = fmps; }
00598   if(r.Get("CCPIDCut", fmps))   { kCCPIDCut = fmps;  }
00599   if(r.Get("HighEnergyCut", fmps)) { kHighECut = fmps; }
00600   if(r.Get("LowEnergyCut", fmps))  { kLowECut = fmps; }
00601 
00602   if(r.Get("PhStripCut",fmps)) { kPhStripCut=fmps;}
00603   if(r.Get("PhPlaneCut",fmps)) { kPhPlaneCut=fmps;}
00604   if(r.Get("MSTminsig",fmps)){ MSTminsig=fmps; }
00605   if(r.Get("MSTmaxmetric",fmps)){ MSTmaxmetric=fmps; }
00606   if(r.Get("MSTminfarsig",fmps)){ MSTminfarsig=fmps; }
00607   if(r.Get("MSTmaxmetriclowz",fmps)){ MSTmaxmetriclowz=fmps; }
00608   if(r.Get("MdaThreshCut",fmps)) { threshCut = fmps;}
00609 
00610   if(r.Get("MuPiDir",tmps)){kMuPiDir=(string)(tmps);}
00611 
00612 //  if(r.Get("BeamType",imps)){kBeamType=imps;}
00613 
00614   if(r.Get("BeamString", tmps)){
00615      beamstring = tmps;  
00616      BeamType::BeamType_t beam = BeamType::kUnknown;
00617      if(beamstring.find("le010z185i")!=string::npos){ beam=BeamType::kL010z185i; }
00618      if(beamstring.find("le100z200i")!=string::npos){ beam=BeamType::kL100z200i; }
00619      if(beamstring.find("le250z200i")!=string::npos){ beam=BeamType::kL250z200i; }
00620      if(beamstring.find("le150z200i")!=string::npos){ beam=BeamType::kL150z200i; }
00621      if(beamstring.find("le010z200i")!=string::npos){ beam=BeamType::kL010z200i; }
00622      if(beamstring.find("le010z170i")!=string::npos){ beam=BeamType::kL010z170i; }
00623      if(beamstring.find("le010z000i")!=string::npos){ beam=BeamType::kL010z200i; }
00624      kBeamType = beam;
00625   }
00626 
00627   if(r.Get("FixMuParents",imps)){ 
00628     if(imps) kFixMuParents=true; 
00629     else kFixMuParents=false;
00630   }
00631 
00632   if(r.Get("MRCC",imps)){ SetMRCCRunning(imps);}
00633 }
00634 
00635 void NueModule::BeginJob()
00636 {
00637   MSG("NueModule",Msg::kDebug)<<"In NueModule::BeginJob"<<endl;
00638    
00639   if(tmpltfile!=""){
00640     MSG("NueModule",Msg::kDebug)<<"opening MST template file "
00641                                 <<tmpltfile<<endl;
00642     TFile f(tmpltfile.c_str());
00643     if(f.IsOpen()){
00644       MSTetemplate = (TProfile2D *)f.Get("nlambdanele");
00645       MSTbtemplate = (TProfile2D *)f.Get("nlambdanother");
00646       MSTemtemplate = (TProfile2D *)f.Get("mipdistele");
00647       MSTbmtemplate = (TProfile2D *)f.Get("mipdistother");
00648       MSG("NueModule",Msg::kDebug)<<"Did I get the histos? "
00649                                   <<MSTetemplate<<" "<<MSTbtemplate<<" "
00650                                   <<MSTemtemplate<<" "<<MSTbmtemplate<<endl;
00651       MSTetemplate->SetDirectory(0);
00652       MSTbtemplate->SetDirectory(0);
00653       MSTemtemplate->SetDirectory(0);
00654       MSTbmtemplate->SetDirectory(0);
00655       f.Close();
00656       MSG("NueModule",Msg::kDebug)<<"Do I still have them? "
00657                                   <<MSTetemplate->GetName()<<endl;
00658 
00659     }
00660   }
00661 // Beam Summary ntuples are obsolete!
00662 //  LoadBeamSummaryData(bmondir.c_str());
00663 }
00664 
00665 void NueModule::EndJob()
00666 {
00667 
00668    MSG("NueModule",Msg::kInfo)<<"Counter "<<counter
00669                               <<" passcutcounter "<<passcutcounter
00670                               <<" passcounter "<<passcounter
00671                               <<" failcounter "<<failcounter
00672                               <<" writecounter "<<writecounter<<endl;
00673 //   MSG("NueModule",Msg::kInfo)<<"Number of POT in this run: "<<pot<<endl;
00674 
00675    if(MSTetemplate!=0){
00676      delete MSTetemplate;
00677      MSTetemplate=0;
00678    }
00679    if(MSTbtemplate!=0){
00680      delete MSTbtemplate;
00681      MSTbtemplate=0;
00682    }
00683    if(MSTemtemplate!=0){
00684      delete MSTemtemplate;
00685      MSTemtemplate=0;
00686    }
00687    if(MSTbmtemplate!=0){
00688      delete MSTbmtemplate;
00689      MSTbmtemplate=0;
00690    }
00691 
00692 }
00693 
00694 void NueModule::LoadBeamSummaryData(const char *bd)
00695 {
00696     MSG("NueModule",Msg::kError)<<"Beam Summary ntuples are obsolete!"<<endl;
00697     return;
00698 
00699 
00700   DIR *dfd;
00701   if(!(dfd =  opendir(bd))){
00702     MSG("NueModule",Msg::kError)<<"Can not ls Beam Monitoring path "
00703                                 <<bd<<" "<<dfd<<std::endl;
00704     return;
00705   }
00706 }
00707 
00708 BeamType::BeamType_t NueModule::DetermineBeamType(VldContext vc){
00709 
00710 /*    BDSpillAccessor& sa = BDSpillAccessor::Get();
00711     VldContext evt_vldc = nr->GetHeader().GetVldContext();
00712 
00713     const BeamMonSpill* bms = sa.LoadSpill(vc.GetTimeStamp());
00714     VldTimeStamp bms_vts;
00715     if (!bms) {
00716        MSG("NueBeamMon",Msg::kError) << "No BeamMonSpill found for " << evt_vldc << endl;
00717        bms_vts = VldTimeStamp::GetEOT();
00718     }
00719     else {
00720         bms_vts = bms->SpillTime();
00721     }
00722     return bms->BeamType();
00723 */
00724     int time = vc.GetTimeStamp().GetSec();
00725 
00726     BeamType::BeamType_t beam = BeamType::kUnknown;
00727 
00728     if(time >= 1107216000 && time < 1109539850) beam = BeamType::kL100z200i;
00729     if(time >= 1109540615 && time < 1109899325) beam = BeamType::kL250z200i;
00730     if(time >= 1109899938 && time < 1110239564) beam = BeamType::kL100z200i;
00731     if(time >= 1110323763 && time < 1111622400) beam = BeamType::kL000z200i;
00732     if(time >= 1114892377 && time < 1115927583) beam = BeamType::kL100z200i;
00733     if(time >= 1115937438 && time < 1116604821) beam = BeamType::kL250z200i;
00734     if(time >= 1116618256 && time < 1122659668) beam = BeamType::kL010z185i;
00735     if(time >= 1122659886 && time < 1122922688) beam = BeamType::kL010z170i;
00736     if(time >= 1122922890 && time < 1123112674) beam = BeamType::kL010z200i;
00737     if(time >= 1123112803 && time < 1139605423) beam = BeamType::kL010z185i;
00738     if(time >= 1139605543 && time < 1140022084) beam = BeamType::kL010z000i;
00739     if(time >= 1140026702 && time < 1140908579) beam = BeamType::kL010z185i;
00740     // End of Run 1
00741     if(time >= 1149180600 && time < 1150047780) beam = BeamType::kL150z200i;
00742     if(time >= 1150047780 && time < 1151690460) beam = BeamType::kL250z200i;
00743     if(time >= 1153956600 && time < 1155510000) beam = BeamType::kL250z200i;
00744     if(time >= 1158004800 && time < 1158019870) beam = BeamType::kL010z200i;
00745     if(time >= 1158019870 && time < 1161892800) beam = BeamType::kL010z185i;
00746     if(time >= 1161892800 && time < 1184351737) beam = BeamType::kL010z185i;
00747     if(time >= 1184351737 && time < 1184708040) beam = BeamType::kL010z000i;
00748     //End of Run 2
00749 
00750     if(time >= 1184800000 ) beam = BeamType::kL010z185i;
00751 
00752     return beam;
00753 }
00754 
00755 BeamType::BeamType_t NueModule::DetermineBeamType(string file)
00756 {
00757    BeamType::BeamType_t beam = BeamType::kUnknown;
00758    if(file.find("L010185")!=string::npos){ beam=BeamType::kL010z185i; }
00759    if(file.find("L100200")!=string::npos){ beam=BeamType::kL100z200i; }
00760    if(file.find("L250200")!=string::npos){ beam=BeamType::kL250z200i; }
00761    if(file.find("L150200")!=string::npos){ beam=BeamType::kL150z200i; }
00762    if(file.find("L010200")!=string::npos){ beam=BeamType::kL010z200i; }
00763    if(file.find("L010170")!=string::npos){ beam=BeamType::kL010z170i; }
00764    if(file.find("L010000")!=string::npos){ beam=BeamType::kL010z000i; }
00765 
00766    return beam;
00767 }
00768 
00769 bool NueModule::PassesBlindingCuts(NueRecord *nr)
00770 {
00771   bool passes = true;
00772 
00773   if( kPidName != "None"){
00774      Selection::Selection_t pid = Selection::StringToEnum(kPidName.c_str());
00775 
00776      double pidVal = NueStandard::GetPIDValue(nr, pid);
00777      
00778      if(!ANtpDefVal::IsDefault(kPIDHighCut))
00779          passes = pidVal < kPIDHighCut;
00780 
00781      if(!ANtpDefVal::IsDefault(kPIDLowCut))
00782          passes = (passes) && pidVal > kPIDLowCut;
00783 
00784     if(pid != Selection::kANN6) nr->ann.pid_6inp = ANtpDefVal::kDouble;
00785     if(pid != Selection::kANN30) nr->ann.pid_30inp = ANtpDefVal::kDouble;
00786     if(pid != Selection::kSSPID) 
00787              nr->subshowervars.pid_daikon = ANtpDefVal::kDouble;
00788     if(pid != Selection::kMCNN) nr->mcnnv.fracCCy = ANtpDefVal::kDouble;
00789     if(pid != Selection::kCuts) nr->treepid.fCutPID = ANtpDefVal::kInt;
00790 
00791   }
00792 
00793   if(!ANtpDefVal::IsDefault(kCCPIDCut)){
00794      if(kCCPidName == "CC_DP")
00795          passes = passes &&  nr->mri.orig_cc_pid > kCCPIDCut;
00796      if(kCCPidName == "CC_AB")
00797          passes = passes &&  nr->mri.orig_abCCPID > kCCPIDCut;
00798   }
00799 
00800   NueConvention::NueEnergyCorrection(nr);
00801 
00802   if(!ANtpDefVal::IsDefault(kHighECut))
00803      passes = passes && nr->srevent.phNueGeV < kHighECut;
00804 
00805   if(!ANtpDefVal::IsDefault(kLowECut))
00806      passes =  passes && nr->srevent.phNueGeV > kLowECut;
00807 
00808   return passes;
00809 }
00810 

Generated on Fri Mar 28 15:36:52 2008 for loon by  doxygen 1.3.9.1