1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 #include "AliMUONSimpleClusterServer.h"
20 #include "AliMUONConstants.h"
21 #include "AliMUONCluster.h"
22 #include "AliMUONGeometryTransformer.h"
23 #include "AliMUONPad.h"
24 #include "AliMUONVCluster.h"
25 #include "AliMUONVClusterFinder.h"
26 #include "AliMUONVClusterStore.h"
27 #include "AliMUONVDigitStore.h"
28 #include "AliMpArea.h"
29 #include "AliMpDEIterator.h"
30 #include "AliMpDEManager.h"
31 #include "AliMpExMap.h"
32 #include "AliMpSegmentation.h"
33 #include "AliMpVPadIterator.h"
34 #include "AliMpVSegmentation.h"
37 #include <Riostream.h>
38 #include <TClonesArray.h>
41 /// \class AliMUONSimpleClusterServer
43 /// Implementation of AliMUONVClusterServer interface
46 /// \author Laurent Aphecetche, Subatech
49 ClassImp(AliMUONSimpleClusterServer)
54 TString AsString(const AliMpArea& area)
56 return Form("(X,Y)=(%7.3f,%7.3f) (DX,DY)=(%7.3f,%7.3f)",
59 area.Dimensions().Y(),
60 area.Dimensions().Y());
64 //_____________________________________________________________________________
65 AliMUONSimpleClusterServer::AliMUONSimpleClusterServer(AliMUONVClusterFinder& clusterFinder,
66 const AliMUONGeometryTransformer& transformer)
67 : AliMUONVClusterServer(),
68 fClusterFinder(clusterFinder),
69 fTransformer(transformer),
71 fDEAreas(new AliMpExMap(true))
79 /// Generate the DE areas in global coordinates
81 while ( !it.IsDone() )
83 Int_t detElemId = it.CurrentDEId();
85 const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::kCath0);
89 AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
91 Double_t xl(0.0), yl(0.0), zl(0.0);
92 Double_t dx(seg->Dimensions().X());
93 Double_t dy(seg->Dimensions().Y());
95 if ( stationType == AliMp::kStation1 || stationType == AliMp::kStation2 )
97 Double_t xmin(FLT_MAX);
98 Double_t xmax(-FLT_MAX);
99 Double_t ymin(FLT_MAX);
100 Double_t ymax(-FLT_MAX);
102 for ( Int_t icathode = 0; icathode < 2; ++icathode )
104 const AliMpVSegmentation* cathode
105 = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::GetCathodType(icathode));
107 AliMpVPadIterator* it = cathode->CreateIterator();
111 while ( !it->IsDone() )
113 AliMpPad pad = it->CurrentItem();
114 AliMpArea a(pad.Position(),pad.Dimensions());
115 xmin = TMath::Min(xmin,a.LeftBorder());
116 xmax = TMath::Max(xmax,a.RightBorder());
117 ymin = TMath::Min(ymin,a.DownBorder());
118 ymax = TMath::Max(ymax,a.UpBorder());
125 xl = (xmin+xmax)/2.0;
126 yl = (ymin+ymax)/2.0;
127 dx = (xmax-xmin)/2.0;
128 dy = (ymax-ymin)/2.0;
130 fTransformer.Local2Global(detElemId,xl,yl,zl,xg,yg,zg);
134 fTransformer.Local2Global(detElemId,xl,yl,zl,xg,yg,zg);
137 fDEAreas->Add(detElemId,new AliMpArea(TVector2(xg,yg),TVector2(dx,dy)));
143 //_____________________________________________________________________________
144 AliMUONSimpleClusterServer::~AliMUONSimpleClusterServer()
152 //_____________________________________________________________________________
154 AliMUONSimpleClusterServer::Clusterize(Int_t chamberId,
155 AliMUONVClusterStore& clusterStore,
156 const AliMpArea& area)
158 /// Area is in absolute coordinate. If not valid, means clusterize all
161 /// We first find out the list of DE that have a non-zero overlap with area,
162 /// and then use the clusterfinder to find clusters in those areas (and DE).
168 Int_t nofAddedClusters(0);
169 Int_t fNCluster = clusterStore.GetSize();
171 AliDebug(1,Form("chamberId = %2d NofClusters before = %d searchArea=%s",
172 chamberId,fNCluster,AsString(area).Data()));
174 while ( !it.IsDone() )
176 Int_t detElemId = it.CurrentDEId();
178 TClonesArray* pads[2] =
180 static_cast<TClonesArray*>(fPads[0]->GetValue(detElemId)),
181 static_cast<TClonesArray*>(fPads[1]->GetValue(detElemId))
184 if ( ( pads[0] && pads[0]->GetLast()>=0 ) ||
185 ( pads[1] && pads[1]->GetLast()>=0 ) )
187 AliMpArea deArea; // area in DE-local-coordinates
190 if ( area.IsValid() )
192 ok = Overlap(detElemId,area,deArea);
197 if ( fClusterFinder.NeedSegmentation() )
199 const AliMpVSegmentation* seg[2] =
200 { AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::kCath0),
201 AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::kCath1)
203 fClusterFinder.Prepare(detElemId,pads,deArea,seg);
207 fClusterFinder.Prepare(detElemId,pads,deArea);
210 AliDebug(1,Form("Clusterizing DE %04d with %3d pads (cath0) and %3d pads (cath1)",
212 (pads[0] ? pads[0]->GetLast()+1 : 0),
213 (pads[1] ? pads[1]->GetLast()+1 : 0)));
215 AliMUONCluster* cluster;
217 while ( ( cluster = fClusterFinder.NextCluster() ) )
219 // add new cluster to the store with information to build its ID
220 // increment the number of clusters into the store
221 AliMUONVCluster* rawCluster = clusterStore.Add(AliMpDEManager::GetChamberId(detElemId), detElemId, fNCluster++);
225 // fill array of Id of digits attached to this cluster
226 Int_t nPad = cluster->Multiplicity();
227 if (nPad < 1) AliWarning("no pad attached to the cluster");
229 for (Int_t iPad=0; iPad<nPad; iPad++)
231 AliMUONPad *pad = cluster->Pad(iPad);
234 if (!pad->IsReal()) continue;
236 rawCluster->AddDigitId(pad->GetUniqueID());
239 // fill charge and other cluster informations
240 rawCluster->SetCharge(cluster->Charge());
241 rawCluster->SetChi2(cluster->Chi2());
244 fTransformer.Local2Global(detElemId,
245 cluster->Position().X(), cluster->Position().Y(),
247 rawCluster->SetXYZ(xg, yg, zg);
249 AliDebug(1,Form("Adding RawCluster detElemId %4d mult %2d charge %e (xl,yl,zl)=(%e,%e,%e) (xg,yg,zg)=(%e,%e,%e)",
250 detElemId,rawCluster->GetNDigits(),rawCluster->GetCharge(),
251 cluster->Position().X(),cluster->Position().Y(),0.0,
259 AliDebug(1,Form("chamberId = %2d NofClusters after = %d",chamberId,fNCluster));
261 return nofAddedClusters;
264 //_____________________________________________________________________________
266 AliMUONSimpleClusterServer::Global2Local(Int_t detElemId, const AliMpArea& globalArea,
267 AliMpArea& localArea) const
269 /// Convert a global area in local area for a given DE
273 Double_t zg = AliMUONConstants::DefaultChamberZ(AliMpDEManager::GetChamberId(detElemId));
275 fTransformer.Global2Local(detElemId,
276 globalArea.Position().X(),globalArea.Position().Y(),zg,
279 localArea = AliMpArea(TVector2(xl,yl), globalArea.Dimensions());
282 //_____________________________________________________________________________
284 AliMUONSimpleClusterServer::Overlap(Int_t detElemId,
285 const AliMpArea& area,
286 AliMpArea& deArea) const
288 /// Check whether (global) area overlaps with the given DE.
289 /// If it is, set deArea to the overlap region and convert it
290 /// in the local coordinate system of that DE.
292 Bool_t overlap(kFALSE);
294 AliMpArea* globalDEArea = static_cast<AliMpArea*>(fDEAreas->GetValue(detElemId));
296 AliMpArea overlapArea;
298 if ( area.Overlap(*globalDEArea) )
300 overlapArea = area.Intersect(*globalDEArea);
301 Global2Local(detElemId,overlapArea,deArea);
306 deArea = AliMpArea();
309 AliDebug(1,Form("DE %04d area %s globalDEArea %s overlapArea %s deArea %s overlap=%d",
311 AsString(area).Data(),
312 AsString(*globalDEArea).Data(),
313 AsString(overlapArea).Data(),
314 AsString(deArea).Data(),
320 //_____________________________________________________________________________
322 AliMUONSimpleClusterServer::PadArray(Int_t detElemId, Int_t cathode) const
324 /// Return array for given cathode of given DE
326 return static_cast<TClonesArray*>(fPads[cathode]->GetValue(detElemId));
329 //_____________________________________________________________________________
331 AliMUONSimpleClusterServer::UseDigitStore(const AliMUONVDigitStore& digitStore)
333 /// Convert digitStore into two arrays of AliMUONPads
338 fPads[0] = new AliMpExMap(true);
339 fPads[1] = new AliMpExMap(true);
341 TIter next(digitStore.CreateIterator());
344 while ( ( d = static_cast<AliMUONVDigit*>(next()) ) )
346 if ( ! d->Charge() > 0 ) continue; // skip void digits.
347 Int_t ix = d->PadX();
348 Int_t iy = d->PadY();
349 Int_t cathode = d->Cathode();
350 Int_t detElemId = d->DetElemId();
351 const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->
352 GetMpSegmentation(detElemId,AliMp::GetCathodType(cathode));
353 AliMpPad pad = seg->PadByIndices(AliMpIntPair(ix,iy));
355 TClonesArray* padArray = PadArray(detElemId,cathode);
358 padArray = new TClonesArray("AliMUONPad",100);
359 fPads[cathode]->Add(detElemId,padArray);
362 AliMUONPad mpad(detElemId,cathode,
363 ix,iy,pad.Position().X(),pad.Position().Y(),
364 pad.Dimensions().X(),pad.Dimensions().Y(),
366 if ( d->IsSaturated() ) mpad.SetSaturated(kTRUE);
367 mpad.SetUniqueID(d->GetUniqueID());
368 new ((*padArray)[padArray->GetLast()+1]) AliMUONPad(mpad);
372 //_____________________________________________________________________________
374 AliMUONSimpleClusterServer::Print(Option_t*) const
376 /// Printout for debug only
382 while ( !it.IsDone() )
384 Int_t detElemId = it.CurrentDEId();
386 // printout the number of pads / de, and number of used pads / de
388 if ( ( PadArray(detElemId,0) && PadArray(detElemId,0)->GetLast() >= 0 ) ||
389 ( PadArray(detElemId,1) && PadArray(detElemId,1)->GetLast() >= 0 ) )
391 cout << Form("---- DE %04d",detElemId) << endl;
393 for ( Int_t cathode = 0; cathode < 2; ++cathode )
395 cout << Form(" -- Cathode %1d",cathode) << endl;
397 TClonesArray* padArray = PadArray(detElemId,cathode);
401 cout << "no pad array" << endl;
403 else if ( padArray->GetLast() < 0 )
405 cout << "no pads" << endl;
409 TIter next(padArray);
411 while ( ( pad = static_cast<AliMUONPad*>(next()) ) )