CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/SimCalorimetry/EcalTrigPrimProducers/plugins/EcalTrigPrimAnalyzer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Class:      EcalTrigPrimAnalyzer
00004 //
00010 //
00011 //
00012 // Original Author:  Ursula Berthon, Stephanie Baffioni, Pascal Paganini
00013 //         Created:  Thu Jul 4 11:38:38 CEST 2005
00014 // $Id: EcalTrigPrimAnalyzer.cc,v 1.18 2008/06/24 13:03:14 uberthon Exp $
00015 //
00016 //
00017 
00018 
00019 // system include files
00020 #include <memory>
00021 #include <utility>
00022 
00023 // user include files
00024 #include "FWCore/Framework/interface/EDAnalyzer.h"
00025 #include "FWCore/Framework/interface/Event.h"
00026 #include "FWCore/Framework/interface/MakerMacros.h"
00027 
00028 #include "Geometry/CaloTopology/interface/EcalTrigTowerConstituentsMap.h"
00029 #include "FWCore/Framework/interface/EventSetup.h"
00030 #include "FWCore/Framework/interface/ESHandle.h"
00031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00032 
00033 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
00034 #include "DataFormats/EcalDigi/interface/EcalTriggerPrimitiveDigi.h"
00035 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
00036 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00037 
00038 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00039 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
00040 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
00041 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00042 
00043 #include "CalibCalorimetry/EcalTPGTools/interface/EcalTPGScale.h"
00044 
00045 #include "EcalTrigPrimAnalyzer.h"
00046 
00047 #include <TMath.h>
00048 
00049 using namespace edm;
00050 class CaloSubdetectorGeometry;
00051 
00052 EcalTrigPrimAnalyzer::EcalTrigPrimAnalyzer(const edm::ParameterSet&  iConfig)
00053 
00054 {
00055   ecal_parts_.push_back("Barrel");
00056   ecal_parts_.push_back("Endcap");
00057 
00058   histfile_=new TFile("histos.root","RECREATE");
00059   tree_ = new TTree("TPGtree","TPGtree");
00060   tree_->Branch("iphi",&iphi_,"iphi/I");
00061   tree_->Branch("ieta",&ieta_,"ieta/I");
00062   tree_->Branch("eRec",&eRec_,"eRec/F");
00063   tree_->Branch("tpgADC",&tpgADC_,"tpgADC/I");
00064   tree_->Branch("tpgGeV",&tpgGeV_,"tpgGeV/F");
00065   tree_->Branch("ttf",&ttf_,"ttf/I");
00066   tree_->Branch("fg",&fg_,"fg/I");
00067   for (unsigned int i=0;i<2;++i) {
00068     ecal_et_[i]=new TH1I(ecal_parts_[i].c_str(),"Et",255,0,255);
00069     char title[30];
00070     sprintf(title,"%s_ttf",ecal_parts_[i].c_str());
00071     ecal_tt_[i]=new TH1I(title,"TTF",10,0,10);
00072     sprintf(title,"%s_fgvb",ecal_parts_[i].c_str());
00073     ecal_fgvb_[i]=new TH1I(title,"FGVB",10,0,10);
00074   }
00075 
00076   recHits_= iConfig.getParameter<bool>("AnalyzeRecHits");
00077   label_=iConfig.getParameter<edm::InputTag>("inputTP");
00078   if (recHits_) {
00079     hTPvsRechit_= new TH2F("TP_vs_RecHit","TP vs  rechit",256,-1,255,255,0,255);
00080     hTPoverRechit_= new TH1F("TP_over_RecHit","TP over rechit",500,0,4);
00081     rechits_labelEB_=iConfig.getParameter<edm::InputTag>("inputRecHitsEB");
00082     rechits_labelEE_=iConfig.getParameter<edm::InputTag>("inputRecHitsEE");
00083   }
00084 }
00085 
00086 
00087 EcalTrigPrimAnalyzer::~EcalTrigPrimAnalyzer()
00088 {
00089 
00090    // do anything here that needs to be done at desctruction time
00091    // (e.g. close files, deallocate resources etc.)
00092 
00093   histfile_->Write();
00094   histfile_->Close();
00095 
00096 }
00097 
00098 
00099 //
00100 // member functions
00101 //
00102 
00103 // ------------ method called to analyze the data  ------------
00104 void
00105 EcalTrigPrimAnalyzer::analyze(const edm::Event& iEvent, const  edm::EventSetup & iSetup)
00106 {
00107   using namespace edm;
00108   using namespace std;
00109 
00110   // Get input
00111   edm::Handle<EcalTrigPrimDigiCollection> tp;
00112   iEvent.getByLabel(label_,tp);
00113   for (unsigned int i=0;i<tp.product()->size();i++) {
00114     EcalTriggerPrimitiveDigi d=(*(tp.product()))[i];
00115     int subdet=d.id().subDet()-1;
00116     if (subdet==0) {
00117       ecal_et_[subdet]->Fill(d.compressedEt());
00118     }
00119     else {
00120       if (d.id().ietaAbs()==27 || d.id().ietaAbs()==28) {
00121         if (i%2) ecal_et_[subdet]->Fill(d.compressedEt()*2.);
00122       }
00123       else ecal_et_[subdet]->Fill(d.compressedEt());
00124     }
00125     ecal_tt_[subdet]->Fill(d.ttFlag());
00126     ecal_fgvb_[subdet]->Fill(d.fineGrain());
00127 
00128   }
00129   if (!recHits_) return;
00130 
00131   // comparison with RecHits
00132   edm::Handle<EcalRecHitCollection> rechit_EB_col;
00133   iEvent.getByLabel(rechits_labelEB_,rechit_EB_col);
00134 
00135   edm::Handle<EcalRecHitCollection> rechit_EE_col;
00136   iEvent.getByLabel(rechits_labelEE_,rechit_EE_col);
00137   
00138 
00139   edm::ESHandle<CaloGeometry> theGeometry;
00140   edm::ESHandle<CaloSubdetectorGeometry> theBarrelGeometry_handle;
00141   edm::ESHandle<CaloSubdetectorGeometry> theEndcapGeometry_handle;
00142   iSetup.get<CaloGeometryRecord>().get( theGeometry );
00143   iSetup.get<EcalEndcapGeometryRecord>().get("EcalEndcap",theEndcapGeometry_handle);
00144   iSetup.get<EcalBarrelGeometryRecord>().get("EcalBarrel",theBarrelGeometry_handle);
00145 
00146   const CaloSubdetectorGeometry *theEndcapGeometry,*theBarrelGeometry;
00147   theEndcapGeometry = &(*theEndcapGeometry_handle);
00148   theBarrelGeometry = &(*theBarrelGeometry_handle);
00149   edm::ESHandle<EcalTrigTowerConstituentsMap> eTTmap_;
00150   iSetup.get<IdealGeometryRecord>().get(eTTmap_);
00151 
00152   map<EcalTrigTowerDetId, float> mapTow_Et;
00153 
00154 
00155   for (unsigned int i=0;i<rechit_EB_col.product()->size();i++) {
00156     const EBDetId & myid1=(*rechit_EB_col.product())[i].id();
00157     EcalTrigTowerDetId towid1= myid1.tower();
00158     float theta =  theBarrelGeometry->getGeometry(myid1)->getPosition().theta();
00159     float Etsum=((*rechit_EB_col.product())[i].energy())*sin(theta);
00160     bool test_alreadyin= false;
00161     map<EcalTrigTowerDetId, float>::iterator ittest=  mapTow_Et.find(towid1);
00162     if (ittest!= mapTow_Et.end()) test_alreadyin=true;
00163     if (test_alreadyin) continue;
00164     unsigned int j=i+1;
00165     bool loopend=false;
00166     unsigned int count=0;
00167     while( j<rechit_EB_col.product()->size() && !loopend){
00168       count++;
00169       const EBDetId & myid2=(*rechit_EB_col.product())[j].id();
00170       EcalTrigTowerDetId towid2= myid2.tower();
00171       if( towid1==towid2 ) {
00172         float  theta=theBarrelGeometry->getGeometry(myid2)->getPosition().theta();
00173         Etsum += (*rechit_EB_col.product())[j].energy()*sin(theta);
00174       }
00175       j++;
00176       if (count>1800) loopend=true;
00177     }
00178     mapTow_Et.insert(pair<EcalTrigTowerDetId,float>(towid1, Etsum));
00179   }
00180 
00181 
00182   for (unsigned int i=0;i<rechit_EE_col.product()->size();i++) {
00183     const EEDetId & myid1=(*rechit_EE_col.product())[i].id();
00184     EcalTrigTowerDetId towid1= (*eTTmap_).towerOf(myid1);
00185     float  theta=theEndcapGeometry->getGeometry(myid1)->getPosition().theta();
00186     float Etsum=(*rechit_EE_col.product())[i].energy()*sin(theta);
00187     bool test_alreadyin= false;
00188     map<EcalTrigTowerDetId, float>::iterator ittest=  mapTow_Et.find(towid1);
00189     if (ittest!= mapTow_Et.end()) test_alreadyin=true;
00190     if (test_alreadyin) continue;
00191     unsigned int j=i+1;
00192     bool loopend=false;
00193     unsigned int count=0;
00194     while( j<rechit_EE_col.product()->size() && !loopend){
00195       const EEDetId & myid2=(*rechit_EE_col.product())[j].id();
00196       EcalTrigTowerDetId towid2= (*eTTmap_).towerOf(myid2);
00197       if( towid1==towid2 ) {
00198         float  theta=theEndcapGeometry->getGeometry(myid2)->getPosition().theta();
00199         Etsum += (*rechit_EE_col.product())[j].energy()*sin(theta);
00200       }
00201       //  else loopend=true;
00202       j++;
00203       if (count>500) loopend=true;
00204     }
00205     //    alreadyin_EE.push_back(towid1);
00206     mapTow_Et.insert(pair<EcalTrigTowerDetId,float>(towid1, Etsum));
00207   }
00208 
00209 
00210   EcalTPGScale ecalScale ;
00211   ecalScale.setEventSetup(iSetup) ;
00212   for (unsigned int i=0;i<tp.product()->size();i++) {
00213     EcalTriggerPrimitiveDigi d=(*(tp.product()))[i];
00214     const EcalTrigTowerDetId TPtowid= d.id();
00215     map<EcalTrigTowerDetId, float>::iterator it=  mapTow_Et.find(TPtowid);
00216     float Et = ecalScale.getTPGInGeV(d.compressedEt(), TPtowid) ; 
00217     if (d.id().ietaAbs()==27 || d.id().ietaAbs()==28)    Et*=2;
00218     iphi_ = TPtowid.iphi() ;
00219     ieta_ = TPtowid.ieta() ;
00220     tpgADC_ = d.compressedEt() ;
00221     tpgGeV_ = Et ;
00222     ttf_ = d.ttFlag() ;
00223     fg_ = d.fineGrain() ;
00224     if (it!= mapTow_Et.end()) {
00225       hTPvsRechit_->Fill(it->second,Et);
00226       hTPoverRechit_->Fill(Et/it->second);
00227       eRec_ = it->second ;
00228     }
00229     tree_->Fill() ;
00230   }
00231 
00232 }
00233 
00234 void
00235 EcalTrigPrimAnalyzer::endJob(){
00236   for (unsigned int i=0;i<2;++i) {
00237     ecal_et_[i]->Write();
00238     ecal_tt_[i]->Write();
00239     ecal_fgvb_[i]->Write();
00240   }
00241   if (recHits_) {
00242     hTPvsRechit_->Write();
00243     hTPoverRechit_->Write();
00244   }
00245 }
00246