00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012 #include <cassert>
00013
00014 #include "Candidate/CandContext.h"
00015 #include "Candidate/CandHandle.h"
00016 #include "CandDigit/CandDeMuxDigitHandle.h"
00017 #include "CandDigit/CandDeMuxDigitListHandle.h"
00018 #include "MessageService/MsgService.h"
00019 #include "Algorithm/AlgConfig.h"
00020 #include "DeMux/DmxStatus.h"
00021 #include "DeMux/DmxUtilities.h"
00022 #include "DeMux/DmxHypothesis.h"
00023 #include "DeMux/DmxPlane.h"
00024 #include "DeMux/DmxShowerPlane.h"
00025 #include "DeMux/DmxMuonPlane.h"
00026 #include "Algorithm/AlgFactory.h"
00027 #include "Algorithm/AlgHandle.h"
00028 #include "DeMux/AlgDeMuxGolden.h"
00029 #include "Navigation/NavKey.h"
00030 #include "Navigation/NavSet.h"
00031 #include "TObjArray.h"
00032 #include "TH1.h"
00033 #include "TFolder.h"
00034 #include "TROOT.h"
00035
00036
00037
00038 static NavKey KeyPlane( const DmxPlane *currentPlane){
00039 return currentPlane->GetPlaneNumber();
00040 }
00041
00042
00043 NavKey KeyU( const DmxPlane *currentPlane){
00044 return currentPlane->GetPlaneView() == PlaneView::kU;
00045 }
00046
00047 NavKey KeyV( const DmxPlane *currentPlane){
00048 return currentPlane->GetPlaneView() == PlaneView::kV;
00049 }
00050
00051
00052 NavKey KeyOnGoldenU( const DmxPlane *currentPlane){
00053 return currentPlane->IsGolden() && currentPlane->GetPlaneView() == PlaneView::kU;
00054 }
00055
00056 NavKey KeyOnGoldenV( const DmxPlane *currentPlane){
00057 return currentPlane->IsGolden() && currentPlane->GetPlaneView() == PlaneView::kV;
00058 }
00059
00060
00061 NavKey KeyOnLeadU( const DmxPlane *currentPlane){
00062 return !currentPlane->IsGolden() && currentPlane->GetPlaneView() == PlaneView::kU;
00063 }
00064
00065 NavKey KeyOnLeadV( const DmxPlane *currentPlane){
00066 return !currentPlane->IsGolden() && currentPlane->GetPlaneView() == PlaneView::kV;
00067 }
00068
00069 ClassImp(AlgDeMuxGolden)
00070
00071
00072
00073
00074 CVSID("$Id: AlgDeMuxGolden.cxx,v 1.15 2003/05/14 19:28:02 brebel Exp $");
00075
00076
00077
00078 AlgDeMuxGolden::AlgDeMuxGolden() :
00079 fStrayPlanes(0),
00080 fPlanesInSet(6),
00081 fStrayCut(6)
00082 {
00083
00084 }
00085
00086
00087
00088 AlgDeMuxGolden::~AlgDeMuxGolden()
00089 {
00090
00091 }
00092
00093
00094
00095 void AlgDeMuxGolden::RunAlg(AlgConfig &acd, CandHandle &ch, CandContext & )
00096 {
00097
00098 assert( ch.InheritsFrom("CandDeMuxDigitListHandle") );
00099 CandDeMuxDigitListHandle &cdlh = dynamic_cast<CandDeMuxDigitListHandle&>(ch);
00100
00101 fPlanesInSet = acd.GetInt("PlanesInSet");
00102
00103
00104
00105
00106 DmxStatus *status = dynamic_cast<DmxStatus *>(gROOT->GetRootFolder()->FindObject("Loon/DeMux/DmxStatus"));
00107 bool tempStatus = false;
00108 if (status == 0) {
00109 MSG("DMXX", Msg::kDebug) << "//root/Loon/DeMux/DmxStatus not found."
00110 << " Create a temporary DmxStatus." << endl;
00111 status = new DmxStatus;
00112 tempStatus = true;
00113 }
00114 else status->ResetStatus();
00115
00116
00117 DmxUtilities util;
00118
00119 util.FillPlaneArray(status, cdlh, acd);
00120 const TObjArray *planeArray = status->GetPlaneArray();
00121
00122
00123
00124
00125 DmxPlaneItr planeItr(planeArray);
00126 DmxPlaneKeyFunc *pnKF = planeItr.CreateKeyFunc();
00127 pnKF->SetFun(KeyPlane);
00128 planeItr.GetSet()->AdoptSortKeyFunc(pnKF);
00129 pnKF = 0;
00130
00131 planeItr.ResetFirst();
00132 status->SetNumberOfPlanes(planeItr.SizeSelect());
00133 status->SetVertexPlaneNumber(util.FindVertexPlane(planeItr));
00134
00135
00136 if( status->GetVertexPlaneNumber() != -1){
00137
00138 planeItr.ResetFirst();
00139 planeItr.GetSet()->Slice(status->GetVertexPlaneNumber(), 500);
00140
00141 status->SetEndPlaneNumber(util.FindEndPlane(planeItr));
00142 planeItr.GetSet()->Slice();
00143 planeItr.ResetFirst();
00144
00145
00146 planeItr.GetSet()->Slice(status->GetVertexPlaneNumber());
00147 planeItr.ResetFirst();
00148 status->SetVertexPlaneZPosition(dynamic_cast<DmxPlane *>(planeItr.Ptr())->GetZPosition());
00149
00150 planeItr.GetSet()->Slice();
00151 planeItr.ResetFirst();
00152
00153
00154
00155
00156
00157 DmxPlaneItr leadPlaneItr(planeArray);
00158 DmxPlaneItr vertexPlaneItr(planeArray);
00159 DmxPlaneItr goldenPlaneItr(planeArray);
00160
00161
00162 DmxPlaneKeyFunc *pnKF = leadPlaneItr.CreateKeyFunc();
00163 DmxPlaneKeyFunc *vertexPlaneKF = vertexPlaneItr.CreateKeyFunc();
00164 DmxPlaneKeyFunc *goldenPlaneKF = goldenPlaneItr.CreateKeyFunc();
00165
00166
00167 pnKF->SetFun(KeyPlane);
00168 vertexPlaneKF->SetFun(KeyPlane);
00169 goldenPlaneKF->SetFun(KeyPlane);
00170
00171
00172 leadPlaneItr.GetSet()->AdoptSortKeyFunc(pnKF);
00173 vertexPlaneItr.GetSet()->AdoptSortKeyFunc(vertexPlaneKF);
00174 goldenPlaneItr.GetSet()->AdoptSortKeyFunc(goldenPlaneKF);
00175
00176
00177
00178 pnKF = 0;
00179 vertexPlaneKF = 0;
00180 goldenPlaneKF = 0;
00181 leadPlaneItr.ResetFirst();
00182 goldenPlaneItr.ResetFirst();
00183 vertexPlaneItr.ResetFirst();
00184
00185
00186 DmxPlaneKeyFunc *orientGoldenUKF = goldenPlaneItr.CreateKeyFunc();
00187 DmxPlaneKeyFunc *orientLeadUKF = leadPlaneItr.CreateKeyFunc();
00188 DmxPlaneKeyFunc *orientGoldenVKF = goldenPlaneItr.CreateKeyFunc();
00189 DmxPlaneKeyFunc *orientLeadVKF = leadPlaneItr.CreateKeyFunc();
00190
00191 Int_t viewCtr = 0;
00192 while( viewCtr < 2 ){
00193
00194 if( viewCtr == 0){
00195
00196 orientLeadUKF->SetFun(KeyOnLeadU);
00197 orientGoldenUKF->SetFun(KeyOnGoldenU);
00198
00199
00200 leadPlaneItr.GetSet()->AdoptSelectKeyFunc(orientLeadUKF);
00201 orientLeadUKF = 0;
00202 leadPlaneItr.Reset();
00203 goldenPlaneItr.GetSet()->AdoptSelectKeyFunc(orientGoldenUKF);
00204 orientGoldenUKF = 0;
00205 goldenPlaneItr.Reset();
00206 }
00207 else if(viewCtr == 1){
00208
00209 orientLeadVKF->SetFun(KeyOnLeadV);
00210 orientGoldenVKF->SetFun(KeyOnGoldenV);
00211
00212
00213 leadPlaneItr.GetSet()->AdoptSelectKeyFunc(orientLeadVKF);
00214 orientLeadVKF = 0;
00215 leadPlaneItr.Reset();
00216 goldenPlaneItr.GetSet()->AdoptSelectKeyFunc(orientGoldenVKF);
00217 orientGoldenVKF = 0;
00218 goldenPlaneItr.Reset();
00219 }
00220
00221
00222 goldenPlaneItr.GetSet()->Slice(status->GetVertexPlaneNumber(), status->GetEndPlaneNumber());
00223
00224 if(goldenPlaneItr.SizeSelect() >=2 ){
00225
00226
00227
00228 while(goldenPlaneItr.IsValid() ){
00229
00230
00231 if(dynamic_cast<DmxPlane*>(goldenPlaneItr.Ptr())->GetPlaneType() == DmxPlaneTypes::kShower){
00232 dynamic_cast<DmxShowerPlane *>(goldenPlaneItr.Ptr())->SetStrips("best");
00233 }
00234 goldenPlaneItr.Next();
00235 }
00236
00237 goldenPlaneItr.Reset();
00238
00239 UseGoldenFit(leadPlaneItr, goldenPlaneItr, status->GetVertexPlaneNumber(),
00240 status->GetEndPlaneNumber());
00241
00242
00243 fStrayPlanes -= util.CheckFit(leadPlaneItr);
00244
00245
00246 leadPlaneItr.GetSet()->Slice();
00247 goldenPlaneItr.GetSet()->Slice();
00248 vertexPlaneItr.GetSet()->Slice(status->GetEndPlaneNumber()+1, 500);
00249
00250
00251
00252 Int_t nextVertex = -1;
00253 if(vertexPlaneItr.SizeSelect() > 3) nextVertex = util.FindVertexPlane(vertexPlaneItr);
00254
00255 while( nextVertex != -1){
00256
00257 status->SetMultipleMuon(true);
00258 vertexPlaneItr.GetSet()->Slice();
00259 vertexPlaneItr.GetSet()->Slice(nextVertex, 500);
00260
00261
00262 Int_t endPlane = util.FindEndPlane(vertexPlaneItr);
00263
00264
00265
00266
00267
00268 goldenPlaneItr.GetSet()->Slice(nextVertex, endPlane);
00269
00270 if(goldenPlaneItr.SizeSelect() >= 2 ){
00271
00272 while(goldenPlaneItr.IsValid() ){
00273
00274 if(dynamic_cast<DmxPlane*>(goldenPlaneItr.Ptr())->GetPlaneType() == DmxPlaneTypes::kShower){
00275 dynamic_cast<DmxShowerPlane *>(goldenPlaneItr.Ptr())->SetStrips("best");
00276 }
00277 goldenPlaneItr.Next();
00278 }
00279
00280 goldenPlaneItr.Reset();
00281
00282 UseGoldenFit(leadPlaneItr, goldenPlaneItr, status->GetVertexPlaneNumber(),
00283 status->GetEndPlaneNumber());
00284
00285
00286 fStrayPlanes -= util.CheckFit(leadPlaneItr);
00287
00288
00289
00290 }
00291
00292
00293 leadPlaneItr.GetSet()->Slice();
00294 goldenPlaneItr.GetSet()->Slice();
00295 vertexPlaneItr.GetSet()->Slice();
00296 vertexPlaneItr.GetSet()->Slice(endPlane+1, 500);
00297
00298
00299
00300
00301 vertexPlaneItr.Reset();
00302
00303 if(vertexPlaneItr.SizeSelect() > 0){
00304 nextVertex = util.FindVertexPlane(vertexPlaneItr);
00305 }
00306 else{ nextVertex = -1; }
00307 }
00308 }
00309 else{
00310 MSG("DMX", Msg::kWarning)<< "Event " << status->GetEventNumber()
00311 << " not demuxed; not enough golden planes in view" << endl;
00312 status->SetValidPlanesFailure(true);
00313 }
00314
00315 status->SetFigureOfMerit(goldenPlaneItr.SizeSelect(), fStrayPlanes);
00316 if(viewCtr == 0 && status->GetEventDeMuxed()){
00317 status->SetUStrayPlanes(fStrayPlanes);
00318 status->SetUValidPlanes(goldenPlaneItr.SizeSelect());
00319 if( status->GetFigureOfMeritFailure() )
00320
00321
00322 status->SetUOverlappingMultiple(util.IsOverlappingMultiple(goldenPlaneItr, status->GetVertexZPosition(),
00323 acd.GetDouble("HoughInterceptRMSLimit"),
00324 acd.GetDouble("HoughSlopeRMSLimit"),
00325 acd.GetDouble("HoughPeakLimit")));
00326 }
00327 if(viewCtr == 1 && status->GetEventDeMuxed()){
00328 status->SetVStrayPlanes(fStrayPlanes);
00329 status->SetVValidPlanes(goldenPlaneItr.SizeSelect());
00330
00331
00332 if( status->GetFigureOfMeritFailure() )
00333 status->SetVOverlappingMultiple(util.IsOverlappingMultiple(goldenPlaneItr, status->GetVertexZPosition(),
00334 acd.GetDouble("HoughInterceptRMSLimit"),
00335 acd.GetDouble("HoughSlopeRMSLimit"),
00336 acd.GetDouble("HoughPeakLimit")));
00337 }
00338
00339
00340
00341 vertexPlaneItr.GetSet()->Slice();
00342 leadPlaneItr.GetSet()->Slice();
00343 leadPlaneItr.GetSet()->AdoptSelectKeyFunc(0);
00344 leadPlaneItr.Reset();
00345 goldenPlaneItr.GetSet()->Slice();
00346 goldenPlaneItr.GetSet()->AdoptSelectKeyFunc(0);
00347 goldenPlaneItr.Reset();
00348
00349 ++viewCtr;
00350 }
00351
00352 }
00353 return;
00354 }
00355
00356
00357 void AlgDeMuxGolden::Trace(const char * ) const
00358 {
00359 }
00360
00361
00362
00363 void AlgDeMuxGolden::UseGoldenFit(DmxPlaneItr &leadPlaneItr, DmxPlaneItr &goldenPlaneItr,
00364 Int_t vertexPlane, Int_t endPlane)
00365 {
00366
00367
00368
00369 Int_t numLoops = goldenPlaneItr.SizeSelect() - 1;
00370 Int_t loopCtr = 0;
00371 DmxUtilities util = DmxUtilities();
00372
00373 goldenPlaneItr.Reset();
00374
00375 while(loopCtr < numLoops){
00376
00377
00378 Int_t goldCtr = 0;
00379 Float_t goldCoG1 = -1.;
00380 Float_t goldCoG2 = -1.;
00381 Float_t goldZ1 = -1.;
00382 Float_t goldZ2 = -1.;
00383 Int_t firstPlane = -1;
00384 Int_t lastPlane = -1;
00385
00386 while(goldCtr < 2 && goldenPlaneItr.IsValid()){
00387
00388
00389
00390 if(goldCtr == 0){
00391 firstPlane = dynamic_cast<DmxPlane*>(goldenPlaneItr.Ptr())->GetPlaneNumber();
00392 goldCoG1 = dynamic_cast<DmxPlane*>(goldenPlaneItr.Ptr())->GetCoG();
00393 goldZ1 = dynamic_cast<DmxPlane*>(goldenPlaneItr.Ptr())->GetZPosition();
00394 goldenPlaneItr.Next();
00395 }
00396 else if(goldCtr == 1){
00397 lastPlane = dynamic_cast<DmxPlane*>(goldenPlaneItr.Ptr())->GetPlaneNumber();
00398 goldCoG2 = dynamic_cast<DmxPlane*>(goldenPlaneItr.Ptr())->GetCoG();
00399 goldZ2 = dynamic_cast<DmxPlane*>(goldenPlaneItr.Ptr())->GetZPosition();
00400 }
00401 ++goldCtr;
00402 }
00403
00404
00405 Float_t slope = (goldCoG2 - goldCoG1)/(goldZ2 - goldZ1);
00406 Float_t intercept = goldCoG2 - goldZ2*slope;
00407
00408
00409
00410
00411
00412
00413
00414
00415 if(loopCtr == 0) firstPlane = vertexPlane;
00416 else if(loopCtr == numLoops-1) lastPlane = endPlane;
00417
00418 leadPlaneItr.GetSet()->Slice(firstPlane, lastPlane);
00419
00420 SetPlanesToDeterminedFit(leadPlaneItr, intercept, slope, firstPlane, lastPlane);
00421
00422 fStrayPlanes += util.FindPlanesOffFit(leadPlaneItr, fStrayCut);
00423
00424
00425 leadPlaneItr.GetSet()->Slice();
00426
00427 ++loopCtr;
00428 }
00429
00430 leadPlaneItr.Reset();
00431 goldenPlaneItr.Reset();
00432 return;
00433
00434 }
00435
00436
00437
00438 void AlgDeMuxGolden::SetPlanesToDeterminedFit(DmxPlaneItr &planeItr, Double_t a,
00439 Double_t b,
00440 Int_t firstPlane, Int_t lastPlane)
00441 {
00442 planeItr.ResetFirst();
00443
00444 while( planeItr.IsValid() ){
00445
00446 DmxPlane *plane = dynamic_cast<DmxPlane *>(planeItr.Ptr());
00447
00448
00449 if(plane->GetPlaneNumber()>=firstPlane && plane->GetPlaneNumber()<=lastPlane){
00450 Double_t fitCoG = a + (plane->GetZPosition() * b);
00451
00452 plane->SetStrips(fitCoG);
00453 }
00454
00455 planeItr.Next();
00456 }
00457
00458 planeItr.Reset();
00459
00460 return;
00461 }
00462