CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/SimCalorimetry/EcalTrigPrimProducers/plugins/EcalTrigPrimAnalyzerMIPs.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Class:      EcalTrigPrimAnalyzerMIPs
00004 //
00005 //
00006 // Original Author:  Pascal Paganini
00007 //
00008 //
00009 
00010 
00011 // system include files
00012 #include <memory>
00013 #include <utility>
00014 
00015 // user include files
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   // general tree
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   // tree to analyze missing FEDs 
00090   fedtree_ = new TTree("fedtree","fedtree");
00091   fedtree_->Branch("fedId",&fedId_,"fedId/I");
00092   fedtree_->Branch("fedSize",&fedSize_,"fedSize/I");
00093 
00094   // tree for TOP-Bottom coincidence
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 // member functions
00118 //
00119 
00120 // ------------ method called to analyze the data  ------------
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   // Get digi input
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   // Get Emulators TP
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   // Get TP data
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   // fill tree
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 //     int maxtpg = 0 ;
00291 //     if (tpgEmul0_ > tpgEmul1_ && tpgEmul0_ > tpgEmul2_ && tpgEmul0_ > tpgEmul3_ && tpgEmul0_ > tpgEmul4_) maxtpg = tpgEmul0_ ;
00292 //     if (tpgEmul1_ > tpgEmul0_ && tpgEmul1_ > tpgEmul2_ && tpgEmul1_ > tpgEmul3_ && tpgEmul1_ > tpgEmul4_) maxtpg = tpgEmul1_ ;
00293 //     if (tpgEmul2_ > tpgEmul1_ && tpgEmul2_ > tpgEmul0_ && tpgEmul2_ > tpgEmul3_ && tpgEmul2_ > tpgEmul4_) maxtpg = tpgEmul2_ ;
00294 //     if (tpgEmul3_ > tpgEmul1_ && tpgEmul3_ > tpgEmul2_ && tpgEmul3_ > tpgEmul0_ && tpgEmul3_ > tpgEmul4_) maxtpg = tpgEmul3_ ;
00295 //     if (tpgEmul4_ > tpgEmul1_ && tpgEmul4_ > tpgEmul2_ && tpgEmul4_ > tpgEmul3_ && tpgEmul4_ > tpgEmul0_) maxtpg = tpgEmul4_ ;
00296 
00297 //     if (maxtpg>=40) {
00298 
00299 //       int phiArray[19] = {19, 11, 12, 55, 56, 57, 58, 51, 52, 53, 54, 55, 56, 57, 58, 15, 16, 17, 18} ;
00300 //       int etaArray[19] = {15, 9, 9, 12, 12, 12, 12, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6} ;
00301 
00302 //       for (int bad=0 ; bad<19 ; bad++) {
00303       
00304 //      if (iphi_==phiArray[bad] && ieta_==etaArray[bad]) {
00305 //        std::cout<<"nevt "<<nevt_<<" "<<iphi_<<" "<<ieta_<<std::endl ;
00306         
00307 //        float max = 0. ;
00308 //        int xtal_iphi = 0, xtal_ieta = 0, xtal_ic = 0, xtal_sm = 0 ;
00309 //        for (unsigned int i=0;i<digi.product()->size();i++) {
00310 //          const EBDataFrame & df = (*(digi.product()))[i];
00311 //          const EBDetId & id=df.id();
00312 //          const EcalTrigTowerDetId towid= id.tower();
00313 //          if (towid.iphi()== phiArray[bad] && towid.ieta()== etaArray[bad]) {
00314               
00315 //            float mean = (df[0].adc()+df[1].adc())/2. ;
00316 //            float adc = 0. ;
00317 //            for (int s=0 ; s<10 ; s++) if (df[s].adc() > adc) adc = df[s].adc() ;
00318 //            adc -= mean ;
00319 
00320 //            if (adc>max) {
00321 //              max = adc ;
00322 //              xtal_iphi = id.iphi() ;
00323 //              xtal_ieta = id.ieta() ;     
00324 //              xtal_ic = id.ic() ;         
00325 //              xtal_sm = id.ism() ;        
00326 //            }
00327                       
00328 //          }
00329 //        }
00330 //        std::cout<<xtal_iphi<<" "<<xtal_ieta<<" "<<xtal_ic<<" "<<xtal_sm<<" "<<max<<std::endl ;
00331 //      }
00332 //       }
00333 //     }
00334 
00335       
00336   }
00337 
00338 
00339 // trying to find coincidence :
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     // lets's exclude noisy tower: 
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       // top:
00360       if (id.ism() >= 4 && id.ism() <= 7) {
00361         // get the most energetic xtal:
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       // bottom:
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     // now lets make a 3x3 window
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