]>
Commit | Line | Data |
---|---|---|
7a086578 | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
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 | **************************************************************************/ | |
15 | ||
16 | // $Id$ | |
17 | ||
18 | /////////////////////////////////////////////////////////////////////////// | |
19 | // Class AliDevice | |
20 | // Signal (Hit) handling of a generic device. | |
21 | // Basically this class provides a user interface to group and handle | |
22 | // various instances of AliSignal objects, called generically "hits". | |
23 | // An AliDevice object itself has (in addition to hit storage) also the | |
24 | // complete functionality of the class AliSignal. | |
25 | // | |
26 | // Example : | |
27 | // ========= | |
28 | // | |
29 | // AliDevice m; | |
9e6577df | 30 | // // Set user defined status word to indicate e.g. readout electronics version |
31 | // m.SetStatus(100201); | |
7a086578 | 32 | // m.SetHitCopy(1); |
33 | // m.SetName("OM123"); | |
34 | // | |
35 | // Float_t pos[3]={1,2,3}; | |
36 | // m.SetPosition(pos,"car"); | |
37 | // | |
38 | // AliSignal s; | |
39 | // | |
40 | // s.Reset(1); | |
41 | // s.SetName("OM123 Hit 1"); | |
42 | // s.SetSlotName("ADC"); | |
43 | // s.SetSignal(10); | |
44 | // s.SetSlotName("LE",2); | |
45 | // s.SetSignal(-100,2); | |
46 | // s.SetSlotName("TOT",3); | |
47 | // s.SetSignal(-1000,3); | |
48 | // m.AddHit(s); | |
49 | // | |
50 | // s.Reset(1); | |
51 | // s.SetName("OM123 Hit 2"); | |
52 | // s.SetSlotName("ADC"); | |
53 | // s.SetSignal(11); | |
54 | // s.SetSlotName("LE",2); | |
55 | // s.SetSignal(-101,2); | |
56 | // s.SetSlotName("TOT",3); | |
57 | // s.SetSignal(1001,3); | |
58 | // m.AddHit(s); | |
59 | // | |
60 | // s.Reset(1); | |
61 | // s.SetName("OM123 Hit 3"); | |
62 | // s.SetSlotName("ADC"); | |
63 | // s.SetSignal(12); | |
64 | // s.SetSlotName("LE",2); | |
65 | // s.SetSignal(-102,2); | |
66 | // s.SetSlotName("TOT",3); | |
67 | // s.SetSignal(-1002,3); | |
68 | // m.AddHit(s); | |
69 | // | |
7b825f44 | 70 | // TObjArray* ordered=m.SortHits("TOT"); |
71 | // nhits=ordered->GetEntries(); | |
7a086578 | 72 | // for (Int_t i=0; i<nhits; i++) |
73 | // { | |
7b825f44 | 74 | // AliSignal* sx=(AliSignal*)ordered->At(i); |
7a086578 | 75 | // if (sx) sx->Data(); |
76 | // } | |
77 | // | |
78 | //--- Author: Nick van Eijndhoven 23-jun-2004 Utrecht University | |
79 | //- Modified: NvE $Date$ Utrecht University | |
80 | /////////////////////////////////////////////////////////////////////////// | |
81 | ||
82 | #include "AliDevice.h" | |
83 | #include "Riostream.h" | |
84 | ||
85 | ClassImp(AliDevice) // Class implementation to enable ROOT I/O | |
86 | ||
87 | AliDevice::AliDevice() : AliSignal() | |
88 | { | |
89 | // Default constructor. | |
9e6577df | 90 | // The user definable status word is set to zero. |
7b825f44 | 91 | // By default private copies of the recorded hits will be made. |
92 | // This implies that by default the device will own the registered hits. | |
93 | // See the SetHitCopy() memberfunction for further details. | |
9e6577df | 94 | fStatus=0; |
7b825f44 | 95 | fHitCopy=1; |
7a086578 | 96 | fHits=0; |
7b825f44 | 97 | fOrdered=0; |
965bd237 | 98 | fMarkers=0; |
7a086578 | 99 | } |
100 | /////////////////////////////////////////////////////////////////////////// | |
101 | AliDevice::~AliDevice() | |
102 | { | |
103 | // Default destructor. | |
b055c99d | 104 | |
105 | // Remove backward links to this device from the hits | |
106 | // which were not owned by it. | |
107 | if (!fHitCopy) | |
108 | { | |
109 | for (Int_t ih=1; ih<=GetNhits(); ih++) | |
110 | { | |
111 | AliSignal* sx=GetHit(ih); | |
112 | if (sx) sx->ResetLinks(this); | |
113 | } | |
114 | } | |
115 | ||
7a086578 | 116 | if (fHits) |
117 | { | |
118 | delete fHits; | |
119 | fHits=0; | |
120 | } | |
7b825f44 | 121 | |
122 | if (fOrdered) | |
123 | { | |
124 | delete fOrdered; | |
125 | fOrdered=0; | |
126 | } | |
965bd237 | 127 | |
128 | if (fMarkers) | |
129 | { | |
130 | delete fMarkers; | |
131 | fMarkers=0; | |
132 | } | |
7a086578 | 133 | } |
134 | /////////////////////////////////////////////////////////////////////////// | |
135 | AliDevice::AliDevice(const AliDevice& dev) : AliSignal(dev) | |
136 | { | |
137 | // Copy constructor. | |
7b825f44 | 138 | |
139 | fHits=0; | |
140 | fOrdered=0; | |
965bd237 | 141 | fMarkers=0; |
7b825f44 | 142 | |
9e6577df | 143 | fStatus=dev.GetStatus(); |
7a086578 | 144 | fHitCopy=dev.GetHitCopy(); |
7b825f44 | 145 | |
7a086578 | 146 | Int_t nhits=dev.GetNhits(); |
147 | if (nhits) | |
148 | { | |
149 | fHits=new TObjArray(nhits); | |
150 | if (fHitCopy) fHits->SetOwner(); | |
151 | for (Int_t ih=1; ih<=nhits; ih++) | |
152 | { | |
153 | AliSignal* sx=dev.GetHit(ih); | |
154 | if (fHitCopy) | |
155 | { | |
156 | fHits->Add(sx->Clone()); | |
b055c99d | 157 | AliSignal* s=(AliSignal*)fHits->Last(); |
7a086578 | 158 | s->ResetLinks((AliDevice*)&dev); |
965bd237 | 159 | s->SetDevice(this); |
7a086578 | 160 | } |
161 | else | |
162 | { | |
163 | sx->AddLink(this); | |
164 | fHits->Add(sx); | |
165 | } | |
166 | } | |
167 | } | |
168 | } | |
169 | /////////////////////////////////////////////////////////////////////////// | |
170 | void AliDevice::Reset(Int_t mode) | |
171 | { | |
172 | // Reset registered hits and AliSignal attributes. | |
9e6577df | 173 | // Note : The status word and HitCopy flag are NOT modified. |
174 | // Use SetStatus() and SetHitCopy() to modify these parameters. | |
7a086578 | 175 | // See AliSignal::Reset() for further details. |
176 | RemoveHits(); | |
177 | AliSignal::Reset(mode); | |
178 | } | |
179 | /////////////////////////////////////////////////////////////////////////// | |
180 | void AliDevice::SetHitCopy(Int_t j) | |
181 | { | |
182 | // (De)activate the creation of private copies of the AliSignals added as hits. | |
183 | // j=0 ==> No private copies are made; pointers of original hits are stored. | |
184 | // j=1 ==> Private copies of the hits are made and these pointers are stored. | |
185 | // | |
186 | // Note : Once the storage contains pointer(s) to hit(s) one cannot | |
187 | // change the HitCopy mode anymore. | |
188 | // To change the HitCopy mode for an existing AliDevice containing | |
189 | // hits one first has to invoke either RemoveHits() or Reset(). | |
190 | if (!fHits) | |
191 | { | |
192 | if (j==0 || j==1) | |
193 | { | |
194 | fHitCopy=j; | |
195 | } | |
196 | else | |
197 | { | |
198 | cout << "*AliDevice::SetHitCopy* Invalid argument : " << j << endl; | |
199 | } | |
200 | } | |
201 | else | |
202 | { | |
203 | cout << "*AliDevice::SetHitCopy* Storage already contained hits." | |
204 | << " ==> HitCopy mode not changed." << endl; | |
205 | } | |
206 | } | |
207 | /////////////////////////////////////////////////////////////////////////// | |
208 | Int_t AliDevice::GetHitCopy() const | |
209 | { | |
210 | // Provide value of the HitCopy mode. | |
211 | // 0 ==> No private copies are made; pointers of original hits are stored. | |
212 | // 1 ==> Private copies of the hits are made and these pointers are stored. | |
213 | return fHitCopy; | |
214 | } | |
215 | /////////////////////////////////////////////////////////////////////////// | |
9e6577df | 216 | void AliDevice::SetStatus(Int_t word) |
217 | { | |
218 | // Set a user defined status word for this device. | |
219 | fStatus=word; | |
220 | } | |
221 | /////////////////////////////////////////////////////////////////////////// | |
222 | Int_t AliDevice::GetStatus() const | |
223 | { | |
224 | // Provide the user defined status word for this device. | |
225 | return fStatus; | |
226 | } | |
227 | /////////////////////////////////////////////////////////////////////////// | |
7a086578 | 228 | void AliDevice::AddHit(AliSignal& s) |
229 | { | |
230 | // Register an AliSignal object as a hit to this device. | |
965bd237 | 231 | // Note : In case this device owns the AliSignal object, the pointer to |
232 | // this device will be stored in the special owning device | |
233 | // pointer of the AliSignal object. | |
234 | // In case this device does not own the AliSignal object, a (backward) | |
235 | // link to this device is added to the first slot of the AliSignal | |
236 | // if there was no link to this device already present. | |
237 | ||
7a086578 | 238 | if (!fHits) |
239 | { | |
240 | fHits=new TObjArray(1); | |
241 | if (fHitCopy) fHits->SetOwner(); | |
242 | } | |
243 | ||
244 | // Check if this signal is already stored for this device. | |
245 | Int_t nhits=GetNhits(); | |
246 | for (Int_t i=0; i<nhits; i++) | |
247 | { | |
248 | if (&s==fHits->At(i)) return; | |
249 | } | |
250 | ||
965bd237 | 251 | // Check for existing (backward) link to this device. |
252 | Int_t nlinks=s.GetNlinks(this); | |
7a086578 | 253 | |
254 | if (fHitCopy) | |
255 | { | |
256 | fHits->Add(s.Clone()); | |
965bd237 | 257 | // Remove unnecessary backward link(s) from the various slots |
258 | // and set the owning link to this device | |
259 | AliSignal* sx=(AliSignal*)fHits->Last(); | |
260 | if (nlinks) sx->ResetLinks(this); | |
261 | sx->SetDevice(this); | |
7a086578 | 262 | } |
263 | else | |
264 | { | |
265 | fHits->Add(&s); | |
965bd237 | 266 | // Set (backward) link to the this device |
267 | if (!nlinks) s.AddLink(this); | |
7a086578 | 268 | } |
269 | } | |
270 | /////////////////////////////////////////////////////////////////////////// | |
271 | void AliDevice::RemoveHit(AliSignal& s) | |
272 | { | |
273 | // Remove AliSignal object registered as a hit from this device. | |
274 | if (fHits) | |
275 | { | |
276 | AliSignal* test=(AliSignal*)fHits->Remove(&s); | |
277 | if (test) | |
278 | { | |
279 | fHits->Compress(); | |
280 | if (fHitCopy) delete test; | |
281 | } | |
282 | } | |
7b825f44 | 283 | if (fOrdered) |
284 | { | |
285 | AliSignal* test=(AliSignal*)fOrdered->Remove(&s); | |
286 | if (test) fOrdered->Compress(); | |
287 | } | |
7a086578 | 288 | } |
289 | /////////////////////////////////////////////////////////////////////////// | |
290 | void AliDevice::RemoveHits() | |
291 | { | |
292 | // Remove all AliSignal objects registered as hits from this device. | |
293 | if (fHits) | |
294 | { | |
295 | delete fHits; | |
296 | fHits=0; | |
297 | } | |
7b825f44 | 298 | if (fOrdered) |
299 | { | |
300 | delete fOrdered; | |
301 | fOrdered=0; | |
302 | } | |
965bd237 | 303 | if (fMarkers) |
304 | { | |
305 | delete fMarkers; | |
306 | fMarkers=0; | |
307 | } | |
7a086578 | 308 | } |
309 | /////////////////////////////////////////////////////////////////////////// | |
310 | Int_t AliDevice::GetNhits() const | |
311 | { | |
312 | // Provide the number of registered hits for this device. | |
313 | Int_t nhits=0; | |
314 | if (fHits) nhits=fHits->GetEntries(); | |
315 | return nhits; | |
316 | } | |
317 | /////////////////////////////////////////////////////////////////////////// | |
318 | AliSignal* AliDevice::GetHit(Int_t j) const | |
319 | { | |
320 | // Provide the AliSignal object registered as hit number j. | |
321 | // Note : j=1 denotes the first hit. | |
322 | if (!fHits) return 0; | |
323 | ||
324 | if ((j >= 1) && (j <= GetNhits())) | |
325 | { | |
326 | return (AliSignal*)fHits->At(j-1); | |
327 | } | |
328 | else | |
329 | { | |
330 | return 0; | |
331 | } | |
332 | } | |
333 | /////////////////////////////////////////////////////////////////////////// | |
4f368c8c | 334 | AliSignal* AliDevice::GetIdHit(Int_t id) const |
335 | { | |
336 | // Return the hit with unique identifier "id". | |
337 | if (!fHits || id<0) return 0; | |
338 | ||
339 | AliSignal* sx=0; | |
340 | Int_t sid=0; | |
341 | for (Int_t i=0; i<GetNhits(); i++) | |
342 | { | |
343 | sx=(AliSignal*)fHits->At(i); | |
344 | if (sx) | |
345 | { | |
346 | sid=sx->GetUniqueID(); | |
347 | if (id==sid) return sx; | |
348 | } | |
349 | } | |
350 | return 0; // No matching id found | |
351 | } | |
352 | /////////////////////////////////////////////////////////////////////////// | |
7a086578 | 353 | TObjArray* AliDevice::GetHits() |
354 | { | |
355 | // Provide the references to all the registered hits. | |
356 | return fHits; | |
357 | } | |
358 | /////////////////////////////////////////////////////////////////////////// | |
359 | void AliDevice::ShowHit(Int_t j) const | |
360 | { | |
361 | // Show data of the registered j-th hit. | |
362 | // If j=0 all associated hits will be shown. | |
363 | // The default is j=0. | |
364 | if (!j) | |
365 | { | |
366 | Int_t nhits=GetNhits(); | |
367 | for (Int_t ih=1; ih<=nhits; ih++) | |
368 | { | |
369 | AliSignal* sx=GetHit(ih); | |
370 | if (sx) sx->Data(); | |
371 | } | |
372 | } | |
373 | else | |
374 | { | |
375 | AliSignal* s=GetHit(j); | |
376 | if (s) s->Data(); | |
377 | } | |
378 | } | |
379 | /////////////////////////////////////////////////////////////////////////// | |
1f241680 | 380 | void AliDevice::Data(TString f,TString u) const |
7a086578 | 381 | { |
382 | // Print the device and all registered hit info according to the specified | |
1f241680 | 383 | // coordinate frame f. |
384 | // | |
385 | // The string argument "u" allows to choose between different angular units | |
386 | // in case e.g. a spherical frame is selected. | |
387 | // u = "rad" : angles provided in radians | |
388 | // "deg" : angles provided in degrees | |
389 | // | |
390 | // The defaults are f="car" and u="rad". | |
391 | ||
392 | AliSignal::Data(f,u); | |
7a086578 | 393 | Int_t nhits=GetNhits(); |
394 | if (nhits) | |
395 | { | |
396 | cout << " The following " << nhits << " hits are registered : " << endl; | |
397 | ShowHit(); | |
398 | } | |
399 | else | |
400 | { | |
401 | cout << " No hits have been registered for this device." << endl; | |
402 | } | |
403 | } | |
404 | /////////////////////////////////////////////////////////////////////////// | |
27e6d856 | 405 | void AliDevice::GetExtremes(Float_t& vmin,Float_t& vmax,Int_t idx,TObjArray* hits,Int_t mode) const |
965bd237 | 406 | { |
407 | // Provide the min. and max. signal values of an array of hits. | |
408 | // The input argument "idx" denotes the index of the signal slots to be investigated. | |
409 | // The default is idx=1; | |
410 | // In case hits=0 (default), the registered hits of the current device are used. | |
411 | // Signals which were declared as "Dead" will be rejected. | |
27e6d856 | 412 | // The gain etc... corrected signals will be used in the process as specified |
413 | // by the "mode" argument. The definition of this "mode" parameter corresponds to | |
414 | // the description provided in the GetSignal memberfunction of class AliSignal. | |
415 | // The default is mode=1 (for backward compatibility reasons). | |
965bd237 | 416 | |
417 | vmin=0; | |
418 | vmax=0; | |
419 | ||
420 | if (!hits) hits=fHits; | |
421 | ||
422 | if (idx<=0 || !hits) return; | |
423 | ||
424 | Int_t nhits=hits->GetEntries(); | |
425 | ||
426 | Float_t sig=0; | |
427 | for (Int_t i=0; i<nhits; i++) | |
428 | { | |
429 | AliSignal* sx=(AliSignal*)hits->At(i); | |
430 | ||
431 | if (!sx) continue; | |
432 | if (idx > sx->GetNvalues()) continue; // User specified slotindex out of range for this signal | |
433 | if (sx->GetDeadValue(idx)) continue; // Only take alive signals | |
434 | ||
27e6d856 | 435 | sig=sx->GetSignal(idx,mode); |
965bd237 | 436 | if (i==0) |
437 | { | |
438 | vmin=sig; | |
439 | vmax=sig; | |
440 | } | |
441 | else | |
442 | { | |
443 | if (sig<vmin) vmin=sig; | |
444 | if (sig>vmax) vmax=sig; | |
445 | } | |
446 | } | |
447 | } | |
448 | /////////////////////////////////////////////////////////////////////////// | |
27e6d856 | 449 | void AliDevice::GetExtremes(Float_t& vmin,Float_t& vmax,TString name,TObjArray* hits,Int_t mode) const |
965bd237 | 450 | { |
451 | // Provide the min. and max. signal values of an array of hits. | |
452 | // The input argument "name" denotes the name of the signal slots to be investigated. | |
453 | // In case hits=0 (default), the registered hits of the current device are used. | |
454 | // Signals which were declared as "Dead" will be rejected. | |
27e6d856 | 455 | // The gain etc... corrected signals will be used in the process as specified |
456 | // by the "mode" argument. The definition of this "mode" parameter corresponds to | |
457 | // the description provided in the GetSignal memberfunction of class AliSignal. | |
458 | // The default is mode=1 (for backward compatibility reasons). | |
965bd237 | 459 | |
460 | vmin=0; | |
461 | vmax=0; | |
462 | ||
463 | if (!hits) hits=fHits; | |
464 | ||
465 | if (!hits) return; | |
466 | ||
467 | Int_t nhits=hits->GetEntries(); | |
468 | ||
469 | Int_t idx=0; // The signal slotindex to perform the sorting on | |
470 | ||
471 | Float_t sig=0; | |
472 | for (Int_t i=0; i<nhits; i++) | |
473 | { | |
474 | AliSignal* sx=(AliSignal*)hits->At(i); | |
475 | ||
476 | if (!sx) continue; | |
477 | ||
478 | // Obtain the slotindex corresponding to the user selection | |
479 | idx=sx->GetSlotIndex(name); | |
480 | if (!idx) continue; | |
481 | ||
482 | if (sx->GetDeadValue(idx)) continue; // Only take alive signals | |
483 | ||
27e6d856 | 484 | sig=sx->GetSignal(idx,mode); |
965bd237 | 485 | if (i==0) |
486 | { | |
487 | vmin=sig; | |
488 | vmax=sig; | |
489 | } | |
490 | else | |
491 | { | |
492 | if (sig<vmin) vmin=sig; | |
493 | if (sig>vmax) vmax=sig; | |
494 | } | |
495 | } | |
496 | } | |
497 | /////////////////////////////////////////////////////////////////////////// | |
27e6d856 | 498 | TObjArray* AliDevice::SortHits(Int_t idx,Int_t mode,TObjArray* hits,Int_t mcal) |
7a086578 | 499 | { |
500 | // Order the references to an array of hits by looping over the input array "hits" | |
501 | // and checking the signal value. The ordered array is returned as a TObjArray. | |
502 | // In case hits=0 (default), the registered hits of the current device are used. | |
965bd237 | 503 | // Note that the original hit array is not modified. |
7a086578 | 504 | // A "hit" represents an abstract object which is derived from AliSignal. |
505 | // The user can specify the index of the signal slot to perform the sorting on. | |
506 | // By default the slotindex will be 1. | |
507 | // Via the "mode" argument the user can specify ordering in decreasing | |
508 | // order (mode=-1) or ordering in increasing order (mode=1). | |
509 | // The default is mode=-1. | |
510 | // Signals which were declared as "Dead" will be rejected. | |
27e6d856 | 511 | // The gain etc... corrected signals will be used in the ordering process as |
512 | // specified by the "mcal" argument. The definition of this "mcal" parameter | |
513 | // corresponds to the signal correction mode described in the GetSignal | |
514 | // memberfunction of class AliSignal. | |
515 | // The default is mcal=1 (for backward compatibility reasons). | |
7a086578 | 516 | |
7b825f44 | 517 | if (fOrdered) |
518 | { | |
519 | delete fOrdered; | |
520 | fOrdered=0; | |
521 | } | |
7a086578 | 522 | |
523 | if (!hits) hits=fHits; | |
524 | ||
7b825f44 | 525 | if (idx<=0 || abs(mode)!=1 || !hits) return fOrdered; |
7a086578 | 526 | |
527 | Int_t nhits=hits->GetEntries(); | |
528 | if (!nhits) | |
529 | { | |
7b825f44 | 530 | return fOrdered; |
7a086578 | 531 | } |
532 | else | |
533 | { | |
7b825f44 | 534 | fOrdered=new TObjArray(nhits); |
7a086578 | 535 | } |
536 | ||
537 | Int_t nord=0; | |
538 | for (Int_t i=0; i<nhits; i++) // Loop over all hits of the array | |
539 | { | |
540 | AliSignal* s=(AliSignal*)hits->At(i); | |
541 | ||
542 | if (!s) continue; | |
543 | ||
544 | if (idx > s->GetNvalues()) continue; // User specified slotindex out of range for this signal | |
545 | if (s->GetDeadValue(idx)) continue; // Only take alive signals | |
546 | ||
547 | if (nord == 0) // store the first hit with a signal at the first ordered position | |
548 | { | |
549 | nord++; | |
7b825f44 | 550 | fOrdered->AddAt(s,nord-1); |
7a086578 | 551 | continue; |
552 | } | |
553 | ||
554 | for (Int_t j=0; j<=nord; j++) // put hit in the right ordered position | |
555 | { | |
556 | if (j == nord) // module has smallest (mode=-1) or largest (mode=1) signal seen so far | |
557 | { | |
558 | nord++; | |
7b825f44 | 559 | fOrdered->AddAt(s,j); // add hit at the end |
7a086578 | 560 | break; // go for next hit |
561 | } | |
562 | ||
27e6d856 | 563 | if (mode==-1 && s->GetSignal(idx,mcal) < ((AliSignal*)fOrdered->At(j))->GetSignal(idx,mcal)) continue; |
564 | if (mode==1 && s->GetSignal(idx,mcal) > ((AliSignal*)fOrdered->At(j))->GetSignal(idx,mcal)) continue; | |
7a086578 | 565 | |
566 | nord++; | |
567 | for (Int_t k=nord-1; k>j; k--) // create empty position | |
568 | { | |
7b825f44 | 569 | fOrdered->AddAt(fOrdered->At(k-1),k); |
7a086578 | 570 | } |
7b825f44 | 571 | fOrdered->AddAt(s,j); // put hit at empty position |
4962c850 | 572 | break; // go for next hit |
7a086578 | 573 | } |
574 | } | |
7b825f44 | 575 | return fOrdered; |
7a086578 | 576 | } |
577 | /////////////////////////////////////////////////////////////////////////// | |
27e6d856 | 578 | TObjArray* AliDevice::SortHits(TString name,Int_t mode,TObjArray* hits,Int_t mcal) |
7a086578 | 579 | { |
580 | // Order the references to an array of hits by looping over the input array "hits" | |
581 | // and checking the signal value. The ordered array is returned as a TObjArray. | |
582 | // In case hits=0 (default), the registered hits of the current device are used. | |
965bd237 | 583 | // Note that the input array is not modified. |
7a086578 | 584 | // A "hit" represents an abstract object which is derived from AliSignal. |
585 | // The user can specify the name of the signal slot to perform the sorting on. | |
586 | // In case no matching slotname is found, the signal will be skipped. | |
587 | // Via the "mode" argument the user can specify ordering in decreasing | |
588 | // order (mode=-1) or ordering in increasing order (mode=1). | |
589 | // The default is mode=-1. | |
590 | // Signals which were declared as "Dead" will be rejected. | |
27e6d856 | 591 | // The gain etc... corrected signals will be used in the ordering process as |
592 | // specified by the "mcal" argument. The definition of this "mcal" parameter | |
593 | // corresponds to the signal correction mode described in the GetSignal | |
594 | // memberfunction of class AliSignal. | |
595 | // The default is mcal=1 (for backward compatibility reasons). | |
7a086578 | 596 | |
7b825f44 | 597 | if (fOrdered) |
598 | { | |
599 | delete fOrdered; | |
600 | fOrdered=0; | |
601 | } | |
7a086578 | 602 | |
603 | if (!hits) hits=fHits; | |
604 | ||
7b825f44 | 605 | if (abs(mode)!=1 || !hits) return fOrdered; |
7a086578 | 606 | |
607 | Int_t nhits=hits->GetEntries(); | |
608 | if (!nhits) | |
609 | { | |
7b825f44 | 610 | return fOrdered; |
7a086578 | 611 | } |
612 | else | |
613 | { | |
7b825f44 | 614 | fOrdered=new TObjArray(nhits); |
7a086578 | 615 | } |
616 | ||
617 | Int_t idx=0; // The signal slotindex to perform the sorting on | |
618 | ||
619 | Int_t nord=0; | |
620 | for (Int_t i=0; i<nhits; i++) // loop over all hits of the array | |
621 | { | |
622 | AliSignal* s=(AliSignal*)hits->At(i); | |
623 | ||
624 | if (!s) continue; | |
625 | ||
626 | // Obtain the slotindex corresponding to the user selection | |
627 | idx=s->GetSlotIndex(name); | |
628 | if (!idx) continue; | |
629 | ||
630 | if (s->GetDeadValue(idx)) continue; // only take alive signals | |
631 | ||
632 | if (nord == 0) // store the first hit with a signal at the first ordered position | |
633 | { | |
634 | nord++; | |
7b825f44 | 635 | fOrdered->AddAt(s,nord-1); |
7a086578 | 636 | continue; |
637 | } | |
638 | ||
639 | for (Int_t j=0; j<=nord; j++) // put hit in the right ordered position | |
640 | { | |
641 | if (j == nord) // module has smallest (mode=-1) or largest (mode=1) signal seen so far | |
642 | { | |
643 | nord++; | |
7b825f44 | 644 | fOrdered->AddAt(s,j); // add hit at the end |
7a086578 | 645 | break; // go for next hit |
646 | } | |
647 | ||
27e6d856 | 648 | if (mode==-1 && s->GetSignal(idx,mcal) < ((AliSignal*)fOrdered->At(j))->GetSignal(idx,mcal)) continue; |
649 | if (mode==1 && s->GetSignal(idx,mcal) > ((AliSignal*)fOrdered->At(j))->GetSignal(idx,mcal)) continue; | |
7a086578 | 650 | |
651 | nord++; | |
652 | for (Int_t k=nord-1; k>j; k--) // create empty position | |
653 | { | |
7b825f44 | 654 | fOrdered->AddAt(fOrdered->At(k-1),k); |
7a086578 | 655 | } |
7b825f44 | 656 | fOrdered->AddAt(s,j); // put hit at empty position |
4962c850 | 657 | break; // go for next hit |
7a086578 | 658 | } |
659 | } | |
7b825f44 | 660 | return fOrdered; |
7a086578 | 661 | } |
662 | /////////////////////////////////////////////////////////////////////////// | |
27e6d856 | 663 | void AliDevice::DisplayHits(Int_t idx,Float_t scale,TObjArray* hits,Int_t dp,Int_t mode,Int_t mcol) |
965bd237 | 664 | { |
665 | // 3D color display of an array hits. | |
666 | // The user can specify the index (default=1) of the signal slot to perform the display for. | |
667 | // The marker size will indicate the absolute value of the signal (specified by the slotindex) | |
668 | // as a percentage of the input argument "scale". | |
669 | // In case scale<0 the maximum absolute signal value encountered in the hit array will be used | |
670 | // to define the 100% scale. The default is scale=-1. | |
671 | // In case hits=0 (default), the registered hits of the current device are used. | |
672 | // Note that the input array is not modified. | |
673 | // In case dp=1 the device position will be used, otherwise the hit position will | |
674 | // be used in the display. The default is dp=0. | |
27e6d856 | 675 | // Via the "mcol" argument the user can specify the marker color (see TPolyMarker3D). |
676 | // The default is mcol=blue. | |
965bd237 | 677 | // Signals which were declared as "Dead" will not be displayed. |
678 | // The gain etc... corrected signals will be used to determine the marker size. | |
27e6d856 | 679 | // The gain correction is performed according to "mode" argument. The definition of this |
680 | // "mode" parameter corresponds to the description provided in the GetSignal | |
681 | // memberfunction of class AliSignal. | |
682 | // The default is mode=1 (for backward compatibility reasons). | |
965bd237 | 683 | // |
684 | // Note : | |
685 | // ------ | |
686 | // Before any display activity, a TCanvas and a TView have to be initiated | |
687 | // first by the user like for instance | |
688 | // | |
689 | // TCanvas* c1=new TCanvas("c1","c1"); | |
690 | // TView* view=new TView(1); | |
691 | // view->SetRange(-1000,-1000,-1000,1000,1000,1000); | |
692 | // view->ShowAxis(); | |
693 | ||
694 | Int_t thisdev=0; // Indicate whether this is the owning device or not | |
695 | if (!hits) | |
696 | { | |
697 | hits=fHits; | |
698 | thisdev=1; | |
699 | } | |
700 | ||
701 | if (idx<=0 || !hits) return; | |
702 | ||
703 | Int_t nhits=hits->GetEntries(); | |
704 | if (!nhits) return; | |
705 | ||
706 | Float_t sigmax=fabs(scale); | |
707 | if (scale<0) | |
708 | { | |
709 | Float_t vmin,vmax; | |
710 | GetExtremes(vmin,vmax,idx,hits); | |
711 | sigmax=fabs(vmax); | |
712 | if (fabs(vmin)>sigmax) sigmax=fabs(vmin); | |
713 | } | |
714 | ||
715 | if (sigmax <=0) return; | |
716 | ||
717 | if (fMarkers) | |
718 | { | |
719 | delete fMarkers; | |
720 | fMarkers=0; | |
721 | } | |
722 | fMarkers=new TObjArray(nhits); | |
723 | fMarkers->SetOwner(); | |
724 | ||
725 | Float_t pos[3]; | |
726 | GetPosition(pos,"car"); | |
727 | ||
728 | Float_t sig=0; | |
729 | for (Int_t ih=0; ih<nhits; ih++) | |
730 | { | |
731 | AliSignal* sx=(AliSignal*)hits->At(ih); | |
732 | if (!sx) continue; | |
733 | if (!dp) | |
734 | { | |
735 | sx->GetPosition(pos,"car"); | |
736 | } | |
737 | else | |
738 | { | |
739 | if (!thisdev) | |
740 | { | |
741 | AliDevice* dev=sx->GetDevice(); | |
742 | if (dev) dev->GetPosition(pos,"car"); | |
743 | } | |
744 | } | |
27e6d856 | 745 | sig=sx->GetSignal(idx,mode); |
965bd237 | 746 | TPolyMarker3D* m=new TPolyMarker3D(); |
27e6d856 | 747 | m->SetMarkerStyle(8); |
965bd237 | 748 | m->SetMarkerColor(mcol); |
749 | m->SetMarkerSize(100.*fabs(sig)/sigmax); | |
750 | m->SetPoint(0,pos[0],pos[1],pos[2]); | |
751 | fMarkers->Add(m); | |
752 | m->Draw(); | |
753 | } | |
754 | } | |
755 | /////////////////////////////////////////////////////////////////////////// | |
27e6d856 | 756 | void AliDevice::DisplayHits(TString name,Float_t scale,TObjArray* hits,Int_t dp,Int_t mode,Int_t mcol) |
965bd237 | 757 | { |
758 | // 3D color display of an array hits. | |
759 | // The user can specify the name of the signal slot to perform the display for. | |
760 | // The marker size will indicate the absolute value of the signal (specified by the slotname) | |
761 | // as a percentage of the input argument "scale". | |
762 | // In case scale<0 the maximum absolute signal value encountered in the hit array will be used | |
763 | // to define the 100% scale. The default is scale=-1. | |
764 | // In case hits=0 (default), the registered hits of the current device are used. | |
765 | // Note that the input array is not modified. | |
766 | // In case dp=1 the device position will be used, otherwise the hit position will | |
767 | // be used in the display. The default is dp=0. | |
768 | // The marker size will indicate the percentage of the maximum encountered value | |
769 | // of the absolute value of the name-specified input signal slots. | |
27e6d856 | 770 | // Via the "mcol" argument the user can specify the marker color (see TPolyMarker3D). |
771 | // The default is mcol=blue. | |
965bd237 | 772 | // Signals which were declared as "Dead" will not be displayed. |
773 | // The gain etc... corrected signals will be used to determine the marker size. | |
27e6d856 | 774 | // The gain correction is performed according to "mode" argument. The definition of this |
775 | // "mode" parameter corresponds to the description provided in the GetSignal | |
776 | // memberfunction of class AliSignal. | |
777 | // The default is mode=1 (for backward compatibility reasons). | |
965bd237 | 778 | // |
779 | // Note : | |
780 | // ------ | |
781 | // Before any display activity, a TCanvas and a TView have to be initiated | |
782 | // first by the user like for instance | |
783 | // | |
784 | // TCanvas* c1=new TCanvas("c1","c1"); | |
785 | // TView* view=new TView(1); | |
786 | // view->SetRange(-1000,-1000,-1000,1000,1000,1000); | |
787 | // view->ShowAxis(); | |
788 | ||
789 | Int_t thisdev=0; // Indicate whether this is the owning device or not | |
790 | if (!hits) | |
791 | { | |
792 | hits=fHits; | |
793 | thisdev=1; | |
794 | } | |
795 | ||
796 | if (!hits) return; | |
797 | ||
798 | Int_t nhits=hits->GetEntries(); | |
799 | ||
800 | if (!nhits) return; | |
801 | ||
802 | Float_t sigmax=fabs(scale); | |
803 | if (scale<0) | |
804 | { | |
805 | Float_t vmin,vmax; | |
806 | GetExtremes(vmin,vmax,name,hits); | |
807 | sigmax=fabs(vmax); | |
808 | if (fabs(vmin)>sigmax) sigmax=fabs(vmin); | |
809 | } | |
810 | ||
811 | if (sigmax <=0) return; | |
812 | ||
813 | if (fMarkers) | |
814 | { | |
815 | delete fMarkers; | |
816 | fMarkers=0; | |
817 | } | |
818 | fMarkers=new TObjArray(nhits); | |
819 | fMarkers->SetOwner(); | |
820 | ||
821 | Float_t pos[3]; | |
822 | GetPosition(pos,"car"); | |
823 | ||
824 | Int_t idx=0; // The slot index corresponding to the user specified name | |
825 | Float_t sig=0; | |
826 | for (Int_t ih=0; ih<nhits; ih++) | |
827 | { | |
828 | AliSignal* sx=(AliSignal*)hits->At(ih); | |
829 | if (!sx) continue; | |
830 | idx=sx->GetSlotIndex(name); | |
831 | if (!idx) continue; | |
832 | if (!dp) | |
833 | { | |
834 | sx->GetPosition(pos,"car"); | |
835 | } | |
836 | else | |
837 | { | |
838 | if (!thisdev) | |
839 | { | |
840 | AliDevice* dev=sx->GetDevice(); | |
841 | if (dev) dev->GetPosition(pos,"car"); | |
842 | } | |
843 | } | |
27e6d856 | 844 | sig=sx->GetSignal(idx,mode); |
965bd237 | 845 | TPolyMarker3D* m=new TPolyMarker3D(); |
27e6d856 | 846 | m->SetMarkerStyle(8); |
965bd237 | 847 | m->SetMarkerColor(mcol); |
848 | m->SetMarkerSize(100.*fabs(sig)/sigmax); | |
849 | m->SetPoint(0,pos[0],pos[1],pos[2]); | |
850 | fMarkers->Add(m); | |
851 | m->Draw(); | |
852 | } | |
853 | } | |
854 | /////////////////////////////////////////////////////////////////////////// | |
7a086578 | 855 | TObject* AliDevice::Clone(const char* name) const |
856 | { | |
857 | // Make a deep copy of the current object and provide the pointer to the copy. | |
858 | // This memberfunction enables automatic creation of new objects of the | |
859 | // correct type depending on the object type, a feature which may be very useful | |
860 | // for containers like AliEvent when adding objects in case the | |
861 | // container owns the objects. This feature allows e.g. AliEvent | |
862 | // to store either AliDevice objects or objects derived from AliDevice | |
863 | // via tha AddDevice memberfunction, provided these derived classes also have | |
864 | // a proper Clone memberfunction. | |
865 | ||
866 | AliDevice* dev=new AliDevice(*this); | |
867 | if (name) | |
868 | { | |
869 | if (strlen(name)) dev->SetName(name); | |
870 | } | |
871 | return dev; | |
872 | } | |
873 | /////////////////////////////////////////////////////////////////////////// |