ALIROOT-5433 Transition to CDHv3 in HLT
[u/mrichter/AliRoot.git] / HLT / MUON / AliHLTMUONEvent.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   AliHLTMUONEvent.cxx
21 /// @author Artur Szostak <artursz@iafrica.com>
22 /// @date   29 Sep 2007
23 /// @brief  Implementation of the AliHLTMUONEvent class.
24 ///
25 /// The class is used to store all ROOTified data objects from the dHLT chain
26 /// for a single event together.
27
28 #include "AliHLTMUONEvent.h"
29 #include "AliHLTMUONRecHit.h"
30 #include "AliHLTMUONTriggerRecord.h"
31 #include "AliHLTMUONMansoTrack.h"
32 #include "AliHLTMUONTrack.h"
33 #include "AliHLTMUONDecision.h"
34 #include "AliLog.h"
35 #include <iostream>
36 #include <map>
37
38 ClassImp(AliHLTMUONEvent);
39
40
41 AliHLTMUONEvent::AliHLTMUONEvent(const AliHLTMUONEvent& event) :
42         TObject(event),
43         fEventId(event.fEventId),
44         fArray()
45 {
46         /// Copy constructor performs a deep copy of the object.
47         
48         fArray.SetOwner(kTRUE);
49         DeepCopy(event);
50 }
51
52
53 AliHLTMUONEvent& AliHLTMUONEvent::operator = (const AliHLTMUONEvent& event)
54 {
55         /// The assignment operator performs a deep copy of the object.
56         
57         if (this == &event) return *this;
58         fArray.Clear();
59         TObject::operator = (event);
60         DeepCopy(event);
61         return *this;
62 }
63
64
65 const AliHLTMUONDecision* AliHLTMUONEvent::FindDecision() const
66 {
67         /// Finds the decision object in the event from the list of dHLT objects.
68         /// There should only be one such object in the event. If not, then only
69         /// the first object found is returned. You will need to manually search
70         /// for the other objects.
71         /// \returns  The AliHLTMUONDecision object in the event or NULL if none exists.
72         
73         for (Int_t i = 0; i < fArray.GetEntriesFast(); i++)
74         {
75                 if (fArray[i]->IsA() == AliHLTMUONDecision::Class())
76                 {
77                         return static_cast<const AliHLTMUONDecision*>(fArray[i]);
78                 }
79         }
80         
81         return NULL;
82 }
83
84
85 void AliHLTMUONEvent::Print(Option_t* option) const
86 {
87         ///
88         /// Inherited from TObject. Prints the contents of the event objects in fArray.
89         /// \param option  This is an option string that is just passed on to individual
90         ///     objects in the event's fArray list of objects.
91         ///
92         
93         std::cout << "################## EVENT: " << fEventId << " ##################" << std::endl;
94         for (Int_t i = 0; i < fArray.GetEntriesFast(); i++)
95                 if (fArray[i] != NULL) fArray[i]->Print(option);
96 }
97
98
99 void AliHLTMUONEvent::Clear(Option_t* option)
100 {
101         /// Clears the internal array of event objects.
102         
103         fEventId = AliHLTEventID_t(-1);
104         fArray.Clear(option);
105 }
106
107
108 void AliHLTMUONEvent::Copy(TObject& object) const
109 {
110         /// Deep copy this object to the target object.
111         /// \param object  The target object to copy to.
112         
113         if (object.IsA() != this->IsA())
114         {
115                 AliError(Form("Cannot copy an object of type %s to a type of %s.",
116                         this->ClassName(), object.ClassName()
117                 ));
118                 return;
119         }
120         
121         TObject::Copy(object);
122         AliHLTMUONEvent& event = static_cast<AliHLTMUONEvent&>(object);
123         event.DeepCopy(*this);
124 }
125
126
127 void AliHLTMUONEvent::DeepCopy(const AliHLTMUONEvent& event)
128 {
129         /// Performs a deep copy of the event.
130         
131         fEventId = event.fEventId;
132         TObjArray tocopy = event.fArray;
133         std::map<const TObject*, TObject*> objmap;
134         
135         // We need to copy all the objects from the old event while maintaining the
136         // pointer cross references contained in the track and decision objects:
137         // Start by looping over all objects and first copy the trigger records and hits.
138         TIter next(&tocopy);
139         TObject* obj = NULL;
140         while ( (obj = next()) != NULL )
141         {
142                 if (obj->IsA() == AliHLTMUONTriggerRecord::Class() or
143                     obj->IsA() == AliHLTMUONRecHit::Class()
144                    )
145                 {
146                         TObject* newobj = obj->Clone();
147                         objmap[obj] = newobj;
148                         fArray.Add(newobj);
149                         tocopy.Remove(obj);
150                 }
151         }
152         
153         // Now loop over all objects that still need to be copied and copy the tracks.
154         next.Reset();
155         while ( (obj = next()) != NULL )
156         {
157                 if (obj->IsA() == AliHLTMUONMansoTrack::Class())
158                 {
159                         AliHLTMUONMansoTrack* track = static_cast<AliHLTMUONMansoTrack*>(obj);
160                         AliHLTMUONMansoTrack* newtrack = new AliHLTMUONMansoTrack(
161                                 track->Id(), track->Sign(),
162                                 track->Px(), track->Py(), track->Pz(),
163                                 track->Chi2(),
164                                 static_cast<const AliHLTMUONTriggerRecord*>( objmap[track->TriggerRecord()] ),
165                                 static_cast<const AliHLTMUONRecHit*>( objmap[track->Hit(7)] ),
166                                 static_cast<const AliHLTMUONRecHit*>( objmap[track->Hit(8)] ),
167                                 static_cast<const AliHLTMUONRecHit*>( objmap[track->Hit(9)] ),
168                                 static_cast<const AliHLTMUONRecHit*>( objmap[track->Hit(10)] ),
169                                 track->Zmiddle(), track->QBL()
170                         );
171                         for (int i = 7; i <= 10; ++i)
172                         {
173                                 const TVector3& b = track->RoICentre(i);
174                                 newtrack->SetRoI(i, b.X(), b.Y(), b.Z(), track->RoIRadius(i));
175                         }
176                         objmap[obj] = newtrack;
177                         fArray.Add(newtrack);
178                         tocopy.Remove(obj);
179                 }
180                 else if (obj->IsA() == AliHLTMUONTrack::Class())
181                 {
182                         AliHLTMUONTrack* track = static_cast<AliHLTMUONTrack*>(obj);
183                         
184                         const AliHLTMUONRecHit* newhits[16];
185                         for (int i = 0; i < 16; ++i)
186                         {
187                                 newhits[i] = static_cast<const AliHLTMUONRecHit*>( objmap[track->Hit(i)] );
188                         }
189                         AliHLTMUONTrack* newtrack = new AliHLTMUONTrack(
190                                 track->Id(), track->Sign(),
191                                 track->Px(), track->Py(), track->Pz(),
192                                 track->InverseBendingMomentum(),
193                                 track->ThetaX(), track->ThetaY(),
194                                 track->X(), track->Y(), track->Z(),
195                                 track->Chi2(),
196                                 static_cast<const AliHLTMUONTriggerRecord*>( objmap[track->TriggerRecord()] ),
197                                 newhits
198                         );
199                         objmap[obj] = newtrack;
200                         fArray.Add(newtrack);
201                         tocopy.Remove(obj);
202                 }
203         }
204         
205         // Finally copy over the decision objects.
206         next.Reset();
207         while ( (obj = next()) != NULL )
208         {
209                 if (obj->IsA() == AliHLTMUONDecision::Class())
210                 {
211                         AliHLTMUONDecision* dec = static_cast<AliHLTMUONDecision*>(obj);
212                         AliHLTMUONDecision* newdec = new AliHLTMUONDecision(
213                                 dec->NumberOfLowPtTriggers(),
214                                 dec->NumberOfHighPtTriggers(),
215                                 dec->NumberOfUnlikePairs(),
216                                 dec->NumberOfUnlikeLowPtPairs(),
217                                 dec->NumberOfUnlikeHighPtPairs(),
218                                 dec->NumberOfLikePairs(),
219                                 dec->NumberOfLikeLowPtPairs(),
220                                 dec->NumberOfLikeHighPtPairs(),
221                                 dec->NumberOfMassTriggers(),
222                                 dec->NumberOfLowMassTriggers(),
223                                 dec->NumberOfHighMassTriggers()
224                         );
225                         for (Int_t i = 0; i < dec->NumberOfTracks(); ++i)
226                         {
227                                 const AliHLTMUONDecision::AliTrackDecision* d = dec->SingleTrackDecision(i);
228                                 newdec->AddDecision(
229                                         d->Pt(), d->PassedLowPtCut(), d->PassedHighPtCut(),
230                                         objmap[d->Track()]
231                                 );
232                         }
233                         for (Int_t i = 0; i < dec->NumberOfPairs(); ++i)
234                         {
235                                 const AliHLTMUONDecision::AliPairDecision* d = dec->TrackPairDecision(i);
236                                 newdec->AddDecision(
237                                         d->Mass(), d->PassedLowMassCut(),
238                                         d->PassedHighMassCut(), d->UnlikeSign(),
239                                         d->NumberPassedLowPtCut(), d->NumberPassedHighPtCut(),
240                                         objmap[d->TrackA()], objmap[d->TrackB()]
241                                 );
242                         }
243                         objmap[obj] = newdec;
244                         fArray.Add(newdec);
245                         tocopy.Remove(obj);
246                 }
247         }
248         
249         // Copy all the remaining objects that we do not handle in a special way.
250         next.Reset();
251         while ( (obj = next()) != NULL )
252         {
253                 fArray.Add(obj->Clone());
254         }
255 }