-
Notifications
You must be signed in to change notification settings - Fork 3
/
SoLIDGEMTracker.cxx
354 lines (310 loc) · 12.5 KB
/
SoLIDGEMTracker.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
//c++
#include <cassert>
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
//ROOT
#include "TVector2.h"
//SoLID Tracking
#include "SoLIDGEMTracker.h"
#include "SoLIDTrackerSystem.h"
#include "SoLIDUtility.h"
#define OUTMAX 4096
ClassImp(SoLIDGEMTracker)
using namespace std;
SoLIDGEMTracker::SoLIDGEMTracker(Int_t iGEM, const char* name, const char* description,
THaDetectorBase* parent)
: THaSubDetector(name,description,parent), fTrackerID(iGEM), fNHits(0)
{
static const char* const here = "SoLIDGEMTracker";
assert( name && parent );
try {
#ifdef MCDATA
if( dynamic_cast<SoLIDTrackerSystem*>(GetMainDetector())->TestBit(SoLIDTrackerSystem::kMCData) )
fHits = new TClonesArray("SoLIDMCGEMHit", OUTMAX);
else
#endif
fHits = new TClonesArray("SoLIDGEMHit", OUTMAX);
}
catch( std::bad_alloc ) {
Error( Here(here), "Out of memory allocating hit array for tracker "
" %d. Call expert.", fTrackerID );
MakeZombie();
}
}
//_________________________________________________________________________________________
SoLIDGEMTracker::~SoLIDGEMTracker()
{
if( fIsSetup )
RemoveVariables();
DeleteContainer(fGEMChamber);
delete fHits;
}
//_________________________________________________________________________________________
void SoLIDGEMTracker::Clear( Option_t* opt)
{
if( !opt or *opt != 'I' ) {
for (Int_t i=0; i<fNChamber; ++i){
fGEMChamber[i]->Clear(opt);
}
}
fHits->Clear(opt);
fNHits = 0;
}
//_________________________________________________________________________________________
Int_t SoLIDGEMTracker::Decode( const THaEvData& evdata)
{
//cout<<"GEM tracker "<<fTrackerID<<endl;
for (Int_t i=0; i<fNChamber; i++){
fGEMChamber[i]->Decode(evdata);
}
//if (!fDoCombineHits) return 0; //fNHits = CombineChamberHits();
fNHits = 0;
for (Int_t i=0; i<fNChamber; i++){
TSeqCollection* hits = fGEMChamber[i]->GetHits();
fNHits += hits->GetEntries();
}
#ifdef MCDATA
Int_t nHit = 0;
Int_t countMC = 0;
fMCDecoder = dynamic_cast<const Podd::SimDecoder*>(&evdata);
if (dynamic_cast<SoLIDTrackerSystem*>(GetMainDetector())->TestBit(SoLIDTrackerSystem::kMCData)){
for (Int_t i = 0; i < fMCDecoder->GetNMCPoints(); i++){
Podd::MCTrackPoint* pt = fMCDecoder->GetMCPoint(i);
if (pt->fPlane != fTrackerID) continue; //not from this tracker
if (pt->fType != 0) continue;
countMC++;
Double_t mcX = (pt->fMCPoint).X();
Double_t mcY = (pt->fMCPoint).Y();
//cout<<fTrackerID<<" "<< (pt->fMCPoint).X()<<" "<<(pt->fMCPoint).Y()<<" "<<(pt->fMCPoint).Z()<<" "<<pt->fType<<endl;
//find which chamber the MC hit belongs to
Double_t phi = atan2( mcY, mcX );
Int_t chamberList[3] = {-1, -1, -1};
//for PVDIS there is no need to search for neighboring chamber
Int_t searchChamber = 3 < fNChamber ? 3 : 1 ;
for (Int_t j=0; j<fNChamber; j++){
Double_t dphi = phi - fGEMChamber[j]->GetPhiInLab();
dphi = TVector2::Phi_mpi_pi(dphi);
if ( dphi < fGEMChamber[j]->GetPhiCover()/2. && dphi > -1*fGEMChamber[j]->GetPhiCover()/2.){
for (Int_t k=0; k<3; k++){
chamberList[k] = j-1+k;
if (chamberList[k] < 0) chamberList[k] += fNChamber;
if (chamberList[k] > fNChamber-1) chamberList[k] -= fNChamber;
}
break;
}
}
SoLIDMCGEMHit *closeHit = NULL;
Double_t dist = 1.e9;
for (Int_t j=0; j<searchChamber; j++){
TSeqCollection* hits = fGEMChamber[chamberList[j]]->GetHits();
Double_t mcU, mcV;
if (!fGEMChamber[chamberList[j]]->CartesianToUV(mcX, mcY, mcU, mcV) ) continue;
for (Int_t k=0; k<hits->GetLast()+1; k++){
SoLIDMCGEMHit *thisHit = (SoLIDMCGEMHit*)hits->At(k);
if ( fabs(mcU - thisHit->GetUPos()) > 3.* fGEMChamber[chamberList[j]]->GetReadOut(0)->GetPitch() ||
fabs(mcV - thisHit->GetVPos()) > 3.* fGEMChamber[chamberList[j]]->GetReadOut(1)->GetPitch() )
continue;
Double_t thisDist = sqrt( pow(mcX - thisHit->GetX(), 2)
+ pow(mcY - thisHit->GetY(), 2) );
if ( thisDist < dist){
dist = thisDist;
closeHit = thisHit;
}
}
}
if (closeHit != NULL && closeHit->IsSignalHit()) closeHit->SetGoodMCHit(1);
if (!fDoCombineHits && closeHit != NULL){
new ( (*fHits)[nHit++]) SoLIDMCGEMHit(*closeHit);
}
}
}
if (!fDoCombineHits) assert(nHit <= countMC); //for each MC hit, there is at most one cloest hit
#endif
if (fDoCombineHits) CombineChamberHits();
return 1;
}
//_________________________________________________________________________________________
THaAnalysisObject::EStatus SoLIDGEMTracker::Init( const TDatime& date )
{
cout<<"Initializing tracker "<<fTrackerID<<endl;
EStatus status = THaAnalysisObject::Init(date);
if (status == kOK){
//fGEMChamber = new SoLIDGEMChamber *[fNChamber];
for (Int_t i=0; i<fNChamber; i++){
stringstream sn, sd;
sn <<i;
sd << "Chamber " << i << " on GEM Tracker "<<fTrackerID;
SoLIDGEMChamber *theChamber = new SoLIDGEMChamber(i, sn.str().c_str(),
sd.str().c_str(), this);
fGEMChamber.push_back(theChamber);
status = fGEMChamber[i]->Init(date);
if (status) break;
}
}
if( status ){
return fStatus = status;
}
return fStatus = kOK;
}
//_________________________________________________________________________________________
void SoLIDGEMTracker::Print( Option_t* opt ) const
{
}
//_________________________________________________________________________________________
void SoLIDGEMTracker::PrintDataBase(Int_t level) const
{
if (level>=0 && level<3){
if (level == 0){
int parent_systemID = dynamic_cast<SoLIDTrackerSystem*>(GetParent())->GetSystemID();
string out_prefix = Form("solid.trackersystem.%d.", parent_systemID);
cout<<"******parameter from database for tracker "<<fTrackerID<<" in tracker system "<<
parent_systemID<<"******"<<endl;
cout<<out_prefix<<fTrackerID<<".nchamber = "<<fNChamber<<endl;
cout<<out_prefix<<fTrackerID<<".tracker_z = "<<fTrackerZ<<endl;
cout<<"************************************************************************"<<endl;
}else if(level > 0){
level--;
for (Int_t i=0; i<fNChamber; i++){
fGEMChamber[i]->PrintDataBase(level);
}
}
}
}
//_________________________________________________________________________________________
Int_t SoLIDGEMTracker::Begin( THaRunBase* /*r*/ )
{
return 0;
}
//_________________________________________________________________________________________
Int_t SoLIDGEMTracker::End( THaRunBase* /*r*/ )
{
return 0;
}
//_________________________________________________________________________________________
Int_t SoLIDGEMTracker::ReadDatabase( const TDatime& date )
{
static const char* const here = "SoLIDGEMTracker::ReadDatabase";
fIsInit = kFALSE;
FILE* file = OpenFile( date );
if( !file ) return kFileError;
fNChamber = -1;
fTrackerZ = -100;
fDoCombineHits = -1;
const DBRequest request[] = {
{ "nchamber", &fNChamber, kInt, 0, 0 },
{ "tracker_z", &fTrackerZ, kDouble, 0, 0 },
{ "combine_hits", &fDoCombineHits, kInt, 0, 0 },
{ "kill_cross_talk", &fKillCrossTalk, kInt, 0, 0 },
{ "cross_talk_thres", &fCrossTalkThres, kDouble, 0, 0 },
{ "cross_strip_apart", &fCrossStripApart, kInt, 0, 0 },
{ 0 }
};
Int_t status = LoadDB( file, date, request, fPrefix );
assert(fNChamber > 0 && fTrackerZ != -100 && fDoCombineHits>=0);
fIsInit = kTRUE;
return kOK;
}
//__________________________________________________________________________________________
Int_t SoLIDGEMTracker::DefineVariables( EMode mode )
{
// initialize global variables
if( mode == kDefine && fIsSetup ) return kOK;
fIsSetup = ( mode == kDefine );
// Register variables in global list
Int_t ret;
if( !dynamic_cast<SoLIDTrackerSystem*>(GetMainDetector())->TestBit(SoLIDTrackerSystem::kMCData) ) {
RVarDef vars[] = {
{ "nhits", "total number of hits on this tracker", "GetNHits()" },
{ 0 },
};
ret = DefineVarsFromList( vars, mode );
}else{
#ifdef MCDATA
//Monte-Carlo hit data
RVarDef mcvars[] = {
{ "nhits", "total number of hits on this tracker", "GetNHits()" },
{ "hit2D.x", "2D hit x coordinate", "fHits.SoLIDMCGEMHit.GetX()" },
{ "hit2D.y", "2D hit y coordinate", "fHits.SoLIDMCGEMHit.GetY()" },
{ "hit2D.z", "2D hit z coordinate", "fHits.SoLIDMCGEMHit.GetZ()" },
{ "hit2D.r", "2D hit r coordinate", "fHits.SoLIDMCGEMHit.GetR()" },
{ "hit2D.qu", "2D hit charge deposition on u", "fHits.SoLIDMCGEMHit.GetQU()" },
{ "hit2D.qv", "2D hit charge deposition on v", "fHits.SoLIDMCGEMHit.GetQV()" },
{ "hit2D.upos", "2D hit position on u", "fHits.SoLIDMCGEMHit.GetUPos()" },
{ "hit2D.vpos", "2D hit position on v", "fHits.SoLIDMCGEMHit.GetVPos()" },
{ "hit2D.usize", "2D hit cluster size on u", "fHits.SoLIDMCGEMHit.GetUSize()" },
{ "hit2D.vsize", "2D hit cluster size on v", "fHits.SoLIDMCGEMHit.GetVSize()" },
{ "hit2D.umcpos", "2D hit mc position on u", "fHits.SoLIDMCGEMHit.GetUPosMC()" },
{ "hit2D.vmcpos", "2D hit mc position on v", "fHits.SoLIDMCGEMHit.GetVPosMC()" },
{ "hit2D.phi", "2D hit phi coordinate", "fHits.SoLIDMCGEMHit.GetPhi()" },
{ "hit2D.signal", "if this hit is signal", "fHits.SoLIDMCGEMHit.IsSignalHit()" },
{ "hit2D.chamber", "2D hit chamber ID", "fHits.SoLIDMCGEMHit.GetChamberID()" },
{ "hit2D.isgoodmc","if it is the closest to MC hit", "fHits.SoLIDMCGEMHit.IsGoodMCHit()" },
{ "u.occu", "occupancy pass noise cut", "GetUMeanOccu()" },
{ "v.occu", "occupancy pass noise cut", "GetVMeanOccu()" },
{ "u.rawoccu", "deconvoluted occupancy for u", "GetUMeanHitOccu()" },
{ "v.rawoccu", "deconvoluted occupancy for v", "GetVMeanHitOccu()" },
{ 0 }
};
ret = DefineVarsFromList( mcvars, mode );
#endif
}
return ret;
}
//___________________________________________________________________________________________
Int_t SoLIDGEMTracker::CombineChamberHits()
{
//collect all the MC hits info here on this GEM tracker
assert(fDoCombineHits == 1);
Int_t nTotalHits = 0;
Int_t nHit = 0;
for (Int_t i=0; i<fNChamber; i++){
TSeqCollection* hits = fGEMChamber[i]->GetHits();
nTotalHits += hits->GetEntries();
for (Int_t j=0; j<fGEMChamber[i]->GetNHits(); j++){
#ifdef MCDATA
SoLIDMCGEMHit *thisHit = (SoLIDMCGEMHit*)hits->At(j);
//if (!thisHit->IsSignalHit()) continue;
new ( (*fHits)[nHit++]) SoLIDMCGEMHit(*thisHit);
#endif
}
}
return nTotalHits;
}
//_____________________________________________________________________________________________
Double_t SoLIDGEMTracker::GetUMeanOccu()
{
Double_t meanUOccu = 0.;
for (Int_t i=0; i<fNChamber; i++){
meanUOccu += fGEMChamber[i]->GetUOccupancy();
}
return meanUOccu/(Double_t)fNChamber;
}
//_____________________________________________________________________________________________
Double_t SoLIDGEMTracker::GetVMeanOccu()
{
Double_t meanVOccu = 0.;
for (Int_t i=0; i<fNChamber; i++){
meanVOccu += fGEMChamber[i]->GetVOccupancy();
}
return meanVOccu/(Double_t)fNChamber;
}
//______________________________________________________________________________________________
Double_t SoLIDGEMTracker::GetUMeanHitOccu()
{
Double_t meanUOccu = 0.;
for (Int_t i=0; i<fNChamber; i++){
meanUOccu += fGEMChamber[i]->GetUHitOccupancy();
}
return meanUOccu/(Double_t)fNChamber;
}
//______________________________________________________________________________________________
Double_t SoLIDGEMTracker::GetVMeanHitOccu()
{
Double_t meanVOccu = 0.;
for (Int_t i=0; i<fNChamber; i++){
meanVOccu += fGEMChamber[i]->GetVHitOccupancy();
}
return meanVOccu/(Double_t)fNChamber;
}