12#include "GaudiKernel/AlgFactory.h"
13#include "GaudiKernel/DataObject.h"
14#include "GaudiKernel/IEventProcessor.h"
16#include "GaudiKernel/Incident.h"
17#include "GaudiKernel/IIncidentSvc.h"
18#include "GaudiKernel/Memory.h"
23#include "GaudiKernel/ISvcLocator.h"
24#include "GaudiKernel/IDataProviderSvc.h"
25#include "GaudiKernel/Bootstrap.h"
26#include "GaudiKernel/RegistryEntry.h"
27#include "GaudiKernel/MsgStream.h"
37#include "GaudiKernel/SmartDataPtr.h"
45 Algorithm(name,pSvcLocator){
48 declareProperty(
"selGoodDigi",m_selGoodDigi=1);
49 declareProperty(
"minDigiTime",m_minDigiTime=-8875);
50 declareProperty(
"maxDigiTime",m_maxDigiTime=-8562);
51 declareProperty(
"minQDigi",myQMin=0.0);
52 declareProperty(
"LUTfile", lutfile =
"/bes3fs/cgemCosmic/data/CGEM_cosmic_look_up_table_from_17_to_17.root");
69 MsgStream log(
msgSvc(), name());
70 log << MSG::INFO <<
"TestClusterWithHit initialize()" << endreq;
75 sc = service(
"CgemGeomSvc", m_SvcCgem);
76 if(sc != StatusCode::SUCCESS) {
77 log << MSG::ERROR <<
"can not use CgemGeomSvc" << endreq;
78 return StatusCode::FAILURE;
85 output =
new TFile(
"cluster.root",
"RECREATE");
86 tree =
new TTree(
"tree",
"cluster info tree");
92 return StatusCode::SUCCESS;
96void TestClusterWithHit::DefineHitTree() {
98 tree->Branch(
"event", &event,
"event/I");
99 tree->Branch(
"nhit", &nhit,
"nhit/I");
101 tree->Branch(
"hit_strip", &hit_strip,
"hit_strip[nhit]/I");
102 tree->Branch(
"hit_view", &hit_view,
"hit_view[nhit]/I");
103 tree->Branch(
"hit_layer", &hit_layer,
"hit_layer[nhit]/I");
104 tree->Branch(
"hit_sheet", &hit_sheet,
"hit_sheet[nhit]/I");
108void TestClusterWithHit::DefineClusterTree() {
110 tree->Branch(
"ncluster", &ncluster,
"ncluster/I");
112 tree->Branch(
"ncluster_1d", &ncluster_1d,
"ncluster_1d/I");
113 tree->Branch(
"ncluster_1d_L1_S1_x", &ncluster_1d_L1_S1_x,
"ncluster_1d_L1_S1_x/I");
114 tree->Branch(
"ncluster_1d_L2_S1_x", &ncluster_1d_L2_S1_x,
"ncluster_1d_L2_S1_x/I");
115 tree->Branch(
"ncluster_1d_L2_S2_x", &ncluster_1d_L2_S2_x,
"ncluster_1d_L2_S2_x/I");
116 tree->Branch(
"ncluster_1d_L1_S1_v", &ncluster_1d_L1_S1_v,
"ncluster_1d_L1_S1_v/I");
117 tree->Branch(
"ncluster_1d_L2_S1_v", &ncluster_1d_L2_S1_v,
"ncluster_1d_L2_S1_v/I");
118 tree->Branch(
"ncluster_1d_L2_S2_v", &ncluster_1d_L2_S2_v,
"ncluster_1d_L2_S2_v/I");
119 tree->Branch(
"cluster_1d_ID", &cluster_1d_ID,
"cluster_1d_ID[ncluster]/D");
120 tree->Branch(
"cluster_1d_t", &cluster_1d_t,
"cluster_1d_t[ncluster]/D");
121 tree->Branch(
"cluster_1d_q", &cluster_1d_q,
"cluster_1d_q[ncluster]/D");
122 tree->Branch(
"cluster_1d_r", &cluster_1d_r,
"cluster_1d_r[ncluster]/D");
123 tree->Branch(
"cluster_1d_v", &cluster_1d_v,
"cluster_1d_v[ncluster]/D");
124 tree->Branch(
"cluster_1d_v_cc", &cluster_1d_v_cc,
"cluster_1d_v_cc[ncluster]/D");
125 tree->Branch(
"cluster_1d_v_tpc", &cluster_1d_v_tpc,
"cluster_1d_v_tpc[ncluster]/D");
126 tree->Branch(
"cluster_1d_phi", &cluster_1d_phi,
"cluster_1d_phi[ncluster]/D");
127 tree->Branch(
"cluster_1d_phi_cc", &cluster_1d_phi_cc,
"cluster_1d_phi_cc[ncluster]/D");
128 tree->Branch(
"cluster_1d_phi_tpc", &cluster_1d_phi_tpc,
"cluster_1d_phi_tpc[ncluster]/D");
129 tree->Branch(
"cluster_1d_layerid", &cluster_1d_layerid,
"cluster_1d_layerid[ncluster]/I");
130 tree->Branch(
"cluster_1d_sheetid", &cluster_1d_sheetid,
"cluster_1d_sheetid[ncluster]/I");
131 tree->Branch(
"cluster_1d_view", &cluster_1d_view,
"cluster_1d_view[ncluster]/I");
132 tree->Branch(
"cluster_1d_strip1", &cluster_1d_strip1,
"cluster_1d_strip1[ncluster]/I");
133 tree->Branch(
"cluster_1d_strip2", &cluster_1d_strip2,
"cluster_1d_strip2[ncluster]/I");
134 tree->Branch(
"cluster_1d_size", &cluster_1d_size,
"cluster_1d_size[ncluster]/I");
135 tree->Branch(
"cluster_1d_a_tpc", &cluster_1d_a_tpc,
"cluster_1d_a_tpc[ncluster]/D");
136 tree->Branch(
"cluster_1d_b_tpc", &cluster_1d_b_tpc,
"cluster_1d_b_tpc[ncluster]/D");
137 tree->Branch(
"cluster_1d_hitindex", cluster_1d_hitindex,
"cluster_1d_hitindex[ncluster][50]/I");
140 tree->Branch(
"ncluster_2d", &ncluster_2d,
"ncluster_2d/I");
141 tree->Branch(
"cluster_2d_t", &cluster_2d_t,
"cluster_2d_t[ncluster]/D");
142 tree->Branch(
"cluster_2d_q", &cluster_2d_q,
"cluster_2d_q[ncluster]/D");
143 tree->Branch(
"cluster_2d_r", &cluster_2d_r,
"cluster_2d_r[ncluster]/D");
144 tree->Branch(
"cluster_2d_z", &cluster_2d_z,
"cluster_2d_z[ncluster]/D");
145 tree->Branch(
"cluster_2d_z_cc", &cluster_2d_z_cc,
"cluster_2d_z_cc[ncluster]/D");
146 tree->Branch(
"cluster_2d_z_tpc", &cluster_2d_z_tpc,
"cluster_2d_z_tpc[ncluster]/D");
147 tree->Branch(
"cluster_2d_phi", &cluster_2d_phi,
"cluster_2d_phi[ncluster]/D");
148 tree->Branch(
"cluster_2d_phi_cc", &cluster_2d_phi_cc,
"cluster_2d_phi_cc[ncluster]/D");
149 tree->Branch(
"cluster_2d_phi_tpc", &cluster_2d_phi_tpc,
"cluster_2d_phi_tpc[ncluster]/D");
150 tree->Branch(
"cluster_2d_layerid", &cluster_2d_layerid,
"cluster_2d_layerid[ncluster]/I");
151 tree->Branch(
"cluster_2d_sheetid", &cluster_2d_sheetid,
"cluster_2d_sheetid[ncluster]/I");
152 tree->Branch(
"cluster_2d_view", &cluster_2d_view,
"cluster_2d_view[ncluster]/I");
153 tree->Branch(
"cluster_2d_idx", &cluster_2d_idx,
"cluster_2d_idx[ncluster]/I");
154 tree->Branch(
"cluster_2d_idv", &cluster_2d_idv,
"cluster_2d_idv[ncluster]/I");
155 tree->Branch(
"cluster_2d_highest", &cluster_2d_highest,
"cluster_2d_highest[ncluster]/I");
170 for(
int ihit = 0; ihit <
MAXNOFHITS; ihit++) {
171 hit_strip[ihit] = -1;
173 hit_layer[ihit] = -1;
174 hit_sheet[ihit] = -1;
181 ncluster_1d_L1_S1_x = 0;
182 ncluster_1d_L2_S1_x = 0;
183 ncluster_1d_L2_S2_x = 0;
184 ncluster_1d_L1_S1_v = 0;
185 ncluster_1d_L2_S1_v = 0;
186 ncluster_1d_L2_S2_v = 0;
190 cluster_1d_t[iclu] = 0.;
191 cluster_1d_q[iclu] = 0.;
192 cluster_1d_r[iclu] = 0.;
193 cluster_1d_v[iclu] = 0.;
194 cluster_1d_phi[iclu] = 0.;
195 cluster_1d_v_cc[iclu] = 0.;
196 cluster_1d_phi_cc[iclu] = 0.;
197 cluster_1d_v_tpc[iclu] = 0.;
198 cluster_1d_phi_tpc[iclu] = 0.;
199 cluster_1d_a_tpc[iclu] = 0.;
200 cluster_1d_b_tpc[iclu] = 0.;
201 cluster_1d_layerid[iclu] = -1;
202 cluster_1d_sheetid[iclu] = -1;
203 cluster_1d_view[iclu] = -1;
204 cluster_1d_size[iclu] = -1;
205 cluster_1d_strip1[iclu] = -1;
206 cluster_1d_strip2[iclu] = -1;
207 for(
int ihit = 0; ihit <
MAXNOFHITS; ihit++) cluster_1d_hitindex[iclu][ihit] = -1;
217 ncluster_2d_L1_S1 = 0;
218 ncluster_2d_L2_S1 = 0;
219 ncluster_2d_L2_S2 = 0;
223 cluster_2d_t[iclu] = 0.;
224 cluster_2d_q[iclu] = 0.;
225 cluster_2d_r[iclu] = 0.;
226 cluster_2d_z[iclu] = 0.;
227 cluster_2d_phi[iclu] = 0.;
228 cluster_2d_z_cc[iclu] = 0.;
229 cluster_2d_phi_cc[iclu] = 0.;
230 cluster_2d_z_tpc[iclu] = 0.;
231 cluster_2d_phi_tpc[iclu] = 0.;
232 cluster_2d_layerid[iclu] = -1;
233 cluster_2d_sheetid[iclu] = -1;
234 cluster_2d_view[iclu] = -1;
235 cluster_2d_idx[iclu] = -1;
236 cluster_2d_idv[iclu] = -1;
237 cluster_2d_highest[iclu] = -1;
244 map_L1_S1_stripx_to_hit.clear();
245 map_L2_S1_stripx_to_hit.clear();
246 map_L2_S2_stripx_to_hit.clear();
247 map_L1_S1_stripv_to_hit.clear();
248 map_L2_S1_stripv_to_hit.clear();
249 map_L2_S2_stripv_to_hit.clear();
253bool TestClusterWithHit::selDigi(CgemDigiCol::iterator
iter,
int sel)
255 if(sel==0)
return true;
257 double time = (*iter)->getTime_ns();
258 bool timeIsGood=
true;
259 if(time<m_minDigiTime||time>m_maxDigiTime) timeIsGood=
false;
261 double Q = (*iter)->getCharge_fc();
262 bool chargeIsGood=
true;
263 if(Q<myQMin) chargeIsGood=
false;
271 if(is_xstrip ==
true) view = 0;
272 int quality = lutreader->
GetQuality(layer, sheet, view, strip);
273 bool qualityIsGood=
true;
274 if(quality!=0) qualityIsGood=
false;
276 if(sel==1)
return timeIsGood&&chargeIsGood;
277 else if(sel==-1)
return !timeIsGood&&chargeIsGood;
278 else if(sel==2)
return timeIsGood&&chargeIsGood&&qualityIsGood;
288std::map<int, std::vector < int > > * TestClusterWithHit::GetStripToHitMap(
int ilayer,
int isheet,
int iview) {
291 if(ilayer == 0 && isheet == 0)
return &map_L1_S1_stripx_to_hit;
292 else if(ilayer == 1 && isheet == 0)
return &map_L2_S2_stripx_to_hit;
293 else if(ilayer == 1 && isheet == 1)
return &map_L2_S1_stripx_to_hit;
296 if(ilayer == 0 && isheet == 0)
return &map_L1_S1_stripv_to_hit;
297 else if(ilayer == 1 && isheet == 0)
return &map_L2_S2_stripv_to_hit;
298 else if(ilayer == 1 && isheet == 1)
return &map_L2_S1_stripv_to_hit;
305 MsgStream log(
msgSvc(), name());
306 if(event%1000==0) cout <<
"->TestClusterWithHit::execute " <<
event << endl;
309 ISvcLocator* svcLocator = Gaudi::svcLocator();
310 StatusCode sc=svcLocator->service(
"EventDataSvc", m_evtSvc);
312 cout<<
"Could not accesss EventDataSvc!"<<endl;
319 SmartDataPtr<CgemDigiCol> aDigiCol(m_evtSvc,
"/Event/Digi/CgemDigiCol");
321 cout<<
"Could not retrieve CGEM digi collection"<<endl;
322 nhit = aDigiCol->size();
327 CgemDigiCol::iterator iDigiCol;
328 for(iDigiCol=aDigiCol->begin(); iDigiCol!=aDigiCol->end(); iDigiCol++)
330 const Identifier ident = (*iDigiCol)->identify();
336 if(is_xstrip ==
true) view = 0;
337 double charge = (*iDigiCol)->getCharge_fc();
338 double time = (*iDigiCol)->getTime_ns();
340 hit_strip[ihit] = strip;
341 hit_layer[ihit] = layer;
342 hit_sheet[ihit] = sheet;
343 hit_view[ihit] = view;
345 if(selDigi(iDigiCol, m_selGoodDigi)==
true) {
349 std::map<int, std::vector < int > > *map_strip_to_hit = GetStripToHitMap(layer, sheet, view);
350 std::map<int, std::vector < int > >::iterator it1 = map_strip_to_hit->find(strip);
351 if (it1 != map_strip_to_hit->end()) {
352 it1->second.push_back(ihit);
355 std::vector< int > hitlist;
356 hitlist.push_back(ihit);
357 std::pair<int, std::vector < int> > pair(strip, hitlist);
358 map_strip_to_hit->insert(pair);
378 SmartDataPtr<RecCgemClusterCol> aClusterCol(m_evtSvc,
"/Event/Recon/RecCgemClusterCol");
380 cout<<
"Could not retrieve CGEM cluster collection"<<endl;
382 int nclu = aClusterCol->size();
384 std::cout <<
"nclu " << nclu << std::endl;
393 anode_radius_L1_x = anode->
getRX();
394 anode_radius_L1_v = anode->
getRV();
397 anode_radius_L2_x = anode->
getRX();
398 anode_radius_L2_v = anode->
getRV();
401 int tmp_cluster_L1_S1 = -1;
402 int tmp_cluster_L2_S1 = -1;
403 int tmp_cluster_L2_S2 = -1;
404 double tmp_charge_L1_S1 = 0.;
405 double tmp_charge_L2_S1 = 0.;
406 double tmp_charge_L2_S2 = 0.;
409 RecCgemClusterCol::iterator iClusterCol;
410 for(iClusterCol=aClusterCol->begin(); iClusterCol!=aClusterCol->end(); iClusterCol++)
415 int flag = (*iClusterCol)->getflag();
416 int clusterid = (*iClusterCol)->getclusterid();
417 int trkid = (*iClusterCol)->getTrkId();
418 int layerid = (*iClusterCol)->getlayerid();
419 int sheetid = (*iClusterCol)->getsheetid();
420 double edep = (*iClusterCol)->getenergydeposit();
421 double phi = (*iClusterCol)->getrecphi();
422 double v = (*iClusterCol)->getrecv();
423 double z = (*iClusterCol)->getRecZ();
424 double phi_cc = (*iClusterCol)->getrecphi_CC();
425 double v_cc = (*iClusterCol)->getrecv_CC();
426 double z_cc = (*iClusterCol)->getRecZ_CC();
427 double phi_tpc = (*iClusterCol)->getrecphi_mTPC();
428 double v_tpc = (*iClusterCol)->getrecv_mTPC();
429 double z_tpc = (*iClusterCol)->getRecZ_mTPC();
445 int flagB = (*iClusterCol)->getclusterflagb();
446 int flagE = (*iClusterCol)->getclusterflage();
450 if(flag==0 || flag == 1) {
451 cluster_1d_ID[ncluster] = clusterid;
453 cluster_1d_t[ncluster] = 0;
454 cluster_1d_q[ncluster] = edep;
456 cluster_1d_layerid[ncluster] = layerid;
457 cluster_1d_sheetid[ncluster] = sheetid;
458 cluster_1d_view[ncluster] = flag;
459 cluster_1d_r[ncluster] = anode_mid_gap;
460 cluster_1d_phi[ncluster] = phi;
461 cluster_1d_phi_cc[ncluster] = phi_cc;
462 cluster_1d_phi_tpc[ncluster] = phi_tpc;
463 cluster_1d_v[ncluster] =
v;
464 cluster_1d_v_cc[ncluster] = v_cc;
465 cluster_1d_v_tpc[ncluster] = v_tpc;
466 cluster_1d_a_tpc[ncluster] = a_tpc;
467 cluster_1d_b_tpc[ncluster] = b_tpc;
469 cluster_1d_strip1[ncluster] = flagB;
470 cluster_1d_strip2[ncluster] = flagE;
471 int size = flagE - flagB + 1;
472 cluster_1d_size[ncluster] = size;
476 std::map<int, std::vector < int > > *read_map_strip_to_hit = GetStripToHitMap(layerid, sheetid, flag);
477 std::map<int, std::vector < int > >::iterator it2;
487 for(
int istrip = 0; istrip < size; istrip++) {
488 int stripid = flagB + istrip;
489 it2 = read_map_strip_to_hit->find(stripid);
490 std::vector< int > hitlist = it2->second;
491 int size_hitlist = hitlist.size();
493 cluster_1d_hitindex[ncluster][istrip] = hitlist[size_hitlist-1];
500 else if(flag==2 || flag==3) {
501 cluster_2d_ID[ncluster] = clusterid;
503 cluster_2d_t[ncluster] = 0;
504 cluster_2d_q[ncluster] = edep;
506 cluster_2d_layerid[ncluster] = layerid;
507 cluster_2d_sheetid[ncluster] = sheetid;
508 cluster_2d_view[ncluster] = flag;
509 cluster_2d_r[ncluster] = anode_mid_gap;
510 cluster_2d_z[ncluster] = z;
511 cluster_2d_z_cc[ncluster] = z_cc;
512 cluster_2d_z_tpc[ncluster] = z_tpc;
513 cluster_2d_phi[ncluster] = phi;
514 cluster_2d_phi_cc[ncluster] = phi_cc;
515 cluster_2d_phi_tpc[ncluster] = phi_tpc;
517 cluster_2d_idx[ncluster] = flagB;
518 cluster_2d_idv[ncluster] = flagE;
529 if(edep > tmp_charge_L1_S1) {
530 tmp_charge_L1_S1 = edep; tmp_cluster_L1_S1 = ncluster;
533 else if(layerid==1 && sheetid==0) {
534 if(edep > tmp_charge_L2_S1){
535 tmp_charge_L2_S1 = edep; tmp_cluster_L2_S1 = ncluster;
538 else if(layerid==1 && sheetid==1) {
539 if(edep > tmp_charge_L2_S2){
540 tmp_charge_L2_S2 = edep; tmp_cluster_L2_S2 = ncluster;
552 if(layerid == 0) ncluster_1d_L1_S1_x++;
553 else if(layerid == 1) {
554 if(sheetid == 0) ncluster_1d_L2_S1_x++;
555 else ncluster_1d_L2_S2_x++;
560 if(layerid == 0) ncluster_1d_L1_S1_v++;
561 else if(layerid == 1) {
562 if(sheetid == 0) ncluster_1d_L2_S1_v++;
563 else ncluster_1d_L2_S2_v++;
568 if(layerid == 0) ncluster_2d_L1_S1++;
569 else if(layerid == 1) {
570 if(sheetid == 0) ncluster_2d_L2_S1++;
571 else ncluster_2d_L2_S2++;
581 if(tmp_cluster_L1_S1!=-1) cluster_2d_highest[tmp_cluster_L1_S1]=1;
582 if(tmp_cluster_L2_S1!=-1) cluster_2d_highest[tmp_cluster_L2_S1]=1;
583 if(tmp_cluster_L2_S2!=-1) cluster_2d_highest[tmp_cluster_L2_S2]=1;
599 return StatusCode::SUCCESS;
603 MsgStream log(
msgSvc(),name());
604 log << MSG::INFO <<
"TestClusterWithHit finalize()" << endreq;
607 return StatusCode::SUCCESS;
**********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
static int strip(const Identifier &id)
static int sheet(const Identifier &id)
static int layer(const Identifier &id)
static bool is_xstrip(const Identifier &id)
int GetQuality(int ilayer, int isheet, int iview, int istrip)
virtual CgemGeoReadoutPlane * getReadoutPlane(int iLayer, int iSheet) const =0
TestClusterWithHit(const std::string &name, ISvcLocator *pSvcLocator)