#include <OnlineDB/CSCCondDB/interface/CSCOldGainAnalyzer.h>
Public Member Functions | |
virtual void | analyze (edm::Event const &e, edm::EventSetup const &iSetup) |
CSCOldGainAnalyzer (edm::ParameterSet const &conf) | |
Analyzer for reading CSC pedestals. | |
~CSCOldGainAnalyzer () | |
Private Attributes | |
TH2F | adcCharge |
float | adcMax [DDU_oldga][CHAMBERS_oldga][LAYERS_oldga][STRIPS_oldga] |
float | adcMean_max [DDU_oldga][CHAMBERS_oldga][LAYERS_oldga][STRIPS_oldga] |
std::string | chamber_id |
int | chamber_index |
int | chamber_num |
int | counter |
int | crateID [CHAMBERS_oldga] |
bool | debug |
int | dmbID [CHAMBERS_oldga] |
int | eventNumber |
int | evt |
int | fff |
std::ifstream | filein |
int | first_strip_index |
int | flagGain |
int | flagIntercept |
float | gainIntercept |
float | gainSlope |
int | i_chamber |
int | i_layer |
int | length |
int | lines |
float | maxmodten [NUMMODTEN_oldga][CHAMBERS_oldga][LAYERS_oldga][STRIPS_oldga] |
int | misMatch |
float | myCharge [10] |
int | myIndex |
std::string | name |
int | NChambers |
int | Nddu |
std::vector< int > | newadc |
float | newChi2 [480] |
float | newGain [480] |
float | newIntercept [480] |
std::string | PSet |
time_t | rawtime |
int | record |
int | reportedChambers |
int | ret_code |
int | sector |
int | size [CHAMBERS_oldga] |
int | strip |
int | strips_per_layer |
Definition at line 33 of file CSCOldGainAnalyzer.h.
CSCOldGainAnalyzer::CSCOldGainAnalyzer | ( | edm::ParameterSet const & | conf | ) | [explicit] |
Analyzer for reading CSC pedestals.
author S. Durkin, O.Boeriu 18/03/06 ripped from Jeremy's and Rick's analyzers
Definition at line 34 of file CSCOldGainAnalyzer.cc.
References adcCharge, adcMax, adcMean_max, CHAMBERS_oldga, counter, DDU_oldga, debug, eventNumber, evt, flagGain, flagIntercept, gainIntercept, gainSlope, edm::ParameterSet::getUntrackedParameter(), i, i_chamber, i_layer, j, k, edm::es::l(), LAYERS_oldga, length, maxmodten, misMatch, NChambers, Nddu, newChi2, newGain, newIntercept, NUMMODTEN_oldga, reportedChambers, size, strip, and STRIPS_oldga.
00034 { 00035 debug = conf.getUntrackedParameter<bool>("debug",false); 00036 eventNumber=0,evt=0,Nddu=0,flagGain=-9,flagIntercept=-9; 00037 strip=0,misMatch=0,NChambers=0; 00038 i_chamber=0,i_layer=0,reportedChambers=0; 00039 length=1,gainSlope=-999.0,gainIntercept=-999.0; 00040 counter=0; 00041 00042 adcCharge = TH2F("adcCharge","adcCharge", 100,0,300,100,0,2000); 00043 00044 for (int i=0; i<NUMMODTEN_oldga; i++){ 00045 for (int j=0; j<CHAMBERS_oldga; j++){ 00046 for (int k=0; k<LAYERS_oldga; k++){ 00047 for (int l=0; l<STRIPS_oldga; l++){ 00048 maxmodten[i][j][k][l] = 0.0; 00049 } 00050 } 00051 } 00052 } 00053 00054 00055 for (int i=0; i<CHAMBERS_oldga; i++){ 00056 size[i] = 0; 00057 } 00058 00059 for (int iii=0;iii<DDU_oldga;iii++){ 00060 for (int i=0; i<CHAMBERS_oldga; i++){ 00061 for (int j=0; j<LAYERS_oldga; j++){ 00062 for (int k=0; k<STRIPS_oldga; k++){ 00063 adcMax[iii][i][j][k] = -999.0; 00064 adcMean_max[iii][i][j][k] = -999.0; 00065 } 00066 } 00067 } 00068 } 00069 00070 for (int i=0; i<480; i++){ 00071 newGain[i] =0.0; 00072 newIntercept[i]=0.0; 00073 newChi2[i] =0.0; 00074 } 00075 }
CSCOldGainAnalyzer::~CSCOldGainAnalyzer | ( | ) |
Definition at line 166 of file CSCOldGainAnalyzer.cc.
References condbon::cdbon_last_record(), condbon::cdbon_write(), chamber_id, chamber_index, chamber_num, counter, GenMuonPlsPt100GeV_cfg::cout, cscmap::crate_chamber(), crateID, debug, dmbID, lat::endl(), filein, first_strip_index, flagGain, flagIntercept, gainIntercept, gainSlope, edm::isnan(), j, k, LAYERS_oldga, lines, python::multivaluedict::map(), maxmodten, myCharge, myIndex, name, NChambers, Nddu, NULL, NUMBERPLOTTED_oldga, CSCobject::obj, out, record, sector, size, STRIPS_oldga, and strips_per_layer.
00166 { 00167 //get time of Run file for DB transfer 00168 filein.open("../test/CSColdgain.cfg"); 00169 filein.ignore(1000,'\n'); 00170 00171 while(filein != NULL){ 00172 lines++; 00173 getline(filein,PSet); 00174 00175 if (lines==2){ 00176 name=PSet; 00177 std::cout<<name<<std::endl; 00178 } 00179 } 00180 std::string::size_type runNameStart = name.find("\"",0); 00181 std::string::size_type runNameEnd = name.find("raw",0); 00182 std::string::size_type rootStart = name.find("Gains",0); 00183 int nameSize = runNameEnd+2-runNameStart; 00184 int myRootSize = rootStart-runNameStart+8; 00185 std::string myname= name.substr(runNameStart+1,nameSize); 00186 std::string myRootName= name.substr(runNameStart+1,myRootSize); 00187 std::string myRootEnd = ".root"; 00188 std::string myASCIIFileEnd = ".dat"; 00189 std::string runFile= myRootName; 00190 std::string myRootFileName = runFile+myRootEnd; 00191 std::string myASCIIFileName= runFile+myASCIIFileEnd; 00192 const char *myNewName=myRootFileName.c_str(); 00193 const char *myFileName=myASCIIFileName.c_str(); 00194 00195 struct tm* clock; 00196 struct stat attrib; 00197 stat(myname.c_str(), &attrib); 00198 clock = localtime(&(attrib.st_mtime)); 00199 std::string myTime=asctime(clock); 00200 std::ofstream myGainsFile(myFileName,std::ios::out); 00201 00202 //DB object and map 00203 CSCobject *cn = new CSCobject(); 00204 cscmap *map = new cscmap(); 00205 condbon *dbon = new condbon(); 00206 00207 //root ntuple information 00208 /* 00209 TCalibOldGainEvt calib_evt; 00210 TFile calibfile(myNewName, "RECREATE"); 00211 TTree calibtree("Calibration","Gains"); 00212 calibtree.Branch("EVENT", &calib_evt, "slope/F:intercept/F:chi2/F:strip/I:layer/I:cham/I:id/I:flagGain/I:flagIntercept/I"); 00213 */ 00214 00215 for (int dduiter=0;dduiter<Nddu;dduiter++){ 00216 for(int chamberiter=0; chamberiter<NChambers; chamberiter++){ 00217 for (int cham=0;cham<NChambers;cham++){ 00218 if (cham !=chamberiter) continue; 00219 00220 //get chamber ID from DB mapping 00221 int new_crateID = crateID[cham]; 00222 int new_dmbID = dmbID[cham]; 00223 std::cout<<" Crate: "<<new_crateID<<" and DMB: "<<new_dmbID<<std::endl; 00224 map->crate_chamber(new_crateID,new_dmbID,&chamber_id,&chamber_num,§or,&first_strip_index,&strips_per_layer,&chamber_index); 00225 std::cout<<"Data is for chamber:: "<< chamber_id<<" in sector: "<<sector<<" index "<<first_strip_index<<std::endl; 00226 00227 //calib_evt.id=chamber_num; 00228 00229 for (int layeriter=0; layeriter<LAYERS_oldga; layeriter++){ 00230 for (int stripiter=0; stripiter<STRIPS_oldga; stripiter++){ 00231 00232 for (int j=0; j<LAYERS_oldga; j++){//layer 00233 if (j != layeriter) continue; 00234 00235 int layer_id=chamber_num+j+1; 00236 if(sector==-100)continue; 00237 cn->obj[layer_id].resize(size[cham]); 00238 for (int k=0; k<size[cham]; k++){//strip 00239 if (k != stripiter) continue; 00240 float sumOfX = 0.0; 00241 float sumOfY = 0.0; 00242 float sumOfXY = 0.0; 00243 float sumx2 = 0.0; 00244 float gainSlope = 0.0; 00245 float gainIntercept = 0.0; 00246 float chi2 = 0.0; 00247 00248 float charge[NUMBERPLOTTED_oldga]={22.4, 44.8, 67.2, 89.6, 112, 134.4, 156.8, 179.2, 201.6, 224.0}; 00249 00250 00251 for(int ii=0; ii<NUMBERPLOTTED_oldga; ii++){//numbers 00252 sumOfX += charge[ii]; 00253 sumOfY += maxmodten[ii][cham][j][k]; 00254 sumOfXY += (charge[ii]*maxmodten[ii][cham][j][k]); 00255 sumx2 += (charge[ii]*charge[ii]); 00256 myCharge[ii] = 22.4 +(22.4*ii); 00257 //adcCharge.Fill(myCharge[ii],maxmodten[ii][cham][j][k]); 00258 } 00259 00260 00261 //Fit parameters for straight line 00262 gainSlope = ((NUMBERPLOTTED_oldga*sumOfXY) - (sumOfX * sumOfY))/((NUMBERPLOTTED_oldga*sumx2) - (sumOfX*sumOfX));//k 00263 gainIntercept = ((sumOfY*sumx2)-(sumOfX*sumOfXY))/((NUMBERPLOTTED_oldga*sumx2)-(sumOfX*sumOfX));//m 00264 00265 //if (gainSlope <3.0) gainSlope = 0.0; 00266 if (isnan(gainSlope)) gainSlope = 0.0; 00267 00268 for(int ii=0; ii<NUMBERPLOTTED_oldga; ii++){ 00269 chi2 += (maxmodten[ii][cham][j][k]-(gainIntercept+(gainSlope*charge[ii])))*(maxmodten[ii][cham][j][k]-(gainIntercept+(gainSlope*charge[ii])))/(NUMBERPLOTTED_oldga*NUMBERPLOTTED_oldga); 00270 } 00271 00272 // std::cout <<"Chamber: "<<cham<<" Layer: "<<j<<" Strip: "<<k<<" Slope: "<<gainSlope <<" Intercept: "<<gainIntercept <<" chi2 "<<chi2<<std::endl; 00273 00274 00275 if (gainSlope>5.0 && gainSlope<10.0) flagGain=1; // ok 00276 if (gainSlope<5.0) flagGain=2; // warning fit fails 00277 if (gainSlope>10.0) flagGain=3; // warning fit fails 00278 00279 if (gainIntercept> -40. && gainIntercept<15.) flagIntercept = 1 ; 00280 if (gainIntercept< -40.) flagIntercept = 2 ; 00281 if (gainIntercept> 15.) flagIntercept = 3 ; 00282 00283 //dump values to ASCII file 00284 counter++; 00285 myIndex = first_strip_index+counter-1; 00286 if (counter>size[cham]*LAYERS_oldga) counter=0; 00287 myGainsFile <<layer_id<<" "<<" "<<myIndex-1<<" "<<k<<" "<<gainSlope<<" "<<gainIntercept<<" "<<chi2<<std::endl; 00288 00289 /* 00290 calib_evt.slope = gainSlope; 00291 calib_evt.intercept = gainIntercept; 00292 calib_evt.chi2 = chi2; 00293 calib_evt.strip = k; 00294 calib_evt.layer = j; 00295 calib_evt.cham = cham; 00296 calib_evt.flagGain = flagGain; 00297 calib_evt.flagIntercept = flagIntercept; 00298 00299 calibtree.Fill(); 00300 */ 00301 cn->obj[layer_id][k].resize(3); 00302 cn->obj[layer_id][k][0] = gainSlope; 00303 cn->obj[layer_id][k][1] = gainIntercept; 00304 cn->obj[layer_id][k][2] = chi2; 00305 }//k loop 00306 }//j loop 00307 }//stripiter loop 00308 }//layiter loop 00309 }//cham 00310 }//chamberiter 00311 }//dduiter 00312 00313 //send data to DB 00314 dbon->cdbon_last_record("gains",&record); 00315 std::cout<<"Last gains record "<<record<<" for run file "<<myname<<" saved "<<myTime<<std::endl; 00316 if(debug) dbon->cdbon_write(cn,"gains",12,3498,myTime); 00317 /* 00318 adcCharge.Write(); 00319 calibfile.Write(); 00320 calibfile.Close(); 00321 */ 00322 00323 }
void CSCOldGainAnalyzer::analyze | ( | edm::Event const & | e, | |
edm::EventSetup const & | iSetup | |||
) | [virtual] |
Take a reference to this FED's data
unpack data
get a pointer to data and pass it to constructor for unpacking
loop over DDUs
get a reference to chamber data
Implements edm::EDAnalyzer.
Definition at line 77 of file CSCOldGainAnalyzer.cc.
References ecalMGPA::adc(), adcMax, adcMean_max, CSCDMBHeader::cfebAvailable(), CHAMBERS_oldga, GenMuonPlsPt100GeV_cfg::cout, crateID, FEDRawData::data(), DDU_oldga, dmbID, lat::endl(), eventNumber, evt, first, edm::Event::getByLabel(), edm::Event::getByType(), FEDNumbering::getCSCFEDIds(), i, i_chamber, i_layer, id, int, k, kk, LAYERS_oldga, maxmodten, misMatch, NChambers, Nddu, NUMBERPLOTTED_oldga, NUMMODTEN_oldga, reportedChambers, FEDRawData::size(), size, strip, and STRIPS_oldga.
00077 { 00078 00079 edm::Handle<CSCStripDigiCollection> strips; 00080 e.getByLabel("cscunpacker","MuonCSCStripDigi",strips); 00081 00082 edm::Handle<FEDRawDataCollection> rawdata; 00083 e.getByType(rawdata); 00084 00085 for (int id=FEDNumbering::getCSCFEDIds().first; 00086 id<=FEDNumbering::getCSCFEDIds().second; ++id){ //for each of our DCCs 00087 00089 const FEDRawData& fedData = rawdata->FEDData(id); 00090 if (fedData.size()){ 00091 00093 CSCDCCEventData dccData((short unsigned int *) fedData.data()); 00094 00095 const std::vector<CSCDDUEventData> & dduData = dccData.dduData(); 00096 00097 evt++; 00098 for (unsigned int iDDU=0; iDDU<dduData.size(); ++iDDU) { 00099 00101 const std::vector<CSCEventData> & cscData = dduData[iDDU].cscData(); 00102 Nddu = dduData.size(); 00103 reportedChambers += dduData[iDDU].header().ncsc(); 00104 NChambers = cscData.size(); 00105 int repChambers = dduData[iDDU].header().ncsc(); 00106 std::cout << " Reported Chambers = " << repChambers <<" "<<NChambers<< std::endl; 00107 if (NChambers!=repChambers) { std::cout<< "misMatched size!!!" << std::endl; misMatch++;} 00108 00109 for (int i_chamber=0; i_chamber<NChambers; i_chamber++) { 00110 00111 for (int i_layer = 1; i_layer <=6; ++i_layer) { 00112 00113 std::vector<CSCStripDigi> digis = cscData[i_chamber].stripDigis(i_layer) ; 00114 const CSCDMBHeader * thisDMBheader = cscData[i_chamber].dmbHeader(); 00115 00116 if (thisDMBheader->cfebAvailable()){ 00117 dmbID[i_chamber] = cscData[i_chamber].dmbHeader()->dmbID();//get DMB ID 00118 crateID[i_chamber] = cscData[i_chamber].dmbHeader()->crateID();//get crate ID 00119 if(crateID[i_chamber] == 255) continue; 00120 00121 for (unsigned int i=0; i<digis.size(); i++){ 00122 size[i_chamber] = digis.size(); 00123 std::vector<int> adc = digis[i].getADCCounts(); 00124 strip = digis[i].getStrip(); 00125 adcMax[iDDU][i_chamber][i_layer-1][strip-1]=-99.0; 00126 for(unsigned int k=0; k<adc.size(); k++){ 00127 float ped=(adc[0]+adc[1])/2.; 00128 if(adc[k]-ped > adcMax[iDDU][i_chamber][i_layer-1][strip-1]) { 00129 adcMax[iDDU][i_chamber][i_layer-1][strip-1]=adc[k]-ped; 00130 } 00131 } 00132 00133 adcMean_max[iDDU][i_chamber][i_layer-1][strip-1] += adcMax[iDDU][i_chamber][i_layer-1][strip-1]/20.; 00134 00135 //On the 20th event save 00136 if (evt%20 == 0 && (strip-1)%16 == (evt-1)/NUMMODTEN_oldga){ 00137 int ten = int((evt-1)/20)%NUMBERPLOTTED_oldga ; 00138 maxmodten[ten][i_chamber][i_layer-1][strip-1] = adcMean_max[iDDU][i_chamber][i_layer-1][strip-1]; 00139 } 00140 }//end digis loop 00141 }//end cfeb.available loop 00142 }//end layer loop 00143 }//end chamber loop 00144 00145 //was %20 00146 if((evt-1)%20==0){ 00147 for(int iii=0;iii<DDU_oldga;iii++){ 00148 for(int ii=0; ii<CHAMBERS_oldga; ii++){ 00149 for(int jj=0; jj<LAYERS_oldga; jj++){ 00150 for(int kk=0; kk<STRIPS_oldga; kk++){ 00151 adcMean_max[iii][ii][jj][kk]=0.0; 00152 } 00153 } 00154 } 00155 } 00156 } 00157 00158 eventNumber++; 00159 edm::LogInfo ("CSCOldGainAnalyzer") << "end of event number " << eventNumber; 00160 } 00161 } 00162 } 00163 }
TH2F CSCOldGainAnalyzer::adcCharge [private] |
float CSCOldGainAnalyzer::adcMax[DDU_oldga][CHAMBERS_oldga][LAYERS_oldga][STRIPS_oldga] [private] |
Definition at line 55 of file CSCOldGainAnalyzer.h.
Referenced by analyze(), and CSCOldGainAnalyzer().
float CSCOldGainAnalyzer::adcMean_max[DDU_oldga][CHAMBERS_oldga][LAYERS_oldga][STRIPS_oldga] [private] |
Definition at line 56 of file CSCOldGainAnalyzer.h.
Referenced by analyze(), and CSCOldGainAnalyzer().
std::string CSCOldGainAnalyzer::chamber_id [private] |
int CSCOldGainAnalyzer::chamber_index [private] |
int CSCOldGainAnalyzer::chamber_num [private] |
int CSCOldGainAnalyzer::counter [private] |
Definition at line 62 of file CSCOldGainAnalyzer.h.
Referenced by CSCOldGainAnalyzer(), and ~CSCOldGainAnalyzer().
int CSCOldGainAnalyzer::crateID[CHAMBERS_oldga] [private] |
Definition at line 53 of file CSCOldGainAnalyzer.h.
Referenced by analyze(), and ~CSCOldGainAnalyzer().
bool CSCOldGainAnalyzer::debug [private] |
Definition at line 65 of file CSCOldGainAnalyzer.h.
Referenced by CSCOldGainAnalyzer(), and ~CSCOldGainAnalyzer().
int CSCOldGainAnalyzer::dmbID[CHAMBERS_oldga] [private] |
Definition at line 53 of file CSCOldGainAnalyzer.h.
Referenced by analyze(), and ~CSCOldGainAnalyzer().
int CSCOldGainAnalyzer::eventNumber [private] |
Definition at line 50 of file CSCOldGainAnalyzer.h.
Referenced by analyze(), and CSCOldGainAnalyzer().
int CSCOldGainAnalyzer::evt [private] |
Definition at line 50 of file CSCOldGainAnalyzer.h.
Referenced by analyze(), and CSCOldGainAnalyzer().
int CSCOldGainAnalyzer::fff [private] |
Definition at line 51 of file CSCOldGainAnalyzer.h.
std::ifstream CSCOldGainAnalyzer::filein [private] |
int CSCOldGainAnalyzer::first_strip_index [private] |
int CSCOldGainAnalyzer::flagGain [private] |
Definition at line 62 of file CSCOldGainAnalyzer.h.
Referenced by CSCOldGainAnalyzer(), and ~CSCOldGainAnalyzer().
int CSCOldGainAnalyzer::flagIntercept [private] |
Definition at line 62 of file CSCOldGainAnalyzer.h.
Referenced by CSCOldGainAnalyzer(), and ~CSCOldGainAnalyzer().
float CSCOldGainAnalyzer::gainIntercept [private] |
Definition at line 54 of file CSCOldGainAnalyzer.h.
Referenced by CSCOldGainAnalyzer(), and ~CSCOldGainAnalyzer().
float CSCOldGainAnalyzer::gainSlope [private] |
Definition at line 54 of file CSCOldGainAnalyzer.h.
Referenced by CSCOldGainAnalyzer(), and ~CSCOldGainAnalyzer().
int CSCOldGainAnalyzer::i_chamber [private] |
Definition at line 50 of file CSCOldGainAnalyzer.h.
Referenced by analyze(), and CSCOldGainAnalyzer().
int CSCOldGainAnalyzer::i_layer [private] |
Definition at line 50 of file CSCOldGainAnalyzer.h.
Referenced by analyze(), and CSCOldGainAnalyzer().
int CSCOldGainAnalyzer::length [private] |
int CSCOldGainAnalyzer::lines [private] |
float CSCOldGainAnalyzer::maxmodten[NUMMODTEN_oldga][CHAMBERS_oldga][LAYERS_oldga][STRIPS_oldga] [private] |
Definition at line 57 of file CSCOldGainAnalyzer.h.
Referenced by analyze(), CSCOldGainAnalyzer(), and ~CSCOldGainAnalyzer().
int CSCOldGainAnalyzer::misMatch [private] |
Definition at line 51 of file CSCOldGainAnalyzer.h.
Referenced by analyze(), and CSCOldGainAnalyzer().
float CSCOldGainAnalyzer::myCharge[10] [private] |
int CSCOldGainAnalyzer::myIndex [private] |
std::string CSCOldGainAnalyzer::name [private] |
int CSCOldGainAnalyzer::NChambers [private] |
Definition at line 51 of file CSCOldGainAnalyzer.h.
Referenced by analyze(), CSCOldGainAnalyzer(), and ~CSCOldGainAnalyzer().
int CSCOldGainAnalyzer::Nddu [private] |
Definition at line 51 of file CSCOldGainAnalyzer.h.
Referenced by analyze(), CSCOldGainAnalyzer(), and ~CSCOldGainAnalyzer().
std::vector<int> CSCOldGainAnalyzer::newadc [private] |
Definition at line 48 of file CSCOldGainAnalyzer.h.
float CSCOldGainAnalyzer::newChi2[480] [private] |
float CSCOldGainAnalyzer::newGain[480] [private] |
float CSCOldGainAnalyzer::newIntercept[480] [private] |
std::string CSCOldGainAnalyzer::PSet [private] |
Definition at line 64 of file CSCOldGainAnalyzer.h.
time_t CSCOldGainAnalyzer::rawtime [private] |
Definition at line 52 of file CSCOldGainAnalyzer.h.
int CSCOldGainAnalyzer::record [private] |
int CSCOldGainAnalyzer::reportedChambers [private] |
Definition at line 50 of file CSCOldGainAnalyzer.h.
Referenced by analyze(), and CSCOldGainAnalyzer().
int CSCOldGainAnalyzer::ret_code [private] |
Definition at line 51 of file CSCOldGainAnalyzer.h.
int CSCOldGainAnalyzer::sector [private] |
int CSCOldGainAnalyzer::size[CHAMBERS_oldga] [private] |
Definition at line 53 of file CSCOldGainAnalyzer.h.
Referenced by analyze(), CSCOldGainAnalyzer(), and ~CSCOldGainAnalyzer().
int CSCOldGainAnalyzer::strip [private] |
Definition at line 51 of file CSCOldGainAnalyzer.h.
Referenced by analyze(), and CSCOldGainAnalyzer().
int CSCOldGainAnalyzer::strips_per_layer [private] |