00001
00002
00003
00004
00005
00006
00008 #include "TClonesArray.h"
00009
00010 #include "MCMonitorBeam.h"
00011 #include "MessageService/MsgService.h"
00012 #include "MinosObjectMap/MomNavigator.h"
00013 #include "JobControl/JobCModuleRegistry.h"
00014 #include "HistMan/HistMan.h"
00015 #include "MCNtuple/NtpMCStdHep.h"
00016 #include "MCNtuple/NtpMCTruth.h"
00017
00018 JOBMODULE(MCMonitorBeam, "MCMonitorBeam",
00019 "Produce MC plots for beam ray validation.");
00020 CVSID("$Id: MCMonitorBeam.cxx,v 1.1 2008/02/05 20:30:05 schubert Exp $");
00021 ClassImp(MCMonitorBeam)
00022
00023
00024 MCMonitorBeam::MCMonitorBeam() :
00025 fHists(new MCMonitorBeamHistograms("MCMonBeam")),fOutRootFileName("") {
00026
00027
00028 MSG("MCMon",Msg::kDebug) << "In MCMonitorBeam constructor" << endl;
00029
00030 }
00031
00032 MCMonitorBeam::~MCMonitorBeam()
00033 {
00034
00035 MSG("MCMon",Msg::kDebug) << "In MCMonitorBeam destructor" << endl;
00036
00037 }
00038
00039 void MCMonitorBeam::BeginJob() {
00040
00041 MSG("MCMon",Msg::kDebug) << "In MCMonitorBeam::BeginJob" << endl;
00042
00043 }
00044
00045 void MCMonitorBeam::EndJob() {
00046
00047
00048 MSG("MCMon",Msg::kDebug) << "In MCMonitorBeam::EndJob" << endl;
00049
00050 if (fNumSnarlsInCurrFile != 0) EndFile();
00051
00052 unsigned int numFiles = fNumSnarlsInFile.size();
00053 unsigned int numSnarls = 0;
00054 for ( unsigned int ifile = 0; ifile < numFiles; ifile++ ) {
00055 numSnarls += fNumSnarlsInFile[ifile];
00056 }
00057
00058 fHists->SetCanRebin();
00059 fHists->AllSumw2();
00060
00061
00062 MSG("MCMon",Msg::kInfo)
00063 << "MCMonitor::EndJob storing histograms to file "
00064 << fOutRootFileName.c_str() << endl;
00065 HistMan hm((fHists->GetName()).c_str());
00066 hm.WriteOut(fOutRootFileName.c_str());
00067
00068
00069 cout << std::string(75,'-') << endl;
00070 cout << "Processed " << numFiles << " files" << endl
00071 << "Processed " << numSnarls << " snarls" << endl
00072 << "Produced " << fHists->NumHistograms()
00073 << " histograms written to file: " << fOutRootFileName.c_str()
00074 << endl;
00075 cout << std::string(75,'-') << endl;
00076
00077 }
00078
00079 void MCMonitorBeam::BeginFile() {
00080
00081
00082 MSG("MCMon",Msg::kDebug) << "In MCMonitorBeam::BeginFile" << endl;
00083
00084 }
00085
00086 void MCMonitorBeam::EndFile() {
00087
00088 MSG("MCMon",Msg::kDebug)
00089 << "In MCMonitorBeam::EndFile \n"
00090 << "Num Snarls in Current File : "
00091 << fNumSnarlsInCurrFile << endl;
00092
00093 fNumSnarlsInFile.push_back(fNumSnarlsInCurrFile);
00094
00095 fNumSnarlsInCurrFile = 0;
00096
00097 }
00098
00099
00100 JobCResult MCMonitorBeam::Ana(const MomNavigator* mom)
00101 {
00102
00103 MSG("MCMon",Msg::kDebug) << "In MCMonitorBeam::Ana" << endl;
00104
00105
00106 NtpStRecord* strec =
00107 dynamic_cast<NtpStRecord*>( mom->GetFragment("NtpStRecord") );
00108
00109 NtpMCRecord* mcrec = 0;
00110
00111 if (!strec) {
00112 mcrec = dynamic_cast<NtpMCRecord*>( mom->GetFragment("NtpMCRecord") );
00113 if (!mcrec) {
00114 MSG("MCMon",Msg::kWarning)
00115 << "No NtpStRecord or NtpMCRecord in Mom! Aborting . . ."
00116 << endl;
00117 return JobCResult::kFailed;
00118 }
00119 }
00120
00121 fHists -> FillHistograms(strec, mcrec);
00122
00123
00124 fNumSnarlsInCurrFile++;
00125
00126 MSG("MCMon",Msg::kDebug) << "\n-----> Processed " << fNumSnarlsInCurrFile
00127 << " snarls in this file." << endl;
00128
00129 return JobCResult::kPassed;
00130
00131 }
00132
00133 const Registry& MCMonitorBeam::DefaultConfig() const
00134 {
00135
00136
00137
00138 MSG("MCMon",Msg::kDebug) << "In MCMonitorBeam::DefaultConfig" << endl;
00139
00140 static Registry r;
00141
00142
00143 std::string name = this->GetName();
00144 name += ".config.default";
00145 r.SetName(name.c_str());
00146
00147
00148 r.UnLockValues();
00149 r.Set("OutFile","mcmonitor.root");
00150 r.LockValues();
00151
00152 return r;
00153 }
00154
00155 void MCMonitorBeam::Config(const Registry& r)
00156 {
00157
00158
00159
00160
00161 MSG("MCMon",Msg::kDebug) << "In MCMonitorBeam::Config" << endl;
00162
00163 fOutRootFileName = r.GetCharString("OutFile");
00164 }
00165