set some configuration parameters that can be set from the command line - these over-ride those from the configuration file Fixme: which is best? set them from the command line first, and then ignore them in the config file, or set from the config file, and then override them with command line arguments later? Theres only one way to find out...
true by default - command line options sets to false so should override what is in the config file
here we set a pTMax value less than pT, then only set the max pT in the filter if we read a pTMax value greater than pT
new code - can extract vtx name, pt, any extra options that we want, but also chop off everythiung after :post
track selectors so we can select multiple times with different filters if we want (simpler then looping over vectors each time
create a map of the name to analysis string for selecting the correct analysis from the chain name
create the analyses and initialise them - this will create a root directory and book all the histograms
try not exiting if ref chain is different from default, temporarily ...
now we know that there is a corresponding tag, we can add the probe ...
if matching tag found then initialise tag and probe object and store tag and probe chains in there this will be passed into the ConfAnalysis, which will delete it when necessary
could perhaps be done with a unique_ptr
useful debug - leave this here ...
don't use the vertex name as the directory, since then we cannot easily plot on the same plot
When setting different pt cuts, then an additional track selector will need to be created, this can then be added to the TIDA::FeatireStore of the analysis, and retrieved each time it is required
still needed for the moment ...
Determine what sort of matching is required ...
I don't prefer range based for loops ...
get the tracks from the reference chain - shouldn't be one of the test chains, since there will be a 1-to-1 mapping but might be a useful check
leave this in for the moment ...
both legs have the same reference ...
different references for each leg ...
tag leg reference ...
do we want to filter on the RoI properties? If so, if the RoI fails the cuts, then skip this roi
here we set the roi for the filter so we can request only those tracks inside the roi
what is all this logic doing ? It looks needlessly convoluted, and should at the very least have some proper explanation of what it is supposed to be doing
get the truth particles ...
check configuration is provided ...
if requesting an object match, remove any tracks which correspond to an object below the object PT threshold
do for all vertices now ...
don't add vertices with no matching tracks - remember the tracks are filtered by Roi already so some vertices may have no tracks in the Roi - ntracks set to 0 by default
NB: because ntracks = 0 by default, this second clause should always be true unless ntracks has been set to some value
so we now use a handy wrapper function to do the conversion for us ...
522{
528
529
530
531 if ( argc<2 ) {
532 std::cerr << "Error: no config file specified\n" << std::endl;
533 return usage(argv[0], -1);
534 }
535
536
537
545
546 std::cout << "$0 :: compiled " << __DATE__ << " " << __TIME__ << std::endl;
547
549
550 std::string histofilename("");
551
552 std::string datafile = "";
553
554 std::vector<std::string> refChains(0);
555
556 std::vector<TrackFilter*> refFilters(0);
557
560
561 std::string refChain = "";
562
564
565 std::vector<std::string> testChains;
566
567 std::string binningConfigFile = "";
568
569 bool useoldrms = true;
570 bool nofit = false;
571
572 std::string vertexSelection = "";
573 std::string vertexSelection_rec = "";
574
575 unsigned Nentries = 0;
576
577 for (
int i=1 ;
i<
argc ;
i++ ) {
578 if ( std::string(argv[i])=="-h" || std::string(argv[i])=="--help" ) {
579 return usage(argv[0], 0);
580 }
581 else if ( std::string(argv[i])=="-e" || std::string(argv[i])=="--entries" ) {
582 if ( ++i>=argc )
return usage(argv[0], -1);
583 Nentries = std::atoi(argv[i]);
584 }
585 else if ( std::string(argv[i])=="-o" || std::string(argv[i])=="-f" || std::string(argv[i])=="--file" ) {
586 if ( ++i>=argc )
return usage(argv[0], -1);
587 histofilename =
argv[
i];
588 if ( histofilename.find(".root")==std::string::npos ) histofilename += ".root";
589 }
590 else if ( std::string(argv[i])=="-r" || std::string(argv[i])=="--refChain" ) {
591 if ( ++i>=argc )
return usage(argv[0], -1);
593
594
595 if (refChain.find("+") != string::npos){
596 std::istringstream iss(refChain);
597 std::string token;
598 while (std::getline(iss, token, '+')){
599 refChains.push_back(token);
600 refFilters.push_back(0);
601 }
602 }
603 else {
604 refChains.push_back(argv[i]);
605 refFilters.push_back(0);
606 }
607 }
608 else if ( std::string(argv[i])=="--rms" ) useoldrms = false;
609 else if ( std::string(argv[i])=="-n" || std::string(argv[i])=="--nofit" ) nofit = true;
610 else if ( std::string(argv[i])=="-t" || std::string(argv[i])=="--testChain" ) {
611 if ( ++i>=argc )
return usage(argv[0], -1);
612 testChains.push_back(argv[i]);
613 }
614 else if ( std::string(argv[i])=="-p" || std::string(argv[i])=="--pdgId" ) {
615 if ( ++i>=argc )
return usage(argv[0], -1);
617 }
618 else if ( std::string(argv[i])=="--vr" ) {
619 if ( ++i>=argc )
return usage(argv[0], -1);
620 vertexSelection =
argv[
i];
621 }
622 else if ( std::string(argv[i])=="--vt" ) {
623 if ( ++i>=argc )
return usage(argv[0], -1);
624 vertexSelection_rec =
argv[
i];
625 }
626 else if ( std::string(argv[i])=="-b" || std::string(argv[i])=="--binConfig" ) {
627 if ( ++i>=argc )
return usage(argv[0], -1);
628 binningConfigFile = std::string(argv[i]);
629 }
630 else if ( std::string(argv[i]).
find(
'-')==0 ) {
632 std::cerr <<
"unknown option " <<
argv[
i] << std::endl;
633 return usage(argv[0], -1);
634 }
635 else {
637 }
638 }
639
640
641
642 if ( datafile=="" ) {
643 std::cerr << "no config file specifed\n" << endl;
644 return usage(argv[0], -1);
645 }
646
647 std::cout <<
time_str() << std::endl;
648
650
652
655 if ( useoldrms ) {
656 bool oldrms95 = true;
657 inputdata.declareProperty(
"OldRMS95", oldrms95 );
658 std::cout << "setting Resplot old rms95 " << oldrms95 << std::endl;
660 }
661 else {
662 std::cout << "setting Resplot old rms95 " << useoldrms << std::endl;
664 }
665
666
667 if ( nofit ) {
668 std::cout << "Not fitting resplots " << std::endl;
670 }
671
672
673 unsigned nfiles = 0;
674 inputdata.declareProperty(
"NFiles", nfiles );
675
676
677 if ( histofilename=="" ){
678 if (
inputdata.isTagDefined(
"outputFile") ) histofilename =
inputdata.GetString(
"outputFile");
679 else {
680 std::cerr << "Error: no output file defined\n" << std::endl;
681 return usage(argv[0], -1);
682 }
683 }
684
686 TFile foutput( histofilename.c_str(), "recreate" );
687 if (!foutput.IsOpen()) {
688 std::cerr << "Error: could not open output file\n" << std::endl;
689 return -1;
690 }
691
693
694 std::cout << "writing output to " << histofilename << std::endl;
695
696 TH1D* hevent = new TH1D( "event", "event", 1000, 10000, 80000 );
697 Resplot* hcorr =
new Resplot(
"correlation", 21, -0.5, 20.5, 75, 0, 600);
698
700
703 double zed = 2000;
704
705 double a0min=0.;
706
707 int npix = 1;
708 int nsct = 6;
709 int nbl = -1;
710
711 int nsiholes = 2;
712 int npixholes = 20;
713 int nsctholes = 20;
714
715 bool expectBL = false;
716
717 double chi2prob = 0;
718
719 int npix_rec = -2;
720 int nsct_rec = -2;
721
722 double pT_rec = 0;
723 double eta_rec = 5;
724
725 double Rmatch = 0.1;
726
727 int ntracks = 0;
728
729 double massMax = 130;
730 double massMin = 50;
731
732
733
734 bool rotate_testtracks = false;
735
736 if (
inputdata.isTagDefined(
"RotateTestTracks") ) rotate_testtracks = (
inputdata.GetValue(
"RotateTestTracks") ?
true :
false );
737
738 bool truthMatch = false;
739
740 if (
inputdata.isTagDefined(
"TruthMatch") ) truthMatch = (
inputdata.GetValue(
"TruthMatch") ?
true :
false );
741
742
743
744
745 std::vector<size_t> refPtOrd_indices;
746 bool use_pt_ordered_ref = false;
747
748 if (
inputdata.isTagDefined(
"UsePtOrderedRefTracks") ) {
749 std::vector<double> refPtOrd_indices_tmp;
750
751 use_pt_ordered_ref = true;
752 refPtOrd_indices_tmp = (
inputdata.GetVector(
"UsePtOrderedRefTracks") );
753
754 std::cout << "using PT ordered reference tracks: " << refPtOrd_indices_tmp << std::endl;
755
756 for ( size_t i=refPtOrd_indices_tmp.size(); i-- ; ) {
757 refPtOrd_indices.push_back( refPtOrd_indices_tmp.at(i) );
758 }
759 }
760
764
769
770
772
773
779 if (
inputdata.isTagDefined(
"npixholes") ) npixholes =
inputdata.GetValue(
"npixholes");
780 if (
inputdata.isTagDefined(
"nsctholes") ) nsctholes =
inputdata.GetValue(
"nsctholes");
781 if (
inputdata.isTagDefined(
"expectBL") ) expectBL = (
inputdata.GetValue(
"expectBL") > 0.5 ?
true :
false );
785
787
788
790
793
794 if (
inputdata.isTagDefined(
"InvMassMax") ) massMax =
inputdata.GetValue(
"InvMassMax");
795 if (
inputdata.isTagDefined(
"InvMassMin") ) massMin =
inputdata.GetValue(
"InvMassMin");
796
799
802
805
807
808 std::string useMatcher = "DeltaR";
809 if (
inputdata.isTagDefined(
"UseMatcher") ) useMatcher =
inputdata.GetString(
"UseMatcher");
810
811
813 if ( refChain=="" ) {
814 if (
inputdata.isTagDefined(
"refChain") ) {
815 refChain =
inputdata.GetString(
"refChain");
816 refChains.push_back(refChain);
817 refFilters.push_back(0);
818 }
819 else {
820 std::cerr << "Error: no reference chain defined\n" << std::endl;
821
822 return -1;
823 }
824 }
825
827
829
830 if (
inputdata.isTagDefined(
"Exclude") ) {
833 }
834
835 if (refChains.size() == 0){
836 std::cerr << "Error: refChains is empty\n" <<std::endl;
837 return -1;
838 }
839
841 if ( testChains.size()==0 ) {
842 if (
inputdata.isTagDefined(
"testChains") ) testChains =
inputdata.GetStringVector(
"testChains");
843 else if (
inputdata.isTagDefined(
"testChain") ) testChains.push_back(
inputdata.GetString(
"testChain") );
844 }
845
848
849 std::vector<ChainString> chainConfig;
850
851 for (
size_t ic=0 ;
ic<testChains.size() ;
ic++ ) {
852 chainConfig.push_back(
ChainString( testChains[ic] ) );
853 testChains[
ic] = chainConfig.back().pre();
854 }
855
856
858
859
861
862
864 bool select_roi = true;
865
866
867
868
869
870 bool use_custom_ref_roi = false;
871 const int custRefRoi_nParams = 3;
872
873 double custRefRoi_params[custRefRoi_nParams] = {-999., -999., -999.};
874 std::vector<std::string> custRefRoi_chainList;
875 std::set<std::string> customRoi_chains;
876
877 if (
inputdata.isTagDefined(
"customRefRoi_etaHalfWidth") ) custRefRoi_params[0] =
inputdata.GetValue(
"customRefRoi_etaHalfWidth");
878 if (
inputdata.isTagDefined(
"customRefRoi_phiHalfWidth") ) custRefRoi_params[1] =
inputdata.GetValue(
"customRefRoi_phiHalfWidth");
879 if (
inputdata.isTagDefined(
"customRefRoi_zedHalfWidth") ) custRefRoi_params[2] =
inputdata.GetValue(
"customRefRoi_zedHalfWidth");
880
881 if (
inputdata.isTagDefined(
"customRefRoi_chainList") ) custRefRoi_chainList =
inputdata.GetStringVector(
"customRefRoi_chainList");
882
883 for (
unsigned ic=0 ;
ic<custRefRoi_chainList.size() ;
ic++ ) customRoi_chains.insert( custRefRoi_chainList[ic] );
884
885 for ( int param_idx=0 ; param_idx<custRefRoi_nParams ; param_idx++ ) {
886 if ( custRefRoi_params[param_idx] != -999 ) {
887 select_roi = true;
888 use_custom_ref_roi = true;
889 }
890 }
891
892 if ( use_custom_ref_roi ) {
893 std::cout << "**** \t****" << std::endl;
894 std::cout << "**** Custom RoI will be used to filter ref. tracks\t****" << std::endl;
895
896 if ( custRefRoi_params[0] != -999. ) std::cout << "**** etaHalfWidth = " << custRefRoi_params[0] << "\t\t\t\t****" << std::endl;
897 else std::cout << "**** etaHalfWidth = value used in trigger RoI\t****" << std::endl;
898
899 if ( custRefRoi_params[1] != -999. ) std::cout << "**** phiHalfWidth = " << custRefRoi_params[1] << "\t\t\t\t****" << std::endl;
900 else std::cout << "**** phiHalfWidth = value used in trigger RoI\t****" << std::endl;
901
902 if ( custRefRoi_params[2] != -999. ) std::cout << "**** zedHalfWidth = " << custRefRoi_params[2] << "\t\t\t\t****" << std::endl;
903 else std::cout << "**** zedHalfWidth = value used in trigger RoI\t****" << std::endl;
904
905 if ( !custRefRoi_chainList.empty() ) {
906 std::cout << "**** \t****" << std::endl;
907 std::cout << "**** Applying custom RoI only to specified chains\t****" << std::endl;
908 }
909 std::cout << "**** \t****" << std::endl;
910 }
911
912
913
914 if (
inputdata.isTagDefined(
"SelectRoi") ) {
915 select_roi = (
inputdata.GetValue(
"SelectRoi")!=0 ?
true :
false );
916 }
917
918 if ( !select_roi ) {
919 std::cout << "**** ****" << std::endl;
920 std::cout << "**** RoI filtering of reference tracks is disabled ****" << std::endl;
921 std::cout << "**** ****" << std::endl;
922 }
923
924
925
926
927
928
929
932
933
936 std::vector<std::string> grlvector =
inputdata.GetStringVector(
"GRL");
937 std::cout << "Reading GRL from: " << grlvector << std::endl;
938 for (
size_t igrl=0 ; igrl<grlvector.size() ; igrl++ )
goodrunslist.read( grlvector[igrl] );
939
940 }
941 else if (
inputdata.isTagDefined(
"LumiBlocks") ) {
944
946 goodrunslist.addRange( lumiblocks[i], lumiblocks[i+1], lumiblocks[i+2] );
947 }
948 }
949
950
952
953
954 if ( vertexSelection == "" ) {
955 if (
inputdata.isTagDefined(
"VertexSelection") ) vertexSelection =
inputdata.GetString(
"VertexSelection");
956 }
957
958 bool bestPTVtx = false;
959 bool bestPT2Vtx = false;
960 int vtxind = -1;
961
962 if ( vertexSelection!="" ) {
963 if ( vertexSelection=="BestPT" ) bestPTVtx = true;
964 else if ( vertexSelection=="BestPT2" ) bestPT2Vtx = true;
966 }
967
968
969
970
972
973 if ( vertexSelection_rec == "" ) {
974 if (
inputdata.isTagDefined(
"VertexSelectionRec") ) vertexSelection_rec =
inputdata.GetString(
"VertexSelectionRec");
975 }
976
977 bool bestPTVtx_rec = false;
978 bool bestPT2Vtx_rec = false;
979 int vtxind_rec = -1;
980
981 if ( vertexSelection_rec!="" ) {
982 if ( vertexSelection_rec=="BestPT" ) bestPTVtx_rec = true;
983 else if ( vertexSelection_rec=="BestPT2" ) bestPT2Vtx_rec = true;
984 else vtxind_rec =
atoi_check( vertexSelection_rec );
985 }
986
987 std::cout << "vertexSelection: " << vertexSelection << std::endl;
988 std::cout << "vertexSelection_rec: " << vertexSelection_rec << std::endl;
989
990
991#if 0
992
995
996 bool useBestVertex = false;
997 if (
inputdata.isTagDefined(
"useBestVertex") ) useBestVertex = (
inputdata.GetValue(
"useBestVertex") ? 1 : 0 );
998
999 bool useSumPtVertex = true;
1000 if (
inputdata.isTagDefined(
"useSumPtVertex") ) useSumPtVertex = (
inputdata.GetValue(
"useSumPtVertex") ? 1 : 0 );
1001
1002 int MinVertices = 1;
1003 if (
inputdata.isTagDefined(
"MinVertices") ) MinVertices =
inputdata.GetValue(
"MinVertices");
1004
1006
1007#endif
1008
1010 bool useVertexTracks = false;
1011 if (
inputdata.isTagDefined(
"UseVertexTracks") ) useVertexTracks = (
inputdata.GetValue(
"UseVertexTracks") > 0 );
1012
1013
1014 std::string vertex_refname = "Vertex";
1015 if (
inputdata.isTagDefined(
"VertexReference") ) vertex_refname +=
":" +
inputdata.GetString(
"VertexReference");
1016
1018 int NVtxTrackCut = 2;
1019 if (
inputdata.isTagDefined(
"NVtxTrackCut") ) NVtxTrackCut =
inputdata.GetValue(
"NVtxTrackCut");
1020
1021
1023 bool event_selector_flag = false;
1024
1026
1028
1029 if ( es.size() ) event_selector_flag = true;
1030
1031
1032 std::vector<double> beamTest;
1033 std::vector<double> beamRef;
1034
1035
1036 bool correctBeamlineRef = false;
1037 bool correctBeamlineTest = false;
1038
1039 if (
inputdata.isTagDefined(
"CorrectBeamlineRef") ) correctBeamlineRef = (
inputdata.GetValue(
"CorrectBeamlineRef") == 0 ?
false :
true );
1040 if (
inputdata.isTagDefined(
"CorrectBeamlineTest") ) correctBeamlineTest = (
inputdata.GetValue(
"CorrectBeamlineTest") == 0 ?
false :
true );
1041
1042
1043 if (
inputdata.isTagDefined(
"BeamTest") ) beamTest =
inputdata.GetVector(
"BeamTest");
1044 else {
1045 if (
inputdata.isTagDefined(
"BeamTestx") ) beamTest.push_back(
inputdata.GetValue(
"BeamTestx"));
1046 if (
inputdata.isTagDefined(
"BeamTesty") ) beamTest.push_back(
inputdata.GetValue(
"BeamTesty"));
1047 }
1048
1049
1051 else {
1052 if (
inputdata.isTagDefined(
"BeamRefx") ) beamRef.push_back(
inputdata.GetValue(
"BeamRefx"));
1053 if (
inputdata.isTagDefined(
"BeamRefy") ) beamRef.push_back(
inputdata.GetValue(
"BeamRefy"));
1054 }
1055
1056
1057
1058 if ( ( beamTest.size()!=0 && beamTest.size()!=2 && beamTest.size()!=3 ) ||
1059 ( beamRef.size()!=0 && beamRef.size()!=2 && beamRef.size()!=3 ) ) {
1060 std::cerr << "incorrectly specified beamline position" << std::endl;
1061 return (-1);
1062 }
1063
1064 if ( beamTest.size()>0 ) correctBeamlineTest = true;
1065 if ( beamRef.size()>0 ) correctBeamlineRef = true;
1066
1067 if ( correctBeamlineRef ) std::cout << "main() correcting beamline for reference tracks" << std::endl;
1068 if ( correctBeamlineTest ) std::cout << "main() correcting beamline for test tracks" << std::endl;
1069
1070
1071
1072 if ( beamRef.size()>0 ) std::cout << "beamref " << beamRef << std::endl;
1073 if ( beamTest.size()>0 ) std::cout << "beamtest " << beamTest << std::endl;
1074
1075 double a0v = 1000;
1076 double z0v = 2000;
1077
1080
1081
1082 double a0vrec = 1000;
1083 double z0vrec = 2000;
1084
1087
1088 bool initialiseFirstEvent = false;
1089 if (
inputdata.isTagDefined(
"InitialiseFirstEvent") ) initialiseFirstEvent =
inputdata.GetValue(
"InitialiseFirstEvent");
1090
1091
1092
1094
1095
1096 bool doPurity = false;
1097 if (
inputdata.isTagDefined(
"doPurity") ) doPurity = (
inputdata.GetValue(
"doPurity")==0 ?
false :
true );
1098
1100
1101
1102 bool monitorZBeam = false;
1103 if (
inputdata.isTagDefined(
"MonitorinZBeam") ) monitorZBeam = (
inputdata.GetValue(
"MonitorZBeam")==0 ?
false :
true );
1104
1105 std::cout << "dbg " << __LINE__ << std::endl;
1106
1108
1110
1111 if ( binningConfigFile!=
"" ) binningConfig =
new ReadCards( binningConfigFile );
1112
1120
1121
1123 if ( binningConfig!=&inputdata ) delete binningConfig;
1124
1125
1127
1128 int selectcharge = 0;
1130
1131
1132 std::cout << "using reference " << refChain << std::endl;
1133 if ( refChain.find(
"Truth") != string::npos ) std::cout <<
"using pdgId " <<
pdgId << std::endl;
1134 if ( refChains.size() > 1 ) std::cout<<"Multiple reference chains split to: " << refChains <<std::endl;
1135
1137
1139
1141
1142
1143
1144
1146
1147 std::cout << "a0v: " << a0v << std::endl;
1148 std::cout << "z0v: " << z0v << std::endl;
1149
1151
1153 npix, nsct, -1, nbl,
1154 -2, -2, chi2prob,
1155 npixholes, nsctholes, nsiholes, expectBL );
1156
1157 if ( selectcharge!=0 ) filter_offline.chargeSelection( selectcharge );
1158 if ( pTMax>pT ) filter_offline.maxpT( pTMax );
1159
1161
1162
1163
1164
1166
1167
1168
1169
1170
1171
1173
1175
1177
1180
1182
1184
1185 Filter_Track filter_onlinekine( eta_rec, 1000, 0., 2000, pT, -1, npix, nsct, -1, -2, -2);
1187 Filter_Combined filter_online( &filter_onlinekine, &filter_onlinevertex );
1188
1189 Filter_Track filter_offkinetight( 5, 1000, 0., 2000, pT, -1, 0, 0, -1, -2, -2);
1190 Filter_Combined filter_offtight( &filter_offkinetight, &filter_inout );
1191
1197
1198
1199 if (
inputdata.isTagDefined(
"Filter" ) ) {
1201 std::cout <<
"Filter: " <<
inputdata.GetString(
"Filter") <<
" : " <<
filter << std::endl;
1202 if (
filter.head()==
"Offline2017" ) {
1203 std::string filter_type =
filter.tail();
1205 filter_offCP =
new Filter_Combined ( filter_offline2017, &filter_vertex);
1206 refFilter = filter_offCP;
1207 }
1208 else if (
filter.head()==
"OfflineR22" ) {
1209 std::string filter_type =
filter.tail();
1211 filter_offCP =
new Filter_Combined ( filter_offlineR22, &filter_vertex);
1212 refFilter = filter_offCP;
1213 }
1214 else {
1215 std::cerr <<
"unimplemented Filter requested: " <<
filter.head() << std::endl;
1216 return -1;
1217 }
1218 }
1219 else {
1220 if ( !(refFilter =
getFilter( refChains[0], pdgId, &filter_off, &filter_muon, &filter_truth ) ) ) {
1221 std::cerr << "unknown reference chain defined" << std::endl;
1222 return (-1);
1223 }
1224 }
1225
1226 refFilters.push_back(refFilter);
1227
1228
1229 std::map<std::string,TIDA::Reference>
ref;
1230
1231 std::vector<NtupleTrackSelector*> refSelectors;
1232
1233#if 0
1237
1238 for (
size_t ic=0 ;
ic<refChains.size() ;
ic++ ) {
1239
1240 if ( refFilter==0 ) {
1241 if ( !(refFilters[ic] =
getFilter( refChains[ic], pdgId, &filter_off, &filter_muon, &filter_truth ) ) ) {
1242 std::cerr << "unknown reference chain defined" << std::endl;
1243 return (-1);
1244 }
1245 refFilter = refFilters[
ic];
1246 }
1247 else refFilters[
ic] = refFilter;
1248
1250
1251 }
1252
1253# endif
1254
1255 if (pdgId==0) truthFilter = &filter_off;
1256 else truthFilter = &filter_truth;
1257
1258
1259
1260
1261
1262 std::cout << "filter_passthrough" << std::endl;
1263
1264 Filter_Track filter_passthrough( 10, 1000, 0., 2000, pT_rec, npix_rec, nsct_rec, 1, -2, -2, -2);
1265
1267
1268
1269 std::cout << "using tracks: " << refChain << " for reference sample" << std::endl;
1270
1271
1273
1274
1275 std::vector<std::string>& test_chains = testChains;
1276
1279
1280 std::map<std::string,TrackAnalysis*> analysis;
1281
1285
1286 std::vector<TrackAnalysis*>
analyses;
1287 analyses.reserve(test_chains.size());
1288
1289 std::cout << "booking " << test_chains.size() << " analyses" << std::endl;
1290
1291 for (
unsigned i=0 ;
i<test_chains.size() ;
i++ ) {
1292
1293 std::string chainname =
ChainString(test_chains[i]);
1294
1295 std::vector<std::string> chainnames;
1296
1297 chainnames.push_back(chainname);
1298
1299
1300
1301
1304
1305 std::string probe_extra = probe.
extra();
1306
1307 if ( probe_extra.empty() ) probe_extra = probe.
postvalue(
"extra");
1308
1309 if ( probe_extra.find(
"_tag")!=std::string::npos || probe.
extra().find(
"_tag")!=std::string::npos ) {
1310 std::cout << "rejecting tag chain " << probe << std::endl;
1311 continue;
1312 }
1313
1314
1315 size_t p = probe_extra.find(
"_probe");
1316
1317 if ( p!=std::string::npos ) {
1318
1319 std::string probe_ref = refChains[0];
1320
1321 if ( !probe.
postvalue(
"ref").empty() ) {
1322
1324
1325 if ( refChains[0] != probe_ref ) {
1326 std::cerr << "default and probe chain references do not match: probe ref: " << probe_ref << " ref: " << refChains[0] << std::endl;
1328
1329 }
1330
1331 }
1332
1333
1334 std::string probe_key = probe_extra.erase(p, 6);
1335
1336 for ( unsigned j=0 ; j<test_chains.size(); ++j) {
1337
1338 if ( i==j ) continue;
1339
1341
1342 if (
tag.head() != probe.
head() )
continue;
1343
1344
1345
1346 std::string tag_extra =
tag.extra();
1347
1348 if ( tag_extra.empty() ) tag_extra =
tag.postvalue(
"extra");
1349 if ( tag_extra.find("_tag")==std::string::npos ) continue;
1350
1351
1352 std::string tag_key = tag_extra.erase( tag_extra.find("_tag"), 4) ;
1353
1354
1355 if ( tag_key != probe_key ) continue;
1356
1357 if (
tag.element() == probe.
element() )
continue;
1358
1359 std::string tag_ref = refChains[0];
1360
1362
1364
1366
1367 if ( !
tag.postvalue(
"ref").empty() ) {
1368
1369 tag_ref =
tag.postvalue(
"ref");
1370
1371
1372 std::cout << "tag ref: " << tag_ref << std::endl;
1373
1374 if (
ref.find(tag_ref)==
ref.end() ) {
1376
1378 }
1379 }
1380
1384
1385 TnP_tool =
new TagNProbe( tag_ref, probe_ref, massMin, massMax);
1387 TnP_tool->
probe(probe);
1388 std::cout <<
"Tag and probe pair found! \n\t Tag : " <<
tag <<
"\n\t Probe : " << probe
1389 << "\n\t tag ref: " << tag_ref
1390 << "\n\tprobe ref: " << probe_ref
1391 << "\n-------------------" << std::endl;
1392
1394
1395
1396 break ;
1397 }
1398
1399 }
1400
1401
1402 if ( TnP_tool )
replace( chainname,
"/",
"_" );
1404
1408
1409 std::string vtxTool = chainConfig[
i].postvalue(
"rvtx");
1410
1411 if ( vtxTool!="" ) {
1415
1416 analy_conf->
store().
insert( anal_confvtx,
"rvtx" );
1417 }
1418
1419
1420
1421
1426
1431
1432 if ( chainConfig[i].
values().size()>0 ) {
1433 std::cout <<
"chain:: " << chainname <<
" : size " << chainConfig[
i].values().size() << std::endl;
1434 for (
unsigned ik=chainConfig[i].
values().size() ; ik-- ; ) {
1435 std::cout <<
"\tchainconfig: " << ik <<
"\tkey " << chainConfig[
i].keys()[ik] <<
" " << chainConfig[
i].values()[ik] << std::endl;
1436 }
1437 }
1438
1440
1441
1442 if ( analysis.find( chainname )==analysis.end() ) {
1443 analysis.insert( std::map<std::string,TrackAnalysis*>::value_type( chainname, analy_conf ) );
1445 }
1446 else {
1447 std::cerr << "WARNING: Duplicated chain"
1448 << "\n"
1449 << "---------------------------------"
1450 << "---------------------------------"
1451 << "---------------------------------" << std::endl;
1452 continue;
1453 }
1454
1455 std::cout << "analysis: " << chainname << "\t" << analy_conf
1456 << "\n"
1457 << "---------------------------------"
1458 << "---------------------------------"
1459 << "---------------------------------" << std::endl;
1460
1461 if ( doPurity ) {
1463 std::cout << "purity " << (chainnames[0]+"-purity") << std::endl;
1466
1467 analysis[chainnames[0]+"-purity"] = analp;
1469 }
1470
1471 }
1472
1473 std::cout << "main() finished looping" << std::endl;
1474
1476
1477 bool fullyContainTracks = false;
1478
1479 if (
inputdata.isTagDefined(
"FullyContainTracks") ) {
1480 fullyContainTracks = (
inputdata.GetValue(
"FullyContainTracks")==0 ?
false :
true );
1481 }
1482
1483 bool containTracksPhi = true;
1484
1485 if (
inputdata.isTagDefined(
"ContainTracksPhi") ) {
1486 containTracksPhi = (
inputdata.GetValue(
"ContainTracksPhi")==0 ?
false :
true );
1487 }
1488
1491 dynamic_cast<Filter_Combined*
>(refFilter)->containtracks(fullyContainTracks);
1492 dynamic_cast<Filter_Combined*
>(refFilter)->containtracksPhi(containTracksPhi);
1493 }
1494
1498
1500
1501
1502
1503
1504
1505
1506
1508
1509 bool filterRoi = false;
1510
1511 double roieta = 0;
1512 bool roicomposite = false;
1513 size_t roimult = 1;
1514
1515 if (
inputdata.isTagDefined(
"FilterRoi" ) ) {
1516
1517 filterRoi = true;
1518
1519 std::vector<double> filter_values =
inputdata.GetVector(
"FilterRoi" );
1520
1521 if ( filter_values.size()>0 ) roieta = filter_values[0];
1522 if ( filter_values.size()>1 ) roicomposite = ( filter_values[1]==0 ? false : true );
1523 if ( filter_values.size()>2 ) roimult = int(filter_values[2]+0.5);
1524
1525 }
1526
1527 RoiFilter roiFilter( roieta, roicomposite, roimult );
1528
1530
1532
1534 else if ( useMatcher == "DeltaRZ" || useMatcher == "DeltaRZSinTheta" ) {
1535 double deta = 0.05;
1536 double dphi = 0.05;
1537 double dzed = 25;
1538 if (
inputdata.isTagDefined(
"Matcher_deta" ) ) deta =
inputdata.GetValue(
"Matcher_deta");
1539 if (
inputdata.isTagDefined(
"Matcher_dphi" ) ) dphi =
inputdata.GetValue(
"Matcher_dphi");
1540 if (
inputdata.isTagDefined(
"Matcher_dzed" ) ) dzed =
inputdata.GetValue(
"Matcher_dzed");
1541
1544 }
1545 else if ( useMatcher == "pT_2" ) {
1546 double pTmatchLim_2 = 1.0;
1547 if (
inputdata.isTagDefined(
"Matcher_pTLim_2") ) pTmatchLim_2 =
inputdata.GetValue(
"Matcher_pTLim_2");
1549 }
1550 else if ( useMatcher == "Truth" ) {
1552 }
1553 else {
1557 }
1558
1561 if ( truthMatch ) {
1563 else if ( useMatcher == "DeltaRZ" || useMatcher == "DeltaRZSinTheta" ) {
1564 double deta = 0.05;
1565 double dphi = 0.05;
1566 double dzed = 25;
1567 if (
inputdata.isTagDefined(
"Matcher_deta" ) ) deta =
inputdata.GetValue(
"Matcher_deta");
1568 if (
inputdata.isTagDefined(
"Matcher_dphi" ) ) dphi =
inputdata.GetValue(
"Matcher_dphi");
1569 if (
inputdata.isTagDefined(
"Matcher_dzed" ) ) dzed =
inputdata.GetValue(
"Matcher_dzed");
1570
1573 }
1574 else if ( useMatcher == "pT_2" ) {
1575 double pTmatchLim_2 = 1.0;
1576 if (
inputdata.isTagDefined(
"Matcher_pTLim_2") ) pTmatchLim_2 =
inputdata.GetValue(
"Matcher_pTLim_2");
1578 }
1579 else if ( useMatcher == "Truth" ) {
1581 }
1582 else {
1586 }
1587 }
1588
1589
1590
1591
1592
1594
1597
1598
1599
1601
1602
1603 if (
inputdata.isTagDefined(
"DataSets") ) {
1604
1605 std::cout << "fetching dataset details" << std::endl;
1608 std::cout <<
"\tdataset " <<
datasets[
ids] << std::endl;
1610 std::vector<std::string> filenames_ =
d.datafiles();
1611 std::cout << "\tdataset contains " << filenames_.size() << " files" << std::endl;
1613 }
1614 }
1616 else {
1617 std::cerr << "no input data specified" << std::endl;
1618 return (-1);
1619 }
1620
1621
1623
1624
1625
1626
1627 bool show_release = true;
1628
1629 std::vector<std::string> release_data;
1630
1631 std::string release_data_save = "";
1632
1633 if ( show_release ){
1634
1636
1638
1639 TFile* finput = TFile::Open( filenames[i].c_str() );
1640
1641
1642 if ( finput==0 || !finput->IsOpen() || finput->IsZombie() ) {
1643 std::cerr <<
"Error: could not open input file: " <<
filenames[
i] << std::endl;
1645 }
1646
1647 TTree* dataTree = (TTree*)finput->Get("dataTree");
1648 TString* releaseData = new TString("");
1649
1650 if ( dataTree ) {
1651 dataTree->SetBranchAddress( "ReleaseMetaData", &releaseData);
1652
1653 for (
unsigned int i=0;
i<dataTree->GetEntries() ;
i++ ) {
1654 dataTree->GetEntry(i);
1655 release_data.push_back( releaseData->Data() );
1656 if ( release_data_save != release_data.back() ) {
1657 std::cout << "main() release data: " << release_data.back() << " : " << *releaseData << std::endl;
1658 }
1660 release_data_save = release_data.back();
1661 }
1662 }
1663
1664 if ( finput ) delete finput;
1665 }
1666
1667
1668
1669 if ( !release_data.empty() ) {
1670 std::sort(release_data.begin(), release_data.end());
1671 release_data.erase(
std::unique(release_data.begin(), release_data.end()), release_data.end());
1672
1673
1674
1675 foutdir->cd();
1676
1677 TTree* dataTree = new TTree("dataTree", "dataTree");
1678 TString* releaseData = new TString("");
1679
1680 if ( dataTree ) {
1681 dataTree->Branch( "ReleaseMetaData", "TString", &releaseData);
1682
1683 for ( unsigned ird=0 ; ird<release_data.size() ; ird++ ) {
1684 *releaseData = release_data[ird];
1685 dataTree->Fill();
1686 }
1687
1688 dataTree->Write("", TObject::kOverwrite);
1689 delete dataTree;
1690 }
1691 }
1692
1693 }
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706 if ( Nentries==0 &&
inputdata.isTagDefined(
"Nentries") ) {
1708 }
1709
1711
1712 typedef std::pair<int,double> zpair;
1713 std::vector<zpair> refz;
1714 std::vector<zpair> testz;
1715
1716 std::vector<double> beamline_ref;
1717 std::vector<double> beamline_test;
1718
1719 int maxtime = 0;
1720 int mintime = 0;
1721
1722 std::cout << "opening files" << std::endl;
1723
1725
1726 int pregrl_events = 0;
1727 int grl_counter = 0;
1728
1729
1730 std::cout <<
"starting event loop " <<
time_str() << std::endl;
1731
1732
1734 if ( nfiles!=0 && nfiles<max_files ) max_files = nfiles;
1735
1737
1739
1740
1741 TFile* finput = TFile::Open( filenames[ifile].c_str() );
1742
1743 if ( finput==0 || !finput->IsOpen() || finput->IsZombie() ) {
1744 std::cerr <<
"Error: could not open output file " <<
filenames[
ifile] << std::endl;
1745 continue;
1746 }
1747
1748 TTree*
data = (TTree*)finput->Get(
"tree");
1749
1751 std::cerr <<
"Error: cannot open TTree: " <<
filenames[
ifile] << std::endl;
1752 continue;
1753 }
1754
1756
1758
1759 data->SetBranchAddress(
"TIDA::Event",&track_ev);
1760
1761
1764
1765 unsigned cNentries =
data->GetEntries();
1766
1768
1771 for (
unsigned int i=0;
skip &&
run &&
i<cNentries ;
i++ ) {
1772
1774
1779
1781
1782
1783
1785
1786
1787
1789
1790 pregrl_events++;
1791
1793 if ( !ingrl ) continue;
1794
1795 grl_counter++;
1796
1797
1799 if ( event_selector_flag && !es.in( event ) ) continue;
1800
1801 if ( mintime>
ts ) mintime =
ts;
1802 if ( maxtime<
ts ) maxtime =
ts;
1803
1804 if ( Nentries>0 && event_counter>Nentries ) {
1806 std::cout <<
"breaking out " <<
run << std::endl;
1807 break;
1808 }
1809
1811
1812
1813
1814
1815
1816 hevent->Fill( event );
1817
1819 if ( (cNentries<10) || i%(cNentries/10)==0 || i%1000==0 ||
debugPrintout ) {
1820 std::cout <<
"run " << track_ev->
run_number()
1823 <<
"\tchains " << track_ev->
chains().size()
1825 std::cout <<
"\t : processed " <<
i <<
" events so far (" << int((1000*i)/cNentries)*0.1 <<
"%)\t" <<
time_str() << std::endl;
1826
1827 }
1828 }
1829 else if ( newfile ) {
1830
1832 if ( nfiles>0 ) pfiles = nfiles;
1833
1834
1835 std::cout <<
"file entries=" <<
data->GetEntries();
1836
1837 if (
data->GetEntries()<100 ) std::cout <<
" ";
1838 if (
data->GetEntries()<1000 ) std::cout <<
" ";
1839 if (
data->GetEntries()<10000 ) std::cout <<
" ";
1840
1841 std::cout << "\t";
1842
1843
1844 std::cout <<
"run " << track_ev->
run_number()
1847 <<
"\tchains " << track_ev->
chains().size()
1849
1850 std::cout <<
"\t : processed " <<
ifile <<
" files so far (" << int((1e3*ifile)/pfiles)*0.1 <<
"%)\t" <<
time_str() << std::endl;
1851
1853 }
1854
1855
1856
1858
1860
1861 offTracks.clear();
1862 refTracks.clear();
1863 truthTracks.clear();
1864 refPurityTracks.clear();
1865
1868 mit->second.selector()->clear();
1870 }
1871
1873
1874 const std::vector<TIDA::Chain>&
chains = track_ev->
chains();
1875
1878 if ( truthMatch ) {
1879 for (
unsigned int ic=0 ;
ic<
chains.size() ;
ic++ ) {
1880 if ( chains[ic].
name()==
"Truth" ) {
1881 truthTracks.selectTracks( chains[ic][0].tracks() );
1882 break;
1883 }
1884 }
1885 }
1886
1888 for (
const std::string&
rc : refChains){
1889 for (
unsigned int ic=0 ;
ic<
chains.size() ;
ic++ ) {
1890 if ( chains[ic].
name()==
rc ) {
1891 offTracks.selectTracks( chains[ic][0].tracks() );
1892
1893 beamline_ref =
chains[
ic][0].user();
1894
1895 break;
1896 }
1897 }
1898 }
1899
1901
1902 std::vector<TIDA::Vertex> vertices;
1903
1905
1906 if ( vtxchain && vtxchain->
size()>0 ) {
1907
1908 const std::vector<TIDA::Vertex>& mv = vtxchain->
at(0).
vertices();
1909
1910 int selectvtx = -1;
1912
1913 if (
debugPrintout ) std::cout <<
"vertices:\n" << mv << std::endl;
1914
1915 if ( bestPTVtx || bestPT2Vtx ) {
1916 for ( size_t iv=0 ; iv<mv.size() ; iv++ ) {
1917 if ( mv[iv].Ntracks()==0 ) continue;
1918 double selection_ = 0.0;
1920 vtx_temp.selectTracks( offTracks.tracks() );
1921 for (unsigned itr=0; itr<vtx_temp.tracks().size(); itr++) {
1923 if ( bestPTVtx ) selection_ += std::fabs(tr->
pT());
1924 else if ( bestPT2Vtx ) selection_ += std::fabs(tr->
pT())*std::fabs(tr->
pT());
1925 }
1928 selectvtx = iv;
1929 }
1930 }
1931 if ( selectvtx!=-1 ) {
1932 vertices.push_back( mv[selectvtx] );
1933 }
1934 }
1935 else if ( vtxind>=0 ) {
1936 if ( size_t(vtxind)<mv.size() ) {
1937 vertices.push_back( mv[vtxind] );
1938 }
1939 }
1940 else {
1941 for ( size_t iv=0 ; iv<mv.size() ; iv++ ) {
1942 vertices.push_back( mv[iv] );
1943 }
1944 }
1945
1947 filter_vertex.setVertex( vertices );
1948
1950
1952
1953 for ( unsigned iv=0 ; iv<mv.size() ; iv++ ) {
1954 int Ntracks = mv[iv].Ntracks();
1955 if ( Ntracks>NVtxTrackCut ) {
1957
1959 }
1960 }
1961 }
1962
1963
1964
1966
1968
1972 bool foundReference = false;
1973
1975
1978
1980
1981 for (
const std::string&
rc : refChains ) {
1983 }
1984
1986
1987
1989
1990 std::string refname = mitr->first;
1991
1993
1996
1998
1999 *mitr->second.tom() = rtom;
2000
2004
2005
2006
2007
2008 }
2009
2010
2011
2012
2013 if ( !foundReference ) continue;
2014
2016 std::cout << "reference chain:\n" << *refchain << std::endl;
2017 }
2018
2019 for (
unsigned ic=0 ;
ic<track_ev->
chains().size() ;
ic++ ) {
2020
2022
2023
2024
2026 std::map<std::string,TrackAnalysis*>::iterator analitr = analysis.find(
chain.name());
2027
2029
2030 if ( analitr==analysis.end() ) continue;
2031
2033 std::cout <<
"test chain:\n" <<
chain << std::endl;
2034 }
2035
2037
2038 std::vector<TIDA::Roi*>
rois;
2039
2040
2042
2043 if ( TnP_tool ) {
2044
2045 foutdir->cd();
2047
2050
2051 std::map<std::string,TIDA::Reference>::iterator mit0=
ref.find(TnP_tool->
type0());
2052
2055
2057
2058 if ( TnP_tool->
type0() == TnP_tool->
type1() ) {
2060 rois = TnP_tool->
GetRois( track_ev->
chains(), selector0, filter0, invmass, invmass_obj, rtom );
2061 }
2062 else {
2064
2066 std::map<std::string,TIDA::Reference>::iterator mit1=
ref.find(TnP_tool->
type1());
2067
2070
2072
2073#if 0
2074 for (
size_t ia=0 ; ia<selector1->
tracks().size() ; ia++ ) {
2076 std::cout << ia <<
"\t" << *
track << std::endl;
2077 std::cout <<
"\t" << rtom1->
object(
track->id()) << std::endl;
2078 }
2079
2080 std::cout << *TnP_tool << std::endl;
2081#endif
2082
2083 rois = TnP_tool->
GetRois( track_ev->
chains(), selector0, filter0, selector1, filter1, invmass, invmass_obj, rtom, rtom1 );
2084 }
2085 }
2086 else {
2087
2090 }
2091
2093 if (
false ) std::cout <<
"++++++++++++ rois size = " <<
rois.size() <<
" +++++++++++" << std::endl;
2094
2095
2096 for (
unsigned int ir=0 ;
ir<
rois.size() ;
ir++ ) {
2097
2099
2100
2103
2104 testTracks.clear();
2105
2106 testTracks.selectTracks( troi.
tracks() );
2107
2109 std::vector<TIDA::Track*> testp = testTracks.tracks();
2110
2113
2114 if ( filterRoi && !roiFilter.filter( roi ) ) continue;
2115
2117 const std::vector<TIDA::Vertex>& mvt = troi.
vertices();
2118
2119 std::vector<TIDA::Vertex> vertices_test;
2120
2121 int selectvtx = -1;
2123
2124 if ( bestPTVtx_rec || bestPT2Vtx_rec ) {
2125
2126
2127
2128 for ( unsigned iv=0 ; iv<mvt.size() ; iv++ ) {
2129 double selection_ = 0.0;
2131 vtx_temp.selectTracks( testp );
2132 for (unsigned itr=0; itr<vtx_temp.tracks().size(); itr++) {
2134 if ( bestPTVtx ) selection_ += std::fabs(tr->
pT());
2135 else if ( bestPT2Vtx ) selection_ += std::fabs(tr->
pT())*std::fabs(tr->
pT());
2136 }
2139 selectvtx = iv;
2140 }
2141 }
2142 if ( selectvtx!=-1 ) {
2144 if ( useVertexTracks ) selected.selectTracks( testp );
2145 vertices_test.push_back(selected);
2146 }
2147 }
2148 else if ( vtxind_rec!=-1 ) {
2149 if ( unsigned(vtxind_rec)<mvt.size() ) {
2151 if ( useVertexTracks ) selected.selectTracks( testp );
2152 vertices_test.push_back( selected );
2153 }
2154 }
2155 else {
2156 for ( unsigned iv=0 ; iv<mvt.size() ; iv++ ) {
2158 if ( useVertexTracks ) selected.selectTracks( testp );
2159 vertices_test.push_back( selected );
2160 }
2161 }
2162
2163
2164 beamline_test =
rois[
ir]->user();
2165
2166
2167 for (
size_t i=
analyses.size() ; i-- ; ) {
2168
2170
2171 if ( correctBeamlineTest ) {
2172 if ( beamTest.size()==2 ) analy_track->
setBeamTest( beamTest[0], beamTest[1] );
2173
2174 else {
2175 if ( !
inputdata.isTagDefined(
"BeamTest") ) {
2176 if ( beamline_test.size()==2 ) analy_track->
setBeamTest( beamline_test[0], beamline_test[1] );
2177
2178 }
2179 }
2180 }
2181
2182 if ( correctBeamlineRef ) {
2183 if ( beamRef.size()==2 ) analy_track->
setBeamRef( beamRef[0], beamRef[1] );
2184
2185 else {
2186 if ( !
inputdata.isTagDefined(
"BeamRef") ) {
2187 if ( beamline_ref.size()==2 ) analy_track->
setBeamRef( beamline_ref[0], beamline_ref[1] );
2188
2189 }
2190 }
2191 }
2192
2193 }
2194
2197
2199
2200 if ( select_roi ) {
2201
2205
2206 bool customRefRoi_thisChain = false;
2207
2208 if ( use_custom_ref_roi ) {
2209 if ( customRoi_chains.size() ) {
2210 if ( customRoi_chains.find(
chain.name() )!=customRoi_chains.end() ) customRefRoi_thisChain =
true;
2211 }
2212 else customRefRoi_thisChain = true;
2213 }
2214
2215 if ( use_custom_ref_roi && customRefRoi_thisChain ) {
2216 refRoi =
makeCustomRefRoi( roi, custRefRoi_params[0], custRefRoi_params[1], custRefRoi_params[2] );
2217 }
2218 else refRoi = roi;
2219
2221 }
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232 std::vector<TIDA::Track*> refp_vec = refTracks.tracks( refFilter );
2233
2234
2235 if ( truthMatch ) {
2237 if ( select_roi )
dynamic_cast<Filter_Combined*
>(truthFilter)->setRoi(&roi);
2238 const std::vector<TIDA::Track*>& truth = truthTracks.tracks(truthFilter);
2239 const std::vector<TIDA::Track*>& refp_tmp = refp_vec;
2240
2242 truth_matcher->
match( refp_tmp, truth );
2243
2244 std::vector<TIDA::Track*> refp_matched;
2245
2247 for (
unsigned i=0 ;
i<refp_vec.size() ;
i++ ) {
2248 if ( truth_matcher->
matched( refp_vec[i] ) ) refp_matched.push_back( refp_vec[i] );
2249 }
2250
2251 refp_vec.clear();
2252 refp_vec = refp_matched;
2253 }
2254
2255
2256 if ( use_pt_ordered_ref ) {
2258
2259 size_t nRefTracks = refp_vec.size();
2260
2261 std::vector<TIDA::Track*> refp_chosenPtOrd;
2262
2264
2265 for ( size_t sidx=refPtOrd_indices.size() ; sidx-- ; ) {
2266 if ( refPtOrd_indices.at(sidx)>nRefTracks ) {
2267 std::cout << "WARNING: for event " << event
2268 << ", pT ordered reference track at vector position " << refPtOrd_indices.at(sidx)
2269 << " requested but not found" << std::endl;
2270 break;
2271 }
2272 }
2273 }
2274
2275 for ( size_t sidx=refPtOrd_indices.size() ; sidx-- ; ) {
2276 for (
size_t idx=0 ;
idx<refp_vec.size() ;
idx++ ) {
2277 if ( idx == refPtOrd_indices.at(sidx) ) {
2278 refp_chosenPtOrd.push_back(refp_vec.at(idx));
2279 break;
2280 }
2281 }
2282 }
2283
2284 refp_vec.clear();
2285 refp_vec = refp_chosenPtOrd;
2286
2287
2288 }
2289
2291 if ( cf ) {
2292
2294
2296 if ( ptconfig!="" ) {
2297 double pt = std::atof( ptconfig.c_str() );
2298 if ( pt>0 ) {
2299 std::vector<TIDA::Track*> reft; reft.reserve(refp_vec.size());
2300 for ( std::vector<TIDA::Track*>::const_iterator itr=refp_vec.begin() ; itr!=refp_vec.end() ; ++itr ) {
2301 if ( std::fabs((*itr)->pT())>=pt ) reft.push_back( *itr );
2302 }
2303 refp_vec = reft;
2304 }
2305 }
2306
2308
2310 if ( d0config!="" ) {
2311 double d0 = std::atof( d0config.c_str() );
2312 if ( d0>0 ) {
2313 std::vector<TIDA::Track*> reft; reft.reserve(refp_vec.size());
2314 for ( std::vector<TIDA::Track*>::const_iterator itr=refp_vec.begin() ; itr!=refp_vec.end() ; ++itr ) {
2315 if ( std::fabs((*itr)->a0())<=d0 ) reft.push_back( *itr );
2316 }
2317 refp_vec = reft;
2318 }
2319 }
2320
2321 }
2322
2325
2327
2329
2331
2332 if ( objectET != "" ) {
2333
2334 double ETconfig = std::atof( objectET.c_str() );
2335
2336 if ( ETconfig>0 ) {
2337
2338 std::vector<TIDA::Track*>::iterator itr=refp_vec.begin() ;
2339
2340 while ( itr!=refp_vec.end() ) {
2342
2343 if ( tobj==0 || tobj->
pt()<ETconfig )
2344 itr=refp_vec.erase( itr );
2345 else
2346 ++itr;
2347 }
2348 }
2349 }
2350 }
2351
2352 const std::vector<TIDA::Track*>& refp = refp_vec;
2353
2354
2355
2356
2357
2358
2359
2360
2361
2363
2367
2368
2369 std::vector<TIDA::Vertex> vertices_roi;
2370
2372
2373 {
2374
2376
2377 vertices_roi.clear();
2378
2379 const std::vector<TIDA::Vertex>& mv = vertices;
2380
2381
2382
2383
2384 for ( unsigned iv=0 ; iv<mv.size() ; iv++ ) {
2385
2387
2388
2389
2390 bool accept_vertex = false;
2391 if ( roi.composite() ) {
2392 for (
size_t ir=0 ;
ir<roi.size() ;
ir++ ) {
2393 if ( roi[
ir]->zedMinus()<=vx.
z() && roi[
ir]->zedPlus()>=vx.
z() ) accept_vertex =
true;
2394 }
2395 }
2396 else {
2397 if ( roi.zedMinus()<=vx.
z() && roi.zedPlus()>=vx.
z() ) accept_vertex =
true;
2398 }
2399
2400 if ( !accept_vertex ) continue;
2401
2402
2403
2404 int trackcount = 0;
2405
2406 if ( useVertexTracks ) {
2407
2409 vertex_roi.selectTracks( refp );
2410 trackcount = vertex_roi.Ntracks();
2411 if ( trackcount>=ntracks && trackcount>0 ) {
2412 vertices_roi.push_back( vertex_roi );
2413 }
2414 }
2415 else {
2416
2417 for (unsigned itr=0; itr<refp.size(); itr++){
2419 double theta_ = 2*std::atan(std::exp(-tr->
eta()));
2420 double dzsintheta = std::fabs( (vx.
z()-tr->
z0()) * std::sin(theta_) );
2421 if( dzsintheta < 1.5 ) trackcount++;
2422 }
2426 if ( trackcount>=ntracks && trackcount>0 ) {
2428 vertices_roi.push_back( vertex_roi );
2429 }
2430 }
2431
2432 }
2433 }
2434
2435
2436 if ( rotate_testtracks )
for (
size_t i=testp.size() ; i-- ; ) testp[
i]->rotate();
2437
2438 foutdir->cd();
2439
2440
2441
2442 if ( monitorZBeam ) {
2443 if ( beamline_ref.size()>2 && beamline_test.size()>2 ) {
2444 refz.push_back( zpair(
lb, beamline_ref[2]) );
2445 testz.push_back( zpair(
lb, beamline_test[2]) );
2446 }
2447 }
2448
2449 matcher->
match( refp, testp);
2450
2451 if ( tom.
status() ) analitr->second->execute( refp, testp, matcher, &tom );
2452 else analitr->second->execute( refp, testp, matcher );
2453
2455 analitr->second->store().find( vtxanal, "rvtx" );
2456
2459 if ( vtxanal && ( refp.size() >= size_t(ntracks) ) ) {
2460
2468
2470
2472
2473 }
2474
2475
2477
2478 std::cout <<
"\nselected tracks:" <<
chain.name() << std::endl;
2479 std::cout << "ref tracks refp.size() " << refp.size() << "\n" << refp << std::endl;
2480 std::cout << "test tracks testp.size() " << testp.size() << "\n" << testp << std::endl;
2481
2482 TrackAssociator::map_type::const_iterator titr = matcher->TrackAssociator::matched().begin();
2483 TrackAssociator::map_type::const_iterator
tend = matcher->TrackAssociator::matched().end();
2485 std::cout << "track matches:\n";
2486 while (titr!=tend) {
2487 std::cout <<
"\t" <<
im++ <<
"\t" << *titr->first <<
" ->\n\t\t" << *titr->second << std::endl;
2488 ++titr;
2489 }
2490
2491
2492 std::cout <<
"completed : " <<
chain.name() <<
"\n";
2493 std::cout << "-----------------------------------" << std::endl;
2494
2495 }
2496
2497#if 0
2498 if ( _matcher->size()<refp.size() ) {
2499
2500 if ( refp.size()==1 && testp.size()==0 ) {
2501 std::cout << track_ev->
chains()[
ic] <<std::endl;
2502 std::cout <<
"roi\n" << track_ev->
chains()[
ic].rois()[
ir] << endl;
2503 }
2504
2505 }
2506#endif
2507
2509
2510 if ( doPurity ) {
2511
2512 const std::vector<TIDA::Track*>& refpp = refPurityTracks.tracks( refFilter );
2513
2514 testPurityTracks.clear();
2515
2516 testPurityTracks.selectTracks( troi.
tracks() );
2517 std::vector<TIDA::Track*> testpp = testPurityTracks.tracks();
2518
2519 matcher->
match(refpp, testpp);
2520
2521
2522 std::map<std::string,TrackAnalysis*>::iterator analitrp = analysis.find(
chain.name()+
"-purity");
2523
2524 if ( analitrp == analysis.end() ) continue;
2525
2526
2527 analitrp->second->execute( refpp, testpp, matcher );
2528
2529
2530
2531 }
2532
2533 }
2534
2535 }
2536
2537 }
2538
2539 delete track_ev;
2541 delete finput;
2542
2543
2544
2545 }
2546
2548 << "\ttimes " << mintime << " " << maxtime
2549 << "\t( grl: " << grl_counter << " / " << pregrl_events << " )" << std::endl;
2550
2551 if ( monitorZBeam )
zbeam zb( refz, testz );
2552
2553 foutdir->cd();
2554
2555
2556
2559
2560 for (
int i=
analyses.size() ; i-- ; ) {
2561
2563
2565 analyses[
i]->store().find( vtxanal,
"rvtx" );
2566 if ( vtxanal ) vtxanal->
finalise();
2567
2569 }
2570
2571 foutput.Write();
2572 foutput.Close();
2573
2574
2575
2577 mit->second.Clean();
2578 }
2579
2580
2581 if ( ex_matcher ) delete ex_matcher;
2582
2583 std::cout << "done" << std::endl;
2584
2585 return 0;
2586}
const boost::regex ref(r_ef)
BinConfig cosmicBinConfig("cosmic")
BinConfig electronBinConfig("electron")
BinConfig muonBinConfig("muon")
bool PRINT_BRESIDUALS
stack trace headers
BinConfig g_binConfig("standard")
BinConfig bjetBinConfig("bjet")
BinConfig tauBinConfig("tau")
char data[hepevt_bytes_allocation_ATLAS]
TIDA::Associator< TIDA::Track > TrackAssociator
const std::string & extra() const
const std::string & head() const
std::string postvalue(const std::string &key) const
same here regarding returning a reference
const std::string & element() const
virtual TH1F * getHist_invmass()
const ChainString & config() const
virtual TagNProbe * getTnPtool()
virtual void initialise()
book all the histograms
virtual TH1F * getHist_invmassObj()
virtual void initialiseInternal()
void initialiseFirstEvent(bool b=true)
void execute(const std::vector< TIDA::Vertex * > &vtx0, const std::vector< TIDA::Vertex * > &vtx1, const TIDA::Event *tevt=0)
void setRoi(TIDARoiDescriptor *r)
sadly need to include a root dependency, but no matter - the TIDA::Track class itself inherets from T...
virtual void initialise()
book all the histograms
Get tag-value pairs from a file.
int Finalise(double a=-999, double b=-999, TF1 *(*func)(TH1D *s, double a, double b)=Resplot::FitGaussian)
Int_t Write(const char *=0, Int_t=0, Int_t=0) const
Hooray, this stupidity is to overwride both the const and non-const TObject Write methods Fixme: shou...
static TF1 * FitNull95(TH1D *s, double a=0, double b=0)
static bool setoldrms95(bool b)
int Fill(double x, double y, double w=1)
static bool setnofit(bool b)
Describes the Region of Ineterest geometry It has basically 8 parameters.
unsigned size() const
number of rois
const TIDA::Chain * chain(const std::string &s) const
void lumi_block(unsigned lb)
void event_number(unsigned long long e)
void time_stamp(unsigned t)
void run_number(unsigned r)
accessors
const std::vector< TIDA::Chain > & chains() const
void insert(T *t, const std::string &key)
std::map< std::string, Reference >::iterator iterator
std::map< std::string, Reference >::value_type value_type
const TIDARoiDescriptor & roi() const
access the roi information
const std::vector< TIDA::Track > & tracks() const
const std::vector< TIDA::Vertex > & vertices() const
access the vertices
void probe(const std::string &chainName)
std::vector< TIDA::Roi * > GetRois(std::vector< TIDA::Chain > &chains, const TrackSelector *selector, TrackFilter *filter, T *hmass, T *hmass_obj, TrigObjectMatcher *tom=0) const
void tag(const std::string &chainName)
getters and setters
const std::string & type0() const
const std::string & type1() const
TIDA::FeatureStore & store()
void setBeamTest(double x, double y, double z=0)
void setBeamRef(double x, double y, double z=0)
set the beamline positions
const std::vector< TIDA::Track * > & tracks() const
const TrackTrigObject * object(unsigned long track_id)
int ir
counter of the current depth
const std::string selection
TIDARoiDescriptor * groi
all these externals initialised in globals.cxx
std::string replace(std::string s, const std::string &s2, const std::string &s3)
std::string find(const std::string &s)
return a remapped string
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)
event_counter(input_file_pattern)
Count total number of events in input files.
DataModel_detail::iterator< DVL > unique(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of unique for DataVector/List.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
bool trackPtGrtr(TIDA::Track *trackA, TIDA::Track *trackB)
TrackFilter * getFilter(const std::string &refname, int pdgId, TrackFilter *foff, TrackFilter *fmu, TrackFilter *ftruth)
This is awful code, passing in lots of filter pointers just so that they can be assigned neatly ?
std::vector< T * > pointers(std::vector< T > &v)
void handler(int sig)
signal handler
TIDARoiDescriptor makeCustomRefRoi(const TIDARoiDescriptor &roi, double etaHalfWidth=-999, double phiHalfWidth=-999, double zedHalfWidth=-999)
bool GetRefTracks(const std::string &rc, const std::string &exclude, const std::vector< TIDA::Chain > &chains, NtupleTrackSelector &refTracks, TrackAssociator *ex_matcher, TrigObjectMatcher &tom)
int atoi_check(const std::string &s)
convert string to integer with check if successful
double ETovPTmin
this is a swiss knife function - by default if ET/PT > 0 such that fabs(ET/PT) > 0 is always true and...