CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/Calibration/HcalCalibAlgos/src/HcalIsoTrkAnalyzer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:  HcalCalibAlgos  
00004 // Class:    HcalIsoTrkAnalyzer 
00005 
00006 // 
00013 //
00014 // Original Authors: Andrey Pozdnyakov, Sergey Petrushanko,
00015 //                   Grigory Safronov, Olga Kodolova
00016 //         Created:  Thu Jul 12 18:12:19 CEST 2007
00017 // $Id: HcalIsoTrkAnalyzer.cc,v 1.25 2010/03/17 19:43:12 wmtan Exp $
00018 //
00019 //
00020 
00021 // system include files
00022 #include <memory>
00023 
00024 // user include files
00025 #include "FWCore/Framework/interface/Frameworkfwd.h"
00026 #include "FWCore/Framework/interface/EDAnalyzer.h"
00027 
00028 #include "FWCore/Framework/interface/Event.h"
00029 #include "FWCore/Framework/interface/MakerMacros.h"
00030 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00031 #include "DataFormats/TrackReco/interface/Track.h"
00032 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00033 #include "FWCore/Framework/interface/ESHandle.h"
00034 #include "FWCore/Framework/interface/EventSetup.h"
00035 
00036 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
00037 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00038 #include "FWCore/Utilities/interface/Exception.h"
00039 
00040 #include "TrackingTools/TrackAssociator/interface/TrackDetMatchInfo.h"
00041 #include "TrackingTools/TrackAssociator/interface/TrackAssociatorParameters.h"
00042 #include "TrackingTools/TrackAssociator/interface/TrackDetectorAssociator.h"
00043 
00044 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
00045 #include "DataFormats/HcalDetId/interface/HcalSubdetector.h" 
00046 
00047 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
00048 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h" 
00049 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00050 #include "Geometry/CaloEventSetup/interface/CaloTopologyRecord.h"
00051 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00052 
00053 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00054 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00055 #include "TrackPropagation/SteppingHelixPropagator/interface/SteppingHelixPropagator.h"
00056 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00057 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00058 #include "DataFormats/HcalIsolatedTrack/interface/IsolatedPixelTrackCandidate.h"
00059 #include "DataFormats/HcalIsolatedTrack/interface/IsolatedPixelTrackCandidateFwd.h"
00060 #include "Calibration/Tools/interface/MinL3AlgoUniv.h"
00061 #include "Calibration/HcalCalibAlgos/src/TCell.h"
00062 #include "CondFormats/HcalObjects/interface/HcalRespCorrs.h"
00063 #include "CondFormats/DataRecord/interface/HcalRespCorrsRcd.h"
00064 
00065 #include "Calibration/HcalCalibAlgos/interface/CommonUsefulStuff.h"
00066 
00067 
00068 #include "TROOT.h"
00069 #include "TH1.h"
00070 #include "TH2.h"
00071 #include "TFile.h"
00072 #include "TTree.h"
00073 
00074 #include "TString.h"
00075 #include "TObject.h"
00076 #include "TObjArray.h"
00077 #include "TClonesArray.h"
00078 #include "TRefArray.h"
00079 #include "TLorentzVector.h"
00080 
00081 
00082 #include <iostream>
00083 #include <fstream>
00084 
00085 using namespace edm;
00086 using namespace std;
00087 using namespace reco;
00088 
00089 //
00090 // class decleration
00091 //
00092 
00093 class HcalIsoTrkAnalyzer : public edm::EDAnalyzer {
00094 public:
00095   explicit HcalIsoTrkAnalyzer(const edm::ParameterSet&);
00096   ~HcalIsoTrkAnalyzer();
00097 
00098   //double getDistInPlaneSimple(const GlobalPoint caloPoint, const GlobalPoint rechitPoint);
00099 
00100 private:
00101   virtual void beginJob() ;
00102   virtual void analyze(const edm::Event&, const edm::EventSetup&);
00103   virtual void endJob() ;
00104   
00105   // ----------member data ---------------------------
00106   
00107  
00108   TrackDetectorAssociator trackAssociator_;
00109   TrackAssociatorParameters parameters_;
00110 
00111   const CaloGeometry* geo;
00112   InputTag hbheLabel_, hoLabel_, eLabel_, trackLabel_, trackLabel1_;
00113 
00114   std::string m_inputTrackLabel;
00115   std::string m_ecalLabel;
00116   std::string m_ebInstance;
00117   std::string m_eeInstance;
00118   std::string m_hcalLabel;
00119   int m_histoFlag;
00120 
00121   double associationConeSize_, calibrationConeSize_;
00122   string AxB_;
00123   bool allowMissingInputs_;
00124   string outputFileName_;
00125 
00126   double trackEta, trackPhi; 
00127   double rvert;
00128   
00129   
00130   int nIterations, MinNTrackHitsBarrel,MinNTECHitsEndcap;
00131   float eventWeight;
00132   double energyMinIso, energyMaxIso;
00133   double energyECALmip, maxPNear;
00134   double hottestHitDistance, EcalCone, EcalConeOuter;
00135 
00136   TFile* rootFile;
00137   TTree* tree;
00138   Float_t targetE;
00139   UInt_t numberOfCells;
00140   UInt_t cell;
00141   Float_t cellEnergy; 
00142   
00143   TClonesArray* cells;
00144   TRefArray* cells3x3;
00145   TRefArray* cellsPF;
00146   UInt_t  eventNumber;
00147   UInt_t  runNumber;
00148   Int_t   iEtaHit;
00149   UInt_t  iPhiHit;
00150 
00151   Float_t xTrkEcal, yTrkEcal, zTrkEcal;
00152   Float_t xTrkHcal, yTrkHcal, zTrkHcal;
00153   Float_t PxTrkHcal, PyTrkHcal, PzTrkHcal;
00154 
00155   Float_t emEnergy, emRingEnergy;
00156 
00157   //    TLorentzVector* exampleP4; 
00158   TLorentzVector* tagJetP4; // dijet
00159   TLorentzVector* probeJetP4; // dijet
00160   Float_t etVetoJet; // dijet
00161   Float_t tagJetEmFrac; // dijet
00162   Float_t probeJetEmFrac; // dijet
00163   
00164   ofstream input_to_L3;
00165   
00166 };
00167 
00168 
00169 HcalIsoTrkAnalyzer::HcalIsoTrkAnalyzer(const edm::ParameterSet& iConfig)
00170 {
00171   
00172   m_ecalLabel = iConfig.getUntrackedParameter<std::string> ("ecalRecHitsLabel","ecalRecHit");
00173   m_ebInstance = iConfig.getUntrackedParameter<std::string> ("ebRecHitsInstance","EcalRecHitsEB");
00174   m_eeInstance = iConfig.getUntrackedParameter<std::string> ("eeRecHitsInstance","EcalRecHitsEE");
00175   m_hcalLabel = iConfig.getUntrackedParameter<std::string> ("hcalRecHitsLabel","hbhereco");
00176  
00177   hbheLabel_= iConfig.getParameter<edm::InputTag>("hbheInput");
00178   hoLabel_=iConfig.getParameter<edm::InputTag>("hoInput");
00179   eLabel_=iConfig.getParameter<edm::InputTag>("eInput");
00180   trackLabel_ = iConfig.getParameter<edm::InputTag>("HcalIsolTrackInput");
00181   trackLabel1_ = iConfig.getParameter<edm::InputTag>("trackInput");
00182   associationConeSize_=iConfig.getParameter<double>("associationConeSize");
00183   allowMissingInputs_=iConfig.getUntrackedParameter<bool>("allowMissingInputs",true);
00184   outputFileName_=iConfig.getParameter<std::string>("outputFileName");
00185 
00186   AxB_=iConfig.getParameter<std::string>("AxB");
00187   calibrationConeSize_=iConfig.getParameter<double>("calibrationConeSize");
00188 
00189   nIterations = iConfig.getParameter<int>("noOfIterations");
00190   eventWeight = iConfig.getParameter<double>("eventWeight");
00191   energyMinIso = iConfig.getParameter<double>("energyMinIso");
00192   energyMaxIso = iConfig.getParameter<double>("energyMaxIso");
00193   energyECALmip = iConfig.getParameter<double>("energyECALmip");
00194   maxPNear = iConfig.getParameter<double>("maxPNear");
00195   MinNTrackHitsBarrel =  iConfig.getParameter<int>("MinNTrackHitsBarrel");
00196   MinNTECHitsEndcap =  iConfig.getParameter<int>("MinNTECHitsEndcap");
00197   hottestHitDistance = iConfig.getParameter<double>("hottestHitDistance");
00198   EcalCone = iConfig.getParameter<double>("EcalCone");
00199   EcalConeOuter = iConfig.getParameter<double>("EcalConeOuter");
00200 
00201   edm::ParameterSet parameters = iConfig.getParameter<edm::ParameterSet>("TrackAssociatorParameters");
00202   parameters_.loadParameters( parameters );
00203   trackAssociator_.useDefaultPropagator();
00204 
00205 }
00206 
00207 HcalIsoTrkAnalyzer::~HcalIsoTrkAnalyzer()
00208 {
00209 }
00210 
00211 // ------------ method called to for each event  ------------
00212 void
00213 HcalIsoTrkAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00214 {
00215   using namespace edm;
00216   using namespace std;
00217 
00218   vector<float> rawEnergyVec;
00219   vector<int> detiphi;
00220   vector<int> detieta;
00221   vector<int> i3i5;
00222   vector<HcalDetId> detidvec;
00223   float calEnergy;
00224 
00225   edm::Handle<reco::TrackCollection> isoProdTracks;
00226   iEvent.getByLabel(trackLabel1_,isoProdTracks);  
00227 
00228   edm::Handle<reco::IsolatedPixelTrackCandidateCollection> isoPixelTracks;
00229   iEvent.getByLabel(trackLabel_,isoPixelTracks);
00230     
00231   edm::Handle<EcalRecHitCollection> ecal;
00232   iEvent.getByLabel(eLabel_,ecal);
00233   const EcalRecHitCollection Hitecal = *(ecal.product());
00234     
00235   edm::Handle<HBHERecHitCollection> hbhe;
00236   iEvent.getByLabel(hbheLabel_,hbhe);
00237   const HBHERecHitCollection Hithbhe = *(hbhe.product());
00238 
00239   edm::ESHandle<CaloGeometry> pG;
00240   iSetup.get<CaloGeometryRecord>().get(pG);
00241   geo = pG.product();
00242 
00243   const CaloSubdetectorGeometry* gHcal = geo->getSubdetectorGeometry(DetId::Hcal,HcalBarrel);
00244   //Note: even though it says HcalBarrel, we actually get the whole Hcal detector geometry!
00245 
00246 
00247 // rof 16.05.2008 start: include the possibility for recalibration (use "recalibrate" label for safety)
00248 /*
00249   edm::ESHandle <HcalRespCorrs> recalibCorrs;
00250   iSetup.get<HcalRespCorrsRcd>().get("recalibrate",recalibCorrs);
00251   const HcalRespCorrs* myRecalib = recalibCorrs.product();
00252 */
00253 // rof end
00254 
00255   parameters_.useEcal = true;
00256   parameters_.useHcal = true;
00257   parameters_.useCalo = false;
00258   parameters_.useMuon = false;
00259   parameters_.dREcal = 0.5;
00260   parameters_.dRHcal = 0.6;  
00261 
00262   if (isoPixelTracks->size()==0) return;
00263 
00264   for (reco::TrackCollection::const_iterator trit=isoProdTracks->begin(); trit!=isoProdTracks->end(); trit++)
00265     {
00266       reco::IsolatedPixelTrackCandidateCollection::const_iterator isoMatched=isoPixelTracks->begin();
00267       bool matched=false;
00268 
00269       //Note: this part needs to be changed: obtain isoPixelTracks from isoProdTracks (should be a way)
00270       for (reco::IsolatedPixelTrackCandidateCollection::const_iterator it = isoPixelTracks->begin(); it!=isoPixelTracks->end(); it++)
00271         { 
00272 
00273           if (abs((trit->pt() - it->pt())/it->pt()) < 0.005 && abs(trit->eta() - it->eta()) < 0.01) 
00274             {
00275               isoMatched=it;
00276               matched=true;
00277               break;
00278             }
00279         }
00280       if (!matched) continue;
00281       
00282       if (trit->hitPattern().numberOfValidHits()<MinNTrackHitsBarrel) continue;
00283       if (fabs(trit->eta())>1.47&&trit->hitPattern().numberOfValidStripTECHits()<MinNTECHitsEndcap) continue;
00284       
00285 
00286       calEnergy = sqrt(trit->px()*trit->px()+trit->py()*trit->py()+trit->pz()*trit->pz()+0.14*0.14);
00287 
00288       trackEta = trit->eta();
00289       trackPhi = trit->phi();
00290       
00291       double corrHCAL = 1.; //another possibility for correction.  - why?
00292 
00293       //      cout << endl << " ISO TRACK E = "<< calEnergy << " ETA = " << trackEta<< " PHI = " << trackPhi <<  " Correction " <<  corrHCAL<< endl;
00294       
00295       rvert = sqrt(trit->vx()*trit->vx()+trit->vy()*trit->vy()+trit->vz()*trit->vz());      
00296       
00297       //Associate track with a calorimeter
00298       TrackDetMatchInfo info = trackAssociator_.associate(iEvent, iSetup,trackAssociator_.getFreeTrajectoryState(iSetup, *trit),parameters_);
00299 
00300         
00301       xTrkHcal=info.trkGlobPosAtHcal.x();
00302       yTrkHcal=info.trkGlobPosAtHcal.y();
00303       zTrkHcal=info.trkGlobPosAtHcal.z();
00304       
00305       xTrkEcal=info.trkGlobPosAtEcal.x();
00306       yTrkEcal=info.trkGlobPosAtEcal.y();
00307       zTrkEcal=info.trkGlobPosAtEcal.z();
00308       
00309       if (xTrkEcal==0 && yTrkEcal==0&& zTrkEcal==0) {cout<<"zero point at Ecal"<<endl; continue;}
00310       if (xTrkHcal==0 && yTrkHcal==0&& zTrkHcal==0) {cout<<"zero point at Hcal"<<endl; continue;}       
00311       
00312       GlobalVector trackMomAtEcal = info.trkMomAtEcal;
00313       GlobalVector trackMomAtHcal = info.trkMomAtHcal;
00314         
00315       PxTrkHcal = trackMomAtHcal.x();
00316       PyTrkHcal = trackMomAtHcal.y();
00317       PzTrkHcal = trackMomAtHcal.z();
00318       
00319       //PxTrkHcal=0;
00320       //PyTrkHcal=0;
00321       //PzTrkHcal=0;
00322 
00323       GlobalPoint gPointEcal(xTrkEcal,yTrkEcal,zTrkEcal);
00324       GlobalPoint gPointHcal(xTrkHcal,yTrkHcal,zTrkHcal);
00325       
00326       //        emEnergy = isoMatched->energyIn();
00327       emEnergy =  ecalEnergyInCone(gPointEcal, EcalCone, Hitecal, geo);
00328       
00329       emRingEnergy = ecalEnergyInCone(gPointEcal, EcalConeOuter, Hitecal, geo) - ecalEnergyInCone(gPointEcal, EcalCone, Hitecal, geo);
00330 
00331       
00332         int iphitrue = -10;
00333         int ietatrue = 100;
00334         
00335         const HcalDetId tempId = gHcal->getClosestCell(gPointHcal);
00336         ietatrue = tempId.ieta();
00337         iphitrue = tempId.iphi();
00338 
00339 
00340       //container for used recHits
00341       std::vector<int> usedHits; 
00342       //      
00343       //clear usedHits
00344       usedHits.clear();
00345 
00346 
00347       // Find Hcal RecHit with maximum energy and collect other information
00348       MaxHit_struct MaxHit;
00349       MaxHit.hitenergy=-100;
00350           
00351 
00352       for (HBHERecHitCollection::const_iterator hhit=Hithbhe.begin(); hhit!=Hithbhe.end(); hhit++) 
00353         {
00354           
00355           //check that this hit was not considered before and push it into usedHits
00356           bool hitIsUsed=false;
00357           int hitHashedIndex=hhit->id().hashed_index();
00358           for (uint32_t i=0; i<usedHits.size(); i++)
00359             {
00360               if (usedHits[i]==hitHashedIndex) hitIsUsed=true;
00361             }
00362           if (hitIsUsed) continue;
00363           usedHits.push_back(hitHashedIndex);
00364           //
00365 
00366           // rof 16.05.2008 start: include the possibility for recalibration
00367           float recal = 1;
00368           // rof end
00369 
00370           GlobalPoint pos = geo->getPosition(hhit->detid());
00371 
00372           int iphihitm  = (hhit->id()).iphi();
00373           int ietahitm  = (hhit->id()).ieta();
00374           int depthhit = (hhit->id()).depth();
00375           double enehit = hhit->energy() * recal;
00376           
00377           if (depthhit!=1) continue;
00378            
00379 
00380           double distAtHcal =  getDistInPlaneTrackDir(gPointHcal, trackMomAtHcal, pos);
00381           //double distAtHcal =  getDistInPlaneSimple(gPointHcal, pos);
00382 
00383           //if(dr<associationConeSize_)          
00384           if(distAtHcal < associationConeSize_) 
00385             {
00386               for (HBHERecHitCollection::const_iterator hhit2=Hithbhe.begin(); hhit2!=Hithbhe.end(); hhit2++) 
00387                 {
00388                   int iphihitm2  = (hhit2->id()).iphi();
00389                   int ietahitm2  = (hhit2->id()).ieta();
00390                   int depthhit2 = (hhit2->id()).depth();
00391                   double enehit2 = hhit2->energy() * recal;
00392                   
00393                   if ( iphihitm==iphihitm2 && ietahitm==ietahitm2  && depthhit!=depthhit2){
00394                     
00395                     enehit = enehit+enehit2;
00396                   }
00397                 }
00398               
00399               if(enehit > MaxHit.hitenergy) 
00400                 {
00401                   MaxHit.hitenergy =  enehit;
00402                   MaxHit.ietahitm   = (hhit->id()).ieta();
00403                   MaxHit.iphihitm   = (hhit->id()).iphi();
00404                   MaxHit.depthhit  = (hhit->id()).depth();
00405                   MaxHit.dr   = distAtHcal;
00406 
00407                   MaxHit.posMax = geo->getPosition(hhit->detid());
00408                   
00409                 }
00410             }
00411         }
00412       
00413 
00414       Bool_t passCuts = kFALSE;
00415       if(calEnergy > energyMinIso && calEnergy < energyMaxIso && emEnergy < energyECALmip && 
00416          isoMatched->maxPtPxl() < maxPNear && abs(MaxHit.ietahitm)<30 && MaxHit.hitenergy > 0. && 
00417           MaxHit.dr < hottestHitDistance && emRingEnergy<8.){ passCuts = kTRUE; }
00418       
00419       
00420       if(AxB_=="5x5" || AxB_=="3x3" || AxB_=="7x7"|| AxB_=="Cone")
00421         {
00422 
00423           //clear usedHits
00424           usedHits.clear();
00425           //
00426 
00427           for (HBHERecHitCollection::const_iterator hhit=Hithbhe.begin(); hhit!=Hithbhe.end(); hhit++) 
00428             {
00429 
00430               //check that this hit was not considered before and push it into usedHits
00431               bool hitIsUsed=false;
00432               int hitHashedIndex=hhit->id().hashed_index();
00433               for (uint32_t i=0; i<usedHits.size(); i++)
00434                 {
00435                   if (usedHits[i]==hitHashedIndex) hitIsUsed=true;
00436                 }
00437               if (hitIsUsed) 
00438                 {
00439                   //cout<<"Hit is Used!   ieta: "<< (hhit->id()).ieta()<<"  iphi: "<<(hhit->id()).iphi()<<"  depth: "<<(hhit->id()).depth()<<"  hashed_index: "<<hitHashedIndex<<endl;
00440                   continue;}
00441               
00442               usedHits.push_back(hitHashedIndex);
00443               //
00444 
00445               int DIETA = 100;
00446               if(MaxHit.ietahitm*(hhit->id()).ieta()>0)
00447                 {
00448                   DIETA = MaxHit.ietahitm - (hhit->id()).ieta();
00449                 }
00450               if(MaxHit.ietahitm*(hhit->id()).ieta()<0)
00451                 {
00452                   DIETA = MaxHit.ietahitm - (hhit->id()).ieta();
00453                   DIETA = DIETA>0 ? DIETA-1 : DIETA+1; 
00454                 }
00455               
00456               int DIPHI = abs(MaxHit.iphihitm - (hhit->id()).iphi());
00457               DIPHI = DIPHI>36 ? 72-DIPHI : DIPHI;
00458               /*AP DIPHI = DIPHI<-36 ? 72+DIPHI : DIPHI; */
00459               
00460               int numbercell=0;
00461               if(AxB_=="3x3") numbercell = 1;
00462               if(AxB_=="5x5") numbercell = 2;
00463               if(AxB_=="7x7") numbercell = 3;
00464               if(AxB_=="Cone") numbercell = 1000;
00465               
00466               if( abs(DIETA)<=numbercell && (abs(DIPHI)<=numbercell || ( abs(MaxHit.ietahitm)>=20 && abs(DIPHI)<=numbercell+1)) )  {
00467                 
00468                 // rof 16.05.2008 start: include the possibility for recalibration
00469                 float recal = 1;
00470                 
00471                 int iii3i5 = 0;
00472                 
00473                 const GlobalPoint pos2 = geo->getPosition(hhit->detid());               
00474                 
00475                 if(passCuts){
00476                   
00477                   if(AxB_=="5x5" || AxB_=="3x3" || AxB_=="7x7") {
00478                     
00479                     rawEnergyVec.push_back(hhit->energy() * recal * corrHCAL);
00480                     detidvec.push_back(hhit->id());
00481                     detiphi.push_back((hhit->id()).iphi());
00482                     detieta.push_back((hhit->id()).ieta());
00483                     i3i5.push_back(iii3i5);
00484                     
00485                   }
00486                   
00487                   if (AxB_=="Cone" && getDistInPlaneTrackDir(gPointHcal, trackMomAtHcal, pos2) < calibrationConeSize_) {
00488                     //if (AxB_=="Cone" && getDistInPlaneSimple(gPointHcal,pos2) < calibrationConeSize_) {
00489                     
00490                     rawEnergyVec.push_back(hhit->energy() * recal * corrHCAL);
00491                     detidvec.push_back(hhit->id());
00492                     detiphi.push_back((hhit->id()).iphi());
00493                     detieta.push_back((hhit->id()).ieta());
00494                     i3i5.push_back(iii3i5);
00495                     
00496                   }
00497                   
00498                 }
00499               }
00500             }
00501         }
00502       
00503       if(AxB_!="3x3" && AxB_!="5x5" && AxB_!="7x7" && AxB_!="Cone") LogWarning(" AxB ")<<"   Not supported: "<< AxB_;
00504       
00505       if(passCuts){
00506         
00507         input_to_L3 << rawEnergyVec.size() << "   " << calEnergy;
00508         
00509         
00510         for (unsigned int i=0; i<rawEnergyVec.size(); i++)
00511           {
00512             input_to_L3 << "   " << rawEnergyVec.at(i) << "   " << detidvec.at(i).rawId() ;        
00513             
00514           }
00515         input_to_L3 <<endl;
00516         
00517         eventNumber = iEvent.id().event();
00518         runNumber = iEvent.id().run();
00519         iEtaHit = ietatrue;
00520         iPhiHit = iphitrue;
00521 
00522         numberOfCells=rawEnergyVec.size();
00523         targetE = calEnergy;
00524         
00525         for (unsigned int ia=0; ia<numberOfCells; ++ia) {
00526           cellEnergy = rawEnergyVec.at(ia);
00527           cell = detidvec.at(ia).rawId();
00528           
00529           new((*cells)[ia])  TCell(cell, cellEnergy);
00530           
00531 
00532         } 
00533         
00534         tree->Fill();
00535         
00536         cells->Clear();   
00537         
00538       }
00539       
00540       rawEnergyVec.clear();
00541       detidvec.clear();
00542       detiphi.clear();
00543       detieta.clear();
00544       i3i5.clear();
00545 
00546       try {
00547         Handle<HORecHitCollection> ho;
00548         iEvent.getByLabel(hoLabel_,ho);
00549         const HORecHitCollection Hitho = *(ho.product());
00550         
00551         //clear usedHits
00552         usedHits.clear();
00553         //
00554         
00555         for(HORecHitCollection::const_iterator hoItr=Hitho.begin(); hoItr!=Hitho.end(); hoItr++)
00556           {
00557 
00558             //check that this hit was not considered before and push it into usedHits
00559             bool hitIsUsed=false;
00560             int hitHashedIndex=hoItr->id().hashed_index();
00561             for (uint32_t i=0; i<usedHits.size(); i++)
00562               {
00563                 if (usedHits[i]==hitHashedIndex) hitIsUsed=true;
00564               }
00565             if (hitIsUsed) continue;
00566 
00567             usedHits.push_back(hitHashedIndex);
00568 
00569             /*AP
00570             GlobalPoint pos = geo->getPosition(hoItr->detid());
00571             double phihit = pos.phi();
00572             double etahit = pos.eta();
00573             
00574             int iphihitm = (hoItr->id()).iphi();
00575             int ietahitm = (hoItr->id()).ieta();
00576             int depthhit = (hoItr->id()).depth();
00577             
00578             double dphi = fabs(trackPhi - phihit); 
00579             if(dphi > 4.*atan(1.)) dphi = 8.*atan(1.) - dphi;
00580             double deta = fabs(trackEta - etahit); 
00581             double dr = sqrt(dphi*dphi + deta*deta);
00582             */
00583             
00584           }
00585       } catch (cms::Exception& e) { // can't find it!
00586         if (!allowMissingInputs_) throw e;
00587       }
00588     }
00589 }
00590     
00591       
00592 
00593 // ------------ method called once each job just before starting event loop  ------------
00594 void 
00595 HcalIsoTrkAnalyzer::beginJob()
00596 {
00597 
00598   //  MyL3Algo = new MinL3AlgoUniv<HcalDetId>(eventWeight);
00599 
00600     input_to_L3.open("input_to_l3.txt");
00601 
00602     rootFile = new TFile("rootFile.root", "RECREATE");
00603     tree = new TTree("hcalCalibTree", "Tree for IsoTrack Calibration");  
00604     cells = new TClonesArray("TCell", 10000);
00605 //    cells3x3 = new TRefArray;
00606 //    cellsPF = new TRefArray;
00607 //    exampleP4 = new TLorentzVector();
00608     tagJetP4 = new TLorentzVector(); // dijet
00609     probeJetP4 = new TLorentzVector();  // dijet   
00610     
00611     tree->Branch("cells", &cells, 64000, 0);
00612     tree->Branch("targetE", &targetE, "targetE/F");
00613     tree->Branch("emEnergy", &emEnergy, "emEnergy/F");
00614 
00615     tree->Branch("PxTrkHcal", &PxTrkHcal, "PxTrkHcal/F");
00616     tree->Branch("PyTrkHcal", &PyTrkHcal, "PyTrkHcal/F");
00617     tree->Branch("PzTrkHcal", &PzTrkHcal, "PzTrkHcal/F");
00618 
00619 
00620     tree->Branch("xTrkHcal", &xTrkHcal, "xTrkHcal/F");
00621     tree->Branch("yTrkHcal", &yTrkHcal, "yTrkHcal/F");
00622     tree->Branch("zTrkHcal", &zTrkHcal, "zTrkHcal/F");
00623 
00624     tree->Branch("iEtaHit", &iEtaHit, "iEtaHit/I");
00625     tree->Branch("iPhiHit", &iPhiHit, "iPhiHit/i");
00626     tree->Branch("eventNumber", &eventNumber, "eventNumber/i");
00627     tree->Branch("runNumber", &runNumber, "runNumber/i");
00628 
00629     tree->Branch("tagJetP4", "TLorentzVector", &tagJetP4); // dijet
00630     tree->Branch("probeJetP4", "TLorentzVector", &probeJetP4); // dijet
00631     tree->Branch("etVetoJet", &etVetoJet, "etVetoJet/F"); // dijet
00632     tree->Branch("tagJetEmFrac", &tagJetEmFrac,"tagJetEmFrac/F"); // dijet
00633     tree->Branch("probeJetEmFrac", &probeJetEmFrac,"probeJetEmFrac/F"); // dijet
00634 
00635 }
00636 
00637 // ------------ method called once each job just after ending the event loop  ------------
00638 void 
00639 HcalIsoTrkAnalyzer::endJob() {
00640 
00641     input_to_L3.close();
00642 
00643     rootFile->Write();
00644     rootFile->Close();
00645 
00646     if (cells) delete cells;
00647 //    if (cells3x3) delete cells3x3;
00648 //    if (cellsPF) delete cellsPF;
00649 //    if (exampleP4) delete exampleP4;
00650     if (tagJetP4) delete tagJetP4; // dijet
00651     if (probeJetP4) delete probeJetP4; // dijet
00652 
00653 }
00654 
00655 //define this as a plug-in
00656 DEFINE_FWK_MODULE(HcalIsoTrkAnalyzer);
00657