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