12#include "Identifier/Identifier.h"
71 std::string OccupancyCacheName =
"GlobalTRTOccupancyData";
77 return StatusCode::SUCCESS;
81 std::vector<float> output ;
83 ATH_MSG_INFO(
"Cannot compute Global Occupancies in trigger environment! Returning empty vector");
89 ATH_MSG_INFO(
"Cannot get occupancy data. Returning empty vector.");
93 output.push_back(
data->m_occ_total[0]*1.e-2 ) ;
94 output.push_back(
data->m_occ_total[1]*1.e-2 ) ;
95 output.push_back(
data->m_occ_total[2]*1.e-2 ) ;
96 output.push_back(
data->m_occ_total[3]*1.e-2 ) ;
97 output.push_back(
data->m_occ_total[4]*1.e-2 ) ;
98 output.push_back(
data->m_occ_total[5]*1.e-2 ) ;
99 output.push_back(
data->m_occ_total[6]*1.e-2 ) ;
102 << output.at(0) <<
"\t Barrel C: " << output.at(1)
103 <<
"\t EndcapA C: " << output.at(2) <<
"\t EndcapB C: "
104 << output.at(3) <<
"\t Barrel A: " << output.at(4)
105 <<
"\t EndcapA A: " << output.at(5)
106 <<
"\t EndcapB A: " << output.at(6));
112 ATH_MSG_DEBUG(
"Compute LocalOccupancy(const Trk::Track& track ) for tool: " << name());
119 for (;tsos!=tsosEnd;++tsos) {
142 track_local[i_total-1][
phi] +=1;
146 std::unique_ptr<OccupancyData> data_ptr;
151 data = data_ptr.get();
157 ATH_MSG_INFO(
"Cannot get occupancy data. Returning 0.");
161 float averageocc = 0;
163 const std::array<std::array<int,NLOCALPHI>,
NLOCAL> &stw_local =
data->m_stw_local;
165 for (
int i=0; i<6; ++i){
166 for (
int j = 0; j < 32; j++){
168 float hits_array = track_local[i][j] ;
169 if (hits_array<1)
continue;
171 occ = (
data->m_occ_local [i][j])*1.e-2 ;
172 if (stw_local[i][j] != 0){
173 if(occ == 0 &&
float(hits_array)/stw_local[i][j] > 0.01){
174 ATH_MSG_DEBUG(
"Occupancy is 0 for : " << i <<
" " << j <<
" BUT THERE ARE HITS!!!: " << hits_array);
178 averageocc += (occ*hits_array);
181 ATH_MSG_DEBUG(
"new track: " << i <<
" " << j <<
"\t" << hits_array <<
"\t" << occ );
184 if (nhits>0) averageocc = averageocc / nhits;
185 ATH_MSG_DEBUG(
"Compute LocalOccupancy(const Trk::Track& track ) for tool: " << averageocc <<
" is over" );
197 std::map<int,int> hitCounter;
198 std::map<int,double> occResults;
202 for ( ; RDO_collection_iter!= RDO_collection_end; ++RDO_collection_iter) {
204 if (!RDO_Collection)
continue;
205 if (!RDO_Collection->
empty()){
208 for(
r=rb;
r!=
re; ++
r) {
222 unsigned int word = (*r)->getWord();
226 unsigned mask = 0x02000000;
227 bool SawZero =
false;
229 for(tdcvalue=0;tdcvalue<24;++tdcvalue)
231 if ( (word & mask) && SawZero)
break;
232 if ( !(word & mask) ) SawZero =
true;
234 if(tdcvalue==7 || tdcvalue==15) mask>>=1;
236 if(tdcvalue!=0 && tdcvalue!=24) {
251 const std::array<int,TRTCond::AliveStraws::NTOTAL> &straws = strawCounts->
getStwTotal();
253 occResults[-1] = (double)hitCounter[-1]/(
double)straws[1];
254 occResults[-2] = (double)hitCounter[-2]/(
double)(straws[2] + straws[3]);
255 occResults[1] = (double)hitCounter[1] /(
double)straws[4];
256 occResults[2] = (double)hitCounter[2] /(
double)(straws[5] + straws[6]);
268 if (!driftCircleContainer.
isValid()){
273 bool allOfEndcapAFound[2][
NLOCALPHI] = {{
false}};
275 for (
int i=0; i<
NLOCAL; ++i){
279 if (track_local[i][j] < 1)
continue;
282 if (
data.m_hit_local[i][j] > 0)
continue;
284 for (
const InDet::TRT_DriftCircleCollection *colNext : *driftCircleContainer) {
285 if (!colNext)
continue;
288 for(; p_rdo!=p_rdo_end; ++p_rdo){
299 if (i_total != i ||
phi != j)
continue;
301 if (i%3==1 && lay>4) allOfEndcapAFound[(i<3?0:1)][
phi]=
true;
303 data.m_hit_local[i_total][
phi] +=1;
307 int hits =
data.m_hit_local[i][j];
308 int stws =
data.m_stw_local[i][j];
309 data.m_occ_local[i][j] = int(hits*100) / stws;
317 for (
int i=0; i<
NLOCAL; ++i){
319 if (i%3!=1)
continue;
321 if (track_local[i][j] < 1)
continue;
322 if (!allOfEndcapAFound[(i<3?0:1)][j] && !region_rescaled[i][j]){
326 data.m_occ_local[i][j]/=(
data.m_stws_ratio[(i<3?0:1)][j]);
327 region_rescaled[i][j]=
true;
329 else if (allOfEndcapAFound[(i<3?0:1)][j] && region_rescaled[i][j]){
333 data.m_occ_local[i][j]*=(
data.m_stws_ratio[(i<3?0:1)][j]);
334 region_rescaled[i][j]=
false;
343 const double t_phi)
const {
360 if (partition > 5 || phisector > 31) {
362 return data->m_occ_total[0]*1.e-2 ;
365 float mapped_occ =
data->m_occ_local[partition][phisector]*1.e-2;
375 unsigned mask = 0x00010000;
377 for (i=0; i<8; ++i) {
378 if (word & mask)
return true;
385 bool foundInterval =
false;
386 unsigned mask = 0x02000000;
388 while ( !foundInterval && (i < 24) ) {
390 float thisTime = ((0.5+i)*3.125)-
t0;
394 if (i == 7 || i == 15)
398 return foundInterval;
407 if (det == -1) arrayindex = 1;
408 else if (det == -2) {
409 if (lay < 6) arrayindex = 2;
412 else if (det == 1) arrayindex = 4;
414 if (lay < 6) arrayindex = 5;
417 else ATH_MSG_WARNING(
" detector value is: " << det <<
", out of range -2, -1, 1, 2, so THIS IS NOT TRT!!!");
428 double phi2pi = (t_phi > 0) ? t_phi : t_phi + 2*
M_PI;
430 phisector = int ( (phi2pi + dphi)*32./(2*
M_PI) );
438 double abseta = fabs(t_eta);
441 if ( abseta <= 0.90 ) partition = 0;
442 else if ( abseta > 0.90 && abseta <= 1.55 ) partition = 1;
443 else if ( abseta > 1.55 && abseta <= 2.00 ) partition = 2;
446 if (t_eta>0.) partition += 3;
460 return wh.put (
makeData(ctx),
true);
464std::unique_ptr<TRT_LocalOccupancy::OccupancyData>
471 auto data = std::make_unique<OccupancyData>(strawCounts->
getStwLocal());
478 if ( driftCircleContainer.
isValid() ) {
480 for (
const InDet::TRT_DriftCircleCollection *colNext : *driftCircleContainer) {
481 if(!colNext)
continue;
485 for(; p_rdo!=p_rdo_end; ++p_rdo){
495 data->m_hit_total[0] +=1;
496 data->m_hit_total[i_total] +=1;
497 data->m_hit_local[i_total-1][
phi] +=1;
505 const std::array<int,NTOTAL> &stw_total = strawCounts->
getStwTotal();
506 const std::array<std::array<int,NLOCALPHI>,
NLOCAL> &stw_local = strawCounts->
getStwLocal();
509 for (
int i=0; i<
NTOTAL; ++i) {
511 int hits =
data->m_hit_total[i];
512 int stws = stw_total[i];
513 if (stws>0) occ = float(hits*100)/stws;
514 data->m_occ_total[i] = int(occ);
516 for (
int i=0; i<
NLOCAL; ++i) {
519 int hits =
data->m_hit_local[i][j];
520 int stws = stw_local[i][j];
521 if (stws>0) occ = float(hits*100)/stws;
522 data->m_occ_local[i][j] = int(occ);
526 ATH_MSG_DEBUG(
"Active straws: " << stw_total[0] <<
"\t total number of hits: "
527 <<
data->m_hit_total[0]
528 <<
"\t occ: " <<
data->m_occ_total[0]);
533std::unique_ptr<TRT_LocalOccupancy::OccupancyData>
539 auto data = std::make_unique<OccupancyData>(strawCounts->
getStwLocal());
540 const std::array<std::array<int,NLOCALPHI>,
NLOCAL> &stw_local = strawCounts->
getStwLocal();;
541 const std::array<std::array<int,NLOCALPHI>,
NWHEEL> &stw_wheel = strawCounts->
getStwWheel();
543 for (
int i=0; i<5; ++i){
545 data->m_stws_ratio[0][j]+=float(stw_wheel[i+3 ][j])/stw_local[1][j];
546 data->m_stws_ratio[1][j]+=float(stw_wheel[i+20][j])/stw_local[4][j];
const boost::regex re(r_e)
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
#define CHECK(...)
Evaluate an expression and check for errors.
char data[hepevt_bytes_allocation_ATLAS]
Handle class for reading from StoreGate.
This is an Identifier helper class for the TRT subdetector.
InDetRawDataContainer< InDetRawDataCollection< TRT_RDORawData > > TRT_RDO_Container
DataModel_detail::const_iterator< DataVector > const_iterator
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
bool empty() const noexcept
Returns true if the collection is empty.
const_iterator end() const
return const_iterator for end of container
const_iterator begin() const
return const_iterator for first entry
This is a "hash" representation of an Identifier.
Represents 'corrected' measurements from the TRT (for example, corrected for wire sag).
std::unique_ptr< OccupancyData > makeData(const EventContext &ctx) const
SG::ReadCondHandleKey< TRTCond::AliveStraws > m_strawReadKey
SG::ReadHandleKey< TRT_DriftCircleContainer > m_trt_driftcircles
Gaudi::Property< bool > m_T0Shift
TRT_LocalOccupancy(const std::string &, const std::string &, const IInterface *)
std::unique_ptr< OccupancyData > makeDataTrigger(const EventContext &ctx) const
virtual std::map< int, double > getDetectorOccupancy(const EventContext &ctx, const TRT_RDO_Container *p_trtRDOContainer) const override
Return a map of the occupancy in the barrel (-1,+1) and endcaps (-2,+2)
Gaudi::Property< float > m_lowWideGate
SG::WriteHandleKey< OccupancyData > m_occupancyCacheWrite
static bool isMiddleBXOn(unsigned int word)
Gaudi::Property< float > m_highWideGate
static const int NLOCALPHI
virtual float LocalOccupancy(const EventContext &ctx, const Trk::Track &track) const override
Return the local occupancy for the sectors crossed by a given track.
const TRT_ID * m_TRTHelper
External tools:
static int mapPhiToPhisector(const double phi)
virtual StatusCode initialize() override
standard Athena-Algorithm method
Gaudi::Property< float > m_lowGate
SG::ReadHandleKey< OccupancyData > m_occupancyCacheRead
const OccupancyData * getData(const EventContext &ctx) const
int mapEtaToPartition(const double eta) const
bool passValidityGate(unsigned int word, float t0) const
ToolHandle< ITRT_CalDbTool > m_CalDbTool
Gaudi::Property< float > m_highGate
SG::ReadCondHandleKey< TRTCond::StrawStatusData > m_strawStatusKey
int findArrayTotalIndex(const int det, const int lay) const
To convert from array index to det id and viceversa.
virtual std::vector< float > GlobalOccupancy(const EventContext &ctx) const override
Return the global occupancy of the event.
void countHitsNearTrack(const EventContext &ctx, OccupancyData &data, int track_local[NLOCAL][NLOCALPHI]) const
Gaudi::Property< bool > m_isTrigger
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
const std::array< std::array< int, NLOCALPHI >, NWHEEL > & getStwWheel() const
const std::array< int, NTOTAL > & getStwTotal() const
const std::array< std::array< int, NLOCALPHI >, NLOCAL > & getStwLocal() const
unsigned int findStatus(const IdentifierHash &hashID) const
This is an Identifier helper class for the TRT subdetector.
This class is the pure abstract base class for all fittable tracking measurements.
virtual bool type(MeasurementBaseType::Type type) const =0
Interface method checking the type.
Identifier identify() const
return the identifier
Class to handle RIO On Tracks ROT) for InDet and Muons, it inherits from the common MeasurementBase.
Identifier identify() const
return the identifier -extends MeasurementBase
virtual bool rioType(RIO_OnTrackType::Type type) const =0
Method checking the Rio On Track type.
DataVector< const Trk::TrackStateOnSurface > TrackStates