diff --git a/examples/hodtest.C b/examples/hodtest.C index bac859d6ad0a95f8560874f3ba8bda6b2b138151..cd4d937a257d7a3a3fc9fe75979631b106c06cda 100644 --- a/examples/hodtest.C +++ b/examples/hodtest.C @@ -71,6 +71,7 @@ analyzer->SetOutFile( "hodtest.root" ); analyzer->SetOdefFile("output.def"); analyzer->SetCutFile("hodtest_cuts.def"); // optional + analyzer->SetCountMode(2);// Counter event number same as gen_event_ID_number // File to record cuts accounting information // analyzer->SetSummaryFile("summary_example.log"); // optional diff --git a/examples/report.template b/examples/report.template index 5856b9fa3ddd981872b1450616f7bd56e24a7278..53b51a8eedd9bd1fde7bf0d4b103f3ceaf33e9ff 100644 --- a/examples/report.template +++ b/examples/report.template @@ -28,6 +28,14 @@ a c-style format after the expression. The HMS reconstruction coefficient file name is {h_recon_coeff_filename} The names of the HMS drift chamber planes are: {hdc_plane_names} +DC Events: {hdc_tot_events} +Hit in chamber: {hdc_cham_hits[0]/hdc_tot_events:%.3f} {hdc_cham_hits[1]/hdc_tot_events:%.3f} +Hit in plane: {hdc_hits_per_plane[0]/hdc_tot_events:%.3f} {hdc_hits_per_plane[1]/hdc_tot_events:%.3f} {hdc_hits_per_plane[2]/hdc_tot_events:%.3f} {hdc_hits_per_plane[3]/hdc_tot_events:%.3f} {hdc_hits_per_plane[4]/hdc_tot_events:%.3f} {hdc_hits_per_plane[5]/hdc_tot_events:%.3f} {hdc_hits_per_plane[6]/hdc_tot_events:%.3f} {hdc_hits_per_plane[7]/hdc_tot_events:%.3f} {hdc_hits_per_plane[8]/hdc_tot_events:%.3f} {hdc_hits_per_plane[9]/hdc_tot_events:%.3f} {hdc_hits_per_plane[10]/hdc_tot_events:%.3f} {hdc_hits_per_plane[11]/hdc_tot_events:%.3f} + +Run #{gen_run_number} +first event = {gen_run_starting_event:%7d} +last event = {gen_event_id_number:%7d} + Later, such things as hardware scalers will be added to the set of variables that can be used in expressions. diff --git a/src/THcAnalyzer.cxx b/src/THcAnalyzer.cxx index d238146d4de58a6f40c9e3ff1a4c2a4cca7fe0dc..6c97bba481b5793e99d0a1a9568d61d7053fee0e 100644 --- a/src/THcAnalyzer.cxx +++ b/src/THcAnalyzer.cxx @@ -22,6 +22,7 @@ ////////////////////////////////////////////////////////////////////////// #include "THcAnalyzer.h" +#include "THaRunBase.h" #include "THaBenchmark.h" #include "TList.h" #include "THcParmList.h" @@ -74,8 +75,11 @@ void THcAnalyzer::PrintReport(const char* templatefile, const char* ofile) if(!ostr.is_open()) { cout << "Error opening report output file " << ofile << endl; + return; } + LoadInfo(); // Load some run information into gHcParms + // In principle, we should allow braces to be escaped. But for // now we won't. Existing template files don't seem to output // any braces @@ -115,7 +119,11 @@ void THcAnalyzer::PrintReport(const char* templatefile, const char* ofile) format = "%f"; } } - replacement=Form(format.c_str(),value); + if(format[format.length()-1] == 'd') { + replacement=Form(format.c_str(),TMath::Nint(value)); + } else { + replacement=Form(format.c_str(),value); + } } // cout << "Replacement:" << replacement << endl; line.replace(start,end-start+1,replacement); @@ -128,6 +136,46 @@ void THcAnalyzer::PrintReport(const char* templatefile, const char* ofile) return; } +//_____________________________________________________________________________ +void THcAnalyzer::LoadInfo() +{ + // Copy some run information into gHcParms variables so that in can + // be used in reports. + // For example run number, first event analyzed, number of events, etc. + Int_t* runnum; + Int_t* firstevent; + Int_t* lastevent; + + THaVar* varptr; + varptr = gHcParms->Find("gen_run_number"); + if(varptr) { + runnum = (Int_t*) varptr->GetValuePointer(); // Assume correct type + } else { + runnum = new Int_t[1]; + gHcParms->Define("gen_run_number","Run Number", *runnum); + } + *runnum = fRun->GetNumber(); + + varptr = gHcParms->Find("gen_run_starting_event"); + if(varptr) { + firstevent = (Int_t*) varptr->GetValuePointer(); // Assume correct type + } else { + firstevent = new Int_t[1]; + gHcParms->Define("gen_run_starting_event","First event analyzed", *firstevent); + } + // May not agree with engine event definintions + *firstevent = fRun->GetFirstEvent(); + + varptr = gHcParms->Find("gen_event_id_number"); + if(varptr) { + lastevent = (Int_t*)varptr->GetValuePointer(); // Assume correct type + } else { + lastevent = new Int_t[1]; + gHcParms->Define("gen_event_id_number","Last event analyzed", *lastevent); + } + // Not accurate + *lastevent = fRun->GetFirstEvent()+fRun->GetNumAnalyzed(); +} //_____________________________________________________________________________ diff --git a/src/THcAnalyzer.h b/src/THcAnalyzer.h index e57d75e361826b42c4c310bfaaa4c76ef7c71992..fcb2842a5017d91e233478c0901a5b67be965722 100644 --- a/src/THcAnalyzer.h +++ b/src/THcAnalyzer.h @@ -27,7 +27,8 @@ protected: private: // THcAnalyzer( const THcAnalyzer& ); // THcAnalyzer& operator=( const THcAnalyzer& ); - + void LoadInfo(); + ClassDef(THcAnalyzer,0) //Hall C Analyzer Standard Event Loop }; diff --git a/src/THcDC.cxx b/src/THcDC.cxx index b963890ebb176face292160a7d3c0365db578d38..30ecae9c696bc2928409c1651fcfc1ec4664ec45 100644 --- a/src/THcDC.cxx +++ b/src/THcDC.cxx @@ -80,18 +80,17 @@ void THcDC::Setup(const char* name, const char* description) { static const char* const here = "Setup"; - char prefix[2]; THaApparatus *app = GetApparatus(); if(app) { cout << app->GetName() << endl; + fPrefix[0]=tolower(app->GetName()[0]); + fPrefix[1]='\0'; } else { cout << "No apparatus found" << endl; + fPrefix[0]='\0'; } - prefix[0]=tolower(app->GetName()[0]); - prefix[1]='\0'; - string planenamelist; DBRequest list[]={ {"dc_num_planes",&fNPlanes, kInt}, @@ -102,7 +101,7 @@ void THcDC::Setup(const char* name, const char* description) {0} }; - gHcParms->LoadParmValues((DBRequest*)&list,prefix); + gHcParms->LoadParmValues((DBRequest*)&list,fPrefix); cout << planenamelist << endl; cout << "Drift Chambers: " << fNPlanes << " planes in " << fNChambers << " chambers" << endl; @@ -164,7 +163,8 @@ THaAnalysisObject::EStatus THcDC::Init( const TDatime& date ) static const char* const here = "Init()"; Setup(GetName(), GetTitle()); // Create the subdetectors here - + EffInit(); + // Should probably put this in ReadDatabase as we will know the // maximum number of hits after setting up the detector map THcHitList::InitHitList(fDetMap, "THcRawDCHit", 1000); @@ -231,7 +231,6 @@ Int_t THcDC::ReadDatabase( const TDatime& date ) // 'date' contains the date/time of the run being analyzed. // static const char* const here = "ReadDatabase()"; - char prefix[2]; // Read data from database // Pull values from the THcParmList instead of reading a database @@ -243,10 +242,6 @@ Int_t THcDC::ReadDatabase( const TDatime& date ) // Will need to determine which spectrometer in order to construct // the parameter names (e.g. hscin_1x_nr vs. sscin_1x_nr) - prefix[0]=tolower(GetApparatus()->GetName()[0]); - - prefix[1]='\0'; - delete [] fXCenter; fXCenter = new Double_t [fNChambers]; delete [] fYCenter; fYCenter = new Double_t [fNChambers]; delete [] fMinHits; fMinHits = new Int_t [fNChambers]; @@ -311,7 +306,7 @@ Int_t THcDC::ReadDatabase( const TDatime& date ) {"debugtrackprint", &fdebugtrackprint , kInt}, {0} }; - gHcParms->LoadParmValues((DBRequest*)&list,prefix); + gHcParms->LoadParmValues((DBRequest*)&list,fPrefix); if(fNTracksMaxFP <= 0) fNTracksMaxFP = 10; // if(fNTracksMaxFP > HNRACKS_MAX) fNTracksMaxFP = NHTRACKS_MAX; cout << "Plane counts:"; @@ -453,6 +448,7 @@ Int_t THcDC::Decode( const THaEvData& evdata ) } cout << endl; } + Eff(); // Accumlate statistics return fNhits; } @@ -473,6 +469,7 @@ Int_t THcDC::CoarseTrack( TClonesArray& tracks ) // Apply corrections and reconstruct the complete hits. // // static const Double_t sqrt2 = TMath::Sqrt(2.); + for(Int_t i=0;i<fNChambers;i++) { fChambers[i]->FindSpacePoints(); fChambers[i]->CorrectHitTimes(); @@ -974,5 +971,49 @@ Double_t THcDC::DpsiFun(Double_t ray[4], Int_t plane) return(DpsiFun); } +//_____________________________________________________________________________ +Int_t THcDC::End(THaRunBase* run) +{ + // EffCalc(); +} + +//_____________________________________________________________________________ +void THcDC::EffInit() +{ + // Create, and initialize counters used to calculate + // efficiencies. Register the counters in gHcParms so that the + // variables can be used in end of run reports. + + delete [] fNChamHits; fNChamHits = new Int_t [fNChambers]; + delete [] fHitsPerPlane; fHitsPerPlane = new Int_t [fNPlanes]; + + fTotEvents = 0; + for(Int_t i=0;i<fNChambers;i++) { + fNChamHits[i] = 0; + } + for(Int_t i=0;i<fNPlanes;i++) { + fHitsPerPlane[i] = 0; + } + gHcParms->Define(Form("%sdc_tot_events",fPrefix),"Total DC Events",fTotEvents); + gHcParms->Define(Form("%sdc_cham_hits[%d]",fPrefix,fNChambers),"N events with hits per chamber",*fNChamHits); + gHcParms->Define(Form("%sdc_hits_per_plane[%d]",fPrefix,fNPlanes),"N events with hits per plane",*fHitsPerPlane); + cout << Form("%sdc_hits_per_plane[%d]",fPrefix,fNPlanes) << endl; +} + +//_____________________________________________________________________________ +void THcDC::Eff() +{ + // Accumulate statistics for efficiency calculations + + fTotEvents++; + for(Int_t i=0;i<fNChambers;i++) { + if(fChambers[i]->GetNHits()>0) fNChamHits[i]++; + } + for(Int_t i=0;i<fNPlanes;i++) { + if(fPlanes[i]->GetNHits() > 0) fHitsPerPlane[i]++; + } + return; +} + ClassImp(THcDC) //////////////////////////////////////////////////////////////////////////////// diff --git a/src/THcDC.h b/src/THcDC.h index fecf5be966ac3c7626d24b2e5aada4ea66402ca6..041b2eb6baf4bd2b5ef7d131469e7b359c538ea7 100644 --- a/src/THcDC.h +++ b/src/THcDC.h @@ -84,6 +84,7 @@ protected: // Calibration // Hall C Parameters + char fPrefix[2]; Int_t fNPlanes; // Total number of DC planes char** fPlaneNames; Int_t fNChambers; @@ -137,6 +138,11 @@ protected: Double_t* fSigma; Double_t** fPlaneCoeffs; + // For accumulating statitics for efficiencies + Int_t fTotEvents; + Int_t* fNChamHits; + Int_t* fHitsPerPlane; + // Useful derived quantities // double tan_angle, sin_angle, cos_angle; @@ -155,6 +161,9 @@ protected: void LinkStubs(); void TrackFit(); Double_t DpsiFun(Double_t ray[4], Int_t plane); + Int_t End(THaRunBase* run); + void EffInit(); + void Eff(); void Setup(const char* name, const char* description); diff --git a/src/THcDriftChamber.h b/src/THcDriftChamber.h index d9e1afa0c0861368fc0d2e395c9d81dcc0f7016a..33eb2458d2d7274240a4ba6397d035e90d1a4e0a 100644 --- a/src/THcDriftChamber.h +++ b/src/THcDriftChamber.h @@ -44,7 +44,7 @@ public: virtual void Clear( Option_t* opt="" ); - // Int_t GetNHits() const { return fNhit; } + Int_t GetNHits() const { return fNhits; } Int_t GetNSpacePoints() const { return(fNSpacePoints);} Int_t GetNTracks() const { return fTrackProj->GetLast()+1; } const TClonesArray* GetTrackHits() const { return fTrackProj; }