00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00012
00013 #include "DeMux/DmxShowerPlane.h"
00014 #include "DeMux/DmxHypothesis.h"
00015 #include "MessageService/MsgService.h"
00016 #include "Navigation/NavKey.h"
00017 #include "Navigation/NavSet.h"
00018 #include "MINF_Classes/MINFast.h"
00019 #include "Conventions/PlaneView.h"
00020 #include "UgliGeometry/UgliStripHandle.h"
00021 #include "UgliGeometry/UgliScintPlnHandle.h"
00022 #include "Plex/PlexStripEndId.h"
00023 #include "Algorithm/AlgConfig.h"
00024 #include "TMath.h"
00025
00026 XXXITRIMP(TObject)
00027
00028
00029 static NavKey KeyValidHypo( const DmxHypothesis *hypo){
00030
00031 return (Int_t)hypo->IsValid() == 1;
00032 }
00033
00034
00035 static NavKey KeyStat( const DmxHypothesis *hypo){
00036 return hypo->GetStat();
00037 }
00038
00039 ClassImp(DmxShowerPlane)
00040
00041
00042 CVSID("$Id: DmxShowerPlane.cxx,v 1.77 2007/11/11 07:36:22 rhatcher Exp $");
00043
00044
00045 DmxShowerPlane::DmxShowerPlane() :
00046 fBestHypo(0),
00047 fHypothesisArray(0),
00048 fSecondBestHypo(0),
00049 fSetHypo(0),
00050 fThirdBestHypo(0),
00051 fUgh(0)
00052 {
00053 }
00054
00055
00056
00057
00058 DmxShowerPlane::DmxShowerPlane(AlgConfig &acd, CandDeMuxDigitHandleItr &cdhitr,
00059 Int_t planeNumber) :
00060 fBestCoG(0.),
00061 fBestHypo(0),
00062 fCoG(0.),
00063 fCompare(0),
00064 fHypothesisArray(new TObjArray(acd.GetInt("NumberOfHypotheses"), 0)),
00065 fIsValid(false),
00066 fIsStray(false),
00067 fIsGolden(false),
00068 fNumberOfHypotheses(acd.GetInt("NumberOfHypotheses")),
00069 fNumberOfStrips(0),
00070 fPlaneCharge(0.),
00071 fPlaneNumber(planeNumber),
00072 fPlaneType(DmxPlaneTypes::kShower),
00073 fPlaneView(PlaneView::kUnknown),
00074 fSecondBestCoG(0.),
00075 fSecondBestHypo(0),
00076 fSetHypo(0),
00077 fThirdBestCoG(0.),
00078 fThirdBestHypo(0),
00079 fStripsSet(0),
00080 fUgh(0)
00081 {
00082
00083
00084
00085 Int_t hypothesisSize = acd.GetInt("HypothesisSize");
00086
00087
00088 fUgh = new UgliGeomHandle(*cdhitr.Ptr()->GetVldContext());
00089
00090 Int_t lowerStrip = 0;
00091 Int_t upperStrip = 0;
00092 for(Int_t i = 0; i < fNumberOfHypotheses; i++){
00093 lowerStrip = i;
00094 upperStrip = i + (hypothesisSize - 1);
00095 fHypothesisArray->AddAt(new DmxHypothesis(acd, cdhitr, lowerStrip, upperStrip), lowerStrip);
00096 }
00097
00098
00099
00100
00101
00102 DmxHypothesisItr hypoItr(fHypothesisArray);
00103
00104 fCompare = hypoItr.Ptr()->GetCompareFlag();
00105
00106
00107 DmxHypothesisKeyFunc *hypStatKF = hypoItr.CreateKeyFunc();
00108
00109
00110 hypStatKF->SetFun(KeyStat);
00111
00112
00113 hypoItr.GetSet()->AdoptSortKeyFunc(hypStatKF);
00114
00115
00116
00117 hypStatKF = 0;
00118
00119
00120 DmxHypothesisKeyFunc *validKF = hypoItr.CreateKeyFunc();
00121
00122
00123 validKF->SetFun(KeyValidHypo);
00124
00125
00126 hypoItr.GetSet()->AdoptSelectKeyFunc(validKF);
00127 validKF = 0;
00128
00129
00130 hypoItr.ResetLast();
00131 fBestHypo = dynamic_cast<DmxHypothesis *>(hypoItr.Ptr());
00132 fSecondBestHypo = dynamic_cast<DmxHypothesis *>(hypoItr.Ptr());
00133 fThirdBestHypo = dynamic_cast<DmxHypothesis *>(hypoItr.Ptr());
00134
00135
00136
00137 DmxHypothesis *hypo = 0;
00138
00139
00140 hypoItr.ResetFirst();
00141
00142 if( hypoItr.SizeSelect() > 1 ){
00143
00144 fIsValid = true;
00145
00146 for(Int_t i = 1; i < 4; i++){
00147
00148
00149 while( (hypo = hypoItr()) ){
00150
00151
00152
00153
00154
00155
00156 if(hypo->GetNumberOfStripsUsed()>fNumberOfStrips)
00157 fNumberOfStrips = hypo->GetNumberOfStripsUsed();
00158
00159 if( i == 1 && CompareHypotheses(hypo, fBestHypo) == DmxCompareTypes::kBetter ){
00160 fBestHypo = hypo;
00161 }
00162 else if( i == 2 && CompareHypotheses(hypo, fBestHypo) == DmxCompareTypes::kWorse
00163 && CompareHypotheses(hypo, fSecondBestHypo) == DmxCompareTypes::kBetter){
00164 fSecondBestHypo = hypo;
00165 }
00166 else if( i == 3 && CompareHypotheses(hypo, fSecondBestHypo) == DmxCompareTypes::kWorse
00167 && CompareHypotheses(hypo, fThirdBestHypo) == DmxCompareTypes::kBetter){
00168 fThirdBestHypo = hypo;
00169 }
00170
00171 }
00172 hypoItr.ResetFirst();
00173 }
00174 }
00175 else if(hypoItr.SizeSelect() == 1){
00176
00177
00178 fBestHypo = hypoItr.Ptr();
00179 fSecondBestHypo = hypoItr.Ptr();
00180 fThirdBestHypo = hypoItr.Ptr();
00181
00182
00183
00184 if(fBestHypo->GetMatedSignalRatio()>=0.9){
00185 fIsGolden = true;
00186 SetStrips("best");
00187 }
00188
00189 }
00190
00191 if(hypoItr.SizeSelect() == 2){
00192
00193 fThirdBestHypo = fSecondBestHypo;
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205 if(fBestHypo->GetMatedSignalRatio()>=0.9
00206 && fSecondBestHypo->GetMatedSignalRatio()<0.8){
00207 fIsGolden = true;
00208 SetStrips("best");
00209 }
00210 else if(fBestHypo->GetMatedSignalRatio()>=0.9
00211 && TMath::Abs(fBestHypo->GetCoG()-fSecondBestHypo->GetCoG())<3.){
00212 fIsGolden = true;
00213 SetStrips("best");
00214 }
00215 }
00216 else if(hypoItr.SizeSelect() >= 3){
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228 if(fBestHypo->GetMatedSignalRatio()>=0.9
00229 && fSecondBestHypo->GetMatedSignalRatio()<0.8
00230 && fThirdBestHypo->GetMatedSignalRatio()<0.8){
00231 fIsGolden = true;
00232 SetStrips("best");
00233 }
00234 else if(fBestHypo->GetMatedSignalRatio()>=0.9
00235 && TMath::Abs(fBestHypo->GetCoG()-fSecondBestHypo->GetCoG())<3.
00236 && TMath::Abs(fBestHypo->GetCoG()-fThirdBestHypo->GetCoG())<3.){
00237 fIsGolden = true;
00238 SetStrips("best");
00239 }
00240 else if(fBestHypo->GetMatedSignalRatio()>=0.9
00241 && fSecondBestHypo->GetMatedSignalRatio()>=0.8
00242 && TMath::Abs(fBestHypo->GetCoG()-fSecondBestHypo->GetCoG())<3.
00243 && fThirdBestHypo->GetMatedSignalRatio()<0.8){
00244 fIsGolden = true;
00245 SetStrips("best");
00246 }
00247 else if(fBestHypo->GetMatedSignalRatio()>=0.9
00248 && fSecondBestHypo->GetMatedSignalRatio()<0.8
00249 && fThirdBestHypo->GetMatedSignalRatio()>=0.8
00250 && TMath::Abs(fBestHypo->GetCoG()-fThirdBestHypo->GetCoG())<3.){
00251 fIsGolden = true;
00252 SetStrips("best");
00253 }
00254
00255
00256
00257
00258
00259 if(fBestHypo->GetMatedSignalRatio()-fThirdBestHypo->GetMatedSignalRatio()>0.2
00260 &&fSecondBestHypo->GetMatedSignalRatio()-fThirdBestHypo->GetMatedSignalRatio()>0.2)
00261 fThirdBestHypo = fSecondBestHypo;
00262
00263 }
00264
00265
00266 hypoItr.GetSet()->AdoptSelectKeyFunc(0);
00267
00268
00269 cdhitr.Reset();
00270 fPlaneView = cdhitr.Ptr()->GetPlexSEIdAltL().GetPlaneView();
00271 while(cdhitr.IsValid()){
00272 if(cdhitr.Ptr()->GetDeMuxDigitFlagWord() == 0) fPlaneCharge += cdhitr.Ptr()->GetCharge();
00273 MSG("DmxShower", Msg::kDebug) << "plane = " << cdhitr.Ptr()->GetPlexSEIdAltL().GetPlane()
00274 << " digit charge = " << cdhitr.Ptr()->GetCharge() << endl;
00275 cdhitr.Next();
00276 }
00277
00278
00279 if(fBestHypo && !fIsGolden) SetStrips("best");
00280
00281 return;
00282 }
00283
00284
00285 DmxShowerPlane::~DmxShowerPlane()
00286 {
00287 fHypothesisArray->Delete();
00288 delete fHypothesisArray;
00289 delete fUgh;
00290
00291
00292 }
00293
00294
00295 Int_t DmxShowerPlane::GetNumberOfStrips() const
00296 {
00297 return fNumberOfStrips;
00298 }
00299
00300 DmxHypothesis *DmxShowerPlane::GetBestHypothesis()
00301 {
00302 return fBestHypo;
00303 }
00304
00305
00306 Float_t DmxShowerPlane::GetCoG() const
00307 {
00308
00309 PlexStripEndId seid(Detector::kFar,fPlaneNumber,TMath::Nint(fCoG));
00310 UgliStripHandle ush = fUgh->GetStripHandle(seid);
00311
00312 return ush.GetTPos();
00313
00314 }
00315
00316
00317 Float_t DmxShowerPlane::GetStripCoG() const
00318 {
00319 return fCoG;
00320 }
00321
00322
00323 Float_t DmxShowerPlane::GetHypothesisCoG(Int_t hypoLowerBound)
00324 {
00325 Float_t hypCoG = dynamic_cast<DmxHypothesis *>(fHypothesisArray->At(hypoLowerBound))->GetCoG();
00326
00327
00328 PlexStripEndId seid(Detector::kFar,fPlaneNumber,TMath::Nint(hypCoG));
00329 UgliStripHandle ush = fUgh->GetStripHandle(seid);
00330
00331 return ush.GetTPos();
00332 }
00333
00334
00335 DmxHypothesis *DmxShowerPlane::GetHypothesis(Int_t hypoLowerBound)
00336 {
00337 return dynamic_cast<DmxHypothesis *>(fHypothesisArray->At(hypoLowerBound));
00338 }
00339
00340
00341 DmxHypothesis *DmxShowerPlane::GetSecondBestHypothesis()
00342 {
00343 return fSecondBestHypo;
00344 }
00345
00346
00347 DmxHypothesis *DmxShowerPlane::GetSetHypothesis()
00348 {
00349 return fSetHypo;
00350 }
00351
00352
00353 DmxHypothesis *DmxShowerPlane::GetThirdBestHypothesis()
00354 {
00355 return fThirdBestHypo;
00356 }
00357
00358
00359 Float_t DmxShowerPlane::GetBestCoG() const
00360 {
00361
00362 PlexStripEndId seid(Detector::kFar,fPlaneNumber,TMath::Nint(fBestHypo->GetCoG()));
00363 UgliStripHandle ush = fUgh->GetStripHandle(seid);
00364
00365 return ush.GetTPos();
00366
00367 }
00368
00369
00370 Float_t DmxShowerPlane::GetSecondBestCoG() const
00371 {
00372
00373 PlexStripEndId seid(Detector::kFar,fPlaneNumber,TMath::Nint(fSecondBestHypo->GetCoG()));
00374 UgliStripHandle ush = fUgh->GetStripHandle(seid);
00375
00376 return ush.GetTPos();
00377
00378 }
00379
00380
00381 Float_t DmxShowerPlane::GetThirdBestCoG() const
00382 {
00383
00384 PlexStripEndId seid(Detector::kFar,fPlaneNumber,TMath::Nint(fThirdBestHypo->GetCoG()));
00385 UgliStripHandle ush = fUgh->GetStripHandle(seid);
00386
00387 return ush.GetTPos();
00388
00389 }
00390
00391
00392 Bool_t DmxShowerPlane::GetStripsSetFlag() const
00393 {
00394 return fStripsSet == 1;
00395 }
00396
00397
00398 Bool_t DmxShowerPlane::IsValid() const
00399 {
00400 return fIsValid;
00401 }
00402
00403
00404 Bool_t DmxShowerPlane::IsStray() const
00405 {
00406 return fIsStray;
00407 }
00408
00409
00410 Bool_t DmxShowerPlane::IsGolden() const
00411 {
00412 return fIsGolden;
00413 }
00414
00415
00416 DmxCompareTypes::CompareType_t DmxShowerPlane::CompareHypotheses(DmxHypothesis *hypo1, DmxHypothesis *hypo2)
00417 {
00418
00419
00420
00421
00422 DmxCompareTypes::CompareType_t stat = DmxCompareTypes::kWorse;
00423
00424
00425 if(fCompare == 0){
00426 if(hypo1->GetStat() < hypo2->GetStat()) stat = DmxCompareTypes::kBetter;
00427 else if( hypo1->GetStat() == hypo2->GetStat() ){
00428 if( hypo1->GetTieBreakerStat() < hypo2->GetTieBreakerStat() ) stat = DmxCompareTypes::kBetter;
00429 else if( hypo1->GetTieBreakerStat() == hypo2->GetTieBreakerStat() ) stat = DmxCompareTypes::kSame;
00430 }
00431 }
00432 else if(fCompare == 1){
00433 if(hypo1->GetStat() > hypo2->GetStat()) stat = DmxCompareTypes::kBetter;
00434 else if( hypo1->GetStat() == hypo2->GetStat() ){
00435 if( hypo1->GetTieBreakerStat() > hypo2->GetTieBreakerStat() ) stat = DmxCompareTypes::kBetter;
00436 else if( hypo1->GetTieBreakerStat() == hypo2->GetTieBreakerStat() ) stat = DmxCompareTypes::kSame;
00437 }
00438 }
00439 return stat;
00440 }
00441
00442
00443 void DmxShowerPlane::SetStrips()
00444 {
00445 if(fBestHypo) SetStrips("best");
00446
00447 return;
00448 }
00449
00450
00451
00452
00453 void DmxShowerPlane::SetStrips(const Char_t *option)
00454 {
00455 fStripsSet = 1;
00456 Int_t hypLowerBound = 0;
00457 Float_t fitCoG = 0.;
00458
00459
00460 if(strcmp(option, "best") == 0 && fBestHypo) fitCoG = fBestHypo->GetCoG();
00461 else if(strcmp(option, "second") == 0 && fSecondBestHypo) fitCoG = fSecondBestHypo->GetCoG();
00462 else if(strcmp(option, "third") == 0 && fThirdBestHypo) fitCoG = fThirdBestHypo->GetCoG();
00463
00464 if(fitCoG >= 11.5 && fitCoG <= 179.5){hypLowerBound = TMath::Nint(fitCoG-11.5);}
00465 else if(fitCoG < 11.5){hypLowerBound = 0;}
00466 else if(fitCoG > 179.5){hypLowerBound = 168;}
00467
00468 if(hypLowerBound <= fNumberOfHypotheses){
00469 dynamic_cast<DmxHypothesis *>(fHypothesisArray->At(hypLowerBound))->SetStrips();
00470 fCoG = dynamic_cast<DmxHypothesis *>(fHypothesisArray->At(hypLowerBound))->GetCoG();
00471 fSetHypo = dynamic_cast<DmxHypothesis *>(fHypothesisArray->At(hypLowerBound));
00472 }
00473 else{
00474
00475
00476 fSetHypo = 0;
00477 }
00478 return;
00479 }
00480
00481
00482 Int_t DmxShowerPlane::GetHypothesisLowerBound(Float_t tPos) const
00483 {
00484
00485 PlexStripEndId seid(Detector::kFar, fPlaneNumber, 1);
00486 UgliScintPlnHandle usph = fUgh->GetScintPlnHandle(seid);
00487 UgliStripHandle ush = usph.GetClosestStrip(tPos);
00488 Float_t fitCoG = 1.*ush.GetSEId().GetStrip();
00489
00490 Int_t hypLowerBound = 0;
00491 if(fitCoG >= 11.5 && fitCoG <= 179.5){hypLowerBound = TMath::Nint(fitCoG-11.5);}
00492 else if(fitCoG < 11.5){hypLowerBound = 0;}
00493 else if(fitCoG > 179.5){hypLowerBound = 168;}
00494
00495 return hypLowerBound;
00496 }
00497
00498
00499 void DmxShowerPlane::SetStrips(Float_t tPos)
00500 {
00501
00502
00503 PlexStripEndId seid(Detector::kFar, fPlaneNumber, 1);
00504 UgliScintPlnHandle usph = fUgh->GetScintPlnHandle(seid);
00505 UgliStripHandle ush = usph.GetClosestStrip(tPos);
00506 Float_t fitCoG = 1.*ush.GetSEId().GetStrip();
00507
00508
00509
00510
00511
00512 Int_t hypLowerBound = 0;
00513 if(fitCoG >= 11.5 && fitCoG <= 179.5){hypLowerBound = TMath::Nint(fitCoG-11.5);}
00514 else if(fitCoG < 11.5){hypLowerBound = 0;}
00515 else if(fitCoG > 179.5){hypLowerBound = 168;}
00516
00517 fStripsSet = 1;
00518
00519 if(hypLowerBound <= fNumberOfHypotheses){
00520 dynamic_cast<DmxHypothesis *>(fHypothesisArray->At(hypLowerBound))->SetStrips();
00521 fCoG = dynamic_cast<DmxHypothesis *>(fHypothesisArray->At(hypLowerBound))->GetCoG();
00522 fSetHypo = dynamic_cast<DmxHypothesis *>(fHypothesisArray->At(hypLowerBound));
00523 }
00524 else{
00525
00526
00527 fSetHypo = 0;
00528 }
00529 return;
00530 }
00531
00532
00533 Float_t DmxShowerPlane::GetPlaneCharge() const
00534 {
00535 return fPlaneCharge;
00536 }
00537
00538
00539 Int_t DmxShowerPlane::GetPlaneNumber() const
00540 {
00541 return fPlaneNumber;
00542 }
00543
00544
00545 Float_t DmxShowerPlane::GetTimingOffset()
00546 {
00547 if(fSetHypo){
00548 return fSetHypo->GetTimingOffset(fUgh);
00549 }
00550
00551
00552
00553 return -10.;
00554 }
00555
00556
00557 Float_t DmxShowerPlane::GetZPosition() const
00558 {
00559 PlexStripEndId seid(Detector::kFar, fPlaneNumber, 1);
00560 UgliScintPlnHandle usph = fUgh->GetScintPlnHandle(seid);
00561 return usph.GetZ0();
00562
00563 }
00564
00565
00566 DmxPlaneTypes::PlaneType_t DmxShowerPlane::GetPlaneType() const
00567 {
00568 return fPlaneType;
00569 }
00570
00571
00572 PlaneView::PlaneView_t DmxShowerPlane::GetPlaneView() const
00573 {
00574 return fPlaneView;
00575 }
00576
00577
00578 void DmxShowerPlane::PrintRecon()
00579 {
00580 MSG("Dmx", Msg::kInfo) << "Plane = " << fPlaneNumber
00581 << "\tIsValid = " << fIsValid << endl;
00582 fSetHypo->PrintRecon();
00583 }
00584
00585
00586 void DmxShowerPlane::PrintRecon(Int_t hypoLowerBound)
00587 {
00588 MSG("DMX", Msg::kInfo) << "Plane\t" << fPlaneNumber << endl;
00589 dynamic_cast<DmxHypothesis *>(fHypothesisArray->At(hypoLowerBound))->PrintRecon();
00590 }
00591
00592
00593
00594 void DmxShowerPlane::SetStripsSetFlag(Int_t flag)
00595 {
00596 if(flag == 0 || flag == 1){fStripsSet = flag;}
00597 else MSG("Dmx", Msg::kError) << "input flag value is not an option" << endl;
00598 }
00599
00600
00601 void DmxShowerPlane::SetStray(bool stray)
00602 {
00603 fIsStray = stray;
00604 return;
00605 }
00606
00607
00608 void DmxShowerPlane::SetGolden(bool golden)
00609 {
00610 fIsGolden = golden;
00611 return;
00612 }
00613
00614
00615
00616