00001
00002
00003
00004
00005
00006
00007
00008
00010
00011 #include "AnalysisNtuples/Module/CondensedNtpModule.h"
00012 #include "AnalysisNtuples/Module/ANtpRecoNtpManipulator.h"
00013 #include "MessageService/MsgService.h"
00014 #include "MinosObjectMap/MomNavigator.h"
00015 #include "JobControl/JobCModuleRegistry.h"
00016 #include "JobControl/JobCommand.h"
00017 #include "Validity/VldTimeStamp.h"
00018 #include "CandNtupleSR/NtpSRRecord.h"
00019 #include "CandNtupleSR/NtpSREvent.h"
00020 #include "CandNtupleSR/NtpSREventSummary.h"
00021 #include "CandNtupleSR/NtpSRSlice.h"
00022 #include "CandNtupleSR/NtpSRTrack.h"
00023 #include "CandNtupleSR/NtpSRShower.h"
00024 #include "CandNtupleSR/NtpSRShieldStrip.h"
00025 #include "CandNtupleSR/NtpSRShieldSummary.h"
00026 #include "CandNtupleSR/NtpSRCosmicRay.h"
00027 #include "CandNtupleSR/NtpSRDmxStatus.h"
00028 #include "MCNtuple/NtpMCRecord.h"
00029 #include "MCNtuple/NtpMCTruth.h"
00030 #include "MCNtuple/NtpMCStdHep.h"
00031 #include "TruthHelperNtuple/NtpTHRecord.h"
00032 #include "TruthHelperNtuple/NtpTHEvent.h"
00033 #include "TruthHelperNtuple/NtpTHTrack.h"
00034 #include "TruthHelperNtuple/NtpTHShower.h"
00035 #include "TruthHelperNtuple/NtpTHStrip.h"
00036 #include "Record/RecCandHeader.h"
00037 #include "Conventions/Detector.h"
00038 #include "Conventions/SimFlag.h"
00039
00040 #include "TFolder.h"
00041 #include "TDirectory.h"
00042 #include "TObjArray.h"
00043
00044 #include <cassert>
00045 #include <algorithm>
00046
00047 ClassImp(CondensedNtpModule)
00048
00049 CVSID("$Id: CondensedNtpModule.cxx,v 1.35 2007/02/12 21:25:37 asousa Exp $");
00050
00051
00052
00053
00054
00055 JOBMODULE(CondensedNtpModule,
00056 "CondensedNtpModule",
00057 "A module used for making analysis tress from SR ntuples");
00058
00059
00060 CondensedNtpModule::CondensedNtpModule() :
00061 fFileName("analysisNtuple.root"),
00062 fTreeName("analysisNtuple"),
00063 fNtpFile(0),
00064 fNtuple(0),
00065 fDetector(1),
00066 fEventInfo(0),
00067 fHeaderInfo(0),
00068 fShowerInfo(0),
00069 fTrackInfo(0),
00070 fTruthInfo(0),
00071 fStripInfoPresent(1),
00072 fDataType(1),
00073 fReconstructed(1)
00074 {
00075
00076 MSG("JobC", Msg::kDebug) << "CondensedNtpModule::Constructor" << endl;
00077
00078 fHeaderInfo = new ANtpHeaderInfo();
00079 fEventInfo = new ANtpEventInfo();
00080 fTrackInfo = new ANtpTrackInfo();
00081 fShowerInfo = new ANtpShowerInfo();
00082 fTruthInfo = new ANtpTruthInfo();
00083
00084
00085 fInfoFiller = new ANtpInfoObjectFiller();
00086
00087 }
00088
00089
00090 CondensedNtpModule::~CondensedNtpModule()
00091 {
00092
00093 MSG("JobC", Msg::kDebug) << "CondensedNtpModule::Destructor" << endl;
00094
00095 if(fHeaderInfo) delete fHeaderInfo;
00096 if(fEventInfo) delete fEventInfo;
00097 if(fShowerInfo) delete fShowerInfo;
00098 if(fTrackInfo) delete fTrackInfo;
00099 if(fTruthInfo) delete fTruthInfo;
00100
00101 }
00102
00103
00104 void CondensedNtpModule::BeginJob()
00105 {
00106 MSG("CondensedNtpModule", Msg::kDebug)
00107 << "In BeginJob\n" << fFileName.c_str()
00108 << " " << fTreeName.c_str() << endl;
00109
00110
00111
00112
00113 switch (fDetector)
00114 {
00115 case 0:
00116 fInfoFiller->SetDetector(Detector::kNear);
00117 break;
00118 case 1:
00119 fInfoFiller->SetDetector(Detector::kFar);
00120 break;
00121 default:
00122 fInfoFiller->SetDetector(Detector::kUnknown);
00123 break;
00124 }
00125
00126
00127 TDirectory* savedir = gDirectory;
00128
00129
00130
00131 fNtpFile = new TFile(fFileName.c_str(),"RECREATE");
00132
00133
00134
00135 fNtuple = new TTree(fTreeName.c_str(), "Analysis Tree");
00136
00137
00138 fNtuple->Branch("header.", "ANtpHeaderInfo", &fHeaderInfo, 64000, 2);
00139 fNtuple->Branch("event.", "ANtpEventInfo", &fEventInfo, 64000, 2);
00140 fNtuple->Branch("shower.", "ANtpShowerInfo", &fShowerInfo, 64000, 2);
00141 fNtuple->Branch("track.", "ANtpTrackInfo", &fTrackInfo, 64000, 2);
00142 if(fDataType>0){
00143 fNtuple->Branch("truth.", "ANtpTruthInfo", &fTruthInfo, 64000, 2);
00144 }
00145
00146
00147 savedir->cd();
00148
00149 return;
00150 }
00151
00152
00153
00154
00155 JobCResult CondensedNtpModule::Ana(const MomNavigator *mom)
00156 {
00157 MSG("CondensedNtpModule", Msg::kDebug) << "start ana" << endl;
00158
00159 JobCResult result(JobCResult::kPassed);
00160
00161
00162 assert(mom);
00163
00164 NtpSRRecord *record = dynamic_cast<NtpSRRecord *>(mom->GetFragment("NtpSRRecord"));
00165 NtpStRecord *stRecord = dynamic_cast<NtpStRecord *>(mom->GetFragment("NtpStRecord"));
00166
00167 if(!record && !stRecord){
00168 MSG("CondensedNtpModuleAtm", Msg::kWarning) << "Could not get NtpSR or NtpSt Record from MOM" << endl;
00169 result.SetWarning().SetFailed();
00170 return result;
00171 }
00172
00173
00174 NtpMCRecord *mcRecord = 0;
00175 mcRecord = dynamic_cast<NtpMCRecord *>(mom->GetFragment("NtpMCRecord"));
00176 if(!mcRecord&&fDataType&&!stRecord){
00177 MSG("CondensedNtpModule", Msg::kWarning) << "Could not get NtpMCRecord from MOM "
00178 << " - hopefully you werent expecting one " << endl;
00179 result.SetWarning().SetFailed();
00180 return result;
00181 }
00182
00183 NtpTHRecord *thRecord = 0;
00184 thRecord = dynamic_cast<NtpTHRecord *>(mom->GetFragment("NtpTHRecord"));
00185
00186
00187 Detector::Detector_t det = Detector::kFar;
00188 if(fDetector<1) det = Detector::kNear;
00189
00190 SimFlag::SimFlag_t dataType = SimFlag::kData;
00191 if(fDataType) dataType = SimFlag::kMC;
00192
00193
00194 ANtpRecoNtpManipulator *ntpManipulator = 0;
00195 if(record) ntpManipulator = new ANtpRecoNtpManipulator(record, mcRecord, thRecord);
00196 else if(stRecord) ntpManipulator = new ANtpRecoNtpManipulator(stRecord);
00197
00198 fInfoFiller->SetStripArray(ntpManipulator->GetStripArray());
00199 fInfoFiller->FillHeaderInformation(ntpManipulator, det, dataType, fHeaderInfo);
00200
00201
00202
00203 ntpManipulator->SetPrimaryTrackCriteria(0,1,0);
00204 ntpManipulator->SetPrimaryShowerCriteria(0,1);
00205
00206
00207
00208
00209 if((mcRecord&&!record&&fDataType)
00210 || (stRecord&&fDataType&&ntpManipulator->GetSnarlEventSummary().nevent<1)){
00211
00212 MSG("CondensedNtpModule", Msg::kDebug) << "why am i here?" << endl;
00213
00214 fReconstructed = 0;
00215
00216
00217
00218
00219 FillUnRecoedMCInformation(ntpManipulator->GetMCArray(), ntpManipulator->GetStdHepArray());
00220 fNtuple->Fill();
00221 ResetTreeVariables();
00222
00223 return result;
00224 }
00225
00226 fReconstructed = 1;
00227
00228
00229
00230
00231
00232 NtpSRTrack *ntpTrack = 0;
00233 NtpSRStrip *ntpStrip = 0;
00234 NtpSREvent *ntpEvent = 0;
00235 NtpSRShower *ntpShower = 0;
00236 NtpMCTruth *ntpMCTruth = 0;
00237 NtpMCStdHep *ntpMCStdHep = 0;
00238 NtpTHEvent *ntpTHEvent = 0;
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252 for(Int_t i = 0; i < ntpManipulator->GetSnarlEventSummary().nevent; ++i){
00253
00254 MSG("CondensedNtpModule", Msg::kDebug) << "on event " << i << endl;
00255
00256 fEventInfo->index = i;
00257
00258
00259
00260
00261 ntpManipulator->GetEventManipulator()->SetEventInSnarl(i);
00262 ntpEvent = ntpManipulator->GetEventManipulator()->GetEvent();
00263 if(ntpEvent) fInfoFiller->FillEventInformation(ntpManipulator,
00264 ntpEvent,
00265 fEventInfo);
00266
00267
00268
00269 ntpTrack = ntpManipulator->GetEventManipulator()->GetPrimaryTrack();
00270 if(ntpTrack) fInfoFiller->FillTrackInformation(ntpTrack, fTrackInfo);
00271
00272
00273
00274 ntpShower = ntpManipulator->GetEventManipulator()->GetPrimaryShower();
00275 if(ntpShower) fInfoFiller->FillShowerInformation(ntpShower, fShowerInfo);
00276
00277
00278
00279 if(fStripInfoPresent) ntpStrip = ntpManipulator->GetEventManipulator()->GetStrip(0);
00280
00281 MSG("CondensedNtpModule", Msg::kDebug) << "CondensedNtpModule::Ana mcRecord="<<mcRecord << endl;
00282 MSG("CondensedNtpModule", Msg::kDebug) << "CondensedNtpModule::Ana thRecord="<<thRecord << endl;
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295 ntpTHEvent = ntpManipulator->GetMCManipulator()->GetNtpTHEvent(i);
00296 if(ntpTHEvent){
00297 ntpMCTruth = ntpManipulator->GetMCManipulator()->GetNtpMCTruth(ntpTHEvent->neumc);
00298 ntpMCStdHep = ntpManipulator->GetMCManipulator()->GetNtpMCStdHep(ntpTHEvent->neustdhep);
00299 }
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327 MSG("CondensedNtpModule", Msg::kDebug) << "CondensedNtpModule::Ana ntpMCTruth="<<ntpMCTruth<< endl;
00328 if(ntpMCTruth){
00329 fInfoFiller->FillMCTruthInformation(ntpMCTruth, fTruthInfo);
00330 }
00331
00332
00333 fNtuple->Fill();
00334 ResetTreeVariables();
00335 }
00336
00337
00338 delete ntpManipulator;
00339
00340 return result;
00341 }
00342
00343
00344 void CondensedNtpModule::Help()
00345 {
00346 MSG("JobC", Msg::kInfo)
00347 << "NearElectronicsCheck::Help\n"
00348 <<"CondensedNtpModule is a module which demultiplexes events "
00349 <<"in the far detector."
00350 << endl;
00351 }
00352
00353
00354 void CondensedNtpModule::EndJob()
00355 {
00356
00357 MSG("CondensedNtpModule", Msg::kInfo) << "start end job method" << endl;
00358
00359
00360 TDirectory *savedir = gDirectory;
00361
00362
00363 fNtpFile->cd();
00364
00365 fNtuple->Write();
00366
00367
00368 savedir->cd();
00369
00370 fNtpFile->Write();
00371 fNtpFile->Close();
00372
00373 return;
00374 }
00375
00376
00377 const Registry& CondensedNtpModule::DefaultConfig() const
00378 {
00379
00380 int itrue = 1;
00381 int ifalse = 0;
00382
00383 static Registry r;
00384
00385 r.UnLockValues();
00386
00387 r.Set("FileName", "analysisTree.root");
00388 r.Set("TreeName", "analysisTree");
00389 r.Set("EndPlane", 485);
00390 r.Set("Detector", 1);
00391 r.Set("StripInfoPresent", 1);
00392 r.Set("DataType", 1);
00393
00394 r.LockValues();
00395
00396
00397 itrue = ifalse;
00398
00399 return r;
00400 }
00401
00402
00403 void CondensedNtpModule::Config(const Registry& r)
00404 {
00405 int tmpb;
00406 int tmpi;
00407 double tmpd;
00408 const char* tmps;
00409
00410 if (r.Get("FileName", tmps)) fFileName = tmps;
00411 if (r.Get("TreeName", tmps)) fTreeName = tmps;
00412 if (r.Get("EndPlane", tmpi)) fEndPlane = tmpi;
00413 if (r.Get("Detector", tmpi)) fDetector = tmpi;
00414 if (r.Get("StripInfoPresent", tmpi)) fStripInfoPresent = tmpi;
00415 if (r.Get("DataType", tmpi)) fDataType = tmpi;
00416
00417
00418 tmpb = 0;
00419 tmpd = 0.;
00420
00421 return;
00422 }
00423
00424
00425 void CondensedNtpModule::FillUnRecoedMCInformation(TClonesArray *mcArray, TClonesArray *stdArray)
00426 {
00427 NtpMCTruth *ntpMCTruth = 0;
00428 NtpMCStdHep *ntpMCStdHep = 0;
00429
00430
00431 Int_t numMCEntries = mcArray->GetLast()+1;
00432 Int_t stdHepLow = 0;
00433 Int_t stdHepHigh = 0;
00434
00435
00436
00437 for(Int_t i = 0; i < numMCEntries; ++i){
00438
00439 fEventInfo->index = i;
00440
00441 ntpMCTruth = dynamic_cast<NtpMCTruth *>(mcArray->At(i));
00442 if(ntpMCTruth) fInfoFiller->FillMCTruthInformation(ntpMCTruth, fTruthInfo);
00443
00444 stdHepLow = ntpMCTruth->stdhep[0];
00445 stdHepHigh = ntpMCTruth->stdhep[1];
00446
00447
00448 for(Int_t j = stdHepLow; j < stdHepHigh+1; ++j){
00449 ntpMCStdHep = dynamic_cast<NtpMCStdHep *>(stdArray->At(j));
00450
00451
00452 }
00453
00454 }
00455
00456
00457 return;
00458 }
00459
00460
00461 void CondensedNtpModule::ResetTreeVariables()
00462 {
00463
00464 fEventInfo->Reset();
00465 fShowerInfo->Reset();
00466 fTrackInfo->Reset();
00467 fTruthInfo->Reset();
00468
00469 return;
00470 }