00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <memory>
00013 #include <utility>
00014
00015
00016 #include "FWCore/Framework/interface/EDAnalyzer.h"
00017 #include "FWCore/Framework/interface/Event.h"
00018 #include "FWCore/Framework/interface/MakerMacros.h"
00019
00020 #include "FWCore/Framework/interface/EventSetup.h"
00021 #include "FWCore/Framework/interface/ESHandle.h"
00022 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00023
00024 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
00025 #include "DataFormats/EcalDigi/interface/EcalTriggerPrimitiveDigi.h"
00026 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
00027 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00028 #include <DataFormats/FEDRawData/interface/FEDRawData.h>
00029 #include <DataFormats/FEDRawData/interface/FEDNumbering.h>
00030 #include <DataFormats/FEDRawData/interface/FEDRawDataCollection.h>
00031
00032 #include "Geometry/CaloTopology/interface/EcalTrigTowerConstituentsMap.h"
00033 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00034 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
00035 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
00036 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00037
00038 #include "CalibCalorimetry/EcalTPGTools/interface/EcalTPGScale.h"
00039
00040 #include "EcalTrigPrimAnalyzerMIPs.h"
00041
00042 #include <TMath.h>
00043
00044 using namespace edm;
00045 class CaloSubdetectorGeometry;
00046
00047 EcalTrigPrimAnalyzerMIPs::EcalTrigPrimAnalyzerMIPs(const edm::ParameterSet& iConfig)
00048 : nevt_(0)
00049 {
00050 label_= iConfig.getParameter<std::string>("Label");
00051 producer_= iConfig.getParameter<std::string>("Producer");
00052 digi_label_= iConfig.getParameter<std::string>("DigiLabel");
00053 digi_producer_= iConfig.getParameter<std::string>("DigiProducer");
00054 emul_label_= iConfig.getParameter<std::string>("EmulLabel");
00055 emul_producer_= iConfig.getParameter<std::string>("EmulProducer");
00056
00057
00058 histfile_ = new TFile("histos.root","RECREATE");
00059
00060
00061 tree_ = new TTree("TPGtree","TPGtree");
00062 tree_->Branch("iphi",&iphi_,"iphi/I");
00063 tree_->Branch("ieta",&ieta_,"ieta/I");
00064 tree_->Branch("eRec",&eRec_,"eRec/F");
00065 tree_->Branch("mean",&mean_,"mean/F");
00066 tree_->Branch("data0",&data0_,"data0/F");
00067 tree_->Branch("data1",&data1_,"data1/F");
00068 tree_->Branch("data2",&data2_,"data2/F");
00069 tree_->Branch("data3",&data3_,"data3/F");
00070 tree_->Branch("data4",&data4_,"data4/F");
00071 tree_->Branch("data5",&data5_,"data5/F");
00072 tree_->Branch("data6",&data6_,"data6/F");
00073 tree_->Branch("data7",&data7_,"data7/F");
00074 tree_->Branch("data8",&data8_,"data8/F");
00075 tree_->Branch("data9",&data9_,"data9/F");
00076 tree_->Branch("tpgADC",&tpgADC_,"tpgADC/I");
00077 tree_->Branch("tpgGeV",&tpgGeV_,"tpgGeV/F");
00078 tree_->Branch("tpgEmul0",&tpgEmul0_,"tpgEmul0/I");
00079 tree_->Branch("tpgEmul1",&tpgEmul1_,"tpgEmul1/I");
00080 tree_->Branch("tpgEmul2",&tpgEmul2_,"tpgEmul2/I");
00081 tree_->Branch("tpgEmul3",&tpgEmul3_,"tpgEmul3/I");
00082 tree_->Branch("tpgEmul4",&tpgEmul4_,"tpgEmul4/I");
00083 tree_->Branch("ttf",&ttf_,"ttf/I");
00084 tree_->Branch("fg",&fg_,"fg/I");
00085 tree_->Branch("nevt",&nevt_,"nevt/I");
00086 tree_->Branch("nXtal",&nXtal_,"nXtal/I");
00087 tree_->Branch("sample",&sample_,"sample/F");
00088
00089
00090 fedtree_ = new TTree("fedtree","fedtree");
00091 fedtree_->Branch("fedId",&fedId_,"fedId/I");
00092 fedtree_->Branch("fedSize",&fedSize_,"fedSize/I");
00093
00094
00095 treetopbot_ = new TTree("topbottree", "topbottree") ;
00096 treetopbot_->Branch("nevt",&nevt_,"nevt/I");
00097 treetopbot_->Branch("iphitop",&iphitop_,"iphitop/I");
00098 treetopbot_->Branch("ietatop",&ietatop_,"ietatop/I");
00099 treetopbot_->Branch("Etop",&Etop_,"Etop/F");
00100 treetopbot_->Branch("Ntop",&Ntop_,"Ntop/I");
00101 treetopbot_->Branch("iphibot",&iphibot_,"iphibot/I");
00102 treetopbot_->Branch("ietabot",&ietabot_,"ietabot/I");
00103 treetopbot_->Branch("Ebot",&Ebot_,"Ebot/F");
00104 treetopbot_->Branch("Nbot",&Nbot_,"Nbot/I");
00105
00106 }
00107
00108
00109 EcalTrigPrimAnalyzerMIPs::~EcalTrigPrimAnalyzerMIPs()
00110 {
00111 histfile_->Write();
00112 histfile_->Close();
00113 }
00114
00115
00116
00117
00118
00119
00120
00121 void EcalTrigPrimAnalyzerMIPs::analyze(const edm::Event& iEvent, const edm::EventSetup & iSetup)
00122 {
00123 using namespace edm;
00124 using namespace std;
00125
00126
00127
00128 edm::Handle<FEDRawDataCollection> rawdata;
00129 iEvent.getByType(rawdata);
00130 for (int id= 0; id<=FEDNumbering::MAXFEDID; ++id){
00131 if (id < 600 || id > 654) continue;
00132 const FEDRawData& data = rawdata->FEDData(id);
00133 fedId_ = id ;
00134 fedSize_ = data.size() ;
00135 fedtree_->Fill() ;
00136 }
00137
00138
00139 map<EcalTrigTowerDetId, towerEner> mapTower ;
00140 map<EcalTrigTowerDetId, towerEner>::iterator itTT ;
00141
00142
00143 edm::Handle<EBDigiCollection> digi;
00144 iEvent.getByLabel(digi_label_, digi_producer_, digi);
00145 for (unsigned int i=0;i<digi.product()->size();i++) {
00146 const EBDataFrame & df = (*(digi.product()))[i];
00147
00148 int gain, adc ;
00149 float E_xtal = 0. ;
00150 int theSamp = 0 ;
00151 float mean = 0., max = -999 ;
00152 for (int samp = 0 ; samp<10 ; samp++) {
00153 adc = df[samp].adc() ;
00154 if (samp<2) mean += adc ;
00155 if (adc>max) {
00156 max = adc ;
00157 theSamp = samp ;
00158 }
00159 }
00160 mean /= 2 ;
00161 if (mean>0 && max > mean + 10) {
00162 gain = df[theSamp].gainId() ;
00163 adc = df[theSamp].adc() ;
00164 if (gain == 1) E_xtal = (adc-mean) ;
00165 if (gain == 2) E_xtal = 2.*(adc-mean) ;
00166 if (gain == 3) E_xtal = 12.*(adc-mean) ;
00167 if (gain == 0) E_xtal = 12.*(adc-mean) ;
00168 }
00169 const EBDetId & id=df.id();
00170 const EcalTrigTowerDetId towid= id.tower();
00171 itTT = mapTower.find(towid) ;
00172 if (itTT != mapTower.end()) {
00173 (itTT->second).eRec_ += E_xtal ;
00174 (itTT->second).sample_ += E_xtal*theSamp ;
00175 for (int samp = 0 ; samp<10 ; samp++) (itTT->second).data_[samp] += df[samp].adc()-mean ;
00176 if (E_xtal != 0) {
00177 (itTT->second).nXtal_ ++ ;
00178 (itTT->second).mean_ += mean ;
00179 }
00180 }
00181 else {
00182 towerEner tE ;
00183 tE.eRec_ = E_xtal ;
00184 tE.sample_ += E_xtal*theSamp ;
00185 for (int samp = 0 ; samp<10 ; samp++) tE.data_[samp] = df[samp].adc()-mean ;
00186 if (E_xtal != 0) {
00187 tE.nXtal_ ++ ;
00188 tE.mean_ = mean ;
00189 }
00190 mapTower[towid] = tE ;
00191 }
00192 }
00193
00194
00195
00196
00197 edm::Handle<EcalTrigPrimDigiCollection> tpEmul ;
00198 iEvent.getByLabel(emul_label_, emul_producer_, tpEmul);
00199 for (unsigned int i=0;i<tpEmul.product()->size();i++) {
00200 EcalTriggerPrimitiveDigi d = (*(tpEmul.product()))[i];
00201 const EcalTrigTowerDetId TPtowid= d.id();
00202 itTT = mapTower.find(TPtowid) ;
00203
00204 if (itTT != mapTower.end()) {
00205 (itTT->second).tpgEmul0_ = (d[0].raw() & 0x1ff) ;
00206 (itTT->second).tpgEmul1_ = (d[1].raw() & 0x1ff) ;
00207 (itTT->second).tpgEmul2_ = (d[2].raw() & 0x1ff) ;
00208 (itTT->second).tpgEmul3_ = (d[3].raw() & 0x1ff) ;
00209 (itTT->second).tpgEmul4_ = (d[4].raw() & 0x1ff) ;
00210 }
00211 else {
00212 towerEner tE ;
00213 tE.tpgEmul0_ = (d[0].raw() & 0x1ff) ;
00214 tE.tpgEmul1_ = (d[1].raw() & 0x1ff) ;
00215 tE.tpgEmul2_ = (d[2].raw() & 0x1ff) ;
00216 tE.tpgEmul3_ = (d[3].raw() & 0x1ff) ;
00217 tE.tpgEmul4_ = (d[4].raw() & 0x1ff) ;
00218 mapTower[TPtowid] = tE ;
00219 }
00220 }
00221
00222
00223
00224
00225 edm::Handle<EcalTrigPrimDigiCollection> tp;
00226 iEvent.getByLabel(label_,producer_,tp);
00227 EcalTPGScale ecalScale;
00228 ecalScale.setEventSetup(iSetup) ;
00229 for (unsigned int i=0;i<tp.product()->size();i++) {
00230 EcalTriggerPrimitiveDigi d = (*(tp.product()))[i];
00231 const EcalTrigTowerDetId TPtowid= d.id();
00232 float Et = ecalScale.getTPGInGeV(d) ;
00233 if (d.id().ietaAbs()==27 || d.id().ietaAbs()==28) Et*=2;
00234
00235 itTT = mapTower.find(TPtowid) ;
00236 if (itTT != mapTower.end()) {
00237 (itTT->second).iphi_ = TPtowid.iphi() ;
00238 (itTT->second).ieta_ = TPtowid.ieta() ;
00239 (itTT->second).tpgADC_ = d.compressedEt() ;
00240 (itTT->second).tpgGeV_ = Et ;
00241 (itTT->second).ttf_ = d.ttFlag() ;
00242 (itTT->second).fg_ = d.fineGrain() ;
00243 }
00244 else {
00245 towerEner tE ;
00246 tE.iphi_ = TPtowid.iphi() ;
00247 tE.ieta_ = TPtowid.ieta() ;
00248 tE.tpgADC_ = d.compressedEt() ;
00249 tE.tpgGeV_ = Et ;
00250 tE.ttf_ = d.ttFlag() ;
00251 tE.fg_ = d.fineGrain() ;
00252 mapTower[TPtowid] = tE ;
00253 }
00254
00255 }
00256
00257
00258
00259
00260 if (mapTower.size()>0) nevt_++ ;
00261 for (itTT = mapTower.begin() ; itTT != mapTower.end() ; ++itTT ) {
00262 iphi_ = (itTT->second).iphi_ ;
00263 ieta_ = (itTT->second).ieta_ ;
00264 tpgADC_ = (itTT->second).tpgADC_ ;
00265 tpgGeV_ = (itTT->second).tpgGeV_ ;
00266 tpgEmul0_ = (itTT->second).tpgEmul0_ ;
00267 tpgEmul1_ = (itTT->second).tpgEmul1_ ;
00268 tpgEmul2_ = (itTT->second).tpgEmul2_ ;
00269 tpgEmul3_ = (itTT->second).tpgEmul3_ ;
00270 tpgEmul4_ = (itTT->second).tpgEmul4_ ;
00271 ttf_ = (itTT->second).ttf_ ;
00272 fg_ = (itTT->second).fg_ ;
00273 eRec_ = (itTT->second).eRec_ ;
00274 mean_ = (itTT->second).mean_ ;
00275 data0_ = (itTT->second).data_[0] ;
00276 data1_ = (itTT->second).data_[1] ;
00277 data2_ = (itTT->second).data_[2] ;
00278 data3_ = (itTT->second).data_[3] ;
00279 data4_ = (itTT->second).data_[4] ;
00280 data5_ = (itTT->second).data_[5] ;
00281 data6_ = (itTT->second).data_[6] ;
00282 data7_ = (itTT->second).data_[7] ;
00283 data8_ = (itTT->second).data_[8] ;
00284 data9_ = (itTT->second).data_[9] ;
00285 nXtal_ = (itTT->second).nXtal_ ;
00286 sample_ = 0 ;
00287 if (eRec_>0) sample_ = (itTT->second).sample_/eRec_ ;
00288 tree_->Fill() ;
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336 }
00337
00338
00339
00340 float E_max_top = 0., E_max_bot = 0.;
00341 EBDetId idRef_top, idRef_bot ;
00342 for (unsigned int i=0;i<digi.product()->size();i++) {
00343 const EBDataFrame & df = (*(digi.product()))[i];
00344 const EBDetId & id=df.id();
00345 const EcalTrigTowerDetId towid= id.tower();
00346
00347
00348 bool good(true) ;
00349 if (towid.ieta() == 15 && towid.iphi() == 19) good = false ;
00350 if (towid.ieta() == 9 && towid.iphi() == 11) good = false ;
00351 if (towid.ieta() == 9 && towid.iphi() == 12) good = false ;
00352 if (towid.ieta() == 12 && towid.iphi()>54 && towid.iphi()<59) good = false ;
00353 if (towid.ieta() == 5 && towid.iphi()>50 && towid.iphi()<55) good = false ;
00354 if (towid.ieta() == 6 && towid.iphi()>54 && towid.iphi()<59) good = false ;
00355 if (towid.ieta() == 6 && towid.iphi()>14 && towid.iphi()<19) good = false ;
00356
00357 if (good) {
00358
00359
00360 if (id.ism() >= 4 && id.ism() <= 7) {
00361
00362 int adc ;
00363 float E_xtal = 0. ;
00364 float mean = 0.5*(df[0].adc()+df[1].adc()) ;
00365 float max = -999 ;
00366 for (int samp = 0 ; samp<10 ; samp++) {
00367 adc = df[samp].adc() ;
00368 if (adc>max) max = adc ;
00369 }
00370 if (mean>0 && max > mean + 10) E_xtal = (adc-mean) ;
00371 if (E_xtal > E_max_top) {
00372 E_max_top = E_xtal ;
00373 idRef_top = id ;
00374 }
00375 }
00376
00377
00378 if (id.ism() >= 14 && id.ism() <= 16) {
00379 int adc ;
00380 float E_xtal = 0. ;
00381 float mean = 0.5*(df[0].adc()+df[1].adc()) ;
00382 float max = -999 ;
00383 for (int samp = 0 ; samp<10 ; samp++) {
00384 adc = df[samp].adc() ;
00385 if (adc>max) max = adc ;
00386 }
00387 if (mean>0 && max > mean + 10) E_xtal = (adc-mean) ;
00388 if (E_xtal > E_max_bot) {
00389 E_max_bot = E_xtal ;
00390 idRef_bot = id ;
00391 }
00392 }
00393
00394 }
00395 }
00396 if (E_max_top >0 && E_max_bot>0) {
00397 std::cout<<nevt_<<std::endl ;
00398 std::cout<<idRef_top.iphi()<<" "<<idRef_top.ieta()<<" "<<idRef_top.ic()<<" "<<idRef_top.ism()<<" "<<E_max_top<<std::endl ;
00399 std::cout<<idRef_bot.iphi()<<" "<<idRef_bot.ieta()<<" "<<idRef_bot.ic()<<" "<<idRef_bot.ism()<<" "<<E_max_bot<<std::endl ;
00400
00401
00402 int rangePhitop[3] = {idRef_top.iphi()-1, idRef_top.iphi(), idRef_top.iphi()+1} ;
00403 int rangeEtatop[3] = {idRef_top.ieta()-1, idRef_top.ieta(), idRef_top.ieta()+1} ;
00404 int rangePhibot[3] = {idRef_bot.iphi()-1, idRef_bot.iphi(), idRef_bot.iphi()+1} ;
00405 int rangeEtabot[3] = {idRef_bot.ieta()-1, idRef_bot.ieta(), idRef_bot.ieta()+1} ;
00406 for (int i=0 ; i<3 ; i++) {
00407 if (rangePhitop[i] <= 0) rangePhitop[i] += 360 ;
00408 if (rangePhitop[i] > 360) rangePhitop[i] -= 360 ;
00409 if (rangeEtatop[i] <= 0 || rangeEtatop[i]>85) rangeEtatop[i] = 999999 ;
00410 if (rangePhibot[i] <= 0) rangePhibot[i] += 360 ;
00411 if (rangePhibot[i] > 360) rangePhibot[i] -= 360 ;
00412 if (rangeEtabot[i] <= 0 || rangeEtabot[i]>85) rangeEtabot[i] = 999999 ;
00413 }
00414
00415 Etop_ = 0. ;
00416 Ebot_ = 0. ;
00417 Ntop_ = 0 ;
00418 Nbot_ = 0 ;
00419 for (unsigned int i=0;i<digi.product()->size();i++) {
00420 const EBDataFrame & df = (*(digi.product()))[i];
00421 const EBDetId & id=df.id();
00422 int adc ;
00423 float E_xtal = 0. ;
00424 float mean = 0.5*(df[0].adc()+df[1].adc()) ;
00425 float max = -999 ;
00426 for (int samp = 0 ; samp<10 ; samp++) {
00427 adc = df[samp].adc() ;
00428 if (adc>max) max = adc ;
00429 }
00430 E_xtal = (adc-mean) ;
00431
00432 for (int phiIndex=0 ; phiIndex<3 ; phiIndex++)
00433 for (int etaIndex = 0 ; etaIndex<3 ; etaIndex++) {
00434 if (id.iphi() == rangePhitop[phiIndex] && id.ieta() == rangeEtatop[etaIndex]) {
00435 Etop_ += E_xtal ;
00436 Ntop_ ++ ;
00437 }
00438 if (id.iphi() == rangePhibot[phiIndex] && id.ieta() == rangeEtabot[etaIndex]) {
00439 Ebot_ += E_xtal ;
00440 Nbot_ ++ ;
00441 }
00442 }
00443 }
00444
00445 iphitop_ = idRef_top.iphi() ;
00446 ietatop_ = idRef_top.ieta() ;
00447 iphibot_ = idRef_bot.iphi() ;
00448 ietabot_ = idRef_bot.ieta() ;
00449 treetopbot_->Fill() ;
00450 }
00451
00452 }
00453