Skip to content

Commit

Permalink
Keep and print statistics about multihit warnings in THaScintillator
Browse files Browse the repository at this point in the history
If fDebug>0, per-event warnings are printed, as before. Otherwise
End() prints a summary, which is what people are usually interested in.

Better yet would be a scintilaltor Decode() method that actually deals
with multiple hits on a channel. But at least the nuisance warnings
are gone now.

Closes #37 and Redmine bug 64.
  • Loading branch information
hansenjo committed Jan 23, 2018
1 parent eff79bd commit ab263d7
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 10 deletions.
91 changes: 83 additions & 8 deletions src/THaScintillator.C
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <iostream>
#include <cassert>
#include <iomanip>
#include <sstream>

using namespace std;

Expand Down Expand Up @@ -335,6 +336,70 @@ void THaScintillator::DeleteArrays()
delete [] fYa; fYa = NULL;
}

//_____________________________________________________________________________
Int_t THaScintillator::Begin( THaRunBase* r )
{
// Clear warning message buffer at the beginning of analysis

THaNonTrackingDetector::Begin(r);

fMessages.clear();
fNEventsWithWarnings = 0;
return 0;
}

//_____________________________________________________________________________
Int_t THaScintillator::End( THaRunBase* r )
{
// Print warning message summary at end of analysis

THaNonTrackingDetector::End(r);

if( !fMessages.empty() ) {
ULong64_t ntot = 0;
map<string,UInt_t> chan_count;
for( map<string,UInt_t>::const_iterator it = fMessages.begin();
it != fMessages.end(); ++it ) {
ntot += it->second;
const string& m = it->first;
string::size_type pos = m.find("channel");
if( pos > 3 ) pos -= 4;
++chan_count[m.substr(pos)]; // e.g. substr = "TDC channel 1/2/3"
}
ostringstream msg;
msg << endl
<< " Encountered " << fNEventsWithWarnings << " events with "
<< "multihit warnings, " << ntot << " total warnings"
<< endl
<< " affecting " << chan_count.size() << " out of "
<< fDetMap->GetTotNumChan() << " channels. Check signals for noise!"
<< endl
<< " Call Print(\"WARN\") for channel list. "
<< "Re-run with fDebug>0 for per-event details.";
Warning( Here("End"), "%s", msg.str().c_str() );
}
return 0;
}

//_____________________________________________________________________________
void THaScintillator::Print( Option_t* opt ) const
{
// Print scintillator details

THaNonTrackingDetector::Print(opt);

if( opt && strstr(opt,"WARN") != 0 && !fMessages.empty() ) {
string name = GetPrefix();
if( !name.empty() && name[name.length()-1] == '.' )
name.erase(name.length()-1);
cout << "Scintillator \"" << name << "\" multihit warnings:" << endl;
for( map<string,UInt_t>::const_iterator it = fMessages.begin();
it != fMessages.end(); ++it ) {
cout << " " << it->first << ": " << it->second << " times" << endl;
}
}
}

//_____________________________________________________________________________
void THaScintillator::Clear( Option_t* opt )
{
Expand Down Expand Up @@ -365,6 +430,7 @@ Int_t THaScintillator::Decode( const THaEvData& evdata )

// Loop over all modules defined for this detector

bool multihit_warning = false;
for( Int_t i = 0; i < fDetMap->GetSize(); i++ ) {
THaDetMap::Module* d = fDetMap->GetModule( i );
bool adc = ( d->model ? fDetMap->IsADC(d) : (i < fDetMap->GetSize()/2) );
Expand All @@ -375,26 +441,32 @@ Int_t THaScintillator::Decode( const THaEvData& evdata )
Int_t chan = evdata.GetNextChan( d->crate, d->slot, j );
if( chan < d->lo || chan > d->hi ) continue; // Not one of my channels

#ifdef WITH_DEBUG
Int_t nhit = evdata.GetNumHits(d->crate, d->slot, chan);
if( nhit > 1 )
Warning( Here("Decode"), "%d hits on %s channel %d/%d/%d",
nhit, adc ? "ADC" : "TDC", d->crate, d->slot, chan );
if( nhit > 1 ) {
ostringstream msg;
msg << nhit << " hits on " << (adc ? "ADC" : "TDC")
<< " channel " << d->crate << "/" << d->slot << "/" << chan;
++fMessages[msg.str()];
#ifdef WITH_DEBUG
if( fDebug>0 ) {
Warning( Here("Decode"), "Event %d: %s", evdata.GetEvNum(),
msg.str().c_str() );
}
#endif
multihit_warning = true;
}
// Get the data. Scintillators are assumed to have only single hit (hit=0)
Int_t data = evdata.GetData( d->crate, d->slot, chan, 0 );

// Get the detector channel number, starting at 0
Int_t k = d->first + ((d->reverse) ? d->hi - chan : chan - d->lo) - 1;

#ifdef WITH_DEBUG
if( k<0 || k>NDEST*fNelem ) {
// Indicates bad database
Warning( Here("Decode()"), "Illegal detector channel: %d", k );
Warning( Here("Decode()"), "Illegal detector channel: %d. "
"Fix detector map in database", k );
continue;
}
// cout << "adc,j,k = " <<adc<<","<<j<< ","<<k<< endl;
#endif
// Copy the data to the local variables.
DataDest* dest = fDataDest + k/fNelem;
k = k % fNelem;
Expand All @@ -411,6 +483,9 @@ Int_t THaScintillator::Decode( const THaEvData& evdata )
}
}

if( multihit_warning )
++fNEventsWithWarnings;

#ifdef WITH_DEBUG
if ( fDebug > 3 ) {
cout << endl << endl;
Expand Down
11 changes: 9 additions & 2 deletions src/THaScintillator.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
///////////////////////////////////////////////////////////////////////////////

#include "THaNonTrackingDetector.h"
#include <map>

class TClonesArray;

Expand All @@ -19,11 +20,14 @@ class THaScintillator : public THaNonTrackingDetector {
THaScintillator();
virtual ~THaScintillator();

virtual void Clear( Option_t* ="" );
virtual Int_t Begin( THaRunBase* r=0 );
virtual void Clear( Option_t* opt="" );
virtual Int_t End( THaRunBase* r=0 );
virtual Int_t Decode( const THaEvData& );
virtual EStatus Init( const TDatime& run_time );
virtual Int_t CoarseProcess( TClonesArray& tracks );
virtual Int_t FineProcess( TClonesArray& tracks );
virtual void Print( Option_t* opt="" ) const;

virtual Int_t ApplyCorrections( void );

Expand Down Expand Up @@ -99,6 +103,9 @@ class THaScintillator : public THaNonTrackingDetector {
Double_t* fYt; // [fNelem] y-position of hit in paddle from TDC (m)
Double_t* fYa; // [fNelem] y-position of hit in paddle from ADC (m)

std::map<std::string,UInt_t> fMessages; // Warning messages & count
UInt_t fNEventsWithWarnings; // Events with warnings

void DeleteArrays();
virtual Int_t ReadDatabase( const TDatime& date );
virtual Int_t DefineVariables( EMode mode = kDefine );
Expand All @@ -108,7 +115,7 @@ class THaScintillator : public THaNonTrackingDetector {
virtual Double_t TimeWalkCorrection( const Int_t& paddle,
const ESide side );

ClassDef(THaScintillator,1) // Generic scintillator class
ClassDef(THaScintillator,2) // Generic scintillator class
};

////////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit ab263d7

Please sign in to comment.