]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUON.cxx
Add scaler event for trigger, copy data blockwise in buffers
[u/mrichter/AliRoot.git] / MUON / AliMUON.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
19 ///////////////////////////////////////////////
20 //  Manager and hits classes for set:MUON     //
21 ////////////////////////////////////////////////
22
23 #include "Riostream.h"
24
25 #include <AliPDG.h>
26 #include <TBRIK.h>
27 #include <TCanvas.h>
28 #include <TDirectory.h>
29 #include <TFile.h>
30 #include <TGeometry.h>
31 #include <TMinuit.h>
32 #include <TNode.h> 
33 #include <TNtuple.h>
34 #include <TObjArray.h>
35 #include <TObject.h>
36 #include <TObjectTable.h>
37 #include <TPad.h>
38 #include <TParticle.h>
39 #include <TROOT.h>
40 #include <TRandom.h> 
41 #include <TRotMatrix.h>
42 #include <TTUBE.h>
43 #include <TTUBE.h>
44 #include <TTree.h> 
45 #include <TVector.h>
46 #include <TVirtualMC.h>
47
48 //#include "AliHeader.h"
49 #include "AliLoader.h"
50 #include "AliRunDigitizer.h"
51 #include "AliMC.h"
52 #include "AliRun.h"     
53 #include "AliMUON.h"
54 #include "AliMUONChamberTrigger.h"
55 #include "AliMUONConstants.h"
56 #include "AliMUONHit.h" 
57 #include "AliMUONRawCluster.h"
58 #include "AliMUONTransientDigit.h"
59 #include "AliMUONTriggerCircuit.h"
60 #include "AliMUONGeometry.h"
61 #include "AliMUONGeometryTransformer.h"
62 #include "AliMUONGeometryBuilder.h"
63 #include "AliMUONCommonGeometryBuilder.h"
64 #include "AliMUONVGeometryBuilder.h"    
65 #include "AliMUONGeometrySegmentation.h"
66 #include "AliMUONDigitizerv2.h"
67 #include "AliMUONSDigitizerv1.h"
68 #include "AliMUONRawWriter.h"
69 #include "AliMUONSegmentation.h"
70 #include "AliLog.h"
71
72 // Defaults parameters for Z positions of chambers
73 // taken from values for "stations" in AliMUON::AliMUON
74 //     const Float_t zch[7]={528, 690., 975., 1249., 1449., 1610, 1710.};
75 // and from array "dstation" in AliMUONv1::CreateGeometry
76 //          Float_t dstation[5]={20., 20., 20, 20., 20.};
77 //     for tracking chambers,
78 //          according to (Z1 = zch - dstation) and  (Z2 = zch + dstation)
79 //          for the first and second chambers in the station, respectively,
80 // and from "DTPLANES" in AliMUONv1::CreateGeometry
81 //           const Float_t DTPLANES = 15.;
82 //     for trigger chambers,
83 //          according to (Z1 = zch) and  (Z2 = zch + DTPLANES)
84 //          for the first and second chambers in the station, respectively
85
86 ClassImp(AliMUON)
87
88 //__________________________________________________________________
89 AliMUON::AliMUON()
90   : AliDetector(),
91     fNCh(0),
92     fNTrackingCh(0),
93     fMUONData(0),
94     fSplitLevel(0),
95     fChambers(0),
96     fTriggerCircuits(0),
97     fGeometryBuilder(0),
98     fSegmentation(0),
99     fAccCut(kFALSE),
100     fAccMin(0.),
101     fAccMax(0.),   
102     fMaxStepGas(0.),
103     fMaxStepAlu(0.),
104     fMaxDestepGas(0.),
105     fMaxDestepAlu(0.),
106     fMaxIterPad(0),
107     fCurIterPad(0),
108     fTriggerScalerEvent(kFALSE)
109 {
110 // Default Constructor
111 //
112         AliDebug(1,Form("default (empty) ctor this=%p",this));
113     fIshunt          = 0;
114 }
115
116 //__________________________________________________________________
117 AliMUON::AliMUON(const char *name, const char *title)
118   : AliDetector(name,title),
119     fNCh(AliMUONConstants::NCh()),
120     fNTrackingCh(AliMUONConstants::NTrackingCh()),
121     fMUONData(0),
122     fSplitLevel(0),
123     fChambers(0),
124     fTriggerCircuits(0),
125     fGeometryBuilder(0),
126     fSegmentation(0),
127     fAccCut(kFALSE),
128     fAccMin(0.),
129     fAccMax(0.),   
130     fMaxStepGas(0.1),
131     fMaxStepAlu(0.1),
132     fMaxDestepGas(-1), // Negatives values are ignored by geant3 CONS200 
133     fMaxDestepAlu(-1), // in the calculation of the tracking parameters
134     fMaxIterPad(0),
135     fCurIterPad(0),
136     fTriggerScalerEvent(kFALSE)
137 {
138         AliDebug(1,Form("ctor this=%p",this));
139   fIshunt =  0;
140
141   SetMarkerColor(kRed);//
142     
143   // Geometry builder
144   fGeometryBuilder = new AliMUONGeometryBuilder(this);
145   
146   // Common geometry definitions
147   fGeometryBuilder
148     ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
149
150 //
151 // Creating List of Chambers
152     Int_t ch;
153     fChambers = new TObjArray(AliMUONConstants::NCh());
154
155     // Loop over stations
156     for (Int_t st = 0; st < AliMUONConstants::NCh() / 2; st++) {
157       // Loop over 2 chambers in the station
158       for (Int_t stCH = 0; stCH < 2; stCH++) {
159         //
160         //    
161         //    Default Parameters for Muon Tracking Stations
162         ch = 2 * st + stCH;
163         if (ch < AliMUONConstants::NTrackingCh()) {
164           fChambers->AddAt(new AliMUONChamber(ch),ch);
165         } else {
166           fChambers->AddAt(new AliMUONChamberTrigger(ch, GetGeometryTransformer()),ch);
167         }
168       } // Chamber stCH (0, 1) in 
169     }     // Station st (0...)
170     
171     // cp new design of AliMUONTriggerDecision
172     fTriggerCircuits = new TObjArray(AliMUONConstants::NTriggerCircuit());
173     for (Int_t circ=0; circ<AliMUONConstants::NTriggerCircuit(); circ++) {
174       fTriggerCircuits->AddAt(new AliMUONTriggerCircuit(),circ);          
175     }
176 }
177
178 //____________________________________________________________________
179 AliMUON::AliMUON(const AliMUON& rMUON)
180  : AliDetector(rMUON)
181 {
182 // Protected copy constructor
183
184   AliFatal("Not implemented.");
185 }
186
187 //____________________________________________________________________
188 AliMUON::~AliMUON()
189 {
190 // Destructor
191   AliDebug(1,Form("dtor this=%p",this));
192   fIshunt  = 0;
193
194   if (fChambers){
195     fChambers->Delete();
196     delete fChambers;
197   }
198   if (fTriggerCircuits){
199     fTriggerCircuits->Delete();
200     delete fTriggerCircuits;
201   }
202   delete fMUONData;
203   delete fGeometryBuilder;
204   delete fSegmentation;
205 }
206
207 //________________________________________________________________________
208 AliMUON& AliMUON::operator = (const AliMUON& rhs)
209 {
210 // Protected assignement operator
211
212   if (this == &rhs) return *this;
213
214   AliFatal("Not implemented.");
215     
216   return *this;  
217 }
218
219 //_____________________________________________________________________________
220 void AliMUON::AddGeometryBuilder(AliMUONVGeometryBuilder* geomBuilder)
221 {
222 // Adds the geometry builder to the list
223 // ---
224
225   fGeometryBuilder->AddBuilder(geomBuilder);
226 }
227
228 //____________________________________________________________________
229 void AliMUON::BuildGeometry()
230 {
231 // Geometry for event display
232
233
234 //     for (Int_t i = 0; i < AliMUONConstants::NCh(); i++)     
235 //       this->Chamber(i).SegmentationModel2(1)->Draw("eventdisplay");// to be check !
236      
237   
238 }
239
240 //____________________________________________________________________
241 const AliMUONGeometry*  AliMUON::GetGeometry() const
242 {
243 // Return geometry parametrisation
244
245   if ( !fGeometryBuilder) {
246     AliWarningStream() << "GeometryBuilder not defined." << std::endl;
247     return 0;
248   }
249   
250   return fGeometryBuilder->GetGeometry();
251 }   
252
253 //____________________________________________________________________
254 const AliMUONGeometryTransformer*  AliMUON::GetGeometryTransformer() const
255 {
256 // Return geometry parametrisation
257
258   const AliMUONGeometry* kGeometry = GetGeometry();
259   
260   if ( !kGeometry) return 0;
261
262   return kGeometry->GetTransformer();
263 }   
264
265 //__________________________________________________________________
266 void  AliMUON::SetTreeAddress()
267 {
268   GetMUONData()->SetLoader(fLoader); 
269   //  GetMUONData()->MakeBranch("D,S,RC");
270   //  GetMUONData()->SetTreeAddress("H,D,S,RC");
271   GetMUONData()->SetTreeAddress("H");
272   if (fHits !=  GetMUONData()->Hits())  {
273     if ( gAlice->GetMCApp() )
274       if ( gAlice->GetMCApp()->GetHitLists() ) {
275         fHits = GetMUONData()->Hits();
276         gAlice->GetMCApp()->AddHitList(fHits); // For purifyKine, only necessary when Hit list is created in AliMUONData
277       }  
278   }
279   fHits = GetMUONData()->Hits(); // Added by Ivana to use the methods FisrtHit, NextHit of AliDetector    
280 }
281
282 //_________________________________________________________________
283 void AliMUON::SetChargeSlope(Int_t id, Float_t p1)
284 {
285 // Set the inverse charge slope for chamber id
286     Int_t i=2*(id-1);    //PH    ((AliMUONChamber*) (*fChambers)[i])->SetSigmaIntegration(p1);
287     //PH    ((AliMUONChamber*) (*fChambers)[i+1])->SetSigmaIntegration(p1);
288     ((AliMUONChamber*) fChambers->At(i))->SetChargeSlope(p1);
289     ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSlope(p1);
290 }
291 //__________________________________________________________________
292 void AliMUON::SetChargeSpread(Int_t id, Float_t p1, Float_t p2)
293 {
294 // Set sigma of charge spread for chamber id
295     Int_t i=2*(id-1);
296     ((AliMUONChamber*) fChambers->At(i))->SetChargeSpread(p1,p2);
297     ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSpread(p1,p2);
298 }
299 //___________________________________________________________________
300 void AliMUON::SetSigmaIntegration(Int_t id, Float_t p1)
301 {
302 // Set integration limits for charge spread
303     Int_t i=2*(id-1);
304     ((AliMUONChamber*) fChambers->At(i))->SetSigmaIntegration(p1);
305     ((AliMUONChamber*) fChambers->At(i+1))->SetSigmaIntegration(p1);
306 }
307
308 //__________________________________________________________________
309 void AliMUON::SetMaxAdc(Int_t id, Int_t p1)
310 {
311 // Set maximum number for ADCcounts (saturation)
312     Int_t i=2*(id-1);
313     ((AliMUONChamber*) fChambers->At(i))->SetMaxAdc(p1);
314     ((AliMUONChamber*) fChambers->At(i+1))->SetMaxAdc(p1);
315 }
316
317 //__________________________________________________________________
318 void AliMUON::SetMaxStepGas(Float_t p1)
319 {
320 // Set stepsize in gas
321   fMaxStepGas=p1;
322 }
323 //__________________________________________________________________
324 void AliMUON::SetMaxStepAlu(Float_t p1)
325 {
326 // Set step size in Alu
327     fMaxStepAlu=p1;
328 }
329 //__________________________________________________________________
330 void AliMUON::SetMaxDestepGas(Float_t p1)
331 {
332 // Set maximum step size in Gas
333     fMaxDestepGas=p1;
334 }
335 //__________________________________________________________________
336 void AliMUON::SetMaxDestepAlu(Float_t p1)
337 {
338 // Set maximum step size in Alu
339   fMaxDestepAlu=p1;
340 }
341
342 //____________________________________________________________________
343 Float_t  AliMUON::GetMaxStepGas() const
344 {
345 // Return stepsize in gas
346   
347   return fMaxStepGas;
348 }  
349
350 //____________________________________________________________________
351 Float_t  AliMUON::GetMaxStepAlu() const
352 {
353 // Return step size in Alu
354   
355   return fMaxStepAlu;
356 }
357   
358 //____________________________________________________________________
359 Float_t  AliMUON::GetMaxDestepGas() const
360 {
361 // Return maximum step size in Gas
362   
363   return fMaxDestepGas;
364 }
365   
366 //____________________________________________________________________
367 Float_t  AliMUON::GetMaxDestepAlu() const
368 {
369 // Return maximum step size in Gas
370   
371   return fMaxDestepAlu;
372 }
373
374 //____________________________________________________________________
375  void  AliMUON::SetAlign(Bool_t align)
376 {
377  // Sets option for alignement to geometry builder
378  
379    fGeometryBuilder->SetAlign(align);
380 }   
381
382 //____________________________________________________________________
383  void  AliMUON::SetAlign(const TString& fileName, Bool_t align)
384 {
385  // Sets option for alignement to geometry builder
386  
387    fGeometryBuilder->SetAlign(fileName, align);
388 }   
389
390 //____________________________________________________________________
391 void   AliMUON::SetResponseModel(Int_t id, AliMUONResponse *response)
392 {
393 // Set the response for chamber id
394     ((AliMUONChamber*) fChambers->At(id))->SetResponseModel(response);
395 }
396 //____________________________________________________________________
397 AliDigitizer* AliMUON::CreateDigitizer(AliRunDigitizer* manager) const
398 {
399   return new AliMUONDigitizerv2(manager);
400 }
401 //_____________________________________________________________________
402 void AliMUON::SDigits2Digits()
403 {
404
405 // write TreeD here 
406
407     char hname[30];
408     //    sprintf(hname,"TreeD%d",fLoader->GetHeader()->GetEvent());
409     fLoader->TreeD()->Write(hname,TObject::kOverwrite);
410     fLoader->TreeD()->Reset();
411 }
412
413 //_____________________________________________________________________
414 void AliMUON::Hits2SDigits()
415 {
416   // Adaption of AliMUONSDigitizerv1 to be excuted by the AliSimulation framework
417   AliRunLoader* runLoader = fLoader->GetRunLoader();
418   AliRunDigitizer   * manager = new AliRunDigitizer(1,1);
419   manager->SetInputStream(0,runLoader->GetFileName(),AliConfig::GetDefaultEventFolderName());
420   AliMUONDigitizer * dMUON   = new AliMUONSDigitizerv1(manager);
421   fLoader->LoadHits("READ");
422   for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
423     runLoader->GetEvent(iEvent);
424     dMUON->Exec("");
425   }
426   fLoader->UnloadHits();
427 }
428 //_____________________________________________________________________
429 void AliMUON::Digits2Raw()
430 {
431   // convert digits of the current event to raw data
432   
433   AliMUONRawWriter* rawData = new AliMUONRawWriter(fLoader,fMUONData);
434
435   if(fTriggerScalerEvent == kTRUE)
436     rawData->SetScalerEvent();
437
438   if (!rawData->Digits2Raw()) AliInfo("pb writting raw data");
439   delete rawData;
440   return;
441 }
442 //_______________________________________________________________________
443 AliLoader* AliMUON::MakeLoader(const char* topfoldername)
444
445 //builds standard getter (AliLoader type)
446 //if detector wants to use castomized getter, it must overload this method
447
448  
449  AliDebug(1,Form("Creating standard getter for detector %s. Top folder is %s.",
450          GetName(),topfoldername));
451  fLoader   = new AliLoader(GetName(),topfoldername);
452  fMUONData = new AliMUONData(fLoader,GetName(),GetName()); 
453  fMUONData->SetSplitLevel(fSplitLevel);
454  return fLoader;
455 }
456 //_______________________________________________________________________
457
458 AliMUONRawCluster *AliMUON::RawCluster(Int_t ichamber, Int_t icathod, Int_t icluster)
459 {
460 //
461 //  Return rawcluster (icluster) for chamber ichamber and cathode icathod
462 //  Obsolete ??
463     TClonesArray *muonRawCluster  = GetMUONData()->RawClusters(ichamber);
464     ResetRawClusters();
465     TTree *treeR = fLoader->TreeR();
466     Int_t nent=(Int_t)treeR->GetEntries();
467     treeR->GetEvent(nent-2+icathod-1);
468     //treeR->GetEvent(icathod);
469     //Int_t nrawcl = (Int_t)muonRawCluster->GetEntriesFast();
470
471     AliMUONRawCluster * mRaw = (AliMUONRawCluster*)muonRawCluster->UncheckedAt(icluster);
472     //printf("RawCluster _ nent nrawcl icluster mRaw %d %d %d%p\n",nent,nrawcl,icluster,mRaw);
473     
474     return  mRaw;
475 }
476 //________________________________________________________________________
477