BOSS 7.0.3
BESIII Offline Software System
Loading...
Searching...
No Matches
MucRecRoadFinder.cxx
Go to the documentation of this file.
1//$id$
2//
3//$log$
4
5/*
6 * 2003/12/26 Zhengyun You Peking University
7 *
8 */
9
10#include "GaudiKernel/MsgStream.h"
11#include "GaudiKernel/AlgFactory.h"
12#include "GaudiKernel/ISvcLocator.h"
13#include "GaudiKernel/SmartDataPtr.h"
14#include "GaudiKernel/IDataProviderSvc.h"
15#include "GaudiKernel/IDataManagerSvc.h"
16#include "GaudiKernel/PropertyMgr.h"
17#include "EventModel/EventHeader.h"
18#include "EmcRecEventModel/RecEmcEventModel.h"
19#include "MdcRawEvent/MdcDigi.h"
20#include "TofRawEvent/TofDigi.h"
21#include "EmcRawEvent/EmcDigi.h"
22#include "MucRawEvent/MucDigi.h"
23#include "ReconEvent/ReconEvent.h"
24#include "ExtEvent/RecExtTrack.h"
25#include "MdcRecEvent/RecMdcTrack.h"
26#include "McTruth/McKine.h"
27#include "McTruth/McParticle.h"
28#include "Identifier/Identifier.h"
29#include "Identifier/MucID.h"
30#include "GaudiKernel/IPartPropSvc.h"
31#include "MucRecAlg/MucRecRoadFinder.h"
32#include "MucRecAlg/MucRecRoadFinderParameter.h"
33#include "MucGeomSvc/IMucGeomSvc.h"
34#include "MucGeomSvc/MucConstant.h"
35#include "MucRecEvent/MucRecHit.h"
36#include "MucRecEvent/MucRecHitContainer.h"
37#include "MucRecEvent/RecMucTrack.h"
38#include "MucRecEvent/MucRec3DRoad.h"
39#include "MucRecEvent/MucRec2DRoad.h"
40
41#include <vector>
42#include <iostream>
43#include <fstream>
44#include <iomanip>
45
46using namespace std;
47using namespace Event;
48
49MucRecRoadFinder::MucRecRoadFinder(const std::string &name, ISvcLocator* pSvcLocator) :
50 Algorithm(name, pSvcLocator)
51{
52 // Declare the properties
53 declareProperty("FittingMethod", m_fittingMethod = 2);
54 declareProperty("ConfigFile", m_configFile = "MucConfig.xml");
55 declareProperty("McCosmic", m_mccosmic = 0);
56 declareProperty("OnlySeedFit", m_onlyseedfit = 0);
57 declareProperty("NtOutput", m_NtOutput = 0);
58 declareProperty("MaxHitsRec", m_maxHitsRec = 200);
59 declareProperty("United", m_united = 0);
60 declareProperty("SeedType", m_seedtype = 0);
61 declareProperty("MsOutput", m_MsOutput = false);
62 declareProperty("FilterFile", m_filter_filename);
63}
64
65// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
67{
68 MsgStream log(msgSvc(), name());
69 log << MSG::INFO << "in initialize()" << endreq;
70
71 m_NHitsTotal = 0;
72 m_NHitsLostTotal = 0;
73 for(int i = 0; i < 20; i++) m_NHitsLost.push_back(0);
74 for(int i = 0; i < 10; i++) m_NHitsLostInGap.push_back(0);
75
76 m_NEvent = 0;
77 m_NEventWithHit = 0;
78 m_NEventReco = 0;
79
80 IMucGeomSvc* mucGeomSvc;
81 StatusCode sc = service("MucGeomSvc", mucGeomSvc);
82 if (sc == StatusCode::SUCCESS) {
83 mucGeomSvc->Dump();
84 //cout<<"1st wire id:"<<mucGeomSvc->Wire(0)->Id()<<endl;
85 //cout<<"2nd wire lyr id:"<<mucGeomSvc->Wire(1)->Lyr()->Id()<<endl;
86 //cout<<"6860th wire lyr id:"<<mucGeomSvc->Wire(6859)->Lyr()->Id()<<endl;
87 } else {
88 return StatusCode::FAILURE;
89 }
90
91 aMucRecHitContainer = 0;
92
93 if(m_NtOutput>=1){
94 NTuplePtr nt1(ntupleSvc(), "FILE401/T");
95
96 if ( nt1 ) { m_tuple = nt1;}
97 else {
98 // m_tuple = ntupleSvc()->book ("MyTuples/1", CLID_RowWiseTuple, "MdcTrkRecon N-Tuple");
99 m_tuple = ntupleSvc()->book ("FILE401/T", CLID_RowWiseTuple, "MucTrkRecon N-Tuple");
100 if ( m_tuple ) {
101 sc = m_tuple->addItem ("part", m_part);
102 sc = m_tuple->addItem ("seg", m_seg);
103 sc = m_tuple->addItem ("gap", m_gap);
104 sc = m_tuple->addItem ("strip", m_strip);
105 sc = m_tuple->addItem ("diff", m_diff);
106 sc = m_tuple->addItem ("dist", m_dist);
107 sc = m_tuple->addItem ("run", m_run);
108 sc = m_tuple->addItem ("event", m_event);
109 sc = m_tuple->addItem ("ngap", m_ngapwithhits);
110 sc = m_tuple->addItem ("nhit", m_nhit);
111 sc = m_tuple->addItem ("maxhit", m_maxhit);
112 sc = m_tuple->addItem ("multihit",m_multihit);
113 sc = m_tuple->addItem ("angleCosmic",m_angle_cosmic);
114 sc = m_tuple->addItem ("angleUpdown",m_angle_updown);
115 sc = m_tuple->addItem ("px",m_px);
116 sc = m_tuple->addItem ("py",m_py);
117 sc = m_tuple->addItem ("pz",m_pz);
118 sc = m_tuple->addItem ("theta",m_theta);
119 sc = m_tuple->addItem ("phi",m_phi);
120 sc = m_tuple->addItem ("theta_pipe",m_theta_pipe);
121 sc = m_tuple->addItem ("phi_pipe",m_phi_pipe);
122 sc = m_tuple->addItem ("pxmc",m_px_mc);
123 sc = m_tuple->addItem ("pymc",m_py_mc);
124 sc = m_tuple->addItem ("pzmc",m_pz_mc);
125 sc = m_tuple->addItem ("thetamc",m_theta_mc);
126 sc = m_tuple->addItem ("phimc",m_phi_mc);
127 sc = m_tuple->addItem ("thetamc_pipe",m_theta_mc_pipe);
128 sc = m_tuple->addItem ("phimc_pipe",m_phi_mc_pipe);
129 sc = m_tuple->addItem ("emcUp",m_emcUp);
130 sc = m_tuple->addItem ("emcDown",m_emcDown);
131 sc = m_tuple->addItem ("mucUp",m_mucUp);
132 sc = m_tuple->addItem ("mucDown",m_mucDown);
133 sc = m_tuple->addItem ("projx",m_projx);
134 sc = m_tuple->addItem ("projz",m_projz);
135
136 }
137 else { // did not manage to book the N tuple....
138 log << MSG::ERROR << " Cannot book N-tuple:" << long(m_tuple) << endmsg;
139 //return StatusCode::FAILURE;
140 }
141 }
142 }
143
144 // load the filter event
145 if ( m_filter_filename == "") {
146 m_filter_filename =getenv("MUCRECALGROOT");
147 m_filter_filename +="/share/filter.txt";
148 }
149
150 if (m_filter_filename.size()) {
151 std::ifstream infile(m_filter_filename.c_str());
152
153 while (!infile.eof()) {
154 FilterEvent filterevt;
155 infile >> filterevt.bossver >> filterevt.runid >> filterevt.eventid;
156 if ((!infile.good()) || (infile.eof())) {
157 break;
158 }
159
160 m_filter_event.push_back(filterevt);
161// cout << filterevt.bossver << " "
162// << filterevt.runid << " "
163// << filterevt.eventid << std::endl;
164 }
165 }
166
167 return StatusCode::SUCCESS;
168}
169
170// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
172
173 MsgStream log(msgSvc(), name());
174 log << MSG::INFO << "in execute()" << endreq;
175
176 // Part 1: Get the event header, print out event and run number
177 int event, run;
178
179 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
180 if (!eventHeader) {
181 log << MSG::FATAL << "Could not find Event Header" << endreq;
182 return( StatusCode::FAILURE);
183 }
184 log << MSG::INFO << "Run: " << eventHeader->runNumber() << " Event: " << eventHeader->eventNumber() << endreq;
185
186event = eventHeader->eventNumber();
187run = eventHeader->runNumber();
188
189//cout<<"events run "<<event <<" "<<run<<endl;
190 string release = getenv("BES_RELEASE");
191 // if(release=="6.6.5"&&run==35896&&event==7448){return ( StatusCode::SUCCESS);}
192 // if(release=="6.6.5"&&run==37241&&event==1690731){return ( StatusCode::SUCCESS);}
193 // filter the event
194 for (std::vector<FilterEvent>::iterator it = m_filter_event.begin();
195 it != m_filter_event.end(); ++it) {
196 const FilterEvent& fe = (*it);
197 if (release == fe.bossver && run == fe.runid && event == fe.eventid) {
198 cout << "SKIP: " << fe.bossver << " "
199 << fe.runid << " "
200 << fe.eventid << std::endl;
201 return StatusCode::SUCCESS;
202 }
203 }
204
205 int digiId;
206
207 //Part 2: Retrieve MC truth
208
209 Hep3Vector cosmicMom;
210 if(m_mccosmic==1){
211 SmartDataPtr<McParticleCol> mcParticleCol(eventSvc(),"/Event/MC/McParticleCol");
212 if (!mcParticleCol) {
213 log << MSG::FATAL << "Could not find McParticle" << endreq;
214 return( StatusCode::FAILURE);
215 }
216
217 McParticleCol::iterator iter_mc = mcParticleCol->begin();
218 for (;iter_mc != mcParticleCol->end(); iter_mc++, digiId++) {
219 log << MSG::DEBUG
220 << " particleId = " << (*iter_mc)->particleProperty()
221 << endreq;
222 int pid = (*iter_mc)->particleProperty();
223 //cout<<"in mucroadfinder pid = "<<pid<<endl;
224 if(fabs(pid)!=13) continue;
225
226 HepLorentzVector initialMomentum = (*iter_mc)->initialFourMomentum();
227 Hep3Vector startP(initialMomentum.px(), initialMomentum.py(), initialMomentum.pz());
228 Hep3Vector rotate(-initialMomentum.px(),initialMomentum.pz(),initialMomentum.py());
229
230 if(m_NtOutput>=1){
231 m_px_mc = initialMomentum.px();
232 m_py_mc = initialMomentum.py();
233 m_pz_mc = initialMomentum.pz();
234
235 m_theta_mc = rotate.theta();
236 m_phi_mc = rotate.phi();
237
238 m_theta_mc_pipe = startP.theta();
239 m_phi_mc_pipe = startP.phi();
240
241 //m_tuple->write();
242 }
243
244 //if(initialMomentum.py()>0)cout<<"py>0????? "<<pid<<endl;
245 cosmicMom = startP;
246
247 }
248 }
249 /*
250 //Part 3: Retrieve MDC digi
251 SmartDataPtr<MdcDigiCol> mdcDigiCol(eventSvc(),"/Event/Digi/MdcDigiCol");
252 if (!mdcDigiCol) {
253 log << MSG::FATAL << "Could not find MDC digi" << endreq;
254 return( StatusCode::FAILURE);
255 }
256
257 MdcDigiCol::iterator iter1 = mdcDigiCol->begin();
258 digiId = 0;
259
260 for (;iter1 != mdcDigiCol->end(); iter1++, digiId++) {
261 log << MSG::INFO << "MDC digit No: " << digiId << endreq;
262
263 log << MSG::INFO
264 << " time_channel = " << (*iter1)->getTimeChannel()
265 << " charge_channel = " << (*iter1)->getChargeChannel()
266 << endreq;
267 }
268
269 //Part 4: Retrieve TOF digi
270 SmartDataPtr<TofDigiCol> tofDigiCol(eventSvc(),"/Event/Digi/TofDigiCol");
271 if (!tofDigiCol) {
272 log << MSG::FATAL << "Could not find TOF digi" << endreq;
273 return( StatusCode::FAILURE);
274 }
275
276 TofDigiCol::iterator iter2 = tofDigiCol->begin();
277 digiId = 0;
278
279 for (;iter2 != tofDigiCol->end(); iter2++, digiId++) {
280 log << MSG::INFO << "TOF digit No: " << digiId << endreq;
281
282 }
283
284 //Part 5: Retrieve EMC digi
285 SmartDataPtr<EmcDigiCol> emcDigiCol(eventSvc(),"/Event/Digi/EmcDigiCol");
286 if (!emcDigiCol) {
287 log << MSG::FATAL << "Could not find EMC digi" << endreq;
288 return( StatusCode::FAILURE);
289 }
290
291 EmcDigiCol::iterator iter3 = emcDigiCol->begin();
292 digiId = 0;
293
294 for (;iter3 != emcDigiCol->end(); iter3++, digiId++) {
295 log << MSG::INFO << "Emc digit No: " << digiId << endreq;
296
297 log << MSG::INFO
298 << " time_channel = " << (*iter3)->getTimeChannel()
299 << " charge_channel = " << (*iter3)->getChargeChannel()
300 << endreq;
301 }
302 */
303
304 //Part 6: Retrieve MUC digi
305 SmartDataPtr<MucDigiCol> mucDigiCol(eventSvc(),"/Event/Digi/MucDigiCol");
306 if (!mucDigiCol) {
307 log << MSG::FATAL << "Could not find MUC digi" << endreq;
308 return( StatusCode::FAILURE);
309 }
310
311 MucDigiCol::iterator iter4 = mucDigiCol->begin();
312 digiId = 0;
313 for (;iter4 != mucDigiCol->end(); iter4++, digiId++) {
314 }
315 log << MSG::INFO << "MUC digis:: " << digiId << endreq;
316 if( digiId == 0) return( StatusCode::SUCCESS );
317
318 //********************************//
319 RecMucTrackCol *aMucTrackCol;
320 int trackId = -1;
321 int muctrackId = -1;
322
323 if(m_united != 1) // if this algorithm run individualy, we need create hitcollection and trackcollection...
324 {
325 Identifier mucID;
326 if (!aMucRecHitContainer) {
327 aMucRecHitContainer = new MucRecHitContainer();
328 }
329 aMucRecHitContainer->Clear();
330
331 MucRecHitCol *aMucRecHitCol = new MucRecHitCol();
332 aMucRecHitContainer->SetMucRecHitCol(aMucRecHitCol);
333
334
335 SmartIF<IDataManagerSvc> dataManSvc(eventSvc());
336 DataObject *mucRecHitCol;
337 eventSvc()->findObject("/Event/Recon/MucRecHitCol",mucRecHitCol);
338 if(mucRecHitCol != NULL) {
339 dataManSvc->clearSubTree("/Event/Recon/MucRecHitCol");
340 eventSvc()->unregisterObject("/Event/Recon/MucRecHitCol");
341 }
342
343 StatusCode sc = eventSvc()->registerObject("/Event/Recon/MucRecHitCol", aMucRecHitContainer->GetMucRecHitCol());
344
345 MucDigiCol::iterator iterMuc = mucDigiCol->begin();
346 int mucDigiId = 0;
347 for (;iterMuc != mucDigiCol->end(); iterMuc++, mucDigiId++) {
348 mucID = (*iterMuc)->identify();
349 int part = MucID::barrel_ec(mucID);
350 int seg = MucID::segment(mucID);
351 int gap = MucID::layer(mucID);
352 int strip = MucID::channel(mucID);
353 //aMucRecHitContainer->AddHit(mucID);
354 //if(part==1 && seg==2 && gap==8 && (strip==19||strip==16));//cout<<"noise hit!!!=========="<<endl;
355 //else /////this problem has been solved!
356 aMucRecHitContainer->AddHit(part, seg, gap, strip);
357 log << MSG::INFO << " digit" << mucDigiId << " : "
358 << " part " << part
359 << " seg " << seg
360 << " gap " << gap
361 << " strip " << strip
362 << endreq;
363 }
364
365 DataObject *aReconEvent ;
366 eventSvc()->findObject("/Event/Recon",aReconEvent);
367 if(aReconEvent==NULL) {
368 //then register Recon
369 aReconEvent = new ReconEvent();
370 StatusCode sc = eventSvc()->registerObject("/Event/Recon",aReconEvent);
371 if(sc!=StatusCode::SUCCESS) {
372 log << MSG::FATAL << "Could not register ReconEvent" <<endreq;
373 return( StatusCode::FAILURE);
374 }
375 }
376 StatusCode fr = eventSvc()->findObject("/Event/Recon",aReconEvent);
377 if(fr!=StatusCode::SUCCESS) {
378 log << MSG::WARNING << "Could not find register ReconEvent, will create it" <<endreq;
379 StatusCode sc = eventSvc()->registerObject("/Event/Recon",aReconEvent);
380 if(sc!=StatusCode::SUCCESS) {
381 log << MSG::FATAL << "Could not register ReconEvent" <<endreq;
382 return( StatusCode::FAILURE);
383 }
384 }
385
386 //********************************//
387 // Create track Container;
388 DataObject *mucTrackCol;
389 eventSvc()->findObject("/Event/Recon/RecMucTrackCol",mucTrackCol);
390 if(mucTrackCol != NULL) {
391 dataManSvc->clearSubTree("/Event/Recon/RecMucTrackCol");
392 eventSvc()->unregisterObject("/Event/Recon/RecMucTrackCol");
393 }
394
395 aMucTrackCol = new RecMucTrackCol();
396 sc = eventSvc()->registerObject("/Event/Recon/RecMucTrackCol", aMucTrackCol);
397 aMucTrackCol->clear();
398
399 // check MucTrackCol registered
400 SmartDataPtr<RecMucTrackCol> findMucTrackCol(eventSvc(),"/Event/Recon/RecMucTrackCol");
401 if (!findMucTrackCol) {
402 log << MSG::FATAL << "Could not find RecMucTrackCol" << endreq;
403 return( StatusCode::FAILURE);
404 }
405 aMucTrackCol->clear();
406
407
408 log << MSG::INFO <<"MaxHitsRec : "<<m_maxHitsRec<< endreq;
409 if(digiId> m_maxHitsRec) return StatusCode::SUCCESS; //too many digit! abnormal------2008-04-17
410 //********************************//
411 // Create track Container;
412
413 trackId = 0;
414 muctrackId = 0;
415 }//// conrespond to if(m_united != 1) !!!!!!!
416 else if(m_united == 1){
417
418 Identifier mucID;
419 if (!aMucRecHitContainer) {
420 aMucRecHitContainer = new MucRecHitContainer();
421 }
422 aMucRecHitContainer->Clear();
423
424 SmartDataPtr<MucRecHitCol> aMucRecHitCol (eventSvc(),"/Event/Recon/MucRecHitCol");
425 if(aMucRecHitCol == NULL) {
426 log << MSG::WARNING << "MucRecHitCol is NULL" << endreq;
427 }
428
429 aMucRecHitContainer->SetMucRecHitCol(aMucRecHitCol);
430
431 SmartDataPtr<RecMucTrackCol> mucTrackCol (eventSvc(),"/Event/Recon/RecMucTrackCol");
432 if(mucTrackCol == NULL) {
433 log << MSG::WARNING << "aMucTrackCol is NULL" << endreq;
434 }
435
436 log << MSG::INFO <<"mucTrackCol size: "<<mucTrackCol->size()<<" hitCol size: "<<aMucRecHitCol->size()<<endreq;
437 aMucTrackCol = mucTrackCol;
438
439 // Retrieve Ext track Col from TDS for setting trackId
440 SmartDataPtr<RecExtTrackCol> aExtTrackCol(eventSvc(),"/Event/Recon/RecExtTrackCol");
441 if (!aExtTrackCol) {
442 log << MSG::WARNING << "Can't find ExtTrackCol in TDS!" << endreq;
443 }
444
445 SmartDataPtr<RecMdcTrackCol> aMdcTrackCol(eventSvc(),"/Event/Recon/RecMdcTrackCol");
446 if (!aMdcTrackCol) {
447 log << MSG::WARNING << "Can't find MdcTrackCol in TDS!" << endreq;
448 }
449
450 if( aExtTrackCol && aMdcTrackCol ) trackId = aMdcTrackCol->size();
451 muctrackId = aMucTrackCol->size();
452 }
453
454 int hasEmcUp = 0;
455 int hasEmcDown = 0;
456 SmartDataPtr<RecEmcShowerCol> aShowerCol(eventSvc(),"/Event/Recon/RecEmcShowerCol");
457 if (!aShowerCol) {
458 log << MSG::WARNING << "Could not find RecEmcShowerCol" << endreq;
459 //return( StatusCode::FAILURE);
460 }
461 else{
462 RecEmcShowerCol::iterator iShowerCol;
463 for(iShowerCol=aShowerCol->begin();
464 iShowerCol!=aShowerCol->end();
465 iShowerCol++){
466 /*
467 cout<<"check EmcRecShowerCol registered:"<<endl;
468 cout<<"shower id: "<<(*iShowerCol)->ShowerId()<<"\t"
469 <<"shower energy: "<<(*iShowerCol)->Energy()<<"\n"
470 <<"shower position: "<<(*iShowerCol)->Position()<<endl;
471 */
472 if(((*iShowerCol)->position()).phi()>0&&((*iShowerCol)->position()).phi()<3.1415926) hasEmcUp++;
473 else hasEmcDown++;
474 }
475 }
476 if(m_NtOutput >= 1){
477 m_emcUp = hasEmcUp; m_emcDown = hasEmcDown;
478 }
479
480 //********************************//
481 m_NEvent++;
483 // Find or create the 3D road container ...
484 if (!p3DRoadC) {
485 p3DRoadC = new MucRec3DRoadContainer();
486 }
487 p3DRoadC->clear(); // make sure that the container is empty
488
490 // Find or create the 2D road0 container ...
491 if (!p2DRoad0C) {
492 p2DRoad0C = new MucRec2DRoadContainer();
493 }
494 p2DRoad0C->clear(); // make sure that the container is empty
495
497 // Find or create the 2D road1 container ...
498 if (!p2DRoad1C) {
499 p2DRoad1C = new MucRec2DRoadContainer();
500 }
501 p2DRoad1C->clear(); // make sure that the container is empty
502 log << MSG::INFO << "Muc 2D 3D Road Container created" << endreq;
503
504 // We have all of the input and output parameters now, so do
505 // something useful with them!
506 //static bool first_call = true;
507 //
508 // Now find some roads!
509 //
510
511 MucRecHit *pHit0 = 0, *pHit1 = 0;
512 int count0, count1, count, iGap0, iGap1;
513 int orient;
514
515 for (int iPart = 0; iPart < (int)MucID::getPartNum(); iPart++) {
516 for (int iSeg = 0; iSeg < (int)MucID::getSegNum(iPart); iSeg++) {
517 for (int iOrient = 0; iOrient < 2; iOrient++) {
518 int nLoops = 1;
519 if(m_seedtype == 1) nLoops = kNSeedLoops;
520 for (int iLoop = 0; iLoop < nLoops; iLoop++) { //now only 1 loop
521 // checkout the seed gap(s) from search order
522 int length = kSearchLength[iLoop][iPart][iOrient];
523 if(m_seedtype == 1){
524 iGap0 = kSearchOrder[iLoop][iPart][iOrient][0];
525 iGap1 = kSearchOrder[iLoop][iPart][iOrient][1];
526 }
527 else { //new method to calc seed gaps------//
528 int setgap0 = 0;
529 MucDigiCol::iterator iterMuc = mucDigiCol->begin();
530 int mucDigiId = 0;
531 Identifier mucID;
532 iGap0 = 0; iGap1 = 0;
533 for (;iterMuc != mucDigiCol->end(); iterMuc++, mucDigiId++) {
534 mucID = (*iterMuc)->identify();
535 int part = MucID::barrel_ec(mucID);
536 int seg = MucID::segment(mucID);
537 int gap = MucID::layer(mucID);
538 int strip = MucID::channel(mucID);
539 int orient = 0;
540 if ( (part == 1 && gap % 2 == 0) || (part != 1 && gap % 2 == 1) ) orient = 1;
541
542 if(part == iPart && seg == iSeg && orient == iOrient && setgap0 == 0){
543 iGap0 = gap;
544 setgap0 = 1;
545 }//make sure that iGap0 record the 1st gap in this orient
546 if(part == iPart && seg == iSeg && orient == iOrient && setgap0 == 1 && gap != iGap0 ){
547 iGap1 = gap;
548 }//make sure that iGap1 record the last gap in this orient
549 }
550 }
551 //
552 if(m_MsOutput) cout <<"Find seed gap in ( "<<iPart<<" "<<iSeg<<" ) gap0: "<<iGap0<<" gap1: "<<iGap1<<endl;
553
554 //new method to calc seed gaps------//
555 if(iGap0 > iGap1){
556 int tempGap = iGap0;
557 iGap0 = iGap1;
558 iGap1 = tempGap;
559 }
560 if(iGap1 == iGap0) continue;
561
562 count0 = aMucRecHitContainer->GetGapHitCount(iPart, iSeg, iGap0);
563 for (int iHit0 = 0; iHit0 < count0; iHit0++) {
564 //cout << "iHit0 = " << iHit0 << endl;
565 pHit0 = aMucRecHitContainer->GetHit(iPart, iSeg, iGap0, iHit0);
566 if (!pHit0) {
567 log << MSG::FATAL << "MucRecRoadFinder-E10 " << " part " << iPart
568 << " seg " << iSeg << " gap " << iGap0 << " null pointer"
569 << endl;
570 }
571 else {
572
573 //this algo use with ext and this hit has been used before;
574 if(m_united == 1 && pHit0->GetHitMode() != -1) continue;
575
576 count1 = aMucRecHitContainer->GetGapHitCount(iPart, iSeg, iGap1);
577 if(m_MsOutput) cout << "part " << iPart << " seg " << iSeg << " orient " << iOrient
578 << " gap0 " << iGap0 << " count0 " << count0
579 << " gap1 " << iGap1 << " count1 " << count1 << endl;
580 for (int iHit1 = 0; iHit1 < count1; iHit1++) {
581 //cout << "iHit1 = " << iHit1 << endl;
582 pHit1 = aMucRecHitContainer->GetHit(iPart, iSeg, iGap1, iHit1);
583 if (!pHit1) {
584 log << MSG::ERROR << "MucRecRoadFinder-E10 " << " part " << iPart
585 << " seg " << iSeg << " gap " << iGap1 << " null pointer"
586 << endl;
587 } else {
588
589 //this algo use with ext and this hit has been used before;
590 if(m_united == 1 && pHit1->GetHitMode() != -1) continue;
591
592 // Found seed hit(s), create a new 2D road object,
593 // and attach hit pHit1 and pHit0
594 MucRec2DRoad *road2D = new MucRec2DRoad(iPart, iSeg, iOrient, 0.0, 0.0, 3000.0);
595 if (!road2D) {
596 log << MSG::FATAL << "MucRecRoadFinder-E20 " << "failed to create 2D road!" << endreq;
597 continue;
598 }
600
601 if (!pHit0->GetGap()) log << MSG::ERROR << "pHit0->GetGap(), null pointer" << endreq;
602 if (pHit0->GetGap()->Orient() == iOrient) {
603 //float xStrip, yStrip, zStrip;
604 //MucRecGeometry::GetPointer()->GetStripPointer(pHit0->GetSoftID())->GetCenterPos(xStrip, yStrip, zStrip);
605 //cout << " x = " << xStrip << " y = " << yStrip << " z = " << zStrip << endl;
606
607 //set hit as seed then
608 bool isseed = true;
609 pHit0->SetHitSeed(true);
610 pHit1->SetHitSeed(true);
611
612 road2D->AttachHit(pHit0);
613 if(m_MsOutput) cout << "pHit0 attached, " << road2D->GetTotalHits()
614 << ", hitId= "<<pHit0->Part()<<" "<<pHit0->Seg()<<" "<<pHit0->Gap()<<" "<<pHit0->Strip()<<endl;
615 }
616
617 if (pHit1->GetGap()->Orient() == iOrient) {
618 //cout << pHit1->GetSoftID() << endl;
619 //float xStrip, yStrip, zStrip;
620 //MucRecGeometry::GetPointer()->GetStripPointer(pHit1->GetSoftID())->GetCenterPos(xStrip, yStrip, zStrip);
621 //cout << " x = " << xStrip << " y = " << yStrip << " z = " << zStrip << endl;
622 road2D->AttachHit(pHit1);
623 if(m_MsOutput) cout << "pHit1 attached, " << road2D->GetTotalHits()
624 << ", hitId= "<<pHit1->Part()<<" "<<pHit1->Seg()<<" "<<pHit1->Gap()<<" "<<pHit1->Strip()<<endl;
625 }
626 if(m_MsOutput) cout << "Hit cout " << road2D->GetTotalHits() << ", slope " << road2D->GetSlope() << endl;
627
628 // After first (two) hit(s) is(are) attached,
629 // calculate reference pos, direction.
630 // Project to the other planes;
631 // attach clusters within search window.
632
633 for (int i = 0; i < length; i++) {
634 int iGap = kSearchOrder[iLoop][iPart][iOrient][i];
635
636 float dXmin = kInfinity;
637 MucRecHit *pHit = 0;
638
639 float Win = kWindowSize[iPart][iGap];
640 //Win = road2D->GetSearchWindowSize(iGap);
641
642 // following line should be removed after
643 // we have a good function classes for search window
644 //Win = WindowParGamma[iGap];
645
646 //search hit in iGap
647 count = aMucRecHitContainer->GetGapHitCount(iPart, iSeg, iGap);
648 for (int iHit = 0; iHit < count; iHit++) {
649 pHit = aMucRecHitContainer->GetHit(iPart, iSeg, iGap, iHit);
650 if (!pHit) {
651 log << MSG::FATAL << "MucRecRoadFinder-E20 null cluster pointer pHit" << endreq;
652 continue;
653 }
654 else {
655
656 //this algo use with ext and this hit has been used before;
657 if(m_united == 1 && pHit->GetHitMode() != -1) continue;
658
659 // Get the displacement of hit pHit to road2D
660 float dX = road2D->GetHitDistance(pHit);
661 if(m_MsOutput) cout<<"dX = "<<dX<<" Win = "<<Win<<", hit: "<<pHit->Part()<<" "<<pHit->Seg()<<" "<<pHit->Gap()<<" "<<pHit->Strip()<<endl;
662
663 if (dX < Win) {
664 // Attach the hit if it exists
665 // cout << "meet window " << pHit->GetSoftID() << endl;
666 if(iGap == iGap0 || iGap == iGap1) { //hits in these gap is used to be seed, so unvailable for calibrate effi;
667 if(pHit->GetHitMode() == -1){
668 pHit->SetHitMode(3); //self road finder mode
669 }
670 else if(pHit->GetHitMode() == 3){
671 pHit->SetHitMode(4); //self road finder mode used!!!
672 }
673 }
674 // attach hits if we need fit or hit. OR, only attach hits not in seed layers
675 if(m_onlyseedfit == 0)road2D->AttachHit(pHit);
676 else {
677 if(iGap == iGap0 || iGap == iGap1) road2D->AttachHit(pHit);
678 else road2D->AttachHitNoFit(pHit);
679 }
680 }
681 }
682 }
683
684
685 } // for (int i = 0; i < length; ...), Search all gaps
686
687
688 // Ok we found a road already, we need to know
689 // whether we should save it or not
690 // check road quality...
691 //
692
693 // 1. last gap of the road
694 bool lastGapOK = false;
695 if ( road2D->GetLastGap() >= kMinLastGap2D ) {
696 lastGapOK = true;
697 }
698 else {
699 log<<MSG::INFO << " 2D lastGap " << road2D->GetLastGap() << " < " << kMinLastGap2D << endreq;
700 }
701
702 // 2. positon at reference plane
703
704 // 3. number of gaps contain hits
705 bool firedGapsOK = false;
706 if (road2D->GetNGapsWithHits() >= kMinFiredGaps) {
707 firedGapsOK = true;
708 }
709 else {
710 log<<MSG::INFO << " 2D firedGaps " << road2D->GetNGapsWithHits() << " < " << kMinFiredGaps << endreq;
711 }
712
713 // 4. duplicated road check
714 bool duplicateRoad = false;
715 int maxSharedHits = 0, sharedHits = 0;
716 if (iOrient == 0) {
717 for (int index = 0; index < (int)p2DRoad0C->size(); index++) {
718 sharedHits =(*p2DRoad0C)[index]->GetNSharedHits(road2D);
719 }
720 if (maxSharedHits < sharedHits) maxSharedHits = sharedHits;
721 }
722 else {
723 for (int index = 0; index < (int)p2DRoad1C->size(); index++) {
724 sharedHits = (*p2DRoad1C)[index]->GetNSharedHits(road2D);
725 }
726 if (maxSharedHits < sharedHits) maxSharedHits = sharedHits;
727 }
728
729 if(road2D->GetTotalHits() == maxSharedHits
730 || maxSharedHits >= kMinSharedHits2D ) {
731 duplicateRoad = true;
732 log<<MSG::INFO << " maxSharedHits " << maxSharedHits << " > " << kMinSharedHits2D << endreq;
733 }
734
735 // Here is our criteria for a candidate road
736 // i.e. 1) There are at least two gaps containing hits
737 // 2) LastGap of the road passes last plane cut
738 // 3) Reference position passes vertex cut
739 // 4) No existing road share same hits with the road
740
741 if (lastGapOK && firedGapsOK && !duplicateRoad) {
742 if (iOrient == 0) {
743 log<<MSG::INFO << "Add a road0" << endreq;
744 p2DRoad0C->add(road2D);
745 }
746 else {
747 log<<MSG::INFO << "Add a road1" << endreq;
748 p2DRoad1C->add(road2D);
749 }
750 }
751 else {
752
753 // reset hit mode to be -1 if this road useless!
754 vector<MucRecHit*> road2DHits = road2D->GetHits();
755 for(int i=0; i< road2DHits.size(); i++)
756 {
757 MucRecHit *ihit = road2DHits[i];
758 if(ihit->Gap() == iGap0 || ihit->Gap() == iGap1){
759 if(ihit->GetHitMode() == 3) ihit->SetHitMode(-1);
760 if(ihit->GetHitMode() == 4) ihit->SetHitMode(3);
761 }
762 }
763 delete road2D;
764 }
765 } // else {
766 } // for ( int iHit = 0 ...)
767 } // else {
768 } // for ( int iHit0 ...)
769 } // for (int iLoop ...)
770 } // for (int iOrient ...)
771 } // for (int iSeg ...)
772 } // for(iPartArm ...)
773
774 int print2DRoadInfo = 0;
775 if (print2DRoadInfo == 1) {
776 // print 2DRoad container info.
777 cout << "In 2DRoad container : " << endl
778 << " Num of 2DRoad0 = " << p2DRoad0C->size() << endl
779 << endl;
780
781 for (int iRoad = 0; iRoad < (int)p2DRoad0C->size(); iRoad++) {
782
783 MucRec2DRoad *road = (*p2DRoad0C)[iRoad];
784 cout << " " << iRoad << "th 2DRoad0 :" << endl
785 << " Part = " << road->GetPart() << endl
786 << " Seg = " << road->GetSeg() << endl
787 << " Orient = " << road->GetOrient() << endl
788 << " LastGap = " << road->GetLastGap() << endl
789 << " TotalHits = " << road->GetTotalHits() << endl
790 << " DOF = " << road->GetDegreesOfFreedom() << endl
791 << " Slope = " << road->GetSlope() << endl
792 << " Intercept = " << road->GetIntercept() << endl
793 << endl;
794 //road->PrintHitsInfo();
795 }
796
797 cout << " Num of 2DRoad1 = " << p2DRoad1C->size() << endl
798 << endl;
799
800 for ( int iRoad = 0; iRoad < (int)p2DRoad1C->size(); iRoad++) {
801
802 MucRec2DRoad *road = (*p2DRoad1C)[iRoad];
803 cout << " " << iRoad << "th 2DRoad1 :" << endl
804 << " Part = " << road->GetPart() << endl
805 << " Seg = " << road->GetSeg() << endl
806 << " Orient = " << road->GetOrient() << endl
807 << " LastGap = " << road->GetLastGap() << endl
808 << " TotalHits = " << road->GetTotalHits() << endl
809 << " DOF = " << road->GetDegreesOfFreedom() << endl
810 << " Slope = " << road->GetSlope() << endl
811 << " Intercept = " << road->GetIntercept() << endl
812 << endl;
813 //road->PrintHitsInfo();
814 }
815 }
816
817 // We found all possible 2D roads in one part and seg
818 // and now it is time to construct 3D roads base on those 2D roads
819 for ( int iRoad0 = 0; iRoad0 < (int)p2DRoad0C->size(); iRoad0++) {
820 MucRec2DRoad *road0 = (*p2DRoad0C)[iRoad0];
821 for ( int iRoad1 = 0; iRoad1 < (int)p2DRoad1C->size(); iRoad1++){
822 MucRec2DRoad *road1 = (*p2DRoad1C)[iRoad1];
823
824 // Create a new road object with road0 and road1
825 if ( !(road0 &&road1) ) {
826 cout << "Null pointer to road0 or road1: "
827 << "road0 = " << road0
828 << "road1 = " << road1
829 << endl;
830 continue;
831 }
832
833 // Check that both 1D roads are in the same part and segment.
834 if ( (road0->GetPart() != road1->GetPart())
835 || (road0->GetSeg() != road1->GetSeg()) ) {
836 continue;
837 }
838
839 MucRec3DRoad *road3D = new MucRec3DRoad(road0, road1);
840
841 // What are our criteria for accepting a road as valid?
842 // Check them here.
843 // 1. difference of total number clusters in road0 and in road1
844 // 2. difference of last gaps in road0 and road1
845 // 3. InterSection OK or not (if X Y clusters in each gap are
846 // in same panel or overlap region)
847 // 4. Reference position check
848 // 5. Chisquare check
849 // 6. Last Gap check
850 // 7. Duplicate road check
851
852 bool lastGapDeltaOK = false;
853 if ( road3D->GetLastGapDelta() <= kMaxDeltaLastGap ) {
854 lastGapDeltaOK = true;
855 }
856 else {
857 cout << "LastGapDelta = " << road3D->GetLastGapDelta() << endl;
858 }
859
860 bool totalHitsDeltaOK = false;
861 if ( road3D->GetTotalHitsDelta() <= kMaxDeltaTotalHits ) {
862 totalHitsDeltaOK = true;
863 }
864 else {
865 //cout << "TotalHitsDelta = " << road3D->GetTotalHitsDelta() << endl;
866 }
867
868 bool chiSquareCutOK = false;
869 float xChiSquare = road0->GetReducedChiSquare();
870 float yChiSquare = road1->GetReducedChiSquare();
871 if ( xChiSquare <= kMaxXChisq
872 && yChiSquare <= kMaxYChisq ) {
873 chiSquareCutOK = true;
874 }
875 else {
876 cout << "xChiSquare = " << xChiSquare
877 << "yChiSquare = " << yChiSquare
878 << endl;
879 }
880
881 bool minLastGapOK = false;
882 if ( road3D->GetLastGap() >= kMinLastGap3D ) {
883 minLastGapOK = true;
884 }
885 else {
886 log<<MSG::INFO << " minLastGap = " << road3D->GetLastGap() << endreq;
887 }
888
889 bool duplicateRoad = false;
890 int maxSharedHits = 0, sharedHits = 0;
891 for ( int i = 0; i < (int)p3DRoadC->size(); i++){
892 sharedHits =(*p3DRoadC)[i]->GetNSharedHits(road3D);
893 if ( maxSharedHits < sharedHits) maxSharedHits = sharedHits;
894
895 //cout<<"judge shared hits: road["<<i<<"] max = "<<maxSharedHits<<endl;
896 }
897 if(road3D->GetTotalHits() == maxSharedHits
898 || maxSharedHits >= kMinSharedHits2D ) {
899 duplicateRoad = true;
900 log<<MSG::INFO << " MaxShareHits = " << maxSharedHits << endreq;
901 }
902
903 if ( lastGapDeltaOK &&
904 totalHitsDeltaOK &&
905 chiSquareCutOK &&
906 minLastGapOK &&
907 !duplicateRoad ) {
908 float vx, vy, x0, y0;
909 float slope1 = 100, slope0 = 100;
910 if(fabs(road1->GetSlope())<100) slope1 = road1->GetSlope();
911 if(fabs(road0->GetSlope())<100) slope0 = road0->GetSlope();
912
913 if ( road3D->GetPart() == 1 ){
914 road3D->TransformPhiRToXY( slope1, slope0,
915 road1->GetIntercept(), road0->GetIntercept(),
916 vx, vy, x0, y0);
917 }
918 else {
919 vx = slope1;
920 x0 = road1->GetIntercept();
921 vy = slope0;
922 y0 = road0->GetIntercept();
923 }
924 road3D->SetSimpleFitParams(vx, x0, vy, y0);
925
926 log<<MSG::INFO << "Add a 3D Road ... " << endreq;
927
928 float startx = 0.0, starty = 0.0, startz = 0.0;
929 float sigmax = 0.0, sigmay = 0.0, sigmaz = 0.0;
930 road3D->ProjectWithSigma(0, startx, starty, startz, sigmax, sigmay, sigmaz);//gap0
931
932 //cout<<"slope1,0 = "<<slope1<<" "<<slope0<<" vx,y = "<<vx<<" "<<vy<<endl;
933 //cout<<"startxyz= "<<startx<<" "<<starty<<" "<<startz<<endl;
934 //mom(vx,vy,1)
935 float vz = 1;
936 float sign = vy/fabs(vy);
937 float signx = vx/fabs(vx);
938 //cout<<"vxyz = "<<vx<<" "<<vy<<" "<<vz<<endl;
939 if(road3D->GetPart() == 1){
940 if(road3D->GetSeg() > 4){ //down segment
941
942 vx *= -sign;
943 vy *= -sign;
944 vz *= -sign;
945 }
946 else if(road3D->GetSeg()<2){
947 vx *= signx;
948 vy *= signx;
949 vz *= signx;
950 }
951 else if(road3D->GetSeg()>=3 && road3D->GetSeg()<=4){
952 vx *= -signx;
953 vy *= -signx;
954 vz *= -signx;
955 }
956 else{
957 vx *= sign;
958 vy *= sign;
959 vz *= sign;
960 }
961 }
962 else if(road3D->GetPart() == 0){
963 //fix me
964
965 //cout<<"startxyz= "<<startx<<" "<<starty<<" "<<startz<<endl;
966 //cout<<"vx,y,z = "<<vx<<" "<<vy<<" "<<vz<<endl;
967 //cout<<"in road finder a endcap finded!!! -------------"<<endl;
968 }
969 else if(road3D->GetPart() == 2){
970 //fix me
971
972 vx *= -1;
973 vy *= -1;
974 vz *= -1;
975 //cout<<"startxyz= "<<startx<<" "<<starty<<" "<<startz<<endl;
976 //cout<<"vx,y,z = "<<vx<<" "<<vy<<" "<<vz<<endl;
977 //cout<<"in road finder a endcap finded!!! ------------2-"<<endl;
978
979 }
980
981
982 Hep3Vector mom(vx, vy, vz);
983
984 ////////////construct track
985 //MucTrack *aTrack = new MucTrack(road3D);
986 //cout<<"startxyz = "<<startx<<" "<<starty<<" "<<startz<<endl;
987 //cout<<"vxyz = "<<vx<<" "<<vy<<" "<<vz<<endl;
988
989 startx /= 10; starty /= 10; startz /= 10; //mm->cm
990 startx -= vx/mom.mag(); starty -= vy/mom.mag(); startz -= vz/mom.mag(); // decrease a little
991
992 //cout<<"startxyz = "<<startx<<" "<<starty<<" "<<startz<<endl;
993 RecMucTrack *aTrack = new RecMucTrack();
994 aTrack->SetExtMucPos(startx, starty, startz); //mm->cm
995 aTrack->SetExtMucMomentum(vx, vy, vz);
996 aTrack->SetMucPos(startx, starty, startz);
997 aTrack->SetMucMomentum(vx, vy, vz);
998 aTrack->SetCurrentPos( startx, starty, startz);
999 aTrack->SetCurrentDir( vx, vy, vz);
1000 aTrack->SetRecMode(3);
1001 //aTrack->LineFit(1);
1002 //aTrack->ComputeTrackInfo(1);
1003
1004 aTrack->setTrackId(trackId);
1005 aTrack->setId(muctrackId);
1006 trackId++;
1007 muctrackId++;
1008
1009 //cout<<"find a track!!!"<<endl;
1010 aMucTrackCol->add(aTrack);
1011 TrackFinding(aTrack);
1012 p3DRoadC->add(road3D);
1013
1014 ////////////record strip info in this track//////////////
1015
1016 vector<MucRecHit*> attachedHits = aTrack->GetHits();
1017 vector<MucRecHit*> expectedHits = aTrack->GetExpectedHits();
1018 vector<float> distanceHits = aTrack->getDistHits();
1019
1020 for(int i=0; i< expectedHits.size(); i++)
1021 {
1022 MucRecHit *ihit = expectedHits[i];
1023 //cout<<"expected Hits: "<<ihit->Part()<<" "<<ihit->Seg()<<" "<<ihit->Gap()<<" "<<ihit->Strip()<<endl;
1024 }
1025
1026 vector<int> multiHit;
1027 for(int i=0; i< attachedHits.size(); i++)
1028 {
1029 MucRecHit *ihit = attachedHits[i];
1030 //cout<<"attached Hits: "<<ihit->Part()<<" "<<ihit->Seg()<<" "<<ihit->Gap()<<" "<<ihit->Strip()<<" hitmode: "<<ihit->GetHitMode()<<endl;
1031 //calc multiplicity hits;
1032 int hitnum = 0;
1033 for(int k=0; k < attachedHits.size(); k++){
1034 MucRecHit *khit = attachedHits[k];
1035 if((ihit->Part()==khit->Part())&&(ihit->Seg()==khit->Seg())&&(ihit->Gap()==khit->Gap()))
1036 hitnum++;
1037 }
1038 multiHit.push_back(hitnum);
1039 //cout<<"multi hit: "<<hitnum<<" "<<multiHit[i]<<endl;
1040
1041 }
1042
1043 for(int i=0; i< expectedHits.size(); i++)
1044 { //calc distance between attached hits and expected hits
1045
1046 MucRecHit *ihit = expectedHits[i];
1047 //cout<<"attached Hits: "<<ihit->Part()<<" "<<ihit->Seg()<<" "<<ihit->Gap()<<" "<<ihit->Strip()<<endl;
1048
1049 int diff = -999;
1050
1051 for(int j=0; j< attachedHits.size(); j++){
1052 MucRecHit *jhit = attachedHits[j];
1053
1054 // if(attachedHits.size()!=distanceHits.size())cout<<"attached hits size no same as disthits!!!"<<endl;
1055
1056 if((jhit->Part()==ihit->Part())&&(jhit->Seg()==ihit->Seg())&&(jhit->Gap()==ihit->Gap())&&attachedHits.size()==distanceHits.size())
1057 { // same gap, cale distance
1058 diff = ihit->Strip() - jhit->Strip();
1059 //cout<<"diff = "<<diff<<endl;
1060
1061 if(m_NtOutput>=2){
1062
1063 m_part = ihit->Part(); m_seg = ihit->Seg(); m_gap = ihit->Gap();
1064 m_strip = jhit->Strip();
1065 m_diff = diff;
1066 m_dist = distanceHits[j];
1067 //cout<<"distance = "<<m_dist<<endl;
1068
1069 m_angle_cosmic = -999;
1070 m_angle_updown = -999;
1071 //m_px = -999; m_py = -999; m_pz = -999; m_theta = -999; m_phi = -999; m_theta_pipe = -999; m_phi_pipe = -999;
1072 //m_px_mc = -999; m_py_mc = -999; m_pz_mc = -999; m_theta_mc = -999; m_phi_mc = -999;
1073 //m_theta_mc_pipe = -999; m_phi_mc_pipe = -999;
1074 m_ngapwithhits = aTrack->numLayers();
1075 m_nhit = aTrack->numHits();
1076 m_maxhit = aTrack->maxHitsInLayer();
1077 m_multihit = multiHit[j];
1078 m_run = eventHeader->runNumber();
1079 m_event = eventHeader->eventNumber();
1080
1081 m_tuple->write();
1082 }
1083 }
1084
1085
1086 }
1087
1088
1089
1090 if(diff == -999) { // to calc effi of this strip
1091 if(m_NtOutput>=2){
1092 m_part = ihit->Part(); m_seg = ihit->Seg(); m_gap = ihit->Gap();
1093 m_strip = ihit->Strip();
1094 m_diff = diff;
1095 m_dist = -999;
1096 m_angle_updown = -999;
1097 m_angle_cosmic = -999;
1098 //m_px = -999; m_py = -999; m_pz = -999; m_theta = -999; m_phi = -999; m_theta_pipe = -999; m_phi_pipe = -999;
1099 //m_px_mc = -999; m_py_mc = -999; m_pz_mc = -999; m_theta_mc = -999; m_phi_mc = -999;
1100 //m_theta_mc_pipe = -999; m_phi_mc_pipe = -999;
1101 m_ngapwithhits = aTrack->numLayers();
1102 m_run = eventHeader->runNumber();
1103 m_event = eventHeader->eventNumber();
1104 //m_tuple->write();
1105 }
1106 }
1107 //if(diff != -999) cout<< "has hit in this layer"<<endl;
1108
1109 }
1110 ////////////record strip info in this track//////////////
1111 /*
1112 m_part = -999;
1113 m_seg = -999;
1114 m_gap = -999;
1115 m_strip= -999;
1116 m_diff = -999;
1117
1118 m_angle_updown = -999;
1119 m_angle_cosmic = cosmicMom.angle(aTrack->getMucMomentum());
1120 if(m_angle_cosmic>1.57) m_angle_cosmic = 3.14159265 - m_angle_cosmic;
1121 m_run = eventHeader->runNumber();
1122 m_event = eventHeader->eventNumber();
1123
1124 double px,py,pz,p,theta,phi;
1125 px = (aTrack->getMucMomentum()).x();
1126 py = (aTrack->getMucMomentum()).y();
1127 pz = (aTrack->getMucMomentum()).z();
1128
1129 Hep3Vector rotate(-px,pz,py);
1130 theta = rotate.theta();
1131 phi = rotate.phi();
1132
1133
1134 m_px = px; m_py = py; m_pz = pz;
1135 m_theta = theta; m_phi = phi;
1136 m_theta_pipe = (aTrack->getMucMomentum()).theta();
1137 m_phi_pipe = (aTrack->getMucMomentum()).phi();
1138 //m_px_mc = -999; m_py_mc = -999; m_pz_mc = -999; m_theta_mc = -999; m_phi_mc = -999;
1139 //m_theta_mc_pipe = -999; m_phi_mc_pipe = -999;
1140 //////////if(m_py>0)m_tuple->write();
1141
1142 */
1143
1144 }
1145 else {
1146 //cout << "Delete a 3D Road ... " << endl;
1147 delete road3D;
1148 // don't keep it if it's not a good condidate
1149 }
1150 } // for ( int iRoad1 ...
1151 } // for ( int iRoad0 ..
1152
1153
1154 //for cosmic ray, to combine 2 track to 1
1155 RecMucTrack *aaTrack = 0;
1156 RecMucTrack *bbTrack = 0;
1157
1158 int hasMucUp = 0;
1159 int hasMucDown = 0;
1160 for(int iTrack = 0; iTrack < (int)aMucTrackCol->size(); iTrack++) {
1161 aaTrack = (*aMucTrackCol)[iTrack];
1162 if((aaTrack->getMucMomentum()).phi()<3.1415926&&(aaTrack->getMucMomentum()).phi()>0) hasMucUp++;
1163 else hasMucDown++;
1164
1165
1166 double px,py,pz,p,theta,phi;
1167 px = (aaTrack->getMucMomentum()).x();
1168 py = (aaTrack->getMucMomentum()).y();
1169 pz = (aaTrack->getMucMomentum()).z();
1170
1171 if(py<0)continue;
1172
1173 if(m_NtOutput>=1){
1174
1175 m_angle_updown = -999;
1176 m_angle_cosmic = cosmicMom.angle(aaTrack->getMucMomentum());
1177 if(m_angle_cosmic>1.57) m_angle_cosmic = 3.14159265 - m_angle_cosmic;
1178 m_run = eventHeader->runNumber();
1179 m_event = eventHeader->eventNumber();
1180
1181 Hep3Vector rotate(-px,pz,py);
1182 theta = rotate.theta();
1183 phi = rotate.phi();
1184
1185 m_px = px; m_py = py; m_pz = pz;
1186 m_theta = theta; m_phi = phi;
1187 m_theta_pipe = (aaTrack->getMucMomentum()).theta();
1188 m_phi_pipe = (aaTrack->getMucMomentum()).phi();
1189
1190 //if(fabs(m_phi_pipe*57.2958-90)>3)cout<<"px,y,z = "<<m_px<<" "<<m_py<<" "<<m_pz<<endl;
1191
1192 //calc proj point in y=0 plane
1193 Hep3Vector mucPos = aaTrack->getMucPos();
1194 double posx, posy, posz;
1195 posx = mucPos.x(); posy = mucPos.y(); posz = mucPos.z();
1196 //double projx, projz;
1197 m_projx = -999; m_projz = -999;
1198 if(py!=0){
1199 m_projx = posx - px/py*posy;
1200 m_projz = posz - pz/py*posy;
1201 }
1202 //cout<<"projection: "<<projx<<" "<<projz<<endl;
1203 }
1204
1205 }
1206 if(m_NtOutput>=1){
1207 m_mucUp = hasMucUp; m_mucDown = hasMucDown;
1208 m_tuple->write();
1209 }
1210
1211 int forCosmic = 0;
1212 if(aMucTrackCol->size()>=2 && forCosmic == 1){
1213 for(int iTrack = 0; iTrack < (int)aMucTrackCol->size(); iTrack++) {
1214 log << MSG::DEBUG << "iTrack " << iTrack << " / " <<(int)aMucTrackCol->size()<<endreq;
1215 aaTrack = (*aMucTrackCol)[iTrack];
1216 if(aaTrack->trackId()>=0) continue; // this track has been used
1217 aaTrack->setTrackId(iTrack);
1218 //cout<<"atrack set index "<<iTrack<<endl;
1219 for(int jTrack = iTrack+1; jTrack < (int)aMucTrackCol->size(); jTrack++){
1220 bbTrack = (*aMucTrackCol)[jTrack];
1221
1222 Hep3Vector mom_a = aaTrack->getMucMomentum();
1223 Hep3Vector mom_b = bbTrack->getMucMomentum();
1224
1225 //cout<<"angle is : "<<mom_a.angle(mom_b)<<endl;
1226 if(fabs(mom_a.angle(mom_b) - 3.1415926)<0.2)
1227 {
1228 bbTrack->setTrackId(iTrack);
1229 //cout<<"btrack set index "<<iTrack<<endl;
1230 //cout<<"find one cosmic ray"<<endl;
1231
1232 //cout<<"angle = "<<cosmicMom.angle(mom_a)<<" "<<cosmicMom.angle(mom_b)<<endl;
1233
1234 }
1235
1236 if(m_NtOutput>=1){
1237 m_angle_cosmic = cosmicMom.angle(mom_a);
1238 if(cosmicMom.angle(mom_a)>1.57) m_angle_cosmic = 3.14159265 - cosmicMom.angle(mom_a);
1239
1240 m_angle_updown = fabs(mom_a.angle(mom_b) - 3.1415926);
1241 m_px = -999; m_py = -999; m_pz = -999; m_theta = -999; m_phi = -999; m_theta_pipe = -999; m_phi_pipe = -999;
1242 m_px_mc = -999; m_py_mc = -999; m_pz_mc = -999; m_theta_mc = -999; m_phi_mc = -999;
1243 m_theta_mc_pipe = -999; m_phi_mc_pipe = -999;
1244
1245 //m_tuple->write();
1246 }
1247 }
1248
1249 }
1250
1251
1252 }
1253
1254 if( p3DRoadC->size() !=0 ) {
1255 log<<MSG::INFO << "In 3DRoad container : "
1256 << " Num of 3DRoad = " << p3DRoadC->size() <<endreq;
1257
1258 int print2DRoadInfo = 0;
1259 if (print2DRoadInfo == 1) {
1260 for ( int iRoad = 0; iRoad < (int)p3DRoadC->size(); iRoad++) {
1261 MucRec3DRoad *road = (*p3DRoadC)[iRoad];
1262 cout << endl << " " << iRoad << "th 3DRoad :" << endl
1263 << " Part = " << road->GetPart() << endl
1264 << " Seg = " << road->GetSeg() << endl
1265 << " NumGapsWithHits = " << road->GetNGapsWithHits() << endl
1266 << " TotalHits = " << road->GetTotalHits() << endl
1267 << " MaxHitsPerGap = " << road->GetMaxHitsPerGap() << endl
1268 << " LastGapDelta = " << road->GetLastGapDelta() << endl
1269 << " TotalHitsDelta = " << road->GetTotalHitsDelta() << endl
1270 << " DegreesOfFreedom = " << road->GetDegreesOfFreedom() << endl
1271 << " ReducedChiSquare = " << road->GetReducedChiSquare() << endl
1272 << " SlopeZX = " << road->GetSlopeZX() << endl
1273 << " InterceptZX = " << road->GetInterceptZX() << endl
1274 << " SlopeZY = " << road->GetSlopeZY() << endl
1275 << " InterceptZY = " << road->GetInterceptZY() << endl
1276 << " Hits Info : " << endl;
1277 //road->PrintHitsInfo();
1278 }
1279 }
1280
1281 m_NEventReco ++;
1282 }
1283
1284 //delete p3DRoadC
1285 for(int i = 0 ; i < p3DRoadC->size(); i++)
1286 delete (*p3DRoadC)[i];
1287 for(int i = 0 ; i < p2DRoad0C->size(); i++)
1288 delete (*p2DRoad0C)[i];
1289 for(int i = 0 ; i < p2DRoad1C->size(); i++)
1290 delete (*p2DRoad1C)[i];
1291
1292 p3DRoadC->clear();
1293 p2DRoad0C->clear();
1294 p2DRoad1C->clear();
1295 delete p3DRoadC;
1296 delete p2DRoad0C;
1297 delete p2DRoad1C;
1298 return StatusCode::SUCCESS;
1299}
1300
1301// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1303{
1304 MsgStream log(msgSvc(), name());
1305 log << MSG::INFO << "in finalize()" << endreq;
1306
1307 //cout << m_NHitsLostTotal << " of " << m_NHitsTotal << " total hits" << endl;
1308 //for(int i = 0; i < 20; i++) cout << "lost " << i << " hits event " << m_NHitsLost[i] << endl;
1309 //for(int i = 0; i < 9; i++) cout << "lost on gap " << i << " is " << m_NHitsLostInGap[i] << endl;
1310
1311 return StatusCode::SUCCESS;
1312}
1313
1314void
1316{
1317 MsgStream log(msgSvc(), name());
1318
1319 Hep3Vector currentPos = aTrack->GetCurrentPos();
1320 Hep3Vector currentDir = aTrack->GetCurrentDir();
1321 // if(currentPos.mag() < kMinor) {
1322 // log << MSG::WARNING << "No MUC intersection in track " << endreq;
1323 // continue;
1324 // }
1325
1326 int firstHitFound[2] = { 0, 0}; // Has the fist position in this orient determined? if so, could CorrectDirection()
1327 int firstHitGap[2] = {-1, -1}; // When the fist position in this orient determined, the gap it is on
1328 for(int partSeq = 0; partSeq < (int)MucID::getPartNum(); partSeq++) {
1329 int iPart = kPartSeq[partSeq];
1330 for(int iGap = 0; iGap < (int)MucID::getGapNum(iPart); iGap++) {
1331 int seg = -1;
1332 int orient = MucGeoGeneral::Instance()->GetGap(iPart, 0, iGap)->Orient();;
1333
1334 float xInsct, yInsct, zInsct;
1335 aTrack->Project(iPart, iGap, xInsct, yInsct, zInsct, seg);
1336 if(m_MsOutput) cout<<"part "<<iPart<<" gap "<<iGap<<" x "<<xInsct<<" y "<<yInsct<<" z "<<zInsct<<" seg "<<seg<<endl;
1337
1338 if(seg == -1) {
1339 //log << MSG::DEBUG << "no intersection with part " << iPart
1340 // << " gap " << iGap << " in this track !" << endl;
1341 continue;
1342 }
1343
1344 aTrack->SetCurrentInsct(xInsct, yInsct, zInsct);
1345
1346 for(int iDeltaSeg = 0; iDeltaSeg < kNSegSearch; iDeltaSeg++) {
1347 int iSeg = seg + kDeltaSeg[iDeltaSeg]; // also find on neighbor seg;
1348 if(iSeg < 0) iSeg += MucID::getSegNum(iPart);
1349 if(iSeg > (int)MucID::getSegNum(iPart) - 1) iSeg -= MucID::getSegNum(iPart);
1350
1351 float window = kWindowSize[iPart][iGap];
1352
1353 for (int iHit = 0; iHit < aMucRecHitContainer->GetGapHitCount(iPart, iSeg, iGap); iHit++) {
1354 log << MSG::DEBUG << "iSeg " << iSeg << " iHit " << iHit << endreq;
1355 MucRecHit* pHit = aMucRecHitContainer->GetHit(iPart, iSeg, iGap, iHit);
1356 //cout<< "strip " << pHit->Strip() << " center " << pHit->GetCenterPos() << endl;
1357
1358 if (!pHit) {
1359 log << MSG::WARNING << "MucRecTrkExt: null pointer to pHit" << endreq;
1360 continue;
1361 }
1362 else {
1363
1364 //this algo use with ext and this hit has been used before;
1365 if(pHit->GetHitMode() != -1 && pHit->GetHitMode() != 3) continue;
1366
1367 // Get the displacement of hit pHit to intersection
1368 float dX = aTrack->GetHitDistance(pHit);
1369 log << MSG::DEBUG << "distance = " << setw(8) << dX << " size " << setw(4) << window << endreq;
1370
1371 //cout<<"dX= "<<dX<<" window="<<window<<endl;
1372
1373 if (dX < window) {
1374 // Attach the hit if it exists
1375 //cout << "meet window " << pHit->GetSoftID() << endl;
1376 //****************if this if emc track, we abondon used hit in mdc*******************
1377 //if(m_emcrec == 1 )
1378 if(aTrack->GetRecMode() == 0) {
1379 pHit->SetHitMode(1); //mdc ext
1380 aTrack->AttachHit(pHit);
1381 //cout<<"in MucRecTrkExt: trackmode==0 so mdc ext "<<iPart<<" "<<iSeg<<" "<<iGap<<" "<<iHit<<endl;
1382 }
1383 if(aTrack->GetRecMode() == 1) {
1384 //cout<<"in MucRecTrkExt: HitMode = "<<pHit->GetHitMode()<<" part: "<<iPart<<" "<<iSeg<<" "<<iGap<<" "<<iHit<<endl;
1385 if(pHit->GetHitMode()!=1) {
1386 aTrack->AttachHit(pHit); //this hit has not been used by mdc ext
1387 pHit->SetHitMode(2); //emc ext
1388 }
1389 }
1390 if(aTrack->GetRecMode() == 2) {
1391 aTrack->AttachHit(pHit); //this hit has not been used by mdc ext
1392 //pHit->SetHitMode(2); //emc ext
1393 }
1394 if(aTrack->GetRecMode() == 3) {
1395 if(pHit->GetHitMode()!=1) {
1396 aTrack->AttachHit(pHit); //this hit has not been used by mdc ext
1397 pHit->SetHitMode(3); //emc ext
1398 }
1399 }
1400
1401 if (firstHitGap[orient] == -1) firstHitGap[orient] = iGap;
1402 firstHitFound[orient] = 1;
1403 //cout << "You could correct directon in orient " << orient << endl;
1404
1405 //cout<< " part " << iPart << " seg " << iSeg << " gap " << iGap
1406 // << " strip " << setw(2) << pHit->Strip() << " attatched" << endl;
1407
1408 log << MSG::DEBUG << " part " << iPart << " seg " << iSeg << " gap " << iGap
1409 << " strip " << setw(2) << pHit->Strip() << " attatched" << endreq;
1410 log << MSG::DEBUG << "current total hits " << aTrack->GetTotalHits() << endreq;
1411 }
1412 else {
1413 m_NHitsLostInGap[iGap]++;
1414 //log << MSG::DEBUG cout << " part " << iPart << " seg " << iSeg << " gap " << iGap
1415 // << " strip " << setw(2) << pHit->GetSoftID().GetStrip()
1416 // << " not attached !" << endreq;
1417 }
1418 }
1419 }
1420 aTrack->CalculateInsct(iPart, iSeg, iGap);
1421 }
1422
1423 if(m_onlyseedfit == 0) {//
1424 // When correct dir in the orient is permitted and this gap is not the gap first hit locates.
1425 if (firstHitFound[orient] && firstHitGap[orient] != iGap) aTrack->CorrectDir();
1426 aTrack->CorrectPos();
1427 //cout << "Current Intersection " << aTrack->GetCurrentInsct() << endl;
1428 //cout << "Current Direction " << aTrack->GetCurrentDir() << endl;
1429 aTrack->AttachInsct(aTrack->GetCurrentInsct());
1430 }// else; not correct pos & dir.
1431
1432 }
1433 }
1434 aTrack->LineFit(1);
1435 aTrack->ComputeTrackInfo(1);
1436 log << MSG::INFO << "Fit track done! trackIndex: " << aTrack->trackId() << ", mucId: " << aTrack->id() << ", RecMode: " << aTrack->GetRecMode() << endreq;
1437 //cout<<" in TrackFinding: depth= "<<aTrack->GetDepth()<<endl;
1438}
1439
1440// END
1441
1442
1443
struct sembuf release
Definition: BesClient.cxx:122
Double_t x[10]
DOUBLE_PRECISION count[3]
const int kSearchOrder[kNSeedLoops][3][2][5]
ObjectVector< MucRec2DRoad > MucRec2DRoadContainer
ObjectVector< MucRec3DRoad > MucRec3DRoadContainer
ObjectVector< MucRecHit > MucRecHitCol
ObjectVector< RecMucTrack > RecMucTrackCol
virtual void Dump()=0
MucGeoGap * GetGap(const int part, const int seg, const int gap) const
Get a pointer to the gap identified by (part,seg,gap).
static MucGeoGeneral * Instance()
Get a pointer to the single instance of MucGeoGeneral.
static int barrel_ec(const Identifier &id)
Values of different levels.
Definition: MucID.cxx:41
static int layer(const Identifier &id)
Definition: MucID.cxx:61
static int channel(const Identifier &id)
Definition: MucID.cxx:71
static int segment(const Identifier &id)
Definition: MucID.cxx:51
static value_type getPartNum()
Definition: MucID.cxx:159
static value_type getSegNum(int part)
Definition: MucID.cxx:164
static value_type getGapNum(int part)
Definition: MucID.cxx:171
int GetNGapsWithHits() const
How many gaps provide hits attached to this road?
int GetTotalHits() const
How many hits in all does this road contain?
float GetReducedChiSquare() const
Chi-square parameter (per degree of freedom) of the trajectory fit.
float GetIntercept() const
Intercept of trajectory.
void AttachHit(MucRecHit *hit)
Attach the given hit to this road.
int GetLastGap() const
Which gap is the last one with hits attached to this road?
void AttachHitNoFit(MucRecHit *hit)
Attach the given hit to this road, but not fit this road.
float GetSlope() const
Slope of trajectory.
void SetMaxNSkippedGaps(const int &nGaps)
int GetPart() const
In which part was this road found?
float GetHitDistance(const MucRecHit *hit)
Distance to a hit.
int GetDegreesOfFreedom() const
How many degrees of freedom in the trajectory fit?
vector< MucRecHit * > GetHits() const
int GetSeg() const
In which segment was this road found?
int GetOrient() const
In which orientation was this road found?
float GetSlopeZX() const
Get Z-X dimension slope.
float GetSlopeZY() const
Get Z-Y dimension slope.
void TransformPhiRToXY(const float &vk, const float &vr, const float &k0, const float &r0, float &vx, float &vy, float &x0, float &y0) const
Where does the trajectory of this road intersect the reference plane?
int GetLastGapDelta() const
Difference between the last gap in the two 1-D roads.
int GetPart() const
In which part was this road found?
int GetLastGap() const
Which gap is the last one with hits attached to this road?
int GetTotalHitsDelta() const
Difference between the number of hits in the two 1-D roads.
int GetTotalHits() const
How many hits in all does this road contain?
float GetInterceptZY() const
Get Z-Y dimension intercept.
void SetSimpleFitParams(const float &m_SlopeZX, const float &m_InterceptZX, const float &m_SlopeZY, const float &m_InterceptZY)
set the fit parameters : slope and intercept for XZ and YZ.
int GetSeg() const
In which segment was this road found?
int GetDegreesOfFreedom() const
How many degrees of freedom in the trajectory fit?
void ProjectWithSigma(const int &gap, float &x, float &y, float &z, float &sigmaX, float &sigmaY, float &sigmaZ)
Where does the trajectory of this road intersect a specific gap?
float GetInterceptZX() const
Get Z-X dimension intercept.
int GetNGapsWithHits() const
How many gaps provide hits attached to this road?
float GetReducedChiSquare() const
Chi-square parameter (per degree of freedom) of the trajectory fit.
int GetMaxHitsPerGap() const
How many hits were attached in the gap with the most attached hits?
void Clear()
Remove all hit objects from the container, and destroy them.
MucRecHit * GetHit(const MucRecHitID hitID)
Get a MucRecHit object by hit identifier.
void AddHit(const Identifier id)
MucRecHitCol * GetMucRecHitCol()
Get MucRecHitCol pointer.
void SetMucRecHitCol(MucRecHitCol *p)
int GetGapHitCount(const MucRecHitID gapID)
How many hits are there in this gap?
MucGeoGap * GetGap() const
Get geometry data for the gap containing this hit.
MucRecRoadFinder(const std::string &name, ISvcLocator *pSvcLocator)
StatusCode initialize()
void TrackFinding(RecMucTrack *aTrack)
int GetTotalHits() const
How many hits in all does this track contain?
void LineFit(int fittingMethod)
Line fit with hits on a seg with max hits.
void CorrectPos()
Correct current position of this trajectory.
void CorrectDir()
Correct direction of this trajectory.
void ComputeTrackInfo(int fittingmethod)
Get corresponding monte carlo track pointer.
Hep3Vector getMucPos() const
start position of this track in Muc.
void AttachInsct(Hep3Vector insct)
Attach the intersection to this trajectory.
void SetExtMucPos(const float x, const float y, const float z)
set start position of ext track in Muc. (compute from MdcPos MdcMomentum or get from ExtTrack)
void SetCurrentDir(const float x, const float y, const float z)
set current direction of the trajectory.
float GetHitDistance(const MucRecHit *hit)
Calculate the distance of the hit to the intersection in read direction.
void setTrackId(const int trackId)
set the index for this track.
Hep3Vector GetCurrentDir() const
Current direction.
Hep3Vector CalculateInsct(const int part, const int seg, const int gap)
Calculate intersection from all hits attached on this gap.
void Project(const int &part, const int &gap, float &x, float &y, float &z, int &seg)
Where does the trajectory of this track intersect a specific gap?
void SetMucMomentum(const float px, const float py, const float pz)
set start moment of the track in Muc.
Hep3Vector GetCurrentInsct() const
Current intersection.
void SetExtMucMomentum(const float px, const float py, const float pz)
set start moment of ext track in Muc.
vector< MucRecHit * > GetHits() const
Get all hits on this track.
void AttachHit(MucRecHit *hit)
set corresponding monte carlo track pointer.
Hep3Vector GetCurrentPos() const
Current position.
void SetCurrentInsct(const float x, const float y, const float z)
set current intersection of the trajectory with strip plane.
Hep3Vector getMucMomentum() const
Start momentum of this track in Muc.
void SetCurrentPos(const float x, const float y, const float z)
set current position of the trajectory.
vector< MucRecHit * > GetExpectedHits() const
void SetMucPos(const float x, const float y, const float z)
set start position of the track in Muc. (after line fit and correction)