22 #ifdef DO_TPCCATRACKER_EFF_PERFORMANCE 
   33 #ifndef HLTCA_STANDALONE 
   46 #include "Riostream.h" 
   53 PndCAPerformance::PndCAPerformance()
 
   55   static bool first_call = 
true;
 
   58     typedef TSubPerformance TSP;
 
   62     const int NSPerfo = 1;
 
   63     const TSP perfos[NSPerfo] = {
 
   67     subPerformances.resize(NSPerfo);
 
   68     for (
int iP = 0; iP < NSPerfo; iP++){
 
   69       subPerformances[iP] = perfos[iP];
 
   76 PndCAPerformance::~PndCAPerformance()
 
   81   for (
unsigned int iPerf = 0; iPerf < subPerformances.size(); iPerf++){ 
 
   82     if (subPerformances[iPerf].perf) 
delete subPerformances[iPerf].perf;
 
   86 PndCAPerformance &PndCAPerformance::Instance()
 
   89   static PndCAPerformance gPndCAPerformance;
 
   90   return gPndCAPerformance;
 
   93 bool PndCAPerformance::SetNewEvent(
PndCAGBTracker* 
const tracker, 
string mcTracksFile, 
string mcPointsFile)
 
   97   FILE *
file = std::fopen( mcTracksFile.data(), 
"rb" );
 
  104   file = std::fopen( mcPointsFile.data(), 
"rb" );
 
  108    ReadLocalMCPoints( file );
 
  114 void PndCAPerformance::InitSubPerformances()
 
  117   static bool first_call = 
true;
 
  119   for (
unsigned int iPerf = 0; iPerf < subPerformances.size(); iPerf++){
 
  120     subPerformances[iPerf]->SetNewEvent(fTracker, &fHitLabels, &fMCTracks, &fLocalMCPoints);
 
  123   if (first_call) CreateHistos();
 
  128 void PndCAPerformance::CreateHistos()
 
  130   for (
unsigned int iPerf = 0; iPerf < subPerformances.size(); iPerf++){
 
  131     if(!(subPerformances[iPerf]->IsHistoCreated())) 
 
  132       subPerformances[iPerf]->CreateHistos(subPerformances[iPerf].
name, fOutputFile);
 
  136 bool PndCAPerformance::CreateHistos(
string name)
 
  139   for( ; i < (subPerformances.size()) && (subPerformances[i].name != name); i++);
 
  140   if(!(subPerformances[i]->IsHistoCreated()) && i != subPerformances.size()) 
 
  141     subPerformances[i]->CreateHistos(subPerformances[i].name, fOutputFile);
 
  142   if ( i == subPerformances.size() ) 
return 0;
 
  147 void PndCAPerformance::WriteDir2Current( TObject *
obj )
 
  150   if ( !obj->IsFolder() ) obj->Write();
 
  152     TDirectory *cur = gDirectory;
 
  153     ((TDirectory*)obj)->cd();
 
  154     TList *listSub = ( ( TDirectory* )obj )->GetList();
 
  156     while ( TObject *obj1 = it() ) WriteDir2Current( obj1 );
 
  162 void PndCAPerformance::WriteHistos()
 
  164   if(fOutputFile) WriteDir2Current(fOutputFile);
 
  167 void PndCAPerformance::ExecPerformance()
 
  171   for (
unsigned int iPerf = 0; iPerf < subPerformances.size(); iPerf++){
 
  172     if(subPerformances[iPerf].IsGlobalPerf) subPerformances[iPerf]->Exec(0);
 
  174 #if 1  // current event efficiencies 
  175   for (
unsigned int iPerf = 0; iPerf < subPerformances.size(); iPerf++){    
 
  177         << 
" ---- " << subPerformances[iPerf].name << 
" event " << fStatNEvents << 
" ---- "<< endl;
 
  178     subPerformances[iPerf]->PrintEfficiency();
 
  180   cout << endl << 
" ============================== " << endl;
 
  182   for (
unsigned int iPerf = 0; iPerf < subPerformances.size(); iPerf++){  
 
  184         << 
" ---- " << subPerformances[iPerf].name << 
" " << fStatNEvents << 
" events Statistic ---- " << endl;
 
  185     if(subPerformances[iPerf].IsGlobalPerf) subPerformances[iPerf]->PrintEfficiencyStatistic();
 
  190 PndCAPerformanceBase* PndCAPerformance::GetSubPerformance(
string name)
 
  193   for( ; (i < subPerformances.size()) && (subPerformances[i].name != name); i++);
 
  195   if ( i == subPerformances.size() ) 
return 0;
 
  196   return subPerformances[
i].perf;
 
  201 void PndCAPerformance::WriteMCEvent( FILE *file )
 const 
  204   int n = fMCTracks.size();
 
  205   std::fwrite( &n, 
sizeof( 
int ), 1, file );
 
  206   n = fHitLabels.size();
 
  207   std::fwrite( &n, 
sizeof( 
int ), 1, file );
 
  208   std::fwrite( &fMCTracks[0], 
sizeof( 
PndCAMCTrack ), fMCTracks.size(), 
file );
 
  209   std::fwrite( &fHitLabels[0], 
sizeof( PndCAHitLabel ), fHitLabels.size(), 
file );
 
  212 void PndCAPerformance::ReadMCEvent( FILE *file )
 
  218   read = std::fread( &n, 
sizeof( 
int ), 1, file );
 
  220   fMCTracks.resize( n );
 
  221   read = std::fread( &n, 
sizeof( 
int ), 1, file );
 
  223   fHitLabels.resize( n );
 
  225   read = std::fread( &fMCTracks[0], 
sizeof( 
PndCAMCTrack ), fMCTracks.size(), 
file );
 
  226   assert( read == (
int) fMCTracks.size() );
 
  228   read = std::fread( &fHitLabels[0], 
sizeof( PndCAHitLabel ), fHitLabels.size(), 
file );
 
  229   assert( read == (
int) fHitLabels.size() );
 
  251 void PndCAPerformance::ReadLocalMCPoints( FILE *file )
 
  257   read = std::fread( &n, 
sizeof( 
int ), 1, file );
 
  259   fLocalMCPoints.resize( n );
 
  261   read = std::fread( &fLocalMCPoints[0], 
sizeof( PndCALocalMCPoint ), fLocalMCPoints.size(), 
file );
 
  262   assert( read == (
int) fLocalMCPoints.size() );
 
  267 void PndCAPerformance::SetMCTracks(vector<PndCAMCTrack>& mcTracks)
 
  269   const int N = mcTracks.size();
 
  271   for(
int i = 0; i < N; i++){
 
  272     fMCTracks[
i] = mcTracks[
i];
 
  276 void PndCAPerformance::SetMCPoints(vector<PndCALocalMCPoint>& mcPoints)
 
  278   const int N = mcPoints.size();
 
  279   fLocalMCPoints.resize(N);
 
  280   for(
int i = 0; i < N; i++){
 
  281     fLocalMCPoints[
i] = mcPoints[
i];
 
  285 void PndCAPerformance::SetHitLabels(vector<PndCAHitLabel>& hitLabels)
 
  287   const int N = hitLabels.size();
 
  288   fHitLabels.resize(N);
 
  289   for(
int i = 0; i < N; i++){
 
  290     fHitLabels[
i] = hitLabels[
i];
 
  294 void PndCAPerformance::SaveDataInFiles(
string prefix)
 const 
  298     std::ofstream ofile((prefix+
"hitLabels.data").data(),
ios::out|ios::app);
 
  299     const int Size = fHitLabels.size();
 
  300     ofile << Size << std::endl;
 
  301     for (
unsigned int i = 0; i < fHitLabels.size(); i++){
 
  302       const PndCAHitLabel &l = fHitLabels[
i];
 
  309     std::ofstream ofile((prefix+
"MCTracks.data").data(),
ios::out|ios::app);
 
  310     const int Size = fMCTracks.size();
 
  311     ofile << Size << std::endl;
 
  312     for (
unsigned int i = 0; i < fMCTracks.size(); i++){
 
  320     std::ofstream ofile((prefix+
"MCPoints.data").data(),
ios::out|ios::app);
 
  321     const int Size = fLocalMCPoints.size();
 
  322     ofile << Size << std::endl;
 
  323     for (
unsigned int i = 0; i < fLocalMCPoints.size(); i++){
 
  324       const PndCALocalMCPoint &l = fLocalMCPoints[
i];
 
  331 bool PndCAPerformance::ReadDataFromFiles(
string prefix)
 
  335     std::ifstream ifile((prefix+
"hitLabels.data").data());
 
  336     if ( !ifile.is_open() ) 
return 0;
 
  339     fHitLabels.resize(Size);
 
  340     for (
int i = 0; i < Size; i++){
 
  341       PndCAHitLabel &l = fHitLabels[
i];
 
  349     std::ifstream ifile((prefix+
"MCTracks.data").data());
 
  350     if ( !ifile.is_open() ) 
return 0;
 
  353     fMCTracks.resize(Size);
 
  354     for (
int i = 0; i < Size; i++){
 
  363     std::ifstream ifile((prefix+
"MCPoints.data").data());
 
  364     if ( !ifile.is_open() ) 
return 0;
 
  367     fLocalMCPoints.resize(Size);
 
  368     for (
int i = 0; i < Size; i++){
 
  369       PndCALocalMCPoint &l = fLocalMCPoints[
i];
 
  382     const int NMCTracks = fMCTracks.size();
 
  384     for (
int i = 0; i < NMCTracks; ++
i ){
 
  389         rows[fLocalMCPoints[iP].IRow()]++;
 
  394       int istaold = -2, ncont=0;
 
  395       for (
unsigned int j = 0 ; j < rows.size(); j++) {
 
  399           if( istaold == static_cast<int>(j)-1 ) {
 
  403             nMCContRows = (nMCContRows > ncont) ? nMCContRows : ncont;
 
  409       nMCContRows = (nMCContRows > ncont) ? nMCContRows : ncont;
 
  418     vector< vector<int> > nmchits(NMCTracks,zero);
 
  421     for ( 
int i = 0; i < fTracker->NHits(); i++) {
 
  422       int id = hits[
i].ID();
 
  423       for ( 
int il = 0; il < 3; il++ ) {
 
  424         int trackId = HitLabel(
id).fLab[il];
 
  425         if(trackId < 0) 
continue;
 
  426         ASSERT(trackId < NMCTracks, 
"Incorrect MCPoints of MCTracks file. " <<  trackId << 
" < " << NMCTracks );
 
  431         nmchits[trackId][hits[
i].IRow()]++;
 
  435     for (
int i = 0; i < NMCTracks; ++
i ){
 
  439       int nHitContRows = 0;
 
  440       int istaold = -1, ncont=0;
 
  442         if ( nmchits[i][j] ) {
 
  445           if( istaold == j-1 ) {
 
  449             nHitContRows = (nHitContRows > ncont) ? nHitContRows : ncont;
 
  455       nHitContRows = (nHitContRows > ncont) ? nHitContRows : ncont;
 
  462     fPV[0] = fPV[1] = fPV[2] = 0;
 
  463     for (
int i = 0; i < NMCTracks; ++
i ){
 
  482   Vector3( 
const float& 
x, 
const float& 
y, 
const float& 
z):fx(x),fy(y),fz(z){};
 
  483   float X()
 const { 
return fx; }
 
  484   float Y()
 const { 
return fy; }
 
  485   float Z()
 const { 
return fz; }
 
  491 bool operator<(
const Vector3& 
a, 
const Vector3& 
b) {
 
  493     return a.X() < b.X();
 
  496       return a.Y() < b.Y();
 
  498       return a.Z() < b.Z();
 
  502 void PndCAPerformance::CombineHits(){
 
  504   vector<PndCAGBHit>& hits = 
const_cast<PndCAGBTracker *
>(fTracker)->fHits;
 
  506   int nLabels = fHitLabels.size();
 
  509   for( 
unsigned int ih = 0; ih < hits.size(); ih++ ){
 
  512     for( ; jh<nHitsNew; jh++ ){
 
  514       if( hi.
IRow() != hj.
IRow() ) 
continue;
 
  517       double dz = hi.
Z() - hj.
Z();
 
  518       if( dx*dx+dy*dy+dz*dz >  1.e-8 ) 
continue;
 
  529       cout<<
"Pile up in MVD, something is wrong"<<endl;
 
  532     bool mergeLabels = ( hj.
ID() < nLabels && hi.
ID()<nLabels );
 
  533     PndCAHitLabel *lto = 0, *lfrom = 0;
 
  536       lto = &fHitLabels[hj.
ID()];
 
  537       lfrom = &fHitLabels[hi.
ID()];
 
  540     if( hi.
R() < hj.
R() ){ 
 
  542         lto   = &fHitLabels[hi.
ID()];
 
  543         lfrom = &fHitLabels[hj.
ID()];
 
  549       for( ; k < 3 && lto->fLab[k] >=0; k++ );
 
  550       if ( k>=3 ) 
continue; 
 
  551       for( 
int a=0; a<3; a++ ){
 
  552         int lab = lfrom->fLab[
a];
 
  553         if( lab<0 ) 
continue;
 
  555         for( 
int b=0; b<k; b++ ) 
if( lto->fLab[b]==lab ) store=
false;
 
  556         if( store ) lto->fLab[k] = lab; 
 
  562   hits.resize(nHitsNew);
 
  567 #endif //DO_TPCCATRACKER_EFF_PERFORMANCE 
int FirstMCPointID() const 
vector< FitStore > store(3000)
void SetNMCContRows(int v)
void SetNHitContRows(int v)
friend F32vec4 operator<(const F32vec4 &a, const F32vec4 &b)