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"
46#include "CgemRawEvent/CgemDigi.h"
47#include "CgemRecEvent/RecCgemCluster.h"
49#include "Identifier/CgemID.h"
51#include "RawEvent/RawDataUtil.h"
52#include "RawEvent/DigiEvent.h"
53#include "ReconEvent/ReconEvent.h"
54#include "EventModel/EventHeader.h"
55#include "GaudiKernel/SmartDataPtr.h"
57#include "ReadCosmicRayData/ReadCosmicRayData.h"
61 Algorithm(name,pSvcLocator){
63 declareProperty(
"Dir_file", Dir_file =
"Cosmic_data_01.root");
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);
98 f =
new TFile(TDir_file);
101 TString TTreeDigi(TreeDigi);
102 Tdigi = (TTree*)f->Get(TTreeDigi);
105 Tdigi->SetBranchAddress(
"Event", &m_Event_D);
106 Tdigi->SetBranchAddress(
"nGemHit", &m_nGemHit);
110 Tdigi->SetBranchAddress(
"GemHit_channel", m_channel);
111 Tdigi->SetBranchAddress(
"GemHit_ROC", m_ROC);
112 Tdigi->SetBranchAddress(
"GemHit_chip", m_chip);
113 Tdigi->SetBranchAddress(
"GemHit_FEB", m_FEB);
114 Tdigi->SetBranchAddress(
"GemHit_plane", m_plane);
115 Tdigi->SetBranchAddress(
"GemHit_view", m_view);
116 Tdigi->SetBranchAddress(
"GemHit_strip", m_strip);
119 Tdigi->SetBranchAddress(
"GemHit_saturated", m_saturated);
120 Tdigi->SetBranchAddress(
"GemHit_q", m_charge);
121 Tdigi->SetBranchAddress(
"GemHit_time", m_time);
124 No_Entries_D = Tdigi->GetEntries();
159 return StatusCode::SUCCESS;
163int ReadCosmicRayData::TranslateDigitLayerID(
int Input_LayerID)
165 int ShiftValue = Shift_DigitLayerID;
166 return Input_LayerID+ShiftValue;
169int ReadCosmicRayData::TranslateDigitSheetID(
int Input_SheetID)
171 int ShiftValue = Shift_DigitSheetID;
172 return Input_SheetID+ShiftValue;
175int ReadCosmicRayData::TranslateDigitXStripID(
int Input_StripID)
177 int ShiftValue = Shift_DigitXStripID;
178 return Input_StripID+ShiftValue;
181int ReadCosmicRayData::TranslateDigitVStripID(
int Input_StripID)
183 int ShiftValue = Shift_DigitVStripID;
184 return Input_StripID+ShiftValue;
187int ReadCosmicRayData::TranslateDigitStripID(
int Input_StripID,
int StripType)
189 int Output_StripID = -1;
190 if(StripType==0) Output_StripID = TranslateDigitXStripID(Input_StripID);
191 if(StripType==1) Output_StripID = TranslateDigitVStripID(Input_StripID);
192 return Output_StripID;
195int ReadCosmicRayData::TranslateDigitStripType(
int Input_StripType)
197 return Input_StripType;
200int ReadCosmicRayData::TranslateClusterLayerID(
int Input_LayerID)
202 int ShiftValue = Shift_ClusterLayerID;
203 return Input_LayerID+ShiftValue;
206int ReadCosmicRayData::TranslateClusterSheetID(
int Input_SheetID)
208 int ShiftValue = Shift_ClusterSheetID;
209 return Input_SheetID+ShiftValue;
212int ReadCosmicRayData::TranslateClusterFlag(
int Input_Flag)
217double ReadCosmicRayData::TranslateRecPhi(
double Input_RecPhi)
219 double ShiftValue = Shift_RecPhi;
220 return Input_RecPhi+ShiftValue;
223double ReadCosmicRayData::TranslateRecV(
double Input_RecV)
225 double ShiftValue = Shift_RecV;
226 return Input_RecV+ShiftValue;
229double ReadCosmicRayData::TranslateRecZ(
double Input_RecZ)
231 double ShiftValue = Shift_RecZ;
232 return Input_RecZ+ShiftValue;
235void ReadCosmicRayData::ReadCgemDigits()
238 Tdigi->GetEntry(Ind_Entry_D);
242void ReadCosmicRayData::ReadCgemClusters()
245 Tcluster->GetEntry(Ind_Entry_C);
249bool ReadCosmicRayData::ConvertHitToDigi(
int ihit,
unsigned int &charge_channel,
unsigned int &time_channel)
252 if(CosmicRayDataSetID ==
"CR201909") {
260 if(m_plane[ihit] == 0) m_LayerID[ihit] = 0;
261 else if(m_plane[ihit] == 1) m_LayerID[ihit] = 1;
262 else if(m_plane[ihit] == 2) m_LayerID[ihit] = 1;
264 cout<<
"ReadCosmicRayData::ConvertHitToDigi: unknown plane "<<m_plane[ihit]<<endl;
269 if(m_view[ihit] == 2) m_StripType[ihit] = 0;
270 else if(m_view[ihit] == 3) m_StripType[ihit] = 1;
272 cout<<
"ReadCosmicRayData::ConvertHitToDigi: unknown view "<<m_view[ihit]<<endl;
278 if(m_LayerID[ihit] == 0) {
280 m_StripID[ihit] = m_strip[ihit]-1;
281 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;
282 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;
284 if(m_LayerID[ihit] == 1) {
286 if(m_StripType[ihit] == 0)
300 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;
302 else if(m_StripType[ihit] == 1)
304 if(m_strip[ihit] == 539 || m_strip[ihit] == 1617)
return false;
305 else if(m_strip[ihit] < 539) {
315 else if(m_strip[ihit] < 1617) {
325 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 cout <<
"ERROR : ReadCosmicRayData::ConvertGRAALToCgemBoss(), the data set " << CosmicRayDataSetID <<
" is unknown! " << endl;
341void ReadCosmicRayData::SaveCgemDigits()
344 bool printFlag=
false;
353 for(
int i=0;i<m_nGemHit;i++)
355 unsigned int charge_channel;
356 unsigned int time_channel;
357 bool is_converted = ConvertHitToDigi(i, charge_channel, time_channel);
359 cout<<
"ReadCosmicRayData::SaveCgemDigits failed to convert hit "<<i<<
" to digi in event "<<m_Event_D<<endl;
363 TranslateDigitLayerID(m_LayerID[i]),
364 TranslateDigitSheetID(m_SheetID[i]),
365 TranslateDigitStripType(m_StripType[i]),
366 TranslateDigitStripID(m_StripID[i],TranslateDigitStripType(m_StripType[i])));
393 <<
" time channel=" << time_channel
394 <<
" charge channel=" << charge_channel << endl;
400 aCgemDigiCol->push_back(aCgemDigi);
406 StatusCode scCgem = m_evtSvc->registerObject(
"/Event/Digi/CgemDigiCol", aCgemDigiCol);
407 if(scCgem!=StatusCode::SUCCESS)
409 cout <<
"ERROR : ReadCosmicRayData::SaveCgemDigits(), Could not register CGEM digi collection! " << endl;
434void ReadCosmicRayData::SaveCgemClusters()
437 bool printFlag=
false;
443 int nCluster = m_nGemCluster;
447 for(
int i=0;i<nCluster;i++)
452 aRecCgemCluster->
setlayerid(TranslateClusterLayerID(m_ClusterLayerID[i]));
454 aRecCgemCluster->
setflag(TranslateClusterFlag(m_Flag[i]));
456 if(TranslateClusterFlag(m_Flag[i])==0)
458 aRecCgemCluster->
setrecphi(m_Cluster_x[i]);
462 if(TranslateClusterFlag(m_Flag[i])==1)
464 aRecCgemCluster->
setrecv(m_Cluster_x[i]);
465 aRecCgemCluster->
setrecv_CC(m_Cluster_x_cc[i]);
468 aRecCgemCluster->
setRecZ(ClusterRecZ);
474 aRecCgemCluster->
setclusterflag(m_ClusterHitIndex[i][0],m_ClusterHitIndex[i][m_ClusternHit[i]-1]);
480 <<
" clusterlayerID=" << aRecCgemCluster->
getlayerid()
481 <<
" clustersheetID=" << aRecCgemCluster->
getsheetid()
482 <<
" flag=" << aRecCgemCluster->
getflag()
484 <<
" recphi=" << aRecCgemCluster->
getrecphi()
485 <<
" recv=" << aRecCgemCluster->
getrecv()
486 <<
" recZ=" << aRecCgemCluster->
getRecZ()
491 aRecCgemClusterCol->push_back(aRecCgemCluster);
498 StatusCode scCgem = m_evtSvc->registerObject(
"/Event/Recon/RecCgemClusterCol", aRecCgemClusterCol);
499 if(scCgem!=StatusCode::SUCCESS)
501 cout <<
"ERROR : ReadCosmicRayData:::SaveCgemClusters(), Could not register CGEM cluster collection! " << endl;
509 MsgStream log(
msgSvc(), name());
510 if(ReadDigi&&!ReadCluster) log << MSG::INFO <<
"ReadCosmicRayData execute(): "<<Ind_Entry_D+1<<
"/"<<No_Entries_D<<
" events are finished !" << endreq;
511 if(!ReadDigi&&ReadCluster) log << MSG::INFO <<
"ReadCosmicRayData execute(): "<<Ind_Entry_C+1<<
"/"<<No_Entries_C<<
" events are finished !" << endreq;
512 if(ReadDigi&&ReadCluster) log << MSG::INFO <<
"ReadCosmicRayData execute(): "<<Ind_Entry_C+1<<
"/"<<No_Entries_C<<
" events are finished !" << endreq;
516 ISvcLocator* svcLocator = Gaudi::svcLocator();
517 StatusCode sc=svcLocator->service(
"EventDataSvc", m_evtSvc);
519 cout<<
"Could not accesss EventDataSvc!"<<endl;
522 SmartDataPtr<Event::EventHeader> eventHeader(m_evtSvc,
"/Event/EventHeader");
525 StatusCode sc = m_evtSvc->registerObject(
"/Event/EventHeader",eventHeader);
534 sc = m_evtSvc->registerObject(
"/Event/Digi",aDigiEvent);
535 if(sc!=StatusCode::SUCCESS) {
536 cout<<
"Could not register DigiEvent" <<endl;
543 if(Ind_Entry_D==No_Entries_D)
545 log << MSG::INFO <<
"scheduling a event processing stop...." << endreq;
546 SmartIF<IEventProcessor> ep(serviceLocator());
547 if (ep) ep->stopRun();
554 sc = m_evtSvc->registerObject(
"/Event/Recon",aReconEvent);
555 if(sc!=StatusCode::SUCCESS) {
556 cout<<
"Could not register ReconEvent" <<endl;
562 if(Ind_Entry_C==No_Entries_C)
565 SmartIF<IEventProcessor> ep(serviceLocator());
566 if (ep) ep->stopRun();
569 return StatusCode::SUCCESS;
573 MsgStream log(
msgSvc(),name());
574 log << MSG::INFO <<
"ReadCosmicRayData finalize()" << endreq;
596 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