00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
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
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00148
00149 #include <set>
00150 #include <vector>
00151 #include "TClonesArray.h"
00152 #include "TSystem.h"
00153 #include "TRandom.h"
00154 #include "TVectorD.h"
00155
00156 #include "Mad/MadMKAnalysis.h"
00157 #include "Mad/NearbyEvents.h"
00158 #include "Mad/Moments.h"
00159 #include "DataUtil/EnergyCorrections.h"
00160
00161
00162 #include "MCReweight/GnumiInterface.h"
00163 #include "MCReweight/NuParent.h"
00164 #include "MCReweight/BeamEnergyCalculator.h"
00165
00166 #include "NeugenInterface/neugen_config.h"
00167 #include "NeugenInterface/neugen_wrapper.h"
00168 #include "NeugenInterface/inuke_rw.h"
00169
00170 #include "Conventions/BeamType.h"
00171
00172 #include "BeamDataUtil/BeamMonSpill.h"
00173 #include "BeamDataUtil/BMSpillAna.h"
00174 #include "BeamDataUtil/BDSpillAccessor.h"
00175 #include "SpillTiming/SpillTimeFinder.h"
00176
00177 using namespace EnergyCorrections;
00178
00179 const Float_t MadMKAnalysis::kVetoEndZ = 1.2154;
00180 const Float_t MadMKAnalysis::kTargEndZ = 3.5914;
00181 const Float_t MadMKAnalysis::kCalorEndZ = 7.1554;
00182 const Float_t MadMKAnalysis::kHalfCalorEndZ = kTargEndZ+(kCalorEndZ-kTargEndZ)*0.5;
00183 const Float_t MadMKAnalysis::kSpecEndZ = 16.656;
00184 const Float_t MadMKAnalysis::kXcenter = 1.4885;
00185 const Float_t MadMKAnalysis::kYcenter = 0.1397;
00186
00187 const Double_t MadMKAnalysis::fEarlyActivityWindowSize=10.;
00188 const Double_t MadMKAnalysis::fPMTTimeConstant=700.;
00189 const Int_t MadMKAnalysis::fNPlaneEarlyAct=30;
00190 const Double_t MadMKAnalysis::fEarlyPlaneSphere=0.5;
00191
00192 MadMKAnalysis::MadMKAnalysis(TChain *chainSR,TChain *chainMC,
00193 TChain *chainTH,TChain *chainEM)
00194 : MadAnalysis(chainSR, chainMC, chainTH, chainEM)
00195 {
00196 fMCBeam=BeamType::kUnknown;
00197 fDataUseMCBeam=false;
00198 fDoInukeReweight=false;
00199 fNRandomSets=0;
00200 fOnlyWriteFidEvents=false;
00201 if(!chainSR) {
00202 record = 0;
00203 emrecord = 0;
00204 mcrecord = 0;
00205 threcord = 0;
00206 Clear();
00207 whichSource = -1;
00208 isMC = true;
00209 isTH = true;
00210 isEM = true;
00211 Nentries = -1;
00212 return;
00213 }
00214 static const char* default_bec_file="/afs/fnal.gov/files/data/minos/d04/kordosky/bec_files/pbeams_0.5_gnumi_v16.root";
00215 fBECConfig.Set("beam:flux_file",default_bec_file);
00216 fBECConfig.Set("beam:beam_type",BeamType::kLE);
00217 fBECConfig.Set("beam:detector",Detector::kNear);
00218 fBECConfig.Set("beam:low_energy_limit",0.5);
00219 fBECConfig.Set("beam:high_energy_limit",60.0);
00220
00221
00222
00223 whichSource = 0;
00224
00225 }
00226
00227
00228 MadMKAnalysis::MadMKAnalysis(JobC *j,string path,int entries) : MadAnalysis(j, path, entries)
00229 {
00230 fMCBeam=BeamType::kUnknown;
00231 fDataUseMCBeam=false;
00232 fDoInukeReweight=false;
00233 fNRandomSets=0;
00234 fOnlyWriteFidEvents=false;
00235 record = 0;
00236 emrecord = 0;
00237 mcrecord = 0;
00238 threcord = 0;
00239 Clear();
00240 isMC = true;
00241 isTH = true;
00242 isEM = true;
00243 Nentries = entries;
00244 whichSource = 1;
00245 jcPath = path;
00246 fJC = j;
00247 fChain = NULL;
00248
00249
00250 static const char* default_bec_file="/afs/fnal.gov/files/data/minos/d04/kordosky/bec_files/pbeams_0.5_gnumi_v16.root";
00251 fBECConfig.Set("beam:flux_file",default_bec_file);
00252 fBECConfig.Set("beam:beam_type",BeamType::kLE);
00253 fBECConfig.Set("beam:detector",Detector::kNear);
00254 fBECConfig.Set("beam:low_energy_limit",0.5);
00255 fBECConfig.Set("beam:high_energy_limit",60.0);
00256
00257 }
00258
00259
00260 MadMKAnalysis::~MadMKAnalysis()
00261 {
00262
00263 }
00264
00265 void MadMKAnalysis::CreatePAN(std::string tag, const char* )
00266 {
00267
00268
00269 this->GetEntry(0);
00270 const bool file_is_mc
00271 =(ntpHeader->GetVldContext().GetSimFlag()==SimFlag::kMC);
00272
00273
00274
00275 GnumiInterface* gnumi=0;
00276 if(file_is_mc){
00277 gnumi=new GnumiInterface();
00278
00279 if(!gnumi->Status()) {
00280 cout << "Warning: MadMKAnalysis::CreatePAN() - Flux files not open."
00281 << " Will not be filling NuParent info"
00282 << endl;
00283 cout << "Set environmental variable $GNUMIAUX to point to the "
00284 << "directory containing the gnumi files to fix this!"
00285 << endl;
00286 }
00287 else{
00288 const char* gnumidir= getenv("GNUMIAUX");
00289 cout<<"Read gnumi files from "<<gnumidir<<endl;
00290 }
00291 }
00292
00293
00294 NuParent *nuparent = new NuParent();
00295
00296
00297
00298
00299 Float_t true_enu;
00300 Float_t true_emu;
00301 Float_t true_eshw;
00302 Float_t true_x;
00303 Float_t true_y;
00304 Float_t true_q2;
00305 Float_t true_w2;
00306 Float_t true_dircosneu;
00307 Float_t true_dircosz;
00308 Float_t true_vtxx;
00309 Float_t true_vtxy;
00310 Float_t true_vtxz;
00311 Int_t true_pitt_fid;
00312 Float_t true_trk_cmplt;
00313
00314
00315 Float_t flavour;
00316 Int_t process;
00317 Int_t nucleus;
00318 Int_t cc_nc;
00319 Int_t initial_state;
00320 Int_t inu;
00321 Int_t resnum;
00322
00323 Short_t npp;
00324 Short_t npm;
00325 Short_t npz;
00326 Short_t np;
00327 Short_t nn;
00328 float epp;
00329 float epm;
00330 float epz;
00331 float ep;
00332 float en;
00333
00334
00335
00336 Int_t detector;
00337 Int_t run;
00338 Int_t snarl;
00339 Int_t subrun;
00340 UInt_t trgsrc;
00341 double trgtime;
00342 Int_t spilltype;
00343
00344
00345
00346 Int_t nevent;
00347 Int_t event;
00348 Int_t mcevent;
00349 Int_t ntrack;
00350 Int_t nshower;
00351 Int_t nstrip;
00352
00353 Int_t is_fid;
00354 Int_t is_cev;
00355 Int_t is_mc;
00356 Int_t pass_basic;
00357 Int_t is_pitt_fid;
00358 Int_t is_trk_fid;
00359
00360 Int_t nd_radial_fid;
00361 Int_t pitt_evt_class;
00362
00363
00364
00365
00366 Int_t pitt_trk_qual;
00367 Int_t duvvtx;
00368
00369 Float_t pid0;
00370 Float_t pid1;
00371 Float_t pid2;
00372 Int_t pass_track;
00373 Int_t pass;
00374
00375 Int_t emu_meth;
00376 Float_t reco_enu;
00377 Float_t reco_emu;
00378 Float_t reco_mushw;
00379 Float_t reco_eshw;
00380 Float_t reco_wtd_eshw;
00381 Float_t reco_vtx_eshw;
00382 Float_t reco_vtx_wtd_eshw;
00383
00384 Float_t reco_dircosneu;
00385 Float_t reco_dircosz;
00386
00387 Float_t reco_vtxx;
00388 Float_t reco_vtxy;
00389 Float_t reco_vtxz;
00390 Float_t reco_vtxr;
00391
00392 Float_t reco_trk_vtxx;
00393 Float_t reco_trk_vtxy;
00394 Float_t reco_trk_vtxz;
00395 Float_t reco_trk_vtxr;
00396
00397 Float_t reco_shw_vtxx;
00398 Float_t reco_shw_vtxy;
00399 Float_t reco_shw_vtxz;
00400 Float_t reco_shw_vtxr;
00401
00402
00403 Float_t reco_trk_endx;
00404 Float_t reco_trk_endy;
00405 Float_t reco_trk_endz;
00406 Float_t reco_trk_endr;
00407
00408 Int_t evt_nplanes;
00409 Int_t trk_nplanes;
00410 Int_t slc_nplanes;
00411 Int_t shw_nplanes_cut;
00412 Int_t shw_nplanes_raw;
00413 Float_t shw_ph_cut, shw_ph_raw;
00414
00415 Int_t evt_nstrips;
00416 Int_t trk_nstrips;
00417 Int_t slc_nstrips;
00418
00419
00420
00421
00422
00423 Float_t reco_y;
00424 Float_t reco_Q2;
00425 Float_t reco_x;
00426 Float_t reco_W2;
00427
00428
00429 Float_t reco_qe_enu;
00430 Float_t reco_qe_q2;
00431
00432
00433 Float_t evtlength;
00434 Float_t shwlength;
00435 Float_t trklength;
00436 Int_t ntrklike;
00437 Float_t trkmomrange;
00438 Float_t trkqp;
00439 Float_t trkeqp;
00440 Float_t trkphfrac;
00441 Float_t trkphplane;
00442 Float_t trkchi2;
00443 Int_t trkndf;
00444
00445
00446 Int_t trkend, trkendu, trkendv;
00447 Int_t shwend,shwbeg;
00448
00449 Int_t nss[6];
00450 Float_t ess[6];
00451 Int_t ntotss;
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474 Int_t nvsi, bvsi, nvti, bvti;
00475 Int_t nvsevt, bvsevt, nvtevt, bvtevt;
00476 Float_t nvsd, bvsd, nvtd, bvtd;
00477 Float_t nvst, bvst, nvtt, bvtt;
00478 Float_t nvsp, bvsp, nvtp, bvtp;
00479
00480
00481 Float_t evtph;
00482 Float_t evtphgev;
00483
00484
00485
00486 Float_t evtsigfull,trksigfull,evtsigpart,trksigpart;
00487
00488
00489
00490 double evttimemin, evttimemax, evttimeln;
00491 double evttimeminphc, evttimemaxphc, evttimelnphc;
00492
00493
00494 float earlywph, earlywphpw, earlywphsphere;
00495 float ph1000, ph500, ph100;
00496 float lateph1000, lateph500, lateph100, lateph50;
00497
00498
00499 int nduprs;
00500 float dupphrs;
00501
00502
00503
00504 double litime;
00505
00506
00507 UChar_t dmx_stat;
00508
00509
00510
00511
00512 float lowphrat;
00513
00514
00515
00516 std::string savename = "PAN_" + tag + ".root";
00517 TFile save(savename.c_str(),"RECREATE");
00518 save.cd();
00519 TTree *tree = new TTree("pan","pan");
00520
00521 tree->Branch("true_enu",&true_enu,"true_enu/F",32000);
00522 tree->Branch("true_emu",&true_emu,"true_emu/F",32000);
00523 tree->Branch("true_eshw",&true_eshw,"true_eshw/F",32000);
00524 tree->Branch("true_x",&true_x,"true_x/F",32000);
00525 tree->Branch("true_y",&true_y,"true_y/F",32000);
00526 tree->Branch("true_q2",&true_q2,"true_q2/F",32000);
00527 tree->Branch("true_w2",&true_w2,"true_w2/F",32000);
00528 Float_t nu_px, nu_py, nu_pz;
00529 Float_t tar_px, tar_py, tar_pz, tar_e;
00530 tree->Branch("nu_px", &nu_px, "nu_px/F");
00531 tree->Branch("nu_py", &nu_py, "nu_py/F");
00532 tree->Branch("nu_pz", &nu_pz, "nu_pz/F");
00533 tree->Branch("tar_px", &tar_px, "tar_px/F");
00534 tree->Branch("tar_py", &tar_py, "tar_py/F");
00535 tree->Branch("tar_pz", &tar_pz, "tar_pz/F");
00536 tree->Branch("tar_e", &tar_e, "tar_e/F");
00537
00538
00539 tree->Branch("true_dircosneu",&true_dircosneu,"true_dircosneu/F",32000);
00540 tree->Branch("true_dircosz",&true_dircosz,"true_dircosz/F",32000);
00541 tree->Branch("true_vtxx",&true_vtxx,"true_vtxx/F",32000);
00542 tree->Branch("true_vtxy",&true_vtxy,"true_vtxy/F",32000);
00543 tree->Branch("true_vtxz",&true_vtxz,"true_vtxz/F",32000);
00544 tree->Branch("true_pitt_fid",&true_pitt_fid,"true_pitt_fid/I",32000);
00545 tree->Branch("true_trk_cmplt",&true_trk_cmplt,"true_trk_cmplt/F",32000);
00546
00547
00548 tree->Branch("flavour",&flavour,"flavour/F",32000);
00549 tree->Branch("process",&process,"process/I",32000);
00550 tree->Branch("nucleus",&nucleus,"nucleus/I",32000);
00551 tree->Branch("cc_nc",&cc_nc,"cc_nc/I",32000);
00552 tree->Branch("inu",&inu,"inu/I",32000);
00553
00554 tree->Branch("initial_state",&initial_state,"initial_state/I",32000);
00555 tree->Branch("resnum",&resnum,"resnum/I",32000);
00556 tree->Branch("npp",&npp,"npp/S",32000);
00557 tree->Branch("npm",&npm,"npm/S",32000);
00558 tree->Branch("npz",&npz,"npz/S",32000);
00559 tree->Branch("np",&np,"np/S",32000);
00560 tree->Branch("nn",&nn,"nn/S",32000);
00561
00562 tree->Branch("epp",&epp,"epp/F",32000);
00563 tree->Branch("epm",&epm,"epm/F",32000);
00564 tree->Branch("epz",&epz,"epz/F",32000);
00565 tree->Branch("ep",&ep,"ep/F",32000);
00566 tree->Branch("en",&en,"en/F",32000);
00567
00568
00569 tree->Branch("detector",&detector,"detector/I",32000);
00570 tree->Branch("run",&run,"run/I",32000);
00571 tree->Branch("snarl",&snarl,"snarl/I",32000);
00572 tree->Branch("subrun",&subrun,"subrun/I",32000);
00573 tree->Branch("trgsrc",&trgsrc,"trgsrc/i",32000);
00574 tree->Branch("trgtime",&trgtime,"trgtime/D",32000);
00575 tree->Branch("spilltype",&spilltype,"spiltype/I",32000);
00576 tree->Branch("nevent",&nevent,"nevent/I",32000);
00577 tree->Branch("event",&event,"event/I",32000);
00578 tree->Branch("mcevent",&mcevent,"mcevent/I",32000);
00579 tree->Branch("ntrack",&ntrack,"ntrack/I",32000);
00580 tree->Branch("nshower",&nshower,"nshower/I",32000);
00581 tree->Branch("nstrip",&nstrip,"nstrip/I",32000);
00582
00583 tree->Branch("is_fid",&is_fid,"is_fid/I",32000);
00584 tree->Branch("is_cev",&is_cev,"is_cev/I",32000);
00585 tree->Branch("is_mc",&is_mc,"is_mc/I",32000);
00586 tree->Branch("pass_basic",&pass_basic,"pass_basic/I",32000);
00587 tree->Branch("pass_track",&pass_track,"pass_track/I",32000);
00588 tree->Branch("emu_meth",&emu_meth,"emu_meth/I",32000);
00589 tree->Branch("is_pitt_fid",&is_pitt_fid,"is_pitt_fid/I",32000);
00590 tree->Branch("is_trk_fid",&is_trk_fid,"is_trk_fid/I",32000);
00591
00592 tree->Branch("nd_radial_fid",&nd_radial_fid,"nd_radial_fid/I",32000);
00593 tree->Branch("pitt_evt_class",&pitt_evt_class,"pitt_evt_class/I",32000);
00594 tree->Branch("pitt_trk_qual",&pitt_trk_qual,"pitt_trk_qual/I",32000);
00595 tree->Branch("duvvtx",&duvvtx,"duvvtx/I",32000);
00596
00597 tree->Branch("pid0",&pid0,"pid0/F",32000);
00598 tree->Branch("pid1",&pid1,"pid1/F",32000);
00599 tree->Branch("pid2",&pid2,"pid2/F",32000);
00600 tree->Branch("pass",&pass,"pass/I",32000);
00601
00602 float med_qe_pid;
00603 int med_qe_pass;
00604 tree->Branch("med_qe_pid",&med_qe_pid,"med_qe_pid/F",32000);
00605 tree->Branch("med_qe_pass",&med_qe_pass,"med_qe_pass/I",32000);
00606
00607 double niki_cc_pid;
00608 tree->Branch("niki_cc_pid",&niki_cc_pid,"niki_cc_pid/D",32000);
00609 float dave_cc_pid;
00610 tree->Branch("dave_cc_pid",&dave_cc_pid,"dave_cc_pid/F",32000);
00611
00612
00613 tree->Branch("reco_enu",&reco_enu,"reco_enu/F",32000);
00614 tree->Branch("reco_emu",&reco_emu,"reco_emu/F",32000);
00615 tree->Branch("reco_mushw",&reco_mushw,"reco_mushw/F",32000);
00616 tree->Branch("reco_eshw",&reco_eshw,"reco_eshw/F",32000);
00617 tree->Branch("reco_wtd_eshw",&reco_wtd_eshw,"reco_wtd_eshw/F",32000);
00618 tree->Branch("reco_vtx_eshw",&reco_vtx_eshw,"reco_vtx_eshw/F",32000);
00619 tree->Branch("reco_vtx_wtd_eshw",&reco_vtx_wtd_eshw,"reco_vtx_wtd_eshw/F",32000);
00620 Float_t shw_pur, shw_comp;
00621 tree->Branch("shw_pur",&shw_pur,"shw_pur/F",32000);
00622 tree->Branch("shw_comp",&shw_comp,"shw_comp/F",32000);
00623
00624
00625
00626 tree->Branch("reco_dircosneu",&reco_dircosneu,"reco_dircosneu/F",32000);
00627 tree->Branch("reco_dircosz",&reco_dircosz,"reco_dircosz/F",32000);
00628
00629 tree->Branch("reco_vtxx",&reco_vtxx,"reco_vtxx/F",32000);
00630 tree->Branch("reco_vtxy",&reco_vtxy,"reco_vtxy/F",32000);
00631 tree->Branch("reco_vtxz",&reco_vtxz,"reco_vtxz/F",32000);
00632 tree->Branch("reco_vtxr",&reco_vtxr,"reco_vtxr/F",32000);
00633
00634 tree->Branch("reco_trk_vtxx",&reco_trk_vtxx,"reco_trk_vtxx/F",32000);
00635 tree->Branch("reco_trk_vtxy",&reco_trk_vtxy,"reco_trk_vtxy/F",32000);
00636 tree->Branch("reco_trk_vtxz",&reco_trk_vtxz,"reco_trk_vtxz/F",32000);
00637 tree->Branch("reco_trk_vtxr",&reco_trk_vtxr,"reco_trk_vtxr/F",32000);
00638
00639 tree->Branch("reco_shw_vtxx",&reco_shw_vtxx,"reco_shw_vtxx/F",32000);
00640 tree->Branch("reco_shw_vtxy",&reco_shw_vtxy,"reco_shw_vtxy/F",32000);
00641 tree->Branch("reco_shw_vtxz",&reco_shw_vtxz,"reco_shw_vtxz/F",32000);
00642
00643
00644 tree->Branch("reco_trk_endx",&reco_trk_endx,"reco_trk_endx/F",32000);
00645 tree->Branch("reco_trk_endy",&reco_trk_endy,"reco_trk_endy/F",32000);
00646 tree->Branch("reco_trk_endz",&reco_trk_endz,"reco_trk_endz/F",32000);
00647 tree->Branch("reco_trk_endr",&reco_trk_endr,"reco_trk_endr/F",32000);
00648
00649 tree->Branch("evt_nplanes",&evt_nplanes,"evt_nplanes/I",32000);
00650 tree->Branch("trk_nplanes",&trk_nplanes,"trk_nplanes/I",32000);
00651 tree->Branch("slc_nplanes",&slc_nplanes,"slc_nplanes/I",32000);
00652 tree->Branch("shw_nplanes_cut",&shw_nplanes_cut,"shw_nplanes_cut/I",32000);
00653 tree->Branch("shw_nplanes_raw",&shw_nplanes_raw,"shw_nplanes_raw/I",32000);
00654
00655 tree->Branch("shw_ph_cut",&shw_ph_cut,"shw_ph_cut/F",32000);
00656 tree->Branch("shw_ph_raw",&shw_ph_raw,"shw_ph_raw/F",32000);
00657
00658
00659 tree->Branch("evt_nstrips",&evt_nstrips,"evt_nstrips/I",32000);
00660 tree->Branch("trk_nstrips",&trk_nstrips,"trk_nstrips/I",32000);
00661 tree->Branch("slc_nstrips",&slc_nstrips,"slc_nstrips/I",32000);
00662
00663 tree->Branch("reco_y",&reco_y,"reco_y/F",32000);
00664 tree->Branch("reco_Q2",&reco_Q2,"reco_Q2/F",32000);
00665 tree->Branch("reco_x",&reco_x,"reco_x/F",32000);
00666 tree->Branch("reco_W2",&reco_W2,"reco_W2/F",32000);
00667
00668 tree->Branch("reco_qe_enu",&reco_qe_enu,"reco_qe_enu/F",32000);
00669 tree->Branch("reco_qe_q2",&reco_qe_q2,"reco_qe_q2/F",32000);
00670
00671 tree->Branch("evtlength",&evtlength,"evtlength/F",32000);
00672 tree->Branch("trklength",&trklength,"trklength/F",32000);
00673 tree->Branch("shwlength",&shwlength,"shwlength/F",32000);
00674 tree->Branch("ntrklike",&ntrklike,"ntrklike/I",32000);
00675 tree->Branch("trkend",&trkend,"trkend/I",32000);
00676 tree->Branch("trkendu",&trkendu,"trkendu/I",32000);
00677 tree->Branch("trkendv",&trkendv,"trkendv/I",32000);
00678 tree->Branch("shwbeg",&shwbeg,"shwbeg/I",32000);
00679 tree->Branch("shwend",&shwend,"shwend/I",32000);
00680
00681
00682 Int_t trknstp;
00683 tree->Branch("trkmomrange",&trkmomrange,"trkmomrange/F",32000);
00684 tree->Branch("trkqp",&trkqp,"trkqp/F",32000);
00685 tree->Branch("trkeqp",&trkeqp,"trkeqp/F",32000);
00686 tree->Branch("trkphfrac",&trkphfrac,"trkphfrac/F",32000);
00687 tree->Branch("trkphplane",&trkphplane,"trkphplane/F",32000);
00688 tree->Branch("trkchi2",&trkchi2,"trkchi2/F",32000);
00689 tree->Branch("trkndf",&trkndf,"trkndf/I",32000);
00690 tree->Branch("trknstp",&trknstp,"trknstp/I",32000);
00691
00692
00693
00694 tree->Branch("nvsi", &nvsi, "nvsi/I");
00695 tree->Branch("nvsevt", &nvsevt, "nvsevt/I");
00696 tree->Branch("nvsd", &nvsd, "nvsd/F");
00697 tree->Branch("nvst", &nvst, "nvst/F");
00698 tree->Branch("nvsp", &nvsp, "nvsp/F");
00699 tree->Branch("nvti", &nvti, "nvti/I");
00700 tree->Branch("nvtevt", &nvtevt, "nvtevt/I");
00701 tree->Branch("nvtd", &nvtd, "nvtd/F");
00702 tree->Branch("nvtt", &nvtt, "nvtt/F");
00703 tree->Branch("nvtp", &nvtp, "nvtp/F");
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717 tree->Branch("evtph", &evtph, "evtph/F");
00718 tree->Branch("evtphgev", &evtphgev, "evtphgev/F");
00719
00720 tree->Branch("evtsigfull", &evtsigfull, "evtsigfull/F");
00721 tree->Branch("evtsigpart", &evtsigpart, "evtsigpart/F");
00722
00723 tree->Branch("trksigfull", &trksigfull, "trksigfull/F");
00724 tree->Branch("trksigpart", &trksigpart, "trksigpart/F");
00725
00726 tree->Branch("evttimemin",&evttimemin,"evttimemin/D");
00727 tree->Branch("evttimemax",&evttimemax,"evttimemax/D");
00728 tree->Branch("evttimeln",&evttimeln,"evttimeln/D");
00729
00730 tree->Branch("evttimeminphc",&evttimeminphc,"evttimeminphc/D");
00731 tree->Branch("evttimemaxphc",&evttimemaxphc,"evttimemaxphc/D");
00732 tree->Branch("evttimelnphc",&evttimelnphc,"evttimelnphc/D");
00733
00734 tree->Branch("earlywph",&earlywph,"earlywph/F");
00735 tree->Branch("earlywphpw",&earlywphpw,"earlywphpw/F");
00736 tree->Branch("earlywphsphere",&earlywphsphere,"earlywphsphere/F");
00737 tree->Branch("ph1000",&ph1000,"ph1000/F");
00738 tree->Branch("ph500",&ph500,"ph500/F");
00739 tree->Branch("ph100",&ph100,"ph100/F");
00740 tree->Branch("lateph1000",&lateph1000,"lateph1000/F");
00741 tree->Branch("lateph500",&lateph500,"lateph500/F");
00742 tree->Branch("lateph100",&lateph100,"lateph100/F");
00743 tree->Branch("lateph50",&lateph50,"lateph50/F");
00744
00745 tree->Branch("nduprs",&nduprs,"ndubrs/I");
00746 tree->Branch("dupphrs",&dupphrs,"dupphrs/F");
00747
00748 tree->Branch("nss", nss, "nss[6]/I");
00749 tree->Branch("ess", ess, "ess[6]/F");
00750 tree->Branch("ntotss", &ntotss, "ntotss/I");
00751
00752 Float_t etu, etv, elu, elv;
00753 tree->Branch("etu", &etu, "etu/F");
00754 tree->Branch("etv", &etv, "etv/F");
00755 tree->Branch("elu", &elu, "elu/F");
00756 tree->Branch("elv", &elv, "elv/F");
00757
00758 Float_t swu,swv,wswu,wswv;
00759 tree->Branch("swu",&swu, "swu/F");
00760 tree->Branch("swv",&swv, "swv/F");
00761 tree->Branch("wswu",&wswu, "wswu/F");
00762 tree->Branch("wswv",&wswv, "wswv/F");
00763
00764
00765
00766 Float_t bec_inve, bec_le, bec_050, bec_100, bec_200, bec_250;
00767
00768 tree->Branch("bec_inve", &bec_inve, "bec_inve/F");
00769 tree->Branch("bec_le", &bec_le, "bec_le/F");
00770 tree->Branch("bec_050", &bec_050, "bec_050/F");
00771 tree->Branch("bec_100", &bec_100, "bec_100/F");
00772 tree->Branch("bec_200", &bec_200, "bec_200/F");
00773 tree->Branch("bec_250", &bec_250, "bec_250/F");
00774
00775
00776 tree->Branch("litime",&litime,"litime/D");
00777
00778
00779 tree->Branch("dmx_stat",&dmx_stat,"dmx_stat/b");
00780 tree->Branch("lowphrat",&lowphrat,"lowphrat/F");
00781
00782
00783 Double_t hbw,vbw,hpos1,vpos1,hpos2,vpos2,hornI,closestspill;
00784
00785
00786
00787 UInt_t beamcnf;
00788
00789 Double_t nuTarZ;
00790
00791 Int_t goodbeam;
00792
00793
00794 UInt_t horn_on, target_in, n_batches;
00795 Float_t tor101, tr101d, tortgt, trtgtd;
00796 Float_t hadmon, mumon1, mumon2, mumon3;
00797
00798 tree->Branch("hbw",&hbw,"hbw/D");
00799 tree->Branch("vbw",&vbw,"vbw/D");
00800 tree->Branch("hpos1",&hpos1,"hpos1/D");
00801 tree->Branch("vpos1",&vpos1,"vpos1/D");
00802 tree->Branch("hpos2",&hpos2,"hpos2/D");
00803 tree->Branch("vpos2",&vpos2,"vpos2/D");
00804 tree->Branch("hornI",&hornI,"hornI/D");
00805 tree->Branch("closestspill",&closestspill,"closestspill/D");
00806 tree->Branch("beamcnf",&beamcnf,"beamcnf/i");
00807 tree->Branch("nuTarZ",&nuTarZ,"nuTarZ/D");
00808 tree->Branch("goodbeam",&goodbeam,"goodbeam/I");
00809 tree->Branch("horn_on",&horn_on,"horn_on/i");
00810 tree->Branch("target_in",&target_in,"target_in/i");
00811 tree->Branch("n_batches",&n_batches,"n_batches/i");
00812 tree->Branch("tor101",&tor101,"tor101/F");
00813 tree->Branch("tr101d",&tr101d,"tr101d/F");
00814 tree->Branch("tortgt",&tortgt,"tortgt/F");
00815 tree->Branch("trtgtd",&trtgtd,"trtgtd/F");
00816 tree->Branch("hadmon",&hadmon,"hadmon/F");
00817 tree->Branch("mumon1",&mumon1,"mumon1/F");
00818 tree->Branch("mumon2",&mumon2,"mumon2/F");
00819 tree->Branch("mumon3",&mumon3,"mumon3/F");
00820
00821
00822 Short_t coil_stat;
00823 tree->Branch("coil_stat",&coil_stat,"coil_stat/S");
00824
00825
00826
00827 tree->Branch("NuParent","NuParent",&nuparent,8000,1);
00828
00829
00830 Int_t fluxrun;
00831 Int_t fluxevtno;
00832 Float_t nudxdz;
00833 Float_t nudydz;
00834 Float_t nupz;
00835 Float_t nuenergy;
00836 Float_t nudxdznear;
00837 Float_t nudydznear;
00838 Float_t nuenergynear;
00839 Float_t nwtnear;
00840 Float_t nudxdzfar;
00841 Float_t nudydzfar;
00842 Float_t nuenergyfar;
00843 Float_t nwtfar;
00844 Int_t norig;
00845 Int_t ndecay;
00846 Int_t ntype;
00847 Float_t vx;
00848 Float_t vy;
00849 Float_t vz;
00850 Float_t pdpx;
00851 Float_t pdpy;
00852 Float_t pdpz;
00853 Float_t ppdxdz;
00854 Float_t ppdydz;
00855 Float_t pppz;
00856 Float_t ppenergy;
00857 Int_t ppmedium;
00858 Int_t ptype;
00859 Float_t ppvx;
00860 Float_t ppvy;
00861 Float_t ppvz;
00862 Float_t muparpx;
00863 Float_t muparpy;
00864 Float_t muparpz;
00865 Float_t mupare;
00866 Float_t necm;
00867 Float_t nimpwt;
00868 Float_t xpoint;
00869 Float_t ypoint;
00870 Float_t zpoint;
00871 Float_t tvx;
00872 Float_t tvy;
00873 Float_t tvz;
00874 Float_t tpx;
00875 Float_t tpy;
00876 Float_t tpz;
00877 Int_t tptype;
00878 Int_t tgen;
00879
00880 tree->Branch("fluxrun",&fluxrun,"fluxrun/I");
00881 tree->Branch("fluxevtno",&fluxevtno,"fluxevtno/I");
00882 tree->Branch("nudxdz",&nudxdz,"nudxdz/F");
00883 tree->Branch("nudydz",&nudydz,"nudydz/F");
00884 tree->Branch("nupz",&nupz,"nupz/F");
00885 tree->Branch("nuenergy",&nuenergy,"nuenergy/F");
00886 tree->Branch("nudxdznear",&nudxdznear,"nudxdznear/F");
00887 tree->Branch("nudydznear",&nudydznear,"nudydznear/F");
00888 tree->Branch("nuenergynear",&nuenergynear,"nuenergynear/F");
00889 tree->Branch("nwtnear",&nwtnear,"nwtnear/F");
00890 tree->Branch("nudxdzfar",&nudxdzfar,"nudxdzfar/F");
00891 tree->Branch("nudydzfar",&nudydzfar,"nudydzfar/F");
00892 tree->Branch("nuenergyfar",&nuenergyfar,"nuenergyfar/F");
00893 tree->Branch("nwtfar",&nwtfar,"nwtfar/F");
00894 tree->Branch("norig",&norig,"norig/I");
00895 tree->Branch("ndecay",&ndecay,"ndecay/I");
00896 tree->Branch("ntype",&ntype,"ntype/I");
00897 tree->Branch("vx",&vx,"vx/F");
00898 tree->Branch("vy",&vy,"vy/F");
00899 tree->Branch("vz",&vz,"vz/F");
00900 tree->Branch("pdpx",&pdpx,"pdpx/F");
00901 tree->Branch("pdpy",&pdpy,"pdpy/F");
00902 tree->Branch("pdpz",&pdpz,"pdpz/F");
00903 tree->Branch("ppdxdz",&ppdxdz,"ppdxdz/F");
00904 tree->Branch("ppdydz",&ppdydz,"ppdydz/F");
00905 tree->Branch("pppz",&pppz,"pppz/F");
00906 tree->Branch("ppenergy",&ppenergy,"ppenergy/F");
00907 tree->Branch("ppmedium",&ppmedium,"ppmedium/I");
00908 tree->Branch("ptype",&ptype,"ptype/I");
00909 tree->Branch("ppvx",&ppvx,"ppvx/F");
00910 tree->Branch("ppvy",&ppvy,"ppvy/F");
00911 tree->Branch("ppvz",&ppvz,"ppvz/F");
00912 tree->Branch("muparpx",&muparpx,"muparpx/F");
00913 tree->Branch("muparpy",&muparpy,"muparpy/F");
00914 tree->Branch("muparpz",&muparpz,"muparpz/F");
00915 tree->Branch("mupare",&mupare,"mupare/F");
00916 tree->Branch("necm",&necm,"necm/F");
00917 tree->Branch("nimpwt",&nimpwt,"nimpwt/F");
00918 tree->Branch("xpoint",&xpoint,"xpoint/F");
00919 tree->Branch("ypoint",&ypoint,"ypoint/F");
00920 tree->Branch("zpoint",&zpoint,"zpoint/F");
00921 tree->Branch("tvx",&tvx,"tvx/F");
00922 tree->Branch("tvy",&tvy,"tvy/F");
00923 tree->Branch("tvz",&tvz,"tvz/F");
00924 tree->Branch("tpx",&tpx,"tpx/F");
00925 tree->Branch("tpy",&tpy,"tpy/F");
00926 tree->Branch("tpz",&tpz,"tpz/F");
00927 tree->Branch("tptype",&tptype,"tptype/I");
00928 tree->Branch("tgen",&tgen,"tgen/I");
00929
00930
00931 float pottor101=0.;
00932 float pottortgt=0.;
00933 float pot=0.;
00934 int NRUNS=0;
00935 int NSNARLS=0;
00936 TTree *pottree = new TTree("pottree","pottree");
00937 pottree->Branch("pot",&pot,"pot/F");
00938 pottree->Branch("pottor101",&pottor101,"pottor101/F");
00939 pottree->Branch("pottortgt",&pottortgt,"pottortgt/F");
00940 pottree->Branch("nruns",&NRUNS,"nruns/I");
00941 pottree->Branch("nsnarls",&NSNARLS,"nsnarls/I");
00942
00943
00944 BMSpillAna bmana;
00945
00946
00950 TTree* inukerw = 0;
00951 int n_inuke_wts=0;
00952 float* inuke_wts=0;
00953 double nucrad=-1.0;
00954 double wrad=1.0;
00955 std::vector<inuke_reweight::parameter_set> psets;
00956
00957 if(file_is_mc && fDoInukeReweight){
00958
00959 inuke_reweight::parameter_set sigmas;
00960
00961 neugen_config nc("MODBYRS");
00962 nc.set_config_no(4);
00963 neugen_wrapper nw(&nc);
00964 nw.print_configuration();
00965 gSystem->Setenv("NEUGEN3_XSEC","MODBYRS4_xsec.dat");
00966 nw.begin_generation();
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976
00977 sigmas.pi_fate.elas=0.1;
00978 sigmas.pi_fate.inel=0.4;
00979 sigmas.pi_fate.abs=0.3;
00980 sigmas.pi_fate.cex=0.49;
00981 sigmas.pi_fate.piprod=0.2;
00982
00983 sigmas.pi_scale.xsec=0.1;
00984
00985 sigmas.pn_fate.abs=0.2;
00986 sigmas.pn_fate.piprod=0.2;
00987
00988 sigmas.pn_scale.xsec=0.1;
00989
00990 sigmas.pi_scale.ft=0.5;
00991
00992 std::cout<<"Inuke Reweight sigmas: "<<std::endl;
00993 sigmas.print(std::cout);
00994
00995 if(fNRandomSets<=0) {
00996 inuke_reweight::generate_1sigma_shifts(sigmas,psets);
00997 for (unsigned int iset=0; iset<psets.size(); iset++){
00998 psets[iset].pi_fate.set_abs_fates();
00999 psets[iset].pn_fate.set_abs_fates();
01000 psets[iset].pn_scale.ft=psets[iset].pi_scale.ft;
01001
01002 if(psets[iset].pn_scale.xsec!=0) {
01003 psets[iset].pn_fate.elas = 2.0*psets[iset].pn_scale.xsec;
01004 }
01005 }
01006 }
01007 else{
01008 inuke_reweight::parameter_limits limits(sigmas,2.0);
01009 limits.upper.pi_scale.ft=0.5;
01010 limits.lower.pi_scale.ft=-0.5;
01011 std::cout<<"Inuke Reweight Limits: "<<std::endl;
01012 limits.print(std::cout);
01013 gRandom->SetSeed(1);
01014 for(int i=0; i<fNRandomSets; i++){
01015 inuke_reweight::parameter_set p;
01016 inuke_reweight::generate_uncor_shifts(sigmas,limits,p);
01017 psets.push_back(p);
01018 }
01019
01020 for(int iset=0; iset<fNRandomSets; iset++){
01021 psets[iset].pi_fate.set_abs_fates();
01022 psets[iset].pn_fate.set_abs_fates();
01023 psets[iset].pn_scale.ft=psets[iset].pi_scale.ft;
01024
01025 if(psets[iset].pn_scale.xsec!=0) {
01026 psets[iset].pn_fate.elas = 2.0*psets[iset].pn_scale.xsec;
01027 }
01028 }
01029
01030
01031 }
01032
01033 n_inuke_wts=psets.size();
01034 inuke_wts = new float[n_inuke_wts];
01035
01036
01037 inukerw=tree;
01038 inukerw->Branch("r",&run,"r/I");
01039 inukerw->Branch("s",&snarl,"s/I");
01040 inukerw->Branch("e",&event,"e/I");
01041 inukerw->Branch("nwts",&n_inuke_wts,"nwts/I");
01042 inukerw->Branch("wts",inuke_wts,"wts[nwts]/F");
01043 inukerw->Branch("nucrad",&nucrad,"nucrad/D");
01044 inukerw->Branch("wrad",&wrad,"wrad/D");
01045
01046
01047
01048 for(int ipar=0; ipar<24; ipar++){
01049 TVectorD* vptr = new TVectorD(n_inuke_wts);
01050 inukerw->GetUserInfo()->Add(vptr);
01051 }
01052 for(int iset=0; iset<n_inuke_wts; iset++){
01053 for(int ipar=0; ipar<24; ipar++){
01054 TVectorD* vptr =
01055 dynamic_cast<TVectorD*>(inukerw->GetUserInfo()->At(ipar));
01056 (*vptr)[iset]=psets[iset].get_par(ipar);
01057 }
01058 }
01059
01060
01061 }
01062
01066
01067
01068
01069
01070
01071
01072
01073
01074
01080 BeamEnergyCalculator ecalc(&fBECConfig);
01081 double bec_high=0; double bec_low=0;
01082 ecalc.GetStandardConfig()->Print();
01083 ecalc.GetStandardConfig()->Get("beam:high_energy_limit",bec_high);
01084 ecalc.GetStandardConfig()->Get("beam:low_energy_limit",bec_low);
01085
01086
01087
01088
01089
01090
01092
01093
01094 int lastrun=-1;
01095 for(int ii=0;ii<Nentries;ii++){
01096 if(ii%1000==0) std::cout << float(ii)*100./float(Nentries)
01097 << "% done" << std::endl;
01098
01099 if(!this->GetEntry(ii)) continue;
01100 NSNARLS++;
01101
01102 if(file_is_mc) FillMCHists(&save);
01103
01104
01105
01106
01107
01108
01109
01110
01111
01112
01113
01114
01115
01116
01117
01118
01119
01120
01121
01122
01123
01124
01125 nevent = eventSummary->nevent;
01126 run = ntpHeader->GetRun();
01127 if(run!=lastrun){
01128 NRUNS++;
01129 lastrun = run;
01130 }
01131 snarl = ntpHeader->GetSnarl();
01132 subrun = ntpHeader->GetSubRun();
01133 trgsrc = ntpHeader->GetTrigSrc();
01134 spilltype = ntpHeader->GetRemoteSpillType();
01135 trgtime = eventSummary->trigtime;
01136 litime = eventSummary->litime;
01137 coil_stat = detStatus->coilstatus;
01138 dmx_stat=0;
01139
01140
01141 dmx_stat+=(dmxStatus->nonphysicalfail);
01142 dmx_stat+=((dmxStatus->validplanesfail<<1));
01143 dmx_stat+=((dmxStatus->vertexplanefail<<2));
01144
01145
01146 lowphrat=0.;
01147 lowphrat = ComputeLowPHRatio();
01148
01150
01151
01152
01154 NearbyVertexFinder nby(nevent);
01155 nby.ProcessEntry(this);
01156
01157
01158 detector = -1;
01159
01160 const Detector::Detector_t det
01161 = ntpHeader->GetVldContext().GetDetector();
01162 if(det==Detector::kFar){
01163 detector = 2;
01164 }
01165 else if(det==Detector::kNear){
01166 detector = 1;
01167 }
01168
01169 BeamType::BeamType_t current_beam=BeamType::kUnknown;
01170 if(file_is_mc){
01171
01172 current_beam=fMCBeam;
01173
01174 }
01175
01176
01178
01180 hbw=vbw=hpos1=vpos1=hpos2=vpos2=hornI=closestspill=0.0;
01181 beamcnf=0;
01182 nuTarZ=0.0;
01183 goodbeam=0;
01184 horn_on=target_in=n_batches=0;
01185 tor101=tr101d=tortgt=trtgtd=0.0;
01186 hadmon=mumon1=mumon2=mumon3=0.0;
01187
01188 if(!file_is_mc){
01189 VldContext vc = ntpHeader->GetVldContext();
01190 VldTimeStamp vts = vc.GetTimeStamp();
01191
01192 BDSpillAccessor &sa = BDSpillAccessor::Get();
01193 const BeamMonSpill *bs = sa.LoadSpill(vts);
01194 hbw=bs->fProfWidX*1000.;
01195 vbw=bs->fProfWidY*1000.;
01196 hpos1=bs->fTargProfX*1000.;
01197 vpos1=bs->fTargProfY*1000.;
01198 n_batches=0;
01199 float btint=0.;
01200 hpos2=0.;
01201 vpos2=0.;
01202 for(int bt=0;bt<6;bt++){
01203
01204
01205 hpos2+=(bs->fTargBpmX[bt]*bs->fBpmInt[bt]);
01206 vpos2+=(bs->fTargBpmY[bt]*bs->fBpmInt[bt]);
01207 if(bs->fBpmInt[bt]>0.001){
01208 n_batches++;
01209 }
01210 btint+=bs->fBpmInt[bt];
01211 }
01212 if(btint!=0){
01213 hpos2=hpos2*1000./btint;
01214 vpos2=vpos2*1000./btint;
01215 }
01216 else{
01217 hpos2=-999.;
01218 vpos2=-999.;
01219 }
01220
01221 hornI=bs->fHornCur;
01222 SpillTimeFinder &sfind= SpillTimeFinder::Instance();
01223 closestspill =
01224 sfind.GetTimeToNearestSpill(vc);
01225
01226 beamcnf =bs->GetStatusBits().beam_type;
01227 nuTarZ=0.;
01228 horn_on = bs->GetStatusBits().horn_on;
01229 target_in = bs->GetStatusBits().target_in;
01230
01231
01232 tor101=bs->fTor101;
01233 tr101d=bs->fTr101d;
01234 tortgt=bs->fTortgt;
01235 trtgtd=bs->fTrtgtd;
01236 hadmon=bs->fHadInt;
01237 mumon1=bs->fMuInt1;
01238 mumon2=bs->fMuInt2;
01239 mumon3=bs->fMuInt3;
01240
01241 goodbeam=0;
01242
01243
01244
01245
01246
01247
01248
01249
01250
01251
01252
01253
01254
01255
01256
01257
01258
01259
01260
01261
01262
01263
01264
01265
01266
01267
01268
01269
01270
01271
01272
01273
01274
01275
01276
01277
01278
01279
01280
01281
01282
01283
01284
01285
01286
01287
01288
01289
01290
01291
01292
01293
01294
01295
01296 bmana.SetSpill(*bs);
01297 bmana.SetTimeDiff(closestspill);
01298 if(bmana.SelectSpill()){
01299 goodbeam=1;
01300 }
01301 else{
01302 goodbeam=0;
01303 }
01304
01305
01306 if(fDataUseMCBeam==true){
01307
01308 current_beam=fMCBeam;
01309 }
01310 else{
01311
01312 current_beam = BeamType::FromBeamMon(beamcnf);
01313 }
01314
01315 if(goodbeam==1&&spilltype!=3){
01316 pot+=tortgt;
01317 pottor101+=tor101;
01318 pottortgt+=tortgt;
01319 }
01320 }
01321
01322
01323 event=-1; ntrack=-1; nshower=-1; reco_emu=0.0; reco_enu=0.0; reco_eshw=0;
01324 true_enu=0.0; true_emu=0.0; true_eshw=0.0;
01325 pass=0; is_fid=0;
01326 tree->Fill();
01327 for(int iwt=0; iwt<n_inuke_wts; iwt++) inuke_wts[iwt]=-1.0;
01328 if(inukerw!=0 && inukerw!=tree) inukerw->Fill();
01329
01330 if(nevent==0) continue;
01331
01332 for(int i=0;i<eventSummary->nevent;i++){
01333 if(!LoadEvent(i)) continue;
01334
01335
01336 event = i;
01337 ntrack = ntpEvent->ntrack;
01338 nshower = ntpEvent->nshower;
01339 nstrip = ntpEvent->nstrip;
01340
01342
01343 true_enu = 0; true_emu = 0; true_eshw = 0; true_x = 0; true_y = 0;
01344 true_q2 = 0; true_w2 = 0; true_dircosneu = 0; true_dircosz = 0;
01345 true_vtxx = 0; true_vtxy = 0; true_vtxz = 0; true_pitt_fid=0;
01346 true_trk_cmplt=0.;
01347 resnum=0;
01348 npp=npm=npz=np=nn=0;
01349 epp=epm=epz=ep=en=0.0;
01350
01351 fluxrun=0; fluxevtno=0; nudxdz=0.; nudydz=0.; nupz=0.; nuenergy=0.;
01352 nudxdznear=0.; nudydznear=0.; nuenergynear=0.; nwtnear=0.; nudxdzfar=0.;
01353 nudydzfar=0.; nuenergyfar=0.; nwtfar=0.; norig=0; ndecay=0; ntype=0;
01354 vx=0.; vy=0.; vz=0.; pdpx=0.; pdpy=0.; pdpz=0.; ppdxdz=0.; ppdydz=0.; pppz=0.;
01355 ppenergy=0.; ppmedium=0; ptype=0; ppvx=0.; ppvy=0.; ppvz=0.;
01356 muparpx=0.; muparpy=0.; muparpz=0.; mupare=0.; necm=0.; nimpwt=0.;
01357 xpoint=0.; ypoint=0.; zpoint=0.; tvx=0.; tvy=0.; tvz=0.; tpx=0.;
01358 tpy=0.; tpz=0.; tptype=0; tgen=0;
01359
01360 flavour = 0; process = 0; nucleus = 0; cc_nc = 0; initial_state = 0;
01361
01362 mcevent = -1;
01363 is_fid = 0; is_cev = 0; is_mc = 0; pass_basic = 0;
01364 is_pitt_fid=0; pitt_evt_class=0; pitt_trk_qual=0; nd_radial_fid=0;
01365 is_trk_fid=0;
01366 duvvtx=0;
01367 pid0 = 0; pid1 = 0; pid2 = 0; pass = 0;
01368 reco_enu = 0; reco_emu = 0; reco_eshw = 0; reco_wtd_eshw=0;
01369 reco_vtx_eshw=0; reco_vtx_wtd_eshw=0;
01370 reco_qe_enu = 0; reco_mushw=0;
01371 reco_qe_q2 = 0; reco_dircosneu = 0; reco_dircosz = 0;
01372 reco_vtxx = reco_vtxy = reco_vtxz = reco_vtxr=0;
01373 reco_trk_vtxx = reco_trk_vtxy = reco_trk_vtxz = reco_trk_vtxr=0;
01374 reco_shw_vtxx = reco_shw_vtxy = reco_shw_vtxz = reco_shw_vtxr=0;
01375 reco_trk_endx = reco_trk_endy = reco_trk_endz = reco_trk_endr=0;
01376 evt_nstrips = slc_nstrips = trk_nstrips=0;
01377 evt_nplanes = slc_nplanes = trk_nplanes=0;
01378 shw_nplanes_cut=shw_nplanes_raw=0;
01379 shw_ph_cut=shw_ph_raw=0.0;
01380
01381 evtlength = trklength = shwlength=trknstp=0;
01382 trkphfrac = trkphplane = 0;
01383 ntrklike= trkend=trkendu=trkendv=shwbeg=shwend=0;
01384 trkmomrange = 0; trkqp = 0; trkeqp = 0;
01385 trkchi2=0.0; trkndf=0;
01386 pass_track=0; emu_meth=0;
01387
01388
01389 reco_y = reco_x = reco_Q2 = reco_W2 = -1;
01390
01391 shw_pur = shw_comp = -1;
01392
01393
01394
01395 nvsi=nvti=bvsi=bvti=-1;
01396 nvsevt=bvsevt=nvtevt=bvtevt=-1;
01397 nvsd=nvtd=bvsd=bvtd=999999;
01398 nvst=bvst=nvtt=bvtt=1e6;
01399 nvsp=nvtp=bvsp=bvtp=-1.0;
01400
01401 evtph=0; evtphgev=0;
01402 evtsigfull=evtsigpart=trksigfull=trksigpart=0;
01403
01404 evttimemin=evttimemax=evttimeln=0.;
01405 evttimeminphc=evttimemaxphc=evttimelnphc=0.;
01406
01407 earlywph=earlywphpw=earlywphsphere=0.;
01408 ph1000=ph500=ph100=0.;
01409 lateph1000=lateph500=lateph100=lateph50=0.;
01410
01411 nduprs=0;
01412 dupphrs=0.;
01413
01414 nu_px=nu_py=nu_pz=tar_px=tar_py=tar_pz=tar_e=0.0;
01415 inu=0;
01416 ntotss=0;
01417 for(int iss=0; iss<6; iss++){nss[iss]=0; ess[iss]=0;}
01418
01419 med_qe_pid=-1001.0;
01420 med_qe_pass=0;
01421 niki_cc_pid=-999;
01422 dave_cc_pid=-999;
01423
01424 is_fid = InFidVol();
01425
01426
01427
01428
01429 if(LoadTruthForRecoTH(i,mcevent)) {
01430
01431
01432
01433
01434
01435 is_mc = 1;
01436 nucleus = Nucleus(mcevent);
01437 flavour = Flavour(mcevent);
01438 initial_state = Initial_state(mcevent);
01439 process = IResonance(mcevent);
01440 cc_nc = IAction(mcevent);
01441 true_enu = TrueNuEnergy(mcevent);
01442 true_emu = TrueMuEnergy(mcevent);
01443 true_eshw = TrueShwEnergy(mcevent);
01444 true_x = X(mcevent);
01445 true_y = Y(mcevent);
01446 true_q2 = Q2(mcevent);
01447 true_w2 = W2(mcevent);
01448 true_dircosz = TrueMuDCosZ(mcevent);
01449 true_dircosneu = TrueMuDCosNeu(mcevent);
01450
01451
01452
01453 if(LoadTruth(mcevent)){
01454 fluxrun=ntpTruth->flux.fluxrun;
01455 fluxevtno=ntpTruth->flux.fluxevtno;
01456 nudxdz=ntpTruth->flux.ndxdz;
01457 nudydz=ntpTruth->flux.ndydz;
01458 nupz=ntpTruth->flux.npz;
01459 nuenergy=ntpTruth->flux.nenergy;
01460 nudxdznear=ntpTruth->flux.ndxdznear;
01461 nudydznear=ntpTruth->flux.ndydznear;
01462 nuenergynear=ntpTruth->flux.nenergynear;
01463 nwtnear=ntpTruth->flux.nwtnear;
01464 nudxdzfar=ntpTruth->flux.ndxdzfar;
01465 nudydzfar=ntpTruth->flux.ndydzfar;
01466 nuenergyfar=ntpTruth->flux.nenergyfar;
01467 nwtfar=ntpTruth->flux.nwtfar;
01468 norig=ntpTruth->flux.norig;
01469 ndecay=ntpTruth->flux.ndecay;
01470 ntype=ntpTruth->flux.ntype;
01471 vx=ntpTruth->flux.vx;
01472 vy=ntpTruth->flux.vy;
01473 vz=ntpTruth->flux.vz;
01474 pdpx=ntpTruth->flux.pdpx;
01475 pdpy=ntpTruth->flux.pdpy;
01476 pdpz=ntpTruth->flux.pdpz;
01477 ppdxdz=ntpTruth->flux.ppdxdz;
01478 ppdydz=ntpTruth->flux.ppdydz;
01479 pppz=ntpTruth->flux.pppz;
01480 ppenergy=ntpTruth->flux.ppenergy;
01481 ppmedium=ntpTruth->flux.ppmedium;
01482 ptype=ntpTruth->flux.ptype;
01483 ppvx=ntpTruth->flux.ppvx;
01484 ppvy=ntpTruth->flux.ppvy;
01485 ppvz=ntpTruth->flux.ppvz;
01486 muparpx=ntpTruth->flux.muparpx;
01487 muparpy=ntpTruth->flux.muparpy;
01488 muparpz=ntpTruth->flux.muparpz;
01489 mupare=ntpTruth->flux.mupare;
01490 necm=ntpTruth->flux.necm;
01491 nimpwt=ntpTruth->flux.nimpwt;
01492 xpoint=ntpTruth->flux.xpoint;
01493 ypoint=ntpTruth->flux.ypoint;
01494 zpoint=ntpTruth->flux.zpoint;
01495 tvx=ntpTruth->flux.tvx;
01496 tvy=ntpTruth->flux.tvy;
01497 tvz=ntpTruth->flux.tvz;
01498 tpx=ntpTruth->flux.tpx;
01499 tpy=ntpTruth->flux.tpy;
01500 tpz=ntpTruth->flux.tpz;
01501 tptype=ntpTruth->flux.tptype;
01502 tgen=ntpTruth->flux.tgen;
01503 }
01504
01505 if(ntpTHTrack){
01506 if(ntpTHTrack->neumc==mcevent){
01507 true_trk_cmplt=ntpTHTrack->completeslc;
01508 }
01509 }
01510
01511 Float_t* true_p = TrueNuMom(mcevent);
01512 if(true_p){
01513 nu_px=true_p[0]; nu_py=true_p[1]; nu_pz=true_p[2];
01514 delete[] true_p; true_p=0;
01515 }
01516 true_p = Target4Vector(mcevent);
01517 if(true_p){
01518 tar_px=true_p[0]; tar_py=true_p[1]; tar_pz=true_p[2];
01519 tar_e=true_p[3];
01520 delete[] true_p; true_p=0;
01521 }
01522
01523 Float_t *vtx = TrueVtx(mcevent);
01524 true_vtxx = vtx[0];
01525 true_vtxy = vtx[1];
01526 true_vtxz = vtx[2];
01527 float true_vtxu = (true_vtxx + true_vtxy)/sqrt(2.0);
01528 float true_vtxv = (true_vtxy - true_vtxx)/sqrt(2.0);
01529 true_pitt_fid=PittInFidVol(true_vtxx, true_vtxy,
01530 true_vtxz,
01531 true_vtxu, true_vtxv);
01532
01533 resnum = HadronicFinalState(mcevent);
01534 npp = NumFSPion(mcevent,+1);
01535 npm = NumFSPion(mcevent,-1);
01536 npz = NumFSPiZero(mcevent);
01537 np = NumFSProton(mcevent);
01538 nn = NumFSNeutron(mcevent);
01539
01540 epp = TotFSPionEnergy(mcevent,+1);
01541 epm = TotFSPionEnergy(mcevent,-1);
01542 epz = TotFSPiZeroEnergy(mcevent);
01543 ep = TotFSProtonEnergy(mcevent);
01544 en = TotFSNeutronEnergy(mcevent);
01545
01546
01547 inu=0;
01548 inu = INu(mcevent);
01549
01550
01551
01552
01553
01554
01555
01556
01557
01558
01559
01560
01561
01562
01563
01565 delete [] vtx;
01566 }
01567
01568 if(PassBasicCuts(event)) {
01569
01570 pass_basic = 1;
01571
01572
01573
01574 int track_index = -1;
01575
01576 LoadLargestTrackFromEvent(i,track_index);
01577
01578 pass_track = PassTrackCuts(track_index);
01579
01580
01581 reco_emu = RecoMKMuEnergy(emu_meth,track_index);
01582
01583 int shower_index = -1;
01584
01585
01586
01587
01588
01589
01590
01591
01592
01593
01594
01595
01596
01597
01598
01599
01600
01601 LoadShower_Jim(i,shower_index,det);
01602 reco_eshw = RecoShwEnergy(shower_index, det,1,!file_is_mc);
01603 if(shower_index>-1) reco_wtd_eshw = ntpShower->shwph.wtCCgev;
01604 reco_vtx_eshw = reco_eshw;
01605 reco_vtx_wtd_eshw = reco_wtd_eshw;
01606
01607
01608 if(is_mc && shower_index>-1){
01609 LoadTHShower(shower_index);
01610 assert(ntpTHShower);
01611 shw_pur=ntpTHShower->purity;
01612 shw_comp=ntpTHShower->completeslc;
01613 }
01614
01615
01616 reco_enu = reco_emu + reco_eshw;
01617
01618 evtphgev = ntpEvent->ph.gev;
01619 if(reco_enu>0){
01620 reco_qe_enu = RecoQENuEnergy(track_index);
01621 reco_qe_q2 = RecoQEQ2(track_index);
01622
01623
01624 is_cev = IsFidAll(track_index);
01625
01626 if(detector==1){
01627
01628
01629
01630 is_pitt_fid = PittInFidVol(ntpEvent->vtx.x, ntpEvent->vtx.y,
01631 ntpEvent->vtx.z,
01632 ntpEvent->vtx.u, ntpEvent->vtx.v);
01633 nd_radial_fid = NDRadialFidVol(ntpEvent->vtx.x,ntpEvent->vtx.y,
01634 ntpEvent->vtx.z);
01635 }
01636 else{
01637 is_pitt_fid = InFidVol();
01638 }
01639
01640 reco_vtxx = ntpEvent->vtx.x;
01641 reco_vtxy = ntpEvent->vtx.y;
01642 reco_vtxz = ntpEvent->vtx.z;
01643
01644
01645
01646
01647 if(shower_index!=-1){
01648
01649 const float max_shw_dist=14*0.06;
01650 float dist_z = fabs(reco_vtxz - ntpShower->vtx.z);
01651 float dist_r = sqrt( pow(ntpEvent->vtx.u-ntpShower->vtx.u,2) +
01652 pow(ntpEvent->vtx.v-ntpShower->vtx.v,2) );
01653 if( (dist_z + dist_r) > max_shw_dist ){
01654 reco_vtx_eshw=0;
01655 reco_vtx_wtd_eshw=0;
01656 }
01657
01658 }
01659
01660 if(detector==1){
01661 reco_vtxr = pow(reco_vtxx-kXcenter,2)
01662 + pow(reco_vtxy-kYcenter,2);
01663 reco_vtxr=sqrt(reco_vtxr);
01664 }
01665 else reco_vtxr = sqrt (pow(reco_vtxx,2)+pow(reco_vtxy,2));
01666
01667
01668 SigInOut(track_index,evtsigfull,evtsigpart,trksigfull,trksigpart);
01669 if(detector==2){
01670
01671 evtsigfull=ntpEvent->ph.sigcor;
01672 evtsigpart=0.;
01673 if(track_index!=-1){
01674 trksigfull=ntpTrack->ph.sigcor;
01675 }
01676 else{
01677 trksigfull=0.;
01678 }
01679 trksigpart=0.;
01680 }
01681
01682
01683 reco_dircosz = RecoMuDCosZ(track_index);
01684
01685
01686 float vtx_array[3];
01687 vtx_array[0]=ntpEvent->vtx.x; vtx_array[2]=ntpEvent->vtx.y;
01688 vtx_array[2]=ntpEvent->vtx.z;
01689 if(detector==1)
01690 reco_dircosneu = RecoMuDCosNeuND(track_index, vtx_array);
01691 else reco_dircosneu = RecoMuDCosNeuFD(track_index, vtx_array);
01692
01693 evtlength = ntpEvent->plane.end-ntpEvent->plane.beg;
01694 if(track_index!=-1){
01695
01696 trklength = ntpTrack->plane.end-ntpTrack->plane.beg;
01697 ntrklike =ntpTrack->plane.ntrklike;
01698 trkend = ntpTrack->plane.end;
01699 trkendu = ntpTrack->plane.endu;
01700 trkendv = ntpTrack->plane.endv;
01701 trknstp = ntpTrack->nstrip;
01702 trkmomrange = ntpTrack->momentum.range;
01703 trkmomrange = CorrectMomentumFromRange(trkmomrange,!file_is_mc,det);
01704 trkqp = ntpTrack->momentum.qp;
01705 if(trkqp!=0){
01706 trkqp = 1.0/CorrectSignedMomentumFromCurvature(1.0/trkqp,
01707 !file_is_mc, det);
01708 }
01709
01710 trkeqp = ntpTrack->momentum.eqp;
01711 trkphfrac = ntpTrack->ph.sigcor/ntpEvent->ph.sigcor;
01712 trkphplane = ntpTrack->ph.mip/ntpTrack->plane.n;
01713 trkchi2 = ntpTrack->fit.chi2;
01714 trkndf = ntpTrack->fit.ndof;
01715 reco_trk_vtxx = ntpTrack->vtx.x;
01716 reco_trk_vtxy = ntpTrack->vtx.y;
01717 reco_trk_vtxz = ntpTrack->vtx.z;
01718
01719 reco_trk_endx = ntpTrack->end.x;
01720 reco_trk_endy = ntpTrack->end.y;
01721 reco_trk_endz = ntpTrack->end.z;
01722
01723 pitt_evt_class = PittTrkContained(ntpTrack->end.x,
01724 ntpTrack->end.y,
01725 ntpTrack->end.z,
01726 ntpTrack->end.u,
01727 ntpTrack->end.v);
01728 duvvtx=abs(ntpTrack->plane.begu - ntpTrack->plane.begv);
01729
01730
01731 if(detector==1){
01732 if(pitt_evt_class>0){
01733 int do_meth=0;
01734 if( (pitt_evt_class == 1) || (pitt_evt_class == 3) )
01735 do_meth=2;
01736 else if( (pitt_evt_class == 2) || (pitt_evt_class == 4) )
01737 do_meth=1;
01738 if(do_meth==1 || do_meth==2){
01739 reco_emu = RecoMKMuEnergy(do_meth,track_index,
01740 !file_is_mc,det);
01741 reco_enu = reco_emu+reco_eshw;
01742 }
01743 emu_meth=do_meth;
01744 }
01745 }
01746 else if(detector==2){
01747 int do_meth=FarTrkContained(ntpTrack->end.x,
01748 ntpTrack->end.y,
01749 ntpTrack->end.z);
01750 if(do_meth==1 || do_meth==2){
01751 reco_emu = RecoMKMuEnergy(do_meth,track_index);
01752 reco_enu = reco_emu+reco_eshw;
01753 }
01754 emu_meth=do_meth;
01755 }
01756
01757
01758 if(detector==1){
01759 is_trk_fid = PittInFidVol(ntpTrack->vtx.x, ntpTrack->vtx.y,
01760 ntpTrack->vtx.z,
01761 ntpTrack->vtx.u, ntpTrack->vtx.v);
01762 }
01763 else{
01764 is_trk_fid = InFidVol(ntpTrack->vtx.x,ntpTrack->vtx.y,
01765 ntpTrack->vtx.z);
01766 }
01767
01768
01769 reco_mushw=MuonShowerEnergy(ntpEvent, ntpTrack);
01770
01771
01772 Double_t tmp_ndof=ntpTrack->fit.ndof;
01773 if(tmp_ndof<=0.0) tmp_ndof=1.0;
01774
01775 if( (ntpTrack->fit.pass>0)
01776 && (ntpTrack->fit.chi2/tmp_ndof <20 )
01777 && abs(ntpTrack->plane.begu - ntpTrack->plane.begv)<6 )
01778 pitt_trk_qual=1;
01779
01781 const double M=(0.93827 + 0.93957)/2.0;
01782 if(reco_emu>0) reco_Q2 =
01783 2*reco_enu*reco_emu*(1.0 - reco_dircosneu);
01784 reco_W2 = M*M - reco_Q2 + 2*M*reco_eshw;
01785 if(reco_enu>0) reco_y = reco_eshw/reco_enu;
01786 if(reco_eshw>0 && reco_Q2>0) reco_x = reco_Q2/(2*M*reco_eshw);
01788
01790 const double muM=0.10566;
01791 const double muP=sqrt(reco_emu*reco_emu -muM*muM);
01792 reco_qe_enu = (M*reco_emu - muM*muM/2.0)
01793 /(M - reco_emu + muP*reco_dircosneu);
01794 reco_qe_q2 = abs(-2.0*reco_qe_enu*(reco_emu-muP*reco_dircosneu)+muM*muM);
01796
01798
01799 med_qe_pid=qeid.AltCalcQEID(this,event,reco_enu,reco_W2);
01800 med_qe_pass=qeid.PassMEDQECut(reco_enu,med_qe_pid);
01802
01804 if(nsid.ChooseWeightFile(det,current_beam)){
01805 if(!nsid.GetPID(this,event,det,niki_cc_pid)) niki_cc_pid=-999;
01806 }
01807 else niki_cc_pid=-999;
01808
01809
01810
01811
01813
01815 if(det==Detector::kFar && !file_is_mc){
01816 dpid.SetPHCorrection(1.018);
01817 }
01818 if(dpid.ChoosePDFs(det,current_beam)){
01819 dave_cc_pid = dpid.CalcPID(this,event,0);
01820 }
01822
01823 TObject *recobj=0;
01824 if(record!=0){
01825 recobj=record;
01826 }
01827 else{
01828 recobj=strecord;
01829 }
01830
01831
01832 LoadTrack(track_index);
01833
01834 float temp_ph;
01835 trk_nplanes=NPlanesInObj(recobj,ntpTrack,1.5,temp_ph);
01836
01837 trk_nstrips=NStripsInObj(recobj,ntpTrack,1.5,temp_ph);
01838
01839 }
01840 else {
01841 trklength = 0;
01842 trkmomrange = 0;
01843 trkqp = 0;
01844 trkeqp = 0;
01845 trkphfrac = 0;
01846 trkphplane = 0;
01847 is_trk_fid = -1;
01848 }
01849
01850
01851
01852
01853 LoadSlice(ntpEvent->slc);
01854
01855
01856 TObject *recobj=0;
01857 if(record!=0){
01858 recobj=record;
01859 }
01860 else{
01861 recobj=strecord;
01862 }
01863
01864 float temp_ph;
01865
01866 slc_nplanes=NPlanesInObj(recobj,ntpSlice,1.5,temp_ph);
01867
01868 evt_nplanes=NPlanesInObj(recobj,ntpEvent,1.5,temp_ph);
01869
01870 slc_nstrips=NStripsInObj(recobj,ntpSlice,1.5,temp_ph);
01871
01872 evt_nstrips=NStripsInObj(recobj,ntpEvent,1.5,temp_ph);
01873
01874
01875 if(shower_index!=-1 && reco_eshw>0){
01876 LoadShower(shower_index);
01877 shwlength=ntpShower->plane.n;
01878 shw_nplanes_raw=NPlanesInObj(recobj,ntpShower,0.0,shw_ph_raw);
01879 shw_nplanes_cut=NPlanesInObj(recobj,ntpShower,1.5,shw_ph_cut);
01880
01881 shwend=ntpShower->plane.end;
01882 shwbeg=ntpShower->plane.beg;
01883 reco_shw_vtxx=ntpShower->vtx.x;
01884 reco_shw_vtxy=ntpShower->vtx.y;
01885 reco_shw_vtxz=ntpShower->vtx.z;
01886
01887
01889 int ncl = ntpShower->ncluster;
01890
01891
01892
01893
01894
01895
01896
01897
01898
01899
01900
01901
01902
01903
01904
01905 Moments mom_swu;
01906 Moments mom_swu_wtd;
01907 Moments mom_swv;
01908 Moments mom_swv_wtd;
01909
01910 etu=etv=elu=elv=0.0;
01911 swu=swv=wswu=wswv=0.0;
01912
01913
01914 const float ss_cut=0.0;
01915 float totsigssu=0.0;
01916 float totsigssv=0.0;
01917 for(int ii=0; ii<ncl; ii++){
01918 if(LoadCluster(ntpShower->clu[ii])){
01919 if(ntpCluster->ph.gev >ss_cut){
01920 nss[ntpCluster->id]+=1;
01921 ess[ntpCluster->id]+=ntpCluster->ph.gev;
01922 ntotss++;
01923 if(ntpCluster->id <2){
01924
01925 float sinang = sin(atan(ntpCluster->slope));
01926 if(ntpCluster->planeview==PlaneView::kU){
01927 totsigssu+=ntpCluster->ph.gev;
01928
01929 mom_swu.AddPoint(ntpCluster->tposvtx);
01930 mom_swu_wtd.AddPoint(ntpCluster->tposvtx,
01931 ntpCluster->ph.gev);
01932
01933 etu += sinang*ntpCluster->ph.gev;
01934 elu += sqrt(fabs(1-sinang*sinang))*ntpCluster->ph.gev;
01935 }
01936 else if(ntpCluster->planeview==PlaneView::kV){
01937 totsigssv+=ntpCluster->ph.gev;
01938
01939 mom_swv.AddPoint(ntpCluster->tposvtx);
01940 mom_swv_wtd.AddPoint(ntpCluster->tposvtx,
01941 ntpCluster->ph.gev);
01942
01943 etv += sinang*ntpCluster->ph.gev;
01944 elv += sqrt(fabs(1-sinang*sinang))*ntpCluster->ph.gev;
01945 }
01946 }
01947 }
01948 }
01949 }
01950
01951
01952
01953
01954
01955
01956
01957
01958
01959
01960
01961
01962
01963
01964
01965
01966
01967
01968
01969
01970
01971
01972
01973
01974 swv=mom_swv.GetRMS();
01975 swu=mom_swu.GetRMS();
01976 wswv=mom_swv_wtd.GetRMS();
01977 wswu=mom_swu_wtd.GetRMS();
01978
01980 }
01981 if(ntrack==1 && reco_enu>0.0 && reco_enu<140
01982 && is_pitt_fid && pitt_trk_qual && (is_trk_fid!=0)) pass=1;
01983
01984 }
01985 }
01986
01987
01988
01989
01990
01991
01992
01993
01994
01995
01996
01997
01998
01999
02000
02001 nby.ClosestSpatial(i,nvsi,nvsd,nvst,nvsp,nvsevt);
02002 nby.ClosestSpatial(nvsi,bvsi,bvsd,bvst,bvsp,bvsevt);
02003 nby.ClosestTemporal(i,nvti,nvtd,nvtt,nvtp,nvtevt);
02004 nby.ClosestTemporal(nvti,bvti,bvtd,bvtt,bvtp,bvtevt);
02005
02006 GetEvtTimeChar(evttimemin,evttimemax,evttimeln);
02007 GetEvtTimeCharPHC(evttimeminphc,evttimemaxphc,evttimelnphc);
02008 EarlyActivity(i,earlywph,earlywphpw,earlywphsphere,
02009 ph1000,ph500,ph100,lateph1000,lateph500,
02010 lateph100,lateph50);
02011 evtph = ntpEvent->ph.sigcor;
02012
02013 DupRecoStrips(i,nduprs,dupphrs);
02014
02016 if(file_is_mc){
02017 if(gnumi->Status()) {
02018 if(isST) gnumi->GetParent(strecord,mcevent,*nuparent);
02019 else gnumi->GetParent(mcrecord,mcevent,*nuparent);
02020 }
02021 }
02023
02027 if(fDoInukeReweight && file_is_mc && inukerw!=0) {
02028
02029 if((fOnlyWriteFidEvents && is_pitt_fid==1) || !fOnlyWriteFidEvents){
02030 std::vector<double> weights(n_inuke_wts,1.0);
02031
02032 inuke_reweight::calc_weights(strecord,ntpTruth,psets,weights,nucrad,wrad,false);
02033 for (unsigned int iwt=0; iwt<weights.size(); iwt++) inuke_wts[iwt]=weights[iwt];
02034 }
02035
02036
02037 }
02041
02043 if((fOnlyWriteFidEvents && is_pitt_fid==1) || !fOnlyWriteFidEvents) {
02044 tree->Fill(); if(inukerw!=0 && inukerw!=tree) inukerw->Fill();
02045 }
02046
02047
02048 }
02049 }
02050
02051
02052 save.cd();
02053 pottree->Fill();
02054 pottree->Write();
02055 tree->Write();if(inukerw!=0 && inukerw!=tree) inukerw->Write();
02056
02057 save.Write();
02058 save.Close();
02059
02060 }
02061
02062 bool MadMKAnalysis::InFidVol(Int_t evidx){
02063 if(!LoadEvent(evidx)) return false;
02064 return InFidVol();
02065 }
02066
02067 bool MadMKAnalysis::InFidVol()
02068 {
02069 return InFidVol(ntpEvent->vtx.x,ntpEvent->vtx.y,ntpEvent->vtx.z);
02070 }
02071
02072 bool MadMKAnalysis::InFidVol(float vx, float vy, float vz){
02073
02074
02075 bool is_fid=false;
02076
02077
02078 if(ntpHeader->GetVldContext().GetDetector()==Detector::kFar){
02079
02080 is_fid = true;
02081 if(vz<0.5 || vz>28.0 ||
02082 (vz<16.2&&vz>14.3) ||
02083 ((vx*vx)+(vy*vy))>14.0) is_fid = false;
02084 }
02085 else if(ntpHeader->GetVldContext().GetDetector()==Detector::kNear){
02086
02087
02088
02089
02090
02091
02092
02093
02094 is_fid = false;
02095
02096
02097
02098 double radius = pow(vx-kXcenter,2) + pow(vy-kYcenter,2);
02099
02100 radius=sqrt(radius);
02101
02102
02103
02104
02105
02106
02107
02108 if(vz>=1.0 && vz<=5.0 && radius<=1.0) is_fid = true;
02109 }
02110 return is_fid;
02111 }
02112
02113 Float_t MadMKAnalysis::RecoMKMuEnergy(Int_t& opt,Int_t itrk, bool isdata, const Detector::Detector_t det){
02114 const float mumass=0.10566;
02115 if(LoadTrack(itrk)){
02116 float mr=ntpTrack->momentum.range;
02117 mr=CorrectMomentumFromRange(mr,isdata,det);
02118 float mc=0.0;
02119 if(ntpTrack->momentum.qp!=0) mc = 1.0/(ntpTrack->momentum.qp);
02120 mc=CorrectSignedMomentumFromCurvature(mc,isdata,det);
02121
02122 if(opt==0){
02123
02124
02125 if(ntpTrack->fidall.dr>0.5&&ntpTrack->fidall.dz>0.5) {
02126 opt=2;
02127 return sqrt(mr*mr+ mumass*mumass);
02128 }
02129 else {
02130 opt=1;
02131
02132
02133
02134
02135
02136
02137 if(ntpTrack->momentum.qp == 0.0) return 10000.0;
02138 else return sqrt(mc*mc+mumass*mumass);
02139 }
02140 }
02141 else if(opt==1) {
02142 if(ntpTrack->momentum.qp == 0.0) return 10000.0;
02143 else return sqrt(mc*mc+mumass*mumass);
02144 }
02145 else if(opt==2)
02146 return sqrt(mr*mr + mumass*mumass);
02147 else return 0;
02148 }
02149 return 0.;
02150 }
02151
02152 Float_t MadMKAnalysis::RecoShwEnergy(int opt, const Detector::Detector_t& det, int mode, bool isdata){
02153
02154 Float_t result = 0;
02155
02156 Bool_t ok = LoadShower(opt);
02157 if(!ok) return 0;
02158
02159
02160
02161
02162 result = ntpShower->shwph.linCCgev;
02163 if(result<=0.0) result=(ntpShower->ph.gev/1.23);
02164 else{
02165 result = CorrectShowerEnergy(result,det,CandShowerHandle::kCC,mode,isdata);
02166 }
02167 return result;
02168
02169 }
02170
02171
02172
02173
02174
02175
02176
02177
02178
02179
02180
02181
02182
02183
02184
02185
02186
02187
02188
02189
02190
02191 Float_t MadMKAnalysis::RecoMuDCosNeuFD(Int_t itr, Float_t* ){
02192 if(!LoadTrack(itr)) return 0.;
02193
02194 Float_t bl_z = TMath::Cos(TMath::Pi()*3./180.);
02195 Float_t bl_y = sqrt(1. - bl_z*bl_z);
02196 Float_t costhbl = ntpTrack->vtx.dcosz*bl_z + ntpTrack->vtx.dcosy*bl_y;
02197
02198 return costhbl;
02199 }
02200
02201 Float_t MadMKAnalysis::RecoMuDCosNeuND(Int_t itr, Float_t* ){
02202 if(!LoadTrack(itr)) return 0.;
02203
02204
02205
02206
02207
02208
02209
02210
02211
02212
02213
02214
02215
02216 float nu_cos = -5.799E-2;
02217 float nu_sin = sqrt(1 -nu_cos*nu_cos);
02218 float cosz = ntpTrack->vtx.dcosz*nu_sin + ntpTrack->vtx.dcosy*nu_cos;
02219
02220 return cosz;
02221
02222 }
02223
02224
02225
02226
02227
02228
02229
02230
02231 Float_t MadMKAnalysis::ClosestPointToLine(const Float_t& x1,
02232 const Float_t& y1,
02233 const Float_t& x2,
02234 const Float_t& y2,
02235 const Float_t& xpt,
02236 const Float_t& ypt,
02237 Float_t& x, Float_t& y){
02238
02239
02240
02241
02242 Float_t u= (xpt-x1)*(x2-x1)+(ypt-y1)*(y2-y1);
02243 u/=sqrt( pow(x2-x1,2) + pow(y2-y1,2));
02244 x=x1+u*(x2-x1);
02245 y=y1+u*(y2-y1);
02246 Float_t dist =sqrt(pow(xpt-x, 2)+pow(ypt-y,2));
02247 return dist;
02248 }
02249
02250
02251
02252
02253
02254
02255
02256
02257
02258
02259
02260
02261
02262
02263
02264
02265
02266 Int_t MadMKAnalysis::NDRadialFidVol(Float_t x,Float_t y, Float_t z){
02267
02268 Float_t rings[5]={0.1,0.25,0.5,1.0,1.5};
02269 Int_t result=0;
02270 for (unsigned int i=0; i<5; i++){
02271 Float_t radius = pow(x-kXcenter,2)
02272 + pow(y-(kYcenter - z*TMath::Tan(0.058)),2);
02273 radius=sqrt(radius);
02274
02275 if(z>=kVetoEndZ &&
02276 z<=kTargEndZ &&
02277 radius<=rings[i]) result|=(1<<i);
02278 }
02279 return result;
02280 }
02281
02282 Bool_t MadMKAnalysis::PittInFidVol(Float_t x, Float_t y, Float_t z, Float_t u, Float_t v){
02283
02284
02285
02286
02287
02288 if( !( z>0.6 && z<3.56) ) return kFALSE;
02289 if( !( u>0.3 && u<1.8) ) return kFALSE;
02290 if( !( v>-1.8 && v< -0.3) ) return kFALSE;
02291 if( x>=2.4) return kFALSE;
02292 const Float_t coil_cut=0.8*0.8;
02293 if( (x*x + y*y) <= coil_cut) return kFALSE;
02294 return kTRUE;
02295
02296 }
02297
02298 Int_t MadMKAnalysis::PittTrkContained(Float_t x, Float_t y, Float_t z,
02299 Float_t u, Float_t v){
02300
02301
02302
02303
02304
02305
02306
02307
02308
02309
02310
02311
02312
02313 const Float_t radsq = x*x + y*y;
02314 int result=0;
02315 if(z<7.0) {
02316
02317 static const Float_t coil_cut=0.8*0.8;
02318
02319 if( (u>0.3 && u<1.8) && (v>-1.8 && v<-0.3) && (x<2.4) && (radsq>coil_cut) )
02320 result=1;
02321 else result=2;
02322 }
02323 else{
02324
02325
02326
02327
02328
02329
02330
02331
02332
02333
02334 static const Float_t coil_cut=0.8*0.8;
02335 static const Float_t x0=0.8;
02336 static const Float_t y0=0.0;
02337 static const Float_t a=1.7;
02338 static const Float_t b=1.4;
02339 const Float_t xsc = (x-x0)/a;
02340 const Float_t ysc = (y-y0)/b;
02341
02342 if( (sqrt(xsc*xsc + ysc*ysc)<1.0) && (radsq>coil_cut) && (z<15.6))
02343 result = 3;
02344 else result = 4;
02345 }
02346 return result;
02347
02348 }
02349
02350 Int_t MadMKAnalysis::InPartialRegion(UShort_t plane, UShort_t strip){
02351
02352
02353
02354
02355
02356
02357
02358
02359
02360
02361
02362
02363
02364
02365
02366
02367
02368 static bool first=true;
02369 static UShort_t ptype[282];
02370 if(first){
02371 ptype[0]=0;
02372 for(int i=1; i<=281; i++){
02373 if(i%2==0) ptype[i]=1;
02374 else ptype[i]=2;
02375 if((i-1)%5 == 0) ptype[i]+=2;
02376 else if(i>120) ptype[i]=0;
02377 }
02378 first=false;
02379 }
02380 if(plane>281){
02381
02382 return 0;
02383 }
02384 UShort_t pt = ptype[plane];
02385
02386 Int_t result;
02387 switch(pt){
02388 case 1:
02389 case 3:
02390 if(strip<=4 || strip>=67) result=1;
02391 else result = -1;
02392 break;
02393 case 2:
02394 if(strip==0 || strip == 63) result=1;
02395 else result = -1;
02396 break;
02397 case 4:
02398 if(strip<=26 || strip>=88) result=1;
02399 else result = -1;
02400 break;
02401 case 0:
02402 default:
02403 result=0;
02404 break;
02405 }
02406 return result;
02407
02408 }
02409
02410 void MadMKAnalysis::SigInOut(Float_t& sigfull, Float_t& sigpart,
02411 Float_t& trkfull, Float_t& trkpart){
02412
02413
02414
02415
02416
02417
02418
02419
02420 sigfull=sigpart=0;
02421
02422
02423
02424 for(int i=0; i<ntpEvent->nstrip; i++){
02425 if(!LoadStrip(ntpEvent->stp[i])) continue;
02426 Int_t pr = InPartialRegion(ntpStrip->plane, ntpStrip->strip);
02427 if(pr==1){
02428 sigpart+=ntpStrip->ph0.sigcor + ntpStrip->ph1.sigcor;
02429 }
02430 else if(pr==-1){
02431 sigfull+=ntpStrip->ph0.sigcor + ntpStrip->ph1.sigcor;
02432 }
02433 }
02434
02435
02436
02437 trkfull=trkpart=0;
02438
02439 if(ntpTrack){
02440 for(int i=0; i<ntpTrack->nstrip; i++){
02441 if(!LoadStrip(ntpTrack->stp[i])) continue;
02442 Int_t pr = InPartialRegion(ntpStrip->plane, ntpStrip->strip);
02443 if(pr==1){
02444 trkpart+=ntpStrip->ph0.sigcor + ntpStrip->ph1.sigcor;
02445 }
02446 else if(pr==-1){
02447 trkfull+=ntpStrip->ph0.sigcor + ntpStrip->ph1.sigcor;
02448 }
02449 }
02450 }
02451
02452 }
02453
02454 void MadMKAnalysis::SigInOut(Int_t trkidx, Float_t& sigfull, Float_t& sigpart,
02455 Float_t& trkfull, Float_t& trkpart){
02456
02457 if(trkidx==-1) ntpTrack=0;
02458 else if (!(LoadTrack(trkidx))) ntpTrack=0;
02459 SigInOut(sigfull,sigpart,trkfull,trkpart);
02460 }
02461
02462 void MadMKAnalysis::SetBECFile(const char* f){
02463 if(f){
02464 fBECConfig.Set("beam:flux_file",f);
02465 }
02466 }
02467
02468 Int_t MadMKAnalysis::NPlanesInObj(TObject *rec, TObject *obj, float phcut, float& sumph)
02469 {
02470 sumph=0.0;
02471
02472 std::set<UShort_t> planes;
02473
02474 NtpSRRecord *srrec = dynamic_cast<NtpSRRecord *>(rec);
02475 NtpStRecord *strec = dynamic_cast<NtpStRecord *>(rec);
02476
02477 Int_t *stripindex=0;
02478 Int_t nstrip=0;
02479 NtpSRSlice *slc = dynamic_cast<NtpSRSlice *>(obj);
02480 NtpSRTrack *trk = dynamic_cast<NtpSRTrack *>(obj);
02481 NtpSREvent *evt = dynamic_cast<NtpSREvent *>(obj);
02482 NtpSRShower *shw = dynamic_cast<NtpSRShower *>(obj);
02483
02484 if(slc!=0){
02485 stripindex=slc->stp;
02486 nstrip=slc->nstrip;
02487
02488 }
02489 else if(trk!=0){
02490 stripindex=trk->stp;
02491 nstrip=trk->nstrip;
02492
02493 }
02494 else if(evt!=0){
02495 stripindex=evt->stp;
02496 nstrip=evt->nstrip;
02497
02498 }
02499 else if(shw!=0){
02500 stripindex=shw->stp;
02501 nstrip=shw->nstrip;
02502
02503 }
02504
02505 TClonesArray *striplist=0;
02506 int TOTSTRIPS=0;
02507 if(srrec!=0){
02508 striplist = srrec->stp;
02509 TOTSTRIPS=srrec->evthdr.nstrip;
02510
02511 }
02512 else{
02513 striplist = strec->stp;
02514 TOTSTRIPS=strec->evthdr.nstrip;
02515
02516 }
02517
02518 if(striplist!=0){
02519
02520 for(int i=0;i<nstrip;i++){
02521 int sindex = stripindex[i];
02522 if(sindex<0) continue;
02523 if(sindex<TOTSTRIPS){
02524 NtpSRStrip *strip = dynamic_cast<NtpSRStrip *>
02525 ((*striplist)[sindex]);
02526 if(!strip) continue;
02527
02528
02529
02530 if(strip->ph0.pe+strip->ph1.pe>phcut){
02531 planes.insert(strip->plane);
02532 sumph+=strip->ph0.sigcor+strip->ph1.sigcor;
02533 }
02534 }
02535 }
02536 }
02537 else{
02538
02539 for(int i=0;i<TOTSTRIPS;i++){
02540 NtpSRStrip *strip = dynamic_cast<NtpSRStrip *>((*striplist)[i]);
02541 if(!strip) continue;
02542
02543
02544
02545 if(strip->ph0.pe+strip->ph1.pe>phcut){
02546 planes.insert(strip->plane);
02547 sumph+=strip->ph0.sigcor+strip->ph1.sigcor;
02548 }
02549 }
02550 }
02551
02552
02553 return planes.size();
02554 }
02555
02556
02557 Int_t MadMKAnalysis::NStripsInObj(TObject *rec, TObject *obj, float phcut, float& sumph)
02558 {
02559 sumph=0.0;
02560 std::vector<UShort_t> strips;
02561
02562 NtpSRRecord *srrec = dynamic_cast<NtpSRRecord *>(rec);
02563 NtpStRecord *strec = dynamic_cast<NtpStRecord *>(rec);
02564
02565 Int_t *stripindex=0;
02566 Int_t nstrip=0;
02567 NtpSRSlice *slc = dynamic_cast<NtpSRSlice *>(obj);
02568 NtpSRTrack *trk = dynamic_cast<NtpSRTrack *>(obj);
02569 NtpSREvent *evt = dynamic_cast<NtpSREvent *>(obj);
02570 NtpSRShower *shw = dynamic_cast<NtpSRShower *>(obj);
02571
02572 if(slc!=0){
02573 stripindex=slc->stp;
02574 nstrip=slc->nstrip;
02575 }
02576 else if(trk!=0){
02577 stripindex=trk->stp;
02578 nstrip=trk->nstrip;
02579 }
02580 else if(evt!=0){
02581 stripindex=evt->stp;
02582 nstrip=evt->nstrip;
02583 }
02584 else if(shw!=0){
02585 stripindex=shw->stp;
02586 nstrip=shw->nstrip;
02587 }
02588
02589 TClonesArray *striplist=0;
02590 int TOTSTRIPS;
02591 if(srrec!=0){
02592 striplist = srrec->stp;
02593 TOTSTRIPS=srrec->evthdr.nstrip;
02594 }
02595 else{
02596 striplist = strec->stp;
02597 TOTSTRIPS=strec->evthdr.nstrip;
02598 }
02599
02600
02601 if(striplist!=0){
02602 for(int i=0;i<nstrip;i++){
02603 int sindex=stripindex[i];
02604 if(sindex<0) continue;
02605 NtpSRStrip *strip = dynamic_cast<NtpSRStrip *>((*striplist)[sindex]);
02606 if(!strip) continue;
02607 if(strip->ph0.pe+strip->ph1.pe>phcut){
02608 strips.push_back(strip->plane);
02609 sumph+=strip->ph0.sigcor+strip->ph1.sigcor;
02610 }
02611 }
02612 }
02613 else{
02614 if(srrec!=0){
02615 nstrip=srrec->evthdr.nstrip;
02616 }
02617 else{
02618 nstrip=strec->evthdr.nstrip;
02619 }
02620 for(int i=0;i<nstrip;i++){
02621
02622 NtpSRStrip *strip = dynamic_cast<NtpSRStrip *>((*striplist)[i]);
02623
02624 if(!strip) continue;
02625 if(strip->ph0.pe+strip->ph1.pe>phcut){
02626 strips.push_back(strip->plane);
02627 sumph+=strip->ph0.sigcor+strip->ph1.sigcor;
02628 }
02629 }
02630 }
02631
02632
02633 return strips.size();
02634 }
02635
02636 void MadMKAnalysis::GetEvtTimeChar(double &evttimemin, double &evttimemax, double &evttimeln)
02637 {
02638
02639 double trgtime=eventSummary->trigtime;
02640 double timemax=0.;
02641 double timemin=1.e10;
02642
02643
02644 if(ntpHeader->GetVldContext().GetDetector()==Detector::kNear){
02645 for(Int_t evss=0;evss<ntpEvent->nstrip;evss++){
02646 Int_t stp_index=((ntpEvent->stp)[evss]);
02647 if(!LoadStrip(stp_index)) continue;
02648 Double_t striptime=ntpStrip->time1-trgtime;
02649 if(striptime<=timemin) timemin=striptime;
02650 if(striptime>=timemax) timemax=striptime;
02651 }
02652 }
02653
02654 if(ntpHeader->GetVldContext().GetDetector()==Detector::kFar){
02655 for(Int_t evss=0;evss<ntpEvent->nstrip;evss++){
02656 Int_t stp_index=((ntpEvent->stp)[evss]);
02657 if(!LoadStrip(stp_index)) continue;
02658 Double_t striptime1=ntpStrip->time1-trgtime;
02659 Double_t striptime0=ntpStrip->time0-trgtime;
02660 Double_t striptime = 0;
02661 if(striptime1>0 && striptime0<0) striptime=striptime1;
02662 if(striptime0>0 && striptime1<0) striptime=striptime0;
02663 if(striptime0>0 && striptime1>0) striptime=(striptime0+striptime1)/2.;
02664 if(striptime<=timemin) timemin=striptime;
02665 if(striptime>=timemax) timemax=striptime;
02666 }
02667 }
02668
02669 evttimemax=timemax;
02670 evttimemin=timemin;
02671 evttimeln=timemax-timemin;
02672
02673 }
02674
02675 void MadMKAnalysis::GetEvtTimeCharPHC(double &evttimemin, double &evttimemax, double &evttimeln)
02676 {
02677
02678
02679
02680 double trgtime=eventSummary->trigtime;
02681 double timemax=0.;
02682 double timemin=1.e10;
02683
02684
02685 if(ntpHeader->GetVldContext().GetDetector()==Detector::kNear){
02686 for(Int_t evss=0;evss<ntpEvent->nstrip;evss++){
02687 Int_t stp_index=((ntpEvent->stp)[evss]);
02688 if(!LoadStrip(stp_index)) continue;
02689 Double_t striptime=ntpStrip->time1-trgtime;
02690 if(ntpStrip->ph1.sigcor>200){
02691 if(striptime<=timemin) timemin=striptime;
02692 if(striptime>=timemax) timemax=striptime;
02693 }
02694 }
02695 }
02696
02697 if(ntpHeader->GetVldContext().GetDetector()==Detector::kFar){
02698 for(Int_t evss=0;evss<ntpEvent->nstrip;evss++){
02699 Int_t stp_index=((ntpEvent->stp)[evss]);
02700 if(!LoadStrip(stp_index)) continue;
02701 Double_t striptime1=ntpStrip->time1-trgtime;
02702 Double_t striptime0=ntpStrip->time0-trgtime;
02703 Double_t striptime = 0;
02704 if(striptime1>0 && striptime0<0) striptime=striptime1;
02705 if(striptime0>0 && striptime1<0) striptime=striptime0;
02706 if(striptime0>0 && striptime1>0) striptime=(striptime0+striptime1)/2.;
02707 if(ntpStrip->ph0.sigcor+ntpStrip->ph1.sigcor>160){
02708 if(striptime<=timemin) timemin=striptime;
02709 if(striptime>=timemax) timemax=striptime;
02710 }
02711 }
02712 }
02713
02714 evttimemax=timemax;
02715 evttimemin=timemin;
02716 evttimeln=timemax-timemin;
02717
02718 }
02719
02720
02721
02722 float MadMKAnalysis::MuonShowerEnergy(const NtpSREvent* evt,const NtpSRTrack* trk){
02723
02724
02725 static TH2* hr = new TH2F("h_mushw_rph",
02726 "; track - shw r dist (m); shower energy (GeV)",
02727 10,0,0.2,40,0,2);
02728
02729 static TH2* hz = new TH2F("h_mushw_zph",
02730 "; track - shw z dist (m); shower energy (GeV)",
02731 20,-0.2,0.2,40,0,2);
02732
02733 static TH2* ht = new TH2F("h_mushw_tph",
02734 "; track - shw t dist (m); shower energy (GeV)",
02735 600,-1e-6,10e-6,40,0,2);
02736
02737
02738 if(evt==0 || trk==0) return 0;
02739 float result=0;
02740 NtpSRShower* save_shwr = ntpShower;
02741
02742 const float max_vtx_dist=14*0.06;
02743 for(int i=0; i<evt->nshower; i++){
02744 LoadShower(evt->shw[i]);
02745 if(!ntpShower) continue;
02746
02747
02748 float dist_vtx = pow(ntpShower->vtx.z - ntpEvent->vtx.z,2)
02749 + pow(ntpShower->vtx.u - ntpEvent->vtx.u,2)
02750 + pow(ntpShower->vtx.v - ntpEvent->vtx.v,2);
02751 dist_vtx=sqrt(dist_vtx);
02752 if(dist_vtx<max_vtx_dist) continue;
02753
02754
02755
02756
02757 float min_dist=1e6; float min_r=1e6; float min_z=1e6; float min_t=1e6;
02758 float min_ph=0; float add_ph=0;
02759 for(int j=0; j<trk->nstrip; j++){
02760 float dist_trk= pow(trk->stpz[j]-ntpShower->vtx.z,2)
02761 + pow(trk->stpu[j]-ntpShower->vtx.u,2)
02762 + pow(trk->stpv[j]-ntpShower->vtx.v,2);
02763 dist_trk=sqrt(dist_trk);
02764 float tdist = (trk->vtx.t + (trk->stpz[j]-trk->vtx.z)/3e8)
02765 - ntpShower->vtx.t;
02766
02767
02768
02769
02770
02771
02772 if(fabs(dist_trk)<fabs(min_dist)) {
02773 min_ph=ntpShower->shwph.EMgev;
02774 min_z = fabs(ntpShower->vtx.z-trk->stpz[j]);
02775 min_r = sqrt( pow(ntpShower->vtx.u-trk->stpu[j],2)
02776 + pow(ntpShower->vtx.v-trk->stpv[j],2));
02777 min_t = tdist;
02778 }
02779
02780 const float max_trk_dist=1.76*3.0;
02781 const float max_trk_tdist=40e-9;
02782 if(fabs(dist_trk)<max_trk_dist && fabs(tdist)<max_trk_tdist){
02783
02784 add_ph=min_ph;
02785 }
02786 }
02787 result+=min_ph;
02788
02789
02790 hr->Fill(min_r,min_ph);
02791 hz->Fill(min_z,min_ph);
02792 ht->Fill(min_t,min_ph);
02793
02794 }
02795
02796
02797 ntpShower=save_shwr;
02798
02799 return result;
02800 }
02801
02802 void MadMKAnalysis::EarlyActivity(int evidx, float &earlywph,
02803 float &earlywphpw,
02804 float &earlywphsphere,
02805 float &ph1000,
02806 float &ph500,
02807 float &ph100,
02808 float &lateph1000,
02809 float &lateph500,
02810 float &lateph100,
02811 float &lateph50)
02812 {
02813
02814 earlywph=0.;
02815 earlywphpw=0.;
02816 earlywphsphere=0.;
02817 ph1000=0.;
02818 ph500=0.;
02819 ph100=0.;
02820 lateph1000=0.;
02821 lateph500=0.;
02822 lateph100=0.;
02823 lateph50=0.;
02824
02825 if(!LoadEvent(evidx)) return;
02826
02827
02828 double earliestEventTime = 1.e20;
02829 double latestEventTime = 0.;
02830 map<int,int> eventPlanes;
02831 double trigtime = eventSummary->trigtime;
02832
02833
02834
02835
02836 for(int s=0;s<ntpEvent->nstrip;s++){
02837 int stripindex = ntpEvent->stp[s];
02838 if(!LoadStrip(stripindex)) continue;
02839
02840
02841 float phwt = ((ntpStrip->ph1.sigcor*ntpStrip->time1+
02842 ntpStrip->ph0.sigcor*ntpStrip->time0)/
02843 (ntpStrip->ph1.sigcor+ntpStrip->ph0.sigcor));
02844
02845 double time = 1.e9*(phwt-trigtime);
02846 if(time<earliestEventTime){
02847 earliestEventTime = time;
02848 }
02849 if(time>latestEventTime){
02850 latestEventTime=time;
02851 }
02852 if(ntpStrip->ph1.sigcor>0){
02853 if(eventPlanes.find(ntpStrip->pmtindex1)==eventPlanes.end()){
02854 eventPlanes[ntpStrip->pmtindex1] = 1;
02855 }
02856 }
02857 if(ntpStrip->ph0.sigcor>0){
02858 if(eventPlanes.find(ntpStrip->pmtindex0)==eventPlanes.end()){
02859 eventPlanes[ntpStrip->pmtindex1] = 1;
02860 }
02861 }
02862 }
02863
02864
02865
02866 for(unsigned int s=0;s<eventSummary->nstrip;s++){
02867 if(!LoadStrip(s)) continue;
02868
02869 float phwt = ((ntpStrip->ph1.sigcor*ntpStrip->time1+
02870 ntpStrip->ph0.sigcor*ntpStrip->time0)/
02871 (ntpStrip->ph1.sigcor+ntpStrip->ph0.sigcor));
02872 double newtime = 1.e9*(phwt-trigtime);
02873 double dt=(earliestEventTime-newtime);
02874 double dtlate=newtime-latestEventTime;
02875 float d=1000.;
02876 if((int)ntpStrip->planeview==PlaneView::kU){
02877 d=sqrt((pow(ntpEvent->vtx.u-ntpStrip->tpos,2)+
02878 pow(ntpEvent->vtx.z-ntpStrip->z,2)));
02879 }
02880 else{
02881 d=sqrt((pow(ntpEvent->vtx.v-ntpStrip->tpos,2)+
02882 pow(ntpEvent->vtx.z-ntpStrip->z,2)));
02883 }
02884 if(d<fEarlyPlaneSphere&&dtlate>0.){
02885 if(dtlate<1000.){
02886 lateph1000+=ntpStrip->ph1.sigcor+ntpStrip->ph0.sigcor;
02887 }
02888 if(dtlate<500.){
02889 lateph500+=ntpStrip->ph1.sigcor+ntpStrip->ph0.sigcor;
02890 }
02891 if(dtlate<100.){
02892 lateph100+=ntpStrip->ph1.sigcor+ntpStrip->ph0.sigcor;
02893 }
02894 if(dtlate<50.){
02895 lateph50+=ntpStrip->ph1.sigcor+ntpStrip->ph0.sigcor;
02896 }
02897 }
02898 if(d<fEarlyPlaneSphere&&dt>0.){
02899 if(dt<1000.){
02900 ph1000+=ntpStrip->ph1.sigcor+ntpStrip->ph0.sigcor;
02901 }
02902 if(dt<500.){
02903 ph500+=ntpStrip->ph1.sigcor+ntpStrip->ph0.sigcor;
02904 }
02905 if(dt<100.){
02906 ph100+=ntpStrip->ph1.sigcor+ntpStrip->ph0.sigcor;
02907 }
02908 }
02909 if(dt>0.&&dt<1000.*fEarlyActivityWindowSize){
02910 double eadc = ((ntpStrip->ph1.sigcor+ntpStrip->ph1.sigcor)*
02911 TMath::Exp(-1.*dt/fPMTTimeConstant));
02912
02913
02914 if(eventPlanes.find(ntpStrip->pmtindex1)!=eventPlanes.end()){
02915 earlywph += eadc;
02916 }
02917
02918
02919 if(d<fEarlyPlaneSphere){
02920 earlywphsphere+=eadc;
02921 }
02922
02923
02924 if(ntpStrip->plane>=ntpEvent->vtx.plane&&
02925 ntpStrip->plane<=ntpEvent->vtx.plane+fNPlaneEarlyAct){
02926 earlywphpw+=eadc;
02927 }
02928 }
02929 }
02930 }
02931
02932
02933 void MadMKAnalysis::FillMCHists(TFile* fout){
02934
02935 static bool first=true;
02936
02937 static TH1* h_numu_pf_tot = new TH1F("h_numu_pf_tot","CC; true neutrino energy (GeV)",
02938 240,0.0,120.0);
02939
02940 static TH1* h_numu_pf_qe = new TH1F("h_numu_pf_qe","QE; true neutrino energy (GeV)",
02941 240,0.0,120.0);
02942
02943 static TH1* h_numu_pf_res = new TH1F("h_numu_pf_res","RES; true neutrino energy (GeV)",
02944 240,0.0,120.0);
02945
02946 static TH1* h_numu_pf_dis = new TH1F("h_numu_pf_dis","DIS; true neutrino energy (GeV)",
02947 240,0.0,120.0);
02948 static TH1* h_numu_pf_nc = new TH1F("h_numu_pf_nc","NC; true neutrino energy (GeV)",
02949 240,0.0,120.0);
02950 if(first){
02951 h_numu_pf_tot->SetDirectory(fout);
02952 h_numu_pf_qe->SetDirectory(fout);
02953 h_numu_pf_res->SetDirectory(fout);
02954 h_numu_pf_dis->SetDirectory(fout);
02955 h_numu_pf_nc->SetDirectory(fout);
02956 }
02957
02958 static TH1* h_numubar_pf_tot = new TH1F("h_numubar_pf_tot","CC; true neutrino energy (GeV)",
02959 240,0.0,120.0);
02960
02961 static TH1* h_numubar_pf_qe = new TH1F("h_numubar_pf_qe","QE; true neutrino energy (GeV)",
02962 240,0.0,120.0);
02963
02964 static TH1* h_numubar_pf_res = new TH1F("h_numubar_pf_res","RES; true neutrino energy (GeV)",
02965 240,0.0,120.0);
02966
02967 static TH1* h_numubar_pf_dis = new TH1F("h_numubar_pf_dis","DIS; true neutrino energy (GeV)",
02968 240,0.0,120.0);
02969 static TH1* h_numubar_pf_nc = new TH1F("h_numubar_pf_nc","NC; true neutrino energy (GeV)",
02970 240,0.0,120.0);
02971 if(first){
02972 h_numubar_pf_tot->SetDirectory(fout);
02973 h_numubar_pf_qe->SetDirectory(fout);
02974 h_numubar_pf_res->SetDirectory(fout);
02975 h_numubar_pf_dis->SetDirectory(fout);
02976 h_numubar_pf_nc->SetDirectory(fout);
02977 }
02978
02979
02980
02981 static TH1* h_numu_1m_tot = new TH1F("h_numu_1m_tot","CC; true neutrino energy (GeV)",
02982 240,0.0,120.0);
02983
02984 static TH1* h_numu_1m_qe = new TH1F("h_numu_1m_qe","QE; true neutrino energy (GeV)",
02985 240,0.0,120.0);
02986
02987 static TH1* h_numu_1m_res = new TH1F("h_numu_1m_res","RES; true neutrino energy (GeV)",
02988 240,0.0,120.0);
02989
02990 static TH1* h_numu_1m_dis = new TH1F("h_numu_1m_dis","DIS; true neutrino energy (GeV)",
02991 240,0.0,120.0);
02992 static TH1* h_numu_1m_nc = new TH1F("h_numu_1m_nc","NC; true neutrino energy (GeV)",
02993 240,0.0,120.0);
02994 if(first){
02995 h_numu_1m_tot->SetDirectory(fout);
02996 h_numu_1m_qe->SetDirectory(fout);
02997 h_numu_1m_res->SetDirectory(fout);
02998 h_numu_1m_dis->SetDirectory(fout);
02999 h_numu_1m_nc->SetDirectory(fout);
03000 }
03001
03002 static TH1* h_numubar_1m_tot = new TH1F("h_numubar_1m_tot","CC; true neutrino energy (GeV)",
03003 240,0.0,120.0);
03004
03005 static TH1* h_numubar_1m_qe = new TH1F("h_numubar_1m_qe","QE; true neutrino energy (GeV)",
03006 240,0.0,120.0);
03007
03008 static TH1* h_numubar_1m_res = new TH1F("h_numubar_1m_res","RES; true neutrino energy (GeV)",
03009 240,0.0,120.0);
03010
03011 static TH1* h_numubar_1m_dis = new TH1F("h_numubar_1m_dis","DIS; true neutrino energy (GeV)",
03012 240,0.0,120.0);
03013 static TH1* h_numubar_1m_nc = new TH1F("h_numubar_1m_nc","NC; true neutrino energy (GeV)",
03014 240,0.0,120.0);
03015 if(first){
03016 h_numubar_1m_tot->SetDirectory(fout);
03017 h_numubar_1m_qe->SetDirectory(fout);
03018 h_numubar_1m_res->SetDirectory(fout);
03019 h_numubar_1m_dis->SetDirectory(fout);
03020 h_numubar_1m_nc->SetDirectory(fout);
03021 }
03022
03023
03024 static TH1* h_other_pf = new TH1F("h_other_pf",
03025 "other; true neutrino energy (GeV)",
03026 240,0.0,120.0);
03027
03028 static TH1* h_other_1m = new TH1F("h_other_1m",
03029 "other; true neutrino energy (GeV)",
03030 240,0.0,120.0);
03031 if(first){
03032 h_other_pf->SetDirectory(fout);
03033 h_other_1m->SetDirectory(fout);
03034 }
03035 if(!mcHeader) {
03036 first=true;
03037 return;
03038 }
03039 for(Int_t i=0; i<mcHeader->nmc; i++){
03040 if(!LoadTruth(i)) continue;
03041 const Float_t k = 1.0/sqrt(2.0);
03042 Float_t x = ntpTruth->vtxx;
03043 Float_t y = ntpTruth->vtxy;
03044 Float_t z = ntpTruth->vtxz;
03045 Float_t u = k*(y+x);
03046 Float_t v = k*(y-x);
03047 Bool_t inpf = PittInFidVol(x,y,z,u,v);
03048 Int_t ndr = NDRadialFidVol(x,y,z);
03049 Bool_t inr =kFALSE;
03050 if((ndr&0x8)>0) inr=kTRUE;
03051 Int_t ccnc = ntpTruth->iaction;
03052 Int_t process = ntpTruth->iresonance;
03053 Int_t inu = ntpTruth->inu;
03054 Float_t E = ntpTruth->p4neu[3];
03055
03056
03057 if(inu==14){
03058 if(ccnc==0){
03059 if(inpf) h_numu_pf_nc->Fill(E);
03060 if(inr) h_numu_1m_nc->Fill(E);
03061 }
03062 else if(ccnc==1){
03063 if(inpf) h_numu_pf_tot->Fill(E);
03064 if(inr) h_numu_1m_tot->Fill(E);
03065 switch(process){
03066 case 1001:
03067 if(inpf) h_numu_pf_qe->Fill(E);
03068 if(inr) h_numu_1m_qe->Fill(E);
03069 break;
03070 case 1002:
03071 if(inpf) h_numu_pf_res->Fill(E);
03072 if(inr) h_numu_1m_res->Fill(E);
03073 break;
03074 case 1003:
03075 if(inpf) h_numu_pf_dis->Fill(E);
03076 if(inr) h_numu_1m_dis->Fill(E);
03077 break;
03078 default:
03079 break;
03080 }
03081 }
03082 }
03083 else if(inu==-14){
03084 if(ccnc==0){
03085 if(inpf) h_numubar_pf_nc->Fill(E);
03086 if(inr) h_numubar_1m_nc->Fill(E);
03087 }
03088 else if(ccnc==1){
03089 if(inpf) h_numubar_pf_tot->Fill(E);
03090 if(inr) h_numubar_1m_tot->Fill(E);
03091 switch(process){
03092 case 1001:
03093 if(inpf) h_numubar_pf_qe->Fill(E);
03094 if(inr) h_numubar_1m_qe->Fill(E);
03095 break;
03096 case 1002:
03097 if(inpf) h_numubar_pf_res->Fill(E);
03098 if(inr) h_numubar_1m_res->Fill(E);
03099 break;
03100 case 1003:
03101 if(inpf) h_numubar_pf_dis->Fill(E);
03102 if(inr) h_numubar_1m_dis->Fill(E);
03103 break;
03104 default:
03105 break;
03106 }
03107 }
03108 }
03109 else{
03110 if(inpf) h_other_pf->Fill(E);
03111 if(inr) h_other_1m->Fill(E);
03112 }
03113 }
03114
03115 first=false;
03116 }
03117
03118 int MadMKAnalysis::FarTrkContained(Float_t x, Float_t y, Float_t z)
03119 {
03120 int is_cont=0;
03121
03122
03123
03124
03125 const Float_t r = sqrt(x*x+y*y);
03126
03127 if(r<=3.5&&r>.5&&((z>=0.5&&z<=14.5)||(z>=16.5&&z<=29.4))){
03128 is_cont=2;
03129 }
03130 else{
03131 is_cont=1;
03132 }
03133 return is_cont;
03134 }
03135
03136 float MadMKAnalysis::ComputeLowPHRatio()
03137 {
03138 float lowphsum=0.;
03139 float totphsum=0.;
03140
03141 for(unsigned int i=0;i<GetEventSummary()->nstrip;i++){
03142 if(!LoadStrip(i)) continue;
03143 totphsum+=ntpStrip->ph1.pe+ntpStrip->ph0.pe;
03144 if(ntpStrip->ph1.pe+ntpStrip->ph0.pe<2){
03145 lowphsum+=ntpStrip->ph1.pe+ntpStrip->ph0.pe;
03146 }
03147 }
03148
03149 float result=-1.;
03150 if(totphsum!=0){
03151 result = lowphsum/totphsum;
03152 }
03153
03154 return result;
03155
03156 }
03157
03158 void MadMKAnalysis::DupRecoStrips(int evidx, int &nduprs, float &dupphrs)
03159 {
03160
03161 nduprs=0;
03162 dupphrs=0.;
03163
03164 if(!LoadEvent(evidx)) return;
03165
03166 map<int,float> sindex;
03167 for(int i=0;i<ntpEvent->nstrip;i++){
03168 int si = ntpEvent->stp[i];
03169 if(!LoadStrip(si)) continue;
03170 float ph = ntpStrip->ph0.sigcor+ntpStrip->ph1.sigcor;
03171 sindex[ntpEvent->stp[i]]=ph;
03172 }
03173
03174 for(int i=0;i<eventSummary->nevent;i++){
03175 if(i==evidx){
03176 continue;
03177 }
03178 LoadEvent(i);
03179 for(int j=0;j<ntpEvent->nstrip;j++){
03180 map<int,float>::iterator it(sindex.find(ntpEvent->stp[j]));
03181 if(it!=sindex.end()){
03182 nduprs++;
03183 dupphrs+=it->second;
03184 }
03185 }
03186 }
03187
03188
03189 LoadEvent(evidx);
03190 }