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

Module/VtxModule.cxx

Go to the documentation of this file.
00001 
00002 // $Id: VtxModule.cxx,v 1.2 2007/03/01 16:56:24 rhatcher Exp $
00003 //
00004 // FILL_IN: [Document your code!!]
00005 //
00006 // vahle@hep.ucl.ac.uk
00008 #include <dirent.h>
00009 #include "TChain.h"
00010 #include "TClonesArray.h"
00011 #include "TProfile2D.h"
00012 #include "StandardNtuple/NtpStRecord.h"
00013 #include "MessageService/MsgService.h"
00014 #include "MinosObjectMap/MomNavigator.h"
00015 #include "JobControl/JobCModuleRegistry.h" // For JOBMODULE macro
00016 #include "Calibrator/CalMIPCalibration.h"
00017 #include "MCNtuple/NtpMCRecord.h"
00018 #include "MCNtuple/NtpMCTruth.h"
00019 #include "TruthHelperNtuple/NtpTHRecord.h"
00020 #include "CandNtupleSR/NtpSRRecord.h"
00021 #include "CandNtupleSR/NtpSRStrip.h"
00022 #include "CandNtupleSR/NtpSREvent.h"
00023 #include "CandNtupleSR/NtpSRTrack.h"
00024 #include "NueAna/SntpHelpers.h"
00025 #include "NueAna/NueModule.h"
00026 #include "NueAna/NueRecord.h"
00027 #include "NueAna/NueRecordAna.h"
00028 #include "BeamData/ana/Summary/BeamSummary.h"
00029 #include "NueAna/EventFilter.h"
00030 
00031 #include "VertexFinder/Module/VtxModule.h"
00032 #include "VertexFinder/Module/VtxRecordAna.h"
00033 
00034 
00035 CVSID("$Id: VtxModule.cxx,v 1.2 2007/03/01 16:56:24 rhatcher Exp $");
00036 
00037 #include "DatabaseInterface/DbiResultPtr.tpl"
00038 
00039 
00040 JOBMODULE(VtxModule, "VtxModule",
00041           "");
00042 //......................................................................
00043 
00044 VtxModule::VtxModule():
00045    counter(0),
00046    passcounter(0),
00047    passcutcounter(0),
00048    failcounter(0),
00049    writecounter(0),
00050    foundmeu(false),
00051    SIGCORRMEU(1.),
00052    pot(0.),
00053    MEUPERGEV(25.66)
00054 {}
00055 
00056 //......................................................................
00057 
00058 VtxModule::~VtxModule()
00059 {
00060 }
00061 
00062 //......................................................................
00063 
00064 JobCResult VtxModule::Reco(MomNavigator* mom)
00065 {
00066 //======================================================================
00067 // Reads in sue-style ntuples from mom, calculates a bunch of useful
00068 // nue quantites
00069 //======================================================================
00070    MSG("VtxModule",Msg::kDebug)<<"In VtxModule::Reco"<<endl;
00071 
00072    if(counter%1000==0){      
00073       MSG("VtxModule",Msg::kInfo)<<"On entry "<<counter<<endl;
00074    }
00075    counter++;
00076    bool foundST=false;
00077       
00078    VldContext vc;
00079    //first ask mom for a NtpStRecord
00080    NtpStRecord *str=dynamic_cast<NtpStRecord *>(mom->GetFragment("NtpStRecord"));
00081    if(str){
00082      foundST=true;
00083      vc=str->GetHeader().GetVldContext();
00084    }
00085 
00086    //if we didn't find a NtpStRecord, it could be because we're reading an 
00087    //old tree, check for the other records
00088                                                 
00089    if(!foundST){
00090       //got nothing useful from mom
00091       MSG("VtxModule",Msg::kWarning)<<"Got Nothing from mom"<<endl;
00092       failcounter++;
00093       return JobCResult::kFailed;
00094    }
00095    
00096    //UGLY!!!!
00097    //need to be able to compare single strip 
00098    //pulseheight between ND and FD, but we can't
00099    //in the ntuple.  Will ask the db for the
00100    //conversion from sigcor to MEU 
00101    //on the first event, and use throughout.  
00102    //Since sigcorrs are already corrected for all strip variations, 
00103    //it's ok to ask for 1 number.  
00104    //Should be ok for MC, maybe ok for 1 run of data at a time, but will
00105    //definitely be wrong if many weeks worth of data are strung together
00106    //we should revisit this and make it better in the future!!!!!!!
00107    if(!foundmeu){
00108      DbiResultPtr<CalMIPCalibration> dbp(vc);
00109      if(dbp.GetNumRows()>0){
00110        const CalMIPCalibration *m = dbp.GetRow(0);
00111        float mip=m->GetMIP(1.); 
00112        if(mip>0){
00113          SIGCORRMEU=1./mip;
00114          foundmeu=true;
00115        }
00116      }
00117    }
00118 
00119    if(foundST){
00120      //find number of events in the snarl
00121       int evtn=str->evthdr.nevent;
00122       MSG("VtxModule",Msg::kDebug)<<"Events in this snarl: "<<evtn<<endl;
00123       
00124       //find vldcontext to make the header
00125       VldContext vc = str->GetHeader().GetVldContext();
00126       
00127       if(evtn==0){
00128         //we found an SR, but nothing got reco'ed in it
00129         
00130         //make a header
00131         NueHeader h(vc);
00132       
00133       //fill header info
00134         h.SetSnarl(str->GetHeader().GetSnarl());
00135         h.SetRun(str->GetHeader().GetRun());
00136         h.SetSubRun(str->GetHeader().GetSubRun());
00137         h.SetEventNo(-1);
00138         h.SetEvents(0);
00139         h.SetTrackLength(0);
00140         h.SetFoundBits(false,true,false);
00141       
00142         //make an ana_nue object
00143         VtxRecord *vtxRec = new VtxRecord(h);
00144         vtxRec->SetName("VtxRecord");
00145 
00146         //make a nuerecordana object
00147         VtxRecordAna ana_vtx(*vtxRec);
00148         
00149         //fill the truth info
00150         //if it's data, we can also do beam mon analyze
00151         ana_vtx.FillTrue(0,str);
00152 
00153         //give the ana_nue object to mom, she'll write it to the file
00154          mom->AdoptFragment(vtxRec);
00155          writecounter++;
00156          failcounter++;
00157         
00158          return JobCResult::kPassed;
00159       }      
00160       
00161       //if events were reco'd, loop over events in a snarl
00162       for(int i=0;i<evtn;i++){
00163               
00164         //make a header
00165         NueHeader h(vc);
00166         
00167         //fill header info
00168         h.SetSnarl(str->GetHeader().GetSnarl());
00169         h.SetRun(str->GetHeader().GetRun());
00170         h.SetSubRun(str->GetHeader().GetSubRun());
00171         h.SetEventNo(i);
00172         h.SetEvents(evtn);
00173         h.SetFoundBits(true,true,true);
00174         
00175         MSG("VtxModule",Msg::kDebug)<<"Getting event"<<endl;
00176         NtpSREvent *event = SntpHelpers::GetEvent(i,str);
00177       
00178         //loop over tracks in this event, find longest
00179         int longtrack=0;
00180         for(int j=0;j<event->ntrack;j++){
00181           int tindex = SntpHelpers::GetTrackIndex(j,event);
00182           NtpSRTrack *track = SntpHelpers::GetTrack(tindex,str);
00183           if(longtrack<track->plane.n){
00184             longtrack = track->plane.n;
00185           }
00186         }
00187         h.SetTrackLength(longtrack);
00188         
00189         VtxRecord *vtxRec = new VtxRecord(h);
00190         vtxRec->SetName("VtxRecord");
00191 
00192         //make a nuerecordana object
00193         VtxRecordAna ana_vtx(*vtxRec);
00194 
00195         //configure BeamMonAna
00196          passcutcounter++;
00197           //analyze calculates everybodies
00198           //variables, then calls the Truth and Reco Object Fillers
00199           //configure MSTCalcAna routine
00200          ana_vtx.ansia.SetParams(SIGCORRMEU, MEUPERGEV);
00201          ana_vtx.antia.SetParams(SIGCORRMEU, MEUPERGEV);          
00202          ana_vtx.aneia.SetParams(SIGCORRMEU, MEUPERGEV);
00203           //analysize
00204          ana_vtx.FillTrue(i,str);
00205          ana_vtx.FillReco(i,str);                        
00206          ana_vtx.Analyze(i,str);
00207         
00208         //give the ana_nue object to mom, she'll write it to the file
00209         MSG("VtxModule",Msg::kDebug)<<"Giving Fragment to mom"<<endl;
00210         writecounter++;
00211         mom->AdoptFragment(vtxRec);
00212         MSG("VtxModule",Msg::kDebug)<<"Mom took it"<<endl;
00213       }
00214       MSG("VtxModule",Msg::kDebug)<<"Done with snarl"<<endl;
00215       passcounter++;
00216       return JobCResult::kPassed; // kNoDecision, kFailed, etc.       
00217    }
00218 
00219    return JobCResult::kFailed;
00220 }
00221 
00222 //......................................................................
00223 
00224 const Registry& VtxModule::DefaultConfig() const
00225 {
00226 //======================================================================
00227 // Supply the default configuration for the module
00228 //======================================================================
00229    MSG("VtxModule",Msg::kDebug)<<"In VtxModule::DefaultConfig"<<endl;
00230 
00231   static Registry r; // Default configuration for module
00232 
00233   // Set name of config
00234   std::string name = this->GetName();
00235   name += ".config.default";
00236   r.SetName(name.c_str());
00237 
00238   // Set values in configuration
00239   r.UnLockValues();
00240   r.LockValues();
00241 
00242   return r;
00243 }
00244 
00245 //......................................................................
00246 
00247 void VtxModule::Config(const Registry& r)
00248 {
00249 //======================================================================
00250 // Configure the module given the Registry r
00251 //======================================================================
00252   MSG("VtxModule",Msg::kDebug)<<"In VtxModule::Config"<<endl;
00253 
00254 }
00255 
00256 void VtxModule::BeginJob()
00257 {
00258   MSG("VtxModule",Msg::kDebug)<<"In VtxModule::BeginJob"<<endl;
00259 }
00260 
00261 void VtxModule::EndJob()
00262 {
00263 
00264    MSG("VtxModule",Msg::kInfo)<<"Counter "<<counter
00265                               <<" passcutcounter "<<passcutcounter
00266                               <<" passcounter "<<passcounter
00267                               <<" failcounter "<<failcounter
00268                               <<" writecounter "<<writecounter<<endl;
00269    MSG("VtxModule",Msg::kInfo)<<"Number of POT in this run: "<<pot<<endl;
00270 
00271 }
00272 

Generated on Fri Mar 28 15:41:54 2008 for loon by  doxygen 1.3.9.1