19 std::vector< art::Ptr< beam::ProtoDUNEBeamEvent > > beamVec;
21 if( beamHandle.isValid() ){
31 std::vector<art::Ptr<beam::ProtoDUNEBeamEvent>> beamVec;
32 if( beamHandle.isValid()){
46 std::vector<art::Ptr<beam::ProtoDUNEBeamEvent>> beamVec;
47 if( beamHandle.isValid()){
54 for(
size_t i = 0; i <
AllDevices.size(); ++i ){
60 std::cout << monitor <<
" has active fibers: " <<
std::endl;
61 for(
size_t j = 0; j <
ActiveFibers.at(monitor).size(); ++j ){
67 std::cout << monitor <<
" has no active fibers" <<
std::endl;
74 std::vector< recob::Track >
tracks;
86 all_good = ( ( HorizUpstreamFibers.size() > 0 ) && ( VertUpstreamFibers.size() > 0 )
87 && ( HorizDownstreamFibers.size() > 0 ) && ( VertDownstreamFibers.size() > 0 ) );
90 std::cout <<
"At least one empty monitor. Producing no track" <<
std::endl;
95 std::vector< std::pair<short, short> > UpstreamPairedFibers;
96 std::vector< std::pair<short, short> > DownstreamPairedFibers;
98 std::vector< TVector3 > UpstreamPositions;
99 std::vector< TVector3 > DownstreamPositions;
101 for(
size_t iH = 0; iH < HorizUpstreamFibers.size(); ++iH){
103 size_t HorizFiber = HorizUpstreamFibers[iH];
105 for(
size_t iV = 0; iV < VertUpstreamFibers.size(); ++iV){
106 size_t VertFiber = VertUpstreamFibers[iV];
109 std::cout <<
"Paired: " << HorizFiber <<
" " << VertFiber <<
std::endl;
110 UpstreamPairedFibers.push_back(std::make_pair(HorizFiber, VertFiber));
114 if (iV < VertUpstreamFibers.size() - 1){
115 if (VertUpstreamFibers[iV] == (VertUpstreamFibers[iV + 1] - 1)) ++iV;
119 if (iH < HorizUpstreamFibers.size() - 1){
120 if (HorizUpstreamFibers[iH] == (HorizUpstreamFibers[iH + 1] - 1)) ++iH;
126 for(
size_t i = 0; i < UpstreamPairedFibers.size(); ++i){
128 std::pair<short,short> thePair = UpstreamPairedFibers.at(i);
133 std::cout <<
"normal " << xPos <<
" " << yPos <<
std::endl;
135 std::cout << posInDet.X() <<
" " << posInDet.Y() <<
" " << posInDet.Z() <<
std::endl;
136 UpstreamPositions.push_back( posInDet );
139 for(
size_t iH = 0; iH < HorizDownstreamFibers.size(); ++iH){
141 size_t HorizFiber = HorizDownstreamFibers[iH];
143 for(
size_t iV = 0; iV < VertDownstreamFibers.size(); ++iV){
144 size_t VertFiber = VertDownstreamFibers[iV];
147 std::cout <<
"Paired: " << HorizFiber <<
" " << VertFiber <<
std::endl;
148 DownstreamPairedFibers.push_back(std::make_pair(HorizFiber, VertFiber));
152 if (iV < VertDownstreamFibers.size() - 1){
153 if (VertDownstreamFibers[iV] == (VertDownstreamFibers[iV + 1] - 1)) ++iV;
157 if (iH < HorizDownstreamFibers.size() - 1){
158 if (HorizDownstreamFibers[iH] == (HorizDownstreamFibers[iH + 1] - 1)) ++iH;
164 for(
size_t i = 0; i < DownstreamPairedFibers.size(); ++i){
166 std::pair<short,short> thePair = DownstreamPairedFibers.at(i);
171 std::cout <<
"normal " << xPos <<
" " << yPos <<
std::endl;
173 std::cout << posInDet.X() <<
" " << posInDet.Y() <<
" " << posInDet.Z() <<
std::endl;
174 DownstreamPositions.push_back( posInDet );
177 for(
size_t iU = 0; iU < UpstreamPositions.size(); ++iU){
178 for(
size_t iD = 0; iD < DownstreamPositions.size(); ++iD){
179 std::vector<TVector3> thePoints;
180 thePoints.push_back(UpstreamPositions.at(iU));
181 thePoints.push_back(DownstreamPositions.at(iD));
184 thePoints.push_back(
ProjectToTPC(thePoints[0],thePoints[1]) );
185 std::cout <<
"Projected: " << thePoints.back().X() <<
" " << thePoints.back().Y() <<
" " << thePoints.back().Z() <<
std::endl;
188 std::vector<TVector3> theMomenta;
190 theMomenta.push_back( ( DownstreamPositions.at(iD) - UpstreamPositions.at(iU) ).Unit() );
191 theMomenta.push_back( ( DownstreamPositions.at(iD) - UpstreamPositions.at(iU) ).Unit() );
192 theMomenta.push_back( ( DownstreamPositions.at(iD) - UpstreamPositions.at(iU) ).Unit() );
198 tracks.push_back( tempTrack );
226 L1 = p.
get<
double>(
"L1");
227 L2 = p.
get<
double>(
"L2");
228 L3 = p.
get<
double>(
"L3");
244 return 1.*(96 - theFiber) - .5;
263 TVector3
result(newX/10., newY/10., newZ/10.);
287 TVector3 dR = (secondPoint - firstPoint);
289 double deltaZ = -1.*secondPoint.Z();
290 double deltaX = deltaZ * (dR.X() / dR.Z());
291 double deltaY = deltaZ * (dR.Y() / dR.Z());
293 TVector3 lastPoint = secondPoint + TVector3(deltaX, deltaY, deltaZ);
303 std::vector< double > theMomenta;
306 std::cout <<
"Warning! Low magnet current. Momentum spectrometry invalid. Returning empty momenta vector." <<
std::endl;
323 std::cout <<
BProf1 <<
" has " << BProf1Fibers.size() <<
" active fibers" <<
std::endl;
324 for(
size_t i = 0; i < BProf1Fibers.size(); ++i){
325 std::cout << BProf1Fibers[i] <<
" ";
329 std::cout <<
BProf2 <<
" has " << BProf2Fibers.size() <<
" active fibers" <<
std::endl;
330 for(
size_t i = 0; i < BProf2Fibers.size(); ++i){
331 std::cout << BProf2Fibers[i] <<
" ";
335 std::cout <<
BProf3 <<
" has " << BProf3Fibers.size() <<
" active fibers" <<
std::endl;
336 for(
size_t i = 0; i < BProf3Fibers.size(); ++i){
337 std::cout << BProf3Fibers[i] <<
" ";
342 if( (BProf1Fibers.size() < 1) || (BProf2Fibers.size() < 1) || (BProf3Fibers.size() < 1) ){
343 std::cout <<
"Warning, at least one empty Beam Profiler. Not checking momentum" <<
std::endl;
348 std::cout <<
"Getting all trio-wise hits" <<
std::endl;
349 std::cout <<
"N1,N2,N3 " << BProf1Fibers.size()
350 <<
" " << BProf2Fibers.size()
351 <<
" " << BProf3Fibers.size() <<
std::endl;
353 for(
size_t i1 = 0; i1 < BProf1Fibers.size(); ++i1){
359 if (i1 < BProf1Fibers.size() - 1){
360 if (BProf1Fibers[i1] == (BProf1Fibers[i1 + 1] - 1)){
366 for(
size_t i2 = 0; i2 < BProf2Fibers.size(); ++i2){
370 if (i2 < BProf2Fibers.size() - 1){
371 if (BProf2Fibers[i2] == (BProf2Fibers[i2 + 1] - 1)){
377 for(
size_t i3 = 0; i3 < BProf3Fibers.size(); ++i3){
379 std::cout <<
"\t" << i1 <<
" " << i2 <<
" " << i3 <<
std::endl;
383 if (i3 < BProf3Fibers.size() - 1){
384 if (BProf3Fibers[i3] == (BProf3Fibers[i3 + 1] - 1)){
397 double momentum = 299792458*LB/(1.E9 * acos(cosTheta));
399 theMomenta.push_back(momentum);
401 if (i3 < BProf3Fibers.size() - 1){
402 if (BProf3Fibers[i3] == (BProf3Fibers[i3 + 1] - 1)){
410 if (i2 < BProf2Fibers.size() - 1){
411 if (BProf2Fibers[i2] == (BProf2Fibers[i2 + 1] - 1)){
418 if (i1 < BProf1Fibers.size() - 1){
419 if (BProf1Fibers[i1] == (BProf1Fibers[i1 + 1] - 1)){
435 double denomTerm1, denomTerm2, denom;
436 denomTerm1 = sqrt(
L1*
L1 + (a - X1)*(a - X1) );
438 + TMath::Power( ( (
L3 -
L2) ),2) );
439 denom = denomTerm1 * denomTerm2;
441 double cosTheta = numTerm/denom;
451 for(
size_t iBeamEvent=0; iBeamEvent < beamHand->size(); iBeamEvent++)
461 std::vector< int > thePIDs = thePIDCands.getPDGCodes();
467 for(
size_t iBeamEvent=0; iBeamEvent < beamHand->size(); iBeamEvent++)
469 return GetPID(beamHand->at(iBeamEvent),nominal_momentum);
471 return std::vector<int>();
479 std::vector< double > valid_momenta = {1., 2., 3., 6., 7.};
480 if( std::find(valid_momenta.begin(), valid_momenta.end(), nominal_momentum) == valid_momenta.end() ){
481 std::cout <<
"Reference momentum " << nominal_momentum <<
" not valid" <<
std::endl;
503 if( nominal_momentum == 1. ){
508 if( low_pressure_status == -1 ){
509 std::cout <<
"High pressure status invalid" <<
std::endl;
513 const double & tof = beamevt.
GetTOF();
517 && low_pressure_status == 1
524 && low_pressure_status == 0 ){
525 candidates.
muon =
true;
526 candidates.
pion =
true;
531 && low_pressure_status == 0 ) {
535 else if( nominal_momentum == 2. ){
540 if( low_pressure_status == -1 ){
541 std::cout <<
"High pressure Cerenkov status invalid" <<
std::endl;
545 const double & tof = beamevt.
GetTOF();
549 && low_pressure_status == 1
556 && low_pressure_status == 0 ){
557 candidates.
muon =
true;
558 candidates.
pion =
true;
563 && low_pressure_status == 0 ) {
567 else if( nominal_momentum == 3. ){
568 if( high_pressure_status == -1 || low_pressure_status == -1 ){
569 std::cout <<
"At least one Cerenkov status invalid " <<
std::endl;
570 std::cout <<
"High: " << high_pressure_status <<
" Low: " << low_pressure_status <<
std::endl;
573 else if ( low_pressure_status == 1 && high_pressure_status == 1 )
576 else if ( low_pressure_status == 0 && high_pressure_status == 1 ){
577 candidates.
muon =
true;
578 candidates.
pion =
true;
583 candidates.
kaon =
true;
586 else if( nominal_momentum == 6. || nominal_momentum == 7. ){
587 if( high_pressure_status == -1 || low_pressure_status == -1 ){
588 std::cout <<
"At least one Cerenkov status invalid " <<
std::endl;
589 std::cout <<
"High: " << high_pressure_status <<
" Low: " << low_pressure_status <<
std::endl;
592 else if ( low_pressure_status == 1 && high_pressure_status == 1 ){
594 candidates.
muon =
true;
595 candidates.
pion =
true;
597 else if ( low_pressure_status == 0 && high_pressure_status == 1 )
598 candidates.
kaon =
true;
610 std::vector< int > thePIDs = thePIDCands.getPDGCodes();
615 if( momentum < .0000001 ){
616 std::cout <<
"Low Momentum" <<
std::endl;
621 std::cout <<
"PDG " << pdg <<
" not found" <<
std::endl;
627 tof = tof / sqrt( 1. - m*m / (momentum*momentum + m*m) );
633 if( tof < .0000001 ){
639 std::cout <<
"PDG " << pdg <<
" not found" <<
std::endl;
665 std::vector< short > fibers_p1 = beamEvent.
GetActiveFibers(
"XBPF022697" );
666 std::vector< short > fibers_p2 = beamEvent.
GetActiveFibers(
"XBPF022701" );
667 std::vector< short > fibers_p3 = beamEvent.
GetActiveFibers(
"XBPF022702" );
670 std::array< short, 192 > glitch_mask = beamEvent.
GetFBM(
"XBPF022697" ).
glitch_mask;
672 for(
size_t i = 0; i < fibers_p1.size(); ++i ){
673 if( !glitch_mask[ fibers_p1[i] ] )
679 for(
size_t i = 0; i < fibers_p2.size(); ++i ){
680 if( !glitch_mask[ fibers_p2[i] ] )
686 for(
size_t i = 0; i < fibers_p3.size(); ++i ){
687 if( !glitch_mask[ fibers_p3[i] ] )
691 return ( nP1 == 1 && nP2 == 1 && nP3 == 1 );
696 std::vector<double>
result;
699 for (
const auto & massSquared: massSquareds)
701 const auto & mass = std::sqrt(massSquared);
702 result.push_back(mass);
708 std::vector<double> tofs;
709 std::vector<double> momenta;
710 std::vector<double>
result;
712 std::vector<art::Ptr<beam::ProtoDUNEBeamEvent>> beamVec;
714 if(beamHand.isValid())
719 for(
size_t iBeamEvent=0; iBeamEvent < beamVec.size(); iBeamEvent++)
722 tofs.push_back(beamEvent.
GetTOF());
725 for(
size_t iMom=0; iMom < beamMomenta.size(); iMom++)
730 for(
const auto & tof : tofs)
732 for(
const auto &
momentum : momenta)
736 result.push_back(massSquared);
745 double tof = -99999.;
749 std::vector<art::Ptr<beam::ProtoDUNEBeamEvent>> beamVec;
751 if(beamHand.isValid())
755 for(
size_t iBeamEvent=0; iBeamEvent < beamVec.size(); iBeamEvent++)
763 if (beamMomenta.size() > 0)
768 return std::make_tuple(momentum, tof, ckov0, ckov1);
774 double tof = -99999.;
775 int tofChannel = -99999.;
778 double ckov0Pressure = -99999.;
779 double ckov1Pressure = -99999.;
780 int timingTrigger = -99999.;
781 int BITrigger = -99999.;
782 bool areBIAndTimingMatched =
false;
784 std::vector<art::Ptr<beam::ProtoDUNEBeamEvent>> beamVec;
786 if(beamHand.isValid())
790 for(
size_t iBeamEvent=0; iBeamEvent < beamVec.size(); iBeamEvent++)
804 if (beamMomenta.size() > 0)
810 return std::make_tuple(momentum, tof, tofChannel, ckov0, ckov1, ckov0Pressure, ckov1Pressure, timingTrigger, BITrigger, areBIAndTimingMatched);
float fMomentumScaleFactor
std::string HorizDownstream
const FBM & GetFBM(std::string) const
PossibleParticleCands GetPIDCandidates(beam::ProtoDUNEBeamEvent const &beamevt, double nominal_momentum)
std::vector< std::string > AllDevices
const int & GetTimingTrigger() const
double GetPosition(short)
ROOT::Math::SMatrix< Double32_t, 5, 5, ROOT::Math::MatRepSym< Double32_t, 5 > > SMatrixSym55
std::vector< Vector_t > convertCollToVector(std::vector< Vector > const &coll)
double fSecondTrackingProfZ
const double & GetCKov0Pressure() const
TVector3 ProjectToTPC(TVector3, TVector3)
const short & GetCKov1Status() const
TrackTrajectory::Flags_t Flags_t
const std::tuple< double, double, int, int, int, double, double, int, int, bool > GetBeamlineVarsAndStatus(art::Event const &evt) const
double MomentumCosTheta(double, double, double)
bool HasPerfectBeamMomentum(art::Event const &evt) const
std::string VertDownstream
art::InputTag fBeamEventTag
std::vector< double > GetBeamlineMassSquared(art::Event const &evt) const
ProtoDUNEBeamlineUtils(fhicl::ParameterSet const &pset)
std::string HorizUpstream
std::vector< double > GetBeamlineMass(art::Event const &evt) const
double ComputeMomentum(int pdg, double tof)
const std::tuple< double, double, int, int > GetBeamlineVars(art::Event const &evt) const
void RotateMonitorVector(TVector3 &)
const std::vector< short > & GetActiveFibers(std::string) const
void GetFibers(art::Event const &evt)
const std::vector< double > & GetRecoBeamMomenta() const
A trajectory in space reconstructed from hits.
const double & GetTOF() const
T get(std::string const &key) const
std::map< int, double > particle_mass
PossibleParticleCands GetPIDCandidates_CERNCalib(beam::ProtoDUNEBeamEvent const &beamevt, double nominal_momentum)
std::vector< double > MomentumSpec(art::Event const &evt)
~ProtoDUNEBeamlineUtils()
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
std::vector< Point_t > convertCollToPoint(std::vector< Point > const &coll)
bool IsGoodBeamlineTrigger(art::Event const &evt) const
void GetCurrent(art::Event const &evt)
double fFirstTrackingProfZ
void reconfigure(fhicl::ParameterSet const &pset)
bool fUseCERNCalibSelection
std::vector< int > GetPID(beam::ProtoDUNEBeamEvent const &beamevt, double nominal_momentum)
TVector3 ConvertMonitorCoordinates(double, double, double, double)
double ComputeTOF(int pdg, double momentum)
std::array< short, 192 > glitch_mask
const short & GetCKov0Status() const
const int & GetBITrigger() const
std::map< std::string, std::vector< short > > ActiveFibers
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
std::vector< int > GetPID_CERNCalib(beam::ProtoDUNEBeamEvent const &beamevt, double nominal_momentum)
def momentum(x1, x2, x3, scale=1.)
const double & GetRecoBeamMomentum(size_t i) const
const double & GetMagnetCurrent() const
const bool & CheckIsMatched() const
const int & GetTOFChan() const
std::vector< recob::Track > MakeTracks(art::Event const &evt)
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
const beam::ProtoDUNEBeamEvent GetBeamEvent(art::Event const &evt) const
QTextStream & endl(QTextStream &s)
void BeamMonitorBasisVectors()
const double & GetCKov1Pressure() const