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 ///////////////////////////////////////////////////////////////////////////
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.
30 // // Set user defined status word to indicate e.g. readout electronics version
31 // m.SetStatus(100201);
33 // m.SetName("OM123");
35 // Float_t pos[3]={1,2,3};
36 // m.SetPosition(pos,"car");
41 // s.SetName("OM123 Hit 1");
42 // s.SetSlotName("ADC");
44 // s.SetSlotName("LE",2);
45 // s.SetSignal(-100,2);
46 // s.SetSlotName("TOT",3);
47 // s.SetSignal(-1000,3);
51 // s.SetName("OM123 Hit 2");
52 // s.SetSlotName("ADC");
54 // s.SetSlotName("LE",2);
55 // s.SetSignal(-101,2);
56 // s.SetSlotName("TOT",3);
57 // s.SetSignal(1001,3);
61 // s.SetName("OM123 Hit 3");
62 // s.SetSlotName("ADC");
64 // s.SetSlotName("LE",2);
65 // s.SetSignal(-102,2);
66 // s.SetSlotName("TOT",3);
67 // s.SetSignal(-1002,3);
70 // TObjArray* ordered=m.SortHits("TOT");
71 // nhits=ordered->GetEntries();
72 // for (Int_t i=0; i<nhits; i++)
74 // AliSignal* sx=(AliSignal*)ordered->At(i);
75 // if (sx) sx->Data();
78 //--- Author: Nick van Eijndhoven 23-jun-2004 Utrecht University
79 //- Modified: NvE $Date$ Utrecht University
80 ///////////////////////////////////////////////////////////////////////////
82 #include "AliDevice.h"
83 #include "Riostream.h"
85 ClassImp(AliDevice) // Class implementation to enable ROOT I/O
87 AliDevice::AliDevice() : AliSignal()
89 // Default constructor.
90 // The user definable status word is set to zero.
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.
100 ///////////////////////////////////////////////////////////////////////////
101 AliDevice::~AliDevice()
103 // Default destructor.
105 // Remove backward links to this device from the hits
106 // which were not owned by it.
109 for (Int_t ih=1; ih<=GetNhits(); ih++)
111 AliSignal* sx=GetHit(ih);
112 if (sx) sx->ResetLinks(this);
134 ///////////////////////////////////////////////////////////////////////////
135 AliDevice::AliDevice(const AliDevice& dev) : AliSignal(dev)
143 fStatus=dev.GetStatus();
144 fHitCopy=dev.GetHitCopy();
146 Int_t nhits=dev.GetNhits();
149 fHits=new TObjArray(nhits);
150 if (fHitCopy) fHits->SetOwner();
151 for (Int_t ih=1; ih<=nhits; ih++)
153 AliSignal* sx=dev.GetHit(ih);
156 fHits->Add(sx->Clone());
157 AliSignal* s=(AliSignal*)fHits->Last();
158 s->ResetLinks((AliDevice*)&dev);
169 ///////////////////////////////////////////////////////////////////////////
170 void AliDevice::Reset(Int_t mode)
172 // Reset registered hits and AliSignal attributes.
173 // Note : The status word and HitCopy flag are NOT modified.
174 // Use SetStatus() and SetHitCopy() to modify these parameters.
175 // See AliSignal::Reset() for further details.
177 AliSignal::Reset(mode);
179 ///////////////////////////////////////////////////////////////////////////
180 void AliDevice::SetHitCopy(Int_t j)
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.
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().
198 cout << "*AliDevice::SetHitCopy* Invalid argument : " << j << endl;
203 cout << "*AliDevice::SetHitCopy* Storage already contained hits."
204 << " ==> HitCopy mode not changed." << endl;
207 ///////////////////////////////////////////////////////////////////////////
208 Int_t AliDevice::GetHitCopy() const
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.
215 ///////////////////////////////////////////////////////////////////////////
216 void AliDevice::SetStatus(Int_t word)
218 // Set a user defined status word for this device.
221 ///////////////////////////////////////////////////////////////////////////
222 Int_t AliDevice::GetStatus() const
224 // Provide the user defined status word for this device.
227 ///////////////////////////////////////////////////////////////////////////
228 void AliDevice::AddHit(AliSignal& s)
230 // Register an AliSignal object as a hit to this device.
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.
240 fHits=new TObjArray(1);
241 if (fHitCopy) fHits->SetOwner();
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++)
248 if (&s==fHits->At(i)) return;
251 // Check for existing (backward) link to this device.
252 Int_t nlinks=s.GetNlinks(this);
256 fHits->Add(s.Clone());
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);
266 // Set (backward) link to the this device
267 if (!nlinks) s.AddLink(this);
270 ///////////////////////////////////////////////////////////////////////////
271 void AliDevice::RemoveHit(AliSignal& s)
273 // Remove AliSignal object registered as a hit from this device.
276 AliSignal* test=(AliSignal*)fHits->Remove(&s);
280 if (fHitCopy) delete test;
285 AliSignal* test=(AliSignal*)fOrdered->Remove(&s);
286 if (test) fOrdered->Compress();
289 ///////////////////////////////////////////////////////////////////////////
290 void AliDevice::RemoveHits()
292 // Remove all AliSignal objects registered as hits from this device.
309 ///////////////////////////////////////////////////////////////////////////
310 Int_t AliDevice::GetNhits() const
312 // Provide the number of registered hits for this device.
314 if (fHits) nhits=fHits->GetEntries();
317 ///////////////////////////////////////////////////////////////////////////
318 AliSignal* AliDevice::GetHit(Int_t j) const
320 // Provide the AliSignal object registered as hit number j.
321 // Note : j=1 denotes the first hit.
322 if (!fHits) return 0;
324 if ((j >= 1) && (j <= GetNhits()))
326 return (AliSignal*)fHits->At(j-1);
333 ///////////////////////////////////////////////////////////////////////////
334 AliSignal* AliDevice::GetHit(TString name) const
336 // Provide the AliSignal object registered as hit with the specified name.
337 // Note : The first hit encountered with the specified name will be provided.
339 if (!fHits) return 0;
342 Int_t nhits=GetNhits();
343 for (Int_t i=0; i<nhits; i++)
345 AliSignal* sx=(AliSignal*)fHits->At(i);
348 hitname=sx->GetName();
349 if (hitname == name) return sx;
353 return 0; // No matching name found
355 ///////////////////////////////////////////////////////////////////////////
356 AliSignal* AliDevice::GetIdHit(Int_t id) const
358 // Return the hit with unique identifier "id".
359 if (!fHits || id<0) return 0;
363 for (Int_t i=0; i<GetNhits(); i++)
365 sx=(AliSignal*)fHits->At(i);
368 sid=sx->GetUniqueID();
369 if (id==sid) return sx;
372 return 0; // No matching id found
374 ///////////////////////////////////////////////////////////////////////////
375 TObjArray* AliDevice::GetHits()
377 // Provide the references to all the registered hits.
380 ///////////////////////////////////////////////////////////////////////////
381 void AliDevice::ShowHit(Int_t j) const
383 // Show data of the registered j-th hit.
384 // If j=0 all associated hits will be shown.
385 // The default is j=0.
388 Int_t nhits=GetNhits();
389 for (Int_t ih=1; ih<=nhits; ih++)
391 AliSignal* sx=GetHit(ih);
397 AliSignal* s=GetHit(j);
401 ///////////////////////////////////////////////////////////////////////////
402 void AliDevice::Data(TString f,TString u) const
404 // Print the device and all registered hit info according to the specified
405 // coordinate frame f.
407 // The string argument "u" allows to choose between different angular units
408 // in case e.g. a spherical frame is selected.
409 // u = "rad" : angles provided in radians
410 // "deg" : angles provided in degrees
412 // The defaults are f="car" and u="rad".
414 AliSignal::Data(f,u);
415 Int_t nhits=GetNhits();
418 cout << " The following " << nhits << " hits are registered : " << endl;
423 cout << " No hits have been registered for this device." << endl;
426 ///////////////////////////////////////////////////////////////////////////
427 void AliDevice::GetExtremes(Float_t& vmin,Float_t& vmax,Int_t idx,TObjArray* hits,Int_t mode) const
429 // Provide the min. and max. signal values of an array of hits.
430 // The input argument "idx" denotes the index of the signal slots to be investigated.
431 // The default is idx=1;
432 // In case hits=0 (default), the registered hits of the current device are used.
433 // Signals which were declared as "Dead" will be rejected.
434 // The gain etc... corrected signals will be used in the process as specified
435 // by the "mode" argument. The definition of this "mode" parameter corresponds to
436 // the description provided in the GetSignal memberfunction of class AliSignal.
437 // The default is mode=1 (for backward compatibility reasons).
442 if (!hits) hits=fHits;
444 if (idx<=0 || !hits) return;
446 Int_t nhits=hits->GetEntries();
449 for (Int_t i=0; i<nhits; i++)
451 AliSignal* sx=(AliSignal*)hits->At(i);
454 if (idx > sx->GetNvalues()) continue; // User specified slotindex out of range for this signal
455 if (sx->GetDeadValue(idx)) continue; // Only take alive signals
457 sig=sx->GetSignal(idx,mode);
465 if (sig<vmin) vmin=sig;
466 if (sig>vmax) vmax=sig;
470 ///////////////////////////////////////////////////////////////////////////
471 void AliDevice::GetExtremes(Float_t& vmin,Float_t& vmax,TString name,TObjArray* hits,Int_t mode) const
473 // Provide the min. and max. signal values of an array of hits.
474 // The input argument "name" denotes the name of the signal slots to be investigated.
475 // In case hits=0 (default), the registered hits of the current device are used.
476 // Signals which were declared as "Dead" will be rejected.
477 // The gain etc... corrected signals will be used in the process as specified
478 // by the "mode" argument. The definition of this "mode" parameter corresponds to
479 // the description provided in the GetSignal memberfunction of class AliSignal.
480 // The default is mode=1 (for backward compatibility reasons).
485 if (!hits) hits=fHits;
489 Int_t nhits=hits->GetEntries();
491 Int_t idx=0; // The signal slotindex to perform the sorting on
494 for (Int_t i=0; i<nhits; i++)
496 AliSignal* sx=(AliSignal*)hits->At(i);
500 // Obtain the slotindex corresponding to the user selection
501 idx=sx->GetSlotIndex(name);
504 if (sx->GetDeadValue(idx)) continue; // Only take alive signals
506 sig=sx->GetSignal(idx,mode);
514 if (sig<vmin) vmin=sig;
515 if (sig>vmax) vmax=sig;
519 ///////////////////////////////////////////////////////////////////////////
520 TObjArray* AliDevice::SortHits(Int_t idx,Int_t mode,TObjArray* hits,Int_t mcal)
522 // Order the references to an array of hits by looping over the input array "hits"
523 // and checking the signal value. The ordered array is returned as a TObjArray.
524 // In case hits=0 (default), the registered hits of the current device are used.
525 // Note that the original hit array is not modified.
526 // A "hit" represents an abstract object which is derived from AliSignal.
527 // The user can specify the index of the signal slot to perform the sorting on.
528 // By default the slotindex will be 1.
529 // Via the "mode" argument the user can specify ordering in decreasing
530 // order (mode=-1) or ordering in increasing order (mode=1).
531 // The default is mode=-1.
532 // Signals which were declared as "Dead" will be rejected.
533 // The gain etc... corrected signals will be used in the ordering process as
534 // specified by the "mcal" argument. The definition of this "mcal" parameter
535 // corresponds to the signal correction mode described in the GetSignal
536 // memberfunction of class AliSignal.
537 // The default is mcal=1 (for backward compatibility reasons).
545 if (!hits) hits=fHits;
547 if (idx<=0 || abs(mode)!=1 || !hits) return fOrdered;
549 Int_t nhits=hits->GetEntries();
556 fOrdered=new TObjArray(nhits);
560 for (Int_t i=0; i<nhits; i++) // Loop over all hits of the array
562 AliSignal* s=(AliSignal*)hits->At(i);
566 if (idx > s->GetNvalues()) continue; // User specified slotindex out of range for this signal
567 if (s->GetDeadValue(idx)) continue; // Only take alive signals
569 if (nord == 0) // store the first hit with a signal at the first ordered position
572 fOrdered->AddAt(s,nord-1);
576 for (Int_t j=0; j<=nord; j++) // put hit in the right ordered position
578 if (j == nord) // module has smallest (mode=-1) or largest (mode=1) signal seen so far
581 fOrdered->AddAt(s,j); // add hit at the end
582 break; // go for next hit
585 if (mode==-1 && s->GetSignal(idx,mcal) <= ((AliSignal*)fOrdered->At(j))->GetSignal(idx,mcal)) continue;
586 if (mode==1 && s->GetSignal(idx,mcal) >= ((AliSignal*)fOrdered->At(j))->GetSignal(idx,mcal)) continue;
589 for (Int_t k=nord-1; k>j; k--) // create empty position
591 fOrdered->AddAt(fOrdered->At(k-1),k);
593 fOrdered->AddAt(s,j); // put hit at empty position
594 break; // go for next hit
599 ///////////////////////////////////////////////////////////////////////////
600 TObjArray* AliDevice::SortHits(TString name,Int_t mode,TObjArray* hits,Int_t mcal)
602 // Order the references to an array of hits by looping over the input array "hits"
603 // and checking the signal value. The ordered array is returned as a TObjArray.
604 // In case hits=0 (default), the registered hits of the current device are used.
605 // Note that the input array is not modified.
606 // A "hit" represents an abstract object which is derived from AliSignal.
607 // The user can specify the name of the signal slot to perform the sorting on.
608 // In case no matching slotname is found, the signal will be skipped.
609 // Via the "mode" argument the user can specify ordering in decreasing
610 // order (mode=-1) or ordering in increasing order (mode=1).
611 // The default is mode=-1.
612 // Signals which were declared as "Dead" will be rejected.
613 // The gain etc... corrected signals will be used in the ordering process as
614 // specified by the "mcal" argument. The definition of this "mcal" parameter
615 // corresponds to the signal correction mode described in the GetSignal
616 // memberfunction of class AliSignal.
617 // The default is mcal=1 (for backward compatibility reasons).
625 if (!hits) hits=fHits;
627 if (abs(mode)!=1 || !hits) return fOrdered;
629 Int_t nhits=hits->GetEntries();
636 fOrdered=new TObjArray(nhits);
639 Int_t idx=0; // The signal slotindex to perform the sorting on
642 for (Int_t i=0; i<nhits; i++) // loop over all hits of the array
644 AliSignal* s=(AliSignal*)hits->At(i);
648 // Obtain the slotindex corresponding to the user selection
649 idx=s->GetSlotIndex(name);
652 if (s->GetDeadValue(idx)) continue; // only take alive signals
654 if (nord == 0) // store the first hit with a signal at the first ordered position
657 fOrdered->AddAt(s,nord-1);
661 for (Int_t j=0; j<=nord; j++) // put hit in the right ordered position
663 if (j == nord) // module has smallest (mode=-1) or largest (mode=1) signal seen so far
666 fOrdered->AddAt(s,j); // add hit at the end
667 break; // go for next hit
670 if (mode==-1 && s->GetSignal(idx,mcal) <= ((AliSignal*)fOrdered->At(j))->GetSignal(idx,mcal)) continue;
671 if (mode==1 && s->GetSignal(idx,mcal) >= ((AliSignal*)fOrdered->At(j))->GetSignal(idx,mcal)) continue;
674 for (Int_t k=nord-1; k>j; k--) // create empty position
676 fOrdered->AddAt(fOrdered->At(k-1),k);
678 fOrdered->AddAt(s,j); // put hit at empty position
679 break; // go for next hit
684 ///////////////////////////////////////////////////////////////////////////
685 void AliDevice::DisplayHits(Int_t idx,Float_t scale,TObjArray* hits,Int_t dp,Int_t mode,Int_t mcol)
687 // 3D color display of an array hits.
688 // The user can specify the index (default=1) of the signal slot to perform the display for.
689 // The marker size will indicate the absolute value of the signal (specified by the slotindex)
690 // as a percentage of the input argument "scale".
691 // In case scale<0 the maximum absolute signal value encountered in the hit array will be used
692 // to define the 100% scale. The default is scale=-1.
693 // In case hits=0 (default), the registered hits of the current device are used.
694 // Note that the input array is not modified.
695 // In case dp=1 the device position will be used, otherwise the hit position will
696 // be used in the display. The default is dp=0.
697 // Via the "mcol" argument the user can specify the marker color (see TPolyMarker3D).
698 // The default is mcol=blue.
699 // Signals which were declared as "Dead" will not be displayed.
700 // The gain etc... corrected signals will be used to determine the marker size.
701 // The gain correction is performed according to "mode" argument. The definition of this
702 // "mode" parameter corresponds to the description provided in the GetSignal
703 // memberfunction of class AliSignal.
704 // The default is mode=1 (for backward compatibility reasons).
708 // Before any display activity, a TCanvas and a TView have to be initiated
709 // first by the user like for instance
711 // TCanvas* c1=new TCanvas("c1","c1");
712 // TView* view=new TView(1);
713 // view->SetRange(-1000,-1000,-1000,1000,1000,1000);
716 Int_t thisdev=0; // Indicate whether this is the owning device or not
723 if (idx<=0 || !hits) return;
725 Int_t nhits=hits->GetEntries();
728 Float_t sigmax=fabs(scale);
732 GetExtremes(vmin,vmax,idx,hits,mode);
734 if (fabs(vmin)>sigmax) sigmax=fabs(vmin);
737 if (sigmax <=0) return;
744 fMarkers=new TObjArray(nhits);
745 fMarkers->SetOwner();
748 GetPosition(pos,"car");
751 for (Int_t ih=0; ih<nhits; ih++)
753 AliSignal* sx=(AliSignal*)hits->At(ih);
757 sx->GetPosition(pos,"car");
763 AliDevice* dev=sx->GetDevice();
764 if (dev) dev->GetPosition(pos,"car");
767 sig=sx->GetSignal(idx,mode);
770 if (fabs(sig) <= 0.) continue;
772 TPolyMarker3D* m=new TPolyMarker3D();
773 m->SetMarkerStyle(8);
774 m->SetMarkerColor(mcol);
775 m->SetMarkerSize(100.*fabs(sig)/sigmax);
776 m->SetPoint(0,pos[0],pos[1],pos[2]);
781 ///////////////////////////////////////////////////////////////////////////
782 void AliDevice::DisplayHits(TString name,Float_t scale,TObjArray* hits,Int_t dp,Int_t mode,Int_t mcol)
784 // 3D color display of an array hits.
785 // The user can specify the name of the signal slot to perform the display for.
786 // The marker size will indicate the absolute value of the signal (specified by the slotname)
787 // as a percentage of the input argument "scale".
788 // In case scale<0 the maximum absolute signal value encountered in the hit array will be used
789 // to define the 100% scale. The default is scale=-1.
790 // In case hits=0 (default), the registered hits of the current device are used.
791 // Note that the input array is not modified.
792 // In case dp=1 the device position will be used, otherwise the hit position will
793 // be used in the display. The default is dp=0.
794 // The marker size will indicate the percentage of the maximum encountered value
795 // of the absolute value of the name-specified input signal slots.
796 // Via the "mcol" argument the user can specify the marker color (see TPolyMarker3D).
797 // The default is mcol=blue.
798 // Signals which were declared as "Dead" will not be displayed.
799 // The gain etc... corrected signals will be used to determine the marker size.
800 // The gain correction is performed according to "mode" argument. The definition of this
801 // "mode" parameter corresponds to the description provided in the GetSignal
802 // memberfunction of class AliSignal.
803 // The default is mode=1 (for backward compatibility reasons).
807 // Before any display activity, a TCanvas and a TView have to be initiated
808 // first by the user like for instance
810 // TCanvas* c1=new TCanvas("c1","c1");
811 // TView* view=new TView(1);
812 // view->SetRange(-1000,-1000,-1000,1000,1000,1000);
815 Int_t thisdev=0; // Indicate whether this is the owning device or not
824 Int_t nhits=hits->GetEntries();
828 Float_t sigmax=fabs(scale);
832 GetExtremes(vmin,vmax,name,hits,mode);
834 if (fabs(vmin)>sigmax) sigmax=fabs(vmin);
837 if (sigmax <=0) return;
844 fMarkers=new TObjArray(nhits);
845 fMarkers->SetOwner();
848 GetPosition(pos,"car");
850 Int_t idx=0; // The slot index corresponding to the user specified name
852 for (Int_t ih=0; ih<nhits; ih++)
854 AliSignal* sx=(AliSignal*)hits->At(ih);
856 idx=sx->GetSlotIndex(name);
860 sx->GetPosition(pos,"car");
866 AliDevice* dev=sx->GetDevice();
867 if (dev) dev->GetPosition(pos,"car");
870 sig=sx->GetSignal(idx,mode);
873 if (fabs(sig) <= 0.) continue;
875 TPolyMarker3D* m=new TPolyMarker3D();
876 m->SetMarkerStyle(8);
877 m->SetMarkerColor(mcol);
878 m->SetMarkerSize(100.*fabs(sig)/sigmax);
879 m->SetPoint(0,pos[0],pos[1],pos[2]);
884 ///////////////////////////////////////////////////////////////////////////
885 TObject* AliDevice::Clone(const char* name) const
887 // Make a deep copy of the current object and provide the pointer to the copy.
888 // This memberfunction enables automatic creation of new objects of the
889 // correct type depending on the object type, a feature which may be very useful
890 // for containers like AliEvent when adding objects in case the
891 // container owns the objects. This feature allows e.g. AliEvent
892 // to store either AliDevice objects or objects derived from AliDevice
893 // via tha AddDevice memberfunction, provided these derived classes also have
894 // a proper Clone memberfunction.
896 AliDevice* dev=new AliDevice(*this);
899 if (strlen(name)) dev->SetName(name);
903 ///////////////////////////////////////////////////////////////////////////