CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/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.27 2012/11/12 21:08:18 dlange 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 trackMomAtHcal = info.trkMomAtHcal;
00313         
00314       PxTrkHcal = trackMomAtHcal.x();
00315       PyTrkHcal = trackMomAtHcal.y();
00316       PzTrkHcal = trackMomAtHcal.z();
00317       
00318       //PxTrkHcal=0;
00319       //PyTrkHcal=0;
00320       //PzTrkHcal=0;
00321 
00322       GlobalPoint gPointEcal(xTrkEcal,yTrkEcal,zTrkEcal);
00323       GlobalPoint gPointHcal(xTrkHcal,yTrkHcal,zTrkHcal);
00324       
00325       //        emEnergy = isoMatched->energyIn();
00326       emEnergy =  ecalEnergyInCone(gPointEcal, EcalCone, Hitecal, geo);
00327       
00328       emRingEnergy = ecalEnergyInCone(gPointEcal, EcalConeOuter, Hitecal, geo) - ecalEnergyInCone(gPointEcal, EcalCone, Hitecal, geo);
00329 
00330       
00331         int iphitrue = -10;
00332         int ietatrue = 100;
00333         
00334         const HcalDetId tempId = gHcal->getClosestCell(gPointHcal);
00335         ietatrue = tempId.ieta();
00336         iphitrue = tempId.iphi();
00337 
00338 
00339       //container for used recHits
00340         std::vector<DetId> usedHits; 
00341       //      
00342       //clear usedHits
00343       usedHits.clear();
00344 
00345 
00346       // Find Hcal RecHit with maximum energy and collect other information
00347       MaxHit_struct MaxHit;
00348       MaxHit.hitenergy=-100;
00349           
00350 
00351       for (HBHERecHitCollection::const_iterator hhit=Hithbhe.begin(); hhit!=Hithbhe.end(); hhit++) 
00352         {
00353           
00354           //check that this hit was not considered before and push it into usedHits
00355           bool hitIsUsed=false;
00356           DetId hitId=hhit->id();
00357           for (uint32_t i=0; i<usedHits.size(); i++)
00358             {
00359               if (usedHits[i]==hitId) hitIsUsed=true;
00360             }
00361           if (hitIsUsed) continue;
00362           usedHits.push_back(hitId);
00363           //
00364 
00365           // rof 16.05.2008 start: include the possibility for recalibration
00366           float recal = 1;
00367           // rof end
00368 
00369           GlobalPoint pos = geo->getPosition(hhit->detid());
00370 
00371           int iphihitm  = (hhit->id()).iphi();
00372           int ietahitm  = (hhit->id()).ieta();
00373           int depthhit = (hhit->id()).depth();
00374           double enehit = hhit->energy() * recal;
00375           
00376           if (depthhit!=1) continue;
00377            
00378 
00379           double distAtHcal =  getDistInPlaneTrackDir(gPointHcal, trackMomAtHcal, pos);
00380           //double distAtHcal =  getDistInPlaneSimple(gPointHcal, pos);
00381 
00382           //if(dr<associationConeSize_)          
00383           if(distAtHcal < associationConeSize_) 
00384             {
00385               for (HBHERecHitCollection::const_iterator hhit2=Hithbhe.begin(); hhit2!=Hithbhe.end(); hhit2++) 
00386                 {
00387                   int iphihitm2  = (hhit2->id()).iphi();
00388                   int ietahitm2  = (hhit2->id()).ieta();
00389                   int depthhit2 = (hhit2->id()).depth();
00390                   double enehit2 = hhit2->energy() * recal;
00391                   
00392                   if ( iphihitm==iphihitm2 && ietahitm==ietahitm2  && depthhit!=depthhit2){
00393                     
00394                     enehit = enehit+enehit2;
00395                   }
00396                 }
00397               
00398               if(enehit > MaxHit.hitenergy) 
00399                 {
00400                   MaxHit.hitenergy =  enehit;
00401                   MaxHit.ietahitm   = (hhit->id()).ieta();
00402                   MaxHit.iphihitm   = (hhit->id()).iphi();
00403                   MaxHit.depthhit  = (hhit->id()).depth();
00404                   MaxHit.dr   = distAtHcal;
00405 
00406                   MaxHit.posMax = geo->getPosition(hhit->detid());
00407                   
00408                 }
00409             }
00410         }
00411       
00412 
00413       Bool_t passCuts = kFALSE;
00414       if(calEnergy > energyMinIso && calEnergy < energyMaxIso && emEnergy < energyECALmip && 
00415          isoMatched->maxPtPxl() < maxPNear && abs(MaxHit.ietahitm)<30 && MaxHit.hitenergy > 0. && 
00416           MaxHit.dr < hottestHitDistance && emRingEnergy<8.){ passCuts = kTRUE; }
00417       
00418       
00419       if(AxB_=="5x5" || AxB_=="3x3" || AxB_=="7x7"|| AxB_=="Cone")
00420         {
00421 
00422           //clear usedHits
00423           usedHits.clear();
00424           //
00425 
00426           for (HBHERecHitCollection::const_iterator hhit=Hithbhe.begin(); hhit!=Hithbhe.end(); hhit++) 
00427             {
00428 
00429               //check that this hit was not considered before and push it into usedHits
00430               bool hitIsUsed=false;
00431               DetId hitId=hhit->id();
00432               for (uint32_t i=0; i<usedHits.size(); i++)
00433                 {
00434                   if (usedHits[i]==hitId) hitIsUsed=true;
00435                 }
00436               if (hitIsUsed) 
00437                 {
00438                   //cout<<"Hit is Used!   ieta: "<< (hhit->id()).ieta()<<"  iphi: "<<(hhit->id()).iphi()<<"  depth: "<<(hhit->id()).depth()<<"  hashed_index: "<<hitHashedIndex<<endl;
00439                   continue;}
00440               
00441               usedHits.push_back(hitId);
00442               //
00443 
00444               int DIETA = 100;
00445               if(MaxHit.ietahitm*(hhit->id()).ieta()>0)
00446                 {
00447                   DIETA = MaxHit.ietahitm - (hhit->id()).ieta();
00448                 }
00449               if(MaxHit.ietahitm*(hhit->id()).ieta()<0)
00450                 {
00451                   DIETA = MaxHit.ietahitm - (hhit->id()).ieta();
00452                   DIETA = DIETA>0 ? DIETA-1 : DIETA+1; 
00453                 }
00454               
00455               int DIPHI = abs(MaxHit.iphihitm - (hhit->id()).iphi());
00456               DIPHI = DIPHI>36 ? 72-DIPHI : DIPHI;
00457               /*AP DIPHI = DIPHI<-36 ? 72+DIPHI : DIPHI; */
00458               
00459               int numbercell=0;
00460               if(AxB_=="3x3") numbercell = 1;
00461               if(AxB_=="5x5") numbercell = 2;
00462               if(AxB_=="7x7") numbercell = 3;
00463               if(AxB_=="Cone") numbercell = 1000;
00464               
00465               if( abs(DIETA)<=numbercell && (abs(DIPHI)<=numbercell || ( abs(MaxHit.ietahitm)>=20 && abs(DIPHI)<=numbercell+1)) )  {
00466                 
00467                 // rof 16.05.2008 start: include the possibility for recalibration
00468                 float recal = 1;
00469                 
00470                 int iii3i5 = 0;
00471                 
00472                 const GlobalPoint pos2 = geo->getPosition(hhit->detid());               
00473                 
00474                 if(passCuts){
00475                   
00476                   if(AxB_=="5x5" || AxB_=="3x3" || AxB_=="7x7") {
00477                     
00478                     rawEnergyVec.push_back(hhit->energy() * recal * corrHCAL);
00479                     detidvec.push_back(hhit->id());
00480                     detiphi.push_back((hhit->id()).iphi());
00481                     detieta.push_back((hhit->id()).ieta());
00482                     i3i5.push_back(iii3i5);
00483                     
00484                   }
00485                   
00486                   if (AxB_=="Cone" && getDistInPlaneTrackDir(gPointHcal, trackMomAtHcal, pos2) < calibrationConeSize_) {
00487                     //if (AxB_=="Cone" && getDistInPlaneSimple(gPointHcal,pos2) < calibrationConeSize_) {
00488                     
00489                     rawEnergyVec.push_back(hhit->energy() * recal * corrHCAL);
00490                     detidvec.push_back(hhit->id());
00491                     detiphi.push_back((hhit->id()).iphi());
00492                     detieta.push_back((hhit->id()).ieta());
00493                     i3i5.push_back(iii3i5);
00494                     
00495                   }
00496                   
00497                 }
00498               }
00499             }
00500         }
00501       
00502       if(AxB_!="3x3" && AxB_!="5x5" && AxB_!="7x7" && AxB_!="Cone") LogWarning(" AxB ")<<"   Not supported: "<< AxB_;
00503       
00504       if(passCuts){
00505         
00506         input_to_L3 << rawEnergyVec.size() << "   " << calEnergy;
00507         
00508         
00509         for (unsigned int i=0; i<rawEnergyVec.size(); i++)
00510           {
00511             input_to_L3 << "   " << rawEnergyVec.at(i) << "   " << detidvec.at(i).rawId() ;        
00512             
00513           }
00514         input_to_L3 <<endl;
00515         
00516         eventNumber = iEvent.id().event();
00517         runNumber = iEvent.id().run();
00518         iEtaHit = ietatrue;
00519         iPhiHit = iphitrue;
00520 
00521         numberOfCells=rawEnergyVec.size();
00522         targetE = calEnergy;
00523         
00524         for (unsigned int ia=0; ia<numberOfCells; ++ia) {
00525           cellEnergy = rawEnergyVec.at(ia);
00526           cell = detidvec.at(ia).rawId();
00527           
00528           new((*cells)[ia])  TCell(cell, cellEnergy);
00529           
00530 
00531         } 
00532         
00533         tree->Fill();
00534         
00535         cells->Clear();   
00536         
00537       }
00538       
00539       rawEnergyVec.clear();
00540       detidvec.clear();
00541       detiphi.clear();
00542       detieta.clear();
00543       i3i5.clear();
00544 
00545       try {
00546         Handle<HORecHitCollection> ho;
00547         iEvent.getByLabel(hoLabel_,ho);
00548         const HORecHitCollection Hitho = *(ho.product());
00549         
00550         //clear usedHits
00551         usedHits.clear();
00552         //
00553         
00554         for(HORecHitCollection::const_iterator hoItr=Hitho.begin(); hoItr!=Hitho.end(); hoItr++)
00555           {
00556 
00557             //check that this hit was not considered before and push it into usedHits
00558             bool hitIsUsed=false;
00559             DetId hitId=hoItr->id();
00560             for (uint32_t i=0; i<usedHits.size(); i++)
00561               {
00562                 if (usedHits[i]==hitId) hitIsUsed=true;
00563               }
00564             if (hitIsUsed) continue;
00565 
00566             usedHits.push_back(hitId);
00567 
00568             /*AP
00569             GlobalPoint pos = geo->getPosition(hoItr->detid());
00570             double phihit = pos.phi();
00571             double etahit = pos.eta();
00572             
00573             int iphihitm = (hoItr->id()).iphi();
00574             int ietahitm = (hoItr->id()).ieta();
00575             int depthhit = (hoItr->id()).depth();
00576             
00577             double dphi = fabs(trackPhi - phihit); 
00578             if(dphi > 4.*atan(1.)) dphi = 8.*atan(1.) - dphi;
00579             double deta = fabs(trackEta - etahit); 
00580             double dr = sqrt(dphi*dphi + deta*deta);
00581             */
00582             
00583           }
00584       } catch (cms::Exception& e) { // can't find it!
00585         if (!allowMissingInputs_) throw e;
00586       }
00587     }
00588 }
00589     
00590       
00591 
00592 // ------------ method called once each job just before starting event loop  ------------
00593 void 
00594 HcalIsoTrkAnalyzer::beginJob()
00595 {
00596 
00597   //  MyL3Algo = new MinL3AlgoUniv<HcalDetId>(eventWeight);
00598 
00599     input_to_L3.open("input_to_l3.txt");
00600 
00601     rootFile = new TFile("rootFile.root", "RECREATE");
00602     tree = new TTree("hcalCalibTree", "Tree for IsoTrack Calibration");  
00603     cells = new TClonesArray("TCell", 10000);
00604 //    cells3x3 = new TRefArray;
00605 //    cellsPF = new TRefArray;
00606 //    exampleP4 = new TLorentzVector();
00607     tagJetP4 = new TLorentzVector(); // dijet
00608     probeJetP4 = new TLorentzVector();  // dijet   
00609     
00610     tree->Branch("cells", &cells, 64000, 0);
00611     tree->Branch("targetE", &targetE, "targetE/F");
00612     tree->Branch("emEnergy", &emEnergy, "emEnergy/F");
00613 
00614     tree->Branch("PxTrkHcal", &PxTrkHcal, "PxTrkHcal/F");
00615     tree->Branch("PyTrkHcal", &PyTrkHcal, "PyTrkHcal/F");
00616     tree->Branch("PzTrkHcal", &PzTrkHcal, "PzTrkHcal/F");
00617 
00618 
00619     tree->Branch("xTrkHcal", &xTrkHcal, "xTrkHcal/F");
00620     tree->Branch("yTrkHcal", &yTrkHcal, "yTrkHcal/F");
00621     tree->Branch("zTrkHcal", &zTrkHcal, "zTrkHcal/F");
00622 
00623     tree->Branch("iEtaHit", &iEtaHit, "iEtaHit/I");
00624     tree->Branch("iPhiHit", &iPhiHit, "iPhiHit/i");
00625     tree->Branch("eventNumber", &eventNumber, "eventNumber/i");
00626     tree->Branch("runNumber", &runNumber, "runNumber/i");
00627 
00628     tree->Branch("tagJetP4", "TLorentzVector", &tagJetP4); // dijet
00629     tree->Branch("probeJetP4", "TLorentzVector", &probeJetP4); // dijet
00630     tree->Branch("etVetoJet", &etVetoJet, "etVetoJet/F"); // dijet
00631     tree->Branch("tagJetEmFrac", &tagJetEmFrac,"tagJetEmFrac/F"); // dijet
00632     tree->Branch("probeJetEmFrac", &probeJetEmFrac,"probeJetEmFrac/F"); // dijet
00633 
00634 }
00635 
00636 // ------------ method called once each job just after ending the event loop  ------------
00637 void 
00638 HcalIsoTrkAnalyzer::endJob() {
00639 
00640     input_to_L3.close();
00641 
00642     rootFile->Write();
00643     rootFile->Close();
00644 
00645     if (cells) delete cells;
00646 //    if (cells3x3) delete cells3x3;
00647 //    if (cellsPF) delete cellsPF;
00648 //    if (exampleP4) delete exampleP4;
00649     if (tagJetP4) delete tagJetP4; // dijet
00650     if (probeJetP4) delete probeJetP4; // dijet
00651 
00652 }
00653 
00654 //define this as a plug-in
00655 DEFINE_FWK_MODULE(HcalIsoTrkAnalyzer);
00656