Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

CheckGC Class Reference

#include <CheckGC.h>

List of all members.

Public Member Functions

 CheckGC ()
 ~CheckGC ()
void SettsStart (UInt_t year, UInt_t month, UInt_t day, UInt_t hour, UInt_t min, UInt_t sec, UInt_t nsec=0, Bool_t isUTC=true, Int_t secOffset=0)
void SettsEnd (UInt_t year, UInt_t month, UInt_t day, UInt_t hour, UInt_t min, UInt_t sec, UInt_t nsec=0, Bool_t isUTC=true, Int_t secOffset=0)
void SetDetType (Int_t dettype)
void checklin ()
void ZeroCorr ()

Private Attributes

VldTimeStamp tsStart
VldTimeStamp tsEnd
Detector::Detector_t fDetector
GCSummarygc


Constructor & Destructor Documentation

CheckGC::CheckGC  ) 
 

Definition at line 41 of file CheckGC.cxx.

00042 {
00043   gc = new GCSummary();
00044 }

CheckGC::~CheckGC  ) 
 

Definition at line 48 of file CheckGC.cxx.

00049 {
00050 }


Member Function Documentation

void CheckGC::checklin  ) 
 

Definition at line 100 of file CheckGC.cxx.

References GCSummary::aggno, GCSummary::dettype, digit(), GCSummary::errorPin, GCSummary::errorPmt, fDetector, FillArray(), GCSummary::fnhlcode, gc, PulserGain::GetAggregateNo(), PulserGainPin::GetAggregateNo(), VldTimeStamp::GetDate(), PulserGain::GetError(), PlexPinDiodeId::GetGain(), PlexLedId::GetLedInBox(), PulserGain::GetMean(), PulserGain::GetNumEntries(), PulserGain::GetNumPoints(), DbiResultPtr< T >::GetNumRows(), PulserGain::GetNumTriggers(), PulserGainPin::GetPinDiodeId(), PlexPlaneId::GetPlane(), PlexLedId::GetPulserBox(), DbiResultPtr< T >::GetRow(), DbiValidityRec::GetSeqNo(), PlexStripEndId::GetStrip(), PulserGain::GetStripEnd(), DbiValidityRec::GetTask(), VldRange::GetTimeEnd(), VldRange::GetTimeStart(), DbiResultPtr< T >::GetValidityRec(), DbiValidityRec::GetVldRange(), GCSummary::highlow, GCSummary::led, GCSummary::meanPinraw, GCSummary::meanPmtraw, GCSummary::nearfar, GCSummary::numEntriesPin, GCSummary::numEntriesPmt, GCSummary::numPointsPin, GCSummary::numPointsPmt, GCSummary::numTrigsPin, GCSummary::numTrigsPmt, GCSummary::pb, GCSummary::plane, GCSummary::Reset(), GCSummary::strip, GCSummary::stripend, GCSummary::timeEnd, GCSummary::timeStart, tsEnd, tsStart, PlexStripEndId::UnbuildPlnStripEndKey(), and ZeroCorr().

00101 {
00102 
00103   //create the new TFile for holding the GC tree
00104   char filename[100];
00105 
00106   cout<<"tsStart: "<<tsStart<<endl;
00107   cout<<"tsEnd:   "<<tsEnd<<endl;
00108 
00109   UInt_t year1,month1,day1;
00110   UInt_t year2,month2,day2;
00111   tsStart.GetDate(true,0,&year1,&month1,&day1);
00112   tsEnd.GetDate(true,0,&year2,&month2,&day2);
00113 
00114   if (fDetector == Detector::kNear){
00115     cout<<"Checking near detector gain curves"<<endl;
00116     sprintf(filename,"ngc%s%s%s.root",digit(year1%100),digit(month1),digit(day1));
00117   }
00118   else if (fDetector == Detector::kFar){
00119     cout<<"Checking far detector gain curves"<<endl;
00120     sprintf(filename,"fgc%s%s%s.root",digit(year1%100),digit(month1),digit(day1));
00121   }
00122 
00123   TFile *fNtpFile = new  TFile(filename,"RECREATE");
00124   fNtpFile->cd();
00125   cout<<"File opened "<<filename<<endl;
00126   TTree *fNtuple = new TTree("gc_tree","GC Analysis Tree");
00127   fNtuple->Branch("","GCSummary",&gc,64000,1);
00128 
00129   //Set validity context
00130   VldContext vldc(fDetector,SimFlag::kData,tsStart);
00131   PlexHandle plex(vldc);
00132 
00133   DbiSqlContext extContext(DbiSqlContext::kStarts,tsStart,tsEnd,fDetector,SimFlag::kData);
00134 
00135   string extClause = "stripend=124017 || stripend=124016";
00136 
00137   // perform the query
00138   DbiResultPtr<PulserGainPin> rsPin("PULSERGAINPIN",extContext,Dbi::kAnyTask); 
00139   DbiResultPtr<PulserGain> rsStripEnd("PULSERGAIN",extContext,Dbi::kAnyTask);
00140   //DbiResultPtr<PulserGain> rsStripEnd("PULSERGAIN",extContext,Dbi::kAnyTask,extClause.c_str()); 
00141   
00142   const int numPin = rsPin.GetNumRows();
00143   const int numStripEnd = rsStripEnd.GetNumRows();
00144   
00145   cout << "got " << numPin << " PINs" << endl;
00146   cout << "got " << numStripEnd << " StripEnds"<<endl;
00147   map<int,PulserGainPin*> hgpinmap;
00148   map<int,PulserGainPin*> lgpinmap;
00149   map<int,VldTimeStamp> pintimeStart; //Currently PulserGain and PulserGainPin share the same timestamp for entries with the same aggregateno. We'll record timestamps to synchronize CALPULSERFITS with PulserGain and PulserGainPin.
00150   map<int,VldTimeStamp> pintimeEnd;
00151 
00152   //  HistMan *hm = new HistMan("allres");
00153 
00154   for (int ir=0; ir<numPin; ir++) {
00155     
00156     //Pointer to row
00157     const PulserGainPin* rs = rsPin.GetRow(ir);
00158     
00159     int pingain = rs->GetPinDiodeId().GetGain();
00160     int aggregateno = rs->GetAggregateNo();
00161     PlexLedId led(aggregateno);
00162 
00163     // Get the DbiValidityRec for the specfic row and hence its start and end time.
00164     // Unfortunately, because of overlaps, it may not be exactly what you
00165     // want.  The DBI is interested in effective validities i.e. for what
00166     // period of time an entry is the highest priority.  Normally a new
00167     // calibration will be made before the old one has expired and the two
00168     // will overlap with the later entry taking priority.  So in the normal
00169     // situation, timeStart as derived above will be O.K., but the timeEnd
00170     // is likely to be too early.  --Nick West
00171     // The following code was suggested by Nick
00172     const DbiValidityRec* vrec  = rsPin.GetValidityRec(rs);
00173     UInt_t seqno                = vrec->GetSeqNo();
00174     DbiResultPtr<PulserGainPin> rsPin2("PULSERGAINPIN",seqno,0);  //0 = cascade entry
00175     const DbiValidityRec* vrec2 = rsPin2.GetValidityRec();
00176     const VldRange& vrng        = vrec2->GetVldRange();
00177     VldTimeStamp timeStart      = vrng.GetTimeStart();
00178     VldTimeStamp timeEnd        = vrng.GetTimeEnd();
00179     //insert timeStart and timeEnd
00180     pintimeStart.insert(pair<int,VldTimeStamp>(aggregateno,timeStart));
00181     pintimeEnd.insert(pair<int,VldTimeStamp>(aggregateno,timeEnd));
00182 
00183     //If low gain (gain = 1) save first
00184     if (pingain == 1) {
00185       lgpinmap.insert(pair<int,PulserGainPin*>(aggregateno,const_cast<PulserGainPin*>(rs) ));
00186     }
00187     //If high gain (gain = 0)
00188     if (fDetector==Detector::kNear && led.GetPulserBox()==0) continue;//no high gain pin diode chennles in the near detector
00189     //if (fDetector==1 && led.GetPulserBox()==0) continue;//no high gain pin diode chennles in the near detector
00190     if (pingain == 0) { 
00191       hgpinmap.insert(pair<int,PulserGainPin*>(aggregateno,const_cast<PulserGainPin*>(rs) ));
00192     }
00193   }
00194 
00195   cout<<"Finish reading PULSERGAINPIN"<<endl;
00196 
00197   int counter = 0;
00198   int countled = 0;
00199   int aggregateno_old = -1;
00200 
00201   gc->dettype = int(fDetector);
00202 
00203   for (int ir=0; ir<numStripEnd; ir++) {
00204     if (ir%1000==0) cout<<ir<<"/"<<numStripEnd<<endl;
00205     
00206     gc->Reset();
00207     
00208     //Pointer to row
00209     const PulserGain* rs = rsStripEnd.GetRow(ir);
00210     int aggregateno = rs->GetAggregateNo();
00211     int stripendid = rs->GetStripEnd();
00212     PlexLedId ledid0(aggregateno);
00213     PlexLedId ledid(fDetector,ledid0.GetPulserBox(),ledid0.GetLedInBox());
00214     gc->aggno = aggregateno;
00215     gc->led = ledid.GetLedInBox();
00216     gc->pb = ledid.GetPulserBox();
00217     gc->stripend = stripendid;
00218     (pintimeStart.find(aggregateno)->second).Copy(gc->timeStart);
00219     (pintimeEnd.find(aggregateno)->second).Copy(gc->timeEnd);
00220     // Get mean and entries to calculate residual
00221     int numpoints = rs->GetNumPoints();
00222     
00223     gc->numPointsPmt = rs->GetNumPoints();
00224     //if (ledid.GetPulserBox()!=0) continue;
00225     
00226     if (numpoints<20) {
00227       cout << "Less than 20 points in GC! Number of entries: " << numpoints << endl;
00228     }
00229 
00230     FillArray(gc->meanPmtraw,rs->GetMean(),gc->numPointsPmt);
00231     FillArray(gc->errorPmt,rs->GetError(),gc->numPointsPmt);
00232     FillArray(gc->numEntriesPmt,rs->GetNumEntries(),gc->numPointsPmt);
00233     FillArray(gc->numTrigsPmt,rs->GetNumTriggers(),gc->numPointsPmt);
00234     
00235     if ( aggregateno_old != aggregateno) {
00236       
00237       aggregateno_old = aggregateno;
00238       counter = 0;
00239       countled++;
00240     } else {
00241       //if (counter>5) continue;
00242       
00243     }
00244     
00245     PlexStripEndId seid = PlexStripEndId::UnbuildPlnStripEndKey(fDetector,stripendid);
00246     int planeno = seid.GetPlane();
00247     int stripno = seid.GetStrip();
00248     
00249     gc->plane = planeno;
00250     gc->strip = stripno;
00251 
00252 
00253     // Get validity of row
00254     const DbiValidityRec* dbival =  rsStripEnd.GetValidityRec(rs);
00255     
00256     // near end: task = 1
00257     // far end: task = 2
00258     int task = dbival->GetTask();
00259     if (task==1) {
00260       gc->nearfar = 0;
00261       if (lgpinmap.find(aggregateno)!=lgpinmap.end()){//low gain
00262         gc->highlow = 1;
00263         gc->fnhlcode = gc->nearfar*2 + gc->highlow;
00264         gc->numPointsPin = (lgpinmap.find(aggregateno)->second)->GetNumPoints();
00265         FillArray(gc->meanPinraw,(lgpinmap.find(aggregateno)->second)->GetMean(),gc->numPointsPin);
00266         FillArray(gc->errorPin,(lgpinmap.find(aggregateno)->second)->GetError(),gc->numPointsPin);
00267         FillArray(gc->numEntriesPin,(lgpinmap.find(aggregateno)->second)->GetNumEntries(),gc->numPointsPin);
00268         FillArray(gc->numTrigsPin,(lgpinmap.find(aggregateno)->second)->GetNumTriggers(),gc->numPointsPin);
00269         this->ZeroCorr();
00270         fNtuple->Fill();
00271       }
00272       if (hgpinmap.find(aggregateno)!=hgpinmap.end()){//high gain
00273         gc->highlow = 0;
00274         gc->fnhlcode = gc->nearfar*2 + gc->highlow;
00275         gc->numPointsPin = (hgpinmap.find(aggregateno)->second)->GetNumPoints();
00276         FillArray(gc->meanPinraw,(hgpinmap.find(aggregateno)->second)->GetMean(),gc->numPointsPin);
00277         FillArray(gc->errorPin,(hgpinmap.find(aggregateno)->second)->GetError(),gc->numPointsPin);
00278         FillArray(gc->numEntriesPin,(hgpinmap.find(aggregateno)->second)->GetNumEntries(),gc->numPointsPin);
00279         FillArray(gc->numTrigsPin,(hgpinmap.find(aggregateno)->second)->GetNumTriggers(),gc->numPointsPin);
00280         this->ZeroCorr();
00281         fNtuple->Fill();
00282       }
00283     }
00284 
00285     else if (task==2) {
00286       gc->nearfar = 1;
00287       if (lgpinmap.find(aggregateno)!=lgpinmap.end()){//low gain
00288         gc->highlow = 1;
00289         gc->fnhlcode = gc->nearfar*2 + gc->highlow;
00290         gc->numPointsPin = (lgpinmap.find(aggregateno)->second)->GetNumPoints();
00291         FillArray(gc->meanPinraw,(lgpinmap.find(aggregateno)->second)->GetMean(),gc->numPointsPin);
00292         FillArray(gc->errorPin,(lgpinmap.find(aggregateno)->second)->GetError(),gc->numPointsPin);
00293         FillArray(gc->numEntriesPin,(lgpinmap.find(aggregateno)->second)->GetNumEntries(),gc->numPointsPin);
00294         FillArray(gc->numTrigsPin,(lgpinmap.find(aggregateno)->second)->GetNumTriggers(),gc->numPointsPin);
00295         this->ZeroCorr();
00296         fNtuple->Fill();
00297       }
00298       if (hgpinmap.find(aggregateno)!=hgpinmap.end()){//high gain
00299         gc->highlow = 0;
00300         gc->fnhlcode = gc->nearfar*2 + gc->highlow;
00301         gc->numPointsPin = (hgpinmap.find(aggregateno)->second)->GetNumPoints();
00302         FillArray(gc->meanPinraw,(hgpinmap.find(aggregateno)->second)->GetMean(),gc->numPointsPin);
00303         FillArray(gc->errorPin,(hgpinmap.find(aggregateno)->second)->GetError(),gc->numPointsPin);
00304         FillArray(gc->numEntriesPin,(hgpinmap.find(aggregateno)->second)->GetNumEntries(),gc->numPointsPin);
00305         FillArray(gc->numTrigsPin,(hgpinmap.find(aggregateno)->second)->GetNumTriggers(),gc->numPointsPin);
00306         this->ZeroCorr();
00307         fNtuple->Fill();
00308       }
00309     }
00310   }
00311   
00312   fNtpFile->Write();
00313   fNtpFile->Close();
00314 }

void CheckGC::SetDetType Int_t  dettype  ) 
 

Definition at line 92 of file CheckGC.cxx.

References fDetector.

00093 {
00094   if (dettype==1) fDetector = Detector::kNear;
00095   else if (dettype==2) fDetector = Detector::kFar;
00096   else fDetector = Detector::kUnknown;
00097   //fDetector = dettype;
00098 }

void CheckGC::SettsEnd UInt_t  year,
UInt_t  month,
UInt_t  day,
UInt_t  hour,
UInt_t  min,
UInt_t  sec,
UInt_t  nsec = 0,
Bool_t  isUTC = true,
Int_t  secOffset = 0
 

Definition at line 82 of file CheckGC.cxx.

References VldTimeStamp::Copy(), min, month, and tsEnd.

00087 {
00088   VldTimeStamp ts(year, month, day, hour, min, sec, nsec, isUTC, secOffset);
00089   ts.Copy(tsEnd);
00090 }

void CheckGC::SettsStart UInt_t  year,
UInt_t  month,
UInt_t  day,
UInt_t  hour,
UInt_t  min,
UInt_t  sec,
UInt_t  nsec = 0,
Bool_t  isUTC = true,
Int_t  secOffset = 0
 

Definition at line 72 of file CheckGC.cxx.

References VldTimeStamp::Copy(), min, month, and tsStart.

00077 {
00078   VldTimeStamp ts(year, month, day, hour, min, sec, nsec, isUTC, secOffset);
00079   ts.Copy(tsStart);
00080 }

void CheckGC::ZeroCorr  ) 
 

Definition at line 316 of file CheckGC.cxx.

References gc, GCSummary::meanPin, GCSummary::meanPinraw, GCSummary::meanPmt, GCSummary::meanPmtraw, GCSummary::numEntriesPin, GCSummary::numEntriesPmt, GCSummary::numPointsPin, GCSummary::numPointsPmt, GCSummary::numTrigsPin, and GCSummary::numTrigsPmt.

Referenced by checklin().

00317 {
00318   for (int i = 0; i<gc->numPointsPin; i++){
00319     if (gc->numTrigsPin[i]) 
00320       gc->meanPin[i] = gc->meanPinraw[i]*gc->numEntriesPin[i]/gc->numTrigsPin[i];
00321     else gc->meanPin[i] = gc->meanPinraw[i];
00322   }
00323 
00324   for (int i = 0; i<gc->numPointsPmt; i++){
00325     if (gc->numTrigsPmt[i])
00326       gc->meanPmt[i] = gc->meanPmtraw[i]*gc->numEntriesPmt[i]/gc->numTrigsPmt[i];
00327     else gc->meanPmt[i] = gc->meanPmtraw[i];
00328   }
00329 }


Member Data Documentation

Detector::Detector_t CheckGC::fDetector [private]
 

Definition at line 50 of file CheckGC.h.

Referenced by checklin(), and SetDetType().

GCSummary* CheckGC::gc [private]
 

Definition at line 53 of file CheckGC.h.

Referenced by checklin(), and ZeroCorr().

VldTimeStamp CheckGC::tsEnd [private]
 

Definition at line 49 of file CheckGC.h.

Referenced by checklin(), and SettsEnd().

VldTimeStamp CheckGC::tsStart [private]
 

Definition at line 48 of file CheckGC.h.

Referenced by checklin(), and SettsStart().


The documentation for this class was generated from the following files:
Generated on Mon Feb 15 11:08:59 2010 for loon by  doxygen 1.3.9.1