00001 using namespace std;
00002 #include "DemuxFast.h"
00003 #include "MyDemuxPatternMaster.h"
00004
00005 #include <cstdio>
00006 #include <vector>
00007
00008 #include "MessageService/MsgService.h"
00009 #include "MinosObjectMap/MomNavigator.h"
00010 #include "CandData/CandRecord.h"
00011 #include "CandDigit/CandDigitListHandle.h"
00012 #include "CandDigit/CandDigitHandle.h"
00013 #include "CandDigit/CandDeMuxDigitListHandle.h"
00014 #include "CandDigit/CandDeMuxDigitHandle.h"
00015 #include "JobControl/JobCommand.h"
00016 #include "JobControl/JobCModuleRegistry.h"
00017 #include "DataUtil/GetCandidate.h"
00018 #include "Validity/VldContext.h"
00019 #include "Plex/PlexPlaneId.h"
00020 #include "RawData/RawRecord.h"
00021 #include "RawData/RawDaqSnarlHeader.h"
00022
00023
00024 #include "CandStripSR/CandStripSRHandle.h"
00025 #include "CandStripSR/CandStripSRListHandle.h"
00026
00027
00028 #include "MINF_Classes/MINFast.h"
00029 #include "REROOT_Classes/REROOT_NeuKin.h"
00030 #include "REROOT_Classes/REROOT_NeuVtx.h"
00031 #include "REROOT_Classes/REROOT_FLSHit.h"
00032
00033
00034 #include "TFile.h"
00035 #include "TPolyMarker.h"
00036
00037 CVSID("$Id: DemuxFast.cxx,v 1.4 2004/03/11 17:07:12 rhatcher Exp $");
00038
00039 JOBMODULE(DemuxFast,"DemuxFast","MC Cheese Module/n");
00040
00041 ClassImp(DemuxFast);
00042
00043 DemuxFast::DemuxFast()
00044
00045 {
00046 pMaster = new MyDemuxPatternMaster();
00047
00048 _vaChip0[0] = -1;
00049 _vaChip0[1] = -1;
00050 _vaChip0[2] = 14;
00051 _vaChip0[3] = 0;
00052 _vaChip0[4] = 15;
00053 _vaChip0[5] = 1;
00054 _vaChip0[6] = 10;
00055 _vaChip0[7] = 4;
00056 _vaChip0[8] = 11;
00057 _vaChip0[9] = 5;
00058 _vaChip0[10] = 6;
00059 _vaChip0[11] = 8;
00060 _vaChip0[12] = 7;
00061 _vaChip0[13] = 9;
00062 _vaChip0[14] = 2;
00063 _vaChip0[15] = 13;
00064 _vaChip0[16] = 3;
00065 _vaChip0[17] = 12;
00066
00067 for(int i=0;i<500;i++){
00068 if(i<249)_UVmap[i] = (i%2)+1;
00069 if(i>249)_UVmap[i] = ((i+1)%2)+1;
00070 if(i==249)_UVmap[i] = 0;
00071 }
00072
00073
00074 }
00075
00076 void DemuxFast::BeginJob()
00077 {
00078 }
00079
00080 JobCResult DemuxFast::Reco(MomNavigator *mom)
00081 {
00082 int ndigits=0;
00083
00084 for(int i=0; i<500;i++){
00085 PlanesAltListsE[i].erase(PlanesAltListsE[i].begin(),PlanesAltListsE[i].end());
00086 PlanesAltListsW[i].erase(PlanesAltListsW[i].begin(),PlanesAltListsW[i].end());
00087 planehit[i] = 0;
00088 goldplanehit[i] = 0;
00089 _goldGuide[i] = 0;
00090 _qTotE[i] = 0;
00091 _qTotW[i] = 0;
00092 _qMaxE[i] = 0;
00093 _qMaxW[i] = 0;
00094 }
00095
00096
00097 PlexSEIdAltL altlist;
00098 PlexSEIdAltL* paltlist;
00099
00100
00101 CandRecord* candrecord = dynamic_cast<CandRecord*>(mom->GetFragment("CandRecord","PrimaryCandidateRecord"));
00102
00103 if (candrecord == 0) {
00104 MSG("DemuxFast", Msg::kWarning) << "No PrimaryCandidateRecord in MOM."
00105 << endl;
00106 return JobCResult::kError;
00107 }
00108
00109 int run;
00110 int snarl;
00111
00112 TObject* obj;
00113 for (int i=0; (obj=mom->At(i)); ++i) {
00114 const RawRecord* rr = dynamic_cast<RawRecord*>(obj);
00115 if (rr) {
00116 const RawDaqSnarlHeader*
00117 rdsh = dynamic_cast<const RawDaqSnarlHeader*>(rr->GetRawHeader());
00118 if (rdsh) {
00119 run = rdsh->GetRun();
00120 snarl = rdsh->GetSnarl();
00121 }
00122 }
00123 }
00124
00125 MSG("DmxFast",Msg::kInfo) << " Run : " << run << " Snarl : " << snarl << endl;
00126
00127
00128
00129 const CandDigitListHandle *canddigit =
00130 DataUtil::GetCandidate<CandDigitListHandle>(mom,
00131 "CandDigitListHandle",
00132 "canddigitlist");
00133 MSG("DmxFast",Msg::kDebug) << " *** DemuxFast::Ana CandDigit*** " <<canddigit << endl;
00134
00135 if (canddigit == 0) {
00136 MSG("DemuxFast",Msg::kWarning) << "Failed to get CandDigitListHandle!\n";
00137 return JobCResult::kFailed;
00138 }
00139
00140
00141 CandDigitHandleItr cdhItr(canddigit->GetDaughterIterator());
00142
00143 while ( CandDigitHandle *cdh = cdhItr() ) {
00144
00145 paltlist = const_cast<PlexSEIdAltL*>(&(cdh->GetPlexSEIdAltL()));
00146 int iplane = paltlist->GetPlane();
00147 if(paltlist->IsVetoShield())MSG("DmxFast",Msg::kInfo) << " IS VETO SHIELD " << iplane << endl;
00148 if(iplane>0&&iplane<500){
00149 int pixel = _vaChip0[cdh->GetChannelId().GetVaChannel()];
00150 if(paltlist->GetEnd()==StripEnd::kEast){
00151 pixelE[iplane][cdh->GetChannelId().GetVaChip()][pixel] += cdh->GetCharge();
00152 }else{
00153
00154 pixelW[iplane][cdh->GetChannelId().GetVaChip()][pixel] += cdh->GetCharge();
00155 }
00156 ndigits++;
00157 }
00158 }
00159
00160
00161 CandDigitHandleItr cdhIt(canddigit->GetDaughterIterator());
00162 while ( CandDigitHandle *cdh = cdhIt() ) {
00163
00164 paltlist = const_cast<PlexSEIdAltL*>(&(cdh->GetPlexSEIdAltL()));
00165 int iplane = paltlist->GetPlane();
00166 if(iplane>0&&iplane<500){
00167 float crossTalk;
00168 int pixel = _vaChip0[cdh->GetChannelId().GetVaChannel()];
00169 int va = cdh->GetChannelId().GetVaChip();
00170 if(paltlist->GetEnd()==StripEnd::kEast){
00171 crossTalk = this->IsItXTalk(0,iplane,va,pixel);
00172 if(crossTalk<10.*cdh->GetCharge()){
00173 PlanesAltListsE[iplane].push_back(paltlist);
00174 paltlist->SetFirst();
00175 _qTotE[iplane] += paltlist->GetCurrentItem().GetPE();
00176 if(paltlist->GetCurrentItem().GetPE()>_qMaxE[iplane])_qMaxE[iplane]=
00177 paltlist->GetCurrentItem().GetPE();
00178 }
00179 }else{
00180 crossTalk = this->IsItXTalk(1,iplane,va,pixel);
00181 if(crossTalk<10.*cdh->GetCharge()){
00182 PlanesAltListsW[iplane].push_back(paltlist);
00183 paltlist->SetFirst();
00184 _qTotW[iplane] += paltlist->GetCurrentItem().GetPE();
00185 if(paltlist->GetCurrentItem().GetPE()>_qMaxW[iplane])_qMaxW[iplane]=
00186 paltlist->GetCurrentItem().GetPE();
00187 }
00188 }
00189 if(crossTalk>10.*cdh->GetCharge())MSG("DmxFast",Msg::kDebug) << "Plane : " << iplane << " : " << cdh->GetCharge() << " cf " << crossTalk << endl;
00190 }
00191 }
00192
00193
00194 for(int i=0; i<500; i++){
00195 if(PlanesAltListsE[i].size()>0){
00196 for(int j=0;j<16;j++){
00197 pixelE[i][0][j]=0;
00198 pixelE[i][1][j]=0;
00199 pixelE[i][2][j]=0;
00200 }
00201 }
00202 if(PlanesAltListsE[i].size()>0){
00203 for(int j=0;j<16;j++){
00204 pixelW[i][0][j]=0;
00205 pixelW[i][1][j]=0;
00206 pixelW[i][2][j]=0;
00207 }
00208 }
00209 }
00210
00211
00212 _cutRatioLow = 0.2;
00213 _cutRatioHigh = 5.0;
00214 _cutPEmin = 2.0;
00215 _cutFractionMin = 0.05;
00216 _cutSigmaQ = 0.0;
00217 _cutTrackTargetQ=20.0;
00218
00219
00220 _rangeWindow = 4;
00221 for(int i=0; i<500; i++){
00222 if(PlanesAltListsE[i].size()&&PlanesAltListsW[i].size()){
00223 MSG("DmxFast",Msg::kDebug) << i << " : " << PlanesAltListsE[i].size() << " : " << PlanesAltListsW[i].size() << endl;
00224 this->ResetMap(PlanesAltListsE[i].size(),PlanesAltListsW[i].size());
00225 this->MakeMap(i);
00226
00227 this->GroupHits(ecount,wcount);
00228 this->SelectHits(true);
00229 }
00230 }
00231 this->MakeGoldGuide();
00232
00233
00234
00235 MSG("DmxFast",Msg::kDebug) << "**************************************" << endl;
00236 MSG("DmxFast",Msg::kDebug) << "* *" << endl;
00237 MSG("DmxFast",Msg::kDebug) << "* Finished Loop 0 *" << endl;
00238 MSG("DmxFast",Msg::kDebug) << "* *" << endl;
00239 MSG("DmxFast",Msg::kDebug) << "**************************************" << endl;
00240
00241
00242
00243 NdemuxedHits=NdemuxedHitsU = NdemuxedHitsV = 0;
00244 demuxedHitPlane.clear();
00245 demuxedHitStrip.clear();
00246
00247 _cutRatioLow = 0.2;
00248 _cutRatioHigh = 5.0;
00249 _cutPEmin = 4.0;
00250 _cutFractionMin = 0.1;
00251 _cutSigmaQ = 3.0;
00252 _rangeWindow = 4;
00253
00254
00255 for(int i=0; i<500; i++){
00256 if(PlanesAltListsE[i].size()&&PlanesAltListsW[i].size()){
00257 MSG("DmxFast",Msg::kDebug) << i << " : " << PlanesAltListsE[i].size() << " : " << PlanesAltListsW[i].size() << endl;
00258 this->ResetMap(PlanesAltListsE[i].size(),PlanesAltListsW[i].size());
00259 this->MakeMap(i);
00260
00261 this->GroupHits(ecount,wcount);
00262 this->SelectHits(false,true);
00263 }
00264 }
00265
00266 MSG("DmxFast",Msg::kDebug) << "**************************************" << endl;
00267 MSG("DmxFast",Msg::kDebug) << "* *" << endl;
00268 MSG("DmxFast",Msg::kDebug) << "* Finished Loop 1a *" << endl;
00269 MSG("DmxFast",Msg::kDebug) << "* *" << endl;
00270 MSG("DmxFast",Msg::kDebug) << "**************************************" << endl;
00271
00272 MSG("DmxFast",Msg::kDebug) << " N : " << NdemuxedHits << endl;
00273
00274 _cutFractionMin = 0.25;
00275
00276 if(NdemuxedHitsU==0){
00277 for(int i=0; i<500; i++){
00278 if(_UVmap[i]==1){
00279 if(PlanesAltListsE[i].size()&&PlanesAltListsW[i].size()){
00280 MSG("DmxFast",Msg::kDebug) << i << " : " << PlanesAltListsE[i].size() << " : " << PlanesAltListsW[i].size() << endl;
00281 this->ResetMap(PlanesAltListsE[i].size(),PlanesAltListsW[i].size());
00282 this->MakeMap(i);
00283
00284 this->GroupHits(ecount,wcount);
00285 this->SelectHits(false,false);
00286 }
00287 }
00288 }
00289 }
00290
00291
00292 if(NdemuxedHitsV==0){
00293 for(int i=0; i<500; i++){
00294 if(_UVmap[i]==2){
00295 if(PlanesAltListsE[i].size()&&PlanesAltListsW[i].size()){
00296 MSG("DmxFast",Msg::kDebug) << i << " : " << PlanesAltListsE[i].size() << " : " << PlanesAltListsW[i].size() << endl;
00297 this->ResetMap(PlanesAltListsE[i].size(),PlanesAltListsW[i].size());
00298 this->MakeMap(i);
00299
00300 this->GroupHits(ecount,wcount);
00301 this->SelectHits(false,false);
00302 }
00303 }
00304 }
00305 }
00306
00307
00308 MSG("DmxFast",Msg::kDebug) << "**************************************" << endl;
00309 MSG("DmxFast",Msg::kDebug) << "* *" << endl;
00310 MSG("DmxFast",Msg::kDebug) << "* Finished Loop 1b *" << endl;
00311 MSG("DmxFast",Msg::kDebug) << "* *" << endl;
00312 MSG("DmxFast",Msg::kDebug) << "**************************************" << endl;
00313
00314
00315
00316 _cutRatioLow = 0.1;
00317 _cutRatioHigh =10.0;
00318 _cutPEmin = 2.0;
00319 _cutFractionMin = 0.05;
00320 _cutSigmaQ = 5.0;
00321 _rangeWindow = 100;
00322
00323 this->MakeSearchTactics();
00324
00325 vector <DemuxSearchTactic>::iterator literS;
00326 vector <DemuxSearchTactic>::iterator literSE;
00327
00328 for(unsigned int i=0; i<searchTactics.size(); i++){
00329 int plane = searchTactics[i].iplane;
00330 if(searchTactics[i].goodTactic){
00331 this->ResetMap(PlanesAltListsE[plane].size(),PlanesAltListsW[plane].size());
00332 this->MakeMap(searchTactics[i]);
00333 this->GroupHits(ecount,wcount);
00334 if(this->SelectHits(false)){
00335 MSG("DmxFast",Msg::kDebug) << " OK go and make a new tactic " << endl;
00336 this->NewTactic(searchTactics[i]);
00337 }
00338 }else{
00339 this->NewTactic(searchTactics[i]);
00340 }
00341 literS++;
00342 }
00343
00344 literS = searchTactics.begin();
00345 literSE = searchTactics.end();
00346
00347 MSG("DmxFast",Msg::kDebug) << "**************************************" << endl;
00348 MSG("DmxFast",Msg::kDebug) << "* *" << endl;
00349 MSG("DmxFast",Msg::kDebug) << "* Finished Loop 2 *" << endl;
00350 MSG("DmxFast",Msg::kDebug) << "* *" << endl;
00351 MSG("DmxFast",Msg::kDebug) << "**************************************" << endl;
00352
00353 this->MakeSearchTacticsX();
00354
00355
00356 for(unsigned int i=0; i<searchTactics.size(); i++){
00357 int plane = searchTactics[i].iplane;
00358 if(searchTactics[i].goodTactic){
00359 this->ResetMap(PlanesAltListsE[plane].size(),PlanesAltListsW[plane].size());
00360 this->MakeMap(searchTactics[i]);
00361
00362 this->GroupHits(ecount,wcount);
00363 this->NewTactic( searchTactics[i] );
00364 }
00365 this->NewTactic( searchTactics[i] );
00366 }
00367
00368 MSG("DmxFast",Msg::kDebug) << "**************************************" << endl;
00369 MSG("DmxFast",Msg::kDebug) << "* *" << endl;
00370 MSG("DmxFast",Msg::kDebug) << "* Finished Loop 3 *" << endl;
00371 MSG("DmxFast",Msg::kDebug) << "* *" << endl;
00372 MSG("DmxFast",Msg::kDebug) << "**************************************" << endl;
00373
00374
00375
00376
00377 this->MakeSearchTacticsY();
00378
00379
00380 literS = searchTactics.begin();
00381 while(literS!=searchTactics.end()){
00382 if((*literS).goodTactic){
00383 this->DemuxSingles((*literS));
00384 }
00385 literS++;
00386 }
00387
00388 MSG("DmxFast",Msg::kDebug) << "**************************************" << endl;
00389 MSG("DmxFast",Msg::kDebug) << "* *" << endl;
00390 MSG("DmxFast",Msg::kDebug) << "* Finished Loop 4 *" << endl;
00391 MSG("DmxFast",Msg::kDebug) << "* *" << endl;
00392 MSG("DmxFast",Msg::kDebug) << "**************************************" << endl;
00393
00394 JobCResult result = JobCResult::kAOK;
00395
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454 return result;
00455 }
00456
00457
00458 JobCResult DemuxFast::Ana(const MomNavigator* )
00459 {
00460 MSG("DmxFast",Msg::kDebug) << " *** DemuxFast::Ana *** " << endl;
00461 return JobCResult::kAOK;
00462 }
00463
00464 void DemuxFast::PrintMap(int ne, int nw){
00465
00466
00467 MSG("DmxFast",Msg::kDebug) << "Print Map " << ne << " : " << nw << endl;
00468 for(int ie=0;ie<=ne;ie++){
00469 for(int iw=0;iw<=nw;iw++){
00470 MSG("DmxFast",Msg::kDebug) << _amap[ie][iw];
00471 }
00472 MSG("DmxFast",Msg::kDebug) << endl;
00473 }
00474
00475 return;
00476 }
00477
00478
00479
00480 void DemuxFast::ResetMap(int ne, int nw){
00481
00482
00483 for(int ie=0;ie<=ne;ie++){
00484 for(int iw=0;iw<=nw;iw++){
00485 _amap[ie][iw] = false;
00486 }
00487 }
00488
00489
00490 return;
00491 }
00492
00493 void DemuxFast::NewTactic(DemuxSearchTactic oldTactic){
00494
00495 MSG("DmxFast",Msg::kDebug) << "DemuxFast::NewTactic" <<endl;
00496
00497 bool foundh;
00498 bool foundl;
00499 bool found;
00500 DemuxSearchTactic newTactic;
00501
00502 switch(oldTactic.searchType){
00503 case SEARCH_GAP:
00504
00505 break;
00506 case SEARCH_GAP_B:
00507 MSG("DmxFast",Msg::kDebug) << " SEARCH_GAP_B : do something" << endl;
00508 found = false;
00509 MSG("DmxFast",Msg::kDebug) << " Old : " << oldTactic.lowplane << ":"
00510 << oldTactic.iplane << ":" << oldTactic.highplane << endl;
00511 for(int i=oldTactic.highplane-2;i>=oldTactic.iplane+2&&found==false;i-=2){
00512 if(!_searched[i]&&PlanesAltListsE[i].size()&&PlanesAltListsW[i].size()){
00513 MSG("DmxFast",Msg::kDebug) << "Make New Tactic for Plane " << i << endl;
00514 found = true;
00515 newTactic.iplane = i;
00516 newTactic.goodTactic = true;
00517 newTactic.lowplane = oldTactic.lowplane;
00518 newTactic.highplane = oldTactic.iplane;
00519 newTactic.searchType = SEARCH_GAP_F;
00520 }
00521 }
00522 if(found){
00523 MSG("DmxFast",Msg::kDebug) <<"Inserting new tactic : " << newTactic.lowplane << ":"
00524 << newTactic.iplane << ":" << newTactic.highplane << endl;
00525 searchTactics.push_back(newTactic);
00526 _searched[newTactic.iplane] = true;
00527 }
00528 break;
00529 case SEARCH_GAP_F:
00530 MSG("DmxFast",Msg::kDebug) << " SEARCH_GAP_F : do something" << endl;
00531 found = false;
00532 for(int i=oldTactic.iplane+2;i<=oldTactic.highplane-2&&found==false;i+=2){
00533 if(!_searched[i]&&PlanesAltListsE[i].size()&&PlanesAltListsW[i].size()){
00534 MSG("DmxFast",Msg::kDebug) << "Make New Tactic for Plane " << i << endl;
00535 found = true;
00536 newTactic.iplane = i;
00537 newTactic.goodTactic = true;
00538 newTactic.lowplane = oldTactic.iplane;
00539 newTactic.highplane = oldTactic.highplane;
00540 newTactic.searchType = SEARCH_GAP_F;
00541 }
00542 }
00543 if(found){
00544 MSG("DmxFast",Msg::kDebug) <<"Inserting new tactic : " << newTactic.lowplane<<":" << newTactic.iplane << ":" << newTactic.highplane << endl;
00545 searchTactics.push_back(newTactic);
00546 _searched[newTactic.iplane] = true;
00547 }
00548 break;
00549 case SEARCH_FORWARDS:
00550 foundh = false;
00551 foundl = false;
00552 if(oldTactic.goodTactic){
00553 MSG("DmxFast",Msg::kDebug) << "Continuing forwards search " << endl;
00554 for(int i=oldTactic.iplane+2;i<500&&foundh==false;i+=2){
00555 if(PlanesAltListsE[i].size()&&PlanesAltListsW[i].size()){
00556 MSG("DmxFast",Msg::kDebug) << "Make Tactic for Plane " << i << endl;
00557 foundh = true;
00558 newTactic.iplane = i;
00559 newTactic.goodTactic = true;
00560 newTactic.highplane = oldTactic.iplane;
00561 newTactic.lowplane = oldTactic.highplane;
00562 newTactic.searchType = SEARCH_FORWARDS;
00563 }
00564 }
00565 }else{
00566 MSG("DmxFast",Msg::kDebug) << "Starting forwards search " << endl;
00567 for(int i=oldTactic.iplane+2;i<500&&foundh==false;i+=2){
00568 if(PlanesAltListsE[i].size()&&PlanesAltListsW[i].size()){
00569 MSG("DmxFast",Msg::kDebug) << "Make Tactic for Plane " << i << endl;
00570 foundh = true;
00571 newTactic.highplane = oldTactic.iplane;
00572 newTactic.iplane = i;
00573 newTactic.goodTactic = true;
00574 newTactic.lowplane = -100;
00575 newTactic.searchType = SEARCH_FORWARDS;
00576 }
00577 }
00578 for(int i=oldTactic.iplane-2;i>oldTactic.iplane-12&&foundl==false;i-=2){
00579 if(planehit[i]>0){
00580 foundl = true;
00581 newTactic.lowplane = i;
00582 }
00583 }
00584 }
00585 if(foundh){
00586 MSG("DmxFast",Msg::kDebug) <<"Inserting new tactic : " << newTactic.lowplane << ":"
00587 << newTactic.iplane << ":" << newTactic.highplane << endl;
00588 searchTactics.push_back(newTactic);
00589 }
00590 break;
00591 case SEARCH_BACKWARDS:
00592 foundh = false;
00593 foundl = false;
00594 if(oldTactic.goodTactic){
00595 MSG("DmxFast",Msg::kDebug) << "Continuing backwards search " << endl;
00596 for(int i=oldTactic.iplane-2;i>0&&foundl==false;i-=2){
00597 if(PlanesAltListsE[i].size()&&PlanesAltListsW[i].size()){
00598 MSG("DmxFast",Msg::kDebug) << "Make Tactic for Plane " << i << endl;
00599 foundl = true;
00600 newTactic.iplane = i;
00601 newTactic.lowplane = oldTactic.iplane;
00602 newTactic.goodTactic = true;
00603 newTactic.highplane = oldTactic.lowplane;
00604 newTactic.searchType = SEARCH_BACKWARDS;
00605 }
00606 }
00607 }else{
00608 MSG("DmxFast",Msg::kDebug) << "Starting backwards search " << endl;
00609 for(int i=oldTactic.iplane-2;i>0&&foundl==false;i-=2){
00610 if(PlanesAltListsE[i].size()&&PlanesAltListsW[i].size()){
00611 MSG("DmxFast",Msg::kDebug) << "Make Tactic for Plane " << i << endl;
00612 foundl = true;
00613 newTactic.lowplane = oldTactic.iplane;
00614 newTactic.iplane = i;
00615 newTactic.goodTactic = true;
00616 newTactic.highplane = -100;
00617 newTactic.searchType = SEARCH_BACKWARDS;
00618 }
00619 }
00620 for(int i=oldTactic.iplane+2;i<oldTactic.iplane+12&&foundh==false;i+=2){
00621 if(planehit[i]>0){
00622 foundh = true;
00623 newTactic.highplane = i;
00624 }
00625 }
00626 }
00627 if(foundl){
00628 MSG("DmxFast",Msg::kDebug) <<"Inserting new tactic : " << newTactic.lowplane << ":"
00629 << newTactic.iplane << ":" << newTactic.highplane << endl;
00630 searchTactics.push_back(newTactic);
00631 }
00632 break;
00633 default:
00634 break;
00635 }
00636
00637 return;
00638 }
00639
00640
00641 void DemuxFast::MakeSearchTactics()
00642 {
00643
00644 bool ifirstU=false;
00645 bool ifirstV=false;
00646 int firstUplane=0;
00647 int firstVplane=0;
00648 int lastUplane=0;
00649 int lastVplane=0;
00650 int foundPlane=0;
00651
00652
00653 searchTactics.erase(searchTactics.begin(),searchTactics.end());
00654
00655 for(int i=0; i<500; i++){
00656 _searched[i] = false;
00657 if(planehit[i]>0){
00658 MSG("DmxFast",Msg::kDebug) << "Found a hit plane " << i << endl;
00659 if(ifirstU==false){
00660 if( _UVmap[i]==1){
00661 ifirstU = true;
00662 firstUplane = i;
00663 }
00664 }
00665 if(ifirstV==false){
00666 if( _UVmap[i]==2){
00667 ifirstV = true;
00668 firstVplane = i;
00669 }
00670 }
00671 if(_UVmap[i]==1)lastUplane =i;
00672 if(_UVmap[i]==2)lastVplane =i;
00673
00674 int inext = i+2;
00675 if(inext==249)inext=250;
00676 if(inext==250)inext=251;
00677 if(planehit[inext]==0){
00678 MSG("DmxFast",Msg::kDebug) << "Found an empty plane " << inext << endl;
00679 int j = inext+2;
00680 bool found = false;
00681 while(found==false&&j-inext <=24){
00682 j++;
00683 if(_UVmap[j]==_UVmap[i]&&planehit[j]>0)found=true;
00684 }
00685 if(found){
00686 MSG("DmxFast",Msg::kDebug) << "Looking in GAP " << i << ":" << j << endl;
00687 bool lfound = false;
00688
00689 for(int k=i+2; k<=j-2; k++){
00690 if(_UVmap[k]==_UVmap[i]){
00691 if(!lfound && PlanesAltListsE[k].size()&&PlanesAltListsW[k].size()){
00692 lfound = true;
00693 DemuxSearchTactic tactic;
00694 foundPlane = k;
00695 tactic.iplane = k;
00696 tactic.searchType = SEARCH_GAP_F;
00697 tactic.lowplane = i;
00698 tactic.highplane = j;
00699 tactic.goodTactic = true;
00700 searchTactics.push_back(tactic);
00701 _searched[k] = true;
00702 MSG("DmxFast",Msg::kDebug) << "Inserting F GAP search tactic : " << k<<"("<<i<<"," << j << ")" << endl;
00703 }
00704 }
00705 }
00706
00707 if(lfound){
00708 MSG("DmxFast",Msg::kDebug) << " Loop : " << j-2 << ":" << foundPlane+2 << endl;
00709 bool found = false;
00710 for(int k=j-2; k>=foundPlane+2; k--){
00711 if(_UVmap[k]==_UVmap[i]){
00712 if(!found &&PlanesAltListsE[k].size()&&PlanesAltListsW[k].size()){
00713 found = true;
00714 DemuxSearchTactic tactic;
00715 tactic.iplane = k;
00716 tactic.searchType = SEARCH_GAP_B;
00717 tactic.lowplane = i;
00718 tactic.highplane = j;
00719 tactic.goodTactic = true;
00720 searchTactics.push_back(tactic);
00721 _searched[k] = true;
00722 MSG("DmxFast",Msg::kDebug) << "Inserting B GAP search tactic : " << k<<"("<<i<<"," << j << ")" << endl;
00723 }
00724 }
00725 }
00726 }
00727 }
00728 }
00729 }
00730 }
00731 if(ifirstU){
00732 DemuxSearchTactic tactic;
00733 tactic.iplane = firstUplane;
00734 tactic.lowplane = firstUplane;
00735 tactic.highplane = firstUplane;
00736 tactic.searchType = SEARCH_BACKWARDS;
00737 tactic.goodTactic = false;
00738 searchTactics.push_back(tactic);
00739
00740
00741 tactic.iplane = lastUplane;
00742 tactic.lowplane = lastUplane;
00743 tactic.highplane = lastUplane;
00744 tactic.searchType = SEARCH_FORWARDS;
00745 tactic.goodTactic = false;
00746 searchTactics.push_back(tactic);
00747 }
00748
00749 if(ifirstV){
00750 DemuxSearchTactic tactic;
00751 tactic.iplane = firstVplane;
00752 tactic.lowplane = firstVplane;
00753 tactic.highplane = firstVplane;
00754 tactic.searchType = SEARCH_BACKWARDS;
00755 tactic.goodTactic = false;
00756 searchTactics.push_back(tactic);
00757
00758 tactic.iplane = lastVplane;
00759 tactic.lowplane = lastVplane;
00760 tactic.highplane = lastVplane;
00761 tactic.searchType = SEARCH_FORWARDS;
00762 tactic.goodTactic = false;
00763 searchTactics.push_back(tactic);
00764 }
00765
00766 return;
00767 }
00768
00769
00770 void DemuxFast::MakeSearchTacticsX()
00771 {
00772
00773 searchTactics.erase(searchTactics.begin(),searchTactics.end());
00774 bool found;
00775
00776 for(int i=0; i<500; i++){
00777 if(planehit[i]>0){
00778 if(PlanesAltListsE[i].size()&&PlanesAltListsW[i].size()){
00779 int j = -100;
00780 int k = -100;
00781 int jj = i-2;
00782 if(jj==248 || jj==249)jj--;
00783 int kk = i+2;
00784 if(kk==249 || kk==250)kk++;
00785 found = false;
00786 while(found==false){
00787 if(planehit[jj]){
00788 j=jj;
00789 found = true;
00790 }
00791 jj-=2;
00792 if(jj==248 || jj==249)jj--;
00793 if(jj<0||jj<i-12)found =true;
00794 }
00795 found = false;
00796 while(found==false){
00797 if(planehit[kk]){
00798 k=kk;
00799 found = true;
00800 }
00801 kk+=2;
00802 if(kk==249 || kk==250)kk++;
00803 if(kk>499||kk>i+12)found =true;
00804 }
00805 DemuxSearchTactic tactic;
00806 tactic.iplane = i;
00807 tactic.searchType = SEARCH_GAP;
00808 tactic.lowplane = j;
00809 tactic.highplane = k;
00810 tactic.goodTactic = true;
00811 searchTactics.push_back(tactic);
00812
00813 }
00814 }
00815 }
00816 return;
00817 }
00818
00819
00820 void DemuxFast::MakeSearchTacticsY()
00821 {
00822
00823 searchTactics.erase(searchTactics.begin(),searchTactics.end());
00824 bool found;
00825
00826 for(int i=0; i<500; i++){
00827 if(PlanesAltListsE[i].size()||PlanesAltListsW[i].size()){
00828 int j = -100;
00829 int k = -100;
00830 int jj = i-2;
00831 if(jj==248 || jj==249)jj--;
00832 int kk = i+2;
00833 if(kk==249 || kk==250)kk++;
00834 found = false;
00835 while(found==false){
00836 if(planehit[jj]){
00837 j=jj;
00838 found = true;
00839 }
00840 jj-=2;
00841 if(jj==248 || jj==249)jj--;
00842 if(jj<0||jj<i-12)found =true;
00843 }
00844 found = false;
00845 while(found==false){
00846 if(planehit[kk]){
00847 k=kk;
00848 found = true;
00849 }
00850 kk+=2;
00851 if(kk==249 || kk==250)kk++;
00852 if(kk>499||kk>i+12)found =true;
00853 }
00854 DemuxSearchTactic tactic;
00855 tactic.iplane = i;
00856 tactic.searchType = SEARCH_SINGLES;
00857 tactic.lowplane = j;
00858 tactic.highplane = k;
00859 tactic.goodTactic = true;
00860 searchTactics.push_back(tactic);
00861
00862 }
00863 }
00864 return;
00865 }
00866
00867
00868 void DemuxFast::GroupHits(int ecount, int wcount){
00869
00870
00871
00872 for(int iw=0;iw<=wcount; iw++){
00873 for(int iwp=0;iwp<=wcount; iwp++){
00874 _bmap[iw][iwp] = false;
00875 }
00876 }
00877
00878 for(int ie =0; ie<=ecount; ie++){
00879 for(int iw=0;iw<=wcount; iw++){
00880 if(_amap[ie][iw]){
00881 for(int iwp =0;iwp<=wcount; iwp++){
00882 if(_amap[ie][iwp]){
00883 _bmap[iw][iwp] = true;
00884 _bmap[iwp][iw] = true;
00885 }
00886 }
00887 }
00888 }
00889 }
00890
00891
00892 for(int iw=0;iw<=wcount; iw++){
00893 _bmap[iw][iw] = true;
00894 for(int iwp=0;iwp<=wcount; iwp++){
00895 if(_bmap[iw][iwp]==false){
00896 for(int k=0;k<=wcount; k++)_bmap[iw][iwp] |= _bmap[iw][k] && _bmap[k][iwp];
00897 }
00898
00899 }
00900
00901 }
00902
00903
00904 ngroup = 0;
00905 for(int iw=0;iw<=wcount; iw++){wfound[iw]=false;}
00906 for(int ie=0;ie<=ecount; ie++){efound[ie]=false;}
00907
00908 for(int iw=0;iw<=wcount; iw++){
00909 if(wfound[iw]==false){
00910 ngroup++;
00911 ningroupw[ngroup]=0;
00912 for(int iwp=0;iwp<=wcount; iwp++){
00913 if(_bmap[iw][iwp]){
00914 ningroupw[ngroup]++;
00915 wgroup[ngroup][ningroupw[ngroup]]=iwp;
00916 wfound[iwp]=true;
00917 }
00918 }
00919 }
00920 }
00921
00922 if(ngroup>0){
00923 for(int ig=1;ig<=ngroup;ig++){
00924 ningroupe[ig]=0;
00925 for(int iw=1;iw<=ningroupw[ig];iw++){
00926 for(int ie=0;ie<=ecount;ie++){
00927 if(efound[ie]==false && _amap[ie][(wgroup[ig][iw])]){
00928 ningroupe[ig]++;
00929 egroup[ig][ningroupe[ig]]=ie;
00930 efound[ie] = true;
00931 }
00932 }
00933 }
00934 }
00935 }
00936
00937 return;
00938 }
00939
00940 void DemuxFast::MakeMap(int i, bool useTargets)
00941 {
00942
00943 vector <PlexSEIdAltL*>::iterator literE;
00944 vector <PlexSEIdAltL*>::iterator literW;
00945 float ratioQ;
00946 float ratioEW=0;
00947 float qE;
00948 float qW;
00949 float sigma;
00950 float r=0;
00951 float av;
00952 float ed;
00953 float ratio;
00954 int s;
00955
00956
00957 if(_qTotW[i]>0)ratioEW = _qTotE[i]/_qTotW[i];
00958
00959 literE = PlanesAltListsE[i].begin();
00960 ecount = -1;
00961 kView = (*literE)->GetPlaneView();
00962 currentPlane = (*literE)->GetPlane();
00963 MSG("DmxFast",Msg::kDebug) << " current Plane : " << currentPlane << endl;
00964 while (literE != PlanesAltListsE[i].end()){
00965 ecount++;
00966 _pAmapE[ecount] = (*literE);
00967 literW = PlanesAltListsW[i].begin();
00968 wcount = -1;
00969 while ( literW != PlanesAltListsW[i].end()){
00970 wcount++;
00971 _pAmapW[wcount] = (*literW);
00972
00973 (*literE)->SetFirst();
00974 while( (*literE)->IsValid() ){
00975
00976 qE = (*literE)->GetCurrentItem().GetPE()*CalDigitType::kPE;
00977 (*literW)->SetFirst();
00978 while( (*literW)->IsValid() ){
00979 qW = (*literW)->GetCurrentItem().GetPE()*CalDigitType::kPE;
00980
00981 if((*literE)->GetCurrentSEId().GetStrip()==(*literW)->GetCurrentSEId().GetStrip()){
00982 s = (*literE)->GetCurrentSEId().GetStrip();
00983 ratioQ = qE/qW;
00984
00985 bool goodComb = true;
00986
00987 if(ratioQ<(ratioEW*_cutRatioLow))goodComb=false;
00988 if(ratioQ>(ratioEW*_cutRatioHigh))goodComb=false;
00989 if((*literE)->GetCurrentItem().GetPE()*CalDigitType::kPE < _cutPEmin)goodComb = false;
00990 if((*literW)->GetCurrentItem().GetPE()*CalDigitType::kPE < _cutPEmin)goodComb = false;
00991 if((*literE)->GetCurrentItem().GetPE()<_cutFractionMin*_qMaxE[i])goodComb=false;
00992 if((*literW)->GetCurrentItem().GetPE()<_cutFractionMin*_qMaxW[i])goodComb=false;
00993
00994 av = _goldGuide[currentPlane];
00995 ed = 0.;
00996 if(av>0){
00997 ratio = (qE-qW)/(qE+qW);
00998 sigma = 4.0*sqrt( qE*qW*(qE+qW) )/(qE+qW)/(qE+qW);
00999 if(kView==PlaneView::kU)r = -0.55+1.1*(av/192.);
01000 if(kView==PlaneView::kV)r = 0.55-1.1*(av/192.);
01001 ed = (ratio-r)/sigma;
01002 }
01003
01004
01005
01006 MSG("DmxFast",Msg::kDebug) << "Poss : " << qE << " : " << qW << " : " << ed << " : " << (*literE)->GetCurrentSEId().GetStrip();
01007 if(goodComb){
01008 MSG("DmxFast",Msg::kDebug) << " *";
01009 }
01010 if( fabs(ed)-0.001 >= _cutSigmaQ )goodComb = false;
01011
01012 if(goodComb&&useTargets){
01013 bool found = false;
01014 for(unsigned int t=0;t<targets.size()&&found==false;t++){
01015 if(abs(targets[t]-s)<12){
01016 found = true;
01017 }
01018 }
01019 goodComb = found;
01020 }
01021
01022 if(goodComb){
01023 _amap[ecount][wcount] = true;
01024 MSG("DmxFast",Msg::kDebug) << "*";
01025 }
01026
01027 MSG("DmxFast",Msg::kDebug) << endl;
01028
01029 _smap[ecount][wcount] = s;
01030 }
01031 (*literW)->Next();
01032 }
01033 (*literE)->Next();
01034 }
01035 literW++;
01036 }
01037 literE++;
01038 }
01039 return;
01040 }
01041
01042 void DemuxFast::MakeMap(DemuxSearchTactic tactic)
01043 {
01044
01045 int i = tactic.iplane;
01046 int j = tactic.lowplane;
01047 int k = tactic.highplane;
01048 int itarget;
01049 int it;
01050
01051 targets.erase(targets.begin(),targets.end());
01052
01053 if(planehit[i]>0){
01054 for(int ii=1;ii<=planehit[i];ii++){
01055 itarget = hitmap[i][ii];
01056 targets.push_back(itarget);
01057 MSG("DmxFast",Msg::kDebug) << " I target " << ii << " : " << hitmap[i][ii] << endl;
01058 }
01059 }
01060 if(j>0){
01061 for(int jj=1;jj<=planehit[j];jj++){
01062
01063 itarget = hitmap[j][jj];
01064 targets.push_back(itarget);
01065 MSG("DmxFast",Msg::kDebug) << " J target " << jj << " : " << hitmap[j][jj] << endl;
01066 }
01067 }
01068 if(k>0){
01069 for(int kk=1;kk<=planehit[k];kk++){
01070 itarget = hitmap[k][kk];
01071 targets.push_back(itarget);
01072 MSG("DmxFast",Msg::kDebug) << " K target " << kk << " : " << hitmap[k][kk] << endl;
01073 }
01074 }
01075
01076 if(j>0&&k>0){
01077 for(int jj=1;jj<=planehit[j];jj++){
01078 if(qhitmapE[j][jj]>_cutTrackTargetQ && qhitmapW[j][jj]>_cutTrackTargetQ){
01079 for(int kk=1;kk<=planehit[k];kk++){
01080 if(qhitmapE[k][kk]>_cutTrackTargetQ && qhitmapW[k][kk]>_cutTrackTargetQ){
01081 it =hitmap[j][jj] + (hitmap[k][kk]-hitmap[j][jj])*(i-j)/(k-j);
01082 MSG("DmxFast",Msg::kDebug) << "JK target " << jj<<kk << " : " << it << endl;
01083 targets.push_back(it);
01084 }
01085 }
01086 }
01087 }
01088 }
01089
01090 this->MakeMap(i,true);
01091
01092 return;
01093 }
01094
01095 void DemuxFast::DemuxSingles(DemuxSearchTactic tactic)
01096 {
01097
01098 vector <PlexSEIdAltL*>::iterator literE;
01099 vector <PlexSEIdAltL*>::iterator literW;
01100
01101 int i = tactic.iplane;
01102 int j = tactic.lowplane;
01103 int k = tactic.highplane;
01104 int itarget;
01105 int it;
01106 int s;
01107 int sbest;
01108 int closeness;
01109 float q;
01110
01111 targets.erase(targets.begin(),targets.end());
01112
01113 MSG("DmxFast",Msg::kDebug) << "DemuxFast::DemuxSingles " << i << endl;
01114
01115 if(planehit[i]>0){
01116 for(int ii=1;ii<=planehit[i];ii++){
01117 itarget = hitmap[i][ii];
01118 targets.push_back(itarget);
01119 MSG("DmxFast",Msg::kDebug) << " I target " << ii << " : " << hitmap[i][ii] << endl;
01120 }
01121 }
01122 if(j>0){
01123 for(int jj=1;jj<=planehit[j];jj++){
01124 itarget = hitmap[j][jj];
01125 targets.push_back(itarget);
01126 MSG("DmxFast",Msg::kDebug) << " J target " << jj << " : " << hitmap[j][jj] << endl;
01127 }
01128 }
01129 if(k>0){
01130 for(int kk=1;kk<=planehit[k];kk++){
01131 itarget = hitmap[k][kk];
01132 targets.push_back(itarget);
01133 MSG("DmxFast",Msg::kDebug) << " K target " << kk << " : " << hitmap[k][kk] << endl;
01134 }
01135 }
01136 if(j>0&&k>0){
01137 for(int jj=1;jj<=planehit[j];jj++){
01138 if(qhitmapE[j][jj]>_cutTrackTargetQ && qhitmapW[j][jj]>_cutTrackTargetQ){
01139 for(int kk=1;kk<=planehit[k];kk++){
01140 if(qhitmapE[k][kk]>_cutTrackTargetQ && qhitmapW[k][kk]>_cutTrackTargetQ){
01141 it =hitmap[j][jj] + (hitmap[k][kk]-hitmap[j][jj])*(i-j)/(k-j);
01142 if(j<249 && i>249)it =hitmap[j][jj] + (hitmap[k][kk]-hitmap[j][jj])*(i-j-15)/(k-j-15);
01143 if(i<249 && k>249)it =hitmap[j][jj] + (hitmap[k][kk]-hitmap[j][jj])*(i-j)/(k+15-j);
01144 MSG("DmxFast",Msg::kDebug) << "JK target " << jj<<kk << " : " << it << endl;
01145 targets.push_back(it);
01146 }
01147 }
01148 }
01149 }
01150 }
01151
01152 if(targets.size()<1)return;
01153
01154 currentPlane = i;
01155
01156 if(PlanesAltListsE[i].size()>0){
01157 literE = PlanesAltListsE[i].begin();
01158 kView = (*literE)->GetPlaneView();
01159 currentPlane = (*literE)->GetPlane();
01160 while (PlanesAltListsE[i].size()>0){
01161 sbest =0;
01162 closeness = 999;
01163 literE = PlanesAltListsE[i].begin();
01164 (*literE)->SetFirst();
01165 q = (*literE)->GetCurrentItem().GetPE()*CalDigitType::kPE;
01166 while( (*literE)->IsValid() ){
01167 s = (*literE)->GetCurrentSEId().GetStrip();
01168 bool found = false;
01169 for(unsigned int t=0;t<targets.size()&&found==false;t++){
01170 if(abs(targets[t]-s)<closeness){
01171 closeness = abs(targets[t]-s);
01172 sbest = s;
01173 if(closeness==0)found = true;
01174 }
01175 }
01176 (*literE)->Next();
01177 }
01178 MSG("DmxFast",Msg::kDebug) << "Closest Strip : " << closeness << " --> " << sbest << endl;
01179
01180 demuxedHitPlane.push_back(currentPlane);
01181 demuxedHitStrip.push_back(sbest);
01182 demuxedHitQ.push_back(q);
01183 NdemuxedHits++;
01184 if(kView==PlaneView::kV) NdemuxedHitsV++;
01185 if(kView==PlaneView::kU) NdemuxedHitsU++;
01186
01187 MSG("DmxFast",Msg::kDebug) << "Adding U " << NdemuxedHitsU << " : " << currentPlane << " : " << sbest << endl;
01188
01189 this->DemuxHitE(*literE, sbest);
01190 }
01191 }
01192
01193
01194
01195 if(PlanesAltListsW[i].size()>0){
01196 literW = PlanesAltListsW[i].begin();
01197 kView = (*literW)->GetPlaneView();
01198 currentPlane = (*literW)->GetPlane();
01199 MSG("DmxFast",Msg::kDebug) << " current W Plane : " << currentPlane << endl;
01200 while (PlanesAltListsW[i].size()>0){
01201 literW = PlanesAltListsW[i].begin();
01202 sbest =0;
01203 closeness = 999;
01204 (*literW)->SetFirst();
01205 q = (*literW)->GetCurrentItem().GetPE();
01206 while( (*literW)->IsValid() ){
01207 s = (*literW)->GetCurrentSEId().GetStrip();
01208 bool found = false;
01209 for(unsigned int t=0;t<targets.size()&&found==false;t++){
01210 if(abs(targets[t]-s)<closeness){
01211 closeness = abs(targets[t]-s);
01212 sbest = s;
01213 if(closeness==0)found = true;
01214 }
01215 }
01216 (*literW)->Next();
01217 }
01218 MSG("DmxFast",Msg::kDebug) << "Closest Strip : " << closeness << " --> " << sbest << endl;
01219
01220 demuxedHitPlane.push_back(currentPlane);
01221 demuxedHitStrip.push_back(sbest);
01222 demuxedHitQ.push_back(q);
01223 NdemuxedHits++;
01224 if(kView==PlaneView::kV) NdemuxedHitsV++;
01225 if(kView==PlaneView::kU) NdemuxedHitsU++;
01226
01227 this->DemuxHitW(*literW, sbest);
01228 literW++; }
01229 }
01230
01231 return;
01232 }
01233
01234
01235
01236
01237 void DemuxFast::PrintWhatRemains()
01238 {
01239 vector <PlexSEIdAltL*>::iterator literE;
01240 vector <PlexSEIdAltL*>::iterator literW;
01241
01242 for(int i=0; i<500; i++){
01243 if(PlanesAltListsE[i].size()||PlanesAltListsW[i].size()){
01244
01245 }
01246
01247 if(PlanesAltListsE[i].size()&&PlanesAltListsW[i].size()){
01248 literE = PlanesAltListsE[i].begin();
01249 while (literE != PlanesAltListsE[i].end()){
01250 literW = PlanesAltListsW[i].begin();
01251 while ( literW != PlanesAltListsW[i].end()){
01252 (*literE)->SetFirst();
01253 while( (*literE)->IsValid() ){
01254 (*literW)->SetFirst();
01255 while( (*literW)->IsValid() ){
01256 if((*literE)->GetCurrentSEId().GetStrip()==(*literW)->GetCurrentSEId().GetStrip()){
01257 MSG("DmxFast",Msg::kDebug) << " We have a possibilility " << i << " : " << (*literE)->GetCurrentItem().GetPE()*CalDigitType::kPE << " : " << (*literW)->GetCurrentItem().GetPE()*CalDigitType::kPE << " : " << (*literE)->GetCurrentSEId().GetStrip() << endl;
01258 }
01259 (*literW)->Next();
01260 }
01261 (*literE)->Next();
01262 }
01263 literW++;
01264 }
01265 literE++;
01266 }
01267 }
01268 if(PlanesAltListsE[i].size()){
01269 literE = PlanesAltListsE[i].begin();
01270 while (literE != PlanesAltListsE[i].end()){
01271 (*literE)->SetFirst();
01272 while( (*literE)->IsValid() ){
01273 MSG("DmxFast",Msg::kDebug) << " Single possibilility : " << i << " : " << (*literE)->GetCurrentItem().GetPE()*CalDigitType::kPE << " : " << (*literE)->GetCurrentSEId().GetStrip() << endl;
01274 (*literE)->Next();
01275 }
01276 literE++;
01277 }
01278 }
01279 if(PlanesAltListsW[i].size()){
01280 literW = PlanesAltListsW[i].begin();
01281 while (literW != PlanesAltListsW[i].end()){
01282 (*literW)->SetFirst();
01283 while( (*literW)->IsValid() ){
01284 MSG("DmxFast",Msg::kDebug) << " Single possibilility : " << i << " : " << (*literW)->GetCurrentItem().GetPE()*CalDigitType::kPE << " : " << (*literW)->GetCurrentSEId().GetStrip() << endl;
01285 (*literW)->Next();
01286 }
01287 literW++;
01288 }
01289 }
01290 }
01291
01292 return;
01293 }
01294
01295 bool DemuxFast::SelectHits(bool gold, bool useGold)
01296 {
01297 bool success = false;
01298
01299 for(int ig=1;ig<=ngroup;ig++){
01300
01301 MSG("DmxFast",Msg::kDebug) << "Asking Pattern Master for " << ningroupe[ig] << " : " << ningroupw[ig] << endl;
01302 MSG("DmxFast",Msg::kDebug) << "Returned : " << pMaster->SelectPattern(ningroupe[ig],ningroupw[ig]) << endl;
01303 MyDemuxPattern* pP;
01304 MyDemuxPattern* pBest;
01305 PatternPair wibble;
01306 int smin;
01307 int smax;
01308 int srange;
01309 int srange1;
01310 int srange2;
01311 int count;
01312
01313 pBest = NULL;
01314 count =0;
01315 srange1 = 1000;
01316 srange2 = 1000;
01317 if(pMaster->SelectPattern(ningroupe[ig],ningroupw[ig])){
01318 while( (pP = pMaster->Next())!=NULL ){
01319 count++;
01320 bool patok = true;
01321 smin =999;
01322 smax =0;
01323 for(int i=0; i< pP->Size(); i++){
01324 wibble = pP->GetI(i);
01325 if(patok)patok = _amap[(egroup[ig][wibble.eEntry])][(wgroup[ig][wibble.wEntry])];
01326
01327 int s = _smap[(egroup[ig][wibble.eEntry])][(wgroup[ig][wibble.wEntry])];
01328 if(s<smin)smin=s;
01329 if(s>smax)smax=s;
01330
01331 }
01332 if(patok){
01333 srange = smax-smin;
01334 if(srange<=srange1){
01335 srange2 = srange1;
01336 srange1 = srange;
01337 pBest = pP;
01338 }else{
01339 if(srange<=srange2)srange2=srange;
01340 }
01341 }
01342 }
01343
01344 if(pBest==NULL)return false;
01345
01346 if(srange1 < pBest->Size()+_rangeWindow && srange1+pBest->Size()<srange2){
01347 success = true;
01348 for(int i=0; i< pBest->Size(); i++){
01349 wibble = pBest->GetI(i);
01350
01351 int s = _smap[(egroup[ig][wibble.eEntry])][(wgroup[ig][wibble.wEntry])];
01352
01353 MSG("DmxFast",Msg::kDebug) << " **Using combination " << s << endl;
01354 if(gold)this->GoldHits(egroup[ig][wibble.eEntry],wgroup[ig][wibble.wEntry],s);
01355 if(!gold){
01356 bool found = false;
01357 if(useGold){
01358 for(int i=1;!found && i<=goldplanehit[currentPlane];i++){
01359 if(s==goldhitmap[currentPlane][i])found=true;
01360 }
01361 }
01362 if(!useGold ||found)this->DemuxHits(egroup[ig][wibble.eEntry],wgroup[ig][wibble.wEntry],s);
01363 if( useGold && !found)MSG("DmxFast",Msg::kDebug) << "VETOING THIS HIT " << endl;
01364 }
01365 }
01366 }
01367 }else{
01368
01369 if( (ningroupe[ig]>3) && (ningroupw[ig]>3) ){
01370 success = this->DemuxBigGroup(ig,gold);
01371 }
01372 }
01373 }
01374 MSG("DmxFast",Msg::kDebug) << "Returning " << success << endl;
01375 return success;
01376 }
01377
01378
01379
01380 bool DemuxFast::DemuxBigGroup(int ig,bool gold)
01381 {
01382 bool success = false;
01383 MSG("DmxFast",Msg::kDebug) << "BIG GROUP TRY A DIFFERENT APPROACH" << endl;
01384 int strips[192];
01385 int estrips[192];
01386 int wstrips[192];
01387 for(int i=0;i<192;i++)strips[i]=0;
01388 for(int ie=1;ie<=ningroupe[ig];ie++){
01389 for(int iw=1;iw<=ningroupw[ig];iw++){
01390 if(_amap[(egroup[ig][ie])][(wgroup[ig][iw])]){
01391 int s = _smap[(egroup[ig][ie])][(wgroup[ig][iw])];
01392 strips[s]++;
01393 estrips[s] = ie;
01394 wstrips[s] = iw;
01395 }
01396 }
01397 }
01398 int istartStrip=-1;
01399 int iendStrip=-1;
01400 int ngroups = 0;
01401 int ming = ningroupe[ig];
01402 if(ningroupw[ig]<ming)ming = ningroupw[ig];
01403 int icount;
01404 for(int is=0; is<192-ming; is++){
01405 if(strips[is]==1){
01406 icount = 1;
01407 int iend = is+ming+5;
01408 int ie;
01409 if(iend>191)iend=192;
01410 for(ie=is+1; ie<iend && icount != ming; ie++){
01411 if(strips[ie]>0)icount++;
01412 }
01413 if(icount==ming){
01414 ngroups++;
01415 istartStrip = is;
01416 iendStrip = ie-1;
01417 MSG("DmxFast",Msg::kDebug) << "Found a group : " << is << ":" << ie-1 << endl;
01418 }
01419 }
01420 }
01421 MSG("DmxFast",Msg::kDebug) << "Found " << ngroups << " groups " << endl;
01422 if(ngroups==1){
01423 success = true;
01424 int ie;
01425 int iw;
01426 for(int is=istartStrip; is<=iendStrip;is++){
01427 if(strips[is]==1){
01428 ie = estrips[is];
01429 iw = wstrips[is];
01430 MSG("DmxFast",Msg::kDebug) << " Strip : " << is << " ew " << ie << ":" << iw << endl;
01431 if(gold)this->GoldHits(egroup[ig][ie],wgroup[ig][iw],is);
01432 if(!gold)this->DemuxHits(egroup[ig][ie],wgroup[ig][iw],is);
01433 }
01434 }
01435 }
01436 return success;
01437 }
01438
01439
01440 float DemuxFast::IsItXTalk(int iew, int iplane, int iva, int ipixel)
01441 {
01442
01443 float crossTalk;
01444 if(iew==0){
01445 switch(ipixel){
01446 case 0:
01447 crossTalk = pixelE[iplane][iva][1] +
01448 pixelE[iplane][iva][4];
01449 break;
01450 case 1:
01451 crossTalk = pixelE[iplane][iva][0] +
01452 pixelE[iplane][iva][2] +
01453 pixelE[iplane][iva][5];
01454 break;
01455 case 2:
01456 crossTalk = pixelE[iplane][iva][1] +
01457 pixelE[iplane][iva][3] +
01458 pixelE[iplane][iva][6];
01459 break;
01460 case 3:
01461 crossTalk = pixelE[iplane][iva][2] +
01462 pixelE[iplane][iva][7];
01463 break;
01464 case 4:
01465 crossTalk = pixelE[iplane][iva][0] +
01466 pixelE[iplane][iva][5] +
01467 pixelE[iplane][iva][8];
01468 break;
01469 case 5:
01470 crossTalk = pixelE[iplane][iva][1] +
01471 pixelE[iplane][iva][4] +
01472 pixelE[iplane][iva][6] +
01473 pixelE[iplane][iva][9];
01474 break;
01475 case 6:
01476 crossTalk = pixelE[iplane][iva][2] +
01477 pixelE[iplane][iva][5] +
01478 pixelE[iplane][iva][7] +
01479 pixelE[iplane][iva][10];
01480 break;
01481 case 7:
01482 crossTalk = pixelE[iplane][iva][3] +
01483 pixelE[iplane][iva][6] +
01484 pixelE[iplane][iva][11];
01485 break;
01486 case 8:
01487 crossTalk = pixelE[iplane][iva][4] +
01488 pixelE[iplane][iva][9] +
01489 pixelE[iplane][iva][12];
01490 break;
01491 case 9:
01492 crossTalk = pixelE[iplane][iva][5] +
01493 pixelE[iplane][iva][8] +
01494 pixelE[iplane][iva][10] +
01495 pixelE[iplane][iva][13];
01496 break;
01497 case 10:
01498 crossTalk = pixelE[iplane][iva][6] +
01499 pixelE[iplane][iva][9] +
01500 pixelE[iplane][iva][11] +
01501 pixelE[iplane][iva][14];
01502 break;
01503 case 11:
01504 crossTalk = pixelE[iplane][iva][7] +
01505 pixelE[iplane][iva][10] +
01506 pixelE[iplane][iva][15];
01507 break;
01508 case 12:
01509 crossTalk = pixelE[iplane][iva][8] +
01510 pixelE[iplane][iva][13];
01511 break;
01512 case 13:
01513 crossTalk = pixelE[iplane][iva][9] +
01514 pixelE[iplane][iva][12]+
01515 pixelE[iplane][iva][14];
01516 break;
01517 case 14:
01518 crossTalk = pixelE[iplane][iva][10] +
01519 pixelE[iplane][iva][13]+
01520 pixelE[iplane][iva][15];
01521 break;
01522 case 15:
01523 crossTalk = pixelE[iplane][iva][11]+
01524 pixelE[iplane][iva][14];
01525 break;
01526 default:
01527 crossTalk = 0;
01528 break;
01529 }
01530 }else{
01531 switch(ipixel){
01532 case 0:
01533 crossTalk = pixelW[iplane][iva][1] +
01534 pixelW[iplane][iva][4];
01535 break;
01536 case 1:
01537 crossTalk = pixelW[iplane][iva][0] +
01538 pixelW[iplane][iva][2] +
01539 pixelW[iplane][iva][5];
01540 break;
01541 case 2:
01542 crossTalk = pixelW[iplane][iva][1] +
01543 pixelW[iplane][iva][3] +
01544 pixelW[iplane][iva][6];
01545 break;
01546 case 3:
01547 crossTalk = pixelW[iplane][iva][2] +
01548 pixelW[iplane][iva][7];
01549 break;
01550 case 4:
01551 crossTalk = pixelW[iplane][iva][0] +
01552 pixelW[iplane][iva][5] +
01553 pixelW[iplane][iva][8];
01554 break;
01555 case 5:
01556 crossTalk = pixelW[iplane][iva][1] +
01557 pixelW[iplane][iva][4] +
01558 pixelW[iplane][iva][6] +
01559 pixelW[iplane][iva][9];
01560 break;
01561 case 6:
01562 crossTalk = pixelW[iplane][iva][2] +
01563 pixelW[iplane][iva][5] +
01564 pixelW[iplane][iva][7] +
01565 pixelW[iplane][iva][10];
01566 break;
01567 case 7:
01568 crossTalk = pixelW[iplane][iva][3] +
01569 pixelW[iplane][iva][6] +
01570 pixelW[iplane][iva][11];
01571 break;
01572 case 8:
01573 crossTalk = pixelW[iplane][iva][4] +
01574 pixelW[iplane][iva][9] +
01575 pixelW[iplane][iva][12];
01576 break;
01577 case 9:
01578 crossTalk = pixelW[iplane][iva][5] +
01579 pixelW[iplane][iva][8] +
01580 pixelW[iplane][iva][10] +
01581 pixelW[iplane][iva][13];
01582 break;
01583 case 10:
01584 crossTalk = pixelW[iplane][iva][6] +
01585 pixelW[iplane][iva][9] +
01586 pixelW[iplane][iva][11] +
01587 pixelW[iplane][iva][14];
01588 break;
01589 case 11:
01590 crossTalk = pixelW[iplane][iva][7] +
01591 pixelW[iplane][iva][10] +
01592 pixelW[iplane][iva][15];
01593 break;
01594 case 12:
01595 crossTalk = pixelW[iplane][iva][8] +
01596 pixelW[iplane][iva][13];
01597 break;
01598 case 13:
01599 crossTalk = pixelW[iplane][iva][9] +
01600 pixelW[iplane][iva][12]+
01601 pixelW[iplane][iva][14];
01602 break;
01603 case 14:
01604 crossTalk = pixelW[iplane][iva][10] +
01605 pixelW[iplane][iva][13]+
01606 pixelW[iplane][iva][15];
01607 break;
01608 case 15:
01609 crossTalk = pixelW[iplane][iva][11]+
01610 pixelW[iplane][iva][14];
01611 break;
01612 default:
01613 crossTalk = 0.0;
01614 break;
01615 }
01616 }
01617
01618 return crossTalk;
01619 }
01620
01621 void DemuxFast::DemuxHits(int ie,int iw, int is ){
01622
01623 float qE;
01624 float qW;
01625
01626 this->DemuxHitE(ie,is);
01627 this->DemuxHitW(iw,is);
01628
01629 qE= _pAmapE[ie]->GetBestItem().GetPE()*CalDigitType::kPE;
01630 qW= _pAmapW[iw]->GetBestItem().GetPE()*CalDigitType::kPE;
01631
01632 demuxedHitPlane.push_back(currentPlane);
01633 demuxedHitStrip.push_back(is);
01634 demuxedHitQ.push_back(qE+qW);
01635 NdemuxedHits++;
01636
01637 planehit[currentPlane] += 1;
01638 hitmap[currentPlane][planehit[currentPlane]] = is;
01639 qhitmapE[currentPlane][planehit[currentPlane]] = qE;
01640 qhitmapW[currentPlane][planehit[currentPlane]] = qW;
01641
01642 return;
01643
01644 }
01645
01646 void DemuxFast::GoldHits(int,
01647 int,
01648 int is)
01649 {
01650 goldplanehit[currentPlane] += 1;
01651 goldhitmap[currentPlane][goldplanehit[currentPlane]] = is;
01652
01653 return;
01654 }
01655
01656
01657 void DemuxFast::MakeGoldGuide(){
01658
01659 for(int ip=1;ip<500;ip++){
01660 if(goldplanehit[ip-1]>0||goldplanehit[ip+1]>0){
01661 float n =0;
01662 float tot = 0;
01663 for(int i=1;i<=goldplanehit[ip-1];i++){
01664 n+=1;
01665 tot += goldhitmap[ip-1][i];
01666 }
01667 for(int i=1;i<=goldplanehit[ip+1];i++){
01668 n+=1;
01669 tot += goldhitmap[ip+1][i];
01670 }
01671 _goldGuide[ip] = tot/n;
01672 MSG("DmxFast",Msg::kDebug) << "Gold Guide " << ip << " : " << _goldGuide[ip] << endl;
01673 }
01674 }
01675
01676 return;
01677
01678 }
01679
01680
01681 void DemuxFast::DemuxHitE(int ie, int is){
01682
01683 PlexSEIdAltL* pAltL;
01684
01685 pAltL = _pAmapE[ie];
01686 this->DemuxHitE(pAltL,is);
01687 return;
01688 }
01689
01690
01691 void DemuxFast::DemuxHitW(int iw, int is){
01692
01693 PlexSEIdAltL* pAltL;
01694 pAltL = _pAmapW[iw];
01695 this->DemuxHitW(pAltL,is);
01696
01697 return;
01698 }
01699
01700 void DemuxFast::DemuxHitE(PlexSEIdAltL* pAltL, int is){
01701
01702 vector <PlexSEIdAltL*>::iterator literA;
01703 bool notFound;
01704 float q;
01705
01706 pAltL->SetFirst();
01707
01708
01709 q = pAltL->GetCurrentItem().GetPE();
01710 notFound = true;
01711 while(notFound && pAltL->IsValid()){
01712 if(pAltL->GetCurrentSEId().GetStrip()==is){
01713 pAltL->SetCurrentWeight(1.);
01714 notFound = false;
01715 }
01716 if(notFound)pAltL->Next();
01717 }
01718
01719 literA = PlanesAltListsE[currentPlane].begin();
01720 notFound = true;
01721 while (notFound && literA != PlanesAltListsE[currentPlane].end()){
01722 if(*literA==pAltL){
01723 PlanesAltListsE[currentPlane].erase(literA);
01724 notFound = false;
01725 }
01726 literA++;
01727 }
01728
01729
01730 return;
01731 }
01732
01733 void DemuxFast::DemuxHitW(PlexSEIdAltL* pAltL, int is){
01734
01735
01736 vector <PlexSEIdAltL*>::iterator literA;
01737 bool notFound;
01738 float q;
01739
01740
01741 pAltL->SetFirst();
01742
01743 notFound = true;
01744 q = pAltL->GetCurrentItem().GetPE();
01745 while(notFound && pAltL->IsValid()){
01746 if(pAltL->GetCurrentSEId().GetStrip()==is){
01747 pAltL->SetCurrentWeight(1.);
01748 notFound = false;
01749 }
01750 if(notFound)pAltL->Next();
01751 }
01752
01753 literA = PlanesAltListsW[currentPlane].begin();
01754 notFound = true;
01755 while (notFound && literA != PlanesAltListsW[currentPlane].end()){
01756 if(*literA==pAltL){
01757 PlanesAltListsW[currentPlane].erase(literA);
01758 notFound = false;
01759 }
01760 literA++;
01761 }
01762 return;
01763 }
01764
01765
01766 void DemuxFast::EndJob()
01767 {
01768
01769 TFile *hfile = new TFile("FastDeMuxHistos.root","recreate");
01770
01771 MSG("DmxFast",Msg::kDebug) << " Writing Histograms to file : DeMuxHistos.root " << endl;
01772
01773 hfile->Close();
01774 delete hfile;
01775
01776 }
01777