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.30 2008/03/03 17:52:25 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.30 2008/03/03 17:52:25 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      ana_nue.aneia.Analyze(-10,str);  //need to fill srevent to get quality
00358                                                                                 
00359      //give the ana_nue object to mom, she'll write it to the file
00360      mom->AdoptFragment(nue);
00361      writecounter++;
00362      failcounter++;
00363      return JobCResult::kPassed;
00364    }
00365 
00366    bool anypassed = false;
00367   for(int i=0;i<evtn;i++){
00368      passesCuts = false;
00369     
00370      const int SIZE = 5500;
00371      float ph0[SIZE] = {-1};
00372      float ph1[SIZE] = {-1};
00373      for(int k=0; k < SIZE; k++) { ph0[k] = ph1[k] = -1;}
00374 
00375      SntpHelpers::FillEventEnergy(ph0, ph1, i, str, SIZE);
00376  
00377      //make a header
00378      NueHeader h(vc);
00379      
00380      //fill header info
00381      h.SetSnarl(header->GetSnarl());
00382      h.SetRun(header->GetRun());
00383      h.SetSubRun(header->GetSubRun());
00384      h.SetEventNo(i);
00385      h.SetEvents(evtn);
00386      h.SetRelease(release);
00387      h.SetBeamType(kBeamType);
00388      h.SetFoundBits((foundSR || foundST), foundMC || foundST,
00389                     foundTH || foundST, foundMR);
00390 
00391      MSG("NueModule",Msg::kDebug)<<"Getting event"<<endl;
00392      
00393      NtpSREvent *event = 0;
00394      if(foundST) event = SntpHelpers::GetEvent(i,str);
00395      if(foundSR) event = SntpHelpers::GetEvent(i,sr);
00396      
00397      //loop over tracks in this event, find longest
00398      int longtrack=0;
00399      if(event){
00400        for(int j=0;j<event->ntrack;j++){
00401            int tindex = SntpHelpers::GetTrackIndex(j,event);
00402            NtpSRTrack *track = 0;
00403            if(foundST) track = SntpHelpers::GetTrack(tindex,str);
00404            if(foundSR) track = SntpHelpers::GetTrack(tindex,sr);
00405            if(track && longtrack<track->plane.n){
00406               longtrack = track->plane.n;
00407            }
00408         }
00409      }
00410      
00411      h.SetTrackLength(longtrack);
00412      
00413      NueRecord *nue = new NueRecord(h);
00414      //make a nuerecordana object
00415      NueRecordAna ana_nue(*nue);
00416      ana_nue.SetRelease(release);
00417      ana_nue.SetBeamType(kBeamType);
00418      ana_nue.SetEventEnergyArray(ph0, ph1);
00419 
00420      nue->SetTitle(title.c_str());
00421 
00422      
00423      if(foundST)
00424      {                   
00425         fCut.SetInfoObject(i, str);
00426         passesCuts = fCut.PassesAllCuts();
00427      }
00428 
00429      if(foundSR)
00430      {
00431        passesCuts = true;
00432        MSG("NueModule",Msg::kWarning)
00433           <<"Unable to cut on pre-Birch files - why are you running these files?"<<endl;
00434      }
00435      
00436      ana_nue.aneia.SetParams(SIGCORRMEU, MEUPERGEV);
00437      ana_nue.ansia.SetParams(SIGCORRMEU, MEUPERGEV);
00438      ana_nue.antia.SetParams(SIGCORRMEU, MEUPERGEV);
00439      ana_nue.hca.SetParams(SIGCORRMEU, MEUPERGEV);
00440 
00441      //must set the beam and parent helper to fill flux info
00442 //     ana_nue.nuefwa.SetBeam(kzarkoBeamType);
00443 //     ana_nue.nuefwa.SetBeam(kBeamType);
00444      ana_nue.nuefwa.SetSKZPCalc(skzpCalc, skzpcfg);
00445 
00446 //     ana_nue.nuefwa.SetZbeam(zbeam);
00447 //     ana_nue.nuefwa.SetZfluk(zfluk);
00448      ana_nue.nuefwa.SetKfluk(kfluk);
00449      ana_nue.fiana.SetMuParentHelper(mupar);
00450      ana_nue.fiana.FixMuParents(kFixMuParents);
00451 
00452      //set xsec registry and mcreweight to do xsec reweighting
00453      ana_nue.nuexsa.SetMCReweight(mcr);
00454      ana_nue.nuexsa.SetRegistry(xsecreweightreg);
00455   
00456 
00457      if(foundST){
00458          ana_nue.FillTrue(i,str);
00459          ana_nue.FillReco(i,str);
00460      }
00461      if(foundSR){
00462          ana_nue.FillTrue(i,sr,mc,th);
00463          ana_nue.FillReco(i,sr);
00464      }
00465                                                                               
00466      if(passesCuts)
00467      {
00468          MSG("NueModule",Msg::kDebug)<<"Tracklength: "<<longtrack
00469             <<"Event Length: "<<event->plane.n
00470             <<"Event Energy: "<<event->ph.sigcor
00471             <<"Event Energy : "<<event->ph.sigcor<<endl;
00472 
00473          passcutcounter++;
00474          //analyze calculates everybodies variables, then calls the Truth and Reco Object Fillers
00475          //configure MSTCalcAna routine
00476          MSG("NueModule",Msg::kDebug)<<"Setting templates: "
00477                                      <<MSTetemplate->GetName()<<" "
00478                                      <<MSTbtemplate->GetName()<<" "
00479                                      <<MSTemtemplate->GetName()<<" "
00480                                      <<MSTbmtemplate->GetName()<<endl;
00481          
00482          ana_nue.msta.SetSigTemplate(MSTetemplate);
00483          ana_nue.msta.SetBGTemplate(MSTbtemplate);
00484          ana_nue.msta.SetSigMIPTemplate(MSTemtemplate);
00485          ana_nue.msta.SetBGMIPTemplate(MSTemtemplate);
00486          ana_nue.msta.SetMSTParams(MSTminsig,MSTmaxmetric,
00487                                    MSTminfarsig,MSTmaxmetriclowz,SIGCORRMEU);
00488          ana_nue.sfa.SetParams(SIGCORRMEU, MEUPERGEV);
00489          ana_nue.sfa.SetCutParams(kDPlaneCut,kPhStripCut,kPhPlaneCut);
00490          ana_nue.fva.SetParams(SIGCORRMEU, MEUPERGEV);
00491          ana_nue.mda.SetMdaParams(threshCut, sasFileName);
00492                                
00493          if(foundST)  ana_nue.Analyze(i,str);
00494          if(foundSR)  ana_nue.Analyze(i,sr);
00495          if(foundMR)  ana_nue.Analyze(i,mr,oldst);
00496          if(foundUR)  ana_nue.Analyze(ur);
00497      }// end of If(passcuts)
00498      else{
00499        cout<<"Rejecting based on cuts"<<endl;
00500      }
00501 
00502      if(PassesBlindingCuts(nue)){  
00503        anypassed = true;
00504        //give the ana_nue object to mom, she'll write it to the file
00505        MSG("NueModule",Msg::kDebug)<<"Giving Fragment to mom"<<endl;
00506        writecounter++;
00507        mom->AdoptFragment(nue);
00508        MSG("NueModule",Msg::kDebug)<<"Mom took it"<<endl;
00509      }
00510  
00511      if(i+1 == evtn && !anypassed){ 
00512        //push through something so the POT are still counted
00513        h.SetEvents(evtn);
00514        NueRecord *nue = new NueRecord(h);
00515        NueRecordAna ana_nue(*nue);
00516        ana_nue.SetRelease(release);
00517        ana_nue.SetBeamType(kBeamType);
00518        nue->SetTitle(title.c_str());
00519        ana_nue.aneia.Analyze(-10,str);
00520        writecounter++;
00521        mom->AdoptFragment(nue);
00522      }
00523    }
00524    MSG("NueModule",Msg::kDebug)<<"Done with snarl"<<endl;
00525    passcounter++;
00526    return JobCResult::kPassed; // kNoDecision, kFailed, etc.
00527 }
00528 
00529 //......................................................................
00530 
00531 const Registry& NueModule::DefaultConfig() const
00532 {
00533 //======================================================================
00534 // Supply the default configuration for the module
00535 //======================================================================
00536    MSG("NueModule",Msg::kDebug)<<"In NueModule::DefaultConfig"<<endl;
00537 
00538   static Registry r  = fCut.DefaultConfig(); // Default configuration for module
00539 
00540   // Set name of config
00541   std::string name = this->GetName();
00542   name += ".config.default";
00543   r.SetName(name.c_str());
00544 
00545   // Set values in configuration
00546   r.UnLockValues();
00547   r.Set("MSTTmpltFile","templates.root");
00548   r.Set("DPlaneCut",-1);
00549   r.Set("LoPhNStripCut",-1);
00550   r.Set("LoPhNPlaneCut",-1);
00551   r.Set("PhStripCut",-1);
00552   r.Set("PhPlaneCut",-1);
00553 
00554   r.Set("MSTminsig",0.5);
00555   r.Set("MSTmaxmetric",1000.);
00556   r.Set("MSTminfarsig",1.5);
00557   r.Set("MSTmaxmetriclowz",20.);
00558   
00559   r.Set("MdaThreshCut",0.0);
00560   r.Set("MdaSASFile","");
00561   r.Set("BeamString", "");
00562   r.Set("MuPiDir","");
00563   r.Set("BeamType",2);
00564   r.Set("FixMuParents",0);
00565   r.Set("MRCC", 0);
00566 
00567   r.Set("HighEnergyCut", ANtpDefVal::kDouble);
00568   r.Set("LowEnergyCut", ANtpDefVal::kDouble);
00569   r.Set("HighPIDCut", ANtpDefVal::kDouble);
00570   r.Set("LowPIDCut", ANtpDefVal::kDouble);
00571   r.Set("ANTIPID", "None");
00572   r.Set("CCPID", "None");
00573 
00574   r.LockValues();
00575 
00576   return r;
00577 }
00578 
00579 //......................................................................
00580 
00581 void NueModule::Config(const Registry& r)
00582 {
00583 //======================================================================
00584 // Configure the module given the Registry r
00585 //======================================================================
00586   MSG("NueModule",Msg::kDebug)<<"In NueModule::Config"<<endl;
00587 
00588   fCut.Config(r);
00589 
00590   const char* tmps;
00591 
00592   if(r.Get("ANTIPID", tmps)) {kPidName = tmps;}
00593   if(r.Get("CCPID", tmps))      { kCCPidName = tmps;}
00594 
00595   if(r.Get("MSTTmpltFile",tmps)) { tmpltfile = tmps;}
00596   int imps;
00597   if(r.Get("DPlaneCut",imps)) { kDPlaneCut=imps;}
00598   if(r.Get("LoPhNStripCut",imps)) { kLoPhNStripCut=imps;}
00599   if(r.Get("LoPhNPlaneCut",imps)) { kLoPhNPlaneCut=imps;}
00600 
00601   if(r.Get("MdaSASFile",tmps)) { sasFileName = tmps;}
00602 
00603   double fmps;
00604   if(r.Get("HighPIDCut", fmps)) { kPIDHighCut = fmps; }
00605   if(r.Get("LowPIDCut", fmps))  { kPIDLowCut = fmps; }
00606   if(r.Get("CCPIDCut", fmps))   { kCCPIDCut = fmps;  }
00607   if(r.Get("HighEnergyCut", fmps)) { kHighECut = fmps; }
00608   if(r.Get("LowEnergyCut", fmps))  { kLowECut = fmps; }
00609 
00610   if(r.Get("PhStripCut",fmps)) { kPhStripCut=fmps;}
00611   if(r.Get("PhPlaneCut",fmps)) { kPhPlaneCut=fmps;}
00612   if(r.Get("MSTminsig",fmps)){ MSTminsig=fmps; }
00613   if(r.Get("MSTmaxmetric",fmps)){ MSTmaxmetric=fmps; }
00614   if(r.Get("MSTminfarsig",fmps)){ MSTminfarsig=fmps; }
00615   if(r.Get("MSTmaxmetriclowz",fmps)){ MSTmaxmetriclowz=fmps; }
00616   if(r.Get("MdaThreshCut",fmps)) { threshCut = fmps;}
00617 
00618   if(r.Get("MuPiDir",tmps)){kMuPiDir=(string)(tmps);}
00619 
00620 //  if(r.Get("BeamType",imps)){kBeamType=imps;}
00621 
00622   if(r.Get("BeamString", tmps)){
00623      beamstring = tmps;  
00624      BeamType::BeamType_t beam = BeamType::kUnknown;
00625      if(beamstring.find("le010z185i")!=string::npos){ beam=BeamType::kL010z185i; }
00626      if(beamstring.find("le100z200i")!=string::npos){ beam=BeamType::kL100z200i; }
00627      if(beamstring.find("le250z200i")!=string::npos){ beam=BeamType::kL250z200i; }
00628      if(beamstring.find("le150z200i")!=string::npos){ beam=BeamType::kL150z200i; }
00629      if(beamstring.find("le010z200i")!=string::npos){ beam=BeamType::kL010z200i; }
00630      if(beamstring.find("le010z170i")!=string::npos){ beam=BeamType::kL010z170i; }
00631      if(beamstring.find("le010z000i")!=string::npos){ beam=BeamType::kL010z200i; }
00632      kBeamType = beam;
00633   }
00634 
00635   if(r.Get("FixMuParents",imps)){ 
00636     if(imps) kFixMuParents=true; 
00637     else kFixMuParents=false;
00638   }
00639 
00640   if(r.Get("MRCC",imps)){ SetMRCCRunning(imps);}
00641 }
00642 
00643 void NueModule::BeginJob()
00644 {
00645   MSG("NueModule",Msg::kDebug)<<"In NueModule::BeginJob"<<endl;
00646    
00647   if(tmpltfile!=""){
00648     MSG("NueModule",Msg::kDebug)<<"opening MST template file "
00649                                 <<tmpltfile<<endl;
00650     TFile f(tmpltfile.c_str());
00651     if(f.IsOpen()){
00652       MSTetemplate = (TProfile2D *)f.Get("nlambdanele");
00653       MSTbtemplate = (TProfile2D *)f.Get("nlambdanother");
00654       MSTemtemplate = (TProfile2D *)f.Get("mipdistele");
00655       MSTbmtemplate = (TProfile2D *)f.Get("mipdistother");
00656       MSG("NueModule",Msg::kDebug)<<"Did I get the histos? "
00657                                   <<MSTetemplate<<" "<<MSTbtemplate<<" "
00658                                   <<MSTemtemplate<<" "<<MSTbmtemplate<<endl;
00659       MSTetemplate->SetDirectory(0);
00660       MSTbtemplate->SetDirectory(0);
00661       MSTemtemplate->SetDirectory(0);
00662       MSTbmtemplate->SetDirectory(0);
00663       f.Close();
00664       MSG("NueModule",Msg::kDebug)<<"Do I still have them? "
00665                                   <<MSTetemplate->GetName()<<endl;
00666 
00667     }
00668   }
00669 // Beam Summary ntuples are obsolete!
00670 //  LoadBeamSummaryData(bmondir.c_str());
00671 }
00672 
00673 void NueModule::EndJob()
00674 {
00675 
00676    MSG("NueModule",Msg::kInfo)<<"Counter "<<counter
00677                               <<" passcutcounter "<<passcutcounter
00678                               <<" passcounter "<<passcounter
00679                               <<" failcounter "<<failcounter
00680                               <<" writecounter "<<writecounter<<endl;
00681 //   MSG("NueModule",Msg::kInfo)<<"Number of POT in this run: "<<pot<<endl;
00682 
00683    if(MSTetemplate!=0){
00684      delete MSTetemplate;
00685      MSTetemplate=0;
00686    }
00687    if(MSTbtemplate!=0){
00688      delete MSTbtemplate;
00689      MSTbtemplate=0;
00690    }
00691    if(MSTemtemplate!=0){
00692      delete MSTemtemplate;
00693      MSTemtemplate=0;
00694    }
00695    if(MSTbmtemplate!=0){
00696      delete MSTbmtemplate;
00697      MSTbmtemplate=0;
00698    }
00699 
00700 }
00701 
00702 void NueModule::LoadBeamSummaryData(const char *bd)
00703 {
00704     MSG("NueModule",Msg::kError)<<"Beam Summary ntuples are obsolete!"<<endl;
00705     return;
00706 
00707 
00708   DIR *dfd;
00709   if(!(dfd =  opendir(bd))){
00710     MSG("NueModule",Msg::kError)<<"Can not ls Beam Monitoring path "
00711                                 <<bd<<" "<<dfd<<std::endl;
00712     return;
00713   }
00714 }
00715 
00716 BeamType::BeamType_t NueModule::DetermineBeamType(VldContext vc){
00717 
00718 /*    BDSpillAccessor& sa = BDSpillAccessor::Get();
00719     VldContext evt_vldc = nr->GetHeader().GetVldContext();
00720 
00721     const BeamMonSpill* bms = sa.LoadSpill(vc.GetTimeStamp());
00722     VldTimeStamp bms_vts;
00723     if (!bms) {
00724        MSG("NueBeamMon",Msg::kError) << "No BeamMonSpill found for " << evt_vldc << endl;
00725        bms_vts = VldTimeStamp::GetEOT();
00726     }
00727     else {
00728         bms_vts = bms->SpillTime();
00729     }
00730     return bms->BeamType();
00731 */
00732     int time = vc.GetTimeStamp().GetSec();
00733 
00734     BeamType::BeamType_t beam = BeamType::kUnknown;
00735 
00736     if(time >= 1107216000 && time < 1109539850) beam = BeamType::kL100z200i;
00737     if(time >= 1109540615 && time < 1109899325) beam = BeamType::kL250z200i;
00738     if(time >= 1109899938 && time < 1110239564) beam = BeamType::kL100z200i;
00739     if(time >= 1110323763 && time < 1111622400) beam = BeamType::kL000z200i;
00740     if(time >= 1114892377 && time < 1115927583) beam = BeamType::kL100z200i;
00741     if(time >= 1115937438 && time < 1116604821) beam = BeamType::kL250z200i;
00742     if(time >= 1116618256 && time < 1122659668) beam = BeamType::kL010z185i;
00743     if(time >= 1122659886 && time < 1122922688) beam = BeamType::kL010z170i;
00744     if(time >= 1122922890 && time < 1123112674) beam = BeamType::kL010z200i;
00745     if(time >= 1123112803 && time < 1139605423) beam = BeamType::kL010z185i;
00746     if(time >= 1139605543 && time < 1140022084) beam = BeamType::kL010z000i;
00747     if(time >= 1140026702 && time < 1140908579) beam = BeamType::kL010z185i;
00748     // End of Run 1
00749     if(time >= 1149180600 && time < 1150047780) beam = BeamType::kL150z200i;
00750     if(time >= 1150047780 && time < 1151690460) beam = BeamType::kL250z200i;
00751     if(time >= 1153956600 && time < 1155510000) beam = BeamType::kL250z200i;
00752     if(time >= 1158004800 && time < 1158019870) beam = BeamType::kL010z200i;
00753     if(time >= 1158019870 && time < 1161892800) beam = BeamType::kL010z185i;
00754     if(time >= 1161892800 && time < 1184351737) beam = BeamType::kL010z185i;
00755     if(time >= 1184351737 && time < 1184708040) beam = BeamType::kL010z000i;
00756     //End of Run 2
00757 
00758     if(time >= 1184800000 ) beam = BeamType::kL010z185i;
00759 
00760     return beam;
00761 }
00762 
00763 BeamType::BeamType_t NueModule::DetermineBeamType(string file)
00764 {
00765    BeamType::BeamType_t beam = BeamType::kUnknown;
00766    if(file.find("L010185")!=string::npos){ beam=BeamType::kL010z185i; }
00767    if(file.find("L100200")!=string::npos){ beam=BeamType::kL100z200i; }
00768    if(file.find("L250200")!=string::npos){ beam=BeamType::kL250z200i; }
00769    if(file.find("L150200")!=string::npos){ beam=BeamType::kL150z200i; }
00770    if(file.find("L010200")!=string::npos){ beam=BeamType::kL010z200i; }
00771    if(file.find("L010170")!=string::npos){ beam=BeamType::kL010z170i; }
00772    if(file.find("L010000")!=string::npos){ beam=BeamType::kL010z000i; }
00773 
00774    return beam;
00775 }
00776 
00777 bool NueModule::PassesBlindingCuts(NueRecord *nr)
00778 {
00779   bool passes = true;
00780 
00781   if( kPidName != "None"){
00782      Selection::Selection_t pid = Selection::StringToEnum(kPidName.c_str());
00783 
00784      double pidVal = NueStandard::GetPIDValue(nr, pid);
00785      
00786      if(!ANtpDefVal::IsDefault(kPIDHighCut))
00787          passes = pidVal < kPIDHighCut;
00788 
00789      if(!ANtpDefVal::IsDefault(kPIDLowCut))
00790          passes = (passes) && pidVal > kPIDLowCut;
00791 
00792     if(pid != Selection::kANN6) nr->ann.pid_6inp = ANtpDefVal::kDouble;
00793     if(pid != Selection::kANN30) nr->ann.pid_30inp = ANtpDefVal::kDouble;
00794     if(pid != Selection::kSSPID) 
00795              nr->subshowervars.pid_daikon = ANtpDefVal::kDouble;
00796     if(pid != Selection::kMCNN) nr->mcnnv.fracCCy = ANtpDefVal::kDouble;
00797     if(pid != Selection::kCuts) nr->treepid.fCutPID = ANtpDefVal::kInt;
00798 
00799   }
00800 
00801   if(!ANtpDefVal::IsDefault(kCCPIDCut)){
00802      if(kCCPidName == "CC_DP")
00803          passes = passes &&  nr->mri.orig_cc_pid > kCCPIDCut;
00804      if(kCCPidName == "CC_AB")
00805          passes = passes &&  nr->mri.orig_abCCPID > kCCPIDCut;
00806   }
00807 
00808   NueConvention::NueEnergyCorrection(nr);
00809 
00810   if(!ANtpDefVal::IsDefault(kHighECut))
00811      passes = passes && nr->srevent.phNueGeV < kHighECut;
00812 
00813   if(!ANtpDefVal::IsDefault(kLowECut))
00814      passes =  passes && nr->srevent.phNueGeV > kLowECut;
00815 
00816   return passes;
00817 }
00818 

Generated on Mon Jun 16 14:58:04 2008 for loon by  doxygen 1.3.9.1