00001 #include "Calibration/EcalAlCaRecoProducers/interface/AlCaPi0BasicClusterRecHitsProducer.h"
00002 #include "DataFormats/EgammaReco/interface/BasicCluster.h"
00003 #include "DataFormats/EgammaReco/interface/BasicClusterFwd.h"
00004 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00005 #include "DataFormats/DetId/interface/DetId.h"
00006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00007
00008 AlCaPi0BasicClusterRecHitsProducer::AlCaPi0BasicClusterRecHitsProducer(const edm::ParameterSet& iConfig)
00009 {
00010 ecalHitsProducer_ = iConfig.getParameter< std::string > ("ecalRecHitsProducer");
00011 barrelHits_ = iConfig.getParameter< std::string > ("barrelHitCollection");
00012 pi0BarrelHits_ = iConfig.getParameter< std::string > ("pi0BarrelHitCollection");
00013 islandBCProd_ = iConfig.getParameter< std::string > ("islandBCProd");
00014 islandBCColl_ = iConfig.getParameter< std::string > ("islandBCColl");
00015
00016 gammaCandEtaSize_ = iConfig.getParameter<int> ("gammaCandEtaSize");
00017 gammaCandPhiSize_ = iConfig.getParameter<int> ("gammaCandPhiSize");
00018 if ( gammaCandPhiSize_ % 2 == 0 || gammaCandEtaSize_ % 2 == 0)
00019 edm::LogError("AlCaPi0BasicClusterRecHitsProducerError") << "Size of eta/phi should be odd numbers";
00020
00021 selePtGammaOne_ = iConfig.getParameter<double> ("selePtGammaOne");
00022 selePtGammaTwo_ = iConfig.getParameter<double> ("selePtGammaTwo");
00023 selePtPi0_ = iConfig.getParameter<double> ("selePtPi0");
00024 seleMinvMaxPi0_ = iConfig.getParameter<double> ("seleMinvMaxPi0");
00025 seleMinvMinPi0_ = iConfig.getParameter<double> ("seleMinvMinPi0");
00026
00027
00028
00029 produces< EBRecHitCollection >(pi0BarrelHits_);
00030 }
00031
00032
00033 AlCaPi0BasicClusterRecHitsProducer::~AlCaPi0BasicClusterRecHitsProducer()
00034 {
00035
00036 TimingReport::current()->dump(std::cout);
00037
00038 }
00039
00040
00041
00042 void
00043 AlCaPi0BasicClusterRecHitsProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00044 {
00045 using namespace edm;
00046 using namespace std;
00047
00048
00049 const std::string category = "AlCaPi0BasicClusterRecHitsProducer";
00050 TimerStack timers;
00051 string timerName = category + "::Total";
00052 timers.push(timerName);
00053
00054
00055
00056 Handle<EBRecHitCollection> barrelRecHitsHandle;
00057
00058 iEvent.getByLabel(ecalHitsProducer_,barrelHits_,barrelRecHitsHandle);
00059 if (!barrelRecHitsHandle.isValid()) {
00060 LogDebug("") << "AlCaPi0RecHitsProducer: Error! can't get product!" << std::endl;
00061 }
00062
00063 recHitsEB_map = new std::map<DetId, EcalRecHit>();
00064
00065
00066
00067 std::auto_ptr< EBRecHitCollection > pi0EBRecHitCollection( new EBRecHitCollection );
00068
00069
00070 EBRecHitCollection::const_iterator itb;
00071 cout<< " EB RecHits #: "<<barrelRecHitsHandle->size()<<endl;
00072 for (itb=barrelRecHitsHandle->begin(); itb!=barrelRecHitsHandle->end(); itb++) {
00073
00074 std::pair<DetId, EcalRecHit> map_entry(itb->id(), *itb);
00075 recHitsEB_map->insert(map_entry);
00076
00077 }
00078
00079 timerName = category + "::readEBRecHitsCollection";
00080 timers.push(timerName);
00081
00082
00083
00084
00085
00086 static const int MAXBCEB = 200;
00087 int nIslandBCEB;
00088 float eIslandBCEB[MAXBCEB];
00089 float etIslandBCEB[MAXBCEB];
00090 float etaIslandBCEB[MAXBCEB];
00091 float phiIslandBCEB[MAXBCEB];
00092
00093 nIslandBCEB=0;
00094 for(int i=0; i<MAXBCEB; i++){
00095 eIslandBCEB[i] = 0;
00096 etIslandBCEB[i] = 0;
00097 etaIslandBCEB[i] = 0;
00098 phiIslandBCEB[i] = 0;
00099 }
00100
00101 static const int MAXPI0 = 20;
00102 int npi0=0;
00103 int BC1[MAXPI0],BC2[MAXPI0];
00104 for(int i=0; i<MAXPI0; i++){
00105 BC1[i]=0;
00106 BC2[i]=0;
00107 }
00108
00109 Handle<reco::BasicClusterCollection> pIslandBarrelBasicClusters;
00110 iEvent.getByLabel(islandBCProd_, islandBCColl_, pIslandBarrelBasicClusters);
00111 const reco::BasicClusterCollection* islandBarrelBasicClusters = pIslandBarrelBasicClusters.product();
00112 cout << " island Basic Clusters # "<< islandBarrelBasicClusters->size() <<endl;
00113
00114 for(reco::BasicClusterCollection::const_iterator aClus = islandBarrelBasicClusters->begin();
00115 aClus != islandBarrelBasicClusters->end(); aClus++) {
00116
00117
00118
00119
00120
00121 float theta = 2. * atan(exp(-aClus->position().eta()));
00122 float p0x = aClus->energy() * sin(theta) * cos(aClus->position().phi());
00123 float p0y = aClus->energy() * sin(theta) * sin(aClus->position().phi());
00124 float p0z = aClus->energy() * cos(theta);
00125 float et = sqrt( p0x*p0x + p0y*p0y);
00126
00127
00128
00129 eIslandBCEB[nIslandBCEB] = aClus->energy();
00130 etIslandBCEB[nIslandBCEB] = et;
00131 etaIslandBCEB[nIslandBCEB] = aClus->position().eta();
00132 phiIslandBCEB[nIslandBCEB] = aClus->position().phi();
00133
00134 nIslandBCEB++;
00135 }
00136
00137 timerName = category + "::readIslandBasicClustersCollection";
00138 timers.push(timerName);
00139
00140
00141
00142
00143
00144 if (nIslandBCEB > 1)
00145 {
00146 for(Int_t i=0 ; i<nIslandBCEB ; i++)
00147 {
00148 for(Int_t j=i+1 ; j<nIslandBCEB ; j++)
00149 {
00150
00151 if( etIslandBCEB[i]>selePtGammaOne_ && etIslandBCEB[j]>selePtGammaTwo_)
00152 {
00153
00154 float theta_0 = 2. * atan(exp(-etaIslandBCEB[i]));
00155 float theta_1 = 2. * atan(exp(-etaIslandBCEB[j]));
00156
00157 float p0x = eIslandBCEB[i] * sin(theta_0) * cos(phiIslandBCEB[i]);
00158 float p1x = eIslandBCEB[j] * sin(theta_1) * cos(phiIslandBCEB[j]);
00159
00160 float p0y = eIslandBCEB[i] * sin(theta_0) * sin(phiIslandBCEB[i]);
00161 float p1y = eIslandBCEB[j] * sin(theta_1) * sin(phiIslandBCEB[j]);
00162 float p0z = eIslandBCEB[i] * cos(theta_0);
00163 float p1z = eIslandBCEB[j] * cos(theta_1);
00164
00165
00166
00167 float pt_pi0 = sqrt( (p0x+p1x)*(p0x+p1x) + (p0y+p1y)*(p0y+p1y));
00168
00169 if (pt_pi0 > selePtPi0_)
00170 {
00171 float m_inv = sqrt ( (eIslandBCEB[i] + eIslandBCEB[j])*(eIslandBCEB[i] + eIslandBCEB[j]) - (p0x+p1x)*(p0x+p1x) - (p0y+p1y)*(p0y+p1y) - (p0z+p1z)*(p0z+p1z) );
00172 if ( (m_inv<seleMinvMaxPi0_) && (m_inv>seleMinvMinPi0_) )
00173 {
00174 cout <<" pi0 Candidate (pt>2.5 GeV, m_inv<0.2) pt,m_inv,i,j : "<<pt_pi0<<" "<<m_inv<<" "<<i<<" "<<j<<" "<<endl;
00175 BC1[npi0]=i;
00176 BC2[npi0]=j;
00177 npi0++;
00178 }
00179
00180 }
00181
00182 }
00183 }
00184 }
00185
00186
00187 cout<<" "<<endl;
00188 cout<<" Pi0 candidates #: "<<npi0<<endl;
00189
00190 timerName = category + "::makePi0Cand";
00191 timers.pop_and_push(timerName);
00192
00193
00194
00195 vector<EBDetId> scXtals;
00196 scXtals.clear();
00197 for(Int_t i=0 ; i<npi0 ; i++)
00198 {
00199
00200
00201 int intbc=0;
00202
00203 for(reco::BasicClusterCollection::const_iterator aClus = islandBarrelBasicClusters->begin();
00204 aClus != islandBarrelBasicClusters->end(); aClus++) {
00205
00206
00207 if((intbc==BC1[i]) || (intbc==BC2[i]))
00208 {
00209
00210 std::vector<DetId> hits = aClus->getHitsByDetId();
00211
00212 std::map<DetId, EcalRecHit>::iterator aHit;
00213
00214
00215
00216 double currEnergy = 0.;
00217 EBDetId maxHit(0);
00218
00219 for( std::vector<DetId>::const_iterator idsIt = hits.begin(); idsIt != hits.end(); ++idsIt) {
00220
00221 if((*idsIt).subdetId()!=EcalBarrel || (*idsIt).det()!= DetId::Ecal) continue;
00222
00223 if(((recHitsEB_map->find(*idsIt))->second).energy() > currEnergy) {
00224 currEnergy=((recHitsEB_map->find(*idsIt))->second).energy();
00225 maxHit=*idsIt;
00226 }
00227 aHit = recHitsEB_map->find(*idsIt);
00228 pi0EBRecHitCollection->push_back(aHit->second);
00229 scXtals.push_back(*idsIt);
00230
00231
00232
00233
00234
00235
00236 }
00237
00238 if (!maxHit.null())
00239 for (int icry=0;icry< gammaCandEtaSize_*gammaCandPhiSize_;icry++)
00240 {
00241
00242 int row = icry / gammaCandEtaSize_;
00243 int column= icry % gammaCandEtaSize_;
00244 int curr_eta=maxHit.ieta() + column - (gammaCandEtaSize_/2);
00245 int curr_phi=maxHit.iphi() + row - (gammaCandPhiSize_/2);
00246
00247 if (curr_eta * maxHit.ieta() <= 0) {if (maxHit.ieta() > 0) curr_eta--; else curr_eta++; }
00248 if (curr_phi < 1) curr_phi += 360;
00249 if (curr_phi > 360) curr_phi -= 360;
00250
00251 try
00252 {
00253 EBDetId det = EBDetId(curr_eta,curr_phi,EBDetId::ETAPHIMODE);
00254 std::vector<EBDetId>::const_iterator usedIds;
00255
00256 bool HitAlreadyUsed=false;
00257 for(usedIds=scXtals.begin(); usedIds!=scXtals.end(); usedIds++)
00258 if(*usedIds==det)
00259 {
00260 HitAlreadyUsed=true;
00261 break;
00262 }
00263
00264 if(!HitAlreadyUsed)
00265 if (recHitsEB_map->find(det) != recHitsEB_map->end())
00266 {
00267 aHit = recHitsEB_map->find(det);
00268 pi0EBRecHitCollection->push_back(aHit->second);
00269 scXtals.push_back(det);
00270
00271
00272
00273
00274
00275
00276 }
00277 }
00278 catch (...)
00279 {
00280 }
00281 }
00282
00283 }
00284 intbc++;
00285
00286 }
00287 }
00288 }
00289
00290 timerName = category + "::preparePi0RecHitsCollection";
00291 timers.pop_and_push(timerName);
00292
00293
00294
00295
00296
00297 cout<< " EB RecHits # in Collection: "<<pi0EBRecHitCollection->size()<<endl;
00298 iEvent.put( pi0EBRecHitCollection, pi0BarrelHits_);
00299
00300 timerName = category + "::storePi0RecHitsCollection";
00301 timers.pop_and_push(timerName);
00302
00303 timers.clear_stack();
00304 delete recHitsEB_map;
00305
00306 }