00001
00002
00003
00004
00005
00006
00007
00008
00010
00011 #include "AnalysisNtuples/Module/CondensedNtpModuleNC.h"
00012
00013 #include "AnalysisNtuples/ANtpNueInfo.h"
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/ANtpDefaultValue.h"
00021 #include "AnalysisNtuples/ANtpEventInfoMRCC.h"
00022
00023 #include "AnalysisNtuples/Module/ANtpInfoObjectFillerNC.h"
00024 #include "AnalysisNtuples/Module/ANtpInfoObjectFillerMRCC.h"
00025 #include "AnalysisNtuples/Module/ANtpInfoObjectFillerNue.h"
00026 #include "AnalysisNtuples/Module/ANtpRecoNtpManipulator.h"
00027
00028 #include "Conventions/Detector.h"
00029 #include "Conventions/SimFlag.h"
00030 #include "MessageService/MsgService.h"
00031 #include "MinosObjectMap/MomNavigator.h"
00032 #include "JobControl/JobCModuleRegistry.h"
00033
00034 #include "TFile.h"
00035 #include "TTree.h"
00036
00037 #include <cassert>
00038
00039 class NtpSRRecord;
00040 class NtpMCRecord;
00041 class NtpMRRecord;
00042 class NtpStRecord;
00043 class NtpTHRecord;
00044
00045
00046 CVSID("$Id: CondensedNtpModuleNC.cxx,v 1.29 2009/11/24 16:50:39 rodriges Exp $");
00047
00048
00049
00050
00051
00052 JOBMODULE(CondensedNtpModuleNC,
00053 "CondensedNtpModuleNC",
00054 "A module used for making analysis tress from SR ntuples");
00055
00056
00057 CondensedNtpModuleNC::CondensedNtpModuleNC() :
00058 fFileName("analysisNtuple.root"),
00059 fTreeName("analysisNtuple"),
00060 fNtpFile(0),
00061 fNtuple(0),
00062 fVHSPlanes(20),
00063 fVHSStrips(20)
00064 {
00065 MSG("JobC", Msg::kDebug) << "CondensedNtpModuleNC::Constructor" << endl;
00066
00067 fHeaderInfo = new ANtpHeaderInfo;
00068 fEventInfo = new ANtpEventInfoNC;
00069 fNueInfo = new ANtpNueInfo;
00070 fTrackInfo = new ANtpTrackInfoNC;
00071 fShowerInfo = new ANtpShowerInfoNC;
00072 fTruthInfo = new ANtpTruthInfoBeam;
00073 fBeamInfo = new ANtpBeamInfo;
00074 fEventInfoMRCC = new ANtpEventInfoMRCC;
00075
00076 fInfoFiller = new ANtpInfoObjectFillerNC;
00077 fInfoFillerNue = new ANtpInfoObjectFillerNue;
00078 fInfoFillerMRCC = new ANtpInfoObjectFillerMRCC;
00079
00080 fFailedDeMux = 0;
00081 }
00082
00083
00084 CondensedNtpModuleNC::~CondensedNtpModuleNC()
00085 {
00086
00087 MSG("JobC", Msg::kDebug) << "CondensedNtpModuleNC::Destructor" << endl;
00088
00089 if(fHeaderInfo) delete fHeaderInfo;
00090 if(fEventInfo) delete fEventInfo;
00091 if(fEventInfoMRCC) delete fEventInfoMRCC;
00092 if(fShowerInfo) delete fShowerInfo;
00093 if(fTrackInfo) delete fTrackInfo;
00094 if(fTruthInfo) delete fTruthInfo;
00095 if(fBeamInfo) delete fBeamInfo;
00096 if(fNueInfo) delete fNueInfo;
00097 }
00098
00099
00100 void CondensedNtpModuleNC::BeginJob()
00101 {
00102 MSG("CondensedNtpModuleNC", Msg::kDebug)
00103 << "in BeginJob" << endl;
00104
00105
00106
00107
00108
00109
00110 fNtpFile = new TFile(fFileName,"RECREATE");
00111
00112
00113
00114
00115
00116 fNtuple = new TTree(fTreeName, "Analysis Tree");
00117
00118
00119
00120 fNtuple->Branch("header.", "ANtpHeaderInfo", &fHeaderInfo, 64000, 2);
00121 fNtuple->Branch("event.", "ANtpEventInfoNC", &fEventInfo, 64000, 2);
00122 fNtuple->Branch("shower.", "ANtpShowerInfoNC", &fShowerInfo, 64000, 2);
00123 fNtuple->Branch("track.", "ANtpTrackInfoNC", &fTrackInfo, 64000, 2);
00124 fNtuple->Branch("beam.", "ANtpBeamInfo", &fBeamInfo, 64000, 2);
00125 if(fMakeNueBranch)fNtuple->Branch("nue.", "ANtpNueInfo", &fNueInfo, 64000, 2);
00126 if(fDataType==1)
00127 fNtuple->Branch("truth.", "ANtpTruthInfoBeam", &fTruthInfo, 64000, 2);
00128
00129 MSG("CondensedNtpModuleNC", Msg::kDebug) << "got branches" << endl;
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139 return;
00140 }
00141
00142
00143
00144
00145 JobCResult CondensedNtpModuleNC::Ana(const MomNavigator *mom)
00146 {
00147 JobCResult result(JobCResult::kPassed);
00148
00149
00150 assert(mom);
00151
00152 NtpSRRecord* record = (NtpSRRecord*)(mom->GetFragment("NtpSRRecord"));
00153 NtpMRRecord* mrRecord = (NtpMRRecord*)(mom->GetFragment("NtpMRRecord"));
00154
00155 NtpStRecord* stRecord=0;
00156 NtpStRecord* stRecordOrig=0;
00157
00158
00159
00160 if(mrRecord){
00161
00162
00163
00164
00165
00166
00167 stRecordOrig = (NtpStRecord*)(mom->GetFragment("NtpStRecord",
00168 "Primary"));
00169 stRecord = (NtpStRecord*)(mom->GetFragment("NtpStRecord",
00170 "MuonRemoved"));
00171
00172 if(!stRecordOrig){
00173
00174
00175
00176
00177
00178
00179 MAXMSG("CondensedNtpModuleNC", Msg::kWarning, 10)
00180 << "No NtpStRecord found. Probably the sntp file is shorter than the mrnt."
00181 << "Ignoring this snarl" << endl;
00182 return JobCResult::kFailed;
00183 }
00184 static bool once = true;
00185 if(once){
00186 fNtuple->Branch("mrcc.", "ANtpEventInfoMRCC", &fEventInfoMRCC, 64000, 2);
00187 once = false;
00188 }
00189 }
00190 else{
00191
00192 stRecord = (NtpStRecord*)(mom->GetFragment("NtpStRecord",
00193 "Primary"));
00194 }
00195
00196 if(!record && !stRecord){
00197 MSG("CondensedNtpModuleNC", Msg::kWarning) << "Could not get NtpSR or NtpSt "
00198 << "Record from MOM" << endl;
00199 result.SetWarning().SetFailed();
00200 return result;
00201 }
00202
00203 NtpMCRecord* mcRecord = (NtpMCRecord*)(mom->GetFragment("NtpMCRecord"));
00204 NtpTHRecord* thRecord = (NtpTHRecord*)(mom->GetFragment("NtpTHRecord"));
00205
00206
00207 ANtpRecoNtpManipulator *ntpManipulator = 0;
00208 if(record) ntpManipulator = new ANtpRecoNtpManipulator(record, mcRecord, thRecord);
00209 else if(stRecord) ntpManipulator = new ANtpRecoNtpManipulator(stRecord);
00210
00211 const VldContext *vldc = stRecord ? stRecord->GetVldContext() : record->GetVldContext();
00212 VldTimeStamp timeStamp = vldc->GetTimeStamp();
00213
00214
00215 Detector::Detector_t det = vldc->GetDetector();
00216
00217
00218 SimFlag::SimFlag_t dataType = vldc->GetSimFlag();
00219
00220 fInfoFiller->SetDetector(det);
00221 fInfoFiller->SetStripArray(ntpManipulator->GetStripArray());
00222 fInfoFiller->SetClusterArray(ntpManipulator->GetClusterArray());
00223 fInfoFiller->FillHeaderInformation(ntpManipulator, det, dataType, fHeaderInfo);
00224
00225 if(fHeaderInfo->snarl%500==0)
00226 MSG("CondensedNtpModuleNC", Msg::kInfo) << "snarl " << fHeaderInfo->snarl << endl;
00227
00228
00229
00230
00231 if(fHeaderInfo->year > 2004){
00232 fInfoFiller->FillBeamInformation(timeStamp, det, dataType, fBeamInfo);
00233 MAXMSG("CondensedNtpModuleNC",Msg::kDebug,1)
00234 << "Calling db method to fill beam info." << endl;
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 fEventInfoMRCC->Reset();
00262 fNtuple->Fill();
00263 return result;
00264 }
00265
00266
00267 fInfoFiller->InitializekNN(ntpManipulator);
00268
00269
00270 for(Int_t i = 0; i < fHeaderInfo->events; ++i){
00271
00272 MSG("CondensedNtpModuleNC", Msg::kDebug) << "on event " << i << endl;
00273
00274
00275 ResetTreeVariables();
00276
00277
00278
00279 if(i > 0) fHeaderInfo->newSnarl = 0;
00280
00281 if(fMakeNueBranch)fInfoFillerNue->Analyze(i, ntpManipulator->GetNtpStRecord(), fNueInfo);
00282
00283
00284
00285
00286
00287
00288
00289
00290 if( fInfoFiller->FillInformation(i, ntpManipulator, fEventInfo, fTrackInfo,
00291 fShowerInfo, fTruthInfo) ){
00292
00293
00294 assert(fEventInfo->index == i);
00295
00296
00297
00298 if(mrRecord){
00299 fInfoFillerMRCC->FillEventInformation(i, mrRecord, stRecordOrig,
00300 fEventInfoMRCC,
00301 fDataType==1 ? fTruthInfo : 0);
00302
00303 assert(fEventInfoMRCC->bestEvent == fEventInfo->index ||
00304 fEventInfoMRCC->bestEvent == ANtpDefaultValue::kInt);
00305 }
00306
00307 fNtuple->Fill();
00308
00309 }
00310 }
00311
00312
00313 return result;
00314 }
00315
00316
00317 void CondensedNtpModuleNC::Help()
00318 {
00319 MSG("JobC", Msg::kDebug)
00320 << "CondensedNtpModuleNC::Help\n"
00321 <<"CondensedNtpModuleNC is a module which demultiplexes events "
00322 <<"in the far detector."
00323 << endl;
00324 }
00325
00326
00327 void CondensedNtpModuleNC::EndJob()
00328 {
00329
00330 MSG("CondensedNtpModuleNC", Msg::kInfo) << "start end job method " << fFailedDeMux
00331 << " failed demuxing" << endl;
00332
00333
00334 fNtpFile->cd();
00335
00336
00337 fNtpFile->Write();
00338 fNtpFile->Close();
00339
00340 return;
00341 }
00342
00343
00344 const Registry& CondensedNtpModuleNC::DefaultConfig() const
00345 {
00346
00347 int itrue = 1;
00348 int ifalse = 0;
00349
00350 static Registry r;
00351
00352 r.UnLockValues();
00353
00354 r.Set("FileName", "analysisTree.root");
00355 r.Set("TreeName", "analysisTree");
00356 r.Set("DataType", 1);
00357
00358 r.Set("VHSPlanes",20);
00359 r.Set("VHSStrips",20);
00360
00361 r.Set("MakeNueBranch", false);
00362
00363 r.LockValues();
00364
00365
00366 itrue = ifalse;
00367
00368 return r;
00369 }
00370
00371
00372 void CondensedNtpModuleNC::Config(const Registry& r)
00373 {
00374 int tmpb;
00375 int tmpi;
00376 const char* tmps;
00377
00378 if (r.Get("FileName", tmps)) fFileName = tmps;
00379 if (r.Get("TreeName", tmps)) fTreeName = tmps;
00380 if (r.Get("DataType", tmpi)) fDataType = tmpi;
00381
00382 if (r.Get("VHSPlanes", tmpi)) fVHSPlanes = tmpi;
00383 if (r.Get("VHSStrips", tmpi)) fVHSStrips = tmpi;
00384
00385 if (r.Get("MakeNueBranch", tmpb)) fMakeNueBranch = tmpb;
00386
00387 }
00388
00389
00390 void CondensedNtpModuleNC::ResetTreeVariables()
00391 {
00392
00393 fEventInfo->Reset();
00394 fTrackInfo->Reset();
00395 fShowerInfo->Reset();
00396 fTruthInfo->Reset();
00397 if(fMakeNueBranch)fNueInfo->Reset();
00398 fEventInfoMRCC->Reset();
00399
00400 return;
00401 }