#include <CastorLedAnalysis.h>
Classes | |
struct | CALIBBUNCH |
Public Member Functions | |
CastorLedAnalysis (const edm::ParameterSet &ps) | |
Constructor. | |
void | LedDone () |
void | LedSampleAnalysis () |
void | LedSetup (const std::string &m_outputFileROOT) |
void | processLedEvent (const CastorDigiCollection &castor, const CastorDbService &cond) |
~CastorLedAnalysis () | |
Destructor. | |
Private Types | |
typedef std::pair< TH1F *, std::pair< std::map< int, std::vector< double > >, std::vector< TH1F * > > > | LEDBUNCH |
Private Member Functions | |
float | BinsizeCorr (float time) |
void | GetLedConst (std::map< HcalDetId, std::map< int, LEDBUNCH > > &toolT) |
void | LedCastorHists (const HcalDetId &detid, const CastorDataFrame &ledDigi, std::map< HcalDetId, std::map< int, LEDBUNCH > > &toolT, const CastorDbService &cond) |
void | LedTrendings (std::map< HcalDetId, std::map< int, LEDBUNCH > > &toolT) |
void | SetupLEDHists (int id, const HcalDetId detid, std::map< HcalDetId, std::map< int, LEDBUNCH > > &toolT) |
Private Attributes | |
std::map< HcalCalibDetId, CALIBBUNCH >::iterator | _meca |
std::map< HcalDetId, std::map < int, float > >::iterator | _meee |
std::map< HcalDetId, std::map < int, LEDBUNCH > >::iterator | _meol |
struct { | |
TH1F * ALLLEDS | |
TH1F * CHI2 | |
TH1F * LEDMEAN | |
TH1F * LEDRMS | |
std::map< HcalDetId, std::map < int, LEDBUNCH > > LEDTRENDS | |
} | castorHists |
int | evt |
int | evt_curr |
std::map< HcalDetId, std::map < int, float > > | m_AllPedVals |
const CastorQIECoder * | m_coder |
int | m_endTS |
TFile * | m_file |
int | m_fitflag |
int | m_hiSaveflag |
std::ofstream | m_logFile |
int | m_nevtsample |
std::ofstream | m_outFile |
std::string | m_outputFileROOT |
std::string | m_outputFileText |
std::string | m_outputFileX |
std::ofstream | m_outputFileXML |
const CastorPedestal * | m_ped |
const CastorQIEShape * | m_shape |
int | m_startTS |
bool | m_usecalib |
char | output [100] |
int | sample |
std::vector< bool > | state |
Definition at line 33 of file CastorLedAnalysis.h.
typedef std::pair<TH1F*,std::pair<std::map<int, std::vector<double> >,std::vector<TH1F*> > > CastorLedAnalysis::LEDBUNCH [private] |
Definition at line 66 of file CastorLedAnalysis.h.
CastorLedAnalysis::CastorLedAnalysis | ( | const edm::ParameterSet & | ps | ) |
Constructor.
Definition at line 17 of file CastorLedAnalysis.cc.
References gather_cfg::cout, edm::ParameterSet::getUntrackedParameter(), gen::k, and convertSQLitetoXML_cfg::output.
{ // init evt=0; sample=0; m_file=0; // output files for(int k=0;k<4;k++) state.push_back(true); // 4 cap-ids (do we care?) m_outputFileText = ps.getUntrackedParameter<string>("outputFileText", ""); m_outputFileX = ps.getUntrackedParameter<string>("outputFileXML",""); if ( m_outputFileText.size() != 0 ) { cout << "Castor LED results will be saved to " << m_outputFileText.c_str() << endl; m_outFile.open(m_outputFileText.c_str()); } m_outputFileROOT = ps.getUntrackedParameter<string>("outputFileHist", ""); if ( m_outputFileROOT.size() != 0 ) { cout << "Castor LED histograms will be saved to " << m_outputFileROOT.c_str() << endl; } m_nevtsample = ps.getUntrackedParameter<int>("nevtsample",9999999); if(m_nevtsample<1)m_nevtsample=9999999; m_hiSaveflag = ps.getUntrackedParameter<int>("hiSaveflag",0); if(m_hiSaveflag<0)m_hiSaveflag=0; if(m_hiSaveflag>0)m_hiSaveflag=1; m_fitflag = ps.getUntrackedParameter<int>("analysisflag",2); if(m_fitflag<0)m_fitflag=0; if(m_fitflag>4)m_fitflag=4; m_startTS = ps.getUntrackedParameter<int>("firstTS", 0); if(m_startTS<0) m_startTS=0; m_endTS = ps.getUntrackedParameter<int>("lastTS", 9); m_usecalib = ps.getUntrackedParameter<bool>("usecalib",false); m_logFile.open("CastorLedAnalysis.log"); int runNum = ps.getUntrackedParameter<int>("runNumber",999999); // histogram booking castorHists.ALLLEDS = new TH1F("Castor All LEDs","HF All Leds",10,0,9); castorHists.LEDRMS= new TH1F("Castor All LED RMS","HF All LED RMS",100,0,3); castorHists.LEDMEAN= new TH1F("Castor All LED Means","HF All LED Means",100,0,9); castorHists.CHI2= new TH1F("Castor Chi2 by ndf for Landau fit","HF Chi2/ndf Landau",200,0.,50.); //XML file header m_outputFileXML.open(m_outputFileX.c_str()); sprintf(output, "<?xml version='1.0' encoding='UTF-8'?>"); m_outputFileXML << output << endl; sprintf(output, "<ROOT>"); m_outputFileXML << output << endl << endl; sprintf(output, " <HEADER>"); m_outputFileXML << output << endl; sprintf(output, " <TYPE>"); m_outputFileXML << output << endl; sprintf(output, " <EXTENSION_TABLE_NAME>HCAL_LED_TIMING</EXTENSION_TABLE_NAME>"); m_outputFileXML << output << endl; sprintf(output, " <NAME>HCAL LED Timing</NAME>"); m_outputFileXML << output << endl; sprintf(output, " </TYPE>"); m_outputFileXML << output << endl; sprintf(output, " <RUN>"); m_outputFileXML << output << endl; sprintf(output, " <RUN_TYPE>hcal-led-timing-test</RUN_TYPE>"); m_outputFileXML << output << endl; sprintf(output, " <RUN_NUMBER>%06i</RUN_NUMBER>", runNum); m_outputFileXML << output << endl; sprintf(output, " <RUN_BEGIN_TIMESTAMP>2007-07-09 00:00:00.0</RUN_BEGIN_TIMESTAMP>"); m_outputFileXML << output << endl; sprintf(output, " <COMMENT_DESCRIPTION></COMMENT_DESCRIPTION>"); m_outputFileXML << output << endl; sprintf(output, " </RUN>"); m_outputFileXML << output << endl; sprintf(output, " </HEADER>"); m_outputFileXML << output << endl; sprintf(output, "<!-- Tags secton -->"); m_outputFileXML << output << endl; sprintf(output, " <ELEMENTS>"); m_outputFileXML << output << endl; sprintf(output, " <DATA_SET id='-1'/>"); m_outputFileXML << output << endl; sprintf(output, " <IOV id='1'>"); m_outputFileXML << output << endl; sprintf(output, " <INTERVAL_OF_VALIDITY_BEGIN>2147483647</INTERVAL_OF_VALIDITY_BEGIN>"); m_outputFileXML << output << endl; sprintf(output, " <INTERVAL_OF_VALIDITY_END>0</INTERVAL_OF_VALIDITY_END>"); m_outputFileXML << output << endl; sprintf(output, " </IOV>"); m_outputFileXML << output << endl; sprintf(output, " <TAG id='2' mode='auto'>"); m_outputFileXML << output << endl; sprintf(output, " <TAG_NAME>laser_led_%06i<TAG_NAME>", runNum); m_outputFileXML << output << endl; sprintf(output, " <DETECTOR_NAME>HCAL</DETECTOR_NAME>"); m_outputFileXML << output << endl; sprintf(output, " <COMMENT_DESCRIPTION></COMMENT_DESCRIPTION>"); m_outputFileXML << output << endl; sprintf(output, " </TAG>"); m_outputFileXML << output << endl; sprintf(output, " </ELEMENTS>"); m_outputFileXML << output << endl; sprintf(output, " <MAPS>"); m_outputFileXML << output << endl; sprintf(output, " <TAG idref ='2'>"); m_outputFileXML << output << endl; sprintf(output, " <IOV idref='1'>"); m_outputFileXML << output << endl; sprintf(output, " <DATA_SET idref='-1' />"); m_outputFileXML << output << endl; sprintf(output, " </IOV>"); m_outputFileXML << output << endl; sprintf(output, " </TAG>"); m_outputFileXML << output << endl; sprintf(output, " </MAPS>"); m_outputFileXML << output << endl; }
CastorLedAnalysis::~CastorLedAnalysis | ( | ) |
Destructor.
All done, clean up!!
Definition at line 133 of file CastorLedAnalysis.cc.
References i.
{ for(_meol=castorHists.LEDTRENDS.begin(); _meol!=castorHists.LEDTRENDS.end(); _meol++){ for(int i=0; i<15; i++) _meol->second[i].first->Delete(); } castorHists.ALLLEDS->Delete(); castorHists.LEDRMS->Delete(); castorHists.LEDMEAN->Delete(); castorHists.CHI2->Delete(); }
float CastorLedAnalysis::BinsizeCorr | ( | float | time | ) | [private] |
Definition at line 622 of file CastorLedAnalysis.cc.
References i.
{ // this is the bin size correction to be applied for laser data (from Andy), // it comes from a pulse shape measured from TB04 data (from Jordan) // This should eventually be replaced with the more thorough treatment from Phil float corrtime=0.; static const float tstrue[32]={0.003, 0.03425, 0.06548, 0.09675, 0.128, 0.15925, 0.1905, 0.22175, 0.253, 0.28425, 0.3155, 0.34675, 0.378, 0.40925, 0.4405, 0.47175, 0.503, 0.53425, 0.5655, 0.59675, 0.628, 0.65925, 0.6905, 0.72175, 0.753, 0.78425, 0.8155, 0.84675, 0.878, 0.90925, 0.9405, 0.97175}; static const float tsreco[32]={-0.00422, 0.01815, 0.04409, 0.07346, 0.09799, 0.12192, 0.15072, 0.18158, 0.21397, 0.24865, 0.28448, 0.31973, 0.35449, 0.39208, 0.43282, 0.47244, 0.5105, 0.55008, 0.58827, 0.62828, 0.6717, 0.70966, 0.74086, 0.77496, 0.80843, 0.83472, 0.86044, 0.8843, 0.90674, 0.92982, 0.95072, 0.9726}; int inttime=(int)time; float restime=time-inttime; for(int i=0; i<=32; i++) { float lolim=0.; float uplim=1.; float tsdown; float tsup; if(i>0){ lolim=tsreco[i-1]; tsdown=tstrue[i-1]; } else tsdown=tstrue[31]-1.; if(i<32){ uplim=tsreco[i]; tsup=tstrue[i]; } else tsup=tstrue[0]+1.; if(restime>=lolim && restime<uplim){ corrtime=(tsdown*(uplim-restime)+tsup*(restime-lolim)) / (uplim-lolim); } } corrtime+=inttime; return corrtime; }
void CastorLedAnalysis::GetLedConst | ( | std::map< HcalDetId, std::map< int, LEDBUNCH > > & | toolT | ) | [private] |
void CastorLedAnalysis::LedCastorHists | ( | const HcalDetId & | detid, |
const CastorDataFrame & | ledDigi, | ||
std::map< HcalDetId, std::map< int, LEDBUNCH > > & | toolT, | ||
const CastorDbService & | cond | ||
) | [private] |
Definition at line 550 of file CastorLedAnalysis.cc.
References ecalMGPA::adc(), first, CastorDbService::getCastorCoder(), CastorDbService::getCastorShape(), CastorDbService::getPedestal(), i, gen::k, and CastorDataFrame::size().
{ map<int,LEDBUNCH> _mei; _meol = toolT.find(detid); _mei = _meol->second; // Rest the histos if we're at the end of a 'bunch' if((evt-1)%m_nevtsample==0 && state[0]){ for(int k=0; k<(int)state.size();k++) state[k]=false; for(int i=0; i<16; i++) _mei[i].first->Reset(); } // now we have the signal in fC, let's get rid of that darn pedestal // Most of this is borrowed from CastorSimpleReconstructor, so thanks Jeremy/Phil float max_fC = 0; float ta = 0; m_coder = cond.getCastorCoder(detid); m_ped = cond.getPedestal(detid); m_shape = cond.getCastorShape(); //cout << "New Digi!!!!!!!!!!!!!!!!!!!!!!" << endl; for (int TS = m_startTS; TS < m_endTS && TS < ledDigi.size(); TS++){ int capid = ledDigi[TS].capid(); // BE CAREFUL: this is assuming peds are stored in ADCs int adc = (int)(ledDigi[TS].adc() - m_ped->getValue(capid)); if (adc < 0){ adc = 0; } // to prevent negative adcs after ped subtraction, which should really only happen // if you're using the wrong peds. double fC = m_coder->charge(*m_shape,adc,capid); //ta = (fC - m_ped->getValue(capid)); ta = fC; //cout << "DetID: " << detid << " CapID: " << capid << " ADC: " << adc << " Ped: " << m_ped->getValue(capid) << " fC: " << fC << endl; _mei[TS].first->Fill(ta); _mei[10].first->AddBinContent(TS+1,ta); // This is average pulse, could probably do better (Profile?) if(m_fitflag>1){ if(TS==m_startTS)_mei[11].first->Reset(); _mei[11].first->SetBinContent(TS+1,ta); } // keep track of max TS and max amplitude (in fC) if (ta > max_fC){ max_fC = ta; } } // Now we have a sample with pedestals subtracted and in units of fC // If we are using a weighted mean (m_fitflag = 2) to extraxt timing // we now want to use Phil's timing correction. This is not necessary // if we are performing a Landau fit (m_fitflag = 3) float sum=0.; for(int i=0; i<10; i++)sum=sum+_mei[11].first->GetBinContent(i+1); if(sum>100){ if(m_fitflag==2 || m_fitflag==4){ float timmean=_mei[11].first->GetMean(); // let's use Phil's way instead float timmeancorr=BinsizeCorr(timmean); _mei[12].first->Fill(timmeancorr); } _mei[16].first->Fill(_mei[11].first->Integral()); // Integrated charge (may be more usfull to convert to Energy first?) if(m_fitflag==3 || m_fitflag==4){ _mei[11].first->Fit("landau","Q"); TF1 *fit = _mei[11].first->GetFunction("landau"); _mei[13].first->Fill(fit->GetParameter(1)); _mei[14].first->Fill(fit->GetParError(1)); _mei[15].first->Fill(fit->GetChisquare()/fit->GetNDF()); } } }
void CastorLedAnalysis::LedDone | ( | ) |
Definition at line 460 of file CastorLedAnalysis.cc.
References gather_cfg::cout.
{ // First process the last sample (remaining events). if(evt%m_nevtsample!=0) LedSampleAnalysis(); // Now do the end of run analysis: trending histos if(sample>1 && m_fitflag!=4){ m_file->cd(); m_file->cd("Castor"); LedTrendings(castorHists.LEDTRENDS); } // Write other histograms. m_file->cd(); m_file->cd("Castor"); castorHists.ALLLEDS->Write(); castorHists.LEDRMS->Write(); castorHists.LEDMEAN->Write(); // Write the histo file and close it // m_file->Write(); m_file->Close(); cout << "Castor histograms written to " << m_outputFileROOT.c_str() << endl; }
void CastorLedAnalysis::LedSampleAnalysis | ( | ) |
Definition at line 414 of file CastorLedAnalysis.cc.
{ // it is called every m_nevtsample events (a sample) and the end of run char LedSampleNum[20]; sprintf(LedSampleNum,"LedSample_%d",sample); m_file->cd(); m_file->mkdir(LedSampleNum); m_file->cd(LedSampleNum); // Compute LED constants GetLedConst(castorHists.LEDTRENDS); }
void CastorLedAnalysis::LedSetup | ( | const std::string & | m_outputFileROOT | ) |
Definition at line 147 of file CastorLedAnalysis.cc.
{ // open the histogram file, create directories within m_file=new TFile(m_outputFileROOT.c_str(),"RECREATE"); m_file->mkdir("Castor"); m_file->cd(); }
void CastorLedAnalysis::LedTrendings | ( | std::map< HcalDetId, std::map< int, LEDBUNCH > > & | toolT | ) | [private] |
void CastorLedAnalysis::processLedEvent | ( | const CastorDigiCollection & | castor, |
const CastorDbService & | cond | ||
) |
Definition at line 487 of file CastorLedAnalysis.cc.
References edm::SortedCollection< T, SORT >::begin(), edm::SortedCollection< T, SORT >::end(), i, CastorDataFrame::id(), j, and edm::SortedCollection< T, SORT >::size().
{ evt++; sample = (evt-1)/m_nevtsample +1; evt_curr = evt%m_nevtsample; if(evt_curr==0)evt_curr=m_nevtsample; // HF/Castor try{ if(!castor.size()) throw (int)castor.size(); for (CastorDigiCollection::const_iterator j=castor.begin(); j!=castor.end(); j++){ const CastorDataFrame digi = (const CastorDataFrame)(*j); _meol = castorHists.LEDTRENDS.find(digi.id()); if (_meol==castorHists.LEDTRENDS.end()){ SetupLEDHists(2,digi.id(),castorHists.LEDTRENDS); } LedCastorHists(digi.id(),digi,castorHists.LEDTRENDS,cond); } } catch (int i ) { // m_logFile << "Event with " << i<<" Castor Digis passed." << std::endl; } // Call the function every m_nevtsample events if(evt%m_nevtsample==0) LedSampleAnalysis(); }
void CastorLedAnalysis::SetupLEDHists | ( | int | id, |
const HcalDetId | detid, | ||
std::map< HcalDetId, std::map< int, LEDBUNCH > > & | toolT | ||
) | [private] |
std::map<HcalCalibDetId,CALIBBUNCH>::iterator CastorLedAnalysis::_meca [private] |
Definition at line 116 of file CastorLedAnalysis.h.
std::map<HcalDetId,std::map<int,float> >::iterator CastorLedAnalysis::_meee [private] |
Definition at line 114 of file CastorLedAnalysis.h.
std::map<HcalDetId,std::map<int, LEDBUNCH > >::iterator CastorLedAnalysis::_meol [private] |
Definition at line 112 of file CastorLedAnalysis.h.
Definition at line 107 of file CastorLedAnalysis.h.
struct { ... } CastorLedAnalysis::castorHists [private] |
TH1F* CastorLedAnalysis::CHI2 |
Definition at line 110 of file CastorLedAnalysis.h.
int CastorLedAnalysis::evt [private] |
Definition at line 119 of file CastorLedAnalysis.h.
int CastorLedAnalysis::evt_curr [private] |
Definition at line 121 of file CastorLedAnalysis.h.
Definition at line 109 of file CastorLedAnalysis.h.
Definition at line 108 of file CastorLedAnalysis.h.
std::map<HcalDetId,std::map<int, LEDBUNCH > > CastorLedAnalysis::LEDTRENDS |
Definition at line 106 of file CastorLedAnalysis.h.
std::map<HcalDetId,std::map<int,float> > CastorLedAnalysis::m_AllPedVals [private] |
Definition at line 113 of file CastorLedAnalysis.h.
const CastorQIECoder* CastorLedAnalysis::m_coder [private] |
Definition at line 103 of file CastorLedAnalysis.h.
int CastorLedAnalysis::m_endTS [private] |
Definition at line 88 of file CastorLedAnalysis.h.
TFile* CastorLedAnalysis::m_file [private] |
Definition at line 72 of file CastorLedAnalysis.h.
int CastorLedAnalysis::m_fitflag [private] |
Definition at line 100 of file CastorLedAnalysis.h.
int CastorLedAnalysis::m_hiSaveflag [private] |
Definition at line 90 of file CastorLedAnalysis.h.
std::ofstream CastorLedAnalysis::m_logFile [private] |
Definition at line 83 of file CastorLedAnalysis.h.
int CastorLedAnalysis::m_nevtsample [private] |
Definition at line 89 of file CastorLedAnalysis.h.
std::ofstream CastorLedAnalysis::m_outFile [private] |
Definition at line 82 of file CastorLedAnalysis.h.
std::string CastorLedAnalysis::m_outputFileROOT [private] |
Definition at line 79 of file CastorLedAnalysis.h.
std::string CastorLedAnalysis::m_outputFileText [private] |
Definition at line 80 of file CastorLedAnalysis.h.
std::string CastorLedAnalysis::m_outputFileX [private] |
Definition at line 81 of file CastorLedAnalysis.h.
std::ofstream CastorLedAnalysis::m_outputFileXML [private] |
Definition at line 84 of file CastorLedAnalysis.h.
const CastorPedestal* CastorLedAnalysis::m_ped [private] |
Definition at line 104 of file CastorLedAnalysis.h.
const CastorQIEShape* CastorLedAnalysis::m_shape [private] |
Definition at line 102 of file CastorLedAnalysis.h.
int CastorLedAnalysis::m_startTS [private] |
Definition at line 87 of file CastorLedAnalysis.h.
bool CastorLedAnalysis::m_usecalib [private] |
Definition at line 91 of file CastorLedAnalysis.h.
char CastorLedAnalysis::output[100] [private] |
Definition at line 85 of file CastorLedAnalysis.h.
int CastorLedAnalysis::sample [private] |
Definition at line 120 of file CastorLedAnalysis.h.
std::vector<bool> CastorLedAnalysis::state [private] |
Definition at line 122 of file CastorLedAnalysis.h.