3540 std::cout <<
"Analysing.\n\n";
3549 std::vector<art::Ptr<recob::Hit> > hitlist;
3556 std::vector<art::Ptr<recob::Cluster> > clusterlist;
3559 if (clusterListHandle)
3567 std::cout <<
"Saving SpacepointSolver info.";
3570 if (spacepointListHandle->size() != pointchargeListHandle->size()) {
3572 <<
"size of point and charge containers must be equal" <<
std::endl;
3577 std::vector<art::Ptr<recob::OpFlash> > flashlist;
3579 if (flashListHandle)
3583 std::vector<art::Ptr<raw::ExternalTrigger> > countlist;
3585 if (countListHandle)
3590 std::vector<art::Ptr<simb::MCTruth> > mclist;
3593 if (mctruthListHandle)
3599 std::vector<art::Ptr<simb::MCTruth> > mclistcry;
3602 if (mctruthcryListHandle) {
3608 mf::LogError(
"AnalysisTree") <<
"Requested CRY information but none exists, hence not saving CRY information.";
3614 std::vector<art::Ptr<simb::MCTruth> > mclistproto;
3617 if (mctruthprotoListHandle) {
3623 mf::LogError(
"AnalysisTree") <<
"Requested protoDUNE beam generator information but none exists, hence not saving protoDUNE beam generator information.";
3634 nMCShowers = mcshowerh->size();
3643 nMCTracks = mctrackh->size();
3646 int nCryPrimaries = 0;
3649 mctruthcry = mclistcry[0];
3654 int nProtoPrimaries = 0;
3656 mctruthproto = mclistproto[0];
3657 nProtoPrimaries = mctruthproto->
NParticles();
3660 int nGeniePrimaries = 0, nGEANTparticles = 0;
3668 auto const allmclists = evt.
getMany<std::vector<simb::MCTruth>>();
3669 for(
size_t mcl = 0; mcl < allmclists.size(); ++mcl){
3671 for(
size_t m = 0;
m < mclistHandle->size(); ++
m){
3679 if (!mclist.empty()){
3693 mctruth = mclist[0];
3698 const sim::ParticleList& plist = pi_serv->
ParticleList();
3699 nGEANTparticles = plist.size();
3705 << nGEANTparticles <<
" GEANT particles, " 3706 << nGeniePrimaries <<
" GENIE particles";
3710 int nSpacePoints = 0;
3712 nSpacePoints = spacepointListHandle->size();
3716 fData->ResizeGenie(nGeniePrimaries);
3718 fData->ResizeCry(nCryPrimaries);
3720 fData->ResizeProto(nProtoPrimaries);
3722 fData->ResizeGEANT(nGEANTparticles);
3724 fData->ResizeMCShower(nMCShowers);
3726 fData->ResizeMCTrack(nMCTracks);
3728 fData->ResizeSpacePointSolver(nSpacePoints);
3730 fData->ClearLocalData();
3734 const size_t NHits = hitlist.size();
3736 const size_t NClusters = clusterlist.size();
3737 const size_t NFlashes = flashlist.size();
3738 const size_t NExternCounts = countlist.size();
3749 std::vector<art::Ptr<raw::Trigger>> triggerlist;
3751 if (triggerListHandle)
3754 if (triggerlist.size()){
3755 fData->triggernumber = triggerlist[0]->TriggerNumber();
3756 fData->triggertime = triggerlist[0]->TriggerTime();
3757 fData->beamgatetime = triggerlist[0]->BeamGateTime();
3758 fData->triggerbits = triggerlist[0]->TriggerBits();
3762 std::vector< art::Handle< std::vector<recob::Vertex> > > vertexListHandle(NVertexAlgos);
3763 std::vector< std::vector<art::Ptr<recob::Vertex> > > vertexlist(NVertexAlgos);
3764 for (
unsigned int it = 0; it < NVertexAlgos; ++it){
3766 if (vertexListHandle[it])
3776 std::vector< art::Handle< std::vector<recob::Track> > > trackListHandle(NTrackers);
3777 std::vector< std::vector<art::Ptr<recob::Track> > > tracklist(NTrackers);
3778 for (
unsigned int it = 0; it < NTrackers; ++it){
3780 if (trackListHandle[it])
3789 std::vector<std::vector<recob::Shower>
const*> showerList;
3790 std::vector< art::Handle< std::vector<recob::Shower> > > showerListHandle;
3794 auto ShowerHandle = evt.
getHandle<std::vector<recob::Shower>>(ShowerInputTag);
3795 if (!ShowerHandle) {
3796 showerList.push_back(
nullptr);
3799 <<
"Showers with input tag '" << ShowerInputTag.encode()
3800 <<
"' were not found in the event." 3801 " If you really know what you are doing," 3802 " set AnalysisTree's configuration parameter IgnoreMissingShowers" 3803 " to \"true\"; the lack of any shower set will be tolerated," 3804 " and the shower list in the corresponding event will be set to" 3805 " a list of one shower, with an invalid ID.\n";
3810 <<
"No showers found for input tag '" << ShowerInputTag.encode()
3811 <<
"' ; FILLING WITH FAKE DATA AS FOR USER'S REQUEST";
3815 else showerList.push_back(ShowerHandle.product());
3817 showerListHandle.push_back(ShowerHandle);
3825 std::vector<const sim::AuxDetSimChannel*> fAuxDetSimChannels;
3830 std::vector<const sim::SimChannel*> fSimChannels;
3840 fData->evttime = tts.AsDouble();
3845 fData->beamtime = (double)
beam->get_t_ms();
3846 fData->beamtime/=1000.;
3847 std::map<std::string, std::vector<double>> datamap =
beam->GetDataMap();
3848 if (datamap[
"E:TOR860"].
size()){
3849 fData->potbnb = datamap[
"E:TOR860"][0];
3851 if (datamap[
"E:TORTGT"].
size()){
3852 fData->potnumitgt = datamap[
"E:TORTGT"][0];
3854 if (datamap[
"E:TOR101"].
size()){
3855 fData->potnumi101 = datamap[
"E:TOR101"][0];
3869 fData->no_hits_stored = TMath::Min( (
int) NHits, (
int)
kMaxHits);
3873 mf::LogError(
"AnalysisTree:limits") <<
"event has " << NHits
3874 <<
" hits, only kMaxHits=" <<
kMaxHits <<
" stored in tree";
3876 for (
size_t i = 0; i < NHits && i <
kMaxHits ; ++i){
3877 fData->hit_channel[i] = hitlist[i]->Channel();
3878 fData->hit_tpc[i] = hitlist[i]->WireID().TPC;
3879 fData->hit_plane[i] = hitlist[i]->WireID().Plane;
3880 fData->hit_wire[i] = hitlist[i]->WireID().Wire;
3881 fData->hit_peakT[i] = hitlist[i]->PeakTime();
3882 fData->hit_charge[i] = hitlist[i]->Integral();
3883 fData->hit_ph[i] = hitlist[i]->PeakAmplitude();
3884 fData->hit_startT[i] = hitlist[i]->PeakTimeMinusRMS();
3885 fData->hit_endT[i] = hitlist[i]->PeakTimePlusRMS();
3886 fData->hit_rms[i] = hitlist[i]->RMS();
3887 fData->hit_goodnessOfFit[i] = hitlist[i]->GoodnessOfFit();
3888 fData->hit_multiplicity[i] = hitlist[i]->Multiplicity();
3894 std::vector<const sim::IDE*> ides;
3901 fData->hit_trueX[i] = xyz[0];
3921 int dataSize = fmrd.at(i)[0]->Samples();
3922 short ped = fmrd.at(i)[0]->GetPedestal();
3924 std::vector<short> rawadc(dataSize);
3925 raw::Uncompress(fmrd.at(i)[0]->ADCs(), rawadc, fmrd.at(i)[0]->Compression());
3926 int t0 = hitlist[i]->PeakTime() - 3*(hitlist[i]->RMS());
3928 int t1 = hitlist[i]->PeakTime() + 3*(hitlist[i]->RMS());
3929 if (t1>=dataSize) t1 = dataSize-1;
3930 fData->rawD_ph[i] = -1;
3931 fData->rawD_peakT[i] = -1;
3932 for (
int j = t0; j<=
t1; ++j){
3933 if (rawadc[j]-ped>
fData->rawD_ph[i]){
3934 fData->rawD_ph[i] = rawadc[j]-ped;
3935 fData->rawD_peakT[i] = j;
3938 fData->rawD_charge[i] = 0;
3939 fData->rawD_fwhh[i] = 0;
3940 double mean_t = 0.0;
3941 double mean_t2 = 0.0;
3942 for (
int j = t0; j<=
t1; ++j){
3943 if (rawadc[j]-ped>=0.5*
fData->rawD_ph[i]){
3944 ++
fData->rawD_fwhh[i];
3946 if (rawadc[j]-ped>=0.1*
fData->rawD_ph[i]){
3947 fData->rawD_charge[i] += rawadc[j]-ped;
3948 mean_t += (double)j*(rawadc[j]-ped);
3949 mean_t2 += (double)j*(
double)j*(rawadc[j]-ped);
3952 mean_t/=
fData->rawD_charge[i];
3953 mean_t2/=
fData->rawD_charge[i];
3954 fData->rawD_rms[i] = sqrt(mean_t2-mean_t*mean_t);
3959 fData -> hit_nelec[i] = 0;
3960 fData -> hit_energy[i] = 0;
3962 for(
size_t sc = 0; sc < fSimChannels.size(); ++sc){
3963 if(fSimChannels[sc]->Channel() == hitlist[i]->Channel()) chan = fSimChannels[sc];
3966 for(
auto const& mapitr : chan->
TDCIDEMap()){
3968 for(
auto const& ide : mapitr.second){
3969 fData -> hit_nelec[i] += ide.numElectrons;
3970 fData -> hit_energy[i] += ide.energy;
3978 if (hitListHandle) {
3981 for (
size_t i = 0; i < NHits && i <
kMaxHits ; ++i){
3982 if (fmtk.isValid()){
3983 if (fmtk.at(i).size()!=0){
3984 fData->hit_trkid[i] = fmtk.at(i)[0]->ID();
3985 fData->hit_trkKey[i] = fmtk.at(i)[0].key();
3989 fData->hit_trkid[i] = -1;
3999 if (hitListHandle) {
4003 for (
size_t i = 0; i < NHits && i <
kMaxHits ; ++i){
4004 if (fmcl.isValid() && fmcl.at(i).size()!=0){
4005 fData->hit_clusterid[i] = fmcl.at(i)[0]->ID();
4006 fData->hit_clusterKey[i] = fmcl.at(i)[0].key();
4009 if(fmsp.isValid() && fmsp.at(i).size()!=0){
4010 fData->hit_spacepointid[i] = fmsp.at(i)[0]->ID();
4011 fData->hit_spacepointKey[i] = fmsp.at(i)[0].key();
4026 for (
unsigned int n = 0;
n < particleVector.size(); ++
n) {
4034 mf::LogError(
"AnalysisTree:limits") <<
"event has " << nprim
4035 <<
" nu neutrino vertices, only kMaxVertices=" <<
kMaxVertices <<
" stored in tree";
4038 fData->nnuvtx = nprim;
4041 for (
unsigned int n = 0;
n < particleVector.size(); ++
n) {
4045 if (particlesToVertices.end() != vIter) {
4047 if (!vertexVector.empty()) {
4048 if (vertexVector.size() == 1) {
4050 double xyz[3] = {0.0, 0.0, 0.0} ;
4052 fData->nuvtxx[iv] = xyz[0];
4053 fData->nuvtxy[iv] = xyz[1];
4054 fData->nuvtxz[iv] = xyz[2];
4066 fData->nclusters = (
int) NClusters;
4070 mf::LogError(
"AnalysisTree:limits") <<
"event has " << NClusters
4071 <<
" clusters, only kMaxClusters=" <<
kMaxClusters <<
" stored in tree";
4073 for(
unsigned int ic=0; ic<NClusters;++ic){
4076 fData->clusterId[ic] = cluster.
ID();
4077 fData->clusterView[ic] = cluster.
View();
4097 if (fmcct.isValid()){
4098 fData->cluncosmictags_tagger[ic] = fmcct.at(ic).size();
4099 if (fmcct.at(ic).size()>0){
4100 if(fmcct.at(ic).size()>1)
4101 std::cerr <<
"\n Warning : more than one cosmic tag per cluster in module! assigning the first tag to the cluster" <<
fCosmicClusterTaggerAssocLabel;
4102 fData->clucosmicscore_tagger[ic] = fmcct.at(ic).at(0)->CosmicScore();
4103 fData->clucosmictype_tagger[ic] = fmcct.at(ic).at(0)->CosmicType();
4110 fData->nspacepoints = (
unsigned int) nSpacePoints;
4116 size_t emLikeIdx = cluResults->getIndex(
"em");
4118 const art::FindManyP<recob::Hit> hitsFromClusters(cluResults->dataHandle(),
evt, cluResults->dataTag());
4121 std::vector<size_t> sizeScore(nSpacePoints, 0);
4123 for(
size_t c = 0;
c < cluResults->size(); ++
c) {
4124 const std::vector< art::Ptr<recob::Hit> > & hits = hitsFromClusters.at(
c);
4125 std::array<float, MVA_LENGTH> cnn_out = cluResults->getOutput(
c);
4127 for (
auto& hptr : hits) {
4128 const std::vector< art::Ptr<recob::SpacePoint> > & sp = spFromHits.at(hptr.key());
4129 for(
const auto & spptr : sp) {
4130 if(hits.size() > sizeScore[spptr.key()]) {
4131 sizeScore[spptr.key()] = hits.size();
4132 fData->SpacePointEmScore[spptr.key()] = cnn_out[emLikeIdx];
4140 for (
unsigned int is = 0; is < (
unsigned int)nSpacePoints;
4142 fData->SpacePointX[is] = (*spacepointListHandle)[is].XYZ()[0];
4143 fData->SpacePointY[is] = (*spacepointListHandle)[is].XYZ()[1];
4144 fData->SpacePointZ[is] = (*spacepointListHandle)[is].XYZ()[2];
4146 fData->SpacePointQ[is] = (*pointchargeListHandle)[is].charge();
4148 fData->SpacePointErrX[is] = (*spacepointListHandle)[is].ErrXYZ()[0];
4149 fData->SpacePointErrY[is] = (*spacepointListHandle)[is].ErrXYZ()[1];
4150 fData->SpacePointErrZ[is] = (*spacepointListHandle)[is].ErrXYZ()[2];
4152 fData->SpacePointID[is] = (*spacepointListHandle)[is].ID();
4154 fData->SpacePointID[is] = (*spacepointListHandle)[is].Chisq();
4159 fData->no_flashes = (
int) NFlashes;
4163 mf::LogError(
"AnalysisTree:limits") <<
"event has " << NFlashes
4164 <<
" flashes, only kMaxFlashes=" <<
kMaxFlashes <<
" stored in tree";
4169 for (
size_t i = 0; i < NFlashes && i <
kMaxFlashes ; ++i){
4170 fData->flash_time[i] = flashlist[i]->Time();
4171 fData->flash_pe[i] = flashlist[i]->TotalPE();
4172 fData->flash_ycenter[i] = flashlist[i]->YCenter();
4173 fData->flash_zcenter[i] = flashlist[i]->ZCenter();
4174 fData->flash_ywidth[i] = flashlist[i]->YWidth();
4175 fData->flash_zwidth[i] = flashlist[i]->ZWidth();
4176 fData->flash_timewidth[i] = flashlist[i]->TimeWidth();
4181 fData->no_ExternCounts = (
int) NExternCounts;
4185 mf::LogError(
"AnalysisTree:limits") <<
"event has " << NExternCounts
4186 <<
" External Counters, only kMaxExternCounts=" <<
kMaxExternCounts <<
" stored in tree";
4189 fData->externcounts_time[i] = countlist[i]->GetTrigTime();
4190 fData->externcounts_id[i] = countlist[i]->GetTrigID();
4196 std::map<Short_t, Short_t> trackIDtoPFParticleIDMap, vertexIDtoPFParticleIDMap, showerIDtoPFParticleIDMap;
4200 AnalysisTreeDataStruct::PFParticleDataStruct& PFParticleData =
fData->GetPFParticleData();
4201 size_t NPFParticles = pfparticlelist.size();
4203 PFParticleData.SetMaxPFParticles(
std::max(NPFParticles, (
size_t) 1));
4204 PFParticleData.Clear();
4206 PFParticleData.nPFParticles = (short) NPFParticles;
4212 if (NPFParticles > PFParticleData.GetMaxPFParticles()) {
4213 mf::LogError(
"AnalysisTree:limits") <<
"event has " << NPFParticles
4214 <<
" PFParticles, only " 4215 << PFParticleData.GetMaxPFParticles() <<
" stored in tree";
4220 PFParticleData.pfp_numNeutrinos = neutrinoPFParticles.size();
4223 PFParticleData.pfp_neutrinoIDs[i] = neutrinoPFParticles[i]->Self();
4227 std::cerr <<
"Warning: there were " << neutrinoPFParticles.size() <<
" reconstructed PFParticle neutrinos; only the first " <<
kMaxNPFPNeutrinos <<
" being stored in tree" <<
std::endl;
4244 for (
size_t i = 0; i < NPFParticles && i < PFParticleData.GetMaxPFParticles() ; ++i){
4245 PFParticleData.pfp_selfID[i] = pfparticlelist[i]->Self();
4246 PFParticleData.pfp_isPrimary[i] = (Short_t)pfparticlelist[i]->IsPrimary();
4247 PFParticleData.pfp_numDaughters[i] = pfparticlelist[i]->NumDaughters();
4248 PFParticleData.pfp_parentID[i] = pfparticlelist[i]->Parent();
4249 PFParticleData.pfp_pdgCode[i] = pfparticlelist[i]->PdgCode();
4253 std::vector<size_t> daughterIDs = pfparticlelist[i]->Daughters();
4255 for (
size_t j = 0; j < daughterIDs.size(); ++j)
4256 PFParticleData.pfp_daughterIDs[i][j] = daughterIDs[j];
4259 auto vertexMapIter = pfParticleToVertexMap.find(pfparticlelist[i]);
4260 if (vertexMapIter != pfParticleToVertexMap.end()) {
4263 if (pfParticleVertices.size() > 1)
4264 std::cerr <<
"Warning: there was more than one vertex found for PFParticle with ID " << pfparticlelist[i]->Self() <<
", storing only one" <<
std::endl;
4266 if (pfParticleVertices.size() > 0) {
4267 PFParticleData.pfp_vertexID[i] = pfParticleVertices.at(0)->ID();
4268 vertexIDtoPFParticleIDMap.insert(std::make_pair(pfParticleVertices.at(0)->ID(), pfparticlelist[i]->Self()));
4272 std::cerr <<
"Warning: there was no vertex found for PFParticle with ID " << pfparticlelist[i]->Self() <<
std::endl;
4275 PFParticleData.pfp_isTrack[i] = 1;
4278 auto trackMapIter = pfParticleToTrackMap.find(pfparticlelist[i]);
4279 if (trackMapIter != pfParticleToTrackMap.end()) {
4282 if (pfParticleTracks.size() > 1)
4283 std::cerr <<
"Warning: there was more than one track found for PFParticle with ID " << pfparticlelist[i]->Self() <<
std::endl;
4285 if (pfParticleTracks.size() > 0) {
4286 PFParticleData.pfp_trackID[i] = pfParticleTracks.at(0)->ID();
4287 trackIDtoPFParticleIDMap.insert(std::make_pair(pfParticleTracks.at(0)->ID(), pfparticlelist[i]->Self()));
4291 std::cerr <<
"Warning: there was no track found for track-like PFParticle with ID " << pfparticlelist[i]->Self() <<
std::endl;
4294 PFParticleData.pfp_isTrack[i] = 0;
4297 PFParticleData.pfp_isShower[i] = 1;
4299 auto showerMapIter = pfParticleToShowerMap.find(pfparticlelist[i]);
4300 if (showerMapIter != pfParticleToShowerMap.end()) {
4303 if (pfParticleShowers.size() > 1)
4304 std::cerr <<
"Warning: there was more than one shower found for PFParticle with ID " << pfparticlelist[i]->Self() <<
std::endl;
4306 if (pfParticleShowers.size() > 0) {
4307 PFParticleData.pfp_showerID[i] = pfParticleShowers.at(0)->ID();
4308 showerIDtoPFParticleIDMap.insert(std::make_pair(pfParticleShowers.at(0)->ID(), pfparticlelist[i]->Self()));
4312 std::cerr <<
"Warning: there was no shower found for shower-like PFParticle with ID " << pfparticlelist[i]->Self() <<
std::endl;
4315 PFParticleData.pfp_isShower[i] = 0;
4318 auto clusterMapIter = pfParticleToClusterMap.find(pfparticlelist[i]);
4319 if (clusterMapIter != pfParticleToClusterMap.end()) {
4321 PFParticleData.pfp_numClusters[i] = pfParticleClusters.size();
4323 for (
size_t j = 0; j < pfParticleClusters.size(); ++j)
4324 PFParticleData.pfp_clusterIDs[i][j] = pfParticleClusters[j]->ID();
4334 for (
size_t iShowerAlgo = 0; iShowerAlgo < NShowerAlgos; ++iShowerAlgo) {
4335 AnalysisTreeDataStruct::ShowerDataStruct& ShowerData
4336 =
fData->GetShowerData(iShowerAlgo);
4337 std::vector<recob::Shower>
const* pShowers = showerList[iShowerAlgo];
4345 if(fmvapid.isValid()){
4346 for(
unsigned int iShower=0;iShower<showerHandle->size();++iShower){
4348 ShowerData.shwr_pidmvamu[iShower] = pid->
mvaOutput.at(
"muon");
4349 ShowerData.shwr_pidmvae[iShower] = pid->
mvaOutput.at(
"electron");
4350 ShowerData.shwr_pidmvapich[iShower] = pid->
mvaOutput.at(
"pich");
4351 ShowerData.shwr_pidmvaphoton[iShower] = pid->
mvaOutput.at(
"photon");
4352 ShowerData.shwr_pidmvapr[iShower] = pid->
mvaOutput.at(
"proton");
4357 else ShowerData.MarkMissing(
fTree);
4364 for (
unsigned int iTracker=0; iTracker < NTrackers; ++iTracker){
4365 AnalysisTreeDataStruct::TrackDataStruct& TrackerData =
fData->GetTrackerData(iTracker);
4367 size_t NTracks = tracklist[iTracker].size();
4369 TrackerData.SetMaxTracks(
std::max(NTracks, (
size_t) 1));
4370 TrackerData.Clear();
4372 TrackerData.ntracks = (
int) NTracks;
4377 if (NTracks > TrackerData.GetMaxTracks()) {
4380 mf::LogError(
"AnalysisTree:limits") <<
"event has " << NTracks
4382 << TrackerData.GetMaxTracks() <<
" stored in tree";
4389 for(
size_t iTrk=0; iTrk < NTracks; ++iTrk){
4392 art::FindManyP<anab::T0> fmt0(trackListHandle[iTracker],evt,
fFlashT0FinderLabel[iTracker]);
4393 if (fmt0.isValid()){
4394 if(fmt0.at(iTrk).size()>0){
4395 if(fmt0.at(iTrk).size()>1)
4396 std::cerr <<
"\n Warning : more than one cosmic tag per track in module! assigning the first tag to the track" <<
fFlashT0FinderLabel[iTracker];
4397 TrackerData.trkflashT0[iTrk] = fmt0.at(iTrk).at(0)->Time();
4402 art::FindManyP<anab::T0> fmmct0(trackListHandle[iTracker],evt,
fMCT0FinderLabel[iTracker]);
4403 if (fmmct0.isValid()){
4404 if(fmmct0.at(iTrk).size()>0){
4405 if(fmmct0.at(iTrk).size()>1)
4406 std::cerr <<
"\n Warning : more than one cosmic tag per track in module! assigning the first tag to the cluster" <<
fMCT0FinderLabel[iTracker];
4407 TrackerData.trktrueT0[iTrk] = fmmct0.at(iTrk).at(0)->Time();
4413 if (fmct.isValid()){
4414 TrackerData.trkncosmictags_tagger[iTrk] = fmct.at(iTrk).size();
4415 if (fmct.at(iTrk).size()>0){
4416 if(fmct.at(iTrk).size()>1)
4417 std::cerr <<
"\n Warning : more than one cosmic tag per track in module! assigning the first tag to the track" <<
fCosmicTaggerAssocLabel[iTracker];
4418 TrackerData.trkcosmicscore_tagger[iTrk] = fmct.at(iTrk).at(0)->CosmicScore();
4419 TrackerData.trkcosmictype_tagger[iTrk] = fmct.at(iTrk).at(0)->CosmicType();
4425 if (fmcnt.isValid()){
4426 TrackerData.trkncosmictags_containmenttagger[iTrk] = fmcnt.at(iTrk).size();
4427 if (fmcnt.at(iTrk).size()>0){
4428 if(fmcnt.at(iTrk).size()>1)
4429 std::cerr <<
"\n Warning : more than one containment tag per track in module! assigning the first tag to the track" <<
fContainmentTaggerAssocLabel[iTracker];
4430 TrackerData.trkcosmicscore_containmenttagger[iTrk] = fmcnt.at(iTrk).at(0)->CosmicScore();
4431 TrackerData.trkcosmictype_containmenttagger[iTrk] = fmcnt.at(iTrk).at(0)->CosmicType();
4437 art::FindManyP<anab::CosmicTag> fmbfm(trackListHandle[iTracker],evt,
fFlashMatchAssocLabel[iTracker]);
4438 if (fmbfm.isValid()){
4439 TrackerData.trkncosmictags_flashmatch[iTrk] = fmbfm.at(iTrk).size();
4440 if (fmbfm.at(iTrk).size()>0){
4441 if(fmbfm.at(iTrk).size()>1)
4442 std::cerr <<
"\n Warning : more than one cosmic tag per track in module! assigning the first tag to the track" <<
fFlashMatchAssocLabel[iTracker];
4443 TrackerData.trkcosmicscore_flashmatch[iTrk] = fmbfm.at(iTrk).at(0)->CosmicScore();
4444 TrackerData.trkcosmictype_flashmatch[iTrk] = fmbfm.at(iTrk).at(0)->CosmicType();
4452 TVector3
pos, dir_start, dir_end,
end;
4454 double tlen = 0., mom = 0.;
4459 pos = track.
Vertex<TVector3>();
4462 end = track.
End<TVector3>();
4468 TrackID = track.
ID();
4470 double theta_xz = std::atan2(dir_start.X(), dir_start.Z());
4471 double theta_yz = std::atan2(dir_start.Y(), dir_start.Z());
4472 double dpos =
bdist(pos);
4473 double dend =
bdist(end);
4475 TrackerData.trkId[iTrk] =
TrackID;
4476 TrackerData.trkstartx[iTrk] = pos.X();
4477 TrackerData.trkstarty[iTrk] = pos.Y();
4478 TrackerData.trkstartz[iTrk] = pos.Z();
4479 TrackerData.trkstartd[iTrk] = dpos;
4480 TrackerData.trkendx[iTrk] = end.X();
4481 TrackerData.trkendy[iTrk] = end.Y();
4482 TrackerData.trkendz[iTrk] = end.Z();
4483 TrackerData.trkendd[iTrk] = dend;
4484 TrackerData.trktheta[iTrk] = dir_start.Theta();
4485 TrackerData.trkphi[iTrk] = dir_start.Phi();
4486 TrackerData.trkstartdcosx[iTrk] = dir_start.X();
4487 TrackerData.trkstartdcosy[iTrk] = dir_start.Y();
4488 TrackerData.trkstartdcosz[iTrk] = dir_start.Z();
4489 TrackerData.trkenddcosx[iTrk] = dir_end.X();
4490 TrackerData.trkenddcosy[iTrk] = dir_end.Y();
4491 TrackerData.trkenddcosz[iTrk] = dir_end.Z();
4492 TrackerData.trkthetaxz[iTrk] = theta_xz;
4493 TrackerData.trkthetayz[iTrk] = theta_yz;
4494 TrackerData.trkmom[iTrk] = mom;
4495 TrackerData.trklen[iTrk] = tlen;
4496 TrackerData.trkmomrange[iTrk] = trkm.GetTrackMomentum(tlen,13);
4501 auto mapIter = trackIDtoPFParticleIDMap.find(TrackID);
4502 if (mapIter != trackIDtoPFParticleIDMap.end()) {
4504 TrackerData.trkhasPFParticle[iTrk] = 1;
4505 TrackerData.trkPFParticleID[iTrk] = mapIter->second;
4508 TrackerData.trkhasPFParticle[iTrk] = 0;
4592 if(fmvapid.isValid()) {
4594 TrackerData.trkpidmvamu[iTrk] = pid->
mvaOutput.at(
"muon");
4595 TrackerData.trkpidmvae[iTrk] = pid->
mvaOutput.at(
"electron");
4596 TrackerData.trkpidmvapich[iTrk] = pid->
mvaOutput.at(
"pich");
4597 TrackerData.trkpidmvaphoton[iTrk] = pid->
mvaOutput.at(
"photon");
4598 TrackerData.trkpidmvapr[iTrk] = pid->
mvaOutput.at(
"proton");
4602 if (fmcal.isValid()){
4603 std::vector<const anab::Calorimetry*> calos = fmcal.at(iTrk);
4604 if (calos.size() > TrackerData.GetMaxPlanesPerTrack(iTrk)) {
4609 <<
" has " << calos.size() <<
" planes for calorimetry , only " 4610 << TrackerData.GetMaxPlanesPerTrack(iTrk) <<
" stored in tree";
4612 for (
size_t ical = 0; ical<calos.size(); ++ical){
4613 if (!calos[ical])
continue;
4614 if (!calos[ical]->
PlaneID().isValid)
continue;
4615 int planenum = calos[ical]->PlaneID().Plane;
4616 if (planenum<0||planenum>2)
continue;
4617 TrackerData.trkke[iTrk][planenum] = calos[ical]->KineticEnergy();
4618 TrackerData.trkrange[iTrk][planenum] = calos[ical]->Range();
4620 TrackerData.trkpitchc[iTrk][planenum]= calos[ical] -> TrkPitchC();
4621 const size_t NHits = calos[ical] ->
dEdx().size();
4622 TrackerData.ntrkhits[iTrk][planenum] = (
int) NHits;
4623 if (NHits > TrackerData.GetMaxHitsPerTrack(iTrk, planenum)) {
4627 <<
" has " << NHits <<
" hits on calorimetry plane #" << planenum
4629 << TrackerData.GetMaxHitsPerTrack(iTrk, planenum) <<
" stored in tree";
4632 for(
size_t iTrkHit = 0; iTrkHit < NHits && iTrkHit < TrackerData.GetMaxHitsPerTrack(iTrk, planenum); ++iTrkHit) {
4633 TrackerData.trkdedx[iTrk][planenum][iTrkHit] = (calos[ical] ->
dEdx())[iTrkHit];
4634 TrackerData.trkdqdx[iTrk][planenum][iTrkHit] = (calos[ical] -> dQdx())[iTrkHit];
4635 TrackerData.trkresrg[iTrk][planenum][iTrkHit] = (calos[ical] -> ResidualRange())[iTrkHit];
4636 TrackerData.trktpc[iTrk][planenum][iTrkHit] = (calos[ical] ->
PlaneID()).
TPC;
4637 const auto& TrkPos = (calos[ical] -> XYZ())[iTrkHit];
4638 auto& TrkXYZ = TrackerData.trkxyz[iTrk][planenum][iTrkHit];
4639 TrkXYZ[0] = TrkPos.X();
4640 TrkXYZ[1] = TrkPos.Y();
4641 TrkXYZ[2] = TrkPos.Z();
4645 if(TrackerData.ntrkhits[iTrk][0] > TrackerData.ntrkhits[iTrk][1] && TrackerData.ntrkhits[iTrk][0] > TrackerData.ntrkhits[iTrk][2]) TrackerData.trkpidbestplane[iTrk] = 0;
4646 else if(TrackerData.ntrkhits[iTrk][1] > TrackerData.ntrkhits[iTrk][0] && TrackerData.ntrkhits[iTrk][1] > TrackerData.ntrkhits[iTrk][2]) TrackerData.trkpidbestplane[iTrk] = 1;
4647 else if(TrackerData.ntrkhits[iTrk][2] > TrackerData.ntrkhits[iTrk][0] && TrackerData.ntrkhits[iTrk][2] > TrackerData.ntrkhits[iTrk][1]) TrackerData.trkpidbestplane[iTrk] = 2;
4648 else if(TrackerData.ntrkhits[iTrk][2] == TrackerData.ntrkhits[iTrk][0] && TrackerData.ntrkhits[iTrk][2] > TrackerData.ntrkhits[iTrk][1]) TrackerData.trkpidbestplane[iTrk] = 2;
4649 else if(TrackerData.ntrkhits[iTrk][2] == TrackerData.ntrkhits[iTrk][1] && TrackerData.ntrkhits[iTrk][2] > TrackerData.ntrkhits[iTrk][0]) TrackerData.trkpidbestplane[iTrk] = 2;
4650 else if(TrackerData.ntrkhits[iTrk][1] == TrackerData.ntrkhits[iTrk][0] && TrackerData.ntrkhits[iTrk][1] > TrackerData.ntrkhits[iTrk][2]) TrackerData.trkpidbestplane[iTrk] = 0;
4651 else if(TrackerData.ntrkhits[iTrk][1] == TrackerData.ntrkhits[iTrk][0] && TrackerData.ntrkhits[iTrk][1] == TrackerData.ntrkhits[iTrk][2]) TrackerData.trkpidbestplane[iTrk] = 2;
4659 art::FindManyP<recob::Hit> fmht(trackListHandle[iTracker], evt,
fTrackModuleLabel[iTracker]);
4660 std::vector< art::Ptr<recob::Hit> > allHits = fmht.at(iTrk);
4661 std::vector< art::Ptr<recob::Hit> > hits[
kNplanes];
4663 for(
size_t ah = 0; ah < allHits.size(); ++ah){
4665 allHits[ah]->
WireID().Plane < 3){
4666 hits[allHits[ah]->WireID().Plane].push_back(allHits[ah]);
4669 for (
size_t ipl = 0; ipl < 3; ++ipl){
4671 HitsPurity(clockData, hits[ipl],TrackerData.trkidtruth[iTrk][ipl],TrackerData.trkpurtruth[iTrk][ipl],maxe);
4673 if (TrackerData.trkidtruth[iTrk][ipl]>0){
4675 TrackerData.trkorigin[iTrk][ipl] = mc->
Origin();
4678 const std::vector<const sim::IDE*> vide=bt_serv->
TrackIdToSimIDEs_Ps(TrackerData.trkidtruth[iTrk][ipl]);
4679 for (
auto ide: vide) {
4680 tote += ide->energy;
4682 TrackerData.trkpdgtruth[iTrk][ipl] = particle->
PdgCode();
4683 TrackerData.trkefftruth[iTrk][ipl] = maxe/(tote/
kNplanes);
4689 HitsPurity(clockData, allHits,TrackerData.trkg4id[iTrk],TrackerData.trkpurity[iTrk],maxe);
4690 if (TrackerData.trkg4id[iTrk]>0){
4692 TrackerData.trkorig[iTrk] = mc->
Origin();
4694 if (allHits.size()){
4695 std::vector<art::Ptr<recob::Hit> > all_hits;
4697 float totenergy = 0;
4698 if (evt.
get(allHits[0].id(), hithandle)){
4700 for(
size_t h = 0;
h < all_hits.size(); ++
h){
4703 std::vector<sim::IDE*> ides;
4707 for(
size_t e = 0;
e < eveIDs.size(); ++
e){
4709 if (eveIDs[
e].trackID==TrackerData.trkg4id[iTrk]) totenergy += eveIDs[
e].energy;
4713 if (totenergy) TrackerData.trkcompleteness[iTrk] = maxe/totenergy;
4726 for (
unsigned int iVertexAlg=0; iVertexAlg < NVertexAlgos; ++iVertexAlg){
4727 AnalysisTreeDataStruct::VertexDataStruct& VertexData =
fData->GetVertexData(iVertexAlg);
4729 size_t NVertices = vertexlist[iVertexAlg].size();
4731 VertexData.SetMaxVertices(
std::max(NVertices, (
size_t) 1));
4734 VertexData.nvtx = (short) NVertices;
4739 if (NVertices > VertexData.GetMaxVertices()) {
4742 mf::LogError(
"AnalysisTree:limits") <<
"event has " << NVertices
4744 << VertexData.GetMaxVertices() <<
" stored in tree";
4747 for (
size_t i = 0; i < NVertices && i <
kMaxVertices ; ++i){
4748 VertexData.vtxId[i] = vertexlist[iVertexAlg][i]->ID();
4749 Double_t xyz[3] = {};
4750 vertexlist[iVertexAlg][i] -> XYZ(xyz);
4751 VertexData.vtxx[i] = xyz[0];
4752 VertexData.vtxy[i] = xyz[1];
4753 VertexData.vtxz[i] = xyz[2];
4756 auto mapIter = vertexIDtoPFParticleIDMap.find(vertexlist[iVertexAlg][i]->
ID());
4757 if (mapIter != vertexIDtoPFParticleIDMap.end()) {
4759 VertexData.vtxhasPFParticle[i] = 1;
4760 VertexData.vtxPFParticleID[i] = mapIter->second;
4763 VertexData.vtxhasPFParticle[i] = 0;
4767 art::FindMany<recob::PFParticle> fmPFParticle(vertexListHandle[iVertexAlg], evt,
fPFParticleModuleLabel);
4768 if(fmPFParticle.isValid()) {
4769 std::vector<const recob::PFParticle*> pfparticles = fmPFParticle.at(i);
4770 if(pfparticles.size() > 1)
4771 std::cerr <<
"Warning: more than one associated PFParticle found for a vertex. Only one stored in tree." << std::endl;
4772 if (pfparticles.size() == 0)
4773 VertexData.vtxhasPFParticle[i] = 0;
4775 VertexData.vtxhasPFParticle[i] = 1;
4776 VertexData.vtxPFParticleID[i] = pfparticles.at(0)->Self();
4789 art::FindOne<simb::MCFlux> find_mcflux(mctruthListHandle,
4794 fData->mcevts_truthcry = mclistcry.size();
4795 fData->cry_no_primaries = nCryPrimaries;
4797 for(Int_t iPartc = 0; iPartc < mctruthcry->
NParticles(); ++iPartc){
4799 fData->cry_primaries_pdg[iPartc]=partc.PdgCode();
4800 fData->cry_Eng[iPartc]=partc.E();
4801 fData->cry_Px[iPartc]=partc.Px();
4802 fData->cry_Py[iPartc]=partc.Py();
4803 fData->cry_Pz[iPartc]=partc.Pz();
4804 fData->cry_P[iPartc]=partc.P();
4805 fData->cry_StartPointx[iPartc] = partc.Vx();
4806 fData->cry_StartPointy[iPartc] = partc.Vy();
4807 fData->cry_StartPointz[iPartc] = partc.Vz();
4808 fData->cry_StartPointt[iPartc] = partc.T();
4809 fData->cry_status_code[iPartc]=partc.StatusCode();
4810 fData->cry_mass[iPartc]=partc.Mass();
4811 fData->cry_trackID[iPartc]=partc.TrackId();
4812 fData->cry_ND[iPartc]=partc.NumberDaughters();
4813 fData->cry_mother[iPartc]=partc.Mother();
4819 fData->proto_no_primaries = nProtoPrimaries;
4820 for(Int_t iPartp = 0; iPartp < nProtoPrimaries; ++iPartp){
4823 fData->proto_isGoodParticle[iPartp] = (partp.Process() ==
"primary");
4824 fData->proto_vx[iPartp] = partp.Vx();
4825 fData->proto_vy[iPartp] = partp.Vy();
4826 fData->proto_vz[iPartp] = partp.Vz();
4827 fData->proto_t[iPartp] = partp.T();
4828 fData->proto_px[iPartp] = partp.Px();
4829 fData->proto_py[iPartp] = partp.Py();
4830 fData->proto_pz[iPartp] = partp.Pz();
4831 fData->proto_momentum[iPartp] = partp.P();
4832 fData->proto_energy[iPartp] = partp.E();
4833 fData->proto_pdg[iPartp] = partp.PdgCode();
4839 fData->mcevts_truth = mclist.size();
4840 if (
fData->mcevts_truth > 0){
4843 for(
unsigned int iList = 0; (iList < mclist.size()) && (neutrino_i <
kMaxTruth) ; ++iList){
4844 if (mclist[iList]->NeutrinoSet()){
4845 fData->nuPDG_truth[neutrino_i] = mclist[iList]->GetNeutrino().Nu().PdgCode();
4846 fData->ccnc_truth[neutrino_i] = mclist[iList]->GetNeutrino().CCNC();
4847 fData->mode_truth[neutrino_i] = mclist[iList]->GetNeutrino().Mode();
4848 fData->Q2_truth[neutrino_i] = mclist[iList]->GetNeutrino().QSqr();
4849 fData->W_truth[neutrino_i] = mclist[iList]->GetNeutrino().W();
4850 fData->X_truth[neutrino_i] = mclist[iList]->GetNeutrino().X();
4851 fData->Y_truth[neutrino_i] = mclist[iList]->GetNeutrino().Y();
4852 fData->hitnuc_truth[neutrino_i] = mclist[iList]->GetNeutrino().HitNuc();
4853 fData->enu_truth[neutrino_i] = mclist[iList]->GetNeutrino().Nu().E();
4854 fData->nuvtxx_truth[neutrino_i] = mclist[iList]->GetNeutrino().Nu().Vx();
4855 fData->nuvtxy_truth[neutrino_i] = mclist[iList]->GetNeutrino().Nu().Vy();
4856 fData->nuvtxz_truth[neutrino_i] = mclist[iList]->GetNeutrino().Nu().Vz();
4857 if (mclist[iList]->GetNeutrino().Nu().
P()){
4858 fData->nu_dcosx_truth[neutrino_i] = mclist[iList]->GetNeutrino().Nu().Px()/mclist[iList]->GetNeutrino().Nu().P();
4859 fData->nu_dcosy_truth[neutrino_i] = mclist[iList]->GetNeutrino().Nu().Py()/mclist[iList]->GetNeutrino().Nu().P();
4860 fData->nu_dcosz_truth[neutrino_i] = mclist[iList]->GetNeutrino().Nu().Pz()/mclist[iList]->GetNeutrino().Nu().P();
4862 fData->lep_mom_truth[neutrino_i] = mclist[iList]->GetNeutrino().Lepton().P();
4863 if (mclist[iList]->GetNeutrino().Lepton().
P()){
4864 fData->lep_dcosx_truth[neutrino_i] = mclist[iList]->GetNeutrino().Lepton().Px()/mclist[iList]->GetNeutrino().Lepton().P();
4865 fData->lep_dcosy_truth[neutrino_i] = mclist[iList]->GetNeutrino().Lepton().Py()/mclist[iList]->GetNeutrino().Lepton().P();
4866 fData->lep_dcosz_truth[neutrino_i] = mclist[iList]->GetNeutrino().Lepton().Pz()/mclist[iList]->GetNeutrino().Lepton().P();
4876 if (find_mcflux.isValid()) {
4877 auto flux_maybe_ref = find_mcflux.at(iList);
4878 if (flux_maybe_ref.isValid()) {
4879 auto flux_ref = flux_maybe_ref.ref();
4880 fData->vx_flux[neutrino_i] = flux_ref.fvx;
4881 fData->vy_flux[neutrino_i] = flux_ref.fvy;
4882 fData->vz_flux[neutrino_i] = flux_ref.fvz;
4883 fData->pdpx_flux[neutrino_i] = flux_ref.fpdpx;
4884 fData->pdpy_flux[neutrino_i] = flux_ref.fpdpy;
4885 fData->pdpz_flux[neutrino_i] = flux_ref.fpdpz;
4886 fData->ppdxdz_flux[neutrino_i] = flux_ref.fppdxdz;
4887 fData->ppdydz_flux[neutrino_i] = flux_ref.fppdydz;
4888 fData->pppz_flux[neutrino_i] = flux_ref.fpppz;
4890 fData->ptype_flux[neutrino_i] = flux_ref.fptype;
4891 fData->ppvx_flux[neutrino_i] = flux_ref.fppvx;
4892 fData->ppvy_flux[neutrino_i] = flux_ref.fppvy;
4893 fData->ppvz_flux[neutrino_i] = flux_ref.fppvz;
4894 fData->muparpx_flux[neutrino_i] = flux_ref.fmuparpx;
4895 fData->muparpy_flux[neutrino_i] = flux_ref.fmuparpy;
4896 fData->muparpz_flux[neutrino_i] = flux_ref.fmuparpz;
4897 fData->mupare_flux[neutrino_i] = flux_ref.fmupare;
4899 fData->tgen_flux[neutrino_i] = flux_ref.ftgen;
4900 fData->tgptype_flux[neutrino_i] = flux_ref.ftgptype;
4901 fData->tgppx_flux[neutrino_i] = flux_ref.ftgppx;
4902 fData->tgppy_flux[neutrino_i] = flux_ref.ftgppy;
4903 fData->tgppz_flux[neutrino_i] = flux_ref.ftgppz;
4904 fData->tprivx_flux[neutrino_i] = flux_ref.ftprivx;
4905 fData->tprivy_flux[neutrino_i] = flux_ref.ftprivy;
4906 fData->tprivz_flux[neutrino_i] = flux_ref.ftprivz;
4908 fData->dk2gen_flux[neutrino_i] = flux_ref.fdk2gen;
4909 fData->gen2vtx_flux[neutrino_i] = flux_ref.fgen2vtx;
4911 fData->tpx_flux[neutrino_i] = flux_ref.ftpx;
4912 fData->tpy_flux[neutrino_i] = flux_ref.ftpy;
4913 fData->tpz_flux[neutrino_i] = flux_ref.ftpz;
4914 fData->tptype_flux[neutrino_i] = flux_ref.ftptype;
4925 size_t StoreParticles =
std::min((
size_t)
fData->genie_no_primaries,
fData->GetMaxGeniePrimaries());
4926 if (
fData->genie_no_primaries > (
int) StoreParticles) {
4930 <<
fData->genie_no_primaries <<
" MC particles, only " 4931 << StoreParticles <<
" stored in tree";
4933 for(
size_t iPart = 0; iPart < StoreParticles; ++iPart){
4935 fData->genie_primaries_pdg[iPart]=part.PdgCode();
4936 fData->genie_Eng[iPart]=part.E();
4937 fData->genie_Px[iPart]=part.Px();
4938 fData->genie_Py[iPart]=part.Py();
4939 fData->genie_Pz[iPart]=part.Pz();
4940 fData->genie_P[iPart]=part.P();
4941 fData->genie_status_code[iPart]=part.StatusCode();
4942 fData->genie_mass[iPart]=part.Mass();
4943 fData->genie_trackID[iPart]=part.TrackId();
4944 fData->genie_ND[iPart]=part.NumberDaughters();
4945 fData->genie_mother[iPart]=part.Mother();
4953 fData->no_mcshowers = nMCShowers;
4956 imcshwr != mcshowerh->end(); ++imcshwr) {
4965 fData->mcshwr_endX[shwr] = mcshwr.
End().
X();
4966 fData->mcshwr_endY[shwr] = mcshwr.
End().
Y();
4967 fData->mcshwr_endZ[shwr] = mcshwr.
End().
Z();
4969 fData->mcshwr_isEngDeposited[shwr] = 1;
4977 fData->mcshwr_dEdx[shwr] = mcshwr.
dEdx();
4983 fData->mcshwr_isEngDeposited[shwr] = 0;
5004 fData->mcshwr_Process.resize(shwr);
5005 fData->mcshwr_MotherProcess.resize(shwr);
5006 fData->mcshwr_AncestorProcess.resize(shwr);
5011 fData->no_mctracks = nMCTracks;
5015 TLorentzVector tpcstart, tpcend, tpcmom;
5016 double plen =
driftedLength(detProp, mctrk, tpcstart, tpcend, tpcmom);
5024 fData->mctrk_endX[trk] = mctrk.
End().
X();
5025 fData->mctrk_endY[trk] = mctrk.
End().
Y();
5026 fData->mctrk_endZ[trk] = mctrk.
End().
Z();
5046 fData->mctrk_len_drifted[trk] = plen;
5049 fData->mctrk_startX_drifted[trk] = tpcstart.X();
5050 fData->mctrk_startY_drifted[trk] = tpcstart.Y();
5051 fData->mctrk_startZ_drifted[trk] = tpcstart.Z();
5052 fData->mctrk_endX_drifted[trk] = tpcend.X();
5053 fData->mctrk_endY_drifted[trk] = tpcend.Y();
5054 fData->mctrk_endZ_drifted[trk] = tpcend.Z();
5055 fData->mctrk_p_drifted[trk] = tpcmom.Vect().Mag();
5056 fData->mctrk_px_drifted[trk] = tpcmom.X();
5057 fData->mctrk_py_drifted[trk] = tpcmom.Y();
5058 fData->mctrk_pz_drifted[trk] = tpcmom.Z();
5063 fData->mctrk_Process.resize(trk);
5064 fData->mctrk_MotherProcess.resize(trk);
5065 fData->mctrk_AncestorProcess.resize(trk);
5072 const sim::ParticleList& plist = pi_serv->
ParticleList();
5077 size_t geant_particle=0;
5082 std::map<int, size_t> TrackIDtoIndex;
5083 std::vector<int> gpdg;
5084 std::vector<int> gmother;
5085 for(
size_t iPart = 0; (iPart < plist.size()) && (itPart != pend); ++iPart){
5089 <<
"GEANT particle #" << iPart <<
" returned a null pointer";
5093 bool isPrimary = pPart->
Process() == pri;
5094 int TrackID = pPart->
TrackId();
5095 TrackIDtoIndex.emplace(TrackID, iPart);
5096 gpdg.push_back(pPart->
PdgCode());
5097 gmother.push_back(pPart->
Mother());
5098 if (iPart < fData->GetMaxGEANTparticles()) {
5099 if (pPart->
E()<
fG4minE&&(!isPrimary))
continue;
5100 if (isPrimary) ++primary;
5102 TLorentzVector mcstart, mcend, mcstartdrifted, mcenddrifted;
5103 unsigned int pstarti, pendi, pstartdriftedi, penddriftedi;
5104 double plen =
length(*pPart, mcstart, mcend, pstarti, pendi);
5105 double plendrifted =
driftedLength(detProp, *pPart, mcstartdrifted, mcenddrifted, pstartdriftedi, penddriftedi);
5107 bool isActive = plen != 0;
5108 bool isDrifted = plendrifted!= 0;
5111 fData->process_primary[geant_particle] =
int(isPrimary);
5117 fData->Eng[geant_particle]=pPart->
E();
5118 fData->EndE[geant_particle]=pPart->
EndE();
5119 fData->Mass[geant_particle]=pPart->
Mass();
5120 fData->Px[geant_particle]=pPart->
Px();
5121 fData->Py[geant_particle]=pPart->
Py();
5122 fData->Pz[geant_particle]=pPart->
Pz();
5124 fData->StartPointx[geant_particle]=pPart->
Vx();
5125 fData->StartPointy[geant_particle]=pPart->
Vy();
5126 fData->StartPointz[geant_particle]=pPart->
Vz();
5127 fData->StartT[geant_particle] = pPart->
T();
5131 fData->EndT[geant_particle] = pPart->
EndT();
5134 fData->theta_xz[geant_particle] = std::atan2(pPart->
Px(), pPart->
Pz());
5135 fData->theta_yz[geant_particle] = std::atan2(pPart->
Py(), pPart->
Pz());
5136 fData->pathlen[geant_particle] = plen;
5137 fData->pathlen_drifted[geant_particle] = plendrifted;
5139 fData->inTPCActive[geant_particle] =
int(isActive);
5140 fData->inTPCDrifted[geant_particle] =
int(isDrifted);
5143 fData->origin[geant_particle] = mc_truth->
Origin();
5144 fData->MCTruthIndex[geant_particle] = mc_truth.
key();
5147 fData->StartPointx_tpcAV[geant_particle] = mcstart.X();
5148 fData->StartPointy_tpcAV[geant_particle] = mcstart.Y();
5149 fData->StartPointz_tpcAV[geant_particle] = mcstart.Z();
5150 fData->StartT_tpcAV[geant_particle] = mcstart.T();
5151 fData->StartE_tpcAV[geant_particle] = pPart->
E(pstarti);
5152 fData->StartP_tpcAV[geant_particle] = pPart->
P(pstarti);
5153 fData->StartPx_tpcAV[geant_particle] = pPart->
Px(pstarti);
5154 fData->StartPy_tpcAV[geant_particle] = pPart->
Py(pstarti);
5155 fData->StartPz_tpcAV[geant_particle] = pPart->
Pz(pstarti);
5156 fData->EndPointx_tpcAV[geant_particle] = mcend.X();
5157 fData->EndPointy_tpcAV[geant_particle] = mcend.Y();
5158 fData->EndPointz_tpcAV[geant_particle] = mcend.Z();
5159 fData->EndT_tpcAV[geant_particle] = mcend.T();
5160 fData->EndE_tpcAV[geant_particle] = pPart->
E(pendi);
5161 fData->EndP_tpcAV[geant_particle] = pPart->
P(pendi);
5162 fData->EndPx_tpcAV[geant_particle] = pPart->
Px(pendi);
5163 fData->EndPy_tpcAV[geant_particle] = pPart->
Py(pendi);
5164 fData->EndPz_tpcAV[geant_particle] = pPart->
Pz(pendi);
5167 fData->StartPointx_drifted[geant_particle] = mcstartdrifted.X();
5168 fData->StartPointy_drifted[geant_particle] = mcstartdrifted.Y();
5169 fData->StartPointz_drifted[geant_particle] = mcstartdrifted.Z();
5170 fData->StartT_drifted[geant_particle] = mcstartdrifted.T();
5171 fData->StartE_drifted[geant_particle] = pPart->
E(pstartdriftedi);
5172 fData->StartP_drifted[geant_particle] = pPart->
P(pstartdriftedi);
5173 fData->StartPx_drifted[geant_particle] = pPart->
Px(pstartdriftedi);
5174 fData->StartPy_drifted[geant_particle] = pPart->
Py(pstartdriftedi);
5175 fData->StartPz_drifted[geant_particle] = pPart->
Pz(pstartdriftedi);
5176 fData->EndPointx_drifted[geant_particle] = mcenddrifted.X();
5177 fData->EndPointy_drifted[geant_particle] = mcenddrifted.Y();
5178 fData->EndPointz_drifted[geant_particle] = mcenddrifted.Z();
5179 fData->EndT_drifted[geant_particle] = mcenddrifted.T();
5180 fData->EndE_drifted[geant_particle] = pPart->
E(penddriftedi);
5181 fData->EndP_drifted[geant_particle] = pPart->
P(penddriftedi);
5182 fData->EndPx_drifted[geant_particle] = pPart->
Px(penddriftedi);
5183 fData->EndPy_drifted[geant_particle] = pPart->
Py(penddriftedi);
5184 fData->EndPz_drifted[geant_particle] = pPart->
Pz(penddriftedi);
5189 unsigned short nAD = 0;
5196 const std::vector<sim::AuxDetIDE>& setOfIDEs =
c->AuxDetIDEs();
5203 setOfIDEs.begin(), setOfIDEs.end(),
5206 if (iIDE == setOfIDEs.end())
continue;
5214 for(
const auto& adtracks: setOfIDEs) {
5215 if( fabs(adtracks.trackID) ==
TrackID )
5216 totalE += adtracks.energyDeposited;
5221 fData->AuxDetID[geant_particle][nAD] =
c->AuxDetID();
5222 fData->entryX[geant_particle][nAD] = iIDE->entryX;
5223 fData->entryY[geant_particle][nAD] = iIDE->entryY;
5224 fData->entryZ[geant_particle][nAD] = iIDE->entryZ;
5225 fData->entryT[geant_particle][nAD] = iIDE->entryT;
5226 fData->exitX[geant_particle][nAD] = iIDE->exitX;
5227 fData->exitY[geant_particle][nAD] = iIDE->exitY;
5228 fData->exitZ[geant_particle][nAD] = iIDE->exitZ;
5229 fData->exitT[geant_particle][nAD] = iIDE->exitT;
5230 fData->exitPx[geant_particle][nAD] = iIDE->exitMomentumX;
5231 fData->exitPy[geant_particle][nAD] = iIDE->exitMomentumY;
5232 fData->exitPz[geant_particle][nAD] = iIDE->exitMomentumZ;
5233 fData->CombinedEnergyDep[geant_particle][nAD] = totalE;
5237 fData->NAuxDets[geant_particle] = nAD;
5242 <<
"particle #" << iPart
5243 <<
" touches " << nAD <<
" auxiliary detector cells, only " 5244 <<
kMaxAuxDets <<
" of them are saved in the tree";
5250 else if (iPart ==
fData->GetMaxGEANTparticles()) {
5254 << plist.size() <<
" MC particles, only " 5255 <<
fData->GetMaxGEANTparticles() <<
" will be stored in tree";
5259 fData->geant_list_size_in_tpcAV = active;
5260 fData->no_primaries = primary;
5261 fData->geant_list_size = geant_particle;
5262 fData->processname.resize(geant_particle);
5265 <<
fData->geant_list_size <<
" GEANT particles (" 5266 <<
fData->geant_list_size_in_tpcAV <<
" in AV), " 5267 <<
fData->no_primaries <<
" primaries, " 5268 <<
fData->genie_no_primaries <<
" GENIE particles";
5270 FillWith(
fData->MergedId, 0);
5305 for(Int_t prt = 0; prt < nProtoPrimaries; ++prt){
5306 for(Int_t gnt = 0; gnt <
fData->geant_list_size; ++gnt){
5308 if(
fData->proto_pdg[prt] ==
fData->pdg[gnt] && std::fabs(
fData->proto_px[prt] -
fData->Px[gnt]) < 0.0001){
5309 fData->proto_geantTrackID[prt] =
fData->TrackId[gnt];
5310 fData->proto_geantIndex[prt] = gnt;
5319 fData->taulife = detProp.ElectronLifetime();
5327 <<
"Tree data structure contains:" 5328 <<
"\n - " <<
fData->no_hits <<
" hits (" <<
fData->GetMaxHits() <<
")" 5329 <<
"\n - " <<
fData->genie_no_primaries <<
" genie primaries (" <<
fData->GetMaxGeniePrimaries() <<
")" 5330 <<
"\n - " <<
fData->geant_list_size <<
" GEANT particles (" <<
fData->GetMaxGEANTparticles() <<
"), " 5331 <<
fData->no_primaries <<
" primaries" 5332 <<
"\n - " <<
fData->geant_list_size_in_tpcAV <<
" GEANT particles in AV " 5333 <<
"\n - " << ((
int)
fData->kNTracker) <<
" trackers:" 5336 size_t iTracker = 0;
5337 for (
auto tracker =
fData->TrackData.cbegin();
5338 tracker !=
fData->TrackData.cend(); ++tracker, ++iTracker
5342 <<
" tracks (" << tracker->GetMaxTracks() <<
")" 5344 for (
int iTrk = 0; iTrk < tracker->ntracks; ++iTrk) {
5345 logStream <<
"\n [" << iTrk <<
"] "<< tracker->ntrkhits[iTrk][0];
5346 for (
size_t ipl = 1; ipl < tracker->GetMaxPlanesPerTrack(iTrk); ++ipl)
5347 logStream <<
" + " << tracker->ntrkhits[iTrk][ipl];
5348 logStream <<
" hits (" << tracker->GetMaxHitsPerTrack(iTrk, 0);
5349 for (
size_t ipl = 1; ipl < tracker->GetMaxPlanesPerTrack(iTrk); ++ipl)
5350 logStream <<
" + " << tracker->GetMaxHitsPerTrack(iTrk, ipl);
5360 MF_LOG_DEBUG(
"AnalysisTreeStructure") <<
"Freeing the tree data structure";
double E(const int i=0) const
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
code to link reconstructed objects back to the MC truth information
void DestroyData()
Destroy the local buffers (existing branches will point to invalid address!)
void XYZ(double *xyz) const
Legacy method to access vertex position, preserved to avoid breaking code. Please try to use Vertex::...
bool fSaveRawDigitInfo
whether to extract and save Hit information
void CreateTree(bool bClearData=false)
Create the output tree and the data structures, if needed.
simb::Origin_t Origin() const
constexpr std::uint32_t timeLow() const
double VertexMomentum() const
double driftedLength(detinfo::DetectorPropertiesData const &detProp, const simb::MCParticle &part, TLorentzVector &start, TLorentzVector &end, unsigned int &starti, unsigned int &endi)
const MCStep & End() const
double Py(const int i=0) const
float SummedADCaverage() const
Returns the average signal ADC counts of the cluster hits.
float IntegralAverage() const
Returns the average charge of the cluster hits.
bool fSavePFParticleInfo
whether to extract and save Shower information
Energy deposited on a readout channel by simulated tracks.
std::string fMCTrackModuleLabel
constexpr int kMaxNPFPNeutrinos
const TLorentzVector & EndPosition() const
std::vector< std::string > fCosmicTaggerAssocLabel
whether to extract and save CNN information
std::map< art::Ptr< recob::PFParticle >, ClusterVector > PFParticlesToClusters
std::string fGenieGenModuleLabel
constexpr unsigned short kMaxAuxDets
max number of auxiliary detector cells per MC particle
unsigned int TrackID() const
static bool IsNeutrino(const art::Ptr< recob::PFParticle > particle)
Determine whether a particle has been reconstructed as a neutrino.
bool fSaveAuxDetInfo
whether to extract and save auxiliary detector data
std::string fOpFlashModuleLabel
Handle< PROD > getHandle(SelectorBase const &) const
void SetVertexAddresses(size_t iVertexAlg)
const simb::MCParticle * TrackIdToParticle_P(int id) const
const std::string & AncestorProcess() const
constexpr std::uint32_t timeHigh() const
simb::Origin_t Origin() const
double Px(const int i=0) const
bool fSaveCaloCosmics
save calorimetry information for cosmics
const MCStep & MotherEnd() const
unsigned int AncestorTrackID() const
size_t NumberTrajectoryPoints() const
Various functions related to the presence and the number of (valid) points.
float StartWire() const
Returns the wire coordinate of the start of the cluster.
std::string fSpacePointSolverModuleLabel
Vector_t VertexDirection() const
static bool IsShower(const art::Ptr< recob::PFParticle > particle)
Determine whether a particle has been reconstructed as shower-like.
std::vector< std::string > fMVAPIDShowerModuleLabel
bool get(SelectorBase const &, Handle< PROD > &result) const
std::vector< const sim::IDE * > TrackIdToSimIDEs_Ps(int const &id) const
std::pair< float, std::string > P
int PdgCode() const
Return the type of particle as a PDG ID.
void SetPFParticleAddress()
Set of hits with a 2D structure.
std::vector< art::Ptr< recob::Shower > > ShowerVector
float EndTick() const
Returns the tick coordinate of the end of the cluster.
float MultipleHitDensity() const
Density of wires in the cluster with more than one hit.
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
Cluster finding and building.
std::string fCryGenModuleLabel
std::string Process() const
std::vector< std::string > fContainmentTaggerAssocLabel
int AncestorPdgCode() const
constexpr int kMaxExternCounts
bool isValid() const
Returns if the cluster is valid (that is, if its ID is not invalid)
const MCStep & End() const
float StartAngle() const
Returns the starting angle of the cluster.
std::vector< std::string > fMCT0FinderLabel
std::map< art::Ptr< recob::PFParticle >, TrackVector > PFParticlesToTracks
const art::Ptr< simb::MCTruth > & ParticleToMCTruth_P(const simb::MCParticle *p) const
std::vector< std::string > fVertexModuleLabel
int NumberDaughters() const
unsigned int MotherTrackID() const
std::map< art::Ptr< recob::PFParticle >, VertexVector > PFParticlesToVertices
bool isValid() const noexcept
std::vector< std::string > fFlashT0FinderLabel
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
const TVector3 & StartDir() const
Collection of particles crossing one auxiliary detector cell.
bool fSaveExternCounterInfo
whether to extract and save Flash information
float EndCharge() const
Returns the charge on the last wire of the cluster.
double dEdx(float dqdx, float Efield)
float SummedADC() const
Returns the total charge of the cluster from signal ADC counts.
double bdist(const TVector3 &pos)
std::string fCosmicClusterTaggerAssocLabel
simb::Origin_t Origin() const
double Length(size_t p=0) const
Access to various track properties.
std::map< art::Ptr< recob::PFParticle >, ShowerVector > PFParticlesToShowers
std::vector< std::string > fMVAPIDTrackModuleLabel
AnalysisTreeDataStruct::SubRunData_t SubRunData
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
int MotherPdgCode() const
const std::string & AncestorProcess() const
std::vector< art::Ptr< recob::PFParticle > > PFParticleVector
bool fSaveVertexInfo
whether to extract and save Track information
const art::Ptr< simb::MCTruth > & TrackIdToMCTruth_P(int id) const
static void CollectShowers(const art::Event &evt, const std::string &label, ShowerVector &showerVector, PFParticlesToShowers &particlesToShowers)
Collect the reconstructed PFParticles and associated Showers from the ART event record.
std::vector< Handle< PROD > > getMany(SelectorBase const &selector=MatchAllSelector{}) const
double P(const int i=0) const
key_type key() const noexcept
float Width() const
A measure of the cluster width, in homogenized units.
size_t GetNShowerAlgos() const
Returns the number of shower algorithms configured.
Point_t const & Vertex() const
static void CollectVertices(const art::Event &evt, const std::string &label, VertexVector &vertexVector, PFParticlesToVertices &particlesToVertices)
Collect the reconstructed PFParticles and associated Vertices from the ART event record.
std::string fPandoraNuVertexModuleLabel
double T(const int i=0) const
std::vector< std::string > fCalorimetryModuleLabel
std::string fClusterModuleLabel
constexpr int kMaxClusters
struct recob::OpFlashPtrSortByPE_t OpFlashPtrSortByPE
bool fUseBuffer
whether to use a permanent buffer (faster, huge memory)
SubRunNumber_t subRun() const
bool IsPrimary() const
Returns whether the particle is the root of the flow.
std::vector< art::Ptr< recob::Track > > TrackVector
const MCStep & AncestorStart() const
static int max(int a, int b)
size_t GetNVertexAlgos() const
std::string fCnnModuleLabel
std::string fPFParticleModuleLabel
const MCStep & AncestorStart() const
static void CollectTracks(const art::Event &evt, const std::string &label, TrackVector &trackVector, PFParticlesToTracks &particlesToTracks)
Collect the reconstructed PFParticles and associated Tracks from the ART event record.
bool fSaveProtoInfo
whether to extract and save Genie information
const std::string & MotherProcess() const
static void CollectPFParticles(const art::Event &evt, const std::string &label, PFParticleVector &particleVector)
Collect the reconstructed PFParticles from the ART event record.
bool fSaveTrackInfo
whether to extract and save Raw Digit information
std::string fProtoGenModuleLabel
bool fSaveClusterInfo
whether to extract and save Vertex information
unsigned int AncestorTrackID() const
const MCStep & AncestorEnd() const
const MCStep & DetProfile() const
Detector simulation of raw signals on wires.
const sim::ParticleList & ParticleList() const
bool isCosmics
if it contains cosmics
const simb::MCParticle & GetParticle(int i) const
static void SelectNeutrinoPFParticles(const PFParticleVector &inputParticles, PFParticleVector &outputParticles)
Select reconstructed neutrino particles from a list of all reconstructed particles.
std::vector< std::string > fTrackModuleLabel
bool fSavePandoraNuVertexInfo
whether to extract and save Cluster information
const MCStep & Start() const
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
constexpr int kMaxVertices
double Vx(const int i=0) const
geo::View_t View() const
Returns the view for this cluster.
std::string fHitsModuleLabel
const MCStep & MotherStart() const
bool fSaveFlashInfo
whether to extract and save nu vertex information from Pandora
constexpr int kMaxFlashes
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
int MotherPdgCode() const
const MCStep & MotherEnd() const
std::string fExternalCounterModuleLabel
float StartCharge() const
Returns the charge on the first wire of the cluster.
bool fSaveMCShowerInfo
whether to extract and save Geant information
bool fSaveMCTrackInfo
whether to extract and save MC Shower information
ID_t ID() const
Identifier of this cluster.
std::string fLArG4ModuleLabel
std::string fDigitModuleLabel
Vector_t EndDirection() const
MC truth information to make RawDigits and do back tracking.
std::vector< sim::TrackIDE > HitToEveTrackIDEs(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
const TLorentzVector & Momentum(const int i=0) const
const std::string & Process() const
const std::string & MotherProcess() const
bool fSaveGeantInfo
whether to extract and save ProtDUNE beam simulation information
static bool IsTrack(const art::Ptr< recob::PFParticle > particle)
Determine whether a particle has been reconstructed as track-like.
double Pz(const int i=0) const
float fG4minE
Energy threshold to save g4 particle info.
size_t GetNTrackers() const
Returns the number of trackers configured.
void SetTrackerAddresses(size_t iTracker)
std::string fMCShowerModuleLabel
unsigned int MotherTrackID() const
double Vz(const int i=0) const
std::vector< double > SimIDEsToXYZ(std::vector< sim::IDE > const &ides) const
const std::string & Process() const
std::vector< art::Ptr< recob::Vertex > > VertexVector
std::unique_ptr< AnalysisTreeDataStruct > fData
bool bIgnoreMissingShowers
whether to ignore missing shower information
EventNumber_t event() const
Point_t const & End() const
const MCStep & MotherStart() const
detail::Node< FrameID, bool > PlaneID
bool fSaveCnnInfo
whether to extract and save SpacePointSolver information
const MCStep & Start() const
TDCIDEs_t const & TDCIDEMap() const
Returns all the deposited energy information as stored.
std::vector< const sim::IDE * > HitToSimIDEs_Ps(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
std::size_t getView(std::string const &moduleLabel, std::string const &productInstanceName, std::string const &processName, std::vector< ELEMENT const * > &result) const
std::vector< art::Ptr< recob::Cluster > > ClusterVector
unsigned int NHits() const
Number of hits in the cluster.
unsigned int TrackID() const
int AncestorPdgCode() const
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
std::map< std::string, double > mvaOutput
void CreateData(bool bClearData=false)
Creates the structure for the tree data; optionally initializes it.
float EndAngle() const
Returns the ending angle of the cluster.
void Uncompress(const std::vector< short > &adc, std::vector< short > &uncompressed, raw::Compress_t compress)
Uncompresses a raw data buffer.
double length(const recob::Track &track)
second_as<> second
Type of time stored in seconds, in double precision.
recob::tracking::Plane Plane
std::vector< std::string > fFlashMatchAssocLabel
float StartTick() const
Returns the tick coordinate of the start of the cluster.
void HitsPurity(detinfo::DetectorClocksData const &clockData, std::vector< art::Ptr< recob::Hit > > const &hits, Int_t &trackid, Float_t &purity, double &maxe)
std::vector< std::string > fShowerModuleLabel
void FillShowers(AnalysisTreeDataStruct::ShowerDataStruct &showerData, std::vector< recob::Shower > const &showers, const bool fSavePFParticleInfo, const std::map< Short_t, Short_t > &showerIDtoPFParticleIDMap) const
Stores the information of all showers into showerData.
bool fSaveHitInfo
whether to extract and save MC Track information
static std::unique_ptr< MVAReader > create(const art::Event &evt, const art::InputTag &tag)
double Vy(const int i=0) const
const MCStep & AncestorEnd() const
bool fSaveGenieInfo
whether to extract and save CRY particle data
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
cet::coded_exception< error, detail::translate > exception
QTextStream & endl(QTextStream &s)
bool fSaveSpacePointSolverInfo
whether to extract and save PFParticle information
float Integral() const
Returns the total charge of the cluster from hit shape.
float EndWire() const
Returns the wire coordinate of the end of the cluster.
bool fSaveShowerInfo
whether to extract and save External Counter information