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

MCMonitorCosmic.cxx

Go to the documentation of this file.
00001 
00002 //
00003 // MCMonitorCosmic
00004 //    Modified version of Kregg Arm's MCMonitor class to generate
00005 //    histograms specific to comparison of ptsim to gminos cosmic ray
00006 //    muons
00008 #include "TClonesArray.h"
00009 
00010 #include "MCMonitorCosmic.h"
00011 #include "MessageService/MsgService.h"
00012 #include "MinosObjectMap/MomNavigator.h"
00013 #include "JobControl/JobCModuleRegistry.h" // For JOBMODULE macro
00014 #include "HistMan/HistMan.h"
00015 #include "MCNtuple/NtpMCStdHep.h"
00016 #include "MCNtuple/NtpMCTruth.h"
00017 #include "MCNtuple/NtpMCDigiScintHit.h"
00018 
00019 JOBMODULE(MCMonitorCosmic, "MCMonitorCosmic",
00020           "Produce MC plots for cosmic ray muon validation.");
00021 CVSID("$Id: MCMonitorCosmic.cxx,v 1.1 2007/10/10 03:11:22 schubert Exp $");
00022 ClassImp(MCMonitorCosmic)
00023 
00024 //___________________________________________________________________________
00025 MCMonitorCosmic::MCMonitorCosmic() : 
00026   fHists(new MCMonitorCosmicHistograms("MCMonCosmic")),fOutRootFileName("") {
00027   // Default constructor
00028 
00029   MSG("MCMon",Msg::kDebug) << "In MCMonitorCosmic constructor" << endl;
00030 
00031 }
00032 //___________________________________________________________________________
00033 MCMonitorCosmic::~MCMonitorCosmic()
00034 {
00035   // Destructor
00036   MSG("MCMon",Msg::kDebug) << "In MCMonitorCosmic destructor" << endl;
00037 
00038 }
00039 //___________________________________________________________________________
00040 void MCMonitorCosmic::BeginJob() {
00041   
00042   MSG("MCMon",Msg::kDebug) << "In MCMonitorCosmic::BeginJob" << endl;
00043 
00044 }
00045 //___________________________________________________________________________
00046 void MCMonitorCosmic::EndJob() {
00047   //
00048   //
00049   MSG("MCMon",Msg::kDebug) << "In MCMonitorCosmic::EndJob" << endl;
00050 
00051   if (fNumSnarlsInCurrFile !=  0) EndFile();
00052 
00053   unsigned int numFiles = fNumSnarlsInFile.size();
00054   unsigned int numSnarls = 0;
00055   for ( unsigned int ifile = 0; ifile < numFiles; ifile++ ) {
00056     numSnarls += fNumSnarlsInFile[ifile];
00057   }
00058   
00059   fHists->SetCanRebin();
00060   fHists->AllSumw2();
00061   
00062   // Send all of the histograms to output root file
00063   MSG("MCMon",Msg::kInfo)
00064      << "MCMonitor::EndJob storing histograms to file "
00065      << fOutRootFileName.c_str() << endl;
00066   HistMan hm((fHists->GetName()).c_str());
00067   hm.WriteOut(fOutRootFileName.c_str());
00068 
00069   // Print a summary of the module
00070   cout << std::string(75,'-') << endl;
00071   cout << "Processed " << numFiles << " files" << endl
00072        << "Processed " << numSnarls << " snarls" << endl
00073        << "Produced  " << fHists->NumHistograms()
00074        << " histograms written to file: " << fOutRootFileName.c_str()
00075        << endl;
00076   cout << std::string(75,'-') << endl;
00077 
00078 }
00079 //___________________________________________________________________________
00080 void MCMonitorCosmic::BeginFile() {
00081   //
00082 
00083   MSG("MCMon",Msg::kDebug) << "In MCMonitorCosmic::BeginFile" << endl;
00084 
00085 }
00086 //___________________________________________________________________________
00087 void MCMonitorCosmic::EndFile() {
00088 
00089   MSG("MCMon",Msg::kDebug)
00090     << "In MCMonitorCosmic::EndFile \n" 
00091     << "Num Snarls in Current File           : "
00092     << fNumSnarlsInCurrFile << endl;
00093   // Send 'number of X per file' info to vectors; increment fFileNum
00094   fNumSnarlsInFile.push_back(fNumSnarlsInCurrFile);
00095 
00096   fNumSnarlsInCurrFile = 0;
00097 
00098 }
00099 
00100 //___________________________________________________________________________
00101 JobCResult MCMonitorCosmic::Ana(const MomNavigator* mom)
00102 {
00103 
00104   MSG("MCMon",Msg::kDebug) << "In MCMonitorCosmic::Ana" << endl;
00105 
00106   // get NtpSt from the file
00107   NtpStRecord* strec =
00108     dynamic_cast<NtpStRecord*>( mom->GetFragment("NtpStRecord") );
00109   // (just in case strec isn't present . . .)
00110   NtpMCRecord* mcrec = 0;
00111   NtpSRRecord* srrec = 0;
00112   NtpTHRecord* threc = 0;
00113   
00114   if (!strec) {
00115     mcrec = dynamic_cast<NtpMCRecord*>( mom->GetFragment("NtpMCRecord") );
00116     if (!mcrec) {
00117       MSG("MCMon",Msg::kWarning)
00118         << "No NtpStRecord or NtpMCRecord in Mom! Aborting . . ."
00119         << endl;
00120       return JobCResult::kFailed;
00121     }
00122     srrec = dynamic_cast<NtpSRRecord*>(mom->GetFragment("NtpSRRecord"));
00123     threc = dynamic_cast<NtpTHRecord*>(mom->GetFragment("NtpTHRecord"));
00124   } 
00125 
00126   fHists -> FillHistograms(strec, mcrec, srrec, threc);
00127 
00128   // Increment #snarls/file
00129   fNumSnarlsInCurrFile++;
00130 
00131   MSG("MCMon",Msg::kDebug) << "\n-----> Processed " << fNumSnarlsInCurrFile 
00132                            << " snarls in this file." << endl;
00133 
00134   return JobCResult::kPassed; 
00135 
00136 }
00137 //___________________________________________________________________________
00138 const Registry& MCMonitorCosmic::DefaultConfig() const
00139 {
00140   //
00141   // Supply the default configuration for the module
00142   //
00143   MSG("MCMon",Msg::kDebug) << "In MCMonitorCosmic::DefaultConfig" << endl;
00144 
00145   static Registry r; // Default configuration for module
00146 
00147   // Set name of config
00148   std::string name = this->GetName();
00149   name += ".config.default";
00150   r.SetName(name.c_str());
00151 
00152   // Set values in configuration
00153   r.UnLockValues();
00154   r.Set("OutFile","mcmonitor.root");    // Output root file for histograms
00155   r.LockValues();
00156 
00157   return r;
00158 }
00159 //___________________________________________________________________________
00160 void MCMonitorCosmic::Config(const Registry& r)
00161 {
00162   //
00163   // Configure the module given the Registry r
00164   //
00165 
00166   MSG("MCMon",Msg::kDebug) << "In MCMonitorCosmic::Config" << endl;
00167 
00168   fOutRootFileName   = r.GetCharString("OutFile");
00169 }
00170 //___________________________________________________________________________

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