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

CondensedNtpModuleNC.cxx

Go to the documentation of this file.
00001 
00002 //$Id: CondensedNtpModuleNC.cxx,v 1.23 2007/09/05 15:28:24 brebel Exp $
00003 //
00004 //CondensedNtpModuleNC.cxx
00005 //
00006 //Module for making analysis trees from SR ntuples
00007 //
00008 //B. Rebel 10/2004
00010 
00011 #include "AnalysisNtuples/Module/CondensedNtpModuleNC.h"
00012 
00013 //User/LOON Includes
00014 #include "AnalysisNtuples/ANtpEventInfoNC.h"
00015 #include "AnalysisNtuples/ANtpShowerInfoNC.h"
00016 #include "AnalysisNtuples/ANtpTrackInfoNC.h"
00017 #include "AnalysisNtuples/ANtpTruthInfoBeam.h"
00018 #include "AnalysisNtuples/ANtpBeamInfo.h"
00019 #include "AnalysisNtuples/ANtpHeaderInfo.h"
00020 #include "AnalysisNtuples/Module/ANtpInfoObjectFillerNC.h"
00021 #include "AnalysisNtuples/Module/ANtpRecoNtpManipulator.h"
00022 #include "MessageService/MsgService.h"
00023 #include "MinosObjectMap/MomNavigator.h"
00024 #include "JobControl/JobCModuleRegistry.h" // For JOBMODULE macro
00025 #include "JobControl/JobCommand.h"
00026 #include "Validity/VldTimeStamp.h" 
00027 #include "Validity/VldContext.h" 
00028 #include "StandardNtuple/NtpStRecord.h"
00029 #include "CandNtupleSR/NtpSRRecord.h"
00030 #include "CandNtupleSR/NtpSREvent.h"
00031 #include "CandNtupleSR/NtpSREventSummary.h"
00032 #include "CandNtupleSR/NtpSRSlice.h"
00033 #include "CandNtupleSR/NtpSRTrack.h"
00034 #include "CandNtupleSR/NtpSRShower.h"
00035 #include "CandNtupleSR/NtpSRShieldStrip.h"
00036 #include "CandNtupleSR/NtpSRShieldSummary.h"
00037 #include "CandNtupleSR/NtpSRCosmicRay.h"
00038 #include "CandNtupleSR/NtpSRDmxStatus.h"
00039 #include "MCNtuple/NtpMCRecord.h"
00040 #include "MCNtuple/NtpMCTruth.h"
00041 #include "MCNtuple/NtpMCStdHep.h"
00042 #include "TruthHelperNtuple/NtpTHRecord.h"
00043 #include "TruthHelperNtuple/NtpTHEvent.h"
00044 #include "Record/RecCandHeader.h"
00045 #include "RecoBase/ArrivalTime.h"
00046 #include "RecoBase/LinearFit.h"
00047 #include "Conventions/PlaneView.h"
00048 #include "Conventions/Detector.h"
00049 #include "Conventions/SimFlag.h"
00050 #include "BeamDataNtuple/NtpBDLiteRecord.h"
00051 
00052 #include "TFolder.h"
00053 #include "TDirectory.h"
00054 #include "TObjArray.h"
00055 #include "TCanvas.h"
00056 #include "TPaveText.h"
00057 #include "TPad.h"
00058 #include "TGraph.h"
00059 #include "TH2.h"
00060 #include "TH1.h"
00061 #include "Riostream.h"
00062 
00063 #include <cassert>
00064 #include <algorithm>
00065 #include <vector>
00066 
00067 using namespace std;
00068 
00069 CVSID("$Id: CondensedNtpModuleNC.cxx,v 1.23 2007/09/05 15:28:24 brebel Exp $");
00070 
00071 // Declare this module to JobControl. Arguments are:
00072 //  (1) The class name 
00073 //  (2) The human-readable name 
00074 //  (3) A short, human-readable description of what the module does
00075 JOBMODULE(CondensedNtpModuleNC, 
00076           "CondensedNtpModuleNC",
00077           "A module used for making analysis tress from SR ntuples");
00078 
00079 //......................................................................
00080 CondensedNtpModuleNC::CondensedNtpModuleNC() :
00081   fFileName("analysisNtuple.root"),
00082   fTreeName("analysisNtuple"),
00083   fNtpFile(0),
00084   fNtuple(0),
00085   fEventInfo(0),
00086   fHeaderInfo(0),
00087   fShowerInfo(0),
00088   fTrackInfo(0),
00089   fTruthInfo(0),
00090   fVHSPlanes(20),
00091   fVHSStrips(20)
00092 {
00093   MSG("JobC", Msg::kDebug) << "CondensedNtpModuleNC::Constructor" << endl;
00094     
00095   fHeaderInfo = new ANtpHeaderInfo();
00096   fEventInfo = new ANtpEventInfoNC();
00097   fTrackInfo = new ANtpTrackInfoNC();
00098   fShowerInfo = new ANtpShowerInfoNC();
00099   fTruthInfo = new ANtpTruthInfoBeam();
00100   fBeamInfo = new ANtpBeamInfo();
00101   
00102   fInfoFiller = new ANtpInfoObjectFillerNC();
00103   
00104   fFailedDeMux = 0;
00105 }
00106 
00107 //----------------------------------------------------------------------
00108 CondensedNtpModuleNC::~CondensedNtpModuleNC()
00109 {
00110   
00111   MSG("JobC", Msg::kDebug) << "CondensedNtpModuleNC::Destructor" << endl;
00112   
00113   if(fHeaderInfo) delete fHeaderInfo;   
00114   if(fEventInfo) delete fEventInfo;     
00115   if(fShowerInfo) delete fShowerInfo;   
00116   if(fTrackInfo) delete fTrackInfo;     
00117   if(fTruthInfo) delete fTruthInfo;     
00118   if(fBeamInfo) delete fBeamInfo;
00119 
00120 }
00121 
00122 //----------------------------------------------------------------------
00123 void CondensedNtpModuleNC::BeginJob()
00124 {
00125   MSG("CondensedNtpModuleNC", Msg::kDebug) 
00126     << "in BeginJob" << endl;
00127   
00128   // save the current working directory
00129   //TDirectory* savedir  = gDirectory;  
00130   
00131   //create the new TFile for holding the electronics tree
00132   // this changes the value of gDirectory
00133   fNtpFile = new TFile(fFileName,"RECREATE");  
00134 //   if(!fNtpFile->IsOpen() ) MSG("CondensedNtpModuleNC", Msg::kFatal) << "file not open " 
00135 //                                                                  << fFileName << endl;
00136 
00137   // create TTree, these will attach themselves to the current 
00138   //working directory   
00139   fNtuple = new TTree(fTreeName, "Analysis Tree");
00140   
00141   //-----------------------------------------------------------------------
00142   //here is where you define your tree
00143   fNtuple->Branch("header.", "ANtpHeaderInfo", &fHeaderInfo, 64000, 2);
00144   fNtuple->Branch("event.", "ANtpEventInfoNC", &fEventInfo, 64000, 2);
00145   fNtuple->Branch("shower.", "ANtpShowerInfoNC", &fShowerInfo, 64000, 2);
00146   fNtuple->Branch("track.", "ANtpTrackInfoNC", &fTrackInfo, 64000, 2);
00147   fNtuple->Branch("beam.", "ANtpBeamInfo", &fBeamInfo, 64000, 2);
00148   if(fDataType==1) 
00149     fNtuple->Branch("truth.", "ANtpTruthInfoBeam", &fTruthInfo, 64000, 2);
00150   
00151   MSG("CondensedNtpModuleNC", Msg::kDebug) << "got branches" << endl;
00152   
00153   //-----------------------------------------------------------------------
00154 
00155   // Setup Kregg's image recognition filling
00156   fInfoFiller->InitializeVHSTraining(fVHSPlanes, fVHSStrips);
00157     
00158   // change back to current working directory before leaving constructor
00159   //savedir->cd();   
00160   
00161   return;
00162 }
00163 
00164 //......................................................................
00165 //here is where you would loop over the events in the snarl to fill the 
00166 //analysis tree
00167 JobCResult CondensedNtpModuleNC::Ana(const MomNavigator *mom)
00168 {
00169   // bool mc = false;
00170   
00171   JobCResult result(JobCResult::kPassed);
00172   
00173   //get the records from MOM
00174   assert(mom);
00175   
00176   NtpSRRecord *record = dynamic_cast<NtpSRRecord *>(mom->GetFragment("NtpSRRecord"));
00177   NtpStRecord *stRecord = dynamic_cast<NtpStRecord *>(mom->GetFragment("NtpStRecord"));
00178   
00179   if(!record && !stRecord){
00180     MSG("CondensedNtpModuleAtm", Msg::kWarning) << "Could not get NtpSR or NtpSt "
00181                                                 << "Record from MOM" << endl;
00182     result.SetWarning().SetFailed();
00183     return result;
00184   }//end if no NtpSRRecord
00185   
00186   NtpMCRecord *mcRecord = 0;
00187   NtpTHRecord *thRecord = 0;
00188   
00189   mcRecord = dynamic_cast<NtpMCRecord *>(mom->GetFragment("NtpMCRecord"));
00190   thRecord = dynamic_cast<NtpTHRecord *>(mom->GetFragment("NtpTHRecord"));
00191 
00192   //get the record for the beam tree
00193   NtpBDLiteRecord *bdRecord = 0;
00194   //bdRecord = dynamic_cast<NtpBDLiteRecord *>(mom->GetFragment("NtpBDLiteRecord"));
00195       
00196   //instantiate a NtpHelper object to help you get the info you want
00197   ANtpRecoNtpManipulator *ntpManipulator = 0;
00198   if(record) ntpManipulator = new ANtpRecoNtpManipulator(record, mcRecord, thRecord);
00199   else if(stRecord) ntpManipulator = new ANtpRecoNtpManipulator(stRecord);
00200 
00201   const VldContext *vldc = stRecord ? stRecord->GetVldContext() : record->GetVldContext();
00202   VldTimeStamp timeStamp = vldc->GetTimeStamp();
00203 
00204   //fill the header information
00205   Detector::Detector_t det = vldc->GetDetector();
00206 
00207   //get a sim flag
00208   SimFlag::SimFlag_t dataType = vldc->GetSimFlag();
00209 
00210   fInfoFiller->SetDetector(det);
00211   fInfoFiller->SetStripArray(ntpManipulator->GetStripArray());
00212   fInfoFiller->SetClusterArray(ntpManipulator->GetClusterArray());
00213   fInfoFiller->FillHeaderInformation(ntpManipulator, det, dataType, fHeaderInfo);
00214 
00215   MSG("CondensedNtpModuleNC", Msg::kDebug) << "snarl " << fHeaderInfo->snarl << endl;
00216   
00217 //   MAXMSG("CondensedNtpModuleNC",Msg::kDebug,20)
00218 //     << "detector = " << fHeaderInfo->detector << " " << det << endl;
00219 
00220   if(fHeaderInfo->year > 2004){
00221     if(bdRecord) {
00222       fInfoFiller->FillBeamInformation(bdRecord, fBeamInfo);
00223       MAXMSG("CondensedNtpModuleNC",Msg::kDebug,1) 
00224         << "Using NtpBDLiteRecord to fill beam info." << endl;
00225       MAXMSG("CondensedNtpModuleNC", Msg::kDebug,100) << timeStamp << " " 
00226                                                      << " " << fHeaderInfo->utc 
00227                                                      << " " << fBeamInfo->tortgt
00228                                                      << endl;
00229     }
00230     else {
00231       fInfoFiller->FillBeamInformation(timeStamp, det, dataType, fBeamInfo);
00232       MAXMSG("CondensedNtpModuleNC",Msg::kDebug,1)
00233         << "Calling db method to fill beam info." << endl;
00234     }
00235   }
00236 
00237   if(fHeaderInfo->passedDeMux == 0)
00238     ++fFailedDeMux;
00239   
00240   //set up which flags you want to use to determine the primary shower or track
00241   //a value of 0 for a flag means it will not be used
00242   ntpManipulator->SetPrimaryTrackCriteria(0,1,0); // nplanes, length, total pulse height
00243 
00244   //for now set the primary shower criteria both to 0, that will pick out the first
00245   //shower in the reco array, which has been determined to be the one to use.  some 
00246   //other cuts still apply, but can be put in at the analysis level, not the ntuple
00247   //making level.  this was settled at the reco meeting on 2/9/06 - bjr
00248   ntpManipulator->SetPrimaryShowerCriteria(0,0); // nplanes, total pulse height
00249   
00250   //--------------------------------------------------------------------
00251   //here is where you start looping over the events in the ntuple to fill 
00252   //your analysis tree
00253   
00254   //handle the special case where you have a spill but no events
00255   if(fHeaderInfo->events < 1){
00256     //reset all the event, track and shower info objects to their default values
00257     //the beam and header values remain
00258     fEventInfo->Reset();
00259     fTrackInfo->Reset();
00260     fShowerInfo->Reset();
00261     fNtuple->Fill();
00262     return result;
00263   }
00264 
00265   //initialize the kNN stuff as it should only be done once per snarl
00266   fInfoFiller->InitializekNN(ntpManipulator);
00267 
00268   //loop over the events in the snarl
00269   for(Int_t i = 0; i < fHeaderInfo->events; ++i){
00270     
00271     MSG("CondensedNtpModuleNC", Msg::kDebug) << "on event " << i << endl;
00272  
00273     //reset the variables for the tree
00274     ResetTreeVariables();
00275 
00276     //if this isnt the first event in the snarl, then set the fHeaderInfo->newSnarl
00277     //to 0
00278     if(i > 0) fHeaderInfo->newSnarl = 0;
00279 
00280     if( fInfoFiller->FillInformation(i, ntpManipulator, fEventInfo, fTrackInfo,
00281                                      fShowerInfo, fTruthInfo) ){
00282     
00283       fNtuple->Fill();
00284       
00285     }//end if filling succeeded
00286   }//end loop over events for this snarl
00287   //-------------------------------------------------------------------
00288   
00289   return result;
00290 }
00291 
00292 //......................................................................
00293 void CondensedNtpModuleNC::Help() 
00294 {
00295   MSG("JobC", Msg::kDebug) 
00296     << "CondensedNtpModuleNC::Help\n"
00297     <<"CondensedNtpModuleNC is a module which demultiplexes events "
00298     <<"in the far detector."
00299     << endl;
00300 }
00301 
00302 //----------------------------------------------------------------------
00303 void CondensedNtpModuleNC::EndJob() 
00304 {
00305   
00306   MSG("CondensedNtpModuleNC", Msg::kInfo) << "start end job method " << fFailedDeMux 
00307                                           << " failed demuxing" << endl;        
00308   
00309   //cd to the "directory" of the file
00310   fNtpFile->cd();
00311   
00312   // only write file  -- this is enough and prevents duplication
00313   fNtpFile->Write();
00314   fNtpFile->Close();
00315   
00316   return;
00317 }
00318 
00319 //......................................................................
00320 const Registry& CondensedNtpModuleNC::DefaultConfig() const
00321 {
00322   
00323   int itrue = 1;  // work around for lack of bool in registry
00324   int ifalse = 0; // work around for lack of bool in registry
00325   
00326   static Registry r;
00327   
00328   r.UnLockValues();
00329   
00330   r.Set("FileName",               "analysisTree.root");
00331   r.Set("TreeName",               "analysisTree");
00332   r.Set("DataType",               1);
00333 
00334   r.Set("VHSPlanes",20);
00335   r.Set("VHSStrips",20);
00336 
00337   r.LockValues();
00338 
00339   //quiet the compiler
00340   itrue = ifalse;
00341   
00342   return r;
00343 }
00344 
00345 //......................................................................
00346 void CondensedNtpModuleNC::Config(const Registry& r)
00347 {
00348   int         tmpb;  // a temp bool. See comment under DefaultConfig...
00349   int         tmpi;  // a temp int.
00350   double      tmpd;  // a temp double.
00351   const char* tmps;  // a temp string
00352   
00353   if (r.Get("FileName",               tmps)) fFileName             =  tmps;
00354   if (r.Get("TreeName",               tmps)) fTreeName             =  tmps;
00355   if (r.Get("DataType",               tmpi)) fDataType             =  tmpi;
00356 
00357   if (r.Get("VHSPlanes",              tmpi)) fVHSPlanes            =  tmpi;
00358   if (r.Get("VHSStrips",              tmpi)) fVHSStrips            =  tmpi;
00359 
00360   tmpb = 0;
00361   tmpd = 1.;
00362 
00363   return;
00364 }
00365 
00366 //......................................................................
00367 void CondensedNtpModuleNC::ResetTreeVariables()
00368 {
00369 
00370   fEventInfo->Reset();
00371   fTrackInfo->Reset();
00372   fShowerInfo->Reset();
00373   fTruthInfo->Reset();
00374 
00375   return;
00376 }

Generated on Mon Jun 16 14:56:52 2008 for loon by  doxygen 1.3.9.1