23#include "FairRootManager.h"
24#include "TClonesArray.h"
27#include "TStopwatch.h"
48 : FairTask(
"MuchFindHitsGem", 1)
49 , fDigiFile(digiFileName)
52 , fClusterSeparationTime(100.)
53 , fThresholdRatio(0.1)
63 , fClusters(new TClonesArray(
"CbmMuchCluster", 1000))
64 , fHits(new TClonesArray(
"CbmMuchPixelHit", 1000))
79 FairRootManager* ioman = FairRootManager::Instance();
102 fEvents =
dynamic_cast<TClonesArray*
>(FairRootManager::Instance()->GetObject(
"Event"));
103 if (!
fEvents)
fEvents =
dynamic_cast<TClonesArray*
>(FairRootManager::Instance()->GetObject(
"CbmEvent"));
106 LOG(info) << GetName() <<
": No event branch present.";
112 LOG(info) << GetName() <<
"TimeSlice: Event-by-event mode after Event Building selected. ";
115 ioman->Register(
"MuchCluster",
"Cluster in MUCH",
fClusters, IsOutputBranchPersistent(
"MuchCluster"));
116 ioman->Register(
"MuchPixelHit",
"Hit in MUCH",
fHits, IsOutputBranchPersistent(
"MuchPixelHit"));
120 TFile* oldFile = gFile;
121 TDirectory* oldDir = gDirectory;
124 LOG_IF(fatal, !file) <<
"Could not open file " <<
fDigiFile;
125 TObjArray* stations = file->Get<TObjArray>(
"stations");
126 LOG_IF(fatal, !stations) <<
"TObjArray stations not found in file " <<
fDigiFile;
199 LOG(info) << setw(20) << left << GetName() <<
": processing time is " << timer.RealTime()
203 <<
" clusters " <<
fClusters->GetEntriesFast() <<
" total hits " <<
fHits->GetEntriesFast();
208 Int_t nEvents =
fEvents->GetEntriesFast();
209 for (Int_t iEvent = 0; iEvent < nEvents; iEvent++) {
217 LOG(debug) << setw(20) << left
220 <<
": Time slice " <<
fNofTimeslices <<
" with " << nEvents << (nEvents == 1 ?
" event" :
" events")
221 <<
" and processing event nubmer " << iEvent <<
" digis "
227 LOG(info) << setw(20) << left << GetName() <<
": Processing Time is " << timer.RealTime() <<
": Time slice "
228 <<
fNofTimeslices <<
" with " << nEvents << (nEvents == 1 ?
" event" :
" events") <<
"s digis "
231 <<
" and event wise total "
232 <<
" clusters " <<
fClusters->GetEntriesFast() <<
" total hits " <<
fHits->GetEntriesFast();
247 TStopwatch EventTimer;
256 for (Int_t clusterIndex = 0; clusterIndex < NuOfClusterInEvent; ++clusterIndex) {
278 LOG(fatal) << GetName() <<
"::Exec: The algorithm index does not exist.";
296 LOG(debug2) <<
" Timeslice " <<
fNofTimeslices <<
" event : " <<
event->GetNumber() <<
" nDigi : " << nDigis;
297 if (nDigis < 0)
return;
299 for (Int_t iDigi = 0; iDigi < nDigis; iDigi++) {
328 for (UInt_t m = 0; m < modules.size(); m++)
329 modules[m]->ClearDigis();
333 for (Int_t iDigi = 0; iDigi < nDigis; iDigi++) {
343 Double_t time = digi->
GetTime();
385 for (UInt_t m = 0; m < modules.size(); m++) {
388 multimap<Double_t, Int_t> digis = modules[m]->GetDigis();
389 multimap<Double_t, Int_t>::iterator it, itmin, itmax;
392 vector<multimap<Double_t, Int_t>::iterator> slices;
393 Double_t tlast = -10000;
395 for (it = digis.begin(); it != digis.end(); ++it) {
396 Double_t t = it->first;
400 slices.push_back(it);
401 for (UInt_t s = 1; s < slices.size(); s++) {
403 for (it = slices[s - 1]; it != slices[s]; it++) {
404 Int_t iDigi = it->second;
419 CbmMuchPad* pad =
module->GetPad(digi->GetAddress());
425 for (UInt_t p = 0; p <
fFiredPads.size(); p++) {
460 if (digiIndex < 0)
return;
464 for (UInt_t i = 0; i < neighbours.size(); i++)
487 for (Int_t iDigi = 0; iDigi < cluster->
GetNofDigis(); iDigi++) {
488 Int_t digiIndex = cluster->
GetDigi(iDigi);
495 Int_t charge = digi->
GetAdc();
496 if (charge > maxCharge) maxCharge = charge;
503 for (Int_t iDigi = 0; iDigi < cluster->
GetNofDigis(); iDigi++) {
504 Int_t digiIndex = cluster->
GetDigi(iDigi);
511 if (digi->
GetAdc() <= threshold)
continue;
517 CbmMuchPad* pad =
module->GetPad(digi->GetAddress());
521 for (UInt_t p = 0; p <
fFiredPads.size(); p++) {
548 for (Int_t i = 0; i < nDigis; i++) {
549 Int_t iDigi = cluster->
GetDigi(i);
566 Int_t adc = digi->
GetAdc();
573 for (Int_t i = 0; i < nDigis; i++) {
576 vector<Int_t> selected_neighbours;
577 for (UInt_t ip = 0; ip < neighbours.size(); ip++) {
581 selected_neighbours.push_back(it -
fClusterPads.begin());
587 for (Int_t i = 0; i < nDigis; i++) {
589 for (UInt_t n = 0; n <
fNeighbours[i].size(); n++) {
598 for (Int_t i = 0; i < nDigis; i++) {
606 for (UInt_t p = 0; p <
fFiredPads.size(); p++) {
622 Double_t sumq = 0, sumx = 0, sumy = 0, sumdx2 = 0, sumdy2 = 0, sumdxy2 = 0,
624 Double_t q = 0,
x = 0,
y = 0, t = 0, z = 0, dx = 0, dy = 0, dxy = 0, dt = 0;
625 Double_t nX = 0, nY = 0, nZ = 0;
632 for (Int_t i = 0; i < nDigis; i++) {
633 Int_t iDigi = cluster->
GetDigi(i);
646 module = (CbmMuchModuleGem*) fGeoScheme->GetModuleByDetId(digi->GetAddress());
648 z =
module->GetPosition()[2];
658 CbmMuchPad* pad =
module->GetPad(digi->GetAddress());
663 Double_t gemDriftTimeCorrc = 15.0;
664 Double_t rpcDriftTimeCorrc = 8.33;
665 Double_t gemHitTimeError = 4.0;
666 Double_t rpcHitTimeError =
668 Double_t timeShift = 0.5;
673 t = digi->
GetTime() - gemDriftTimeCorrc + timeShift;
676 dt = gemHitTimeError;
680 t = digi->
GetTime() - rpcDriftTimeCorrc + timeShift;
681 dt = rpcHitTimeError;
684 if (tmin < 0) tmin = t;
685 if (tmin < t) tmin = t;
695 sumdx2 += q * q * dx * dx;
696 sumdy2 += q * q * dy * dy;
697 sumdxy2 += q * q * dxy * dxy;
698 sumdt2 += q * q * dt * dt;
706 dx =
sqrt(sumdx2 / 12) / sumq;
707 dy =
sqrt(sumdy2 / 12) / sumq;
708 dxy =
sqrt(sumdxy2 / 12) / sumq;
709 dt =
sqrt(sumdt2) / sumq;
710 Int_t iHit =
fHits->GetEntriesFast();
714 Double_t tX = 8.5, tY = 81.0;
729 LOG(error) <<
"Unknown detector type";
738 new ((*fHits)[iHit])
CbmMuchPixelHit(address, nX, nY, nZ, dx, dy, 0, dxy, iCluster, planeId, t, dt);
741 new ((*fHits)[iHit])
CbmMuchPixelHit(address,
x,
y, z, dx, dy, 0, dxy, iCluster, planeId, t, dt);
ClassImp(CbmConverterManager)
@ kMuch
Muon detection system.
Data container for MUCH clusters.
Class for pixel hits in MUCH detector.
friend fvec sqrt(const fvec &a)
void SetAddress(int32_t address)
int32_t GetDigi(int32_t index) const
Get digi at position index.
void AddDigis(const std::vector< int32_t > &indices)
Add array of digi to cluster.
int32_t GetNofDigis() const
Number of digis in cluster.
static Int_t GetNofDigis(ECbmModuleId systemId)
void UseMuchBeamTimeDigi(Bool_t)
Use CbmMuchBeamTimeDigi instead of CbmMuchDigi for MUCH.
InitStatus Init()
Initialisation.
const Digi * Get(Int_t index) const
Get a digi object.
static CbmDigiManager * Instance()
Static instance.
Class characterising one event by a collection of links (indices) to data objects,...
static int32_t GetModuleIndex(int32_t address)
static int32_t GetSectorIndex(int32_t address)
static int32_t GetChannelIndex(int32_t address)
static int32_t GetLayerIndex(int32_t address)
static int32_t GetLayerSideIndex(int32_t address)
static int32_t GetElementAddress(int32_t address, int32_t level)
static uint32_t GetAddress(int32_t station=0, int32_t layer=0, int32_t side=0, int32_t module=0, int32_t sector=0, int32_t channel=0)
static int32_t GetStationIndex(int32_t address)
Data container for MUCH clusters.
int32_t GetAddress() const
CbmDigiManager * fDigiManager
std::vector< Int_t > fClusterCharges
Double_t fClusterSeparationTime
virtual void Exec(Option_t *opt)
void CreateHits(CbmMuchCluster *cluster, Int_t iCluster, CbmEvent *event)
void ExecClusteringPeaks(CbmMuchCluster *cluster, Int_t iCluster, CbmEvent *event)
std::vector< Bool_t > fLocalMax
void ProcessData(CbmEvent *)
std::vector< Double_t > IgnoredAddresses
std::vector< CbmMuchPad * > fClusterPads
std::vector< CbmMuchPad * > fFiredPads
void CreateCluster(CbmMuchPad *pad)
CbmMuchGeoScheme * fGeoScheme
CbmMuchFindHitsGem(const char *digiFileName, Int_t flag)
void FindClusters(CbmEvent *)
std::vector< Int_t > fDigiIndices
virtual InitStatus Init()
std::vector< std::vector< Int_t > > fNeighbours
TClonesArray * fEvents
Interface to digi branch.
void ExecClusteringSimple(CbmMuchCluster *cluster, Int_t iCluster, CbmEvent *event)
Int_t GetLayerSideNr(Int_t detId) const
std::vector< CbmMuchModuleGem * > GetGemModules() const
void Init(TObjArray *stations, Int_t flag)
CbmMuchModule * GetModuleByDetId(Int_t detId) const
CbmMuchPad * GetPad(Int_t address)
Int_t GetDetectorType() const
void AddDigi(Double_t time, Int_t id)
void SetDigiIndex(Int_t iDigi)
std::vector< CbmMuchPad * > GetNeighbours() const
Int_t GetDigiIndex() const