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