CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/Calibration/HcalCalibAlgos/src/HcalIsoTrkAnalyzer.cc

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