00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00017
00018 #include <cassert>
00019
00020 #include "TROOT.h"
00021
00022 #include "CandStripSR/StripSRListModule.h"
00023
00024 #include "Algorithm/AlgConfig.h"
00025 #include "Algorithm/AlgFactory.h"
00026 #include "Algorithm/AlgHandle.h"
00027 #include "CandData/CandHeader.h"
00028 #include "CandData/CandRecord.h"
00029 #include "CandDigit/CandDigitListHandle.h"
00030 #include "CandDigit/CandDeMuxDigitListHandle.h"
00031 #include "Candidate/CandContext.h"
00032 #include "Conventions/Munits.h"
00033 #include "Conventions/StripEnd.h"
00034 #include "Conventions/Detector.h"
00035 #include "JobControl/JobCModuleRegistry.h"
00036 #include "JobControl/JobCommand.h"
00037 #include "MessageService/MsgService.h"
00038 #include "MinosObjectMap/MomNavigator.h"
00039 #include "RawData/RawDigit.h"
00040 #include "RawData/RawHeader.h"
00041 #include "RawData/RawRecord.h"
00042 #include "RawData/RawDigitDataBlock.h"
00043 #include "RawData/RawChannelId.h"
00044 #include "RawData/RawDaqSnarlHeader.h"
00045 #include "RawData/RawDaqHeaderBlock.h"
00046 #include "RawData/RawDigitDataBlock.h"
00047 #include "RawData/RawVarcErrorInTfBlock.h"
00048
00049 #include "RecoBase/CandStripListHandle.h"
00050 #include "RecoBase/CandStripHandle.h"
00051 #include "RecoBase/CandStrip.h"
00052 #include "RecoBase/CandStripList.h"
00053
00054 #include "Validity/VldContext.h"
00055
00056 ClassImp(StripSRListModule)
00057
00058
00059 CVSID("$Id: StripSRListModule.cxx,v 1.29 2010/01/06 18:52:19 rhatcher Exp $");
00060 JOBMODULE(StripSRListModule, "StripSRListModule",
00061 "Builds CandStripList from CandDigitList");
00062
00063
00064 StripSRListModule::StripSRListModule():
00065 fTFolder(0)
00066 {
00067
00068
00069
00070
00071
00072
00073
00074 if (fTFolder==0) {
00075 TFolder *lf = dynamic_cast<TFolder *>(gROOT->FindObject("Loon"));
00076 if (lf==0) {
00077 MSG("StripSR", Msg::kDebug) << "Creating Loon TFolder" << endl;
00078 lf = gROOT->GetRootFolder()->AddFolder("Loon", "Loon analysis");
00079 gROOT->GetListOfBrowsables()->Add(lf, "Loon");
00080 }
00081 fTFolder = lf->AddFolder("CandStripSR", "CandStripSR statistics");
00082 fTFolder->Add(&fStats);
00083 }
00084
00085
00086
00087
00088
00089 }
00090
00091
00092 StripSRListModule::~StripSRListModule()
00093 {
00094 }
00095
00096
00097 void StripSRListModule::BeginJob()
00098 {
00099 }
00100
00101 void StripSRListModule::EndJob()
00102 {
00103
00104 fStats.Print();
00105
00106 }
00107
00108
00109 const Registry &StripSRListModule::DefaultConfig() const
00110 {
00111
00112
00113
00114
00115
00116
00117
00118
00119 static Registry def_cfg;
00120 static bool been_here = false;
00121 if(been_here)return def_cfg;
00122 been_here=true;
00123
00124 string name = this->JobCModule::GetName();
00125 name += ".config.default";
00126 def_cfg.SetName(name.c_str());
00127
00128
00129 def_cfg.Set("StripListAlgorithm","AlgStripSRList");
00130 def_cfg.Set("StripListAlgConfig","default");
00131 def_cfg.Set("ListIn","canddigitlist");
00132 def_cfg.Set("ListOut","CandStripList");
00133 def_cfg.Set("LogLevel","Fatal");
00134 def_cfg.Set("UseDeMuxQualityWord", 0);
00135 return def_cfg;
00136 }
00137
00138
00139 JobCResult StripSRListModule::Reco(MomNavigator *mom)
00140 {
00141 JobCResult result(JobCResult::kPassed);
00142
00143
00144 const char* tmps = 0;
00145 Int_t tmpi=0;
00146 const char* alg_name = 0;
00147 const char* alg_config_name = 0;
00148 const char* list_in = 0;
00149 const char* list_out = 0;
00150 Int_t useDeMuxQualityWord=0;
00151
00152 Registry& cfg = this->GetConfig();
00153 if (cfg.Get("StripListAlgorithm",tmps)) alg_name = tmps;
00154 if (cfg.Get("StripListAlgConfig",tmps)) alg_config_name = tmps;
00155 if (cfg.Get("ListIn",tmps)) list_in = tmps;
00156 if (cfg.Get("ListOut",tmps)) list_out = tmps;
00157 if (cfg.Get("UseDeMuxQualityWord",tmpi)) useDeMuxQualityWord = tmpi;
00158
00159
00160
00161 RawRecord *rr = dynamic_cast<RawRecord *>(mom->GetFragment("RawRecord",0,"DaqSnarl"));
00162 if (rr == 0) {
00163 MSG("EventSR", Msg::kWarning) << "No RawRecord in MOM." << endl;
00164 return result;
00165 }
00166
00167
00168 CandRecord *candrec = dynamic_cast<CandRecord *>
00169 (mom->GetFragment("CandRecord", "PrimaryCandidateRecord"));
00170 if (candrec == 0) {
00171 MSG("StripSR", Msg::kWarning) << "No PrimaryCandidateRecord in MOM."
00172 << endl;
00173 result.SetWarning().SetFailed();
00174 return result;
00175 }
00176
00177 CandDigitListHandle *cdlh = dynamic_cast<CandDigitListHandle *>
00178 (candrec->FindCandHandle("CandDigitListHandle", list_in));
00179
00180
00181 if (!cdlh || cdlh->GetNDaughters() < 1) {
00182 MSG("StripSR", Msg::kDebug)
00183 << "Null CandDigit list. Bail out of event." << endl;
00184 result.SetFailed();
00185 return result;
00186 }
00187
00188
00189
00190 if(useDeMuxQualityWord == 1
00191 && cdlh->GetVldContext()->GetDetector() == Detector::kFar){
00192 const CandDeMuxDigitListHandle *ddlh = 0;
00193 if(cdlh->InheritsFrom("CandDeMuxDigitListHandle")){
00194 ddlh = dynamic_cast<const CandDeMuxDigitListHandle *>(cdlh);
00195 if(ddlh->GetDeMuxDigitListFlagWord() == CandDeMuxDigitList::kEventFailedFilter ){
00196 MSG("StripSR", Msg::kDebug) << "failed DeMuxDigitList filter" << endl;
00197 result.SetFailed();
00198 return result;
00199 }
00200 }
00201 }
00202
00203 AlgFactory &af = AlgFactory::GetInstance();
00204 AlgHandle adlh = af.GetAlgHandle(alg_name,alg_config_name);
00205 CandContext cx(this, mom);
00206 cx.SetDataIn(cdlh);
00207 CandStripListHandle cslh = CandStripList::MakeCandidate(adlh, cx);
00208
00209 cslh.SetName(list_out);
00210 cslh.SetTitle(TString("Created by StripSRListModule from ").
00211 Append(cdlh->GetName()));
00212 candrec->SecureCandHandle(cslh);
00213
00214
00215 return result;
00216 }
00217
00218 ClassImp(StripStat)
00219
00220
00221
00223 StripStat::StripStat():
00224 fDoNoiseNear(true), fDoNoiseStats(false), fNearNoiseADC(40)
00225 {
00226
00227 }
00228 StripStat::~StripStat()
00229 {
00230
00231 }
00232 void StripStat::Add(const RawChannelId& rcid, Bool_t noise)
00233 {
00234
00235 if (fNearStripStats.find(rcid) == fNearStripStats.end() )
00236 {
00237
00238 fNearStripStats[rcid].all=0;
00239 fNearStripStats[rcid].noise=0;
00240 }
00241
00242 fNearStripStats[rcid].all++;
00243 if (noise) fNearStripStats[rcid].noise++;
00244 }
00245
00246 void StripStat::Print()
00247 {
00248
00249 MSG("StripSR",Msg::kInfo) <<"\n NearDet Strip Noise Filtering="<<
00250 fDoNoiseNear<< "\n"<<endl;
00251 if (!fDoNoiseStats) {
00252 MSG("StripSR", Msg::kInfo) << "DoNoiseStats=false. No"<<
00253 " NearDet noise statistics in StripSRListModule.\n"
00254 <<" NearNoiseADC="<<fNearNoiseADC <<endl;
00255 return;
00256 }
00257
00258 MSG("StripSR", Msg::kInfo) <<
00259 "----------------------------------------------------------------\n"
00260 << " Strips Cut by StripSRListModule::CleanNoiseNear\n"
00261 << " single digits with ADC<"<<fNearNoiseADC<< " \n"
00262 <<" Stripends with more than 10%% cut out of at least 10 strips:\n" <<
00263 "----------------------------------------------------------------\n"
00264 <<endl;
00265 MSG("StripSR", Msg::kInfo) << setw(10)<< "Crate" <<
00266 setw(10) <<"Master"<<
00267 setw(10) <<"MasterCh"<<
00268 setw(10) <<"Menu"<<
00269 setw(10) <<"Total"<<
00270 setw(10) <<"Cut"<<
00271 setw(10) <<"Fraction"<<endl;
00272
00273 for (map<RawChannelId,fStripStats>::iterator itmap=
00274 fNearStripStats.begin();
00275 itmap != fNearStripStats.end();
00276 itmap++)
00277 {
00278
00279 RawChannelId rcid=itmap->first;
00280 fStripStats stats=itmap->second;
00281 if ( 9 < stats.noise) {
00282 Float_t fraction=(Float_t)
00283 stats.noise/stats.all;
00284 if (fraction > 0.1)
00285 MSG("StripSR", Msg::kInfo)
00286 << setw(10)<< (rcid.GetCrate())<<
00287 setw(10) << (rcid.GetMaster())<<
00288 setw(10) << (rcid.GetMinder())<<
00289 setw(10) << (rcid.GetMenu())<<
00290 setw(10) << stats.all<<
00291 setw(10) <<stats.noise<<
00292 setw(10) << fraction
00293 <<endl;
00294 }
00295
00296 }
00297
00298 MSG("StripSR", Msg::kInfo) <<
00299 "----------------------------------------------------------------\n"
00300 <<
00301 "----------------------------------------------------------------\n"
00302 <<endl;
00303
00304
00305 }