]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONSDigitizerV2.cxx
Fixes for memory leaks (Christian)
[u/mrichter/AliRoot.git] / MUON / AliMUONSDigitizerV2.cxx
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 #include <TClonesArray.h>
19
20 #include "AliMUONSDigitizerV2.h"
21
22 #include "AliLog.h"
23 #include "AliMUON.h"
24 #include "AliMUONChamber.h"
25 #include "AliMUONVDigit.h"
26 #include "AliMUONHit.h"
27 #include "AliMpDEManager.h"
28 #include "AliMpCDB.h"
29 #include "AliLoader.h"
30 #include "AliRun.h"
31 #include "AliRunLoader.h"
32 #include "AliMUONVDigitStore.h"
33 #include "AliMUONVHitStore.h"
34
35 #include "AliCDBManager.h"
36 #include "AliMUONCalibrationData.h"
37 #include "AliMUONResponseTrigger.h"
38
39 //-----------------------------------------------------------------------------
40 /// The sdigitizer performs the transformation from hits (energy deposits by
41 /// the transport code) to sdigits (equivalent of charges on pad).
42 ///
43 /// It does so by converting the energy deposit into a charge and then spreading
44 /// this charge over several pads, according to the response function (a 
45 /// Mathieson distribution, basically).
46 /// 
47 /// See also AliMUONResponseV0, which is doing the real job (in DisIntegrate
48 /// method), while this sdigitizer is just "steering" the process.
49 ///
50 /// Please note that we do *not* merge sdigits after creation, which means
51 /// that after sdigitization, a given pad can have several sdigits. This
52 /// merging is taken care of later on by the digitizer(V3).
53 //-----------------------------------------------------------------------------
54
55 ClassImp(AliMUONSDigitizerV2)
56
57 //_____________________________________________________________________________
58 AliMUONSDigitizerV2::AliMUONSDigitizerV2() 
59 : TTask("AliMUONSDigitizerV2","From Hits to SDigits for MUON")
60 {
61   ///
62   /// ctor.
63   ///
64   if ( ! AliMpCDB::LoadMpSegmentation() ) 
65   {
66     AliFatal("Could not access mapping from OCDB !");
67   }
68 }
69
70 //_____________________________________________________________________________
71 AliMUONSDigitizerV2::~AliMUONSDigitizerV2()
72 {
73   ///
74   /// dtor.
75   ///
76 }
77
78 //_____________________________________________________________________________
79 void
80 AliMUONSDigitizerV2::Exec(Option_t*)
81 {
82   ///
83   /// Go from hits to sdigits.
84   ///
85   /// In the code below, apart from the loop itself (which look complicated
86   /// but is really only a loop on each hit in the input file) the main
87   /// work is done in AliMUONResponse::DisIntegrate method, which converts
88   /// a single hit in (possibly) several sdigits.
89   ///
90   
91   AliDebug(1,"");
92   
93   AliRunLoader* runLoader = AliRunLoader::GetRunLoader();
94   AliLoader* loader = runLoader->GetDetectorLoader("MUON");
95
96   loader->LoadHits("READ");
97   
98   AliMUON* muon = static_cast<AliMUON*>(gAlice->GetModule("MUON"));
99
100   AliMUONCalibrationData *calibrationData = 0x0;
101
102   if(muon->GetTriggerEffCells()){
103     Int_t runnumber = AliCDBManager::Instance()->GetRun();
104     calibrationData = new AliMUONCalibrationData(runnumber);
105     for (Int_t chamber = 10; chamber < 14; chamber++) {
106       ((AliMUONResponseTrigger *) (muon->Chamber(chamber).ResponseModel()))->InitTriggerEfficiency(calibrationData->TriggerEfficiency()); // Init trigger efficiency
107     }
108   }
109   
110   Int_t nofEvents(runLoader->GetNumberOfEvents());
111   
112   TString classname = muon->DigitStoreClassName();
113   
114   AliMUONVDigitStore* sDigitStore = AliMUONVDigitStore::Create(classname.Data());
115   
116   if (!sDigitStore)
117   {
118     AliFatal(Form("Could not create digitstore of class %s",classname.Data()));
119   }
120   
121   AliInfo(Form("Will use digitStore of type %s",sDigitStore->ClassName()));
122           
123   for ( Int_t iEvent = 0; iEvent < nofEvents; ++iEvent ) 
124   {    
125     // Loop over events.
126     TObjArray tdlist;
127     tdlist.SetOwner(kTRUE);
128     
129     AliDebug(1,Form("iEvent=%d",iEvent));
130     runLoader->GetEvent(iEvent);
131   
132     loader->MakeSDigitsContainer();
133
134     TTree* treeS = loader->TreeS();
135
136     if ( !treeS )
137     {
138       AliFatal("");
139     }
140
141     sDigitStore->Connect(*treeS);
142     
143     TTree* treeH = loader->TreeH();
144
145     AliMUONVHitStore* hitStore = AliMUONVHitStore::Create(*treeH);
146     hitStore->Connect(*treeH);
147     
148     Long64_t nofTracks = treeH->GetEntries();
149     
150     for ( Long64_t iTrack = 0; iTrack < nofTracks; ++iTrack )
151     {
152       // Loop over the tracks of this event.
153       treeH->GetEvent(iTrack);
154
155       AliMUONHit* hit;
156       TIter next(hitStore->CreateIterator());
157       Int_t ihit(0);
158       
159       while ( ( hit = static_cast<AliMUONHit*>(next()) ) )       
160       {
161         Int_t chamberId = hit->Chamber()-1;
162         AliMUONChamber& chamber = muon->Chamber(chamberId);
163         AliMUONResponse* response = chamber.ResponseModel();
164         
165         // This is the heart of this method : the dis-integration
166         TList digits;        
167         response->DisIntegrate(*hit,digits);
168         
169         TIter next(&digits);
170         AliMUONVDigit* d;
171         while ( ( d = (AliMUONVDigit*)next() ) )
172         {
173           // Update some sdigit information that could not be known
174           // by the DisIntegrate method
175           d->SetHit(ihit);
176           d->AddTrack(iTrack,d->Charge());
177           tdlist.Add(d);
178         }
179         ++ihit;
180       }
181       hitStore->Clear();
182     } // end of loop on tracks within an event
183     
184     TIter next(&tdlist);
185     AliMUONVDigit* d;
186     
187     while ( ( d = static_cast<AliMUONVDigit*>(next()) ) )
188     {
189       if ( d->Charge() > 0 ) // that check would be better in the disintegrate
190         // method, but to compare with old sdigitizer, it has to be there.
191       {
192         AliMUONVDigit* added = sDigitStore->Add(*d,AliMUONVDigitStore::kMerge);
193         if (!added)
194         {
195           AliError("Could not add digit to digitStore");
196         }
197       }
198     }
199
200     treeS->Fill();
201     
202     loader->WriteSDigits("OVERWRITE");
203     
204     sDigitStore->Clear();
205     
206     loader->UnloadSDigits();
207     
208     delete hitStore;
209     
210   } // loop on events
211   
212   loader->UnloadHits();  
213   
214   delete sDigitStore;
215
216   if(calibrationData) delete calibrationData;
217 }