File indexing completed on 2024-04-06 12:23:22
0001
0002
0003
0004 #include "DataFormats/FWLite/interface/Handle.h"
0005 #include "DataFormats/PatCandidates/interface/Jet.h"
0006 #include "DataFormats/PatCandidates/interface/Muon.h"
0007 #include "DataFormats/HepMCCandidate/interface/FlavorHistory.h"
0008 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
0009 #include "Math/GenVector/PxPyPzM4D.h"
0010
0011 #include "PhysicsTools/FWLite/interface/EventContainer.h"
0012 #include "PhysicsTools/FWLite/interface/CommandLineParser.h"
0013
0014
0015 #include "TROOT.h"
0016 #include "TH2F.h"
0017
0018 using namespace std;
0019 using optutl::CommandLineParser;
0020
0021 enum
0022 {
0023 kNormalMode,
0024 kVqqMode,
0025 kLFMode,
0026 kWcMode
0027 };
0028
0029
0030
0031
0032
0033
0034
0035
0036 void outputNameTagFunc (string &tag);
0037
0038
0039
0040 void bookHistograms (fwlite::EventContainer &eventCont);
0041
0042
0043
0044
0045 bool calcSampleName (fwlite::EventContainer &eventCont, string &sampleName);
0046
0047
0048
0049
0050
0051
0052
0053 int main (int argc, char* argv[])
0054 {
0055
0056
0057
0058
0059
0060
0061
0062 CommandLineParser parser ("Creates SecVtx Mass templates");
0063
0064
0065
0066
0067 parser.addOption ("mode", CommandLineParser::kInteger,
0068 "Normal(0), VQQ(1), LF(2), Wc(3)",
0069 0);
0070 parser.addOption ("sampleName", CommandLineParser::kString,
0071 "Sample name (e.g., top, Wqq, etc.)");
0072
0073
0074 parser.stringValue ("outputFile") = "jetPt";
0075
0076
0077 parser.parseArguments (argc, argv);
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088 parser.parseArguments (argc, argv);
0089
0090
0091
0092
0093
0094
0095
0096 fwlite::EventContainer eventCont (parser);
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106 gROOT->SetStyle ("Plain");
0107
0108
0109 bookHistograms (eventCont);
0110
0111
0112
0113
0114
0115
0116
0117 for (eventCont.toBegin(); !eventCont.atEnd(); ++eventCont)
0118 {
0119
0120
0121
0122 fwlite::Handle< vector< pat::Jet > > jetCollection;
0123 jetCollection.getByLabel (eventCont, "selectedLayer1Jets");
0124 assert ( jetCollection.isValid() );
0125
0126 fwlite::Handle< vector< pat::Muon > > goodMuonCollection;
0127 goodMuonCollection.getByLabel (eventCont, "goodLeptons");
0128 assert ( goodMuonCollection.isValid() );
0129
0130
0131 if (! goodMuonCollection->size() )
0132 {
0133 continue;
0134 }
0135
0136
0137 string sampleName;
0138 if ( ! calcSampleName (eventCont, sampleName) )
0139 {
0140
0141 continue;
0142 }
0143
0144
0145
0146
0147 int numBottom = 0, numCharm = 0, numLight = 0;
0148 int numTags = 0;
0149 double sumVertexMass = 0.;
0150
0151 const vector< pat::Jet >::const_iterator kJetEnd = jetCollection->end();
0152 for (vector< pat::Jet >::const_iterator jetIter = jetCollection->begin();
0153 kJetEnd != jetIter;
0154 ++jetIter)
0155 {
0156
0157 if( jetIter->bDiscriminator("simpleSecondaryVertexBJetTags") < 2.05 )
0158 {
0159
0160 continue;
0161 }
0162 reco::SecondaryVertexTagInfo const * svTagInfos
0163 = jetIter->tagInfoSecondaryVertex("secondaryVertex");
0164 if ( svTagInfos->nVertices() <= 0 )
0165 {
0166
0167
0168
0169 continue;
0170 }
0171
0172
0173 ++numTags;
0174
0175
0176 int jetFlavor = std::abs( jetIter->partonFlavour() );
0177 if (5 == jetFlavor)
0178 {
0179 ++numBottom;
0180 }
0181 else if (4 == jetFlavor)
0182 {
0183 ++numCharm;
0184 }
0185 else
0186 {
0187 ++numLight;
0188 }
0189
0190
0191
0192
0193 ROOT::Math::LorentzVector< ROOT::Math::PxPyPzM4D<double> > sumVec;
0194 reco::CompositeCandidate vertexCand;
0195 reco::Vertex::trackRef_iterator
0196 kEndTracks = svTagInfos->secondaryVertex(0).tracks_end();
0197 for (reco::Vertex::trackRef_iterator trackIter =
0198 svTagInfos->secondaryVertex(0).tracks_begin();
0199 trackIter != kEndTracks;
0200 ++trackIter )
0201 {
0202 const double kPionMass = 0.13957018;
0203 ROOT::Math::LorentzVector< ROOT::Math::PxPyPzM4D<double> > vec;
0204 vec.SetPx( (*trackIter)->px() );
0205 vec.SetPy( (*trackIter)->py() );
0206 vec.SetPz( (*trackIter)->pz() );
0207 vec.SetM (kPionMass);
0208 sumVec += vec;
0209 }
0210 sumVertexMass += sumVec.M();
0211 if (2 == numTags)
0212 {
0213
0214 break;
0215 }
0216 }
0217
0218
0219
0220
0221 int numJets = std::min( (int) jetCollection->size(), 5 );
0222 eventCont.hist( sampleName + "_jettag")->Fill (numJets, numTags);
0223
0224
0225 if ( ! numTags)
0226 {
0227 continue;
0228 }
0229
0230
0231
0232
0233
0234 sumVertexMass /= numTags;
0235 string whichtag = "";
0236 if (1 == numTags)
0237 {
0238
0239 if (numBottom) whichtag = "_b";
0240 else if (numCharm) whichtag = "_c";
0241 else if (numLight) whichtag = "_q";
0242 else whichtag = "_X";
0243 } else {
0244
0245 if (2 == numBottom) whichtag = "_bb";
0246 else if (2 == numCharm) whichtag = "_cc";
0247 else if (2 == numLight) whichtag = "_qq";
0248 else if (numBottom && numCharm) whichtag = "_bc";
0249 else if (numBottom && numLight) whichtag = "_bq";
0250 else if (numCharm && numLight) whichtag = "_bq";
0251 else whichtag = "_XX";
0252 }
0253 string massName = sampleName
0254 + Form("_secvtxMass_%dj_%dt", numJets, numTags);
0255 eventCont.hist(massName)->Fill (sumVertexMass);
0256 eventCont.hist(massName + whichtag)->Fill (sumVertexMass);
0257 }
0258
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269 return 0;
0270 }
0271
0272
0273
0274
0275
0276
0277
0278
0279
0280 void outputNameTagFunc (string &tag)
0281 {
0282
0283
0284
0285
0286
0287
0288
0289
0290 }
0291
0292
0293 void bookHistograms (fwlite::EventContainer &eventCont)
0294 {
0295
0296
0297
0298
0299 CommandLineParser &parser = eventCont.parser();
0300 CommandLineParser::SVec baseNameVec;
0301 CommandLineParser::SVec beginningVec, endingVec;
0302 switch ( parser.integerValue ("mode") )
0303 {
0304 case kVqqMode:
0305
0306
0307
0308 beginningVec.push_back ("X");
0309 beginningVec.push_back ("W");
0310 beginningVec.push_back ("Z");
0311
0312 endingVec.push_back( "bb" );
0313 endingVec.push_back( "b2" );
0314 endingVec.push_back( "cc" );
0315 endingVec.push_back( "c2" );
0316 for (CommandLineParser::SVecConstIter outerIter = beginningVec.begin();
0317 beginningVec.end() != outerIter;
0318 ++outerIter)
0319 {
0320 for (CommandLineParser::SVecConstIter innerIter = endingVec.begin();
0321 endingVec.end() != innerIter;
0322 ++innerIter)
0323 {
0324 baseNameVec.push_back( *outerIter + *innerIter);
0325 }
0326 }
0327 break;
0328 case kLFMode:
0329
0330
0331 baseNameVec.push_back(parser.stringValue ("sampleName") + "b3");
0332 baseNameVec.push_back(parser.stringValue ("sampleName") + "c3");
0333
0334 default:
0335
0336 baseNameVec.push_back(parser.stringValue ("sampleName"));
0337 }
0338
0339
0340
0341
0342 CommandLineParser::SVec singleTagEndingVec, doubleTagEndingVec;
0343 singleTagEndingVec.push_back ("_b");
0344 singleTagEndingVec.push_back ("_c");
0345 singleTagEndingVec.push_back ("_q");
0346 doubleTagEndingVec.push_back ("_bb");
0347 doubleTagEndingVec.push_back ("_cc");
0348 doubleTagEndingVec.push_back ("_qq");
0349 doubleTagEndingVec.push_back ("_bc");
0350 doubleTagEndingVec.push_back ("_bq");
0351 doubleTagEndingVec.push_back ("_cq");
0352
0353
0354
0355
0356 for (CommandLineParser::SVecConstIter baseIter = baseNameVec.begin();
0357 baseNameVec.end() != baseIter;
0358 ++baseIter)
0359 {
0360
0361
0362
0363 TString histName = *baseIter + "_jettag";
0364 eventCont.add( new TH2F( histName, histName,
0365 6, -0.5, 5.5,
0366 3, -0.5, 2.5) );
0367 for (int jet = 1; jet <= 5; ++jet)
0368 {
0369 for (int tag = 1; tag <= 2; ++tag)
0370 {
0371
0372
0373
0374 if (tag > jet) continue;
0375 histName = *baseIter + Form ("_secvtxMass_%dj_%dt", jet, tag);
0376 eventCont.add( new TH1F( histName, histName, 40, 0, 10) );
0377 CommandLineParser::SVec *vecPtr = &singleTagEndingVec;
0378 if (2 == tag)
0379 {
0380 vecPtr = &doubleTagEndingVec;
0381 }
0382 for (CommandLineParser::SVecConstIter tagIter = vecPtr->begin();
0383 vecPtr->end() != tagIter;
0384 ++tagIter)
0385 {
0386
0387
0388
0389 histName = *baseIter + Form ("_secvtxMass_%dj_%dt", jet, tag)
0390 + *tagIter;
0391 eventCont.add( new TH1F( histName, histName, 40, 0, 10) );
0392 }
0393 }
0394 }
0395 }
0396 }
0397
0398
0399 bool calcSampleName (fwlite::EventContainer &eventCont, string &sampleName)
0400 {
0401
0402 CommandLineParser &parser = eventCont.parser();
0403 sampleName = parser.stringValue ("sampleName");
0404 int mode = parser.integerValue ("mode");
0405
0406
0407
0408
0409 if (kNormalMode == mode)
0410 {
0411
0412 return true;
0413 }
0414
0415 fwlite::Handle< unsigned int > heavyFlavorCategory;
0416 heavyFlavorCategory.getByLabel (eventCont, "flavorHistoryFilter");
0417 assert ( heavyFlavorCategory.isValid() );
0418 int HFcat = (*heavyFlavorCategory);
0419
0420
0421
0422
0423 if (kLFMode == mode)
0424 {
0425
0426 if (5 == HFcat)
0427 {
0428 sampleName += "b3";
0429 } else if (6 == HFcat)
0430 {
0431 sampleName += "c3";
0432 } else if (11 != HFcat)
0433 {
0434
0435 return false;
0436 }
0437 return true;
0438 }
0439
0440
0441
0442
0443 if (kWcMode == mode)
0444 {
0445
0446 if (4 != HFcat)
0447 {
0448
0449 return false;
0450 }
0451 return true;
0452 }
0453
0454
0455
0456
0457
0458
0459
0460
0461
0462
0463 sampleName = "X";
0464 fwlite::Handle< vector< reco::GenParticle > > genParticleCollection;
0465 genParticleCollection.getByLabel (eventCont, "genParticles");
0466 assert ( genParticleCollection.isValid() );
0467
0468
0469 const vector< reco::GenParticle>::const_iterator
0470 kGenPartEnd = genParticleCollection->end();
0471 for (vector< reco::GenParticle>::const_iterator gpIter =
0472 genParticleCollection->begin();
0473 gpIter != kGenPartEnd; ++gpIter )
0474 {
0475 if (gpIter->status() == 3 && std::abs(gpIter->pdgId()) == 23)
0476 {
0477 sampleName = "Z";
0478 break;
0479 }
0480 if (gpIter->status() == 3 && std::abs(gpIter->pdgId()) == 24)
0481 {
0482 sampleName = "W";
0483 break;
0484 }
0485 }
0486 switch (HFcat)
0487 {
0488
0489
0490
0491
0492
0493
0494
0495
0496
0497
0498
0499
0500
0501 case 1:
0502 sampleName += "bb";
0503 break;
0504 case 2:
0505
0506
0507
0508 sampleName += "b2";
0509 break;
0510 case 3:
0511 sampleName += "cc";
0512 break;
0513 case 4:
0514
0515
0516
0517 sampleName += "c2";
0518 break;
0519 default:
0520
0521
0522 return false;
0523 }
0524 return true;
0525 }