diff --git a/Muon/MuonMoniDigi/src/MuonDigitChecker.cpp b/Muon/MuonMoniDigi/src/MuonDigitChecker.cpp index a71e0c483a2ca2eccd0e608787632e7062af6c56..0e258837688c8f444d03bf6381302e10a848a901 100755 --- a/Muon/MuonMoniDigi/src/MuonDigitChecker.cpp +++ b/Muon/MuonMoniDigi/src/MuonDigitChecker.cpp @@ -26,26 +26,26 @@ #include "Event/MuonDigit.h" #include "MuonDet/DeMuonDetector.h" #include "MuonDigitChecker.h" +#include <limits> #include <sstream> +namespace { + constexpr auto NaN = std::numeric_limits<double>::signaling_NaN(); +} + DECLARE_COMPONENT( MuonDigitChecker ) //============================================================================= // Standard constructor, initializes variables //============================================================================= MuonDigitChecker::MuonDigitChecker( const std::string& name, ISvcLocator* pSvcLocator ) - : GaudiTupleAlg( name, pSvcLocator ), m_hitMonitor( false ), m_base( NULL ) { + : GaudiTupleAlg( name, pSvcLocator ), m_hitMonitor( false ) { declareProperty( "hitMonitor", m_hitMonitor ); // setProperty( "NTupleProduce", "false" ); setProperty( "HistoTopDir", "MUON/" ); setProperty( "NTupleTopDir", "MUON/" ); } -//============================================================================= -// Destructor -//============================================================================= -MuonDigitChecker::~MuonDigitChecker() {} - //============================================================================= // Initialisation. Check parameters //============================================================================= @@ -57,15 +57,15 @@ StatusCode MuonDigitChecker::initialize() { for ( int ix = 0; ix < 6; ix++ ) { if ( ix < 4 && m_hitMonitor ) { for ( int i = 0; i < 5; i++ ) { - for ( int j = 0; j < 4; j++ ) { nhit[i][j][ix] = cnt[i][j][ix] = 0; } + for ( int j = 0; j < 4; j++ ) { m_nhit[i][j][ix] = m_cnt[i][j][ix] = 0; } } } for ( int i = 0; i < 5; i++ ) { - for ( int j = 0; j < 4; j++ ) { nDhit[i][j][ix] = Dcnt[i][j][ix] = 0; } + for ( int j = 0; j < 4; j++ ) { m_nDhit[i][j][ix] = m_Dcnt[i][j][ix] = 0; } } } - m_base = new MuonBasicGeometry( this->detSvc(), this->msgSvc() ); + m_base = std::make_unique<MuonBasicGeometry>( this->detSvc(), this->msgSvc() ); return StatusCode::SUCCESS; } @@ -89,13 +89,13 @@ StatusCode MuonDigitChecker::execute() { } } - std::vector<float> m_sta, m_reg, m_cha, m_con, m_x, m_y, m_z, m_time, m_id; - std::vector<float> m_px, m_py, m_pz, m_E, m_xv, m_yv, m_zv, m_tv, m_mom; - std::vector<float> m_ple, m_hen, m_dix, m_dxz, m_dyz; + std::vector<float> sta, reg, cha, con, x, y, z, vtime, id; + std::vector<float> px, py, pz, E, xv, yv, zv, tv, mom; + std::vector<float> ple, hen, dix, dxz, dyz; - std::vector<float> m_digit_s, m_digit_r, m_digit_x, m_digit_y; - std::vector<float> m_digit_z, m_digit_dx, m_digit_dy, m_digit_dz, m_digit_time; - std::vector<float> m_digit_origin, m_digit_bx, m_digit_firing, m_digit_multi; + std::vector<float> digit_s, digit_r, digit_x, digit_y; + std::vector<float> digit_z, digit_dx, digit_dy, digit_dz, digit_time; + std::vector<float> digit_origin, digit_bx, digit_firing, digit_multi; DeMuonDetector* muonD = getDet<DeMuonDetector>( DeMuonLocation::Default ); @@ -119,13 +119,12 @@ StatusCode MuonDigitChecker::execute() { LHCb::MCHits* hits = get<LHCb::MCHits>( LHCb::MCHitLocation::Muon ); - LHCb::MCHits::const_iterator iter; - int MyDetID; + int MyDetID; // Loop over Muon Hits of given type - if ( hits != 0 ) { - for ( iter = hits->begin(); iter < hits->end(); iter++ ) { + if ( hits ) { + for ( const auto* hit : *hits ) { - MyDetID = ( *iter )->sensDetID(); + MyDetID = hit->sensDetID(); if ( MyDetID < 0 ) continue; // Needs to extract info from sens ID int station = muonD->stationID( MyDetID ); @@ -134,31 +133,31 @@ StatusCode MuonDigitChecker::execute() { if ( msgLevel( MSG::DEBUG ) ) debug() << " region:: " << region << endmsg; - float xpos = (float)( ( ( *iter )->entry().x() + ( *iter )->exit().x() ) / 2.0 ); - float ypos = (float)( ( ( *iter )->entry().y() + ( *iter )->exit().y() ) / 2.0 ); - float zpos = (float)( ( ( *iter )->entry().z() + ( *iter )->exit().z() ) / 2.0 ); - float time = (float)( ( *iter )->time() ); + float xpos = ( hit->entry().x() + hit->exit().x() ) / 2.0; + float ypos = ( hit->entry().y() + hit->exit().y() ) / 2.0; + float zpos = ( hit->entry().z() + hit->exit().z() ) / 2.0; + float time = hit->time(); double tof = time - sqrt( xpos * xpos + ypos * ypos + zpos * zpos ) / 300.0; if ( tof < 0.1 ) tof = 0.1; float r = sqrt( xpos * xpos + ypos * ypos ); - m_sta.push_back( (float)station ); - m_reg.push_back( (float)region ); - m_cha.push_back( (float)chamber ); - m_con.push_back( (float)container ); + sta.push_back( station ); + reg.push_back( region ); + cha.push_back( chamber ); + con.push_back( container ); // Temporary monitoring (need to check if already available) - m_ple.push_back( (float)( ( *iter )->pathLength() ) ); - m_hen.push_back( (float)( ( *iter )->energy() ) ); - m_dix.push_back( (float)( ( *iter )->displacement().x() ) ); - m_dxz.push_back( (float)( ( *iter )->dxdz() ) ); - m_dyz.push_back( (float)( ( *iter )->dydz() ) ); + ple.push_back( hit->pathLength() ); + hen.push_back( hit->energy() ); + dix.push_back( hit->displacement().x() ); + dxz.push_back( hit->dxdz() ); + dyz.push_back( hit->dydz() ); - m_x.push_back( xpos ); - m_y.push_back( ypos ); - m_z.push_back( zpos ); - m_time.push_back( time ); + x.push_back( xpos ); + y.push_back( ypos ); + z.push_back( zpos ); + vtime.push_back( time ); // Fill some histos int hh = station * 4 + region; @@ -167,41 +166,39 @@ StatusCode MuonDigitChecker::execute() { plot( tof, hh + 1000, "Time multiplicity", 0., 100., 200 ); // MC truth - const LHCb::MCParticle* particle = ( *iter )->mcParticle(); + const LHCb::MCParticle* particle = hit->mcParticle(); if ( particle ) { - if ( abs( particle->particleID().pid() ) < 100000 ) { - m_id.push_back( (float)particle->particleID().pid() ); - } + if ( abs( particle->particleID().pid() ) < 100000 ) { id.push_back( particle->particleID().pid() ); } - m_px.push_back( (float)particle->momentum().px() ); - m_py.push_back( (float)particle->momentum().py() ); + px.push_back( particle->momentum().px() ); + py.push_back( particle->momentum().py() ); // Pz sign tells you the particle direction - m_pz.push_back( (float)particle->momentum().pz() ); - m_E.push_back( (float)particle->momentum().e() ); + pz.push_back( particle->momentum().pz() ); + E.push_back( particle->momentum().e() ); // Particle Vertex studies - m_xv.push_back( (float)particle->originVertex()->position().x() ); - m_yv.push_back( (float)particle->originVertex()->position().y() ); - m_zv.push_back( (float)particle->originVertex()->position().z() ); - m_tv.push_back( (float)particle->originVertex()->time() ); + xv.push_back( particle->originVertex()->position().x() ); + yv.push_back( particle->originVertex()->position().y() ); + zv.push_back( particle->originVertex()->position().z() ); + tv.push_back( particle->originVertex()->time() ); const LHCb::MCParticle* moth = particle->mother(); if ( moth && ( abs( moth->particleID().pid() ) < 100000 ) ) { - m_mom.push_back( (float)moth->particleID().pid() ); + mom.push_back( moth->particleID().pid() ); } else { - m_mom.push_back( 0 ); + mom.push_back( 0 ); } } else { - m_id.push_back( 0 ); - m_px.push_back( 0 ); - m_py.push_back( 0 ); - m_pz.push_back( 0 ); - m_E.push_back( 0 ); - m_xv.push_back( 0 ); - m_yv.push_back( 0 ); - m_zv.push_back( 0 ); - m_tv.push_back( 0 ); - m_mom.push_back( 0 ); + id.push_back( 0 ); + px.push_back( 0 ); + py.push_back( 0 ); + pz.push_back( 0 ); + E.push_back( 0 ); + xv.push_back( 0 ); + yv.push_back( 0 ); + zv.push_back( 0 ); + tv.push_back( 0 ); + mom.push_back( 0 ); } tnhit[station][region][container]++; } @@ -211,8 +208,8 @@ StatusCode MuonDigitChecker::execute() { for ( int r = 0; r < 4; r++ ) { for ( int s = 0; s < 5; s++ ) { // Looking at mean number of hits - cnt[s][r][ic]++; - nhit[s][r][ic] += tnhit[s][r][ic]; + m_cnt[s][r][ic]++; + m_nhit[s][r][ic] += tnhit[s][r][ic]; } } } @@ -223,38 +220,37 @@ StatusCode MuonDigitChecker::execute() { LHCb::MuonDigits* digit = get<LHCb::MuonDigits>( LHCb::MuonDigitLocation::MuonDigit ); LHCb::MCMuonDigits* mcdigit = get<LHCb::MCMuonDigits>( LHCb::MCMuonDigitLocation::MCMuonDigit ); - LHCb::MuonDigits::const_iterator jdigit; - int Dsta, Dreg, Dcon; - double Dfir; - bool Deve; - double x, y, z; - double dx, dy, dz; + int Dsta, Dreg, Dcon; + double Dfir; + bool Deve; - for ( jdigit = digit->begin(); jdigit < digit->end(); jdigit++ ) { - Dsta = ( *jdigit )->key().station(); - Dreg = ( *jdigit )->key().region(); + for ( const auto* jdigit : *digit ) { + Dsta = jdigit->key().station(); + Dreg = jdigit->key().region(); - m_digit_s.push_back( (float)Dsta ); - m_digit_r.push_back( (float)Dreg ); - m_digit_time.push_back( (float)( *jdigit )->TimeStamp() ); + digit_s.push_back( Dsta ); + digit_r.push_back( Dreg ); + digit_time.push_back( jdigit->TimeStamp() ); // Timestamp is one of the 8 intervals (8 digits) in which // the 20ns acceptance window is subdivided after beam crossing - StatusCode sc = muonD->Tile2XYZ( ( *jdigit )->key(), x, dx, y, dy, z, dz ); + double x = NaN, y = NaN, z = NaN; + double dx = NaN, dy = NaN, dz = NaN; + StatusCode sc = muonD->Tile2XYZ( jdigit->key(), x, dx, y, dy, z, dz ); if ( sc.isFailure() && msgLevel( MSG::DEBUG ) ) debug() << "error in tile " << endmsg; - m_digit_x.push_back( (float)x ); - m_digit_y.push_back( (float)y ); - m_digit_z.push_back( (float)z ); + digit_x.push_back( x ); + digit_y.push_back( y ); + digit_z.push_back( z ); - m_digit_dx.push_back( (float)dx ); - m_digit_dy.push_back( (float)dy ); - m_digit_dz.push_back( (float)dz ); + digit_dx.push_back( dx ); + digit_dy.push_back( dy ); + digit_dz.push_back( dz ); // Match with "true" MC digit - LHCb::MCMuonDigit* MCmd = mcdigit->object( ( *jdigit )->key() ); + LHCb::MCMuonDigit* MCmd = mcdigit->object( jdigit->key() ); if ( NULL == MCmd ) { - error() << "Could not find the match for " << ( *jdigit )->key() << " in " - << LHCb::MCMuonDigitLocation::MCMuonDigit << endmsg; + error() << "Could not find the match for " << jdigit->key() << " in " << LHCb::MCMuonDigitLocation::MCMuonDigit + << endmsg; return StatusCode::FAILURE; } @@ -271,12 +267,12 @@ StatusCode MuonDigitChecker::execute() { Deve = digInfo.doesFiringHitBelongToCurrentEvent(); // bool Dali = digInfo.isAlive(); // not used Dfir = MCmd->firingTime(); - m_digit_firing.push_back( (float)Dfir ); - m_digit_origin.push_back( (float)Dcon ); - m_digit_bx.push_back( (float)Deve ); + digit_firing.push_back( Dfir ); + digit_origin.push_back( Dcon ); + digit_bx.push_back( Deve ); // Hits mupltiplicity - m_digit_multi.push_back( (float)MCmd->mcHits().size() ); + digit_multi.push_back( MCmd->mcHits().size() ); // if(Deve) tnDhit[Dsta][Dreg][Dcon]++; // if(globalTimeOffset()>0)info()<<" qui "<<Dcon<<" "<<Dfir<<" "<<Deve<<" "<<Dsta<<" "<<Dreg<<endmsg; @@ -286,64 +282,64 @@ StatusCode MuonDigitChecker::execute() { for ( int c = 0; c < 6; c++ ) { for ( int r = 0; r < 4; r++ ) { for ( int s = 0; s < 5; s++ ) { - Dcnt[s][r][c]++; - nDhit[s][r][c] += tnDhit[s][r][c]; + m_Dcnt[s][r][c]++; + m_nDhit[s][r][c] += tnDhit[s][r][c]; } } } if ( m_hitMonitor ) { Tuple nt1 = nTuple( 41, "MC HITS", CLID_ColumnWiseTuple ); - longlong m_evt = evt->evtNumber(); - StatusCode sc = nt1->column( "Event", m_evt, 0LL, 10000LL ); + longlong evtNr = evt->evtNumber(); + StatusCode sc = nt1->column( "Event", evtNr, 0LL, 10000LL ); if ( sc.isFailure() && msgLevel( MSG::DEBUG ) ) debug() << "nt error" << endmsg; - nt1->farray( "is", m_sta, "Nhits", 1000 ); - nt1->farray( "ir", m_reg, "Nhits", 1000 ); - nt1->farray( "ch", m_cha, "Nhits", 1000 ); - nt1->farray( "ic", m_con, "Nhits", 1000 ); - nt1->farray( "x", m_x, "Nhits", 1000 ); - nt1->farray( "y", m_y, "Nhits", 1000 ); - nt1->farray( "z", m_z, "Nhits", 1000 ); - nt1->farray( "t", m_time, "Nhits", 1000 ); - nt1->farray( "id", m_id, "Nhits", 1000 ); - nt1->farray( "px", m_px, "Nhits", 1000 ); - nt1->farray( "py", m_py, "Nhits", 1000 ); - nt1->farray( "pz", m_pz, "Nhits", 1000 ); - nt1->farray( "E", m_E, "Nhits", 1000 ); - nt1->farray( "xv", m_xv, "Nhits", 1000 ); - nt1->farray( "yv", m_yv, "Nhits", 1000 ); - nt1->farray( "zv", m_zv, "Nhits", 1000 ); - nt1->farray( "tv", m_tv, "Nhits", 1000 ); - nt1->farray( "idm", m_mom, "Nhits", 1000 ); - nt1->farray( "pl", m_ple, "Nhits", 1000 ); - nt1->farray( "he", m_hen, "Nhits", 1000 ); - nt1->farray( "dx", m_dix, "Nhits", 1000 ); - nt1->farray( "xz", m_dxz, "Nhits", 1000 ); - nt1->farray( "yz", m_dyz, "Nhits", 1000 ); + nt1->farray( "is", sta, "Nhits", 1000 ); + nt1->farray( "ir", reg, "Nhits", 1000 ); + nt1->farray( "ch", cha, "Nhits", 1000 ); + nt1->farray( "ic", con, "Nhits", 1000 ); + nt1->farray( "x", x, "Nhits", 1000 ); + nt1->farray( "y", y, "Nhits", 1000 ); + nt1->farray( "z", z, "Nhits", 1000 ); + nt1->farray( "t", vtime, "Nhits", 1000 ); + nt1->farray( "id", id, "Nhits", 1000 ); + nt1->farray( "px", px, "Nhits", 1000 ); + nt1->farray( "py", py, "Nhits", 1000 ); + nt1->farray( "pz", pz, "Nhits", 1000 ); + nt1->farray( "E", E, "Nhits", 1000 ); + nt1->farray( "xv", xv, "Nhits", 1000 ); + nt1->farray( "yv", yv, "Nhits", 1000 ); + nt1->farray( "zv", zv, "Nhits", 1000 ); + nt1->farray( "tv", tv, "Nhits", 1000 ); + nt1->farray( "idm", mom, "Nhits", 1000 ); + nt1->farray( "pl", ple, "Nhits", 1000 ); + nt1->farray( "he", hen, "Nhits", 1000 ); + nt1->farray( "dx", dix, "Nhits", 1000 ); + nt1->farray( "xz", dxz, "Nhits", 1000 ); + nt1->farray( "yz", dyz, "Nhits", 1000 ); sc = nt1->write(); if ( sc.isFailure() && msgLevel( MSG::DEBUG ) ) debug() << "Failure writing nt1" << endmsg; Tuple nt2 = nTuple( 42, "DIGITS", CLID_ColumnWiseTuple ); - longlong m_digit_evt = evt->evtNumber(); - // StatusCode sc=nt2->column("Event", m_digit_evt, 0LL,10000LL); - sc = nt2->column( "Event", m_digit_evt, 0LL, 10000LL ); + longlong digit_evt = evt->evtNumber(); + // StatusCode sc=nt2->column("Event", digit_evt, 0LL,10000LL); + sc = nt2->column( "Event", digit_evt, 0LL, 10000LL ); if ( sc.isFailure() ) debug() << " nt2 error " << endmsg; - sc = nt2->farray( "is", m_digit_s, "Ndigits", 1000 ); - sc = nt2->farray( "ir", m_digit_r, "Ndigits", 1000 ); - sc = nt2->farray( "x", m_digit_x, "Ndigits", 1000 ); - sc = nt2->farray( "y", m_digit_y, "Ndigits", 1000 ); - sc = nt2->farray( "z", m_digit_z, "Ndigits", 1000 ); - sc = nt2->farray( "dx", m_digit_dx, "Ndigits", 1000 ); - sc = nt2->farray( "dy", m_digit_dy, "Ndigits", 1000 ); - sc = nt2->farray( "dz", m_digit_dz, "Ndigits", 1000 ); - sc = nt2->farray( "t", m_digit_time, "Ndigits", 1000 ); - sc = nt2->farray( "origin", m_digit_origin, "Ndigits", 1000 ); - sc = nt2->farray( "bx", m_digit_bx, "Ndigits", 1000 ); - sc = nt2->farray( "firing", m_digit_firing, "Ndigits", 1000 ); - sc = nt2->farray( "multip", m_digit_multi, "Ndigits", 1000 ); + sc = nt2->farray( "is", digit_s, "Ndigits", 1000 ); + sc = nt2->farray( "ir", digit_r, "Ndigits", 1000 ); + sc = nt2->farray( "x", digit_x, "Ndigits", 1000 ); + sc = nt2->farray( "y", digit_y, "Ndigits", 1000 ); + sc = nt2->farray( "z", digit_z, "Ndigits", 1000 ); + sc = nt2->farray( "dx", digit_dx, "Ndigits", 1000 ); + sc = nt2->farray( "dy", digit_dy, "Ndigits", 1000 ); + sc = nt2->farray( "dz", digit_dz, "Ndigits", 1000 ); + sc = nt2->farray( "t", digit_time, "Ndigits", 1000 ); + sc = nt2->farray( "origin", digit_origin, "Ndigits", 1000 ); + sc = nt2->farray( "bx", digit_bx, "Ndigits", 1000 ); + sc = nt2->farray( "firing", digit_firing, "Ndigits", 1000 ); + sc = nt2->farray( "multip", digit_multi, "Ndigits", 1000 ); sc = nt2->write(); if ( sc.isFailure() && msgLevel( MSG::DEBUG ) ) debug() << "Failure writing nt2" << endmsg; } @@ -381,8 +377,8 @@ StatusCode MuonDigitChecker::finalize() { info() << statStr.str() << endmsg; for ( int r = 0; r < 4; r++ ) { for ( int s = 0; s < nStations; s++ ) { - if ( cnt[s][r][c] ) { - info() << format( "%5.3lf ", (double)nhit[s][r][c] / cnt[s][r][c] ); + if ( m_cnt[s][r][c] ) { + info() << format( "%5.3lf ", (double)m_nhit[s][r][c] / m_cnt[s][r][c] ); } else { info() << "0.000 "; } @@ -408,8 +404,8 @@ StatusCode MuonDigitChecker::finalize() { info() << statStr.str() << endmsg; for ( int r = 0; r < 4; r++ ) { for ( int s = 0; s < nStations; s++ ) { - if ( Dcnt[s][r][c] ) { - info() << format( "%5.3lf ", (double)nDhit[s][r][c] / Dcnt[s][r][c] ); + if ( m_Dcnt[s][r][c] ) { + info() << format( "%5.3lf ", (double)m_nDhit[s][r][c] / m_Dcnt[s][r][c] ); } else { info() << "0.000 "; } @@ -418,10 +414,7 @@ StatusCode MuonDigitChecker::finalize() { } } - if ( NULL != m_base ) { - delete m_base; - m_base = NULL; - } + m_base.reset(); // Execute the base class finalize return GaudiTupleAlg::finalize(); diff --git a/Muon/MuonMoniDigi/src/MuonDigitChecker.h b/Muon/MuonMoniDigi/src/MuonDigitChecker.h index 60df3726f49dc1306e90bf13719d968324c65c22..8e9c8adde17f967caba3811efbf0940235c9fa7f 100755 --- a/Muon/MuonMoniDigi/src/MuonDigitChecker.h +++ b/Muon/MuonMoniDigi/src/MuonDigitChecker.h @@ -28,17 +28,15 @@ public: /// Standard constructor MuonDigitChecker( const std::string& name, ISvcLocator* pSvcLocator ); - virtual ~MuonDigitChecker(); ///< Destructor StatusCode initialize() override; /// initialization StatusCode execute() override; /// execution StatusCode finalize() override; /// finalization -protected: private: - int nhit[5][4][4], cnt[5][4][4]; - int nDhit[5][4][6], Dcnt[5][4][6]; + int m_nhit[5][4][4], m_cnt[5][4][4]; + int m_nDhit[5][4][6], m_Dcnt[5][4][6]; - bool m_hitMonitor; - MuonBasicGeometry* m_base; + bool m_hitMonitor; + std::unique_ptr<MuonBasicGeometry> m_base; }; #endif // MuonDigitChecker_H