]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/MUON/AliHLTMUONRecHit.cxx
Fixes to trigger reconstruction component to handle real data better.
[u/mrichter/AliRoot.git] / HLT / MUON / AliHLTMUONRecHit.cxx
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
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 ///
28
29 #include "AliHLTMUONRecHit.h"
30 #include "AliLog.h"
31 #include "mapping/AliMpDEManager.h"
32 #include <cstring>
33 #include <iostream>
34 #include <iomanip>
35
36 ClassImp(AliHLTMUONRecHit);
37 ClassImp(AliHLTMUONRecHit::AliChannel);
38
39
40 std::ostream& operator << (std::ostream& stream, const AliHLTMUONRecHit& hit)
41 {
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'.
46
47         stream << "(" << hit.X() << ", " << hit.Y() << ", " << hit.Z() << ")";
48         return stream;
49 }
50
51
52 void AliHLTMUONRecHit::SetDebugInfo(
53                 Int_t detElemId, Int_t clusterId,
54                 UShort_t nChExpB, UShort_t nChExpNB,
55                 Float_t chargeB, Float_t chargeNB,
56                 Int_t sourceDDL
57         )
58 {
59 /// Sets the extra debugging information.
60 /// @param detElemId  The detector element ID.
61 /// @param clusterId  Cluster ID of the hit's cluster.
62 /// @param nChExpB    Number of expected channels in the bending plane forming the cluster.
63 /// @param nChExpNB   Number of expected channels in the non-bending plane forming the cluster.
64 /// @param chargeB    The charge of the cluster in the bending plane.
65 /// @param chargeNB   The charge of the cluster in the non-bending plane.
66 /// @param sourceDDL  The source DDL of this hit.
67
68         fSourceDDL = sourceDDL;
69         fDetElemId = detElemId;
70         fClusterId = clusterId;
71         fNchExpB = nChExpB;
72         fNchExpNB = nChExpNB;
73         fChargeB = chargeB;
74         fChargeNB = chargeNB;
75 }
76         
77
78 Int_t AliHLTMUONRecHit::Chamber(bool warn) const
79 {
80 /// Returns the chamber ID for this hit.
81 /// \param warn  Indicates if any warning should be printed in case of problems.
82 /// \returns The chamber number of this hit in the range [1..14] or -1 if not known.
83
84         if (fDetElemId != -1) return AliMpDEManager::GetChamberId(fDetElemId, warn);
85         
86         if (warn)
87         {
88                 AliWarning("Neither the DDL source nor the detector element ID was not set,"
89                         " so we do not know on which chamber this hit was reconstructed."
90                 );
91         }
92         return -1;
93 }
94
95
96 void AliHLTMUONRecHit::AddChannel(
97                 Short_t buspatch, Short_t manu, Short_t channel, Short_t signal,
98                 UInt_t rawDataWord
99         )
100 {
101 /// Adds a new channel to the channels list forming this hit's cluster.
102 /// @param buspatch  The bus patch ID of the channel.
103 /// @param manu    The MANU number
104 /// @param channel The MANU channel address.
105 /// @param signal  The ADC signal value measured on the channel.
106 /// @param rawDataWord This is the raw data word as read from the DDL.
107
108         Int_t index = fChannels.GetEntriesFast();
109         new (fChannels[index]) AliChannel(buspatch, manu, channel, signal, rawDataWord);
110 }
111
112
113 void AliHLTMUONRecHit::Print(Option_t* option) const
114 {
115 /// Prints the coordinates of this hit to standard output (screen).
116 /// \param option  Can be one of the following:
117 ///           - "compact" - prints in a compact format.
118 ///           - "detail" - prints hit information in a more detailed format.
119 ///           - "all" - prints a full dump of the hit object.
120
121         using namespace std;
122
123         if (    option == NULL or strcmp(option, "") == 0 or
124                 strcmp(option, "compact") == 0
125            )
126         {
127                 cout << *this << endl;
128         }
129         else if (strcmp(option, "detail") == 0)
130         {
131                 cout << "(x = " << X() << " cm, y = " << Y()
132                         << " cm, z = " << Z()
133                         << " cm); source DDL = " << fSourceDDL
134                         << "; DetElemID = " << fDetElemId
135                         << "; cluster ID = " << fClusterId
136                         << "; total charge = " << fChargeB + fChargeNB
137                         << "; expected #ch = " << fNchExpB + fNchExpNB << endl;
138         }
139         else if (strcmp(option, "all") == 0)
140         {
141                 streamsize w = cout.width();
142                 ios::fmtflags f = cout.flags();
143                 cout << "RecHit: (x = " << X() << " cm, y = " << Y()
144                         << " cm, z = " << Z()
145                         << " cm); source DDL = " << fSourceDDL
146                         << "; DetElemID = " << fDetElemId
147                         << "; cluster ID = " << fClusterId
148                         << endl;
149                 cout << setw(0) << "              Plane:" << setw(14) << "Bending" << setw(14) << "Non-bending" << endl;
150                 cout << setw(0) << "             Charge:" << setw(14) << fChargeB << setw(14) << fChargeNB << endl;
151                 cout << setw(0) << "Expected channels #:" << setw(14) << fNchExpB << setw(14) << fNchExpNB << setw(0) << endl;
152                 if (fChannels.GetEntriesFast() == 0)
153                 {
154                         cout << "No channels found for this hit." << endl;
155                 }
156                 else
157                 {
158                         cout << setw(12) << "MANU"
159                                 << setw(12) << "Channel"
160                                 << setw(12) << "Signal"
161                                 << setw(15) << "Raw data word" << endl;
162                         cout << showbase;
163                         for (Int_t i = 0; i < fChannels.GetEntriesFast(); i++)
164                         {
165                                 const AliHLTMUONRecHit::AliChannel* c =
166                                         static_cast<const AliHLTMUONRecHit::AliChannel*>(fChannels[i]);
167                                 cout << dec << setw(12) << c->Manu()
168                                         << setw(12) << c->Address()
169                                         << setw(12) << c->Signal()
170                                         << "     " << hex << setw(10) << internal;
171                                 ios::char_type fc = cout.fill('0');
172                                 cout << c->RawDataWord() << right << endl;
173                                 cout.fill(fc);
174                         }
175                 }
176                 cout.width(w); // reset the field width to previous value.
177                 cout.flags(f); // reset the flags to previous values.
178         }
179         else
180         {
181                 AliError("Unknown option specified. Can only be one of 'compact',"
182                         " 'detail' or 'all'."
183                 );
184         }
185 }
186
187
188 Int_t AliHLTMUONRecHit::Compare(const TObject* obj) const
189 {
190 /// We compare this object with 'obj' first by X, then Y, then Z.
191 /// \param obj  This is the object to compare to. It must be of type AliHLTMUONRecHit.
192 /// \returns  -1 if 'this' is smaller than 'obj', 1 if greater and zero if both
193 ///      objects are the same.
194
195         if (obj->IsA() == AliHLTMUONRecHit::Class())
196         {
197                 const AliHLTMUONRecHit* h = static_cast<const AliHLTMUONRecHit*>(obj);
198                 if (X() < h->X()) return -1;
199                 if (X() > h->X()) return 1;
200                 if (Y() < h->Y()) return -1;
201                 if (Y() > h->Y()) return 1;
202                 if (Z() < h->Z()) return -1;
203                 if (Z() > h->Z()) return 1;
204                 return 0;
205         }
206         else
207         {
208                 AliError(Form("Do not know how to compare %s to %s.",
209                         this->ClassName(),
210                         obj->ClassName()
211                 ));
212                 return -999;
213         }
214 }
215
216
217 std::ostream& operator << (std::ostream& stream, const AliHLTMUONRecHit::AliChannel& c)
218 {
219 /// Stream operator for std::ostream classes.
220 /// \param stream  The output stream object being written to.
221 /// \param c  The channel object to print to the stream.
222 /// \returns  Returns 'stream'.
223
224         stream << "Channel: " << c.fManu << " , " << c.fAddress
225                 << "; ADC: " << c.fSignal;
226         return stream;
227 }
228
229
230 void AliHLTMUONRecHit::AliChannel::Print(Option_t* option) const
231 {
232 /// Prints the details of this channel to standard output (screen).
233 /// \param option  Can be one of the following:
234 ///           - "compact" - prints in a compact format.
235 ///           - "detail" - prints channel information in a more detailed format.
236
237         using namespace std;
238         
239         if (    option == NULL or strcmp(option, "") == 0 or
240                 strcmp(option, "compact") == 0
241            )
242         {
243                 cout << *this << endl;
244         }
245         else if (strcmp(option, "detail") == 0)
246         {
247                 streamsize w = cout.width();
248                 ios::fmtflags f = cout.flags();
249                 cout << "MANU = " << fManu << ", Channel address = " << fAddress
250                         << ", Signal = " << fSignal
251                         << "; Raw data word = " << hex << setw(10) << internal;
252                 ios::char_type fc = cout.fill('0');
253                 cout << fRawDataWord << endl;
254                 cout.fill(fc); // reset fill character
255                 cout.width(w); // reset the field width to previous value.
256                 cout.flags(f); // reset the flags to previous values.
257         }
258         else
259         {
260                 AliError("Unknown option specified. Can only be one of"
261                         " 'compact' or 'detail'."
262                 );
263         }
264 }
265
266
267 Int_t AliHLTMUONRecHit::AliChannel::Compare(const TObject* obj) const
268 {
269 /// We compare this object with 'obj' first by MANU number, then by MANU channel
270 /// address, then ADC signal.
271 /// \param obj  This is the object to compare to. It must be of type AliHLTMUONRecHit::Channel.
272 /// \returns  -1 if 'this' is smaller than 'obj', 1 if greater and zero if both
273 ///      objects are the same.
274
275         if (obj->IsA() == AliChannel::Class())
276         {
277                 const AliChannel* c = static_cast<const AliChannel*>(obj);
278                 if (fManu < c->Manu()) return -1;
279                 if (fManu > c->Manu()) return 1;
280                 if (fAddress < c->Address()) return -1;
281                 if (fAddress > c->Address()) return 1;
282                 if (fSignal < c->Signal()) return -1;
283                 if (fSignal > c->Signal()) return 1;
284                 return 0;
285         }
286         else
287         {
288                 AliError(Form("Do not know how to compare %s to %s.",
289                         this->ClassName(),
290                         obj->ClassName()
291                 ));
292                 return -999;
293         }
294 }