00001
00002
00003
00004
00005
00006
00007
00008
00010
00011 #include "AnalysisNtuples/Module/CondensedNtpModuleNC.h"
00012
00013
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"
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
00072
00073
00074
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
00129
00130
00131
00132
00133 fNtpFile = new TFile(fFileName,"RECREATE");
00134
00135
00136
00137
00138
00139 fNtuple = new TTree(fTreeName, "Analysis Tree");
00140
00141
00142
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
00156 fInfoFiller->InitializeVHSTraining(fVHSPlanes, fVHSStrips);
00157
00158
00159
00160
00161 return;
00162 }
00163
00164
00165
00166
00167 JobCResult CondensedNtpModuleNC::Ana(const MomNavigator *mom)
00168 {
00169
00170
00171 JobCResult result(JobCResult::kPassed);
00172
00173
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 }
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
00193 NtpBDLiteRecord *bdRecord = 0;
00194
00195
00196
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
00205 Detector::Detector_t det = vldc->GetDetector();
00206
00207
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
00218
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
00241
00242 ntpManipulator->SetPrimaryTrackCriteria(0,1,0);
00243
00244
00245
00246
00247
00248 ntpManipulator->SetPrimaryShowerCriteria(0,0);
00249
00250
00251
00252
00253
00254
00255 if(fHeaderInfo->events < 1){
00256
00257
00258 fEventInfo->Reset();
00259 fTrackInfo->Reset();
00260 fShowerInfo->Reset();
00261 fNtuple->Fill();
00262 return result;
00263 }
00264
00265
00266 fInfoFiller->InitializekNN(ntpManipulator);
00267
00268
00269 for(Int_t i = 0; i < fHeaderInfo->events; ++i){
00270
00271 MSG("CondensedNtpModuleNC", Msg::kDebug) << "on event " << i << endl;
00272
00273
00274 ResetTreeVariables();
00275
00276
00277
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 }
00286 }
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
00310 fNtpFile->cd();
00311
00312
00313 fNtpFile->Write();
00314 fNtpFile->Close();
00315
00316 return;
00317 }
00318
00319
00320 const Registry& CondensedNtpModuleNC::DefaultConfig() const
00321 {
00322
00323 int itrue = 1;
00324 int ifalse = 0;
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
00340 itrue = ifalse;
00341
00342 return r;
00343 }
00344
00345
00346 void CondensedNtpModuleNC::Config(const Registry& r)
00347 {
00348 int tmpb;
00349 int tmpi;
00350 double tmpd;
00351 const char* tmps;
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 }