00001 #include <cmath>
00002 #include <fstream>
00003 #include <map>
00004 #include <sstream>
00005 #include <string>
00006
00007 #include "TH1F.h"
00008 #include "TFile.h"
00009
00010 #include "NueAna/NueRecord.h"
00011 #include "MessageService/MsgService.h"
00012 #include "MinosObjectMap/MomNavigator.h"
00013 #include "MessageService/MsgService.h"
00014 #include "JobControl/JobCModuleRegistry.h"
00015
00016 #include "AnalysisNtuples/ANtpDefaultValue.h"
00017 #include "TClass.h"
00018 #include "TDataType.h"
00019 #include "TDataMember.h"
00020 #include "TRealData.h"
00021 #include "XTalkFilter.h"
00022 #include "StandardNtuple/NtpStRecord.h"
00023
00024 #include "CandNtupleSR/NtpSRRecord.h"
00025
00026 #include "TClonesArray.h"
00027
00028 #include "CandNtupleSR/NtpSRStrip.h"
00029 #include "CandNtupleSR/NtpSREvent.h"
00030 #include "CandNtupleSR/NtpSRShower.h"
00031 #include "CandNtupleSR/NtpSRTrack.h"
00032
00033 #include "TObject.h"
00034
00035 #include "VertexFinder/NtpVtxFinder/NtpVtxFinder.h"
00036
00037 #include "PMT.h"
00038
00039 JOBMODULE(XTalkFilter, "XTalkFilter",
00040 "Filter out strips below a given PE");
00041
00042 CVSID("$Id: XTalkFilter.cxx,v 1.9 2009/06/23 22:50:10 scavan Exp $");
00043
00044 int XTalkFilter::printit=-1;
00045
00046
00047
00048
00049
00050
00051
00052 std::vector<std::pair<int,int > > XTalkFilter::GetXTalkPixelsNear(int pixel)
00053 {
00054 std::vector<std::pair<int,int> > ret;
00055
00056
00057
00058 if(pixel==0)
00059 {
00060 ret.push_back(std::pair<int,int>(1,5));
00061 ret.push_back(std::pair<int,int>(8,7));
00062 ret.push_back(std::pair<int,int>(9,8));
00063 }else if(pixel==7){
00064 ret.push_back(std::pair<int,int>(6,3));
00065 ret.push_back(std::pair<int,int>(14,6));
00066 ret.push_back(std::pair<int,int>(15,7));
00067 }else if(pixel==56){
00068 ret.push_back(std::pair<int,int>(48,1));
00069 ret.push_back(std::pair<int,int>(49,2));
00070 ret.push_back(std::pair<int,int>(57,5));
00071 }else if(pixel==63){
00072 ret.push_back(std::pair<int,int>(62,3));
00073 ret.push_back(std::pair<int,int>(54,0));
00074 ret.push_back(std::pair<int,int>(55,1));
00075 }
00076
00077
00078 else if(pixel>0 && pixel<7)
00079 {
00080 ret.push_back(std::pair<int,int>(pixel-1,3));
00081 ret.push_back(std::pair<int,int>(pixel+1,5));
00082 ret.push_back(std::pair<int,int>(pixel+7,6));
00083 ret.push_back(std::pair<int,int>(pixel+8,7));
00084 ret.push_back(std::pair<int,int>(pixel+9,8));
00085 }
00086
00087
00088 else if(pixel>56 && pixel<63)
00089 {
00090 ret.push_back(std::pair<int,int>(pixel-1,3));
00091 ret.push_back(std::pair<int,int>(pixel+1,5));
00092 ret.push_back(std::pair<int,int>(pixel-7,2));
00093 ret.push_back(std::pair<int,int>(pixel-8,1));
00094 ret.push_back(std::pair<int,int>(pixel-9,0));
00095 }
00096
00097
00098
00099 else if(pixel%8==0 && pixel>0 && pixel<56)
00100 {
00101 ret.push_back(std::pair<int,int>(pixel-8,1));
00102 ret.push_back(std::pair<int,int>(pixel-7,2));
00103 ret.push_back(std::pair<int,int>(pixel+1,5));
00104 ret.push_back(std::pair<int,int>(pixel+8,7));
00105 ret.push_back(std::pair<int,int>(pixel+9,8));
00106 }
00107
00108
00109 else if((pixel+1)%8==0 && pixel>7 && pixel<63)
00110 {
00111 ret.push_back(std::pair<int,int>(pixel-8,1));
00112 ret.push_back(std::pair<int,int>(pixel-9,0));
00113 ret.push_back(std::pair<int,int>(pixel-1,3));
00114 ret.push_back(std::pair<int,int>(pixel+7,6));
00115 ret.push_back(std::pair<int,int>(pixel+8,7));
00116 }
00117
00118
00119 else{
00120 ret.push_back(std::pair<int,int>(pixel-9,0));
00121 ret.push_back(std::pair<int,int>(pixel-8,1));
00122 ret.push_back(std::pair<int,int>(pixel-7,2));
00123 ret.push_back(std::pair<int,int>(pixel-1,3));
00124 ret.push_back(std::pair<int,int>(pixel+1,5));
00125 ret.push_back(std::pair<int,int>(pixel+7,6));
00126 ret.push_back(std::pair<int,int>(pixel+8,7));
00127 ret.push_back(std::pair<int,int>(pixel+9,8));
00128 }
00129 return ret;
00130 }
00131
00132
00133
00134
00135
00136 std::vector<std::pair<int,int > > XTalkFilter::GetXTalkPixelsFar(int pixel)
00137 {
00138 std::vector<std::pair<int,int> > ret;
00139
00140 switch(pixel){
00141 case 0:
00142 ret.push_back(std::pair<int,int>(1,5));
00143 ret.push_back(std::pair<int,int>(4,7));
00144 ret.push_back(std::pair<int,int>(5,8));
00145 break;
00146 case 1:
00147 ret.push_back(std::pair<int,int>(0,3));
00148 ret.push_back(std::pair<int,int>(2,5));
00149 ret.push_back(std::pair<int,int>(4,6));
00150 ret.push_back(std::pair<int,int>(5,7));
00151 ret.push_back(std::pair<int,int>(6,8));
00152 break;
00153 case 2:
00154 ret.push_back(std::pair<int,int>(1,3));
00155 ret.push_back(std::pair<int,int>(3,5));
00156 ret.push_back(std::pair<int,int>(5,6));
00157 ret.push_back(std::pair<int,int>(6,7));
00158 ret.push_back(std::pair<int,int>(7,8));
00159 break;
00160 case 3:
00161 ret.push_back(std::pair<int,int>(2,3));
00162 ret.push_back(std::pair<int,int>(6,6));
00163 ret.push_back(std::pair<int,int>(7,7));
00164 break;
00165 case 4:
00166 ret.push_back(std::pair<int,int>(0,1));
00167 ret.push_back(std::pair<int,int>(1,2));
00168 ret.push_back(std::pair<int,int>(5,5));
00169 ret.push_back(std::pair<int,int>(8,7));
00170 ret.push_back(std::pair<int,int>(9,8));
00171 break;
00172 case 5:
00173 ret.push_back(std::pair<int,int>(0,0));
00174 ret.push_back(std::pair<int,int>(1,1));
00175 ret.push_back(std::pair<int,int>(2,2));
00176 ret.push_back(std::pair<int,int>(4,3));
00177 ret.push_back(std::pair<int,int>(6,5));
00178 ret.push_back(std::pair<int,int>(8,6));
00179 ret.push_back(std::pair<int,int>(9,7));
00180 ret.push_back(std::pair<int,int>(10,8));
00181 break;
00182 case 6:
00183 ret.push_back(std::pair<int,int>(1,0));
00184 ret.push_back(std::pair<int,int>(2,1));
00185 ret.push_back(std::pair<int,int>(3,2));
00186 ret.push_back(std::pair<int,int>(5,3));
00187 ret.push_back(std::pair<int,int>(7,5));
00188 ret.push_back(std::pair<int,int>(9,6));
00189 ret.push_back(std::pair<int,int>(10,7));
00190 ret.push_back(std::pair<int,int>(11,8));
00191 break;
00192 case 7:
00193 ret.push_back(std::pair<int,int>(2,0));
00194 ret.push_back(std::pair<int,int>(3,1));
00195 ret.push_back(std::pair<int,int>(6,3));
00196 ret.push_back(std::pair<int,int>(10,6));
00197 ret.push_back(std::pair<int,int>(11,7));
00198 break;
00199 case 8:
00200 ret.push_back(std::pair<int,int>(4,1));
00201 ret.push_back(std::pair<int,int>(5,2));
00202 ret.push_back(std::pair<int,int>(9,5));
00203 ret.push_back(std::pair<int,int>(12,7));
00204 ret.push_back(std::pair<int,int>(13,8));
00205 break;
00206 case 9:
00207 ret.push_back(std::pair<int,int>(4,0));
00208 ret.push_back(std::pair<int,int>(5,1));
00209 ret.push_back(std::pair<int,int>(6,2));
00210 ret.push_back(std::pair<int,int>(8,3));
00211 ret.push_back(std::pair<int,int>(10,5));
00212 ret.push_back(std::pair<int,int>(12,6));
00213 ret.push_back(std::pair<int,int>(13,7));
00214 ret.push_back(std::pair<int,int>(14,8));
00215 break;
00216 case 10:
00217 ret.push_back(std::pair<int,int>(5,0));
00218 ret.push_back(std::pair<int,int>(6,1));
00219 ret.push_back(std::pair<int,int>(7,2));
00220 ret.push_back(std::pair<int,int>(9,3));
00221 ret.push_back(std::pair<int,int>(11,5));
00222 ret.push_back(std::pair<int,int>(13,6));
00223 ret.push_back(std::pair<int,int>(14,7));
00224 ret.push_back(std::pair<int,int>(15,8));
00225 break;
00226 case 11:
00227 ret.push_back(std::pair<int,int>(6,0));
00228 ret.push_back(std::pair<int,int>(7,1));
00229 ret.push_back(std::pair<int,int>(10,3));
00230 ret.push_back(std::pair<int,int>(14,6));
00231 ret.push_back(std::pair<int,int>(15,7));
00232 break;
00233 case 12:
00234 ret.push_back(std::pair<int,int>(8,1));
00235 ret.push_back(std::pair<int,int>(9,2));
00236 ret.push_back(std::pair<int,int>(13,5));
00237 break;
00238 case 13:
00239 ret.push_back(std::pair<int,int>(8,0));
00240 ret.push_back(std::pair<int,int>(9,1));
00241 ret.push_back(std::pair<int,int>(10,2));
00242 ret.push_back(std::pair<int,int>(12,3));
00243 ret.push_back(std::pair<int,int>(14,5));
00244 break;
00245 case 14:
00246 ret.push_back(std::pair<int,int>(9,0));
00247 ret.push_back(std::pair<int,int>(10,1));
00248 ret.push_back(std::pair<int,int>(11,2));
00249 ret.push_back(std::pair<int,int>(13,3));
00250 ret.push_back(std::pair<int,int>(15,5));
00251 break;
00252 case 15:
00253 ret.push_back(std::pair<int,int>(10,0));
00254 ret.push_back(std::pair<int,int>(11,1));
00255 ret.push_back(std::pair<int,int>(14,3));
00256 break;
00257 default:
00258 break;
00259 }
00260
00261 return ret;
00262 }
00263
00265
00266 void XTalkFilter::Initialize()
00267 {
00268
00269
00270 _pixelToVaChannel[0] = 3;
00271 _pixelToVaChannel[1] = 5;
00272 _pixelToVaChannel[2] = 14;
00273 _pixelToVaChannel[3] = 16;
00274 _pixelToVaChannel[4] = 7;
00275 _pixelToVaChannel[5] = 9;
00276 _pixelToVaChannel[6] = 10;
00277 _pixelToVaChannel[7] = 12;
00278 _pixelToVaChannel[8] = 11;
00279 _pixelToVaChannel[9] = 13;
00280 _pixelToVaChannel[10] = 6;
00281 _pixelToVaChannel[11] = 8;
00282 _pixelToVaChannel[12] = 17;
00283 _pixelToVaChannel[13] = 15;
00284 _pixelToVaChannel[14] = 2;
00285 _pixelToVaChannel[15] = 4;
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377 }
00378
00379 PMT * XTalkFilter::GetPMT(std::vector<PMT> &v, int id, int create)
00380 {
00381 for(unsigned int i=0;i<v.size();i++)
00382 {
00383 if(v[i].GetId()==id)return &(v[i]);
00384 }
00385
00386 if(!create)return 0;
00387
00388
00389 PMT newpmt(id);
00390 v.push_back(newpmt);
00391 return & (v[v.size()-1]);
00392
00393 }
00394
00395 void XTalkFilter::DoTrueFilter(NtpStRecord * record, int ievt){
00396
00397
00398 east.clear();
00399 west.clear();
00400
00401 detector = record->GetHeader().GetVldContext().GetDetector();
00402
00403
00404 GetPixelMaps();
00405
00406 NtpSREvent* event = dynamic_cast<NtpSREvent*>(record->evt->At(ievt));
00407 int nstrips=event->nstrip;
00408
00409
00410 fPlexHandle = new PlexHandle(record->GetHeader().GetVldContext());
00411
00412 if (record!=NULL){
00413
00414
00415 for(int istp = 0; istp< nstrips; istp++){
00416
00417
00418 const NtpSRStrip* strip = dynamic_cast<const NtpSRStrip*>
00419 (record->stp->At(event->stp[istp]));
00420
00421 if (!strip)
00422 {
00423 printf("missing strip!!! idx %d total %d\n",event->stp[istp],
00424 record->stp->GetEntries());
00425
00426 }
00427
00428 PlexStripEndId pseid_east(detector,
00429 strip->plane,strip->strip,StripEnd::kEast);
00430 PlexStripEndId pseid_west(detector,
00431 strip->plane,strip->strip,StripEnd::kWest);
00432
00433 PlexPixelSpotId ppsid_east = fPlexHandle->GetPixelSpotId(pseid_east);
00434 PlexPixelSpotId ppsid_west = fPlexHandle->GetPixelSpotId(pseid_west);
00435
00436 Int_t PMTmuxID_east = CalculatePMTmuxID(ppsid_east);
00437 Int_t PMTmuxID_west = CalculatePMTmuxID(ppsid_west);
00438
00439 Float_t strip_e = (strip->ph0.sigcor+strip->ph1.sigcor)/60.;
00440
00441
00442
00443 Float_t q = strip->ph0.pe;
00444 Float_t qc = strip->ph0.sigcor/60.;
00445 if(q!=0){
00446 if(PMTmuxID_east<MAX_NUMBER_OF_PMTS && !pseid_east.IsVetoShield()){
00447
00448
00449
00450
00451
00452
00453 PMT * pmte = GetPMT(east,PMTmuxID_east);
00454 pmte->GetPixel(ppsid_east.GetPixel())->GetPixelSpot(ppsid_east.GetSpot())->AddStrip(event->stp[istp], qc, strip_e);
00455
00456 } else {
00457 cout << "Warning in XTalkRemover: Had a PMTmuxID higher than MAX_NUMBER_OF_PMTS and/or a veto shield hit" << endl;
00458 }
00459 }
00460
00461
00462
00463 q = strip->ph1.pe;
00464 qc = strip->ph1.sigcor/60.;
00465 if(q!=0){
00466 if(PMTmuxID_west<MAX_NUMBER_OF_PMTS && !pseid_west.IsVetoShield()){
00467
00468
00469
00470
00471
00472 PMT * pmtw = GetPMT(west,PMTmuxID_west);
00473 pmtw->GetPixel(ppsid_west.GetPixel())->GetPixelSpot(ppsid_west.GetSpot())->AddStrip(event->stp[istp], qc, strip_e);
00474
00475 } else {
00476 cout << "Warning in XTalkRemover: Had a PMTmuxID higher than MAX_NUMBER_OF_PMTS and/or a veto shield hit" << endl;
00477 }
00478 }
00479
00480 }
00481
00482 } else {
00483 cout << "Warning: Passed empty record to MakePixelMap in XTalkRemover" << endl;
00484 }
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505 if(printit)printf("CleanXTalk east\n");
00506 CleanXTalk(east,record);
00507 if(printit)printf("CleanXTalk west\n");
00508 CleanXTalk(west,record);
00509
00510 SaveAdjustment(east,0,record);
00511 SaveAdjustment(west,1,record);
00512
00513 }
00514
00515 void XTalkFilter::SaveAdjustment(std::vector<PMT> & pmts, int side, NtpStRecord * record)
00516 {
00517
00518
00519 for(unsigned int i=0;i<pmts.size();i++)
00520 {
00521 PMT* pmt = &pmts[i];
00522 if(!pmt->GetStatus())continue;
00523
00524 std::vector<int>pixels=pmt->GetPixelVector();
00525 for(unsigned int j=0;j<pixels.size();j++)
00526 {
00527 Pixel* p = pmt->GetPixel(pixels[j],0);
00528 if(!p)continue;
00529 if(!p->GetStatus())continue;
00530
00531 std::vector<int> psv = p->GetPixelSpotVector();
00532 for(unsigned int l=0;l<psv.size();l++)
00533 {
00534 PixelSpot * ps=p->GetPixelSpot(psv[l],0);
00535 if(!ps)continue;
00536 if(!ps->GetStatus())continue;
00537
00538
00539 double adjfrac=0;
00540 double totalstrippe=0;
00541 std::vector<int> strips = ps->GetStrips();
00542 for(unsigned int m=0;m<strips.size();m++)
00543 {
00544 NtpSRStrip* strip = (NtpSRStrip*)(record->stp->At(strips[m]));
00545 totalstrippe += side==0?strip->ph0.sigcor/60.:strip->ph1.sigcor/60.;
00546 }
00547
00548 double thispe = ps->GetE();
00549 adjfrac = totalstrippe>0?thispe / totalstrippe : 0;
00550 if(adjfrac<1e-5)adjfrac=0;
00551
00552
00553
00554 if(printit)printf("adj pmt %d p %d ps %d ee %f adjfrac %f stripe %f\n",pmt->GetId(), p->GetId(), ps->GetId(), thispe, adjfrac, totalstrippe);
00555
00556 for(unsigned int m=0;m<strips.size();m++)
00557 {
00558
00559
00560
00561 NtpSRStrip* strip = (NtpSRStrip*)(record->stp->At(strips[m]));
00562
00563 if(!strip)
00564 {
00565 printf("CANT FIND STRIP AT IDX %d\n",strips[m]);
00566 continue;
00567
00568 }
00569
00570
00571
00572
00573
00574
00575
00576 if(side==0)
00577 {
00578 if(printit)printf("adjusting frac %f strip %d pe %f to %f sc %f to %f\n",adjfrac,strips[m],strip->ph0.pe,strip->ph0.pe*adjfrac,strip->ph0.sigcor,strip->ph0.sigcor*adjfrac);
00579
00580 strip->ph0.pe*=adjfrac;
00581 strip->ph0.siglin*=adjfrac;
00582 strip->ph0.sigcor*=adjfrac;
00583 strip->ph0.raw*=adjfrac;
00584 }else{
00585 if(printit)printf("adjusting frac %f strip %d pe %f to %f sc %f to %f\n",adjfrac,strips[m],strip->ph1.pe,strip->ph1.pe*adjfrac,strip->ph1.sigcor,strip->ph1.sigcor*adjfrac);
00586
00587 strip->ph1.pe*=adjfrac;
00588 strip->ph1.siglin*=adjfrac;
00589 strip->ph1.sigcor*=adjfrac;
00590 strip->ph1.raw*=adjfrac;
00591 }
00592
00593
00594 }
00595 }
00596 }
00597 }
00598
00599
00600 }
00601
00602 int XTalkFilter::GetHops(PMT *pmt, Pixel* startPixel)
00603 {
00604 std::vector<int>pixels=pmt->GetPixelVector();
00605 std::vector<int>visited;
00606 int nhops= GetHops(pmt, pixels,-1,startPixel,visited);
00607 if(nhops>=1000)nhops=-1;
00608 return nhops;
00609 }
00610
00611
00612
00613 int XTalkFilter::GetHops(PMT *pmt, std::vector<int> &pixels, int pixelID, Pixel* startPixel,std::vector<int> visited)
00614 {
00615
00616 if(pixelID==startPixel->GetId())return 1000;
00617 if(pixelID<0)pixelID=startPixel->GetId();
00618 visited.push_back(pixelID);
00619
00620 Pixel* p = pmt->GetPixel(pixelID,0);
00621
00622 if(p->type==1)return 0;
00623
00624 int minhops=1000;
00625 std::vector<std::pair<int,int> > * pmap=&pixelmaps[pixelID];
00626 for(unsigned int k=0;k<pmap->size();k++)
00627 {
00628 int pid = (*pmap)[k].first;
00629 Pixel * q = 0;
00630
00631
00632 int alreadydid=0;
00633 for(unsigned int j=0;j<visited.size();j++)
00634 if(visited[j]==pid){alreadydid=1;break;}
00635 if(alreadydid)continue;
00636
00637 q=pmt->GetPixel(pid,0);
00638 if(!q)continue;
00639
00640 int hops = GetHops(pmt,pixels,q->GetId(),startPixel,visited);
00641
00642 if(hops<minhops)minhops=hops;
00643 }
00644 return minhops+1;
00645 }
00646
00647 void XTalkFilter::CleanXTalk(std::vector<PMT> & pmts, NtpStRecord * )
00648 {
00649
00650
00651 double xtalke=0;
00652 double totale=0;
00653
00654 int xtalkstrips=0;
00655 int xtalkpmts=0;
00656
00657
00658
00659
00660
00661
00662
00663 for(unsigned int i=0;i<pmts.size();i++)
00664 {
00665 PMT* pmt = &pmts[i];
00666 if(pmt->GetNStrips()<2)continue;
00667
00668 xtalkpmts++;
00669 xtalkstrips+=pmt->GetNStrips();
00670
00671
00672
00673
00674
00675
00676 std::vector<int>pixels=pmt->GetPixelVector();
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694 if(detector==Detector::kFar)
00695 {
00696 for(unsigned int j=0;j<pixels.size();j++)
00697 {
00698 Pixel* p = pmt->GetPixel(pixels[j],0);
00699 if(!p)continue;
00700
00701
00702 if(fabs(p->GetE() - p->GetStripE() )<1e-5)
00703 {
00704
00705 p->type=0;
00706 }else{
00707
00708 p->type=1;
00709 }
00710 }
00711 }
00712
00713
00714
00715
00716
00717 double nearthresh=0.1;
00718
00719 if(detector==Detector::kNear)
00720 {
00721 for(unsigned int j=0;j<pixels.size();j++)
00722 {
00723 Pixel* p = pmt->GetPixel(pixels[j],0);
00724 if(!p)continue;
00725 double neighborE=0;
00726
00727
00728
00729 std::vector<std::pair<int,int> > * pmap=&pixelmaps[p->GetId()];
00730 for(unsigned int k=0;k<pmap->size();k++)
00731 {
00732 int pid = (*pmap)[k].first;
00733
00734 Pixel *pn = pmt->GetPixel(pid,0);
00735 if(!pn)continue;
00736 neighborE+=pn->GetE();
00737 }
00738
00739 if(neighborE)
00740 {
00741 if((p->GetE()/neighborE)<nearthresh)p->type=0;
00742 else p->type=1;
00743 }else{
00744 p->type=1;
00745 }
00746 }
00747 }
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773
00774
00775
00776
00777
00778
00779
00780
00781
00782
00783
00784
00785
00786
00787
00788
00789
00790 std::multimap<int,int>hops;
00791
00792 for(unsigned int j=0;j<pixels.size();j++)
00793 {
00794 Pixel* p = pmt->GetPixel(pixels[j],0);
00795 if(!p)continue;
00796 totale+=p->GetE();
00797 int nhops = GetHops(pmt,p);
00798 p->hopstomixed=nhops;
00799 hops.insert(std::pair<int,int>(nhops,pixels[j]));
00800
00801 }
00802
00803
00804
00805
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818 std::multimap<int,int>::reverse_iterator ith;
00819 for(ith=hops.rbegin();ith!=hops.rend();ith++)
00820 {
00821 Pixel *p = pmt->GetPixel(ith->second,0);
00822 if(!p)continue;
00823
00824
00825 double e=p->GetE();
00826 if(e==0)continue;
00827
00828
00829
00830
00831
00832
00833 std::vector<std::pair<int,int> > * pmap=&pixelmaps[p->GetId()];
00834
00835 std::vector<std::pair<int, int> > toadj;
00836 std::vector<double> contribe;
00837
00838 double sum_e=0;
00839 for(unsigned int k=0;k<pmap->size();k++)
00840 {
00841 int pid = (*pmap)[k].first;
00842
00843
00844
00845 Pixel * q = pmt->GetPixel(pid,0);
00846 if(!q)continue;
00847
00848
00849
00850 std::vector<int> psv = q->GetPixelSpotVector();
00851
00852
00853 for(unsigned int l=0;l<psv.size();l++)
00854 {
00855 PixelSpot * ps=q->GetPixelSpot(psv[l],0);
00856 if(!ps)continue;
00857
00858
00859 double xe = ps->GetE() ;
00860
00861 toadj.push_back(std::pair<int,int>(pid,ps->GetId()));
00862 contribe.push_back(xe);
00863 sum_e+=xe;
00864
00865
00866 }
00867 }
00868
00869
00870 }
00871
00872
00873
00875
00876
00877
00878
00879
00880
00881
00882
00883
00884
00885
00886
00887
00888
00889
00890 for(ith=hops.rbegin();ith!=hops.rend();ith++)
00891 {
00892 Pixel *p = pmt->GetPixel(ith->second,0);
00893 if(!p)continue;
00894
00895 double pixelE=p->GetE();
00896 if(pixelE<=0)continue;
00897
00898 if(p->hopstomixed<0)continue;
00899 if(p->type==1)continue;
00900
00901
00902
00903
00904 std::vector<std::pair<int,int> > * pmap=&pixelmaps[p->GetId()];
00905
00906 std::vector<std::pair<int, int> > toadj;
00907 std::vector<double> contribe;
00908
00909 double sum_e=0;
00910 for(unsigned int k=0;k<pmap->size();k++)
00911 {
00912 int pid = (*pmap)[k].first;
00913
00914
00915 Pixel * q = pmt->GetPixel(pid,0);
00916 if(!q)continue;
00917
00918 double qe=q->GetE();
00919 if(qe<1e-5)continue;
00920
00921
00922 if(q->hopstomixed>p->hopstomixed)continue;
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932 std::vector<int> psv = q->GetPixelSpotVector();
00933
00934
00935 for(unsigned int l=0;l<psv.size();l++)
00936 {
00937 PixelSpot*ps = q->GetPixelSpot(psv[l],0);
00938 if(!ps)continue;
00939
00940 if(ps->GetStatus())continue;
00941
00942 double xe = ps->GetE();
00943
00944 toadj.push_back(std::pair<int,int>(pid,ps->GetId()));
00945 contribe.push_back(xe);
00946 sum_e+=xe;
00947
00948
00949 }
00950 }
00951
00952 if(sum_e>0)
00953 for(unsigned int k=0;k<toadj.size();k++)
00954 {
00955
00956 double toadd=contribe[k]/sum_e*pixelE;
00957 p->TakeE(toadd);
00958 Pixel * q = pmt->GetPixel(toadj[k].first,0);
00959 Pixel oldp = *q;
00960
00961 if(!q)continue;
00962 PixelSpot *ps = q->GetPixelSpot(toadj[k].second,0);
00963 if(!ps)continue;
00964 ps->AddE(toadd);
00965
00966
00967
00968 xtalke+=toadd;
00969 }
00970
00971
00972 }
00973
00974
00975
00977
00978
00979
00980
00981
00982
00983
00984
00985
00986
00987
00988
00989
00990
00991
00992
00993
00994
00995
00996
00997
00998
00999
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011
01012
01013
01014
01015
01016
01017
01018
01019
01020
01021
01022
01024 }
01025
01026 if(printit)printf("found %d strips in %d pmts with total %f energy and %f redistributed\n",xtalkstrips, xtalkpmts,totale,xtalke);
01027
01028 }
01029
01030
01031
01032
01033
01034
01035 XTalkFilter::XTalkFilter()
01036 {
01037 if(printit<0)
01038 {
01039 if(MsgService::Instance()->IsActive("XTalkFilter",Msg::kDebug))printit=1;
01040 else printit=0;
01041 }
01042
01043 detector = Detector::kUnknown;
01044 lastpixelmap = Detector::kUnknown;
01045 method=0;
01046 Initialize();
01047 }
01048
01049
01050 void XTalkFilter::GetPixelMaps()
01051 {
01052 if(lastpixelmap != detector)
01053 {
01054 pixelmaps.clear();
01055 if(detector==Detector::kFar)
01056 {
01057 for(int i=0;i<16;i++)
01058 {
01059 pixelmaps.push_back(GetXTalkPixelsFar(i));
01060 }
01061 }
01062 if(detector==Detector::kNear)
01063 {
01064 for(int i=0;i<64;i++)
01065 {
01066 pixelmaps.push_back(GetXTalkPixelsNear(i));
01067 }
01068 }
01069
01070
01071 lastpixelmap=detector;
01072
01073 }
01074
01075
01076 }
01077
01078
01079
01080
01081 XTalkFilter::~XTalkFilter()
01082 {}
01083
01084
01085 void XTalkFilter::BeginJob()
01086 {
01087
01088 }
01089
01090
01091 void XTalkFilter::EndJob()
01092 {
01093 }
01094
01095 JobCResult XTalkFilter::Reco(MomNavigator* mom)
01096 {
01097 bool foundST=false;
01098
01099
01100
01101
01102
01103
01104 std::vector<TObject*> records = mom->GetFragmentList("NtpStRecord");
01105
01106
01107 for(unsigned int i=0;i<records.size();i++)
01108 {
01109
01110 NtpStRecord *str=dynamic_cast<NtpStRecord *>(records[i]);
01111 if(str){
01112 foundST=true;
01113
01114 }else{
01115 continue;
01116 }
01117
01118
01119 NtpSREventSummary * evthdr = dynamic_cast<NtpSREventSummary *>(&str->evthdr);
01120
01121 for(int ievt=0;ievt<evthdr->nevent;ievt++)
01122 {
01123
01124
01125
01126
01127
01128
01129
01130
01131
01132
01133
01134
01135
01136
01137
01138
01139
01140 if(method==0)DoTrueFilter(str,ievt);
01141 }
01142 }
01143
01144 return JobCResult::kPassed;
01145 }
01146
01147
01148
01149
01150 const Registry& XTalkFilter::DefaultConfig() const
01151 {
01152
01153
01154
01155 MSG("XTalkFilter",Msg::kDebug)<<"In Trimmer::DefaultConfig"<<endl;
01156
01157
01158 static Registry r;
01159 std::string name = this->JobCModule::GetName();
01160 name += ".config.default";
01161 r.SetName(name.c_str());
01162
01163 r.UnLockValues();
01164 r.Set("Method",0);
01165
01166 r.LockValues();
01167
01168
01169 return r;
01170 }
01171
01172 void XTalkFilter::Config(const Registry& r)
01173 {
01174
01175
01176
01177 MSG("XTalkFilter",Msg::kDebug)<<"In Trimmer::Config"<<endl;
01178
01179 bool islocked = this->GetConfig().ValuesLocked();
01180 if (islocked) this->GetConfig().UnLockValues();
01181
01182 int valint;
01183 if(r.Get("Method", valint))
01184 {
01185 method=valint;
01186 }
01187
01188 if (islocked) this->GetConfig().LockValues();
01189
01190 MSG("XTalkFilter",Msg::kDebug)<< "Using method "<<method<<endl;
01191
01192 }
01193
01194
01195
01196
01197
01198
01199 Int_t XTalkFilter::CalculatePMTmuxID(PlexPixelSpotId &ppsid){
01200
01201 Int_t elvalue=0;
01202 elvalue = ppsid.GetTube() + 3*ppsid.GetInRack() + 24*ppsid.GetRackBay();
01203
01204 Char_t level = ppsid.GetRackLevel();
01205 Char_t ew = ppsid.GetEastWest();
01206
01207 if(level=='U'){
01208 elvalue += 450;
01209 }
01210 if(ew =='E'){
01211 elvalue += 900;
01212 }
01213
01214 return elvalue;
01215
01216 }