545 MF_LOG_DEBUG(
"CRT") <<
"beginning analyis" <<
'\n';
549 throw cet::exception(
"CRTSimAnalysis")
550 <<
" PDG/Momtenta values not set correctly in fhicl - lists have different sizes"
551 <<
" Line " << __LINE__ <<
" in file " << __FILE__ << std::endl;
555 fEvent =
event.id().event();
563 art::Handle< vector<simb::MCTruth>> genHandle;
566 art::Handle< vector<simb::MCParticle> > particleHandle;
567 map< int, const simb::MCParticle*> particleMap;
569 if (!event.getByLabel(
"generator", genHandle)) {
570 std::cout <<
"could not get handle to gen objects!!!" << std::endl;
580 throw cet::exception(
"CRTSimAnalysis")
581 <<
" No simb::MCParticle objects in this event - "
582 <<
" Line " << __LINE__ <<
" in file " << __FILE__ << std::endl;
586 art::Handle<vector<sim::AuxDetSimChannel> > auxDetSimChannelHandle;
588 throw cet::exception(
"CRTSimAnalysis")
589 <<
" No sim::AuxDetSimChannel objects in this event - "
590 <<
" Line " << __LINE__ <<
" in file " << __FILE__ << std::endl;
593 if((*genHandle).size()>1)
594 throw cet::exception(
"CRTSimAnalysis") <<
"gen stage MCParticle vector has more than 1 entry!" <<
'\n';
596 auto const& truth = (*genHandle)[0];
597 fNGen = truth.NParticles();
605 for (
int i=0; i<
fNGen; i++ )
607 auto const& part = truth.GetParticle(i);
610 fGenPDG.push_back(part.PdgCode());
612 const TLorentzVector startPos = part.Position(0);
613 const TLorentzVector endPos = part.EndPosition();
614 const TLorentzVector startMom = part.Momentum(0);
615 const TLorentzVector endMom = part.EndMomentum();
617 fGenStartXYZT.push_back({startPos.X(),startPos.Y(),startPos.Z(),startPos.T()});
618 fGenEndXYZT.push_back({endPos.X(),endPos.Y(),endPos.Z(),endPos.T()});
619 fGenStartPE.push_back({startMom.Px(),startMom.Py(),startMom.Pz(),startMom.E()});
620 fGenEndPE.push_back({endMom.Px(),endMom.Py(),endMom.Pz(),endMom.E()});
629 for (
auto const& particle : (*particleHandle) )
633 particleMap.insert(std::make_pair(particle.TrackId(),&particle));
636 std::cout <<
"event " <<
fEvent <<
" with " << particleMap.size() <<
" MCParticles" << std::endl;
648 for (
auto const& particle : (*particleHandle) )
651 vector<int>::iterator it =
fPDGs.begin();
652 const TLorentzVector& momentumStart = particle.Momentum(0);
653 const double p = (momentumStart.Vect()).Mag();
659 while (it!=
fPDGs.end()) {
661 index = (size_t)(it -
fPDGs.begin());
685 fNDaught = particle.NumberDaughters();
690 map<int,const simb::MCParticle*>::const_iterator it = particleMap.find(
fMother);
691 if(it==particleMap.end()){
699 int tmpID=it->second->Mother();
701 map<int,const simb::MCParticle*>::iterator it2 = particleMap.begin();
704 else while(it2!=particleMap.end()&&ctr<particleMap.size()){
705 it2=particleMap.find(tmpID);
706 if(it2!=particleMap.end()){
707 if(it2->second->PdgCode()==13||it2->second->PdgCode()==-13){
711 tmpID = it2->second->Mother();
715 if(ctr==particleMap.size())
std::cout<<
"manual break!"<<std::endl;
730 fSimHits = particle.NumberTrajectoryPoints();
736 const TLorentzVector& positionStart = particle.Position(0);
737 const TLorentzVector& positionEnd = particle.Position(last);
739 const TLorentzVector& momentumEnd = particle.Momentum(last);
745 momentumEnd.GetXYZT(
fEndPE );
778 for (
unsigned int i=0; i<
fSimHits; i++){
779 const TLorentzVector& pos = particle.Position(i);
780 const TLorentzVector& posnext = particle.Position(i+1);
781 const TLorentzVector& mom = particle.Momentum(i);
782 const double point[3] = {pos.X(),pos.Y(),pos.Z()};
783 const double pointnext[3] = {posnext.X(),posnext.Y(),posnext.Z()};
784 double opDetPos[3] = {-FLT_MAX, -FLT_MAX, -FLT_MAX};
785 double entryPos[3] = {-FLT_MAX, -FLT_MAX, -FLT_MAX};
786 double entryT = -FLT_MAX;
787 bool active0 =
false, active1 =
false, activenext0 =
false, activenext1 =
false;
790 fCDxyzt.push_back({pos.X(),pos.Y(),pos.Z(),pos.T()});
791 fCDpe.push_back({mom.Px(),mom.Py(),mom.Pz(),mom.E()});
792 fCDSlopes.push_back({mom.Px()/mom.P(), mom.Py()/mom.P(), mom.Pz()/mom.P()});
804 if ( (oldreg!=10&&!active0&&!active1) || (active0&&oldreg!=5) || (active1&&oldreg!=6)) {
806 fRegEntryPE.push_back({mom.Px(),mom.Py(),mom.Pz(),mom.E()});
807 fRegEntrySlope.push_back({mom.Px()/mom.P(), mom.Py()/mom.P(), mom.Pz()/mom.P()});
809 if (active0) oldreg = 5;
810 if (active1) oldreg = 6;
814 if (!cryo0.
ContainsPosition(pointnext) || (oldreg==10&&(activenext0||activenext1))
816 || (active0 && !activenext0) || (active1&&!activenext1) ){
821 fRegExitXYZT.push_back({pos.X(),pos.Y(),pos.Z(),pos.T()});
822 fRegExitPE.push_back({mom.Px(),mom.Py(),mom.Pz(),mom.E()});
823 fRegExitSlope.push_back({mom.Px()/mom.P(), mom.Py()/mom.P(), mom.Pz()/mom.P()});
844 std::cout <<
"entry/exit point size mismatch! " <<
850 for (
int index=0; index<3; index++) entryPos[index] =
fRegEntryXYZT[fNReg][index];
856 + pow(opDetPos[1]-entryPos[1],2)
857 + pow(opDetPos[2]-entryPos[2],2)));
859 for (
int index=0; index<3; index++)
fRegOpDetXYZT[fNReg].push_back(opDetPos[index]);
874 if ( (oldreg!=12&&!active0&&!active1) || (active0&&oldreg!=7) || (active1&&oldreg!=8)) {
876 fRegEntryPE.push_back({mom.Px(),mom.Py(),mom.Pz(),mom.E()});
877 fRegEntrySlope.push_back({mom.Px()/mom.P(), mom.Py()/mom.P(), mom.Pz()/mom.P()});
879 if (active0) oldreg = 7;
880 if (active1) oldreg = 8;
883 if (!cryo1.
ContainsPosition(pointnext) || (oldreg==12&&(activenext0||activenext1))
885 || (active0 && !activenext0) || (active1&&!activenext1) ){
890 fRegExitXYZT.push_back({pos.X(),pos.Y(),pos.Z(),pos.T()});
891 fRegExitPE.push_back({mom.Px(),mom.Py(),mom.Pz(),mom.E()});
892 fRegExitSlope.push_back({mom.Px()/mom.P(), mom.Py()/mom.P(), mom.Pz()/mom.P()});
916 for (
int index=0; index<3; index++) entryPos[index] =
fRegEntryXYZT[fNReg][index];
922 + pow(opDetPos[1]-entryPos[1],2)
923 + pow(opDetPos[2]-entryPos[2],2)));
925 for (
int index=0; index<3; index++)
fRegOpDetXYZT[fNReg].push_back(opDetPos[index]);
941 map< int, vector<double> > regCRTEnter, regCRTExit, regCRTEnterPE, regCRTExitPE;
961 for (
auto const& channel : (*auxDetSimChannelHandle) )
964 auto const& auxDetIDEs = channel.AuxDetIDEs();
967 for (
auto const& ide : auxDetIDEs )
972 if ( ide.energyDeposited * 1.0e6 < 50 )
continue;
974 size_t adid = channel.AuxDetID();
996 double dx = ide.entryX-ide.exitX;
997 double dy = ide.entryY-ide.exitY;
998 double dz = ide.entryZ-ide.exitZ;
999 double adlength = sqrt(dx*dx+dy*dy+dz*dz);
1000 if ( adlength < 0.0001)
continue;
1003 fADEDep.push_back(ide.energyDeposited);
1005 fAuxDetID.push_back(channel.AuxDetID());
1007 fADEnterXYZT.push_back({ide.entryX,ide.entryY,ide.entryZ,ide.entryT});
1008 fADExitXYZT.push_back({ide.exitX,ide.exitY,ide.exitZ,ide.exitT});
1010 double pmag = sqrt(pow(ide.exitMomentumX,2)+pow(ide.exitMomentumY,2)+pow(ide.exitMomentumZ,2));
1011 fADExitPE.push_back({ide.exitMomentumX,ide.exitMomentumY,ide.exitMomentumZ,pmag});
1017 if (regCRTEnter[
fAuxDetReg[fNAuxDet]][3] > ide.entryT) {
1027 if (regCRTExit.find(
fAuxDetReg[fNAuxDet])!=regCRTExit.end()) {
1028 if (regCRTExit[
fAuxDetReg[fNAuxDet]][3] < ide.exitT){
1046 for(
auto it=regCRTEnter.begin(); it!=regCRTEnter.end(); it++) {
1049 fRegEntryXYZT.push_back({(it->second)[0],(it->second)[1],(it->second)[2],(it->second)[3]});
1050 fRegExitXYZT.push_back({regCRTExit[it->first][0],regCRTExit[it->first][1],regCRTExit[it->first][2],
1051 regCRTExit[it->first][3]});
1055 fRegEntryPE.push_back({regCRTEnterPE[it->first][0],regCRTEnterPE[it->first][1],
1056 regCRTEnterPE[it->first][2], regCRTEnterPE[it->first][3]});
1057 fRegExitPE.push_back({regCRTExitPE[it->first][0],regCRTExitPE[it->first][1],
1058 regCRTExitPE[it->first][2], regCRTExitPE[it->first][3]});
1074 for(
int i = 1; (i <= (int)fNReg) &&
flag; i++)
1077 for (
int j=0; j < ((int)fNReg -1); j++)
1096 for (
int k=0;
k<4;
k++) {
1131 art::Handle<vector<CRTData>> crtDetSimHandle;
1134 vector<art::Ptr<CRTData>> febdata;
1135 art::fill_ptr_vector(febdata,crtDetSimHandle);
1136 mf::LogPrint(
"CRTSimAnalysis") <<
"found " << febdata.size() <<
" CRTData" <<
'\n';
1138 for (
auto const& data : febdata ) {
1139 fMac5 = data->fMac5;
1150 bool passfilter =
false;
1159 for(
int ch=0; ch<64; ch++) {
1160 fADC[ch] = data->fAdc[ch];
1171 if (particleMap.find(trk) != particleMap.end() ){
1172 fDetPDG.push_back(particleMap[trk]->PdgCode());
1191 mf::LogWarning(
"CRTSimAnalysis") <<
"CRTData products not found! (expected if gen/G4 step)" <<
'\n';
1195 art::Handle<vector<CRTHit>> crtSimHitHandle;
1199 vector<art::Ptr<CRTHit>> crtSimHits;
1200 art::fill_ptr_vector(crtSimHits,crtSimHitHandle);
1202 mf::LogPrint(
"CRTSimAnalysis") <<
"found " << crtSimHits.size() <<
" sim CRTHits" <<
'\n';
1203 for (
auto const&
hit : crtSimHits )
1223 uint8_t mactmp =
hit->feb_id[0];
1227 bool passfilter=
false;
1228 if(fPDGs.size()==1 && fPDGs[0]==0)
1231 for(
auto const& mactopes :
hit->pesmap){
1233 for(
auto const& chanpe : mactopes.second) {
1237 fHitPe.push_back(chanpe.second);
1246 if ( particleMap.find(trk) != particleMap.end()) {
1247 fHitPDG.push_back(particleMap[trk]->PdgCode());
1249 for(
int const&
pdg: fPDGs) {
1264 mf::LogWarning(
"CRTSimAnalysis")
1265 <<
"CRTHit products not found! (expected if gen/G4/detsim step)" <<
'\n';
1268 art::Handle<vector<CRTHit>> crtTrueHitHandle;
1272 vector<art::Ptr<CRTHit>> crtTrueHits;
1273 art::fill_ptr_vector(crtTrueHits,crtTrueHitHandle);
1275 mf::LogPrint(
"CRTSimAnalysis") <<
"found " << crtTrueHits.size() <<
" true CRTHits" <<
'\n';
1276 for (
auto const&
hit : crtTrueHits )
1296 uint8_t mactmp =
hit->feb_id[0];
1300 bool passfilter=
false;
1301 if(fPDGs.size()==1 && fPDGs[0]==0)
1304 for(
auto const& mactopes :
hit->pesmap){
1305 for(
auto const& chanpe : mactopes.second) {
1317 if ( particleMap.find(trk) != particleMap.end()){
1318 fTrueHitPDG.push_back(particleMap[trk]->PdgCode());
1320 for(
int const&
pdg: fPDGs) {
1335 mf::LogWarning(
"CRTSimAnalysis") <<
"true CRTHit products not found" <<
'\n';
1338 art::Handle<vector<sbn::crt::CRTTrack>> crtSimTrackHandle;
1342 vector<art::Ptr<sbn::crt::CRTTrack>> crtTracks;
1343 art::fill_ptr_vector(crtTracks,crtSimTrackHandle);
1346 art::FindManyP<CRTHit> findManyHits(
1349 mf::LogPrint(
"CRTSimAnalysis") <<
"found " << crtTracks.size() <<
" sim CRTTracks" <<
'\n';
1350 for (
size_t itrk=0; itrk<crtTracks.size(); itrk++ )
1352 auto const& trk = crtTracks[itrk];
1365 auto const& trkhits = findManyHits.at(itrk);
1367 uint32_t tstart=UINT32_MAX;
1369 size_t ihit_start=0, ihit_end=0;
1370 for(
size_t ihit=0; ihit<trkhits.size(); ihit++){
1371 if(trkhits[ihit]->ts0_ns<tstart) {
1373 tstart = trkhits[ihit]->ts0_ns;
1375 if(trkhits[ihit]->ts0_ns>tend){
1377 tend = trkhits[ihit]->ts0_ns;
1397 mf::LogWarning(
"CRTSimAnalysis") <<
"no CRTTrack products not found" <<
'\n';
string MacToRegion(uint8_t mac)
vector< float > fMinMomenta
unsigned int GetClosestOpDet(geo::Point_t const &point) const
vector< vector< double > > fRegEntryXYZT
float fTrueXHitErr
stat error of CRT hit reco X (cm)
int fSimTrackID
GEANT ID of the particle being processed.
art::InputTag fSimulationProducerLabel
The name of the producer that tracked simulated particles through the detector.
TTree * fTrueCRTHitNtuple
int fEntry
front-end board entry number (reset for each event)
float fXHit
signal inducing particle(s)' PDG code
then echo unknown compiler flag
float fZHitErr
stat error of CRT hit reco Z (cm)
vector< uint32_t > fAuxDetID
Global CRT module ID.
vector< int > fTrueHitPDG
art::InputTag fCRTTrueHitProducerLabel
float fT1Hit
hit time w.r.t. PPS
int fNSimTrack
number of simulated CRT tracks for this event
vector< vector< double > > fCDxyzt
vector< double > fADdEdx
average dEdx for particle traversing CRT strip
vector< vector< double > > fGenStartXYZT
Geometry information for a single TPC.
vector< int > fTrueHitMod
float fYHit
reconstructed Y position of CRT hit (cm)
int GetAuxDetTypeCode(size_t adid)
TTree * fSimulationNtuple
tuple with simulated data
void GetCenter(double *xyz, double localz=0.0) const
geo::GeometryCore const * fGeometryService
pointer to Geometry provider
size_t MacToAuxDetID(uint8_t mac, int chan)
vector< float > fTrueHitPe
Geometry information for a single cryostat.
vector< int > fTrueHitStrip
int fNHit
number of CRT hits for this event
CRTCommonUtils * fCrtutils
uint32_t fNAuxDet
Number of scintillator strips hit.
float fEndPE[4]
(Px,Py,Pz,E) at the true end of the particle
int AuxDetRegionNameToNum(string reg)
int fHitReg
region code of CRT hit
int fT0
signal time w.r.t. global event time
int fTrueHitReg
region code of CRT hit
vector< vector< double > > fRegExitSlope
int fEvent
number of the event being processed
int fMother
G4 track ID of mother that directly produced this MCParticle.
TTree * fCosmicDisplayNtuple
for ROOT based event display
vector< vector< double > > fRegExitPE
int fNDaught
number of daughters belonging to this MCParticle
float fTrueZHitErr
stat error of CRT hit reco Z (cm)
int fSimProcess
process that created the particle (e.g. brehmstralung)
float fTrueYHitErr
stat error of CRT hit reco Y (cm)
art::InputTag fCRTDetSimProducerLabel
uint32_t fSimHits
number of trajectory points for each MCParticle
const OpDetGeo & OpDet(unsigned int iopdet) const
Return the iopdet'th optical detector in the cryostat.
int fProgenitor
G4 track ID of the primary particle that ultimately led to this one.
int fRun
number of the run being processed
float fTrueYHit
reconstructed Y position of CRT hit (cm)
int fMac5
Mac5 address for this front-end board.
vector< vector< double > > fADEnterXYZT
4-position of entry into CRT strip
vector< int > fPDGs
PDG code of particle we'll focus on.
vector< uint32_t > fADMac
Mac5 address of the CRT module.
pair< uint8_t, uint8_t > ADToMac(size_t adid)
vector< double > fADTrackLength
Track length in CRT strip (cm)
CryostatGeo const & Cryostat(geo::CryostatID const &cryoid) const
Returns the specified cryostat.
float fTrackLength
total track length for each MCParticle
float fStartPE[4]
(Px,Py,Pz,E) at the true start of the particle
vector< double > fADEDep
Energy deposited in CRT strip (GeV)
vector< vector< double > > fGenEndXYZT
float fSimTrackHitStart[4]
vector< vector< double > > fCDpe
4-momentum
int fSimPDG
PDG ID of the particle being processed.
static const int LAR_PROP_DELAY
float fZHit
reconstructed Z position of CRT hit (cm)
vector< vector< double > > fCDSlopes
direction cosines
art::InputTag fCRTSimTrackProducerLabel
vector< double > fRegDistToOpDet
vector< double > fRegEDep
int fADC[64]
signal amplitude
vector< vector< double > > fRegEntryPE
uint32_t fTrueNHit
number of CRT hits for this event
vector< vector< double > > fADEnterPE
4-position of entry into CRT strip
bool InFiducialY(double y, double neg_margin, double pos_margin) const
Returns whether TPC fiducial volume contains world y coordinate.
int fT1
signal time w.r.t. PPS
string GetAuxDetRegion(size_t adid)
float fTrueXHit
reconstructed X position of CRT hit (cm)
int fFEBReg
CRT region for this front-end board.
vector< uint32_t > fAuxDetReg
CRT region code.
float fEndXYZT[4]
(x,y,z,t) of the true end of the particle
float fXHitErr
stat error of CRT hit reco X (cm)
vector< int > fTrackID
track ID(s) of particle that produced the signal
const TPCGeo & TPC(unsigned int itpc) const
Return the itpc'th TPC in the cryostat.
float fYHitErr
stat error of CRT hit reco Y (cm)
vector< int > fRegRegions
vector< vector< double > > fADExitXYZT
4-position of exit from CRT strip
vector< int > fTrueHitTrk
int MacToTypeCode(uint8_t mac)
int ChannelToAuxDetSensitiveID(uint8_t mac, int chan)
vector< float > fMaxMomenta
vector< vector< double > > fRegEntrySlope
int fSimEndProcess
process the killed the particle (e.g. annihilation)
std::vector< int > AllTrueIds(const art::Event &event, const CRTData &data)
float fTrueT1Hit
hit time w.r.t. global event time
float fStartXYZT[4]
(x,y,z,t) of the true start of the particle
art::InputTag fCRTSimHitProducerLabel
The name of the producer that created hits.
float fT0Hit
hit time w.r.t. global event time
bool InFiducialX(double x, double neg_margin, double pos_margin) const
Returns whether TPC fiducial volume contains world x coordinate.
vector< int > fRegOpDetID
float fTrueZHit
reconstructed Z position of CRT hit (cm)
vector< uint32_t > fADType
bool InFiducialZ(double z, double neg_margin, double pos_margin) const
Returns whether TPC fiducial volume contains world z coordinate.
vector< vector< double > > fADExitPE
4-position of exit from CRT strip
float fTrueT0Hit
hit time w.r.t. global event time
vector< vector< double > > fGenStartPE
vector< vector< double > > fRegExitXYZT
bool ContainsPosition(geo::Point_t const &point, double wiggle=1.0) const
Returns whether this volume contains the specified point.
BEGIN_PROLOG could also be cout
vector< vector< double > > fRegOpDetXYZT
vector< uint32_t > fAuxDetSensitiveID
Strip ID in module.
vector< vector< double > > fGenEndPE