00001 #include "NueAna/ParticlePID/ParticleAna/DetailedParticle.h"
00002 #include "TH3F.h"
00003 #include "NueAna/ParticlePID/ParticleFinder/Particle3D.h"
00004
00005 #include "TH2F.h"
00006 #include "TFile.h"
00007 #include "TMath.h"
00008
00009 #include "MCNtuple/NtpMCStdHep.h"
00010
00011 #include "NueAna/ParticlePID/ParticleAna/TruthCompareAna.h"
00012 #include "MessageService/MsgService.h"
00013
00014 DetailedParticle::DetailedParticle(const char*fname)
00015 {
00016 input=new TChain("PO");
00017 inputPA=new TChain("PA");
00018 input->Add(fname);
00019 inputPA->Add(fname);
00020 poh=new ParticleObjectHolder();
00021 prec=new PRecord();
00022 input->SetBranchAddress("ParticleObjectHolder",&poh);
00023 inputPA->SetBranchAddress("PRecord",&prec);
00024 }
00025
00026 DetailedParticle::~DetailedParticle()
00027 {}
00028
00029
00030 int DetailedParticle::PassesPreselec()
00031 {
00032 int pass=1;
00033
00034
00035
00036
00037 pass = pass && ( (prec->event.vtx_z>0.5 && prec->event.vtx_z<14.5) || (prec->event.vtx_z>16.5 && prec->event.vtx_z<29.5) );
00038
00039 double r = sqrt(prec->event.vtx_u*prec->event.vtx_u+prec->event.vtx_v*prec->event.vtx_v);
00040
00041 pass = pass && (r>0.25 && r<3.9);
00042
00043 pass = pass && prec->event.nstrips>10;
00044 pass = pass && prec->event.nstrips<50;
00045 pass = pass && prec->particles.longest_s_particle_s<0.9;
00046 pass = pass && prec->particles.emfrac>0.4;
00047 pass = pass && prec->particles.elec_vise/25.>1;
00048 pass = pass && prec->particles.primary_long_e<40;
00049 pass = pass && prec->particles.largest_particle_e/prec->particles.totvise>0.65;
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 return pass;
00107 }
00108
00109 void DetailedParticle::Run()
00110 {
00111
00112
00113 TH2F * hist_sumdist[5];
00114 TH2F * hist_weighted_sumdist[5];
00115 TH1F * hist_max_dist[5];
00116 TH1F * hist_max_dist_per_gev[5];
00117
00118
00119 TH1F * hist_weighted_area[5];
00120
00121
00122 TH1F * hist_first_peak[5];
00123 TH1F * hist_second_peak[5];
00124 TH1F * hist_twopeak_diff[5];
00125
00126 TH1F * hist_back_peak_dist[5];
00127
00128 TH1F * hist_view_e_asym[5];
00129
00130
00131 TH2F * hist_prim_angle_vs_prim_eres[5];
00132 TH2F * hist_prim_angle_vs_prim_true[5];
00133
00134 TH2F * hist_sum_curv_vs_part_e[5];
00135 TH2F * hist_pu_pz[5];
00136 TH2F * hist_pv_pz[5];
00137 TH2F * hist_pt_pz[5];
00138 TH2F * hist_pu_pv[5];
00139
00140 for(int i=0;i<5;i++)
00141 {
00142 char tmp[200];
00143
00144 sprintf(tmp,"sumdist_%d",i);
00145 hist_sumdist[i] = new TH2F(tmp,tmp,100,0, 50,20,0,20);
00146
00147 sprintf(tmp,"weighted_sumdist_%d",i);
00148 hist_weighted_sumdist[i] = new TH2F(tmp,tmp,100,0, 50,20,0,20);
00149
00150 sprintf(tmp,"max_dist_%d",i);
00151 hist_max_dist[i] = new TH1F(tmp,tmp,100,0,20);
00152
00153 sprintf(tmp,"max_dist_per_gev_%d",i);
00154 hist_max_dist_per_gev[i] = new TH1F(tmp,tmp,100,0,1);
00155
00156 sprintf(tmp,"weighted_area_%d",i);
00157 hist_weighted_area[i] = new TH1F(tmp,tmp,100,0,20);
00158
00159 sprintf(tmp,"first_peak_%d",i);
00160 hist_first_peak[i] = new TH1F(tmp,tmp,100,0,2);
00161
00162 sprintf(tmp,"second_peak_%d",i);
00163 hist_second_peak[i] = new TH1F(tmp,tmp,100,0,2);
00164
00165 sprintf(tmp,"twopeak_diff_peak_%d",i);
00166 hist_twopeak_diff[i] = new TH1F(tmp,tmp,100,0,2);
00167
00168 sprintf(tmp,"back_peak_dist_%d",i);
00169 hist_back_peak_dist[i] = new TH1F(tmp,tmp,100,0,2);
00170
00171 sprintf(tmp,"view_e_asym_%d",i);
00172 hist_view_e_asym[i] = new TH1F(tmp,tmp,100,0,1);
00173
00174 sprintf(tmp,"prim_angle_vs_prim_eres_%d",i);
00175 hist_prim_angle_vs_prim_eres[i] = new TH2F(tmp,tmp,100,0, 3,100,-1,1);
00176 sprintf(tmp,"prim_angle_vs_prim_true_%d",i);
00177 hist_prim_angle_vs_prim_true[i] = new TH2F(tmp,tmp,100,0, 3,100,0,10);
00178
00179
00180 sprintf(tmp,"sum_curv_vs_part_e_%d",i);
00181 hist_sum_curv_vs_part_e[i]=new TH2F(tmp,tmp,1000,0,50,100,0,10);
00182 sprintf(tmp,"pu_pz_%d",i);
00183 hist_pu_pz[i]=new TH2F(tmp,tmp,100,-10,10,100,0,10);
00184 sprintf(tmp,"pv_pz_%d",i);
00185 hist_pv_pz[i]=new TH2F(tmp,tmp,100,-10,10,100,0,10);
00186 sprintf(tmp,"pt_pz_%d",i);
00187 hist_pt_pz[i]=new TH2F(tmp,tmp,100,0,10,100,0,10);
00188
00189 sprintf(tmp,"pu_pv_%d",i);
00190 hist_pu_pv[i]=new TH2F(tmp,tmp,100,-10,10,100,-10,10);
00191
00192 }
00193
00194
00195
00196
00197
00198 int ent =input->GetEntries();
00199 int entpa =inputPA->GetEntries();
00200 printf("%d %d total entries\n",ent,entpa);
00201
00202
00203 double typecnt[5];
00204 for(int i=0;i<5;i++)typecnt[i]=0;
00205
00206
00207 int saved=0;
00208 int ji=0;
00209 input->GetEntry(0);
00210 for(int ent_idx=0;ent_idx<entpa;ent_idx++)
00211 {
00212
00213 inputPA->GetEntry(ent_idx);
00214
00215 while(poh->GetHeader().GetRun() != prec->GetHeader().GetRun() || poh->GetHeader().GetSnarl()!=prec->GetHeader().GetSnarl() || poh->GetHeader().GetEvent()!=prec->GetHeader().GetEvent())
00216 input->GetEntry(ji++);
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245 saved++;
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268 if(!PassesPreselec())continue;
00269
00270
00271
00272 double weight = poh->mctrue.totbeamweight*poh->mctrue.oscprob*3.25/6.5/5;
00273
00274 double paweight = prec->mctrue.totbeamweight*prec->mctrue.oscprob*3.25/6.5/5;
00275
00276 if(fabs(weight-paweight)>0.001)printf("weight mismatch!\n");
00277
00278 int type=poh->mctrue.type;
00279
00280 if(type<0 || type>5)continue;
00281
00282 if(type==0)weight=weight/3.;
00283
00284
00285
00286
00287
00288
00289
00290
00291
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
00327
00328
00329
00330
00331
00332 double pu=0;
00333 double pv=0;
00334 double pz_u=0;
00335 double pz_v=0;
00336 double pz=0;
00337 double pt=0;
00338 for(int j=0;j<(int)poh->particles3d.size();j++)
00339 {
00340
00341 Particle3D * p = &poh->particles3d[j];
00342 if(!p)continue;
00343
00344 for(int i=0;i<p->entries;i++)
00345 {
00346 if(p->view[i]==2)
00347 {
00348 double dt=p->u[i]-poh->event.vtx_u;
00349 double dz=p->z[i]-poh->event.vtx_z;
00350 double r = sqrt(dt*dt+dz*dz);
00351 if(r>0)pu+= p->e[i]/25.*dt/r;
00352 if(r>0)pz_u+= p->e[i]/25.*dz/r;
00353 }
00354
00355 if(p->view[i]==2)
00356 {
00357 double dt=p->v[i]-poh->event.vtx_v;
00358 double dz=p->z[i]-poh->event.vtx_z;
00359 double r = sqrt(dt*dt+dz*dz);
00360 if(r>0)pv+= p->e[i]/25.*dt/r;
00361 if(r>0)pz_v+= p->e[i]/25.*dz/r;
00362 }
00363
00364 double du=p->u[i]-poh->event.vtx_u;
00365 double dv=p->v[i]-poh->event.vtx_v;
00366 double dz=p->z[i]-poh->event.vtx_z;
00367 double r = sqrt(du*du+dv*dv+dz*dz);
00368 double dt=sqrt(du*du+dv*dv);
00369 if(r>0)pt+=p->e[i]/25.*dt/r;
00370 if(r>0)pz+=p->e[i]/25.*dz/r;
00371
00372 }
00373
00374 }
00375
00376 hist_pu_pz[type]->Fill(pu,pz_u,weight);
00377 hist_pv_pz[type]->Fill(pv,pz_v,weight);
00378 hist_pt_pz[type]->Fill(pt,pz,weight);
00379 hist_pu_pv[type]->Fill(pu,pv,weight);
00380
00381
00382 int longest_id=-1;
00383 double longZ=0;
00384
00385 int largest_id=-1;
00386 double largeE=0;
00387
00388 for(int j=0;j<(int)poh->particles3d.size();j++)
00389 {
00390
00391 Particle3D * p = &poh->particles3d[j];
00392 if(!p)continue;
00393
00394
00395
00396 if(p->sum_e>largeE)
00397 {
00398 largest_id=j;
00399 largeE=p->sum_e;
00400 }
00401
00402 if(p->end_z-p->start_z>longZ)
00403 {
00404 longest_id=j;
00405 longZ=p->end_z-p->start_z;
00406 }
00407
00408
00410 double sum_z2=0;
00411 double sum_z=0;
00412 double sum_u=0;
00413 double sum_zu=0;
00414 double sum_v=0;
00415 double sum_zv=0;
00416 int n=0;
00417
00418 for(int k=0;k<p->entries;k++)
00419 {
00420 sum_z2+=p->z[k]*p->z[k];
00421 sum_z+=p->z[k];
00422 sum_zu+=p->z[k]*p->u[k];
00423 sum_u+=p->u[k];
00424 sum_zv+=p->z[k]*p->v[k];
00425 sum_v+=p->v[k];
00426 n++;
00427 }
00428
00429
00430 double slope_u= (n*sum_zu - sum_z*sum_u)/(n*sum_z2-sum_z*sum_z);
00431
00432
00433
00434 double slope_v= (n*sum_zv - sum_z*sum_v)/(n*sum_z2-sum_z*sum_z);
00435
00436
00437
00438
00439 double dz=p->end_z-p->start_z;
00440 double du=dz*slope_u;
00441 double dv=dz*slope_v;
00442
00443 double r2 = du*du+dv*dv+dz*dz;
00444 r2=sqrt(r2);
00445
00446
00447
00448
00449
00450
00451
00452
00453 }
00454
00455
00456
00457
00458 if(largest_id>-1)
00459 {
00460 Particle3D * p = &poh->particles3d[largest_id];
00461
00462
00463
00464 double curv=0;
00465 for(int i=1;i<p->entries;i++)
00466 {
00467 double du = p->u[i]-p->u[i-1];
00468 double dv = p->v[i]-p->v[i-1];
00469 double dz = p->z[i]-p->z[i-1];
00470 double ds = sqrt(du*du+dv*dv+dz*dz);
00471 if(dz>0)curv+=ds/dz;
00472 }
00473 hist_sum_curv_vs_part_e[type]->Fill(curv,p->sum_e/25.,weight);
00474
00475
00476 double sum_z2=0;
00477 double sum_z=0;
00478 double sum_u=0;
00479 double sum_zu=0;
00480 double sum_v=0;
00481 double sum_zv=0;
00482 int n=0;
00483
00484 for(int i=0;i<p->entries;i++)
00485 {
00486 sum_z2+=p->z[i]*p->z[i];
00487 sum_z+=p->z[i];
00488 sum_zu+=p->z[i]*p->u[i];
00489 sum_u+=p->u[i];
00490 sum_zv+=p->z[i]*p->v[i];
00491 sum_v+=p->v[i];
00492 n++;
00493 }
00494
00495 double off_u= (sum_u*sum_z2 - sum_z*sum_zu)/(n*sum_z2-sum_z*sum_z);
00496 double slope_u= (n*sum_zu - sum_z*sum_u)/(n*sum_z2-sum_z*sum_z);
00497
00498
00499 double off_v= (sum_v*sum_z2 - sum_z*sum_zv)/(n*sum_z2-sum_z*sum_z);
00500 double slope_v= (n*sum_zv - sum_z*sum_v)/(n*sum_z2-sum_z*sum_z);
00501
00502
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00545
00546
00547
00548 double sumdist=0;
00549 double weighted_sumdist=0;
00550 double sume=0;
00551
00552 for(int i=0;i<p->entries;i++)
00553 {
00554 double pu = slope_u*p->z[i]+off_u;
00555 double pv = slope_v*p->z[i]+off_v;
00556
00557 sumdist += sqrt((pu*p->u[i])*(pu*p->u[i])+(pv*p->v[i])*(pv*p->v[i]));
00558
00559
00560
00561 weighted_sumdist += p->e[i]*sqrt((pu*p->u[i])*(pu*p->u[i])+(pv*p->v[i])*(pv*p->v[i]));
00562 sume+=p->e[i];
00563 }
00564 weighted_sumdist/=sume;
00565 sumdist/=n;
00566 hist_sumdist[type]->Fill(sumdist,n,weight);
00567 hist_weighted_sumdist[type]->Fill(weighted_sumdist,n,weight);
00568
00569
00570 double max_e=0;
00571 double max_e_dist=0;
00572 for(int i=0;i<p->entries;i++)
00573 {
00574 if(max_e<p->e[i])
00575 {
00576 max_e=p->e[i];
00577 max_e_dist=sqrt((p->u[i]-p->u[0])*(p->u[i]-p->u[0]) + (p->v[i]-p->v[0])*(p->v[i]-p->v[0]) + (p->z[i]-p->z[0])*(p->z[i]-p->z[0]) );
00578
00579
00580 }
00581 }
00582
00583
00584 hist_max_dist[type]->Fill(max_e_dist,weight);
00585 hist_max_dist_per_gev[type]->Fill(max_e_dist/sume*25.0,weight);
00586
00587
00588
00589
00590
00591
00594
00595
00596
00597 int ent=p->entries-1;
00598 double slopeu = (p->u[ent]-p->u[0])/(p->z[ent]-p->z[0]);
00599 double slopev = (p->v[ent]-p->v[0])/(p->z[ent]-p->z[0]);
00600
00601 double offu = p->u[0]-p->z[0]*slopeu;
00602 double offv = p->v[0]-p->z[0]*slopev;
00603
00604 double sum_dr=0;
00605
00606 for(int i=0;i<p->entries;i++)
00607 {
00608 double eu=p->z[i]*slopeu+offu;
00609 double ev=p->z[i]*slopev+offv;
00610
00611 double dr = sqrt((eu-p->u[i])*(eu-p->u[i]) + (ev-p->v[i])*(ev-p->v[i]));
00612
00613 sum_dr+=dr*p->e[i];
00614 }
00615
00616 sum_dr/=sume;
00617 hist_weighted_area[type]->Fill(sum_dr,weight);
00618
00620
00621 int fp=-1;
00622 double fpe=0;
00623 int sp=-1;
00624
00625 for(int i=1;i<p->entries;i++)
00626 {
00627
00628 if(i==1 &&p->e[0]>p->e[1])fp=0;
00629
00630 if(i<p->entries-1)
00631 if(p->e[i-1]<p->e[i] && p->e[i+1]<p->e[i])
00632 {
00633 if(fp<0){
00634 fp=i;
00635 fpe=p->e[i];
00636 }
00637 else if(p->e[i] *0.5 > fpe)
00638 {
00639 sp=i;
00640 break;
00641 }
00642
00643 }
00644
00645
00646 if(i==p->entries-1 && p->e[i-1]<p->e[i])
00647 {
00648 if(fp>-1)sp=i;
00649 else fp=i;
00650 }
00651
00652 }
00653
00654 if(fp>-1)hist_first_peak[type]->Fill(p->z[fp]-p->z[0],weight);
00655 else hist_first_peak[type]->Fill(0.,weight);
00656 if(sp>-1)hist_second_peak[type]->Fill(p->z[sp]-p->z[0],weight);
00657 else hist_second_peak[type]->Fill(0.,weight);
00658 if(fp>-1 && sp>-1)hist_twopeak_diff[type]->Fill(p->z[sp]-p->z[fp],weight);
00659 else hist_twopeak_diff[type]->Fill(0.,weight);
00660
00661
00662
00664 double maxe=0;
00665 for(int i=0;i<p->entries;i++)
00666 {
00667 if(maxe<p->e[i])maxe=p->e[i];
00668 }
00669
00670 int pkidx=-1;
00671 for(int i=p->entries-1;i>-1;i--)
00672 {
00673 if(maxe*0.7<p->e[i])
00674 {
00675 pkidx=i;
00676 break;
00677 }
00678 }
00679
00680
00681
00682 if(pkidx>-1)
00683 hist_back_peak_dist[type]->Fill(p->z[pkidx]-p->z[0],weight);
00684 else
00685 hist_back_peak_dist[type]->Fill(0.,weight);
00687
00688
00689
00690
00691 double eu=0;
00692 double ev=0;
00693 for(int i=0;i<p->entries;i++)
00694 {
00695 if(p->view[i]==2)eu+=p->e[i];
00696 if(p->view[i]==3)ev+=p->e[i];
00697 }
00698
00699 hist_view_e_asym[type]->Fill(fabs(eu-ev)/(eu+ev),weight);
00700
00701
00702 }
00703
00704
00705
00706 typecnt[type]+=weight;
00707
00708
00709
00710 if(ent_idx%10000==0)printf("Entry %d\n",ent_idx);
00711 }
00712
00713
00714 printf("used %d entries\n",saved);
00715
00716
00717
00718 printf("values\n");
00719 for(int i=0;i<5;i++)
00720 printf("%d %2.2f\n",i,typecnt[i]);
00721
00722 printf("FOM %2.2f\n",typecnt[1]/sqrt(typecnt[0]+typecnt[2]+typecnt[3]+typecnt[4]));
00723
00724
00725 TFile *f = new TFile("detailplots.root","RECREATE");
00726 f->cd();
00727 for(int i=0;i<5;i++)
00728 {
00729 hist_sumdist[i]->Write();
00730 hist_weighted_sumdist[i]->Write();
00731
00732 hist_max_dist[i]->Write();
00733 hist_max_dist_per_gev[i]->Write();
00734
00735 hist_weighted_area[i]->Write();
00736
00737 hist_first_peak[i]->Write();
00738 hist_second_peak[i]->Write();
00739 hist_twopeak_diff[i]->Write();
00740 hist_back_peak_dist[i]->Write();
00741 hist_view_e_asym[i]->Write();
00742
00743 hist_prim_angle_vs_prim_eres[i]->Write();
00744 hist_prim_angle_vs_prim_true[i]->Write();
00745
00746
00747 hist_sum_curv_vs_part_e[i]->Write();
00748 hist_pu_pz[i]->Write();
00749 hist_pv_pz[i]->Write();
00750 hist_pt_pz[i]->Write();
00751 hist_pu_pv[i]->Write();
00752
00753 }
00754 f->Close();
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
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
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855
00856
00857
00858
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877
00878
00879
00880
00881
00882
00883
00884
00885
00886
00887
00888
00889
00890
00891
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905
00906
00907
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917
00918
00919
00920
00921
00922