751 {
752
753
754 if (hitlist.empty())
755 return true;
756
757
758 static double unknown = -1.0e99;
759 double mom(unknown),
time(unknown);
760 if (p) {
762 if (v) {
764 time =
v->position().t()/CLHEP::c_light;
765
766 }
767 }
768
769
770
771
772
773 bool sawhitwithoutmominfo(false);
774 bool sawhitwithmominfo(mom!=unknown);
775 SimHitList::iterator
it(hitlist.begin()),
itE(hitlist.end());
777 const bool hasinfo =
it->second->momentum()>=0.0;
778 if (hasinfo)
779 sawhitwithmominfo = true;
780 else
781 sawhitwithoutmominfo = true;
782 if (sawhitwithoutmominfo&&sawhitwithmominfo)
783 break;
784 }
785
786 if (!sawhitwithoutmominfo) {
787
788 return true;
789 }
790 if (!sawhitwithmominfo) {
791
792 theclass->messageDebug(
"Discarding hitlist." );
793 SimHitList::iterator
it(hitlist.begin()),
itE(hitlist.end());
796 hitlist.clear();
797 return false;
798 }
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814 if (mom==unknown) {
815 if (hitlist.at(0).second->momentum()<0.0) {
816 SimHitList::iterator
it(hitlist.begin()),
itE(hitlist.end());
818 if (
it->second->momentum()>=0.0) {
819 hitlist.at(0).second->setFakeMomentum(
it->second->momentum()*1.00001);
820 break;
821 }
822 }
823 if (hitlist.at(0).second->momentum()<0.0) {
824 theclass->messageDebug(
"fixMomentumInfoInSimHits ERROR: Should not happen! (1)" );
825
826 return false;
827 }
828 }
829 mom = hitlist.at(0).second->momentum();
830 time = hitlist.at(0).second->hitTime();
831 }
832
833
834
835
836
837
838 unsigned ilast = hitlist.size()-1;
839 if (hitlist.at(ilast).second->momentum()<0.0) {
840 for (int iLastWithMom = ilast-1;iLastWithMom>=0;--iLastWithMom) {
841 if (hitlist.at(iLastWithMom).second->momentum()>0.0) {
842 hitlist.at(ilast).second->setFakeMomentum(hitlist.at(iLastWithMom).second->momentum()*0.99999);
843 break;
844 }
845 }
846 if (hitlist.at(ilast).second->momentum()<0.0) {
847
848 if (mom==unknown) {
849 theclass->messageDebug(
"fixMomentumInfoInSimHits ERROR: Should not happen! (2)" );
850
851 return false;
852 }
853 hitlist.at(ilast).second->setFakeMomentum(mom*0.99999);
854 }
855 }
856
857
858 if (mom==unknown||time==unknown) {
859
860 mom = hitlist.at(0).second->momentum();
861 time = hitlist.at(0).second->hitTime();
862 }
863
864 unsigned iNextWithMom(0);
865 for (
unsigned i = 0;
i < hitlist.size(); ++
i) {
866 if (hitlist.at(i).second->momentum()>=0.0) {
867 mom = hitlist.at(i).second->momentum();
868 time = hitlist.at(i).second->hitTime();
869 continue;
870 }
871 if (iNextWithMom<=i) {
872 for (unsigned j = i+1;j<hitlist.size();++j) {
873 if (hitlist.at(j).second->momentum()>=0.0) {
874 iNextWithMom = j;
875 break;
876 }
877 }
878 if (iNextWithMom<=i) {
879 theclass->messageDebug(
"fixMomentumInfoInSimHits ERROR: Should not happen! (3)" );
880
881 return false;
882 }
883 }
884
885 double time2 = hitlist.at(iNextWithMom).second->hitTime();
886 double mom2 = hitlist.at(iNextWithMom).second->momentum();
887 double t = hitlist.at(i).second->hitTime();
888
889
890 if (t<=time||t>=time2||time2<=time)
891 theclass->message(
"SUSPICIOUS TIME");
892 if (mom2>=mom)
893 theclass->message(
"SUSPICIOUS MOM mom="+
str(mom)+
", mom2="+
str(mom2));
896 hitlist.at(i).second->setFakeMomentum(mom);
897 }
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953 return true;
954
955}
Scalar mag() const
mag method
time(flags, cells_name, *args, **kw)
const HepMC::GenVertex * ConstGenVertexPtr