BOSS 7.1.0
BESIII Offline Software System
Loading...
Searching...
No Matches
EmcSelBhaEvent.cxx
Go to the documentation of this file.
1//--------------------------------------------------------------------------
2// File and Version Information:
3//
4// Description:
5// Class EmcSelBhaEvent - Select Bhabha events (MCdata) for Emc-digi
6// Calibration; read rec-data, read MDC & Emc information from tracklist
7// and select Bhabha event
8//
9// Environment:
10// Software developed for the BESIII Detector at the BEPCII.
11//
12// Author List:
13// Chunxiu Liu
14//
15// Copyright Information:
16// Copyright (C) 2008 IHEP
17//
18//------------------------------------------------------------------------
19
20
21//-----------------------
22
23
24//-------------
25// C Headers --
26//-------------
27extern "C" {
28
29}
30#include <iostream>
31#include <fstream>
32#include <cmath>
33#include <cassert>
34#include <cstdlib>
35//-------------------------------
36// Collaborating Class Headers --
37//-------------------------------
38
39#include "GaudiKernel/MsgStream.h"
40#include "GaudiKernel/AlgFactory.h"
41#include "GaudiKernel/SmartDataPtr.h"
42#include "GaudiKernel/IDataProviderSvc.h"
43#include "GaudiKernel/PropertyMgr.h"
44#include "GaudiKernel/ISvcLocator.h"
45#include "GaudiKernel/Bootstrap.h"
46
48#include "EventModel/Event.h"
49
51
54#include "EmcRawEvent/EmcDigi.h"
58
59#include "CLHEP/Vector/ThreeVector.h"
60#include "CLHEP/Geometry/Point3D.h"
61#ifndef ENABLE_BACKWARDS_COMPATIBILITY
63#endif
64#include "CLHEP/Random/RandGauss.h"
65
66using namespace std;
67using namespace Event;
68using CLHEP::Hep3Vector;
69using CLHEP::RandGauss;
70
71#include <vector>
72#include <list>
73typedef std::vector<int> Vint;
74typedef std::vector<HepLorentzVector> Vp4;
75
76DECLARE_COMPONENT(EmcSelBhaEvent)
77//----------------
78// Constructors --
79//----------------
80EmcSelBhaEvent::EmcSelBhaEvent(const std::string& name, ISvcLocator* pSvcLocator)
81 :Algorithm(name, pSvcLocator),
82 m_vr0cut(1.0),
83 m_vz0cut(5.0),
84 m_lowEnergyShowerCut(0.1),
85 m_highEnergyShowerCut(0.5),
86 m_matchThetaCut(0.2),
87 m_matchPhiCut(0.2),
88 m_highMomentumCut(0.5),
89 m_EoPMaxCut(1.3),
90 m_EoPMinCut(0.6),
91 m_minAngShEnergyCut(0.2),
92 m_minAngCut(0.3),
93 m_acolliCut(0.03),
94 m_eNormCut(0.5),
95 m_pNormCut(0.5),
96 m_oneProngMomentumCut(1.2),
97
98 m_digiRangeCut(6),
99 m_ShEneThreshCut(0.02),
100 m_ShEneLeptonCut(1.),
101 m_minNrXtalsShowerCut(10),
102 m_maxNrXtalsShowerCut(70),
103 m_phiDiffMinCut(0.05),
104 m_phiDiffMaxCut(0.2),
105 m_nrShThreshCut(20),
106 m_thetaDiffCut(0.04),
107 m_LATCut(0.8),
108
109 m_showersAccepted(0),
110 //--------------------
111 m_writeMVToFile(true),
112 m_fileExt(""),
113 m_inputFileDir("../InputData/"),
114 m_fileDir("/home/besdata/public/liucx/Calib/"),
115 m_selMethod("Ixtal"),
116 m_nXtals(6240),
117 m_sigmaCut(1.),
118 m_beamEnergy(1.843),
119 m_MsgFlag(0),
120 m_Num(0),
121 m_fileNum(0)
122
123{
124
125 // Declare the properties
126
127
128 declareProperty ("Vr0cut", m_vr0cut); // suggest cut: |z0|<5cm && r0<1cm
129 declareProperty ("Vz0cut", m_vz0cut);
130
131 declareProperty ("lowEnergyShowerCut", m_lowEnergyShowerCut);
132 declareProperty ("highEnergyShowerCut", m_highEnergyShowerCut);
133 declareProperty ("matchThetaCut", m_matchThetaCut);
134 declareProperty ("matchPhiCut", m_matchPhiCut);
135
136 declareProperty ("highMomentumCut", m_highMomentumCut);
137 declareProperty ("EoPMaxCut", m_EoPMaxCut);
138 declareProperty ("EoPMinCut", m_EoPMinCut);
139 declareProperty ("minAngShEnergyCut", m_minAngShEnergyCut);
140 declareProperty ("minAngCut", m_minAngCut);
141 declareProperty ("acolliCut", m_acolliCut);
142 declareProperty ("eNormCut", m_eNormCut);
143 declareProperty ("pNormCut", m_pNormCut);
144 declareProperty ("oneProngMomentumCut", m_oneProngMomentumCut);
145
146 // *
147
148 declareProperty("digiRangeCut", m_digiRangeCut);
149
150 declareProperty("ShEneThreshCut", m_ShEneThreshCut);
151 declareProperty("ShEneLeptonCut", m_ShEneLeptonCut);
152
153 declareProperty("minNrXtalsShowerCut", m_minNrXtalsShowerCut);
154 declareProperty("maxNrXtalsShowerCut", m_maxNrXtalsShowerCut);
155 declareProperty("phiDiffMinCut", m_phiDiffMinCut);
156 declareProperty("phiDiffMaxCut", m_phiDiffMaxCut);
157 declareProperty("nrShThreshCut", m_nrShThreshCut);
158 declareProperty("thetaDiffCut", m_thetaDiffCut);
159 declareProperty("LATCut", m_LATCut);
160
161 //--------------------
162 declareProperty("writeMVToFile", m_writeMVToFile);
163 declareProperty("fileExt", m_fileExt);
164 declareProperty("fileDir", m_fileDir);
165 declareProperty("inputFileDir", m_inputFileDir);
166 declareProperty("selMethod",m_selMethod);
167 declareProperty("sigmaCut", m_sigmaCut);
168 declareProperty("ReadBeamEFromDB", m_ReadBeamEFromDB = false );
169
170 declareProperty("beamEnergy", m_beamEnergy);
171 declareProperty("Dbeam", m_dbeam=0.00);
172
173 declareProperty("UseBeamDetectorEnergy", m_useBeamDetectorEnergy=false);
174
175 declareProperty("elecSaturation", m_elecSaturation = true );
176
177 declareProperty("MsgFlag", m_MsgFlag);
178 declareProperty("Num", m_Num);
179 declareProperty("fileNum", m_fileNum);
180
181 int j = 0;
182 m_index = new int*[56];
183 for (j=0;j<56;j++ ) {
184 m_index[j] = new int[120];
185 for ( int k=0; k<120; k++) {
186 m_index[j][k]=-1;
187 }
188 }
189
190 m_iGeoSvc=0;
191
192 for (int i=0; i<6240;i++)
193 {
194 m_inputConst[i] = 1.0;
195 }
196
197 m_irun=0;
198}
199
200//--------------
201// Destructor --
202//--------------
204
205 if ( m_index != 0 ) {
206 for (int i =0; i<56; i++ )
207 delete[] m_index[i];
208 delete[] m_index;
209 m_index = 0;
210 }
211
212 ///////////
213 for (int j=0;j<6240;j++ ) {
214 m_measure[j]=-1;
215 }
216}
217// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
219
220 MsgStream log(msgSvc(), name());
221 log << MSG::INFO << "in initialize()" << endreq;
222
223 //---------------------------------------<<<<<<<<<<
224 m_showersAccepted=0;
225 m_events=0;
226 m_Nothing=0;
227 m_OneProng=0;
228 //number of events with TwoProngMatched
229 m_TwoProngMatched=0;
230 //number of events with TwoProngOneMatched
231 m_TwoProngOneMatched=0;
232
233 //--------------------------------------->>>>>>>>>>>
234 //initialize Emc geometry to convert between index <=> theta,phi
235 initGeom();
236
237 //create the object that holds the calibration data
238 if ( m_writeMVToFile )
239 myCalibData = new EmcBhaCalibData(m_nXtals,m_MsgFlag);
240 else
241 myCalibData = 0;
242
243 //get EmcRecGeoSvc
244
245 ISvcLocator* svcLocator = Gaudi::svcLocator();
246 StatusCode sc = svcLocator->service("EmcRecGeoSvc",m_iGeoSvc);
247 if(sc!=StatusCode::SUCCESS) {
248 cout<<"Error: Can't get EmcRecGeoSvc"<<endl;
249 }
250
251 /*
252 // use EmcCalibConstSvc
253 StatusCode scCalib;
254 scCalib = Gaudi::svcLocator() -> service("EmcCalibConstSvc", m_emcCalibConstSvc);
255 if( scCalib != StatusCode::SUCCESS){
256 log << MSG::ERROR << "can not use EmcCalibConstSvc" << endreq;
257 }
258 else {
259 std::cout << "Test EmcCalibConstSvc DigiCalibConst(0)= "
260 << m_emcCalibConstSvc -> getDigiCalibConst(0) << std::endl;
261 }
262 */
263
264 StatusCode scBeamEnergy;
265 scBeamEnergy = Gaudi::svcLocator() -> service("BeamEnergySvc", m_BeamEnergySvc);
266
267 if( scBeamEnergy != StatusCode::SUCCESS){
268 log << MSG::ERROR << "can not use BeamEnergySvc" << endreq;
269 }
270
271
272
273 // read correction function from the file of 'cor.conf'
274 //from MC Bhabha data,
275 // expected depostion energy for bhabha calibration at cms. system
276 //it is as a function of thetaID(0-55)
277 readCorFun();
278 // read Esigma(Itheta)
279 //from MC Bhabha data,
280 //it is as a function of thetaID(0-55) from the file of 'sigma.conf'
281 readEsigma();
282
283 //read peak of bhabha rawdata before bhabha calibration,
284 //it is as a function of thetaID(0-55) from the file of "peakI.conf"
286
287 //read sigma of bhabha rawdata before bhabha calibration,
288 //it is as a function of thetaID(0-55) from the file of "sigmaI.conf"
289 readSigmaExp();
291 //read data/mc(expected) with ixtal
293 /*
294 ofstream out;
295 out.open("expectedE.conf");
296 for(int i=0; i<6240;i++){
297 out<<i<<"\t"<<expectedEnergy(i)<<endl;
298 }
299 out.close();
300 */
301 return StatusCode::SUCCESS;
302}
303
304// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
306
307 MsgStream log(msgSvc(), name());
308 log << MSG::DEBUG << "in execute()" << endreq;
309
310 //create the object that store the needed data of the Bhabha event
311
312 int event, run;
313
314 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
315
316 run=eventHeader->runNumber();
317 event=eventHeader->eventNumber();
318 //cout<<"---------"<<event<<".........."<<run<<endl;
319 m_events++;
320 m_run = run;
321
322
323 //////////////////
324 // get beam energy
325 //////////////////
326 if(m_ReadBeamEFromDB&&m_irun!=run){
327 m_irun=run;
328 m_BeamEnergySvc ->getBeamEnergyInfo();
329 if(m_BeamEnergySvc->isRunValid())
330 m_beamEnergy=m_BeamEnergySvc->getbeamE();
331 // if(m_readDb.isRunValid(m_irun))
332 // m_beamEnergy=m_readDb.getbeamE(m_irun);
333 //if(m_BeamEnergySvc->isRunValid())
334 // m_beamEnergy=m_BeamEnergySvc->getbeamE();
335 cout<< "beamEnergy="<< m_beamEnergy<<endl;
336 m_beamEnergy=m_beamEnergy-m_dbeam;
337
338 double the=0.011;
339 double phi=0;
340 HepLorentzVector ptrk;
341 ptrk.setPx(m_beamEnergy*sin(the)*cos(phi));
342 ptrk.setPy(m_beamEnergy*sin(the)*sin(phi));
343 ptrk.setPz(m_beamEnergy*cos(the));
344 ptrk.setE(m_beamEnergy);
345
346 ptrk=ptrk.boost(-0.011,0,0);
347
348 cout<< "beamEnergy="<< m_beamEnergy<<" cms "<<ptrk.e()<<" ratio="<< (m_beamEnergy-ptrk.e())/ptrk.e()<<endl;
349 m_beamEnergy=ptrk.e();
350 }
351
352
353 if(m_useBeamDetectorEnergy){
354
355
356 IScanEnergySvc* m_ScanEnergySvc=0;
357 StatusCode scScan;
358 scScan = Gaudi::svcLocator()->service("ScanEnergySvc", m_ScanEnergySvc);
359 if( scScan != StatusCode::SUCCESS){
360 cout << "can not use ScanEnergySvc" << endreq;
361 }
362 else {
363
364 std::cout << "Test ScanEnergySvc getScanEnergy= "
365 << m_ScanEnergySvc -> getScanEnergy()
366 << std::endl;
367 m_beamEnergy= m_ScanEnergySvc -> getScanEnergy()/2.0/1000.;
368 cout<< "ScanbeamEnergy="<< m_beamEnergy<<endl;
369 }
370 }
371
372
373
374
375
376 ////////////
377 // int mmea=0;
378
379 for (int j=0;j<6240;j++ ) {
380 m_measure[j]=-1;
381 }
382
383 if (m_elecSaturation==true)
384 {
385
386 ///////////////////////////find Measure/////////////
387 SmartDataPtr<EmcDigiCol> emcDigiCol(eventSvc(),"/Event/Digi/EmcDigiCol");
388 if (!emcDigiCol) {
389 log << MSG::FATAL << "Could not find EMC digi" << endreq;
390 return( StatusCode::FAILURE);
391 }
392
393 EmcDigiCol::iterator iter3;
394 for (iter3=emcDigiCol->begin();iter3!= emcDigiCol->end();iter3++) {
395 RecEmcID id((*(iter3))->identify());
396 //cout<<id<<endl;
397
398 unsigned int npart,ntheta,nphi;
399 npart = EmcID::barrel_ec(id);
400 ntheta = EmcID::theta_module(id);
401 nphi = EmcID::phi_module(id);
402
403 unsigned int newthetaInd;
404 if (npart==0) newthetaInd = ntheta;
405 if (npart==1) newthetaInd = ntheta + 6;
406 if (npart==2) newthetaInd = 55 - ntheta;
407
408 int ixtal= index(newthetaInd,nphi);
409 m_measure[ixtal]=(*iter3)->getMeasure();
410 //if ((*iter3)->getMeasure()==3) mmea=9;
411
412 }
413 }
414
415 ////////////
416
417 myBhaEvt = new EmcBhabhaEvent();
418
419 //Select Bhabha
420 SelectBhabha();
421 if(m_selectedType == BhabhaType::OneProng) m_OneProng++;
422 //number of events with TwoProngMatched
423 if(m_selectedType == BhabhaType::TwoProngMatched) m_TwoProngMatched++;
424 //number of events with TwoProngOneMatched
425 if(m_selectedType == BhabhaType::TwoProngOneMatched) m_TwoProngOneMatched++;
426
427 if(m_selectedType == BhabhaType::Nothing){
428 m_Nothing++;
429 }
430
431 //retreive shower list of event
432
433 if (m_selectedType == BhabhaType::TwoProngMatched) {
434 FillBhabha();
435
436 //collect bhabha event for digi-calibration of EMC
437 //and fill matrix and vector of system of linear equations
439 }
440
441 delete myBhaEvt;
442 myBhaEvt=0;
443
444 return StatusCode::SUCCESS;
445}
446
447// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
449
450 MsgStream log(msgSvc(), name());
451
452 log << MSG::INFO << "in finalize()" << endreq;
453
454 //output the data of Matrix and vector to files
455 OutputMV();
456 /*
457 for (int i=1000; i < 1500; i++) {
458 int xtalIndex=myCalibData->xtalInd(i);
459
460 int nhitxtal=myCalibData->xtalHitsDir(xtalIndex);
461 cout<<"ixtal, Nhitdir="<< xtalIndex<<" "<<nhitxtal<<endl;
462
463 }
464 */
465 if ( m_writeMVToFile ) {
466 delete myCalibData;
467 myCalibData = 0;
468 }
469
470 cout<<"Event="<<m_events<<endl;
471
472 cout<<"m_Nothing ="<<m_Nothing <<endl;
473 cout<<"m_OneProng="<<m_OneProng<<endl;
474
475 cout<<"m_TwoProngMatched="<<m_TwoProngMatched<<endl;
476
477 cout<<"m_TwoProngOneMatched="<<m_TwoProngOneMatched<<endl;
478
479 cout<<"m_showersAccepted="<<m_showersAccepted<<endl;
480
481 return StatusCode::SUCCESS;
482}
483
484
485
486// * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
487
488double
489EmcSelBhaEvent::expectedEnergy( long int ixtal ) {
490
491 EmcStructure* theEmcStruc=new EmcStructure() ;
492 theEmcStruc->setEmcStruc();
493
494 unsigned int module, ntheta, nphi,ThetaIndex;
495
496 module=theEmcStruc->getPartId(ixtal);
497 ntheta=theEmcStruc->getTheta(ixtal);
498 nphi=theEmcStruc->getPhi(ixtal);
499
500 if (module==0) ThetaIndex = ntheta;
501 if (module==1) ThetaIndex = ntheta + 6;
502 if (module==2) ThetaIndex = 55 - ntheta;
503
504 RecEmcID shId= EmcID::crystal_id(module,ntheta,nphi);
505 HepPoint3D SeedPos(0,0,0);
506 SeedPos=m_iGeoSvc->GetCFrontCenter(shId);
507
508
509 double theta=SeedPos.theta();
510 double phi=SeedPos.phi();
511 HepLorentzVector ptrk;
512 ptrk.setPx(m_beamEnergy*sin(theta)*cos(phi));
513 ptrk.setPy(m_beamEnergy*sin(theta)*sin(phi));
514 ptrk.setPz(m_beamEnergy*cos(theta));
515 ptrk.setE(m_beamEnergy);
516
517 ptrk=ptrk.boost(0.011,0,0);
518
519 double depoEne_lab = m_corFun[ThetaIndex]*ptrk.e();
520
521 return depoEne_lab;
522}
523
524
525// * * * * * * * * * * * *
526
528
529 MsgStream log(msgSvc(), name());
530
531 SmartDataPtr<EvtRecEvent> evtRecEvent(eventSvc(), EventModel::EvtRec::EvtRecEvent);
532
533 SmartDataPtr<EvtRecTrackCol> evtRecTrkCol(eventSvc(), EventModel::EvtRec::EvtRecTrackCol);
534
535 m_selectedType = BhabhaType::Nothing;
536 m_events++;
537
538 /*
539 Vint iGood;
540 iGood.clear();
541 int nCharge = 0;
542 int numberOfTrack = 0;
543
544 //the accumulated event information
545 double totalEnergy = 0.;
546 int numberOfShowers = 0;
547 int numberOfShowersWithTrack = 0;
548 bool secondUnMTrackFound=false;
549 float eNorm = 0.;
550 float pNorm = 0.;
551 float acolli_min = 999.;
552 double minAngFirstSh = 999., minAngSecondSh = 999.;
553 float theFirstTracksTheta = 0;
554 float theFirstTracksMomentum = 0;
555
556 //the selection candidates
557 RecMdcTrack *theFirstTrack = 0;
558 RecMdcTrack *theSecondTrack = 0;
559 RecMdcTrack *theKeptTrack = 0;
560 RecEmcShower *theFirstShower = 0;
561
562 RecEmcShower *theSecondShower = 0;
563 RecEmcShower *theKeptShower = 0;
564 double keptTheta = 0.;
565 int theFirstShID = 9999;
566 int theSecondShID = 9999;
567 int theKeptShID = 9999;
568 int theTrkID = 9999;
569 */
570
571 Vint iGam;
572 iGam.clear();
573
574 //double ene5x5,theta,phi,eseed;
575 //double showerX,showerY,showerZ;
576 //long int thetaIndex,phiIndex;
577 //HepPoint3D showerPosition(0,0,0);
578 // RecEmcID showerId;
579 //unsigned int npart;
580
581 for(int i = 0; i < evtRecEvent->totalTracks(); i++){
582
583 if(i>=evtRecTrkCol->size()) break;
584
585 EvtRecTrackIterator itTrk=evtRecTrkCol->begin() + i;
586
587 if((*itTrk)->isEmcShowerValid()) {
588
589
590 RecEmcShower *theShower = (*itTrk)->emcShower();
591 int TrkID = (*itTrk)->trackId();
592 double Shower5x5=theShower->e5x5();
593 //cout<<"Shower5x5="<<Shower5x5<<endl;
594 /*
595 ene5x5=theShower->e5x5(); //uncorrected 5x5 energy unit GeV
596 eseed=theShower->eSeed(); //unit GeV
597
598 showerPosition = theShower->position();
599 theta = theShower->theta();
600 phi= theShower->phi();
601 showerX=theShower->x();
602 showerY=theShower->y();
603 showerZ=theShower->z();
604
605 showerId = theShower->getShowerId();
606
607 npart = EmcID::barrel_ec(showerId);
608
609 //The theta number is defined by Endcap_east(0-5),Barrel(0-43),Endcap_west(0-5)
610 //module is defined by Endcap_east(0),Barrel(1),Endcap_west(2)
611
612 thetaIndex=EmcID::theta_module(showerId);
613
614 phiIndex=EmcID::phi_module(showerId);
615 */
616
617 if (Shower5x5>(0.6*m_beamEnergy)){
618
619 iGam.push_back( TrkID );
620
621
622 }
623
624 }
625 }
626 int nGam = iGam.size();
627 //log << MSG::DEBUG << "num Good Photon " << nGam << " , " <<evtRecEvent->totalNeutral() <<endreq;
628
629
630 if (nGam==2) {
631
632 m_selectedType = BhabhaType::TwoProngMatched;
633 m_selectedTrkID1 =iGam[0];
634 m_selectedTrkID2 = iGam[1];
635
636 }
637
638
639 return StatusCode::SUCCESS;
640
641}
642
643
644// * * * * * * * * * * * *
645void
647
648 MsgStream log(msgSvc(), name());
649
650 SmartDataPtr<EvtRecEvent> evtRecEvent(eventSvc(), EventModel::EvtRec::EvtRecEvent);
651 SmartDataPtr<EvtRecTrackCol> evtRecTrkCol(eventSvc(), EventModel::EvtRec::EvtRecTrackCol);
652
653 EvtRecTrackIterator itTrk1 = evtRecTrkCol->begin() + m_selectedTrkID1;
654
655 RecEmcShower *theShower1 = (*itTrk1)->emcShower();
656 //RecMdcTrack *theMdcTrk1 = (*itTrk1)->mdcTrack();
657
658 EvtRecTrackIterator itTrk2 = evtRecTrkCol->begin() + m_selectedTrkID2;
659
660 RecEmcShower *theShower2 = (*itTrk2)->emcShower();
661 //RecMdcTrack *theMdcTrk2 = (*itTrk2)->mdcTrack();
663 RecEmcShower *theShower;
664
665
666 // * * * * * * * * * * * * * * * * * * * * * * * * * ** * ** *
667 //loop all showers of an event set EmcShower and EmcShDigi
668
669 EmcShower* aShower =new EmcShower();
670
671 double ene,theta,phi,eseed;
672 double showerX,showerY,showerZ;
673 long int thetaIndex,phiIndex,numberOfDigis;
674
675 RecEmcID showerId;
676 unsigned int showerModule;
677
678 HepPoint3D showerPosition(0,0,0);
679
680 if ( ! m_showerList.empty()) m_showerList.clear();
681
682 for (int ish=0; ish<2; ish++){
683
684 if (ish==0) {
685 itTrk= itTrk1;
686 theShower=theShower1;
687 }
688 if (ish==1) {
689 itTrk= itTrk2;
690 theShower=theShower2;
691 }
692 //ene=theShower->energy(); //corrected shower energy unit GeV
693 ene=theShower->e5x5(); //uncorrected 5x5 energy unit GeV
694 eseed=theShower->eSeed(); //unit GeV
695
696
697 /////////////////
698 /*
699 RecExtTrack *extTrk = (*itTrk)->extTrack();
700
701 Hep3Vector extpos = extTrk->emcPosition();
702
703 cout<<"Extpos="<<extpos<<endl;
704
705
706 RecEmcShower *theShower = (*itTrk)->emcShower();
707
708 Hep3Vector emcpos(theShower->x(), theShower->y(), theShower->z());
709
710 cout<<"emcpos="<<emcpos<<endl;
711
712 RecEmcID shId= theShower->getShowerId();
713 unsigned int nprt= EmcID::barrel_ec(shId);
714 //RecEmcID cellId= theShower->cellId();
715 HepPoint3D SeedPos(0,0,0);
716 SeedPos=m_iGeoSvc->GetCFrontCenter(shId);
717 cout<<"SeedPos="<<SeedPos<<endl;
718 */
719 //////////////////
720
721 showerPosition = theShower->position();
722 theta = theShower->theta();
723 phi= theShower->phi();
724 showerX=theShower->x();
725 showerY=theShower->y();
726 showerZ=theShower->z();
727
728 showerId = theShower->getShowerId();
729 showerModule = EmcID::barrel_ec(showerId);
730
731 //The theta number is defined by Endcap_east(0-5),Barrel(0-43),Endcap_west(0-5)
732 //module is defined by Endcap_east(0),Barrel(1),Endcap_west(2)
733
734 thetaIndex=EmcID::theta_module(showerId);
735
736 phiIndex=EmcID::phi_module(showerId);
737
738 //cout<<thetaIndex<<" "<<phiIndex<<endl;
739 //-------------------
740
741 EmcShDigi* aShDigi= new EmcShDigi();
742 EmcShDigi maxima =EmcShDigi();
743 list<EmcShDigi> shDigiList;
744 RecEmcID cellId;
745 unsigned int module;
746 double digiEne, time, fraction, digiTheta, digiPhi;
747 double digiX, digiY, digiZ;
748 long int digiThetaIndex,digiPhiIndex;
749 HepPoint3D digiPos(0,0,0);
750
751 RecEmcFractionMap::const_iterator ciFractionMap;
752
753 if ( ! shDigiList.empty()) shDigiList.clear();
754 RecEmcFractionMap fracMap5x5=theShower->getFractionMap5x5();
755 for(ciFractionMap=fracMap5x5.begin();
756 ciFractionMap!=fracMap5x5.end();
757 ciFractionMap++){
758
759 digiEne = ciFractionMap->second.getEnergy(); //digit energy unit GeV
760
761 time = ciFractionMap->second.getTime();
762 fraction = ciFractionMap->second.getFraction();
763
764 cellId=ciFractionMap->second.getCellId();
765
766 digiPos=m_iGeoSvc->GetCFrontCenter(cellId);
767 digiTheta = digiPos.theta();
768 digiPhi = digiPos.phi();
769 digiX = digiPos.x();
770 digiY = digiPos.y();
771 digiZ = digiPos.z();
772
773 module=EmcID::barrel_ec(cellId);
774 //The theta number is defined by Endcap_east(0-5),Barrel(0-43),Endcap_west(0-5)
775 //module is defined by Endcap_east(0),Barrel(1),Endcap_west(2)
776
777 digiThetaIndex=EmcID::theta_module(cellId);
778
779 digiPhiIndex = EmcID::phi_module(cellId);
780
781 //set EmcShDigi
782 aShDigi->setEnergy(digiEne);
783 aShDigi->setTheta(digiTheta);
784 aShDigi->setPhi(digiPhi);
785 aShDigi->setModule(module);
786 aShDigi->setThetaIndex(digiThetaIndex);
787 aShDigi->setPhiIndex(digiPhiIndex);
788 aShDigi->setTime(time);
789 aShDigi->setFraction(fraction);
790 aShDigi->setWhere(digiPos);
791 aShDigi->setY(digiX);
792 aShDigi->setY(digiY);
793 aShDigi->setZ(digiZ);
794
795 shDigiList.push_back(*aShDigi);
796
797 }
798 shDigiList.sort(); //sort energy from small to large
799
800 numberOfDigis = shDigiList.size();
801
802 maxima = *(--shDigiList.end());
803 //cout<<"maxima="<<maxima.energy()<<endl;
804 //cout<<maxima.thetaIndex()<<" max "<<maxima.phiIndex()<<endl;
805 //set EmcShower
806 aShower->setEnergy(ene);
807 aShower->setTheta(theta);
808 aShower->setPhi(phi);
809 aShower->setModule(showerModule);
810 aShower->setThetaIndex(thetaIndex);
811 aShower->setPhiIndex(phiIndex);
812 aShower->setNumberOfDigis(numberOfDigis);
813 aShower->setDigiList(shDigiList);
814 aShower->setMaxima(maxima);
815 aShower->setWhere(showerPosition);
816 aShower->setX(showerX);
817 aShower->setY(showerY);
818 aShower->setZ(showerZ);
819 m_showerList.push_back(*aShower);
820 delete aShDigi;
821
822 }
823 //m_showerList.sort(); //sort energy from small to large
824
825 delete aShower;
826
827 ///////////////
828
829 if (m_showerList.size() == 2) {
830 //iterator for the bump list
831 list<EmcShower>::const_iterator iter_Sh;
832 int itrk=0;
833 for (iter_Sh = m_showerList.begin();
834 iter_Sh != m_showerList.end(); iter_Sh++) {
835
836 itrk++;
837 EmcShower shower;
838 shower = EmcShower();
839 double theta = iter_Sh->theta();
840 shower = *iter_Sh;
841
842 //fill the Bhabha event
843 // if ( (itrk==1&&theMdcTrk1->charge()>0)
844 // ||(itrk==2&&theMdcTrk2->charge()>0) ){
845 if (itrk==1){
846 //set properties
847 myBhaEvt->setPositron()->setShower(shower);
848 myBhaEvt->setPositron()->setTheta(shower.theta());
849 myBhaEvt->setPositron()->setPhi(shower.phi());
850 unsigned int newthetaInd ;
851 //The thetaIndex is defined by Endcap_east(0-5),Barrel(6-49),Endcap_west(50-55)
852 //in Emc Bhabha Calibration
853 if (shower.module()==0) newthetaInd = shower.thetaIndex();
854 if (shower.module()==1) newthetaInd = shower.thetaIndex() + 6;
855 if (shower.module()==2) newthetaInd = 55 - shower.thetaIndex();
856
857 myBhaEvt->setPositron()->setThetaIndex(newthetaInd);
858
859 unsigned int newphiInd=shower.phiIndex();
860 myBhaEvt->setPositron()->setPhiIndex(newphiInd);
861 myBhaEvt->setPositron()->setFound(true);
862
863
864 log << MSG::INFO << name() << ": Positron: theta,phi energy "
865 << myBhaEvt->positron()->theta() << ","
866 << myBhaEvt->positron()->shower().phi() << " "
867 << myBhaEvt->positron()->shower().energy()
868 << endreq;
869
870
871 }
872
873 //if ( (itrk==1&&theMdcTrk1->charge()<0)
874 // ||(itrk==2&&theMdcTrk2->charge()<0) ){
875 if (itrk==2){
876 //set properties including vertex corrected theta
877 myBhaEvt->setElectron()->setShower(shower);
878 myBhaEvt->setElectron()->setTheta(shower.theta());
879 myBhaEvt->setElectron()->setPhi(shower.phi());
880 unsigned int newthetaInd;
881 //The thetaIndex is defined by Endcap_east(0-5),Barrel(6-49),Endcap_west(50-55)
882 //in Emc Bhabha Calibration
883 if (shower.module()==0) newthetaInd = shower.thetaIndex();
884 if (shower.module()==1) newthetaInd = shower.thetaIndex() + 6;
885 if (shower.module()==2) newthetaInd = 55 - shower.thetaIndex();
886
887 myBhaEvt->setElectron()->setThetaIndex(newthetaInd);
888 unsigned int newphiInd=shower.phiIndex();
889 myBhaEvt->setElectron()->setPhiIndex(newphiInd);
890 myBhaEvt->setElectron()->setFound(true);
891
892 log << MSG::INFO << name() << ": Electron: theta,phi energy "
893 << myBhaEvt->electron()->theta() << ","
894 << myBhaEvt->electron()->shower().phi() << " "
895 << myBhaEvt->electron()->shower().energy()
896 << endreq;
897
898 }
899 }
900 }
901
902
903}
904
905void
907
908 MsgStream log(msgSvc(), name());
909
910 //check if the Bhabhas were found
911 if ( 0 != myBhaEvt->positron()->found() ||
912 0 != myBhaEvt->electron()->found() ) {
913
914 m_taken++;
915 //fill the EmcBhabhas
916 double calibEnergy=0.;
917 double energyError=0.;
918
919 //------------- electron found --------------------------------------
920 if (myBhaEvt->electron()->found() ) {
921 /*
922 int ixtalIndex = index(myBhaEvt->electron()->thetaIndex(),
923 myBhaEvt->electron()->phiIndex());
924 calibEnergy = m_eMcPeak[ixtalIndex];
925 */
926
927 unsigned int module, ntheta, nphi;
928 if ( myBhaEvt->electron()->thetaIndex()<=5) {
929 module=0;
930 ntheta=myBhaEvt->electron()->thetaIndex();
931
932 } else if ( myBhaEvt->electron()->thetaIndex()>=50){
933 module=2;
934 ntheta=55-myBhaEvt->electron()->thetaIndex();
935
936 } else {
937 module=1;
938 ntheta=myBhaEvt->electron()->thetaIndex()-6;
939 }
940 nphi=myBhaEvt->electron()->phiIndex();
941
942
943 RecEmcID shId= EmcID::crystal_id(module,ntheta,nphi);
944 HepPoint3D SeedPos(0,0,0);
945 SeedPos=m_iGeoSvc->GetCFrontCenter(shId);
946 /*
947 calibEnergy = myBhaEvt->
948 getDepoMCShowerEnergy_lab(myBhaEvt->electron()->theta(),
949 myBhaEvt->electron()->phi(),
950 myBhaEvt->electron()->thetaIndex(),
951 myBhaEvt->electron()->phiIndex(),
952 m_corFun[myBhaEvt->electron()->thetaIndex()],
953 m_beamEnergy);
954 */
955 calibEnergy = myBhaEvt->
956 getDepoMCShowerEnergy_lab(SeedPos.theta(),
957 SeedPos.phi(),
958 myBhaEvt->electron()->thetaIndex(),
959 myBhaEvt->electron()->phiIndex(),
960 m_corFun[myBhaEvt->electron()->thetaIndex()],
961 m_beamEnergy);
962
963 if (m_selMethod=="DataMCIxtal"){
964 calibEnergy = myBhaEvt->
965 getDepoMCShowerEnergy_lab(SeedPos.theta(),
966 SeedPos.phi(),
967 myBhaEvt->electron()->thetaIndex(),
968 myBhaEvt->electron()->phiIndex(),
969 m_eMeanMC[index(myBhaEvt->electron()->thetaIndex(),myBhaEvt->electron()->phiIndex())],
970 m_beamEnergy);
971 }
972 /*
973 calibEnergy = myBhaEvt->
974 getDepoMCShowerEnergy(myBhaEvt->electron()->thetaIndex(),
975 myBhaEvt->electron()->phiIndex(),
976 m_corFun[myBhaEvt->electron()->thetaIndex()],
977 m_beamEnergy);
978 */
979
980 if ( calibEnergy > 0 ) {
981
982 energyError = myBhaEvt->
983 getErrorDepoMCShowerEnergy(myBhaEvt->electron()->thetaIndex(),
984 myBhaEvt->electron()->phiIndex(),
985 m_eSigma[myBhaEvt->electron()->thetaIndex()]*m_beamEnergy/100.);
986 if (m_selMethod=="DataMCIxtal"){
987 energyError = m_eRmsMC[index(myBhaEvt->electron()->thetaIndex(),myBhaEvt->electron()->phiIndex())]*m_beamEnergy;
988 }
989
990 } else
991 log << MSG::WARNING << " Did not find MC deposited cluster energy "
992 <<" for this cluster: thetaInd: "
993 << myBhaEvt->electron()->thetaIndex()
994 << " phiInd: "
995 << myBhaEvt->electron()->phiIndex()
996 << endl
997 << "Will not use this cluster for the Emc "
998 << "Bhabha calibration !"
999 << endreq;
1000
1001 //set all that stuff in an EmcBhabha
1002 myBhaEvt->setElectron()->setErrorOnCalibEnergy(energyError);
1003 myBhaEvt->setElectron()->setCalibEnergy(calibEnergy);
1004
1005 //myBhaEvt->electron()->print();
1006
1007 } else
1008 log << MSG::INFO<< name()
1009 << ": Electron was not selected ! "
1010 << endreq;
1011
1012 calibEnergy=0.;
1013 energyError=0.;
1014
1015 //---------------- positron found ----------------------------------
1016 if (myBhaEvt->positron()->found() ) {
1017 /*
1018 int ixtalIndex = index(myBhaEvt->positron()->thetaIndex(),
1019 myBhaEvt->positron()->phiIndex());
1020 calibEnergy = m_eMcPeak[ixtalIndex];
1021 */
1022
1023 unsigned int module, ntheta, nphi;
1024 if ( myBhaEvt->positron()->thetaIndex()<=5) {
1025 module=0;
1026 ntheta=myBhaEvt->positron()->thetaIndex();
1027
1028 } else if ( myBhaEvt->positron()->thetaIndex()>=50){
1029 module=2;
1030 ntheta=55-myBhaEvt->positron()->thetaIndex();
1031
1032 } else {
1033 module=1;
1034 ntheta=myBhaEvt->positron()->thetaIndex()-6;
1035 }
1036 nphi=myBhaEvt->positron()->phiIndex();
1037
1038
1039 RecEmcID shId= EmcID::crystal_id(module,ntheta,nphi);
1040 HepPoint3D SeedPos(0,0,0);
1041 SeedPos=m_iGeoSvc->GetCFrontCenter(shId);
1042 /*
1043 calibEnergy = myBhaEvt->
1044 getDepoMCShowerEnergy_lab(myBhaEvt->positron()->theta(),
1045 myBhaEvt->positron()->phi(),
1046 myBhaEvt->positron()->thetaIndex(),
1047 myBhaEvt->positron()->phiIndex(),
1048 m_corFun[myBhaEvt->positron()->thetaIndex()],
1049 m_beamEnergy);
1050 */
1051 calibEnergy = myBhaEvt->
1052 getDepoMCShowerEnergy_lab(SeedPos.theta(),
1053 SeedPos.phi(),
1054 myBhaEvt->positron()->thetaIndex(),
1055 myBhaEvt->positron()->phiIndex(),
1056 m_corFun[myBhaEvt->positron()->thetaIndex()],
1057 m_beamEnergy);
1058
1059 if (m_selMethod=="DataMCIxtal"){
1060 calibEnergy = myBhaEvt->
1061 getDepoMCShowerEnergy_lab(SeedPos.theta(),
1062 SeedPos.phi(),
1063 myBhaEvt->positron()->thetaIndex(),
1064 myBhaEvt->positron()->phiIndex(),
1065 m_eMeanMC[index(myBhaEvt->positron()->thetaIndex(),myBhaEvt->positron()->phiIndex())],
1066 m_beamEnergy);
1067 }
1068
1069 /*
1070 calibEnergy = myBhaEvt->
1071 getDepoMCShowerEnergy(myBhaEvt->positron()->thetaIndex(),
1072 myBhaEvt->positron()->phiIndex(),
1073 m_corFun[myBhaEvt->positron()->thetaIndex()],
1074 m_beamEnergy);
1075 */
1076
1077 if ( calibEnergy > 0. ) {
1078
1079 energyError = myBhaEvt->
1080 getErrorDepoMCShowerEnergy(myBhaEvt->positron()->thetaIndex(),
1081 myBhaEvt->positron()->phiIndex(),
1082 m_eSigma[myBhaEvt->positron()->thetaIndex()]*m_beamEnergy/100.);
1083
1084 if (m_selMethod=="DataMCIxtal"){
1085 energyError = m_eRmsMC[index(myBhaEvt->electron()->thetaIndex(),myBhaEvt->electron()->phiIndex())]*m_beamEnergy;
1086 }
1087
1088 } else
1089 log << MSG::WARNING << " Did not find MC deposited cluster energy "
1090 << "for this cluster: thetaInd: "
1091 << myBhaEvt->positron()->thetaIndex()
1092 << " phiInd: "
1093 << myBhaEvt->positron()->phiIndex()
1094 << endl
1095 << "Will not use this cluster for the Emc "
1096 << "Bhabha calibration !"
1097 << endreq;
1098
1099
1100 //set all that stuff in an EmcBhabha
1101 myBhaEvt->setPositron()->setErrorOnCalibEnergy(energyError);
1102 myBhaEvt->setPositron()->setCalibEnergy(calibEnergy);
1103
1104 //myBhaEvt->positron()->print();
1105
1106 } else
1107 log << MSG::INFO << name()
1108 << ": Positron was not selected ! "
1109 << endreq;
1110
1111 //calculate elements of Matrix M and vector R from Bhabha event,
1112 //M is in SLAP triad format
1113 fillMatrix();
1114
1115 } else {
1116 log << MSG::WARNING << " No Bhabha data for calibration found in event !"
1117 << endreq;
1118
1119 }
1120
1121}
1122
1123
1124void
1125EmcSelBhaEvent::fillMatrix( ) {
1126
1127 EmcBhabha _theBhabha=EmcBhabha();
1128 EmcShower _theShower=EmcShower();
1129 EmcShDigi _DigiMax=EmcShDigi();
1130 double _sigmaBha;
1131
1132 // ---- get the current calibration constants
1133
1134
1135 // ---- loop over the two particles
1136 for ( int i = 1; i <= 2; i++ ) {
1137
1138 if ( i == 2 ) _theBhabha = *(myBhaEvt->electron());
1139 else _theBhabha = *(myBhaEvt->positron());
1140 //-----------------------------------------------------------
1141 // ---- fill the matrix only if we found the particle and ---
1142 // ---- a energy to calibrate on -----
1143 double _sig=_theBhabha.errorOnCalibEnergy();
1144 double _calibEne=_theBhabha.calibEnergy();
1145 double _bhaEne=_theBhabha.shower().energy();
1146 int _bhaThetaIndex=_theBhabha.thetaIndex();
1147 int _bhaPhiIndex=_theBhabha.phiIndex();
1148 //cout<<_sig<<" "<< _calibEne<<" "<<_bhaEne<<" "<<endl;
1149 ///////////////boost to cms
1150 double eraw =_bhaEne ;
1151 double phi = _theBhabha.shower().phi();
1152 double the = _theBhabha.shower().theta();
1153
1154 HepLorentzVector ptrk;
1155 ptrk.setPx(eraw*sin(the)*cos(phi));
1156 ptrk.setPy(eraw*sin(the)*sin(phi));
1157 ptrk.setPz(eraw*cos(the));
1158 ptrk.setE(eraw);
1159
1160 ptrk=ptrk.boost(-0.011,0,0);
1161 _bhaEne=ptrk.e();
1162 //////////////
1163
1164 double SigCut=0.0;
1165
1166 SigCut=m_sigmaCut;
1167
1168 int ixtalIndex = index(_bhaThetaIndex,_bhaPhiIndex);
1169 double peakCutMin,peakCutMax;
1170
1171 //peak+/- 1 sigma
1172 if (m_selMethod=="Ithe"){
1173 peakCutMin= m_eDepEne[_bhaThetaIndex]*m_beamEnergy
1174 - SigCut*m_eSigmaExp[_bhaThetaIndex]*m_beamEnergy/100.;
1175
1176 peakCutMax=m_eDepEne[_bhaThetaIndex] *m_beamEnergy
1177 + SigCut*m_eSigmaExp[_bhaThetaIndex]*m_beamEnergy/100.;
1178 }
1179 /*
1180 if (ixtalIndex==2408){
1181 peakCutMin= 1.685
1182 - SigCut*m_eSigmaExp[_bhaThetaIndex]*m_beamEnergy/100.;
1183
1184 peakCutMax=1.685
1185 + SigCut*m_eSigmaExp[_bhaThetaIndex]*m_beamEnergy/100.;
1186 }
1187 */
1188
1189 //Raw mean+/- 1 RMS
1190 // peakCutMin= m_eRawMean[ixtalIndex] - m_eRawRMS[ixtalIndex]*SigCut;
1191
1192 //peakCutMax= m_eRawMean[ixtalIndex] + m_eRawRMS[ixtalIndex]*SigCut;
1193
1194 // cout<< ixtalIndex<<" "<<peakCutMin<<" " <<peakCutMax<<endl;
1195
1196
1197 //peak(ixtal)+/- 1 sigma
1198 if (m_selMethod=="Ixtal"){
1199 peakCutMin= m_eRawPeak[ixtalIndex] *m_beamEnergy
1200 - SigCut*m_eSigmaExp[_bhaThetaIndex]*m_beamEnergy/100.;
1201
1202 peakCutMax= m_eRawPeak[ixtalIndex] *m_beamEnergy
1203 + SigCut*m_eSigmaExp[_bhaThetaIndex]*m_beamEnergy/100.;
1204 }
1205
1206 if (m_selMethod=="DataMCIxtal"){
1207 peakCutMin= m_eMeanData[ixtalIndex] *m_beamEnergy
1208 -SigCut*m_eRmsData[ixtalIndex]*m_beamEnergy;
1209 //- SigCut*m_eSigmaExp[_bhaThetaIndex]*m_beamEnergy/100.;
1210
1211 peakCutMax= m_eMeanData[ixtalIndex] *m_beamEnergy
1212 +SigCut*m_eRmsData[ixtalIndex]*m_beamEnergy;
1213 //+ SigCut*m_eSigmaExp[_bhaThetaIndex]*m_beamEnergy/100.;
1214 }
1215
1216// if (ixtalIndex==689) cout<<peakCutMin<<"\t"<<peakCutMax<<"\t"<<_bhaEne<<endl;
1217 /*
1218 if (ixtalIndex==2408){
1219 peakCutMin= 1.685
1220 - SigCut*m_eSigmaExp[_bhaThetaIndex]*m_beamEnergy/100.;
1221
1222 peakCutMax=1.685
1223 + SigCut*m_eSigmaExp[_bhaThetaIndex]*m_beamEnergy/100.;
1224 }
1225 */
1226 /*
1227
1228 if (_bhaThetaIndex==26&&_bhaPhiIndex==26){
1229 peakCutMin= 1.75
1230 - SigCut*m_eSigmaExp[_bhaThetaIndex]*m_beamEnergy/100.;
1231
1232 peakCutMax=1.75
1233 + SigCut*m_eSigmaExp[_bhaThetaIndex]*m_beamEnergy/100.;
1234 }
1235
1236 if (_bhaThetaIndex==29&&_bhaPhiIndex==26){
1237 peakCutMin= 1.9
1238 - SigCut*m_eSigmaExp[_bhaThetaIndex]*m_beamEnergy/100.;
1239
1240 peakCutMax=1.9
1241 + SigCut*m_eSigmaExp[_bhaThetaIndex]*m_beamEnergy/100.;
1242 }
1243
1244 if (_bhaThetaIndex==30&&_bhaPhiIndex==26){
1245 peakCutMin= 1.655
1246 - SigCut*m_eSigmaExp[_bhaThetaIndex]*m_beamEnergy/100.;
1247
1248 peakCutMax=1.655
1249 + SigCut*m_eSigmaExp[_bhaThetaIndex]*m_beamEnergy/100.;
1250 }
1251 */
1252
1253 if ( _theBhabha.found()!=0 && _theBhabha.calibEnergy() > 0.
1254 && _bhaEne >= peakCutMin
1255 && _bhaEne <= peakCutMax
1256 && m_measure[ixtalIndex] !=3 ) {
1257
1258
1259 //if ( _theBhabha.found()!=0 && _theBhabha.calibEnergy() > 0.
1260 // && _bhaEne >= m_eDepMean[ixtalIndex]
1261 // - SigCut*m_eSigmaExp[_bhaThetaIndex]*m_beamEnergy/100.
1262 // &&_bhaEne <= m_eDepMean[ixtalIndex]
1263 // + SigCut*m_eSigmaExp[_bhaThetaIndex]*m_beamEnergy/100.) {
1264
1265 // if ( _theBhabha.found()!=0 && _theBhabha.calibEnergy() > 0.
1266 // && _bhaEne >= m_eDepPeak[ixtalIndex]
1267 // - SigCut*m_eDepSigma[ixtalIndex]
1268 // &&_bhaEne <= m_eDepPeak[ixtalIndex]
1269 //+ SigCut*m_eDepSigma[ixtalIndex]) {
1270
1271 m_showersAccepted++;
1272 //the error (measurement + error on the energy to calibrate on)
1273 _sigmaBha = _theBhabha.sigma2();
1274 //cout<<"sigma2="<<_sigmaBha<<endl;
1275
1276 _theShower = _theBhabha.shower();
1277
1278 //The thetaIndex is defined by Endcap_east(0-5),Barrel(6-49),Endcap_west(50-55)
1279 //in Emc Bhabha Calibration
1280
1281 _DigiMax = _theShower.maxima();
1282
1283 unsigned int newThetaIndMax=999;
1284 if (_DigiMax.module()==0) newThetaIndMax = _DigiMax.thetaIndex();
1285 if (_DigiMax.module()==1) newThetaIndMax = _DigiMax.thetaIndex() + 6;
1286 if (_DigiMax.module()==2) newThetaIndMax = 55 - _DigiMax.thetaIndex();
1287
1288 // if(_DigiMax.module()==1)
1289 // { // only for MC data
1290 // cout<<"theta..,phi="<<_DigiMax.thetaIndex()<<" "<<_DigiMax.phiIndex()<<endl;
1291 //}
1292
1293 int maximaIndex=0;
1294 maximaIndex = index(newThetaIndMax,_DigiMax.phiIndex());
1295 //if (maximaIndex>500&&maximaIndex<5000){
1296 // cout<<"max="<<maximaIndex<<" "<<_DigiMax.thetaIndex()
1297 //<<" "<<_DigiMax.phiIndex()<<endl;
1298 //}
1299
1300 list<EmcShDigi> _DigiList=_theShower.digiList();
1301
1302 list<EmcShDigi>::const_iterator _Digi1,_Digi2;
1303
1304 //------------------------------------------------------
1305 //---- double loop over the digis to fill the matrix ---
1306
1307 //first loop over Digis
1308 for (_Digi1 = _DigiList.begin();
1309 _Digi1 != _DigiList.end(); _Digi1++) {
1310
1311 //get Xtal index
1312
1313 //The thetaIndex is defined by Endcap_east(0-5),Barrel(6-49),Endcap_west(50-55)
1314 //in Emc Bhabha Calibration
1315 unsigned int newThetaInd1=999;
1316 if (_Digi1->module()==0) newThetaInd1 = _Digi1->thetaIndex();
1317 if (_Digi1->module()==1) newThetaInd1 = _Digi1->thetaIndex() + 6;
1318 if (_Digi1->module()==2) newThetaInd1 = 55 - _Digi1->thetaIndex();
1319
1320 int Digi1Index = index(newThetaInd1,_Digi1->phiIndex());
1321
1322 //if (Digi1Index>1000&&Digi1Index<5000){
1323 // cout<<"max="<<Digi1Index<<" "<<_Digi1->thetaIndex()
1324 // <<" "<<_Digi1->phiIndex()<<endl;
1325 //}
1326
1327
1328 //calculate the vector with Raw data
1329 double dvec = ( (static_cast<double>(_Digi1->energy())) *
1330 _theBhabha.calibEnergy() / _sigmaBha);
1331
1332 //fill the vector
1333 if ( m_writeMVToFile )
1334 (myCalibData->vectorR(Digi1Index)) += dvec;
1335
1336 //count hits in Xtals and keep theta and phi
1337 if ( m_writeMVToFile )
1338
1339 (myCalibData->xtalHits(Digi1Index))++;
1340
1341 //if ( *(_theShower.maxima()) == *(_Digi1) ) {
1342
1343 if ( Digi1Index == maximaIndex ) {
1344 if ( m_writeMVToFile ){
1345 (myCalibData->xtalHitsDir(Digi1Index))++;
1346
1347 }
1348 }
1349
1350 //second loop over Digis
1351 for (_Digi2 = _Digi1;
1352 _Digi2 != _DigiList.end(); _Digi2++) {
1353
1354 unsigned int newThetaInd2=999;
1355 if (_Digi2->module()==0) newThetaInd2 = _Digi2->thetaIndex();
1356 if (_Digi2->module()==1) newThetaInd2 = _Digi2->thetaIndex() + 6;
1357 if (_Digi2->module()==2) newThetaInd2 = 55 - _Digi2->thetaIndex();
1358
1359 int Digi2Index = index(newThetaInd2, _Digi2->phiIndex());
1360
1361 //calculate the matrix element with raw data
1362 double val =
1363 static_cast<double>((( (_Digi1->energy() *
1364 _Digi2->energy() )
1365 ))/_sigmaBha);
1366
1367 if ( m_writeMVToFile )
1368 myCalibData->matrixMEle( Digi1Index, Digi2Index) += val;
1369
1370 }
1371 }
1372
1373 } //if paricle found and calibration energy
1374
1375 }//loop over particles
1376
1377}
1378
1379
1380void
1382
1383 MsgStream log(msgSvc(), name());
1384
1385 int numberOfXtalsRing;
1386
1387 EmcStructure* theEmcStruc=new EmcStructure() ;
1388 theEmcStruc->setEmcStruc();
1389
1390 //number Of Theta Rings
1391 int nrOfTheRings = theEmcStruc->getNumberOfTheRings();
1392
1393 m_nXtals = theEmcStruc->getNumberOfXtals();
1394
1395 //init geometry
1396 for ( int the = theEmcStruc->startingTheta(); the< nrOfTheRings; the++) {
1397
1398 numberOfXtalsRing = theEmcStruc->crystalsInRing((unsigned int) the );
1399
1400 for ( int phi=0; phi < numberOfXtalsRing; phi++) {
1401
1402 m_index[the][phi] = theEmcStruc->getIndex( (unsigned int)the , (unsigned int)phi);
1403
1404 }
1405
1406 }
1407
1408 log << MSG::INFO << " Emc geometry for Bhabha calibration initialized !! "
1409 << endl
1410 << "Number of Xtals: " << m_nXtals << endreq;
1411 delete theEmcStruc;
1412
1413
1414
1415}
1416
1417
1418void
1420
1421 MsgStream log(msgSvc(), name());
1422
1423 //check this first because I sometimes got two endJob transitions
1424 if ( myCalibData != 0 )
1425
1426 //if set write the matrix and vector to a file
1427 if ( m_writeMVToFile ) {
1428
1429 int count;
1430 char cnum[20];
1431 if (m_run<0){
1432 count = sprintf(cnum,"MC%d_%i",-m_run,m_Num);
1433 }
1434 if (m_run>=0){
1435 count = sprintf(cnum,"%d_%i",m_run,m_fileNum);
1436 }
1437
1438 std::string runnum="";
1439 runnum.append(cnum);
1440
1441 ofstream runnumberOut;
1442 std::string runnumberFile = m_fileDir;
1443 runnumberFile += m_fileExt;
1444 runnumberFile +="runnumbers.dat";
1445 runnumberOut.open(runnumberFile.c_str(),ios::out|ios::app);
1446
1447 ifstream runnumberIn;
1448 runnumberIn.open(runnumberFile.c_str());
1449 bool status=false;
1450 while( !runnumberIn.eof() ) {
1451
1452 std::string num;
1453 runnumberIn >> num;
1454 if (runnum==num) {
1455 status=true;
1456 log << MSG::INFO<< " the runnumber: "<<runnum
1457 <<" exists in the file runnumbers.dat" <<endreq;
1458 break;
1459 }else{
1460 status=false;
1461 log << MSG::INFO<< " the runnumber: "<<runnum
1462 <<" does not exist in the file runnumbers.dat" <<endreq;
1463 }
1464 }
1465 runnumberIn.close();
1466
1467 ofstream vectorOut;
1468 std::string vectorFile = m_fileDir;
1469 vectorFile += m_fileExt;
1470 vectorFile += runnum;
1471 vectorFile += "CalibVector.dat";
1472 vectorOut.open(vectorFile.c_str());
1473
1474 ofstream matrixOut;
1475 std::string matrixFile = m_fileDir;
1476 matrixFile += m_fileExt;
1477 matrixFile += runnum;
1478 matrixFile += "CalibMatrix.dat";
1479 matrixOut.open(matrixFile.c_str());
1480
1481 if ( vectorOut.good() && matrixOut.good() &&runnumberOut.good()) {
1482
1483 myCalibData->writeOut(matrixOut, vectorOut);
1484
1485 log << MSG::INFO<< " Wrote files "
1486 << (vectorFile) << " and "
1487 << (matrixFile) <<endreq;
1488
1489
1490 if ( !status ) {
1491 runnumberOut<<runnum<<"\n";
1492 log << MSG::INFO<< "Wrote files "<<runnumberFile<< endreq;
1493 }
1494
1495 } else
1496 log << MSG::WARNING << " Could not open vector and/or matrix file !"
1497 << endl
1498 << "matrix file : " << matrixFile << endl
1499 << "vector file : " << vectorFile
1500 << endreq;
1501
1502 vectorOut.close();
1503 matrixOut.close();
1504 runnumberOut.close();
1505 }
1506
1507}
1508
1509
1510double
1512{
1513 double diff;
1514 diff = phi1 - phi2; //rad
1515
1516 while( diff> pi ) diff -= twopi;
1517 while( diff< -pi ) diff += twopi;
1518
1519 return diff;
1520}
1521
1522
1523void
1525
1526 ifstream corFunIn;
1527 std::string corFunFile = m_inputFileDir;
1528 corFunFile += m_fileExt;
1529 corFunFile += "cor.conf";
1530 corFunIn.open(corFunFile.c_str());
1531 for(int i=0;i<56;i++) {
1532 corFunIn>>m_corFun[i];
1533
1534 cout<<"energy corFun="<<m_corFun[i]<<endl;
1535 }
1536 corFunIn.close();
1537}
1538
1539void
1541
1542 ifstream EsigmaIn;
1543 std::string EsigmaFile = m_inputFileDir;
1544 EsigmaFile += m_fileExt;
1545 EsigmaFile += "sigma.conf";
1546 EsigmaIn.open(EsigmaFile.c_str());
1547 for(int i=0;i<56;i++) {
1548 EsigmaIn>>m_eSigma[i];
1549
1550 cout<<"Sigma="<<m_eSigma[i]<<endl;
1551 }
1552 EsigmaIn.close();
1553}
1554
1555void
1557
1558 ifstream EDepEneIn;
1559 std::string EDepEneFile = m_inputFileDir;
1560 EDepEneFile += m_fileExt;
1561 EDepEneFile += "peakI.conf";
1562 EDepEneIn.open(EDepEneFile.c_str());
1563 for(int i=0;i<56;i++) {
1564 EDepEneIn>>m_eDepEne[i];
1565 //m_eDepEne[i]=m_eDepEne[i]-0.020;
1566 //m_eDepEne[i]=m_eDepEne[i]/1.843*m_beamEnergy;
1567 cout<<"DepEne="<<m_eDepEne[i]<<endl;
1568 }
1569 EDepEneIn.close();
1570
1571}
1572
1573void
1575 ifstream ESigmaExpIn;
1576 std::string ESigmaExpFile = m_inputFileDir;
1577 ESigmaExpFile += m_fileExt;
1578 ESigmaExpFile += "sigmaI.conf";
1579 ESigmaExpIn.open(ESigmaExpFile.c_str());
1580 for(int i=0;i<56;i++) {
1581 ESigmaExpIn>>m_eSigmaExp[i];
1582 cout<<"SigmaExp="<<m_eSigmaExp[i]<<endl;
1583 }
1584 ESigmaExpIn.close();
1585
1586
1587}
1588
1589void
1591
1592
1593 ifstream EIn;
1594 std::string EFile = m_inputFileDir;
1595 EFile += m_fileExt;
1596 EFile += "findpeak.conf";
1597 EIn.open(EFile.c_str());
1598
1599 double Peak[6240];
1600 int ixtal;
1601 for(int i=0;i<6240;i++) {
1602 EIn>>ixtal>>Peak[i];
1603 m_eRawPeak[ixtal]=Peak[i];
1604 }
1605 EIn.close();
1606
1607 /*
1608 ifstream EIn1;
1609 std::string EFile1 = m_inputFileDir;
1610 EFile1 += m_fileExt;
1611 EFile1 += "findpeak-mc.conf";
1612 EIn1.open(EFile1.c_str());
1613
1614 double Peak1[6240];
1615 int ixtal1;
1616 for(int i=0;i<6240;i++) {
1617 EIn1>>ixtal1>>Peak1[i];
1618 m_eMcPeak[ixtal1]=Peak1[i];
1619 }
1620 EIn1.close();
1621 */
1622}
1623
1624void
1626 //read mean of e5x5cms
1627 ifstream EIn;
1628 std::string EFile = m_inputFileDir;
1629 EFile += m_fileExt;
1630 EFile += "X4680-meaNo3-e5x5cmsCut0.7-2mc.conf";
1631 EIn.open(EFile.c_str());
1632
1633 double MeanData[6240],MeanMC[6240];
1634 double RmsData[6240],RmsMC[6240];
1635 int ixtal;
1636 for(int i=0;i<6240;i++) {
1637 EIn>>ixtal>>MeanData[i]>>MeanMC[i]>>RmsData[i]>>RmsMC[i];
1638 m_eMeanData[ixtal]=MeanData[i];
1639 m_eMeanMC[ixtal]=MeanMC[i];
1640 //m_eRmsData[ixtal]=RmsData[i];
1641 //m_eRmsMC[ixtal]=RmsMC[i];
1642 }
1643 EIn.close();
1644
1645
1646 /////////////////// read peak of e5x5cms
1647
1648 ifstream EIn1,EIn2,EIn3,EIn4;
1649
1650 std::string EFile1 = m_inputFileDir;
1651 std::string EFile2 = m_inputFileDir;
1652 std::string EFile3 = m_inputFileDir;
1653 std::string EFile4 = m_inputFileDir;
1654
1655 EFile1 += "findpeak-all-IV.conf";
1656 EFile2 += "findrms-all-IV.conf";
1657 EFile3 += "peakIxtalMC.conf";
1658 EFile4 += "findrms-all-MC.conf";
1659
1660 EIn1.open(EFile1.c_str());
1661 EIn2.open(EFile2.c_str());
1662 EIn3.open(EFile3.c_str());
1663 EIn4.open(EFile4.c_str());
1664
1665 //double MeanData[6240],MeanMC[6240];
1666 //double RmsData[6240],RmsMC[6240];
1667 int ixtal1,ixtal2,ixtal3,ixtal4;
1668 for(int i=0;i<6240;i++) {
1669 EIn1>>ixtal1>>MeanData[i];
1670 EIn2>>ixtal2>>RmsData[i];
1671 EIn3>>ixtal3>>MeanMC[i];
1672 EIn4>>ixtal4>>RmsMC[i];
1673 //m_eMeanData[ixtal1]=MeanData[i];
1674 m_eRmsData[ixtal2]=RmsData[i];
1675 //m_eMeanMC[ixtal3]=MeanMC[i];
1676 m_eRmsMC[ixtal4]=RmsMC[i];
1677 // cout<<"..........."<< m_eMeanData[ixtal1]<<"\t"<<m_eRmsData[ixtal2]<<"\t"<<m_eMeanMC[ixtal3]<<"\t"<<m_eRmsMC[ixtal4]<<endl;
1678 }
1679
1680 EIn1.close();
1681 EIn2.close();
1682 EIn3.close();
1683 EIn4.close();
1684}
1685
1686double
1688
1689 double minDist=999;
1690
1691 SmartDataPtr<EvtRecEvent> evtRecEvent(eventSvc(), EventModel::EvtRec::EvtRecEvent);
1692 SmartDataPtr<EvtRecTrackCol> evtRecTrkCol(eventSvc(), EventModel::EvtRec::EvtRecTrackCol);
1693
1694 EvtRecTrackIterator itTrk = evtRecTrkCol->begin() + ShowerID;
1695
1696 RecEmcShower *theShower = (*itTrk)->emcShower();
1697 HepLorentzVector theShowerVec(1,1,1,1);
1698 theShowerVec.setTheta(theShower->theta());
1699 theShowerVec.setPhi(theShower->phi());
1700 theShowerVec.setRho(theShower->energy());
1701 theShowerVec.setE(theShower->energy());
1702
1703 for(int j = 0; j < evtRecEvent->totalTracks(); j++){
1704 EvtRecTrackIterator jtTrk=evtRecTrkCol->begin() + j;
1705
1706 if(!(*jtTrk)->isEmcShowerValid()) continue;
1707 if (ShowerID == (*jtTrk)->trackId()) continue;
1708
1709 RecEmcShower *aShower = (*jtTrk)->emcShower();
1710
1711 if (aShower->energy() > m_minAngShEnergyCut ){
1712
1713 HepLorentzVector aShowerVec(1,1,1,1);
1714 aShowerVec.setTheta(aShower->theta());
1715 aShowerVec.setPhi(aShower->phi());
1716 aShowerVec.setRho(aShower->energy());
1717 aShowerVec.setE(aShower->energy());
1718
1719 double dist = theShowerVec.angle(aShowerVec);
1720
1721 if ( dist < minDist )
1722 minDist = dist;
1723
1724 }
1725
1726 }
1727
1728 return minDist;
1729}
1730
double sin(const BesAngle a)
Definition: BesAngle.h:210
double cos(const BesAngle a)
Definition: BesAngle.h:213
sprintf(cut,"kal_costheta0_em>-0.93&&kal_costheta0_em<0.93&&kal_pxy0_em>=0.05+%d*0.1&&kal_pxy0_em<0.15+%d*0.1&&NGch>=2", j, j)
Double_t phi2
Double_t phi1
Double_t time
HepGeom::Point3D< double > HepPoint3D
std::vector< HepLorentzVector > Vp4
std::vector< int > Vint
DOUBLE_PRECISION count[3]
EvtRecTrackCol::iterator EvtRecTrackIterator
Definition: EvtRecTrack.h:111
std::vector< int > Vint
Definition: Gam4pikp.cxx:52
map< RecEmcID, RecEmcFraction, less< RecEmcID > > RecEmcFractionMap
IMessageSvc * msgSvc()
HepPoint3D position() const
Definition: DstEmcShower.h:34
double eSeed() const
Definition: DstEmcShower.h:47
double theta() const
Definition: DstEmcShower.h:38
double phi() const
Definition: DstEmcShower.h:39
int trackId() const
Definition: DstEmcShower.h:29
double x() const
Definition: DstEmcShower.h:35
double e5x5() const
Definition: DstEmcShower.h:49
double z() const
Definition: DstEmcShower.h:37
double energy() const
Definition: DstEmcShower.h:45
double y() const
Definition: DstEmcShower.h:36
double & vectorR(int ind)
int & xtalHitsDir(int ind)
double & matrixMEle(int row, int column)
void writeOut(ostream &OutM, ostream &outV)
int & xtalHits(int ind)
EmcBhabha * setElectron()
EmcBhabha * positron() const
EmcBhabha * setPositron()
EmcBhabha * electron() const
const double & theta() const
Definition: EmcBhabha.h:59
void setPhiIndex(unsigned int phiIndex)
Definition: EmcBhabha.h:96
void setCalibEnergy(double energy)
Definition: EmcBhabha.h:90
double sigma2() const
Definition: EmcBhabha.cxx:79
void setPhi(double phi)
Definition: EmcBhabha.h:94
const double & calibEnergy() const
Definition: EmcBhabha.h:46
EmcShower shower() const
Definition: EmcBhabha.h:55
const bool & found()
Definition: EmcBhabha.h:43
const double & errorOnCalibEnergy() const
Definition: EmcBhabha.h:49
void setErrorOnCalibEnergy(double error)
Definition: EmcBhabha.h:91
void setShower(EmcShower aShower)
Definition: EmcBhabha.h:92
void setTheta(double theta)
Definition: EmcBhabha.h:93
void setFound(bool what)
Definition: EmcBhabha.h:89
const unsigned int & thetaIndex() const
Definition: EmcBhabha.h:73
const unsigned int & phiIndex() const
Definition: EmcBhabha.h:78
void setThetaIndex(unsigned int thetaIndex)
Definition: EmcBhabha.h:95
static Identifier crystal_id(const unsigned int barrel_ec, const unsigned int theta_module, const unsigned int phi_module)
For a single crystal.
Definition: EmcID.cxx:71
static unsigned int barrel_ec(const Identifier &id)
Values of different levels (failure returns 0)
Definition: EmcID.cxx:38
static unsigned int theta_module(const Identifier &id)
Definition: EmcID.cxx:43
static unsigned int phi_module(const Identifier &id)
Definition: EmcID.cxx:48
double findPhiDiff(double phi1, double phi2)
StatusCode SelectBhabha()
StatusCode execute()
int index(int theta, int phi) const
double Angle2ClosestShower(int ShowerID)
StatusCode initialize()
StatusCode finalize()
void setWhere(HepPoint3D where)
Definition: EmcShDigi.h:52
const unsigned int & thetaIndex() const
Definition: EmcShDigi.h:35
const unsigned int & phiIndex() const
Definition: EmcShDigi.h:36
void setZ(double z)
Definition: EmcShDigi.h:55
void setTheta(double theta)
Definition: EmcShDigi.h:45
void setY(double y)
Definition: EmcShDigi.h:54
void setModule(unsigned int module)
Definition: EmcShDigi.h:47
void setEnergy(double energy)
Definition: EmcShDigi.h:44
void setPhi(double phi)
Definition: EmcShDigi.h:46
void setFraction(double fraction)
Definition: EmcShDigi.h:51
void setTime(double time)
Definition: EmcShDigi.h:50
void setPhiIndex(unsigned int phiIndex)
Definition: EmcShDigi.h:49
void setThetaIndex(unsigned int thetaIndex)
Definition: EmcShDigi.h:48
const unsigned int & module() const
Definition: EmcShDigi.h:34
void setPhi(double phi)
Definition: EmcShower.h:57
const unsigned int & thetaIndex() const
Definition: EmcShower.h:42
void setEnergy(double energy)
Definition: EmcShower.h:55
const double & theta() const
Definition: EmcShower.h:39
void setTheta(double theta)
Definition: EmcShower.h:56
const double & energy() const
Definition: EmcShower.h:38
void setDigiList(std::list< EmcShDigi > digiList)
Definition: EmcShower.h:62
void setPhiIndex(unsigned int phiIndex)
Definition: EmcShower.h:60
void setX(double x)
Definition: EmcShower.h:65
const double & phi() const
Definition: EmcShower.h:40
void setY(double y)
Definition: EmcShower.h:66
void setThetaIndex(unsigned int thetaIndex)
Definition: EmcShower.h:59
const EmcShDigi maxima() const
Definition: EmcShower.h:46
void setZ(double z)
Definition: EmcShower.h:67
void setMaxima(EmcShDigi maxima)
Definition: EmcShower.h:63
const unsigned int & phiIndex() const
Definition: EmcShower.h:43
void setWhere(HepPoint3D where)
Definition: EmcShower.h:64
const std::list< EmcShDigi > digiList() const
Definition: EmcShower.h:45
void setNumberOfDigis(long int numberOfDigis)
Definition: EmcShower.h:61
const unsigned int & module() const
Definition: EmcShower.h:41
void setModule(unsigned int module)
Definition: EmcShower.h:58
void setEmcStruc()
long getIndex(unsigned int thetaIndex, unsigned int phiIndex) const
unsigned int getNumberOfTheRings()
unsigned int startingTheta()
Definition: EmcStructure.h:26
unsigned int crystalsInRing(unsigned int theta) const
unsigned int getPartId(long Index) const
Definition: EmcStructure.h:35
unsigned int getNumberOfXtals()
unsigned int getPhi(long Index) const
Definition: EmcStructure.h:37
unsigned int getTheta(long Index) const
Definition: EmcStructure.h:36
virtual bool isRunValid()=0
virtual double getbeamE()=0
virtual void getBeamEnergyInfo()=0
virtual HepPoint3D GetCFrontCenter(const Identifier &id) const =0
RecEmcFractionMap getFractionMap5x5() const
RecEmcID getShowerId() const
Definition: RecEmcShower.h:55
_EXTERN_ std::string EvtRecEvent
Definition: EventModel.h:116
_EXTERN_ std::string EvtRecTrackCol
Definition: EventModel.h:117
Definition: Event.h:21
float ptrk
const float pi
Definition: vector3.h:133