14 #include "GaudiKernel/MsgStream.h"
33 for (Long64_t jentry=0; jentry<
nentries;jentry++) {
36 Long64_t centry =
tree.LoadTree(jentry);
37 if (centry < 0)
return;
38 tree.GetEntry(jentry);
41 if( jentry%1000 == 0 ){
42 if (
log.level()<=MSG::INFO) {
43 log << MSG::INFO <<
" new event " << jentry <<
endmsg;
50 typedef std::map<int,std::vector<int> > TrackMap;
51 auto fillTrackMap = [](
const std::vector<int>& trkids, TrackMap& trackMap ){
52 for(
unsigned int i=0;
i<trkids.size();++
i){
53 trackMap[ trkids[
i] ].push_back(
i);
57 TrackMap track_seg_map;
60 TrackMap track_hough_map;
63 TrackMap track_hit_map;
66 TrackMap track_time_map;
69 TrackMap track_candidate_map;
86 for(
int ii=0;ii<3;++ii ){
105 unsigned int ntruth = 0;
106 unsigned int nseg = 0;
107 unsigned int nseg1 = 0;
108 unsigned int nseg2 = 0;
109 unsigned int nseg3 = 0;
110 unsigned int nhough = 0;
114 if(
pos != track_seg_map.end() ) {
122 pos = track_hough_map.find(
i);
123 if(
pos != track_hough_map.end() ) {
128 pos = track_hit_map.find(
i);
129 if(
pos != track_hit_map.end() ) {
134 pos = track_time_map.find(
i);
135 if(
pos != track_time_map.end() ) {
141 if( matchingStrategy ==
SameTrack || matchingStrategy ==
All ) {
143 trackPlots->
fill(ntruth,nseg,nseg1,nseg2,nseg3,nhough);
145 pos = track_candidate_map.find(
i);
150 std::pair<unsigned int,unsigned int> candidateCounts(0,0);
152 if( candidateCounts.first == 0 ) {
153 plots.etaMissed->Fill(eta);
154 plots.etaBetaMissed->Fill(eta,betaTruth);
155 plots.betaMissed->Fill(betaTruth);
157 if( candidateCounts.second == 0 ) {
158 plots.etaMissedCombined->Fill(eta);
159 plots.betaMissedCombined->Fill(betaTruth);
161 plots.ncandidates->Fill(candidateCounts.first);
162 plots.ncombinedCandidates->Fill(candidateCounts.second);
165 if( nseg3 < 2 )
continue;
167 pos = track_time_map.find(
i);
168 if(
pos != track_time_map.end() ) {
173 for(
unsigned int co=0;co<2;++co ){
177 if( betaFitResult.
status != 0 ) betaRegionPlots.
mdt.
fill( betaFitResult.
beta, betaTruth, betaFitResult.
chi2, betaFitResult.
ndof );
182 if( betaFitResult.
status != 0 ) betaRegionPlots.
rpc.
fill( betaFitResult.
beta, betaTruth, betaFitResult.
chi2, betaFitResult.
ndof );
186 if( betaFitResult.
status != 0 ) betaRegionPlots.
rpct.
fill( betaFitResult.
beta, betaTruth, betaFitResult.
chi2, betaFitResult.
ndof );
190 if( betaFitResult.
status != 0 ) betaRegionPlots.
all.
fill( betaFitResult.
beta, betaTruth, betaFitResult.
chi2, betaFitResult.
ndof );
194 if( betaFitResult.
status != 0 ) {
195 betaRegionPlots.
allt.
fill( betaFitResult.
beta, betaTruth, betaFitResult.
chi2, betaFitResult.
ndof );
202 if( betaFitResult.
status != 0 ) {
203 betaRegionPlots.
mdtt.
fill( betaFitResult.
beta, betaTruth, betaFitResult.
chi2, betaFitResult.
ndof );
215 const std::vector<int>& indexVec,
225 int bestTagCandidateIndex = -1;
226 float bestRes = FLT_MAX;
227 int bestCombinedCandidateIndex = -1;
228 float bestCombinedRes = FLT_MAX;
229 unsigned int ncandidates = 0;
230 unsigned int ncombinedCandidates = 0;
231 for( std::vector<int>::const_iterator
it=indexVec.begin();
it!=indexVec.end();++
it ){
241 float res = std::abs(
beta-betaTruth);
248 if(
res < bestCombinedRes ){
249 bestCombinedRes =
res;
250 bestCombinedCandidateIndex = *
it;
254 ++ncombinedCandidates;
258 bestTagCandidateIndex = *
it;
265 if( bestCombinedCandidateIndex != -1 ){
270 if( bestTagCandidateIndex != -1 ){
274 int bestCandidateIndex = bestCombinedCandidateIndex != -1 ? bestCombinedCandidateIndex : bestTagCandidateIndex;
275 if( bestCandidateIndex != -1 ){
279 return std::make_pair(ncandidates,ncombinedCandidates);
283 const std::vector<int>& indexVec,
int stage,
287 unsigned int nseg = 0;
291 for( std::vector<int>::const_iterator
it=indexVec.begin();
it!=indexVec.end();++
it ){
297 if( !
testStrategy(matchingStrategy,sameTrack) )
continue;
309 unsigned int nhough = 0;
312 for( std::vector<int>::const_iterator
it=indexVec.begin();
it!=indexVec.end();++
it ){
316 if( !
testStrategy(matchingStrategy,sameTrack) )
continue;
334 std::map<int,int> countsPerLayer;
336 for( std::vector<int>::const_iterator
it=indexVec.begin();
it!=indexVec.end();++
it ){
340 if( !
testStrategy(matchingStrategy,sameTrack) )
continue;
346 unsigned int nlayers = 0;
348 if(
it->second>2 )++nlayers;
354 if( matchingStrategy ==
SameTrack && !sameTrack )
return false;
355 if( matchingStrategy ==
NotSameTrack && sameTrack )
return false;
370 for( std::vector<int>::const_iterator
it=indexVec.begin();
it!=indexVec.end();++
it ){
374 if (
log.level()<=MSG::WARNING)
log << MSG::WARNING <<
"index out of range: " << (*it) <<
" max " << ntuple.
timeBlock.
type->size() <<
endmsg;
384 if( !
plots )
continue;
390 const std::vector<int>& indexVec,
const std::set<int>& types ) {
393 std::map<int,TimePointBetaFitter::HitVec> hitsPerCandidate;
397 for( std::vector<int>::const_iterator
it=indexVec.begin();
it!=indexVec.end();++
it ){
400 if (
log.level()<=MSG::WARNING)
log << MSG::WARNING <<
"index out of range: " << (*it) <<
" max " << ntuple.
timeBlock.
type->size() <<
endmsg;
406 if( !types.count(
type) )
continue;
416 if( hitsPerCandidate.size() > 1 ){
417 if (
log.level()<=MSG::INFO)
log << MSG::INFO <<
"multple candidates for track " << hitsPerCandidate.size() <<
endmsg;
421 for( ;cit!=cit_end;++cit ){
426 float chi2ndof = candidateResult.
chi2/candidateResult.
ndof;
427 if (
log.level()<=MSG::INFO) {
428 if(
hits.size() > 1 && candidateResult.
status != 0 && chi2ndof>5 ){
430 log << MSG::INFO <<
"Beta " << candidateResult.
beta <<
" of fit for types ";
431 for(
auto type : types ) std::cout <<
" " <<
type;
432 log << MSG::INFO <<
" with large chi2 " << chi2ndof <<
" hits " <<
hits.size() <<
endmsg;
433 for(
auto& hit :
hits ){
434 const char*
text = hit.useInFit ?
" hit " :
" outlier ";
435 log << MSG::INFO <<
text <<
": dist "<< std::setw(7) << (
int)hit.distance
436 <<
" time " << std::setprecision(3) << std::setw(6) << hit.time - betaUtils.
calculateTof(1.,hit.distance)
437 <<
" beta " << std::setw(6) << betaUtils.
calculateBeta(hit.time,hit.distance)
438 <<
" error " << std::setw(6) << hit.error <<
" residual " << std::setw(6) << hit.residual <<
" pull " << std::setw(6) << hit.residual/hit.error <<
endmsg;
442 if( candidateResult.
status != 0 ){