Added missing files
[u/mrichter/AliRoot.git] / HLT / MUON / AliHLTMUONRecHit.cxx
CommitLineData
753896cd 1/**************************************************************************
2 * This file is property of and copyright by the ALICE HLT Project *
3 * All rights reserved. *
4 * *
5 * Primary Authors: *
6 * Artur Szostak <artursz@iafrica.com> *
7 * *
8 * Permission to use, copy, modify and distribute this software and its *
9 * documentation strictly for non-commercial purposes is hereby granted *
10 * without fee, provided that the above copyright notice appears in all *
11 * copies and that both the copyright notice and this permission notice *
12 * appear in the supporting documentation. The authors make no claims *
13 * about the suitability of this software for any purpose. It is *
14 * provided "as is" without express or implied warranty. *
15 **************************************************************************/
16
17/* $Id$ */
18
450e0b36 19///
20/// @file AliHLTMUONRecHit.cxx
21/// @author Artur Szostak <artursz@iafrica.com>
22/// @date 29 Sep 2007
23/// @brief Implementation of the AliHLTMUONRecHit class.
24///
25/// The AliHLTMUONRecHit object is used to store 3D hit coordinates translated
26/// from dHLT raw data.
27///
753896cd 28
29#include "AliHLTMUONRecHit.h"
30#include "AliLog.h"
31#include "mapping/AliMpDEManager.h"
32#include <cstring>
33#include <iostream>
34#include <iomanip>
753896cd 35
36ClassImp(AliHLTMUONRecHit);
450e0b36 37ClassImp(AliHLTMUONRecHit::AliChannel);
753896cd 38
39
40std::ostream& operator << (std::ostream& stream, const AliHLTMUONRecHit& hit)
41{
450e0b36 42/// Stream operator for std::ostream classes.
43/// \param stream The output stream object being written to.
44/// \param track The hit object to print to the stream.
45/// \returns Returns 'stream'.
753896cd 46
47 stream << "(" << hit.X() << ", " << hit.Y() << ", " << hit.Z() << ")";
48 return stream;
49}
50
51
52void AliHLTMUONRecHit::SetDebugInfo(
83d66053 53 Int_t detElemId, Int_t clusterId, UInt_t nChExp,
54 Float_t charge, Int_t sourceDDL
753896cd 55 )
56{
450e0b36 57/// Sets the debugging information.
58/// @param detElemId The detector element ID.
59/// @param clusterId Cluster ID of the hit's cluster.
60/// @param nChExp Number of expected channels forming the cluster.
83d66053 61/// @param charge The total charge of the cluster.
450e0b36 62/// @param sourceDDL The source DDL of this hit.
753896cd 63
64 fSourceDDL = sourceDDL;
65 fDetElemId = detElemId;
66 fClusterId = clusterId;
67 fNchExp = nChExp;
83d66053 68 fCharge = charge;
753896cd 69}
70
71
72Int_t AliHLTMUONRecHit::Chamber(bool warn) const
73{
450e0b36 74/// Returns the chamber ID for this hit.
75/// \param warn Indicates if any warning should be printed in case of problems.
76/// \returns The chamber number of this hit in the range [1..14] or -1 if not known.
753896cd 77
753896cd 78 if (fDetElemId != -1) return AliMpDEManager::GetChamberId(fDetElemId, warn);
79
80 if (warn)
81 {
82 AliWarning("Neither the DDL source nor the detector element ID was not set,"
83 " so we do not know on which chamber this hit was reconstructed."
84 );
85 }
86 return -1;
87}
88
89
90void AliHLTMUONRecHit::AddChannel(
91 Short_t manu, Short_t channel, Short_t signal,
92 UInt_t rawDataWord
93 )
94{
450e0b36 95/// Adds a new channel to the channels list forming this hit's cluster.
96/// @param manu The MANU number
97/// @param channel The MANU channel address.
98/// @param signal The ADC signal value measured on the channel.
99/// @param rawDataWord This is the raw data word as read from the DDL.
753896cd 100
101 Int_t index = fChannels.GetEntriesFast();
450e0b36 102 new (fChannels[index]) AliChannel(manu, channel, signal, rawDataWord);
753896cd 103}
104
105
106void AliHLTMUONRecHit::Print(Option_t* option) const
107{
450e0b36 108/// Prints the coordinates of this hit to standard output (screen).
109/// \param option Can be one of the following:
110/// - "compact" - prints in a compact format.
111/// - "detail" - prints hit information in a more detailed format.
112/// - "all" - prints a full dump of the hit object.
113
114 using namespace std;
753896cd 115
116 if ( option == NULL or strcmp(option, "") == 0 or
117 strcmp(option, "compact") == 0
118 )
119 {
120 cout << *this << endl;
121 }
122 else if (strcmp(option, "detail") == 0)
123 {
124 cout << "(x = " << X() << " cm, y = " << Y()
125 << " cm, z = " << Z()
126 << " cm); source DDL = " << fSourceDDL
127 << "; DetElemID = " << fDetElemId
128 << "; cluster ID = " << fClusterId
83d66053 129 << "; total charge = " << fCharge
753896cd 130 << "; expected #ch = " << fNchExp << endl;
131 }
132 else if (strcmp(option, "all") == 0)
133 {
134 cout << "(x = " << X() << " cm, y = " << Y()
135 << " cm, z = " << Z()
136 << " cm); source DDL = " << fSourceDDL
137 << "; DetElemID = " << fDetElemId
138 << "; cluster ID = " << fClusterId
83d66053 139 << "; total charge = " << fCharge
753896cd 140 << "; expected #ch = " << fNchExp << endl;
141 if (fChannels.GetEntriesFast() == 0)
142 {
143 cout << "No channels found for this hit." << endl;
144 }
145 else
146 {
147 streamsize w = cout.width();
148 ios::fmtflags f = cout.flags();
149 cout << setw(12) << "MANU"
150 << setw(12) << "Channel"
151 << setw(12) << "Signal"
152 << setw(15) << "Raw data word" << endl;
153 cout << showbase;
154 for (Int_t i = 0; i < fChannels.GetEntriesFast(); i++)
155 {
450e0b36 156 const AliHLTMUONRecHit::AliChannel* c =
157 static_cast<const AliHLTMUONRecHit::AliChannel*>(fChannels[i]);
753896cd 158 cout << dec << setw(12) << c->Manu()
159 << setw(12) << c->Address()
160 << setw(12) << c->Signal()
161 << " " << hex << setw(10) << internal;
162 ios::char_type fc = cout.fill('0');
163 cout << c->RawDataWord() << right << endl;
164 cout.fill(fc);
165 }
166 cout.width(w); // reset the field width to previous value.
167 cout.flags(f); // reset the flags to previous values.
168 }
169 }
170 else
171 {
172 AliError("Unknown option specified. Can only be one of 'compact',"
173 " 'detail' or 'all'."
174 );
175 }
176}
177
178
179Int_t AliHLTMUONRecHit::Compare(const TObject* obj) const
180{
450e0b36 181/// We compare this object with 'obj' first by X, then Y, then Z.
182/// \param obj This is the object to compare to. It must be of type AliHLTMUONRecHit.
183/// \returns -1 if 'this' is smaller than 'obj', 1 if greater and zero if both
184/// objects are the same.
753896cd 185
186 if (obj->IsA() == AliHLTMUONRecHit::Class())
187 {
188 const AliHLTMUONRecHit* h = static_cast<const AliHLTMUONRecHit*>(obj);
189 if (X() < h->X()) return -1;
190 if (X() > h->X()) return 1;
191 if (Y() < h->Y()) return -1;
192 if (Y() > h->Y()) return 1;
193 if (Z() < h->Z()) return -1;
194 if (Z() > h->Z()) return 1;
195 return 0;
196 }
197 else
198 {
199 AliError(Form("Do not know how to compare %s to %s.",
200 this->ClassName(),
201 obj->ClassName()
202 ));
203 return -999;
204 }
205}
206
207
450e0b36 208std::ostream& operator << (std::ostream& stream, const AliHLTMUONRecHit::AliChannel& c)
753896cd 209{
450e0b36 210/// Stream operator for std::ostream classes.
211/// \param stream The output stream object being written to.
212/// \param c The channel object to print to the stream.
213/// \returns Returns 'stream'.
753896cd 214
215 stream << "Channel: " << c.fManu << " , " << c.fAddress
216 << "; ADC: " << c.fSignal;
217 return stream;
218}
219
220
450e0b36 221void AliHLTMUONRecHit::AliChannel::Print(Option_t* option) const
753896cd 222{
450e0b36 223/// Prints the details of this channel to standard output (screen).
224/// \param option Can be one of the following:
225/// - "compact" - prints in a compact format.
226/// - "detail" - prints channel information in a more detailed format.
753896cd 227
450e0b36 228 using namespace std;
229
753896cd 230 if ( option == NULL or strcmp(option, "") == 0 or
231 strcmp(option, "compact") == 0
232 )
233 {
234 cout << *this << endl;
235 }
236 else if (strcmp(option, "detail") == 0)
237 {
238 streamsize w = cout.width();
239 ios::fmtflags f = cout.flags();
240 cout << "MANU = " << fManu << ", Channel address = " << fAddress
241 << ", Signal = " << fSignal
242 << "; Raw data word = " << hex << setw(10) << internal;
243 ios::char_type fc = cout.fill('0');
244 cout << fRawDataWord << endl;
245 cout.fill(fc); // reset fill character
246 cout.width(w); // reset the field width to previous value.
247 cout.flags(f); // reset the flags to previous values.
248 }
249 else
250 {
251 AliError("Unknown option specified. Can only be one of"
252 " 'compact' or 'detail'."
253 );
254 }
255}
256
257
450e0b36 258Int_t AliHLTMUONRecHit::AliChannel::Compare(const TObject* obj) const
753896cd 259{
450e0b36 260/// We compare this object with 'obj' first by MANU number, then by MANU channel
261/// address, then ADC signal.
262/// \param obj This is the object to compare to. It must be of type AliHLTMUONRecHit::Channel.
263/// \returns -1 if 'this' is smaller than 'obj', 1 if greater and zero if both
264/// objects are the same.
753896cd 265
450e0b36 266 if (obj->IsA() == AliChannel::Class())
753896cd 267 {
450e0b36 268 const AliChannel* c = static_cast<const AliChannel*>(obj);
753896cd 269 if (fManu < c->Manu()) return -1;
270 if (fManu > c->Manu()) return 1;
271 if (fAddress < c->Address()) return -1;
272 if (fAddress > c->Address()) return 1;
273 if (fSignal < c->Signal()) return -1;
274 if (fSignal > c->Signal()) return 1;
275 return 0;
276 }
277 else
278 {
279 AliError(Form("Do not know how to compare %s to %s.",
280 this->ClassName(),
281 obj->ClassName()
282 ));
283 return -999;
284 }
285}