Raw data reconstruction (K.Shileev)
[u/mrichter/AliRoot.git] / RICH / RichConfig.C
1 #include <TPDGCode.h>
2
3 class RichConfig : public TGMainFrame
4 {
5 RQ_OBJECT()
6 public:
7  
8           RichConfig(const char*sFileName);
9          ~RichConfig()                    {Info("ctor","");Cleanup();}
10 //protected:
11   enum EVersOpts  {kNo=-1,kVer0,kVer1,kTestBeam,kTestRadio,kOnTop,kDeclust=301,kSagita,kFeedback};
12   enum EGenTypes  {kGunAlongZ=100,kBox1,kBox7,kGun7,kPythia7,kHijing,kHijingPara,kRichLib,kSignalHijing,kHijingPara2Proton};
13   
14   enum EDetectors {kPIPE=1,kITS,kTPC,kTRD,kTOF,kFRAME,kMAG,kCRT,kHALL,kPHOS,kSTART,kFMD,kABSO,kPMD,kDIPO,kEMCAL,kVZERO,kMUON,kZDC,kSHILD,kRICH};
15   enum EProcesses {kDCAY=1,kPAIR,kCOMP,kPHOT,kPFIS,kDRAY,kANNI,kBREM,kMUNU,kCKOV,kHADR,kLOSS,kMULS,kRAYL,kALL};
16   enum EBatchFlags{kNoRaw=0,kRawDdl,kRawDate,kRawRoot,kRecon,kFillEsd};
17 //SLOTS  
18   void    AddDetector(Int_t id)          {if(id==kTRD || id==kTOF) fDetBG->SetButton(kFRAME);}
19   void    RemoveDetector(Int_t id)       {if(id==kFRAME) {fDetBG->SetButton(kTRD,kFALSE);fDetBG->SetButton(kTOF,kFALSE);}}
20   
21   void    AddProcess(Int_t id)           {if(id==kALL) for(int i=1;i<=fProcBG->GetCount();i++) fProcBG->SetButton(i,kButtonDown);}
22   void    RemoveProcess(Int_t id)        {if(id==kALL) for(int i=1;i<=fProcBG->GetCount();i++) fProcBG->SetButton(i,kButtonUp);}
23   void    GeneratorSlot(Int_t type);
24   void    VerSlot(Int_t ver)             {if(ver==kTestBeam){ fMagCB->SetState(kButtonUp); fGenTypeCO->Select(kGunAlongZ);}}        
25   
26   Float_t Eta2Theta(Float_t arg)    const{return (180./TMath::Pi())*2.*TMath::ATan(TMath::Exp(-arg));}
27   void    CreateConfig();      //create Config.C
28   void    Generator(FILE *pF); //write generatro part of Config.C
29   void    CreateRichBatch();   //create RichBatch.C
30   void    Exit();
31      
32   TGComboBox   *fRichCO;  TGButtonGroup *fRichBG;                                                                              //RICH
33   TGButton     *fMagCB;                                                                                                     //MAG
34   TGComboBox   *fGenTypeCO,*fGenPidCO,*fGenMinMomCO,*fGenMaxMomCO,*fGenChamberCO; TGGroupFrame *fGenGF,*fGenOptGF,*fGenPrimGF; TGNumberEntry *fGenPrimNE;             //GEN
35   TGButtonGroup *fDetBG;                                                                                                       //DETECTORS
36   TGButtonGroup *fProcBG;                                                                                                      //PROCESSES
37   TGButtonGroup *fRawBG;                                                                                                       //RAW 
38   TGButtonGroup *fRecoBG;                                                                                                      //RAW   
39   char         *fFileName;
40 };//class RichConfig
41 //__________________________________________________________________________________________________     
42 RichConfig::RichConfig(const char *sFileName):TGMainFrame(gClient->GetRoot(),700,400)
43 {// creates configuration file  
44   fFileName=sFileName;
45
46 //  --------------------  
47 //  | |--------------------
48 //  | ||-------|
49 //  | ||       |
50 //  | ||-------|
51 //  | |  
52 //  | ||-------|   
53   
54 //  | |--------------------
55 //  | ---------------------         
56   
57 //  Connect("CloseWindow()","RichConfig",this,"CloseWindow()");   
58   AddFrame(pMainHF=new TGHorizontalFrame(this,100,200)); //main horizontal frame
59 //Left vertical frame containing RICH and MagField  
60   pMainHF->AddFrame(pLeftVF=new TGVerticalFrame(pMainHF,100,200));  
61 //RICH
62   pLeftVF->AddFrame(pRichGF=new TGGroupFrame(pLeftVF,"RICH"));
63   pRichGF->AddFrame(fRichCO=new TGComboBox(pRichGF,100));
64   fRichCO->Connect("Selected(Int_t)" ,"RichConfig",this,"VerSlot(Int_t)");
65     fRichCO->AddEntry("no RICH"      ,kNo);
66     fRichCO->AddEntry("debug RICH 0" ,kVer0);
67     fRichCO->AddEntry("normal RICH 1",kVer1);
68     fRichCO->AddEntry("RICH on top"  ,kOnTop);
69     fRichCO->AddEntry("test beam"    ,kTestBeam);
70     fRichCO->AddEntry("radio source" ,kTestRadio);
71     fRichCO->Select(kVer1); 
72     fRichCO->Resize(150,20);
73   pRichGF->AddFrame(fRichBG=new TGButtonGroup(pRichGF,"Options"));
74     new TGCheckButton(fRichBG,"Decluster?"   ,kDeclust);      fRichBG->SetButton(kDeclust);
75     new TGCheckButton(fRichBG,"Wire sagita?" ,kSagita);       fRichBG->SetButton(kSagita);
76     new TGCheckButton(fRichBG,"Feedbacks?"   ,kFeedback);     fRichBG->SetButton(kFeedback); 
77 // Magnetic Field
78   pLeftVF->AddFrame(pMagGF=new TGGroupFrame(pLeftVF,"Magnetic Field"));
79   pMagGF->AddFrame(fMagCB=new TGCheckButton(pMagGF,"On/Off"));
80   fMagCB->SetState(kButtonDown);
81 //Generator  
82   pMainHF->AddFrame(fGenGF=new TGGroupFrame(pMainHF,"Generator"));
83   fGenGF->AddFrame(fGenTypeCO=new TGComboBox(fGenGF,100));
84   fGenTypeCO->Connect("Selected(Int_t)" ,"RichConfig",this,"GeneratorSlot(Int_t)");
85   fGenTypeCO->AddEntry("gun along z"                  ,kGunAlongZ);  
86   fGenTypeCO->AddEntry("box gun to single chamber"    ,kBox1);  
87   fGenTypeCO->AddEntry("gun to all chambers"          ,kGun7);
88   fGenTypeCO->AddEntry("box to all chambers"          ,kBox7);
89   fGenTypeCO->AddEntry("7 guns+Pythia"                ,kPythia7);
90   fGenTypeCO->AddEntry("HIJING"                       ,kHijing);
91   fGenTypeCO->AddEntry("HIJING para"                  ,kHijingPara);
92   fGenTypeCO->AddEntry("2 p+HIJING"                   ,kHijingPara2Proton);
93   fGenTypeCO->AddEntry("RICH lib"                     ,kRichLib);
94   fGenTypeCO->AddEntry("RICH lib+HIJING"              ,kSignalHijing);
95   fGenTypeCO->Select(kHijing);
96   fGenTypeCO->Resize(160,20);
97   
98   
99   fGenGF->AddFrame(fGenOptGF=new TGGroupFrame(fGenGF,"Options")); //PID for guns
100
101   
102   fGenOptGF->AddFrame(fGenPidCO=new TGComboBox(fGenOptGF,100)); //PID for guns
103   fGenPidCO->AddEntry("Pion+"     ,kPiPlus);
104   fGenPidCO->AddEntry("Pion-"     ,kPiMinus);
105   fGenPidCO->AddEntry("Kaon+"     ,kKPlus);
106   fGenPidCO->AddEntry("Kaon-"     ,kKMinus);
107   fGenPidCO->AddEntry("K0s"       ,kK0Short);    
108   fGenPidCO->AddEntry("Proton"    ,kProton);
109   fGenPidCO->AddEntry("ProtonBar" ,kProtonBar);
110   fGenPidCO->AddEntry("Lambda"    ,kLambda0);
111   fGenPidCO->AddEntry("LambdaBar" ,kLambda0Bar);
112   fGenPidCO->Select(kProton);  fGenPidCO->Resize(160,20);
113
114   fGenOptGF->AddFrame(fGenMinMomCO=new TGComboBox(fGenOptGF,100)); //particle energy for guns  
115   for(Int_t i=5;i<=95;i+=5)
116     fGenMinMomCO->AddEntry(Form("%3.1f GeV",0.1*i), i);
117   fGenMinMomCO->Select(15);  fGenMinMomCO->Resize(160,20);
118   
119   fGenOptGF->AddFrame(fGenMaxMomCO=new TGComboBox(fGenOptGF,100)); //particle energy for guns
120   for(Int_t i=10;i<=95;i+=5)
121     fGenMaxMomCO->AddEntry(Form("%3.1f GeV",0.1*i), i);
122   fGenMaxMomCO->Select(40);  fGenMaxMomCO->Resize(160,20);
123   
124   fGenOptGF->AddFrame(fGenChamberCO=new TGComboBox(fGenOptGF,100)); //chamber number in case of gun1
125   for(int i=1;i<=7;i++) fGenChamberCO->AddEntry(Form("Chamber %i",i),i);
126   fGenChamberCO->Select(4); fGenChamberCO->Resize(160,20);
127   
128   fGenOptGF->AddFrame(fGenPrimGF=new TGGroupFrame(fGenOptGF,"Number of primaries"));
129   fGenPrimGF->AddFrame(fGenPrimNE=new TGNumberEntry(fGenPrimGF,500));  
130 //Detectors
131   pMainHF->AddFrame(fDetBG=new TGButtonGroup(pMainHF,"Detectors"));
132   fDetBG->Connect("Pressed(Int_t)" ,"RichConfig",this,"AddDetector(Int_t)");
133   fDetBG->Connect("Released(Int_t)","RichConfig",this,"RemoveDetector(Int_t)");
134     new TGCheckButton(fDetBG,"PIPE"  ,kPIPE));         
135     new TGCheckButton(fDetBG,"ITS"   ,kITS));         
136     new TGCheckButton(fDetBG,"TPC"   ,kTPC));
137     new TGCheckButton(fDetBG,"TRD"   ,kTRD));
138     new TGCheckButton(fDetBG,"TOF"   ,kTOF));         
139     new TGCheckButton(fDetBG,"FRAME" ,kFRAME));         
140     new TGCheckButton(fDetBG,"MAG"   ,kMAG));         
141     new TGCheckButton(fDetBG,"CRT"   ,kCRT));         
142     new TGCheckButton(fDetBG,"HALL"  ,kHALL));         
143     new TGCheckButton(fDetBG,"PHOS"  ,kPHOS));         
144     new TGCheckButton(fDetBG,"START" ,kSTART));         
145     new TGCheckButton(fDetBG,"FMD"   ,kFMD));         
146     new TGCheckButton(fDetBG,"ABSO"  ,kABSO));         
147     new TGCheckButton(fDetBG,"PMD"   ,kPMD));         
148     new TGCheckButton(fDetBG,"DIPO"  ,kDIPO));         
149     new TGCheckButton(fDetBG,"EMCAL" ,kEMCAL));         
150     new TGCheckButton(fDetBG,"VZERO" ,kVZERO));         
151     new TGCheckButton(fDetBG,"MUON"  ,kMUON));         
152     new TGCheckButton(fDetBG,"ZDC"   ,kZDC));         
153     new TGCheckButton(fDetBG,"SHILD" ,kSHILD));         
154 //Processes  
155   pMainHF->AddFrame(fProcBG=new TGButtonGroup(pMainHF,"Processes"));
156   fProcBG->Connect("Pressed(Int_t)" ,"RichConfig",this,"AddProcess(Int_t)");
157   fProcBG->Connect("Released(Int_t)","RichConfig",this,"RemoveProcess(Int_t)");
158     new TGCheckButton(fProcBG,"ALL  ON/OFF"                 ,kALL)) ;
159     new TGCheckButton(fProcBG,"DCAY Decay"                  ,kDCAY));  fProcBG->SetButton(kDCAY);       
160     new TGCheckButton(fProcBG,"PAIR Pair production"        ,kPAIR));  fProcBG->SetButton(kPAIR);       
161     new TGCheckButton(fProcBG,"COMP Compton"                ,kCOMP));  fProcBG->SetButton(kCOMP);
162     new TGCheckButton(fProcBG,"PHOT"                        ,kPHOT));  fProcBG->SetButton(kPHOT);
163     new TGCheckButton(fProcBG,"PFIS Photofission"           ,kPFIS));  
164     new TGCheckButton(fProcBG,"DRAY Delta electrons"        ,kDRAY));  
165     new TGCheckButton(fProcBG,"ANNI Annihilation"           ,kANNI));  fProcBG->SetButton(kANNI);       
166     new TGCheckButton(fProcBG,"BREM Bremstraslung"          ,kBREM));  fProcBG->SetButton(kBREM);       
167     new TGCheckButton(fProcBG,"MUNU Muon-Nuclear"           ,kMUNU));  fProcBG->SetButton(kMUNU);       
168     new TGCheckButton(fProcBG,"CKOV Cerenkovs"              ,kCKOV));  fProcBG->SetButton(kCKOV);       
169     new TGCheckButton(fProcBG,"HADR Hadronic interactions " ,kHADR));  fProcBG->SetButton(kHADR);       
170     new TGCheckButton(fProcBG,"LOSS Energy losses"          ,kLOSS));  fProcBG->SetButton(kLOSS);       
171     new TGCheckButton(fProcBG,"MULS Multiple scattering"    ,kMULS));  fProcBG->SetButton(kMULS);       
172     new TGCheckButton(fProcBG,"RAYL"                        ,kRAYL));  fProcBG->SetButton(kRAYL);       
173 //RichBatch part
174   pMainHF->AddFrame(pBatchVF=new TGVerticalFrame(pMainHF));    
175   pBatchVF->AddFrame(fRawBG=new TGButtonGroup(pBatchVF,"RichBatch"));
176     new TGRadioButton(fRawBG,"No RAW files"      ,kNoRaw)) ;   fRawBG->SetButton(kNoRaw);
177     new TGRadioButton(fRawBG,"RAW DDL"           ,kRawDdl)) ;
178     new TGRadioButton(fRawBG,"RAW DATE"          ,kRawDate)) ;
179     new TGRadioButton(fRawBG,"RAW ROOT"          ,kRawRoot)) ;
180   fRawBG->AddFrame(fRecoBG=new TGButtonGroup(fRawBG,""));
181     new TGCheckButton(fRecoBG,"Reconstruct"    ,kRecon)) ; fRecoBG->SetButton(kRecon);  
182     new TGCheckButton(fRecoBG,"Fill ESD"       ,kFillEsd)) ; fRecoBG->SetButton(kFillEsd);
183 //File    
184   AddFrame(pFileHF=new TGHorizontalFrame(this,100,200));
185   pFileHF->AddFrame(pCrtTB=new TGTextButton(pFileHF,"Create"));
186   pCrtTB->Connect("Clicked()","RichConfig",this,"Exit()");                                 
187   pFileHF->AddFrame(new TGLabel(pFileHF,Form(" config file as %s",fFileName)));  
188   
189   MapSubwindows();   
190   //Layout(); 
191   Resize(GetDefaultSize());
192   SetWindowName("Create AliROOT scripts");
193   MapWindow();      
194 }//KirCondig::ctor
195 //__________________________________________________________________________________________________
196 void RichConfig::GeneratorSlot(Int_t type)
197 {//enable-disable generator widegets according to generator type
198   if(type==kHijing) fGenGF->HideFrame(fGenOptGF); 
199   
200   if(type==kHijingPara){
201     fGenGF->ShowFrame(fGenOptGF);
202     fGenOptGF->ShowFrame(fGenPrimGF);        
203     fGenOptGF->HideFrame(fGenPidCO);
204     fGenOptGF->HideFrame(fGenMinMomCO);
205     fGenOptGF->HideFrame(fGenMaxMomCO);
206     fGenOptGF->HideFrame(fGenChamberCO);
207   }
208   
209   if(type==kGunAlongZ) {
210     fGenGF->ShowFrame(fGenOptGF);
211     fGenOptGF->ShowFrame(fGenPidCO);
212     fGenOptGF->ShowFrame(fGenMinMomCO);
213     fGenOptGF->HideFrame(fGenMaxMomCO);
214     fGenOptGF->HideFrame(fGenChamberCO);
215     fGenOptGF->HideFrame(fGenPrimGF);    
216   }
217 }//GeneratorSlot()        
218 //__________________________________________________________________________________________________          
219 void RichConfig::CreateConfig()
220 {   
221   FILE *fp=fopen(fFileName,"w"); if(!fp){Info("CreateConfigFile","Cannot open output file:%sn",fFileName);return;}
222   
223   fprintf(fp,"void Config()\n");
224   fprintf(fp,"{\n");
225   fprintf(fp,"  ::Info(\"RICH private config\",\"Start\");\n\n"); 
226 //Random
227   fprintf(fp,"  gRandom->SetSeed(123456);//put 0 to use system time\n\n");    
228 //Geant  
229   fprintf(fp,"  gSystem->Load(\"libgeant321\");\n");
230   fprintf(fp,"  new TGeant3TGeo(\"C++ Interface to Geant3\");\n\n");
231 //File
232   fprintf(fp,"  AliRunLoader *pAL=AliRunLoader::Open(\"galice.root\",AliConfig::GetDefaultEventFolderName(),\"recreate\");\n");    
233   fprintf(fp,"  pAL->SetCompressionLevel(2);\n");
234   fprintf(fp,"  pAL->SetNumberOfEventsPerFile(1000);\n");
235   fprintf(fp,"  gAlice->SetRunLoader(pAL);\n\n");
236 //Decayer  
237   fprintf(fp,"  TVirtualMCDecayer *pDecayer=new AliDecayerPythia();\n");
238   fprintf(fp,"  pDecayer->SetForceDecay(kAll);\n"); 
239   fprintf(fp,"  pDecayer->Init();\n"); 
240   fprintf(fp,"  gMC->SetExternalDecayer(pDecayer);\n\n");
241   Physics(fp);
242 //Field
243   if(fMagCB->GetState()==kButtonDown) fprintf(fp,"  gAlice->SetField();\n\n");else fprintf(fp,"  gAlice->SetField(0);\n\n");
244   fprintf(fp,"  pAL->CdGAFile();\n\n");                                 //????       
245 //BODY-ALIC 
246   fprintf(fp,"  new AliBODY(\"BODY\",\"Alice envelop\");\n\n");
247 //RICH
248   if(!fRichBG->GetButton(kDeclust)->GetState()) fprintf(fp,"  AliRICHParam::SetDeclustering(kFALSE);\n");
249   if(!fRichBG->GetButton(kSagita)->GetState())  fprintf(fp,"  AliRICHParam::SetWireSag(kFALSE);\n")     ;
250   switch(fRichCO->GetSelected()){
251     case kNo:                                                                                                  break;
252     case kVer0:  fprintf(fp,"  AliRICH *pRICH=new AliRICHv0(\"RICH\",\"Rich with debug StepManager\");\n\n"); break;      
253     case kVer1:  fprintf(fp,"  AliRICH *pRICH=new AliRICHv1(\"RICH\",\"Normal\");\n\n");                 break;      
254   }//switch RICH
255 //Generator
256   Generator(fp);
257 //central before RICH detectors                  
258   if(fDetBG->GetButton(kPIPE )->GetState()) fprintf(fp,"\n  new AliPIPEv0(\"PIPE\",\"Beam Pipe\");\n");
259   if(fDetBG->GetButton(kSHILD)->GetState()) fprintf(fp,"\n  new AliSHILv2(\"SHIL\",\"Shielding Version 2\");\n");  
260   if(fDetBG->GetButton(kITS  )->GetState()){
261     fprintf(fp,"\n  AliITSvPPRasymmFMD *pIts =new AliITSvPPRasymmFMD(\"ITS\",\"ITS PPR detailed version\");\n");
262     fprintf(fp,"  pIts->SetMinorVersion(2); pIts->SetReadDet(kTRUE);\n");
263     fprintf(fp,"  pIts->SetThicknessDet1(200.); pIts->SetThicknessDet2(200.);\n");
264     fprintf(fp,"  pIts->SetThicknessChip1(200.); pIts->SetThicknessChip2(200.);\n");
265     fprintf(fp,"  pIts->SetRails(0); pIts->SetCoolingFluid(1);\n");
266     fprintf(fp,"  pIts->SetEUCLID(0);\n");
267   }  
268   if(fDetBG->GetButton(kTPC  )->GetState()) {fprintf(fp,"\n  AliTPC *pTpc=new AliTPCv2(\"TPC\",\"Default\"); pTpc->SetSecAU(-1);pTpc->SetSecAL(-1);\n");}  
269   if(fDetBG->GetButton(kFRAME)->GetState())  fprintf(fp,"\n  AliFRAMEv2 *pFrame=new AliFRAMEv2(\"FRAME\",\"Space Frame\"); pFrame->SetHoles(1);\n");
270   if(fDetBG->GetButton(kTRD  )->GetState()) {
271     fprintf(fp,"\n  AliTRD *pTrd=new AliTRDv1(\"TRD\",\"TRD slow simulator\");\n");
272     fprintf(fp,"  pTrd->SetGasMix(1); pTrd->SetPHOShole();pTrd->CreateTR();\n");
273   }  
274   if(fDetBG->GetButton(kTOF  )->GetState()) fprintf(fp,"\n  new AliTOFv4T0(\"TOF\", \"normal TOF\");\n");
275 //central after RICH detectors  
276   if(fDetBG->GetButton(kMAG  )->GetState()) fprintf(fp,"\n  new AliMAG(\"MAG\",\"Magnet\");\n");  
277   if(fDetBG->GetButton(kHALL )->GetState()) fprintf(fp,"\n  new AliHALL(\"HALL\",\"Alice Hall\");\n");
278 //forward detectors  
279   if(fDetBG->GetButton(kFMD  )->GetState()) fprintf(fp,"\n  new AliFMDv1(\"FMD\",\"normal FMD\");\n");
280   if(fDetBG->GetButton(kABSO )->GetState()) fprintf(fp,"\n  new AliABSOv0(\"ABSO\",\"Muon absorber\");\n");
281   if(fDetBG->GetButton(kDIPO )->GetState()) fprintf(fp,"\n  new AliDIPOv2(\"DIPO\",\"Dipole version 2\");\n");
282   if(fDetBG->GetButton(kMUON )->GetState()) fprintf(fp,"\n  new AliMUONv1(\"MUON\",\"default\");\n");
283   if(fDetBG->GetButton(kPMD  )->GetState()) fprintf(fp,"\n  new AliPMDv1(\"PMD\",\"normal PMD\");\n");
284   if(fDetBG->GetButton(kSTART)->GetState()) fprintf(fp,"\n  new AliSTARTv1(\"START\",\"START Detector\");\n");
285   if(fDetBG->GetButton(kVZERO)->GetState()) fprintf(fp,"\n  new AliVZEROv2(\"VZERO\",\"normal VZERO\");\n");
286   if(fDetBG->GetButton(kZDC  )->GetState()) fprintf(fp,"\n  new AliZDCv2(\"ZDC\",\"normal ZDC\");\n");
287 //different phase space detectors  
288   if(fDetBG->GetButton(kPHOS )->GetState()) fprintf(fp,"\n  new AliPHOSv1(\"PHOS\",\"IHEP\");\n");
289   if(fDetBG->GetButton(kEMCAL)->GetState()) fprintf(fp,"\n  new AliEMCALv1(\"EMCAL\",\"G56_2_55_19_104_14\");\n");
290   if(fDetBG->GetButton(kCRT  )->GetState()) fprintf(fp,"\n  new AliCRTv0(\"CRT\",\"normal ACORDE\");\n");
291
292   fprintf(fp,"\n  ::Info(\"RICH private config\",\"Stop\");\n"); 
293   fprintf(fp,"}\n");
294 out:  
295   fclose(fp);  
296 //  CloseWindow();
297 }//CreateConfig
298 //__________________________________________________________________________________________________
299 void RichConfig::Physics(FILE *fp)
300 {
301   if(fProcBG->GetButton(kDCAY)->GetState()) fprintf(fp,"  gMC->SetProcess(\"DCAY\",1);");  else fprintf(fp,"  gMC->SetProcess(\"DCAY\",0);");
302   if(fProcBG->GetButton(kPAIR)->GetState()) fprintf(fp,"  gMC->SetProcess(\"PAIR\",1);\n");else fprintf(fp,"  gMC->SetProcess(\"PAIR\",0);\n");
303   if(fProcBG->GetButton(kCOMP)->GetState()) fprintf(fp,"  gMC->SetProcess(\"COMP\",1);");  else fprintf(fp,"  gMC->SetProcess(\"COMP\",0);");
304   if(fProcBG->GetButton(kPHOT)->GetState()) fprintf(fp,"  gMC->SetProcess(\"PHOT\",1);\n");else fprintf(fp,"  gMC->SetProcess(\"PHOT\",0);\n");
305   if(fProcBG->GetButton(kPFIS)->GetState()) fprintf(fp,"  gMC->SetProcess(\"PFIS\",1);");  else fprintf(fp,"  gMC->SetProcess(\"PFIS\",0);");
306   if(fProcBG->GetButton(kDRAY)->GetState()) fprintf(fp,"  gMC->SetProcess(\"DRAY\",1);\n");else fprintf(fp,"  gMC->SetProcess(\"DRAY\",0);\n");
307   if(fProcBG->GetButton(kANNI)->GetState()) fprintf(fp,"  gMC->SetProcess(\"ANNI\",1);");  else fprintf(fp,"  gMC->SetProcess(\"ANNI\",0);");
308   if(fProcBG->GetButton(kBREM)->GetState()) fprintf(fp,"  gMC->SetProcess(\"BREM\",1);\n");else fprintf(fp,"  gMC->SetProcess(\"BREM\",0);\n");
309   if(fProcBG->GetButton(kMUNU)->GetState()) fprintf(fp,"  gMC->SetProcess(\"MUNU\",1);");  else fprintf(fp,"  gMC->SetProcess(\"MUNU\",0);");
310   if(fProcBG->GetButton(kCKOV)->GetState()) fprintf(fp,"  gMC->SetProcess(\"CKOV\",1);\n");else fprintf(fp,"  gMC->SetProcess(\"CKOV\",0);\n");
311   if(fProcBG->GetButton(kHADR)->GetState()) fprintf(fp,"  gMC->SetProcess(\"HADR\",1);");  else fprintf(fp,"  gMC->SetProcess(\"HADR\",0);");
312   if(fProcBG->GetButton(kLOSS)->GetState()) fprintf(fp,"  gMC->SetProcess(\"LOSS\",2);\n");else fprintf(fp,"  gMC->SetProcess(\"LOSS\",0);\n");
313   if(fProcBG->GetButton(kMULS)->GetState()) fprintf(fp,"  gMC->SetProcess(\"MULS\",1);");  else fprintf(fp,"  gMC->SetProcess(\"MULS\",0);");
314   if(fProcBG->GetButton(kRAYL)->GetState()) fprintf(fp,"  gMC->SetProcess(\"RAYL\",1);\n");else fprintf(fp,"  gMC->SetProcess(\"RAYL\",0);\n");
315   
316   fprintf(fp,"\n");  
317   fprintf(fp,"  gMC->SetCut(\"CUTGAM\",0.001); ");  fprintf(fp,"  gMC->SetCut(\"CUTELE\",0.001); ");
318   fprintf(fp,"  gMC->SetCut(\"CUTNEU\",0.001);\n"); fprintf(fp,"  gMC->SetCut(\"CUTHAD\",0.001); ");
319   fprintf(fp,"  gMC->SetCut(\"CUTMUO\",0.001); ");  fprintf(fp,"  gMC->SetCut(\"BCUTE\" ,0.001);\n");
320   fprintf(fp,"  gMC->SetCut(\"BCUTM\" ,0.001); ");  fprintf(fp,"  gMC->SetCut(\"DCUTE\" ,0.001); ");
321   fprintf(fp,"  gMC->SetCut(\"DCUTM\" ,0.001);\n"); fprintf(fp,"  gMC->SetCut(\"PPCUTM\",0.001); ");
322   fprintf(fp,"  gMC->SetCut(\"TOFMAX\",1e10);\n\n"); 
323 }//Physics()
324 //__________________________________________________________________________________________________
325 void RichConfig::Generator(FILE *fp)
326 {
327   switch(fGenTypeCO->GetSelected()){
328     case kHijingPara: 
329       fprintf(fp,"  AliGenHIJINGpara *pGen=new AliGenHIJINGpara(%i);\n",(int)fGenPrimNE->GetNumber());
330       fprintf(fp,"  pGen->SetMomentumRange(0,999); pGen->SetThetaRange(%f,%f); pGen->SetPhiRange(0,360);\n",Eta2Theta(8),Eta2Theta(-8));
331       fprintf(fp,"  pGen->SetOrigin(0,0,0);  pGen->SetSigma(0,0,0);\n");
332       fprintf(fp,"  pGen->Init();\n");
333     break;
334     case kBox1:     
335       fprintf(fp,"  AliGenBox *pGen=new AliGenBox(1);\n");  
336       fprintf(fp,"  pGen->SetPart(%i); pGen->SetOrigin(0,0,0);\n",fGenPidCO->GetSelected());  
337       fprintf(fp,"  pGen->SetMomentumRange(%.1f,%.1f); \n",float(fGenMinMomCO->GetSelected())/10,   float(fGenMaxMomCO->GetSelected())/10);
338       fprintf(fp,"  pGen->SetThetaRange(pRICH->C(%i)->ThetaD()-3,pRICH->C(%i)->ThetaD()-1); \n",fGenChamberCO->GetSelected(),fGenChamberCO->GetSelected());
339       fprintf(fp,"  pGen->SetPhiRange(pRICH->C(%i)->PhiD()-1,pRICH->C(%i)->PhiD()+1); \n",fGenChamberCO->GetSelected(),fGenChamberCO->GetSelected());    
340       fprintf(fp,"  pGen->Init();\n");
341     break;    
342     case kBox7:   
343       fprintf(fp,"  AliGenCocktail *pCocktail=new AliGenCocktail();\n");
344       fprintf(fp,"  for(int i=1;i<=7;i++){\n");
345       fprintf(fp,"    AliGenBox *pBox=new AliGenBox(1);\n");
346       fprintf(fp,"    pBox->SetMomentumRange(%.1f,%.1f); \n",float(fGenMinMomCO->GetSelected())/10,   float(fGenMaxMomCO->GetSelected())/10);
347       fprintf(fp,"    pBox->SetPart(%i); pBox->SetOrigin(0,0,0);\n",fGenPidCO->GetSelected());
348       fprintf(fp,"    pBox->SetThetaRange(pRICH->C(i)->ThetaD()-3,pRICH->C(i)->ThetaD()-1); \n");
349       fprintf(fp,"    pBox->SetPhiRange(pRICH->C(i)->PhiD()-1,pRICH->C(i)->PhiD()+1); \n");    
350       fprintf(fp,"    pCocktail->AddGenerator(pBox,Form(\"Box %i\",i),1);\n  }\n");  
351       fprintf(fp,"  pCocktail->Init();\n");
352     break;
353     case kGunAlongZ:   
354       fprintf(fp,"  AliGenFixed *pGen=new AliGenFixed(1);\n");
355       fprintf(fp,"  pGen->SetPart(%i); pGen->SetOrigin(0,0,0); pGen->SetMomentum(%.1f); pGen->SetTheta(0);\n",fGenPidCO->GetSelected(),float(fGenMinMomCO->GetSelected())/10);
356       fprintf(fp,"  pGen->Init();\n");
357     break;
358     case kGun7:   
359       fprintf(fp,"  AliGenCocktail *pCocktail=new AliGenCocktail();\n");
360       fprintf(fp,"  for(int i=1;i<=7;i++){\n");
361       fprintf(fp,"    AliGenFixed *pFixed=new AliGenFixed(1);\n");
362       fprintf(fp,"    pFixed->SetPart(%i); pFixed->SetMomentum(1.0+i*0.5); pFixed->SetOrigin(0,0,0);\n",fGenPidCO->GetSelected());
363       fprintf(fp,"    pFixed->SetPhi(pRICH->C(i)->PhiD()); pFixed->SetTheta(pRICH->C(i)->ThetaD()-2);\n");                             
364       fprintf(fp,"    pCocktail->AddGenerator(pFixed,Form(\"Fixed %i\",i),1);\n  }\n");  
365       fprintf(fp,"  pCocktail->Init();\n");
366     break;
367     case kPythia7:      
368       fprintf(fp,"  AliGenCocktail *pCocktail=new AliGenCocktail();\n");
369       fprintf(fp,"  for(int i=1;i<=7;i++){\n");
370       fprintf(fp,"    AliGenFixed *pFixed=new AliGenFixed(1);\n");
371       fprintf(fp,"    pFixed->SetPart(%i); pFixed->SetMomentum(2.5+i*0.4); pFixed->SetOrigin(0,0,0);\n",fGenPidCO->GetSelected());
372       fprintf(fp,"    pFixed->SetPhiRange(pRICH->C(i)->PhiD()); pFixed->SetThetaRange(pRICH->C(i)->ThetaD()-2);\n");                             
373       fprintf(fp,"    pCocktail->AddGenerator(pFixed,Form(\"Fixed %i\",i),1);\n  }\n");  
374       fprintf(fp,"  AliGenPythia *pPythia = new AliGenPythia(-1);\n");
375       fprintf(fp,"  pPythia->SetMomentumRange(0,999999); pPythia->SetPhiRange(20,80); pPythia->SetThetaRange(75,115);\n");
376       fprintf(fp,"  pPythia->SetYRange(-12,12);  pPythia->SetPtRange(0,1000);  pPythia->SetStrucFunc(kCTEQ4L);\n");
377       fprintf(fp,"  pPythia->SetProcess(kPyMb);  pPythia->SetEnergyCMS(14000);\n");      
378       fprintf(fp,"  pCocktail->AddGenerator(pPythia,\"Pythia\",1);\n");  
379       fprintf(fp,"  pCocktail->Init();\n");
380     case kHijing:  
381       fprintf(fp,"  AliGenHijing *pGen=new AliGenHijing(-1); pGen->SetEnergyCMS(5500); pGen->SetReferenceFrame(\"CMS\");\n");
382       fprintf(fp,"  pGen->SetProjectile(\"A\", 208, 82); pGen->SetTarget(\"A\", 208, 82);\n");      
383       fprintf(fp,"  pGen->SetJetQuenching(0); pGen->SetShadowing(0);\n");
384       fprintf(fp,"  pGen->KeepFullEvent(); pGen->SetSelectAll(0); \n");
385       fprintf(fp,"  pGen->SetImpactParameterRange(0., 5.);\n");
386       fprintf(fp,"  pGen->Init();\n");
387     break;  
388     case kHijingPara2Proton:  
389       fprintf(fp,"  AliGenCocktail *pCocktail=new AliGenCocktail();\n");
390       fprintf(fp,"  for(int i=1;i<=7;i++){\n");
391       fprintf(fp,"    AliGenFixed *pProton1=new AliGenFixed(1);\n");
392       fprintf(fp,"    AliGenFixed *pProton2=new AliGenFixed(1);\n");
393       fprintf(fp,"    pProton1->SetPart(kProton); pProton1->SetMomentum(2.0+i*0.5); pProton1->SetOrigin(0,0,0);\n");
394       fprintf(fp,"    pProton2->SetPart(kProton); pProton2->SetMomentum(2.0+i*0.5); pProton2->SetOrigin(0,0,0);\n");
395       fprintf(fp,"    pProton1->SetPhiRange(pRICH->C(i)->PhiD()); pProton1->SetThetaRange(pRICH->C(i)->ThetaD());\n");                             
396       fprintf(fp,"    pProton2->SetPhiRange(pRICH->C(i)->PhiD()); pProton2->SetThetaRange(pRICH->C(i)->ThetaD()-4);\n");                             
397       fprintf(fp,"    pCocktail->AddGenerator(pProton1,Form(\"proton1 %i\",i),1);\n");  
398       fprintf(fp,"    pCocktail->AddGenerator(pProton2,Form(\"proton2 %i\",i),1);\n  }\n");  
399       
400       fprintf(fp,"  AliGenHIJINGpara *pHijingPara=new AliGenHIJINGpara(510);\n");
401       fprintf(fp,"  pHijingPara->SetMomentumRange(0,99); pHijingPara->SetThetaRange(60,120); pHijingPara->SetPhiRange(0,60);\n");
402       fprintf(fp,"  pHijingPara->SetOrigin(0,0,0);  pHijingPara->SetSigma(0,0,0);\n");
403       fprintf(fp,"  pCocktail->AddGenerator(pHijingPara,\"HijingPara\",1);\n");  
404       fprintf(fp,"  pCocktail->Init();\n");
405     break;  
406      case kRichLib:
407       fprintf(fp,"  AliGenParam *pGen=new AliGenParam(2,new AliGenRICHlib,%i,\"EXP\"); \n",fGenPidCO->GetSelected());
408       fprintf(fp,"  pGen->SetPtRange(%3.1f,%3.1f); \n",fGenMinMomCO->GetSelected()/10,fGenMaxMomCO->GetSelected()/10);
409       fprintf(fp,"  pGen->SetYRange(-0.6,0.6); \n");
410       fprintf(fp,"  pGen->SetPhiRange(0.,60.); \n");
411       fprintf(fp,"  pGen->SetForceDecay(kAll); \n");
412       fprintf(fp,"  pGen->Init();\n");
413     break;
414    case kSignalHijing:
415       fprintf(fp,"  AliGenParam *pRichLib=new AliGenParam(2,new AliGenRICHlib,%i,\"FLAT\"); \n",fGenPidCO->GetSelected());
416       fprintf(fp,"  pRichLib->SetPtRange(%3.1f,%3.1f); \n",fGenMinMomCO->GetSelected()/10,fGenMaxMomCO->GetSelected()/10);
417       fprintf(fp,"  pRichLib->SetYRange(-0.6,0.6); \n");
418       fprintf(fp,"  pRichLib->SetPhiRange(0.,60.); \n");
419       fprintf(fp,"  pRichLib->SetForceDecay(kPhiKK); \n");
420
421       fprintf(fp,"  AliGenHijing *pHijing=new AliGenHijing(-1); pHijing->SetEnergyCMS(5500); pHijing->SetReferenceFrame(\"CMS\");\n");
422       fprintf(fp,"  pHijing->SetProjectile(\"A\", 208, 82); pHijing->SetTarget(\"A\", 208, 82);\n");
423       fprintf(fp,"  pHijing->SetJetQuenching(0); pHijing->SetShadowing(0);\n");
424       fprintf(fp,"  pHijing->KeepFullEvent(); pHijing->SetSelectAll(0); \n");
425       fprintf(fp,"  pHijing->SetImpactParameterRange(0., 5.);\n");
426
427       fprintf(fp,"  AliGenCocktail *pCocktail=new AliGenCocktail();\n");
428       fprintf(fp,"  pCocktail->AddGenerator(pRichLib,\"RichLib\",1);\n");
429       fprintf(fp,"  pCocktail->AddGenerator(pHijing,\"Hijing\",1);\n");
430       fprintf(fp,"  pCocktail->Init();\n");
431     break;
432   }
433 }//Generator()
434
435
436 //__________________________________________________________________________________________________
437 void RichConfig::CreateRichBatch()
438 {//creates RichBatch.C file
439   FILE *fp=fopen("RichBatch.C","w"); if(!fp){Info("CreateRichBatch","Cannot open output file: RichBatch.C");return;}
440 //header and debug   
441   fprintf(fp,"void RichBatch(const Int_t iNevents,const Bool_t isDebug,const char *sConfigFileName)\n");
442   fprintf(fp,"{\n");
443   fprintf(fp,"  gSystem->Exec(\"rm -rf *.root hlt hough fort* raw* ZZZ*\");\n");
444   fprintf(fp,"  if(isDebug)   AliLog::SetGlobalDebugLevel(AliLog::kDebug);\n");
445   fprintf(fp,"  gBenchmark->Start(\"ALICE\");\n  TDatime time;\n\n");
446 //simulation section  
447   fprintf(fp,"  AliSimulation     *pSim=new AliSimulation(sConfigFileName);\n");
448   if(fGenTypeCO->GetSelected()==kBox1||fGenTypeCO->GetSelected()==kGun7) {
449     fprintf(fp,"  pSim->SetRegionOfInterest(kTRUE);\n");
450     fprintf(fp,"  pSim->SetMakeSDigits(\"TOF RICH\");\n");
451     fprintf(fp,"  pSim->SetMakeDigitsFromHits(\"ITS TPC TRD\");\n");
452   }
453 //RAW data generation  
454   if     (fRawBG->GetButton(kRawDdl)->GetState())  fprintf(fp,"  pSim->SetWriteRawData(\"ALL\");\n");
455   else if(fRawBG->GetButton(kRawDate)->GetState()) fprintf(fp,"  pSim->SetWriteRawData(\"ALL\",\".date\");\n");
456   else if(fRawBG->GetButton(kRawRoot)->GetState()) fprintf(fp,"  pSim->SetWriteRawData(\"ALL\",\".root\");\n");
457   
458   fprintf(fp,"  pSim->Run(iNevents);\n  delete pSim;\n\n");
459 //reconstraction section  
460   if(fRecoBG->GetButton(kRecon)->GetState()){
461     fprintf(fp,"  AliReconstruction *pRec=new AliReconstruction;\n");
462     fprintf(fp,"  pRec->SetRunLocalReconstruction(\"ITS TPC TRD TOF RICH\");\n");
463     if(fRecoBG->GetButton(kFillEsd)->GetState())
464       fprintf(fp,"  pRec->SetFillESD(\"ITS TPC TRD TOF RICH\");\n");
465     fprintf(fp,"  pRec->Run();\n");         
466     fprintf(fp,"  delete pRec;\n\n");
467   }
468 //benchmarks  
469   fprintf(fp,"  cout<<\"!!!!!!!!!!!!Info in <my/RichBatch.C>: Start time: \";time.Print();\n");
470   fprintf(fp,"  cout<<\"!!!!!!!!!!!!Info in <my/RichBatch.C>: Stop  time: \";time.Set();  time.Print();\n");
471   fprintf(fp,"  gBenchmark->Show(\"ALICE\");\n");
472 //indicate end of job  
473   fprintf(fp,"  gSystem->Exec(\"touch ZZZ______finished_______ZZZ\");\n");
474   fprintf(fp,"  gSystem->Exec(\"playwave ~/bin/end.wav\");\n");
475   fprintf(fp,"}\n");
476   
477   fclose(fp);  
478 }//CreateRichBatch()
479 //__________________________________________________________________________________________________
480 void RichConfig::Exit()
481 {
482 //slot to be invoked by clik on the Create button  
483   CreateConfig();
484   CreateRichBatch();
485   SendCloseMessage();
486 }
487 //__________________________________________________________________________________________________
488 RichConfig *rc;
489 void RichConfig()
490 {
491    rc=new RichConfig("Config.C");
492 }   
493