mEmcGeaMakeClusterEvaluation.C

Go to the documentation of this file.
00001 #include "mEmcGeaMakeClusterEvaluation.h"
00002 #include <iostream>
00003 #include <cassert>
00004 #include "phool.h"
00005 #include <cmath>
00006 
00007 #include "emcNodeHelper.h"
00008 
00009 #include "dEmcGeaTrackWrapper.h"
00010 #include "dEmcGeaTowerTrackWrapper.h"
00011 #include "dEmcGeaTrackClusterWrapper.h"
00012 #include "dEmcGeaClusterTrackWrapper.h"
00013 
00014 #include "EmcIndexer.h"
00015 
00016 #include "emcClusterContainer.h"
00017 #include "emcClusterContent.h"
00018 
00019 using namespace std;
00020 
00021 //_____________________________________________________________________________
00022 mEmcGeaMakeClusterEvaluation::mEmcGeaMakeClusterEvaluation()
00023 {
00024   name = "mEmcGeaMakeClusterEvaluation";
00025 }
00026 
00027 //_____________________________________________________________________________
00028 mEmcGeaMakeClusterEvaluation::~mEmcGeaMakeClusterEvaluation()
00029 {}
00030 
00031 //_____________________________________________________________________________
00032 PHBoolean
00033 mEmcGeaMakeClusterEvaluation::event(PHCompositeNode* topNode)
00034 {
00035   emcNodeHelper nh;
00036 
00037   dEmcGeaTrackWrapper* dEmcGeaTrack = nh.getTable<dEmcGeaTrackWrapper>
00038     ("dEmcGeaTrack",topNode);
00039 
00040   if (!dEmcGeaTrack)
00041     {
00042       cerr << PHWHERE << " Could not find dEmcGeaTrack" << endl;
00043       return False;
00044     }
00045 
00046   dEmcGeaTowerTrackWrapper* dEmcGeaTowerTrack = 
00047     nh.getTable<dEmcGeaTowerTrackWrapper>("dEmcGeaTowerTrack",topNode);
00048 
00049   if (!dEmcGeaTowerTrack)
00050     {
00051       cerr << PHWHERE << " Could not find dEmcGeaTowerTrack" << endl;
00052       return False;
00053     }
00054   
00055   emcClusterContainer* clusterList = 
00056     nh.getObject<emcClusterContainer>("emcClusterContainer",topNode);
00057 
00058   if (!clusterList)
00059     {
00060       cerr << PHWHERE << " Could not find emcClusterContainer" << endl;
00061       return False;
00062     }
00063 
00064   dEmcGeaClusterTrackWrapper* dEmcGeaClusterTrack = 
00065     nh.getTable<dEmcGeaClusterTrackWrapper>("dEmcGeaClusterTrack",topNode);
00066 
00067   if (!dEmcGeaClusterTrack)
00068     {
00069       cerr << PHWHERE << " Could not find dEmcGeaClusterTrack" << endl;
00070       return False;
00071     }
00072 
00073   dEmcGeaTrackClusterWrapper* dEmcGeaTrackCluster =
00074     nh.getTable<dEmcGeaTrackClusterWrapper>("dEmcGeaTrackCluster",topNode);
00075 
00076   if (!dEmcGeaClusterTrack)
00077     {
00078       cerr << PHWHERE << " Could not find dEmcGeaClusterTrack" << endl;
00079       return False;
00080     }
00081 
00082   if ( dEmcGeaTrack->RowCount() == 0 ||
00083        dEmcGeaTowerTrack->RowCount() == 0 ||
00084        clusterList->size() == 0 )
00085     {
00086       return False;
00087     }
00088 
00089   // Global boolean if one contributor is ever found in the cluster
00090   // needed for the real+simul merging !
00091   int AtLeastOneContributorFound = 0 ;
00092 
00093   int maxNumOfTracksPerTower = 50;
00094 
00095   // We consider a realistic maximum of *3* tracks contributing to 
00096   // the same tower.
00097   // The most common case is, of course, 1 ...
00098   int maxNumOfTracksKeptPerTower = 3;
00099 
00100   /* ia_track will store the track numbers of the tracks contributing
00101      to a specific cluster 
00102   */
00103   int ia_track[maxNumOfTracksPerTower];
00104 
00105   /* ra_track will store data of tracks listed in ia_track.
00106      Field: 0 - energy (cumulates "edep" field of TowerTrack)
00107      1 - pid
00108      2 - ptot
00109      3-5 - impact xyz
00110      6 - twrhit
00111      7 - edep ("edep" field of GeaTrack)
00112      8 - anclvl
00113      9-11 - vertex xyz
00114   */
00115 
00116   float ra_track[12][maxNumOfTracksPerTower];
00117 
00118   float ra_work[12];
00119 
00120   int i_cltr_id = 0;
00121 
00122   /* First part.  Figure out cluster overlaps, i.e. which track deposited */
00123   /* energy in a specific cluster */
00124 
00125   /* Loop over all clusters found */
00126 
00127   for ( size_t i = 0; i < clusterList->size(); ++i)
00128     {
00129       emcClusterContent* cluster = clusterList->getCluster(i);
00130       assert(cluster!=0);
00131 
00132       // reset "AtLeastOneContributorFound" for each cluster
00133       AtLeastOneContributorFound = 0 ;
00134 
00135       /* Zeroing temporary arrays */
00136 
00137       for (size_t ll = 0; ll < sizeof(ra_track) / sizeof(ra_track[0][0]); ++ll)
00138         {
00139           *((float *)ra_track + ll) = 0.0;
00140         }
00141       for (size_t ll = 0; ll < sizeof(ia_track) / sizeof(ia_track[0]); ++ll)
00142         {
00143           *(ia_track + ll) = 0;
00144         }
00145 
00146       /* Loop over all towers included in a cluster */
00147 
00148       int ntowers = cluster->multiplicity();
00149       /* There was a logic flaw in assigning dominant contributor (GEANT-speak)
00150          when the clustering routine split up a big cluster into two showers.
00151          The measured energies were shared properly between the clusters,
00152          but the evaluation never knew about sharing.
00153          We circumvent this problem by modifying dEmcGeaTowerTrack on the
00154          fly: when dealing with a cluster, we subtract from tower "edep" as much
00155          energy as has been "used up" for the first cluster.  In the process we
00156          cheat a bit, never allowing tower "edep" to be zero, to avoid other
00157          problems with "holes" in the energy deposit...*/
00158       float e_assigned_this_tower = 0.0;
00159       float e_new_edep;
00160       
00161       for ( int j = 0; j < ntowers; ++j )
00162         {
00163           assert(cluster->partesum(j) > 0);
00164           e_assigned_this_tower = (j==0) ? 
00165             cluster->partesum(0) : cluster->partesum(j) - cluster->partesum(j-1);
00166           int towerid = cluster->towerid(j);
00167 
00168           int i_twrkey = EmcIndexer::SoftwareKey(towerid);
00169 
00170           /* Loop over all tracks contributing to a given tower */
00171 
00172           int l_found = -1;
00173           size_t k = 0;
00174           while ( l_found < 0 && k < dEmcGeaTowerTrack->RowCount() )
00175             {
00176               if ( i_twrkey == dEmcGeaTowerTrack->get_twrkey(k) )
00177                 {
00178                   l_found = k;
00179                   AtLeastOneContributorFound = 1 ;
00180                 }
00181               ++k;
00182             } /* while Loop over GeaTowerTrack to find contributor */
00183 
00184           if ( l_found >= 0)  // Contributor found
00185             {
00186 
00187               // We consider a maximum of *3* tracks contributing 
00188               // to the same tower
00189 
00190               for ( int k = 0; k <= maxNumOfTracksKeptPerTower - 1; k++)
00191                 {
00192                   int i_track = dEmcGeaTowerTrack->get_trkno(k,l_found);
00193                   if ( i_track > 0)
00194                     {
00195                       int l_found1 = -1;
00196                       int k1 = 0;
00197 
00198                       while ( l_found1 < 0 && k1 < maxNumOfTracksPerTower)
00199                         {
00200                           if ( (ia_track[k1] == i_track) || 
00201                                (ia_track[k1] == 0))
00202                             {
00203                               l_found1 = k1;
00204                             }
00205                           ++k1;
00206                         }  /* while Loop over ia_track (already registered?) */
00207 
00208                       /* Let's hope you either found the track or there is
00209                          still free space in the array */
00210 
00211                       if ( l_found1 >= 0)
00212                         {
00213                           ia_track[l_found1] = i_track;
00214                           ra_track[0][l_found1] = ra_track[0][l_found1] +
00215                             dEmcGeaTowerTrack->get_edep(k,l_found);
00216                           /*
00217                           printf(" Cluster %d tower %d partesum %f e_assigned %f twrkey %d track %d edep %f \n",
00218                                  i,j,cluster->partesum(j),e_assigned_this_tower,i_twrkey,i_track,
00219                                  dEmcGeaTowerTrack->get_edep(k,l_found));
00220                           */
00221                           e_new_edep = (dEmcGeaTowerTrack->get_edep(k,l_found) >= e_assigned_this_tower) ?
00222                             dEmcGeaTowerTrack->get_edep(k,l_found) - e_assigned_this_tower : 0.001;
00223                           dEmcGeaTowerTrack->set_edep(k,l_found,e_new_edep);
00224                           
00225                         }
00226 
00227                     } /* trkno[k] > 0 */
00228 
00229                 } /* for Loop over k within a specific GeaTowerTrack record */
00230 
00231             }  /* l_found > 0, found tower */
00232 
00233 
00234         } /* for Loop over j, non-zero towers in a specific cluster */
00235 
00236       /*  You are done with all tower contributors of a cluster */
00237 
00238       if ( AtLeastOneContributorFound )
00239         {
00240           /* Sort them decreasing */
00241           for ( int j = 0; j < maxNumOfTracksPerTower - 1; j++)
00242             {
00243               /*          for( k = j + 1; k < maxNumOfTracksPerTower; k++) */
00244               for ( int k = 1; k < maxNumOfTracksPerTower; k++)
00245                 {
00246                   if (ra_track[0][k - 1] < ra_track[0][k])
00247                     {
00248                       int i_work1 = ia_track[k - 1];
00249                       for ( int k1 = 0; k1 <= 11; k1++)
00250                         {
00251                           ra_work[k1] = ra_track[k1][k - 1];
00252                         }
00253                       for ( int k1 = 0; k1 <= 11; k1++) 
00254                         {
00255                           ra_track[k1][k - 1] = ra_track[k1][k];
00256                         }
00257                       for ( int k1 = 0; k1 <= 11; k1++)
00258                         {
00259                           ra_track[k1][k] = ra_work[k1];
00260                         }
00261                       ia_track[k - 1] = ia_track[k];
00262                       ia_track[k] = i_work1;
00263                     }  /* End interchange of elements */
00264                 }      /* End sort inner loop */
00265             }          /* End sort outer loop */
00266 
00267           /* Search pid and ptot for the top 3 tracks */
00268 
00269           for ( int j = 0; j <= maxNumOfTracksKeptPerTower - 1; j++)
00270             {
00271               int l_found2 = -1;
00272               size_t k = 0;
00273 
00274               while ( k < dEmcGeaTrack->RowCount() && 
00275                       l_found2 < 0 && 
00276                       ia_track[j] > 0)
00277                 {
00278                   if (dEmcGeaTrack->get_trkno(k) == ia_track[j])
00279                     {
00280                       l_found2 = k;
00281                     }
00282                   ++k;
00283                 } /* for Loop over k, entries in dEmcGeaTrack */
00284 
00285               if ( l_found2 >= 0)
00286                 {
00287                   ra_track[1][j] = dEmcGeaTrack->get_pid(l_found2);
00288                   /*          ra_track[2][j] = dEmcGeaTrack[l_found2].ekin; */
00289                   ra_track[2][j] = dEmcGeaTrack->get_ptot(l_found2);
00290                   ra_track[3][j] = dEmcGeaTrack->get_impxyz(0,l_found2);
00291                   ra_track[4][j] = dEmcGeaTrack->get_impxyz(1,l_found2);
00292                   ra_track[5][j] = dEmcGeaTrack->get_impxyz(2,l_found2);
00293                   ra_track[6][j] = dEmcGeaTrack->get_twrhit(l_found2);
00294                   ra_track[7][j] = dEmcGeaTrack->get_edep(l_found2);
00295                   ra_track[8][j] = dEmcGeaTrack->get_anclvl(l_found2);
00296                   ra_track[9][j] = dEmcGeaTrack->get_xyz(0,l_found2);
00297                   ra_track[10][j] = dEmcGeaTrack->get_xyz(1,l_found2);
00298                   ra_track[11][j] = dEmcGeaTrack->get_xyz(2,l_found2);
00299                 }
00300 
00301             }    /* for Loop over j to search for pid at ptot of top 3 tracks */
00302 
00303         }  /* Contributor found */
00304 
00305       /* Write output record for this cluster */
00306 
00307       // In the case of embedded sim+real data, you often DO NOT find GEANT
00308       // contributors to a reconstructed cluster. At this point we have,
00309       // thus, 2 options:
00310       //
00311       // 1) Do not apply the AtLeastOneContributorFound condition:
00312       //    Fill dEmcGeaClusterTrack in all cases (though the *pure* dEmcGeaClusterTrack
00313       //    fields below would be empty in most of the cases ...).
00314       //    In the analysis afterwards, the way to distinguish a "pure" ClusterTrack
00315       //    (with some GEANT track in it) and a ClusterLocal without contribution
00316       //    will be, e.g., asking that the first track not be there (trkno_1 ==0).
00317 
00318       // 2) Apply the AtLeastOneContributorFound condition: Fill only dEmcGeaClusterTrack
00319       //    when a GEANT contributor is found. The resulting dEmcGeaClusterTrack
00320       //    tables are much less heavy, but we have to propagate the (real) event
00321       //    cluster multiplicity information in an adhoc manner ...
00322       //
00323       // We choose now option 2) and propagate the clus. mult. info in the
00324       // unused "Charged" field of dEmcGeaClusterTrack D.d'E. (2002)
00325       //
00326 
00327       if ( AtLeastOneContributorFound )
00328         {
00329           dEmcGeaClusterTrack->set_id(i_cltr_id,i_cltr_id);
00330           dEmcGeaClusterTrack->set_clusid(i_cltr_id,i);
00331           dEmcGeaClusterTrack->set_input(i_cltr_id,0);
00332 
00333           // Fields common to emcClusterContainer (hum, more or less, e.g.
00334           // evno is not there.
00335           dEmcGeaClusterTrack->set_evno(i_cltr_id,0); // evno not in clustCont
00336           int softkey = EmcIndexer::SoftwareKey(cluster->towerid(0));
00337           dEmcGeaClusterTrack->set_keycent(i_cltr_id,softkey);
00338           dEmcGeaClusterTrack->set_type(i_cltr_id,cluster->type());
00339           dEmcGeaClusterTrack->set_arm(i_cltr_id,cluster->arm());
00340           dEmcGeaClusterTrack->set_sector(i_cltr_id,cluster->sector());
00341           dEmcGeaClusterTrack->set_mease(i_cltr_id,cluster->e());
00342        
00343           dEmcGeaClusterTrack->set_ecore(i_cltr_id,cluster->ecore());
00344 
00345           dEmcGeaClusterTrack->set_tof(i_cltr_id,cluster->tof());
00346           dEmcGeaClusterTrack->set_tofmin(i_cltr_id,cluster->tofmin());
00347           dEmcGeaClusterTrack->set_tofmax(i_cltr_id,cluster->tofmax());
00348           // the energy of the first-TOF tower is the energy 
00349           // of the highest tower:
00350           dEmcGeaClusterTrack->set_etof(i_cltr_id,cluster->ecent());
00351           dEmcGeaClusterTrack->set_etofmin(i_cltr_id,cluster->etofmin());
00352           dEmcGeaClusterTrack->set_etofmax(i_cltr_id,cluster->etofmax());
00353 
00354           dEmcGeaClusterTrack->set_twrhit(i_cltr_id,cluster->multiplicity());
00355           
00356           for ( int k = 0 ; k < 2 ; ++k)
00357             {
00358               dEmcGeaClusterTrack->set_e_sh(k,i_cltr_id,0); 
00359             }
00360           dEmcGeaClusterTrack->set_disp(1,i_cltr_id,cluster->dispy());
00361           dEmcGeaClusterTrack->set_disp(0,i_cltr_id,cluster->dispz());
00362           dEmcGeaClusterTrack->set_padisp(1,i_cltr_id,cluster->padispy());
00363           dEmcGeaClusterTrack->set_padisp(0,i_cltr_id,cluster->padispz());
00364           //      dEmcGeaClusterTrack->set_measxyz(0,i_cltr_id,cluster->z());
00365           //      dEmcGeaClusterTrack->set_measxyz(1,i_cltr_id,cluster->y());
00366           dEmcGeaClusterTrack->set_measxyz(0,i_cltr_id,cluster->x());
00367           dEmcGeaClusterTrack->set_measxyz(1,i_cltr_id,cluster->y());
00368           dEmcGeaClusterTrack->set_measxyz(2,i_cltr_id,cluster->z());
00369 
00370           for ( int k = 0; k < 8; ++k)
00371             {
00372               if ( k < cluster->multiplicity() )
00373                 {
00374                   dEmcGeaClusterTrack->set_partesum(k,i_cltr_id,
00375                                                     cluster->partesum(k));
00376                 }
00377               else
00378                 {
00379                   dEmcGeaClusterTrack->set_partesum(k,i_cltr_id,0);
00380                 }
00381             }
00382 
00383           // Fields common to emcClusterContainer but somehow different ...
00384           dEmcGeaClusterTrack->set_chi2_sh(i_cltr_id,cluster->chi2());
00385           dEmcGeaClusterTrack->set_prob_photon_sh(i_cltr_id,cluster->prob_photon());
00386 
00387           // "Pure" dEmcGeaClusterTrack fields
00388 
00389           for ( int k = 0 ; k < maxNumOfTracksKeptPerTower  ; ++k )
00390             {
00391               dEmcGeaClusterTrack->set_trkno(k,i_cltr_id,ia_track[k]);
00392               dEmcGeaClusterTrack->set_edep(k,i_cltr_id,ra_track[0][k]);
00393               dEmcGeaClusterTrack->set_pid(k,i_cltr_id,ra_track[1][k]);
00394               dEmcGeaClusterTrack->set_ptot(k,i_cltr_id,ra_track[2][k]);
00395               dEmcGeaClusterTrack->set_tracktwrhit(k,i_cltr_id,
00396                                                    static_cast<int>(rint(ra_track[6][k])));
00397               dEmcGeaClusterTrack->set_edep_nom(k,i_cltr_id,ra_track[7][k]);
00398               dEmcGeaClusterTrack->set_ancestry(k,i_cltr_id,ra_track[8][k]);
00399               for ( int j = 0; j <= 2; ++j )
00400                 {
00401                   dEmcGeaClusterTrack->set_xyz(j,k,i_cltr_id,
00402                                                ra_track[3 + j][k]);
00403                   dEmcGeaClusterTrack->set_vertex(j,k,i_cltr_id,
00404                                                   ra_track[9 + j][k]);
00405                 }
00406             }
00407 
00408           if (dEmcGeaClusterTrack->get_mease(i_cltr_id) > 0.0)
00409             {
00410               for ( int k = 0; k < maxNumOfTracksKeptPerTower  ; ++k )
00411                 {
00412                   float frac =  dEmcGeaClusterTrack->get_edep(k,i_cltr_id) /
00413                     dEmcGeaClusterTrack->get_mease(i_cltr_id);
00414                   dEmcGeaClusterTrack->set_efrac(k,i_cltr_id,frac);
00415                 }
00416             }
00417           // "Pure" dEmcGeaClusterTrack fields not used
00418 
00419           // WATCH-OUT: we (ab)use of this field to store the real evt. cluster info
00420           // dEmcGeaClusterTrack[i_cltr_id].charged = 0;
00421           // FIXME : what should it be really ? + have a field in
00422           // the yet-to-come phenix-standard replacement for the STAF table
00423           // dEmcGeaClusterTrack
00424           dEmcGeaClusterTrack->set_charged(i_cltr_id,clusterList->size());
00425 
00426           for ( int k = 0; k < 8; ++k )
00427             {
00428               dEmcGeaClusterTrack->set_chglist(k,i_cltr_id,0);
00429             }
00430 
00431           // WATCH-OUT: we (ab)use of this field to store the dead/warn map info
00432           //for( k=0; k<3; k++)
00433           //  {
00434           //   dEmcGeaClusterTrack[i_cltr_id].pc3proj[k] = 0.;
00435           //  }
00436 
00437           // FIXME : have the corresponding fields in
00438           // the yet-to-come phenix-standard replacement for the STAF table
00439           // dEmcGeaClusterTrack
00440           // WARNING : (21+9 bits int stored in floats)
00441           dEmcGeaClusterTrack->set_pc3proj(0,i_cltr_id,cluster->deadmap());
00442           dEmcGeaClusterTrack->set_pc3proj(1,i_cltr_id,cluster->warnmap());
00443           dEmcGeaClusterTrack->set_pc3proj(2,i_cltr_id,0);
00444 
00445           /* Increment STAF row counter */
00446           ++i_cltr_id;
00447 
00448         } /* End of  if( AtLeastOneContributorFound ) , i.e. you found at least one GEANT
00449              contributor to this cluster */
00450 
00451     }    /* Loop over i, all clusters recognized in dEmcClusterLocalExt */
00452 
00453   dEmcGeaClusterTrack->SetRowCount(i_cltr_id);
00454 
00455   /* -------------------------------------------------------------   */
00456 
00457   /* Second part.  Loop over all tracks that deposited anything in the
00458      calorimeter.  Point to clusters where a specific track contributed */
00459 
00460   int i_trcl_id = 0;
00461 
00462   for ( size_t i = 0; i < dEmcGeaTrack->RowCount(); ++i ) 
00463     {
00464 
00465       int l_found = -1;   /* Found at least one cluster where it contributed */
00466       AtLeastOneContributorFound = 0 ;
00467 
00468       // Zeroing arrays
00469       for ( size_t ll = 0; ll < sizeof(ra_track)/sizeof(ra_track[0][0]); ll++)
00470         {
00471           *((float *)ra_track + ll) = 0;
00472         }
00473 
00474       /* Since 0 is a valid pointer now, "not found" is indicated
00475          by -1 */
00476       for ( int j = 0; j < maxNumOfTracksKeptPerTower ; j++)
00477         {
00478           ia_track[j] = -1;
00479         }
00480       int i_track = dEmcGeaTrack->get_trkno(i);
00481       float nom_edep = dEmcGeaTrack->get_edep(i);
00482 
00483       for ( size_t j = 0; j < dEmcGeaClusterTrack->RowCount(); ++j ) 
00484         {
00485           for ( int k = 0; k < maxNumOfTracksKeptPerTower  ; ++k )
00486             {
00487               if ( dEmcGeaClusterTrack->get_trkno(k,j) == i_track
00488                    && l_found < maxNumOfTracksPerTower - 1 )
00489                 {
00490                   ++l_found;
00491                   AtLeastOneContributorFound = 1 ;
00492                   ia_track[l_found] = dEmcGeaClusterTrack->get_clusid(j);
00493                   ra_track[0][l_found] = dEmcGeaClusterTrack->get_pid(k,j);
00494                   ra_track[1][l_found] = dEmcGeaClusterTrack->get_ptot(k,j);
00495                   ra_track[2][l_found] = dEmcGeaClusterTrack->get_edep(k,j);
00496                   /*
00497                     ra_track[3][l_found] = dEmcGeaClusterTrack[j].efrac[k];
00498                   */
00499                   if (nom_edep > 0.1)
00500                     {
00501                       ra_track[3][l_found] =
00502                         dEmcGeaClusterTrack->get_edep(k,j) / nom_edep;
00503                     }
00504                   else
00505                     {
00506                       ra_track[3][l_found] = 0.0;
00507                     }
00508                 }  /* New cluster found where it contributed */
00509 
00510             }  /* Loop over k = 0, 2, within one dEmcGeaClusterTrack record */
00511 
00512         }   /* Loop over j = 0,dEmcGeaClusterTrack_h.nok   */
00513 
00514       /* Sort descending the clusters where the track contributed */
00515 
00516       if ( AtLeastOneContributorFound )
00517         {
00518           for (int j = 0; j < l_found; j++)
00519             {
00520               for ( int k = 1; k <= l_found; k++)
00521                 {
00522                   if (ra_track[3][k - 1] < ra_track[3][k])
00523                     {
00524                       int i_work1 = ia_track[k - 1];
00525                       for ( int k1 = 0; k1 <= 11; k1++)
00526                         {
00527                           ra_work[k1] = ra_track[k1][k - 1];
00528                         }
00529                       for ( int k1 = 0; k1 <= 11; k1++)
00530                         {
00531                           ra_track[k1][k - 1] = ra_track[k1][k];
00532                         }
00533                       for ( int k1 = 0; k1 <= 11; k1++)
00534                         {
00535                           ra_track[k1][k] = ra_work[k1];
00536                         }
00537                       ia_track[k - 1] = ia_track[k];
00538                       ia_track[k] = i_work1;
00539                     }
00540                 }  /* End loop over k, inner sort loop */
00541             }      /* End loop over j, outer sort loop */
00542 
00543           /* Write out a new record of dEmcGeaTrackCluster */
00544 
00545           dEmcGeaTrackCluster->set_id(i_trcl_id,i_trcl_id + 1);
00546           dEmcGeaTrackCluster->set_trkno(i_trcl_id,i_track);
00547           dEmcGeaTrackCluster->set_track_ptr(i_trcl_id,i);
00548           dEmcGeaTrackCluster->set_nom_edep(i_trcl_id,nom_edep);
00549           dEmcGeaTrackCluster->set_input(i_trcl_id,0);
00550 
00551           for ( int k = 0; k < maxNumOfTracksKeptPerTower ; k++)
00552             {
00553               dEmcGeaTrackCluster->set_clusid(k,i_trcl_id,ia_track[k]);
00554               dEmcGeaTrackCluster->set_pid(i_trcl_id,ra_track[0][0]);
00555               dEmcGeaTrackCluster->set_ptot(i_trcl_id,ra_track[1][0]);
00556               dEmcGeaTrackCluster->set_edep(k,i_trcl_id,ra_track[2][k]);
00557               dEmcGeaTrackCluster->set_efrac(k,i_trcl_id,ra_track[3][k]);
00558             }
00559           
00560           ++i_trcl_id;
00561         }   /* End if(l_found) - found at least one cluster where contrib. */
00562       
00563     }   /*  Loop over i = 0,dEmcGeaTrack_h.nok , all tracks depositing E */
00564   
00565   
00566   dEmcGeaTrackCluster->SetRowCount(i_trcl_id);
00567 
00568   return True;
00569 }