]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONproto.cxx
Corrected some bugs - it should compile now
[u/mrichter/AliRoot.git] / MUON / AliMUONproto.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 $Log$
17 Revision 1.2  2000/06/15 07:58:49  morsch
18 Code from MUON-dev joined
19
20 Revision 1.1.2.1  2000/04/18 09:11:15  morsch
21 Implementation of MUON Chamber Prototype Class
22 Both read digits from raw data or use the Monte-Carlo.
23 Rachid GUERNANE, IPN Lyon guernane@ipnl.in2p3.fr
24
25 */
26
27 /*
28 Implementation of MUON Chamber Prototype Class 
29 Both read digits from raw data or use the Monte-Carlo. 
30 1-Feb-2000 Rachid GUERNANE, IPN Lyon guernane@ipnl.in2p3.fr
31 */
32
33
34 ////////////////////////////////////////////////
35 //  Manager and hits classes for set:PROTO    //
36 ////////////////////////////////////////////////
37
38 #include <TTUBE.h>
39 #include <TBRIK.h>
40 #include <TRotMatrix.h>
41 #include <TNode.h> 
42 #include <TTree.h> 
43 #include <TRandom.h> 
44 #include <TObject.h>
45 #include <TVector.h>
46 #include <TObjArray.h>
47 #include <TMinuit.h>
48 #include <TParticle.h>
49 #include <TROOT.h>
50 #include <TFile.h>
51 #include <TNtuple.h>
52 #include <TCanvas.h>
53 #include <TPad.h>
54 #include <TDirectory.h>
55 #include <TObjectTable.h>
56 #include <AliPDG.h>
57 #include <TArrayI.h>
58 #include <AliDetector.h>
59
60 #include "AliMUONChamber.h"
61 #include "AliMUONproto.h"
62 #include "AliMUONHit.h"
63 #include "TTUBE.h"
64 #include "AliMUONClusterFinder.h"
65 #include "AliRun.h"
66 #include "AliMC.h"
67 #include "iostream.h"
68 #include "AliCallf77.h" 
69 #include "AliConst.h"
70 //#include "chainalice2.h"
71 #include "AliMUONSegmentationV0.h"
72 //#include "AliMUONSegResV11.h"
73
74 ClassImp(AliMUONproto)
75
76 //___________________________________________    
77 AliMUONproto::AliMUONproto()
78         : AliMUON()
79 {
80     cout << "\n Calling AliMUONproto constructor..." << endl;
81     
82         //
83         //
84         //
85 }
86  
87 //___________________________________________
88 AliMUONproto::AliMUONproto(const char *name, const char *title) 
89         : AliMUON(name,title)
90 //  AliMUON defines everything, but the chamber for NCH=1
91 {
92     
93 //  z-Positions of Chambers
94     const Float_t zch[1] = {975.};
95 //
96 //  inner diameter
97     const Float_t dmi[1] = {0.};
98 //
99 //  outer diameter
100     const Float_t dma[1] = {29.2};
101 //
102 //    
103 //    Default Parameters for ALICE2 prototype
104
105 //
106     (*fChambers)[0] = new AliMUONChamber();
107     AliMUONChamber* chamber = (AliMUONChamber*) (*fChambers)[0];
108     chamber->SetGid(0);
109     chamber->SetZ(zch[0]);
110 //
111     chamber->InitGeo(zch[0]); 
112     chamber->SetRInner(dmi[0]/2);
113     chamber->SetROuter(dma[0]/2);
114
115     for (int i = 0; i <= 99; i++) {
116         fThreshold[i] = 0.;
117     }
118     
119 }
120
121 #ifdef WE_FORGET_FOR_THE_MOMENT
122 //___________________________________________ 
123 void AliMUONproto::GetRawDigits(Int_t evnb, Int_t *lptr, Int_t ilen) {
124
125     Int_t ip = 0;
126     Int_t equip = 0;
127     Int_t nochnl;
128     Int_t loop;
129     Int_t val;    
130     Int_t itype;
131     Int_t id;
132     Int_t serial;
133     Int_t equiplen;
134
135     Int_t digits[5]; 
136     
137     AliMUON* MUON  = (AliMUON*)gAlice->GetModule("MUON");
138     AliMUONSegmentationV0* seg = (AliMUONSegmentationV0*) Chamber(0).SegmentationModel(1);
139     
140     Int_t tracks[10];
141     Int_t charges[10];
142         
143     for (Int_t i = 0; i < 10; i++) {
144         tracks[i] = 0;
145         charges[i] = 0;
146     }
147         
148     Int_t ich = 0;
149     
150   nwtype:             
151
152     itype = lptr[ip++];
153     id = lptr[ip++];
154     equiplen = lptr[ip++];
155     
156     if (equiplen < 0 ) return;
157
158     if (itype != (int)(0XCACCA008)) {        
159         ip += equiplen;
160         if (ip < ilen-2)  goto nwtype;
161     }    
162     else {
163         serial = id >> 16;
164         equip = id & 0x1;
165         if ((serial == 190) && (equip == 1)) {
166             for (loop = 0; loop < equiplen; loop++) {
167                 nochnl = (lptr[ip] & 0x7ff000 ) >> 12;
168                 val = lptr[ip] & 0x3ff;
169                 // fill digits from raw data according to cathode connexions
170                 if (group[nochnl][2][1]!=0)
171                     digits[0] = group[nochnl][2][1] - 12;
172                 else if  (group[nochnl][1][1]!=0)
173                     digits[0] = group[nochnl][1][1] - 12;
174                 else
175                     digits[0] = group[nochnl][0][1] - 12;
176                 digits[1] = group[nochnl][0][0];
177                 if (digits[0] != seg->Ix(digits[0], digits[1]))
178                     printf("Pb pour ix=%d,iy=%d\n", digits[0], digits[1]);
179                 digits[2] = val;
180                 digits[3] = 0;
181                 digits[4] = 0;
182                 if (digits[2] >= fThreshold[nochnl]) 
183                     MUON->AddDigits(ich, tracks, charges, digits);
184
185                 ip++;
186             }   
187         } 
188         else
189             ip += equiplen;
190         
191         if (ip < ilen-2) goto nwtype;
192     }
193     
194     gAlice->TreeD()->Fill();
195     MUON->ResetDigits();
196
197     gAlice->TreeD()->Fill();
198     MUON->ResetDigits();
199     
200     char hname[30];
201     sprintf(hname, "TreeD%d", evnb);
202     gAlice->TreeD()->Write(hname);
203     // reset tree
204     gAlice->TreeD()->Reset();
205
206 }
207 #endif
208
209 //___________________________________________
210 void AliMUONproto::SetPadSize(Int_t id, Int_t isec, Float_t p1, Float_t p2)
211 {
212     Int_t i=2*(id-1);
213     ((AliMUONChamber*)(*fChambers)[i])->SetPadSize(isec,p1,p2);
214 }
215
216 //___________________________________________
217 void AliMUONproto::SetChargeSlope(Int_t id, Float_t p1)
218 {
219     Int_t i=2*(id-1);
220     ((AliMUONChamber*) (*fChambers)[i])->SetChargeSlope(p1);
221 }
222
223 //___________________________________________
224 void AliMUONproto::SetChargeSpread(Int_t id, Float_t p1, Float_t p2)
225 {
226     Int_t i=2*(id-1);
227     ((AliMUONChamber*) (*fChambers)[i])->SetChargeSpread(p1,p2);
228 }
229
230 //___________________________________________
231 void AliMUONproto::SetMaxAdc(Int_t id, Float_t p1)
232 {
233     Int_t i=2*(id-1);
234     ((AliMUONChamber*) (*fChambers)[i])->SetMaxAdc(p1);
235 }
236
237 //___________________________________________
238 void AliMUONproto::CreateGeometry()
239 {
240     Int_t *idtmed = fIdtmed->GetArray()-1099;
241 //
242     Float_t zpos;
243     Float_t bpar[3];
244     Int_t idGas=idtmed[1100];
245     
246     AliMUONChamber *iChamber;
247 //********************************************************************
248 //                          Prototype ALICE2                        **
249 //********************************************************************
250     iChamber=(AliMUONChamber*) (*fChambers)[0];
251     
252     zpos=iChamber->Z(); 
253 //
254     const Float_t X_POS = 11*.975/2; //half x
255     const Float_t Y_POS = 18*.55/2;  //half y
256     const Float_t Z_POS = 0.325;
257     
258     bpar[0] = X_POS; 
259     bpar[1] = Y_POS;  
260     bpar[2] = Z_POS;
261     
262     gMC->Gsvolu("C01G", "BOX", idGas, bpar, 3);
263     gMC->Gspos("C01G", 1, "ALIC", -bpar[0], bpar[1], zpos, 0, "ONLY");
264 }
265
266 //___________________________________________
267 void AliMUONproto::CreateMaterials()
268 {
269   // *** DEFINITION OF AVAILABLE MUON MATERIALS *** 
270   //
271   //     Ar-CO2 gas 
272     Float_t ag1[3]   = { 39.95,12.01,16. };
273     Float_t zg1[3]   = { 18.,6.,8. };
274     Float_t wg1[3]   = { .8,.0667,.13333 };
275     Float_t dg1      = .001821;
276     
277     Float_t epsil  = .001; // Tracking precision, 
278     Float_t tmaxfd = -20.; // Maximum angle due to field deflection
279     Float_t stmin  = -.8;
280     Int_t ISXFLD   = gAlice->Field()->Integ();
281     Float_t SXMGMX = gAlice->Field()->Max();
282
283     //
284     // --- Define the various materials for GEANT ---
285     AliMixture(22, "ArCO2 80%$", ag1, zg1, dg1, 3, wg1);
286
287     //
288     //    Ar/CO2
289     AliMedium(1, "ARG_CO2   ", 22, 1, ISXFLD, SXMGMX, tmaxfd, fMaxStepGas,
290               fMaxDestepAlu, epsil, stmin);
291     //    Air 
292         //AliMedium(1, "AIR_CH_US         ", 15, 1, ISXFLD, SXMGMX, tmaxfd, -1., -.3, epsil, stmin);
293 }
294
295 //___________________________________________
296 void AliMUONproto::Init()
297 {
298    printf("\n\n\n Start Init for Prototype ALICE2 - CPC chamber type\n\n\n");
299
300    // 
301    // Initialize Tracking Chambers
302    //
303    
304    ( (AliMUONChamber*) (*fChambers)[0])->Init();
305    
306    //
307    // Set the chamber (sensitive region) GEANT identifier
308    AliMC* gMC = AliMC::GetMC(); 
309    ((AliMUONChamber*)(*fChambers)[0])->SetGid(gMC->VolId("C01G"));
310
311    printf("\n\n\n Finished Init for Prototype ALICE2 - CPC chamber type\n\n\n");
312
313 }
314
315 //___________________________________________
316 void AliMUONproto::StepManager()
317 {
318   Int_t          copy, id;
319   static Int_t   idvol;
320   static Int_t   vol[2];
321   Int_t          ipart;
322   TLorentzVector pos;
323   TLorentzVector mom;
324   Float_t        theta,phi;
325   Float_t        destep, step;
326   
327   static Float_t eloss, eloss2, xhit, yhit, tlength;
328   const  Float_t big=1.e10;
329   
330   //  modifs perso
331   static Float_t hits[14];
332
333   TClonesArray &lhits = *fHits;
334
335   //
336   // Set maximum step size for gas
337   // numed=gMC->GetMedium();
338   //
339   // Only charged tracks
340   if( !(gMC->TrackCharge()) ) return; 
341   //
342   // Only gas gap inside chamber
343   // Tag chambers and record hits when track enters 
344   idvol=-1;
345   id=gMC->CurrentVolID(copy);
346   
347     for (Int_t i=1; i<=kNCH; i++) {
348       if(id==((AliMUONChamber*)(*fChambers)[i-1])->GetGid()){ 
349           vol[0]=i; 
350           idvol=i-1;
351       }
352     }
353     if (idvol == -1) return;
354   //
355   // Get current particle id (ipart), track position (pos)  and momentum (mom) 
356   gMC->TrackPosition(pos);
357   gMC->TrackMomentum(mom);
358
359   ipart  = gMC->TrackPid();
360   //Int_t ipart1 = gMC->IdFromPDG(ipart);
361   //printf("ich, ipart %d %d \n",vol[0],ipart1);
362
363   //
364   // momentum loss and steplength in last step
365   destep = gMC->Edep();
366   step   = gMC->TrackStep();
367   
368   //
369   // record hits when track enters ...
370   if( gMC->IsTrackEntering()) {
371       gMC->SetMaxStep(fMaxStepGas);
372       Double_t tc = mom[0]*mom[0]+mom[1]*mom[1];
373       Double_t rt = TMath::Sqrt(tc);
374       Double_t pmom = TMath::Sqrt(tc+mom[2]*mom[2]);
375       Double_t tx=mom[0]/pmom;
376       Double_t ty=mom[1]/pmom;
377       Double_t tz=mom[2]/pmom;
378       Double_t s=((AliMUONChamber*)(*fChambers)[idvol])
379           ->ResponseModel()
380           ->Pitch()/tz;
381       theta   = Float_t(TMath::ATan2(rt,Double_t(mom[2])))*kRaddeg;
382       phi     = Float_t(TMath::ATan2(Double_t(mom[1]),Double_t(mom[0])))*kRaddeg;
383       hits[0] = Float_t(ipart);         // Geant3 particle type
384       hits[1] = pos[0]+s*tx;                 // X-position for hit
385       hits[2] = pos[1]+s*ty;                 // Y-position for hit
386       hits[3] = pos[2]+s*tz;                 // Z-position for hit
387       hits[4] = theta;                  // theta angle of incidence
388       hits[5] = phi;                    // phi angle of incidence 
389       hits[8] = (Float_t) fNPadHits;   // first padhit
390       hits[9] = -1;                     // last pad hit
391
392       // modifs perso
393       hits[10] = mom[3]; // hit momentum P
394       hits[11] = mom[0]; // Px/P
395       hits[12] = mom[1]; // Py/P
396       hits[13] = mom[2]; // Pz/P
397       // fin modifs perso
398
399       // phi angle of incidence
400       tlength = 0;
401       eloss   = 0;
402       eloss2  = 0;
403       xhit    = pos[0];
404       yhit    = pos[1];      
405       // Only if not trigger chamber
406       if(idvol<10) {
407           //
408           //  Initialize hit position (cursor) in the segmentation model 
409           ((AliMUONChamber*) (*fChambers)[idvol])
410               ->SigGenInit(pos[0], pos[1], pos[2]);
411       } else {
412           //geant3->Gpcxyz();
413           //printf("In the Trigger Chamber #%d\n",idvol-9);
414       }
415   }
416   eloss2+=destep;
417   
418   // 
419   // Calculate the charge induced on a pad (disintegration) in case 
420   //
421   // Mip left chamber ...
422   if( gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared()){
423       gMC->SetMaxStep(big);
424       eloss   += destep;
425       tlength += step;
426       
427       // Only if not trigger chamber
428       if(idvol<10) {
429           if (eloss > 0) 
430               MakePadHits(0.5*(xhit+pos[0]),0.5*(yhit+pos[1]),eloss,0.0,idvol);
431       }
432           
433       hits[6]=tlength;
434       hits[7]=eloss2;
435       if (fNPadHits > (Int_t)hits[8]) {
436           hits[8]= hits[8]+1;
437           hits[9]= (Float_t) fNPadHits;
438       }
439     
440       new(lhits[fNhits++]) 
441           AliMUONHit(fIshunt,gAlice->CurrentTrack(),vol,hits);
442       eloss = 0; 
443       //
444       // Check additional signal generation conditions 
445       // defined by the segmentation
446       // model (boundary crossing conditions) 
447   } else if 
448       (((AliMUONChamber*) (*fChambers)[idvol])
449        ->SigGenCond(pos[0], pos[1], pos[2]))
450   {
451       ((AliMUONChamber*) (*fChambers)[idvol])
452           ->SigGenInit(pos[0], pos[1], pos[2]);
453 //      printf("\n-> MakePadHits, reason special %d",ipart);
454       if (eloss > 0)
455           MakePadHits(0.5*(xhit+pos[0]),0.5*(yhit+pos[1]),eloss,0.0,idvol);
456       xhit     = pos[0];
457       yhit     = pos[1]; 
458       eloss    = destep;
459       tlength += step ;
460       //
461       // nothing special  happened, add up energy loss
462   } else {        
463       eloss   += destep;
464       tlength += step ;
465   }
466 }
467
468 //___________________________________________
469 void AliMUONproto::BuildGeometry()
470 {
471     TNode *Node;
472     TNode *Top;
473     
474     const int kColorMUON = kBlue;
475     //
476     Top=gAlice->GetGeometry()->GetNode("alice");
477     //
478     //
479     //
480     float dx, dy, dz, zpos;
481
482     const Float_t cz[1]={975.};
483     
484     zpos=cz[0];
485
486     dx=11*.975/2;
487     dy=18*.55/2;
488     dz=0.325;
489
490     new TBRIK("C_MUON101","Mother volume for Proto.","void",dx*2,dy*2,dz*2);
491     TBRIK* PROTO = new TBRIK("PROT", "Proto. Sens. Region","void",dx,dy,dz);
492     Top->cd();
493     Node = new TNode("MUON101","ChamberNode","C_MUON101",0,0,zpos,"");
494     Node->SetLineColor(kColorMUON);
495     Node->SetVisibility(0);    
496     fNodes->Add(Node);
497     Node->cd();
498     Node = new TNode("MUON201", "Proto. Sens. Region Node", PROTO, -dx, dy, dz);
499     Node->SetLineColor(kColorMUON);    
500
501 }
502
503 //_____________________________________________________________________________
504 void AliMUONproto::FindClusters(Int_t nev, Int_t last_entry)
505 {
506
507 //
508 // Loop on chambers and on cathode planes
509 //
510   for (Int_t icat = 0; icat < 2; icat++) {
511             gAlice->ResetDigits();
512             gAlice->TreeD()->GetEvent(last_entry+icat);
513             
514       for (Int_t ich = 0; ich < kNTrackingCh; ich++) {
515           AliMUONChamber* iChamber=(AliMUONChamber*) (*fChambers)[ich];
516           TClonesArray *MUONdigits  = this->DigitsAddress(ich);
517           if (MUONdigits == 0) continue;
518           //
519           // Get ready the current chamber stuff
520           //
521
522           AliMUONResponse* response = iChamber->ResponseModel();
523           AliMUONSegmentation* seg = iChamber->SegmentationModel(icat+1);
524           AliMUONClusterFinder* rec = iChamber->ReconstructionModel();
525
526           if (seg) {      
527               rec->SetSegmentation(seg);
528               rec->SetResponse(response);
529               rec->SetDigits(MUONdigits);
530               rec->SetChamber(ich);
531               rec->FindRawClusters();
532           }
533           
534           TClonesArray *fRch;
535           fRch=RawClustAddress(ich);
536           fRch->Sort();
537           // it seems to work
538           
539       } // for ich
540       // fill the tree
541       gAlice->TreeR()->Fill();
542
543       ResetRawClusters();
544   } // for icat
545
546   char hname[30];
547   sprintf(hname,"TreeR%d",nev);
548   gAlice->TreeR()->Write(hname);
549   gAlice->TreeR()->Reset();
550 }
551
552 #ifdef WE_FORGRET_THIS_SHIT
553 //_____________________________________________________________________________
554 void AliMUONproto::SetThreshold()
555 {
556
557     ifstream inputFile("/home/alice/guernane/aliroot/pro/MUON/crped190.dat", ios::in);
558
559     if (inputFile.fail()) {
560         cout << "Error opening file" << endl;
561         exit(2);
562     }
563
564     char buff[32];
565     Int_t Serial;
566     Int_t Ntrigger;
567     Int_t Nchannel;
568     Int_t i1;
569     Int_t i2;
570         
571     inputFile >> buff;
572
573     inputFile >> Serial;
574     inputFile >> Ntrigger;
575     inputFile >> Nchannel;
576     inputFile >> i1;
577     inputFile >> i2;
578
579     Float_t ped0[Nchannel];
580     Float_t sig0[Nchannel];
581     Float_t ped1[Nchannel];
582     Float_t sig1[Nchannel];
583     Int_t ichannel;
584
585     for (Int_t i = 0; i < Nchannel-1; i++) {
586     ped0[i] = 0;
587     sig0[i] = 0;
588     ped1[i] = 0;
589     sig1[i] = 0;        
590     }
591     
592     for (Int_t i = 0; i < Nchannel-1; i++) {
593         inputFile >> ichannel;
594         inputFile >> ped0[i];
595         inputFile >> sig0[i];
596         inputFile >> ped1[i];
597         inputFile >> sig1[i];
598         fThreshold[i] = fNsigma*sig1[i];        
599     }
600     
601     inputFile.close();    
602 }
603 #endif