2#include "GaudiKernel/MsgStream.h"
3#include "GaudiKernel/AlgFactory.h"
4#include "GaudiKernel/ISvcLocator.h"
5#include "GaudiKernel/SmartDataPtr.h"
6#include "GaudiKernel/IDataProviderSvc.h"
7#include "GaudiKernel/IPartPropSvc.h"
8#include "GaudiKernel/PropertyMgr.h"
9#include "GaudiKernel/IService.h"
10#include "GaudiKernel/NTuple.h"
11#include "GaudiKernel/INTupleSvc.h"
18#include "TStopwatch.h"
56#include "GaudiKernel/IPartPropSvc.h"
75#include "CLHEP/Vector/ThreeVector.h"
76#include "CLHEP/Vector/LorentzVector.h"
77#include "CLHEP/Vector/TwoVector.h"
78using CLHEP::Hep3Vector;
79using CLHEP::Hep2Vector;
80using CLHEP::HepLorentzVector;
112 Algorithm(name, pSvcLocator)
114 declareProperty(
"sigma", sigma = 0.13);
115 declareProperty(
"Run10_Flag", Run10_Flag =
false);
116 declareProperty(
"Align_Flag", Align_Flag =
false);
118 declareProperty(
"Method", Method = 0);
119 declareProperty(
"MAX_COMB",
MAX_COMB = 50);
120 declareProperty(
"MAX_Clusters", MAX_Clusters = 500);
121 declareProperty(
"MaxClu_Sheet",
Nmax = 3);
122 declareProperty(
"Chisq_cut", Chisq_cut = 2000);
123 declareProperty(
"TEST_N",
TEST_N = 0);
124 declareProperty(
"Debug",
debug = 0);
126 declareProperty(
"MC",
MC = 0);
131 MsgStream log(
msgSvc(), name());
134 log << MSG::INFO <<
"in initialize()" << endreq;
136 NTuplePtr cosmic(
ntupleSvc(),
"LineFit/cosmic");
137 if ( cosmic ) m_tuple = cosmic;
139 m_tuple =
ntupleSvc()->book (
"LineFit/cosmic", CLID_ColumnWiseTuple,
"N-Tuple example");
142 sc = m_tuple->addItem (
"run",run);
143 sc = m_tuple->addItem (
"event",event);
144 sc = m_tuple->addItem (
"R0",R0);
145 sc = m_tuple->addItem (
"R1",R1);
146 sc = m_tuple->addItem (
"R2",R2);
147 sc = m_tuple->addItem (
"clst_0",clst_0);
148 sc = m_tuple->addItem (
"clst_1",clst_1);
149 sc = m_tuple->addItem (
"clst_2",clst_2);
150 sc = m_tuple->addItem (
"clst_01",clst_01);
151 sc = m_tuple->addItem (
"clst_00",clst_00);
152 sc = m_tuple->addItem (
"clst_11",clst_11);
153 sc = m_tuple->addItem (
"clst_10",clst_10);
154 sc = m_tuple->addItem (
"status1",status1);
155 sc = m_tuple->addItem (
"status2",status2);
156 sc = m_tuple->addItem (
"status3",status3);
157 sc = m_tuple->addItem (
"ini_0",ini_0);
158 sc = m_tuple->addItem (
"ini_1",ini_1);
159 sc = m_tuple->addItem (
"ini_2",ini_2);
160 sc = m_tuple->addItem (
"ini_3",ini_3);
161 sc = m_tuple->addItem (
"inim_0",inim_0);
162 sc = m_tuple->addItem (
"inim_1",inim_1);
163 sc = m_tuple->addItem (
"inim_2",inim_2);
164 sc = m_tuple->addItem (
"inim_3",inim_3);
165 sc = m_tuple->addItem (
"inii_0",inii_0);
166 sc = m_tuple->addItem (
"inii_1",inii_1);
167 sc = m_tuple->addItem (
"inii_2",inii_2);
168 sc = m_tuple->addItem (
"inii_3",inii_3);
169 sc = m_tuple->addItem (
"par0",par0);
170 sc = m_tuple->addItem (
"par1",par1);
171 sc = m_tuple->addItem (
"par2",par2);
172 sc = m_tuple->addItem (
"par3",par3);
173 sc = m_tuple->addItem (
"MC_par0",MC_par0);
174 sc = m_tuple->addItem (
"MC_par1",MC_par1);
175 sc = m_tuple->addItem (
"MC_par2",MC_par2);
176 sc = m_tuple->addItem (
"MC_par3",MC_par3);
177 sc = m_tuple->addItem (
"MC_px",MC_px);
178 sc = m_tuple->addItem (
"MC_py",MC_py);
179 sc = m_tuple->addItem (
"MC_pz",MC_pz);
180 sc = m_tuple->addItem (
"Err_par0",Err_par0);
181 sc = m_tuple->addItem (
"Err_par1",Err_par1);
182 sc = m_tuple->addItem (
"Err_par2",Err_par2);
183 sc = m_tuple->addItem (
"Err_par3",Err_par3);
185 sc = m_tuple->addItem (
"x_2_up",x_2_up);
186 sc = m_tuple->addItem (
"v_2_up",v_2_up);
187 sc = m_tuple->addItem (
"x_1_up",x_1_up);
188 sc = m_tuple->addItem (
"v_1_up",v_1_up);
189 sc = m_tuple->addItem (
"x_0_up",x_0_up);
190 sc = m_tuple->addItem (
"v_0_up",v_0_up);
191 sc = m_tuple->addItem (
"x_2_down",x_2_down);
192 sc = m_tuple->addItem (
"v_2_down",v_2_down);
193 sc = m_tuple->addItem (
"z_1_up",z_1_up);
194 sc = m_tuple->addItem (
"z_2_up",z_2_up);
195 sc = m_tuple->addItem (
"z_0_up",z_0_up);
196 sc = m_tuple->addItem (
"z_1_down",z_1_down);
197 sc = m_tuple->addItem (
"z_2_down",z_2_down);
198 sc = m_tuple->addItem (
"z_0_down",z_0_down);
199 sc = m_tuple->addItem (
"x_1_down",x_1_down);
200 sc = m_tuple->addItem (
"v_1_down",v_1_down);
201 sc = m_tuple->addItem (
"x_0_down",x_0_down);
202 sc = m_tuple->addItem (
"v_0_down",v_0_down);
205 sc = m_tuple->addItem (
"x_2_up_m",x_2_up_m);
206 sc = m_tuple->addItem (
"x_1_up_m",x_1_up_m);
207 sc = m_tuple->addItem (
"x_0_up_m",x_0_up_m);
208 sc = m_tuple->addItem (
"x_0_down_m",x_0_down_m);
209 sc = m_tuple->addItem (
"x_1_down_m",x_1_down_m);
210 sc = m_tuple->addItem (
"x_2_down_m",x_2_down_m);
211 sc = m_tuple->addItem (
"v_2_up_m",v_2_up_m);
212 sc = m_tuple->addItem (
"v_1_up_m",v_1_up_m);
213 sc = m_tuple->addItem (
"v_0_up_m",v_0_up_m);
214 sc = m_tuple->addItem (
"v_0_down_m",v_0_down_m);
215 sc = m_tuple->addItem (
"v_1_down_m",v_1_down_m);
216 sc = m_tuple->addItem (
"v_2_down_m",v_2_down_m);
217 sc = m_tuple->addItem (
"z_2_up_m",z_2_up_m);
218 sc = m_tuple->addItem (
"z_1_up_m",z_1_up_m);
219 sc = m_tuple->addItem (
"z_0_up_m",z_0_up_m);
220 sc = m_tuple->addItem (
"z_0_down_m",z_0_down_m);
221 sc = m_tuple->addItem (
"z_1_down_m",z_1_down_m);
222 sc = m_tuple->addItem (
"z_2_down_m",z_2_down_m);
224 sc = m_tuple->addItem (
"x_2_up_f",x_2_up_f);
225 sc = m_tuple->addItem (
"x_1_up_f",x_1_up_f);
226 sc = m_tuple->addItem (
"x_0_up_f",x_0_up_f);
227 sc = m_tuple->addItem (
"x_0_down_f",x_0_down_f);
228 sc = m_tuple->addItem (
"x_1_down_f",x_1_down_f);
229 sc = m_tuple->addItem (
"x_2_down_f",x_2_down_f);
230 sc = m_tuple->addItem (
"v_2_up_f",v_2_up_f);
231 sc = m_tuple->addItem (
"v_1_up_f",v_1_up_f);
232 sc = m_tuple->addItem (
"v_0_up_f",v_0_up_f);
233 sc = m_tuple->addItem (
"v_0_down_f",v_0_down_f);
234 sc = m_tuple->addItem (
"v_1_down_f",v_1_down_f);
235 sc = m_tuple->addItem (
"v_2_down_f",v_2_down_f);
237 sc = m_tuple->addItem (
"x_2_up_mc",x_2_up_mc);
238 sc = m_tuple->addItem (
"x_1_up_mc",x_1_up_mc);
239 sc = m_tuple->addItem (
"x_0_up_mc",x_0_up_mc);
240 sc = m_tuple->addItem (
"x_0_down_mc",x_0_down_mc);
241 sc = m_tuple->addItem (
"x_1_down_mc",x_1_down_mc);
242 sc = m_tuple->addItem (
"x_2_down_mc",x_2_down_mc);
243 sc = m_tuple->addItem (
"v_2_up_mc",v_2_up_mc);
244 sc = m_tuple->addItem (
"v_1_up_mc",v_1_up_mc);
245 sc = m_tuple->addItem (
"v_0_up_mc",v_0_up_mc);
246 sc = m_tuple->addItem (
"v_0_down_mc",v_0_down_mc);
247 sc = m_tuple->addItem (
"v_1_down_mc",v_1_down_mc);
248 sc = m_tuple->addItem (
"v_2_down_mc",v_2_down_mc);
251 sc = m_tuple->addItem (
"inter_1_x",inter_1_x);
252 sc = m_tuple->addItem (
"inter_2_x",inter_2_x);
253 sc = m_tuple->addItem (
"inter_3_x",inter_3_x);
254 sc = m_tuple->addItem (
"inter_4_x",inter_4_x);
256 sc = m_tuple->addItem (
"inter_1_V",inter_1_V);
257 sc = m_tuple->addItem (
"inter_2_V",inter_2_V);
258 sc = m_tuple->addItem (
"inter_3_V",inter_3_V);
259 sc = m_tuple->addItem (
"inter_4_V",inter_4_V);
261 sc = m_tuple->addItem (
"inter_1_flag",inter_1_flag);
262 sc = m_tuple->addItem (
"inter_2_flag",inter_2_flag);
263 sc = m_tuple->addItem (
"inter_3_flag",inter_3_flag);
264 sc = m_tuple->addItem (
"inter_4_flag",inter_4_flag);
266 sc = m_tuple->addItem (
"inter_1_z",inter_1_z);
267 sc = m_tuple->addItem (
"inter_2_z",inter_2_z);
268 sc = m_tuple->addItem (
"inter_3_z",inter_3_z);
269 sc = m_tuple->addItem (
"inter_4_z",inter_4_z);
272 sc = m_tuple->addItem (
"chisq_1",chisq_1);
273 sc = m_tuple->addItem (
"chisq_2",chisq_2);
274 sc = m_tuple->addItem (
"chisq_3",chisq_3);
275 sc = m_tuple->addItem (
"pos_x",pos_x);
276 sc = m_tuple->addItem (
"pos_y",pos_y);
277 sc = m_tuple->addItem (
"pos_z",pos_z);
279 sc = m_tuple->addItem (
"hit_x",hit_x);
280 sc = m_tuple->addItem (
"hit_y",hit_y);
281 sc = m_tuple->addItem (
"hit_z",hit_z);
283 sc = m_tuple->addItem (
"ang_1",ang_1);
284 sc = m_tuple->addItem (
"ang_1_x",ang_1_x);
285 sc = m_tuple->addItem (
"ang_1_v",ang_1_v);
287 sc = m_tuple->addItem (
"ang_2",ang_2);
288 sc = m_tuple->addItem (
"ang_2_x",ang_2_x);
289 sc = m_tuple->addItem (
"ang_2_v",ang_2_v);
291 sc = m_tuple->addItem (
"ang_3",ang_3);
292 sc = m_tuple->addItem (
"ang_3_x",ang_3_x);
293 sc = m_tuple->addItem (
"ang_3_v",ang_3_v);
295 sc = m_tuple->addItem (
"ang_4",ang_4);
296 sc = m_tuple->addItem (
"ang_4_x",ang_4_x);
297 sc = m_tuple->addItem (
"ang_4_v",ang_4_v);
298 sc = m_tuple->addItem (
"Res_phi",Res_phi);
299 sc = m_tuple->addItem (
"Res_V",Res_V);
300 sc = m_tuple->addItem (
"Test_phi",Test_phi);
301 sc = m_tuple->addItem (
"Test_V",Test_V);
304 log << MSG::ERROR <<
"Cannot book N-tuple:" << long(m_tuple) << endmsg;
305 return StatusCode::FAILURE;
314 m_tuple_track =
ntupleSvc()->book (
"LineFit/Track", CLID_ColumnWiseTuple,
"N-Tuple example");
315 if ( m_tuple_track ) {
316 sc = m_tuple_track->addItem (
"run", tr_run);
317 sc = m_tuple_track->addItem (
"event", tr_event);
318 sc = m_tuple_track->addItem (
"drho", tr_drho);
319 sc = m_tuple_track->addItem (
"phi0", tr_phi0);
320 sc = m_tuple_track->addItem (
"dz0", tr_dz0);
321 sc = m_tuple_track->addItem (
"chisq", tr_chisq);
322 sc = m_tuple_track->addItem (
"Is_fitted", tr_Is_fitted);
323 sc = m_tuple_track->addItem (
"tanLam", tr_tanLam);
324 sc = m_tuple_track->addItem (
"ncluster", tr_ncluster, 0, 5000);
325 sc = m_tuple_track->addItem (
"id_cluster", tr_ncluster, tr_id_cluster);
326 sc = m_tuple_track->addItem (
"x_cluster", tr_ncluster, tr_x_cluster);
327 sc = m_tuple_track->addItem (
"y_cluster", tr_ncluster, tr_y_cluster);
328 sc = m_tuple_track->addItem (
"z_cluster", tr_ncluster, tr_z_cluster);
329 sc = m_tuple_track->addItem (
"Q_cluster", tr_ncluster, tr_Q_cluster);
330 sc = m_tuple_track->addItem (
"phi_cluster", tr_ncluster, tr_phi_cluster);
331 sc = m_tuple_track->addItem (
"layer_cluster", tr_ncluster, tr_layer_cluster);
332 sc = m_tuple_track->addItem (
"sheet_cluster", tr_ncluster, tr_sheet_cluster);
333 sc = m_tuple_track->addItem (
"Is_selected_cluster", tr_ncluster, tr_Is_selected_cluster);
337 log << MSG::ERROR <<
"Cannot book N-tuple:" << long(m_tuple_track) << endmsg;
338 return StatusCode::FAILURE;
343 sc = service (
"RawDataProviderSvc", irawDataProviderSvc);
345 if ( sc.isFailure() ){
346 log << MSG::FATAL << name()<<
" Could not load RawDataProviderSvc!" << endreq;
347 return StatusCode::FAILURE;
351 sc = service (
"CgemGeomSvc", icgemGeomSvc);
352 m_cgemGeomSvc =
dynamic_cast<CgemGeomSvc*
> (icgemGeomSvc);
354 if ( sc.isFailure() ){
355 log << MSG::FATAL <<
"Could not load CgemGeomSvc!" << endreq;
356 return StatusCode::FAILURE;
377 cout <<
"CgemLineFit alignment: is it on? " << Align_Flag << endl;
379 for(
int ilay=0; ilay<6; ilay++) {
380 cout <<
"LAYER " << ilay+1 << endl;
381 cout <<
"shift dx " <<
Al->
getDx(ilay) <<
" dy " <<
Al->
getDy(ilay) <<
" dz " <<
Al->
getDz(ilay) << endl;
382 cout <<
"rotation Rx " <<
Al->
getRx(ilay) <<
" Ry " <<
Al->
getRy(ilay) <<
" Rz " <<
Al->
getRz(ilay) << endl;
383 cout <<
"midplane radius " <<
Mp->
getR(
int(ilay/2)) << endl;
388 sc = service (
"CgemCalibFunSvc", icgemCalibSvc);
390 if ( sc.isFailure() ){
391 log << MSG::FATAL <<
"Could not load CgemCalibFunSvc!" << endreq;
392 return StatusCode::FAILURE;
395 return StatusCode::SUCCESS;
400 MsgStream log(
msgSvc(), name());
401 log << MSG::INFO <<
"in execute()" << endreq;
403 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
405 log << MSG::FATAL <<
"Could not find Event Header" << endreq;
406 return StatusCode::FAILURE;
409 SmartDataPtr<RecCgemClusterCol> recCgemClusterCol(eventSvc(),
"/Event/Recon/RecCgemClusterCol");
410 if (!recCgemClusterCol){
411 log << MSG::WARNING <<
"Could not retrieve Cgem cluster list" << endreq;
412 return StatusCode::FAILURE;
415 m_event=eventHeader->eventNumber();
416 m_run=eventHeader->runNumber();
421 if((m_event % 100)==0)cout<<
" begin evt : "<<
event <<endl;
443 SmartRefVector<RecCgemCluster>().swap(vecclusters);
453 if(
debug) cout<<
"start Straight line fit"<<endl;
458 m_tuple_track->write();
459 return StatusCode::SUCCESS;}}
464 m_tuple_track->write();
465 return StatusCode::SUCCESS;}}
470 m_tuple_track->write();
471 return StatusCode::SUCCESS;}}
476 m_tuple_track->write();
477 return StatusCode::SUCCESS;}}
482 m_tuple_track->write();
483 return StatusCode::SUCCESS;}}
486 return StatusCode::SUCCESS;
492 double trkpar[4]={-999,-999,-999,-999};
493 double trkparErr[4]={-999,-999,-999,-999};
494 Int_t ierflg ,npari,nparx,istat3;
495 Double_t fmin,edm,errdef;
496 fit -> mnstat(fmin, edm, errdef, npari, nparx, istat3);
497 for(
int i=0; i<4; i++){
498 fit -> GetParameter(i, trkpar[i], trkparErr[i]);}
505 double chisq_last = chisq_3;
508 vector<double> _trkpar=
Trans(trkpar[0],trkpar[1],trkpar[2],trkpar[3]);
514 Err_par0=trkparErr[0];
515 Err_par1=trkparErr[1];
516 Err_par2=trkparErr[2];
517 Err_par3=trkparErr[3];
535 if(
debug) cout<<
"Get_otherIniPar"<<endl;
544 if(
debug) cout<<
"Rec_Clusters"<<endl;
549 if(
debug) cout<<
"Fit_Clusters"<<endl;
553 if(
debug) cout<<
"GetIntersection"<<endl;
557 if(
debug) cout<<
"GetRes"<<endl;
559 StraightLine l_fit(trkpar[0],trkpar[1],trkpar[2],trkpar[3]);
569 m_tuple_track->write();
570 if(
debug) cout<<
"Finish all"<<endl;
573 return StatusCode::SUCCESS;
578 MsgStream log(
msgSvc(), name());
579 log << MSG::INFO<<
"in finalize()" << endreq;
580 return StatusCode::SUCCESS;
589 double cl_00(0),cl_01(0),cl_11(0),cl_10(0);
592 SmartDataPtr<RecCgemClusterCol> recCgemClusterCol(eventSvc(),
"/Event/Recon/RecCgemClusterCol");
593 RecCgemClusterCol::iterator
iter =recCgemClusterCol->begin();
594 for(;
iter!=recCgemClusterCol->end();
iter++)
599 if(flag!=2)
continue;
608 int vir_layerid =
GetVirLay(layerid, _phi);
609 if(layerid==2||((!Run10_Flag)&&layerid==0&&_phi>acos(-1)))
continue;
618 Vec_v.push_back(_v );
623 vecclusters.push_back(cluster);
626 int NC = vecclusters.size();
627 if(
debug) cout<<
"NC is "<<
NC<<endl;
657 double cl_00(0),cl_01(0),cl_11(0),cl_10(0);
659 double maxQ_11(0),maxQ_10(0),maxQ_00(0),maxQ_01(0);
660 int max_11(-1),max_10(-1),max_00(-1),max_01(-1);
661 double maxv_00(0),maxv_01;
663 double phi_11(-1),phi_10(-1),phi_00(-1),phi_01(-1);
664 double z_11(0),z_10(0),z_00(0),z_01(0);
665 double cid_11(-1),cid_10(-1),cid_00(-1),cid_01(-1);
666 double Xid_11(-1),Xid_10(-1),Xid_00(-1),Xid_01(-1);
667 double Vid_11(-1),Vid_10(-1),Vid_00(-1),Vid_01(-1);
669 SmartDataPtr<RecCgemClusterCol> recCgemClusterCol(eventSvc(),
"/Event/Recon/RecCgemClusterCol");
670 RecCgemClusterCol::iterator
iter =recCgemClusterCol->begin();
674 for(;
iter!=recCgemClusterCol->end();
iter++)
691 if(_loop>MAX_Clusters)
break;
696 tr_id_cluster[ic]=clusterid;
701 tr_phi_cluster[ic]=_phi;
702 tr_layer_cluster[ic]=layerid;
703 tr_sheet_cluster[ic]=sheetid;
707 if(layerid==1&&sheetid==1&&maxQ_11<_Q){
708 maxQ_11=_Q;max_11=_loop;phi_11=_phi;z_11=z;cid_11=clusterid;Xid_11=clusterflagb;Vid_11=clusterflage;}
709 if(layerid==1&&sheetid==0&&maxQ_10<_Q){
710 maxQ_10=_Q;max_10=_loop;phi_10=_phi;z_10=z;cid_10=clusterid;Xid_10=clusterflagb;Vid_10=clusterflage;}
711 if(layerid==0&&sheetid==0&&_phi>0&&maxQ_01<_Q&&maxv_00!=_v){
712 maxQ_01=_Q;max_01=_loop;phi_01=_phi;z_01=z;cid_01=clusterid;Xid_01=clusterflagb;Vid_01=clusterflage;}
713 if(layerid==0&&sheetid==0&&_phi<0&&maxQ_00<_Q&&maxv_00!=_v){
714 maxQ_00=_Q;max_00=_loop;phi_00=_phi;z_00=z;cid_00=clusterid;Xid_00=clusterflagb;Vid_00=clusterflage;}
716 if(layerid==1&&sheetid==1)cl_11++;
717 if(layerid==0&&sheetid==0&&_phi>0)cl_01++;
718 if(layerid==0&&sheetid==0&&_phi<0)cl_00++;
719 if(layerid==1&&sheetid==0)cl_10++;
724 for(
int i=0; i<ic; i++)
726 tr_Is_selected_cluster[i]=0;
727 if(i==(max_00-1)&&maxQ_00>0) tr_Is_selected_cluster[i] =1;
728 if(i==(max_01-1)&&maxQ_01>0) tr_Is_selected_cluster[i] =1;
729 if(i==(max_10-1)&&maxQ_10>0) tr_Is_selected_cluster[i] =1;
730 if(i==(max_11-1)&&maxQ_11>0) tr_Is_selected_cluster[i] =1;
740 iter =recCgemClusterCol->begin();
741 for(;
iter!=recCgemClusterCol->end();
iter++)
758 if(!(_loop==max_00||_loop==max_10||_loop==max_01||_loop==max_11))
continue;
774 Vec_v.push_back(_v );
785 vecclusters.push_back(cluster);
788 NC = vecclusters.size();
815 double cl_00(0),cl_01(0),cl_11(0),cl_10(0);
817 double maxQ_11(0),maxQ_10(0),maxQ_00(0);
818 int max_11(-1),max_10(-1),max_00(-1);
819 SmartDataPtr<RecCgemClusterCol> recCgemClusterCol(eventSvc(),
"/Event/Recon/RecCgemClusterCol");
820 RecCgemClusterCol::iterator
iter =recCgemClusterCol->begin();
822 for(;
iter!=recCgemClusterCol->end();
iter++)
832 if(layerid==1&&sheetid==1&&maxQ_11<_Q){
833 maxQ_11=_Q;max_11=_loop; }
834 if(layerid==1&&sheetid==0&&maxQ_10<_Q){
835 maxQ_10=_Q;max_10=_loop; }
836 if(layerid==1&&sheetid==1)cl_11++;
837 if(layerid==0&&sheetid==0&&_phi>0)cl_01++;
838 if(layerid==0&&sheetid==0&&_phi<0)cl_00++;
839 if(layerid==1&&sheetid==0)cl_10++;
846 iter =recCgemClusterCol->begin();
847 for(;
iter!=recCgemClusterCol->end();
iter++)
864 if(_loop!=max_11&&_loop!=max_10&&layerid!=0)
continue;
872 Vec_v.push_back(t_v);
873 Vec_Z.push_back(t_Z);
881 Vec_v.push_back(_v );
892 vecclusters.push_back(cluster);
895 NC = vecclusters.size();
926 double cl_00(0),cl_01(0),cl_11(0),cl_10(0);
928 double maxQ_11(0),maxQ_10(0),maxQ_00(0);
929 int max_11(-1),max_10(-1),max_00(-1);
930 double C_00(0),C_10(0),C_11(0),C_01(0);
931 vector<double>Vec_00_layer,Vec_00_phi,Vec_00_Z,Vec_00_layerid,Vec_00_v,Vec_00_flag,Vec_00_Q,Vec_00_sheetid;
932 vector<double>Vec_01_layer,Vec_01_phi,Vec_01_Z,Vec_01_layerid,Vec_01_v,Vec_01_flag,Vec_01_Q,Vec_01_sheetid;
933 vector<double>Vec_10_layer,Vec_10_phi,Vec_10_Z,Vec_10_layerid,Vec_10_v,Vec_10_flag,Vec_10_Q,Vec_10_sheetid;
934 vector<double>Vec_11_layer,Vec_11_phi,Vec_11_Z,Vec_11_layerid,Vec_11_v,Vec_11_flag,Vec_11_Q,Vec_11_sheetid;
936 SmartDataPtr<RecCgemClusterCol> recCgemClusterCol(eventSvc(),
"/Event/Recon/RecCgemClusterCol");
937 RecCgemClusterCol::iterator
iter =recCgemClusterCol->begin();
938 vector<int>L_00,L_01,L_10,L_11;
940 for(;
iter!=recCgemClusterCol->end();
iter++)
957 if(_loop>MAX_Clusters)
break;
961 if(layerid==1&&sheetid==1&&
TEST_N!=1){
962 L_11.push_back(_loop); }
963 if(layerid==1&&sheetid==0&&
TEST_N!=4){
964 L_10.push_back(_loop); }
965 if(layerid==0&&sheetid==0&&_phi>0&&
TEST_N!=2){
966 L_01.push_back(_loop); }
967 if(layerid==0&&sheetid==0&&_phi<0&&
TEST_N!=3){
968 L_00.push_back(_loop); }
971 if(
TEST_N==1) L_11.push_back(-1);
972 if(
TEST_N==2) L_01.push_back(-1);
973 if(
TEST_N==3) L_00.push_back(-1);
974 if(
TEST_N==4) L_10.push_back(-1);
976 double Min_chi(1E10);
978 if((L_00.size()*L_01.size()*L_10.size()*L_11.size())>
MAX_COMB)
983 NXComb = L_00.size()*L_01.size()*L_10.size()*L_11.size();
985 for(
int i_11=0;i_11<L_11.size();i_11++){
986 for(
int i_10=0;i_10<L_10.size();i_10++){
987 for(
int i_00=0;i_00<L_00.size();i_00++){
988 for(
int i_01=0;i_01<L_01.size();i_01++){
1008 iter =recCgemClusterCol->begin();
1009 for(;
iter!=recCgemClusterCol->end();
iter++)
1014 if(!(_loop==L_11[i_11]||_loop==L_10[i_10]||_loop==L_00[i_00]||_loop==L_01[i_01]))
continue;
1025 int vir_layerid =
GetVirLay(layerid, _phi);
1035 Vec_v.push_back(t_v);
1036 Vec_Z.push_back(t_Z);
1044 Vec_v.push_back(_v );
1064 TMinuit* _fit=
Fit(l_outer_tmp,
fa,1);
1065 double _chi=_fit->fAmin;
1084 iter =recCgemClusterCol->begin();
1085 L_00.clear();L_01.clear();L_10.clear();L_11.clear();
1088 for(;
iter!=recCgemClusterCol->end();
iter++)
1093 if(flag!=2)
continue;
1100 if(C_00==_phi||C_01==_phi||C_11==_phi||C_10==_phi){
1101 if(layerid==1&&sheetid==1){
1102 L_11.push_back(_loop); }
1103 if(layerid==1&&sheetid==0){
1104 L_10.push_back(_loop); }
1105 if(layerid==0&&sheetid==0&&_phi>0){
1106 L_01.push_back(_loop); }
1107 if(layerid==0&&sheetid==0&&_phi<0){
1108 L_00.push_back(_loop); }
1114 if(
TEST_N==1)L_11.push_back(-1);
1115 if(
TEST_N==2)L_01.push_back(-1);
1116 if(
TEST_N==3)L_00.push_back(-1);
1117 if(
TEST_N==4)L_10.push_back(-1);
1119 clst_11=L_11.size();
1120 clst_01=L_01.size();
1121 clst_10=L_10.size();
1122 clst_00=L_00.size();
1123 if((L_00.size()*L_01.size()*L_10.size()*L_11.size())>
MAX_COMB)
1124 {cout<<
"xv size much "<<endl;
1128 NVComb = L_00.size()*L_01.size()*L_10.size()*L_11.size();
1130 for(
int i_11=0;i_11<L_11.size();i_11++){
1131 for(
int i_10=0;i_10<L_10.size();i_10++){
1132 for(
int i_00=0;i_00<L_00.size();i_00++){
1133 for(
int i_01=0;i_01<L_01.size();i_01++){
1153 iter =recCgemClusterCol->begin();
1154 for(;
iter!=recCgemClusterCol->end();
iter++)
1159 if(flag!=2)
continue;
1170 int vir_layerid =
GetVirLay(layerid, _phi);
1172 if(!(_loop==L_11[i_11]||_loop==L_10[i_10]||_loop==L_00[i_00]||_loop==L_01[i_01]))
continue;
1183 Vec_v.push_back(t_v);
1184 Vec_Z.push_back(t_Z);
1193 Vec_v.push_back(_v );
1216 TMinuit* _fit=
Fit(l_outer_tmp,
fa,2);
1217 double _chi=_fit->fAmin;
1253 iter =recCgemClusterCol->begin();
1254 for(;
iter!=recCgemClusterCol->end();
iter++)
1274 int vir_layerid =
GetVirLay(layerid, _phi);
1276 if(_loop>MAX_Clusters)
break;
1277 if(flag!=2)
continue;
1279 tr_id_cluster[ic]=clusterid;
1283 tr_Q_cluster[ic]=_Q;
1284 tr_phi_cluster[ic]=_phi;
1285 tr_layer_cluster[ic]=layerid;
1286 tr_sheet_cluster[ic]=sheetid;
1287 tr_Is_selected_cluster[ic] =0;
1289 if(!(_loop==C_00||_loop==C_10||_loop==C_01||_loop==C_11))
continue;
1291 tr_Is_selected_cluster[ic-1] =1;
1301 Vec_v.push_back(t_v);
1302 Vec_Z.push_back(t_Z);
1310 Vec_v.push_back(_v );
1320 vecclusters.push_back(cluster);
1323 NC = vecclusters.size();
1342 if(Min_chi<Chisq_cut)
1352 double cl_00(0),cl_01(0),cl_11(0),cl_10(0);
1354 double maxQ_11(0),maxQ_10(0),maxQ_00(0);
1355 int max_11(-1),max_10(-1),max_00(-1);
1356 double C_00(0),C_10(0),C_11(0),C_01(0);
1357 vector<double>Vec_00_layer,Vec_00_phi,Vec_00_Z,Vec_00_layerid,Vec_00_v,Vec_00_flag,Vec_00_Q,Vec_00_sheetid;
1358 vector<double>Vec_01_layer,Vec_01_phi,Vec_01_Z,Vec_01_layerid,Vec_01_v,Vec_01_flag,Vec_01_Q,Vec_01_sheetid;
1359 vector<double>Vec_10_layer,Vec_10_phi,Vec_10_Z,Vec_10_layerid,Vec_10_v,Vec_10_flag,Vec_10_Q,Vec_10_sheetid;
1360 vector<double>Vec_11_layer,Vec_11_phi,Vec_11_Z,Vec_11_layerid,Vec_11_v,Vec_11_flag,Vec_11_Q,Vec_11_sheetid;
1362 SmartDataPtr<RecCgemClusterCol> recCgemClusterCol(eventSvc(),
"/Event/Recon/RecCgemClusterCol");
1363 RecCgemClusterCol::iterator
iter =recCgemClusterCol->begin();
1364 vector<int>L_00,L_01,L_10,L_11;
1365 vector<double>Q_00,Q_01,Q_10,Q_11;
1367 if(
debug) cout<<
"start Loop_MaxQ method"<<endl;
1369 for(;
iter!=recCgemClusterCol->end();
iter++)
1386 if(
debug) cout<<
"layerid is "<<layerid<<endl;
1387 if(_loop>MAX_Clusters)
break;
1389 if(flag!=0)
continue;
1391 if(layerid==1&&sheetid==1){
1392 L_11.push_back(_loop); Q_11.push_back(_Q); }
1393 if(layerid==1&&sheetid==0){
1394 L_10.push_back(_loop); Q_10.push_back(_Q); }
1395 if(layerid==0&&sheetid==0&&_phi>0){
1396 L_01.push_back(_loop); Q_01.push_back(_Q); }
1397 if(layerid==0&&sheetid==0&&_phi<0){
1398 L_00.push_back(_loop); Q_00.push_back(_Q); }
1403 vector<int>L_00_s,L_01_s,L_10_s,L_11_s;
1410 if(
TEST_N==1){L_11_s.clear();L_11_s.push_back(-1);}
1411 else if(
TEST_N==2){L_01_s.clear();L_01_s.push_back(-1);}
1412 else if(
TEST_N==3){L_00_s.clear();L_00_s.push_back(-1);}
1413 else if(
TEST_N==4){L_10_s.clear();L_10_s.push_back(-1);}
1415 if(
debug) cout<<
"finish the first loop"<<endl;
1417 double Min_chi(1E10);
1418 NXComb = L_00_s.size()*L_01_s.size()*L_10_s.size()*L_11_s.size();
1420 for(
int i_11=0;i_11<L_11_s.size();i_11++){
1421 for(
int i_10=0;i_10<L_10_s.size();i_10++){
1422 for(
int i_00=0;i_00<L_00_s.size();i_00++){
1423 for(
int i_01=0;i_01<L_01_s.size();i_01++){
1443 iter =recCgemClusterCol->begin();
1444 for(;
iter!=recCgemClusterCol->end();
iter++)
1449 if(!(_loop==L_11_s[i_11]||_loop==L_10_s[i_10]||_loop==L_00_s[i_00]||_loop==L_01_s[i_01]))
continue;
1460 int vir_layerid =
GetVirLay(layerid, _phi);
1470 Vec_v.push_back(t_v);
1471 Vec_Z.push_back(t_Z);
1480 Vec_v.push_back(_v );
1491 if(
debug) cout<<
"before OrderCluster"<<endl;
1498 if(
debug) cout<<
"before IniPar"<<endl;
1504 if(
debug) cout<<
"before fit"<<endl;
1505 TMinuit* _fit=
Fit(l_outer_tmp,
fa,1);
1506 double _chi=_fit->fAmin;
1507 if(
debug) cout<<
"finish the fit and the chisq is "<<_chi<<endl;
1508 if(
debug) cout<<
"----------------------------------------"<<endl;
1526 if(
debug) cout<<
"finish the second loop"<<endl;
1528 iter =recCgemClusterCol->begin();
1529 L_00.clear();L_01.clear();L_10.clear();L_11.clear();
1530 L_00_s.clear();L_01_s.clear();L_10_s.clear();L_11_s.clear();
1531 Q_00.clear();Q_01.clear();Q_10.clear();Q_11.clear();
1534 for(;
iter!=recCgemClusterCol->end();
iter++)
1539 if(flag!=2)
continue;
1546 if(C_00==_phi||C_01==_phi||C_11==_phi||C_10==_phi){
1547 if(layerid==1&&sheetid==1){
1548 L_11.push_back(_loop); Q_11.push_back(_Q); }
1549 if(layerid==1&&sheetid==0){
1550 L_10.push_back(_loop); Q_10.push_back(_Q); }
1551 if(layerid==0&&sheetid==0&&_phi>0){
1552 L_01.push_back(_loop); Q_01.push_back(_Q); }
1553 if(layerid==0&&sheetid==0&&_phi<0){
1554 L_00.push_back(_loop); Q_00.push_back(_Q); }
1558 if(
debug) cout<<
"finish the third loop"<<endl;
1562 clst_11=L_11.size();
1563 clst_01=L_01.size();
1564 clst_10=L_10.size();
1565 clst_00=L_00.size();
1572 if(
TEST_N==1) {L_11_s.clear();L_11_s.push_back(-1);}
1573 else if(
TEST_N==2){L_01_s.clear();L_01_s.push_back(-1);}
1574 else if(
TEST_N==3){L_00_s.clear();L_00_s.push_back(-1);}
1575 else if(
TEST_N==4){L_10_s.clear();L_10_s.push_back(-1);}
1577 NVComb = L_00_s.size()*L_01_s.size()*L_10_s.size()*L_11_s.size();
1579 for(
int i_11=0;i_11<L_11_s.size();i_11++){
1580 for(
int i_10=0;i_10<L_10_s.size();i_10++){
1581 for(
int i_00=0;i_00<L_00_s.size();i_00++){
1582 for(
int i_01=0;i_01<L_01_s.size();i_01++){
1602 iter =recCgemClusterCol->begin();
1603 for(;
iter!=recCgemClusterCol->end();
iter++)
1608 if(flag!=2)
continue;
1609 if(!(_loop==L_11_s[i_11]||_loop==L_10_s[i_10]||_loop==L_00_s[i_00]||_loop==L_01_s[i_01]))
continue;
1620 int vir_layerid =
GetVirLay(layerid, _phi);
1632 Vec_v.push_back(t_v);
1633 Vec_Z.push_back(t_Z);
1642 Vec_v.push_back(_v );
1664 TMinuit* _fit=
Fit(l_outer_tmp,
fa,2);
1665 double _chi=_fit->fAmin;
1699 if(
debug) cout<<
"finish the forth loop"<<endl;
1702 iter =recCgemClusterCol->begin();
1703 for(;
iter!=recCgemClusterCol->end();
iter++)
1723 int vir_layerid =
GetVirLay(layerid, _phi);
1724 if(_loop>MAX_Clusters)
break;
1725 if(flag!=2)
continue;
1727 tr_id_cluster[ic]=clusterid;
1731 tr_Q_cluster[ic]=_Q;
1732 tr_phi_cluster[ic]=_phi;
1733 tr_layer_cluster[ic]=layerid;
1734 tr_sheet_cluster[ic]=sheetid;
1735 tr_Is_selected_cluster[ic] =0;
1739 if(!(_loop==C_00||_loop==C_10||_loop==C_01||_loop==C_11))
continue;
1740 tr_Is_selected_cluster[ic-1] =1;
1750 Vec_v.push_back(t_v);
1751 Vec_Z.push_back(t_Z);
1760 Vec_v.push_back(_v );
1770 vecclusters.push_back(cluster);
1773 NC = vecclusters.size();
1775 if(
debug) cout<<
"finish the fifth loop"<<endl;
1793 if(
debug) cout<<
"Event "<<
event<<
", Clu. ID are "<<C_00<<
", "<<C_01<<
", "<<C_10<<
", "<<C_11<<
", Loop_MaxQ Min_chi = "<<Min_chi<<endl;
1795 if(Min_chi<Chisq_cut)
1808 MsgStream log(
msgSvc(), name());
1810 IDataProviderSvc* eventSvc = NULL;
1811 Gaudi::svcLocator()->service(
"EventDataSvc", eventSvc);
1813 log << MSG::INFO <<
"makeTds:event Svc has been found" << endreq;
1815 log << MSG::FATAL <<
"makeTds:Could not find eventSvc" << endreq;
1816 return StatusCode::FAILURE;
1819 IDataManagerSvc *dataManSvc =
dynamic_cast<IDataManagerSvc*
>(eventSvc);;
1824 DataObject *aRecMdcTrackCol;
1825 eventSvc->findObject(
"/Event/Recon/RecMdcTrackCol",aRecMdcTrackCol);
1826 if(aRecMdcTrackCol != NULL) {
1827 dataManSvc->clearSubTree(
"/Event/Recon/RecMdcTrackCol");
1828 eventSvc->unregisterObject(
"/Event/Recon/RecMdcTrackCol");
1831 sc = eventSvc->registerObject(
"/Event/Recon/RecMdcTrackCol", recMdcTrackCol);
1832 if(sc.isFailure()) {
1833 log << MSG::FATAL <<
" Could not register RecMdcTrack collection" <<endreq;
1834 return StatusCode::FAILURE;
1836 log << MSG::INFO <<
"RecMdcTrackCol registered successfully!" <<endreq;
1840 DataObject *aRecMdcHitCol;
1841 eventSvc->findObject(
"/Event/Recon/RecMdcHitCol",aRecMdcHitCol);
1842 if(aRecMdcHitCol != NULL) {
1843 dataManSvc->clearSubTree(
"/Event/Recon/RecMdcHitCol");
1844 eventSvc->unregisterObject(
"/Event/Recon/RecMdcHitCol");
1847 sc = eventSvc->registerObject(
"/Event/Recon/RecMdcHitCol", recMdcHitCol);
1848 if(sc.isFailure()) {
1849 log << MSG::FATAL <<
" Could not register RecMdcHit collection" <<endreq;
1850 return StatusCode::FAILURE;
1852 log << MSG::INFO <<
"RecMdcHitCol registered successfully!" <<endreq;
1854 return StatusCode::SUCCESS;
1902 double dv1(0),dx1(0) ;
1924double CgemLineFit::dx(
double vir_layerid ,
double R,
double dr,
double phi0,
double dz,
double tanl,
double x )
1926 if(dr>R)
return 9999999999999;
1928 double phiV_up[2],phiV_down[2];
1930 double phiV_up1_old[2],phiV_down1_old[2];
1932 bool findinter =
false;
1936 if(!findinter)
return 9999999999999;
1938 phiV_up[0] = fmod((phiV_up[0]),(2.0*TMath::Pi()));
1939 phiV_down[0] = fmod((phiV_down[0]),(2.0*TMath::Pi()));
1941 if(phiV_up[0]<0) phiV_up[0]+=2.0*TMath::Pi();
1942 if(phiV_down[0]<0) phiV_down[0]+=2.0*TMath::Pi();
1946 double mdv=min(pow(dx1,2.0),pow(dx2,2.0));
1951double CgemLineFit::dV(
int vir_layerid,
double R ,
double dr,
double phi0,
double z0,
double tglam,
double x,
double V)
1956 double phiV_up[2],phiV_down[2];
1957 bool findinter =
false;
1961 if(!findinter)
return 9999999999999;
1966 if(dx1<dx2)
return pow(fabs(phiV_down[1]-V),2.0);
1967 else return pow(fabs(phiV_up[1]-V),2.0);
1977 double trkpar[4]={-999,-999,-999,-999};
1978 double trkparErr[4]={-999,-999,-999,-999};
1983 Int_t ierflg ,npari,nparx,istat1,istat2,istat3;
1984 Double_t fmin,edm,errdef;
1985 Double_t arglist[10];
1991 TMinuit *Min3 =
new TMinuit(4);
1992 Min3 -> SetFCN(
fcn3);
1993 Min3 -> SetPrintLevel(-1);
1995 Min3 -> mnparm(1,
"phi0" ,
l_outer->
phi0(), 0.01, -100*acos(-1), 100*acos(-1), ierflg);
1996 Min3 -> mnparm(2,
"dz" ,
l_outer->
dz(), 0.1 , -0.5*length, 0.5*length, ierflg);
1997 Min3 -> mnparm(3,
"tanL" ,
l_outer->
tanl(), 0.01, -9999, 9999, ierflg);
1998 Min3 -> mnexcm(
"MIGRAD", arglist, 2, ierflg);
2005 arglist[0] = 2000000;
2006 arglist[1] = 0.0001;
2008 TMinuit *Min =
new TMinuit(2);
2009 Min -> SetPrintLevel(-1);
2011 Min -> SetErrorDef(1.0);
2013 Min -> mnparm(1,
"phi0" ,
l_outer->
phi0(), 0.001, -100*acos(-1), 100*acos(-1), ierflg);
2014 arglist[0] = 2000000;
2018 Min -> mnexcm(
"MIGRAD", arglist, 2, ierflg);
2019 Min -> mnstat(fmin, edm, errdef, npari, nparx, istat1);
2020 Min -> GetParameter(0, trkpar[0], trkparErr[0]);
2021 Min -> GetParameter(1, trkpar[1], trkparErr[1]);
2027 if(typ==1)
return Min;
2031 TMinuit *Min2 =
new TMinuit(2);
2032 Min2 -> SetFCN(
fcn2);
2033 Min2 -> SetPrintLevel(-1);
2034 Min2 -> mnparm(0,
"dz" ,
l_outer->
dz(), 0.001 , -0.5*length, 0.5*length, ierflg);
2035 Min2 -> mnparm(1,
"tanL" ,
l_outer->
tanl(), 0.001 , -9999 , 9999, ierflg);
2036 Min2 -> mnexcm(
"MIGRAD", arglist, 2, ierflg);
2037 Min2 -> mnstat(fmin, edm, errdef, npari, nparx, istat2);
2038 for(
int i=0; i<2; i++){
2039 Min2 -> GetParameter(i, trkpar[i+2], trkparErr[i+2]);
2041 chisq_2=Min2->fAmin;
2047 TMinuit *Min3 =
new TMinuit(4);
2048 Min3 -> SetFCN(
fcn3);
2049 Min3 -> SetPrintLevel(-1);
2050 Min3 -> mnparm(0,
"dr" , trkpar[0], 0.001 , -1*
R_layer[2],
R_layer[2], ierflg);
2051 Min3 -> mnparm(1,
"phi0" , trkpar[1], 0.001 , -100*acos(-1), 100*acos(-1), ierflg);
2052 Min3 -> mnparm(2,
"dz" , trkpar[2], 0.001 , -0.5*length, 0.5*length, ierflg);
2053 Min3 -> mnparm(3,
"tanL" , trkpar[3], 0.001 , -9999, 9999, ierflg);
2054 Min3 -> mnexcm(
"MIGRAD", arglist, 2, ierflg);
2056 if(typ==0)
return Min3;
2067 for(
int i=0;i<
Vec_flag.size()-1;i++)
2108 vector<double>_x,_v;
2111 for(
int i=0;i<3;i++)
2114 _v.push_back(
Vec_v[i]);
2117 if(_x[0]==_x[1]&&_v[0]==_v[2])wrong=0;
2118 else if(_x[0]==_x[1]&&_v[1]==_v[2])wrong=1;
2119 else if(_x[0]==_x[2]&&_v[0]==_v[1])wrong=0;
2120 else if(_x[0]==_x[2]&&_v[2]==_v[1])wrong=2;
2121 else if(_x[1]==_x[2]&&_v[1]==_v[0])wrong=1;
2122 else if(_x[1]==_x[2]&&_v[2]==_v[0])wrong=2;
2126 erase(_iter[wrong]);
2132 vector<double>::iterator _iter_v;
2133 _iter_v=
Vec_v.begin();
2134 Vec_v.erase( _iter_v+i );
2136 vector<double>::iterator _iter_phi;
2140 vector<double>::iterator _iter_Z;
2141 _iter_Z=
Vec_Z.begin();
2142 Vec_Z.erase( _iter_Z+i );
2144 vector<double>::iterator _iter_layer;
2148 vector<double >::iterator _iter_layerid;
2152 vector<double >::iterator _iter_Virlayerid;
2156 vector<double>::iterator _iter_flag;
2198 vector <double>dst_up;
2199 vector <double>dst_down;
2208 number.push_back(i);
2215 for (
int j =0; j<number.size();j++)
2223 while(Loop!=number.size()-1){
2225 for (
int j=0 ;j<number.size()-1;j++)
2227 if(dst_up[j]>dst_up[j+1])
2229 swap(dst_up[j],dst_up[j+1]);
2230 swap(dst_down[j],dst_down[j+1]);
2231 swap(number[j],number[j+1]);
2238 for (
int j =0; j<number.size();j++)
2244 number.erase(number.begin());
2245 dst_up.erase(dst_up.begin());
2246 dst_down.erase(dst_down.begin());
2249 for (
int j =0; j<number.size();j++)
2256 while(Loop!=number.size()-1){
2258 for (
int j=0 ;j<number.size()-1;j++)
2260 if(dst_down[j]>dst_down[j+1])
2262 swap(dst_down[j],dst_down[j+1]);
2263 swap(number[j],number[j+1]);
2269 for (
int j =0; j<number.size();j++)
2274 number.erase(number.begin());
2282 number.push_back(i);
2290 while(Loop!=number.size()-1){
2292 for (
int j=0 ;j<number.size()-1;j++)
2296 swap(dst[j],dst[j+1]);
2297 swap(number[j],number[j+1]);
2304 number.erase(number.begin());
2308 for (
int j =0; j<number.size();j++)
2314 sort(number.begin(),number.end(),less<int>());
2315 for(
int i=number.size()-1;i!=-1;i--)
2327 vector<double>Vec_truth;
2331 vector<double> _Vec_truth=
Trans(Vec_truth[0],Vec_truth[1],Vec_truth[2],Vec_truth[3]);
2333 MC_par0=_Vec_truth[0];
2334 MC_par1=_Vec_truth[1];
2335 MC_par2=_Vec_truth[2];
2336 MC_par3=_Vec_truth[3];
2342 x_0_up_mc=V_MC_clusters[0];
2343 v_0_up_mc=V_MC_clusters[1];
2344 x_0_down_mc=V_MC_clusters[2];
2345 v_0_down_mc=V_MC_clusters[3];
2347 x_1_up_mc=V_MC_clusters[4];
2348 v_1_up_mc=V_MC_clusters[5];
2349 x_1_down_mc=V_MC_clusters[6];
2350 v_1_down_mc=V_MC_clusters[7];
2352 x_2_up_mc=V_MC_clusters[8];
2353 v_2_up_mc=V_MC_clusters[9];
2354 x_2_down_mc=V_MC_clusters[10];
2355 v_2_down_mc=V_MC_clusters[11];
2362 SmartDataPtr<Event::McParticleCol> mcParticleCol(eventSvc(),
"/Event/MC/McParticleCol");
2364 Event::McParticleCol::iterator iter_mc=mcParticleCol->begin();
2365 HepLorentzVector p4_mu(0,0,0,0);
2366 HepLorentzVector p4_pos(0,0,0,0);
2367 for(;iter_mc!=mcParticleCol->end();iter_mc++)
2369 if (!(*iter_mc)->decayFromGenerator())
continue;
2370 HepLorentzVector p4_mc(0,0,0,0);
2372 if (13==(*iter_mc)->particleProperty())
2375 p4_mu = (*iter_mc)->initialFourMomentum();
2376 p4_pos = (*iter_mc)->initialPosition();
2380 Hep3Vector _BP(p4_pos.x()*10,p4_pos.y()*10,p4_pos.z()*10);
2386 _mc.push_back(p4_mu.px());
2387 _mc.push_back(p4_mu.py());
2388 _mc.push_back(p4_mu.pz());
2402 vector<double>_V_par;
2410 double k=-1*(xa*xb+ya*yb)/(xb*xb+yb*yb);
2417 _V_par.push_back(l.
dr());
2418 _V_par.push_back(l.
phi0());
2419 _V_par.push_back(l.
dz());
2420 _V_par.push_back(l.
tanl());
2427 double L(500),W(160),
H(600);
2429 vector<double>_V_par;
2445 if(fabs(xc)>W/2)
return false;
2446 if(fabs(zc)>L/2)
return false;
2459 if(clst_0>=2&&clst_1>=2){
2462 vector<double> inii_par=
Trans(l_ini_i->
dr(),l_ini_i->
phi0(),l_ini_i->
dz(),l_ini_i->
tanl());
2471 vector<double> inim_par=
Trans(l_ini_m->
dr(),l_ini_m->
phi0(),l_ini_m->
dz(),l_ini_m->
tanl());
2483 if(clst_0>=2&&clst_1>=2){
2486 vector<double> inii_par=
Trans(l_ini_i->
dr(),l_ini_i->
phi0(),l_ini_i->
dz(),l_ini_i->
tanl());
2495 vector<double> inim_par=
Trans(l_ini_m->
dr(),l_ini_m->
phi0(),l_ini_m->
dz(),l_ini_m->
tanl());
2522 v_2_down =
Vec_v[i];
2523 z_2_down =
Vec_Z[i];
2535 v_1_down =
Vec_v[i];
2536 z_1_down =
Vec_Z[i];
2612 vector<double>Vec_truth;
2613 Vec_truth.push_back(par[0]);
2614 Vec_truth.push_back(par[1]);
2615 Vec_truth.push_back(par[2]);
2616 Vec_truth.push_back(par[3]);
2620 x_0_up_f= clusters[0];
2621 v_0_up_f= clusters[1];
2622 x_0_down_f= clusters[2];
2623 v_0_down_f= clusters[3];
2625 x_1_up_f= clusters[4];
2626 v_1_up_f= clusters[5];
2627 x_1_down_f= clusters[6];
2628 v_1_down_f= clusters[7];
2630 x_2_up_f= clusters[8];
2631 v_2_up_f= clusters[9];
2632 x_2_down_f= clusters[10];
2633 v_2_down_f= clusters[11];
2640 if(
debug) cout<<
"Start Getintersection"<<endl;
2641 Double_t fmin,edm,errdef;
2642 Int_t ierflg ,npari,nparx,istat;
2643 double trkpar[4]={-999,-999,-999,-999};
2644 double trkparErr[4]={-999,-999,-999,-999};
2646 double phiV_up[2],phiV_down[2];
2648 double phiV_up_Tmp[2],phiV_down_Tmp[2];
2654 fit -> mnstat(fmin, edm, errdef, npari, nparx, istat);
2656 for(
int i=0; i<4; i++){
2657 fit -> GetParameter(i, trkpar[i], trkparErr[i]);}
2671 inter_1_x=phiV_up[0];
2672 inter_1_V=phiV_up[1];
2676 inter_4_x=phiV_down[0];
2677 inter_4_V=phiV_down[1];
2699 fit -> mnstat(fmin, edm, errdef, npari, nparx, istat);
2701 for(
int i=0; i<4; i++){
2702 fit -> GetParameter(i, trkpar[i], trkparErr[i]);}
2713 inter_2_x=phiV_up[0];
2714 inter_2_V=phiV_up[1];
2729 fit -> mnstat(fmin, edm, errdef, npari, nparx, istat);
2731 for(
int i=0; i<4; i++){
2732 fit -> GetParameter(i, trkpar[i], trkparErr[i]);}
2744 inter_3_x=phiV_down[0];
2745 inter_3_V=phiV_down[1];
2761 vector<double>clusters;
2762 StraightLine l(Vec_truth[0],Vec_truth[1],Vec_truth[2],Vec_truth[3]);
2763 double phiV_up[2],phiV_down[2];
2766 double phiV_up_Tmp[2],phiV_down_Tmp[2];
2778 clusters.push_back(phiV_up[0]);
2779 clusters.push_back(phiV_up[1]);
2780 clusters.push_back(phiV_down[0]);
2781 clusters.push_back(phiV_down[1]);
2792 clusters.push_back(phiV_up[0]);
2793 clusters.push_back(phiV_up[1]);
2794 clusters.push_back(phiV_down[0]);
2795 clusters.push_back(phiV_down[1]);
2806 clusters.push_back(phiV_up[0]);
2807 clusters.push_back(phiV_up[1]);
2808 clusters.push_back(phiV_down[0]);
2809 clusters.push_back(phiV_down[1]);
2817 arg = fmod((
arg),(2.0*TMath::Pi()));
2818 if(
arg<0)
arg += 2.0*TMath::Pi();
2824 double diff_raw=fabs(arg1-arg2);
2826 if(diff_raw>acos(-1))
return (2*acos(-1)-diff_raw);
2827 else return diff_raw;
2833 double phiV_up[2],phiV_down[2];
2842 pow((phiV_up[1]-
v),2)+
2846 pow((phiV_down[1]-
v),2)+
2849 return min(ds1,ds2);
2856 double phiV_up[2],phiV_down[2];
2862 pow((phiV_up[1]-z),2)+
2874 double phiV_up[2],phiV_down[2];
2881 pow((phiV_down[1]-
v),2)+
2892 double phiV_up[2],phiV_down[2];
2897 if(Up[0]>9999||Up[1]>9999||Down[0]>9999||Down[1]>9999)
2906 vector<double> rotat;
2909 rotat.push_back(par0);
2910 rotat.push_back(par1);
2911 rotat.push_back(par2);
2912 rotat.push_back(par3);
2919 int virsheet = (phi<0)? 0:1;
2920 int virlay = geolay*2 +virsheet;
2928 vector<double> Q_11_s;
2930 if (L_11.size()>
Nmax)
2932 for(
int i=0;i<
Nmax;i++)
2934 for(
int j=i+1;j<L_11.size();j++)
2947 Q_11_s.push_back(Q_11[i]);
2948 L_11_s.push_back(L_11[i]);
2954 L_11_s.assign(L_11.begin(), L_11.end());
2955 Q_11_s.assign(Q_11.begin(), Q_11.end());
2966 int max_1_0(0),max_0_0(0);
2968 max_1_0=_size;max_0_0=_size;
2981 for(
int k=
Vec_flag.size()-1;k>max_0_0;k--)
2983 for(
int m=
Vec_flag.size()-2;m>max_1_0;m--)
2989 double trkpar[4]={-999,-999,-999,-999};
2990 double trkparErr[4]={-999,-999,-999,-999};
2992 Int_t ierflg ,npari,nparx,istat3;
2993 Double_t fmin,edm,errdef;
2995 fit -> mnstat(fmin, edm, errdef, npari, nparx, istat3);
2996 for(
int i=0; i<4; i++){
2997 fit -> GetParameter(i, trkpar[i], trkparErr[i]);}
2999 fit->mnemat(emat,4);
3004 helixPar[0]=trkpar[0];
3005 helixPar[1]=trkpar[1];
3007 helixPar[3]=trkpar[2];
3008 helixPar[4]=trkpar[3];
3009 double errorMat[15];
3011 errorMat[0]=emat[0];
3012 errorMat[1]=emat[1];
3014 errorMat[3]=emat[2];
3015 errorMat[4]=emat[3];
3016 errorMat[5]=emat[5];
3018 errorMat[7]=emat[6];
3019 errorMat[8]=emat[7];
3023 errorMat[12]=emat[10];
3024 errorMat[13]=emat[11];
3025 errorMat[14]=emat[15];
3027 recMdcTrack->
setChi2(fit->fAmin);
3034 m_trackList_tds->push_back(recMdcTrack);
3042 const Hep3Vector Normals(cluster[0],cluster[1],0);
3046 const Hep3Vector CosmicRay(x2[0]-x1[0],x2[1]-x1[1],x2[2]-x1[2]);
3047 const Hep3Vector z(0,0,1);
3048 const Hep3Vector phi=z.cross(Normals);
3049 Hep3Vector _phi=phi;
3051 const Hep3Vector V=_phi.rotate(-1*theta,Normals);
3053 const Hep3Vector N_V=Normals.cross(V);
3054 const Hep3Vector N_phi=Normals.cross(phi);
3056 Hep3Vector C_phi=CosmicRay-CosmicRay.project(N_phi);
3057 ang[0]=Normals.angle(C_phi);
3059 Hep3Vector C_V=CosmicRay-CosmicRay.project(N_V);
3060 ang[1]=Normals.angle(C_V);
3061 ang[2]=Normals.angle(CosmicRay);
3074 if(i_inter==1||i_inter==4)
3077 if(i_inter==1) i_sheet=1;
3079 double phiV_up[2],phiV_down[2];
3081 double phiV_up_Tmp[2],phiV_down_Tmp[2];
3090 double V,phi,min_dst(99999),min_V(99999),min_phi(99999);
3095 if(i_inter==3||i_inter==4){
3101 SmartDataPtr<RecCgemClusterCol> recCgemClusterCol(eventSvc(),
"/Event/Recon/RecCgemClusterCol");
3102 RecCgemClusterCol::iterator
iter =recCgemClusterCol->begin();
3104 for(;
iter!=recCgemClusterCol->end();
iter++)
3111 if(layerid!=i_layer)
continue;
3113 if(sheetid!=i_sheet)
continue;
3118 if(flag!=2)
continue;
3119 double dst=pow(_V-V,2.0)+pow(_phi-phi,2.0);
3141 if(SimuPhi <= TMath::Pi()) RPhi = SimuPhi;
3142 else RPhi = SimuPhi-2*TMath::Pi();
double sin(const BesAngle a)
double cos(const BesAngle a)
vector< double > Vec_m_layer
vector< double > Vec_Virlayerid
vector< double > Vec_flag
vector< double > Vec_m_layerid
vector< double > Vec_m_phi
vector< double > Vec_sheetid
CgemGeoReadoutPlane * pl_00
vector< double > Vec_layer
vector< double > Vec_m_flag
CgemGeoReadoutPlane * pl_20
vector< double > Vec_layerid
CgemGeoReadoutPlane * pl_11
CgemGeoReadoutPlane * pl_10
CgemGeoReadoutPlane * pl_21
vector< double > Vec_m_sheetid
double arg(const EvtComplex &c)
**********Class see also m_nmax DOUBLE PRECISION m_amel DOUBLE PRECISION m_x2 DOUBLE PRECISION m_alfinv DOUBLE PRECISION m_Xenph INTEGER m_KeyWtm INTEGER m_idyfs DOUBLE PRECISION m_zini DOUBLE PRECISION m_q2 DOUBLE PRECISION m_Wt_KF DOUBLE PRECISION m_WtCut INTEGER m_KFfin *COMMON c_KarLud $ !Input CMS energy[GeV] $ !CMS energy after beam spread beam strahlung[GeV] $ !Beam energy spread[GeV] $ !z boost due to beam spread $ !electron beam mass *ff pair spectrum $ !minimum v
ObjectVector< RecMdcHit > RecMdcHitCol
ObjectVector< RecMdcTrack > RecMdcTrackCol
double getDx(int layer_vir)
double getRx(int layer_vir)
double getRy(int layer_vir)
double getRz(int layer_vir)
double getDz(int layer_vir)
HepPoint3D point_invTransform(int layer_vir, HepPoint3D pos)
double getDy(int layer_vir)
CgemGeoLayer * getCgemLayer(int i) const
double getLengthOfCgem() const
CgemGeoReadoutPlane * getReadoutPlane(int iLayer, int iSheet) const
CgemMidDriftPlane * getMidDriftPtr() const
CgemGeoAlign * getAlignPtr() const
static vector< int > GetNMaxQ(vector< double > Q_11, vector< int > L_11, int Nmax)
void Filter(int layerid, StraightLine *l1)
StraightLine * IniPar(double phi1, double z1, int i, double phi2, double z2, int j)
vector< double > Get4Par(HepLorentzVector p4, Hep3Vector bp)
double Min_dis_up(int R_id, double x, double z, StraightLine *l1)
CgemLineFit(const std::string &name, ISvcLocator *pSvcLocator)
int GetVirLay(int geolay, double phi)
void Fit_Clusters(double par[])
static void fcn2(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag)
bool Layer_cross(int R_id, StraightLine *l1)
static vector< double > Trans(double par0, double par1, double par2, double par3)
double Min_dis_down(int R_id, double x, double z, StraightLine *l1)
static void fcn3(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag)
static void fcn(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag)
void IncidentAngle(StraightLine *cosmic_ray, HepPoint3D cluster, double theta, double ang[])
static double dV(int layer, double R, double dr, double phi0, double z0, double tglam, double x, double V)
double Min_dis(int R_id, double x, double z, StraightLine *l1)
vector< double > MC_truth()
bool HitPos(HepLorentzVector p4, Hep3Vector bp)
static void to_0_2pi(double &arg)
TMinuit * Fit(StraightLine *l_outer, int sheetflag, int typ)
static double dx(double layerid, double R, double dr, double phi0, double z0, double tanl, double x)
void Get_OtherIniPar(int clst_0, int clst_1, int clst_2)
static double Min_diff(double arg1, double arg2)
void Store_Trk(TMinuit *fit, int trkid)
double RealPhi(double SimuPhi)
vector< double > Get_Clusters(vector< double >Vec_truth)
StatusCode registerTrack(RecMdcTrackCol *&recMdcTrackCol, RecMdcHitCol *&recMdcHitCol)
bool getPointIdealGeom(int layer_vir, StraightLine pLine, HepPoint3D &posUp, HepPoint3D &posDown, double phiVUp[], double phiVDown[])
bool getPointAligned(int layer_vir, StraightLine pLine, HepPoint3D &posUp, HepPoint3D &posDown, double phiVUp[], double phiVDown[])
void setTrackId(const int trackId)
void setError(double err[15])
void setHelix(double helix[5])
void setChi2(const double chi)
double getrecphi_mTPC(void) const
double getenergydeposit(void) const
double getRecZ(void) const
int getclusterid(void) const
double getrecv_mTPC(void) const
int getlayerid(void) const
int getclusterflagb(void) const
double getRecZ_mTPC(void) const
double getrecphi(void) const
double getrecv(void) const
int getsheetid(void) const
int getclusterflage(void) const
void setVecClusters(ClusterRefVec vecclusters)
void setNcluster(int ncluster)
HepPoint3D x(double s=0.) const
returns position after moving s in downwoards
double dr(void) const
returns an element of parameters.