00001
00002
00003
00004
00005
00007
00008 #include <set>
00009
00010 #include "TClonesArray.h"
00011
00012 #include "MessageService/MsgService.h"
00013 #include "CandNtupleSR/NtpSRStrip.h"
00014 #include "StandardNtuple/NtpStRecord.h"
00015
00016 #include "NtupleUtils/LISieve.h"
00017
00018 CVSID("$Id: LISieve.cxx,v 1.5 2009/11/16 14:02:16 jdejong Exp $");
00019
00020
00021
00022 Bool_t LISieve::IsLIforNC(const NtpStRecord& ntp)
00023 {
00029
00030
00031 if (ntp.GetHeader().GetVldContext().GetDetector()!=
00032 Detector::kFar) return false;
00033
00034
00035 Msg::LogLevel_t logLevel=Msg::kVerbose;
00036
00037
00038 const Bool_t cleanTheEvent=true;
00039
00040
00041 multiset<Double_t> times;
00042
00043 Int_t numStrips=ntp.stp->GetEntries();
00044 if (numStrips<=0) return false;
00046
00048 for (Int_t hit=0;hit<numStrips;hit++){
00049 NtpSRStrip* strip = dynamic_cast<NtpSRStrip*>((*ntp.stp)[hit]);
00050
00051 Double_t time=strip->time0;
00052 if (time<0 || time>1) time=strip->time1;
00053
00054 if (time>0 && time<=1) {
00055 times.insert(time);
00056 }
00057
00058 }
00059
00060
00061 multiset<Double_t>::const_iterator it=times.begin();
00062 advance(it,times.size()/2);
00063 Double_t medianTime=*it;
00064 MAXMSG("LISieve",Msg::kDebug,100)
00065 <<"LISieve: Median time="<<medianTime<<endl;
00066
00067 map<Int_t,Int_t> hpp;
00068 Float_t sumSigCorEast=0;
00069 Float_t sumSigCorWest=0;
00070
00071 for (Int_t hit=0;hit<numStrips;hit++){
00072 NtpSRStrip* strip = dynamic_cast<NtpSRStrip*>((*ntp.stp)[hit]);
00073
00074 if (cleanTheEvent) {
00075 if (strip->ph0.sigcor > 0){
00076 if (strip->time0<medianTime-200e-9 ||
00077 strip->time0>medianTime+200e-9) continue;
00078 }
00079 if (strip->ph1.sigcor > 0){
00080 if (strip->time1<medianTime-200e-9 ||
00081 strip->time1>medianTime+200e-9) continue;
00082 }
00083 }
00084
00085 sumSigCorEast+=strip->ph0.sigcor;
00086 sumSigCorWest+=strip->ph1.sigcor;
00087
00088 hpp[strip->plane] += 1;
00089 }
00090
00091 Float_t avHpp=0;
00092 vector<Float_t> pb(8);
00093 vector<Float_t> pbStrips(8);
00094
00095
00096 for (map<Int_t,Int_t>::iterator hppIt=hpp.begin();
00097 hppIt!=hpp.end();++hppIt){
00098 avHpp+=hppIt->second;
00099
00100 Int_t pl=hppIt->first;
00101
00102 if (pl>=1 && pl<=64) pb[0]+=1./64;
00103 else if (pl>=65 && pl<=128) pb[1]+=1./64;
00104 else if (pl>=129 && pl<=192) pb[2]+=1./64;
00105 else if (pl>=193 && pl<=248) pb[3]+=1./56;
00106 else if (pl>=250 && pl<=313) pb[4]+=1./64;
00107 else if (pl>=314 && pl<=377) pb[5]+=1./64;
00108 else if (pl>=378 && pl<=441) pb[6]+=1./64;
00109 else if (pl>=442 && pl<=485) pb[7]+=1./44;
00110
00111
00112 if (pl>=1 && pl<=64) pbStrips[0]+=avHpp*1./(64*192.);
00113 else if (pl>=65 && pl<=128) pbStrips[1]+=avHpp*1./(64*192.);
00114 else if (pl>=129 && pl<=192) pbStrips[2]+=avHpp*1./(64*192.);
00115 else if (pl>=193 && pl<=248) pbStrips[3]+=avHpp*1./(56*192.);
00116 else if (pl>=250 && pl<=313) pbStrips[4]+=avHpp*1./(64*192.);
00117 else if (pl>=314 && pl<=377) pbStrips[5]+=avHpp*1./(64*192.);
00118 else if (pl>=378 && pl<=441) pbStrips[6]+=avHpp*1./(64*192.);
00119 else if (pl>=442 && pl<=485) pbStrips[7]+=avHpp*1./(44*192.);
00120
00121
00122
00123 MAXMSG("LISieve",Msg::kVerbose,2000)
00124 <<"plane="<<pl<<", hpp="<<hppIt->second<<endl;
00125 }
00126 if (hpp.size()>0) avHpp/=hpp.size();
00127 Float_t sumSig=sumSigCorEast+sumSigCorWest;
00128 Float_t minSigCorEW = TMath::Min(sumSigCorEast, sumSigCorWest);
00129 Float_t asym=0;
00130
00131 if (sumSig) asym = (sumSig - 2 * minSigCorEW) / sumSig;
00132
00133
00134
00135 Float_t fractFlashed1=0;
00136 Float_t fractFlashed2=0;
00137
00138 for (vector<Float_t>::iterator it=pb.begin();
00139 it!=pb.end();++it)
00140 {
00141 Float_t fract=*it;
00142 if (fract>fractFlashed1){
00143
00144 fractFlashed2=fractFlashed1;
00145
00146 fractFlashed1=fract;
00147 }
00148
00149 else if (fract>fractFlashed2) {
00150 fractFlashed2=fract;
00151 }
00152
00153 MAXMSG("LISieve",Msg::kVerbose,200)
00154 <<"fract="<<fract<<", f1="<<fractFlashed1
00155 <<", f2="<<fractFlashed2<<endl;
00156 }
00157
00158 Float_t ratioFlashed=0;
00159 if (fractFlashed1>0) ratioFlashed=fractFlashed2/fractFlashed1;
00160
00161
00162
00163
00164
00165
00166 Float_t fractStripsFlashed1=0;
00167 Float_t fractStripsFlashed2=0;
00168
00169 for (vector<Float_t>::iterator it=pbStrips.begin();
00170 it!=pbStrips.end();++it)
00171 {
00172 Float_t fract=*it;
00173 if (fract>fractStripsFlashed1){
00174
00175 fractStripsFlashed2=fractStripsFlashed1;
00176
00177 fractStripsFlashed1=fract;
00178 }
00179
00180 else if (fract>fractStripsFlashed2) {
00181 fractStripsFlashed2=fract;
00182 }
00183
00184 MAXMSG("LISieve",Msg::kVerbose,200)
00185 <<"fractStrip="<<fract<<", f1="<<fractStripsFlashed1
00186 <<", f2="<<fractStripsFlashed2<<endl;
00187 }
00188
00189 Float_t ratioStripsFlashed=0;
00190 if (fractStripsFlashed1>0)
00191 ratioStripsFlashed=fractStripsFlashed2/fractStripsFlashed1;
00192
00193
00194
00195
00196 Bool_t li=false;
00197
00198
00199
00200
00201
00202
00203
00204 if ( (asym>0.55 || minSigCorEW>1.7e6) &&
00205 ratioStripsFlashed<0.006 &&
00206 fractStripsFlashed1>0.02 )
00207 {
00208 li=true;
00209
00210 MAXMSG("LISieve",logLevel,100)
00211 <<"LI Event:"<<endl
00212 <<" Asymmetry="<<asym<<endl
00213 <<" Av. HPP ="<<avHpp<<endl
00214 <<" Fract Fl1="<<fractFlashed1
00215 <<", Fract Fl2="<<fractFlashed2
00216 <<" Ratio Fla="<<ratioFlashed
00217 <<" Strips Fl1="<<fractStripsFlashed1
00218 <<", StripsFl2="<<fractStripsFlashed2
00219 <<" Ratio Strips="<<ratioStripsFlashed<<endl;
00220 }
00221 else
00222 {
00223 MAXMSG("LISieve",logLevel,10)
00224 <<"Non-LI Event:"<<endl
00225 <<" Asymmetry="<<asym<<endl
00226 <<" Av. HPP ="<<avHpp<<endl
00227 <<" Fract Fl1="<<fractFlashed1
00228 <<", Fract Fl2="<<fractFlashed2
00229 <<" Ratio Fla="<<ratioFlashed
00230 <<" Strips Fl1="<<fractStripsFlashed1
00231 <<", StripsFl2="<<fractStripsFlashed2
00232 <<" Ratio Strips="<<ratioStripsFlashed<<endl;
00233 }
00234
00235 return li;
00236 }
00237
00238 Bool_t LISieve::IsLI(const NtpStRecord& ntp)
00239 {
00245
00246
00247 if (ntp.GetHeader().GetVldContext().GetDetector()!=
00248 Detector::kFar) return false;
00249
00250
00251 Msg::LogLevel_t logLevel=Msg::kVerbose;
00252
00253
00254 const Bool_t cleanTheEvent=true;
00255
00256
00257 multiset<Double_t> times;
00258
00259 Int_t numStrips=ntp.stp->GetEntries();
00260 if (numStrips<=0) return false;
00262
00264 for (Int_t hit=0;hit<numStrips;hit++){
00265 NtpSRStrip* strip = dynamic_cast<NtpSRStrip*>((*ntp.stp)[hit]);
00266
00267 Double_t time=strip->time0;
00268 if (time<0 || time>1) time=strip->time1;
00269
00270 if (time>0 && time<=1) {
00271 times.insert(time);
00272 }
00273
00274 }
00275
00276
00277 multiset<Double_t>::const_iterator it=times.begin();
00278 advance(it,times.size()/2);
00279 Double_t medianTime=*it;
00280 MAXMSG("LISieve",Msg::kDebug,100)
00281 <<"LISieve: Median time="<<medianTime<<endl;
00282
00283 map<Int_t,Int_t> hpp;
00284 Float_t sumSigCorEast=0;
00285 Float_t sumSigCorWest=0;
00286
00287 for (Int_t hit=0;hit<numStrips;hit++){
00288 NtpSRStrip* strip = dynamic_cast<NtpSRStrip*>((*ntp.stp)[hit]);
00289
00290 if (cleanTheEvent) {
00291 if (strip->ph0.sigcor > 0){
00292 if (strip->time0<medianTime-200e-9 ||
00293 strip->time0>medianTime+200e-9) continue;
00294 }
00295 if (strip->ph1.sigcor > 0){
00296 if (strip->time1<medianTime-200e-9 ||
00297 strip->time1>medianTime+200e-9) continue;
00298 }
00299 }
00300
00301 sumSigCorEast+=strip->ph0.sigcor;
00302 sumSigCorWest+=strip->ph1.sigcor;
00303
00304 hpp[strip->plane] += 1;
00305 }
00306
00307 Float_t avHpp=0;
00308 vector<Float_t> pb(8);
00309
00310
00311 for (map<Int_t,Int_t>::iterator hppIt=hpp.begin();
00312 hppIt!=hpp.end();++hppIt){
00313 avHpp+=hppIt->second;
00314
00315 Int_t pl=hppIt->first;
00316
00317 if (pl>=1 && pl<=64) pb[0]+=1./64;
00318 else if (pl>=65 && pl<=128) pb[1]+=1./64;
00319 else if (pl>=129 && pl<=192) pb[2]+=1./64;
00320 else if (pl>=193 && pl<=248) pb[3]+=1./56;
00321 else if (pl>=250 && pl<=313) pb[4]+=1./64;
00322 else if (pl>=314 && pl<=377) pb[5]+=1./64;
00323 else if (pl>=378 && pl<=441) pb[6]+=1./64;
00324 else if (pl>=442 && pl<=485) pb[7]+=1./44;
00325
00326 MAXMSG("LISieve",Msg::kVerbose,2000)
00327 <<"plane="<<pl<<", hpp="<<hppIt->second<<endl;
00328 }
00329 if (hpp.size()>0) avHpp/=hpp.size();
00330 Float_t sumSig=sumSigCorEast+sumSigCorWest;
00331 Float_t minSigCorEW = TMath::Min(sumSigCorEast, sumSigCorWest);
00332 Float_t asym=0;
00333
00334 if (sumSig) asym = (sumSig - 2 * minSigCorEW) / sumSig;
00335
00336
00337
00338 Float_t fractFlashed1=0;
00339 Float_t fractFlashed2=0;
00340
00341 for (vector<Float_t>::iterator it=pb.begin();
00342 it!=pb.end();++it)
00343 {
00344 Float_t fract=*it;
00345 if (fract>fractFlashed1){
00346
00347 fractFlashed2=fractFlashed1;
00348
00349 fractFlashed1=fract;
00350 }
00351
00352 else if (fract>fractFlashed2) {
00353 fractFlashed2=fract;
00354 }
00355
00356 MAXMSG("LISieve",Msg::kVerbose,200)
00357 <<"fract="<<fract<<", f1="<<fractFlashed1
00358 <<", f2="<<fractFlashed2<<endl;
00359 }
00360
00361 Float_t ratioFlashed=0;
00362 if (fractFlashed1>0) ratioFlashed=fractFlashed2/fractFlashed1;
00363
00364
00365 Bool_t li=false;
00366
00367
00368
00369 if ( (asym>0.5 || minSigCorEW>1.7e6) &&
00370 avHpp>3 && ratioFlashed<0.05 &&
00371 fractFlashed1>0.85 && fractFlashed2<0.1 )
00372 {
00373 li=true;
00374
00375 MAXMSG("LISieve",logLevel,100)
00376 <<"LI Event:"<<endl
00377 <<" Asymmetry="<<asym<<endl
00378 <<" Av. HPP ="<<avHpp<<endl
00379 <<" Fract Fl1="<<fractFlashed1
00380 <<", Fract Fl2="<<fractFlashed2
00381 <<" Ratio Fla="<<ratioFlashed << endl;
00382 }
00383 else
00384 {
00385 MAXMSG("LISieve",logLevel,10)
00386 <<"Non-LI Event:"<<endl
00387 <<" Asymmetry="<<asym<<endl
00388 <<" Av. HPP ="<<avHpp<<endl
00389 <<" Fract Fl1="<<fractFlashed1
00390 <<", Fract Fl2="<<fractFlashed2
00391 <<" Ratio Fla="<<ratioFlashed <<endl;
00392 }
00393
00394 return li;
00395 }
00396
00397
00398