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
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
hooray !! Set any additional aspects to the analysis up here so should be able to set individual, chain related variables eg set individual pt limits, different selection of reference objects, whether to run a vertex analysis ...
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
AAAAAARGH!!! because you cannot cast vector<T> to const vector<const T> we first need to copy the actual elements from the const vector, to a normal vector. This is because if we take the address of elements of a const vector<T> they will by of type const T*, so we can only add them to a vector<const T*> and all our functions are using const vector<T>&, so we would need to duplicate all the functions to allow over riding with vector<T*> and vector<const T*> to get this nonsense to work
so we now use a handy wrapper function to do the conversion for us ...
531 std::cerr <<
"Error: no config file specified\n" << std::endl;
545 std::cout <<
"$0 :: compiled " << __DATE__ <<
" " << __TIME__ << std::endl;
549 std::string histofilename(
"");
551 std::string datafile =
"";
553 std::vector<std::string> refChains(0);
555 std::vector<TrackFilter*> refFilters(0);
560 std::string refChain =
"";
564 std::vector<std::string> testChains;
566 std::string binningConfigFile =
"";
568 bool useoldrms =
true;
571 std::string vertexSelection =
"";
572 std::string vertexSelection_rec =
"";
574 unsigned Nentries = 0;
576 for (
int i=1 ;
i<
argc ;
i++ ) {
577 if ( std::string(
argv[
i])==
"-h" || std::string(
argv[
i])==
"--help" ) {
580 else if ( std::string(
argv[
i])==
"-e" || std::string(
argv[
i])==
"--entries" ) {
584 else if ( std::string(
argv[
i])==
"-o" || std::string(
argv[
i])==
"-f" || std::string(
argv[
i])==
"--file" ) {
586 histofilename =
argv[
i];
587 if ( histofilename.find(
".root")==std::string::npos ) histofilename +=
".root";
589 else if ( std::string(
argv[
i])==
"-r" || std::string(
argv[
i])==
"--refChain" ) {
594 if (refChain.find(
"+") != string::npos){
595 std::istringstream iss(refChain);
597 while (std::getline(iss, token,
'+')){
598 refChains.push_back(token);
599 refFilters.push_back(0);
603 refChains.push_back(
argv[
i]);
604 refFilters.push_back(0);
607 else if ( std::string(
argv[
i])==
"--rms" ) useoldrms =
false;
608 else if ( std::string(
argv[
i])==
"-n" || std::string(
argv[
i])==
"--nofit" ) nofit =
true;
609 else if ( std::string(
argv[
i])==
"-t" || std::string(
argv[
i])==
"--testChain" ) {
611 testChains.push_back(
argv[
i]);
613 else if ( std::string(
argv[
i])==
"-p" || std::string(
argv[
i])==
"--pdgId" ) {
617 else if ( std::string(
argv[
i])==
"--vr" ) {
619 vertexSelection =
argv[
i];
621 else if ( std::string(
argv[
i])==
"--vt" ) {
623 vertexSelection_rec =
argv[
i];
625 else if ( std::string(
argv[
i])==
"-b" || std::string(
argv[
i])==
"--binConfig" ) {
627 binningConfigFile = std::string(
argv[
i]);
629 else if ( std::string(
argv[
i]).
find(
'-')==0 ) {
631 std::cerr <<
"unknown option " <<
argv[
i] << std::endl;
641 if ( datafile==
"" ) {
642 std::cerr <<
"no config file specifed\n" << endl;
646 std::cout <<
time_str() << std::endl;
655 bool oldrms95 =
true;
656 inputdata.declareProperty(
"OldRMS95", oldrms95 );
657 std::cout <<
"setting Resplot old rms95 " << oldrms95 << std::endl;
661 std::cout <<
"setting Resplot old rms95 " << useoldrms << std::endl;
667 std::cout <<
"Not fitting resplots " << std::endl;
673 inputdata.declareProperty(
"NFiles", nfiles );
676 if ( histofilename==
"" ){
677 if (
inputdata.isTagDefined(
"outputFile") ) histofilename =
inputdata.GetString(
"outputFile");
679 std::cerr <<
"Error: no output file defined\n" << std::endl;
685 TFile foutput( histofilename.c_str(),
"recreate" );
686 if (!foutput.IsOpen()) {
687 std::cerr <<
"Error: could not open output file\n" << std::endl;
693 std::cout <<
"writing output to " << histofilename << std::endl;
695 TH1D* hevent =
new TH1D(
"event",
"event", 1000, 10000, 80000 );
696 Resplot* hcorr =
new Resplot(
"correlation", 21, -0.5, 20.5, 75, 0, 600);
714 bool expectBL =
false;
728 double massMax = 130;
733 bool rotate_testtracks =
false;
735 if (
inputdata.isTagDefined(
"RotateTestTracks") ) rotate_testtracks = (
inputdata.GetValue(
"RotateTestTracks") ? true : false );
737 bool truthMatch =
false;
739 if (
inputdata.isTagDefined(
"TruthMatch") ) truthMatch = (
inputdata.GetValue(
"TruthMatch") ? true : false );
744 std::vector<size_t> refPtOrd_indices;
745 bool use_pt_ordered_ref =
false;
747 if (
inputdata.isTagDefined(
"UsePtOrderedRefTracks") ) {
748 std::vector<double> refPtOrd_indices_tmp;
750 use_pt_ordered_ref =
true;
751 refPtOrd_indices_tmp = (
inputdata.GetVector(
"UsePtOrderedRefTracks") );
753 std::cout <<
"using PT ordered reference tracks: " << refPtOrd_indices_tmp << std::endl;
755 for (
size_t i=refPtOrd_indices_tmp.size();
i-- ; ) {
756 refPtOrd_indices.push_back( refPtOrd_indices_tmp.at(
i) );
778 if (
inputdata.isTagDefined(
"npixholes") ) npixholes =
inputdata.GetValue(
"npixholes");
779 if (
inputdata.isTagDefined(
"nsctholes") ) nsctholes =
inputdata.GetValue(
"nsctholes");
780 if (
inputdata.isTagDefined(
"expectBL") ) expectBL = (
inputdata.GetValue(
"expectBL") > 0.5 ? true : false );
791 if ( pdgId==0 &&
inputdata.isTagDefined(
"pdgId") ) pdgId =
inputdata.GetValue(
"pdgId");
793 if (
inputdata.isTagDefined(
"InvMassMax") ) massMax =
inputdata.GetValue(
"InvMassMax");
794 if (
inputdata.isTagDefined(
"InvMassMin") ) massMin =
inputdata.GetValue(
"InvMassMin");
807 std::string useMatcher =
"DeltaR";
808 if (
inputdata.isTagDefined(
"UseMatcher") ) useMatcher =
inputdata.GetString(
"UseMatcher");
812 if ( refChain==
"" ) {
813 if (
inputdata.isTagDefined(
"refChain") ) {
814 refChain =
inputdata.GetString(
"refChain");
815 refChains.push_back(refChain);
816 refFilters.push_back(0);
819 std::cerr <<
"Error: no reference chain defined\n" << std::endl;
829 if (
inputdata.isTagDefined(
"Exclude") ) {
834 if (refChains.size() == 0){
835 std::cerr <<
"Error: refChains is empty\n" <<std::endl;
840 if ( testChains.size()==0 ) {
841 if (
inputdata.isTagDefined(
"testChains") ) testChains =
inputdata.GetStringVector(
"testChains");
842 else if (
inputdata.isTagDefined(
"testChain") ) testChains.push_back(
inputdata.GetString(
"testChain") );
848 std::vector<ChainString> chainConfig;
850 for (
size_t ic=0 ;
ic<testChains.size() ;
ic++ ) {
852 testChains[
ic] = chainConfig.back().pre();
863 bool select_roi =
true;
869 bool use_custom_ref_roi =
false;
870 const int custRefRoi_nParams = 3;
872 double custRefRoi_params[custRefRoi_nParams] = {-999., -999., -999.};
873 std::vector<std::string> custRefRoi_chainList;
874 std::set<std::string> customRoi_chains;
876 if (
inputdata.isTagDefined(
"customRefRoi_etaHalfWidth") ) custRefRoi_params[0] =
inputdata.GetValue(
"customRefRoi_etaHalfWidth");
877 if (
inputdata.isTagDefined(
"customRefRoi_phiHalfWidth") ) custRefRoi_params[1] =
inputdata.GetValue(
"customRefRoi_phiHalfWidth");
878 if (
inputdata.isTagDefined(
"customRefRoi_zedHalfWidth") ) custRefRoi_params[2] =
inputdata.GetValue(
"customRefRoi_zedHalfWidth");
880 if (
inputdata.isTagDefined(
"customRefRoi_chainList") ) custRefRoi_chainList =
inputdata.GetStringVector(
"customRefRoi_chainList");
882 for (
unsigned ic=0 ;
ic<custRefRoi_chainList.size() ;
ic++ ) customRoi_chains.insert( custRefRoi_chainList[
ic] );
884 for (
int param_idx=0 ; param_idx<custRefRoi_nParams ; param_idx++ ) {
885 if ( custRefRoi_params[param_idx] != -999 ) {
887 use_custom_ref_roi =
true;
891 if ( use_custom_ref_roi ) {
892 std::cout <<
"**** \t****" << std::endl;
893 std::cout <<
"**** Custom RoI will be used to filter ref. tracks\t****" << std::endl;
895 if ( custRefRoi_params[0] != -999. ) std::cout <<
"**** etaHalfWidth = " << custRefRoi_params[0] <<
"\t\t\t\t****" << std::endl;
896 else std::cout <<
"**** etaHalfWidth = value used in trigger RoI\t****" << std::endl;
898 if ( custRefRoi_params[1] != -999. ) std::cout <<
"**** phiHalfWidth = " << custRefRoi_params[1] <<
"\t\t\t\t****" << std::endl;
899 else std::cout <<
"**** phiHalfWidth = value used in trigger RoI\t****" << std::endl;
901 if ( custRefRoi_params[2] != -999. ) std::cout <<
"**** zedHalfWidth = " << custRefRoi_params[2] <<
"\t\t\t\t****" << std::endl;
902 else std::cout <<
"**** zedHalfWidth = value used in trigger RoI\t****" << std::endl;
904 if ( !custRefRoi_chainList.empty() ) {
905 std::cout <<
"**** \t****" << std::endl;
906 std::cout <<
"**** Applying custom RoI only to specified chains\t****" << std::endl;
908 std::cout <<
"**** \t****" << std::endl;
913 if (
inputdata.isTagDefined(
"SelectRoi") ) {
914 select_roi = (
inputdata.GetValue(
"SelectRoi")!=0 ? true : false );
918 std::cout <<
"**** ****" << std::endl;
919 std::cout <<
"**** RoI filtering of reference tracks is disabled ****" << std::endl;
920 std::cout <<
"**** ****" << std::endl;
935 std::vector<std::string> grlvector =
inputdata.GetStringVector(
"GRL");
936 std::cout <<
"Reading GRL from: " << grlvector << std::endl;
937 for (
size_t igrl=0 ; igrl<grlvector.size() ; igrl++ )
goodrunslist.read( grlvector[igrl] );
940 else if (
inputdata.isTagDefined(
"LumiBlocks") ) {
953 if ( vertexSelection ==
"" ) {
954 if (
inputdata.isTagDefined(
"VertexSelection") ) vertexSelection =
inputdata.GetString(
"VertexSelection");
957 bool bestPTVtx =
false;
958 bool bestPT2Vtx =
false;
961 if ( vertexSelection!=
"" ) {
962 if ( vertexSelection==
"BestPT" ) bestPTVtx =
true;
963 else if ( vertexSelection==
"BestPT2" ) bestPT2Vtx =
true;
972 if ( vertexSelection_rec ==
"" ) {
973 if (
inputdata.isTagDefined(
"VertexSelectionRec") ) vertexSelection_rec =
inputdata.GetString(
"VertexSelectionRec");
976 bool bestPTVtx_rec =
false;
977 bool bestPT2Vtx_rec =
false;
980 if ( vertexSelection_rec!=
"" ) {
981 if ( vertexSelection_rec==
"BestPT" ) bestPTVtx_rec =
true;
982 else if ( vertexSelection_rec==
"BestPT2" ) bestPT2Vtx_rec =
true;
983 else vtxind_rec =
atoi_check( vertexSelection_rec );
986 std::cout <<
"vertexSelection: " << vertexSelection << std::endl;
987 std::cout <<
"vertexSelection_rec: " << vertexSelection_rec << std::endl;
995 bool useBestVertex =
false;
996 if (
inputdata.isTagDefined(
"useBestVertex") ) useBestVertex = (
inputdata.GetValue(
"useBestVertex") ? 1 : 0 );
998 bool useSumPtVertex =
true;
999 if (
inputdata.isTagDefined(
"useSumPtVertex") ) useSumPtVertex = (
inputdata.GetValue(
"useSumPtVertex") ? 1 : 0 );
1001 int MinVertices = 1;
1002 if (
inputdata.isTagDefined(
"MinVertices") ) MinVertices =
inputdata.GetValue(
"MinVertices");
1009 bool useVertexTracks =
false;
1010 if (
inputdata.isTagDefined(
"UseVertexTracks") ) useVertexTracks = (
inputdata.GetValue(
"UseVertexTracks") > 0 );
1013 std::string vertex_refname =
"Vertex";
1014 if (
inputdata.isTagDefined(
"VertexReference") ) vertex_refname +=
":" +
inputdata.GetString(
"VertexReference");
1017 int NVtxTrackCut = 2;
1018 if (
inputdata.isTagDefined(
"NVtxTrackCut") ) NVtxTrackCut =
inputdata.GetValue(
"NVtxTrackCut");
1022 bool event_selector_flag =
false;
1028 if ( es.size() ) event_selector_flag =
true;
1031 std::vector<double> beamTest;
1032 std::vector<double> beamRef;
1035 bool correctBeamlineRef =
false;
1036 bool correctBeamlineTest =
false;
1038 if (
inputdata.isTagDefined(
"CorrectBeamlineRef") ) correctBeamlineRef = (
inputdata.GetValue(
"CorrectBeamlineRef") == 0 ? false : true );
1039 if (
inputdata.isTagDefined(
"CorrectBeamlineTest") ) correctBeamlineTest = (
inputdata.GetValue(
"CorrectBeamlineTest") == 0 ? false : true );
1042 if (
inputdata.isTagDefined(
"BeamTest") ) beamTest =
inputdata.GetVector(
"BeamTest");
1044 if (
inputdata.isTagDefined(
"BeamTestx") ) beamTest.push_back(
inputdata.GetValue(
"BeamTestx"));
1045 if (
inputdata.isTagDefined(
"BeamTesty") ) beamTest.push_back(
inputdata.GetValue(
"BeamTesty"));
1051 if (
inputdata.isTagDefined(
"BeamRefx") ) beamRef.push_back(
inputdata.GetValue(
"BeamRefx"));
1052 if (
inputdata.isTagDefined(
"BeamRefy") ) beamRef.push_back(
inputdata.GetValue(
"BeamRefy"));
1057 if ( ( beamTest.size()!=0 && beamTest.size()!=2 && beamTest.size()!=3 ) ||
1058 ( beamRef.size()!=0 && beamRef.size()!=2 && beamRef.size()!=3 ) ) {
1059 std::cerr <<
"incorrectly specified beamline position" << std::endl;
1063 if ( beamTest.size()>0 ) correctBeamlineTest =
true;
1064 if ( beamRef.size()>0 ) correctBeamlineRef =
true;
1066 if ( correctBeamlineRef ) std::cout <<
"main() correcting beamline for reference tracks" << std::endl;
1067 if ( correctBeamlineTest ) std::cout <<
"main() correcting beamline for test tracks" << std::endl;
1071 if ( beamRef.size()>0 ) std::cout <<
"beamref " << beamRef << std::endl;
1072 if ( beamTest.size()>0 ) std::cout <<
"beamtest " << beamTest << std::endl;
1081 double a0vrec = 1000;
1082 double z0vrec = 2000;
1087 bool initialiseFirstEvent =
false;
1088 if (
inputdata.isTagDefined(
"InitialiseFirstEvent") ) initialiseFirstEvent =
inputdata.GetValue(
"InitialiseFirstEvent");
1095 bool doPurity =
false;
1096 if (
inputdata.isTagDefined(
"doPurity") ) doPurity = (
inputdata.GetValue(
"doPurity")==0 ? false : true );
1101 bool monitorZBeam =
false;
1102 if (
inputdata.isTagDefined(
"MonitorinZBeam") ) monitorZBeam = (
inputdata.GetValue(
"MonitorZBeam")==0 ? false : true );
1104 std::cout <<
"dbg " << __LINE__ << std::endl;
1110 if ( binningConfigFile!=
"" ) binningConfig =
new ReadCards( binningConfigFile );
1122 if ( binningConfig!=&
inputdata )
delete binningConfig;
1127 int selectcharge = 0;
1131 std::cout <<
"using reference " << refChain << std::endl;
1132 if ( refChain.find(
"Truth") != string::npos ) std::cout <<
"using pdgId " << pdgId << std::endl;
1133 if ( refChains.size() > 1 ) std::cout<<
"Multiple reference chains split to: " << refChains <<std::endl;
1146 std::cout <<
"a0v: " << a0v << std::endl;
1147 std::cout <<
"z0v: " << z0v << std::endl;
1152 npix, nsct, -1, nbl,
1154 npixholes, nsctholes, nsiholes, expectBL );
1156 if ( selectcharge!=0 ) filter_offline.chargeSelection( selectcharge );
1157 if ( pTMax>
pT ) filter_offline.maxpT( pTMax );
1184 Filter_Track filter_onlinekine( eta_rec, 1000, 0., 2000,
pT, -1, npix, nsct, -1, -2, -2);
1186 Filter_Combined filter_online( &filter_onlinekine, &filter_onlinevertex );
1188 Filter_Track filter_offkinetight( 5, 1000, 0., 2000,
pT, -1, 0, 0, -1, -2, -2);
1189 Filter_Combined filter_offtight( &filter_offkinetight, &filter_inout );
1197 if (
inputdata.isTagDefined(
"Filter" ) ) {
1199 std::cout <<
"Filter: " <<
inputdata.GetString(
"Filter") <<
" : " <<
filter << std::endl;
1200 if (
filter.head()==
"Offline2017" ) {
1201 std::string filter_type =
filter.tail();
1203 filter_off2017 =
new Filter_Combined ( filter_offline2017, &filter_vertex);
1204 refFilter = filter_off2017;
1207 std::cerr <<
"unimplemented Filter requested: " <<
filter.head() << std::endl;
1212 if ( !(refFilter =
getFilter( refChains[0], pdgId, &filter_off, &filter_muon, &filter_truth ) ) ) {
1213 std::cerr <<
"unknown reference chain defined" << std::endl;
1218 refFilters.push_back(refFilter);
1221 std::map<std::string,TIDA::Reference>
ref;
1223 std::vector<NtupleTrackSelector*> refSelectors;
1230 for (
size_t ic=0 ;
ic<refChains.size() ;
ic++ ) {
1232 if ( refFilter==0 ) {
1233 if ( !(refFilters[
ic] =
getFilter( refChains[
ic], pdgId, &filter_off, &filter_muon, &filter_truth ) ) ) {
1234 std::cerr <<
"unknown reference chain defined" << std::endl;
1237 refFilter = refFilters[
ic];
1239 else refFilters[
ic] = refFilter;
1247 if (pdgId==0) truthFilter = &filter_off;
1248 else truthFilter = &filter_truth;
1254 std::cout <<
"filter_passthrough" << std::endl;
1256 Filter_Track filter_passthrough( 10, 1000, 0., 2000, pT_rec, npix_rec, nsct_rec, 1, -2, -2, -2);
1261 std::cout <<
"using tracks: " << refChain <<
" for reference sample" << std::endl;
1267 std::vector<std::string>& test_chains = testChains;
1272 std::map<std::string,TrackAnalysis*> analysis;
1278 std::vector<TrackAnalysis*>
analyses;
1279 analyses.reserve(test_chains.size());
1281 std::cout <<
"booking " << test_chains.size() <<
" analyses" << std::endl;
1283 for (
unsigned i=0 ;
i<test_chains.size() ;
i++ ) {
1287 std::vector<std::string> chainnames;
1289 chainnames.push_back(chainname);
1297 std::string probe_extra = probe.
extra();
1299 if ( probe_extra.empty() ) probe_extra = probe.
postvalue(
"extra");
1301 if ( probe_extra.find(
"_tag")!=std::string::npos || probe.
extra().find(
"_tag")!=std::string::npos ) {
1302 std::cout <<
"rejecting tag chain " << probe << std::endl;
1307 size_t p = probe_extra.find(
"_probe");
1309 if (
p!=std::string::npos ) {
1311 std::string probe_ref = refChains[0];
1313 if ( !probe.
postvalue(
"ref").empty() ) {
1317 if ( refChains[0] != probe_ref ) {
1318 std::cerr <<
"default and probe chain references do not match: probe ref: " << probe_ref <<
" ref: " << refChains[0] << std::endl;
1325 std::string probe_key = probe_extra.erase(
p, 6);
1327 for (
unsigned j=0 ; j<test_chains.size(); ++j) {
1329 if (
i==j )
continue;
1333 if (
tag.head() != probe.
head() )
continue;
1337 std::string tag_extra =
tag.extra();
1339 if ( tag_extra.empty() ) tag_extra =
tag.postvalue(
"extra");
1340 if ( tag_extra.find(
"_tag")==std::string::npos )
continue;
1343 std::string tag_key = tag_extra.erase( tag_extra.find(
"_tag"), 4) ;
1346 if ( tag_key != probe_key )
continue;
1348 if (
tag.element() == probe.
element() )
continue;
1350 std::string tag_ref = refChains[0];
1358 if ( !
tag.postvalue(
"ref").empty() ) {
1360 tag_ref =
tag.postvalue(
"ref");
1363 std::cout <<
"tag ref: " << tag_ref << std::endl;
1365 if (
ref.find(tag_ref)==
ref.end() ) {
1376 TnP_tool =
new TagNProbe( tag_ref, probe_ref, massMin, massMax);
1378 TnP_tool->
probe(probe);
1379 std::cout <<
"Tag and probe pair found! \n\t Tag : " <<
tag <<
"\n\t Probe : " << probe
1380 <<
"\n\t tag ref: " << tag_ref
1381 <<
"\n\tprobe ref: " << probe_ref
1382 <<
"\n-------------------" << std::endl;
1393 if ( TnP_tool )
replace( chainname,
"/",
"_" );
1400 std::string vtxTool = chainConfig[
i].postvalue(
"rvtx");
1402 if ( vtxTool!=
"" ) {
1407 analy_conf->
store().
insert( anal_confvtx,
"rvtx" );
1424 std::cout <<
"chain:: " << chainname <<
" : size " << chainConfig[
i].values().size() << std::endl;
1425 for (
unsigned ik=chainConfig[
i].
values().
size() ; ik-- ; ) {
1426 std::cout <<
"\tchainconfig: " << ik <<
"\tkey " << chainConfig[
i].keys()[ik] <<
" " << chainConfig[
i].values()[ik] << std::endl;
1433 if ( analysis.find( chainname )==analysis.end() ) {
1434 analysis.insert( std::map<std::string,TrackAnalysis*>::value_type( chainname, analy_conf ) );
1438 std::cerr <<
"WARNING: Duplicated chain"
1440 <<
"---------------------------------"
1441 <<
"---------------------------------"
1442 <<
"---------------------------------" << std::endl;
1446 std::cout <<
"analysis: " << chainname <<
"\t" << analy_conf
1448 <<
"---------------------------------"
1449 <<
"---------------------------------"
1450 <<
"---------------------------------" << std::endl;
1454 std::cout <<
"purity " << (chainnames[0]+
"-purity") << std::endl;
1458 analysis[chainnames[0]+
"-purity"] = analp;
1464 std::cout <<
"main() finished looping" << std::endl;
1468 bool fullyContainTracks =
false;
1470 if (
inputdata.isTagDefined(
"FullyContainTracks") ) {
1471 fullyContainTracks = (
inputdata.GetValue(
"FullyContainTracks")==0 ? false : true );
1474 bool containTracksPhi =
true;
1476 if (
inputdata.isTagDefined(
"ContainTracksPhi") ) {
1477 containTracksPhi = (
inputdata.GetValue(
"ContainTracksPhi")==0 ? false : true );
1482 dynamic_cast<Filter_Combined*
>(refFilter)->containtracks(fullyContainTracks);
1483 dynamic_cast<Filter_Combined*
>(refFilter)->containtracksPhi(containTracksPhi);
1500 bool filterRoi =
false;
1503 bool roicomposite =
false;
1506 if (
inputdata.isTagDefined(
"FilterRoi" ) ) {
1510 std::vector<double> filter_values =
inputdata.GetVector(
"FilterRoi" );
1512 if ( filter_values.size()>0 ) roieta = filter_values[0];
1513 if ( filter_values.size()>1 ) roicomposite = ( filter_values[1]==0 ? false : true );
1514 if ( filter_values.size()>2 ) roimult =
int(filter_values[2]+0.5);
1518 RoiFilter roiFilter( roieta, roicomposite, roimult );
1525 else if ( useMatcher ==
"DeltaRZ" || useMatcher ==
"DeltaRZSinTheta" ) {
1529 if (
inputdata.isTagDefined(
"Matcher_deta" ) ) deta =
inputdata.GetValue(
"Matcher_deta");
1530 if (
inputdata.isTagDefined(
"Matcher_dphi" ) ) dphi =
inputdata.GetValue(
"Matcher_dphi");
1531 if (
inputdata.isTagDefined(
"Matcher_dzed" ) ) dzed =
inputdata.GetValue(
"Matcher_dzed");
1536 else if ( useMatcher ==
"pT_2" ) {
1537 double pTmatchLim_2 = 1.0;
1538 if (
inputdata.isTagDefined(
"Matcher_pTLim_2") ) pTmatchLim_2 =
inputdata.GetValue(
"Matcher_pTLim_2");
1541 else if ( useMatcher ==
"Truth" ) {
1554 else if ( useMatcher ==
"DeltaRZ" || useMatcher ==
"DeltaRZSinTheta" ) {
1558 if (
inputdata.isTagDefined(
"Matcher_deta" ) ) deta =
inputdata.GetValue(
"Matcher_deta");
1559 if (
inputdata.isTagDefined(
"Matcher_dphi" ) ) dphi =
inputdata.GetValue(
"Matcher_dphi");
1560 if (
inputdata.isTagDefined(
"Matcher_dzed" ) ) dzed =
inputdata.GetValue(
"Matcher_dzed");
1565 else if ( useMatcher ==
"pT_2" ) {
1566 double pTmatchLim_2 = 1.0;
1567 if (
inputdata.isTagDefined(
"Matcher_pTLim_2") ) pTmatchLim_2 =
inputdata.GetValue(
"Matcher_pTLim_2");
1570 else if ( useMatcher ==
"Truth" ) {
1594 if (
inputdata.isTagDefined(
"DataSets") ) {
1596 std::cout <<
"fetching dataset details" << std::endl;
1597 std::vector<std::string> datasets =
inputdata.GetStringVector(
"DataSets");
1598 for (
unsigned int ids=0 ;
ids<datasets.size() ;
ids++ ) {
1599 std::cout <<
"\tdataset " << datasets[
ids] << std::endl;
1601 std::vector<std::string> filenames_ =
d.datafiles();
1602 std::cout <<
"\tdataset contains " << filenames_.size() <<
" files" << std::endl;
1608 std::cerr <<
"no input data specified" << std::endl;
1618 bool show_release =
true;
1620 std::vector<std::string> release_data;
1622 std::string release_data_save =
"";
1624 if ( show_release ){
1630 TFile* finput = TFile::Open(
filenames[
i].c_str() );
1633 if ( finput==0 || !finput->IsOpen() || finput->IsZombie() ) {
1634 std::cerr <<
"Error: could not open input file: " <<
filenames[
i] << std::endl;
1638 TTree* dataTree = (TTree*)finput->Get(
"dataTree");
1639 TString* releaseData =
new TString(
"");
1642 dataTree->SetBranchAddress(
"ReleaseMetaData", &releaseData);
1644 for (
unsigned int i=0;
i<dataTree->GetEntries() ;
i++ ) {
1645 dataTree->GetEntry(
i);
1646 release_data.push_back( releaseData->Data() );
1647 if ( release_data_save != release_data.back() ) {
1648 std::cout <<
"main() release data: " << release_data.back() <<
" : " << *releaseData << std::endl;
1651 release_data_save = release_data.back();
1655 if ( finput )
delete finput;
1660 if ( !release_data.empty() ) {
1661 std::sort(release_data.begin(), release_data.end());
1662 release_data.erase(std::unique(release_data.begin(), release_data.end()), release_data.end());
1668 TTree* dataTree =
new TTree(
"dataTree",
"dataTree");
1669 TString* releaseData =
new TString(
"");
1672 dataTree->Branch(
"ReleaseMetaData",
"TString", &releaseData);
1674 for (
unsigned ird=0 ; ird<release_data.size() ; ird++ ) {
1675 *releaseData = release_data[ird];
1679 dataTree->Write(
"", TObject::kOverwrite);
1697 if ( Nentries==0 &&
inputdata.isTagDefined(
"Nentries") ) {
1703 typedef std::pair<int,double> zpair;
1704 std::vector<zpair> refz;
1705 std::vector<zpair> testz;
1707 std::vector<double> beamline_ref;
1708 std::vector<double> beamline_test;
1713 std::cout <<
"opening files" << std::endl;
1717 int pregrl_events = 0;
1718 int grl_counter = 0;
1721 std::cout <<
"starting event loop " <<
time_str() << std::endl;
1725 if ( nfiles!=0 && nfiles<max_files ) max_files = nfiles;
1734 if ( finput==0 || !finput->IsOpen() || finput->IsZombie() ) {
1735 std::cerr <<
"Error: could not open output file " <<
filenames[
ifile] << std::endl;
1739 TTree*
data = (TTree*)finput->Get(
"tree");
1742 std::cerr <<
"Error: cannot open TTree: " <<
filenames[
ifile] << std::endl;
1750 data->SetBranchAddress(
"TIDA::Event",&track_ev);
1756 unsigned cNentries =
data->GetEntries();
1762 for (
unsigned int i=0;
skip &&
run &&
i<cNentries ;
i++ ) {
1784 if ( !ingrl )
continue;
1790 if ( event_selector_flag && !es.in(
event ) )
continue;
1792 if ( mintime>
ts ) mintime =
ts;
1793 if ( maxtime<
ts ) maxtime =
ts;
1797 std::cout <<
"breaking out " <<
run << std::endl;
1807 hevent->Fill(
event );
1810 if ( (cNentries<10) ||
i%(cNentries/10)==0 ||
i%1000==0 ||
debugPrintout ) {
1811 std::cout <<
"run " << track_ev->
run_number()
1814 <<
"\tchains " << track_ev->
chains().size()
1816 std::cout <<
"\t : processed " <<
i <<
" events so far (" <<
int((1000*
i)/cNentries)*0.1 <<
"%)\t" <<
time_str() << std::endl;
1823 if ( nfiles>0 ) pfiles = nfiles;
1826 std::cout <<
"file entries=" <<
data->GetEntries();
1828 if (
data->GetEntries()<100 ) std::cout <<
" ";
1829 if (
data->GetEntries()<1000 ) std::cout <<
" ";
1830 if (
data->GetEntries()<10000 ) std::cout <<
" ";
1835 std::cout <<
"run " << track_ev->
run_number()
1838 <<
"\tchains " << track_ev->
chains().size()
1841 std::cout <<
"\t : processed " <<
ifile <<
" files so far (" <<
int((1
e3*
ifile)/pfiles)*0.1 <<
"%)\t" <<
time_str() << std::endl;
1854 truthTracks.clear();
1855 refPurityTracks.clear();
1859 mit->second.selector()->clear();
1865 const std::vector<TIDA::Chain>&
chains = track_ev->
chains();
1872 truthTracks.selectTracks(
chains[
ic][0].tracks() );
1879 for (
const std::string& rc : refChains){
1882 offTracks.selectTracks(
chains[
ic][0].tracks() );
1884 beamline_ref =
chains[
ic][0].user();
1893 std::vector<TIDA::Vertex> vertices;
1897 if ( vtxchain && vtxchain->
size()>0 ) {
1899 const std::vector<TIDA::Vertex>& mv = vtxchain->
at(0).
vertices();
1904 if (
debugPrintout ) std::cout <<
"vertices:\n" << mv << std::endl;
1906 if ( bestPTVtx || bestPT2Vtx ) {
1907 for (
size_t iv=0 ; iv<mv.size() ; iv++ ) {
1908 if ( mv[iv].Ntracks()==0 )
continue;
1909 double selection_ = 0.0;
1911 vtx_temp.selectTracks( offTracks.tracks() );
1912 for (
unsigned itr=0; itr<vtx_temp.tracks().
size(); itr++) {
1914 if ( bestPTVtx ) selection_ += std::fabs(tr->
pT());
1915 else if ( bestPT2Vtx ) selection_ += std::fabs(tr->
pT())*std::fabs(tr->
pT());
1922 if ( selectvtx!=-1 ) {
1923 vertices.push_back( mv[selectvtx] );
1926 else if ( vtxind>=0 ) {
1927 if (
size_t(vtxind)<mv.size() ) {
1928 vertices.push_back( mv[vtxind] );
1932 for (
size_t iv=0 ; iv<mv.size() ; iv++ ) {
1933 vertices.push_back( mv[iv] );
1938 filter_vertex.setVertex( vertices );
1944 for (
unsigned iv=0 ; iv<mv.size() ; iv++ ) {
1945 int Ntracks = mv[iv].Ntracks();
1946 if ( Ntracks>NVtxTrackCut ) {
1963 bool foundReference =
false;
1972 for (
const std::string& rc : refChains ) {
1981 std::string refname = mitr->first;
1990 *mitr->second.tom() = rtom;
2004 if ( !foundReference )
continue;
2007 std::cout <<
"reference chain:\n" << *refchain << std::endl;
2021 if ( analitr==analysis.end() )
continue;
2024 std::cout <<
"test chain:\n" <<
chain << std::endl;
2029 std::vector<TIDA::Roi*>
rois;
2049 if ( TnP_tool->
type0() == TnP_tool->
type1() ) {
2051 rois = TnP_tool->
GetRois( track_ev->
chains(), selector0, filter0, invmass, invmass_obj, rtom );
2065 for (
size_t ia=0 ; ia<selector1->
tracks().size() ; ia++ ) {
2067 std::cout << ia <<
"\t" << *
track << std::endl;
2068 std::cout <<
"\t" << rtom1->
object(
track->id()) << std::endl;
2071 std::cout << *TnP_tool << std::endl;
2074 rois = TnP_tool->
GetRois( track_ev->
chains(), selector0, filter0, selector1, filter1, invmass, invmass_obj, rtom, rtom1 );
2084 if (
false ) std::cout <<
"++++++++++++ rois size = " <<
rois.size() <<
" +++++++++++" << std::endl;
2087 for (
unsigned int ir=0 ;
ir<
rois.size() ;
ir++ ) {
2097 testTracks.selectTracks( troi.
tracks() );
2100 std::vector<TIDA::Track*> testp = testTracks.tracks();
2105 if ( filterRoi && !roiFilter.filter( roi ) )
continue;
2108 const std::vector<TIDA::Vertex>& mvt = troi.
vertices();
2110 std::vector<TIDA::Vertex> vertices_test;
2115 if ( bestPTVtx_rec || bestPT2Vtx_rec ) {
2119 for (
unsigned iv=0 ; iv<mvt.size() ; iv++ ) {
2120 double selection_ = 0.0;
2122 vtx_temp.selectTracks( testp );
2123 for (
unsigned itr=0; itr<vtx_temp.tracks().
size(); itr++) {
2125 if ( bestPTVtx ) selection_ += std::fabs(tr->
pT());
2126 else if ( bestPT2Vtx ) selection_ += std::fabs(tr->
pT())*std::fabs(tr->
pT());
2133 if ( selectvtx!=-1 ) {
2135 if ( useVertexTracks ) selected.selectTracks( testp );
2136 vertices_test.push_back(selected);
2139 else if ( vtxind_rec!=-1 ) {
2140 if (
unsigned(vtxind_rec)<mvt.size() ) {
2142 if ( useVertexTracks ) selected.selectTracks( testp );
2143 vertices_test.push_back( selected );
2147 for (
unsigned iv=0 ; iv<mvt.size() ; iv++ ) {
2149 if ( useVertexTracks ) selected.selectTracks( testp );
2150 vertices_test.push_back( selected );
2155 beamline_test =
rois[
ir]->user();
2162 if ( correctBeamlineTest ) {
2163 if ( beamTest.size()==2 ) analy_track->
setBeamTest( beamTest[0], beamTest[1] );
2166 if ( !
inputdata.isTagDefined(
"BeamTest") ) {
2167 if ( beamline_test.size()==2 ) analy_track->
setBeamTest( beamline_test[0], beamline_test[1] );
2173 if ( correctBeamlineRef ) {
2174 if ( beamRef.size()==2 ) analy_track->
setBeamRef( beamRef[0], beamRef[1] );
2177 if ( !
inputdata.isTagDefined(
"BeamRef") ) {
2178 if ( beamline_ref.size()==2 ) analy_track->
setBeamRef( beamline_ref[0], beamline_ref[1] );
2197 bool customRefRoi_thisChain =
false;
2199 if ( use_custom_ref_roi ) {
2200 if ( customRoi_chains.size() ) {
2201 if ( customRoi_chains.find(
chain.name() )!=customRoi_chains.end() ) customRefRoi_thisChain =
true;
2203 else customRefRoi_thisChain =
true;
2206 if ( use_custom_ref_roi && customRefRoi_thisChain ) {
2207 refRoi =
makeCustomRefRoi( roi, custRefRoi_params[0], custRefRoi_params[1], custRefRoi_params[2] );
2223 std::vector<TIDA::Track*> refp_vec = refTracks.tracks( refFilter );
2228 if ( select_roi )
dynamic_cast<Filter_Combined*
>(truthFilter)->setRoi(&roi);
2229 const std::vector<TIDA::Track*>& truth = truthTracks.tracks(truthFilter);
2230 const std::vector<TIDA::Track*>& refp_tmp = refp_vec;
2233 truth_matcher->
match( refp_tmp, truth );
2235 std::vector<TIDA::Track*> refp_matched;
2238 for (
unsigned i=0 ;
i<refp_vec.size() ;
i++ ) {
2239 if ( truth_matcher->
matched( refp_vec[
i] ) ) refp_matched.push_back( refp_vec[
i] );
2243 refp_vec = refp_matched;
2247 if ( use_pt_ordered_ref ) {
2250 size_t nRefTracks = refp_vec.size();
2252 std::vector<TIDA::Track*> refp_chosenPtOrd;
2256 for (
size_t sidx=refPtOrd_indices.size() ; sidx-- ; ) {
2257 if ( refPtOrd_indices.at(sidx)>nRefTracks ) {
2258 std::cout <<
"WARNING: for event " <<
event
2259 <<
", pT ordered reference track at vector position " << refPtOrd_indices.at(sidx)
2260 <<
" requested but not found" << std::endl;
2266 for (
size_t sidx=refPtOrd_indices.size() ; sidx-- ; ) {
2267 for (
size_t idx=0 ;
idx<refp_vec.size() ;
idx++ ) {
2268 if (
idx == refPtOrd_indices.at(sidx) ) {
2269 refp_chosenPtOrd.push_back(refp_vec.at(
idx));
2276 refp_vec = refp_chosenPtOrd;
2287 if ( ptconfig!=
"" ) {
2290 std::vector<TIDA::Track*> reft; reft.reserve(refp_vec.size());
2291 for ( std::vector<TIDA::Track*>::const_iterator itr=refp_vec.begin() ; itr!=refp_vec.end() ; ++itr ) {
2292 if ( std::fabs((*itr)->pT())>=
pt ) reft.push_back( *itr );
2301 if ( d0config!=
"" ) {
2304 std::vector<TIDA::Track*> reft; reft.reserve(refp_vec.size());
2305 for ( std::vector<TIDA::Track*>::const_iterator itr=refp_vec.begin() ; itr!=refp_vec.end() ; ++itr ) {
2306 if ( std::fabs((*itr)->a0())<=
d0 ) reft.push_back( *itr );
2323 if ( objectET !=
"" ) {
2325 double ETconfig =
std::atof( objectET.c_str() );
2331 while ( itr!=refp_vec.end() ) {
2334 if ( tobj==0 || tobj->
pt()<ETconfig )
2335 itr=refp_vec.erase( itr );
2343 const std::vector<TIDA::Track*>& refp = refp_vec;
2360 std::vector<TIDA::Vertex> vertices_roi;
2368 vertices_roi.clear();
2370 const std::vector<TIDA::Vertex>& mv = vertices;
2375 for (
unsigned iv=0 ; iv<mv.size() ; iv++ ) {
2381 bool accept_vertex =
false;
2382 if ( roi.composite() ) {
2383 for (
size_t ir=0 ;
ir<roi.size() ;
ir++ ) {
2384 if ( roi[
ir]->zedMinus()<=vx.
z() && roi[
ir]->zedPlus()>=vx.
z() ) accept_vertex =
true;
2388 if ( roi.zedMinus()<=vx.
z() && roi.zedPlus()>=vx.
z() ) accept_vertex =
true;
2391 if ( !accept_vertex )
continue;
2397 if ( useVertexTracks ) {
2400 vertex_roi.selectTracks( refp );
2401 trackcount = vertex_roi.Ntracks();
2402 if ( trackcount>=ntracks && trackcount>0 ) {
2403 vertices_roi.push_back( vertex_roi );
2408 for (
unsigned itr=0; itr<refp.size(); itr++){
2411 double dzsintheta = std::fabs( (vx.
z()-tr->
z0()) *
std::sin(theta_) );
2412 if( dzsintheta < 1.5 ) trackcount++;
2417 if ( trackcount>=ntracks && trackcount>0 ) {
2419 vertices_roi.push_back( vertex_roi );
2427 if ( rotate_testtracks )
for (
size_t i=testp.size() ;
i-- ; ) testp[
i]->rotate();
2433 if ( monitorZBeam ) {
2434 if ( beamline_ref.size()>2 && beamline_test.size()>2 ) {
2435 refz.push_back( zpair(
lb, beamline_ref[2]) );
2436 testz.push_back( zpair(
lb, beamline_test[2]) );
2440 matcher->
match( refp, testp);
2442 if ( tom.
status() ) analitr->second->execute( refp, testp, matcher, &tom );
2443 else analitr->second->execute( refp, testp, matcher );
2446 analitr->second->store().find( vtxanal,
"rvtx" );
2450 if ( vtxanal && ( refp.size() >=
size_t(ntracks) ) ) {
2469 std::cout <<
"\nselected tracks:" <<
chain.name() << std::endl;
2470 std::cout <<
"ref tracks refp.size() " << refp.size() <<
"\n" << refp << std::endl;
2471 std::cout <<
"test tracks testp.size() " << testp.size() <<
"\n" << testp << std::endl;
2473 TrackAssociator::map_type::const_iterator titr = matcher->TrackAssociator::matched().begin();
2474 TrackAssociator::map_type::const_iterator
tend = matcher->TrackAssociator::matched().end();
2476 std::cout <<
"track matches:\n";
2477 while (titr!=
tend) {
2478 std::cout <<
"\t" <<
im++ <<
"\t" << *titr->first <<
" ->\n\t\t" << *titr->second << std::endl;
2483 std::cout <<
"completed : " <<
chain.name() <<
"\n";
2484 std::cout <<
"-----------------------------------" << std::endl;
2489 if ( _matcher->size()<refp.size() ) {
2491 if ( refp.size()==1 && testp.size()==0 ) {
2492 std::cout << track_ev->
chains()[
ic] <<std::endl;
2493 std::cout <<
"roi\n" << track_ev->
chains()[
ic].rois()[
ir] << endl;
2503 const std::vector<TIDA::Track*>& refpp = refPurityTracks.tracks( refFilter );
2505 testPurityTracks.clear();
2507 testPurityTracks.selectTracks( troi.
tracks() );
2508 std::vector<TIDA::Track*> testpp = testPurityTracks.tracks();
2510 matcher->
match(refpp, testpp);
2515 if ( analitrp == analysis.end() )
continue;
2518 analitrp->second->execute( refpp, testpp, matcher );
2539 <<
"\ttimes " << mintime <<
" " << maxtime
2540 <<
"\t( grl: " << grl_counter <<
" / " << pregrl_events <<
" )" << std::endl;
2542 if ( monitorZBeam )
zbeam zb( refz, testz );
2556 analyses[
i]->store().find( vtxanal,
"rvtx" );
2557 if ( vtxanal ) vtxanal->
finalise();
2568 mit->second.Clean();
2572 if ( ex_matcher )
delete ex_matcher;
2574 std::cout <<
"done" << std::endl;