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