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

FixModule.cxx

Go to the documentation of this file.
00001 
00002 //
00003 // FILL_IN: [Document your code!!]
00004 //
00005 // boehm@physics.harvard.edu
00007 #include "TH1F.h"
00008 #include "TFile.h"
00009 #include "Conventions/Detector.h"
00010 #include "NueAna/NueRecord.h"
00011 #include "MessageService/MsgService.h"
00012 #include "MinosObjectMap/MomNavigator.h"
00013 #include "MessageService/MsgService.h"
00014 #include "JobControl/JobCModuleRegistry.h" // For JOBMODULE macro
00015 #include "HistMan/HistMan.h"
00016 #include <fstream>
00017 #include "AnalysisNtuples/ANtpDefaultValue.h"                                   
00018 #include "TClass.h"
00019 #include "TDataType.h"
00020 #include "TDataMember.h"
00021 #include "TRealData.h"
00022 #include <string>
00023 #include "FixModule.h"
00024 #include "TChain.h"
00025 #include "NueAna/NuePOT.h"
00026 #include "TDirectory.h"
00027 #include "TROOT.h"
00028 
00029 
00030 #include "NueAna/Module/SetKNNModule.h"
00031 #include "PhysicsNtuple/Handle.h"
00032 #include "PhysicsNtuple/Factory.h"
00033 
00034 const int CALend=110;
00035 const int SM1end=230;
00036 const int SM2end=484;
00037 
00038 JOBMODULE(FixModule, "FixModule",
00039           "Reduce the file size of AnaNue files by filtering out events");
00040 CVSID("$Id: FixModule.cxx,v 1.2 2008/11/19 18:33:13 rhatcher Exp $");
00041 //......................................................................
00042 
00043 FixModule::FixModule():
00044   counter(0)
00045 {}
00046 
00047 //......................................................................
00048 
00049 FixModule::~FixModule()
00050 {}
00051 
00052 //......................................................................
00053 void FixModule::BeginJob()
00054 {
00055   kept = 0;
00056 //  fCuts.Reset();
00057   if(counter%1000==0){
00058     cout<<"On entry "<<counter<<endl;
00059   }
00060 }
00061 
00062 
00063 JobCResult FixModule::Reco(MomNavigator* mom)
00064 {
00065    //get all NueRecords from mom 
00066    //may have more than one per go since mom reads in a snarl's worth of data
00067    //so, this is a little more complicated than just asking for a NueRecord
00068    TObject *obj=0;
00069 //  static Float_t total_pot = 0;
00070 
00071    vector<NueRecord *> records;
00072 
00073    Anp::Handle<StorekNNData> data = Anp::Factory<StorekNNData>::Instance().Get("kNNData");
00074    if(!data.valid())
00075    {
00076       MAXMSG("NueModule", Msg::kError, 1)
00077            << "NueModule::Reco - Handle<StorekNNData> is invalid, assuming no Rustem variable to run"
00078            << endl;
00079    }
00080 
00081    bool foundOne = false;
00082    TIter objiter = mom->FragmentIter();
00083    while((obj=objiter.Next())){
00084       NueRecord *nr = dynamic_cast<NueRecord *>(obj);
00085       if(nr){
00086          foundOne = true;
00087          MSG("FixModule",Msg::kDebug)<<"Found a NueRecord in MOM"<<endl;
00088       }
00089       else{
00090          MSG("FixModule",Msg::kDebug)<<"Didn't find a NueRecord in MOM"<<endl;
00091          continue;
00092       }
00093       MSG("FixModule",Msg::kDebug)<<"Found a NueRecord in MOM"
00094                        <<" Snarl "<<nr->GetHeader().GetSnarl()
00095                        <<" Event "<<nr->GetHeader().GetEventNo()<<endl;
00096  
00097 
00098       if(nr->mri.orig_event > -10){
00099         float knn_pid;
00100 
00101         data -> SetPrefix("OldSNTP");
00102         data -> Get(nr->mri.orig_event, "knn_pid", knn_pid);
00103         nr->mri.orig_roCCPID = knn_pid; 
00104       }
00105 
00106       if(counter%1000==0){
00107          cout<<"On entry "<<counter<<endl;
00108       }
00109       counter++;
00110    }
00111 
00112    data->Clear();
00113    if(!foundOne) return JobCResult::kFailed;
00114 
00115    return JobCResult::kPassed; // kNoDecision, kFailed, etc.
00116 }
00117 
00119 void FixModule::EndJob()
00120 {
00121   cout<<counter<<" events processed and "<<kept<<" were output"<<endl;
00122 
00123   TChain* ch = new TChain("pottree");
00124   ch->Add(fInFile.c_str());
00125   
00126   NuePOT* pt = new NuePOT();
00127   
00128   ch->SetBranchAddress("NuePOT", &pt);
00129   ch->GetEntry(0);  
00130 
00131   TDirectory *savedir = gDirectory;
00132 
00133   cout<<"Trying to access: "<<fOutFile<<endl;
00134 
00135   TFile *fpf = dynamic_cast<TFile *>(gROOT->GetListOfFiles()->FindObject(fOutFile.c_str()));
00136   if(fpf){
00137      cout<<"Got the file and rolling"<<endl;
00138      fpf->cd();
00139      TTree *pottree = new TTree("pottree","pottree");
00140      pottree->Branch("NuePOT",&pt);
00141      pottree->Fill();
00142      pottree->Write();
00143      savedir->cd();
00144    }else{
00145     cout<<"failed!"<<endl;
00146   }
00147 }
00148 
00149 const Registry& FixModule::DefaultConfig() const
00150 {
00151     static Registry r;
00152     r.UnLockValues();
00153     r.Set("InFileName","blank.root");
00154     r.Set("FileName","pottree.root");
00155     r.LockValues();
00156     
00157     return r;
00158 }
00159 
00160 void FixModule::Config(const Registry& r)
00161 {
00162     const char* tmps;
00163     if(r.Get("InFileName",tmps)){ fInFile=tmps;}
00164     if(r.Get("FileName",tmps)){fOutFile=tmps;}
00165 }
00166 
00167 

Generated on Mon Feb 15 11:06:44 2010 for loon by  doxygen 1.3.9.1