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 "AliCodeTimer.h"
22 #include "AliMUONCluster.h"
23 #include "AliMUONConstants.h"
24 #include "AliMUONGeometryTransformer.h"
25 #include "AliMUONPad.h"
26 #include "AliMUONTriggerTrackToTrackerClusters.h"
27 #include "AliMUONVCluster.h"
28 #include "AliMUONVClusterFinder.h"
29 #include "AliMUONVClusterStore.h"
30 #include "AliMUONVDigitStore.h"
31 #include "AliMUONRecoParam.h"
32 #include "AliMpArea.h"
33 #include "AliMpDEIterator.h"
34 #include "AliMpDEManager.h"
35 #include "AliMpExMap.h"
37 #include "AliMpSegmentation.h"
38 #include "AliMpVSegmentation.h"
39 #include <Riostream.h>
40 #include <TClonesArray.h>
44 /// \class AliMUONSimpleClusterServer
46 /// Implementation of AliMUONVClusterServer interface
49 /// \author Laurent Aphecetche, Subatech
52 ClassImp(AliMUONSimpleClusterServer)
57 TString AsString(const AliMpArea& area)
59 return Form("(X,Y)=(%7.3f,%7.3f) (DX,DY)=(%7.3f,%7.3f)",
62 area.Dimensions().Y(),
63 area.Dimensions().Y());
67 //_____________________________________________________________________________
68 AliMUONSimpleClusterServer::AliMUONSimpleClusterServer(AliMUONVClusterFinder* clusterFinder,
69 const AliMUONGeometryTransformer& transformer)
70 : AliMUONVClusterServer(),
71 fClusterFinder(clusterFinder),
72 fTransformer(transformer),
74 fTriggerTrackStore(0x0),
78 /// Note that we take ownership of the clusterFinder
80 fPads[0] = new AliMpExMap;
81 fPads[1] = new AliMpExMap;
85 //_____________________________________________________________________________
86 AliMUONSimpleClusterServer::~AliMUONSimpleClusterServer()
89 delete fClusterFinder;
95 //_____________________________________________________________________________
97 AliMUONSimpleClusterServer::Clusterize(Int_t chamberId,
98 AliMUONVClusterStore& clusterStore,
99 const AliMpArea& area,
100 const AliMUONRecoParam* recoParam)
102 /// Area is in absolute coordinate. If not valid, means clusterize all
105 /// We first find out the list of DE that have a non-zero overlap with area,
106 /// and then use the clusterfinder to find clusters in those areas (and DE).
108 AliCodeTimerAuto(Form("Chamber %d",chamberId));
110 if ( fTriggerTrackStore && chamberId >= 6 )
112 return fBypass->GenerateClusters(chamberId,clusterStore);
116 AliError("Reconstruction parameters are missing: unable to clusterize");
124 Int_t nofAddedClusters(0);
125 Int_t fNCluster = clusterStore.GetSize();
127 AliDebug(1,Form("chamberId = %2d NofClusters before = %d searchArea=%s",
128 chamberId,fNCluster,AsString(area).Data()));
130 while ( !it.IsDone() )
132 Int_t detElemId = it.CurrentDEId();
134 TClonesArray* pads[2] =
136 static_cast<TClonesArray*>(fPads[0]->GetValue(detElemId)),
137 static_cast<TClonesArray*>(fPads[1]->GetValue(detElemId))
140 if ( ( pads[0] && pads[0]->GetLast()>=0 ) ||
141 ( pads[1] && pads[1]->GetLast()>=0 ) )
143 AliMpArea deArea; // area in DE-local-coordinates
146 if ( area.IsValid() )
148 ok = Overlap(detElemId,area,deArea);
153 if ( fClusterFinder->NeedSegmentation() )
155 const AliMpVSegmentation* seg[2] =
156 { AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::kCath0),
157 AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::kCath1)
159 fClusterFinder->Prepare(detElemId,pads,deArea,seg);
163 fClusterFinder->Prepare(detElemId,pads,deArea);
166 AliDebug(1,Form("Clusterizing DE %04d with %3d pads (cath0) and %3d pads (cath1)",
168 (pads[0] ? pads[0]->GetLast()+1 : 0),
169 (pads[1] ? pads[1]->GetLast()+1 : 0)));
171 AliMUONCluster* cluster;
173 while ( ( cluster = fClusterFinder->NextCluster() ) )
175 // add new cluster to the store with information to build its ID
176 // increment the number of clusters into the store
177 AliMUONVCluster* rawCluster = clusterStore.Add(chamberId, detElemId, fNCluster++);
181 // fill array of Id of digits attached to this cluster
182 Int_t nPad = cluster->Multiplicity();
183 if (nPad < 1) AliWarning("no pad attached to the cluster");
185 for (Int_t iPad=0; iPad<nPad; iPad++)
187 AliMUONPad *pad = cluster->Pad(iPad);
190 if (!pad->IsReal()) continue;
192 rawCluster->AddDigitId(pad->GetUniqueID());
195 // fill charge and other cluster informations
196 rawCluster->SetCharge(cluster->Charge());
197 rawCluster->SetChi2(cluster->Chi2());
200 fTransformer.Local2Global(detElemId,
201 cluster->Position().X(), cluster->Position().Y(),
203 rawCluster->SetXYZ(xg, yg, zg);
204 rawCluster->SetErrXY(recoParam->GetDefaultNonBendingReso(chamberId),recoParam->GetDefaultBendingReso(chamberId));
206 AliDebug(1,Form("Adding RawCluster detElemId %4d mult %2d charge %e (xl,yl,zl)=(%e,%e,%e) (xg,yg,zg)=(%e,%e,%e)",
207 detElemId,rawCluster->GetNDigits(),rawCluster->GetCharge(),
208 cluster->Position().X(),cluster->Position().Y(),0.0,
216 AliDebug(1,Form("chamberId = %2d NofClusters after = %d",chamberId,fNCluster));
218 return nofAddedClusters;
222 //_____________________________________________________________________________
224 AliMUONSimpleClusterServer::Global2Local(Int_t detElemId, const AliMpArea& globalArea,
225 AliMpArea& localArea) const
227 /// Convert a global area in local area for a given DE
231 Double_t zg = AliMUONConstants::DefaultChamberZ(AliMpDEManager::GetChamberId(detElemId));
233 fTransformer.Global2Local(detElemId,
234 globalArea.Position().X(),globalArea.Position().Y(),zg,
237 localArea = AliMpArea(TVector2(xl,yl), globalArea.Dimensions());
240 //_____________________________________________________________________________
242 AliMUONSimpleClusterServer::Overlap(Int_t detElemId,
243 const AliMpArea& area,
244 AliMpArea& deArea) const
246 /// Check whether (global) area overlaps with the given DE.
247 /// If it is, set deArea to the overlap region and convert it
248 /// in the local coordinate system of that DE.
250 Bool_t overlap(kFALSE);
252 AliMpArea* globalDEArea = fTransformer.GetDEArea(detElemId);
254 if (!globalDEArea) return kFALSE;
256 AliMpArea overlapArea;
258 if ( area.Overlap(*globalDEArea) )
260 overlapArea = area.Intersect(*globalDEArea);
261 Global2Local(detElemId,overlapArea,deArea);
266 deArea = AliMpArea();
269 AliDebug(1,Form("DE %04d area %s globalDEArea %s overlapArea %s deArea %s overlap=%d",
271 AsString(area).Data(),
272 AsString(*globalDEArea).Data(),
273 AsString(overlapArea).Data(),
274 AsString(deArea).Data(),
280 //_____________________________________________________________________________
282 AliMUONSimpleClusterServer::PadArray(Int_t detElemId, Int_t cathode) const
284 /// Return array for given cathode of given DE
286 return static_cast<TClonesArray*>(fPads[cathode]->GetValue(detElemId));
289 //_____________________________________________________________________________
291 AliMUONSimpleClusterServer::UseTriggerTrackStore(AliMUONVTriggerTrackStore* trackStore)
293 /// Tells us to use trigger track store, and thus to bypass St45 clusters
294 fTriggerTrackStore = trackStore; // not owner
296 fBypass = new AliMUONTriggerTrackToTrackerClusters(fTransformer,fTriggerTrackStore);
300 //_____________________________________________________________________________
302 AliMUONSimpleClusterServer::UseDigits(TIter& next)
304 /// Convert digitStore into two arrays of AliMUONPads
310 while ( ( d = static_cast<AliMUONVDigit*>(next()) ) )
312 if ( ! d->Charge() > 0 ) continue; // skip void digits.
313 Int_t ix = d->PadX();
314 Int_t iy = d->PadY();
315 Int_t cathode = d->Cathode();
316 Int_t detElemId = d->DetElemId();
317 const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->
318 GetMpSegmentation(detElemId,AliMp::GetCathodType(cathode));
319 AliMpPad pad = seg->PadByIndices(AliMpIntPair(ix,iy));
321 TClonesArray* padArray = PadArray(detElemId,cathode);
324 padArray = new TClonesArray("AliMUONPad",100);
325 fPads[cathode]->Add(detElemId,padArray);
328 AliMUONPad mpad(detElemId,cathode,
329 ix,iy,pad.Position().X(),pad.Position().Y(),
330 pad.Dimensions().X(),pad.Dimensions().Y(),
332 if ( d->IsSaturated() ) mpad.SetSaturated(kTRUE);
333 mpad.SetUniqueID(d->GetUniqueID());
334 new ((*padArray)[padArray->GetLast()+1]) AliMUONPad(mpad);
338 //_____________________________________________________________________________
340 AliMUONSimpleClusterServer::Print(Option_t*) const
342 /// Printout for debug only
348 while ( !it.IsDone() )
350 Int_t detElemId = it.CurrentDEId();
352 // printout the number of pads / de, and number of used pads / de
354 if ( ( PadArray(detElemId,0) && PadArray(detElemId,0)->GetLast() >= 0 ) ||
355 ( PadArray(detElemId,1) && PadArray(detElemId,1)->GetLast() >= 0 ) )
357 cout << Form("---- DE %04d",detElemId) << endl;
359 for ( Int_t cathode = 0; cathode < 2; ++cathode )
361 cout << Form(" -- Cathode %1d",cathode) << endl;
363 TClonesArray* padArray = PadArray(detElemId,cathode);
367 cout << "no pad array" << endl;
369 else if ( padArray->GetLast() < 0 )
371 cout << "no pads" << endl;
375 TIter next(padArray);
377 while ( ( pad = static_cast<AliMUONPad*>(next()) ) )