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