00001
00002
00003
00004
00005
00007 #include <cmath>
00008 #include <fstream>
00009 #include <map>
00010 #include <sstream>
00011 #include <string>
00012
00013 #include "TH1F.h"
00014 #include "TFile.h"
00015 #include "Conventions/Detector.h"
00016 #include "NueAna/NueRecord.h"
00017 #include "MessageService/MsgService.h"
00018 #include "MinosObjectMap/MomNavigator.h"
00019 #include "MessageService/MsgService.h"
00020 #include "JobControl/JobCModuleRegistry.h"
00021
00022 #include "AnalysisNtuples/ANtpDefaultValue.h"
00023 #include "TClass.h"
00024 #include "TDataType.h"
00025 #include "TDataMember.h"
00026 #include "TRealData.h"
00027 #include "PETrimmer.h"
00028 #include "StandardNtuple/NtpStRecord.h"
00029
00030 #include "CandNtupleSR/NtpSRRecord.h"
00031
00032 #include "TClonesArray.h"
00033
00034 #include "CandNtupleSR/NtpSRStrip.h"
00035 #include "CandNtupleSR/NtpSREvent.h"
00036 #include "CandNtupleSR/NtpSRShower.h"
00037 #include "CandNtupleSR/NtpSRTrack.h"
00038
00039 #include "TObject.h"
00040
00041 #include "VertexFinder/NtpVtxFinder/NtpVtxFinder.h"
00042
00043 JOBMODULE(PETrimmer, "PETrimmer",
00044 "Filter out strips below a given PE");
00045
00046 CVSID("$Id: PETrimmer.cxx,v 1.15 2009/08/12 15:22:46 scavan Exp $");
00047
00048
00049
00050 PETrimmer::PETrimmer():
00051 pecut(0.0),
00052 updateEventEnergy(1)
00053 {}
00054
00055
00056
00057 PETrimmer::~PETrimmer()
00058 {}
00059
00060
00061 void PETrimmer::BeginJob()
00062 {
00063
00064 }
00065
00066
00067 JobCResult PETrimmer::Reco(MomNavigator* mom)
00068 {
00069 bool foundST=false;
00070
00071
00072
00073
00074
00075
00076 std::vector<TObject*> records = mom->GetFragmentList("NtpStRecord");
00077
00078
00079 for(unsigned int i=0;i<records.size();i++)
00080 {
00081
00082 NtpStRecord *str=dynamic_cast<NtpStRecord *>(records[i]);
00083 if(str){
00084 foundST=true;
00085
00086 }else{
00087 continue;
00088 }
00089
00090
00091 TrimRecord(str);
00092
00093 }
00094
00095 return JobCResult::kPassed;
00096
00097 }
00098
00099
00100 void PETrimmer::TrimRecord(NtpStRecord *str)
00101 {
00102 DumpIt(str);
00103
00104
00105
00106 MSG("PETrimmer",Msg::kDebug)<< "Cutting out strips below "<<pecut<<" pe"<<endl;
00107
00108 std::vector<const NtpSRStrip* > stp = str->GetStrips();
00109
00110 if(stp.size()<1)return;
00111
00112 std::vector< NtpSREvent* > evts;
00113 std::vector< NtpSRShower* > shw;
00114 std::vector< NtpSRTrack* > trk;
00115
00116
00117 MSG("PETrimmer",Msg::kDebug)<< "Snarl " << str->GetHeader().GetSnarl() << endl;
00118
00119
00120
00121 TClonesArray* tc = str->evt;
00122 for(int i=0;i<tc->GetEntries();i++)
00123 evts.push_back((NtpSREvent*)tc->At(i));
00124
00125 TClonesArray* ts = str->shw;
00126 for(int i=0;i<ts->GetEntries();i++)
00127 shw.push_back((NtpSRShower*)ts->At(i));
00128
00129 TClonesArray* tt = str->trk;
00130 for(int i=0;i<tt->GetEntries();i++)
00131 trk.push_back((NtpSRTrack*)tt->At(i));
00132
00133
00134 for(int i=0;i<(int)evts.size();i++)
00135 {
00136 MSG("PETrimmer",Msg::kDebug)<< "Event "<<i<<" strips "<<evts[i]->nstrip<<" idx "<<evts[i]->index<<endl;
00137 };
00138
00139
00140
00141
00143 for(int i=0;i<(int)shw.size();i++)
00144 {
00145
00146
00147
00148
00149 if(shw[i]->stp[shw[i]->nstrip-1]<0)
00150 {
00151 int nstrip = shw[i]->nstrip;
00152 MSG("PETrimmer",Msg::kError)<<"Shower "<<i<<" is missing the last strip!!!! adjusting strip size from "<< nstrip <<" to "<<(nstrip-1)<<endl;
00153 shw[i]->nstrip=shw[i]->nstrip-1;
00154 shw[i]->nstpcnt=shw[i]->nstrip;
00155 }
00156
00157 }
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203 int pepass[100000];
00204 float stripe_trk[3 * 100000];
00205 float stripe_shw[3 * 100000];
00206
00207
00208
00209
00210 int goodshower[1000];
00211 for(int i=0;i<1000;i++)goodshower[i]=1;
00212
00213 int goodevent[1000];
00214 for(int i=0;i<1000;i++)goodevent[i]=1;
00215
00216 int goodtrack[1000];
00217 for(int i=0;i<1000;i++)goodtrack[i]=1;
00218
00219
00220 for(int i=0;i<(int)stp.size();i++)
00221 {
00222 pepass[i]=stp[i]->ph0.pe+stp[i]->ph1.pe - pecut > 0.0001 ? 1: 0;
00223
00224 for(int j=0;j<3;j++)
00225 {
00226 stripe_trk[j + 3*i]=0;
00227 stripe_shw[j + 3*i]=0;
00228 }
00229 }
00230
00231
00232
00233
00234
00235 for(int i=0;i<(int)shw.size();i++)
00236 {
00237 MSG("PETrimmer",Msg::kDebug)<< "Shw "<<i<<" nstrip " << shw[i]->nstrip<< " stpcnt "<<shw[i]->nstpcnt<<endl;
00238 NtpSRShower *sh = shw[i];
00239 goodshower[i]=CleanShower(sh,stp,pepass,stripe_shw);
00240 }
00241
00242
00243
00244 for(int i=0;i<(int)trk.size();i++)
00245 {
00246 MSG("PETrimmer",Msg::kDebug)<< "Trk "<<i<<" nstrip " << trk[i]->nstrip<< " stpcnt "<<trk[i]->nstpcnt<<endl;
00247 NtpSRTrack *tr = trk[i];
00248 goodtrack[i]=CleanTrack(tr,stp,pepass,stripe_trk);
00249 }
00250
00251
00252 for(int i=0;i<(int)evts.size();i++)
00253 {
00254 MSG("PETrimmer",Msg::kDebug)<< "Event "<<i<<" nstrip " << evts[i]->nstrip<< " stpcnt "<<evts[i]->nstpcnt<<endl;
00255 NtpSREvent* evt = evts[i];
00256 goodevent[i]=CleanEvent(evt,shw,trk,stp,pepass,stripe_trk,stripe_shw,goodshower,goodtrack);
00257
00258
00259
00260 if(!goodevent[i])continue;
00261
00262 NtpVtxFinder finder(i,str);
00263 if(finder.FindVertex() >0)
00264 {
00265 evt->vtx.x=finder.VtxX();
00266 evt->vtx.y=finder.VtxY();
00267 evt->vtx.z=finder.VtxZ();
00268 evt->vtx.u=finder.VtxU();
00269 evt->vtx.v=finder.VtxV();
00270 evt->vtx.t=finder.VtxT();
00271 evt->vtx.plane=finder.VtxPlane();
00272 }
00273
00274 int thisVtxPlane=evt->vtx.plane;
00275 int invtxwindow=0;
00276 for(int j=0;j<evt->nstpcnt;j++)
00277 {
00278 if(evt->stp[j]<0)continue;
00279 if(pepass[evt->stp[j]])
00280 if(stp[evt->stp[j]]->plane >= thisVtxPlane && stp[evt->stp[j]]->plane < (thisVtxPlane+5))
00281 {
00282 invtxwindow=1;
00283 break;
00284 }
00285 }
00286
00287 if(!invtxwindow)
00288 {
00289 float evtpes=0;
00290 for(int j=0;j<evt->nstpcnt;j++)
00291 {
00292 if(evt->stp[j]<0)continue;
00293 if(pepass[evt->stp[j]])
00294 evtpes+= (stp[evt->stp[j]]->ph0.pe + stp[evt->stp[j]]->ph1.pe);
00295 }
00296 MSG("PETrimmer",Msg::kWarning)<<"removing "<<evtpes<<" pe event that has no strips in vtx window!"<<endl;
00297
00298 goodevent[i]=0;
00299 }
00300
00301 }
00302
00303
00304
00305
00306
00307
00308 std::vector<NtpSREvent *>todelrec;
00309
00310
00311 int off=0;
00312 for(int i=0;i<(int)evts.size();i++)
00313 {
00314 if(!goodevent[i+off])
00315 {
00316
00317 MSG("PETrimmer",Msg::kDebug)<< "Event removed from snarl "<<i+off<<endl;
00318
00319 todelrec.push_back(evts[i]);
00320 evts.erase(evts.begin()+i);
00321 i--;
00322 off++;
00323
00324 }
00325
00326 }
00327
00328
00329
00330
00331
00332 for(int i=0;i<(int)evts.size();i++)
00333 {
00334 if(evts[i]->primtrk > -1){
00335 bool isOK = false;
00336 int longest = 0;
00337 int longestTrackIndex = -1;
00338
00339 for(int j=0;j<(int)evts[i]->ntrack && !isOK; j++)
00340 {
00341 int index = evts[i]->trk[j];
00342 if(index == -1) continue;
00343 if(index == evts[i]->primtrk) isOK = true;
00344
00345 NtpSRTrack* track = trk[index];
00346 int length = TMath::Abs(track->plane.end - track->plane.beg);
00347 if(length > longest){
00348 longest = length; longestTrackIndex = j;
00349 }
00350 }
00351 if(!isOK) { evts[i]->primtrk = longestTrackIndex;
00352
00353 }
00354 }
00355
00356
00357 if(evts[i]->primshw>-1) {
00358 bool isOK = false;
00359
00360
00361
00362 double biggestE = -1;
00363 double closeE = -1;
00364 int primShwIndex = -1;
00365 int largestShwIndex = -1;
00366 int closeShwIndex = -1;
00367 double dzLarge = 0;
00368 double dzClose = 1e6;
00369 NtpSRTrack *primaryTrack = 0;
00370 if(evts[i]->primtrk != -1) primaryTrack = trk[evts[i]->trk[evts[i]->primtrk]];
00371
00372 for(int j=0;j<(int)evts[i]->nshower && !isOK;j++)
00373 {
00374 int index = evts[i]->shw[j];
00375 if(index == -1) continue;
00376 if(index==evts[i]->primshw) isOK = true;
00377
00378 NtpSRShower* shower = shw[index];
00379 if(shower->ph.mip > biggestE){
00380 largestShwIndex = j;
00381 biggestE = shower->ph.mip;
00382 if(primaryTrack) dzLarge = fabs(shower->vtx.z - primaryTrack->vtx.z);
00383 }
00384 if(primaryTrack){
00385 if(fabs(shower->vtx.z - primaryTrack->vtx.z) < dzClose){
00386 dzClose = fabs(shower->vtx.z - primaryTrack->vtx.z);
00387 closeShwIndex = j;
00388 closeE = shower->ph.mip;
00389 }
00390 }
00391 }
00392 if(!isOK){
00393 float eratio = 1;
00394 if(biggestE > 0) eratio = closeE/biggestE;
00395
00396
00397 if(closeShwIndex > -1 && (dzLarge - dzClose) > 1 && eratio > 0.2)
00398 primShwIndex = closeShwIndex;
00399 else
00400 primShwIndex = largestShwIndex;
00401
00402 if(primShwIndex > -1 && primaryTrack){
00403 NtpSRShower *PShw = shw[evts[i]->shw[primShwIndex]];
00404 if(PShw == 0) cout<<"Failed to load shower - VERY BAD"<<endl;
00405 if(fabs(PShw->vtx.z - primaryTrack->vtx.z) > 0.5 &&
00406 PShw->shwph.linNCgev < 2.0){
00407 primShwIndex = -1;
00408 }
00409 }
00410 evts[i]->primshw = primShwIndex;
00411
00412
00413 }
00414
00415 }
00416 }
00417
00418
00419
00420
00421
00422
00423
00424 for(int i=0;i<(int)todelrec.size();i++)
00425 str->evt->Remove(todelrec[i]);
00426
00427
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441 evts.clear();
00442 for(int i=0;i<tc->GetEntries();i++)
00443 {
00444 NtpSREvent * e = ((NtpSREvent*)str->evt->At(i));
00445 if(!e)continue;
00446 e->index=i;
00447 evts.push_back((NtpSREvent*)str->evt->At(i));
00448 }
00449
00450
00451 for(int i=0;i<(int)evts.size();i++)
00452 {
00453 MSG("PETrimmer",Msg::kDebug)<< "Event "<<i<<" strips "<<evts[i]->nstrip<<" idx "<<evts[i]->index<<endl;
00454 };
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475 for(int i=0;i<(int)evts.size();i++)
00476 {
00477 std::ostringstream s;
00478 s<<" showers ";
00479 for(int j=0;j<evts[i]->nshower;j++)
00480 s<<" " << evts[i]->shw[j] <<" ";
00481 s<<" tracks ";
00482 for(int j=0;j<evts[i]->ntrack;j++)
00483 s<<" " << evts[i]->trk[j] <<" ";
00484
00485
00486 MSG("PETrimmer",Msg::kDebug)<< "Event done strips "<<evts[i]->nstrip<< s.str() << endl;
00487
00488 }
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499 }
00500
00501
00502 bool showergreater(std::pair<float, NtpSRShower *> p1, std::pair<float, NtpSRShower *> p2){return p1.first < p2.first;}
00503 bool trackgreater(std::pair<float, NtpSRTrack *> p1, std::pair<float, NtpSRTrack *> p2){return p1.first < p2.first;}
00504
00505
00506
00507 int PETrimmer::CleanEvent(NtpSREvent * evt, std::vector< NtpSRShower* > shw, std::vector< NtpSRTrack* > trk, std::vector<const NtpSRStrip* > stp, int *pepass, float *stripe_trk, float* stripe_shw,int*goodshower,int*goodtrack)
00508 {
00509 int goodevent=1;
00510
00511
00512
00513 std::map<int,int> shwstpmap;
00514
00515
00516 for(int i=0;i<evt->nshower;i++)
00517 {
00518 if(!goodshower[evt->shw[i]])
00519 {
00520
00521 for(int j=0;j<shw[evt->shw[i]]->nstrip;j++)
00522 shwstpmap[shw[evt->shw[i]]->stp[j]]=1;
00523
00524
00525 evt->shw[i]=-1;
00526
00527 }
00528 }
00529
00530
00531 for(int i=0;i<evt->nshower;i++)
00532 {
00533 if(evt->shw[i]<0)
00534 {
00535 for(int j=i+1;j<evt->nshower;j++)
00536 evt->shw[j-1]=evt->shw[j];
00537 evt->shw[evt->nshower-1]=-1;
00538 evt->nshower--;
00539 i--;
00540 }
00541 }
00542
00543
00544
00545
00546
00547 for(int i=0;i<evt->ntrack;i++)
00548 {
00549 if(evt->trk[i]<0)continue;
00550 if(!goodtrack[evt->trk[i]])
00551 {
00552
00553 for(int j=0;j<trk[evt->trk[i]]->nstrip;j++)
00554 shwstpmap[trk[evt->trk[i]]->stp[j]]=1;
00555
00556
00557 evt->trk[i]=-1;
00558
00559 }
00560 }
00561
00562
00563 for(int i=0;i<evt->ntrack;i++)
00564 {
00565 if(evt->trk[i]<0)
00566 {
00567 for(int j=i+1;j<evt->ntrack;j++)
00568 evt->trk[j-1]=evt->trk[j];
00569 evt->trk[evt->ntrack-1]=-1;
00570 evt->ntrack--;
00571 i--;
00572 }
00573 }
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584 for(int i=0;i<evt->ntrack;i++)
00585 {
00586 for(int j=0;j<trk[evt->trk[i]]->nstrip;j++)
00587 {
00588 shwstpmap[trk[evt->trk[i]]->stp[j]]=0;
00589
00590
00591 }
00592 }
00593
00594
00595 for(int i=0;i<evt->nshower;i++)
00596 {
00597 for(int j=0;j<shw[evt->shw[i]]->nstrip;j++)
00598 {
00599 shwstpmap[shw[evt->shw[i]]->stp[j]]=0;
00600
00601
00602 }
00603 }
00604
00605
00606
00607 std::map<int,int>::iterator iter;
00608 for(iter=shwstpmap.begin();iter!=shwstpmap.end();iter++)
00609 {
00610
00611
00612 if(iter->second==1)
00613 {
00614 int j=evt->nstrip;
00615 for(int i=0;i<evt->nstrip;i++)
00616 {
00617 if(evt->stp[i]==iter->first)
00618 {
00619 j=i;
00620 break;
00621 }
00622 }
00623 for(int i=j;i<evt->nstrip-1;i++)
00624 {
00625 evt->stp[i]=evt->stp[i+1];
00626
00627 }
00628
00629 evt->stp[evt->nstrip-1]=-1;
00630 evt->nstrip--;
00631 evt->nstpcnt--;
00632 }
00633
00634 }
00635
00636 if(evt->nstrip<1)return 0;
00637
00638
00639 int cutcount =0;
00640
00641
00642 std::vector<float> stpph0sigmap;
00643 std::vector<float> stpph0mip;
00644 std::vector<float> stpph0gev;
00645 std::vector<float> stpph1sigmap;
00646 std::vector<float> stpph1mip;
00647 std::vector<float> stpph1gev;
00648 std::vector<int> stpid;
00649
00650 if(updateEventEnergy){
00651
00652 evt->ph.raw =0;
00653 evt->ph.pe =0;
00654 evt->ph.sigcor =0;
00655 evt->ph.siglin =0;
00656 evt->ph.sigmap =0;
00657
00658 evt->ph.gev =0;
00659 }
00660
00661 int us=0;
00662 int vs=0;
00663 for(int j=0;j<evt->nstpcnt;j++)
00664 {
00665
00666
00667 if(evt->stp[j]<0)continue;
00668
00669
00670
00671
00672 if(pepass[evt->stp[j]])
00673 {
00674
00675
00676
00677
00678
00679
00680 stpid.push_back(evt->stp[j]);
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692 if(updateEventEnergy){
00693
00694
00695 evt->ph.raw += (stp[evt->stp[j]]->ph0.raw + stp[evt->stp[j]]->ph1.raw);
00696 evt->ph.pe += (stp[evt->stp[j]]->ph0.pe + stp[evt->stp[j]]->ph1.pe);
00697 evt->ph.sigcor += (stp[evt->stp[j]]->ph0.sigcor + stp[evt->stp[j]]->ph1.sigcor);
00698 evt->ph.siglin += (stp[evt->stp[j]]->ph0.siglin + stp[evt->stp[j]]->ph1.siglin);
00699
00700
00701
00702
00703
00704 evt->ph.sigmap += stripe_trk[3*evt->stp[j]]>0 ? stripe_trk[3*evt->stp[j]] :stripe_shw[3*evt->stp[j]];
00705
00706
00707
00708
00709
00710
00711 std::vector<std::pair<float, NtpSRShower *> >showers;
00712 std::vector<std::pair<float, NtpSRTrack *> >tracks;
00713
00714 for(int k=0;k<evt->nshower;k++)
00715 showers.push_back(make_pair((float)shw[evt->shw[k]]->ph.mip,shw[evt->shw[k]]));
00716 for(int k=0;k<evt->ntrack;k++)
00717 tracks.push_back(make_pair((float)trk[evt->trk[k]]->ph.mip,trk[evt->trk[k]]));
00718
00719
00720 std::sort(showers.begin(),showers.end(),showergreater);
00721 std::sort(tracks.begin(),tracks.end(),trackgreater);
00722
00723 float ees[100000];
00724 for(int k=0;k<100000;k++)ees[k]=0;
00725
00726 for(unsigned int k=0;k<showers.size();k++)
00727 for(int j=0;j<showers[k].second->nstrip;j++)
00728 {
00729 int sidx = showers[k].second->stp[j];
00730 if(sidx>0 && sidx < 100000)
00731 {
00732 if(ees[sidx]==0)ees[sidx]=showers[k].second->stpph0mip[j]+showers[k].second->stpph1mip[j];
00733 }
00734 }
00735
00736 for(unsigned int k=0;k<tracks.size();k++)
00737 for(int j=0;j<tracks[k].second->nstrip;j++)
00738 {
00739 int sidx = tracks[k].second->stp[j];
00740 if(sidx>0 && sidx < 100000)
00741 {
00742 if(ees[sidx]==0)ees[sidx]=tracks[k].second->stpph0mip[j]+tracks[k].second->stpph1mip[j];
00743 }
00744 }
00745
00746 float summeu=0;
00747 for(int k=0;k<evt->nstrip;k++)
00748 if(ees[evt->stp[k]] > 0 && ees[evt->stp[k]] < 100000)
00749 summeu+=ees[evt->stp[k]];
00750
00751 evt->ph.gev=summeu;
00752
00753
00754 }
00755
00756 if(stp[evt->stp[j]]->planeview==2)
00757 us++;
00758 if(stp[evt->stp[j]]->planeview==3)
00759 vs++;
00760
00761
00762 }else{
00763 cutcount++;
00764 }
00765 }
00766
00767
00768 MSG("PETrimmer",Msg::kDebug)<<"Cut "<<cutcount<<" strips from event!"<<endl;
00769 MSG("PETrimmer",Msg::kDebug)<<"Shower us "<<us << " vs "<< vs <<endl;
00770
00771 if(us==0 || vs==0)
00772 {
00773 goodevent=0;
00774 return goodevent;
00775 }
00776
00777
00778
00779
00780
00781
00782
00783
00784
00785 if (cutcount==0)return goodevent;
00786
00787
00788 for(int j=0;j<evt->nstpcnt;j++)
00789 {
00790 evt->stp[j]=-1;
00791
00792
00793
00794
00795
00796
00797 }
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819 int planes[1000];
00820 for(int i=0;i<1000;i++)planes[i]=0;
00821
00822 evt->nstpcnt=stpid.size();
00823 evt->nstrip=stpid.size();
00824 for(int j=0;j<(int)stpid.size();j++)
00825 {
00826 if(stpid[j]<0 || stpid[j]>(int)stp.size()-1)continue;
00827
00828 int p=stp[stpid[j]]->plane;
00829 if(p>-1 && p < 1000) planes[p]=stp[stpid[j]]->planeview;
00830
00831
00832 if(stpid[j]>-1 && stpid[j] < (int)stp.size())
00833 evt->stp[j]=stpid[j];
00834
00835
00836
00837
00838
00839
00840 }
00841
00842
00843 int totplanes =0;
00844 int begu=1000;
00845 int begv=1000;
00846 int endu=0;
00847 int endv=0;
00848 int nu=0;
00849 int nv=0;
00850 for(int i=0;i<1000;i++)
00851 {
00852 if(planes[i]>0)totplanes++;
00853 if(planes[i]==2)
00854 {
00855 nu++;
00856 begu=begu<i? begu:i;
00857 endu=endu<i? i :endu;
00858 }else if(planes[i]==3)
00859 {
00860 nv++;
00861 begv=begv<i? begv:i;
00862 endv=endv<i?i:endv;
00863 }
00864 }
00865 evt->plane.n=totplanes;
00866 evt->plane.nu=nu;
00867 evt->plane.nv=nv;
00868 evt->plane.beg=begu<begv?begu:begv;
00869 evt->plane.begu=begu;
00870 evt->plane.begv=begv;
00871 evt->plane.end=endu<endv?endv:endu;
00872 evt->plane.endu=endu;
00873 evt->plane.endv=endv;
00874
00875
00876 return goodevent;
00877
00878 }
00879
00880
00881
00882
00883
00884 int PETrimmer::CleanShower(NtpSRShower * shw, std::vector<const NtpSRStrip* > stp, int *pepass, float* stripe)
00885 {
00886 int goodshower=1;
00887 int cutcount =0;
00888
00889
00890 std::vector<float> stpph0sigmap;
00891 std::vector<float> stpph0mip;
00892 std::vector<float> stpph0gev;
00893 std::vector<float> stpph1sigmap;
00894 std::vector<float> stpph1mip;
00895 std::vector<float> stpph1gev;
00896 std::vector<int> stpid;
00897
00898 int us=0;
00899 int vs=0;
00900 for(int j=0;j<shw->nstpcnt;j++)
00901 {
00902
00903
00904
00905
00906 if(pepass[shw->stp[j]])
00907 {
00908
00909
00910 stpid.push_back(shw->stp[j]);
00911 stpph0sigmap.push_back(shw->stpph0sigmap[j]);
00912 stpph1sigmap.push_back(shw->stpph1sigmap[j]);
00913 stpph0gev.push_back(shw->stpph0gev[j]);
00914 stpph1gev.push_back(shw->stpph1gev[j]);
00915 stpph0mip.push_back(shw->stpph0mip[j]);
00916 stpph1mip.push_back(shw->stpph1mip[j]);
00917
00918 stripe[shw->stp[j]*3]= shw->stpph0sigmap[j]+shw->stpph1sigmap[j];
00919 stripe[1+shw->stp[j]*3]= shw->stpph0mip[j]+shw->stpph1mip[j];
00920 stripe[2+shw->stp[j]*3]= shw->stpph0gev[j]+shw->stpph1gev[j];
00921
00922 if(stp[shw->stp[j]]->planeview==2)
00923 us++;
00924 if(stp[shw->stp[j]]->planeview==3)
00925 vs++;
00926
00927
00928 }else{
00929 cutcount++;
00930
00931
00932 shw->ph.raw -= (stp[shw->stp[j]]->ph0.raw + stp[shw->stp[j]]->ph1.raw);
00933 shw->ph.pe -= (stp[shw->stp[j]]->ph0.pe + stp[shw->stp[j]]->ph1.pe);
00934 shw->ph.sigcor -= (stp[shw->stp[j]]->ph0.sigcor + stp[shw->stp[j]]->ph1.sigcor);
00935 shw->ph.siglin -= (stp[shw->stp[j]]->ph0.siglin + stp[shw->stp[j]]->ph1.siglin);
00936 shw->ph.sigmap -= (shw->stpph0sigmap[j] + shw->stpph1sigmap[j]);
00937 shw->ph.mip -= (shw->stpph0mip[j] + shw->stpph1mip[j]);
00938 shw->ph.gev -= (shw->stpph0gev[j] + shw->stpph1gev[j]);
00939
00940 }
00941
00942
00943 }
00944
00945 MSG("PETrimmer",Msg::kDebug)<<"Shower us "<<us << " vs "<< vs <<endl;
00946 if(us ==0 || vs==0)goodshower=0;
00947
00948 MSG("PETrimmer",Msg::kDebug)<<"Cut "<<cutcount<<" strips from shower!"<<endl;
00949
00950
00951 if (cutcount==0)return goodshower;
00952
00953
00954 for(int j=0;j<shw->nstpcnt;j++)
00955 {
00956 shw->stp[j]=-1;
00957 shw->stpph0sigmap[j]=0;
00958 shw->stpph1sigmap[j]=0;
00959 shw->stpph0gev[j]=0;
00960 shw->stpph1gev[j]=0;
00961 shw->stpph0mip[j]=0;
00962 shw->stpph1mip[j]=0;
00963 }
00964
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976
00977
00978
00979
00980
00981
00982
00983
00984
00985 shw->nstpcnt=stpid.size();
00986 shw->nstrip=stpid.size();
00987
00988 for(int j=0;j<(int)stpid.size();j++)
00989 {
00990 shw->stp[j]=-1;
00991 if(stpid[j]>-1 && stpid[j] < (int)stp.size())
00992 shw->stp[j]=stpid[j];
00993 shw->stpph0sigmap[j]=stpph0sigmap[j];
00994 shw->stpph1sigmap[j]=stpph1sigmap[j];
00995 shw->stpph0gev[j]=stpph0gev[j];
00996 shw->stpph1gev[j]=stpph1gev[j];
00997 shw->stpph0mip[j]=stpph0mip[j];
00998 shw->stpph1mip[j]=stpph1mip[j];
00999 }
01000
01001 return goodshower;
01002
01003 }
01004
01005
01006
01007
01008
01009 int PETrimmer::CleanTrack(NtpSRTrack * trk, std::vector<const NtpSRStrip* > stp, int *pepass, float* stripe)
01010 {
01011 int cutcount =0;
01012 int goodtrack=1;
01013
01014 std::vector<float> stpph0sigmap;
01015 std::vector<float> stpph0mip;
01016 std::vector<float> stpph0gev;
01017 std::vector<float> stpph1sigmap;
01018 std::vector<float> stpph1mip;
01019 std::vector<float> stpph1gev;
01020 std::vector<int> stpid;
01021
01022
01023 int us=0;
01024 int vs=0;
01025
01026 for(int j=0;j<trk->nstpcnt;j++)
01027 {
01028
01029
01030 if(trk->stp[j]>0)
01031 if(pepass[trk->stp[j]])
01032 {
01033
01034
01035 stpid.push_back(trk->stp[j]);
01036 stpph0sigmap.push_back(trk->stpph0sigmap[j]);
01037 stpph1sigmap.push_back(trk->stpph1sigmap[j]);
01038 stpph0gev.push_back(trk->stpph0gev[j]);
01039 stpph1gev.push_back(trk->stpph1gev[j]);
01040 stpph0mip.push_back(trk->stpph0mip[j]);
01041 stpph1mip.push_back(trk->stpph1mip[j]);
01042
01043
01044 stripe[trk->stp[j]*3]= trk->stpph0sigmap[j]+trk->stpph1sigmap[j];
01045 stripe[1+trk->stp[j]*3]= trk->stpph0mip[j]+trk->stpph1mip[j];
01046 stripe[2+trk->stp[j]*3]= trk->stpph0gev[j]+trk->stpph1gev[j];
01047
01048
01049 if(stp[trk->stp[j]]->planeview==2)
01050 us++;
01051 if(stp[trk->stp[j]]->planeview==3)
01052 vs++;
01053
01054
01055
01056
01057 }else{
01058 cutcount++;
01059
01060
01061 trk->ph.raw -= (stp[trk->stp[j]]->ph0.raw + stp[trk->stp[j]]->ph1.raw);
01062 trk->ph.pe -= (stp[trk->stp[j]]->ph0.pe + stp[trk->stp[j]]->ph1.pe);
01063 trk->ph.sigcor -= (stp[trk->stp[j]]->ph0.sigcor + stp[trk->stp[j]]->ph1.sigcor);
01064 trk->ph.siglin -= (stp[trk->stp[j]]->ph0.siglin + stp[trk->stp[j]]->ph1.siglin);
01065 trk->ph.sigmap -= (trk->stpph0sigmap[j] + trk->stpph1sigmap[j]);
01066 trk->ph.mip -= (trk->stpph0mip[j] + trk->stpph1mip[j]);
01067 trk->ph.gev -= (trk->stpph0gev[j] + trk->stpph1gev[j]);
01068
01069
01070 }
01071 }
01072
01073 MSG("PETrimmer",Msg::kDebug)<<"Track us "<<us << " vs "<< vs <<endl;
01074 if(us ==0 || vs==0)goodtrack=0;
01075
01076 MSG("PETrimmer",Msg::kDebug)<<"Cut "<<cutcount<<" strips from track!"<<endl;
01077 if(!goodtrack)MSG("PETrimmer",Msg::kDebug)<<"Track marked as bad!"<<endl;
01078
01079 if (cutcount==0 )return goodtrack;
01080
01081
01082 for(int j=0;j<trk->nstpcnt;j++)
01083 {
01084 trk->stp[j]=-1;
01085 trk->stpph0sigmap[j]=0;
01086 trk->stpph1sigmap[j]=0;
01087 trk->stpph0gev[j]=0;
01088 trk->stpph1gev[j]=0;
01089 trk->stpph0mip[j]=0;
01090 trk->stpph1mip[j]=0;
01091 }
01092
01093
01094
01095
01096
01097
01098
01099
01100
01101
01102
01103
01104
01105
01106
01107
01108
01109
01110
01111
01112
01113 trk->nstpcnt=stpid.size();
01114 trk->nstrip=stpid.size();
01115
01116 for(int j=0;j<(int)stpid.size();j++)
01117 {
01118 trk->stp[j]=-1;
01119 if(stpid[j]>-1 && stpid[j] < (int)stp.size())
01120 trk->stp[j]=stpid[j];
01121 trk->stpph0sigmap[j]=stpph0sigmap[j];
01122 trk->stpph1sigmap[j]=stpph1sigmap[j];
01123 trk->stpph0gev[j]=stpph0gev[j];
01124 trk->stpph1gev[j]=stpph1gev[j];
01125 trk->stpph0mip[j]=stpph0mip[j];
01126 trk->stpph1mip[j]=stpph1mip[j];
01127 }
01128
01129
01130
01131 return goodtrack;
01132
01133
01134 }
01135
01136
01137
01139 void PETrimmer::EndJob()
01140 {
01141 }
01142
01143 const Registry& PETrimmer::DefaultConfig() const
01144 {
01145
01146
01147
01148 MSG("PETrimmer",Msg::kDebug)<<"In Trimmer::DefaultConfig"<<endl;
01149
01150
01151 static Registry r;
01152 std::string name = this->JobCModule::GetName();
01153 name += ".config.default";
01154 r.SetName(name.c_str());
01155
01156 r.UnLockValues();
01157 r.Set("PECut", 0.0);
01158 r.Set("updateEventEnergy",1);
01159
01160 r.LockValues();
01161
01162
01163 return r;
01164 }
01165
01166 void PETrimmer::Config(const Registry& r)
01167 {
01168
01169
01170
01171 MSG("PETrimmer",Msg::kDebug)<<"In Trimmer::Config"<<endl;
01172
01173 bool islocked = this->GetConfig().ValuesLocked();
01174 if (islocked) this->GetConfig().UnLockValues();
01175
01176
01177 double fmps;
01178 if(r.Get("PECut", fmps)) {pecut = fmps;}
01179
01180 int imps;
01181 if(r.Get("updateEventEnergy", imps)) {updateEventEnergy = imps;}
01182 if (islocked) this->GetConfig().LockValues();
01183
01184 }
01185
01186
01187
01188 void PETrimmer::DumpIt(NtpStRecord * str)
01189 {
01190 std::vector< NtpSREvent* > evts;
01191 std::vector< NtpSRShower* > shw;
01192 std::vector< NtpSRTrack* > trk;
01193
01194 TClonesArray* tc = str->evt;
01195 for(int i=0;i<tc->GetEntries();i++)
01196 evts.push_back((NtpSREvent*)tc->At(i));
01197
01198 TClonesArray* ts = str->shw;
01199 for(int i=0;i<ts->GetEntries();i++)
01200 shw.push_back((NtpSRShower*)ts->At(i));
01201
01202 TClonesArray* tt = str->trk;
01203 for(int i=0;i<tt->GetEntries();i++)
01204 trk.push_back((NtpSRTrack*)tt->At(i));
01205
01206 std::vector<const NtpSRStrip* > stp = str->GetStrips();
01207
01208
01209
01210
01211
01212 for(int i=0;i<(int)shw.size();i++)
01213 {
01214 ostringstream os;
01215
01216 os <<"Shower "<<i<<": ";
01217 for(int j=0;j<shw[i]->nstrip;j++)
01218 {
01219
01220 if(i<0 || i > (int)shw.size()-1)
01221 {
01222 os << "bad shower index!";
01223 continue;
01224 }
01225 int strip = shw[i]->stp[j];
01226 if(strip<0)
01227 {
01228 os<<"("<<shw[i]->stp[j]<<",NO STRIP HERE....) ";
01229 MSG("PETrimmer",Msg::kError)<<"Shower "<<i<<" is missing a strip at index "<<j<< " strip index "<<shw[i]->stp[j]<<endl;
01230 }
01231 else
01232 os<<"("<<shw[i]->stp[j]<<","<<stp[shw[i]->stp[j]]->ph0.pe+stp[shw[i]->stp[j]]->ph1.pe<<") ";
01233 }
01234 os <<"\n";
01235 MSG("PETrimmer",Msg::kDebug)<<os.str()<<endl;
01236
01237
01238 }
01239
01240 for(int i=0;i<(int)trk.size();i++)
01241 {
01242 ostringstream os;
01243
01244 os <<"Track "<<i<<": ";
01245 for(int j=0;j<trk[i]->nstrip;j++)
01246 {
01247 if(i<0 || i > (int)trk.size()-1)
01248 {
01249 os << "bad track index!";
01250 continue;
01251 }
01252 int strip = trk[i]->stp[j];
01253 if(strip<0)
01254 os<<"("<<trk[i]->stp[j]<<",NO STRIP HERE...) ";
01255 else
01256 os<<"("<<trk[i]->stp[j]<<","<<stp[trk[i]->stp[j]]->ph0.pe+stp[trk[i]->stp[j]]->ph1.pe<<") ";
01257 }
01258 os <<"\n";
01259 MSG("PETrimmer",Msg::kDebug)<<os.str()<<endl;
01260 }
01261
01262
01263 for(int i=0;i<(int)evts.size();i++)
01264 {
01265 ostringstream os;
01266
01267 os <<"Event "<<i<<": ";
01268 for(int j=0;j<evts[i]->nstrip;j++)
01269 {
01270
01271 if(i<0 || i > (int)evts.size()-1)
01272 {
01273 os << "bad event index!";
01274 continue;
01275 }
01276 int strip = evts[i]->stp[j];
01277 if(strip<0)
01278 os<<"("<<evts[i]->stp[j]<<",NO STRIP HERE...) ";
01279 else
01280 os<<"("<<evts[i]->stp[j]<<","<<stp[evts[i]->stp[j]]->ph0.pe+stp[evts[i]->stp[j]]->ph1.pe<<") ";
01281 }
01282 os <<"\n";
01283
01284
01285 os<<"\tShowers: ";
01286 for(int j=0;j<evts[i]->nshower;j++)
01287 os<<evts[i]->shw[j]<<" ";
01288
01289 os<<"\tTracks: ";
01290 for(int j=0;j<evts[i]->ntrack;j++)
01291 os<<evts[i]->trk[j]<<" ";
01292
01293
01294
01295
01296 MSG("PETrimmer",Msg::kDebug)<<os.str()<<endl;
01297 }
01298
01299
01300 }