00001
00002 #include <stdio.h>
00003 #include <assert.h>
00004 #include <math.h>
00005 #include "MC4Vector.H"
00006 #include "HEPParticle.H"
00007 #include "TH1.h"
00008 #include "Setup.H"
00009 #include "TObjArray.h"
00010 #include "TMath.h"
00011 #define PI 3.141592653
00012
00013 inline bool ifSofty(int Id,int nparams, double *params){
00014 if (nparams<5 && Id==22) return true;
00015 for (int i=nparams-1; i>3; i--)
00016 if (Id==params[i]) return true;
00017 return false;
00018 }
00019
00020
00021 inline void fillUserHisto(char *name,double val, double weight=1.0,
00022 double min=Setup::bin_min[0][0],
00023 double max=Setup::bin_max[0][0]){
00024
00025 TH1D *h=(TH1D*)(Setup::user_histograms->FindObject(name));
00026 if(!h){
00027 h=new TH1D(name,name,Setup::nbins[0][0],min,max);
00028 if(!h) return;
00029 Setup::user_histograms->Add(h);
00030
00031 }
00032 h->Fill(val,weight);
00033
00034 }
00035 double angle(double X, double Y){
00036
00037
00038 double an=0.0;
00039 double R=sqrt(X*X+Y*Y);
00040
00041 if(R<pow(10,-20)) return an;
00042
00043 if(TMath::Abs(X)/R<0.8)
00044 {
00045 an=acos(X/R);
00046 if(Y<0 && an>0) an=-an;
00047 if(Y>0 && an<0) an=-an;
00048 }
00049 else
00050 {
00051 an=asin(Y/R);
00052 if(X<0 && an>=0.) an=PI-an;
00053 else if(X<0.) an=-PI-an;
00054
00055 }
00056 return an;
00057 }
00058
00059 int counter=0;
00060
00061 int ZtautauAnalysis(HEPParticle *mother,HEPParticleList *stableDaughters, int nparams, double *params)
00062 {
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 assert(mother!=0);
00085 assert(stableDaughters!=0);
00086
00087
00088 double threshold=0.05, leftmax=0.0, selector=0.0, actLost=0.0;
00089 if (nparams>0 && params==0) return -1;
00090 if (nparams>0) threshold=params[0];
00091 if (nparams>1) leftmax =params[1];
00092 if (nparams>2) selector =params[2];
00093 if (nparams>3) actLost =params[3];
00094
00095
00096 HEPParticleList *lostDaughters=new HEPParticleList;
00097 double pt_limit=threshold*mother->GetM();
00098
00099 HEPParticleListIterator daughters (*stableDaughters);
00100 int nphot=0;
00101 double ephot=pow(10,22);
00102 bool redo=false;
00103 for (HEPParticle *part=daughters.first(); part!=0; (redo)? part=part:part=daughters.next() ) {
00104 if(redo) redo=false;
00105 MC4Vector d4(part->GetE(),part->GetPx(),part->GetPy(),part->GetPz(),part->GetM());
00106
00107 d4.Boost(mother->GetPx(),mother->GetPy(),mother->GetPz(),mother->GetE(),mother->GetM());
00108
00109
00110
00111 double p_t=d4.GetX0();
00112 switch ((int) selector)
00113 {
00114 case 1: p_t=part->GetE(); break;
00115 case 2: p_t=d4.Xt(); break;
00116 }
00117
00118
00119 if(ifSofty(part->GetPDGId(),nparams,params)) nphot++;
00120 if ( ifSofty(part->GetPDGId(),nparams,params) && p_t < pt_limit) {
00121
00122 nphot=0;
00123 lostDaughters->push_back(part);
00124 stableDaughters->remove(part);
00125 part=daughters.first();
00126 redo=true;
00127 continue;
00128 }
00129 if( ifSofty(part->GetPDGId(),nparams,params) && ephot>p_t) ephot=p_t;
00130 }
00131 while(nphot>(int) leftmax)
00132 {
00133 double ephot1=pow(10,22);
00134 redo=false;
00135 for (HEPParticle *part=daughters.first(); part!=0; (redo)? part=part:part=daughters.next() ) {
00136 if(redo) redo=false;
00137 MC4Vector d4(part->GetE(),part->GetPx(),part->GetPy(),part->GetPz(),part->GetM());
00138
00139 d4.Boost(mother->GetPx(),mother->GetPy(),mother->GetPz(),mother->GetE(),mother->GetM());
00140
00141
00142 double p_t=d4.GetX0();
00143 switch ((int) selector)
00144 {
00145 case 1: p_t=part->GetE(); break;
00146 case 2: p_t=d4.Xt(); break;
00147 }
00148
00149
00150 if ( ifSofty(part->GetPDGId(),nparams,params) && p_t == ephot) {
00151
00152 nphot--;
00153 lostDaughters->push_back(part);
00154 stableDaughters->remove(part);
00155 ephot1=pow(10,22);
00156 part=daughters.first();
00157 redo=true;
00158 continue;
00159 }
00160 if( ifSofty(part->GetPDGId(),nparams,params) && ephot1>p_t) ephot1=p_t;
00161 }
00162 ephot=ephot1;
00163
00164 }
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178 int version=(int) actLost;
00179
00180 switch(version)
00181 {
00182 case 1:
00183 {
00184 HEPParticleListIterator lost (*lostDaughters);
00185 for (HEPParticle *lostpart=lost.first(); lostpart!=0; lostpart=lost.next() ) {
00186 HEPParticle* Best=0;
00187 double searchvirt=pow(10.0,22);
00188 MC4Vector VV;
00189 for( HEPParticle *part=daughters.first(); part!=0; part=daughters.next() ){
00190 if(part->GetCharge()==0) continue;
00191 VV=lostpart->GetP4()+part->GetP4();
00192 VV.AdjustM();
00193 if (VV.GetM()<searchvirt) {searchvirt=VV.GetM(); Best=part;}
00194 }
00195 if(Best) {
00196 Best->SetPx(Best->GetPx()+lostpart->GetPx());
00197 Best->SetPy(Best->GetPy()+lostpart->GetPy());
00198 Best->SetPz(Best->GetPz()+lostpart->GetPz());
00199 Best->SetE (Best->GetE ()+lostpart->GetE ());
00200 }
00201 }
00202 break;
00203 }
00204 default: break;
00205 }
00206
00207 delete lostDaughters;
00208
00209
00210
00211
00212
00213 double px=0,py=0,pz=0,e=0;
00214 double px1=0,py1=0,pz1=0,e1=0;
00215
00216
00217 for(HEPParticle *part=daughters.first();part!=0;part=daughters.next())
00218 {
00219 if(abs(part->GetPDGId())==211)
00220 {
00221 px1+=part->GetPx();
00222 py1+=part->GetPy();
00223 pz1+=part->GetPz();
00224 e1+=part->GetE();
00225 }
00226 if(abs(part->GetPDGId())==211) continue;
00227
00228 px+=part->GetPx();
00229 py+=part->GetPy();
00230 pz+=part->GetPz();
00231 e+=part->GetE();
00232 }
00233 double mass=e*e-px*px-py*py-pz*pz;
00234 double mass1=(e+e1)*(e+e1)-(px+px1)*(px+px1)-(py+py1)*(py+py1)-(pz+pz1)*(pz+pz1);
00235 mass=1-mass/mass1;
00236 char mm[] = "pi-energy";
00237 fillUserHisto(mm,mass,1.0,0.0,1.1);
00238
00239
00240 bool activateUserHist=false;
00241 if(!activateUserHist) return 1;
00242
00243
00244
00245 double X=mother->GetPx(), Y=mother->GetPy(), Z=mother->GetPz();
00246
00247
00248
00249 double pt=sqrt(X*X+Y*Y);
00250 double eta=log((sqrt(pt*pt+Z*Z)+TMath::Abs(Z))/pt);
00251 if(Z<0 && eta>0) eta=-eta;
00252 if(Z>0 && eta<0) eta=-eta;
00253 double phi=angle(X,Y);
00254 char hist1[] = "mother-PT";
00255 char hist2[] = "mother-eta";
00256 char hist3[] = "mother-phi";
00257 fillUserHisto(hist1,pt,1.0,0.0,100.0);
00258 fillUserHisto(hist2,eta,1.0,-8.0,8.0);
00259 fillUserHisto(hist3,phi,1.0,-PI,PI);
00260 return 1;
00261 }