PhotonStatSummarizer Class Reference

#include <PhotonStatSummarizer.h>

Inheritance diagram for PhotonStatSummarizer:
Summarizer CfgPromptConfigurable

List of all members.

Public Member Functions

 PhotonStatSummarizer ()
virtual void ConfigModified ()
virtual ~PhotonStatSummarizer ()
virtual void SummarizePoint (VldContext vldPointStart, VldContext vldPoint)
virtual void LoadDataFromDB (VldContext vldPoint)
virtual void ComputePmtDrifts ()
virtual void ComputeDetectorDrift ()
virtual void FillPmtDatabase (Int_t version, VldContext vldPointStart, Int_t task)
virtual bool DoesTableExist (Int_t version, VldContext vldPointStart, Int_t task)
virtual void FillTrees (VldContext vldPoint)
void CreateTables ()

Protected Types

typedef std::map
< PlexPixelSpotId, SpotDrift
SpotList_t
typedef std::map< UInt_t,
PmtDrift
PmtList_t

Protected Member Functions

 ClassDef (PhotonStatSummarizer, 0)

Protected Attributes

Int_t fTask
Bool_t fOverwriteDB
Bool_t fWriteDB
Bool_t fWriteDetTree
Bool_t fWritePmtTree
Bool_t fWriteSpotTree
Int_t fPrescale
Int_t fWhichEnd
DbiResultPtr< PulserDriftfDriftTable
SpotList_t fSpots
PmtList_t fPmts
DetectorDrift fDetectorDrift
TTree * fPmtTree
TTree * fSpotTree
TTree * fDetTree
TFile * fFile

Detailed Description

Definition at line 104 of file PhotonStatSummarizer.h.


Member Typedef Documentation

typedef std::map<UInt_t,PmtDrift> PhotonStatSummarizer::PmtList_t [protected]

Definition at line 152 of file PhotonStatSummarizer.h.

Definition at line 149 of file PhotonStatSummarizer.h.


Constructor & Destructor Documentation

PhotonStatSummarizer::PhotonStatSummarizer (  ) 

Definition at line 84 of file PhotonStatSummarizer.cxx.

References CreateTables(), fDetTree, fFile, fPmtTree, fSpotTree, fTask, fWhichEnd, CfgPromptConfigurable::InitializeConfig(), Pulser::kFarEnd, Pulser::kNearEnd, CalPmtDrift::kPhotonStat, CalPmtDrift::kPhotonStatFarEnd, and Registry::Set().

00085 {
00086   CreateTables();
00087 
00088   fTask = CalPmtDrift::kPhotonStat;
00089   if(fWhichEnd==Pulser::kFarEnd) fTask = CalPmtDrift::kPhotonStatFarEnd;
00090 
00091   Registry r;
00092   r.Set("WriteDB",1);
00093   r.Set("OverwriteDB",0);
00094   r.Set("WriteDetTree",1);
00095   r.Set("WritePmtTree",1);
00096   r.Set("WriteSpotTree",0);
00097   r.Set("FileName","drifts.root");
00098   r.Set("Prescale",0);
00099   r.Set("WhichEnd",Pulser::kNearEnd); // near 1 far 2
00100 
00101   InitializeConfig(r);
00102 
00103   fDetTree = fPmtTree = fSpotTree = 0;
00104   fFile = 0;
00105 }

PhotonStatSummarizer::~PhotonStatSummarizer (  )  [virtual]

Definition at line 120 of file PhotonStatSummarizer.cxx.

References fDetTree, fFile, fPmtTree, fSpotTree, Msg::kInfo, and MSG.

00121 {
00122   if(fDetTree) {
00123     MSG("PmtDrift",Msg::kInfo) << "Writing Detector tree data." << endl;
00124     fDetTree->Write("",TObject::kOverwrite);
00125   }
00126 
00127   if(fPmtTree) {
00128     MSG("PmtDrift",Msg::kInfo) << "Writing PMT tree data." << endl;
00129     fPmtTree->Write("",TObject::kOverwrite);
00130   }
00131 
00132   if(fSpotTree) {
00133     MSG("PmtDrift",Msg::kInfo) << "Writing PixelSpot tree data." << endl;
00134     fSpotTree->Write("",TObject::kOverwrite);
00135   }
00136 
00137   if(fFile) {    
00138     MSG("PmtDrift",Msg::kInfo) << "Closing file." << endl;  
00139     fFile->Write();
00140     delete fFile;
00141   };
00142 }


Member Function Documentation

PhotonStatSummarizer::ClassDef ( PhotonStatSummarizer  ,
 
) [protected]
void PhotonStatSummarizer::ComputeDetectorDrift (  )  [virtual]

Definition at line 452 of file PhotonStatSummarizer.cxx.

References fDetectorDrift, fPmts, fSpots, Munits::g, PlexMuxBoxId::GetEastWest(), PlexMuxBoxId::GetRackBay(), PlexMuxBoxId::GetRackLevel(), DetectorDrift::highestPmt, it, DetectorDrift::lowestPmt, DetectorDrift::meanPmtGain, DetectorDrift::meanSpotGain, n, DetectorDrift::numPmts, DetectorDrift::numSpots, DetectorDrift::Reset(), and DetectorDrift::section.

Referenced by SummarizePoint().

00453 {
00454   fDetectorDrift.Reset();
00455 
00456   double tot = 0;
00457   double tot2 = 0;
00458   double n = 0;
00459 
00460   // Loop spots.
00461   SpotList_t::iterator it;
00462   SpotList_t::iterator end= fSpots.end();
00463   for(it = fSpots.begin(); it!=end; it++) {
00464     double g = it->second.gain;
00465     tot += g;
00466     tot2 += g*g;
00467     n+=1.0;
00468   }
00469   if(n>2) {
00470     fDetectorDrift.meanSpotGain = tot/n;
00471     fDetectorDrift. rmsSpotGain = sqrt(fabs(tot2 - tot*tot/n)/(n-1));
00472   }
00473   fDetectorDrift.numSpots = n;
00474 
00475 
00476   // Loop PMTs.
00477   tot=tot2=n=0;
00478   double stots[8];
00479   double sn[8];
00480   for(UInt_t i=0;i<8;i++) { stots[i] = sn[i] = 0; };
00481 
00482   PmtList_t::iterator pit;
00483   PmtList_t::iterator pend = fPmts.end();
00484   for(pit = fPmts.begin(); pit!=pend; pit++) {
00485     PlexPixelSpotId psid = pit->second.pmt;
00486     int section = 0;
00487     if(psid.GetEastWest()!='E') section+=1;
00488     if(psid.GetRackLevel()!='L') section+=2;
00489     if(psid.GetRackBay()>8) section+=4;
00490 
00491     double g = pit->second.finalGain;
00492     tot += g;
00493     tot2+= g*g;
00494     n+=1;
00495     if(g<fDetectorDrift.lowestPmt) fDetectorDrift.lowestPmt = g;
00496     if(g>fDetectorDrift.highestPmt) fDetectorDrift.highestPmt = g;    
00497     stots[section] +=g;
00498     sn[section] += 1.0;
00499   }
00500 
00501   if(n>2) {
00502     fDetectorDrift.meanPmtGain = tot/n;
00503     fDetectorDrift. rmsPmtGain = sqrt(fabs(tot2 - tot*tot/n)/(n-1));
00504   }
00505   fDetectorDrift.numPmts = n;
00506   for(UInt_t i=0;i<8;i++) {
00507     if(sn[i]>0)  fDetectorDrift.section[i] = stots[i]/sn[i];
00508   };
00509   
00510 }

void PhotonStatSummarizer::ComputePmtDrifts (  )  [virtual]

Definition at line 334 of file PhotonStatSummarizer.cxx.

References PlexPixelSpotId::AsString(), PmtDrift::bay, PmtDrift::encoded, PmtDrift::finalGain, Form(), fPmts, fSpots, PlexMuxBoxId::GetEastWest(), PlexPixelSpotId::GetEncoded(), PlexMuxBoxId::GetInRack(), PlexMuxBoxId::GetRackBay(), PlexMuxBoxId::GetRackLevel(), PlexPixelSpotId::GetTube(), PlexPixelSpotId::GetUniquePmtEncodedValue(), GetWeightedMean(), PmtDrift::highestGain, it, Msg::kDebug, Msg::kError, PmtDrift::level, PmtDrift::lowestGain, PmtDrift::meanGain, MSG, PmtDrift::muxbox, PmtDrift::nbadHigh, PmtDrift::nbadLow, PmtDrift::ngood, PmtDrift::nspot, PmtDrift::pmt, PmtDrift::rawGain, PmtDrift::rcid, PlexPixelSpotId::SetPixel(), PlexPixelSpotId::SetSpot(), PmtDrift::side, PmtDrift::spots, PmtDrift::sysError, and PmtDrift::tube.

Referenced by SummarizePoint().

00335 {
00337   // Fill the spot data into the PMT objects:
00338   fPmts.clear();
00339 
00340   SpotList_t::iterator it;
00341   SpotList_t::iterator end= fSpots.end();
00342 
00343   for(it = fSpots.begin(); it!=end; it++) {
00344     PlexPixelSpotId pmt = it->first;
00345     FloatErr spotGain = it->second.gain;
00346 
00347     
00348     PmtDrift& d = fPmts[pmt.GetUniquePmtEncodedValue()];
00349     d.pmt = pmt;
00350 
00351     if(d.nspot>127) {
00352       MSG("PmtDrift",Msg::kError) << "Found too many spots. " << it->first.AsString() << endl;
00353     } else {
00354      d.spots[d.nspot] = it->second;
00355      d.nspot    += 1;
00356     }
00357     if(spotGain > d.highestGain) d.highestGain = spotGain;
00358     if(spotGain < d.lowestGain) d.lowestGain = spotGain;    
00359     d.rcid = it->second.rcid;
00360     //cout << "Inserting spot " << pmt.AsString() << " into pmt " << pmt.GetUniquePmtEncodedValue() << " gain " << spotGain << endl;
00361     //d.Print();
00362     //fPmts.begin()->second.Print();
00363   }
00364 
00366   // Compute the PMT statistics.
00367 
00368   PmtList_t::iterator pit;
00369   PmtList_t::iterator pend = fPmts.end();
00370 
00371   for(pit = fPmts.begin(); pit!=pend; pit++) {
00372     PmtDrift& d = pit->second;
00373 
00374     PlexPixelSpotId pmt = d.pmt;
00375     d.pmt.SetPixel(127);
00376     d.pmt.SetSpot(15);
00377     d.encoded = pmt.GetEncoded();
00378     d.side = pmt.GetEastWest();
00379     d.level = pmt.GetRackLevel();
00380     d.bay = pmt.GetRackBay();
00381     d.muxbox = pmt.GetInRack();
00382     d.tube   = pmt.GetTube();
00383 
00384     // Compute raw mean:
00385     d.rawGain = 0;
00386     for(int i=0;i<d.nspot;i++) d.rawGain += d.spots[i].gain/FloatErr(d.nspot);
00387     // Find the biggest gain and throw it out.
00388     int   big = 0;
00389     for(int i=0;i<d.nspot;i++) if(d.spots[i].gain > d.spots[big].gain) { big=i; };
00390     d.spots[big].bad=3; // make it bad.
00391 
00392     // sort the spots by goodness:
00393     std::sort(d.spots.begin(),d.spots.begin() + d.nspot);
00394     
00395     // Start throwing them out.
00396     d.ngood = 0;
00397     d.nbadLow = d.nbadHigh = 0;
00398 
00399     for(Int_t i=0;i<d.nspot;i++) {
00400       if(d.spots[i].bad ==0) d.ngood++;
00401       else if(d.spots[i].bad ==1) d.nbadLow++;
00402       else if(d.spots[i].bad ==2) d.nbadHigh++;
00403     }
00404     
00405     // Because we sorted, the first d.ngood spots are the good ones.
00406     
00407     if(d.ngood>0) {
00408 
00409       // Work out the mean gain, using only good spots.
00410       d.meanGain = 0;
00411       for(int i=0;i<d.ngood;i++) d.meanGain+=d.spots[i].gain / FloatErr(d.ngood,0);
00412       
00413       // The final gain is created using weights.
00414       d.finalGain = GetWeightedMean(d.spots.begin(), d.spots.begin() + d.ngood);
00415 
00416       // Work out the systematic error.
00417       int worst = d.ngood-1; // Worst is the last in list.
00418       if( (d.ngood<d.nspot)               // There are bad ones in the list.
00419           //&& (d.spots[d.ngood-1].bad<2) // The first bad one isn't VERY bad.
00420           ) {
00421           worst = d.ngood;  // Use the first bad one for the error estimate.
00422       }
00423 
00424       // Without the worst one:
00425       FloatErr meanWithout(0,0);
00426       FloatErr meanWith(0,0);
00427 
00428       //meanWithout = GetWeightedMean(d.spots.begin(), d.spots.begin() + worst);
00429       for(int i=0;i<worst;i++) meanWithout += d.spots[i].gain / FloatErr(worst);
00430 
00431       // With the worst one:
00432       //meanWith = GetWeightedMean(d.spots.begin(), d.spots.begin() + worst + 1);
00433       meanWith = (meanWithout*FloatErr(worst) + d.spots[worst].gain) / FloatErr(worst+1);
00434  
00435       //cout << meanWithout << "\t" << meanWith << "\t" << meanWithout-meanWith << endl;
00436 
00437       d.sysError = fabs(meanWith - meanWithout);
00438 
00439       MSG("PmtDrift",Msg::kDebug) << "Pmt " << d.pmt.AsString() 
00440                                   << Form("%3d %3d", d.nspot, d.ngood)
00441                                   << " \t" << d.finalGain 
00442                                   << " \t" << d.rawGain 
00443                                   << " \t" << d.sysError
00444                                   << " \t" << d.lowestGain 
00445                                   << " \t" << d.highestGain 
00446                                   << endl;
00447 
00448     }
00449   }
00450 }

void PhotonStatSummarizer::ConfigModified ( void   )  [virtual]

Implements CfgPromptConfigurable.

Definition at line 107 of file PhotonStatSummarizer.cxx.

References fOverwriteDB, fPrescale, fWhichEnd, fWriteDB, fWriteDetTree, fWritePmtTree, fWriteSpotTree, CfgPromptConfigurable::GetConfig(), and Registry::GetInt().

00108 {
00109   fWriteDB = GetConfig().GetInt("WriteDB");
00110   fOverwriteDB = GetConfig().GetInt("OverwriteDB");
00111   fWriteDetTree = GetConfig().GetInt("WriteDetTree");
00112   fWritePmtTree = GetConfig().GetInt("WritePmtTree");
00113   fWriteSpotTree = GetConfig().GetInt("WriteSpotTree");
00114   fPrescale = GetConfig().GetInt("Prescale");
00115   fWhichEnd = GetConfig().GetInt("WhichEnd");
00116 
00117 }

void PhotonStatSummarizer::CreateTables (  ) 

Definition at line 198 of file PhotonStatSummarizer.cxx.

References DbiCascader::CreateStatement(), DbiStatement::ExecuteUpdate(), DbiTableProxyRegistry::GetCascader(), and DbiTableProxyRegistry::Instance().

Referenced by PhotonStatSummarizer().

00199 {
00200   // create tables.
00201 
00202   DbiStatement* s = DbiTableProxyRegistry::Instance()
00203     .GetCascader()
00204     .CreateStatement(0);
00205   
00206   //s->ExecuteUpdate("drop table CALPMTDRIFTVLD");
00207   //s->ExecuteUpdate("drop table CALPMTDRIFT");
00208 
00209 
00210   s->ExecuteUpdate("create table if not exists CALPMTDRIFTVLD ("
00211                    " SEQNO         int not null primary key auto_increment,"
00212                    " TIMESTART     datetime not null,"
00213                    " TIMEEND       datetime not null,"
00214                    " DETECTORMASK  tinyint,"
00215                    " SIMMASK       tinyint,"
00216                    " TASK          int,"
00217                    " AGGREGATENO   int,"
00218                    " CREATIONDATE  datetime not null,"
00219                    " INSERTDATE    datetime not null )");
00220 
00221   s->ExecuteUpdate("create table if not exists CALPMTDRIFT ("
00222                    " SEQNO integer,"
00223                    " ROW_COUNTER int, "
00224                    " PMT bigint, "
00225                    " CHANNEL bigint,"
00226                    " DRIFT float, "
00227                    " STATERROR float,"
00228                    " SYSERROR float,"
00229                    " SPOTSUSED float,"
00230                    " SPOTSAVAIL float,"
00231                    " CRUDEDRIFT float,"
00232                    " MINDRIFT float,"
00233                    " MAXDRIFT float,"
00234                    " index (SEQNO))");
00235 }

bool PhotonStatSummarizer::DoesTableExist ( Int_t  version,
VldContext  vldPointStart,
Int_t  task 
) [virtual]

Definition at line 585 of file PhotonStatSummarizer.cxx.

References VldTimeStamp::AsString(), Form(), VldContext::GetDetector(), DbiResultPtr< T >::GetNumRows(), VldContext::GetSimFlag(), VldContext::GetTimeStamp(), VldRange::GetTimeStart(), DbiResultPtr< T >::GetValidityRec(), DbiValidityRec::GetVldRange(), Msg::kWarning, and MSG.

Referenced by SummarizePoint().

00588 {
00589   // Question: Does a table already exist with this data?
00590   // Return true if it does.
00591 
00592   // Compose the VldTimeStamp for the creation date.
00593   // This is the time the data was taken, plus an integer number of seconds
00594   // representing the version number of the constants generator.
00595   VldTimeStamp creationTime = vldPointStart.GetTimeStamp() + VldTimeStamp(version,0);
00596 
00597   const char* sqltxt = Form("(CREATIONDATE='%s') and (TASK=%d) and (DETECTORMASK & %d) and (SIMMASK & %d) order by TIMESTART asc limit 1",
00598                             creationTime.AsString("s"),
00599                             task,
00600                             vldPointStart.GetDetector(),
00601                             vldPointStart.GetSimFlag() );
00602   
00603   DbiSqlContext myContext(sqltxt);
00604   
00605   DbiResultPtr<CalPmtDrift> resPtr("CALPMTDRIFT",myContext);
00606   VldTimeStamp ts= resPtr.GetValidityRec()->GetVldRange().GetTimeStart();
00607   
00608   if(ts == vldPointStart.GetTimeStamp()) {
00609     // This table already exists.
00610     if(resPtr.GetNumRows()==0) {
00611       MSG("PmtDrift",Msg::kWarning) << "..Found existing table version " << version << " but no data. Treating as empty." << endl;
00612       return false;
00613     }
00614 
00615     return true;
00616   } 
00617   return false;
00618 }

void PhotonStatSummarizer::FillPmtDatabase ( Int_t  version,
VldContext  vldPointStart,
Int_t  task 
) [virtual]

Definition at line 513 of file PhotonStatSummarizer.cxx.

References VldContext::AsString(), DbiWriter< T >::Close(), PmtDrift::finalGain, Form(), fPmts, RawChannelId::GetCrate(), VldContext::GetDetector(), ValueErr< T >::GetError(), VldContext::GetSimFlag(), VldContext::GetTimeStamp(), ValueErr< T >::GetValue(), PmtDrift::highestGain, Msg::kInfo, Detector::kNear, Msg::kWarning, PmtDrift::lowestGain, MSG, PmtDrift::ngood, PmtDrift::nspot, PmtDrift::pmt, PmtDrift::rawGain, PmtDrift::rcid, and PmtDrift::sysError.

Referenced by SummarizePoint().

00516 {
00517   if(fPmts.size() == 0) {
00518     MSG("PmtDrift",Msg::kWarning) << "No PMTs to fill into DB. " << vldPointStart.AsString() << endl;
00519   }
00520   VldTimeStamp creationTime = vldPointStart.GetTimeStamp() + VldTimeStamp(version,0);
00521   VldTimeStamp beginTime = vldPointStart.GetTimeStamp();
00522   VldTimeStamp endTime = beginTime + VldTimeStamp(3600*24,0); // 1 day later
00523   VldRange range(vldPointStart.GetDetector(),
00524                  vldPointStart.GetSimFlag(),
00525                  beginTime,
00526                  endTime,
00527                  "PhotonStatSummarizer::Summarize" );
00528 
00529   // Each crate in the detector is an aggregate, so loop through them all.
00530   int ncrates = 16;
00531   if(vldPointStart.GetDetector()==Detector::kNear) ncrates = 8;
00532 
00533   int crates_with_data = 0;
00534   int rows_total = 0;
00535   
00536   for(int crate = 0; crate< ncrates; crate++) {
00537     // Set up the DB writer.
00538     DbiWriter<CalPmtDrift> writer(range,
00539                                   crate, //aggregate,
00540                                   task, // task no
00541                                   creationTime,
00542                                   0,
00543                                   Form("Code version %d. Created by %s",
00544                                        version, 
00545                                        "$Id: PhotonStatSummarizer.cxx,v 1.25 2006/05/27 10:05:44 rhatcher Exp $")
00546                                   );
00547 
00548     PmtList_t::iterator pit;
00549     PmtList_t::iterator pend = fPmts.end();
00550     Int_t nrows = 0;
00551     
00552     for(pit = fPmts.begin(); pit!=pend; pit++) {
00553       PmtDrift& d         = pit->second;
00554       
00555       if(d.rcid.GetCrate()==crate) {
00556         CalPmtDrift cpd(d.pmt,
00557                         d.rcid,
00558                         d.finalGain.GetValue(),
00559                         d.finalGain.GetError(),
00560                         d.sysError,
00561                         d.ngood,
00562                         d.nspot,
00563                         d.rawGain,
00564                         d.lowestGain,
00565                         d.highestGain);
00566         
00567         writer << cpd;    
00568         nrows++;
00569       }
00570     }
00571     
00572     // Write only if data exists. Otherwise, trash it.
00573     if(nrows>0){
00574       writer.Close();
00575       crates_with_data++;
00576       rows_total += nrows;
00577     }
00578   }
00579 
00580   MSG("PmtDrift",Msg::kInfo) << "Wrote " << rows_total << " rows to DB from " 
00581                              << fPmts.size() << " PMTs, in " << crates_with_data << " aggregates" << endl;
00582 }

void PhotonStatSummarizer::FillTrees ( VldContext  vldPoint  )  [virtual]

Definition at line 621 of file PhotonStatSummarizer.cxx.

References VldContext::AsString(), fDetectorDrift, fDetTree, fFile, fPmts, fPmtTree, fSpots, fSpotTree, fWriteDetTree, fWritePmtTree, fWriteSpotTree, CfgPromptConfigurable::GetConfig(), Calibrator::GetTemperature(), Calibrator::Instance(), it, and CalScheme::Reset().

Referenced by SummarizePoint().

00622 {
00623   static DetectorDrift* det_ptr = 0;
00624   static PmtDrift* pmt_ptr =0;
00625   static SpotDrift* spot_ptr =0;
00626   static VldContext* cx_ptr = 0;
00627   static Float_t* temp_ptr = 0;
00628   static Float_t temp;
00629 
00630   if(fFile==0) {
00631     fFile = new TFile(GetConfig().GetCharString("FileName"),"RECREATE"); 
00632     fDetTree = (TTree*) fFile->Get("det");
00633     fPmtTree = (TTree*) fFile->Get("pmts");
00634     fSpotTree = (TTree*) fFile->Get("spots");
00635   }
00636   
00637   cx_ptr = &vldPoint;
00638   temp_ptr = &temp;
00639   Calibrator::Instance().Reset(vldPoint);
00640   temp = Calibrator::Instance().GetTemperature();
00641   cout << vldPoint.AsString() << " Temp = " << temp << endl;
00642 
00643   if(fWriteDetTree) {
00644     if(fPmtTree==0) {
00645       fDetTree = new TTree("det","det");
00646       fDetTree->Branch("det_br","DetectorDrift",&det_ptr,32000,3);
00647       fDetTree->Branch("cx_br","VldContext",&cx_ptr,32000,3);
00648       fDetTree->Branch("temp_br",temp_ptr,"T/F",32000);
00649     } else {
00650       fDetTree->SetBranchAddress("det_br",&det_ptr);
00651       fDetTree->SetBranchAddress("cx_br",&cx_ptr);
00652       fDetTree->SetBranchAddress("temp_br",temp_ptr);
00653     }    
00654     det_ptr = &fDetectorDrift;
00655     fDetTree->Fill();
00656     fDetTree->AutoSave();
00657   }
00658 
00659   
00660   if(fWritePmtTree) {
00661     if(fPmtTree==0) {
00662       fPmtTree = new TTree("pmts","pmts");
00663       fPmtTree->Branch("pmt_br","PmtDrift",&pmt_ptr,32000,3);
00664       fPmtTree->Branch("cx_br","VldContext",&cx_ptr,32000,3);
00665       fPmtTree->Branch("temp_br",temp_ptr,"T/F",32000);
00666     } else {
00667       fPmtTree->SetBranchAddress("pmt_br",&pmt_ptr);
00668       fPmtTree->SetBranchAddress("cx_br",&cx_ptr);
00669       fPmtTree->SetBranchAddress("temp_br",temp_ptr);
00670     }
00671     
00672     PmtList_t::iterator pit;
00673     PmtList_t::iterator pend = fPmts.end();
00674     for(pit = fPmts.begin(); pit!=pend; pit++) {
00675       pmt_ptr = &(pit->second);
00676       fPmtTree->Fill();
00677     }
00678     fPmtTree->AutoSave();
00679   }
00680 
00681   if(fWriteSpotTree) {
00682     if(fSpotTree==0) {
00683       fSpotTree = new TTree("spots","spots");
00684       fSpotTree->Branch("spot_br","SpotDrift",&spot_ptr,32000,3);
00685       fSpotTree->Branch("cx_br","VldContext",&cx_ptr,32000,3);
00686       fSpotTree->Branch("temp_br",temp_ptr,"T/F",32000);
00687     } else {
00688       fSpotTree->SetBranchAddress("spot_br",&spot_ptr);
00689       fSpotTree->SetBranchAddress("cx_br",&cx_ptr);
00690       fSpotTree->SetBranchAddress("temp_br",temp_ptr);
00691     }
00692 
00693     SpotList_t::iterator it;
00694     SpotList_t::iterator end= fSpots.end();
00695     
00696     for(it = fSpots.begin(); it!=end; it++) {
00697     spot_ptr = &(it->second);
00698     fSpotTree->Fill();
00699     }
00700     fSpotTree->AutoSave();
00701   }
00702 }

void PhotonStatSummarizer::LoadDataFromDB ( VldContext  vldPoint  )  [virtual]

Definition at line 239 of file PhotonStatSummarizer.cxx.

References VldContext::AsString(), PlexStripEndId::AsString(), SpotDrift::bad, SpotDrift::crate, err(), fDriftTable, fSpots, fWhichEnd, SpotDrift::gain, SpotDrift::geo, RawChannelId::GetCrate(), VldContext::GetDetector(), PulserDrift::GetError(), RawChannelId::GetGeographicAddress(), RawChannelId::GetMasterChannel(), PulserDrift::GetMean(), RawChannelId::GetMinderChannel(), PulserDrift::GetNumEntries(), DbiResultPtr< T >::GetNumRows(), PulserDrift::GetNumTriggers(), PlexHandle::GetPixelSpotId(), PlexHandle::GetRawChannelId(), DbiResultPtr< T >::GetRow(), PulserDrift::GetStripEnd(), RawChannelId::GetVaAdcSel(), RawChannelId::GetVaChannel(), RawChannelId::GetVaChip(), ValueErr< T >::GetValue(), RawChannelId::GetVarcId(), RawChannelId::GetVmm(), Msg::kInfo, ElecType::kVA, Msg::kWarning, SpotDrift::masterch, SpotDrift::mean, SpotDrift::minderch, MSG, SpotDrift::n, DbiResultPtr< T >::NewQuery(), SpotDrift::nflash, SpotDrift::psid, SpotDrift::rcid, SpotDrift::rms2, SpotDrift::seid, ValueErr< T >::SetError(), PlexStripEndId::UnbuildPlnStripEndKey(), SpotDrift::vachan, SpotDrift::vachip, SpotDrift::varc, SpotDrift::vfb, and SpotDrift::vmm.

Referenced by SummarizePoint().

00240 {
00241   fDriftTable.NewQuery(vldPoint,fWhichEnd);
00242   MSG("PmtDrift",Msg::kInfo) << "Loaded " << vldPoint.AsString() << " end = " << fWhichEnd << " rows = " << fDriftTable.GetNumRows() << endl;
00243 
00244   fSpots.clear();
00245 
00246   PlexHandle plex(vldPoint);
00247 
00248   for(UInt_t i=0;i<fDriftTable.GetNumRows();i++) {
00249     const PulserDrift* row = fDriftTable.GetRow(i);
00250     if(row) {
00251       PlexStripEndId seid = 
00252         PlexStripEndId::UnbuildPlnStripEndKey(vldPoint.GetDetector(),
00253                                               row->GetStripEnd()
00254                                               );
00255 
00256       PlexPixelSpotId psid = plex.GetPixelSpotId(seid);
00257       //cout << "Looking at " << row->GetStripEnd() << " " << seid.AsString() << " " << psid.AsString() << endl;
00258       //cout << row->GetStripEnd() << " " << row->GetAggregateNo() << " " << row->GetMean() << " " << row->GetError() << endl;
00259 
00260       if(psid.IsValid()) {
00261         SpotDrift& s = fSpots[psid];
00262         if(s.n != 0) MSG("PmtDrift",Msg::kWarning) << "Conflict! Two strips with psid " << psid.AsString() << " " << seid.AsString() << endl;
00263         s.seid = seid;
00264         s.psid = psid;
00265         s.rcid = plex.GetRawChannelId(seid);
00266         s.crate  =  s.rcid.GetCrate();
00267         s.geo      = s.rcid.GetGeographicAddress();
00268         s.masterch = s.rcid.GetMasterChannel();
00269         s.minderch = s.rcid.GetMinderChannel();
00270         s.varc = s.rcid.GetVarcId();
00271         s.vmm = s.rcid.GetVmm();
00272         s.vfb = s.rcid.GetVaAdcSel();
00273         s.vachip = s.rcid.GetVaChip();
00274         s.vachan = s.rcid.GetVaChannel();
00275           
00276         // Notes on the math:
00277         // Assuming a gaussian distribution:
00278         //
00279         // The variance on the mean is Var(x) = sigma^2
00280         // Error on the mean is = sigma/sqrt(N)
00281         // 
00282         // The variance on sigma^2 is:
00283         //   Var(sigma^2) = 2 sigma^4
00284         
00285         s.n        = row->GetNumEntries();
00286         s.nflash   = row->GetNumTriggers();
00287         s.mean     = FloatErr(row->GetMean(),row->GetError());
00288         float err  = row->GetError();
00289         s.rms2     = err*err*s.n;                // rms squared
00290         if(s.n>0)
00291           s.rms2.SetError(sqrt(2.0)*s.rms2.GetValue()/sqrt(s.n)); // Statisical error on sigma squared
00292         else 
00293           s.rms2.SetError(s.rms2.GetValue() * 1e9); // big
00294                 
00295         const FloatErr k1PeWidthCorr(1.0/1.2,0);
00296         
00297         // Includes error calculation:
00298         s.gain = (s.rms2/s.mean)*k1PeWidthCorr; // Rough correction for 1-pe width.
00299         
00300         // Apply zero-correction if the gain is obviously low.
00301         if(s.mean<150) {          
00302           FloatErr corrMean = s.mean*s.n/s.nflash;
00303           FloatErr corrRms2 = s.rms2; //((s.n-1)*s.rms2 + (s.nflash-s.n)*s.mean*s.mean) / FloatErr(s.nflash);
00304           s.gain = corrRms2/corrMean * k1PeWidthCorr;
00305         }
00306 
00307         if(psid.GetElecType()==ElecType::kVA) {
00308           // Appropriate for FD:        
00309           s.bad = 0; // good by default
00310           
00311           //if((s.n/s.nflash)<0.950) s.bad = 1; // Missed more than 5% of flashes           
00312           if(s.mean<150.)          s.bad = 1; // mean is < 2.5 pe
00313           if(s.mean>9000.)         s.bad = 2; // Mean is > 150pe
00314         } else {
00315           // ND:
00316           s.bad = 0; // good by default
00317           
00318           //if((s.n/s.nflash)<0.950) s.bad = 1; // Missed more than 5% of flashes           
00319           if(s.mean<250.)           s.bad = 1; // mean is < 2.5 pe
00320           if(s.mean>15000.)         s.bad = 2; // Mean is > 150pe
00321           if(s.gain>400.)           s.bad = 3;
00322         }       
00323         
00324 
00325       }
00326     }
00327   }
00328   MSG("PmtDrift",Msg::kInfo) << "Found " << fSpots.size() << " spots." << endl;
00329 }

void PhotonStatSummarizer::SummarizePoint ( VldContext  vldPointStart,
VldContext  vldPoint 
) [virtual]

Reimplemented from Summarizer.

Definition at line 147 of file PhotonStatSummarizer.cxx.

References VldContext::AsString(), ComputeDetectorDrift(), ComputePmtDrifts(), DoesTableExist(), FillPmtDatabase(), FillTrees(), fOverwriteDB, fPrescale, fTask, fWriteDB, fWriteDetTree, fWritePmtTree, fWriteSpotTree, Msg::kInfo, LoadDataFromDB(), and MSG.

00151 {
00152   MSG("PmtDrift",Msg::kInfo) << endl;
00153   MSG("PmtDrift",Msg::kInfo) << "Looking at drift point starting " << vldPointStart.AsString() << endl;
00154 
00155   const int kGoodVersion = 2; // If data exists with this version, don't overwrite
00156   const int kCurrentVersion = 4; // Write new data with this version.
00157 
00158   if(fPrescale) {
00159     static int iteration = 0;
00160     iteration++;
00161     if((iteration % fPrescale)!=0) {
00162       MSG("PmtDrift",Msg::kInfo) << "--Prescaling away " << vldPointStart.AsString() << endl;
00163       return; // skip.
00164     }
00165   }
00166 
00167   if(fWriteDB) {
00168     if(!fOverwriteDB) {
00169       for(int iVersion=kGoodVersion; iVersion<=kCurrentVersion; iVersion++){
00170         if(DoesTableExist(iVersion, vldPointStart, fTask)) {
00171           MSG("PmtDrift",Msg::kInfo) << "Skipping drift point at " << vldPointStart.AsString() 
00172                                      << " because version " << iVersion << " data already exists." << endl;
00173           return;
00174         }
00175       }
00176     }
00177   }
00178 
00179   // Get the Pixel data:
00180   LoadDataFromDB(vldPoint);
00181 
00182     // Build the PMT info:
00183   ComputePmtDrifts();
00184 
00185   ComputeDetectorDrift();
00186 
00187   if(fWriteDB) {
00188     // Fill the database:
00189     FillPmtDatabase(kCurrentVersion, vldPointStart, fTask);
00190   };
00191   
00192   if(fWritePmtTree||fWriteSpotTree||fWriteDetTree) 
00193     FillTrees(vldPoint);
00194   
00195 }


Member Data Documentation

Definition at line 155 of file PhotonStatSummarizer.h.

Referenced by ComputeDetectorDrift(), and FillTrees().

TTree* PhotonStatSummarizer::fDetTree [protected]

Definition at line 159 of file PhotonStatSummarizer.h.

Referenced by FillTrees(), PhotonStatSummarizer(), and ~PhotonStatSummarizer().

Definition at line 147 of file PhotonStatSummarizer.h.

Referenced by LoadDataFromDB().

TFile* PhotonStatSummarizer::fFile [protected]

Definition at line 160 of file PhotonStatSummarizer.h.

Referenced by FillTrees(), PhotonStatSummarizer(), and ~PhotonStatSummarizer().

Definition at line 137 of file PhotonStatSummarizer.h.

Referenced by ConfigModified(), and SummarizePoint().

TTree* PhotonStatSummarizer::fPmtTree [protected]

Definition at line 157 of file PhotonStatSummarizer.h.

Referenced by FillTrees(), PhotonStatSummarizer(), and ~PhotonStatSummarizer().

Definition at line 142 of file PhotonStatSummarizer.h.

Referenced by ConfigModified(), and SummarizePoint().

TTree* PhotonStatSummarizer::fSpotTree [protected]

Definition at line 158 of file PhotonStatSummarizer.h.

Referenced by FillTrees(), PhotonStatSummarizer(), and ~PhotonStatSummarizer().

Int_t PhotonStatSummarizer::fTask [protected]

Definition at line 134 of file PhotonStatSummarizer.h.

Referenced by PhotonStatSummarizer(), and SummarizePoint().

Definition at line 143 of file PhotonStatSummarizer.h.

Referenced by ConfigModified(), LoadDataFromDB(), and PhotonStatSummarizer().

Bool_t PhotonStatSummarizer::fWriteDB [protected]

Definition at line 138 of file PhotonStatSummarizer.h.

Referenced by ConfigModified(), and SummarizePoint().

Definition at line 139 of file PhotonStatSummarizer.h.

Referenced by ConfigModified(), FillTrees(), and SummarizePoint().

Definition at line 140 of file PhotonStatSummarizer.h.

Referenced by ConfigModified(), FillTrees(), and SummarizePoint().

Definition at line 141 of file PhotonStatSummarizer.h.

Referenced by ConfigModified(), FillTrees(), and SummarizePoint().


The documentation for this class was generated from the following files:

Generated on 22 Nov 2017 for loon by  doxygen 1.6.1