00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00015
00016
00017 #include "DetectorAlignmentModule.h"
00018 #include "DetectorAlignment.h"
00019 #include "NtpAlignmentRecord.h"
00020
00021
00022 #include "MessageService/MsgService.h"
00023 #include "MinosObjectMap/MomNavigator.h"
00024 #include "CandData/CandRecord.h"
00025 #include "RawData/RawRecord.h"
00026 #include "RawData/RawDaqSnarlHeader.h"
00027 #include "RecoBase/CandStripListHandle.h"
00028 #include "CandTrackSR/CandTrackSRHandle.h"
00029 #include "CandTrackSR/CandTrackSRListHandle.h"
00030 #include "JobControl/JobCModuleRegistry.h"
00031
00032
00033 #include <iostream>
00034 #include <cassert>
00035
00036 JOBMODULE(DetectorAlignmentModule,"DetectorAlignment","Aligns detector using straight tracks");
00037
00038 CVSID("$Id: DetectorAlignmentModule.cxx,v 1.5 2005/07/30 21:25:31 rustem Exp $");
00039
00040 DetectorAlignmentModule::DetectorAlignmentModule()
00041 : fAlign(0),
00042 fNRecords(0),
00043 fNProcessedRecords(0),
00044 fNSkippedRecords(0),
00045 fNAlignmentTracks(0),
00046 fNMultipleTracks(0)
00047 {
00048 MSG("Align", Msg::kInfo) << "Constructor DetectorAlignmentModule()" << endl;
00049 fAlign = new DetectorAlignment();
00050 }
00051
00052 void DetectorAlignmentModule::BeginJob()
00053 {
00054 MSG("Align", Msg::kInfo) << "DetectorAlignmentModule::BeginJob()" << endl;
00055 fTimer.Start();
00056 }
00057
00058 JobCResult DetectorAlignmentModule::Reco(MomNavigator* mom)
00059 {
00060 assert(mom);
00061 fNRecords++;
00062
00063 RawRecord *raw_record=0;
00064 CandRecord *cand_record=0;
00065 int n_raw_record=0, n_cand_record=0;
00066
00067 TIter mit(mom -> FragmentIter());
00068 TObject *fragment_obj;
00069 while( (fragment_obj = mit()) )
00070 {
00071 raw_record = dynamic_cast<RawRecord *> (fragment_obj);
00072 cand_record = dynamic_cast<CandRecord *> (fragment_obj);
00073 if(raw_record) n_raw_record++;
00074 if(cand_record) n_cand_record++;
00075 }
00076
00077 if(n_raw_record != 1 && n_cand_record != 1)
00078 {
00079 MSG("Align", Msg::kWarning) << "Multiple entries for RawRecord or CandRecord!" << endl;
00080 return JobCResult::kAOK;
00081 }
00082
00083 const RawDaqSnarlHeader *rawhdr = dynamic_cast<const RawDaqSnarlHeader *>(raw_record->GetRawHeader());
00084 if(!rawhdr)
00085 {
00086 MSG("Align", Msg::kError) << "Missing required raw data header." << endl;
00087 return JobCResult::kAOK;
00088 }
00089
00090 CandTrackSRListHandle *tklh=0;
00091 CandStripListHandle *cslh=0;
00092 int n_track_lists=0, n_strip_lists=0;
00093
00094 TIter cit(cand_record -> GetCandHandleIter());
00095 TObject *cand_obj;
00096 while( (cand_obj = mit()) )
00097 {
00098 tklh = dynamic_cast<CandTrackSRListHandle *> (cand_obj);
00099 cslh = dynamic_cast<CandStripListHandle *> (cand_obj);
00100 if(tklh) n_track_lists++;
00101 if(cslh) n_strip_lists++;
00102 }
00103
00104 if(n_track_lists != 1 && n_strip_lists != 1)
00105 {
00106 MSG("Align", Msg::kWarning) << "Multiple entries for track or strip lists." << endl;
00107 return JobCResult::kAOK;
00108 }
00109
00110
00111 if(tklh->GetNDaughters() != 1)
00112 {
00113 fNMultipleTracks++;
00114 MSG("Align", Msg::kDebug)<< "There are "<< tklh -> GetNDaughters() << " tracks." << endl;
00115 return JobCResult::kAOK;
00116 }
00117
00118 TIter itr(tklh -> GetDaughterIterator());
00119 while( CandTrackSRHandle* trkh = dynamic_cast<CandTrackSRHandle *>(itr()) )
00120 {
00121 MSG("Align", Msg::kDebug) << "Found alignment track"<< endl;
00122
00123 fNAlignmentTracks++;
00124 RecCandHeader ntphdr(rawhdr -> GetVldContext(),
00125 rawhdr -> GetRun(),
00126 rawhdr -> GetSubRun(),
00127 rawhdr -> GetRunType(),
00128 rawhdr -> GetErrorCode(),
00129 rawhdr -> GetSnarl(),
00130 rawhdr -> GetTrigSrc(),
00131 rawhdr -> GetTimeFrameNum(),
00132 rawhdr -> GetRemoteSpillType(),
00133 fNAlignmentTracks);
00134
00135 NtpAlignmentRecord* ntpalignrec = new NtpAlignmentRecord(ntphdr);
00136
00137
00138 const bool result = fAlign -> RunAlignment(trkh, cslh, ntpalignrec);
00139
00140 if(result)
00141 mom -> AdoptFragment(ntpalignrec);
00142 else
00143 {
00144 delete ntpalignrec;
00145 MSG("Align",Msg::kDebug) << "Snarl "<<fNRecords<<" false result!"<<endl;
00146 fNSkippedRecords++;
00147 }
00148 }
00149
00150 if(fNRecords % 1000 == 0)
00151 MSG("Align", Msg::kInfo) << "DetectorAlignmentModule snarl #" << fNRecords << endl;
00152 else
00153 MSG("Align",Msg::kDebug) << "DetectorAlignmentModule snarl #" << fNRecords << endl;
00154
00155 fNProcessedRecords++;
00156 return JobCResult::kAOK;
00157 }
00158
00159 void DetectorAlignmentModule::EndJob()
00160 {
00161
00162 MSG("Align", Msg::kInfo) << "DetectorAlignmentModule: EndJob()" << endl
00163 << "Number of processed snarls: " << fNRecords << endl
00164 << "Number of alignment tracks: " << fNAlignmentTracks << endl
00165 << "Number of proccesed records: " << fNProcessedRecords << endl
00166 << "Number of skipped records: " << fNSkippedRecords << endl
00167 << "Number of multiple tracks records: " << fNMultipleTracks << endl
00168 << "Cpu time: " << fTimer.CpuTime() << endl
00169 << "Real time: " << fTimer.RealTime() << endl;
00170
00171 if(fAlign){
00172 delete fAlign;
00173 fAlign = 0;
00174 }
00175 }
00176
00177
00178 DetectorAlignmentModule::~DetectorAlignmentModule()
00179 {
00180 MSG("Align", Msg::kInfo) << "Destructor ~DetectorAlignmentModule()" << endl;
00181 if(fAlign)
00182 {
00183 delete fAlign;
00184 fAlign = 0;
00185 }
00186 }