00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00012
00013
00014 #include "DeMux/DmxHypothesis.h"
00015 #include "MessageService/MsgService.h"
00016 #include "MessageService/MsgFormat.h"
00017 #include "DeMux/DmxChiSqrStat.h"
00018 #include "DeMux/DmxRMSStat.h"
00019 #include "DeMux/DmxStatTypes.h"
00020 #include "Navigation/NavSet.h"
00021 #include "UgliGeometry/UgliStripHandle.h"
00022 #include "UgliGeometry/UgliScintPlnHandle.h"
00023 #include "UgliGeometry/UgliGeomHandle.h"
00024 #include "Algorithm/AlgConfig.h"
00025 #include "CandDigit/CandDeMuxDigit.h"
00026 #include "CandDigit/CandDeMuxDigitHandle.h"
00027
00028 #include "TMath.h"
00029
00030 ClassImp(DmxHypothesis)
00031 XXXITRIMP(DmxHypothesis)
00032
00033
00034 CVSID("$Id: DmxHypothesis.cxx,v 1.62 2007/02/04 05:55:06 rhatcher Exp $");
00035
00036
00037 DmxHypothesis::DmxHypothesis() :
00038 fStat(0)
00039 {
00040 }
00041
00042
00043 DmxHypothesis::DmxHypothesis(AlgConfig &acd, CandDeMuxDigitHandleItr &cdhitr,
00044 Int_t lowerStrip, Int_t upperStrip) :
00045 fAllUsed(true),
00046 fCdhit(cdhitr),
00047 fCompare(0),
00048 fCoG(0.),
00049 fLowerBound(lowerStrip),
00050 fMaxSeparation(23),
00051 fMatedSignalRatio(0.0),
00052 fRequiredMatedSignalRatio(acd.GetDouble("RatioMatedSignalForValid")),
00053 fStat(0),
00054 fStripsUsed(0),
00055
00056 fUpperBound(upperStrip)
00057 {
00058
00059 fCdhit.Reset();
00060
00061
00062
00063
00064 Float_t numerator = 0.;
00065 Float_t denominator = 0.;
00066
00067
00068 Float_t signalE[192];
00069 Float_t signalW[192];
00070
00071
00072
00073
00074
00075
00076
00077
00078 for(Int_t i = 0; i<192; i++){
00079 }
00080
00081 for(Int_t vv = 0; vv < 192; vv++){
00082 signalE[vv] = 0.;
00083 signalW[vv] = 0.;
00084
00085
00086
00087
00088 }
00089
00090 while( fCdhit.IsValid() ){
00091
00092
00093 CandDeMuxDigitHandle *currentDigit = fCdhit.Ptr();
00094
00095
00096 currentDigit->GetPlexSEIdAltL().SetFirst();
00097
00098
00099
00100
00101 bool digitUsed = false;
00102
00103 while( currentDigit->GetPlexSEIdAltL().IsValid() ){
00104 Int_t strip = currentDigit->GetPlexSEIdAltL().GetCurrentSEId().GetStrip();
00105 if(strip >= fLowerBound && strip <= fUpperBound){
00106
00107
00108
00109 if(currentDigit->GetDeMuxDigitFlagWord() == 0){
00110
00111 digitUsed = true;
00112
00113 if( currentDigit->GetPlexSEIdAltL().GetEnd() == StripEnd::kEast ){
00114 signalE[strip] = currentDigit->GetCharge();
00115
00116 }
00117 else if( currentDigit->GetPlexSEIdAltL().GetEnd() == StripEnd::kWest ){
00118 signalW[strip] = currentDigit->GetCharge();
00119
00120 }
00121
00122 numerator += currentDigit->GetCharge() * strip;
00123 denominator += currentDigit->GetCharge();
00124
00125 }
00126
00127
00128 break;
00129 }
00130
00131
00132 currentDigit->GetPlexSEIdAltL().Next();
00133
00134 }
00135
00136 if( !digitUsed && currentDigit->GetDeMuxDigitFlagWord() == 0){ fAllUsed = false; }
00137
00138 fCdhit.Next();
00139 }
00140
00141 fCdhit.ResetFirst();
00142
00143
00144
00145 Float_t matches = 0.0;
00146
00147 for(Int_t j = 0; j < 192; j++){
00148 if( signalW[j] > 0. && signalE[j] > 0.)
00149 matches += signalW[j] + signalE[j];
00150 if(signalW[j]>0. || signalE[j]>0.) ++fStripsUsed;
00151 }
00152
00153 if(denominator > 0.){
00154 fCoG = numerator / denominator;
00155 fMatedSignalRatio = matches / denominator;
00156 }
00157
00158
00159
00160
00161 fStat = new DmxChiSqrStat(signalW, signalE, fCoG);
00162
00163
00164
00165
00166
00167 return;
00168 }
00169
00170
00171 DmxHypothesis::~DmxHypothesis()
00172 {
00173
00174
00175 delete fStat;
00176 }
00177
00178
00179 Int_t DmxHypothesis::GetNumberOfStripsUsed() const
00180 {
00181 return fStripsUsed;
00182 }
00183
00184
00185 Float_t DmxHypothesis::GetCoG() const
00186 {
00187 return fCoG;
00188 }
00189
00190
00191 Int_t DmxHypothesis::GetCompareFlag() const
00192 {
00193 return fCompare;
00194 }
00195
00196
00197 Int_t DmxHypothesis::GetLowerBound() const
00198 {
00199 return fLowerBound;
00200 }
00201
00202
00203 Float_t DmxHypothesis::GetMatedSignalRatio() const
00204 {
00205 return fMatedSignalRatio;
00206 }
00207
00208
00209 Float_t DmxHypothesis::GetStat() const
00210 {
00211 return fStat->GetGoodness();
00212 }
00213
00214
00215 DmxStatistic *DmxHypothesis::GetStatObject() const
00216 {
00217 return fStat;
00218 }
00219
00220
00221 Float_t DmxHypothesis::GetTieBreakerStat() const
00222 {
00223 return fStat->GetTieBreaker();
00224 }
00225
00226
00227 Int_t DmxHypothesis::GetUpperBound() const
00228 {
00229 return fUpperBound;
00230 }
00231
00232
00233 Bool_t DmxHypothesis::IsValid() const
00234 {
00235
00236
00237
00238
00239 return fMatedSignalRatio>fRequiredMatedSignalRatio && fAllUsed;
00240 }
00241
00242
00243 void DmxHypothesis::PrintRecon()
00244 {
00245 MSG("DMX", Msg::kInfo) << "\tLower Bound = " << fLowerBound
00246 << "\tGoodness of Fit = " << fStat->GetGoodness()
00247 << "\tTieBreaker = " << fStat->GetTieBreaker() << endl;
00248 while( fCdhit.IsValid() ){
00249 while( fCdhit.Ptr()->GetPlexSEIdAltL().IsValid() ){
00250 if( fCdhit.Ptr()->GetPlexSEIdAltL().GetCurrentSEId().GetStrip() >= fLowerBound &&
00251 fCdhit.Ptr()->GetPlexSEIdAltL().GetCurrentSEId().GetStrip() <= fUpperBound){
00252
00253 if( fCdhit.Ptr()->GetPlexSEIdAltL().GetEnd() == StripEnd::kWest ){
00254 MSG("DMX", Msg::kInfo)<< "\t\tWest\t"
00255 << fCdhit.Ptr()->GetPlexSEIdAltL().GetCurrentSEId().GetStrip()
00256 << "\t" << fCdhit.Ptr()->GetCharge() << endl;
00257 }
00258 if( fCdhit.Ptr()->GetPlexSEIdAltL().GetEnd() == StripEnd::kEast ){
00259 MSG("DMX", Msg::kInfo)<< "\t\tEast\t"
00260 << fCdhit.Ptr()->GetPlexSEIdAltL().GetCurrentSEId().GetStrip()
00261 << "\t" << fCdhit.Ptr()->GetCharge() << endl;
00262 }
00263 }
00264 }
00265 fCdhit.Next();
00266 }
00267
00268 return;
00269 }
00270
00271
00272 void DmxHypothesis::SetStrips()
00273 {
00274 fCdhit.Reset();
00275 while( fCdhit.IsValid() ){
00276
00277
00278 CandDeMuxDigitHandle *currentDigit = fCdhit.Ptr();
00279
00280
00281 currentDigit->GetPlexSEIdAltLWritable().ClearWeights();
00282
00283
00284 currentDigit->GetPlexSEIdAltL().SetFirst();
00285
00286
00287
00288 currentDigit->GetPlexSEIdAltLWritable().SetDemuxVetoFlag(1);
00289
00290
00291
00292
00293 while( currentDigit->GetPlexSEIdAltL().IsValid() ){
00294 if( currentDigit->GetPlexSEIdAltL().GetCurrentSEId().GetStrip() >= fLowerBound &&
00295 currentDigit->GetPlexSEIdAltL().GetCurrentSEId().GetStrip() <= fUpperBound){
00296
00297
00298 currentDigit->GetPlexSEIdAltLWritable().SetCurrentWeight(1.0);
00299 currentDigit->GetPlexSEIdAltLWritable().SetDemuxVetoFlag(0);
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310 break;
00311 }
00312
00313 currentDigit->GetPlexSEIdAltL().Next();
00314 }
00315
00316 fCdhit.Next();
00317 }
00318 fCdhit.Reset();
00319 }
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329 Float_t DmxHypothesis::GetTimingOffset(UgliGeomHandle *ugh)
00330 {
00331
00332
00333 Float_t westFiber[192];
00334 Float_t eastFiber[192];
00335 Float_t eastTime[192];
00336 Float_t westTime[192];
00337
00338
00339 for(Int_t i = 0; i<192; i++){
00340 westFiber[i] = -1.;
00341 eastFiber[i] = -1.;
00342 eastTime[i] = -1.;
00343 westTime[i] = -1.;
00344 }
00345
00346
00347
00348 fCdhit.ResetFirst();
00349
00350
00351 while(fCdhit.IsValid()){
00352
00353 CandDeMuxDigitHandle *digit = fCdhit.Ptr();
00354
00355 if(digit->GetPlexSEIdAltL().GetDemuxVetoFlag() == 0 && digit->GetDeMuxDigitFlagWord() == 0){
00356
00357 Int_t strip = digit->GetPlexSEIdAltL().GetBestSEId().GetStrip();
00358
00359
00360 UgliStripHandle ush = ugh->GetStripHandle(digit->GetPlexSEIdAltL().GetBestSEId());
00361
00362 if( digit->GetPlexSEIdAltL().GetEnd() == StripEnd::kEast ){
00363 eastFiber[strip] = ush.ClearFiber(StripEnd::kEast) + ush.WlsPigtail(StripEnd::kEast);
00364 eastTime[strip] = 1e9*digit->GetTime(CalTimeType::kT0) - 2093./(102.+TMath::Power(1.*digit->GetCharge(),1.2));
00365 }
00366 else if( digit->GetPlexSEIdAltL().GetEnd() == StripEnd::kWest ){
00367 westFiber[strip] = ush.ClearFiber(StripEnd::kWest) + ush.WlsPigtail(StripEnd::kWest);
00368 westTime[strip] = 1e9*digit->GetTime(CalTimeType::kT0) - 2093./(102.+TMath::Power(1.*digit->GetCharge(),1.2));
00369 }
00370
00371 }
00372 fCdhit.Next();
00373 }
00374
00375
00376 Float_t avTimeNum = 0.;
00377 Float_t avTimeDenom = 0.;
00378 Float_t offset = -10.;
00379 for(Int_t k=0; k<192; k++){
00380
00381
00382 if(westTime[k] != -1.&& eastTime[k] != -1.){
00383 offset = (0.0825*(eastTime[k] - westTime[k]) + (westFiber[k]-eastFiber[k])/2.);
00384
00385 avTimeNum += offset;
00386 avTimeDenom += 1.;
00387 }
00388 }
00389
00390 if(avTimeDenom>0) offset = avTimeNum/avTimeDenom;
00391
00392
00393
00394 fCdhit.Reset();
00395
00396 return offset;
00397 }
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408