00001
00002
00003
00004
00005
00007
00008 #include <cmath>
00009
00010 #include "TClonesArray.h"
00011 #include "TF1.h"
00012 #include "TGraph.h"
00013
00014 #include "MessageService/MsgService.h"
00015 #include "CandNtupleSR/NtpSRTrack.h"
00016 #include "CandNtupleSR/NtpSRStrip.h"
00017 #include "StandardNtuple/NtpStRecord.h"
00018 #include "DataUtil/PlaneOutline.h"
00019 #include "Plex/PlexHandle.h"
00020 #include "UgliGeometry/UgliGeomHandle.h"
00021
00022 #include "MeuCal/MeuHitInfo.h"
00023 #include "MeuCal/MeuReco.h"
00024 #include "MeuCal/MeuSummary.h"
00025
00026 using std::endl;
00027 using std::cout;
00028 using std::map;
00029 using std::vector;
00030
00031 CVSID("$Id: MeuReco.cxx,v 1.9 2007/05/09 14:08:38 hartnell Exp $");
00032
00033
00034
00035 MeuReco::MeuReco()
00036 {
00037 MSG("MeuReco",Msg::kDebug)
00038 <<"Running MeuReco Constructor..."<<endl;
00039
00040
00041 MSG("MeuReco",Msg::kDebug)
00042 <<"Finished MeuReco Constructor"<<endl;
00043 }
00044
00045
00046
00047 MeuReco::~MeuReco()
00048 {
00049 MSG("MeuReco",Msg::kDebug)
00050 <<"Running MeuReco Destructor..."<<endl;
00051
00052
00053 MSG("MeuReco",Msg::kDebug)
00054 <<"Finished MeuReco Destructor"<<endl;
00055 }
00056
00057
00058
00059 Bool_t MeuReco::CalcPosOfGaps
00060 (MeuSummary& s,std::map<Int_t,MeuHitInfo>& plInfo) const
00061 {
00062
00063
00064
00065 Msg::LogLevel_t logLevel=Msg::kDebug;
00066
00067 MAXMSG("MeuReco",logLevel,1000)
00068 <<endl<<"CalcPosOfGaps: Trying to fill gaps"
00069 <<", track:"<<s.VtxPlane<<"->"<<s.EndPlane
00070 <<", minPlane2="<<s.MinPlane2<<", maxPlane2="<<s.MaxPlane2
00071 <<", minPlane3="<<s.MinPlane3<<", maxPlane3="<<s.MaxPlane3
00072 <<endl;
00073
00074 Float_t initValue=-999;
00075 Bool_t posDir=(s.EndPlane>s.VtxPlane);
00076 Bool_t allGapsFilled=true;
00077
00078
00079 Int_t pl=s.VtxPlane;
00080 Int_t tmpEndPlane=s.EndPlane;
00081 if (posDir) tmpEndPlane+=1;
00082 else tmpEndPlane-=1;
00083
00084
00085
00086 while (pl!=tmpEndPlane){
00087
00088 MeuHitInfo& cp=plInfo[pl];
00089
00090 MAXMSG("MeuReco",logLevel,1000)
00091 <<"first: pl="<<cp.Plane<<", cp.z="<<cp.Z
00092 <<endl;
00093
00094
00095 VldTimeStamp vldts;
00096
00097 VldContext vc
00098 (static_cast<Detector::Detector_t>(s.Detector),
00099 static_cast<SimFlag::ESimFlag>(s.SimFlag),vldts);
00100
00101 UgliGeomHandle ugh(vc);
00102 PlexPlaneId plidScint
00103 (static_cast<Detector::Detector_t>(s.Detector),pl);
00104 Float_t zScint=ugh.GetScintPlnHandle(plidScint).GetZ0();
00105 MAXMSG("MeuReco",logLevel,1000)
00106 <<", zScint="<<zScint<<endl;
00107
00108 cp.Z=zScint;
00109
00110 cp.Plane=pl;
00111
00112
00113 PlaneView::PlaneView_t pv=PlaneView::kUnknown;
00114 pv=ugh.GetScintPlnHandle(plidScint).GetPlaneView();
00115 cp.View=pv;
00116
00117 if (posDir) pl++;
00118 else pl--;
00119 }
00120
00121 MAXMSG("MeuReco",logLevel,1000)
00122 <<"CalcPosOfGaps: second loop"<<endl;
00123
00127
00128
00129 pl=s.VtxPlane;
00130 if (posDir) pl+=2;
00131 else pl-=2;
00132 tmpEndPlane=s.EndPlane;
00133 if (posDir) tmpEndPlane-=1;
00134 else tmpEndPlane+=1;
00135
00136
00137
00138 while (pl!=tmpEndPlane){
00139 MeuHitInfo& cp=plInfo[pl];
00140
00141 if (cp.TPos<=initValue) {
00142
00143 MeuHitInfo& cpA=plInfo[pl+2];
00144 MeuHitInfo& cpB=plInfo[pl-2];
00145
00146 if (cpA.TPos<=initValue || cpB.TPos<=initValue) {
00147 MAXMSG("MeuReco",Msg::kVerbose,1000)
00148 <<"Gap too big to fill by simple average of neighbours, pl="
00149 <<cp.Plane<<endl;
00150 allGapsFilled=false;
00151 }
00152 else{
00153 Float_t avTPos=(cpA.TPos+cpB.TPos)*0.5;
00154 cp.TPos=avTPos;
00155 }
00156 }
00157
00158 if (posDir) pl++;
00159 else pl--;
00160 }
00161
00162
00163
00164
00165 Int_t plNearVtx=s.VtxPlane-1;
00166 if (posDir) plNearVtx=s.VtxPlane+1;
00167 Int_t plNearEnd=s.EndPlane+1;
00168 if (posDir) plNearEnd=s.EndPlane-1;
00169
00170
00171 Bool_t foundVtxGap=false;
00172 if (plInfo[plNearVtx].TPos<=initValue){
00173 foundVtxGap=true;
00174 }
00175 Bool_t foundEndGap=false;
00176 if (plInfo[plNearEnd].TPos<=initValue){
00177 foundEndGap=true;
00178 }
00179 if (foundVtxGap || foundEndGap) allGapsFilled=false;
00180
00181 return allGapsFilled;
00182 }
00183
00184
00185
00186 Bool_t MeuReco::CalcPosOfBigGaps
00187 (MeuSummary& s,std::map<Int_t,MeuHitInfo>& plInfo) const
00188 {
00189
00190
00191 MAXMSG("MeuReco",Msg::kDebug,1000)
00192 <<endl<<"CalcPosOfBigGaps: Trying to fill big gap"<<endl;
00193
00194 Float_t initValue=-999;
00195 Bool_t posDir=(s.EndPlane>s.VtxPlane);
00196 Bool_t allGapsFilled=true;
00197
00198
00199 Int_t pl=s.VtxPlane;
00200
00201
00202
00203
00204
00205 while (pl!=s.EndPlane){
00206
00207 MAXMSG("MeuReco",Msg::kVerbose,10000)
00208 <<"pl="<<pl<<", track:"<<s.VtxPlane<<"->"<<s.EndPlane<<endl;
00209
00210 MeuHitInfo& cp=plInfo[pl];
00211 if (cp.TPos<=initValue) {
00212
00213 MAXMSG("MeuReco",Msg::kDebug,1000)
00214 <<"plane="<<pl<<" has no tpos"
00215 <<", track:"<<s.VtxPlane<<"->"<<s.EndPlane<<endl;
00216 allGapsFilled=false;
00217 if (posDir) pl++;
00218 else pl--;
00219 continue;
00220 }
00221
00222
00223 Int_t nextPlane=pl;
00224 if (posDir) nextPlane+=2;
00225 else nextPlane-=2;
00226 Bool_t beyondEndPlane=(nextPlane<s.EndPlane);
00227 if (posDir) beyondEndPlane=(nextPlane>s.EndPlane);
00228 if (beyondEndPlane) {
00229 MAXMSG("MeuReco",Msg::kDebug,1000)
00230 <<"Reached end of track. nextPlane="<<nextPlane
00231 <<", track:"<<s.VtxPlane<<"->"<<s.EndPlane<<endl;
00232 break;
00233 }
00234
00235 MeuHitInfo* cpGap=&plInfo[nextPlane];
00236 MeuHitInfo* cpAfterGap=0;
00237
00238
00239 if (cpGap->TPos<=initValue){
00240
00241 MAXMSG("MeuReco",Msg::kDebug,1000)
00242 <<"Found a big gap in plane="<<nextPlane<<endl;
00243
00244 Bool_t foundGoodTPos=false;
00245
00246
00247 for (Int_t iteration=0;iteration<100000;iteration++){
00248 if (posDir) nextPlane+=2;
00249 else nextPlane-=2;
00250
00251 Bool_t beyondEndPlane=(nextPlane<s.EndPlane);
00252 if (posDir) beyondEndPlane=(nextPlane>s.EndPlane);
00253 if (beyondEndPlane) {
00254
00255 MAXMSG("MeuReco",Msg::kDebug,1000)
00256 <<"Iterated beyond the end plane in track:"
00257 <<s.VtxPlane<<"->"<<s.EndPlane<<endl;
00258 allGapsFilled=false;
00259 break;
00260 }
00261
00262
00263 cpAfterGap=&plInfo[nextPlane];
00264 if (cpAfterGap->TPos<=initValue) {
00265 MAXMSG("MeuReco",Msg::kDebug,1000)
00266 <<"Found another gap on iteration="<<iteration
00267 <<", in plane="<<nextPlane<<endl;
00268 continue;
00269 }
00270 else{
00271 MAXMSG("MeuReco",Msg::kDebug,1000)
00272 <<"Found next plane with good tpos, pl="<<nextPlane
00273 <<", iteration="<<iteration<<endl;
00274 foundGoodTPos=true;
00275 break;
00276 }
00277 }
00278
00279 if (foundGoodTPos){
00280
00281
00282
00283
00284 MeuHitInfo& cp1=cp;
00285 MeuHitInfo& cp2=*cpAfterGap;
00286 Float_t m=(cp1.TPos-cp2.TPos)/(cp1.Z-cp2.Z);
00287
00288 Float_t tpos=(cpGap->Z-cp2.Z)*m+cp2.TPos;
00289 if (cpGap) cpGap->TPos=tpos;
00290 else {
00291 MAXMSG("MeuReco",Msg::kWarning,1000)
00292 <<"Ahhhhh, not found a cp for after gap"<<endl;
00293 allGapsFilled=false;
00294 }
00295
00296 MAXMSG("MeuReco",Msg::kDebug,1000)
00297 <<"Doing interpolation:"<<endl
00298 <<"Point1: tpos="<<cp1.TPos<<", z="<<cp1.Z<<endl
00299 <<" gap sizes: ="<<cp1.TPos-cpGap->TPos
00300 <<", z="<<cp1.Z-cpGap->Z<<endl
00301 <<"Interp point: tpos="<<cpGap->TPos<<", z="<<cpGap->Z<<endl
00302 <<" gap sizes: ="<<cpGap->TPos-cp2.TPos
00303 <<", ="<<cpGap->Z-cp2.Z<<endl
00304 <<"Point2: tpos="<<cp2.TPos<<", z="<<cp2.Z<<endl
00305 <<endl;
00306
00307
00308
00309
00310
00311
00312 }
00313 }
00314 else {
00315 MAXMSG("MeuReco",Msg::kDebug,5000)
00316 <<"Big gap search: no gap in plane="<<nextPlane<<endl;
00317 }
00318
00319 if (posDir) pl++;
00320 else pl--;
00321 }
00322
00323 MAXMSG("MeuReco",Msg::kDebug,5000)
00324 <<"CalcPosOfBigGaps: End of big gap search"<<endl<<endl;
00325 return allGapsFilled;
00326 }
00327
00328
00329
00330 Bool_t MeuReco::CalcPosOfTrkEndGaps
00331 (MeuSummary& s,std::map<Int_t,MeuHitInfo>& plInfo) const
00332 {
00333
00334
00335
00336
00337
00338
00339 Msg::LogLevel_t logLevel=Msg::kDebug;
00340
00341 MAXMSG("MeuReco",logLevel,1000)
00342 <<endl<<"CalcPosOfTrkEndGaps: Trying to fill trk end gap"
00343 <<", track:"<<s.VtxPlane<<"->"<<s.EndPlane<<endl;
00344
00345 Float_t initValue=-999;
00346 Bool_t posDir=(s.EndPlane>s.VtxPlane);
00347 Bool_t allGapsFilled=true;
00348
00349
00350 Int_t plNearVtx=s.VtxPlane-1;
00351 if (posDir) plNearVtx=s.VtxPlane+1;
00352 Int_t plNearEnd=s.EndPlane+1;
00353 if (posDir) plNearEnd=s.EndPlane-1;
00354
00355
00356 Bool_t foundVtxGap=false;
00357 if (plInfo[plNearVtx].TPos<=initValue){
00358 foundVtxGap=true;
00359 }
00360 Bool_t foundEndGap=false;
00361 if (plInfo[plNearEnd].TPos<=initValue){
00362 foundEndGap=true;
00363 }
00364
00365 MAXMSG("MeuReco",logLevel,1000)
00366 <<"foundVtxGap="<<foundVtxGap<<", plNearVtx="<<plNearVtx<<endl
00367 <<"foundEndGap="<<foundEndGap<<", plNearEnd="<<plNearEnd<<endl;
00368
00369
00370
00371
00372 for (Int_t i=0;i<2;i++){
00373 Bool_t movingTowardsEnd=true;
00374 if (i==1) movingTowardsEnd=false;
00375
00376
00377 if (movingTowardsEnd){
00378 if (!foundEndGap) {
00379 MAXMSG("MeuReco",logLevel,1000)
00380 <<"No gap at end of track, so not entering loop"<<endl;
00381 continue;
00382 }
00383 }
00384 else{
00385 if (!foundVtxGap) {
00386 MAXMSG("MeuReco",logLevel,1000)
00387 <<"No gap at vtx of track, so not entering loop"<<endl;
00388 continue;
00389 }
00390 }
00391
00392 MeuHitInfo* cpA=0;
00393 MeuHitInfo* cpB=0;
00394
00395
00396 Int_t pl=(s.VtxPlane+s.EndPlane)/2;
00397
00398 if (!movingTowardsEnd){
00399 if (pl%2!=plNearVtx%2) pl++;
00400 }
00401 else{
00402 if (pl%2!=plNearEnd%2) pl++;
00403 }
00404
00405
00406
00407 Int_t plBeyondEnd=plNearEnd-2;
00408 if (posDir) plBeyondEnd=plNearEnd+2;
00409 Int_t plBeyondVtx=plNearVtx+2;
00410 if (posDir) plBeyondVtx=plNearVtx-2;
00411
00412 Int_t lastLoopPlane=plBeyondEnd;
00413 if (!movingTowardsEnd) lastLoopPlane=plBeyondVtx;
00414
00415 MAXMSG("MeuReco",logLevel,1000)
00416 <<"Starting on pl="<<pl
00417 <<" and working towards pl="<<lastLoopPlane
00418 <<", movingTowardsEnd="<<movingTowardsEnd<<endl;
00419
00420
00421
00422 while (pl!=lastLoopPlane){
00423
00424 MAXMSG("MeuReco",logLevel,1000)
00425 <<"CalcPosOfTrkEndGaps: pl="<<pl
00426 <<", track:"<<s.VtxPlane<<"->"<<s.EndPlane<<endl;
00427
00428 MeuHitInfo* cp=&plInfo[pl];
00429 if (cp->TPos<=initValue){
00430 MAXMSG("MeuReco",logLevel,1000)
00431 <<"Found gap at pl="<<pl<<endl;
00432 allGapsFilled=false;
00433
00434
00435 if (cpA!=0 && cpB!=0){
00436
00437
00438
00439
00440
00441 MeuHitInfo& cp1=*cpA;
00442 MeuHitInfo& cp2=*cpB;
00443 MeuHitInfo* cpGap=cp;
00444 Float_t m=(cp1.TPos-cp2.TPos)/(cp1.Z-cp2.Z);
00445
00446 Float_t tpos=(cpGap->Z-cp2.Z)*m+cp2.TPos;
00447 if (cpGap) {
00448 cpGap->TPos=tpos;
00449
00450 allGapsFilled=true;
00451 }
00452 else {
00453 MAXMSG("MeuReco",Msg::kWarning,1000)
00454 <<"Ahhhhh, not found a cp for after gap"<<endl;
00455 allGapsFilled=false;
00456 }
00457
00458 MAXMSG("MeuReco",logLevel,1000)
00459 <<"Doing interpolation:"<<endl
00460 <<"Point1: tpos="<<cp1.TPos<<", z="<<cp1.Z<<endl
00461 <<" gap sizes: ="<<cp1.TPos-cpGap->TPos
00462 <<", z="<<cp1.Z-cpGap->Z<<endl
00463 <<"Interp point: tpos="<<cpGap->TPos
00464 <<", z="<<cpGap->Z<<endl
00465 <<" gap sizes: ="<<cpGap->TPos-cp2.TPos
00466 <<", ="<<cpGap->Z-cp2.Z<<endl
00467 <<"Point2: tpos="<<cp2.TPos<<", z="<<cp2.Z<<endl
00468 <<endl;
00469
00470 VldTimeStamp vldts;
00471
00472 VldContext vc
00473 (static_cast<Detector::Detector_t>(s.Detector),
00474 static_cast<SimFlag::ESimFlag>(s.SimFlag),vldts);
00475
00476 UgliGeomHandle ugh(vc);
00477
00478
00479 Float_t tmin=-1;
00480 Float_t tmax=-1;
00481 PlexPlaneId plidScint
00482 (static_cast<Detector::Detector_t>(s.Detector),
00483 pl);
00484 PlaneView::PlaneView_t pv=PlaneView::kUnknown;
00485 pv=ugh.GetScintPlnHandle(plidScint).GetPlaneView();
00486 string sPv="";
00487
00488 ugh.GetTransverseExtent(pv,tmin,tmax);
00489 MAXMSG("MeuReco",Msg::kVerbose,1000)
00490 <<"pl="<<pl<<", view="<<sPv<<endl
00491
00492 <<"Got TransverseExtent, min="<<tmin<<", max="<<tmax<<endl;
00493
00494 if (tpos>tmax || tpos<tmin){
00495 Float_t tposToUse=tmax;
00496 if (tpos<0) tposToUse=tmin;
00497
00498 MAXMSG("MeuReco",logLevel,1000)
00499 <<endl<<"Interpolated out of the detector: tpos="<<tpos
00500 <<", capping the value at "<<tposToUse<<endl
00501 <<"TransverseExtent: min="<<tmin<<", max="<<tmax
00502 <<endl;
00503
00504 cpGap->TPos=tposToUse;
00505 allGapsFilled=true;
00506 }
00507 }
00508 }
00509 else{
00510 MAXMSG("MeuReco",logLevel,1000)
00511 <<"Found good tpos in plane="<<pl<<endl;
00512 cpB=cpA;
00513 cpA=cp;
00514 }
00515
00516 if (movingTowardsEnd) {
00517
00518 if (posDir) pl+=2;
00519 else pl-=2;
00520 }
00521 else{
00522
00523 if (posDir) pl-=2;
00524 else pl+=2;
00525 }
00526 }
00527 }
00528
00529 Bool_t warningUnfilledGaps=false;
00530
00531 if (!allGapsFilled) {
00532 MAXMSG("MeuReco",Msg::kDebug,1000)
00533 <<"Failed to fill all gaps"<<endl;
00534 }
00535 else{
00536
00537 Int_t pl=s.VtxPlane;
00538 Int_t tmpEndPlane=s.EndPlane;
00539 if (posDir) tmpEndPlane+=1;
00540 else tmpEndPlane-=1;
00541
00542
00543
00544 while (pl!=tmpEndPlane){
00545 MeuHitInfo& cp=plInfo[pl];
00546 if (cp.TPos<=initValue){
00547 MAXMSG("MeuReco",Msg::kWarning,20)
00548 <<endl<<endl<<"**** Found unfilled gap! ****"<<endl<<endl;
00549 warningUnfilledGaps=true;
00550 allGapsFilled=false;
00551 }
00552
00553 if (posDir) pl++;
00554 else pl--;
00555 }
00556 }
00557
00558 if (warningUnfilledGaps){
00559 MAXMSG("MeuReco",Msg::kInfo,20)
00560 <<"Event="<<s.Event<<", run="<<s.Run<<", fSnarl="<<s.Snarl
00561 <<endl;
00562 Int_t pl=s.VtxPlane;
00563 Int_t tmpEndPlane=s.EndPlane;
00564 if (posDir) tmpEndPlane+=1;
00565 else tmpEndPlane-=1;
00566
00567
00568 while (pl!=tmpEndPlane){
00569 MeuHitInfo& cp=plInfo[pl];
00570 MAXMSG("MeuReco",Msg::kInfo,100)
00571 <<"pl="<<cp.Plane<<", st="<<cp.Strip<<", view="<<cp.View
00572 <<", sigCor="<<cp.SigCor
00573 <<", t="<<cp.TPos<<", l="<<cp.LPos<<endl;
00574
00575 if (posDir) pl++;
00576 else pl--;
00577 }
00578 }
00579
00580 MAXMSG("MeuReco",logLevel,1000)
00581 <<"CalcPosOfTrkEndGaps: End of trk end gap search"<<endl;
00582 return allGapsFilled;
00583 }
00584
00585
00586
00587 void MeuReco::CalcPLCor(MeuSummary& s,
00588 std::map<Int_t,MeuHitInfo>& plInfo) const
00589 {
00590
00591 Msg::LogLevel_t logLevel=Msg::kDebug;
00592 Msg::LogLevel_t logLevel2=Msg::kDebug;
00593
00594 MAXMSG("MeuReco",logLevel,1000)
00595 <<endl<<"CalcPLCor: Get path length correction, track: "
00596 <<s.VtxPlane<<"->"<<s.EndPlane<<endl;
00597
00598 Float_t initValue=-999;
00599 Bool_t posDir=(s.EndPlane>s.VtxPlane);
00600 static Int_t event=0;
00601 event++;
00602
00603
00604 Int_t pl=s.VtxPlane;
00605 Int_t tmpEndPlane=s.EndPlane;
00606 if (posDir) tmpEndPlane++;
00607 else tmpEndPlane--;
00608
00609
00610 while (pl!=tmpEndPlane){
00611 MAXMSG("MeuReco",Msg::kVerbose,1000)
00612 <<"pl="<<pl<<endl;
00613
00614
00615 MeuHitInfo& cp=plInfo[pl];
00616
00617
00618
00619
00620 Int_t nextPlane=pl;
00621 if (posDir) nextPlane+=2;
00622 else nextPlane-=2;
00623
00624 Bool_t beyondEndPlane=(nextPlane<s.EndPlane);
00625 if (posDir) beyondEndPlane=(nextPlane>s.EndPlane);
00626 if (beyondEndPlane) {
00627 MAXMSG("MeuReco",logLevel2,1000)
00628 <<"pl+2="<<nextPlane<<", gone beyond the end plane in track: "
00629 <<s.VtxPlane<<"->"<<s.EndPlane<<endl;
00630
00631
00632 nextPlane=pl;
00633 if (posDir) nextPlane+=1;
00634 else nextPlane-=1;
00635 beyondEndPlane=(nextPlane<s.EndPlane);
00636 if (posDir) beyondEndPlane=(nextPlane>s.EndPlane);
00637
00638 if (beyondEndPlane) {
00639 MAXMSG("MeuReco",logLevel2,1000)
00640 <<"pl+1="<<nextPlane<<", gone beyond the end plane in track: "
00641 <<s.VtxPlane<<"->"<<s.EndPlane<<endl;
00642 nextPlane=pl;
00643 }
00644 else{
00645 MAXMSG("MeuReco",logLevel2,1000)
00646 <<"pl+1="<<nextPlane<<", is ok for track: "
00647 <<s.VtxPlane<<"->"<<s.EndPlane<<endl;
00648 }
00649 }
00650
00651
00652 Int_t prevPlane=pl;
00653 if (posDir) prevPlane-=2;
00654 else prevPlane+=2;
00655
00656 Bool_t beyondVtxPlane=(prevPlane>s.VtxPlane);
00657 if (posDir) beyondVtxPlane=(prevPlane<s.VtxPlane);
00658 if (beyondVtxPlane) {
00659 MAXMSG("MeuReco",logLevel2,1000)
00660 <<"pl+2="<<prevPlane<<", gone beyond the end plane in track: "
00661 <<s.VtxPlane<<"->"<<s.EndPlane<<endl;
00662
00663
00664 prevPlane=pl;
00665 if (posDir) prevPlane-=1;
00666 else prevPlane+=1;
00667 beyondVtxPlane=(prevPlane>s.VtxPlane);
00668 if (posDir) beyondVtxPlane=(prevPlane<s.VtxPlane);
00669
00670 if (beyondVtxPlane) {
00671 MAXMSG("MeuReco",logLevel2,1000)
00672 <<"pl+1="<<prevPlane<<", gone beyond the end plane in track: "
00673 <<s.VtxPlane<<"->"<<s.EndPlane<<endl;
00674 prevPlane=pl;
00675 }
00676 else{
00677 MAXMSG("MeuReco",logLevel2,1000)
00678 <<"pl+1="<<prevPlane<<", is ok for track: "
00679 <<s.VtxPlane<<"->"<<s.EndPlane<<endl;
00680 }
00681 }
00682
00683 MAXMSG("MeuReco",logLevel2,1000)
00684 <<"For pl="<<pl<<" using planes: "<<prevPlane<<"->"<<nextPlane
00685 <<endl;
00686
00687
00688
00689
00690 TGraph gx_z(3);
00691 TGraph gy_z(3);
00692 Int_t tmpPl=prevPlane;
00693 Int_t tmpPlEnd=nextPlane-1;
00694 if (posDir) tmpPlEnd=nextPlane+1;
00695 Int_t i=0;
00696
00697 while (tmpPl!=tmpPlEnd){
00698 MeuHitInfo& tmpcp=plInfo[tmpPl];
00699
00700 Float_t x=tmpcp.X;
00701 Float_t y=tmpcp.Y;
00702 Float_t z=tmpcp.Z;
00703 gx_z.SetPoint(i,z,x);
00704 gy_z.SetPoint(i,z,y);
00705 MAXMSG("MeuReco",Msg::kVerbose,1000)
00706 <<"Adding points to graphs: x="<<x<<", y="<<y<<", z="<<z<<endl;
00707
00708 i++;
00709
00710 if (posDir) tmpPl++;
00711 else tmpPl--;
00712 }
00713
00714
00715 Double_t PLCorMC=-1;
00716 Double_t pathLength=-1;
00717 if (pathLength>=0){
00718 static Double_t lastPL=1.3*Munits::cm;
00719
00720 if (pathLength<=0) pathLength=lastPL;
00721 lastPL=pathLength;
00722
00723 PLCorMC=pathLength/(0.95*Munits::cm);
00724 }
00725
00726 Float_t PLCor=initValue;
00727 if (i>=3){
00728 gx_z.Fit("pol1","q");
00729 gy_z.Fit("pol1","q");
00730 Float_t mx_z=gx_z.GetFunction("pol1")->GetParameter(1);
00731 Float_t my_z=gy_z.GetFunction("pol1")->GetParameter(1);
00732
00733
00734
00735 PLCor=sqrt(pow(mx_z,2)+pow(my_z,2)+1);
00736 MAXMSG("MeuReco",logLevel,1000)
00737 <<"pl="<<pl<<", reconstructed PLCor="<<PLCor
00738 <<", MC PLCor="<<PLCorMC
00739 <<endl;
00740
00741 cp.PLCor=PLCor;
00742 }
00743 else {
00744 MSG("MeuReco",Msg::kWarning)
00745 <<"Less than 3 points, can't do local grad. fit"<<endl;
00746 }
00747
00748 if (posDir) pl++;
00749 else pl--;
00750 }
00751 }
00752
00753
00754
00755 void MeuReco::CalcMEU(MeuSummary& s,
00756 std::map<Int_t,MeuHitInfo>& plInfo) const
00757 {
00758
00759 Msg::LogLevel_t logLevel=Msg::kDebug;
00760
00761 MAXMSG("MeuReco",logLevel,1000)
00762 <<endl<<"CalcMEU: Get the MEU, track: "
00763 <<s.VtxPlane<<"->"<<s.EndPlane<<endl;
00764
00765
00766 Bool_t posDir=(s.EndPlane>s.VtxPlane);
00767
00768
00769
00770 Float_t meuSigLinOnly=0;
00771 Float_t meuSigDrf=0;
00772 Float_t meuAdc=0;
00773 Float_t meuPe=0;
00774 Float_t meuSigLin=0;
00775 Float_t meuSigCor=0;
00776 Float_t meuSigMap=0;
00777 Float_t meuNumDigits=0;
00778 Float_t meuNumStrips=0;
00779 Float_t meuEnDep=0;
00780 Float_t meuSigMap_MeV=0;
00781 Float_t meuSigCor_MeV=0;
00782 Float_t sigCorSum=0;
00783 Float_t sigMapSum=0;
00784 Float_t enDepSum=0;
00785 Float_t materialFromTrkEnd=0;
00786 Float_t materialInWindow=0;
00787 Int_t winCounter=0;
00788 Float_t avPLCor=0;
00789 Int_t winStopSidePl=-1;
00790 Int_t winVtxSidePl=-1;
00791
00792 const Float_t material01Pl=(5.94)*Munits::cm;
00793 const Float_t material16Pl=16*material01Pl;
00794 const Float_t material14Pl=14*material01Pl;
00795 MAXMSG("MeuReco",Msg::kInfo,1)
00796 <<endl<<"Using 14 pls material="<<material14Pl
00797 <<", 16 plns="<<material16Pl
00798 <<", 1 plns="<<material01Pl<<endl;
00799
00800
00801 if (s.EndPlane>=0){
00802
00803
00804
00805 Int_t pl=s.EndPlane;
00806 Int_t tmpVtxPlane=s.VtxPlane;
00807 if (posDir) tmpVtxPlane--;
00808 else tmpVtxPlane++;
00809
00810
00811 while (pl!=tmpVtxPlane){
00812
00813
00814 MeuHitInfo& cp=plInfo[pl];
00815 Float_t PLCor=cp.PLCor;
00816 Float_t plMaterial=PLCor*material01Pl;
00817
00818
00819
00820
00821
00822 if ((materialFromTrkEnd>material16Pl ||
00823 materialFromTrkEnd+plMaterial>material16Pl) &&
00824 materialInWindow<material14Pl){
00825
00826
00827 if (winStopSidePl<0) {
00828 winStopSidePl=pl;
00829 }
00830 winVtxSidePl=pl;
00831
00832
00833 materialInWindow+=plMaterial;
00834
00835
00836 avPLCor+=PLCor;
00837
00838
00839 meuSigLinOnly+=cp.SigLinOnly/PLCor;
00840 meuSigDrf+=cp.SigDrf/PLCor;
00841 meuAdc+=cp.Adc/PLCor;
00842 meuPe+=cp.Pe/PLCor;
00843 meuSigLin+=cp.SigLin/PLCor;
00844 meuSigCor+=cp.SigCor/PLCor;
00845 meuSigMap+=cp.SigMap/PLCor;
00846 meuNumDigits+=cp.NumDigits;
00847 meuNumStrips+=cp.NumStrips;
00848
00849 if (cp.MCEnDep>0) meuEnDep+=cp.MCEnDep/PLCor;
00850
00851 sigCorSum+=cp.SigCor;
00852 sigMapSum+=cp.SigMap;
00853 enDepSum+=cp.MCEnDep;
00854 winCounter++;
00855 }
00856
00857 materialFromTrkEnd+=plMaterial;
00858
00859 MAXMSG("MeuReco",logLevel,1000)
00860 <<"plMat="<<plMaterial
00861 <<", matTrk="<<materialFromTrkEnd<<" (of "<<material16Pl<<")"
00862 <<", matWin="<<materialInWindow<<" (of "<<material14Pl<<")"
00863 <<endl
00864 <<"meuSigMap="<<meuSigMap<<", PLCor="<<PLCor<<endl;
00865
00866
00867 if (posDir) pl--;
00868 else pl++;
00869 }
00870 }
00871 else{
00872 MAXMSG("MeuReco",Msg::kWarning,1000)
00873 <<"Can't CalcMEU: fEndPlane="<<s.EndPlane
00874 <<", vtxPl="<<s.VtxPlane<<endl;
00875 }
00876
00877
00878 s.TotalMatTraversed=materialFromTrkEnd;
00879
00880
00881 if (materialInWindow>material14Pl){
00882
00883 if (winCounter>0){
00884 meuSigLinOnly/=winCounter;
00885 meuSigDrf/=winCounter;
00886 meuAdc/=winCounter;
00887 meuPe/=winCounter;
00888 meuSigLin/=winCounter;
00889 meuSigCor/=winCounter;
00890 meuSigMap/=winCounter;
00891 meuNumDigits/=winCounter;
00892 meuNumStrips/=winCounter;
00893 meuEnDep/=winCounter;
00894
00895 if (enDepSum>0){
00896 meuSigMap_MeV=sigMapSum/(enDepSum/Munits::MeV);
00897 meuSigCor_MeV=sigCorSum/(enDepSum/Munits::MeV);
00898 }
00899
00900 avPLCor/=winCounter;
00901
00902
00903 s.WinSigLinOnly=meuSigLinOnly;
00904 s.WinSigDrf=meuSigDrf;
00905 s.WinAdc=meuAdc;
00906 s.WinPe=meuPe;
00907 s.WinSigLin=meuSigLin;
00908 s.WinSigCor=meuSigCor;
00909 s.WinSigMap=meuSigMap;
00910 s.WinAvNumDigits=meuNumDigits;
00911 s.WinAvNumStrips=meuNumStrips;
00912 s.MCWinEnDep=meuEnDep;
00913
00914 s.MCWinSigCor_MeV=meuSigCor_MeV;
00915 s.MCWinSigMap_MeV=meuSigMap_MeV;
00916
00917
00918 s.WinAvPLCor=avPLCor;
00919 s.WinAvCosThetaZ=1./s.WinAvPLCor;
00920 if (!posDir) s.WinAvCosThetaZ*=-1;
00921 s.WinStopSidePl=winStopSidePl;
00922 s.WinVtxSidePl=winVtxSidePl;
00923 }
00924 }
00925
00926 }
00927
00928
00929
00930 void MeuReco::PrintMeuHitInfo
00931 (const std::map<Int_t,MeuHitInfo>& plInfo) const
00932 {
00933 Msg::LogLevel_t logLevel=Msg::kInfo;
00934
00935 for (map<Int_t,MeuHitInfo>::const_iterator it=plInfo.begin();
00936 it!=plInfo.end();++it){
00937
00938 const MeuHitInfo& cp=it->second;
00939
00940 MAXMSG("MeuReco",logLevel,1000)
00941 <<"Print: pl="<<cp.Plane<<", st="<<cp.Strip
00942 <<", view="<<cp.View
00943 <<", LPos="<<cp.LPos
00944 <<", TPos="<<cp.TPos
00945 <<endl;
00946 }
00947 }
00948
00949
00950
00951 void MeuReco::PrintMeuHitInfoFull
00952 (const std::map<Int_t,MeuHitInfo>& plInfo) const
00953 {
00954 Msg::LogLevel_t logLevel=Msg::kInfo;
00955
00956 MSG("MeuReco",logLevel)<<"Printing full MeuHitInfo:"<<endl;
00957
00958 for (map<Int_t,MeuHitInfo>::const_iterator it=plInfo.begin();
00959 it!=plInfo.end();++it){
00960
00961 const MeuHitInfo& cp=it->second;
00962
00963 MSG("MeuReco",logLevel)
00964 <<"pl="<<cp.Plane<<", st="<<cp.Strip
00965 <<", view="<<cp.View
00966 <<", T="<<cp.TPos<<", L="<<cp.LPos
00967 <<", PLCor="<<cp.PLCor
00968 <<", xyz="<<cp.X<<","<<cp.Y<<","<<cp.Z
00969 <<endl
00970 <<"ADC: "<<cp.Adc<<" ("<<cp.Adc1<<","<<cp.Adc2<<")"
00971 <<", SigLin: "<<cp.SigLin
00972 <<" ("<<cp.SigLin1<<","<<cp.SigLin2<<")"
00973 <<endl
00974 <<"PE: "<<cp.Pe<<" ("<<cp.Pe1<<","<<cp.Pe2<<")"
00975 <<endl
00976 <<"SigCor: "<<cp.SigCor
00977 <<" ("<<cp.SigCor1<<","<<cp.SigCor2<<")"
00978 <<"SigCorTrk: "<<-1
00979 <<" ("<<cp.SigCorTrk1<<","<<cp.SigCorTrk2<<")"
00980 <<endl
00981 <<"SigMap: "<<cp.SigMap
00982 <<" ("<<cp.SigMap<<","<<cp.SigMap<<")"
00983 <<", MCSigMap: "<<cp.MCSigMap
00984 <<endl
00985 <<"MCEnDep="<<cp.MCEnDep
00986 <<", MCSuppEnDep="<<cp.MCSuppEnDep
00987 <<endl;
00988 }
00989 }
00990
00991
00992
00993 void MeuReco::PrintMeuSummary(const MeuSummary& s) const
00994 {
00995 Msg::LogLevel_t logLevel=Msg::kInfo;
00996
00997 MSG("MeuReco",logLevel)
00998 <<"Printing full MeuHitInfo:"<<endl
00999 <<"fCount"<<s.Count<<endl
01000 <<"fTemperature"<<s.Temperature<<endl
01001
01002 <<"fEvent"<<s.Event<<endl
01003 <<"fRun"<<s.Run<<endl
01004 <<"fSubRun"<<s.SubRun<<endl
01005 <<"fTimeSec"<<s.TimeSec<<endl
01006 <<"fSnarl"<<s.Snarl<<endl
01007 <<"fNStrip"<<s.NStrip<<endl
01008
01009 <<"fGoodContainment"<<s.GoodContainment<<endl
01010 <<"fGoodWindow"<<s.GoodWindow<<endl
01011
01012 <<"fSM1"<<s.SM1<<endl
01013 <<"fSM2"<<s.SM2<<endl
01014 <<"fSMBoth"<<s.SMBoth<<endl
01015
01016 <<"fEntSM1Front"<<s.EntSM1Front<<endl
01017 <<"fEntSM1Back"<<s.EntSM1Back<<endl
01018 <<"fEntSM2Front"<<s.EntSM2Front<<endl
01019 <<"fEntSM2Back"<<s.EntSM2Back<<endl
01020 <<"fEntSMEnd"<<s.EntSMEnd<<endl
01021
01022 <<"fExitSM1Front"<<s.ExitSM1Front<<endl
01023 <<"fExitSM1Back"<<s.ExitSM1Back<<endl
01024 <<"fExitSM2Front"<<s.ExitSM2Front<<endl
01025 <<"fExitSM2Back"<<s.ExitSM2Back<<endl
01026 <<"fExitSMEnd"<<s.ExitSMEnd<<endl
01027
01028 <<"fPC"<<s.PC<<endl
01029 <<"fFC"<<s.FC<<endl
01030 <<"fAwayFromCoil"<<s.AwayFromCoil<<endl
01031
01032 <<"fMCHighEn"<<s.MCHighEn<<endl
01033 <<"fMCLowEn"<<s.MCLowEn<<endl
01034 <<"fMCParticleId"<<s.MCParticleId<<endl
01035 <<"fRFid"<<s.RFid<<endl
01036 <<"fRFidCoil"<<s.RFidCoil<<endl
01037 <<"fRVtx"<<s.RVtx<<endl
01038 <<"fREnd"<<s.REnd<<endl
01039 <<"fVtxPlane"<<s.VtxPlane<<endl
01040 <<"fEndPlane"<<s.EndPlane<<endl
01041 <<"fMCVtxPlane"<<s.MCVtxPlane<<endl
01042 <<"fMCEndPlane"<<s.MCEndPlane<<endl;
01043 }
01044
01045
01046
01047 Bool_t MeuReco::CalcLPos(MeuSummary& s,
01048 std::map<Int_t,MeuHitInfo>& plInfo) const
01049 {
01050
01051 Msg::LogLevel_t logLevel=Msg::kDebug;
01052
01053 MAXMSG("MeuReco",logLevel,1000)
01054 <<endl<<"CalcLPos: Get position along strip, track: "
01055 <<s.VtxPlane<<"->"<<s.EndPlane<<endl;
01056
01057 Float_t initValue=-999;
01058 Bool_t posDir=(s.EndPlane>s.VtxPlane);
01059
01060
01061 Int_t pl=s.VtxPlane;
01062 if (posDir) pl+=1;
01063 else pl-=1;
01064 Int_t tmpEndPlane=s.EndPlane;
01065
01066
01067
01068 while (pl!=tmpEndPlane){
01069 MeuHitInfo& cp=plInfo[pl];
01070
01071 if (cp.LPos<=initValue) {
01072
01073 MeuHitInfo& cpA=plInfo[pl+1];
01074 MeuHitInfo& cpB=plInfo[pl-1];
01075
01076 if (cpA.TPos<=initValue || cpB.TPos<=initValue) {
01077 MAXMSG("MeuReco",Msg::kWarning,1000)
01078 <<"Found a gap, pl="<<cp.Plane
01079 <<", pl+1 tposA="<<cpA.TPos
01080 <<", pl-1 tposB="<<cpB.TPos
01081 <<endl;
01082 }
01083 else{
01084 Float_t avTPos=(cpA.TPos+cpB.TPos)*0.5;
01085 cp.LPos=avTPos;
01086 MAXMSG("MeuReco",logLevel,1000)
01087 <<"Calc LPos: pl="<<cp.Plane<<", st="<<cp.Strip
01088 <<", tposA="<<cpA.TPos
01089 <<", tposB="<<cpB.TPos
01090 <<", LPos="<<cp.LPos<<endl;
01091 }
01092 }
01093 else{
01094 MAXMSG("MeuReco",Msg::kWarning,1000)
01095 <<"LPos value already found="<<cp.LPos
01096 <<", pl="<<cp.Plane<<endl;
01097 }
01098
01099 if (posDir) pl++;
01100 else pl--;
01101 }
01102
01103
01104
01105 Int_t plNearVtxA=s.VtxPlane-1;
01106 Int_t plNearVtxB=s.VtxPlane-3;
01107 if (posDir) {
01108 plNearVtxA=s.VtxPlane+1;
01109 plNearVtxB=s.VtxPlane+3;
01110 }
01111 Int_t plNearEndA=s.EndPlane+1;
01112 Int_t plNearEndB=s.EndPlane+3;
01113 if (posDir) {
01114 plNearEndA=s.EndPlane-1;
01115 plNearEndB=s.EndPlane-3;
01116 }
01117
01118 Bool_t interpError=false;
01119
01120 MeuHitInfo& cpEnd=plInfo[s.EndPlane];
01121 MeuHitInfo& cpEndA=plInfo[plNearEndA];
01122 MeuHitInfo& cpEndB=plInfo[plNearEndB];
01123 MeuHitInfo& cpVtx=plInfo[s.VtxPlane];
01124 MeuHitInfo& cpVtxA=plInfo[plNearVtxA];
01125 MeuHitInfo& cpVtxB=plInfo[plNearVtxB];
01126
01127
01128 for (Int_t i=0;i<2;i++){
01129
01130 MeuHitInfo* cpGap=&cpVtx;
01131 MeuHitInfo* cp1=&cpVtxA;
01132 MeuHitInfo* cp2=&cpVtxB;
01133 if (i==1) {
01134 cpGap=&cpEnd;
01135 cp1=&cpEndA;
01136 cp2=&cpEndB;
01137 }
01138
01139 Int_t pl=cpGap->Plane;
01140
01141
01142
01143
01144
01145 Float_t m=(cp1->TPos-cp2->TPos)/(cp1->Z-cp2->Z);
01146
01147 Float_t tpos=(cpGap->Z-cp2->Z)*m+cp2->TPos;
01148 if (cpGap) {
01149
01150 cpGap->LPos=tpos;
01151 }
01152 else {
01153 MAXMSG("MeuReco",Msg::kWarning,1000)
01154 <<"Ahhhhh, not found a cp for after gap"<<endl;
01155 interpError=true;
01156 }
01157
01158 MAXMSG("MeuReco",logLevel,1000)
01159 <<"Doing interpolation:"<<endl
01160 <<"Point1: tpos="<<cp1->TPos<<", z="<<cp1->Z<<endl
01161 <<" gap sizes: ="<<cp1->TPos-cpGap->LPos
01162 <<", z="<<cp1->Z-cpGap->Z<<endl
01163 <<"Interp point: tpos="<<cpGap->LPos
01164 <<", z="<<cpGap->Z<<endl
01165 <<" gap sizes: ="<<cpGap->LPos-cp2->TPos
01166 <<", ="<<cpGap->Z-cp2->Z<<endl
01167 <<"Point2: tpos="<<cp2->TPos<<", z="<<cp2->Z<<endl
01168 <<endl;
01169
01170 VldTimeStamp vldts;
01171
01172 VldContext vc
01173 (static_cast<Detector::Detector_t>(s.Detector),
01174 static_cast<SimFlag::ESimFlag>(s.SimFlag),vldts);
01175
01176 UgliGeomHandle ugh(vc);
01177
01178
01179 Float_t tmin=-1;
01180 Float_t tmax=-1;
01181 PlexPlaneId plidScint
01182 (static_cast<Detector::Detector_t>(s.Detector),pl);
01183 PlaneView::PlaneView_t pv=PlaneView::kUnknown;
01184 pv=ugh.GetScintPlnHandle(plidScint).GetPlaneView();
01185 string sPv="";
01186
01187 if (cpGap->Strip<0) cout<<"Ahhhhh, bad strip="
01188 <<cpGap->Strip<<endl;
01189 PlexStripEndId seid
01190 (static_cast<Detector::Detector_t>(s.Detector),
01191 pl,cpGap->Strip,StripEnd::kWest);
01192
01193 if (!seid.IsValid()){
01194 interpError=true;
01195 MSG("MeuReco",Msg::kInfo)
01196 <<"Strip not valid: pl="<<pl<<", st="<<cpGap->Strip
01197 <<", view="<<sPv<<endl;
01198 seid.Print();
01199 break;
01200 }
01201
01202 UgliStripHandle ush=ugh.GetStripHandle(seid);
01203 Float_t halflen=ush.GetHalfLength();
01204 TVector3 localCenter(0,0,0);
01205 TVector3 localEastEnd(-halflen,0,0);
01206 TVector3 localWestEnd(+halflen,0,0);
01207
01208
01209 TVector3 xyzE = ush.LocalToGlobal(localEastEnd);
01210 TVector3 xyzW = ush.LocalToGlobal(localWestEnd);
01211
01212 TVector3 uvzE = ugh.xyz2uvz(xyzE);
01213 TVector3 uvzW = ugh.xyz2uvz(xyzW);
01214
01215
01216
01217 Float_t lposE=-999;
01218 Float_t lposW=-999;
01219 if (pv==PlaneView::kU){
01220 lposE=uvzE.Y();
01221 lposW=uvzW.Y();
01222 }
01223 else if (pv==PlaneView::kV){
01224 lposE=uvzE.X();
01225 lposW=uvzW.X();
01226 }
01227 else cout<<"ahhhhhhh"<<endl;
01228
01229
01230 Float_t lmax=lposE;
01231 Float_t lmin=lposW;
01232 if (lposE<lposW){
01233 lmin=lposE;
01234 lmax=lposW;
01235 }
01236
01237
01238 ugh.GetTransverseExtent(pv,tmin,tmax);
01239 MAXMSG("MeuReco",Msg::kVerbose,1000)
01240 <<"pl="<<pl<<", st="<<cpGap->Strip<<", view="<<sPv<<endl
01241
01242 <<"Got TransverseExtent, min="<<tmin<<", max="<<tmax<<endl
01243 <<"Got LongitudinalExtent, min="<<lmin<<", max="<<lmax<<endl;
01244
01245
01246 if (tpos>lmax || tpos<lmin){
01247 Float_t lposToUse=lmax;
01248 if (tpos<0) lposToUse=lmin;
01249
01250 Float_t newLPos=tpos;
01251
01252
01253
01254 if (fabs(lposToUse-tpos)<20*Munits::cm) {
01255
01256 newLPos=lposToUse;
01257
01258
01259 if (cpGap) {
01260
01261 cpGap->LPos=newLPos;
01262 }
01263 else {
01264 MAXMSG("MeuReco",Msg::kWarning,1000)
01265 <<"Ahhhhh, not found a cp for after gap"<<endl;
01266 interpError=true;
01267 }
01268 }
01269 else{
01270 MAXMSG("MeuReco",logLevel,1000)
01271 <<endl<<"Interpolated out of the detector significantly"
01272 <<" for trk end plane"<<endl
01273 <<"LPos="<<tpos<<", not capping the value at "
01274 <<lposToUse<<endl
01275 <<"LongitudinalExtent: min="<<lmin<<", max="<<lmax<<endl;
01276
01277
01278 interpError=true;
01279 }
01280 }
01281 }
01282
01283
01284 if (interpError){
01285 MAXMSG("MeuReco",logLevel,1000)
01286 <<"Couldn't fill LPos of track end planes"<<endl;
01287 }
01288
01289 return !interpError;
01290 }
01291
01292
01293
01294 void MeuReco::CalcStripDists
01295 (const MeuSummary& s,std::map<Int_t,MeuHitInfo>& plInfo) const
01296 {
01297
01298 Msg::LogLevel_t logLevel=Msg::kDebug;
01299
01300 MAXMSG("MeuReco",logLevel,1000)
01301 <<endl<<"CalcStripDists: Get position along strip, track: "
01302 <<s.VtxPlane<<"->"<<s.EndPlane<<endl;
01303
01304 VldTimeStamp vldts;
01305
01306 VldContext vc
01307 (static_cast<Detector::Detector_t>(s.Detector),
01308 static_cast<SimFlag::ESimFlag>(s.SimFlag),vldts);
01309
01310 UgliGeomHandle ugh(vc);
01311
01312 typedef map<Int_t,MeuHitInfo>::iterator cpIt;
01313 for (cpIt it=plInfo.begin();it!=plInfo.end();++it){
01314
01315 MeuHitInfo& cp=it->second;
01316 Int_t pl=cp.Plane;
01317
01318 PlexPlaneId plidScint
01319 (static_cast<Detector::Detector_t>(s.Detector),pl);
01320 PlaneView::PlaneView_t pv=PlaneView::kUnknown;
01321 pv=ugh.GetScintPlnHandle(plidScint).GetPlaneView();
01322 string sPv="";
01323
01324
01325 Int_t strip=ugh.GetScintPlnHandle(plidScint).
01326 GetClosestStrip(cp.TPos,cp.LPos).GetSEId().GetStrip();
01327
01328 if (cp.Strip>=0 && cp.Strip!=strip) {
01329 PlexStripEndId seidW
01330 (static_cast<Detector::Detector_t>(s.Detector),
01331 pl,strip,StripEnd::kWest);
01332 PlexStripEndId seidWOrig
01333 (static_cast<Detector::Detector_t>(s.Detector),
01334 pl,cp.Strip,StripEnd::kWest);
01335
01336 MAXMSG("MeuReco",Msg::kInfo,5)
01337 <<"Weird strip: orig="<<cp.Strip
01338 <<", ugli="<<strip
01339 <<", ugli2="<<ugh.GetScintPlnHandle(plidScint).
01340 GetClosestStrip(cp.TPos).GetSEId().GetStrip()
01341 <<", pl="<<pl<<endl
01342 <<"tposOrig="<<ugh.GetStripHandle(seidWOrig).GetTPos()
01343 <<", tposNew="<<ugh.GetStripHandle(seidW).GetTPos()
01344 <<", tposNtp="<<cp.TPos<<endl;
01345 strip=cp.Strip;
01346 }
01347
01348
01349 cp.StripBestGuess=strip;
01350
01351 PlexStripEndId seidW
01352 (static_cast<Detector::Detector_t>(s.Detector),
01353 pl,strip,StripEnd::kWest);
01354
01355 MAXMSG("MeuReco",Msg::kDebug,100)
01356 <<"pl="<<pl<<", st="<<strip<<endl;
01357
01358 if (!seidW.IsValid()){
01359 MSG("MeuReco",Msg::kError)
01360 <<"Strip not valid: pl="<<pl<<", st="<<strip
01361 <<", view="<<sPv<<endl;
01362 seidW.Print();
01363 break;
01364 }
01365
01366
01367 UgliStripHandle ushW=ugh.GetStripHandle(seidW);
01368 cp.StripHalfLength=ushW.GetHalfLength();
01369 cp.StripClearFibre2=ushW.ClearFiber(StripEnd::kWest);
01370 cp.StripPigtail2=ushW.WlsPigtail(StripEnd::kWest);
01371
01372 if (s.Detector!=Detector::kNear){
01373 PlexStripEndId seidE
01374 (static_cast<Detector::Detector_t>(s.Detector),
01375 pl,strip,StripEnd::kEast);
01376 UgliStripHandle ushE=ugh.GetStripHandle(seidE);
01377 cp.StripClearFibre1=ushE.ClearFiber(StripEnd::kEast);
01378 cp.StripPigtail1=ushE.WlsPigtail(StripEnd::kEast);
01379 }
01380
01381
01382 TVector3 xyz(cp.X,cp.Y,cp.Z);
01383
01384
01385
01386 TVector3 localPos=ushW.GlobalToLocal(xyz);
01387
01388 cp.DistToStripCentre=localPos.X();
01389
01390
01391
01392
01393
01394
01395
01396
01397
01398
01399
01400
01401
01402 }
01403 }
01404
01405
01406
01407 void MeuReco::ConvertToXYZ(MeuSummary& s,
01408 std::map<Int_t,MeuHitInfo>& plInfo) const
01409 {
01410
01411 Msg::LogLevel_t logLevel=Msg::kDebug;
01412
01413 MAXMSG("MeuReco",logLevel,1000)
01414 <<endl<<"ConvertToXYZ: Turn TPos, LPos and z -> xyz"<<endl;
01415
01416
01417 Bool_t posDir=(s.EndPlane>s.VtxPlane);
01418
01419
01420 Int_t pl=s.VtxPlane;
01421 Int_t tmpEndPlane=s.EndPlane;
01422 if (posDir) tmpEndPlane++;
01423 else tmpEndPlane--;
01424
01425 VldTimeStamp vldts;
01426
01427 VldContext vc
01428 (static_cast<Detector::Detector_t>(s.Detector),
01429 static_cast<SimFlag::ESimFlag>(s.SimFlag),vldts);
01430
01431 UgliGeomHandle ugh(vc);
01432 TVector3 uvz;
01433
01434
01435 while (pl!=tmpEndPlane){
01436 MAXMSG("MeuReco",Msg::kVerbose,1000)
01437 <<"pl="<<pl<<endl;
01438
01439
01440 MeuHitInfo& cp=plInfo[pl];
01441
01442
01443 uvz.SetZ(cp.Z);
01444
01445
01446 if (cp.View==PlaneView::kU){
01447 uvz.SetX(cp.TPos);
01448 uvz.SetY(cp.LPos);
01449 }
01450 else if (cp.View==PlaneView::kV){
01451 uvz.SetY(cp.TPos);
01452 uvz.SetX(cp.LPos);
01453 }
01454 else cout<<"ahhhhhhh"<<endl;
01455
01456
01457 TVector3 xyz=ugh.uvz2xyz(uvz);
01458
01459
01460 cp.X=xyz.X();
01461 cp.Y=xyz.Y();
01462
01463 MAXMSG("MeuReco",logLevel,1000)
01464 <<"pl="<<pl<<", cp: X="<<cp.X<<", Y="<<cp.Y<<", Z="<<cp.Z
01465 <<endl;
01466
01467 if (posDir) pl++;
01468 else pl--;
01469 }
01470 }
01471
01472
01473
01474 Bool_t MeuReco::Reconstruct(MeuSummary& s,
01475 std::map<Int_t,MeuHitInfo>& plInfo) const
01476 {
01477
01478 Msg::LogLevel_t logLevel=Msg::kDebug;
01479
01480 MSG("MeuReco",logLevel)
01481 <<"Running Reconstruct..."<<endl;
01482
01483
01484
01485
01486
01487
01488
01489
01490 Bool_t allGapsFilled=this->CalcPosOfGaps(s,plInfo);
01491 if (!allGapsFilled) {
01492 MSG("MeuReco",logLevel)
01493 <<"Running CalcPosOfBigGaps..."<<endl;
01494 allGapsFilled=this->CalcPosOfBigGaps(s,plInfo);
01495 }
01496 if (!allGapsFilled) {
01497 MSG("MeuReco",logLevel)
01498 <<"Running CalcPosOfTrkEndGaps..."<<endl;
01499 allGapsFilled=this->CalcPosOfTrkEndGaps(s,plInfo);
01500 }
01501 if (!allGapsFilled) {
01502 MAXMSG("MeuReco",Msg::kDebug,100)
01503 <<"Giving up on this event, gaps not filled"<<endl;
01504
01505 return false;
01506 }
01507
01508 MSG("MeuReco",logLevel)
01509 <<"Running CalcLPos..."<<endl;
01510
01511 Bool_t goodLPos=this->CalcLPos(s,plInfo);
01512 if (!goodLPos) {
01513 MAXMSG("MeuReco",Msg::kDebug,100)
01514 <<"Giving up on this event, LPos is bad"<<endl;
01515 return false;
01516 }
01517
01518 MSG("MeuReco",logLevel)
01519 <<"Running ConvertToXYZ..."<<endl;
01520
01521 this->ConvertToXYZ(s,plInfo);
01522
01523 MSG("MeuReco",logLevel)
01524 <<"Running CalcPLCor..."<<endl;
01525
01526 this->CalcPLCor(s,plInfo);
01527
01528 return true;
01529 }
01530
01531
01532
01533 void MeuReco::CalcWindow(MeuSummary& s,
01534 std::map<Int_t,MeuHitInfo>& plInfo) const
01535 {
01536
01537 Msg::LogLevel_t logLevel=Msg::kDebug;
01538
01539 MSG("MeuReco",logLevel)
01540 <<"Running CalcWindow..."<<endl;
01544
01545
01546
01547
01548
01549
01550
01551
01552 MSG("MeuReco",logLevel)
01553 <<"Running CalcMEU..."<<endl;
01554
01555 this->CalcMEU(s,plInfo);
01556
01557 if (s.WinSigMap>0){
01558 static Float_t avMeuSigCor=0;
01559 static Float_t avMeuSigMap=0;
01560 static Int_t counter=0;
01561 avMeuSigCor+=s.WinSigCor;
01562 avMeuSigMap+=s.WinSigMap;
01563 counter++;
01564
01565 MAXMSG("MeuReco",Msg::kDebug,1000)
01566 <<"Completed the window:"<<endl
01567 <<" s.WinSigMap="<<s.WinSigMap
01568 <<", runing av="<<avMeuSigMap/counter<<endl
01569 <<" s.WinSigCor="<<s.WinSigCor
01570 <<", runing av="<<avMeuSigCor/counter
01571 <<" (N="<<counter<<")"<<endl;
01572 }
01573 }
01574
01575
01576
01577 void MeuReco::CalcVtxSpecialND
01578 (MeuSummary& s,const std::map<Int_t,MeuHitInfo>& plInfo) const
01579 {
01580
01581
01582
01583
01584 if (s.Detector!=Detector::kNear) return;
01585
01586
01587 Msg::LogLevel_t logLevel=Msg::kDebug;
01588
01589 if (s.VtxPlane<=120 && s.EndPlane<=120) {
01590
01591 }
01592 else if (s.VtxPlane>120 && s.EndPlane<=118) {
01593 for (Int_t pl=120;pl>0;pl--){
01594 if (plInfo.find(pl)!=plInfo.end()){
01595 const MeuHitInfo& cp=plInfo.find(pl)->second;
01596 MSG("MeuReco",logLevel)
01597 <<"MeuReco::CalcVtxSpecialND pl="<<pl
01598 <<", st="<<cp.Strip<<endl;
01599 if (cp.Strip!=-1) {
01600 s.VtxPlane=pl;
01601 MSG("MeuReco",logLevel)
01602 <<"Breaking out of loop, s.VtxPlane="
01603 <<s.VtxPlane<<endl;
01604 break;
01605 }
01606 }
01607 else {
01608 MSG("MeuReco",logLevel)
01609 <<"CalcVtxSpecialND: No pl="<<pl<<endl;
01610 }
01611 }
01612 }
01613 else if (s.EndPlane>120) {
01614 MSG("MeuReco",Msg::kError)
01615 <<"End plane is in Spectrometer"<<endl;
01616 }
01617 else MSG("MeuReco",Msg::kError)<<"Spectrometer issues!!!"<<endl;
01618
01619
01620 if (s.VtxPlane>120) {
01621 MSG("MeuReco",Msg::kError)
01622 <<"Ahhh, last part of special missed vtx plane >120, pl="
01623 <<s.VtxPlane<<endl;
01624 this->PrintMeuHitInfo(plInfo);
01625 }
01626 }
01627
01628
01629
01630 void MeuReco::CalcVtx(MeuSummary& s,
01631 const std::map<Int_t,MeuHitInfo>& plInfo) const
01632 {
01633
01634
01635
01636 map<Int_t,MeuHitInfo>::const_iterator itBegin=plInfo.begin();
01637 map<Int_t,MeuHitInfo>::const_iterator itEnd=--plInfo.end();
01638
01639
01640 while (itBegin->second.Strip<0 || itEnd->second.Strip<0){
01641
01642 MAXMSG("MeuReco",Msg::kDebug,500)
01643 <<"Beg/End plane not on track:"<<endl
01644 <<"Beg: pl="<<itBegin->second.Plane
01645 <<", st="<<itBegin->second.Strip<<endl
01646 <<", End: pl="<<itEnd->second.Plane
01647 <<", st="<<itEnd->second.Strip
01648 <<endl;
01649
01650
01651 if (itBegin->second.Strip<0) ++itBegin;
01652 if (itEnd->second.Strip<0) --itEnd;
01653
01654 MAXMSG("MeuReco",Msg::kDebug,500)
01655 <<"trying next plane in on track..."<<endl
01656 <<"Beg: pl="<<itBegin->second.Plane
01657 <<", st="<<itBegin->second.Strip<<endl
01658 <<", End: pl="<<itEnd->second.Plane
01659 <<", st="<<itEnd->second.Strip
01660 <<endl;
01661
01662
01663 if (itBegin==plInfo.end()) {
01664 MAXMSG("MeuReco",Msg::kWarning,500)
01665 <<"Failed to find beg/end strip"<<endl;
01666 break;
01667 }
01668
01669 }
01670
01671 if (s.TrigSrc>60000) {
01672 MAXMSG("MeuReco",Msg::kInfo,1)
01673 <<"CalcVtx in spill mode"<<endl;
01674 s.VtxPlane=itBegin->second.Plane;
01675 s.EndPlane=itEnd->second.Plane;
01676
01677 const MeuHitInfo& cvtx=itBegin->second;
01678 const MeuHitInfo& cend=itEnd->second;
01679 if (s.Detector==Detector::kNear){
01680 s.RVtx=sqrt(pow(cvtx.X-1.5,2)+pow(cvtx.Y,2));
01681 s.REnd=sqrt(pow(cend.X-1.5,2)+pow(cend.Y,2));
01682 }
01683 else if (s.Detector==Detector::kFar){
01684 s.RVtx=sqrt(pow(cvtx.X,2)+pow(cvtx.Y,2));
01685 s.REnd=sqrt(pow(cend.X,2)+pow(cend.Y,2));
01686 }
01687 else cout<<"No detector type recognised"<<endl;
01688 }
01689 else {
01690 MAXMSG("MeuReco",Msg::kInfo,1)
01691 <<"CalcVtx in cosmics mode"<<endl;
01692
01693 if (itBegin->second.Y>itEnd->second.Y) {
01694 s.VtxPlane=itBegin->second.Plane;
01695 s.EndPlane=itEnd->second.Plane;
01696
01697 const MeuHitInfo& cvtx=itBegin->second;
01698 const MeuHitInfo& cend=itEnd->second;
01699 if (s.Detector==Detector::kNear) {
01700 s.RVtx=sqrt(pow(cvtx.X-1.5,2)+pow(cvtx.Y,2));
01701 s.REnd=sqrt(pow(cend.X-1.5,2)+pow(cend.Y,2));
01702 }
01703 else if (s.Detector==Detector::kFar) {
01704 s.RVtx=sqrt(pow(cvtx.X,2)+pow(cvtx.Y,2));
01705 s.REnd=sqrt(pow(cend.X,2)+pow(cend.Y,2));
01706 }
01707 else cout<<"No detector type recognised"<<endl;
01708 }
01709 else {
01710 s.VtxPlane=itEnd->second.Plane;
01711 s.EndPlane=itBegin->second.Plane;
01712
01713 const MeuHitInfo& cvtx=itEnd->second;
01714 const MeuHitInfo& cend=itBegin->second;
01715 if (s.Detector==Detector::kNear) {
01716 s.RVtx=sqrt(pow(cvtx.X-1.5,2)+pow(cvtx.Y,2));
01717 s.REnd=sqrt(pow(cend.X-1.5,2)+pow(cend.Y,2));
01718 }
01719 else if (s.Detector==Detector::kFar) {
01720 s.RVtx=sqrt(pow(cvtx.X,2)+pow(cvtx.Y,2));
01721 s.REnd=sqrt(pow(cend.X,2)+pow(cend.Y,2));
01722 }
01723 else cout<<"No detector type recognised"<<endl;
01724 }
01725 }
01726 }
01727
01728
01729
01730 Float_t MeuReco::CalcSmallestDeepDistToEdge(const MeuHitInfo& cp) const
01731 {
01732
01733
01734
01735 Float_t distUPI=0;
01736 Float_t distVPI=0;
01737 Float_t distUFI=0;
01738 Float_t distVFI=0;
01739 Float_t xedge=0;
01740 Float_t yedge=0;
01741
01742 PlaneOutline po;
01743
01744
01745 po.DistanceToEdge(cp.X,cp.Y,PlaneView::kU,
01746 PlaneCoverage::kNearPartial,
01747 distUPI,xedge,yedge);
01748 Bool_t isInsideUPI=po.IsInside(cp.X,cp.Y,PlaneView::kU,
01749 PlaneCoverage::kNearPartial);
01750
01751
01752 po.DistanceToEdge(cp.X,cp.Y,PlaneView::kU,
01753 PlaneCoverage::kNearFull,
01754 distUFI,xedge,yedge);
01755 Bool_t isInsideUFI=po.IsInside(cp.X,cp.Y,PlaneView::kU,
01756 PlaneCoverage::kNearFull);
01757
01758
01759 po.DistanceToEdge(cp.X,cp.Y,PlaneView::kV,
01760 PlaneCoverage::kNearPartial,
01761 distVPI,xedge,yedge);
01762 Bool_t isInsideVPI=po.IsInside(cp.X,cp.Y,PlaneView::kV,
01763 PlaneCoverage::kNearPartial);
01764
01765
01766 po.DistanceToEdge(cp.X,cp.Y,PlaneView::kV,
01767 PlaneCoverage::kNearFull,
01768 distVFI,xedge,yedge);
01769 Bool_t isInsideVFI=po.IsInside(cp.X,cp.Y,PlaneView::kV,
01770 PlaneCoverage::kNearFull);
01771
01772
01773
01774 Float_t smallestDist=999;
01775 if (isInsideUPI && isInsideUFI && isInsideVPI && isInsideVFI){
01776 if (smallestDist>distUPI) smallestDist=distUPI;
01777 if (smallestDist>distUFI) smallestDist=distUFI;
01778 if (smallestDist>distVPI) smallestDist=distVPI;
01779 if (smallestDist>distVFI) smallestDist=distVFI;
01780 }
01781
01782
01783
01784
01785 if (smallestDist==999) {
01786 smallestDist=0;
01787 if (smallestDist<distUPI && !isInsideUPI) smallestDist=distUPI;
01788 if (smallestDist<distUFI && !isInsideUFI) smallestDist=distUFI;
01789 if (smallestDist<distVPI && !isInsideVPI) smallestDist=distVPI;
01790 if (smallestDist<distVFI && !isInsideVFI) smallestDist=distVFI;
01791
01792
01793 smallestDist*=-1;
01794 }
01795
01796 if (smallestDist==999) cout<<"Ahhhhhhh"<<endl;
01797
01798 MAXMSG("MeuReco",Msg::kDebug,500)
01799 <<"smallestDist="<<smallestDist
01800 <<", UPI="<<distUPI<<" (in="<<isInsideUPI<<")"
01801 <<", UFI="<<distUFI<<" (in="<<isInsideUFI<<")"
01802 <<", VPI="<<distVPI<<" (in="<<isInsideVPI<<")"
01803 <<", VFI="<<distVFI<<" (in="<<isInsideVFI<<")"<<endl;
01804
01805 return smallestDist;
01806 }
01807
01808
01809
01810 Float_t MeuReco::CheckDeepDistToEdge(const MeuHitInfo& cp) const
01811 {
01812
01813
01814
01815 Float_t distUPI=0;
01816 Float_t distVPI=0;
01817 Float_t distUFI=0;
01818 Float_t distVFI=0;
01819 Float_t xedge=0;
01820 Float_t yedge=0;
01821
01822 PlaneOutline po;
01823
01824
01825 po.DistanceToEdge(cp.X,cp.Y,PlaneView::kU,
01826 PlaneCoverage::kNearPartial,
01827 distUPI,xedge,yedge);
01828 Bool_t isInsideUPI=po.IsInside(cp.X,cp.Y,PlaneView::kU,
01829 PlaneCoverage::kNearPartial);
01830
01831
01832 po.DistanceToEdge(cp.X,cp.Y,PlaneView::kU,
01833 PlaneCoverage::kNearFull,
01834 distUFI,xedge,yedge);
01835 Bool_t isInsideUFI=po.IsInside(cp.X,cp.Y,PlaneView::kU,
01836 PlaneCoverage::kNearFull);
01837
01838
01839 po.DistanceToEdge(cp.X,cp.Y,PlaneView::kV,
01840 PlaneCoverage::kNearPartial,
01841 distVPI,xedge,yedge);
01842 Bool_t isInsideVPI=po.IsInside(cp.X,cp.Y,PlaneView::kV,
01843 PlaneCoverage::kNearPartial);
01844
01845
01846 po.DistanceToEdge(cp.X,cp.Y,PlaneView::kV,
01847 PlaneCoverage::kNearFull,
01848 distVFI,xedge,yedge);
01849 Bool_t isInsideVFI=po.IsInside(cp.X,cp.Y,PlaneView::kV,
01850 PlaneCoverage::kNearFull);
01851
01852
01853 Float_t smallestDist=999;
01854 if (isInsideUPI && isInsideUFI && isInsideVPI && isInsideVFI){
01855 if (smallestDist>distUPI) smallestDist=distUPI;
01856 if (smallestDist>distUFI) smallestDist=distUFI;
01857 if (smallestDist>distVPI) smallestDist=distVPI;
01858 if (smallestDist>distVFI) smallestDist=distVFI;
01859 }
01860
01861
01862 if (smallestDist==999) smallestDist=0;
01863
01864 MAXMSG("MeuReco",Msg::kDebug,500)
01865 <<"smallestDist="<<smallestDist
01866 <<", UPI="<<distUPI
01867 <<", UFI="<<distUFI
01868 <<", VPI="<<distVPI
01869 <<", VFI="<<distVFI<<endl;
01870
01871 return smallestDist;
01872 }
01873
01874
01875
01876 void MeuReco::CalcFCPC(MeuSummary& s,
01877 const std::map<Int_t,MeuHitInfo>& plInfo) const
01878 {
01879
01880 if (s.Detector==Detector::kNear) {
01881
01882 s.SM1=true;
01883 s.SM2=false;
01884 s.SMBoth=false;
01885
01886
01887 s.EntSM1Front=s.VtxPlane<=5;
01888 s.EntSM1Back=s.VtxPlane>=116;
01889 s.EntSMEnd=s.EntSM1Front || s.EntSM1Back;
01890
01891
01892 s.ExitSM1Front=s.EndPlane<=5;
01893 s.ExitSM1Back=s.EndPlane>=116;
01894 s.ExitSMEnd=s.ExitSM1Front || s.ExitSM1Back;
01895
01896
01897
01898 if (plInfo.find(s.VtxPlane)==plInfo.end()) {
01899 MSG("MeuReco",Msg::kFatal)<<"Ahhhhh! No vtx"<<endl;
01900 }
01901 const MeuHitInfo& cp=plInfo.find(s.VtxPlane)->second;
01902 s.VtxDistToEdge=this->CheckDeepDistToEdge(cp);
01903
01904
01905 if (plInfo.find(s.EndPlane)==plInfo.end()) {
01906 MSG("MeuReco",Msg::kError)<<"Ahhhhh2! No end"<<endl;
01907 }
01908 const MeuHitInfo& cpEnd=plInfo.find(s.EndPlane)->second;
01909 s.EndDistToEdge=this->CheckDeepDistToEdge(cpEnd);
01910
01911
01912 if (s.TrigSrc>60000) {
01913 MAXMSG("MeuReco",Msg::kInfo,1)
01914 <<"CalcFCPC: Spill mode"<<endl;
01915 s.PC=!s.ExitSMEnd && s.EndDistToEdge>s.DistToEdgeFid;
01916 }
01917 else {
01918 MAXMSG("MeuReco",Msg::kInfo,1)
01919 <<"CalcFCPC: Cosmics mode"<<endl;
01920 s.PC=!s.ExitSMEnd && s.EndDistToEdge>s.DistToEdgeFid &&
01921 (s.VtxDistToEdge<s.DistToEdgeFid || s.EntSMEnd);
01922 }
01923
01924 if (!s.PC) {
01925 s.FC=!s.ExitSMEnd && !s.EntSMEnd &&
01926 s.VtxDistToEdge>s.DistToEdgeFid &&
01927 s.EndDistToEdge>s.DistToEdgeFid;
01928 }
01929 else s.FC=false;
01930
01931
01932
01933
01934
01935
01936
01937
01938 }
01939 else if (s.Detector==Detector::kFar) {
01940
01941 Float_t maxPlane=s.MaxPlane2;
01942 if (s.MaxPlane3>s.MaxPlane2) maxPlane=s.MaxPlane3;
01943 Float_t minPlane=s.MinPlane2;
01944 if (s.MinPlane3<s.MinPlane2) minPlane=s.MinPlane3;
01945
01946
01947 s.SM1=maxPlane<=248;
01948 s.SM2=minPlane>=250;
01949 s.SMBoth=minPlane<=248 && maxPlane>=250;
01950
01951
01952 s.MinPlane2=s.MinPlane2;
01953 s.MinPlane3=s.MinPlane3;
01954 s.MaxPlane2=s.MaxPlane2;
01955 s.MaxPlane3=s.MaxPlane3;
01956
01957
01958 s.EntSM1Front=s.VtxPlane<=5;
01959 s.EntSM1Back=s.VtxPlane>=244 && s.VtxPlane<=248;
01960 s.EntSM2Front=s.VtxPlane>=250 && s.VtxPlane<=254;
01961 s.EntSM2Back=s.VtxPlane>=481;
01962 s.EntSMEnd=s.EntSM1Front || s.EntSM1Back || s.EntSM2Front ||
01963 s.EntSM2Back;
01964
01965
01966 s.ExitSM1Front=s.EndPlane<=5;
01967 s.ExitSM1Back=s.EndPlane>=244 && s.EndPlane<=248;
01968 s.ExitSM2Front=s.EndPlane>=250 && s.EndPlane<=254;
01969 s.ExitSM2Back=s.EndPlane>=481;
01970 s.ExitSMEnd=s.ExitSM1Front || s.ExitSM1Back ||
01971 s.ExitSM2Front || s.ExitSM2Back;
01972
01973
01974 s.PC=!s.ExitSMEnd && s.REnd<s.RFid &&
01975 (s.RVtx>s.RFid || s.EntSMEnd);
01976 s.FC=!s.ExitSMEnd && !s.EntSMEnd && s.RVtx<s.RFid &&
01977 s.REnd<s.RFid;
01978
01979
01980 }
01981 else {
01982 MAXMSG("MeuReco",Msg::kFatal,500)
01983 <<"CalcFCPC: Detector not implemented = "<<s.Detector<<endl;
01984 }
01985
01986
01987 Bool_t print=false;
01988 if (print){
01989 if (s.PC){
01990 MAXMSG("MeuReco",Msg::kInfo,500)
01991 <<"PC"
01992 <<", vtx Pl="<<s.VtxPlane<<", end Pl="<<s.EndPlane
01993 <<", dVtx="<<s.VtxDistToEdge
01994 <<", dEnd="<<s.EndDistToEdge<<endl;
01995 for (map<Int_t,MeuHitInfo>::const_iterator it=plInfo.begin();
01996 it!=plInfo.end();++it){
01997 const MeuHitInfo& c=it->second;
01998 MAXMSG("MeuReco",Msg::kInfo,500)
01999 <<"pl="<<c.Plane<<", y="<<c.Y<<endl;
02000 }
02001 }
02002 else if (s.FC){
02003 MAXMSG("MeuReco",Msg::kInfo,500)
02004 <<"FC!!!!!"
02005 <<", vtx Pl="<<s.VtxPlane<<", end Pl="<<s.EndPlane
02006 <<", dVtx="<<s.VtxDistToEdge
02007 <<", dEnd="<<s.EndDistToEdge<<endl;
02008 for (map<Int_t,MeuHitInfo>::const_iterator it=plInfo.begin();
02009 it!=plInfo.end();++it){
02010 const MeuHitInfo& c=it->second;
02011 MAXMSG("MeuReco",Msg::kInfo,500)
02012 <<"pl="<<c.Plane<<", y="<<c.Y<<endl;
02013 }
02014 }
02015 else {
02016 MAXMSG("MeuReco",Msg::kInfo,500)
02017 <<"NOT PC or FC"<<endl;
02018 }
02019 }
02020 }
02021
02022
02023
02024 void MeuReco::PrintContainment(const MeuSummary& s) const
02025 {
02026 MSG("MeuReco",Msg::kInfo)
02027 <<"Containment summary:"<<endl;
02028 MSG("MeuReco",Msg::kInfo)
02029 <<" Track: "<<s.VtxPlane<<" -> "<<s.EndPlane<<endl;
02030 MSG("MeuReco",Msg::kInfo)
02031 <<" EntSMEnd="<<s.EntSMEnd
02032 <<" (SM1: F="<<s.EntSM1Front<<", B="<<s.EntSM1Back
02033 <<" SM2: F="<<s.EntSM2Front<<", B="<<s.EntSM2Back<<")"<<endl;
02034 MSG("MeuReco",Msg::kInfo)
02035 <<" ExitSMEnd="<<s.ExitSMEnd
02036 <<" (SM1: F="<<s.ExitSM1Front<<", B="<<s.ExitSM1Back
02037 <<" SM2: F="<<s.ExitSM2Front<<", B="<<s.ExitSM2Back<<")"<<endl;
02038 MSG("MeuReco",Msg::kInfo)
02039 <<" Radius: fREnd="<<s.REnd<<", fRVtx="<<s.RVtx
02040 <<", (fRFid="<<s.RFid<<")"<<endl;
02041 MSG("MeuReco",Msg::kInfo)
02042 <<" VtxDistToEdge="<<s.VtxDistToEdge
02043 <<", EndDistToEdge="<<s.EndDistToEdge
02044 <<", PC="<<s.PC<<", FC="<<s.FC<<endl;
02045 }
02046
02047
02048
02049 Bool_t MeuReco::CheckWinContainment
02050 (const MeuSummary& s,const std::map<Int_t,MeuHitInfo>& plInfo) const
02051 {
02052 Bool_t contained=true;
02053 Float_t containDisttoEdge=0.1;
02054
02055 if (s.Detector==Detector::kNear) {
02056
02057 Int_t lowPl=s.WinVtxSidePl;
02058 Int_t highPl=s.WinStopSidePl;
02059 if (lowPl>highPl){
02060 lowPl=s.WinStopSidePl;
02061 highPl=s.WinVtxSidePl;
02062 }
02063
02064
02065 if (plInfo.find(lowPl)==plInfo.end() ||
02066 plInfo.find(highPl)==plInfo.end()) {
02067 MAXMSG("MeuReco",Msg::kFatal,200)
02068 <<"Can't find track window edge planes, returning !contained"
02069 <<endl;
02070 contained=false;
02071 return contained;
02072 }
02073
02074
02075 for (map<Int_t,MeuHitInfo>::const_iterator it=plInfo.find(lowPl);
02076 it!=++plInfo.find(highPl);++it){
02077
02078 const MeuHitInfo& cp=it->second;
02079
02080 Float_t distToEdge=this->CheckDeepDistToEdge(cp);
02081
02082 if(distToEdge<containDisttoEdge) {
02083 contained=false;
02084 MAXMSG("MeuReco",Msg::kDebug,500)
02085 <<"pl="<<cp.Plane<<", st="<<cp.Strip
02086 <<", d="<<distToEdge
02087 <<", con="<<contained<<endl;
02088 break;
02089 }
02090 }
02091 }
02092 else if (s.Detector==Detector::kFar) {
02093
02094 }
02095 else {
02096 cout<<"Detector type not supported"<<endl;
02097 }
02098
02099 return contained;
02100 }
02101
02102
02103
02104 Bool_t MeuReco::CheckTrackGaps
02105 (const std::map<Int_t,MeuHitInfo>& plInfo) const
02106 {
02107 Bool_t gapsOk=true;
02108 Int_t lastTrkPl=-1;
02109 Int_t gap=0;
02110
02111
02112
02113
02114
02115
02116
02117
02118
02119
02120
02121
02122
02123
02124
02125
02126
02127
02128
02129
02130
02131 Float_t minU=-0.14*Munits::m;
02132 Float_t maxU=2.3*Munits::m;
02133 Float_t minV=-maxU;
02134 Float_t maxV=-minU;
02135 MAXMSG("MeuReco",Msg::kInfo,50)
02136 <<"minU="<<minU<<", maxU="<<maxU
02137 <<", minV="<<minV<<", maxV="<<maxV
02138 <<endl;
02139
02140 for (map<Int_t,MeuHitInfo>::const_iterator it=plInfo.begin();
02141 it!=plInfo.end();++it){
02142 const MeuHitInfo& cp=it->second;
02143 Int_t pl=cp.Plane;
02144 if (pl>120) continue;
02145
02146 Float_t u=cp.TPos;
02147 Float_t v=cp.LPos;
02148 if (cp.View==PlaneView::kV){
02149 v=cp.TPos;
02150 u=cp.LPos;
02151 }
02152
02153 Bool_t fid=false;
02154 if (u>minU && u<maxU && v>minV && v<maxV){
02155 fid=true;
02156 }
02157
02158 if (cp.Strip!=-1) {
02159 gap=0;
02160 lastTrkPl=pl;
02161 }
02162 else gap++;
02163
02164 MAXMSG("MeuReco",Msg::kInfo,500)
02165 <<"pl="<<cp.Plane<<", st="<<cp.Strip
02166 <<", sigcor="<<cp.SigCor
02167 <<", gap="<<gap
02168 <<", fid="<<fid<<", u="<<u<<", v="<<v<<endl;
02169
02170 if (gap>=3) gapsOk=false;
02171
02172 }
02173
02174 return gapsOk;
02175 }
02176
02177
02178
02179 Bool_t MeuReco::CalcTrace
02180 (const MeuSummary& s,const std::map<Int_t,MeuHitInfo>& plInfo,
02181 Float_t* trace,Float_t* traceZ) const
02182 {
02183 if (s.Detector!=Detector::kFar) {
02184 MAXMSG("MeuReco",Msg::kInfo,1)
02185 <<"Not calculating trace for detector="<<s.Detector
02186 <<", only implemented for FD"<<endl;
02187 return true;
02188 }
02189
02190
02191 Msg::LogLevel_t logLevel=Msg::kDebug;
02192
02193 MAXMSG("MeuReco",logLevel,50)
02194 <<endl<<"CalcTrace: Get position along strip, track: "
02195 <<s.VtxPlane<<"->"<<s.EndPlane<<endl;
02196
02197 Bool_t posDir=(s.EndPlane>s.VtxPlane);
02198
02199 Int_t pl=s.EndPlane;
02200 if (posDir) pl-=5;
02201 else pl+=5;
02202
02203 const MeuHitInfo& cpEnd=plInfo.find(s.EndPlane)->second;
02204 const MeuHitInfo* tmpcp=&(plInfo.find(pl)->second);
02205
02206 if (tmpcp->Strip<0){
02207 MAXMSG("MeuReco",Msg::kDebug,100)
02208 <<"Can't find strip for this plane="<<pl
02209 <<", strip="<<tmpcp->Strip
02210 <<", trk: "<<s.VtxPlane<<"->"<<s.EndPlane<<endl;
02211
02212 if (posDir) pl--;
02213 else pl++;
02214 tmpcp=&(plInfo.find(pl)->second);
02215
02216 if (tmpcp->Strip<0){
02217 MAXMSG("MeuReco",Msg::kDebug,1000)
02218 <<"Can't find strip (again) for this plane="<<pl
02219 <<", strip="<<tmpcp->Strip
02220 <<", trk: "<<s.VtxPlane<<"->"<<s.EndPlane<<endl;
02221
02222 if (posDir) pl--;
02223 else pl++;
02224 tmpcp=&(plInfo.find(pl)->second);
02225
02226 if (tmpcp->Strip<0){
02227 MAXMSG("MeuReco",logLevel,100)
02228 <<"Can't find strip (again2) for this plane="<<pl
02229 <<", strip="<<tmpcp->Strip
02230 <<", trk: "<<s.VtxPlane<<"->"<<s.EndPlane<<endl
02231 <<"Given up looking... and returned false"<<endl;
02232 return false;
02233 }
02234 }
02235 MAXMSG("MeuReco",Msg::kDebug,10)
02236 <<"Found pl="<<pl<<", strip="<<tmpcp->Strip<<endl;
02237 }
02238
02239
02240 const MeuHitInfo& cp=*tmpcp;
02241
02242 static vector<TVector3> va;
02243 static vector<TVector3> vb;
02244 static vector<TVector3> vc;
02245
02246
02247 if (va.size()==0){
02249
02251
02252
02253 va.push_back(TVector3( 0, 4 ,0));
02254 va.push_back(TVector3(-4, 1.66,0));
02255 va.push_back(TVector3(-4, 0 ,0));
02256 va.push_back(TVector3(-4,-1.66,0));
02257 va.push_back(TVector3( 0,-4 ,0));
02258 va.push_back(TVector3( 4,-1.66,0));
02259 va.push_back(TVector3( 4, 0 ,0));
02260 va.push_back(TVector3( 4, 1.66,0));
02261
02262
02263 va.push_back(TVector3( 0, 0 , 0));
02264 va.push_back(TVector3( 0, 0 ,14.772));
02265 va.push_back(TVector3( 0, 0 ,15.957));
02266 va.push_back(TVector3( 0, 0 ,29.948));
02267
02269
02271
02272
02273
02274 vb.push_back(TVector3(-1, 0, 0));
02275 vb.push_back(TVector3(-1,-1, 0));
02276 vb.push_back(TVector3( 0,-1, 0));
02277 vb.push_back(TVector3( 1,-1, 0));
02278
02279 vb.push_back(TVector3( 1, 0, 0));
02280 vb.push_back(TVector3( 1, 1, 0));
02281 vb.push_back(TVector3( 0, 1, 0));
02282 vb.push_back(TVector3(-1, 1, 0));
02283
02284
02285 for (Int_t i=0;i<4;i++){
02286 vb.push_back(TVector3( 0, 1, 0));
02287 }
02288
02290
02292
02293
02294 for (Int_t i=0;i<8;i++){
02295 vc.push_back(TVector3( 0, 0, 1));
02296 }
02297
02298 for (Int_t i=0;i<4;i++){
02299 vc.push_back(TVector3( 1, 0, 0));
02300 }
02301 }
02302
02303 MAXMSG("MeuReco",logLevel,1)
02304 <<"Sizes: va="<<va.size()
02305 <<", vb="<<vb.size()
02306 <<", vc="<<vc.size()<<endl;
02307
02308 const TVector3 d(cpEnd.X,cpEnd.Y,cpEnd.Z);
02309 Float_t dX=cpEnd.X-cp.X;
02310 Float_t dY=cpEnd.Y-cp.Y;
02311
02312
02313
02314 if (dX==0){
02315 dX+=0.001;
02316 MAXMSG("MeuReco",Msg::kDebug,1000)
02317 <<"Tweaking dX so !=0"<<endl;
02318 }
02319 if (dY==0){
02320 dY-=0.001;
02321 MAXMSG("MeuReco",Msg::kDebug,1000)
02322 <<"Tweaking dY so !=0"<<endl;
02323 }
02324
02325
02326 if (fabs(dX)==fabs(dY)){
02327 dX+=0.001;
02328 MAXMSG("MeuReco",Msg::kDebug,1000)
02329 <<"Tweaking dX so !=dY"<<endl;
02330 }
02331 const TVector3 e(dX,dY,cpEnd.Z-cp.Z);
02332
02333
02334 vector<Float_t> dist(va.size(),-999);
02335 vector<TVector3> vintersect(va.size());
02336 Float_t closestDist=999999;
02337 Int_t closesti=-1;
02338 Float_t closestdZ=999;
02339
02340 MAXMSG("MeuReco",logLevel,50)
02341 <<"pl="<<pl<<", strip="<<cp.Strip
02342 <<", trk: "<<s.VtxPlane<<"->"<<s.EndPlane<<endl
02343 <<"pl5.X,Y,Z="<<cp.X<<" , "<<cp.Y<<" , "<<cp.Z<<endl
02344 <<"d.X,Y,Z="<<d.X()<<" , "<<d.Y()<<" , "<<d.Z()<<endl
02345 <<"e.X,Y,Z="<<e.X()<<" , "<<e.Y()<<" , "<<e.Z()
02346 <<endl;
02347
02348 for (UInt_t i=0;i<va.size();i++){
02349
02350 TVector3& a=va[i];
02351 TVector3& b=vb[i];
02352 TVector3& c=vc[i];
02353 TVector3& intersect=vintersect[i];
02354
02355
02356 TVector3 d_a=d-a;
02357
02358 Float_t denominator=b.Cross(c).Dot(-e);
02359 MAXMSG("MeuReco",logLevel,500)
02360 <<"Denominator="<<denominator<<endl;
02361
02362 Float_t distance=999999;
02363 if (denominator!=0){
02364 Float_t numerator=b.Cross(c).Dot(d_a);
02365 Float_t lambda=numerator/denominator;
02366
02367 intersect=d+(lambda*e);
02368 Float_t dZ=fabs(intersect.Z()-d.Z());
02369
02370 distance=lambda*e.Mag();
02371
02372 MAXMSG("MeuReco",logLevel,500)
02373 <<"i="<<i<<", numerator="<<numerator<<", Mag="<<e.Mag()
02374 <<", closest distance="<<distance<<endl
02375 <<" in.X,Y,Z="<<intersect.X()<<" , "<<intersect.Y()
02376 <<" , "<<intersect.Z()
02377 <<", R="<<sqrt(pow(intersect.X(),2)+pow(intersect.Y(),2))
02378 <<", dZ="<<dZ
02379 <<" (pl="<<dZ/(5.94*Munits::cm)<<")"
02380 <<endl;
02381
02382
02383 dist[i]=distance;
02384
02385
02386 if (distance<closestDist && distance>=0) {
02387 closesti=i;
02388 closestdZ=dZ;
02389 closestDist=distance;
02390 }
02391 }
02392 else{
02393 MAXMSG("MeuReco",logLevel,200)
02394 <<endl<<endl<<"Bad denominator, pl="<<pl<<", strip="<<cp.Strip
02395 <<", trk: "<<s.VtxPlane<<"->"<<s.EndPlane<<endl
02396 <<"pl5.X,Y,Z="<<cp.X<<" , "<<cp.Y<<" , "<<cp.Z<<endl
02397 <<"d.X,Y,Z="<<d.X()<<" , "<<d.Y()<<" , "<<d.Z()<<endl
02398 <<"e.X,Y,Z="<<e.X()<<" , "<<e.Y()<<" , "<<e.Z()
02399 <<endl;
02400 cout<<"CalcTrace: denominator=0!!!"<<endl<<endl;
02401 }
02402 }
02403
02404 MAXMSG("MeuReco",logLevel,100)
02405 <<"ClosestDist="<<closestDist<<endl;
02406
02407 if (closestDist<0.5 || (closestdZ<0.5 && closesti<8)){
02408 MAXMSG("MeuReco",logLevel,100)
02409 <<"ClosestDist="<<closestDist<<", dZ="<<closestdZ
02410 <<", i="<<closesti<<endl;
02411 }
02412
02413 if (trace!=0 && traceZ!=0) {
02414 *trace=closestDist;
02415 if (closesti<8){
02416 *traceZ=closestdZ;
02417 }
02418 else *traceZ=999;
02419
02420 }
02421
02422 return true;
02423 }
02424
02425