diff --git a/Digi/Boole/CMakeLists.txt b/Digi/Boole/CMakeLists.txt index 7dc169beb563411c5db72eb61a991f5cc52a3c5f..f2ab200780e6ca0b1a6c3b2dc1331033d9c032ee 100644 --- a/Digi/Boole/CMakeLists.txt +++ b/Digi/Boole/CMakeLists.txt @@ -34,7 +34,6 @@ if(BUILD_TESTING AND USE_DD4HEP) set_property( TEST # these test are using condition Conditions/Calibration/VP/VPDigitisationParam/Thresholds - Boole.boole-Muon Boole.boole-spillover Boole.boole-upgrade-baseline Boole.boole-run3 diff --git a/Muon/MuonAlgs/src/MuonDigitization.cpp b/Muon/MuonAlgs/src/MuonDigitization.cpp index a3971091c91bc659e1457c4adb2c4802e870d86b..8f68205c12412ba6f50b53f8c40245b62f643b8c 100644 --- a/Muon/MuonAlgs/src/MuonDigitization.cpp +++ b/Muon/MuonAlgs/src/MuonDigitization.cpp @@ -33,6 +33,12 @@ #include <string> #include <vector> #ifdef USE_DD4HEP +# include "Detector/Muon/DeMuon.h" +# include "Detector/Muon/DeMuonChamber.h" +# include "Detector/Muon/MuonConstants.h" +# include "Detector/Muon/MuonVolumeID.h" +# include "Detector/Muon/Namespace.h" +# include "LbDD4hep/ConditionAccessorHolder.h" # include <DD4hep/GrammarUnparsed.h> #endif @@ -55,6 +61,16 @@ private: : det{muonDet}, detectorResponse{std::make_unique<MuonDetectorResponse>( muonDet, randSvc, msgSvc )} {} Cache& operator=( Cache&& ) = default; + // ---- EDL ---- + // To do as it is defined in MuonDigitChecker.cpp cache + // ------- + // int maxDimension() const { return gaps * stationsNumber; } + // int chamberOffset( int station, int region ) const { return chamberInRegion[station * 4 + region]; } + // int stationsNumber = 0; + // std::vector<std::string> stationsNames; + // unsigned int gaps = 0; + // std::array<int, 20> chamberInRegion; + // ---- DetElementRef<DeMuonDetector> det; std::unique_ptr<MuonDetectorResponse> detectorResponse; }; @@ -176,7 +192,8 @@ StatusCode MuonDigitization::execute() const { debug() << "muon x , y, z entry , " << i->entry().x() << " " << i->entry().y() << " " << i->entry().z() << endmsg; debug() << "time of flight , " << i->time() << endmsg; - int det = i->sensDetID(); + + int det = cache.det->sensitiveVolumeID( i->midPoint() ); debug() << " chamber and gap ID " << cache.det->chamberID( det ) << " " << cache.det->gapID( det ) << endmsg; } @@ -315,15 +332,30 @@ void MuonDigitization::createInput( MuonDigitizationData<MuonPhyChannelInput>& P SmartDataPtr<LHCb::MCHits> hitPointer( eventSvc(), path ); if ( !hitPointer ) continue; + int MyDetID; + for ( auto& iter : *hitPointer ) { // loop over hits - const int det = iter->sensDetID(); + if ( m_verboseDebug ) { + info() << "createInput: midpoint " << iter->midPoint().x() << " " << iter->midPoint().y() << " " + << iter->midPoint().z() << endmsg; + } + MyDetID = cache.det->sensitiveVolumeID( iter->midPoint() ); + int det = MyDetID; + if ( m_verboseDebug ) { + info() << "createInput: MyDetID " << cache.det->sensitiveVolumeID( iter->midPoint() ) << endmsg; + } if ( det < 0 ) continue; - const unsigned int hitStation = cache.det->stationID( det ); - const unsigned int hitRegion = cache.det->regionID( det ); - const unsigned int hitChamber = cache.det->chamberID( det ); - const unsigned int hitGap = cache.det->gapID( det ); - const unsigned int hitQuarter = cache.det->quadrantID( det ); + const unsigned int hitStation = cache.det->stationID( MyDetID ); + const unsigned int hitRegion = cache.det->regionID( MyDetID ); + // ---- EDL ---- + // To do as it is defined in MuonDigitChecker.cpp cache + // ------- + // const unsigned int hitChamber = cache.det->chamberID( MyDetID ) + cache.chamberOffset( hitStation, hitRegion + // ); + const unsigned int hitChamber = cache.det->chamberID( MyDetID ); + const unsigned int hitGap = cache.det->gapID( MyDetID ); + const unsigned int hitQuarter = cache.det->quadrantID( MyDetID ); for ( const auto& [fe, distanceFromBoundary] : cache.det->listOfPhysChannels( iter->entry(), iter->exit(), hitRegion, hitChamber ) ) { @@ -359,9 +391,12 @@ void MuonDigitization::createInput( MuonDigitizationData<MuonPhyChannelInput>& P if ( m_verboseDebug ) { const int code = ( iter->mcParticle() ? iter->mcParticle()->particleID().abspid() : 0 ); - info() << "hit processing " << hitStation << " " << hitRegion << " " << hitQuarter << " " << hitChamber - << " " << hitGap << " " << fe.getLayer() << " " << fe.getReadout() << " " << tofOfLight << " " - << OriginOfHitsContainer[container] << " " << ispill << " " << code << endmsg; + info() << "hit processing Station = " << hitStation << " Region = " << hitRegion + << " Quarter = " << hitQuarter << " Chamber = " << hitChamber << " Gap = " << hitGap + << " fe.getLayer() = " << fe.getLayer() << " fe.getReadout() = " << fe.getReadout() + << " tofOfLight = " << tofOfLight + << " OriginOfHitsContainer[container] = " << OriginOfHitsContainer[container] + << " ispill = " << ispill << " code = " << code << endmsg; info() << " ph ch ID " << inputPointer.phChID() << " id " << inputPointer.phChID().getID() << endmsg; } diff --git a/Muon/MuonBackground/src/MuonBackground.cpp b/Muon/MuonBackground/src/MuonBackground.cpp index b2eea4b3a36663b43f9f697a4bf5c4678fb62f44..521cccb8c46379c26dc89c17958faf62dd81cad6 100755 --- a/Muon/MuonBackground/src/MuonBackground.cpp +++ b/Muon/MuonBackground/src/MuonBackground.cpp @@ -49,6 +49,12 @@ #endif #ifdef USE_DD4HEP +# include "Detector/Muon/DeMuon.h" +# include "Detector/Muon/DeMuonChamber.h" +# include "Detector/Muon/MuonConstants.h" +# include "Detector/Muon/MuonVolumeID.h" +# include "Detector/Muon/Namespace.h" +# include "LbDD4hep/ConditionAccessorHolder.h" # include <DD4hep/GrammarUnparsed.h> #endif @@ -276,13 +282,14 @@ MuonBackground::Cache MuonBackground::makeCache( const DeMuonDetector& det ) con StatusCode MuonBackground::execute() { const Cache& c = m_cache.get( getConditionContext( Gaudi::Hive::currentContext() ) ); - if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Execute" << m_readSpilloverEvents << endmsg; + if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Execute m_readSpilloverEvents = " << m_readSpilloverEvents << endmsg; StatusCode sc; for ( int ispill = 0; ispill <= m_readSpilloverEvents; ispill++ ) { auto collisions = calculateNumberOfCollision( ispill ); if ( !collisions ) continue; - if ( msgLevel( MSG::VERBOSE ) ) verbose() << "==> collision " << collisions << endmsg; + if ( msgLevel( MSG::VERBOSE ) ) + verbose() << "================= ispill = " << ispill << " and ==> collision " << collisions << endmsg; LHCb::MCHits* hitsContainer = new LHCb::MCHits(); std::vector<std::vector<int>> results{collisions}; @@ -294,7 +301,9 @@ StatusCode MuonBackground::execute() { for ( unsigned int multi = 0; multi < c.gaps; multi++ ) { int index = station * c.gaps + multi; int startingHits = results[coll][index]; - if ( msgLevel( MSG::VERBOSE ) ) verbose() << "station safe start end hits " << startingHits << endmsg; + if ( msgLevel( MSG::VERBOSE ) ) + verbose() << "> collision n. " << coll << " station n. " << station << " multi n. " << multi << endmsg; + if ( msgLevel( MSG::VERBOSE ) ) verbose() << "> station safe start end hits " << startingHits << endmsg; // extract number of hits to be added int hitToAdd = 0; @@ -310,8 +319,9 @@ StatusCode MuonBackground::execute() { // yy<< " "<< hitToAdd<<" "<<startingHits<<endmsg; if ( msgLevel( MSG::VERBOSE ) ) - verbose() << "adding " << hitToAdd << " to orginal " << startingHits << " in station " << station - << " for multiplicity " << multi << " and collisions/spill " << coll << " " << ispill << endmsg; + verbose() << " m_type == LowEnergy >> adding " << hitToAdd << " to orginal " << startingHits + << " in station " << station << " for multiplicity " << multi << " and collisions/spill " + << coll << " " << ispill << endmsg; for ( int hitID = 0; hitID < hitToAdd; hitID++ ) { StatusCode asc = createHit( c, hitsContainer, station, multi, ispill ); @@ -359,8 +369,8 @@ StatusCode MuonBackground::execute() { int hitToAdd = 0; hitToAdd = howManyHit( floatHit ); if ( msgLevel( MSG::VERBOSE ) ) - verbose() << "adding " << hitToAdd << " in station " << station << " for multiplicity " << multi - << " and spill" << fspill << endmsg; + verbose() << " m_type == FlatSpill >> adding " << hitToAdd << " in station " << station + << " for multiplicity " << multi << " and spill" << fspill << endmsg; for ( int hitID = 0; hitID < hitToAdd; hitID++ ) { StatusCode asc = createHit( c, hitsContainer, station, multi, fspill ); if ( asc.isFailure() && msgLevel( MSG::DEBUG ) ) debug() << "failing hit creation " << endmsg; @@ -547,23 +557,27 @@ StatusCode MuonBackground::calculateStartingNumberOfHits( const Cache& c, int is preGap = -1; preIndex = -1; preChamber = -1; + int MyDetID; + if ( hitPointer != 0 ) { for ( auto& hit : *hitPointer ) { - int det = hit->sensDetID(); - if ( det < 0 ) continue; - - station = c.det->stationID( det ); - region = c.det->regionID( det ); - gap = c.det->gapID( det ); - - chamber = c.det->chamberID( det ) + c.chamberOffset( station, region ); - index = hit->mcParticle()->key(); - if ( msgLevel( MSG::VERBOSE ) ) { - verbose() << " index, chamber, gap " << index << " " << chamber << " " << gap << endmsg; - verbose() << " index " << index << " in position " << hit->entry().x() << " " << hit->entry().y() << " " - << hit->entry().z() << " " - << " out position " << hit->exit().x() << " " << hit->exit().y() << " " << hit->exit().z() - << endmsg; + MyDetID = c.det->sensitiveVolumeID( hit->midPoint() ); + if ( msgLevel( MSG::DEBUG ) ) debug() << " calculateStartingNumberOfHit >>> MyDetID " << MyDetID << endmsg; + if ( MyDetID < 0 ) continue; + + station = c.det->stationID( MyDetID ); + region = c.det->regionID( MyDetID ); + gap = c.det->gapID( MyDetID ); + chamber = c.det->chamberID( MyDetID ) + c.chamberOffset( station, region ); + + index = hit->mcParticle()->key(); + if ( msgLevel( MSG::DEBUG ) ) { + debug() << " MyDetID " << MyDetID << endmsg; + debug() << " station, region " << station << " " << region << endmsg; + debug() << " index, chamber, gap " << index << " " << chamber << " " << gap << endmsg; + debug() << " index " << index << " in position " << hit->entry().x() << " " << hit->entry().y() << " " + << hit->entry().z() << " " + << " out position " << hit->exit().x() << " " << hit->exit().y() << " " << hit->exit().z() << endmsg; } const LHCb::MCVertex* pointVertex = hit->mcParticle()->primaryVertex(); unsigned int collNumber = numberOfCollision( pointVertex, vtxList ); @@ -602,7 +616,7 @@ StatusCode MuonBackground::calculateStartingNumberOfHits( const Cache& c, int is } } - if ( msgLevel( MSG::DEBUG ) ) debug() << " --- end of routine " << endmsg; + if ( msgLevel( MSG::DEBUG ) ) debug() << " <== calculateStartingNumberOfHit --- end of routine " << endmsg; return StatusCode::SUCCESS; } @@ -680,8 +694,14 @@ MuonBackground::getRadialPosition( const Cache& c, int index, int station ) cons float ypos = float( r * sin( globalPhi ) * Gaudi::Units::mm * m_unitLength ); try { + DetElementRef<DeMuonChamber> chamber = c.det->pos2StChamber( xpos, ypos, station ); - // check n ot only that hit is inside chamber but also gap... + if ( msgLevel( MSG::DEBUG ) ) + debug() << " MuonBackground::getRadialPosition ==> Chamber stationNumber " << chamber->stationNumber() + << " Chamber regionNumber " << chamber->regionNumber() << " station " << station << " position " + << xpos << " " << ypos << " " << endmsg; + + // check not only that hit is inside chamber but also gap... if ( chamber->checkHitAndGapInChamber( xpos, ypos ) ) { // remember this is the chamber number inside a region.... if ( msgLevel( MSG::DEBUG ) ) @@ -704,6 +724,8 @@ StatusCode MuonBackground::createHit( const Cache& c, LHCb::MCHits* hitsContaine int ispill ) const { int index = station * c.gaps + multi; + if ( msgLevel( MSG::DEBUG ) ) + debug() << "MuonBackground::createHit >> station = " << station << " multi = " << multi << endmsg; // 1) extract the radial position auto pos = getRadialPosition( c, index, station ); @@ -770,7 +792,12 @@ StatusCode MuonBackground::createHit( const Cache& c, LHCb::MCHits* hitsContaine pChamber->calculateHitPosInGap( gapNumber, xpos, ypos, xSlope, ySlope, averageZ, entryGlobal, exitGlobal ); if ( success ) { if ( msgLevel( MSG::DEBUG ) ) debug() << "found hit in chamber " << endmsg; + if ( msgLevel( MSG::DEBUG ) ) + debug() << " gapNumber " << gapNumber << " xpos " << xpos << " ypos " << ypos << " xSlope " << xSlope + << " ySlope " << ySlope << " averageZ " << averageZ << " entryGlobal " << entryGlobal + << " exitGlobal " << exitGlobal << endmsg; } else { + if ( msgLevel( MSG::DEBUG ) ) debug() << "NOT found hit in chamber " << endmsg; allHitsInsideCha = false; } } @@ -815,12 +842,22 @@ StatusCode MuonBackground::createHit( const Cache& c, LHCb::MCHits* hitsContaine } if ( msgLevel( MSG::DEBUG ) ) debug() << " mid point " << x << " " << y << " " << z << endmsg; - int sen = c.det->sensitiveVolumeID( Gaudi::XYZPoint( x, y, z ) ); + ROOT::Math::XYZPoint midpoint( x, y, z ); + + if ( msgLevel( MSG::DEBUG ) ) + debug() << " midpoint x = " << midpoint.x() << " y = " << midpoint.y() << " z = " << midpoint.z() << endmsg; + int sen = c.det->sensitiveVolumeID( midpoint ); + if ( msgLevel( MSG::DEBUG ) ) debug() << " the volume ID is " << sen << endmsg; + if ( msgLevel( MSG::DEBUG ) ) + debug() << " Station " << c.det->stationID( sen ) << " Region " << c.det->regionID( sen ) << " Gap " + << c.det->gapID( sen ) << endmsg; + pHit->setSensDetID( sen ); + if ( msgLevel( MSG::DEBUG ) ) - debug() << "gap, time, position " << gapNumber << " " << pChamber->chamberNumber() << " " - << timeBest + tofOfLight << " " << x << " " << y << " " << endmsg; + debug() << "gap, pChamber->chamberNumber(), time, position " << gapNumber << " " << pChamber->chamberNumber() + << " " << timeBest + tofOfLight << " " << x << " " << y << " " << endmsg; if ( correct ) { ( hitsContainer )->push_back( pHit ); if ( msgLevel( MSG::DEBUG ) ) { diff --git a/Muon/MuonMoniDigi/src/MuonDigitChecker.cpp b/Muon/MuonMoniDigi/src/MuonDigitChecker.cpp index 4cb7f12e9c30215cfbcbe099399f567831d3d92d..e4bd736f9c249175bff7a7fcc74c64f0c13859a9 100644 --- a/Muon/MuonMoniDigi/src/MuonDigitChecker.cpp +++ b/Muon/MuonMoniDigi/src/MuonDigitChecker.cpp @@ -143,8 +143,7 @@ void MuonDigitChecker::operator()( const LHCb::MCHeader& evt, const LHCb::MCHits int MyDetID; // Loop over Muon Hits of given type for ( const auto* hit : hits ) { - - MyDetID = hit->sensDetID(); + MyDetID = muon.sensitiveVolumeID( hit->midPoint() ); if ( MyDetID < 0 ) continue; // Needs to extract info from sens ID int station = muon.stationID( MyDetID ); @@ -303,16 +302,21 @@ void MuonDigitChecker::operator()( const LHCb::MCHeader& evt, const LHCb::MCHits digit_firing.push_back( Dfir ); digit_origin.push_back( Dcon ); digit_bx.push_back( Deve ); - + if ( msgLevel( MSG::DEBUG ) ) debug() << " Hit origin = " << Dcon << " = " << endmsg; // Hits mupltiplicity digit_multi.push_back( MCmd->mcHits().size() ); // if(Deve) ++tnDhit[( ( Dsta + m_stationIdOffset ) * 4 + Dreg ) * 6 + Dcon]; - // if(globalTimeOffset()>0)info()<<" qui "<<Dcon<<" "<<Dfir<<" "<<Deve<<" "<<Dsta<<" "<<Dreg<<endmsg; + if ( msgLevel( MSG::DEBUG ) ) + debug() << " Firing Time" << Dfir << " Belongs to event ? " << Deve << " Station " << Dsta << " Region " << Dreg + << endmsg; } // the weird start of loop is to skip M1 if not present - for ( std::size_t i = m_stationIdOffset * 4 * 6; i < tnDhit.size(); ++i ) { m_avgDHits[i] += tnDhit[i]; } + for ( std::size_t i = m_stationIdOffset * 4 * 6; i < tnDhit.size(); ++i ) { + m_avgDHits[i] += tnDhit[i]; + if ( msgLevel( MSG::DEBUG ) ) debug() << " i = " << i << " m_avgDHits[i] = " << m_avgDHits[i] << endmsg; + } // -- Fill some histos with digits infos plot( occu[0], 3002, "Digits Multiplicity Station M2 ", 0., 350., 50 );