ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitHzz4l/Selection/src/applySelection.cc
(Generate patch)

Comparing UserCode/MitHzz4l/Selection/src/applySelection.cc (file contents):
Revision 1.16 by khahn, Wed May 9 14:57:20 2012 UTC vs.
Revision 1.21 by khahn, Sat May 12 03:00:15 2012 UTC

# Line 5 | Line 5
5   #include <iostream>                 // standard I/O
6   #include <iomanip>                  // functions to format standard I/O
7   #include <bitset>  
8 + #include <map>  
9   using namespace std;
10  
11   //
# Line 50 | Line 51 | using namespace std;
51   #include "IsolationSelection.h"
52  
53   //#include "Selection.h"
54 < #include "ReferenceSelection.h"
54 > //#include "ReferenceSelection.h"
55 > #include "ReferenceSelection2.h"
56  
57   #include "TriggerUtils.h"
58   #include "PassHLT.h"
# Line 83 | Line 85 | TH1D * hpu;
85   RunLumiRangeMap rlrm;
86   vector<SimpleLepton> failingLeptons ; // for fake estimation
87   vector<SimpleLepton> passingLeptons;      // for fake estimation
88 + vector<unsigned> cutvec;
89 + vector<vector<unsigned> > zcutvec;
90 + vector<vector<unsigned> > zzcutvec;
91 + map<unsigned,float>       evtrhoMap;
92 + vector<string> cutstrs;
93 + bool passes_HLT_MC;
94  
95   //
96   // prototypes
# Line 92 | Line 100 | void initPUWeights();
100   double getPUWeight(unsigned npu);
101   void setEffiencyWeights(EventData&, WeightStruct& );
102   void initRunLumiRangeMap();
103 + void initEvtRhoMap(map<unsigned,float> &);
104   //----------------------------------------------------------------------------
105  
106  
# Line 101 | Line 110 | void initRunLumiRangeMap();
110   int main(int argc, char** argv)
111   //----------------------------------------------------------------------------
112   {
113 +  cutstrs.push_back(string("skim0"));              //0
114 +  cutstrs.push_back(string("skim1"));              //1
115 +  cutstrs.push_back(string("trigger"));            //2
116 +  // -------------------------------------------------
117 +  cutstrs.push_back(string("Z candidate"));        //3
118 +  cutstrs.push_back(string("good Z1"));            //4
119 +  // -------------------------------------------------
120 +  cutstrs.push_back(string("4l"));                 //5  
121 +  cutstrs.push_back(string("ZZ candidate"));       //6
122 +  cutstrs.push_back(string("good Z2"));            //7
123 +  cutstrs.push_back(string("ZZ 20/10"));           //8
124 +  cutstrs.push_back(string("resonance"));          //9
125 +  cutstrs.push_back(string("m4l>70"));             //10
126 +  cutstrs.push_back(string("m4l>100"));            //11
127 +
128 +
129 +
130 +
131    string cmsswpath(CMSSW_BASE);
132    cmsswpath.append("/src");
133    std::bitset<1024> triggerBits;
134    vector<vector<string> > inputFiles;
135    inputFiles.push_back(vector<string>());
136    map<string,unsigned> entrymap; // number of unskimmed entries in each file
137 +  for( int i=0; i<cutstrs.size(); i++ ) cutvec.push_back(0);
138 +  for( int i=0; i<2; i++ )  {
139 +    zcutvec.push_back(vector<unsigned>());
140 +    for( int j=0; j<cutstrs.size(); j++ ) zcutvec[i].push_back(0);
141 +  }
142 +  for( int i=0; i<3; i++ )  {
143 +    zzcutvec.push_back(vector<unsigned>());
144 +    for( int j=0; j<cutstrs.size(); j++ ) zzcutvec[i].push_back(0);
145 +  }
146 +
147  
148    //
149    // args
# Line 178 | Line 215 | int main(int argc, char** argv)
215    nt.makeAngleBranch(angles);
216    nt.makeKinematicsBranch(kinematics);
217    nt.makeInfoBranch(evtinfo);
218 <  FOTuple foTree( nt.getFile(), (const char*)"fo");
218 >
219 >  FOTuple foTree( nt.getFile(), (const char*)"FOtree");
220    foTree.makeFailedLeptonBranch(failingLeptons);
221    foTree.makeZLeptonBranch(passingLeptons);
222  
# Line 209 | Line 247 | int main(int argc, char** argv)
247    initElectronIDMVA();
248    initElectronIsoMVA();
249    initTrigger();
250 <  
250 >
251 >  // hack
252 >  initEvtRhoMap(evtrhoMap);
253  
254    
255    //
# Line 248 | Line 288 | int main(int argc, char** argv)
288    chain->SetBranchAddress(fMuonName,        &muonArr);
289    chain->SetBranchAddress(fPrimVtxName,     &vtxArr);
290    chain->SetBranchAddress(fPFCandidateName, &pfArr);
291 <  chain->SetBranchAddress(fPileupInfoName,  &puArr);
291 >  if( ctrl.mc ) chain->SetBranchAddress(fPileupInfoName,  &puArr);
292    chain->SetBranchAddress(fPileupEnergyDensityName, &puDArr);
293    chain->SetBranchAddress(fTrackName, &trkArr);
294    chain->SetBranchAddress(fTriggerMaskName, &trigMask);
# Line 281 | Line 321 | int main(int argc, char** argv)
321      {
322        chain->GetEntry(ientry);
323        if(!(ientry%1000)) cerr << "entry: " << ientry << endl;
284      if( ientry>100 )break;
324        setPV( ctrl, vtxArr, vtx);
325  
326 +      cout << "origrho: " << puDArr->At(0)->Rho()
327 +           << "\torigrholoweta: " << puDArr->At(0)->RhoLowEta()
328 +           << endl;
329 +
330  
331        //
332        // data/MC
# Line 292 | Line 335 | int main(int argc, char** argv)
335          //
336          // xsec & PU weights
337          //
338 <        weights.w = getWeight(xstab,entrymap,chain)/ctrl.totalMC;
338 >        //      weights.w = getWeight(xstab,entrymap,chain)/ctrl.totalMC;
339          int npu = -1;
340          for(int i=0;i<puArr->GetEntries();i++) {
341            if(puArr->At(i)->GetBunchCrossing() == 0)
# Line 302 | Line 345 | int main(int argc, char** argv)
345          evtinfo.npu;
346          weights.npuw = getPUWeight(evtinfo.npu);
347          //      cout << "weight: " << weights.w << endl;
348 +        //
349 +        // trigger
350 +        //
351 +        if( string(chain->GetFile()->GetEndpointUrl()->GetFile()) != currentFile ) {
352 +          currentFile = string(chain->GetFile()->GetEndpointUrl()->GetFile());
353 +          hltchain->SetBranchAddress(fTriggerTableName, &hltTableStrings);
354 +          hltchain->GetEntry(0);
355 +          hltTable->Clear();
356 +          fillTriggerBits(hltTable, hltTableStrings );
357 +        }
358 +        if( ctrl.debug ) cout << "file is : " << currentFile  << endl;
359 +        fillTriggerBits( hltTable, trigMask, triggerBits );
360 +        passes_HLT_MC = true; // passed to apply as extern global, just for sync
361 +        if( !passHLTMC(triggerBits, info->RunNum(), info->EvtNum() ) ) {
362 +          passes_HLT_MC = false;
363 +        }
364        } else {
365          //
366          // JSON
367          //
368 +        /*
369          RunLumiRangeMap::RunLumiPairType rl(info->RunNum(), info->LumiSec());      
370          if( !(rlrm.HasRunLumi(rl)) )  {
371            if( ctrl.debug ) cout << "\tfails JSON" << endl;
372            continue;
373          }
374 +        */
375          //
376          // trigger
377          //
# Line 322 | Line 383 | int main(int argc, char** argv)
383            fillTriggerBits(hltTable, hltTableStrings );
384          }
385          if( ctrl.debug ) cout << "file is : " << currentFile  << endl;
386 +        /*
387          fillTriggerBits( hltTable, trigMask, triggerBits );
388          if( !passHLT(triggerBits, info->RunNum(), info->EvtNum() ) ) {
389            if( ctrl.debug ) cout << "\tfails trigger ... " << endl;
390            continue;
391          }
392 +        */
393        }
394  
395        //
# Line 335 | Line 398 | int main(int argc, char** argv)
398        failingLeptons.clear();
399        passingLeptons.clear();
400        EventData ret4l =
401 <        apply_HZZ4L_reference_selection(ctrl, info,
401 >
402 >        /*
403 >        apply_HZZ4L_reference2_selection(ctrl, info,
404 >                                         vtx,
405 >                                         pfArr,
406 >                                         puDArr,
407 >                                         electronArr,
408 >                                         &electronReferencePreSelection,
409 >                                         &electronReferenceIDMVASelection,
410 >                                         &electronReferenceIsoSelection,
411 >                                         muonArr,
412 >                                         &muonReferencePreSelection,
413 >                                         &muonIDPFSelection,
414 >                                         &muonReferenceIsoSelection);
415 >        */
416 >        apply_HZZ4L_reference2_selection(ctrl, info,
417                                vtx,
418                                pfArr,
419                                puDArr,
420                                electronArr,
421                                &electronReferencePreSelection,
422                                &electronReferenceIDMVASelection,
345                              &electronReferenceIsoSelection,
346                              muonArr,
347                              &muonReferencePreSelection,
348                              &muonIDPFSelection,
349                              &muonReferenceIsoSelection);
350        /*
351        apply_HZZ4L_reference_selection(ctrl, info,
352                              vtx,
353                              pfArr,
354                              puArr,
355                              electronArr,
356                              &electronPreSelection,
357                              &electronIDMVASelection,
423                                &electronIsoMVASelection,
424                                muonArr,
425 <                              &muonPreSelection,
425 >                              &muonReferencePreSelection,
426                                &muonIDPFSelection,
427                                &muonIsoMVASelection);
428 <        */
428 >
429 >
430  
431        if( ctrl.debug ) cout << endl;
432  
433 <      //      cout << "bits: " << ret4l.status.selectionBits << endl;
433 >
434 >      int Z1type=0, Z2type=0;
435 >      if( ret4l.status.selectionBits.to_ulong() >= PASS_ZCANDIDATE ) {
436 >        if( abs(ret4l.Z1leptons[0].type) == 11  ) Z1type = 11;
437 >        if( abs(ret4l.Z1leptons[0].type) == 13  ) Z1type = 13;
438 >      }  
439 >      if( ret4l.status.selectionBits.to_ulong() >= PASS_ZZCANDIDATE ) {
440 >        if( abs(ret4l.Z2leptons[0].type) == 11  ) Z2type = 11;
441 >        if( abs(ret4l.Z2leptons[0].type) == 13  ) Z2type = 13;
442 >      }  
443 >      
444 >      cout  << "bits: " << ret4l.status.selectionBits  << "\t"
445 >            << "Z1: " << Z1type << "\t"
446 >            << "Z2: " << Z2type << endl;
447 >      cout << endl;
448 >                      
449        
450        if( ret4l.status.pass() ) {
370        
451          fillAngles(ret4l,angles);
452          fillKinematics(ret4l,kinematics);
453          fillEventInfo(info,evtinfo);
# Line 399 | Line 479 | int main(int argc, char** argv)
479          pass++;
480          //      if( pass > 3 ) break;
481  
482 <      } else if( ret4l.status.selectionBits.test(PASS_ZCANDIDATE) ) { // save for fakes ...
483 <        cout << "failingLeptons : " << failingLeptons.size() << endl;
484 <        for( int f=0; f<failingLeptons.size(); f++ ) {
485 <          SimpleLepton  l = failingLeptons[f];
486 <          cout << "f: " << f << "\t"
487 <               << "type: " << l.type << "\t"
488 <               << "pT: " << l.vec->Pt()
489 <               << endl;
490 <        }
491 <        /*
492 <        cout << "passingLeptons : " << passingLeptons.GetSize() << endl;
413 <        for( int f=0; f<passingLeptons.GetSize(); f++ ) {
414 <          cout << "f: " << f << "\t"
415 <               << "type: " << passingLeptons.At(f).type << "\t"
416 <               << "pT: " << passingLeptons.At(f).vec->Pt()
417 <               << endl;
482 >      } else if( ret4l.status.selectionBits.test(PASS_GOODZ1) ) { // save for fakes ...
483 >        //      if(ctrl.debug) {
484 >          cout << "failingLeptons : " << failingLeptons.size() << endl;
485 >          for( int f=0; f<failingLeptons.size(); f++ ) {
486 >            SimpleLepton  l = failingLeptons[f];
487 >            cout << "f: " << f << "\t"
488 >                 << "type: " << l.type << "\t"
489 >                 << "pT: " << l.vec.Pt()  << "\t"
490 >                 << "eta: " << l.vec.Eta()
491 >                 << endl;
492 >            //    }
493          }
419        */
420        cout << endl;
494          foTree.Fill();
495        }
496      }  
# Line 426 | Line 499 | int main(int argc, char** argv)
499    foTree.getFile()->cd();
500    foTree.getTree()->Write();
501    nt.WriteClose();
502 +
503 +  cout << endl;
504 +  cout << endl;
505 +  for( int i=0; i<cutvec.size(); i++ ) {
506 +    cout << "cut: " << i << "\t"
507 +         << "pass: " << cutvec[i];
508 +
509 +    if( i>PASS_TRIGGER&&i<=PASS_GOODZ1 )
510 +      cout << "\t2e: " << zcutvec[0][i]
511 +           << "\t2m: " << zcutvec[1][i];
512 +
513 +    if( i>PASS_ZCANDIDATE )
514 +      cout << "\t4e: " << zzcutvec[0][i]
515 +           << "\t4m: " << zzcutvec[1][i]
516 +           << "\t2e2m: " << zzcutvec[2][i];
517 +
518 +    cout << "\t" << cutstrs[i] << endl;
519 +
520 +    cout << endl;
521 +  }
522 +
523   }
524  
525   //----------------------------------------------------------------------------
# Line 502 | Line 596 | void setEffiencyWeights(EventData & evtd
596    
597    for( int k=0; k<lepvec.size(); k++ ) {
598      if( abs(lepvec[k].type) == 13 ) {
599 <      mvec.push_back( std::pair<float,float> (fabs(lepvec[k].vec->Eta()), lepvec[k].vec->Pt()) );
600 <      wlegs.push_back( muonPerLegOfflineEfficiencyWeight( fabs(lepvec[k].vec->Eta()),
601 <                                                          lepvec[k].vec->Pt() ) );
599 >      mvec.push_back( std::pair<float,float> (fabs(lepvec[k].vec.Eta()), lepvec[k].vec.Pt()) );
600 >      wlegs.push_back( muonPerLegOfflineEfficiencyWeight( fabs(lepvec[k].vec.Eta()),
601 >                                                          lepvec[k].vec.Pt() ) );
602      } else {
603        
604        // now deal with medium vs loose
605        //              evec.push_back( std::pair<float,float> (fabs(lepvec[k].vec.Eta()), lepvec[k].vec.Pt()) );
606        
607 <      std::pair<float,float> tmppair(fabs(lepvec[k].vec->Eta()), lepvec[k].vec->Pt());
607 >      std::pair<float,float> tmppair(fabs(lepvec[k].vec.Eta()), lepvec[k].vec.Pt());
608        evec.push_back( std::pair<bool, std::pair<float,float> > (lepvec[k].isTight, tmppair) );
609        
610 <      //              wlegs.push_back( elePerLegOfflineEfficiencyWeight(  fabs(lepvec[k].vec->Eta()),
611 <      //                                                                 lepvec[k].vec->Pt() ) );
610 >      //              wlegs.push_back( elePerLegOfflineEfficiencyWeight(  fabs(lepvec[k].vec.Eta()),
611 >      //                                                                 lepvec[k].vec.Pt() ) );
612        
613 <      wlegs.push_back( elePerLegOfflineEfficiencyWeight(  fabs(lepvec[k].vec->Eta()),
614 <                                                          lepvec[k].vec->Pt(),
613 >      wlegs.push_back( elePerLegOfflineEfficiencyWeight(  fabs(lepvec[k].vec.Eta()),
614 >                                                          lepvec[k].vec.Pt(),
615                                                            lepvec[k].isTight ) );
616        
617      }
# Line 563 | Line 657 | double getPUWeight(unsigned npu)
657   {
658    return hpu->GetBinContent(hpu->FindBin(npu));
659   }
660 +
661 + //----------------------------------------------------------------------------
662 + void initEvtRhoMap( map<unsigned, float> & evtrhoMap )
663 + //----------------------------------------------------------------------------
664 + {
665 +  unsigned evt;
666 +  float rho;
667 +
668 +  FILE * f = fopen("evtrho.dat", "r");
669 +  while( fscanf( f, "%u:%f", &evt, &rho ) ) {
670 +    evtrhoMap[evt] = rho;
671 +  }
672 +  
673 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines