00001
00002
00003
00004
00005
00006
00007
00008
00010
00011
00012 #include "DeMux/DmxMuonPlane.h"
00013 #include "MessageService/MsgService.h"
00014 #include "Navigation/NavSet.h"
00015 #include "Conventions/PlaneView.h"
00016 #include "Conventions/StripEnd.h"
00017 #include "UgliGeometry/UgliStripHandle.h"
00018 #include "UgliGeometry/UgliScintPlnHandle.h"
00019 #include "Plex/PlexStripEndId.h"
00020 #include "Algorithm/AlgConfig.h"
00021 #include "CandDigit/CandDeMuxDigit.h"
00022 #include "CandDigit/CandDeMuxDigitHandle.h"
00023 #include "TMath.h"
00024
00025 ClassImp(DmxMuonPlane)
00026
00027
00028 CVSID("$Id: DmxMuonPlane.cxx,v 1.52 2007/11/11 07:36:22 rhatcher Exp $");
00029
00030
00031 DmxMuonPlane::DmxMuonPlane()
00032 {
00033 }
00034
00035
00036 DmxMuonPlane::DmxMuonPlane(AlgConfig & ,
00037 CandDeMuxDigitHandleItr &cdhitr,
00038 Int_t planeNumber) :
00039 fCdhit(cdhitr),
00040 fCoG(0.),
00041 fInitialCoG(-1.),
00042 fNumberOfStrips(1),
00043 fPlaneCharge(0.),
00044 fPlaneNumber(planeNumber),
00045 fPlaneType(DmxPlaneTypes::kMuon),
00046 fPlaneView(PlaneView::kUnknown),
00047 fStripsSet(0),
00048 fIsValid(false),
00049 fIsStray(false),
00050 fIsGolden(false),
00051 fUgh(0)
00052 {
00053 fCdhit.Reset();
00054
00055
00056 fPlaneView = fCdhit.Ptr()->GetPlexSEIdAltL().GetPlaneView();
00057
00058
00059 fUgh = new UgliGeomHandle(*fCdhit.Ptr()->GetVldContext());
00060
00061 Int_t numDigits = 0;
00062 while( fCdhit.IsValid() ){
00063 if( fCdhit.Ptr()->GetDeMuxDigitFlagWord() == 0) ++numDigits;
00064 fCdhit.Next();
00065 }
00066 fCdhit.Reset();
00067
00068
00069
00070
00071 if( numDigits == 2){
00072
00073 Int_t west = 0;
00074 Int_t east = 0;
00075 CandDeMuxDigitHandle *westDigit = fCdhit.Ptr();
00076 CandDeMuxDigitHandle *eastDigit = fCdhit.Ptr();
00077
00078 while( fCdhit.IsValid() ){
00079 fCdhit.Ptr()->GetPlexSEIdAltLWritable().ClearWeights();
00080 fCdhit.Ptr()->GetPlexSEIdAltL().SetFirst();
00081
00082 if( fCdhit.Ptr()->GetPlexSEIdAltL().GetEnd() == StripEnd::kEast
00083 && fCdhit.Ptr()->GetDeMuxDigitFlagWord() == 0){
00084 east = 1;
00085 eastDigit = fCdhit.Ptr();
00086 }
00087 else if( fCdhit.Ptr()->GetPlexSEIdAltL().GetEnd() == StripEnd::kWest
00088 && fCdhit.Ptr()->GetDeMuxDigitFlagWord() == 0){
00089 west = 1;
00090 westDigit = fCdhit.Ptr();
00091 }
00092
00093 fCdhit.Next();
00094 }
00095 if(west + east == 2){
00096
00097 Int_t westStrip = -1;
00098 Int_t eastStrip = -2;
00099
00100
00101 westDigit->GetPlexSEIdAltL().SetFirst();
00102
00103 while( westDigit->GetPlexSEIdAltL().IsValid() ){
00104 westStrip = westDigit->GetPlexSEIdAltL().GetCurrentSEId().GetStrip();
00105
00106
00107
00108 eastDigit->GetPlexSEIdAltL().SetFirst();
00109
00110 while( eastDigit->GetPlexSEIdAltL().IsValid() ){
00111 eastStrip = eastDigit->GetPlexSEIdAltL().GetCurrentSEId().GetStrip();
00112
00113
00114 if(eastStrip == westStrip){
00115 westDigit->GetPlexSEIdAltLWritable().SetCurrentWeight(1.0);
00116 eastDigit->GetPlexSEIdAltLWritable().SetCurrentWeight(1.0);
00117
00118
00119 westDigit->GetPlexSEIdAltLWritable().SetDemuxVetoFlag(0);
00120 eastDigit->GetPlexSEIdAltLWritable().SetDemuxVetoFlag(0);
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131 fCoG = westDigit->GetPlexSEIdAltL().GetCurrentSEId().GetStrip();
00132 fInitialCoG = fCoG;
00133
00134
00135
00136
00137
00138 if(!fIsValid){
00139 fIsValid = true;
00140 fIsGolden = true;
00141 }
00142 else{
00143 fIsValid = false;
00144 fIsGolden = false;
00145 }
00146
00147 fStripsSet = 1;
00148 }
00149 eastDigit->GetPlexSEIdAltL().Next();
00150 }
00151
00152 westDigit->GetPlexSEIdAltL().Next();
00153 }
00154 }
00155 }
00156
00157 MSG("DmxMuonPlane", Msg::kDebug) << "plane = " << fPlaneNumber
00158 << " initial muon cog = " << fInitialCoG << "/" << fCoG << endl;
00159
00160
00161
00162 if(fIsGolden) SetStrips();
00163
00164
00165 fCdhit.ResetFirst();
00166 while(fCdhit.IsValid()){
00167
00168 if( fCdhit.Ptr()->GetDeMuxDigitFlagWord() == 0)
00169 fPlaneCharge += fCdhit.Ptr()->GetCharge();
00170 fCdhit.Next();
00171 }
00172 fCdhit.Reset();
00173 return;
00174 }
00175
00176
00177 DmxMuonPlane::~DmxMuonPlane()
00178 {
00179 delete fUgh;
00180
00181
00182 }
00183
00184
00185 Int_t DmxMuonPlane::GetNumberOfStrips() const
00186 {
00187 return fNumberOfStrips;
00188 }
00189
00190 Float_t DmxMuonPlane::GetCoG() const
00191 {
00192
00193 PlexStripEndId seid(Detector::kFar,fPlaneNumber,TMath::Nint(fCoG));
00194 UgliStripHandle ush = fUgh->GetStripHandle(seid);
00195
00196 return ush.GetTPos();
00197
00198 }
00199
00200
00201 Float_t DmxMuonPlane::GetInitialCoG() const
00202 {
00203
00204 MSG("DmxMuonPlane", Msg::kDebug) << "plane = " << fPlaneNumber
00205 << " initial muon cog = " << fInitialCoG << "/" << fCoG << endl;
00206
00207
00208 PlexStripEndId seid(Detector::kFar,fPlaneNumber,TMath::Nint(fInitialCoG));
00209 UgliStripHandle ush = fUgh->GetStripHandle(seid);
00210
00211 return ush.GetTPos();
00212
00213 }
00214
00215
00216 Int_t DmxMuonPlane::GetHypothesisLowerBound(Float_t tPos) const
00217 {
00218
00219 PlexStripEndId seid(Detector::kFar, fPlaneNumber, 1);
00220 UgliScintPlnHandle usph = fUgh->GetScintPlnHandle(seid);
00221 UgliStripHandle ush = usph.GetClosestStrip(tPos);
00222 Float_t fitCoG = 1.*ush.GetSEId().GetStrip();
00223
00224 Int_t hypLowerBound = 0;
00225 if(fitCoG >= 11.5 && fitCoG <= 179.5){hypLowerBound = TMath::Nint(fitCoG-11.5);}
00226 else if(fitCoG < 11.5){hypLowerBound = 0;}
00227 else if(fitCoG > 179.5){hypLowerBound = 168;}
00228
00229 return hypLowerBound;
00230 }
00231
00232
00233 Float_t DmxMuonPlane::GetStripCoG() const
00234 {
00235 return fCoG;
00236 }
00237
00238
00239 Float_t DmxMuonPlane::GetInitialStripCoG() const
00240 {
00241 return fInitialCoG;
00242 }
00243
00244
00245 Float_t DmxMuonPlane::GetPlaneCharge() const
00246 {
00247 return fPlaneCharge;
00248 }
00249
00250
00251 Int_t DmxMuonPlane::GetPlaneNumber() const
00252 {
00253 return fPlaneNumber;
00254 }
00255
00256
00257 Float_t DmxMuonPlane::GetZPosition() const
00258 {
00259 PlexStripEndId seid(Detector::kFar, fPlaneNumber, 1);
00260 UgliScintPlnHandle usph = fUgh->GetScintPlnHandle(seid);
00261 return usph.GetZ0();
00262
00263 }
00264
00265
00266 DmxPlaneTypes::PlaneType_t DmxMuonPlane::GetPlaneType() const
00267 {
00268 return fPlaneType;
00269 }
00270
00271
00272 PlaneView::PlaneView_t DmxMuonPlane::GetPlaneView() const
00273 {
00274 return fPlaneView;
00275 }
00276
00277
00278 Bool_t DmxMuonPlane::GetStripsSetFlag() const
00279 {
00280 return fStripsSet>0;
00281 }
00282
00283
00284 Bool_t DmxMuonPlane::IsValid() const
00285 {
00286 return fIsValid;
00287 }
00288
00289
00290 Bool_t DmxMuonPlane::IsStray() const
00291 {
00292 return fIsStray;
00293 }
00294
00295
00296 Bool_t DmxMuonPlane::IsGolden() const
00297 {
00298 return fIsGolden;
00299 }
00300
00301
00302 void DmxMuonPlane::PrintRecon()
00303 {
00304 fCdhit.Reset();
00305 MSG("Dmx", Msg::kInfo) << "Plane = " << fPlaneNumber
00306 << "\tIsValid = " << (Int_t)fIsValid << endl;
00307 while( fCdhit.IsValid() ){
00308 CandDeMuxDigitHandle *currentDigit = fCdhit.Ptr();
00309
00310 if(currentDigit->GetPlexSEIdAltL().GetEnd() == StripEnd::kWest){
00311 MSG("Dmx", Msg::kInfo) << "\tWest\t" ;
00312 }
00313 else if(currentDigit->GetPlexSEIdAltL().GetEnd() == StripEnd::kEast){
00314 MSG("Dmx", Msg::kInfo) << "\tEast\t" ;
00315 }
00316 MSG("Dmx", Msg::kInfo) << currentDigit->GetPlexSEIdAltL().GetBestSEId().GetStrip() << "\t";
00317 MSG("Dmx", Msg::kInfo) << currentDigit->GetCharge() << endl;
00318
00319 fCdhit.Next();
00320 }
00321 return;
00322 }
00323
00324 void DmxMuonPlane::SetStrips()
00325 {
00326 Float_t fitCoG = fInitialCoG;
00327 Int_t hypLower = 0;
00328 if(fitCoG >= 11.5 && fitCoG <= 179.5){hypLower = TMath::Nint(fitCoG-11.5);}
00329 else if(fitCoG < 11.5){hypLower = 0;}
00330 else if(fitCoG > 179.5){hypLower = 168;}
00331
00332 fStripsSet = 1;
00333 fCdhit.Reset();
00334
00335 Double_t cogNum = 0.;
00336 Double_t cogDenom = 0.;
00337
00338 while( fCdhit.IsValid() ){
00339
00340
00341 CandDeMuxDigitHandle *currentDigit = fCdhit.Ptr();
00342
00343
00344 currentDigit->GetPlexSEIdAltLWritable().ClearWeights();
00345
00346
00347 currentDigit->GetPlexSEIdAltL().SetFirst();
00348
00349
00350
00351 currentDigit->GetPlexSEIdAltLWritable().SetDemuxVetoFlag(1);
00352
00353
00354
00355 while( currentDigit->GetPlexSEIdAltL().IsValid() ){
00356
00357 if( currentDigit->GetPlexSEIdAltL().GetCurrentSEId().GetStrip()
00358 >= hypLower && currentDigit->GetPlexSEIdAltL().GetCurrentSEId().GetStrip()
00359 <= (hypLower+23)){
00360
00361
00362
00363 currentDigit->GetPlexSEIdAltLWritable().SetCurrentWeight(1.0);
00364 currentDigit->GetPlexSEIdAltLWritable().SetDemuxVetoFlag(0);
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374 if(currentDigit->GetDeMuxDigitFlagWord() == 0){
00375
00376 cogNum += currentDigit->GetCharge()*currentDigit->GetPlexSEIdAltL().GetCurrentSEId().GetStrip();
00377 cogDenom += currentDigit->GetCharge();
00378 }
00379
00380
00381 break;
00382 }
00383
00384 currentDigit->GetPlexSEIdAltL().Next();
00385 }
00386
00387 fCdhit.Next();
00388 }
00389
00390 if(cogDenom >0.) fCoG = cogNum/cogDenom;
00391
00392 return;
00393 }
00394
00395
00396 void DmxMuonPlane::SetStrips(Float_t tPos)
00397 {
00398
00399 PlexStripEndId seid(Detector::kFar, fPlaneNumber, 1);
00400 UgliScintPlnHandle usph = fUgh->GetScintPlnHandle(seid);
00401 UgliStripHandle ush = usph.GetClosestStrip(tPos);
00402 Float_t fitCoG = 1.*ush.GetSEId().GetStrip();
00403
00404
00405 Int_t hypLower = 0;
00406 if(fitCoG >= 11.5 && fitCoG <= 179.5) hypLower = TMath::Nint(fitCoG-11.5);
00407 else if(fitCoG < 11.5) hypLower = 0;
00408 else if(fitCoG > 179.5) hypLower = 168;
00409
00410 MSG("DmxMuonPlane", Msg::kDebug) << "\tfit in strip vs plane space " << fPlaneNumber
00411 << "\t" << fitCoG << " " << hypLower << endl;
00412 MSG("DmxMuonPlane", Msg::kDebug) << "\tfit in tpos vs z space " << GetZPosition()
00413 << "\t" << tPos << endl;
00414
00415 fStripsSet = 1;
00416 fCdhit.Reset();
00417
00418 Double_t cogNum = 0.;
00419 Double_t cogDenom = 0.;
00420
00421 while( fCdhit.IsValid() ){
00422
00423
00424 CandDeMuxDigitHandle *currentDigit = fCdhit.Ptr();
00425
00426
00427 currentDigit->GetPlexSEIdAltLWritable().ClearWeights();
00428
00429
00430 currentDigit->GetPlexSEIdAltLWritable().SetFirst();
00431
00432
00433
00434 currentDigit->GetPlexSEIdAltLWritable().SetDemuxVetoFlag(1);
00435
00436
00437
00438 while( currentDigit->GetPlexSEIdAltLWritable().IsValid() ){
00439
00440 MSG("DmxMuonPlane", Msg::kDebug) << "plane = "
00441 << currentDigit->GetPlexSEIdAltLWritable().GetPlane()
00442 << " strip alt = "
00443 << currentDigit->GetPlexSEIdAltLWritable().GetCurrentSEId().GetStrip()
00444 << endl;
00445
00446 if( currentDigit->GetPlexSEIdAltLWritable().GetCurrentSEId().GetStrip()
00447 >= hypLower && currentDigit->GetPlexSEIdAltLWritable().GetCurrentSEId().GetStrip()
00448 <= (hypLower+23)){
00449
00450
00451
00452 currentDigit->GetPlexSEIdAltLWritable().SetCurrentWeight(1.0);
00453 currentDigit->GetPlexSEIdAltLWritable().SetDemuxVetoFlag(0);
00454
00455 MSG("DmxMuonPlane", Msg::kDebug) << "strip = "
00456 << currentDigit->GetPlexSEIdAltLWritable().GetCurrentSEId().GetStrip()
00457 << " " << currentDigit->GetPlexSEIdAltLWritable().GetCurrentWeight()
00458 << endl;
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468 if(currentDigit->GetDeMuxDigitFlagWord() == 0){
00469 cogNum += currentDigit->GetCharge()*currentDigit->GetPlexSEIdAltL().GetCurrentSEId().GetStrip();
00470 cogDenom += currentDigit->GetCharge();
00471 }
00472
00473
00474 break;
00475 }
00476
00477 currentDigit->GetPlexSEIdAltL().Next();
00478 }
00479
00480 fCdhit.Next();
00481 }
00482
00483 if(cogDenom >0.) fCoG = cogNum/cogDenom;
00484
00485 return;
00486 }
00487
00488
00489 void DmxMuonPlane::SetStray(bool stray)
00490 {
00491 fIsStray = stray;
00492 return;
00493 }
00494
00495
00496 void DmxMuonPlane::SetGolden(bool golden)
00497 {
00498 fIsGolden = golden;
00499 return;
00500 }
00501
00502
00503 Float_t DmxMuonPlane::GetTimingOffset()
00504 {
00505
00506 Float_t westFiber[192];
00507 Float_t eastFiber[192];
00508 Float_t eastTime[192];
00509 Float_t westTime[192];
00510
00511
00512 for(Int_t i = 0; i<192; i++){
00513 westFiber[i] = -1.;
00514 eastFiber[i] = -1.;
00515 eastTime[i] = -1.;
00516 westTime[i] = -1.;
00517 }
00518
00519 fCdhit.Reset();
00520
00521 while(fCdhit.IsValid()){
00522
00523 CandDeMuxDigitHandle *digit = fCdhit.Ptr();
00524
00525 if(digit->GetPlexSEIdAltL().GetDemuxVetoFlag() == 0 && digit->GetDeMuxDigitFlagWord() == 0){
00526
00527 Int_t strip = digit->GetPlexSEIdAltL().GetBestSEId().GetStrip();
00528
00529
00530 UgliStripHandle ush = fUgh->GetStripHandle(digit->GetPlexSEIdAltL().GetBestSEId());
00531
00532 if( digit->GetPlexSEIdAltL().GetEnd() == StripEnd::kEast ){
00533 eastFiber[strip] = ush.ClearFiber(StripEnd::kEast) + ush.WlsPigtail(StripEnd::kEast);
00534 eastTime[strip] = 1e9*digit->GetTime(CalTimeType::kT0) - 2093./(102.+TMath::Power(1.*digit->GetCharge(),1.2));
00535 }
00536 else if( digit->GetPlexSEIdAltL().GetEnd() == StripEnd::kWest ){
00537 westFiber[strip] = ush.ClearFiber(StripEnd::kWest) + ush.WlsPigtail(StripEnd::kWest);
00538 westTime[strip] = 1e9*digit->GetTime(CalTimeType::kT0) - 2093./(102.+TMath::Power(1.*digit->GetCharge(),1.2));
00539 }
00540
00541 }
00542 fCdhit.Next();
00543 }
00544
00545
00546 Float_t avTimeNum = 0.;
00547 Float_t avTimeDenom = 0.;
00548 Float_t offset = -10.;
00549 for(Int_t k=0; k<192; k++){
00550
00551
00552 if(westTime[k] != -1.&& eastTime[k] != -1.){
00553 offset = (0.0825*(eastTime[k] - westTime[k]) + (westFiber[k]-eastFiber[k])/2.);
00554
00555 avTimeNum += offset;
00556 avTimeDenom += 1.;
00557 }
00558 }
00559
00560 if(avTimeDenom>0) offset = avTimeNum/avTimeDenom;
00561
00562
00563
00564
00565 fCdhit.Reset();
00566
00567 return offset;
00568 }
00569
00570
00571
00572