ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/yangyong/src/RecoAnalyzer.cc
Revision: 1.1
Committed: Mon Feb 14 12:29:43 2011 UTC (14 years, 2 months ago) by yangyong
Content type: text/plain
Branch: MAIN
Log Message:

AlcaPi0 analyzer for offline inter-calibration

File Contents

# Content
1 #include "UserCode/yangyong/interface/RecoAnalyzer.h"
2
3 #include "DataFormats/EgammaReco/interface/BasicCluster.h"
4 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
5 #include "DataFormats/EcalDetId/interface/EBDetId.h"
6 #include "DataFormats/EcalDetId/interface/EEDetId.h"
7 #include "DataFormats/EcalDetId/interface/ESDetId.h"
8 #include "DataFormats/DetId/interface/DetId.h"
9 #include "DataFormats/Math/interface/Point3D.h"
10
11 #include "FWCore/Framework/interface/Event.h"
12 #include "FWCore/Framework/interface/EventSetup.h"
13 #include "DataFormats/Common/interface/Handle.h"
14 #include "FWCore/Framework/interface/ESHandle.h"
15 #include "FWCore/MessageLogger/interface/MessageLogger.h"
16
17 #include "DataFormats/RecoCandidate/interface/RecoEcalCandidate.h"
18 #include "DataFormats/RecoCandidate/interface/RecoEcalCandidateFwd.h"
19
20 #include "DataFormats/GeometryVector/interface/LocalPoint.h"
21
22 //Level 1 Trigger
23 #include "DataFormats/L1Trigger/interface/L1EmParticle.h"
24 #include "DataFormats/L1Trigger/interface/L1EmParticleFwd.h"
25 #include "CondFormats/L1TObjects/interface/L1CaloGeometry.h"
26 #include "CondFormats/DataRecord/interface/L1CaloGeometryRecord.h"
27 #include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"
28 #include "Geometry/Records/interface/CaloGeometryRecord.h"
29
30 /// EgammaCoreTools
31
32 #include "RecoEcal/EgammaCoreTools/interface/PositionCalc.h"
33 #include "RecoEcal/EgammaCoreTools/interface/EcalEtaPhiRegion.h"
34
35
36 // Ecal Mapping
37 #include "DataFormats/EcalRawData/interface/EcalListOfFEDS.h"
38 #include "Geometry/EcalMapping/interface/EcalElectronicsMapping.h"
39 #include "Geometry/EcalMapping/interface/EcalMappingRcd.h"
40 #include <DataFormats/FEDRawData/interface/FEDNumbering.h>
41
42 // Jets stuff
43 #include "DataFormats/L1Trigger/interface/L1JetParticle.h"
44 #include "DataFormats/L1Trigger/interface/L1JetParticleFwd.h"
45
46 //// Ecal Electrons Id
47 #include "DataFormats/EcalDetId/interface/EcalElectronicsId.h"
48 #include "DataFormats/EcalDetId/interface/EcalTriggerElectronicsId.h"
49
50
51 // ES stuff
52 #include "Geometry/EcalAlgo/interface/EcalPreshowerGeometry.h"
53 #include "Geometry/CaloTopology/interface/EcalPreshowerTopology.h"
54 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
55 #include "DataFormats/EgammaReco/interface/PreshowerClusterFwd.h"
56
57 //Ecal status
58 #include "CondFormats/DataRecord/interface/EcalChannelStatusRcd.h"
59 #include "CondFormats/EcalObjects/interface/EcalChannelStatus.h"
60
61 #include "CondFormats/L1TObjects/interface/L1GtTriggerMenuFwd.h"
62 #include "CondFormats/L1TObjects/interface/L1GtTriggerMenu.h"
63 #include "CondFormats/DataRecord/interface/L1GtTriggerMenuRcd.h"
64
65
66 #include "CondFormats/EcalObjects/interface/EcalPedestals.h"
67 #include "CondFormats/DataRecord/interface/EcalPedestalsRcd.h"
68
69 #include "CondFormats/EcalObjects/interface/EcalMGPAGainRatio.h"
70 #include "CondFormats/EcalObjects/interface/EcalGainRatios.h"
71 #include "CondFormats/DataRecord/interface/EcalGainRatiosRcd.h"
72
73 #include "CondFormats/EcalObjects/interface/EcalIntercalibConstantsMC.h"
74 #include "CondFormats/DataRecord/interface/EcalIntercalibConstantsMCRcd.h"
75
76 #include "TVector3.h"
77
78 #include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHitCollection.h"
79
80 #include "CLHEP/Matrix/Vector.h"
81 #include "CLHEP/Matrix/SymMatrix.h"
82
83 #include "FWCore/ServiceRegistry/interface/Service.h"
84 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
85 #include "CLHEP/Random/RandGaussQ.h"
86
87 #include "DataFormats/VertexReco/interface/Vertex.h"
88 #include "DataFormats/VertexReco/interface/VertexFwd.h"
89 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
90 #include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h"
91 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
92 ///#include "Geometry/TrackerTopology/interface/RectangularPixelTopology.h"
93 #include "Geometry/TrackerGeometryBuilder/interface/RectangularPixelTopology.h"
94
95 // needed for trigger bits from EventSetup as in ALCARECO paths
96 #include "CondFormats/HLTObjects/interface/AlCaRecoTriggerBits.h"
97 #include "CondFormats/DataRecord/interface/AlCaRecoTriggerBitsRcd.h"
98
99
100 //#include "HLTrigger/HLTfilters/interface/HLTHighLevelDev.h"
101 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
102 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
103
104 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
105 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
106 #include "DataFormats/CaloTowers/interface/CaloTower.h"
107 #include "DataFormats/CaloTowers/interface/CaloTowerFwd.h"
108
109 #include "DataFormats/TrackReco/interface/Track.h"
110 #include "DataFormats/TrackCandidate/interface/TrackCandidateCollection.h"
111 #include "DataFormats/TrackCandidate/interface/TrackCandidate.h"
112 #include "DataFormats/TrackReco/interface/Track.h"
113 #include "DataFormats/TrackReco/interface/TrackFwd.h"
114
115 #include "PhysicsTools/FWLite/interface/CommandLineParser.h"
116 #include "DataFormats/EgammaCandidates/interface/Conversion.h"
117
118
119 #define TWOPI 6.283185308
120
121 using namespace l1extra;
122 using namespace edm;
123 using namespace std;
124 using namespace reco;
125 //using namespace trigger;
126
127
128 class PtSorter {
129 public:
130 template <class T> bool operator() ( const T& a, const T& b ) {
131 return ( a.pt() > b.pt() );
132 }
133 };
134
135
136
137 bool sort_pred(const std::pair<double,int> & left, const std::pair<double,int>& right)
138 {
139 return left.first < right.first;
140 }
141
142
143 RecoAnalyzer::RecoAnalyzer(const edm::ParameterSet& iConfig){
144
145 cout<<"gettting parameters.." <<endl;
146 clusSeedThr_ = iConfig.getParameter<double> ("clusSeedThr");
147 clusSeedThrEndCap_ = iConfig.getParameter<double> ("clusSeedThrEndCap");
148
149 clusEtaSize_ = iConfig.getParameter<int> ("clusEtaSize");
150 clusPhiSize_ = iConfig.getParameter<int> ("clusPhiSize");
151 if ( clusPhiSize_ % 2 == 0 || clusEtaSize_ % 2 == 0) {
152 edm::LogError("AlCaPi0RecHitsProducerError") << "Size of eta/phi for simple clustering should be odd numbers, reset to be 3 ";
153 clusPhiSize_ = 3;
154 clusEtaSize_ = 3;
155 }
156
157
158 removeSpike_ = iConfig.getUntrackedParameter<int>("removeSpike",0);
159
160 doSelForPi0Barrel_ = iConfig.getParameter<bool> ("doSelForPi0Barrel");
161 if(doSelForPi0Barrel_){
162 barrelHits_ = iConfig.getParameter< edm::InputTag > ("barrelHits");
163 ///for Pi0 barrel selection
164 selePtGamma_ = iConfig.getParameter<double> ("selePtGamma");
165 selePtPi0_ = iConfig.getParameter<double> ("selePtPi0");
166 seleMinvMaxPi0_ = iConfig.getParameter<double> ("seleMinvMaxPi0");
167 seleMinvMinPi0_ = iConfig.getParameter<double> ("seleMinvMinPi0");
168 seleS4S9Gamma_ = iConfig.getParameter<double> ("seleS4S9Gamma");
169 selePi0BeltDR_ = iConfig.getParameter<double> ("selePi0BeltDR");
170 selePi0BeltDeta_ = iConfig.getParameter<double> ("selePi0BeltDeta");
171 selePi0Iso_ = iConfig.getParameter<double> ("selePi0Iso");
172 ptMinForIsolation_ = iConfig.getParameter<double>("ptMinForIsolation");
173
174 }
175
176 doSelForPi0Endcap_ = iConfig.getParameter<bool>("doSelForPi0Endcap");
177 if(doSelForPi0Endcap_){
178 endcapHits_ = iConfig.getParameter< edm::InputTag > ("endcapHits");
179
180 ///for Pi0 endcap selection
181 /// selePtGammaEndCap_ = iConfig.getParameter<double> ("selePtGammaEndCap");
182 /// selePtPi0EndCap_ = iConfig.getParameter<double> ("selePtPi0EndCap");
183
184 ///try to divide endcap region into 3 parts
185 /// eta< 2 ; eta>2 && eta<2.5 ; eta>2.5;
186 region1_Pi0EndCap_ = iConfig.getParameter<double> ("region1_Pi0EndCap");
187 selePtGammaPi0EndCap_region1_ = iConfig.getParameter<double> ("selePtGammaPi0EndCap_region1");
188 selePtPi0EndCap_region1_ = iConfig.getParameter<double> ("selePtPi0EndCap_region1");
189
190 region2_Pi0EndCap_ = iConfig.getParameter<double> ("region2_Pi0EndCap");
191 selePtGammaPi0EndCap_region2_ = iConfig.getParameter<double> ("selePtGammaPi0EndCap_region2");
192 selePtPi0EndCap_region2_ = iConfig.getParameter<double> ("selePtPi0EndCap_region2");
193
194 selePtGammaPi0EndCap_region3_ = iConfig.getParameter<double> ("selePtGammaPi0EndCap_region3");
195 selePtPi0EndCap_region3_ = iConfig.getParameter<double> ("selePtPi0EndCap_region3");
196
197
198 seleS4S9GammaEndCap_ = iConfig.getParameter<double> ("seleS4S9GammaEndCap");
199 seleMinvMaxPi0EndCap_ = iConfig.getParameter<double> ("seleMinvMaxPi0EndCap");
200 seleMinvMinPi0EndCap_ = iConfig.getParameter<double> ("seleMinvMinPi0EndCap");
201 selePi0BeltDREndCap_ = iConfig.getParameter<double> ("selePi0BeltDREndCap");
202 selePi0BeltDetaEndCap_ = iConfig.getParameter<double> ("selePi0BeltDetaEndCap");
203
204 selePi0IsoEndCap_ = iConfig.getParameter<double> ("selePi0IsoEndCap");
205
206 preshHitProducer_ = iConfig.getParameter<edm::InputTag>("preshRecHitProducer");
207 ptMinForIsolationEndCap_ = iConfig.getParameter<double>("ptMinForIsolationEndCap");
208
209 }
210
211 doSelForEtaBarrel_ = iConfig.getParameter<bool> ("doSelForEtaBarrel");
212 if(doSelForEtaBarrel_){
213 barrelHitsEta_ = iConfig.getParameter< edm::InputTag > ("barrelHitsEta");
214 selePtGammaEta_ = iConfig.getParameter<double> ("selePtGammaEta");
215 selePtEta_ = iConfig.getParameter<double> ("selePtEta");
216 seleMinvMaxEta_ = iConfig.getParameter<double> ("seleMinvMaxEta");
217 seleMinvMinEta_ = iConfig.getParameter<double> ("seleMinvMinEta");
218 seleS4S9GammaEta_ = iConfig.getParameter<double> ("seleS4S9GammaEta");
219 seleS9S25GammaEta_ = iConfig.getParameter<double> ("seleS9S25GammaEta");
220
221 seleEtaBeltDR_ = iConfig.getParameter<double> ("seleEtaBeltDR");
222 seleEtaBeltDeta_ = iConfig.getParameter<double> ("seleEtaBeltDeta");
223
224 seleEtaIso_ = iConfig.getParameter<double> ("seleEtaIso");
225 ptMinForIsolationEta_ = iConfig.getParameter<double>("ptMinForIsolationEta");
226
227 removePi0CandidatesForEta_ = iConfig.getParameter<bool>("removePi0CandidatesForEta");
228 massLowPi0Cand_ = iConfig.getParameter<double> ("massLowPi0Cand");
229 massHighPi0Cand_ = iConfig.getParameter<double> ("massHighPi0Cand");
230
231 }
232
233
234 doSelForEtaEndcap_ = iConfig.getParameter<bool>("doSelForEtaEndcap");
235 if(doSelForEtaEndcap_){
236 endcapHitsEta_ = iConfig.getParameter< edm::InputTag > ("endcapHitsEta");
237
238 ///for Eta endcap selection
239 /// selePtGammaEndCap_ = iConfig.getParameter<double> ("selePtGammaEndCap");
240 /// selePtEtaEndCap_ = iConfig.getParameter<double> ("selePtEtaEndCap");
241
242 ///try to divide endcap region into 3 parts
243 /// eta< 2 ; eta>2 && eta<2.5 ; eta>2.5;
244 region1_EtaEndCap_ = iConfig.getParameter<double> ("region1_EtaEndCap");
245 selePtGammaEtaEndCap_region1_ = iConfig.getParameter<double> ("selePtGammaEtaEndCap_region1");
246 selePtEtaEndCap_region1_ = iConfig.getParameter<double> ("selePtEtaEndCap_region1");
247
248 region2_EtaEndCap_ = iConfig.getParameter<double> ("region2_EtaEndCap");
249 selePtGammaEtaEndCap_region2_ = iConfig.getParameter<double> ("selePtGammaEtaEndCap_region2");
250 selePtEtaEndCap_region2_ = iConfig.getParameter<double> ("selePtEtaEndCap_region2");
251
252 selePtGammaEtaEndCap_region3_ = iConfig.getParameter<double> ("selePtGammaEtaEndCap_region3");
253 selePtEtaEndCap_region3_ = iConfig.getParameter<double> ("selePtEtaEndCap_region3");
254
255
256 seleS4S9GammaEtaEndCap_ = iConfig.getParameter<double> ("seleS4S9GammaEtaEndCap");
257 seleS9S25GammaEtaEndCap_ = iConfig.getParameter<double> ("seleS9S25GammaEtaEndCap");
258
259 seleMinvMaxEtaEndCap_ = iConfig.getParameter<double> ("seleMinvMaxEtaEndCap");
260 seleMinvMinEtaEndCap_ = iConfig.getParameter<double> ("seleMinvMinEtaEndCap");
261 seleEtaBeltDREndCap_ = iConfig.getParameter<double> ("seleEtaBeltDREndCap");
262 seleEtaBeltDetaEndCap_ = iConfig.getParameter<double> ("seleEtaBeltDetaEndCap");
263 ptMinForIsolationEtaEndCap_ = iConfig.getParameter<double>("ptMinForIsolationEtaEndCap");
264
265 seleEtaIsoEndCap_ = iConfig.getParameter<double> ("seleEtaIsoEndCap");
266 preshHitProducerEta_ = iConfig.getParameter<edm::InputTag>("preshRecHitProducerEta");
267 }
268
269
270 // input tag for L1GtTriggerMenuLite
271 m_l1GtTmLInputTag = iConfig.getParameter<edm::InputTag> ("L1GtTmLInputTag");
272
273
274 ///for storing rechits ES for each selected EE clusters.
275 storeRecHitES_ = iConfig.getParameter<bool>("storeRecHitES");
276 if(storeRecHitES_){
277 // maximum number of matched ES clusters (in each ES layer) to each BC
278 preshNclust_ = iConfig.getParameter<int>("preshNclust");
279 // min energy of ES clusters
280 preshClustECut = iConfig.getParameter<double>("preshClusterEnergyCut");
281 // algo params
282 double preshStripECut = iConfig.getParameter<double>("preshStripEnergyCut");
283 int preshSeededNst = iConfig.getParameter<int>("preshSeededNstrip");
284 // calibration parameters:
285 calib_planeX_ = iConfig.getParameter<double>("preshCalibPlaneX");
286 calib_planeY_ = iConfig.getParameter<double>("preshCalibPlaneY");
287 gamma_ = iConfig.getParameter<double>("preshCalibGamma");
288 mip_ = iConfig.getParameter<double>("preshCalibMIP");
289
290 // The debug level
291 std::string debugString = iConfig.getParameter<std::string>("debugLevelES");
292 if (debugString == "DEBUG") debugL = PreshowerClusterAlgo::pDEBUG;
293 else if (debugString == "INFO") debugL = PreshowerClusterAlgo::pINFO;
294 else debugL = PreshowerClusterAlgo::pERROR;
295 // ES algo constructor:
296 presh_algo = new PreshowerClusterAlgo(preshStripECut,preshClustECut,preshSeededNst,debugL);
297
298
299 }
300
301 InputDataFormat_ = iConfig.getParameter<int>("dataformat"); ///defautl input data
302
303 m_l1GtRecordInputTag = iConfig.getParameter<edm::InputTag>("L1GtRecordInputTag");
304
305
306 posCalculator_ = PositionCalc( iConfig.getParameter<edm::ParameterSet>("posCalcParameters") );
307
308 inputTag_ = iConfig.getParameter<edm::InputTag> ("TriggerResultsTag");
309
310 outputFile_ = iConfig.getParameter<std::string>("outputFile");
311 rootFile_ = new TFile(outputFile_.c_str(),"RECREATE"); // open output file to store histograms
312
313 std::cout<<"RecoAnalyzer initilized .." <<" "<<outputFile_.c_str()<<" opened."<<endl;
314
315 std::cout<<"dataformat: "<< InputDataFormat_ <<endl;
316 alcaL1trigNames_ = iConfig.getParameter<vstring>("alcaL1trigNames");
317
318 nEventsProcessed = 0;
319
320 nErrorPrinted = 0;
321
322 nPassedBSC = 0;
323 nPassedBSC_noBeamHalo = 0;
324
325 for(int j=0; j< 200; j++){
326 nL1bits_fired[j] = 0;
327 nL1bitsTech_fired[j] = 0;
328 }
329
330
331 }
332
333
334 RecoAnalyzer::~RecoAnalyzer()
335 {
336
337 if(storeRecHitES_){
338 delete presh_algo;
339 }
340
341 cout<<"totalProcessed: "<< nEventsProcessed<< " BSC4041 "<< nPassedBSC <<" noBeamHalo "<< nPassedBSC_noBeamHalo <<endl;
342 // TimingReport::current()->dump(std::cout);
343
344 }
345
346
347 // ------------ method called to produce the data ------------
348 void
349 RecoAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
350 //RecoAnalyzer::analyze(edm::Event& iEvent, const edm::EventSetup& iSetup)
351 {
352
353
354 if( nEventsProcessed ==0){
355
356
357 // edm::ESHandle<L1GtTriggerMenu> menuRcd;
358 // iSetup.get<L1GtTriggerMenuRcd>().get(menuRcd) ;
359 // const L1GtTriggerMenu* menu = menuRcd.product();
360 // cout <<" L1 Menu Name: "<< menuRcd->gtTriggerMenuName()<<endl;
361 // for (CItAlgo algo = menu->gtAlgorithmMap().begin(); algo!=menu->gtAlgorithmMap().end(); ++algo) {
362 // cout<< "L1MenuPhy" << "Name: " << (algo->second).algoName() << " Alias: " << (algo->second).algoAlias() << std::endl;
363 // }
364 // for (CItAlgo techTrig = menu->gtTechnicalTriggerMap().begin(); techTrig != menu->gtTechnicalTriggerMap().end(); ++techTrig) {
365 // cout << "L1MenuTech" << (techTrig->second).algoName() << std::endl;
366 // }
367
368 iSetup.get<EcalADCToGeVConstantRcd>().get(agc);
369 agcp = agc.product();
370 cout<<"agc: "<< agc->getEBValue() << " "<< agc->getEEValue() <<endl;
371
372 }
373
374
375 edm::ESHandle<CaloGeometry> geoHandle;
376 iSetup.get<CaloGeometryRecord>().get(geoHandle);
377
378
379
380
381 ////////////////////for MC information of pi0s and eta////////////
382 nMCpart =0;
383 if( InputDataFormat_ < 10){
384
385 for(int i=0; i<MAXMC; i++){ ///MC
386 pxMCpart[i] = 0;
387 pyMCpart[i] = 0;
388 pzMCpart[i] = 0;
389 ptotMCpart[i] = 0;
390 ptMCpart[i]=0;
391 etMCpart[i] = 0;
392 eMCpart[i] = 0;
393 etaMCpart[i] = -10;
394 phiMCpart[i] = -10;
395 pidMCpart[i] = 0;
396 pidmomMCpart[i] = 0;
397 vtxXMCpart[i] =0;
398 vtxYMCpart[i] =0;
399 vtxZMCpart[i] =0;
400 barcodemomMCpart[i]=-1;
401 statusMCpart[i] =-1;
402
403 nDauMCpart[i] =0;
404 for( int j=0; j<MAXDAU; j++){
405 barcodeDauMCpart[i][j] = -1;
406 }
407
408 convPhtMCpart[i][0] = 0;
409 convPhtMCpart[i][1] = -1;
410 convPhtMCpart[i][2] = -1;
411
412 }
413
414 }
415
416 nGenpi0 = 0;
417 nGeneta = 0;
418
419 procID = -1;
420 ptHAT = -1;
421
422 npizallgen = 0;
423 netaallgen = 0;
424
425 nChaGen = 0;
426
427
428
429
430 runNumber = iEvent.id().run();
431 evtNumber = iEvent.id().event();
432 lumiBlock = iEvent.luminosityBlock();
433 bunchX = iEvent.bunchCrossing();
434 orbitNumber = iEvent.orbitNumber();
435 const edm::Timestamp jtime = iEvent.time();
436 evtTime = jtime.value() >> 32;
437
438
439 /////*******************
440 //// Get generator Info
441 /////*******************
442
443 if( InputDataFormat_ < 10){
444
445 Handle<GenEventInfoProduct> geninfos;
446 try{
447 iEvent.getByLabel("generator",geninfos);
448
449 procID = int( geninfos->signalProcessID());
450 ///this is q, not pthat.
451 /// ptHAT = geninfos->qScale();
452 ptHAT = geninfos->binningValues()[0]; //this is ptHAT
453
454
455 }catch(std::exception& ex ){
456 nErrorPrinted++;
457 if(nErrorPrinted< maxErrorToPrint) cout<<"generator not working.."<<endl;
458 }
459
460
461 Handle<GenParticleCollection> genPart;
462 try {
463 iEvent.getByLabel( "genParticles", genPart);
464 nMCpart = 0;
465 for(int i=0; i< int(genPart->size())&& nMCpart<MAXMC; i++){
466 const GenParticle & p = (*genPart)[i];
467 eMCpart[nMCpart] = p.energy();
468 ptotMCpart[nMCpart] = p.p();
469 pxMCpart[nMCpart] =p.px();
470 pyMCpart[nMCpart] =p.py();
471 pzMCpart[nMCpart] =p.pz();
472 ptMCpart[nMCpart] =p.pt();
473 etMCpart[nMCpart] = p.et();
474 etaMCpart[nMCpart] = p.eta();
475 phiMCpart[nMCpart] = p.phi();
476 mMCpart[nMCpart] = p.mass();
477 pidMCpart[nMCpart] = p.pdgId();
478 chargeMCpart[nMCpart] = p.charge();
479 statusMCpart[nMCpart] = p.status();
480 nDauMCpart[nMCpart] = p.numberOfDaughters();
481 vtxXMCpart[nMCpart] = p.vx();
482 vtxYMCpart[nMCpart] = p.vy();
483 vtxZMCpart[nMCpart] = p.vz();
484
485
486
487 if(p.charge() !=0 && p.status() ==1 ){
488 ptChaGen[nChaGen] = p.pt();
489 etaChaGen[nChaGen] = p.eta();
490 pidChaGen[nChaGen] = p.pdgId();
491 chaChaGen[nChaGen] = p.charge();
492 staChaGen[nChaGen] = p.status();
493 nChaGen ++;
494 }
495
496
497 nMCpart++;
498 }
499 if(debug_>=1) cout<<"n total MCpart: "<<nMCpart<<endl;
500
501 ///let's try to find the index of mother and daughters.
502 for(int i=0; i< int(genPart->size())&& nMCpart<MAXMC; i++){
503 const Candidate & p = (*genPart)[i];
504 ///don't look if it's not photon
505 // if( p.pdgId() != 22) continue;
506 int pid = p.pdgId();
507 if( pid != 22 && pid != 111 && pid != 221 ) continue;
508 const Candidate * mom = p.mother();
509 if( mom !=NULL){
510 pidmomMCpart[i] = mom->pdgId();
511 barcodemomMCpart[i] = indexofParticle(mom->px(),mom->pz(),mom->status());
512 }
513 }
514
515
516
517 } catch( std::exception& ex){
518 nErrorPrinted++;
519 if(nErrorPrinted< maxErrorToPrint) cout<<"genparticle not working.."<<endl;
520
521 }
522 // Simulated tracks (i.e. GEANT particles).
523 Handle<edm::SimTrackContainer> psimtracks;
524 // Get the associated vertices
525 Handle<SimVertexContainer> simvertices;
526 try{
527 iEvent.getByLabel("g4SimHits", simvertices);
528
529 }catch( std::exception& ex){
530 nErrorPrinted++;
531 if(nErrorPrinted< maxErrorToPrint) cout<<" SimVertexContainer not working.."<<endl;
532
533 }
534
535
536 try{
537 iEvent.getByLabel("g4SimHits", psimtracks);
538 // Need to check that SimTrackContainer is sorted; otherwise, copy and sort :-(
539 std::auto_ptr<SimTrackContainer> simtracksTmp;
540 const SimTrackContainer * simtracksSorted = &* psimtracks;
541 if (!__gnu_cxx::is_sorted(psimtracks->begin(), psimtracks->end(), LessById())) {
542 simtracksTmp.reset(new SimTrackContainer(*psimtracks));
543 std::sort(simtracksTmp->begin(), simtracksTmp->end(), LessById());
544 if(debug_ >=1) cout<<"get g4SimHits..sorted."<<endl;
545
546 simtracksSorted = &* simtracksTmp;
547 }
548
549
550 int nMCpartGen = nMCpart;
551
552
553 map<unsigned int,int> map_simtrackid;
554
555 // loop through all simParticles
556 for (SimTrackContainer::const_iterator iM = psimtracks->begin();
557 iM != psimtracks->end(); ++iM) {
558
559 // Skip PYTHIA tracks.
560 if (iM->genpartIndex() != -1) continue;
561
562 /// skip if it is not electron
563 if( iM->type() != 11 && iM->type() != -11) continue;
564
565
566
567 if( nMCpart >= MAXMC) break;
568
569 map_simtrackid.insert(make_pair(iM->trackId(),nMCpart));
570
571 pxMCpart[nMCpart] = iM->momentum().px();
572 pyMCpart[nMCpart] = iM->momentum().py();
573 pzMCpart[nMCpart] = iM->momentum().pz();
574 ptMCpart[nMCpart] = iM->momentum().pt();
575 etaMCpart[nMCpart] = iM->momentum().eta();
576 phiMCpart[nMCpart] = iM->momentum().phi();
577 pidMCpart[nMCpart] = iM->type();
578
579 chargeMCpart[nMCpart] = int(iM->charge());
580
581 eMCpart[nMCpart] = sqrt(0.000511* 0.000511 + iM->momentum().px()*iM->momentum().px() + iM->momentum().py()*iM->momentum().py() + iM->momentum().pz()*iM->momentum().pz());
582
583 statusMCpart[nMCpart] = -99;
584
585 vtxXMCpart[nMCpart] = 0;
586 vtxYMCpart[nMCpart] = 0;
587 vtxZMCpart[nMCpart] = 0;
588
589 if (! iM->noVertex()) {
590 const SimVertex &vtx = (*simvertices)[iM->vertIndex()];
591 vtxXMCpart[nMCpart] = vtx.position().x();
592 vtxYMCpart[nMCpart] = vtx.position().y();
593 vtxZMCpart[nMCpart] = vtx.position().z();
594 }
595
596 barcodemomMCpart[nMCpart] = -2;
597 nMCpart ++;
598
599 }
600
601
602 vector<int> inde1; ///+ /
603 vector<int> inde2; ///-
604 vector<int> indpht;
605
606
607
608 int nSimTrack = 0;
609
610 ///loop over again
611 // loop through all simParticles
612 for (SimTrackContainer::const_iterator iM = psimtracks->begin();
613 iM != psimtracks->end(); ++iM) {
614
615 // Skip PYTHIA tracks.
616 if (iM->genpartIndex() != -1) continue;
617
618 /// skip if it is not electron
619 if( iM->type() != 11 && iM->type() != -11) continue;
620
621
622 if( nMCpartGen + nSimTrack >= MAXMC) break;
623
624
625 barcodemomMCpart[nMCpartGen+nSimTrack] = -2;
626
627
628 // find simtrack that has a genParticle match to its parent
629 // Look at the production vertex. If there is no vertex, I can do nothing...
630 if (! iM->noVertex()) {
631 // Pick the vertex (isimtrk.vertIndex() is really an index)
632 const SimVertex &vtx = (*simvertices)[iM->vertIndex()];
633
634 // Now note that vtx.parentIndex() is NOT an index, it's a track id, so I have to search for it
635 unsigned int idx = vtx.parentIndex();
636 SimTrackContainer::const_iterator it = std::lower_bound(simtracksSorted->begin(), simtracksSorted->end(), idx, LessById());
637
638 if ((it != simtracksSorted->end()) && (it->trackId() == idx)) { //it is the parent sim track
639 if (it->genpartIndex() != -1) {
640
641 barcodemomMCpart[nMCpartGen+nSimTrack] = it->genpartIndex() -1;
642
643 convPhtMCpart[it->genpartIndex() -1][0] = 1; ///this gen photon converts
644
645
646 vector<int>::iterator iit = find(indpht.begin(),indpht.end(),it->genpartIndex() -1);
647 if( iit == indpht.end()){
648 indpht.push_back(it->genpartIndex() -1);
649 }
650 if( iM->type() == 11) inde1.push_back(nMCpartGen+nSimTrack);
651 else inde2.push_back(nMCpartGen+nSimTrack);
652
653
654 }else{
655 map<unsigned int,int>::iterator intt = map_simtrackid.find(idx);
656 if( intt != map_simtrackid.end()){
657 barcodemomMCpart[nMCpartGen+nSimTrack] = intt->second;
658 }else{
659 barcodemomMCpart[nMCpartGen+nSimTrack] = -3; ////check this if any
660 }
661
662 }
663 } ///found parent in simtrack
664
665 }
666
667 nSimTrack ++;
668
669
670 } ///end of 2nd loop
671
672
673 ///now let's try to find for each indpht, it's correponding two electrons index
674 vector<int> pht;
675 vector<int> e1;
676 vector<int> e2;
677
678
679
680 for(int j =0; j< int(indpht.size());j++){
681 int k = indpht[j];
682
683 int found1 = -1;
684 int found2 = -1;
685 vector<int>::iterator it1= inde1.begin();
686 for(int j1 =0; j1< int(inde1.size()); j1++){
687 if(k == barcodemomMCpart[inde1[j1]]){
688 found1 = inde1[j1];
689 inde1.erase(it1+j1);
690 break;
691 }
692 }
693 vector<int>::iterator it2= inde2.begin();
694 for(int j2 =0; j2< int(inde2.size()); j2++){
695 if(k == barcodemomMCpart[inde2[j2]]){
696 found2 = inde2[j2];
697 inde2.erase(it2+j2);
698 break;
699 }
700 }
701
702 convPhtMCpart[k][1] = found1;
703 convPhtMCpart[k][2] = found2;
704
705
706 if( found1 > 0 && found2 >0) convPhtMCpart[k][0] = 2; /// both electron found in sim
707 else if( found1 >0 && found2 < 0) convPhtMCpart[k][0] = 3; /// only one found in sim
708 else if( found1 <0 && found2 > 0) convPhtMCpart[k][0] = 3; /// only one found in sim
709 else if( found1 <0 && found2 < 0) convPhtMCpart[k][0] = -10; /// neither found in sim
710
711 }
712
713
714 }catch( std::exception& ex){
715 nErrorPrinted++;
716 if(nErrorPrinted< maxErrorToPrint) cout<<"SimTrackContainer not working.."<<endl;
717
718 }
719
720 findgenpi0eta();
721
722
723 } ///If for MC samples
724
725
726
727
728 /////*******************
729 //// Get Level-1 Info
730 /////*******************
731
732 edm::Handle<L1GlobalTriggerReadoutRecord> gtReadoutRecord;
733 m_l1GtUtils.retrieveL1EventSetup(iSetup);
734 m_l1GtUtils.retrieveL1GtTriggerMenuLite(iEvent, m_l1GtTmLInputTag);
735
736 int iErrorCode = -1;
737 vector<int> l1res;
738 nL1Alca = int(alcaL1trigNames_.size());
739 for(int j=0; j< nL1Alca; j++){
740 string m_nameAlgTechTrig = alcaL1trigNames_[j];
741 bool decisionBeforeMaskAlgTechTrig = m_l1GtUtils.decisionBeforeMask(iEvent, m_nameAlgTechTrig, iErrorCode);
742 if (iErrorCode == 0) {
743 L1Alca[j] = int(decisionBeforeMaskAlgTechTrig);
744 } else if (iErrorCode == 1) {
745 l1res.push_back(-1);
746 L1Alca[j] = -1;
747 } else {
748 L1Alca[j] = -2;
749 }
750
751 }
752
753 try{
754 iEvent.getByLabel(m_l1GtRecordInputTag , gtReadoutRecord);
755 DecisionWord gtDecisionWord = gtReadoutRecord->decisionWord();
756
757 nL1bits = int( gtDecisionWord.size());
758 if(debug_>=1) cout<<"nL1bits; "<<nL1bits<<" # physics triggers: "<< L1GlobalTriggerReadoutSetup::NumberPhysTriggers <<endl;
759 for (int iBit = 0; iBit < nL1bits; ++iBit) {
760 L1bits[iBit] = gtDecisionWord[iBit] ;
761 if(L1bits[iBit] ==1) nL1bits_fired[iBit] ++;
762 }
763 ///acess techinical trigger
764 const TechnicalTriggerWord& technicalTriggerWordBeforeMask = gtReadoutRecord->technicalTriggerWord();
765 //// Replacing L1GlobalTriggerReadoutRecord with L1GlobalTriggerRecord and the corresponding label, one gets the values after masking.
766 nL1bitsTech = int(technicalTriggerWordBeforeMask.size());
767 for(int iBit = 0; iBit < nL1bitsTech; ++iBit) {
768 L1bitsTech[iBit] = technicalTriggerWordBeforeMask.at(iBit);
769 if( L1bitsTech[iBit] ==1) nL1bitsTech_fired[iBit] ++;
770 }
771 }catch(std::exception& ex ){
772 nErrorPrinted++;
773 if(nErrorPrinted< maxErrorToPrint) cout<<"L1 record not working.."<<endl;
774 }
775
776
777
778 if( nEventsProcessed % 10000 ==0) {
779 cout<<"nEventProcessed: "<< nEventsProcessed<< endl;
780 }
781 nEventsProcessed ++;
782
783
784
785 /////*******************
786 //// Get HLT Info
787 /////*******************
788 Handle<TriggerResults> trh;
789
790 nHLTbits = 0;
791 try {
792 iEvent.getByLabel(inputTag_, trh);
793 if(trh.isValid()) {
794 nHLTbits = int(trh->size());
795 if(nHLTbits>MAXHLTbits){
796 cout<<"nhltbits exeed max: "<<nHLTbits<<endl;
797 nHLTbits=MAXHLTbits;
798 }
799 for(int i=0; i< int(trh->size()) && i<MAXHLTbits; i++) {
800 //hltbits.push_back((*trh)[i].accept());
801 HLTbits[i] = (*trh)[i].accept();
802 }
803 }
804 }catch(std::exception& ex ){
805 nErrorPrinted++;
806 if(nErrorPrinted< maxErrorToPrint) cout<<" HLT not working.."<<endl;
807 }
808
809
810 /////*******************
811 //// Selection and root-trees for Pi0 in the barrel
812 /////*******************
813
814 if( doSelForPi0Barrel_){
815
816 try{
817 Handle<EBRecHitCollection> barrelRecHitsHandle;
818 iEvent.getByLabel(barrelHits_,barrelRecHitsHandle);
819 const EcalRecHitCollection *hitCollection_p = barrelRecHitsHandle.product();
820
821 if(debug_>=2) cout<<"making cluster pi0 barrel.." <<" "<< hitCollection_p->size()<<endl;
822
823 makeNxNClusters(iEvent,iSetup,hitCollection_p, reco::CaloID::DET_ECAL_BARREL);
824
825 if(debug_>=2) cout<<"do selection pi0 barrel.." <<endl;
826
827 doSelectionAndFillTree(iEvent,iSetup,reco::CaloID::DET_ECAL_BARREL,false,PIZ,seleS4S9Gamma_,-999,seleMinvMinPi0_,seleMinvMaxPi0_,selePi0BeltDeta_,selePi0BeltDR_,ptMinForIsolation_,selePi0Iso_);
828
829
830 }catch(std::exception& ex ){
831 nErrorPrinted++;
832 if(nErrorPrinted< maxErrorToPrint) cout<<"barrelRecHits NA.."<<endl;
833 }
834
835 }
836
837
838 /////*******************
839 //// Selection and root-trees for Eta in the barrel
840 /////*******************
841
842 if(doSelForEtaBarrel_){
843 try{
844 Handle<EBRecHitCollection> barrelRecHitsHandle;
845 iEvent.getByLabel(barrelHitsEta_,barrelRecHitsHandle);
846 const EcalRecHitCollection *hitCollection_p = barrelRecHitsHandle.product();
847
848 if(debug_>=2) cout<<"making cluster eta barrel.."<<" "<< hitCollection_p->size()<<endl;
849
850 makeNxNClusters(iEvent,iSetup,hitCollection_p, reco::CaloID::DET_ECAL_BARREL);
851
852 if(debug_>=2) cout<<"do selection eta barrel.." <<endl;
853
854 doSelectionAndFillTree(iEvent,iSetup,reco::CaloID::DET_ECAL_BARREL,removePi0CandidatesForEta_,ETA,seleS4S9GammaEta_,seleS9S25GammaEta_,seleMinvMinEta_,seleMinvMaxEta_,seleEtaBeltDeta_,seleEtaBeltDR_,ptMinForIsolationEta_,seleEtaIso_);
855
856
857 }catch(std::exception& ex ){
858 nErrorPrinted++;
859 if(nErrorPrinted< maxErrorToPrint) cout<<"barrelRecHitsEta NA.."<<endl;
860 }
861 }
862
863
864 /////*******************
865 //// Selection and root-trees for Pi0 in the endcap
866 /////*******************
867
868 if(doSelForPi0Endcap_){
869 try{
870 Handle<EERecHitCollection> endcapRecHitsHandle;
871 iEvent.getByLabel(endcapHits_,endcapRecHitsHandle);
872 const EcalRecHitCollection *hitCollection_p = endcapRecHitsHandle.product();
873
874 makeNxNClusters(iEvent,iSetup,hitCollection_p, reco::CaloID::DET_ECAL_ENDCAP);
875
876 if(debug_>=2) cout<<"do selection pi0 endcap.." <<endl;
877
878 doSelectionAndFillTree(iEvent,iSetup,reco::CaloID::DET_ECAL_ENDCAP,false,PIZ,seleS4S9GammaEndCap_,-999,seleMinvMinPi0EndCap_,seleMinvMaxPi0EndCap_,selePi0BeltDetaEndCap_,selePi0BeltDREndCap_,ptMinForIsolationEndCap_,selePi0IsoEndCap_);
879
880
881 }catch(std::exception& ex ){
882 nErrorPrinted++;
883 if(nErrorPrinted< maxErrorToPrint) cout<<"encapRecHitsEta NA.."<<endl;
884 }
885 }
886
887 /////*******************
888 //// Selection and root-trees for Eta in the endcap
889 /////*******************
890
891 if(doSelForEtaEndcap_){
892 try{
893 Handle<EERecHitCollection> endcapRecHitsHandle;
894 iEvent.getByLabel(endcapHitsEta_,endcapRecHitsHandle);
895 const EcalRecHitCollection *hitCollection_p = endcapRecHitsHandle.product();
896
897 makeNxNClusters(iEvent,iSetup,hitCollection_p, reco::CaloID::DET_ECAL_ENDCAP);
898
899 if(debug_>=2) cout<<"do selection eta endcap.." <<endl;
900
901
902 doSelectionAndFillTree(iEvent,iSetup,reco::CaloID::DET_ECAL_ENDCAP,false,ETA,seleS4S9GammaEtaEndCap_,seleS9S25GammaEtaEndCap_,seleMinvMinEtaEndCap_,seleMinvMaxEtaEndCap_,seleEtaBeltDetaEndCap_,seleEtaBeltDREndCap_,ptMinForIsolationEtaEndCap_,seleEtaIsoEndCap_);
903
904
905 }catch(std::exception& ex ){
906 nErrorPrinted++;
907 if(nErrorPrinted< maxErrorToPrint) cout<<"endcapRecHitsEta NA.."<<endl;
908 }
909 }
910
911
912 }
913
914
915
916 void RecoAnalyzer::beginJob()
917 {
918
919
920 rootFile_->cd();
921
922 if( doSelForPi0Barrel_ ){
923
924 mytree_pizeb = new TTree("pizSelb","Reco Simple Analysis");
925 mytree_pizeb->Branch("lumiBlock",&lumiBlock,"lumiBlock/I");
926 mytree_pizeb->Branch("runNumber",&runNumber,"runNumber/I");
927 mytree_pizeb->Branch("evtNumber",&evtNumber,"evtNumber/I");
928
929 // bunchX ,, those are never used. ??
930 //mytree_pizeb->Branch("bunchX",&bunchX,"bunchX/I");
931 //mytree_pizeb->Branch("orbitNumber",&orbitNumber,"orbitNumber/I");
932 mytree_pizeb->Branch("evtTime",&evtTime,"evtTime/I");
933
934 mytree_pizeb->Branch("nL1Alca",&nL1Alca,"nL1Alca/I");
935 mytree_pizeb->Branch("L1Alca",L1Alca,"L1Alca[nL1Alca]/I");
936
937
938 mytree_pizeb->Branch("mpair",&mpair,"mpair/F");
939 mytree_pizeb->Branch("ptpair",&ptpair,"ptpair/F");
940 mytree_pizeb->Branch("etapair",&etapair,"etapair/F");
941 ///mytree_pizeb->Branch("phipair",&phipair,"phipair/F");
942 mytree_pizeb->Branch("ptmin",&ptmin,"ptmin/F");
943 mytree_pizeb->Branch("isolation",&isolation,"isolation/F");
944
945 mytree_pizeb->Branch("s4s9min",&s4s9min,"s4s9min/F");
946 //mytree_pizeb->Branch("s9s25min",&s9s25min,"s9s25min/F");
947
948
949
950 mytree_pizeb->Branch("nxtClus1",&nxtClus1,"nxtClus1/I");
951 mytree_pizeb->Branch("eXtalClus1",eXtalClus1,"eXtalClus1[nxtClus1]/F");
952 mytree_pizeb->Branch("ietaXtalClus1",ietaXtalClus1,"ietaXtalClus1[nxtClus1]/I");
953 mytree_pizeb->Branch("iphiXtalClus1",iphiXtalClus1,"iphiXtalClus1[nxtClus1]/I");
954 mytree_pizeb->Branch("tXtalClus1",tXtalClus1,"tXtalClus1[nxtClus1]/F"); //timing
955
956 mytree_pizeb->Branch("nxtClus2",&nxtClus2,"nxtClus2/I");
957 mytree_pizeb->Branch("eXtalClus2",eXtalClus2,"eXtalClus2[nxtClus2]/F");
958 mytree_pizeb->Branch("ietaXtalClus2",ietaXtalClus2,"ietaXtalClus2[nxtClus2]/I");
959 mytree_pizeb->Branch("iphiXtalClus2",iphiXtalClus2,"iphiXtalClus2[nxtClus2]/I");
960 mytree_pizeb->Branch("tXtalClus2",tXtalClus2,"tXtalClus2[nxtClus2]/F"); //timing
961
962 ///gen info
963 if( InputDataFormat_ <10){
964 mytree_pizeb->Branch("genMatched",&genMatched,"genMatched/I");
965 mytree_pizeb->Branch("geninfo",geninfo,"geninfo[6]/F");
966 mytree_pizeb->Branch("convinfo",convinfo,"convinfo[2]/I");
967 }
968
969 }
970
971
972
973 if( doSelForPi0Endcap_ ){
974
975 mytree_pizee = new TTree("pizSele","Reco Simple Analysis");
976 mytree_pizee->Branch("lumiBlock",&lumiBlock,"lumiBlock/I");
977 mytree_pizee->Branch("runNumber",&runNumber,"runNumber/I");
978 mytree_pizee->Branch("evtNumber",&evtNumber,"evtNumber/I");
979 // bunchX
980 //mytree_pizee->Branch("bunchX",&bunchX,"bunchX/I");
981 // mytree_pizee->Branch("orbitNumber",&orbitNumber,"orbitNumber/I");
982 mytree_pizee->Branch("evtTime",&evtTime,"evtTime/I");
983
984
985 mytree_pizee->Branch("nL1Alca",&nL1Alca,"nL1Alca/I");
986 mytree_pizee->Branch("L1Alca",L1Alca,"L1Alca[nL1Alca]/I");
987
988
989
990 mytree_pizee->Branch("mpair",&mpair,"mpair/F");
991 mytree_pizee->Branch("ptpair",&ptpair,"ptpair/F");
992 mytree_pizee->Branch("etapair",&etapair,"etapair/F");
993 ////mytree_pizee->Branch("phipair",&phipair,"phipair/F");
994 mytree_pizee->Branch("ptmin",&ptmin,"ptmin/F");
995 mytree_pizee->Branch("isolation",&isolation,"isolation/F");
996
997 mytree_pizee->Branch("s4s9min",&s4s9min,"s4s9min/F");
998 //mytree_pizee->Branch("s9s25min",&s9s25min,"s9s25min/F");
999
1000
1001
1002 mytree_pizee->Branch("nxtClus1",&nxtClus1,"nxtClus1/I");
1003 mytree_pizee->Branch("eXtalClus1",eXtalClus1,"eXtalClus1[nxtClus1]/F");
1004 mytree_pizee->Branch("ietaXtalClus1",ietaXtalClus1,"ietaXtalClus1[nxtClus1]/I");
1005 mytree_pizee->Branch("iphiXtalClus1",iphiXtalClus1,"iphiXtalClus1[nxtClus1]/I");
1006 mytree_pizee->Branch("izXtalClus1",&izXtalClus1,"izXtalClus1/I");
1007 mytree_pizee->Branch("tXtalClus1",tXtalClus1,"tXtalClus1[nxtClus1]/F"); //timing
1008
1009 mytree_pizee->Branch("nxtClus2",&nxtClus2,"nxtClus2/I");
1010 mytree_pizee->Branch("eXtalClus2",eXtalClus2,"eXtalClus2[nxtClus2]/F");
1011 mytree_pizee->Branch("izXtalClus2",&izXtalClus2,"izXtalClus2/I");
1012 mytree_pizee->Branch("ietaXtalClus2",ietaXtalClus2,"ietaXtalClus2[nxtClus2]/I");
1013 mytree_pizee->Branch("iphiXtalClus2",iphiXtalClus2,"iphiXtalClus2[nxtClus2]/I");
1014 mytree_pizee->Branch("tXtalClus2",tXtalClus2,"tXtalClus2[nxtClus2]/F"); //timing
1015
1016
1017 //PreshowerS infoESX[2][8], infoESY[2][8],
1018 mytree_pizee->Branch("infoESX",infoESX,"infoESX[2][8]/F"); //timing
1019 mytree_pizee->Branch("infoESY",infoESY,"infoESY[2][8]/F"); //timing
1020
1021
1022 ///gen info
1023 if( InputDataFormat_ <10){
1024 mytree_pizee->Branch("genMatched",&genMatched,"genMatched/I");
1025 mytree_pizee->Branch("geninfo",geninfo,"geninfo[6]/F");
1026 mytree_pizee->Branch("convinfo",convinfo,"convinfo[2]/I");
1027
1028 }
1029
1030 }
1031
1032
1033
1034
1035 if( doSelForEtaBarrel_ ){
1036
1037 mytree_etaeb = new TTree("etaSelb","Reco Simple Analysis");
1038 mytree_etaeb->Branch("lumiBlock",&lumiBlock,"lumiBlock/I");
1039 mytree_etaeb->Branch("runNumber",&runNumber,"runNumber/I");
1040 mytree_etaeb->Branch("evtNumber",&evtNumber,"evtNumber/I");
1041 // bunchX
1042
1043 //mytree_etaeb->Branch("bunchX",&bunchX,"bunchX/I");
1044 // mytree_etaeb->Branch("orbitNumber",&orbitNumber,"orbitNumber/I");
1045 mytree_etaeb->Branch("evtTime",&evtTime,"evtTime/I");
1046
1047
1048 mytree_etaeb->Branch("nL1Alca",&nL1Alca,"nL1Alca/I");
1049 mytree_etaeb->Branch("L1Alca",L1Alca,"L1Alca[nL1Alca]/I");
1050
1051
1052
1053 mytree_etaeb->Branch("mpair",&mpair,"mpair/F");
1054 mytree_etaeb->Branch("ptpair",&ptpair,"ptpair/F");
1055 mytree_etaeb->Branch("etapair",&etapair,"etapair/F");
1056 ///mytree_etaeb->Branch("phipair",&phipair,"phipair/F");
1057 mytree_etaeb->Branch("ptmin",&ptmin,"ptmin/F");
1058 mytree_etaeb->Branch("isolation",&isolation,"isolation/F");
1059
1060 mytree_etaeb->Branch("s4s9min",&s4s9min,"s4s9min/F");
1061 mytree_etaeb->Branch("s9s25min",&s9s25min,"s9s25min/F");
1062
1063
1064
1065 mytree_etaeb->Branch("nxtClus1",&nxtClus1,"nxtClus1/I");
1066 mytree_etaeb->Branch("eXtalClus1",eXtalClus1,"eXtalClus1[nxtClus1]/F");
1067 mytree_etaeb->Branch("ietaXtalClus1",ietaXtalClus1,"ietaXtalClus1[nxtClus1]/I");
1068 mytree_etaeb->Branch("iphiXtalClus1",iphiXtalClus1,"iphiXtalClus1[nxtClus1]/I");
1069 mytree_etaeb->Branch("tXtalClus1",tXtalClus1,"tXtalClus1[nxtClus1]/F"); //timing
1070
1071 mytree_etaeb->Branch("nxtClus2",&nxtClus2,"nxtClus2/I");
1072 mytree_etaeb->Branch("eXtalClus2",eXtalClus2,"eXtalClus2[nxtClus2]/F");
1073 mytree_etaeb->Branch("ietaXtalClus2",ietaXtalClus2,"ietaXtalClus2[nxtClus2]/I");
1074 mytree_etaeb->Branch("iphiXtalClus2",iphiXtalClus2,"iphiXtalClus2[nxtClus2]/I");
1075 mytree_etaeb->Branch("tXtalClus2",tXtalClus2,"tXtalClus2[nxtClus2]/F"); //timing
1076
1077 ///5x5
1078 mytree_etaeb->Branch("nxt5x5Clus1",&nxt5x5Clus1,"nxt5x5Clus1/I");
1079 mytree_etaeb->Branch("eXtal5x5Clus1",eXtal5x5Clus1,"eXtal5x5Clus1[nxt5x5Clus1]/F");
1080 mytree_etaeb->Branch("ietaXtal5x5Clus1",ietaXtal5x5Clus1,"ietaXtal5x5Clus1[nxt5x5Clus1]/I");
1081 mytree_etaeb->Branch("iphiXtal5x5Clus1",iphiXtal5x5Clus1,"iphiXtal5x5Clus1[nxt5x5Clus1]/I");
1082 mytree_etaeb->Branch("tXtal5x5Clus1",tXtal5x5Clus1,"tXtal5x5Clus1[nxt5x5Clus1]/F"); //timing
1083
1084 mytree_etaeb->Branch("nxt5x5Clus2",&nxt5x5Clus2,"nxt5x5Clus2/I");
1085 mytree_etaeb->Branch("eXtal5x5Clus2",eXtal5x5Clus2,"eXtal5x5Clus2[nxt5x5Clus2]/F");
1086 mytree_etaeb->Branch("ietaXtal5x5Clus2",ietaXtal5x5Clus2,"ietaXtal5x5Clus2[nxt5x5Clus2]/I");
1087 mytree_etaeb->Branch("iphiXtal5x5Clus2",iphiXtal5x5Clus2,"iphiXtal5x5Clus2[nxt5x5Clus2]/I");
1088 mytree_etaeb->Branch("tXtal5x5Clus2",tXtal5x5Clus2,"tXtal5x5Clus2[nxt5x5Clus2]/F"); //timing
1089
1090
1091
1092 ///gen info
1093 if( InputDataFormat_ <10){
1094 mytree_etaeb->Branch("genMatched",&genMatched,"genMatched/I");
1095 mytree_etaeb->Branch("geninfo",geninfo,"geninfo[6]/F");
1096 mytree_etaeb->Branch("convinfo",convinfo,"convinfo[2]/I");
1097 }
1098
1099 }
1100
1101
1102 if( doSelForEtaEndcap_ ){
1103
1104 mytree_etaee = new TTree("etaSele","Reco Simple Analysis");
1105 mytree_etaee->Branch("lumiBlock",&lumiBlock,"lumiBlock/I");
1106 mytree_etaee->Branch("runNumber",&runNumber,"runNumber/I");
1107 mytree_etaee->Branch("evtNumber",&evtNumber,"evtNumber/I");
1108 // bunchX
1109 //mytree_etaee->Branch("bunchX",&bunchX,"bunchX/I");
1110 // mytree_etaee->Branch("orbitNumber",&orbitNumber,"orbitNumber/I");
1111 mytree_etaee->Branch("evtTime",&evtTime,"evtTime/I");
1112
1113 mytree_etaee->Branch("nL1Alca",&nL1Alca,"nL1Alca/I");
1114 mytree_etaee->Branch("L1Alca",L1Alca,"L1Alca[nL1Alca]/I");
1115
1116 mytree_etaee->Branch("mpair",&mpair,"mpair/F");
1117 mytree_etaee->Branch("ptpair",&ptpair,"ptpair/F");
1118 mytree_etaee->Branch("etapair",&etapair,"etapair/F");
1119 ///mytree_etaee->Branch("phipair",&phipair,"phipair/F");
1120 mytree_etaee->Branch("ptmin",&ptmin,"ptmin/F");
1121 mytree_etaee->Branch("isolation",&isolation,"isolation/F");
1122
1123 mytree_etaee->Branch("s4s9min",&s4s9min,"s4s9min/F");
1124 mytree_etaee->Branch("s9s25min",&s9s25min,"s9s25min/F");
1125 ///mytree_etaee->Branch("s9s25min",&s9s25min,"s9s25min/F");
1126
1127
1128
1129 mytree_etaee->Branch("nxtClus1",&nxtClus1,"nxtClus1/I");
1130 mytree_etaee->Branch("eXtalClus1",eXtalClus1,"eXtalClus1[nxtClus1]/F");
1131 mytree_etaee->Branch("ietaXtalClus1",ietaXtalClus1,"ietaXtalClus1[nxtClus1]/I");
1132 mytree_etaee->Branch("iphiXtalClus1",iphiXtalClus1,"iphiXtalClus1[nxtClus1]/I");
1133 mytree_etaee->Branch("tXtalClus1",tXtalClus1,"tXtalClus1[nxtClus1]/F"); //timing
1134 mytree_etaee->Branch("izXtalClus1",&izXtalClus1,"izXtalClus1/I");
1135
1136 mytree_etaee->Branch("nxtClus2",&nxtClus2,"nxtClus2/I");
1137 mytree_etaee->Branch("eXtalClus2",eXtalClus2,"eXtalClus2[nxtClus2]/F");
1138 mytree_etaee->Branch("ietaXtalClus2",ietaXtalClus2,"ietaXtalClus2[nxtClus2]/I");
1139 mytree_etaee->Branch("iphiXtalClus2",iphiXtalClus2,"iphiXtalClus2[nxtClus2]/I");
1140 mytree_etaee->Branch("tXtalClus2",tXtalClus2,"tXtalClus2[nxtClus2]/F"); //timing
1141 mytree_etaee->Branch("izXtalClus2",&izXtalClus2,"izXtalClus2/I");
1142
1143
1144 ///5x5
1145 mytree_etaee->Branch("nxt5x5Clus1",&nxt5x5Clus1,"nxt5x5Clus1/I");
1146 mytree_etaee->Branch("eXtal5x5Clus1",eXtal5x5Clus1,"eXtal5x5Clus1[nxt5x5Clus1]/F");
1147 mytree_etaee->Branch("ietaXtal5x5Clus1",ietaXtal5x5Clus1,"ietaXtal5x5Clus1[nxt5x5Clus1]/I");
1148 mytree_etaee->Branch("iphiXtal5x5Clus1",iphiXtal5x5Clus1,"iphiXtal5x5Clus1[nxt5x5Clus1]/I");
1149 ////mytree_etaee->Branch("iphiXtal5x5Clus1",iphiXtal5x5Clus1,"izXtal5x5Clus1[nxt5x5Clus1]/I"); for 5x5 don't save iz, the same as
1150 mytree_etaee->Branch("tXtal5x5Clus1",tXtal5x5Clus1,"tXtal5x5Clus1[nxt5x5Clus1]/F"); //timing
1151
1152 mytree_etaee->Branch("nxt5x5Clus2",&nxt5x5Clus2,"nxt5x5Clus2/I");
1153 mytree_etaee->Branch("eXtal5x5Clus2",eXtal5x5Clus2,"eXtal5x5Clus2[nxt5x5Clus2]/F");
1154 mytree_etaee->Branch("ietaXtal5x5Clus2",ietaXtal5x5Clus2,"ietaXtal5x5Clus2[nxt5x5Clus2]/I");
1155 mytree_etaee->Branch("iphiXtal5x5Clus2",iphiXtal5x5Clus2,"iphiXtal5x5Clus2[nxt5x5Clus2]/I");
1156 mytree_etaee->Branch("tXtal5x5Clus2",tXtal5x5Clus2,"tXtal5x5Clus2[nxt5x5Clus2]/F"); //timing
1157
1158 //PreshowerS infoESX[2][8], infoESY[2][8],
1159 mytree_etaee->Branch("infoESX",infoESX,"infoESX[2][8]/F"); //timing
1160 mytree_etaee->Branch("infoESY",infoESY,"infoESY[2][8]/F"); //timing
1161
1162 ///gen info
1163 if( InputDataFormat_ <10){
1164 mytree_etaee->Branch("genMatched",&genMatched,"genMatched/I");
1165 mytree_etaee->Branch("geninfo",geninfo,"geninfo[6]/F");
1166 mytree_etaee->Branch("convinfo",convinfo,"convinfo[2]/I");
1167 }
1168
1169 }
1170
1171
1172
1173
1174 }
1175
1176
1177
1178 // ------------ method called once each job just after ending the event loop ------------
1179
1180 void
1181 RecoAnalyzer::endJob() {
1182
1183
1184 rootFile_->cd();
1185
1186
1187
1188 if(doSelForPi0Barrel_){
1189 mytree_pizeb->Write();
1190 }
1191 if(doSelForPi0Endcap_){
1192 mytree_pizee->Write();
1193 }
1194
1195 if(doSelForEtaBarrel_){
1196 mytree_etaeb->Write();
1197 }
1198 if(doSelForEtaEndcap_){
1199 mytree_etaee->Write();
1200 }
1201
1202
1203 rootFile_->Write() ;
1204 rootFile_->Close() ;
1205
1206
1207
1208
1209
1210 }
1211
1212
1213
1214
1215
1216
1217 void RecoAnalyzer::convxtalid(int &nphi,int &neta)
1218 {
1219 // Barrel only
1220 // Output nphi 0...359; neta 0...84; nside=+1 (for eta>0), or 0 (for eta<0).
1221 // neta will be [-85,-1] , or [0,84], the minus sign indicates the z<0 side.
1222
1223 if(neta > 0) neta -= 1;
1224 if(nphi > 359) nphi=nphi-360;
1225
1226 // final check
1227 if(nphi >359 || nphi <0 || neta< -85 || neta > 84)
1228 {
1229 std::cout <<" unexpected fatal error in RecoAnalyzer::convxtalid "<< nphi << " " << neta << " " <<std::endl;
1230 //exit(1);
1231 }
1232 } //end of convxtalid
1233
1234
1235
1236
1237 int RecoAnalyzer::diff_neta_s(int neta1, int neta2){
1238 int mdiff;
1239 mdiff=(neta1-neta2);
1240 return mdiff;
1241 }
1242
1243 // Calculate the distance in xtals taking into account the periodicity of the Barrel
1244 int RecoAnalyzer::diff_nphi_s(int nphi1,int nphi2) {
1245 int mdiff;
1246 if(abs(nphi1-nphi2) < (360-abs(nphi1-nphi2))) {
1247 mdiff=nphi1-nphi2;
1248 }
1249 else {
1250 mdiff=360-abs(nphi1-nphi2);
1251 if(nphi1>nphi2) mdiff=-mdiff;
1252 }
1253 return mdiff;
1254 }
1255
1256
1257
1258
1259 double RecoAnalyzer::DeltaPhi(double v1, double v2)
1260 { // Computes the correctly normalized phi difference
1261 // v1, v2 = phi of object 1 and 2
1262 double diff = fabs(v2 - v1);
1263 double corr = 2*acos(-1.) - diff; //// 2*pi - diff;
1264 if (diff < acos(-1.)){ return diff;} else { return corr;}
1265
1266 }
1267
1268
1269 double RecoAnalyzer::GetDeltaR(double eta1, double eta2, double phi1, double phi2){
1270 // Computes the DeltaR of two objects from their eta and phi values
1271
1272 return sqrt( (eta1-eta2)*(eta1-eta2)
1273 + DeltaPhi(phi1, phi2)*DeltaPhi(phi1, phi2) );
1274
1275 }
1276
1277 double RecoAnalyzer::getcosd(double eta1, double phi1, double eta2, double phi2) {
1278 double theta1 = 2*atan(exp(-eta1));
1279 double theta2 = 2*atan(exp(-eta2));
1280 double cosd;
1281 double dphi = DeltaPhi(phi1,phi2);
1282 cosd = cos(theta1)*cos(theta2)+sin(theta1)*sin(theta2)*cos(dphi); //opening angle
1283 return cosd;
1284 }
1285
1286
1287
1288 int RecoAnalyzer::indexofParticle(float px, float pz, int status){
1289
1290 float err = 0.00001;
1291
1292 // int ind = -10;
1293
1294 vector<int> nn;
1295
1296 for( int j=0; j<nMCpart; j++){
1297 if(fabs(px-pxMCpart[j])<err && fabs(pz-pzMCpart[j])<err
1298 && status == statusMCpart[j]){
1299 nn.push_back(j);
1300 }
1301 }
1302 // if(int(nn.size()) !=1){ ///diquarks or gluon has two copy sometimesss!!!
1303 // cout<<"wrong! indexofParticle: n: "<<int(nn.size())<<endl;
1304 // for(int j=0; j<int(nn.size()); j++){
1305 // cout<<" dup j: "<<j<<" ind "<<nn[j]<<endl;
1306 // }
1307 // }
1308 return nn[0];
1309
1310 }
1311
1312
1313 int RecoAnalyzer::getMotherIndex(int j){
1314 if(j<0) {
1315 cout<<"no mother. input -1!!!!!!!!"<<endl;
1316 // cout<<"entry: "<<entry<<" input j: "<<j<<endl;
1317 // exit(1);
1318 return -1;
1319 }
1320
1321 int indmom = barcodemomMCpart[j];
1322 if(indmom>=0){
1323 int st = statusMCpart[indmom];
1324 int indf = indmom;
1325 if(st==3 && pidMCpart[indmom]==pidMCpart[j]){ //if ==3 && it's itself. trace back more.
1326 indf = barcodemomMCpart[indmom];
1327 if(indf>=0){
1328 st = statusMCpart[indf];
1329 }
1330 else cout<<"warning! ptcl has no mother!"<<endl;
1331 }
1332 return indf;
1333
1334 }
1335 else{
1336 return -1;
1337 }
1338
1339 }
1340
1341
1342
1343
1344 void RecoAnalyzer::findgenpi0eta(){
1345
1346 indpi0Gen.clear();
1347 indetaGen.clear();
1348 indpht1pi0Gen.clear();
1349 indpht2pi0Gen.clear();
1350 indpht1etaGen.clear();
1351 indpht2etaGen.clear();
1352
1353
1354 int pidPi0 = 111;
1355 int pidPht = 22;
1356 int pidEta = 221;
1357
1358 ////float eta_max = 1000000;
1359 // float et_min = 2.0;
1360
1361 ////float epht_min = 0.1;
1362
1363 ///epht_min = 0.;
1364
1365
1366 ////txtout<<"entry: "<<entry<<endl;
1367
1368 vector<int> indphtpi0Gen;
1369 vector<int> indphtetaGen;
1370
1371 int npi0all = 0;
1372 int netaall = 0;
1373
1374
1375 for( int j=0; j<nMCpart; j++){
1376
1377
1378 if( pidMCpart[j] == pidPi0 ) npi0all++;
1379 if( pidMCpart[j] == pidEta ) netaall++;
1380 if( statusMCpart[j] ==1 && pidMCpart[j] == pidPht ){
1381 int indmom = getMotherIndex(j);
1382
1383 if(pidMCpart[indmom] == pidPi0){
1384 indphtpi0Gen.push_back(j);
1385 }
1386 if(pidMCpart[indmom] == pidEta){
1387 indphtetaGen.push_back(j);
1388 }
1389 } //end of found one photon
1390
1391 }
1392
1393 vector< std::pair<double,int> > indpiz_eta;
1394 vector< std::pair<double,int> > indeta_eta;
1395
1396 int npi0_sel = 0;
1397 int neta_sel = 0;
1398
1399
1400 for( int j=0; j<int(indphtpi0Gen.size());j++){
1401 int ind = getMotherIndex(indphtpi0Gen[j]);
1402 int nsame = 0;
1403 vector<int> isame;
1404 for(int k=0; k<int(indphtpi0Gen.size());k++){
1405 if( k!=j && getMotherIndex(indphtpi0Gen[k]) == ind) {
1406 isame.push_back(k);
1407 nsame++;
1408 }
1409 }
1410 if(nsame==1){
1411 int ind1 =indphtpi0Gen[j];
1412 int ind2 = indphtpi0Gen[isame[0]];
1413
1414 indpht1pi0Gen.push_back(ind1);
1415 indpht2pi0Gen.push_back(ind2);
1416
1417 indpi0Gen.push_back(ind);
1418 indphtpi0Gen.erase(indphtpi0Gen.begin()+j);
1419 indphtpi0Gen.erase(indphtpi0Gen.begin()+isame[0]-1);
1420
1421 indpiz_eta.push_back( make_pair(fabs(etaMCpart[ind]), npi0_sel));
1422 npi0_sel ++;
1423
1424
1425 j = j-1; ////start from previous j again becasue size(indphtpi0Gen) decreased by 2.
1426 }
1427
1428 }
1429 /////eta
1430 for( int j=0; j<int(indphtetaGen.size());j++){
1431 int ind = getMotherIndex(indphtetaGen[j]);
1432 int nsame = 0;
1433 vector<int> isame;
1434 for(int k=0; k<int(indphtetaGen.size());k++){
1435 if( k!=j && getMotherIndex(indphtetaGen[k]) == ind) {
1436 isame.push_back(k);
1437 nsame++;
1438 }
1439 }
1440 if(nsame==1){
1441 int ind1 =indphtetaGen[j];
1442 int ind2 = indphtetaGen[isame[0]];
1443
1444 indpht1etaGen.push_back(ind1);
1445 indpht2etaGen.push_back(ind2);
1446
1447 indetaGen.push_back(ind);
1448 indphtetaGen.erase(indphtetaGen.begin()+j);
1449 indphtetaGen.erase(indphtetaGen.begin()+isame[0]-1);
1450
1451 indeta_eta.push_back( make_pair(fabs(etaMCpart[ind]), neta_sel) );
1452 neta_sel ++;
1453
1454 j = j-1; ////start from previous j again becasue size(indphtpi0Gen) decreased by 2.
1455 }
1456
1457 }
1458
1459
1460 //fillthe tree
1461
1462 sort(indpiz_eta.begin(),indpiz_eta.end(),sort_pred);
1463 sort(indeta_eta.begin(),indeta_eta.end(),sort_pred);
1464
1465
1466 nGenpi0 = 0;
1467
1468
1469 if(debug_>=1) cout<<"ngenpi0: "<< npi0all <<" "<< int(indpi0Gen.size())<<endl;
1470
1471
1472 for( int j=0; j<int(indpiz_eta.size()) && nGenpi0<MAXGenPIZ; j++){
1473 int k = indpiz_eta[j].second;
1474
1475
1476 int indmc = indpi0Gen[k];
1477 int indph1 = indpht1pi0Gen[k];
1478 int indph2 = indpht2pi0Gen[k];
1479
1480
1481 eGenpi0[nGenpi0] = eMCpart[indmc];
1482 phiGenpi0[nGenpi0] = phiMCpart[indmc];
1483 etaGenpi0[nGenpi0] = etaMCpart[indmc];
1484
1485
1486 vtxGenpi0[nGenpi0][0] = vtxXMCpart[indmc];
1487 vtxGenpi0[nGenpi0][1] = vtxYMCpart[indmc];
1488 vtxGenpi0[nGenpi0][2] = vtxZMCpart[indmc];
1489
1490 barcodeMomGenpi0[nGenpi0]= getMotherIndex(indmc);
1491 pidMomGenpi0[nGenpi0]= pidMCpart[barcodeMomGenpi0[nGenpi0]];
1492
1493
1494 ///a littel difference
1495 vtxPhtGenpi0[nGenpi0][0] = vtxXMCpart[indph1];
1496 vtxPhtGenpi0[nGenpi0][1] = vtxYMCpart[indph1];
1497 vtxPhtGenpi0[nGenpi0][2] = vtxZMCpart[indph1];
1498
1499
1500 ePhtGenpi0[nGenpi0][0] = eMCpart[indph1];
1501 ePhtGenpi0[nGenpi0][1] = eMCpart[indph2];
1502 etaPhtGenpi0[nGenpi0][0] = etaMCpart[indph1];
1503 etaPhtGenpi0[nGenpi0][1] = etaMCpart[indph2];
1504 phiPhtGenpi0[nGenpi0][0] = phiMCpart[indph1];
1505 phiPhtGenpi0[nGenpi0][1] = phiMCpart[indph2];
1506
1507 isConvPhtGenpi0[nGenpi0][0] = convPhtMCpart[indph1][0];
1508 isConvPhtGenpi0[nGenpi0][1] = convPhtMCpart[indph2][0];
1509
1510 int e1 = convPhtMCpart[indph1][1];
1511 int e2 = convPhtMCpart[indph1][2];
1512
1513 if( e1 >0){
1514 convPht1Genpi0[nGenpi0][0] = eMCpart[e1];
1515 convPht1Genpi0[nGenpi0][1] = etaMCpart[e1];
1516 convPht1Genpi0[nGenpi0][2] = phiMCpart[e1];
1517
1518
1519 }
1520 if( e2 >0){
1521 convPht1Genpi0[nGenpi0][3] = eMCpart[e2];
1522 convPht1Genpi0[nGenpi0][4] = etaMCpart[e2];
1523 convPht1Genpi0[nGenpi0][5] = phiMCpart[e2];
1524 }
1525
1526 for(int jj=0; jj<6; jj++){
1527 convVtxPhtGenpi0[nGenpi0][jj] = 0;
1528 }
1529 if( e1 >0){
1530 convVtxPhtGenpi0[nGenpi0][0] = vtxXMCpart[e1];
1531 convVtxPhtGenpi0[nGenpi0][1] = vtxYMCpart[e1];
1532 convVtxPhtGenpi0[nGenpi0][2] = vtxZMCpart[e1];
1533 }else if( e2 >0){
1534 convVtxPhtGenpi0[nGenpi0][0] = vtxXMCpart[e2];
1535 convVtxPhtGenpi0[nGenpi0][1] = vtxYMCpart[e2];
1536 convVtxPhtGenpi0[nGenpi0][2] = vtxZMCpart[e2];
1537 }else{
1538 convVtxPhtGenpi0[nGenpi0][0] = 0;
1539 convVtxPhtGenpi0[nGenpi0][1] = 0;
1540 convVtxPhtGenpi0[nGenpi0][2] = 0;
1541 }
1542
1543
1544
1545 e1 = convPhtMCpart[indph2][1];
1546 e2 = convPhtMCpart[indph2][2];
1547 if( e1 >0){
1548 convPht2Genpi0[nGenpi0][0] = eMCpart[e1];
1549 convPht2Genpi0[nGenpi0][1] = etaMCpart[e1];
1550 convPht2Genpi0[nGenpi0][2] = phiMCpart[e1];
1551 }
1552 if( e2 >0){
1553 convPht2Genpi0[nGenpi0][3] = eMCpart[e2];
1554 convPht2Genpi0[nGenpi0][4] = etaMCpart[e2];
1555 convPht2Genpi0[nGenpi0][5] = phiMCpart[e2];
1556 }
1557 if( e1 >0){
1558 convVtxPhtGenpi0[nGenpi0][3] = vtxXMCpart[e1];
1559 convVtxPhtGenpi0[nGenpi0][4] = vtxYMCpart[e1];
1560 convVtxPhtGenpi0[nGenpi0][5] = vtxZMCpart[e1];
1561 }else if( e2 >0){
1562 convVtxPhtGenpi0[nGenpi0][3] = vtxXMCpart[e2];
1563 convVtxPhtGenpi0[nGenpi0][4] = vtxYMCpart[e2];
1564 convVtxPhtGenpi0[nGenpi0][5] = vtxZMCpart[e2];
1565 }else {
1566 convVtxPhtGenpi0[nGenpi0][3] = 0;
1567 convVtxPhtGenpi0[nGenpi0][4] = 0;
1568 convVtxPhtGenpi0[nGenpi0][5] = 0;
1569 }
1570
1571 nGenpi0++;
1572
1573
1574 }
1575
1576
1577 if(debug_>=1) cout<<"ngenpi0gg: "<< npi0all <<" "<< int(indpi0Gen.size())<<" "<< nGenpi0 <<endl;
1578
1579
1580
1581 nGeneta = 0;
1582
1583
1584 for( int j=0; j<int(indeta_eta.size()) && nGeneta<MAXGenPIZ; j++){
1585 int k = indeta_eta[j].second;
1586
1587
1588 int indmc = indetaGen[k];
1589 int indph1 = indpht1etaGen[k];
1590 int indph2 = indpht2etaGen[k];
1591
1592 eGeneta[nGeneta] = eMCpart[indmc];
1593 phiGeneta[nGeneta] = phiMCpart[indmc];
1594 etaGeneta[nGeneta] = etaMCpart[indmc];
1595
1596 vtxGeneta[nGeneta][0] = vtxXMCpart[indmc];
1597 vtxGeneta[nGeneta][1] = vtxYMCpart[indmc];
1598 vtxGeneta[nGeneta][2] = vtxZMCpart[indmc];
1599 vtxPhtGeneta[nGeneta][0] = vtxXMCpart[indph1];
1600 vtxPhtGeneta[nGeneta][1] = vtxYMCpart[indph1];
1601 vtxPhtGeneta[nGeneta][2] = vtxZMCpart[indph1];
1602
1603
1604 barcodeMomGeneta[nGeneta] = getMotherIndex(indmc);
1605 pidMomGeneta[nGeneta]= pidMCpart[barcodeMomGeneta[nGeneta]];
1606
1607
1608
1609 ePhtGeneta[nGeneta][0] = eMCpart[indph1];
1610 ePhtGeneta[nGeneta][1] = eMCpart[indph2];
1611 etaPhtGeneta[nGeneta][0] = etaMCpart[indph1];
1612 etaPhtGeneta[nGeneta][1] = etaMCpart[indph2];
1613 phiPhtGeneta[nGeneta][0] = phiMCpart[indph1];
1614 phiPhtGeneta[nGeneta][1] = phiMCpart[indph2];
1615
1616
1617
1618 isConvPhtGeneta[nGeneta][0] = convPhtMCpart[indph1][0];
1619 isConvPhtGeneta[nGeneta][1] = convPhtMCpart[indph2][0];
1620
1621 int e1 = convPhtMCpart[indph1][1];
1622 int e2 = convPhtMCpart[indph1][2];
1623
1624 if( e1 >0){
1625 convPht1Geneta[nGeneta][0] = eMCpart[e1];
1626 convPht1Geneta[nGeneta][1] = etaMCpart[e1];
1627 convPht1Geneta[nGeneta][2] = phiMCpart[e1];
1628 }else{
1629 convPht1Geneta[nGeneta][0] = 0;
1630 convPht1Geneta[nGeneta][1] = 0;
1631 convPht1Geneta[nGeneta][2] = 0;
1632 }
1633 if( e2 >0){
1634 convPht1Geneta[nGeneta][3] = eMCpart[e2];
1635 convPht1Geneta[nGeneta][4] = etaMCpart[e2];
1636 convPht1Geneta[nGeneta][5] = phiMCpart[e2];
1637 }else{
1638 convPht1Geneta[nGeneta][3] = 0;
1639 convPht1Geneta[nGeneta][4] = 0;
1640 convPht1Geneta[nGeneta][5] = 0;
1641 }
1642
1643
1644 if( e1 >0){
1645 convVtxPhtGeneta[nGeneta][0] = vtxXMCpart[e1];
1646 convVtxPhtGeneta[nGeneta][1] = vtxYMCpart[e1];
1647 convVtxPhtGeneta[nGeneta][2] = vtxZMCpart[e1];
1648 }else if( e2 >0){
1649 convVtxPhtGeneta[nGeneta][0] = vtxXMCpart[e2];
1650 convVtxPhtGeneta[nGeneta][1] = vtxYMCpart[e2];
1651 convVtxPhtGeneta[nGeneta][2] = vtxZMCpart[e2];
1652 }else{
1653 convVtxPhtGeneta[nGeneta][0] = 0;
1654 convVtxPhtGeneta[nGeneta][1] = 0;
1655 convVtxPhtGeneta[nGeneta][2] = 0;
1656 }
1657
1658
1659 e1 = convPhtMCpart[indph2][1];
1660 e2 = convPhtMCpart[indph2][2];
1661 if( e1 >0){
1662 convPht2Geneta[nGeneta][0] = eMCpart[e1];
1663 convPht2Geneta[nGeneta][1] = etaMCpart[e1];
1664 convPht2Geneta[nGeneta][2] = phiMCpart[e1];
1665 }else{
1666 convPht2Geneta[nGeneta][0] = 0;
1667 convPht2Geneta[nGeneta][1] = 0;
1668 convPht2Geneta[nGeneta][2] = 0;
1669 }
1670 if( e2 >0){
1671 convPht2Geneta[nGeneta][3] = eMCpart[e2];
1672 convPht2Geneta[nGeneta][4] = etaMCpart[e2];
1673 convPht2Geneta[nGeneta][5] = phiMCpart[e2];
1674 }else{
1675 convPht2Geneta[nGeneta][3] = 0;
1676 convPht2Geneta[nGeneta][4] = 0;
1677 convPht2Geneta[nGeneta][5] = 0;
1678 }
1679
1680
1681 if( e1 >0){
1682 convVtxPhtGeneta[nGeneta][3] = vtxXMCpart[e1];
1683 convVtxPhtGeneta[nGeneta][4] = vtxYMCpart[e1];
1684 convVtxPhtGeneta[nGeneta][5] = vtxZMCpart[e1];
1685 }else if( e2 >0){
1686 convVtxPhtGeneta[nGeneta][3] = vtxXMCpart[e2];
1687 convVtxPhtGeneta[nGeneta][4] = vtxYMCpart[e2];
1688 convVtxPhtGeneta[nGeneta][5] = vtxZMCpart[e2];
1689 }else{
1690 convVtxPhtGeneta[nGeneta][3] = 0;
1691 convVtxPhtGeneta[nGeneta][4] = 0;
1692 convVtxPhtGeneta[nGeneta][5] = 0;
1693 }
1694
1695
1696 nGeneta++;
1697
1698 }
1699
1700
1701
1702
1703 npizallgen = npi0all;
1704 netaallgen = netaall;
1705
1706
1707 }
1708
1709
1710 ////transform eta ( z, pho), to eta at ecal ( w.r.t 0,0,0,)
1711 double RecoAnalyzer::ecalEta(double EtaParticle ,double Zvertex, double RhoVertex){
1712
1713
1714 // const Double_t PI = 3.1415927;
1715 double PI = acos(-1);
1716
1717 //---Definitions for ECAL
1718 double R_ECAL = 136.5;
1719 double Z_Endcap = 328.0;
1720 double etaBarrelEndcap = 1.479;
1721
1722 if (EtaParticle!= 0.)
1723 {
1724 double Theta = 0.0 ;
1725 double ZEcal = (R_ECAL-RhoVertex)*sinh(EtaParticle)+Zvertex;
1726
1727 if(ZEcal != 0.0) Theta = atan(R_ECAL/ZEcal);
1728 if(Theta<0.0) Theta = Theta+PI;
1729
1730 double ETA = - log(tan(0.5*Theta));
1731
1732 if( fabs(ETA) > etaBarrelEndcap )
1733 {
1734 double Zend = Z_Endcap ;
1735 if(EtaParticle<0.0 ) Zend = -Zend ;
1736 double Zlen = Zend - Zvertex ;
1737 double RR = Zlen/sinh(EtaParticle);
1738 Theta = atan((RR+RhoVertex)/Zend);
1739 if(Theta<0.0) Theta = Theta+PI;
1740 ETA = - log(tan(0.5*Theta));
1741 }
1742 return ETA;
1743 }
1744 else
1745 {
1746 return EtaParticle;
1747 }
1748 }
1749
1750
1751
1752 double RecoAnalyzer::ecalPhi(double phi,double x0,double y0){
1753
1754 //double R_ECAL = 136.5; ///cm
1755 double r = 136.5;
1756
1757 double r0 = sqrt(x0*x0 + y0*y0);
1758
1759 if(r0<1E-5) return phi;
1760
1761 if( r0 >= r){
1762 cout<<"warning. ecalPhi vtx outside ecal return input" << r0 <<" "<< r <<endl;
1763 return phi;
1764 }
1765
1766 double theta0 ;
1767 if(fabs(y0)>0) theta0= y0/fabs(y0) * acos(x0/r0);
1768 else theta0 = acos(x0/r0);
1769
1770 double theta = phi + asin( r0/r *sin(theta0-phi));
1771
1772 double PI = acos(-1);
1773 while ( theta < -PI) theta += PI;
1774 while ( theta > PI) theta -= PI;
1775
1776 return theta;
1777
1778
1779 }
1780
1781
1782 void RecoAnalyzer::makeNxNClusters(const edm::Event &evt, const edm::EventSetup &es,
1783 const EcalRecHitCollection *hits, const reco::CaloID::Detectors detector){
1784
1785
1786
1787 nClus = 0;
1788
1789 eClus.clear();
1790 etaClus.clear();
1791 phiClus.clear();
1792 thetaClus.clear();
1793 etClus.clear();
1794 s4s9Clus.clear();
1795 s9s25Clus.clear();
1796 xClus.clear();
1797 yClus.clear();
1798 zClus.clear();
1799
1800
1801 RecHitsCluster.clear();
1802 RecHitsCluster5x5.clear();
1803
1804
1805 std::vector<EcalRecHit> seeds;
1806
1807 double clusterSeedThreshold ;
1808 if (detector == reco::CaloID::DET_ECAL_BARREL){
1809 clusterSeedThreshold = clusSeedThr_;
1810 }else{
1811 clusterSeedThreshold = clusSeedThrEndCap_;
1812 }
1813
1814
1815 for(EcalRecHitCollection::const_iterator itt = hits->begin(); itt != hits->end(); itt++){
1816 double energy = itt->energy();
1817 if (energy > clusterSeedThreshold ) seeds.push_back(*itt);
1818 }
1819
1820
1821 // get the geometry and topology from the event setup:
1822 edm::ESHandle<CaloGeometry> geoHandle;
1823 es.get<CaloGeometryRecord>().get(geoHandle);
1824
1825 const CaloSubdetectorGeometry *geometry_p;
1826 CaloSubdetectorTopology *topology_p;
1827 if (detector == reco::CaloID::DET_ECAL_BARREL) {
1828 geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
1829 topology_p = new EcalBarrelTopology(geoHandle);
1830 }else {
1831 geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
1832 topology_p = new EcalEndcapTopology(geoHandle);
1833 }
1834
1835 const CaloSubdetectorGeometry *geometryES_p;
1836 geometryES_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
1837
1838
1839 std::vector<reco::BasicCluster> clusters;
1840 std::vector<DetId> usedXtals;
1841 // sort seed according to Energy
1842 sort(seeds.begin(), seeds.end(), ecalRecHitLess());
1843
1844
1845 for (std::vector<EcalRecHit>::iterator itseed=seeds.begin(); itseed!=seeds.end(); itseed++) {
1846 DetId seed_id = itseed->id();
1847 std::vector<DetId>::const_iterator usedIds;
1848
1849 ///sed not yet used
1850 std::vector<DetId>::iterator itdet = find(usedXtals.begin(),usedXtals.end(),seed_id);
1851 if(itdet != usedXtals.end()) continue;
1852
1853 std::vector<DetId> clus_v = topology_p->getWindow(seed_id,clusEtaSize_,clusPhiSize_);
1854 float clus_energy = 0;
1855 vector<EcalRecHit> RecHitsInWindow;
1856 vector<EcalRecHit> RecHitsInWindow5x5;
1857 vector<DetId> DetIdInWindow;
1858 std::vector<std::pair<DetId, float> > clus_used;
1859
1860 for (std::vector<DetId>::iterator det=clus_v.begin(); det!=clus_v.end(); det++) {
1861 DetId detid = *det;
1862
1863 //not yet used
1864 std::vector<DetId>::iterator itdet = find(usedXtals.begin(),usedXtals.end(),detid);
1865 if(itdet != usedXtals.end()) continue;
1866 //inside the collection
1867 EcalRecHitCollection::const_iterator hit = hits->find(detid);
1868 if( hit == hits->end()) continue;
1869 usedXtals.push_back(detid);
1870 clus_used.push_back(std::pair<DetId, float>(detid, 1.) );
1871 clus_energy += hit->energy();
1872
1873
1874 RecHitsInWindow.push_back(*hit);
1875 DetIdInWindow.push_back(detid);
1876
1877
1878 } //// end of making one nxn simple cluster
1879
1880 if( clus_energy <= 0 ) continue;
1881
1882
1883 math::XYZPoint clus_pos = posCalculator_.Calculate_Location(clus_used,hits,geometry_p,geometryES_p);
1884
1885 sort(RecHitsInWindow.begin(), RecHitsInWindow.end(), ecalRecHitLess());
1886
1887 if (debug_>=2 ) LogDebug("")<<"nxn_cluster in run "<< evt.id().run()<<" event "<<evt.id().event()<<" energy: "<<clus_energy <<" eta: "<< clus_pos.Eta()<<" phi: "<< clus_pos.Phi()<<" nRecHits: "<< RecHitsInWindow.size()<<endl;
1888
1889
1890 int seedx; /// = seed_id.ieta();
1891 int seedy; /// = seed_id.iphi();
1892
1893 if (detector == reco::CaloID::DET_ECAL_BARREL) {
1894 EBDetId ebd = EBDetId(seed_id);
1895 seedx = ebd.ieta();
1896 seedy = ebd.iphi();
1897 convxtalid(seedy,seedx);
1898
1899 }else{
1900 EEDetId eed = EEDetId(seed_id);
1901 seedx = eed.ix();
1902 seedy = eed.iy();
1903 }
1904
1905
1906 float e2x2[4]={0};
1907 float e3x3 = 0;
1908 float e5x5 = 0;
1909
1910 std::vector<DetId> clus_v5x5;
1911 clus_v5x5 = topology_p->getWindow(seed_id,5,5);
1912
1913 for( std::vector<DetId>::const_iterator idItr = clus_v5x5.begin(); idItr != clus_v5x5.end(); idItr++){
1914 DetId ed = *idItr;
1915 EcalRecHitCollection::const_iterator rit = hits ->find( ed );
1916 if ( rit == hits ->end() ) continue;
1917 float energy = (*rit).energy();
1918 e5x5 += energy;
1919
1920 //check if already in 3x3 , so no need to push_back here
1921 std::vector<DetId>::const_iterator already3x3 = find(DetIdInWindow.begin(),DetIdInWindow.end(),ed);
1922 if( already3x3 != DetIdInWindow.end() ) continue;
1923 RecHitsInWindow5x5.push_back( *rit);
1924 }
1925
1926
1927 for(unsigned int j=0; j<RecHitsInWindow.size();j++){
1928 DetId det = RecHitsInWindow[j].id();
1929 int dx,dy;
1930 if (detector == reco::CaloID::DET_ECAL_BARREL) {
1931 EBDetId ebd = EBDetId(det);
1932 int x = ebd.ieta();
1933 int y = ebd.iphi();
1934 convxtalid(y,x);
1935 dx = diff_neta_s(x,seedx);
1936 dy = diff_nphi_s(y,seedy);
1937 }else{
1938 EEDetId eed = EEDetId(det);
1939 int x = eed.ix();
1940 int y = eed.iy();
1941 dx = x-seedx;
1942 dy = y-seedy;
1943 }
1944 float energy = RecHitsInWindow[j].energy();
1945 if(abs(dx)<=1 && abs(dy)<=1){
1946 if(dx <= 0 && dy <=0) e2x2[0] += energy;
1947 if(dx >= 0 && dy <=0) e2x2[1] += energy;
1948 if(dx <= 0 && dy >=0) e2x2[2] += energy;
1949 if(dx >= 0 && dy >=0) e2x2[3] += energy;
1950 e3x3 += energy;
1951 }
1952 }
1953
1954 if (detector == reco::CaloID::DET_ECAL_BARREL ) {
1955 if( removeSpike_==1){ ///check E9 >2GeV && Emax/E9 > 0.95
1956 if( clus_energy >2 && e3x3>0 && RecHitsInWindow[0].energy() / e3x3 > 0.95) continue;
1957 }
1958 }
1959
1960 ///Now fill the vector of everything
1961 eClus.push_back( clus_energy);
1962 etaClus.push_back( clus_pos.Eta());
1963 phiClus.push_back( clus_pos.Phi());
1964 thetaClus.push_back(2. * atan(exp(-clus_pos.Eta())));
1965 etClus.push_back( clus_energy * sin(2. * atan(exp(-clus_pos.Eta()))));
1966
1967 float s4max = *max_element( e2x2,e2x2+4);
1968 s4s9Clus.push_back( s4max/ e3x3);
1969 float s9s25 = e5x5 !=0 ? e3x3/e5x5:-1;
1970 s9s25Clus.push_back(s9s25);
1971 xClus.push_back( clus_pos.X());
1972 yClus.push_back( clus_pos.Y());
1973 zClus.push_back( clus_pos.Z());
1974
1975
1976 RecHitsCluster.push_back(RecHitsInWindow);
1977 RecHitsCluster5x5.push_back(RecHitsInWindow5x5);
1978
1979 nClus ++;
1980
1981
1982 }
1983
1984
1985
1986 }
1987
1988
1989
1990 void RecoAnalyzer::doSelectionAndFillTree(const edm::Event &evt, const edm::EventSetup &es, const reco::CaloID::Detectors detector, bool rmPiz, int pizEta, double s4s9Cut, double s9s25Cut, double minvMinCut, double minvMaxCut, double isodetaCut, double isodrCut, double isoptCut, double isoCut){
1991
1992
1993 //
1994
1995 double ptminCut = 0 ;
1996 double ptpairCut = 0 ;/// double s4s9Cut, double s9s25Cut, double minvMinCut, double minvMaxCut, double isodetaCut, double isodrCut, double isoptCut, double isoCut;
1997 double ptminCut_endcap_region1 = 0;
1998 double ptminCut_endcap_region2 = 0 ;
1999 double ptminCut_endcap_region3 = 0 ;
2000 double ptpairCut_endcap_region1 = 0 ;
2001 double ptpairCut_endcap_region2 = 0 ;
2002 double ptpairCut_endcap_region3 = 0 ;
2003
2004 double eta_endcap_region1 = 0 ;
2005 double eta_endcap_region2 = 0 ;
2006
2007
2008 if( detector == reco::CaloID::DET_ECAL_ENDCAP){
2009
2010 if(pizEta == PIZ){
2011
2012 ptminCut_endcap_region1 = selePtGammaPi0EndCap_region1_;
2013 ptminCut_endcap_region2 = selePtGammaPi0EndCap_region2_;
2014 ptminCut_endcap_region3 = selePtGammaPi0EndCap_region3_;
2015
2016 ptpairCut_endcap_region1 = selePtPi0EndCap_region1_;
2017 ptpairCut_endcap_region2 = selePtPi0EndCap_region2_;
2018 ptpairCut_endcap_region3 = selePtPi0EndCap_region3_;
2019
2020 eta_endcap_region1 = region1_Pi0EndCap_;
2021 eta_endcap_region2 = region2_Pi0EndCap_;
2022
2023 }else{
2024
2025 ptminCut_endcap_region1 = selePtGammaEtaEndCap_region1_;
2026 ptminCut_endcap_region2 = selePtGammaEtaEndCap_region2_;
2027 ptminCut_endcap_region3 = selePtGammaEtaEndCap_region3_;
2028
2029 ptpairCut_endcap_region1 = selePtEtaEndCap_region1_;
2030 ptpairCut_endcap_region2 = selePtEtaEndCap_region2_;
2031 ptpairCut_endcap_region3 = selePtEtaEndCap_region3_;
2032
2033 eta_endcap_region1 = region1_EtaEndCap_;
2034 eta_endcap_region2 = region2_EtaEndCap_;
2035
2036 }
2037
2038 }else{
2039 if(pizEta == PIZ){
2040 ptminCut = selePtGamma_;
2041 ptpairCut = selePtPi0_;
2042 }else{
2043 ptminCut = selePtGammaEta_;
2044 ptpairCut = selePtEta_;
2045 }
2046 }
2047
2048 const CaloSubdetectorGeometry *geometry_es;
2049 CaloSubdetectorTopology *topology_es=0;
2050 if( detector == reco::CaloID::DET_ECAL_ENDCAP){
2051 edm::ESHandle<CaloGeometry> geoHandle;
2052 es.get<CaloGeometryRecord>().get(geoHandle);
2053 geometry_es = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
2054 topology_es = new EcalPreshowerTopology(geoHandle);
2055 }
2056
2057 esrechits_map.clear();
2058
2059
2060 if( detector == reco::CaloID::DET_ECAL_ENDCAP && storeRecHitES_){
2061 Handle<ESRecHitCollection> esRecHitsHandle;
2062 try{
2063 if(pizEta==1){
2064 evt.getByLabel(preshHitProducer_,esRecHitsHandle);
2065 }else{
2066 evt.getByLabel(preshHitProducerEta_,esRecHitsHandle);
2067 }
2068
2069 ///const EcalRecHitCollection* hitCollection_es = esRecHitsHandle.product();
2070 EcalRecHitCollection::const_iterator iter;
2071 for (iter = esRecHitsHandle->begin(); iter != esRecHitsHandle->end(); iter++) {
2072 //Make the map of DetID, EcalRecHit pairs
2073 esrechits_map.insert(std::make_pair(iter->id(), *iter));
2074 }
2075
2076 }catch(std::exception& ex ){
2077 storeRecHitES_ = false;
2078 cout<<"preshowerRecHit not working.."<<endl;
2079 }
2080
2081 }
2082
2083
2084 vector<int> indClusPi0Candidates; ///those clusters identified as pi0s
2085 if( detector == reco::CaloID::DET_ECAL_BARREL && rmPiz){
2086 for(int i=0 ; i<nClus ; i++){
2087 for(int j=i+1 ; j<nClus ; j++){
2088
2089 double p0x = etClus[i] * cos(phiClus[i]);
2090 double p1x = etClus[j] * cos(phiClus[j]);
2091 double p0y = etClus[i] * sin(phiClus[i]);
2092 double p1y = etClus[j] * sin(phiClus[j]);
2093 double p0z = eClus[i] * cos(thetaClus[i]);
2094 double p1z = eClus[j] * cos(thetaClus[j]);
2095
2096 double m_inv = sqrt ( (eClus[i] + eClus[j])*(eClus[i] + eClus[j]) - (p0x+p1x)*(p0x+p1x) - (p0y+p1y)*(p0y+p1y) - (p0z+p1z)*(p0z+p1z) );
2097
2098 if( m_inv > massLowPi0Cand_ && m_inv < massHighPi0Cand_){
2099
2100 int indtmp[2] = {i,j};
2101 for(int k=0; k<2; k++){
2102 std::vector<int>::iterator it = find(indClusPi0Candidates.begin(),indClusPi0Candidates.end(),indtmp[k]);
2103 if( it == indClusPi0Candidates.end()) indClusPi0Candidates.push_back(indtmp[k]);
2104 }
2105
2106 }
2107
2108 }
2109
2110 }
2111 }
2112
2113
2114 used_strips.clear();
2115 ///we need to make sure for every endcap cluster we have the same preshower cluster
2116 std::map<int, vector<float > > infoES_saved;
2117 vector<int> indClusSelected;
2118
2119
2120 ///after selection do NxN matching with MC
2121 vector<int> indPairCand; ///pair of cluster passed the cuts
2122 vector<float> mPairCand; /// mpair of of cluster passed the cuts
2123 vector<float> mPairv1Cand; /// mpair of of cluster passed the cuts
2124
2125 vector<float> etaPairCand;
2126 vector<float> phiPairCand;
2127 vector<float> ptPairCand;
2128 vector<float> isoPairCand;
2129
2130
2131 for(int i=0 ; i<nClus ; i++){
2132
2133 if( detector == reco::CaloID::DET_ECAL_BARREL && rmPiz){
2134 std::vector<int>::iterator it = find(indClusPi0Candidates.begin(),indClusPi0Candidates.end(),i);
2135 if( it != indClusPi0Candidates.end()) continue;
2136 }
2137
2138 if ( s4s9Clus[i] < s4s9Cut || s9s25Clus[i] < s9s25Cut ) continue;
2139
2140 for(int j=i+1 ; j<nClus ; j++){
2141
2142 if( detector == reco::CaloID::DET_ECAL_BARREL && rmPiz){
2143 std::vector<int>::iterator it = find(indClusPi0Candidates.begin(),indClusPi0Candidates.end(),j);
2144 if( it != indClusPi0Candidates.end()) continue;
2145 }
2146
2147 if ( s4s9Clus[j] < s4s9Cut || s9s25Clus[j] < s9s25Cut ) continue;
2148
2149 double p0x = etClus[i] * cos(phiClus[i]);
2150 double p1x = etClus[j] * cos(phiClus[j]);
2151 double p0y = etClus[i] * sin(phiClus[i]);
2152 double p1y = etClus[j] * sin(phiClus[j]);
2153 double p0z = eClus[i] * cos(thetaClus[i]);
2154 double p1z = eClus[j] * cos(thetaClus[j]);
2155 ptpair = sqrt( (p0x+p1x)*(p0x+p1x) + (p0y+p1y)*(p0y+p1y));
2156 if (ptpair < ptpairCut )continue;
2157 TVector3 pairVect = TVector3((p0x+p1x), (p0y+p1y), (p0z+p1z));
2158 etapair = pairVect.Eta();
2159 phipair = pairVect.Phi();
2160
2161 ptmin = etClus[i]< etClus[j] ? etClus[i] : etClus[j] ;
2162 if( detector == reco::CaloID::DET_ECAL_ENDCAP){
2163 if( fabs(etapair) < eta_endcap_region1){
2164 if(ptmin < ptminCut_endcap_region1 || ptpair < ptpairCut_endcap_region1) continue;
2165 }else if (fabs(etapair)< eta_endcap_region2){
2166 if(ptmin < ptminCut_endcap_region2 || ptpair < ptpairCut_endcap_region2) continue;
2167 }else{
2168 if(ptmin < ptminCut_endcap_region3 || ptpair < ptpairCut_endcap_region3) continue;
2169 }
2170 }else{
2171
2172 if(ptmin < ptminCut || ptpair < ptpairCut) continue;
2173
2174 }
2175
2176
2177 mpair = sqrt ( (eClus[i] + eClus[j])*(eClus[i] + eClus[j]) - (p0x+p1x)*(p0x+p1x) - (p0y+p1y)*(p0y+p1y) - (p0z+p1z)*(p0z+p1z) );
2178
2179
2180 if( mpair < minvMinCut || mpair > minvMaxCut ) continue;
2181
2182 if(debug_>=2) cout<<"selpi0pair1: "<< ptpair <<" "<< etClus[i]<<" "<< etClus[j]<<" "<< s4s9Clus[i]<<" "<< s4s9Clus[j]<<" "<<mpair<<endl;
2183
2184
2185 ///Isolation
2186 isolation = 0;
2187 for(int k=0 ; k<nClus ; k++){
2188 if(k==i || k==j)continue;
2189 if( etClus[k] < isoptCut ) continue;
2190
2191 TVector3 clusVect = TVector3(etClus[k] *cos(phiClus[k]), etClus[k] * sin(phiClus[k]) , eClus[k] * cos(thetaClus[k]));
2192 double dretacl = fabs(etaClus[k] - pairVect.Eta());
2193 double drcl = clusVect.DeltaR(pairVect);
2194
2195 if( drcl < isodrCut && dretacl < isodetaCut ){
2196 isolation += etClus[k];
2197 }
2198 }
2199 isolation /= ptpair;
2200
2201
2202 if( isolation > isoCut ) continue;
2203
2204
2205 TVector3 vtmp0( xClus[i] - xOffPVwithBS, yClus[i] - yOffPVwithBS, zClus[i] - zOffPVwithBS);
2206 TVector3 vtmp1( xClus[j] - xOffPVwithBS, yClus[j] - yOffPVwithBS, zClus[j] - zOffPVwithBS);
2207 float cosd = getcosd( vtmp0.Eta(),vtmp0.Phi(),vtmp1.Eta(),vtmp1.Phi());
2208 mpairv1 = sqrt( 2 * eClus[i] * eClus[j] * (1- cosd));
2209
2210 indPairCand.push_back(i * nClus + j);
2211 mPairCand.push_back(mpair);
2212 mPairv1Cand.push_back(mpairv1);
2213 ptPairCand.push_back(ptpair);
2214 etaPairCand.push_back(etapair);
2215 phiPairCand.push_back(phipair);
2216 isoPairCand.push_back(isolation);
2217
2218 }
2219 }
2220
2221
2222 vector<int> pairRecoMatchedtoGenPiz;
2223 vector<int> pairRecoMatchedtoGen1stPhtInd; //the 1st photon int the pair matched to 0 /1 genpht
2224 vector<int> genpi0MatchedtoReco; //for pi0/eta both
2225
2226 float drMatch = 0.05;
2227 if( detector == reco::CaloID::DET_ECAL_BARREL){
2228 drMatch = 0.03;
2229 }
2230
2231 if( InputDataFormat_ <10){
2232 if(pizEta == PIZ){
2233 NtoNmatchingPi0(drMatch, indPairCand,pairRecoMatchedtoGenPiz,pairRecoMatchedtoGen1stPhtInd,genpi0MatchedtoReco);
2234 }else{
2235 NtoNmatchingEta(drMatch, indPairCand,pairRecoMatchedtoGenPiz,pairRecoMatchedtoGen1stPhtInd,genpi0MatchedtoReco);
2236 }
2237
2238 }
2239
2240
2241 ///Now Fill what selected
2242 for(int k=0; k< int(indPairCand.size()); k++){
2243
2244 mpair = mPairCand[k];
2245 mpairv1 = mPairv1Cand[k];
2246
2247 int i = indPairCand[k] / nClus;
2248 int j = indPairCand[k] % nClus;
2249
2250 ptpair = ptPairCand[k];
2251 etapair = etaPairCand[k];
2252 phipair = phiPairCand[k];
2253 isolation = isoPairCand[k];
2254 ptmin = etClus[i] < etClus[j]? etClus[i] : etClus[j];
2255
2256 s4s9min = s4s9Clus[i] < s4s9Clus[j] ? s4s9Clus[i] : s4s9Clus[j];
2257 s9s25min = s9s25Clus[i] < s9s25Clus[j] ? s9s25Clus[i] : s9s25Clus[j];
2258
2259
2260
2261
2262 if( InputDataFormat_ <10){
2263 for(int kk =0; kk<6; kk++) geninfo[kk]= -99;
2264 genMatched = 0;
2265 int indgen = pairRecoMatchedtoGenPiz[k];
2266 if(indgen>=0){
2267 genMatched = 1;
2268 int indga1 = pairRecoMatchedtoGen1stPhtInd[k];
2269 if(pizEta == PIZ){
2270 geninfo[0] = ePhtGenpi0[indgen][indga1];
2271 geninfo[1] = etaPhtGenpi0[indgen][indga1];
2272 geninfo[2] = phiPhtGenpi0[indgen][indga1];
2273 geninfo[3] = ePhtGenpi0[indgen][1-indga1];
2274 geninfo[4] = etaPhtGenpi0[indgen][1-indga1];
2275 geninfo[5] = phiPhtGenpi0[indgen][1-indga1];
2276
2277 convinfo[0] = isConvPhtGenpi0[indgen][indga1];
2278 convinfo[1] = isConvPhtGenpi0[indgen][1-indga1];
2279
2280 }else{
2281 geninfo[0] = ePhtGeneta[indgen][indga1];
2282 geninfo[1] = etaPhtGeneta[indgen][indga1];
2283 geninfo[2] = phiPhtGeneta[indgen][indga1];
2284 geninfo[3] = ePhtGeneta[indgen][1-indga1];
2285 geninfo[4] = etaPhtGeneta[indgen][1-indga1];
2286 geninfo[5] = phiPhtGeneta[indgen][1-indga1];
2287
2288 convinfo[0] = isConvPhtGeneta[indgen][indga1];
2289 convinfo[1] = isConvPhtGeneta[indgen][1-indga1];
2290
2291 }
2292
2293 }
2294 }
2295
2296
2297 int indtmp[2]={i,j};
2298
2299
2300 izXtalClus1 = 0;
2301 izXtalClus2 = 0;
2302
2303
2304 for(int jj =0; jj<2; jj++){
2305 int ind = indtmp[jj];
2306
2307 if( jj==0) nxtClus1 = int(RecHitsCluster[ind].size());
2308 else nxtClus2 = int(RecHitsCluster[ind].size());
2309
2310
2311 for(unsigned int Rec=0;Rec<RecHitsCluster[ind].size();Rec++) {
2312 int ietathis;
2313 int iphithis;
2314
2315 if( detector == reco::CaloID::DET_ECAL_BARREL){
2316 EBDetId det = (EBDetId)RecHitsCluster[ind][Rec].id();
2317 ietathis = det.ieta();
2318 iphithis = det.iphi();
2319 }else{
2320 EEDetId det = (EEDetId)RecHitsCluster[ind][Rec].id();
2321 ietathis = det.ix();
2322 iphithis = det.iy();
2323 if(jj==0) izXtalClus1 = det.zside();
2324 else izXtalClus2 = det.zside();
2325 }
2326 if( jj==0){
2327 eXtalClus1[Rec] = RecHitsCluster[ind][Rec].energy();
2328 ietaXtalClus1[Rec] = ietathis;
2329 iphiXtalClus1[Rec] = iphithis;
2330
2331 fXtalClus1[Rec] = RecHitsCluster[ind][Rec].recoFlag();
2332 tXtalClus1[Rec] = RecHitsCluster[ind][Rec].time();
2333 }else{
2334 ietaXtalClus2[Rec] = ietathis;
2335 iphiXtalClus2[Rec] = iphithis;
2336 fXtalClus2[Rec] = RecHitsCluster[ind][Rec].recoFlag();
2337 eXtalClus2[Rec] = RecHitsCluster[ind][Rec].energy();
2338 tXtalClus2[Rec] = RecHitsCluster[ind][Rec].time();
2339 }
2340 }
2341 }
2342
2343 if(pizEta==2){ //save also additional 5x5 around the 3x3 alredy saved
2344
2345 for(int jj =0; jj<2; jj++){
2346 int ind = indtmp[jj];
2347
2348 if( jj==0) nxt5x5Clus1 = int(RecHitsCluster5x5[ind].size());
2349 else nxt5x5Clus2 = int(RecHitsCluster5x5[ind].size());
2350
2351 for(unsigned int Rec=0;Rec<RecHitsCluster5x5[ind].size();Rec++) {
2352 int ietathis;
2353 int iphithis;
2354 if( detector == reco::CaloID::DET_ECAL_BARREL){
2355 EBDetId det = (EBDetId)RecHitsCluster5x5[ind][Rec].id();
2356 ietathis = det.ieta();
2357 iphithis = det.iphi();
2358 }else{
2359 EEDetId det = (EEDetId)RecHitsCluster5x5[ind][Rec].id();
2360 ietathis = det.ix();
2361 iphithis = det.iy();
2362 }
2363
2364 if( jj==0){
2365 eXtal5x5Clus1[Rec] = RecHitsCluster5x5[ind][Rec].energy();
2366 ietaXtal5x5Clus1[Rec] = ietathis;
2367 iphiXtal5x5Clus1[Rec] = iphithis;
2368 fXtal5x5Clus1[Rec] = RecHitsCluster5x5[ind][Rec].recoFlag();
2369 tXtal5x5Clus1[Rec] = RecHitsCluster5x5[ind][Rec].time();
2370 }else{
2371 ietaXtal5x5Clus2[Rec] = ietathis;
2372 iphiXtal5x5Clus2[Rec] = iphithis;
2373 fXtal5x5Clus2[Rec] = RecHitsCluster5x5[ind][Rec].recoFlag();
2374 eXtal5x5Clus2[Rec] = RecHitsCluster5x5[ind][Rec].energy();
2375 tXtal5x5Clus2[Rec] = RecHitsCluster5x5[ind][Rec].time();
2376 }
2377 }
2378 }
2379 }
2380
2381 ///Now finally fill the trees
2382
2383 if( detector == reco::CaloID::DET_ECAL_BARREL){
2384 if(pizEta ==1) mytree_pizeb->Fill();
2385 else mytree_etaeb->Fill();
2386 }else{
2387
2388 //adding preshower information as well
2389 if( storeRecHitES_){
2390
2391
2392 for(int jj =0; jj<2; jj++){
2393 for(int n=0; n<8; n++) {
2394 infoESX[jj][n] = 0;
2395 infoESY[jj][n] = 0;
2396 }
2397 int ind = indtmp[jj];
2398 std::vector<int>::iterator it = find(indClusSelected.begin(),indClusSelected.end(),ind);
2399 if( it == indClusSelected.end()){
2400 indClusSelected.push_back(ind);
2401
2402 double e1=0;
2403 double e2=0;
2404 double deltaE=0;
2405 double deltaE1=0;
2406 double deltaE2=0;
2407
2408 const GlobalPoint point(xClus[ind],yClus[ind],zClus[ind]);
2409
2410
2411 DetId tmp1 = (dynamic_cast<const EcalPreshowerGeometry*>(geometry_es))->getClosestCellInPlane(point, 1);
2412 DetId tmp2 = (dynamic_cast<const EcalPreshowerGeometry*>(geometry_es))->getClosestCellInPlane(point, 2);
2413 ESDetId strip1 = (tmp1 == DetId(0)) ? ESDetId(0) : ESDetId(tmp1);
2414 ESDetId strip2 = (tmp2 == DetId(0)) ? ESDetId(0) : ESDetId(tmp2);
2415
2416 std::set<DetId> used_strips_before = used_strips;
2417 // Get ES clusters (found by the PreshSeeded algorithm) associated with a given EE cluster.
2418 /// Energy weight cluster 1
2419 double wtposEs[2][3]={{0}};
2420 double mposEs[2][3]={{0}}; //energy highest
2421 double max_es[2]={0};
2422
2423 for (int i2=0; i2<preshNclust_; i2++) {
2424 reco::PreshowerCluster cl1 = presh_algo->makeOneCluster(strip1,&used_strips,&esrechits_map,geometry_es,topology_es);
2425 if ( cl1.energy() > preshClustECut) {
2426 e1 += cl1.energy();
2427
2428 wtposEs[0][0] += cl1.energy() * cl1.position().X();
2429 wtposEs[0][1] += cl1.energy() * cl1.position().Y();
2430 wtposEs[0][2] += cl1.energy() * cl1.position().Z();
2431
2432 if( cl1.energy() > max_es[0]){
2433 max_es[0] = cl1.energy() ;
2434 mposEs[0][0] = cl1.position().X();
2435 mposEs[0][1] = cl1.position().Y();
2436 mposEs[0][2] = cl1.position().Z();
2437 }
2438
2439 }
2440 reco::PreshowerCluster cl2 = presh_algo->makeOneCluster(strip2,&used_strips,&esrechits_map,geometry_es,topology_es);
2441 if ( cl2.energy() > preshClustECut) {
2442 e2 += cl2.energy();
2443 wtposEs[1][0] += cl2.energy() * cl2.position().X();
2444 wtposEs[1][1] += cl2.energy() * cl2.position().Y();
2445 wtposEs[1][2] += cl2.energy() * cl2.position().Z();
2446 if( cl2.energy() > max_es[1]){
2447 max_es[1] = cl2.energy();
2448 mposEs[1][0] = cl2.position().X();
2449 mposEs[1][1] = cl2.position().Y();
2450 mposEs[1][2] = cl2.position().Z();
2451 }
2452 }
2453 } // end of cycle over ES clusters
2454
2455 if(e1+e2 > 1.0E-10) {
2456
2457 if( e1 > 0){
2458 for(int n=0; n<3; n++){
2459 wtposEs[0][n] /= e1;
2460 }
2461 }
2462 if( e2 > 0){
2463 for(int n=0; n<3; n++){
2464 wtposEs[1][n] /= e2;
2465 }
2466 }
2467 // GeV to #MIPs
2468 e1 = e1 / mip_;
2469 e2 = e2 / mip_;
2470 deltaE = gamma_*(calib_planeX_*e1+calib_planeY_*e2);
2471 deltaE1 = gamma_*(calib_planeX_*e1);
2472 deltaE2 = gamma_*(calib_planeY_*e2);
2473
2474 max_es[0] *= gamma_*(calib_planeX_)/ mip_;
2475 max_es[1] *= gamma_*(calib_planeY_)/ mip_;
2476
2477 if(debug_>=2){
2478 cout<<"e1e1max: "<< deltaE1 <<" "<< max_es[0]<<" "<< deltaE2 <<" "<<max_es[1]<<endl;
2479 }
2480
2481 ///x plane
2482 infoESX[jj][0] = deltaE1;
2483 for(int n=0; n<3; n++){
2484 infoESX[jj][n+1] = wtposEs[0][n];
2485 }
2486 infoESX[jj][4] = max_es[0];
2487 for(int n=0; n<3; n++){
2488 infoESX[jj][n+5] = mposEs[0][n];
2489 }
2490 //y plane
2491 infoESY[jj][0] = deltaE2;
2492 for(int n=0; n<3; n++){
2493 infoESY[jj][n+1] = wtposEs[1][n];
2494 }
2495 infoESY[jj][4] = max_es[1];
2496 for(int n=0; n<3; n++){
2497 infoESY[jj][n+5] = mposEs[1][n];
2498 }
2499
2500 }
2501 //now push_back to the map of ES information
2502 vector<float> infoES_v;
2503 for(int n=0; n<8; n++) {
2504 infoES_v.push_back(infoESX[jj][n]) ;
2505 }
2506 for(int n=0; n<8; n++) {
2507 infoES_v.push_back(infoESY[jj][n]) ;
2508 }
2509 infoES_saved.insert( make_pair(ind, infoES_v) );
2510
2511
2512 }else{
2513 std::map<int, vector<float> >::iterator itmap = infoES_saved.find(ind);
2514 ///double es = (itmap->second).energy();
2515 if( itmap != infoES_saved.end()){
2516 for(int n=0;n<8; n++) infoESX[jj][n] = (itmap->second)[n];
2517 for(int n=0;n<8; n++) infoESY[jj][n] = (itmap->second)[n+8];
2518 }
2519 }
2520
2521 }
2522
2523 }
2524
2525 if(pizEta ==1) mytree_pizee->Fill();
2526 else mytree_etaee->Fill();
2527 } /// endcap
2528
2529
2530
2531 } ///end of filling tree
2532
2533
2534
2535
2536
2537
2538 delete topology_es;
2539
2540
2541
2542 }
2543
2544 void RecoAnalyzer::NtoNmatchingPi0(float drMatch, vector<int> pairReco ,vector<int> &pairRecoMatchedtoGen, vector<int> &pairRecoMatchedtoGen1stPhtInd,vector<int> &genpi0MatchedtoReco){
2545
2546 float zpht;
2547 float rpht;
2548 float xpht;
2549 float ypht;
2550
2551 //a list of pair reco ( direction w.r.t (0,0,0))
2552
2553 ///matched to a list of gen
2554
2555
2556 ////based on the smallest dr of sum of dr_photon1+ dr_photon2
2557 vector< std::pair<double,int> > dr_jk;
2558 int n =0;
2559
2560 ////try to use x,y,Z of cluster w.r.t to gen-Level pi0/eta
2561 ///bool useGenVtxforRecoGenMatch = true;
2562 int indga1 = 0;
2563
2564 vector< std::pair<int,int> > indga1_jk;
2565
2566
2567 for(int j=0; j< int(pairReco.size()); j++){
2568
2569 int j1 = pairReco[j]/nClus;
2570 int j2 = pairReco[j]%nClus;
2571
2572 int jtmp[2] = {j1,j2};
2573
2574 ////eta ,phi from (0,0,0);
2575 float eta_2pht[2] ={etaClus[j1],etaClus[j2]};
2576 float phi_2pht[2] ={phiClus[j1],phiClus[j2]};
2577 for(int tt=0;tt<2; tt++){
2578 TVector3 vv(xClus[jtmp[tt]],yClus[jtmp[tt]],zClus[jtmp[tt]]);
2579 eta_2pht[tt] = vv.Eta();
2580 phi_2pht[tt] = vv.Phi();
2581 }
2582
2583
2584 for(int k=0; k< nGenpi0; k++){
2585
2586 float dr_twopht[2]={1,1};
2587 float drsum = 0;
2588 float allDR[4];
2589
2590 int kk = 0;
2591 for( int k1 =0; k1<2; k1++){
2592 float eta = eta_2pht[k1];
2593 float phi = phi_2pht[k1];
2594
2595 for( int k2 = 0; k2<2; k2++){
2596
2597 zpht = vtxPhtGenpi0[k][2];
2598 rpht = sqrt( vtxPhtGenpi0[k][0] * vtxPhtGenpi0[k][0] + vtxPhtGenpi0[k][1] * vtxPhtGenpi0[k][1]);
2599 xpht = vtxPhtGenpi0[k][0];
2600 ypht = vtxPhtGenpi0[k][1];
2601
2602 float etag = etaPhtGenpi0[k][k2];
2603 float phig = phiPhtGenpi0[k][k2];
2604
2605 etag = ecalEta(etaPhtGenpi0[k][k2],zpht,rpht);
2606 phig = ecalPhi(phiPhtGenpi0[k][k2],xpht,ypht);
2607
2608
2609
2610 allDR[kk] = GetDeltaR(eta,etag,phi,phig);
2611 kk++;
2612
2613 }
2614 }
2615
2616 float drsum1 = allDR[0] + allDR[3];
2617 float drsum2 = allDR[1] + allDR[2];
2618 drsum = drsum1 < drsum2? drsum1: drsum2;
2619
2620 if(drsum1<drsum2){
2621 dr_twopht[0] = allDR[0];
2622 dr_twopht[1] = allDR[3];
2623 indga1 = 0;
2624 }else{
2625 dr_twopht[0] = allDR[1];
2626 dr_twopht[1] = allDR[2];
2627 indga1 = 1;
2628 }
2629
2630 if( dr_twopht[0]< drMatch && dr_twopht[1] < drMatch){
2631 dr_jk.push_back( make_pair ( drsum, n));
2632
2633 indga1_jk.push_back( make_pair ( indga1, n));
2634 }
2635
2636 n++;
2637
2638 }
2639 }
2640
2641
2642 sort(dr_jk.begin(),dr_jk.end(),sort_pred);
2643
2644 vector<int> nn_matched;
2645 vector<int> j_used;
2646 vector<int> k_used;
2647 vector<int>::iterator it;
2648 vector<int>::iterator it2;
2649
2650 int nn = int( dr_jk.size());
2651
2652 for(int n=0; n< nn; n++){
2653
2654 int nn0 = dr_jk[n].second;
2655 int j = nn0 / nGenpi0;
2656 int k = nn0 % nGenpi0;
2657
2658 it = find(j_used.begin(),j_used.end(),j);
2659 it2 = find(k_used.begin(),k_used.end(),k);
2660
2661 if( it == j_used.end() && it2 == k_used.end()){
2662 j_used.push_back(j);
2663 k_used.push_back(k);
2664 nn_matched.push_back(nn0); /// this matters a lot if to use more than once when matching...
2665 }
2666 }
2667
2668
2669 ///nn_matched are the final matched pair reco <==> gen pi0
2670 for(int j=0; j< int(pairReco.size()); j++){
2671 int matched = -1; //if matched, be the index in the array of genpi0
2672 int nn0 = -1;
2673 for(int n=0; n< int( nn_matched.size()); n++){
2674 int j1 = nn_matched[n]/ nGenpi0;
2675 int k = nn_matched[n] % nGenpi0;
2676 if( j1 == j){
2677 matched = k;
2678 nn0 = nn_matched[n];
2679 break;
2680 }
2681 }
2682
2683 ////cout<<"pairREco Mathced: "<< j<<" "<< matched <<endl;
2684
2685 pairRecoMatchedtoGen.push_back(matched);
2686 indga1 = 0;
2687 for(int n =0; n< int( indga1_jk.size()); n++){
2688 if( indga1_jk[n].second == nn0){
2689 indga1 = indga1_jk[n].first;
2690 n = int( indga1_jk.size()+1);
2691 }
2692 }
2693 pairRecoMatchedtoGen1stPhtInd.push_back(indga1);
2694
2695 }
2696
2697
2698
2699 }
2700
2701 void RecoAnalyzer::NtoNmatchingEta(float drMatch, vector<int> pairReco ,vector<int> &pairRecoMatchedtoGen, vector<int> &pairRecoMatchedtoGen1stPhtInd, vector<int> &genetaMatchedtoReco){
2702
2703
2704 float zpht;
2705 float rpht;
2706 float xpht;
2707 float ypht;
2708
2709 //a list of pair reco ( direction w.r.t (0,0,0))
2710
2711 ///matched to a list of gen
2712 int indga1 = 0;
2713 vector< std::pair<int,int> > indga1_jk;
2714
2715
2716
2717 ////based on the smallest dr of sum of dr_photon1+ dr_photon2
2718 vector< std::pair<double,int> > dr_jk;
2719 int n =0;
2720
2721 ////try to use x,y,Z of cluster w.r.t to gen-Level eta/eta
2722 ///bool useGenVtxforRecoGenMatch = true;
2723
2724
2725 for(int j=0; j< int(pairReco.size()); j++){
2726
2727 int j1 = pairReco[j]/nClus ;
2728 int j2 = pairReco[j]%nClus;
2729
2730 int jtmp[2] = {j1,j2};
2731
2732 ////eta ,phi from (0,0,0);
2733 float eta_2pht[2] ={etaClus[j1],etaClus[j2]};
2734 float phi_2pht[2] ={phiClus[j1],phiClus[j2]};
2735 for(int tt=0;tt<2; tt++){
2736 TVector3 vv(xClus[jtmp[tt]],yClus[jtmp[tt]],zClus[jtmp[tt]]);
2737 eta_2pht[tt] = vv.Eta();
2738 phi_2pht[tt] = vv.Phi();
2739 }
2740
2741
2742 for(int k=0; k< nGeneta; k++){
2743
2744 float dr_twopht[2]={1,1};
2745 float drsum = 0;
2746 float allDR[4];
2747
2748 int kk = 0;
2749 for( int k1 =0; k1<2; k1++){
2750 float eta = eta_2pht[k1];
2751 float phi = phi_2pht[k1];
2752
2753 for( int k2 = 0; k2<2; k2++){
2754
2755 zpht = vtxPhtGeneta[k][2];
2756 rpht = sqrt( vtxPhtGeneta[k][0] * vtxPhtGeneta[k][0] + vtxPhtGeneta[k][1] * vtxPhtGeneta[k][1]);
2757 xpht = vtxPhtGeneta[k][0];
2758 ypht = vtxPhtGeneta[k][1];
2759
2760 float etag = etaPhtGeneta[k][k2];
2761 float phig = phiPhtGeneta[k][k2];
2762 etag = ecalEta(etaPhtGeneta[k][k2],zpht,rpht);
2763 phig = ecalPhi(phiPhtGeneta[k][k2],xpht,ypht);
2764
2765 allDR[kk] = GetDeltaR(eta,etag,phi,phig);
2766 kk++;
2767
2768 }
2769 }
2770
2771 float drsum1 = allDR[0] + allDR[3];
2772 float drsum2 = allDR[1] + allDR[2];
2773 drsum = drsum1 < drsum2? drsum1: drsum2;
2774
2775 if(drsum1<drsum2){
2776 dr_twopht[0] = allDR[0];
2777 dr_twopht[1] = allDR[3];
2778 }else{
2779 dr_twopht[0] = allDR[1];
2780 dr_twopht[1] = allDR[2];
2781 }
2782
2783 if( dr_twopht[0]< drMatch && dr_twopht[1] <drMatch ){
2784 dr_jk.push_back( make_pair ( drsum, n));
2785 indga1_jk.push_back( make_pair ( indga1, n));
2786
2787
2788 }
2789
2790 n++;
2791
2792 }
2793 }
2794
2795
2796 sort(dr_jk.begin(),dr_jk.end(),sort_pred);
2797
2798 vector<int> nn_matched;
2799 vector<int> j_used;
2800 vector<int> k_used;
2801 vector<int>::iterator it;
2802 vector<int>::iterator it2;
2803
2804 int nn = int( dr_jk.size());
2805
2806 for(int n=0; n< nn; n++){
2807
2808 int nn0 = dr_jk[n].second;
2809 int j = nn0 / nGeneta;
2810 int k = nn0 % nGeneta;
2811
2812 it = find(j_used.begin(),j_used.end(),j);
2813 it2 = find(k_used.begin(),k_used.end(),k);
2814
2815 if( it == j_used.end() && it2 == k_used.end()){
2816 j_used.push_back(j);
2817 k_used.push_back(k);
2818 nn_matched.push_back(nn0); /// this matters a lot if to use more than once when matching...
2819 }
2820
2821 }
2822
2823
2824 ///nn_matched are the final matched pair reco <==> gen eta
2825 for(int j=0; j< int(pairReco.size()); j++){
2826 int matched = -1; //if matched, be the index in the array of geneta
2827
2828 int nn0 = -1;
2829
2830 for(int n=0; n< int( nn_matched.size()); n++){
2831 int j1 = nn_matched[n]/ nGeneta;
2832 int k = nn_matched[n] % nGeneta;
2833 if( j1 == j){
2834 matched = k;
2835
2836 nn0 = nn_matched[n];
2837
2838 break;
2839 }
2840 }
2841
2842 ////cout<<"pairREco Mathced: "<< j<<" "<< matched <<endl;
2843
2844 pairRecoMatchedtoGen.push_back(matched);
2845 indga1 = 0;
2846 for(int n =0; n< int( indga1_jk.size()); n++){
2847 if( indga1_jk[n].second == nn0){
2848 indga1 = indga1_jk[n].first;
2849 n = int( indga1_jk.size()+1); ///break;
2850 }
2851 }
2852 pairRecoMatchedtoGen1stPhtInd.push_back(indga1);
2853
2854
2855 }
2856
2857 }
2858
2859
2860
2861 //define this as a plug-in
2862 DEFINE_FWK_MODULE(RecoAnalyzer);