29#include "GaudiKernel/AlgFactory.h"
30#include "GaudiKernel/DataObject.h"
31#include "GaudiKernel/IEventProcessor.h"
33#include "GaudiKernel/Incident.h"
34#include "GaudiKernel/IIncidentSvc.h"
35#include "GaudiKernel/Memory.h"
40#include "GaudiKernel/ISvcLocator.h"
41#include "GaudiKernel/IDataProviderSvc.h"
42#include "GaudiKernel/Bootstrap.h"
43#include "GaudiKernel/RegistryEntry.h"
44#include "GaudiKernel/MsgStream.h"
55#include "GaudiKernel/SmartDataPtr.h"
61 Algorithm(name,pSvcLocator){
63 declareProperty(
"Dir_file", Dir_file =
"input_file.txt");
64 declareProperty(
"TreeDigi", TreeDigi =
"t1");
65 declareProperty(
"TreeCluster", TreeCluster =
"t1");
66 declareProperty(
"ReadDigi", ReadDigi =
true);
67 declareProperty(
"ReadCluster", ReadCluster =
true);
68 declareProperty(
"DigiSheetID", DigiSheetID = 0);
69 declareProperty(
"Cut_on_tpc", Cut_on_tpc =
false);
70 declareProperty(
"ClusterSheetID", ClusterSheetID = 0);
71 declareProperty(
"ClusterRecZ", ClusterRecZ = 0);
72 declareProperty(
"R_Cluster", R_Cluster = 1.0);
73 declareProperty(
"Shift_DigitLayerID", Shift_DigitLayerID = 0);
74 declareProperty(
"Shift_DigitSheetID", Shift_DigitSheetID = 0);
75 declareProperty(
"Shift_DigitXStripID", Shift_DigitXStripID = 0);
76 declareProperty(
"Shift_DigitVStripID", Shift_DigitVStripID = 0);
77 declareProperty(
"Shift_ClusterLayerID", Shift_ClusterLayerID = 0);
78 declareProperty(
"Shift_ClusterSheetID", Shift_ClusterSheetID = 0);
79 declareProperty(
"Shift_RecPhi", Shift_RecPhi = 0);
80 declareProperty(
"Shift_RecV", Shift_RecV = 0);
81 declareProperty(
"Shift_RecZ", Shift_RecZ = 0);
82 declareProperty(
"CosmicRayDataSetID", CosmicRayDataSetID =
"CR201909");
83 declareProperty(
"runNo", m_runNo = 1);
92 MsgStream log(
msgSvc(), name());
93 log << MSG::INFO <<
"ReadCosmicRayData initialize()" << endreq;
97 TString TDir_file(Dir_file);
100 TString TTreeDigi(TreeDigi);
101 Tdigi =
new TChain(TTreeDigi);
102 TFileCollection* fc =
new TFileCollection(
"mylist",
"mylist",TDir_file);
103 Tdigi->AddFileInfoList((TCollection*)fc->GetList());
106 Tdigi->SetBranchAddress(
"Event", &m_Event_D);
107 Tdigi->SetBranchAddress(
"nGemHit", &m_nGemHit);
111 Tdigi->SetBranchAddress(
"GemHit_channel", m_channel);
112 Tdigi->SetBranchAddress(
"GemHit_ROC", m_ROC);
113 Tdigi->SetBranchAddress(
"GemHit_chip", m_chip);
114 Tdigi->SetBranchAddress(
"GemHit_FEB", m_FEB);
115 Tdigi->SetBranchAddress(
"GemHit_plane", m_plane);
116 Tdigi->SetBranchAddress(
"GemHit_sheet", m_sheet);
117 Tdigi->SetBranchAddress(
"GemHit_view", m_view);
118 Tdigi->SetBranchAddress(
"GemHit_strip", m_strip);
121 Tdigi->SetBranchAddress(
"GemHit_saturated", m_saturated);
122 Tdigi->SetBranchAddress(
"GemHit_q", m_charge);
123 Tdigi->SetBranchAddress(
"GemHit_time", m_time);
126 No_Entries_D = Tdigi->GetEntries();
127 cout<<
"total Entry is "<<No_Entries_D<<endl;
162 return StatusCode::SUCCESS;
166int ReadCosmicRayData::TranslateDigitLayerID(
int Input_LayerID)
168 int ShiftValue = Shift_DigitLayerID;
169 return Input_LayerID+ShiftValue;
172int ReadCosmicRayData::TranslateDigitSheetID(
int Input_SheetID)
174 int ShiftValue = Shift_DigitSheetID;
175 return Input_SheetID+ShiftValue;
178int ReadCosmicRayData::TranslateDigitXStripID(
int Input_StripID)
180 int ShiftValue = Shift_DigitXStripID;
181 return Input_StripID+ShiftValue;
184int ReadCosmicRayData::TranslateDigitVStripID(
int Input_StripID)
186 int ShiftValue = Shift_DigitVStripID;
187 return Input_StripID+ShiftValue;
190int ReadCosmicRayData::TranslateDigitStripID(
int Input_StripID,
int StripType)
192 int Output_StripID = -1;
193 if(StripType==0) Output_StripID = TranslateDigitXStripID(Input_StripID);
194 if(StripType==1) Output_StripID = TranslateDigitVStripID(Input_StripID);
195 return Output_StripID;
198int ReadCosmicRayData::TranslateDigitStripType(
int Input_StripType)
200 return Input_StripType;
203int ReadCosmicRayData::TranslateClusterLayerID(
int Input_LayerID)
205 int ShiftValue = Shift_ClusterLayerID;
206 return Input_LayerID+ShiftValue;
209int ReadCosmicRayData::TranslateClusterSheetID(
int Input_SheetID)
211 int ShiftValue = Shift_ClusterSheetID;
212 return Input_SheetID+ShiftValue;
215int ReadCosmicRayData::TranslateClusterFlag(
int Input_Flag)
220double ReadCosmicRayData::TranslateRecPhi(
double Input_RecPhi)
222 double ShiftValue = Shift_RecPhi;
223 return Input_RecPhi+ShiftValue;
226double ReadCosmicRayData::TranslateRecV(
double Input_RecV)
228 double ShiftValue = Shift_RecV;
229 return Input_RecV+ShiftValue;
232double ReadCosmicRayData::TranslateRecZ(
double Input_RecZ)
234 double ShiftValue = Shift_RecZ;
235 return Input_RecZ+ShiftValue;
238void ReadCosmicRayData::ReadCgemDigits()
241 Tdigi->GetEntry(Ind_Entry_D);
245void ReadCosmicRayData::ReadCgemClusters()
248 Tcluster->GetEntry(Ind_Entry_C);
252bool ReadCosmicRayData::ConvertHitToDigi(
int ihit,
unsigned int &charge_channel,
unsigned int &time_channel)
255 if(CosmicRayDataSetID ==
"CR201909") {
263 if(m_plane[ihit] == 0) m_LayerID[ihit] = 0;
264 else if(m_plane[ihit] == 1) m_LayerID[ihit] = 1;
265 else if(m_plane[ihit] == 2) m_LayerID[ihit] = 1;
267 cout<<
"ReadCosmicRayData::ConvertHitToDigi: unknown plane "<<m_plane[ihit]<<endl;
272 if(m_view[ihit] == 2) m_StripType[ihit] = 0;
273 else if(m_view[ihit] == 3) m_StripType[ihit] = 1;
275 cout<<
"ReadCosmicRayData::ConvertHitToDigi: unknown view "<<m_view[ihit]<<endl;
281 if(m_LayerID[ihit] == 0) {
283 m_StripID[ihit] = m_strip[ihit]-1;
284 if(m_StripType[ihit] == 0 && (m_StripID[ihit]<0||m_StripID[ihit]>=
CgemID::getXSTRIP_MAX(m_LayerID[ihit]))) cout<<
"ReadCosmicRayData::ConvertHitToDigi: X-strip ID out of range on layer1, sheet "<<m_SheetID[ihit]<<
" : "<<m_StripID[ihit]<<endl;
285 if(m_StripType[ihit] == 1 && (m_StripID[ihit]<0||m_StripID[ihit]>=
CgemID::getVSTRIP_MAX(m_LayerID[ihit]))) cout<<
"ReadCosmicRayData::ConvertHitToDigi: V-strip ID out of range on layer1, sheet "<<m_SheetID[ihit]<<
" : "<<m_StripID[ihit]<<endl;
287 if(m_LayerID[ihit] == 1) {
289 if(m_StripType[ihit] == 0)
303 if(m_StripID[ihit]<0||m_StripID[ihit]>=
CgemID::getXSTRIP_MAX(m_LayerID[ihit])) cout<<
"ReadCosmicRayData::ConvertHitToDigi: X-strip ID out of range on layer2, sheet "<<m_SheetID[ihit]<<
" : "<<m_StripID[ihit]<<endl;
305 else if(m_StripType[ihit] == 1)
307 if(m_strip[ihit] == 539 || m_strip[ihit] == 1617) {
308 cout<<
"ReadCosmicRayData::ConvertHitToDigi: unexpated firing strip"<<m_strip[ihit]<<endl;
311 else if(m_strip[ihit] < 539) {
321 else if(m_strip[ihit] < 1617) {
331 if(m_StripID[ihit]<0||m_StripID[ihit]>=
CgemID::getVSTRIP_MAX(m_LayerID[ihit])) cout<<
"ReadCosmicRayData::ConvertHitToDigi: V-strip ID out of range on layer2, sheet "<<m_SheetID[ihit]<<
" : "<<m_StripID[ihit]<<endl;
336 else if(CosmicRayDataSetID ==
"CR202001") {
344 if(m_plane[ihit] == 0) m_LayerID[ihit] = 0;
345 else if(m_plane[ihit] == 1) m_LayerID[ihit] = 1;
346 else if(m_plane[ihit] == 2) m_LayerID[ihit] = 1;
348 cout<<
"ReadCosmicRayData::ConvertHitToDigi: unknown plane "<<m_plane[ihit]<<endl;
353 if(m_view[ihit] == 2) m_StripType[ihit] = 0;
354 else if(m_view[ihit] == 3) m_StripType[ihit] = 1;
356 cout<<
"ReadCosmicRayData::ConvertHitToDigi: unknown view "<<m_view[ihit]<<endl;
360 if(m_strip[ihit] < 0)
return false;
365 if(m_StripType[ihit] == 0)
367 if(m_LayerID[ihit] == 0) {
371 else if(m_LayerID[ihit] == 1) {
384 if(m_StripID[ihit]<0||m_StripID[ihit]>=
CgemID::getXSTRIP_MAX(m_LayerID[ihit])) cout<<
"ReadCosmicRayData::ConvertHitToDigi: X-strip ID out of range on layer2, sheet "<<m_SheetID[ihit]<<
" : "<<m_StripID[ihit]<<endl;
386 else if(m_StripType[ihit] == 1)
388 if(m_LayerID[ihit] == 0) {
392 else if(m_LayerID[ihit] == 1) {
405 if(m_StripID[ihit]<0||m_StripID[ihit]>=
CgemID::getVSTRIP_MAX(m_LayerID[ihit])) cout<<
"ReadCosmicRayData::ConvertHitToDigi: V-strip ID out of range on layer2, sheet "<<m_SheetID[ihit]<<
" : "<<m_StripID[ihit]<<endl;
414 else if(CosmicRayDataSetID ==
"NEW202001") {
420 if(m_plane[ihit] != 0 && m_plane[ihit] != 1) {
421 cout<<
"ReadCosmicRayData::ConvertHitToDigi: unknown plane "<<m_plane[ihit]<<endl;
424 else m_LayerID[ihit] = m_plane[ihit] ;
427 if(m_view[ihit] == 2) m_StripType[ihit] = 0;
428 else if(m_view[ihit] == 3) m_StripType[ihit] = 1;
430 cout<<
"ReadCosmicRayData::ConvertHitToDigi: unknown view "<<m_view[ihit]<<endl;
434 if(m_strip[ihit] < 0)
return false;
437 m_SheetID[ihit] = m_sheet[ihit] ;
440 m_StripID[ihit] = m_strip[ihit];
444 cout<<
"ReadCosmicRayData::ConvertHitToDigi: X-strip ID out of range on layer " << m_LayerID[ihit] <<
", sheet " << m_SheetID[ihit] <<
": " << m_StripID[ihit] << endl;
447 cout<<
"ReadCosmicRayData::ConvertHitToDigi: V-strip ID out of range on layer " << m_LayerID[ihit] <<
", sheet " << m_SheetID[ihit] <<
": " << m_StripID[ihit] << endl;
454 cout <<
"ERROR : ReadCosmicRayData::ConvertGRAALToCgemBoss(), the data set " << CosmicRayDataSetID <<
" is unknown! " << endl;
459void ReadCosmicRayData::SaveCgemDigits()
462 bool printFlag=
false;
471 for(
int i=0;i<m_nGemHit;i++)
473 unsigned int charge_channel;
474 unsigned int time_channel;
475 bool is_converted = ConvertHitToDigi(i, charge_channel, time_channel);
477 cout<<
"ReadCosmicRayData::SaveCgemDigits failed to convert hit "<<i<<
" to digi in event "<<m_Event_D<<endl;
481 TranslateDigitLayerID(m_LayerID[i]),
482 TranslateDigitSheetID(m_SheetID[i]),
483 TranslateDigitStripType(m_StripType[i]),
484 TranslateDigitStripID(m_StripID[i],TranslateDigitStripType(m_StripType[i])));
511 <<
" time channel=" << time_channel
512 <<
" charge channel=" << charge_channel << endl;
518 aCgemDigiCol->push_back(aCgemDigi);
524 StatusCode scCgem = m_evtSvc->registerObject(
"/Event/Digi/CgemDigiCol", aCgemDigiCol);
525 if(scCgem!=StatusCode::SUCCESS)
527 cout <<
"ERROR : ReadCosmicRayData::SaveCgemDigits(), Could not register CGEM digi collection! " << endl;
552void ReadCosmicRayData::SaveCgemClusters()
555 bool printFlag=
false;
561 int nCluster = m_nGemCluster;
565 for(
int i=0;i<nCluster;i++)
570 aRecCgemCluster->
setlayerid(TranslateClusterLayerID(m_ClusterLayerID[i]));
572 aRecCgemCluster->
setflag(TranslateClusterFlag(m_Flag[i]));
574 if(TranslateClusterFlag(m_Flag[i])==0)
576 aRecCgemCluster->
setrecphi(m_Cluster_x[i]);
580 if(TranslateClusterFlag(m_Flag[i])==1)
582 aRecCgemCluster->
setrecv(m_Cluster_x[i]);
583 aRecCgemCluster->
setrecv_CC(m_Cluster_x_cc[i]);
586 aRecCgemCluster->
setRecZ(ClusterRecZ);
592 aRecCgemCluster->
setclusterflag(m_ClusterHitIndex[i][0],m_ClusterHitIndex[i][m_ClusternHit[i]-1]);
598 <<
" clusterlayerID=" << aRecCgemCluster->
getlayerid()
599 <<
" clustersheetID=" << aRecCgemCluster->
getsheetid()
600 <<
" flag=" << aRecCgemCluster->
getflag()
602 <<
" recphi=" << aRecCgemCluster->
getrecphi()
603 <<
" recv=" << aRecCgemCluster->
getrecv()
604 <<
" recZ=" << aRecCgemCluster->
getRecZ()
609 aRecCgemClusterCol->push_back(aRecCgemCluster);
616 StatusCode scCgem = m_evtSvc->registerObject(
"/Event/Recon/RecCgemClusterCol", aRecCgemClusterCol);
617 if(scCgem!=StatusCode::SUCCESS)
619 cout <<
"ERROR : ReadCosmicRayData:::SaveCgemClusters(), Could not register CGEM cluster collection! " << endl;
627 MsgStream log(
msgSvc(), name());
628 if(ReadDigi&&!ReadCluster) log << MSG::INFO <<
"ReadCosmicRayData execute(): "<<Ind_Entry_D+1<<
"/"<<No_Entries_D<<
" events are finished !" << endreq;
629 if(!ReadDigi&&ReadCluster) log << MSG::INFO <<
"ReadCosmicRayData execute(): "<<Ind_Entry_C+1<<
"/"<<No_Entries_C<<
" events are finished !" << endreq;
630 if(ReadDigi&&ReadCluster) log << MSG::INFO <<
"ReadCosmicRayData execute(): "<<Ind_Entry_C+1<<
"/"<<No_Entries_C<<
" events are finished !" << endreq;
634 ISvcLocator* svcLocator = Gaudi::svcLocator();
635 StatusCode sc=svcLocator->service(
"EventDataSvc", m_evtSvc);
637 cout<<
"Could not accesss EventDataSvc!"<<endl;
640 SmartDataPtr<Event::EventHeader> eventHeader(m_evtSvc,
"/Event/EventHeader");
643 StatusCode sc = m_evtSvc->registerObject(
"/Event/EventHeader",eventHeader);
645 eventHeader->setEventNumber(Ind_Entry_D);
646 eventHeader->setRunNumber( m_runNo);
652 sc = m_evtSvc->registerObject(
"/Event/Digi",aDigiEvent);
653 if(sc!=StatusCode::SUCCESS) {
654 cout<<
"Could not register DigiEvent" <<endl;
661 if(Ind_Entry_D==No_Entries_D)
663 log << MSG::INFO <<
"scheduling a event processing stop...." << endreq;
664 SmartIF<IEventProcessor> ep(serviceLocator());
665 if (ep) ep->stopRun();
672 sc = m_evtSvc->registerObject(
"/Event/Recon",aReconEvent);
673 if(sc!=StatusCode::SUCCESS) {
674 cout<<
"Could not register ReconEvent" <<endl;
680 if(Ind_Entry_C==No_Entries_C)
683 SmartIF<IEventProcessor> ep(serviceLocator());
684 if (ep) ep->stopRun();
687 return StatusCode::SUCCESS;
691 MsgStream log(
msgSvc(),name());
692 log << MSG::INFO <<
"ReadCosmicRayData finalize()" << endreq;
714 return StatusCode::SUCCESS;
ObjectVector< CgemDigi > CgemDigiCol
ObjectVector< RecCgemCluster > RecCgemClusterCol
void setCharge_fc(double q)
void setTime_ns(double t)
static int strip(const Identifier &id)
static int sheet(const Identifier &id)
static value_type getXSTRIP_MAX(unsigned int f_layer)
static int layer(const Identifier &id)
static value_type getVSTRIP_MAX(unsigned int f_layer)
static bool is_xstrip(const Identifier &id)
static Identifier strip_id(int f_layer, int f_sheet, int f_strip_type, int f_strip)
value_type get_value() const
ReadCosmicRayData(const std::string &name, ISvcLocator *pSvcLocator)
void setsheetid(int sheetid)
void setlayerid(int layerid)
void setRecZ_mTPC(double recZ)
void setrecv_CC(double recv)
double getenergydeposit(void) const
void setrecphi_CC(double recphi)
void setclusterid(int clusterid)
void setenergydeposit(double energydeposit)
double getRecZ(void) const
int getclusterid(void) const
void setrecv(double recv)
void setRecZ(double recZ)
int getlayerid(void) const
int getclusterflagb(void) const
void setrecphi_mTPC(double recphi)
void setRecZ_CC(double recZ)
double getrecphi(void) const
double getrecv(void) const
int getsheetid(void) const
void setclusterflag(int begin, int end)
void setrecv_mTPC(double recv)
void setrecphi(double recphi)
int getclusterflage(void) const