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

TrimModule.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 "TrimModule.h"
00024 #include "NueAna/NueAnalysisCuts.h"
00025 
00026 const int CALend=110;
00027 const int SM1end=230;
00028 const int SM2end=484;
00029 
00030 JOBMODULE(TrimModule, "TrimModule",
00031           "Reduce the file size of AnaNue files by filtering out events");
00032 CVSID("$Id: TrimModule.cxx,v 1.2 2008/11/19 18:22:51 rhatcher Exp $");
00033 //......................................................................
00034 
00035 TrimModule::TrimModule():
00036   counter(0),
00037   kOutputFile("TrimmedOut.root"),
00038   kReWeight(0),
00039   kTheta23(1.0),
00040   kUe3Square(0.01),
00041   kDeltaMSquare(0.0025)
00042 {}
00043 
00044 //......................................................................
00045 
00046 TrimModule::~TrimModule()
00047 {}
00048 
00049 //......................................................................
00050 void TrimModule::BeginJob()
00051 {
00052   kept = 0;
00053 //  fCuts.Reset();
00054   if(counter%1000==0){
00055     cout<<"On entry "<<counter<<endl;
00056   }
00057 }
00058 
00059 
00060 JobCResult TrimModule::Reco(MomNavigator* mom)
00061 {
00062    //get all NueRecords from mom 
00063    //may have more than one per go since mom reads in a snarl's worth of data
00064    //so, this is a little more complicated than just asking for a NueRecord
00065    TObject *obj=0;
00066 //  static Float_t total_pot = 0;
00067 
00068    vector<NueRecord *> records;
00069 
00070    TIter objiter = mom->FragmentIter();
00071    while((obj=objiter.Next())){
00072       NueRecord *nr = dynamic_cast<NueRecord *>(obj);
00073       if(nr){
00074          MSG("TrimModule",Msg::kDebug)<<"Found a NueRecord in MOM"<<endl;
00075       }
00076       else{
00077          MSG("TrimModule",Msg::kError)<<"Didn't find a NueRecord in MOM"<<endl;
00078          continue;
00079       }
00080       nr->SetName("NueRecord_junk");
00081       MSG("TrimModule",Msg::kDebug)<<"Found a NueRecord in MOM"
00082                        <<" Snarl "<<nr->GetHeader().GetSnarl()
00083                        <<" Event "<<nr->GetHeader().GetEventNo()<<endl;
00084  
00085       if(nr->GetHeader().GetEventNo()<0){
00086         continue;
00087       }
00088 
00089       if(kReWeight)
00090       {
00091           int nuFlavor = nr->mctrue.nuFlavor;
00092           int  nonOsc = nr->mctrue.nonOscNuFlavor;
00093           float energy = nr->mctrue.nuEnergy;
00094                                                                                 
00095           Float_t newWeight = NueConvention::Oscillate(nuFlavor, nonOsc, energy,
00096                                 735, kDeltaMSquare, kTheta23, kUe3Square);
00097                                                                   
00098           nr->mctrue.Ue3Squared = kUe3Square;
00099           nr->mctrue.DeltamSquared23 = kDeltaMSquare;
00100           nr->mctrue.Theta23  = kTheta23;
00101           nr->mctrue.fOscProb = newWeight;
00102       }
00103 
00104       fCuts.SetInfoObject(nr);
00105       if(PassesCuts(nr) && PassesBeamCuts(nr)){
00106            MSG("TrimModule",Msg::kDebug)<<"Excellent a NueRecord survives"
00107                      <<" Snarl "<<nr->GetHeader().GetSnarl()
00108                      <<" Event "<<nr->GetHeader().GetEventNo()<<endl;
00109 
00110            nr->SetName("NueRecord_trim");
00111            kept++;
00112       }
00113       if(counter%1000==0){
00114          cout<<"On entry "<<counter<<endl;
00115       }
00116       counter++;
00117    }
00118 
00119    return JobCResult::kPassed; // kNoDecision, kFailed, etc.
00120 }
00121 
00123 void TrimModule::EndJob()
00124 {
00125   cout<<counter<<" events processed and "<<kept<<" were output"<<endl;
00126 
00127   //fCuts.Report();
00128 //Now i have to output the tree
00129   // Here is where all of the writeout work will be done, first the tree and then the histos
00130 
00131   //If we are oscillating the files, then the effective exposure is only one third per file
00132   //    if you are not using an equal number of files from each type I accept no responsibility
00133   //    for the nature of your results
00134 
00135 }
00136 
00137 const Registry& TrimModule::DefaultConfig() const
00138 {
00139 //======================================================================
00140 // Supply the default configuration for the module
00141 //======================================================================
00142    MSG("TrimModule",Msg::kDebug)<<"In TrimModule::DefaultConfig"<<endl;
00143 
00144   static Registry r = fCuts.DefaultConfig();
00145  
00146   // Set name of config
00147   std::string name = this->GetName();
00148   name += ".config.default";
00149   r.SetName(name.c_str());
00150                                                                                 
00151   // Set values in configuration
00152   r.UnLockValues();
00153   r.Set("OutputFile", "TrimmedNtuple.root");
00154 
00155   r.Set("DeltaMSquare", 0.0025);
00156   r.Set("Theta23", TMath::Pi()/4);
00157   r.Set("Ue3Square", 0.01);
00158   r.Set("ReWeight", 0);
00159   
00160   r.LockValues();
00161                                                                                 
00162   return r;
00163 }
00164 
00165 void TrimModule::Config(const Registry& r)
00166 {
00167 //======================================================================
00168 // Configure the module given the Registry r
00169 //======================================================================
00170   MSG("TrimModule",Msg::kDebug)<<"In TrimModule::Config"<<endl;
00171   
00172   fCuts.Config(r);
00173                                                                                
00174   //  const char* tmps;
00175   int imps;
00176   if(r.Get("ReWeight", imps)) {kReWeight = imps;}
00177   
00178   double fmps;
00179   if(r.Get("DeltaMSquare", fmps)) {kDeltaMSquare = fmps;}
00180   if(r.Get("Ue3Square", fmps))    {kUe3Square = fmps;}
00181   if(r.Get("Theta23", fmps))  {kTheta23 = fmps;}
00182 
00183   const char* tmps;
00184   if(r.Get("OutputFile", tmps)) {kOutputFile = tmps;}
00185   
00186 }
00187 
00188 bool TrimModule::PassesBeamCuts(NueRecord* nr)
00189 {
00190   //bool passes = true;
00191   if(nr->GetHeader().GetVldContext().GetSimFlag()!=SimFlag::kData) return true;
00192   if(fCuts.PassesBeamCut()) return true;;
00193 
00194   return false;
00195 }
00196 
00197 
00198 
00199 bool TrimModule::PassesCuts(NueRecord* nr)
00200 {
00201     bool passes = true;   
00202     if(nr == 0) return false;
00203     if(!fCuts.PassesFiducialVolume())    passes = false;
00204     if(!fCuts.PassesFullContainment())  passes = false;   
00205      
00206     if(!fCuts.PassesAllCuts())           passes = false;
00207 
00208      // Cut on min Total pulse height per prong (sigcor)
00209 //     if((nr->srevent.planes<1.05||nr->srevent.planes>16) ||
00210 //         (nr->hitcalc.fHitLongEnergy<30||nr->hitcalc.fHitLongEnergy>5000)||
00211 //         (nr->shwfit.uv_molrad_vert<0||nr->shwfit.uv_molrad_vert>5.51)||
00212 //        (nr->shwfit.par_b<0.315||nr->shwfit.par_b>1.47)) passes=false;
00213 
00214    return passes;
00215 }
00216 

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