00001 #include "DQM/CastorMonitor/interface/CastorLEDMonitor.h"
00002 #include "DQMServices/Core/interface/DQMStore.h"
00003 #include "DQMServices/Core/interface/MonitorElement.h"
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 CastorLEDMonitor::CastorLEDMonitor() {
00016 doPerChannel_ = false;
00017 sigS0_=0;
00018 sigS1_=9;
00019 }
00020
00021
00022
00023
00024 CastorLEDMonitor::~CastorLEDMonitor() {}
00025
00026
00027
00028
00029
00030
00031 void CastorLEDMonitor::setup(const edm::ParameterSet& ps, DQMStore* dbe){
00032
00033 CastorBaseMonitor::setup(ps,dbe);
00034
00035 baseFolder_ = rootFolder_+"CastorLEDMonitor";
00036
00038 if ( ps.getUntrackedParameter<bool>("LEDPerChannel", false) )
00039 doPerChannel_ = true;
00040
00041 sigS0_ = ps.getUntrackedParameter<int>("FirstSignalBin", 0);
00042 sigS1_ = ps.getUntrackedParameter<int>("LastSignalBin", 9);
00043 adcThresh_ = ps.getUntrackedParameter<double>("LED_ADC_Thresh", 0);
00044 std::cout << "LED Monitor threshold set to " << adcThresh_ << std::endl;
00045 std::cout << "LED Monitor signal window set to " << sigS0_ <<"-"<< sigS1_ << std::endl;
00046
00047 if(sigS0_<0){
00048 std::cout << "CastorLEDMonitor::setup, illegal range for first sample: " << sigS0_ << std::endl;
00049 sigS0_=0;
00050 }
00051 if(sigS1_>9){
00052 std::cout << "CastorLEDMonitor::setup, illegal range for last sample: " << sigS1_ << std::endl;
00053 sigS1_=9;
00054 }
00055
00056 if(sigS0_ > sigS1_){
00057 std::cout<< "CastorLEDMonitor::setup, illegal range for first: "<< sigS0_ << " and last sample: " << sigS1_ << std::endl;
00058 sigS0_=0; sigS1_=9;
00059 }
00060
00061 ievt_=0;
00062
00063 if ( m_dbe ) {
00064
00065 m_dbe->setCurrentFolder(baseFolder_);
00066 meEVT_ = m_dbe->bookInt("LED Task Event Number");
00067 meEVT_->Fill(ievt_);
00068
00069 castHists.shapePED = m_dbe->book1D("Castor Ped Subtracted Pulse Shape","Castor Ped Subtracted Pulse Shape",10,-0.5,9.5);
00070 castHists.shapeALL = m_dbe->book1D("Castor Average Pulse Shape","Castor Average Pulse Shape",10,-0.5,9.5);
00071 castHists.energyALL = m_dbe->book1D("Castor Average Pulse Energy","Castor Average Pulse Energy",500,0,500);
00072 castHists.timeALL = m_dbe->book1D("Castor Average Pulse Time","Castor Average Pulse Time",200,-1,10);
00073 castHists.rms_shape = m_dbe->book1D("Castor LED Shape RMS Values","Castor LED Shape RMS Values",100,0,5);
00074 castHists.mean_shape = m_dbe->book1D("Castor LED Shape Mean Values","Castor LED Shape Mean Values",100,-0.5,9.5);
00075 castHists.rms_time = m_dbe->book1D("Castor LED Time RMS Values","Castor LED Time RMS Values",100,0,5);
00076 castHists.mean_time = m_dbe->book1D("Castor LED Time Mean Values","Castor LED Time Mean Values",100,-1,10);
00077 castHists.rms_energy = m_dbe->book1D("Castor LED Energy RMS Values","Castor LED Energy RMS Values",100,0,500);
00078 castHists.mean_energy = m_dbe->book1D("Castor LED Energy Mean Values","Castor LED Energy Mean Values",100,0,1000);
00079
00080 }
00081
00082 return;
00083 }
00084
00085
00086
00087
00088
00089
00090 void CastorLEDMonitor::createFEDmap(unsigned int fed){
00091 fedIter = MEAN_MAP_SHAPE_DCC.find(fed);
00092
00093 if(fedIter==MEAN_MAP_SHAPE_DCC.end()){
00094 m_dbe->setCurrentFolder(baseFolder_);
00095 char name[256];
00096
00097 sprintf(name,"DCC %d Mean Shape Map",fed);
00098 MonitorElement* mean_shape = m_dbe->book2D(name,name,24,0.5,24.5,15,0.5,15.5);
00099 sprintf(name,"DCC %d RMS Shape Map",fed);
00100 MonitorElement* rms_shape = m_dbe->book2D(name,name,24,0.5,24.5,15,0.5,15.5);
00101
00102 MEAN_MAP_SHAPE_DCC[fed] = mean_shape;
00103 RMS_MAP_SHAPE_DCC[fed] = rms_shape;
00104
00105 sprintf(name,"DCC %d Mean Time Map",fed);
00106 MonitorElement* mean_time = m_dbe->book2D(name,name,24,0.5,24.5,15,0.5,15.5);
00107 sprintf(name,"DCC %d RMS Time Map",fed);
00108 MonitorElement* rms_time = m_dbe->book2D(name,name,24,0.5,24.5,15,0.5,15.5);
00109 MEAN_MAP_TIME_DCC[fed] = mean_time;
00110 RMS_MAP_TIME_DCC[fed] = rms_time;
00111
00112 sprintf(name,"DCC %d Mean Energy Map",fed);
00113 MonitorElement* mean_energy = m_dbe->book2D(name,name,24,0.5,24.5,15,0.5,15.5);
00114 sprintf(name,"DCC %d RMS Energy Map",fed);
00115 MonitorElement* rms_energy = m_dbe->book2D(name,name,24,0.5,24.5,15,0.5,15.5);
00116 MEAN_MAP_ENERGY_DCC[fed] = mean_energy;
00117 RMS_MAP_ENERGY_DCC[fed] = rms_energy;
00118 }
00119 }
00120
00121
00122
00123
00124
00125
00126 void CastorLEDMonitor::reset(){
00127
00128 MonitorElement* unpackedFEDS = m_dbe->get("Castor/FEDs Unpacked");
00129 if(unpackedFEDS){
00130 for(int b=1; b<=unpackedFEDS->getNbinsX(); b++){
00131 if(unpackedFEDS->getBinContent(b)>0){
00132 createFEDmap(700+(b-1));
00133 }
00134 }
00135 }
00136 }
00137
00138
00139
00140
00141
00142
00143 void CastorLEDMonitor::processEvent( const CastorDigiCollection& castorDigis, const CastorDbService& cond){
00144
00145
00146 meEVT_->Fill(ievt_);
00147
00148
00149 if(!m_dbe){
00150 if(fVerbosity>0) std::cout<<"CastorLEDMonitor::processEvent DQMStore not instantiated!!!"<<std::endl;
00151 return;
00152 }
00153 float vals[10];
00154
00155
00156 if(castorDigis.size()>0) {
00157
00158 for (CastorDigiCollection::const_iterator j=castorDigis.begin(); j!=castorDigis.end(); j++){
00159 const CastorDataFrame digi = (const CastorDataFrame)(*j);
00160
00164
00165 float energy=0;
00166 float ts =0; float bs=0;
00167 int maxi=0; float maxa=0;
00168 for(int i=sigS0_; i<=sigS1_; i++){
00169 if(digi.sample(i).adc()>maxa){maxa=digi.sample(i).adc(); maxi=i;}
00170 }
00171 for(int i=sigS0_; i<=sigS1_; i++){
00172 float tmp1 =0;
00173 int j1=digi.sample(i).adc();
00174 tmp1 = (LedMonAdc2fc[j1]+0.5);
00175 energy += tmp1-calibs_.pedestal(digi.sample(i).capid());
00176 if(i>=(maxi-1) && i<=maxi+1){
00177 ts += i*(tmp1-calibs_.pedestal(digi.sample(i).capid()));
00178 bs += tmp1-calibs_.pedestal(digi.sample(i).capid());
00179 }
00180 }
00181 if(energy<adcThresh_) continue;
00182
00183 castHists.energyALL->Fill(energy);
00184 if(bs!=0) castHists.timeALL->Fill(ts/bs);
00185
00186
00187 for (int i=0; i<digi.size(); i++) {
00188 float tmp =0;
00189 int j=digi.sample(i).adc();
00190 tmp = (LedMonAdc2fc[j]+0.5);
00191 castHists.shapeALL->Fill(i,tmp);
00192 castHists.shapePED->Fill(i,tmp-calibs_.pedestal(digi.sample(i).capid()));
00193 vals[i] = tmp-calibs_.pedestal(digi.sample(i).capid());
00194 }
00195
00196
00197 if( doPerChannel_) perChanHists(digi.id(),vals,castHists.shape, castHists.time, castHists.energy, baseFolder_);
00198 }
00199 } else {
00200 if(fVerbosity > 0) std::cout << "CastorPSMonitor::processEvent NO Castor Digis !!!" << std::endl;
00201 }
00202
00203
00204 ievt_++;
00205
00206 return;
00207 }
00208
00209
00210
00211
00212
00213
00214 void CastorLEDMonitor::done(){
00216 return;
00217 }
00218
00219
00220
00221
00222
00223 void CastorLEDMonitor::perChanHists(const HcalCastorDetId DetID, float* vals,
00224 std::map<HcalCastorDetId, MonitorElement*> &tShape,
00225 std::map<HcalCastorDetId, MonitorElement*> &tTime,
00226 std::map<HcalCastorDetId, MonitorElement*> &tEnergy,
00227 std::string baseFolder){
00228
00229 std::string type = "CastorLEDPerChannel";
00230 if(m_dbe) m_dbe->setCurrentFolder(baseFolder+"/"+type);
00231
00232 MonitorElement* me;
00233 if(m_dbe==NULL) return;
00234 meIter=tShape.begin();
00235 meIter = tShape.find(DetID);
00236
00237 if (meIter!=tShape.end()){
00238 me= meIter->second;
00239 if(me==NULL && fVerbosity>0) printf("CastorLEDAnalysis::perChanHists This histo is NULL!!??\n");
00240 else{
00241 float energy=0;
00242 float ts =0; float bs=0;
00243 int maxi=0; float maxa=0;
00244 for(int i=sigS0_; i<=sigS1_; i++){
00245 if(vals[i]>maxa){maxa=vals[i]; maxi=i;}
00246 }
00247 for(int i=sigS0_; i<=sigS1_; i++){
00248 energy += vals[i];
00249 if(i>=(maxi-1) && i<=maxi+1){
00250 ts += i*vals[i];
00251 bs += vals[i];
00252 }
00253 me->Fill(i,vals[i]);
00254 }
00255 me = tTime[DetID];
00256 if(bs!=0) me->Fill(ts/bs);
00257 me = tEnergy[DetID];
00258 me->Fill(energy);
00259 }
00260 }
00261 else{
00262 char name[1024];
00263 sprintf(name,"Castor LED Shape zside=%d module=%d sector=%d",DetID.zside(),DetID.module(),DetID.sector());
00264 MonitorElement* insert1;
00265 insert1 = m_dbe->book1D(name,name,10,-0.5,9.5);
00266 float energy=0;
00267 float ts =0; float bs=0;
00268 int maxi=0; float maxa=0;
00269 for(int i=sigS0_; i<=sigS1_; i++){
00270 if(vals[i]>maxa){maxa=vals[i]; maxi=i;}
00271 insert1->Fill(i,vals[i]);
00272 }
00273 for(int i=sigS0_; i<=sigS1_; i++){
00274 energy += vals[i];
00275 if(i>=(maxi-1) && i<=maxi+1){
00276 ts += i*vals[i];
00277 bs += vals[i];
00278 }
00279 }
00280 tShape[DetID] = insert1;
00281
00282 sprintf(name,"Castor LED Time zside=%d module=%d sector=%d",DetID.zside(),DetID.module(),DetID.sector());
00283 MonitorElement* insert2 = m_dbe->book1D(name,name,100,0,10);
00284 if(bs!=0) insert2->Fill(ts/bs);
00285 tTime[DetID] = insert2;
00286
00287
00288 sprintf(name,"Castor LED Energy zside=%d module=%d sector=%d",DetID.zside(),DetID.module(),DetID.sector());
00289 MonitorElement* insert3 = m_dbe->book1D(name,name,500,0,500);
00290 insert3->Fill(energy);
00291 tEnergy[DetID] = insert3;
00292
00293 }
00294
00295 return;
00296
00297 }