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

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